1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#ifndef SCSI_TRANSPORT_FC_H
28#define SCSI_TRANSPORT_FC_H
29
30#include <linux/sched.h>
31#include <linux/bsg-lib.h>
32#include <asm/unaligned.h>
33#include <scsi/scsi.h>
34#include <scsi/scsi_netlink.h>
35#include <scsi/scsi_host.h>
36
37struct scsi_transport_template;
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59enum fc_port_type {
60 FC_PORTTYPE_UNKNOWN,
61 FC_PORTTYPE_OTHER,
62 FC_PORTTYPE_NOTPRESENT,
63 FC_PORTTYPE_NPORT,
64 FC_PORTTYPE_NLPORT,
65 FC_PORTTYPE_LPORT,
66 FC_PORTTYPE_PTP,
67 FC_PORTTYPE_NPIV,
68};
69
70
71
72
73
74
75enum fc_port_state {
76 FC_PORTSTATE_UNKNOWN,
77 FC_PORTSTATE_NOTPRESENT,
78 FC_PORTSTATE_ONLINE,
79 FC_PORTSTATE_OFFLINE,
80 FC_PORTSTATE_BLOCKED,
81 FC_PORTSTATE_BYPASSED,
82 FC_PORTSTATE_DIAGNOSTICS,
83 FC_PORTSTATE_LINKDOWN,
84 FC_PORTSTATE_ERROR,
85 FC_PORTSTATE_LOOPBACK,
86 FC_PORTSTATE_DELETED,
87};
88
89
90
91
92
93
94enum fc_vport_state {
95 FC_VPORT_UNKNOWN,
96 FC_VPORT_ACTIVE,
97 FC_VPORT_DISABLED,
98 FC_VPORT_LINKDOWN,
99 FC_VPORT_INITIALIZING,
100 FC_VPORT_NO_FABRIC_SUPP,
101 FC_VPORT_NO_FABRIC_RSCS,
102 FC_VPORT_FABRIC_LOGOUT,
103 FC_VPORT_FABRIC_REJ_WWN,
104 FC_VPORT_FAILED,
105};
106
107
108
109
110
111
112
113
114
115#define FC_COS_UNSPECIFIED 0
116#define FC_COS_CLASS1 2
117#define FC_COS_CLASS2 4
118#define FC_COS_CLASS3 8
119#define FC_COS_CLASS4 0x10
120#define FC_COS_CLASS6 0x40
121
122
123
124
125
126
127
128#define FC_PORTSPEED_UNKNOWN 0
129
130#define FC_PORTSPEED_1GBIT 1
131#define FC_PORTSPEED_2GBIT 2
132#define FC_PORTSPEED_10GBIT 4
133#define FC_PORTSPEED_4GBIT 8
134#define FC_PORTSPEED_8GBIT 0x10
135#define FC_PORTSPEED_16GBIT 0x20
136#define FC_PORTSPEED_32GBIT 0x40
137#define FC_PORTSPEED_20GBIT 0x80
138#define FC_PORTSPEED_40GBIT 0x100
139#define FC_PORTSPEED_50GBIT 0x200
140#define FC_PORTSPEED_100GBIT 0x400
141#define FC_PORTSPEED_25GBIT 0x800
142#define FC_PORTSPEED_NOT_NEGOTIATED (1 << 15)
143
144
145
146
147
148enum fc_tgtid_binding_type {
149 FC_TGTID_BIND_NONE,
150 FC_TGTID_BIND_BY_WWPN,
151 FC_TGTID_BIND_BY_WWNN,
152 FC_TGTID_BIND_BY_ID,
153};
154
155
156
157
158
159
160
161#define FC_PORT_ROLE_UNKNOWN 0x00
162#define FC_PORT_ROLE_FCP_TARGET 0x01
163#define FC_PORT_ROLE_FCP_INITIATOR 0x02
164#define FC_PORT_ROLE_IP_PORT 0x04
165#define FC_PORT_ROLE_FCP_DUMMY_INITIATOR 0x08
166
167
168#define FC_RPORT_ROLE_UNKNOWN FC_PORT_ROLE_UNKNOWN
169#define FC_RPORT_ROLE_FCP_TARGET FC_PORT_ROLE_FCP_TARGET
170#define FC_RPORT_ROLE_FCP_INITIATOR FC_PORT_ROLE_FCP_INITIATOR
171#define FC_RPORT_ROLE_IP_PORT FC_PORT_ROLE_IP_PORT
172
173
174
175#define FC_VPORT_ATTR(_name,_mode,_show,_store) \
176struct device_attribute dev_attr_vport_##_name = \
177 __ATTR(_name,_mode,_show,_store)
178
179
180
181
182
183
184
185
186
187
188
189
190#define FC_VPORT_SYMBOLIC_NAMELEN 64
191struct fc_vport_identifiers {
192 u64 node_name;
193 u64 port_name;
194 u32 roles;
195 bool disable;
196 enum fc_port_type vport_type;
197 char symbolic_name[FC_VPORT_SYMBOLIC_NAMELEN];
198};
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229struct fc_vport {
230
231
232
233
234
235 enum fc_vport_state vport_state;
236 enum fc_vport_state vport_last_state;
237 u64 node_name;
238 u64 port_name;
239 u32 roles;
240 u32 vport_id;
241 enum fc_port_type vport_type;
242 char symbolic_name[FC_VPORT_SYMBOLIC_NAMELEN];
243
244
245 void *dd_data;
246
247
248 struct Scsi_Host *shost;
249 unsigned int channel;
250 u32 number;
251 u8 flags;
252 struct list_head peers;
253 struct device dev;
254 struct work_struct vport_delete_work;
255} __attribute__((aligned(sizeof(unsigned long))));
256
257
258#define FC_VPORT_CREATING 0x01
259#define FC_VPORT_DELETING 0x02
260#define FC_VPORT_DELETED 0x04
261#define FC_VPORT_DEL 0x06
262
263#define dev_to_vport(d) \
264 container_of(d, struct fc_vport, dev)
265#define transport_class_to_vport(dev) \
266 dev_to_vport(dev->parent)
267#define vport_to_shost(v) \
268 (v->shost)
269#define vport_to_shost_channel(v) \
270 (v->channel)
271#define vport_to_parent(v) \
272 (v->dev.parent)
273
274
275
276#define VPCERR_UNSUPPORTED -ENOSYS
277
278#define VPCERR_BAD_WWN -ENOTUNIQ
279
280#define VPCERR_NO_FABRIC_SUPP -EOPNOTSUPP
281
282
283
284
285
286
287
288
289
290
291
292struct fc_rport_identifiers {
293 u64 node_name;
294 u64 port_name;
295 u32 port_id;
296 u32 roles;
297};
298
299
300
301#define FC_RPORT_ATTR(_name,_mode,_show,_store) \
302struct device_attribute dev_attr_rport_##_name = \
303 __ATTR(_name,_mode,_show,_store)
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333struct fc_rport {
334
335 u32 maxframe_size;
336 u32 supported_classes;
337
338
339 u32 dev_loss_tmo;
340
341
342 u64 node_name;
343 u64 port_name;
344 u32 port_id;
345 u32 roles;
346 enum fc_port_state port_state;
347 u32 scsi_target_id;
348 u32 fast_io_fail_tmo;
349
350
351 void *dd_data;
352
353
354 unsigned int channel;
355 u32 number;
356 u8 flags;
357 struct list_head peers;
358 struct device dev;
359 struct delayed_work dev_loss_work;
360 struct work_struct scan_work;
361 struct delayed_work fail_io_work;
362 struct work_struct stgt_delete_work;
363 struct work_struct rport_delete_work;
364 struct request_queue *rqst_q;
365} __attribute__((aligned(sizeof(unsigned long))));
366
367
368#define FC_RPORT_DEVLOSS_PENDING 0x01
369#define FC_RPORT_SCAN_PENDING 0x02
370#define FC_RPORT_FAST_FAIL_TIMEDOUT 0x04
371#define FC_RPORT_DEVLOSS_CALLBK_DONE 0x08
372
373#define dev_to_rport(d) \
374 container_of(d, struct fc_rport, dev)
375#define transport_class_to_rport(dev) \
376 dev_to_rport(dev->parent)
377#define rport_to_shost(r) \
378 dev_to_shost(r->dev.parent)
379
380
381
382
383
384
385
386
387
388
389
390
391
392struct fc_starget_attrs {
393
394 u64 node_name;
395 u64 port_name;
396 u32 port_id;
397};
398
399#define fc_starget_node_name(x) \
400 (((struct fc_starget_attrs *)&(x)->starget_data)->node_name)
401#define fc_starget_port_name(x) \
402 (((struct fc_starget_attrs *)&(x)->starget_data)->port_name)
403#define fc_starget_port_id(x) \
404 (((struct fc_starget_attrs *)&(x)->starget_data)->port_id)
405
406#define starget_to_rport(s) \
407 scsi_is_fc_rport(s->dev.parent) ? dev_to_rport(s->dev.parent) : NULL
408
409
410
411
412
413
414
415struct fc_host_statistics {
416
417 u64 seconds_since_last_reset;
418 u64 tx_frames;
419 u64 tx_words;
420 u64 rx_frames;
421 u64 rx_words;
422 u64 lip_count;
423 u64 nos_count;
424 u64 error_frames;
425 u64 dumped_frames;
426 u64 link_failure_count;
427 u64 loss_of_sync_count;
428 u64 loss_of_signal_count;
429 u64 prim_seq_protocol_err_count;
430 u64 invalid_tx_word_count;
431 u64 invalid_crc_count;
432
433
434 u64 fcp_input_requests;
435 u64 fcp_output_requests;
436 u64 fcp_control_requests;
437 u64 fcp_input_megabytes;
438 u64 fcp_output_megabytes;
439 u64 fcp_packet_alloc_failures;
440 u64 fcp_packet_aborts;
441 u64 fcp_frame_alloc_failures;
442
443
444 u64 fc_no_free_exch;
445 u64 fc_no_free_exch_xid;
446 u64 fc_xid_not_found;
447 u64 fc_xid_busy;
448 u64 fc_seq_not_found;
449 u64 fc_non_bls_resp;
450
451};
452
453
454
455
456
457
458
459
460
461
462enum fc_host_event_code {
463 FCH_EVT_LIP = 0x1,
464 FCH_EVT_LINKUP = 0x2,
465 FCH_EVT_LINKDOWN = 0x3,
466 FCH_EVT_LIPRESET = 0x4,
467 FCH_EVT_RSCN = 0x5,
468 FCH_EVT_ADAPTER_CHANGE = 0x103,
469 FCH_EVT_PORT_UNKNOWN = 0x200,
470 FCH_EVT_PORT_OFFLINE = 0x201,
471 FCH_EVT_PORT_ONLINE = 0x202,
472 FCH_EVT_PORT_FABRIC = 0x204,
473 FCH_EVT_LINK_UNKNOWN = 0x500,
474 FCH_EVT_VENDOR_UNIQUE = 0xffff,
475};
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495#define FC_FC4_LIST_SIZE 32
496#define FC_SYMBOLIC_NAME_SIZE 256
497#define FC_VERSION_STRING_SIZE 64
498#define FC_SERIAL_NUMBER_SIZE 80
499
500struct fc_host_attrs {
501
502 u64 node_name;
503 u64 port_name;
504 u64 permanent_port_name;
505 u32 supported_classes;
506 u8 supported_fc4s[FC_FC4_LIST_SIZE];
507 u32 supported_speeds;
508 u32 maxframe_size;
509 u16 max_npiv_vports;
510 char serial_number[FC_SERIAL_NUMBER_SIZE];
511 char manufacturer[FC_SERIAL_NUMBER_SIZE];
512 char model[FC_SYMBOLIC_NAME_SIZE];
513 char model_description[FC_SYMBOLIC_NAME_SIZE];
514 char hardware_version[FC_VERSION_STRING_SIZE];
515 char driver_version[FC_VERSION_STRING_SIZE];
516 char firmware_version[FC_VERSION_STRING_SIZE];
517 char optionrom_version[FC_VERSION_STRING_SIZE];
518
519
520 u32 port_id;
521 enum fc_port_type port_type;
522 enum fc_port_state port_state;
523 u8 active_fc4s[FC_FC4_LIST_SIZE];
524 u32 speed;
525 u64 fabric_name;
526 char symbolic_name[FC_SYMBOLIC_NAME_SIZE];
527 char system_hostname[FC_SYMBOLIC_NAME_SIZE];
528 u32 dev_loss_tmo;
529
530
531 enum fc_tgtid_binding_type tgtid_bind_type;
532
533
534 struct list_head rports;
535 struct list_head rport_bindings;
536 struct list_head vports;
537 u32 next_rport_number;
538 u32 next_target_id;
539 u32 next_vport_number;
540 u16 npiv_vports_inuse;
541
542
543 char work_q_name[20];
544 struct workqueue_struct *work_q;
545 char devloss_work_q_name[20];
546 struct workqueue_struct *devloss_work_q;
547
548
549 struct request_queue *rqst_q;
550};
551
552#define shost_to_fc_host(x) \
553 ((struct fc_host_attrs *)(x)->shost_data)
554
555#define fc_host_node_name(x) \
556 (((struct fc_host_attrs *)(x)->shost_data)->node_name)
557#define fc_host_port_name(x) \
558 (((struct fc_host_attrs *)(x)->shost_data)->port_name)
559#define fc_host_permanent_port_name(x) \
560 (((struct fc_host_attrs *)(x)->shost_data)->permanent_port_name)
561#define fc_host_supported_classes(x) \
562 (((struct fc_host_attrs *)(x)->shost_data)->supported_classes)
563#define fc_host_supported_fc4s(x) \
564 (((struct fc_host_attrs *)(x)->shost_data)->supported_fc4s)
565#define fc_host_supported_speeds(x) \
566 (((struct fc_host_attrs *)(x)->shost_data)->supported_speeds)
567#define fc_host_maxframe_size(x) \
568 (((struct fc_host_attrs *)(x)->shost_data)->maxframe_size)
569#define fc_host_max_npiv_vports(x) \
570 (((struct fc_host_attrs *)(x)->shost_data)->max_npiv_vports)
571#define fc_host_serial_number(x) \
572 (((struct fc_host_attrs *)(x)->shost_data)->serial_number)
573#define fc_host_manufacturer(x) \
574 (((struct fc_host_attrs *)(x)->shost_data)->manufacturer)
575#define fc_host_model(x) \
576 (((struct fc_host_attrs *)(x)->shost_data)->model)
577#define fc_host_model_description(x) \
578 (((struct fc_host_attrs *)(x)->shost_data)->model_description)
579#define fc_host_hardware_version(x) \
580 (((struct fc_host_attrs *)(x)->shost_data)->hardware_version)
581#define fc_host_driver_version(x) \
582 (((struct fc_host_attrs *)(x)->shost_data)->driver_version)
583#define fc_host_firmware_version(x) \
584 (((struct fc_host_attrs *)(x)->shost_data)->firmware_version)
585#define fc_host_optionrom_version(x) \
586 (((struct fc_host_attrs *)(x)->shost_data)->optionrom_version)
587#define fc_host_port_id(x) \
588 (((struct fc_host_attrs *)(x)->shost_data)->port_id)
589#define fc_host_port_type(x) \
590 (((struct fc_host_attrs *)(x)->shost_data)->port_type)
591#define fc_host_port_state(x) \
592 (((struct fc_host_attrs *)(x)->shost_data)->port_state)
593#define fc_host_active_fc4s(x) \
594 (((struct fc_host_attrs *)(x)->shost_data)->active_fc4s)
595#define fc_host_speed(x) \
596 (((struct fc_host_attrs *)(x)->shost_data)->speed)
597#define fc_host_fabric_name(x) \
598 (((struct fc_host_attrs *)(x)->shost_data)->fabric_name)
599#define fc_host_symbolic_name(x) \
600 (((struct fc_host_attrs *)(x)->shost_data)->symbolic_name)
601#define fc_host_system_hostname(x) \
602 (((struct fc_host_attrs *)(x)->shost_data)->system_hostname)
603#define fc_host_tgtid_bind_type(x) \
604 (((struct fc_host_attrs *)(x)->shost_data)->tgtid_bind_type)
605#define fc_host_rports(x) \
606 (((struct fc_host_attrs *)(x)->shost_data)->rports)
607#define fc_host_rport_bindings(x) \
608 (((struct fc_host_attrs *)(x)->shost_data)->rport_bindings)
609#define fc_host_vports(x) \
610 (((struct fc_host_attrs *)(x)->shost_data)->vports)
611#define fc_host_next_rport_number(x) \
612 (((struct fc_host_attrs *)(x)->shost_data)->next_rport_number)
613#define fc_host_next_target_id(x) \
614 (((struct fc_host_attrs *)(x)->shost_data)->next_target_id)
615#define fc_host_next_vport_number(x) \
616 (((struct fc_host_attrs *)(x)->shost_data)->next_vport_number)
617#define fc_host_npiv_vports_inuse(x) \
618 (((struct fc_host_attrs *)(x)->shost_data)->npiv_vports_inuse)
619#define fc_host_work_q_name(x) \
620 (((struct fc_host_attrs *)(x)->shost_data)->work_q_name)
621#define fc_host_work_q(x) \
622 (((struct fc_host_attrs *)(x)->shost_data)->work_q)
623#define fc_host_devloss_work_q_name(x) \
624 (((struct fc_host_attrs *)(x)->shost_data)->devloss_work_q_name)
625#define fc_host_devloss_work_q(x) \
626 (((struct fc_host_attrs *)(x)->shost_data)->devloss_work_q)
627#define fc_host_dev_loss_tmo(x) \
628 (((struct fc_host_attrs *)(x)->shost_data)->dev_loss_tmo)
629
630
631struct fc_function_template {
632 void (*get_rport_dev_loss_tmo)(struct fc_rport *);
633 void (*set_rport_dev_loss_tmo)(struct fc_rport *, u32);
634
635 void (*get_starget_node_name)(struct scsi_target *);
636 void (*get_starget_port_name)(struct scsi_target *);
637 void (*get_starget_port_id)(struct scsi_target *);
638
639 void (*get_host_port_id)(struct Scsi_Host *);
640 void (*get_host_port_type)(struct Scsi_Host *);
641 void (*get_host_port_state)(struct Scsi_Host *);
642 void (*get_host_active_fc4s)(struct Scsi_Host *);
643 void (*get_host_speed)(struct Scsi_Host *);
644 void (*get_host_fabric_name)(struct Scsi_Host *);
645 void (*get_host_symbolic_name)(struct Scsi_Host *);
646 void (*set_host_system_hostname)(struct Scsi_Host *);
647
648 struct fc_host_statistics * (*get_fc_host_stats)(struct Scsi_Host *);
649 void (*reset_fc_host_stats)(struct Scsi_Host *);
650
651 int (*issue_fc_host_lip)(struct Scsi_Host *);
652
653 void (*dev_loss_tmo_callbk)(struct fc_rport *);
654 void (*terminate_rport_io)(struct fc_rport *);
655
656 void (*set_vport_symbolic_name)(struct fc_vport *);
657 int (*vport_create)(struct fc_vport *, bool);
658 int (*vport_disable)(struct fc_vport *, bool);
659 int (*vport_delete)(struct fc_vport *);
660
661
662 int (*bsg_request)(struct bsg_job *);
663 int (*bsg_timeout)(struct bsg_job *);
664
665
666 u32 dd_fcrport_size;
667 u32 dd_fcvport_size;
668 u32 dd_bsg_size;
669
670
671
672
673
674
675
676
677
678 unsigned long show_rport_maxframe_size:1;
679 unsigned long show_rport_supported_classes:1;
680 unsigned long show_rport_dev_loss_tmo:1;
681
682
683
684
685
686
687 unsigned long show_starget_node_name:1;
688 unsigned long show_starget_port_name:1;
689 unsigned long show_starget_port_id:1;
690
691
692 unsigned long show_host_node_name:1;
693 unsigned long show_host_port_name:1;
694 unsigned long show_host_permanent_port_name:1;
695 unsigned long show_host_supported_classes:1;
696 unsigned long show_host_supported_fc4s:1;
697 unsigned long show_host_supported_speeds:1;
698 unsigned long show_host_maxframe_size:1;
699 unsigned long show_host_serial_number:1;
700 unsigned long show_host_manufacturer:1;
701 unsigned long show_host_model:1;
702 unsigned long show_host_model_description:1;
703 unsigned long show_host_hardware_version:1;
704 unsigned long show_host_driver_version:1;
705 unsigned long show_host_firmware_version:1;
706 unsigned long show_host_optionrom_version:1;
707
708 unsigned long show_host_port_id:1;
709 unsigned long show_host_port_type:1;
710 unsigned long show_host_port_state:1;
711 unsigned long show_host_active_fc4s:1;
712 unsigned long show_host_speed:1;
713 unsigned long show_host_fabric_name:1;
714 unsigned long show_host_symbolic_name:1;
715 unsigned long show_host_system_hostname:1;
716
717 unsigned long disable_target_scan:1;
718};
719
720
721
722
723
724
725
726
727
728
729static inline int
730fc_remote_port_chkready(struct fc_rport *rport)
731{
732 int result;
733
734 switch (rport->port_state) {
735 case FC_PORTSTATE_ONLINE:
736 if (rport->roles & FC_PORT_ROLE_FCP_TARGET)
737 result = 0;
738 else if (rport->flags & FC_RPORT_DEVLOSS_PENDING)
739 result = DID_IMM_RETRY << 16;
740 else
741 result = DID_NO_CONNECT << 16;
742 break;
743 case FC_PORTSTATE_BLOCKED:
744 if (rport->flags & FC_RPORT_FAST_FAIL_TIMEDOUT)
745 result = DID_TRANSPORT_FAILFAST << 16;
746 else
747 result = DID_IMM_RETRY << 16;
748 break;
749 default:
750 result = DID_NO_CONNECT << 16;
751 break;
752 }
753 return result;
754}
755
756static inline u64 wwn_to_u64(u8 *wwn)
757{
758 return get_unaligned_be64(wwn);
759}
760
761static inline void u64_to_wwn(u64 inm, u8 *wwn)
762{
763 put_unaligned_be64(inm, wwn);
764}
765
766
767
768
769
770
771
772
773
774
775
776
777static inline void
778fc_vport_set_state(struct fc_vport *vport, enum fc_vport_state new_state)
779{
780 if ((new_state != FC_VPORT_UNKNOWN) &&
781 (new_state != FC_VPORT_INITIALIZING))
782 vport->vport_last_state = vport->vport_state;
783 vport->vport_state = new_state;
784}
785
786struct scsi_transport_template *fc_attach_transport(
787 struct fc_function_template *);
788void fc_release_transport(struct scsi_transport_template *);
789void fc_remove_host(struct Scsi_Host *);
790struct fc_rport *fc_remote_port_add(struct Scsi_Host *shost,
791 int channel, struct fc_rport_identifiers *ids);
792void fc_remote_port_delete(struct fc_rport *rport);
793void fc_remote_port_rolechg(struct fc_rport *rport, u32 roles);
794int scsi_is_fc_rport(const struct device *);
795u32 fc_get_event_number(void);
796void fc_host_post_event(struct Scsi_Host *shost, u32 event_number,
797 enum fc_host_event_code event_code, u32 event_data);
798void fc_host_post_vendor_event(struct Scsi_Host *shost, u32 event_number,
799 u32 data_len, char * data_buf, u64 vendor_id);
800
801
802
803
804struct fc_vport *fc_vport_create(struct Scsi_Host *shost, int channel,
805 struct fc_vport_identifiers *);
806int fc_vport_terminate(struct fc_vport *vport);
807int fc_block_scsi_eh(struct scsi_cmnd *cmnd);
808enum blk_eh_timer_return fc_eh_timed_out(struct scsi_cmnd *scmd);
809
810static inline struct Scsi_Host *fc_bsg_to_shost(struct bsg_job *job)
811{
812 if (scsi_is_host_device(job->dev))
813 return dev_to_shost(job->dev);
814 return rport_to_shost(dev_to_rport(job->dev));
815}
816
817static inline struct fc_rport *fc_bsg_to_rport(struct bsg_job *job)
818{
819 if (scsi_is_fc_rport(job->dev))
820 return dev_to_rport(job->dev);
821 return NULL;
822}
823
824#endif
825