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
Person | Tokens | Prop | Commits | CommitProp |
Robert Love | 54 | 100.00% | 1 | 100.00% |
Total | 54 | 100.00% | 1 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Robert Love | 24 | 96.00% | 1 | 50.00% |
Vasiliy Kulikov | 1 | 4.00% | 1 | 50.00% |
Total | 25 | 100.00% | 2 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Robert Love | 20 | 100.00% | 2 | 100.00% |
Total | 20 | 100.00% | 2 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Robert Love | 204 | 99.51% | 2 | 66.67% |
Bart Van Assche | 1 | 0.49% | 1 | 33.33% |
Total | 205 | 100.00% | 3 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Robert Love | 73 | 97.33% | 1 | 50.00% |
Julia Lawall | 2 | 2.67% | 1 | 50.00% |
Total | 75 | 100.00% | 2 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Vasu Dev | 40 | 100.00% | 1 | 100.00% |
Total | 40 | 100.00% | 1 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Vasu Dev | 59 | 77.63% | 1 | 33.33% |
Hannes Reinecke | 9 | 11.84% | 1 | 33.33% |
Bart Van Assche | 8 | 10.53% | 1 | 33.33% |
Total | 76 | 100.00% | 3 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Vasu Dev | 38 | 100.00% | 1 | 100.00% |
Total | 38 | 100.00% | 1 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Robert Love | 64 | 98.46% | 1 | 50.00% |
Vasu Dev | 1 | 1.54% | 1 | 50.00% |
Total | 65 | 100.00% | 2 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Vasu Dev | 41 | 100.00% | 1 | 100.00% |
Total | 41 | 100.00% | 1 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Vasu Dev | 39 | 100.00% | 1 | 100.00% |
Total | 39 | 100.00% | 1 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Robert Love | 63 | 40.13% | 1 | 25.00% |
Hillf Danton | 48 | 30.57% | 1 | 25.00% |
Hannes Reinecke | 26 | 16.56% | 1 | 25.00% |
Vasu Dev | 20 | 12.74% | 1 | 25.00% |
Total | 157 | 100.00% | 4 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Robert Love | 153 | 72.51% | 3 | 37.50% |
Bart Van Assche | 25 | 11.85% | 1 | 12.50% |
Vasu Dev | 13 | 6.16% | 2 | 25.00% |
Neil Horman | 11 | 5.21% | 1 | 12.50% |
Joe Eykholt | 9 | 4.27% | 1 | 12.50% |
Total | 211 | 100.00% | 8 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Neil Horman | 53 | 81.54% | 1 | 33.33% |
Robert Love | 12 | 18.46% | 2 | 66.67% |
Total | 65 | 100.00% | 3 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Robert Love | 49 | 100.00% | 2 | 100.00% |
Total | 49 | 100.00% | 2 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Robert Love | 53 | 100.00% | 2 | 100.00% |
Total | 53 | 100.00% | 2 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Robert Love | 48 | 100.00% | 2 | 100.00% |
Total | 48 | 100.00% | 2 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Joe Eykholt | 70 | 53.03% | 1 | 50.00% |
Bart Van Assche | 62 | 46.97% | 1 | 50.00% |
Total | 132 | 100.00% | 2 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Robert Love | 143 | 70.10% | 2 | 28.57% |
Hannes Reinecke | 26 | 12.75% | 1 | 14.29% |
Bart Van Assche | 25 | 12.25% | 1 | 14.29% |
Vasu Dev | 9 | 4.41% | 2 | 28.57% |
Neil Horman | 1 | 0.49% | 1 | 14.29% |
Total | 204 | 100.00% | 7 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Vasu Dev | 58 | 100.00% | 1 | 100.00% |
Total | 58 | 100.00% | 1 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Bart Van Assche | 173 | 100.00% | 1 | 100.00% |
Total | 173 | 100.00% | 1 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Robert Love | 188 | 87.44% | 2 | 28.57% |
Bart Van Assche | 12 | 5.58% | 1 | 14.29% |
Neerav Parikh | 8 | 3.72% | 1 | 14.29% |
Hannes Reinecke | 5 | 2.33% | 1 | 14.29% |
Vasu Dev | 2 | 0.93% | 2 | 28.57% |
Total | 215 | 100.00% | 7 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Robert Love | 242 | 54.75% | 2 | 22.22% |
Vasu Dev | 95 | 21.49% | 3 | 33.33% |
Hillf Danton | 53 | 11.99% | 1 | 11.11% |
Hannes Reinecke | 34 | 7.69% | 1 | 11.11% |
Bart Van Assche | 14 | 3.17% | 1 | 11.11% |
Joe Eykholt | 4 | 0.90% | 1 | 11.11% |
Total | 442 | 100.00% | 9 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Vasu Dev | 56 | 74.67% | 1 | 33.33% |
Martin K. Petersen | 18 | 24.00% | 1 | 33.33% |
Robert Love | 1 | 1.33% | 1 | 33.33% |
Total | 75 | 100.00% | 3 | 100.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