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 | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 19 | #include "bfa_plog.h" |
| 20 | #include "bfa_cs.h" |
| 21 | #include "bfa_modules.h" |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 22 | |
| 23 | BFA_TRC_FILE(HAL, FCXP); |
| 24 | BFA_MODULE(fcxp); |
| 25 | BFA_MODULE(sgpg); |
| 26 | BFA_MODULE(lps); |
| 27 | BFA_MODULE(fcport); |
| 28 | BFA_MODULE(rport); |
| 29 | BFA_MODULE(uf); |
| 30 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 31 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 32 | * LPS related definitions |
| 33 | */ |
| 34 | #define BFA_LPS_MIN_LPORTS (1) |
| 35 | #define BFA_LPS_MAX_LPORTS (256) |
| 36 | |
| 37 | /* |
| 38 | * Maximum Vports supported per physical port or vf. |
| 39 | */ |
| 40 | #define BFA_LPS_MAX_VPORTS_SUPP_CB 255 |
| 41 | #define BFA_LPS_MAX_VPORTS_SUPP_CT 190 |
| 42 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 43 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 44 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 45 | * FC PORT related definitions |
| 46 | */ |
| 47 | /* |
| 48 | * The port is considered disabled if corresponding physical port or IOC are |
| 49 | * disabled explicitly |
| 50 | */ |
| 51 | #define BFA_PORT_IS_DISABLED(bfa) \ |
| 52 | ((bfa_fcport_is_disabled(bfa) == BFA_TRUE) || \ |
| 53 | (bfa_ioc_is_disabled(&bfa->ioc) == BFA_TRUE)) |
| 54 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 55 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 56 | * BFA port state machine events |
| 57 | */ |
| 58 | enum bfa_fcport_sm_event { |
| 59 | BFA_FCPORT_SM_START = 1, /* start port state machine */ |
| 60 | BFA_FCPORT_SM_STOP = 2, /* stop port state machine */ |
| 61 | BFA_FCPORT_SM_ENABLE = 3, /* enable port */ |
| 62 | BFA_FCPORT_SM_DISABLE = 4, /* disable port state machine */ |
| 63 | BFA_FCPORT_SM_FWRSP = 5, /* firmware enable/disable rsp */ |
| 64 | BFA_FCPORT_SM_LINKUP = 6, /* firmware linkup event */ |
| 65 | BFA_FCPORT_SM_LINKDOWN = 7, /* firmware linkup down */ |
| 66 | BFA_FCPORT_SM_QRESUME = 8, /* CQ space available */ |
| 67 | BFA_FCPORT_SM_HWFAIL = 9, /* IOC h/w failure */ |
| 68 | }; |
| 69 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 70 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 71 | * BFA port link notification state machine events |
| 72 | */ |
| 73 | |
| 74 | enum bfa_fcport_ln_sm_event { |
| 75 | BFA_FCPORT_LN_SM_LINKUP = 1, /* linkup event */ |
| 76 | BFA_FCPORT_LN_SM_LINKDOWN = 2, /* linkdown event */ |
| 77 | BFA_FCPORT_LN_SM_NOTIFICATION = 3 /* done notification */ |
| 78 | }; |
| 79 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 80 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 81 | * RPORT related definitions |
| 82 | */ |
| 83 | #define bfa_rport_offline_cb(__rp) do { \ |
| 84 | if ((__rp)->bfa->fcs) \ |
| 85 | bfa_cb_rport_offline((__rp)->rport_drv); \ |
| 86 | else { \ |
| 87 | bfa_cb_queue((__rp)->bfa, &(__rp)->hcb_qe, \ |
| 88 | __bfa_cb_rport_offline, (__rp)); \ |
| 89 | } \ |
| 90 | } while (0) |
| 91 | |
| 92 | #define bfa_rport_online_cb(__rp) do { \ |
| 93 | if ((__rp)->bfa->fcs) \ |
| 94 | bfa_cb_rport_online((__rp)->rport_drv); \ |
| 95 | else { \ |
| 96 | bfa_cb_queue((__rp)->bfa, &(__rp)->hcb_qe, \ |
| 97 | __bfa_cb_rport_online, (__rp)); \ |
| 98 | } \ |
| 99 | } while (0) |
| 100 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 101 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 102 | * forward declarations FCXP related functions |
| 103 | */ |
| 104 | static void __bfa_fcxp_send_cbfn(void *cbarg, bfa_boolean_t complete); |
| 105 | static void hal_fcxp_rx_plog(struct bfa_s *bfa, struct bfa_fcxp_s *fcxp, |
| 106 | struct bfi_fcxp_send_rsp_s *fcxp_rsp); |
| 107 | static void hal_fcxp_tx_plog(struct bfa_s *bfa, u32 reqlen, |
| 108 | struct bfa_fcxp_s *fcxp, struct fchs_s *fchs); |
| 109 | static void bfa_fcxp_qresume(void *cbarg); |
| 110 | static void bfa_fcxp_queue(struct bfa_fcxp_s *fcxp, |
| 111 | struct bfi_fcxp_send_req_s *send_req); |
| 112 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 113 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 114 | * forward declarations for LPS functions |
| 115 | */ |
| 116 | static void bfa_lps_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *ndm_len, |
| 117 | u32 *dm_len); |
| 118 | static void bfa_lps_attach(struct bfa_s *bfa, void *bfad, |
| 119 | struct bfa_iocfc_cfg_s *cfg, |
| 120 | struct bfa_meminfo_s *meminfo, |
| 121 | struct bfa_pcidev_s *pcidev); |
| 122 | static void bfa_lps_detach(struct bfa_s *bfa); |
| 123 | static void bfa_lps_start(struct bfa_s *bfa); |
| 124 | static void bfa_lps_stop(struct bfa_s *bfa); |
| 125 | static void bfa_lps_iocdisable(struct bfa_s *bfa); |
| 126 | static void bfa_lps_login_rsp(struct bfa_s *bfa, |
| 127 | struct bfi_lps_login_rsp_s *rsp); |
| 128 | static void bfa_lps_logout_rsp(struct bfa_s *bfa, |
| 129 | struct bfi_lps_logout_rsp_s *rsp); |
| 130 | static void bfa_lps_reqq_resume(void *lps_arg); |
| 131 | static void bfa_lps_free(struct bfa_lps_s *lps); |
| 132 | static void bfa_lps_send_login(struct bfa_lps_s *lps); |
| 133 | static void bfa_lps_send_logout(struct bfa_lps_s *lps); |
Krishna Gudipati | b704495 | 2010-12-13 16:17:42 -0800 | [diff] [blame] | 134 | 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] | 135 | static void bfa_lps_login_comp(struct bfa_lps_s *lps); |
| 136 | static void bfa_lps_logout_comp(struct bfa_lps_s *lps); |
| 137 | static void bfa_lps_cvl_event(struct bfa_lps_s *lps); |
| 138 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 139 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 140 | * forward declaration for LPS state machine |
| 141 | */ |
| 142 | static void bfa_lps_sm_init(struct bfa_lps_s *lps, enum bfa_lps_event event); |
| 143 | static void bfa_lps_sm_login(struct bfa_lps_s *lps, enum bfa_lps_event event); |
| 144 | static void bfa_lps_sm_loginwait(struct bfa_lps_s *lps, enum bfa_lps_event |
| 145 | event); |
| 146 | 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] | 147 | static void bfa_lps_sm_online_n2n_pid_wait(struct bfa_lps_s *lps, |
| 148 | enum bfa_lps_event event); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 149 | static void bfa_lps_sm_logout(struct bfa_lps_s *lps, enum bfa_lps_event event); |
| 150 | static void bfa_lps_sm_logowait(struct bfa_lps_s *lps, enum bfa_lps_event |
| 151 | event); |
| 152 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 153 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 154 | * forward declaration for FC Port functions |
| 155 | */ |
| 156 | static bfa_boolean_t bfa_fcport_send_enable(struct bfa_fcport_s *fcport); |
| 157 | static bfa_boolean_t bfa_fcport_send_disable(struct bfa_fcport_s *fcport); |
| 158 | static void bfa_fcport_update_linkinfo(struct bfa_fcport_s *fcport); |
| 159 | static void bfa_fcport_reset_linkinfo(struct bfa_fcport_s *fcport); |
| 160 | static void bfa_fcport_set_wwns(struct bfa_fcport_s *fcport); |
| 161 | static void __bfa_cb_fcport_event(void *cbarg, bfa_boolean_t complete); |
| 162 | static void bfa_fcport_scn(struct bfa_fcport_s *fcport, |
| 163 | enum bfa_port_linkstate event, bfa_boolean_t trunk); |
| 164 | static void bfa_fcport_queue_cb(struct bfa_fcport_ln_s *ln, |
| 165 | enum bfa_port_linkstate event); |
| 166 | static void __bfa_cb_fcport_stats_clr(void *cbarg, bfa_boolean_t complete); |
| 167 | static void bfa_fcport_stats_get_timeout(void *cbarg); |
| 168 | static void bfa_fcport_stats_clr_timeout(void *cbarg); |
| 169 | static void bfa_trunk_iocdisable(struct bfa_s *bfa); |
| 170 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 171 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 172 | * forward declaration for FC PORT state machine |
| 173 | */ |
| 174 | static void bfa_fcport_sm_uninit(struct bfa_fcport_s *fcport, |
| 175 | enum bfa_fcport_sm_event event); |
| 176 | static void bfa_fcport_sm_enabling_qwait(struct bfa_fcport_s *fcport, |
| 177 | enum bfa_fcport_sm_event event); |
| 178 | static void bfa_fcport_sm_enabling(struct bfa_fcport_s *fcport, |
| 179 | enum bfa_fcport_sm_event event); |
| 180 | static void bfa_fcport_sm_linkdown(struct bfa_fcport_s *fcport, |
| 181 | enum bfa_fcport_sm_event event); |
| 182 | static void bfa_fcport_sm_linkup(struct bfa_fcport_s *fcport, |
| 183 | enum bfa_fcport_sm_event event); |
| 184 | static void bfa_fcport_sm_disabling(struct bfa_fcport_s *fcport, |
| 185 | enum bfa_fcport_sm_event event); |
| 186 | static void bfa_fcport_sm_disabling_qwait(struct bfa_fcport_s *fcport, |
| 187 | enum bfa_fcport_sm_event event); |
| 188 | static void bfa_fcport_sm_toggling_qwait(struct bfa_fcport_s *fcport, |
| 189 | enum bfa_fcport_sm_event event); |
| 190 | static void bfa_fcport_sm_disabled(struct bfa_fcport_s *fcport, |
| 191 | enum bfa_fcport_sm_event event); |
| 192 | static void bfa_fcport_sm_stopped(struct bfa_fcport_s *fcport, |
| 193 | enum bfa_fcport_sm_event event); |
| 194 | static void bfa_fcport_sm_iocdown(struct bfa_fcport_s *fcport, |
| 195 | enum bfa_fcport_sm_event event); |
| 196 | static void bfa_fcport_sm_iocfail(struct bfa_fcport_s *fcport, |
| 197 | enum bfa_fcport_sm_event event); |
| 198 | |
| 199 | static void bfa_fcport_ln_sm_dn(struct bfa_fcport_ln_s *ln, |
| 200 | enum bfa_fcport_ln_sm_event event); |
| 201 | static void bfa_fcport_ln_sm_dn_nf(struct bfa_fcport_ln_s *ln, |
| 202 | enum bfa_fcport_ln_sm_event event); |
| 203 | static void bfa_fcport_ln_sm_dn_up_nf(struct bfa_fcport_ln_s *ln, |
| 204 | enum bfa_fcport_ln_sm_event event); |
| 205 | static void bfa_fcport_ln_sm_up(struct bfa_fcport_ln_s *ln, |
| 206 | enum bfa_fcport_ln_sm_event event); |
| 207 | static void bfa_fcport_ln_sm_up_nf(struct bfa_fcport_ln_s *ln, |
| 208 | enum bfa_fcport_ln_sm_event event); |
| 209 | static void bfa_fcport_ln_sm_up_dn_nf(struct bfa_fcport_ln_s *ln, |
| 210 | enum bfa_fcport_ln_sm_event event); |
| 211 | static void bfa_fcport_ln_sm_up_dn_up_nf(struct bfa_fcport_ln_s *ln, |
| 212 | enum bfa_fcport_ln_sm_event event); |
| 213 | |
| 214 | static struct bfa_sm_table_s hal_port_sm_table[] = { |
| 215 | {BFA_SM(bfa_fcport_sm_uninit), BFA_PORT_ST_UNINIT}, |
| 216 | {BFA_SM(bfa_fcport_sm_enabling_qwait), BFA_PORT_ST_ENABLING_QWAIT}, |
| 217 | {BFA_SM(bfa_fcport_sm_enabling), BFA_PORT_ST_ENABLING}, |
| 218 | {BFA_SM(bfa_fcport_sm_linkdown), BFA_PORT_ST_LINKDOWN}, |
| 219 | {BFA_SM(bfa_fcport_sm_linkup), BFA_PORT_ST_LINKUP}, |
| 220 | {BFA_SM(bfa_fcport_sm_disabling_qwait), BFA_PORT_ST_DISABLING_QWAIT}, |
| 221 | {BFA_SM(bfa_fcport_sm_toggling_qwait), BFA_PORT_ST_TOGGLING_QWAIT}, |
| 222 | {BFA_SM(bfa_fcport_sm_disabling), BFA_PORT_ST_DISABLING}, |
| 223 | {BFA_SM(bfa_fcport_sm_disabled), BFA_PORT_ST_DISABLED}, |
| 224 | {BFA_SM(bfa_fcport_sm_stopped), BFA_PORT_ST_STOPPED}, |
| 225 | {BFA_SM(bfa_fcport_sm_iocdown), BFA_PORT_ST_IOCDOWN}, |
| 226 | {BFA_SM(bfa_fcport_sm_iocfail), BFA_PORT_ST_IOCDOWN}, |
| 227 | }; |
| 228 | |
| 229 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 230 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 231 | * forward declaration for RPORT related functions |
| 232 | */ |
| 233 | static struct bfa_rport_s *bfa_rport_alloc(struct bfa_rport_mod_s *rp_mod); |
| 234 | static void bfa_rport_free(struct bfa_rport_s *rport); |
| 235 | static bfa_boolean_t bfa_rport_send_fwcreate(struct bfa_rport_s *rp); |
| 236 | static bfa_boolean_t bfa_rport_send_fwdelete(struct bfa_rport_s *rp); |
| 237 | static bfa_boolean_t bfa_rport_send_fwspeed(struct bfa_rport_s *rp); |
| 238 | static void __bfa_cb_rport_online(void *cbarg, |
| 239 | bfa_boolean_t complete); |
| 240 | static void __bfa_cb_rport_offline(void *cbarg, |
| 241 | bfa_boolean_t complete); |
| 242 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 243 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 244 | * forward declaration for RPORT state machine |
| 245 | */ |
| 246 | static void bfa_rport_sm_uninit(struct bfa_rport_s *rp, |
| 247 | enum bfa_rport_event event); |
| 248 | static void bfa_rport_sm_created(struct bfa_rport_s *rp, |
| 249 | enum bfa_rport_event event); |
| 250 | static void bfa_rport_sm_fwcreate(struct bfa_rport_s *rp, |
| 251 | enum bfa_rport_event event); |
| 252 | static void bfa_rport_sm_online(struct bfa_rport_s *rp, |
| 253 | enum bfa_rport_event event); |
| 254 | static void bfa_rport_sm_fwdelete(struct bfa_rport_s *rp, |
| 255 | enum bfa_rport_event event); |
| 256 | static void bfa_rport_sm_offline(struct bfa_rport_s *rp, |
| 257 | enum bfa_rport_event event); |
| 258 | static void bfa_rport_sm_deleting(struct bfa_rport_s *rp, |
| 259 | enum bfa_rport_event event); |
| 260 | static void bfa_rport_sm_offline_pending(struct bfa_rport_s *rp, |
| 261 | enum bfa_rport_event event); |
| 262 | static void bfa_rport_sm_delete_pending(struct bfa_rport_s *rp, |
| 263 | enum bfa_rport_event event); |
| 264 | static void bfa_rport_sm_iocdisable(struct bfa_rport_s *rp, |
| 265 | enum bfa_rport_event event); |
| 266 | static void bfa_rport_sm_fwcreate_qfull(struct bfa_rport_s *rp, |
| 267 | enum bfa_rport_event event); |
| 268 | static void bfa_rport_sm_fwdelete_qfull(struct bfa_rport_s *rp, |
| 269 | enum bfa_rport_event event); |
| 270 | static void bfa_rport_sm_deleting_qfull(struct bfa_rport_s *rp, |
| 271 | enum bfa_rport_event event); |
| 272 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 273 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 274 | * PLOG related definitions |
| 275 | */ |
| 276 | static int |
| 277 | plkd_validate_logrec(struct bfa_plog_rec_s *pl_rec) |
| 278 | { |
| 279 | if ((pl_rec->log_type != BFA_PL_LOG_TYPE_INT) && |
| 280 | (pl_rec->log_type != BFA_PL_LOG_TYPE_STRING)) |
| 281 | return 1; |
| 282 | |
| 283 | if ((pl_rec->log_type != BFA_PL_LOG_TYPE_INT) && |
| 284 | (pl_rec->log_num_ints > BFA_PL_INT_LOG_SZ)) |
| 285 | return 1; |
| 286 | |
| 287 | return 0; |
| 288 | } |
| 289 | |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 290 | static u64 |
| 291 | bfa_get_log_time(void) |
| 292 | { |
| 293 | u64 system_time = 0; |
| 294 | struct timeval tv; |
| 295 | do_gettimeofday(&tv); |
| 296 | |
| 297 | /* We are interested in seconds only. */ |
| 298 | system_time = tv.tv_sec; |
| 299 | return system_time; |
| 300 | } |
| 301 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 302 | static void |
| 303 | bfa_plog_add(struct bfa_plog_s *plog, struct bfa_plog_rec_s *pl_rec) |
| 304 | { |
| 305 | u16 tail; |
| 306 | struct bfa_plog_rec_s *pl_recp; |
| 307 | |
| 308 | if (plog->plog_enabled == 0) |
| 309 | return; |
| 310 | |
| 311 | if (plkd_validate_logrec(pl_rec)) { |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 312 | WARN_ON(1); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 313 | return; |
| 314 | } |
| 315 | |
| 316 | tail = plog->tail; |
| 317 | |
| 318 | pl_recp = &(plog->plog_recs[tail]); |
| 319 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 320 | memcpy(pl_recp, pl_rec, sizeof(struct bfa_plog_rec_s)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 321 | |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 322 | pl_recp->tv = bfa_get_log_time(); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 323 | BFA_PL_LOG_REC_INCR(plog->tail); |
| 324 | |
| 325 | if (plog->head == plog->tail) |
| 326 | BFA_PL_LOG_REC_INCR(plog->head); |
| 327 | } |
| 328 | |
| 329 | void |
| 330 | bfa_plog_init(struct bfa_plog_s *plog) |
| 331 | { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 332 | memset((char *)plog, 0, sizeof(struct bfa_plog_s)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 333 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 334 | memcpy(plog->plog_sig, BFA_PL_SIG_STR, BFA_PL_SIG_LEN); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 335 | plog->head = plog->tail = 0; |
| 336 | plog->plog_enabled = 1; |
| 337 | } |
| 338 | |
| 339 | void |
| 340 | bfa_plog_str(struct bfa_plog_s *plog, enum bfa_plog_mid mid, |
| 341 | enum bfa_plog_eid event, |
| 342 | u16 misc, char *log_str) |
| 343 | { |
| 344 | struct bfa_plog_rec_s lp; |
| 345 | |
| 346 | if (plog->plog_enabled) { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 347 | memset(&lp, 0, sizeof(struct bfa_plog_rec_s)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 348 | lp.mid = mid; |
| 349 | lp.eid = event; |
| 350 | lp.log_type = BFA_PL_LOG_TYPE_STRING; |
| 351 | lp.misc = misc; |
| 352 | strncpy(lp.log_entry.string_log, log_str, |
| 353 | BFA_PL_STRING_LOG_SZ - 1); |
| 354 | lp.log_entry.string_log[BFA_PL_STRING_LOG_SZ - 1] = '\0'; |
| 355 | bfa_plog_add(plog, &lp); |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | void |
| 360 | bfa_plog_intarr(struct bfa_plog_s *plog, enum bfa_plog_mid mid, |
| 361 | enum bfa_plog_eid event, |
| 362 | u16 misc, u32 *intarr, u32 num_ints) |
| 363 | { |
| 364 | struct bfa_plog_rec_s lp; |
| 365 | u32 i; |
| 366 | |
| 367 | if (num_ints > BFA_PL_INT_LOG_SZ) |
| 368 | num_ints = BFA_PL_INT_LOG_SZ; |
| 369 | |
| 370 | if (plog->plog_enabled) { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 371 | memset(&lp, 0, sizeof(struct bfa_plog_rec_s)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 372 | lp.mid = mid; |
| 373 | lp.eid = event; |
| 374 | lp.log_type = BFA_PL_LOG_TYPE_INT; |
| 375 | lp.misc = misc; |
| 376 | |
| 377 | for (i = 0; i < num_ints; i++) |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 378 | lp.log_entry.int_log[i] = intarr[i]; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 379 | |
| 380 | lp.log_num_ints = (u8) num_ints; |
| 381 | |
| 382 | bfa_plog_add(plog, &lp); |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | void |
| 387 | bfa_plog_fchdr(struct bfa_plog_s *plog, enum bfa_plog_mid mid, |
| 388 | enum bfa_plog_eid event, |
| 389 | u16 misc, struct fchs_s *fchdr) |
| 390 | { |
| 391 | struct bfa_plog_rec_s lp; |
| 392 | u32 *tmp_int = (u32 *) fchdr; |
| 393 | u32 ints[BFA_PL_INT_LOG_SZ]; |
| 394 | |
| 395 | if (plog->plog_enabled) { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 396 | memset(&lp, 0, sizeof(struct bfa_plog_rec_s)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 397 | |
| 398 | ints[0] = tmp_int[0]; |
| 399 | ints[1] = tmp_int[1]; |
| 400 | ints[2] = tmp_int[4]; |
| 401 | |
| 402 | bfa_plog_intarr(plog, mid, event, misc, ints, 3); |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | void |
| 407 | bfa_plog_fchdr_and_pl(struct bfa_plog_s *plog, enum bfa_plog_mid mid, |
| 408 | enum bfa_plog_eid event, u16 misc, struct fchs_s *fchdr, |
| 409 | u32 pld_w0) |
| 410 | { |
| 411 | struct bfa_plog_rec_s lp; |
| 412 | u32 *tmp_int = (u32 *) fchdr; |
| 413 | u32 ints[BFA_PL_INT_LOG_SZ]; |
| 414 | |
| 415 | if (plog->plog_enabled) { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 416 | memset(&lp, 0, sizeof(struct bfa_plog_rec_s)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 417 | |
| 418 | ints[0] = tmp_int[0]; |
| 419 | ints[1] = tmp_int[1]; |
| 420 | ints[2] = tmp_int[4]; |
| 421 | ints[3] = pld_w0; |
| 422 | |
| 423 | bfa_plog_intarr(plog, mid, event, misc, ints, 4); |
| 424 | } |
| 425 | } |
| 426 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 427 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 428 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 429 | * fcxp_pvt BFA FCXP private functions |
| 430 | */ |
| 431 | |
| 432 | static void |
| 433 | claim_fcxp_req_rsp_mem(struct bfa_fcxp_mod_s *mod, struct bfa_meminfo_s *mi) |
| 434 | { |
| 435 | u8 *dm_kva = NULL; |
| 436 | u64 dm_pa; |
| 437 | u32 buf_pool_sz; |
| 438 | |
| 439 | dm_kva = bfa_meminfo_dma_virt(mi); |
| 440 | dm_pa = bfa_meminfo_dma_phys(mi); |
| 441 | |
| 442 | buf_pool_sz = mod->req_pld_sz * mod->num_fcxps; |
| 443 | |
| 444 | /* |
| 445 | * Initialize the fcxp req payload list |
| 446 | */ |
| 447 | mod->req_pld_list_kva = dm_kva; |
| 448 | mod->req_pld_list_pa = dm_pa; |
| 449 | dm_kva += buf_pool_sz; |
| 450 | dm_pa += buf_pool_sz; |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 451 | memset(mod->req_pld_list_kva, 0, buf_pool_sz); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 452 | |
| 453 | /* |
| 454 | * Initialize the fcxp rsp payload list |
| 455 | */ |
| 456 | buf_pool_sz = mod->rsp_pld_sz * mod->num_fcxps; |
| 457 | mod->rsp_pld_list_kva = dm_kva; |
| 458 | mod->rsp_pld_list_pa = dm_pa; |
| 459 | dm_kva += buf_pool_sz; |
| 460 | dm_pa += buf_pool_sz; |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 461 | memset(mod->rsp_pld_list_kva, 0, buf_pool_sz); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 462 | |
| 463 | bfa_meminfo_dma_virt(mi) = dm_kva; |
| 464 | bfa_meminfo_dma_phys(mi) = dm_pa; |
| 465 | } |
| 466 | |
| 467 | static void |
| 468 | claim_fcxps_mem(struct bfa_fcxp_mod_s *mod, struct bfa_meminfo_s *mi) |
| 469 | { |
| 470 | u16 i; |
| 471 | struct bfa_fcxp_s *fcxp; |
| 472 | |
| 473 | fcxp = (struct bfa_fcxp_s *) bfa_meminfo_kva(mi); |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 474 | memset(fcxp, 0, sizeof(struct bfa_fcxp_s) * mod->num_fcxps); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 475 | |
| 476 | INIT_LIST_HEAD(&mod->fcxp_free_q); |
| 477 | INIT_LIST_HEAD(&mod->fcxp_active_q); |
| 478 | |
| 479 | mod->fcxp_list = fcxp; |
| 480 | |
| 481 | for (i = 0; i < mod->num_fcxps; i++) { |
| 482 | fcxp->fcxp_mod = mod; |
| 483 | fcxp->fcxp_tag = i; |
| 484 | |
| 485 | list_add_tail(&fcxp->qe, &mod->fcxp_free_q); |
| 486 | bfa_reqq_winit(&fcxp->reqq_wqe, bfa_fcxp_qresume, fcxp); |
| 487 | fcxp->reqq_waiting = BFA_FALSE; |
| 488 | |
| 489 | fcxp = fcxp + 1; |
| 490 | } |
| 491 | |
| 492 | bfa_meminfo_kva(mi) = (void *)fcxp; |
| 493 | } |
| 494 | |
| 495 | static void |
| 496 | bfa_fcxp_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *ndm_len, |
| 497 | u32 *dm_len) |
| 498 | { |
| 499 | u16 num_fcxp_reqs = cfg->fwcfg.num_fcxp_reqs; |
| 500 | |
| 501 | if (num_fcxp_reqs == 0) |
| 502 | return; |
| 503 | |
| 504 | /* |
| 505 | * Account for req/rsp payload |
| 506 | */ |
| 507 | *dm_len += BFA_FCXP_MAX_IBUF_SZ * num_fcxp_reqs; |
| 508 | if (cfg->drvcfg.min_cfg) |
| 509 | *dm_len += BFA_FCXP_MAX_IBUF_SZ * num_fcxp_reqs; |
| 510 | else |
| 511 | *dm_len += BFA_FCXP_MAX_LBUF_SZ * num_fcxp_reqs; |
| 512 | |
| 513 | /* |
| 514 | * Account for fcxp structs |
| 515 | */ |
| 516 | *ndm_len += sizeof(struct bfa_fcxp_s) * num_fcxp_reqs; |
| 517 | } |
| 518 | |
| 519 | static void |
| 520 | bfa_fcxp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg, |
| 521 | struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev) |
| 522 | { |
| 523 | struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa); |
| 524 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 525 | memset(mod, 0, sizeof(struct bfa_fcxp_mod_s)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 526 | mod->bfa = bfa; |
| 527 | mod->num_fcxps = cfg->fwcfg.num_fcxp_reqs; |
| 528 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 529 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 530 | * Initialize FCXP request and response payload sizes. |
| 531 | */ |
| 532 | mod->req_pld_sz = mod->rsp_pld_sz = BFA_FCXP_MAX_IBUF_SZ; |
| 533 | if (!cfg->drvcfg.min_cfg) |
| 534 | mod->rsp_pld_sz = BFA_FCXP_MAX_LBUF_SZ; |
| 535 | |
| 536 | INIT_LIST_HEAD(&mod->wait_q); |
| 537 | |
| 538 | claim_fcxp_req_rsp_mem(mod, meminfo); |
| 539 | claim_fcxps_mem(mod, meminfo); |
| 540 | } |
| 541 | |
| 542 | static void |
| 543 | bfa_fcxp_detach(struct bfa_s *bfa) |
| 544 | { |
| 545 | } |
| 546 | |
| 547 | static void |
| 548 | bfa_fcxp_start(struct bfa_s *bfa) |
| 549 | { |
| 550 | } |
| 551 | |
| 552 | static void |
| 553 | bfa_fcxp_stop(struct bfa_s *bfa) |
| 554 | { |
| 555 | } |
| 556 | |
| 557 | static void |
| 558 | bfa_fcxp_iocdisable(struct bfa_s *bfa) |
| 559 | { |
| 560 | struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa); |
| 561 | struct bfa_fcxp_s *fcxp; |
| 562 | struct list_head *qe, *qen; |
| 563 | |
| 564 | list_for_each_safe(qe, qen, &mod->fcxp_active_q) { |
| 565 | fcxp = (struct bfa_fcxp_s *) qe; |
| 566 | if (fcxp->caller == NULL) { |
| 567 | fcxp->send_cbfn(fcxp->caller, fcxp, fcxp->send_cbarg, |
| 568 | BFA_STATUS_IOC_FAILURE, 0, 0, NULL); |
| 569 | bfa_fcxp_free(fcxp); |
| 570 | } else { |
| 571 | fcxp->rsp_status = BFA_STATUS_IOC_FAILURE; |
| 572 | bfa_cb_queue(bfa, &fcxp->hcb_qe, |
| 573 | __bfa_fcxp_send_cbfn, fcxp); |
| 574 | } |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | static struct bfa_fcxp_s * |
| 579 | bfa_fcxp_get(struct bfa_fcxp_mod_s *fm) |
| 580 | { |
| 581 | struct bfa_fcxp_s *fcxp; |
| 582 | |
| 583 | bfa_q_deq(&fm->fcxp_free_q, &fcxp); |
| 584 | |
| 585 | if (fcxp) |
| 586 | list_add_tail(&fcxp->qe, &fm->fcxp_active_q); |
| 587 | |
| 588 | return fcxp; |
| 589 | } |
| 590 | |
| 591 | static void |
| 592 | bfa_fcxp_init_reqrsp(struct bfa_fcxp_s *fcxp, |
| 593 | struct bfa_s *bfa, |
| 594 | u8 *use_ibuf, |
| 595 | u32 *nr_sgles, |
| 596 | bfa_fcxp_get_sgaddr_t *r_sga_cbfn, |
| 597 | bfa_fcxp_get_sglen_t *r_sglen_cbfn, |
| 598 | struct list_head *r_sgpg_q, |
| 599 | int n_sgles, |
| 600 | bfa_fcxp_get_sgaddr_t sga_cbfn, |
| 601 | bfa_fcxp_get_sglen_t sglen_cbfn) |
| 602 | { |
| 603 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 604 | WARN_ON(bfa == NULL); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 605 | |
| 606 | bfa_trc(bfa, fcxp->fcxp_tag); |
| 607 | |
| 608 | if (n_sgles == 0) { |
| 609 | *use_ibuf = 1; |
| 610 | } else { |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 611 | WARN_ON(*sga_cbfn == NULL); |
| 612 | WARN_ON(*sglen_cbfn == NULL); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 613 | |
| 614 | *use_ibuf = 0; |
| 615 | *r_sga_cbfn = sga_cbfn; |
| 616 | *r_sglen_cbfn = sglen_cbfn; |
| 617 | |
| 618 | *nr_sgles = n_sgles; |
| 619 | |
| 620 | /* |
| 621 | * alloc required sgpgs |
| 622 | */ |
| 623 | if (n_sgles > BFI_SGE_INLINE) |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 624 | WARN_ON(1); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | } |
| 628 | |
| 629 | static void |
| 630 | bfa_fcxp_init(struct bfa_fcxp_s *fcxp, |
| 631 | void *caller, struct bfa_s *bfa, int nreq_sgles, |
| 632 | int nrsp_sgles, bfa_fcxp_get_sgaddr_t req_sga_cbfn, |
| 633 | bfa_fcxp_get_sglen_t req_sglen_cbfn, |
| 634 | bfa_fcxp_get_sgaddr_t rsp_sga_cbfn, |
| 635 | bfa_fcxp_get_sglen_t rsp_sglen_cbfn) |
| 636 | { |
| 637 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 638 | WARN_ON(bfa == NULL); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 639 | |
| 640 | bfa_trc(bfa, fcxp->fcxp_tag); |
| 641 | |
| 642 | fcxp->caller = caller; |
| 643 | |
| 644 | bfa_fcxp_init_reqrsp(fcxp, bfa, |
| 645 | &fcxp->use_ireqbuf, &fcxp->nreq_sgles, &fcxp->req_sga_cbfn, |
| 646 | &fcxp->req_sglen_cbfn, &fcxp->req_sgpg_q, |
| 647 | nreq_sgles, req_sga_cbfn, req_sglen_cbfn); |
| 648 | |
| 649 | bfa_fcxp_init_reqrsp(fcxp, bfa, |
| 650 | &fcxp->use_irspbuf, &fcxp->nrsp_sgles, &fcxp->rsp_sga_cbfn, |
| 651 | &fcxp->rsp_sglen_cbfn, &fcxp->rsp_sgpg_q, |
| 652 | nrsp_sgles, rsp_sga_cbfn, rsp_sglen_cbfn); |
| 653 | |
| 654 | } |
| 655 | |
| 656 | static void |
| 657 | bfa_fcxp_put(struct bfa_fcxp_s *fcxp) |
| 658 | { |
| 659 | struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod; |
| 660 | struct bfa_fcxp_wqe_s *wqe; |
| 661 | |
| 662 | bfa_q_deq(&mod->wait_q, &wqe); |
| 663 | if (wqe) { |
| 664 | bfa_trc(mod->bfa, fcxp->fcxp_tag); |
| 665 | |
| 666 | bfa_fcxp_init(fcxp, wqe->caller, wqe->bfa, wqe->nreq_sgles, |
| 667 | wqe->nrsp_sgles, wqe->req_sga_cbfn, |
| 668 | wqe->req_sglen_cbfn, wqe->rsp_sga_cbfn, |
| 669 | wqe->rsp_sglen_cbfn); |
| 670 | |
| 671 | wqe->alloc_cbfn(wqe->alloc_cbarg, fcxp); |
| 672 | return; |
| 673 | } |
| 674 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 675 | WARN_ON(!bfa_q_is_on_q(&mod->fcxp_active_q, fcxp)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 676 | list_del(&fcxp->qe); |
| 677 | list_add_tail(&fcxp->qe, &mod->fcxp_free_q); |
| 678 | } |
| 679 | |
| 680 | static void |
| 681 | bfa_fcxp_null_comp(void *bfad_fcxp, struct bfa_fcxp_s *fcxp, void *cbarg, |
| 682 | bfa_status_t req_status, u32 rsp_len, |
| 683 | u32 resid_len, struct fchs_s *rsp_fchs) |
| 684 | { |
| 685 | /* discarded fcxp completion */ |
| 686 | } |
| 687 | |
| 688 | static void |
| 689 | __bfa_fcxp_send_cbfn(void *cbarg, bfa_boolean_t complete) |
| 690 | { |
| 691 | struct bfa_fcxp_s *fcxp = cbarg; |
| 692 | |
| 693 | if (complete) { |
| 694 | fcxp->send_cbfn(fcxp->caller, fcxp, fcxp->send_cbarg, |
| 695 | fcxp->rsp_status, fcxp->rsp_len, |
| 696 | fcxp->residue_len, &fcxp->rsp_fchs); |
| 697 | } else { |
| 698 | bfa_fcxp_free(fcxp); |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | static void |
| 703 | hal_fcxp_send_comp(struct bfa_s *bfa, struct bfi_fcxp_send_rsp_s *fcxp_rsp) |
| 704 | { |
| 705 | struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa); |
| 706 | struct bfa_fcxp_s *fcxp; |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 707 | u16 fcxp_tag = be16_to_cpu(fcxp_rsp->fcxp_tag); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 708 | |
| 709 | bfa_trc(bfa, fcxp_tag); |
| 710 | |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 711 | fcxp_rsp->rsp_len = be32_to_cpu(fcxp_rsp->rsp_len); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 712 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 713 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 714 | * @todo f/w should not set residue to non-0 when everything |
| 715 | * is received. |
| 716 | */ |
| 717 | if (fcxp_rsp->req_status == BFA_STATUS_OK) |
| 718 | fcxp_rsp->residue_len = 0; |
| 719 | else |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 720 | fcxp_rsp->residue_len = be32_to_cpu(fcxp_rsp->residue_len); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 721 | |
| 722 | fcxp = BFA_FCXP_FROM_TAG(mod, fcxp_tag); |
| 723 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 724 | WARN_ON(fcxp->send_cbfn == NULL); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 725 | |
| 726 | hal_fcxp_rx_plog(mod->bfa, fcxp, fcxp_rsp); |
| 727 | |
| 728 | if (fcxp->send_cbfn != NULL) { |
| 729 | bfa_trc(mod->bfa, (NULL == fcxp->caller)); |
| 730 | if (fcxp->caller == NULL) { |
| 731 | fcxp->send_cbfn(fcxp->caller, fcxp, fcxp->send_cbarg, |
| 732 | fcxp_rsp->req_status, fcxp_rsp->rsp_len, |
| 733 | fcxp_rsp->residue_len, &fcxp_rsp->fchs); |
| 734 | /* |
| 735 | * fcxp automatically freed on return from the callback |
| 736 | */ |
| 737 | bfa_fcxp_free(fcxp); |
| 738 | } else { |
| 739 | fcxp->rsp_status = fcxp_rsp->req_status; |
| 740 | fcxp->rsp_len = fcxp_rsp->rsp_len; |
| 741 | fcxp->residue_len = fcxp_rsp->residue_len; |
| 742 | fcxp->rsp_fchs = fcxp_rsp->fchs; |
| 743 | |
| 744 | bfa_cb_queue(bfa, &fcxp->hcb_qe, |
| 745 | __bfa_fcxp_send_cbfn, fcxp); |
| 746 | } |
| 747 | } else { |
| 748 | bfa_trc(bfa, (NULL == fcxp->send_cbfn)); |
| 749 | } |
| 750 | } |
| 751 | |
| 752 | static void |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 753 | hal_fcxp_tx_plog(struct bfa_s *bfa, u32 reqlen, struct bfa_fcxp_s *fcxp, |
| 754 | struct fchs_s *fchs) |
| 755 | { |
| 756 | /* |
| 757 | * TODO: TX ox_id |
| 758 | */ |
| 759 | if (reqlen > 0) { |
| 760 | if (fcxp->use_ireqbuf) { |
| 761 | u32 pld_w0 = |
| 762 | *((u32 *) BFA_FCXP_REQ_PLD(fcxp)); |
| 763 | |
| 764 | bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_FCXP, |
| 765 | BFA_PL_EID_TX, |
| 766 | reqlen + sizeof(struct fchs_s), fchs, |
| 767 | pld_w0); |
| 768 | } else { |
| 769 | bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP, |
| 770 | BFA_PL_EID_TX, |
| 771 | reqlen + sizeof(struct fchs_s), |
| 772 | fchs); |
| 773 | } |
| 774 | } else { |
| 775 | bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP, BFA_PL_EID_TX, |
| 776 | reqlen + sizeof(struct fchs_s), fchs); |
| 777 | } |
| 778 | } |
| 779 | |
| 780 | static void |
| 781 | hal_fcxp_rx_plog(struct bfa_s *bfa, struct bfa_fcxp_s *fcxp, |
| 782 | struct bfi_fcxp_send_rsp_s *fcxp_rsp) |
| 783 | { |
| 784 | if (fcxp_rsp->rsp_len > 0) { |
| 785 | if (fcxp->use_irspbuf) { |
| 786 | u32 pld_w0 = |
| 787 | *((u32 *) BFA_FCXP_RSP_PLD(fcxp)); |
| 788 | |
| 789 | bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_FCXP, |
| 790 | BFA_PL_EID_RX, |
| 791 | (u16) fcxp_rsp->rsp_len, |
| 792 | &fcxp_rsp->fchs, pld_w0); |
| 793 | } else { |
| 794 | bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP, |
| 795 | BFA_PL_EID_RX, |
| 796 | (u16) fcxp_rsp->rsp_len, |
| 797 | &fcxp_rsp->fchs); |
| 798 | } |
| 799 | } else { |
| 800 | bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_FCXP, BFA_PL_EID_RX, |
| 801 | (u16) fcxp_rsp->rsp_len, &fcxp_rsp->fchs); |
| 802 | } |
| 803 | } |
| 804 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 805 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 806 | * Handler to resume sending fcxp when space in available in cpe queue. |
| 807 | */ |
| 808 | static void |
| 809 | bfa_fcxp_qresume(void *cbarg) |
| 810 | { |
| 811 | struct bfa_fcxp_s *fcxp = cbarg; |
| 812 | struct bfa_s *bfa = fcxp->fcxp_mod->bfa; |
| 813 | struct bfi_fcxp_send_req_s *send_req; |
| 814 | |
| 815 | fcxp->reqq_waiting = BFA_FALSE; |
| 816 | send_req = bfa_reqq_next(bfa, BFA_REQQ_FCXP); |
| 817 | bfa_fcxp_queue(fcxp, send_req); |
| 818 | } |
| 819 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 820 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 821 | * Queue fcxp send request to foimrware. |
| 822 | */ |
| 823 | static void |
| 824 | bfa_fcxp_queue(struct bfa_fcxp_s *fcxp, struct bfi_fcxp_send_req_s *send_req) |
| 825 | { |
| 826 | struct bfa_s *bfa = fcxp->fcxp_mod->bfa; |
| 827 | struct bfa_fcxp_req_info_s *reqi = &fcxp->req_info; |
| 828 | struct bfa_fcxp_rsp_info_s *rspi = &fcxp->rsp_info; |
| 829 | struct bfa_rport_s *rport = reqi->bfa_rport; |
| 830 | |
| 831 | bfi_h2i_set(send_req->mh, BFI_MC_FCXP, BFI_FCXP_H2I_SEND_REQ, |
| 832 | bfa_lpuid(bfa)); |
| 833 | |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 834 | send_req->fcxp_tag = cpu_to_be16(fcxp->fcxp_tag); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 835 | if (rport) { |
| 836 | send_req->rport_fw_hndl = rport->fw_handle; |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 837 | send_req->max_frmsz = cpu_to_be16(rport->rport_info.max_frmsz); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 838 | if (send_req->max_frmsz == 0) |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 839 | send_req->max_frmsz = cpu_to_be16(FC_MAX_PDUSZ); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 840 | } else { |
| 841 | send_req->rport_fw_hndl = 0; |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 842 | send_req->max_frmsz = cpu_to_be16(FC_MAX_PDUSZ); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 843 | } |
| 844 | |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 845 | send_req->vf_id = cpu_to_be16(reqi->vf_id); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 846 | send_req->lp_tag = reqi->lp_tag; |
| 847 | send_req->class = reqi->class; |
| 848 | send_req->rsp_timeout = rspi->rsp_timeout; |
| 849 | send_req->cts = reqi->cts; |
| 850 | send_req->fchs = reqi->fchs; |
| 851 | |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 852 | send_req->req_len = cpu_to_be32(reqi->req_tot_len); |
| 853 | send_req->rsp_maxlen = cpu_to_be32(rspi->rsp_maxlen); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 854 | |
| 855 | /* |
| 856 | * setup req sgles |
| 857 | */ |
| 858 | if (fcxp->use_ireqbuf == 1) { |
Krishna Gudipati | 85ce928 | 2011-06-13 15:39:36 -0700 | [diff] [blame] | 859 | bfa_alen_set(&send_req->req_alen, reqi->req_tot_len, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 860 | BFA_FCXP_REQ_PLD_PA(fcxp)); |
| 861 | } else { |
| 862 | if (fcxp->nreq_sgles > 0) { |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 863 | WARN_ON(fcxp->nreq_sgles != 1); |
Krishna Gudipati | 85ce928 | 2011-06-13 15:39:36 -0700 | [diff] [blame] | 864 | bfa_alen_set(&send_req->req_alen, reqi->req_tot_len, |
| 865 | fcxp->req_sga_cbfn(fcxp->caller, 0)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 866 | } else { |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 867 | WARN_ON(reqi->req_tot_len != 0); |
Krishna Gudipati | 85ce928 | 2011-06-13 15:39:36 -0700 | [diff] [blame] | 868 | bfa_alen_set(&send_req->rsp_alen, 0, 0); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 869 | } |
| 870 | } |
| 871 | |
| 872 | /* |
| 873 | * setup rsp sgles |
| 874 | */ |
| 875 | if (fcxp->use_irspbuf == 1) { |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 876 | WARN_ON(rspi->rsp_maxlen > BFA_FCXP_MAX_LBUF_SZ); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 877 | |
Krishna Gudipati | 85ce928 | 2011-06-13 15:39:36 -0700 | [diff] [blame] | 878 | bfa_alen_set(&send_req->rsp_alen, rspi->rsp_maxlen, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 879 | BFA_FCXP_RSP_PLD_PA(fcxp)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 880 | } else { |
| 881 | if (fcxp->nrsp_sgles > 0) { |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 882 | WARN_ON(fcxp->nrsp_sgles != 1); |
Krishna Gudipati | 85ce928 | 2011-06-13 15:39:36 -0700 | [diff] [blame] | 883 | bfa_alen_set(&send_req->rsp_alen, rspi->rsp_maxlen, |
| 884 | fcxp->rsp_sga_cbfn(fcxp->caller, 0)); |
| 885 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 886 | } else { |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 887 | WARN_ON(rspi->rsp_maxlen != 0); |
Krishna Gudipati | 85ce928 | 2011-06-13 15:39:36 -0700 | [diff] [blame] | 888 | bfa_alen_set(&send_req->rsp_alen, 0, 0); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 889 | } |
| 890 | } |
| 891 | |
| 892 | hal_fcxp_tx_plog(bfa, reqi->req_tot_len, fcxp, &reqi->fchs); |
| 893 | |
| 894 | bfa_reqq_produce(bfa, BFA_REQQ_FCXP); |
| 895 | |
| 896 | bfa_trc(bfa, bfa_reqq_pi(bfa, BFA_REQQ_FCXP)); |
| 897 | bfa_trc(bfa, bfa_reqq_ci(bfa, BFA_REQQ_FCXP)); |
| 898 | } |
| 899 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 900 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 901 | * Allocate an FCXP instance to send a response or to send a request |
| 902 | * that has a response. Request/response buffers are allocated by caller. |
| 903 | * |
| 904 | * @param[in] bfa BFA bfa instance |
| 905 | * @param[in] nreq_sgles Number of SG elements required for request |
| 906 | * buffer. 0, if fcxp internal buffers are used. |
| 907 | * Use bfa_fcxp_get_reqbuf() to get the |
| 908 | * internal req buffer. |
| 909 | * @param[in] req_sgles SG elements describing request buffer. Will be |
| 910 | * copied in by BFA and hence can be freed on |
| 911 | * return from this function. |
| 912 | * @param[in] get_req_sga function ptr to be called to get a request SG |
| 913 | * Address (given the sge index). |
| 914 | * @param[in] get_req_sglen function ptr to be called to get a request SG |
| 915 | * len (given the sge index). |
| 916 | * @param[in] get_rsp_sga function ptr to be called to get a response SG |
| 917 | * Address (given the sge index). |
| 918 | * @param[in] get_rsp_sglen function ptr to be called to get a response SG |
| 919 | * len (given the sge index). |
| 920 | * |
| 921 | * @return FCXP instance. NULL on failure. |
| 922 | */ |
| 923 | struct bfa_fcxp_s * |
| 924 | bfa_fcxp_alloc(void *caller, struct bfa_s *bfa, int nreq_sgles, |
| 925 | int nrsp_sgles, bfa_fcxp_get_sgaddr_t req_sga_cbfn, |
| 926 | bfa_fcxp_get_sglen_t req_sglen_cbfn, |
| 927 | bfa_fcxp_get_sgaddr_t rsp_sga_cbfn, |
| 928 | bfa_fcxp_get_sglen_t rsp_sglen_cbfn) |
| 929 | { |
| 930 | struct bfa_fcxp_s *fcxp = NULL; |
| 931 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 932 | WARN_ON(bfa == NULL); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 933 | |
| 934 | fcxp = bfa_fcxp_get(BFA_FCXP_MOD(bfa)); |
| 935 | if (fcxp == NULL) |
| 936 | return NULL; |
| 937 | |
| 938 | bfa_trc(bfa, fcxp->fcxp_tag); |
| 939 | |
| 940 | bfa_fcxp_init(fcxp, caller, bfa, nreq_sgles, nrsp_sgles, req_sga_cbfn, |
| 941 | req_sglen_cbfn, rsp_sga_cbfn, rsp_sglen_cbfn); |
| 942 | |
| 943 | return fcxp; |
| 944 | } |
| 945 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 946 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 947 | * Get the internal request buffer pointer |
| 948 | * |
| 949 | * @param[in] fcxp BFA fcxp pointer |
| 950 | * |
| 951 | * @return pointer to the internal request buffer |
| 952 | */ |
| 953 | void * |
| 954 | bfa_fcxp_get_reqbuf(struct bfa_fcxp_s *fcxp) |
| 955 | { |
| 956 | struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod; |
| 957 | void *reqbuf; |
| 958 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 959 | WARN_ON(fcxp->use_ireqbuf != 1); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 960 | reqbuf = ((u8 *)mod->req_pld_list_kva) + |
| 961 | fcxp->fcxp_tag * mod->req_pld_sz; |
| 962 | return reqbuf; |
| 963 | } |
| 964 | |
| 965 | u32 |
| 966 | bfa_fcxp_get_reqbufsz(struct bfa_fcxp_s *fcxp) |
| 967 | { |
| 968 | struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod; |
| 969 | |
| 970 | return mod->req_pld_sz; |
| 971 | } |
| 972 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 973 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 974 | * Get the internal response buffer pointer |
| 975 | * |
| 976 | * @param[in] fcxp BFA fcxp pointer |
| 977 | * |
| 978 | * @return pointer to the internal request buffer |
| 979 | */ |
| 980 | void * |
| 981 | bfa_fcxp_get_rspbuf(struct bfa_fcxp_s *fcxp) |
| 982 | { |
| 983 | struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod; |
| 984 | void *rspbuf; |
| 985 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 986 | WARN_ON(fcxp->use_irspbuf != 1); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 987 | |
| 988 | rspbuf = ((u8 *)mod->rsp_pld_list_kva) + |
| 989 | fcxp->fcxp_tag * mod->rsp_pld_sz; |
| 990 | return rspbuf; |
| 991 | } |
| 992 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 993 | /* |
Maggie Zhang | da99dcc | 2010-12-09 19:13:20 -0800 | [diff] [blame] | 994 | * Free the BFA FCXP |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 995 | * |
| 996 | * @param[in] fcxp BFA fcxp pointer |
| 997 | * |
| 998 | * @return void |
| 999 | */ |
| 1000 | void |
| 1001 | bfa_fcxp_free(struct bfa_fcxp_s *fcxp) |
| 1002 | { |
| 1003 | struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod; |
| 1004 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 1005 | WARN_ON(fcxp == NULL); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1006 | bfa_trc(mod->bfa, fcxp->fcxp_tag); |
| 1007 | bfa_fcxp_put(fcxp); |
| 1008 | } |
| 1009 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1010 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1011 | * Send a FCXP request |
| 1012 | * |
| 1013 | * @param[in] fcxp BFA fcxp pointer |
| 1014 | * @param[in] rport BFA rport pointer. Could be left NULL for WKA rports |
| 1015 | * @param[in] vf_id virtual Fabric ID |
| 1016 | * @param[in] lp_tag lport tag |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1017 | * @param[in] cts use Continuous sequence |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1018 | * @param[in] cos fc Class of Service |
| 1019 | * @param[in] reqlen request length, does not include FCHS length |
| 1020 | * @param[in] fchs fc Header Pointer. The header content will be copied |
| 1021 | * in by BFA. |
| 1022 | * |
| 1023 | * @param[in] cbfn call back function to be called on receiving |
| 1024 | * the response |
| 1025 | * @param[in] cbarg arg for cbfn |
| 1026 | * @param[in] rsp_timeout |
| 1027 | * response timeout |
| 1028 | * |
| 1029 | * @return bfa_status_t |
| 1030 | */ |
| 1031 | void |
| 1032 | bfa_fcxp_send(struct bfa_fcxp_s *fcxp, struct bfa_rport_s *rport, |
| 1033 | u16 vf_id, u8 lp_tag, bfa_boolean_t cts, enum fc_cos cos, |
| 1034 | u32 reqlen, struct fchs_s *fchs, bfa_cb_fcxp_send_t cbfn, |
| 1035 | void *cbarg, u32 rsp_maxlen, u8 rsp_timeout) |
| 1036 | { |
| 1037 | struct bfa_s *bfa = fcxp->fcxp_mod->bfa; |
| 1038 | struct bfa_fcxp_req_info_s *reqi = &fcxp->req_info; |
| 1039 | struct bfa_fcxp_rsp_info_s *rspi = &fcxp->rsp_info; |
| 1040 | struct bfi_fcxp_send_req_s *send_req; |
| 1041 | |
| 1042 | bfa_trc(bfa, fcxp->fcxp_tag); |
| 1043 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1044 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1045 | * setup request/response info |
| 1046 | */ |
| 1047 | reqi->bfa_rport = rport; |
| 1048 | reqi->vf_id = vf_id; |
| 1049 | reqi->lp_tag = lp_tag; |
| 1050 | reqi->class = cos; |
| 1051 | rspi->rsp_timeout = rsp_timeout; |
| 1052 | reqi->cts = cts; |
| 1053 | reqi->fchs = *fchs; |
| 1054 | reqi->req_tot_len = reqlen; |
| 1055 | rspi->rsp_maxlen = rsp_maxlen; |
| 1056 | fcxp->send_cbfn = cbfn ? cbfn : bfa_fcxp_null_comp; |
| 1057 | fcxp->send_cbarg = cbarg; |
| 1058 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1059 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1060 | * If no room in CPE queue, wait for space in request queue |
| 1061 | */ |
| 1062 | send_req = bfa_reqq_next(bfa, BFA_REQQ_FCXP); |
| 1063 | if (!send_req) { |
| 1064 | bfa_trc(bfa, fcxp->fcxp_tag); |
| 1065 | fcxp->reqq_waiting = BFA_TRUE; |
| 1066 | bfa_reqq_wait(bfa, BFA_REQQ_FCXP, &fcxp->reqq_wqe); |
| 1067 | return; |
| 1068 | } |
| 1069 | |
| 1070 | bfa_fcxp_queue(fcxp, send_req); |
| 1071 | } |
| 1072 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1073 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1074 | * Abort a BFA FCXP |
| 1075 | * |
| 1076 | * @param[in] fcxp BFA fcxp pointer |
| 1077 | * |
| 1078 | * @return void |
| 1079 | */ |
| 1080 | bfa_status_t |
| 1081 | bfa_fcxp_abort(struct bfa_fcxp_s *fcxp) |
| 1082 | { |
| 1083 | bfa_trc(fcxp->fcxp_mod->bfa, fcxp->fcxp_tag); |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 1084 | WARN_ON(1); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1085 | return BFA_STATUS_OK; |
| 1086 | } |
| 1087 | |
| 1088 | void |
| 1089 | bfa_fcxp_alloc_wait(struct bfa_s *bfa, struct bfa_fcxp_wqe_s *wqe, |
| 1090 | bfa_fcxp_alloc_cbfn_t alloc_cbfn, void *alloc_cbarg, |
| 1091 | void *caller, int nreq_sgles, |
| 1092 | int nrsp_sgles, bfa_fcxp_get_sgaddr_t req_sga_cbfn, |
| 1093 | bfa_fcxp_get_sglen_t req_sglen_cbfn, |
| 1094 | bfa_fcxp_get_sgaddr_t rsp_sga_cbfn, |
| 1095 | bfa_fcxp_get_sglen_t rsp_sglen_cbfn) |
| 1096 | { |
| 1097 | struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa); |
| 1098 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 1099 | WARN_ON(!list_empty(&mod->fcxp_free_q)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1100 | |
| 1101 | wqe->alloc_cbfn = alloc_cbfn; |
| 1102 | wqe->alloc_cbarg = alloc_cbarg; |
| 1103 | wqe->caller = caller; |
| 1104 | wqe->bfa = bfa; |
| 1105 | wqe->nreq_sgles = nreq_sgles; |
| 1106 | wqe->nrsp_sgles = nrsp_sgles; |
| 1107 | wqe->req_sga_cbfn = req_sga_cbfn; |
| 1108 | wqe->req_sglen_cbfn = req_sglen_cbfn; |
| 1109 | wqe->rsp_sga_cbfn = rsp_sga_cbfn; |
| 1110 | wqe->rsp_sglen_cbfn = rsp_sglen_cbfn; |
| 1111 | |
| 1112 | list_add_tail(&wqe->qe, &mod->wait_q); |
| 1113 | } |
| 1114 | |
| 1115 | void |
| 1116 | bfa_fcxp_walloc_cancel(struct bfa_s *bfa, struct bfa_fcxp_wqe_s *wqe) |
| 1117 | { |
| 1118 | struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa); |
| 1119 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 1120 | WARN_ON(!bfa_q_is_on_q(&mod->wait_q, wqe)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1121 | list_del(&wqe->qe); |
| 1122 | } |
| 1123 | |
| 1124 | void |
| 1125 | bfa_fcxp_discard(struct bfa_fcxp_s *fcxp) |
| 1126 | { |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1127 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1128 | * If waiting for room in request queue, cancel reqq wait |
| 1129 | * and free fcxp. |
| 1130 | */ |
| 1131 | if (fcxp->reqq_waiting) { |
| 1132 | fcxp->reqq_waiting = BFA_FALSE; |
| 1133 | bfa_reqq_wcancel(&fcxp->reqq_wqe); |
| 1134 | bfa_fcxp_free(fcxp); |
| 1135 | return; |
| 1136 | } |
| 1137 | |
| 1138 | fcxp->send_cbfn = bfa_fcxp_null_comp; |
| 1139 | } |
| 1140 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1141 | void |
| 1142 | bfa_fcxp_isr(struct bfa_s *bfa, struct bfi_msg_s *msg) |
| 1143 | { |
| 1144 | switch (msg->mhdr.msg_id) { |
| 1145 | case BFI_FCXP_I2H_SEND_RSP: |
| 1146 | hal_fcxp_send_comp(bfa, (struct bfi_fcxp_send_rsp_s *) msg); |
| 1147 | break; |
| 1148 | |
| 1149 | default: |
| 1150 | bfa_trc(bfa, msg->mhdr.msg_id); |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 1151 | WARN_ON(1); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1152 | } |
| 1153 | } |
| 1154 | |
| 1155 | u32 |
| 1156 | bfa_fcxp_get_maxrsp(struct bfa_s *bfa) |
| 1157 | { |
| 1158 | struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa); |
| 1159 | |
| 1160 | return mod->rsp_pld_sz; |
| 1161 | } |
| 1162 | |
| 1163 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1164 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1165 | * BFA LPS state machine functions |
| 1166 | */ |
| 1167 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1168 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1169 | * Init state -- no login |
| 1170 | */ |
| 1171 | static void |
| 1172 | bfa_lps_sm_init(struct bfa_lps_s *lps, enum bfa_lps_event event) |
| 1173 | { |
| 1174 | bfa_trc(lps->bfa, lps->lp_tag); |
| 1175 | bfa_trc(lps->bfa, event); |
| 1176 | |
| 1177 | switch (event) { |
| 1178 | case BFA_LPS_SM_LOGIN: |
| 1179 | if (bfa_reqq_full(lps->bfa, lps->reqq)) { |
| 1180 | bfa_sm_set_state(lps, bfa_lps_sm_loginwait); |
| 1181 | bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe); |
| 1182 | } else { |
| 1183 | bfa_sm_set_state(lps, bfa_lps_sm_login); |
| 1184 | bfa_lps_send_login(lps); |
| 1185 | } |
| 1186 | |
| 1187 | if (lps->fdisc) |
| 1188 | bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS, |
| 1189 | BFA_PL_EID_LOGIN, 0, "FDISC Request"); |
| 1190 | else |
| 1191 | bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS, |
| 1192 | BFA_PL_EID_LOGIN, 0, "FLOGI Request"); |
| 1193 | break; |
| 1194 | |
| 1195 | case BFA_LPS_SM_LOGOUT: |
| 1196 | bfa_lps_logout_comp(lps); |
| 1197 | break; |
| 1198 | |
| 1199 | case BFA_LPS_SM_DELETE: |
| 1200 | bfa_lps_free(lps); |
| 1201 | break; |
| 1202 | |
| 1203 | case BFA_LPS_SM_RX_CVL: |
| 1204 | case BFA_LPS_SM_OFFLINE: |
| 1205 | break; |
| 1206 | |
| 1207 | case BFA_LPS_SM_FWRSP: |
| 1208 | /* |
| 1209 | * Could happen when fabric detects loopback and discards |
| 1210 | * the lps request. Fw will eventually sent out the timeout |
| 1211 | * Just ignore |
| 1212 | */ |
| 1213 | break; |
| 1214 | |
| 1215 | default: |
| 1216 | bfa_sm_fault(lps->bfa, event); |
| 1217 | } |
| 1218 | } |
| 1219 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1220 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1221 | * login is in progress -- awaiting response from firmware |
| 1222 | */ |
| 1223 | static void |
| 1224 | bfa_lps_sm_login(struct bfa_lps_s *lps, enum bfa_lps_event event) |
| 1225 | { |
| 1226 | bfa_trc(lps->bfa, lps->lp_tag); |
| 1227 | bfa_trc(lps->bfa, event); |
| 1228 | |
| 1229 | switch (event) { |
| 1230 | case BFA_LPS_SM_FWRSP: |
| 1231 | if (lps->status == BFA_STATUS_OK) { |
| 1232 | bfa_sm_set_state(lps, bfa_lps_sm_online); |
| 1233 | if (lps->fdisc) |
| 1234 | bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS, |
| 1235 | BFA_PL_EID_LOGIN, 0, "FDISC Accept"); |
| 1236 | else |
| 1237 | bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS, |
| 1238 | BFA_PL_EID_LOGIN, 0, "FLOGI Accept"); |
Krishna Gudipati | b704495 | 2010-12-13 16:17:42 -0800 | [diff] [blame] | 1239 | /* If N2N, send the assigned PID to FW */ |
| 1240 | bfa_trc(lps->bfa, lps->fport); |
| 1241 | bfa_trc(lps->bfa, lps->lp_pid); |
| 1242 | |
| 1243 | if (!lps->fport && lps->lp_pid) |
| 1244 | bfa_sm_send_event(lps, BFA_LPS_SM_SET_N2N_PID); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1245 | } else { |
| 1246 | bfa_sm_set_state(lps, bfa_lps_sm_init); |
| 1247 | if (lps->fdisc) |
| 1248 | bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS, |
| 1249 | BFA_PL_EID_LOGIN, 0, |
| 1250 | "FDISC Fail (RJT or timeout)"); |
| 1251 | else |
| 1252 | bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS, |
| 1253 | BFA_PL_EID_LOGIN, 0, |
| 1254 | "FLOGI Fail (RJT or timeout)"); |
| 1255 | } |
| 1256 | bfa_lps_login_comp(lps); |
| 1257 | break; |
| 1258 | |
| 1259 | case BFA_LPS_SM_OFFLINE: |
Krishna Gudipati | be540a9 | 2011-06-13 15:53:04 -0700 | [diff] [blame] | 1260 | case BFA_LPS_SM_DELETE: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1261 | bfa_sm_set_state(lps, bfa_lps_sm_init); |
| 1262 | break; |
| 1263 | |
Krishna Gudipati | b704495 | 2010-12-13 16:17:42 -0800 | [diff] [blame] | 1264 | case BFA_LPS_SM_SET_N2N_PID: |
| 1265 | bfa_trc(lps->bfa, lps->fport); |
| 1266 | bfa_trc(lps->bfa, lps->lp_pid); |
| 1267 | break; |
| 1268 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1269 | default: |
| 1270 | bfa_sm_fault(lps->bfa, event); |
| 1271 | } |
| 1272 | } |
| 1273 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1274 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1275 | * login pending - awaiting space in request queue |
| 1276 | */ |
| 1277 | static void |
| 1278 | bfa_lps_sm_loginwait(struct bfa_lps_s *lps, enum bfa_lps_event event) |
| 1279 | { |
| 1280 | bfa_trc(lps->bfa, lps->lp_tag); |
| 1281 | bfa_trc(lps->bfa, event); |
| 1282 | |
| 1283 | switch (event) { |
| 1284 | case BFA_LPS_SM_RESUME: |
| 1285 | bfa_sm_set_state(lps, bfa_lps_sm_login); |
| 1286 | break; |
| 1287 | |
| 1288 | case BFA_LPS_SM_OFFLINE: |
Krishna Gudipati | be540a9 | 2011-06-13 15:53:04 -0700 | [diff] [blame] | 1289 | case BFA_LPS_SM_DELETE: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1290 | bfa_sm_set_state(lps, bfa_lps_sm_init); |
| 1291 | bfa_reqq_wcancel(&lps->wqe); |
| 1292 | break; |
| 1293 | |
| 1294 | case BFA_LPS_SM_RX_CVL: |
| 1295 | /* |
| 1296 | * Login was not even sent out; so when getting out |
| 1297 | * of this state, it will appear like a login retry |
| 1298 | * after Clear virtual link |
| 1299 | */ |
| 1300 | break; |
| 1301 | |
| 1302 | default: |
| 1303 | bfa_sm_fault(lps->bfa, event); |
| 1304 | } |
| 1305 | } |
| 1306 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1307 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1308 | * login complete |
| 1309 | */ |
| 1310 | static void |
| 1311 | bfa_lps_sm_online(struct bfa_lps_s *lps, enum bfa_lps_event event) |
| 1312 | { |
| 1313 | bfa_trc(lps->bfa, lps->lp_tag); |
| 1314 | bfa_trc(lps->bfa, event); |
| 1315 | |
| 1316 | switch (event) { |
| 1317 | case BFA_LPS_SM_LOGOUT: |
| 1318 | if (bfa_reqq_full(lps->bfa, lps->reqq)) { |
| 1319 | bfa_sm_set_state(lps, bfa_lps_sm_logowait); |
| 1320 | bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe); |
| 1321 | } else { |
| 1322 | bfa_sm_set_state(lps, bfa_lps_sm_logout); |
| 1323 | bfa_lps_send_logout(lps); |
| 1324 | } |
| 1325 | bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS, |
| 1326 | BFA_PL_EID_LOGO, 0, "Logout"); |
| 1327 | break; |
| 1328 | |
| 1329 | case BFA_LPS_SM_RX_CVL: |
| 1330 | bfa_sm_set_state(lps, bfa_lps_sm_init); |
| 1331 | |
| 1332 | /* Let the vport module know about this event */ |
| 1333 | bfa_lps_cvl_event(lps); |
| 1334 | bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS, |
| 1335 | BFA_PL_EID_FIP_FCF_CVL, 0, "FCF Clear Virt. Link Rx"); |
| 1336 | break; |
| 1337 | |
Krishna Gudipati | b704495 | 2010-12-13 16:17:42 -0800 | [diff] [blame] | 1338 | case BFA_LPS_SM_SET_N2N_PID: |
| 1339 | if (bfa_reqq_full(lps->bfa, lps->reqq)) { |
| 1340 | bfa_sm_set_state(lps, bfa_lps_sm_online_n2n_pid_wait); |
| 1341 | bfa_reqq_wait(lps->bfa, lps->reqq, &lps->wqe); |
| 1342 | } else |
| 1343 | bfa_lps_send_set_n2n_pid(lps); |
| 1344 | break; |
| 1345 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1346 | case BFA_LPS_SM_OFFLINE: |
| 1347 | case BFA_LPS_SM_DELETE: |
| 1348 | bfa_sm_set_state(lps, bfa_lps_sm_init); |
| 1349 | break; |
| 1350 | |
| 1351 | default: |
| 1352 | bfa_sm_fault(lps->bfa, event); |
| 1353 | } |
| 1354 | } |
| 1355 | |
Jing Huang | 8f4bfad | 2010-12-26 21:50:10 -0800 | [diff] [blame] | 1356 | /* |
Krishna Gudipati | b704495 | 2010-12-13 16:17:42 -0800 | [diff] [blame] | 1357 | * login complete |
| 1358 | */ |
| 1359 | static void |
| 1360 | bfa_lps_sm_online_n2n_pid_wait(struct bfa_lps_s *lps, enum bfa_lps_event event) |
| 1361 | { |
| 1362 | bfa_trc(lps->bfa, lps->lp_tag); |
| 1363 | bfa_trc(lps->bfa, event); |
| 1364 | |
| 1365 | switch (event) { |
| 1366 | case BFA_LPS_SM_RESUME: |
| 1367 | bfa_sm_set_state(lps, bfa_lps_sm_online); |
| 1368 | bfa_lps_send_set_n2n_pid(lps); |
| 1369 | break; |
| 1370 | |
| 1371 | case BFA_LPS_SM_LOGOUT: |
| 1372 | bfa_sm_set_state(lps, bfa_lps_sm_logowait); |
| 1373 | bfa_plog_str(lps->bfa->plog, BFA_PL_MID_LPS, |
| 1374 | BFA_PL_EID_LOGO, 0, "Logout"); |
| 1375 | break; |
| 1376 | |
| 1377 | case BFA_LPS_SM_RX_CVL: |
| 1378 | bfa_sm_set_state(lps, bfa_lps_sm_init); |
| 1379 | bfa_reqq_wcancel(&lps->wqe); |
| 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 | |
| 1387 | case BFA_LPS_SM_OFFLINE: |
| 1388 | case BFA_LPS_SM_DELETE: |
| 1389 | bfa_sm_set_state(lps, bfa_lps_sm_init); |
| 1390 | bfa_reqq_wcancel(&lps->wqe); |
| 1391 | break; |
| 1392 | |
| 1393 | default: |
| 1394 | bfa_sm_fault(lps->bfa, event); |
| 1395 | } |
| 1396 | } |
| 1397 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1398 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1399 | * logout in progress - awaiting firmware response |
| 1400 | */ |
| 1401 | static void |
| 1402 | bfa_lps_sm_logout(struct bfa_lps_s *lps, enum bfa_lps_event event) |
| 1403 | { |
| 1404 | bfa_trc(lps->bfa, lps->lp_tag); |
| 1405 | bfa_trc(lps->bfa, event); |
| 1406 | |
| 1407 | switch (event) { |
| 1408 | case BFA_LPS_SM_FWRSP: |
| 1409 | bfa_sm_set_state(lps, bfa_lps_sm_init); |
| 1410 | bfa_lps_logout_comp(lps); |
| 1411 | break; |
| 1412 | |
| 1413 | case BFA_LPS_SM_OFFLINE: |
Krishna Gudipati | be540a9 | 2011-06-13 15:53:04 -0700 | [diff] [blame] | 1414 | case BFA_LPS_SM_DELETE: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1415 | bfa_sm_set_state(lps, bfa_lps_sm_init); |
| 1416 | break; |
| 1417 | |
| 1418 | default: |
| 1419 | bfa_sm_fault(lps->bfa, event); |
| 1420 | } |
| 1421 | } |
| 1422 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1423 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1424 | * logout pending -- awaiting space in request queue |
| 1425 | */ |
| 1426 | static void |
| 1427 | bfa_lps_sm_logowait(struct bfa_lps_s *lps, enum bfa_lps_event event) |
| 1428 | { |
| 1429 | bfa_trc(lps->bfa, lps->lp_tag); |
| 1430 | bfa_trc(lps->bfa, event); |
| 1431 | |
| 1432 | switch (event) { |
| 1433 | case BFA_LPS_SM_RESUME: |
| 1434 | bfa_sm_set_state(lps, bfa_lps_sm_logout); |
| 1435 | bfa_lps_send_logout(lps); |
| 1436 | break; |
| 1437 | |
| 1438 | case BFA_LPS_SM_OFFLINE: |
Krishna Gudipati | be540a9 | 2011-06-13 15:53:04 -0700 | [diff] [blame] | 1439 | case BFA_LPS_SM_DELETE: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1440 | bfa_sm_set_state(lps, bfa_lps_sm_init); |
| 1441 | bfa_reqq_wcancel(&lps->wqe); |
| 1442 | break; |
| 1443 | |
| 1444 | default: |
| 1445 | bfa_sm_fault(lps->bfa, event); |
| 1446 | } |
| 1447 | } |
| 1448 | |
| 1449 | |
| 1450 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1451 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1452 | * lps_pvt BFA LPS private functions |
| 1453 | */ |
| 1454 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1455 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1456 | * return memory requirement |
| 1457 | */ |
| 1458 | static void |
| 1459 | bfa_lps_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *ndm_len, |
| 1460 | u32 *dm_len) |
| 1461 | { |
| 1462 | if (cfg->drvcfg.min_cfg) |
| 1463 | *ndm_len += sizeof(struct bfa_lps_s) * BFA_LPS_MIN_LPORTS; |
| 1464 | else |
| 1465 | *ndm_len += sizeof(struct bfa_lps_s) * BFA_LPS_MAX_LPORTS; |
| 1466 | } |
| 1467 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1468 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1469 | * bfa module attach at initialization time |
| 1470 | */ |
| 1471 | static void |
| 1472 | bfa_lps_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg, |
| 1473 | struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev) |
| 1474 | { |
| 1475 | struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa); |
| 1476 | struct bfa_lps_s *lps; |
| 1477 | int i; |
| 1478 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 1479 | memset(mod, 0, sizeof(struct bfa_lps_mod_s)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1480 | mod->num_lps = BFA_LPS_MAX_LPORTS; |
| 1481 | if (cfg->drvcfg.min_cfg) |
| 1482 | mod->num_lps = BFA_LPS_MIN_LPORTS; |
| 1483 | else |
| 1484 | mod->num_lps = BFA_LPS_MAX_LPORTS; |
| 1485 | mod->lps_arr = lps = (struct bfa_lps_s *) bfa_meminfo_kva(meminfo); |
| 1486 | |
| 1487 | bfa_meminfo_kva(meminfo) += mod->num_lps * sizeof(struct bfa_lps_s); |
| 1488 | |
| 1489 | INIT_LIST_HEAD(&mod->lps_free_q); |
| 1490 | INIT_LIST_HEAD(&mod->lps_active_q); |
| 1491 | |
| 1492 | for (i = 0; i < mod->num_lps; i++, lps++) { |
| 1493 | lps->bfa = bfa; |
| 1494 | lps->lp_tag = (u8) i; |
| 1495 | lps->reqq = BFA_REQQ_LPS; |
| 1496 | bfa_reqq_winit(&lps->wqe, bfa_lps_reqq_resume, lps); |
| 1497 | list_add_tail(&lps->qe, &mod->lps_free_q); |
| 1498 | } |
| 1499 | } |
| 1500 | |
| 1501 | static void |
| 1502 | bfa_lps_detach(struct bfa_s *bfa) |
| 1503 | { |
| 1504 | } |
| 1505 | |
| 1506 | static void |
| 1507 | bfa_lps_start(struct bfa_s *bfa) |
| 1508 | { |
| 1509 | } |
| 1510 | |
| 1511 | static void |
| 1512 | bfa_lps_stop(struct bfa_s *bfa) |
| 1513 | { |
| 1514 | } |
| 1515 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1516 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1517 | * IOC in disabled state -- consider all lps offline |
| 1518 | */ |
| 1519 | static void |
| 1520 | bfa_lps_iocdisable(struct bfa_s *bfa) |
| 1521 | { |
| 1522 | struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa); |
| 1523 | struct bfa_lps_s *lps; |
| 1524 | struct list_head *qe, *qen; |
| 1525 | |
| 1526 | list_for_each_safe(qe, qen, &mod->lps_active_q) { |
| 1527 | lps = (struct bfa_lps_s *) qe; |
| 1528 | bfa_sm_send_event(lps, BFA_LPS_SM_OFFLINE); |
| 1529 | } |
| 1530 | } |
| 1531 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1532 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1533 | * Firmware login response |
| 1534 | */ |
| 1535 | static void |
| 1536 | bfa_lps_login_rsp(struct bfa_s *bfa, struct bfi_lps_login_rsp_s *rsp) |
| 1537 | { |
| 1538 | struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa); |
| 1539 | struct bfa_lps_s *lps; |
| 1540 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 1541 | WARN_ON(rsp->lp_tag >= mod->num_lps); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1542 | lps = BFA_LPS_FROM_TAG(mod, rsp->lp_tag); |
| 1543 | |
| 1544 | lps->status = rsp->status; |
| 1545 | switch (rsp->status) { |
| 1546 | case BFA_STATUS_OK: |
| 1547 | lps->fport = rsp->f_port; |
Krishna Gudipati | b704495 | 2010-12-13 16:17:42 -0800 | [diff] [blame] | 1548 | if (lps->fport) |
| 1549 | lps->lp_pid = rsp->lp_pid; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1550 | lps->npiv_en = rsp->npiv_en; |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 1551 | lps->pr_bbcred = be16_to_cpu(rsp->bb_credit); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1552 | lps->pr_pwwn = rsp->port_name; |
| 1553 | lps->pr_nwwn = rsp->node_name; |
| 1554 | lps->auth_req = rsp->auth_req; |
| 1555 | lps->lp_mac = rsp->lp_mac; |
| 1556 | lps->brcd_switch = rsp->brcd_switch; |
| 1557 | lps->fcf_mac = rsp->fcf_mac; |
Krishna Gudipati | be540a9 | 2011-06-13 15:53:04 -0700 | [diff] [blame] | 1558 | lps->pr_bbscn = rsp->bb_scn; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1559 | |
| 1560 | break; |
| 1561 | |
| 1562 | case BFA_STATUS_FABRIC_RJT: |
| 1563 | lps->lsrjt_rsn = rsp->lsrjt_rsn; |
| 1564 | lps->lsrjt_expl = rsp->lsrjt_expl; |
| 1565 | |
| 1566 | break; |
| 1567 | |
| 1568 | case BFA_STATUS_EPROTOCOL: |
| 1569 | lps->ext_status = rsp->ext_status; |
| 1570 | |
| 1571 | break; |
| 1572 | |
| 1573 | default: |
| 1574 | /* Nothing to do with other status */ |
| 1575 | break; |
| 1576 | } |
| 1577 | |
| 1578 | bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP); |
| 1579 | } |
| 1580 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1581 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1582 | * Firmware logout response |
| 1583 | */ |
| 1584 | static void |
| 1585 | bfa_lps_logout_rsp(struct bfa_s *bfa, struct bfi_lps_logout_rsp_s *rsp) |
| 1586 | { |
| 1587 | struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa); |
| 1588 | struct bfa_lps_s *lps; |
| 1589 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 1590 | WARN_ON(rsp->lp_tag >= mod->num_lps); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1591 | lps = BFA_LPS_FROM_TAG(mod, rsp->lp_tag); |
| 1592 | |
| 1593 | bfa_sm_send_event(lps, BFA_LPS_SM_FWRSP); |
| 1594 | } |
| 1595 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1596 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1597 | * Firmware received a Clear virtual link request (for FCoE) |
| 1598 | */ |
| 1599 | static void |
| 1600 | bfa_lps_rx_cvl_event(struct bfa_s *bfa, struct bfi_lps_cvl_event_s *cvl) |
| 1601 | { |
| 1602 | struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa); |
| 1603 | struct bfa_lps_s *lps; |
| 1604 | |
| 1605 | lps = BFA_LPS_FROM_TAG(mod, cvl->lp_tag); |
| 1606 | |
| 1607 | bfa_sm_send_event(lps, BFA_LPS_SM_RX_CVL); |
| 1608 | } |
| 1609 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1610 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1611 | * Space is available in request queue, resume queueing request to firmware. |
| 1612 | */ |
| 1613 | static void |
| 1614 | bfa_lps_reqq_resume(void *lps_arg) |
| 1615 | { |
| 1616 | struct bfa_lps_s *lps = lps_arg; |
| 1617 | |
| 1618 | bfa_sm_send_event(lps, BFA_LPS_SM_RESUME); |
| 1619 | } |
| 1620 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1621 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1622 | * lps is freed -- triggered by vport delete |
| 1623 | */ |
| 1624 | static void |
| 1625 | bfa_lps_free(struct bfa_lps_s *lps) |
| 1626 | { |
| 1627 | struct bfa_lps_mod_s *mod = BFA_LPS_MOD(lps->bfa); |
| 1628 | |
| 1629 | lps->lp_pid = 0; |
| 1630 | list_del(&lps->qe); |
| 1631 | list_add_tail(&lps->qe, &mod->lps_free_q); |
| 1632 | } |
| 1633 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1634 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1635 | * send login request to firmware |
| 1636 | */ |
| 1637 | static void |
| 1638 | bfa_lps_send_login(struct bfa_lps_s *lps) |
| 1639 | { |
| 1640 | struct bfi_lps_login_req_s *m; |
| 1641 | |
| 1642 | m = bfa_reqq_next(lps->bfa, lps->reqq); |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 1643 | WARN_ON(!m); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1644 | |
| 1645 | bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_LOGIN_REQ, |
| 1646 | bfa_lpuid(lps->bfa)); |
| 1647 | |
| 1648 | m->lp_tag = lps->lp_tag; |
| 1649 | m->alpa = lps->alpa; |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 1650 | m->pdu_size = cpu_to_be16(lps->pdusz); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1651 | m->pwwn = lps->pwwn; |
| 1652 | m->nwwn = lps->nwwn; |
| 1653 | m->fdisc = lps->fdisc; |
| 1654 | m->auth_en = lps->auth_en; |
Krishna Gudipati | be540a9 | 2011-06-13 15:53:04 -0700 | [diff] [blame] | 1655 | m->bb_scn = lps->bb_scn; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1656 | |
| 1657 | bfa_reqq_produce(lps->bfa, lps->reqq); |
| 1658 | } |
| 1659 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1660 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1661 | * send logout request to firmware |
| 1662 | */ |
| 1663 | static void |
| 1664 | bfa_lps_send_logout(struct bfa_lps_s *lps) |
| 1665 | { |
| 1666 | struct bfi_lps_logout_req_s *m; |
| 1667 | |
| 1668 | m = bfa_reqq_next(lps->bfa, lps->reqq); |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 1669 | WARN_ON(!m); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1670 | |
| 1671 | bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_LOGOUT_REQ, |
| 1672 | bfa_lpuid(lps->bfa)); |
| 1673 | |
| 1674 | m->lp_tag = lps->lp_tag; |
| 1675 | m->port_name = lps->pwwn; |
| 1676 | bfa_reqq_produce(lps->bfa, lps->reqq); |
| 1677 | } |
| 1678 | |
Jing Huang | 8f4bfad | 2010-12-26 21:50:10 -0800 | [diff] [blame] | 1679 | /* |
Krishna Gudipati | b704495 | 2010-12-13 16:17:42 -0800 | [diff] [blame] | 1680 | * send n2n pid set request to firmware |
| 1681 | */ |
| 1682 | static void |
| 1683 | bfa_lps_send_set_n2n_pid(struct bfa_lps_s *lps) |
| 1684 | { |
| 1685 | struct bfi_lps_n2n_pid_req_s *m; |
| 1686 | |
| 1687 | m = bfa_reqq_next(lps->bfa, lps->reqq); |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 1688 | WARN_ON(!m); |
Krishna Gudipati | b704495 | 2010-12-13 16:17:42 -0800 | [diff] [blame] | 1689 | |
| 1690 | bfi_h2i_set(m->mh, BFI_MC_LPS, BFI_LPS_H2I_N2N_PID_REQ, |
| 1691 | bfa_lpuid(lps->bfa)); |
| 1692 | |
| 1693 | m->lp_tag = lps->lp_tag; |
| 1694 | m->lp_pid = lps->lp_pid; |
| 1695 | bfa_reqq_produce(lps->bfa, lps->reqq); |
| 1696 | } |
| 1697 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1698 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1699 | * Indirect login completion handler for non-fcs |
| 1700 | */ |
| 1701 | static void |
| 1702 | bfa_lps_login_comp_cb(void *arg, bfa_boolean_t complete) |
| 1703 | { |
| 1704 | struct bfa_lps_s *lps = arg; |
| 1705 | |
| 1706 | if (!complete) |
| 1707 | return; |
| 1708 | |
| 1709 | if (lps->fdisc) |
| 1710 | bfa_cb_lps_fdisc_comp(lps->bfa->bfad, lps->uarg, lps->status); |
| 1711 | else |
| 1712 | bfa_cb_lps_flogi_comp(lps->bfa->bfad, lps->uarg, lps->status); |
| 1713 | } |
| 1714 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1715 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1716 | * Login completion handler -- direct call for fcs, queue for others |
| 1717 | */ |
| 1718 | static void |
| 1719 | bfa_lps_login_comp(struct bfa_lps_s *lps) |
| 1720 | { |
| 1721 | if (!lps->bfa->fcs) { |
| 1722 | bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_login_comp_cb, |
| 1723 | lps); |
| 1724 | return; |
| 1725 | } |
| 1726 | |
| 1727 | if (lps->fdisc) |
| 1728 | bfa_cb_lps_fdisc_comp(lps->bfa->bfad, lps->uarg, lps->status); |
| 1729 | else |
| 1730 | bfa_cb_lps_flogi_comp(lps->bfa->bfad, lps->uarg, lps->status); |
| 1731 | } |
| 1732 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1733 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1734 | * Indirect logout completion handler for non-fcs |
| 1735 | */ |
| 1736 | static void |
| 1737 | bfa_lps_logout_comp_cb(void *arg, bfa_boolean_t complete) |
| 1738 | { |
| 1739 | struct bfa_lps_s *lps = arg; |
| 1740 | |
| 1741 | if (!complete) |
| 1742 | return; |
| 1743 | |
| 1744 | if (lps->fdisc) |
| 1745 | bfa_cb_lps_fdisclogo_comp(lps->bfa->bfad, lps->uarg); |
| 1746 | } |
| 1747 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1748 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1749 | * Logout completion handler -- direct call for fcs, queue for others |
| 1750 | */ |
| 1751 | static void |
| 1752 | bfa_lps_logout_comp(struct bfa_lps_s *lps) |
| 1753 | { |
| 1754 | if (!lps->bfa->fcs) { |
| 1755 | bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_logout_comp_cb, |
| 1756 | lps); |
| 1757 | return; |
| 1758 | } |
| 1759 | if (lps->fdisc) |
| 1760 | bfa_cb_lps_fdisclogo_comp(lps->bfa->bfad, lps->uarg); |
| 1761 | } |
| 1762 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1763 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1764 | * Clear virtual link completion handler for non-fcs |
| 1765 | */ |
| 1766 | static void |
| 1767 | bfa_lps_cvl_event_cb(void *arg, bfa_boolean_t complete) |
| 1768 | { |
| 1769 | struct bfa_lps_s *lps = arg; |
| 1770 | |
| 1771 | if (!complete) |
| 1772 | return; |
| 1773 | |
| 1774 | /* Clear virtual link to base port will result in link down */ |
| 1775 | if (lps->fdisc) |
| 1776 | bfa_cb_lps_cvl_event(lps->bfa->bfad, lps->uarg); |
| 1777 | } |
| 1778 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1779 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1780 | * Received Clear virtual link event --direct call for fcs, |
| 1781 | * queue for others |
| 1782 | */ |
| 1783 | static void |
| 1784 | bfa_lps_cvl_event(struct bfa_lps_s *lps) |
| 1785 | { |
| 1786 | if (!lps->bfa->fcs) { |
| 1787 | bfa_cb_queue(lps->bfa, &lps->hcb_qe, bfa_lps_cvl_event_cb, |
| 1788 | lps); |
| 1789 | return; |
| 1790 | } |
| 1791 | |
| 1792 | /* Clear virtual link to base port will result in link down */ |
| 1793 | if (lps->fdisc) |
| 1794 | bfa_cb_lps_cvl_event(lps->bfa->bfad, lps->uarg); |
| 1795 | } |
| 1796 | |
| 1797 | |
| 1798 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1799 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1800 | * lps_public BFA LPS public functions |
| 1801 | */ |
| 1802 | |
| 1803 | u32 |
| 1804 | bfa_lps_get_max_vport(struct bfa_s *bfa) |
| 1805 | { |
| 1806 | if (bfa_ioc_devid(&bfa->ioc) == BFA_PCI_DEVICE_ID_CT) |
| 1807 | return BFA_LPS_MAX_VPORTS_SUPP_CT; |
| 1808 | else |
| 1809 | return BFA_LPS_MAX_VPORTS_SUPP_CB; |
| 1810 | } |
| 1811 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1812 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1813 | * Allocate a lport srvice tag. |
| 1814 | */ |
| 1815 | struct bfa_lps_s * |
| 1816 | bfa_lps_alloc(struct bfa_s *bfa) |
| 1817 | { |
| 1818 | struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa); |
| 1819 | struct bfa_lps_s *lps = NULL; |
| 1820 | |
| 1821 | bfa_q_deq(&mod->lps_free_q, &lps); |
| 1822 | |
| 1823 | if (lps == NULL) |
| 1824 | return NULL; |
| 1825 | |
| 1826 | list_add_tail(&lps->qe, &mod->lps_active_q); |
| 1827 | |
| 1828 | bfa_sm_set_state(lps, bfa_lps_sm_init); |
| 1829 | return lps; |
| 1830 | } |
| 1831 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1832 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1833 | * Free lport service tag. This can be called anytime after an alloc. |
| 1834 | * No need to wait for any pending login/logout completions. |
| 1835 | */ |
| 1836 | void |
| 1837 | bfa_lps_delete(struct bfa_lps_s *lps) |
| 1838 | { |
| 1839 | bfa_sm_send_event(lps, BFA_LPS_SM_DELETE); |
| 1840 | } |
| 1841 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1842 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1843 | * Initiate a lport login. |
| 1844 | */ |
| 1845 | void |
| 1846 | 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] | 1847 | 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] | 1848 | { |
| 1849 | lps->uarg = uarg; |
| 1850 | lps->alpa = alpa; |
| 1851 | lps->pdusz = pdusz; |
| 1852 | lps->pwwn = pwwn; |
| 1853 | lps->nwwn = nwwn; |
| 1854 | lps->fdisc = BFA_FALSE; |
| 1855 | lps->auth_en = auth_en; |
Krishna Gudipati | be540a9 | 2011-06-13 15:53:04 -0700 | [diff] [blame] | 1856 | lps->bb_scn = bb_scn; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1857 | bfa_sm_send_event(lps, BFA_LPS_SM_LOGIN); |
| 1858 | } |
| 1859 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1860 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1861 | * Initiate a lport fdisc login. |
| 1862 | */ |
| 1863 | void |
| 1864 | bfa_lps_fdisc(struct bfa_lps_s *lps, void *uarg, u16 pdusz, wwn_t pwwn, |
| 1865 | wwn_t nwwn) |
| 1866 | { |
| 1867 | lps->uarg = uarg; |
| 1868 | lps->alpa = 0; |
| 1869 | lps->pdusz = pdusz; |
| 1870 | lps->pwwn = pwwn; |
| 1871 | lps->nwwn = nwwn; |
| 1872 | lps->fdisc = BFA_TRUE; |
| 1873 | lps->auth_en = BFA_FALSE; |
| 1874 | bfa_sm_send_event(lps, BFA_LPS_SM_LOGIN); |
| 1875 | } |
| 1876 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1877 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1878 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1879 | * Initiate a lport FDSIC logout. |
| 1880 | */ |
| 1881 | void |
| 1882 | bfa_lps_fdisclogo(struct bfa_lps_s *lps) |
| 1883 | { |
| 1884 | bfa_sm_send_event(lps, BFA_LPS_SM_LOGOUT); |
| 1885 | } |
| 1886 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1887 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1888 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1889 | * Return lport services tag given the pid |
| 1890 | */ |
| 1891 | u8 |
| 1892 | bfa_lps_get_tag_from_pid(struct bfa_s *bfa, u32 pid) |
| 1893 | { |
| 1894 | struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa); |
| 1895 | struct bfa_lps_s *lps; |
| 1896 | int i; |
| 1897 | |
| 1898 | for (i = 0, lps = mod->lps_arr; i < mod->num_lps; i++, lps++) { |
| 1899 | if (lps->lp_pid == pid) |
| 1900 | return lps->lp_tag; |
| 1901 | } |
| 1902 | |
| 1903 | /* Return base port tag anyway */ |
| 1904 | return 0; |
| 1905 | } |
| 1906 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 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 | * return port id assigned to the base lport |
| 1910 | */ |
| 1911 | u32 |
| 1912 | bfa_lps_get_base_pid(struct bfa_s *bfa) |
| 1913 | { |
| 1914 | struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa); |
| 1915 | |
| 1916 | return BFA_LPS_FROM_TAG(mod, 0)->lp_pid; |
| 1917 | } |
| 1918 | |
Jing Huang | 8f4bfad | 2010-12-26 21:50:10 -0800 | [diff] [blame] | 1919 | /* |
Krishna Gudipati | b704495 | 2010-12-13 16:17:42 -0800 | [diff] [blame] | 1920 | * Set PID in case of n2n (which is assigned during PLOGI) |
| 1921 | */ |
| 1922 | void |
| 1923 | bfa_lps_set_n2n_pid(struct bfa_lps_s *lps, uint32_t n2n_pid) |
| 1924 | { |
| 1925 | bfa_trc(lps->bfa, lps->lp_tag); |
| 1926 | bfa_trc(lps->bfa, n2n_pid); |
| 1927 | |
| 1928 | lps->lp_pid = n2n_pid; |
| 1929 | bfa_sm_send_event(lps, BFA_LPS_SM_SET_N2N_PID); |
| 1930 | } |
| 1931 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1932 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1933 | * LPS firmware message class handler. |
| 1934 | */ |
| 1935 | void |
| 1936 | bfa_lps_isr(struct bfa_s *bfa, struct bfi_msg_s *m) |
| 1937 | { |
| 1938 | union bfi_lps_i2h_msg_u msg; |
| 1939 | |
| 1940 | bfa_trc(bfa, m->mhdr.msg_id); |
| 1941 | msg.msg = m; |
| 1942 | |
| 1943 | switch (m->mhdr.msg_id) { |
Krishna Gudipati | 43ffdf4 | 2011-06-13 15:46:21 -0700 | [diff] [blame] | 1944 | case BFI_LPS_I2H_LOGIN_RSP: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1945 | bfa_lps_login_rsp(bfa, msg.login_rsp); |
| 1946 | break; |
| 1947 | |
Krishna Gudipati | 43ffdf4 | 2011-06-13 15:46:21 -0700 | [diff] [blame] | 1948 | case BFI_LPS_I2H_LOGOUT_RSP: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1949 | bfa_lps_logout_rsp(bfa, msg.logout_rsp); |
| 1950 | break; |
| 1951 | |
Krishna Gudipati | 43ffdf4 | 2011-06-13 15:46:21 -0700 | [diff] [blame] | 1952 | case BFI_LPS_I2H_CVL_EVENT: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1953 | bfa_lps_rx_cvl_event(bfa, msg.cvl_event); |
| 1954 | break; |
| 1955 | |
| 1956 | default: |
| 1957 | bfa_trc(bfa, m->mhdr.msg_id); |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 1958 | WARN_ON(1); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1959 | } |
| 1960 | } |
| 1961 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1962 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1963 | * FC PORT state machine functions |
| 1964 | */ |
| 1965 | static void |
| 1966 | bfa_fcport_sm_uninit(struct bfa_fcport_s *fcport, |
| 1967 | enum bfa_fcport_sm_event event) |
| 1968 | { |
| 1969 | bfa_trc(fcport->bfa, event); |
| 1970 | |
| 1971 | switch (event) { |
| 1972 | case BFA_FCPORT_SM_START: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1973 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1974 | * Start event after IOC is configured and BFA is started. |
| 1975 | */ |
Krishna Gudipati | f3a060c | 2010-12-13 16:16:50 -0800 | [diff] [blame] | 1976 | fcport->use_flash_cfg = BFA_TRUE; |
| 1977 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1978 | if (bfa_fcport_send_enable(fcport)) { |
| 1979 | bfa_trc(fcport->bfa, BFA_TRUE); |
| 1980 | bfa_sm_set_state(fcport, bfa_fcport_sm_enabling); |
| 1981 | } else { |
| 1982 | bfa_trc(fcport->bfa, BFA_FALSE); |
| 1983 | bfa_sm_set_state(fcport, |
| 1984 | bfa_fcport_sm_enabling_qwait); |
| 1985 | } |
| 1986 | break; |
| 1987 | |
| 1988 | case BFA_FCPORT_SM_ENABLE: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1989 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1990 | * Port is persistently configured to be in enabled state. Do |
| 1991 | * not change state. Port enabling is done when START event is |
| 1992 | * received. |
| 1993 | */ |
| 1994 | break; |
| 1995 | |
| 1996 | case BFA_FCPORT_SM_DISABLE: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1997 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1998 | * If a port is persistently configured to be disabled, the |
| 1999 | * first event will a port disable request. |
| 2000 | */ |
| 2001 | bfa_sm_set_state(fcport, bfa_fcport_sm_disabled); |
| 2002 | break; |
| 2003 | |
| 2004 | case BFA_FCPORT_SM_HWFAIL: |
| 2005 | bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown); |
| 2006 | break; |
| 2007 | |
| 2008 | default: |
| 2009 | bfa_sm_fault(fcport->bfa, event); |
| 2010 | } |
| 2011 | } |
| 2012 | |
| 2013 | static void |
| 2014 | bfa_fcport_sm_enabling_qwait(struct bfa_fcport_s *fcport, |
| 2015 | enum bfa_fcport_sm_event event) |
| 2016 | { |
| 2017 | char pwwn_buf[BFA_STRING_32]; |
| 2018 | struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad; |
| 2019 | bfa_trc(fcport->bfa, event); |
| 2020 | |
| 2021 | switch (event) { |
| 2022 | case BFA_FCPORT_SM_QRESUME: |
| 2023 | bfa_sm_set_state(fcport, bfa_fcport_sm_enabling); |
| 2024 | bfa_fcport_send_enable(fcport); |
| 2025 | break; |
| 2026 | |
| 2027 | case BFA_FCPORT_SM_STOP: |
| 2028 | bfa_reqq_wcancel(&fcport->reqq_wait); |
| 2029 | bfa_sm_set_state(fcport, bfa_fcport_sm_stopped); |
| 2030 | break; |
| 2031 | |
| 2032 | case BFA_FCPORT_SM_ENABLE: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2033 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2034 | * Already enable is in progress. |
| 2035 | */ |
| 2036 | break; |
| 2037 | |
| 2038 | case BFA_FCPORT_SM_DISABLE: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2039 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2040 | * Just send disable request to firmware when room becomes |
| 2041 | * available in request queue. |
| 2042 | */ |
| 2043 | bfa_sm_set_state(fcport, bfa_fcport_sm_disabled); |
| 2044 | bfa_reqq_wcancel(&fcport->reqq_wait); |
| 2045 | bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL, |
| 2046 | BFA_PL_EID_PORT_DISABLE, 0, "Port Disable"); |
| 2047 | wwn2str(pwwn_buf, fcport->pwwn); |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 2048 | BFA_LOG(KERN_INFO, bfad, bfa_log_level, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2049 | "Base port disabled: WWN = %s\n", pwwn_buf); |
| 2050 | break; |
| 2051 | |
| 2052 | case BFA_FCPORT_SM_LINKUP: |
| 2053 | case BFA_FCPORT_SM_LINKDOWN: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2054 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2055 | * Possible to get link events when doing back-to-back |
| 2056 | * enable/disables. |
| 2057 | */ |
| 2058 | break; |
| 2059 | |
| 2060 | case BFA_FCPORT_SM_HWFAIL: |
| 2061 | bfa_reqq_wcancel(&fcport->reqq_wait); |
| 2062 | bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown); |
| 2063 | break; |
| 2064 | |
| 2065 | default: |
| 2066 | bfa_sm_fault(fcport->bfa, event); |
| 2067 | } |
| 2068 | } |
| 2069 | |
| 2070 | static void |
| 2071 | bfa_fcport_sm_enabling(struct bfa_fcport_s *fcport, |
| 2072 | enum bfa_fcport_sm_event event) |
| 2073 | { |
| 2074 | char pwwn_buf[BFA_STRING_32]; |
| 2075 | struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad; |
| 2076 | bfa_trc(fcport->bfa, event); |
| 2077 | |
| 2078 | switch (event) { |
| 2079 | case BFA_FCPORT_SM_FWRSP: |
| 2080 | case BFA_FCPORT_SM_LINKDOWN: |
| 2081 | bfa_sm_set_state(fcport, bfa_fcport_sm_linkdown); |
| 2082 | break; |
| 2083 | |
| 2084 | case BFA_FCPORT_SM_LINKUP: |
| 2085 | bfa_fcport_update_linkinfo(fcport); |
| 2086 | bfa_sm_set_state(fcport, bfa_fcport_sm_linkup); |
| 2087 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 2088 | WARN_ON(!fcport->event_cbfn); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2089 | bfa_fcport_scn(fcport, BFA_PORT_LINKUP, BFA_FALSE); |
| 2090 | break; |
| 2091 | |
| 2092 | case BFA_FCPORT_SM_ENABLE: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2093 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2094 | * Already being enabled. |
| 2095 | */ |
| 2096 | break; |
| 2097 | |
| 2098 | case BFA_FCPORT_SM_DISABLE: |
| 2099 | if (bfa_fcport_send_disable(fcport)) |
| 2100 | bfa_sm_set_state(fcport, bfa_fcport_sm_disabling); |
| 2101 | else |
| 2102 | bfa_sm_set_state(fcport, |
| 2103 | bfa_fcport_sm_disabling_qwait); |
| 2104 | |
| 2105 | bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL, |
| 2106 | BFA_PL_EID_PORT_DISABLE, 0, "Port Disable"); |
| 2107 | wwn2str(pwwn_buf, fcport->pwwn); |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 2108 | BFA_LOG(KERN_INFO, bfad, bfa_log_level, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2109 | "Base port disabled: WWN = %s\n", pwwn_buf); |
| 2110 | break; |
| 2111 | |
| 2112 | case BFA_FCPORT_SM_STOP: |
| 2113 | bfa_sm_set_state(fcport, bfa_fcport_sm_stopped); |
| 2114 | break; |
| 2115 | |
| 2116 | case BFA_FCPORT_SM_HWFAIL: |
| 2117 | bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown); |
| 2118 | break; |
| 2119 | |
| 2120 | default: |
| 2121 | bfa_sm_fault(fcport->bfa, event); |
| 2122 | } |
| 2123 | } |
| 2124 | |
| 2125 | static void |
| 2126 | bfa_fcport_sm_linkdown(struct bfa_fcport_s *fcport, |
| 2127 | enum bfa_fcport_sm_event event) |
| 2128 | { |
| 2129 | struct bfi_fcport_event_s *pevent = fcport->event_arg.i2hmsg.event; |
| 2130 | char pwwn_buf[BFA_STRING_32]; |
| 2131 | struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad; |
| 2132 | |
| 2133 | bfa_trc(fcport->bfa, event); |
| 2134 | |
| 2135 | switch (event) { |
| 2136 | case BFA_FCPORT_SM_LINKUP: |
| 2137 | bfa_fcport_update_linkinfo(fcport); |
| 2138 | bfa_sm_set_state(fcport, bfa_fcport_sm_linkup); |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 2139 | WARN_ON(!fcport->event_cbfn); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2140 | bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL, |
| 2141 | BFA_PL_EID_PORT_ST_CHANGE, 0, "Port Linkup"); |
| 2142 | if (!bfa_ioc_get_fcmode(&fcport->bfa->ioc)) { |
| 2143 | |
| 2144 | bfa_trc(fcport->bfa, |
| 2145 | pevent->link_state.vc_fcf.fcf.fipenabled); |
| 2146 | bfa_trc(fcport->bfa, |
| 2147 | pevent->link_state.vc_fcf.fcf.fipfailed); |
| 2148 | |
| 2149 | if (pevent->link_state.vc_fcf.fcf.fipfailed) |
| 2150 | bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL, |
| 2151 | BFA_PL_EID_FIP_FCF_DISC, 0, |
| 2152 | "FIP FCF Discovery Failed"); |
| 2153 | else |
| 2154 | bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL, |
| 2155 | BFA_PL_EID_FIP_FCF_DISC, 0, |
| 2156 | "FIP FCF Discovered"); |
| 2157 | } |
| 2158 | |
| 2159 | bfa_fcport_scn(fcport, BFA_PORT_LINKUP, BFA_FALSE); |
| 2160 | wwn2str(pwwn_buf, fcport->pwwn); |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 2161 | BFA_LOG(KERN_INFO, bfad, bfa_log_level, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2162 | "Base port online: WWN = %s\n", pwwn_buf); |
| 2163 | break; |
| 2164 | |
| 2165 | case BFA_FCPORT_SM_LINKDOWN: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2166 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2167 | * Possible to get link down event. |
| 2168 | */ |
| 2169 | break; |
| 2170 | |
| 2171 | case BFA_FCPORT_SM_ENABLE: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2172 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2173 | * Already enabled. |
| 2174 | */ |
| 2175 | break; |
| 2176 | |
| 2177 | case BFA_FCPORT_SM_DISABLE: |
| 2178 | if (bfa_fcport_send_disable(fcport)) |
| 2179 | bfa_sm_set_state(fcport, bfa_fcport_sm_disabling); |
| 2180 | else |
| 2181 | bfa_sm_set_state(fcport, |
| 2182 | bfa_fcport_sm_disabling_qwait); |
| 2183 | |
| 2184 | bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL, |
| 2185 | BFA_PL_EID_PORT_DISABLE, 0, "Port Disable"); |
| 2186 | wwn2str(pwwn_buf, fcport->pwwn); |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 2187 | BFA_LOG(KERN_INFO, bfad, bfa_log_level, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2188 | "Base port disabled: WWN = %s\n", pwwn_buf); |
| 2189 | break; |
| 2190 | |
| 2191 | case BFA_FCPORT_SM_STOP: |
| 2192 | bfa_sm_set_state(fcport, bfa_fcport_sm_stopped); |
| 2193 | break; |
| 2194 | |
| 2195 | case BFA_FCPORT_SM_HWFAIL: |
| 2196 | bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown); |
| 2197 | break; |
| 2198 | |
| 2199 | default: |
| 2200 | bfa_sm_fault(fcport->bfa, event); |
| 2201 | } |
| 2202 | } |
| 2203 | |
| 2204 | static void |
| 2205 | bfa_fcport_sm_linkup(struct bfa_fcport_s *fcport, |
| 2206 | enum bfa_fcport_sm_event event) |
| 2207 | { |
| 2208 | char pwwn_buf[BFA_STRING_32]; |
| 2209 | struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad; |
| 2210 | |
| 2211 | bfa_trc(fcport->bfa, event); |
| 2212 | |
| 2213 | switch (event) { |
| 2214 | case BFA_FCPORT_SM_ENABLE: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2215 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2216 | * Already enabled. |
| 2217 | */ |
| 2218 | break; |
| 2219 | |
| 2220 | case BFA_FCPORT_SM_DISABLE: |
| 2221 | if (bfa_fcport_send_disable(fcport)) |
| 2222 | bfa_sm_set_state(fcport, bfa_fcport_sm_disabling); |
| 2223 | else |
| 2224 | bfa_sm_set_state(fcport, |
| 2225 | bfa_fcport_sm_disabling_qwait); |
| 2226 | |
| 2227 | bfa_fcport_reset_linkinfo(fcport); |
| 2228 | bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE); |
| 2229 | bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL, |
| 2230 | BFA_PL_EID_PORT_DISABLE, 0, "Port Disable"); |
| 2231 | wwn2str(pwwn_buf, fcport->pwwn); |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 2232 | BFA_LOG(KERN_INFO, bfad, bfa_log_level, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2233 | "Base port offline: WWN = %s\n", pwwn_buf); |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 2234 | BFA_LOG(KERN_INFO, bfad, bfa_log_level, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2235 | "Base port disabled: WWN = %s\n", pwwn_buf); |
| 2236 | break; |
| 2237 | |
| 2238 | case BFA_FCPORT_SM_LINKDOWN: |
| 2239 | bfa_sm_set_state(fcport, bfa_fcport_sm_linkdown); |
| 2240 | bfa_fcport_reset_linkinfo(fcport); |
| 2241 | bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE); |
| 2242 | bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL, |
| 2243 | BFA_PL_EID_PORT_ST_CHANGE, 0, "Port Linkdown"); |
| 2244 | wwn2str(pwwn_buf, fcport->pwwn); |
| 2245 | if (BFA_PORT_IS_DISABLED(fcport->bfa)) |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 2246 | BFA_LOG(KERN_INFO, bfad, bfa_log_level, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2247 | "Base port offline: WWN = %s\n", pwwn_buf); |
| 2248 | else |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 2249 | BFA_LOG(KERN_ERR, bfad, bfa_log_level, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2250 | "Base port (WWN = %s) " |
| 2251 | "lost fabric connectivity\n", pwwn_buf); |
| 2252 | break; |
| 2253 | |
| 2254 | case BFA_FCPORT_SM_STOP: |
| 2255 | bfa_sm_set_state(fcport, bfa_fcport_sm_stopped); |
| 2256 | bfa_fcport_reset_linkinfo(fcport); |
| 2257 | wwn2str(pwwn_buf, fcport->pwwn); |
| 2258 | if (BFA_PORT_IS_DISABLED(fcport->bfa)) |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 2259 | BFA_LOG(KERN_INFO, bfad, bfa_log_level, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2260 | "Base port offline: WWN = %s\n", pwwn_buf); |
| 2261 | else |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 2262 | BFA_LOG(KERN_ERR, bfad, bfa_log_level, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2263 | "Base port (WWN = %s) " |
| 2264 | "lost fabric connectivity\n", pwwn_buf); |
| 2265 | break; |
| 2266 | |
| 2267 | case BFA_FCPORT_SM_HWFAIL: |
| 2268 | bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown); |
| 2269 | bfa_fcport_reset_linkinfo(fcport); |
| 2270 | bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_FALSE); |
| 2271 | wwn2str(pwwn_buf, fcport->pwwn); |
| 2272 | if (BFA_PORT_IS_DISABLED(fcport->bfa)) |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 2273 | BFA_LOG(KERN_INFO, bfad, bfa_log_level, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2274 | "Base port offline: WWN = %s\n", pwwn_buf); |
| 2275 | else |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 2276 | BFA_LOG(KERN_ERR, bfad, bfa_log_level, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2277 | "Base port (WWN = %s) " |
| 2278 | "lost fabric connectivity\n", pwwn_buf); |
| 2279 | break; |
| 2280 | |
| 2281 | default: |
| 2282 | bfa_sm_fault(fcport->bfa, event); |
| 2283 | } |
| 2284 | } |
| 2285 | |
| 2286 | static void |
| 2287 | bfa_fcport_sm_disabling_qwait(struct bfa_fcport_s *fcport, |
| 2288 | enum bfa_fcport_sm_event event) |
| 2289 | { |
| 2290 | bfa_trc(fcport->bfa, event); |
| 2291 | |
| 2292 | switch (event) { |
| 2293 | case BFA_FCPORT_SM_QRESUME: |
| 2294 | bfa_sm_set_state(fcport, bfa_fcport_sm_disabling); |
| 2295 | bfa_fcport_send_disable(fcport); |
| 2296 | break; |
| 2297 | |
| 2298 | case BFA_FCPORT_SM_STOP: |
| 2299 | bfa_sm_set_state(fcport, bfa_fcport_sm_stopped); |
| 2300 | bfa_reqq_wcancel(&fcport->reqq_wait); |
| 2301 | break; |
| 2302 | |
| 2303 | case BFA_FCPORT_SM_ENABLE: |
| 2304 | bfa_sm_set_state(fcport, bfa_fcport_sm_toggling_qwait); |
| 2305 | break; |
| 2306 | |
| 2307 | case BFA_FCPORT_SM_DISABLE: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2308 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2309 | * Already being disabled. |
| 2310 | */ |
| 2311 | break; |
| 2312 | |
| 2313 | case BFA_FCPORT_SM_LINKUP: |
| 2314 | case BFA_FCPORT_SM_LINKDOWN: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2315 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2316 | * Possible to get link events when doing back-to-back |
| 2317 | * enable/disables. |
| 2318 | */ |
| 2319 | break; |
| 2320 | |
| 2321 | case BFA_FCPORT_SM_HWFAIL: |
| 2322 | bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail); |
| 2323 | bfa_reqq_wcancel(&fcport->reqq_wait); |
| 2324 | break; |
| 2325 | |
| 2326 | default: |
| 2327 | bfa_sm_fault(fcport->bfa, event); |
| 2328 | } |
| 2329 | } |
| 2330 | |
| 2331 | static void |
| 2332 | bfa_fcport_sm_toggling_qwait(struct bfa_fcport_s *fcport, |
| 2333 | enum bfa_fcport_sm_event event) |
| 2334 | { |
| 2335 | bfa_trc(fcport->bfa, event); |
| 2336 | |
| 2337 | switch (event) { |
| 2338 | case BFA_FCPORT_SM_QRESUME: |
| 2339 | bfa_sm_set_state(fcport, bfa_fcport_sm_disabling); |
| 2340 | bfa_fcport_send_disable(fcport); |
| 2341 | if (bfa_fcport_send_enable(fcport)) |
| 2342 | bfa_sm_set_state(fcport, bfa_fcport_sm_enabling); |
| 2343 | else |
| 2344 | bfa_sm_set_state(fcport, |
| 2345 | bfa_fcport_sm_enabling_qwait); |
| 2346 | break; |
| 2347 | |
| 2348 | case BFA_FCPORT_SM_STOP: |
| 2349 | bfa_sm_set_state(fcport, bfa_fcport_sm_stopped); |
| 2350 | bfa_reqq_wcancel(&fcport->reqq_wait); |
| 2351 | break; |
| 2352 | |
| 2353 | case BFA_FCPORT_SM_ENABLE: |
| 2354 | break; |
| 2355 | |
| 2356 | case BFA_FCPORT_SM_DISABLE: |
| 2357 | bfa_sm_set_state(fcport, bfa_fcport_sm_disabling_qwait); |
| 2358 | break; |
| 2359 | |
| 2360 | case BFA_FCPORT_SM_LINKUP: |
| 2361 | case BFA_FCPORT_SM_LINKDOWN: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2362 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2363 | * Possible to get link events when doing back-to-back |
| 2364 | * enable/disables. |
| 2365 | */ |
| 2366 | break; |
| 2367 | |
| 2368 | case BFA_FCPORT_SM_HWFAIL: |
| 2369 | bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail); |
| 2370 | bfa_reqq_wcancel(&fcport->reqq_wait); |
| 2371 | break; |
| 2372 | |
| 2373 | default: |
| 2374 | bfa_sm_fault(fcport->bfa, event); |
| 2375 | } |
| 2376 | } |
| 2377 | |
| 2378 | static void |
| 2379 | bfa_fcport_sm_disabling(struct bfa_fcport_s *fcport, |
| 2380 | enum bfa_fcport_sm_event event) |
| 2381 | { |
| 2382 | char pwwn_buf[BFA_STRING_32]; |
| 2383 | struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad; |
| 2384 | bfa_trc(fcport->bfa, event); |
| 2385 | |
| 2386 | switch (event) { |
| 2387 | case BFA_FCPORT_SM_FWRSP: |
| 2388 | bfa_sm_set_state(fcport, bfa_fcport_sm_disabled); |
| 2389 | break; |
| 2390 | |
| 2391 | case BFA_FCPORT_SM_DISABLE: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2392 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2393 | * Already being disabled. |
| 2394 | */ |
| 2395 | break; |
| 2396 | |
| 2397 | case BFA_FCPORT_SM_ENABLE: |
| 2398 | if (bfa_fcport_send_enable(fcport)) |
| 2399 | bfa_sm_set_state(fcport, bfa_fcport_sm_enabling); |
| 2400 | else |
| 2401 | bfa_sm_set_state(fcport, |
| 2402 | bfa_fcport_sm_enabling_qwait); |
| 2403 | |
| 2404 | bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL, |
| 2405 | BFA_PL_EID_PORT_ENABLE, 0, "Port Enable"); |
| 2406 | wwn2str(pwwn_buf, fcport->pwwn); |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 2407 | BFA_LOG(KERN_INFO, bfad, bfa_log_level, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2408 | "Base port enabled: WWN = %s\n", pwwn_buf); |
| 2409 | break; |
| 2410 | |
| 2411 | case BFA_FCPORT_SM_STOP: |
| 2412 | bfa_sm_set_state(fcport, bfa_fcport_sm_stopped); |
| 2413 | break; |
| 2414 | |
| 2415 | case BFA_FCPORT_SM_LINKUP: |
| 2416 | case BFA_FCPORT_SM_LINKDOWN: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2417 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2418 | * Possible to get link events when doing back-to-back |
| 2419 | * enable/disables. |
| 2420 | */ |
| 2421 | break; |
| 2422 | |
| 2423 | case BFA_FCPORT_SM_HWFAIL: |
| 2424 | bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail); |
| 2425 | break; |
| 2426 | |
| 2427 | default: |
| 2428 | bfa_sm_fault(fcport->bfa, event); |
| 2429 | } |
| 2430 | } |
| 2431 | |
| 2432 | static void |
| 2433 | bfa_fcport_sm_disabled(struct bfa_fcport_s *fcport, |
| 2434 | enum bfa_fcport_sm_event event) |
| 2435 | { |
| 2436 | char pwwn_buf[BFA_STRING_32]; |
| 2437 | struct bfad_s *bfad = (struct bfad_s *)fcport->bfa->bfad; |
| 2438 | bfa_trc(fcport->bfa, event); |
| 2439 | |
| 2440 | switch (event) { |
| 2441 | case BFA_FCPORT_SM_START: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2442 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2443 | * Ignore start event for a port that is disabled. |
| 2444 | */ |
| 2445 | break; |
| 2446 | |
| 2447 | case BFA_FCPORT_SM_STOP: |
| 2448 | bfa_sm_set_state(fcport, bfa_fcport_sm_stopped); |
| 2449 | break; |
| 2450 | |
| 2451 | case BFA_FCPORT_SM_ENABLE: |
| 2452 | if (bfa_fcport_send_enable(fcport)) |
| 2453 | bfa_sm_set_state(fcport, bfa_fcport_sm_enabling); |
| 2454 | else |
| 2455 | bfa_sm_set_state(fcport, |
| 2456 | bfa_fcport_sm_enabling_qwait); |
| 2457 | |
| 2458 | bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL, |
| 2459 | BFA_PL_EID_PORT_ENABLE, 0, "Port Enable"); |
| 2460 | wwn2str(pwwn_buf, fcport->pwwn); |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 2461 | BFA_LOG(KERN_INFO, bfad, bfa_log_level, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2462 | "Base port enabled: WWN = %s\n", pwwn_buf); |
| 2463 | break; |
| 2464 | |
| 2465 | case BFA_FCPORT_SM_DISABLE: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2466 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2467 | * Already disabled. |
| 2468 | */ |
| 2469 | break; |
| 2470 | |
| 2471 | case BFA_FCPORT_SM_HWFAIL: |
| 2472 | bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail); |
| 2473 | break; |
| 2474 | |
| 2475 | default: |
| 2476 | bfa_sm_fault(fcport->bfa, event); |
| 2477 | } |
| 2478 | } |
| 2479 | |
| 2480 | static void |
| 2481 | bfa_fcport_sm_stopped(struct bfa_fcport_s *fcport, |
| 2482 | enum bfa_fcport_sm_event event) |
| 2483 | { |
| 2484 | bfa_trc(fcport->bfa, event); |
| 2485 | |
| 2486 | switch (event) { |
| 2487 | case BFA_FCPORT_SM_START: |
| 2488 | if (bfa_fcport_send_enable(fcport)) |
| 2489 | bfa_sm_set_state(fcport, bfa_fcport_sm_enabling); |
| 2490 | else |
| 2491 | bfa_sm_set_state(fcport, |
| 2492 | bfa_fcport_sm_enabling_qwait); |
| 2493 | break; |
| 2494 | |
| 2495 | default: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2496 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2497 | * Ignore all other events. |
| 2498 | */ |
| 2499 | ; |
| 2500 | } |
| 2501 | } |
| 2502 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2503 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2504 | * Port is enabled. IOC is down/failed. |
| 2505 | */ |
| 2506 | static void |
| 2507 | bfa_fcport_sm_iocdown(struct bfa_fcport_s *fcport, |
| 2508 | enum bfa_fcport_sm_event event) |
| 2509 | { |
| 2510 | bfa_trc(fcport->bfa, event); |
| 2511 | |
| 2512 | switch (event) { |
| 2513 | case BFA_FCPORT_SM_START: |
| 2514 | if (bfa_fcport_send_enable(fcport)) |
| 2515 | bfa_sm_set_state(fcport, bfa_fcport_sm_enabling); |
| 2516 | else |
| 2517 | bfa_sm_set_state(fcport, |
| 2518 | bfa_fcport_sm_enabling_qwait); |
| 2519 | break; |
| 2520 | |
| 2521 | default: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2522 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2523 | * Ignore all events. |
| 2524 | */ |
| 2525 | ; |
| 2526 | } |
| 2527 | } |
| 2528 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2529 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2530 | * Port is disabled. IOC is down/failed. |
| 2531 | */ |
| 2532 | static void |
| 2533 | bfa_fcport_sm_iocfail(struct bfa_fcport_s *fcport, |
| 2534 | enum bfa_fcport_sm_event event) |
| 2535 | { |
| 2536 | bfa_trc(fcport->bfa, event); |
| 2537 | |
| 2538 | switch (event) { |
| 2539 | case BFA_FCPORT_SM_START: |
| 2540 | bfa_sm_set_state(fcport, bfa_fcport_sm_disabled); |
| 2541 | break; |
| 2542 | |
| 2543 | case BFA_FCPORT_SM_ENABLE: |
| 2544 | bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown); |
| 2545 | break; |
| 2546 | |
| 2547 | default: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2548 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2549 | * Ignore all events. |
| 2550 | */ |
| 2551 | ; |
| 2552 | } |
| 2553 | } |
| 2554 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2555 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2556 | * Link state is down |
| 2557 | */ |
| 2558 | static void |
| 2559 | bfa_fcport_ln_sm_dn(struct bfa_fcport_ln_s *ln, |
| 2560 | enum bfa_fcport_ln_sm_event event) |
| 2561 | { |
| 2562 | bfa_trc(ln->fcport->bfa, event); |
| 2563 | |
| 2564 | switch (event) { |
| 2565 | case BFA_FCPORT_LN_SM_LINKUP: |
| 2566 | bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_nf); |
| 2567 | bfa_fcport_queue_cb(ln, BFA_PORT_LINKUP); |
| 2568 | break; |
| 2569 | |
| 2570 | default: |
| 2571 | bfa_sm_fault(ln->fcport->bfa, event); |
| 2572 | } |
| 2573 | } |
| 2574 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2575 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2576 | * Link state is waiting for down notification |
| 2577 | */ |
| 2578 | static void |
| 2579 | bfa_fcport_ln_sm_dn_nf(struct bfa_fcport_ln_s *ln, |
| 2580 | enum bfa_fcport_ln_sm_event event) |
| 2581 | { |
| 2582 | bfa_trc(ln->fcport->bfa, event); |
| 2583 | |
| 2584 | switch (event) { |
| 2585 | case BFA_FCPORT_LN_SM_LINKUP: |
| 2586 | bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_up_nf); |
| 2587 | break; |
| 2588 | |
| 2589 | case BFA_FCPORT_LN_SM_NOTIFICATION: |
| 2590 | bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn); |
| 2591 | break; |
| 2592 | |
| 2593 | default: |
| 2594 | bfa_sm_fault(ln->fcport->bfa, event); |
| 2595 | } |
| 2596 | } |
| 2597 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2598 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2599 | * Link state is waiting for down notification and there is a pending up |
| 2600 | */ |
| 2601 | static void |
| 2602 | bfa_fcport_ln_sm_dn_up_nf(struct bfa_fcport_ln_s *ln, |
| 2603 | enum bfa_fcport_ln_sm_event event) |
| 2604 | { |
| 2605 | bfa_trc(ln->fcport->bfa, event); |
| 2606 | |
| 2607 | switch (event) { |
| 2608 | case BFA_FCPORT_LN_SM_LINKDOWN: |
| 2609 | bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf); |
| 2610 | break; |
| 2611 | |
| 2612 | case BFA_FCPORT_LN_SM_NOTIFICATION: |
| 2613 | bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_nf); |
| 2614 | bfa_fcport_queue_cb(ln, BFA_PORT_LINKUP); |
| 2615 | break; |
| 2616 | |
| 2617 | default: |
| 2618 | bfa_sm_fault(ln->fcport->bfa, event); |
| 2619 | } |
| 2620 | } |
| 2621 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2622 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2623 | * Link state is up |
| 2624 | */ |
| 2625 | static void |
| 2626 | bfa_fcport_ln_sm_up(struct bfa_fcport_ln_s *ln, |
| 2627 | enum bfa_fcport_ln_sm_event event) |
| 2628 | { |
| 2629 | bfa_trc(ln->fcport->bfa, event); |
| 2630 | |
| 2631 | switch (event) { |
| 2632 | case BFA_FCPORT_LN_SM_LINKDOWN: |
| 2633 | bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf); |
| 2634 | bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN); |
| 2635 | break; |
| 2636 | |
| 2637 | default: |
| 2638 | bfa_sm_fault(ln->fcport->bfa, event); |
| 2639 | } |
| 2640 | } |
| 2641 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2642 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2643 | * Link state is waiting for up notification |
| 2644 | */ |
| 2645 | static void |
| 2646 | bfa_fcport_ln_sm_up_nf(struct bfa_fcport_ln_s *ln, |
| 2647 | enum bfa_fcport_ln_sm_event event) |
| 2648 | { |
| 2649 | bfa_trc(ln->fcport->bfa, event); |
| 2650 | |
| 2651 | switch (event) { |
| 2652 | case BFA_FCPORT_LN_SM_LINKDOWN: |
| 2653 | bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_nf); |
| 2654 | break; |
| 2655 | |
| 2656 | case BFA_FCPORT_LN_SM_NOTIFICATION: |
| 2657 | bfa_sm_set_state(ln, bfa_fcport_ln_sm_up); |
| 2658 | break; |
| 2659 | |
| 2660 | default: |
| 2661 | bfa_sm_fault(ln->fcport->bfa, event); |
| 2662 | } |
| 2663 | } |
| 2664 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2665 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2666 | * Link state is waiting for up notification and there is a pending down |
| 2667 | */ |
| 2668 | static void |
| 2669 | bfa_fcport_ln_sm_up_dn_nf(struct bfa_fcport_ln_s *ln, |
| 2670 | enum bfa_fcport_ln_sm_event event) |
| 2671 | { |
| 2672 | bfa_trc(ln->fcport->bfa, event); |
| 2673 | |
| 2674 | switch (event) { |
| 2675 | case BFA_FCPORT_LN_SM_LINKUP: |
| 2676 | bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_up_nf); |
| 2677 | break; |
| 2678 | |
| 2679 | case BFA_FCPORT_LN_SM_NOTIFICATION: |
| 2680 | bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf); |
| 2681 | bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN); |
| 2682 | break; |
| 2683 | |
| 2684 | default: |
| 2685 | bfa_sm_fault(ln->fcport->bfa, event); |
| 2686 | } |
| 2687 | } |
| 2688 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2689 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2690 | * Link state is waiting for up notification and there are pending down and up |
| 2691 | */ |
| 2692 | static void |
| 2693 | bfa_fcport_ln_sm_up_dn_up_nf(struct bfa_fcport_ln_s *ln, |
| 2694 | enum bfa_fcport_ln_sm_event event) |
| 2695 | { |
| 2696 | bfa_trc(ln->fcport->bfa, event); |
| 2697 | |
| 2698 | switch (event) { |
| 2699 | case BFA_FCPORT_LN_SM_LINKDOWN: |
| 2700 | bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_nf); |
| 2701 | break; |
| 2702 | |
| 2703 | case BFA_FCPORT_LN_SM_NOTIFICATION: |
| 2704 | bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_up_nf); |
| 2705 | bfa_fcport_queue_cb(ln, BFA_PORT_LINKDOWN); |
| 2706 | break; |
| 2707 | |
| 2708 | default: |
| 2709 | bfa_sm_fault(ln->fcport->bfa, event); |
| 2710 | } |
| 2711 | } |
| 2712 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2713 | static void |
| 2714 | __bfa_cb_fcport_event(void *cbarg, bfa_boolean_t complete) |
| 2715 | { |
| 2716 | struct bfa_fcport_ln_s *ln = cbarg; |
| 2717 | |
| 2718 | if (complete) |
| 2719 | ln->fcport->event_cbfn(ln->fcport->event_cbarg, ln->ln_event); |
| 2720 | else |
| 2721 | bfa_sm_send_event(ln, BFA_FCPORT_LN_SM_NOTIFICATION); |
| 2722 | } |
| 2723 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2724 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2725 | * Send SCN notification to upper layers. |
| 2726 | * trunk - false if caller is fcport to ignore fcport event in trunked mode |
| 2727 | */ |
| 2728 | static void |
| 2729 | bfa_fcport_scn(struct bfa_fcport_s *fcport, enum bfa_port_linkstate event, |
| 2730 | bfa_boolean_t trunk) |
| 2731 | { |
| 2732 | if (fcport->cfg.trunked && !trunk) |
| 2733 | return; |
| 2734 | |
| 2735 | switch (event) { |
| 2736 | case BFA_PORT_LINKUP: |
| 2737 | bfa_sm_send_event(&fcport->ln, BFA_FCPORT_LN_SM_LINKUP); |
| 2738 | break; |
| 2739 | case BFA_PORT_LINKDOWN: |
| 2740 | bfa_sm_send_event(&fcport->ln, BFA_FCPORT_LN_SM_LINKDOWN); |
| 2741 | break; |
| 2742 | default: |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 2743 | WARN_ON(1); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2744 | } |
| 2745 | } |
| 2746 | |
| 2747 | static void |
| 2748 | bfa_fcport_queue_cb(struct bfa_fcport_ln_s *ln, enum bfa_port_linkstate event) |
| 2749 | { |
| 2750 | struct bfa_fcport_s *fcport = ln->fcport; |
| 2751 | |
| 2752 | if (fcport->bfa->fcs) { |
| 2753 | fcport->event_cbfn(fcport->event_cbarg, event); |
| 2754 | bfa_sm_send_event(ln, BFA_FCPORT_LN_SM_NOTIFICATION); |
| 2755 | } else { |
| 2756 | ln->ln_event = event; |
| 2757 | bfa_cb_queue(fcport->bfa, &ln->ln_qe, |
| 2758 | __bfa_cb_fcport_event, ln); |
| 2759 | } |
| 2760 | } |
| 2761 | |
| 2762 | #define FCPORT_STATS_DMA_SZ (BFA_ROUNDUP(sizeof(union bfa_fcport_stats_u), \ |
| 2763 | BFA_CACHELINE_SZ)) |
| 2764 | |
| 2765 | static void |
| 2766 | bfa_fcport_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *ndm_len, |
| 2767 | u32 *dm_len) |
| 2768 | { |
| 2769 | *dm_len += FCPORT_STATS_DMA_SZ; |
| 2770 | } |
| 2771 | |
| 2772 | static void |
| 2773 | bfa_fcport_qresume(void *cbarg) |
| 2774 | { |
| 2775 | struct bfa_fcport_s *fcport = cbarg; |
| 2776 | |
| 2777 | bfa_sm_send_event(fcport, BFA_FCPORT_SM_QRESUME); |
| 2778 | } |
| 2779 | |
| 2780 | static void |
| 2781 | bfa_fcport_mem_claim(struct bfa_fcport_s *fcport, struct bfa_meminfo_s *meminfo) |
| 2782 | { |
| 2783 | u8 *dm_kva; |
| 2784 | u64 dm_pa; |
| 2785 | |
| 2786 | dm_kva = bfa_meminfo_dma_virt(meminfo); |
| 2787 | dm_pa = bfa_meminfo_dma_phys(meminfo); |
| 2788 | |
| 2789 | fcport->stats_kva = dm_kva; |
| 2790 | fcport->stats_pa = dm_pa; |
| 2791 | fcport->stats = (union bfa_fcport_stats_u *) dm_kva; |
| 2792 | |
| 2793 | dm_kva += FCPORT_STATS_DMA_SZ; |
| 2794 | dm_pa += FCPORT_STATS_DMA_SZ; |
| 2795 | |
| 2796 | bfa_meminfo_dma_virt(meminfo) = dm_kva; |
| 2797 | bfa_meminfo_dma_phys(meminfo) = dm_pa; |
| 2798 | } |
| 2799 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2800 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2801 | * Memory initialization. |
| 2802 | */ |
| 2803 | static void |
| 2804 | bfa_fcport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg, |
| 2805 | struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev) |
| 2806 | { |
| 2807 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 2808 | struct bfa_port_cfg_s *port_cfg = &fcport->cfg; |
| 2809 | struct bfa_fcport_ln_s *ln = &fcport->ln; |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 2810 | struct timeval tv; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2811 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 2812 | memset(fcport, 0, sizeof(struct bfa_fcport_s)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2813 | fcport->bfa = bfa; |
| 2814 | ln->fcport = fcport; |
| 2815 | |
| 2816 | bfa_fcport_mem_claim(fcport, meminfo); |
| 2817 | |
| 2818 | bfa_sm_set_state(fcport, bfa_fcport_sm_uninit); |
| 2819 | bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn); |
| 2820 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2821 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2822 | * initialize time stamp for stats reset |
| 2823 | */ |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 2824 | do_gettimeofday(&tv); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2825 | fcport->stats_reset_time = tv.tv_sec; |
| 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 | * initialize and set default configuration |
| 2829 | */ |
| 2830 | port_cfg->topology = BFA_PORT_TOPOLOGY_P2P; |
| 2831 | port_cfg->speed = BFA_PORT_SPEED_AUTO; |
| 2832 | port_cfg->trunked = BFA_FALSE; |
| 2833 | port_cfg->maxfrsize = 0; |
| 2834 | |
| 2835 | port_cfg->trl_def_speed = BFA_PORT_SPEED_1GBPS; |
| 2836 | |
| 2837 | bfa_reqq_winit(&fcport->reqq_wait, bfa_fcport_qresume, fcport); |
| 2838 | } |
| 2839 | |
| 2840 | static void |
| 2841 | bfa_fcport_detach(struct bfa_s *bfa) |
| 2842 | { |
| 2843 | } |
| 2844 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2845 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2846 | * Called when IOC is ready. |
| 2847 | */ |
| 2848 | static void |
| 2849 | bfa_fcport_start(struct bfa_s *bfa) |
| 2850 | { |
| 2851 | bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_START); |
| 2852 | } |
| 2853 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2854 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2855 | * Called before IOC is stopped. |
| 2856 | */ |
| 2857 | static void |
| 2858 | bfa_fcport_stop(struct bfa_s *bfa) |
| 2859 | { |
| 2860 | bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_STOP); |
| 2861 | bfa_trunk_iocdisable(bfa); |
| 2862 | } |
| 2863 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2864 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2865 | * Called when IOC failure is detected. |
| 2866 | */ |
| 2867 | static void |
| 2868 | bfa_fcport_iocdisable(struct bfa_s *bfa) |
| 2869 | { |
| 2870 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 2871 | |
| 2872 | bfa_sm_send_event(fcport, BFA_FCPORT_SM_HWFAIL); |
| 2873 | bfa_trunk_iocdisable(bfa); |
| 2874 | } |
| 2875 | |
| 2876 | static void |
| 2877 | bfa_fcport_update_linkinfo(struct bfa_fcport_s *fcport) |
| 2878 | { |
| 2879 | struct bfi_fcport_event_s *pevent = fcport->event_arg.i2hmsg.event; |
| 2880 | struct bfa_fcport_trunk_s *trunk = &fcport->trunk; |
| 2881 | |
| 2882 | fcport->speed = pevent->link_state.speed; |
| 2883 | fcport->topology = pevent->link_state.topology; |
| 2884 | |
| 2885 | if (fcport->topology == BFA_PORT_TOPOLOGY_LOOP) |
| 2886 | fcport->myalpa = 0; |
| 2887 | |
| 2888 | /* QoS Details */ |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 2889 | fcport->qos_attr = pevent->link_state.qos_attr; |
| 2890 | fcport->qos_vc_attr = pevent->link_state.vc_fcf.qos_vc_attr; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2891 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2892 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2893 | * update trunk state if applicable |
| 2894 | */ |
| 2895 | if (!fcport->cfg.trunked) |
| 2896 | trunk->attr.state = BFA_TRUNK_DISABLED; |
| 2897 | |
| 2898 | /* update FCoE specific */ |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 2899 | fcport->fcoe_vlan = be16_to_cpu(pevent->link_state.vc_fcf.fcf.vlan); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2900 | |
| 2901 | bfa_trc(fcport->bfa, fcport->speed); |
| 2902 | bfa_trc(fcport->bfa, fcport->topology); |
| 2903 | } |
| 2904 | |
| 2905 | static void |
| 2906 | bfa_fcport_reset_linkinfo(struct bfa_fcport_s *fcport) |
| 2907 | { |
| 2908 | fcport->speed = BFA_PORT_SPEED_UNKNOWN; |
| 2909 | fcport->topology = BFA_PORT_TOPOLOGY_NONE; |
Krishna Gudipati | be540a9 | 2011-06-13 15:53:04 -0700 | [diff] [blame] | 2910 | fcport->bbsc_op_state = BFA_FALSE; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2911 | } |
| 2912 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2913 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2914 | * Send port enable message to firmware. |
| 2915 | */ |
| 2916 | static bfa_boolean_t |
| 2917 | bfa_fcport_send_enable(struct bfa_fcport_s *fcport) |
| 2918 | { |
| 2919 | struct bfi_fcport_enable_req_s *m; |
| 2920 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2921 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2922 | * Increment message tag before queue check, so that responses to old |
| 2923 | * requests are discarded. |
| 2924 | */ |
| 2925 | fcport->msgtag++; |
| 2926 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2927 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2928 | * check for room in queue to send request now |
| 2929 | */ |
| 2930 | m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT); |
| 2931 | if (!m) { |
| 2932 | bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT, |
| 2933 | &fcport->reqq_wait); |
| 2934 | return BFA_FALSE; |
| 2935 | } |
| 2936 | |
| 2937 | bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_ENABLE_REQ, |
| 2938 | bfa_lpuid(fcport->bfa)); |
| 2939 | m->nwwn = fcport->nwwn; |
| 2940 | m->pwwn = fcport->pwwn; |
| 2941 | m->port_cfg = fcport->cfg; |
| 2942 | m->msgtag = fcport->msgtag; |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 2943 | m->port_cfg.maxfrsize = cpu_to_be16(fcport->cfg.maxfrsize); |
Krishna Gudipati | f3a060c | 2010-12-13 16:16:50 -0800 | [diff] [blame] | 2944 | m->use_flash_cfg = fcport->use_flash_cfg; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2945 | bfa_dma_be_addr_set(m->stats_dma_addr, fcport->stats_pa); |
| 2946 | bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_lo); |
| 2947 | bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_hi); |
| 2948 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2949 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2950 | * queue I/O message to firmware |
| 2951 | */ |
| 2952 | bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT); |
| 2953 | return BFA_TRUE; |
| 2954 | } |
| 2955 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2956 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2957 | * Send port disable message to firmware. |
| 2958 | */ |
| 2959 | static bfa_boolean_t |
| 2960 | bfa_fcport_send_disable(struct bfa_fcport_s *fcport) |
| 2961 | { |
| 2962 | struct bfi_fcport_req_s *m; |
| 2963 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2964 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2965 | * Increment message tag before queue check, so that responses to old |
| 2966 | * requests are discarded. |
| 2967 | */ |
| 2968 | fcport->msgtag++; |
| 2969 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2970 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2971 | * check for room in queue to send request now |
| 2972 | */ |
| 2973 | m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT); |
| 2974 | if (!m) { |
| 2975 | bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT, |
| 2976 | &fcport->reqq_wait); |
| 2977 | return BFA_FALSE; |
| 2978 | } |
| 2979 | |
| 2980 | bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_DISABLE_REQ, |
| 2981 | bfa_lpuid(fcport->bfa)); |
| 2982 | m->msgtag = fcport->msgtag; |
| 2983 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2984 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2985 | * queue I/O message to firmware |
| 2986 | */ |
| 2987 | bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT); |
| 2988 | |
| 2989 | return BFA_TRUE; |
| 2990 | } |
| 2991 | |
| 2992 | static void |
| 2993 | bfa_fcport_set_wwns(struct bfa_fcport_s *fcport) |
| 2994 | { |
Maggie Zhang | f7f7381 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 2995 | fcport->pwwn = fcport->bfa->ioc.attr->pwwn; |
| 2996 | fcport->nwwn = fcport->bfa->ioc.attr->nwwn; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2997 | |
| 2998 | bfa_trc(fcport->bfa, fcport->pwwn); |
| 2999 | bfa_trc(fcport->bfa, fcport->nwwn); |
| 3000 | } |
| 3001 | |
| 3002 | static void |
| 3003 | bfa_fcport_send_txcredit(void *port_cbarg) |
| 3004 | { |
| 3005 | |
| 3006 | struct bfa_fcport_s *fcport = port_cbarg; |
| 3007 | struct bfi_fcport_set_svc_params_req_s *m; |
| 3008 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3009 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3010 | * check for room in queue to send request now |
| 3011 | */ |
| 3012 | m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT); |
| 3013 | if (!m) { |
| 3014 | bfa_trc(fcport->bfa, fcport->cfg.tx_bbcredit); |
| 3015 | return; |
| 3016 | } |
| 3017 | |
| 3018 | bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_SET_SVC_PARAMS_REQ, |
| 3019 | bfa_lpuid(fcport->bfa)); |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 3020 | m->tx_bbcredit = cpu_to_be16((u16)fcport->cfg.tx_bbcredit); |
Krishna Gudipati | be540a9 | 2011-06-13 15:53:04 -0700 | [diff] [blame] | 3021 | m->bb_scn = fcport->cfg.bb_scn; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3022 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3023 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3024 | * queue I/O message to firmware |
| 3025 | */ |
| 3026 | bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT); |
| 3027 | } |
| 3028 | |
| 3029 | static void |
| 3030 | bfa_fcport_qos_stats_swap(struct bfa_qos_stats_s *d, |
| 3031 | struct bfa_qos_stats_s *s) |
| 3032 | { |
| 3033 | u32 *dip = (u32 *) d; |
Maggie | 50444a3 | 2010-11-29 18:26:32 -0800 | [diff] [blame] | 3034 | __be32 *sip = (__be32 *) s; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3035 | int i; |
| 3036 | |
| 3037 | /* Now swap the 32 bit fields */ |
| 3038 | 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] | 3039 | dip[i] = be32_to_cpu(sip[i]); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3040 | } |
| 3041 | |
| 3042 | static void |
| 3043 | bfa_fcport_fcoe_stats_swap(struct bfa_fcoe_stats_s *d, |
| 3044 | struct bfa_fcoe_stats_s *s) |
| 3045 | { |
| 3046 | u32 *dip = (u32 *) d; |
Maggie | 50444a3 | 2010-11-29 18:26:32 -0800 | [diff] [blame] | 3047 | __be32 *sip = (__be32 *) s; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3048 | int i; |
| 3049 | |
| 3050 | for (i = 0; i < ((sizeof(struct bfa_fcoe_stats_s))/sizeof(u32)); |
| 3051 | i = i + 2) { |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 3052 | #ifdef __BIG_ENDIAN |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 3053 | dip[i] = be32_to_cpu(sip[i]); |
| 3054 | dip[i + 1] = be32_to_cpu(sip[i + 1]); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3055 | #else |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 3056 | dip[i] = be32_to_cpu(sip[i + 1]); |
| 3057 | dip[i + 1] = be32_to_cpu(sip[i]); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3058 | #endif |
| 3059 | } |
| 3060 | } |
| 3061 | |
| 3062 | static void |
| 3063 | __bfa_cb_fcport_stats_get(void *cbarg, bfa_boolean_t complete) |
| 3064 | { |
| 3065 | struct bfa_fcport_s *fcport = cbarg; |
| 3066 | |
| 3067 | if (complete) { |
| 3068 | if (fcport->stats_status == BFA_STATUS_OK) { |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 3069 | struct timeval tv; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3070 | |
| 3071 | /* Swap FC QoS or FCoE stats */ |
| 3072 | if (bfa_ioc_get_fcmode(&fcport->bfa->ioc)) { |
| 3073 | bfa_fcport_qos_stats_swap( |
| 3074 | &fcport->stats_ret->fcqos, |
| 3075 | &fcport->stats->fcqos); |
| 3076 | } else { |
| 3077 | bfa_fcport_fcoe_stats_swap( |
| 3078 | &fcport->stats_ret->fcoe, |
| 3079 | &fcport->stats->fcoe); |
| 3080 | |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 3081 | do_gettimeofday(&tv); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3082 | fcport->stats_ret->fcoe.secs_reset = |
| 3083 | tv.tv_sec - fcport->stats_reset_time; |
| 3084 | } |
| 3085 | } |
| 3086 | fcport->stats_cbfn(fcport->stats_cbarg, fcport->stats_status); |
| 3087 | } else { |
| 3088 | fcport->stats_busy = BFA_FALSE; |
| 3089 | fcport->stats_status = BFA_STATUS_OK; |
| 3090 | } |
| 3091 | } |
| 3092 | |
| 3093 | static void |
| 3094 | bfa_fcport_stats_get_timeout(void *cbarg) |
| 3095 | { |
| 3096 | struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg; |
| 3097 | |
| 3098 | bfa_trc(fcport->bfa, fcport->stats_qfull); |
| 3099 | |
| 3100 | if (fcport->stats_qfull) { |
| 3101 | bfa_reqq_wcancel(&fcport->stats_reqq_wait); |
| 3102 | fcport->stats_qfull = BFA_FALSE; |
| 3103 | } |
| 3104 | |
| 3105 | fcport->stats_status = BFA_STATUS_ETIMER; |
| 3106 | bfa_cb_queue(fcport->bfa, &fcport->hcb_qe, __bfa_cb_fcport_stats_get, |
| 3107 | fcport); |
| 3108 | } |
| 3109 | |
| 3110 | static void |
| 3111 | bfa_fcport_send_stats_get(void *cbarg) |
| 3112 | { |
| 3113 | struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg; |
| 3114 | struct bfi_fcport_req_s *msg; |
| 3115 | |
| 3116 | msg = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT); |
| 3117 | |
| 3118 | if (!msg) { |
| 3119 | fcport->stats_qfull = BFA_TRUE; |
| 3120 | bfa_reqq_winit(&fcport->stats_reqq_wait, |
| 3121 | bfa_fcport_send_stats_get, fcport); |
| 3122 | bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT, |
| 3123 | &fcport->stats_reqq_wait); |
| 3124 | return; |
| 3125 | } |
| 3126 | fcport->stats_qfull = BFA_FALSE; |
| 3127 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 3128 | memset(msg, 0, sizeof(struct bfi_fcport_req_s)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3129 | bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_GET_REQ, |
| 3130 | bfa_lpuid(fcport->bfa)); |
| 3131 | bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT); |
| 3132 | } |
| 3133 | |
| 3134 | static void |
| 3135 | __bfa_cb_fcport_stats_clr(void *cbarg, bfa_boolean_t complete) |
| 3136 | { |
| 3137 | struct bfa_fcport_s *fcport = cbarg; |
| 3138 | |
| 3139 | if (complete) { |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 3140 | struct timeval tv; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3141 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3142 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3143 | * re-initialize time stamp for stats reset |
| 3144 | */ |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 3145 | do_gettimeofday(&tv); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3146 | fcport->stats_reset_time = tv.tv_sec; |
| 3147 | |
| 3148 | fcport->stats_cbfn(fcport->stats_cbarg, fcport->stats_status); |
| 3149 | } else { |
| 3150 | fcport->stats_busy = BFA_FALSE; |
| 3151 | fcport->stats_status = BFA_STATUS_OK; |
| 3152 | } |
| 3153 | } |
| 3154 | |
| 3155 | static void |
| 3156 | bfa_fcport_stats_clr_timeout(void *cbarg) |
| 3157 | { |
| 3158 | struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg; |
| 3159 | |
| 3160 | bfa_trc(fcport->bfa, fcport->stats_qfull); |
| 3161 | |
| 3162 | if (fcport->stats_qfull) { |
| 3163 | bfa_reqq_wcancel(&fcport->stats_reqq_wait); |
| 3164 | fcport->stats_qfull = BFA_FALSE; |
| 3165 | } |
| 3166 | |
| 3167 | fcport->stats_status = BFA_STATUS_ETIMER; |
| 3168 | bfa_cb_queue(fcport->bfa, &fcport->hcb_qe, |
| 3169 | __bfa_cb_fcport_stats_clr, fcport); |
| 3170 | } |
| 3171 | |
| 3172 | static void |
| 3173 | bfa_fcport_send_stats_clear(void *cbarg) |
| 3174 | { |
| 3175 | struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg; |
| 3176 | struct bfi_fcport_req_s *msg; |
| 3177 | |
| 3178 | msg = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT); |
| 3179 | |
| 3180 | if (!msg) { |
| 3181 | fcport->stats_qfull = BFA_TRUE; |
| 3182 | bfa_reqq_winit(&fcport->stats_reqq_wait, |
| 3183 | bfa_fcport_send_stats_clear, fcport); |
| 3184 | bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT, |
| 3185 | &fcport->stats_reqq_wait); |
| 3186 | return; |
| 3187 | } |
| 3188 | fcport->stats_qfull = BFA_FALSE; |
| 3189 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 3190 | memset(msg, 0, sizeof(struct bfi_fcport_req_s)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3191 | bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_CLEAR_REQ, |
| 3192 | bfa_lpuid(fcport->bfa)); |
| 3193 | bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT); |
| 3194 | } |
| 3195 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3196 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3197 | * Handle trunk SCN event from firmware. |
| 3198 | */ |
| 3199 | static void |
| 3200 | bfa_trunk_scn(struct bfa_fcport_s *fcport, struct bfi_fcport_trunk_scn_s *scn) |
| 3201 | { |
| 3202 | struct bfa_fcport_trunk_s *trunk = &fcport->trunk; |
| 3203 | struct bfi_fcport_trunk_link_s *tlink; |
| 3204 | struct bfa_trunk_link_attr_s *lattr; |
| 3205 | enum bfa_trunk_state state_prev; |
| 3206 | int i; |
| 3207 | int link_bm = 0; |
| 3208 | |
| 3209 | bfa_trc(fcport->bfa, fcport->cfg.trunked); |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 3210 | WARN_ON(scn->trunk_state != BFA_TRUNK_ONLINE && |
| 3211 | scn->trunk_state != BFA_TRUNK_OFFLINE); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3212 | |
| 3213 | bfa_trc(fcport->bfa, trunk->attr.state); |
| 3214 | bfa_trc(fcport->bfa, scn->trunk_state); |
| 3215 | bfa_trc(fcport->bfa, scn->trunk_speed); |
| 3216 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3217 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3218 | * Save off new state for trunk attribute query |
| 3219 | */ |
| 3220 | state_prev = trunk->attr.state; |
| 3221 | if (fcport->cfg.trunked && (trunk->attr.state != BFA_TRUNK_DISABLED)) |
| 3222 | trunk->attr.state = scn->trunk_state; |
| 3223 | trunk->attr.speed = scn->trunk_speed; |
| 3224 | for (i = 0; i < BFA_TRUNK_MAX_PORTS; i++) { |
| 3225 | lattr = &trunk->attr.link_attr[i]; |
| 3226 | tlink = &scn->tlink[i]; |
| 3227 | |
| 3228 | lattr->link_state = tlink->state; |
| 3229 | lattr->trunk_wwn = tlink->trunk_wwn; |
| 3230 | lattr->fctl = tlink->fctl; |
| 3231 | lattr->speed = tlink->speed; |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 3232 | lattr->deskew = be32_to_cpu(tlink->deskew); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3233 | |
| 3234 | if (tlink->state == BFA_TRUNK_LINK_STATE_UP) { |
| 3235 | fcport->speed = tlink->speed; |
| 3236 | fcport->topology = BFA_PORT_TOPOLOGY_P2P; |
| 3237 | link_bm |= 1 << i; |
| 3238 | } |
| 3239 | |
| 3240 | bfa_trc(fcport->bfa, lattr->link_state); |
| 3241 | bfa_trc(fcport->bfa, lattr->trunk_wwn); |
| 3242 | bfa_trc(fcport->bfa, lattr->fctl); |
| 3243 | bfa_trc(fcport->bfa, lattr->speed); |
| 3244 | bfa_trc(fcport->bfa, lattr->deskew); |
| 3245 | } |
| 3246 | |
| 3247 | switch (link_bm) { |
| 3248 | case 3: |
| 3249 | bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL, |
| 3250 | BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(0,1)"); |
| 3251 | break; |
| 3252 | case 2: |
| 3253 | bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL, |
| 3254 | BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(-,1)"); |
| 3255 | break; |
| 3256 | case 1: |
| 3257 | bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL, |
| 3258 | BFA_PL_EID_TRUNK_SCN, 0, "Trunk up(0,-)"); |
| 3259 | break; |
| 3260 | default: |
| 3261 | bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL, |
| 3262 | BFA_PL_EID_TRUNK_SCN, 0, "Trunk down"); |
| 3263 | } |
| 3264 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3265 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3266 | * Notify upper layers if trunk state changed. |
| 3267 | */ |
| 3268 | if ((state_prev != trunk->attr.state) || |
| 3269 | (scn->trunk_state == BFA_TRUNK_OFFLINE)) { |
| 3270 | bfa_fcport_scn(fcport, (scn->trunk_state == BFA_TRUNK_ONLINE) ? |
| 3271 | BFA_PORT_LINKUP : BFA_PORT_LINKDOWN, BFA_TRUE); |
| 3272 | } |
| 3273 | } |
| 3274 | |
| 3275 | static void |
| 3276 | bfa_trunk_iocdisable(struct bfa_s *bfa) |
| 3277 | { |
| 3278 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3279 | int i = 0; |
| 3280 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3281 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3282 | * In trunked mode, notify upper layers that link is down |
| 3283 | */ |
| 3284 | if (fcport->cfg.trunked) { |
| 3285 | if (fcport->trunk.attr.state == BFA_TRUNK_ONLINE) |
| 3286 | bfa_fcport_scn(fcport, BFA_PORT_LINKDOWN, BFA_TRUE); |
| 3287 | |
| 3288 | fcport->trunk.attr.state = BFA_TRUNK_OFFLINE; |
| 3289 | fcport->trunk.attr.speed = BFA_PORT_SPEED_UNKNOWN; |
| 3290 | for (i = 0; i < BFA_TRUNK_MAX_PORTS; i++) { |
| 3291 | fcport->trunk.attr.link_attr[i].trunk_wwn = 0; |
| 3292 | fcport->trunk.attr.link_attr[i].fctl = |
| 3293 | BFA_TRUNK_LINK_FCTL_NORMAL; |
| 3294 | fcport->trunk.attr.link_attr[i].link_state = |
| 3295 | BFA_TRUNK_LINK_STATE_DN_LINKDN; |
| 3296 | fcport->trunk.attr.link_attr[i].speed = |
| 3297 | BFA_PORT_SPEED_UNKNOWN; |
| 3298 | fcport->trunk.attr.link_attr[i].deskew = 0; |
| 3299 | } |
| 3300 | } |
| 3301 | } |
| 3302 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3303 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3304 | * Called to initialize port attributes |
| 3305 | */ |
| 3306 | void |
| 3307 | bfa_fcport_init(struct bfa_s *bfa) |
| 3308 | { |
| 3309 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3310 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3311 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3312 | * Initialize port attributes from IOC hardware data. |
| 3313 | */ |
| 3314 | bfa_fcport_set_wwns(fcport); |
| 3315 | if (fcport->cfg.maxfrsize == 0) |
| 3316 | fcport->cfg.maxfrsize = bfa_ioc_maxfrsize(&bfa->ioc); |
| 3317 | fcport->cfg.rx_bbcredit = bfa_ioc_rx_bbcredit(&bfa->ioc); |
| 3318 | fcport->speed_sup = bfa_ioc_speed_sup(&bfa->ioc); |
| 3319 | |
Krishna Gudipati | 43ffdf4 | 2011-06-13 15:46:21 -0700 | [diff] [blame] | 3320 | if (bfa_fcport_is_pbcdisabled(bfa)) |
| 3321 | bfa->modules.port.pbc_disabled = BFA_TRUE; |
| 3322 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 3323 | WARN_ON(!fcport->cfg.maxfrsize); |
| 3324 | WARN_ON(!fcport->cfg.rx_bbcredit); |
| 3325 | WARN_ON(!fcport->speed_sup); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3326 | } |
| 3327 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3328 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3329 | * Firmware message handler. |
| 3330 | */ |
| 3331 | void |
| 3332 | bfa_fcport_isr(struct bfa_s *bfa, struct bfi_msg_s *msg) |
| 3333 | { |
| 3334 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3335 | union bfi_fcport_i2h_msg_u i2hmsg; |
| 3336 | |
| 3337 | i2hmsg.msg = msg; |
| 3338 | fcport->event_arg.i2hmsg = i2hmsg; |
| 3339 | |
| 3340 | bfa_trc(bfa, msg->mhdr.msg_id); |
| 3341 | bfa_trc(bfa, bfa_sm_to_state(hal_port_sm_table, fcport->sm)); |
| 3342 | |
| 3343 | switch (msg->mhdr.msg_id) { |
| 3344 | case BFI_FCPORT_I2H_ENABLE_RSP: |
Krishna Gudipati | f3a060c | 2010-12-13 16:16:50 -0800 | [diff] [blame] | 3345 | if (fcport->msgtag == i2hmsg.penable_rsp->msgtag) { |
| 3346 | |
| 3347 | if (fcport->use_flash_cfg) { |
| 3348 | fcport->cfg = i2hmsg.penable_rsp->port_cfg; |
| 3349 | fcport->cfg.maxfrsize = |
| 3350 | cpu_to_be16(fcport->cfg.maxfrsize); |
| 3351 | fcport->cfg.path_tov = |
| 3352 | cpu_to_be16(fcport->cfg.path_tov); |
| 3353 | fcport->cfg.q_depth = |
| 3354 | cpu_to_be16(fcport->cfg.q_depth); |
| 3355 | |
| 3356 | if (fcport->cfg.trunked) |
| 3357 | fcport->trunk.attr.state = |
| 3358 | BFA_TRUNK_OFFLINE; |
| 3359 | else |
| 3360 | fcport->trunk.attr.state = |
| 3361 | BFA_TRUNK_DISABLED; |
| 3362 | fcport->use_flash_cfg = BFA_FALSE; |
| 3363 | } |
| 3364 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3365 | bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP); |
Krishna Gudipati | f3a060c | 2010-12-13 16:16:50 -0800 | [diff] [blame] | 3366 | } |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3367 | break; |
| 3368 | |
| 3369 | case BFI_FCPORT_I2H_DISABLE_RSP: |
| 3370 | if (fcport->msgtag == i2hmsg.penable_rsp->msgtag) |
| 3371 | bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP); |
| 3372 | break; |
| 3373 | |
| 3374 | case BFI_FCPORT_I2H_EVENT: |
| 3375 | if (i2hmsg.event->link_state.linkstate == BFA_PORT_LINKUP) |
| 3376 | bfa_sm_send_event(fcport, BFA_FCPORT_SM_LINKUP); |
| 3377 | else |
| 3378 | bfa_sm_send_event(fcport, BFA_FCPORT_SM_LINKDOWN); |
| 3379 | break; |
| 3380 | |
| 3381 | case BFI_FCPORT_I2H_TRUNK_SCN: |
| 3382 | bfa_trunk_scn(fcport, i2hmsg.trunk_scn); |
| 3383 | break; |
| 3384 | |
| 3385 | case BFI_FCPORT_I2H_STATS_GET_RSP: |
| 3386 | /* |
| 3387 | * check for timer pop before processing the rsp |
| 3388 | */ |
| 3389 | if (fcport->stats_busy == BFA_FALSE || |
| 3390 | fcport->stats_status == BFA_STATUS_ETIMER) |
| 3391 | break; |
| 3392 | |
| 3393 | bfa_timer_stop(&fcport->timer); |
| 3394 | fcport->stats_status = i2hmsg.pstatsget_rsp->status; |
| 3395 | bfa_cb_queue(fcport->bfa, &fcport->hcb_qe, |
| 3396 | __bfa_cb_fcport_stats_get, fcport); |
| 3397 | break; |
| 3398 | |
| 3399 | case BFI_FCPORT_I2H_STATS_CLEAR_RSP: |
| 3400 | /* |
| 3401 | * check for timer pop before processing the rsp |
| 3402 | */ |
| 3403 | if (fcport->stats_busy == BFA_FALSE || |
| 3404 | fcport->stats_status == BFA_STATUS_ETIMER) |
| 3405 | break; |
| 3406 | |
| 3407 | bfa_timer_stop(&fcport->timer); |
| 3408 | fcport->stats_status = BFA_STATUS_OK; |
| 3409 | bfa_cb_queue(fcport->bfa, &fcport->hcb_qe, |
| 3410 | __bfa_cb_fcport_stats_clr, fcport); |
| 3411 | break; |
| 3412 | |
| 3413 | case BFI_FCPORT_I2H_ENABLE_AEN: |
| 3414 | bfa_sm_send_event(fcport, BFA_FCPORT_SM_ENABLE); |
| 3415 | break; |
| 3416 | |
| 3417 | case BFI_FCPORT_I2H_DISABLE_AEN: |
| 3418 | bfa_sm_send_event(fcport, BFA_FCPORT_SM_DISABLE); |
| 3419 | break; |
| 3420 | |
| 3421 | default: |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 3422 | WARN_ON(1); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3423 | break; |
| 3424 | } |
| 3425 | } |
| 3426 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3427 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3428 | * Registered callback for port events. |
| 3429 | */ |
| 3430 | void |
| 3431 | bfa_fcport_event_register(struct bfa_s *bfa, |
| 3432 | void (*cbfn) (void *cbarg, |
| 3433 | enum bfa_port_linkstate event), |
| 3434 | void *cbarg) |
| 3435 | { |
| 3436 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3437 | |
| 3438 | fcport->event_cbfn = cbfn; |
| 3439 | fcport->event_cbarg = cbarg; |
| 3440 | } |
| 3441 | |
| 3442 | bfa_status_t |
| 3443 | bfa_fcport_enable(struct bfa_s *bfa) |
| 3444 | { |
| 3445 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3446 | |
Krishna Gudipati | 43ffdf4 | 2011-06-13 15:46:21 -0700 | [diff] [blame] | 3447 | if (bfa_fcport_is_pbcdisabled(bfa)) |
| 3448 | return BFA_STATUS_PBC; |
| 3449 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3450 | if (bfa_ioc_is_disabled(&bfa->ioc)) |
| 3451 | return BFA_STATUS_IOC_DISABLED; |
| 3452 | |
| 3453 | if (fcport->diag_busy) |
| 3454 | return BFA_STATUS_DIAG_BUSY; |
| 3455 | |
| 3456 | bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_ENABLE); |
| 3457 | return BFA_STATUS_OK; |
| 3458 | } |
| 3459 | |
| 3460 | bfa_status_t |
| 3461 | bfa_fcport_disable(struct bfa_s *bfa) |
| 3462 | { |
Krishna Gudipati | 43ffdf4 | 2011-06-13 15:46:21 -0700 | [diff] [blame] | 3463 | if (bfa_fcport_is_pbcdisabled(bfa)) |
| 3464 | return BFA_STATUS_PBC; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3465 | |
| 3466 | if (bfa_ioc_is_disabled(&bfa->ioc)) |
| 3467 | return BFA_STATUS_IOC_DISABLED; |
| 3468 | |
| 3469 | bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_DISABLE); |
| 3470 | return BFA_STATUS_OK; |
| 3471 | } |
| 3472 | |
Krishna Gudipati | 43ffdf4 | 2011-06-13 15:46:21 -0700 | [diff] [blame] | 3473 | /* If PBC is disabled on port, return error */ |
| 3474 | bfa_status_t |
| 3475 | bfa_fcport_is_pbcdisabled(struct bfa_s *bfa) |
| 3476 | { |
| 3477 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3478 | struct bfa_iocfc_s *iocfc = &bfa->iocfc; |
| 3479 | struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp; |
| 3480 | |
| 3481 | if (cfgrsp->pbc_cfg.port_enabled == BFI_PBC_PORT_DISABLED) { |
| 3482 | bfa_trc(bfa, fcport->pwwn); |
| 3483 | return BFA_STATUS_PBC; |
| 3484 | } |
| 3485 | return BFA_STATUS_OK; |
| 3486 | } |
| 3487 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3488 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3489 | * Configure port speed. |
| 3490 | */ |
| 3491 | bfa_status_t |
| 3492 | bfa_fcport_cfg_speed(struct bfa_s *bfa, enum bfa_port_speed speed) |
| 3493 | { |
| 3494 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3495 | |
| 3496 | bfa_trc(bfa, speed); |
| 3497 | |
| 3498 | if (fcport->cfg.trunked == BFA_TRUE) |
| 3499 | return BFA_STATUS_TRUNK_ENABLED; |
| 3500 | if ((speed != BFA_PORT_SPEED_AUTO) && (speed > fcport->speed_sup)) { |
| 3501 | bfa_trc(bfa, fcport->speed_sup); |
| 3502 | return BFA_STATUS_UNSUPP_SPEED; |
| 3503 | } |
| 3504 | |
Krishna Gudipati | a714134 | 2011-06-24 20:23:19 -0700 | [diff] [blame^] | 3505 | /* For Mezz card, port speed entered needs to be checked */ |
| 3506 | if (bfa_mfg_is_mezz(fcport->bfa->ioc.attr->card_type)) { |
| 3507 | if (bfa_ioc_get_type(&fcport->bfa->ioc) == BFA_IOC_TYPE_FC) { |
| 3508 | /* For CT2, 1G is not supported */ |
| 3509 | if ((speed == BFA_PORT_SPEED_1GBPS) && |
| 3510 | (bfa_asic_id_ct2(bfa->ioc.pcidev.device_id))) |
| 3511 | return BFA_STATUS_UNSUPP_SPEED; |
| 3512 | |
| 3513 | /* Already checked for Auto Speed and Max Speed supp */ |
| 3514 | if (!(speed == BFA_PORT_SPEED_1GBPS || |
| 3515 | speed == BFA_PORT_SPEED_2GBPS || |
| 3516 | speed == BFA_PORT_SPEED_4GBPS || |
| 3517 | speed == BFA_PORT_SPEED_8GBPS || |
| 3518 | speed == BFA_PORT_SPEED_16GBPS || |
| 3519 | speed == BFA_PORT_SPEED_AUTO)) |
| 3520 | return BFA_STATUS_UNSUPP_SPEED; |
| 3521 | } else { |
| 3522 | if (speed != BFA_PORT_SPEED_10GBPS) |
| 3523 | return BFA_STATUS_UNSUPP_SPEED; |
| 3524 | } |
| 3525 | } |
| 3526 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3527 | fcport->cfg.speed = speed; |
| 3528 | |
| 3529 | return BFA_STATUS_OK; |
| 3530 | } |
| 3531 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3532 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3533 | * Get current speed. |
| 3534 | */ |
| 3535 | enum bfa_port_speed |
| 3536 | bfa_fcport_get_speed(struct bfa_s *bfa) |
| 3537 | { |
| 3538 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3539 | |
| 3540 | return fcport->speed; |
| 3541 | } |
| 3542 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3543 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3544 | * Configure port topology. |
| 3545 | */ |
| 3546 | bfa_status_t |
| 3547 | bfa_fcport_cfg_topology(struct bfa_s *bfa, enum bfa_port_topology topology) |
| 3548 | { |
| 3549 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3550 | |
| 3551 | bfa_trc(bfa, topology); |
| 3552 | bfa_trc(bfa, fcport->cfg.topology); |
| 3553 | |
| 3554 | switch (topology) { |
| 3555 | case BFA_PORT_TOPOLOGY_P2P: |
| 3556 | case BFA_PORT_TOPOLOGY_LOOP: |
| 3557 | case BFA_PORT_TOPOLOGY_AUTO: |
| 3558 | break; |
| 3559 | |
| 3560 | default: |
| 3561 | return BFA_STATUS_EINVAL; |
| 3562 | } |
| 3563 | |
| 3564 | fcport->cfg.topology = topology; |
| 3565 | return BFA_STATUS_OK; |
| 3566 | } |
| 3567 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3568 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3569 | * Get current topology. |
| 3570 | */ |
| 3571 | enum bfa_port_topology |
| 3572 | bfa_fcport_get_topology(struct bfa_s *bfa) |
| 3573 | { |
| 3574 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3575 | |
| 3576 | return fcport->topology; |
| 3577 | } |
| 3578 | |
| 3579 | bfa_status_t |
| 3580 | bfa_fcport_cfg_hardalpa(struct bfa_s *bfa, u8 alpa) |
| 3581 | { |
| 3582 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3583 | |
| 3584 | bfa_trc(bfa, alpa); |
| 3585 | bfa_trc(bfa, fcport->cfg.cfg_hardalpa); |
| 3586 | bfa_trc(bfa, fcport->cfg.hardalpa); |
| 3587 | |
| 3588 | fcport->cfg.cfg_hardalpa = BFA_TRUE; |
| 3589 | fcport->cfg.hardalpa = alpa; |
| 3590 | |
| 3591 | return BFA_STATUS_OK; |
| 3592 | } |
| 3593 | |
| 3594 | bfa_status_t |
| 3595 | bfa_fcport_clr_hardalpa(struct bfa_s *bfa) |
| 3596 | { |
| 3597 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3598 | |
| 3599 | bfa_trc(bfa, fcport->cfg.cfg_hardalpa); |
| 3600 | bfa_trc(bfa, fcport->cfg.hardalpa); |
| 3601 | |
| 3602 | fcport->cfg.cfg_hardalpa = BFA_FALSE; |
| 3603 | return BFA_STATUS_OK; |
| 3604 | } |
| 3605 | |
| 3606 | bfa_boolean_t |
| 3607 | bfa_fcport_get_hardalpa(struct bfa_s *bfa, u8 *alpa) |
| 3608 | { |
| 3609 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3610 | |
| 3611 | *alpa = fcport->cfg.hardalpa; |
| 3612 | return fcport->cfg.cfg_hardalpa; |
| 3613 | } |
| 3614 | |
| 3615 | u8 |
| 3616 | bfa_fcport_get_myalpa(struct bfa_s *bfa) |
| 3617 | { |
| 3618 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3619 | |
| 3620 | return fcport->myalpa; |
| 3621 | } |
| 3622 | |
| 3623 | bfa_status_t |
| 3624 | bfa_fcport_cfg_maxfrsize(struct bfa_s *bfa, u16 maxfrsize) |
| 3625 | { |
| 3626 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3627 | |
| 3628 | bfa_trc(bfa, maxfrsize); |
| 3629 | bfa_trc(bfa, fcport->cfg.maxfrsize); |
| 3630 | |
| 3631 | /* with in range */ |
| 3632 | if ((maxfrsize > FC_MAX_PDUSZ) || (maxfrsize < FC_MIN_PDUSZ)) |
| 3633 | return BFA_STATUS_INVLD_DFSZ; |
| 3634 | |
| 3635 | /* power of 2, if not the max frame size of 2112 */ |
| 3636 | if ((maxfrsize != FC_MAX_PDUSZ) && (maxfrsize & (maxfrsize - 1))) |
| 3637 | return BFA_STATUS_INVLD_DFSZ; |
| 3638 | |
| 3639 | fcport->cfg.maxfrsize = maxfrsize; |
| 3640 | return BFA_STATUS_OK; |
| 3641 | } |
| 3642 | |
| 3643 | u16 |
| 3644 | bfa_fcport_get_maxfrsize(struct bfa_s *bfa) |
| 3645 | { |
| 3646 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3647 | |
| 3648 | return fcport->cfg.maxfrsize; |
| 3649 | } |
| 3650 | |
| 3651 | u8 |
| 3652 | bfa_fcport_get_rx_bbcredit(struct bfa_s *bfa) |
| 3653 | { |
| 3654 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3655 | |
| 3656 | return fcport->cfg.rx_bbcredit; |
| 3657 | } |
| 3658 | |
| 3659 | void |
Krishna Gudipati | be540a9 | 2011-06-13 15:53:04 -0700 | [diff] [blame] | 3660 | 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] | 3661 | { |
| 3662 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3663 | |
| 3664 | fcport->cfg.tx_bbcredit = (u8)tx_bbcredit; |
Krishna Gudipati | be540a9 | 2011-06-13 15:53:04 -0700 | [diff] [blame] | 3665 | fcport->cfg.bb_scn = bb_scn; |
| 3666 | if (bb_scn) |
| 3667 | fcport->bbsc_op_state = BFA_TRUE; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3668 | bfa_fcport_send_txcredit(fcport); |
| 3669 | } |
| 3670 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3671 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3672 | * Get port attributes. |
| 3673 | */ |
| 3674 | |
| 3675 | wwn_t |
| 3676 | bfa_fcport_get_wwn(struct bfa_s *bfa, bfa_boolean_t node) |
| 3677 | { |
| 3678 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3679 | if (node) |
| 3680 | return fcport->nwwn; |
| 3681 | else |
| 3682 | return fcport->pwwn; |
| 3683 | } |
| 3684 | |
| 3685 | void |
| 3686 | bfa_fcport_get_attr(struct bfa_s *bfa, struct bfa_port_attr_s *attr) |
| 3687 | { |
| 3688 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3689 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 3690 | memset(attr, 0, sizeof(struct bfa_port_attr_s)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3691 | |
| 3692 | attr->nwwn = fcport->nwwn; |
| 3693 | attr->pwwn = fcport->pwwn; |
| 3694 | |
Maggie Zhang | f7f7381 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 3695 | attr->factorypwwn = bfa->ioc.attr->mfg_pwwn; |
| 3696 | attr->factorynwwn = bfa->ioc.attr->mfg_nwwn; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3697 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 3698 | memcpy(&attr->pport_cfg, &fcport->cfg, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3699 | sizeof(struct bfa_port_cfg_s)); |
| 3700 | /* speed attributes */ |
| 3701 | attr->pport_cfg.speed = fcport->cfg.speed; |
| 3702 | attr->speed_supported = fcport->speed_sup; |
| 3703 | attr->speed = fcport->speed; |
| 3704 | attr->cos_supported = FC_CLASS_3; |
| 3705 | |
| 3706 | /* topology attributes */ |
| 3707 | attr->pport_cfg.topology = fcport->cfg.topology; |
| 3708 | attr->topology = fcport->topology; |
| 3709 | attr->pport_cfg.trunked = fcport->cfg.trunked; |
| 3710 | |
| 3711 | /* beacon attributes */ |
| 3712 | attr->beacon = fcport->beacon; |
| 3713 | attr->link_e2e_beacon = fcport->link_e2e_beacon; |
Maggie Zhang | f7f7381 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 3714 | attr->plog_enabled = (bfa_boolean_t)fcport->bfa->plog->plog_enabled; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3715 | attr->io_profile = bfa_fcpim_get_io_profile(fcport->bfa); |
| 3716 | |
| 3717 | attr->pport_cfg.path_tov = bfa_fcpim_path_tov_get(bfa); |
| 3718 | attr->pport_cfg.q_depth = bfa_fcpim_qdepth_get(bfa); |
| 3719 | 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] | 3720 | attr->bbsc_op_status = fcport->bbsc_op_state; |
Krishna Gudipati | 43ffdf4 | 2011-06-13 15:46:21 -0700 | [diff] [blame] | 3721 | |
| 3722 | /* PBC Disabled State */ |
| 3723 | if (bfa_fcport_is_pbcdisabled(bfa)) |
| 3724 | attr->port_state = BFA_PORT_ST_PREBOOT_DISABLED; |
| 3725 | else { |
| 3726 | if (bfa_ioc_is_disabled(&fcport->bfa->ioc)) |
| 3727 | attr->port_state = BFA_PORT_ST_IOCDIS; |
| 3728 | else if (bfa_ioc_fw_mismatch(&fcport->bfa->ioc)) |
| 3729 | attr->port_state = BFA_PORT_ST_FWMISMATCH; |
Krishna Gudipati | a714134 | 2011-06-24 20:23:19 -0700 | [diff] [blame^] | 3730 | else if (bfa_ioc_is_acq_addr(&fcport->bfa->ioc)) |
| 3731 | attr->port_state = BFA_PORT_ST_ACQ_ADDR; |
Krishna Gudipati | 43ffdf4 | 2011-06-13 15:46:21 -0700 | [diff] [blame] | 3732 | } |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3733 | |
| 3734 | /* FCoE vlan */ |
| 3735 | attr->fcoe_vlan = fcport->fcoe_vlan; |
| 3736 | } |
| 3737 | |
| 3738 | #define BFA_FCPORT_STATS_TOV 1000 |
| 3739 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3740 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3741 | * Fetch port statistics (FCQoS or FCoE). |
| 3742 | */ |
| 3743 | bfa_status_t |
| 3744 | bfa_fcport_get_stats(struct bfa_s *bfa, union bfa_fcport_stats_u *stats, |
| 3745 | bfa_cb_port_t cbfn, void *cbarg) |
| 3746 | { |
| 3747 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3748 | |
| 3749 | if (fcport->stats_busy) { |
| 3750 | bfa_trc(bfa, fcport->stats_busy); |
| 3751 | return BFA_STATUS_DEVBUSY; |
| 3752 | } |
| 3753 | |
| 3754 | fcport->stats_busy = BFA_TRUE; |
| 3755 | fcport->stats_ret = stats; |
| 3756 | fcport->stats_cbfn = cbfn; |
| 3757 | fcport->stats_cbarg = cbarg; |
| 3758 | |
| 3759 | bfa_fcport_send_stats_get(fcport); |
| 3760 | |
| 3761 | bfa_timer_start(bfa, &fcport->timer, bfa_fcport_stats_get_timeout, |
| 3762 | fcport, BFA_FCPORT_STATS_TOV); |
| 3763 | return BFA_STATUS_OK; |
| 3764 | } |
| 3765 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3766 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3767 | * Reset port statistics (FCQoS or FCoE). |
| 3768 | */ |
| 3769 | bfa_status_t |
| 3770 | bfa_fcport_clear_stats(struct bfa_s *bfa, bfa_cb_port_t cbfn, void *cbarg) |
| 3771 | { |
| 3772 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3773 | |
| 3774 | if (fcport->stats_busy) { |
| 3775 | bfa_trc(bfa, fcport->stats_busy); |
| 3776 | return BFA_STATUS_DEVBUSY; |
| 3777 | } |
| 3778 | |
| 3779 | fcport->stats_busy = BFA_TRUE; |
| 3780 | fcport->stats_cbfn = cbfn; |
| 3781 | fcport->stats_cbarg = cbarg; |
| 3782 | |
| 3783 | bfa_fcport_send_stats_clear(fcport); |
| 3784 | |
| 3785 | bfa_timer_start(bfa, &fcport->timer, bfa_fcport_stats_clr_timeout, |
| 3786 | fcport, BFA_FCPORT_STATS_TOV); |
| 3787 | return BFA_STATUS_OK; |
| 3788 | } |
| 3789 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3790 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3791 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3792 | * Fetch port attributes. |
| 3793 | */ |
| 3794 | bfa_boolean_t |
| 3795 | bfa_fcport_is_disabled(struct bfa_s *bfa) |
| 3796 | { |
| 3797 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3798 | |
| 3799 | return bfa_sm_to_state(hal_port_sm_table, fcport->sm) == |
| 3800 | BFA_PORT_ST_DISABLED; |
| 3801 | |
| 3802 | } |
| 3803 | |
| 3804 | bfa_boolean_t |
| 3805 | bfa_fcport_is_ratelim(struct bfa_s *bfa) |
| 3806 | { |
| 3807 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3808 | |
| 3809 | return fcport->cfg.ratelimit ? BFA_TRUE : BFA_FALSE; |
| 3810 | |
| 3811 | } |
| 3812 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3813 | /* |
Krishna Gudipati | a714134 | 2011-06-24 20:23:19 -0700 | [diff] [blame^] | 3814 | * Enable/Disable FAA feature in port config |
| 3815 | */ |
| 3816 | void |
| 3817 | bfa_fcport_cfg_faa(struct bfa_s *bfa, u8 state) |
| 3818 | { |
| 3819 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3820 | |
| 3821 | bfa_trc(bfa, state); |
| 3822 | fcport->cfg.faa_state = state; |
| 3823 | } |
| 3824 | |
| 3825 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3826 | * Get default minimum ratelim speed |
| 3827 | */ |
| 3828 | enum bfa_port_speed |
| 3829 | bfa_fcport_get_ratelim_speed(struct bfa_s *bfa) |
| 3830 | { |
| 3831 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3832 | |
| 3833 | bfa_trc(bfa, fcport->cfg.trl_def_speed); |
| 3834 | return fcport->cfg.trl_def_speed; |
| 3835 | |
| 3836 | } |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3837 | |
| 3838 | bfa_boolean_t |
| 3839 | bfa_fcport_is_linkup(struct bfa_s *bfa) |
| 3840 | { |
| 3841 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3842 | |
| 3843 | return (!fcport->cfg.trunked && |
| 3844 | bfa_sm_cmp_state(fcport, bfa_fcport_sm_linkup)) || |
| 3845 | (fcport->cfg.trunked && |
| 3846 | fcport->trunk.attr.state == BFA_TRUNK_ONLINE); |
| 3847 | } |
| 3848 | |
| 3849 | bfa_boolean_t |
| 3850 | bfa_fcport_is_qos_enabled(struct bfa_s *bfa) |
| 3851 | { |
| 3852 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3853 | |
| 3854 | return fcport->cfg.qos_enabled; |
| 3855 | } |
| 3856 | |
Krishna Gudipati | be540a9 | 2011-06-13 15:53:04 -0700 | [diff] [blame] | 3857 | bfa_boolean_t |
| 3858 | bfa_fcport_is_trunk_enabled(struct bfa_s *bfa) |
| 3859 | { |
| 3860 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
| 3861 | |
| 3862 | return fcport->cfg.trunked; |
| 3863 | } |
| 3864 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3865 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3866 | * Rport State machine functions |
| 3867 | */ |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3868 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3869 | * Beginning state, only online event expected. |
| 3870 | */ |
| 3871 | static void |
| 3872 | bfa_rport_sm_uninit(struct bfa_rport_s *rp, enum bfa_rport_event event) |
| 3873 | { |
| 3874 | bfa_trc(rp->bfa, rp->rport_tag); |
| 3875 | bfa_trc(rp->bfa, event); |
| 3876 | |
| 3877 | switch (event) { |
| 3878 | case BFA_RPORT_SM_CREATE: |
| 3879 | bfa_stats(rp, sm_un_cr); |
| 3880 | bfa_sm_set_state(rp, bfa_rport_sm_created); |
| 3881 | break; |
| 3882 | |
| 3883 | default: |
| 3884 | bfa_stats(rp, sm_un_unexp); |
| 3885 | bfa_sm_fault(rp->bfa, event); |
| 3886 | } |
| 3887 | } |
| 3888 | |
| 3889 | static void |
| 3890 | bfa_rport_sm_created(struct bfa_rport_s *rp, enum bfa_rport_event event) |
| 3891 | { |
| 3892 | bfa_trc(rp->bfa, rp->rport_tag); |
| 3893 | bfa_trc(rp->bfa, event); |
| 3894 | |
| 3895 | switch (event) { |
| 3896 | case BFA_RPORT_SM_ONLINE: |
| 3897 | bfa_stats(rp, sm_cr_on); |
| 3898 | if (bfa_rport_send_fwcreate(rp)) |
| 3899 | bfa_sm_set_state(rp, bfa_rport_sm_fwcreate); |
| 3900 | else |
| 3901 | bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull); |
| 3902 | break; |
| 3903 | |
| 3904 | case BFA_RPORT_SM_DELETE: |
| 3905 | bfa_stats(rp, sm_cr_del); |
| 3906 | bfa_sm_set_state(rp, bfa_rport_sm_uninit); |
| 3907 | bfa_rport_free(rp); |
| 3908 | break; |
| 3909 | |
| 3910 | case BFA_RPORT_SM_HWFAIL: |
| 3911 | bfa_stats(rp, sm_cr_hwf); |
| 3912 | bfa_sm_set_state(rp, bfa_rport_sm_iocdisable); |
| 3913 | break; |
| 3914 | |
| 3915 | default: |
| 3916 | bfa_stats(rp, sm_cr_unexp); |
| 3917 | bfa_sm_fault(rp->bfa, event); |
| 3918 | } |
| 3919 | } |
| 3920 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3921 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3922 | * Waiting for rport create response from firmware. |
| 3923 | */ |
| 3924 | static void |
| 3925 | bfa_rport_sm_fwcreate(struct bfa_rport_s *rp, enum bfa_rport_event event) |
| 3926 | { |
| 3927 | bfa_trc(rp->bfa, rp->rport_tag); |
| 3928 | bfa_trc(rp->bfa, event); |
| 3929 | |
| 3930 | switch (event) { |
| 3931 | case BFA_RPORT_SM_FWRSP: |
| 3932 | bfa_stats(rp, sm_fwc_rsp); |
| 3933 | bfa_sm_set_state(rp, bfa_rport_sm_online); |
| 3934 | bfa_rport_online_cb(rp); |
| 3935 | break; |
| 3936 | |
| 3937 | case BFA_RPORT_SM_DELETE: |
| 3938 | bfa_stats(rp, sm_fwc_del); |
| 3939 | bfa_sm_set_state(rp, bfa_rport_sm_delete_pending); |
| 3940 | break; |
| 3941 | |
| 3942 | case BFA_RPORT_SM_OFFLINE: |
| 3943 | bfa_stats(rp, sm_fwc_off); |
| 3944 | bfa_sm_set_state(rp, bfa_rport_sm_offline_pending); |
| 3945 | break; |
| 3946 | |
| 3947 | case BFA_RPORT_SM_HWFAIL: |
| 3948 | bfa_stats(rp, sm_fwc_hwf); |
| 3949 | bfa_sm_set_state(rp, bfa_rport_sm_iocdisable); |
| 3950 | break; |
| 3951 | |
| 3952 | default: |
| 3953 | bfa_stats(rp, sm_fwc_unexp); |
| 3954 | bfa_sm_fault(rp->bfa, event); |
| 3955 | } |
| 3956 | } |
| 3957 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3958 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3959 | * Request queue is full, awaiting queue resume to send create request. |
| 3960 | */ |
| 3961 | static void |
| 3962 | bfa_rport_sm_fwcreate_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event) |
| 3963 | { |
| 3964 | bfa_trc(rp->bfa, rp->rport_tag); |
| 3965 | bfa_trc(rp->bfa, event); |
| 3966 | |
| 3967 | switch (event) { |
| 3968 | case BFA_RPORT_SM_QRESUME: |
| 3969 | bfa_sm_set_state(rp, bfa_rport_sm_fwcreate); |
| 3970 | bfa_rport_send_fwcreate(rp); |
| 3971 | break; |
| 3972 | |
| 3973 | case BFA_RPORT_SM_DELETE: |
| 3974 | bfa_stats(rp, sm_fwc_del); |
| 3975 | bfa_sm_set_state(rp, bfa_rport_sm_uninit); |
| 3976 | bfa_reqq_wcancel(&rp->reqq_wait); |
| 3977 | bfa_rport_free(rp); |
| 3978 | break; |
| 3979 | |
| 3980 | case BFA_RPORT_SM_OFFLINE: |
| 3981 | bfa_stats(rp, sm_fwc_off); |
| 3982 | bfa_sm_set_state(rp, bfa_rport_sm_offline); |
| 3983 | bfa_reqq_wcancel(&rp->reqq_wait); |
| 3984 | bfa_rport_offline_cb(rp); |
| 3985 | break; |
| 3986 | |
| 3987 | case BFA_RPORT_SM_HWFAIL: |
| 3988 | bfa_stats(rp, sm_fwc_hwf); |
| 3989 | bfa_sm_set_state(rp, bfa_rport_sm_iocdisable); |
| 3990 | bfa_reqq_wcancel(&rp->reqq_wait); |
| 3991 | break; |
| 3992 | |
| 3993 | default: |
| 3994 | bfa_stats(rp, sm_fwc_unexp); |
| 3995 | bfa_sm_fault(rp->bfa, event); |
| 3996 | } |
| 3997 | } |
| 3998 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 3999 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4000 | * Online state - normal parking state. |
| 4001 | */ |
| 4002 | static void |
| 4003 | bfa_rport_sm_online(struct bfa_rport_s *rp, enum bfa_rport_event event) |
| 4004 | { |
| 4005 | struct bfi_rport_qos_scn_s *qos_scn; |
| 4006 | |
| 4007 | bfa_trc(rp->bfa, rp->rport_tag); |
| 4008 | bfa_trc(rp->bfa, event); |
| 4009 | |
| 4010 | switch (event) { |
| 4011 | case BFA_RPORT_SM_OFFLINE: |
| 4012 | bfa_stats(rp, sm_on_off); |
| 4013 | if (bfa_rport_send_fwdelete(rp)) |
| 4014 | bfa_sm_set_state(rp, bfa_rport_sm_fwdelete); |
| 4015 | else |
| 4016 | bfa_sm_set_state(rp, bfa_rport_sm_fwdelete_qfull); |
| 4017 | break; |
| 4018 | |
| 4019 | case BFA_RPORT_SM_DELETE: |
| 4020 | bfa_stats(rp, sm_on_del); |
| 4021 | if (bfa_rport_send_fwdelete(rp)) |
| 4022 | bfa_sm_set_state(rp, bfa_rport_sm_deleting); |
| 4023 | else |
| 4024 | bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull); |
| 4025 | break; |
| 4026 | |
| 4027 | case BFA_RPORT_SM_HWFAIL: |
| 4028 | bfa_stats(rp, sm_on_hwf); |
| 4029 | bfa_sm_set_state(rp, bfa_rport_sm_iocdisable); |
| 4030 | break; |
| 4031 | |
| 4032 | case BFA_RPORT_SM_SET_SPEED: |
| 4033 | bfa_rport_send_fwspeed(rp); |
| 4034 | break; |
| 4035 | |
| 4036 | case BFA_RPORT_SM_QOS_SCN: |
| 4037 | qos_scn = (struct bfi_rport_qos_scn_s *) rp->event_arg.fw_msg; |
| 4038 | rp->qos_attr = qos_scn->new_qos_attr; |
| 4039 | bfa_trc(rp->bfa, qos_scn->old_qos_attr.qos_flow_id); |
| 4040 | bfa_trc(rp->bfa, qos_scn->new_qos_attr.qos_flow_id); |
| 4041 | bfa_trc(rp->bfa, qos_scn->old_qos_attr.qos_priority); |
| 4042 | bfa_trc(rp->bfa, qos_scn->new_qos_attr.qos_priority); |
| 4043 | |
| 4044 | qos_scn->old_qos_attr.qos_flow_id = |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 4045 | be32_to_cpu(qos_scn->old_qos_attr.qos_flow_id); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4046 | qos_scn->new_qos_attr.qos_flow_id = |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 4047 | be32_to_cpu(qos_scn->new_qos_attr.qos_flow_id); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4048 | |
| 4049 | if (qos_scn->old_qos_attr.qos_flow_id != |
| 4050 | qos_scn->new_qos_attr.qos_flow_id) |
| 4051 | bfa_cb_rport_qos_scn_flowid(rp->rport_drv, |
| 4052 | qos_scn->old_qos_attr, |
| 4053 | qos_scn->new_qos_attr); |
| 4054 | if (qos_scn->old_qos_attr.qos_priority != |
| 4055 | qos_scn->new_qos_attr.qos_priority) |
| 4056 | bfa_cb_rport_qos_scn_prio(rp->rport_drv, |
| 4057 | qos_scn->old_qos_attr, |
| 4058 | qos_scn->new_qos_attr); |
| 4059 | break; |
| 4060 | |
| 4061 | default: |
| 4062 | bfa_stats(rp, sm_on_unexp); |
| 4063 | bfa_sm_fault(rp->bfa, event); |
| 4064 | } |
| 4065 | } |
| 4066 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4067 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4068 | * Firmware rport is being deleted - awaiting f/w response. |
| 4069 | */ |
| 4070 | static void |
| 4071 | bfa_rport_sm_fwdelete(struct bfa_rport_s *rp, enum bfa_rport_event event) |
| 4072 | { |
| 4073 | bfa_trc(rp->bfa, rp->rport_tag); |
| 4074 | bfa_trc(rp->bfa, event); |
| 4075 | |
| 4076 | switch (event) { |
| 4077 | case BFA_RPORT_SM_FWRSP: |
| 4078 | bfa_stats(rp, sm_fwd_rsp); |
| 4079 | bfa_sm_set_state(rp, bfa_rport_sm_offline); |
| 4080 | bfa_rport_offline_cb(rp); |
| 4081 | break; |
| 4082 | |
| 4083 | case BFA_RPORT_SM_DELETE: |
| 4084 | bfa_stats(rp, sm_fwd_del); |
| 4085 | bfa_sm_set_state(rp, bfa_rport_sm_deleting); |
| 4086 | break; |
| 4087 | |
| 4088 | case BFA_RPORT_SM_HWFAIL: |
| 4089 | bfa_stats(rp, sm_fwd_hwf); |
| 4090 | bfa_sm_set_state(rp, bfa_rport_sm_iocdisable); |
| 4091 | bfa_rport_offline_cb(rp); |
| 4092 | break; |
| 4093 | |
| 4094 | default: |
| 4095 | bfa_stats(rp, sm_fwd_unexp); |
| 4096 | bfa_sm_fault(rp->bfa, event); |
| 4097 | } |
| 4098 | } |
| 4099 | |
| 4100 | static void |
| 4101 | bfa_rport_sm_fwdelete_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event) |
| 4102 | { |
| 4103 | bfa_trc(rp->bfa, rp->rport_tag); |
| 4104 | bfa_trc(rp->bfa, event); |
| 4105 | |
| 4106 | switch (event) { |
| 4107 | case BFA_RPORT_SM_QRESUME: |
| 4108 | bfa_sm_set_state(rp, bfa_rport_sm_fwdelete); |
| 4109 | bfa_rport_send_fwdelete(rp); |
| 4110 | break; |
| 4111 | |
| 4112 | case BFA_RPORT_SM_DELETE: |
| 4113 | bfa_stats(rp, sm_fwd_del); |
| 4114 | bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull); |
| 4115 | break; |
| 4116 | |
| 4117 | case BFA_RPORT_SM_HWFAIL: |
| 4118 | bfa_stats(rp, sm_fwd_hwf); |
| 4119 | bfa_sm_set_state(rp, bfa_rport_sm_iocdisable); |
| 4120 | bfa_reqq_wcancel(&rp->reqq_wait); |
| 4121 | bfa_rport_offline_cb(rp); |
| 4122 | break; |
| 4123 | |
| 4124 | default: |
| 4125 | bfa_stats(rp, sm_fwd_unexp); |
| 4126 | bfa_sm_fault(rp->bfa, event); |
| 4127 | } |
| 4128 | } |
| 4129 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4130 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4131 | * Offline state. |
| 4132 | */ |
| 4133 | static void |
| 4134 | bfa_rport_sm_offline(struct bfa_rport_s *rp, enum bfa_rport_event event) |
| 4135 | { |
| 4136 | bfa_trc(rp->bfa, rp->rport_tag); |
| 4137 | bfa_trc(rp->bfa, event); |
| 4138 | |
| 4139 | switch (event) { |
| 4140 | case BFA_RPORT_SM_DELETE: |
| 4141 | bfa_stats(rp, sm_off_del); |
| 4142 | bfa_sm_set_state(rp, bfa_rport_sm_uninit); |
| 4143 | bfa_rport_free(rp); |
| 4144 | break; |
| 4145 | |
| 4146 | case BFA_RPORT_SM_ONLINE: |
| 4147 | bfa_stats(rp, sm_off_on); |
| 4148 | if (bfa_rport_send_fwcreate(rp)) |
| 4149 | bfa_sm_set_state(rp, bfa_rport_sm_fwcreate); |
| 4150 | else |
| 4151 | bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull); |
| 4152 | break; |
| 4153 | |
| 4154 | case BFA_RPORT_SM_HWFAIL: |
| 4155 | bfa_stats(rp, sm_off_hwf); |
| 4156 | bfa_sm_set_state(rp, bfa_rport_sm_iocdisable); |
| 4157 | break; |
| 4158 | |
| 4159 | default: |
| 4160 | bfa_stats(rp, sm_off_unexp); |
| 4161 | bfa_sm_fault(rp->bfa, event); |
| 4162 | } |
| 4163 | } |
| 4164 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4165 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4166 | * Rport is deleted, waiting for firmware response to delete. |
| 4167 | */ |
| 4168 | static void |
| 4169 | bfa_rport_sm_deleting(struct bfa_rport_s *rp, enum bfa_rport_event event) |
| 4170 | { |
| 4171 | bfa_trc(rp->bfa, rp->rport_tag); |
| 4172 | bfa_trc(rp->bfa, event); |
| 4173 | |
| 4174 | switch (event) { |
| 4175 | case BFA_RPORT_SM_FWRSP: |
| 4176 | bfa_stats(rp, sm_del_fwrsp); |
| 4177 | bfa_sm_set_state(rp, bfa_rport_sm_uninit); |
| 4178 | bfa_rport_free(rp); |
| 4179 | break; |
| 4180 | |
| 4181 | case BFA_RPORT_SM_HWFAIL: |
| 4182 | bfa_stats(rp, sm_del_hwf); |
| 4183 | bfa_sm_set_state(rp, bfa_rport_sm_uninit); |
| 4184 | bfa_rport_free(rp); |
| 4185 | break; |
| 4186 | |
| 4187 | default: |
| 4188 | bfa_sm_fault(rp->bfa, event); |
| 4189 | } |
| 4190 | } |
| 4191 | |
| 4192 | static void |
| 4193 | bfa_rport_sm_deleting_qfull(struct bfa_rport_s *rp, enum bfa_rport_event event) |
| 4194 | { |
| 4195 | bfa_trc(rp->bfa, rp->rport_tag); |
| 4196 | bfa_trc(rp->bfa, event); |
| 4197 | |
| 4198 | switch (event) { |
| 4199 | case BFA_RPORT_SM_QRESUME: |
| 4200 | bfa_stats(rp, sm_del_fwrsp); |
| 4201 | bfa_sm_set_state(rp, bfa_rport_sm_deleting); |
| 4202 | bfa_rport_send_fwdelete(rp); |
| 4203 | break; |
| 4204 | |
| 4205 | case BFA_RPORT_SM_HWFAIL: |
| 4206 | bfa_stats(rp, sm_del_hwf); |
| 4207 | bfa_sm_set_state(rp, bfa_rport_sm_uninit); |
| 4208 | bfa_reqq_wcancel(&rp->reqq_wait); |
| 4209 | bfa_rport_free(rp); |
| 4210 | break; |
| 4211 | |
| 4212 | default: |
| 4213 | bfa_sm_fault(rp->bfa, event); |
| 4214 | } |
| 4215 | } |
| 4216 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4217 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4218 | * Waiting for rport create response from firmware. A delete is pending. |
| 4219 | */ |
| 4220 | static void |
| 4221 | bfa_rport_sm_delete_pending(struct bfa_rport_s *rp, |
| 4222 | enum bfa_rport_event event) |
| 4223 | { |
| 4224 | bfa_trc(rp->bfa, rp->rport_tag); |
| 4225 | bfa_trc(rp->bfa, event); |
| 4226 | |
| 4227 | switch (event) { |
| 4228 | case BFA_RPORT_SM_FWRSP: |
| 4229 | bfa_stats(rp, sm_delp_fwrsp); |
| 4230 | if (bfa_rport_send_fwdelete(rp)) |
| 4231 | bfa_sm_set_state(rp, bfa_rport_sm_deleting); |
| 4232 | else |
| 4233 | bfa_sm_set_state(rp, bfa_rport_sm_deleting_qfull); |
| 4234 | break; |
| 4235 | |
| 4236 | case BFA_RPORT_SM_HWFAIL: |
| 4237 | bfa_stats(rp, sm_delp_hwf); |
| 4238 | bfa_sm_set_state(rp, bfa_rport_sm_uninit); |
| 4239 | bfa_rport_free(rp); |
| 4240 | break; |
| 4241 | |
| 4242 | default: |
| 4243 | bfa_stats(rp, sm_delp_unexp); |
| 4244 | bfa_sm_fault(rp->bfa, event); |
| 4245 | } |
| 4246 | } |
| 4247 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4248 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4249 | * Waiting for rport create response from firmware. Rport offline is pending. |
| 4250 | */ |
| 4251 | static void |
| 4252 | bfa_rport_sm_offline_pending(struct bfa_rport_s *rp, |
| 4253 | enum bfa_rport_event event) |
| 4254 | { |
| 4255 | bfa_trc(rp->bfa, rp->rport_tag); |
| 4256 | bfa_trc(rp->bfa, event); |
| 4257 | |
| 4258 | switch (event) { |
| 4259 | case BFA_RPORT_SM_FWRSP: |
| 4260 | bfa_stats(rp, sm_offp_fwrsp); |
| 4261 | if (bfa_rport_send_fwdelete(rp)) |
| 4262 | bfa_sm_set_state(rp, bfa_rport_sm_fwdelete); |
| 4263 | else |
| 4264 | bfa_sm_set_state(rp, bfa_rport_sm_fwdelete_qfull); |
| 4265 | break; |
| 4266 | |
| 4267 | case BFA_RPORT_SM_DELETE: |
| 4268 | bfa_stats(rp, sm_offp_del); |
| 4269 | bfa_sm_set_state(rp, bfa_rport_sm_delete_pending); |
| 4270 | break; |
| 4271 | |
| 4272 | case BFA_RPORT_SM_HWFAIL: |
| 4273 | bfa_stats(rp, sm_offp_hwf); |
| 4274 | bfa_sm_set_state(rp, bfa_rport_sm_iocdisable); |
| 4275 | break; |
| 4276 | |
| 4277 | default: |
| 4278 | bfa_stats(rp, sm_offp_unexp); |
| 4279 | bfa_sm_fault(rp->bfa, event); |
| 4280 | } |
| 4281 | } |
| 4282 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4283 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4284 | * IOC h/w failed. |
| 4285 | */ |
| 4286 | static void |
| 4287 | bfa_rport_sm_iocdisable(struct bfa_rport_s *rp, enum bfa_rport_event event) |
| 4288 | { |
| 4289 | bfa_trc(rp->bfa, rp->rport_tag); |
| 4290 | bfa_trc(rp->bfa, event); |
| 4291 | |
| 4292 | switch (event) { |
| 4293 | case BFA_RPORT_SM_OFFLINE: |
| 4294 | bfa_stats(rp, sm_iocd_off); |
| 4295 | bfa_rport_offline_cb(rp); |
| 4296 | break; |
| 4297 | |
| 4298 | case BFA_RPORT_SM_DELETE: |
| 4299 | bfa_stats(rp, sm_iocd_del); |
| 4300 | bfa_sm_set_state(rp, bfa_rport_sm_uninit); |
| 4301 | bfa_rport_free(rp); |
| 4302 | break; |
| 4303 | |
| 4304 | case BFA_RPORT_SM_ONLINE: |
| 4305 | bfa_stats(rp, sm_iocd_on); |
| 4306 | if (bfa_rport_send_fwcreate(rp)) |
| 4307 | bfa_sm_set_state(rp, bfa_rport_sm_fwcreate); |
| 4308 | else |
| 4309 | bfa_sm_set_state(rp, bfa_rport_sm_fwcreate_qfull); |
| 4310 | break; |
| 4311 | |
| 4312 | case BFA_RPORT_SM_HWFAIL: |
| 4313 | break; |
| 4314 | |
| 4315 | default: |
| 4316 | bfa_stats(rp, sm_iocd_unexp); |
| 4317 | bfa_sm_fault(rp->bfa, event); |
| 4318 | } |
| 4319 | } |
| 4320 | |
| 4321 | |
| 4322 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4323 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4324 | * bfa_rport_private BFA rport private functions |
| 4325 | */ |
| 4326 | |
| 4327 | static void |
| 4328 | __bfa_cb_rport_online(void *cbarg, bfa_boolean_t complete) |
| 4329 | { |
| 4330 | struct bfa_rport_s *rp = cbarg; |
| 4331 | |
| 4332 | if (complete) |
| 4333 | bfa_cb_rport_online(rp->rport_drv); |
| 4334 | } |
| 4335 | |
| 4336 | static void |
| 4337 | __bfa_cb_rport_offline(void *cbarg, bfa_boolean_t complete) |
| 4338 | { |
| 4339 | struct bfa_rport_s *rp = cbarg; |
| 4340 | |
| 4341 | if (complete) |
| 4342 | bfa_cb_rport_offline(rp->rport_drv); |
| 4343 | } |
| 4344 | |
| 4345 | static void |
| 4346 | bfa_rport_qresume(void *cbarg) |
| 4347 | { |
| 4348 | struct bfa_rport_s *rp = cbarg; |
| 4349 | |
| 4350 | bfa_sm_send_event(rp, BFA_RPORT_SM_QRESUME); |
| 4351 | } |
| 4352 | |
| 4353 | static void |
| 4354 | bfa_rport_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *km_len, |
| 4355 | u32 *dm_len) |
| 4356 | { |
| 4357 | if (cfg->fwcfg.num_rports < BFA_RPORT_MIN) |
| 4358 | cfg->fwcfg.num_rports = BFA_RPORT_MIN; |
| 4359 | |
| 4360 | *km_len += cfg->fwcfg.num_rports * sizeof(struct bfa_rport_s); |
| 4361 | } |
| 4362 | |
| 4363 | static void |
| 4364 | bfa_rport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg, |
| 4365 | struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev) |
| 4366 | { |
| 4367 | struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa); |
| 4368 | struct bfa_rport_s *rp; |
| 4369 | u16 i; |
| 4370 | |
| 4371 | INIT_LIST_HEAD(&mod->rp_free_q); |
| 4372 | INIT_LIST_HEAD(&mod->rp_active_q); |
| 4373 | |
| 4374 | rp = (struct bfa_rport_s *) bfa_meminfo_kva(meminfo); |
| 4375 | mod->rps_list = rp; |
| 4376 | mod->num_rports = cfg->fwcfg.num_rports; |
| 4377 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 4378 | WARN_ON(!mod->num_rports || |
| 4379 | (mod->num_rports & (mod->num_rports - 1))); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4380 | |
| 4381 | for (i = 0; i < mod->num_rports; i++, rp++) { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 4382 | memset(rp, 0, sizeof(struct bfa_rport_s)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4383 | rp->bfa = bfa; |
| 4384 | rp->rport_tag = i; |
| 4385 | bfa_sm_set_state(rp, bfa_rport_sm_uninit); |
| 4386 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4387 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4388 | * - is unused |
| 4389 | */ |
| 4390 | if (i) |
| 4391 | list_add_tail(&rp->qe, &mod->rp_free_q); |
| 4392 | |
| 4393 | bfa_reqq_winit(&rp->reqq_wait, bfa_rport_qresume, rp); |
| 4394 | } |
| 4395 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4396 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4397 | * consume memory |
| 4398 | */ |
| 4399 | bfa_meminfo_kva(meminfo) = (u8 *) rp; |
| 4400 | } |
| 4401 | |
| 4402 | static void |
| 4403 | bfa_rport_detach(struct bfa_s *bfa) |
| 4404 | { |
| 4405 | } |
| 4406 | |
| 4407 | static void |
| 4408 | bfa_rport_start(struct bfa_s *bfa) |
| 4409 | { |
| 4410 | } |
| 4411 | |
| 4412 | static void |
| 4413 | bfa_rport_stop(struct bfa_s *bfa) |
| 4414 | { |
| 4415 | } |
| 4416 | |
| 4417 | static void |
| 4418 | bfa_rport_iocdisable(struct bfa_s *bfa) |
| 4419 | { |
| 4420 | struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa); |
| 4421 | struct bfa_rport_s *rport; |
| 4422 | struct list_head *qe, *qen; |
| 4423 | |
| 4424 | list_for_each_safe(qe, qen, &mod->rp_active_q) { |
| 4425 | rport = (struct bfa_rport_s *) qe; |
| 4426 | bfa_sm_send_event(rport, BFA_RPORT_SM_HWFAIL); |
| 4427 | } |
| 4428 | } |
| 4429 | |
| 4430 | static struct bfa_rport_s * |
| 4431 | bfa_rport_alloc(struct bfa_rport_mod_s *mod) |
| 4432 | { |
| 4433 | struct bfa_rport_s *rport; |
| 4434 | |
| 4435 | bfa_q_deq(&mod->rp_free_q, &rport); |
| 4436 | if (rport) |
| 4437 | list_add_tail(&rport->qe, &mod->rp_active_q); |
| 4438 | |
| 4439 | return rport; |
| 4440 | } |
| 4441 | |
| 4442 | static void |
| 4443 | bfa_rport_free(struct bfa_rport_s *rport) |
| 4444 | { |
| 4445 | struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(rport->bfa); |
| 4446 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 4447 | WARN_ON(!bfa_q_is_on_q(&mod->rp_active_q, rport)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4448 | list_del(&rport->qe); |
| 4449 | list_add_tail(&rport->qe, &mod->rp_free_q); |
| 4450 | } |
| 4451 | |
| 4452 | static bfa_boolean_t |
| 4453 | bfa_rport_send_fwcreate(struct bfa_rport_s *rp) |
| 4454 | { |
| 4455 | struct bfi_rport_create_req_s *m; |
| 4456 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4457 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4458 | * check for room in queue to send request now |
| 4459 | */ |
| 4460 | m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT); |
| 4461 | if (!m) { |
| 4462 | bfa_reqq_wait(rp->bfa, BFA_REQQ_RPORT, &rp->reqq_wait); |
| 4463 | return BFA_FALSE; |
| 4464 | } |
| 4465 | |
| 4466 | bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_CREATE_REQ, |
| 4467 | bfa_lpuid(rp->bfa)); |
| 4468 | m->bfa_handle = rp->rport_tag; |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 4469 | m->max_frmsz = cpu_to_be16(rp->rport_info.max_frmsz); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4470 | m->pid = rp->rport_info.pid; |
| 4471 | m->lp_tag = rp->rport_info.lp_tag; |
| 4472 | m->local_pid = rp->rport_info.local_pid; |
| 4473 | m->fc_class = rp->rport_info.fc_class; |
| 4474 | m->vf_en = rp->rport_info.vf_en; |
| 4475 | m->vf_id = rp->rport_info.vf_id; |
| 4476 | m->cisc = rp->rport_info.cisc; |
| 4477 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4478 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4479 | * queue I/O message to firmware |
| 4480 | */ |
| 4481 | bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT); |
| 4482 | return BFA_TRUE; |
| 4483 | } |
| 4484 | |
| 4485 | static bfa_boolean_t |
| 4486 | bfa_rport_send_fwdelete(struct bfa_rport_s *rp) |
| 4487 | { |
| 4488 | struct bfi_rport_delete_req_s *m; |
| 4489 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4490 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4491 | * check for room in queue to send request now |
| 4492 | */ |
| 4493 | m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT); |
| 4494 | if (!m) { |
| 4495 | bfa_reqq_wait(rp->bfa, BFA_REQQ_RPORT, &rp->reqq_wait); |
| 4496 | return BFA_FALSE; |
| 4497 | } |
| 4498 | |
| 4499 | bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_DELETE_REQ, |
| 4500 | bfa_lpuid(rp->bfa)); |
| 4501 | m->fw_handle = rp->fw_handle; |
| 4502 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4503 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4504 | * queue I/O message to firmware |
| 4505 | */ |
| 4506 | bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT); |
| 4507 | return BFA_TRUE; |
| 4508 | } |
| 4509 | |
| 4510 | static bfa_boolean_t |
| 4511 | bfa_rport_send_fwspeed(struct bfa_rport_s *rp) |
| 4512 | { |
| 4513 | struct bfa_rport_speed_req_s *m; |
| 4514 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4515 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4516 | * check for room in queue to send request now |
| 4517 | */ |
| 4518 | m = bfa_reqq_next(rp->bfa, BFA_REQQ_RPORT); |
| 4519 | if (!m) { |
| 4520 | bfa_trc(rp->bfa, rp->rport_info.speed); |
| 4521 | return BFA_FALSE; |
| 4522 | } |
| 4523 | |
| 4524 | bfi_h2i_set(m->mh, BFI_MC_RPORT, BFI_RPORT_H2I_SET_SPEED_REQ, |
| 4525 | bfa_lpuid(rp->bfa)); |
| 4526 | m->fw_handle = rp->fw_handle; |
| 4527 | m->speed = (u8)rp->rport_info.speed; |
| 4528 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4529 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4530 | * queue I/O message to firmware |
| 4531 | */ |
| 4532 | bfa_reqq_produce(rp->bfa, BFA_REQQ_RPORT); |
| 4533 | return BFA_TRUE; |
| 4534 | } |
| 4535 | |
| 4536 | |
| 4537 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4538 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4539 | * bfa_rport_public |
| 4540 | */ |
| 4541 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4542 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4543 | * Rport interrupt processing. |
| 4544 | */ |
| 4545 | void |
| 4546 | bfa_rport_isr(struct bfa_s *bfa, struct bfi_msg_s *m) |
| 4547 | { |
| 4548 | union bfi_rport_i2h_msg_u msg; |
| 4549 | struct bfa_rport_s *rp; |
| 4550 | |
| 4551 | bfa_trc(bfa, m->mhdr.msg_id); |
| 4552 | |
| 4553 | msg.msg = m; |
| 4554 | |
| 4555 | switch (m->mhdr.msg_id) { |
| 4556 | case BFI_RPORT_I2H_CREATE_RSP: |
| 4557 | rp = BFA_RPORT_FROM_TAG(bfa, msg.create_rsp->bfa_handle); |
| 4558 | rp->fw_handle = msg.create_rsp->fw_handle; |
| 4559 | rp->qos_attr = msg.create_rsp->qos_attr; |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 4560 | WARN_ON(msg.create_rsp->status != BFA_STATUS_OK); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4561 | bfa_sm_send_event(rp, BFA_RPORT_SM_FWRSP); |
| 4562 | break; |
| 4563 | |
| 4564 | case BFI_RPORT_I2H_DELETE_RSP: |
| 4565 | rp = BFA_RPORT_FROM_TAG(bfa, msg.delete_rsp->bfa_handle); |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 4566 | WARN_ON(msg.delete_rsp->status != BFA_STATUS_OK); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4567 | bfa_sm_send_event(rp, BFA_RPORT_SM_FWRSP); |
| 4568 | break; |
| 4569 | |
| 4570 | case BFI_RPORT_I2H_QOS_SCN: |
| 4571 | rp = BFA_RPORT_FROM_TAG(bfa, msg.qos_scn_evt->bfa_handle); |
| 4572 | rp->event_arg.fw_msg = msg.qos_scn_evt; |
| 4573 | bfa_sm_send_event(rp, BFA_RPORT_SM_QOS_SCN); |
| 4574 | break; |
| 4575 | |
| 4576 | default: |
| 4577 | bfa_trc(bfa, m->mhdr.msg_id); |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 4578 | WARN_ON(1); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4579 | } |
| 4580 | } |
| 4581 | |
| 4582 | |
| 4583 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4584 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4585 | * bfa_rport_api |
| 4586 | */ |
| 4587 | |
| 4588 | struct bfa_rport_s * |
| 4589 | bfa_rport_create(struct bfa_s *bfa, void *rport_drv) |
| 4590 | { |
| 4591 | struct bfa_rport_s *rp; |
| 4592 | |
| 4593 | rp = bfa_rport_alloc(BFA_RPORT_MOD(bfa)); |
| 4594 | |
| 4595 | if (rp == NULL) |
| 4596 | return NULL; |
| 4597 | |
| 4598 | rp->bfa = bfa; |
| 4599 | rp->rport_drv = rport_drv; |
Maggie Zhang | f7f7381 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 4600 | memset(&rp->stats, 0, sizeof(rp->stats)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4601 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 4602 | WARN_ON(!bfa_sm_cmp_state(rp, bfa_rport_sm_uninit)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4603 | bfa_sm_send_event(rp, BFA_RPORT_SM_CREATE); |
| 4604 | |
| 4605 | return rp; |
| 4606 | } |
| 4607 | |
| 4608 | void |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4609 | bfa_rport_online(struct bfa_rport_s *rport, struct bfa_rport_info_s *rport_info) |
| 4610 | { |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 4611 | WARN_ON(rport_info->max_frmsz == 0); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4612 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4613 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4614 | * Some JBODs are seen to be not setting PDU size correctly in PLOGI |
| 4615 | * responses. Default to minimum size. |
| 4616 | */ |
| 4617 | if (rport_info->max_frmsz == 0) { |
| 4618 | bfa_trc(rport->bfa, rport->rport_tag); |
| 4619 | rport_info->max_frmsz = FC_MIN_PDUSZ; |
| 4620 | } |
| 4621 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 4622 | rport->rport_info = *rport_info; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4623 | bfa_sm_send_event(rport, BFA_RPORT_SM_ONLINE); |
| 4624 | } |
| 4625 | |
| 4626 | void |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4627 | bfa_rport_speed(struct bfa_rport_s *rport, enum bfa_port_speed speed) |
| 4628 | { |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 4629 | WARN_ON(speed == 0); |
| 4630 | WARN_ON(speed == BFA_PORT_SPEED_AUTO); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4631 | |
| 4632 | rport->rport_info.speed = speed; |
| 4633 | bfa_sm_send_event(rport, BFA_RPORT_SM_SET_SPEED); |
| 4634 | } |
| 4635 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4636 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4637 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4638 | * SGPG related functions |
| 4639 | */ |
| 4640 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4641 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4642 | * Compute and return memory needed by FCP(im) module. |
| 4643 | */ |
| 4644 | static void |
| 4645 | bfa_sgpg_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *km_len, |
| 4646 | u32 *dm_len) |
| 4647 | { |
| 4648 | if (cfg->drvcfg.num_sgpgs < BFA_SGPG_MIN) |
| 4649 | cfg->drvcfg.num_sgpgs = BFA_SGPG_MIN; |
| 4650 | |
| 4651 | *km_len += (cfg->drvcfg.num_sgpgs + 1) * sizeof(struct bfa_sgpg_s); |
| 4652 | *dm_len += (cfg->drvcfg.num_sgpgs + 1) * sizeof(struct bfi_sgpg_s); |
| 4653 | } |
| 4654 | |
| 4655 | |
| 4656 | static void |
| 4657 | bfa_sgpg_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg, |
| 4658 | struct bfa_meminfo_s *minfo, struct bfa_pcidev_s *pcidev) |
| 4659 | { |
| 4660 | struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa); |
| 4661 | int i; |
| 4662 | struct bfa_sgpg_s *hsgpg; |
| 4663 | struct bfi_sgpg_s *sgpg; |
| 4664 | u64 align_len; |
| 4665 | |
| 4666 | union { |
| 4667 | u64 pa; |
| 4668 | union bfi_addr_u addr; |
| 4669 | } sgpg_pa, sgpg_pa_tmp; |
| 4670 | |
| 4671 | INIT_LIST_HEAD(&mod->sgpg_q); |
| 4672 | INIT_LIST_HEAD(&mod->sgpg_wait_q); |
| 4673 | |
| 4674 | bfa_trc(bfa, cfg->drvcfg.num_sgpgs); |
| 4675 | |
| 4676 | mod->num_sgpgs = cfg->drvcfg.num_sgpgs; |
| 4677 | mod->sgpg_arr_pa = bfa_meminfo_dma_phys(minfo); |
| 4678 | align_len = (BFA_SGPG_ROUNDUP(mod->sgpg_arr_pa) - mod->sgpg_arr_pa); |
| 4679 | mod->sgpg_arr_pa += align_len; |
| 4680 | mod->hsgpg_arr = (struct bfa_sgpg_s *) (bfa_meminfo_kva(minfo) + |
| 4681 | align_len); |
| 4682 | mod->sgpg_arr = (struct bfi_sgpg_s *) (bfa_meminfo_dma_virt(minfo) + |
| 4683 | align_len); |
| 4684 | |
| 4685 | hsgpg = mod->hsgpg_arr; |
| 4686 | sgpg = mod->sgpg_arr; |
| 4687 | sgpg_pa.pa = mod->sgpg_arr_pa; |
| 4688 | mod->free_sgpgs = mod->num_sgpgs; |
| 4689 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 4690 | WARN_ON(sgpg_pa.pa & (sizeof(struct bfi_sgpg_s) - 1)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4691 | |
| 4692 | for (i = 0; i < mod->num_sgpgs; i++) { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 4693 | memset(hsgpg, 0, sizeof(*hsgpg)); |
| 4694 | memset(sgpg, 0, sizeof(*sgpg)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4695 | |
| 4696 | hsgpg->sgpg = sgpg; |
| 4697 | sgpg_pa_tmp.pa = bfa_sgaddr_le(sgpg_pa.pa); |
| 4698 | hsgpg->sgpg_pa = sgpg_pa_tmp.addr; |
| 4699 | list_add_tail(&hsgpg->qe, &mod->sgpg_q); |
| 4700 | |
| 4701 | hsgpg++; |
| 4702 | sgpg++; |
| 4703 | sgpg_pa.pa += sizeof(struct bfi_sgpg_s); |
| 4704 | } |
| 4705 | |
| 4706 | bfa_meminfo_kva(minfo) = (u8 *) hsgpg; |
| 4707 | bfa_meminfo_dma_virt(minfo) = (u8 *) sgpg; |
| 4708 | bfa_meminfo_dma_phys(minfo) = sgpg_pa.pa; |
| 4709 | } |
| 4710 | |
| 4711 | static void |
| 4712 | bfa_sgpg_detach(struct bfa_s *bfa) |
| 4713 | { |
| 4714 | } |
| 4715 | |
| 4716 | static void |
| 4717 | bfa_sgpg_start(struct bfa_s *bfa) |
| 4718 | { |
| 4719 | } |
| 4720 | |
| 4721 | static void |
| 4722 | bfa_sgpg_stop(struct bfa_s *bfa) |
| 4723 | { |
| 4724 | } |
| 4725 | |
| 4726 | static void |
| 4727 | bfa_sgpg_iocdisable(struct bfa_s *bfa) |
| 4728 | { |
| 4729 | } |
| 4730 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4731 | bfa_status_t |
| 4732 | bfa_sgpg_malloc(struct bfa_s *bfa, struct list_head *sgpg_q, int nsgpgs) |
| 4733 | { |
| 4734 | struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa); |
| 4735 | struct bfa_sgpg_s *hsgpg; |
| 4736 | int i; |
| 4737 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4738 | if (mod->free_sgpgs < nsgpgs) |
| 4739 | return BFA_STATUS_ENOMEM; |
| 4740 | |
| 4741 | for (i = 0; i < nsgpgs; i++) { |
| 4742 | bfa_q_deq(&mod->sgpg_q, &hsgpg); |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 4743 | WARN_ON(!hsgpg); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4744 | list_add_tail(&hsgpg->qe, sgpg_q); |
| 4745 | } |
| 4746 | |
| 4747 | mod->free_sgpgs -= nsgpgs; |
| 4748 | return BFA_STATUS_OK; |
| 4749 | } |
| 4750 | |
| 4751 | void |
| 4752 | bfa_sgpg_mfree(struct bfa_s *bfa, struct list_head *sgpg_q, int nsgpg) |
| 4753 | { |
| 4754 | struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa); |
| 4755 | struct bfa_sgpg_wqe_s *wqe; |
| 4756 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4757 | mod->free_sgpgs += nsgpg; |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 4758 | WARN_ON(mod->free_sgpgs > mod->num_sgpgs); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4759 | |
| 4760 | list_splice_tail_init(sgpg_q, &mod->sgpg_q); |
| 4761 | |
| 4762 | if (list_empty(&mod->sgpg_wait_q)) |
| 4763 | return; |
| 4764 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4765 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4766 | * satisfy as many waiting requests as possible |
| 4767 | */ |
| 4768 | do { |
| 4769 | wqe = bfa_q_first(&mod->sgpg_wait_q); |
| 4770 | if (mod->free_sgpgs < wqe->nsgpg) |
| 4771 | nsgpg = mod->free_sgpgs; |
| 4772 | else |
| 4773 | nsgpg = wqe->nsgpg; |
| 4774 | bfa_sgpg_malloc(bfa, &wqe->sgpg_q, nsgpg); |
| 4775 | wqe->nsgpg -= nsgpg; |
| 4776 | if (wqe->nsgpg == 0) { |
| 4777 | list_del(&wqe->qe); |
| 4778 | wqe->cbfn(wqe->cbarg); |
| 4779 | } |
| 4780 | } while (mod->free_sgpgs && !list_empty(&mod->sgpg_wait_q)); |
| 4781 | } |
| 4782 | |
| 4783 | void |
| 4784 | bfa_sgpg_wait(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe, int nsgpg) |
| 4785 | { |
| 4786 | struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa); |
| 4787 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 4788 | WARN_ON(nsgpg <= 0); |
| 4789 | WARN_ON(nsgpg <= mod->free_sgpgs); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4790 | |
| 4791 | wqe->nsgpg_total = wqe->nsgpg = nsgpg; |
| 4792 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4793 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4794 | * allocate any left to this one first |
| 4795 | */ |
| 4796 | if (mod->free_sgpgs) { |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4797 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4798 | * no one else is waiting for SGPG |
| 4799 | */ |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 4800 | WARN_ON(!list_empty(&mod->sgpg_wait_q)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4801 | list_splice_tail_init(&mod->sgpg_q, &wqe->sgpg_q); |
| 4802 | wqe->nsgpg -= mod->free_sgpgs; |
| 4803 | mod->free_sgpgs = 0; |
| 4804 | } |
| 4805 | |
| 4806 | list_add_tail(&wqe->qe, &mod->sgpg_wait_q); |
| 4807 | } |
| 4808 | |
| 4809 | void |
| 4810 | bfa_sgpg_wcancel(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe) |
| 4811 | { |
| 4812 | struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa); |
| 4813 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 4814 | WARN_ON(!bfa_q_is_on_q(&mod->sgpg_wait_q, wqe)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4815 | list_del(&wqe->qe); |
| 4816 | |
| 4817 | if (wqe->nsgpg_total != wqe->nsgpg) |
| 4818 | bfa_sgpg_mfree(bfa, &wqe->sgpg_q, |
| 4819 | wqe->nsgpg_total - wqe->nsgpg); |
| 4820 | } |
| 4821 | |
| 4822 | void |
| 4823 | bfa_sgpg_winit(struct bfa_sgpg_wqe_s *wqe, void (*cbfn) (void *cbarg), |
| 4824 | void *cbarg) |
| 4825 | { |
| 4826 | INIT_LIST_HEAD(&wqe->sgpg_q); |
| 4827 | wqe->cbfn = cbfn; |
| 4828 | wqe->cbarg = cbarg; |
| 4829 | } |
| 4830 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4831 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4832 | * UF related functions |
| 4833 | */ |
| 4834 | /* |
| 4835 | ***************************************************************************** |
| 4836 | * Internal functions |
| 4837 | ***************************************************************************** |
| 4838 | */ |
| 4839 | static void |
| 4840 | __bfa_cb_uf_recv(void *cbarg, bfa_boolean_t complete) |
| 4841 | { |
| 4842 | struct bfa_uf_s *uf = cbarg; |
| 4843 | struct bfa_uf_mod_s *ufm = BFA_UF_MOD(uf->bfa); |
| 4844 | |
| 4845 | if (complete) |
| 4846 | ufm->ufrecv(ufm->cbarg, uf); |
| 4847 | } |
| 4848 | |
| 4849 | static void |
| 4850 | claim_uf_pbs(struct bfa_uf_mod_s *ufm, struct bfa_meminfo_s *mi) |
| 4851 | { |
| 4852 | u32 uf_pb_tot_sz; |
| 4853 | |
| 4854 | ufm->uf_pbs_kva = (struct bfa_uf_buf_s *) bfa_meminfo_dma_virt(mi); |
| 4855 | ufm->uf_pbs_pa = bfa_meminfo_dma_phys(mi); |
| 4856 | uf_pb_tot_sz = BFA_ROUNDUP((sizeof(struct bfa_uf_buf_s) * ufm->num_ufs), |
| 4857 | BFA_DMA_ALIGN_SZ); |
| 4858 | |
| 4859 | bfa_meminfo_dma_virt(mi) += uf_pb_tot_sz; |
| 4860 | bfa_meminfo_dma_phys(mi) += uf_pb_tot_sz; |
| 4861 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 4862 | memset((void *)ufm->uf_pbs_kva, 0, uf_pb_tot_sz); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4863 | } |
| 4864 | |
| 4865 | static void |
| 4866 | claim_uf_post_msgs(struct bfa_uf_mod_s *ufm, struct bfa_meminfo_s *mi) |
| 4867 | { |
| 4868 | struct bfi_uf_buf_post_s *uf_bp_msg; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4869 | u16 i; |
| 4870 | u16 buf_len; |
| 4871 | |
| 4872 | ufm->uf_buf_posts = (struct bfi_uf_buf_post_s *) bfa_meminfo_kva(mi); |
| 4873 | uf_bp_msg = ufm->uf_buf_posts; |
| 4874 | |
| 4875 | for (i = 0, uf_bp_msg = ufm->uf_buf_posts; i < ufm->num_ufs; |
| 4876 | i++, uf_bp_msg++) { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 4877 | memset(uf_bp_msg, 0, sizeof(struct bfi_uf_buf_post_s)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4878 | |
| 4879 | uf_bp_msg->buf_tag = i; |
| 4880 | buf_len = sizeof(struct bfa_uf_buf_s); |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 4881 | uf_bp_msg->buf_len = cpu_to_be16(buf_len); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4882 | bfi_h2i_set(uf_bp_msg->mh, BFI_MC_UF, BFI_UF_H2I_BUF_POST, |
| 4883 | bfa_lpuid(ufm->bfa)); |
Krishna Gudipati | 85ce928 | 2011-06-13 15:39:36 -0700 | [diff] [blame] | 4884 | 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] | 4885 | } |
| 4886 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4887 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4888 | * advance pointer beyond consumed memory |
| 4889 | */ |
| 4890 | bfa_meminfo_kva(mi) = (u8 *) uf_bp_msg; |
| 4891 | } |
| 4892 | |
| 4893 | static void |
| 4894 | claim_ufs(struct bfa_uf_mod_s *ufm, struct bfa_meminfo_s *mi) |
| 4895 | { |
| 4896 | u16 i; |
| 4897 | struct bfa_uf_s *uf; |
| 4898 | |
| 4899 | /* |
| 4900 | * Claim block of memory for UF list |
| 4901 | */ |
| 4902 | ufm->uf_list = (struct bfa_uf_s *) bfa_meminfo_kva(mi); |
| 4903 | |
| 4904 | /* |
| 4905 | * Initialize UFs and queue it in UF free queue |
| 4906 | */ |
| 4907 | 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] | 4908 | memset(uf, 0, sizeof(struct bfa_uf_s)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4909 | uf->bfa = ufm->bfa; |
| 4910 | uf->uf_tag = i; |
| 4911 | uf->pb_len = sizeof(struct bfa_uf_buf_s); |
| 4912 | uf->buf_kva = (void *)&ufm->uf_pbs_kva[i]; |
| 4913 | uf->buf_pa = ufm_pbs_pa(ufm, i); |
| 4914 | list_add_tail(&uf->qe, &ufm->uf_free_q); |
| 4915 | } |
| 4916 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 4917 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4918 | * advance memory pointer |
| 4919 | */ |
| 4920 | bfa_meminfo_kva(mi) = (u8 *) uf; |
| 4921 | } |
| 4922 | |
| 4923 | static void |
| 4924 | uf_mem_claim(struct bfa_uf_mod_s *ufm, struct bfa_meminfo_s *mi) |
| 4925 | { |
| 4926 | claim_uf_pbs(ufm, mi); |
| 4927 | claim_ufs(ufm, mi); |
| 4928 | claim_uf_post_msgs(ufm, mi); |
| 4929 | } |
| 4930 | |
| 4931 | static void |
| 4932 | bfa_uf_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *ndm_len, u32 *dm_len) |
| 4933 | { |
| 4934 | u32 num_ufs = cfg->fwcfg.num_uf_bufs; |
| 4935 | |
| 4936 | /* |
| 4937 | * dma-able memory for UF posted bufs |
| 4938 | */ |
| 4939 | *dm_len += BFA_ROUNDUP((sizeof(struct bfa_uf_buf_s) * num_ufs), |
| 4940 | BFA_DMA_ALIGN_SZ); |
| 4941 | |
| 4942 | /* |
| 4943 | * kernel Virtual memory for UFs and UF buf post msg copies |
| 4944 | */ |
| 4945 | *ndm_len += sizeof(struct bfa_uf_s) * num_ufs; |
| 4946 | *ndm_len += sizeof(struct bfi_uf_buf_post_s) * num_ufs; |
| 4947 | } |
| 4948 | |
| 4949 | static void |
| 4950 | bfa_uf_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg, |
| 4951 | struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev) |
| 4952 | { |
| 4953 | struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa); |
| 4954 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 4955 | memset(ufm, 0, sizeof(struct bfa_uf_mod_s)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4956 | ufm->bfa = bfa; |
| 4957 | ufm->num_ufs = cfg->fwcfg.num_uf_bufs; |
| 4958 | INIT_LIST_HEAD(&ufm->uf_free_q); |
| 4959 | INIT_LIST_HEAD(&ufm->uf_posted_q); |
| 4960 | |
| 4961 | uf_mem_claim(ufm, meminfo); |
| 4962 | } |
| 4963 | |
| 4964 | static void |
| 4965 | bfa_uf_detach(struct bfa_s *bfa) |
| 4966 | { |
| 4967 | } |
| 4968 | |
| 4969 | static struct bfa_uf_s * |
| 4970 | bfa_uf_get(struct bfa_uf_mod_s *uf_mod) |
| 4971 | { |
| 4972 | struct bfa_uf_s *uf; |
| 4973 | |
| 4974 | bfa_q_deq(&uf_mod->uf_free_q, &uf); |
| 4975 | return uf; |
| 4976 | } |
| 4977 | |
| 4978 | static void |
| 4979 | bfa_uf_put(struct bfa_uf_mod_s *uf_mod, struct bfa_uf_s *uf) |
| 4980 | { |
| 4981 | list_add_tail(&uf->qe, &uf_mod->uf_free_q); |
| 4982 | } |
| 4983 | |
| 4984 | static bfa_status_t |
| 4985 | bfa_uf_post(struct bfa_uf_mod_s *ufm, struct bfa_uf_s *uf) |
| 4986 | { |
| 4987 | struct bfi_uf_buf_post_s *uf_post_msg; |
| 4988 | |
| 4989 | uf_post_msg = bfa_reqq_next(ufm->bfa, BFA_REQQ_FCXP); |
| 4990 | if (!uf_post_msg) |
| 4991 | return BFA_STATUS_FAILED; |
| 4992 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 4993 | memcpy(uf_post_msg, &ufm->uf_buf_posts[uf->uf_tag], |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 4994 | sizeof(struct bfi_uf_buf_post_s)); |
| 4995 | bfa_reqq_produce(ufm->bfa, BFA_REQQ_FCXP); |
| 4996 | |
| 4997 | bfa_trc(ufm->bfa, uf->uf_tag); |
| 4998 | |
| 4999 | list_add_tail(&uf->qe, &ufm->uf_posted_q); |
| 5000 | return BFA_STATUS_OK; |
| 5001 | } |
| 5002 | |
| 5003 | static void |
| 5004 | bfa_uf_post_all(struct bfa_uf_mod_s *uf_mod) |
| 5005 | { |
| 5006 | struct bfa_uf_s *uf; |
| 5007 | |
| 5008 | while ((uf = bfa_uf_get(uf_mod)) != NULL) { |
| 5009 | if (bfa_uf_post(uf_mod, uf) != BFA_STATUS_OK) |
| 5010 | break; |
| 5011 | } |
| 5012 | } |
| 5013 | |
| 5014 | static void |
| 5015 | uf_recv(struct bfa_s *bfa, struct bfi_uf_frm_rcvd_s *m) |
| 5016 | { |
| 5017 | struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa); |
| 5018 | u16 uf_tag = m->buf_tag; |
| 5019 | struct bfa_uf_buf_s *uf_buf = &ufm->uf_pbs_kva[uf_tag]; |
| 5020 | struct bfa_uf_s *uf = &ufm->uf_list[uf_tag]; |
| 5021 | u8 *buf = &uf_buf->d[0]; |
| 5022 | struct fchs_s *fchs; |
| 5023 | |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 5024 | m->frm_len = be16_to_cpu(m->frm_len); |
| 5025 | m->xfr_len = be16_to_cpu(m->xfr_len); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5026 | |
| 5027 | fchs = (struct fchs_s *)uf_buf; |
| 5028 | |
| 5029 | list_del(&uf->qe); /* dequeue from posted queue */ |
| 5030 | |
| 5031 | uf->data_ptr = buf; |
| 5032 | uf->data_len = m->xfr_len; |
| 5033 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 5034 | WARN_ON(uf->data_len < sizeof(struct fchs_s)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5035 | |
| 5036 | if (uf->data_len == sizeof(struct fchs_s)) { |
| 5037 | bfa_plog_fchdr(bfa->plog, BFA_PL_MID_HAL_UF, BFA_PL_EID_RX, |
| 5038 | uf->data_len, (struct fchs_s *)buf); |
| 5039 | } else { |
| 5040 | u32 pld_w0 = *((u32 *) (buf + sizeof(struct fchs_s))); |
| 5041 | bfa_plog_fchdr_and_pl(bfa->plog, BFA_PL_MID_HAL_UF, |
| 5042 | BFA_PL_EID_RX, uf->data_len, |
| 5043 | (struct fchs_s *)buf, pld_w0); |
| 5044 | } |
| 5045 | |
| 5046 | if (bfa->fcs) |
| 5047 | __bfa_cb_uf_recv(uf, BFA_TRUE); |
| 5048 | else |
| 5049 | bfa_cb_queue(bfa, &uf->hcb_qe, __bfa_cb_uf_recv, uf); |
| 5050 | } |
| 5051 | |
| 5052 | static void |
| 5053 | bfa_uf_stop(struct bfa_s *bfa) |
| 5054 | { |
| 5055 | } |
| 5056 | |
| 5057 | static void |
| 5058 | bfa_uf_iocdisable(struct bfa_s *bfa) |
| 5059 | { |
| 5060 | struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa); |
| 5061 | struct bfa_uf_s *uf; |
| 5062 | struct list_head *qe, *qen; |
| 5063 | |
| 5064 | list_for_each_safe(qe, qen, &ufm->uf_posted_q) { |
| 5065 | uf = (struct bfa_uf_s *) qe; |
| 5066 | list_del(&uf->qe); |
| 5067 | bfa_uf_put(ufm, uf); |
| 5068 | } |
| 5069 | } |
| 5070 | |
| 5071 | static void |
| 5072 | bfa_uf_start(struct bfa_s *bfa) |
| 5073 | { |
| 5074 | bfa_uf_post_all(BFA_UF_MOD(bfa)); |
| 5075 | } |
| 5076 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 5077 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 5078 | * Register handler for all unsolicted receive frames. |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5079 | * |
| 5080 | * @param[in] bfa BFA instance |
| 5081 | * @param[in] ufrecv receive handler function |
| 5082 | * @param[in] cbarg receive handler arg |
| 5083 | */ |
| 5084 | void |
| 5085 | bfa_uf_recv_register(struct bfa_s *bfa, bfa_cb_uf_recv_t ufrecv, void *cbarg) |
| 5086 | { |
| 5087 | struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa); |
| 5088 | |
| 5089 | ufm->ufrecv = ufrecv; |
| 5090 | ufm->cbarg = cbarg; |
| 5091 | } |
| 5092 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 5093 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5094 | * Free an unsolicited frame back to BFA. |
| 5095 | * |
| 5096 | * @param[in] uf unsolicited frame to be freed |
| 5097 | * |
| 5098 | * @return None |
| 5099 | */ |
| 5100 | void |
| 5101 | bfa_uf_free(struct bfa_uf_s *uf) |
| 5102 | { |
| 5103 | bfa_uf_put(BFA_UF_MOD(uf->bfa), uf); |
| 5104 | bfa_uf_post_all(BFA_UF_MOD(uf->bfa)); |
| 5105 | } |
| 5106 | |
| 5107 | |
| 5108 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 5109 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5110 | * uf_pub BFA uf module public functions |
| 5111 | */ |
| 5112 | void |
| 5113 | bfa_uf_isr(struct bfa_s *bfa, struct bfi_msg_s *msg) |
| 5114 | { |
| 5115 | bfa_trc(bfa, msg->mhdr.msg_id); |
| 5116 | |
| 5117 | switch (msg->mhdr.msg_id) { |
| 5118 | case BFI_UF_I2H_FRM_RCVD: |
| 5119 | uf_recv(bfa, (struct bfi_uf_frm_rcvd_s *) msg); |
| 5120 | break; |
| 5121 | |
| 5122 | default: |
| 5123 | bfa_trc(bfa, msg->mhdr.msg_id); |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 5124 | WARN_ON(1); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 5125 | } |
| 5126 | } |
| 5127 | |
| 5128 | |