1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#ifndef _LIBFC_H_
21#define _LIBFC_H_
22
23#include <linux/timer.h>
24#include <linux/if.h>
25#include <linux/percpu.h>
26
27#include <scsi/scsi_transport.h>
28#include <scsi/scsi_transport_fc.h>
29
30#include <scsi/fc/fc_fcp.h>
31#include <scsi/fc/fc_ns.h>
32#include <scsi/fc/fc_els.h>
33#include <scsi/fc/fc_gs.h>
34
35#include <scsi/fc_frame.h>
36
37#define FC_LIBFC_LOGGING 0x01
38#define FC_LPORT_LOGGING 0x02
39#define FC_DISC_LOGGING 0x04
40#define FC_RPORT_LOGGING 0x08
41#define FC_FCP_LOGGING 0x10
42#define FC_EM_LOGGING 0x20
43#define FC_EXCH_LOGGING 0x40
44#define FC_SCSI_LOGGING 0x80
45
46extern unsigned int fc_debug_logging;
47
48#define FC_CHECK_LOGGING(LEVEL, CMD) \
49do { \
50 if (unlikely(fc_debug_logging & LEVEL)) \
51 do { \
52 CMD; \
53 } while (0); \
54} while (0)
55
56#define FC_LIBFC_DBG(fmt, args...) \
57 FC_CHECK_LOGGING(FC_LIBFC_LOGGING, \
58 printk(KERN_INFO "libfc: " fmt, ##args))
59
60#define FC_LPORT_DBG(lport, fmt, args...) \
61 FC_CHECK_LOGGING(FC_LPORT_LOGGING, \
62 printk(KERN_INFO "host%u: lport %6x: " fmt, \
63 (lport)->host->host_no, \
64 fc_host_port_id((lport)->host), ##args))
65
66#define FC_DISC_DBG(disc, fmt, args...) \
67 FC_CHECK_LOGGING(FC_DISC_LOGGING, \
68 printk(KERN_INFO "host%u: disc: " fmt, \
69 (disc)->lport->host->host_no, \
70 ##args))
71
72#define FC_RPORT_ID_DBG(lport, port_id, fmt, args...) \
73 FC_CHECK_LOGGING(FC_RPORT_LOGGING, \
74 printk(KERN_INFO "host%u: rport %6x: " fmt, \
75 (lport)->host->host_no, \
76 (port_id), ##args))
77
78#define FC_RPORT_DBG(rdata, fmt, args...) \
79 FC_RPORT_ID_DBG((rdata)->local_port, (rdata)->ids.port_id, fmt, ##args)
80
81#define FC_FCP_DBG(pkt, fmt, args...) \
82 FC_CHECK_LOGGING(FC_FCP_LOGGING, \
83 printk(KERN_INFO "host%u: fcp: %6x: " fmt, \
84 (pkt)->lp->host->host_no, \
85 pkt->rport->port_id, ##args))
86
87#define FC_EXCH_DBG(exch, fmt, args...) \
88 FC_CHECK_LOGGING(FC_EXCH_LOGGING, \
89 printk(KERN_INFO "host%u: xid %4x: " fmt, \
90 (exch)->lp->host->host_no, \
91 exch->xid, ##args))
92
93#define FC_SCSI_DBG(lport, fmt, args...) \
94 FC_CHECK_LOGGING(FC_SCSI_LOGGING, \
95 printk(KERN_INFO "host%u: scsi: " fmt, \
96 (lport)->host->host_no, ##args))
97
98
99
100
101#define FC_NO_ERR 0
102#define FC_EX_TIMEOUT 1
103#define FC_EX_CLOSED 2
104
105
106
107#define ntohll(x) be64_to_cpu(x)
108#define htonll(x) cpu_to_be64(x)
109
110#define ntoh24(p) (((p)[0] << 16) | ((p)[1] << 8) | ((p)[2]))
111
112#define hton24(p, v) do { \
113 p[0] = (((v) >> 16) & 0xFF); \
114 p[1] = (((v) >> 8) & 0xFF); \
115 p[2] = ((v) & 0xFF); \
116 } while (0)
117
118
119
120
121enum fc_lport_state {
122 LPORT_ST_DISABLED = 0,
123 LPORT_ST_FLOGI,
124 LPORT_ST_DNS,
125 LPORT_ST_RPN_ID,
126 LPORT_ST_RFT_ID,
127 LPORT_ST_SCR,
128 LPORT_ST_READY,
129 LPORT_ST_LOGO,
130 LPORT_ST_RESET
131};
132
133enum fc_disc_event {
134 DISC_EV_NONE = 0,
135 DISC_EV_SUCCESS,
136 DISC_EV_FAILED
137};
138
139enum fc_rport_state {
140 RPORT_ST_INIT,
141 RPORT_ST_PLOGI,
142 RPORT_ST_PRLI,
143 RPORT_ST_RTV,
144 RPORT_ST_READY,
145 RPORT_ST_LOGO,
146 RPORT_ST_ADISC,
147 RPORT_ST_DELETE,
148};
149
150
151
152
153
154
155
156
157struct fc_disc_port {
158 struct fc_lport *lp;
159 struct list_head peers;
160 struct work_struct rport_work;
161 u32 port_id;
162};
163
164enum fc_rport_event {
165 RPORT_EV_NONE = 0,
166 RPORT_EV_READY,
167 RPORT_EV_FAILED,
168 RPORT_EV_STOP,
169 RPORT_EV_LOGO
170};
171
172struct fc_rport_priv;
173
174struct fc_rport_operations {
175 void (*event_callback)(struct fc_lport *, struct fc_rport_priv *,
176 enum fc_rport_event);
177};
178
179
180
181
182
183
184
185
186
187struct fc_rport_libfc_priv {
188 struct fc_lport *local_port;
189 enum fc_rport_state rp_state;
190 u16 flags;
191 #define FC_RP_FLAGS_REC_SUPPORTED (1 << 0)
192 #define FC_RP_FLAGS_RETRY (1 << 1)
193 unsigned int e_d_tov;
194 unsigned int r_a_tov;
195};
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215struct fc_rport_priv {
216 struct fc_lport *local_port;
217 struct fc_rport *rport;
218 struct kref kref;
219 enum fc_rport_state rp_state;
220 struct fc_rport_identifiers ids;
221 u16 flags;
222 u16 max_seq;
223 u16 disc_id;
224 u16 maxframe_size;
225 unsigned int retries;
226 unsigned int e_d_tov;
227 unsigned int r_a_tov;
228 struct mutex rp_mutex;
229 struct delayed_work retry_work;
230 enum fc_rport_event event;
231 struct fc_rport_operations *ops;
232 struct list_head peers;
233 struct work_struct event_work;
234 u32 supported_classes;
235};
236
237
238
239
240struct fcoe_dev_stats {
241 u64 SecondsSinceLastReset;
242 u64 TxFrames;
243 u64 TxWords;
244 u64 RxFrames;
245 u64 RxWords;
246 u64 ErrorFrames;
247 u64 DumpedFrames;
248 u64 LinkFailureCount;
249 u64 LossOfSignalCount;
250 u64 InvalidTxWordCount;
251 u64 InvalidCRCCount;
252 u64 InputRequests;
253 u64 OutputRequests;
254 u64 ControlRequests;
255 u64 InputMegabytes;
256 u64 OutputMegabytes;
257};
258
259
260
261
262
263
264struct fc_seq_els_data {
265 struct fc_frame *fp;
266 enum fc_els_rjt_reason reason;
267 enum fc_els_rjt_explan explan;
268};
269
270
271
272
273struct fc_fcp_pkt {
274
275
276
277 struct fc_lport *lp;
278 u16 state;
279 u16 tgt_flags;
280 atomic_t ref_cnt;
281 spinlock_t scsi_pkt_lock;
282
283
284
285
286 struct scsi_cmnd *cmd;
287
288 struct list_head list;
289
290
291
292
293 struct timer_list timer;
294 struct completion tm_done;
295 int wait_for_comp;
296 unsigned long start_time;
297 unsigned long end_time;
298 unsigned long last_pkt_time;
299
300
301
302
303 u32 data_len;
304
305
306
307 struct fcp_cmnd cdb_cmd;
308 size_t xfer_len;
309 u16 xfer_ddp;
310 u32 xfer_contig_end;
311 u16 max_payload;
312
313
314
315
316 u32 io_status;
317 u8 cdb_status;
318 u8 status_code;
319
320 u8 scsi_comp_flags;
321 u32 req_flags;
322 u32 scsi_resid;
323
324 struct fc_rport *rport;
325 struct fc_seq *seq_ptr;
326
327
328
329 u8 recov_retry;
330 struct fc_seq *recov_seq;
331};
332
333
334
335static inline bool fc_fcp_is_read(const struct fc_fcp_pkt *fsp)
336{
337 if (fsp && fsp->cmd)
338 return fsp->cmd->sc_data_direction == DMA_FROM_DEVICE;
339 return false;
340}
341
342
343
344
345
346
347
348
349
350
351struct fc_exch_mgr;
352struct fc_exch_mgr_anchor;
353extern u16 fc_cpu_mask;
354
355
356
357
358struct fc_seq {
359 u8 id;
360 u16 ssb_stat;
361 u16 cnt;
362 u32 rec_data;
363};
364
365#define FC_EX_DONE (1 << 0)
366#define FC_EX_RST_CLEANUP (1 << 1)
367
368
369
370
371
372
373
374
375
376struct fc_exch {
377 struct fc_exch_mgr *em;
378 struct fc_exch_pool *pool;
379 u32 state;
380 u16 xid;
381 struct list_head ex_list;
382 spinlock_t ex_lock;
383 atomic_t ex_refcnt;
384 struct delayed_work timeout_work;
385 struct fc_lport *lp;
386 u16 oxid;
387 u16 rxid;
388 u32 oid;
389 u32 sid;
390 u32 did;
391 u32 esb_stat;
392 u32 r_a_tov;
393 u8 seq_id;
394 u32 f_ctl;
395 u8 fh_type;
396 enum fc_class class;
397 struct fc_seq seq;
398
399
400
401 void (*resp)(struct fc_seq *, struct fc_frame *, void *);
402 void (*destructor)(struct fc_seq *, void *);
403
404
405
406
407 void *arg;
408};
409#define fc_seq_exch(sp) container_of(sp, struct fc_exch, seq)
410
411struct libfc_function_template {
412
413
414
415
416
417
418 int (*frame_send)(struct fc_lport *lp, struct fc_frame *fp);
419
420
421
422
423
424
425 struct fc_seq *(*elsct_send)(struct fc_lport *lport,
426 u32 did,
427 struct fc_frame *fp,
428 unsigned int op,
429 void (*resp)(struct fc_seq *,
430 struct fc_frame *fp,
431 void *arg),
432 void *arg, u32 timer_msec);
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467 struct fc_seq *(*exch_seq_send)(struct fc_lport *lp,
468 struct fc_frame *fp,
469 void (*resp)(struct fc_seq *sp,
470 struct fc_frame *fp,
471 void *arg),
472 void (*destructor)(struct fc_seq *sp,
473 void *arg),
474 void *arg, unsigned int timer_msec);
475
476
477
478
479
480
481
482 int (*ddp_setup)(struct fc_lport *lp, u16 xid,
483 struct scatterlist *sgl, unsigned int sgc);
484
485
486
487
488
489
490 int (*ddp_done)(struct fc_lport *lp, u16 xid);
491
492
493
494
495
496 int (*seq_send)(struct fc_lport *lp, struct fc_seq *sp,
497 struct fc_frame *fp);
498
499
500
501
502
503
504
505 void (*seq_els_rsp_send)(struct fc_seq *sp, enum fc_els_cmd els_cmd,
506 struct fc_seq_els_data *els_data);
507
508
509
510
511
512
513
514
515
516
517
518 int (*seq_exch_abort)(const struct fc_seq *req_sp,
519 unsigned int timer_msec);
520
521
522
523
524
525
526
527 void (*exch_done)(struct fc_seq *sp);
528
529
530
531
532
533
534 struct fc_seq *(*seq_start_next)(struct fc_seq *sp);
535
536
537
538
539
540
541
542
543 void (*exch_mgr_reset)(struct fc_lport *,
544 u32 s_id, u32 d_id);
545
546
547
548
549
550
551 void (*rport_flush_queue)(void);
552
553
554
555
556
557
558 void (*lport_recv)(struct fc_lport *lp, struct fc_seq *sp,
559 struct fc_frame *fp);
560
561
562
563
564
565
566 int (*lport_reset)(struct fc_lport *);
567
568
569
570
571
572
573 struct fc_rport_priv *(*rport_create)(struct fc_lport *, u32);
574
575
576
577
578
579
580
581
582
583
584
585
586 int (*rport_login)(struct fc_rport_priv *);
587
588
589
590
591
592
593
594 int (*rport_logoff)(struct fc_rport_priv *);
595
596
597
598
599
600
601 void (*rport_recv_req)(struct fc_seq *, struct fc_frame *,
602 struct fc_lport *);
603
604
605
606
607
608
609 struct fc_rport_priv *(*rport_lookup)(const struct fc_lport *, u32);
610
611
612
613
614
615 void (*rport_destroy)(struct kref *);
616
617
618
619
620
621
622
623
624
625 int (*fcp_cmd_send)(struct fc_lport *lp, struct fc_fcp_pkt *fsp,
626 void (*resp)(struct fc_seq *, struct fc_frame *fp,
627 void *arg));
628
629
630
631
632
633
634 void (*fcp_cleanup)(struct fc_lport *lp);
635
636
637
638
639
640
641 void (*fcp_abort_io)(struct fc_lport *lp);
642
643
644
645
646
647
648 void (*disc_recv_req)(struct fc_seq *,
649 struct fc_frame *, struct fc_lport *);
650
651
652
653
654
655
656 void (*disc_start)(void (*disc_callback)(struct fc_lport *,
657 enum fc_disc_event),
658 struct fc_lport *);
659
660
661
662
663
664
665
666 void (*disc_stop) (struct fc_lport *);
667
668
669
670
671
672
673
674
675 void (*disc_stop_final) (struct fc_lport *);
676};
677
678
679struct fc_disc {
680 unsigned char retry_count;
681 unsigned char pending;
682 unsigned char requested;
683 unsigned short seq_count;
684 unsigned char buf_len;
685 u16 disc_id;
686
687 void (*disc_callback)(struct fc_lport *,
688 enum fc_disc_event);
689
690 struct list_head rports;
691 struct fc_lport *lport;
692 struct mutex disc_mutex;
693 struct fc_gpn_ft_resp partial_buf;
694 struct delayed_work disc_work;
695};
696
697struct fc_lport {
698 struct list_head list;
699
700
701 struct Scsi_Host *host;
702 struct list_head ema_list;
703 struct fc_rport_priv *dns_rp;
704 struct fc_rport_priv *ptp_rp;
705 void *scsi_priv;
706 struct fc_disc disc;
707
708
709 struct libfc_function_template tt;
710 u8 link_up;
711 u8 qfull;
712 enum fc_lport_state state;
713 unsigned long boot_time;
714
715 struct fc_host_statistics host_stats;
716 struct fcoe_dev_stats *dev_stats;
717
718 u64 wwpn;
719 u64 wwnn;
720 u8 retry_count;
721
722
723 u32 sg_supp:1;
724 u32 seq_offload:1;
725 u32 crc_offload:1;
726 u32 lro_enabled:1;
727 u32 mfs;
728 unsigned int service_params;
729 unsigned int e_d_tov;
730 unsigned int r_a_tov;
731 u8 max_retry_count;
732 u8 max_rport_retry_count;
733 u16 link_speed;
734 u16 link_supported_speeds;
735 u16 lro_xid;
736 unsigned int lso_max;
737 struct fc_ns_fts fcts;
738 struct fc_els_rnid_gen rnid_gen;
739
740
741 struct mutex lp_mutex;
742
743
744 struct delayed_work retry_work;
745 struct delayed_work disc_work;
746};
747
748
749
750
751static inline int fc_lport_test_ready(struct fc_lport *lp)
752{
753 return lp->state == LPORT_ST_READY;
754}
755
756static inline void fc_set_wwnn(struct fc_lport *lp, u64 wwnn)
757{
758 lp->wwnn = wwnn;
759}
760
761static inline void fc_set_wwpn(struct fc_lport *lp, u64 wwnn)
762{
763 lp->wwpn = wwnn;
764}
765
766static inline void fc_lport_state_enter(struct fc_lport *lp,
767 enum fc_lport_state state)
768{
769 if (state != lp->state)
770 lp->retry_count = 0;
771 lp->state = state;
772}
773
774static inline int fc_lport_init_stats(struct fc_lport *lp)
775{
776
777 lp->dev_stats = alloc_percpu(struct fcoe_dev_stats);
778 if (!lp->dev_stats)
779 return -ENOMEM;
780 return 0;
781}
782
783static inline void fc_lport_free_stats(struct fc_lport *lp)
784{
785 free_percpu(lp->dev_stats);
786}
787
788static inline struct fcoe_dev_stats *fc_lport_get_stats(struct fc_lport *lp)
789{
790 return per_cpu_ptr(lp->dev_stats, smp_processor_id());
791}
792
793static inline void *lport_priv(const struct fc_lport *lp)
794{
795 return (void *)(lp + 1);
796}
797
798
799
800
801
802
803
804
805static inline struct Scsi_Host *
806libfc_host_alloc(struct scsi_host_template *sht, int priv_size)
807{
808 return scsi_host_alloc(sht, sizeof(struct fc_lport) + priv_size);
809}
810
811
812
813
814int fc_lport_init(struct fc_lport *lp);
815
816
817
818
819
820
821int fc_lport_destroy(struct fc_lport *lp);
822
823
824
825
826int fc_fabric_logoff(struct fc_lport *lp);
827
828
829
830
831
832
833int fc_fabric_login(struct fc_lport *lp);
834
835
836
837
838void fc_linkup(struct fc_lport *);
839
840
841
842
843void fc_linkdown(struct fc_lport *);
844
845
846
847
848int fc_lport_config(struct fc_lport *);
849
850
851
852
853int fc_lport_reset(struct fc_lport *);
854
855
856
857
858int fc_set_mfs(struct fc_lport *lp, u32 mfs);
859
860
861
862
863
864int fc_rport_init(struct fc_lport *lp);
865void fc_rport_terminate_io(struct fc_rport *rp);
866
867
868
869
870int fc_disc_init(struct fc_lport *lp);
871
872
873
874
875
876
877
878
879int fc_fcp_init(struct fc_lport *);
880
881
882
883
884
885
886
887int fc_queuecommand(struct scsi_cmnd *sc_cmd,
888 void (*done)(struct scsi_cmnd *));
889
890
891
892
893
894
895
896void fc_fcp_complete(struct fc_fcp_pkt *fsp);
897
898
899
900
901
902int fc_eh_abort(struct scsi_cmnd *sc_cmd);
903
904
905
906
907int fc_eh_device_reset(struct scsi_cmnd *sc_cmd);
908
909
910
911
912int fc_eh_host_reset(struct scsi_cmnd *sc_cmd);
913
914
915
916
917int fc_slave_alloc(struct scsi_device *sdev);
918
919
920
921
922int fc_change_queue_depth(struct scsi_device *sdev, int qdepth);
923
924
925
926
927int fc_change_queue_type(struct scsi_device *sdev, int tag_type);
928
929
930
931
932void fc_fcp_destroy(struct fc_lport *);
933
934
935
936
937void fc_fcp_ddp_setup(struct fc_fcp_pkt *fsp, u16 xid);
938
939
940
941
942
943
944
945int fc_elsct_init(struct fc_lport *lp);
946
947
948
949
950
951
952
953
954
955int fc_exch_init(struct fc_lport *lp);
956
957
958
959
960
961
962
963
964
965
966struct fc_exch_mgr_anchor *fc_exch_mgr_add(struct fc_lport *lport,
967 struct fc_exch_mgr *mp,
968 bool (*match)(struct fc_frame *));
969
970
971
972
973
974
975
976
977void fc_exch_mgr_del(struct fc_exch_mgr_anchor *ema);
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998struct fc_exch_mgr *fc_exch_mgr_alloc(struct fc_lport *lp,
999 enum fc_class class,
1000 u16 min_xid,
1001 u16 max_xid,
1002 bool (*match)(struct fc_frame *));
1003
1004
1005
1006
1007void fc_exch_mgr_free(struct fc_lport *lport);
1008
1009
1010
1011
1012void fc_exch_recv(struct fc_lport *lp, struct fc_frame *fp);
1013
1014
1015
1016
1017
1018
1019struct fc_seq *fc_exch_seq_send(struct fc_lport *lp,
1020 struct fc_frame *fp,
1021 void (*resp)(struct fc_seq *sp,
1022 struct fc_frame *fp,
1023 void *arg),
1024 void (*destructor)(struct fc_seq *sp,
1025 void *arg),
1026 void *arg, u32 timer_msec);
1027
1028
1029
1030
1031int fc_seq_send(struct fc_lport *lp, struct fc_seq *sp, struct fc_frame *fp);
1032
1033
1034
1035
1036
1037void fc_seq_els_rsp_send(struct fc_seq *sp, enum fc_els_cmd els_cmd,
1038 struct fc_seq_els_data *els_data);
1039
1040
1041
1042
1043
1044
1045int fc_seq_exch_abort(const struct fc_seq *req_sp, unsigned int timer_msec);
1046
1047
1048
1049
1050
1051void fc_exch_done(struct fc_seq *sp);
1052
1053
1054
1055
1056struct fc_exch *fc_exch_alloc(struct fc_lport *lport, struct fc_frame *fp);
1057
1058
1059
1060struct fc_seq *fc_seq_start_next(struct fc_seq *sp);
1061
1062
1063
1064
1065
1066
1067
1068
1069void fc_exch_mgr_reset(struct fc_lport *, u32 s_id, u32 d_id);
1070
1071
1072
1073
1074void fc_get_host_speed(struct Scsi_Host *shost);
1075void fc_get_host_port_type(struct Scsi_Host *shost);
1076void fc_get_host_port_state(struct Scsi_Host *shost);
1077void fc_set_rport_loss_tmo(struct fc_rport *rport, u32 timeout);
1078struct fc_host_statistics *fc_get_host_stats(struct Scsi_Host *);
1079
1080
1081
1082
1083int fc_setup_exch_mgr(void);
1084void fc_destroy_exch_mgr(void);
1085int fc_setup_rport(void);
1086void fc_destroy_rport(void);
1087
1088
1089
1090
1091const char *fc_els_resp_type(struct fc_frame *);
1092
1093#endif
1094