123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759 |
- /*
- * Copyright (c) 2005-2009 Brocade Communications Systems, Inc.
- * All rights reserved
- * www.brocade.com
- *
- * Linux driver for Brocade Fibre Channel Host Bus Adapter.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License (GPL) Version 2 as
- * published by the Free Software Foundation
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- */
- #include <bfa.h>
- #include <bfa_svc.h>
- #include "fcs_lport.h"
- #include "fcs_rport.h"
- #include "fcs_trcmod.h"
- #include "fcs_fcxp.h"
- #include "lport_priv.h"
- BFA_TRC_FILE(FCS, MS);
- #define BFA_FCS_MS_CMD_MAX_RETRIES 2
- /*
- * forward declarations
- */
- static void bfa_fcs_port_ms_send_plogi(void *ms_cbarg,
- struct bfa_fcxp_s *fcxp_alloced);
- static void bfa_fcs_port_ms_timeout(void *arg);
- static void bfa_fcs_port_ms_plogi_response(void *fcsarg,
- struct bfa_fcxp_s *fcxp,
- void *cbarg,
- bfa_status_t req_status,
- u32 rsp_len,
- u32 resid_len,
- struct fchs_s *rsp_fchs);
- static void bfa_fcs_port_ms_send_gmal(void *ms_cbarg,
- struct bfa_fcxp_s *fcxp_alloced);
- static void bfa_fcs_port_ms_gmal_response(void *fcsarg,
- struct bfa_fcxp_s *fcxp,
- void *cbarg,
- bfa_status_t req_status,
- u32 rsp_len,
- u32 resid_len,
- struct fchs_s *rsp_fchs);
- static void bfa_fcs_port_ms_send_gfn(void *ms_cbarg,
- struct bfa_fcxp_s *fcxp_alloced);
- static void bfa_fcs_port_ms_gfn_response(void *fcsarg,
- struct bfa_fcxp_s *fcxp,
- void *cbarg,
- bfa_status_t req_status,
- u32 rsp_len,
- u32 resid_len,
- struct fchs_s *rsp_fchs);
- /**
- * fcs_ms_sm FCS MS state machine
- */
- /**
- * MS State Machine events
- */
- enum port_ms_event {
- MSSM_EVENT_PORT_ONLINE = 1,
- MSSM_EVENT_PORT_OFFLINE = 2,
- MSSM_EVENT_RSP_OK = 3,
- MSSM_EVENT_RSP_ERROR = 4,
- MSSM_EVENT_TIMEOUT = 5,
- MSSM_EVENT_FCXP_SENT = 6,
- MSSM_EVENT_PORT_FABRIC_RSCN = 7
- };
- static void bfa_fcs_port_ms_sm_offline(struct bfa_fcs_port_ms_s *ms,
- enum port_ms_event event);
- static void bfa_fcs_port_ms_sm_plogi_sending(struct bfa_fcs_port_ms_s *ms,
- enum port_ms_event event);
- static void bfa_fcs_port_ms_sm_plogi(struct bfa_fcs_port_ms_s *ms,
- enum port_ms_event event);
- static void bfa_fcs_port_ms_sm_plogi_retry(struct bfa_fcs_port_ms_s *ms,
- enum port_ms_event event);
- static void bfa_fcs_port_ms_sm_gmal_sending(struct bfa_fcs_port_ms_s *ms,
- enum port_ms_event event);
- static void bfa_fcs_port_ms_sm_gmal(struct bfa_fcs_port_ms_s *ms,
- enum port_ms_event event);
- static void bfa_fcs_port_ms_sm_gmal_retry(struct bfa_fcs_port_ms_s *ms,
- enum port_ms_event event);
- static void bfa_fcs_port_ms_sm_gfn_sending(struct bfa_fcs_port_ms_s *ms,
- enum port_ms_event event);
- static void bfa_fcs_port_ms_sm_gfn(struct bfa_fcs_port_ms_s *ms,
- enum port_ms_event event);
- static void bfa_fcs_port_ms_sm_gfn_retry(struct bfa_fcs_port_ms_s *ms,
- enum port_ms_event event);
- static void bfa_fcs_port_ms_sm_online(struct bfa_fcs_port_ms_s *ms,
- enum port_ms_event event);
- /**
- * Start in offline state - awaiting NS to send start.
- */
- static void
- bfa_fcs_port_ms_sm_offline(struct bfa_fcs_port_ms_s *ms,
- enum port_ms_event event)
- {
- bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
- bfa_trc(ms->port->fcs, event);
- switch (event) {
- case MSSM_EVENT_PORT_ONLINE:
- bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_plogi_sending);
- bfa_fcs_port_ms_send_plogi(ms, NULL);
- break;
- case MSSM_EVENT_PORT_OFFLINE:
- break;
- default:
- bfa_assert(0);
- }
- }
- static void
- bfa_fcs_port_ms_sm_plogi_sending(struct bfa_fcs_port_ms_s *ms,
- enum port_ms_event event)
- {
- bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
- bfa_trc(ms->port->fcs, event);
- switch (event) {
- case MSSM_EVENT_FCXP_SENT:
- bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_plogi);
- break;
- case MSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_offline);
- bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
- &ms->fcxp_wqe);
- break;
- default:
- bfa_assert(0);
- }
- }
- static void
- bfa_fcs_port_ms_sm_plogi(struct bfa_fcs_port_ms_s *ms, enum port_ms_event event)
- {
- bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
- bfa_trc(ms->port->fcs, event);
- switch (event) {
- case MSSM_EVENT_RSP_ERROR:
- /*
- * Start timer for a delayed retry
- */
- bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_plogi_retry);
- bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ms->port), &ms->timer,
- bfa_fcs_port_ms_timeout, ms,
- BFA_FCS_RETRY_TIMEOUT);
- break;
- case MSSM_EVENT_RSP_OK:
- /*
- * since plogi is done, now invoke MS related sub-modules
- */
- bfa_fcs_port_fdmi_online(ms);
- /**
- * if this is a Vport, go to online state.
- */
- if (ms->port->vport) {
- bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_online);
- break;
- }
- /*
- * For a base port we need to get the
- * switch's IP address.
- */
- bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_gmal_sending);
- bfa_fcs_port_ms_send_gmal(ms, NULL);
- break;
- case MSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_offline);
- bfa_fcxp_discard(ms->fcxp);
- break;
- default:
- bfa_assert(0);
- }
- }
- static void
- bfa_fcs_port_ms_sm_plogi_retry(struct bfa_fcs_port_ms_s *ms,
- enum port_ms_event event)
- {
- bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
- bfa_trc(ms->port->fcs, event);
- switch (event) {
- case MSSM_EVENT_TIMEOUT:
- /*
- * Retry Timer Expired. Re-send
- */
- bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_plogi_sending);
- bfa_fcs_port_ms_send_plogi(ms, NULL);
- break;
- case MSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_offline);
- bfa_timer_stop(&ms->timer);
- break;
- default:
- bfa_assert(0);
- }
- }
- static void
- bfa_fcs_port_ms_sm_online(struct bfa_fcs_port_ms_s *ms,
- enum port_ms_event event)
- {
- bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
- bfa_trc(ms->port->fcs, event);
- switch (event) {
- case MSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_offline);
- /*
- * now invoke MS related sub-modules
- */
- bfa_fcs_port_fdmi_offline(ms);
- break;
- case MSSM_EVENT_PORT_FABRIC_RSCN:
- bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_gfn_sending);
- ms->retry_cnt = 0;
- bfa_fcs_port_ms_send_gfn(ms, NULL);
- break;
- default:
- bfa_assert(0);
- }
- }
- static void
- bfa_fcs_port_ms_sm_gmal_sending(struct bfa_fcs_port_ms_s *ms,
- enum port_ms_event event)
- {
- bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
- bfa_trc(ms->port->fcs, event);
- switch (event) {
- case MSSM_EVENT_FCXP_SENT:
- bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_gmal);
- break;
- case MSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_offline);
- bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
- &ms->fcxp_wqe);
- break;
- default:
- bfa_assert(0);
- }
- }
- static void
- bfa_fcs_port_ms_sm_gmal(struct bfa_fcs_port_ms_s *ms, enum port_ms_event event)
- {
- bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
- bfa_trc(ms->port->fcs, event);
- switch (event) {
- case MSSM_EVENT_RSP_ERROR:
- /*
- * Start timer for a delayed retry
- */
- if (ms->retry_cnt++ < BFA_FCS_MS_CMD_MAX_RETRIES) {
- bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_gmal_retry);
- bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
- &ms->timer, bfa_fcs_port_ms_timeout, ms,
- BFA_FCS_RETRY_TIMEOUT);
- } else {
- bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_gfn_sending);
- bfa_fcs_port_ms_send_gfn(ms, NULL);
- ms->retry_cnt = 0;
- }
- break;
- case MSSM_EVENT_RSP_OK:
- bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_gfn_sending);
- bfa_fcs_port_ms_send_gfn(ms, NULL);
- break;
- case MSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_offline);
- bfa_fcxp_discard(ms->fcxp);
- break;
- default:
- bfa_assert(0);
- }
- }
- static void
- bfa_fcs_port_ms_sm_gmal_retry(struct bfa_fcs_port_ms_s *ms,
- enum port_ms_event event)
- {
- bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
- bfa_trc(ms->port->fcs, event);
- switch (event) {
- case MSSM_EVENT_TIMEOUT:
- /*
- * Retry Timer Expired. Re-send
- */
- bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_gmal_sending);
- bfa_fcs_port_ms_send_gmal(ms, NULL);
- break;
- case MSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_offline);
- bfa_timer_stop(&ms->timer);
- break;
- default:
- bfa_assert(0);
- }
- }
- /**
- * ms_pvt MS local functions
- */
- static void
- bfa_fcs_port_ms_send_gmal(void *ms_cbarg, struct bfa_fcxp_s *fcxp_alloced)
- {
- struct bfa_fcs_port_ms_s *ms = ms_cbarg;
- struct bfa_fcs_port_s *port = ms->port;
- struct fchs_s fchs;
- int len;
- struct bfa_fcxp_s *fcxp;
- bfa_trc(port->fcs, port->pid);
- fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs);
- if (!fcxp) {
- bfa_fcxp_alloc_wait(port->fcs->bfa, &ms->fcxp_wqe,
- bfa_fcs_port_ms_send_gmal, ms);
- return;
- }
- ms->fcxp = fcxp;
- len = fc_gmal_req_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
- bfa_fcs_port_get_fcid(port),
- bfa_lps_get_peer_nwwn(port->fabric->lps));
- bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
- FC_CLASS_3, len, &fchs, bfa_fcs_port_ms_gmal_response,
- (void *)ms, FC_MAX_PDUSZ, FC_RA_TOV);
- bfa_sm_send_event(ms, MSSM_EVENT_FCXP_SENT);
- }
- static void
- bfa_fcs_port_ms_gmal_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
- void *cbarg, bfa_status_t req_status,
- u32 rsp_len, u32 resid_len,
- struct fchs_s *rsp_fchs)
- {
- struct bfa_fcs_port_ms_s *ms = (struct bfa_fcs_port_ms_s *)cbarg;
- struct bfa_fcs_port_s *port = ms->port;
- struct ct_hdr_s *cthdr = NULL;
- struct fcgs_gmal_resp_s *gmal_resp;
- struct fc_gmal_entry_s *gmal_entry;
- u32 num_entries;
- u8 *rsp_str;
- bfa_trc(port->fcs, req_status);
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- /*
- * Sanity Checks
- */
- if (req_status != BFA_STATUS_OK) {
- bfa_trc(port->fcs, req_status);
- bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
- return;
- }
- cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
- cthdr->cmd_rsp_code = bfa_os_ntohs(cthdr->cmd_rsp_code);
- if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
- gmal_resp = (struct fcgs_gmal_resp_s *)(cthdr + 1);
- num_entries = bfa_os_ntohl(gmal_resp->ms_len);
- if (num_entries == 0) {
- bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
- return;
- }
- /*
- * The response could contain multiple Entries.
- * Entries for SNMP interface, etc.
- * We look for the entry with a telnet prefix.
- * First "http://" entry refers to IP addr
- */
- gmal_entry = (struct fc_gmal_entry_s *)gmal_resp->ms_ma;
- while (num_entries > 0) {
- if (strncmp
- (gmal_entry->prefix, CT_GMAL_RESP_PREFIX_HTTP,
- sizeof(gmal_entry->prefix)) == 0) {
- /*
- * if the IP address is terminating with a '/',
- * remove it. *Byte 0 consists of the length
- * of the string.
- */
- rsp_str = &(gmal_entry->prefix[0]);
- if (rsp_str[gmal_entry->len - 1] == '/')
- rsp_str[gmal_entry->len - 1] = 0;
- /*
- * copy IP Address to fabric
- */
- strncpy(bfa_fcs_port_get_fabric_ipaddr(port),
- gmal_entry->ip_addr,
- BFA_FCS_FABRIC_IPADDR_SZ);
- break;
- } else {
- --num_entries;
- ++gmal_entry;
- }
- }
- bfa_sm_send_event(ms, MSSM_EVENT_RSP_OK);
- return;
- }
- bfa_trc(port->fcs, cthdr->reason_code);
- bfa_trc(port->fcs, cthdr->exp_code);
- bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
- }
- static void
- bfa_fcs_port_ms_sm_gfn_sending(struct bfa_fcs_port_ms_s *ms,
- enum port_ms_event event)
- {
- bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
- bfa_trc(ms->port->fcs, event);
- switch (event) {
- case MSSM_EVENT_FCXP_SENT:
- bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_gfn);
- break;
- case MSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_offline);
- bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
- &ms->fcxp_wqe);
- break;
- default:
- bfa_assert(0);
- }
- }
- static void
- bfa_fcs_port_ms_sm_gfn(struct bfa_fcs_port_ms_s *ms, enum port_ms_event event)
- {
- bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
- bfa_trc(ms->port->fcs, event);
- switch (event) {
- case MSSM_EVENT_RSP_ERROR:
- /*
- * Start timer for a delayed retry
- */
- if (ms->retry_cnt++ < BFA_FCS_MS_CMD_MAX_RETRIES) {
- bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_gfn_retry);
- bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
- &ms->timer, bfa_fcs_port_ms_timeout, ms,
- BFA_FCS_RETRY_TIMEOUT);
- } else {
- bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_online);
- ms->retry_cnt = 0;
- }
- break;
- case MSSM_EVENT_RSP_OK:
- bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_online);
- break;
- case MSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_offline);
- bfa_fcxp_discard(ms->fcxp);
- break;
- default:
- bfa_assert(0);
- }
- }
- static void
- bfa_fcs_port_ms_sm_gfn_retry(struct bfa_fcs_port_ms_s *ms,
- enum port_ms_event event)
- {
- bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
- bfa_trc(ms->port->fcs, event);
- switch (event) {
- case MSSM_EVENT_TIMEOUT:
- /*
- * Retry Timer Expired. Re-send
- */
- bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_gfn_sending);
- bfa_fcs_port_ms_send_gfn(ms, NULL);
- break;
- case MSSM_EVENT_PORT_OFFLINE:
- bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_offline);
- bfa_timer_stop(&ms->timer);
- break;
- default:
- bfa_assert(0);
- }
- }
- /**
- * ms_pvt MS local functions
- */
- static void
- bfa_fcs_port_ms_send_gfn(void *ms_cbarg, struct bfa_fcxp_s *fcxp_alloced)
- {
- struct bfa_fcs_port_ms_s *ms = ms_cbarg;
- struct bfa_fcs_port_s *port = ms->port;
- struct fchs_s fchs;
- int len;
- struct bfa_fcxp_s *fcxp;
- bfa_trc(port->fcs, port->pid);
- fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs);
- if (!fcxp) {
- bfa_fcxp_alloc_wait(port->fcs->bfa, &ms->fcxp_wqe,
- bfa_fcs_port_ms_send_gfn, ms);
- return;
- }
- ms->fcxp = fcxp;
- len = fc_gfn_req_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
- bfa_fcs_port_get_fcid(port),
- bfa_lps_get_peer_nwwn(port->fabric->lps));
- bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
- FC_CLASS_3, len, &fchs, bfa_fcs_port_ms_gfn_response,
- (void *)ms, FC_MAX_PDUSZ, FC_RA_TOV);
- bfa_sm_send_event(ms, MSSM_EVENT_FCXP_SENT);
- }
- static void
- bfa_fcs_port_ms_gfn_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
- bfa_status_t req_status, u32 rsp_len,
- u32 resid_len, struct fchs_s *rsp_fchs)
- {
- struct bfa_fcs_port_ms_s *ms = (struct bfa_fcs_port_ms_s *)cbarg;
- struct bfa_fcs_port_s *port = ms->port;
- struct ct_hdr_s *cthdr = NULL;
- wwn_t *gfn_resp;
- bfa_trc(port->fcs, req_status);
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- /*
- * Sanity Checks
- */
- if (req_status != BFA_STATUS_OK) {
- bfa_trc(port->fcs, req_status);
- bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
- return;
- }
- cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
- cthdr->cmd_rsp_code = bfa_os_ntohs(cthdr->cmd_rsp_code);
- if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
- gfn_resp = (wwn_t *) (cthdr + 1);
- /*
- * check if it has actually changed
- */
- if ((memcmp
- ((void *)&bfa_fcs_port_get_fabric_name(port), gfn_resp,
- sizeof(wwn_t)) != 0))
- bfa_fcs_fabric_set_fabric_name(port->fabric, *gfn_resp);
- bfa_sm_send_event(ms, MSSM_EVENT_RSP_OK);
- return;
- }
- bfa_trc(port->fcs, cthdr->reason_code);
- bfa_trc(port->fcs, cthdr->exp_code);
- bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
- }
- /**
- * ms_pvt MS local functions
- */
- static void
- bfa_fcs_port_ms_send_plogi(void *ms_cbarg, struct bfa_fcxp_s *fcxp_alloced)
- {
- struct bfa_fcs_port_ms_s *ms = ms_cbarg;
- struct bfa_fcs_port_s *port = ms->port;
- struct fchs_s fchs;
- int len;
- struct bfa_fcxp_s *fcxp;
- bfa_trc(port->fcs, port->pid);
- fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs);
- if (!fcxp) {
- port->stats.ms_plogi_alloc_wait++;
- bfa_fcxp_alloc_wait(port->fcs->bfa, &ms->fcxp_wqe,
- bfa_fcs_port_ms_send_plogi, ms);
- return;
- }
- ms->fcxp = fcxp;
- len = fc_plogi_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
- bfa_os_hton3b(FC_MGMT_SERVER),
- bfa_fcs_port_get_fcid(port), 0,
- port->port_cfg.pwwn, port->port_cfg.nwwn,
- bfa_pport_get_maxfrsize(port->fcs->bfa));
- bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
- FC_CLASS_3, len, &fchs, bfa_fcs_port_ms_plogi_response,
- (void *)ms, FC_MAX_PDUSZ, FC_RA_TOV);
- port->stats.ms_plogi_sent++;
- bfa_sm_send_event(ms, MSSM_EVENT_FCXP_SENT);
- }
- static void
- bfa_fcs_port_ms_plogi_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
- void *cbarg, bfa_status_t req_status,
- u32 rsp_len, u32 resid_len,
- struct fchs_s *rsp_fchs)
- {
- struct bfa_fcs_port_ms_s *ms = (struct bfa_fcs_port_ms_s *)cbarg;
- struct bfa_fcs_port_s *port = ms->port;
- struct fc_els_cmd_s *els_cmd;
- struct fc_ls_rjt_s *ls_rjt;
- bfa_trc(port->fcs, req_status);
- bfa_trc(port->fcs, port->port_cfg.pwwn);
- /*
- * Sanity Checks
- */
- if (req_status != BFA_STATUS_OK) {
- port->stats.ms_plogi_rsp_err++;
- bfa_trc(port->fcs, req_status);
- bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
- return;
- }
- els_cmd = (struct fc_els_cmd_s *) BFA_FCXP_RSP_PLD(fcxp);
- switch (els_cmd->els_code) {
- case FC_ELS_ACC:
- if (rsp_len < sizeof(struct fc_logi_s)) {
- bfa_trc(port->fcs, rsp_len);
- port->stats.ms_plogi_acc_err++;
- bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
- break;
- }
- port->stats.ms_plogi_accepts++;
- bfa_sm_send_event(ms, MSSM_EVENT_RSP_OK);
- break;
- case FC_ELS_LS_RJT:
- ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
- bfa_trc(port->fcs, ls_rjt->reason_code);
- bfa_trc(port->fcs, ls_rjt->reason_code_expl);
- port->stats.ms_rejects++;
- bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
- break;
- default:
- port->stats.ms_plogi_unknown_rsp++;
- bfa_trc(port->fcs, els_cmd->els_code);
- bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
- }
- }
- static void
- bfa_fcs_port_ms_timeout(void *arg)
- {
- struct bfa_fcs_port_ms_s *ms = (struct bfa_fcs_port_ms_s *)arg;
- ms->port->stats.ms_timeouts++;
- bfa_sm_send_event(ms, MSSM_EVENT_TIMEOUT);
- }
- void
- bfa_fcs_port_ms_init(struct bfa_fcs_port_s *port)
- {
- struct bfa_fcs_port_ms_s *ms = BFA_FCS_GET_MS_FROM_PORT(port);
- ms->port = port;
- bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_offline);
- /*
- * Invoke init routines of sub modules.
- */
- bfa_fcs_port_fdmi_init(ms);
- }
- void
- bfa_fcs_port_ms_offline(struct bfa_fcs_port_s *port)
- {
- struct bfa_fcs_port_ms_s *ms = BFA_FCS_GET_MS_FROM_PORT(port);
- ms->port = port;
- bfa_sm_send_event(ms, MSSM_EVENT_PORT_OFFLINE);
- }
- void
- bfa_fcs_port_ms_online(struct bfa_fcs_port_s *port)
- {
- struct bfa_fcs_port_ms_s *ms = BFA_FCS_GET_MS_FROM_PORT(port);
- ms->port = port;
- bfa_sm_send_event(ms, MSSM_EVENT_PORT_ONLINE);
- }
- void
- bfa_fcs_port_ms_fabric_rscn(struct bfa_fcs_port_s *port)
- {
- struct bfa_fcs_port_ms_s *ms = BFA_FCS_GET_MS_FROM_PORT(port);
- /*
- * @todo. Handle this only when in Online state
- */
- if (bfa_sm_cmp_state(ms, bfa_fcs_port_ms_sm_online))
- bfa_sm_send_event(ms, MSSM_EVENT_PORT_FABRIC_RSCN);
- }
|