1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (C) 2021 Broadcom. All Rights Reserved. The term
4 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
10 #include "scsi/fc/fc_els.h"
11 #include "scsi/fc/fc_fs.h"
12 #include "scsi/fc/fc_ns.h"
13 #include "scsi/fc/fc_gs.h"
14 #include "scsi/fc_frame.h"
15 #include "../include/efc_common.h"
16 #include "../libefc_sli/sli4.h"
18 #define EFC_SERVICE_PARMS_LENGTH 120
19 #define EFC_NAME_LENGTH 32
20 #define EFC_SM_NAME_LENGTH 64
21 #define EFC_DISPLAY_BUS_INFO_LENGTH 16
23 #define EFC_WWN_LENGTH 32
25 #define EFC_FC_ELS_DEFAULT_RETRIES 3
28 #define EFC_FC_ELS_SEND_DEFAULT_TIMEOUT 0
29 #define EFC_FC_FLOGI_TIMEOUT_SEC 5
30 #define EFC_SHUTDOWN_TIMEOUT_USEC 30000000
32 /* Return values for calls from base driver to libefc */
33 #define EFC_SCSI_CALL_COMPLETE 0
34 #define EFC_SCSI_CALL_ASYNC 1
36 /* Local port topology */
37 enum efc_nport_topology {
38 EFC_NPORT_TOPO_UNKNOWN = 0,
39 EFC_NPORT_TOPO_FABRIC,
44 #define enable_target_rscn(efc) 1
46 enum efc_node_shutd_rsn {
47 EFC_NODE_SHUTDOWN_DEFAULT = 0,
48 EFC_NODE_SHUTDOWN_EXPLICIT_LOGO,
49 EFC_NODE_SHUTDOWN_IMPLICIT_LOGO,
52 enum efc_node_send_ls_acc {
53 EFC_NODE_SEND_LS_ACC_NONE = 0,
54 EFC_NODE_SEND_LS_ACC_PLOGI,
55 EFC_NODE_SEND_LS_ACC_PRLI,
58 #define EFC_LINK_STATUS_UP 0
59 #define EFC_LINK_STATUS_DOWN 1
61 /* State machine context header */
63 void (*current_state)(struct efc_sm_ctx *ctx,
66 const char *description;
70 /* Description of discovered Fabric Domain */
71 struct efc_domain_record {
87 enum efc_hw_domain_event {
88 EFC_HW_DOMAIN_ALLOC_OK,
89 EFC_HW_DOMAIN_ALLOC_FAIL,
90 EFC_HW_DOMAIN_ATTACH_OK,
91 EFC_HW_DOMAIN_ATTACH_FAIL,
92 EFC_HW_DOMAIN_FREE_OK,
93 EFC_HW_DOMAIN_FREE_FAIL,
96 EFC_HW_DOMAIN_CHANGED,
100 * Fibre Channel port object
102 * @list_entry: nport list entry
103 * @ref: reference count, each node takes a reference
104 * @release: function to free nport object
105 * @efc: pointer back to efc
106 * @instance_index: unique instance index value
107 * @display_name: port display name
108 * @is_vport: Is NPIV port
109 * @free_req_pending: pending request to free resources
110 * @attached: mark attached if reg VPI succeeds
111 * @p2p_winner: TRUE if we're the point-to-point winner
112 * @domain: pointer back to domain
115 * @tgt_data: target backend private port data
116 * @ini_data: initiator backend private port data
118 * @fc_id: port FC address
119 * @dma: memory for Service Parameters
120 * @wwnn_str: wwpn string
121 * @sli_wwpn: SLI provided wwpn
122 * @sli_wwnn: SLI provided wwnn
123 * @sm: nport state machine context
124 * @lookup: fc_id to node lookup object
125 * @enable_ini: SCSI initiator enabled for this port
126 * @enable_tgt: SCSI target enabled for this port
127 * @enable_rscn: port will be expecting RSCN
128 * @shutting_down: nport in process of shutting down
129 * @p2p_port_id: our port id for point-to-point
130 * @topology: topology: fabric/p2p/unknown
131 * @service_params: login parameters
132 * @p2p_remote_port_id: remote node's port id for point-to-point
136 struct list_head list_entry;
138 void (*release)(struct kref *arg);
141 char display_name[EFC_NAME_LENGTH];
143 bool free_req_pending;
147 struct efc_domain *domain;
157 u8 wwnn_str[EFC_WWN_LENGTH];
161 struct efc_sm_ctx sm;
162 struct xarray lookup;
168 enum efc_nport_topology topology;
169 u8 service_params[EFC_SERVICE_PARMS_LENGTH];
170 u32 p2p_remote_port_id;
174 * Fibre Channel domain object
176 * This object is a container for the various SLI components needed
177 * to connect to the domain of a FC or FCoE switch
178 * @efc: pointer back to efc
179 * @instance_index: unique instance index value
180 * @display_name: Node display name
181 * @nport_list: linked list of nports associated with this domain
182 * @ref: Reference count, each nport takes a reference
183 * @release: Function to free domain object
184 * @ini_domain: initiator backend private domain data
185 * @tgt_domain: target backend private domain data
186 * @sm: state machine context
187 * @fcf: FC Forwarder table index
188 * @fcf_indicator: FCFI
190 * @nport_count: Number of nports allocated
191 * @dma: memory for Service Parameters
192 * @fcf_wwn: WWN for FCF/switch
193 * @drvsm: driver domain sm context
194 * @attached: set true after attach completes
196 * @is_loop: is loop topology
197 * @is_nlport: is public loop
198 * @domain_found_pending:A domain found is pending, drec is updated
199 * @req_domain_free: True if domain object should be free'd
200 * @req_accept_frames: set in domain state machine to enable frames
201 * @domain_notify_pend: Set in domain SM to avoid duplicate node event post
202 * @pending_drec: Pending drec if a domain found is pending
203 * @service_params: any nports service parameters
204 * @flogi_service_params:Fabric/P2p service parameters from FLOGI
205 * @lookup: d_id to node lookup object
206 * @nport: Pointer to first (physical) SLI port
210 char display_name[EFC_NAME_LENGTH];
211 struct list_head nport_list;
213 void (*release)(struct kref *arg);
217 /* Declarations private to HW/SLI */
224 /* Declarations private to FC trannport */
226 struct efc_sm_ctx drvsm;
231 bool domain_found_pending;
232 bool req_domain_free;
233 bool req_accept_frames;
234 bool domain_notify_pend;
236 struct efc_domain_record pending_drec;
237 u8 service_params[EFC_SERVICE_PARMS_LENGTH];
238 u8 flogi_service_params[EFC_SERVICE_PARMS_LENGTH];
240 struct xarray lookup;
242 struct efc_nport *nport;
248 * This object represents a connection between the SLI port and another
249 * Nx_Port on the fabric. Note this can be either a well known port such
250 * as a F_Port (i.e. ff:ff:fe) or another N_Port.
253 * @attached: true if attached
254 * @nport: associated SLI port
255 * @node: associated node
257 struct efc_remote_node {
264 struct efc_nport *nport;
270 * @efc: pointer back to efc structure
271 * @display_name: Node display name
272 * @nort: Assosiated nport pointer.
273 * @hold_frames: hold incoming frames if true
274 * @els_io_enabled: Enable allocating els ios for this node
275 * @els_ios_lock: lock to protect the els ios list
276 * @els_ios_list: ELS I/O's for this node
277 * @ini_node: backend initiator private node data
278 * @tgt_node: backend target private node data
279 * @rnode: Remote node
280 * @sm: state machine context
281 * @evtdepth: current event posting nesting depth
282 * @req_free: this node is to be free'd
283 * @attached: node is attached (REGLOGIN complete)
284 * @fcp_enabled: node is enabled to handle FCP
285 * @rscn_pending: for name server node RSCN is pending
286 * @send_plogi: send PLOGI accept, upon completion of node attach
287 * @send_plogi_acc: TRUE if io_alloc() is enabled.
288 * @send_ls_acc: type of LS acc to send
289 * @ls_acc_io: SCSI IO for LS acc
290 * @ls_acc_oxid: OX_ID for pending accept
291 * @ls_acc_did: D_ID for pending accept
292 * @shutdown_reason: reason for node shutdown
293 * @sparm_dma_buf: service parameters buffer
294 * @service_params: plogi/acc frame from remote device
295 * @pend_frames_lock: lock for inbound pending frames list
296 * @pend_frames: inbound pending frames list
297 * @pend_frames_processed:count of frames processed in hold frames interval
298 * @ox_id_in_use: used to verify one at a time us of ox_id
299 * @els_retries_remaining:for ELS, number of retries remaining
300 * @els_req_cnt: number of outstanding ELS requests
301 * @els_cmpl_cnt: number of outstanding ELS completions
302 * @abort_cnt: Abort counter for debugging purpos
303 * @current_state_name: current node state
304 * @prev_state_name: previous node state
305 * @current_evt: current event
306 * @prev_evt: previous event
307 * @targ: node is target capable
308 * @init: node is init capable
309 * @refound: Handle node refound case when node is being deleted
310 * @els_io_pend_list: list of pending (not yet processed) ELS IOs
311 * @els_io_active_list: list of active (processed) ELS IOs
312 * @nodedb_state: Node debugging, saved state
313 * @gidpt_delay_timer: GIDPT delay timer
314 * @time_last_gidpt_msec:Start time of last target RSCN GIDPT
315 * @wwnn: remote port WWNN
316 * @wwpn: remote port WWPN
320 char display_name[EFC_NAME_LENGTH];
321 struct efc_nport *nport;
323 void (*release)(struct kref *arg);
333 spinlock_t els_ios_lock;
334 struct list_head els_ios_list;
338 struct efc_remote_node rnode;
339 /* Declarations private to FC trannport */
340 struct efc_sm_ctx sm;
343 enum efc_node_send_ls_acc send_ls_acc;
347 enum efc_node_shutd_rsn shutdown_reason;
351 struct efc_dma sparm_dma_buf;
352 u8 service_params[EFC_SERVICE_PARMS_LENGTH];
353 spinlock_t pend_frames_lock;
354 struct list_head pend_frames;
355 u32 pend_frames_processed;
357 u32 els_retries_remaining;
362 char current_state_name[EFC_SM_NAME_LENGTH];
363 char prev_state_name[EFC_SM_NAME_LENGTH];
367 void (*nodedb_state)(struct efc_sm_ctx *ctx,
369 struct timer_list gidpt_delay_timer;
370 u64 time_last_gidpt_msec;
372 char wwnn[EFC_WWN_LENGTH];
373 char wwpn[EFC_WWN_LENGTH];
379 * Collection of the information required to restore a virtual port across
384 * @tgt_data: target backend pointer
385 * @ini_data: initiator backend pointe
386 * @nport: Used to match record after attaching for update
391 struct list_head list_entry;
399 struct efc_nport *nport;
402 #define node_printf(node, fmt, args...) \
403 efc_log_info(node->efc, "[%s] " fmt, node->display_name, ##args)
405 /* Node SM IO Context Callback structure */
409 struct efc_hw_rq_buffer *header;
410 struct efc_hw_rq_buffer *payload;
411 struct efc_dma els_rsp;
413 /* Actual length of data received */
417 struct efc_hw_rq_buffer {
425 * Defines a general FC sequence object
426 * @hw: HW that owns this sequence
427 * @fcfi: FCFI associated with sequence
428 * @header: Received frame header
429 * @payload: Received frame header
430 * @hw_priv: HW private context
432 struct efc_hw_sequence {
433 struct list_head list_entry;
436 struct efc_hw_rq_buffer *header;
437 struct efc_hw_rq_buffer *payload;
441 enum efc_disc_io_type {
443 EFC_DISC_IO_ELS_RESP,
448 struct efc_io_els_params {
454 struct efc_io_ct_params {
462 union efc_disc_io_param {
463 struct efc_io_els_params els;
464 struct efc_io_ct_params ct;
468 struct efc_dma req; /* send buffer */
469 struct efc_dma rsp; /* receive buffer */
470 enum efc_disc_io_type io_type; /* EFC_DISC_IO_TYPE enum*/
471 u16 xmit_len; /* Length of els request*/
472 u16 rsp_len; /* Max length of rsps to be rcvd */
473 u32 rpi; /* Registered RPI */
474 u32 vpi; /* VPI for this nport */
477 bool rpi_registered; /* if false, use tmp RPI */
478 union efc_disc_io_param iparam;
481 /* Return value indiacating the sequence can not be freed */
482 #define EFC_HW_SEQ_HOLD 0
483 /* Return value indiacating the sequence can be freed */
484 #define EFC_HW_SEQ_FREE 1
486 struct libefc_function_template {
488 int (*new_nport)(struct efc *efc, struct efc_nport *sp);
489 void (*del_nport)(struct efc *efc, struct efc_nport *sp);
492 int (*scsi_new_node)(struct efc *efc, struct efc_node *n);
493 int (*scsi_del_node)(struct efc *efc, struct efc_node *n, int reason);
495 int (*issue_mbox_rqst)(void *efct, void *buf, void *cb, void *arg);
497 int (*send_els)(struct efc *efc, struct efc_disc_io *io);
499 int (*send_bls)(struct efc *efc, u32 type, struct sli_bls_params *bls);
501 int (*hw_seq_free)(struct efc *efc, struct efc_hw_sequence *seq);
504 #define EFC_LOG_LIB 0x01
505 #define EFC_LOG_NODE 0x02
506 #define EFC_LOG_PORT 0x04
507 #define EFC_LOG_DOMAIN 0x08
508 #define EFC_LOG_ELS 0x10
509 #define EFC_LOG_DOMAIN_SM 0x20
510 #define EFC_LOG_SM 0x40
512 /* efc library port structure */
524 mempool_t *node_pool;
525 struct dma_pool *node_dma_pool;
530 struct list_head vport_list;
531 /* lock to protect the vport list */
532 spinlock_t vport_lock;
534 struct libefc_function_template tt;
535 /* lock to protect the discovery library.
536 * Refer to efclib.c for more details.
545 struct efc_domain *domain;
546 void (*domain_free_cb)(struct efc *efc, void *arg);
547 void *domain_free_cb_arg;
549 u64 tgt_rscn_delay_msec;
550 u64 tgt_rscn_period_msec;
552 bool external_loopback;
555 mempool_t *els_io_pool;
556 atomic_t els_io_alloc_failed_count;
558 /* hold pending frames */
560 /* lock to protect pending frames list access */
561 spinlock_t pend_frames_lock;
562 struct list_head pend_frames;
563 /* count of pending frames that were processed */
564 u32 pend_frames_processed;
569 * EFC library registration
570 * **********************************/
571 int efcport_init(struct efc *efc);
572 void efcport_destroy(struct efc *efc);
575 * **********************************/
576 int efc_domain_cb(void *arg, int event, void *data);
578 efc_register_domain_free_cb(struct efc *efc,
579 void (*callback)(struct efc *efc, void *arg),
584 * **********************************/
585 void efc_nport_cb(void *arg, int event, void *data);
587 efc_vport_create_spec(struct efc *efc, u64 wwnn, u64 wwpn, u32 fc_id,
588 bool enable_ini, bool enable_tgt,
589 void *tgt_data, void *ini_data);
590 int efc_nport_vport_new(struct efc_domain *domain, u64 wwpn,
591 u64 wwnn, u32 fc_id, bool ini, bool tgt,
592 void *tgt_data, void *ini_data);
593 int efc_nport_vport_del(struct efc *efc, struct efc_domain *domain,
596 void efc_vport_del_all(struct efc *efc);
600 * **********************************/
601 int efc_remote_node_cb(void *arg, int event, void *data);
602 void efc_node_fcid_display(u32 fc_id, char *buffer, u32 buf_len);
603 void efc_node_post_shutdown(struct efc_node *node, void *arg);
604 u64 efc_node_get_wwpn(struct efc_node *node);
607 * EFC FCP/ELS/CT interface
608 * **********************************/
609 void efc_dispatch_frame(struct efc *efc, struct efc_hw_sequence *seq);
610 void efc_disc_io_complete(struct efc_disc_io *io, u32 len, u32 status,
614 * EFC SCSI INTERACTION LAYER
615 * **********************************/
616 void efc_scsi_sess_reg_complete(struct efc_node *node, u32 status);
617 void efc_scsi_del_initiator_complete(struct efc *efc, struct efc_node *node);
618 void efc_scsi_del_target_complete(struct efc *efc, struct efc_node *node);
619 void efc_scsi_io_list_empty(struct efc *efc, struct efc_node *node);
621 #endif /* __EFCLIB_H__ */