scsi_transport_fc.h 27 KB

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