scsi_transport_fc.h 26 KB

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