efct: Broadcom (Emulex) FC Target driver
Subsystems (2)
Re: [PATCH v3 13/31] elx: libefc: Fabric node state machine interfaces
In reply to James SmartQuoted 108 lines · James Smart
This patch continues the libefc library population.
This patch adds library interface definitions for:
- Fabric node initialization and logins.
- Name/Directory Services node.
- Fabric Controller node to process rscn events.These are all interactions with remote ports that correspond to well-known fabric entities
Signed-off-by Ram Vegesna <[email protected]>Signed-off-by James Smart <[email protected]>---
v3:
Replaceefc_assertwithWARN_ON
Return defined return values--- drivers/scsi/elx/libefc/efc_fabric.c | 1759 ++++++++++++++++++++++++++++++++++ drivers/scsi/elx/libefc/efc_fabric.h | 116 +++ 2 files changed, 1875 insertions(+) create mode 100644 drivers/scsi/elx/libefc/efc_fabric.c create mode 100644 drivers/scsi/elx/libefc/efc_fabric.hdrivers/scsi/elx/libefc/efc_fabric.c new file +78
-0@@ -0,0 +1,1759 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2019 Broadcom. All Rights Reserved. The term +* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +*/ + +/* +* This file implements remote node state machines for: +* - Fabric logins. +* - Fabric controller events. +* - Name/directory services interaction. +* - Point-to-point logins. +*/ + +/* +* fabric_sm Node State Machine: Fabric States +* ns_sm Node State Machine: Name/Directory Services States +* p2p_sm Node State Machine: Point-to-Point Node States +*/ + +#include "efc.h" + +static void +efc_fabric_initiate_shutdown (struct efc_node *node) +{ +int rc; +struct efc *efc = node->efc; + + efc->tt.scsi_io_alloc_disable (efc, node); + +if (node->attached) { +/* issue hw node free; don't care if succeeds right away +* or sometime later, will check node->attached later in +* shutdown process +*/ + rc = efc->tt.hw_node_detach (efc, &node->rnode); +if (rc !=EFC_HW_RTN_SUCCESS && + rc !=EFC_HW_RTN_SUCCESS_SYNC ) { +node_printf (node,"Failed freeing HW node, rc=%d\n" , + rc); + } + } +/* +* node has either been detached or is in the process of being detached, +* call common node's initiate cleanup function +*/ +efc_node_initiate_cleanup (node); +} + +static void * +__efc_fabric_common (const char *funcname,struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node =NULL ; + + node = ctx->app; + +switch (evt) { +case EFC_EVT_DOMAIN_ATTACH_OK : +break ; +case EFC_EVT_SHUTDOWN : + node->shutdown_reason =EFC_NODE_SHUTDOWN_DEFAULT ; +efc_fabric_initiate_shutdown (node); +break ; + +default : +/* call default event handler common to all nodes */ +__efc_node_common (funcname, ctx, evt, arg); +break ; + } +return NULL ; +} + +void * +__efc_fabric_init (struct efc_sm_ctx *ctx,enum efc_sm_event evt, +void *arg) +{ +struct efc_node *node = ctx->app;
drivers/scsi/elx/libefc/efc_fabric.c line 88
Quoted 10 lines
drivers/scsi/elx/libefc/efc_fabric.c new file +10
-0+struct efc *efc = node->efc; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_REENTER :/* not sure why we're getting these ... */ +efc_log_debug (efc,">>> reenter !!\n" ); +/* fall through */
IIRC, /* fall through */ has been replaced by fallthrough;
Quoted 76 lines
drivers/scsi/elx/libefc/efc_fabric.c new file +76
-0+case EFC_EVT_ENTER : +/* sm: / send FLOGI */ + efc->tt.els_send (efc, node,ELS_FLOGI , +EFC_FC_FLOGI_TIMEOUT_SEC , +EFC_FC_ELS_DEFAULT_RETRIES ); +efc_node_transition (node, __efc_fabric_flogi_wait_rsp,NULL ); +break ; + +default : +__efc_fabric_common (__func__, ctx, evt, arg); +break ; + } + +return NULL ; +} + +void +efc_fabric_set_topology (struct efc_node *node, +enum efc_sport_topology topology) +{ + node->sport->topology = topology; +} + +void +efc_fabric_notify_topology (struct efc_node *node) +{ +struct efc_node *tmp_node; +struct efc_node *next; +enum efc_sport_topology topology = node->sport->topology; + +/* +* now loop through the nodes in the sport +* and send topology notification +*/ +list_for_each_entry_safe (tmp_node, next, &node->sport->node_list, + list_entry) { +if (tmp_node != node) { +efc_node_post_event (tmp_node, +EFC_EVT_SPORT_TOPOLOGY_NOTIFY , + (void *)topology); + } + } +} + +static bool efc_rnode_is_nport (struct fc_els_flogi *rsp) +{ +return !(ntohs (rsp->fl_csp.sp_features) &FC_SP_FT_FPORT ); +} + +static bool efc_rnode_is_npiv_capable (struct fc_els_flogi *rsp) +{ +return !!(ntohs (rsp->fl_csp.sp_features) &FC_SP_FT_NPIV_ACC ); +} + +void * +__efc_fabric_flogi_wait_rsp (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node_cb *cbdata = arg; +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_SRRS_ELS_REQ_OK : { +if (efc_node_check_els_req (ctx, evt, arg,ELS_FLOGI , + __efc_fabric_common, __func__)) { +return NULL ; + } +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; + + memcpy(node->sport->domain->flogi_service_params, + cbdata->els_rsp.virt,
drivers/scsi/elx/libefc/efc_fabric.c line 174
Quoted 10 lines
drivers/scsi/elx/libefc/efc_fabric.c new file +10
-0+ sizeof(struct fc_els_flogi)); + +/* Check to see if the fabric is an F_PORT or and N_PORT */ +if (!efc_rnode_is_nport (cbdata->els_rsp.virt)) { +/* sm: if not nport / efc_domain_attach */ +/* ext_status has the fc_id, attach domain */ +if (efc_rnode_is_npiv_capable (cbdata->els_rsp.virt)) { +efc_log_debug (node->efc, +" NPIV is enabled at switch side\n" ); +//node->efc->sw_feature_cap |= 1<<10;
Looks like a left over.
Quoted 662 lines
drivers/scsi/elx/libefc/efc_fabric.c new file +662
-0+ } +efc_fabric_set_topology (node, +EFC_SPORT_TOPOLOGY_FABRIC ); +efc_fabric_notify_topology (node); +WARN_ON (node->sport->domain->attached); +efc_domain_attach (node->sport->domain, + cbdata->ext_status); +efc_node_transition (node, + __efc_fabric_wait_domain_attach, +NULL ); +break ; + } + +/* sm: if nport and p2p_winner / efc_domain_attach */ +efc_fabric_set_topology (node,EFC_SPORT_TOPOLOGY_P2P ); +if (efc_p2p_setup (node->sport)) { +node_printf (node, +"p2p setup failed, shutting down node\n" ); + node->shutdown_reason =EFC_NODE_SHUTDOWN_DEFAULT ; +efc_fabric_initiate_shutdown (node); +break ; + } + +if (node->sport->p2p_winner) { +efc_node_transition (node, + __efc_p2p_wait_domain_attach, +NULL ); +if (node->sport->domain->attached && + !node->sport->domain->domain_notify_pend) { +/* +* already attached, +* just send ATTACH_OK +*/ +node_printf (node, +"p2p winner, domain already attached\n" ); +efc_node_post_event (node, +EFC_EVT_DOMAIN_ATTACH_OK , +NULL ); + } + }else { +/* +* peer is p2p winner; +* PLOGI will be received on the +* remote SID=1 node; +* this node has served its purpose +*/ + node->shutdown_reason =EFC_NODE_SHUTDOWN_DEFAULT ; +efc_fabric_initiate_shutdown (node); + } + +break ; + } + +case EFC_EVT_ELS_REQ_ABORTED : +case EFC_EVT_SRRS_ELS_REQ_RJT : +case EFC_EVT_SRRS_ELS_REQ_FAIL : { +struct efc_sli_port *sport = node->sport; +/* +* with these errors, we have no recovery, +* so shutdown the sport, leave the link +* up and the domain ready +*/ +if (efc_node_check_els_req (ctx, evt, arg,ELS_FLOGI , + __efc_fabric_common, __func__)) { +return NULL ; + } +node_printf (node, +"FLOGI failed evt=%s, shutting down sport [%s]\n" , +efc_sm_event_name (evt), sport->display_name); +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +efc_sm_post_event (&sport->sm,EFC_EVT_SHUTDOWN ,NULL ); +break ; + } + +default : +__efc_fabric_common (__func__, ctx, evt, arg); +break ; + } + +return NULL ; +} + +void * +__efc_vport_fabric_init (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; +struct efc *efc = node->efc; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +/* sm: / send FDISC */ + efc->tt.els_send (efc, node,ELS_FDISC , +EFC_FC_FLOGI_TIMEOUT_SEC , +EFC_FC_ELS_DEFAULT_RETRIES ); + +efc_node_transition (node, __efc_fabric_fdisc_wait_rsp,NULL ); +break ; + +default : +__efc_fabric_common (__func__, ctx, evt, arg); +break ; + } + +return NULL ; +} + +void * +__efc_fabric_fdisc_wait_rsp (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node_cb *cbdata = arg; +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_SRRS_ELS_REQ_OK : { +/* fc_id is in ext_status */ +if (efc_node_check_els_req (ctx, evt, arg,ELS_FDISC , + __efc_fabric_common, __func__)) { +return NULL ; + } + +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +/* sm: / efc_sport_attach */ +efc_sport_attach (node->sport, cbdata->ext_status); +efc_node_transition (node, __efc_fabric_wait_domain_attach, +NULL ); +break ; + } + +case EFC_EVT_SRRS_ELS_REQ_RJT : +case EFC_EVT_SRRS_ELS_REQ_FAIL : { +if (efc_node_check_els_req (ctx, evt, arg,ELS_FDISC , + __efc_fabric_common, __func__)) { +return NULL ; + } +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +efc_log_err (node->efc,"FDISC failed, shutting down sport\n" ); +/* sm: / shutdown sport */ +efc_sm_post_event (&node->sport->sm,EFC_EVT_SHUTDOWN ,NULL ); +break ; + } + +default : +__efc_fabric_common (__func__, ctx, evt, arg); +break ; + } + +return NULL ; +} + +static int +efc_start_ns_node (struct efc_sli_port *sport) +{ +struct efc_node *ns; + +/* Instantiate a name services node */ + ns =efc_node_find (sport,FC_FID_DIR_SERV ); +if (!ns) { + ns =efc_node_alloc (sport,FC_FID_DIR_SERV , false, false); +if (!ns) +return EFC_FAIL ; + } +/* +* for found ns, should we be transitioning from here? +* breaks transition only +* 1. from within state machine or +* 2. if after alloc +*/ +if (ns->efc->nodedb_mask &EFC_NODEDB_PAUSE_NAMESERVER ) +efc_node_pause (ns, __efc_ns_init); +else +efc_node_transition (ns, __efc_ns_init,NULL ); +return EFC_SUCCESS ; +} + +static int +efc_start_fabctl_node (struct efc_sli_port *sport) +{ +struct efc_node *fabctl; + + fabctl =efc_node_find (sport,FC_FID_FCTRL ); +if (!fabctl) { + fabctl =efc_node_alloc (sport,FC_FID_FCTRL , + false, false); +if (!fabctl) +return EFC_FAIL ; + } +/* +* for found ns, should we be transitioning from here? +* breaks transition only +* 1. from within state machine or +* 2. if after alloc +*/ +efc_node_transition (fabctl, __efc_fabctl_init,NULL ); +return EFC_SUCCESS ; +} + +void * +__efc_fabric_wait_domain_attach (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; +case EFC_EVT_DOMAIN_ATTACH_OK : +case EFC_EVT_SPORT_ATTACH_OK : { +int rc; + + rc =efc_start_ns_node (node->sport); +if (rc) +return NULL ; + +/* sm: if enable_ini / start fabctl node */ +/* Instantiate the fabric controller (sends SCR) */ +if (node->sport->enable_rscn) { + rc =efc_start_fabctl_node (node->sport); +if (rc) +return NULL ; + } +efc_node_transition (node, __efc_fabric_idle,NULL ); +break ; + } +default : +__efc_fabric_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_fabric_idle (struct efc_sm_ctx *ctx,enum efc_sm_event evt, +void *arg) +{ +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_DOMAIN_ATTACH_OK : +break ; +default : +__efc_fabric_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_ns_init (struct efc_sm_ctx *ctx,enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; +struct efc *efc = node->efc; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +/* sm: / send PLOGI */ + efc->tt.els_send (efc, node,ELS_PLOGI , +EFC_FC_FLOGI_TIMEOUT_SEC , +EFC_FC_ELS_DEFAULT_RETRIES ); +efc_node_transition (node, __efc_ns_plogi_wait_rsp,NULL ); +break ; +default : +__efc_fabric_common (__func__, ctx, evt, arg); +break ; + } + +return NULL ; +} + +void * +__efc_ns_plogi_wait_rsp (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +int rc; +struct efc_node_cb *cbdata = arg; +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_SRRS_ELS_REQ_OK : { +/* Save service parameters */ +if (efc_node_check_els_req (ctx, evt, arg,ELS_PLOGI , + __efc_fabric_common, __func__)) { +return NULL ; + } +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +/* sm: / save sparams, efc_node_attach */ +efc_node_save_sparms (node, cbdata->els_rsp.virt); + rc =efc_node_attach (node); +efc_node_transition (node, __efc_ns_wait_node_attach,NULL ); +if (rc ==EFC_HW_RTN_SUCCESS_SYNC ) +efc_node_post_event (node,EFC_EVT_NODE_ATTACH_OK , +NULL ); +break ; + } +default : +__efc_fabric_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_ns_wait_node_attach (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; +struct efc *efc = node->efc; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +case EFC_EVT_NODE_ATTACH_OK : + node->attached = true; +/* sm: / send RFTID */ + efc->tt.els_send_ct (efc, node,FC_RCTL_ELS_REQ , +EFC_FC_ELS_SEND_DEFAULT_TIMEOUT , +EFC_FC_ELS_DEFAULT_RETRIES ); +efc_node_transition (node, __efc_ns_rftid_wait_rsp,NULL ); +break ; + +case EFC_EVT_NODE_ATTACH_FAIL : +/* node attach failed, shutdown the node */ + node->attached = false; +node_printf (node,"Node attach failed\n" ); + node->shutdown_reason =EFC_NODE_SHUTDOWN_DEFAULT ; +efc_fabric_initiate_shutdown (node); +break ; + +case EFC_EVT_SHUTDOWN : +node_printf (node,"Shutdown event received\n" ); + node->shutdown_reason =EFC_NODE_SHUTDOWN_DEFAULT ; +efc_node_transition (node, + __efc_fabric_wait_attach_evt_shutdown, +NULL ); +break ; + +/* +* if receive RSCN just ignore, +* we haven't sent GID_PT yet (ACC sent by fabctl node) +*/ +case EFC_EVT_RSCN_RCVD : +break ; + +default : +__efc_fabric_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_fabric_wait_attach_evt_shutdown (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +/* wait for any of these attach events and then shutdown */ +case EFC_EVT_NODE_ATTACH_OK : + node->attached = true; +node_printf (node,"Attach evt=%s, proceed to shutdown\n" , +efc_sm_event_name (evt)); +efc_fabric_initiate_shutdown (node); +break ; + +case EFC_EVT_NODE_ATTACH_FAIL : + node->attached = false; +node_printf (node,"Attach evt=%s, proceed to shutdown\n" , +efc_sm_event_name (evt)); +efc_fabric_initiate_shutdown (node); +break ; + +/* ignore shutdown event as we're already in shutdown path */ +case EFC_EVT_SHUTDOWN : +node_printf (node,"Shutdown event received\n" ); +break ; + +default : +__efc_fabric_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_ns_rftid_wait_rsp (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; +struct efc *efc = node->efc; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_SRRS_ELS_REQ_OK : +if (efc_node_check_ns_req (ctx, evt, arg,FC_NS_RFT_ID , + __efc_fabric_common, __func__)) { +return NULL ; + } +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +/* sm: / send RFFID */ + efc->tt.els_send_ct (efc, node,FC_NS_RFF_ID , +EFC_FC_ELS_SEND_DEFAULT_TIMEOUT , +EFC_FC_ELS_DEFAULT_RETRIES ); +efc_node_transition (node, __efc_ns_rffid_wait_rsp,NULL ); +break ; + +/* +* if receive RSCN just ignore, +* we haven't sent GID_PT yet (ACC sent by fabctl node) +*/ +case EFC_EVT_RSCN_RCVD : +break ; + +default : +__efc_fabric_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +/** +* Waits for an RFFID response event; if configured for an initiator operation, +* a GIDPT name services request is issued. +*/ +void * +__efc_ns_rffid_wait_rsp (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; +struct efc *efc = node->efc; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_SRRS_ELS_REQ_OK : { +if (efc_node_check_ns_req (ctx, evt, arg,FC_NS_RFF_ID , + __efc_fabric_common, __func__)) { +return NULL ; + } +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +if (node->sport->enable_rscn) { +/* sm: if enable_rscn / send GIDPT */ + efc->tt.els_send_ct (efc, node,FC_NS_GID_PT , +EFC_FC_ELS_SEND_DEFAULT_TIMEOUT , +EFC_FC_ELS_DEFAULT_RETRIES ); + +efc_node_transition (node, __efc_ns_gidpt_wait_rsp, +NULL ); + }else { +/* if 'T' only, we're done, go to idle */ +efc_node_transition (node, __efc_ns_idle,NULL ); + } +break ; + } +/* +* if receive RSCN just ignore, +* we haven't sent GID_PT yet (ACC sent by fabctl node) +*/ +case EFC_EVT_RSCN_RCVD : +break ; + +default : +__efc_fabric_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +static int +efc_process_gidpt_payload (struct efc_node *node, +void *data,u32 gidpt_len) +{ +u32 i, j; +struct efc_node *newnode; +struct efc_sli_port *sport = node->sport; +struct efc *efc = node->efc; +u32 port_id =0 , port_count, portlist_count; +struct efc_node *n; +struct efc_node **active_nodes; +int residual; +struct fc_ct_hdr *hdr = data; +struct fc_gid_pn_resp *gidpt = data +sizeof (*hdr); + + residual =be16_to_cpu (hdr->ct_mr_size); + +if (residual !=0 ) +efc_log_debug (node->efc,"residual is %u words\n" , residual); + +if (be16_to_cpu (hdr->ct_cmd) ==FC_FS_RJT ) { +node_printf (node, +"GIDPT request failed: rsn x%x rsn_expl x%x\n" , + hdr->ct_reason, hdr->ct_explan); +return EFC_FAIL ; + } + + portlist_count = (gidpt_len -sizeof (*hdr)) /sizeof (*gidpt); + +/* Count the number of nodes */ + port_count =0 ; +list_for_each_entry (n, &sport->node_list, list_entry) { + port_count++; + } + +/* Allocate a buffer for all nodes */ + active_nodes =kzalloc (port_count *sizeof (*active_nodes),GFP_ATOMIC ); +if (!active_nodes) { +node_printf (node,"efc_malloc failed\n" ); +return EFC_FAIL ; + } + +/* Fill buffer with fc_id of active nodes */ + i =0 ; +list_for_each_entry (n, &sport->node_list, list_entry) { + port_id = n->rnode.fc_id; +switch (port_id) { +case FC_FID_FLOGI : +case FC_FID_FCTRL : +case FC_FID_DIR_SERV : +break ; +default : +if (port_id !=FC_FID_DOM_MGR ) + active_nodes[i++] = n; +break ; + } + } + +/* update the active nodes buffer */ +for (i =0 ; i < portlist_count; i++) { +hton24 (gidpt[i].fp_fid, port_id); + +for (j =0 ; j < port_count; j++) { +if (active_nodes[j] && + port_id == active_nodes[j]->rnode.fc_id) { + active_nodes[j] =NULL ; + } + } + +if (gidpt[i].fp_resvd &FC_NS_FID_LAST ) +break ; + } + +/* Those remaining in the active_nodes[] are now gone ! */ +for (i =0 ; i < port_count; i++) { +/* +* if we're an initiator and the remote node +* is a target, then post the node missing event. +* if we're target and we have enabled +* target RSCN, then post the node missing event. +*/ +if (active_nodes[i]) { +if ((node->sport->enable_ini && + active_nodes[i]->targ) || + (node->sport->enable_tgt && +enable_target_rscn (efc))) { +efc_node_post_event (active_nodes[i], +EFC_EVT_NODE_MISSING , +NULL ); + }else { +node_printf (node, +"GID_PT: skipping non-tgt port_id x%06x\n" , + active_nodes[i]->rnode.fc_id); + } + } + } +kfree (active_nodes); + +for (i =0 ; i < portlist_count; i++) { +hton24 (gidpt[i].fp_fid, port_id); + +/* Don't create node for ourselves */ +if (port_id != node->rnode.sport->fc_id) { + newnode =efc_node_find (sport, port_id); +if (!newnode) { +if (node->sport->enable_ini) { + newnode =efc_node_alloc (sport, + port_id, + false, + false); +if (!newnode) { +efc_log_err (efc, +"efc_node_alloc() failed\n" ); +return EFC_FAIL ; + } +/* +* send PLOGI automatically +* if initiator +*/ +efc_node_init_device (newnode, true); + } +continue ; + } +
drivers/scsi/elx/libefc/efc_fabric.c line 846
Quoted 10 lines
drivers/scsi/elx/libefc/efc_fabric.c new file +10
-0+if (node->sport->enable_ini && newnode->targ) { +efc_node_post_event (newnode, +EFC_EVT_NODE_REFOUND , +NULL ); + } +/* +* original code sends ADISC, +* has notion of "refound" +*/ + }
A helper function or something which makes this heavy idention go away, please. This is hard to read.
Quoted 56 lines
drivers/scsi/elx/libefc/efc_fabric.c new file +56
-0+ +if (gidpt[i].fp_resvd &FC_NS_FID_LAST ) +break ; + } +return EFC_SUCCESS ; +} + +/** +* Wait for a GIDPT response from the name server. Process the FC_IDs that are +* reported by creating new remote ports, as needed. +*/ +void * +__efc_ns_gidpt_wait_rsp (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node_cb *cbdata = arg; +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_SRRS_ELS_REQ_OK : { +if (efc_node_check_ns_req (ctx, evt, arg,FC_NS_GID_PT , + __efc_fabric_common, __func__)) { +return NULL ; + } +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +/* sm: / process GIDPT payload */ +efc_process_gidpt_payload (node, cbdata->els_rsp.virt, + cbdata->els_rsp.len); +efc_node_transition (node, __efc_ns_idle,NULL ); +break ; + } + +case EFC_EVT_SRRS_ELS_REQ_FAIL : { +/* not much we can do; will retry with the next RSCN */ +node_printf (node,"GID_PT failed to complete\n" ); +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +efc_node_transition (node, __efc_ns_idle,NULL ); +break ; + } + +/* if receive RSCN here, queue up another discovery processing */ +case EFC_EVT_RSCN_RCVD : { +node_printf (node,"RSCN received during GID_PT processing\n" ); + node->rscn_pending = true; +break ; + } + +default : +__efc_fabric_common (__func__, ctx, evt, arg); +return NULL ;
drivers/scsi/elx/libefc/efc_fabric.c line 912
Quoted 10 lines
drivers/scsi/elx/libefc/efc_fabric.c new file +10
-0+ } + +return NULL ; +} + +/** +* Idle. Waiting for RSCN received events +* (posted from the fabric controller), and +* restarts the GIDPT name services query and processing. +*/
Not a proper kerneldoc. There are more of those in this file.
Quoted 82 lines
drivers/scsi/elx/libefc/efc_fabric.c new file +82
-0+void * +__efc_ns_idle (struct efc_sm_ctx *ctx,enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; +struct efc *efc = node->efc; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +if (!node->rscn_pending) +break ; + +node_printf (node,"RSCN pending, restart discovery\n" ); + node->rscn_pending = false; + +/* fall through */ + +case EFC_EVT_RSCN_RCVD : { +/* sm: / send GIDPT */ +/* +* If target RSCN processing is enabled, +* and this is target only (not initiator), +* and tgt_rscn_delay is non-zero, +* then we delay issuing the GID_PT +*/ +if (efc->tgt_rscn_delay_msec !=0 && + !node->sport->enable_ini && node->sport->enable_tgt && +enable_target_rscn (efc)) { +efc_node_transition (node, __efc_ns_gidpt_delay,NULL ); + }else { + efc->tt.els_send_ct (efc, node,FC_NS_GID_PT , +EFC_FC_ELS_SEND_DEFAULT_TIMEOUT , +EFC_FC_ELS_DEFAULT_RETRIES ); +efc_node_transition (node, __efc_ns_gidpt_wait_rsp, +NULL ); + } +break ; + } + +default : +__efc_fabric_common (__func__, ctx, evt, arg); +break ; + } + +return NULL ; +} + +/** +* Handle GIDPT delay timer callback +* Post an EFC_EVT_GIDPT_DEIALY_EXPIRED event to the passed in node. +*/ +static void +gidpt_delay_timer_cb (struct timer_list *t) +{ +struct efc_node *node =from_timer (node, t, gidpt_delay_timer); + +del_timer (&node->gidpt_delay_timer); + +efc_node_post_event (node,EFC_EVT_GIDPT_DELAY_EXPIRED ,NULL ); +} + +/** +* Name services node state machine: Delayed GIDPT. +* +* Waiting for GIDPT delay to expire before submitting GIDPT to name server. +*/ +void * +__efc_ns_gidpt_delay (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; +struct efc *efc = node->efc; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : {
drivers/scsi/elx/libefc/efc_fabric.c line 1004
Quoted 10 lines
drivers/scsi/elx/libefc/efc_fabric.c new file +10
-0+time_t delay_msec; + +/* +* Compute the delay time. +* Set to tgt_rscn_delay, if the time since last GIDPT +* is less than tgt_rscn_period, then use tgt_rscn_period. +*/ + delay_msec = efc->tgt_rscn_delay_msec; +if ((jiffies_to_msecs (jiffies) - node->time_last_gidpt_msec) + < efc->tgt_rscn_period_msec) {
Maybe the first part of the condition as new variable to make the if readable.
Quoted 881 lines
drivers/scsi/elx/libefc/efc_fabric.c new file +755
-0+ delay_msec = efc->tgt_rscn_period_msec; + } +timer_setup (&node->gidpt_delay_timer, &gidpt_delay_timer_cb, +0 ); +mod_timer (&node->gidpt_delay_timer, + jiffies +msecs_to_jiffies (delay_msec)); + +break ; + } + +case EFC_EVT_GIDPT_DELAY_EXPIRED : + node->time_last_gidpt_msec =jiffies_to_msecs (jiffies); + + efc->tt.els_send_ct (efc, node,FC_NS_GID_PT , +EFC_FC_ELS_SEND_DEFAULT_TIMEOUT , +EFC_FC_ELS_DEFAULT_RETRIES ); +efc_node_transition (node, __efc_ns_gidpt_wait_rsp,NULL ); +break ; + +case EFC_EVT_RSCN_RCVD : { +efc_log_debug (efc, +"RSCN received while in GIDPT delay - no action\n" ); +break ; + } + +default : +__efc_fabric_common (__func__, ctx, evt, arg); +break ; + } + +return NULL ; +} + +/** +* Fabric controller node state machine: Initial state. +* +* Issue a PLOGI to a well-known fabric controller address. +*/ +void * +__efc_fabctl_init (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; +struct efc *efc = node->efc; + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +/* no need to login to fabric controller, just send SCR */ + efc->tt.els_send (efc, node,ELS_SCR , +EFC_FC_FLOGI_TIMEOUT_SEC , +EFC_FC_ELS_DEFAULT_RETRIES ); +efc_node_transition (node, __efc_fabctl_wait_scr_rsp,NULL ); +break ; + +case EFC_EVT_NODE_ATTACH_OK : + node->attached = true; +break ; + +default : +__efc_fabric_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +/** +* Fabric controller node state machine: Wait for a node attach request +* to complete. +* +* Wait for a node attach to complete. If successful, issue an SCR +* to the fabric controller, subscribing to all RSCN. +*/ +void * +__efc_fabctl_wait_node_attach (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; +struct efc *efc = node->efc; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +case EFC_EVT_NODE_ATTACH_OK : + node->attached = true; +/* sm: / send SCR */ + efc->tt.els_send (efc, node,ELS_SCR , +EFC_FC_ELS_SEND_DEFAULT_TIMEOUT , +EFC_FC_ELS_DEFAULT_RETRIES ); +efc_node_transition (node, __efc_fabctl_wait_scr_rsp,NULL ); +break ; + +case EFC_EVT_NODE_ATTACH_FAIL : +/* node attach failed, shutdown the node */ + node->attached = false; +node_printf (node,"Node attach failed\n" ); + node->shutdown_reason =EFC_NODE_SHUTDOWN_DEFAULT ; +efc_fabric_initiate_shutdown (node); +break ; + +case EFC_EVT_SHUTDOWN : +node_printf (node,"Shutdown event received\n" ); + node->shutdown_reason =EFC_NODE_SHUTDOWN_DEFAULT ; +efc_node_transition (node, + __efc_fabric_wait_attach_evt_shutdown, +NULL ); +break ; + +default : +__efc_fabric_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +/** +* Fabric controller node state machine: +* Wait for an SCR response from the fabric controller. +*/ +void * +__efc_fabctl_wait_scr_rsp (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_SRRS_ELS_REQ_OK : +if (efc_node_check_els_req (ctx, evt, arg,ELS_SCR , + __efc_fabric_common, __func__)) { +return NULL ; + } +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +efc_node_transition (node, __efc_fabctl_ready,NULL ); +break ; + +default : +__efc_fabric_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +static void +efc_process_rscn (struct efc_node *node,struct efc_node_cb *cbdata) +{ +struct efc *efc = node->efc; +struct efc_sli_port *sport = node->sport; +struct efc_node *ns; + +/* Forward this event to the name-services node */ + ns =efc_node_find (sport,FC_FID_DIR_SERV ); +if (ns) +efc_node_post_event (ns,EFC_EVT_RSCN_RCVD , cbdata); +else +efc_log_warn (efc,"can't find name server node\n" ); +} + +/* Fabric controller node state machine: Ready. +* In this state, the fabric controller sends a RSCN, which is received +* by this node and is forwarded to the name services node object; and +* the RSCN LS_ACC is sent. +*/ +void * +__efc_fabctl_ready (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node_cb *cbdata = arg; +struct efc_node *node = ctx->app; +struct efc *efc = node->efc; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_RSCN_RCVD : { +struct fc_frame_header *hdr = cbdata->header->dma.virt; + +/* +* sm: / process RSCN (forward to name services node), +* send LS_ACC +*/ +efc_process_rscn (node, cbdata); + efc->tt.els_send_resp (efc, node,ELS_LS_ACC , +be16_to_cpu (hdr->fh_ox_id)); +efc_node_transition (node, __efc_fabctl_wait_ls_acc_cmpl, +NULL ); +break ; + } + +default : +__efc_fabric_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_fabctl_wait_ls_acc_cmpl (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +case EFC_EVT_SRRS_ELS_CMPL_OK : +WARN_ON (!node->els_cmpl_cnt); + node->els_cmpl_cnt--; +efc_node_transition (node, __efc_fabctl_ready,NULL ); +break ; + +default : +__efc_fabric_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +static uint64_t +efc_get_wwpn (struct fc_els_flogi *sp) +{ +return be64_to_cpu (sp->fl_wwnn); +} + +static int +efc_rnode_is_winner (struct efc_sli_port *sport) +{ +struct fc_els_flogi *remote_sp; +u64 remote_wwpn; +u64 local_wwpn = sport->wwpn; +u64 wwn_bump =0 ; + + remote_sp = (struct fc_els_flogi *)sport->domain->flogi_service_params; + remote_wwpn =efc_get_wwpn (remote_sp); + + local_wwpn ^= wwn_bump; + + remote_wwpn =efc_get_wwpn (remote_sp); + +efc_log_debug (sport->efc,"r: %llx\n" , +be64_to_cpu (remote_sp->fl_wwpn)); +efc_log_debug (sport->efc,"l: %llx\n" , local_wwpn); + +if (remote_wwpn == local_wwpn) { +efc_log_warn (sport->efc, +"WWPN of remote node [%08x %08x] matches local WWPN\n" , + (u32)(local_wwpn >>32ll ), + (u32 )local_wwpn); +return -1 ; + } + +return (remote_wwpn > local_wwpn); +} + +void * +__efc_p2p_wait_domain_attach (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; +struct efc *efc = node->efc; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +case EFC_EVT_DOMAIN_ATTACH_OK : { +struct efc_sli_port *sport = node->sport; +struct efc_node *rnode; + +/* +* this transient node (SID=0 (recv'd FLOGI) +* or DID=fabric (sent FLOGI)) +* is the p2p winner, will use a separate node +* to send PLOGI to peer +*/ +WARN_ON (!node->sport->p2p_winner); + + rnode =efc_node_find (sport, node->sport->p2p_remote_port_id); +if (rnode) { +/* +* the "other" transient p2p node has +* already kicked off the +* new node from which PLOGI is sent +*/ +node_printf (node, +"Node with fc_id x%x already exists\n" , + rnode->rnode.fc_id); + }else { +/* +* create new node (SID=1, DID=2) +* from which to send PLOGI +*/ + rnode =efc_node_alloc (sport, + sport->p2p_remote_port_id, + false, false); +if (!rnode) { +efc_log_err (efc,"node alloc failed\n" ); +return NULL ; + } + +efc_fabric_notify_topology (node); +/* sm: / allocate p2p remote node */ +efc_node_transition (rnode, __efc_p2p_rnode_init, +NULL ); + } + +/* +* the transient node (SID=0 or DID=fabric) +* has served its purpose +*/ +if (node->rnode.fc_id ==0 ) { +/* +* if this is the SID=0 node, +* move to the init state in case peer +* has restarted FLOGI discovery and FLOGI is pending +*/ +/* don't send PLOGI on efc_d_init entry */ +efc_node_init_device (node, false); + }else { +/* +* if this is the DID=fabric node +* (we initiated FLOGI), shut it down +*/ + node->shutdown_reason =EFC_NODE_SHUTDOWN_DEFAULT ; +efc_fabric_initiate_shutdown (node); + } +break ; + } + +default : +__efc_fabric_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_p2p_rnode_init (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node_cb *cbdata = arg; +struct efc_node *node = ctx->app; +struct efc *efc = node->efc; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +/* sm: / send PLOGI */ + efc->tt.els_send (efc, node,ELS_PLOGI , +EFC_FC_FLOGI_TIMEOUT_SEC , +EFC_FC_ELS_DEFAULT_RETRIES ); +efc_node_transition (node, __efc_p2p_wait_plogi_rsp,NULL ); +break ; + +case EFC_EVT_ABTS_RCVD : +/* sm: send BA_ACC */ + efc->tt.bls_send_acc_hdr (efc, node, cbdata->header->dma.virt); +break ; + +default : +__efc_fabric_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_p2p_wait_flogi_acc_cmpl (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node_cb *cbdata = arg; +struct efc_node *node = ctx->app; +struct efc *efc = node->efc; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +case EFC_EVT_SRRS_ELS_CMPL_OK : +WARN_ON (!node->els_cmpl_cnt); + node->els_cmpl_cnt--; + +/* sm: if p2p_winner / domain_attach */ +if (node->sport->p2p_winner) { +efc_node_transition (node, + __efc_p2p_wait_domain_attach, +NULL ); +if (!node->sport->domain->attached) { +node_printf (node,"Domain not attached\n" ); +efc_domain_attach (node->sport->domain, + node->sport->p2p_port_id); + }else { +node_printf (node,"Domain already attached\n" ); +efc_node_post_event (node, +EFC_EVT_DOMAIN_ATTACH_OK , +NULL ); + } + }else { +/* this node has served its purpose; +* we'll expect a PLOGI on a separate +* node (remote SID=0x1); return this node +* to init state in case peer +* restarts discovery -- it may already +* have (pending frames may exist). +*/ +/* don't send PLOGI on efc_d_init entry */ +efc_node_init_device (node, false); + } +break ; + +case EFC_EVT_SRRS_ELS_CMPL_FAIL : +/* +* LS_ACC failed, possibly due to link down; +* shutdown node and wait +* for FLOGI discovery to restart +*/ +node_printf (node,"FLOGI LS_ACC failed, shutting down\n" ); +WARN_ON (!node->els_cmpl_cnt); + node->els_cmpl_cnt--; + node->shutdown_reason =EFC_NODE_SHUTDOWN_DEFAULT ; +efc_fabric_initiate_shutdown (node); +break ; + +case EFC_EVT_ABTS_RCVD : { +/* sm: / send BA_ACC */ + efc->tt.bls_send_acc_hdr (efc, node, + cbdata->header->dma.virt); +break ; + } + +default : +__efc_fabric_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_p2p_wait_plogi_rsp (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +int rc; +struct efc_node_cb *cbdata = arg; +struct efc_node *node = ctx->app; +struct efc *efc = node->efc; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_SRRS_ELS_REQ_OK : { +if (efc_node_check_els_req (ctx, evt, arg,ELS_PLOGI , + __efc_fabric_common, __func__)) { +return NULL ; + } +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +/* sm: / save sparams, efc_node_attach */ +efc_node_save_sparms (node, cbdata->els_rsp.virt); + rc =efc_node_attach (node); +efc_node_transition (node, __efc_p2p_wait_node_attach,NULL ); +if (rc ==EFC_HW_RTN_SUCCESS_SYNC ) +efc_node_post_event (node,EFC_EVT_NODE_ATTACH_OK , +NULL ); +break ; + } +case EFC_EVT_SRRS_ELS_REQ_FAIL : { +if (efc_node_check_els_req (ctx, evt, arg,ELS_PLOGI , + __efc_fabric_common, __func__)) { +return NULL ; + } +node_printf (node,"PLOGI failed, shutting down\n" ); +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; + node->shutdown_reason =EFC_NODE_SHUTDOWN_DEFAULT ; +efc_fabric_initiate_shutdown (node); +break ; + } + +case EFC_EVT_PLOGI_RCVD : { +struct fc_frame_header *hdr = cbdata->header->dma.virt; +/* if we're in external loopback mode, just send LS_ACC */ +if (node->efc->external_loopback) { + efc->tt.els_send_resp (efc, node,ELS_PLOGI , +be16_to_cpu (hdr->fh_ox_id)); + }else { +/* +* if this isn't external loopback, +* pass to default handler +*/ +__efc_fabric_common (__func__, ctx, evt, arg); + } +break ; + } +case EFC_EVT_PRLI_RCVD : +/* I, or I+T */ +/* sent PLOGI and before completion was seen, received the +* PRLI from the remote node (WCQEs and RCQEs come in on +* different queues and order of processing cannot be assumed) +* Save OXID so PRLI can be sent after the attach and continue +* to wait for PLOGI response +*/ +efc_process_prli_payload (node, cbdata->payload->dma.virt); +efc_send_ls_acc_after_attach (node, + cbdata->header->dma.virt, +EFC_NODE_SEND_LS_ACC_PRLI ); +efc_node_transition (node, __efc_p2p_wait_plogi_rsp_recvd_prli, +NULL ); +break ; +default : +__efc_fabric_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_p2p_wait_plogi_rsp_recvd_prli (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +int rc; +struct efc_node_cb *cbdata = arg; +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +/* +* Since we've received a PRLI, we have a port login and will +* just need to wait for the PLOGI response to do the node +* attach and then we can send the LS_ACC for the PRLI. If, +* during this time, we receive FCP_CMNDs (which is possible +* since we've already sent a PRLI and our peer may have +* accepted). +* At this time, we are not waiting on any other unsolicited +* frames to continue with the login process. Thus, it will not +* hurt to hold frames here. +*/ +efc_node_hold_frames (node); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +case EFC_EVT_SRRS_ELS_REQ_OK :/* PLOGI response received */ +/* Completion from PLOGI sent */ +if (efc_node_check_els_req (ctx, evt, arg,ELS_PLOGI , + __efc_fabric_common, __func__)) { +return NULL ; + } +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +/* sm: / save sparams, efc_node_attach */ +efc_node_save_sparms (node, cbdata->els_rsp.virt); + rc =efc_node_attach (node); +efc_node_transition (node, __efc_p2p_wait_node_attach,NULL ); +if (rc ==EFC_HW_RTN_SUCCESS_SYNC ) +efc_node_post_event (node,EFC_EVT_NODE_ATTACH_OK , +NULL ); +break ; + +case EFC_EVT_SRRS_ELS_REQ_FAIL :/* PLOGI response received */ +case EFC_EVT_SRRS_ELS_REQ_RJT : +/* PLOGI failed, shutdown the node */ +if (efc_node_check_els_req (ctx, evt, arg,ELS_PLOGI , + __efc_fabric_common, __func__)) { +return NULL ; + } +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; + node->shutdown_reason =EFC_NODE_SHUTDOWN_DEFAULT ; +efc_fabric_initiate_shutdown (node); +break ; + +default : +__efc_fabric_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_p2p_wait_node_attach (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node_cb *cbdata = arg; +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +case EFC_EVT_NODE_ATTACH_OK : + node->attached = true; +switch (node->send_ls_acc) { +case EFC_NODE_SEND_LS_ACC_PRLI : { +efc_d_send_prli_rsp (node->ls_acc_io, + node->ls_acc_oxid); + node->send_ls_acc =EFC_NODE_SEND_LS_ACC_NONE ; + node->ls_acc_io =NULL ; +break ; + } +case EFC_NODE_SEND_LS_ACC_PLOGI :/* Can't happen in P2P */ +case EFC_NODE_SEND_LS_ACC_NONE : +default : +/* Normal case for I */ +/* sm: send_plogi_acc is not set / send PLOGI acc */ +efc_node_transition (node, __efc_d_port_logged_in, +NULL ); +break ; + } +break ; + +case EFC_EVT_NODE_ATTACH_FAIL : +/* node attach failed, shutdown the node */ + node->attached = false; +node_printf (node,"Node attach failed\n" ); + node->shutdown_reason =EFC_NODE_SHUTDOWN_DEFAULT ; +efc_fabric_initiate_shutdown (node); +break ; + +case EFC_EVT_SHUTDOWN : +node_printf (node,"%s received\n" ,efc_sm_event_name (evt)); + node->shutdown_reason =EFC_NODE_SHUTDOWN_DEFAULT ; +efc_node_transition (node, + __efc_fabric_wait_attach_evt_shutdown, +NULL ); +break ; +case EFC_EVT_PRLI_RCVD : +node_printf (node,"%s: PRLI received before node is attached\n" , +efc_sm_event_name (evt)); +efc_process_prli_payload (node, cbdata->payload->dma.virt); +efc_send_ls_acc_after_attach (node, + cbdata->header->dma.virt, +EFC_NODE_SEND_LS_ACC_PRLI ); +break ; + +default : +__efc_fabric_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +int +efc_p2p_setup (struct efc_sli_port *sport) +{ +struct efc *efc = sport->efc; +int rnode_winner; + + rnode_winner =efc_rnode_is_winner (sport); + +/* set sport flags to indicate p2p "winner" */ +if (rnode_winner ==1 ) { + sport->p2p_remote_port_id =0 ; + sport->p2p_port_id =0 ; + sport->p2p_winner = false; + }else if (rnode_winner ==0 ) { + sport->p2p_remote_port_id =2 ; + sport->p2p_port_id =1 ; + sport->p2p_winner = true; + }else { +/* no winner; only okay if external loopback enabled */ +if (sport->efc->external_loopback) { +/* +* External loopback mode enabled; +* local sport and remote node +* will be registered with an NPortID = 1; +*/ +efc_log_debug (efc, +"External loopback mode enabled\n" ); + sport->p2p_remote_port_id =1 ; + sport->p2p_port_id =1 ; + sport->p2p_winner = true; + }else { +efc_log_warn (efc, +"failed to determine p2p winner\n" ); +return rnode_winner; + } + } +return EFC_SUCCESS ; +}drivers/scsi/elx/libefc/efc_fabric.h new file +116
-0@@ -0,0 +1,116 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2019 Broadcom. All Rights Reserved. The term +* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +*/ + +/* +* Declarations for the interface exported by efc_fabric +*/ + +#ifndef __EFCT_FABRIC_H__ +#define __EFCT_FABRIC_H__ +#include "scsi/fc/fc_els.h" +#include "scsi/fc/fc_fs.h" +#include "scsi/fc/fc_ns.h" + +void * +__efc_fabric_init (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +void * +__efc_fabric_flogi_wait_rsp (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +void * +__efc_fabric_domain_attach_wait (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +void * +__efc_fabric_wait_domain_attach (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); + +void * +__efc_vport_fabric_init (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +void * +__efc_fabric_fdisc_wait_rsp (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +void * +__efc_fabric_wait_sport_attach (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); + +void * +__efc_ns_init (struct efc_sm_ctx *ctx,enum efc_sm_event evt,void *arg); +void * +__efc_ns_plogi_wait_rsp (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +void * +__efc_ns_rftid_wait_rsp (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +void * +__efc_ns_rffid_wait_rsp (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +void * +__efc_ns_wait_node_attach (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +void * +__efc_fabric_wait_attach_evt_shutdown (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +void * +__efc_ns_logo_wait_rsp (struct efc_sm_ctx *ctx, +enum efc_sm_event ,void *arg); +void * +__efc_ns_gidpt_wait_rsp (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +void * +__efc_ns_idle (struct efc_sm_ctx *ctx,enum efc_sm_event evt,void *arg); +void * +__efc_ns_gidpt_delay (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +void * +__efc_fabctl_init (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +void * +__efc_fabctl_wait_node_attach (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +void * +__efc_fabctl_wait_scr_rsp (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +void * +__efc_fabctl_ready (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +void * +__efc_fabctl_wait_ls_acc_cmpl (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +void * +__efc_fabric_idle (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); + +void * +__efc_p2p_rnode_init (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +void * +__efc_p2p_domain_attach_wait (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +void * +__efc_p2p_wait_flogi_acc_cmpl (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +void * +__efc_p2p_wait_plogi_rsp (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +void * +__efc_p2p_wait_plogi_rsp_recvd_prli (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +void * +__efc_p2p_wait_domain_attach (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +void * +__efc_p2p_wait_node_attach (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); + +int +efc_p2p_setup (struct efc_sli_port *sport); +void +efc_fabric_set_topology (struct efc_node *node, +enum efc_sport_topology topology); +void efc_fabric_notify_topology (struct efc_node *node); + +#endif /* __EFCT_FABRIC_H__ */ Signature · 1 line
2.16.4
Thanks,
Daniel
Re: [PATCH v3 13/31] elx: libefc: Fabric node state machine interfaces
In reply to James SmartQuoted 124 lines · James Smart
This patch continues the libefc library population.
This patch adds library interface definitions for:
- Fabric node initialization and logins.
- Name/Directory Services node.
- Fabric Controller node to process rscn events.These are all interactions with remote ports that correspond to well-known fabric entities
Signed-off-by Ram Vegesna <[email protected]>Signed-off-by James Smart <[email protected]>---
v3:
Replaceefc_assertwithWARN_ON
Return defined return values--- drivers/scsi/elx/libefc/efc_fabric.c | 1759 ++++++++++++++++++++++++++++++++++ drivers/scsi/elx/libefc/efc_fabric.h | 116 +++ 2 files changed, 1875 insertions(+)create mode 100644
drivers/scsi/elx/libefc/efc_fabric.ccreate mode 100644drivers/scsi/elx/libefc/efc_fabric.hdrivers/scsi/elx/libefc/efc_fabric.c new file +94
-0@@ -0,0 +1,1759 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2019 Broadcom. All Rights Reserved. The term +* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +*/ + +/* +* This file implements remote node state machines for: +* - Fabric logins. +* - Fabric controller events. +* - Name/directory services interaction. +* - Point-to-point logins. +*/ + +/* +* fabric_sm Node State Machine: Fabric States +* ns_sm Node State Machine: Name/Directory Services States +* p2p_sm Node State Machine: Point-to-Point Node States +*/ + +#include "efc.h" + +static void +efc_fabric_initiate_shutdown (struct efc_node *node) +{ +int rc; +struct efc *efc = node->efc; + + efc->tt.scsi_io_alloc_disable (efc, node); + +if (node->attached) { +/* issue hw node free; don't care if succeeds right away +* or sometime later, will check node->attached later in +* shutdown process +*/ + rc = efc->tt.hw_node_detach (efc, &node->rnode); +if (rc !=EFC_HW_RTN_SUCCESS && + rc !=EFC_HW_RTN_SUCCESS_SYNC ) { +node_printf (node,"Failed freeing HW node, rc=%d\n" , + rc); + } + } +/* +* node has either been detached or is in the process of being detached, +* call common node's initiate cleanup function +*/ +efc_node_initiate_cleanup (node); +} + +static void * +__efc_fabric_common (const char *funcname,struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node =NULL ; + + node = ctx->app; + +switch (evt) { +case EFC_EVT_DOMAIN_ATTACH_OK : +break ; +case EFC_EVT_SHUTDOWN : + node->shutdown_reason =EFC_NODE_SHUTDOWN_DEFAULT ; +efc_fabric_initiate_shutdown (node); +break ; + +default : +/* call default event handler common to all nodes */ +__efc_node_common (funcname, ctx, evt, arg); +break ; + } +return NULL ; +} + +void * +__efc_fabric_init (struct efc_sm_ctx *ctx,enum efc_sm_event evt, +void *arg) +{ +struct efc_node *node = ctx->app; +struct efc *efc = node->efc; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_REENTER :/* not sure why we're getting these ... */ +efc_log_debug (efc,">>> reenter !!\n" ); +/* fall through */ +case EFC_EVT_ENTER : +/* sm: / send FLOGI */ + efc->tt.els_send (efc, node,ELS_FLOGI , +EFC_FC_FLOGI_TIMEOUT_SEC , +EFC_FC_ELS_DEFAULT_RETRIES ); +efc_node_transition (node, __efc_fabric_flogi_wait_rsp,NULL );
drivers/scsi/elx/libefc/efc_fabric.c line 104
Quoted 10 lines
drivers/scsi/elx/libefc/efc_fabric.c new file +10
-0+break ; + +default : +__efc_fabric_common (__func__, ctx, evt, arg); +break ; + } + +return NULL ; +} +
What is going on here?
Why do you declare all function as 'void *', but then continue to return only NULL pointer?
Is this some weird API logic or are these functions being fleshed out in later patches to return something else but NULL?
But as it stands I would recommend to move all of these functions to simple 'void' functions, and updating the function prototypes once they can return anything else than 'NULL'.
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
Re: [PATCH v3 13/31] elx: libefc: Fabric node state machine interfaces
Quoted 10 lines · Hannes Reinecke
What is going on here?
Why do you declare all function as 'void *', but then continue to return only NULL pointer?Is this some weird API logic or are these functions being fleshed out in later patches to return something else but NULL?
But as it stands I would recommend to move all of these functions to simple 'void' functions, and updating the function prototypes once they can return anything else than 'NULL'.
Cheers,
Hannes
We will convert to void functions. Agree with your comments.
-- james
PATCH v3 14/31 elx: libefc: FC node ELS and state handling
In reply to James SmartThis patch continues the libefc library population.
This patch adds library interface definitions for:
- FC node PRLI handling and state management
---
v3:
Replace efc_assert with WARN_ON
Bug Fix: Send LS_RJT for non FCP PRLIs
--- drivers/scsi/elx/libefc/efc_device.c | 1672 ++++++++++++++++++++++++++++++++++ drivers/scsi/elx/libefc/efc_device.h | 72 ++ 2 files changed, 1744 insertions(+) create mode 100644 drivers/scsi/elx/libefc/efc_device.c create mode 100644 drivers/scsi/elx/libefc/efc_device.h
drivers/scsi/elx/libefc/efc_device.c new file +1672 -0
@@ -0,0 +1,1672 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2019 Broadcom. All Rights Reserved. The term +* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +*/ + +/* +* device_sm Node State Machine: Remote Device States +*/ + +#include "efc.h" +#include "efc_device.h" +#include "efc_fabric.h" + +void +efc_d_send_prli_rsp (struct efc_node *node,uint16_t ox_id) +{ +struct efc *efc = node->efc; +/* If the back-end doesn't want to talk to this initiator, +* we send an LS_RJT +*/ +if (node->sport->enable_tgt && + (efc->tt.scsi_validate_node (efc, node) ==0 )) { +node_printf (node,"PRLI rejected by target-server\n" ); + + efc->tt.send_ls_rjt (efc, node, ox_id, +ELS_RJT_UNAB ,ELS_EXPL_NONE ,0 ); + node->shutdown_reason =EFC_NODE_SHUTDOWN_DEFAULT ; +efc_node_transition (node, __efc_d_initiate_shutdown,NULL ); + }else { +/* +* sm: / process PRLI payload, send PRLI acc +*/ + efc->tt.els_send_resp (efc, node,ELS_PRLI , ox_id); + +/* Immediately go to ready state to avoid window where we're +* waiting for the PRLI LS_ACC to complete while holding +* FCP_CMNDs +*/ +efc_node_transition (node, __efc_d_device_ready,NULL ); + } +} + +static void * +__efc_d_common (const char *funcname,struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node =NULL ; +struct efc *efc =NULL ; + + node = ctx->app; + efc = node->efc; + +switch (evt) { +/* Handle shutdown events */ +case EFC_EVT_SHUTDOWN : +efc_log_debug (efc,"[%s] %-20s %-20s\n" , node->display_name, + funcname,efc_sm_event_name (evt)); + node->shutdown_reason =EFC_NODE_SHUTDOWN_DEFAULT ; +efc_node_transition (node, __efc_d_initiate_shutdown,NULL ); +break ; +case EFC_EVT_SHUTDOWN_EXPLICIT_LOGO : +efc_log_debug (efc,"[%s] %-20s %-20s\n" , + node->display_name, funcname, +efc_sm_event_name (evt)); + node->shutdown_reason =EFC_NODE_SHUTDOWN_EXPLICIT_LOGO ; +efc_node_transition (node, __efc_d_initiate_shutdown,NULL ); +break ; +case EFC_EVT_SHUTDOWN_IMPLICIT_LOGO : +efc_log_debug (efc,"[%s] %-20s %-20s\n" , node->display_name, + funcname,efc_sm_event_name (evt)); + node->shutdown_reason =EFC_NODE_SHUTDOWN_IMPLICIT_LOGO ; +efc_node_transition (node, __efc_d_initiate_shutdown,NULL ); +break ; + +default : +/* call default event handler common to all nodes */ +__efc_node_common (funcname, ctx, evt, arg); +break ; + } +return NULL ; +} + +/** +* State is entered when a node sends a delete initiator/target call to the +* target-server/initiator-client and needs to wait for that work to complete. +*/ +static void * +__efc_d_wait_del_node (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +/* Fall through */ + +case EFC_EVT_NODE_ACTIVE_IO_LIST_EMPTY : +case EFC_EVT_ALL_CHILD_NODES_FREE : +/* These are expected events. */ +break ; + +case EFC_EVT_NODE_DEL_INI_COMPLETE : +case EFC_EVT_NODE_DEL_TGT_COMPLETE : +/* +* node has either been detached or is in the process +* of being detached, +* call common node's initiate cleanup function +*/ +efc_node_initiate_cleanup (node); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +case EFC_EVT_SRRS_ELS_REQ_FAIL : +/* Can happen as ELS IO IO's complete */ +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +break ; + +/* ignore shutdown events as we're already in shutdown path */ +case EFC_EVT_SHUTDOWN : +/* have default shutdown event take precedence */ + node->shutdown_reason =EFC_NODE_SHUTDOWN_DEFAULT ; +/* fall through */ +case EFC_EVT_SHUTDOWN_EXPLICIT_LOGO : +case EFC_EVT_SHUTDOWN_IMPLICIT_LOGO : +node_printf (node,"%s received\n" ,efc_sm_event_name (evt)); +break ; +case EFC_EVT_DOMAIN_ATTACH_OK : +/* don't care about domain_attach_ok */ +break ; +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +static void * +__efc_d_wait_del_ini_tgt (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +/* Fall through */ + +case EFC_EVT_NODE_ACTIVE_IO_LIST_EMPTY : +case EFC_EVT_ALL_CHILD_NODES_FREE : +/* These are expected events. */ +break ; + +case EFC_EVT_NODE_DEL_INI_COMPLETE : +case EFC_EVT_NODE_DEL_TGT_COMPLETE : +efc_node_transition (node, __efc_d_wait_del_node,NULL ); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +case EFC_EVT_SRRS_ELS_REQ_FAIL : +/* Can happen as ELS IO IO's complete */ +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +break ; + +/* ignore shutdown events as we're already in shutdown path */ +case EFC_EVT_SHUTDOWN : +/* have default shutdown event take precedence */ + node->shutdown_reason =EFC_NODE_SHUTDOWN_DEFAULT ; +/* fall through */ +case EFC_EVT_SHUTDOWN_EXPLICIT_LOGO : +case EFC_EVT_SHUTDOWN_IMPLICIT_LOGO : +node_printf (node,"%s received\n" ,efc_sm_event_name (evt)); +break ; +case EFC_EVT_DOMAIN_ATTACH_OK : +/* don't care about domain_attach_ok */ +break ; +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_d_initiate_shutdown (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; +struct efc *efc = node->efc; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : { +/* assume no wait needed */ +int rc =EFC_SCSI_CALL_COMPLETE ; + + efc->tt.scsi_io_alloc_disable (efc, node); + +/* make necessary delete upcall(s) */ +if (node->init && !node->targ) { +efc_log_info (node->efc, +"[%s] delete (initiator) WWPN %s WWNN %s\n" , + node->display_name, + node->wwpn, node->wwnn); +efc_node_transition (node, + __efc_d_wait_del_node, +NULL ); +if (node->sport->enable_tgt) + rc = efc->tt.scsi_del_node (efc, node, +EFC_SCSI_INITIATOR_DELETED ); + +if (rc ==EFC_SCSI_CALL_COMPLETE ) +efc_node_post_event (node, +EFC_EVT_NODE_DEL_INI_COMPLETE ,NULL ); + + }else if (node->targ && !node->init) { +efc_log_info (node->efc, +"[%s] delete (target) WWPN %s WWNN %s\n" , + node->display_name, + node->wwpn, node->wwnn); +efc_node_transition (node, + __efc_d_wait_del_node, +NULL ); +if (node->sport->enable_ini) + rc = efc->tt.scsi_del_node (efc, node, +EFC_SCSI_TARGET_DELETED ); + +if (rc ==EFC_SCSI_CALL_COMPLETE ) +efc_node_post_event (node, +EFC_EVT_NODE_DEL_TGT_COMPLETE ,NULL ); + + }else if (node->init && node->targ) { +efc_log_info (node->efc, +"[%s] delete (I+T) WWPN %s WWNN %s\n" , + node->display_name, node->wwpn, node->wwnn); +efc_node_transition (node, __efc_d_wait_del_ini_tgt, +NULL ); +if (node->sport->enable_tgt) + rc = efc->tt.scsi_del_node (efc, node, +EFC_SCSI_INITIATOR_DELETED ); + +if (rc ==EFC_SCSI_CALL_COMPLETE ) +efc_node_post_event (node, +EFC_EVT_NODE_DEL_INI_COMPLETE ,NULL ); +/* assume no wait needed */ + rc =EFC_SCSI_CALL_COMPLETE ; +if (node->sport->enable_ini) + rc = efc->tt.scsi_del_node (efc, node, +EFC_SCSI_TARGET_DELETED ); + +if (rc ==EFC_SCSI_CALL_COMPLETE ) +efc_node_post_event (node, +EFC_EVT_NODE_DEL_TGT_COMPLETE ,NULL ); + } + +/* we've initiated the upcalls as needed, now kick off the node +* detach to precipitate the aborting of outstanding exchanges +* associated with said node +* +* Beware: if we've made upcall(s), we've already transitioned +* to a new state by the time we execute this. +* consider doing this before the upcalls? +*/ +if (node->attached) { +/* issue hw node free; don't care if succeeds right +* away or sometime later, will check node->attached +* later in shutdown process +*/ + rc = efc->tt.hw_node_detach (efc, &node->rnode); +if (rc !=EFC_HW_RTN_SUCCESS && + rc !=EFC_HW_RTN_SUCCESS_SYNC ) +node_printf (node, +"Failed freeing HW node, rc=%d\n" , + rc); + } + +/* if neither initiator nor target, proceed to cleanup */ +if (!node->init && !node->targ) { +/* +* node has either been detached or is in +* the process of being detached, +* call common node's initiate cleanup function +*/ +efc_node_initiate_cleanup (node); + } +break ; + } +case EFC_EVT_ALL_CHILD_NODES_FREE : +/* Ignore, this can happen if an ELS is +* aborted while in a delay/retry state +*/ +break ; +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } +return NULL ; +} + +void * +__efc_d_wait_loop (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +case EFC_EVT_DOMAIN_ATTACH_OK : { +/* send PLOGI automatically if initiator */ +efc_node_init_device (node, true); +break ; + } +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +/* Save the OX_ID for sending LS_ACC sometime later */ +void +efc_send_ls_acc_after_attach (struct efc_node *node, +struct fc_frame_header *hdr, +enum efc_node_send_ls_acc ls) +{ +u16 ox_id =be16_to_cpu (hdr->fh_ox_id); + +WARN_ON (node->send_ls_acc !=EFC_NODE_SEND_LS_ACC_NONE ); + + node->ls_acc_oxid = ox_id; + node->send_ls_acc = ls; + node->ls_acc_did =ntoh24 (hdr->fh_d_id); +} + +void +efc_process_prli_payload (struct efc_node *node,void *prli) +{ +struct fc_els_spp *sp = prli +sizeof (struct fc_els_prli ); + + node->init = (sp->spp_flags &FCP_SPPF_INIT_FCN ) !=0 ; + node->targ = (sp->spp_flags &FCP_SPPF_TARG_FCN ) !=0 ; +} + +void * +__efc_d_wait_plogi_acc_cmpl (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +case EFC_EVT_SRRS_ELS_CMPL_FAIL : +WARN_ON (!node->els_cmpl_cnt); + node->els_cmpl_cnt--; + node->shutdown_reason =EFC_NODE_SHUTDOWN_DEFAULT ; +efc_node_transition (node, __efc_d_initiate_shutdown,NULL ); +break ; + +case EFC_EVT_SRRS_ELS_CMPL_OK :/* PLOGI ACC completions */ +WARN_ON (!node->els_cmpl_cnt); + node->els_cmpl_cnt--; +efc_node_transition (node, __efc_d_port_logged_in,NULL ); +break ; + +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_d_wait_logo_rsp (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +case EFC_EVT_SRRS_ELS_REQ_OK : +case EFC_EVT_SRRS_ELS_REQ_RJT : +case EFC_EVT_SRRS_ELS_REQ_FAIL : +/* LOGO response received, sent shutdown */ +if (efc_node_check_els_req (ctx, evt, arg,ELS_LOGO , + __efc_d_common, __func__)) +return NULL ; + +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +node_printf (node, +"LOGO sent (evt=%s), shutdown node\n" , +efc_sm_event_name (evt)); +/* sm: / post explicit logout */ +efc_node_post_event (node,EFC_EVT_SHUTDOWN_EXPLICIT_LOGO , +NULL ); +break ; + +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } +return NULL ; +} + +void +efc_node_init_device (struct efc_node *node,bool send_plogi) +{ + node->send_plogi = send_plogi; +if ((node->efc->nodedb_mask &EFC_NODEDB_PAUSE_NEW_NODES ) && + (node->rnode.fc_id !=FC_FID_DOM_MGR )) { + node->nodedb_state = __efc_d_init; +efc_node_transition (node, __efc_node_paused,NULL ); + }else { +efc_node_transition (node, __efc_d_init,NULL ); + } +} + +/** +* Device node state machine: Initial node state for an initiator or +* a target. +* +* This state is entered when a node is instantiated, either having been +* discovered from a name services query, or having received a PLOGI/FLOGI. +*/ +void * +__efc_d_init (struct efc_sm_ctx *ctx,enum efc_sm_event evt,void *arg) +{ +int rc; +struct efc_node_cb *cbdata = arg; +struct efc_node *node = ctx->app; +struct efc *efc = node->efc; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +if (!node->send_plogi) +break ; +/* only send if we have initiator capability, +* and domain is attached +*/ +if (node->sport->enable_ini && + node->sport->domain->attached) { + efc->tt.els_send (efc, node,ELS_PLOGI , +EFC_FC_FLOGI_TIMEOUT_SEC , +EFC_FC_ELS_DEFAULT_RETRIES ); + +efc_node_transition (node, __efc_d_wait_plogi_rsp,NULL ); + }else { +node_printf (node,"not sending plogi sport.ini=%d," , + node->sport->enable_ini); +node_printf (node,"domain attached=%d\n" , + node->sport->domain->attached); + } +break ; +case EFC_EVT_PLOGI_RCVD : { +/* T, or I+T */ +struct fc_frame_header *hdr = cbdata->header->dma.virt; +u32 d_id =ntoh24 (hdr->fh_d_id); + +efc_node_save_sparms (node, cbdata->payload->dma.virt); +efc_send_ls_acc_after_attach (node, + cbdata->header->dma.virt, +EFC_NODE_SEND_LS_ACC_PLOGI ); + +/* domain already attached */ +if (node->sport->domain->attached) { + rc =efc_node_attach (node); +efc_node_transition (node, + __efc_d_wait_node_attach,NULL ); +if (rc ==EFC_HW_RTN_SUCCESS_SYNC ) { +efc_node_post_event (node, +EFC_EVT_NODE_ATTACH_OK , +NULL ); + } +break ; + } + +/* domain not attached; several possibilities: */ +switch (node->sport->topology) { +case EFC_SPORT_TOPOLOGY_P2P : +/* we're not attached and sport is p2p, +* need to attach +*/ +efc_domain_attach (node->sport->domain, d_id); +efc_node_transition (node, + __efc_d_wait_domain_attach, +NULL ); +break ; +case EFC_SPORT_TOPOLOGY_FABRIC : +/* we're not attached and sport is fabric, domain +* attach should have already been requested as part +* of the fabric state machine, wait for it +*/ +efc_node_transition (node, __efc_d_wait_domain_attach, +NULL ); +break ; +case EFC_SPORT_TOPOLOGY_UNKNOWN : +/* Two possibilities: +* 1. received a PLOGI before our FLOGI has completed +* (possible since completion comes in on another +* CQ), thus we don't know what we're connected to +* yet; transition to a state to wait for the +* fabric node to tell us; +* 2. PLOGI received before link went down and we +* haven't performed domain attach yet. +* Note: we cannot distinguish between 1. and 2. +* so have to assume PLOGI +* was received after link back up. +*/ +node_printf (node, +"received PLOGI, unknown topology did=0x%x\n" , + d_id); +efc_node_transition (node, + __efc_d_wait_topology_notify, +NULL ); +break ; +default : +node_printf (node, +"received PLOGI, with unexpected topology %d\n" , + node->sport->topology); +break ; + } +break ; + } + +case EFC_EVT_FDISC_RCVD : { +__efc_d_common (__func__, ctx, evt, arg); +break ; + } + +case EFC_EVT_FLOGI_RCVD : { +struct fc_frame_header *hdr = cbdata->header->dma.virt; +u32 d_id =ntoh24 (hdr->fh_d_id); + +/* sm: / save sparams, send FLOGI acc */ +memcpy (node->sport->domain->flogi_service_params, + cbdata->payload->dma.virt, +sizeof (struct fc_els_flogi )); + +/* send FC LS_ACC response, override s_id */ +efc_fabric_set_topology (node,EFC_SPORT_TOPOLOGY_P2P ); + efc->tt.send_flogi_p2p_acc (efc, node, +be16_to_cpu (hdr->fh_ox_id), d_id); +if (efc_p2p_setup (node->sport)) { +node_printf (node, +"p2p setup failed, shutting down node\n" ); +efc_node_post_event (node,EFC_EVT_SHUTDOWN ,NULL ); + }else { +efc_node_transition (node, + __efc_p2p_wait_flogi_acc_cmpl, +NULL ); + } + +break ; + } + +case EFC_EVT_LOGO_RCVD : { +struct fc_frame_header *hdr = cbdata->header->dma.virt; + +if (!node->sport->domain->attached) { +/* most likely a frame left over from before a link +* down; drop and +* shut node down w/ "explicit logout" so pending +* frames are processed +*/ +node_printf (node,"%s domain not attached, dropping\n" , +efc_sm_event_name (evt)); +efc_node_post_event (node, +EFC_EVT_SHUTDOWN_EXPLICIT_LOGO , +NULL ); +break ; + } + efc->tt.els_send_resp (efc, node,ELS_LOGO , +be16_to_cpu (hdr->fh_ox_id)); +efc_node_transition (node, __efc_d_wait_logo_acc_cmpl,NULL ); +break ; + } + +case EFC_EVT_PRLI_RCVD : +case EFC_EVT_PRLO_RCVD : +case EFC_EVT_PDISC_RCVD : +case EFC_EVT_ADISC_RCVD : +case EFC_EVT_RSCN_RCVD : { +struct fc_frame_header *hdr = cbdata->header->dma.virt; + +if (!node->sport->domain->attached) { +/* most likely a frame left over from before a link +* down; drop and shut node down w/ "explicit logout" +* so pending frames are processed +*/ +node_printf (node,"%s domain not attached, dropping\n" , +efc_sm_event_name (evt)); + +efc_node_post_event (node, +EFC_EVT_SHUTDOWN_EXPLICIT_LOGO , +NULL ); +break ; + } +node_printf (node,"%s received, sending reject\n" , +efc_sm_event_name (evt)); + efc->tt.send_ls_rjt (efc, node,be16_to_cpu (hdr->fh_ox_id), +ELS_RJT_UNAB ,ELS_EXPL_PLOGI_REQD ,0 ); + +break ; + } + +case EFC_EVT_FCP_CMD_RCVD : { +/* note: problem, we're now expecting an ELS REQ completion +* from both the LOGO and PLOGI +*/ +if (!node->sport->domain->attached) { +/* most likely a frame left over from before a +* link down; drop and +* shut node down w/ "explicit logout" so pending +* frames are processed +*/ +node_printf (node,"%s domain not attached, dropping\n" , +efc_sm_event_name (evt)); +efc_node_post_event (node, +EFC_EVT_SHUTDOWN_EXPLICIT_LOGO , +NULL ); +break ; + } + +/* Send LOGO */ +node_printf (node,"FCP_CMND received, send LOGO\n" ); +if (efc->tt.els_send (efc, node,ELS_LOGO , +EFC_FC_FLOGI_TIMEOUT_SEC , +EFC_FC_ELS_DEFAULT_RETRIES ) ==NULL ) { +/* +* failed to send LOGO, go ahead and cleanup node +* anyways +*/ +node_printf (node,"Failed to send LOGO\n" ); +efc_node_post_event (node, +EFC_EVT_SHUTDOWN_EXPLICIT_LOGO , +NULL ); + }else { +/* sent LOGO, wait for response */ +efc_node_transition (node, + __efc_d_wait_logo_rsp,NULL ); + } +break ; + } +case EFC_EVT_DOMAIN_ATTACH_OK : +/* don't care about domain_attach_ok */ +break ; + +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_d_wait_plogi_rsp (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +int rc; +struct efc_node_cb *cbdata = arg; +struct efc_node *node = ctx->app; +struct efc *efc = node->efc; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_PLOGI_RCVD : { +/* T, or I+T */ +/* received PLOGI with svc parms, go ahead and attach node +* when PLOGI that was sent ultimately completes, it'll be a +* no-op +* +* If there is an outstanding PLOGI sent, can we set a flag +* to indicate that we don't want to retry it if it times out? +*/ +efc_node_save_sparms (node, cbdata->payload->dma.virt); +efc_send_ls_acc_after_attach (node, + cbdata->header->dma.virt, +EFC_NODE_SEND_LS_ACC_PLOGI ); +/* sm: domain->attached / efc_node_attach */ + rc =efc_node_attach (node); +efc_node_transition (node, __efc_d_wait_node_attach,NULL ); +if (rc ==EFC_HW_RTN_SUCCESS_SYNC ) +efc_node_post_event (node, +EFC_EVT_NODE_ATTACH_OK ,NULL ); + +break ; + } + +case EFC_EVT_PRLI_RCVD : +/* I, or I+T */ +/* sent PLOGI and before completion was seen, received the +* PRLI from the remote node (WCQEs and RCQEs come in on +* different queues and order of processing cannot be assumed) +* Save OXID so PRLI can be sent after the attach and continue +* to wait for PLOGI response +*/ +efc_process_prli_payload (node, cbdata->payload->dma.virt); +efc_send_ls_acc_after_attach (node, + cbdata->header->dma.virt, +EFC_NODE_SEND_LS_ACC_PRLI ); +efc_node_transition (node, __efc_d_wait_plogi_rsp_recvd_prli, +NULL ); +break ; + +case EFC_EVT_LOGO_RCVD :/* why don't we do a shutdown here?? */ +case EFC_EVT_PRLO_RCVD : +case EFC_EVT_PDISC_RCVD : +case EFC_EVT_FDISC_RCVD : +case EFC_EVT_ADISC_RCVD : +case EFC_EVT_RSCN_RCVD : +case EFC_EVT_SCR_RCVD : { +struct fc_frame_header *hdr = cbdata->header->dma.virt; + +node_printf (node,"%s received, sending reject\n" , +efc_sm_event_name (evt)); + + efc->tt.send_ls_rjt (efc, node,be16_to_cpu (hdr->fh_ox_id), +ELS_RJT_UNAB ,ELS_EXPL_PLOGI_REQD ,0 ); + +break ; + } + +case EFC_EVT_SRRS_ELS_REQ_OK :/* PLOGI response received */ +/* Completion from PLOGI sent */ +if (efc_node_check_els_req (ctx, evt, arg,ELS_PLOGI , + __efc_d_common, __func__)) +return NULL ; + +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +/* sm: / save sparams, efc_node_attach */ +efc_node_save_sparms (node, cbdata->els_rsp.virt); + rc =efc_node_attach (node); +efc_node_transition (node, __efc_d_wait_node_attach,NULL ); +if (rc ==EFC_HW_RTN_SUCCESS_SYNC ) +efc_node_post_event (node, +EFC_EVT_NODE_ATTACH_OK ,NULL ); + +break ; + +case EFC_EVT_SRRS_ELS_REQ_FAIL :/* PLOGI response received */ +/* PLOGI failed, shutdown the node */ +if (efc_node_check_els_req (ctx, evt, arg,ELS_PLOGI , + __efc_d_common, __func__)) +return NULL ; + +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +efc_node_post_event (node,EFC_EVT_SHUTDOWN ,NULL ); +break ; + +case EFC_EVT_SRRS_ELS_REQ_RJT : +/* Our PLOGI was rejected, this is ok in some cases */ +if (efc_node_check_els_req (ctx, evt, arg,ELS_PLOGI , + __efc_d_common, __func__)) +return NULL ; + +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +break ; + +case EFC_EVT_FCP_CMD_RCVD : { +/* not logged in yet and outstanding PLOGI so don't send LOGO, +* just drop +*/ +node_printf (node,"FCP_CMND received, drop\n" ); +break ; + } + +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_d_wait_plogi_rsp_recvd_prli (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +int rc; +struct efc_node_cb *cbdata = arg; +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +/* +* Since we've received a PRLI, we have a port login and will +* just need to wait for the PLOGI response to do the node +* attach and then we can send the LS_ACC for the PRLI. If, +* during this time, we receive FCP_CMNDs (which is possible +* since we've already sent a PRLI and our peer may have +* accepted). At this time, we are not waiting on any other +* unsolicited frames to continue with the login process. Thus, +* it will not hurt to hold frames here. +*/ +efc_node_hold_frames (node); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +case EFC_EVT_SRRS_ELS_REQ_OK :/* PLOGI response received */ +/* Completion from PLOGI sent */ +if (efc_node_check_els_req (ctx, evt, arg,ELS_PLOGI , + __efc_d_common, __func__)) +return NULL ; + +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +/* sm: / save sparams, efc_node_attach */ +efc_node_save_sparms (node, cbdata->els_rsp.virt); + rc =efc_node_attach (node); +efc_node_transition (node, __efc_d_wait_node_attach,NULL ); +if (rc ==EFC_HW_RTN_SUCCESS_SYNC ) +efc_node_post_event (node,EFC_EVT_NODE_ATTACH_OK , +NULL ); + +break ; + +case EFC_EVT_SRRS_ELS_REQ_FAIL :/* PLOGI response received */ +case EFC_EVT_SRRS_ELS_REQ_RJT : +/* PLOGI failed, shutdown the node */ +if (efc_node_check_els_req (ctx, evt, arg,ELS_PLOGI , + __efc_d_common, __func__)) +return NULL ; + +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +efc_node_post_event (node,EFC_EVT_SHUTDOWN ,NULL ); +break ; + +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_d_wait_domain_attach (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +int rc; +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +case EFC_EVT_DOMAIN_ATTACH_OK : +WARN_ON (!node->sport->domain->attached); +/* sm: / efc_node_attach */ + rc =efc_node_attach (node); +efc_node_transition (node, __efc_d_wait_node_attach,NULL ); +if (rc ==EFC_HW_RTN_SUCCESS_SYNC ) +efc_node_post_event (node,EFC_EVT_NODE_ATTACH_OK , +NULL ); + +break ; + +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } +return NULL ; +} + +void * +__efc_d_wait_topology_notify (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +int rc; +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +case EFC_EVT_SPORT_TOPOLOGY_NOTIFY : { +enum efc_sport_topology topology = + (enum efc_sport_topology )arg; + +WARN_ON (node->sport->domain->attached); + +WARN_ON (node->send_ls_acc !=EFC_NODE_SEND_LS_ACC_PLOGI ); + +node_printf (node,"topology notification, topology=%d\n" , + topology); + +/* At the time the PLOGI was received, the topology was unknown, +* so we didn't know which node would perform the domain attach: +* 1. The node from which the PLOGI was sent (p2p) or +* 2. The node to which the FLOGI was sent (fabric). +*/ +if (topology ==EFC_SPORT_TOPOLOGY_P2P ) { +/* if this is p2p, need to attach to the domain using +* the d_id from the PLOGI received +*/ +efc_domain_attach (node->sport->domain, + node->ls_acc_did); + } +/* else, if this is fabric, the domain attach +* should be performed by the fabric node (node sending FLOGI); +* just wait for attach to complete +*/ + +efc_node_transition (node, __efc_d_wait_domain_attach,NULL ); +break ; + } +case EFC_EVT_DOMAIN_ATTACH_OK : +WARN_ON (!node->sport->domain->attached); +node_printf (node,"domain attach ok\n" ); +/* sm: / efc_node_attach */ + rc =efc_node_attach (node); +efc_node_transition (node, __efc_d_wait_node_attach,NULL ); +if (rc ==EFC_HW_RTN_SUCCESS_SYNC ) +efc_node_post_event (node, +EFC_EVT_NODE_ATTACH_OK ,NULL ); + +break ; + +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } +return NULL ; +} + +void * +__efc_d_wait_node_attach (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; +struct efc *efc = node->efc; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +case EFC_EVT_NODE_ATTACH_OK : + node->attached = true; +switch (node->send_ls_acc) { +case EFC_NODE_SEND_LS_ACC_PLOGI : { +/* sm: send_plogi_acc is set / send PLOGI acc */ +/* Normal case for T, or I+T */ + efc->tt.els_send_resp (efc, node,ELS_PLOGI , + node->ls_acc_oxid); +efc_node_transition (node, + __efc_d_wait_plogi_acc_cmpl, +NULL ); + node->send_ls_acc =EFC_NODE_SEND_LS_ACC_NONE ; + node->ls_acc_io =NULL ; +break ; + } +case EFC_NODE_SEND_LS_ACC_PRLI : { +efc_d_send_prli_rsp (node, + node->ls_acc_oxid); + node->send_ls_acc =EFC_NODE_SEND_LS_ACC_NONE ; + node->ls_acc_io =NULL ; +break ; + } +case EFC_NODE_SEND_LS_ACC_NONE : +default : +/* Normal case for I */ +/* sm: send_plogi_acc is not set / send PLOGI acc */ +efc_node_transition (node, + __efc_d_port_logged_in,NULL ); +break ; + } +break ; + +case EFC_EVT_NODE_ATTACH_FAIL : +/* node attach failed, shutdown the node */ + node->attached = false; +node_printf (node,"node attach failed\n" ); + node->shutdown_reason =EFC_NODE_SHUTDOWN_DEFAULT ; +efc_node_transition (node, __efc_d_initiate_shutdown,NULL ); +break ; + +/* Handle shutdown events */ +case EFC_EVT_SHUTDOWN : +node_printf (node,"%s received\n" ,efc_sm_event_name (evt)); + node->shutdown_reason =EFC_NODE_SHUTDOWN_DEFAULT ; +efc_node_transition (node, __efc_d_wait_attach_evt_shutdown, +NULL ); +break ; +case EFC_EVT_SHUTDOWN_EXPLICIT_LOGO : +node_printf (node,"%s received\n" ,efc_sm_event_name (evt)); + node->shutdown_reason =EFC_NODE_SHUTDOWN_EXPLICIT_LOGO ; +efc_node_transition (node, __efc_d_wait_attach_evt_shutdown, +NULL ); +break ; +case EFC_EVT_SHUTDOWN_IMPLICIT_LOGO : +node_printf (node,"%s received\n" ,efc_sm_event_name (evt)); + node->shutdown_reason =EFC_NODE_SHUTDOWN_IMPLICIT_LOGO ; +efc_node_transition (node, + __efc_d_wait_attach_evt_shutdown,NULL ); +break ; +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_d_wait_attach_evt_shutdown (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +/* wait for any of these attach events and then shutdown */ +case EFC_EVT_NODE_ATTACH_OK : + node->attached = true; +node_printf (node,"Attach evt=%s, proceed to shutdown\n" , +efc_sm_event_name (evt)); +efc_node_transition (node, __efc_d_initiate_shutdown,NULL ); +break ; + +case EFC_EVT_NODE_ATTACH_FAIL : +/* node attach failed, shutdown the node */ + node->attached = false; +node_printf (node,"Attach evt=%s, proceed to shutdown\n" , +efc_sm_event_name (evt)); +efc_node_transition (node, __efc_d_initiate_shutdown,NULL ); +break ; + +/* ignore shutdown events as we're already in shutdown path */ +case EFC_EVT_SHUTDOWN : +/* have default shutdown event take precedence */ + node->shutdown_reason =EFC_NODE_SHUTDOWN_DEFAULT ; +/* fall through */ +case EFC_EVT_SHUTDOWN_EXPLICIT_LOGO : +case EFC_EVT_SHUTDOWN_IMPLICIT_LOGO : +node_printf (node,"%s received\n" ,efc_sm_event_name (evt)); +break ; + +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_d_port_logged_in (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node_cb *cbdata = arg; +struct efc_node *node = ctx->app; +struct efc *efc = node->efc; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +/* Normal case for I or I+T */ +if (node->sport->enable_ini && + !(node->rnode.fc_id !=FC_FID_DOM_MGR )) { +/* sm: if enable_ini / send PRLI */ + efc->tt.els_send (efc, node,ELS_PRLI , +EFC_FC_ELS_SEND_DEFAULT_TIMEOUT , +EFC_FC_ELS_DEFAULT_RETRIES ); +/* can now expect ELS_REQ_OK/FAIL/RJT */ + } +break ; + +case EFC_EVT_FCP_CMD_RCVD : { +break ; + } + +case EFC_EVT_PRLI_RCVD : { +/* Normal case for T or I+T */ +struct fc_frame_header *hdr = cbdata->header->dma.virt; +struct fc_els_spp *sp = cbdata->payload->dma.virt + +sizeof (struct fc_els_prli ); + +if (sp->spp_type !=FC_TYPE_FCP ) { +/*Only FCP is supported*/ + efc->tt.send_ls_rjt (efc, node, +be16_to_cpu (hdr->fh_ox_id), +ELS_RJT_UNAB ,ELS_EXPL_UNSUPR ,0 ); +break ; + } + +efc_process_prli_payload (node, cbdata->payload->dma.virt); +efc_d_send_prli_rsp (node,be16_to_cpu (hdr->fh_ox_id)); +break ; + } + +case EFC_EVT_SRRS_ELS_REQ_OK : {/* PRLI response */ +/* Normal case for I or I+T */ +if (efc_node_check_els_req (ctx, evt, arg,ELS_PRLI , + __efc_d_common, __func__)) +return NULL ; + +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +/* sm: / process PRLI payload */ +efc_process_prli_payload (node, cbdata->els_rsp.virt); +efc_node_transition (node, __efc_d_device_ready,NULL ); +break ; + } + +case EFC_EVT_SRRS_ELS_REQ_FAIL : {/* PRLI response failed */ +/* I, I+T, assume some link failure, shutdown node */ +if (efc_node_check_els_req (ctx, evt, arg,ELS_PRLI , + __efc_d_common, __func__)) +return NULL ; + +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +efc_node_post_event (node,EFC_EVT_SHUTDOWN ,NULL ); +break ; + } + +case EFC_EVT_SRRS_ELS_REQ_RJT : { +/* PRLI rejected by remote +* Normal for I, I+T (connected to an I) +* Node doesn't want to be a target, stay here and wait for a +* PRLI from the remote node +* if it really wants to connect to us as target +*/ +if (efc_node_check_els_req (ctx, evt, arg,ELS_PRLI , + __efc_d_common, __func__)) +return NULL ; + +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +break ; + } + +case EFC_EVT_SRRS_ELS_CMPL_OK : { +/* Normal T, I+T, target-server rejected the process login */ +/* This would be received only in the case where we sent +* LS_RJT for the PRLI, so +* do nothing. (note: as T only we could shutdown the node) +*/ +WARN_ON (!node->els_cmpl_cnt); + node->els_cmpl_cnt--; +break ; + } + +case EFC_EVT_PLOGI_RCVD : { +/*sm: / save sparams, set send_plogi_acc, +*post implicit logout +* Save plogi parameters +*/ +efc_node_save_sparms (node, cbdata->payload->dma.virt); +efc_send_ls_acc_after_attach (node, + cbdata->header->dma.virt, +EFC_NODE_SEND_LS_ACC_PLOGI ); + +/* Restart node attach with new service parameters, +* and send ACC +*/ +efc_node_post_event (node,EFC_EVT_SHUTDOWN_IMPLICIT_LOGO , +NULL ); +break ; + } + +case EFC_EVT_LOGO_RCVD : { +/* I, T, I+T */ +struct fc_frame_header *hdr = cbdata->header->dma.virt; + +node_printf (node,"%s received attached=%d\n" , +efc_sm_event_name (evt), + node->attached); +/* sm: / send LOGO acc */ + efc->tt.els_send_resp (efc, node,ELS_LOGO , +be16_to_cpu (hdr->fh_ox_id)); +efc_node_transition (node, __efc_d_wait_logo_acc_cmpl,NULL ); +break ; + } + +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_d_wait_logo_acc_cmpl (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +case EFC_EVT_SRRS_ELS_CMPL_OK : +case EFC_EVT_SRRS_ELS_CMPL_FAIL : +/* sm: / post explicit logout */ +WARN_ON (!node->els_cmpl_cnt); + node->els_cmpl_cnt--; +efc_node_post_event (node, +EFC_EVT_SHUTDOWN_EXPLICIT_LOGO ,NULL ); +break ; +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_d_device_ready (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node_cb *cbdata = arg; +struct efc_node *node = ctx->app; +struct efc *efc = node->efc; + +efc_node_evt_set (ctx, evt, __func__); + +if (evt !=EFC_EVT_FCP_CMD_RCVD ) +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : + node->fcp_enabled = true; +if (node->init) { +efc_log_info (efc, +"[%s] found (initiator) WWPN %s WWNN %s\n" , + node->display_name, + node->wwpn, node->wwnn); +if (node->sport->enable_tgt) + efc->tt.scsi_new_node (efc, node); + } +if (node->targ) { +efc_log_info (efc, +"[%s] found (target) WWPN %s WWNN %s\n" , + node->display_name, + node->wwpn, node->wwnn); +if (node->sport->enable_ini) + efc->tt.scsi_new_node (efc, node); + } +break ; + +case EFC_EVT_EXIT : + node->fcp_enabled = false; +break ; + +case EFC_EVT_PLOGI_RCVD : { +/* sm: / save sparams, set send_plogi_acc, post implicit +* logout +* Save plogi parameters +*/ +efc_node_save_sparms (node, cbdata->payload->dma.virt); +efc_send_ls_acc_after_attach (node, + cbdata->header->dma.virt, +EFC_NODE_SEND_LS_ACC_PLOGI ); + +/* +* Restart node attach with new service parameters, +* and send ACC +*/ +efc_node_post_event (node, +EFC_EVT_SHUTDOWN_IMPLICIT_LOGO ,NULL ); +break ; + } + +case EFC_EVT_PRLI_RCVD : { +/* T, I+T: remote initiator is slow to get started */ +struct fc_frame_header *hdr = cbdata->header->dma.virt; +struct fc_els_spp *sp = cbdata->payload->dma.virt + +sizeof (struct fc_els_prli ); + +if (sp->spp_type !=FC_TYPE_FCP ) { +/*Only FCP is supported*/ + efc->tt.send_ls_rjt (efc, node, +be16_to_cpu (hdr->fh_ox_id), +ELS_RJT_UNAB ,ELS_EXPL_UNSUPR ,0 ); +break ; + } + +efc_process_prli_payload (node, cbdata->payload->dma.virt); + + efc->tt.els_send_resp (efc, node,ELS_PRLI , +be16_to_cpu (hdr->fh_ox_id)); +break ; + } + +case EFC_EVT_PRLO_RCVD : { +struct fc_frame_header *hdr = cbdata->header->dma.virt; +/* sm: / send PRLO acc */ + efc->tt.els_send_resp (efc, node,ELS_PRLO , +be16_to_cpu (hdr->fh_ox_id)); +/* need implicit logout? */ +break ; + } + +case EFC_EVT_LOGO_RCVD : { +struct fc_frame_header *hdr = cbdata->header->dma.virt; + +node_printf (node,"%s received attached=%d\n" , +efc_sm_event_name (evt), node->attached); +/* sm: / send LOGO acc */ + efc->tt.els_send_resp (efc, node,ELS_LOGO , +be16_to_cpu (hdr->fh_ox_id)); +efc_node_transition (node, __efc_d_wait_logo_acc_cmpl,NULL ); +break ; + } + +case EFC_EVT_ADISC_RCVD : { +struct fc_frame_header *hdr = cbdata->header->dma.virt; +/* sm: / send ADISC acc */ + efc->tt.els_send_resp (efc, node,ELS_ADISC , +be16_to_cpu (hdr->fh_ox_id)); +break ; + } + +case EFC_EVT_ABTS_RCVD : +/* sm: / process ABTS */ +efc_log_err (efc,"Unexpected event:%s\n" , +efc_sm_event_name (evt)); +break ; + +case EFC_EVT_NODE_ACTIVE_IO_LIST_EMPTY : +break ; + +case EFC_EVT_NODE_REFOUND : +break ; + +case EFC_EVT_NODE_MISSING : +if (node->sport->enable_rscn) +efc_node_transition (node, __efc_d_device_gone,NULL ); + +break ; + +case EFC_EVT_SRRS_ELS_CMPL_OK : +/* T, or I+T, PRLI accept completed ok */ +WARN_ON (!node->els_cmpl_cnt); + node->els_cmpl_cnt--; +break ; + +case EFC_EVT_SRRS_ELS_CMPL_FAIL : +/* T, or I+T, PRLI accept failed to complete */ +WARN_ON (!node->els_cmpl_cnt); + node->els_cmpl_cnt--; +node_printf (node,"Failed to send PRLI LS_ACC\n" ); +break ; + +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_d_device_gone (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +int rc =EFC_SCSI_CALL_COMPLETE ; +int rc_2 =EFC_SCSI_CALL_COMPLETE ; +struct efc_node_cb *cbdata = arg; +struct efc_node *node = ctx->app; +struct efc *efc = node->efc; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : { +static char const *labels[] = {"none" ,"initiator" ,"target" , +"initiator+target" }; + +efc_log_info (efc,"[%s] missing (%s) WWPN %s WWNN %s\n" , + node->display_name, + labels[(node->targ <<1 ) | (node->init)], + node->wwpn, node->wwnn); + +switch (efc_node_get_enable (node)) { +case EFC_NODE_ENABLE_T_TO_T : +case EFC_NODE_ENABLE_I_TO_T : +case EFC_NODE_ENABLE_IT_TO_T : + rc = efc->tt.scsi_del_node (efc, node, +EFC_SCSI_TARGET_MISSING ); +break ; + +case EFC_NODE_ENABLE_T_TO_I : +case EFC_NODE_ENABLE_I_TO_I : +case EFC_NODE_ENABLE_IT_TO_I : + rc = efc->tt.scsi_del_node (efc, node, +EFC_SCSI_INITIATOR_MISSING ); +break ; + +case EFC_NODE_ENABLE_T_TO_IT : + rc = efc->tt.scsi_del_node (efc, node, +EFC_SCSI_INITIATOR_MISSING ); +break ; + +case EFC_NODE_ENABLE_I_TO_IT : + rc = efc->tt.scsi_del_node (efc, node, +EFC_SCSI_TARGET_MISSING ); +break ; + +case EFC_NODE_ENABLE_IT_TO_IT : + rc = efc->tt.scsi_del_node (efc, node, +EFC_SCSI_INITIATOR_MISSING ); + rc_2 = efc->tt.scsi_del_node (efc, node, +EFC_SCSI_TARGET_MISSING ); +break ; + +default : + rc =EFC_SCSI_CALL_COMPLETE ; +break ; + } + +if (rc ==EFC_SCSI_CALL_COMPLETE && + rc_2 ==EFC_SCSI_CALL_COMPLETE ) +efc_node_post_event (node,EFC_EVT_SHUTDOWN ,NULL ); + +break ; + } +case EFC_EVT_NODE_REFOUND : +/* two approaches, reauthenticate with PLOGI/PRLI, or ADISC */ + +/* reauthenticate with PLOGI/PRLI */ +/* efc_node_transition(node, __efc_d_discovered, NULL); */ + +/* reauthenticate with ADISC */ +/* sm: / send ADISC */ + efc->tt.els_send (efc, node,ELS_ADISC , +EFC_FC_FLOGI_TIMEOUT_SEC , +EFC_FC_ELS_DEFAULT_RETRIES ); +efc_node_transition (node, __efc_d_wait_adisc_rsp,NULL ); +break ; + +case EFC_EVT_PLOGI_RCVD : { +/* sm: / save sparams, set send_plogi_acc, post implicit +* logout +* Save plogi parameters +*/ +efc_node_save_sparms (node, cbdata->payload->dma.virt); +efc_send_ls_acc_after_attach (node, + cbdata->header->dma.virt, +EFC_NODE_SEND_LS_ACC_PLOGI ); + +/* +* Restart node attach with new service parameters, and send +* ACC +*/ +efc_node_post_event (node,EFC_EVT_SHUTDOWN_IMPLICIT_LOGO , +NULL ); +break ; + } + +case EFC_EVT_FCP_CMD_RCVD : { +/* most likely a stale frame (received prior to link down), +* if attempt to send LOGO, will probably timeout and eat +* up 20s; thus, drop FCP_CMND +*/ +node_printf (node,"FCP_CMND received, drop\n" ); +break ; + } +case EFC_EVT_LOGO_RCVD : { +/* I, T, I+T */ +struct fc_frame_header *hdr = cbdata->header->dma.virt; + +node_printf (node,"%s received attached=%d\n" , +efc_sm_event_name (evt), node->attached); +/* sm: / send LOGO acc */ + efc->tt.els_send_resp (efc, node,ELS_LOGO , +be16_to_cpu (hdr->fh_ox_id)); +efc_node_transition (node, __efc_d_wait_logo_acc_cmpl,NULL ); +break ; + } +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_d_wait_adisc_rsp (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node_cb *cbdata = arg; +struct efc_node *node = ctx->app; +struct efc *efc = node->efc; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_SRRS_ELS_REQ_OK : +if (efc_node_check_els_req (ctx, evt, arg,ELS_ADISC , + __efc_d_common, __func__)) +return NULL ; + +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +efc_node_transition (node, __efc_d_device_ready,NULL ); +break ; + +case EFC_EVT_SRRS_ELS_REQ_RJT : +/* received an LS_RJT, in this case, send shutdown +* (explicit logo) event which will unregister the node, +* and start over with PLOGI +*/ +if (efc_node_check_els_req (ctx, evt, arg,ELS_ADISC , + __efc_d_common, __func__)) +return NULL ; + +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +/* sm: / post explicit logout */ +efc_node_post_event (node, +EFC_EVT_SHUTDOWN_EXPLICIT_LOGO , +NULL ); +break ; + +case EFC_EVT_LOGO_RCVD : { +/* In this case, we have the equivalent of an LS_RJT for +* the ADISC, so we need to abort the ADISC, and re-login +* with PLOGI +*/ +/* sm: / request abort, send LOGO acc */ +struct fc_frame_header *hdr = cbdata->header->dma.virt; + +node_printf (node,"%s received attached=%d\n" , +efc_sm_event_name (evt), node->attached); + + efc->tt.els_send_resp (efc, node,ELS_LOGO , +be16_to_cpu (hdr->fh_ox_id)); +efc_node_transition (node, __efc_d_wait_logo_acc_cmpl,NULL ); +break ; + } +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +}
drivers/scsi/elx/libefc/efc_device.h new file +72 -0
72 lines not on this page · raw message
Signature · 1 line
2.16.4
Re: [PATCH v3 14/31] elx: libefc: FC node ELS and state handling
Quoted 116 lines · James Smart
This patch continues the libefc library population.
This patch adds library interface definitions for:
- FC node PRLI handling and state managementSigned-off-by Ram Vegesna <[email protected]>Signed-off-by James Smart <[email protected]>---
v3:
Replaceefc_assertwithWARN_ON
Bug Fix: SendLS_RJTfor non FCP PRLIs--- drivers/scsi/elx/libefc/efc_device.c | 1672 ++++++++++++++++++++++++++++++++++ drivers/scsi/elx/libefc/efc_device.h | 72 ++ 2 files changed, 1744 insertions(+) create mode 100644 drivers/scsi/elx/libefc/efc_device.c create mode 100644 drivers/scsi/elx/libefc/efc_device.hdrivers/scsi/elx/libefc/efc_device.c new file +91
-0@@ -0,0 +1,1672 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2019 Broadcom. All Rights Reserved. The term +* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +*/ + +/* +* device_sm Node State Machine: Remote Device States +*/ + +#include "efc.h" +#include "efc_device.h" +#include "efc_fabric.h" + +void +efc_d_send_prli_rsp (struct efc_node *node,uint16_t ox_id) +{ +struct efc *efc = node->efc; +/* If the back-end doesn't want to talk to this initiator, +* we send an LS_RJT +*/ +if (node->sport->enable_tgt && + (efc->tt.scsi_validate_node (efc, node) ==0 )) { +node_printf (node,"PRLI rejected by target-server\n" ); + + efc->tt.send_ls_rjt (efc, node, ox_id, +ELS_RJT_UNAB ,ELS_EXPL_NONE ,0 ); + node->shutdown_reason =EFC_NODE_SHUTDOWN_DEFAULT ; +efc_node_transition (node, __efc_d_initiate_shutdown,NULL ); + }else { +/* +* sm: / process PRLI payload, send PRLI acc +*/ + efc->tt.els_send_resp (efc, node,ELS_PRLI , ox_id); + +/* Immediately go to ready state to avoid window where we're +* waiting for the PRLI LS_ACC to complete while holding +* FCP_CMNDs +*/ +efc_node_transition (node, __efc_d_device_ready,NULL ); + } +} + +static void * +__efc_d_common (const char *funcname,struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node =NULL ; +struct efc *efc =NULL ; + + node = ctx->app; + efc = node->efc; + +switch (evt) { +/* Handle shutdown events */ +case EFC_EVT_SHUTDOWN : +efc_log_debug (efc,"[%s] %-20s %-20s\n" , node->display_name, + funcname,efc_sm_event_name (evt)); + node->shutdown_reason =EFC_NODE_SHUTDOWN_DEFAULT ; +efc_node_transition (node, __efc_d_initiate_shutdown,NULL ); +break ; +case EFC_EVT_SHUTDOWN_EXPLICIT_LOGO : +efc_log_debug (efc,"[%s] %-20s %-20s\n" , + node->display_name, funcname, +efc_sm_event_name (evt)); + node->shutdown_reason =EFC_NODE_SHUTDOWN_EXPLICIT_LOGO ; +efc_node_transition (node, __efc_d_initiate_shutdown,NULL ); +break ; +case EFC_EVT_SHUTDOWN_IMPLICIT_LOGO : +efc_log_debug (efc,"[%s] %-20s %-20s\n" , node->display_name, + funcname,efc_sm_event_name (evt)); + node->shutdown_reason =EFC_NODE_SHUTDOWN_IMPLICIT_LOGO ; +efc_node_transition (node, __efc_d_initiate_shutdown,NULL ); +break ; + +default : +/* call default event handler common to all nodes */ +__efc_node_common (funcname, ctx, evt, arg); +break ; + } +return NULL ; +} + +/** +* State is entered when a node sends a delete initiator/target call to the +* target-server/initiator-client and needs to wait for that work to complete. +*/ +static void * +__efc_d_wait_del_node (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{
drivers/scsi/elx/libefc/efc_device.c line 101
Quoted 10 lines
drivers/scsi/elx/libefc/efc_device.c new file +10
-0+struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +/* Fall through */
fallthrough;
Quoted 21 lines
drivers/scsi/elx/libefc/efc_device.c new file +21
-0+ +case EFC_EVT_NODE_ACTIVE_IO_LIST_EMPTY : +case EFC_EVT_ALL_CHILD_NODES_FREE : +/* These are expected events. */ +break ; + +case EFC_EVT_NODE_DEL_INI_COMPLETE : +case EFC_EVT_NODE_DEL_TGT_COMPLETE : +/* +* node has either been detached or is in the process +* of being detached, +* call common node's initiate cleanup function +*/ +efc_node_initiate_cleanup (node); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +case EFC_EVT_SRRS_ELS_REQ_FAIL :
drivers/scsi/elx/libefc/efc_device.c line 132
Quoted 10 lines
drivers/scsi/elx/libefc/efc_device.c new file +10
-0+/* Can happen as ELS IO IO's complete */ +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +break ; + +/* ignore shutdown events as we're already in shutdown path */ +case EFC_EVT_SHUTDOWN : +/* have default shutdown event take precedence */ + node->shutdown_reason =EFC_NODE_SHUTDOWN_DEFAULT ; +/* fall through */
fallthrough;
Quoted 397 lines
drivers/scsi/elx/libefc/efc_device.c new file +397
-0+case EFC_EVT_SHUTDOWN_EXPLICIT_LOGO : +case EFC_EVT_SHUTDOWN_IMPLICIT_LOGO : +node_printf (node,"%s received\n" ,efc_sm_event_name (evt)); +break ; +case EFC_EVT_DOMAIN_ATTACH_OK : +/* don't care about domain_attach_ok */ +break ; +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +static void * +__efc_d_wait_del_ini_tgt (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +/* Fall through */ + +case EFC_EVT_NODE_ACTIVE_IO_LIST_EMPTY : +case EFC_EVT_ALL_CHILD_NODES_FREE : +/* These are expected events. */ +break ; + +case EFC_EVT_NODE_DEL_INI_COMPLETE : +case EFC_EVT_NODE_DEL_TGT_COMPLETE : +efc_node_transition (node, __efc_d_wait_del_node,NULL ); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +case EFC_EVT_SRRS_ELS_REQ_FAIL : +/* Can happen as ELS IO IO's complete */ +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +break ; + +/* ignore shutdown events as we're already in shutdown path */ +case EFC_EVT_SHUTDOWN : +/* have default shutdown event take precedence */ + node->shutdown_reason =EFC_NODE_SHUTDOWN_DEFAULT ; +/* fall through */ +case EFC_EVT_SHUTDOWN_EXPLICIT_LOGO : +case EFC_EVT_SHUTDOWN_IMPLICIT_LOGO : +node_printf (node,"%s received\n" ,efc_sm_event_name (evt)); +break ; +case EFC_EVT_DOMAIN_ATTACH_OK : +/* don't care about domain_attach_ok */ +break ; +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_d_initiate_shutdown (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; +struct efc *efc = node->efc; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : { +/* assume no wait needed */ +int rc =EFC_SCSI_CALL_COMPLETE ; + + efc->tt.scsi_io_alloc_disable (efc, node); + +/* make necessary delete upcall(s) */ +if (node->init && !node->targ) { +efc_log_info (node->efc, +"[%s] delete (initiator) WWPN %s WWNN %s\n" , + node->display_name, + node->wwpn, node->wwnn); +efc_node_transition (node, + __efc_d_wait_del_node, +NULL ); +if (node->sport->enable_tgt) + rc = efc->tt.scsi_del_node (efc, node, +EFC_SCSI_INITIATOR_DELETED ); + +if (rc ==EFC_SCSI_CALL_COMPLETE ) +efc_node_post_event (node, +EFC_EVT_NODE_DEL_INI_COMPLETE ,NULL ); + + }else if (node->targ && !node->init) { +efc_log_info (node->efc, +"[%s] delete (target) WWPN %s WWNN %s\n" , + node->display_name, + node->wwpn, node->wwnn); +efc_node_transition (node, + __efc_d_wait_del_node, +NULL ); +if (node->sport->enable_ini) + rc = efc->tt.scsi_del_node (efc, node, +EFC_SCSI_TARGET_DELETED ); + +if (rc ==EFC_SCSI_CALL_COMPLETE ) +efc_node_post_event (node, +EFC_EVT_NODE_DEL_TGT_COMPLETE ,NULL ); + + }else if (node->init && node->targ) { +efc_log_info (node->efc, +"[%s] delete (I+T) WWPN %s WWNN %s\n" , + node->display_name, node->wwpn, node->wwnn); +efc_node_transition (node, __efc_d_wait_del_ini_tgt, +NULL ); +if (node->sport->enable_tgt) + rc = efc->tt.scsi_del_node (efc, node, +EFC_SCSI_INITIATOR_DELETED ); + +if (rc ==EFC_SCSI_CALL_COMPLETE ) +efc_node_post_event (node, +EFC_EVT_NODE_DEL_INI_COMPLETE ,NULL ); +/* assume no wait needed */ + rc =EFC_SCSI_CALL_COMPLETE ; +if (node->sport->enable_ini) + rc = efc->tt.scsi_del_node (efc, node, +EFC_SCSI_TARGET_DELETED ); + +if (rc ==EFC_SCSI_CALL_COMPLETE ) +efc_node_post_event (node, +EFC_EVT_NODE_DEL_TGT_COMPLETE ,NULL ); + } + +/* we've initiated the upcalls as needed, now kick off the node +* detach to precipitate the aborting of outstanding exchanges +* associated with said node +* +* Beware: if we've made upcall(s), we've already transitioned +* to a new state by the time we execute this. +* consider doing this before the upcalls? +*/ +if (node->attached) { +/* issue hw node free; don't care if succeeds right +* away or sometime later, will check node->attached +* later in shutdown process +*/ + rc = efc->tt.hw_node_detach (efc, &node->rnode); +if (rc !=EFC_HW_RTN_SUCCESS && + rc !=EFC_HW_RTN_SUCCESS_SYNC ) +node_printf (node, +"Failed freeing HW node, rc=%d\n" , + rc); + } + +/* if neither initiator nor target, proceed to cleanup */ +if (!node->init && !node->targ) { +/* +* node has either been detached or is in +* the process of being detached, +* call common node's initiate cleanup function +*/ +efc_node_initiate_cleanup (node); + } +break ; + } +case EFC_EVT_ALL_CHILD_NODES_FREE : +/* Ignore, this can happen if an ELS is +* aborted while in a delay/retry state +*/ +break ; +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } +return NULL ; +} + +void * +__efc_d_wait_loop (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +case EFC_EVT_DOMAIN_ATTACH_OK : { +/* send PLOGI automatically if initiator */ +efc_node_init_device (node, true); +break ; + } +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +/* Save the OX_ID for sending LS_ACC sometime later */ +void +efc_send_ls_acc_after_attach (struct efc_node *node, +struct fc_frame_header *hdr, +enum efc_node_send_ls_acc ls) +{ +u16 ox_id =be16_to_cpu (hdr->fh_ox_id); + +WARN_ON (node->send_ls_acc !=EFC_NODE_SEND_LS_ACC_NONE ); + + node->ls_acc_oxid = ox_id; + node->send_ls_acc = ls; + node->ls_acc_did =ntoh24 (hdr->fh_d_id); +} + +void +efc_process_prli_payload (struct efc_node *node,void *prli) +{ +struct fc_els_spp *sp = prli +sizeof (struct fc_els_prli ); + + node->init = (sp->spp_flags &FCP_SPPF_INIT_FCN ) !=0 ; + node->targ = (sp->spp_flags &FCP_SPPF_TARG_FCN ) !=0 ; +} + +void * +__efc_d_wait_plogi_acc_cmpl (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +case EFC_EVT_SRRS_ELS_CMPL_FAIL : +WARN_ON (!node->els_cmpl_cnt); + node->els_cmpl_cnt--; + node->shutdown_reason =EFC_NODE_SHUTDOWN_DEFAULT ; +efc_node_transition (node, __efc_d_initiate_shutdown,NULL ); +break ; + +case EFC_EVT_SRRS_ELS_CMPL_OK :/* PLOGI ACC completions */ +WARN_ON (!node->els_cmpl_cnt); + node->els_cmpl_cnt--; +efc_node_transition (node, __efc_d_port_logged_in,NULL ); +break ; + +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_d_wait_logo_rsp (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +case EFC_EVT_SRRS_ELS_REQ_OK : +case EFC_EVT_SRRS_ELS_REQ_RJT : +case EFC_EVT_SRRS_ELS_REQ_FAIL : +/* LOGO response received, sent shutdown */ +if (efc_node_check_els_req (ctx, evt, arg,ELS_LOGO , + __efc_d_common, __func__)) +return NULL ; + +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +node_printf (node, +"LOGO sent (evt=%s), shutdown node\n" , +efc_sm_event_name (evt)); +/* sm: / post explicit logout */ +efc_node_post_event (node,EFC_EVT_SHUTDOWN_EXPLICIT_LOGO , +NULL ); +break ; + +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } +return NULL ; +} + +void +efc_node_init_device (struct efc_node *node,bool send_plogi) +{ + node->send_plogi = send_plogi; +if ((node->efc->nodedb_mask &EFC_NODEDB_PAUSE_NEW_NODES ) && + (node->rnode.fc_id !=FC_FID_DOM_MGR )) { + node->nodedb_state = __efc_d_init; +efc_node_transition (node, __efc_node_paused,NULL ); + }else { +efc_node_transition (node, __efc_d_init,NULL ); + } +} + +/** +* Device node state machine: Initial node state for an initiator or +* a target. +* +* This state is entered when a node is instantiated, either having been +* discovered from a name services query, or having received a PLOGI/FLOGI. +*/ +void * +__efc_d_init (struct efc_sm_ctx *ctx,enum efc_sm_event evt,void *arg) +{ +int rc; +struct efc_node_cb *cbdata = arg; +struct efc_node *node = ctx->app; +struct efc *efc = node->efc; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +if (!node->send_plogi) +break ; +/* only send if we have initiator capability, +* and domain is attached +*/ +if (node->sport->enable_ini && + node->sport->domain->attached) { + efc->tt.els_send (efc, node,ELS_PLOGI , +EFC_FC_FLOGI_TIMEOUT_SEC , +EFC_FC_ELS_DEFAULT_RETRIES ); + +efc_node_transition (node, __efc_d_wait_plogi_rsp,NULL ); + }else { +node_printf (node,"not sending plogi sport.ini=%d," , + node->sport->enable_ini); +node_printf (node,"domain attached=%d\n" , + node->sport->domain->attached); + } +break ; +case EFC_EVT_PLOGI_RCVD : { +/* T, or I+T */ +struct fc_frame_header *hdr = cbdata->header->dma.virt; +u32 d_id =ntoh24 (hdr->fh_d_id); + +efc_node_save_sparms (node, cbdata->payload->dma.virt); +efc_send_ls_acc_after_attach (node, + cbdata->header->dma.virt, +EFC_NODE_SEND_LS_ACC_PLOGI ); + +/* domain already attached */ +if (node->sport->domain->attached) { + rc =efc_node_attach (node); +efc_node_transition (node, + __efc_d_wait_node_attach,NULL );
drivers/scsi/elx/libefc/efc_device.c line 539
Quoted 10 lines
drivers/scsi/elx/libefc/efc_device.c new file +10
-0+if (rc ==EFC_HW_RTN_SUCCESS_SYNC ) { +efc_node_post_event (node, +EFC_EVT_NODE_ATTACH_OK , +NULL ); + } +break ; + } + +/* domain not attached; several possibilities: */ +switch (node->sport->topology) {
This substate machine should go into a new function.
Quoted 1,215 lines
drivers/scsi/elx/libefc/efc_device.c new file +1133
-0+case EFC_SPORT_TOPOLOGY_P2P : +/* we're not attached and sport is p2p, +* need to attach +*/ +efc_domain_attach (node->sport->domain, d_id); +efc_node_transition (node, + __efc_d_wait_domain_attach, +NULL ); +break ; +case EFC_SPORT_TOPOLOGY_FABRIC : +/* we're not attached and sport is fabric, domain +* attach should have already been requested as part +* of the fabric state machine, wait for it +*/ +efc_node_transition (node, __efc_d_wait_domain_attach, +NULL ); +break ; +case EFC_SPORT_TOPOLOGY_UNKNOWN : +/* Two possibilities: +* 1. received a PLOGI before our FLOGI has completed +* (possible since completion comes in on another +* CQ), thus we don't know what we're connected to +* yet; transition to a state to wait for the +* fabric node to tell us; +* 2. PLOGI received before link went down and we +* haven't performed domain attach yet. +* Note: we cannot distinguish between 1. and 2. +* so have to assume PLOGI +* was received after link back up. +*/ +node_printf (node, +"received PLOGI, unknown topology did=0x%x\n" , + d_id); +efc_node_transition (node, + __efc_d_wait_topology_notify, +NULL ); +break ; +default : +node_printf (node, +"received PLOGI, with unexpected topology %d\n" , + node->sport->topology); +break ; + } +break ; + } + +case EFC_EVT_FDISC_RCVD : { +__efc_d_common (__func__, ctx, evt, arg); +break ; + } + +case EFC_EVT_FLOGI_RCVD : { +struct fc_frame_header *hdr = cbdata->header->dma.virt; +u32 d_id =ntoh24 (hdr->fh_d_id); + +/* sm: / save sparams, send FLOGI acc */ +memcpy (node->sport->domain->flogi_service_params, + cbdata->payload->dma.virt, +sizeof (struct fc_els_flogi )); + +/* send FC LS_ACC response, override s_id */ +efc_fabric_set_topology (node,EFC_SPORT_TOPOLOGY_P2P ); + efc->tt.send_flogi_p2p_acc (efc, node, +be16_to_cpu (hdr->fh_ox_id), d_id); +if (efc_p2p_setup (node->sport)) { +node_printf (node, +"p2p setup failed, shutting down node\n" ); +efc_node_post_event (node,EFC_EVT_SHUTDOWN ,NULL ); + }else { +efc_node_transition (node, + __efc_p2p_wait_flogi_acc_cmpl, +NULL ); + } + +break ; + } + +case EFC_EVT_LOGO_RCVD : { +struct fc_frame_header *hdr = cbdata->header->dma.virt; + +if (!node->sport->domain->attached) { +/* most likely a frame left over from before a link +* down; drop and +* shut node down w/ "explicit logout" so pending +* frames are processed +*/ +node_printf (node,"%s domain not attached, dropping\n" , +efc_sm_event_name (evt)); +efc_node_post_event (node, +EFC_EVT_SHUTDOWN_EXPLICIT_LOGO , +NULL ); +break ; + } + efc->tt.els_send_resp (efc, node,ELS_LOGO , +be16_to_cpu (hdr->fh_ox_id)); +efc_node_transition (node, __efc_d_wait_logo_acc_cmpl,NULL ); +break ; + } + +case EFC_EVT_PRLI_RCVD : +case EFC_EVT_PRLO_RCVD : +case EFC_EVT_PDISC_RCVD : +case EFC_EVT_ADISC_RCVD : +case EFC_EVT_RSCN_RCVD : { +struct fc_frame_header *hdr = cbdata->header->dma.virt; + +if (!node->sport->domain->attached) { +/* most likely a frame left over from before a link +* down; drop and shut node down w/ "explicit logout" +* so pending frames are processed +*/ +node_printf (node,"%s domain not attached, dropping\n" , +efc_sm_event_name (evt)); + +efc_node_post_event (node, +EFC_EVT_SHUTDOWN_EXPLICIT_LOGO , +NULL ); +break ; + } +node_printf (node,"%s received, sending reject\n" , +efc_sm_event_name (evt)); + efc->tt.send_ls_rjt (efc, node,be16_to_cpu (hdr->fh_ox_id), +ELS_RJT_UNAB ,ELS_EXPL_PLOGI_REQD ,0 ); + +break ; + } + +case EFC_EVT_FCP_CMD_RCVD : { +/* note: problem, we're now expecting an ELS REQ completion +* from both the LOGO and PLOGI +*/ +if (!node->sport->domain->attached) { +/* most likely a frame left over from before a +* link down; drop and +* shut node down w/ "explicit logout" so pending +* frames are processed +*/ +node_printf (node,"%s domain not attached, dropping\n" , +efc_sm_event_name (evt)); +efc_node_post_event (node, +EFC_EVT_SHUTDOWN_EXPLICIT_LOGO , +NULL ); +break ; + } + +/* Send LOGO */ +node_printf (node,"FCP_CMND received, send LOGO\n" ); +if (efc->tt.els_send (efc, node,ELS_LOGO , +EFC_FC_FLOGI_TIMEOUT_SEC , +EFC_FC_ELS_DEFAULT_RETRIES ) ==NULL ) { +/* +* failed to send LOGO, go ahead and cleanup node +* anyways +*/ +node_printf (node,"Failed to send LOGO\n" ); +efc_node_post_event (node, +EFC_EVT_SHUTDOWN_EXPLICIT_LOGO , +NULL ); + }else { +/* sent LOGO, wait for response */ +efc_node_transition (node, + __efc_d_wait_logo_rsp,NULL ); + } +break ; + } +case EFC_EVT_DOMAIN_ATTACH_OK : +/* don't care about domain_attach_ok */ +break ; + +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_d_wait_plogi_rsp (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +int rc; +struct efc_node_cb *cbdata = arg; +struct efc_node *node = ctx->app; +struct efc *efc = node->efc; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_PLOGI_RCVD : { +/* T, or I+T */ +/* received PLOGI with svc parms, go ahead and attach node +* when PLOGI that was sent ultimately completes, it'll be a +* no-op +* +* If there is an outstanding PLOGI sent, can we set a flag +* to indicate that we don't want to retry it if it times out? +*/ +efc_node_save_sparms (node, cbdata->payload->dma.virt); +efc_send_ls_acc_after_attach (node, + cbdata->header->dma.virt, +EFC_NODE_SEND_LS_ACC_PLOGI ); +/* sm: domain->attached / efc_node_attach */ + rc =efc_node_attach (node); +efc_node_transition (node, __efc_d_wait_node_attach,NULL ); +if (rc ==EFC_HW_RTN_SUCCESS_SYNC ) +efc_node_post_event (node, +EFC_EVT_NODE_ATTACH_OK ,NULL ); + +break ; + } + +case EFC_EVT_PRLI_RCVD : +/* I, or I+T */ +/* sent PLOGI and before completion was seen, received the +* PRLI from the remote node (WCQEs and RCQEs come in on +* different queues and order of processing cannot be assumed) +* Save OXID so PRLI can be sent after the attach and continue +* to wait for PLOGI response +*/ +efc_process_prli_payload (node, cbdata->payload->dma.virt); +efc_send_ls_acc_after_attach (node, + cbdata->header->dma.virt, +EFC_NODE_SEND_LS_ACC_PRLI ); +efc_node_transition (node, __efc_d_wait_plogi_rsp_recvd_prli, +NULL ); +break ; + +case EFC_EVT_LOGO_RCVD :/* why don't we do a shutdown here?? */ +case EFC_EVT_PRLO_RCVD : +case EFC_EVT_PDISC_RCVD : +case EFC_EVT_FDISC_RCVD : +case EFC_EVT_ADISC_RCVD : +case EFC_EVT_RSCN_RCVD : +case EFC_EVT_SCR_RCVD : { +struct fc_frame_header *hdr = cbdata->header->dma.virt; + +node_printf (node,"%s received, sending reject\n" , +efc_sm_event_name (evt)); + + efc->tt.send_ls_rjt (efc, node,be16_to_cpu (hdr->fh_ox_id), +ELS_RJT_UNAB ,ELS_EXPL_PLOGI_REQD ,0 ); + +break ; + } + +case EFC_EVT_SRRS_ELS_REQ_OK :/* PLOGI response received */ +/* Completion from PLOGI sent */ +if (efc_node_check_els_req (ctx, evt, arg,ELS_PLOGI , + __efc_d_common, __func__)) +return NULL ; + +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +/* sm: / save sparams, efc_node_attach */ +efc_node_save_sparms (node, cbdata->els_rsp.virt); + rc =efc_node_attach (node); +efc_node_transition (node, __efc_d_wait_node_attach,NULL ); +if (rc ==EFC_HW_RTN_SUCCESS_SYNC ) +efc_node_post_event (node, +EFC_EVT_NODE_ATTACH_OK ,NULL ); + +break ; + +case EFC_EVT_SRRS_ELS_REQ_FAIL :/* PLOGI response received */ +/* PLOGI failed, shutdown the node */ +if (efc_node_check_els_req (ctx, evt, arg,ELS_PLOGI , + __efc_d_common, __func__)) +return NULL ; + +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +efc_node_post_event (node,EFC_EVT_SHUTDOWN ,NULL ); +break ; + +case EFC_EVT_SRRS_ELS_REQ_RJT : +/* Our PLOGI was rejected, this is ok in some cases */ +if (efc_node_check_els_req (ctx, evt, arg,ELS_PLOGI , + __efc_d_common, __func__)) +return NULL ; + +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +break ; + +case EFC_EVT_FCP_CMD_RCVD : { +/* not logged in yet and outstanding PLOGI so don't send LOGO, +* just drop +*/ +node_printf (node,"FCP_CMND received, drop\n" ); +break ; + } + +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_d_wait_plogi_rsp_recvd_prli (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +int rc; +struct efc_node_cb *cbdata = arg; +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +/* +* Since we've received a PRLI, we have a port login and will +* just need to wait for the PLOGI response to do the node +* attach and then we can send the LS_ACC for the PRLI. If, +* during this time, we receive FCP_CMNDs (which is possible +* since we've already sent a PRLI and our peer may have +* accepted). At this time, we are not waiting on any other +* unsolicited frames to continue with the login process. Thus, +* it will not hurt to hold frames here. +*/ +efc_node_hold_frames (node); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +case EFC_EVT_SRRS_ELS_REQ_OK :/* PLOGI response received */ +/* Completion from PLOGI sent */ +if (efc_node_check_els_req (ctx, evt, arg,ELS_PLOGI , + __efc_d_common, __func__)) +return NULL ; + +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +/* sm: / save sparams, efc_node_attach */ +efc_node_save_sparms (node, cbdata->els_rsp.virt); + rc =efc_node_attach (node); +efc_node_transition (node, __efc_d_wait_node_attach,NULL ); +if (rc ==EFC_HW_RTN_SUCCESS_SYNC ) +efc_node_post_event (node,EFC_EVT_NODE_ATTACH_OK , +NULL ); + +break ; + +case EFC_EVT_SRRS_ELS_REQ_FAIL :/* PLOGI response received */ +case EFC_EVT_SRRS_ELS_REQ_RJT : +/* PLOGI failed, shutdown the node */ +if (efc_node_check_els_req (ctx, evt, arg,ELS_PLOGI , + __efc_d_common, __func__)) +return NULL ; + +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +efc_node_post_event (node,EFC_EVT_SHUTDOWN ,NULL ); +break ; + +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_d_wait_domain_attach (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +int rc; +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +case EFC_EVT_DOMAIN_ATTACH_OK : +WARN_ON (!node->sport->domain->attached); +/* sm: / efc_node_attach */ + rc =efc_node_attach (node); +efc_node_transition (node, __efc_d_wait_node_attach,NULL ); +if (rc ==EFC_HW_RTN_SUCCESS_SYNC ) +efc_node_post_event (node,EFC_EVT_NODE_ATTACH_OK , +NULL ); + +break ; + +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } +return NULL ; +} + +void * +__efc_d_wait_topology_notify (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +int rc; +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +case EFC_EVT_SPORT_TOPOLOGY_NOTIFY : { +enum efc_sport_topology topology = + (enum efc_sport_topology )arg; + +WARN_ON (node->sport->domain->attached); + +WARN_ON (node->send_ls_acc !=EFC_NODE_SEND_LS_ACC_PLOGI ); + +node_printf (node,"topology notification, topology=%d\n" , + topology); + +/* At the time the PLOGI was received, the topology was unknown, +* so we didn't know which node would perform the domain attach: +* 1. The node from which the PLOGI was sent (p2p) or +* 2. The node to which the FLOGI was sent (fabric). +*/ +if (topology ==EFC_SPORT_TOPOLOGY_P2P ) { +/* if this is p2p, need to attach to the domain using +* the d_id from the PLOGI received +*/ +efc_domain_attach (node->sport->domain, + node->ls_acc_did); + } +/* else, if this is fabric, the domain attach +* should be performed by the fabric node (node sending FLOGI); +* just wait for attach to complete +*/ + +efc_node_transition (node, __efc_d_wait_domain_attach,NULL ); +break ; + } +case EFC_EVT_DOMAIN_ATTACH_OK : +WARN_ON (!node->sport->domain->attached); +node_printf (node,"domain attach ok\n" ); +/* sm: / efc_node_attach */ + rc =efc_node_attach (node); +efc_node_transition (node, __efc_d_wait_node_attach,NULL ); +if (rc ==EFC_HW_RTN_SUCCESS_SYNC ) +efc_node_post_event (node, +EFC_EVT_NODE_ATTACH_OK ,NULL ); + +break ; + +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } +return NULL ; +} + +void * +__efc_d_wait_node_attach (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; +struct efc *efc = node->efc; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +case EFC_EVT_NODE_ATTACH_OK : + node->attached = true; +switch (node->send_ls_acc) { +case EFC_NODE_SEND_LS_ACC_PLOGI : { +/* sm: send_plogi_acc is set / send PLOGI acc */ +/* Normal case for T, or I+T */ + efc->tt.els_send_resp (efc, node,ELS_PLOGI , + node->ls_acc_oxid); +efc_node_transition (node, + __efc_d_wait_plogi_acc_cmpl, +NULL ); + node->send_ls_acc =EFC_NODE_SEND_LS_ACC_NONE ; + node->ls_acc_io =NULL ; +break ; + } +case EFC_NODE_SEND_LS_ACC_PRLI : { +efc_d_send_prli_rsp (node, + node->ls_acc_oxid); + node->send_ls_acc =EFC_NODE_SEND_LS_ACC_NONE ; + node->ls_acc_io =NULL ; +break ; + } +case EFC_NODE_SEND_LS_ACC_NONE : +default : +/* Normal case for I */ +/* sm: send_plogi_acc is not set / send PLOGI acc */ +efc_node_transition (node, + __efc_d_port_logged_in,NULL ); +break ; + } +break ; + +case EFC_EVT_NODE_ATTACH_FAIL : +/* node attach failed, shutdown the node */ + node->attached = false; +node_printf (node,"node attach failed\n" ); + node->shutdown_reason =EFC_NODE_SHUTDOWN_DEFAULT ; +efc_node_transition (node, __efc_d_initiate_shutdown,NULL ); +break ; + +/* Handle shutdown events */ +case EFC_EVT_SHUTDOWN : +node_printf (node,"%s received\n" ,efc_sm_event_name (evt)); + node->shutdown_reason =EFC_NODE_SHUTDOWN_DEFAULT ; +efc_node_transition (node, __efc_d_wait_attach_evt_shutdown, +NULL ); +break ; +case EFC_EVT_SHUTDOWN_EXPLICIT_LOGO : +node_printf (node,"%s received\n" ,efc_sm_event_name (evt)); + node->shutdown_reason =EFC_NODE_SHUTDOWN_EXPLICIT_LOGO ; +efc_node_transition (node, __efc_d_wait_attach_evt_shutdown, +NULL ); +break ; +case EFC_EVT_SHUTDOWN_IMPLICIT_LOGO : +node_printf (node,"%s received\n" ,efc_sm_event_name (evt)); + node->shutdown_reason =EFC_NODE_SHUTDOWN_IMPLICIT_LOGO ; +efc_node_transition (node, + __efc_d_wait_attach_evt_shutdown,NULL ); +break ; +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_d_wait_attach_evt_shutdown (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +/* wait for any of these attach events and then shutdown */ +case EFC_EVT_NODE_ATTACH_OK : + node->attached = true; +node_printf (node,"Attach evt=%s, proceed to shutdown\n" , +efc_sm_event_name (evt)); +efc_node_transition (node, __efc_d_initiate_shutdown,NULL ); +break ; + +case EFC_EVT_NODE_ATTACH_FAIL : +/* node attach failed, shutdown the node */ + node->attached = false; +node_printf (node,"Attach evt=%s, proceed to shutdown\n" , +efc_sm_event_name (evt)); +efc_node_transition (node, __efc_d_initiate_shutdown,NULL ); +break ; + +/* ignore shutdown events as we're already in shutdown path */ +case EFC_EVT_SHUTDOWN : +/* have default shutdown event take precedence */ + node->shutdown_reason =EFC_NODE_SHUTDOWN_DEFAULT ; +/* fall through */ +case EFC_EVT_SHUTDOWN_EXPLICIT_LOGO : +case EFC_EVT_SHUTDOWN_IMPLICIT_LOGO : +node_printf (node,"%s received\n" ,efc_sm_event_name (evt)); +break ; + +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_d_port_logged_in (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node_cb *cbdata = arg; +struct efc_node *node = ctx->app; +struct efc *efc = node->efc; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +/* Normal case for I or I+T */ +if (node->sport->enable_ini && + !(node->rnode.fc_id !=FC_FID_DOM_MGR )) { +/* sm: if enable_ini / send PRLI */ + efc->tt.els_send (efc, node,ELS_PRLI , +EFC_FC_ELS_SEND_DEFAULT_TIMEOUT , +EFC_FC_ELS_DEFAULT_RETRIES ); +/* can now expect ELS_REQ_OK/FAIL/RJT */ + } +break ; + +case EFC_EVT_FCP_CMD_RCVD : { +break ; + } + +case EFC_EVT_PRLI_RCVD : { +/* Normal case for T or I+T */ +struct fc_frame_header *hdr = cbdata->header->dma.virt; +struct fc_els_spp *sp = cbdata->payload->dma.virt + +sizeof (struct fc_els_prli ); + +if (sp->spp_type !=FC_TYPE_FCP ) { +/*Only FCP is supported*/ + efc->tt.send_ls_rjt (efc, node, +be16_to_cpu (hdr->fh_ox_id), +ELS_RJT_UNAB ,ELS_EXPL_UNSUPR ,0 ); +break ; + } + +efc_process_prli_payload (node, cbdata->payload->dma.virt); +efc_d_send_prli_rsp (node,be16_to_cpu (hdr->fh_ox_id)); +break ; + } + +case EFC_EVT_SRRS_ELS_REQ_OK : {/* PRLI response */ +/* Normal case for I or I+T */ +if (efc_node_check_els_req (ctx, evt, arg,ELS_PRLI , + __efc_d_common, __func__)) +return NULL ; + +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +/* sm: / process PRLI payload */ +efc_process_prli_payload (node, cbdata->els_rsp.virt); +efc_node_transition (node, __efc_d_device_ready,NULL ); +break ; + } + +case EFC_EVT_SRRS_ELS_REQ_FAIL : {/* PRLI response failed */ +/* I, I+T, assume some link failure, shutdown node */ +if (efc_node_check_els_req (ctx, evt, arg,ELS_PRLI , + __efc_d_common, __func__)) +return NULL ; + +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +efc_node_post_event (node,EFC_EVT_SHUTDOWN ,NULL ); +break ; + } + +case EFC_EVT_SRRS_ELS_REQ_RJT : { +/* PRLI rejected by remote +* Normal for I, I+T (connected to an I) +* Node doesn't want to be a target, stay here and wait for a +* PRLI from the remote node +* if it really wants to connect to us as target +*/ +if (efc_node_check_els_req (ctx, evt, arg,ELS_PRLI , + __efc_d_common, __func__)) +return NULL ; + +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +break ; + } + +case EFC_EVT_SRRS_ELS_CMPL_OK : { +/* Normal T, I+T, target-server rejected the process login */ +/* This would be received only in the case where we sent +* LS_RJT for the PRLI, so +* do nothing. (note: as T only we could shutdown the node) +*/ +WARN_ON (!node->els_cmpl_cnt); + node->els_cmpl_cnt--; +break ; + } + +case EFC_EVT_PLOGI_RCVD : { +/*sm: / save sparams, set send_plogi_acc, +*post implicit logout +* Save plogi parameters +*/ +efc_node_save_sparms (node, cbdata->payload->dma.virt); +efc_send_ls_acc_after_attach (node, + cbdata->header->dma.virt, +EFC_NODE_SEND_LS_ACC_PLOGI ); + +/* Restart node attach with new service parameters, +* and send ACC +*/ +efc_node_post_event (node,EFC_EVT_SHUTDOWN_IMPLICIT_LOGO , +NULL ); +break ; + } + +case EFC_EVT_LOGO_RCVD : { +/* I, T, I+T */ +struct fc_frame_header *hdr = cbdata->header->dma.virt; + +node_printf (node,"%s received attached=%d\n" , +efc_sm_event_name (evt), + node->attached); +/* sm: / send LOGO acc */ + efc->tt.els_send_resp (efc, node,ELS_LOGO , +be16_to_cpu (hdr->fh_ox_id)); +efc_node_transition (node, __efc_d_wait_logo_acc_cmpl,NULL ); +break ; + } + +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_d_wait_logo_acc_cmpl (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +case EFC_EVT_SRRS_ELS_CMPL_OK : +case EFC_EVT_SRRS_ELS_CMPL_FAIL : +/* sm: / post explicit logout */ +WARN_ON (!node->els_cmpl_cnt); + node->els_cmpl_cnt--; +efc_node_post_event (node, +EFC_EVT_SHUTDOWN_EXPLICIT_LOGO ,NULL ); +break ; +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_d_device_ready (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node_cb *cbdata = arg; +struct efc_node *node = ctx->app; +struct efc *efc = node->efc; + +efc_node_evt_set (ctx, evt, __func__); + +if (evt !=EFC_EVT_FCP_CMD_RCVD ) +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : + node->fcp_enabled = true; +if (node->init) { +efc_log_info (efc, +"[%s] found (initiator) WWPN %s WWNN %s\n" , + node->display_name, + node->wwpn, node->wwnn); +if (node->sport->enable_tgt) + efc->tt.scsi_new_node (efc, node); + } +if (node->targ) { +efc_log_info (efc, +"[%s] found (target) WWPN %s WWNN %s\n" , + node->display_name, + node->wwpn, node->wwnn); +if (node->sport->enable_ini) + efc->tt.scsi_new_node (efc, node); + } +break ; + +case EFC_EVT_EXIT : + node->fcp_enabled = false; +break ; + +case EFC_EVT_PLOGI_RCVD : { +/* sm: / save sparams, set send_plogi_acc, post implicit +* logout +* Save plogi parameters +*/ +efc_node_save_sparms (node, cbdata->payload->dma.virt); +efc_send_ls_acc_after_attach (node, + cbdata->header->dma.virt, +EFC_NODE_SEND_LS_ACC_PLOGI ); + +/* +* Restart node attach with new service parameters, +* and send ACC +*/ +efc_node_post_event (node, +EFC_EVT_SHUTDOWN_IMPLICIT_LOGO ,NULL ); +break ; + } + +case EFC_EVT_PRLI_RCVD : { +/* T, I+T: remote initiator is slow to get started */ +struct fc_frame_header *hdr = cbdata->header->dma.virt; +struct fc_els_spp *sp = cbdata->payload->dma.virt + +sizeof (struct fc_els_prli ); + +if (sp->spp_type !=FC_TYPE_FCP ) { +/*Only FCP is supported*/ + efc->tt.send_ls_rjt (efc, node, +be16_to_cpu (hdr->fh_ox_id), +ELS_RJT_UNAB ,ELS_EXPL_UNSUPR ,0 ); +break ; + } + +efc_process_prli_payload (node, cbdata->payload->dma.virt); + + efc->tt.els_send_resp (efc, node,ELS_PRLI , +be16_to_cpu (hdr->fh_ox_id)); +break ; + } + +case EFC_EVT_PRLO_RCVD : { +struct fc_frame_header *hdr = cbdata->header->dma.virt; +/* sm: / send PRLO acc */ + efc->tt.els_send_resp (efc, node,ELS_PRLO , +be16_to_cpu (hdr->fh_ox_id)); +/* need implicit logout? */ +break ; + } + +case EFC_EVT_LOGO_RCVD : { +struct fc_frame_header *hdr = cbdata->header->dma.virt; + +node_printf (node,"%s received attached=%d\n" , +efc_sm_event_name (evt), node->attached); +/* sm: / send LOGO acc */ + efc->tt.els_send_resp (efc, node,ELS_LOGO , +be16_to_cpu (hdr->fh_ox_id)); +efc_node_transition (node, __efc_d_wait_logo_acc_cmpl,NULL ); +break ; + } + +case EFC_EVT_ADISC_RCVD : { +struct fc_frame_header *hdr = cbdata->header->dma.virt; +/* sm: / send ADISC acc */ + efc->tt.els_send_resp (efc, node,ELS_ADISC , +be16_to_cpu (hdr->fh_ox_id)); +break ; + } + +case EFC_EVT_ABTS_RCVD : +/* sm: / process ABTS */ +efc_log_err (efc,"Unexpected event:%s\n" , +efc_sm_event_name (evt)); +break ; + +case EFC_EVT_NODE_ACTIVE_IO_LIST_EMPTY : +break ; + +case EFC_EVT_NODE_REFOUND : +break ; + +case EFC_EVT_NODE_MISSING : +if (node->sport->enable_rscn) +efc_node_transition (node, __efc_d_device_gone,NULL ); + +break ; + +case EFC_EVT_SRRS_ELS_CMPL_OK : +/* T, or I+T, PRLI accept completed ok */ +WARN_ON (!node->els_cmpl_cnt); + node->els_cmpl_cnt--; +break ; + +case EFC_EVT_SRRS_ELS_CMPL_FAIL : +/* T, or I+T, PRLI accept failed to complete */ +WARN_ON (!node->els_cmpl_cnt); + node->els_cmpl_cnt--; +node_printf (node,"Failed to send PRLI LS_ACC\n" ); +break ; + +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_d_device_gone (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +int rc =EFC_SCSI_CALL_COMPLETE ; +int rc_2 =EFC_SCSI_CALL_COMPLETE ; +struct efc_node_cb *cbdata = arg; +struct efc_node *node = ctx->app; +struct efc *efc = node->efc; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : { +static char const *labels[] = {"none" ,"initiator" ,"target" , +"initiator+target" }; + +efc_log_info (efc,"[%s] missing (%s) WWPN %s WWNN %s\n" , + node->display_name, + labels[(node->targ <<1 ) | (node->init)], + node->wwpn, node->wwnn); + +switch (efc_node_get_enable (node)) { +case EFC_NODE_ENABLE_T_TO_T : +case EFC_NODE_ENABLE_I_TO_T : +case EFC_NODE_ENABLE_IT_TO_T : + rc = efc->tt.scsi_del_node (efc, node, +EFC_SCSI_TARGET_MISSING ); +break ; + +case EFC_NODE_ENABLE_T_TO_I : +case EFC_NODE_ENABLE_I_TO_I : +case EFC_NODE_ENABLE_IT_TO_I : + rc = efc->tt.scsi_del_node (efc, node, +EFC_SCSI_INITIATOR_MISSING ); +break ; + +case EFC_NODE_ENABLE_T_TO_IT : + rc = efc->tt.scsi_del_node (efc, node, +EFC_SCSI_INITIATOR_MISSING ); +break ; + +case EFC_NODE_ENABLE_I_TO_IT : + rc = efc->tt.scsi_del_node (efc, node, +EFC_SCSI_TARGET_MISSING ); +break ; + +case EFC_NODE_ENABLE_IT_TO_IT : + rc = efc->tt.scsi_del_node (efc, node, +EFC_SCSI_INITIATOR_MISSING ); + rc_2 = efc->tt.scsi_del_node (efc, node, +EFC_SCSI_TARGET_MISSING ); +break ; + +default : + rc =EFC_SCSI_CALL_COMPLETE ; +break ; + } + +if (rc ==EFC_SCSI_CALL_COMPLETE && + rc_2 ==EFC_SCSI_CALL_COMPLETE ) +efc_node_post_event (node,EFC_EVT_SHUTDOWN ,NULL ); + +break ; + } +case EFC_EVT_NODE_REFOUND : +/* two approaches, reauthenticate with PLOGI/PRLI, or ADISC */ + +/* reauthenticate with PLOGI/PRLI */ +/* efc_node_transition(node, __efc_d_discovered, NULL); */ + +/* reauthenticate with ADISC */ +/* sm: / send ADISC */ + efc->tt.els_send (efc, node,ELS_ADISC , +EFC_FC_FLOGI_TIMEOUT_SEC , +EFC_FC_ELS_DEFAULT_RETRIES ); +efc_node_transition (node, __efc_d_wait_adisc_rsp,NULL ); +break ; + +case EFC_EVT_PLOGI_RCVD : { +/* sm: / save sparams, set send_plogi_acc, post implicit +* logout +* Save plogi parameters +*/ +efc_node_save_sparms (node, cbdata->payload->dma.virt); +efc_send_ls_acc_after_attach (node, + cbdata->header->dma.virt, +EFC_NODE_SEND_LS_ACC_PLOGI ); + +/* +* Restart node attach with new service parameters, and send +* ACC +*/ +efc_node_post_event (node,EFC_EVT_SHUTDOWN_IMPLICIT_LOGO , +NULL ); +break ; + } + +case EFC_EVT_FCP_CMD_RCVD : { +/* most likely a stale frame (received prior to link down), +* if attempt to send LOGO, will probably timeout and eat +* up 20s; thus, drop FCP_CMND +*/ +node_printf (node,"FCP_CMND received, drop\n" ); +break ; + } +case EFC_EVT_LOGO_RCVD : { +/* I, T, I+T */ +struct fc_frame_header *hdr = cbdata->header->dma.virt; + +node_printf (node,"%s received attached=%d\n" , +efc_sm_event_name (evt), node->attached); +/* sm: / send LOGO acc */ + efc->tt.els_send_resp (efc, node,ELS_LOGO , +be16_to_cpu (hdr->fh_ox_id)); +efc_node_transition (node, __efc_d_wait_logo_acc_cmpl,NULL ); +break ; + } +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_d_wait_adisc_rsp (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node_cb *cbdata = arg; +struct efc_node *node = ctx->app; +struct efc *efc = node->efc; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_SRRS_ELS_REQ_OK : +if (efc_node_check_els_req (ctx, evt, arg,ELS_ADISC , + __efc_d_common, __func__)) +return NULL ; + +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +efc_node_transition (node, __efc_d_device_ready,NULL ); +break ; + +case EFC_EVT_SRRS_ELS_REQ_RJT : +/* received an LS_RJT, in this case, send shutdown +* (explicit logo) event which will unregister the node, +* and start over with PLOGI +*/ +if (efc_node_check_els_req (ctx, evt, arg,ELS_ADISC , + __efc_d_common, __func__)) +return NULL ; + +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +/* sm: / post explicit logout */ +efc_node_post_event (node, +EFC_EVT_SHUTDOWN_EXPLICIT_LOGO , +NULL ); +break ; + +case EFC_EVT_LOGO_RCVD : { +/* In this case, we have the equivalent of an LS_RJT for +* the ADISC, so we need to abort the ADISC, and re-login +* with PLOGI +*/ +/* sm: / request abort, send LOGO acc */ +struct fc_frame_header *hdr = cbdata->header->dma.virt; + +node_printf (node,"%s received attached=%d\n" , +efc_sm_event_name (evt), node->attached); + + efc->tt.els_send_resp (efc, node,ELS_LOGO , +be16_to_cpu (hdr->fh_ox_id)); +efc_node_transition (node, __efc_d_wait_logo_acc_cmpl,NULL ); +break ; + } +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +}drivers/scsi/elx/libefc/efc_device.h new file +72
-0@@ -0,0 +1,72 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2019 Broadcom. All Rights Reserved. The term +* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +*/ + +/* +* Node state machine functions for remote device node sm +*/ + +#ifndef __EFCT_DEVICE_H__ +#define __EFCT_DEVICE_H__ +extern void +efc_node_init_device (struct efc_node *node,bool send_plogi); +extern void +efc_process_prli_payload (struct efc_node *node, +void *prli); +extern void +efc_d_send_prli_rsp (struct efc_node *node,uint16_t ox_id); +extern void +efc_send_ls_acc_after_attach (struct efc_node *node, +struct fc_frame_header *hdr, +enum efc_node_send_ls_acc ls); +extern void * +__efc_d_wait_loop (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +extern void * +__efc_d_wait_plogi_acc_cmpl (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +extern void * +__efc_d_init (struct efc_sm_ctx *ctx,enum efc_sm_event evt,void *arg); +extern void * +__efc_d_wait_plogi_rsp (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +extern void * +__efc_d_wait_plogi_rsp_recvd_prli (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +extern void * +__efc_d_wait_domain_attach (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +extern void * +__efc_d_wait_topology_notify (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +extern void * +__efc_d_wait_node_attach (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +extern void * +__efc_d_wait_attach_evt_shutdown (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +extern void * +__efc_d_initiate_shutdown (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +extern void * +__efc_d_port_logged_in (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +extern void * +__efc_d_wait_logo_acc_cmpl (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +extern void * +__efc_d_device_ready (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +extern void * +__efc_d_device_gone (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +extern void * +__efc_d_wait_adisc_rsp (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +extern void * +__efc_d_wait_logo_rsp (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); + +#endif /* __EFCT_DEVICE_H__ */ Signature · 1 line
2.16.4
I run out of steam and thus stop here...
Thanks,
Daniel
Re: [PATCH v3 14/31] elx: libefc: FC node ELS and state handling
On 4/15/2020 11:56 AM, Daniel Wagner wrote:
...
Quoted 7 lines
drivers/scsi/elx/libefc/efc_device.c line 101
Quoted 4 lines
drivers/scsi/elx/libefc/efc_device.c new file +4
-0+switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +/* Fall through */ fallthrough;
Actually the patches that went in for -Wimplicit-fallthrough wants /* fall through */
Other comments are fine and we'll address them.
BTW: Same goes for comments on patches 3, 7, 8, 9, 10, and 11.
Quoted 6 lines
I run out of steam and thus stop here...
Thanks,
Daniel
I understand. Regardless, thank you for the time and effort on this.
-- james
Re: [PATCH v3 14/31] elx: libefc: FC node ELS and state handling
Hi James,
Quoted 10 lines · James Smart
On 4/15/2020 11:56 AM, Daniel Wagner wrote:
...Quoted 7 lines
drivers/scsi/elx/libefc/efc_device.c line 101
Quoted 4 lines
drivers/scsi/elx/libefc/efc_device.c new file +4
-0+switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +/* Fall through */ fallthrough;
Quoted 2 lines
Actually the patches that went in for -Wimplicit-fallthrough wants /* fall through */
Ah okay, I though the fall through rules are active. Anyway, I am sure someone will run a script to report when to change.
Thanks,
Daniel
Re: [PATCH v3 14/31] elx: libefc: FC node ELS and state handling
Quoted 13 lines · Daniel Wagner
Hi James,
Quoted 10 lines · James Smart
On 4/15/2020 11:56 AM, Daniel Wagner wrote:
...Quoted 7 lines
drivers/scsi/elx/libefc/efc_device.c line 101
Quoted 4 lines
drivers/scsi/elx/libefc/efc_device.c new file +4
-0+switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +/* Fall through */ fallthrough;
Quoted 8 lines
Quoted 2 lines
Actually the patches that went in for -Wimplicit-fallthrough wants /* fall through */
Ah okay, I though the fall through rules are active. Anyway, I am sure someone will run a script to report when to change.
Thanks,
Daniel
Indeed, fallthrough; is preferred now, see commit f36d3eb89a43 ("checkpatch:
prefer fallthrough; over fallthrough comments") and the thread that is linked in that commit.
Cheers,
Nathan
Re: [PATCH v3 14/31] elx: libefc: FC node ELS and state handling
In reply to James SmartQuoted 162 lines · James Smart
This patch continues the libefc library population.
This patch adds library interface definitions for:
- FC node PRLI handling and state managementSigned-off-by Ram Vegesna <[email protected]>Signed-off-by James Smart <[email protected]>---
v3:
Replaceefc_assertwithWARN_ON
Bug Fix: SendLS_RJTfor non FCP PRLIs--- drivers/scsi/elx/libefc/efc_device.c | 1672 ++++++++++++++++++++++++++++++++++ drivers/scsi/elx/libefc/efc_device.h | 72 ++ 2 files changed, 1744 insertions(+)create mode 100644
drivers/scsi/elx/libefc/efc_device.ccreate mode 100644drivers/scsi/elx/libefc/efc_device.hdrivers/scsi/elx/libefc/efc_device.c new file +137
-0@@ -0,0 +1,1672 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2019 Broadcom. All Rights Reserved. The term +* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +*/ + +/* +* device_sm Node State Machine: Remote Device States +*/ + +#include "efc.h" +#include "efc_device.h" +#include "efc_fabric.h" + +void +efc_d_send_prli_rsp (struct efc_node *node,uint16_t ox_id) +{ +struct efc *efc = node->efc; +/* If the back-end doesn't want to talk to this initiator, +* we send an LS_RJT +*/ +if (node->sport->enable_tgt && + (efc->tt.scsi_validate_node (efc, node) ==0 )) { +node_printf (node,"PRLI rejected by target-server\n" ); + + efc->tt.send_ls_rjt (efc, node, ox_id, +ELS_RJT_UNAB ,ELS_EXPL_NONE ,0 ); + node->shutdown_reason =EFC_NODE_SHUTDOWN_DEFAULT ; +efc_node_transition (node, __efc_d_initiate_shutdown,NULL ); + }else { +/* +* sm: / process PRLI payload, send PRLI acc +*/ + efc->tt.els_send_resp (efc, node,ELS_PRLI , ox_id); + +/* Immediately go to ready state to avoid window where we're +* waiting for the PRLI LS_ACC to complete while holding +* FCP_CMNDs +*/ +efc_node_transition (node, __efc_d_device_ready,NULL ); + } +} + +static void * +__efc_d_common (const char *funcname,struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node =NULL ; +struct efc *efc =NULL ; + + node = ctx->app; + efc = node->efc; + +switch (evt) { +/* Handle shutdown events */ +case EFC_EVT_SHUTDOWN : +efc_log_debug (efc,"[%s] %-20s %-20s\n" , node->display_name, + funcname,efc_sm_event_name (evt)); + node->shutdown_reason =EFC_NODE_SHUTDOWN_DEFAULT ; +efc_node_transition (node, __efc_d_initiate_shutdown,NULL ); +break ; +case EFC_EVT_SHUTDOWN_EXPLICIT_LOGO : +efc_log_debug (efc,"[%s] %-20s %-20s\n" , + node->display_name, funcname, +efc_sm_event_name (evt)); + node->shutdown_reason =EFC_NODE_SHUTDOWN_EXPLICIT_LOGO ; +efc_node_transition (node, __efc_d_initiate_shutdown,NULL ); +break ; +case EFC_EVT_SHUTDOWN_IMPLICIT_LOGO : +efc_log_debug (efc,"[%s] %-20s %-20s\n" , node->display_name, + funcname,efc_sm_event_name (evt)); + node->shutdown_reason =EFC_NODE_SHUTDOWN_IMPLICIT_LOGO ; +efc_node_transition (node, __efc_d_initiate_shutdown,NULL ); +break ; + +default : +/* call default event handler common to all nodes */ +__efc_node_common (funcname, ctx, evt, arg); +break ; + } +return NULL ; +} + +/** +* State is entered when a node sends a delete initiator/target call to the +* target-server/initiator-client and needs to wait for that work to complete. +*/ +static void * +__efc_d_wait_del_node (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +/* Fall through */ + +case EFC_EVT_NODE_ACTIVE_IO_LIST_EMPTY : +case EFC_EVT_ALL_CHILD_NODES_FREE : +/* These are expected events. */ +break ; + +case EFC_EVT_NODE_DEL_INI_COMPLETE : +case EFC_EVT_NODE_DEL_TGT_COMPLETE : +/* +* node has either been detached or is in the process +* of being detached, +* call common node's initiate cleanup function +*/ +efc_node_initiate_cleanup (node); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +case EFC_EVT_SRRS_ELS_REQ_FAIL : +/* Can happen as ELS IO IO's complete */ +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +break ; + +/* ignore shutdown events as we're already in shutdown path */ +case EFC_EVT_SHUTDOWN : +/* have default shutdown event take precedence */ + node->shutdown_reason =EFC_NODE_SHUTDOWN_DEFAULT ; +/* fall through */ +case EFC_EVT_SHUTDOWN_EXPLICIT_LOGO : +case EFC_EVT_SHUTDOWN_IMPLICIT_LOGO : +node_printf (node,"%s received\n" ,efc_sm_event_name (evt)); +break ; +case EFC_EVT_DOMAIN_ATTACH_OK :
drivers/scsi/elx/libefc/efc_device.c line 147
Quoted 10 lines
drivers/scsi/elx/libefc/efc_device.c new file +10
-0+/* don't care about domain_attach_ok */ +break ; +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} +
If you are going to return NULL anyway, why have a separate return statement in the default case?
Quoted 442 lines
drivers/scsi/elx/libefc/efc_device.c new file +442
-0+static void * +__efc_d_wait_del_ini_tgt (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +/* Fall through */ + +case EFC_EVT_NODE_ACTIVE_IO_LIST_EMPTY : +case EFC_EVT_ALL_CHILD_NODES_FREE : +/* These are expected events. */ +break ; + +case EFC_EVT_NODE_DEL_INI_COMPLETE : +case EFC_EVT_NODE_DEL_TGT_COMPLETE : +efc_node_transition (node, __efc_d_wait_del_node,NULL ); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +case EFC_EVT_SRRS_ELS_REQ_FAIL : +/* Can happen as ELS IO IO's complete */ +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +break ; + +/* ignore shutdown events as we're already in shutdown path */ +case EFC_EVT_SHUTDOWN : +/* have default shutdown event take precedence */ + node->shutdown_reason =EFC_NODE_SHUTDOWN_DEFAULT ; +/* fall through */ +case EFC_EVT_SHUTDOWN_EXPLICIT_LOGO : +case EFC_EVT_SHUTDOWN_IMPLICIT_LOGO : +node_printf (node,"%s received\n" ,efc_sm_event_name (evt)); +break ; +case EFC_EVT_DOMAIN_ATTACH_OK : +/* don't care about domain_attach_ok */ +break ; +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_d_initiate_shutdown (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; +struct efc *efc = node->efc; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : { +/* assume no wait needed */ +int rc =EFC_SCSI_CALL_COMPLETE ; + + efc->tt.scsi_io_alloc_disable (efc, node); + +/* make necessary delete upcall(s) */ +if (node->init && !node->targ) { +efc_log_info (node->efc, +"[%s] delete (initiator) WWPN %s WWNN %s\n" , + node->display_name, + node->wwpn, node->wwnn); +efc_node_transition (node, + __efc_d_wait_del_node, +NULL ); +if (node->sport->enable_tgt) + rc = efc->tt.scsi_del_node (efc, node, +EFC_SCSI_INITIATOR_DELETED ); + +if (rc ==EFC_SCSI_CALL_COMPLETE ) +efc_node_post_event (node, +EFC_EVT_NODE_DEL_INI_COMPLETE ,NULL ); + + }else if (node->targ && !node->init) { +efc_log_info (node->efc, +"[%s] delete (target) WWPN %s WWNN %s\n" , + node->display_name, + node->wwpn, node->wwnn); +efc_node_transition (node, + __efc_d_wait_del_node, +NULL ); +if (node->sport->enable_ini) + rc = efc->tt.scsi_del_node (efc, node, +EFC_SCSI_TARGET_DELETED ); + +if (rc ==EFC_SCSI_CALL_COMPLETE ) +efc_node_post_event (node, +EFC_EVT_NODE_DEL_TGT_COMPLETE ,NULL ); + + }else if (node->init && node->targ) { +efc_log_info (node->efc, +"[%s] delete (I+T) WWPN %s WWNN %s\n" , + node->display_name, node->wwpn, node->wwnn); +efc_node_transition (node, __efc_d_wait_del_ini_tgt, +NULL ); +if (node->sport->enable_tgt) + rc = efc->tt.scsi_del_node (efc, node, +EFC_SCSI_INITIATOR_DELETED ); + +if (rc ==EFC_SCSI_CALL_COMPLETE ) +efc_node_post_event (node, +EFC_EVT_NODE_DEL_INI_COMPLETE ,NULL ); +/* assume no wait needed */ + rc =EFC_SCSI_CALL_COMPLETE ; +if (node->sport->enable_ini) + rc = efc->tt.scsi_del_node (efc, node, +EFC_SCSI_TARGET_DELETED ); + +if (rc ==EFC_SCSI_CALL_COMPLETE ) +efc_node_post_event (node, +EFC_EVT_NODE_DEL_TGT_COMPLETE ,NULL ); + } + +/* we've initiated the upcalls as needed, now kick off the node +* detach to precipitate the aborting of outstanding exchanges +* associated with said node +* +* Beware: if we've made upcall(s), we've already transitioned +* to a new state by the time we execute this. +* consider doing this before the upcalls? +*/ +if (node->attached) { +/* issue hw node free; don't care if succeeds right +* away or sometime later, will check node->attached +* later in shutdown process +*/ + rc = efc->tt.hw_node_detach (efc, &node->rnode); +if (rc !=EFC_HW_RTN_SUCCESS && + rc !=EFC_HW_RTN_SUCCESS_SYNC ) +node_printf (node, +"Failed freeing HW node, rc=%d\n" , + rc); + } + +/* if neither initiator nor target, proceed to cleanup */ +if (!node->init && !node->targ) { +/* +* node has either been detached or is in +* the process of being detached, +* call common node's initiate cleanup function +*/ +efc_node_initiate_cleanup (node); + } +break ; + } +case EFC_EVT_ALL_CHILD_NODES_FREE : +/* Ignore, this can happen if an ELS is +* aborted while in a delay/retry state +*/ +break ; +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } +return NULL ; +} + +void * +__efc_d_wait_loop (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +case EFC_EVT_DOMAIN_ATTACH_OK : { +/* send PLOGI automatically if initiator */ +efc_node_init_device (node, true); +break ; + } +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +/* Save the OX_ID for sending LS_ACC sometime later */ +void +efc_send_ls_acc_after_attach (struct efc_node *node, +struct fc_frame_header *hdr, +enum efc_node_send_ls_acc ls) +{ +u16 ox_id =be16_to_cpu (hdr->fh_ox_id); + +WARN_ON (node->send_ls_acc !=EFC_NODE_SEND_LS_ACC_NONE ); + + node->ls_acc_oxid = ox_id; + node->send_ls_acc = ls; + node->ls_acc_did =ntoh24 (hdr->fh_d_id); +} + +void +efc_process_prli_payload (struct efc_node *node,void *prli) +{ +struct fc_els_spp *sp = prli +sizeof (struct fc_els_prli ); + + node->init = (sp->spp_flags &FCP_SPPF_INIT_FCN ) !=0 ; + node->targ = (sp->spp_flags &FCP_SPPF_TARG_FCN ) !=0 ; +} + +void * +__efc_d_wait_plogi_acc_cmpl (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +case EFC_EVT_SRRS_ELS_CMPL_FAIL : +WARN_ON (!node->els_cmpl_cnt); + node->els_cmpl_cnt--; + node->shutdown_reason =EFC_NODE_SHUTDOWN_DEFAULT ; +efc_node_transition (node, __efc_d_initiate_shutdown,NULL ); +break ; + +case EFC_EVT_SRRS_ELS_CMPL_OK :/* PLOGI ACC completions */ +WARN_ON (!node->els_cmpl_cnt); + node->els_cmpl_cnt--; +efc_node_transition (node, __efc_d_port_logged_in,NULL ); +break ; + +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_d_wait_logo_rsp (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +case EFC_EVT_SRRS_ELS_REQ_OK : +case EFC_EVT_SRRS_ELS_REQ_RJT : +case EFC_EVT_SRRS_ELS_REQ_FAIL : +/* LOGO response received, sent shutdown */ +if (efc_node_check_els_req (ctx, evt, arg,ELS_LOGO , + __efc_d_common, __func__)) +return NULL ; + +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +node_printf (node, +"LOGO sent (evt=%s), shutdown node\n" , +efc_sm_event_name (evt)); +/* sm: / post explicit logout */ +efc_node_post_event (node,EFC_EVT_SHUTDOWN_EXPLICIT_LOGO , +NULL ); +break ; + +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } +return NULL ; +} + +void +efc_node_init_device (struct efc_node *node,bool send_plogi) +{ + node->send_plogi = send_plogi; +if ((node->efc->nodedb_mask &EFC_NODEDB_PAUSE_NEW_NODES ) && + (node->rnode.fc_id !=FC_FID_DOM_MGR )) { + node->nodedb_state = __efc_d_init; +efc_node_transition (node, __efc_node_paused,NULL ); + }else { +efc_node_transition (node, __efc_d_init,NULL ); + } +} + +/** +* Device node state machine: Initial node state for an initiator or +* a target. +* +* This state is entered when a node is instantiated, either having been +* discovered from a name services query, or having received a PLOGI/FLOGI. +*/ +void * +__efc_d_init (struct efc_sm_ctx *ctx,enum efc_sm_event evt,void *arg) +{ +int rc; +struct efc_node_cb *cbdata = arg; +struct efc_node *node = ctx->app; +struct efc *efc = node->efc; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +if (!node->send_plogi) +break ; +/* only send if we have initiator capability, +* and domain is attached +*/ +if (node->sport->enable_ini && + node->sport->domain->attached) { + efc->tt.els_send (efc, node,ELS_PLOGI , +EFC_FC_FLOGI_TIMEOUT_SEC , +EFC_FC_ELS_DEFAULT_RETRIES ); + +efc_node_transition (node, __efc_d_wait_plogi_rsp,NULL ); + }else { +node_printf (node,"not sending plogi sport.ini=%d," , + node->sport->enable_ini); +node_printf (node,"domain attached=%d\n" , + node->sport->domain->attached); + } +break ; +case EFC_EVT_PLOGI_RCVD : { +/* T, or I+T */ +struct fc_frame_header *hdr = cbdata->header->dma.virt; +u32 d_id =ntoh24 (hdr->fh_d_id); + +efc_node_save_sparms (node, cbdata->payload->dma.virt); +efc_send_ls_acc_after_attach (node, + cbdata->header->dma.virt, +EFC_NODE_SEND_LS_ACC_PLOGI ); + +/* domain already attached */ +if (node->sport->domain->attached) { + rc =efc_node_attach (node); +efc_node_transition (node, + __efc_d_wait_node_attach,NULL ); +if (rc ==EFC_HW_RTN_SUCCESS_SYNC ) { +efc_node_post_event (node, +EFC_EVT_NODE_ATTACH_OK , +NULL ); + } +break ; + } + +/* domain not attached; several possibilities: */ +switch (node->sport->topology) { +case EFC_SPORT_TOPOLOGY_P2P : +/* we're not attached and sport is p2p, +* need to attach +*/ +efc_domain_attach (node->sport->domain, d_id); +efc_node_transition (node, + __efc_d_wait_domain_attach, +NULL ); +break ; +case EFC_SPORT_TOPOLOGY_FABRIC : +/* we're not attached and sport is fabric, domain +* attach should have already been requested as part +* of the fabric state machine, wait for it +*/ +efc_node_transition (node, __efc_d_wait_domain_attach, +NULL ); +break ; +case EFC_SPORT_TOPOLOGY_UNKNOWN : +/* Two possibilities: +* 1. received a PLOGI before our FLOGI has completed +* (possible since completion comes in on another +* CQ), thus we don't know what we're connected to +* yet; transition to a state to wait for the +* fabric node to tell us; +* 2. PLOGI received before link went down and we +* haven't performed domain attach yet. +* Note: we cannot distinguish between 1. and 2. +* so have to assume PLOGI +* was received after link back up. +*/ +node_printf (node, +"received PLOGI, unknown topology did=0x%x\n" , + d_id); +efc_node_transition (node, + __efc_d_wait_topology_notify, +NULL ); +break ; +default : +node_printf (node, +"received PLOGI, with unexpected topology %d\n" , + node->sport->topology); +break ; + } +break ; + } + +case EFC_EVT_FDISC_RCVD : { +__efc_d_common (__func__, ctx, evt, arg); +break ; + }
drivers/scsi/elx/libefc/efc_device.c line 599
Quoted 10 lines
drivers/scsi/elx/libefc/efc_device.c new file +10
-0+ +case EFC_EVT_FLOGI_RCVD : { +struct fc_frame_header *hdr = cbdata->header->dma.virt; +u32 d_id =ntoh24 (hdr->fh_d_id); + +/* sm: / save sparams, send FLOGI acc */ +memcpy (node->sport->domain->flogi_service_params, + cbdata->payload->dma.virt, +sizeof (struct fc_els_flogi )); +
Is the '->domain' pointer always present at this point? Shouldn't we rather test for it before accessing?
Quoted 16 lines
drivers/scsi/elx/libefc/efc_device.c new file +16
-0+/* send FC LS_ACC response, override s_id */ +efc_fabric_set_topology (node,EFC_SPORT_TOPOLOGY_P2P ); + efc->tt.send_flogi_p2p_acc (efc, node, +be16_to_cpu (hdr->fh_ox_id), d_id); +if (efc_p2p_setup (node->sport)) { +node_printf (node, +"p2p setup failed, shutting down node\n" ); +efc_node_post_event (node,EFC_EVT_SHUTDOWN ,NULL ); + }else { +efc_node_transition (node, + __efc_p2p_wait_flogi_acc_cmpl, +NULL ); + } + +break ; + }
drivers/scsi/elx/libefc/efc_device.c line 625
Quoted 10 lines
drivers/scsi/elx/libefc/efc_device.c new file +10
-0+ +case EFC_EVT_LOGO_RCVD : { +struct fc_frame_header *hdr = cbdata->header->dma.virt; + +if (!node->sport->domain->attached) { +/* most likely a frame left over from before a link +* down; drop and +* shut node down w/ "explicit logout" so pending +* frames are processed +*/
Same here; I find it slightly weird to have an 'attached' field in the domain structure; attached to what? Doesn't the existence of the ->domain pointer signal the same thing?
If it doesn't, why don't we test for the ->domain pointer before accessing it?
Quoted 15 lines
drivers/scsi/elx/libefc/efc_device.c new file +15
-0+node_printf (node,"%s domain not attached, dropping\n" , +efc_sm_event_name (evt)); +efc_node_post_event (node, +EFC_EVT_SHUTDOWN_EXPLICIT_LOGO , +NULL ); +break ; + } + efc->tt.els_send_resp (efc, node,ELS_LOGO , +be16_to_cpu (hdr->fh_ox_id)); +efc_node_transition (node, __efc_d_wait_logo_acc_cmpl,NULL ); +break ; + } + +case EFC_EVT_PRLI_RCVD : +case EFC_EVT_PRLO_RCVD :
drivers/scsi/elx/libefc/efc_device.c line 650
Quoted 10 lines
drivers/scsi/elx/libefc/efc_device.c new file +10
-0+case EFC_EVT_PDISC_RCVD : +case EFC_EVT_ADISC_RCVD : +case EFC_EVT_RSCN_RCVD : { +struct fc_frame_header *hdr = cbdata->header->dma.virt; + +if (!node->sport->domain->attached) { +/* most likely a frame left over from before a link +* down; drop and shut node down w/ "explicit logout" +* so pending frames are processed +*/
See above.
Quoted 1,091 lines
drivers/scsi/elx/libefc/efc_device.c new file +1022
-0+node_printf (node,"%s domain not attached, dropping\n" , +efc_sm_event_name (evt)); + +efc_node_post_event (node, +EFC_EVT_SHUTDOWN_EXPLICIT_LOGO , +NULL ); +break ; + } +node_printf (node,"%s received, sending reject\n" , +efc_sm_event_name (evt)); + efc->tt.send_ls_rjt (efc, node,be16_to_cpu (hdr->fh_ox_id), +ELS_RJT_UNAB ,ELS_EXPL_PLOGI_REQD ,0 ); + +break ; + } + +case EFC_EVT_FCP_CMD_RCVD : { +/* note: problem, we're now expecting an ELS REQ completion +* from both the LOGO and PLOGI +*/ +if (!node->sport->domain->attached) { +/* most likely a frame left over from before a +* link down; drop and +* shut node down w/ "explicit logout" so pending +* frames are processed +*/ +node_printf (node,"%s domain not attached, dropping\n" , +efc_sm_event_name (evt)); +efc_node_post_event (node, +EFC_EVT_SHUTDOWN_EXPLICIT_LOGO , +NULL ); +break ; + } + +/* Send LOGO */ +node_printf (node,"FCP_CMND received, send LOGO\n" ); +if (efc->tt.els_send (efc, node,ELS_LOGO , +EFC_FC_FLOGI_TIMEOUT_SEC , +EFC_FC_ELS_DEFAULT_RETRIES ) ==NULL ) { +/* +* failed to send LOGO, go ahead and cleanup node +* anyways +*/ +node_printf (node,"Failed to send LOGO\n" ); +efc_node_post_event (node, +EFC_EVT_SHUTDOWN_EXPLICIT_LOGO , +NULL ); + }else { +/* sent LOGO, wait for response */ +efc_node_transition (node, + __efc_d_wait_logo_rsp,NULL ); + } +break ; + } +case EFC_EVT_DOMAIN_ATTACH_OK : +/* don't care about domain_attach_ok */ +break ; + +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_d_wait_plogi_rsp (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +int rc; +struct efc_node_cb *cbdata = arg; +struct efc_node *node = ctx->app; +struct efc *efc = node->efc; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_PLOGI_RCVD : { +/* T, or I+T */ +/* received PLOGI with svc parms, go ahead and attach node +* when PLOGI that was sent ultimately completes, it'll be a +* no-op +* +* If there is an outstanding PLOGI sent, can we set a flag +* to indicate that we don't want to retry it if it times out? +*/ +efc_node_save_sparms (node, cbdata->payload->dma.virt); +efc_send_ls_acc_after_attach (node, + cbdata->header->dma.virt, +EFC_NODE_SEND_LS_ACC_PLOGI ); +/* sm: domain->attached / efc_node_attach */ + rc =efc_node_attach (node); +efc_node_transition (node, __efc_d_wait_node_attach,NULL ); +if (rc ==EFC_HW_RTN_SUCCESS_SYNC ) +efc_node_post_event (node, +EFC_EVT_NODE_ATTACH_OK ,NULL ); + +break ; + } + +case EFC_EVT_PRLI_RCVD : +/* I, or I+T */ +/* sent PLOGI and before completion was seen, received the +* PRLI from the remote node (WCQEs and RCQEs come in on +* different queues and order of processing cannot be assumed) +* Save OXID so PRLI can be sent after the attach and continue +* to wait for PLOGI response +*/ +efc_process_prli_payload (node, cbdata->payload->dma.virt); +efc_send_ls_acc_after_attach (node, + cbdata->header->dma.virt, +EFC_NODE_SEND_LS_ACC_PRLI ); +efc_node_transition (node, __efc_d_wait_plogi_rsp_recvd_prli, +NULL ); +break ; + +case EFC_EVT_LOGO_RCVD :/* why don't we do a shutdown here?? */ +case EFC_EVT_PRLO_RCVD : +case EFC_EVT_PDISC_RCVD : +case EFC_EVT_FDISC_RCVD : +case EFC_EVT_ADISC_RCVD : +case EFC_EVT_RSCN_RCVD : +case EFC_EVT_SCR_RCVD : { +struct fc_frame_header *hdr = cbdata->header->dma.virt; + +node_printf (node,"%s received, sending reject\n" , +efc_sm_event_name (evt)); + + efc->tt.send_ls_rjt (efc, node,be16_to_cpu (hdr->fh_ox_id), +ELS_RJT_UNAB ,ELS_EXPL_PLOGI_REQD ,0 ); + +break ; + } + +case EFC_EVT_SRRS_ELS_REQ_OK :/* PLOGI response received */ +/* Completion from PLOGI sent */ +if (efc_node_check_els_req (ctx, evt, arg,ELS_PLOGI , + __efc_d_common, __func__)) +return NULL ; + +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +/* sm: / save sparams, efc_node_attach */ +efc_node_save_sparms (node, cbdata->els_rsp.virt); + rc =efc_node_attach (node); +efc_node_transition (node, __efc_d_wait_node_attach,NULL ); +if (rc ==EFC_HW_RTN_SUCCESS_SYNC ) +efc_node_post_event (node, +EFC_EVT_NODE_ATTACH_OK ,NULL ); + +break ; + +case EFC_EVT_SRRS_ELS_REQ_FAIL :/* PLOGI response received */ +/* PLOGI failed, shutdown the node */ +if (efc_node_check_els_req (ctx, evt, arg,ELS_PLOGI , + __efc_d_common, __func__)) +return NULL ; + +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +efc_node_post_event (node,EFC_EVT_SHUTDOWN ,NULL ); +break ; + +case EFC_EVT_SRRS_ELS_REQ_RJT : +/* Our PLOGI was rejected, this is ok in some cases */ +if (efc_node_check_els_req (ctx, evt, arg,ELS_PLOGI , + __efc_d_common, __func__)) +return NULL ; + +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +break ; + +case EFC_EVT_FCP_CMD_RCVD : { +/* not logged in yet and outstanding PLOGI so don't send LOGO, +* just drop +*/ +node_printf (node,"FCP_CMND received, drop\n" ); +break ; + } + +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_d_wait_plogi_rsp_recvd_prli (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +int rc; +struct efc_node_cb *cbdata = arg; +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +/* +* Since we've received a PRLI, we have a port login and will +* just need to wait for the PLOGI response to do the node +* attach and then we can send the LS_ACC for the PRLI. If, +* during this time, we receive FCP_CMNDs (which is possible +* since we've already sent a PRLI and our peer may have +* accepted). At this time, we are not waiting on any other +* unsolicited frames to continue with the login process. Thus, +* it will not hurt to hold frames here. +*/ +efc_node_hold_frames (node); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +case EFC_EVT_SRRS_ELS_REQ_OK :/* PLOGI response received */ +/* Completion from PLOGI sent */ +if (efc_node_check_els_req (ctx, evt, arg,ELS_PLOGI , + __efc_d_common, __func__)) +return NULL ; + +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +/* sm: / save sparams, efc_node_attach */ +efc_node_save_sparms (node, cbdata->els_rsp.virt); + rc =efc_node_attach (node); +efc_node_transition (node, __efc_d_wait_node_attach,NULL ); +if (rc ==EFC_HW_RTN_SUCCESS_SYNC ) +efc_node_post_event (node,EFC_EVT_NODE_ATTACH_OK , +NULL ); + +break ; + +case EFC_EVT_SRRS_ELS_REQ_FAIL :/* PLOGI response received */ +case EFC_EVT_SRRS_ELS_REQ_RJT : +/* PLOGI failed, shutdown the node */ +if (efc_node_check_els_req (ctx, evt, arg,ELS_PLOGI , + __efc_d_common, __func__)) +return NULL ; + +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +efc_node_post_event (node,EFC_EVT_SHUTDOWN ,NULL ); +break ; + +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_d_wait_domain_attach (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +int rc; +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +case EFC_EVT_DOMAIN_ATTACH_OK : +WARN_ON (!node->sport->domain->attached); +/* sm: / efc_node_attach */ + rc =efc_node_attach (node); +efc_node_transition (node, __efc_d_wait_node_attach,NULL ); +if (rc ==EFC_HW_RTN_SUCCESS_SYNC ) +efc_node_post_event (node,EFC_EVT_NODE_ATTACH_OK , +NULL ); + +break ; + +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } +return NULL ; +} + +void * +__efc_d_wait_topology_notify (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +int rc; +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +case EFC_EVT_SPORT_TOPOLOGY_NOTIFY : { +enum efc_sport_topology topology = + (enum efc_sport_topology )arg; + +WARN_ON (node->sport->domain->attached); + +WARN_ON (node->send_ls_acc !=EFC_NODE_SEND_LS_ACC_PLOGI ); + +node_printf (node,"topology notification, topology=%d\n" , + topology); + +/* At the time the PLOGI was received, the topology was unknown, +* so we didn't know which node would perform the domain attach: +* 1. The node from which the PLOGI was sent (p2p) or +* 2. The node to which the FLOGI was sent (fabric). +*/ +if (topology ==EFC_SPORT_TOPOLOGY_P2P ) { +/* if this is p2p, need to attach to the domain using +* the d_id from the PLOGI received +*/ +efc_domain_attach (node->sport->domain, + node->ls_acc_did); + } +/* else, if this is fabric, the domain attach +* should be performed by the fabric node (node sending FLOGI); +* just wait for attach to complete +*/ + +efc_node_transition (node, __efc_d_wait_domain_attach,NULL ); +break ; + } +case EFC_EVT_DOMAIN_ATTACH_OK : +WARN_ON (!node->sport->domain->attached); +node_printf (node,"domain attach ok\n" ); +/* sm: / efc_node_attach */ + rc =efc_node_attach (node); +efc_node_transition (node, __efc_d_wait_node_attach,NULL ); +if (rc ==EFC_HW_RTN_SUCCESS_SYNC ) +efc_node_post_event (node, +EFC_EVT_NODE_ATTACH_OK ,NULL ); + +break ; + +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } +return NULL ; +} + +void * +__efc_d_wait_node_attach (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; +struct efc *efc = node->efc; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +case EFC_EVT_NODE_ATTACH_OK : + node->attached = true; +switch (node->send_ls_acc) { +case EFC_NODE_SEND_LS_ACC_PLOGI : { +/* sm: send_plogi_acc is set / send PLOGI acc */ +/* Normal case for T, or I+T */ + efc->tt.els_send_resp (efc, node,ELS_PLOGI , + node->ls_acc_oxid); +efc_node_transition (node, + __efc_d_wait_plogi_acc_cmpl, +NULL ); + node->send_ls_acc =EFC_NODE_SEND_LS_ACC_NONE ; + node->ls_acc_io =NULL ; +break ; + } +case EFC_NODE_SEND_LS_ACC_PRLI : { +efc_d_send_prli_rsp (node, + node->ls_acc_oxid); + node->send_ls_acc =EFC_NODE_SEND_LS_ACC_NONE ; + node->ls_acc_io =NULL ; +break ; + } +case EFC_NODE_SEND_LS_ACC_NONE : +default : +/* Normal case for I */ +/* sm: send_plogi_acc is not set / send PLOGI acc */ +efc_node_transition (node, + __efc_d_port_logged_in,NULL ); +break ; + } +break ; + +case EFC_EVT_NODE_ATTACH_FAIL : +/* node attach failed, shutdown the node */ + node->attached = false; +node_printf (node,"node attach failed\n" ); + node->shutdown_reason =EFC_NODE_SHUTDOWN_DEFAULT ; +efc_node_transition (node, __efc_d_initiate_shutdown,NULL ); +break ; + +/* Handle shutdown events */ +case EFC_EVT_SHUTDOWN : +node_printf (node,"%s received\n" ,efc_sm_event_name (evt)); + node->shutdown_reason =EFC_NODE_SHUTDOWN_DEFAULT ; +efc_node_transition (node, __efc_d_wait_attach_evt_shutdown, +NULL ); +break ; +case EFC_EVT_SHUTDOWN_EXPLICIT_LOGO : +node_printf (node,"%s received\n" ,efc_sm_event_name (evt)); + node->shutdown_reason =EFC_NODE_SHUTDOWN_EXPLICIT_LOGO ; +efc_node_transition (node, __efc_d_wait_attach_evt_shutdown, +NULL ); +break ; +case EFC_EVT_SHUTDOWN_IMPLICIT_LOGO : +node_printf (node,"%s received\n" ,efc_sm_event_name (evt)); + node->shutdown_reason =EFC_NODE_SHUTDOWN_IMPLICIT_LOGO ; +efc_node_transition (node, + __efc_d_wait_attach_evt_shutdown,NULL ); +break ; +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_d_wait_attach_evt_shutdown (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +/* wait for any of these attach events and then shutdown */ +case EFC_EVT_NODE_ATTACH_OK : + node->attached = true; +node_printf (node,"Attach evt=%s, proceed to shutdown\n" , +efc_sm_event_name (evt)); +efc_node_transition (node, __efc_d_initiate_shutdown,NULL ); +break ; + +case EFC_EVT_NODE_ATTACH_FAIL : +/* node attach failed, shutdown the node */ + node->attached = false; +node_printf (node,"Attach evt=%s, proceed to shutdown\n" , +efc_sm_event_name (evt)); +efc_node_transition (node, __efc_d_initiate_shutdown,NULL ); +break ; + +/* ignore shutdown events as we're already in shutdown path */ +case EFC_EVT_SHUTDOWN : +/* have default shutdown event take precedence */ + node->shutdown_reason =EFC_NODE_SHUTDOWN_DEFAULT ; +/* fall through */ +case EFC_EVT_SHUTDOWN_EXPLICIT_LOGO : +case EFC_EVT_SHUTDOWN_IMPLICIT_LOGO : +node_printf (node,"%s received\n" ,efc_sm_event_name (evt)); +break ; + +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_d_port_logged_in (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node_cb *cbdata = arg; +struct efc_node *node = ctx->app; +struct efc *efc = node->efc; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +/* Normal case for I or I+T */ +if (node->sport->enable_ini && + !(node->rnode.fc_id !=FC_FID_DOM_MGR )) { +/* sm: if enable_ini / send PRLI */ + efc->tt.els_send (efc, node,ELS_PRLI , +EFC_FC_ELS_SEND_DEFAULT_TIMEOUT , +EFC_FC_ELS_DEFAULT_RETRIES ); +/* can now expect ELS_REQ_OK/FAIL/RJT */ + } +break ; + +case EFC_EVT_FCP_CMD_RCVD : { +break ; + } + +case EFC_EVT_PRLI_RCVD : { +/* Normal case for T or I+T */ +struct fc_frame_header *hdr = cbdata->header->dma.virt; +struct fc_els_spp *sp = cbdata->payload->dma.virt + +sizeof (struct fc_els_prli ); + +if (sp->spp_type !=FC_TYPE_FCP ) { +/*Only FCP is supported*/ + efc->tt.send_ls_rjt (efc, node, +be16_to_cpu (hdr->fh_ox_id), +ELS_RJT_UNAB ,ELS_EXPL_UNSUPR ,0 ); +break ; + } + +efc_process_prli_payload (node, cbdata->payload->dma.virt); +efc_d_send_prli_rsp (node,be16_to_cpu (hdr->fh_ox_id)); +break ; + } + +case EFC_EVT_SRRS_ELS_REQ_OK : {/* PRLI response */ +/* Normal case for I or I+T */ +if (efc_node_check_els_req (ctx, evt, arg,ELS_PRLI , + __efc_d_common, __func__)) +return NULL ; + +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +/* sm: / process PRLI payload */ +efc_process_prli_payload (node, cbdata->els_rsp.virt); +efc_node_transition (node, __efc_d_device_ready,NULL ); +break ; + } + +case EFC_EVT_SRRS_ELS_REQ_FAIL : {/* PRLI response failed */ +/* I, I+T, assume some link failure, shutdown node */ +if (efc_node_check_els_req (ctx, evt, arg,ELS_PRLI , + __efc_d_common, __func__)) +return NULL ; + +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +efc_node_post_event (node,EFC_EVT_SHUTDOWN ,NULL ); +break ; + } + +case EFC_EVT_SRRS_ELS_REQ_RJT : { +/* PRLI rejected by remote +* Normal for I, I+T (connected to an I) +* Node doesn't want to be a target, stay here and wait for a +* PRLI from the remote node +* if it really wants to connect to us as target +*/ +if (efc_node_check_els_req (ctx, evt, arg,ELS_PRLI , + __efc_d_common, __func__)) +return NULL ; + +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +break ; + } + +case EFC_EVT_SRRS_ELS_CMPL_OK : { +/* Normal T, I+T, target-server rejected the process login */ +/* This would be received only in the case where we sent +* LS_RJT for the PRLI, so +* do nothing. (note: as T only we could shutdown the node) +*/ +WARN_ON (!node->els_cmpl_cnt); + node->els_cmpl_cnt--; +break ; + } + +case EFC_EVT_PLOGI_RCVD : { +/*sm: / save sparams, set send_plogi_acc, +*post implicit logout +* Save plogi parameters +*/ +efc_node_save_sparms (node, cbdata->payload->dma.virt); +efc_send_ls_acc_after_attach (node, + cbdata->header->dma.virt, +EFC_NODE_SEND_LS_ACC_PLOGI ); + +/* Restart node attach with new service parameters, +* and send ACC +*/ +efc_node_post_event (node,EFC_EVT_SHUTDOWN_IMPLICIT_LOGO , +NULL ); +break ; + } + +case EFC_EVT_LOGO_RCVD : { +/* I, T, I+T */ +struct fc_frame_header *hdr = cbdata->header->dma.virt; + +node_printf (node,"%s received attached=%d\n" , +efc_sm_event_name (evt), + node->attached); +/* sm: / send LOGO acc */ + efc->tt.els_send_resp (efc, node,ELS_LOGO , +be16_to_cpu (hdr->fh_ox_id)); +efc_node_transition (node, __efc_d_wait_logo_acc_cmpl,NULL ); +break ; + } + +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_d_wait_logo_acc_cmpl (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node *node = ctx->app; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : +efc_node_hold_frames (node); +break ; + +case EFC_EVT_EXIT : +efc_node_accept_frames (node); +break ; + +case EFC_EVT_SRRS_ELS_CMPL_OK : +case EFC_EVT_SRRS_ELS_CMPL_FAIL : +/* sm: / post explicit logout */ +WARN_ON (!node->els_cmpl_cnt); + node->els_cmpl_cnt--; +efc_node_post_event (node, +EFC_EVT_SHUTDOWN_EXPLICIT_LOGO ,NULL ); +break ; +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_d_device_ready (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node_cb *cbdata = arg; +struct efc_node *node = ctx->app; +struct efc *efc = node->efc; + +efc_node_evt_set (ctx, evt, __func__); + +if (evt !=EFC_EVT_FCP_CMD_RCVD ) +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : + node->fcp_enabled = true; +if (node->init) { +efc_log_info (efc, +"[%s] found (initiator) WWPN %s WWNN %s\n" , + node->display_name, + node->wwpn, node->wwnn); +if (node->sport->enable_tgt) + efc->tt.scsi_new_node (efc, node); + } +if (node->targ) { +efc_log_info (efc, +"[%s] found (target) WWPN %s WWNN %s\n" , + node->display_name, + node->wwpn, node->wwnn); +if (node->sport->enable_ini) + efc->tt.scsi_new_node (efc, node); + } +break ; + +case EFC_EVT_EXIT : + node->fcp_enabled = false; +break ; + +case EFC_EVT_PLOGI_RCVD : { +/* sm: / save sparams, set send_plogi_acc, post implicit +* logout +* Save plogi parameters +*/ +efc_node_save_sparms (node, cbdata->payload->dma.virt); +efc_send_ls_acc_after_attach (node, + cbdata->header->dma.virt, +EFC_NODE_SEND_LS_ACC_PLOGI ); + +/* +* Restart node attach with new service parameters, +* and send ACC +*/ +efc_node_post_event (node, +EFC_EVT_SHUTDOWN_IMPLICIT_LOGO ,NULL ); +break ; + } + +case EFC_EVT_PRLI_RCVD : { +/* T, I+T: remote initiator is slow to get started */ +struct fc_frame_header *hdr = cbdata->header->dma.virt; +struct fc_els_spp *sp = cbdata->payload->dma.virt + +sizeof (struct fc_els_prli ); + +if (sp->spp_type !=FC_TYPE_FCP ) { +/*Only FCP is supported*/ + efc->tt.send_ls_rjt (efc, node, +be16_to_cpu (hdr->fh_ox_id), +ELS_RJT_UNAB ,ELS_EXPL_UNSUPR ,0 ); +break ; + } + +efc_process_prli_payload (node, cbdata->payload->dma.virt); + + efc->tt.els_send_resp (efc, node,ELS_PRLI , +be16_to_cpu (hdr->fh_ox_id)); +break ; + } + +case EFC_EVT_PRLO_RCVD : { +struct fc_frame_header *hdr = cbdata->header->dma.virt; +/* sm: / send PRLO acc */ + efc->tt.els_send_resp (efc, node,ELS_PRLO , +be16_to_cpu (hdr->fh_ox_id)); +/* need implicit logout? */ +break ; + } + +case EFC_EVT_LOGO_RCVD : { +struct fc_frame_header *hdr = cbdata->header->dma.virt; + +node_printf (node,"%s received attached=%d\n" , +efc_sm_event_name (evt), node->attached); +/* sm: / send LOGO acc */ + efc->tt.els_send_resp (efc, node,ELS_LOGO , +be16_to_cpu (hdr->fh_ox_id)); +efc_node_transition (node, __efc_d_wait_logo_acc_cmpl,NULL ); +break ; + } + +case EFC_EVT_ADISC_RCVD : { +struct fc_frame_header *hdr = cbdata->header->dma.virt; +/* sm: / send ADISC acc */ + efc->tt.els_send_resp (efc, node,ELS_ADISC , +be16_to_cpu (hdr->fh_ox_id)); +break ; + } + +case EFC_EVT_ABTS_RCVD : +/* sm: / process ABTS */ +efc_log_err (efc,"Unexpected event:%s\n" , +efc_sm_event_name (evt)); +break ; + +case EFC_EVT_NODE_ACTIVE_IO_LIST_EMPTY : +break ; + +case EFC_EVT_NODE_REFOUND : +break ; + +case EFC_EVT_NODE_MISSING : +if (node->sport->enable_rscn) +efc_node_transition (node, __efc_d_device_gone,NULL ); + +break ; + +case EFC_EVT_SRRS_ELS_CMPL_OK : +/* T, or I+T, PRLI accept completed ok */ +WARN_ON (!node->els_cmpl_cnt); + node->els_cmpl_cnt--; +break ; + +case EFC_EVT_SRRS_ELS_CMPL_FAIL : +/* T, or I+T, PRLI accept failed to complete */ +WARN_ON (!node->els_cmpl_cnt); + node->els_cmpl_cnt--; +node_printf (node,"Failed to send PRLI LS_ACC\n" ); +break ; + +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_d_device_gone (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +int rc =EFC_SCSI_CALL_COMPLETE ; +int rc_2 =EFC_SCSI_CALL_COMPLETE ; +struct efc_node_cb *cbdata = arg; +struct efc_node *node = ctx->app; +struct efc *efc = node->efc; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_ENTER : { +static char const *labels[] = {"none" ,"initiator" ,"target" , +"initiator+target" }; + +efc_log_info (efc,"[%s] missing (%s) WWPN %s WWNN %s\n" , + node->display_name, + labels[(node->targ <<1 ) | (node->init)], + node->wwpn, node->wwnn); + +switch (efc_node_get_enable (node)) { +case EFC_NODE_ENABLE_T_TO_T : +case EFC_NODE_ENABLE_I_TO_T : +case EFC_NODE_ENABLE_IT_TO_T : + rc = efc->tt.scsi_del_node (efc, node, +EFC_SCSI_TARGET_MISSING ); +break ; + +case EFC_NODE_ENABLE_T_TO_I : +case EFC_NODE_ENABLE_I_TO_I : +case EFC_NODE_ENABLE_IT_TO_I : + rc = efc->tt.scsi_del_node (efc, node, +EFC_SCSI_INITIATOR_MISSING ); +break ; + +case EFC_NODE_ENABLE_T_TO_IT : + rc = efc->tt.scsi_del_node (efc, node, +EFC_SCSI_INITIATOR_MISSING ); +break ; + +case EFC_NODE_ENABLE_I_TO_IT : + rc = efc->tt.scsi_del_node (efc, node, +EFC_SCSI_TARGET_MISSING ); +break ; + +case EFC_NODE_ENABLE_IT_TO_IT : + rc = efc->tt.scsi_del_node (efc, node, +EFC_SCSI_INITIATOR_MISSING ); + rc_2 = efc->tt.scsi_del_node (efc, node, +EFC_SCSI_TARGET_MISSING ); +break ; + +default : + rc =EFC_SCSI_CALL_COMPLETE ; +break ; + } + +if (rc ==EFC_SCSI_CALL_COMPLETE && + rc_2 ==EFC_SCSI_CALL_COMPLETE ) +efc_node_post_event (node,EFC_EVT_SHUTDOWN ,NULL ); + +break ; + } +case EFC_EVT_NODE_REFOUND : +/* two approaches, reauthenticate with PLOGI/PRLI, or ADISC */ + +/* reauthenticate with PLOGI/PRLI */ +/* efc_node_transition(node, __efc_d_discovered, NULL); */ + +/* reauthenticate with ADISC */ +/* sm: / send ADISC */ + efc->tt.els_send (efc, node,ELS_ADISC , +EFC_FC_FLOGI_TIMEOUT_SEC , +EFC_FC_ELS_DEFAULT_RETRIES ); +efc_node_transition (node, __efc_d_wait_adisc_rsp,NULL ); +break ; + +case EFC_EVT_PLOGI_RCVD : { +/* sm: / save sparams, set send_plogi_acc, post implicit +* logout +* Save plogi parameters +*/ +efc_node_save_sparms (node, cbdata->payload->dma.virt); +efc_send_ls_acc_after_attach (node, + cbdata->header->dma.virt, +EFC_NODE_SEND_LS_ACC_PLOGI ); + +/* +* Restart node attach with new service parameters, and send +* ACC +*/ +efc_node_post_event (node,EFC_EVT_SHUTDOWN_IMPLICIT_LOGO , +NULL ); +break ; + } + +case EFC_EVT_FCP_CMD_RCVD : { +/* most likely a stale frame (received prior to link down), +* if attempt to send LOGO, will probably timeout and eat +* up 20s; thus, drop FCP_CMND +*/ +node_printf (node,"FCP_CMND received, drop\n" ); +break ; + } +case EFC_EVT_LOGO_RCVD : { +/* I, T, I+T */ +struct fc_frame_header *hdr = cbdata->header->dma.virt; + +node_printf (node,"%s received attached=%d\n" , +efc_sm_event_name (evt), node->attached); +/* sm: / send LOGO acc */ + efc->tt.els_send_resp (efc, node,ELS_LOGO , +be16_to_cpu (hdr->fh_ox_id)); +efc_node_transition (node, __efc_d_wait_logo_acc_cmpl,NULL ); +break ; + } +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +} + +void * +__efc_d_wait_adisc_rsp (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg) +{ +struct efc_node_cb *cbdata = arg; +struct efc_node *node = ctx->app; +struct efc *efc = node->efc; + +efc_node_evt_set (ctx, evt, __func__); + +node_sm_trace (); + +switch (evt) { +case EFC_EVT_SRRS_ELS_REQ_OK : +if (efc_node_check_els_req (ctx, evt, arg,ELS_ADISC , + __efc_d_common, __func__)) +return NULL ; + +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +efc_node_transition (node, __efc_d_device_ready,NULL ); +break ; + +case EFC_EVT_SRRS_ELS_REQ_RJT : +/* received an LS_RJT, in this case, send shutdown +* (explicit logo) event which will unregister the node, +* and start over with PLOGI +*/ +if (efc_node_check_els_req (ctx, evt, arg,ELS_ADISC , + __efc_d_common, __func__)) +return NULL ; + +WARN_ON (!node->els_req_cnt); + node->els_req_cnt--; +/* sm: / post explicit logout */ +efc_node_post_event (node, +EFC_EVT_SHUTDOWN_EXPLICIT_LOGO , +NULL ); +break ; + +case EFC_EVT_LOGO_RCVD : { +/* In this case, we have the equivalent of an LS_RJT for +* the ADISC, so we need to abort the ADISC, and re-login +* with PLOGI +*/ +/* sm: / request abort, send LOGO acc */ +struct fc_frame_header *hdr = cbdata->header->dma.virt; + +node_printf (node,"%s received attached=%d\n" , +efc_sm_event_name (evt), node->attached); + + efc->tt.els_send_resp (efc, node,ELS_LOGO , +be16_to_cpu (hdr->fh_ox_id)); +efc_node_transition (node, __efc_d_wait_logo_acc_cmpl,NULL ); +break ; + } +default : +__efc_d_common (__func__, ctx, evt, arg); +return NULL ; + } + +return NULL ; +}drivers/scsi/elx/libefc/efc_device.h new file +62
-0@@ -0,0 +1,72 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2019 Broadcom. All Rights Reserved. The term +* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +*/ + +/* +* Node state machine functions for remote device node sm +*/ + +#ifndef __EFCT_DEVICE_H__ +#define __EFCT_DEVICE_H__ +extern void +efc_node_init_device (struct efc_node *node,bool send_plogi); +extern void +efc_process_prli_payload (struct efc_node *node, +void *prli); +extern void +efc_d_send_prli_rsp (struct efc_node *node,uint16_t ox_id); +extern void +efc_send_ls_acc_after_attach (struct efc_node *node, +struct fc_frame_header *hdr, +enum efc_node_send_ls_acc ls); +extern void * +__efc_d_wait_loop (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +extern void * +__efc_d_wait_plogi_acc_cmpl (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +extern void * +__efc_d_init (struct efc_sm_ctx *ctx,enum efc_sm_event evt,void *arg); +extern void * +__efc_d_wait_plogi_rsp (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +extern void * +__efc_d_wait_plogi_rsp_recvd_prli (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +extern void * +__efc_d_wait_domain_attach (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +extern void * +__efc_d_wait_topology_notify (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +extern void * +__efc_d_wait_node_attach (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +extern void * +__efc_d_wait_attach_evt_shutdown (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +extern void * +__efc_d_initiate_shutdown (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +extern void * +__efc_d_port_logged_in (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +extern void * +__efc_d_wait_logo_acc_cmpl (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +extern void * +__efc_d_device_ready (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +extern void *
drivers/scsi/elx/libefc/efc_device.h line 72
Quoted 10 lines
drivers/scsi/elx/libefc/efc_device.h new file +10
-0+__efc_d_device_gone(struct efc_sm_ctx *ctx, + enum efc_sm_event evt, void *arg); +extern void * +__efc_d_wait_adisc_rsp (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); +extern void * +__efc_d_wait_logo_rsp (struct efc_sm_ctx *ctx, +enum efc_sm_event evt,void *arg); + +#endif /* __EFCT_DEVICE_H__ */
And, of course, the comment from the previous patch about the really weird logic of 'void *' functions always returning NULL does apply to here, too.
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
Re: [PATCH v3 14/31] elx: libefc: FC node ELS and state handling
On 4/15/2020 11:47 PM, Hannes Reinecke wrote:
...
Quoted 4 lines
Quoted 4 lines
+ case
EFC_EVT_FLOGI_RCVD: {
+ structfc_frame_header*hdr =cbdata->header->dma.virt; + u32d_id=ntoh24(hdr->fh_d_id);
+
Quoted 8 lines
Quoted 5 lines
+ /* sm: / save sparams, send FLOGI acc */ + memcpy(node->sport->domain->flogi_service_params, +
cbdata->payload->dma.virt,
+sizeof(struct fc_els_flogi));
+Is the '->domain' pointer always present at this point? Shouldn't we rather test for it before accessing?
Always - if there's a node ans sport.
Quoted 23 lines
Quoted 23 lines
+ /* send FC
LS_ACCresponse, overrides_id*/ +efc_fabric_set_topology(node, EFC_SPORT_TOPOLOGY_P2P); + efc->tt.send_flogi_p2p_acc(efc, node,
+be16_to_cpu(hdr->fh_ox_id),d_id);
+ if (efc_p2p_setup(node->sport)) {
+ node_printf(node,
+ "p2p setup failed, shutting down node\n"); +efc_node_post_event(node, EFC_EVT_SHUTDOWN, NULL); + } else {
+ efc_node_transition(node,
+__efc_p2p_wait_flogi_acc_cmpl, + NULL);
+ }drivers/scsi/elx/libefc/efc_device.c new file +9
-0+ + break; + } + + case EFC_EVT_LOGO_RCVD: { + struct fc_frame_header *hdr = cbdata->header->dma.virt; + + if (!node->sport->domain->attached) { + /* most likely a frame left over from before a link
Quoted 8 lines
Quoted 4 lines
+ * down; drop and
+ * shut node down w/ "explicit logout" so pending + * frames are processed
+ */Same here; I find it slightly weird to have an 'attached' field in the domain structure; attached to what? Doesn't the existence of the ->domain pointer signal the same thing?
If it doesn't, why don't we test for the ->domain pointer before accessing it?
Attached means something different here. Not only does the structure exist, but there have been VFI/VPI resources registered with the hardware for it.
Agree with your other comments and will address them. And the same agreement for comments on patches 3, 9 & 10.
-- james
PATCH v3 15/31 elx: efct: Data structures and defines for hw operations
In reply to James SmartThis patch starts the population of the efct target mode driver. The driver is contained in the drivers/scsi/elx/efct subdirectory.
This patch creates the efct directory and starts population of the driver by adding SLI-4 configuration parameters, data structures for configuring SLI-4 queues, converting from os to SLI-4 IO requests, and handling async events.
---
v3:
Changed anonymous enums to named.
Removed some structures and defines which are not used. Reworked on efct_hw_io_param struct which can be used for holding
params in WQE submission.
--- drivers/scsi/elx/efct/efct_hw.h | 617 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 617 insertions(+) create mode 100644 drivers/scsi/elx/efct/efct_hw.h
drivers/scsi/elx/efct/efct_hw.h new file +617 -0
@@ -0,0 +1,617 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2019 Broadcom. All Rights Reserved. The term +* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +*/ + +#ifndef _EFCT_HW_H +#define _EFCT_HW_H + +#include "../libefc_sli/sli4.h" + +/* +* EFCT PCI IDs +*/ +#define EFCT_VENDOR_ID 0x10df +/* LightPulse 16Gb x 4 FC (lancer-g6) */ +#define EFCT_DEVICE_LANCER_G6 0xe307 +/* LightPulse 32Gb x 4 FC (lancer-g7) */ +#define EFCT_DEVICE_LANCER_G7 0xf407 + +/*Default RQ entries len used by driver*/ +#define EFCT_HW_RQ_ENTRIES_MIN 512 +#define EFCT_HW_RQ_ENTRIES_DEF 1024 +#define EFCT_HW_RQ_ENTRIES_MAX 4096 + +/*Defines the size of the RQ buffers used for each RQ*/ +#define EFCT_HW_RQ_SIZE_HDR 128 +#define EFCT_HW_RQ_SIZE_PAYLOAD 1024 + +/*Define the maximum number of multi-receive queues*/ +#define EFCT_HW_MAX_MRQS 8 + +/* +* Define count of when to set the WQEC bit in a submitted +* WQE, causing a consummed/released completion to be posted. +*/ +#define EFCT_HW_WQEC_SET_COUNT 32 + +/*Send frame timeout in seconds*/ +#define EFCT_HW_SEND_FRAME_TIMEOUT 10 + +/* +* FDT Transfer Hint value, reads greater than this value +* will be segmented to implement fairness. A value of zero disables +* the feature. +*/ +#define EFCT_HW_FDT_XFER_HINT 8192 + +#define EFCT_HW_TIMECHECK_ITERATIONS 100 +#define EFCT_HW_MAX_NUM_MQ 1 +#define EFCT_HW_MAX_NUM_RQ 32 +#define EFCT_HW_MAX_NUM_EQ 16 +#define EFCT_HW_MAX_NUM_WQ 32 +#define EFCT_HW_DEF_NUM_EQ 1 + +#define OCE_HW_MAX_NUM_MRQ_PAIRS 16 + +#define EFCT_HW_MQ_DEPTH 128 +#define EFCT_HW_EQ_DEPTH 1024 + +/* +* A CQ will be assinged to each WQ +* (CQ must have 2X entries of the WQ for abort +* processing), plus a separate one for each RQ PAIR and one for MQ +*/ +#define EFCT_HW_MAX_NUM_CQ \ + ((EFCT_HW_MAX_NUM_WQ * 2) + 1 + (OCE_HW_MAX_NUM_MRQ_PAIRS * 2)) + +#define EFCT_HW_Q_HASH_SIZE 128 +#define EFCT_HW_RQ_HEADER_SIZE 128 +#define EFCT_HW_RQ_HEADER_INDEX 0 + +#define EFCT_HW_REQUE_XRI_REGTAG 65534 + +/* Options for efct_hw_command() */ +enum efct_cmd_opts { +/* command executes synchronously and busy-waits for completion */ +EFCT_CMD_POLL , +/* command executes asynchronously. Uses callback */ +EFCT_CMD_NOWAIT , +}; + +enum efct_hw_rtn { +EFCT_HW_RTN_SUCCESS =0 , +EFCT_HW_RTN_SUCCESS_SYNC =1 , +EFCT_HW_RTN_ERROR =-1 , +EFCT_HW_RTN_NO_RESOURCES =-2 , +EFCT_HW_RTN_NO_MEMORY =-3 , +EFCT_HW_RTN_IO_NOT_ACTIVE =-4 , +EFCT_HW_RTN_IO_ABORT_IN_PROGRESS =-5 , +EFCT_HW_RTN_IO_PORT_OWNED_ALREADY_ABORTED =-6 , +EFCT_HW_RTN_INVALID_ARG =-7 , +}; + +#define EFCT_HW_RTN_IS_ERROR (e) ((e) < 0) + +enum efct_hw_reset { +EFCT_HW_RESET_FUNCTION , +EFCT_HW_RESET_FIRMWARE , +EFCT_HW_RESET_MAX +}; + +enum efct_hw_topo { +EFCT_HW_TOPOLOGY_AUTO , +EFCT_HW_TOPOLOGY_NPORT , +EFCT_HW_TOPOLOGY_LOOP , +EFCT_HW_TOPOLOGY_NONE , +EFCT_HW_TOPOLOGY_MAX +}; + +/* pack fw revision values into a single uint64_t */ +#define HW_FWREV (a, b, c, d) (((uint64_t)(a) << 48) | ((uint64_t)(b) << 32) \ + | ((uint64_t)(c) << 16) | ((uint64_t)(d))) + +#define EFCT_FW_VER_STR (a, b, c, d) (#a "." #b "." #c "." #d) + +enum efct_hw_io_type { +EFCT_HW_ELS_REQ , +EFCT_HW_ELS_RSP , +EFCT_HW_ELS_RSP_SID , +EFCT_HW_FC_CT , +EFCT_HW_FC_CT_RSP , +EFCT_HW_BLS_ACC , +EFCT_HW_BLS_ACC_SID , +EFCT_HW_BLS_RJT , +EFCT_HW_IO_TARGET_READ , +EFCT_HW_IO_TARGET_WRITE , +EFCT_HW_IO_TARGET_RSP , +EFCT_HW_IO_DNRX_REQUEUE , +EFCT_HW_IO_MAX , +}; + +enum efct_hw_io_state { +EFCT_HW_IO_STATE_FREE , +EFCT_HW_IO_STATE_INUSE , +EFCT_HW_IO_STATE_WAIT_FREE , +EFCT_HW_IO_STATE_WAIT_SEC_HIO , +}; + +struct efct_hw ; + +/** +* HW command context. +* Stores the state for the asynchronous commands sent to the hardware. +*/ +struct efct_command_ctx { +struct list_head list_entry; +int (*cb)(struct efct_hw *hw,int status,u8 *mqe,void *arg); +void *arg;/* Argument for callback */ +u8 *buf;/* buffer holding command / results */ +void *ctx;/* upper layer context */ +}; + +struct efct_hw_sgl { +uintptr_t addr; +size_t len; +}; + +union efct_hw_io_param_u { +struct sli_bls_params bls; +struct sli_els_params els; +struct sli_ct_params fc_ct; +struct sli_fcp_tgt_params fcp_tgt; +}; + +/* WQ steering mode */ +enum efct_hw_wq_steering { +EFCT_HW_WQ_STEERING_CLASS , +EFCT_HW_WQ_STEERING_REQUEST , +EFCT_HW_WQ_STEERING_CPU , +}; + +/* HW wqe object */ +struct efct_hw_wqe { +struct list_head list_entry; +bool abort_wqe_submit_needed; +bool send_abts; +u32 id; +u32 abort_reqtag; +u8 *wqebuf; +}; + +/** +* HW IO object. +* +* Stores the per-IO information necessary +* for both the lower (SLI) and upper +* layers (efct). +*/ +struct efct_hw_io { +/* Owned by HW */ + +/* reference counter and callback function */ +struct kref ref; +void (*release)(struct kref *arg); +/* used for busy, wait_free, free lists */ +struct list_head list_entry; +/* used for timed_wqe list */ +struct list_head wqe_link; +/* used for io posted dnrx list */ +struct list_head dnrx_link; +/* state of IO: free, busy, wait_free */ +enum efct_hw_io_state state; +/* Work queue object, with link for pending */ +struct efct_hw_wqe wqe; +/* pointer back to hardware context */ +struct efct_hw *hw; +struct efc_remote_node *rnode; +struct efc_dma xfer_rdy; +u16 type; +/* WQ assigned to the exchange */ +struct hw_wq *wq; +/* Exchange is active in FW */ +bool xbusy; +/* Function called on IO completion */ +int + (*done)(struct efct_hw_io *hio, +struct efc_remote_node *rnode, +u32 len,int status, +u32 ext,void *ul_arg); +/* argument passed to "IO done" callback */ +void *arg; +/* Function called on abort completion */ +int + (*abort_done)(struct efct_hw_io *hio, +struct efc_remote_node *rnode, +u32 len,int status, +u32 ext,void *ul_arg); +/* argument passed to "abort done" callback */ +void *abort_arg; +/* needed for bug O127585: length of IO */ +size_t length; +/* timeout value for target WQEs */ +u8 tgt_wqe_timeout; +/* timestamp when current WQE was submitted */ +u64 submit_ticks; + +/* if TRUE, latched status shld be returned */ +bool status_saved; +/* if TRUE, abort is in progress */ +bool abort_in_progress; +u32 saved_status; +u32 saved_len; +u32 saved_ext; + +/* EQ that this HIO came up on */ +struct hw_eq *eq; +/* WQ steering mode request */ +enum efct_hw_wq_steering wq_steering; +/* WQ class if steering mode is Class */ +u8 wq_class; + +/* request tag for this HW IO */ +u16 reqtag; +/* request tag for an abort of this HW IO +* (note: this is a 32 bit value +* to allow us to use UINT32_MAX as an uninitialized value) +*/ +u32 abort_reqtag; +u32 indicator;/* XRI */ +struct efc_dma def_sgl;/* default SGL*/ +/* Count of SGEs in default SGL */ +u32 def_sgl_count; +/* pointer to current active SGL */ +struct efc_dma *sgl; +u32 sgl_count;/* count of SGEs in io->sgl */ +u32 first_data_sge;/* index of first data SGE */ +struct efc_dma *ovfl_sgl;/* overflow SGL */ +u32 ovfl_sgl_count; +/* pointer to overflow segment len */ +struct sli4_lsp_sge *ovfl_lsp; +u32 n_sge;/* number of active SGEs */ +u32 sge_offset; + +/* where upper layer can store ref to its IO */ +void *ul_io; +}; + +/* Typedef for HW "done" callback */ +typedef int (*efct_hw_done_t )(struct efct_hw_io *,struct efc_remote_node *, +u32 len,int status,u32 ext,void *ul_arg); + +enum efct_hw_port { +EFCT_HW_PORT_INIT , +EFCT_HW_PORT_SHUTDOWN , +}; + +/* Node group rpi reference */ +struct efct_hw_rpi_ref { +atomic_t rpi_count; +atomic_t rpi_attached; +}; + +enum efct_hw_link_stat { +EFCT_HW_LINK_STAT_LINK_FAILURE_COUNT , +EFCT_HW_LINK_STAT_LOSS_OF_SYNC_COUNT , +EFCT_HW_LINK_STAT_LOSS_OF_SIGNAL_COUNT , +EFCT_HW_LINK_STAT_PRIMITIVE_SEQ_COUNT , +EFCT_HW_LINK_STAT_INVALID_XMIT_WORD_COUNT , +EFCT_HW_LINK_STAT_CRC_COUNT , +EFCT_HW_LINK_STAT_PRIMITIVE_SEQ_TIMEOUT_COUNT , +EFCT_HW_LINK_STAT_ELASTIC_BUFFER_OVERRUN_COUNT , +EFCT_HW_LINK_STAT_ARB_TIMEOUT_COUNT , +EFCT_HW_LINK_STAT_ADVERTISED_RCV_B2B_CREDIT , +EFCT_HW_LINK_STAT_CURR_RCV_B2B_CREDIT , +EFCT_HW_LINK_STAT_ADVERTISED_XMIT_B2B_CREDIT , +EFCT_HW_LINK_STAT_CURR_XMIT_B2B_CREDIT , +EFCT_HW_LINK_STAT_RCV_EOFA_COUNT , +EFCT_HW_LINK_STAT_RCV_EOFDTI_COUNT , +EFCT_HW_LINK_STAT_RCV_EOFNI_COUNT , +EFCT_HW_LINK_STAT_RCV_SOFF_COUNT , +EFCT_HW_LINK_STAT_RCV_DROPPED_NO_AER_COUNT , +EFCT_HW_LINK_STAT_RCV_DROPPED_NO_RPI_COUNT , +EFCT_HW_LINK_STAT_RCV_DROPPED_NO_XRI_COUNT , +EFCT_HW_LINK_STAT_MAX , +}; + +enum efct_hw_host_stat { +EFCT_HW_HOST_STAT_TX_KBYTE_COUNT , +EFCT_HW_HOST_STAT_RX_KBYTE_COUNT , +EFCT_HW_HOST_STAT_TX_FRAME_COUNT , +EFCT_HW_HOST_STAT_RX_FRAME_COUNT , +EFCT_HW_HOST_STAT_TX_SEQ_COUNT , +EFCT_HW_HOST_STAT_RX_SEQ_COUNT , +EFCT_HW_HOST_STAT_TOTAL_EXCH_ORIG , +EFCT_HW_HOST_STAT_TOTAL_EXCH_RESP , +EFCT_HW_HOSY_STAT_RX_P_BSY_COUNT , +EFCT_HW_HOST_STAT_RX_F_BSY_COUNT , +EFCT_HW_HOST_STAT_DROP_FRM_DUE_TO_NO_RQ_BUF_COUNT , +EFCT_HW_HOST_STAT_EMPTY_RQ_TIMEOUT_COUNT , +EFCT_HW_HOST_STAT_DROP_FRM_DUE_TO_NO_XRI_COUNT , +EFCT_HW_HOST_STAT_EMPTY_XRI_POOL_COUNT , +EFCT_HW_HOST_STAT_MAX , +}; + +enum efct_hw_state { +EFCT_HW_STATE_UNINITIALIZED , +EFCT_HW_STATE_QUEUES_ALLOCATED , +EFCT_HW_STATE_ACTIVE , +EFCT_HW_STATE_RESET_IN_PROGRESS , +EFCT_HW_STATE_TEARDOWN_IN_PROGRESS , +}; + +struct efct_hw_link_stat_counts { +u8 overflow; +u32 counter; +}; + +struct efct_hw_host_stat_counts { +u32 counter; +}; + +/* Structure used for the hash lookup of queue IDs */ +struct efct_queue_hash { +bool in_use; +u16 id; +u16 index; +}; + +/* WQ callback object */ +struct hw_wq_callback { +u16 instance_index;/* use for request tag */ +void (*callback)(void *arg,u8 *cqe,int status); +void *arg; +struct list_head list_entry; +}; + +struct reqtag_pool { +spinlock_t lock;/* pool lock */ +struct hw_wq_callback *tags[U16_MAX ]; +struct list_head freelist; +}; + +struct efct_hw_config { +u32 n_eq; +u32 n_cq; +u32 n_mq; +u32 n_rq; +u32 n_wq; +u32 n_io; +u32 n_sgl; +u32 speed; +u32 topology; +/* size of the buffers for first burst */ +u32 rq_default_buffer_size; +u8 esoc; +/* MRQ RQ selection policy */ +u8 rq_selection_policy; +/* RQ quanta if rq_selection_policy == 2 */ +u8 rr_quanta; +u32 filter_def[SLI4_CMD_REG_FCFI_NUM_RQ_CFG ]; +}; + +struct efct_hw { +struct efct *os; +struct sli4 sli; +u16 ulp_start; +u16 ulp_max; +u32 dump_size; +enum efct_hw_state state; +bool hw_setup_called; +u8 sliport_healthcheck; + +/* HW configuration */ +struct efct_hw_config config; + +/* calculated queue sizes for each type */ +u32 num_qentries[SLI_QTYPE_MAX ]; + +/* Storage for SLI queue objects */ +struct sli4_queue wq[EFCT_HW_MAX_NUM_WQ ]; +struct sli4_queue rq[EFCT_HW_MAX_NUM_RQ ]; +u16 hw_rq_lookup[EFCT_HW_MAX_NUM_RQ ]; +struct sli4_queue mq[EFCT_HW_MAX_NUM_MQ ]; +struct sli4_queue cq[EFCT_HW_MAX_NUM_CQ ]; +struct sli4_queue eq[EFCT_HW_MAX_NUM_EQ ]; + +/* HW queue */ +u32 eq_count; +u32 cq_count; +u32 mq_count; +u32 wq_count; +u32 rq_count; +struct list_head eq_list; + +struct efct_queue_hash cq_hash[EFCT_HW_Q_HASH_SIZE ]; +struct efct_queue_hash rq_hash[EFCT_HW_Q_HASH_SIZE ]; +struct efct_queue_hash wq_hash[EFCT_HW_Q_HASH_SIZE ]; + +/* Storage for HW queue objects */ +struct hw_wq *hw_wq[EFCT_HW_MAX_NUM_WQ ]; +struct hw_rq *hw_rq[EFCT_HW_MAX_NUM_RQ ]; +struct hw_mq *hw_mq[EFCT_HW_MAX_NUM_MQ ]; +struct hw_cq *hw_cq[EFCT_HW_MAX_NUM_CQ ]; +struct hw_eq *hw_eq[EFCT_HW_MAX_NUM_EQ ]; +/* count of hw_rq[] entries */ +u32 hw_rq_count; +/* count of multirq RQs */ +u32 hw_mrq_count; + +/* Sequence objects used in incoming frame processing */ +void *seq_pool; + +/* Maintain an ordered, linked list of outstanding HW commands. */ +spinlock_t cmd_lock; +struct list_head cmd_head; +struct list_head cmd_pending; +u32 cmd_head_count; + +struct sli4_link_event link; +struct efc_domain *domain; + +u16 fcf_indicator; + +/* pointer array of IO objects */ +struct efct_hw_io **io; +/* array of WQE buffs mapped to IO objects */ +u8 *wqe_buffs; + +/* IO lock to synchronize list access */ +spinlock_t io_lock; +/* IO lock to synchronize IO aborting */ +spinlock_t io_abort_lock; +/* List of IO objects in use */ +struct list_head io_inuse; +/* List of IO objects waiting to be freed */ +struct list_head io_wait_free; +/* List of IO objects available for allocation */ +struct list_head io_free; + +struct efc_dma loop_map; + +struct efc_dma xfer_rdy; + +struct efc_dma dump_sges; + +struct efc_dma rnode_mem; + +struct efct_hw_rpi_ref *rpi_ref; + +atomic_t io_alloc_failed_count; + +/* stat: wq sumbit count */ +u32 tcmd_wq_submit[EFCT_HW_MAX_NUM_WQ ]; +/* stat: wq complete count */ +u32 tcmd_wq_complete[EFCT_HW_MAX_NUM_WQ ]; + +struct reqtag_pool *wq_reqtag_pool; +atomic_t send_frame_seq_id; +}; + +enum efct_hw_io_count_type { +EFCT_HW_IO_INUSE_COUNT , +EFCT_HW_IO_FREE_COUNT , +EFCT_HW_IO_WAIT_FREE_COUNT , +EFCT_HW_IO_N_TOTAL_IO_COUNT , +}; + +/* HW queue data structures */ +struct hw_eq { +struct list_head list_entry; +enum sli4_qtype type; +u32 instance; +u32 entry_count; +u32 entry_size; +struct efct_hw *hw; +struct sli4_queue *queue; +struct list_head cq_list; +u32 use_count; +}; + +struct hw_cq { +struct list_head list_entry; +enum sli4_qtype type; +u32 instance; +u32 entry_count; +u32 entry_size; +struct hw_eq *eq; +struct sli4_queue *queue; +struct list_head q_list; +u32 use_count; +}; + +struct hw_q { +struct list_head list_entry; +enum sli4_qtype type; +}; + +struct hw_mq { +struct list_head list_entry; +enum sli4_qtype type; +u32 instance; + +u32 entry_count; +u32 entry_size; +struct hw_cq *cq; +struct sli4_queue *queue; + +u32 use_count; +}; + +struct hw_wq { +struct list_head list_entry; +enum sli4_qtype type; +u32 instance; +struct efct_hw *hw; + +u32 entry_count; +u32 entry_size; +struct hw_cq *cq; +struct sli4_queue *queue; +u32 class; + +/* WQ consumed */ +u32 wqec_set_count; +u32 wqec_count; +u32 free_count; +u32 total_submit_count; +struct list_head pending_list; + +/* HW IO allocated for use with Send Frame */ +struct efct_hw_io *send_frame_io; + +/* Stats */ +u32 use_count; +u32 wq_pending_count; +}; + +struct hw_rq { +struct list_head list_entry; +enum sli4_qtype type; +u32 instance; + +u32 entry_count; +u32 use_count; +u32 hdr_entry_size; +u32 first_burst_entry_size; +u32 data_entry_size; +bool is_mrq; +u32 base_mrq_id; + +struct hw_cq *cq; + +u8 filter_mask; +struct sli4_queue *hdr; +struct sli4_queue *first_burst; +struct sli4_queue *data; + +struct efc_hw_rq_buffer *hdr_buf; +struct efc_hw_rq_buffer *fb_buf; +struct efc_hw_rq_buffer *payload_buf; +/* RQ tracker for this RQ */ +struct efc_hw_sequence **rq_tracker; +}; + +struct efct_hw_send_frame_context { +struct efct_hw *hw; +struct hw_wq_callback *wqcb; +struct efct_hw_wqe wqe; +void (*callback)(int status,void *arg); +void *arg; + +/* General purpose elements */ +struct efc_hw_sequence *seq; +struct efc_dma payload; +}; + +struct efct_hw_grp_hdr { +u32 size; +__be32 magic_number; +u32 word2; +u8 rev_name[128 ]; +u8 date[12 ]; +u8 revision[32 ]; +}; + +#endif /* __EFCT_H__ */
Signature · 1 line
2.16.4
Re: [PATCH v3 15/31] elx: efct: Data structures and defines for hw operations
Quoted 297 lines · James Smart
This patch starts the population of the efct target mode driver. The driver is contained in the
drivers/scsi/elx/efctsubdirectory.This patch creates the efct directory and starts population of the driver by adding SLI-4 configuration parameters, data structures for configuring SLI-4 queues, converting from os to SLI-4 IO requests, and handling async events.
Signed-off-by Ram Vegesna <[email protected]>Signed-off-by James Smart <[email protected]>---
v3:
Changed anonymous enums to named.
Removed some structures and defines which are not used. Reworked onefct_hw_io_paramstruct which can be used for holding
params in WQE submission.--- drivers/scsi/elx/efct/efct_hw.h | 617 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 617 insertions(+)create mode 100644
drivers/scsi/elx/efct/efct_hw.hdrivers/scsi/elx/efct/efct_hw.h new file +268
-0@@ -0,0 +1,617 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2019 Broadcom. All Rights Reserved. The term +* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +*/ + +#ifndef _EFCT_HW_H +#define _EFCT_HW_H + +#include "../libefc_sli/sli4.h" + +/* + * EFCT PCI IDs + */ +#define EFCT_VENDOR_ID 0x10df +/* LightPulse 16Gb x 4 FC (lancer-g6) */ +#define EFCT_DEVICE_LANCER_G6 0xe307 +/* LightPulse 32Gb x 4 FC (lancer-g7) */ +#define EFCT_DEVICE_LANCER_G7 0xf407 + +/*Default RQ entries len used by driver*/ +#define EFCT_HW_RQ_ENTRIES_MIN 512 +#define EFCT_HW_RQ_ENTRIES_DEF 1024 +#define EFCT_HW_RQ_ENTRIES_MAX 4096 + +/*Defines the size of the RQ buffers used for each RQ*/ +#define EFCT_HW_RQ_SIZE_HDR 128 +#define EFCT_HW_RQ_SIZE_PAYLOAD 1024 + +/*Define the maximum number of multi-receive queues*/ +#define EFCT_HW_MAX_MRQS 8 + +/* + * Define count of when to set the WQEC bit in a submitted + * WQE, causing a consummed/released completion to be posted. + */ +#define EFCT_HW_WQEC_SET_COUNT 32 + +/*Send frame timeout in seconds*/ +#define EFCT_HW_SEND_FRAME_TIMEOUT 10 + +/* + * FDT Transfer Hint value, reads greater than this value + * will be segmented to implement fairness. A value of zero disables + * the feature. + */ +#define EFCT_HW_FDT_XFER_HINT 8192 + +#define EFCT_HW_TIMECHECK_ITERATIONS 100 +#define EFCT_HW_MAX_NUM_MQ 1 +#define EFCT_HW_MAX_NUM_RQ 32 +#define EFCT_HW_MAX_NUM_EQ 16 +#define EFCT_HW_MAX_NUM_WQ 32 +#define EFCT_HW_DEF_NUM_EQ 1 + +#define OCE_HW_MAX_NUM_MRQ_PAIRS 16 + +#define EFCT_HW_MQ_DEPTH 128 +#define EFCT_HW_EQ_DEPTH 1024 + +/* + * A CQ will be assinged to each WQ + * (CQ must have 2X entries of the WQ for abort + * processing), plus a separate one for each RQ PAIR and one for MQ + */ +#define EFCT_HW_MAX_NUM_CQ \ + ((EFCT_HW_MAX_NUM_WQ * 2) + 1 + (OCE_HW_MAX_NUM_MRQ_PAIRS * 2)) + +#define EFCT_HW_Q_HASH_SIZE 128 +#define EFCT_HW_RQ_HEADER_SIZE 128 +#define EFCT_HW_RQ_HEADER_INDEX 0 + +#define EFCT_HW_REQUE_XRI_REGTAG 65534 + +/* Options for efct_hw_command() */ +enum efct_cmd_opts { + /* command executes synchronously and busy-waits for completion */ + EFCT_CMD_POLL, + /* command executes asynchronously. Uses callback */ + EFCT_CMD_NOWAIT, +}; + +enum efct_hw_rtn { + EFCT_HW_RTN_SUCCESS = 0, + EFCT_HW_RTN_SUCCESS_SYNC = 1, + EFCT_HW_RTN_ERROR = -1, + EFCT_HW_RTN_NO_RESOURCES = -2, + EFCT_HW_RTN_NO_MEMORY = -3, + EFCT_HW_RTN_IO_NOT_ACTIVE = -4, + EFCT_HW_RTN_IO_ABORT_IN_PROGRESS = -5, + EFCT_HW_RTN_IO_PORT_OWNED_ALREADY_ABORTED = -6, + EFCT_HW_RTN_INVALID_ARG = -7, +}; + +#define EFCT_HW_RTN_IS_ERROR(e) ((e) < 0) + +enum efct_hw_reset { + EFCT_HW_RESET_FUNCTION, + EFCT_HW_RESET_FIRMWARE, + EFCT_HW_RESET_MAX +}; + +enum efct_hw_topo { + EFCT_HW_TOPOLOGY_AUTO, + EFCT_HW_TOPOLOGY_NPORT, + EFCT_HW_TOPOLOGY_LOOP, + EFCT_HW_TOPOLOGY_NONE, + EFCT_HW_TOPOLOGY_MAX +}; + +/* pack fw revision values into a single uint64_t */ +#define HW_FWREV(a, b, c, d) (((uint64_t)(a) << 48) | ((uint64_t)(b) << 32) \ + | ((uint64_t)(c) << 16) | ((uint64_t)(d))) + +#define EFCT_FW_VER_STR(a, b, c, d) (#a "." #b "." #c "." #d) + +enum efct_hw_io_type { + EFCT_HW_ELS_REQ, + EFCT_HW_ELS_RSP, + EFCT_HW_ELS_RSP_SID, + EFCT_HW_FC_CT, + EFCT_HW_FC_CT_RSP, + EFCT_HW_BLS_ACC, + EFCT_HW_BLS_ACC_SID, + EFCT_HW_BLS_RJT, + EFCT_HW_IO_TARGET_READ, + EFCT_HW_IO_TARGET_WRITE, + EFCT_HW_IO_TARGET_RSP, + EFCT_HW_IO_DNRX_REQUEUE, + EFCT_HW_IO_MAX, +}; + +enum efct_hw_io_state { + EFCT_HW_IO_STATE_FREE, + EFCT_HW_IO_STATE_INUSE, + EFCT_HW_IO_STATE_WAIT_FREE, + EFCT_HW_IO_STATE_WAIT_SEC_HIO, +}; + +struct efct_hw; + +/** + * HW command context. + * Stores the state for the asynchronous commands sent to the hardware. + */ +struct efct_command_ctx { + struct list_head list_entry; + int (*cb)(struct efct_hw *hw, int status, u8 *mqe, void *arg); + void *arg; /* Argument for callback */ + u8 *buf; /* buffer holding command / results */ + void *ctx; /* upper layer context */ +}; + +struct efct_hw_sgl { + uintptr_t addr; + size_t len; +}; + +union efct_hw_io_param_u { + struct sli_bls_params bls; + struct sli_els_params els; + struct sli_ct_params fc_ct; + struct sli_fcp_tgt_params fcp_tgt; +}; + +/* WQ steering mode */ +enum efct_hw_wq_steering { + EFCT_HW_WQ_STEERING_CLASS, + EFCT_HW_WQ_STEERING_REQUEST, + EFCT_HW_WQ_STEERING_CPU, +}; + +/* HW wqe object */ +struct efct_hw_wqe { + struct list_head list_entry; + bool abort_wqe_submit_needed; + bool send_abts; + u32 id; + u32 abort_reqtag; + u8 *wqebuf; +}; + +/** + * HW IO object. + * + * Stores the per-IO information necessary + * for both the lower (SLI) and upper + * layers (efct). + */ +struct efct_hw_io { + /* Owned by HW */ + + /* reference counter and callback function */ + struct kref ref; + void (*release)(struct kref *arg); + /* used for busy, wait_free, free lists */ + struct list_head list_entry; + /* used for timed_wqe list */ + struct list_head wqe_link; + /* used for io posted dnrx list */ + struct list_head dnrx_link; + /* state of IO: free, busy, wait_free */ + enum efct_hw_io_state state; + /* Work queue object, with link for pending */ + struct efct_hw_wqe wqe; + /* pointer back to hardware context */ + struct efct_hw *hw; + struct efc_remote_node *rnode; + struct efc_dma xfer_rdy; + u16 type; + /* WQ assigned to the exchange */ + struct hw_wq *wq; + /* Exchange is active in FW */ + bool xbusy; + /* Function called on IO completion */ + int + (*done)(struct efct_hw_io *hio, + struct efc_remote_node *rnode, + u32 len, int status, + u32 ext, void *ul_arg); + /* argument passed to "IO done" callback */ + void *arg; + /* Function called on abort completion */ + int + (*abort_done)(struct efct_hw_io *hio, + struct efc_remote_node *rnode, + u32 len, int status, + u32 ext, void *ul_arg); + /* argument passed to "abort done" callback */ + void *abort_arg; + /* needed for bug O127585: length of IO */ + size_t length; + /* timeout value for target WQEs */ + u8 tgt_wqe_timeout; + /* timestamp when current WQE was submitted */ + u64 submit_ticks; + + /* if TRUE, latched status shld be returned */ + bool status_saved; + /* if TRUE, abort is in progress */ + bool abort_in_progress; + u32 saved_status; + u32 saved_len; + u32 saved_ext; + + /* EQ that this HIO came up on */ + struct hw_eq *eq; + /* WQ steering mode request */ + enum efct_hw_wq_steering wq_steering; + /* WQ class if steering mode is Class */ + u8 wq_class; + + /* request tag for this HW IO */ + u16 reqtag; + /* request tag for an abort of this HW IO + * (note: this is a 32 bit value + * to allow us to use UINT32_MAX as an uninitialized value) + */ + u32 abort_reqtag; + u32 indicator; /* XRI */ + struct efc_dma def_sgl; /* default SGL*/ + /* Count of SGEs in default SGL */ + u32 def_sgl_count; + /* pointer to current active SGL */ + struct efc_dma *sgl; + u32 sgl_count; /* count of SGEs in io->sgl */ + u32 first_data_sge; /* index of first data SGE */ + struct efc_dma *ovfl_sgl; /* overflow SGL */
drivers/scsi/elx/efct/efct_hw.h line 278
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw.h new file +10
-0+u32 ovfl_sgl_count; +/* pointer to overflow segment len */ +struct sli4_lsp_sge *ovfl_lsp; +u32 n_sge;/* number of active SGEs */ +u32 sge_offset; + +/* where upper layer can store ref to its IO */ +void *ul_io; +}; +
Please consider running 'pahole' on this structure and rearrange it. Looks like it'll required quite some padding which could be avoided.
Quoted 330 lines
drivers/scsi/elx/efct/efct_hw.h new file +329
-0+/* Typedef for HW "done" callback */ +typedef int (*efct_hw_done_t )(struct efct_hw_io *,struct efc_remote_node *, +u32 len,int status,u32 ext,void *ul_arg); + +enum efct_hw_port { +EFCT_HW_PORT_INIT , +EFCT_HW_PORT_SHUTDOWN , +}; + +/* Node group rpi reference */ +struct efct_hw_rpi_ref { +atomic_t rpi_count; +atomic_t rpi_attached; +}; + +enum efct_hw_link_stat { +EFCT_HW_LINK_STAT_LINK_FAILURE_COUNT , +EFCT_HW_LINK_STAT_LOSS_OF_SYNC_COUNT , +EFCT_HW_LINK_STAT_LOSS_OF_SIGNAL_COUNT , +EFCT_HW_LINK_STAT_PRIMITIVE_SEQ_COUNT , +EFCT_HW_LINK_STAT_INVALID_XMIT_WORD_COUNT , +EFCT_HW_LINK_STAT_CRC_COUNT , +EFCT_HW_LINK_STAT_PRIMITIVE_SEQ_TIMEOUT_COUNT , +EFCT_HW_LINK_STAT_ELASTIC_BUFFER_OVERRUN_COUNT , +EFCT_HW_LINK_STAT_ARB_TIMEOUT_COUNT , +EFCT_HW_LINK_STAT_ADVERTISED_RCV_B2B_CREDIT , +EFCT_HW_LINK_STAT_CURR_RCV_B2B_CREDIT , +EFCT_HW_LINK_STAT_ADVERTISED_XMIT_B2B_CREDIT , +EFCT_HW_LINK_STAT_CURR_XMIT_B2B_CREDIT , +EFCT_HW_LINK_STAT_RCV_EOFA_COUNT , +EFCT_HW_LINK_STAT_RCV_EOFDTI_COUNT , +EFCT_HW_LINK_STAT_RCV_EOFNI_COUNT , +EFCT_HW_LINK_STAT_RCV_SOFF_COUNT , +EFCT_HW_LINK_STAT_RCV_DROPPED_NO_AER_COUNT , +EFCT_HW_LINK_STAT_RCV_DROPPED_NO_RPI_COUNT , +EFCT_HW_LINK_STAT_RCV_DROPPED_NO_XRI_COUNT , +EFCT_HW_LINK_STAT_MAX , +}; + +enum efct_hw_host_stat { +EFCT_HW_HOST_STAT_TX_KBYTE_COUNT , +EFCT_HW_HOST_STAT_RX_KBYTE_COUNT , +EFCT_HW_HOST_STAT_TX_FRAME_COUNT , +EFCT_HW_HOST_STAT_RX_FRAME_COUNT , +EFCT_HW_HOST_STAT_TX_SEQ_COUNT , +EFCT_HW_HOST_STAT_RX_SEQ_COUNT , +EFCT_HW_HOST_STAT_TOTAL_EXCH_ORIG , +EFCT_HW_HOST_STAT_TOTAL_EXCH_RESP , +EFCT_HW_HOSY_STAT_RX_P_BSY_COUNT , +EFCT_HW_HOST_STAT_RX_F_BSY_COUNT , +EFCT_HW_HOST_STAT_DROP_FRM_DUE_TO_NO_RQ_BUF_COUNT , +EFCT_HW_HOST_STAT_EMPTY_RQ_TIMEOUT_COUNT , +EFCT_HW_HOST_STAT_DROP_FRM_DUE_TO_NO_XRI_COUNT , +EFCT_HW_HOST_STAT_EMPTY_XRI_POOL_COUNT , +EFCT_HW_HOST_STAT_MAX , +}; + +enum efct_hw_state { +EFCT_HW_STATE_UNINITIALIZED , +EFCT_HW_STATE_QUEUES_ALLOCATED , +EFCT_HW_STATE_ACTIVE , +EFCT_HW_STATE_RESET_IN_PROGRESS , +EFCT_HW_STATE_TEARDOWN_IN_PROGRESS , +}; + +struct efct_hw_link_stat_counts { +u8 overflow; +u32 counter; +}; + +struct efct_hw_host_stat_counts { +u32 counter; +}; + +/* Structure used for the hash lookup of queue IDs */ +struct efct_queue_hash { +bool in_use; +u16 id; +u16 index; +}; + +/* WQ callback object */ +struct hw_wq_callback { +u16 instance_index;/* use for request tag */ +void (*callback)(void *arg,u8 *cqe,int status); +void *arg; +struct list_head list_entry; +}; + +struct reqtag_pool { +spinlock_t lock;/* pool lock */ +struct hw_wq_callback *tags[U16_MAX ]; +struct list_head freelist; +}; + +struct efct_hw_config { +u32 n_eq; +u32 n_cq; +u32 n_mq; +u32 n_rq; +u32 n_wq; +u32 n_io; +u32 n_sgl; +u32 speed; +u32 topology; +/* size of the buffers for first burst */ +u32 rq_default_buffer_size; +u8 esoc; +/* MRQ RQ selection policy */ +u8 rq_selection_policy; +/* RQ quanta if rq_selection_policy == 2 */ +u8 rr_quanta; +u32 filter_def[SLI4_CMD_REG_FCFI_NUM_RQ_CFG ]; +}; + +struct efct_hw { +struct efct *os; +struct sli4 sli; +u16 ulp_start; +u16 ulp_max; +u32 dump_size; +enum efct_hw_state state; +bool hw_setup_called; +u8 sliport_healthcheck; + +/* HW configuration */ +struct efct_hw_config config; + +/* calculated queue sizes for each type */ +u32 num_qentries[SLI_QTYPE_MAX ]; + +/* Storage for SLI queue objects */ +struct sli4_queue wq[EFCT_HW_MAX_NUM_WQ ]; +struct sli4_queue rq[EFCT_HW_MAX_NUM_RQ ]; +u16 hw_rq_lookup[EFCT_HW_MAX_NUM_RQ ]; +struct sli4_queue mq[EFCT_HW_MAX_NUM_MQ ]; +struct sli4_queue cq[EFCT_HW_MAX_NUM_CQ ]; +struct sli4_queue eq[EFCT_HW_MAX_NUM_EQ ]; + +/* HW queue */ +u32 eq_count; +u32 cq_count; +u32 mq_count; +u32 wq_count; +u32 rq_count; +struct list_head eq_list; + +struct efct_queue_hash cq_hash[EFCT_HW_Q_HASH_SIZE ]; +struct efct_queue_hash rq_hash[EFCT_HW_Q_HASH_SIZE ]; +struct efct_queue_hash wq_hash[EFCT_HW_Q_HASH_SIZE ]; + +/* Storage for HW queue objects */ +struct hw_wq *hw_wq[EFCT_HW_MAX_NUM_WQ ]; +struct hw_rq *hw_rq[EFCT_HW_MAX_NUM_RQ ]; +struct hw_mq *hw_mq[EFCT_HW_MAX_NUM_MQ ]; +struct hw_cq *hw_cq[EFCT_HW_MAX_NUM_CQ ]; +struct hw_eq *hw_eq[EFCT_HW_MAX_NUM_EQ ]; +/* count of hw_rq[] entries */ +u32 hw_rq_count; +/* count of multirq RQs */ +u32 hw_mrq_count; + +/* Sequence objects used in incoming frame processing */ +void *seq_pool; + +/* Maintain an ordered, linked list of outstanding HW commands. */ +spinlock_t cmd_lock; +struct list_head cmd_head; +struct list_head cmd_pending; +u32 cmd_head_count; + +struct sli4_link_event link; +struct efc_domain *domain; + +u16 fcf_indicator; + +/* pointer array of IO objects */ +struct efct_hw_io **io; +/* array of WQE buffs mapped to IO objects */ +u8 *wqe_buffs; + +/* IO lock to synchronize list access */ +spinlock_t io_lock; +/* IO lock to synchronize IO aborting */ +spinlock_t io_abort_lock; +/* List of IO objects in use */ +struct list_head io_inuse; +/* List of IO objects waiting to be freed */ +struct list_head io_wait_free; +/* List of IO objects available for allocation */ +struct list_head io_free; + +struct efc_dma loop_map; + +struct efc_dma xfer_rdy; + +struct efc_dma dump_sges; + +struct efc_dma rnode_mem; + +struct efct_hw_rpi_ref *rpi_ref; + +atomic_t io_alloc_failed_count; + +/* stat: wq sumbit count */ +u32 tcmd_wq_submit[EFCT_HW_MAX_NUM_WQ ]; +/* stat: wq complete count */ +u32 tcmd_wq_complete[EFCT_HW_MAX_NUM_WQ ]; + +struct reqtag_pool *wq_reqtag_pool; +atomic_t send_frame_seq_id; +}; + +enum efct_hw_io_count_type { +EFCT_HW_IO_INUSE_COUNT , +EFCT_HW_IO_FREE_COUNT , +EFCT_HW_IO_WAIT_FREE_COUNT , +EFCT_HW_IO_N_TOTAL_IO_COUNT , +}; + +/* HW queue data structures */ +struct hw_eq { +struct list_head list_entry; +enum sli4_qtype type; +u32 instance; +u32 entry_count; +u32 entry_size; +struct efct_hw *hw; +struct sli4_queue *queue; +struct list_head cq_list; +u32 use_count; +}; + +struct hw_cq { +struct list_head list_entry; +enum sli4_qtype type; +u32 instance; +u32 entry_count; +u32 entry_size; +struct hw_eq *eq; +struct sli4_queue *queue; +struct list_head q_list; +u32 use_count; +}; + +struct hw_q { +struct list_head list_entry; +enum sli4_qtype type; +}; + +struct hw_mq { +struct list_head list_entry; +enum sli4_qtype type; +u32 instance; + +u32 entry_count; +u32 entry_size; +struct hw_cq *cq; +struct sli4_queue *queue; + +u32 use_count; +}; + +struct hw_wq { +struct list_head list_entry; +enum sli4_qtype type; +u32 instance; +struct efct_hw *hw; + +u32 entry_count; +u32 entry_size; +struct hw_cq *cq; +struct sli4_queue *queue; +u32 class; + +/* WQ consumed */ +u32 wqec_set_count; +u32 wqec_count; +u32 free_count; +u32 total_submit_count; +struct list_head pending_list; + +/* HW IO allocated for use with Send Frame */ +struct efct_hw_io *send_frame_io; + +/* Stats */ +u32 use_count; +u32 wq_pending_count; +}; + +struct hw_rq { +struct list_head list_entry; +enum sli4_qtype type; +u32 instance; + +u32 entry_count; +u32 use_count; +u32 hdr_entry_size; +u32 first_burst_entry_size; +u32 data_entry_size; +bool is_mrq; +u32 base_mrq_id; + +struct hw_cq *cq; + +u8 filter_mask; +struct sli4_queue *hdr; +struct sli4_queue *first_burst; +struct sli4_queue *data; + +struct efc_hw_rq_buffer *hdr_buf; +struct efc_hw_rq_buffer *fb_buf; +struct efc_hw_rq_buffer *payload_buf; +/* RQ tracker for this RQ */ +struct efc_hw_sequence **rq_tracker; +}; + +struct efct_hw_send_frame_context { +struct efct_hw *hw; +struct hw_wq_callback *wqcb; +struct efct_hw_wqe wqe; +void (*callback)(int status,void *arg); +void *arg; + +/* General purpose elements */ +struct efc_hw_sequence *seq; +struct efc_dma payload; +}; +
drivers/scsi/elx/efct/efct_hw.h line 617
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw.h new file +10
-0+struct efct_hw_grp_hdr { +u32 size; +__be32 magic_number; +u32 word2; +u8 rev_name[128 ]; +u8 date[12 ]; +u8 revision[32 ]; +}; + +#endif /* __EFCT_H__ */
Other than that:
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
Re: [PATCH v3 15/31] elx: efct: Data structures and defines for hw operations
On 4/15/2020 11:51 PM, Hannes Reinecke wrote:
...
Quoted 3 lines
Please consider running 'pahole' on this structure and rearrange it. Looks like it'll required quite some padding which could be avoided.
we will
Thanks.
-- james
Re: [PATCH v3 15/31] elx: efct: Data structures and defines for hw operations
In reply to James SmartQuoted 210 lines · James Smart
This patch starts the population of the efct target mode driver. The driver is contained in the
drivers/scsi/elx/efctsubdirectory.This patch creates the efct directory and starts population of the driver by adding SLI-4 configuration parameters, data structures for configuring SLI-4 queues, converting from os to SLI-4 IO requests, and handling async events.
Signed-off-by Ram Vegesna <[email protected]>Signed-off-by James Smart <[email protected]>---
v3:
Changed anonymous enums to named.
Removed some structures and defines which are not used. Reworked onefct_hw_io_paramstruct which can be used for holding
params in WQE submission.--- drivers/scsi/elx/efct/efct_hw.h | 617 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 617 insertions(+) create mode 100644 drivers/scsi/elx/efct/efct_hw.hdrivers/scsi/elx/efct/efct_hw.h new file +181
-0@@ -0,0 +1,617 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2019 Broadcom. All Rights Reserved. The term +* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +*/ + +#ifndef _EFCT_HW_H +#define _EFCT_HW_H + +#include "../libefc_sli/sli4.h" + +/* +* EFCT PCI IDs +*/ +#define EFCT_VENDOR_ID 0x10df +/* LightPulse 16Gb x 4 FC (lancer-g6) */ +#define EFCT_DEVICE_LANCER_G6 0xe307 +/* LightPulse 32Gb x 4 FC (lancer-g7) */ +#define EFCT_DEVICE_LANCER_G7 0xf407 + +/*Default RQ entries len used by driver*/ +#define EFCT_HW_RQ_ENTRIES_MIN 512 +#define EFCT_HW_RQ_ENTRIES_DEF 1024 +#define EFCT_HW_RQ_ENTRIES_MAX 4096 + +/*Defines the size of the RQ buffers used for each RQ*/ +#define EFCT_HW_RQ_SIZE_HDR 128 +#define EFCT_HW_RQ_SIZE_PAYLOAD 1024 + +/*Define the maximum number of multi-receive queues*/ +#define EFCT_HW_MAX_MRQS 8 + +/* +* Define count of when to set the WQEC bit in a submitted +* WQE, causing a consummed/released completion to be posted. +*/ +#define EFCT_HW_WQEC_SET_COUNT 32 + +/*Send frame timeout in seconds*/ +#define EFCT_HW_SEND_FRAME_TIMEOUT 10 + +/* +* FDT Transfer Hint value, reads greater than this value +* will be segmented to implement fairness. A value of zero disables +* the feature. +*/ +#define EFCT_HW_FDT_XFER_HINT 8192 + +#define EFCT_HW_TIMECHECK_ITERATIONS 100 +#define EFCT_HW_MAX_NUM_MQ 1 +#define EFCT_HW_MAX_NUM_RQ 32 +#define EFCT_HW_MAX_NUM_EQ 16 +#define EFCT_HW_MAX_NUM_WQ 32 +#define EFCT_HW_DEF_NUM_EQ 1 + +#define OCE_HW_MAX_NUM_MRQ_PAIRS 16 + +#define EFCT_HW_MQ_DEPTH 128 +#define EFCT_HW_EQ_DEPTH 1024 + +/* +* A CQ will be assinged to each WQ +* (CQ must have 2X entries of the WQ for abort +* processing), plus a separate one for each RQ PAIR and one for MQ +*/ +#define EFCT_HW_MAX_NUM_CQ \ + ((EFCT_HW_MAX_NUM_WQ * 2) + 1 + (OCE_HW_MAX_NUM_MRQ_PAIRS * 2)) + +#define EFCT_HW_Q_HASH_SIZE 128 +#define EFCT_HW_RQ_HEADER_SIZE 128 +#define EFCT_HW_RQ_HEADER_INDEX 0 + +#define EFCT_HW_REQUE_XRI_REGTAG 65534 + +/* Options for efct_hw_command() */ +enum efct_cmd_opts { +/* command executes synchronously and busy-waits for completion */ +EFCT_CMD_POLL , +/* command executes asynchronously. Uses callback */ +EFCT_CMD_NOWAIT , +}; + +enum efct_hw_rtn { +EFCT_HW_RTN_SUCCESS =0 , +EFCT_HW_RTN_SUCCESS_SYNC =1 , +EFCT_HW_RTN_ERROR =-1 , +EFCT_HW_RTN_NO_RESOURCES =-2 , +EFCT_HW_RTN_NO_MEMORY =-3 , +EFCT_HW_RTN_IO_NOT_ACTIVE =-4 , +EFCT_HW_RTN_IO_ABORT_IN_PROGRESS =-5 , +EFCT_HW_RTN_IO_PORT_OWNED_ALREADY_ABORTED =-6 , +EFCT_HW_RTN_INVALID_ARG =-7 , +}; + +#define EFCT_HW_RTN_IS_ERROR (e) ((e) < 0) + +enum efct_hw_reset { +EFCT_HW_RESET_FUNCTION , +EFCT_HW_RESET_FIRMWARE , +EFCT_HW_RESET_MAX +}; + +enum efct_hw_topo { +EFCT_HW_TOPOLOGY_AUTO , +EFCT_HW_TOPOLOGY_NPORT , +EFCT_HW_TOPOLOGY_LOOP , +EFCT_HW_TOPOLOGY_NONE , +EFCT_HW_TOPOLOGY_MAX +}; + +/* pack fw revision values into a single uint64_t */ +#define HW_FWREV (a, b, c, d) (((uint64_t)(a) << 48) | ((uint64_t)(b) << 32) \ + | ((uint64_t)(c) << 16) | ((uint64_t)(d))) + +#define EFCT_FW_VER_STR (a, b, c, d) (#a "." #b "." #c "." #d) + +enum efct_hw_io_type { +EFCT_HW_ELS_REQ , +EFCT_HW_ELS_RSP , +EFCT_HW_ELS_RSP_SID , +EFCT_HW_FC_CT , +EFCT_HW_FC_CT_RSP , +EFCT_HW_BLS_ACC , +EFCT_HW_BLS_ACC_SID , +EFCT_HW_BLS_RJT , +EFCT_HW_IO_TARGET_READ , +EFCT_HW_IO_TARGET_WRITE , +EFCT_HW_IO_TARGET_RSP , +EFCT_HW_IO_DNRX_REQUEUE , +EFCT_HW_IO_MAX , +}; + +enum efct_hw_io_state { +EFCT_HW_IO_STATE_FREE , +EFCT_HW_IO_STATE_INUSE , +EFCT_HW_IO_STATE_WAIT_FREE , +EFCT_HW_IO_STATE_WAIT_SEC_HIO , +}; + +struct efct_hw ; + +/** +* HW command context. +* Stores the state for the asynchronous commands sent to the hardware. +*/ +struct efct_command_ctx { +struct list_head list_entry; +int (*cb)(struct efct_hw *hw,int status,u8 *mqe,void *arg); +void *arg;/* Argument for callback */ +u8 *buf;/* buffer holding command / results */ +void *ctx;/* upper layer context */ +}; + +struct efct_hw_sgl { +uintptr_t addr; +size_t len; +}; + +union efct_hw_io_param_u { +struct sli_bls_params bls; +struct sli_els_params els; +struct sli_ct_params fc_ct; +struct sli_fcp_tgt_params fcp_tgt; +}; + +/* WQ steering mode */ +enum efct_hw_wq_steering { +EFCT_HW_WQ_STEERING_CLASS , +EFCT_HW_WQ_STEERING_REQUEST , +EFCT_HW_WQ_STEERING_CPU , +}; + +/* HW wqe object */ +struct efct_hw_wqe { +struct list_head list_entry; +bool abort_wqe_submit_needed; +bool send_abts; +u32 id; +u32 abort_reqtag; +u8 *wqebuf; +};
drivers/scsi/elx/efct/efct_hw.h line 191
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw.h new file +10
-0+ +/** +* HW IO object. +* +* Stores the per-IO information necessary +* for both the lower (SLI) and upper +* layers (efct). +*/ +struct efct_hw_io { +/* Owned by HW */
What are the rules? Live time properties?
drivers/scsi/elx/efct/efct_hw.h line 193
Quoted 2 lines
drivers/scsi/elx/efct/efct_hw.h new file +2
-0+ +/* reference counter and callback function */
Make kerneldoc out of it?
Quoted 17 lines
drivers/scsi/elx/efct/efct_hw.h new file +17
-0+struct kref ref; +void (*release)(struct kref *arg); +/* used for busy, wait_free, free lists */ +struct list_head list_entry; +/* used for timed_wqe list */ +struct list_head wqe_link; +/* used for io posted dnrx list */ +struct list_head dnrx_link; +/* state of IO: free, busy, wait_free */ +enum efct_hw_io_state state; +/* Work queue object, with link for pending */ +struct efct_hw_wqe wqe; +/* pointer back to hardware context */ +struct efct_hw *hw; +struct efc_remote_node *rnode; +struct efc_dma xfer_rdy; +u16 type;
drivers/scsi/elx/efct/efct_hw.h line 220
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw.h new file +10
-0+/* WQ assigned to the exchange */ +struct hw_wq *wq; +/* Exchange is active in FW */ +bool xbusy; +/* Function called on IO completion */ +int + (*done)(struct efct_hw_io *hio, +struct efc_remote_node *rnode, +u32 len,int status, +u32 ext,void *ul_arg);
There is still a bit left till 80 chars are hit.
Quoted 400 lines
drivers/scsi/elx/efct/efct_hw.h new file +397
-0+/* argument passed to "IO done" callback */ +void *arg; +/* Function called on abort completion */ +int + (*abort_done)(struct efct_hw_io *hio, +struct efc_remote_node *rnode, +u32 len,int status, +u32 ext,void *ul_arg); +/* argument passed to "abort done" callback */ +void *abort_arg; +/* needed for bug O127585: length of IO */ +size_t length; +/* timeout value for target WQEs */ +u8 tgt_wqe_timeout; +/* timestamp when current WQE was submitted */ +u64 submit_ticks; + +/* if TRUE, latched status shld be returned */ +bool status_saved; +/* if TRUE, abort is in progress */ +bool abort_in_progress; +u32 saved_status; +u32 saved_len; +u32 saved_ext; + +/* EQ that this HIO came up on */ +struct hw_eq *eq; +/* WQ steering mode request */ +enum efct_hw_wq_steering wq_steering; +/* WQ class if steering mode is Class */ +u8 wq_class; + +/* request tag for this HW IO */ +u16 reqtag; +/* request tag for an abort of this HW IO +* (note: this is a 32 bit value +* to allow us to use UINT32_MAX as an uninitialized value) +*/ +u32 abort_reqtag; +u32 indicator;/* XRI */ +struct efc_dma def_sgl;/* default SGL*/ +/* Count of SGEs in default SGL */ +u32 def_sgl_count; +/* pointer to current active SGL */ +struct efc_dma *sgl; +u32 sgl_count;/* count of SGEs in io->sgl */ +u32 first_data_sge;/* index of first data SGE */ +struct efc_dma *ovfl_sgl;/* overflow SGL */ +u32 ovfl_sgl_count; +/* pointer to overflow segment len */ +struct sli4_lsp_sge *ovfl_lsp; +u32 n_sge;/* number of active SGEs */ +u32 sge_offset; + +/* where upper layer can store ref to its IO */ +void *ul_io; +}; + +/* Typedef for HW "done" callback */ +typedef int (*efct_hw_done_t )(struct efct_hw_io *,struct efc_remote_node *, +u32 len,int status,u32 ext,void *ul_arg); + +enum efct_hw_port { +EFCT_HW_PORT_INIT , +EFCT_HW_PORT_SHUTDOWN , +}; + +/* Node group rpi reference */ +struct efct_hw_rpi_ref { +atomic_t rpi_count; +atomic_t rpi_attached; +}; + +enum efct_hw_link_stat { +EFCT_HW_LINK_STAT_LINK_FAILURE_COUNT , +EFCT_HW_LINK_STAT_LOSS_OF_SYNC_COUNT , +EFCT_HW_LINK_STAT_LOSS_OF_SIGNAL_COUNT , +EFCT_HW_LINK_STAT_PRIMITIVE_SEQ_COUNT , +EFCT_HW_LINK_STAT_INVALID_XMIT_WORD_COUNT , +EFCT_HW_LINK_STAT_CRC_COUNT , +EFCT_HW_LINK_STAT_PRIMITIVE_SEQ_TIMEOUT_COUNT , +EFCT_HW_LINK_STAT_ELASTIC_BUFFER_OVERRUN_COUNT , +EFCT_HW_LINK_STAT_ARB_TIMEOUT_COUNT , +EFCT_HW_LINK_STAT_ADVERTISED_RCV_B2B_CREDIT , +EFCT_HW_LINK_STAT_CURR_RCV_B2B_CREDIT , +EFCT_HW_LINK_STAT_ADVERTISED_XMIT_B2B_CREDIT , +EFCT_HW_LINK_STAT_CURR_XMIT_B2B_CREDIT , +EFCT_HW_LINK_STAT_RCV_EOFA_COUNT , +EFCT_HW_LINK_STAT_RCV_EOFDTI_COUNT , +EFCT_HW_LINK_STAT_RCV_EOFNI_COUNT , +EFCT_HW_LINK_STAT_RCV_SOFF_COUNT , +EFCT_HW_LINK_STAT_RCV_DROPPED_NO_AER_COUNT , +EFCT_HW_LINK_STAT_RCV_DROPPED_NO_RPI_COUNT , +EFCT_HW_LINK_STAT_RCV_DROPPED_NO_XRI_COUNT , +EFCT_HW_LINK_STAT_MAX , +}; + +enum efct_hw_host_stat { +EFCT_HW_HOST_STAT_TX_KBYTE_COUNT , +EFCT_HW_HOST_STAT_RX_KBYTE_COUNT , +EFCT_HW_HOST_STAT_TX_FRAME_COUNT , +EFCT_HW_HOST_STAT_RX_FRAME_COUNT , +EFCT_HW_HOST_STAT_TX_SEQ_COUNT , +EFCT_HW_HOST_STAT_RX_SEQ_COUNT , +EFCT_HW_HOST_STAT_TOTAL_EXCH_ORIG , +EFCT_HW_HOST_STAT_TOTAL_EXCH_RESP , +EFCT_HW_HOSY_STAT_RX_P_BSY_COUNT , +EFCT_HW_HOST_STAT_RX_F_BSY_COUNT , +EFCT_HW_HOST_STAT_DROP_FRM_DUE_TO_NO_RQ_BUF_COUNT , +EFCT_HW_HOST_STAT_EMPTY_RQ_TIMEOUT_COUNT , +EFCT_HW_HOST_STAT_DROP_FRM_DUE_TO_NO_XRI_COUNT , +EFCT_HW_HOST_STAT_EMPTY_XRI_POOL_COUNT , +EFCT_HW_HOST_STAT_MAX , +}; + +enum efct_hw_state { +EFCT_HW_STATE_UNINITIALIZED , +EFCT_HW_STATE_QUEUES_ALLOCATED , +EFCT_HW_STATE_ACTIVE , +EFCT_HW_STATE_RESET_IN_PROGRESS , +EFCT_HW_STATE_TEARDOWN_IN_PROGRESS , +}; + +struct efct_hw_link_stat_counts { +u8 overflow; +u32 counter; +}; + +struct efct_hw_host_stat_counts { +u32 counter; +}; + +/* Structure used for the hash lookup of queue IDs */ +struct efct_queue_hash { +bool in_use; +u16 id; +u16 index; +}; + +/* WQ callback object */ +struct hw_wq_callback { +u16 instance_index;/* use for request tag */ +void (*callback)(void *arg,u8 *cqe,int status); +void *arg; +struct list_head list_entry; +}; + +struct reqtag_pool { +spinlock_t lock;/* pool lock */ +struct hw_wq_callback *tags[U16_MAX ]; +struct list_head freelist; +}; + +struct efct_hw_config { +u32 n_eq; +u32 n_cq; +u32 n_mq; +u32 n_rq; +u32 n_wq; +u32 n_io; +u32 n_sgl; +u32 speed; +u32 topology; +/* size of the buffers for first burst */ +u32 rq_default_buffer_size; +u8 esoc; +/* MRQ RQ selection policy */ +u8 rq_selection_policy; +/* RQ quanta if rq_selection_policy == 2 */ +u8 rr_quanta; +u32 filter_def[SLI4_CMD_REG_FCFI_NUM_RQ_CFG ]; +}; + +struct efct_hw { +struct efct *os; +struct sli4 sli; +u16 ulp_start; +u16 ulp_max; +u32 dump_size; +enum efct_hw_state state; +bool hw_setup_called; +u8 sliport_healthcheck; + +/* HW configuration */ +struct efct_hw_config config; + +/* calculated queue sizes for each type */ +u32 num_qentries[SLI_QTYPE_MAX ]; + +/* Storage for SLI queue objects */ +struct sli4_queue wq[EFCT_HW_MAX_NUM_WQ ]; +struct sli4_queue rq[EFCT_HW_MAX_NUM_RQ ]; +u16 hw_rq_lookup[EFCT_HW_MAX_NUM_RQ ]; +struct sli4_queue mq[EFCT_HW_MAX_NUM_MQ ]; +struct sli4_queue cq[EFCT_HW_MAX_NUM_CQ ]; +struct sli4_queue eq[EFCT_HW_MAX_NUM_EQ ]; + +/* HW queue */ +u32 eq_count; +u32 cq_count; +u32 mq_count; +u32 wq_count; +u32 rq_count; +struct list_head eq_list; + +struct efct_queue_hash cq_hash[EFCT_HW_Q_HASH_SIZE ]; +struct efct_queue_hash rq_hash[EFCT_HW_Q_HASH_SIZE ]; +struct efct_queue_hash wq_hash[EFCT_HW_Q_HASH_SIZE ]; + +/* Storage for HW queue objects */ +struct hw_wq *hw_wq[EFCT_HW_MAX_NUM_WQ ]; +struct hw_rq *hw_rq[EFCT_HW_MAX_NUM_RQ ]; +struct hw_mq *hw_mq[EFCT_HW_MAX_NUM_MQ ]; +struct hw_cq *hw_cq[EFCT_HW_MAX_NUM_CQ ]; +struct hw_eq *hw_eq[EFCT_HW_MAX_NUM_EQ ]; +/* count of hw_rq[] entries */ +u32 hw_rq_count; +/* count of multirq RQs */ +u32 hw_mrq_count; + +/* Sequence objects used in incoming frame processing */ +void *seq_pool; + +/* Maintain an ordered, linked list of outstanding HW commands. */ +spinlock_t cmd_lock; +struct list_head cmd_head; +struct list_head cmd_pending; +u32 cmd_head_count; + +struct sli4_link_event link; +struct efc_domain *domain; + +u16 fcf_indicator; + +/* pointer array of IO objects */ +struct efct_hw_io **io; +/* array of WQE buffs mapped to IO objects */ +u8 *wqe_buffs; + +/* IO lock to synchronize list access */ +spinlock_t io_lock; +/* IO lock to synchronize IO aborting */ +spinlock_t io_abort_lock; +/* List of IO objects in use */ +struct list_head io_inuse; +/* List of IO objects waiting to be freed */ +struct list_head io_wait_free; +/* List of IO objects available for allocation */ +struct list_head io_free; + +struct efc_dma loop_map; + +struct efc_dma xfer_rdy; + +struct efc_dma dump_sges; + +struct efc_dma rnode_mem; + +struct efct_hw_rpi_ref *rpi_ref; + +atomic_t io_alloc_failed_count; + +/* stat: wq sumbit count */ +u32 tcmd_wq_submit[EFCT_HW_MAX_NUM_WQ ]; +/* stat: wq complete count */ +u32 tcmd_wq_complete[EFCT_HW_MAX_NUM_WQ ]; + +struct reqtag_pool *wq_reqtag_pool; +atomic_t send_frame_seq_id; +}; + +enum efct_hw_io_count_type { +EFCT_HW_IO_INUSE_COUNT , +EFCT_HW_IO_FREE_COUNT , +EFCT_HW_IO_WAIT_FREE_COUNT , +EFCT_HW_IO_N_TOTAL_IO_COUNT , +}; + +/* HW queue data structures */ +struct hw_eq { +struct list_head list_entry; +enum sli4_qtype type; +u32 instance; +u32 entry_count; +u32 entry_size; +struct efct_hw *hw; +struct sli4_queue *queue; +struct list_head cq_list; +u32 use_count; +}; + +struct hw_cq { +struct list_head list_entry; +enum sli4_qtype type; +u32 instance; +u32 entry_count; +u32 entry_size; +struct hw_eq *eq; +struct sli4_queue *queue; +struct list_head q_list; +u32 use_count; +}; + +struct hw_q { +struct list_head list_entry; +enum sli4_qtype type; +}; + +struct hw_mq { +struct list_head list_entry; +enum sli4_qtype type; +u32 instance; + +u32 entry_count; +u32 entry_size; +struct hw_cq *cq; +struct sli4_queue *queue; + +u32 use_count; +}; + +struct hw_wq { +struct list_head list_entry; +enum sli4_qtype type; +u32 instance; +struct efct_hw *hw; + +u32 entry_count; +u32 entry_size; +struct hw_cq *cq; +struct sli4_queue *queue; +u32 class; + +/* WQ consumed */ +u32 wqec_set_count; +u32 wqec_count; +u32 free_count; +u32 total_submit_count; +struct list_head pending_list; + +/* HW IO allocated for use with Send Frame */ +struct efct_hw_io *send_frame_io; + +/* Stats */ +u32 use_count; +u32 wq_pending_count; +}; + +struct hw_rq { +struct list_head list_entry; +enum sli4_qtype type; +u32 instance; + +u32 entry_count; +u32 use_count; +u32 hdr_entry_size; +u32 first_burst_entry_size; +u32 data_entry_size; +bool is_mrq; +u32 base_mrq_id; + +struct hw_cq *cq; + +u8 filter_mask; +struct sli4_queue *hdr; +struct sli4_queue *first_burst; +struct sli4_queue *data; + +struct efc_hw_rq_buffer *hdr_buf; +struct efc_hw_rq_buffer *fb_buf; +struct efc_hw_rq_buffer *payload_buf; +/* RQ tracker for this RQ */ +struct efc_hw_sequence **rq_tracker; +}; + +struct efct_hw_send_frame_context { +struct efct_hw *hw; +struct hw_wq_callback *wqcb; +struct efct_hw_wqe wqe; +void (*callback)(int status,void *arg); +void *arg; + +/* General purpose elements */ +struct efc_hw_sequence *seq; +struct efc_dma payload; +}; + +struct efct_hw_grp_hdr { +u32 size; +__be32 magic_number; +u32 word2; +u8 rev_name[128 ]; +u8 date[12 ]; +u8 revision[32 ]; +}; + +#endif /* __EFCT_H__ */ Signature · 1 line
2.16.4
Thanks,
Daniel
Re: [PATCH v3 15/31] elx: efct: Data structures and defines for hw operations
On 4/16/2020 12:22 AM, Daniel Wagner wrote:
...
Quoted 12 lines
drivers/scsi/elx/efct/efct_hw.h line 191
Quoted 9 lines
drivers/scsi/elx/efct/efct_hw.h new file +9
-0+/** +* HW IO object. +* +* Stores the per-IO information necessary +* for both the lower (SLI) and upper +* layers (efct). +*/ +struct efct_hw_io { +/* Owned by HW */ What are the rules? Live time properties?
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ + /* reference counter and callback function */Make kerneldoc out of it?
I'll see if there's something we can write about it.
Agree with rest of comments.
-- james
PATCH v3 16/31 elx: efct: Driver initialization routines
In reply to James SmartThis patch continues the efct driver population.
This patch adds driver definitions for:
Emulex FC Target driver init, attach and hardware setup routines.
---
v3:
Removed Queue topology string.
Used request_threaded_irq instead of a thread.
Use a static fuction to get the model.
Reworked efct_device_attach to use if statements and gotos. Changed efct_fw_reset, removed accessing other functions. Converted to use pci_alloc_irq_vectors api.
Removed proc interface.
Removed efct_hw_get and efct_hw_set functions. Driver implicitly
knows adapter configuration.
Many more small changes.
--- drivers/scsi/elx/efct/efct_driver.c | 856 +++++++++++++++++++++++++++ drivers/scsi/elx/efct/efct_driver.h | 142 +++++ drivers/scsi/elx/efct/efct_hw.c | 1116 +++++++++++++++++++++++++++++++++++ drivers/scsi/elx/efct/efct_hw.h | 15 + drivers/scsi/elx/efct/efct_xport.c | 523 ++++++++++++++++ drivers/scsi/elx/efct/efct_xport.h | 201 +++++++ 6 files changed, 2853 insertions(+) create mode 100644 drivers/scsi/elx/efct/efct_driver.c create mode 100644 drivers/scsi/elx/efct/efct_driver.h create mode 100644 drivers/scsi/elx/efct/efct_hw.c create mode 100644 drivers/scsi/elx/efct/efct_xport.c create mode 100644 drivers/scsi/elx/efct/efct_xport.h
drivers/scsi/elx/efct/efct_driver.c new file +856 -0
@@ -0,0 +1,856 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2019 Broadcom. All Rights Reserved. The term +* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +*/ + +#include "efct_driver.h" + +#include "efct_els.h" +#include "efct_hw.h" +#include "efct_unsol.h" +#include "efct_scsi.h" + +struct efct *efct_devices[MAX_EFCT_DEVICES ]; + +static int logmask; +module_param (logmask, int,0444 ); +MODULE_PARM_DESC (logmask,"logging bitmask (default 0)" ); + +static struct libefc_function_template efct_libefc_templ = { + .hw_domain_alloc = efct_hw_domain_alloc, + .hw_domain_attach = efct_hw_domain_attach, + .hw_domain_free = efct_hw_domain_free, + .hw_domain_force_free = efct_hw_domain_force_free, + .domain_hold_frames = efct_domain_hold_frames, + .domain_accept_frames = efct_domain_accept_frames, + + .hw_port_alloc = efct_hw_port_alloc, + .hw_port_attach = efct_hw_port_attach, + .hw_port_free = efct_hw_port_free, + + .hw_node_alloc = efct_hw_node_alloc, + .hw_node_attach = efct_hw_node_attach, + .hw_node_detach = efct_hw_node_detach, + .hw_node_free_resources = efct_hw_node_free_resources, + .node_purge_pending = efct_node_purge_pending, + + .scsi_io_alloc_disable = efct_scsi_io_alloc_disable, + .scsi_io_alloc_enable = efct_scsi_io_alloc_enable, + .scsi_validate_node = efct_scsi_validate_initiator, + .new_domain = efct_scsi_tgt_new_domain, + .del_domain = efct_scsi_tgt_del_domain, + .new_sport = efct_scsi_tgt_new_sport, + .del_sport = efct_scsi_tgt_del_sport, + .scsi_new_node = efct_scsi_new_initiator, + .scsi_del_node = efct_scsi_del_initiator, + + .els_send = efct_els_req_send, + .els_send_ct = efct_els_send_ct, + .els_send_resp = efct_els_resp_send, + .bls_send_acc_hdr = efct_bls_send_acc_hdr, + .send_flogi_p2p_acc = efct_send_flogi_p2p_acc, + .send_ct_rsp = efct_send_ct_rsp, + .send_ls_rjt = efct_send_ls_rjt, + + .node_io_cleanup = efct_node_io_cleanup, + .node_els_cleanup = efct_node_els_cleanup, + .node_abort_all_els = efct_node_abort_all_els, + + .dispatch_fcp_cmd = efct_dispatch_fcp_cmd, + .recv_abts_frame = efct_node_recv_abts_frame, +}; + +static int +efct_device_init (void ) +{ +int rc; + +/* driver-wide init for target-server */ + rc =efct_scsi_tgt_driver_init (); +if (rc) { +pr_err ("efct_scsi_tgt_init failed rc=%d\n" , + rc); +return rc; + } + + rc =efct_scsi_reg_fc_transport (); +if (rc) { +pr_err ("failed to register to FC host\n" ); +return rc; + } + +return EFC_SUCCESS ; +} + +static void +efct_device_shutdown (void ) +{ +efct_scsi_release_fc_transport (); + +efct_scsi_tgt_driver_exit (); +} + +static void * +efct_device_alloc (u32 nid) +{ +struct efct *efct =NULL ; +u32 i; + + efct =kmalloc_node (sizeof (*efct),GFP_ATOMIC , nid); + +if (efct) { +memset (efct,0 ,sizeof (*efct)); +for (i =0 ; i <ARRAY_SIZE (efct_devices); i++) { +if (!efct_devices[i]) { + efct->instance_index = i; + efct_devices[i] = efct; +break ; + } + } + +if (i ==ARRAY_SIZE (efct_devices)) { +pr_err ("Exceeded max supported devices.\n" ); +kfree (efct); + efct =NULL ; + }else { + efct->attached = false; + } + } +return efct; +} + +static void +efct_teardown_msix (struct efct *efct) +{ +u32 i; + +for (i =0 ; i < efct->n_msix_vec; i++) { +free_irq (pci_irq_vector (efct->pcidev, i), + &efct->intr_context[i]); + } + +pci_free_irq_vectors (efct->pcidev); +} + +static int +efct_efclib_config (struct efct *efct,struct libefc_function_template *tt) +{ +struct efc *efc; +struct sli4 *sli; +int rc =EFC_SUCCESS ; + + efc =kmalloc (sizeof (*efc),GFP_KERNEL ); +if (!efc) +return EFC_FAIL ; + +memset (efc,0 ,sizeof (struct efc )); + efct->efcport = efc; + +memcpy (&efc->tt, tt,sizeof (*tt)); + efc->base = efct; + efc->pcidev = efct->pcidev; + + efc->def_wwnn =efct_get_wwnn (&efct->hw); + efc->def_wwpn =efct_get_wwpn (&efct->hw); + efc->enable_tgt =1 ; + efc->log_level =EFC_LOG_LIB ; + + sli = &efct->hw.sli; + efc->max_xfer_size = sli->sge_supported_length * +sli_get_max_sgl (&efct->hw.sli); + + rc =efcport_init (efc); +if (rc) +efc_log_err (efc,"efcport_init failed\n" ); + +return rc; +} + +static int efct_request_firmware_update (struct efct *efct); + +static const char * +efct_pci_model (u16 device) +{ +switch (device) { +case EFCT_DEVICE_LANCER_G6 :return "LPE31004" ; +case EFCT_DEVICE_LANCER_G7 :return "LPE36000" ; +default :return "unknown" ; + } +} + +static int +efct_device_attach (struct efct *efct) +{ +u32 rc =0 , i =0 ; + +if (efct->attached) { +efc_log_err (efct,"Device is already attached\n" ); +return EFC_FAIL ; + } + +snprintf (efct->name,sizeof (efct->name),"[%s%d] " ,"fc" , + efct->instance_index); + + efct->logmask = logmask; + efct->filter_def ="0,0,0,0" ; + efct->max_isr_time_msec =EFCT_OS_MAX_ISR_TIME_MSEC ; + + efct->model =efct_pci_model (efct->pcidev->device); + + efct->efct_req_fw_upgrade = true; + +/* Allocate transport object and bring online */ + efct->xport =efct_xport_alloc (efct); +if (!efct->xport) { +efc_log_err (efct,"failed to allocate transport object\n" ); + rc = -ENOMEM ; + goto out; + } + + rc =efct_xport_attach (efct->xport); +if (rc) { +efc_log_err (efct,"failed to attach transport object\n" ); + goto xport_out; + } + + rc =efct_xport_initialize (efct->xport); +if (rc) { +efc_log_err (efct,"failed to initialize transport object\n" ); + goto xport_out; + } + + rc =efct_efclib_config (efct, &efct_libefc_templ); +if (rc) { +efc_log_err (efct,"failed to init efclib\n" ); + goto efclib_out; + } + +for (i =0 ; i < efct->n_msix_vec; i++) { +efc_log_debug (efct,"irq %d enabled\n" , i); +enable_irq (pci_irq_vector (efct->pcidev, i)); + } + + efct->attached = true; + +if (efct->efct_req_fw_upgrade) +efct_request_firmware_update (efct); + +return rc; + +efclib_out: +efct_xport_detach (efct->xport); +xport_out: +if (efct->xport) { +efct_xport_free (efct->xport); + efct->xport =NULL ; + } +out: +return rc; +} + +static int +efct_device_detach (struct efct *efct) +{ +int rc =0 , i; + +if (efct) { +if (!efct->attached) { +efc_log_warn (efct,"Device is not attached\n" ); +return EFC_FAIL ; + } + + rc =efct_xport_control (efct->xport,EFCT_XPORT_SHUTDOWN ); +if (rc) +efc_log_err (efct,"Transport Shutdown timed out\n" ); + +for (i =0 ; i < efct->n_msix_vec; i++) +disable_irq (pci_irq_vector (efct->pcidev, i)); + +if (efct_xport_detach (efct->xport) !=0 ) +efc_log_err (efct,"Transport detach failed\n" ); + +efct_xport_free (efct->xport); + efct->xport =NULL ; + +efcport_destroy (efct->efcport); +kfree (efct->efcport); + + efct->attached = false; + } + +return EFC_SUCCESS ; +} + +static void +efct_fw_write_cb (int status,u32 actual_write_length, +u32 change_status,void *arg) +{ +struct efct_fw_write_result *result = arg; + + result->status = status; + result->actual_xfer = actual_write_length; + result->change_status = change_status; + +complete (&result->done); +} + +static int +efct_firmware_write (struct efct *efct,const u8 *buf,size_t buf_len, +u8 *change_status) +{ +int rc =0 ; +u32 bytes_left; +u32 xfer_size; +u32 offset; +struct efc_dma dma; +int last =0 ; +struct efct_fw_write_result result; + +init_completion (&result.done); + + bytes_left = buf_len; + offset =0 ; + + dma.size =FW_WRITE_BUFSIZE ; + dma.virt =dma_alloc_coherent (&efct->pcidev->dev, + dma.size, &dma.phys,GFP_DMA ); +if (!dma.virt) +return -ENOMEM ; + +while (bytes_left >0 ) { +if (bytes_left >FW_WRITE_BUFSIZE ) + xfer_size =FW_WRITE_BUFSIZE ; +else + xfer_size = bytes_left; + +memcpy (dma.virt, buf + offset, xfer_size); + +if (bytes_left == xfer_size) + last =1 ; + +efct_hw_firmware_write (&efct->hw, &dma, xfer_size, offset, + last, efct_fw_write_cb, &result); + +if (wait_for_completion_interruptible (&result.done) !=0 ) { + rc = -ENXIO ; +break ; + } + +if (result.actual_xfer ==0 || result.status !=0 ) { + rc = -EFAULT ; +break ; + } + +if (last) + *change_status = result.change_status; + + bytes_left -= result.actual_xfer; + offset += result.actual_xfer; + } + +dma_free_coherent (&efct->pcidev->dev, dma.size, dma.virt, dma.phys); +return rc; +} + +/* +* Firmware reset to activate the new firmware. +* Function 0 will update and load the new firmware +* during attach. +*/ +static int +efct_fw_reset (struct efct *efct) +{ +int rc =0 ; + +if (timer_pending (&efct->xport->stats_timer)) +del_timer (&efct->xport->stats_timer); + +if (efct_hw_reset (&efct->hw,EFCT_HW_RESET_FIRMWARE )) { +efc_log_info (efct,"failed to reset firmware\n" ); + rc =-1 ; + }else { +efc_log_info (efct, +"successfully reset firmware.Now resetting port\n" ); + +efct_device_detach (efct); + rc =efct_device_attach (efct); + } +return rc; +} + +static int +efct_request_firmware_update (struct efct *efct) +{ +int rc =0 ; +u8 file_name[256 ], fw_change_status =0 ; +const struct firmware *fw; +struct efct_hw_grp_hdr *fw_image; + +snprintf (file_name,256 ,"%s.grp" , efct->model); + + rc =request_firmware (&fw, file_name, &efct->pcidev->dev); +if (rc) { +efc_log_debug (efct,"Firmware file(%s) not found.\n" , + file_name); +return rc; + } + + fw_image = (struct efct_hw_grp_hdr *)fw->data; + +if (!strncmp (efct->hw.sli.fw_name[0 ], fw_image->revision, +strnlen (fw_image->revision,16 ))) { +efc_log_debug (efct, +"Skipped update. Firmware is already up to date.\n" ); + goto exit; + } + +efc_log_info (efct,"Firmware update is initiated. %s -> %s\n" , + efct->hw.sli.fw_name[0 ], fw_image->revision); + + rc =efct_firmware_write (efct, fw->data, fw->size, &fw_change_status); +if (rc) { +efc_log_err (efct, +"Firmware update failed. Return code = %d\n" , rc); + goto exit; + } + +efc_log_info (efct,"Firmware updated successfully\n" ); +switch (fw_change_status) { +case 0x00 : +efc_log_info (efct,"New firmware is active.\n" ); +break ; +case 0x01 : +efc_log_info (efct, +"System reboot needed to activate the new firmware\n" ); +break ; +case 0x02 : +case 0x03 : +efc_log_info (efct, +"firmware is resetting to activate the new firmware\n" ); +efct_fw_reset (efct); +break ; +default : +efc_log_info (efct, +"Unexected value change_status:%d\n" , fw_change_status); +break ; + } + +exit: +release_firmware (fw); + +return rc; +} + +static void +efct_device_free (struct efct *efct) +{ +if (efct) { + efct_devices[efct->instance_index] =NULL ; + +kfree (efct); + } +} + +static int +efct_device_interrupts_required (struct efct *efct) +{ +if (efct_hw_setup (&efct->hw, efct, efct->pcidev) + !=EFCT_HW_RTN_SUCCESS ) { +return -1 ; + } + +return efct->hw.config.n_eq; +} + +static irqreturn_t +efct_intr_thread (int irq,void *handle) +{ +struct efct_intr_context *intr_ctx = handle; +struct efct *efct = intr_ctx->efct; + +efct_hw_process (&efct->hw, intr_ctx->index, efct->max_isr_time_msec); +return IRQ_HANDLED ; +} + +static irqreturn_t +efct_intr_msix (int irq,void *handle) +{ +return IRQ_WAKE_THREAD ; +} + +static int +efct_setup_msix (struct efct *efct,u32 num_intrs) +{ +int rc =0 , i; + +if (!pci_find_capability (efct->pcidev,PCI_CAP_ID_MSIX )) { +dev_err (&efct->pcidev->dev, +"%s : MSI-X not available\n" , __func__); +return -EINVAL ; + } + + efct->n_msix_vec = num_intrs; + + rc =pci_alloc_irq_vectors (efct->pcidev, num_intrs, num_intrs, +PCI_IRQ_MSIX |PCI_IRQ_AFFINITY ); + +if (rc <0 ) { +dev_err (&efct->pcidev->dev,"Failed to alloc irq : %d\n" , rc); +return rc; + } + +for (i =0 ; i < num_intrs; i++) { +struct efct_intr_context *intr_ctx =NULL ; + + intr_ctx = &efct->intr_context[i]; + intr_ctx->efct = efct; + intr_ctx->index = i; + + rc =request_threaded_irq (pci_irq_vector (efct->pcidev, i), + efct_intr_msix, efct_intr_thread,0 , +EFCT_DRIVER_NAME , intr_ctx); +if (rc) { +dev_err (&efct->pcidev->dev, +"Failed to register %d vector: %d\n" , i, rc); + goto out; + } + } + +return rc; + +out: +while (--i >=0 ) +free_irq (pci_irq_vector (efct->pcidev, i), + &efct->intr_context[i]); + +pci_free_irq_vectors (efct->pcidev); +return rc; +} + +static struct pci_device_id efct_pci_table[] = { + {PCI_DEVICE (EFCT_VENDOR_ID ,EFCT_DEVICE_LANCER_G6 ),0 }, + {PCI_DEVICE (EFCT_VENDOR_ID ,EFCT_DEVICE_LANCER_G7 ),0 }, + {}/* terminate list */ +}; + +static int +efct_pci_probe (struct pci_dev *pdev,const struct pci_device_id *ent) +{ +struct efct *efct =NULL ; +int rc; +u32 i, r; +int num_interrupts =0 ; +int nid; + +dev_info (&pdev->dev,"%s\n" ,EFCT_DRIVER_NAME ); + + rc =pci_enable_device_mem (pdev); +if (rc) +return rc; + +pci_set_master (pdev); + + rc =pci_set_mwi (pdev); +if (rc) { +dev_info (&pdev->dev, +"pci_set_mwi returned %d\n" , rc); + goto mwi_out; + } + + rc =pci_request_regions (pdev,EFCT_DRIVER_NAME ); +if (rc) { +dev_err (&pdev->dev,"pci_request_regions failed %d\n" , rc); + goto req_regions_out; + } + +/* Fetch the Numa node id for this device */ + nid =dev_to_node (&pdev->dev); +if (nid <0 ) { +dev_err (&pdev->dev, +"Warning Numa node ID is %d\n" , nid); + nid =0 ; + } + +/* Allocate efct */ + efct =efct_device_alloc (nid); +if (!efct) { +dev_err (&pdev->dev,"Failed to allocate efct\n" ); + rc = -ENOMEM ; + goto alloc_out; + } + + efct->pcidev = pdev; + + efct->numa_node = nid; + +/* Map all memory BARs */ +for (i =0 , r =0 ; i <EFCT_PCI_MAX_REGS ; i++) { +if (pci_resource_flags (pdev, i) &IORESOURCE_MEM ) { + efct->reg[r] =ioremap (pci_resource_start (pdev, i), +pci_resource_len (pdev, i)); + r++; + } + +/* +* If the 64-bit attribute is set, both this BAR and the +* next form the complete address. Skip processing the +* next BAR. +*/ +if (pci_resource_flags (pdev, i) &IORESOURCE_MEM_64 ) + i++; + } + +pci_set_drvdata (pdev, efct); + +if (pci_set_dma_mask (pdev,DMA_BIT_MASK (64 )) !=0 || +pci_set_consistent_dma_mask (pdev,DMA_BIT_MASK (64 )) !=0 ) { +dev_warn (&pdev->dev, +"trying DMA_BIT_MASK(32)\n" ); +if (pci_set_dma_mask (pdev,DMA_BIT_MASK (32 )) !=0 || +pci_set_consistent_dma_mask (pdev,DMA_BIT_MASK (32 )) !=0 ) { +dev_err (&pdev->dev, +"setting DMA_BIT_MASK failed\n" ); + rc =-1 ; + goto dma_mask_out; + } + } + + num_interrupts =efct_device_interrupts_required (efct); +if (num_interrupts <0 ) { +efc_log_err (efct,"efct_device_interrupts_required failed\n" ); + rc =-1 ; + goto dma_mask_out; + } + +/* +* Initialize MSIX interrupts, note, +* efct_setup_msix() enables the interrupt +*/ + rc =efct_setup_msix (efct, num_interrupts); +if (rc) { +dev_err (&pdev->dev,"Can't setup msix\n" ); + goto dma_mask_out; + } +/* Disable interrupt for now */ +for (i =0 ; i < efct->n_msix_vec; i++) { +efc_log_debug (efct,"irq %d disabled\n" , i); +disable_irq (pci_irq_vector (efct->pcidev, i)); + } + + rc =efct_device_attach ((struct efct *)efct); +if (rc) + goto attach_out; + +return EFC_SUCCESS ; + +attach_out: +efct_teardown_msix (efct); +dma_mask_out: +pci_set_drvdata (pdev,NULL ); + +for (i =0 ; i <EFCT_PCI_MAX_REGS ; i++) { +if (efct->reg[i]) +iounmap (efct->reg[i]); + } +efct_device_free (efct); +alloc_out: +pci_release_regions (pdev); +req_regions_out: +pci_clear_mwi (pdev); +mwi_out: +pci_disable_device (pdev); +return rc; +} + +static void +efct_pci_remove (struct pci_dev *pdev) +{ +struct efct *efct =pci_get_drvdata (pdev); +u32 i; + +if (!efct) +return ; + +efct_device_detach (efct); + +efct_teardown_msix (efct); + +for (i =0 ; i <EFCT_PCI_MAX_REGS ; i++) { +if (efct->reg[i]) +iounmap (efct->reg[i]); + } + +pci_set_drvdata (pdev,NULL ); + + efct_devices[efct->instance_index] =NULL ; + +efct_device_free (efct); + +pci_release_regions (pdev); + +pci_disable_device (pdev); +} + +static void +efct_device_prep_for_reset (struct efct *efct,struct pci_dev *pdev) +{ +if (efct) { +efc_log_debug (efct, +"PCI channel disable preparing for reset\n" ); +efct_device_detach (efct); +/* Disable interrupt and pci device */ +efct_teardown_msix (efct); + } +pci_disable_device (pdev); +} + +static void +efct_device_prep_for_recover (struct efct *efct) +{ +if (efct) { +efc_log_debug (efct,"PCI channel preparing for recovery\n" ); +efct_hw_io_abort_all (&efct->hw); + } +} + +/** +* efct_pci_io_error_detected - method for handling PCI I/O error +* @pdev: pointer to PCI device. +* @state: the current PCI connection state. +* +* This routine is registered to the PCI subsystem for error handling. This +* function is called by the PCI subsystem after a PCI bus error affecting +* this device has been detected. When this routine is invoked, it dispatches +* device error detected handling routine, which will perform the proper +* error detected operation. +* +* Return codes +* PCI_ERS_RESULT_NEED_RESET - need to reset before recovery +* PCI_ERS_RESULT_DISCONNECT - device could not be recovered +*/ +static pci_ers_result_t +efct_pci_io_error_detected (struct pci_dev *pdev,pci_channel_state_t state) +{ +struct efct *efct =pci_get_drvdata (pdev); +pci_ers_result_t rc; + +switch (state) { +case pci_channel_io_normal: +efct_device_prep_for_recover (efct); + rc =PCI_ERS_RESULT_CAN_RECOVER ; +break ; +case pci_channel_io_frozen: +efct_device_prep_for_reset (efct, pdev); + rc =PCI_ERS_RESULT_NEED_RESET ; +break ; +case pci_channel_io_perm_failure: +efct_device_detach (efct); + rc =PCI_ERS_RESULT_DISCONNECT ; +break ; +default : +efc_log_debug (efct,"Unknown PCI error state:0x%x\n" , + state); +efct_device_prep_for_reset (efct, pdev); + rc =PCI_ERS_RESULT_NEED_RESET ; +break ; + } + +return rc; +} + +static pci_ers_result_t +efct_pci_io_slot_reset (struct pci_dev *pdev) +{ +int rc; +struct efct *efct =pci_get_drvdata (pdev); + + rc =pci_enable_device_mem (pdev); +if (rc) { +efc_log_err (efct, +"failed to re-enable PCI device after reset.\n" ); +return PCI_ERS_RESULT_DISCONNECT ; + } + +/* +* As the new kernel behavior of pci_restore_state() API call clears +* device saved_state flag, need to save the restored state again. +*/ + +pci_save_state (pdev); + +pci_set_master (pdev); + + rc =efct_setup_msix (efct, efct->n_msix_vec); +if (rc) +efc_log_err (efct,"rc %d returned, IRQ allocation failed\n" , + rc); + +/* Perform device reset */ +efct_device_detach (efct); +/* Bring device to online*/ +efct_device_attach (efct); + +return PCI_ERS_RESULT_RECOVERED ; +} + +static void +efct_pci_io_resume (struct pci_dev *pdev) +{ +struct efct *efct =pci_get_drvdata (pdev); + +/* Perform device reset */ +efct_device_detach (efct); +/* Bring device to online*/ +efct_device_attach (efct); +} + +MODULE_DEVICE_TABLE (pci, efct_pci_table); + +static struct pci_error_handlers efct_pci_err_handler = { + .error_detected = efct_pci_io_error_detected, + .slot_reset = efct_pci_io_slot_reset, + .resume = efct_pci_io_resume, +}; + +static struct pci_driver efct_pci_driver = { + .name =EFCT_DRIVER_NAME , + .id_table = efct_pci_table, + .probe = efct_pci_probe, + .remove = efct_pci_remove, + .err_handler = &efct_pci_err_handler, +}; + +static +int __init efct_init (void ) +{ +int rc = -ENODEV ; + + rc =efct_device_init (); +if (rc) { +pr_err ("efct_device_init failed rc=%d\n" , rc); +return -ENOMEM ; + } + + rc =pci_register_driver (&efct_pci_driver); +if (rc) + goto l1; + +return rc; + +l1: +efct_device_shutdown (); +return rc; +} + +static void __exit efct_exit(void) +{ +pci_unregister_driver (&efct_pci_driver); +efct_device_shutdown (); +} + +module_init (efct_init); +module_exit (efct_exit); +MODULE_VERSION (EFCT_DRIVER_VERSION ); +MODULE_LICENSE ("GPL" ); +MODULE_AUTHOR ("Broadcom" );
drivers/scsi/elx/efct/efct_driver.h new file +142 -0
142 lines not on this page · raw message
drivers/scsi/elx/efct/efct_hw.c new file +1116 -0
1,116 lines not on this page · raw message
drivers/scsi/elx/efct/efct_hw.h +15 -0
@@ -614,4 +614,19 @@ struct efct_hw_grp_hdr { u8 revision[32]; }; +static inline int +efct_hw_get_link_speed (struct efct_hw *hw) { +return hw->link.speed; +} + +extern enum efct_hw_rtn +efct_hw_setup (struct efct_hw *hw,void *os,struct pci_dev *pdev); +enum efct_hw_rtn efct_hw_init (struct efct_hw *hw); +extern enum efct_hw_rtn +efct_hw_parse_filter (struct efct_hw *hw,void *value); +extern uint64_t +efct_get_wwnn (struct efct_hw *hw); +extern uint64_t +efct_get_wwpn (struct efct_hw *hw); +#endif /* __EFCT_H__ */
drivers/scsi/elx/efct/efct_xport.c new file +523 -0
523 lines not on this page · raw message
drivers/scsi/elx/efct/efct_xport.h new file +201 -0
201 lines not on this page · raw message
Signature · 1 line
2.16.4
Re: [PATCH v3 16/31] elx: efct: Driver initialization routines
Quoted 131 lines · James Smart
This patch continues the efct driver population.
This patch adds driver definitions for:
Emulex FC Target driver init, attach and hardware setup routines.Signed-off-by Ram Vegesna <[email protected]>Signed-off-by James Smart <[email protected]>---
v3:
Removed Queue topology string.
Usedrequest_threaded_irqinstead of a thread.
Use a static fuction to get the model.
Reworkedefct_device_attachto use if statements and gotos. Changedefct_fw_reset, removed accessing other functions. Converted to usepci_alloc_irq_vectorsapi.
Removed proc interface.
Removedefct_hw_getandefct_hw_setfunctions. Driver implicitly
knows adapter configuration.
Many more small changes.--- drivers/scsi/elx/efct/efct_driver.c | 856 +++++++++++++++++++++++++++ drivers/scsi/elx/efct/efct_driver.h | 142 +++++ drivers/scsi/elx/efct/efct_hw.c | 1116 +++++++++++++++++++++++++++++++++++ drivers/scsi/elx/efct/efct_hw.h | 15 + drivers/scsi/elx/efct/efct_xport.c | 523 ++++++++++++++++ drivers/scsi/elx/efct/efct_xport.h | 201 +++++++ 6 files changed, 2853 insertions(+)create mode 100644
drivers/scsi/elx/efct/efct_driver.ccreate mode 100644drivers/scsi/elx/efct/efct_driver.hcreate mode 100644drivers/scsi/elx/efct/efct_hw.ccreate mode 100644drivers/scsi/elx/efct/efct_xport.ccreate mode 100644drivers/scsi/elx/efct/efct_xport.hdrivers/scsi/elx/efct/efct_driver.c new file +91
-0@@ -0,0 +1,856 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2019 Broadcom. All Rights Reserved. The term +* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +*/ + +#include "efct_driver.h" + +#include "efct_els.h" +#include "efct_hw.h" +#include "efct_unsol.h" +#include "efct_scsi.h" + +struct efct *efct_devices[MAX_EFCT_DEVICES ]; + +static int logmask; +module_param (logmask, int,0444 ); +MODULE_PARM_DESC (logmask,"logging bitmask (default 0)" ); + +static struct libefc_function_template efct_libefc_templ = { + .hw_domain_alloc = efct_hw_domain_alloc, + .hw_domain_attach = efct_hw_domain_attach, + .hw_domain_free = efct_hw_domain_free, + .hw_domain_force_free = efct_hw_domain_force_free, + .domain_hold_frames = efct_domain_hold_frames, + .domain_accept_frames = efct_domain_accept_frames, + + .hw_port_alloc = efct_hw_port_alloc, + .hw_port_attach = efct_hw_port_attach, + .hw_port_free = efct_hw_port_free, + + .hw_node_alloc = efct_hw_node_alloc, + .hw_node_attach = efct_hw_node_attach, + .hw_node_detach = efct_hw_node_detach, + .hw_node_free_resources = efct_hw_node_free_resources, + .node_purge_pending = efct_node_purge_pending, + + .scsi_io_alloc_disable = efct_scsi_io_alloc_disable, + .scsi_io_alloc_enable = efct_scsi_io_alloc_enable, + .scsi_validate_node = efct_scsi_validate_initiator, + .new_domain = efct_scsi_tgt_new_domain, + .del_domain = efct_scsi_tgt_del_domain, + .new_sport = efct_scsi_tgt_new_sport, + .del_sport = efct_scsi_tgt_del_sport, + .scsi_new_node = efct_scsi_new_initiator, + .scsi_del_node = efct_scsi_del_initiator, + + .els_send = efct_els_req_send, + .els_send_ct = efct_els_send_ct, + .els_send_resp = efct_els_resp_send, + .bls_send_acc_hdr = efct_bls_send_acc_hdr, + .send_flogi_p2p_acc = efct_send_flogi_p2p_acc, + .send_ct_rsp = efct_send_ct_rsp, + .send_ls_rjt = efct_send_ls_rjt, + + .node_io_cleanup = efct_node_io_cleanup, + .node_els_cleanup = efct_node_els_cleanup, + .node_abort_all_els = efct_node_abort_all_els, + + .dispatch_fcp_cmd = efct_dispatch_fcp_cmd, + .recv_abts_frame = efct_node_recv_abts_frame, +}; + +static int +efct_device_init (void ) +{ +int rc; + +/* driver-wide init for target-server */ + rc =efct_scsi_tgt_driver_init (); +if (rc) { +pr_err ("efct_scsi_tgt_init failed rc=%d\n" , + rc); +return rc; + } + + rc =efct_scsi_reg_fc_transport (); +if (rc) { +pr_err ("failed to register to FC host\n" ); +return rc; + } + +return EFC_SUCCESS ; +} + +static void +efct_device_shutdown (void ) +{ +efct_scsi_release_fc_transport (); + +efct_scsi_tgt_driver_exit ();
drivers/scsi/elx/efct/efct_driver.c line 101
Quoted 10 lines
drivers/scsi/elx/efct/efct_driver.c new file +10
-0+} + +static void * +efct_device_alloc (u32 nid) +{ +struct efct *efct =NULL ; +u32 i; + + efct =kmalloc_node (sizeof (*efct),GFP_ATOMIC , nid); +
kzalloc_node() ?
Quoted 7 lines
drivers/scsi/elx/efct/efct_driver.c new file +7
-0+if (efct) { +memset (efct,0 ,sizeof (*efct)); +for (i =0 ; i <ARRAY_SIZE (efct_devices); i++) { +if (!efct_devices[i]) { + efct->instance_index = i; + efct_devices[i] = efct; +break ;
drivers/scsi/elx/efct/efct_driver.c line 118
Quoted 10 lines
drivers/scsi/elx/efct/efct_driver.c new file +10
-0+ } + } + +if (i ==ARRAY_SIZE (efct_devices)) { +pr_err ("Exceeded max supported devices.\n" ); +kfree (efct); + efct =NULL ; + }else { + efct->attached = false; + }
Errm. This is wrong.
When we exit the for() loop above, i _will_ equal the array size. Surely you mean
if (i < ARRAY_SIZE())
right?
Quoted 358 lines
drivers/scsi/elx/efct/efct_driver.c new file +358
-0+ } +return efct; +} + +static void +efct_teardown_msix (struct efct *efct) +{ +u32 i; + +for (i =0 ; i < efct->n_msix_vec; i++) { +free_irq (pci_irq_vector (efct->pcidev, i), + &efct->intr_context[i]); + } + +pci_free_irq_vectors (efct->pcidev); +} + +static int +efct_efclib_config (struct efct *efct,struct libefc_function_template *tt) +{ +struct efc *efc; +struct sli4 *sli; +int rc =EFC_SUCCESS ; + + efc =kmalloc (sizeof (*efc),GFP_KERNEL ); +if (!efc) +return EFC_FAIL ; + +memset (efc,0 ,sizeof (struct efc )); + efct->efcport = efc; + +memcpy (&efc->tt, tt,sizeof (*tt)); + efc->base = efct; + efc->pcidev = efct->pcidev; + + efc->def_wwnn =efct_get_wwnn (&efct->hw); + efc->def_wwpn =efct_get_wwpn (&efct->hw); + efc->enable_tgt =1 ; + efc->log_level =EFC_LOG_LIB ; + + sli = &efct->hw.sli; + efc->max_xfer_size = sli->sge_supported_length * +sli_get_max_sgl (&efct->hw.sli); + + rc =efcport_init (efc); +if (rc) +efc_log_err (efc,"efcport_init failed\n" ); + +return rc; +} + +static int efct_request_firmware_update (struct efct *efct); + +static const char * +efct_pci_model (u16 device) +{ +switch (device) { +case EFCT_DEVICE_LANCER_G6 :return "LPE31004" ; +case EFCT_DEVICE_LANCER_G7 :return "LPE36000" ; +default :return "unknown" ; + } +} + +static int +efct_device_attach (struct efct *efct) +{ +u32 rc =0 , i =0 ; + +if (efct->attached) { +efc_log_err (efct,"Device is already attached\n" ); +return EFC_FAIL ; + } + +snprintf (efct->name,sizeof (efct->name),"[%s%d] " ,"fc" , + efct->instance_index); + + efct->logmask = logmask; + efct->filter_def ="0,0,0,0" ; + efct->max_isr_time_msec =EFCT_OS_MAX_ISR_TIME_MSEC ; + + efct->model =efct_pci_model (efct->pcidev->device); + + efct->efct_req_fw_upgrade = true; + +/* Allocate transport object and bring online */ + efct->xport =efct_xport_alloc (efct); +if (!efct->xport) { +efc_log_err (efct,"failed to allocate transport object\n" ); + rc = -ENOMEM ; + goto out; + } + + rc =efct_xport_attach (efct->xport); +if (rc) { +efc_log_err (efct,"failed to attach transport object\n" ); + goto xport_out; + } + + rc =efct_xport_initialize (efct->xport); +if (rc) { +efc_log_err (efct,"failed to initialize transport object\n" ); + goto xport_out; + } + + rc =efct_efclib_config (efct, &efct_libefc_templ); +if (rc) { +efc_log_err (efct,"failed to init efclib\n" ); + goto efclib_out; + } + +for (i =0 ; i < efct->n_msix_vec; i++) { +efc_log_debug (efct,"irq %d enabled\n" , i); +enable_irq (pci_irq_vector (efct->pcidev, i)); + } + + efct->attached = true; + +if (efct->efct_req_fw_upgrade) +efct_request_firmware_update (efct); + +return rc; + +efclib_out: +efct_xport_detach (efct->xport); +xport_out: +if (efct->xport) { +efct_xport_free (efct->xport); + efct->xport =NULL ; + } +out: +return rc; +} + +static int +efct_device_detach (struct efct *efct) +{ +int rc =0 , i; + +if (efct) { +if (!efct->attached) { +efc_log_warn (efct,"Device is not attached\n" ); +return EFC_FAIL ; + } + + rc =efct_xport_control (efct->xport,EFCT_XPORT_SHUTDOWN ); +if (rc) +efc_log_err (efct,"Transport Shutdown timed out\n" ); + +for (i =0 ; i < efct->n_msix_vec; i++) +disable_irq (pci_irq_vector (efct->pcidev, i)); + +if (efct_xport_detach (efct->xport) !=0 ) +efc_log_err (efct,"Transport detach failed\n" ); + +efct_xport_free (efct->xport); + efct->xport =NULL ; + +efcport_destroy (efct->efcport); +kfree (efct->efcport); + + efct->attached = false; + } + +return EFC_SUCCESS ; +} + +static void +efct_fw_write_cb (int status,u32 actual_write_length, +u32 change_status,void *arg) +{ +struct efct_fw_write_result *result = arg; + + result->status = status; + result->actual_xfer = actual_write_length; + result->change_status = change_status; + +complete (&result->done); +} + +static int +efct_firmware_write (struct efct *efct,const u8 *buf,size_t buf_len, +u8 *change_status) +{ +int rc =0 ; +u32 bytes_left; +u32 xfer_size; +u32 offset; +struct efc_dma dma; +int last =0 ; +struct efct_fw_write_result result; + +init_completion (&result.done); + + bytes_left = buf_len; + offset =0 ; + + dma.size =FW_WRITE_BUFSIZE ; + dma.virt =dma_alloc_coherent (&efct->pcidev->dev, + dma.size, &dma.phys,GFP_DMA ); +if (!dma.virt) +return -ENOMEM ; + +while (bytes_left >0 ) { +if (bytes_left >FW_WRITE_BUFSIZE ) + xfer_size =FW_WRITE_BUFSIZE ; +else + xfer_size = bytes_left; + +memcpy (dma.virt, buf + offset, xfer_size); + +if (bytes_left == xfer_size) + last =1 ; + +efct_hw_firmware_write (&efct->hw, &dma, xfer_size, offset, + last, efct_fw_write_cb, &result); + +if (wait_for_completion_interruptible (&result.done) !=0 ) { + rc = -ENXIO ; +break ; + } + +if (result.actual_xfer ==0 || result.status !=0 ) { + rc = -EFAULT ; +break ; + } + +if (last) + *change_status = result.change_status; + + bytes_left -= result.actual_xfer; + offset += result.actual_xfer; + } + +dma_free_coherent (&efct->pcidev->dev, dma.size, dma.virt, dma.phys); +return rc; +} + +/* +* Firmware reset to activate the new firmware. +* Function 0 will update and load the new firmware +* during attach. +*/ +static int +efct_fw_reset (struct efct *efct) +{ +int rc =0 ; + +if (timer_pending (&efct->xport->stats_timer)) +del_timer (&efct->xport->stats_timer); + +if (efct_hw_reset (&efct->hw,EFCT_HW_RESET_FIRMWARE )) { +efc_log_info (efct,"failed to reset firmware\n" ); + rc =-1 ; + }else { +efc_log_info (efct, +"successfully reset firmware.Now resetting port\n" ); + +efct_device_detach (efct); + rc =efct_device_attach (efct); + } +return rc; +} + +static int +efct_request_firmware_update (struct efct *efct) +{ +int rc =0 ; +u8 file_name[256 ], fw_change_status =0 ; +const struct firmware *fw; +struct efct_hw_grp_hdr *fw_image; + +snprintf (file_name,256 ,"%s.grp" , efct->model); + + rc =request_firmware (&fw, file_name, &efct->pcidev->dev); +if (rc) { +efc_log_debug (efct,"Firmware file(%s) not found.\n" , + file_name); +return rc; + } + + fw_image = (struct efct_hw_grp_hdr *)fw->data; + +if (!strncmp (efct->hw.sli.fw_name[0 ], fw_image->revision, +strnlen (fw_image->revision,16 ))) { +efc_log_debug (efct, +"Skipped update. Firmware is already up to date.\n" ); + goto exit; + } + +efc_log_info (efct,"Firmware update is initiated. %s -> %s\n" , + efct->hw.sli.fw_name[0 ], fw_image->revision); + + rc =efct_firmware_write (efct, fw->data, fw->size, &fw_change_status); +if (rc) { +efc_log_err (efct, +"Firmware update failed. Return code = %d\n" , rc); + goto exit; + } + +efc_log_info (efct,"Firmware updated successfully\n" ); +switch (fw_change_status) { +case 0x00 : +efc_log_info (efct,"New firmware is active.\n" ); +break ; +case 0x01 : +efc_log_info (efct, +"System reboot needed to activate the new firmware\n" ); +break ; +case 0x02 : +case 0x03 : +efc_log_info (efct, +"firmware is resetting to activate the new firmware\n" ); +efct_fw_reset (efct); +break ; +default : +efc_log_info (efct, +"Unexected value change_status:%d\n" , fw_change_status); +break ; + } + +exit: +release_firmware (fw); + +return rc; +} + +static void +efct_device_free (struct efct *efct) +{ +if (efct) { + efct_devices[efct->instance_index] =NULL ; + +kfree (efct); + } +} + +static int +efct_device_interrupts_required (struct efct *efct) +{ +if (efct_hw_setup (&efct->hw, efct, efct->pcidev) + !=EFCT_HW_RTN_SUCCESS ) { +return -1 ; + } + +return efct->hw.config.n_eq; +} + +static irqreturn_t +efct_intr_thread (int irq,void *handle) +{ +struct efct_intr_context *intr_ctx = handle; +struct efct *efct = intr_ctx->efct; + +efct_hw_process (&efct->hw, intr_ctx->index, efct->max_isr_time_msec); +return IRQ_HANDLED ; +} + +static irqreturn_t
drivers/scsi/elx/efct/efct_driver.c line 486
Quoted 10 lines
drivers/scsi/elx/efct/efct_driver.c new file +10
-0+efct_intr_msix(int irq, void *handle) +{ + return IRQ_WAKE_THREAD; +} + +static int +efct_setup_msix (struct efct *efct,u32 num_intrs) +{ +int rc =0 , i; +
Drop the tab between 'int' and 'rc'.
Quoted 708 lines
drivers/scsi/elx/efct/efct_driver.c new file +370
-0+if (!pci_find_capability (efct->pcidev,PCI_CAP_ID_MSIX )) { +dev_err (&efct->pcidev->dev, +"%s : MSI-X not available\n" , __func__); +return -EINVAL ; + } + + efct->n_msix_vec = num_intrs; + + rc =pci_alloc_irq_vectors (efct->pcidev, num_intrs, num_intrs, +PCI_IRQ_MSIX |PCI_IRQ_AFFINITY ); + +if (rc <0 ) { +dev_err (&efct->pcidev->dev,"Failed to alloc irq : %d\n" , rc); +return rc; + } + +for (i =0 ; i < num_intrs; i++) { +struct efct_intr_context *intr_ctx =NULL ; + + intr_ctx = &efct->intr_context[i]; + intr_ctx->efct = efct; + intr_ctx->index = i; + + rc =request_threaded_irq (pci_irq_vector (efct->pcidev, i), + efct_intr_msix, efct_intr_thread,0 , +EFCT_DRIVER_NAME , intr_ctx); +if (rc) { +dev_err (&efct->pcidev->dev, +"Failed to register %d vector: %d\n" , i, rc); + goto out; + } + } + +return rc; + +out: +while (--i >=0 ) +free_irq (pci_irq_vector (efct->pcidev, i), + &efct->intr_context[i]); + +pci_free_irq_vectors (efct->pcidev); +return rc; +} + +static struct pci_device_id efct_pci_table[] = { + {PCI_DEVICE (EFCT_VENDOR_ID ,EFCT_DEVICE_LANCER_G6 ),0 }, + {PCI_DEVICE (EFCT_VENDOR_ID ,EFCT_DEVICE_LANCER_G7 ),0 }, + {}/* terminate list */ +}; + +static int +efct_pci_probe (struct pci_dev *pdev,const struct pci_device_id *ent) +{ +struct efct *efct =NULL ; +int rc; +u32 i, r; +int num_interrupts =0 ; +int nid; + +dev_info (&pdev->dev,"%s\n" ,EFCT_DRIVER_NAME ); + + rc =pci_enable_device_mem (pdev); +if (rc) +return rc; + +pci_set_master (pdev); + + rc =pci_set_mwi (pdev); +if (rc) { +dev_info (&pdev->dev, +"pci_set_mwi returned %d\n" , rc); + goto mwi_out; + } + + rc =pci_request_regions (pdev,EFCT_DRIVER_NAME ); +if (rc) { +dev_err (&pdev->dev,"pci_request_regions failed %d\n" , rc); + goto req_regions_out; + } + +/* Fetch the Numa node id for this device */ + nid =dev_to_node (&pdev->dev); +if (nid <0 ) { +dev_err (&pdev->dev, +"Warning Numa node ID is %d\n" , nid); + nid =0 ; + } + +/* Allocate efct */ + efct =efct_device_alloc (nid); +if (!efct) { +dev_err (&pdev->dev,"Failed to allocate efct\n" ); + rc = -ENOMEM ; + goto alloc_out; + } + + efct->pcidev = pdev; + + efct->numa_node = nid; + +/* Map all memory BARs */ +for (i =0 , r =0 ; i <EFCT_PCI_MAX_REGS ; i++) { +if (pci_resource_flags (pdev, i) &IORESOURCE_MEM ) { + efct->reg[r] =ioremap (pci_resource_start (pdev, i), +pci_resource_len (pdev, i)); + r++; + } + +/* +* If the 64-bit attribute is set, both this BAR and the +* next form the complete address. Skip processing the +* next BAR. +*/ +if (pci_resource_flags (pdev, i) &IORESOURCE_MEM_64 ) + i++; + } + +pci_set_drvdata (pdev, efct); + +if (pci_set_dma_mask (pdev,DMA_BIT_MASK (64 )) !=0 || +pci_set_consistent_dma_mask (pdev,DMA_BIT_MASK (64 )) !=0 ) { +dev_warn (&pdev->dev, +"trying DMA_BIT_MASK(32)\n" ); +if (pci_set_dma_mask (pdev,DMA_BIT_MASK (32 )) !=0 || +pci_set_consistent_dma_mask (pdev,DMA_BIT_MASK (32 )) !=0 ) { +dev_err (&pdev->dev, +"setting DMA_BIT_MASK failed\n" ); + rc =-1 ; + goto dma_mask_out; + } + } + + num_interrupts =efct_device_interrupts_required (efct); +if (num_interrupts <0 ) { +efc_log_err (efct,"efct_device_interrupts_required failed\n" ); + rc =-1 ; + goto dma_mask_out; + } + +/* +* Initialize MSIX interrupts, note, +* efct_setup_msix() enables the interrupt +*/ + rc =efct_setup_msix (efct, num_interrupts); +if (rc) { +dev_err (&pdev->dev,"Can't setup msix\n" ); + goto dma_mask_out; + } +/* Disable interrupt for now */ +for (i =0 ; i < efct->n_msix_vec; i++) { +efc_log_debug (efct,"irq %d disabled\n" , i); +disable_irq (pci_irq_vector (efct->pcidev, i)); + } + + rc =efct_device_attach ((struct efct *)efct); +if (rc) + goto attach_out; + +return EFC_SUCCESS ; + +attach_out: +efct_teardown_msix (efct); +dma_mask_out: +pci_set_drvdata (pdev,NULL ); + +for (i =0 ; i <EFCT_PCI_MAX_REGS ; i++) { +if (efct->reg[i]) +iounmap (efct->reg[i]); + } +efct_device_free (efct); +alloc_out: +pci_release_regions (pdev); +req_regions_out: +pci_clear_mwi (pdev); +mwi_out: +pci_disable_device (pdev); +return rc; +} + +static void +efct_pci_remove (struct pci_dev *pdev) +{ +struct efct *efct =pci_get_drvdata (pdev); +u32 i; + +if (!efct) +return ; + +efct_device_detach (efct); + +efct_teardown_msix (efct); + +for (i =0 ; i <EFCT_PCI_MAX_REGS ; i++) { +if (efct->reg[i]) +iounmap (efct->reg[i]); + } + +pci_set_drvdata (pdev,NULL ); + + efct_devices[efct->instance_index] =NULL ; + +efct_device_free (efct); + +pci_release_regions (pdev); + +pci_disable_device (pdev); +} + +static void +efct_device_prep_for_reset (struct efct *efct,struct pci_dev *pdev) +{ +if (efct) { +efc_log_debug (efct, +"PCI channel disable preparing for reset\n" ); +efct_device_detach (efct); +/* Disable interrupt and pci device */ +efct_teardown_msix (efct); + } +pci_disable_device (pdev); +} + +static void +efct_device_prep_for_recover (struct efct *efct) +{ +if (efct) { +efc_log_debug (efct,"PCI channel preparing for recovery\n" ); +efct_hw_io_abort_all (&efct->hw); + } +} + +/** +* efct_pci_io_error_detected - method for handling PCI I/O error +* @pdev: pointer to PCI device. +* @state: the current PCI connection state. +* +* This routine is registered to the PCI subsystem for error handling. This +* function is called by the PCI subsystem after a PCI bus error affecting +* this device has been detected. When this routine is invoked, it dispatches +* device error detected handling routine, which will perform the proper +* error detected operation. +* +* Return codes +* PCI_ERS_RESULT_NEED_RESET - need to reset before recovery +* PCI_ERS_RESULT_DISCONNECT - device could not be recovered +*/ +static pci_ers_result_t +efct_pci_io_error_detected (struct pci_dev *pdev,pci_channel_state_t state) +{ +struct efct *efct =pci_get_drvdata (pdev); +pci_ers_result_t rc; + +switch (state) { +case pci_channel_io_normal: +efct_device_prep_for_recover (efct); + rc =PCI_ERS_RESULT_CAN_RECOVER ; +break ; +case pci_channel_io_frozen: +efct_device_prep_for_reset (efct, pdev); + rc =PCI_ERS_RESULT_NEED_RESET ; +break ; +case pci_channel_io_perm_failure: +efct_device_detach (efct); + rc =PCI_ERS_RESULT_DISCONNECT ; +break ; +default : +efc_log_debug (efct,"Unknown PCI error state:0x%x\n" , + state); +efct_device_prep_for_reset (efct, pdev); + rc =PCI_ERS_RESULT_NEED_RESET ; +break ; + } + +return rc; +} + +static pci_ers_result_t +efct_pci_io_slot_reset (struct pci_dev *pdev) +{ +int rc; +struct efct *efct =pci_get_drvdata (pdev); + + rc =pci_enable_device_mem (pdev); +if (rc) { +efc_log_err (efct, +"failed to re-enable PCI device after reset.\n" ); +return PCI_ERS_RESULT_DISCONNECT ; + } + +/* +* As the new kernel behavior of pci_restore_state() API call clears +* device saved_state flag, need to save the restored state again. +*/ + +pci_save_state (pdev); + +pci_set_master (pdev); + + rc =efct_setup_msix (efct, efct->n_msix_vec); +if (rc) +efc_log_err (efct,"rc %d returned, IRQ allocation failed\n" , + rc); + +/* Perform device reset */ +efct_device_detach (efct); +/* Bring device to online*/ +efct_device_attach (efct); + +return PCI_ERS_RESULT_RECOVERED ; +} + +static void +efct_pci_io_resume (struct pci_dev *pdev) +{ +struct efct *efct =pci_get_drvdata (pdev); + +/* Perform device reset */ +efct_device_detach (efct); +/* Bring device to online*/ +efct_device_attach (efct); +} + +MODULE_DEVICE_TABLE (pci, efct_pci_table); + +static struct pci_error_handlers efct_pci_err_handler = { + .error_detected = efct_pci_io_error_detected, + .slot_reset = efct_pci_io_slot_reset, + .resume = efct_pci_io_resume, +}; + +static struct pci_driver efct_pci_driver = { + .name =EFCT_DRIVER_NAME , + .id_table = efct_pci_table, + .probe = efct_pci_probe, + .remove = efct_pci_remove, + .err_handler = &efct_pci_err_handler, +}; + +static +int __init efct_init (void ) +{ +int rc = -ENODEV ; + + rc =efct_device_init (); +if (rc) { +pr_err ("efct_device_init failed rc=%d\n" , rc); +return -ENOMEM ; + } + + rc =pci_register_driver (&efct_pci_driver); +if (rc) + goto l1; + +return rc; + +l1: +efct_device_shutdown (); +return rc; +} + +static void __exit efct_exit(void) +{ +pci_unregister_driver (&efct_pci_driver); +efct_device_shutdown (); +} + +module_init (efct_init); +module_exit (efct_exit); +MODULE_VERSION (EFCT_DRIVER_VERSION ); +MODULE_LICENSE ("GPL" ); +MODULE_AUTHOR ("Broadcom" );drivers/scsi/elx/efct/efct_driver.h new file +142
-0@@ -0,0 +1,142 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2019 Broadcom. All Rights Reserved. The term +* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +*/ + +#if !defined(__EFCT_DRIVER_H__) +#define __EFCT_DRIVER_H__ + +/*************************************************************************** +* OS specific includes +*/ +#include <stdarg.h> +#include <linux/version.h> +#include <linux/init.h> +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/list.h> +#include <linux/interrupt.h> +#include <asm-generic/ioctl.h> +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/pci.h> +#include <linux/dma-mapping.h> +#include <linux/bitmap.h> +#include <linux/slab.h> +#include <linux/spinlock.h> +#include <asm/byteorder.h> +#include <linux/timer.h> +#include <linux/delay.h> +#include <linux/fs.h> +#include <linux/uaccess.h> +#include <linux/sched.h> +#include <asm/current.h> +#include <asm/cacheflush.h> +#include <linux/pagemap.h> +#include <linux/kthread.h> +#include <linux/proc_fs.h> +#include <linux/seq_file.h> +#include <linux/random.h> +#include <linux/sched.h> +#include <linux/jiffies.h> +#include <linux/ctype.h> +#include <linux/debugfs.h> +#include <linux/firmware.h> +#include <linux/sched/signal.h> +#include "../include/efc_common.h" + +#define EFCT_DRIVER_NAME "efct" +#define EFCT_DRIVER_VERSION "1.0.0.0" + +/* EFCT_OS_MAX_ISR_TIME_MSEC - +* maximum time driver code should spend in an interrupt +* or kernel thread context without yielding +*/ +#define EFCT_OS_MAX_ISR_TIME_MSEC 1000 + +#define EFCT_FC_MAX_SGL 64 +#define EFCT_FC_DIF_SEED 0 + +/* Timeouts */ +#define EFCT_FC_ELS_SEND_DEFAULT_TIMEOUT 0 +#define EFCT_FC_ELS_DEFAULT_RETRIES 3 +#define EFCT_FC_FLOGI_TIMEOUT_SEC 5 +#define EFCT_FC_DOMAIN_SHUTDOWN_TIMEOUT_USEC 30000000/* 30 seconds */ + +/* Watermark */ +#define EFCT_WATERMARK_HIGH_PCT 90 +#define EFCT_WATERMARK_LOW_PCT 80 +#define EFCT_IO_WATERMARK_PER_INITIATOR 8 + +#include "../libefc/efclib.h" +#include "efct_hw.h" +#include "efct_io.h" +#include "efct_xport.h" + +#define EFCT_PCI_MAX_REGS 6 +#define MAX_PCI_INTERRUPTS 16 + +struct efct_intr_context { +struct efct *efct; +u32 index; +}; + +struct efct { +struct pci_dev *pcidev; +void __iomem *reg[EFCT_PCI_MAX_REGS ]; + +u32 n_msix_vec; +struct efct_intr_context intr_context[MAX_PCI_INTERRUPTS ]; +u32 numa_node; + +char name[EFC_NAME_LENGTH ]; +bool attached; +struct efct_scsi_tgt tgt_efct; +struct efct_xport *xport; +struct efc *efcport; +struct Scsi_Host *shost; +int logmask; +u32 max_isr_time_msec; + +const char *desc; +u32 instance_index; + +const char *model; + +struct efct_hw hw; + +u32 num_vports; +u32 rq_selection_policy; +char *filter_def; + +bool soft_wwn_enable; + +/* +* Target IO timer value: +* Zero: target command timeout disabled. +* Non-zero: Timeout value, in seconds, for target commands +*/ +u32 target_io_timer_sec; + +int speed; +int topology; + +u8 efct_req_fw_upgrade; +u16 sw_feature_cap; +struct dentry *sess_debugfs_dir; +}; + +#define FW_WRITE_BUFSIZE (64 * 1024) + +struct efct_fw_write_result { +struct completion done; +int status; +u32 actual_xfer; +u32 change_status; +}; + +#define MAX_EFCT_DEVICES 64 +extern struct efct *efct_devices[MAX_EFCT_DEVICES ]; + +#endif /* __EFCT_DRIVER_H__ */ drivers/scsi/elx/efct/efct_hw.c new file +184
-0@@ -0,0 +1,1116 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2019 Broadcom. All Rights Reserved. The term +* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +*/ + +#include "efct_driver.h" +#include "efct_hw.h" + +static enum efct_hw_rtn +efct_hw_link_event_init (struct efct_hw *hw) +{ + hw->link.status =SLI_LINK_STATUS_MAX ; + hw->link.topology =SLI_LINK_TOPO_NONE ; + hw->link.medium =SLI_LINK_MEDIUM_MAX ; + hw->link.speed =0 ; + hw->link.loop_map =NULL ; + hw->link.fc_id =U32_MAX ; + +return EFCT_HW_RTN_SUCCESS ; +} + +static enum efct_hw_rtn +efct_hw_read_max_dump_size (struct efct_hw *hw) +{ +u8 buf[SLI4_BMBX_SIZE ]; +struct efct *efct = hw->os; +int rc =EFCT_HW_RTN_SUCCESS ; +struct sli4_rsp_cmn_set_dump_location *rsp; + +/* attempt to detemine the dump size for function 0 only. */ +if (PCI_FUNC (efct->pcidev->devfn) !=0 ) +return rc; + + rc =sli_cmd_common_set_dump_location (&hw->sli, buf,SLI4_BMBX_SIZE ,1 , +0 ,NULL ,0 ); +if (rc) +return rc; + + rsp = (struct sli4_rsp_cmn_set_dump_location *) + (buf + offsetof(struct sli4_cmd_sli_config, payload.embed)); + + rc =efct_hw_command (hw, buf,EFCT_CMD_POLL ,NULL ,NULL ); +if (rc !=EFCT_HW_RTN_SUCCESS ) { +efc_log_test (hw->os,"set dump location cmd failed\n" ); +return rc; + } + hw->dump_size = (le32_to_cpu (rsp->buffer_length_dword) & +SLI4_CMN_SET_DUMP_BUFFER_LEN ); +efc_log_debug (hw->os,"Dump size %x\n" , hw->dump_size); + +return rc; +} + +static int +__efct_read_topology_cb (struct efct_hw *hw,int status, +u8 *mqe,void *arg) +{ +struct sli4_cmd_read_topology *read_topo = + (struct sli4_cmd_read_topology *)mqe; +u8 speed; +struct efc_domain_record drec = {0 }; +struct efct *efct = hw->os; + +if (status ||le16_to_cpu (read_topo->hdr.status)) { +efc_log_debug (hw->os,"bad status cqe=%#x mqe=%#x\n" , + status, +le16_to_cpu (read_topo->hdr.status)); +kfree (mqe); +return EFC_FAIL ; + } + +switch (le32_to_cpu (read_topo->dw2_attentype) & +SLI4_READTOPO_ATTEN_TYPE ) { +case SLI4_READ_TOPOLOGY_LINK_UP : + hw->link.status =SLI_LINK_STATUS_UP ; +break ; +case SLI4_READ_TOPOLOGY_LINK_DOWN : + hw->link.status =SLI_LINK_STATUS_DOWN ; +break ; +case SLI4_READ_TOPOLOGY_LINK_NO_ALPA : + hw->link.status =SLI_LINK_STATUS_NO_ALPA ; +break ; +default : + hw->link.status =SLI_LINK_STATUS_MAX ; +break ; + } + +switch (read_topo->topology) { +case SLI4_READ_TOPOLOGY_NPORT : + hw->link.topology =SLI_LINK_TOPO_NPORT ; +break ; +case SLI4_READ_TOPOLOGY_FC_AL : + hw->link.topology =SLI_LINK_TOPO_LOOP ; +if (hw->link.status ==SLI_LINK_STATUS_UP ) + hw->link.loop_map = hw->loop_map.virt; + hw->link.fc_id = read_topo->acquired_al_pa; +break ; +default : + hw->link.topology =SLI_LINK_TOPO_MAX ; +break ; + } + + hw->link.medium =SLI_LINK_MEDIUM_FC ; + + speed = (le32_to_cpu (read_topo->currlink_state) & +SLI4_READTOPO_LINKSTATE_SPEED ) >>8 ; +switch (speed) { +case SLI4_READ_TOPOLOGY_SPEED_1G : + hw->link.speed =1 *1000 ; +break ; +case SLI4_READ_TOPOLOGY_SPEED_2G : + hw->link.speed =2 *1000 ; +break ; +case SLI4_READ_TOPOLOGY_SPEED_4G : + hw->link.speed =4 *1000 ; +break ; +case SLI4_READ_TOPOLOGY_SPEED_8G : + hw->link.speed =8 *1000 ; +break ; +case SLI4_READ_TOPOLOGY_SPEED_16G : + hw->link.speed =16 *1000 ; + hw->link.loop_map =NULL ; +break ; +case SLI4_READ_TOPOLOGY_SPEED_32G : + hw->link.speed =32 *1000 ; + hw->link.loop_map =NULL ; +break ; + } + +kfree (mqe); + + drec.speed = hw->link.speed; + drec.fc_id = hw->link.fc_id; + drec.is_nport = true; +efc_domain_cb (efct->efcport,EFC_HW_DOMAIN_FOUND , &drec); + +return EFC_SUCCESS ; +} + +/* Callback function for the SLI link events */ +static int +efct_hw_cb_link (void *ctx,void *e) +{ +struct efct_hw *hw = ctx; +struct sli4_link_event *event = e; +struct efc_domain *d =NULL ; +int rc =EFCT_HW_RTN_ERROR ; +struct efct *efct = hw->os; +struct efc_dma *dma; + +efct_hw_link_event_init (hw); + +switch (event->status) { +case SLI_LINK_STATUS_UP : + + hw->link = *event; + efct->efcport->link_status =EFC_LINK_STATUS_UP ; + +if (event->topology ==SLI_LINK_TOPO_NPORT ) { +struct efc_domain_record drec = {0 }; + +efc_log_info (hw->os,"Link Up, NPORT, speed is %d\n" , + event->speed); + drec.speed = event->speed; + drec.fc_id = event->fc_id; + drec.is_nport = true; +efc_domain_cb (efct->efcport,EFC_HW_DOMAIN_FOUND , + &drec); + }else if (event->topology ==SLI_LINK_TOPO_LOOP ) { +u8 *buf =NULL ; + +efc_log_info (hw->os,"Link Up, LOOP, speed is %d\n" , + event->speed); + dma = &hw->loop_map; + dma->size =SLI4_MIN_LOOP_MAP_BYTES ; + dma->virt =dma_alloc_coherent (&efct->pcidev->dev, + dma->size, &dma->phys, +GFP_DMA ); +if (!dma->virt) +efc_log_err (hw->os,"efct_dma_alloc_fail\n" ); + + buf =kmalloc (SLI4_BMBX_SIZE ,GFP_ATOMIC ); +if (!buf)
drivers/scsi/elx/efct/efct_hw.c line 194
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw.c new file +10
-0+break ; + +if (!sli_cmd_read_topology (&hw->sli, buf, +SLI4_BMBX_SIZE , + &hw->loop_map)) { + rc =efct_hw_command (hw, buf,EFCT_CMD_NOWAIT , + __efct_read_topology_cb, +NULL ); + } +
Not sure if this is a good idea; we'll have to allocate extra memory whenever the loop topology changes.
Which typically happens when there had been a failure somewhere, and chances are that it'll affect our root fs, making memory allocation something we really need to look at. Can't we pre-allocate a buffer here somewhere in the global initialisation so that we don't have to allocate it every time?
Quoted 1,334 lines
drivers/scsi/elx/efct/efct_hw.c new file +922
-0+if (rc !=EFCT_HW_RTN_SUCCESS ) { +efc_log_test (hw->os,"READ_TOPOLOGY failed\n" ); +kfree (buf); + } + }else { +efc_log_info (hw->os,"%s(%#x), speed is %d\n" , +"Link Up, unsupported topology " , + event->topology, event->speed); + } +break ; +case SLI_LINK_STATUS_DOWN : +efc_log_info (hw->os,"Link down\n" ); + + hw->link.status = event->status; + efct->efcport->link_status =EFC_LINK_STATUS_DOWN ; + + d = hw->domain; +if (d) +efc_domain_cb (efct->efcport,EFC_HW_DOMAIN_LOST , d); +break ; +default : +efc_log_test (hw->os,"unhandled link status %#x\n" , + event->status); +break ; + } + +return EFC_SUCCESS ; +} + +enum efct_hw_rtn +efct_hw_setup (struct efct_hw *hw,void *os,struct pci_dev *pdev) +{ +u32 i, max_sgl; + +if (hw->hw_setup_called) +return EFCT_HW_RTN_SUCCESS ; + +/* +* efct_hw_init() relies on NULL pointers indicating that a structure +* needs allocation. If a structure is non-NULL, efct_hw_init() won't +* free/realloc that memory +*/ +memset (hw,0 ,sizeof (struct efct_hw )); + + hw->hw_setup_called = true; + + hw->os = os; + +spin_lock_init (&hw->cmd_lock); +INIT_LIST_HEAD (&hw->cmd_head); +INIT_LIST_HEAD (&hw->cmd_pending); + hw->cmd_head_count =0 ; + +spin_lock_init (&hw->io_lock); +spin_lock_init (&hw->io_abort_lock); + +atomic_set (&hw->io_alloc_failed_count,0 ); + + hw->config.speed =FC_LINK_SPEED_AUTO_16_8_4 ; +if (sli_setup (&hw->sli, hw->os, pdev, ((struct efct *)os)->reg)) { +efc_log_err (hw->os,"SLI setup failed\n" ); +return EFCT_HW_RTN_ERROR ; + } + +efct_hw_link_event_init (hw); + +sli_callback (&hw->sli,SLI4_CB_LINK , efct_hw_cb_link, hw); + +/* +* Set all the queue sizes to the maximum allowed. +*/ +for (i =0 ; i <ARRAY_SIZE (hw->num_qentries); i++) + hw->num_qentries[i] = hw->sli.qinfo.max_qentries[i]; +/* +* Adjust the the size of the WQs so that the CQ is twice as +* big as the WQ to allow for 2 completions per IO. This allows us to +* handle multi-phase as well as aborts. +*/ + hw->num_qentries[SLI_QTYPE_WQ ] = hw->num_qentries[SLI_QTYPE_CQ ] /2 ; + +/* +* The RQ assignment for RQ pair mode. +*/ + hw->config.rq_default_buffer_size =EFCT_HW_RQ_SIZE_PAYLOAD ; + hw->config.n_io = hw->sli.extent[SLI_RSRC_XRI ].size; + hw->config.n_eq =EFCT_HW_DEF_NUM_EQ ; + + max_sgl =sli_get_max_sgl (&hw->sli) -SLI4_SGE_MAX_RESERVED ; + max_sgl = (max_sgl >EFCT_FC_MAX_SGL ) ?EFCT_FC_MAX_SGL : max_sgl; + hw->config.n_sgl = max_sgl; + + (void )efct_hw_read_max_dump_size (hw); + +return EFCT_HW_RTN_SUCCESS ; +} + +static void +efct_logfcfi (struct efct_hw *hw,u32 j,u32 i,u32 id) +{ +efc_log_info (hw->os, +"REG_FCFI: filter[%d] %08X -> RQ[%d] id=%d\n" , + j, hw->config.filter_def[j], i, id); +} + +static inline void +efct_hw_init_free_io (struct efct_hw_io *io) +{ +/* +* Set io->done to NULL, to avoid any callbacks, should +* a completion be received for one of these IOs +*/ + io->done =NULL ; + io->abort_done =NULL ; + io->status_saved = false; + io->abort_in_progress = false; + io->rnode =NULL ; + io->type =0xFFFF ; + io->wq =NULL ; + io->ul_io =NULL ; + io->tgt_wqe_timeout =0 ; +} + +static u8 efct_hw_iotype_is_originator (u16 io_type) +{ +switch (io_type) { +case EFCT_HW_FC_CT : +case EFCT_HW_ELS_REQ : +return 1 ; +default : +return EFC_SUCCESS ; + } +} + +static void +efct_hw_io_restore_sgl (struct efct_hw *hw,struct efct_hw_io *io) +{ +/* Restore the default */ + io->sgl = &io->def_sgl; + io->sgl_count = io->def_sgl_count; + +/* Clear the overflow SGL */ + io->ovfl_sgl =NULL ; + io->ovfl_sgl_count =0 ; + io->ovfl_lsp =NULL ; +} + +static void +efct_hw_wq_process_io (void *arg,u8 *cqe,int status) +{ +struct efct_hw_io *io = arg; +struct efct_hw *hw = io->hw; +struct sli4_fc_wcqe *wcqe = (void *)cqe; +u32 len =0 ; +u32 ext =0 ; + +/* clear xbusy flag if WCQE[XB] is clear */ +if (io->xbusy && (wcqe->flags &SLI4_WCQE_XB ) ==0 ) + io->xbusy = false; + +/* get extended CQE status */ +switch (io->type) { +case EFCT_HW_BLS_ACC : +case EFCT_HW_BLS_ACC_SID : +break ; +case EFCT_HW_ELS_REQ : +sli_fc_els_did (&hw->sli, cqe, &ext); + len =sli_fc_response_length (&hw->sli, cqe); +break ; +case EFCT_HW_ELS_RSP : +case EFCT_HW_ELS_RSP_SID : +case EFCT_HW_FC_CT_RSP : +break ; +case EFCT_HW_FC_CT : + len =sli_fc_response_length (&hw->sli, cqe); +break ; +case EFCT_HW_IO_TARGET_WRITE : + len =sli_fc_io_length (&hw->sli, cqe); +break ; +case EFCT_HW_IO_TARGET_READ : + len =sli_fc_io_length (&hw->sli, cqe); +break ; +case EFCT_HW_IO_TARGET_RSP : +break ; +case EFCT_HW_IO_DNRX_REQUEUE : +/* release the count for re-posting the buffer */ +/* efct_hw_io_free(hw, io); */ +break ; +default : +efc_log_test (hw->os,"unhandled io type %#x for XRI 0x%x\n" , + io->type, io->indicator); +break ; + } +if (status) { + ext =sli_fc_ext_status (&hw->sli, cqe); +/* +* If we're not an originator IO, and XB is set, then issue +* abort for the IO from within the HW +*/ +if ((!efct_hw_iotype_is_originator (io->type)) && + wcqe->flags &SLI4_WCQE_XB ) { +enum efct_hw_rtn rc; + +efc_log_debug (hw->os,"aborting xri=%#x tag=%#x\n" , + io->indicator, io->reqtag); + +/* +* Because targets may send a response when the IO +* completes using the same XRI, we must wait for the +* XRI_ABORTED CQE to issue the IO callback +*/ + rc =efct_hw_io_abort (hw, io, false,NULL ,NULL ); +if (rc ==EFCT_HW_RTN_SUCCESS ) { +/* +* latch status to return after abort is +* complete +*/ + io->status_saved = true; + io->saved_status = status; + io->saved_ext = ext; + io->saved_len = len; + goto exit_efct_hw_wq_process_io; + }else if (rc ==EFCT_HW_RTN_IO_ABORT_IN_PROGRESS ) { +/* +* Already being aborted by someone else (ABTS +* perhaps). Just fall thru and return original +* error. +*/ +efc_log_debug (hw->os,"%s%#x tag=%#x\n" , +"abort in progress xri=" , + io->indicator, io->reqtag); + + }else { +/* Failed to abort for some other reason, log +* error +*/ +efc_log_test (hw->os,"%s%#x tag=%#x rc=%d\n" , +"Failed to abort xri=" , + io->indicator, io->reqtag, rc); + } + } + } + +if (io->done) { +efct_hw_done_t done = io->done; +void *arg = io->arg; + + io->done =NULL ; + +if (io->status_saved) { +/* use latched status if exists */ + status = io->saved_status; + len = io->saved_len; + ext = io->saved_ext; + io->status_saved = false; + } + +/* Restore default SGL */ +efct_hw_io_restore_sgl (hw, io); +done (io, io->rnode, len, status, ext, arg); + } + +exit_efct_hw_wq_process_io: +return ; +} + +/* Initialize the pool of HW IO objects */ +static enum efct_hw_rtn +efct_hw_setup_io (struct efct_hw *hw) +{ +u32 i =0 ; +struct efct_hw_io *io =NULL ; +uintptr_t xfer_virt =0 ; +uintptr_t xfer_phys =0 ; +u32 index; +bool new_alloc = true; +struct efc_dma *dma; +struct efct *efct = hw->os; + +if (!hw->io) { + hw->io =kmalloc_array (hw->config.n_io,sizeof (io), +GFP_KERNEL ); + +if (!hw->io) +return EFCT_HW_RTN_NO_MEMORY ; + +memset (hw->io,0 , hw->config.n_io *sizeof (io)); + +for (i =0 ; i < hw->config.n_io; i++) { + hw->io[i] =kmalloc (sizeof (*io),GFP_KERNEL ); +if (!hw->io[i]) + goto error; + +memset (hw->io[i],0 ,sizeof (struct efct_hw_io )); + } + +/* Create WQE buffs for IO */ + hw->wqe_buffs =kmalloc ((hw->config.n_io * + hw->sli.wqe_size), +GFP_ATOMIC ); +if (!hw->wqe_buffs) { +kfree (hw->io); +return EFCT_HW_RTN_NO_MEMORY ; + } +memset (hw->wqe_buffs,0 , (hw->config.n_io * + hw->sli.wqe_size)); + + }else { +/* re-use existing IOs, including SGLs */ + new_alloc = false; + } + +if (new_alloc) { + dma = &hw->xfer_rdy; + dma->size =sizeof (struct fcp_txrdy ) * hw->config.n_io; + dma->virt =dma_alloc_coherent (&efct->pcidev->dev, + dma->size, &dma->phys,GFP_DMA ); +if (!dma->virt) +return EFCT_HW_RTN_NO_MEMORY ; + } + xfer_virt = (uintptr_t )hw->xfer_rdy.virt; + xfer_phys = hw->xfer_rdy.phys; + +for (i =0 ; i < hw->config.n_io; i++) { +struct hw_wq_callback *wqcb; + + io = hw->io[i]; + +/* initialize IO fields */ + io->hw = hw; + +/* Assign a WQE buff */ + io->wqe.wqebuf = &hw->wqe_buffs[i * hw->sli.wqe_size]; + +/* Allocate the request tag for this IO */ + wqcb =efct_hw_reqtag_alloc (hw, efct_hw_wq_process_io, io); +if (!wqcb) { +efc_log_err (hw->os,"can't allocate request tag\n" ); +return EFCT_HW_RTN_NO_RESOURCES ; + } + io->reqtag = wqcb->instance_index; + +/* Now for the fields that are initialized on each free */ +efct_hw_init_free_io (io); + +/* The XB flag isn't cleared on IO free, so init to zero */ + io->xbusy =0 ; + +if (sli_resource_alloc (&hw->sli,SLI_RSRC_XRI , + &io->indicator, &index)) { +efc_log_err (hw->os, +"sli_resource_alloc failed @ %d\n" , i); +return EFCT_HW_RTN_NO_MEMORY ; + } +if (new_alloc) { + dma = &io->def_sgl; + dma->size = hw->config.n_sgl * +sizeof (struct sli4_sge ); + dma->virt =dma_alloc_coherent (&efct->pcidev->dev, + dma->size, &dma->phys, +GFP_DMA ); +if (!dma->virt) { +efc_log_err (hw->os,"dma_alloc fail %d\n" , i); +memset (&io->def_sgl,0 , +sizeof (struct efc_dma )); +return EFCT_HW_RTN_NO_MEMORY ; + } + } + io->def_sgl_count = hw->config.n_sgl; + io->sgl = &io->def_sgl; + io->sgl_count = io->def_sgl_count; + +if (hw->xfer_rdy.size) { + io->xfer_rdy.virt = (void *)xfer_virt; + io->xfer_rdy.phys = xfer_phys; + io->xfer_rdy.size =sizeof (struct fcp_txrdy ); + + xfer_virt +=sizeof (struct fcp_txrdy ); + xfer_phys +=sizeof (struct fcp_txrdy ); + } + } + +return EFCT_HW_RTN_SUCCESS ; +error: +for (i =0 ; i < hw->config.n_io && hw->io[i]; i++) { +kfree (hw->io[i]); + hw->io[i] =NULL ; + } + +kfree (hw->io); + hw->io =NULL ; + +return EFCT_HW_RTN_NO_MEMORY ; +} + +static enum efct_hw_rtn +efct_hw_init_io (struct efct_hw *hw) +{ +u32 i =0 , io_index =0 ; +bool prereg = false; +struct efct_hw_io *io =NULL ; +u8 cmd[SLI4_BMBX_SIZE ]; +enum efct_hw_rtn rc =EFCT_HW_RTN_SUCCESS ; +u32 nremaining; +u32 n =0 ; +u32 sgls_per_request =256 ; +struct efc_dma **sgls =NULL ; +struct efc_dma reqbuf; +struct efct *efct = hw->os; + + prereg = hw->sli.sgl_pre_registered; + +memset (&reqbuf,0 ,sizeof (struct efc_dma )); +if (prereg) { + sgls =kmalloc_array (sgls_per_request,sizeof (*sgls), +GFP_ATOMIC ); +if (!sgls) +return EFCT_HW_RTN_NO_MEMORY ; + + reqbuf.size =32 + sgls_per_request *16 ; + reqbuf.virt =dma_alloc_coherent (&efct->pcidev->dev, + reqbuf.size, &reqbuf.phys, +GFP_DMA ); +if (!reqbuf.virt) { +efc_log_err (hw->os,"dma_alloc reqbuf failed\n" ); +kfree (sgls); +return EFCT_HW_RTN_NO_MEMORY ; + } + } + +for (nremaining = hw->config.n_io; nremaining; nremaining -= n) { +if (prereg) { +/* Copy address of SGL's into local sgls[] array, break +* out if the xri is not contiguous. +*/ +u32 min = (sgls_per_request < nremaining) + ? sgls_per_request : nremaining; +for (n =0 ; n < min; n++) { +/* Check that we have contiguous xri values */ +if (n >0 ) { +if (hw->io[io_index + n]->indicator != + hw->io[io_index + n -1 ]->indicator + +1 ) +break ; + } + sgls[n] = hw->io[io_index + n]->sgl; + } + +if (!sli_cmd_post_sgl_pages (&hw->sli, cmd, +sizeof (cmd), + hw->io[io_index]->indicator, + n, sgls,NULL , &reqbuf)) { +if (efct_hw_command (hw, cmd,EFCT_CMD_POLL , +NULL ,NULL )) { + rc =EFCT_HW_RTN_ERROR ; +efc_log_err (hw->os, +"SGL post failed\n" ); +break ; + } + } + }else { + n = nremaining; + } + +/* Add to tail if successful */ +for (i =0 ; i < n; i++, io_index++) { + io = hw->io[io_index]; + io->state =EFCT_HW_IO_STATE_FREE ; +INIT_LIST_HEAD (&io->list_entry); +list_add_tail (&io->list_entry, &hw->io_free); + } + } + +if (prereg) { +dma_free_coherent (&efct->pcidev->dev, + reqbuf.size, reqbuf.virt, reqbuf.phys); +memset (&reqbuf,0 ,sizeof (struct efc_dma )); +kfree (sgls); + } + +return rc; +} + +static enum efct_hw_rtn +efct_hw_config_set_fdt_xfer_hint (struct efct_hw *hw,u32 fdt_xfer_hint) +{ +enum efct_hw_rtn rc =EFCT_HW_RTN_SUCCESS ; +u8 buf[SLI4_BMBX_SIZE ]; +struct sli4_rqst_cmn_set_features_set_fdt_xfer_hint param; + +memset (¶m,0 ,sizeof (param)); + param.fdt_xfer_hint =cpu_to_le32 (fdt_xfer_hint); +/* build the set_features command */ +sli_cmd_common_set_features (&hw->sli, buf,SLI4_BMBX_SIZE , +SLI4_SET_FEATURES_SET_FTD_XFER_HINT , +sizeof (param), + ¶m); + + rc =efct_hw_command (hw, buf,EFCT_CMD_POLL ,NULL ,NULL ); +if (rc) +efc_log_warn (hw->os,"set FDT hint %d failed: %d\n" , + fdt_xfer_hint, rc); +else +efc_log_info (hw->os,"Set FTD transfer hint to %d\n" , +le32_to_cpu (param.fdt_xfer_hint)); + +return rc; +} + +static int +efct_hw_config_rq (struct efct_hw *hw) +{ +u32 min_rq_count, i, rc; +struct sli4_cmd_rq_cfg rq_cfg[SLI4_CMD_REG_FCFI_NUM_RQ_CFG ]; +u8 buf[SLI4_BMBX_SIZE ]; + +efc_log_info (hw->os,"using REG_FCFI standard\n" ); + +/* +* Set the filter match/mask values from hw's +* filter_def values +*/ +for (i =0 ; i <SLI4_CMD_REG_FCFI_NUM_RQ_CFG ; i++) { + rq_cfg[i].rq_id =cpu_to_le16 (0xffff ); + rq_cfg[i].r_ctl_mask = (u8 )hw->config.filter_def[i]; + rq_cfg[i].r_ctl_match = (u8)(hw->config.filter_def[i] >>8 ); + rq_cfg[i].type_mask = (u8)(hw->config.filter_def[i] >>16 ); + rq_cfg[i].type_match = (u8)(hw->config.filter_def[i] >>24 ); + } + +/* +* Update the rq_id's of the FCF configuration +* (don't update more than the number of rq_cfg +* elements) +*/ + min_rq_count = (hw->hw_rq_count <SLI4_CMD_REG_FCFI_NUM_RQ_CFG ) ? + hw->hw_rq_count :SLI4_CMD_REG_FCFI_NUM_RQ_CFG ; +for (i =0 ; i < min_rq_count; i++) { +struct hw_rq *rq = hw->hw_rq[i]; +u32 j; + +for (j =0 ; j <SLI4_CMD_REG_FCFI_NUM_RQ_CFG ; j++) { +u32 mask = (rq->filter_mask !=0 ) ? + rq->filter_mask :1 ; + +if (!(mask & (1U << j))) +continue ; + + rq_cfg[j].rq_id =cpu_to_le16 (rq->hdr->id); +efct_logfcfi (hw, j, i, rq->hdr->id); + } + } + + rc =EFCT_HW_RTN_ERROR ; +if (!sli_cmd_reg_fcfi (&hw->sli, buf, +SLI4_BMBX_SIZE ,0 , + rq_cfg)) { + rc =efct_hw_command (hw, buf,EFCT_CMD_POLL , +NULL ,NULL ); + } + +if (rc !=EFCT_HW_RTN_SUCCESS ) { +efc_log_err (hw->os, +"FCFI registration failed\n" ); +return rc; + } + hw->fcf_indicator = +le16_to_cpu (((struct sli4_cmd_reg_fcfi *)buf)->fcfi); + +return rc; +} + +static void +efct_hw_queue_hash_add (struct efct_queue_hash *hash, +u16 id,u16 index) +{ +u32 hash_index = id & (EFCT_HW_Q_HASH_SIZE -1 ); + +/* +* Since the hash is always bigger than the number of queues, then we +* never have to worry about an infinite loop. +*/ +while (hash[hash_index].in_use) + hash_index = (hash_index +1 ) & (EFCT_HW_Q_HASH_SIZE -1 ); + +/* not used, claim the entry */ + hash[hash_index].id = id; + hash[hash_index].in_use = true; + hash[hash_index].index = index; +} + +/* enable sli port health check */ +static enum efct_hw_rtn +efct_hw_config_sli_port_health_check (struct efct_hw *hw,u8 query, +u8 enable) +{ +enum efct_hw_rtn rc =EFCT_HW_RTN_SUCCESS ; +u8 buf[SLI4_BMBX_SIZE ]; +struct sli4_rqst_cmn_set_features_health_check param; +u32 health_check_flag =0 ; + +memset (¶m,0 ,sizeof (param)); + +if (enable) + health_check_flag |=SLI4_RQ_HEALTH_CHECK_ENABLE ; + +if (query) + health_check_flag |=SLI4_RQ_HEALTH_CHECK_QUERY ; + + param.health_check_dword =cpu_to_le32 (health_check_flag); + +/* build the set_features command */ +sli_cmd_common_set_features (&hw->sli, buf,SLI4_BMBX_SIZE , +SLI4_SET_FEATURES_SLI_PORT_HEALTH_CHECK , +sizeof (param), + ¶m); + + rc =efct_hw_command (hw, buf,EFCT_CMD_POLL ,NULL ,NULL ); +if (rc) +efc_log_err (hw->os,"efct_hw_command returns %d\n" , rc); +else +efc_log_test (hw->os,"SLI Port Health Check is enabled\n" ); + +return rc; +} + +enum efct_hw_rtn +efct_hw_init (struct efct_hw *hw) +{ +enum efct_hw_rtn rc; +u32 i =0 ; +u32 max_rpi; +int rem_count; +unsigned long flags =0 ; +struct efct_hw_io *temp; +struct sli4 *sli = &hw->sli; +struct hw_rq *rq; + +/* +* Make sure the command lists are empty. If this is start-of-day, +* they'll be empty since they were just initialized in efct_hw_setup. +* If we've just gone through a reset, the command and command pending +* lists should have been cleaned up as part of the reset +* (efct_hw_reset()). +*/ +spin_lock_irqsave (&hw->cmd_lock, flags); +if (!list_empty (&hw->cmd_head)) { +efc_log_err (hw->os,"command found on cmd list\n" ); +spin_unlock_irqrestore (&hw->cmd_lock, flags); +return EFCT_HW_RTN_ERROR ; + } +if (!list_empty (&hw->cmd_pending)) { +efc_log_err (hw->os, +"command found on pending list\n" ); +spin_unlock_irqrestore (&hw->cmd_lock, flags); +return EFCT_HW_RTN_ERROR ; + } +spin_unlock_irqrestore (&hw->cmd_lock, flags); + +/* Free RQ buffers if prevously allocated */ +efct_hw_rx_free (hw); + +/* +* The IO queues must be initialized here for the reset case. The +* efct_hw_init_io() function will re-add the IOs to the free list. +* The cmd_head list should be OK since we free all entries in +* efct_hw_command_cancel() that is called in the efct_hw_reset(). +*/ + +/* If we are in this function due to a reset, there may be stale items +* on lists that need to be removed. Clean them up. +*/ + rem_count =0 ; +if (hw->io_wait_free.next) { +while ((!list_empty (&hw->io_wait_free))) { + rem_count++; + temp =list_first_entry (&hw->io_wait_free, + struct efct_hw_io, + list_entry); +list_del (&temp->list_entry); + } +if (rem_count >0 ) { +efc_log_debug (hw->os, +"rmvd %d items from io_wait_free list\n" , + rem_count); + } + } + rem_count =0 ; +if (hw->io_inuse.next) { +while ((!list_empty (&hw->io_inuse))) { + rem_count++; + temp =list_first_entry (&hw->io_inuse, + struct efct_hw_io, + list_entry); +list_del (&temp->list_entry); + } +if (rem_count >0 ) +efc_log_debug (hw->os, +"rmvd %d items from io_inuse list\n" , + rem_count); + } + rem_count =0 ; +if (hw->io_free.next) { +while ((!list_empty (&hw->io_free))) { + rem_count++; + temp =list_first_entry (&hw->io_free, + struct efct_hw_io, + list_entry); +list_del (&temp->list_entry); + } +if (rem_count >0 ) +efc_log_debug (hw->os, +"rmvd %d items from io_free list\n" , + rem_count); + } + +INIT_LIST_HEAD (&hw->io_inuse); +INIT_LIST_HEAD (&hw->io_free); +INIT_LIST_HEAD (&hw->io_wait_free); + +/* If MRQ not required, Make sure we dont request feature. */ + hw->sli.features &= (~SLI4_REQFEAT_MRQP ); + +if (sli_init (&hw->sli)) { +efc_log_err (hw->os,"SLI failed to initialize\n" ); +return EFCT_HW_RTN_ERROR ; + } + +if (hw->sliport_healthcheck) { + rc =efct_hw_config_sli_port_health_check (hw,0 ,1 ); +if (rc !=EFCT_HW_RTN_SUCCESS ) { +efc_log_err (hw->os,"Enable port Health check fail\n" ); +return rc; + } + } + +/* +* Set FDT transfer hint, only works on Lancer +*/ +if (hw->sli.if_type ==SLI4_INTF_IF_TYPE_2 ) { +/* +* Non-fatal error. In particular, we can disregard failure to +* set EFCT_HW_FDT_XFER_HINT on devices with legacy firmware +* that do not support EFCT_HW_FDT_XFER_HINT feature. +*/ +efct_hw_config_set_fdt_xfer_hint (hw,EFCT_HW_FDT_XFER_HINT ); + } + +/* zero the hashes */ +memset (hw->cq_hash,0 ,sizeof (hw->cq_hash)); +efc_log_debug (hw->os,"Max CQs %d, hash size = %d\n" , +EFCT_HW_MAX_NUM_CQ ,EFCT_HW_Q_HASH_SIZE ); + +memset (hw->rq_hash,0 ,sizeof (hw->rq_hash)); +efc_log_debug (hw->os,"Max RQs %d, hash size = %d\n" , +EFCT_HW_MAX_NUM_RQ ,EFCT_HW_Q_HASH_SIZE ); + +memset (hw->wq_hash,0 ,sizeof (hw->wq_hash)); +efc_log_debug (hw->os,"Max WQs %d, hash size = %d\n" , +EFCT_HW_MAX_NUM_WQ ,EFCT_HW_Q_HASH_SIZE ); + + rc =efct_hw_init_queues (hw); +if (rc !=EFCT_HW_RTN_SUCCESS ) +return rc; + +/* Allocate and post RQ buffers */ + rc =efct_hw_rx_allocate (hw); +if (rc) { +efc_log_err (hw->os,"rx_allocate failed\n" ); +return rc; + } + + rc =efct_hw_rx_post (hw); +if (rc) { +efc_log_err (hw->os,"WARNING - error posting RQ buffers\n" ); +return rc; + } + + max_rpi = sli->extent[SLI_RSRC_RPI ].size; +/* Allocate rpi_ref if not previously allocated */ +if (!hw->rpi_ref) { + hw->rpi_ref =kmalloc_array (max_rpi,sizeof (*hw->rpi_ref), +GFP_KERNEL ); +if (!hw->rpi_ref) +return EFCT_HW_RTN_NO_MEMORY ; + +memset (hw->rpi_ref,0 , max_rpi *sizeof (*hw->rpi_ref)); + } + +for (i =0 ; i < max_rpi; i++) { +atomic_set (&hw->rpi_ref[i].rpi_count,0 ); +atomic_set (&hw->rpi_ref[i].rpi_attached,0 ); + } + + rc =efct_hw_config_rq (hw); +if (rc) { +efc_log_err (hw->os,"efct_hw_config_rq failed %d\n" , rc); +return rc; + } + +/* +* Allocate the WQ request tag pool, if not previously allocated +* (the request tag value is 16 bits, thus the pool allocation size +* of 64k) +*/ + hw->wq_reqtag_pool =efct_hw_reqtag_pool_alloc (hw); +if (!hw->wq_reqtag_pool) { +efc_log_err (hw->os,"efct_hw_reqtag_init failed %d\n" , rc); +return rc; + } + + rc =efct_hw_setup_io (hw); +if (rc) { +efc_log_err (hw->os,"IO allocation failure\n" ); +return rc; + } + + rc =efct_hw_init_io (hw); +if (rc) { +efc_log_err (hw->os,"IO initialization failure\n" ); +return rc; + } + +/* +* Arming the EQ allows (e.g.) interrupts when CQ completions write EQ +* entries +*/ +for (i =0 ; i < hw->eq_count; i++) +sli_queue_arm (&hw->sli, &hw->eq[i], true); + +/* +* Initialize RQ hash +*/ +for (i =0 ; i < hw->rq_count; i++) +efct_hw_queue_hash_add (hw->rq_hash, hw->rq[i].id, i); + +/* +* Initialize WQ hash +*/ +for (i =0 ; i < hw->wq_count; i++) +efct_hw_queue_hash_add (hw->wq_hash, hw->wq[i].id, i); + +/* +* Arming the CQ allows (e.g.) MQ completions to write CQ entries +*/ +for (i =0 ; i < hw->cq_count; i++) { +efct_hw_queue_hash_add (hw->cq_hash, hw->cq[i].id, i); +sli_queue_arm (&hw->sli, &hw->cq[i], true); + } + +/* Set RQ process limit*/ +for (i =0 ; i < hw->hw_rq_count; i++) { + rq = hw->hw_rq[i]; + hw->cq[rq->cq->instance].proc_limit = hw->config.n_io /2 ; + } + +/* record the fact that the queues are functional */ + hw->state =EFCT_HW_STATE_ACTIVE ; +/* +* Allocate a HW IOs for send frame. +*/ + hw->hw_wq[0 ]->send_frame_io =efct_hw_io_alloc (hw); +if (!hw->hw_wq[0 ]->send_frame_io) +efc_log_err (hw->os,"alloc for send_frame_io failed\n" ); + +/* Initialize send frame frame sequence id */ +atomic_set (&hw->send_frame_seq_id,0 ); + +return EFCT_HW_RTN_SUCCESS ; +} + +enum efct_hw_rtn +efct_hw_parse_filter (struct efct_hw *hw,void *value) +{ +enum efct_hw_rtn rc =EFCT_HW_RTN_SUCCESS ; +char *p =NULL ; +char *token; +u32 idx =0 ; + +for (idx =0 ; idx <ARRAY_SIZE (hw->config.filter_def); idx++) + hw->config.filter_def[idx] =0 ; + + p =kstrdup (value,GFP_KERNEL ); +if (!p || !*p) { +efc_log_err (hw->os,"p is NULL\n" ); +return EFCT_HW_RTN_NO_MEMORY ; + } + + idx =0 ; +while ((token =strsep (&p,"," )) && *token) { +if (kstrtou32 (token,0 , &hw->config.filter_def[idx++])) +efc_log_err (hw->os,"kstrtoint failed\n" ); + +if (!p || !*p) +break ; + +if (idx ==ARRAY_SIZE (hw->config.filter_def)) +break ; + } +kfree (p); + +return rc; +} + +u64 +efct_get_wwnn (struct efct_hw *hw) +{ +struct sli4 *sli = &hw->sli; +u8 p[8 ]; + +memcpy (p, sli->wwnn,sizeof (p)); +return get_unaligned_be64 (p); +} + +u64 +efct_get_wwpn (struct efct_hw *hw) +{ +struct sli4 *sli = &hw->sli; +u8 p[8 ]; + +memcpy (p, sli->wwpn,sizeof (p)); +return get_unaligned_be64 (p); +}drivers/scsi/elx/efct/efct_hw.h +15
-0@@ -614,4 +614,19 @@ struct efct_hw_grp_hdr { u8 revision[32]; }; +static inline int +efct_hw_get_link_speed (struct efct_hw *hw) { +return hw->link.speed; +} + +extern enum efct_hw_rtn +efct_hw_setup (struct efct_hw *hw,void *os,struct pci_dev *pdev); +enum efct_hw_rtn efct_hw_init (struct efct_hw *hw); +extern enum efct_hw_rtn +efct_hw_parse_filter (struct efct_hw *hw,void *value); +extern uint64_t +efct_get_wwnn (struct efct_hw *hw); +extern uint64_t +efct_get_wwpn (struct efct_hw *hw); +#endif /* __EFCT_H__ */ drivers/scsi/elx/efct/efct_xport.c new file +382
-0@@ -0,0 +1,523 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2019 Broadcom. All Rights Reserved. The term +* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +*/ + +#include "efct_driver.h" +#include "efct_unsol.h" + +/* Post node event callback argument. */ +struct efct_xport_post_node_event { +struct completion done; +atomic_t refcnt; +struct efc_node *node; +u32 evt; +void *context; +}; + +static struct dentry *efct_debugfs_root; +static atomic_t efct_debugfs_count; + +static struct scsi_host_template efct_template = { + .module =THIS_MODULE , + .name =EFCT_DRIVER_NAME , + .supported_mode =MODE_TARGET , +}; + +/* globals */ +static struct fc_function_template efct_xport_functions; +static struct fc_function_template efct_vport_functions; + +static struct scsi_transport_template *efct_xport_fc_tt; +static struct scsi_transport_template *efct_vport_fc_tt; + +/* +* transport object is allocated, +* and associated with a device instance +*/ +struct efct_xport * +efct_xport_alloc (struct efct *efct) +{ +struct efct_xport *xport; + + xport =kmalloc (sizeof (*xport),GFP_KERNEL ); +if (!xport) +return xport; + +memset (xport,0 ,sizeof (*xport)); + xport->efct = efct; +return xport; +} + +static int +efct_xport_init_debugfs (struct efct *efct) +{ +/* Setup efct debugfs root directory */ +if (!efct_debugfs_root) { + efct_debugfs_root =debugfs_create_dir ("efct" ,NULL ); +atomic_set (&efct_debugfs_count,0 ); +if (!efct_debugfs_root) { +efc_log_err (efct,"failed to create debugfs entry\n" ); + goto debugfs_fail; + } + } + +/* Create a directory for sessions in root */ +if (!efct->sess_debugfs_dir) { + efct->sess_debugfs_dir =debugfs_create_dir ("sessions" ,NULL ); +if (!efct->sess_debugfs_dir) { +efc_log_err (efct, +"failed to create debugfs entry for sessions\n" ); + goto debugfs_fail; + } +atomic_inc (&efct_debugfs_count); + } + +return EFC_SUCCESS ; + +debugfs_fail: +return EFC_FAIL ; +} + +static void efct_xport_delete_debugfs (struct efct *efct) +{ +/* Remove session debugfs directory */ +debugfs_remove (efct->sess_debugfs_dir); + efct->sess_debugfs_dir =NULL ; +atomic_dec (&efct_debugfs_count); + +if (atomic_read (&efct_debugfs_count) ==0 ) { +/* remove root debugfs directory */ +debugfs_remove (efct_debugfs_root); + efct_debugfs_root =NULL ; + } +} + +int +efct_xport_attach (struct efct_xport *xport) +{ +struct efct *efct = xport->efct; +int rc; + + xport->fcfi.hold_frames = true; +spin_lock_init (&xport->fcfi.pend_frames_lock); +INIT_LIST_HEAD (&xport->fcfi.pend_frames); + + rc =efct_hw_setup (&efct->hw, efct, efct->pcidev); +if (rc) { +efc_log_err (efct,"%s: Can't setup hardware\n" , efct->desc); +return rc; + } + +efct_hw_parse_filter (&efct->hw, (void *)efct->filter_def); + + xport->io_pool =efct_io_pool_create (efct, efct->hw.config.n_sgl); +if (!xport->io_pool) { +efc_log_err (efct,"Can't allocate IO pool\n" ); +return -ENOMEM ; + } + +return EFC_SUCCESS ; +} + +static void +efct_xport_link_stats_cb (int status,u32 num_counters, +struct efct_hw_link_stat_counts *counters,void *arg) +{ +union efct_xport_stats_u *result = arg; + + result->stats.link_stats.link_failure_error_count = + counters[EFCT_HW_LINK_STAT_LINK_FAILURE_COUNT ].counter; + result->stats.link_stats.loss_of_sync_error_count = + counters[EFCT_HW_LINK_STAT_LOSS_OF_SYNC_COUNT ].counter; + result->stats.link_stats.primitive_sequence_error_count = + counters[EFCT_HW_LINK_STAT_PRIMITIVE_SEQ_COUNT ].counter; + result->stats.link_stats.invalid_transmission_word_error_count = + counters[EFCT_HW_LINK_STAT_INVALID_XMIT_WORD_COUNT ].counter; + result->stats.link_stats.crc_error_count = + counters[EFCT_HW_LINK_STAT_CRC_COUNT ].counter; + +complete (&result->stats.done); +} + +static void +efct_xport_host_stats_cb (int status,u32 num_counters, +struct efct_hw_host_stat_counts *counters,void *arg) +{ +union efct_xport_stats_u *result = arg; + + result->stats.host_stats.transmit_kbyte_count = + counters[EFCT_HW_HOST_STAT_TX_KBYTE_COUNT ].counter; + result->stats.host_stats.receive_kbyte_count = + counters[EFCT_HW_HOST_STAT_RX_KBYTE_COUNT ].counter; + result->stats.host_stats.transmit_frame_count = + counters[EFCT_HW_HOST_STAT_TX_FRAME_COUNT ].counter; + result->stats.host_stats.receive_frame_count = + counters[EFCT_HW_HOST_STAT_RX_FRAME_COUNT ].counter; + +complete (&result->stats.done); +} + +static void +efct_xport_async_link_stats_cb (int status,u32 num_counters, +struct efct_hw_link_stat_counts *counters, +void *arg) +{ +union efct_xport_stats_u *result = arg; + + result->stats.link_stats.link_failure_error_count = + counters[EFCT_HW_LINK_STAT_LINK_FAILURE_COUNT ].counter; + result->stats.link_stats.loss_of_sync_error_count = + counters[EFCT_HW_LINK_STAT_LOSS_OF_SYNC_COUNT ].counter; + result->stats.link_stats.primitive_sequence_error_count = + counters[EFCT_HW_LINK_STAT_PRIMITIVE_SEQ_COUNT ].counter; + result->stats.link_stats.invalid_transmission_word_error_count = + counters[EFCT_HW_LINK_STAT_INVALID_XMIT_WORD_COUNT ].counter; + result->stats.link_stats.crc_error_count = + counters[EFCT_HW_LINK_STAT_CRC_COUNT ].counter; +} + +static void +efct_xport_async_host_stats_cb (int status,u32 num_counters, +struct efct_hw_host_stat_counts *counters, +void *arg) +{ +union efct_xport_stats_u *result = arg; + + result->stats.host_stats.transmit_kbyte_count = + counters[EFCT_HW_HOST_STAT_TX_KBYTE_COUNT ].counter; + result->stats.host_stats.receive_kbyte_count = + counters[EFCT_HW_HOST_STAT_RX_KBYTE_COUNT ].counter; + result->stats.host_stats.transmit_frame_count = + counters[EFCT_HW_HOST_STAT_TX_FRAME_COUNT ].counter; + result->stats.host_stats.receive_frame_count = + counters[EFCT_HW_HOST_STAT_RX_FRAME_COUNT ].counter; +} + +static void +efct_xport_config_stats_timer (struct efct *efct); + +static void +efct_xport_stats_timer_cb (struct timer_list *t) +{ +struct efct_xport *xport =from_timer (xport, t, stats_timer); +struct efct *efct = xport->efct; + +efct_xport_config_stats_timer (efct); +} + +static void +efct_xport_config_stats_timer (struct efct *efct) +{ +u32 timeout =3 *1000 ; +struct efct_xport *xport =NULL ; + +if (!efct) { +pr_err ("%s: failed to locate EFCT device\n" , __func__); +return ; + } + + xport = efct->xport; +efct_hw_get_link_stats (&efct->hw,0 ,0 ,0 , + efct_xport_async_link_stats_cb, + &xport->fc_xport_stats); +efct_hw_get_host_stats (&efct->hw,0 , efct_xport_async_host_stats_cb, + &xport->fc_xport_stats); + +timer_setup (&xport->stats_timer, + &efct_xport_stats_timer_cb,0 ); +mod_timer (&xport->stats_timer, + jiffies +msecs_to_jiffies (timeout)); +} + +int +efct_xport_initialize (struct efct_xport *xport) +{ +struct efct *efct = xport->efct; +int rc =0 ; + +/* Initialize io lists */ +spin_lock_init (&xport->io_pending_lock); +INIT_LIST_HEAD (&xport->io_pending_list); +atomic_set (&xport->io_active_count,0 ); +atomic_set (&xport->io_pending_count,0 ); +atomic_set (&xport->io_total_free,0 ); +atomic_set (&xport->io_total_pending,0 ); +atomic_set (&xport->io_alloc_failed_count,0 ); +atomic_set (&xport->io_pending_recursing,0 ); + rc =efct_hw_init (&efct->hw); +if (rc) { +efc_log_err (efct,"efct_hw_init failure\n" ); + goto out; + } + + rc =efct_scsi_tgt_new_device (efct); +if (rc) { +efc_log_err (efct,"failed to initialize target\n" ); + goto hw_init_out; + } + + rc =efct_scsi_new_device (efct); +if (rc) { +efc_log_err (efct,"failed to initialize initiator\n" ); + goto tgt_dev_out; + } + +/* Get FC link and host statistics perodically*/ +efct_xport_config_stats_timer (efct); + +efct_xport_init_debugfs (efct); + +return rc; + +tgt_dev_out: +efct_scsi_tgt_del_device (efct); + +hw_init_out: +efct_hw_teardown (&efct->hw); +out: +return rc; +} + +int +efct_xport_status (struct efct_xport *xport,enum efct_xport_status cmd, +union efct_xport_stats_u *result) +{ +u32 rc =0 ; +struct efct *efct =NULL ; +union efct_xport_stats_u value; + + efct = xport->efct; + +switch (cmd) { +case EFCT_XPORT_CONFIG_PORT_STATUS : +if (xport->configured_link_state ==0 ) { +/* +* Initial state is offline. configured_link_state is +* set to online explicitly when port is brought online +*/ + xport->configured_link_state =EFCT_XPORT_PORT_OFFLINE ; + } + result->value = xport->configured_link_state; +break ; + +case EFCT_XPORT_PORT_STATUS : +/* Determine port status based on link speed. */ + value.value =efct_hw_get_link_speed (&efct->hw); +if (value.value ==0 ) + result->value =0 ; +else + result->value =1 ; + rc =0 ; +break ; + +case EFCT_XPORT_LINK_SPEED : { + result->value =efct_hw_get_link_speed (&efct->hw); + +break ; + } +case EFCT_XPORT_LINK_STATISTICS : +memcpy ((void *)result, &efct->xport->fc_xport_stats, +sizeof (union efct_xport_stats_u )); +break ; +case EFCT_XPORT_LINK_STAT_RESET : { +/* Create a completion to synchronize the stat reset process. */ +init_completion (&result->stats.done); + +/* First reset the link stats */ + rc =efct_hw_get_link_stats (&efct->hw,0 ,1 ,1 , + efct_xport_link_stats_cb, result); + +/* Wait for completion to be signaled when the cmd completes */ +if (wait_for_completion_interruptible (&result->stats.done)) { +/* Undefined failure */ +efc_log_test (efct,"sem wait failed\n" ); + rc = -ENXIO ; +break ; + } + +/* Next reset the host stats */ + rc =efct_hw_get_host_stats (&efct->hw,1 , + efct_xport_host_stats_cb, result); + +/* Wait for completion to be signaled when the cmd completes */ +if (wait_for_completion_interruptible (&result->stats.done)) { +/* Undefined failure */ +efc_log_test (efct,"sem wait failed\n" ); + rc = -ENXIO ; +break ; + } +break ; + } +default : + rc =-1 ; +break ; + } + +return rc; +} + +int +efct_scsi_new_device (struct efct *efct) +{ +struct Scsi_Host *shost =NULL ; +int error =0 ; +struct efct_vport *vport =NULL ; +union efct_xport_stats_u speed; +u32 supported_speeds =0 ; + + shost =scsi_host_alloc (&efct_template,sizeof (*vport)); +if (!shost) { +efc_log_err (efct,"failed to allocate Scsi_Host struct\n" ); +return EFC_FAIL ; + } + +/* save shost to initiator-client context */ + efct->shost = shost; + +/* save efct information to shost LLD-specific space */ + vport = (struct efct_vport *)shost->hostdata; + vport->efct = efct; +
drivers/scsi/elx/efct/efct_xport.c line 392
Quoted 10 lines
drivers/scsi/elx/efct/efct_xport.c new file +10
-0+/* +* Set initial can_queue value to the max SCSI IOs. This is the maximum +* global queue depth (as opposed to the per-LUN queue depth -- +* .cmd_per_lun This may need to be adjusted for I+T mode. +*/ + shost->can_queue = efct->hw.config.n_io; + shost->max_cmd_len =16 ;/* 16-byte CDBs */ + shost->max_id =0xffff ; + shost->max_lun =0xffffffff ; +
What happened to multiqueue support?
The original lpfc driver did it, so we should regress for the new driver...
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
Re: [PATCH v3 16/31] elx: efct: Driver initialization routines
On 4/16/2020 12:11 AM, Hannes Reinecke wrote:
...
Quoted 18 lines
Quoted 9 lines
+ if (efct) {
+memset(efct, 0, sizeof(*efct));
+ for (i = 0; i <ARRAY_SIZE(efct_devices); i++) { + if (!efct_devices[i]) {
+efct->instance_index= i;
+ efct_devices[i] = efct;
+ break;
+ }
+ }Quoted 8 lines
+
+ if (i ==ARRAY_SIZE(efct_devices)) {
+pr_err("Exceeded max supported devices.\n"); + kfree(efct);
+ efct = NULL;
+ } else {
+efct->attached= false;
+ }
Quoted 8 lines
Errm. This is wrong.
When we exit thefor()loop above, i _will_ equal the array size. Surely you meanif (i <
ARRAY_SIZE())right?
No. We want to free the structure if we went through the array and didn't find an empty slot. It only breaks from the loop if it found an empty slot and used it.
Quoted 21 lines
Quoted 21 lines
+ } else if (
event->topology==SLI_LINK_TOPO_LOOP) { + u8 *buf = NULL;drivers/scsi/elx/efct/efct_hw.c new file +19
-0+ + efc_log_info(hw->os, "Link Up, LOOP, speed is %d\n", + event->speed); + dma = &hw->loop_map; + dma->size = SLI4_MIN_LOOP_MAP_BYTES; + dma->virt = dma_alloc_coherent(&efct->pcidev->dev, + dma->size, &dma->phys, + GFP_DMA); + if (!dma->virt) + efc_log_err(hw->os, "efct_dma_alloc_fail\n"); + + buf = kmalloc(SLI4_BMBX_SIZE, GFP_ATOMIC); + if (!buf) + break; + + if (!sli_cmd_read_topology(&hw->sli, buf, + SLI4_BMBX_SIZE, + &hw->loop_map)) { + rc = efct_hw_command(hw, buf, EFCT_CMD_NOWAIT,
Quoted 8 lines
Quoted 4 lines
+
__efct_read_topology_cb, + NULL);
+ }
+Not sure if this is a good idea; we'll have to allocate extra memory whenever the loop topology changes.
Which typically happens when there had been a failure somewhere, and chances are that it'll affect our root fs, making memory allocation something we really need to look at. Can't we pre-allocate a buffer here somewhere in the global initialisation so that we don't have to allocate it every time?
Agree. will look into it.
...
Quoted 3 lines
What happened to multiqueue support?
The original lpfc driver did it, so we should regress for the new driver...
For a target driver ?
When something like this is in the tgt infrastructure we'll do something with it.
-- james
Re: [PATCH v3 16/31] elx: efct: Driver initialization routines
In reply to James SmartQuoted 130 lines · James Smart
This patch continues the efct driver population.
This patch adds driver definitions for:
Emulex FC Target driver init, attach and hardware setup routines.Signed-off-by Ram Vegesna <[email protected]>Signed-off-by James Smart <[email protected]>---
v3:
Removed Queue topology string.
Usedrequest_threaded_irqinstead of a thread.
Use a static fuction to get the model.
Reworkedefct_device_attachto use if statements and gotos. Changedefct_fw_reset, removed accessing other functions. Converted to usepci_alloc_irq_vectorsapi.
Removed proc interface.
Removedefct_hw_getandefct_hw_setfunctions. Driver implicitly
knows adapter configuration.
Many more small changes.--- drivers/scsi/elx/efct/efct_driver.c | 856 +++++++++++++++++++++++++++ drivers/scsi/elx/efct/efct_driver.h | 142 +++++ drivers/scsi/elx/efct/efct_hw.c | 1116 +++++++++++++++++++++++++++++++++++ drivers/scsi/elx/efct/efct_hw.h | 15 + drivers/scsi/elx/efct/efct_xport.c | 523 ++++++++++++++++ drivers/scsi/elx/efct/efct_xport.h | 201 +++++++ 6 files changed, 2853 insertions(+) create mode 100644 drivers/scsi/elx/efct/efct_driver.c create mode 100644 drivers/scsi/elx/efct/efct_driver.h create mode 100644 drivers/scsi/elx/efct/efct_hw.c create mode 100644 drivers/scsi/elx/efct/efct_xport.c create mode 100644 drivers/scsi/elx/efct/efct_xport.hdrivers/scsi/elx/efct/efct_driver.c new file +90
-0@@ -0,0 +1,856 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2019 Broadcom. All Rights Reserved. The term +* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +*/ + +#include "efct_driver.h" + +#include "efct_els.h" +#include "efct_hw.h" +#include "efct_unsol.h" +#include "efct_scsi.h" + +struct efct *efct_devices[MAX_EFCT_DEVICES ]; + +static int logmask; +module_param (logmask, int,0444 ); +MODULE_PARM_DESC (logmask,"logging bitmask (default 0)" ); + +static struct libefc_function_template efct_libefc_templ = { + .hw_domain_alloc = efct_hw_domain_alloc, + .hw_domain_attach = efct_hw_domain_attach, + .hw_domain_free = efct_hw_domain_free, + .hw_domain_force_free = efct_hw_domain_force_free, + .domain_hold_frames = efct_domain_hold_frames, + .domain_accept_frames = efct_domain_accept_frames, + + .hw_port_alloc = efct_hw_port_alloc, + .hw_port_attach = efct_hw_port_attach, + .hw_port_free = efct_hw_port_free, + + .hw_node_alloc = efct_hw_node_alloc, + .hw_node_attach = efct_hw_node_attach, + .hw_node_detach = efct_hw_node_detach, + .hw_node_free_resources = efct_hw_node_free_resources, + .node_purge_pending = efct_node_purge_pending, + + .scsi_io_alloc_disable = efct_scsi_io_alloc_disable, + .scsi_io_alloc_enable = efct_scsi_io_alloc_enable, + .scsi_validate_node = efct_scsi_validate_initiator, + .new_domain = efct_scsi_tgt_new_domain, + .del_domain = efct_scsi_tgt_del_domain, + .new_sport = efct_scsi_tgt_new_sport, + .del_sport = efct_scsi_tgt_del_sport, + .scsi_new_node = efct_scsi_new_initiator, + .scsi_del_node = efct_scsi_del_initiator, + + .els_send = efct_els_req_send, + .els_send_ct = efct_els_send_ct, + .els_send_resp = efct_els_resp_send, + .bls_send_acc_hdr = efct_bls_send_acc_hdr, + .send_flogi_p2p_acc = efct_send_flogi_p2p_acc, + .send_ct_rsp = efct_send_ct_rsp, + .send_ls_rjt = efct_send_ls_rjt, + + .node_io_cleanup = efct_node_io_cleanup, + .node_els_cleanup = efct_node_els_cleanup, + .node_abort_all_els = efct_node_abort_all_els, + + .dispatch_fcp_cmd = efct_dispatch_fcp_cmd, + .recv_abts_frame = efct_node_recv_abts_frame, +}; + +static int +efct_device_init (void ) +{ +int rc; + +/* driver-wide init for target-server */ + rc =efct_scsi_tgt_driver_init (); +if (rc) { +pr_err ("efct_scsi_tgt_init failed rc=%d\n" , + rc); +return rc; + } + + rc =efct_scsi_reg_fc_transport (); +if (rc) { +pr_err ("failed to register to FC host\n" ); +return rc; + } + +return EFC_SUCCESS ; +} + +static void +efct_device_shutdown (void ) +{ +efct_scsi_release_fc_transport (); +
drivers/scsi/elx/efct/efct_driver.c line 100
Quoted 10 lines
drivers/scsi/elx/efct/efct_driver.c new file +10
-0+efct_scsi_tgt_driver_exit (); +} + +static void * +efct_device_alloc (u32 nid) +{ +struct efct *efct =NULL ; +u32 i; + + efct =kmalloc_node (sizeof (*efct),GFP_ATOMIC , nid);
GFP_KERNEL
drivers/scsi/elx/efct/efct_driver.c line 102
Quoted 2 lines
drivers/scsi/elx/efct/efct_driver.c new file +2
-0+ +if (efct) {
if (!efct) return NULL;
Quoted 5 lines
drivers/scsi/elx/efct/efct_driver.c new file +5
-0+memset (efct,0 ,sizeof (*efct)); +for (i =0 ; i <ARRAY_SIZE (efct_devices); i++) { +if (!efct_devices[i]) { + efct->instance_index = i; + efct_devices[i] = efct;
drivers/scsi/elx/efct/efct_driver.c line 117
Quoted 10 lines
drivers/scsi/elx/efct/efct_driver.c new file +10
-0+break ; + } + } + +if (i ==ARRAY_SIZE (efct_devices)) { +pr_err ("Exceeded max supported devices.\n" ); +kfree (efct); + efct =NULL ; + }else { + efct->attached = false;
Isn't this done by memset already?
Quoted 130 lines
drivers/scsi/elx/efct/efct_driver.c new file +130
-0+ } + } +return efct; +} + +static void +efct_teardown_msix (struct efct *efct) +{ +u32 i; + +for (i =0 ; i < efct->n_msix_vec; i++) { +free_irq (pci_irq_vector (efct->pcidev, i), + &efct->intr_context[i]); + } + +pci_free_irq_vectors (efct->pcidev); +} + +static int +efct_efclib_config (struct efct *efct,struct libefc_function_template *tt) +{ +struct efc *efc; +struct sli4 *sli; +int rc =EFC_SUCCESS ; + + efc =kmalloc (sizeof (*efc),GFP_KERNEL ); +if (!efc) +return EFC_FAIL ; + +memset (efc,0 ,sizeof (struct efc )); + efct->efcport = efc; + +memcpy (&efc->tt, tt,sizeof (*tt)); + efc->base = efct; + efc->pcidev = efct->pcidev; + + efc->def_wwnn =efct_get_wwnn (&efct->hw); + efc->def_wwpn =efct_get_wwpn (&efct->hw); + efc->enable_tgt =1 ; + efc->log_level =EFC_LOG_LIB ; + + sli = &efct->hw.sli; + efc->max_xfer_size = sli->sge_supported_length * +sli_get_max_sgl (&efct->hw.sli); + + rc =efcport_init (efc); +if (rc) +efc_log_err (efc,"efcport_init failed\n" ); + +return rc; +} + +static int efct_request_firmware_update (struct efct *efct); + +static const char * +efct_pci_model (u16 device) +{ +switch (device) { +case EFCT_DEVICE_LANCER_G6 :return "LPE31004" ; +case EFCT_DEVICE_LANCER_G7 :return "LPE36000" ; +default :return "unknown" ; + } +} + +static int +efct_device_attach (struct efct *efct) +{ +u32 rc =0 , i =0 ; + +if (efct->attached) { +efc_log_err (efct,"Device is already attached\n" ); +return EFC_FAIL ; + } + +snprintf (efct->name,sizeof (efct->name),"[%s%d] " ,"fc" , + efct->instance_index); + + efct->logmask = logmask; + efct->filter_def ="0,0,0,0" ; + efct->max_isr_time_msec =EFCT_OS_MAX_ISR_TIME_MSEC ; + + efct->model =efct_pci_model (efct->pcidev->device); + + efct->efct_req_fw_upgrade = true; + +/* Allocate transport object and bring online */ + efct->xport =efct_xport_alloc (efct); +if (!efct->xport) { +efc_log_err (efct,"failed to allocate transport object\n" ); + rc = -ENOMEM ; + goto out; + } + + rc =efct_xport_attach (efct->xport); +if (rc) { +efc_log_err (efct,"failed to attach transport object\n" ); + goto xport_out; + } + + rc =efct_xport_initialize (efct->xport); +if (rc) { +efc_log_err (efct,"failed to initialize transport object\n" ); + goto xport_out; + } + + rc =efct_efclib_config (efct, &efct_libefc_templ); +if (rc) { +efc_log_err (efct,"failed to init efclib\n" ); + goto efclib_out; + } + +for (i =0 ; i < efct->n_msix_vec; i++) { +efc_log_debug (efct,"irq %d enabled\n" , i); +enable_irq (pci_irq_vector (efct->pcidev, i)); + } + + efct->attached = true; + +if (efct->efct_req_fw_upgrade) +efct_request_firmware_update (efct); + +return rc; + +efclib_out: +efct_xport_detach (efct->xport); +xport_out: +if (efct->xport) { +efct_xport_free (efct->xport); + efct->xport =NULL ; + }
drivers/scsi/elx/efct/efct_driver.c line 257
Quoted 10 lines
drivers/scsi/elx/efct/efct_driver.c new file +10
-0+out: +return rc; +} + +static int +efct_device_detach (struct efct *efct) +{ +int rc =0 , i; + +if (efct) {
if (!efct) return EFC_SUCCESS;
Quoted 1,396 lines
drivers/scsi/elx/efct/efct_driver.c new file +599
-0+if (!efct->attached) { +efc_log_warn (efct,"Device is not attached\n" ); +return EFC_FAIL ; + } + + rc =efct_xport_control (efct->xport,EFCT_XPORT_SHUTDOWN ); +if (rc) +efc_log_err (efct,"Transport Shutdown timed out\n" ); + +for (i =0 ; i < efct->n_msix_vec; i++) +disable_irq (pci_irq_vector (efct->pcidev, i)); + +if (efct_xport_detach (efct->xport) !=0 ) +efc_log_err (efct,"Transport detach failed\n" ); + +efct_xport_free (efct->xport); + efct->xport =NULL ; + +efcport_destroy (efct->efcport); +kfree (efct->efcport); + + efct->attached = false; + } + +return EFC_SUCCESS ; +} + +static void +efct_fw_write_cb (int status,u32 actual_write_length, +u32 change_status,void *arg) +{ +struct efct_fw_write_result *result = arg; + + result->status = status; + result->actual_xfer = actual_write_length; + result->change_status = change_status; + +complete (&result->done); +} + +static int +efct_firmware_write (struct efct *efct,const u8 *buf,size_t buf_len, +u8 *change_status) +{ +int rc =0 ; +u32 bytes_left; +u32 xfer_size; +u32 offset; +struct efc_dma dma; +int last =0 ; +struct efct_fw_write_result result; + +init_completion (&result.done); + + bytes_left = buf_len; + offset =0 ; + + dma.size =FW_WRITE_BUFSIZE ; + dma.virt =dma_alloc_coherent (&efct->pcidev->dev, + dma.size, &dma.phys,GFP_DMA ); +if (!dma.virt) +return -ENOMEM ; + +while (bytes_left >0 ) { +if (bytes_left >FW_WRITE_BUFSIZE ) + xfer_size =FW_WRITE_BUFSIZE ; +else + xfer_size = bytes_left; + +memcpy (dma.virt, buf + offset, xfer_size); + +if (bytes_left == xfer_size) + last =1 ; + +efct_hw_firmware_write (&efct->hw, &dma, xfer_size, offset, + last, efct_fw_write_cb, &result); + +if (wait_for_completion_interruptible (&result.done) !=0 ) { + rc = -ENXIO ; +break ; + } + +if (result.actual_xfer ==0 || result.status !=0 ) { + rc = -EFAULT ; +break ; + } + +if (last) + *change_status = result.change_status; + + bytes_left -= result.actual_xfer; + offset += result.actual_xfer; + } + +dma_free_coherent (&efct->pcidev->dev, dma.size, dma.virt, dma.phys); +return rc; +} + +/* +* Firmware reset to activate the new firmware. +* Function 0 will update and load the new firmware +* during attach. +*/ +static int +efct_fw_reset (struct efct *efct) +{ +int rc =0 ; + +if (timer_pending (&efct->xport->stats_timer)) +del_timer (&efct->xport->stats_timer); + +if (efct_hw_reset (&efct->hw,EFCT_HW_RESET_FIRMWARE )) { +efc_log_info (efct,"failed to reset firmware\n" ); + rc =-1 ; + }else { +efc_log_info (efct, +"successfully reset firmware.Now resetting port\n" ); + +efct_device_detach (efct); + rc =efct_device_attach (efct); + } +return rc; +} + +static int +efct_request_firmware_update (struct efct *efct) +{ +int rc =0 ; +u8 file_name[256 ], fw_change_status =0 ; +const struct firmware *fw; +struct efct_hw_grp_hdr *fw_image; + +snprintf (file_name,256 ,"%s.grp" , efct->model); + + rc =request_firmware (&fw, file_name, &efct->pcidev->dev); +if (rc) { +efc_log_debug (efct,"Firmware file(%s) not found.\n" , + file_name); +return rc; + } + + fw_image = (struct efct_hw_grp_hdr *)fw->data; + +if (!strncmp (efct->hw.sli.fw_name[0 ], fw_image->revision, +strnlen (fw_image->revision,16 ))) { +efc_log_debug (efct, +"Skipped update. Firmware is already up to date.\n" ); + goto exit; + } + +efc_log_info (efct,"Firmware update is initiated. %s -> %s\n" , + efct->hw.sli.fw_name[0 ], fw_image->revision); + + rc =efct_firmware_write (efct, fw->data, fw->size, &fw_change_status); +if (rc) { +efc_log_err (efct, +"Firmware update failed. Return code = %d\n" , rc); + goto exit; + } + +efc_log_info (efct,"Firmware updated successfully\n" ); +switch (fw_change_status) { +case 0x00 : +efc_log_info (efct,"New firmware is active.\n" ); +break ; +case 0x01 : +efc_log_info (efct, +"System reboot needed to activate the new firmware\n" ); +break ; +case 0x02 : +case 0x03 : +efc_log_info (efct, +"firmware is resetting to activate the new firmware\n" ); +efct_fw_reset (efct); +break ; +default : +efc_log_info (efct, +"Unexected value change_status:%d\n" , fw_change_status); +break ; + } + +exit: +release_firmware (fw); + +return rc; +} + +static void +efct_device_free (struct efct *efct) +{ +if (efct) { + efct_devices[efct->instance_index] =NULL ; + +kfree (efct); + } +} + +static int +efct_device_interrupts_required (struct efct *efct) +{ +if (efct_hw_setup (&efct->hw, efct, efct->pcidev) + !=EFCT_HW_RTN_SUCCESS ) { +return -1 ; + } + +return efct->hw.config.n_eq; +} + +static irqreturn_t +efct_intr_thread (int irq,void *handle) +{ +struct efct_intr_context *intr_ctx = handle; +struct efct *efct = intr_ctx->efct; + +efct_hw_process (&efct->hw, intr_ctx->index, efct->max_isr_time_msec); +return IRQ_HANDLED ; +} + +static irqreturn_t +efct_intr_msix (int irq,void *handle) +{ +return IRQ_WAKE_THREAD ; +} + +static int +efct_setup_msix (struct efct *efct,u32 num_intrs) +{ +int rc =0 , i; + +if (!pci_find_capability (efct->pcidev,PCI_CAP_ID_MSIX )) { +dev_err (&efct->pcidev->dev, +"%s : MSI-X not available\n" , __func__); +return -EINVAL ; + } + + efct->n_msix_vec = num_intrs; + + rc =pci_alloc_irq_vectors (efct->pcidev, num_intrs, num_intrs, +PCI_IRQ_MSIX |PCI_IRQ_AFFINITY ); + +if (rc <0 ) { +dev_err (&efct->pcidev->dev,"Failed to alloc irq : %d\n" , rc); +return rc; + } + +for (i =0 ; i < num_intrs; i++) { +struct efct_intr_context *intr_ctx =NULL ; + + intr_ctx = &efct->intr_context[i]; + intr_ctx->efct = efct; + intr_ctx->index = i; + + rc =request_threaded_irq (pci_irq_vector (efct->pcidev, i), + efct_intr_msix, efct_intr_thread,0 , +EFCT_DRIVER_NAME , intr_ctx); +if (rc) { +dev_err (&efct->pcidev->dev, +"Failed to register %d vector: %d\n" , i, rc); + goto out; + } + } + +return rc; + +out: +while (--i >=0 ) +free_irq (pci_irq_vector (efct->pcidev, i), + &efct->intr_context[i]); + +pci_free_irq_vectors (efct->pcidev); +return rc; +} + +static struct pci_device_id efct_pci_table[] = { + {PCI_DEVICE (EFCT_VENDOR_ID ,EFCT_DEVICE_LANCER_G6 ),0 }, + {PCI_DEVICE (EFCT_VENDOR_ID ,EFCT_DEVICE_LANCER_G7 ),0 }, + {}/* terminate list */ +}; + +static int +efct_pci_probe (struct pci_dev *pdev,const struct pci_device_id *ent) +{ +struct efct *efct =NULL ; +int rc; +u32 i, r; +int num_interrupts =0 ; +int nid; + +dev_info (&pdev->dev,"%s\n" ,EFCT_DRIVER_NAME ); + + rc =pci_enable_device_mem (pdev); +if (rc) +return rc; + +pci_set_master (pdev); + + rc =pci_set_mwi (pdev); +if (rc) { +dev_info (&pdev->dev, +"pci_set_mwi returned %d\n" , rc); + goto mwi_out; + } + + rc =pci_request_regions (pdev,EFCT_DRIVER_NAME ); +if (rc) { +dev_err (&pdev->dev,"pci_request_regions failed %d\n" , rc); + goto req_regions_out; + } + +/* Fetch the Numa node id for this device */ + nid =dev_to_node (&pdev->dev); +if (nid <0 ) { +dev_err (&pdev->dev, +"Warning Numa node ID is %d\n" , nid); + nid =0 ; + } + +/* Allocate efct */ + efct =efct_device_alloc (nid); +if (!efct) { +dev_err (&pdev->dev,"Failed to allocate efct\n" ); + rc = -ENOMEM ; + goto alloc_out; + } + + efct->pcidev = pdev; + + efct->numa_node = nid; + +/* Map all memory BARs */ +for (i =0 , r =0 ; i <EFCT_PCI_MAX_REGS ; i++) { +if (pci_resource_flags (pdev, i) &IORESOURCE_MEM ) { + efct->reg[r] =ioremap (pci_resource_start (pdev, i), +pci_resource_len (pdev, i)); + r++; + } + +/* +* If the 64-bit attribute is set, both this BAR and the +* next form the complete address. Skip processing the +* next BAR. +*/ +if (pci_resource_flags (pdev, i) &IORESOURCE_MEM_64 ) + i++; + } + +pci_set_drvdata (pdev, efct); + +if (pci_set_dma_mask (pdev,DMA_BIT_MASK (64 )) !=0 || +pci_set_consistent_dma_mask (pdev,DMA_BIT_MASK (64 )) !=0 ) { +dev_warn (&pdev->dev, +"trying DMA_BIT_MASK(32)\n" ); +if (pci_set_dma_mask (pdev,DMA_BIT_MASK (32 )) !=0 || +pci_set_consistent_dma_mask (pdev,DMA_BIT_MASK (32 )) !=0 ) { +dev_err (&pdev->dev, +"setting DMA_BIT_MASK failed\n" ); + rc =-1 ; + goto dma_mask_out; + } + } + + num_interrupts =efct_device_interrupts_required (efct); +if (num_interrupts <0 ) { +efc_log_err (efct,"efct_device_interrupts_required failed\n" ); + rc =-1 ; + goto dma_mask_out; + } + +/* +* Initialize MSIX interrupts, note, +* efct_setup_msix() enables the interrupt +*/ + rc =efct_setup_msix (efct, num_interrupts); +if (rc) { +dev_err (&pdev->dev,"Can't setup msix\n" ); + goto dma_mask_out; + } +/* Disable interrupt for now */ +for (i =0 ; i < efct->n_msix_vec; i++) { +efc_log_debug (efct,"irq %d disabled\n" , i); +disable_irq (pci_irq_vector (efct->pcidev, i)); + } + + rc =efct_device_attach ((struct efct *)efct); +if (rc) + goto attach_out; + +return EFC_SUCCESS ; + +attach_out: +efct_teardown_msix (efct); +dma_mask_out: +pci_set_drvdata (pdev,NULL ); + +for (i =0 ; i <EFCT_PCI_MAX_REGS ; i++) { +if (efct->reg[i]) +iounmap (efct->reg[i]); + } +efct_device_free (efct); +alloc_out: +pci_release_regions (pdev); +req_regions_out: +pci_clear_mwi (pdev); +mwi_out: +pci_disable_device (pdev); +return rc; +} + +static void +efct_pci_remove (struct pci_dev *pdev) +{ +struct efct *efct =pci_get_drvdata (pdev); +u32 i; + +if (!efct) +return ; + +efct_device_detach (efct); + +efct_teardown_msix (efct); + +for (i =0 ; i <EFCT_PCI_MAX_REGS ; i++) { +if (efct->reg[i]) +iounmap (efct->reg[i]); + } + +pci_set_drvdata (pdev,NULL ); + + efct_devices[efct->instance_index] =NULL ; + +efct_device_free (efct); + +pci_release_regions (pdev); + +pci_disable_device (pdev); +} + +static void +efct_device_prep_for_reset (struct efct *efct,struct pci_dev *pdev) +{ +if (efct) { +efc_log_debug (efct, +"PCI channel disable preparing for reset\n" ); +efct_device_detach (efct); +/* Disable interrupt and pci device */ +efct_teardown_msix (efct); + } +pci_disable_device (pdev); +} + +static void +efct_device_prep_for_recover (struct efct *efct) +{ +if (efct) { +efc_log_debug (efct,"PCI channel preparing for recovery\n" ); +efct_hw_io_abort_all (&efct->hw); + } +} + +/** +* efct_pci_io_error_detected - method for handling PCI I/O error +* @pdev: pointer to PCI device. +* @state: the current PCI connection state. +* +* This routine is registered to the PCI subsystem for error handling. This +* function is called by the PCI subsystem after a PCI bus error affecting +* this device has been detected. When this routine is invoked, it dispatches +* device error detected handling routine, which will perform the proper +* error detected operation. +* +* Return codes +* PCI_ERS_RESULT_NEED_RESET - need to reset before recovery +* PCI_ERS_RESULT_DISCONNECT - device could not be recovered +*/ +static pci_ers_result_t +efct_pci_io_error_detected (struct pci_dev *pdev,pci_channel_state_t state) +{ +struct efct *efct =pci_get_drvdata (pdev); +pci_ers_result_t rc; + +switch (state) { +case pci_channel_io_normal: +efct_device_prep_for_recover (efct); + rc =PCI_ERS_RESULT_CAN_RECOVER ; +break ; +case pci_channel_io_frozen: +efct_device_prep_for_reset (efct, pdev); + rc =PCI_ERS_RESULT_NEED_RESET ; +break ; +case pci_channel_io_perm_failure: +efct_device_detach (efct); + rc =PCI_ERS_RESULT_DISCONNECT ; +break ; +default : +efc_log_debug (efct,"Unknown PCI error state:0x%x\n" , + state); +efct_device_prep_for_reset (efct, pdev); + rc =PCI_ERS_RESULT_NEED_RESET ; +break ; + } + +return rc; +} + +static pci_ers_result_t +efct_pci_io_slot_reset (struct pci_dev *pdev) +{ +int rc; +struct efct *efct =pci_get_drvdata (pdev); + + rc =pci_enable_device_mem (pdev); +if (rc) { +efc_log_err (efct, +"failed to re-enable PCI device after reset.\n" ); +return PCI_ERS_RESULT_DISCONNECT ; + } + +/* +* As the new kernel behavior of pci_restore_state() API call clears +* device saved_state flag, need to save the restored state again. +*/ + +pci_save_state (pdev); + +pci_set_master (pdev); + + rc =efct_setup_msix (efct, efct->n_msix_vec); +if (rc) +efc_log_err (efct,"rc %d returned, IRQ allocation failed\n" , + rc); + +/* Perform device reset */ +efct_device_detach (efct); +/* Bring device to online*/ +efct_device_attach (efct); + +return PCI_ERS_RESULT_RECOVERED ; +} + +static void +efct_pci_io_resume (struct pci_dev *pdev) +{ +struct efct *efct =pci_get_drvdata (pdev); + +/* Perform device reset */ +efct_device_detach (efct); +/* Bring device to online*/ +efct_device_attach (efct); +} + +MODULE_DEVICE_TABLE (pci, efct_pci_table); + +static struct pci_error_handlers efct_pci_err_handler = { + .error_detected = efct_pci_io_error_detected, + .slot_reset = efct_pci_io_slot_reset, + .resume = efct_pci_io_resume, +}; + +static struct pci_driver efct_pci_driver = { + .name =EFCT_DRIVER_NAME , + .id_table = efct_pci_table, + .probe = efct_pci_probe, + .remove = efct_pci_remove, + .err_handler = &efct_pci_err_handler, +}; + +static +int __init efct_init (void ) +{ +int rc = -ENODEV ; + + rc =efct_device_init (); +if (rc) { +pr_err ("efct_device_init failed rc=%d\n" , rc); +return -ENOMEM ; + } + + rc =pci_register_driver (&efct_pci_driver); +if (rc) + goto l1; + +return rc; + +l1: +efct_device_shutdown (); +return rc; +} + +static void __exit efct_exit(void) +{ +pci_unregister_driver (&efct_pci_driver); +efct_device_shutdown (); +} + +module_init (efct_init); +module_exit (efct_exit); +MODULE_VERSION (EFCT_DRIVER_VERSION ); +MODULE_LICENSE ("GPL" ); +MODULE_AUTHOR ("Broadcom" );drivers/scsi/elx/efct/efct_driver.h new file +142
-0@@ -0,0 +1,142 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2019 Broadcom. All Rights Reserved. The term +* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +*/ + +#if !defined(__EFCT_DRIVER_H__) +#define __EFCT_DRIVER_H__ + +/*************************************************************************** +* OS specific includes +*/ +#include <stdarg.h> +#include <linux/version.h> +#include <linux/init.h> +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/list.h> +#include <linux/interrupt.h> +#include <asm-generic/ioctl.h> +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/pci.h> +#include <linux/dma-mapping.h> +#include <linux/bitmap.h> +#include <linux/slab.h> +#include <linux/spinlock.h> +#include <asm/byteorder.h> +#include <linux/timer.h> +#include <linux/delay.h> +#include <linux/fs.h> +#include <linux/uaccess.h> +#include <linux/sched.h> +#include <asm/current.h> +#include <asm/cacheflush.h> +#include <linux/pagemap.h> +#include <linux/kthread.h> +#include <linux/proc_fs.h> +#include <linux/seq_file.h> +#include <linux/random.h> +#include <linux/sched.h> +#include <linux/jiffies.h> +#include <linux/ctype.h> +#include <linux/debugfs.h> +#include <linux/firmware.h> +#include <linux/sched/signal.h> +#include "../include/efc_common.h" + +#define EFCT_DRIVER_NAME "efct" +#define EFCT_DRIVER_VERSION "1.0.0.0" + +/* EFCT_OS_MAX_ISR_TIME_MSEC - +* maximum time driver code should spend in an interrupt +* or kernel thread context without yielding +*/ +#define EFCT_OS_MAX_ISR_TIME_MSEC 1000 + +#define EFCT_FC_MAX_SGL 64 +#define EFCT_FC_DIF_SEED 0 + +/* Timeouts */ +#define EFCT_FC_ELS_SEND_DEFAULT_TIMEOUT 0 +#define EFCT_FC_ELS_DEFAULT_RETRIES 3 +#define EFCT_FC_FLOGI_TIMEOUT_SEC 5 +#define EFCT_FC_DOMAIN_SHUTDOWN_TIMEOUT_USEC 30000000/* 30 seconds */ + +/* Watermark */ +#define EFCT_WATERMARK_HIGH_PCT 90 +#define EFCT_WATERMARK_LOW_PCT 80 +#define EFCT_IO_WATERMARK_PER_INITIATOR 8 + +#include "../libefc/efclib.h" +#include "efct_hw.h" +#include "efct_io.h" +#include "efct_xport.h" + +#define EFCT_PCI_MAX_REGS 6 +#define MAX_PCI_INTERRUPTS 16 + +struct efct_intr_context { +struct efct *efct; +u32 index; +}; + +struct efct { +struct pci_dev *pcidev; +void __iomem *reg[EFCT_PCI_MAX_REGS ]; + +u32 n_msix_vec; +struct efct_intr_context intr_context[MAX_PCI_INTERRUPTS ]; +u32 numa_node; + +char name[EFC_NAME_LENGTH ]; +bool attached; +struct efct_scsi_tgt tgt_efct; +struct efct_xport *xport; +struct efc *efcport; +struct Scsi_Host *shost; +int logmask; +u32 max_isr_time_msec; + +const char *desc; +u32 instance_index; + +const char *model; + +struct efct_hw hw; + +u32 num_vports; +u32 rq_selection_policy; +char *filter_def; + +bool soft_wwn_enable; + +/* +* Target IO timer value: +* Zero: target command timeout disabled. +* Non-zero: Timeout value, in seconds, for target commands +*/ +u32 target_io_timer_sec; + +int speed; +int topology; + +u8 efct_req_fw_upgrade; +u16 sw_feature_cap; +struct dentry *sess_debugfs_dir; +}; + +#define FW_WRITE_BUFSIZE (64 * 1024) + +struct efct_fw_write_result { +struct completion done; +int status; +u32 actual_xfer; +u32 change_status; +}; + +#define MAX_EFCT_DEVICES 64 +extern struct efct *efct_devices[MAX_EFCT_DEVICES ]; + +#endif /* __EFCT_DRIVER_H__ */ drivers/scsi/elx/efct/efct_hw.c new file +643
-0@@ -0,0 +1,1116 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2019 Broadcom. All Rights Reserved. The term + * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. + */ + +#include "efct_driver.h" +#include "efct_hw.h" + +static enum efct_hw_rtn +efct_hw_link_event_init(struct efct_hw *hw) +{ + hw->link.status = SLI_LINK_STATUS_MAX; + hw->link.topology = SLI_LINK_TOPO_NONE; + hw->link.medium = SLI_LINK_MEDIUM_MAX; + hw->link.speed = 0; + hw->link.loop_map = NULL; + hw->link.fc_id = U32_MAX; + + return EFCT_HW_RTN_SUCCESS; +} + +static enum efct_hw_rtn +efct_hw_read_max_dump_size(struct efct_hw *hw) +{ + u8 buf[SLI4_BMBX_SIZE]; + struct efct *efct = hw->os; + int rc = EFCT_HW_RTN_SUCCESS; + struct sli4_rsp_cmn_set_dump_location *rsp; + + /* attempt to detemine the dump size for function 0 only. */ + if (PCI_FUNC(efct->pcidev->devfn) != 0) + return rc; + + rc = sli_cmd_common_set_dump_location(&hw->sli, buf, SLI4_BMBX_SIZE, 1, + 0, NULL, 0); + if (rc) + return rc; + + rsp = (struct sli4_rsp_cmn_set_dump_location *) + (buf + offsetof(struct sli4_cmd_sli_config, payload.embed)); + + rc = efct_hw_command(hw, buf, EFCT_CMD_POLL, NULL, NULL); + if (rc != EFCT_HW_RTN_SUCCESS) { + efc_log_test(hw->os, "set dump location cmd failed\n"); + return rc; + } + hw->dump_size = (le32_to_cpu(rsp->buffer_length_dword) & + SLI4_CMN_SET_DUMP_BUFFER_LEN); + efc_log_debug(hw->os, "Dump size %x\n", hw->dump_size); + + return rc; +} + +static int +__efct_read_topology_cb(struct efct_hw *hw, int status, + u8 *mqe, void *arg) +{ + struct sli4_cmd_read_topology *read_topo = + (struct sli4_cmd_read_topology *)mqe; + u8 speed; + struct efc_domain_record drec = {0}; + struct efct *efct = hw->os; + + if (status || le16_to_cpu(read_topo->hdr.status)) { + efc_log_debug(hw->os, "bad status cqe=%#x mqe=%#x\n", + status, + le16_to_cpu(read_topo->hdr.status)); + kfree(mqe); + return EFC_FAIL; + } + + switch (le32_to_cpu(read_topo->dw2_attentype) & + SLI4_READTOPO_ATTEN_TYPE) { + case SLI4_READ_TOPOLOGY_LINK_UP: + hw->link.status = SLI_LINK_STATUS_UP; + break; + case SLI4_READ_TOPOLOGY_LINK_DOWN: + hw->link.status = SLI_LINK_STATUS_DOWN; + break; + case SLI4_READ_TOPOLOGY_LINK_NO_ALPA: + hw->link.status = SLI_LINK_STATUS_NO_ALPA; + break; + default: + hw->link.status = SLI_LINK_STATUS_MAX; + break; + } + + switch (read_topo->topology) { + case SLI4_READ_TOPOLOGY_NPORT: + hw->link.topology = SLI_LINK_TOPO_NPORT; + break; + case SLI4_READ_TOPOLOGY_FC_AL: + hw->link.topology = SLI_LINK_TOPO_LOOP; + if (hw->link.status == SLI_LINK_STATUS_UP) + hw->link.loop_map = hw->loop_map.virt; + hw->link.fc_id = read_topo->acquired_al_pa; + break; + default: + hw->link.topology = SLI_LINK_TOPO_MAX; + break; + } + + hw->link.medium = SLI_LINK_MEDIUM_FC; + + speed = (le32_to_cpu(read_topo->currlink_state) & + SLI4_READTOPO_LINKSTATE_SPEED) >> 8; + switch (speed) { + case SLI4_READ_TOPOLOGY_SPEED_1G: + hw->link.speed = 1 * 1000; + break; + case SLI4_READ_TOPOLOGY_SPEED_2G: + hw->link.speed = 2 * 1000; + break; + case SLI4_READ_TOPOLOGY_SPEED_4G: + hw->link.speed = 4 * 1000; + break; + case SLI4_READ_TOPOLOGY_SPEED_8G: + hw->link.speed = 8 * 1000; + break; + case SLI4_READ_TOPOLOGY_SPEED_16G: + hw->link.speed = 16 * 1000; + hw->link.loop_map = NULL; + break; + case SLI4_READ_TOPOLOGY_SPEED_32G: + hw->link.speed = 32 * 1000; + hw->link.loop_map = NULL; + break; + } + + kfree(mqe); + + drec.speed = hw->link.speed; + drec.fc_id = hw->link.fc_id; + drec.is_nport = true; + efc_domain_cb(efct->efcport, EFC_HW_DOMAIN_FOUND, &drec); + + return EFC_SUCCESS; +} + +/* Callback function for the SLI link events */ +static int +efct_hw_cb_link(void *ctx, void *e) +{ + struct efct_hw *hw = ctx; + struct sli4_link_event *event = e; + struct efc_domain *d = NULL; + int rc = EFCT_HW_RTN_ERROR; + struct efct *efct = hw->os; + struct efc_dma *dma; + + efct_hw_link_event_init(hw); + + switch (event->status) { + case SLI_LINK_STATUS_UP: + + hw->link = *event; + efct->efcport->link_status = EFC_LINK_STATUS_UP; + + if (event->topology == SLI_LINK_TOPO_NPORT) { + struct efc_domain_record drec = {0}; + + efc_log_info(hw->os, "Link Up, NPORT, speed is %d\n", + event->speed); + drec.speed = event->speed; + drec.fc_id = event->fc_id; + drec.is_nport = true; + efc_domain_cb(efct->efcport, EFC_HW_DOMAIN_FOUND, + &drec); + } else if (event->topology == SLI_LINK_TOPO_LOOP) { + u8 *buf = NULL; + + efc_log_info(hw->os, "Link Up, LOOP, speed is %d\n", + event->speed); + dma = &hw->loop_map; + dma->size = SLI4_MIN_LOOP_MAP_BYTES; + dma->virt = dma_alloc_coherent(&efct->pcidev->dev, + dma->size, &dma->phys, + GFP_DMA); + if (!dma->virt) + efc_log_err(hw->os, "efct_dma_alloc_fail\n"); + + buf = kmalloc(SLI4_BMBX_SIZE, GFP_ATOMIC); + if (!buf) + break; + + if (!sli_cmd_read_topology(&hw->sli, buf, + SLI4_BMBX_SIZE, + &hw->loop_map)) { + rc = efct_hw_command(hw, buf, EFCT_CMD_NOWAIT, + __efct_read_topology_cb, + NULL); + } + + if (rc != EFCT_HW_RTN_SUCCESS) { + efc_log_test(hw->os, "READ_TOPOLOGY failed\n"); + kfree(buf); + } + } else { + efc_log_info(hw->os, "%s(%#x), speed is %d\n", + "Link Up, unsupported topology ", + event->topology, event->speed); + } + break; + case SLI_LINK_STATUS_DOWN: + efc_log_info(hw->os, "Link down\n"); + + hw->link.status = event->status; + efct->efcport->link_status = EFC_LINK_STATUS_DOWN; + + d = hw->domain; + if (d) + efc_domain_cb(efct->efcport, EFC_HW_DOMAIN_LOST, d); + break; + default: + efc_log_test(hw->os, "unhandled link status %#x\n", + event->status); + break; + } + + return EFC_SUCCESS; +} + +enum efct_hw_rtn +efct_hw_setup(struct efct_hw *hw, void *os, struct pci_dev *pdev) +{ + u32 i, max_sgl; + + if (hw->hw_setup_called) + return EFCT_HW_RTN_SUCCESS; + + /* + * efct_hw_init() relies on NULL pointers indicating that a structure + * needs allocation. If a structure is non-NULL, efct_hw_init() won't + * free/realloc that memory + */ + memset(hw, 0, sizeof(struct efct_hw)); + + hw->hw_setup_called = true; + + hw->os = os; + + spin_lock_init(&hw->cmd_lock); + INIT_LIST_HEAD(&hw->cmd_head); + INIT_LIST_HEAD(&hw->cmd_pending); + hw->cmd_head_count = 0; + + spin_lock_init(&hw->io_lock); + spin_lock_init(&hw->io_abort_lock); + + atomic_set(&hw->io_alloc_failed_count, 0); + + hw->config.speed = FC_LINK_SPEED_AUTO_16_8_4; + if (sli_setup(&hw->sli, hw->os, pdev, ((struct efct *)os)->reg)) { + efc_log_err(hw->os, "SLI setup failed\n"); + return EFCT_HW_RTN_ERROR; + } + + efct_hw_link_event_init(hw); + + sli_callback(&hw->sli, SLI4_CB_LINK, efct_hw_cb_link, hw); + + /* + * Set all the queue sizes to the maximum allowed. + */ + for (i = 0; i < ARRAY_SIZE(hw->num_qentries); i++) + hw->num_qentries[i] = hw->sli.qinfo.max_qentries[i]; + /* + * Adjust the the size of the WQs so that the CQ is twice as + * big as the WQ to allow for 2 completions per IO. This allows us to + * handle multi-phase as well as aborts. + */ + hw->num_qentries[SLI_QTYPE_WQ] = hw->num_qentries[SLI_QTYPE_CQ] / 2; + + /* + * The RQ assignment for RQ pair mode. + */ + hw->config.rq_default_buffer_size = EFCT_HW_RQ_SIZE_PAYLOAD; + hw->config.n_io = hw->sli.extent[SLI_RSRC_XRI].size; + hw->config.n_eq = EFCT_HW_DEF_NUM_EQ; + + max_sgl = sli_get_max_sgl(&hw->sli) - SLI4_SGE_MAX_RESERVED; + max_sgl = (max_sgl > EFCT_FC_MAX_SGL) ? EFCT_FC_MAX_SGL : max_sgl; + hw->config.n_sgl = max_sgl; + + (void)efct_hw_read_max_dump_size(hw); + + return EFCT_HW_RTN_SUCCESS; +} + +static void +efct_logfcfi(struct efct_hw *hw, u32 j, u32 i, u32 id) +{ + efc_log_info(hw->os, + "REG_FCFI: filter[%d] %08X -> RQ[%d] id=%d\n", + j, hw->config.filter_def[j], i, id); +} + +static inline void +efct_hw_init_free_io(struct efct_hw_io *io) +{ + /* + * Set io->done to NULL, to avoid any callbacks, should + * a completion be received for one of these IOs + */ + io->done = NULL; + io->abort_done = NULL; + io->status_saved = false; + io->abort_in_progress = false; + io->rnode = NULL; + io->type = 0xFFFF; + io->wq = NULL; + io->ul_io = NULL; + io->tgt_wqe_timeout = 0; +} + +static u8 efct_hw_iotype_is_originator(u16 io_type) +{ + switch (io_type) { + case EFCT_HW_FC_CT: + case EFCT_HW_ELS_REQ: + return 1; + default: + return EFC_SUCCESS; + } +} + +static void +efct_hw_io_restore_sgl(struct efct_hw *hw, struct efct_hw_io *io) +{ + /* Restore the default */ + io->sgl = &io->def_sgl; + io->sgl_count = io->def_sgl_count; + + /* Clear the overflow SGL */ + io->ovfl_sgl = NULL; + io->ovfl_sgl_count = 0; + io->ovfl_lsp = NULL; +} + +static void +efct_hw_wq_process_io(void *arg, u8 *cqe, int status) +{ + struct efct_hw_io *io = arg; + struct efct_hw *hw = io->hw; + struct sli4_fc_wcqe *wcqe = (void *)cqe; + u32 len = 0; + u32 ext = 0; + + /* clear xbusy flag if WCQE[XB] is clear */ + if (io->xbusy && (wcqe->flags & SLI4_WCQE_XB) == 0) + io->xbusy = false; + + /* get extended CQE status */ + switch (io->type) { + case EFCT_HW_BLS_ACC: + case EFCT_HW_BLS_ACC_SID: + break; + case EFCT_HW_ELS_REQ: + sli_fc_els_did(&hw->sli, cqe, &ext); + len = sli_fc_response_length(&hw->sli, cqe); + break; + case EFCT_HW_ELS_RSP: + case EFCT_HW_ELS_RSP_SID: + case EFCT_HW_FC_CT_RSP: + break; + case EFCT_HW_FC_CT: + len = sli_fc_response_length(&hw->sli, cqe); + break; + case EFCT_HW_IO_TARGET_WRITE: + len = sli_fc_io_length(&hw->sli, cqe); + break; + case EFCT_HW_IO_TARGET_READ: + len = sli_fc_io_length(&hw->sli, cqe); + break; + case EFCT_HW_IO_TARGET_RSP: + break; + case EFCT_HW_IO_DNRX_REQUEUE: + /* release the count for re-posting the buffer */ + /* efct_hw_io_free(hw, io); */ + break; + default: + efc_log_test(hw->os, "unhandled io type %#x for XRI 0x%x\n", + io->type, io->indicator); + break; + } + if (status) { + ext = sli_fc_ext_status(&hw->sli, cqe); + /* + * If we're not an originator IO, and XB is set, then issue + * abort for the IO from within the HW + */ + if ((!efct_hw_iotype_is_originator(io->type)) && + wcqe->flags & SLI4_WCQE_XB) { + enum efct_hw_rtn rc; + + efc_log_debug(hw->os, "aborting xri=%#x tag=%#x\n", + io->indicator, io->reqtag); + + /* + * Because targets may send a response when the IO + * completes using the same XRI, we must wait for the + * XRI_ABORTED CQE to issue the IO callback + */ + rc = efct_hw_io_abort(hw, io, false, NULL, NULL); + if (rc == EFCT_HW_RTN_SUCCESS) { + /* + * latch status to return after abort is + * complete + */ + io->status_saved = true; + io->saved_status = status; + io->saved_ext = ext; + io->saved_len = len; + goto exit_efct_hw_wq_process_io; + } else if (rc == EFCT_HW_RTN_IO_ABORT_IN_PROGRESS) { + /* + * Already being aborted by someone else (ABTS + * perhaps). Just fall thru and return original + * error. + */ + efc_log_debug(hw->os, "%s%#x tag=%#x\n", + "abort in progress xri=", + io->indicator, io->reqtag); + + } else { + /* Failed to abort for some other reason, log + * error + */ + efc_log_test(hw->os, "%s%#x tag=%#x rc=%d\n", + "Failed to abort xri=", + io->indicator, io->reqtag, rc); + } + } + } + + if (io->done) { + efct_hw_done_t done = io->done; + void *arg = io->arg; + + io->done = NULL; + + if (io->status_saved) { + /* use latched status if exists */ + status = io->saved_status; + len = io->saved_len; + ext = io->saved_ext; + io->status_saved = false; + } + + /* Restore default SGL */ + efct_hw_io_restore_sgl(hw, io); + done(io, io->rnode, len, status, ext, arg); + } + +exit_efct_hw_wq_process_io: + return; +} + +/* Initialize the pool of HW IO objects */ +static enum efct_hw_rtn +efct_hw_setup_io(struct efct_hw *hw) +{ + u32 i = 0; + struct efct_hw_io *io = NULL; + uintptr_t xfer_virt = 0; + uintptr_t xfer_phys = 0; + u32 index; + bool new_alloc = true; + struct efc_dma *dma; + struct efct *efct = hw->os; + + if (!hw->io) { + hw->io = kmalloc_array(hw->config.n_io, sizeof(io), + GFP_KERNEL); + + if (!hw->io) + return EFCT_HW_RTN_NO_MEMORY; + + memset(hw->io, 0, hw->config.n_io * sizeof(io)); + + for (i = 0; i < hw->config.n_io; i++) { + hw->io[i] = kmalloc(sizeof(*io), GFP_KERNEL); + if (!hw->io[i]) + goto error; + + memset(hw->io[i], 0, sizeof(struct efct_hw_io)); + } + + /* Create WQE buffs for IO */ + hw->wqe_buffs = kmalloc((hw->config.n_io * + hw->sli.wqe_size), + GFP_ATOMIC); + if (!hw->wqe_buffs) { + kfree(hw->io); + return EFCT_HW_RTN_NO_MEMORY; + } + memset(hw->wqe_buffs, 0, (hw->config.n_io * + hw->sli.wqe_size)); + + } else { + /* re-use existing IOs, including SGLs */ + new_alloc = false; + } + + if (new_alloc) { + dma = &hw->xfer_rdy; + dma->size = sizeof(struct fcp_txrdy) * hw->config.n_io; + dma->virt = dma_alloc_coherent(&efct->pcidev->dev, + dma->size, &dma->phys, GFP_DMA); + if (!dma->virt) + return EFCT_HW_RTN_NO_MEMORY; + } + xfer_virt = (uintptr_t)hw->xfer_rdy.virt; + xfer_phys = hw->xfer_rdy.phys; + + for (i = 0; i < hw->config.n_io; i++) { + struct hw_wq_callback *wqcb; + + io = hw->io[i]; + + /* initialize IO fields */ + io->hw = hw; + + /* Assign a WQE buff */ + io->wqe.wqebuf = &hw->wqe_buffs[i * hw->sli.wqe_size]; + + /* Allocate the request tag for this IO */ + wqcb = efct_hw_reqtag_alloc(hw, efct_hw_wq_process_io, io); + if (!wqcb) { + efc_log_err(hw->os, "can't allocate request tag\n"); + return EFCT_HW_RTN_NO_RESOURCES; + } + io->reqtag = wqcb->instance_index; + + /* Now for the fields that are initialized on each free */ + efct_hw_init_free_io(io); + + /* The XB flag isn't cleared on IO free, so init to zero */ + io->xbusy = 0; + + if (sli_resource_alloc(&hw->sli, SLI_RSRC_XRI, + &io->indicator, &index)) { + efc_log_err(hw->os, + "sli_resource_alloc failed @ %d\n", i); + return EFCT_HW_RTN_NO_MEMORY; + } + if (new_alloc) { + dma = &io->def_sgl; + dma->size = hw->config.n_sgl * + sizeof(struct sli4_sge); + dma->virt = dma_alloc_coherent(&efct->pcidev->dev, + dma->size, &dma->phys, + GFP_DMA); + if (!dma->virt) { + efc_log_err(hw->os, "dma_alloc fail %d\n", i); + memset(&io->def_sgl, 0, + sizeof(struct efc_dma)); + return EFCT_HW_RTN_NO_MEMORY; + } + } + io->def_sgl_count = hw->config.n_sgl; + io->sgl = &io->def_sgl; + io->sgl_count = io->def_sgl_count; + + if (hw->xfer_rdy.size) { + io->xfer_rdy.virt = (void *)xfer_virt; + io->xfer_rdy.phys = xfer_phys; + io->xfer_rdy.size = sizeof(struct fcp_txrdy); + + xfer_virt += sizeof(struct fcp_txrdy); + xfer_phys += sizeof(struct fcp_txrdy); + } + } + + return EFCT_HW_RTN_SUCCESS; +error: + for (i = 0; i < hw->config.n_io && hw->io[i]; i++) { + kfree(hw->io[i]); + hw->io[i] = NULL; + } + + kfree(hw->io); + hw->io = NULL; + + return EFCT_HW_RTN_NO_MEMORY; +} + +static enum efct_hw_rtn +efct_hw_init_io(struct efct_hw *hw) +{ + u32 i = 0, io_index = 0; + bool prereg = false; + struct efct_hw_io *io = NULL; + u8 cmd[SLI4_BMBX_SIZE]; + enum efct_hw_rtn rc = EFCT_HW_RTN_SUCCESS; + u32 nremaining; + u32 n = 0; + u32 sgls_per_request = 256; + struct efc_dma **sgls = NULL; + struct efc_dma reqbuf; + struct efct *efct = hw->os; + + prereg = hw->sli.sgl_pre_registered; + + memset(&reqbuf, 0, sizeof(struct efc_dma)); + if (prereg) { + sgls = kmalloc_array(sgls_per_request, sizeof(*sgls), + GFP_ATOMIC); + if (!sgls) + return EFCT_HW_RTN_NO_MEMORY; + + reqbuf.size = 32 + sgls_per_request * 16; + reqbuf.virt = dma_alloc_coherent(&efct->pcidev->dev, + reqbuf.size, &reqbuf.phys, + GFP_DMA); + if (!reqbuf.virt) { + efc_log_err(hw->os, "dma_alloc reqbuf failed\n"); + kfree(sgls); + return EFCT_HW_RTN_NO_MEMORY; + } + } + + for (nremaining = hw->config.n_io; nremaining; nremaining -= n) { + if (prereg) { + /* Copy address of SGL's into local sgls[] array, break + * out if the xri is not contiguous. + */ + u32 min = (sgls_per_request < nremaining) + ? sgls_per_request : nremaining; + for (n = 0; n < min; n++) { + /* Check that we have contiguous xri values */ + if (n > 0) { + if (hw->io[io_index + n]->indicator != + hw->io[io_index + n - 1]->indicator + + 1) + break; + } + sgls[n] = hw->io[io_index + n]->sgl; + } + + if (!sli_cmd_post_sgl_pages(&hw->sli, cmd, + sizeof(cmd),
drivers/scsi/elx/efct/efct_hw.c line 653
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw.c new file +10
-0+ hw->io[io_index]->indicator, + n, sgls, NULL, &reqbuf)) { +if (efct_hw_command (hw, cmd,EFCT_CMD_POLL , +NULL ,NULL )) { + rc =EFCT_HW_RTN_ERROR ; +efc_log_err (hw->os, +"SGL post failed\n" ); +break ; + } + }
Maybe move this into a function to avoid cluttering everthing to right side.
Quoted 179 lines
drivers/scsi/elx/efct/efct_hw.c new file +179
-0+ }else { + n = nremaining; + } + +/* Add to tail if successful */ +for (i =0 ; i < n; i++, io_index++) { + io = hw->io[io_index]; + io->state =EFCT_HW_IO_STATE_FREE ; +INIT_LIST_HEAD (&io->list_entry); +list_add_tail (&io->list_entry, &hw->io_free); + } + } + +if (prereg) { +dma_free_coherent (&efct->pcidev->dev, + reqbuf.size, reqbuf.virt, reqbuf.phys); +memset (&reqbuf,0 ,sizeof (struct efc_dma )); +kfree (sgls); + } + +return rc; +} + +static enum efct_hw_rtn +efct_hw_config_set_fdt_xfer_hint (struct efct_hw *hw,u32 fdt_xfer_hint) +{ +enum efct_hw_rtn rc =EFCT_HW_RTN_SUCCESS ; +u8 buf[SLI4_BMBX_SIZE ]; +struct sli4_rqst_cmn_set_features_set_fdt_xfer_hint param; + +memset (¶m,0 ,sizeof (param)); + param.fdt_xfer_hint =cpu_to_le32 (fdt_xfer_hint); +/* build the set_features command */ +sli_cmd_common_set_features (&hw->sli, buf,SLI4_BMBX_SIZE , +SLI4_SET_FEATURES_SET_FTD_XFER_HINT , +sizeof (param), + ¶m); + + rc =efct_hw_command (hw, buf,EFCT_CMD_POLL ,NULL ,NULL ); +if (rc) +efc_log_warn (hw->os,"set FDT hint %d failed: %d\n" , + fdt_xfer_hint, rc); +else +efc_log_info (hw->os,"Set FTD transfer hint to %d\n" , +le32_to_cpu (param.fdt_xfer_hint)); + +return rc; +} + +static int +efct_hw_config_rq (struct efct_hw *hw) +{ +u32 min_rq_count, i, rc; +struct sli4_cmd_rq_cfg rq_cfg[SLI4_CMD_REG_FCFI_NUM_RQ_CFG ]; +u8 buf[SLI4_BMBX_SIZE ]; + +efc_log_info (hw->os,"using REG_FCFI standard\n" ); + +/* +* Set the filter match/mask values from hw's +* filter_def values +*/ +for (i =0 ; i <SLI4_CMD_REG_FCFI_NUM_RQ_CFG ; i++) { + rq_cfg[i].rq_id =cpu_to_le16 (0xffff ); + rq_cfg[i].r_ctl_mask = (u8 )hw->config.filter_def[i]; + rq_cfg[i].r_ctl_match = (u8)(hw->config.filter_def[i] >>8 ); + rq_cfg[i].type_mask = (u8)(hw->config.filter_def[i] >>16 ); + rq_cfg[i].type_match = (u8)(hw->config.filter_def[i] >>24 ); + } + +/* +* Update the rq_id's of the FCF configuration +* (don't update more than the number of rq_cfg +* elements) +*/ + min_rq_count = (hw->hw_rq_count <SLI4_CMD_REG_FCFI_NUM_RQ_CFG ) ? + hw->hw_rq_count :SLI4_CMD_REG_FCFI_NUM_RQ_CFG ; +for (i =0 ; i < min_rq_count; i++) { +struct hw_rq *rq = hw->hw_rq[i]; +u32 j; + +for (j =0 ; j <SLI4_CMD_REG_FCFI_NUM_RQ_CFG ; j++) { +u32 mask = (rq->filter_mask !=0 ) ? + rq->filter_mask :1 ; + +if (!(mask & (1U << j))) +continue ; + + rq_cfg[j].rq_id =cpu_to_le16 (rq->hdr->id); +efct_logfcfi (hw, j, i, rq->hdr->id); + } + } + + rc =EFCT_HW_RTN_ERROR ; +if (!sli_cmd_reg_fcfi (&hw->sli, buf, +SLI4_BMBX_SIZE ,0 , + rq_cfg)) { + rc =efct_hw_command (hw, buf,EFCT_CMD_POLL , +NULL ,NULL ); + } + +if (rc !=EFCT_HW_RTN_SUCCESS ) { +efc_log_err (hw->os, +"FCFI registration failed\n" ); +return rc; + } + hw->fcf_indicator = +le16_to_cpu (((struct sli4_cmd_reg_fcfi *)buf)->fcfi); + +return rc; +} + +static void +efct_hw_queue_hash_add (struct efct_queue_hash *hash, +u16 id,u16 index) +{ +u32 hash_index = id & (EFCT_HW_Q_HASH_SIZE -1 ); + +/* +* Since the hash is always bigger than the number of queues, then we +* never have to worry about an infinite loop. +*/ +while (hash[hash_index].in_use) + hash_index = (hash_index +1 ) & (EFCT_HW_Q_HASH_SIZE -1 ); + +/* not used, claim the entry */ + hash[hash_index].id = id; + hash[hash_index].in_use = true; + hash[hash_index].index = index; +} + +/* enable sli port health check */ +static enum efct_hw_rtn +efct_hw_config_sli_port_health_check (struct efct_hw *hw,u8 query, +u8 enable) +{ +enum efct_hw_rtn rc =EFCT_HW_RTN_SUCCESS ; +u8 buf[SLI4_BMBX_SIZE ]; +struct sli4_rqst_cmn_set_features_health_check param; +u32 health_check_flag =0 ; + +memset (¶m,0 ,sizeof (param)); + +if (enable) + health_check_flag |=SLI4_RQ_HEALTH_CHECK_ENABLE ; + +if (query) + health_check_flag |=SLI4_RQ_HEALTH_CHECK_QUERY ; + + param.health_check_dword =cpu_to_le32 (health_check_flag); + +/* build the set_features command */ +sli_cmd_common_set_features (&hw->sli, buf,SLI4_BMBX_SIZE , +SLI4_SET_FEATURES_SLI_PORT_HEALTH_CHECK , +sizeof (param), + ¶m); + + rc =efct_hw_command (hw, buf,EFCT_CMD_POLL ,NULL ,NULL ); +if (rc) +efc_log_err (hw->os,"efct_hw_command returns %d\n" , rc); +else +efc_log_test (hw->os,"SLI Port Health Check is enabled\n" ); + +return rc; +} + +enum efct_hw_rtn +efct_hw_init (struct efct_hw *hw) +{ +enum efct_hw_rtn rc; +u32 i =0 ; +u32 max_rpi; +int rem_count; +unsigned long flags =0 ; +struct efct_hw_io *temp; +struct sli4 *sli = &hw->sli; +struct hw_rq *rq; + +/*
drivers/scsi/elx/efct/efct_hw.c line 842
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw.c new file +10
-0+* Make sure the command lists are empty. If this is start-of-day, +* they'll be empty since they were just initialized in efct_hw_setup. +* If we've just gone through a reset, the command and command pending +* lists should have been cleaned up as part of the reset +* (efct_hw_reset()). +*/ +spin_lock_irqsave (&hw->cmd_lock, flags); +if (!list_empty (&hw->cmd_head)) { +efc_log_err (hw->os,"command found on cmd list\n" ); +spin_unlock_irqrestore (&hw->cmd_lock, flags);
Move the error logging out of the locking section.
drivers/scsi/elx/efct/efct_hw.c line 847
Quoted 5 lines
drivers/scsi/elx/efct/efct_hw.c new file +5
-0+return EFCT_HW_RTN_ERROR ; + } +if (!list_empty (&hw->cmd_pending)) { +efc_log_err (hw->os, +"command found on pending list\n" );
here too
Quoted 407 lines
drivers/scsi/elx/efct/efct_hw.c new file +269
-0+spin_unlock_irqrestore (&hw->cmd_lock, flags); +return EFCT_HW_RTN_ERROR ; + } +spin_unlock_irqrestore (&hw->cmd_lock, flags); + +/* Free RQ buffers if prevously allocated */ +efct_hw_rx_free (hw); + +/* +* The IO queues must be initialized here for the reset case. The +* efct_hw_init_io() function will re-add the IOs to the free list. +* The cmd_head list should be OK since we free all entries in +* efct_hw_command_cancel() that is called in the efct_hw_reset(). +*/ + +/* If we are in this function due to a reset, there may be stale items +* on lists that need to be removed. Clean them up. +*/ + rem_count =0 ; +if (hw->io_wait_free.next) { +while ((!list_empty (&hw->io_wait_free))) { + rem_count++; + temp =list_first_entry (&hw->io_wait_free, + struct efct_hw_io, + list_entry); +list_del (&temp->list_entry); + } +if (rem_count >0 ) { +efc_log_debug (hw->os, +"rmvd %d items from io_wait_free list\n" , + rem_count); + } + } + rem_count =0 ; +if (hw->io_inuse.next) { +while ((!list_empty (&hw->io_inuse))) { + rem_count++; + temp =list_first_entry (&hw->io_inuse, + struct efct_hw_io, + list_entry); +list_del (&temp->list_entry); + } +if (rem_count >0 ) +efc_log_debug (hw->os, +"rmvd %d items from io_inuse list\n" , + rem_count); + } + rem_count =0 ; +if (hw->io_free.next) { +while ((!list_empty (&hw->io_free))) { + rem_count++; + temp =list_first_entry (&hw->io_free, + struct efct_hw_io, + list_entry); +list_del (&temp->list_entry); + } +if (rem_count >0 ) +efc_log_debug (hw->os, +"rmvd %d items from io_free list\n" , + rem_count); + } + +INIT_LIST_HEAD (&hw->io_inuse); +INIT_LIST_HEAD (&hw->io_free); +INIT_LIST_HEAD (&hw->io_wait_free); + +/* If MRQ not required, Make sure we dont request feature. */ + hw->sli.features &= (~SLI4_REQFEAT_MRQP ); + +if (sli_init (&hw->sli)) { +efc_log_err (hw->os,"SLI failed to initialize\n" ); +return EFCT_HW_RTN_ERROR ; + } + +if (hw->sliport_healthcheck) { + rc =efct_hw_config_sli_port_health_check (hw,0 ,1 ); +if (rc !=EFCT_HW_RTN_SUCCESS ) { +efc_log_err (hw->os,"Enable port Health check fail\n" ); +return rc; + } + } + +/* +* Set FDT transfer hint, only works on Lancer +*/ +if (hw->sli.if_type ==SLI4_INTF_IF_TYPE_2 ) { +/* +* Non-fatal error. In particular, we can disregard failure to +* set EFCT_HW_FDT_XFER_HINT on devices with legacy firmware +* that do not support EFCT_HW_FDT_XFER_HINT feature. +*/ +efct_hw_config_set_fdt_xfer_hint (hw,EFCT_HW_FDT_XFER_HINT ); + } + +/* zero the hashes */ +memset (hw->cq_hash,0 ,sizeof (hw->cq_hash)); +efc_log_debug (hw->os,"Max CQs %d, hash size = %d\n" , +EFCT_HW_MAX_NUM_CQ ,EFCT_HW_Q_HASH_SIZE ); + +memset (hw->rq_hash,0 ,sizeof (hw->rq_hash)); +efc_log_debug (hw->os,"Max RQs %d, hash size = %d\n" , +EFCT_HW_MAX_NUM_RQ ,EFCT_HW_Q_HASH_SIZE ); + +memset (hw->wq_hash,0 ,sizeof (hw->wq_hash)); +efc_log_debug (hw->os,"Max WQs %d, hash size = %d\n" , +EFCT_HW_MAX_NUM_WQ ,EFCT_HW_Q_HASH_SIZE ); + + rc =efct_hw_init_queues (hw); +if (rc !=EFCT_HW_RTN_SUCCESS ) +return rc; + +/* Allocate and post RQ buffers */ + rc =efct_hw_rx_allocate (hw); +if (rc) { +efc_log_err (hw->os,"rx_allocate failed\n" ); +return rc; + } + + rc =efct_hw_rx_post (hw); +if (rc) { +efc_log_err (hw->os,"WARNING - error posting RQ buffers\n" ); +return rc; + } + + max_rpi = sli->extent[SLI_RSRC_RPI ].size; +/* Allocate rpi_ref if not previously allocated */ +if (!hw->rpi_ref) { + hw->rpi_ref =kmalloc_array (max_rpi,sizeof (*hw->rpi_ref), +GFP_KERNEL ); +if (!hw->rpi_ref) +return EFCT_HW_RTN_NO_MEMORY ; + +memset (hw->rpi_ref,0 , max_rpi *sizeof (*hw->rpi_ref)); + } + +for (i =0 ; i < max_rpi; i++) { +atomic_set (&hw->rpi_ref[i].rpi_count,0 ); +atomic_set (&hw->rpi_ref[i].rpi_attached,0 ); + } + + rc =efct_hw_config_rq (hw); +if (rc) { +efc_log_err (hw->os,"efct_hw_config_rq failed %d\n" , rc); +return rc; + } + +/* +* Allocate the WQ request tag pool, if not previously allocated +* (the request tag value is 16 bits, thus the pool allocation size +* of 64k) +*/ + hw->wq_reqtag_pool =efct_hw_reqtag_pool_alloc (hw); +if (!hw->wq_reqtag_pool) { +efc_log_err (hw->os,"efct_hw_reqtag_init failed %d\n" , rc); +return rc; + } + + rc =efct_hw_setup_io (hw); +if (rc) { +efc_log_err (hw->os,"IO allocation failure\n" ); +return rc; + } + + rc =efct_hw_init_io (hw); +if (rc) { +efc_log_err (hw->os,"IO initialization failure\n" ); +return rc; + } + +/* +* Arming the EQ allows (e.g.) interrupts when CQ completions write EQ +* entries +*/ +for (i =0 ; i < hw->eq_count; i++) +sli_queue_arm (&hw->sli, &hw->eq[i], true); + +/* +* Initialize RQ hash +*/ +for (i =0 ; i < hw->rq_count; i++) +efct_hw_queue_hash_add (hw->rq_hash, hw->rq[i].id, i); + +/* +* Initialize WQ hash +*/ +for (i =0 ; i < hw->wq_count; i++) +efct_hw_queue_hash_add (hw->wq_hash, hw->wq[i].id, i); + +/* +* Arming the CQ allows (e.g.) MQ completions to write CQ entries +*/ +for (i =0 ; i < hw->cq_count; i++) { +efct_hw_queue_hash_add (hw->cq_hash, hw->cq[i].id, i); +sli_queue_arm (&hw->sli, &hw->cq[i], true); + } + +/* Set RQ process limit*/ +for (i =0 ; i < hw->hw_rq_count; i++) { + rq = hw->hw_rq[i]; + hw->cq[rq->cq->instance].proc_limit = hw->config.n_io /2 ; + } + +/* record the fact that the queues are functional */ + hw->state =EFCT_HW_STATE_ACTIVE ; +/* +* Allocate a HW IOs for send frame. +*/ + hw->hw_wq[0 ]->send_frame_io =efct_hw_io_alloc (hw); +if (!hw->hw_wq[0 ]->send_frame_io) +efc_log_err (hw->os,"alloc for send_frame_io failed\n" ); + +/* Initialize send frame frame sequence id */ +atomic_set (&hw->send_frame_seq_id,0 ); + +return EFCT_HW_RTN_SUCCESS ; +} + +enum efct_hw_rtn +efct_hw_parse_filter (struct efct_hw *hw,void *value) +{ +enum efct_hw_rtn rc =EFCT_HW_RTN_SUCCESS ; +char *p =NULL ; +char *token; +u32 idx =0 ; + +for (idx =0 ; idx <ARRAY_SIZE (hw->config.filter_def); idx++) + hw->config.filter_def[idx] =0 ; + + p =kstrdup (value,GFP_KERNEL ); +if (!p || !*p) { +efc_log_err (hw->os,"p is NULL\n" ); +return EFCT_HW_RTN_NO_MEMORY ; + } + + idx =0 ; +while ((token =strsep (&p,"," )) && *token) { +if (kstrtou32 (token,0 , &hw->config.filter_def[idx++])) +efc_log_err (hw->os,"kstrtoint failed\n" ); + +if (!p || !*p) +break ; + +if (idx ==ARRAY_SIZE (hw->config.filter_def)) +break ; + } +kfree (p); + +return rc; +} + +u64 +efct_get_wwnn (struct efct_hw *hw) +{ +struct sli4 *sli = &hw->sli; +u8 p[8 ]; + +memcpy (p, sli->wwnn,sizeof (p)); +return get_unaligned_be64 (p); +} + +u64 +efct_get_wwpn (struct efct_hw *hw) +{ +struct sli4 *sli = &hw->sli; +u8 p[8 ]; + +memcpy (p, sli->wwpn,sizeof (p)); +return get_unaligned_be64 (p); +}drivers/scsi/elx/efct/efct_hw.h +15
-0@@ -614,4 +614,19 @@ struct efct_hw_grp_hdr { u8 revision[32]; }; +static inline int +efct_hw_get_link_speed (struct efct_hw *hw) { +return hw->link.speed; +} + +extern enum efct_hw_rtn +efct_hw_setup (struct efct_hw *hw,void *os,struct pci_dev *pdev); +enum efct_hw_rtn efct_hw_init (struct efct_hw *hw); +extern enum efct_hw_rtn +efct_hw_parse_filter (struct efct_hw *hw,void *value); +extern uint64_t +efct_get_wwnn (struct efct_hw *hw); +extern uint64_t +efct_get_wwpn (struct efct_hw *hw); +#endif /* __EFCT_H__ */ drivers/scsi/elx/efct/efct_xport.c new file +108
-0@@ -0,0 +1,523 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2019 Broadcom. All Rights Reserved. The term +* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +*/ + +#include "efct_driver.h" +#include "efct_unsol.h" + +/* Post node event callback argument. */ +struct efct_xport_post_node_event { +struct completion done; +atomic_t refcnt; +struct efc_node *node; +u32 evt; +void *context; +}; + +static struct dentry *efct_debugfs_root; +static atomic_t efct_debugfs_count; + +static struct scsi_host_template efct_template = { + .module =THIS_MODULE , + .name =EFCT_DRIVER_NAME , + .supported_mode =MODE_TARGET , +}; + +/* globals */ +static struct fc_function_template efct_xport_functions; +static struct fc_function_template efct_vport_functions; + +static struct scsi_transport_template *efct_xport_fc_tt; +static struct scsi_transport_template *efct_vport_fc_tt; + +/* +* transport object is allocated, +* and associated with a device instance +*/ +struct efct_xport * +efct_xport_alloc (struct efct *efct) +{ +struct efct_xport *xport; + + xport =kmalloc (sizeof (*xport),GFP_KERNEL ); +if (!xport) +return xport; + +memset (xport,0 ,sizeof (*xport)); + xport->efct = efct; +return xport; +} + +static int +efct_xport_init_debugfs (struct efct *efct) +{ +/* Setup efct debugfs root directory */ +if (!efct_debugfs_root) { + efct_debugfs_root =debugfs_create_dir ("efct" ,NULL ); +atomic_set (&efct_debugfs_count,0 ); +if (!efct_debugfs_root) { +efc_log_err (efct,"failed to create debugfs entry\n" ); + goto debugfs_fail; + } + } + +/* Create a directory for sessions in root */ +if (!efct->sess_debugfs_dir) { + efct->sess_debugfs_dir =debugfs_create_dir ("sessions" ,NULL ); +if (!efct->sess_debugfs_dir) { +efc_log_err (efct, +"failed to create debugfs entry for sessions\n" ); + goto debugfs_fail; + } +atomic_inc (&efct_debugfs_count); + } + +return EFC_SUCCESS ; + +debugfs_fail: +return EFC_FAIL ; +} + +static void efct_xport_delete_debugfs (struct efct *efct) +{ +/* Remove session debugfs directory */ +debugfs_remove (efct->sess_debugfs_dir); + efct->sess_debugfs_dir =NULL ; +atomic_dec (&efct_debugfs_count); + +if (atomic_read (&efct_debugfs_count) ==0 ) { +/* remove root debugfs directory */ +debugfs_remove (efct_debugfs_root); + efct_debugfs_root =NULL ; + } +} + +int +efct_xport_attach (struct efct_xport *xport) +{ +struct efct *efct = xport->efct; +int rc; + + xport->fcfi.hold_frames = true; +spin_lock_init (&xport->fcfi.pend_frames_lock); +INIT_LIST_HEAD (&xport->fcfi.pend_frames); + + rc =efct_hw_setup (&efct->hw, efct, efct->pcidev); +if (rc) {
drivers/scsi/elx/efct/efct_xport.c line 118
Quoted 10 lines
drivers/scsi/elx/efct/efct_xport.c new file +10
-0+efc_log_err (efct,"%s: Can't setup hardware\n" , efct->desc); +return rc; + } + +efct_hw_parse_filter (&efct->hw, (void *)efct->filter_def); + + xport->io_pool =efct_io_pool_create (efct, efct->hw.config.n_sgl); +if (!xport->io_pool) { +efc_log_err (efct,"Can't allocate IO pool\n" ); +return -ENOMEM ;
I am still confused when you default error codes are used and when EFC_FAIL is used.
Quoted 226 lines
drivers/scsi/elx/efct/efct_xport.c new file +226
-0+ } + +return EFC_SUCCESS ; +} + +static void +efct_xport_link_stats_cb (int status,u32 num_counters, +struct efct_hw_link_stat_counts *counters,void *arg) +{ +union efct_xport_stats_u *result = arg; + + result->stats.link_stats.link_failure_error_count = + counters[EFCT_HW_LINK_STAT_LINK_FAILURE_COUNT ].counter; + result->stats.link_stats.loss_of_sync_error_count = + counters[EFCT_HW_LINK_STAT_LOSS_OF_SYNC_COUNT ].counter; + result->stats.link_stats.primitive_sequence_error_count = + counters[EFCT_HW_LINK_STAT_PRIMITIVE_SEQ_COUNT ].counter; + result->stats.link_stats.invalid_transmission_word_error_count = + counters[EFCT_HW_LINK_STAT_INVALID_XMIT_WORD_COUNT ].counter; + result->stats.link_stats.crc_error_count = + counters[EFCT_HW_LINK_STAT_CRC_COUNT ].counter; + +complete (&result->stats.done); +} + +static void +efct_xport_host_stats_cb (int status,u32 num_counters, +struct efct_hw_host_stat_counts *counters,void *arg) +{ +union efct_xport_stats_u *result = arg; + + result->stats.host_stats.transmit_kbyte_count = + counters[EFCT_HW_HOST_STAT_TX_KBYTE_COUNT ].counter; + result->stats.host_stats.receive_kbyte_count = + counters[EFCT_HW_HOST_STAT_RX_KBYTE_COUNT ].counter; + result->stats.host_stats.transmit_frame_count = + counters[EFCT_HW_HOST_STAT_TX_FRAME_COUNT ].counter; + result->stats.host_stats.receive_frame_count = + counters[EFCT_HW_HOST_STAT_RX_FRAME_COUNT ].counter; + +complete (&result->stats.done); +} + +static void +efct_xport_async_link_stats_cb (int status,u32 num_counters, +struct efct_hw_link_stat_counts *counters, +void *arg) +{ +union efct_xport_stats_u *result = arg; + + result->stats.link_stats.link_failure_error_count = + counters[EFCT_HW_LINK_STAT_LINK_FAILURE_COUNT ].counter; + result->stats.link_stats.loss_of_sync_error_count = + counters[EFCT_HW_LINK_STAT_LOSS_OF_SYNC_COUNT ].counter; + result->stats.link_stats.primitive_sequence_error_count = + counters[EFCT_HW_LINK_STAT_PRIMITIVE_SEQ_COUNT ].counter; + result->stats.link_stats.invalid_transmission_word_error_count = + counters[EFCT_HW_LINK_STAT_INVALID_XMIT_WORD_COUNT ].counter; + result->stats.link_stats.crc_error_count = + counters[EFCT_HW_LINK_STAT_CRC_COUNT ].counter; +} + +static void +efct_xport_async_host_stats_cb (int status,u32 num_counters, +struct efct_hw_host_stat_counts *counters, +void *arg) +{ +union efct_xport_stats_u *result = arg; + + result->stats.host_stats.transmit_kbyte_count = + counters[EFCT_HW_HOST_STAT_TX_KBYTE_COUNT ].counter; + result->stats.host_stats.receive_kbyte_count = + counters[EFCT_HW_HOST_STAT_RX_KBYTE_COUNT ].counter; + result->stats.host_stats.transmit_frame_count = + counters[EFCT_HW_HOST_STAT_TX_FRAME_COUNT ].counter; + result->stats.host_stats.receive_frame_count = + counters[EFCT_HW_HOST_STAT_RX_FRAME_COUNT ].counter; +} + +static void +efct_xport_config_stats_timer (struct efct *efct); + +static void +efct_xport_stats_timer_cb (struct timer_list *t) +{ +struct efct_xport *xport =from_timer (xport, t, stats_timer); +struct efct *efct = xport->efct; + +efct_xport_config_stats_timer (efct); +} + +static void +efct_xport_config_stats_timer (struct efct *efct) +{ +u32 timeout =3 *1000 ; +struct efct_xport *xport =NULL ; + +if (!efct) { +pr_err ("%s: failed to locate EFCT device\n" , __func__); +return ; + } + + xport = efct->xport; +efct_hw_get_link_stats (&efct->hw,0 ,0 ,0 , + efct_xport_async_link_stats_cb, + &xport->fc_xport_stats); +efct_hw_get_host_stats (&efct->hw,0 , efct_xport_async_host_stats_cb, + &xport->fc_xport_stats); + +timer_setup (&xport->stats_timer, + &efct_xport_stats_timer_cb,0 ); +mod_timer (&xport->stats_timer, + jiffies +msecs_to_jiffies (timeout)); +} + +int +efct_xport_initialize (struct efct_xport *xport) +{ +struct efct *efct = xport->efct; +int rc =0 ; + +/* Initialize io lists */ +spin_lock_init (&xport->io_pending_lock); +INIT_LIST_HEAD (&xport->io_pending_list); +atomic_set (&xport->io_active_count,0 ); +atomic_set (&xport->io_pending_count,0 ); +atomic_set (&xport->io_total_free,0 ); +atomic_set (&xport->io_total_pending,0 ); +atomic_set (&xport->io_alloc_failed_count,0 ); +atomic_set (&xport->io_pending_recursing,0 ); + rc =efct_hw_init (&efct->hw); +if (rc) { +efc_log_err (efct,"efct_hw_init failure\n" ); + goto out; + } + + rc =efct_scsi_tgt_new_device (efct); +if (rc) { +efc_log_err (efct,"failed to initialize target\n" ); + goto hw_init_out; + } + + rc =efct_scsi_new_device (efct); +if (rc) { +efc_log_err (efct,"failed to initialize initiator\n" ); + goto tgt_dev_out; + } + +/* Get FC link and host statistics perodically*/ +efct_xport_config_stats_timer (efct); + +efct_xport_init_debugfs (efct); + +return rc; + +tgt_dev_out: +efct_scsi_tgt_del_device (efct); + +hw_init_out: +efct_hw_teardown (&efct->hw); +out: +return rc; +} + +int +efct_xport_status (struct efct_xport *xport,enum efct_xport_status cmd, +union efct_xport_stats_u *result) +{ +u32 rc =0 ; +struct efct *efct =NULL ; +union efct_xport_stats_u value; + + efct = xport->efct; + +switch (cmd) { +case EFCT_XPORT_CONFIG_PORT_STATUS : +if (xport->configured_link_state ==0 ) { +/* +* Initial state is offline. configured_link_state is +* set to online explicitly when port is brought online +*/ + xport->configured_link_state =EFCT_XPORT_PORT_OFFLINE ; + } + result->value = xport->configured_link_state; +break ; + +case EFCT_XPORT_PORT_STATUS : +/* Determine port status based on link speed. */ + value.value =efct_hw_get_link_speed (&efct->hw); +if (value.value ==0 ) + result->value =0 ; +else + result->value =1 ; + rc =0 ; +break ; + +case EFCT_XPORT_LINK_SPEED : { + result->value =efct_hw_get_link_speed (&efct->hw); + +break ; + } +case EFCT_XPORT_LINK_STATISTICS : +memcpy ((void *)result, &efct->xport->fc_xport_stats, +sizeof (union efct_xport_stats_u )); +break ; +case EFCT_XPORT_LINK_STAT_RESET : { +/* Create a completion to synchronize the stat reset process. */ +init_completion (&result->stats.done); + +/* First reset the link stats */ + rc =efct_hw_get_link_stats (&efct->hw,0 ,1 ,1 , + efct_xport_link_stats_cb, result); + +/* Wait for completion to be signaled when the cmd completes */ +if (wait_for_completion_interruptible (&result->stats.done)) { +/* Undefined failure */ +efc_log_test (efct,"sem wait failed\n" ); + rc = -ENXIO ; +break ; + } + +/* Next reset the host stats */ + rc =efct_hw_get_host_stats (&efct->hw,1 , + efct_xport_host_stats_cb, result); + +/* Wait for completion to be signaled when the cmd completes */
drivers/scsi/elx/efct/efct_xport.c line 354
Quoted 10 lines
drivers/scsi/elx/efct/efct_xport.c new file +10
-0+if (wait_for_completion_interruptible (&result->stats.done)) { +/* Undefined failure */ +efc_log_test (efct,"sem wait failed\n" ); + rc = -ENXIO ; +break ; + } +break ; + } +default : + rc =-1 ;
Here again, rc is suddenely -1 and above it's -ENXIO.
Quoted 177 lines
drivers/scsi/elx/efct/efct_xport.c new file +169
-0+break ; + } + +return rc; +} + +int +efct_scsi_new_device (struct efct *efct) +{ +struct Scsi_Host *shost =NULL ; +int error =0 ; +struct efct_vport *vport =NULL ; +union efct_xport_stats_u speed; +u32 supported_speeds =0 ; + + shost =scsi_host_alloc (&efct_template,sizeof (*vport)); +if (!shost) { +efc_log_err (efct,"failed to allocate Scsi_Host struct\n" ); +return EFC_FAIL ; + } + +/* save shost to initiator-client context */ + efct->shost = shost; + +/* save efct information to shost LLD-specific space */ + vport = (struct efct_vport *)shost->hostdata; + vport->efct = efct; + +/* +* Set initial can_queue value to the max SCSI IOs. This is the maximum +* global queue depth (as opposed to the per-LUN queue depth -- +* .cmd_per_lun This may need to be adjusted for I+T mode. +*/ + shost->can_queue = efct->hw.config.n_io; + shost->max_cmd_len =16 ;/* 16-byte CDBs */ + shost->max_id =0xffff ; + shost->max_lun =0xffffffff ; + +/* +* can only accept (from mid-layer) as many SGEs as we've +* pre-registered +*/ + shost->sg_tablesize =sli_get_max_sgl (&efct->hw.sli); + +/* attach FC Transport template to shost */ + shost->transportt = efct_xport_fc_tt; +efc_log_debug (efct,"transport template=%p\n" , efct_xport_fc_tt); + +/* get pci_dev structure and add host to SCSI ML */ + error =scsi_add_host_with_dma (shost, &efct->pcidev->dev, + &efct->pcidev->dev); +if (error) { +efc_log_test (efct,"failed scsi_add_host_with_dma\n" ); +return EFC_FAIL ; + } + +/* Set symbolic name for host port */ +snprintf (fc_host_symbolic_name (shost), +sizeof (fc_host_symbolic_name (shost)), +"Emulex %s FV%s DV%s" , efct->model, + efct->hw.sli.fw_name[0 ],EFCT_DRIVER_VERSION ); + +/* Set host port supported classes */ +fc_host_supported_classes (shost) =FC_COS_CLASS3 ; + + speed.value =1000 ; +if (efct_xport_status (efct->xport,EFCT_XPORT_IS_SUPPORTED_LINK_SPEED , + &speed)) { + supported_speeds |=FC_PORTSPEED_1GBIT ; + } + speed.value =2000 ; +if (efct_xport_status (efct->xport,EFCT_XPORT_IS_SUPPORTED_LINK_SPEED , + &speed)) { + supported_speeds |=FC_PORTSPEED_2GBIT ; + } + speed.value =4000 ; +if (efct_xport_status (efct->xport,EFCT_XPORT_IS_SUPPORTED_LINK_SPEED , + &speed)) { + supported_speeds |=FC_PORTSPEED_4GBIT ; + } + speed.value =8000 ; +if (efct_xport_status (efct->xport,EFCT_XPORT_IS_SUPPORTED_LINK_SPEED , + &speed)) { + supported_speeds |=FC_PORTSPEED_8GBIT ; + } + speed.value =10000 ; +if (efct_xport_status (efct->xport,EFCT_XPORT_IS_SUPPORTED_LINK_SPEED , + &speed)) { + supported_speeds |=FC_PORTSPEED_10GBIT ; + } + speed.value =16000 ; +if (efct_xport_status (efct->xport,EFCT_XPORT_IS_SUPPORTED_LINK_SPEED , + &speed)) { + supported_speeds |=FC_PORTSPEED_16GBIT ; + } + speed.value =32000 ; +if (efct_xport_status (efct->xport,EFCT_XPORT_IS_SUPPORTED_LINK_SPEED , + &speed)) { + supported_speeds |=FC_PORTSPEED_32GBIT ; + } + +fc_host_supported_speeds (shost) = supported_speeds; + +fc_host_node_name (shost) =efct_get_wwnn (&efct->hw); +fc_host_port_name (shost) =efct_get_wwpn (&efct->hw); +fc_host_max_npiv_vports (shost) =128 ; + +return EFC_SUCCESS ; +} + +struct scsi_transport_template * +efct_attach_fc_transport (void ) +{ +struct scsi_transport_template *efct_fc_template =NULL ; + + efct_fc_template =fc_attach_transport (&efct_xport_functions); + +if (!efct_fc_template) +pr_err ("failed to attach EFCT with fc transport\n" ); + +return efct_fc_template; +} + +struct scsi_transport_template * +efct_attach_vport_fc_transport (void ) +{ +struct scsi_transport_template *efct_fc_template =NULL ; + + efct_fc_template =fc_attach_transport (&efct_vport_functions); + +if (!efct_fc_template) +pr_err ("failed to attach EFCT with fc transport\n" ); + +return efct_fc_template; +} + +int +efct_scsi_reg_fc_transport (void ) +{ +/* attach to appropriate scsi_tranport_* module */ + efct_xport_fc_tt =efct_attach_fc_transport (); +if (!efct_xport_fc_tt) { +pr_err ("%s: failed to attach to scsi_transport_*" , __func__); +return EFC_FAIL ; + } + + efct_vport_fc_tt =efct_attach_vport_fc_transport (); +if (!efct_vport_fc_tt) { +pr_err ("%s: failed to attach to scsi_transport_*" , __func__); +efct_release_fc_transport (efct_xport_fc_tt); + efct_xport_fc_tt =NULL ; +return EFC_FAIL ; + } + +return EFC_SUCCESS ; +} + +int +efct_scsi_release_fc_transport (void ) +{ +/* detach from scsi_transport_* */ +efct_release_fc_transport (efct_xport_fc_tt); + efct_xport_fc_tt =NULL ; +if (efct_vport_fc_tt) +efct_release_fc_transport (efct_vport_fc_tt); + efct_vport_fc_tt =NULL ; + +return EFC_SUCCESS ; +}drivers/scsi/elx/efct/efct_xport.h new file +2
-0@@ -0,0 +1,201 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/*
drivers/scsi/elx/efct/efct_xport.h line 12
Quoted 10 lines
drivers/scsi/elx/efct/efct_xport.h new file +10
-0+* Copyright (C) 2019 Broadcom. All Rights Reserved. The term +* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +*/ + +#if !defined(__EFCT_XPORT_H__) +#define __EFCT_XPORT_H__ + +/* FCFI lookup/pending frames */ +struct efct_xport_fcfi { +/* lock to protect pending frames access*/
Does it protect only pend_frames or the whole struct?
drivers/scsi/elx/efct/efct_xport.h line 18
Quoted 6 lines
drivers/scsi/elx/efct/efct_xport.h new file +6
-0+spinlock_t pend_frames_lock; +struct list_head pend_frames; +/* hold pending frames */ +bool hold_frames; +/* count of pending frames that were processed */ +u32 pend_frames_processed;
These members are not aligned.
Quoted 98 lines
drivers/scsi/elx/efct/efct_xport.h new file +98
-0+}; + +enum efct_xport_ctrl { +EFCT_XPORT_PORT_ONLINE =1 , +EFCT_XPORT_PORT_OFFLINE , +EFCT_XPORT_SHUTDOWN , +EFCT_XPORT_POST_NODE_EVENT , +EFCT_XPORT_WWNN_SET , +EFCT_XPORT_WWPN_SET , +}; + +enum efct_xport_status { +EFCT_XPORT_PORT_STATUS , +EFCT_XPORT_CONFIG_PORT_STATUS , +EFCT_XPORT_LINK_SPEED , +EFCT_XPORT_IS_SUPPORTED_LINK_SPEED , +EFCT_XPORT_LINK_STATISTICS , +EFCT_XPORT_LINK_STAT_RESET , +EFCT_XPORT_IS_QUIESCED +}; + +struct efct_xport_link_stats { +bool rec; +bool gec; +bool w02of; +bool w03of; +bool w04of; +bool w05of; +bool w06of; +bool w07of; +bool w08of; +bool w09of; +bool w10of; +bool w11of; +bool w12of; +bool w13of; +bool w14of; +bool w15of; +bool w16of; +bool w17of; +bool w18of; +bool w19of; +bool w20of; +bool w21of; +bool clrc; +bool clof1; +u32 link_failure_error_count; +u32 loss_of_sync_error_count; +u32 loss_of_signal_error_count; +u32 primitive_sequence_error_count; +u32 invalid_transmission_word_error_count; +u32 crc_error_count; +u32 primitive_sequence_event_timeout_count; +u32 elastic_buffer_overrun_error_count; +u32 arbitration_fc_al_timeout_count; +u32 advertised_receive_bufftor_to_buffer_credit; +u32 current_receive_buffer_to_buffer_credit; +u32 advertised_transmit_buffer_to_buffer_credit; +u32 current_transmit_buffer_to_buffer_credit; +u32 received_eofa_count; +u32 received_eofdti_count; +u32 received_eofni_count; +u32 received_soff_count; +u32 received_dropped_no_aer_count; +u32 received_dropped_no_available_rpi_resources_count; +u32 received_dropped_no_available_xri_resources_count; +}; + +struct efct_xport_host_stats { +bool cc; +u32 transmit_kbyte_count; +u32 receive_kbyte_count; +u32 transmit_frame_count; +u32 receive_frame_count; +u32 transmit_sequence_count; +u32 receive_sequence_count; +u32 total_exchanges_originator; +u32 total_exchanges_responder; +u32 receive_p_bsy_count; +u32 receive_f_bsy_count; +u32 dropped_frames_due_to_no_rq_buffer_count; +u32 empty_rq_timeout_count; +u32 dropped_frames_due_to_no_xri_count; +u32 empty_xri_pool_count; +}; + +struct efct_xport_host_statistics { +struct completion done; +struct efct_xport_link_stats link_stats; +struct efct_xport_host_stats host_stats; +}; + +union efct_xport_stats_u { +u32 value; +struct efct_xport_host_statistics stats; +}; + +struct efct_xport_fcp_stats {
drivers/scsi/elx/efct/efct_xport.h line 126
Quoted 10 lines
drivers/scsi/elx/efct/efct_xport.h new file +10
-0+u64 input_bytes; +u64 output_bytes; +u64 input_requests; +u64 output_requests; +u64 control_requests; +}; + +struct efct_xport { +struct efct *efct; +/* wwpn requested by user for primary sport */
kerneldoc?
Quoted 78 lines
drivers/scsi/elx/efct/efct_xport.h new file +75
-0+u64 req_wwpn; +/* wwnn requested by user for primary sport */ +u64 req_wwnn; + +struct efct_xport_fcfi fcfi; + +/* Nodes */ +/* number of allocated nodes */ +u32 nodes_count; +/* array of pointers to nodes */ +struct efc_node **nodes; +/* linked list of free nodes */ +struct list_head nodes_free_list; + +/* Io pool and counts */ +/* pointer to IO pool */ +struct efct_io_pool *io_pool; +/* used to track how often IO pool is empty */ +atomic_t io_alloc_failed_count; +/* lock for io_pending_list */ +spinlock_t io_pending_lock; +/* list of IOs waiting for HW resources +* lock: xport->io_pending_lock +* link: efct_io_s->io_pending_link +*/ +struct list_head io_pending_list; +/* count of totals IOS allocated */ +atomic_t io_total_alloc; +/* count of totals IOS free'd */ +atomic_t io_total_free; +/* count of totals IOS that were pended */ +atomic_t io_total_pending; +/* count of active IOS */ +atomic_t io_active_count; +/* count of pending IOS */ +atomic_t io_pending_count; +/* non-zero if efct_scsi_check_pending is executing */ +atomic_t io_pending_recursing; + +/* Port */ +/* requested link state */ +u32 configured_link_state; + +/* Timer for Statistics */ +struct timer_list stats_timer; +union efct_xport_stats_u fc_xport_stats; +struct efct_xport_fcp_stats fcp_stats; +}; + +struct efct_rport_data { +struct efc_node *node; +}; + +extern struct efct_xport * +efct_xport_alloc (struct efct *efct); +extern int +efct_xport_attach (struct efct_xport *xport); +extern int +efct_xport_initialize (struct efct_xport *xport); +extern int +efct_xport_detach (struct efct_xport *xport); +extern int +efct_xport_control (struct efct_xport *xport,enum efct_xport_ctrl cmd, ...); +extern int +efct_xport_status (struct efct_xport *xport,enum efct_xport_status cmd, +union efct_xport_stats_u *result); +extern void +efct_xport_free (struct efct_xport *xport); + +struct scsi_transport_template *efct_attach_fc_transport (void ); +struct scsi_transport_template *efct_attach_vport_fc_transport (void ); +void +efct_release_fc_transport (struct scsi_transport_template *transport_template); + +#endif /* __EFCT_XPORT_H__ */ Signature · 1 line
2.16.4
Thanks,
Daniel
PATCH v3 17/31 elx: efct: Hardware queues creation and deletion
In reply to James SmartThis patch continues the efct driver population.
This patch adds driver definitions for:
Routines for queue creation, deletion, and configuration.
---
v3:
Removed all Queue topology parsing code
Reworked queue creation code.
--- drivers/scsi/elx/efct/efct_hw_queues.c | 765 +++++++++++++++++++++++++++++++++ 1 file changed, 765 insertions(+) create mode 100644 drivers/scsi/elx/efct/efct_hw_queues.c
drivers/scsi/elx/efct/efct_hw_queues.c new file +765 -0
@@ -0,0 +1,765 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2019 Broadcom. All Rights Reserved. The term +* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +*/ + +#include "efct_driver.h" +#include "efct_hw.h" +#include "efct_unsol.h" + +/** +* SLI queues are created and initialized +*/ +enum efct_hw_rtn +efct_hw_init_queues (struct efct_hw *hw) +{ +struct hw_eq *eq =NULL ; +struct hw_cq *cq =NULL ; +struct hw_wq *wq =NULL ; +struct hw_rq *rq =NULL ; +struct hw_mq *mq =NULL ; + + hw->eq_count =0 ; + hw->cq_count =0 ; + hw->mq_count =0 ; + hw->wq_count =0 ; + hw->rq_count =0 ; + hw->hw_rq_count =0 ; +INIT_LIST_HEAD (&hw->eq_list); + +/* Create EQ */ + eq =efct_hw_new_eq (hw,EFCT_HW_EQ_DEPTH ); +if (!eq) { +efct_hw_queue_teardown (hw); +return EFCT_HW_RTN_NO_MEMORY ; + } + +/* Create RQ*/ + cq =efct_hw_new_cq (eq, hw->num_qentries[SLI_QTYPE_CQ ]); +if (!cq) { +efct_hw_queue_teardown (hw); +return EFCT_HW_RTN_NO_MEMORY ; + } + + rq =efct_hw_new_rq (cq,EFCT_HW_RQ_ENTRIES_DEF ); +if (!rq) { +efct_hw_queue_teardown (hw); +return EFCT_HW_RTN_NO_MEMORY ; + } + +/* Create MQ*/ + cq =efct_hw_new_cq (eq, hw->num_qentries[SLI_QTYPE_CQ ]); +if (!cq) { +efct_hw_queue_teardown (hw); +return EFCT_HW_RTN_NO_MEMORY ; + } + + mq =efct_hw_new_mq (cq,EFCT_HW_MQ_DEPTH ); +if (!mq) { +efct_hw_queue_teardown (hw); +return EFCT_HW_RTN_NO_MEMORY ; + } + +/* Create WQ */ + cq =efct_hw_new_cq (eq, hw->num_qentries[SLI_QTYPE_CQ ]); +if (!cq) { +efct_hw_queue_teardown (hw); +return EFCT_HW_RTN_NO_MEMORY ; + } + + wq =efct_hw_new_wq (cq, hw->num_qentries[SLI_QTYPE_WQ ]); +if (!wq) { +efct_hw_queue_teardown (hw); +return EFCT_HW_RTN_NO_MEMORY ; + } + +return EFCT_HW_RTN_SUCCESS ; +} + +/* Allocate a new EQ object */ +struct hw_eq * +efct_hw_new_eq (struct efct_hw *hw,u32 entry_count) +{ +struct hw_eq *eq =kmalloc (sizeof (*eq),GFP_KERNEL ); + +if (eq) { +memset (eq,0 ,sizeof (*eq)); + eq->type =SLI_QTYPE_EQ ; + eq->hw = hw; + eq->entry_count = entry_count; + eq->instance = hw->eq_count++; + eq->queue = &hw->eq[eq->instance]; +INIT_LIST_HEAD (&eq->cq_list); + +if (sli_queue_alloc (&hw->sli,SLI_QTYPE_EQ , + eq->queue, + entry_count,NULL )) { +efc_log_err (hw->os, +"EQ[%d] allocation failure\n" , + eq->instance); +kfree (eq); + eq =NULL ; + }else { +sli_eq_modify_delay (&hw->sli, eq->queue, +1 ,0 ,8 ); + hw->hw_eq[eq->instance] = eq; +INIT_LIST_HEAD (&eq->list_entry); +list_add_tail (&eq->list_entry, &hw->eq_list); +efc_log_debug (hw->os, +"create eq[%2d] id %3d len %4d\n" , + eq->instance, eq->queue->id, + eq->entry_count); + } + } +return eq; +} + +/* Allocate a new CQ object */ +struct hw_cq * +efct_hw_new_cq (struct hw_eq *eq,u32 entry_count) +{ +struct efct_hw *hw = eq->hw; +struct hw_cq *cq =kmalloc (sizeof (*cq),GFP_KERNEL ); + +if (cq) { +memset (cq,0 ,sizeof (*cq)); + cq->eq = eq; + cq->type =SLI_QTYPE_CQ ; + cq->instance = eq->hw->cq_count++; + cq->entry_count = entry_count; + cq->queue = &hw->cq[cq->instance]; + +INIT_LIST_HEAD (&cq->q_list); + +if (sli_queue_alloc (&hw->sli,SLI_QTYPE_CQ , cq->queue, + cq->entry_count, eq->queue)) { +efc_log_err (hw->os, +"CQ[%d] allocation failure len=%d\n" , + eq->instance, + eq->entry_count); +kfree (cq); + cq =NULL ; + }else { + hw->hw_cq[cq->instance] = cq; +INIT_LIST_HEAD (&cq->list_entry); +list_add_tail (&cq->list_entry, &eq->cq_list); +efc_log_debug (hw->os, +"create cq[%2d] id %3d len %4d\n" , + cq->instance, cq->queue->id, + cq->entry_count); + } + } +return cq; +} + +/* Allocate a new CQ Set of objects */ +u32 +efct_hw_new_cq_set (struct hw_eq *eqs[],struct hw_cq *cqs[], +u32 num_cqs,u32 entry_count) +{ +u32 i; +struct efct_hw *hw = eqs[0 ]->hw; +struct sli4 *sli4 = &hw->sli; +struct hw_cq *cq =NULL ; +struct sli4_queue *qs[SLI_MAX_CQ_SET_COUNT ]; +struct sli4_queue *assefct[SLI_MAX_CQ_SET_COUNT ]; + +/* Initialise CQS pointers to NULL */ +for (i =0 ; i < num_cqs; i++) + cqs[i] =NULL ; + +for (i =0 ; i < num_cqs; i++) { + cq =kmalloc (sizeof (*cq),GFP_KERNEL ); +if (!cq) + goto error; + +memset (cq,0 ,sizeof (*cq)); + cqs[i] = cq; + cq->eq = eqs[i]; + cq->type =SLI_QTYPE_CQ ; + cq->instance = hw->cq_count++; + cq->entry_count = entry_count; + cq->queue = &hw->cq[cq->instance]; + qs[i] = cq->queue; + assefct[i] = eqs[i]->queue; +INIT_LIST_HEAD (&cq->q_list); + } + +if (!sli_cq_alloc_set (sli4, qs, num_cqs, entry_count, assefct)) { +efc_log_err (hw->os,"Failed to create CQ Set.\n" ); + goto error; + } + +for (i =0 ; i < num_cqs; i++) { + hw->hw_cq[cqs[i]->instance] = cqs[i]; +INIT_LIST_HEAD (&cqs[i]->list_entry); +list_add_tail (&cqs[i]->list_entry, &cqs[i]->eq->cq_list); + } + +return EFC_SUCCESS ; + +error: +for (i =0 ; i < num_cqs; i++) { +kfree (cqs[i]); + cqs[i] =NULL ; + } +return EFC_FAIL ; +} + +/* Allocate a new MQ object */ +struct hw_mq * +efct_hw_new_mq (struct hw_cq *cq,u32 entry_count) +{ +struct efct_hw *hw = cq->eq->hw; +struct hw_mq *mq =kmalloc (sizeof (*mq),GFP_KERNEL ); + +if (mq) { +memset (mq,0 ,sizeof (*mq)); + mq->cq = cq; + mq->type =SLI_QTYPE_MQ ; + mq->instance = cq->eq->hw->mq_count++; + mq->entry_count = entry_count; + mq->entry_size =EFCT_HW_MQ_DEPTH ; + mq->queue = &hw->mq[mq->instance]; + +if (sli_queue_alloc (&hw->sli,SLI_QTYPE_MQ , + mq->queue, + mq->entry_size, + cq->queue)) { +efc_log_err (hw->os,"MQ allocation failure\n" ); +kfree (mq); + mq =NULL ; + }else { + hw->hw_mq[mq->instance] = mq; +INIT_LIST_HEAD (&mq->list_entry); +list_add_tail (&mq->list_entry, &cq->q_list); +efc_log_debug (hw->os, +"create mq[%2d] id %3d len %4d\n" , + mq->instance, mq->queue->id, + mq->entry_count); + } + } +return mq; +} + +/* Allocate a new WQ object */ +struct hw_wq * +efct_hw_new_wq (struct hw_cq *cq,u32 entry_count) +{ +struct efct_hw *hw = cq->eq->hw; +struct hw_wq *wq =kmalloc (sizeof (*wq),GFP_KERNEL ); + +if (wq) { +memset (wq,0 ,sizeof (*wq)); + wq->hw = cq->eq->hw; + wq->cq = cq; + wq->type =SLI_QTYPE_WQ ; + wq->instance = cq->eq->hw->wq_count++; + wq->entry_count = entry_count; + wq->queue = &hw->wq[wq->instance]; + wq->wqec_set_count =EFCT_HW_WQEC_SET_COUNT ; + wq->wqec_count = wq->wqec_set_count; + wq->free_count = wq->entry_count -1 ; +INIT_LIST_HEAD (&wq->pending_list); + +if (sli_queue_alloc (&hw->sli,SLI_QTYPE_WQ , wq->queue, + wq->entry_count, cq->queue)) { +efc_log_err (hw->os,"WQ allocation failure\n" ); +kfree (wq); + wq =NULL ; + }else { + hw->hw_wq[wq->instance] = wq; +INIT_LIST_HEAD (&wq->list_entry); +list_add_tail (&wq->list_entry, &cq->q_list); +efc_log_debug (hw->os, +"create wq[%2d] id %3d len %4d cls %d\n" , + wq->instance, wq->queue->id, + wq->entry_count, wq->class); + } + } +return wq; +} + +/* Allocate an RQ object, which encapsulates 2 SLI queues (for rq pair) */ +struct hw_rq * +efct_hw_new_rq (struct hw_cq *cq,u32 entry_count) +{ +struct efct_hw *hw = cq->eq->hw; +struct hw_rq *rq =kmalloc (sizeof (*rq),GFP_KERNEL ); + +if (rq) { +memset (rq,0 ,sizeof (*rq)); + rq->instance = hw->hw_rq_count++; + rq->cq = cq; + rq->type =SLI_QTYPE_RQ ; + rq->entry_count = entry_count; + +/* Create the header RQ */ + rq->hdr = &hw->rq[hw->rq_count]; + rq->hdr_entry_size =EFCT_HW_RQ_HEADER_SIZE ; + +if (sli_fc_rq_alloc (&hw->sli, rq->hdr, + rq->entry_count, + rq->hdr_entry_size, + cq->queue, + true)) { +efc_log_err (hw->os, +"RQ allocation failure - header\n" ); +kfree (rq); +return NULL ; + } +/* Update hw_rq_lookup[] */ + hw->hw_rq_lookup[hw->rq_count] = rq->instance; + hw->rq_count++; +efc_log_debug (hw->os, +"create rq[%2d] id %3d len %4d hdr size %4d\n" , + rq->instance, rq->hdr->id, rq->entry_count, + rq->hdr_entry_size); + +/* Create the default data RQ */ + rq->data = &hw->rq[hw->rq_count]; + rq->data_entry_size = hw->config.rq_default_buffer_size; + +if (sli_fc_rq_alloc (&hw->sli, rq->data, + rq->entry_count, + rq->data_entry_size, + cq->queue, + false)) { +efc_log_err (hw->os, +"RQ allocation failure - first burst\n" ); +kfree (rq); +return NULL ; + } +/* Update hw_rq_lookup[] */ + hw->hw_rq_lookup[hw->rq_count] = rq->instance; + hw->rq_count++; +efc_log_debug (hw->os, +"create rq[%2d] id %3d len %4d data size %4d\n" , + rq->instance, rq->data->id, rq->entry_count, + rq->data_entry_size); + + hw->hw_rq[rq->instance] = rq; +INIT_LIST_HEAD (&rq->list_entry); +list_add_tail (&rq->list_entry, &cq->q_list); + + rq->rq_tracker =kmalloc_array (rq->entry_count, +sizeof (struct efc_hw_sequence *), +GFP_ATOMIC ); +if (!rq->rq_tracker) +return NULL ; + +memset (rq->rq_tracker,0 , + rq->entry_count *sizeof (struct efc_hw_sequence *)); + } +return rq; +} + +/** +* Allocate an RQ object SET, where each element in set +* encapsulates 2 SLI queues (for rq pair) +*/ +u32 +efct_hw_new_rq_set (struct hw_cq *cqs[],struct hw_rq *rqs[], +u32 num_rq_pairs,u32 entry_count) +{ +struct efct_hw *hw = cqs[0 ]->eq->hw; +struct hw_rq *rq =NULL ; +struct sli4_queue *qs[SLI_MAX_RQ_SET_COUNT *2 ] = {NULL }; +u32 i, q_count, size; + +/* Initialise RQS pointers */ +for (i =0 ; i < num_rq_pairs; i++) + rqs[i] =NULL ; + +for (i =0 , q_count =0 ; i < num_rq_pairs; i++, q_count +=2 ) { + rq =kmalloc (sizeof (*rq),GFP_KERNEL ); +if (!rq) + goto error; + +memset (rq,0 ,sizeof (*rq)); + rqs[i] = rq; + rq->instance = hw->hw_rq_count++; + rq->cq = cqs[i]; + rq->type =SLI_QTYPE_RQ ; + rq->entry_count = entry_count; + +/* Header RQ */ + rq->hdr = &hw->rq[hw->rq_count]; + rq->hdr_entry_size =EFCT_HW_RQ_HEADER_SIZE ; + hw->hw_rq_lookup[hw->rq_count] = rq->instance; + hw->rq_count++; + qs[q_count] = rq->hdr; + +/* Data RQ */ + rq->data = &hw->rq[hw->rq_count]; + rq->data_entry_size = hw->config.rq_default_buffer_size; + hw->hw_rq_lookup[hw->rq_count] = rq->instance; + hw->rq_count++; + qs[q_count +1 ] = rq->data; + + rq->rq_tracker =NULL ; + } + +if (!sli_fc_rq_set_alloc (&hw->sli, num_rq_pairs, qs, + cqs[0 ]->queue->id, + rqs[0 ]->entry_count, + rqs[0 ]->hdr_entry_size, + rqs[0 ]->data_entry_size)) { +efc_log_err (hw->os, +"RQ Set allocation failure for base CQ=%d\n" , + cqs[0 ]->queue->id); + goto error; + } + +for (i =0 ; i < num_rq_pairs; i++) { + hw->hw_rq[rqs[i]->instance] = rqs[i]; +INIT_LIST_HEAD (&rqs[i]->list_entry); +list_add_tail (&rqs[i]->list_entry, &cqs[i]->q_list); + size =sizeof (struct efc_hw_sequence *) * rqs[i]->entry_count; + rqs[i]->rq_tracker =kmalloc (size,GFP_KERNEL ); +if (!rqs[i]->rq_tracker) + goto error; + } + +return EFC_SUCCESS ; + +error: +for (i =0 ; i < num_rq_pairs; i++) { +if (rqs[i]) { +kfree (rqs[i]->rq_tracker); +kfree (rqs[i]); + } + } + +return EFC_FAIL ; +} + +void +efct_hw_del_eq (struct hw_eq *eq) +{ +if (eq) { +struct hw_cq *cq; +struct hw_cq *cq_next; + +list_for_each_entry_safe (cq, cq_next, &eq->cq_list, list_entry) +efct_hw_del_cq (cq); +list_del (&eq->list_entry); + eq->hw->hw_eq[eq->instance] =NULL ; +kfree (eq); + } +} + +void +efct_hw_del_cq (struct hw_cq *cq) +{ +if (cq) { +struct hw_q *q; +struct hw_q *q_next; + +list_for_each_entry_safe (q, q_next, &cq->q_list, list_entry) { +switch (q->type) { +case SLI_QTYPE_MQ : +efct_hw_del_mq ((struct hw_mq *)q); +break ; +case SLI_QTYPE_WQ : +efct_hw_del_wq ((struct hw_wq *)q); +break ; +case SLI_QTYPE_RQ : +efct_hw_del_rq ((struct hw_rq *)q); +break ; +default : +break ; + } + } +list_del (&cq->list_entry); + cq->eq->hw->hw_cq[cq->instance] =NULL ; +kfree (cq); + } +} + +void +efct_hw_del_mq (struct hw_mq *mq) +{ +if (mq) { +list_del (&mq->list_entry); + mq->cq->eq->hw->hw_mq[mq->instance] =NULL ; +kfree (mq); + } +} + +void +efct_hw_del_wq (struct hw_wq *wq) +{ +if (wq) { +list_del (&wq->list_entry); + wq->cq->eq->hw->hw_wq[wq->instance] =NULL ; +kfree (wq); + } +} + +void +efct_hw_del_rq (struct hw_rq *rq) +{ +struct efct_hw *hw =NULL ; + +if (rq) { +/* Free RQ tracker */ +kfree (rq->rq_tracker); + rq->rq_tracker =NULL ; +list_del (&rq->list_entry); + hw = rq->cq->eq->hw; + hw->hw_rq[rq->instance] =NULL ; +kfree (rq); + } +} + +void +efct_hw_queue_dump (struct efct_hw *hw) +{ +struct hw_eq *eq; +struct hw_cq *cq; +struct hw_q *q; +struct hw_mq *mq; +struct hw_wq *wq; +struct hw_rq *rq; + +list_for_each_entry (eq, &hw->eq_list, list_entry) { +efc_log_debug (hw->os,"eq[%d] id %2d\n" , + eq->instance, eq->queue->id); +list_for_each_entry (cq, &eq->cq_list, list_entry) { +efc_log_debug (hw->os,"cq[%d] id %2d current\n" , + cq->instance, cq->queue->id); +list_for_each_entry (q, &cq->q_list, list_entry) { +switch (q->type) { +case SLI_QTYPE_MQ : + mq = (struct hw_mq *)q; +efc_log_debug (hw->os, +" mq[%d] id %2d\n" , + mq->instance, mq->queue->id); +break ; +case SLI_QTYPE_WQ : + wq = (struct hw_wq *)q; +efc_log_debug (hw->os, +" wq[%d] id %2d\n" , + wq->instance, wq->queue->id); +break ; +case SLI_QTYPE_RQ : + rq = (struct hw_rq *)q; +efc_log_debug (hw->os, +" rq[%d] hdr id %2d\n" , + rq->instance, rq->hdr->id); +break ; +default : +break ; + } + } + } + } +} + +void +efct_hw_queue_teardown (struct efct_hw *hw) +{ +struct hw_eq *eq; +struct hw_eq *eq_next; + +if (hw->eq_list.next) { +list_for_each_entry_safe (eq, eq_next, &hw->eq_list, + list_entry) { +efct_hw_del_eq (eq); + } + } +} + +static inline int +efct_hw_rqpair_find (struct efct_hw *hw,u16 rq_id) +{ +return efct_hw_queue_hash_find (hw->rq_hash, rq_id); +} + +static struct efc_hw_sequence * +efct_hw_rqpair_get (struct efct_hw *hw,u16 rqindex,u16 bufindex) +{ +struct sli4_queue *rq_hdr = &hw->rq[rqindex]; +struct efc_hw_sequence *seq =NULL ; +struct hw_rq *rq = hw->hw_rq[hw->hw_rq_lookup[rqindex]]; +unsigned long flags =0 ; + +if (bufindex >= rq_hdr->length) { +efc_log_err (hw->os, +"RQidx %d bufidx %d exceed ring len %d for id %d\n" , + rqindex, bufindex, rq_hdr->length, rq_hdr->id); +return NULL ; + } + +/* rq_hdr lock also covers rqindex+1 queue */ +spin_lock_irqsave (&rq_hdr->lock, flags); + + seq = rq->rq_tracker[bufindex]; + rq->rq_tracker[bufindex] =NULL ; + +if (!seq) { +efc_log_err (hw->os, +"RQbuf NULL, rqidx %d, bufidx %d, cur q idx = %d\n" , + rqindex, bufindex, rq_hdr->index); + } + +spin_unlock_irqrestore (&rq_hdr->lock, flags); +return seq; +} + +int +efct_hw_rqpair_process_rq (struct efct_hw *hw,struct hw_cq *cq, +u8 *cqe) +{ +u16 rq_id; +u32 index; +int rqindex; +int rq_status; +u32 h_len; +u32 p_len; +struct efc_hw_sequence *seq; +struct hw_rq *rq; + + rq_status =sli_fc_rqe_rqid_and_index (&hw->sli, cqe, + &rq_id, &index); +if (rq_status !=0 ) { +switch (rq_status) { +case SLI4_FC_ASYNC_RQ_BUF_LEN_EXCEEDED : +case SLI4_FC_ASYNC_RQ_DMA_FAILURE : +/* just get RQ buffer then return to chip */ + rqindex =efct_hw_rqpair_find (hw, rq_id); +if (rqindex <0 ) { +efc_log_test (hw->os, +"status=%#x: lookup fail id=%#x\n" , + rq_status, rq_id); +break ; + } + +/* get RQ buffer */ + seq =efct_hw_rqpair_get (hw, rqindex, index); + +/* return to chip */ +if (efct_hw_rqpair_sequence_free (hw, seq)) { +efc_log_test (hw->os, +"status=%#x,fail rtrn buf to RQ\n" , + rq_status); +break ; + } +break ; +case SLI4_FC_ASYNC_RQ_INSUFF_BUF_NEEDED : +case SLI4_FC_ASYNC_RQ_INSUFF_BUF_FRM_DISC : +/* +* since RQ buffers were not consumed, cannot return +* them to chip +* fall through +*/ +efc_log_debug (hw->os,"Warning: RCQE status=%#x,\n" , + rq_status); +default : +break ; + } +return EFC_FAIL ; + } + + rqindex =efct_hw_rqpair_find (hw, rq_id); +if (rqindex <0 ) { +efc_log_test (hw->os,"Error: rq_id lookup failed for id=%#x\n" , + rq_id); +return EFC_FAIL ; + } + + rq = hw->hw_rq[hw->hw_rq_lookup[rqindex]]; + rq->use_count++; + + seq =efct_hw_rqpair_get (hw, rqindex, index); +if (WARN_ON (!seq)) +return EFC_FAIL ; + + seq->hw = hw; + seq->auto_xrdy =0 ; + seq->out_of_xris =0 ; + seq->hio =NULL ; + +sli_fc_rqe_length (&hw->sli, cqe, &h_len, &p_len); + seq->header->dma.len = h_len; + seq->payload->dma.len = p_len; + seq->fcfi =sli_fc_rqe_fcfi (&hw->sli, cqe); + seq->hw_priv = cq->eq; + +efct_unsolicited_cb (hw->os, seq); + +return EFC_SUCCESS ; +} + +static int +efct_hw_rqpair_put (struct efct_hw *hw,struct efc_hw_sequence *seq) +{ +struct sli4_queue *rq_hdr = &hw->rq[seq->header->rqindex]; +struct sli4_queue *rq_payload = &hw->rq[seq->payload->rqindex]; +u32 hw_rq_index = hw->hw_rq_lookup[seq->header->rqindex]; +struct hw_rq *rq = hw->hw_rq[hw_rq_index]; +u32 phys_hdr[2 ]; +u32 phys_payload[2 ]; +int qindex_hdr; +int qindex_payload; +unsigned long flags =0 ; + +/* Update the RQ verification lookup tables */ + phys_hdr[0 ] =upper_32_bits (seq->header->dma.phys); + phys_hdr[1 ] =lower_32_bits (seq->header->dma.phys); + phys_payload[0 ] =upper_32_bits (seq->payload->dma.phys); + phys_payload[1 ] =lower_32_bits (seq->payload->dma.phys); + +/* rq_hdr lock also covers payload / header->rqindex+1 queue */ +spin_lock_irqsave (&rq_hdr->lock, flags); + +/* +* Note: The header must be posted last for buffer pair mode because +* posting on the header queue posts the payload queue as well. +* We do not ring the payload queue independently in RQ pair mode. +*/ + qindex_payload =sli_rq_write (&hw->sli, rq_payload, + (void *)phys_payload); + qindex_hdr =sli_rq_write (&hw->sli, rq_hdr, (void *)phys_hdr); +if (qindex_hdr <0 || + qindex_payload <0 ) { +efc_log_err (hw->os,"RQ_ID=%#x write failed\n" , rq_hdr->id); +spin_unlock_irqrestore (&rq_hdr->lock, flags); +return EFCT_HW_RTN_ERROR ; + } + +/* ensure the indexes are the same */ +WARN_ON (qindex_hdr != qindex_payload); + +/* Update the lookup table */ +if (!rq->rq_tracker[qindex_hdr]) { + rq->rq_tracker[qindex_hdr] = seq; + }else { +efc_log_test (hw->os, +"expected rq_tracker[%d][%d] buffer to be NULL\n" , + hw_rq_index, qindex_hdr); + } + +spin_unlock_irqrestore (&rq_hdr->lock, flags); +return EFCT_HW_RTN_SUCCESS ; +} + +enum efct_hw_rtn +efct_hw_rqpair_sequence_free (struct efct_hw *hw, +struct efc_hw_sequence *seq) +{ +enum efct_hw_rtn rc =EFCT_HW_RTN_SUCCESS ; + +/* +* Post the data buffer first. Because in RQ pair mode, ringing the +* doorbell of the header ring will post the data buffer as well. +*/ +if (efct_hw_rqpair_put (hw, seq)) { +efc_log_err (hw->os,"error writing buffers\n" ); +return EFCT_HW_RTN_ERROR ; + } + +return rc; +}
Signature · 1 line
2.16.4
Re: [PATCH v3 17/31] elx: efct: Hardware queues creation and deletion
Quoted 8 lines · James Smart
This patch continues the efct driver population.
This patch adds driver definitions for:
Routines for queue creation, deletion, and configuration.Signed-off-by Ram Vegesna <[email protected]>Signed-off-by James Smart <[email protected]>
Quoted 9 lines
---
v3:
Removed all Queue topology parsing code
Reworked queue creation code.--- drivers/scsi/elx/efct/efct_hw_queues.c | 765 +++++++++++++++++++++++++++++++++ 1 file changed, 765 insertions(+)create mode 100644
drivers/scsi/elx/efct/efct_hw_queues.c
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer