cregit-Linux how code gets into the kernel

Release 4.11 drivers/scsi/libfc/fc_exch.c

/*
 * Copyright(c) 2007 Intel Corporation. All rights reserved.
 * Copyright(c) 2008 Red Hat, Inc.  All rights reserved.
 * Copyright(c) 2008 Mike Christie
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Maintained at www.Open-FCoE.org
 */

/*
 * Fibre Channel exchange and sequence handling.
 */

#include <linux/timer.h>
#include <linux/slab.h>
#include <linux/err.h>
#include <linux/export.h>
#include <linux/log2.h>

#include <scsi/fc/fc_fc2.h>

#include <scsi/libfc.h>
#include <scsi/fc_encode.h>

#include "fc_libfc.h"


u16	fc_cpu_mask;		
/* cpu mask for possible cpus */

EXPORT_SYMBOL(fc_cpu_mask);

static u16	fc_cpu_order;	
/* 2's power to represent total possible cpus */

static struct kmem_cache *fc_em_cachep;	       
/* cache for exchanges */

static struct workqueue_struct *fc_exch_workqueue;

/*
 * Structure and function definitions for managing Fibre Channel Exchanges
 * and Sequences.
 *
 * The three primary structures used here are fc_exch_mgr, fc_exch, and fc_seq.
 *
 * fc_exch_mgr holds the exchange state for an N port
 *
 * fc_exch holds state for one exchange and links to its active sequence.
 *
 * fc_seq holds the state for an individual sequence.
 */

/**
 * struct fc_exch_pool - Per cpu exchange pool
 * @next_index:   Next possible free exchange index
 * @total_exches: Total allocated exchanges
 * @lock:         Exch pool lock
 * @ex_list:      List of exchanges
 *
 * This structure manages per cpu exchanges in array of exchange pointers.
 * This array is allocated followed by struct fc_exch_pool memory for
 * assigned range of exchanges to per cpu pool.
 */

struct fc_exch_pool {
	
spinlock_t	 lock;
	
struct list_head ex_list;
	
u16		 next_index;
	
u16		 total_exches;

