drivers/scsi/libfc/fc_exch.c
Source file repositories/reference/linux-study-clean/drivers/scsi/libfc/fc_exch.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/scsi/libfc/fc_exch.c- Extension
.c- Size
- 72625 bytes
- Lines
- 2714
- Domain
- Driver Families
- Bucket
- drivers/scsi
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/timer.hlinux/slab.hlinux/err.hlinux/export.hlinux/log2.hscsi/fc/fc_fc2.hscsi/libfc.hfc_libfc.h
Detected Declarations
struct fc_exch_poolstruct fc_exch_mgrstruct fc_exch_mgr_anchorfunction fc_exch_name_lookupfunction fc_exch_rctl_namefunction fc_exch_holdfunction fc_exch_setup_hdrfunction fc_exch_releasefunction fc_exch_timer_cancelfunction fc_exch_timer_set_lockedfunction msecs_to_jiffiesfunction fc_exch_timer_setfunction fc_exch_done_lockedfunction fc_exch_ptr_getfunction fc_exch_ptr_setfunction fc_exch_deletefunction fc_seq_send_lockedfunction fc_seq_sendfunction fc_seq_allocfunction fc_seq_start_next_lockedfunction fc_seq_start_nextfunction fc_seq_set_respfunction fc_exch_abort_lockedfunction fc_seq_exch_abortfunction fc_invoke_respfunction fc_exch_timeoutfunction fc_exch_em_allocfunction fc_exch_allocfunction list_for_each_entryfunction fc_exch_findfunction fc_exch_donefunction fc_exch_respfunction fc_seq_lookup_recipfunction fc_seq_lookup_origfunction fc_exch_set_addrfunction fc_seq_els_rsp_sendfunction fc_seq_send_lastfunction fc_seq_send_ackfunction fc_exch_send_ba_rjtfunction fc_exch_recv_abtsfunction fc_seq_assignfunction fc_seq_releasefunction fc_exch_recv_reqfunction fc_exch_recv_seq_respfunction fc_exch_recv_respfunction fc_exch_abts_respfunction fc_exch_recv_blsfunction fc_seq_ls_acc
Annotated Snippet
struct fc_exch_pool {
spinlock_t lock;
struct list_head ex_list;
u16 next_index;
u16 total_exches;
u16 left;
u16 right;
} ____cacheline_aligned_in_smp;
/**
* struct fc_exch_mgr - The Exchange Manager (EM).
* @class: Default class for new sequences
* @kref: Reference counter
* @min_xid: Minimum exchange ID
* @max_xid: Maximum exchange ID
* @ep_pool: Reserved exchange pointers
* @pool_max_index: Max exch array index in exch pool
* @pool: Per cpu exch pool
* @lport: Local exchange port
* @stats: Statistics structure
*
* This structure is the center for creating exchanges and sequences.
* It manages the allocation of exchange IDs.
*/
struct fc_exch_mgr {
struct fc_exch_pool __percpu *pool;
mempool_t *ep_pool;
struct fc_lport *lport;
enum fc_class class;
struct kref kref;
u16 min_xid;
u16 max_xid;
u16 pool_max_index;
struct {
atomic_t no_free_exch;
atomic_t no_free_exch_xid;
atomic_t xid_not_found;
atomic_t xid_busy;
atomic_t seq_not_found;
atomic_t non_bls_resp;
} stats;
};
/**
* struct fc_exch_mgr_anchor - primary structure for list of EMs
* @ema_list: Exchange Manager Anchor list
* @mp: Exchange Manager associated with this anchor
* @match: Routine to determine if this anchor's EM should be used
*
* When walking the list of anchors the match routine will be called
* for each anchor to determine if that EM should be used. The last
* anchor in the list will always match to handle any exchanges not
* handled by other EMs. The non-default EMs would be added to the
* anchor list by HW that provides offloads.
*/
struct fc_exch_mgr_anchor {
struct list_head ema_list;
struct fc_exch_mgr *mp;
bool (*match)(struct fc_frame *);
};
static void fc_exch_rrq(struct fc_exch *);
static void fc_seq_ls_acc(struct fc_frame *);
static void fc_seq_ls_rjt(struct fc_frame *, enum fc_els_rjt_reason,
enum fc_els_rjt_explan);
static void fc_exch_els_rec(struct fc_frame *);
static void fc_exch_els_rrq(struct fc_frame *);
/*
* Internal implementation notes.
*
* The exchange manager is one by default in libfc but LLD may choose
* to have one per CPU. The sequence manager is one per exchange manager
* and currently never separated.
*
* Section 9.8 in FC-FS-2 specifies: "The SEQ_ID is a one-byte field
* assigned by the Sequence Initiator that shall be unique for a specific
* D_ID and S_ID pair while the Sequence is open." Note that it isn't
* qualified by exchange ID, which one might think it would be.
* In practice this limits the number of open sequences and exchanges to 256
* per session. For most targets we could treat this limit as per exchange.
*
* The exchange and its sequence are freed when the last sequence is received.
* It's possible for the remote port to leave an exchange open without
* sending any sequences.
*
* Notes on reference counts:
*
Annotation
- Immediate include surface: `linux/timer.h`, `linux/slab.h`, `linux/err.h`, `linux/export.h`, `linux/log2.h`, `scsi/fc/fc_fc2.h`, `scsi/libfc.h`, `fc_libfc.h`.
- Detected declarations: `struct fc_exch_pool`, `struct fc_exch_mgr`, `struct fc_exch_mgr_anchor`, `function fc_exch_name_lookup`, `function fc_exch_rctl_name`, `function fc_exch_hold`, `function fc_exch_setup_hdr`, `function fc_exch_release`, `function fc_exch_timer_cancel`, `function fc_exch_timer_set_locked`.
- Atlas domain: Driver Families / drivers/scsi.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.