Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1 | /* |
| 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 Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 18 | #include "bfad_drv.h" |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 19 | #include "bfad_im.h" |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 20 | #include "bfa_plog.h" |
| 21 | #include "bfa_cs.h" |
| 22 | #include "bfa_modules.h" |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 23 | |
| 24 | BFA_TRC_FILE(HAL, FCXP); |
Krishna Gudipati | 3d7fc66 | 2011-06-24 20:28:17 -0700 | [diff] [blame] | 25 | BFA_MODULE(fcdiag); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 26 | BFA_MODULE(fcxp); |
| 27 | BFA_MODULE(sgpg); |
| 28 | BFA_MODULE(lps); |
| 29 | BFA_MODULE(fcport); |
| 30 | BFA_MODULE(rport); |
| 31 | BFA_MODULE(uf); |
| 32 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 33 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 34 | * 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 Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 45 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 46 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 47 | * 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 Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 57 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 58 | * BFA port state machine events |
| 59 | */ |
| 60 | enum 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 */ |
Krishna Gudipati | e353546 | 2012-09-21 17:26:07 -0700 | [diff] [blame] | 70 | BFA_FCPORT_SM_DPORTENABLE = 10, /* enable dport */ |
| 71 | BFA_FCPORT_SM_DPORTDISABLE = 11,/* disable dport */ |
Krishna Gudipati | 04ea657 | 2012-09-21 17:26:18 -0700 | [diff] [blame^] | 72 | BFA_FCPORT_SM_FAA_MISCONFIG = 12, /* FAA misconfiguratin */ |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 73 | }; |
| 74 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 75 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 76 | * BFA port link notification state machine events |
| 77 | */ |
| 78 | |
| 79 | enum bfa_fcport_ln_sm_event { |
| 80 | BFA_FCPORT_LN_SM_LINKUP = 1, /* linkup event */ |
| 81 | BFA_FCPORT_LN_SM_LINKDOWN = 2, /* linkdown event */ |
| 82 | BFA_FCPORT_LN_SM_NOTIFICATION = 3 /* done notification */ |
| 83 | }; |
| 84 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 85 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 86 | * RPORT related definitions |
| 87 | */ |
| 88 | #define bfa_rport_offline_cb(__rp) do { \ |
| 89 | if ((__rp)->bfa->fcs) \ |
| 90 | bfa_cb_rport_offline((__rp)->rport_drv); \ |
| 91 | else { \ |
| 92 | bfa_cb_queue((__rp)->bfa, &(__rp)->hcb_qe, \ |
| 93 | __bfa_cb_rport_offline, (__rp)); \ |
| 94 | } \ |
| 95 | } while (0) |
| 96 | |
| 97 | #define bfa_rport_online_cb(__rp) do { \ |
| 98 | if ((__rp)->bfa->fcs) \ |
| 99 | bfa_cb_rport_online((__rp)->rport_drv); \ |
| 100 | else { \ |
| 101 | bfa_cb_queue((__rp)->bfa, &(__rp)->hcb_qe, \ |
| 102 | __bfa_cb_rport_online, (__rp)); \ |
| 103 | } \ |
| 104 | } while (0) |
| 105 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 106 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 107 | * forward declarations FCXP related functions |
| 108 | */ |
| 109 | static void __bfa_fcxp_send_cbfn(void *cbarg, bfa_boolean_t complete); |
| 110 | static void hal_fcxp_rx_plog(struct bfa_s *bfa, struct bfa_fcxp_s *fcxp, |
| 111 | struct bfi_fcxp_send_rsp_s *fcxp_rsp); |
| 112 | static void hal_fcxp_tx_plog(struct bfa_s *bfa, u32 reqlen, |
| 113 | struct bfa_fcxp_s *fcxp, struct fchs_s *fchs); |
| 114 | static void bfa_fcxp_qresume(void *cbarg); |
| 115 | static void bfa_fcxp_queue(struct bfa_fcxp_s *fcxp, |
| 116 | struct bfi_fcxp_send_req_s *send_req); |
| 117 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 118 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 119 | * forward declarations for LPS functions |
| 120 | */ |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 121 | static void bfa_lps_meminfo(struct bfa_iocfc_cfg_s *cfg, |
| 122 | struct bfa_meminfo_s *minfo, struct bfa_s *bfa); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 123 | static void bfa_lps_attach(struct bfa_s *bfa, void *bfad, |
| 124 | struct bfa_iocfc_cfg_s *cfg, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 125 | struct bfa_pcidev_s *pcidev); |
| 126 | static void bfa_lps_detach(struct bfa_s *bfa); |
| 127 | static void bfa_lps_start(struct bfa_s *bfa); |
| 128 | static void bfa_lps_stop(struct bfa_s *bfa); |
| 129 | static void bfa_lps_iocdisable(struct bfa_s *bfa); |
| 130 | static void bfa_lps_login_rsp(struct bfa_s *bfa, |
| 131 | struct bfi_lps_login_rsp_s *rsp); |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 132 | static void bfa_lps_no_res(struct bfa_lps_s *first_lps, u8 count); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 133 | static void bfa_lps_logout_rsp(struct bfa_s *bfa, |
| 134 | struct bfi_lps_logout_rsp_s *rsp); |
| 135 | static void bfa_lps_reqq_resume(void *lps_arg); |
| 136 | static void bfa_lps_free(struct bfa_lps_s *lps); |
| 137 | static void bfa_lps_send_login(struct bfa_lps_s *lps); |
| 138 | static void bfa_lps_send_logout(struct bfa_lps_s *lps); |
Krishna Gudipati | b704495 | 2010-12-13 16:17:42 -0800 | [diff] [blame] | 139 | static void bfa_lps_send_set_n2n_pid(struct bfa_lps_s *lps); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 140 | static void bfa_lps_login_comp(struct bfa_lps_s *lps); |
| 141 | static void bfa_lps_logout_comp(struct bfa_lps_s *lps); |
| 142 | static void bfa_lps_cvl_event(struct bfa_lps_s *lps); |
| 143 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 144 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 145 | * forward declaration for LPS state machine |
| 146 | */ |
| 147 | static void bfa_lps_sm_init(struct bfa_lps_s *lps, enum bfa_lps_event event); |
| 148 | static void bfa_lps_sm_login(struct bfa_lps_s *lps, enum bfa_lps_event event); |
| 149 | static void bfa_lps_sm_loginwait(struct bfa_lps_s *lps, enum bfa_lps_event |
| 150 | event); |
| 151 | static void bfa_lps_sm_online(struct bfa_lps_s *lps, enum bfa_lps_event event); |
Krishna Gudipati | b704495 | 2010-12-13 16:17:42 -0800 | [diff] [blame] | 152 | static void bfa_lps_sm_online_n2n_pid_wait(struct bfa_lps_s *lps, |
| 153 | enum bfa_lps_event event); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 154 | static void bfa_lps_sm_logout(struct bfa_lps_s *lps, enum bfa_lps_event event); |
| 155 | static void bfa_lps_sm_logowait(struct bfa_lps_s *lps, enum bfa_lps_event |
| 156 | event); |
| 157 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 158 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 159 | * forward declaration for FC Port functions |
| 160 | */ |
| 161 | static bfa_boolean_t bfa_fcport_send_enable(struct bfa_fcport_s *fcport); |
| 162 | static bfa_boolean_t bfa_fcport_send_disable(struct bfa_fcport_s *fcport); |
| 163 | static void bfa_fcport_update_linkinfo(struct bfa_fcport_s *fcport); |
| 164 | static void bfa_fcport_reset_linkinfo(struct bfa_fcport_s *fcport); |
| 165 | static void bfa_fcport_set_wwns(struct bfa_fcport_s *fcport); |
| 166 | static void __bfa_cb_fcport_event(void *cbarg, bfa_boolean_t complete); |
| 167 | static void bfa_fcport_scn(struct bfa_fcport_s *fcport, |
| 168 | enum bfa_port_linkstate event, bfa_boolean_t trunk); |
| 169 | static void bfa_fcport_queue_cb(struct bfa_fcport_ln_s *ln, |
| 170 | enum bfa_port_linkstate event); |
| 171 | static void __bfa_cb_fcport_stats_clr(void *cbarg, bfa_boolean_t complete); |
| 172 | static void bfa_fcport_stats_get_timeout(void *cbarg); |
| 173 | static void bfa_fcport_stats_clr_timeout(void *cbarg); |
| 174 | static void bfa_trunk_iocdisable(struct bfa_s *bfa); |
| 175 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 176 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 177 | * forward declaration for FC PORT state machine |
| 178 | */ |
| 179 | static void bfa_fcport_sm_uninit(struct bfa_fcport_s *fcport, |
| 180 | enum bfa_fcport_sm_event event); |
| 181 | static void bfa_fcport_sm_enabling_qwait(struct bfa_fcport_s *fcport, |
| 182 | enum bfa_fcport_sm_event event); |
| 183 | static void bfa_fcport_sm_enabling(struct bfa_fcport_s *fcport, |
| 184 | enum bfa_fcport_sm_event event); |
| 185 | static void bfa_fcport_sm_linkdown(struct bfa_fcport_s *fcport, |
| 186 | enum bfa_fcport_sm_event event); |
| 187 | static void bfa_fcport_sm_linkup(struct bfa_fcport_s *fcport, |
| 188 | enum bfa_fcport_sm_event event); |
| 189 | static void bfa_fcport_sm_disabling(struct bfa_fcport_s *fcport, |
| 190 | enum bfa_fcport_sm_event event); |
| 191 | static void bfa_fcport_sm_disabling_qwait(struct bfa_fcport_s *fcport, |
| 192 | enum bfa_fcport_sm_event event); |
| 193 | static void bfa_fcport_sm_toggling_qwait(struct bfa_fcport_s *fcport, |
| 194 | enum bfa_fcport_sm_event event); |
| 195 | static void bfa_fcport_sm_disabled(struct bfa_fcport_s *fcport, |
| 196 | enum bfa_fcport_sm_event event); |
| 197 | static void bfa_fcport_sm_stopped(struct bfa_fcport_s *fcport, |
| 198 | enum bfa_fcport_sm_event event); |
| 199 | static void bfa_fcport_sm_iocdown(struct bfa_fcport_s *fcport, |
| 200 | enum bfa_fcport_sm_event event); |
| 201 | static void bfa_fcport_sm_iocfail(struct bfa_fcport_s *fcport, |
| 202 | enum bfa_fcport_sm_event event); |
Krishna Gudipati | e353546 | 2012-09-21 17:26:07 -0700 | [diff] [blame] | 203 | static void bfa_fcport_sm_dport(struct bfa_fcport_s *fcport, |
| 204 | enum bfa_fcport_sm_event event); |
Krishna Gudipati | 04ea657 | 2012-09-21 17:26:18 -0700 | [diff] [blame^] | 205 | static void bfa_fcport_sm_faa_misconfig(struct bfa_fcport_s *fcport, |
| 206 | enum bfa_fcport_sm_event event); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 207 | |
| 208 | static void bfa_fcport_ln_sm_dn(struct bfa_fcport_ln_s *ln, |
| 209 | enum bfa_fcport_ln_sm_event event); |
| 210 | static void bfa_fcport_ln_sm_dn_nf(struct bfa_fcport_ln_s *ln, |
| 211 | enum bfa_fcport_ln_sm_event event); |
| 212 | static void bfa_fcport_ln_sm_dn_up_nf(struct bfa_fcport_ln_s *ln, |
| 213 | enum bfa_fcport_ln_sm_event event); |
| 214 | static void bfa_fcport_ln_sm_up(struct bfa_fcport_ln_s *ln, |
| 215 | enum bfa_fcport_ln_sm_event event); |
| 216 | static void bfa_fcport_ln_sm_up_nf(struct bfa_fcport_ln_s *ln, |
| 217 | enum bfa_fcport_ln_sm_event event); |
| 218 | static void bfa_fcport_ln_sm_up_dn_nf(struct bfa_fcport_ln_s *ln, |
| 219 | enum bfa_fcport_ln_sm_event event); |
| 220 | static void bfa_fcport_ln_sm_up_dn_up_nf(struct bfa_fcport_ln_s *ln, |
| 221 | enum bfa_fcport_ln_sm_event event); |
| 222 | |
| 223 | static struct bfa_sm_table_s hal_port_sm_table[] = { |
| 224 | {BFA_SM(bfa_fcport_sm_uninit), BFA_PORT_ST_UNINIT}, |
| 225 | {BFA_SM(bfa_fcport_sm_enabling_qwait), BFA_PORT_ST_ENABLING_QWAIT}, |
| 226 | {BFA_SM(bfa_fcport_sm_enabling), BFA_PORT_ST_ENABLING}, |
| 227 | {BFA_SM(bfa_fcport_sm_linkdown), BFA_PORT_ST_LINKDOWN}, |
| 228 | {BFA_SM(bfa_fcport_sm_linkup), BFA_PORT_ST_LINKUP}, |
| 229 | {BFA_SM(bfa_fcport_sm_disabling_qwait), BFA_PORT_ST_DISABLING_QWAIT}, |
| 230 | {BFA_SM(bfa_fcport_sm_toggling_qwait), BFA_PORT_ST_TOGGLING_QWAIT}, |
| 231 | {BFA_SM(bfa_fcport_sm_disabling), BFA_PORT_ST_DISABLING}, |
| 232 | {BFA_SM(bfa_fcport_sm_disabled), BFA_PORT_ST_DISABLED}, |
| 233 | {BFA_SM(bfa_fcport_sm_stopped), BFA_PORT_ST_STOPPED}, |
| 234 | {BFA_SM(bfa_fcport_sm_iocdown), BFA_PORT_ST_IOCDOWN}, |
| 235 | {BFA_SM(bfa_fcport_sm_iocfail), BFA_PORT_ST_IOCDOWN}, |
Krishna Gudipati | e353546 | 2012-09-21 17:26:07 -0700 | [diff] [blame] | 236 | {BFA_SM(bfa_fcport_sm_dport), BFA_PORT_ST_DPORT}, |
Krishna Gudipati | 04ea657 | 2012-09-21 17:26:18 -0700 | [diff] [blame^] | 237 | {BFA_SM(bfa_fcport_sm_faa_misconfig), BFA_PORT_ST_FAA_MISCONFIG}, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 238 | }; |
| 239 | |
| 240 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 241 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 242 | * forward declaration for RPORT related functions |
| 243 | */ |
| 244 | static struct bfa_rport_s *bfa_rport_alloc(struct bfa_rport_mod_s *rp_mod); |
| 245 | static void bfa_rport_free(struct bfa_rport_s *rport); |
| 246 | static bfa_boolean_t bfa_rport_send_fwcreate(struct bfa_rport_s *rp); |
| 247 | static bfa_boolean_t bfa_rport_send_fwdelete(struct bfa_rport_s *rp); |
| 248 | static bfa_boolean_t bfa_rport_send_fwspeed(struct bfa_rport_s *rp); |
| 249 | static void __bfa_cb_rport_online(void *cbarg, |
| 250 | bfa_boolean_t complete); |
| 251 | static void __bfa_cb_rport_offline(void *cbarg, |
| 252 | bfa_boolean_t complete); |
| 253 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 254 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 255 | * forward declaration for RPORT state machine |
| 256 | */ |
| 257 | static void bfa_rport_sm_uninit(struct bfa_rport_s *rp, |
| 258 | enum bfa_rport_event event); |
| 259 | static void bfa_rport_sm_created(struct bfa_rport_s *rp, |
| 260 | enum bfa_rport_event event); |
| 261 | static void bfa_rport_sm_fwcreate(struct bfa_rport_s *rp, |
| 262 | enum bfa_rport_event event); |
| 263 | static void bfa_rport_sm_online(struct bfa_rport_s *rp, |
| 264 | enum bfa_rport_event event); |
| 265 | static void bfa_rport_sm_fwdelete(struct bfa_rport_s *rp, |
| 266 | enum bfa_rport_event event); |
| 267 | static void bfa_rport_sm_offline(struct bfa_rport_s *rp, |
| 268 | enum bfa_rport_event event); |
| 269 | static void bfa_rport_sm_deleting(struct bfa_rport_s *rp, |
| 270 | enum bfa_rport_event event); |
| 271 | static void bfa_rport_sm_offline_pending(struct bfa_rport_s *rp, |
| 272 | enum bfa_rport_event event); |
| 273 | static void bfa_rport_sm_delete_pending(struct bfa_rport_s *rp, |
| 274 | enum bfa_rport_event event); |
| 275 | static void bfa_rport_sm_iocdisable(struct bfa_rport_s *rp, |
| 276 | enum bfa_rport_event event); |
| 277 | static void bfa_rport_sm_fwcreate_qfull(struct bfa_rport_s *rp, |
| 278 | enum bfa_rport_event event); |
| 279 | static void bfa_rport_sm_fwdelete_qfull(struct bfa_rport_s *rp, |
| 280 | enum bfa_rport_event event); |
| 281 | static void bfa_rport_sm_deleting_qfull(struct bfa_rport_s *rp, |
| 282 | enum bfa_rport_event event); |
| 283 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 284 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 285 | * PLOG related definitions |
| 286 | */ |
| 287 | static int |
| 288 | plkd_validate_logrec(struct bfa_plog_rec_s *pl_rec) |
| 289 | { |
| 290 | if ((pl_rec->log_type != BFA_PL_LOG_TYPE_INT) && |
| 291 | (pl_rec->log_type != BFA_PL_LOG_TYPE_STRING)) |
| 292 | return 1; |
| 293 | |
| 294 | if ((pl_rec->log_type != BFA_PL_LOG_TYPE_INT) && |
| 295 | (pl_rec->log_num_ints > BFA_PL_INT_LOG_SZ)) |
| 296 | return 1; |
| 297 | |
| 298 | return 0; |
| 299 | } |
| 300 | |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 301 | static u64 |
| 302 | bfa_get_log_time(void) |
| 303 | { |
| 304 | u64 system_time = 0; |
| 305 | struct timeval tv; |
| 306 | do_gettimeofday(&tv); |
| 307 | |
| 308 | /* We are interested in seconds only. */ |
| 309 | system_time = tv.tv_sec; |
| 310 | return system_time; |
| 311 | } |
| 312 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 313 | static void |
| 314 | bfa_plog_add(struct bfa_plog_s *plog, struct bfa_plog_rec_s *pl_rec) |
| 315 | { |
| 316 | u16 tail; |
| 317 | struct bfa_plog_rec_s *pl_recp; |
| 318 | |
| 319 | if (plog->plog_enabled == 0) |
| 320 | return; |
| 321 | |
| 322 | if (plkd_validate_logrec(pl_rec)) { |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 323 | WARN_ON(1); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 324 | return; |
| 325 | } |
| 326 | |
| 327 | tail = plog->tail; |
| 328 | |
| 329 | pl_recp = &(plog->plog_recs[tail]); |
| 330 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 331 | memcpy(pl_recp, pl_rec, sizeof(struct bfa_plog_rec_s)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 332 | |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 333 | pl_recp->tv = bfa_get_log_time(); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 334 | BFA_PL_LOG_REC_INCR(plog->tail); |
| 335 | |
| 336 | if (plog->head == plog->tail) |
| 337 | BFA_PL_LOG_REC_INCR(plog->head); |
| 338 | } |
| 339 | |
| 340 | void |
| 341 | bfa_plog_init(struct bfa_plog_s *plog) |
| 342 | { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 343 | memset((char *)plog, 0, sizeof(struct bfa_plog_s)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 344 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 345 | memcpy(plog->plog_sig, BFA_PL_SIG_STR, BFA_PL_SIG_LEN); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 346 | plog->head = plog->tail = 0; |
| 347 | plog->plog_enabled = 1; |
| 348 | } |
| 349 | |
| 350 | void |
| 351 | bfa_plog_str(struct bfa_plog_s *plog, enum bfa_plog_mid mid, |
| 352 | enum bfa_plog_eid event, |
| 353 | u16 misc, char *log_str) |
| 354 | { |
| 355 | struct bfa_plog_rec_s lp; |
| 356 | |
| 357 | if (plog->plog_enabled) { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 358 | memset(&lp, 0, sizeof(struct bfa_plog_rec_s)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 359 | lp.mid = mid; |
| 360 | lp.eid = event; |
| 361 | lp.log_type = BFA_PL_LOG_TYPE_STRING; |
| 362 | lp.misc = misc; |
| 363 | strncpy(lp.log_entry.string_log, log_str, |
| 364 | BFA_PL_STRING_LOG_SZ - 1); |
| 365 | lp.log_entry.string_log[BFA_PL_STRING_LOG_SZ - 1] = '\0'; |
| 366 | bfa_plog_add(plog, &lp); |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | void |
| 371 | bfa_plog_intarr(struct bfa_plog_s *plog, enum bfa_plog_mid mid, |
| 372 | enum bfa_plog_eid event, |
| 373 | u16 misc, u32 *intarr, u32 num_ints) |
| 374 | { |
| 375 | struct bfa_plog_rec_s lp; |
| 376 | u32 i; |
| 377 | |
| 378 | if (num_ints > BFA_PL_INT_LOG_SZ) |
| 379 | num_ints = BFA_PL_INT_LOG_SZ; |
| 380 | |
| 381 | if (plog->plog_enabled) { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 382 | memset(&lp, 0, sizeof(struct bfa_plog_rec_s)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 383 | lp.mid = mid; |
| 384 | lp.eid = event; |
| 385 | lp.log_type = BFA_PL_LOG_TYPE_INT; |
| 386 | lp.misc = misc; |
| 387 | |
| 388 | for (i = 0; i < num_ints; i++) |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 389 | lp.log_entry.int_log[i] = intarr[i]; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 390 | |
| 391 | lp.log_num_ints = (u8) num_ints; |
| 392 | |
| 393 | bfa_plog_add(plog, &lp); |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | void |
| 398 | bfa_plog_fchdr(struct bfa_plog_s *plog, enum bfa_plog_mid mid, |
| 399 | enum bfa_plog_eid event, |
| 400 | u16 misc, struct fchs_s *fchdr) |
| 401 | { |
| 402 | struct bfa_plog_rec_s lp; |
| 403 | u32 *tmp_int = (u32 *) fchdr; |
| 404 | u32 ints[BFA_PL_INT_LOG_SZ]; |
| 405 | |
| 406 | if (plog->plog_enabled) { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 407 | memset(&lp, 0, sizeof(struct bfa_plog_rec_s)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 408 | |
| 409 | ints[0] = tmp_int[0]; |
| 410 | ints[1] = tmp_int[1]; |
| 411 | ints[2] = tmp_int[4]; |
| 412 | |
| 413 | bfa_plog_intarr(plog, mid, event, misc, ints, 3); |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | void |
| 418 | bfa_plog_fchdr_and_pl(struct bfa_plog_s *plog, enum bfa_plog_mid mid, |
| 419 | enum bfa_plog_eid event, u16 misc, struct fchs_s *fchdr, |
| 420 | u32 pld_w0) |
| 421 | { |
| 422 | struct bfa_plog_rec_s lp; |
| 423 | u32 *tmp_int = (u32 *) fchdr; |
| 424 | u32 ints[BFA_PL_INT_LOG_SZ]; |
| 425 | |
| 426 | if (plog->plog_enabled) { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 427 | memset(&lp, 0, sizeof(struct bfa_plog_rec_s)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 428 | |
| 429 | ints[0] = tmp_int[0]; |
| 430 | ints[1] = tmp_int[1]; |
| 431 | ints[2] = tmp_int[4]; |
| 432 | ints[3] = pld_w0; |
| 433 | |
| 434 | bfa_plog_intarr(plog, mid, event, misc, ints, 4); |
| 435 | } |
| 436 | } |
| 437 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 438 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 439 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 440 | * fcxp_pvt BFA FCXP private functions |
| 441 | */ |
| 442 | |
| 443 | static void |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 444 | claim_fcxps_mem(struct bfa_fcxp_mod_s *mod) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 445 | { |
| 446 | u16 i; |
| 447 | struct bfa_fcxp_s *fcxp; |
| 448 | |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 449 | fcxp = (struct bfa_fcxp_s *) bfa_mem_kva_curp(mod); |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 450 | memset(fcxp, 0, sizeof(struct bfa_fcxp_s) * mod->num_fcxps); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 451 | |
Krishna Gudipati | c3f1b12 | 2012-08-22 19:51:08 -0700 | [diff] [blame] | 452 | INIT_LIST_HEAD(&mod->fcxp_req_free_q); |
| 453 | INIT_LIST_HEAD(&mod->fcxp_rsp_free_q); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 454 | INIT_LIST_HEAD(&mod->fcxp_active_q); |
Krishna Gudipati | c3f1b12 | 2012-08-22 19:51:08 -0700 | [diff] [blame] | 455 | INIT_LIST_HEAD(&mod->fcxp_req_unused_q); |
| 456 | INIT_LIST_HEAD(&mod->fcxp_rsp_unused_q); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 457 | |
| 458 | mod->fcxp_list = fcxp; |
| 459 | |
| 460 | for (i = 0; i < mod->num_fcxps; i++) { |
| 461 | fcxp->fcxp_mod = mod; |
| 462 | fcxp->fcxp_tag = i; |
| 463 | |
Krishna Gudipati | c3f1b12 | 2012-08-22 19:51:08 -0700 | [diff] [blame] | 464 | if (i < (mod->num_fcxps / 2)) { |
| 465 | list_add_tail(&fcxp->qe, &mod->fcxp_req_free_q); |
| 466 | fcxp->req_rsp = BFA_TRUE; |
| 467 | } else { |
| 468 | list_add_tail(&fcxp->qe, &mod->fcxp_rsp_free_q); |
| 469 | fcxp->req_rsp = BFA_FALSE; |
| 470 | } |
| 471 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 472 | bfa_reqq_winit(&fcxp->reqq_wqe, bfa_fcxp_qresume, fcxp); |
| 473 | fcxp->reqq_waiting = BFA_FALSE; |
| 474 | |
| 475 | fcxp = fcxp + 1; |
| 476 | } |
| 477 | |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 478 | bfa_mem_kva_curp(mod) = (void *)fcxp; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | static void |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 482 | bfa_fcxp_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo, |
| 483 | struct bfa_s *bfa) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 484 | { |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 485 | struct bfa_fcxp_mod_s *fcxp_mod = BFA_FCXP_MOD(bfa); |
| 486 | struct bfa_mem_kva_s *fcxp_kva = BFA_MEM_FCXP_KVA(bfa); |
| 487 | struct bfa_mem_dma_s *seg_ptr; |
| 488 | u16 nsegs, idx, per_seg_fcxp; |
| 489 | u16 num_fcxps = cfg->fwcfg.num_fcxp_reqs; |
| 490 | u32 per_fcxp_sz; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 491 | |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 492 | if (num_fcxps == 0) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 493 | return; |
| 494 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 495 | if (cfg->drvcfg.min_cfg) |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 496 | per_fcxp_sz = 2 * BFA_FCXP_MAX_IBUF_SZ; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 497 | else |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 498 | per_fcxp_sz = BFA_FCXP_MAX_IBUF_SZ + BFA_FCXP_MAX_LBUF_SZ; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 499 | |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 500 | /* dma memory */ |
| 501 | nsegs = BFI_MEM_DMA_NSEGS(num_fcxps, per_fcxp_sz); |
| 502 | per_seg_fcxp = BFI_MEM_NREQS_SEG(per_fcxp_sz); |
| 503 | |
| 504 | bfa_mem_dma_seg_iter(fcxp_mod, seg_ptr, nsegs, idx) { |
| 505 | if (num_fcxps >= per_seg_fcxp) { |
| 506 | num_fcxps -= per_seg_fcxp; |
| 507 | bfa_mem_dma_setup(minfo, seg_ptr, |
| 508 | per_seg_fcxp * per_fcxp_sz); |
| 509 | } else |
| 510 | bfa_mem_dma_setup(minfo, seg_ptr, |
| 511 | num_fcxps * per_fcxp_sz); |
| 512 | } |
| 513 | |
| 514 | /* kva memory */ |
| 515 | bfa_mem_kva_setup(minfo, fcxp_kva, |
| 516 | cfg->fwcfg.num_fcxp_reqs * sizeof(struct bfa_fcxp_s)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | static void |
| 520 | bfa_fcxp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg, |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 521 | struct bfa_pcidev_s *pcidev) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 522 | { |
| 523 | struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa); |
| 524 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 525 | mod->bfa = bfa; |
| 526 | mod->num_fcxps = cfg->fwcfg.num_fcxp_reqs; |
| 527 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 528 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 529 | * Initialize FCXP request and response payload sizes. |
| 530 | */ |
| 531 | mod->req_pld_sz = mod->rsp_pld_sz = BFA_FCXP_MAX_IBUF_SZ; |
| 532 | if (!cfg->drvcfg.min_cfg) |
| 533 | mod->rsp_pld_sz = BFA_FCXP_MAX_LBUF_SZ; |
| 534 | |
Krishna Gudipati | c3f1b12 | 2012-08-22 19:51:08 -0700 | [diff] [blame] | 535 | INIT_LIST_HEAD(&mod->req_wait_q); |
| 536 | INIT_LIST_HEAD(&mod->rsp_wait_q); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 537 | |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 538 | claim_fcxps_mem(mod); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | static void |
| 542 | bfa_fcxp_detach(struct bfa_s *bfa) |
| 543 | { |
| 544 | } |
| 545 | |
| 546 | static void |
| 547 | bfa_fcxp_start(struct bfa_s *bfa) |
| 548 | { |
| 549 | } |
| 550 | |
| 551 | static void |
| 552 | bfa_fcxp_stop(struct bfa_s *bfa) |
| 553 | { |
| 554 | } |
| 555 | |
| 556 | static void |
| 557 | bfa_fcxp_iocdisable(struct bfa_s *bfa) |
| 558 | { |
| 559 | struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa); |
| 560 | struct bfa_fcxp_s *fcxp; |
| 561 | struct list_head *qe, *qen; |
| 562 | |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 563 | /* Enqueue unused fcxp resources to free_q */ |
Krishna Gudipati | c3f1b12 | 2012-08-22 19:51:08 -0700 | [diff] [blame] | 564 | list_splice_tail_init(&mod->fcxp_req_unused_q, &mod->fcxp_req_free_q); |
| 565 | list_splice_tail_init(&mod->fcxp_rsp_unused_q, &mod->fcxp_rsp_free_q); |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 566 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 567 | list_for_each_safe(qe, qen, &mod->fcxp_active_q) { |
| 568 | fcxp = (struct bfa_fcxp_s *) qe; |
| 569 | if (fcxp->caller == NULL) { |
| 570 | fcxp->send_cbfn(fcxp->caller, fcxp, fcxp->send_cbarg, |
| 571 | BFA_STATUS_IOC_FAILURE, 0, 0, NULL); |
| 572 | bfa_fcxp_free(fcxp); |
| 573 | } else { |
| 574 | fcxp->rsp_status = BFA_STATUS_IOC_FAILURE; |
| 575 | bfa_cb_queue(bfa, &fcxp->hcb_qe, |
| 576 | __bfa_fcxp_send_cbfn, fcxp); |
| 577 | } |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | static struct bfa_fcxp_s * |
Krishna Gudipati | c3f1b12 | 2012-08-22 19:51:08 -0700 | [diff] [blame] | 582 | bfa_fcxp_get(struct bfa_fcxp_mod_s *fm, bfa_boolean_t req) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 583 | { |
| 584 | struct bfa_fcxp_s *fcxp; |
| 585 | |
Krishna Gudipati | c3f1b12 | 2012-08-22 19:51:08 -0700 | [diff] [blame] | 586 | if (req) |
| 587 | bfa_q_deq(&fm->fcxp_req_free_q, &fcxp); |
| 588 | else |
| 589 | bfa_q_deq(&fm->fcxp_rsp_free_q, &fcxp); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 590 | |
| 591 | if (fcxp) |
| 592 | list_add_tail(&fcxp->qe, &fm->fcxp_active_q); |
| 593 | |
| 594 | return fcxp; |
| 595 | } |
| 596 | |
| 597 | static void |
| 598 | bfa_fcxp_init_reqrsp(struct bfa_fcxp_s *fcxp, |
| 599 | struct bfa_s *bfa, |
| 600 | u8 *use_ibuf, |
| 601 | u32 *nr_sgles, |
| 602 | bfa_fcxp_get_sgaddr_t *r_sga_cbfn, |
| 603 | bfa_fcxp_get_sglen_t *r_sglen_cbfn, |
| 604 | struct list_head *r_sgpg_q, |
| 605 | int n_sgles, |
| 606 | bfa_fcxp_get_sgaddr_t sga_cbfn, |
| 607 | bfa_fcxp_get_sglen_t sglen_cbfn) |
| 608 | { |
| 609 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 610 | WARN_ON(bfa == NULL); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 611 | |
| 612 | bfa_trc(bfa, fcxp->fcxp_tag); |
| 613 | |
| 614 | if (n_sgles == 0) { |
| 615 | *use_ibuf = 1; |
| 616 | } else { |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 617 | WARN_ON(*sga_cbfn == NULL); |
| 618 | WARN_ON(*sglen_cbfn == NULL); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 619 | |
| 620 | *use_ibuf = 0; |
| 621 | *r_sga_cbfn = sga_cbfn; |
| 622 | *r_sglen_cbfn = sglen_cbfn; |
| 623 | |
| 624 | *nr_sgles = n_sgles; |
| 625 | |
| 626 | /* |
| 627 | * alloc required sgpgs |
| 628 | */ |
| 629 | if (n_sgles > BFI_SGE_INLINE) |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 630 | WARN_ON(1); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | } |
| 634 | |
| 635 | static void |
| 636 | bfa_fcxp_init(struct bfa_fcxp_s *fcxp, |
| 637 | void *caller, struct bfa_s *bfa, int nreq_sgles, |
| 638 | int nrsp_sgles, bfa_fcxp_get_sgaddr_t req_sga_cbfn, |
| 639 | bfa_fcxp_get_sglen_t req_sglen_cbfn, |
| 640 | bfa_fcxp_get_sgaddr_t rsp_sga_cbfn, |
| 641 | bfa_fcxp_get_sglen_t rsp_sglen_cbfn) |
| 642 | { |
| 643 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 644 | WARN_ON(bfa == NULL); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 645 | |
| 646 | bfa_trc(bfa, fcxp->fcxp_tag); |
| 647 | |
| 648 | fcxp->caller = caller; |
| 649 | |
| 650 | bfa_fcxp_init_reqrsp(fcxp, bfa, |
| 651 | &fcxp->use_ireqbuf, &fcxp->nreq_sgles, &fcxp->req_sga_cbfn, |
| 652 | &fcxp->req_sglen_cbfn, &fcxp->req_sgpg_q, |
| 653 | nreq_sgles, req_sga_cbfn, req_sglen_cbfn); |
| 654 | |
| 655 | bfa_fcxp_init_reqrsp(fcxp, bfa, |
| 656 | &fcxp->use_irspbuf, &fcxp->nrsp_sgles, &fcxp->rsp_sga_cbfn, |
| 657 | &fcxp->rsp_sglen_cbfn, &fcxp->rsp_sgpg_q, |
| 658 | nrsp_sgles, rsp_sga_cbfn, rsp_sglen_cbfn); |
| 659 | |
| 660 | } |
| 661 | |
| 662 | static void |
| 663 | bfa_fcxp_put(struct bfa_fcxp_s *fcxp) |
| 664 | { |
| 665 | struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod; |
| 666 | struct bfa_fcxp_wqe_s *wqe; |
| 667 | |
Krishna Gudipati | c3f1b12 | 2012-08-22 19:51:08 -0700 | [diff] [blame] | 668 | if (fcxp->req_rsp) |
| 669 | bfa_q_deq(&mod->req_wait_q, &wqe); |
| 670 | else |
| 671 | bfa_q_deq(&mod->rsp_wait_q, &wqe); |
| 672 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 673 | if (wqe) { |
| 674 | bfa_trc(mod->bfa, fcxp->fcxp_tag); |
| 675 | |
| 676 | bfa_fcxp_init(fcxp, wqe->caller, wqe->bfa, wqe->nreq_sgles, |
| 677 | wqe->nrsp_sgles, wqe->req_sga_cbfn, |
| 678 | wqe->req_sglen_cbfn, wqe->rsp_sga_cbfn, |
| 679 | wqe->rsp_sglen_cbfn); |
| 680 | |
| 681 | wqe->alloc_cbfn(wqe->alloc_cbarg, fcxp); |
| 682 | return; |
| 683 | } |
| 684 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 685 | WARN_ON(!bfa_q_is_on_q(&mod->fcxp_active_q, fcxp)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 686 | list_del(&fcxp->qe); |
Krishna Gudipati | c3f1b12 | 2012-08-22 19:51:08 -0700 | [diff] [blame] | 687 | |
| 688 | if (fcxp->req_rsp) |
| 689 | list_add_tail(&fcxp->qe, &mod->fcxp_req_free_q); |
| 690 | else |
| 691 | list_add_tail(&fcxp->qe, &mod->fcxp_rsp_free_q); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | static void |
| 695 | bfa_fcxp_null_comp(void *bfad_fcxp, struct bfa_fcxp_s *fcxp, void *cbarg, |
| 696 | bfa_status_t req_status, u32 rsp_len, |
| 697 | u32 resid_len, struct fchs_s *rsp_fchs) |
| 698 | { |
| 699 | /* discarded fcxp completion */ |
| 700 | } |
| 701 | |
| 702 | static void |
| 703 | __bfa_fcxp_send_cbfn(void *cbarg, bfa_boolean_t complete) |
| 704 | { |
| 705 | struct bfa_fcxp_s *fcxp = cbarg; |
| 706 | |
| 707 | if (complete) { |
| 708 | fcxp->send_cbfn(fcxp->caller, fcxp, fcxp->send_cbarg, |
| 709 | fcxp->rsp_status, fcxp->rsp_len, |
| 710 | fcxp->residue_len, &fcxp->rsp_fchs); |
| 711 | } else { |
| 712 | bfa_fcxp_free(fcxp); |
| 713 | } |
| 714 | } |
| 715 | |
| 716 | static void |
| 717 | hal_fcxp_send_comp(struct bfa_s *bfa, struct bfi_fcxp_send_rsp_s *fcxp_rsp) |
| 718 | { |
| 719 | struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa); |
| 720 | struct bfa_fcxp_s *fcxp; |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 721 | u16 fcxp_tag = be16_to_cpu(fcxp_rsp->fcxp_tag); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 722 | |
| 723 | bfa_trc(bfa, fcxp_tag); |
| 724 | |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 725 | fcxp_rsp->rsp_len = be32_to_cpu(fcxp_rsp->rsp_len); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 726 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 727 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 728 | * @todo f/w should not set residue to non-0 when everything |
| 729 | * is received. |
| 730 | */ |
| 731 | if (fcxp_rsp->req_status == BFA_STATUS_OK) |
| 732 | fcxp_rsp->residue_len = 0; |
| 733 | else |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 734 | fcxp_rsp->residue_len = be32_to_cpu(fcxp_rsp->residue_len); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 735 | |
| 736 | fcxp = BFA_FCXP_FROM_TAG(mod, fcxp_tag); |
| 737 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 738 | WARN_ON(fcxp->send_cbfn == NULL); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 739 | |
| 740 | hal_fcxp_rx_plog(mod->bfa, fcxp, fcxp_rsp); |
| 741 | |
| 742 | if (fcxp->send_cbfn != NULL) { |
| 743 | bfa_trc(mod->bfa, (NULL == fcxp->caller)); |
| 744 | if (fcxp->caller == NULL) { |
| 745 | fcxp->send_cbfn(fcxp->caller, fcxp, fcxp->send_cbarg, |
| 746 | fcxp_rsp->req_status, fcxp_rsp->rsp_len, |
| 747 | fcxp_rsp->residue_len, &fcxp_rsp->fchs); |
| 748 | /* |
| 749 | * fcxp automatically freed on return from the callback |
| 750 | */ |
| 751 | bfa_fcxp_free(fcxp); |
| 752 | } else { |
| 753 | fcxp->rsp_status = fcxp_rsp->req_status; |
| 754 | fcxp->rsp_len = fcxp_rsp->rsp_len; |
| 755 | fcxp->residue_len = fcxp_rsp->residue_len; |
| 756 | fcxp->rsp_fchs = fcxp_rsp->fchs; |
| 757 | |
| 758 | bfa_cb_queue(bfa, &fcxp->hcb_qe, |
| 759 | __bfa_fcxp_send_cbfn, fcxp); |
| 760 | } |
| 761 | } else { |
| 762 | bfa_trc(bfa, (NULL == fcxp->send_cbfn)); |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | static void |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 767 | hal_fcxp_tx_plog(struct bfa_s *bfa, u32 reqlen, struct bfa_fcxp_s *fcxp, |
| 768 | struct fchs_s *fchs) |
| 769 | { |
| 770 | /* |
| 771 | * TODO: TX ox_id |
| 772 | */ |
| 773 | if (reqlen > 0) { |
| 774 | if (fcxp->use_ireqbuf) { |
| 775 | u32 pld_w0 = |
| 776 | *((u32 *) BFA_FCXP_REQ_PLD(fcxp)); |
| 777 | |
| 778 | bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_FCXP, |
| 779 | BFA_PL_EID_TX, |
| 780 | reqlen + sizeof(struct fchs_s), fchs, |
| 781 | pld_w0); |
| 782 | } else { |
| 783 | bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP, |
| 784 | BFA_PL_EID_TX, |
| 785 | reqlen + sizeof(struct fchs_s), |
| 786 | fchs); |
| 787 | } |
| 788 | } else { |
| 789 | bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP, BFA_PL_EID_TX, |
| 790 | reqlen + sizeof(struct fchs_s), fchs); |
| 791 | } |
| 792 | } |
| 793 | |
| 794 | static void |
| 795 | hal_fcxp_rx_plog(struct bfa_s *bfa, struct bfa_fcxp_s *fcxp, |
| 796 | struct bfi_fcxp_send_rsp_s *fcxp_rsp) |
| 797 | { |
| 798 | if (fcxp_rsp->rsp_len > 0) { |
| 799 | if (fcxp->use_irspbuf) { |
| 800 | u32 pld_w0 = |
| 801 | *((u32 *) BFA_FCXP_RSP_PLD(fcxp)); |
| 802 | |
| 803 | bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_FCXP, |
| 804 | BFA_PL_EID_RX, |
| 805 | (u16) fcxp_rsp->rsp_len, |
| 806 | &fcxp_rsp->fchs, pld_w0); |
| 807 | } else { |
| 808 | bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP, |
| 809 | BFA_PL_EID_RX, |
| 810 | (u16) fcxp_rsp->rsp_len, |
| 811 | &fcxp_rsp->fchs); |
| 812 | } |
| 813 | } else { |
| 814 | bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP, BFA_PL_EID_RX, |
| 815 | (u16) fcxp_rsp->rsp_len, &fcxp_rsp->fchs); |
| 816 | } |
| 817 | } |
| 818 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 819 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 820 | * Handler to resume sending fcxp when space in available in cpe queue. |
| 821 | */ |
| 822 | static void |
| 823 | bfa_fcxp_qresume(void *cbarg) |
| 824 | { |
| 825 | struct bfa_fcxp_s *fcxp = cbarg; |
| 826 | struct bfa_s *bfa = fcxp->fcxp_mod->bfa; |
| 827 | struct bfi_fcxp_send_req_s *send_req; |
| 828 | |
| 829 | fcxp->reqq_waiting = BFA_FALSE; |
| 830 | send_req = bfa_reqq_next(bfa, BFA_REQQ_FCXP); |
| 831 | bfa_fcxp_queue(fcxp, send_req); |
| 832 | } |
| 833 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 834 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 835 | * Queue fcxp send request to foimrware. |
| 836 | */ |
| 837 | static void |
| 838 | bfa_fcxp_queue(struct bfa_fcxp_s *fcxp, struct bfi_fcxp_send_req_s *send_req) |
| 839 | { |
| 840 | struct bfa_s *bfa = fcxp->fcxp_mod->bfa; |
| 841 | struct bfa_fcxp_req_info_s *reqi = &fcxp->req_info; |
| 842 | struct bfa_fcxp_rsp_info_s *rspi = &fcxp->rsp_info; |
| 843 | struct bfa_rport_s *rport = reqi->bfa_rport; |
| 844 | |
| 845 | bfi_h2i_set(send_req->mh, BFI_MC_FCXP, BFI_FCXP_H2I_SEND_REQ, |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 846 | bfa_fn_lpu(bfa)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 847 | |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 848 | send_req->fcxp_tag = cpu_to_be16(fcxp->fcxp_tag); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 849 | if (rport) { |
| 850 | send_req->rport_fw_hndl = rport->fw_handle; |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 851 | send_req->max_frmsz = cpu_to_be16(rport->rport_info.max_frmsz); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 852 | if (send_req->max_frmsz == 0) |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 853 | send_req->max_frmsz = cpu_to_be16(FC_MAX_PDUSZ); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 854 | } else { |
| 855 | send_req->rport_fw_hndl = 0; |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 856 | send_req->max_frmsz = cpu_to_be16(FC_MAX_PDUSZ); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 857 | } |
| 858 | |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 859 | send_req->vf_id = cpu_to_be16(reqi->vf_id); |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 860 | send_req->lp_fwtag = bfa_lps_get_fwtag(bfa, reqi->lp_tag); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 861 | send_req->class = reqi->class; |
| 862 | send_req->rsp_timeout = rspi->rsp_timeout; |
| 863 | send_req->cts = reqi->cts; |
| 864 | send_req->fchs = reqi->fchs; |
| 865 | |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 866 | send_req->req_len = cpu_to_be32(reqi->req_tot_len); |
| 867 | send_req->rsp_maxlen = cpu_to_be32(rspi->rsp_maxlen); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 868 | |
| 869 | /* |
| 870 | * setup req sgles |
| 871 | */ |
| 872 | if (fcxp->use_ireqbuf == 1) { |
Krishna Gudipati | 85ce928 | 2011-06-13 15:39:36 -0700 | [diff] [blame] | 873 | bfa_alen_set(&send_req->req_alen, reqi->req_tot_len, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 874 | BFA_FCXP_REQ_PLD_PA(fcxp)); |
| 875 | } else { |
| 876 | if (fcxp->nreq_sgles > 0) { |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 877 | WARN_ON(fcxp->nreq_sgles != 1); |
Krishna Gudipati | 85ce928 | 2011-06-13 15:39:36 -0700 | [diff] [blame] | 878 | bfa_alen_set(&send_req->req_alen, reqi->req_tot_len, |
| 879 | fcxp->req_sga_cbfn(fcxp->caller, 0)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 880 | } else { |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 881 | WARN_ON(reqi->req_tot_len != 0); |
Krishna Gudipati | 85ce928 | 2011-06-13 15:39:36 -0700 | [diff] [blame] | 882 | bfa_alen_set(&send_req->rsp_alen, 0, 0); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 883 | } |
| 884 | } |
| 885 | |
| 886 | /* |
| 887 | * setup rsp sgles |
| 888 | */ |
| 889 | if (fcxp->use_irspbuf == 1) { |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 890 | WARN_ON(rspi->rsp_maxlen > BFA_FCXP_MAX_LBUF_SZ); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 891 | |
Krishna Gudipati | 85ce928 | 2011-06-13 15:39:36 -0700 | [diff] [blame] | 892 | bfa_alen_set(&send_req->rsp_alen, rspi->rsp_maxlen, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 893 | BFA_FCXP_RSP_PLD_PA(fcxp)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 894 | } else { |
| 895 | if (fcxp->nrsp_sgles > 0) { |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 896 | WARN_ON(fcxp->nrsp_sgles != 1); |
Krishna Gudipati | 85ce928 | 2011-06-13 15:39:36 -0700 | [diff] [blame] | 897 | bfa_alen_set(&send_req->rsp_alen, rspi->rsp_maxlen, |
| 898 | fcxp->rsp_sga_cbfn(fcxp->caller, 0)); |
| 899 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 900 | } else { |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 901 | WARN_ON(rspi->rsp_maxlen != 0); |
Krishna Gudipati | 85ce928 | 2011-06-13 15:39:36 -0700 | [diff] [blame] | 902 | bfa_alen_set(&send_req->rsp_alen, 0, 0); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 903 | } |
| 904 | } |
| 905 | |
| 906 | hal_fcxp_tx_plog(bfa, reqi->req_tot_len, fcxp, &reqi->fchs); |
| 907 | |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 908 | bfa_reqq_produce(bfa, BFA_REQQ_FCXP, send_req->mh); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 909 | |
| 910 | bfa_trc(bfa, bfa_reqq_pi(bfa, BFA_REQQ_FCXP)); |
| 911 | bfa_trc(bfa, bfa_reqq_ci(bfa, BFA_REQQ_FCXP)); |
| 912 | } |
| 913 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 914 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 915 | * Allocate an FCXP instance to send a response or to send a request |
| 916 | * that has a response. Request/response buffers are allocated by caller. |
| 917 | * |
| 918 | * @param[in] bfa BFA bfa instance |
| 919 | * @param[in] nreq_sgles Number of SG elements required for request |
| 920 | * buffer. 0, if fcxp internal buffers are used. |
| 921 | * Use bfa_fcxp_get_reqbuf() to get the |
| 922 | * internal req buffer. |
| 923 | * @param[in] req_sgles SG elements describing request buffer. Will be |
| 924 | * copied in by BFA and hence can be freed on |
| 925 | * return from this function. |
| 926 | * @param[in] get_req_sga function ptr to be called to get a request SG |
| 927 | * Address (given the sge index). |
| 928 | * @param[in] get_req_sglen function ptr to be called to get a request SG |
| 929 | * len (given the sge index). |
| 930 | * @param[in] get_rsp_sga function ptr to be called to get a response SG |
| 931 | * Address (given the sge index). |
| 932 | * @param[in] get_rsp_sglen function ptr to be called to get a response SG |
| 933 | * len (given the sge index). |
Krishna Gudipati | c3f1b12 | 2012-08-22 19:51:08 -0700 | [diff] [blame] | 934 | * @param[in] req Allocated FCXP is used to send req or rsp? |
| 935 | * request - BFA_TRUE, response - BFA_FALSE |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 936 | * |
| 937 | * @return FCXP instance. NULL on failure. |
| 938 | */ |
| 939 | struct bfa_fcxp_s * |
Krishna Gudipati | c3f1b12 | 2012-08-22 19:51:08 -0700 | [diff] [blame] | 940 | bfa_fcxp_req_rsp_alloc(void *caller, struct bfa_s *bfa, int nreq_sgles, |
| 941 | int nrsp_sgles, bfa_fcxp_get_sgaddr_t req_sga_cbfn, |
| 942 | bfa_fcxp_get_sglen_t req_sglen_cbfn, |
| 943 | bfa_fcxp_get_sgaddr_t rsp_sga_cbfn, |
| 944 | bfa_fcxp_get_sglen_t rsp_sglen_cbfn, bfa_boolean_t req) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 945 | { |
| 946 | struct bfa_fcxp_s *fcxp = NULL; |
| 947 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 948 | WARN_ON(bfa == NULL); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 949 | |
Krishna Gudipati | c3f1b12 | 2012-08-22 19:51:08 -0700 | [diff] [blame] | 950 | fcxp = bfa_fcxp_get(BFA_FCXP_MOD(bfa), req); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 951 | if (fcxp == NULL) |
| 952 | return NULL; |
| 953 | |
| 954 | bfa_trc(bfa, fcxp->fcxp_tag); |
| 955 | |
| 956 | bfa_fcxp_init(fcxp, caller, bfa, nreq_sgles, nrsp_sgles, req_sga_cbfn, |
| 957 | req_sglen_cbfn, rsp_sga_cbfn, rsp_sglen_cbfn); |
| 958 | |
| 959 | return fcxp; |
| 960 | } |
| 961 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 962 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 963 | * Get the internal request buffer pointer |
| 964 | * |
| 965 | * @param[in] fcxp BFA fcxp pointer |
| 966 | * |
| 967 | * @return pointer to the internal request buffer |
| 968 | */ |
| 969 | void * |
| 970 | bfa_fcxp_get_reqbuf(struct bfa_fcxp_s *fcxp) |
| 971 | { |
| 972 | struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod; |
| 973 | void *reqbuf; |
| 974 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 975 | WARN_ON(fcxp->use_ireqbuf != 1); |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 976 | reqbuf = bfa_mem_get_dmabuf_kva(mod, fcxp->fcxp_tag, |
| 977 | mod->req_pld_sz + mod->rsp_pld_sz); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 978 | return reqbuf; |
| 979 | } |
| 980 | |
| 981 | u32 |
| 982 | bfa_fcxp_get_reqbufsz(struct bfa_fcxp_s *fcxp) |
| 983 | { |
| 984 | struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod; |
| 985 | |
| 986 | return mod->req_pld_sz; |
| 987 | } |
| 988 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 989 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 990 | * Get the internal response buffer pointer |
| 991 | * |
| 992 | * @param[in] fcxp BFA fcxp pointer |
| 993 | * |
| 994 | * @return pointer to the internal request buffer |
| 995 | */ |
| 996 | void * |
| 997 | bfa_fcxp_get_rspbuf(struct bfa_fcxp_s *fcxp) |
| 998 | { |
| 999 | struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod; |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 1000 | void *fcxp_buf; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1001 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 1002 | WARN_ON(fcxp->use_irspbuf != 1); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1003 | |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 1004 | fcxp_buf = bfa_mem_get_dmabuf_kva(mod, fcxp->fcxp_tag, |
| 1005 | mod->req_pld_sz + mod->rsp_pld_sz); |
| 1006 | |
| 1007 | /* fcxp_buf = req_buf + rsp_buf :- add req_buf_sz to get to rsp_buf */ |
| 1008 | return ((u8 *) fcxp_buf) + mod->req_pld_sz; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1009 | } |
| 1010 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1011 | /* |
Maggie Zhang | da99dcc | 2010-12-09 19:13:20 -0800 | [diff] [blame] | 1012 | * Free the BFA FCXP |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1013 | * |
| 1014 | * @param[in] fcxp BFA fcxp pointer |
| 1015 | * |
| 1016 | * @return void |
| 1017 | */ |
| 1018 | void |
| 1019 | bfa_fcxp_free(struct bfa_fcxp_s *fcxp) |
| 1020 | { |
| 1021 | struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod; |
| 1022 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 1023 | WARN_ON(fcxp == NULL); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1024 | bfa_trc(mod->bfa, fcxp->fcxp_tag); |
| 1025 | bfa_fcxp_put(fcxp); |
| 1026 | } |
| 1027 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1028 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1029 | * Send a FCXP request |
| 1030 | * |
| 1031 | * @param[in] fcxp BFA fcxp pointer |
| 1032 | * @param[in] rport BFA rport pointer. Could be left NULL for WKA rports |
| 1033 | * @param[in] vf_id virtual Fabric ID |
| 1034 | * @param[in] lp_tag lport tag |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1035 | * @param[in] cts use Continuous sequence |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1036 | * @param[in] cos fc Class of Service |
| 1037 | * @param[in] reqlen request length, does not include FCHS length |
| 1038 | * @param[in] fchs fc Header Pointer. The header content will be copied |
| 1039 | * in by BFA. |
| 1040 | * |
| 1041 | * @param[in] cbfn call back function to be called on receiving |
| 1042 | * the response |
| 1043 | * @param[in] cbarg arg for cbfn |
| 1044 | * @param[in] rsp_timeout |
| 1045 | * response timeout |
| 1046 | * |
| 1047 | * @return bfa_status_t |
| 1048 | */ |
| 1049 | void |
| 1050 | bfa_fcxp_send(struct bfa_fcxp_s *fcxp, struct bfa_rport_s *rport, |
| 1051 | u16 vf_id, u8 lp_tag, bfa_boolean_t cts, enum fc_cos cos, |
| 1052 | u32 reqlen, struct fchs_s *fchs, bfa_cb_fcxp_send_t cbfn, |
| 1053 | void *cbarg, u32 rsp_maxlen, u8 rsp_timeout) |
| 1054 | { |
| 1055 | struct bfa_s *bfa = fcxp->fcxp_mod->bfa; |
| 1056 | struct bfa_fcxp_req_info_s *reqi = &fcxp->req_info; |
| 1057 | struct bfa_fcxp_rsp_info_s *rspi = &fcxp->rsp_info; |
| 1058 | struct bfi_fcxp_send_req_s *send_req; |
| 1059 | |
| 1060 | bfa_trc(bfa, fcxp->fcxp_tag); |
| 1061 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1062 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1063 | * setup request/response info |
| 1064 | */ |
| 1065 | reqi->bfa_rport = rport; |
| 1066 | reqi->vf_id = vf_id; |
| 1067 | reqi->lp_tag = lp_tag; |
| 1068 | reqi->class = cos; |
| 1069 | rspi->rsp_timeout = rsp_timeout; |
| 1070 | reqi->cts = cts; |
| 1071 | reqi->fchs = *fchs; |
| 1072 | reqi->req_tot_len = reqlen; |
| 1073 | rspi->rsp_maxlen = rsp_maxlen; |
| 1074 | fcxp->send_cbfn = cbfn ? cbfn : bfa_fcxp_null_comp; |
| 1075 | fcxp->send_cbarg = cbarg; |
| 1076 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1077 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1078 | * If no room in CPE queue, wait for space in request queue |
| 1079 | */ |
| 1080 | send_req = bfa_reqq_next(bfa, BFA_REQQ_FCXP); |
| 1081 | if (!send_req) { |
| 1082 | bfa_trc(bfa, fcxp->fcxp_tag); |
| 1083 | fcxp->reqq_waiting = BFA_TRUE; |
| 1084 | bfa_reqq_wait(bfa, BFA_REQQ_FCXP, &fcxp->reqq_wqe); |
| 1085 | return; |
| 1086 | } |
| 1087 | |
| 1088 | bfa_fcxp_queue(fcxp, send_req); |
| 1089 | } |
| 1090 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1091 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1092 | * Abort a BFA FCXP |
| 1093 | * |
| 1094 | * @param[in] fcxp BFA fcxp pointer |
| 1095 | * |
| 1096 | * @return void |
| 1097 | */ |
| 1098 | bfa_status_t |
| 1099 | bfa_fcxp_abort(struct bfa_fcxp_s *fcxp) |
| 1100 | { |
| 1101 | bfa_trc(fcxp->fcxp_mod->bfa, fcxp->fcxp_tag); |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 1102 | WARN_ON(1); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1103 | return BFA_STATUS_OK; |
| 1104 | } |
| 1105 | |
| 1106 | void |
Krishna Gudipati | c3f1b12 | 2012-08-22 19:51:08 -0700 | [diff] [blame] | 1107 | bfa_fcxp_req_rsp_alloc_wait(struct bfa_s *bfa, struct bfa_fcxp_wqe_s *wqe, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1108 | bfa_fcxp_alloc_cbfn_t alloc_cbfn, void *alloc_cbarg, |
| 1109 | void *caller, int nreq_sgles, |
| 1110 | int nrsp_sgles, bfa_fcxp_get_sgaddr_t req_sga_cbfn, |
| 1111 | bfa_fcxp_get_sglen_t req_sglen_cbfn, |
| 1112 | bfa_fcxp_get_sgaddr_t rsp_sga_cbfn, |
Krishna Gudipati | c3f1b12 | 2012-08-22 19:51:08 -0700 | [diff] [blame] | 1113 | bfa_fcxp_get_sglen_t rsp_sglen_cbfn, bfa_boolean_t req) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1114 | { |
| 1115 | struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa); |
| 1116 | |
Krishna Gudipati | c3f1b12 | 2012-08-22 19:51:08 -0700 | [diff] [blame] | 1117 | if (req) |
| 1118 | WARN_ON(!list_empty(&mod->fcxp_req_free_q)); |
| 1119 | else |
| 1120 | WARN_ON(!list_empty(&mod->fcxp_rsp_free_q)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1121 | |
| 1122 | wqe->alloc_cbfn = alloc_cbfn; |
| 1123 | wqe->alloc_cbarg = alloc_cbarg; |
| 1124 | wqe->caller = caller; |
| 1125 | wqe->bfa = bfa; |
| 1126 | wqe->nreq_sgles = nreq_sgles; |
| 1127 | wqe->nrsp_sgles = nrsp_sgles; |
| 1128 | wqe->req_sga_cbfn = req_sga_cbfn; |
| 1129 | wqe->req_sglen_cbfn = req_sglen_cbfn; |
| 1130 | wqe->rsp_sga_cbfn = rsp_sga_cbfn; |
| 1131 | wqe->rsp_sglen_cbfn = rsp_sglen_cbfn; |
| 1132 | |
Krishna Gudipati | c3f1b12 | 2012-08-22 19:51:08 -0700 | [diff] [blame] | 1133 | if (req) |
| 1134 | list_add_tail(&wqe->qe, &mod->req_wait_q); |
| 1135 | else |
| 1136 | list_add_tail(&wqe->qe, &mod->rsp_wait_q); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | void |
| 1140 | bfa_fcxp_walloc_cancel(struct bfa_s *bfa, struct bfa_fcxp_wqe_s *wqe) |
| 1141 | { |
| 1142 | struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa); |
| 1143 | |
Krishna Gudipati | c3f1b12 | 2012-08-22 19:51:08 -0700 | [diff] [blame] | 1144 | WARN_ON(!bfa_q_is_on_q(&mod->req_wait_q, wqe) || |
| 1145 | !bfa_q_is_on_q(&mod->rsp_wait_q, wqe)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1146 | list_del(&wqe->qe); |
| 1147 | } |
| 1148 | |
| 1149 | void |
| 1150 | bfa_fcxp_discard(struct bfa_fcxp_s *fcxp) |
| 1151 | { |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1152 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1153 | * If waiting for room in request queue, cancel reqq wait |
| 1154 | * and free fcxp. |
| 1155 | */ |
| 1156 | if (fcxp->reqq_waiting) { |
| 1157 | fcxp->reqq_waiting = BFA_FALSE; |
| 1158 | bfa_reqq_wcancel(&fcxp->reqq_wqe); |
| 1159 | bfa_fcxp_free(fcxp); |
| 1160 | return; |
| 1161 | } |
| 1162 | |
| 1163 | fcxp->send_cbfn = bfa_fcxp_null_comp; |
| 1164 | } |
| 1165 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1166 | void |
| 1167 | bfa_fcxp_isr(struct bfa_s *bfa, struct bfi_msg_s *msg) |
| 1168 | { |
| 1169 | switch (msg->mhdr.msg_id) { |
| 1170 | case BFI_FCXP_I2H_SEND_RSP: |
| 1171 | hal_fcxp_send_comp(bfa, (struct bfi_fcxp_send_rsp_s *) msg); |
| 1172 | break; |
| 1173 | |
| 1174 | default: |
| 1175 | bfa_trc(bfa, msg->mhdr.msg_id); |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 1176 | WARN_ON(1); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1177 | } |
| 1178 | } |
| 1179 | |
| 1180 | u32 |
| 1181 | bfa_fcxp_get_maxrsp(struct bfa_s *bfa) |
| 1182 | { |
| 1183 | struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa); |
| 1184 | |
| 1185 | return mod->rsp_pld_sz; |
| 1186 | } |
| 1187 | |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 1188 | void |
| 1189 | bfa_fcxp_res_recfg(struct bfa_s *bfa, u16 num_fcxp_fw) |
| 1190 | { |
| 1191 | struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa); |
| 1192 | struct list_head *qe; |
| 1193 | int i; |
| 1194 | |
| 1195 | for (i = 0; i < (mod->num_fcxps - num_fcxp_fw); i++) { |
Krishna Gudipati | c3f1b12 | 2012-08-22 19:51:08 -0700 | [diff] [blame] | 1196 | if (i < ((mod->num_fcxps - num_fcxp_fw) / 2)) { |
| 1197 | bfa_q_deq_tail(&mod->fcxp_req_free_q, &qe); |
| 1198 | list_add_tail(qe, &mod->fcxp_req_unused_q); |
| 1199 | } else { |
| 1200 | bfa_q_deq_tail(&mod->fcxp_rsp_free_q, &qe); |
| 1201 | list_add_tail(qe, &mod->fcxp_rsp_unused_q); |
| 1202 | } |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 1203 | } |
| 1204 | } |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1205 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1206 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1207 | * BFA LPS state machine functions |
| 1208 | */ |
| 1209 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1210 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1211 | * Init state -- no login |
| 1212 | */ |
| 1213 | static void |
| 1214 | bfa_lps_sm_init(struct bfa_lps_s *lps, enum bfa_lps_event event) |
| 1215 | { |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 1216 | bfa_trc(lps->bfa, lps->bfa_tag); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1217 | bfa_trc(lps->bfa, event); |
| 1218 | |
| 1219 | switch (event) { |
| 1220 | case BFA_LPS_SM_LOGIN: |
| 1221 | if (bfa_reqq_full(lps->bfa, lps->reqq)) { |
| 1222 | bfa_sm_set_state(lps, bfa_lps_sm_loginwait); |
| 1223 | bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe); |
| 1224 | } else { |
| 1225 | bfa_sm_set_state(lps, bfa_lps_sm_login); |
| 1226 | bfa_lps_send_login(lps); |
| 1227 | } |
| 1228 | |
| 1229 | if (lps->fdisc) |
| 1230 | bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS, |
| 1231 | BFA_PL_EID_LOGIN, 0, "FDISC Request"); |
| 1232 | else |
| 1233 | bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS, |
| 1234 | BFA_PL_EID_LOGIN, 0, "FLOGI Request"); |
| 1235 | break; |
| 1236 | |
| 1237 | case BFA_LPS_SM_LOGOUT: |
| 1238 | bfa_lps_logout_comp(lps); |
| 1239 | break; |
| 1240 | |
| 1241 | case BFA_LPS_SM_DELETE: |
| 1242 | bfa_lps_free(lps); |
| 1243 | break; |
| 1244 | |
| 1245 | case BFA_LPS_SM_RX_CVL: |
| 1246 | case BFA_LPS_SM_OFFLINE: |
| 1247 | break; |
| 1248 | |
| 1249 | case BFA_LPS_SM_FWRSP: |
| 1250 | /* |
| 1251 | * Could happen when fabric detects loopback and discards |
| 1252 | * the lps request. Fw will eventually sent out the timeout |
| 1253 | * Just ignore |
| 1254 | */ |
| 1255 | break; |
Krishna Gudipati | bc0e2c2 | 2012-09-21 17:23:59 -0700 | [diff] [blame] | 1256 | case BFA_LPS_SM_SET_N2N_PID: |
| 1257 | /* |
| 1258 | * When topology is set to loop, bfa_lps_set_n2n_pid() sends |
| 1259 | * this event. Ignore this event. |
| 1260 | */ |
| 1261 | break; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1262 | |
| 1263 | default: |
| 1264 | bfa_sm_fault(lps->bfa, event); |
| 1265 | } |
| 1266 | } |
| 1267 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1268 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1269 | * login is in progress -- awaiting response from firmware |
| 1270 | */ |
| 1271 | static void |
| 1272 | bfa_lps_sm_login(struct bfa_lps_s *lps, enum bfa_lps_event event) |
| 1273 | { |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 1274 | bfa_trc(lps->bfa, lps->bfa_tag); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1275 | bfa_trc(lps->bfa, event); |
| 1276 | |
| 1277 | switch (event) { |
| 1278 | case BFA_LPS_SM_FWRSP: |
Krishna Gudipati | bc0e2c2 | 2012-09-21 17:23:59 -0700 | [diff] [blame] | 1279 | case BFA_LPS_SM_OFFLINE: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1280 | if (lps->status == BFA_STATUS_OK) { |
| 1281 | bfa_sm_set_state(lps, bfa_lps_sm_online); |
| 1282 | if (lps->fdisc) |
| 1283 | bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS, |
| 1284 | BFA_PL_EID_LOGIN, 0, "FDISC Accept"); |
| 1285 | else |
| 1286 | bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS, |
| 1287 | BFA_PL_EID_LOGIN, 0, "FLOGI Accept"); |
Krishna Gudipati | b704495 | 2010-12-13 16:17:42 -0800 | [diff] [blame] | 1288 | /* If N2N, send the assigned PID to FW */ |
| 1289 | bfa_trc(lps->bfa, lps->fport); |
| 1290 | bfa_trc(lps->bfa, lps->lp_pid); |
| 1291 | |
| 1292 | if (!lps->fport && lps->lp_pid) |
| 1293 | bfa_sm_send_event(lps, BFA_LPS_SM_SET_N2N_PID); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1294 | } else { |
| 1295 | bfa_sm_set_state(lps, bfa_lps_sm_init); |
| 1296 | if (lps->fdisc) |
| 1297 | bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS, |
| 1298 | BFA_PL_EID_LOGIN, 0, |
| 1299 | "FDISC Fail (RJT or timeout)"); |
| 1300 | else |
| 1301 | bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS, |
| 1302 | BFA_PL_EID_LOGIN, 0, |
| 1303 | "FLOGI Fail (RJT or timeout)"); |
| 1304 | } |
| 1305 | bfa_lps_login_comp(lps); |
| 1306 | break; |
| 1307 | |
Krishna Gudipati | be540a9 | 2011-06-13 15:53:04 -0700 | [diff] [blame] | 1308 | case BFA_LPS_SM_DELETE: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1309 | bfa_sm_set_state(lps, bfa_lps_sm_init); |
| 1310 | break; |
| 1311 | |
Krishna Gudipati | b704495 | 2010-12-13 16:17:42 -0800 | [diff] [blame] | 1312 | case BFA_LPS_SM_SET_N2N_PID: |
| 1313 | bfa_trc(lps->bfa, lps->fport); |
| 1314 | bfa_trc(lps->bfa, lps->lp_pid); |
| 1315 | break; |
| 1316 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1317 | default: |
| 1318 | bfa_sm_fault(lps->bfa, event); |
| 1319 | } |
| 1320 | } |
| 1321 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1322 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1323 | * login pending - awaiting space in request queue |
| 1324 | */ |
| 1325 | static void |
| 1326 | bfa_lps_sm_loginwait(struct bfa_lps_s *lps, enum bfa_lps_event event) |
| 1327 | { |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 1328 | bfa_trc(lps->bfa, lps->bfa_tag); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1329 | bfa_trc(lps->bfa, event); |
| 1330 | |
| 1331 | switch (event) { |
| 1332 | case BFA_LPS_SM_RESUME: |
| 1333 | bfa_sm_set_state(lps, bfa_lps_sm_login); |
Krishna Gudipati | ff179e0 | 2012-03-13 17:40:31 -0700 | [diff] [blame] | 1334 | bfa_lps_send_login(lps); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1335 | break; |
| 1336 | |
| 1337 | case BFA_LPS_SM_OFFLINE: |
Krishna Gudipati | be540a9 | 2011-06-13 15:53:04 -0700 | [diff] [blame] | 1338 | case BFA_LPS_SM_DELETE: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1339 | bfa_sm_set_state(lps, bfa_lps_sm_init); |
| 1340 | bfa_reqq_wcancel(&lps->wqe); |
| 1341 | break; |
| 1342 | |
| 1343 | case BFA_LPS_SM_RX_CVL: |
| 1344 | /* |
| 1345 | * Login was not even sent out; so when getting out |
| 1346 | * of this state, it will appear like a login retry |
| 1347 | * after Clear virtual link |
| 1348 | */ |
| 1349 | break; |
| 1350 | |
| 1351 | default: |
| 1352 | bfa_sm_fault(lps->bfa, event); |
| 1353 | } |
| 1354 | } |
| 1355 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1356 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1357 | * login complete |
| 1358 | */ |
| 1359 | static void |
| 1360 | bfa_lps_sm_online(struct bfa_lps_s *lps, enum bfa_lps_event event) |
| 1361 | { |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 1362 | bfa_trc(lps->bfa, lps->bfa_tag); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1363 | bfa_trc(lps->bfa, event); |
| 1364 | |
| 1365 | switch (event) { |
| 1366 | case BFA_LPS_SM_LOGOUT: |
| 1367 | if (bfa_reqq_full(lps->bfa, lps->reqq)) { |
| 1368 | bfa_sm_set_state(lps, bfa_lps_sm_logowait); |
| 1369 | bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe); |
| 1370 | } else { |
| 1371 | bfa_sm_set_state(lps, bfa_lps_sm_logout); |
| 1372 | bfa_lps_send_logout(lps); |
| 1373 | } |
| 1374 | bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS, |
| 1375 | BFA_PL_EID_LOGO, 0, "Logout"); |
| 1376 | break; |
| 1377 | |
| 1378 | case BFA_LPS_SM_RX_CVL: |
| 1379 | bfa_sm_set_state(lps, bfa_lps_sm_init); |
| 1380 | |
| 1381 | /* Let the vport module know about this event */ |
| 1382 | bfa_lps_cvl_event(lps); |
| 1383 | bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS, |
| 1384 | BFA_PL_EID_FIP_FCF_CVL, 0, "FCF Clear Virt. Link Rx"); |
| 1385 | break; |
| 1386 | |
Krishna Gudipati | b704495 | 2010-12-13 16:17:42 -0800 | [diff] [blame] | 1387 | case BFA_LPS_SM_SET_N2N_PID: |
| 1388 | if (bfa_reqq_full(lps->bfa, lps->reqq)) { |
| 1389 | bfa_sm_set_state(lps, bfa_lps_sm_online_n2n_pid_wait); |
| 1390 | bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe); |
| 1391 | } else |
| 1392 | bfa_lps_send_set_n2n_pid(lps); |
| 1393 | break; |
| 1394 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1395 | case BFA_LPS_SM_OFFLINE: |
| 1396 | case BFA_LPS_SM_DELETE: |
| 1397 | bfa_sm_set_state(lps, bfa_lps_sm_init); |
| 1398 | break; |
| 1399 | |
| 1400 | default: |
| 1401 | bfa_sm_fault(lps->bfa, event); |
| 1402 | } |
| 1403 | } |
| 1404 | |
Jing Huang | 8f4bfad | 2010-12-26 21:50:10 -0800 | [diff] [blame] | 1405 | /* |
Krishna Gudipati | b704495 | 2010-12-13 16:17:42 -0800 | [diff] [blame] | 1406 | * login complete |
| 1407 | */ |
| 1408 | static void |
| 1409 | bfa_lps_sm_online_n2n_pid_wait(struct bfa_lps_s *lps, enum bfa_lps_event event) |
| 1410 | { |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 1411 | bfa_trc(lps->bfa, lps->bfa_tag); |
Krishna Gudipati | b704495 | 2010-12-13 16:17:42 -0800 | [diff] [blame] | 1412 | bfa_trc(lps->bfa, event); |
| 1413 | |
| 1414 | switch (event) { |
| 1415 | case BFA_LPS_SM_RESUME: |
| 1416 | bfa_sm_set_state(lps, bfa_lps_sm_online); |
| 1417 | bfa_lps_send_set_n2n_pid(lps); |
| 1418 | break; |
| 1419 | |
| 1420 | case BFA_LPS_SM_LOGOUT: |
| 1421 | bfa_sm_set_state(lps, bfa_lps_sm_logowait); |
| 1422 | bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS, |
| 1423 | BFA_PL_EID_LOGO, 0, "Logout"); |
| 1424 | break; |
| 1425 | |
| 1426 | case BFA_LPS_SM_RX_CVL: |
| 1427 | bfa_sm_set_state(lps, bfa_lps_sm_init); |
| 1428 | bfa_reqq_wcancel(&lps->wqe); |
| 1429 | |
| 1430 | /* Let the vport module know about this event */ |
| 1431 | bfa_lps_cvl_event(lps); |
| 1432 | bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS, |
| 1433 | BFA_PL_EID_FIP_FCF_CVL, 0, "FCF Clear Virt. Link Rx"); |
| 1434 | break; |
| 1435 | |
| 1436 | case BFA_LPS_SM_OFFLINE: |
| 1437 | case BFA_LPS_SM_DELETE: |
| 1438 | bfa_sm_set_state(lps, bfa_lps_sm_init); |
| 1439 | bfa_reqq_wcancel(&lps->wqe); |
| 1440 | break; |
| 1441 | |
| 1442 | default: |
| 1443 | bfa_sm_fault(lps->bfa, event); |
| 1444 | } |
| 1445 | } |
| 1446 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1447 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1448 | * logout in progress - awaiting firmware response |
| 1449 | */ |
| 1450 | static void |
| 1451 | bfa_lps_sm_logout(struct bfa_lps_s *lps, enum bfa_lps_event event) |
| 1452 | { |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 1453 | bfa_trc(lps->bfa, lps->bfa_tag); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1454 | bfa_trc(lps->bfa, event); |
| 1455 | |
| 1456 | switch (event) { |
| 1457 | case BFA_LPS_SM_FWRSP: |
Krishna Gudipati | 881c1b3 | 2012-08-22 19:52:02 -0700 | [diff] [blame] | 1458 | case BFA_LPS_SM_OFFLINE: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1459 | bfa_sm_set_state(lps, bfa_lps_sm_init); |
| 1460 | bfa_lps_logout_comp(lps); |
| 1461 | break; |
| 1462 | |
Krishna Gudipati | be540a9 | 2011-06-13 15:53:04 -0700 | [diff] [blame] | 1463 | case BFA_LPS_SM_DELETE: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1464 | bfa_sm_set_state(lps, bfa_lps_sm_init); |
| 1465 | break; |
| 1466 | |
| 1467 | default: |
| 1468 | bfa_sm_fault(lps->bfa, event); |
| 1469 | } |
| 1470 | } |
| 1471 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1472 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1473 | * logout pending -- awaiting space in request queue |
| 1474 | */ |
| 1475 | static void |
| 1476 | bfa_lps_sm_logowait(struct bfa_lps_s *lps, enum bfa_lps_event event) |
| 1477 | { |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 1478 | bfa_trc(lps->bfa, lps->bfa_tag); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1479 | bfa_trc(lps->bfa, event); |
| 1480 | |
| 1481 | switch (event) { |
| 1482 | case BFA_LPS_SM_RESUME: |
| 1483 | bfa_sm_set_state(lps, bfa_lps_sm_logout); |
| 1484 | bfa_lps_send_logout(lps); |
| 1485 | break; |
| 1486 | |
| 1487 | case BFA_LPS_SM_OFFLINE: |
Krishna Gudipati | be540a9 | 2011-06-13 15:53:04 -0700 | [diff] [blame] | 1488 | case BFA_LPS_SM_DELETE: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1489 | bfa_sm_set_state(lps, bfa_lps_sm_init); |
| 1490 | bfa_reqq_wcancel(&lps->wqe); |
| 1491 | break; |
| 1492 | |
| 1493 | default: |
| 1494 | bfa_sm_fault(lps->bfa, event); |
| 1495 | } |
| 1496 | } |
| 1497 | |
| 1498 | |
| 1499 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1500 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1501 | * lps_pvt BFA LPS private functions |
| 1502 | */ |
| 1503 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1504 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1505 | * return memory requirement |
| 1506 | */ |
| 1507 | static void |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 1508 | bfa_lps_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo, |
| 1509 | struct bfa_s *bfa) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1510 | { |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 1511 | struct bfa_mem_kva_s *lps_kva = BFA_MEM_LPS_KVA(bfa); |
| 1512 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1513 | if (cfg->drvcfg.min_cfg) |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 1514 | bfa_mem_kva_setup(minfo, lps_kva, |
| 1515 | sizeof(struct bfa_lps_s) * BFA_LPS_MIN_LPORTS); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1516 | else |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 1517 | bfa_mem_kva_setup(minfo, lps_kva, |
| 1518 | sizeof(struct bfa_lps_s) * BFA_LPS_MAX_LPORTS); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1519 | } |
| 1520 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1521 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1522 | * bfa module attach at initialization time |
| 1523 | */ |
| 1524 | static void |
| 1525 | bfa_lps_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg, |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 1526 | struct bfa_pcidev_s *pcidev) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1527 | { |
| 1528 | struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa); |
| 1529 | struct bfa_lps_s *lps; |
| 1530 | int i; |
| 1531 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1532 | mod->num_lps = BFA_LPS_MAX_LPORTS; |
| 1533 | if (cfg->drvcfg.min_cfg) |
| 1534 | mod->num_lps = BFA_LPS_MIN_LPORTS; |
| 1535 | else |
| 1536 | mod->num_lps = BFA_LPS_MAX_LPORTS; |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 1537 | mod->lps_arr = lps = (struct bfa_lps_s *) bfa_mem_kva_curp(mod); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1538 | |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 1539 | bfa_mem_kva_curp(mod) += mod->num_lps * sizeof(struct bfa_lps_s); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1540 | |
| 1541 | INIT_LIST_HEAD(&mod->lps_free_q); |
| 1542 | INIT_LIST_HEAD(&mod->lps_active_q); |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 1543 | INIT_LIST_HEAD(&mod->lps_login_q); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1544 | |
| 1545 | for (i = 0; i < mod->num_lps; i++, lps++) { |
| 1546 | lps->bfa = bfa; |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 1547 | lps->bfa_tag = (u8) i; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1548 | lps->reqq = BFA_REQQ_LPS; |
| 1549 | bfa_reqq_winit(&lps->wqe, bfa_lps_reqq_resume, lps); |
| 1550 | list_add_tail(&lps->qe, &mod->lps_free_q); |
| 1551 | } |
| 1552 | } |
| 1553 | |
| 1554 | static void |
| 1555 | bfa_lps_detach(struct bfa_s *bfa) |
| 1556 | { |
| 1557 | } |
| 1558 | |
| 1559 | static void |
| 1560 | bfa_lps_start(struct bfa_s *bfa) |
| 1561 | { |
| 1562 | } |
| 1563 | |
| 1564 | static void |
| 1565 | bfa_lps_stop(struct bfa_s *bfa) |
| 1566 | { |
| 1567 | } |
| 1568 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1569 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1570 | * IOC in disabled state -- consider all lps offline |
| 1571 | */ |
| 1572 | static void |
| 1573 | bfa_lps_iocdisable(struct bfa_s *bfa) |
| 1574 | { |
| 1575 | struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa); |
| 1576 | struct bfa_lps_s *lps; |
| 1577 | struct list_head *qe, *qen; |
| 1578 | |
| 1579 | list_for_each_safe(qe, qen, &mod->lps_active_q) { |
| 1580 | lps = (struct bfa_lps_s *) qe; |
| 1581 | bfa_sm_send_event(lps, BFA_LPS_SM_OFFLINE); |
| 1582 | } |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 1583 | list_for_each_safe(qe, qen, &mod->lps_login_q) { |
| 1584 | lps = (struct bfa_lps_s *) qe; |
| 1585 | bfa_sm_send_event(lps, BFA_LPS_SM_OFFLINE); |
| 1586 | } |
| 1587 | list_splice_tail_init(&mod->lps_login_q, &mod->lps_active_q); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1588 | } |
| 1589 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1590 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1591 | * Firmware login response |
| 1592 | */ |
| 1593 | static void |
| 1594 | bfa_lps_login_rsp(struct bfa_s *bfa, struct bfi_lps_login_rsp_s *rsp) |
| 1595 | { |
| 1596 | struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa); |
| 1597 | struct bfa_lps_s *lps; |
| 1598 | |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 1599 | WARN_ON(rsp->bfa_tag >= mod->num_lps); |
| 1600 | lps = BFA_LPS_FROM_TAG(mod, rsp->bfa_tag); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1601 | |
| 1602 | lps->status = rsp->status; |
| 1603 | switch (rsp->status) { |
| 1604 | case BFA_STATUS_OK: |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 1605 | lps->fw_tag = rsp->fw_tag; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1606 | lps->fport = rsp->f_port; |
Krishna Gudipati | b704495 | 2010-12-13 16:17:42 -0800 | [diff] [blame] | 1607 | if (lps->fport) |
| 1608 | lps->lp_pid = rsp->lp_pid; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1609 | lps->npiv_en = rsp->npiv_en; |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 1610 | lps->pr_bbcred = be16_to_cpu(rsp->bb_credit); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1611 | lps->pr_pwwn = rsp->port_name; |
| 1612 | lps->pr_nwwn = rsp->node_name; |
| 1613 | lps->auth_req = rsp->auth_req; |
| 1614 | lps->lp_mac = rsp->lp_mac; |
| 1615 | lps->brcd_switch = rsp->brcd_switch; |
| 1616 | lps->fcf_mac = rsp->fcf_mac; |
Krishna Gudipati | be540a9 | 2011-06-13 15:53:04 -0700 | [diff] [blame] | 1617 | lps->pr_bbscn = rsp->bb_scn; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1618 | |
| 1619 | break; |
| 1620 | |
| 1621 | case BFA_STATUS_FABRIC_RJT: |
| 1622 | lps->lsrjt_rsn = rsp->lsrjt_rsn; |
| 1623 | lps->lsrjt_expl = rsp->lsrjt_expl; |
| 1624 | |
| 1625 | break; |
| 1626 | |
| 1627 | case BFA_STATUS_EPROTOCOL: |
| 1628 | lps->ext_status = rsp->ext_status; |
| 1629 | |
| 1630 | break; |
| 1631 | |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 1632 | case BFA_STATUS_VPORT_MAX: |
Krishna Gudipati | ff179e0 | 2012-03-13 17:40:31 -0700 | [diff] [blame] | 1633 | if (rsp->ext_status) |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 1634 | bfa_lps_no_res(lps, rsp->ext_status); |
| 1635 | break; |
| 1636 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1637 | default: |
| 1638 | /* Nothing to do with other status */ |
| 1639 | break; |
| 1640 | } |
| 1641 | |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 1642 | list_del(&lps->qe); |
| 1643 | list_add_tail(&lps->qe, &mod->lps_active_q); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1644 | bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP); |
| 1645 | } |
| 1646 | |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 1647 | static void |
| 1648 | bfa_lps_no_res(struct bfa_lps_s *first_lps, u8 count) |
| 1649 | { |
| 1650 | struct bfa_s *bfa = first_lps->bfa; |
| 1651 | struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa); |
| 1652 | struct list_head *qe, *qe_next; |
| 1653 | struct bfa_lps_s *lps; |
| 1654 | |
| 1655 | bfa_trc(bfa, count); |
| 1656 | |
| 1657 | qe = bfa_q_next(first_lps); |
| 1658 | |
| 1659 | while (count && qe) { |
| 1660 | qe_next = bfa_q_next(qe); |
| 1661 | lps = (struct bfa_lps_s *)qe; |
| 1662 | bfa_trc(bfa, lps->bfa_tag); |
| 1663 | lps->status = first_lps->status; |
| 1664 | list_del(&lps->qe); |
| 1665 | list_add_tail(&lps->qe, &mod->lps_active_q); |
| 1666 | bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP); |
| 1667 | qe = qe_next; |
| 1668 | count--; |
| 1669 | } |
| 1670 | } |
| 1671 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1672 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1673 | * Firmware logout response |
| 1674 | */ |
| 1675 | static void |
| 1676 | bfa_lps_logout_rsp(struct bfa_s *bfa, struct bfi_lps_logout_rsp_s *rsp) |
| 1677 | { |
| 1678 | struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa); |
| 1679 | struct bfa_lps_s *lps; |
| 1680 | |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 1681 | WARN_ON(rsp->bfa_tag >= mod->num_lps); |
| 1682 | lps = BFA_LPS_FROM_TAG(mod, rsp->bfa_tag); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1683 | |
| 1684 | bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP); |
| 1685 | } |
| 1686 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1687 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1688 | * Firmware received a Clear virtual link request (for FCoE) |
| 1689 | */ |
| 1690 | static void |
| 1691 | bfa_lps_rx_cvl_event(struct bfa_s *bfa, struct bfi_lps_cvl_event_s *cvl) |
| 1692 | { |
| 1693 | struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa); |
| 1694 | struct bfa_lps_s *lps; |
| 1695 | |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 1696 | lps = BFA_LPS_FROM_TAG(mod, cvl->bfa_tag); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1697 | |
| 1698 | bfa_sm_send_event(lps, BFA_LPS_SM_RX_CVL); |
| 1699 | } |
| 1700 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1701 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1702 | * Space is available in request queue, resume queueing request to firmware. |
| 1703 | */ |
| 1704 | static void |
| 1705 | bfa_lps_reqq_resume(void *lps_arg) |
| 1706 | { |
| 1707 | struct bfa_lps_s *lps = lps_arg; |
| 1708 | |
| 1709 | bfa_sm_send_event(lps, BFA_LPS_SM_RESUME); |
| 1710 | } |
| 1711 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1712 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1713 | * lps is freed -- triggered by vport delete |
| 1714 | */ |
| 1715 | static void |
| 1716 | bfa_lps_free(struct bfa_lps_s *lps) |
| 1717 | { |
| 1718 | struct bfa_lps_mod_s *mod = BFA_LPS_MOD(lps->bfa); |
| 1719 | |
| 1720 | lps->lp_pid = 0; |
| 1721 | list_del(&lps->qe); |
| 1722 | list_add_tail(&lps->qe, &mod->lps_free_q); |
| 1723 | } |
| 1724 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1725 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1726 | * send login request to firmware |
| 1727 | */ |
| 1728 | static void |
| 1729 | bfa_lps_send_login(struct bfa_lps_s *lps) |
| 1730 | { |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 1731 | struct bfa_lps_mod_s *mod = BFA_LPS_MOD(lps->bfa); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1732 | struct bfi_lps_login_req_s *m; |
| 1733 | |
| 1734 | m = bfa_reqq_next(lps->bfa, lps->reqq); |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 1735 | WARN_ON(!m); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1736 | |
| 1737 | bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_LOGIN_REQ, |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 1738 | bfa_fn_lpu(lps->bfa)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1739 | |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 1740 | m->bfa_tag = lps->bfa_tag; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1741 | m->alpa = lps->alpa; |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 1742 | m->pdu_size = cpu_to_be16(lps->pdusz); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1743 | m->pwwn = lps->pwwn; |
| 1744 | m->nwwn = lps->nwwn; |
| 1745 | m->fdisc = lps->fdisc; |
| 1746 | m->auth_en = lps->auth_en; |
Krishna Gudipati | be540a9 | 2011-06-13 15:53:04 -0700 | [diff] [blame] | 1747 | m->bb_scn = lps->bb_scn; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1748 | |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 1749 | bfa_reqq_produce(lps->bfa, lps->reqq, m->mh); |
| 1750 | list_del(&lps->qe); |
| 1751 | list_add_tail(&lps->qe, &mod->lps_login_q); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1752 | } |
| 1753 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1754 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1755 | * send logout request to firmware |
| 1756 | */ |
| 1757 | static void |
| 1758 | bfa_lps_send_logout(struct bfa_lps_s *lps) |
| 1759 | { |
| 1760 | struct bfi_lps_logout_req_s *m; |
| 1761 | |
| 1762 | m = bfa_reqq_next(lps->bfa, lps->reqq); |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 1763 | WARN_ON(!m); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1764 | |
| 1765 | bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_LOGOUT_REQ, |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 1766 | bfa_fn_lpu(lps->bfa)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1767 | |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 1768 | m->fw_tag = lps->fw_tag; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1769 | m->port_name = lps->pwwn; |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 1770 | bfa_reqq_produce(lps->bfa, lps->reqq, m->mh); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1771 | } |
| 1772 | |
Jing Huang | 8f4bfad | 2010-12-26 21:50:10 -0800 | [diff] [blame] | 1773 | /* |
Krishna Gudipati | b704495 | 2010-12-13 16:17:42 -0800 | [diff] [blame] | 1774 | * send n2n pid set request to firmware |
| 1775 | */ |
| 1776 | static void |
| 1777 | bfa_lps_send_set_n2n_pid(struct bfa_lps_s *lps) |
| 1778 | { |
| 1779 | struct bfi_lps_n2n_pid_req_s *m; |
| 1780 | |
| 1781 | m = bfa_reqq_next(lps->bfa, lps->reqq); |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 1782 | WARN_ON(!m); |
Krishna Gudipati | b704495 | 2010-12-13 16:17:42 -0800 | [diff] [blame] | 1783 | |
| 1784 | bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_N2N_PID_REQ, |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 1785 | bfa_fn_lpu(lps->bfa)); |
Krishna Gudipati | b704495 | 2010-12-13 16:17:42 -0800 | [diff] [blame] | 1786 | |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 1787 | m->fw_tag = lps->fw_tag; |
Krishna Gudipati | b704495 | 2010-12-13 16:17:42 -0800 | [diff] [blame] | 1788 | m->lp_pid = lps->lp_pid; |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 1789 | bfa_reqq_produce(lps->bfa, lps->reqq, m->mh); |
Krishna Gudipati | b704495 | 2010-12-13 16:17:42 -0800 | [diff] [blame] | 1790 | } |
| 1791 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1792 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1793 | * Indirect login completion handler for non-fcs |
| 1794 | */ |
| 1795 | static void |
| 1796 | bfa_lps_login_comp_cb(void *arg, bfa_boolean_t complete) |
| 1797 | { |
| 1798 | struct bfa_lps_s *lps = arg; |
| 1799 | |
| 1800 | if (!complete) |
| 1801 | return; |
| 1802 | |
| 1803 | if (lps->fdisc) |
| 1804 | bfa_cb_lps_fdisc_comp(lps->bfa->bfad, lps->uarg, lps->status); |
| 1805 | else |
| 1806 | bfa_cb_lps_flogi_comp(lps->bfa->bfad, lps->uarg, lps->status); |
| 1807 | } |
| 1808 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1809 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1810 | * Login completion handler -- direct call for fcs, queue for others |
| 1811 | */ |
| 1812 | static void |
| 1813 | bfa_lps_login_comp(struct bfa_lps_s *lps) |
| 1814 | { |
| 1815 | if (!lps->bfa->fcs) { |
| 1816 | bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_login_comp_cb, |
| 1817 | lps); |
| 1818 | return; |
| 1819 | } |
| 1820 | |
| 1821 | if (lps->fdisc) |
| 1822 | bfa_cb_lps_fdisc_comp(lps->bfa->bfad, lps->uarg, lps->status); |
| 1823 | else |
| 1824 | bfa_cb_lps_flogi_comp(lps->bfa->bfad, lps->uarg, lps->status); |
| 1825 | } |
| 1826 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1827 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1828 | * Indirect logout completion handler for non-fcs |
| 1829 | */ |
| 1830 | static void |
| 1831 | bfa_lps_logout_comp_cb(void *arg, bfa_boolean_t complete) |
| 1832 | { |
| 1833 | struct bfa_lps_s *lps = arg; |
| 1834 | |
| 1835 | if (!complete) |
| 1836 | return; |
| 1837 | |
| 1838 | if (lps->fdisc) |
| 1839 | bfa_cb_lps_fdisclogo_comp(lps->bfa->bfad, lps->uarg); |
Krishna Gudipati | 881c1b3 | 2012-08-22 19:52:02 -0700 | [diff] [blame] | 1840 | else |
| 1841 | bfa_cb_lps_flogo_comp(lps->bfa->bfad, lps->uarg); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1842 | } |
| 1843 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1844 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1845 | * Logout completion handler -- direct call for fcs, queue for others |
| 1846 | */ |
| 1847 | static void |
| 1848 | bfa_lps_logout_comp(struct bfa_lps_s *lps) |
| 1849 | { |
| 1850 | if (!lps->bfa->fcs) { |
| 1851 | bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_logout_comp_cb, |
| 1852 | lps); |
| 1853 | return; |
| 1854 | } |
| 1855 | if (lps->fdisc) |
| 1856 | bfa_cb_lps_fdisclogo_comp(lps->bfa->bfad, lps->uarg); |
| 1857 | } |
| 1858 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1859 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1860 | * Clear virtual link completion handler for non-fcs |
| 1861 | */ |
| 1862 | static void |
| 1863 | bfa_lps_cvl_event_cb(void *arg, bfa_boolean_t complete) |
| 1864 | { |
| 1865 | struct bfa_lps_s *lps = arg; |
| 1866 | |
| 1867 | if (!complete) |
| 1868 | return; |
| 1869 | |
| 1870 | /* Clear virtual link to base port will result in link down */ |
| 1871 | if (lps->fdisc) |
| 1872 | bfa_cb_lps_cvl_event(lps->bfa->bfad, lps->uarg); |
| 1873 | } |
| 1874 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1875 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1876 | * Received Clear virtual link event --direct call for fcs, |
| 1877 | * queue for others |
| 1878 | */ |
| 1879 | static void |
| 1880 | bfa_lps_cvl_event(struct bfa_lps_s *lps) |
| 1881 | { |
| 1882 | if (!lps->bfa->fcs) { |
| 1883 | bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_cvl_event_cb, |
| 1884 | lps); |
| 1885 | return; |
| 1886 | } |
| 1887 | |
| 1888 | /* Clear virtual link to base port will result in link down */ |
| 1889 | if (lps->fdisc) |
| 1890 | bfa_cb_lps_cvl_event(lps->bfa->bfad, lps->uarg); |
| 1891 | } |
| 1892 | |
| 1893 | |
| 1894 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1895 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1896 | * lps_public BFA LPS public functions |
| 1897 | */ |
| 1898 | |
| 1899 | u32 |
| 1900 | bfa_lps_get_max_vport(struct bfa_s *bfa) |
| 1901 | { |
| 1902 | if (bfa_ioc_devid(&bfa->ioc) == BFA_PCI_DEVICE_ID_CT) |
| 1903 | return BFA_LPS_MAX_VPORTS_SUPP_CT; |
| 1904 | else |
| 1905 | return BFA_LPS_MAX_VPORTS_SUPP_CB; |
| 1906 | } |
| 1907 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1908 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1909 | * Allocate a lport srvice tag. |
| 1910 | */ |
| 1911 | struct bfa_lps_s * |
| 1912 | bfa_lps_alloc(struct bfa_s *bfa) |
| 1913 | { |
| 1914 | struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa); |
| 1915 | struct bfa_lps_s *lps = NULL; |
| 1916 | |
| 1917 | bfa_q_deq(&mod->lps_free_q, &lps); |
| 1918 | |
| 1919 | if (lps == NULL) |
| 1920 | return NULL; |
| 1921 | |
| 1922 | list_add_tail(&lps->qe, &mod->lps_active_q); |
| 1923 | |
| 1924 | bfa_sm_set_state(lps, bfa_lps_sm_init); |
| 1925 | return lps; |
| 1926 | } |
| 1927 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1928 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1929 | * Free lport service tag. This can be called anytime after an alloc. |
| 1930 | * No need to wait for any pending login/logout completions. |
| 1931 | */ |
| 1932 | void |
| 1933 | bfa_lps_delete(struct bfa_lps_s *lps) |
| 1934 | { |
| 1935 | bfa_sm_send_event(lps, BFA_LPS_SM_DELETE); |
| 1936 | } |
| 1937 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1938 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1939 | * Initiate a lport login. |
| 1940 | */ |
| 1941 | void |
| 1942 | bfa_lps_flogi(struct bfa_lps_s *lps, void *uarg, u8 alpa, u16 pdusz, |
Krishna Gudipati | be540a9 | 2011-06-13 15:53:04 -0700 | [diff] [blame] | 1943 | wwn_t pwwn, wwn_t nwwn, bfa_boolean_t auth_en, uint8_t bb_scn) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1944 | { |
| 1945 | lps->uarg = uarg; |
| 1946 | lps->alpa = alpa; |
| 1947 | lps->pdusz = pdusz; |
| 1948 | lps->pwwn = pwwn; |
| 1949 | lps->nwwn = nwwn; |
| 1950 | lps->fdisc = BFA_FALSE; |
| 1951 | lps->auth_en = auth_en; |
Krishna Gudipati | be540a9 | 2011-06-13 15:53:04 -0700 | [diff] [blame] | 1952 | lps->bb_scn = bb_scn; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1953 | bfa_sm_send_event(lps, BFA_LPS_SM_LOGIN); |
| 1954 | } |
| 1955 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1956 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1957 | * Initiate a lport fdisc login. |
| 1958 | */ |
| 1959 | void |
| 1960 | bfa_lps_fdisc(struct bfa_lps_s *lps, void *uarg, u16 pdusz, wwn_t pwwn, |
| 1961 | wwn_t nwwn) |
| 1962 | { |
| 1963 | lps->uarg = uarg; |
| 1964 | lps->alpa = 0; |
| 1965 | lps->pdusz = pdusz; |
| 1966 | lps->pwwn = pwwn; |
| 1967 | lps->nwwn = nwwn; |
| 1968 | lps->fdisc = BFA_TRUE; |
| 1969 | lps->auth_en = BFA_FALSE; |
| 1970 | bfa_sm_send_event(lps, BFA_LPS_SM_LOGIN); |
| 1971 | } |
| 1972 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1973 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1974 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1975 | * Initiate a lport FDSIC logout. |
| 1976 | */ |
| 1977 | void |
| 1978 | bfa_lps_fdisclogo(struct bfa_lps_s *lps) |
| 1979 | { |
| 1980 | bfa_sm_send_event(lps, BFA_LPS_SM_LOGOUT); |
| 1981 | } |
| 1982 | |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 1983 | u8 |
| 1984 | bfa_lps_get_fwtag(struct bfa_s *bfa, u8 lp_tag) |
| 1985 | { |
| 1986 | struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa); |
| 1987 | |
| 1988 | return BFA_LPS_FROM_TAG(mod, lp_tag)->fw_tag; |
| 1989 | } |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1990 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1991 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1992 | * Return lport services tag given the pid |
| 1993 | */ |
| 1994 | u8 |
| 1995 | bfa_lps_get_tag_from_pid(struct bfa_s *bfa, u32 pid) |
| 1996 | { |
| 1997 | struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa); |
| 1998 | struct bfa_lps_s *lps; |
| 1999 | int i; |
| 2000 | |
| 2001 | for (i = 0, lps = mod->lps_arr; i < mod->num_lps; i++, lps++) { |
| 2002 | if (lps->lp_pid == pid) |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 2003 | return lps->bfa_tag; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2004 | } |
| 2005 | |
| 2006 | /* Return base port tag anyway */ |
| 2007 | return 0; |
| 2008 | } |
| 2009 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2010 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2011 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2012 | * return port id assigned to the base lport |
| 2013 | */ |
| 2014 | u32 |
| 2015 | bfa_lps_get_base_pid(struct bfa_s *bfa) |
| 2016 | { |
| 2017 | struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa); |
| 2018 | |
| 2019 | return BFA_LPS_FROM_TAG(mod, 0)->lp_pid; |
| 2020 | } |
| 2021 | |
Jing Huang | 8f4bfad | 2010-12-26 21:50:10 -0800 | [diff] [blame] | 2022 | /* |
Krishna Gudipati | b704495 | 2010-12-13 16:17:42 -0800 | [diff] [blame] | 2023 | * Set PID in case of n2n (which is assigned during PLOGI) |
| 2024 | */ |
| 2025 | void |
| 2026 | bfa_lps_set_n2n_pid(struct bfa_lps_s *lps, uint32_t n2n_pid) |
| 2027 | { |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 2028 | bfa_trc(lps->bfa, lps->bfa_tag); |
Krishna Gudipati | b704495 | 2010-12-13 16:17:42 -0800 | [diff] [blame] | 2029 | bfa_trc(lps->bfa, n2n_pid); |
| 2030 | |
| 2031 | lps->lp_pid = n2n_pid; |
| 2032 | bfa_sm_send_event(lps, BFA_LPS_SM_SET_N2N_PID); |
| 2033 | } |
| 2034 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2035 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2036 | * LPS firmware message class handler. |
| 2037 | */ |
| 2038 | void |
| 2039 | bfa_lps_isr(struct bfa_s *bfa, struct bfi_msg_s *m) |
| 2040 | { |
| 2041 | union bfi_lps_i2h_msg_u msg; |
| 2042 | |
| 2043 | bfa_trc(bfa, m->mhdr.msg_id); |
| 2044 | msg.msg = m; |
| 2045 | |
| 2046 | switch (m->mhdr.msg_id) { |
Krishna Gudipati | 43ffdf4 | 2011-06-13 15:46:21 -0700 | [diff] [blame] | 2047 | case BFI_LPS_I2H_LOGIN_RSP: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2048 | bfa_lps_login_rsp(bfa, msg.login_rsp); |
| 2049 | break; |
| 2050 | |
Krishna Gudipati | 43ffdf4 | 2011-06-13 15:46:21 -0700 | [diff] [blame] | 2051 | case BFI_LPS_I2H_LOGOUT_RSP: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2052 | bfa_lps_logout_rsp(bfa, msg.logout_rsp); |
| 2053 | break; |
| 2054 | |
Krishna Gudipati | 43ffdf4 | 2011-06-13 15:46:21 -0700 | [diff] [blame] | 2055 | case BFI_LPS_I2H_CVL_EVENT: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2056 | bfa_lps_rx_cvl_event(bfa, msg.cvl_event); |
| 2057 | break; |
| 2058 | |
| 2059 | default: |
| 2060 | bfa_trc(bfa, m->mhdr.msg_id); |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 2061 | WARN_ON(1); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2062 | } |
| 2063 | } |
| 2064 | |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 2065 | static void |
| 2066 | bfa_fcport_aen_post(struct bfa_fcport_s *fcport, enum bfa_port_aen_event event) |
| 2067 | { |
| 2068 | struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad; |
| 2069 | struct bfa_aen_entry_s *aen_entry; |
| 2070 | |
| 2071 | bfad_get_aen_entry(bfad, aen_entry); |
| 2072 | if (!aen_entry) |
| 2073 | return; |
| 2074 | |
| 2075 | aen_entry->aen_data.port.ioc_type = bfa_get_type(fcport->bfa); |
| 2076 | aen_entry->aen_data.port.pwwn = fcport->pwwn; |
| 2077 | |
| 2078 | /* Send the AEN notification */ |
| 2079 | bfad_im_post_vendor_event(aen_entry, bfad, ++fcport->bfa->bfa_aen_seq, |
| 2080 | BFA_AEN_CAT_PORT, event); |
| 2081 | } |
| 2082 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2083 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2084 | * FC PORT state machine functions |
| 2085 | */ |
| 2086 | static void |
| 2087 | bfa_fcport_sm_uninit(struct bfa_fcport_s *fcport, |
| 2088 | enum bfa_fcport_sm_event event) |
| 2089 | { |
| 2090 | bfa_trc(fcport->bfa, event); |
| 2091 | |
| 2092 | switch (event) { |
| 2093 | case BFA_FCPORT_SM_START: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2094 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2095 | * Start event after IOC is configured and BFA is started. |
| 2096 | */ |
Krishna Gudipati | f3a060c | 2010-12-13 16:16:50 -0800 | [diff] [blame] | 2097 | fcport->use_flash_cfg = BFA_TRUE; |
| 2098 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2099 | if (bfa_fcport_send_enable(fcport)) { |
| 2100 | bfa_trc(fcport->bfa, BFA_TRUE); |
| 2101 | bfa_sm_set_state(fcport, bfa_fcport_sm_enabling); |
| 2102 | } else { |
| 2103 | bfa_trc(fcport->bfa, BFA_FALSE); |
| 2104 | bfa_sm_set_state(fcport, |
| 2105 | bfa_fcport_sm_enabling_qwait); |
| 2106 | } |
| 2107 | break; |
| 2108 | |
| 2109 | case BFA_FCPORT_SM_ENABLE: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2110 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2111 | * Port is persistently configured to be in enabled state. Do |
| 2112 | * not change state. Port enabling is done when START event is |
| 2113 | * received. |
| 2114 | */ |
| 2115 | break; |
| 2116 | |
| 2117 | case BFA_FCPORT_SM_DISABLE: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2118 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2119 | * If a port is persistently configured to be disabled, the |
| 2120 | * first event will a port disable request. |
| 2121 | */ |
| 2122 | bfa_sm_set_state(fcport, bfa_fcport_sm_disabled); |
| 2123 | break; |
| 2124 | |
| 2125 | case BFA_FCPORT_SM_HWFAIL: |
| 2126 | bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown); |
| 2127 | break; |
| 2128 | |
| 2129 | default: |
| 2130 | bfa_sm_fault(fcport->bfa, event); |
| 2131 | } |
| 2132 | } |
| 2133 | |
| 2134 | static void |
| 2135 | bfa_fcport_sm_enabling_qwait(struct bfa_fcport_s *fcport, |
| 2136 | enum bfa_fcport_sm_event event) |
| 2137 | { |
| 2138 | char pwwn_buf[BFA_STRING_32]; |
| 2139 | struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad; |
| 2140 | bfa_trc(fcport->bfa, event); |
| 2141 | |
| 2142 | switch (event) { |
| 2143 | case BFA_FCPORT_SM_QRESUME: |
| 2144 | bfa_sm_set_state(fcport, bfa_fcport_sm_enabling); |
| 2145 | bfa_fcport_send_enable(fcport); |
| 2146 | break; |
| 2147 | |
| 2148 | case BFA_FCPORT_SM_STOP: |
| 2149 | bfa_reqq_wcancel(&fcport->reqq_wait); |
| 2150 | bfa_sm_set_state(fcport, bfa_fcport_sm_stopped); |
| 2151 | break; |
| 2152 | |
| 2153 | case BFA_FCPORT_SM_ENABLE: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2154 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2155 | * Already enable is in progress. |
| 2156 | */ |
| 2157 | break; |
| 2158 | |
| 2159 | case BFA_FCPORT_SM_DISABLE: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2160 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2161 | * Just send disable request to firmware when room becomes |
| 2162 | * available in request queue. |
| 2163 | */ |
| 2164 | bfa_sm_set_state(fcport, bfa_fcport_sm_disabled); |
| 2165 | bfa_reqq_wcancel(&fcport->reqq_wait); |
| 2166 | bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL, |
| 2167 | BFA_PL_EID_PORT_DISABLE, 0, "Port Disable"); |
| 2168 | wwn2str(pwwn_buf, fcport->pwwn); |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 2169 | BFA_LOG(KERN_INFO, bfad, bfa_log_level, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2170 | "Base port disabled: WWN = %s\n", pwwn_buf); |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 2171 | bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2172 | break; |
| 2173 | |
| 2174 | case BFA_FCPORT_SM_LINKUP: |
| 2175 | case BFA_FCPORT_SM_LINKDOWN: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2176 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2177 | * Possible to get link events when doing back-to-back |
| 2178 | * enable/disables. |
| 2179 | */ |
| 2180 | break; |
| 2181 | |
| 2182 | case BFA_FCPORT_SM_HWFAIL: |
| 2183 | bfa_reqq_wcancel(&fcport->reqq_wait); |
| 2184 | bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown); |
| 2185 | break; |
| 2186 | |
Krishna Gudipati | 04ea657 | 2012-09-21 17:26:18 -0700 | [diff] [blame^] | 2187 | case BFA_FCPORT_SM_FAA_MISCONFIG: |
| 2188 | bfa_fcport_reset_linkinfo(fcport); |
| 2189 | bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT); |
| 2190 | bfa_sm_set_state(fcport, bfa_fcport_sm_faa_misconfig); |
| 2191 | break; |
| 2192 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2193 | default: |
| 2194 | bfa_sm_fault(fcport->bfa, event); |
| 2195 | } |
| 2196 | } |
| 2197 | |
| 2198 | static void |
| 2199 | bfa_fcport_sm_enabling(struct bfa_fcport_s *fcport, |
| 2200 | enum bfa_fcport_sm_event event) |
| 2201 | { |
| 2202 | char pwwn_buf[BFA_STRING_32]; |
| 2203 | struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad; |
| 2204 | bfa_trc(fcport->bfa, event); |
| 2205 | |
| 2206 | switch (event) { |
| 2207 | case BFA_FCPORT_SM_FWRSP: |
| 2208 | case BFA_FCPORT_SM_LINKDOWN: |
| 2209 | bfa_sm_set_state(fcport, bfa_fcport_sm_linkdown); |
| 2210 | break; |
| 2211 | |
| 2212 | case BFA_FCPORT_SM_LINKUP: |
| 2213 | bfa_fcport_update_linkinfo(fcport); |
| 2214 | bfa_sm_set_state(fcport, bfa_fcport_sm_linkup); |
| 2215 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 2216 | WARN_ON(!fcport->event_cbfn); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2217 | bfa_fcport_scn(fcport, BFA_PORT_LINKUP, BFA_FALSE); |
| 2218 | break; |
| 2219 | |
| 2220 | case BFA_FCPORT_SM_ENABLE: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2221 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2222 | * Already being enabled. |
| 2223 | */ |
| 2224 | break; |
| 2225 | |
| 2226 | case BFA_FCPORT_SM_DISABLE: |
| 2227 | if (bfa_fcport_send_disable(fcport)) |
| 2228 | bfa_sm_set_state(fcport, bfa_fcport_sm_disabling); |
| 2229 | else |
| 2230 | bfa_sm_set_state(fcport, |
| 2231 | bfa_fcport_sm_disabling_qwait); |
| 2232 | |
| 2233 | bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL, |
| 2234 | BFA_PL_EID_PORT_DISABLE, 0, "Port Disable"); |
| 2235 | wwn2str(pwwn_buf, fcport->pwwn); |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 2236 | BFA_LOG(KERN_INFO, bfad, bfa_log_level, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2237 | "Base port disabled: WWN = %s\n", pwwn_buf); |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 2238 | bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2239 | break; |
| 2240 | |
| 2241 | case BFA_FCPORT_SM_STOP: |
| 2242 | bfa_sm_set_state(fcport, bfa_fcport_sm_stopped); |
| 2243 | break; |
| 2244 | |
| 2245 | case BFA_FCPORT_SM_HWFAIL: |
| 2246 | bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown); |
| 2247 | break; |
| 2248 | |
Krishna Gudipati | 04ea657 | 2012-09-21 17:26:18 -0700 | [diff] [blame^] | 2249 | case BFA_FCPORT_SM_FAA_MISCONFIG: |
| 2250 | bfa_fcport_reset_linkinfo(fcport); |
| 2251 | bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT); |
| 2252 | bfa_sm_set_state(fcport, bfa_fcport_sm_faa_misconfig); |
| 2253 | break; |
| 2254 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2255 | default: |
| 2256 | bfa_sm_fault(fcport->bfa, event); |
| 2257 | } |
| 2258 | } |
| 2259 | |
| 2260 | static void |
| 2261 | bfa_fcport_sm_linkdown(struct bfa_fcport_s *fcport, |
| 2262 | enum bfa_fcport_sm_event event) |
| 2263 | { |
| 2264 | struct bfi_fcport_event_s *pevent = fcport->event_arg.i2hmsg.event; |
| 2265 | char pwwn_buf[BFA_STRING_32]; |
| 2266 | struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad; |
| 2267 | |
| 2268 | bfa_trc(fcport->bfa, event); |
| 2269 | |
| 2270 | switch (event) { |
| 2271 | case BFA_FCPORT_SM_LINKUP: |
| 2272 | bfa_fcport_update_linkinfo(fcport); |
| 2273 | bfa_sm_set_state(fcport, bfa_fcport_sm_linkup); |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 2274 | WARN_ON(!fcport->event_cbfn); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2275 | bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL, |
| 2276 | BFA_PL_EID_PORT_ST_CHANGE, 0, "Port Linkup"); |
| 2277 | if (!bfa_ioc_get_fcmode(&fcport->bfa->ioc)) { |
| 2278 | |
| 2279 | bfa_trc(fcport->bfa, |
Krishna Gudipati | bc0e2c2 | 2012-09-21 17:23:59 -0700 | [diff] [blame] | 2280 | pevent->link_state.attr.vc_fcf.fcf.fipenabled); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2281 | bfa_trc(fcport->bfa, |
Krishna Gudipati | bc0e2c2 | 2012-09-21 17:23:59 -0700 | [diff] [blame] | 2282 | pevent->link_state.attr.vc_fcf.fcf.fipfailed); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2283 | |
Krishna Gudipati | bc0e2c2 | 2012-09-21 17:23:59 -0700 | [diff] [blame] | 2284 | if (pevent->link_state.attr.vc_fcf.fcf.fipfailed) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2285 | bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL, |
| 2286 | BFA_PL_EID_FIP_FCF_DISC, 0, |
| 2287 | "FIP FCF Discovery Failed"); |
| 2288 | else |
| 2289 | bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL, |
| 2290 | BFA_PL_EID_FIP_FCF_DISC, 0, |
| 2291 | "FIP FCF Discovered"); |
| 2292 | } |
| 2293 | |
| 2294 | bfa_fcport_scn(fcport, BFA_PORT_LINKUP, BFA_FALSE); |
| 2295 | wwn2str(pwwn_buf, fcport->pwwn); |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 2296 | BFA_LOG(KERN_INFO, bfad, bfa_log_level, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2297 | "Base port online: WWN = %s\n", pwwn_buf); |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 2298 | bfa_fcport_aen_post(fcport, BFA_PORT_AEN_ONLINE); |
Krishna Gudipati | 3ec4f2c | 2011-07-20 17:03:09 -0700 | [diff] [blame] | 2299 | |
| 2300 | /* If QoS is enabled and it is not online, send AEN */ |
| 2301 | if (fcport->cfg.qos_enabled && |
| 2302 | fcport->qos_attr.state != BFA_QOS_ONLINE) |
| 2303 | bfa_fcport_aen_post(fcport, BFA_PORT_AEN_QOS_NEG); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2304 | break; |
| 2305 | |
| 2306 | case BFA_FCPORT_SM_LINKDOWN: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2307 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2308 | * Possible to get link down event. |
| 2309 | */ |
| 2310 | break; |
| 2311 | |
| 2312 | case BFA_FCPORT_SM_ENABLE: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2313 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2314 | * Already enabled. |
| 2315 | */ |
| 2316 | break; |
| 2317 | |
| 2318 | case BFA_FCPORT_SM_DISABLE: |
| 2319 | if (bfa_fcport_send_disable(fcport)) |
| 2320 | bfa_sm_set_state(fcport, bfa_fcport_sm_disabling); |
| 2321 | else |
| 2322 | bfa_sm_set_state(fcport, |
| 2323 | bfa_fcport_sm_disabling_qwait); |
| 2324 | |
| 2325 | bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL, |
| 2326 | BFA_PL_EID_PORT_DISABLE, 0, "Port Disable"); |
| 2327 | wwn2str(pwwn_buf, fcport->pwwn); |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 2328 | BFA_LOG(KERN_INFO, bfad, bfa_log_level, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2329 | "Base port disabled: WWN = %s\n", pwwn_buf); |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 2330 | bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2331 | break; |
| 2332 | |
| 2333 | case BFA_FCPORT_SM_STOP: |
| 2334 | bfa_sm_set_state(fcport, bfa_fcport_sm_stopped); |
| 2335 | break; |
| 2336 | |
| 2337 | case BFA_FCPORT_SM_HWFAIL: |
| 2338 | bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown); |
| 2339 | break; |
| 2340 | |
Krishna Gudipati | 04ea657 | 2012-09-21 17:26:18 -0700 | [diff] [blame^] | 2341 | case BFA_FCPORT_SM_FAA_MISCONFIG: |
| 2342 | bfa_fcport_reset_linkinfo(fcport); |
| 2343 | bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT); |
| 2344 | bfa_sm_set_state(fcport, bfa_fcport_sm_faa_misconfig); |
| 2345 | break; |
| 2346 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2347 | default: |
| 2348 | bfa_sm_fault(fcport->bfa, event); |
| 2349 | } |
| 2350 | } |
| 2351 | |
| 2352 | static void |
| 2353 | bfa_fcport_sm_linkup(struct bfa_fcport_s *fcport, |
| 2354 | enum bfa_fcport_sm_event event) |
| 2355 | { |
| 2356 | char pwwn_buf[BFA_STRING_32]; |
| 2357 | struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad; |
| 2358 | |
| 2359 | bfa_trc(fcport->bfa, event); |
| 2360 | |
| 2361 | switch (event) { |
| 2362 | case BFA_FCPORT_SM_ENABLE: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2363 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2364 | * Already enabled. |
| 2365 | */ |
| 2366 | break; |
| 2367 | |
| 2368 | case BFA_FCPORT_SM_DISABLE: |
| 2369 | if (bfa_fcport_send_disable(fcport)) |
| 2370 | bfa_sm_set_state(fcport, bfa_fcport_sm_disabling); |
| 2371 | else |
| 2372 | bfa_sm_set_state(fcport, |
| 2373 | bfa_fcport_sm_disabling_qwait); |
| 2374 | |
| 2375 | bfa_fcport_reset_linkinfo(fcport); |
| 2376 | bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE); |
| 2377 | bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL, |
| 2378 | BFA_PL_EID_PORT_DISABLE, 0, "Port Disable"); |
| 2379 | wwn2str(pwwn_buf, fcport->pwwn); |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 2380 | BFA_LOG(KERN_INFO, bfad, bfa_log_level, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2381 | "Base port offline: WWN = %s\n", pwwn_buf); |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 2382 | bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE); |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 2383 | BFA_LOG(KERN_INFO, bfad, bfa_log_level, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2384 | "Base port disabled: WWN = %s\n", pwwn_buf); |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 2385 | bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2386 | break; |
| 2387 | |
| 2388 | case BFA_FCPORT_SM_LINKDOWN: |
| 2389 | bfa_sm_set_state(fcport, bfa_fcport_sm_linkdown); |
| 2390 | bfa_fcport_reset_linkinfo(fcport); |
| 2391 | bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE); |
| 2392 | bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL, |
| 2393 | BFA_PL_EID_PORT_ST_CHANGE, 0, "Port Linkdown"); |
| 2394 | wwn2str(pwwn_buf, fcport->pwwn); |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 2395 | if (BFA_PORT_IS_DISABLED(fcport->bfa)) { |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 2396 | BFA_LOG(KERN_INFO, bfad, bfa_log_level, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2397 | "Base port offline: WWN = %s\n", pwwn_buf); |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 2398 | bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE); |
| 2399 | } else { |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 2400 | BFA_LOG(KERN_ERR, bfad, bfa_log_level, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2401 | "Base port (WWN = %s) " |
| 2402 | "lost fabric connectivity\n", pwwn_buf); |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 2403 | bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT); |
| 2404 | } |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2405 | break; |
| 2406 | |
| 2407 | case BFA_FCPORT_SM_STOP: |
| 2408 | bfa_sm_set_state(fcport, bfa_fcport_sm_stopped); |
| 2409 | bfa_fcport_reset_linkinfo(fcport); |
| 2410 | wwn2str(pwwn_buf, fcport->pwwn); |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 2411 | if (BFA_PORT_IS_DISABLED(fcport->bfa)) { |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 2412 | BFA_LOG(KERN_INFO, bfad, bfa_log_level, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2413 | "Base port offline: WWN = %s\n", pwwn_buf); |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 2414 | bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE); |
| 2415 | } else { |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 2416 | BFA_LOG(KERN_ERR, bfad, bfa_log_level, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2417 | "Base port (WWN = %s) " |
| 2418 | "lost fabric connectivity\n", pwwn_buf); |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 2419 | bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT); |
| 2420 | } |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2421 | break; |
| 2422 | |
| 2423 | case BFA_FCPORT_SM_HWFAIL: |
| 2424 | bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown); |
| 2425 | bfa_fcport_reset_linkinfo(fcport); |
| 2426 | bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE); |
| 2427 | wwn2str(pwwn_buf, fcport->pwwn); |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 2428 | if (BFA_PORT_IS_DISABLED(fcport->bfa)) { |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 2429 | BFA_LOG(KERN_INFO, bfad, bfa_log_level, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2430 | "Base port offline: WWN = %s\n", pwwn_buf); |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 2431 | bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE); |
| 2432 | } else { |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 2433 | BFA_LOG(KERN_ERR, bfad, bfa_log_level, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2434 | "Base port (WWN = %s) " |
| 2435 | "lost fabric connectivity\n", pwwn_buf); |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 2436 | bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT); |
| 2437 | } |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2438 | break; |
| 2439 | |
Krishna Gudipati | 04ea657 | 2012-09-21 17:26:18 -0700 | [diff] [blame^] | 2440 | case BFA_FCPORT_SM_FAA_MISCONFIG: |
| 2441 | bfa_fcport_reset_linkinfo(fcport); |
| 2442 | bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT); |
| 2443 | bfa_sm_set_state(fcport, bfa_fcport_sm_faa_misconfig); |
| 2444 | break; |
| 2445 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2446 | default: |
| 2447 | bfa_sm_fault(fcport->bfa, event); |
| 2448 | } |
| 2449 | } |
| 2450 | |
| 2451 | static void |
| 2452 | bfa_fcport_sm_disabling_qwait(struct bfa_fcport_s *fcport, |
| 2453 | enum bfa_fcport_sm_event event) |
| 2454 | { |
| 2455 | bfa_trc(fcport->bfa, event); |
| 2456 | |
| 2457 | switch (event) { |
| 2458 | case BFA_FCPORT_SM_QRESUME: |
| 2459 | bfa_sm_set_state(fcport, bfa_fcport_sm_disabling); |
| 2460 | bfa_fcport_send_disable(fcport); |
| 2461 | break; |
| 2462 | |
| 2463 | case BFA_FCPORT_SM_STOP: |
| 2464 | bfa_sm_set_state(fcport, bfa_fcport_sm_stopped); |
| 2465 | bfa_reqq_wcancel(&fcport->reqq_wait); |
| 2466 | break; |
| 2467 | |
| 2468 | case BFA_FCPORT_SM_ENABLE: |
| 2469 | bfa_sm_set_state(fcport, bfa_fcport_sm_toggling_qwait); |
| 2470 | break; |
| 2471 | |
| 2472 | case BFA_FCPORT_SM_DISABLE: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2473 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2474 | * Already being disabled. |
| 2475 | */ |
| 2476 | break; |
| 2477 | |
| 2478 | case BFA_FCPORT_SM_LINKUP: |
| 2479 | case BFA_FCPORT_SM_LINKDOWN: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2480 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2481 | * Possible to get link events when doing back-to-back |
| 2482 | * enable/disables. |
| 2483 | */ |
| 2484 | break; |
| 2485 | |
| 2486 | case BFA_FCPORT_SM_HWFAIL: |
| 2487 | bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail); |
| 2488 | bfa_reqq_wcancel(&fcport->reqq_wait); |
| 2489 | break; |
| 2490 | |
Krishna Gudipati | 04ea657 | 2012-09-21 17:26:18 -0700 | [diff] [blame^] | 2491 | case BFA_FCPORT_SM_FAA_MISCONFIG: |
| 2492 | bfa_fcport_reset_linkinfo(fcport); |
| 2493 | bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT); |
| 2494 | bfa_sm_set_state(fcport, bfa_fcport_sm_faa_misconfig); |
| 2495 | break; |
| 2496 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2497 | default: |
| 2498 | bfa_sm_fault(fcport->bfa, event); |
| 2499 | } |
| 2500 | } |
| 2501 | |
| 2502 | static void |
| 2503 | bfa_fcport_sm_toggling_qwait(struct bfa_fcport_s *fcport, |
| 2504 | enum bfa_fcport_sm_event event) |
| 2505 | { |
| 2506 | bfa_trc(fcport->bfa, event); |
| 2507 | |
| 2508 | switch (event) { |
| 2509 | case BFA_FCPORT_SM_QRESUME: |
| 2510 | bfa_sm_set_state(fcport, bfa_fcport_sm_disabling); |
| 2511 | bfa_fcport_send_disable(fcport); |
| 2512 | if (bfa_fcport_send_enable(fcport)) |
| 2513 | bfa_sm_set_state(fcport, bfa_fcport_sm_enabling); |
| 2514 | else |
| 2515 | bfa_sm_set_state(fcport, |
| 2516 | bfa_fcport_sm_enabling_qwait); |
| 2517 | break; |
| 2518 | |
| 2519 | case BFA_FCPORT_SM_STOP: |
| 2520 | bfa_sm_set_state(fcport, bfa_fcport_sm_stopped); |
| 2521 | bfa_reqq_wcancel(&fcport->reqq_wait); |
| 2522 | break; |
| 2523 | |
| 2524 | case BFA_FCPORT_SM_ENABLE: |
| 2525 | break; |
| 2526 | |
| 2527 | case BFA_FCPORT_SM_DISABLE: |
| 2528 | bfa_sm_set_state(fcport, bfa_fcport_sm_disabling_qwait); |
| 2529 | break; |
| 2530 | |
| 2531 | case BFA_FCPORT_SM_LINKUP: |
| 2532 | case BFA_FCPORT_SM_LINKDOWN: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2533 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2534 | * Possible to get link events when doing back-to-back |
| 2535 | * enable/disables. |
| 2536 | */ |
| 2537 | break; |
| 2538 | |
| 2539 | case BFA_FCPORT_SM_HWFAIL: |
| 2540 | bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail); |
| 2541 | bfa_reqq_wcancel(&fcport->reqq_wait); |
| 2542 | break; |
| 2543 | |
| 2544 | default: |
| 2545 | bfa_sm_fault(fcport->bfa, event); |
| 2546 | } |
| 2547 | } |
| 2548 | |
| 2549 | static void |
| 2550 | bfa_fcport_sm_disabling(struct bfa_fcport_s *fcport, |
| 2551 | enum bfa_fcport_sm_event event) |
| 2552 | { |
| 2553 | char pwwn_buf[BFA_STRING_32]; |
| 2554 | struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad; |
| 2555 | bfa_trc(fcport->bfa, event); |
| 2556 | |
| 2557 | switch (event) { |
| 2558 | case BFA_FCPORT_SM_FWRSP: |
| 2559 | bfa_sm_set_state(fcport, bfa_fcport_sm_disabled); |
| 2560 | break; |
| 2561 | |
| 2562 | case BFA_FCPORT_SM_DISABLE: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2563 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2564 | * Already being disabled. |
| 2565 | */ |
| 2566 | break; |
| 2567 | |
| 2568 | case BFA_FCPORT_SM_ENABLE: |
| 2569 | if (bfa_fcport_send_enable(fcport)) |
| 2570 | bfa_sm_set_state(fcport, bfa_fcport_sm_enabling); |
| 2571 | else |
| 2572 | bfa_sm_set_state(fcport, |
| 2573 | bfa_fcport_sm_enabling_qwait); |
| 2574 | |
| 2575 | bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL, |
| 2576 | BFA_PL_EID_PORT_ENABLE, 0, "Port Enable"); |
| 2577 | wwn2str(pwwn_buf, fcport->pwwn); |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 2578 | BFA_LOG(KERN_INFO, bfad, bfa_log_level, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2579 | "Base port enabled: WWN = %s\n", pwwn_buf); |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 2580 | bfa_fcport_aen_post(fcport, BFA_PORT_AEN_ENABLE); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2581 | break; |
| 2582 | |
| 2583 | case BFA_FCPORT_SM_STOP: |
| 2584 | bfa_sm_set_state(fcport, bfa_fcport_sm_stopped); |
| 2585 | break; |
| 2586 | |
| 2587 | case BFA_FCPORT_SM_LINKUP: |
| 2588 | case BFA_FCPORT_SM_LINKDOWN: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2589 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2590 | * Possible to get link events when doing back-to-back |
| 2591 | * enable/disables. |
| 2592 | */ |
| 2593 | break; |
| 2594 | |
| 2595 | case BFA_FCPORT_SM_HWFAIL: |
| 2596 | bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail); |
| 2597 | break; |
| 2598 | |
| 2599 | default: |
| 2600 | bfa_sm_fault(fcport->bfa, event); |
| 2601 | } |
| 2602 | } |
| 2603 | |
| 2604 | static void |
| 2605 | bfa_fcport_sm_disabled(struct bfa_fcport_s *fcport, |
| 2606 | enum bfa_fcport_sm_event event) |
| 2607 | { |
| 2608 | char pwwn_buf[BFA_STRING_32]; |
| 2609 | struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad; |
| 2610 | bfa_trc(fcport->bfa, event); |
| 2611 | |
| 2612 | switch (event) { |
| 2613 | case BFA_FCPORT_SM_START: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2614 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2615 | * Ignore start event for a port that is disabled. |
| 2616 | */ |
| 2617 | break; |
| 2618 | |
| 2619 | case BFA_FCPORT_SM_STOP: |
| 2620 | bfa_sm_set_state(fcport, bfa_fcport_sm_stopped); |
| 2621 | break; |
| 2622 | |
| 2623 | case BFA_FCPORT_SM_ENABLE: |
| 2624 | if (bfa_fcport_send_enable(fcport)) |
| 2625 | bfa_sm_set_state(fcport, bfa_fcport_sm_enabling); |
| 2626 | else |
| 2627 | bfa_sm_set_state(fcport, |
| 2628 | bfa_fcport_sm_enabling_qwait); |
| 2629 | |
| 2630 | bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL, |
| 2631 | BFA_PL_EID_PORT_ENABLE, 0, "Port Enable"); |
| 2632 | wwn2str(pwwn_buf, fcport->pwwn); |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 2633 | BFA_LOG(KERN_INFO, bfad, bfa_log_level, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2634 | "Base port enabled: WWN = %s\n", pwwn_buf); |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 2635 | bfa_fcport_aen_post(fcport, BFA_PORT_AEN_ENABLE); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2636 | break; |
| 2637 | |
| 2638 | case BFA_FCPORT_SM_DISABLE: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2639 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2640 | * Already disabled. |
| 2641 | */ |
| 2642 | break; |
| 2643 | |
| 2644 | case BFA_FCPORT_SM_HWFAIL: |
| 2645 | bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail); |
| 2646 | break; |
| 2647 | |
Krishna Gudipati | e353546 | 2012-09-21 17:26:07 -0700 | [diff] [blame] | 2648 | case BFA_FCPORT_SM_DPORTENABLE: |
| 2649 | bfa_sm_set_state(fcport, bfa_fcport_sm_dport); |
| 2650 | break; |
| 2651 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2652 | default: |
| 2653 | bfa_sm_fault(fcport->bfa, event); |
| 2654 | } |
| 2655 | } |
| 2656 | |
| 2657 | static void |
| 2658 | bfa_fcport_sm_stopped(struct bfa_fcport_s *fcport, |
| 2659 | enum bfa_fcport_sm_event event) |
| 2660 | { |
| 2661 | bfa_trc(fcport->bfa, event); |
| 2662 | |
| 2663 | switch (event) { |
| 2664 | case BFA_FCPORT_SM_START: |
| 2665 | if (bfa_fcport_send_enable(fcport)) |
| 2666 | bfa_sm_set_state(fcport, bfa_fcport_sm_enabling); |
| 2667 | else |
| 2668 | bfa_sm_set_state(fcport, |
| 2669 | bfa_fcport_sm_enabling_qwait); |
| 2670 | break; |
| 2671 | |
| 2672 | default: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2673 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2674 | * Ignore all other events. |
| 2675 | */ |
| 2676 | ; |
| 2677 | } |
| 2678 | } |
| 2679 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2680 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2681 | * Port is enabled. IOC is down/failed. |
| 2682 | */ |
| 2683 | static void |
| 2684 | bfa_fcport_sm_iocdown(struct bfa_fcport_s *fcport, |
| 2685 | enum bfa_fcport_sm_event event) |
| 2686 | { |
| 2687 | bfa_trc(fcport->bfa, event); |
| 2688 | |
| 2689 | switch (event) { |
| 2690 | case BFA_FCPORT_SM_START: |
| 2691 | if (bfa_fcport_send_enable(fcport)) |
| 2692 | bfa_sm_set_state(fcport, bfa_fcport_sm_enabling); |
| 2693 | else |
| 2694 | bfa_sm_set_state(fcport, |
| 2695 | bfa_fcport_sm_enabling_qwait); |
| 2696 | break; |
| 2697 | |
| 2698 | default: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2699 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2700 | * Ignore all events. |
| 2701 | */ |
| 2702 | ; |
| 2703 | } |
| 2704 | } |
| 2705 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2706 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2707 | * Port is disabled. IOC is down/failed. |
| 2708 | */ |
| 2709 | static void |
| 2710 | bfa_fcport_sm_iocfail(struct bfa_fcport_s *fcport, |
| 2711 | enum bfa_fcport_sm_event event) |
| 2712 | { |
| 2713 | bfa_trc(fcport->bfa, event); |
| 2714 | |
| 2715 | switch (event) { |
| 2716 | case BFA_FCPORT_SM_START: |
| 2717 | bfa_sm_set_state(fcport, bfa_fcport_sm_disabled); |
| 2718 | break; |
| 2719 | |
| 2720 | case BFA_FCPORT_SM_ENABLE: |
| 2721 | bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown); |
| 2722 | break; |
| 2723 | |
| 2724 | default: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2725 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2726 | * Ignore all events. |
| 2727 | */ |
| 2728 | ; |
| 2729 | } |
| 2730 | } |
| 2731 | |
Krishna Gudipati | e353546 | 2012-09-21 17:26:07 -0700 | [diff] [blame] | 2732 | static void |
| 2733 | bfa_fcport_sm_dport(struct bfa_fcport_s *fcport, enum bfa_fcport_sm_event event) |
| 2734 | { |
| 2735 | bfa_trc(fcport->bfa, event); |
| 2736 | |
| 2737 | switch (event) { |
| 2738 | case BFA_FCPORT_SM_DPORTENABLE: |
| 2739 | case BFA_FCPORT_SM_DISABLE: |
| 2740 | case BFA_FCPORT_SM_ENABLE: |
| 2741 | case BFA_FCPORT_SM_START: |
| 2742 | /* |
| 2743 | * Ignore event for a port that is dport |
| 2744 | */ |
| 2745 | break; |
| 2746 | |
| 2747 | case BFA_FCPORT_SM_STOP: |
| 2748 | bfa_sm_set_state(fcport, bfa_fcport_sm_stopped); |
| 2749 | break; |
| 2750 | |
| 2751 | case BFA_FCPORT_SM_HWFAIL: |
| 2752 | bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail); |
| 2753 | break; |
| 2754 | |
| 2755 | case BFA_FCPORT_SM_DPORTDISABLE: |
| 2756 | bfa_sm_set_state(fcport, bfa_fcport_sm_disabled); |
| 2757 | break; |
| 2758 | |
| 2759 | default: |
| 2760 | bfa_sm_fault(fcport->bfa, event); |
| 2761 | } |
| 2762 | } |
| 2763 | |
Krishna Gudipati | 04ea657 | 2012-09-21 17:26:18 -0700 | [diff] [blame^] | 2764 | static void |
| 2765 | bfa_fcport_sm_faa_misconfig(struct bfa_fcport_s *fcport, |
| 2766 | enum bfa_fcport_sm_event event) |
| 2767 | { |
| 2768 | bfa_trc(fcport->bfa, event); |
| 2769 | |
| 2770 | switch (event) { |
| 2771 | case BFA_FCPORT_SM_DPORTENABLE: |
| 2772 | case BFA_FCPORT_SM_ENABLE: |
| 2773 | case BFA_FCPORT_SM_START: |
| 2774 | /* |
| 2775 | * Ignore event for a port as there is FAA misconfig |
| 2776 | */ |
| 2777 | break; |
| 2778 | |
| 2779 | case BFA_FCPORT_SM_DISABLE: |
| 2780 | if (bfa_fcport_send_disable(fcport)) |
| 2781 | bfa_sm_set_state(fcport, bfa_fcport_sm_disabling); |
| 2782 | else |
| 2783 | bfa_sm_set_state(fcport, bfa_fcport_sm_disabling_qwait); |
| 2784 | |
| 2785 | bfa_fcport_reset_linkinfo(fcport); |
| 2786 | bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE); |
| 2787 | bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL, |
| 2788 | BFA_PL_EID_PORT_DISABLE, 0, "Port Disable"); |
| 2789 | bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE); |
| 2790 | break; |
| 2791 | |
| 2792 | case BFA_FCPORT_SM_STOP: |
| 2793 | bfa_sm_set_state(fcport, bfa_fcport_sm_stopped); |
| 2794 | break; |
| 2795 | |
| 2796 | case BFA_FCPORT_SM_HWFAIL: |
| 2797 | bfa_fcport_reset_linkinfo(fcport); |
| 2798 | bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE); |
| 2799 | bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown); |
| 2800 | break; |
| 2801 | |
| 2802 | default: |
| 2803 | bfa_sm_fault(fcport->bfa, event); |
| 2804 | } |
| 2805 | } |
| 2806 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2807 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2808 | * Link state is down |
| 2809 | */ |
| 2810 | static void |
| 2811 | bfa_fcport_ln_sm_dn(struct bfa_fcport_ln_s *ln, |
| 2812 | enum bfa_fcport_ln_sm_event event) |
| 2813 | { |
| 2814 | bfa_trc(ln->fcport->bfa, event); |
| 2815 | |
| 2816 | switch (event) { |
| 2817 | case BFA_FCPORT_LN_SM_LINKUP: |
| 2818 | bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_nf); |
| 2819 | bfa_fcport_queue_cb(ln, BFA_PORT_LINKUP); |
| 2820 | break; |
| 2821 | |
| 2822 | default: |
| 2823 | bfa_sm_fault(ln->fcport->bfa, event); |
| 2824 | } |
| 2825 | } |
| 2826 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2827 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2828 | * Link state is waiting for down notification |
| 2829 | */ |
| 2830 | static void |
| 2831 | bfa_fcport_ln_sm_dn_nf(struct bfa_fcport_ln_s *ln, |
| 2832 | enum bfa_fcport_ln_sm_event event) |
| 2833 | { |
| 2834 | bfa_trc(ln->fcport->bfa, event); |
| 2835 | |
| 2836 | switch (event) { |
| 2837 | case BFA_FCPORT_LN_SM_LINKUP: |
| 2838 | bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_up_nf); |
| 2839 | break; |
| 2840 | |
| 2841 | case BFA_FCPORT_LN_SM_NOTIFICATION: |
| 2842 | bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn); |
| 2843 | break; |
| 2844 | |
| 2845 | default: |
| 2846 | bfa_sm_fault(ln->fcport->bfa, event); |
| 2847 | } |
| 2848 | } |
| 2849 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2850 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2851 | * Link state is waiting for down notification and there is a pending up |
| 2852 | */ |
| 2853 | static void |
| 2854 | bfa_fcport_ln_sm_dn_up_nf(struct bfa_fcport_ln_s *ln, |
| 2855 | enum bfa_fcport_ln_sm_event event) |
| 2856 | { |
| 2857 | bfa_trc(ln->fcport->bfa, event); |
| 2858 | |
| 2859 | switch (event) { |
| 2860 | case BFA_FCPORT_LN_SM_LINKDOWN: |
| 2861 | bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf); |
| 2862 | break; |
| 2863 | |
| 2864 | case BFA_FCPORT_LN_SM_NOTIFICATION: |
| 2865 | bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_nf); |
| 2866 | bfa_fcport_queue_cb(ln, BFA_PORT_LINKUP); |
| 2867 | break; |
| 2868 | |
| 2869 | default: |
| 2870 | bfa_sm_fault(ln->fcport->bfa, event); |
| 2871 | } |
| 2872 | } |
| 2873 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2874 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2875 | * Link state is up |
| 2876 | */ |
| 2877 | static void |
| 2878 | bfa_fcport_ln_sm_up(struct bfa_fcport_ln_s *ln, |
| 2879 | enum bfa_fcport_ln_sm_event event) |
| 2880 | { |
| 2881 | bfa_trc(ln->fcport->bfa, event); |
| 2882 | |
| 2883 | switch (event) { |
| 2884 | case BFA_FCPORT_LN_SM_LINKDOWN: |
| 2885 | bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf); |
| 2886 | bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN); |
| 2887 | break; |
| 2888 | |
| 2889 | default: |
| 2890 | bfa_sm_fault(ln->fcport->bfa, event); |
| 2891 | } |
| 2892 | } |
| 2893 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2894 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2895 | * Link state is waiting for up notification |
| 2896 | */ |
| 2897 | static void |
| 2898 | bfa_fcport_ln_sm_up_nf(struct bfa_fcport_ln_s *ln, |
| 2899 | enum bfa_fcport_ln_sm_event event) |
| 2900 | { |
| 2901 | bfa_trc(ln->fcport->bfa, event); |
| 2902 | |
| 2903 | switch (event) { |
| 2904 | case BFA_FCPORT_LN_SM_LINKDOWN: |
| 2905 | bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_nf); |
| 2906 | break; |
| 2907 | |
| 2908 | case BFA_FCPORT_LN_SM_NOTIFICATION: |
| 2909 | bfa_sm_set_state(ln, bfa_fcport_ln_sm_up); |
| 2910 | break; |
| 2911 | |
| 2912 | default: |
| 2913 | bfa_sm_fault(ln->fcport->bfa, event); |
| 2914 | } |
| 2915 | } |
| 2916 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2917 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2918 | * Link state is waiting for up notification and there is a pending down |
| 2919 | */ |
| 2920 | static void |
| 2921 | bfa_fcport_ln_sm_up_dn_nf(struct bfa_fcport_ln_s *ln, |
| 2922 | enum bfa_fcport_ln_sm_event event) |
| 2923 | { |
| 2924 | bfa_trc(ln->fcport->bfa, event); |
| 2925 | |
| 2926 | switch (event) { |
| 2927 | case BFA_FCPORT_LN_SM_LINKUP: |
| 2928 | bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_up_nf); |
| 2929 | break; |
| 2930 | |
| 2931 | case BFA_FCPORT_LN_SM_NOTIFICATION: |
| 2932 | bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf); |
| 2933 | bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN); |
| 2934 | break; |
| 2935 | |
| 2936 | default: |
| 2937 | bfa_sm_fault(ln->fcport->bfa, event); |
| 2938 | } |
| 2939 | } |
| 2940 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2941 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2942 | * Link state is waiting for up notification and there are pending down and up |
| 2943 | */ |
| 2944 | static void |
| 2945 | bfa_fcport_ln_sm_up_dn_up_nf(struct bfa_fcport_ln_s *ln, |
| 2946 | enum bfa_fcport_ln_sm_event event) |
| 2947 | { |
| 2948 | bfa_trc(ln->fcport->bfa, event); |
| 2949 | |
| 2950 | switch (event) { |
| 2951 | case BFA_FCPORT_LN_SM_LINKDOWN: |
| 2952 | bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_nf); |
| 2953 | break; |
| 2954 | |
| 2955 | case BFA_FCPORT_LN_SM_NOTIFICATION: |
| 2956 | bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_up_nf); |
| 2957 | bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN); |
| 2958 | break; |
| 2959 | |
| 2960 | default: |
| 2961 | bfa_sm_fault(ln->fcport->bfa, event); |
| 2962 | } |
| 2963 | } |
| 2964 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2965 | static void |
| 2966 | __bfa_cb_fcport_event(void *cbarg, bfa_boolean_t complete) |
| 2967 | { |
| 2968 | struct bfa_fcport_ln_s *ln = cbarg; |
| 2969 | |
| 2970 | if (complete) |
| 2971 | ln->fcport->event_cbfn(ln->fcport->event_cbarg, ln->ln_event); |
| 2972 | else |
| 2973 | bfa_sm_send_event(ln, BFA_FCPORT_LN_SM_NOTIFICATION); |
| 2974 | } |
| 2975 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2976 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2977 | * Send SCN notification to upper layers. |
| 2978 | * trunk - false if caller is fcport to ignore fcport event in trunked mode |
| 2979 | */ |
| 2980 | static void |
| 2981 | bfa_fcport_scn(struct bfa_fcport_s *fcport, enum bfa_port_linkstate event, |
| 2982 | bfa_boolean_t trunk) |
| 2983 | { |
| 2984 | if (fcport->cfg.trunked && !trunk) |
| 2985 | return; |
| 2986 | |
| 2987 | switch (event) { |
| 2988 | case BFA_PORT_LINKUP: |
| 2989 | bfa_sm_send_event(&fcport->ln, BFA_FCPORT_LN_SM_LINKUP); |
| 2990 | break; |
| 2991 | case BFA_PORT_LINKDOWN: |
| 2992 | bfa_sm_send_event(&fcport->ln, BFA_FCPORT_LN_SM_LINKDOWN); |
| 2993 | break; |
| 2994 | default: |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 2995 | WARN_ON(1); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2996 | } |
| 2997 | } |
| 2998 | |
| 2999 | static void |
| 3000 | bfa_fcport_queue_cb(struct bfa_fcport_ln_s *ln, enum bfa_port_linkstate event) |
| 3001 | { |
| 3002 | struct bfa_fcport_s *fcport = ln->fcport; |
| 3003 | |
| 3004 | if (fcport->bfa->fcs) { |
| 3005 | fcport->event_cbfn(fcport->event_cbarg, event); |
| 3006 | bfa_sm_send_event(ln, BFA_FCPORT_LN_SM_NOTIFICATION); |
| 3007 | } else { |
| 3008 | ln->ln_event = event; |
| 3009 | bfa_cb_queue(fcport->bfa, &ln->ln_qe, |
| 3010 | __bfa_cb_fcport_event, ln); |
| 3011 | } |
| 3012 | } |
| 3013 | |
| 3014 | #define FCPORT_STATS_DMA_SZ (BFA_ROUNDUP(sizeof(union bfa_fcport_stats_u), \ |
| 3015 | BFA_CACHELINE_SZ)) |
| 3016 | |
| 3017 | static void |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 3018 | bfa_fcport_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo, |
| 3019 | struct bfa_s *bfa) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3020 | { |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 3021 | struct bfa_mem_dma_s *fcport_dma = BFA_MEM_FCPORT_DMA(bfa); |
| 3022 | |
| 3023 | bfa_mem_dma_setup(minfo, fcport_dma, FCPORT_STATS_DMA_SZ); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3024 | } |
| 3025 | |
| 3026 | static void |
| 3027 | bfa_fcport_qresume(void *cbarg) |
| 3028 | { |
| 3029 | struct bfa_fcport_s *fcport = cbarg; |
| 3030 | |
| 3031 | bfa_sm_send_event(fcport, BFA_FCPORT_SM_QRESUME); |
| 3032 | } |
| 3033 | |
| 3034 | static void |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 3035 | bfa_fcport_mem_claim(struct bfa_fcport_s *fcport) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3036 | { |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 3037 | struct bfa_mem_dma_s *fcport_dma = &fcport->fcport_dma; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3038 | |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 3039 | fcport->stats_kva = bfa_mem_dma_virt(fcport_dma); |
| 3040 | fcport->stats_pa = bfa_mem_dma_phys(fcport_dma); |
| 3041 | fcport->stats = (union bfa_fcport_stats_u *) |
| 3042 | bfa_mem_dma_virt(fcport_dma); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3043 | } |
| 3044 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3045 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3046 | * Memory initialization. |
| 3047 | */ |
| 3048 | static void |
| 3049 | bfa_fcport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg, |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 3050 | struct bfa_pcidev_s *pcidev) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3051 | { |
| 3052 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3053 | struct bfa_port_cfg_s *port_cfg = &fcport->cfg; |
| 3054 | struct bfa_fcport_ln_s *ln = &fcport->ln; |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 3055 | struct timeval tv; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3056 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3057 | fcport->bfa = bfa; |
| 3058 | ln->fcport = fcport; |
| 3059 | |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 3060 | bfa_fcport_mem_claim(fcport); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3061 | |
| 3062 | bfa_sm_set_state(fcport, bfa_fcport_sm_uninit); |
| 3063 | bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn); |
| 3064 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3065 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3066 | * initialize time stamp for stats reset |
| 3067 | */ |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 3068 | do_gettimeofday(&tv); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3069 | fcport->stats_reset_time = tv.tv_sec; |
| 3070 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3071 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3072 | * initialize and set default configuration |
| 3073 | */ |
| 3074 | port_cfg->topology = BFA_PORT_TOPOLOGY_P2P; |
| 3075 | port_cfg->speed = BFA_PORT_SPEED_AUTO; |
| 3076 | port_cfg->trunked = BFA_FALSE; |
| 3077 | port_cfg->maxfrsize = 0; |
| 3078 | |
| 3079 | port_cfg->trl_def_speed = BFA_PORT_SPEED_1GBPS; |
| 3080 | |
Krishna Gudipati | 37ea055 | 2011-07-20 17:02:11 -0700 | [diff] [blame] | 3081 | INIT_LIST_HEAD(&fcport->stats_pending_q); |
| 3082 | INIT_LIST_HEAD(&fcport->statsclr_pending_q); |
| 3083 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3084 | bfa_reqq_winit(&fcport->reqq_wait, bfa_fcport_qresume, fcport); |
| 3085 | } |
| 3086 | |
| 3087 | static void |
| 3088 | bfa_fcport_detach(struct bfa_s *bfa) |
| 3089 | { |
| 3090 | } |
| 3091 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3092 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3093 | * Called when IOC is ready. |
| 3094 | */ |
| 3095 | static void |
| 3096 | bfa_fcport_start(struct bfa_s *bfa) |
| 3097 | { |
| 3098 | bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_START); |
| 3099 | } |
| 3100 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3101 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3102 | * Called before IOC is stopped. |
| 3103 | */ |
| 3104 | static void |
| 3105 | bfa_fcport_stop(struct bfa_s *bfa) |
| 3106 | { |
| 3107 | bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_STOP); |
| 3108 | bfa_trunk_iocdisable(bfa); |
| 3109 | } |
| 3110 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3111 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3112 | * Called when IOC failure is detected. |
| 3113 | */ |
| 3114 | static void |
| 3115 | bfa_fcport_iocdisable(struct bfa_s *bfa) |
| 3116 | { |
| 3117 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3118 | |
| 3119 | bfa_sm_send_event(fcport, BFA_FCPORT_SM_HWFAIL); |
| 3120 | bfa_trunk_iocdisable(bfa); |
| 3121 | } |
| 3122 | |
Krishna Gudipati | bc0e2c2 | 2012-09-21 17:23:59 -0700 | [diff] [blame] | 3123 | /* |
| 3124 | * Update loop info in fcport for SCN online |
| 3125 | */ |
| 3126 | static void |
| 3127 | bfa_fcport_update_loop_info(struct bfa_fcport_s *fcport, |
| 3128 | struct bfa_fcport_loop_info_s *loop_info) |
| 3129 | { |
| 3130 | fcport->myalpa = loop_info->myalpa; |
| 3131 | fcport->alpabm_valid = |
| 3132 | loop_info->alpabm_val; |
| 3133 | memcpy(fcport->alpabm.alpa_bm, |
| 3134 | loop_info->alpabm.alpa_bm, |
| 3135 | sizeof(struct fc_alpabm_s)); |
| 3136 | } |
| 3137 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3138 | static void |
| 3139 | bfa_fcport_update_linkinfo(struct bfa_fcport_s *fcport) |
| 3140 | { |
| 3141 | struct bfi_fcport_event_s *pevent = fcport->event_arg.i2hmsg.event; |
| 3142 | struct bfa_fcport_trunk_s *trunk = &fcport->trunk; |
| 3143 | |
| 3144 | fcport->speed = pevent->link_state.speed; |
| 3145 | fcport->topology = pevent->link_state.topology; |
| 3146 | |
Krishna Gudipati | bc0e2c2 | 2012-09-21 17:23:59 -0700 | [diff] [blame] | 3147 | if (fcport->topology == BFA_PORT_TOPOLOGY_LOOP) { |
| 3148 | bfa_fcport_update_loop_info(fcport, |
| 3149 | &pevent->link_state.attr.loop_info); |
| 3150 | return; |
| 3151 | } |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3152 | |
| 3153 | /* QoS Details */ |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 3154 | fcport->qos_attr = pevent->link_state.qos_attr; |
Krishna Gudipati | bc0e2c2 | 2012-09-21 17:23:59 -0700 | [diff] [blame] | 3155 | fcport->qos_vc_attr = pevent->link_state.attr.vc_fcf.qos_vc_attr; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3156 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3157 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3158 | * update trunk state if applicable |
| 3159 | */ |
| 3160 | if (!fcport->cfg.trunked) |
| 3161 | trunk->attr.state = BFA_TRUNK_DISABLED; |
| 3162 | |
| 3163 | /* update FCoE specific */ |
Krishna Gudipati | bc0e2c2 | 2012-09-21 17:23:59 -0700 | [diff] [blame] | 3164 | fcport->fcoe_vlan = |
| 3165 | be16_to_cpu(pevent->link_state.attr.vc_fcf.fcf.vlan); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3166 | |
| 3167 | bfa_trc(fcport->bfa, fcport->speed); |
| 3168 | bfa_trc(fcport->bfa, fcport->topology); |
| 3169 | } |
| 3170 | |
| 3171 | static void |
| 3172 | bfa_fcport_reset_linkinfo(struct bfa_fcport_s *fcport) |
| 3173 | { |
| 3174 | fcport->speed = BFA_PORT_SPEED_UNKNOWN; |
| 3175 | fcport->topology = BFA_PORT_TOPOLOGY_NONE; |
Krishna Gudipati | be540a9 | 2011-06-13 15:53:04 -0700 | [diff] [blame] | 3176 | fcport->bbsc_op_state = BFA_FALSE; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3177 | } |
| 3178 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3179 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3180 | * Send port enable message to firmware. |
| 3181 | */ |
| 3182 | static bfa_boolean_t |
| 3183 | bfa_fcport_send_enable(struct bfa_fcport_s *fcport) |
| 3184 | { |
| 3185 | struct bfi_fcport_enable_req_s *m; |
| 3186 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3187 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3188 | * Increment message tag before queue check, so that responses to old |
| 3189 | * requests are discarded. |
| 3190 | */ |
| 3191 | fcport->msgtag++; |
| 3192 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3193 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3194 | * check for room in queue to send request now |
| 3195 | */ |
| 3196 | m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT); |
| 3197 | if (!m) { |
| 3198 | bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT, |
| 3199 | &fcport->reqq_wait); |
| 3200 | return BFA_FALSE; |
| 3201 | } |
| 3202 | |
| 3203 | bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_ENABLE_REQ, |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 3204 | bfa_fn_lpu(fcport->bfa)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3205 | m->nwwn = fcport->nwwn; |
| 3206 | m->pwwn = fcport->pwwn; |
| 3207 | m->port_cfg = fcport->cfg; |
| 3208 | m->msgtag = fcport->msgtag; |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 3209 | m->port_cfg.maxfrsize = cpu_to_be16(fcport->cfg.maxfrsize); |
Krishna Gudipati | f3a060c | 2010-12-13 16:16:50 -0800 | [diff] [blame] | 3210 | m->use_flash_cfg = fcport->use_flash_cfg; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3211 | bfa_dma_be_addr_set(m->stats_dma_addr, fcport->stats_pa); |
| 3212 | bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_lo); |
| 3213 | bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_hi); |
| 3214 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3215 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3216 | * queue I/O message to firmware |
| 3217 | */ |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 3218 | bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, m->mh); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3219 | return BFA_TRUE; |
| 3220 | } |
| 3221 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3222 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3223 | * Send port disable message to firmware. |
| 3224 | */ |
| 3225 | static bfa_boolean_t |
| 3226 | bfa_fcport_send_disable(struct bfa_fcport_s *fcport) |
| 3227 | { |
| 3228 | struct bfi_fcport_req_s *m; |
| 3229 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3230 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3231 | * Increment message tag before queue check, so that responses to old |
| 3232 | * requests are discarded. |
| 3233 | */ |
| 3234 | fcport->msgtag++; |
| 3235 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3236 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3237 | * check for room in queue to send request now |
| 3238 | */ |
| 3239 | m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT); |
| 3240 | if (!m) { |
| 3241 | bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT, |
| 3242 | &fcport->reqq_wait); |
| 3243 | return BFA_FALSE; |
| 3244 | } |
| 3245 | |
| 3246 | bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_DISABLE_REQ, |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 3247 | bfa_fn_lpu(fcport->bfa)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3248 | m->msgtag = fcport->msgtag; |
| 3249 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3250 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3251 | * queue I/O message to firmware |
| 3252 | */ |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 3253 | bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, m->mh); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3254 | |
| 3255 | return BFA_TRUE; |
| 3256 | } |
| 3257 | |
| 3258 | static void |
| 3259 | bfa_fcport_set_wwns(struct bfa_fcport_s *fcport) |
| 3260 | { |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 3261 | fcport->pwwn = fcport->bfa->ioc.attr->pwwn; |
| 3262 | fcport->nwwn = fcport->bfa->ioc.attr->nwwn; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3263 | |
| 3264 | bfa_trc(fcport->bfa, fcport->pwwn); |
| 3265 | bfa_trc(fcport->bfa, fcport->nwwn); |
| 3266 | } |
| 3267 | |
| 3268 | static void |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3269 | bfa_fcport_qos_stats_swap(struct bfa_qos_stats_s *d, |
| 3270 | struct bfa_qos_stats_s *s) |
| 3271 | { |
| 3272 | u32 *dip = (u32 *) d; |
Maggie | 50444a3 | 2010-11-29 18:26:32 -0800 | [diff] [blame] | 3273 | __be32 *sip = (__be32 *) s; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3274 | int i; |
| 3275 | |
| 3276 | /* Now swap the 32 bit fields */ |
| 3277 | for (i = 0; i < (sizeof(struct bfa_qos_stats_s)/sizeof(u32)); ++i) |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 3278 | dip[i] = be32_to_cpu(sip[i]); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3279 | } |
| 3280 | |
| 3281 | static void |
| 3282 | bfa_fcport_fcoe_stats_swap(struct bfa_fcoe_stats_s *d, |
| 3283 | struct bfa_fcoe_stats_s *s) |
| 3284 | { |
| 3285 | u32 *dip = (u32 *) d; |
Maggie | 50444a3 | 2010-11-29 18:26:32 -0800 | [diff] [blame] | 3286 | __be32 *sip = (__be32 *) s; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3287 | int i; |
| 3288 | |
| 3289 | for (i = 0; i < ((sizeof(struct bfa_fcoe_stats_s))/sizeof(u32)); |
| 3290 | i = i + 2) { |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 3291 | #ifdef __BIG_ENDIAN |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 3292 | dip[i] = be32_to_cpu(sip[i]); |
| 3293 | dip[i + 1] = be32_to_cpu(sip[i + 1]); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3294 | #else |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 3295 | dip[i] = be32_to_cpu(sip[i + 1]); |
| 3296 | dip[i + 1] = be32_to_cpu(sip[i]); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3297 | #endif |
| 3298 | } |
| 3299 | } |
| 3300 | |
| 3301 | static void |
| 3302 | __bfa_cb_fcport_stats_get(void *cbarg, bfa_boolean_t complete) |
| 3303 | { |
Krishna Gudipati | 37ea055 | 2011-07-20 17:02:11 -0700 | [diff] [blame] | 3304 | struct bfa_fcport_s *fcport = (struct bfa_fcport_s *)cbarg; |
| 3305 | struct bfa_cb_pending_q_s *cb; |
| 3306 | struct list_head *qe, *qen; |
| 3307 | union bfa_fcport_stats_u *ret; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3308 | |
| 3309 | if (complete) { |
Krishna Gudipati | 37ea055 | 2011-07-20 17:02:11 -0700 | [diff] [blame] | 3310 | struct timeval tv; |
| 3311 | if (fcport->stats_status == BFA_STATUS_OK) |
| 3312 | do_gettimeofday(&tv); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3313 | |
Krishna Gudipati | 37ea055 | 2011-07-20 17:02:11 -0700 | [diff] [blame] | 3314 | list_for_each_safe(qe, qen, &fcport->stats_pending_q) { |
| 3315 | bfa_q_deq(&fcport->stats_pending_q, &qe); |
| 3316 | cb = (struct bfa_cb_pending_q_s *)qe; |
| 3317 | if (fcport->stats_status == BFA_STATUS_OK) { |
| 3318 | ret = (union bfa_fcport_stats_u *)cb->data; |
| 3319 | /* Swap FC QoS or FCoE stats */ |
| 3320 | if (bfa_ioc_get_fcmode(&fcport->bfa->ioc)) |
| 3321 | bfa_fcport_qos_stats_swap(&ret->fcqos, |
| 3322 | &fcport->stats->fcqos); |
| 3323 | else { |
| 3324 | bfa_fcport_fcoe_stats_swap(&ret->fcoe, |
| 3325 | &fcport->stats->fcoe); |
| 3326 | ret->fcoe.secs_reset = |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3327 | tv.tv_sec - fcport->stats_reset_time; |
Krishna Gudipati | 37ea055 | 2011-07-20 17:02:11 -0700 | [diff] [blame] | 3328 | } |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3329 | } |
Krishna Gudipati | 37ea055 | 2011-07-20 17:02:11 -0700 | [diff] [blame] | 3330 | bfa_cb_queue_status(fcport->bfa, &cb->hcb_qe, |
| 3331 | fcport->stats_status); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3332 | } |
Krishna Gudipati | 37ea055 | 2011-07-20 17:02:11 -0700 | [diff] [blame] | 3333 | fcport->stats_status = BFA_STATUS_OK; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3334 | } else { |
Krishna Gudipati | 37ea055 | 2011-07-20 17:02:11 -0700 | [diff] [blame] | 3335 | INIT_LIST_HEAD(&fcport->stats_pending_q); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3336 | fcport->stats_status = BFA_STATUS_OK; |
| 3337 | } |
| 3338 | } |
| 3339 | |
| 3340 | static void |
| 3341 | bfa_fcport_stats_get_timeout(void *cbarg) |
| 3342 | { |
| 3343 | struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg; |
| 3344 | |
| 3345 | bfa_trc(fcport->bfa, fcport->stats_qfull); |
| 3346 | |
| 3347 | if (fcport->stats_qfull) { |
| 3348 | bfa_reqq_wcancel(&fcport->stats_reqq_wait); |
| 3349 | fcport->stats_qfull = BFA_FALSE; |
| 3350 | } |
| 3351 | |
| 3352 | fcport->stats_status = BFA_STATUS_ETIMER; |
Krishna Gudipati | 37ea055 | 2011-07-20 17:02:11 -0700 | [diff] [blame] | 3353 | __bfa_cb_fcport_stats_get(fcport, BFA_TRUE); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3354 | } |
| 3355 | |
| 3356 | static void |
| 3357 | bfa_fcport_send_stats_get(void *cbarg) |
| 3358 | { |
| 3359 | struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg; |
| 3360 | struct bfi_fcport_req_s *msg; |
| 3361 | |
| 3362 | msg = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT); |
| 3363 | |
| 3364 | if (!msg) { |
| 3365 | fcport->stats_qfull = BFA_TRUE; |
| 3366 | bfa_reqq_winit(&fcport->stats_reqq_wait, |
| 3367 | bfa_fcport_send_stats_get, fcport); |
| 3368 | bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT, |
| 3369 | &fcport->stats_reqq_wait); |
| 3370 | return; |
| 3371 | } |
| 3372 | fcport->stats_qfull = BFA_FALSE; |
| 3373 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 3374 | memset(msg, 0, sizeof(struct bfi_fcport_req_s)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3375 | bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_GET_REQ, |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 3376 | bfa_fn_lpu(fcport->bfa)); |
| 3377 | bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, msg->mh); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3378 | } |
| 3379 | |
| 3380 | static void |
| 3381 | __bfa_cb_fcport_stats_clr(void *cbarg, bfa_boolean_t complete) |
| 3382 | { |
Krishna Gudipati | 37ea055 | 2011-07-20 17:02:11 -0700 | [diff] [blame] | 3383 | struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg; |
| 3384 | struct bfa_cb_pending_q_s *cb; |
| 3385 | struct list_head *qe, *qen; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3386 | |
| 3387 | if (complete) { |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 3388 | struct timeval tv; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3389 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3390 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3391 | * re-initialize time stamp for stats reset |
| 3392 | */ |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 3393 | do_gettimeofday(&tv); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3394 | fcport->stats_reset_time = tv.tv_sec; |
Krishna Gudipati | 37ea055 | 2011-07-20 17:02:11 -0700 | [diff] [blame] | 3395 | list_for_each_safe(qe, qen, &fcport->statsclr_pending_q) { |
| 3396 | bfa_q_deq(&fcport->statsclr_pending_q, &qe); |
| 3397 | cb = (struct bfa_cb_pending_q_s *)qe; |
| 3398 | bfa_cb_queue_status(fcport->bfa, &cb->hcb_qe, |
| 3399 | fcport->stats_status); |
| 3400 | } |
| 3401 | fcport->stats_status = BFA_STATUS_OK; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3402 | } else { |
Krishna Gudipati | 37ea055 | 2011-07-20 17:02:11 -0700 | [diff] [blame] | 3403 | INIT_LIST_HEAD(&fcport->statsclr_pending_q); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3404 | fcport->stats_status = BFA_STATUS_OK; |
| 3405 | } |
| 3406 | } |
| 3407 | |
| 3408 | static void |
| 3409 | bfa_fcport_stats_clr_timeout(void *cbarg) |
| 3410 | { |
| 3411 | struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg; |
| 3412 | |
| 3413 | bfa_trc(fcport->bfa, fcport->stats_qfull); |
| 3414 | |
| 3415 | if (fcport->stats_qfull) { |
| 3416 | bfa_reqq_wcancel(&fcport->stats_reqq_wait); |
| 3417 | fcport->stats_qfull = BFA_FALSE; |
| 3418 | } |
| 3419 | |
| 3420 | fcport->stats_status = BFA_STATUS_ETIMER; |
Krishna Gudipati | 37ea055 | 2011-07-20 17:02:11 -0700 | [diff] [blame] | 3421 | __bfa_cb_fcport_stats_clr(fcport, BFA_TRUE); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3422 | } |
| 3423 | |
| 3424 | static void |
| 3425 | bfa_fcport_send_stats_clear(void *cbarg) |
| 3426 | { |
| 3427 | struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg; |
| 3428 | struct bfi_fcport_req_s *msg; |
| 3429 | |
| 3430 | msg = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT); |
| 3431 | |
| 3432 | if (!msg) { |
| 3433 | fcport->stats_qfull = BFA_TRUE; |
| 3434 | bfa_reqq_winit(&fcport->stats_reqq_wait, |
| 3435 | bfa_fcport_send_stats_clear, fcport); |
| 3436 | bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT, |
| 3437 | &fcport->stats_reqq_wait); |
| 3438 | return; |
| 3439 | } |
| 3440 | fcport->stats_qfull = BFA_FALSE; |
| 3441 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 3442 | memset(msg, 0, sizeof(struct bfi_fcport_req_s)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3443 | bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_CLEAR_REQ, |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 3444 | bfa_fn_lpu(fcport->bfa)); |
| 3445 | bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, msg->mh); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3446 | } |
| 3447 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3448 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3449 | * Handle trunk SCN event from firmware. |
| 3450 | */ |
| 3451 | static void |
| 3452 | bfa_trunk_scn(struct bfa_fcport_s *fcport, struct bfi_fcport_trunk_scn_s *scn) |
| 3453 | { |
| 3454 | struct bfa_fcport_trunk_s *trunk = &fcport->trunk; |
| 3455 | struct bfi_fcport_trunk_link_s *tlink; |
| 3456 | struct bfa_trunk_link_attr_s *lattr; |
| 3457 | enum bfa_trunk_state state_prev; |
| 3458 | int i; |
| 3459 | int link_bm = 0; |
| 3460 | |
| 3461 | bfa_trc(fcport->bfa, fcport->cfg.trunked); |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 3462 | WARN_ON(scn->trunk_state != BFA_TRUNK_ONLINE && |
| 3463 | scn->trunk_state != BFA_TRUNK_OFFLINE); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3464 | |
| 3465 | bfa_trc(fcport->bfa, trunk->attr.state); |
| 3466 | bfa_trc(fcport->bfa, scn->trunk_state); |
| 3467 | bfa_trc(fcport->bfa, scn->trunk_speed); |
| 3468 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3469 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3470 | * Save off new state for trunk attribute query |
| 3471 | */ |
| 3472 | state_prev = trunk->attr.state; |
| 3473 | if (fcport->cfg.trunked && (trunk->attr.state != BFA_TRUNK_DISABLED)) |
| 3474 | trunk->attr.state = scn->trunk_state; |
| 3475 | trunk->attr.speed = scn->trunk_speed; |
| 3476 | for (i = 0; i < BFA_TRUNK_MAX_PORTS; i++) { |
| 3477 | lattr = &trunk->attr.link_attr[i]; |
| 3478 | tlink = &scn->tlink[i]; |
| 3479 | |
| 3480 | lattr->link_state = tlink->state; |
| 3481 | lattr->trunk_wwn = tlink->trunk_wwn; |
| 3482 | lattr->fctl = tlink->fctl; |
| 3483 | lattr->speed = tlink->speed; |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 3484 | lattr->deskew = be32_to_cpu(tlink->deskew); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3485 | |
| 3486 | if (tlink->state == BFA_TRUNK_LINK_STATE_UP) { |
| 3487 | fcport->speed = tlink->speed; |
| 3488 | fcport->topology = BFA_PORT_TOPOLOGY_P2P; |
| 3489 | link_bm |= 1 << i; |
| 3490 | } |
| 3491 | |
| 3492 | bfa_trc(fcport->bfa, lattr->link_state); |
| 3493 | bfa_trc(fcport->bfa, lattr->trunk_wwn); |
| 3494 | bfa_trc(fcport->bfa, lattr->fctl); |
| 3495 | bfa_trc(fcport->bfa, lattr->speed); |
| 3496 | bfa_trc(fcport->bfa, lattr->deskew); |
| 3497 | } |
| 3498 | |
| 3499 | switch (link_bm) { |
| 3500 | case 3: |
| 3501 | bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL, |
| 3502 | BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(0,1)"); |
| 3503 | break; |
| 3504 | case 2: |
| 3505 | bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL, |
| 3506 | BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(-,1)"); |
| 3507 | break; |
| 3508 | case 1: |
| 3509 | bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL, |
| 3510 | BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(0,-)"); |
| 3511 | break; |
| 3512 | default: |
| 3513 | bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL, |
| 3514 | BFA_PL_EID_TRUNK_SCN, 0, "Trunk down"); |
| 3515 | } |
| 3516 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3517 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3518 | * Notify upper layers if trunk state changed. |
| 3519 | */ |
| 3520 | if ((state_prev != trunk->attr.state) || |
| 3521 | (scn->trunk_state == BFA_TRUNK_OFFLINE)) { |
| 3522 | bfa_fcport_scn(fcport, (scn->trunk_state == BFA_TRUNK_ONLINE) ? |
| 3523 | BFA_PORT_LINKUP : BFA_PORT_LINKDOWN, BFA_TRUE); |
| 3524 | } |
| 3525 | } |
| 3526 | |
| 3527 | static void |
| 3528 | bfa_trunk_iocdisable(struct bfa_s *bfa) |
| 3529 | { |
| 3530 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3531 | int i = 0; |
| 3532 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3533 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3534 | * In trunked mode, notify upper layers that link is down |
| 3535 | */ |
| 3536 | if (fcport->cfg.trunked) { |
| 3537 | if (fcport->trunk.attr.state == BFA_TRUNK_ONLINE) |
| 3538 | bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_TRUE); |
| 3539 | |
| 3540 | fcport->trunk.attr.state = BFA_TRUNK_OFFLINE; |
| 3541 | fcport->trunk.attr.speed = BFA_PORT_SPEED_UNKNOWN; |
| 3542 | for (i = 0; i < BFA_TRUNK_MAX_PORTS; i++) { |
| 3543 | fcport->trunk.attr.link_attr[i].trunk_wwn = 0; |
| 3544 | fcport->trunk.attr.link_attr[i].fctl = |
| 3545 | BFA_TRUNK_LINK_FCTL_NORMAL; |
| 3546 | fcport->trunk.attr.link_attr[i].link_state = |
| 3547 | BFA_TRUNK_LINK_STATE_DN_LINKDN; |
| 3548 | fcport->trunk.attr.link_attr[i].speed = |
| 3549 | BFA_PORT_SPEED_UNKNOWN; |
| 3550 | fcport->trunk.attr.link_attr[i].deskew = 0; |
| 3551 | } |
| 3552 | } |
| 3553 | } |
| 3554 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3555 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3556 | * Called to initialize port attributes |
| 3557 | */ |
| 3558 | void |
| 3559 | bfa_fcport_init(struct bfa_s *bfa) |
| 3560 | { |
| 3561 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3562 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3563 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3564 | * Initialize port attributes from IOC hardware data. |
| 3565 | */ |
| 3566 | bfa_fcport_set_wwns(fcport); |
| 3567 | if (fcport->cfg.maxfrsize == 0) |
| 3568 | fcport->cfg.maxfrsize = bfa_ioc_maxfrsize(&bfa->ioc); |
| 3569 | fcport->cfg.rx_bbcredit = bfa_ioc_rx_bbcredit(&bfa->ioc); |
| 3570 | fcport->speed_sup = bfa_ioc_speed_sup(&bfa->ioc); |
| 3571 | |
Krishna Gudipati | 43ffdf4 | 2011-06-13 15:46:21 -0700 | [diff] [blame] | 3572 | if (bfa_fcport_is_pbcdisabled(bfa)) |
| 3573 | bfa->modules.port.pbc_disabled = BFA_TRUE; |
| 3574 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 3575 | WARN_ON(!fcport->cfg.maxfrsize); |
| 3576 | WARN_ON(!fcport->cfg.rx_bbcredit); |
| 3577 | WARN_ON(!fcport->speed_sup); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3578 | } |
| 3579 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3580 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3581 | * Firmware message handler. |
| 3582 | */ |
| 3583 | void |
| 3584 | bfa_fcport_isr(struct bfa_s *bfa, struct bfi_msg_s *msg) |
| 3585 | { |
| 3586 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3587 | union bfi_fcport_i2h_msg_u i2hmsg; |
| 3588 | |
| 3589 | i2hmsg.msg = msg; |
| 3590 | fcport->event_arg.i2hmsg = i2hmsg; |
| 3591 | |
| 3592 | bfa_trc(bfa, msg->mhdr.msg_id); |
| 3593 | bfa_trc(bfa, bfa_sm_to_state(hal_port_sm_table, fcport->sm)); |
| 3594 | |
| 3595 | switch (msg->mhdr.msg_id) { |
| 3596 | case BFI_FCPORT_I2H_ENABLE_RSP: |
Krishna Gudipati | f3a060c | 2010-12-13 16:16:50 -0800 | [diff] [blame] | 3597 | if (fcport->msgtag == i2hmsg.penable_rsp->msgtag) { |
| 3598 | |
| 3599 | if (fcport->use_flash_cfg) { |
| 3600 | fcport->cfg = i2hmsg.penable_rsp->port_cfg; |
| 3601 | fcport->cfg.maxfrsize = |
| 3602 | cpu_to_be16(fcport->cfg.maxfrsize); |
| 3603 | fcport->cfg.path_tov = |
| 3604 | cpu_to_be16(fcport->cfg.path_tov); |
| 3605 | fcport->cfg.q_depth = |
| 3606 | cpu_to_be16(fcport->cfg.q_depth); |
| 3607 | |
| 3608 | if (fcport->cfg.trunked) |
| 3609 | fcport->trunk.attr.state = |
| 3610 | BFA_TRUNK_OFFLINE; |
| 3611 | else |
| 3612 | fcport->trunk.attr.state = |
| 3613 | BFA_TRUNK_DISABLED; |
| 3614 | fcport->use_flash_cfg = BFA_FALSE; |
| 3615 | } |
| 3616 | |
Krishna Gudipati | 3ec4f2c | 2011-07-20 17:03:09 -0700 | [diff] [blame] | 3617 | if (fcport->cfg.qos_enabled) |
| 3618 | fcport->qos_attr.state = BFA_QOS_OFFLINE; |
| 3619 | else |
| 3620 | fcport->qos_attr.state = BFA_QOS_DISABLED; |
| 3621 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3622 | bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP); |
Krishna Gudipati | f3a060c | 2010-12-13 16:16:50 -0800 | [diff] [blame] | 3623 | } |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3624 | break; |
| 3625 | |
| 3626 | case BFI_FCPORT_I2H_DISABLE_RSP: |
| 3627 | if (fcport->msgtag == i2hmsg.penable_rsp->msgtag) |
| 3628 | bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP); |
| 3629 | break; |
| 3630 | |
| 3631 | case BFI_FCPORT_I2H_EVENT: |
| 3632 | if (i2hmsg.event->link_state.linkstate == BFA_PORT_LINKUP) |
| 3633 | bfa_sm_send_event(fcport, BFA_FCPORT_SM_LINKUP); |
Krishna Gudipati | 04ea657 | 2012-09-21 17:26:18 -0700 | [diff] [blame^] | 3634 | else { |
| 3635 | if (i2hmsg.event->link_state.linkstate_rsn == |
| 3636 | BFA_PORT_LINKSTATE_RSN_FAA_MISCONFIG) |
| 3637 | bfa_sm_send_event(fcport, |
| 3638 | BFA_FCPORT_SM_FAA_MISCONFIG); |
| 3639 | else |
| 3640 | bfa_sm_send_event(fcport, |
| 3641 | BFA_FCPORT_SM_LINKDOWN); |
| 3642 | } |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3643 | break; |
| 3644 | |
| 3645 | case BFI_FCPORT_I2H_TRUNK_SCN: |
| 3646 | bfa_trunk_scn(fcport, i2hmsg.trunk_scn); |
| 3647 | break; |
| 3648 | |
| 3649 | case BFI_FCPORT_I2H_STATS_GET_RSP: |
| 3650 | /* |
| 3651 | * check for timer pop before processing the rsp |
| 3652 | */ |
Krishna Gudipati | 37ea055 | 2011-07-20 17:02:11 -0700 | [diff] [blame] | 3653 | if (list_empty(&fcport->stats_pending_q) || |
| 3654 | (fcport->stats_status == BFA_STATUS_ETIMER)) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3655 | break; |
| 3656 | |
| 3657 | bfa_timer_stop(&fcport->timer); |
| 3658 | fcport->stats_status = i2hmsg.pstatsget_rsp->status; |
Krishna Gudipati | 37ea055 | 2011-07-20 17:02:11 -0700 | [diff] [blame] | 3659 | __bfa_cb_fcport_stats_get(fcport, BFA_TRUE); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3660 | break; |
| 3661 | |
| 3662 | case BFI_FCPORT_I2H_STATS_CLEAR_RSP: |
| 3663 | /* |
| 3664 | * check for timer pop before processing the rsp |
| 3665 | */ |
Krishna Gudipati | 37ea055 | 2011-07-20 17:02:11 -0700 | [diff] [blame] | 3666 | if (list_empty(&fcport->statsclr_pending_q) || |
| 3667 | (fcport->stats_status == BFA_STATUS_ETIMER)) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3668 | break; |
| 3669 | |
| 3670 | bfa_timer_stop(&fcport->timer); |
| 3671 | fcport->stats_status = BFA_STATUS_OK; |
Krishna Gudipati | 37ea055 | 2011-07-20 17:02:11 -0700 | [diff] [blame] | 3672 | __bfa_cb_fcport_stats_clr(fcport, BFA_TRUE); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3673 | break; |
| 3674 | |
| 3675 | case BFI_FCPORT_I2H_ENABLE_AEN: |
| 3676 | bfa_sm_send_event(fcport, BFA_FCPORT_SM_ENABLE); |
| 3677 | break; |
| 3678 | |
| 3679 | case BFI_FCPORT_I2H_DISABLE_AEN: |
| 3680 | bfa_sm_send_event(fcport, BFA_FCPORT_SM_DISABLE); |
| 3681 | break; |
| 3682 | |
| 3683 | default: |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 3684 | WARN_ON(1); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3685 | break; |
| 3686 | } |
| 3687 | } |
| 3688 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3689 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3690 | * Registered callback for port events. |
| 3691 | */ |
| 3692 | void |
| 3693 | bfa_fcport_event_register(struct bfa_s *bfa, |
| 3694 | void (*cbfn) (void *cbarg, |
| 3695 | enum bfa_port_linkstate event), |
| 3696 | void *cbarg) |
| 3697 | { |
| 3698 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3699 | |
| 3700 | fcport->event_cbfn = cbfn; |
| 3701 | fcport->event_cbarg = cbarg; |
| 3702 | } |
| 3703 | |
| 3704 | bfa_status_t |
| 3705 | bfa_fcport_enable(struct bfa_s *bfa) |
| 3706 | { |
| 3707 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3708 | |
Krishna Gudipati | 43ffdf4 | 2011-06-13 15:46:21 -0700 | [diff] [blame] | 3709 | if (bfa_fcport_is_pbcdisabled(bfa)) |
| 3710 | return BFA_STATUS_PBC; |
| 3711 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3712 | if (bfa_ioc_is_disabled(&bfa->ioc)) |
| 3713 | return BFA_STATUS_IOC_DISABLED; |
| 3714 | |
| 3715 | if (fcport->diag_busy) |
| 3716 | return BFA_STATUS_DIAG_BUSY; |
| 3717 | |
| 3718 | bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_ENABLE); |
| 3719 | return BFA_STATUS_OK; |
| 3720 | } |
| 3721 | |
| 3722 | bfa_status_t |
| 3723 | bfa_fcport_disable(struct bfa_s *bfa) |
| 3724 | { |
Krishna Gudipati | 43ffdf4 | 2011-06-13 15:46:21 -0700 | [diff] [blame] | 3725 | if (bfa_fcport_is_pbcdisabled(bfa)) |
| 3726 | return BFA_STATUS_PBC; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3727 | |
| 3728 | if (bfa_ioc_is_disabled(&bfa->ioc)) |
| 3729 | return BFA_STATUS_IOC_DISABLED; |
| 3730 | |
| 3731 | bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_DISABLE); |
| 3732 | return BFA_STATUS_OK; |
| 3733 | } |
| 3734 | |
Krishna Gudipati | 43ffdf4 | 2011-06-13 15:46:21 -0700 | [diff] [blame] | 3735 | /* If PBC is disabled on port, return error */ |
| 3736 | bfa_status_t |
| 3737 | bfa_fcport_is_pbcdisabled(struct bfa_s *bfa) |
| 3738 | { |
| 3739 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3740 | struct bfa_iocfc_s *iocfc = &bfa->iocfc; |
| 3741 | struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp; |
| 3742 | |
| 3743 | if (cfgrsp->pbc_cfg.port_enabled == BFI_PBC_PORT_DISABLED) { |
| 3744 | bfa_trc(bfa, fcport->pwwn); |
| 3745 | return BFA_STATUS_PBC; |
| 3746 | } |
| 3747 | return BFA_STATUS_OK; |
| 3748 | } |
| 3749 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3750 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3751 | * Configure port speed. |
| 3752 | */ |
| 3753 | bfa_status_t |
| 3754 | bfa_fcport_cfg_speed(struct bfa_s *bfa, enum bfa_port_speed speed) |
| 3755 | { |
| 3756 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3757 | |
| 3758 | bfa_trc(bfa, speed); |
| 3759 | |
| 3760 | if (fcport->cfg.trunked == BFA_TRUE) |
| 3761 | return BFA_STATUS_TRUNK_ENABLED; |
Krishna Gudipati | bc0e2c2 | 2012-09-21 17:23:59 -0700 | [diff] [blame] | 3762 | if ((fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP) && |
| 3763 | (speed == BFA_PORT_SPEED_16GBPS)) |
| 3764 | return BFA_STATUS_UNSUPP_SPEED; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3765 | if ((speed != BFA_PORT_SPEED_AUTO) && (speed > fcport->speed_sup)) { |
| 3766 | bfa_trc(bfa, fcport->speed_sup); |
| 3767 | return BFA_STATUS_UNSUPP_SPEED; |
| 3768 | } |
| 3769 | |
Krishna Gudipati | bd5a026 | 2012-03-13 17:41:02 -0700 | [diff] [blame] | 3770 | /* Port speed entered needs to be checked */ |
| 3771 | if (bfa_ioc_get_type(&fcport->bfa->ioc) == BFA_IOC_TYPE_FC) { |
| 3772 | /* For CT2, 1G is not supported */ |
| 3773 | if ((speed == BFA_PORT_SPEED_1GBPS) && |
| 3774 | (bfa_asic_id_ct2(bfa->ioc.pcidev.device_id))) |
| 3775 | return BFA_STATUS_UNSUPP_SPEED; |
Krishna Gudipati | a714134 | 2011-06-24 20:23:19 -0700 | [diff] [blame] | 3776 | |
Krishna Gudipati | bd5a026 | 2012-03-13 17:41:02 -0700 | [diff] [blame] | 3777 | /* Already checked for Auto Speed and Max Speed supp */ |
| 3778 | if (!(speed == BFA_PORT_SPEED_1GBPS || |
| 3779 | speed == BFA_PORT_SPEED_2GBPS || |
| 3780 | speed == BFA_PORT_SPEED_4GBPS || |
| 3781 | speed == BFA_PORT_SPEED_8GBPS || |
| 3782 | speed == BFA_PORT_SPEED_16GBPS || |
| 3783 | speed == BFA_PORT_SPEED_AUTO)) |
| 3784 | return BFA_STATUS_UNSUPP_SPEED; |
| 3785 | } else { |
| 3786 | if (speed != BFA_PORT_SPEED_10GBPS) |
| 3787 | return BFA_STATUS_UNSUPP_SPEED; |
Krishna Gudipati | a714134 | 2011-06-24 20:23:19 -0700 | [diff] [blame] | 3788 | } |
| 3789 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3790 | fcport->cfg.speed = speed; |
| 3791 | |
| 3792 | return BFA_STATUS_OK; |
| 3793 | } |
| 3794 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3795 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3796 | * Get current speed. |
| 3797 | */ |
| 3798 | enum bfa_port_speed |
| 3799 | bfa_fcport_get_speed(struct bfa_s *bfa) |
| 3800 | { |
| 3801 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3802 | |
| 3803 | return fcport->speed; |
| 3804 | } |
| 3805 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3806 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3807 | * Configure port topology. |
| 3808 | */ |
| 3809 | bfa_status_t |
| 3810 | bfa_fcport_cfg_topology(struct bfa_s *bfa, enum bfa_port_topology topology) |
| 3811 | { |
| 3812 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3813 | |
| 3814 | bfa_trc(bfa, topology); |
| 3815 | bfa_trc(bfa, fcport->cfg.topology); |
| 3816 | |
| 3817 | switch (topology) { |
| 3818 | case BFA_PORT_TOPOLOGY_P2P: |
Krishna Gudipati | bc0e2c2 | 2012-09-21 17:23:59 -0700 | [diff] [blame] | 3819 | break; |
| 3820 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3821 | case BFA_PORT_TOPOLOGY_LOOP: |
Krishna Gudipati | bc0e2c2 | 2012-09-21 17:23:59 -0700 | [diff] [blame] | 3822 | if ((bfa_fcport_is_qos_enabled(bfa) != BFA_FALSE) || |
| 3823 | (fcport->qos_attr.state != BFA_QOS_DISABLED)) |
| 3824 | return BFA_STATUS_ERROR_QOS_ENABLED; |
| 3825 | if (fcport->cfg.ratelimit != BFA_FALSE) |
| 3826 | return BFA_STATUS_ERROR_TRL_ENABLED; |
| 3827 | if ((bfa_fcport_is_trunk_enabled(bfa) != BFA_FALSE) || |
| 3828 | (fcport->trunk.attr.state != BFA_TRUNK_DISABLED)) |
| 3829 | return BFA_STATUS_ERROR_TRUNK_ENABLED; |
| 3830 | if ((bfa_fcport_get_speed(bfa) == BFA_PORT_SPEED_16GBPS) || |
| 3831 | (fcport->cfg.speed == BFA_PORT_SPEED_16GBPS)) |
| 3832 | return BFA_STATUS_UNSUPP_SPEED; |
| 3833 | if (bfa_mfg_is_mezz(bfa->ioc.attr->card_type)) |
| 3834 | return BFA_STATUS_LOOP_UNSUPP_MEZZ; |
Krishna Gudipati | e353546 | 2012-09-21 17:26:07 -0700 | [diff] [blame] | 3835 | if (bfa_fcport_is_dport(bfa) != BFA_FALSE) |
| 3836 | return BFA_STATUS_DPORT_ERR; |
Krishna Gudipati | bc0e2c2 | 2012-09-21 17:23:59 -0700 | [diff] [blame] | 3837 | break; |
| 3838 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3839 | case BFA_PORT_TOPOLOGY_AUTO: |
| 3840 | break; |
| 3841 | |
| 3842 | default: |
| 3843 | return BFA_STATUS_EINVAL; |
| 3844 | } |
| 3845 | |
| 3846 | fcport->cfg.topology = topology; |
| 3847 | return BFA_STATUS_OK; |
| 3848 | } |
| 3849 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3850 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3851 | * Get current topology. |
| 3852 | */ |
| 3853 | enum bfa_port_topology |
| 3854 | bfa_fcport_get_topology(struct bfa_s *bfa) |
| 3855 | { |
| 3856 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3857 | |
| 3858 | return fcport->topology; |
| 3859 | } |
| 3860 | |
Krishna Gudipati | bc0e2c2 | 2012-09-21 17:23:59 -0700 | [diff] [blame] | 3861 | /** |
| 3862 | * Get config topology. |
| 3863 | */ |
| 3864 | enum bfa_port_topology |
| 3865 | bfa_fcport_get_cfg_topology(struct bfa_s *bfa) |
| 3866 | { |
| 3867 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3868 | |
| 3869 | return fcport->cfg.topology; |
| 3870 | } |
| 3871 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3872 | bfa_status_t |
| 3873 | bfa_fcport_cfg_hardalpa(struct bfa_s *bfa, u8 alpa) |
| 3874 | { |
| 3875 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3876 | |
| 3877 | bfa_trc(bfa, alpa); |
| 3878 | bfa_trc(bfa, fcport->cfg.cfg_hardalpa); |
| 3879 | bfa_trc(bfa, fcport->cfg.hardalpa); |
| 3880 | |
| 3881 | fcport->cfg.cfg_hardalpa = BFA_TRUE; |
| 3882 | fcport->cfg.hardalpa = alpa; |
| 3883 | |
| 3884 | return BFA_STATUS_OK; |
| 3885 | } |
| 3886 | |
| 3887 | bfa_status_t |
| 3888 | bfa_fcport_clr_hardalpa(struct bfa_s *bfa) |
| 3889 | { |
| 3890 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3891 | |
| 3892 | bfa_trc(bfa, fcport->cfg.cfg_hardalpa); |
| 3893 | bfa_trc(bfa, fcport->cfg.hardalpa); |
| 3894 | |
| 3895 | fcport->cfg.cfg_hardalpa = BFA_FALSE; |
| 3896 | return BFA_STATUS_OK; |
| 3897 | } |
| 3898 | |
| 3899 | bfa_boolean_t |
| 3900 | bfa_fcport_get_hardalpa(struct bfa_s *bfa, u8 *alpa) |
| 3901 | { |
| 3902 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3903 | |
| 3904 | *alpa = fcport->cfg.hardalpa; |
| 3905 | return fcport->cfg.cfg_hardalpa; |
| 3906 | } |
| 3907 | |
| 3908 | u8 |
| 3909 | bfa_fcport_get_myalpa(struct bfa_s *bfa) |
| 3910 | { |
| 3911 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3912 | |
| 3913 | return fcport->myalpa; |
| 3914 | } |
| 3915 | |
| 3916 | bfa_status_t |
| 3917 | bfa_fcport_cfg_maxfrsize(struct bfa_s *bfa, u16 maxfrsize) |
| 3918 | { |
| 3919 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3920 | |
| 3921 | bfa_trc(bfa, maxfrsize); |
| 3922 | bfa_trc(bfa, fcport->cfg.maxfrsize); |
| 3923 | |
| 3924 | /* with in range */ |
| 3925 | if ((maxfrsize > FC_MAX_PDUSZ) || (maxfrsize < FC_MIN_PDUSZ)) |
| 3926 | return BFA_STATUS_INVLD_DFSZ; |
| 3927 | |
| 3928 | /* power of 2, if not the max frame size of 2112 */ |
| 3929 | if ((maxfrsize != FC_MAX_PDUSZ) && (maxfrsize & (maxfrsize - 1))) |
| 3930 | return BFA_STATUS_INVLD_DFSZ; |
| 3931 | |
| 3932 | fcport->cfg.maxfrsize = maxfrsize; |
| 3933 | return BFA_STATUS_OK; |
| 3934 | } |
| 3935 | |
| 3936 | u16 |
| 3937 | bfa_fcport_get_maxfrsize(struct bfa_s *bfa) |
| 3938 | { |
| 3939 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3940 | |
| 3941 | return fcport->cfg.maxfrsize; |
| 3942 | } |
| 3943 | |
| 3944 | u8 |
| 3945 | bfa_fcport_get_rx_bbcredit(struct bfa_s *bfa) |
| 3946 | { |
Krishna Gudipati | bc0e2c2 | 2012-09-21 17:23:59 -0700 | [diff] [blame] | 3947 | if (bfa_fcport_get_topology(bfa) != BFA_PORT_TOPOLOGY_LOOP) |
| 3948 | return (BFA_FCPORT_MOD(bfa))->cfg.rx_bbcredit; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3949 | |
Krishna Gudipati | bc0e2c2 | 2012-09-21 17:23:59 -0700 | [diff] [blame] | 3950 | else |
| 3951 | return 0; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3952 | } |
| 3953 | |
| 3954 | void |
Krishna Gudipati | be540a9 | 2011-06-13 15:53:04 -0700 | [diff] [blame] | 3955 | bfa_fcport_set_tx_bbcredit(struct bfa_s *bfa, u16 tx_bbcredit, u8 bb_scn) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3956 | { |
| 3957 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3958 | |
| 3959 | fcport->cfg.tx_bbcredit = (u8)tx_bbcredit; |
Krishna Gudipati | be540a9 | 2011-06-13 15:53:04 -0700 | [diff] [blame] | 3960 | fcport->cfg.bb_scn = bb_scn; |
| 3961 | if (bb_scn) |
| 3962 | fcport->bbsc_op_state = BFA_TRUE; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3963 | } |
| 3964 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3965 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3966 | * Get port attributes. |
| 3967 | */ |
| 3968 | |
| 3969 | wwn_t |
| 3970 | bfa_fcport_get_wwn(struct bfa_s *bfa, bfa_boolean_t node) |
| 3971 | { |
| 3972 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3973 | if (node) |
| 3974 | return fcport->nwwn; |
| 3975 | else |
| 3976 | return fcport->pwwn; |
| 3977 | } |
| 3978 | |
| 3979 | void |
| 3980 | bfa_fcport_get_attr(struct bfa_s *bfa, struct bfa_port_attr_s *attr) |
| 3981 | { |
| 3982 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3983 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 3984 | memset(attr, 0, sizeof(struct bfa_port_attr_s)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3985 | |
| 3986 | attr->nwwn = fcport->nwwn; |
| 3987 | attr->pwwn = fcport->pwwn; |
| 3988 | |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 3989 | attr->factorypwwn = bfa->ioc.attr->mfg_pwwn; |
| 3990 | attr->factorynwwn = bfa->ioc.attr->mfg_nwwn; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3991 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 3992 | memcpy(&attr->pport_cfg, &fcport->cfg, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3993 | sizeof(struct bfa_port_cfg_s)); |
| 3994 | /* speed attributes */ |
| 3995 | attr->pport_cfg.speed = fcport->cfg.speed; |
| 3996 | attr->speed_supported = fcport->speed_sup; |
| 3997 | attr->speed = fcport->speed; |
| 3998 | attr->cos_supported = FC_CLASS_3; |
| 3999 | |
| 4000 | /* topology attributes */ |
| 4001 | attr->pport_cfg.topology = fcport->cfg.topology; |
| 4002 | attr->topology = fcport->topology; |
| 4003 | attr->pport_cfg.trunked = fcport->cfg.trunked; |
| 4004 | |
| 4005 | /* beacon attributes */ |
| 4006 | attr->beacon = fcport->beacon; |
| 4007 | attr->link_e2e_beacon = fcport->link_e2e_beacon; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4008 | |
| 4009 | attr->pport_cfg.path_tov = bfa_fcpim_path_tov_get(bfa); |
| 4010 | attr->pport_cfg.q_depth = bfa_fcpim_qdepth_get(bfa); |
| 4011 | attr->port_state = bfa_sm_to_state(hal_port_sm_table, fcport->sm); |
Krishna Gudipati | be540a9 | 2011-06-13 15:53:04 -0700 | [diff] [blame] | 4012 | attr->bbsc_op_status = fcport->bbsc_op_state; |
Krishna Gudipati | 43ffdf4 | 2011-06-13 15:46:21 -0700 | [diff] [blame] | 4013 | |
| 4014 | /* PBC Disabled State */ |
| 4015 | if (bfa_fcport_is_pbcdisabled(bfa)) |
| 4016 | attr->port_state = BFA_PORT_ST_PREBOOT_DISABLED; |
| 4017 | else { |
| 4018 | if (bfa_ioc_is_disabled(&fcport->bfa->ioc)) |
| 4019 | attr->port_state = BFA_PORT_ST_IOCDIS; |
| 4020 | else if (bfa_ioc_fw_mismatch(&fcport->bfa->ioc)) |
| 4021 | attr->port_state = BFA_PORT_ST_FWMISMATCH; |
| 4022 | } |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4023 | |
| 4024 | /* FCoE vlan */ |
| 4025 | attr->fcoe_vlan = fcport->fcoe_vlan; |
| 4026 | } |
| 4027 | |
| 4028 | #define BFA_FCPORT_STATS_TOV 1000 |
| 4029 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4030 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4031 | * Fetch port statistics (FCQoS or FCoE). |
| 4032 | */ |
| 4033 | bfa_status_t |
Krishna Gudipati | 37ea055 | 2011-07-20 17:02:11 -0700 | [diff] [blame] | 4034 | bfa_fcport_get_stats(struct bfa_s *bfa, struct bfa_cb_pending_q_s *cb) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4035 | { |
| 4036 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 4037 | |
Krishna Gudipati | 37ea055 | 2011-07-20 17:02:11 -0700 | [diff] [blame] | 4038 | if (bfa_ioc_is_disabled(&bfa->ioc)) |
| 4039 | return BFA_STATUS_IOC_DISABLED; |
| 4040 | |
| 4041 | if (!list_empty(&fcport->statsclr_pending_q)) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4042 | return BFA_STATUS_DEVBUSY; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4043 | |
Krishna Gudipati | 37ea055 | 2011-07-20 17:02:11 -0700 | [diff] [blame] | 4044 | if (list_empty(&fcport->stats_pending_q)) { |
| 4045 | list_add_tail(&cb->hcb_qe.qe, &fcport->stats_pending_q); |
| 4046 | bfa_fcport_send_stats_get(fcport); |
| 4047 | bfa_timer_start(bfa, &fcport->timer, |
| 4048 | bfa_fcport_stats_get_timeout, |
| 4049 | fcport, BFA_FCPORT_STATS_TOV); |
| 4050 | } else |
| 4051 | list_add_tail(&cb->hcb_qe.qe, &fcport->stats_pending_q); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4052 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4053 | return BFA_STATUS_OK; |
| 4054 | } |
| 4055 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4056 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4057 | * Reset port statistics (FCQoS or FCoE). |
| 4058 | */ |
| 4059 | bfa_status_t |
Krishna Gudipati | 37ea055 | 2011-07-20 17:02:11 -0700 | [diff] [blame] | 4060 | bfa_fcport_clear_stats(struct bfa_s *bfa, struct bfa_cb_pending_q_s *cb) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4061 | { |
| 4062 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 4063 | |
Krishna Gudipati | 37ea055 | 2011-07-20 17:02:11 -0700 | [diff] [blame] | 4064 | if (!list_empty(&fcport->stats_pending_q)) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4065 | return BFA_STATUS_DEVBUSY; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4066 | |
Krishna Gudipati | 37ea055 | 2011-07-20 17:02:11 -0700 | [diff] [blame] | 4067 | if (list_empty(&fcport->statsclr_pending_q)) { |
| 4068 | list_add_tail(&cb->hcb_qe.qe, &fcport->statsclr_pending_q); |
| 4069 | bfa_fcport_send_stats_clear(fcport); |
| 4070 | bfa_timer_start(bfa, &fcport->timer, |
| 4071 | bfa_fcport_stats_clr_timeout, |
| 4072 | fcport, BFA_FCPORT_STATS_TOV); |
| 4073 | } else |
| 4074 | list_add_tail(&cb->hcb_qe.qe, &fcport->statsclr_pending_q); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4075 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4076 | return BFA_STATUS_OK; |
| 4077 | } |
| 4078 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4079 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4080 | * Fetch port attributes. |
| 4081 | */ |
| 4082 | bfa_boolean_t |
| 4083 | bfa_fcport_is_disabled(struct bfa_s *bfa) |
| 4084 | { |
| 4085 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 4086 | |
| 4087 | return bfa_sm_to_state(hal_port_sm_table, fcport->sm) == |
| 4088 | BFA_PORT_ST_DISABLED; |
| 4089 | |
| 4090 | } |
| 4091 | |
| 4092 | bfa_boolean_t |
Krishna Gudipati | e353546 | 2012-09-21 17:26:07 -0700 | [diff] [blame] | 4093 | bfa_fcport_is_dport(struct bfa_s *bfa) |
| 4094 | { |
| 4095 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 4096 | |
| 4097 | return (bfa_sm_to_state(hal_port_sm_table, fcport->sm) == |
| 4098 | BFA_PORT_ST_DPORT); |
| 4099 | } |
| 4100 | |
| 4101 | bfa_boolean_t |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4102 | bfa_fcport_is_ratelim(struct bfa_s *bfa) |
| 4103 | { |
| 4104 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 4105 | |
| 4106 | return fcport->cfg.ratelimit ? BFA_TRUE : BFA_FALSE; |
| 4107 | |
| 4108 | } |
| 4109 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4110 | /* |
Krishna Gudipati | a714134 | 2011-06-24 20:23:19 -0700 | [diff] [blame] | 4111 | * Enable/Disable FAA feature in port config |
| 4112 | */ |
| 4113 | void |
| 4114 | bfa_fcport_cfg_faa(struct bfa_s *bfa, u8 state) |
| 4115 | { |
| 4116 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 4117 | |
| 4118 | bfa_trc(bfa, state); |
| 4119 | fcport->cfg.faa_state = state; |
| 4120 | } |
| 4121 | |
| 4122 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4123 | * Get default minimum ratelim speed |
| 4124 | */ |
| 4125 | enum bfa_port_speed |
| 4126 | bfa_fcport_get_ratelim_speed(struct bfa_s *bfa) |
| 4127 | { |
| 4128 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 4129 | |
| 4130 | bfa_trc(bfa, fcport->cfg.trl_def_speed); |
| 4131 | return fcport->cfg.trl_def_speed; |
| 4132 | |
| 4133 | } |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4134 | |
Krishna Gudipati | 3d7fc66 | 2011-06-24 20:28:17 -0700 | [diff] [blame] | 4135 | void |
| 4136 | bfa_fcport_beacon(void *dev, bfa_boolean_t beacon, |
| 4137 | bfa_boolean_t link_e2e_beacon) |
| 4138 | { |
| 4139 | struct bfa_s *bfa = dev; |
| 4140 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 4141 | |
| 4142 | bfa_trc(bfa, beacon); |
| 4143 | bfa_trc(bfa, link_e2e_beacon); |
| 4144 | bfa_trc(bfa, fcport->beacon); |
| 4145 | bfa_trc(bfa, fcport->link_e2e_beacon); |
| 4146 | |
| 4147 | fcport->beacon = beacon; |
| 4148 | fcport->link_e2e_beacon = link_e2e_beacon; |
| 4149 | } |
| 4150 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4151 | bfa_boolean_t |
| 4152 | bfa_fcport_is_linkup(struct bfa_s *bfa) |
| 4153 | { |
| 4154 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 4155 | |
| 4156 | return (!fcport->cfg.trunked && |
| 4157 | bfa_sm_cmp_state(fcport, bfa_fcport_sm_linkup)) || |
| 4158 | (fcport->cfg.trunked && |
| 4159 | fcport->trunk.attr.state == BFA_TRUNK_ONLINE); |
| 4160 | } |
| 4161 | |
| 4162 | bfa_boolean_t |
| 4163 | bfa_fcport_is_qos_enabled(struct bfa_s *bfa) |
| 4164 | { |
| 4165 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 4166 | |
| 4167 | return fcport->cfg.qos_enabled; |
| 4168 | } |
| 4169 | |
Krishna Gudipati | be540a9 | 2011-06-13 15:53:04 -0700 | [diff] [blame] | 4170 | bfa_boolean_t |
| 4171 | bfa_fcport_is_trunk_enabled(struct bfa_s *bfa) |
| 4172 | { |
| 4173 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 4174 | |
| 4175 | return fcport->cfg.trunked; |
| 4176 | } |
| 4177 | |
Krishna Gudipati | e353546 | 2012-09-21 17:26:07 -0700 | [diff] [blame] | 4178 | void |
| 4179 | bfa_fcport_dportenable(struct bfa_s *bfa) |
| 4180 | { |
| 4181 | /* |
| 4182 | * Assume caller check for port is in disable state |
| 4183 | */ |
| 4184 | bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_DPORTENABLE); |
| 4185 | bfa_port_set_dportenabled(&bfa->modules.port, BFA_TRUE); |
| 4186 | } |
| 4187 | |
| 4188 | void |
| 4189 | bfa_fcport_dportdisable(struct bfa_s *bfa) |
| 4190 | { |
| 4191 | /* |
| 4192 | * Assume caller check for port is in disable state |
| 4193 | */ |
| 4194 | bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_DPORTDISABLE); |
| 4195 | bfa_port_set_dportenabled(&bfa->modules.port, BFA_FALSE); |
| 4196 | } |
| 4197 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4198 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4199 | * Rport State machine functions |
| 4200 | */ |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4201 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4202 | * Beginning state, only online event expected. |
| 4203 | */ |
| 4204 | static void |
| 4205 | bfa_rport_sm_uninit(struct bfa_rport_s *rp, enum bfa_rport_event event) |
| 4206 | { |
| 4207 | bfa_trc(rp->bfa, rp->rport_tag); |
| 4208 | bfa_trc(rp->bfa, event); |
| 4209 | |
| 4210 | switch (event) { |
| 4211 | case BFA_RPORT_SM_CREATE: |
| 4212 | bfa_stats(rp, sm_un_cr); |
| 4213 | bfa_sm_set_state(rp, bfa_rport_sm_created); |
| 4214 | break; |
| 4215 | |
| 4216 | default: |
| 4217 | bfa_stats(rp, sm_un_unexp); |
| 4218 | bfa_sm_fault(rp->bfa, event); |
| 4219 | } |
| 4220 | } |
| 4221 | |
| 4222 | static void |
| 4223 | bfa_rport_sm_created(struct bfa_rport_s *rp, enum bfa_rport_event event) |
| 4224 | { |
| 4225 | bfa_trc(rp->bfa, rp->rport_tag); |
| 4226 | bfa_trc(rp->bfa, event); |
| 4227 | |
| 4228 | switch (event) { |
| 4229 | case BFA_RPORT_SM_ONLINE: |
| 4230 | bfa_stats(rp, sm_cr_on); |
| 4231 | if (bfa_rport_send_fwcreate(rp)) |
| 4232 | bfa_sm_set_state(rp, bfa_rport_sm_fwcreate); |
| 4233 | else |
| 4234 | bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull); |
| 4235 | break; |
| 4236 | |
| 4237 | case BFA_RPORT_SM_DELETE: |
| 4238 | bfa_stats(rp, sm_cr_del); |
| 4239 | bfa_sm_set_state(rp, bfa_rport_sm_uninit); |
| 4240 | bfa_rport_free(rp); |
| 4241 | break; |
| 4242 | |
| 4243 | case BFA_RPORT_SM_HWFAIL: |
| 4244 | bfa_stats(rp, sm_cr_hwf); |
| 4245 | bfa_sm_set_state(rp, bfa_rport_sm_iocdisable); |
| 4246 | break; |
| 4247 | |
| 4248 | default: |
| 4249 | bfa_stats(rp, sm_cr_unexp); |
| 4250 | bfa_sm_fault(rp->bfa, event); |
| 4251 | } |
| 4252 | } |
| 4253 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4254 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4255 | * Waiting for rport create response from firmware. |
| 4256 | */ |
| 4257 | static void |
| 4258 | bfa_rport_sm_fwcreate(struct bfa_rport_s *rp, enum bfa_rport_event event) |
| 4259 | { |
| 4260 | bfa_trc(rp->bfa, rp->rport_tag); |
| 4261 | bfa_trc(rp->bfa, event); |
| 4262 | |
| 4263 | switch (event) { |
| 4264 | case BFA_RPORT_SM_FWRSP: |
| 4265 | bfa_stats(rp, sm_fwc_rsp); |
| 4266 | bfa_sm_set_state(rp, bfa_rport_sm_online); |
| 4267 | bfa_rport_online_cb(rp); |
| 4268 | break; |
| 4269 | |
| 4270 | case BFA_RPORT_SM_DELETE: |
| 4271 | bfa_stats(rp, sm_fwc_del); |
| 4272 | bfa_sm_set_state(rp, bfa_rport_sm_delete_pending); |
| 4273 | break; |
| 4274 | |
| 4275 | case BFA_RPORT_SM_OFFLINE: |
| 4276 | bfa_stats(rp, sm_fwc_off); |
| 4277 | bfa_sm_set_state(rp, bfa_rport_sm_offline_pending); |
| 4278 | break; |
| 4279 | |
| 4280 | case BFA_RPORT_SM_HWFAIL: |
| 4281 | bfa_stats(rp, sm_fwc_hwf); |
| 4282 | bfa_sm_set_state(rp, bfa_rport_sm_iocdisable); |
| 4283 | break; |
| 4284 | |
| 4285 | default: |
| 4286 | bfa_stats(rp, sm_fwc_unexp); |
| 4287 | bfa_sm_fault(rp->bfa, event); |
| 4288 | } |
| 4289 | } |
| 4290 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4291 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4292 | * Request queue is full, awaiting queue resume to send create request. |
| 4293 | */ |
| 4294 | static void |
| 4295 | bfa_rport_sm_fwcreate_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event) |
| 4296 | { |
| 4297 | bfa_trc(rp->bfa, rp->rport_tag); |
| 4298 | bfa_trc(rp->bfa, event); |
| 4299 | |
| 4300 | switch (event) { |
| 4301 | case BFA_RPORT_SM_QRESUME: |
| 4302 | bfa_sm_set_state(rp, bfa_rport_sm_fwcreate); |
| 4303 | bfa_rport_send_fwcreate(rp); |
| 4304 | break; |
| 4305 | |
| 4306 | case BFA_RPORT_SM_DELETE: |
| 4307 | bfa_stats(rp, sm_fwc_del); |
| 4308 | bfa_sm_set_state(rp, bfa_rport_sm_uninit); |
| 4309 | bfa_reqq_wcancel(&rp->reqq_wait); |
| 4310 | bfa_rport_free(rp); |
| 4311 | break; |
| 4312 | |
| 4313 | case BFA_RPORT_SM_OFFLINE: |
| 4314 | bfa_stats(rp, sm_fwc_off); |
| 4315 | bfa_sm_set_state(rp, bfa_rport_sm_offline); |
| 4316 | bfa_reqq_wcancel(&rp->reqq_wait); |
| 4317 | bfa_rport_offline_cb(rp); |
| 4318 | break; |
| 4319 | |
| 4320 | case BFA_RPORT_SM_HWFAIL: |
| 4321 | bfa_stats(rp, sm_fwc_hwf); |
| 4322 | bfa_sm_set_state(rp, bfa_rport_sm_iocdisable); |
| 4323 | bfa_reqq_wcancel(&rp->reqq_wait); |
| 4324 | break; |
| 4325 | |
| 4326 | default: |
| 4327 | bfa_stats(rp, sm_fwc_unexp); |
| 4328 | bfa_sm_fault(rp->bfa, event); |
| 4329 | } |
| 4330 | } |
| 4331 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4332 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4333 | * Online state - normal parking state. |
| 4334 | */ |
| 4335 | static void |
| 4336 | bfa_rport_sm_online(struct bfa_rport_s *rp, enum bfa_rport_event event) |
| 4337 | { |
| 4338 | struct bfi_rport_qos_scn_s *qos_scn; |
| 4339 | |
| 4340 | bfa_trc(rp->bfa, rp->rport_tag); |
| 4341 | bfa_trc(rp->bfa, event); |
| 4342 | |
| 4343 | switch (event) { |
| 4344 | case BFA_RPORT_SM_OFFLINE: |
| 4345 | bfa_stats(rp, sm_on_off); |
| 4346 | if (bfa_rport_send_fwdelete(rp)) |
| 4347 | bfa_sm_set_state(rp, bfa_rport_sm_fwdelete); |
| 4348 | else |
| 4349 | bfa_sm_set_state(rp, bfa_rport_sm_fwdelete_qfull); |
| 4350 | break; |
| 4351 | |
| 4352 | case BFA_RPORT_SM_DELETE: |
| 4353 | bfa_stats(rp, sm_on_del); |
| 4354 | if (bfa_rport_send_fwdelete(rp)) |
| 4355 | bfa_sm_set_state(rp, bfa_rport_sm_deleting); |
| 4356 | else |
| 4357 | bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull); |
| 4358 | break; |
| 4359 | |
| 4360 | case BFA_RPORT_SM_HWFAIL: |
| 4361 | bfa_stats(rp, sm_on_hwf); |
| 4362 | bfa_sm_set_state(rp, bfa_rport_sm_iocdisable); |
| 4363 | break; |
| 4364 | |
| 4365 | case BFA_RPORT_SM_SET_SPEED: |
| 4366 | bfa_rport_send_fwspeed(rp); |
| 4367 | break; |
| 4368 | |
| 4369 | case BFA_RPORT_SM_QOS_SCN: |
| 4370 | qos_scn = (struct bfi_rport_qos_scn_s *) rp->event_arg.fw_msg; |
| 4371 | rp->qos_attr = qos_scn->new_qos_attr; |
| 4372 | bfa_trc(rp->bfa, qos_scn->old_qos_attr.qos_flow_id); |
| 4373 | bfa_trc(rp->bfa, qos_scn->new_qos_attr.qos_flow_id); |
| 4374 | bfa_trc(rp->bfa, qos_scn->old_qos_attr.qos_priority); |
| 4375 | bfa_trc(rp->bfa, qos_scn->new_qos_attr.qos_priority); |
| 4376 | |
| 4377 | qos_scn->old_qos_attr.qos_flow_id = |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 4378 | be32_to_cpu(qos_scn->old_qos_attr.qos_flow_id); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4379 | qos_scn->new_qos_attr.qos_flow_id = |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 4380 | be32_to_cpu(qos_scn->new_qos_attr.qos_flow_id); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4381 | |
| 4382 | if (qos_scn->old_qos_attr.qos_flow_id != |
| 4383 | qos_scn->new_qos_attr.qos_flow_id) |
| 4384 | bfa_cb_rport_qos_scn_flowid(rp->rport_drv, |
| 4385 | qos_scn->old_qos_attr, |
| 4386 | qos_scn->new_qos_attr); |
| 4387 | if (qos_scn->old_qos_attr.qos_priority != |
| 4388 | qos_scn->new_qos_attr.qos_priority) |
| 4389 | bfa_cb_rport_qos_scn_prio(rp->rport_drv, |
| 4390 | qos_scn->old_qos_attr, |
| 4391 | qos_scn->new_qos_attr); |
| 4392 | break; |
| 4393 | |
| 4394 | default: |
| 4395 | bfa_stats(rp, sm_on_unexp); |
| 4396 | bfa_sm_fault(rp->bfa, event); |
| 4397 | } |
| 4398 | } |
| 4399 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4400 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4401 | * Firmware rport is being deleted - awaiting f/w response. |
| 4402 | */ |
| 4403 | static void |
| 4404 | bfa_rport_sm_fwdelete(struct bfa_rport_s *rp, enum bfa_rport_event event) |
| 4405 | { |
| 4406 | bfa_trc(rp->bfa, rp->rport_tag); |
| 4407 | bfa_trc(rp->bfa, event); |
| 4408 | |
| 4409 | switch (event) { |
| 4410 | case BFA_RPORT_SM_FWRSP: |
| 4411 | bfa_stats(rp, sm_fwd_rsp); |
| 4412 | bfa_sm_set_state(rp, bfa_rport_sm_offline); |
| 4413 | bfa_rport_offline_cb(rp); |
| 4414 | break; |
| 4415 | |
| 4416 | case BFA_RPORT_SM_DELETE: |
| 4417 | bfa_stats(rp, sm_fwd_del); |
| 4418 | bfa_sm_set_state(rp, bfa_rport_sm_deleting); |
| 4419 | break; |
| 4420 | |
| 4421 | case BFA_RPORT_SM_HWFAIL: |
| 4422 | bfa_stats(rp, sm_fwd_hwf); |
| 4423 | bfa_sm_set_state(rp, bfa_rport_sm_iocdisable); |
| 4424 | bfa_rport_offline_cb(rp); |
| 4425 | break; |
| 4426 | |
| 4427 | default: |
| 4428 | bfa_stats(rp, sm_fwd_unexp); |
| 4429 | bfa_sm_fault(rp->bfa, event); |
| 4430 | } |
| 4431 | } |
| 4432 | |
| 4433 | static void |
| 4434 | bfa_rport_sm_fwdelete_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event) |
| 4435 | { |
| 4436 | bfa_trc(rp->bfa, rp->rport_tag); |
| 4437 | bfa_trc(rp->bfa, event); |
| 4438 | |
| 4439 | switch (event) { |
| 4440 | case BFA_RPORT_SM_QRESUME: |
| 4441 | bfa_sm_set_state(rp, bfa_rport_sm_fwdelete); |
| 4442 | bfa_rport_send_fwdelete(rp); |
| 4443 | break; |
| 4444 | |
| 4445 | case BFA_RPORT_SM_DELETE: |
| 4446 | bfa_stats(rp, sm_fwd_del); |
| 4447 | bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull); |
| 4448 | break; |
| 4449 | |
| 4450 | case BFA_RPORT_SM_HWFAIL: |
| 4451 | bfa_stats(rp, sm_fwd_hwf); |
| 4452 | bfa_sm_set_state(rp, bfa_rport_sm_iocdisable); |
| 4453 | bfa_reqq_wcancel(&rp->reqq_wait); |
| 4454 | bfa_rport_offline_cb(rp); |
| 4455 | break; |
| 4456 | |
| 4457 | default: |
| 4458 | bfa_stats(rp, sm_fwd_unexp); |
| 4459 | bfa_sm_fault(rp->bfa, event); |
| 4460 | } |
| 4461 | } |
| 4462 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4463 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4464 | * Offline state. |
| 4465 | */ |
| 4466 | static void |
| 4467 | bfa_rport_sm_offline(struct bfa_rport_s *rp, enum bfa_rport_event event) |
| 4468 | { |
| 4469 | bfa_trc(rp->bfa, rp->rport_tag); |
| 4470 | bfa_trc(rp->bfa, event); |
| 4471 | |
| 4472 | switch (event) { |
| 4473 | case BFA_RPORT_SM_DELETE: |
| 4474 | bfa_stats(rp, sm_off_del); |
| 4475 | bfa_sm_set_state(rp, bfa_rport_sm_uninit); |
| 4476 | bfa_rport_free(rp); |
| 4477 | break; |
| 4478 | |
| 4479 | case BFA_RPORT_SM_ONLINE: |
| 4480 | bfa_stats(rp, sm_off_on); |
| 4481 | if (bfa_rport_send_fwcreate(rp)) |
| 4482 | bfa_sm_set_state(rp, bfa_rport_sm_fwcreate); |
| 4483 | else |
| 4484 | bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull); |
| 4485 | break; |
| 4486 | |
| 4487 | case BFA_RPORT_SM_HWFAIL: |
| 4488 | bfa_stats(rp, sm_off_hwf); |
| 4489 | bfa_sm_set_state(rp, bfa_rport_sm_iocdisable); |
| 4490 | break; |
| 4491 | |
Krishna Gudipati | 61ba439 | 2012-08-22 19:52:58 -0700 | [diff] [blame] | 4492 | case BFA_RPORT_SM_OFFLINE: |
| 4493 | bfa_rport_offline_cb(rp); |
| 4494 | break; |
| 4495 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4496 | default: |
| 4497 | bfa_stats(rp, sm_off_unexp); |
| 4498 | bfa_sm_fault(rp->bfa, event); |
| 4499 | } |
| 4500 | } |
| 4501 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4502 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4503 | * Rport is deleted, waiting for firmware response to delete. |
| 4504 | */ |
| 4505 | static void |
| 4506 | bfa_rport_sm_deleting(struct bfa_rport_s *rp, enum bfa_rport_event event) |
| 4507 | { |
| 4508 | bfa_trc(rp->bfa, rp->rport_tag); |
| 4509 | bfa_trc(rp->bfa, event); |
| 4510 | |
| 4511 | switch (event) { |
| 4512 | case BFA_RPORT_SM_FWRSP: |
| 4513 | bfa_stats(rp, sm_del_fwrsp); |
| 4514 | bfa_sm_set_state(rp, bfa_rport_sm_uninit); |
| 4515 | bfa_rport_free(rp); |
| 4516 | break; |
| 4517 | |
| 4518 | case BFA_RPORT_SM_HWFAIL: |
| 4519 | bfa_stats(rp, sm_del_hwf); |
| 4520 | bfa_sm_set_state(rp, bfa_rport_sm_uninit); |
| 4521 | bfa_rport_free(rp); |
| 4522 | break; |
| 4523 | |
| 4524 | default: |
| 4525 | bfa_sm_fault(rp->bfa, event); |
| 4526 | } |
| 4527 | } |
| 4528 | |
| 4529 | static void |
| 4530 | bfa_rport_sm_deleting_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event) |
| 4531 | { |
| 4532 | bfa_trc(rp->bfa, rp->rport_tag); |
| 4533 | bfa_trc(rp->bfa, event); |
| 4534 | |
| 4535 | switch (event) { |
| 4536 | case BFA_RPORT_SM_QRESUME: |
| 4537 | bfa_stats(rp, sm_del_fwrsp); |
| 4538 | bfa_sm_set_state(rp, bfa_rport_sm_deleting); |
| 4539 | bfa_rport_send_fwdelete(rp); |
| 4540 | break; |
| 4541 | |
| 4542 | case BFA_RPORT_SM_HWFAIL: |
| 4543 | bfa_stats(rp, sm_del_hwf); |
| 4544 | bfa_sm_set_state(rp, bfa_rport_sm_uninit); |
| 4545 | bfa_reqq_wcancel(&rp->reqq_wait); |
| 4546 | bfa_rport_free(rp); |
| 4547 | break; |
| 4548 | |
| 4549 | default: |
| 4550 | bfa_sm_fault(rp->bfa, event); |
| 4551 | } |
| 4552 | } |
| 4553 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4554 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4555 | * Waiting for rport create response from firmware. A delete is pending. |
| 4556 | */ |
| 4557 | static void |
| 4558 | bfa_rport_sm_delete_pending(struct bfa_rport_s *rp, |
| 4559 | enum bfa_rport_event event) |
| 4560 | { |
| 4561 | bfa_trc(rp->bfa, rp->rport_tag); |
| 4562 | bfa_trc(rp->bfa, event); |
| 4563 | |
| 4564 | switch (event) { |
| 4565 | case BFA_RPORT_SM_FWRSP: |
| 4566 | bfa_stats(rp, sm_delp_fwrsp); |
| 4567 | if (bfa_rport_send_fwdelete(rp)) |
| 4568 | bfa_sm_set_state(rp, bfa_rport_sm_deleting); |
| 4569 | else |
| 4570 | bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull); |
| 4571 | break; |
| 4572 | |
| 4573 | case BFA_RPORT_SM_HWFAIL: |
| 4574 | bfa_stats(rp, sm_delp_hwf); |
| 4575 | bfa_sm_set_state(rp, bfa_rport_sm_uninit); |
| 4576 | bfa_rport_free(rp); |
| 4577 | break; |
| 4578 | |
| 4579 | default: |
| 4580 | bfa_stats(rp, sm_delp_unexp); |
| 4581 | bfa_sm_fault(rp->bfa, event); |
| 4582 | } |
| 4583 | } |
| 4584 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4585 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4586 | * Waiting for rport create response from firmware. Rport offline is pending. |
| 4587 | */ |
| 4588 | static void |
| 4589 | bfa_rport_sm_offline_pending(struct bfa_rport_s *rp, |
| 4590 | enum bfa_rport_event event) |
| 4591 | { |
| 4592 | bfa_trc(rp->bfa, rp->rport_tag); |
| 4593 | bfa_trc(rp->bfa, event); |
| 4594 | |
| 4595 | switch (event) { |
| 4596 | case BFA_RPORT_SM_FWRSP: |
| 4597 | bfa_stats(rp, sm_offp_fwrsp); |
| 4598 | if (bfa_rport_send_fwdelete(rp)) |
| 4599 | bfa_sm_set_state(rp, bfa_rport_sm_fwdelete); |
| 4600 | else |
| 4601 | bfa_sm_set_state(rp, bfa_rport_sm_fwdelete_qfull); |
| 4602 | break; |
| 4603 | |
| 4604 | case BFA_RPORT_SM_DELETE: |
| 4605 | bfa_stats(rp, sm_offp_del); |
| 4606 | bfa_sm_set_state(rp, bfa_rport_sm_delete_pending); |
| 4607 | break; |
| 4608 | |
| 4609 | case BFA_RPORT_SM_HWFAIL: |
| 4610 | bfa_stats(rp, sm_offp_hwf); |
| 4611 | bfa_sm_set_state(rp, bfa_rport_sm_iocdisable); |
Krishna Gudipati | 61ba439 | 2012-08-22 19:52:58 -0700 | [diff] [blame] | 4612 | bfa_rport_offline_cb(rp); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4613 | break; |
| 4614 | |
| 4615 | default: |
| 4616 | bfa_stats(rp, sm_offp_unexp); |
| 4617 | bfa_sm_fault(rp->bfa, event); |
| 4618 | } |
| 4619 | } |
| 4620 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4621 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4622 | * IOC h/w failed. |
| 4623 | */ |
| 4624 | static void |
| 4625 | bfa_rport_sm_iocdisable(struct bfa_rport_s *rp, enum bfa_rport_event event) |
| 4626 | { |
| 4627 | bfa_trc(rp->bfa, rp->rport_tag); |
| 4628 | bfa_trc(rp->bfa, event); |
| 4629 | |
| 4630 | switch (event) { |
| 4631 | case BFA_RPORT_SM_OFFLINE: |
| 4632 | bfa_stats(rp, sm_iocd_off); |
| 4633 | bfa_rport_offline_cb(rp); |
| 4634 | break; |
| 4635 | |
| 4636 | case BFA_RPORT_SM_DELETE: |
| 4637 | bfa_stats(rp, sm_iocd_del); |
| 4638 | bfa_sm_set_state(rp, bfa_rport_sm_uninit); |
| 4639 | bfa_rport_free(rp); |
| 4640 | break; |
| 4641 | |
| 4642 | case BFA_RPORT_SM_ONLINE: |
| 4643 | bfa_stats(rp, sm_iocd_on); |
| 4644 | if (bfa_rport_send_fwcreate(rp)) |
| 4645 | bfa_sm_set_state(rp, bfa_rport_sm_fwcreate); |
| 4646 | else |
| 4647 | bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull); |
| 4648 | break; |
| 4649 | |
| 4650 | case BFA_RPORT_SM_HWFAIL: |
| 4651 | break; |
| 4652 | |
| 4653 | default: |
| 4654 | bfa_stats(rp, sm_iocd_unexp); |
| 4655 | bfa_sm_fault(rp->bfa, event); |
| 4656 | } |
| 4657 | } |
| 4658 | |
| 4659 | |
| 4660 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4661 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4662 | * bfa_rport_private BFA rport private functions |
| 4663 | */ |
| 4664 | |
| 4665 | static void |
| 4666 | __bfa_cb_rport_online(void *cbarg, bfa_boolean_t complete) |
| 4667 | { |
| 4668 | struct bfa_rport_s *rp = cbarg; |
| 4669 | |
| 4670 | if (complete) |
| 4671 | bfa_cb_rport_online(rp->rport_drv); |
| 4672 | } |
| 4673 | |
| 4674 | static void |
| 4675 | __bfa_cb_rport_offline(void *cbarg, bfa_boolean_t complete) |
| 4676 | { |
| 4677 | struct bfa_rport_s *rp = cbarg; |
| 4678 | |
| 4679 | if (complete) |
| 4680 | bfa_cb_rport_offline(rp->rport_drv); |
| 4681 | } |
| 4682 | |
| 4683 | static void |
| 4684 | bfa_rport_qresume(void *cbarg) |
| 4685 | { |
| 4686 | struct bfa_rport_s *rp = cbarg; |
| 4687 | |
| 4688 | bfa_sm_send_event(rp, BFA_RPORT_SM_QRESUME); |
| 4689 | } |
| 4690 | |
| 4691 | static void |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 4692 | bfa_rport_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo, |
| 4693 | struct bfa_s *bfa) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4694 | { |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 4695 | struct bfa_mem_kva_s *rport_kva = BFA_MEM_RPORT_KVA(bfa); |
| 4696 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4697 | if (cfg->fwcfg.num_rports < BFA_RPORT_MIN) |
| 4698 | cfg->fwcfg.num_rports = BFA_RPORT_MIN; |
| 4699 | |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 4700 | /* kva memory */ |
| 4701 | bfa_mem_kva_setup(minfo, rport_kva, |
| 4702 | cfg->fwcfg.num_rports * sizeof(struct bfa_rport_s)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4703 | } |
| 4704 | |
| 4705 | static void |
| 4706 | bfa_rport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg, |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 4707 | struct bfa_pcidev_s *pcidev) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4708 | { |
| 4709 | struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa); |
| 4710 | struct bfa_rport_s *rp; |
| 4711 | u16 i; |
| 4712 | |
| 4713 | INIT_LIST_HEAD(&mod->rp_free_q); |
| 4714 | INIT_LIST_HEAD(&mod->rp_active_q); |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 4715 | INIT_LIST_HEAD(&mod->rp_unused_q); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4716 | |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 4717 | rp = (struct bfa_rport_s *) bfa_mem_kva_curp(mod); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4718 | mod->rps_list = rp; |
| 4719 | mod->num_rports = cfg->fwcfg.num_rports; |
| 4720 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 4721 | WARN_ON(!mod->num_rports || |
| 4722 | (mod->num_rports & (mod->num_rports - 1))); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4723 | |
| 4724 | for (i = 0; i < mod->num_rports; i++, rp++) { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 4725 | memset(rp, 0, sizeof(struct bfa_rport_s)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4726 | rp->bfa = bfa; |
| 4727 | rp->rport_tag = i; |
| 4728 | bfa_sm_set_state(rp, bfa_rport_sm_uninit); |
| 4729 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4730 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4731 | * - is unused |
| 4732 | */ |
| 4733 | if (i) |
| 4734 | list_add_tail(&rp->qe, &mod->rp_free_q); |
| 4735 | |
| 4736 | bfa_reqq_winit(&rp->reqq_wait, bfa_rport_qresume, rp); |
| 4737 | } |
| 4738 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4739 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4740 | * consume memory |
| 4741 | */ |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 4742 | bfa_mem_kva_curp(mod) = (u8 *) rp; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4743 | } |
| 4744 | |
| 4745 | static void |
| 4746 | bfa_rport_detach(struct bfa_s *bfa) |
| 4747 | { |
| 4748 | } |
| 4749 | |
| 4750 | static void |
| 4751 | bfa_rport_start(struct bfa_s *bfa) |
| 4752 | { |
| 4753 | } |
| 4754 | |
| 4755 | static void |
| 4756 | bfa_rport_stop(struct bfa_s *bfa) |
| 4757 | { |
| 4758 | } |
| 4759 | |
| 4760 | static void |
| 4761 | bfa_rport_iocdisable(struct bfa_s *bfa) |
| 4762 | { |
| 4763 | struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa); |
| 4764 | struct bfa_rport_s *rport; |
| 4765 | struct list_head *qe, *qen; |
| 4766 | |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 4767 | /* Enqueue unused rport resources to free_q */ |
| 4768 | list_splice_tail_init(&mod->rp_unused_q, &mod->rp_free_q); |
| 4769 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4770 | list_for_each_safe(qe, qen, &mod->rp_active_q) { |
| 4771 | rport = (struct bfa_rport_s *) qe; |
| 4772 | bfa_sm_send_event(rport, BFA_RPORT_SM_HWFAIL); |
| 4773 | } |
| 4774 | } |
| 4775 | |
| 4776 | static struct bfa_rport_s * |
| 4777 | bfa_rport_alloc(struct bfa_rport_mod_s *mod) |
| 4778 | { |
| 4779 | struct bfa_rport_s *rport; |
| 4780 | |
| 4781 | bfa_q_deq(&mod->rp_free_q, &rport); |
| 4782 | if (rport) |
| 4783 | list_add_tail(&rport->qe, &mod->rp_active_q); |
| 4784 | |
| 4785 | return rport; |
| 4786 | } |
| 4787 | |
| 4788 | static void |
| 4789 | bfa_rport_free(struct bfa_rport_s *rport) |
| 4790 | { |
| 4791 | struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(rport->bfa); |
| 4792 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 4793 | WARN_ON(!bfa_q_is_on_q(&mod->rp_active_q, rport)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4794 | list_del(&rport->qe); |
| 4795 | list_add_tail(&rport->qe, &mod->rp_free_q); |
| 4796 | } |
| 4797 | |
| 4798 | static bfa_boolean_t |
| 4799 | bfa_rport_send_fwcreate(struct bfa_rport_s *rp) |
| 4800 | { |
| 4801 | struct bfi_rport_create_req_s *m; |
| 4802 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4803 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4804 | * check for room in queue to send request now |
| 4805 | */ |
| 4806 | m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT); |
| 4807 | if (!m) { |
| 4808 | bfa_reqq_wait(rp->bfa, BFA_REQQ_RPORT, &rp->reqq_wait); |
| 4809 | return BFA_FALSE; |
| 4810 | } |
| 4811 | |
| 4812 | bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_CREATE_REQ, |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 4813 | bfa_fn_lpu(rp->bfa)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4814 | m->bfa_handle = rp->rport_tag; |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 4815 | m->max_frmsz = cpu_to_be16(rp->rport_info.max_frmsz); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4816 | m->pid = rp->rport_info.pid; |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 4817 | m->lp_fwtag = bfa_lps_get_fwtag(rp->bfa, (u8)rp->rport_info.lp_tag); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4818 | m->local_pid = rp->rport_info.local_pid; |
| 4819 | m->fc_class = rp->rport_info.fc_class; |
| 4820 | m->vf_en = rp->rport_info.vf_en; |
| 4821 | m->vf_id = rp->rport_info.vf_id; |
| 4822 | m->cisc = rp->rport_info.cisc; |
| 4823 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4824 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4825 | * queue I/O message to firmware |
| 4826 | */ |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 4827 | bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT, m->mh); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4828 | return BFA_TRUE; |
| 4829 | } |
| 4830 | |
| 4831 | static bfa_boolean_t |
| 4832 | bfa_rport_send_fwdelete(struct bfa_rport_s *rp) |
| 4833 | { |
| 4834 | struct bfi_rport_delete_req_s *m; |
| 4835 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4836 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4837 | * check for room in queue to send request now |
| 4838 | */ |
| 4839 | m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT); |
| 4840 | if (!m) { |
| 4841 | bfa_reqq_wait(rp->bfa, BFA_REQQ_RPORT, &rp->reqq_wait); |
| 4842 | return BFA_FALSE; |
| 4843 | } |
| 4844 | |
| 4845 | bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_DELETE_REQ, |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 4846 | bfa_fn_lpu(rp->bfa)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4847 | m->fw_handle = rp->fw_handle; |
| 4848 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4849 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4850 | * queue I/O message to firmware |
| 4851 | */ |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 4852 | bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT, m->mh); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4853 | return BFA_TRUE; |
| 4854 | } |
| 4855 | |
| 4856 | static bfa_boolean_t |
| 4857 | bfa_rport_send_fwspeed(struct bfa_rport_s *rp) |
| 4858 | { |
| 4859 | struct bfa_rport_speed_req_s *m; |
| 4860 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4861 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4862 | * check for room in queue to send request now |
| 4863 | */ |
| 4864 | m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT); |
| 4865 | if (!m) { |
| 4866 | bfa_trc(rp->bfa, rp->rport_info.speed); |
| 4867 | return BFA_FALSE; |
| 4868 | } |
| 4869 | |
| 4870 | bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_SET_SPEED_REQ, |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 4871 | bfa_fn_lpu(rp->bfa)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4872 | m->fw_handle = rp->fw_handle; |
| 4873 | m->speed = (u8)rp->rport_info.speed; |
| 4874 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4875 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4876 | * queue I/O message to firmware |
| 4877 | */ |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 4878 | bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT, m->mh); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4879 | return BFA_TRUE; |
| 4880 | } |
| 4881 | |
| 4882 | |
| 4883 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4884 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4885 | * bfa_rport_public |
| 4886 | */ |
| 4887 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4888 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4889 | * Rport interrupt processing. |
| 4890 | */ |
| 4891 | void |
| 4892 | bfa_rport_isr(struct bfa_s *bfa, struct bfi_msg_s *m) |
| 4893 | { |
| 4894 | union bfi_rport_i2h_msg_u msg; |
| 4895 | struct bfa_rport_s *rp; |
| 4896 | |
| 4897 | bfa_trc(bfa, m->mhdr.msg_id); |
| 4898 | |
| 4899 | msg.msg = m; |
| 4900 | |
| 4901 | switch (m->mhdr.msg_id) { |
| 4902 | case BFI_RPORT_I2H_CREATE_RSP: |
| 4903 | rp = BFA_RPORT_FROM_TAG(bfa, msg.create_rsp->bfa_handle); |
| 4904 | rp->fw_handle = msg.create_rsp->fw_handle; |
| 4905 | rp->qos_attr = msg.create_rsp->qos_attr; |
Krishna Gudipati | 83763d5 | 2011-07-20 17:04:03 -0700 | [diff] [blame] | 4906 | bfa_rport_set_lunmask(bfa, rp); |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 4907 | WARN_ON(msg.create_rsp->status != BFA_STATUS_OK); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4908 | bfa_sm_send_event(rp, BFA_RPORT_SM_FWRSP); |
| 4909 | break; |
| 4910 | |
| 4911 | case BFI_RPORT_I2H_DELETE_RSP: |
| 4912 | rp = BFA_RPORT_FROM_TAG(bfa, msg.delete_rsp->bfa_handle); |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 4913 | WARN_ON(msg.delete_rsp->status != BFA_STATUS_OK); |
Krishna Gudipati | 83763d5 | 2011-07-20 17:04:03 -0700 | [diff] [blame] | 4914 | bfa_rport_unset_lunmask(bfa, rp); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4915 | bfa_sm_send_event(rp, BFA_RPORT_SM_FWRSP); |
| 4916 | break; |
| 4917 | |
| 4918 | case BFI_RPORT_I2H_QOS_SCN: |
| 4919 | rp = BFA_RPORT_FROM_TAG(bfa, msg.qos_scn_evt->bfa_handle); |
| 4920 | rp->event_arg.fw_msg = msg.qos_scn_evt; |
| 4921 | bfa_sm_send_event(rp, BFA_RPORT_SM_QOS_SCN); |
| 4922 | break; |
| 4923 | |
Krishna Gudipati | bc0e2c2 | 2012-09-21 17:23:59 -0700 | [diff] [blame] | 4924 | case BFI_RPORT_I2H_LIP_SCN_ONLINE: |
| 4925 | bfa_fcport_update_loop_info(BFA_FCPORT_MOD(bfa), |
| 4926 | &msg.lip_scn->loop_info); |
| 4927 | bfa_cb_rport_scn_online(bfa); |
| 4928 | break; |
| 4929 | |
| 4930 | case BFI_RPORT_I2H_LIP_SCN_OFFLINE: |
| 4931 | bfa_cb_rport_scn_offline(bfa); |
| 4932 | break; |
| 4933 | |
| 4934 | case BFI_RPORT_I2H_NO_DEV: |
| 4935 | rp = BFA_RPORT_FROM_TAG(bfa, msg.lip_scn->bfa_handle); |
| 4936 | bfa_cb_rport_scn_no_dev(rp->rport_drv); |
| 4937 | break; |
| 4938 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4939 | default: |
| 4940 | bfa_trc(bfa, m->mhdr.msg_id); |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 4941 | WARN_ON(1); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4942 | } |
| 4943 | } |
| 4944 | |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 4945 | void |
| 4946 | bfa_rport_res_recfg(struct bfa_s *bfa, u16 num_rport_fw) |
| 4947 | { |
| 4948 | struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa); |
| 4949 | struct list_head *qe; |
| 4950 | int i; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4951 | |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 4952 | for (i = 0; i < (mod->num_rports - num_rport_fw); i++) { |
| 4953 | bfa_q_deq_tail(&mod->rp_free_q, &qe); |
| 4954 | list_add_tail(qe, &mod->rp_unused_q); |
| 4955 | } |
| 4956 | } |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4957 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4958 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4959 | * bfa_rport_api |
| 4960 | */ |
| 4961 | |
| 4962 | struct bfa_rport_s * |
| 4963 | bfa_rport_create(struct bfa_s *bfa, void *rport_drv) |
| 4964 | { |
| 4965 | struct bfa_rport_s *rp; |
| 4966 | |
| 4967 | rp = bfa_rport_alloc(BFA_RPORT_MOD(bfa)); |
| 4968 | |
| 4969 | if (rp == NULL) |
| 4970 | return NULL; |
| 4971 | |
| 4972 | rp->bfa = bfa; |
| 4973 | rp->rport_drv = rport_drv; |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 4974 | memset(&rp->stats, 0, sizeof(rp->stats)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4975 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 4976 | WARN_ON(!bfa_sm_cmp_state(rp, bfa_rport_sm_uninit)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4977 | bfa_sm_send_event(rp, BFA_RPORT_SM_CREATE); |
| 4978 | |
| 4979 | return rp; |
| 4980 | } |
| 4981 | |
| 4982 | void |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4983 | bfa_rport_online(struct bfa_rport_s *rport, struct bfa_rport_info_s *rport_info) |
| 4984 | { |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 4985 | WARN_ON(rport_info->max_frmsz == 0); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4986 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4987 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4988 | * Some JBODs are seen to be not setting PDU size correctly in PLOGI |
| 4989 | * responses. Default to minimum size. |
| 4990 | */ |
| 4991 | if (rport_info->max_frmsz == 0) { |
| 4992 | bfa_trc(rport->bfa, rport->rport_tag); |
| 4993 | rport_info->max_frmsz = FC_MIN_PDUSZ; |
| 4994 | } |
| 4995 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 4996 | rport->rport_info = *rport_info; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4997 | bfa_sm_send_event(rport, BFA_RPORT_SM_ONLINE); |
| 4998 | } |
| 4999 | |
| 5000 | void |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5001 | bfa_rport_speed(struct bfa_rport_s *rport, enum bfa_port_speed speed) |
| 5002 | { |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 5003 | WARN_ON(speed == 0); |
| 5004 | WARN_ON(speed == BFA_PORT_SPEED_AUTO); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5005 | |
Krishna Gudipati | 61ba439 | 2012-08-22 19:52:58 -0700 | [diff] [blame] | 5006 | if (rport) { |
| 5007 | rport->rport_info.speed = speed; |
| 5008 | bfa_sm_send_event(rport, BFA_RPORT_SM_SET_SPEED); |
| 5009 | } |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5010 | } |
| 5011 | |
Krishna Gudipati | 83763d5 | 2011-07-20 17:04:03 -0700 | [diff] [blame] | 5012 | /* Set Rport LUN Mask */ |
| 5013 | void |
| 5014 | bfa_rport_set_lunmask(struct bfa_s *bfa, struct bfa_rport_s *rp) |
| 5015 | { |
| 5016 | struct bfa_lps_mod_s *lps_mod = BFA_LPS_MOD(bfa); |
| 5017 | wwn_t lp_wwn, rp_wwn; |
| 5018 | u8 lp_tag = (u8)rp->rport_info.lp_tag; |
| 5019 | |
| 5020 | rp_wwn = ((struct bfa_fcs_rport_s *)rp->rport_drv)->pwwn; |
| 5021 | lp_wwn = (BFA_LPS_FROM_TAG(lps_mod, rp->rport_info.lp_tag))->pwwn; |
| 5022 | |
| 5023 | BFA_LPS_FROM_TAG(lps_mod, rp->rport_info.lp_tag)->lun_mask = |
| 5024 | rp->lun_mask = BFA_TRUE; |
| 5025 | bfa_fcpim_lunmask_rp_update(bfa, lp_wwn, rp_wwn, rp->rport_tag, lp_tag); |
| 5026 | } |
| 5027 | |
| 5028 | /* Unset Rport LUN mask */ |
| 5029 | void |
| 5030 | bfa_rport_unset_lunmask(struct bfa_s *bfa, struct bfa_rport_s *rp) |
| 5031 | { |
| 5032 | struct bfa_lps_mod_s *lps_mod = BFA_LPS_MOD(bfa); |
| 5033 | wwn_t lp_wwn, rp_wwn; |
| 5034 | |
| 5035 | rp_wwn = ((struct bfa_fcs_rport_s *)rp->rport_drv)->pwwn; |
| 5036 | lp_wwn = (BFA_LPS_FROM_TAG(lps_mod, rp->rport_info.lp_tag))->pwwn; |
| 5037 | |
| 5038 | BFA_LPS_FROM_TAG(lps_mod, rp->rport_info.lp_tag)->lun_mask = |
| 5039 | rp->lun_mask = BFA_FALSE; |
| 5040 | bfa_fcpim_lunmask_rp_update(bfa, lp_wwn, rp_wwn, |
| 5041 | BFA_RPORT_TAG_INVALID, BFA_LP_TAG_INVALID); |
| 5042 | } |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5043 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 5044 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5045 | * SGPG related functions |
| 5046 | */ |
| 5047 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 5048 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5049 | * Compute and return memory needed by FCP(im) module. |
| 5050 | */ |
| 5051 | static void |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 5052 | bfa_sgpg_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo, |
| 5053 | struct bfa_s *bfa) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5054 | { |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 5055 | struct bfa_sgpg_mod_s *sgpg_mod = BFA_SGPG_MOD(bfa); |
| 5056 | struct bfa_mem_kva_s *sgpg_kva = BFA_MEM_SGPG_KVA(bfa); |
| 5057 | struct bfa_mem_dma_s *seg_ptr; |
| 5058 | u16 nsegs, idx, per_seg_sgpg, num_sgpg; |
| 5059 | u32 sgpg_sz = sizeof(struct bfi_sgpg_s); |
| 5060 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5061 | if (cfg->drvcfg.num_sgpgs < BFA_SGPG_MIN) |
| 5062 | cfg->drvcfg.num_sgpgs = BFA_SGPG_MIN; |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 5063 | else if (cfg->drvcfg.num_sgpgs > BFA_SGPG_MAX) |
| 5064 | cfg->drvcfg.num_sgpgs = BFA_SGPG_MAX; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5065 | |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 5066 | num_sgpg = cfg->drvcfg.num_sgpgs; |
| 5067 | |
| 5068 | nsegs = BFI_MEM_DMA_NSEGS(num_sgpg, sgpg_sz); |
| 5069 | per_seg_sgpg = BFI_MEM_NREQS_SEG(sgpg_sz); |
| 5070 | |
| 5071 | bfa_mem_dma_seg_iter(sgpg_mod, seg_ptr, nsegs, idx) { |
| 5072 | if (num_sgpg >= per_seg_sgpg) { |
| 5073 | num_sgpg -= per_seg_sgpg; |
| 5074 | bfa_mem_dma_setup(minfo, seg_ptr, |
| 5075 | per_seg_sgpg * sgpg_sz); |
| 5076 | } else |
| 5077 | bfa_mem_dma_setup(minfo, seg_ptr, |
| 5078 | num_sgpg * sgpg_sz); |
| 5079 | } |
| 5080 | |
| 5081 | /* kva memory */ |
| 5082 | bfa_mem_kva_setup(minfo, sgpg_kva, |
| 5083 | cfg->drvcfg.num_sgpgs * sizeof(struct bfa_sgpg_s)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5084 | } |
| 5085 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5086 | static void |
| 5087 | bfa_sgpg_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg, |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 5088 | struct bfa_pcidev_s *pcidev) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5089 | { |
| 5090 | struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5091 | struct bfa_sgpg_s *hsgpg; |
| 5092 | struct bfi_sgpg_s *sgpg; |
| 5093 | u64 align_len; |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 5094 | struct bfa_mem_dma_s *seg_ptr; |
| 5095 | u32 sgpg_sz = sizeof(struct bfi_sgpg_s); |
| 5096 | u16 i, idx, nsegs, per_seg_sgpg, num_sgpg; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5097 | |
| 5098 | union { |
| 5099 | u64 pa; |
| 5100 | union bfi_addr_u addr; |
| 5101 | } sgpg_pa, sgpg_pa_tmp; |
| 5102 | |
| 5103 | INIT_LIST_HEAD(&mod->sgpg_q); |
| 5104 | INIT_LIST_HEAD(&mod->sgpg_wait_q); |
| 5105 | |
| 5106 | bfa_trc(bfa, cfg->drvcfg.num_sgpgs); |
| 5107 | |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 5108 | mod->free_sgpgs = mod->num_sgpgs = cfg->drvcfg.num_sgpgs; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5109 | |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 5110 | num_sgpg = cfg->drvcfg.num_sgpgs; |
| 5111 | nsegs = BFI_MEM_DMA_NSEGS(num_sgpg, sgpg_sz); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5112 | |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 5113 | /* dma/kva mem claim */ |
| 5114 | hsgpg = (struct bfa_sgpg_s *) bfa_mem_kva_curp(mod); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5115 | |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 5116 | bfa_mem_dma_seg_iter(mod, seg_ptr, nsegs, idx) { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5117 | |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 5118 | if (!bfa_mem_dma_virt(seg_ptr)) |
| 5119 | break; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5120 | |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 5121 | align_len = BFA_SGPG_ROUNDUP(bfa_mem_dma_phys(seg_ptr)) - |
| 5122 | bfa_mem_dma_phys(seg_ptr); |
| 5123 | |
| 5124 | sgpg = (struct bfi_sgpg_s *) |
| 5125 | (((u8 *) bfa_mem_dma_virt(seg_ptr)) + align_len); |
| 5126 | sgpg_pa.pa = bfa_mem_dma_phys(seg_ptr) + align_len; |
| 5127 | WARN_ON(sgpg_pa.pa & (sgpg_sz - 1)); |
| 5128 | |
| 5129 | per_seg_sgpg = (seg_ptr->mem_len - (u32)align_len) / sgpg_sz; |
| 5130 | |
| 5131 | for (i = 0; num_sgpg > 0 && i < per_seg_sgpg; i++, num_sgpg--) { |
| 5132 | memset(hsgpg, 0, sizeof(*hsgpg)); |
| 5133 | memset(sgpg, 0, sizeof(*sgpg)); |
| 5134 | |
| 5135 | hsgpg->sgpg = sgpg; |
| 5136 | sgpg_pa_tmp.pa = bfa_sgaddr_le(sgpg_pa.pa); |
| 5137 | hsgpg->sgpg_pa = sgpg_pa_tmp.addr; |
| 5138 | list_add_tail(&hsgpg->qe, &mod->sgpg_q); |
| 5139 | |
| 5140 | sgpg++; |
| 5141 | hsgpg++; |
| 5142 | sgpg_pa.pa += sgpg_sz; |
| 5143 | } |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5144 | } |
| 5145 | |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 5146 | bfa_mem_kva_curp(mod) = (u8 *) hsgpg; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5147 | } |
| 5148 | |
| 5149 | static void |
| 5150 | bfa_sgpg_detach(struct bfa_s *bfa) |
| 5151 | { |
| 5152 | } |
| 5153 | |
| 5154 | static void |
| 5155 | bfa_sgpg_start(struct bfa_s *bfa) |
| 5156 | { |
| 5157 | } |
| 5158 | |
| 5159 | static void |
| 5160 | bfa_sgpg_stop(struct bfa_s *bfa) |
| 5161 | { |
| 5162 | } |
| 5163 | |
| 5164 | static void |
| 5165 | bfa_sgpg_iocdisable(struct bfa_s *bfa) |
| 5166 | { |
| 5167 | } |
| 5168 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5169 | bfa_status_t |
| 5170 | bfa_sgpg_malloc(struct bfa_s *bfa, struct list_head *sgpg_q, int nsgpgs) |
| 5171 | { |
| 5172 | struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa); |
| 5173 | struct bfa_sgpg_s *hsgpg; |
| 5174 | int i; |
| 5175 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5176 | if (mod->free_sgpgs < nsgpgs) |
| 5177 | return BFA_STATUS_ENOMEM; |
| 5178 | |
| 5179 | for (i = 0; i < nsgpgs; i++) { |
| 5180 | bfa_q_deq(&mod->sgpg_q, &hsgpg); |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 5181 | WARN_ON(!hsgpg); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5182 | list_add_tail(&hsgpg->qe, sgpg_q); |
| 5183 | } |
| 5184 | |
| 5185 | mod->free_sgpgs -= nsgpgs; |
| 5186 | return BFA_STATUS_OK; |
| 5187 | } |
| 5188 | |
| 5189 | void |
| 5190 | bfa_sgpg_mfree(struct bfa_s *bfa, struct list_head *sgpg_q, int nsgpg) |
| 5191 | { |
| 5192 | struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa); |
| 5193 | struct bfa_sgpg_wqe_s *wqe; |
| 5194 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5195 | mod->free_sgpgs += nsgpg; |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 5196 | WARN_ON(mod->free_sgpgs > mod->num_sgpgs); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5197 | |
| 5198 | list_splice_tail_init(sgpg_q, &mod->sgpg_q); |
| 5199 | |
| 5200 | if (list_empty(&mod->sgpg_wait_q)) |
| 5201 | return; |
| 5202 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 5203 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5204 | * satisfy as many waiting requests as possible |
| 5205 | */ |
| 5206 | do { |
| 5207 | wqe = bfa_q_first(&mod->sgpg_wait_q); |
| 5208 | if (mod->free_sgpgs < wqe->nsgpg) |
| 5209 | nsgpg = mod->free_sgpgs; |
| 5210 | else |
| 5211 | nsgpg = wqe->nsgpg; |
| 5212 | bfa_sgpg_malloc(bfa, &wqe->sgpg_q, nsgpg); |
| 5213 | wqe->nsgpg -= nsgpg; |
| 5214 | if (wqe->nsgpg == 0) { |
| 5215 | list_del(&wqe->qe); |
| 5216 | wqe->cbfn(wqe->cbarg); |
| 5217 | } |
| 5218 | } while (mod->free_sgpgs && !list_empty(&mod->sgpg_wait_q)); |
| 5219 | } |
| 5220 | |
| 5221 | void |
| 5222 | bfa_sgpg_wait(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe, int nsgpg) |
| 5223 | { |
| 5224 | struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa); |
| 5225 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 5226 | WARN_ON(nsgpg <= 0); |
| 5227 | WARN_ON(nsgpg <= mod->free_sgpgs); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5228 | |
| 5229 | wqe->nsgpg_total = wqe->nsgpg = nsgpg; |
| 5230 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 5231 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5232 | * allocate any left to this one first |
| 5233 | */ |
| 5234 | if (mod->free_sgpgs) { |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 5235 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5236 | * no one else is waiting for SGPG |
| 5237 | */ |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 5238 | WARN_ON(!list_empty(&mod->sgpg_wait_q)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5239 | list_splice_tail_init(&mod->sgpg_q, &wqe->sgpg_q); |
| 5240 | wqe->nsgpg -= mod->free_sgpgs; |
| 5241 | mod->free_sgpgs = 0; |
| 5242 | } |
| 5243 | |
| 5244 | list_add_tail(&wqe->qe, &mod->sgpg_wait_q); |
| 5245 | } |
| 5246 | |
| 5247 | void |
| 5248 | bfa_sgpg_wcancel(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe) |
| 5249 | { |
| 5250 | struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa); |
| 5251 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 5252 | WARN_ON(!bfa_q_is_on_q(&mod->sgpg_wait_q, wqe)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5253 | list_del(&wqe->qe); |
| 5254 | |
| 5255 | if (wqe->nsgpg_total != wqe->nsgpg) |
| 5256 | bfa_sgpg_mfree(bfa, &wqe->sgpg_q, |
| 5257 | wqe->nsgpg_total - wqe->nsgpg); |
| 5258 | } |
| 5259 | |
| 5260 | void |
| 5261 | bfa_sgpg_winit(struct bfa_sgpg_wqe_s *wqe, void (*cbfn) (void *cbarg), |
| 5262 | void *cbarg) |
| 5263 | { |
| 5264 | INIT_LIST_HEAD(&wqe->sgpg_q); |
| 5265 | wqe->cbfn = cbfn; |
| 5266 | wqe->cbarg = cbarg; |
| 5267 | } |
| 5268 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 5269 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5270 | * UF related functions |
| 5271 | */ |
| 5272 | /* |
| 5273 | ***************************************************************************** |
| 5274 | * Internal functions |
| 5275 | ***************************************************************************** |
| 5276 | */ |
| 5277 | static void |
| 5278 | __bfa_cb_uf_recv(void *cbarg, bfa_boolean_t complete) |
| 5279 | { |
| 5280 | struct bfa_uf_s *uf = cbarg; |
| 5281 | struct bfa_uf_mod_s *ufm = BFA_UF_MOD(uf->bfa); |
| 5282 | |
| 5283 | if (complete) |
| 5284 | ufm->ufrecv(ufm->cbarg, uf); |
| 5285 | } |
| 5286 | |
| 5287 | static void |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 5288 | claim_uf_post_msgs(struct bfa_uf_mod_s *ufm) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5289 | { |
| 5290 | struct bfi_uf_buf_post_s *uf_bp_msg; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5291 | u16 i; |
| 5292 | u16 buf_len; |
| 5293 | |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 5294 | ufm->uf_buf_posts = (struct bfi_uf_buf_post_s *) bfa_mem_kva_curp(ufm); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5295 | uf_bp_msg = ufm->uf_buf_posts; |
| 5296 | |
| 5297 | for (i = 0, uf_bp_msg = ufm->uf_buf_posts; i < ufm->num_ufs; |
| 5298 | i++, uf_bp_msg++) { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 5299 | memset(uf_bp_msg, 0, sizeof(struct bfi_uf_buf_post_s)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5300 | |
| 5301 | uf_bp_msg->buf_tag = i; |
| 5302 | buf_len = sizeof(struct bfa_uf_buf_s); |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 5303 | uf_bp_msg->buf_len = cpu_to_be16(buf_len); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5304 | bfi_h2i_set(uf_bp_msg->mh, BFI_MC_UF, BFI_UF_H2I_BUF_POST, |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 5305 | bfa_fn_lpu(ufm->bfa)); |
Krishna Gudipati | 85ce928 | 2011-06-13 15:39:36 -0700 | [diff] [blame] | 5306 | bfa_alen_set(&uf_bp_msg->alen, buf_len, ufm_pbs_pa(ufm, i)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5307 | } |
| 5308 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 5309 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5310 | * advance pointer beyond consumed memory |
| 5311 | */ |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 5312 | bfa_mem_kva_curp(ufm) = (u8 *) uf_bp_msg; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5313 | } |
| 5314 | |
| 5315 | static void |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 5316 | claim_ufs(struct bfa_uf_mod_s *ufm) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5317 | { |
| 5318 | u16 i; |
| 5319 | struct bfa_uf_s *uf; |
| 5320 | |
| 5321 | /* |
| 5322 | * Claim block of memory for UF list |
| 5323 | */ |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 5324 | ufm->uf_list = (struct bfa_uf_s *) bfa_mem_kva_curp(ufm); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5325 | |
| 5326 | /* |
| 5327 | * Initialize UFs and queue it in UF free queue |
| 5328 | */ |
| 5329 | for (i = 0, uf = ufm->uf_list; i < ufm->num_ufs; i++, uf++) { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 5330 | memset(uf, 0, sizeof(struct bfa_uf_s)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5331 | uf->bfa = ufm->bfa; |
| 5332 | uf->uf_tag = i; |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 5333 | uf->pb_len = BFA_PER_UF_DMA_SZ; |
| 5334 | uf->buf_kva = bfa_mem_get_dmabuf_kva(ufm, i, BFA_PER_UF_DMA_SZ); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5335 | uf->buf_pa = ufm_pbs_pa(ufm, i); |
| 5336 | list_add_tail(&uf->qe, &ufm->uf_free_q); |
| 5337 | } |
| 5338 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 5339 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5340 | * advance memory pointer |
| 5341 | */ |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 5342 | bfa_mem_kva_curp(ufm) = (u8 *) uf; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5343 | } |
| 5344 | |
| 5345 | static void |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 5346 | uf_mem_claim(struct bfa_uf_mod_s *ufm) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5347 | { |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 5348 | claim_ufs(ufm); |
| 5349 | claim_uf_post_msgs(ufm); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5350 | } |
| 5351 | |
| 5352 | static void |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 5353 | bfa_uf_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo, |
| 5354 | struct bfa_s *bfa) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5355 | { |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 5356 | struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa); |
| 5357 | struct bfa_mem_kva_s *uf_kva = BFA_MEM_UF_KVA(bfa); |
| 5358 | u32 num_ufs = cfg->fwcfg.num_uf_bufs; |
| 5359 | struct bfa_mem_dma_s *seg_ptr; |
| 5360 | u16 nsegs, idx, per_seg_uf = 0; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5361 | |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 5362 | nsegs = BFI_MEM_DMA_NSEGS(num_ufs, BFA_PER_UF_DMA_SZ); |
| 5363 | per_seg_uf = BFI_MEM_NREQS_SEG(BFA_PER_UF_DMA_SZ); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5364 | |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 5365 | bfa_mem_dma_seg_iter(ufm, seg_ptr, nsegs, idx) { |
| 5366 | if (num_ufs >= per_seg_uf) { |
| 5367 | num_ufs -= per_seg_uf; |
| 5368 | bfa_mem_dma_setup(minfo, seg_ptr, |
| 5369 | per_seg_uf * BFA_PER_UF_DMA_SZ); |
| 5370 | } else |
| 5371 | bfa_mem_dma_setup(minfo, seg_ptr, |
| 5372 | num_ufs * BFA_PER_UF_DMA_SZ); |
| 5373 | } |
| 5374 | |
| 5375 | /* kva memory */ |
| 5376 | bfa_mem_kva_setup(minfo, uf_kva, cfg->fwcfg.num_uf_bufs * |
| 5377 | (sizeof(struct bfa_uf_s) + sizeof(struct bfi_uf_buf_post_s))); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5378 | } |
| 5379 | |
| 5380 | static void |
| 5381 | bfa_uf_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg, |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 5382 | struct bfa_pcidev_s *pcidev) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5383 | { |
| 5384 | struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa); |
| 5385 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5386 | ufm->bfa = bfa; |
| 5387 | ufm->num_ufs = cfg->fwcfg.num_uf_bufs; |
| 5388 | INIT_LIST_HEAD(&ufm->uf_free_q); |
| 5389 | INIT_LIST_HEAD(&ufm->uf_posted_q); |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 5390 | INIT_LIST_HEAD(&ufm->uf_unused_q); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5391 | |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 5392 | uf_mem_claim(ufm); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5393 | } |
| 5394 | |
| 5395 | static void |
| 5396 | bfa_uf_detach(struct bfa_s *bfa) |
| 5397 | { |
| 5398 | } |
| 5399 | |
| 5400 | static struct bfa_uf_s * |
| 5401 | bfa_uf_get(struct bfa_uf_mod_s *uf_mod) |
| 5402 | { |
| 5403 | struct bfa_uf_s *uf; |
| 5404 | |
| 5405 | bfa_q_deq(&uf_mod->uf_free_q, &uf); |
| 5406 | return uf; |
| 5407 | } |
| 5408 | |
| 5409 | static void |
| 5410 | bfa_uf_put(struct bfa_uf_mod_s *uf_mod, struct bfa_uf_s *uf) |
| 5411 | { |
| 5412 | list_add_tail(&uf->qe, &uf_mod->uf_free_q); |
| 5413 | } |
| 5414 | |
| 5415 | static bfa_status_t |
| 5416 | bfa_uf_post(struct bfa_uf_mod_s *ufm, struct bfa_uf_s *uf) |
| 5417 | { |
| 5418 | struct bfi_uf_buf_post_s *uf_post_msg; |
| 5419 | |
| 5420 | uf_post_msg = bfa_reqq_next(ufm->bfa, BFA_REQQ_FCXP); |
| 5421 | if (!uf_post_msg) |
| 5422 | return BFA_STATUS_FAILED; |
| 5423 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 5424 | memcpy(uf_post_msg, &ufm->uf_buf_posts[uf->uf_tag], |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5425 | sizeof(struct bfi_uf_buf_post_s)); |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 5426 | bfa_reqq_produce(ufm->bfa, BFA_REQQ_FCXP, uf_post_msg->mh); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5427 | |
| 5428 | bfa_trc(ufm->bfa, uf->uf_tag); |
| 5429 | |
| 5430 | list_add_tail(&uf->qe, &ufm->uf_posted_q); |
| 5431 | return BFA_STATUS_OK; |
| 5432 | } |
| 5433 | |
| 5434 | static void |
| 5435 | bfa_uf_post_all(struct bfa_uf_mod_s *uf_mod) |
| 5436 | { |
| 5437 | struct bfa_uf_s *uf; |
| 5438 | |
| 5439 | while ((uf = bfa_uf_get(uf_mod)) != NULL) { |
| 5440 | if (bfa_uf_post(uf_mod, uf) != BFA_STATUS_OK) |
| 5441 | break; |
| 5442 | } |
| 5443 | } |
| 5444 | |
| 5445 | static void |
| 5446 | uf_recv(struct bfa_s *bfa, struct bfi_uf_frm_rcvd_s *m) |
| 5447 | { |
| 5448 | struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa); |
| 5449 | u16 uf_tag = m->buf_tag; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5450 | struct bfa_uf_s *uf = &ufm->uf_list[uf_tag]; |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 5451 | struct bfa_uf_buf_s *uf_buf; |
| 5452 | uint8_t *buf; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5453 | struct fchs_s *fchs; |
| 5454 | |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 5455 | uf_buf = (struct bfa_uf_buf_s *) |
| 5456 | bfa_mem_get_dmabuf_kva(ufm, uf_tag, uf->pb_len); |
| 5457 | buf = &uf_buf->d[0]; |
| 5458 | |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 5459 | m->frm_len = be16_to_cpu(m->frm_len); |
| 5460 | m->xfr_len = be16_to_cpu(m->xfr_len); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5461 | |
| 5462 | fchs = (struct fchs_s *)uf_buf; |
| 5463 | |
| 5464 | list_del(&uf->qe); /* dequeue from posted queue */ |
| 5465 | |
| 5466 | uf->data_ptr = buf; |
| 5467 | uf->data_len = m->xfr_len; |
| 5468 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 5469 | WARN_ON(uf->data_len < sizeof(struct fchs_s)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5470 | |
| 5471 | if (uf->data_len == sizeof(struct fchs_s)) { |
| 5472 | bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_UF, BFA_PL_EID_RX, |
| 5473 | uf->data_len, (struct fchs_s *)buf); |
| 5474 | } else { |
| 5475 | u32 pld_w0 = *((u32 *) (buf + sizeof(struct fchs_s))); |
| 5476 | bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_UF, |
| 5477 | BFA_PL_EID_RX, uf->data_len, |
| 5478 | (struct fchs_s *)buf, pld_w0); |
| 5479 | } |
| 5480 | |
| 5481 | if (bfa->fcs) |
| 5482 | __bfa_cb_uf_recv(uf, BFA_TRUE); |
| 5483 | else |
| 5484 | bfa_cb_queue(bfa, &uf->hcb_qe, __bfa_cb_uf_recv, uf); |
| 5485 | } |
| 5486 | |
| 5487 | static void |
| 5488 | bfa_uf_stop(struct bfa_s *bfa) |
| 5489 | { |
| 5490 | } |
| 5491 | |
| 5492 | static void |
| 5493 | bfa_uf_iocdisable(struct bfa_s *bfa) |
| 5494 | { |
| 5495 | struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa); |
| 5496 | struct bfa_uf_s *uf; |
| 5497 | struct list_head *qe, *qen; |
| 5498 | |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 5499 | /* Enqueue unused uf resources to free_q */ |
| 5500 | list_splice_tail_init(&ufm->uf_unused_q, &ufm->uf_free_q); |
| 5501 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5502 | list_for_each_safe(qe, qen, &ufm->uf_posted_q) { |
| 5503 | uf = (struct bfa_uf_s *) qe; |
| 5504 | list_del(&uf->qe); |
| 5505 | bfa_uf_put(ufm, uf); |
| 5506 | } |
| 5507 | } |
| 5508 | |
| 5509 | static void |
| 5510 | bfa_uf_start(struct bfa_s *bfa) |
| 5511 | { |
| 5512 | bfa_uf_post_all(BFA_UF_MOD(bfa)); |
| 5513 | } |
| 5514 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 5515 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 5516 | * Register handler for all unsolicted receive frames. |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5517 | * |
| 5518 | * @param[in] bfa BFA instance |
| 5519 | * @param[in] ufrecv receive handler function |
| 5520 | * @param[in] cbarg receive handler arg |
| 5521 | */ |
| 5522 | void |
| 5523 | bfa_uf_recv_register(struct bfa_s *bfa, bfa_cb_uf_recv_t ufrecv, void *cbarg) |
| 5524 | { |
| 5525 | struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa); |
| 5526 | |
| 5527 | ufm->ufrecv = ufrecv; |
| 5528 | ufm->cbarg = cbarg; |
| 5529 | } |
| 5530 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 5531 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5532 | * Free an unsolicited frame back to BFA. |
| 5533 | * |
| 5534 | * @param[in] uf unsolicited frame to be freed |
| 5535 | * |
| 5536 | * @return None |
| 5537 | */ |
| 5538 | void |
| 5539 | bfa_uf_free(struct bfa_uf_s *uf) |
| 5540 | { |
| 5541 | bfa_uf_put(BFA_UF_MOD(uf->bfa), uf); |
| 5542 | bfa_uf_post_all(BFA_UF_MOD(uf->bfa)); |
| 5543 | } |
| 5544 | |
| 5545 | |
| 5546 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 5547 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5548 | * uf_pub BFA uf module public functions |
| 5549 | */ |
| 5550 | void |
| 5551 | bfa_uf_isr(struct bfa_s *bfa, struct bfi_msg_s *msg) |
| 5552 | { |
| 5553 | bfa_trc(bfa, msg->mhdr.msg_id); |
| 5554 | |
| 5555 | switch (msg->mhdr.msg_id) { |
| 5556 | case BFI_UF_I2H_FRM_RCVD: |
| 5557 | uf_recv(bfa, (struct bfi_uf_frm_rcvd_s *) msg); |
| 5558 | break; |
| 5559 | |
| 5560 | default: |
| 5561 | bfa_trc(bfa, msg->mhdr.msg_id); |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 5562 | WARN_ON(1); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5563 | } |
| 5564 | } |
| 5565 | |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 5566 | void |
| 5567 | bfa_uf_res_recfg(struct bfa_s *bfa, u16 num_uf_fw) |
| 5568 | { |
| 5569 | struct bfa_uf_mod_s *mod = BFA_UF_MOD(bfa); |
| 5570 | struct list_head *qe; |
| 5571 | int i; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5572 | |
Krishna Gudipati | 3fd4598 | 2011-06-24 20:24:08 -0700 | [diff] [blame] | 5573 | for (i = 0; i < (mod->num_ufs - num_uf_fw); i++) { |
| 5574 | bfa_q_deq_tail(&mod->uf_free_q, &qe); |
| 5575 | list_add_tail(qe, &mod->uf_unused_q); |
| 5576 | } |
| 5577 | } |
Krishna Gudipati | 3d7fc66 | 2011-06-24 20:28:17 -0700 | [diff] [blame] | 5578 | |
| 5579 | /* |
Krishna Gudipati | e353546 | 2012-09-21 17:26:07 -0700 | [diff] [blame] | 5580 | * Dport forward declaration |
| 5581 | */ |
| 5582 | |
| 5583 | /* |
| 5584 | * BFA DPORT state machine events |
| 5585 | */ |
| 5586 | enum bfa_dport_sm_event { |
| 5587 | BFA_DPORT_SM_ENABLE = 1, /* dport enable event */ |
| 5588 | BFA_DPORT_SM_DISABLE = 2, /* dport disable event */ |
| 5589 | BFA_DPORT_SM_FWRSP = 3, /* fw enable/disable rsp */ |
| 5590 | BFA_DPORT_SM_QRESUME = 4, /* CQ space available */ |
| 5591 | BFA_DPORT_SM_HWFAIL = 5, /* IOC h/w failure */ |
| 5592 | }; |
| 5593 | |
| 5594 | static void bfa_dport_sm_disabled(struct bfa_dport_s *dport, |
| 5595 | enum bfa_dport_sm_event event); |
| 5596 | static void bfa_dport_sm_enabling_qwait(struct bfa_dport_s *dport, |
| 5597 | enum bfa_dport_sm_event event); |
| 5598 | static void bfa_dport_sm_enabling(struct bfa_dport_s *dport, |
| 5599 | enum bfa_dport_sm_event event); |
| 5600 | static void bfa_dport_sm_enabled(struct bfa_dport_s *dport, |
| 5601 | enum bfa_dport_sm_event event); |
| 5602 | static void bfa_dport_sm_disabling_qwait(struct bfa_dport_s *dport, |
| 5603 | enum bfa_dport_sm_event event); |
| 5604 | static void bfa_dport_sm_disabling(struct bfa_dport_s *dport, |
| 5605 | enum bfa_dport_sm_event event); |
| 5606 | static void bfa_dport_qresume(void *cbarg); |
| 5607 | static void bfa_dport_req_comp(struct bfa_dport_s *dport, |
| 5608 | bfi_diag_dport_rsp_t *msg); |
| 5609 | |
| 5610 | /* |
Krishna Gudipati | 3d7fc66 | 2011-06-24 20:28:17 -0700 | [diff] [blame] | 5611 | * BFA fcdiag module |
| 5612 | */ |
| 5613 | #define BFA_DIAG_QTEST_TOV 1000 /* msec */ |
| 5614 | |
| 5615 | /* |
| 5616 | * Set port status to busy |
| 5617 | */ |
| 5618 | static void |
| 5619 | bfa_fcdiag_set_busy_status(struct bfa_fcdiag_s *fcdiag) |
| 5620 | { |
| 5621 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(fcdiag->bfa); |
| 5622 | |
| 5623 | if (fcdiag->lb.lock) |
| 5624 | fcport->diag_busy = BFA_TRUE; |
| 5625 | else |
| 5626 | fcport->diag_busy = BFA_FALSE; |
| 5627 | } |
| 5628 | |
| 5629 | static void |
| 5630 | bfa_fcdiag_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *meminfo, |
| 5631 | struct bfa_s *bfa) |
| 5632 | { |
| 5633 | } |
| 5634 | |
| 5635 | static void |
| 5636 | bfa_fcdiag_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg, |
| 5637 | struct bfa_pcidev_s *pcidev) |
| 5638 | { |
| 5639 | struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa); |
Krishna Gudipati | e353546 | 2012-09-21 17:26:07 -0700 | [diff] [blame] | 5640 | struct bfa_dport_s *dport = &fcdiag->dport; |
| 5641 | |
Krishna Gudipati | 3d7fc66 | 2011-06-24 20:28:17 -0700 | [diff] [blame] | 5642 | fcdiag->bfa = bfa; |
| 5643 | fcdiag->trcmod = bfa->trcmod; |
| 5644 | /* The common DIAG attach bfa_diag_attach() will do all memory claim */ |
Krishna Gudipati | e353546 | 2012-09-21 17:26:07 -0700 | [diff] [blame] | 5645 | dport->bfa = bfa; |
| 5646 | bfa_sm_set_state(dport, bfa_dport_sm_disabled); |
| 5647 | bfa_reqq_winit(&dport->reqq_wait, bfa_dport_qresume, dport); |
| 5648 | dport->cbfn = NULL; |
| 5649 | dport->cbarg = NULL; |
Krishna Gudipati | 3d7fc66 | 2011-06-24 20:28:17 -0700 | [diff] [blame] | 5650 | } |
| 5651 | |
| 5652 | static void |
| 5653 | bfa_fcdiag_iocdisable(struct bfa_s *bfa) |
| 5654 | { |
| 5655 | struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa); |
Krishna Gudipati | e353546 | 2012-09-21 17:26:07 -0700 | [diff] [blame] | 5656 | struct bfa_dport_s *dport = &fcdiag->dport; |
| 5657 | |
Krishna Gudipati | 3d7fc66 | 2011-06-24 20:28:17 -0700 | [diff] [blame] | 5658 | bfa_trc(fcdiag, fcdiag->lb.lock); |
| 5659 | if (fcdiag->lb.lock) { |
| 5660 | fcdiag->lb.status = BFA_STATUS_IOC_FAILURE; |
| 5661 | fcdiag->lb.cbfn(fcdiag->lb.cbarg, fcdiag->lb.status); |
| 5662 | fcdiag->lb.lock = 0; |
| 5663 | bfa_fcdiag_set_busy_status(fcdiag); |
| 5664 | } |
Krishna Gudipati | e353546 | 2012-09-21 17:26:07 -0700 | [diff] [blame] | 5665 | |
| 5666 | bfa_sm_send_event(dport, BFA_DPORT_SM_HWFAIL); |
Krishna Gudipati | 3d7fc66 | 2011-06-24 20:28:17 -0700 | [diff] [blame] | 5667 | } |
| 5668 | |
| 5669 | static void |
| 5670 | bfa_fcdiag_detach(struct bfa_s *bfa) |
| 5671 | { |
| 5672 | } |
| 5673 | |
| 5674 | static void |
| 5675 | bfa_fcdiag_start(struct bfa_s *bfa) |
| 5676 | { |
| 5677 | } |
| 5678 | |
| 5679 | static void |
| 5680 | bfa_fcdiag_stop(struct bfa_s *bfa) |
| 5681 | { |
| 5682 | } |
| 5683 | |
| 5684 | static void |
| 5685 | bfa_fcdiag_queuetest_timeout(void *cbarg) |
| 5686 | { |
| 5687 | struct bfa_fcdiag_s *fcdiag = cbarg; |
| 5688 | struct bfa_diag_qtest_result_s *res = fcdiag->qtest.result; |
| 5689 | |
| 5690 | bfa_trc(fcdiag, fcdiag->qtest.all); |
| 5691 | bfa_trc(fcdiag, fcdiag->qtest.count); |
| 5692 | |
| 5693 | fcdiag->qtest.timer_active = 0; |
| 5694 | |
| 5695 | res->status = BFA_STATUS_ETIMER; |
| 5696 | res->count = QTEST_CNT_DEFAULT - fcdiag->qtest.count; |
| 5697 | if (fcdiag->qtest.all) |
| 5698 | res->queue = fcdiag->qtest.all; |
| 5699 | |
| 5700 | bfa_trc(fcdiag, BFA_STATUS_ETIMER); |
| 5701 | fcdiag->qtest.status = BFA_STATUS_ETIMER; |
| 5702 | fcdiag->qtest.cbfn(fcdiag->qtest.cbarg, fcdiag->qtest.status); |
| 5703 | fcdiag->qtest.lock = 0; |
| 5704 | } |
| 5705 | |
| 5706 | static bfa_status_t |
| 5707 | bfa_fcdiag_queuetest_send(struct bfa_fcdiag_s *fcdiag) |
| 5708 | { |
| 5709 | u32 i; |
| 5710 | struct bfi_diag_qtest_req_s *req; |
| 5711 | |
| 5712 | req = bfa_reqq_next(fcdiag->bfa, fcdiag->qtest.queue); |
| 5713 | if (!req) |
| 5714 | return BFA_STATUS_DEVBUSY; |
| 5715 | |
| 5716 | /* build host command */ |
| 5717 | bfi_h2i_set(req->mh, BFI_MC_DIAG, BFI_DIAG_H2I_QTEST, |
| 5718 | bfa_fn_lpu(fcdiag->bfa)); |
| 5719 | |
| 5720 | for (i = 0; i < BFI_LMSG_PL_WSZ; i++) |
| 5721 | req->data[i] = QTEST_PAT_DEFAULT; |
| 5722 | |
| 5723 | bfa_trc(fcdiag, fcdiag->qtest.queue); |
| 5724 | /* ring door bell */ |
| 5725 | bfa_reqq_produce(fcdiag->bfa, fcdiag->qtest.queue, req->mh); |
| 5726 | return BFA_STATUS_OK; |
| 5727 | } |
| 5728 | |
| 5729 | static void |
| 5730 | bfa_fcdiag_queuetest_comp(struct bfa_fcdiag_s *fcdiag, |
| 5731 | bfi_diag_qtest_rsp_t *rsp) |
| 5732 | { |
| 5733 | struct bfa_diag_qtest_result_s *res = fcdiag->qtest.result; |
| 5734 | bfa_status_t status = BFA_STATUS_OK; |
| 5735 | int i; |
| 5736 | |
| 5737 | /* Check timer, should still be active */ |
| 5738 | if (!fcdiag->qtest.timer_active) { |
| 5739 | bfa_trc(fcdiag, fcdiag->qtest.timer_active); |
| 5740 | return; |
| 5741 | } |
| 5742 | |
| 5743 | /* update count */ |
| 5744 | fcdiag->qtest.count--; |
| 5745 | |
| 5746 | /* Check result */ |
| 5747 | for (i = 0; i < BFI_LMSG_PL_WSZ; i++) { |
| 5748 | if (rsp->data[i] != ~(QTEST_PAT_DEFAULT)) { |
| 5749 | res->status = BFA_STATUS_DATACORRUPTED; |
| 5750 | break; |
| 5751 | } |
| 5752 | } |
| 5753 | |
| 5754 | if (res->status == BFA_STATUS_OK) { |
| 5755 | if (fcdiag->qtest.count > 0) { |
| 5756 | status = bfa_fcdiag_queuetest_send(fcdiag); |
| 5757 | if (status == BFA_STATUS_OK) |
| 5758 | return; |
| 5759 | else |
| 5760 | res->status = status; |
| 5761 | } else if (fcdiag->qtest.all > 0 && |
| 5762 | fcdiag->qtest.queue < (BFI_IOC_MAX_CQS - 1)) { |
| 5763 | fcdiag->qtest.count = QTEST_CNT_DEFAULT; |
| 5764 | fcdiag->qtest.queue++; |
| 5765 | status = bfa_fcdiag_queuetest_send(fcdiag); |
| 5766 | if (status == BFA_STATUS_OK) |
| 5767 | return; |
| 5768 | else |
| 5769 | res->status = status; |
| 5770 | } |
| 5771 | } |
| 5772 | |
| 5773 | /* Stop timer when we comp all queue */ |
| 5774 | if (fcdiag->qtest.timer_active) { |
| 5775 | bfa_timer_stop(&fcdiag->qtest.timer); |
| 5776 | fcdiag->qtest.timer_active = 0; |
| 5777 | } |
| 5778 | res->queue = fcdiag->qtest.queue; |
| 5779 | res->count = QTEST_CNT_DEFAULT - fcdiag->qtest.count; |
| 5780 | bfa_trc(fcdiag, res->count); |
| 5781 | bfa_trc(fcdiag, res->status); |
| 5782 | fcdiag->qtest.status = res->status; |
| 5783 | fcdiag->qtest.cbfn(fcdiag->qtest.cbarg, fcdiag->qtest.status); |
| 5784 | fcdiag->qtest.lock = 0; |
| 5785 | } |
| 5786 | |
| 5787 | static void |
| 5788 | bfa_fcdiag_loopback_comp(struct bfa_fcdiag_s *fcdiag, |
| 5789 | struct bfi_diag_lb_rsp_s *rsp) |
| 5790 | { |
| 5791 | struct bfa_diag_loopback_result_s *res = fcdiag->lb.result; |
| 5792 | |
| 5793 | res->numtxmfrm = be32_to_cpu(rsp->res.numtxmfrm); |
| 5794 | res->numosffrm = be32_to_cpu(rsp->res.numosffrm); |
| 5795 | res->numrcvfrm = be32_to_cpu(rsp->res.numrcvfrm); |
| 5796 | res->badfrminf = be32_to_cpu(rsp->res.badfrminf); |
| 5797 | res->badfrmnum = be32_to_cpu(rsp->res.badfrmnum); |
| 5798 | res->status = rsp->res.status; |
| 5799 | fcdiag->lb.status = rsp->res.status; |
| 5800 | bfa_trc(fcdiag, fcdiag->lb.status); |
| 5801 | fcdiag->lb.cbfn(fcdiag->lb.cbarg, fcdiag->lb.status); |
| 5802 | fcdiag->lb.lock = 0; |
| 5803 | bfa_fcdiag_set_busy_status(fcdiag); |
| 5804 | } |
| 5805 | |
| 5806 | static bfa_status_t |
| 5807 | bfa_fcdiag_loopback_send(struct bfa_fcdiag_s *fcdiag, |
| 5808 | struct bfa_diag_loopback_s *loopback) |
| 5809 | { |
| 5810 | struct bfi_diag_lb_req_s *lb_req; |
| 5811 | |
| 5812 | lb_req = bfa_reqq_next(fcdiag->bfa, BFA_REQQ_DIAG); |
| 5813 | if (!lb_req) |
| 5814 | return BFA_STATUS_DEVBUSY; |
| 5815 | |
| 5816 | /* build host command */ |
| 5817 | bfi_h2i_set(lb_req->mh, BFI_MC_DIAG, BFI_DIAG_H2I_LOOPBACK, |
| 5818 | bfa_fn_lpu(fcdiag->bfa)); |
| 5819 | |
| 5820 | lb_req->lb_mode = loopback->lb_mode; |
| 5821 | lb_req->speed = loopback->speed; |
| 5822 | lb_req->loopcnt = loopback->loopcnt; |
| 5823 | lb_req->pattern = loopback->pattern; |
| 5824 | |
| 5825 | /* ring door bell */ |
| 5826 | bfa_reqq_produce(fcdiag->bfa, BFA_REQQ_DIAG, lb_req->mh); |
| 5827 | |
| 5828 | bfa_trc(fcdiag, loopback->lb_mode); |
| 5829 | bfa_trc(fcdiag, loopback->speed); |
| 5830 | bfa_trc(fcdiag, loopback->loopcnt); |
| 5831 | bfa_trc(fcdiag, loopback->pattern); |
| 5832 | return BFA_STATUS_OK; |
| 5833 | } |
| 5834 | |
| 5835 | /* |
| 5836 | * cpe/rme intr handler |
| 5837 | */ |
| 5838 | void |
| 5839 | bfa_fcdiag_intr(struct bfa_s *bfa, struct bfi_msg_s *msg) |
| 5840 | { |
| 5841 | struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa); |
| 5842 | |
| 5843 | switch (msg->mhdr.msg_id) { |
| 5844 | case BFI_DIAG_I2H_LOOPBACK: |
| 5845 | bfa_fcdiag_loopback_comp(fcdiag, |
| 5846 | (struct bfi_diag_lb_rsp_s *) msg); |
| 5847 | break; |
| 5848 | case BFI_DIAG_I2H_QTEST: |
| 5849 | bfa_fcdiag_queuetest_comp(fcdiag, (bfi_diag_qtest_rsp_t *)msg); |
| 5850 | break; |
Krishna Gudipati | e353546 | 2012-09-21 17:26:07 -0700 | [diff] [blame] | 5851 | case BFI_DIAG_I2H_DPORT: |
| 5852 | bfa_dport_req_comp(&fcdiag->dport, (bfi_diag_dport_rsp_t *)msg); |
| 5853 | break; |
Krishna Gudipati | 3d7fc66 | 2011-06-24 20:28:17 -0700 | [diff] [blame] | 5854 | default: |
| 5855 | bfa_trc(fcdiag, msg->mhdr.msg_id); |
| 5856 | WARN_ON(1); |
| 5857 | } |
| 5858 | } |
| 5859 | |
| 5860 | /* |
| 5861 | * Loopback test |
| 5862 | * |
| 5863 | * @param[in] *bfa - bfa data struct |
| 5864 | * @param[in] opmode - port operation mode |
| 5865 | * @param[in] speed - port speed |
| 5866 | * @param[in] lpcnt - loop count |
| 5867 | * @param[in] pat - pattern to build packet |
| 5868 | * @param[in] *result - pt to bfa_diag_loopback_result_t data struct |
| 5869 | * @param[in] cbfn - callback function |
| 5870 | * @param[in] cbarg - callback functioin arg |
| 5871 | * |
| 5872 | * @param[out] |
| 5873 | */ |
| 5874 | bfa_status_t |
| 5875 | bfa_fcdiag_loopback(struct bfa_s *bfa, enum bfa_port_opmode opmode, |
| 5876 | enum bfa_port_speed speed, u32 lpcnt, u32 pat, |
| 5877 | struct bfa_diag_loopback_result_s *result, bfa_cb_diag_t cbfn, |
| 5878 | void *cbarg) |
| 5879 | { |
| 5880 | struct bfa_diag_loopback_s loopback; |
| 5881 | struct bfa_port_attr_s attr; |
| 5882 | bfa_status_t status; |
| 5883 | struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa); |
| 5884 | |
| 5885 | if (!bfa_iocfc_is_operational(bfa)) |
| 5886 | return BFA_STATUS_IOC_NON_OP; |
| 5887 | |
| 5888 | /* if port is PBC disabled, return error */ |
| 5889 | if (bfa_fcport_is_pbcdisabled(bfa)) { |
| 5890 | bfa_trc(fcdiag, BFA_STATUS_PBC); |
| 5891 | return BFA_STATUS_PBC; |
| 5892 | } |
| 5893 | |
| 5894 | if (bfa_fcport_is_disabled(bfa) == BFA_FALSE) { |
| 5895 | bfa_trc(fcdiag, opmode); |
| 5896 | return BFA_STATUS_PORT_NOT_DISABLED; |
| 5897 | } |
| 5898 | |
Krishna Gudipati | fb778b0 | 2011-07-20 17:01:07 -0700 | [diff] [blame] | 5899 | /* |
| 5900 | * Check if input speed is supported by the port mode |
| 5901 | */ |
| 5902 | if (bfa_ioc_get_type(&bfa->ioc) == BFA_IOC_TYPE_FC) { |
| 5903 | if (!(speed == BFA_PORT_SPEED_1GBPS || |
| 5904 | speed == BFA_PORT_SPEED_2GBPS || |
| 5905 | speed == BFA_PORT_SPEED_4GBPS || |
| 5906 | speed == BFA_PORT_SPEED_8GBPS || |
| 5907 | speed == BFA_PORT_SPEED_16GBPS || |
| 5908 | speed == BFA_PORT_SPEED_AUTO)) { |
| 5909 | bfa_trc(fcdiag, speed); |
| 5910 | return BFA_STATUS_UNSUPP_SPEED; |
| 5911 | } |
| 5912 | bfa_fcport_get_attr(bfa, &attr); |
| 5913 | bfa_trc(fcdiag, attr.speed_supported); |
| 5914 | if (speed > attr.speed_supported) |
| 5915 | return BFA_STATUS_UNSUPP_SPEED; |
| 5916 | } else { |
| 5917 | if (speed != BFA_PORT_SPEED_10GBPS) { |
| 5918 | bfa_trc(fcdiag, speed); |
| 5919 | return BFA_STATUS_UNSUPP_SPEED; |
| 5920 | } |
| 5921 | } |
Krishna Gudipati | 3d7fc66 | 2011-06-24 20:28:17 -0700 | [diff] [blame] | 5922 | |
Krishna Gudipati | e353546 | 2012-09-21 17:26:07 -0700 | [diff] [blame] | 5923 | /* |
| 5924 | * For CT2, 1G is not supported |
| 5925 | */ |
| 5926 | if ((speed == BFA_PORT_SPEED_1GBPS) && |
| 5927 | (bfa_asic_id_ct2(bfa->ioc.pcidev.device_id))) { |
| 5928 | bfa_trc(fcdiag, speed); |
| 5929 | return BFA_STATUS_UNSUPP_SPEED; |
| 5930 | } |
| 5931 | |
Krishna Gudipati | 3d7fc66 | 2011-06-24 20:28:17 -0700 | [diff] [blame] | 5932 | /* For Mezz card, port speed entered needs to be checked */ |
| 5933 | if (bfa_mfg_is_mezz(bfa->ioc.attr->card_type)) { |
| 5934 | if (bfa_ioc_get_type(&bfa->ioc) == BFA_IOC_TYPE_FC) { |
Krishna Gudipati | 3d7fc66 | 2011-06-24 20:28:17 -0700 | [diff] [blame] | 5935 | if (!(speed == BFA_PORT_SPEED_1GBPS || |
| 5936 | speed == BFA_PORT_SPEED_2GBPS || |
| 5937 | speed == BFA_PORT_SPEED_4GBPS || |
| 5938 | speed == BFA_PORT_SPEED_8GBPS || |
| 5939 | speed == BFA_PORT_SPEED_16GBPS || |
| 5940 | speed == BFA_PORT_SPEED_AUTO)) |
| 5941 | return BFA_STATUS_UNSUPP_SPEED; |
| 5942 | } else { |
| 5943 | if (speed != BFA_PORT_SPEED_10GBPS) |
| 5944 | return BFA_STATUS_UNSUPP_SPEED; |
| 5945 | } |
| 5946 | } |
| 5947 | |
| 5948 | /* check to see if there is another destructive diag cmd running */ |
| 5949 | if (fcdiag->lb.lock) { |
| 5950 | bfa_trc(fcdiag, fcdiag->lb.lock); |
| 5951 | return BFA_STATUS_DEVBUSY; |
| 5952 | } |
| 5953 | |
| 5954 | fcdiag->lb.lock = 1; |
| 5955 | loopback.lb_mode = opmode; |
| 5956 | loopback.speed = speed; |
| 5957 | loopback.loopcnt = lpcnt; |
| 5958 | loopback.pattern = pat; |
| 5959 | fcdiag->lb.result = result; |
| 5960 | fcdiag->lb.cbfn = cbfn; |
| 5961 | fcdiag->lb.cbarg = cbarg; |
| 5962 | memset(result, 0, sizeof(struct bfa_diag_loopback_result_s)); |
| 5963 | bfa_fcdiag_set_busy_status(fcdiag); |
| 5964 | |
| 5965 | /* Send msg to fw */ |
| 5966 | status = bfa_fcdiag_loopback_send(fcdiag, &loopback); |
| 5967 | return status; |
| 5968 | } |
| 5969 | |
| 5970 | /* |
| 5971 | * DIAG queue test command |
| 5972 | * |
| 5973 | * @param[in] *bfa - bfa data struct |
| 5974 | * @param[in] force - 1: don't do ioc op checking |
| 5975 | * @param[in] queue - queue no. to test |
| 5976 | * @param[in] *result - pt to bfa_diag_qtest_result_t data struct |
| 5977 | * @param[in] cbfn - callback function |
| 5978 | * @param[in] *cbarg - callback functioin arg |
| 5979 | * |
| 5980 | * @param[out] |
| 5981 | */ |
| 5982 | bfa_status_t |
| 5983 | bfa_fcdiag_queuetest(struct bfa_s *bfa, u32 force, u32 queue, |
| 5984 | struct bfa_diag_qtest_result_s *result, bfa_cb_diag_t cbfn, |
| 5985 | void *cbarg) |
| 5986 | { |
| 5987 | struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa); |
| 5988 | bfa_status_t status; |
| 5989 | bfa_trc(fcdiag, force); |
| 5990 | bfa_trc(fcdiag, queue); |
| 5991 | |
| 5992 | if (!force && !bfa_iocfc_is_operational(bfa)) |
| 5993 | return BFA_STATUS_IOC_NON_OP; |
| 5994 | |
| 5995 | /* check to see if there is another destructive diag cmd running */ |
| 5996 | if (fcdiag->qtest.lock) { |
| 5997 | bfa_trc(fcdiag, fcdiag->qtest.lock); |
| 5998 | return BFA_STATUS_DEVBUSY; |
| 5999 | } |
| 6000 | |
| 6001 | /* Initialization */ |
| 6002 | fcdiag->qtest.lock = 1; |
| 6003 | fcdiag->qtest.cbfn = cbfn; |
| 6004 | fcdiag->qtest.cbarg = cbarg; |
| 6005 | fcdiag->qtest.result = result; |
| 6006 | fcdiag->qtest.count = QTEST_CNT_DEFAULT; |
| 6007 | |
| 6008 | /* Init test results */ |
| 6009 | fcdiag->qtest.result->status = BFA_STATUS_OK; |
| 6010 | fcdiag->qtest.result->count = 0; |
| 6011 | |
| 6012 | /* send */ |
| 6013 | if (queue < BFI_IOC_MAX_CQS) { |
| 6014 | fcdiag->qtest.result->queue = (u8)queue; |
| 6015 | fcdiag->qtest.queue = (u8)queue; |
| 6016 | fcdiag->qtest.all = 0; |
| 6017 | } else { |
| 6018 | fcdiag->qtest.result->queue = 0; |
| 6019 | fcdiag->qtest.queue = 0; |
| 6020 | fcdiag->qtest.all = 1; |
| 6021 | } |
| 6022 | status = bfa_fcdiag_queuetest_send(fcdiag); |
| 6023 | |
| 6024 | /* Start a timer */ |
| 6025 | if (status == BFA_STATUS_OK) { |
| 6026 | bfa_timer_start(bfa, &fcdiag->qtest.timer, |
| 6027 | bfa_fcdiag_queuetest_timeout, fcdiag, |
| 6028 | BFA_DIAG_QTEST_TOV); |
| 6029 | fcdiag->qtest.timer_active = 1; |
| 6030 | } |
| 6031 | return status; |
| 6032 | } |
| 6033 | |
| 6034 | /* |
| 6035 | * DIAG PLB is running |
| 6036 | * |
| 6037 | * @param[in] *bfa - bfa data struct |
| 6038 | * |
| 6039 | * @param[out] |
| 6040 | */ |
| 6041 | bfa_status_t |
| 6042 | bfa_fcdiag_lb_is_running(struct bfa_s *bfa) |
| 6043 | { |
| 6044 | struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa); |
| 6045 | return fcdiag->lb.lock ? BFA_STATUS_DIAG_BUSY : BFA_STATUS_OK; |
| 6046 | } |
Krishna Gudipati | e353546 | 2012-09-21 17:26:07 -0700 | [diff] [blame] | 6047 | |
| 6048 | /* |
| 6049 | * D-port |
| 6050 | */ |
| 6051 | static bfa_boolean_t bfa_dport_send_req(struct bfa_dport_s *dport, |
| 6052 | enum bfi_dport_req req); |
| 6053 | static void |
| 6054 | bfa_cb_fcdiag_dport(struct bfa_dport_s *dport, bfa_status_t bfa_status) |
| 6055 | { |
| 6056 | if (dport->cbfn != NULL) { |
| 6057 | dport->cbfn(dport->cbarg, bfa_status); |
| 6058 | dport->cbfn = NULL; |
| 6059 | dport->cbarg = NULL; |
| 6060 | } |
| 6061 | } |
| 6062 | |
| 6063 | static void |
| 6064 | bfa_dport_sm_disabled(struct bfa_dport_s *dport, enum bfa_dport_sm_event event) |
| 6065 | { |
| 6066 | bfa_trc(dport->bfa, event); |
| 6067 | |
| 6068 | switch (event) { |
| 6069 | case BFA_DPORT_SM_ENABLE: |
| 6070 | bfa_fcport_dportenable(dport->bfa); |
| 6071 | if (bfa_dport_send_req(dport, BFI_DPORT_ENABLE)) |
| 6072 | bfa_sm_set_state(dport, bfa_dport_sm_enabling); |
| 6073 | else |
| 6074 | bfa_sm_set_state(dport, bfa_dport_sm_enabling_qwait); |
| 6075 | break; |
| 6076 | |
| 6077 | case BFA_DPORT_SM_DISABLE: |
| 6078 | /* Already disabled */ |
| 6079 | break; |
| 6080 | |
| 6081 | case BFA_DPORT_SM_HWFAIL: |
| 6082 | /* ignore */ |
| 6083 | break; |
| 6084 | |
| 6085 | default: |
| 6086 | bfa_sm_fault(dport->bfa, event); |
| 6087 | } |
| 6088 | } |
| 6089 | |
| 6090 | static void |
| 6091 | bfa_dport_sm_enabling_qwait(struct bfa_dport_s *dport, |
| 6092 | enum bfa_dport_sm_event event) |
| 6093 | { |
| 6094 | bfa_trc(dport->bfa, event); |
| 6095 | |
| 6096 | switch (event) { |
| 6097 | case BFA_DPORT_SM_QRESUME: |
| 6098 | bfa_sm_set_state(dport, bfa_dport_sm_enabling); |
| 6099 | bfa_dport_send_req(dport, BFI_DPORT_ENABLE); |
| 6100 | break; |
| 6101 | |
| 6102 | case BFA_DPORT_SM_HWFAIL: |
| 6103 | bfa_reqq_wcancel(&dport->reqq_wait); |
| 6104 | bfa_sm_set_state(dport, bfa_dport_sm_disabled); |
| 6105 | bfa_cb_fcdiag_dport(dport, BFA_STATUS_FAILED); |
| 6106 | break; |
| 6107 | |
| 6108 | default: |
| 6109 | bfa_sm_fault(dport->bfa, event); |
| 6110 | } |
| 6111 | } |
| 6112 | |
| 6113 | static void |
| 6114 | bfa_dport_sm_enabling(struct bfa_dport_s *dport, enum bfa_dport_sm_event event) |
| 6115 | { |
| 6116 | bfa_trc(dport->bfa, event); |
| 6117 | |
| 6118 | switch (event) { |
| 6119 | case BFA_DPORT_SM_FWRSP: |
| 6120 | bfa_sm_set_state(dport, bfa_dport_sm_enabled); |
| 6121 | break; |
| 6122 | |
| 6123 | case BFA_DPORT_SM_HWFAIL: |
| 6124 | bfa_sm_set_state(dport, bfa_dport_sm_disabled); |
| 6125 | bfa_cb_fcdiag_dport(dport, BFA_STATUS_FAILED); |
| 6126 | break; |
| 6127 | |
| 6128 | default: |
| 6129 | bfa_sm_fault(dport->bfa, event); |
| 6130 | } |
| 6131 | } |
| 6132 | |
| 6133 | static void |
| 6134 | bfa_dport_sm_enabled(struct bfa_dport_s *dport, enum bfa_dport_sm_event event) |
| 6135 | { |
| 6136 | bfa_trc(dport->bfa, event); |
| 6137 | |
| 6138 | switch (event) { |
| 6139 | case BFA_DPORT_SM_ENABLE: |
| 6140 | /* Already enabled */ |
| 6141 | break; |
| 6142 | |
| 6143 | case BFA_DPORT_SM_DISABLE: |
| 6144 | bfa_fcport_dportdisable(dport->bfa); |
| 6145 | if (bfa_dport_send_req(dport, BFI_DPORT_DISABLE)) |
| 6146 | bfa_sm_set_state(dport, bfa_dport_sm_disabling); |
| 6147 | else |
| 6148 | bfa_sm_set_state(dport, bfa_dport_sm_disabling_qwait); |
| 6149 | break; |
| 6150 | |
| 6151 | case BFA_DPORT_SM_HWFAIL: |
| 6152 | bfa_sm_set_state(dport, bfa_dport_sm_disabled); |
| 6153 | break; |
| 6154 | |
| 6155 | default: |
| 6156 | bfa_sm_fault(dport->bfa, event); |
| 6157 | } |
| 6158 | } |
| 6159 | |
| 6160 | static void |
| 6161 | bfa_dport_sm_disabling_qwait(struct bfa_dport_s *dport, |
| 6162 | enum bfa_dport_sm_event event) |
| 6163 | { |
| 6164 | bfa_trc(dport->bfa, event); |
| 6165 | |
| 6166 | switch (event) { |
| 6167 | case BFA_DPORT_SM_QRESUME: |
| 6168 | bfa_sm_set_state(dport, bfa_dport_sm_disabling); |
| 6169 | bfa_dport_send_req(dport, BFI_DPORT_DISABLE); |
| 6170 | break; |
| 6171 | |
| 6172 | case BFA_DPORT_SM_HWFAIL: |
| 6173 | bfa_sm_set_state(dport, bfa_dport_sm_disabled); |
| 6174 | bfa_reqq_wcancel(&dport->reqq_wait); |
| 6175 | bfa_cb_fcdiag_dport(dport, BFA_STATUS_OK); |
| 6176 | break; |
| 6177 | |
| 6178 | default: |
| 6179 | bfa_sm_fault(dport->bfa, event); |
| 6180 | } |
| 6181 | } |
| 6182 | |
| 6183 | static void |
| 6184 | bfa_dport_sm_disabling(struct bfa_dport_s *dport, enum bfa_dport_sm_event event) |
| 6185 | { |
| 6186 | bfa_trc(dport->bfa, event); |
| 6187 | |
| 6188 | switch (event) { |
| 6189 | case BFA_DPORT_SM_FWRSP: |
| 6190 | bfa_sm_set_state(dport, bfa_dport_sm_disabled); |
| 6191 | break; |
| 6192 | |
| 6193 | case BFA_DPORT_SM_HWFAIL: |
| 6194 | bfa_sm_set_state(dport, bfa_dport_sm_disabled); |
| 6195 | bfa_cb_fcdiag_dport(dport, BFA_STATUS_OK); |
| 6196 | break; |
| 6197 | |
| 6198 | default: |
| 6199 | bfa_sm_fault(dport->bfa, event); |
| 6200 | } |
| 6201 | } |
| 6202 | |
| 6203 | |
| 6204 | static bfa_boolean_t |
| 6205 | bfa_dport_send_req(struct bfa_dport_s *dport, enum bfi_dport_req req) |
| 6206 | { |
| 6207 | struct bfi_diag_dport_req_s *m; |
| 6208 | |
| 6209 | /* |
| 6210 | * Increment message tag before queue check, so that responses to old |
| 6211 | * requests are discarded. |
| 6212 | */ |
| 6213 | dport->msgtag++; |
| 6214 | |
| 6215 | /* |
| 6216 | * check for room in queue to send request now |
| 6217 | */ |
| 6218 | m = bfa_reqq_next(dport->bfa, BFA_REQQ_DIAG); |
| 6219 | if (!m) { |
| 6220 | bfa_reqq_wait(dport->bfa, BFA_REQQ_PORT, &dport->reqq_wait); |
| 6221 | return BFA_FALSE; |
| 6222 | } |
| 6223 | |
| 6224 | bfi_h2i_set(m->mh, BFI_MC_DIAG, BFI_DIAG_H2I_DPORT, |
| 6225 | bfa_fn_lpu(dport->bfa)); |
| 6226 | m->req = req; |
| 6227 | m->msgtag = dport->msgtag; |
| 6228 | |
| 6229 | /* |
| 6230 | * queue I/O message to firmware |
| 6231 | */ |
| 6232 | bfa_reqq_produce(dport->bfa, BFA_REQQ_DIAG, m->mh); |
| 6233 | |
| 6234 | return BFA_TRUE; |
| 6235 | } |
| 6236 | |
| 6237 | static void |
| 6238 | bfa_dport_qresume(void *cbarg) |
| 6239 | { |
| 6240 | struct bfa_dport_s *dport = cbarg; |
| 6241 | |
| 6242 | bfa_sm_send_event(dport, BFA_DPORT_SM_QRESUME); |
| 6243 | } |
| 6244 | |
| 6245 | static void |
| 6246 | bfa_dport_req_comp(struct bfa_dport_s *dport, bfi_diag_dport_rsp_t *msg) |
| 6247 | { |
| 6248 | bfa_sm_send_event(dport, BFA_DPORT_SM_FWRSP); |
| 6249 | bfa_cb_fcdiag_dport(dport, msg->status); |
| 6250 | } |
| 6251 | |
| 6252 | /* |
| 6253 | * Dport enable |
| 6254 | * |
| 6255 | * @param[in] *bfa - bfa data struct |
| 6256 | */ |
| 6257 | bfa_status_t |
| 6258 | bfa_dport_enable(struct bfa_s *bfa, bfa_cb_diag_t cbfn, void *cbarg) |
| 6259 | { |
| 6260 | struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa); |
| 6261 | struct bfa_dport_s *dport = &fcdiag->dport; |
| 6262 | |
| 6263 | /* |
| 6264 | * Dport is not support in MEZZ card |
| 6265 | */ |
| 6266 | if (bfa_mfg_is_mezz(dport->bfa->ioc.attr->card_type)) { |
| 6267 | bfa_trc(dport->bfa, BFA_STATUS_PBC); |
| 6268 | return BFA_STATUS_CMD_NOTSUPP_MEZZ; |
| 6269 | } |
| 6270 | |
| 6271 | /* |
| 6272 | * Check to see if IOC is down |
| 6273 | */ |
| 6274 | if (!bfa_iocfc_is_operational(bfa)) |
| 6275 | return BFA_STATUS_IOC_NON_OP; |
| 6276 | |
| 6277 | /* if port is PBC disabled, return error */ |
| 6278 | if (bfa_fcport_is_pbcdisabled(bfa)) { |
| 6279 | bfa_trc(dport->bfa, BFA_STATUS_PBC); |
| 6280 | return BFA_STATUS_PBC; |
| 6281 | } |
| 6282 | |
| 6283 | /* |
| 6284 | * Check if port mode is FC port |
| 6285 | */ |
| 6286 | if (bfa_ioc_get_type(&bfa->ioc) != BFA_IOC_TYPE_FC) { |
| 6287 | bfa_trc(dport->bfa, bfa_ioc_get_type(&bfa->ioc)); |
| 6288 | return BFA_STATUS_CMD_NOTSUPP_CNA; |
| 6289 | } |
| 6290 | |
| 6291 | /* |
| 6292 | * Check if port is in LOOP mode |
| 6293 | */ |
| 6294 | if ((bfa_fcport_get_cfg_topology(bfa) == BFA_PORT_TOPOLOGY_LOOP) || |
| 6295 | (bfa_fcport_get_topology(bfa) == BFA_PORT_TOPOLOGY_LOOP)) { |
| 6296 | bfa_trc(dport->bfa, 0); |
| 6297 | return BFA_STATUS_TOPOLOGY_LOOP; |
| 6298 | } |
| 6299 | |
| 6300 | /* |
| 6301 | * Check if port is TRUNK mode |
| 6302 | */ |
| 6303 | if (bfa_fcport_is_trunk_enabled(bfa)) { |
| 6304 | bfa_trc(dport->bfa, 0); |
| 6305 | return BFA_STATUS_ERROR_TRUNK_ENABLED; |
| 6306 | } |
| 6307 | |
| 6308 | /* |
| 6309 | * Check to see if port is disable or in dport state |
| 6310 | */ |
| 6311 | if ((bfa_fcport_is_disabled(bfa) == BFA_FALSE) && |
| 6312 | (bfa_fcport_is_dport(bfa) == BFA_FALSE)) { |
| 6313 | bfa_trc(dport->bfa, 0); |
| 6314 | return BFA_STATUS_PORT_NOT_DISABLED; |
| 6315 | } |
| 6316 | |
| 6317 | /* |
| 6318 | * Check if dport is busy |
| 6319 | */ |
| 6320 | if (bfa_sm_cmp_state(dport, bfa_dport_sm_enabling) || |
| 6321 | bfa_sm_cmp_state(dport, bfa_dport_sm_enabling_qwait) || |
| 6322 | bfa_sm_cmp_state(dport, bfa_dport_sm_disabling) || |
| 6323 | bfa_sm_cmp_state(dport, bfa_dport_sm_disabling_qwait)) { |
| 6324 | return BFA_STATUS_DEVBUSY; |
| 6325 | } |
| 6326 | |
| 6327 | /* |
| 6328 | * Check if dport is already enabled |
| 6329 | */ |
| 6330 | if (bfa_sm_cmp_state(dport, bfa_dport_sm_enabled)) { |
| 6331 | bfa_trc(dport->bfa, 0); |
| 6332 | return BFA_STATUS_DPORT_ENABLED; |
| 6333 | } |
| 6334 | |
| 6335 | dport->cbfn = cbfn; |
| 6336 | dport->cbarg = cbarg; |
| 6337 | |
| 6338 | bfa_sm_send_event(dport, BFA_DPORT_SM_ENABLE); |
| 6339 | return BFA_STATUS_OK; |
| 6340 | } |
| 6341 | |
| 6342 | /* |
| 6343 | * Dport disable |
| 6344 | * |
| 6345 | * @param[in] *bfa - bfa data struct |
| 6346 | */ |
| 6347 | bfa_status_t |
| 6348 | bfa_dport_disable(struct bfa_s *bfa, bfa_cb_diag_t cbfn, void *cbarg) |
| 6349 | { |
| 6350 | struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa); |
| 6351 | struct bfa_dport_s *dport = &fcdiag->dport; |
| 6352 | |
| 6353 | if (bfa_ioc_is_disabled(&bfa->ioc)) |
| 6354 | return BFA_STATUS_IOC_DISABLED; |
| 6355 | |
| 6356 | /* if port is PBC disabled, return error */ |
| 6357 | if (bfa_fcport_is_pbcdisabled(bfa)) { |
| 6358 | bfa_trc(dport->bfa, BFA_STATUS_PBC); |
| 6359 | return BFA_STATUS_PBC; |
| 6360 | } |
| 6361 | |
| 6362 | /* |
| 6363 | * Check to see if port is disable or in dport state |
| 6364 | */ |
| 6365 | if ((bfa_fcport_is_disabled(bfa) == BFA_FALSE) && |
| 6366 | (bfa_fcport_is_dport(bfa) == BFA_FALSE)) { |
| 6367 | bfa_trc(dport->bfa, 0); |
| 6368 | return BFA_STATUS_PORT_NOT_DISABLED; |
| 6369 | } |
| 6370 | |
| 6371 | /* |
| 6372 | * Check if dport is busy |
| 6373 | */ |
| 6374 | if (bfa_sm_cmp_state(dport, bfa_dport_sm_enabling) || |
| 6375 | bfa_sm_cmp_state(dport, bfa_dport_sm_enabling_qwait) || |
| 6376 | bfa_sm_cmp_state(dport, bfa_dport_sm_disabling) || |
| 6377 | bfa_sm_cmp_state(dport, bfa_dport_sm_disabling_qwait)) |
| 6378 | return BFA_STATUS_DEVBUSY; |
| 6379 | |
| 6380 | /* |
| 6381 | * Check if dport is already disabled |
| 6382 | */ |
| 6383 | if (bfa_sm_cmp_state(dport, bfa_dport_sm_disabled)) { |
| 6384 | bfa_trc(dport->bfa, 0); |
| 6385 | return BFA_STATUS_DPORT_DISABLED; |
| 6386 | } |
| 6387 | |
| 6388 | dport->cbfn = cbfn; |
| 6389 | dport->cbarg = cbarg; |
| 6390 | |
| 6391 | bfa_sm_send_event(dport, BFA_DPORT_SM_DISABLE); |
| 6392 | return BFA_STATUS_OK; |
| 6393 | } |
| 6394 | |
| 6395 | /* |
| 6396 | * Get D-port state |
| 6397 | * |
| 6398 | * @param[in] *bfa - bfa data struct |
| 6399 | */ |
| 6400 | |
| 6401 | bfa_status_t |
| 6402 | bfa_dport_get_state(struct bfa_s *bfa, enum bfa_dport_state *state) |
| 6403 | { |
| 6404 | struct bfa_fcdiag_s *fcdiag = BFA_FCDIAG_MOD(bfa); |
| 6405 | struct bfa_dport_s *dport = &fcdiag->dport; |
| 6406 | |
| 6407 | if (bfa_sm_cmp_state(dport, bfa_dport_sm_enabled)) |
| 6408 | *state = BFA_DPORT_ST_ENABLED; |
| 6409 | else if (bfa_sm_cmp_state(dport, bfa_dport_sm_enabling) || |
| 6410 | bfa_sm_cmp_state(dport, bfa_dport_sm_enabling_qwait)) |
| 6411 | *state = BFA_DPORT_ST_ENABLING; |
| 6412 | else if (bfa_sm_cmp_state(dport, bfa_dport_sm_disabled)) |
| 6413 | *state = BFA_DPORT_ST_DISABLED; |
| 6414 | else if (bfa_sm_cmp_state(dport, bfa_dport_sm_disabling) || |
| 6415 | bfa_sm_cmp_state(dport, bfa_dport_sm_disabling_qwait)) |
| 6416 | *state = BFA_DPORT_ST_DISABLING; |
| 6417 | else { |
| 6418 | bfa_trc(dport->bfa, BFA_STATUS_EINVAL); |
| 6419 | return BFA_STATUS_EINVAL; |
| 6420 | } |
| 6421 | return BFA_STATUS_OK; |
| 6422 | } |