	/* two cache of free slot in exch array */
	
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
 * @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:
 *
 * Exchanges are reference counted and exchange gets freed when the reference
 * count becomes zero.
 *
 * Timeouts:
 * Sequences are timed out for E_D_TOV and R_A_TOV.
 *
 * Sequence event handling:
 *
 * The following events may occur on initiator sequences:
 *
 *      Send.
 *          For now, the whole thing is sent.
 *      Receive ACK
 *          This applies only to class F.
 *          The sequence is marked complete.
 *      ULP completion.
 *          The upper layer calls fc_exch_done() when done
 *          with exchange and sequence tuple.
 *      RX-inferred completion.
 *          When we receive the next sequence on the same exchange, we can
 *          retire the previous sequence ID.  (XXX not implemented).
 *      Timeout.
 *          R_A_TOV frees the sequence ID.  If we're waiting for ACK,
 *          E_D_TOV causes abort and calls upper layer response handler
 *          with FC_EX_TIMEOUT error.
 *      Receive RJT
 *          XXX defer.
 *      Send ABTS
 *          On timeout.
 *
 * The following events may occur on recipient sequences:
 *
 *      Receive
 *          Allocate sequence for first frame received.
 *          Hold during receive handler.
 *          Release when final frame received.
 *          Keep status of last N of these for the ELS RES command.  XXX TBD.
 *      Receive ABTS
 *          Deallocate sequence
 *      Send RJT
 *          Deallocate
 *
 * For now, we neglect conditions where only part of a sequence was
 * received or transmitted, or where out-of-order receipt is detected.
 */

/*
 * Locking notes:
 *
 * The EM code run in a per-CPU worker thread.
 *
 * To protect against concurrency between a worker thread code and timers,
 * sequence allocation and deallocation must be locked.
 *  - exchange refcnt can be done atomicly without locks.
 *  - sequence allocation must be locked by exch lock.
 *  - If the EM pool lock and ex_lock must be taken at the same time, then the
 *    EM pool lock must be taken before the ex_lock.
 */

/*
 * opcode names for debugging.
 */

static char *fc_exch_rctl_names[] = FC_RCTL_NAMES_INIT;

/**
 * fc_exch_name_lookup() - Lookup name by opcode
 * @op:        Opcode to be looked up
 * @table:     Opcode/name table
 * @max_index: Index not to be exceeded
 *
 * This routine is used to determine a human-readable string identifying
 * a R_CTL opcode.
 */

static inline const char *fc_exch_name_lookup(unsigned int op, char **table, unsigned int max_index) { const char *name = NULL; if (op < max_index) name = table[op]; if (!name) name = "unknown"; return name; }

Contributors

PersonTokensPropCommitsCommitProp
Robert Love54100.00%1100.00%
Total54100.00%1100.00%

/** * fc_exch_rctl_name() - Wrapper routine for fc_exch_name_lookup() * @op: The opcode to be looked up */
static const char *fc_exch_rctl_name(unsigned int op) { return fc_exch_name_lookup(op, fc_exch_rctl_names, ARRAY_SIZE(fc_exch_rctl_names)); }

Contributors

PersonTokensPropCommitsCommitProp
Robert Love2496.00%150.00%
Vasiliy Kulikov14.00%150.00%
Total25100.00%2100.00%

/** * fc_exch_hold() - Increment an exchange's reference count * @ep: Echange to be held */
static inline void fc_exch_hold(struct fc_exch *ep) { atomic_inc(&ep->ex_refcnt); }

Contributors

PersonTokensPropCommitsCommitProp
Robert Love20100.00%2100.00%
Total20100.00%2100.00%

/** * fc_exch_setup_hdr() - Initialize a FC header by initializing some fields * and determine SOF and EOF. * @ep: The exchange to that will use the header * @fp: The frame whose header is to be modified * @f_ctl: F_CTL bits that will be used for the frame header * * The fields initialized by this routine are: fh_ox_id, fh_rx_id, * fh_seq_id, fh_seq_cnt and the SOF and EOF. */
static void fc_exch_setup_hdr(struct fc_exch *ep, struct fc_frame *fp, u32 f_ctl) { struct fc_frame_header *fh = fc_frame_header_get(fp); u16 fill; fr_sof(fp) = ep->class; if (ep->seq.cnt) fr_sof(fp) = fc_sof_normal(ep->class); if (f_ctl & FC_FC_END_SEQ) { fr_eof(fp) = FC_EOF_T; if (fc_sof_needs_ack(ep->class)) fr_eof(fp) = FC_EOF_N; /* * From F_CTL. * The number of fill bytes to make the length a 4-byte * multiple is the low order 2-bits of the f_ctl. * The fill itself will have been cleared by the frame * allocation. * After this, the length will be even, as expected by * the transport. */ fill = fr_len(fp) & 3; if (fill) { fill = 4 - fill; /* TODO, this may be a problem with fragmented skb */ skb_put(fp_skb(fp), fill); hton24(fh->fh_f_ctl, f_ctl | fill); } } else { WARN_ON(fr_len(fp) % 4 != 0); /* no pad to non last frame */ fr_eof(fp) = FC_EOF_N; } /* Initialize remaining fh fields from fc_fill_fc_hdr */ fh->fh_ox_id = htons(ep->oxid); fh->fh_rx_id = htons(ep->rxid); fh->fh_seq_id = ep->seq.id; fh->fh_seq_cnt = htons(ep->seq.cnt); }

Contributors

PersonTokensPropCommitsCommitProp
Robert Love20499.51%266.67%
Bart Van Assche10.49%133.33%
Total205100.00%3100.00%

/** * fc_exch_release() - Decrement an exchange's reference count * @ep: Exchange to be released * * If the reference count reaches zero and the exchange is complete, * it is freed. */
static void fc_exch_release(struct fc_exch *ep) { struct fc_exch_mgr *mp; if (atomic_dec_and_test(&ep->ex_refcnt)) { mp = ep->em; if (ep->destructor) ep->destructor(&ep->seq, ep->arg); WARN_ON(!(ep->esb_stat & ESB_ST_COMPLETE)); mempool_free(ep, mp->ep_pool); } }

Contributors

PersonTokensPropCommitsCommitProp
Robert Love7397.33%150.00%
Julia Lawall22.67%150.00%
Total75100.00%2100.00%

/** * fc_exch_timer_cancel() - cancel exch timer * @ep: The exchange whose timer to be canceled */
static inline void fc_exch_timer_cancel(struct fc_exch *ep) { if (cancel_delayed_work(&ep->timeout_work)) { FC_EXCH_DBG(ep, "Exchange timer canceled\n"); atomic_dec(&ep->ex_refcnt); /* drop hold for timer */ } }

Contributors

PersonTokensPropCommitsCommitProp
Vasu Dev40100.00%1100.00%
Total40100.00%1100.00%

/** * fc_exch_timer_set_locked() - Start a timer for an exchange w/ the * the exchange lock held * @ep: The exchange whose timer will start * @timer_msec: The timeout period * * Used for upper level protocols to time out the exchange. * The timer is cancelled when it fires or when the exchange completes. */
static inline void fc_exch_timer_set_locked(struct fc_exch *ep, unsigned int timer_msec) { if (ep->state & (FC_EX_RST_CLEANUP | FC_EX_DONE)) return; FC_EXCH_DBG(ep, "Exchange timer armed : %d msecs\n", timer_msec); fc_exch_hold(ep); /* hold for timer */ if (!queue_delayed_work(fc_exch_workqueue, &ep->timeout_work, msecs_to_jiffies(timer_msec))) { FC_EXCH_DBG(ep, "Exchange already queued\n"); fc_exch_release(ep); } }

Contributors

PersonTokensPropCommitsCommitProp
Vasu Dev5977.63%133.33%
Hannes Reinecke911.84%133.33%
Bart Van Assche810.53%133.33%
Total76100.00%3100.00%

/** * fc_exch_timer_set() - Lock the exchange and set the timer * @ep: The exchange whose timer will start * @timer_msec: The timeout period */
static void fc_exch_timer_set(struct fc_exch *ep, unsigned int timer_msec) { spin_lock_bh(&ep->ex_lock); fc_exch_timer_set_locked(ep, timer_msec); spin_unlock_bh(&ep->ex_lock); }

Contributors

PersonTokensPropCommitsCommitProp
Vasu Dev38100.00%1100.00%
Total38100.00%1100.00%

/** * fc_exch_done_locked() - Complete an exchange with the exchange lock held * @ep: The exchange that is complete * * Note: May sleep if invoked from outside a response handler. */
static int fc_exch_done_locked(struct fc_exch *ep) { int rc = 1; /* * We must check for completion in case there are two threads * tyring to complete this. But the rrq code will reuse the * ep, and in that case we only clear the resp and set it as * complete, so it can be reused by the timer to send the rrq. */ if (ep->state & FC_EX_DONE) return rc; ep->esb_stat |= ESB_ST_COMPLETE; if (!(ep->esb_stat & ESB_ST_REC_QUAL)) { ep->state |= FC_EX_DONE; fc_exch_timer_cancel(ep); rc = 0; } return rc; }

Contributors

PersonTokensPropCommitsCommitProp
Robert Love6498.46%150.00%
Vasu Dev11.54%150.00%
Total65100.00%2100.00%

static struct fc_exch fc_quarantine_exch; /** * fc_exch_ptr_get() - Return an exchange from an exchange pool * @pool: Exchange Pool to get an exchange from * @index: Index of the exchange within the pool * * Use the index to get an exchange from within an exchange pool. exches * will point to an array of exchange pointers. The index will select * the exchange within the array. */
static inline struct fc_exch *fc_exch_ptr_get(struct fc_exch_pool *pool, u16 index) { struct fc_exch **exches = (struct fc_exch **)(pool + 1); return exches[index]; }

Contributors

PersonTokensPropCommitsCommitProp
Vasu Dev41100.00%1100.00%
Total41100.00%1100.00%

/** * fc_exch_ptr_set() - Assign an exchange to a slot in an exchange pool * @pool: The pool to assign the exchange to * @index: The index in the pool where the exchange will be assigned * @ep: The exchange to assign to the pool */
static inline void fc_exch_ptr_set(struct fc_exch_pool *pool, u16 index, struct fc_exch *ep) { ((struct fc_exch **)(pool + 1))[index] = ep; }

Contributors

PersonTokensPropCommitsCommitProp
Vasu Dev39100.00%1100.00%
Total39100.00%1100.00%

/** * fc_exch_delete() - Delete an exchange * @ep: The exchange to be deleted */
static void fc_exch_delete(struct fc_exch *ep) { struct fc_exch_pool *pool; u16 index; pool = ep->pool; spin_lock_bh(&pool->lock); WARN_ON(pool->total_exches <= 0); pool->total_exches--; /* update cache of free slot */ index = (ep->xid - ep->em->min_xid) >> fc_cpu_order; if (!(ep->state & FC_EX_QUARANTINE)) { if (pool->left == FC_XID_UNKNOWN) pool->left = index; else if (pool->right == FC_XID_UNKNOWN) pool->right = index; else pool->next_index = index; fc_exch_ptr_set(pool, index, NULL); } else { fc_exch_ptr_set(pool, index, &fc_quarantine_exch); } list_del(&ep->ex_list); spin_unlock_bh(&pool->lock); fc_exch_release(ep); /* drop hold for exch in mp */ }

Contributors

PersonTokensPropCommitsCommitProp
Robert Love6340.13%125.00%
Hillf Danton4830.57%125.00%
Hannes Reinecke2616.56%125.00%
Vasu Dev2012.74%125.00%
Total157100.00%4100.00%


static int fc_seq_send_locked(struct fc_lport *lport, struct fc_seq *sp, struct fc_frame *fp) { struct fc_exch *ep; struct fc_frame_header *fh = fc_frame_header_get(fp); int error = -ENXIO; u32 f_ctl; u8 fh_type = fh->fh_type; ep = fc_seq_exch(sp); if (ep->esb_stat & (ESB_ST_COMPLETE | ESB_ST_ABNORMAL)) { fc_frame_free(fp); goto out; } WARN_ON(!(ep->esb_stat & ESB_ST_SEQ_INIT)); f_ctl = ntoh24(fh->fh_f_ctl); fc_exch_setup_hdr(ep, fp, f_ctl); fr_encaps(fp) = ep->encaps; /* * update sequence count if this frame is carrying * multiple FC frames when sequence offload is enabled * by LLD. */ if (fr_max_payload(fp)) sp->cnt += DIV_ROUND_UP((fr_len(fp) - sizeof(*fh)), fr_max_payload(fp)); else sp->cnt++; /* * Send the frame. */ error = lport->tt.frame_send(lport, fp); if (fh_type == FC_TYPE_BLS) goto out; /* * Update the exchange and sequence flags, * assuming all frames for the sequence have been sent. * We can only be called to send once for each sequence. */ ep->f_ctl = f_ctl & ~FC_FC_FIRST_SEQ; /* not first seq */ if (f_ctl & FC_FC_SEQ_INIT) ep->esb_stat &= ~ESB_ST_SEQ_INIT; out: return error; }

Contributors

PersonTokensPropCommitsCommitProp
Robert Love15372.51%337.50%
Bart Van Assche2511.85%112.50%
Vasu Dev136.16%225.00%
Neil Horman115.21%112.50%
Joe Eykholt94.27%112.50%
Total211100.00%8100.00%

/** * fc_seq_send() - Send a frame using existing sequence/exchange pair * @lport: The local port that the exchange will be sent on * @sp: The sequence to be sent * @fp: The frame to be sent on the exchange * * Note: The frame will be freed either by a direct call to fc_frame_free(fp) * or indirectly by calling libfc_function_template.frame_send(). */
int fc_seq_send(struct fc_lport *lport, struct fc_seq *sp, struct fc_frame *fp) { struct fc_exch *ep; int error; ep = fc_seq_exch(sp); spin_lock_bh(&ep->ex_lock); error = fc_seq_send_locked(lport, sp, fp); spin_unlock_bh(&ep->ex_lock); return error; }

Contributors

PersonTokensPropCommitsCommitProp
Neil Horman5381.54%133.33%
Robert Love1218.46%266.67%
Total65100.00%3100.00%

EXPORT_SYMBOL(fc_seq_send); /** * fc_seq_alloc() - Allocate a sequence for a given exchange * @ep: The exchange to allocate a new sequence for * @seq_id: The sequence ID to be used * * We don't support multiple originated sequences on the same exchange. * By implication, any previously originated sequence on this exchange * is complete, and we reallocate the same sequence. */
static struct fc_seq *fc_seq_alloc(struct fc_exch *ep, u8 seq_id) { struct fc_seq *sp; sp = &ep->seq; sp->ssb_stat = 0; sp->cnt = 0; sp->id = seq_id; return sp; }

Contributors

PersonTokensPropCommitsCommitProp
Robert Love49100.00%2100.00%
Total49100.00%2100.00%

/** * fc_seq_start_next_locked() - Allocate a new sequence on the same * exchange as the supplied sequence * @sp: The sequence/exchange to get a new sequence for */
static struct fc_seq *fc_seq_start_next_locked(struct fc_seq *sp) { struct fc_exch *ep = fc_seq_exch(sp); sp = fc_seq_alloc(ep, ep->seq_id++); FC_EXCH_DBG(ep, "f_ctl %6x seq %2x\n", ep->f_ctl, sp->id); return sp; }

Contributors

PersonTokensPropCommitsCommitProp
Robert Love53100.00%2100.00%
Total53100.00%2100.00%

/** * fc_seq_start_next() - Lock the exchange and get a new sequence * for a given sequence/exchange pair * @sp: The sequence/exchange to get a new exchange for */
struct fc_seq *fc_seq_start_next(struct fc_seq *sp) { struct fc_exch *ep = fc_seq_exch(sp); spin_lock_bh(&ep->ex_lock); sp = fc_seq_start_next_locked(sp); spin_unlock_bh(&ep->ex_lock); return sp; }

Contributors

PersonTokensPropCommitsCommitProp
Robert Love48100.00%2100.00%
Total48100.00%2100.00%

EXPORT_SYMBOL(fc_seq_start_next); /* * Set the response handler for the exchange associated with a sequence. * * Note: May sleep if invoked from outside a response handler. */
void fc_seq_set_resp(struct fc_seq *sp, void (*resp)(struct fc_seq *, struct fc_frame *, void *), void *arg) { struct fc_exch *ep = fc_seq_exch(sp); DEFINE_WAIT(wait); spin_lock_bh(&ep->ex_lock); while (ep->resp_active && ep->resp_task != current) { prepare_to_wait(&ep->resp_wq, &wait, TASK_UNINTERRUPTIBLE); spin_unlock_bh(&ep->ex_lock); schedule(); spin_lock_bh(&ep->ex_lock); } finish_wait(&ep->resp_wq, &wait); ep->resp = resp; ep->arg = arg; spin_unlock_bh(&ep->ex_lock); }

Contributors

PersonTokensPropCommitsCommitProp
Joe Eykholt7053.03%150.00%
Bart Van Assche6246.97%150.00%
Total132100.00%2100.00%

EXPORT_SYMBOL(fc_seq_set_resp); /** * fc_exch_abort_locked() - Abort an exchange * @ep: The exchange to be aborted * @timer_msec: The period of time to wait before aborting * * Abort an exchange and sequence. Generally called because of a * exchange timeout or an abort from the upper layer. * * A timer_msec can be specified for abort timeout, if non-zero * timer_msec value is specified then exchange resp handler * will be called with timeout error if no response to abort. * * Locking notes: Called with exch lock held * * Return value: 0 on success else error code */
static int fc_exch_abort_locked(struct fc_exch *ep, unsigned int timer_msec) { struct fc_seq *sp; struct fc_frame *fp; int error; FC_EXCH_DBG(ep, "exch: abort, time %d msecs\n", timer_msec); if (ep->esb_stat & (ESB_ST_COMPLETE | ESB_ST_ABNORMAL) || ep->state & (FC_EX_DONE | FC_EX_RST_CLEANUP)) { FC_EXCH_DBG(ep, "exch: already completed esb %x state %x\n", ep->esb_stat, ep->state); return -ENXIO; } /* * Send the abort on a new sequence if possible. */ sp = fc_seq_start_next_locked(&ep->seq); if (!sp) return -ENOMEM; if (timer_msec) fc_exch_timer_set_locked(ep, timer_msec); if (ep->sid) { /* * Send an abort for the sequence that timed out. */ fp = fc_frame_alloc(ep->lp, 0); if (fp) { ep->esb_stat |= ESB_ST_SEQ_INIT; fc_fill_fc_hdr(fp, FC_RCTL_BA_ABTS, ep->did, ep->sid, FC_TYPE_BLS, FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0); error = fc_seq_send_locked(ep->lp, sp, fp); } else { error = -ENOBUFS; } } else { /* * If not logged into the fabric, don't send ABTS but leave * sequence active until next timeout. */ error = 0; } ep->esb_stat |= ESB_ST_ABNORMAL; return error; }

Contributors

PersonTokensPropCommitsCommitProp
Robert Love14370.10%228.57%
Hannes Reinecke2612.75%114.29%
Bart Van Assche2512.25%114.29%
Vasu Dev94.41%228.57%
Neil Horman10.49%114.29%
Total204100.00%7100.00%

/** * fc_seq_exch_abort() - Abort an exchange and sequence * @req_sp: The sequence to be aborted * @timer_msec: The period of time to wait before aborting * * Generally called because of a timeout or an abort from the upper layer. * * Return value: 0 on success else error code */
int fc_seq_exch_abort(const struct fc_seq *req_sp, unsigned int timer_msec) { struct fc_exch *ep; int error; ep = fc_seq_exch(req_sp); spin_lock_bh(&ep->ex_lock); error = fc_exch_abort_locked(ep, timer_msec); spin_unlock_bh(&ep->ex_lock); return error; }

Contributors

PersonTokensPropCommitsCommitProp
Vasu Dev58100.00%1100.00%
Total58100.00%1100.00%

/** * fc_invoke_resp() - invoke ep->resp() * * Notes: * It is assumed that after initialization finished (this means the * first unlock of ex_lock after fc_exch_alloc()) ep->resp and ep->arg are * modified only via fc_seq_set_resp(). This guarantees that none of these * two variables changes if ep->resp_active > 0. * * If an fc_seq_set_resp() call is busy modifying ep->resp and ep->arg when * this function is invoked, the first spin_lock_bh() call in this function * will wait until fc_seq_set_resp() has finished modifying these variables. * * Since fc_exch_done() invokes fc_seq_set_resp() it is guaranteed that that * ep->resp() won't be invoked after fc_exch_done() has returned. * * The response handler itself may invoke fc_exch_done(), which will clear the * ep->resp pointer. * * Return value: * Returns true if and only if ep->resp has been invoked. */
static bool fc_invoke_resp(struct fc_exch *ep, struct fc_seq *sp, struct fc_frame *fp) { void (*resp)(struct fc_seq *, struct fc_frame *fp, void *arg); void *arg; bool res = false; spin_lock_bh(&ep->ex_lock); ep->resp_active++; if (ep->resp_task != current) ep->resp_task = !ep->resp_task ? current : NULL; resp = ep->resp; arg = ep->arg; spin_unlock_bh(&ep->ex_lock); if (resp) { resp(sp, fp, arg); res = true; } spin_lock_bh(&ep->ex_lock); if (--ep->resp_active == 0) ep->resp_task = NULL; spin_unlock_bh(&ep->ex_lock); if (ep->resp_active == 0) wake_up(&ep->resp_wq); return res; }

Contributors

PersonTokensPropCommitsCommitProp
Bart Van Assche173100.00%1100.00%
Total173100.00%1100.00%

/** * fc_exch_timeout() - Handle exchange timer expiration * @work: The work_struct identifying the exchange that timed out */
static void fc_exch_timeout(struct work_struct *work) { struct fc_exch *ep = container_of(work, struct fc_exch, timeout_work.work); struct fc_seq *sp = &ep->seq; u32 e_stat; int rc = 1; FC_EXCH_DBG(ep, "Exchange timed out state %x\n", ep->state); spin_lock_bh(&ep->ex_lock); if (ep->state & (FC_EX_RST_CLEANUP | FC_EX_DONE)) goto unlock; e_stat = ep->esb_stat; if (e_stat & ESB_ST_COMPLETE) { ep->esb_stat = e_stat & ~ESB_ST_REC_QUAL; spin_unlock_bh(&ep->ex_lock); if (e_stat & ESB_ST_REC_QUAL) fc_exch_rrq(ep); goto done; } else { if (e_stat & ESB_ST_ABNORMAL) rc = fc_exch_done_locked(ep); spin_unlock_bh(&ep->ex_lock); if (!rc) fc_exch_delete(ep); fc_invoke_resp(ep, sp, ERR_PTR(-FC_EX_TIMEOUT)); fc_seq_set_resp(sp, NULL, ep->arg); fc_seq_exch_abort(sp, 2 * ep->r_a_tov); goto done; } unlock: spin_unlock_bh(&ep->ex_lock); done: /* * This release matches the hold taken when the timer was set. */ fc_exch_release(ep); }

Contributors

PersonTokensPropCommitsCommitProp
Robert Love18887.44%228.57%
Bart Van Assche125.58%114.29%
Neerav Parikh83.72%114.29%
Hannes Reinecke52.33%114.29%
Vasu Dev20.93%228.57%
Total215100.00%7100.00%

/** * fc_exch_em_alloc() - Allocate an exchange from a specified EM. * @lport: The local port that the exchange is for * @mp: The exchange manager that will allocate the exchange * * Returns pointer to allocated fc_exch with exch lock held. */
static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport, struct fc_exch_mgr *mp) { struct fc_exch *ep; unsigned int cpu; u16 index; struct fc_exch_pool *pool; /* allocate memory for exchange */ ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC); if (!ep) { atomic_inc(&mp->stats.no_free_exch); goto out; } memset(ep, 0, sizeof(*ep)); cpu = get_cpu(); pool = per_cpu_ptr(mp->pool, cpu); spin_lock_bh(&pool->lock); put_cpu(); /* peek cache of free slot */ if (pool->left != FC_XID_UNKNOWN) { if (!WARN_ON(fc_exch_ptr_get(pool, pool->left))) { index = pool->left; pool->left = FC_XID_UNKNOWN; goto hit; } } if (pool->right != FC_XID_UNKNOWN) { if (!WARN_ON(fc_exch_ptr_get(pool, pool->right))) { index = pool->right; pool->right = FC_XID_UNKNOWN; goto hit; } } index = pool->next_index; /* allocate new exch from pool */ while (fc_exch_ptr_get(pool, index)) { index = index == mp->pool_max_index ? 0 : index + 1; if (index == pool->next_index) goto err; } pool->next_index = index == mp->pool_max_index ? 0 : index + 1; hit: fc_exch_hold(ep); /* hold for exch in mp */ spin_lock_init(&ep->ex_lock); /* * Hold exch lock for caller to prevent fc_exch_reset() * from releasing exch while fc_exch_alloc() caller is * still working on exch. */ spin_lock_bh(&ep->ex_lock); fc_exch_ptr_set(pool, index, ep); list_add_tail(&ep->ex_list, &pool->ex_list); fc_seq_alloc(ep, ep->seq_id++); pool->total_exches++; spin_unlock_bh(&pool->lock); /* * update exchange */ ep->oxid = ep->xid = (index << fc_cpu_order | cpu) + mp->min_xid; ep->em = mp; ep->pool = pool; ep->lp = lport; ep->f_ctl = FC_FC_FIRST_SEQ; /* next seq is first seq */ ep->rxid = FC_XID_UNKNOWN; ep->class = mp->class; ep->resp_active = 0; init_waitqueue_head(&ep->resp_wq); INIT_DELAYED_WORK(&ep->timeout_work, fc_exch_timeout); out: return ep; err: spin_unlock_bh(&pool->lock); atomic_inc(&mp->stats.no_free_exch_xid); mempool_free(ep, mp->ep_pool); return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
Robert Love24254.75%222.22%
Vasu Dev9521.49%333.33%
Hillf Danton5311.99%111.11%
Hannes Reinecke347.69%111.11%
Bart Van Assche143.17%111.11%
Joe Eykholt40.90%111.11%
Total442100.00%9100.00%

