aboutsummaryrefslogtreecommitdiffstats
path: root/include/scsi/libfc.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/scsi/libfc.h')
-rw-r--r--include/scsi/libfc.h213
1 files changed, 150 insertions, 63 deletions
diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
index 9f2876397dda..45f9cc642c46 100644
--- a/include/scsi/libfc.h
+++ b/include/scsi/libfc.h
@@ -22,6 +22,7 @@
22 22
23#include <linux/timer.h> 23#include <linux/timer.h>
24#include <linux/if.h> 24#include <linux/if.h>
25#include <linux/percpu.h>
25 26
26#include <scsi/scsi_transport.h> 27#include <scsi/scsi_transport.h>
27#include <scsi/scsi_transport_fc.h> 28#include <scsi/scsi_transport_fc.h>
@@ -68,9 +69,6 @@
68/* 69/*
69 * FC HBA status 70 * FC HBA status
70 */ 71 */
71#define FC_PAUSE (1 << 1)
72#define FC_LINK_UP (1 << 0)
73
74enum fc_lport_state { 72enum fc_lport_state {
75 LPORT_ST_NONE = 0, 73 LPORT_ST_NONE = 0,
76 LPORT_ST_FLOGI, 74 LPORT_ST_FLOGI,
@@ -248,6 +246,7 @@ struct fc_fcp_pkt {
248 */ 246 */
249 struct fcp_cmnd cdb_cmd; 247 struct fcp_cmnd cdb_cmd;
250 size_t xfer_len; 248 size_t xfer_len;
249 u16 xfer_ddp; /* this xfer is ddped */
251 u32 xfer_contig_end; /* offset of end of contiguous xfer */ 250 u32 xfer_contig_end; /* offset of end of contiguous xfer */
252 u16 max_payload; /* max payload size in bytes */ 251 u16 max_payload; /* max payload size in bytes */
253 252
@@ -270,6 +269,15 @@ struct fc_fcp_pkt {
270 u8 recov_retry; /* count of recovery retries */ 269 u8 recov_retry; /* count of recovery retries */
271 struct fc_seq *recov_seq; /* sequence for REC or SRR */ 270 struct fc_seq *recov_seq; /* sequence for REC or SRR */
272}; 271};
272/*
273 * FC_FCP HELPER FUNCTIONS
274 *****************************/
275static inline bool fc_fcp_is_read(const struct fc_fcp_pkt *fsp)
276{
277 if (fsp && fsp->cmd)
278 return fsp->cmd->sc_data_direction == DMA_FROM_DEVICE;
279 return false;
280}
273 281
274/* 282/*
275 * Structure and function definitions for managing Fibre Channel Exchanges 283 * Structure and function definitions for managing Fibre Channel Exchanges
@@ -339,31 +347,17 @@ struct fc_exch {
339 347
340struct libfc_function_template { 348struct libfc_function_template {
341 349
342 /**
343 * Mandatory Fields
344 *
345 * These handlers must be implemented by the LLD.
346 */
347
348 /* 350 /*
349 * Interface to send a FC frame 351 * Interface to send a FC frame
350 */
351 int (*frame_send)(struct fc_lport *lp, struct fc_frame *fp);
352
353 /**
354 * Optional Fields
355 * 352 *
356 * The LLD may choose to implement any of the following handlers. 353 * STATUS: REQUIRED
357 * If LLD doesn't specify hander and leaves its pointer NULL then
358 * the default libfc function will be used for that handler.
359 */
360
361 /**
362 * ELS/CT interfaces
363 */ 354 */
355 int (*frame_send)(struct fc_lport *lp, struct fc_frame *fp);
364 356
365 /* 357 /*
366 * elsct_send - sends ELS/CT frame 358 * Interface to send ELS/CT frames
359 *
360 * STATUS: OPTIONAL
367 */ 361 */
368 struct fc_seq *(*elsct_send)(struct fc_lport *lport, 362 struct fc_seq *(*elsct_send)(struct fc_lport *lport,
369 struct fc_rport *rport, 363 struct fc_rport *rport,
@@ -373,9 +367,6 @@ struct libfc_function_template {
373 struct fc_frame *fp, 367 struct fc_frame *fp,
374 void *arg), 368 void *arg),
375 void *arg, u32 timer_msec); 369 void *arg, u32 timer_msec);
376 /**
377 * Exhance Manager interfaces
378 */
379 370
380 /* 371 /*
381 * Send the FC frame payload using a new exchange and sequence. 372 * Send the FC frame payload using a new exchange and sequence.
@@ -407,6 +398,8 @@ struct libfc_function_template {
407 * timer_msec argument is specified. The timer is canceled when 398 * timer_msec argument is specified. The timer is canceled when
408 * it fires or when the exchange is done. The exchange timeout handler 399 * it fires or when the exchange is done. The exchange timeout handler
409 * is registered by EM layer. 400 * is registered by EM layer.
401 *
402 * STATUS: OPTIONAL
410 */ 403 */
411 struct fc_seq *(*exch_seq_send)(struct fc_lport *lp, 404 struct fc_seq *(*exch_seq_send)(struct fc_lport *lp,
412 struct fc_frame *fp, 405 struct fc_frame *fp,
@@ -418,14 +411,33 @@ struct libfc_function_template {
418 void *arg, unsigned int timer_msec); 411 void *arg, unsigned int timer_msec);
419 412
420 /* 413 /*
421 * send a frame using existing sequence and exchange. 414 * Sets up the DDP context for a given exchange id on the given
415 * scatterlist if LLD supports DDP for large receive.
416 *
417 * STATUS: OPTIONAL
418 */
419 int (*ddp_setup)(struct fc_lport *lp, u16 xid,
420 struct scatterlist *sgl, unsigned int sgc);
421 /*
422 * Completes the DDP transfer and returns the length of data DDPed
423 * for the given exchange id.
424 *
425 * STATUS: OPTIONAL
426 */
427 int (*ddp_done)(struct fc_lport *lp, u16 xid);
428 /*
429 * Send a frame using an existing sequence and exchange.
430 *
431 * STATUS: OPTIONAL
422 */ 432 */
423 int (*seq_send)(struct fc_lport *lp, struct fc_seq *sp, 433 int (*seq_send)(struct fc_lport *lp, struct fc_seq *sp,
424 struct fc_frame *fp); 434 struct fc_frame *fp);
425 435
426 /* 436 /*
427 * Send ELS response using mainly infomation 437 * Send an ELS response using infomation from a previous
428 * in exchange and sequence in EM layer. 438 * exchange and sequence.
439 *
440 * STATUS: OPTIONAL
429 */ 441 */
430 void (*seq_els_rsp_send)(struct fc_seq *sp, enum fc_els_cmd els_cmd, 442 void (*seq_els_rsp_send)(struct fc_seq *sp, enum fc_els_cmd els_cmd,
431 struct fc_seq_els_data *els_data); 443 struct fc_seq_els_data *els_data);
@@ -437,6 +449,8 @@ struct libfc_function_template {
437 * A timer_msec can be specified for abort timeout, if non-zero 449 * A timer_msec can be specified for abort timeout, if non-zero
438 * timer_msec value is specified then exchange resp handler 450 * timer_msec value is specified then exchange resp handler
439 * will be called with timeout error if no response to abort. 451 * will be called with timeout error if no response to abort.
452 *
453 * STATUS: OPTIONAL
440 */ 454 */
441 int (*seq_exch_abort)(const struct fc_seq *req_sp, 455 int (*seq_exch_abort)(const struct fc_seq *req_sp,
442 unsigned int timer_msec); 456 unsigned int timer_msec);
@@ -444,6 +458,8 @@ struct libfc_function_template {
444 /* 458 /*
445 * Indicate that an exchange/sequence tuple is complete and the memory 459 * Indicate that an exchange/sequence tuple is complete and the memory
446 * allocated for the related objects may be freed. 460 * allocated for the related objects may be freed.
461 *
462 * STATUS: OPTIONAL
447 */ 463 */
448 void (*exch_done)(struct fc_seq *sp); 464 void (*exch_done)(struct fc_seq *sp);
449 465
@@ -451,6 +467,8 @@ struct libfc_function_template {
451 * Assigns a EM and a free XID for an new exchange and then 467 * Assigns a EM and a free XID for an new exchange and then
452 * allocates a new exchange and sequence pair. 468 * allocates a new exchange and sequence pair.
453 * The fp can be used to determine free XID. 469 * The fp can be used to determine free XID.
470 *
471 * STATUS: OPTIONAL
454 */ 472 */
455 struct fc_exch *(*exch_get)(struct fc_lport *lp, struct fc_frame *fp); 473 struct fc_exch *(*exch_get)(struct fc_lport *lp, struct fc_frame *fp);
456 474
@@ -458,12 +476,16 @@ struct libfc_function_template {
458 * Release previously assigned XID by exch_get API. 476 * Release previously assigned XID by exch_get API.
459 * The LLD may implement this if XID is assigned by LLD 477 * The LLD may implement this if XID is assigned by LLD
460 * in exch_get(). 478 * in exch_get().
479 *
480 * STATUS: OPTIONAL
461 */ 481 */
462 void (*exch_put)(struct fc_lport *lp, struct fc_exch_mgr *mp, 482 void (*exch_put)(struct fc_lport *lp, struct fc_exch_mgr *mp,
463 u16 ex_id); 483 u16 ex_id);
464 484
465 /* 485 /*
466 * Start a new sequence on the same exchange/sequence tuple. 486 * Start a new sequence on the same exchange/sequence tuple.
487 *
488 * STATUS: OPTIONAL
467 */ 489 */
468 struct fc_seq *(*seq_start_next)(struct fc_seq *sp); 490 struct fc_seq *(*seq_start_next)(struct fc_seq *sp);
469 491
@@ -471,26 +493,38 @@ struct libfc_function_template {
471 * Reset an exchange manager, completing all sequences and exchanges. 493 * Reset an exchange manager, completing all sequences and exchanges.
472 * If s_id is non-zero, reset only exchanges originating from that FID. 494 * If s_id is non-zero, reset only exchanges originating from that FID.
473 * If d_id is non-zero, reset only exchanges sending to that FID. 495 * If d_id is non-zero, reset only exchanges sending to that FID.
496 *
497 * STATUS: OPTIONAL
474 */ 498 */
475 void (*exch_mgr_reset)(struct fc_exch_mgr *, 499 void (*exch_mgr_reset)(struct fc_lport *,
476 u32 s_id, u32 d_id); 500 u32 s_id, u32 d_id);
477 501
478 void (*rport_flush_queue)(void); 502 /*
479 /** 503 * Flush the rport work queue. Generally used before shutdown.
480 * Local Port interfaces 504 *
505 * STATUS: OPTIONAL
481 */ 506 */
507 void (*rport_flush_queue)(void);
482 508
483 /* 509 /*
484 * Receive a frame to a local port. 510 * Receive a frame for a local port.
511 *
512 * STATUS: OPTIONAL
485 */ 513 */
486 void (*lport_recv)(struct fc_lport *lp, struct fc_seq *sp, 514 void (*lport_recv)(struct fc_lport *lp, struct fc_seq *sp,
487 struct fc_frame *fp); 515 struct fc_frame *fp);
488 516
517 /*
518 * Reset the local port.
519 *
520 * STATUS: OPTIONAL
521 */
489 int (*lport_reset)(struct fc_lport *); 522 int (*lport_reset)(struct fc_lport *);
490 523
491 /** 524 /*
492 * Remote Port interfaces 525 * Create a remote port
493 */ 526 */
527 struct fc_rport *(*rport_create)(struct fc_disc_port *);
494 528
495 /* 529 /*
496 * Initiates the RP state machine. It is called from the LP module. 530 * Initiates the RP state machine. It is called from the LP module.
@@ -500,26 +534,33 @@ struct libfc_function_template {
500 * - PLOGI 534 * - PLOGI
501 * - PRLI 535 * - PRLI
502 * - RTV 536 * - RTV
537 *
538 * STATUS: OPTIONAL
503 */ 539 */
504 int (*rport_login)(struct fc_rport *rport); 540 int (*rport_login)(struct fc_rport *rport);
505 541
506 /* 542 /*
507 * Logoff, and remove the rport from the transport if 543 * Logoff, and remove the rport from the transport if
508 * it had been added. This will send a LOGO to the target. 544 * it had been added. This will send a LOGO to the target.
545 *
546 * STATUS: OPTIONAL
509 */ 547 */
510 int (*rport_logoff)(struct fc_rport *rport); 548 int (*rport_logoff)(struct fc_rport *rport);
511 549
512 /* 550 /*
513 * Recieve a request from a remote port. 551 * Recieve a request from a remote port.
552 *
553 * STATUS: OPTIONAL
514 */ 554 */
515 void (*rport_recv_req)(struct fc_seq *, struct fc_frame *, 555 void (*rport_recv_req)(struct fc_seq *, struct fc_frame *,
516 struct fc_rport *); 556 struct fc_rport *);
517 557
518 struct fc_rport *(*rport_lookup)(const struct fc_lport *, u32); 558 /*
519 559 * lookup an rport by it's port ID.
520 /** 560 *
521 * FCP interfaces 561 * STATUS: OPTIONAL
522 */ 562 */
563 struct fc_rport *(*rport_lookup)(const struct fc_lport *, u32);
523 564
524 /* 565 /*
525 * Send a fcp cmd from fsp pkt. 566 * Send a fcp cmd from fsp pkt.
@@ -527,30 +568,38 @@ struct libfc_function_template {
527 * 568 *
528 * The resp handler is called when FCP_RSP received. 569 * The resp handler is called when FCP_RSP received.
529 * 570 *
571 * STATUS: OPTIONAL
530 */ 572 */
531 int (*fcp_cmd_send)(struct fc_lport *lp, struct fc_fcp_pkt *fsp, 573 int (*fcp_cmd_send)(struct fc_lport *lp, struct fc_fcp_pkt *fsp,
532 void (*resp)(struct fc_seq *, struct fc_frame *fp, 574 void (*resp)(struct fc_seq *, struct fc_frame *fp,
533 void *arg)); 575 void *arg));
534 576
535 /* 577 /*
536 * Used at least durring linkdown and reset 578 * Cleanup the FCP layer, used durring link down and reset
579 *
580 * STATUS: OPTIONAL
537 */ 581 */
538 void (*fcp_cleanup)(struct fc_lport *lp); 582 void (*fcp_cleanup)(struct fc_lport *lp);
539 583
540 /* 584 /*
541 * Abort all I/O on a local port 585 * Abort all I/O on a local port
586 *
587 * STATUS: OPTIONAL
542 */ 588 */
543 void (*fcp_abort_io)(struct fc_lport *lp); 589 void (*fcp_abort_io)(struct fc_lport *lp);
544 590
545 /** 591 /*
546 * Discovery interfaces 592 * Receive a request for the discovery layer.
593 *
594 * STATUS: OPTIONAL
547 */ 595 */
548
549 void (*disc_recv_req)(struct fc_seq *, 596 void (*disc_recv_req)(struct fc_seq *,
550 struct fc_frame *, struct fc_lport *); 597 struct fc_frame *, struct fc_lport *);
551 598
552 /* 599 /*
553 * Start discovery for a local port. 600 * Start discovery for a local port.
601 *
602 * STATUS: OPTIONAL
554 */ 603 */
555 void (*disc_start)(void (*disc_callback)(struct fc_lport *, 604 void (*disc_start)(void (*disc_callback)(struct fc_lport *,
556 enum fc_disc_event), 605 enum fc_disc_event),
@@ -559,6 +608,8 @@ struct libfc_function_template {
559 /* 608 /*
560 * Stop discovery for a given lport. This will remove 609 * Stop discovery for a given lport. This will remove
561 * all discovered rports 610 * all discovered rports
611 *
612 * STATUS: OPTIONAL
562 */ 613 */
563 void (*disc_stop) (struct fc_lport *); 614 void (*disc_stop) (struct fc_lport *);
564 615
@@ -566,6 +617,8 @@ struct libfc_function_template {
566 * Stop discovery for a given lport. This will block 617 * Stop discovery for a given lport. This will block
567 * until all discovered rports are deleted from the 618 * until all discovered rports are deleted from the
568 * FC transport class 619 * FC transport class
620 *
621 * STATUS: OPTIONAL
569 */ 622 */
570 void (*disc_stop_final) (struct fc_lport *); 623 void (*disc_stop_final) (struct fc_lport *);
571}; 624};
@@ -584,6 +637,7 @@ struct fc_disc {
584 enum fc_disc_event); 637 enum fc_disc_event);
585 638
586 struct list_head rports; 639 struct list_head rports;
640 struct list_head rogue_rports;
587 struct fc_lport *lport; 641 struct fc_lport *lport;
588 struct mutex disc_mutex; 642 struct mutex disc_mutex;
589 struct fc_gpn_ft_resp partial_buf; /* partial name buffer */ 643 struct fc_gpn_ft_resp partial_buf; /* partial name buffer */
@@ -603,12 +657,14 @@ struct fc_lport {
603 657
604 /* Operational Information */ 658 /* Operational Information */
605 struct libfc_function_template tt; 659 struct libfc_function_template tt;
606 u16 link_status; 660 u8 link_up;
661 u8 qfull;
607 enum fc_lport_state state; 662 enum fc_lport_state state;
608 unsigned long boot_time; 663 unsigned long boot_time;
609 664
610 struct fc_host_statistics host_stats; 665 struct fc_host_statistics host_stats;
611 struct fcoe_dev_stats *dev_stats[NR_CPUS]; 666 struct fcoe_dev_stats *dev_stats;
667
612 u64 wwpn; 668 u64 wwpn;
613 u64 wwnn; 669 u64 wwnn;
614 u8 retry_count; 670 u8 retry_count;
@@ -626,6 +682,7 @@ struct fc_lport {
626 u16 link_speed; 682 u16 link_speed;
627 u16 link_supported_speeds; 683 u16 link_supported_speeds;
628 u16 lro_xid; /* max xid for fcoe lro */ 684 u16 lro_xid; /* max xid for fcoe lro */
685 unsigned int lso_max; /* max large send size */
629 struct fc_ns_fts fcts; /* FC-4 type masks */ 686 struct fc_ns_fts fcts; /* FC-4 type masks */
630 struct fc_els_rnid_gen rnid_gen; /* RNID information */ 687 struct fc_els_rnid_gen rnid_gen; /* RNID information */
631 688
@@ -637,14 +694,9 @@ struct fc_lport {
637 struct delayed_work disc_work; 694 struct delayed_work disc_work;
638}; 695};
639 696
640/** 697/*
641 * FC_LPORT HELPER FUNCTIONS 698 * FC_LPORT HELPER FUNCTIONS
642 *****************************/ 699 *****************************/
643static inline void *lport_priv(const struct fc_lport *lp)
644{
645 return (void *)(lp + 1);
646}
647
648static inline int fc_lport_test_ready(struct fc_lport *lp) 700static inline int fc_lport_test_ready(struct fc_lport *lp)
649{ 701{
650 return lp->state == LPORT_ST_READY; 702 return lp->state == LPORT_ST_READY;
@@ -668,8 +720,44 @@ static inline void fc_lport_state_enter(struct fc_lport *lp,
668 lp->state = state; 720 lp->state = state;
669} 721}
670 722
723static inline int fc_lport_init_stats(struct fc_lport *lp)
724{
725 /* allocate per cpu stats block */
726 lp->dev_stats = alloc_percpu(struct fcoe_dev_stats);
727 if (!lp->dev_stats)
728 return -ENOMEM;
729 return 0;
730}
731
732static inline void fc_lport_free_stats(struct fc_lport *lp)
733{
734 free_percpu(lp->dev_stats);
735}
736
737static inline struct fcoe_dev_stats *fc_lport_get_stats(struct fc_lport *lp)
738{
739 return per_cpu_ptr(lp->dev_stats, smp_processor_id());
740}
741
742static inline void *lport_priv(const struct fc_lport *lp)
743{
744 return (void *)(lp + 1);
745}
671 746
672/** 747/**
748 * libfc_host_alloc() - Allocate a Scsi_Host with room for the fc_lport
749 * @sht: ptr to the scsi host templ
750 * @priv_size: size of private data after fc_lport
751 *
752 * Returns: ptr to Scsi_Host
753 */
754static inline struct Scsi_Host *
755libfc_host_alloc(struct scsi_host_template *sht, int priv_size)
756{
757 return scsi_host_alloc(sht, sizeof(struct fc_lport) + priv_size);
758}
759
760/*
673 * LOCAL PORT LAYER 761 * LOCAL PORT LAYER
674 *****************************/ 762 *****************************/
675int fc_lport_init(struct fc_lport *lp); 763int fc_lport_init(struct fc_lport *lp);
@@ -704,12 +792,6 @@ void fc_linkup(struct fc_lport *);
704void fc_linkdown(struct fc_lport *); 792void fc_linkdown(struct fc_lport *);
705 793
706/* 794/*
707 * Pause and unpause traffic.
708 */
709void fc_pause(struct fc_lport *);
710void fc_unpause(struct fc_lport *);
711
712/*
713 * Configure the local port. 795 * Configure the local port.
714 */ 796 */
715int fc_lport_config(struct fc_lport *); 797int fc_lport_config(struct fc_lport *);
@@ -725,19 +807,19 @@ int fc_lport_reset(struct fc_lport *);
725int fc_set_mfs(struct fc_lport *lp, u32 mfs); 807int fc_set_mfs(struct fc_lport *lp, u32 mfs);
726 808
727 809
728/** 810/*
729 * REMOTE PORT LAYER 811 * REMOTE PORT LAYER
730 *****************************/ 812 *****************************/
731int fc_rport_init(struct fc_lport *lp); 813int fc_rport_init(struct fc_lport *lp);
732void fc_rport_terminate_io(struct fc_rport *rp); 814void fc_rport_terminate_io(struct fc_rport *rp);
733 815
734/** 816/*
735 * DISCOVERY LAYER 817 * DISCOVERY LAYER
736 *****************************/ 818 *****************************/
737int fc_disc_init(struct fc_lport *lp); 819int fc_disc_init(struct fc_lport *lp);
738 820
739 821
740/** 822/*
741 * SCSI LAYER 823 * SCSI LAYER
742 *****************************/ 824 *****************************/
743/* 825/*
@@ -798,7 +880,12 @@ int fc_change_queue_type(struct scsi_device *sdev, int tag_type);
798 */ 880 */
799void fc_fcp_destroy(struct fc_lport *); 881void fc_fcp_destroy(struct fc_lport *);
800 882
801/** 883/*
884 * Set up direct-data placement for this I/O request
885 */
886void fc_fcp_ddp_setup(struct fc_fcp_pkt *fsp, u16 xid);
887
888/*
802 * ELS/CT interface 889 * ELS/CT interface
803 *****************************/ 890 *****************************/
804/* 891/*
@@ -807,7 +894,7 @@ void fc_fcp_destroy(struct fc_lport *);
807int fc_elsct_init(struct fc_lport *lp); 894int fc_elsct_init(struct fc_lport *lp);
808 895
809 896
810/** 897/*
811 * EXCHANGE MANAGER LAYER 898 * EXCHANGE MANAGER LAYER
812 *****************************/ 899 *****************************/
813/* 900/*
@@ -916,7 +1003,7 @@ struct fc_seq *fc_seq_start_next(struct fc_seq *sp);
916 * If s_id is non-zero, reset only exchanges originating from that FID. 1003 * If s_id is non-zero, reset only exchanges originating from that FID.
917 * If d_id is non-zero, reset only exchanges sending to that FID. 1004 * If d_id is non-zero, reset only exchanges sending to that FID.
918 */ 1005 */
919void fc_exch_mgr_reset(struct fc_exch_mgr *, u32 s_id, u32 d_id); 1006void fc_exch_mgr_reset(struct fc_lport *, u32 s_id, u32 d_id);
920 1007
921/* 1008/*
922 * Functions for fc_functions_template 1009 * Functions for fc_functions_template