scsi_transport_fc.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * FiberChannel transport specific attributes exported to sysfs.
  4. *
  5. * Copyright (c) 2003 Silicon Graphics, Inc. All rights reserved.
  6. * Copyright (C) 2004-2007 James Smart, Emulex Corporation
  7. * Rewrite for host, target, device, and remote port attributes,
  8. * statistics, and service functions...
  9. */
  10. #ifndef SCSI_TRANSPORT_FC_H
  11. #define SCSI_TRANSPORT_FC_H
  12. #include <linux/sched.h>
  13. #include <linux/bsg-lib.h>
  14. #include <linux/unaligned.h>
  15. #include <scsi/scsi.h>
  16. #include <scsi/scsi_netlink.h>
  17. #include <scsi/scsi_host.h>
  18. struct scsi_transport_template;
  19. /*
  20. * FC Port definitions - Following FC HBAAPI guidelines
  21. *
  22. * Note: Not all binary values for the different fields match HBAAPI.
  23. * Instead, we use densely packed ordinal values or enums.
  24. * We get away with this as we never present the actual binary values
  25. * externally. For sysfs, we always present the string that describes
  26. * the value. Thus, an admin doesn't need a magic HBAAPI decoder ring
  27. * to understand the values. The HBAAPI user-space library is free to
  28. * convert the strings into the HBAAPI-specified binary values.
  29. *
  30. * Note: Not all HBAAPI-defined values are contained in the definitions
  31. * below. Those not appropriate to an fc_host (e.g. FCP initiator) have
  32. * been removed.
  33. */
  34. /*
  35. * fc_port_type: If you alter this, you also need to alter scsi_transport_fc.c
  36. * (for the ascii descriptions).
  37. */
  38. enum fc_port_type {
  39. FC_PORTTYPE_UNKNOWN,
  40. FC_PORTTYPE_OTHER,
  41. FC_PORTTYPE_NOTPRESENT,
  42. FC_PORTTYPE_NPORT, /* Attached to FPort */
  43. FC_PORTTYPE_NLPORT, /* (Public) Loop w/ FLPort */
  44. FC_PORTTYPE_LPORT, /* (Private) Loop w/o FLPort */
  45. FC_PORTTYPE_PTP, /* Point to Point w/ another NPort */
  46. FC_PORTTYPE_NPIV, /* VPORT based on NPIV */
  47. };
  48. /*
  49. * fc_port_state: If you alter this, you also need to alter scsi_transport_fc.c
  50. * (for the ascii descriptions).
  51. */
  52. enum fc_port_state {
  53. FC_PORTSTATE_UNKNOWN,
  54. FC_PORTSTATE_NOTPRESENT,
  55. FC_PORTSTATE_ONLINE,
  56. FC_PORTSTATE_OFFLINE, /* User has taken Port Offline */
  57. FC_PORTSTATE_BLOCKED,
  58. FC_PORTSTATE_BYPASSED,
  59. FC_PORTSTATE_DIAGNOSTICS,
  60. FC_PORTSTATE_LINKDOWN,
  61. FC_PORTSTATE_ERROR,
  62. FC_PORTSTATE_LOOPBACK,
  63. FC_PORTSTATE_DELETED,
  64. FC_PORTSTATE_MARGINAL,
  65. };
  66. /*
  67. * fc_vport_state: If you alter this, you also need to alter
  68. * scsi_transport_fc.c (for the ascii descriptions).
  69. */
  70. enum fc_vport_state {
  71. FC_VPORT_UNKNOWN,
  72. FC_VPORT_ACTIVE,
  73. FC_VPORT_DISABLED,
  74. FC_VPORT_LINKDOWN,
  75. FC_VPORT_INITIALIZING,
  76. FC_VPORT_NO_FABRIC_SUPP,
  77. FC_VPORT_NO_FABRIC_RSCS,
  78. FC_VPORT_FABRIC_LOGOUT,
  79. FC_VPORT_FABRIC_REJ_WWN,
  80. FC_VPORT_FAILED,
  81. };
  82. /*
  83. * FC Classes of Service
  84. * Note: values are not enumerated, as they can be "or'd" together
  85. * for reporting (e.g. report supported_classes). If you alter this list,
  86. * you also need to alter scsi_transport_fc.c (for the ascii descriptions).
  87. */
  88. #define FC_COS_UNSPECIFIED 0
  89. #define FC_COS_CLASS1 2
  90. #define FC_COS_CLASS2 4
  91. #define FC_COS_CLASS3 8
  92. #define FC_COS_CLASS4 0x10
  93. #define FC_COS_CLASS6 0x40
  94. /*
  95. * FC Port Speeds
  96. * Note: values are not enumerated, as they can be "or'd" together
  97. * for reporting (e.g. report supported_speeds). If you alter this list,
  98. * you also need to alter scsi_transport_fc.c (for the ascii descriptions).
  99. */
  100. #define FC_PORTSPEED_UNKNOWN 0 /* Unknown - transceiver
  101. incapable of reporting */
  102. #define FC_PORTSPEED_1GBIT 1
  103. #define FC_PORTSPEED_2GBIT 2
  104. #define FC_PORTSPEED_10GBIT 4
  105. #define FC_PORTSPEED_4GBIT 8
  106. #define FC_PORTSPEED_8GBIT 0x10
  107. #define FC_PORTSPEED_16GBIT 0x20
  108. #define FC_PORTSPEED_32GBIT 0x40
  109. #define FC_PORTSPEED_20GBIT 0x80
  110. #define FC_PORTSPEED_40GBIT 0x100
  111. #define FC_PORTSPEED_50GBIT 0x200
  112. #define FC_PORTSPEED_100GBIT 0x400
  113. #define FC_PORTSPEED_25GBIT 0x800
  114. #define FC_PORTSPEED_64GBIT 0x1000
  115. #define FC_PORTSPEED_128GBIT 0x2000
  116. #define FC_PORTSPEED_256GBIT 0x4000
  117. #define FC_PORTSPEED_NOT_NEGOTIATED (1 << 15) /* Speed not established */
  118. /*
  119. * fc_tgtid_binding_type: If you alter this, you also need to alter
  120. * scsi_transport_fc.c (for the ascii descriptions).
  121. */
  122. enum fc_tgtid_binding_type {
  123. FC_TGTID_BIND_NONE,
  124. FC_TGTID_BIND_BY_WWPN,
  125. FC_TGTID_BIND_BY_WWNN,
  126. FC_TGTID_BIND_BY_ID,
  127. };
  128. /*
  129. * FC Port Roles
  130. * Note: values are not enumerated, as they can be "or'd" together
  131. * for reporting (e.g. report roles). If you alter this list,
  132. * you also need to alter scsi_transport_fc.c (for the ascii descriptions).
  133. */
  134. #define FC_PORT_ROLE_UNKNOWN 0x00
  135. #define FC_PORT_ROLE_FCP_TARGET 0x01
  136. #define FC_PORT_ROLE_FCP_INITIATOR 0x02
  137. #define FC_PORT_ROLE_IP_PORT 0x04
  138. #define FC_PORT_ROLE_FCP_DUMMY_INITIATOR 0x08
  139. #define FC_PORT_ROLE_NVME_INITIATOR 0x10
  140. #define FC_PORT_ROLE_NVME_TARGET 0x20
  141. #define FC_PORT_ROLE_NVME_DISCOVERY 0x40
  142. /* The following are for compatibility */
  143. #define FC_RPORT_ROLE_UNKNOWN FC_PORT_ROLE_UNKNOWN
  144. #define FC_RPORT_ROLE_FCP_TARGET FC_PORT_ROLE_FCP_TARGET
  145. #define FC_RPORT_ROLE_FCP_INITIATOR FC_PORT_ROLE_FCP_INITIATOR
  146. #define FC_RPORT_ROLE_IP_PORT FC_PORT_ROLE_IP_PORT
  147. /* Macro for use in defining Virtual Port attributes */
  148. #define FC_VPORT_ATTR(_name,_mode,_show,_store) \
  149. struct device_attribute dev_attr_vport_##_name = \
  150. __ATTR(_name,_mode,_show,_store)
  151. /*
  152. * fc_vport_identifiers: This set of data contains all elements
  153. * to uniquely identify and instantiate a FC virtual port.
  154. *
  155. * Notes:
  156. * symbolic_name: The driver is to append the symbolic_name string data
  157. * to the symbolic_node_name data that it generates by default.
  158. * the resulting combination should then be registered with the switch.
  159. * It is expected that things like Xen may stuff a VM title into
  160. * this field.
  161. */
  162. #define FC_VPORT_SYMBOLIC_NAMELEN 64
  163. struct fc_vport_identifiers {
  164. u64 node_name;
  165. u64 port_name;
  166. u32 roles;
  167. bool disable;
  168. enum fc_port_type vport_type; /* only FC_PORTTYPE_NPIV allowed */
  169. char symbolic_name[FC_VPORT_SYMBOLIC_NAMELEN];
  170. };
  171. /*
  172. * FC Virtual Port Attributes
  173. *
  174. * This structure exists for each FC port is a virtual FC port. Virtual
  175. * ports share the physical link with the Physical port. Each virtual
  176. * ports has a unique presence on the SAN, and may be instantiated via
  177. * NPIV, Virtual Fabrics, or via additional ALPAs. As the vport is a
  178. * unique presence, each vport has it's own view of the fabric,
  179. * authentication privilege, and priorities.
  180. *
  181. * A virtual port may support 1 or more FC4 roles. Typically it is a
  182. * FCP Initiator. It could be a FCP Target, or exist sole for an IP over FC
  183. * roles. FC port attributes for the vport will be reported on any
  184. * fc_host class object allocated for an FCP Initiator.
  185. *
  186. * --
  187. *
  188. * Fixed attributes are not expected to change. The driver is
  189. * expected to set these values after receiving the fc_vport structure
  190. * via the vport_create() call from the transport.
  191. * The transport fully manages all get functions w/o driver interaction.
  192. *
  193. * Dynamic attributes are expected to change. The driver participates
  194. * in all get/set operations via functions provided by the driver.
  195. *
  196. * Private attributes are transport-managed values. They are fully
  197. * managed by the transport w/o driver interaction.
  198. */
  199. struct fc_vport {
  200. /* Fixed Attributes */
  201. /* Dynamic Attributes */
  202. /* Private (Transport-managed) Attributes */
  203. enum fc_vport_state vport_state;
  204. enum fc_vport_state vport_last_state;
  205. u64 node_name;
  206. u64 port_name;
  207. u32 roles;
  208. u32 vport_id; /* Admin Identifier for the vport */
  209. enum fc_port_type vport_type;
  210. char symbolic_name[FC_VPORT_SYMBOLIC_NAMELEN];
  211. /* exported data */
  212. void *dd_data; /* Used for driver-specific storage */
  213. /* internal data */
  214. struct Scsi_Host *shost; /* Physical Port Parent */
  215. unsigned int channel;
  216. u32 number;
  217. u8 flags;
  218. struct list_head peers;
  219. struct device dev;
  220. struct work_struct vport_delete_work;
  221. } __attribute__((aligned(sizeof(unsigned long))));
  222. /* bit field values for struct fc_vport "flags" field: */
  223. #define FC_VPORT_CREATING 0x01
  224. #define FC_VPORT_DELETING 0x02
  225. #define FC_VPORT_DELETED 0x04
  226. #define FC_VPORT_DEL 0x06 /* Any DELETE state */
  227. #define dev_to_vport(d) \
  228. container_of(d, struct fc_vport, dev)
  229. #define transport_class_to_vport(dev) \
  230. dev_to_vport(dev->parent)
  231. #define vport_to_shost(v) \
  232. (v->shost)
  233. #define vport_to_shost_channel(v) \
  234. (v->channel)
  235. #define vport_to_parent(v) \
  236. (v->dev.parent)
  237. /* Error return codes for vport_create() callback */
  238. #define VPCERR_UNSUPPORTED -ENOSYS /* no driver/adapter
  239. support */
  240. #define VPCERR_BAD_WWN -ENOTUNIQ /* driver validation
  241. of WWNs failed */
  242. #define VPCERR_NO_FABRIC_SUPP -EOPNOTSUPP /* Fabric connection
  243. is loop or the
  244. Fabric Port does
  245. not support NPIV */
  246. /*
  247. * fc_rport_identifiers: This set of data contains all elements
  248. * to uniquely identify a remote FC port. The driver uses this data
  249. * to report the existence of a remote FC port in the topology. Internally,
  250. * the transport uses this data for attributes and to manage consistent
  251. * target id bindings.
  252. */
  253. struct fc_rport_identifiers {
  254. u64 node_name;
  255. u64 port_name;
  256. u32 port_id;
  257. u32 roles;
  258. };
  259. /*
  260. * Fabric Performance Impact Notification Statistics
  261. */
  262. struct fc_fpin_stats {
  263. /* Delivery */
  264. u64 dn;
  265. u64 dn_unknown;
  266. u64 dn_timeout;
  267. u64 dn_unable_to_route;
  268. u64 dn_device_specific;
  269. /* Link Integrity */
  270. u64 li;
  271. u64 li_failure_unknown;
  272. u64 li_link_failure_count;
  273. u64 li_loss_of_sync_count;
  274. u64 li_loss_of_signals_count;
  275. u64 li_prim_seq_err_count;
  276. u64 li_invalid_tx_word_count;
  277. u64 li_invalid_crc_count;
  278. u64 li_device_specific;
  279. /* Congestion/Peer Congestion */
  280. u64 cn;
  281. u64 cn_clear;
  282. u64 cn_lost_credit;
  283. u64 cn_credit_stall;
  284. u64 cn_oversubscription;
  285. u64 cn_device_specific;
  286. };
  287. #define FC_RPORT_ENCRYPTION_STATUS_MAX_LEN 14
  288. /*
  289. * Encryption Information
  290. */
  291. struct fc_encryption_info {
  292. /* Encryption Status */
  293. u8 status;
  294. };
  295. /* Macro for use in defining Remote Port attributes */
  296. #define FC_RPORT_ATTR(_name,_mode,_show,_store) \
  297. struct device_attribute dev_attr_rport_##_name = \
  298. __ATTR(_name,_mode,_show,_store)
  299. /*
  300. * FC Remote Port Attributes
  301. *
  302. * This structure exists for each remote FC port that a LLDD notifies
  303. * the subsystem of. A remote FC port may or may not be a SCSI Target,
  304. * also be a SCSI initiator, IP endpoint, etc. As such, the remote
  305. * port is considered a separate entity, independent of "role" (such
  306. * as scsi target).
  307. *
  308. * --
  309. *
  310. * Attributes are based on HBAAPI V2.0 definitions. Only those
  311. * attributes that are determinable by the local port (aka Host)
  312. * are contained.
  313. *
  314. * Fixed attributes are not expected to change. The driver is
  315. * expected to set these values after successfully calling
  316. * fc_remote_port_add(). The transport fully manages all get functions
  317. * w/o driver interaction.
  318. *
  319. * Dynamic attributes are expected to change. The driver participates
  320. * in all get/set operations via functions provided by the driver.
  321. *
  322. * Private attributes are transport-managed values. They are fully
  323. * managed by the transport w/o driver interaction.
  324. */
  325. struct fc_rport { /* aka fc_starget_attrs */
  326. /* Fixed Attributes */
  327. u32 maxframe_size;
  328. u32 supported_classes;
  329. /* Dynamic Attributes */
  330. u32 dev_loss_tmo; /* Remote Port loss timeout in seconds. */
  331. struct fc_fpin_stats fpin_stats;
  332. /* Private (Transport-managed) Attributes */
  333. u64 node_name;
  334. u64 port_name;
  335. u32 port_id;
  336. u32 roles;
  337. struct fc_encryption_info enc_info;
  338. enum fc_port_state port_state; /* Will only be ONLINE or UNKNOWN */
  339. u32 scsi_target_id;
  340. u32 fast_io_fail_tmo;
  341. /* exported data */
  342. void *dd_data; /* Used for driver-specific storage */
  343. /* internal data */
  344. unsigned int channel;
  345. u32 number;
  346. u8 flags;
  347. struct list_head peers;
  348. struct device dev;
  349. struct delayed_work dev_loss_work;
  350. struct work_struct scan_work;
  351. struct delayed_work fail_io_work;
  352. struct work_struct stgt_delete_work;
  353. struct work_struct rport_delete_work;
  354. struct request_queue *rqst_q; /* bsg support */
  355. struct workqueue_struct *devloss_work_q;
  356. } __attribute__((aligned(sizeof(unsigned long))));
  357. /* bit field values for struct fc_rport "flags" field: */
  358. #define FC_RPORT_DEVLOSS_PENDING 0x01
  359. #define FC_RPORT_SCAN_PENDING 0x02
  360. #define FC_RPORT_FAST_FAIL_TIMEDOUT 0x04
  361. #define FC_RPORT_DEVLOSS_CALLBK_DONE 0x08
  362. #define dev_to_rport(d) \
  363. container_of(d, struct fc_rport, dev)
  364. #define transport_class_to_rport(dev) \
  365. dev_to_rport(dev->parent)
  366. #define rport_to_shost(r) \
  367. dev_to_shost(r->dev.parent)
  368. /*
  369. * FC SCSI Target Attributes
  370. *
  371. * The SCSI Target is considered an extension of a remote port (as
  372. * a remote port can be more than a SCSI Target). Within the scsi
  373. * subsystem, we leave the Target as a separate entity. Doing so
  374. * provides backward compatibility with prior FC transport api's,
  375. * and lets remote ports be handled entirely within the FC transport
  376. * and independently from the scsi subsystem. The drawback is that
  377. * some data will be duplicated.
  378. */
  379. struct fc_starget_attrs { /* aka fc_target_attrs */
  380. /* Dynamic Attributes */
  381. u64 node_name;
  382. u64 port_name;
  383. u32 port_id;
  384. };
  385. #define fc_starget_node_name(x) \
  386. (((struct fc_starget_attrs *)&(x)->starget_data)->node_name)
  387. #define fc_starget_port_name(x) \
  388. (((struct fc_starget_attrs *)&(x)->starget_data)->port_name)
  389. #define fc_starget_port_id(x) \
  390. (((struct fc_starget_attrs *)&(x)->starget_data)->port_id)
  391. #define starget_to_rport(s) \
  392. scsi_is_fc_rport(s->dev.parent) ? dev_to_rport(s->dev.parent) : NULL
  393. /*
  394. * FC Local Port (Host) Statistics
  395. */
  396. /* FC Statistics - Following FC HBAAPI v2.0 guidelines */
  397. struct fc_host_statistics {
  398. /* port statistics */
  399. u64 seconds_since_last_reset;
  400. u64 tx_frames;
  401. u64 tx_words;
  402. u64 rx_frames;
  403. u64 rx_words;
  404. u64 lip_count;
  405. u64 nos_count;
  406. u64 error_frames;
  407. u64 dumped_frames;
  408. u64 link_failure_count;
  409. u64 loss_of_sync_count;
  410. u64 loss_of_signal_count;
  411. u64 prim_seq_protocol_err_count;
  412. u64 invalid_tx_word_count;
  413. u64 invalid_crc_count;
  414. /* fc4 statistics (only FCP supported currently) */
  415. u64 fcp_input_requests;
  416. u64 fcp_output_requests;
  417. u64 fcp_control_requests;
  418. u64 fcp_input_megabytes;
  419. u64 fcp_output_megabytes;
  420. u64 fcp_packet_alloc_failures; /* fcp packet allocation failures */
  421. u64 fcp_packet_aborts; /* fcp packet aborted */
  422. u64 fcp_frame_alloc_failures; /* fcp frame allocation failures */
  423. /* fc exches statistics */
  424. u64 fc_no_free_exch; /* no free exch memory */
  425. u64 fc_no_free_exch_xid; /* no free exch id */
  426. u64 fc_xid_not_found; /* exch not found for a response */
  427. u64 fc_xid_busy; /* exch exist for new a request */
  428. u64 fc_seq_not_found; /* seq is not found for exchange */
  429. u64 fc_non_bls_resp; /* a non BLS response frame with
  430. a sequence responder in new exch */
  431. /* Host Congestion Signals */
  432. u64 cn_sig_warn;
  433. u64 cn_sig_alarm;
  434. };
  435. /*
  436. * FC Event Codes - Polled and Async, following FC HBAAPI v2.0 guidelines
  437. */
  438. /*
  439. * fc_host_event_code: If you alter this, you also need to alter
  440. * scsi_transport_fc.c (for the ascii descriptions).
  441. */
  442. enum fc_host_event_code {
  443. FCH_EVT_LIP = 0x1,
  444. FCH_EVT_LINKUP = 0x2,
  445. FCH_EVT_LINKDOWN = 0x3,
  446. FCH_EVT_LIPRESET = 0x4,
  447. FCH_EVT_RSCN = 0x5,
  448. FCH_EVT_ADAPTER_CHANGE = 0x103,
  449. FCH_EVT_PORT_UNKNOWN = 0x200,
  450. FCH_EVT_PORT_OFFLINE = 0x201,
  451. FCH_EVT_PORT_ONLINE = 0x202,
  452. FCH_EVT_PORT_FABRIC = 0x204,
  453. FCH_EVT_LINK_UNKNOWN = 0x500,
  454. FCH_EVT_LINK_FPIN = 0x501,
  455. FCH_EVT_LINK_FPIN_ACK = 0x502,
  456. FCH_EVT_VENDOR_UNIQUE = 0xffff,
  457. };
  458. /*
  459. * FC Local Port (Host) Attributes
  460. *
  461. * Attributes are based on HBAAPI V2.0 definitions.
  462. * Note: OSDeviceName is determined by user-space library
  463. *
  464. * Fixed attributes are not expected to change. The driver is
  465. * expected to set these values after successfully calling scsi_add_host().
  466. * The transport fully manages all get functions w/o driver interaction.
  467. *
  468. * Dynamic attributes are expected to change. The driver participates
  469. * in all get/set operations via functions provided by the driver.
  470. *
  471. * Private attributes are transport-managed values. They are fully
  472. * managed by the transport w/o driver interaction.
  473. */
  474. #define FC_VENDOR_IDENTIFIER 8
  475. #define FC_FC4_LIST_SIZE 32
  476. #define FC_SYMBOLIC_NAME_SIZE 256
  477. #define FC_VERSION_STRING_SIZE 64
  478. #define FC_SERIAL_NUMBER_SIZE 64
  479. struct fc_host_attrs {
  480. /* Fixed Attributes */
  481. u64 node_name;
  482. u64 port_name;
  483. u64 permanent_port_name;
  484. u32 supported_classes;
  485. u8 supported_fc4s[FC_FC4_LIST_SIZE];
  486. u32 supported_speeds;
  487. u32 maxframe_size;
  488. u16 max_npiv_vports;
  489. u32 max_ct_payload;
  490. u32 num_ports;
  491. u32 num_discovered_ports;
  492. u32 bootbios_state;
  493. char serial_number[FC_SERIAL_NUMBER_SIZE];
  494. char manufacturer[FC_SERIAL_NUMBER_SIZE];
  495. char model[FC_SYMBOLIC_NAME_SIZE];
  496. char model_description[FC_SYMBOLIC_NAME_SIZE];
  497. char hardware_version[FC_VERSION_STRING_SIZE];
  498. char driver_version[FC_VERSION_STRING_SIZE];
  499. char firmware_version[FC_VERSION_STRING_SIZE];
  500. char optionrom_version[FC_VERSION_STRING_SIZE];
  501. char vendor_identifier[FC_VENDOR_IDENTIFIER];
  502. char bootbios_version[FC_SYMBOLIC_NAME_SIZE];
  503. /* Dynamic Attributes */
  504. u32 port_id;
  505. enum fc_port_type port_type;
  506. enum fc_port_state port_state;
  507. u8 active_fc4s[FC_FC4_LIST_SIZE];
  508. u32 speed;
  509. u64 fabric_name;
  510. char symbolic_name[FC_SYMBOLIC_NAME_SIZE];
  511. char system_hostname[FC_SYMBOLIC_NAME_SIZE];
  512. u32 dev_loss_tmo;
  513. struct fc_fpin_stats fpin_stats;
  514. /* Private (Transport-managed) Attributes */
  515. enum fc_tgtid_binding_type tgtid_bind_type;
  516. /* internal data */
  517. struct list_head rports;
  518. struct list_head rport_bindings;
  519. struct list_head vports;
  520. u32 next_rport_number;
  521. u32 next_target_id;
  522. u32 next_vport_number;
  523. u16 npiv_vports_inuse;
  524. /* work queues for rport state manipulation */
  525. struct workqueue_struct *work_q;
  526. /* bsg support */
  527. struct request_queue *rqst_q;
  528. /* FDMI support version*/
  529. u8 fdmi_version;
  530. };
  531. #define shost_to_fc_host(x) \
  532. ((struct fc_host_attrs *)(x)->shost_data)
  533. #define fc_host_node_name(x) \
  534. (((struct fc_host_attrs *)(x)->shost_data)->node_name)
  535. #define fc_host_port_name(x) \
  536. (((struct fc_host_attrs *)(x)->shost_data)->port_name)
  537. #define fc_host_permanent_port_name(x) \
  538. (((struct fc_host_attrs *)(x)->shost_data)->permanent_port_name)
  539. #define fc_host_supported_classes(x) \
  540. (((struct fc_host_attrs *)(x)->shost_data)->supported_classes)
  541. #define fc_host_supported_fc4s(x) \
  542. (((struct fc_host_attrs *)(x)->shost_data)->supported_fc4s)
  543. #define fc_host_supported_speeds(x) \
  544. (((struct fc_host_attrs *)(x)->shost_data)->supported_speeds)
  545. #define fc_host_maxframe_size(x) \
  546. (((struct fc_host_attrs *)(x)->shost_data)->maxframe_size)
  547. #define fc_host_max_npiv_vports(x) \
  548. (((struct fc_host_attrs *)(x)->shost_data)->max_npiv_vports)
  549. #define fc_host_serial_number(x) \
  550. (((struct fc_host_attrs *)(x)->shost_data)->serial_number)
  551. #define fc_host_manufacturer(x) \
  552. (((struct fc_host_attrs *)(x)->shost_data)->manufacturer)
  553. #define fc_host_model(x) \
  554. (((struct fc_host_attrs *)(x)->shost_data)->model)
  555. #define fc_host_model_description(x) \
  556. (((struct fc_host_attrs *)(x)->shost_data)->model_description)
  557. #define fc_host_hardware_version(x) \
  558. (((struct fc_host_attrs *)(x)->shost_data)->hardware_version)
  559. #define fc_host_driver_version(x) \
  560. (((struct fc_host_attrs *)(x)->shost_data)->driver_version)
  561. #define fc_host_firmware_version(x) \
  562. (((struct fc_host_attrs *)(x)->shost_data)->firmware_version)
  563. #define fc_host_optionrom_version(x) \
  564. (((struct fc_host_attrs *)(x)->shost_data)->optionrom_version)
  565. #define fc_host_port_id(x) \
  566. (((struct fc_host_attrs *)(x)->shost_data)->port_id)
  567. #define fc_host_port_type(x) \
  568. (((struct fc_host_attrs *)(x)->shost_data)->port_type)
  569. #define fc_host_port_state(x) \
  570. (((struct fc_host_attrs *)(x)->shost_data)->port_state)
  571. #define fc_host_active_fc4s(x) \
  572. (((struct fc_host_attrs *)(x)->shost_data)->active_fc4s)
  573. #define fc_host_speed(x) \
  574. (((struct fc_host_attrs *)(x)->shost_data)->speed)
  575. #define fc_host_fabric_name(x) \
  576. (((struct fc_host_attrs *)(x)->shost_data)->fabric_name)
  577. #define fc_host_symbolic_name(x) \
  578. (((struct fc_host_attrs *)(x)->shost_data)->symbolic_name)
  579. #define fc_host_system_hostname(x) \
  580. (((struct fc_host_attrs *)(x)->shost_data)->system_hostname)
  581. #define fc_host_tgtid_bind_type(x) \
  582. (((struct fc_host_attrs *)(x)->shost_data)->tgtid_bind_type)
  583. #define fc_host_rports(x) \
  584. (((struct fc_host_attrs *)(x)->shost_data)->rports)
  585. #define fc_host_rport_bindings(x) \
  586. (((struct fc_host_attrs *)(x)->shost_data)->rport_bindings)
  587. #define fc_host_vports(x) \
  588. (((struct fc_host_attrs *)(x)->shost_data)->vports)
  589. #define fc_host_next_rport_number(x) \
  590. (((struct fc_host_attrs *)(x)->shost_data)->next_rport_number)
  591. #define fc_host_next_target_id(x) \
  592. (((struct fc_host_attrs *)(x)->shost_data)->next_target_id)
  593. #define fc_host_next_vport_number(x) \
  594. (((struct fc_host_attrs *)(x)->shost_data)->next_vport_number)
  595. #define fc_host_npiv_vports_inuse(x) \
  596. (((struct fc_host_attrs *)(x)->shost_data)->npiv_vports_inuse)
  597. #define fc_host_work_q(x) \
  598. (((struct fc_host_attrs *)(x)->shost_data)->work_q)
  599. #define fc_host_dev_loss_tmo(x) \
  600. (((struct fc_host_attrs *)(x)->shost_data)->dev_loss_tmo)
  601. #define fc_host_max_ct_payload(x) \
  602. (((struct fc_host_attrs *)(x)->shost_data)->max_ct_payload)
  603. #define fc_host_vendor_identifier(x) \
  604. (((struct fc_host_attrs *)(x)->shost_data)->vendor_identifier)
  605. #define fc_host_num_discovered_ports(x) \
  606. (((struct fc_host_attrs *)(x)->shost_data)->num_discovered_ports)
  607. #define fc_host_num_ports(x) \
  608. (((struct fc_host_attrs *)(x)->shost_data)->num_ports)
  609. #define fc_host_bootbios_version(x) \
  610. (((struct fc_host_attrs *)(x)->shost_data)->bootbios_version)
  611. #define fc_host_bootbios_state(x) \
  612. (((struct fc_host_attrs *)(x)->shost_data)->bootbios_state)
  613. /* The functions by which the transport class and the driver communicate */
  614. struct fc_function_template {
  615. void (*get_rport_dev_loss_tmo)(struct fc_rport *);
  616. void (*set_rport_dev_loss_tmo)(struct fc_rport *, u32);
  617. void (*get_starget_node_name)(struct scsi_target *);
  618. void (*get_starget_port_name)(struct scsi_target *);
  619. void (*get_starget_port_id)(struct scsi_target *);
  620. void (*get_host_port_id)(struct Scsi_Host *);
  621. void (*get_host_port_type)(struct Scsi_Host *);
  622. void (*get_host_port_state)(struct Scsi_Host *);
  623. void (*get_host_active_fc4s)(struct Scsi_Host *);
  624. void (*get_host_speed)(struct Scsi_Host *);
  625. void (*get_host_fabric_name)(struct Scsi_Host *);
  626. void (*get_host_symbolic_name)(struct Scsi_Host *);
  627. void (*set_host_system_hostname)(struct Scsi_Host *);
  628. struct fc_host_statistics * (*get_fc_host_stats)(struct Scsi_Host *);
  629. void (*reset_fc_host_stats)(struct Scsi_Host *);
  630. struct fc_encryption_info * (*get_fc_rport_enc_info)(struct fc_rport *);
  631. int (*issue_fc_host_lip)(struct Scsi_Host *);
  632. void (*dev_loss_tmo_callbk)(struct fc_rport *);
  633. void (*terminate_rport_io)(struct fc_rport *);
  634. void (*set_vport_symbolic_name)(struct fc_vport *);
  635. int (*vport_create)(struct fc_vport *, bool);
  636. int (*vport_disable)(struct fc_vport *, bool);
  637. int (*vport_delete)(struct fc_vport *);
  638. /* bsg support */
  639. u32 max_bsg_segments;
  640. int (*bsg_request)(struct bsg_job *);
  641. int (*bsg_timeout)(struct bsg_job *);
  642. /* allocation lengths for host-specific data */
  643. u32 dd_fcrport_size;
  644. u32 dd_fcvport_size;
  645. u32 dd_bsg_size;
  646. /*
  647. * The driver sets these to tell the transport class it
  648. * wants the attributes displayed in sysfs. If the show_ flag
  649. * is not set, the attribute will be private to the transport
  650. * class
  651. */
  652. /* remote port fixed attributes */
  653. unsigned long show_rport_maxframe_size:1;
  654. unsigned long show_rport_supported_classes:1;
  655. unsigned long show_rport_dev_loss_tmo:1;
  656. /*
  657. * target dynamic attributes
  658. * These should all be "1" if the driver uses the remote port
  659. * add/delete functions (so attributes reflect rport values).
  660. */
  661. unsigned long show_starget_node_name:1;
  662. unsigned long show_starget_port_name:1;
  663. unsigned long show_starget_port_id:1;
  664. /* host fixed attributes */
  665. unsigned long show_host_node_name:1;
  666. unsigned long show_host_port_name:1;
  667. unsigned long show_host_permanent_port_name:1;
  668. unsigned long show_host_supported_classes:1;
  669. unsigned long show_host_supported_fc4s:1;
  670. unsigned long show_host_supported_speeds:1;
  671. unsigned long show_host_maxframe_size:1;
  672. unsigned long show_host_serial_number:1;
  673. unsigned long show_host_manufacturer:1;
  674. unsigned long show_host_model:1;
  675. unsigned long show_host_model_description:1;
  676. unsigned long show_host_hardware_version:1;
  677. unsigned long show_host_driver_version:1;
  678. unsigned long show_host_firmware_version:1;
  679. unsigned long show_host_optionrom_version:1;
  680. /* host dynamic attributes */
  681. unsigned long show_host_port_id:1;
  682. unsigned long show_host_port_type:1;
  683. unsigned long show_host_port_state:1;
  684. unsigned long show_host_active_fc4s:1;
  685. unsigned long show_host_speed:1;
  686. unsigned long show_host_fabric_name:1;
  687. unsigned long show_host_symbolic_name:1;
  688. unsigned long show_host_system_hostname:1;
  689. unsigned long disable_target_scan:1;
  690. };
  691. /**
  692. * fc_remote_port_chkready - called to validate the remote port state
  693. * prior to initiating io to the port.
  694. * @rport: remote port to be checked
  695. *
  696. * Returns: a scsi result code that can be returned by the LLDD.
  697. **/
  698. static inline int
  699. fc_remote_port_chkready(struct fc_rport *rport)
  700. {
  701. int result;
  702. switch (rport->port_state) {
  703. case FC_PORTSTATE_ONLINE:
  704. case FC_PORTSTATE_MARGINAL:
  705. if (rport->roles & FC_PORT_ROLE_FCP_TARGET)
  706. result = 0;
  707. else if (rport->flags & FC_RPORT_DEVLOSS_PENDING)
  708. result = DID_IMM_RETRY << 16;
  709. else
  710. result = DID_NO_CONNECT << 16;
  711. break;
  712. case FC_PORTSTATE_BLOCKED:
  713. if (rport->flags & FC_RPORT_FAST_FAIL_TIMEDOUT)
  714. result = DID_TRANSPORT_FAILFAST << 16;
  715. else
  716. result = DID_IMM_RETRY << 16;
  717. break;
  718. default:
  719. result = DID_NO_CONNECT << 16;
  720. break;
  721. }
  722. return result;
  723. }
  724. static inline u64 wwn_to_u64(const u8 *wwn)
  725. {
  726. return get_unaligned_be64(wwn);
  727. }
  728. static inline void u64_to_wwn(u64 inm, u8 *wwn)
  729. {
  730. put_unaligned_be64(inm, wwn);
  731. }
  732. /**
  733. * fc_vport_set_state() - called to set a vport's state. Saves the old state,
  734. * excepting the transitory states of initializing and sending the ELS
  735. * traffic to instantiate the vport on the link.
  736. *
  737. * Assumes the driver has surrounded this with the proper locking to ensure
  738. * a coherent state change.
  739. *
  740. * @vport: virtual port whose state is changing
  741. * @new_state: new state
  742. **/
  743. static inline void
  744. fc_vport_set_state(struct fc_vport *vport, enum fc_vport_state new_state)
  745. {
  746. if ((new_state != FC_VPORT_UNKNOWN) &&
  747. (new_state != FC_VPORT_INITIALIZING))
  748. vport->vport_last_state = vport->vport_state;
  749. vport->vport_state = new_state;
  750. }
  751. struct scsi_transport_template *fc_attach_transport(
  752. struct fc_function_template *);
  753. void fc_release_transport(struct scsi_transport_template *);
  754. void fc_remove_host(struct Scsi_Host *);
  755. struct fc_rport *fc_remote_port_add(struct Scsi_Host *shost,
  756. int channel, struct fc_rport_identifiers *ids);
  757. void fc_remote_port_delete(struct fc_rport *rport);
  758. void fc_remote_port_rolechg(struct fc_rport *rport, u32 roles);
  759. int scsi_is_fc_rport(const struct device *);
  760. u32 fc_get_event_number(void);
  761. void fc_host_post_event(struct Scsi_Host *shost, u32 event_number,
  762. enum fc_host_event_code event_code, u32 event_data);
  763. void fc_host_post_vendor_event(struct Scsi_Host *shost, u32 event_number,
  764. u32 data_len, char *data_buf, u64 vendor_id);
  765. struct fc_rport *fc_find_rport_by_wwpn(struct Scsi_Host *shost, u64 wwpn);
  766. void fc_host_post_fc_event(struct Scsi_Host *shost, u32 event_number,
  767. enum fc_host_event_code event_code,
  768. u32 data_len, char *data_buf, u64 vendor_id);
  769. /* Note: when specifying vendor_id to fc_host_post_vendor_event()
  770. * or fc_host_post_fc_event(), be sure to read the Vendor Type
  771. * and ID formatting requirements specified in scsi_netlink.h
  772. * Note: when calling fc_host_post_fc_event(), vendor_id may be
  773. * specified as 0.
  774. */
  775. void fc_host_fpin_rcv(struct Scsi_Host *shost, u32 fpin_len, char *fpin_buf,
  776. u8 event_acknowledge);
  777. struct fc_vport *fc_vport_create(struct Scsi_Host *shost, int channel,
  778. struct fc_vport_identifiers *);
  779. int fc_vport_terminate(struct fc_vport *vport);
  780. int fc_block_rport(struct fc_rport *rport);
  781. int fc_block_scsi_eh(struct scsi_cmnd *cmnd);
  782. enum scsi_timeout_action fc_eh_timed_out(struct scsi_cmnd *scmd);
  783. bool fc_eh_should_retry_cmd(struct scsi_cmnd *scmd);
  784. static inline struct Scsi_Host *fc_bsg_to_shost(struct bsg_job *job)
  785. {
  786. if (scsi_is_host_device(job->dev))
  787. return dev_to_shost(job->dev);
  788. return rport_to_shost(dev_to_rport(job->dev));
  789. }
  790. static inline struct fc_rport *fc_bsg_to_rport(struct bsg_job *job)
  791. {
  792. if (scsi_is_fc_rport(job->dev))
  793. return dev_to_rport(job->dev);
  794. return NULL;
  795. }
  796. #endif /* SCSI_TRANSPORT_FC_H */