/** * fc_exch_alloc() - Allocate an exchange from an EM on a * local port's list of EMs. * @lport: The local port that will own the exchange * @fp: The FC frame that the exchange will be for * * This function walks the list of exchange manager(EM) * anchors to select an EM for a new exchange allocation. The * EM is selected when a NULL match function pointer is encountered * or when a call to a match function returns true. */
static struct fc_exch *fc_exch_alloc(struct fc_lport *lport, struct fc_frame *fp) { struct fc_exch_mgr_anchor *ema; struct fc_exch *ep; list_for_each_entry(ema, &lport->ema_list, ema_list) { if (!ema->match || ema->match(fp)) { ep = fc_exch_em_alloc(lport, ema->mp); if (ep) return ep; } } return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
Vasu Dev5674.67%133.33%
Martin K. Petersen1824.00%133.33%
Robert Love11.33%133.33%
Total75100.00%3100.00%

/** * fc_exch_find() - Lookup and hold an exchange * @mp: The exchange manager to lookup the exchange from * @xid: The XID of the exchange to look up */
static struct fc_exch *fc_exch_find(struct fc_exch_mgr *mp, u16 xid) { struct fc_lport *lport = mp->lport; struct fc_exch_pool *pool; struct fc_exch *ep = NULL; u16 cpu = xid & fc_cpu_mask; if (xid == FC_XID_UNKNOWN) return