aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/libfc/fc_exch.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/libfc/fc_exch.c')
-rw-r--r--drivers/scsi/libfc/fc_exch.c934
1 files changed, 598 insertions, 336 deletions
diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
index c1c15748220c..e5df0d4db67e 100644
--- a/drivers/scsi/libfc/fc_exch.c
+++ b/drivers/scsi/libfc/fc_exch.c
@@ -24,7 +24,7 @@
24 */ 24 */
25 25
26#include <linux/timer.h> 26#include <linux/timer.h>
27#include <linux/gfp.h> 27#include <linux/slab.h>
28#include <linux/err.h> 28#include <linux/err.h>
29 29
30#include <scsi/fc/fc_fc2.h> 30#include <scsi/fc/fc_fc2.h>
@@ -32,10 +32,13 @@
32#include <scsi/libfc.h> 32#include <scsi/libfc.h>
33#include <scsi/fc_encode.h> 33#include <scsi/fc_encode.h>
34 34
35#include "fc_libfc.h"
36
35u16 fc_cpu_mask; /* cpu mask for possible cpus */ 37u16 fc_cpu_mask; /* cpu mask for possible cpus */
36EXPORT_SYMBOL(fc_cpu_mask); 38EXPORT_SYMBOL(fc_cpu_mask);
37static u16 fc_cpu_order; /* 2's power to represent total possible cpus */ 39static u16 fc_cpu_order; /* 2's power to represent total possible cpus */
38static struct kmem_cache *fc_em_cachep; /* cache for exchanges */ 40static struct kmem_cache *fc_em_cachep; /* cache for exchanges */
41struct workqueue_struct *fc_exch_workqueue;
39 42
40/* 43/*
41 * Structure and function definitions for managing Fibre Channel Exchanges 44 * Structure and function definitions for managing Fibre Channel Exchanges
@@ -50,35 +53,46 @@ static struct kmem_cache *fc_em_cachep; /* cache for exchanges */
50 * fc_seq holds the state for an individual sequence. 53 * fc_seq holds the state for an individual sequence.
51 */ 54 */
52 55
53/* 56/**
54 * Per cpu exchange pool 57 * struct fc_exch_pool - Per cpu exchange pool
58 * @next_index: Next possible free exchange index
59 * @total_exches: Total allocated exchanges
60 * @lock: Exch pool lock
61 * @ex_list: List of exchanges
55 * 62 *
56 * This structure manages per cpu exchanges in array of exchange pointers. 63 * This structure manages per cpu exchanges in array of exchange pointers.
57 * This array is allocated followed by struct fc_exch_pool memory for 64 * This array is allocated followed by struct fc_exch_pool memory for
58 * assigned range of exchanges to per cpu pool. 65 * assigned range of exchanges to per cpu pool.
59 */ 66 */
60struct fc_exch_pool { 67struct fc_exch_pool {
61 u16 next_index; /* next possible free exchange index */ 68 u16 next_index;
62 u16 total_exches; /* total allocated exchanges */ 69 u16 total_exches;
63 spinlock_t lock; /* exch pool lock */ 70 spinlock_t lock;
64 struct list_head ex_list; /* allocated exchanges list */ 71 struct list_head ex_list;
65}; 72};
66 73
67/* 74/**
68 * Exchange manager. 75 * struct fc_exch_mgr - The Exchange Manager (EM).
76 * @class: Default class for new sequences
77 * @kref: Reference counter
78 * @min_xid: Minimum exchange ID
79 * @max_xid: Maximum exchange ID
80 * @ep_pool: Reserved exchange pointers
81 * @pool_max_index: Max exch array index in exch pool
82 * @pool: Per cpu exch pool
83 * @stats: Statistics structure
69 * 84 *
70 * This structure is the center for creating exchanges and sequences. 85 * This structure is the center for creating exchanges and sequences.
71 * It manages the allocation of exchange IDs. 86 * It manages the allocation of exchange IDs.
72 */ 87 */
73struct fc_exch_mgr { 88struct fc_exch_mgr {
74 enum fc_class class; /* default class for sequences */ 89 enum fc_class class;
75 struct kref kref; /* exchange mgr reference count */ 90 struct kref kref;
76 u16 min_xid; /* min exchange ID */ 91 u16 min_xid;
77 u16 max_xid; /* max exchange ID */ 92 u16 max_xid;
78 struct list_head ex_list; /* allocated exchanges list */ 93 mempool_t *ep_pool;
79 mempool_t *ep_pool; /* reserve ep's */ 94 u16 pool_max_index;
80 u16 pool_max_index; /* max exch array index in exch pool */ 95 struct fc_exch_pool *pool;
81 struct fc_exch_pool *pool; /* per cpu exch pool */
82 96
83 /* 97 /*
84 * currently exchange mgr stats are updated but not used. 98 * currently exchange mgr stats are updated but not used.
@@ -96,6 +110,18 @@ struct fc_exch_mgr {
96}; 110};
97#define fc_seq_exch(sp) container_of(sp, struct fc_exch, seq) 111#define fc_seq_exch(sp) container_of(sp, struct fc_exch, seq)
98 112
113/**
114 * struct fc_exch_mgr_anchor - primary structure for list of EMs
115 * @ema_list: Exchange Manager Anchor list
116 * @mp: Exchange Manager associated with this anchor
117 * @match: Routine to determine if this anchor's EM should be used
118 *
119 * When walking the list of anchors the match routine will be called
120 * for each anchor to determine if that EM should be used. The last
121 * anchor in the list will always match to handle any exchanges not
122 * handled by other EMs. The non-default EMs would be added to the
123 * anchor list by HW that provides FCoE offloads.
124 */
99struct fc_exch_mgr_anchor { 125struct fc_exch_mgr_anchor {
100 struct list_head ema_list; 126 struct list_head ema_list;
101 struct fc_exch_mgr *mp; 127 struct fc_exch_mgr *mp;
@@ -108,7 +134,6 @@ static void fc_seq_ls_rjt(struct fc_seq *, enum fc_els_rjt_reason,
108 enum fc_els_rjt_explan); 134 enum fc_els_rjt_explan);
109static void fc_exch_els_rec(struct fc_seq *, struct fc_frame *); 135static void fc_exch_els_rec(struct fc_seq *, struct fc_frame *);
110static void fc_exch_els_rrq(struct fc_seq *, struct fc_frame *); 136static void fc_exch_els_rrq(struct fc_seq *, struct fc_frame *);
111static struct fc_seq *fc_seq_start_next_locked(struct fc_seq *sp);
112 137
113/* 138/*
114 * Internal implementation notes. 139 * Internal implementation notes.
@@ -196,6 +221,15 @@ static char *fc_exch_rctl_names[] = FC_RCTL_NAMES_INIT;
196 221
197#define FC_TABLE_SIZE(x) (sizeof(x) / sizeof(x[0])) 222#define FC_TABLE_SIZE(x) (sizeof(x) / sizeof(x[0]))
198 223
224/**
225 * fc_exch_name_lookup() - Lookup name by opcode
226 * @op: Opcode to be looked up
227 * @table: Opcode/name table
228 * @max_index: Index not to be exceeded
229 *
230 * This routine is used to determine a human-readable string identifying
231 * a R_CTL opcode.
232 */
199static inline const char *fc_exch_name_lookup(unsigned int op, char **table, 233static inline const char *fc_exch_name_lookup(unsigned int op, char **table,
200 unsigned int max_index) 234 unsigned int max_index)
201{ 235{
@@ -208,25 +242,34 @@ static inline const char *fc_exch_name_lookup(unsigned int op, char **table,
208 return name; 242 return name;
209} 243}
210 244
245/**
246 * fc_exch_rctl_name() - Wrapper routine for fc_exch_name_lookup()
247 * @op: The opcode to be looked up
248 */
211static const char *fc_exch_rctl_name(unsigned int op) 249static const char *fc_exch_rctl_name(unsigned int op)
212{ 250{
213 return fc_exch_name_lookup(op, fc_exch_rctl_names, 251 return fc_exch_name_lookup(op, fc_exch_rctl_names,
214 FC_TABLE_SIZE(fc_exch_rctl_names)); 252 FC_TABLE_SIZE(fc_exch_rctl_names));
215} 253}
216 254
217/* 255/**
218 * Hold an exchange - keep it from being freed. 256 * fc_exch_hold() - Increment an exchange's reference count
257 * @ep: Echange to be held
219 */ 258 */
220static void fc_exch_hold(struct fc_exch *ep) 259static inline void fc_exch_hold(struct fc_exch *ep)
221{ 260{
222 atomic_inc(&ep->ex_refcnt); 261 atomic_inc(&ep->ex_refcnt);
223} 262}
224 263
225/* 264/**
226 * setup fc hdr by initializing few more FC header fields and sof/eof. 265 * fc_exch_setup_hdr() - Initialize a FC header by initializing some fields
227 * Initialized fields by this func: 266 * and determine SOF and EOF.
228 * - fh_ox_id, fh_rx_id, fh_seq_id, fh_seq_cnt 267 * @ep: The exchange to that will use the header
229 * - sof and eof 268 * @fp: The frame whose header is to be modified
269 * @f_ctl: F_CTL bits that will be used for the frame header
270 *
271 * The fields initialized by this routine are: fh_ox_id, fh_rx_id,
272 * fh_seq_id, fh_seq_cnt and the SOF and EOF.
230 */ 273 */
231static void fc_exch_setup_hdr(struct fc_exch *ep, struct fc_frame *fp, 274static void fc_exch_setup_hdr(struct fc_exch *ep, struct fc_frame *fp,
232 u32 f_ctl) 275 u32 f_ctl)
@@ -243,7 +286,7 @@ static void fc_exch_setup_hdr(struct fc_exch *ep, struct fc_frame *fp,
243 if (fc_sof_needs_ack(ep->class)) 286 if (fc_sof_needs_ack(ep->class))
244 fr_eof(fp) = FC_EOF_N; 287 fr_eof(fp) = FC_EOF_N;
245 /* 288 /*
246 * Form f_ctl. 289 * From F_CTL.
247 * The number of fill bytes to make the length a 4-byte 290 * The number of fill bytes to make the length a 4-byte
248 * multiple is the low order 2-bits of the f_ctl. 291 * multiple is the low order 2-bits of the f_ctl.
249 * The fill itself will have been cleared by the frame 292 * The fill itself will have been cleared by the frame
@@ -273,10 +316,12 @@ static void fc_exch_setup_hdr(struct fc_exch *ep, struct fc_frame *fp,
273 fh->fh_seq_cnt = htons(ep->seq.cnt); 316 fh->fh_seq_cnt = htons(ep->seq.cnt);
274} 317}
275 318
276 319/**
277/* 320 * fc_exch_release() - Decrement an exchange's reference count
278 * Release a reference to an exchange. 321 * @ep: Exchange to be released
279 * If the refcnt goes to zero and the exchange is complete, it is freed. 322 *
323 * If the reference count reaches zero and the exchange is complete,
324 * it is freed.
280 */ 325 */
281static void fc_exch_release(struct fc_exch *ep) 326static void fc_exch_release(struct fc_exch *ep)
282{ 327{
@@ -291,6 +336,10 @@ static void fc_exch_release(struct fc_exch *ep)
291 } 336 }
292} 337}
293 338
339/**
340 * fc_exch_done_locked() - Complete an exchange with the exchange lock held
341 * @ep: The exchange that is complete
342 */
294static int fc_exch_done_locked(struct fc_exch *ep) 343static int fc_exch_done_locked(struct fc_exch *ep)
295{ 344{
296 int rc = 1; 345 int rc = 1;
@@ -315,6 +364,15 @@ static int fc_exch_done_locked(struct fc_exch *ep)
315 return rc; 364 return rc;
316} 365}
317 366
367/**
368 * fc_exch_ptr_get() - Return an exchange from an exchange pool
369 * @pool: Exchange Pool to get an exchange from
370 * @index: Index of the exchange within the pool
371 *
372 * Use the index to get an exchange from within an exchange pool. exches
373 * will point to an array of exchange pointers. The index will select
374 * the exchange within the array.
375 */
318static inline struct fc_exch *fc_exch_ptr_get(struct fc_exch_pool *pool, 376static inline struct fc_exch *fc_exch_ptr_get(struct fc_exch_pool *pool,
319 u16 index) 377 u16 index)
320{ 378{
@@ -322,12 +380,22 @@ static inline struct fc_exch *fc_exch_ptr_get(struct fc_exch_pool *pool,
322 return exches[index]; 380 return exches[index];
323} 381}
324 382
383/**
384 * fc_exch_ptr_set() - Assign an exchange to a slot in an exchange pool
385 * @pool: The pool to assign the exchange to
386 * @index: The index in the pool where the exchange will be assigned
387 * @ep: The exchange to assign to the pool
388 */
325static inline void fc_exch_ptr_set(struct fc_exch_pool *pool, u16 index, 389static inline void fc_exch_ptr_set(struct fc_exch_pool *pool, u16 index,
326 struct fc_exch *ep) 390 struct fc_exch *ep)
327{ 391{
328 ((struct fc_exch **)(pool + 1))[index] = ep; 392 ((struct fc_exch **)(pool + 1))[index] = ep;
329} 393}
330 394
395/**
396 * fc_exch_delete() - Delete an exchange
397 * @ep: The exchange to be deleted
398 */
331static void fc_exch_delete(struct fc_exch *ep) 399static void fc_exch_delete(struct fc_exch *ep)
332{ 400{
333 struct fc_exch_pool *pool; 401 struct fc_exch_pool *pool;
@@ -343,8 +411,14 @@ static void fc_exch_delete(struct fc_exch *ep)
343 fc_exch_release(ep); /* drop hold for exch in mp */ 411 fc_exch_release(ep); /* drop hold for exch in mp */
344} 412}
345 413
346/* 414/**
347 * Internal version of fc_exch_timer_set - used with lock held. 415 * fc_exch_timer_set_locked() - Start a timer for an exchange w/ the
416 * the exchange lock held
417 * @ep: The exchange whose timer will start
418 * @timer_msec: The timeout period
419 *
420 * Used for upper level protocols to time out the exchange.
421 * The timer is cancelled when it fires or when the exchange completes.
348 */ 422 */
349static inline void fc_exch_timer_set_locked(struct fc_exch *ep, 423static inline void fc_exch_timer_set_locked(struct fc_exch *ep,
350 unsigned int timer_msec) 424 unsigned int timer_msec)
@@ -354,17 +428,15 @@ static inline void fc_exch_timer_set_locked(struct fc_exch *ep,
354 428
355 FC_EXCH_DBG(ep, "Exchange timer armed\n"); 429 FC_EXCH_DBG(ep, "Exchange timer armed\n");
356 430
357 if (schedule_delayed_work(&ep->timeout_work, 431 if (queue_delayed_work(fc_exch_workqueue, &ep->timeout_work,
358 msecs_to_jiffies(timer_msec))) 432 msecs_to_jiffies(timer_msec)))
359 fc_exch_hold(ep); /* hold for timer */ 433 fc_exch_hold(ep); /* hold for timer */
360} 434}
361 435
362/* 436/**
363 * Set timer for an exchange. 437 * fc_exch_timer_set() - Lock the exchange and set the timer
364 * The time is a minimum delay in milliseconds until the timer fires. 438 * @ep: The exchange whose timer will start
365 * Used for upper level protocols to time out the exchange. 439 * @timer_msec: The timeout period
366 * The timer is cancelled when it fires or when the exchange completes.
367 * Returns non-zero if a timer couldn't be allocated.
368 */ 440 */
369static void fc_exch_timer_set(struct fc_exch *ep, unsigned int timer_msec) 441static void fc_exch_timer_set(struct fc_exch *ep, unsigned int timer_msec)
370{ 442{
@@ -373,7 +445,115 @@ static void fc_exch_timer_set(struct fc_exch *ep, unsigned int timer_msec)
373 spin_unlock_bh(&ep->ex_lock); 445 spin_unlock_bh(&ep->ex_lock);
374} 446}
375 447
376int fc_seq_exch_abort(const struct fc_seq *req_sp, unsigned int timer_msec) 448/**
449 * fc_seq_send() - Send a frame using existing sequence/exchange pair
450 * @lport: The local port that the exchange will be sent on
451 * @sp: The sequence to be sent
452 * @fp: The frame to be sent on the exchange
453 */
454static int fc_seq_send(struct fc_lport *lport, struct fc_seq *sp,
455 struct fc_frame *fp)
456{
457 struct fc_exch *ep;
458 struct fc_frame_header *fh = fc_frame_header_get(fp);
459 int error;
460 u32 f_ctl;
461
462 ep = fc_seq_exch(sp);
463 WARN_ON((ep->esb_stat & ESB_ST_SEQ_INIT) != ESB_ST_SEQ_INIT);
464
465 f_ctl = ntoh24(fh->fh_f_ctl);
466 fc_exch_setup_hdr(ep, fp, f_ctl);
467
468 /*
469 * update sequence count if this frame is carrying
470 * multiple FC frames when sequence offload is enabled
471 * by LLD.
472 */
473 if (fr_max_payload(fp))
474 sp->cnt += DIV_ROUND_UP((fr_len(fp) - sizeof(*fh)),
475 fr_max_payload(fp));
476 else
477 sp->cnt++;
478
479 /*
480 * Send the frame.
481 */
482 error = lport->tt.frame_send(lport, fp);
483
484 /*
485 * Update the exchange and sequence flags,
486 * assuming all frames for the sequence have been sent.
487 * We can only be called to send once for each sequence.
488 */
489 spin_lock_bh(&ep->ex_lock);
490 ep->f_ctl = f_ctl & ~FC_FC_FIRST_SEQ; /* not first seq */
491 if (f_ctl & (FC_FC_END_SEQ | FC_FC_SEQ_INIT))
492 ep->esb_stat &= ~ESB_ST_SEQ_INIT;
493 spin_unlock_bh(&ep->ex_lock);
494 return error;
495}
496
497/**
498 * fc_seq_alloc() - Allocate a sequence for a given exchange
499 * @ep: The exchange to allocate a new sequence for
500 * @seq_id: The sequence ID to be used
501 *
502 * We don't support multiple originated sequences on the same exchange.
503 * By implication, any previously originated sequence on this exchange
504 * is complete, and we reallocate the same sequence.
505 */
506static struct fc_seq *fc_seq_alloc(struct fc_exch *ep, u8 seq_id)
507{
508 struct fc_seq *sp;
509
510 sp = &ep->seq;
511 sp->ssb_stat = 0;
512 sp->cnt = 0;
513 sp->id = seq_id;
514 return sp;
515}
516
517/**
518 * fc_seq_start_next_locked() - Allocate a new sequence on the same
519 * exchange as the supplied sequence
520 * @sp: The sequence/exchange to get a new sequence for
521 */
522static struct fc_seq *fc_seq_start_next_locked(struct fc_seq *sp)
523{
524 struct fc_exch *ep = fc_seq_exch(sp);
525
526 sp = fc_seq_alloc(ep, ep->seq_id++);
527 FC_EXCH_DBG(ep, "f_ctl %6x seq %2x\n",
528 ep->f_ctl, sp->id);
529 return sp;
530}
531
532/**
533 * fc_seq_start_next() - Lock the exchange and get a new sequence
534 * for a given sequence/exchange pair
535 * @sp: The sequence/exchange to get a new exchange for
536 */
537static struct fc_seq *fc_seq_start_next(struct fc_seq *sp)
538{
539 struct fc_exch *ep = fc_seq_exch(sp);
540
541 spin_lock_bh(&ep->ex_lock);
542 sp = fc_seq_start_next_locked(sp);
543 spin_unlock_bh(&ep->ex_lock);
544
545 return sp;
546}
547
548/**
549 * fc_seq_exch_abort() - Abort an exchange and sequence
550 * @req_sp: The sequence to be aborted
551 * @timer_msec: The period of time to wait before aborting
552 *
553 * Generally called because of a timeout or an abort from the upper layer.
554 */
555static int fc_seq_exch_abort(const struct fc_seq *req_sp,
556 unsigned int timer_msec)
377{ 557{
378 struct fc_seq *sp; 558 struct fc_seq *sp;
379 struct fc_exch *ep; 559 struct fc_exch *ep;
@@ -422,11 +602,10 @@ int fc_seq_exch_abort(const struct fc_seq *req_sp, unsigned int timer_msec)
422 error = -ENOBUFS; 602 error = -ENOBUFS;
423 return error; 603 return error;
424} 604}
425EXPORT_SYMBOL(fc_seq_exch_abort);
426 605
427/* 606/**
428 * Exchange timeout - handle exchange timer expiration. 607 * fc_exch_timeout() - Handle exchange timer expiration
429 * The timer will have been cancelled before this is called. 608 * @work: The work_struct identifying the exchange that timed out
430 */ 609 */
431static void fc_exch_timeout(struct work_struct *work) 610static void fc_exch_timeout(struct work_struct *work)
432{ 611{
@@ -474,28 +653,10 @@ done:
474 fc_exch_release(ep); 653 fc_exch_release(ep);
475} 654}
476 655
477/*
478 * Allocate a sequence.
479 *
480 * We don't support multiple originated sequences on the same exchange.
481 * By implication, any previously originated sequence on this exchange
482 * is complete, and we reallocate the same sequence.
483 */
484static struct fc_seq *fc_seq_alloc(struct fc_exch *ep, u8 seq_id)
485{
486 struct fc_seq *sp;
487
488 sp = &ep->seq;
489 sp->ssb_stat = 0;
490 sp->cnt = 0;
491 sp->id = seq_id;
492 return sp;
493}
494
495/** 656/**
496 * fc_exch_em_alloc() - allocate an exchange from a specified EM. 657 * fc_exch_em_alloc() - Allocate an exchange from a specified EM.
497 * @lport: ptr to the local port 658 * @lport: The local port that the exchange is for
498 * @mp: ptr to the exchange manager 659 * @mp: The exchange manager that will allocate the exchange
499 * 660 *
500 * Returns pointer to allocated fc_exch with exch lock held. 661 * Returns pointer to allocated fc_exch with exch lock held.
501 */ 662 */
@@ -563,16 +724,18 @@ err:
563} 724}
564 725
565/** 726/**
566 * fc_exch_alloc() - allocate an exchange. 727 * fc_exch_alloc() - Allocate an exchange from an EM on a
567 * @lport: ptr to the local port 728 * local port's list of EMs.
568 * @fp: ptr to the FC frame 729 * @lport: The local port that will own the exchange
730 * @fp: The FC frame that the exchange will be for
569 * 731 *
570 * This function walks the list of the exchange manager(EM) 732 * This function walks the list of exchange manager(EM)
571 * anchors to select a EM for new exchange allocation. The 733 * anchors to select an EM for a new exchange allocation. The
572 * EM is selected having either a NULL match function pointer 734 * EM is selected when a NULL match function pointer is encountered
573 * or call to match function returning true. 735 * or when a call to a match function returns true.
574 */ 736 */
575struct fc_exch *fc_exch_alloc(struct fc_lport *lport, struct fc_frame *fp) 737static struct fc_exch *fc_exch_alloc(struct fc_lport *lport,
738 struct fc_frame *fp)
576{ 739{
577 struct fc_exch_mgr_anchor *ema; 740 struct fc_exch_mgr_anchor *ema;
578 struct fc_exch *ep; 741 struct fc_exch *ep;
@@ -586,10 +749,11 @@ struct fc_exch *fc_exch_alloc(struct fc_lport *lport, struct fc_frame *fp)
586 } 749 }
587 return NULL; 750 return NULL;
588} 751}
589EXPORT_SYMBOL(fc_exch_alloc);
590 752
591/* 753/**
592 * Lookup and hold an exchange. 754 * fc_exch_find() - Lookup and hold an exchange
755 * @mp: The exchange manager to lookup the exchange from
756 * @xid: The XID of the exchange to look up
593 */ 757 */
594static struct fc_exch *fc_exch_find(struct fc_exch_mgr *mp, u16 xid) 758static struct fc_exch *fc_exch_find(struct fc_exch_mgr *mp, u16 xid)
595{ 759{
@@ -609,7 +773,13 @@ static struct fc_exch *fc_exch_find(struct fc_exch_mgr *mp, u16 xid)
609 return ep; 773 return ep;
610} 774}
611 775
612void fc_exch_done(struct fc_seq *sp) 776
777/**
778 * fc_exch_done() - Indicate that an exchange/sequence tuple is complete and
779 * the memory allocated for the related objects may be freed.
780 * @sp: The sequence that has completed
781 */
782static void fc_exch_done(struct fc_seq *sp)
613{ 783{
614 struct fc_exch *ep = fc_seq_exch(sp); 784 struct fc_exch *ep = fc_seq_exch(sp);
615 int rc; 785 int rc;
@@ -620,10 +790,13 @@ void fc_exch_done(struct fc_seq *sp)
620 if (!rc) 790 if (!rc)
621 fc_exch_delete(ep); 791 fc_exch_delete(ep);
622} 792}
623EXPORT_SYMBOL(fc_exch_done);
624 793
625/* 794/**
626 * Allocate a new exchange as responder. 795 * fc_exch_resp() - Allocate a new exchange for a response frame
796 * @lport: The local port that the exchange was for
797 * @mp: The exchange manager to allocate the exchange from
798 * @fp: The response frame
799 *
627 * Sets the responder ID in the frame header. 800 * Sets the responder ID in the frame header.
628 */ 801 */
629static struct fc_exch *fc_exch_resp(struct fc_lport *lport, 802static struct fc_exch *fc_exch_resp(struct fc_lport *lport,
@@ -664,8 +837,13 @@ static struct fc_exch *fc_exch_resp(struct fc_lport *lport,
664 return ep; 837 return ep;
665} 838}
666 839
667/* 840/**
668 * Find a sequence for receive where the other end is originating the sequence. 841 * fc_seq_lookup_recip() - Find a sequence where the other end
842 * originated the sequence
843 * @lport: The local port that the frame was sent to
844 * @mp: The Exchange Manager to lookup the exchange from
845 * @fp: The frame associated with the sequence we're looking for
846 *
669 * If fc_pf_rjt_reason is FC_RJT_NONE then this function will have a hold 847 * If fc_pf_rjt_reason is FC_RJT_NONE then this function will have a hold
670 * on the ep that should be released by the caller. 848 * on the ep that should be released by the caller.
671 */ 849 */
@@ -771,10 +949,12 @@ rel:
771 return reject; 949 return reject;
772} 950}
773 951
774/* 952/**
775 * Find the sequence for a frame being received. 953 * fc_seq_lookup_orig() - Find a sequence where this end
776 * We originated the sequence, so it should be found. 954 * originated the sequence
777 * We may or may not have originated the exchange. 955 * @mp: The Exchange Manager to lookup the exchange from
956 * @fp: The frame associated with the sequence we're looking for
957 *
778 * Does not hold the sequence for the caller. 958 * Does not hold the sequence for the caller.
779 */ 959 */
780static struct fc_seq *fc_seq_lookup_orig(struct fc_exch_mgr *mp, 960static struct fc_seq *fc_seq_lookup_orig(struct fc_exch_mgr *mp,
@@ -806,8 +986,12 @@ static struct fc_seq *fc_seq_lookup_orig(struct fc_exch_mgr *mp,
806 return sp; 986 return sp;
807} 987}
808 988
809/* 989/**
810 * Set addresses for an exchange. 990 * fc_exch_set_addr() - Set the source and destination IDs for an exchange
991 * @ep: The exchange to set the addresses for
992 * @orig_id: The originator's ID
993 * @resp_id: The responder's ID
994 *
811 * Note this must be done before the first sequence of the exchange is sent. 995 * Note this must be done before the first sequence of the exchange is sent.
812 */ 996 */
813static void fc_exch_set_addr(struct fc_exch *ep, 997static void fc_exch_set_addr(struct fc_exch *ep,
@@ -823,76 +1007,15 @@ static void fc_exch_set_addr(struct fc_exch *ep,
823 } 1007 }
824} 1008}
825 1009
826static struct fc_seq *fc_seq_start_next_locked(struct fc_seq *sp) 1010/**
827{ 1011 * fc_seq_els_rsp_send() - Send an ELS response using infomation from
828 struct fc_exch *ep = fc_seq_exch(sp); 1012 * the existing sequence/exchange.
829 1013 * @sp: The sequence/exchange to get information from
830 sp = fc_seq_alloc(ep, ep->seq_id++); 1014 * @els_cmd: The ELS command to be sent
831 FC_EXCH_DBG(ep, "f_ctl %6x seq %2x\n", 1015 * @els_data: The ELS data to be sent
832 ep->f_ctl, sp->id);
833 return sp;
834}
835/*
836 * Allocate a new sequence on the same exchange as the supplied sequence.
837 * This will never return NULL.
838 */ 1016 */
839struct fc_seq *fc_seq_start_next(struct fc_seq *sp) 1017static void fc_seq_els_rsp_send(struct fc_seq *sp, enum fc_els_cmd els_cmd,
840{ 1018 struct fc_seq_els_data *els_data)
841 struct fc_exch *ep = fc_seq_exch(sp);
842
843 spin_lock_bh(&ep->ex_lock);
844 sp = fc_seq_start_next_locked(sp);
845 spin_unlock_bh(&ep->ex_lock);
846
847 return sp;
848}
849EXPORT_SYMBOL(fc_seq_start_next);
850
851int fc_seq_send(struct fc_lport *lp, struct fc_seq *sp, struct fc_frame *fp)
852{
853 struct fc_exch *ep;
854 struct fc_frame_header *fh = fc_frame_header_get(fp);
855 int error;
856 u32 f_ctl;
857
858 ep = fc_seq_exch(sp);
859 WARN_ON((ep->esb_stat & ESB_ST_SEQ_INIT) != ESB_ST_SEQ_INIT);
860
861 f_ctl = ntoh24(fh->fh_f_ctl);
862 fc_exch_setup_hdr(ep, fp, f_ctl);
863
864 /*
865 * update sequence count if this frame is carrying
866 * multiple FC frames when sequence offload is enabled
867 * by LLD.
868 */
869 if (fr_max_payload(fp))
870 sp->cnt += DIV_ROUND_UP((fr_len(fp) - sizeof(*fh)),
871 fr_max_payload(fp));
872 else
873 sp->cnt++;
874
875 /*
876 * Send the frame.
877 */
878 error = lp->tt.frame_send(lp, fp);
879
880 /*
881 * Update the exchange and sequence flags,
882 * assuming all frames for the sequence have been sent.
883 * We can only be called to send once for each sequence.
884 */
885 spin_lock_bh(&ep->ex_lock);
886 ep->f_ctl = f_ctl & ~FC_FC_FIRST_SEQ; /* not first seq */
887 if (f_ctl & (FC_FC_END_SEQ | FC_FC_SEQ_INIT))
888 ep->esb_stat &= ~ESB_ST_SEQ_INIT;
889 spin_unlock_bh(&ep->ex_lock);
890 return error;
891}
892EXPORT_SYMBOL(fc_seq_send);
893
894void fc_seq_els_rsp_send(struct fc_seq *sp, enum fc_els_cmd els_cmd,
895 struct fc_seq_els_data *els_data)
896{ 1019{
897 switch (els_cmd) { 1020 switch (els_cmd) {
898 case ELS_LS_RJT: 1021 case ELS_LS_RJT:
@@ -911,10 +1034,13 @@ void fc_seq_els_rsp_send(struct fc_seq *sp, enum fc_els_cmd els_cmd,
911 FC_EXCH_DBG(fc_seq_exch(sp), "Invalid ELS CMD:%x\n", els_cmd); 1034 FC_EXCH_DBG(fc_seq_exch(sp), "Invalid ELS CMD:%x\n", els_cmd);
912 } 1035 }
913} 1036}
914EXPORT_SYMBOL(fc_seq_els_rsp_send);
915 1037
916/* 1038/**
917 * Send a sequence, which is also the last sequence in the exchange. 1039 * fc_seq_send_last() - Send a sequence that is the last in the exchange
1040 * @sp: The sequence that is to be sent
1041 * @fp: The frame that will be sent on the sequence
1042 * @rctl: The R_CTL information to be sent
1043 * @fh_type: The frame header type
918 */ 1044 */
919static void fc_seq_send_last(struct fc_seq *sp, struct fc_frame *fp, 1045static void fc_seq_send_last(struct fc_seq *sp, struct fc_frame *fp,
920 enum fc_rctl rctl, enum fc_fh_type fh_type) 1046 enum fc_rctl rctl, enum fc_fh_type fh_type)
@@ -928,9 +1054,12 @@ static void fc_seq_send_last(struct fc_seq *sp, struct fc_frame *fp,
928 fc_seq_send(ep->lp, sp, fp); 1054 fc_seq_send(ep->lp, sp, fp);
929} 1055}
930 1056
931/* 1057/**
1058 * fc_seq_send_ack() - Send an acknowledgement that we've received a frame
1059 * @sp: The sequence to send the ACK on
1060 * @rx_fp: The received frame that is being acknoledged
1061 *
932 * Send ACK_1 (or equiv.) indicating we received something. 1062 * Send ACK_1 (or equiv.) indicating we received something.
933 * The frame we're acking is supplied.
934 */ 1063 */
935static void fc_seq_send_ack(struct fc_seq *sp, const struct fc_frame *rx_fp) 1064static void fc_seq_send_ack(struct fc_seq *sp, const struct fc_frame *rx_fp)
936{ 1065{
@@ -938,14 +1067,14 @@ static void fc_seq_send_ack(struct fc_seq *sp, const struct fc_frame *rx_fp)
938 struct fc_frame_header *rx_fh; 1067 struct fc_frame_header *rx_fh;
939 struct fc_frame_header *fh; 1068 struct fc_frame_header *fh;
940 struct fc_exch *ep = fc_seq_exch(sp); 1069 struct fc_exch *ep = fc_seq_exch(sp);
941 struct fc_lport *lp = ep->lp; 1070 struct fc_lport *lport = ep->lp;
942 unsigned int f_ctl; 1071 unsigned int f_ctl;
943 1072
944 /* 1073 /*
945 * Don't send ACKs for class 3. 1074 * Don't send ACKs for class 3.
946 */ 1075 */
947 if (fc_sof_needs_ack(fr_sof(rx_fp))) { 1076 if (fc_sof_needs_ack(fr_sof(rx_fp))) {
948 fp = fc_frame_alloc(lp, 0); 1077 fp = fc_frame_alloc(lport, 0);
949 if (!fp) 1078 if (!fp)
950 return; 1079 return;
951 1080
@@ -980,12 +1109,16 @@ static void fc_seq_send_ack(struct fc_seq *sp, const struct fc_frame *rx_fp)
980 else 1109 else
981 fr_eof(fp) = FC_EOF_N; 1110 fr_eof(fp) = FC_EOF_N;
982 1111
983 (void) lp->tt.frame_send(lp, fp); 1112 lport->tt.frame_send(lport, fp);
984 } 1113 }
985} 1114}
986 1115
987/* 1116/**
988 * Send BLS Reject. 1117 * fc_exch_send_ba_rjt() - Send BLS Reject
1118 * @rx_fp: The frame being rejected
1119 * @reason: The reason the frame is being rejected
1120 * @explan: The explaination for the rejection
1121 *
989 * This is for rejecting BA_ABTS only. 1122 * This is for rejecting BA_ABTS only.
990 */ 1123 */
991static void fc_exch_send_ba_rjt(struct fc_frame *rx_fp, 1124static void fc_exch_send_ba_rjt(struct fc_frame *rx_fp,
@@ -996,11 +1129,11 @@ static void fc_exch_send_ba_rjt(struct fc_frame *rx_fp,
996 struct fc_frame_header *rx_fh; 1129 struct fc_frame_header *rx_fh;
997 struct fc_frame_header *fh; 1130 struct fc_frame_header *fh;
998 struct fc_ba_rjt *rp; 1131 struct fc_ba_rjt *rp;
999 struct fc_lport *lp; 1132 struct fc_lport *lport;
1000 unsigned int f_ctl; 1133 unsigned int f_ctl;
1001 1134
1002 lp = fr_dev(rx_fp); 1135 lport = fr_dev(rx_fp);
1003 fp = fc_frame_alloc(lp, sizeof(*rp)); 1136 fp = fc_frame_alloc(lport, sizeof(*rp));
1004 if (!fp) 1137 if (!fp)
1005 return; 1138 return;
1006 fh = fc_frame_header_get(fp); 1139 fh = fc_frame_header_get(fp);
@@ -1045,13 +1178,17 @@ static void fc_exch_send_ba_rjt(struct fc_frame *rx_fp,
1045 if (fc_sof_needs_ack(fr_sof(fp))) 1178 if (fc_sof_needs_ack(fr_sof(fp)))
1046 fr_eof(fp) = FC_EOF_N; 1179 fr_eof(fp) = FC_EOF_N;
1047 1180
1048 (void) lp->tt.frame_send(lp, fp); 1181 lport->tt.frame_send(lport, fp);
1049} 1182}
1050 1183
1051/* 1184/**
1052 * Handle an incoming ABTS. This would be for target mode usually, 1185 * fc_exch_recv_abts() - Handle an incoming ABTS
1053 * but could be due to lost FCP transfer ready, confirm or RRQ. 1186 * @ep: The exchange the abort was on
1054 * We always handle this as an exchange abort, ignoring the parameter. 1187 * @rx_fp: The ABTS frame
1188 *
1189 * This would be for target mode usually, but could be due to lost
1190 * FCP transfer ready, confirm or RRQ. We always handle this as an
1191 * exchange abort, ignoring the parameter.
1055 */ 1192 */
1056static void fc_exch_recv_abts(struct fc_exch *ep, struct fc_frame *rx_fp) 1193static void fc_exch_recv_abts(struct fc_exch *ep, struct fc_frame *rx_fp)
1057{ 1194{
@@ -1100,10 +1237,14 @@ free:
1100 fc_frame_free(rx_fp); 1237 fc_frame_free(rx_fp);
1101} 1238}
1102 1239
1103/* 1240/**
1104 * Handle receive where the other end is originating the sequence. 1241 * fc_exch_recv_req() - Handler for an incoming request where is other
1242 * end is originating the sequence
1243 * @lport: The local port that received the request
1244 * @mp: The EM that the exchange is on
1245 * @fp: The request frame
1105 */ 1246 */
1106static void fc_exch_recv_req(struct fc_lport *lp, struct fc_exch_mgr *mp, 1247static void fc_exch_recv_req(struct fc_lport *lport, struct fc_exch_mgr *mp,
1107 struct fc_frame *fp) 1248 struct fc_frame *fp)
1108{ 1249{
1109 struct fc_frame_header *fh = fc_frame_header_get(fp); 1250 struct fc_frame_header *fh = fc_frame_header_get(fp);
@@ -1114,8 +1255,17 @@ static void fc_exch_recv_req(struct fc_lport *lp, struct fc_exch_mgr *mp,
1114 u32 f_ctl; 1255 u32 f_ctl;
1115 enum fc_pf_rjt_reason reject; 1256 enum fc_pf_rjt_reason reject;
1116 1257
1258 /* We can have the wrong fc_lport at this point with NPIV, which is a
1259 * problem now that we know a new exchange needs to be allocated
1260 */
1261 lport = fc_vport_id_lookup(lport, ntoh24(fh->fh_d_id));
1262 if (!lport) {
1263 fc_frame_free(fp);
1264 return;
1265 }
1266
1117 fr_seq(fp) = NULL; 1267 fr_seq(fp) = NULL;
1118 reject = fc_seq_lookup_recip(lp, mp, fp); 1268 reject = fc_seq_lookup_recip(lport, mp, fp);
1119 if (reject == FC_RJT_NONE) { 1269 if (reject == FC_RJT_NONE) {
1120 sp = fr_seq(fp); /* sequence will be held */ 1270 sp = fr_seq(fp); /* sequence will be held */
1121 ep = fc_seq_exch(sp); 1271 ep = fc_seq_exch(sp);
@@ -1138,17 +1288,21 @@ static void fc_exch_recv_req(struct fc_lport *lp, struct fc_exch_mgr *mp,
1138 if (ep->resp) 1288 if (ep->resp)
1139 ep->resp(sp, fp, ep->arg); 1289 ep->resp(sp, fp, ep->arg);
1140 else 1290 else
1141 lp->tt.lport_recv(lp, sp, fp); 1291 lport->tt.lport_recv(lport, sp, fp);
1142 fc_exch_release(ep); /* release from lookup */ 1292 fc_exch_release(ep); /* release from lookup */
1143 } else { 1293 } else {
1144 FC_LPORT_DBG(lp, "exch/seq lookup failed: reject %x\n", reject); 1294 FC_LPORT_DBG(lport, "exch/seq lookup failed: reject %x\n",
1295 reject);
1145 fc_frame_free(fp); 1296 fc_frame_free(fp);
1146 } 1297 }
1147} 1298}
1148 1299
1149/* 1300/**
1150 * Handle receive where the other end is originating the sequence in 1301 * fc_exch_recv_seq_resp() - Handler for an incoming response where the other
1151 * response to our exchange. 1302 * end is the originator of the sequence that is a
1303 * response to our initial exchange
1304 * @mp: The EM that the exchange is on
1305 * @fp: The response frame
1152 */ 1306 */
1153static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp) 1307static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
1154{ 1308{
@@ -1239,8 +1393,11 @@ out:
1239 fc_frame_free(fp); 1393 fc_frame_free(fp);
1240} 1394}
1241 1395
1242/* 1396/**
1243 * Handle receive for a sequence where other end is responding to our sequence. 1397 * fc_exch_recv_resp() - Handler for a sequence where other end is
1398 * responding to our sequence
1399 * @mp: The EM that the exchange is on
1400 * @fp: The response frame
1244 */ 1401 */
1245static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp) 1402static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
1246{ 1403{
@@ -1256,9 +1413,13 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
1256 fc_frame_free(fp); 1413 fc_frame_free(fp);
1257} 1414}
1258 1415
1259/* 1416/**
1260 * Handle the response to an ABTS for exchange or sequence. 1417 * fc_exch_abts_resp() - Handler for a response to an ABT
1261 * This can be BA_ACC or BA_RJT. 1418 * @ep: The exchange that the frame is on
1419 * @fp: The response frame
1420 *
1421 * This response would be to an ABTS cancelling an exchange or sequence.
1422 * The response can be either BA_ACC or BA_RJT
1262 */ 1423 */
1263static void fc_exch_abts_resp(struct fc_exch *ep, struct fc_frame *fp) 1424static void fc_exch_abts_resp(struct fc_exch *ep, struct fc_frame *fp)
1264{ 1425{
@@ -1333,9 +1494,12 @@ static void fc_exch_abts_resp(struct fc_exch *ep, struct fc_frame *fp)
1333 1494
1334} 1495}
1335 1496
1336/* 1497/**
1337 * Receive BLS sequence. 1498 * fc_exch_recv_bls() - Handler for a BLS sequence
1338 * This is always a sequence initiated by the remote side. 1499 * @mp: The EM that the exchange is on
1500 * @fp: The request frame
1501 *
1502 * The BLS frame is always a sequence initiated by the remote side.
1339 * We may be either the originator or recipient of the exchange. 1503 * We may be either the originator or recipient of the exchange.
1340 */ 1504 */
1341static void fc_exch_recv_bls(struct fc_exch_mgr *mp, struct fc_frame *fp) 1505static void fc_exch_recv_bls(struct fc_exch_mgr *mp, struct fc_frame *fp)
@@ -1392,8 +1556,10 @@ static void fc_exch_recv_bls(struct fc_exch_mgr *mp, struct fc_frame *fp)
1392 fc_exch_release(ep); /* release hold taken by fc_exch_find */ 1556 fc_exch_release(ep); /* release hold taken by fc_exch_find */
1393} 1557}
1394 1558
1395/* 1559/**
1396 * Accept sequence with LS_ACC. 1560 * fc_seq_ls_acc() - Accept sequence with LS_ACC
1561 * @req_sp: The request sequence
1562 *
1397 * If this fails due to allocation or transmit congestion, assume the 1563 * If this fails due to allocation or transmit congestion, assume the
1398 * originator will repeat the sequence. 1564 * originator will repeat the sequence.
1399 */ 1565 */
@@ -1413,8 +1579,12 @@ static void fc_seq_ls_acc(struct fc_seq *req_sp)
1413 } 1579 }
1414} 1580}
1415 1581
1416/* 1582/**
1417 * Reject sequence with ELS LS_RJT. 1583 * fc_seq_ls_rjt() - Reject a sequence with ELS LS_RJT
1584 * @req_sp: The request sequence
1585 * @reason: The reason the sequence is being rejected
1586 * @explan: The explaination for the rejection
1587 *
1418 * If this fails due to allocation or transmit congestion, assume the 1588 * If this fails due to allocation or transmit congestion, assume the
1419 * originator will repeat the sequence. 1589 * originator will repeat the sequence.
1420 */ 1590 */
@@ -1437,6 +1607,10 @@ static void fc_seq_ls_rjt(struct fc_seq *req_sp, enum fc_els_rjt_reason reason,
1437 } 1607 }
1438} 1608}
1439 1609
1610/**
1611 * fc_exch_reset() - Reset an exchange
1612 * @ep: The exchange to be reset
1613 */
1440static void fc_exch_reset(struct fc_exch *ep) 1614static void fc_exch_reset(struct fc_exch *ep)
1441{ 1615{
1442 struct fc_seq *sp; 1616 struct fc_seq *sp;
@@ -1446,12 +1620,6 @@ static void fc_exch_reset(struct fc_exch *ep)
1446 1620
1447 spin_lock_bh(&ep->ex_lock); 1621 spin_lock_bh(&ep->ex_lock);
1448 ep->state |= FC_EX_RST_CLEANUP; 1622 ep->state |= FC_EX_RST_CLEANUP;
1449 /*
1450 * we really want to call del_timer_sync, but cannot due
1451 * to the lport calling with the lport lock held (some resp
1452 * functions can also grab the lport lock which could cause
1453 * a deadlock).
1454 */
1455 if (cancel_delayed_work(&ep->timeout_work)) 1623 if (cancel_delayed_work(&ep->timeout_work))
1456 atomic_dec(&ep->ex_refcnt); /* drop hold for timer */ 1624 atomic_dec(&ep->ex_refcnt); /* drop hold for timer */
1457 resp = ep->resp; 1625 resp = ep->resp;
@@ -1471,16 +1639,16 @@ static void fc_exch_reset(struct fc_exch *ep)
1471} 1639}
1472 1640
1473/** 1641/**
1474 * fc_exch_pool_reset() - Resets an per cpu exches pool. 1642 * fc_exch_pool_reset() - Reset a per cpu exchange pool
1475 * @lport: ptr to the local port 1643 * @lport: The local port that the exchange pool is on
1476 * @pool: ptr to the per cpu exches pool 1644 * @pool: The exchange pool to be reset
1477 * @sid: source FC ID 1645 * @sid: The source ID
1478 * @did: destination FC ID 1646 * @did: The destination ID
1479 * 1647 *
1480 * Resets an per cpu exches pool, releasing its all sequences 1648 * Resets a per cpu exches pool, releasing all of its sequences
1481 * and exchanges. If sid is non-zero, then reset only exchanges 1649 * and exchanges. If sid is non-zero then reset only exchanges
1482 * we sourced from that FID. If did is non-zero, reset only 1650 * we sourced from the local port's FID. If did is non-zero then
1483 * exchanges destined to that FID. 1651 * only reset exchanges destined for the local port's FID.
1484 */ 1652 */
1485static void fc_exch_pool_reset(struct fc_lport *lport, 1653static void fc_exch_pool_reset(struct fc_lport *lport,
1486 struct fc_exch_pool *pool, 1654 struct fc_exch_pool *pool,
@@ -1514,15 +1682,15 @@ restart:
1514} 1682}
1515 1683
1516/** 1684/**
1517 * fc_exch_mgr_reset() - Resets all EMs of a lport 1685 * fc_exch_mgr_reset() - Reset all EMs of a local port
1518 * @lport: ptr to the local port 1686 * @lport: The local port whose EMs are to be reset
1519 * @sid: source FC ID 1687 * @sid: The source ID
1520 * @did: destination FC ID 1688 * @did: The destination ID
1521 * 1689 *
1522 * Reset all EMs of a lport, releasing its all sequences and 1690 * Reset all EMs associated with a given local port. Release all
1523 * exchanges. If sid is non-zero, then reset only exchanges 1691 * sequences and exchanges. If sid is non-zero then reset only the
1524 * we sourced from that FID. If did is non-zero, reset only 1692 * exchanges sent from the local port's FID. If did is non-zero then
1525 * exchanges destined to that FID. 1693 * reset only exchanges destined for the local port's FID.
1526 */ 1694 */
1527void fc_exch_mgr_reset(struct fc_lport *lport, u32 sid, u32 did) 1695void fc_exch_mgr_reset(struct fc_lport *lport, u32 sid, u32 did)
1528{ 1696{
@@ -1538,8 +1706,11 @@ void fc_exch_mgr_reset(struct fc_lport *lport, u32 sid, u32 did)
1538} 1706}
1539EXPORT_SYMBOL(fc_exch_mgr_reset); 1707EXPORT_SYMBOL(fc_exch_mgr_reset);
1540 1708
1541/* 1709/**
1542 * Handle incoming ELS REC - Read Exchange Concise. 1710 * fc_exch_els_rec() - Handler for ELS REC (Read Exchange Concise) requests
1711 * @sp: The sequence the REC is on
1712 * @rfp: The REC frame
1713 *
1543 * Note that the requesting port may be different than the S_ID in the request. 1714 * Note that the requesting port may be different than the S_ID in the request.
1544 */ 1715 */
1545static void fc_exch_els_rec(struct fc_seq *sp, struct fc_frame *rfp) 1716static void fc_exch_els_rec(struct fc_seq *sp, struct fc_frame *rfp)
@@ -1621,10 +1792,11 @@ reject:
1621 fc_frame_free(rfp); 1792 fc_frame_free(rfp);
1622} 1793}
1623 1794
1624/* 1795/**
1625 * Handle response from RRQ. 1796 * fc_exch_rrq_resp() - Handler for RRQ responses
1626 * Not much to do here, really. 1797 * @sp: The sequence that the RRQ is on
1627 * Should report errors. 1798 * @fp: The RRQ frame
1799 * @arg: The exchange that the RRQ is on
1628 * 1800 *
1629 * TODO: fix error handler. 1801 * TODO: fix error handler.
1630 */ 1802 */
@@ -1664,21 +1836,99 @@ cleanup:
1664 fc_exch_release(aborted_ep); 1836 fc_exch_release(aborted_ep);
1665} 1837}
1666 1838
1667/* 1839
1668 * Send ELS RRQ - Reinstate Recovery Qualifier. 1840/**
1841 * fc_exch_seq_send() - Send a frame using a new exchange and sequence
1842 * @lport: The local port to send the frame on
1843 * @fp: The frame to be sent
1844 * @resp: The response handler for this request
1845 * @destructor: The destructor for the exchange
1846 * @arg: The argument to be passed to the response handler
1847 * @timer_msec: The timeout period for the exchange
1848 *
1849 * The frame pointer with some of the header's fields must be
1850 * filled before calling this routine, those fields are:
1851 *
1852 * - routing control
1853 * - FC port did
1854 * - FC port sid
1855 * - FC header type
1856 * - frame control
1857 * - parameter or relative offset
1858 */
1859static struct fc_seq *fc_exch_seq_send(struct fc_lport *lport,
1860 struct fc_frame *fp,
1861 void (*resp)(struct fc_seq *,
1862 struct fc_frame *fp,
1863 void *arg),
1864 void (*destructor)(struct fc_seq *,
1865 void *),
1866 void *arg, u32 timer_msec)
1867{
1868 struct fc_exch *ep;
1869 struct fc_seq *sp = NULL;
1870 struct fc_frame_header *fh;
1871 int rc = 1;
1872
1873 ep = fc_exch_alloc(lport, fp);
1874 if (!ep) {
1875 fc_frame_free(fp);
1876 return NULL;
1877 }
1878 ep->esb_stat |= ESB_ST_SEQ_INIT;
1879 fh = fc_frame_header_get(fp);
1880 fc_exch_set_addr(ep, ntoh24(fh->fh_s_id), ntoh24(fh->fh_d_id));
1881 ep->resp = resp;
1882 ep->destructor = destructor;
1883 ep->arg = arg;
1884 ep->r_a_tov = FC_DEF_R_A_TOV;
1885 ep->lp = lport;
1886 sp = &ep->seq;
1887
1888 ep->fh_type = fh->fh_type; /* save for possbile timeout handling */
1889 ep->f_ctl = ntoh24(fh->fh_f_ctl);
1890 fc_exch_setup_hdr(ep, fp, ep->f_ctl);
1891 sp->cnt++;
1892
1893 if (ep->xid <= lport->lro_xid && fh->fh_r_ctl == FC_RCTL_DD_UNSOL_CMD)
1894 fc_fcp_ddp_setup(fr_fsp(fp), ep->xid);
1895
1896 if (unlikely(lport->tt.frame_send(lport, fp)))
1897 goto err;
1898
1899 if (timer_msec)
1900 fc_exch_timer_set_locked(ep, timer_msec);
1901 ep->f_ctl &= ~FC_FC_FIRST_SEQ; /* not first seq */
1902
1903 if (ep->f_ctl & FC_FC_SEQ_INIT)
1904 ep->esb_stat &= ~ESB_ST_SEQ_INIT;
1905 spin_unlock_bh(&ep->ex_lock);
1906 return sp;
1907err:
1908 rc = fc_exch_done_locked(ep);
1909 spin_unlock_bh(&ep->ex_lock);
1910 if (!rc)
1911 fc_exch_delete(ep);
1912 return NULL;
1913}
1914
1915/**
1916 * fc_exch_rrq() - Send an ELS RRQ (Reinstate Recovery Qualifier) command
1917 * @ep: The exchange to send the RRQ on
1918 *
1669 * This tells the remote port to stop blocking the use of 1919 * This tells the remote port to stop blocking the use of
1670 * the exchange and the seq_cnt range. 1920 * the exchange and the seq_cnt range.
1671 */ 1921 */
1672static void fc_exch_rrq(struct fc_exch *ep) 1922static void fc_exch_rrq(struct fc_exch *ep)
1673{ 1923{
1674 struct fc_lport *lp; 1924 struct fc_lport *lport;
1675 struct fc_els_rrq *rrq; 1925 struct fc_els_rrq *rrq;
1676 struct fc_frame *fp; 1926 struct fc_frame *fp;
1677 u32 did; 1927 u32 did;
1678 1928
1679 lp = ep->lp; 1929 lport = ep->lp;
1680 1930
1681 fp = fc_frame_alloc(lp, sizeof(*rrq)); 1931 fp = fc_frame_alloc(lport, sizeof(*rrq));
1682 if (!fp) 1932 if (!fp)
1683 goto retry; 1933 goto retry;
1684 1934
@@ -1694,10 +1944,11 @@ static void fc_exch_rrq(struct fc_exch *ep)
1694 did = ep->sid; 1944 did = ep->sid;
1695 1945
1696 fc_fill_fc_hdr(fp, FC_RCTL_ELS_REQ, did, 1946 fc_fill_fc_hdr(fp, FC_RCTL_ELS_REQ, did,
1697 fc_host_port_id(lp->host), FC_TYPE_ELS, 1947 fc_host_port_id(lport->host), FC_TYPE_ELS,
1698 FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0); 1948 FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0);
1699 1949
1700 if (fc_exch_seq_send(lp, fp, fc_exch_rrq_resp, NULL, ep, lp->e_d_tov)) 1950 if (fc_exch_seq_send(lport, fp, fc_exch_rrq_resp, NULL, ep,
1951 lport->e_d_tov))
1701 return; 1952 return;
1702 1953
1703retry: 1954retry:
@@ -1714,12 +1965,14 @@ retry:
1714} 1965}
1715 1966
1716 1967
1717/* 1968/**
1718 * Handle incoming ELS RRQ - Reset Recovery Qualifier. 1969 * fc_exch_els_rrq() - Handler for ELS RRQ (Reset Recovery Qualifier) requests
1970 * @sp: The sequence that the RRQ is on
1971 * @fp: The RRQ frame
1719 */ 1972 */
1720static void fc_exch_els_rrq(struct fc_seq *sp, struct fc_frame *fp) 1973static void fc_exch_els_rrq(struct fc_seq *sp, struct fc_frame *fp)
1721{ 1974{
1722 struct fc_exch *ep; /* request or subject exchange */ 1975 struct fc_exch *ep = NULL; /* request or subject exchange */
1723 struct fc_els_rrq *rp; 1976 struct fc_els_rrq *rp;
1724 u32 sid; 1977 u32 sid;
1725 u16 xid; 1978 u16 xid;
@@ -1769,17 +2022,24 @@ static void fc_exch_els_rrq(struct fc_seq *sp, struct fc_frame *fp)
1769 * Send LS_ACC. 2022 * Send LS_ACC.
1770 */ 2023 */
1771 fc_seq_ls_acc(sp); 2024 fc_seq_ls_acc(sp);
1772 fc_frame_free(fp); 2025 goto out;
1773 return;
1774 2026
1775unlock_reject: 2027unlock_reject:
1776 spin_unlock_bh(&ep->ex_lock); 2028 spin_unlock_bh(&ep->ex_lock);
1777 fc_exch_release(ep); /* drop hold from fc_exch_find */
1778reject: 2029reject:
1779 fc_seq_ls_rjt(sp, ELS_RJT_LOGIC, explan); 2030 fc_seq_ls_rjt(sp, ELS_RJT_LOGIC, explan);
2031out:
1780 fc_frame_free(fp); 2032 fc_frame_free(fp);
2033 if (ep)
2034 fc_exch_release(ep); /* drop hold from fc_exch_find */
1781} 2035}
1782 2036
2037/**
2038 * fc_exch_mgr_add() - Add an exchange manager to a local port's list of EMs
2039 * @lport: The local port to add the exchange manager to
2040 * @mp: The exchange manager to be added to the local port
2041 * @match: The match routine that indicates when this EM should be used
2042 */
1783struct fc_exch_mgr_anchor *fc_exch_mgr_add(struct fc_lport *lport, 2043struct fc_exch_mgr_anchor *fc_exch_mgr_add(struct fc_lport *lport,
1784 struct fc_exch_mgr *mp, 2044 struct fc_exch_mgr *mp,
1785 bool (*match)(struct fc_frame *)) 2045 bool (*match)(struct fc_frame *))
@@ -1799,6 +2059,10 @@ struct fc_exch_mgr_anchor *fc_exch_mgr_add(struct fc_lport *lport,
1799} 2059}
1800EXPORT_SYMBOL(fc_exch_mgr_add); 2060EXPORT_SYMBOL(fc_exch_mgr_add);
1801 2061
2062/**
2063 * fc_exch_mgr_destroy() - Destroy an exchange manager
2064 * @kref: The reference to the EM to be destroyed
2065 */
1802static void fc_exch_mgr_destroy(struct kref *kref) 2066static void fc_exch_mgr_destroy(struct kref *kref)
1803{ 2067{
1804 struct fc_exch_mgr *mp = container_of(kref, struct fc_exch_mgr, kref); 2068 struct fc_exch_mgr *mp = container_of(kref, struct fc_exch_mgr, kref);
@@ -1808,6 +2072,10 @@ static void fc_exch_mgr_destroy(struct kref *kref)
1808 kfree(mp); 2072 kfree(mp);
1809} 2073}
1810 2074
2075/**
2076 * fc_exch_mgr_del() - Delete an EM from a local port's list
2077 * @ema: The exchange manager anchor identifying the EM to be deleted
2078 */
1811void fc_exch_mgr_del(struct fc_exch_mgr_anchor *ema) 2079void fc_exch_mgr_del(struct fc_exch_mgr_anchor *ema)
1812{ 2080{
1813 /* remove EM anchor from EM anchors list */ 2081 /* remove EM anchor from EM anchors list */
@@ -1817,7 +2085,35 @@ void fc_exch_mgr_del(struct fc_exch_mgr_anchor *ema)
1817} 2085}
1818EXPORT_SYMBOL(fc_exch_mgr_del); 2086EXPORT_SYMBOL(fc_exch_mgr_del);
1819 2087
1820struct fc_exch_mgr *fc_exch_mgr_alloc(struct fc_lport *lp, 2088/**
2089 * fc_exch_mgr_list_clone() - Share all exchange manager objects
2090 * @src: Source lport to clone exchange managers from
2091 * @dst: New lport that takes references to all the exchange managers
2092 */
2093int fc_exch_mgr_list_clone(struct fc_lport *src, struct fc_lport *dst)
2094{
2095 struct fc_exch_mgr_anchor *ema, *tmp;
2096
2097 list_for_each_entry(ema, &src->ema_list, ema_list) {
2098 if (!fc_exch_mgr_add(dst, ema->mp, ema->match))
2099 goto err;
2100 }
2101 return 0;
2102err:
2103 list_for_each_entry_safe(ema, tmp, &dst->ema_list, ema_list)
2104 fc_exch_mgr_del(ema);
2105 return -ENOMEM;
2106}
2107
2108/**
2109 * fc_exch_mgr_alloc() - Allocate an exchange manager
2110 * @lport: The local port that the new EM will be associated with
2111 * @class: The default FC class for new exchanges
2112 * @min_xid: The minimum XID for exchanges from the new EM
2113 * @max_xid: The maximum XID for exchanges from the new EM
2114 * @match: The match routine for the new EM
2115 */
2116struct fc_exch_mgr *fc_exch_mgr_alloc(struct fc_lport *lport,
1821 enum fc_class class, 2117 enum fc_class class,
1822 u16 min_xid, u16 max_xid, 2118 u16 min_xid, u16 max_xid,
1823 bool (*match)(struct fc_frame *)) 2119 bool (*match)(struct fc_frame *))
@@ -1830,7 +2126,7 @@ struct fc_exch_mgr *fc_exch_mgr_alloc(struct fc_lport *lp,
1830 2126
1831 if (max_xid <= min_xid || max_xid == FC_XID_UNKNOWN || 2127 if (max_xid <= min_xid || max_xid == FC_XID_UNKNOWN ||
1832 (min_xid & fc_cpu_mask) != 0) { 2128 (min_xid & fc_cpu_mask) != 0) {
1833 FC_LPORT_DBG(lp, "Invalid min_xid 0x:%x and max_xid 0x:%x\n", 2129 FC_LPORT_DBG(lport, "Invalid min_xid 0x:%x and max_xid 0x:%x\n",
1834 min_xid, max_xid); 2130 min_xid, max_xid);
1835 return NULL; 2131 return NULL;
1836 } 2132 }
@@ -1873,7 +2169,7 @@ struct fc_exch_mgr *fc_exch_mgr_alloc(struct fc_lport *lp,
1873 } 2169 }
1874 2170
1875 kref_init(&mp->kref); 2171 kref_init(&mp->kref);
1876 if (!fc_exch_mgr_add(lp, mp, match)) { 2172 if (!fc_exch_mgr_add(lport, mp, match)) {
1877 free_percpu(mp->pool); 2173 free_percpu(mp->pool);
1878 goto free_mempool; 2174 goto free_mempool;
1879 } 2175 }
@@ -1894,76 +2190,26 @@ free_mp:
1894} 2190}
1895EXPORT_SYMBOL(fc_exch_mgr_alloc); 2191EXPORT_SYMBOL(fc_exch_mgr_alloc);
1896 2192
2193/**
2194 * fc_exch_mgr_free() - Free all exchange managers on a local port
2195 * @lport: The local port whose EMs are to be freed
2196 */
1897void fc_exch_mgr_free(struct fc_lport *lport) 2197void fc_exch_mgr_free(struct fc_lport *lport)
1898{ 2198{
1899 struct fc_exch_mgr_anchor *ema, *next; 2199 struct fc_exch_mgr_anchor *ema, *next;
1900 2200
2201 flush_workqueue(fc_exch_workqueue);
1901 list_for_each_entry_safe(ema, next, &lport->ema_list, ema_list) 2202 list_for_each_entry_safe(ema, next, &lport->ema_list, ema_list)
1902 fc_exch_mgr_del(ema); 2203 fc_exch_mgr_del(ema);
1903} 2204}
1904EXPORT_SYMBOL(fc_exch_mgr_free); 2205EXPORT_SYMBOL(fc_exch_mgr_free);
1905 2206
1906 2207/**
1907struct fc_seq *fc_exch_seq_send(struct fc_lport *lp, 2208 * fc_exch_recv() - Handler for received frames
1908 struct fc_frame *fp, 2209 * @lport: The local port the frame was received on
1909 void (*resp)(struct fc_seq *, 2210 * @fp: The received frame
1910 struct fc_frame *fp,
1911 void *arg),
1912 void (*destructor)(struct fc_seq *, void *),
1913 void *arg, u32 timer_msec)
1914{
1915 struct fc_exch *ep;
1916 struct fc_seq *sp = NULL;
1917 struct fc_frame_header *fh;
1918 int rc = 1;
1919
1920 ep = fc_exch_alloc(lp, fp);
1921 if (!ep) {
1922 fc_frame_free(fp);
1923 return NULL;
1924 }
1925 ep->esb_stat |= ESB_ST_SEQ_INIT;
1926 fh = fc_frame_header_get(fp);
1927 fc_exch_set_addr(ep, ntoh24(fh->fh_s_id), ntoh24(fh->fh_d_id));
1928 ep->resp = resp;
1929 ep->destructor = destructor;
1930 ep->arg = arg;
1931 ep->r_a_tov = FC_DEF_R_A_TOV;
1932 ep->lp = lp;
1933 sp = &ep->seq;
1934
1935 ep->fh_type = fh->fh_type; /* save for possbile timeout handling */
1936 ep->f_ctl = ntoh24(fh->fh_f_ctl);
1937 fc_exch_setup_hdr(ep, fp, ep->f_ctl);
1938 sp->cnt++;
1939
1940 if (ep->xid <= lp->lro_xid)
1941 fc_fcp_ddp_setup(fr_fsp(fp), ep->xid);
1942
1943 if (unlikely(lp->tt.frame_send(lp, fp)))
1944 goto err;
1945
1946 if (timer_msec)
1947 fc_exch_timer_set_locked(ep, timer_msec);
1948 ep->f_ctl &= ~FC_FC_FIRST_SEQ; /* not first seq */
1949
1950 if (ep->f_ctl & FC_FC_SEQ_INIT)
1951 ep->esb_stat &= ~ESB_ST_SEQ_INIT;
1952 spin_unlock_bh(&ep->ex_lock);
1953 return sp;
1954err:
1955 rc = fc_exch_done_locked(ep);
1956 spin_unlock_bh(&ep->ex_lock);
1957 if (!rc)
1958 fc_exch_delete(ep);
1959 return NULL;
1960}
1961EXPORT_SYMBOL(fc_exch_seq_send);
1962
1963/*
1964 * Receive a frame
1965 */ 2211 */
1966void fc_exch_recv(struct fc_lport *lp, struct fc_frame *fp) 2212void fc_exch_recv(struct fc_lport *lport, struct fc_frame *fp)
1967{ 2213{
1968 struct fc_frame_header *fh = fc_frame_header_get(fp); 2214 struct fc_frame_header *fh = fc_frame_header_get(fp);
1969 struct fc_exch_mgr_anchor *ema; 2215 struct fc_exch_mgr_anchor *ema;
@@ -1971,8 +2217,8 @@ void fc_exch_recv(struct fc_lport *lp, struct fc_frame *fp)
1971 u16 oxid; 2217 u16 oxid;
1972 2218
1973 /* lport lock ? */ 2219 /* lport lock ? */
1974 if (!lp || lp->state == LPORT_ST_DISABLED) { 2220 if (!lport || lport->state == LPORT_ST_DISABLED) {
1975 FC_LPORT_DBG(lp, "Receiving frames for an lport that " 2221 FC_LPORT_DBG(lport, "Receiving frames for an lport that "
1976 "has not been initialized correctly\n"); 2222 "has not been initialized correctly\n");
1977 fc_frame_free(fp); 2223 fc_frame_free(fp);
1978 return; 2224 return;
@@ -1981,7 +2227,7 @@ void fc_exch_recv(struct fc_lport *lp, struct fc_frame *fp)
1981 f_ctl = ntoh24(fh->fh_f_ctl); 2227 f_ctl = ntoh24(fh->fh_f_ctl);
1982 oxid = ntohs(fh->fh_ox_id); 2228 oxid = ntohs(fh->fh_ox_id);
1983 if (f_ctl & FC_FC_EX_CTX) { 2229 if (f_ctl & FC_FC_EX_CTX) {
1984 list_for_each_entry(ema, &lp->ema_list, ema_list) { 2230 list_for_each_entry(ema, &lport->ema_list, ema_list) {
1985 if ((oxid >= ema->mp->min_xid) && 2231 if ((oxid >= ema->mp->min_xid) &&
1986 (oxid <= ema->mp->max_xid)) { 2232 (oxid <= ema->mp->max_xid)) {
1987 found = 1; 2233 found = 1;
@@ -1990,13 +2236,13 @@ void fc_exch_recv(struct fc_lport *lp, struct fc_frame *fp)
1990 } 2236 }
1991 2237
1992 if (!found) { 2238 if (!found) {
1993 FC_LPORT_DBG(lp, "Received response for out " 2239 FC_LPORT_DBG(lport, "Received response for out "
1994 "of range oxid:%hx\n", oxid); 2240 "of range oxid:%hx\n", oxid);
1995 fc_frame_free(fp); 2241 fc_frame_free(fp);
1996 return; 2242 return;
1997 } 2243 }
1998 } else 2244 } else
1999 ema = list_entry(lp->ema_list.prev, typeof(*ema), ema_list); 2245 ema = list_entry(lport->ema_list.prev, typeof(*ema), ema_list);
2000 2246
2001 /* 2247 /*
2002 * If frame is marked invalid, just drop it. 2248 * If frame is marked invalid, just drop it.
@@ -2015,37 +2261,56 @@ void fc_exch_recv(struct fc_lport *lp, struct fc_frame *fp)
2015 else if (f_ctl & FC_FC_SEQ_CTX) 2261 else if (f_ctl & FC_FC_SEQ_CTX)
2016 fc_exch_recv_resp(ema->mp, fp); 2262 fc_exch_recv_resp(ema->mp, fp);
2017 else 2263 else
2018 fc_exch_recv_req(lp, ema->mp, fp); 2264 fc_exch_recv_req(lport, ema->mp, fp);
2019 break; 2265 break;
2020 default: 2266 default:
2021 FC_LPORT_DBG(lp, "dropping invalid frame (eof %x)", fr_eof(fp)); 2267 FC_LPORT_DBG(lport, "dropping invalid frame (eof %x)",
2268 fr_eof(fp));
2022 fc_frame_free(fp); 2269 fc_frame_free(fp);
2023 } 2270 }
2024} 2271}
2025EXPORT_SYMBOL(fc_exch_recv); 2272EXPORT_SYMBOL(fc_exch_recv);
2026 2273
2027int fc_exch_init(struct fc_lport *lp) 2274/**
2275 * fc_exch_init() - Initialize the exchange layer for a local port
2276 * @lport: The local port to initialize the exchange layer for
2277 */
2278int fc_exch_init(struct fc_lport *lport)
2028{ 2279{
2029 if (!lp->tt.seq_start_next) 2280 if (!lport->tt.seq_start_next)
2030 lp->tt.seq_start_next = fc_seq_start_next; 2281 lport->tt.seq_start_next = fc_seq_start_next;
2031 2282
2032 if (!lp->tt.exch_seq_send) 2283 if (!lport->tt.exch_seq_send)
2033 lp->tt.exch_seq_send = fc_exch_seq_send; 2284 lport->tt.exch_seq_send = fc_exch_seq_send;
2034 2285
2035 if (!lp->tt.seq_send) 2286 if (!lport->tt.seq_send)
2036 lp->tt.seq_send = fc_seq_send; 2287 lport->tt.seq_send = fc_seq_send;
2037 2288
2038 if (!lp->tt.seq_els_rsp_send) 2289 if (!lport->tt.seq_els_rsp_send)
2039 lp->tt.seq_els_rsp_send = fc_seq_els_rsp_send; 2290 lport->tt.seq_els_rsp_send = fc_seq_els_rsp_send;
2040 2291
2041 if (!lp->tt.exch_done) 2292 if (!lport->tt.exch_done)
2042 lp->tt.exch_done = fc_exch_done; 2293 lport->tt.exch_done = fc_exch_done;
2043 2294
2044 if (!lp->tt.exch_mgr_reset) 2295 if (!lport->tt.exch_mgr_reset)
2045 lp->tt.exch_mgr_reset = fc_exch_mgr_reset; 2296 lport->tt.exch_mgr_reset = fc_exch_mgr_reset;
2046 2297
2047 if (!lp->tt.seq_exch_abort) 2298 if (!lport->tt.seq_exch_abort)
2048 lp->tt.seq_exch_abort = fc_seq_exch_abort; 2299 lport->tt.seq_exch_abort = fc_seq_exch_abort;
2300
2301 return 0;
2302}
2303EXPORT_SYMBOL(fc_exch_init);
2304
2305/**
2306 * fc_setup_exch_mgr() - Setup an exchange manager
2307 */
2308int fc_setup_exch_mgr()
2309{
2310 fc_em_cachep = kmem_cache_create("libfc_em", sizeof(struct fc_exch),
2311 0, SLAB_HWCACHE_ALIGN, NULL);
2312 if (!fc_em_cachep)
2313 return -ENOMEM;
2049 2314
2050 /* 2315 /*
2051 * Initialize fc_cpu_mask and fc_cpu_order. The 2316 * Initialize fc_cpu_mask and fc_cpu_order. The
@@ -2069,20 +2334,17 @@ int fc_exch_init(struct fc_lport *lp)
2069 } 2334 }
2070 fc_cpu_mask--; 2335 fc_cpu_mask--;
2071 2336
2072 return 0; 2337 fc_exch_workqueue = create_singlethread_workqueue("fc_exch_workqueue");
2073} 2338 if (!fc_exch_workqueue)
2074EXPORT_SYMBOL(fc_exch_init);
2075
2076int fc_setup_exch_mgr(void)
2077{
2078 fc_em_cachep = kmem_cache_create("libfc_em", sizeof(struct fc_exch),
2079 0, SLAB_HWCACHE_ALIGN, NULL);
2080 if (!fc_em_cachep)
2081 return -ENOMEM; 2339 return -ENOMEM;
2082 return 0; 2340 return 0;
2083} 2341}
2084 2342
2085void fc_destroy_exch_mgr(void) 2343/**
2344 * fc_destroy_exch_mgr() - Destroy an exchange manager
2345 */
2346void fc_destroy_exch_mgr()
2086{ 2347{
2348 destroy_workqueue(fc_exch_workqueue);
2087 kmem_cache_destroy(fc_em_cachep); 2349 kmem_cache_destroy(fc_em_cachep);
2088} 2350}