scsi_transport_fc.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  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-2005 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/config.h>
  30. #include <linux/sched.h>
  31. #include <scsi/scsi.h>
  32. struct scsi_transport_template;
  33. /*
  34. * FC Port definitions - Following FC HBAAPI guidelines
  35. *
  36. * Note: Not all binary values for the different fields match HBAAPI.
  37. * Instead, we use densely packed ordinal values or enums.
  38. * We get away with this as we never present the actual binary values
  39. * externally. For sysfs, we always present the string that describes
  40. * the value. Thus, an admin doesn't need a magic HBAAPI decoder ring
  41. * to understand the values. The HBAAPI user-space library is free to
  42. * convert the strings into the HBAAPI-specified binary values.
  43. *
  44. * Note: Not all HBAAPI-defined values are contained in the definitions
  45. * below. Those not appropriate to an fc_host (e.g. FCP initiator) have
  46. * been removed.
  47. */
  48. /*
  49. * fc_port_type: If you alter this, you also need to alter scsi_transport_fc.c
  50. * (for the ascii descriptions).
  51. */
  52. enum fc_port_type {
  53. FC_PORTTYPE_UNKNOWN,
  54. FC_PORTTYPE_OTHER,
  55. FC_PORTTYPE_NOTPRESENT,
  56. FC_PORTTYPE_NPORT, /* Attached to FPort */
  57. FC_PORTTYPE_NLPORT, /* (Public) Loop w/ FLPort */
  58. FC_PORTTYPE_LPORT, /* (Private) Loop w/o FLPort */
  59. FC_PORTTYPE_PTP, /* Point to Point w/ another NPort */
  60. };
  61. /*
  62. * fc_port_state: If you alter this, you also need to alter scsi_transport_fc.c
  63. * (for the ascii descriptions).
  64. */
  65. enum fc_port_state {
  66. FC_PORTSTATE_UNKNOWN,
  67. FC_PORTSTATE_NOTPRESENT,
  68. FC_PORTSTATE_ONLINE,
  69. FC_PORTSTATE_OFFLINE, /* User has taken Port Offline */
  70. FC_PORTSTATE_BLOCKED,
  71. FC_PORTSTATE_BYPASSED,
  72. FC_PORTSTATE_DIAGNOSTICS,
  73. FC_PORTSTATE_LINKDOWN,
  74. FC_PORTSTATE_ERROR,
  75. FC_PORTSTATE_LOOPBACK,
  76. };
  77. /*
  78. * FC Classes of Service
  79. * Note: values are not enumerated, as they can be "or'd" together
  80. * for reporting (e.g. report supported_classes). If you alter this list,
  81. * you also need to alter scsi_transport_fc.c (for the ascii descriptions).
  82. */
  83. #define FC_COS_UNSPECIFIED 0
  84. #define FC_COS_CLASS1 2
  85. #define FC_COS_CLASS2 4
  86. #define FC_COS_CLASS3 8
  87. #define FC_COS_CLASS4 0x10
  88. #define FC_COS_CLASS6 0x40
  89. /*
  90. * FC Port Speeds
  91. * Note: values are not enumerated, as they can be "or'd" together
  92. * for reporting (e.g. report supported_speeds). If you alter this list,
  93. * you also need to alter scsi_transport_fc.c (for the ascii descriptions).
  94. */
  95. #define FC_PORTSPEED_UNKNOWN 0 /* Unknown - transceiver
  96. incapable of reporting */
  97. #define FC_PORTSPEED_1GBIT 1
  98. #define FC_PORTSPEED_2GBIT 2
  99. #define FC_PORTSPEED_4GBIT 4
  100. #define FC_PORTSPEED_10GBIT 8
  101. #define FC_PORTSPEED_NOT_NEGOTIATED (1 << 15) /* Speed not established */
  102. /*
  103. * fc_tgtid_binding_type: If you alter this, you also need to alter
  104. * scsi_transport_fc.c (for the ascii descriptions).
  105. */
  106. enum fc_tgtid_binding_type {
  107. FC_TGTID_BIND_NONE,
  108. FC_TGTID_BIND_BY_WWPN,
  109. FC_TGTID_BIND_BY_WWNN,
  110. FC_TGTID_BIND_BY_ID,
  111. };
  112. /*
  113. * FC Remote Port Roles
  114. * Note: values are not enumerated, as they can be "or'd" together
  115. * for reporting (e.g. report roles). If you alter this list,
  116. * you also need to alter scsi_transport_fc.c (for the ascii descriptions).
  117. */
  118. #define FC_RPORT_ROLE_UNKNOWN 0x00
  119. #define FC_RPORT_ROLE_FCP_TARGET 0x01
  120. #define FC_RPORT_ROLE_FCP_INITIATOR 0x02
  121. #define FC_RPORT_ROLE_IP_PORT 0x04
  122. /*
  123. * fc_rport_identifiers: This set of data contains all elements
  124. * to uniquely identify a remote FC port. The driver uses this data
  125. * to report the existence of a remote FC port in the topology. Internally,
  126. * the transport uses this data for attributes and to manage consistent
  127. * target id bindings.
  128. */
  129. struct fc_rport_identifiers {
  130. u64 node_name;
  131. u64 port_name;
  132. u32 port_id;
  133. u32 roles;
  134. };
  135. /* Macro for use in defining Remote Port attributes */
  136. #define FC_RPORT_ATTR(_name,_mode,_show,_store) \
  137. struct class_device_attribute class_device_attr_rport_##_name = \
  138. __ATTR(_name,_mode,_show,_store)
  139. /*
  140. * FC Remote Port Attributes
  141. *
  142. * This structure exists for each remote FC port that a LLDD notifies
  143. * the subsystem of. A remote FC port may or may not be a SCSI Target,
  144. * also be a SCSI initiator, IP endpoint, etc. As such, the remote
  145. * port is considered a separate entity, independent of "role" (such
  146. * as scsi target).
  147. *
  148. * --
  149. *
  150. * Attributes are based on HBAAPI V2.0 definitions. Only those
  151. * attributes that are determinable by the local port (aka Host)
  152. * are contained.
  153. *
  154. * Fixed attributes are not expected to change. The driver is
  155. * expected to set these values after successfully calling
  156. * fc_remote_port_add(). The transport fully manages all get functions
  157. * w/o driver interaction.
  158. *
  159. * Dynamic attributes are expected to change. The driver participates
  160. * in all get/set operations via functions provided by the driver.
  161. *
  162. * Private attributes are transport-managed values. They are fully
  163. * managed by the transport w/o driver interaction.
  164. */
  165. struct fc_rport { /* aka fc_starget_attrs */
  166. /* Fixed Attributes */
  167. u32 maxframe_size;
  168. u32 supported_classes;
  169. /* Dynamic Attributes */
  170. u32 dev_loss_tmo; /* Remote Port loss timeout in seconds. */
  171. /* Private (Transport-managed) Attributes */
  172. u64 node_name;
  173. u64 port_name;
  174. u32 port_id;
  175. u32 roles;
  176. enum fc_port_state port_state; /* Will only be ONLINE or UNKNOWN */
  177. u32 scsi_target_id;
  178. /* exported data */
  179. void *dd_data; /* Used for driver-specific storage */
  180. /* internal data */
  181. unsigned int channel;
  182. u32 number;
  183. struct list_head peers;
  184. struct device dev;
  185. struct work_struct dev_loss_work;
  186. struct work_struct scan_work;
  187. } __attribute__((aligned(sizeof(unsigned long))));
  188. #define dev_to_rport(d) \
  189. container_of(d, struct fc_rport, dev)
  190. #define transport_class_to_rport(classdev) \
  191. dev_to_rport(classdev->dev)
  192. #define rport_to_shost(r) \
  193. dev_to_shost(r->dev.parent)
  194. /*
  195. * FC SCSI Target Attributes
  196. *
  197. * The SCSI Target is considered an extention of a remote port (as
  198. * a remote port can be more than a SCSI Target). Within the scsi
  199. * subsystem, we leave the Target as a separate entity. Doing so
  200. * provides backward compatibility with prior FC transport api's,
  201. * and lets remote ports be handled entirely within the FC transport
  202. * and independently from the scsi subsystem. The drawback is that
  203. * some data will be duplicated.
  204. */
  205. struct fc_starget_attrs { /* aka fc_target_attrs */
  206. /* Dynamic Attributes */
  207. u64 node_name;
  208. u64 port_name;
  209. u32 port_id;
  210. };
  211. #define fc_starget_node_name(x) \
  212. (((struct fc_starget_attrs *)&(x)->starget_data)->node_name)
  213. #define fc_starget_port_name(x) \
  214. (((struct fc_starget_attrs *)&(x)->starget_data)->port_name)
  215. #define fc_starget_port_id(x) \
  216. (((struct fc_starget_attrs *)&(x)->starget_data)->port_id)
  217. #define starget_to_rport(s) \
  218. scsi_is_fc_rport(s->dev.parent) ? dev_to_rport(s->dev.parent) : NULL
  219. /*
  220. * FC Local Port (Host) Statistics
  221. */
  222. /* FC Statistics - Following FC HBAAPI v2.0 guidelines */
  223. struct fc_host_statistics {
  224. /* port statistics */
  225. u64 seconds_since_last_reset;
  226. u64 tx_frames;
  227. u64 tx_words;
  228. u64 rx_frames;
  229. u64 rx_words;
  230. u64 lip_count;
  231. u64 nos_count;
  232. u64 error_frames;
  233. u64 dumped_frames;
  234. u64 link_failure_count;
  235. u64 loss_of_sync_count;
  236. u64 loss_of_signal_count;
  237. u64 prim_seq_protocol_err_count;
  238. u64 invalid_tx_word_count;
  239. u64 invalid_crc_count;
  240. /* fc4 statistics (only FCP supported currently) */
  241. u64 fcp_input_requests;
  242. u64 fcp_output_requests;
  243. u64 fcp_control_requests;
  244. u64 fcp_input_megabytes;
  245. u64 fcp_output_megabytes;
  246. };
  247. /*
  248. * FC Local Port (Host) Attributes
  249. *
  250. * Attributes are based on HBAAPI V2.0 definitions.
  251. * Note: OSDeviceName is determined by user-space library
  252. *
  253. * Fixed attributes are not expected to change. The driver is
  254. * expected to set these values after successfully calling scsi_add_host().
  255. * The transport fully manages all get functions w/o driver interaction.
  256. *
  257. * Dynamic attributes are expected to change. The driver participates
  258. * in all get/set operations via functions provided by the driver.
  259. *
  260. * Private attributes are transport-managed values. They are fully
  261. * managed by the transport w/o driver interaction.
  262. */
  263. #define FC_FC4_LIST_SIZE 32
  264. #define FC_SYMBOLIC_NAME_SIZE 256
  265. #define FC_VERSION_STRING_SIZE 64
  266. #define FC_SERIAL_NUMBER_SIZE 80
  267. struct fc_host_attrs {
  268. /* Fixed Attributes */
  269. u64 node_name;
  270. u64 port_name;
  271. u32 supported_classes;
  272. u8 supported_fc4s[FC_FC4_LIST_SIZE];
  273. char symbolic_name[FC_SYMBOLIC_NAME_SIZE];
  274. u32 supported_speeds;
  275. u32 maxframe_size;
  276. char serial_number[FC_SERIAL_NUMBER_SIZE];
  277. /* Dynamic Attributes */
  278. u32 port_id;
  279. enum fc_port_type port_type;
  280. enum fc_port_state port_state;
  281. u8 active_fc4s[FC_FC4_LIST_SIZE];
  282. u32 speed;
  283. u64 fabric_name;
  284. /* Private (Transport-managed) Attributes */
  285. enum fc_tgtid_binding_type tgtid_bind_type;
  286. /* internal data */
  287. struct list_head rports;
  288. struct list_head rport_bindings;
  289. u32 next_rport_number;
  290. u32 next_target_id;
  291. };
  292. #define fc_host_node_name(x) \
  293. (((struct fc_host_attrs *)(x)->shost_data)->node_name)
  294. #define fc_host_port_name(x) \
  295. (((struct fc_host_attrs *)(x)->shost_data)->port_name)
  296. #define fc_host_supported_classes(x) \
  297. (((struct fc_host_attrs *)(x)->shost_data)->supported_classes)
  298. #define fc_host_supported_fc4s(x) \
  299. (((struct fc_host_attrs *)(x)->shost_data)->supported_fc4s)
  300. #define fc_host_symbolic_name(x) \
  301. (((struct fc_host_attrs *)(x)->shost_data)->symbolic_name)
  302. #define fc_host_supported_speeds(x) \
  303. (((struct fc_host_attrs *)(x)->shost_data)->supported_speeds)
  304. #define fc_host_maxframe_size(x) \
  305. (((struct fc_host_attrs *)(x)->shost_data)->maxframe_size)
  306. #define fc_host_serial_number(x) \
  307. (((struct fc_host_attrs *)(x)->shost_data)->serial_number)
  308. #define fc_host_port_id(x) \
  309. (((struct fc_host_attrs *)(x)->shost_data)->port_id)
  310. #define fc_host_port_type(x) \
  311. (((struct fc_host_attrs *)(x)->shost_data)->port_type)
  312. #define fc_host_port_state(x) \
  313. (((struct fc_host_attrs *)(x)->shost_data)->port_state)
  314. #define fc_host_active_fc4s(x) \
  315. (((struct fc_host_attrs *)(x)->shost_data)->active_fc4s)
  316. #define fc_host_speed(x) \
  317. (((struct fc_host_attrs *)(x)->shost_data)->speed)
  318. #define fc_host_fabric_name(x) \
  319. (((struct fc_host_attrs *)(x)->shost_data)->fabric_name)
  320. #define fc_host_tgtid_bind_type(x) \
  321. (((struct fc_host_attrs *)(x)->shost_data)->tgtid_bind_type)
  322. #define fc_host_rports(x) \
  323. (((struct fc_host_attrs *)(x)->shost_data)->rports)
  324. #define fc_host_rport_bindings(x) \
  325. (((struct fc_host_attrs *)(x)->shost_data)->rport_bindings)
  326. #define fc_host_next_rport_number(x) \
  327. (((struct fc_host_attrs *)(x)->shost_data)->next_rport_number)
  328. #define fc_host_next_target_id(x) \
  329. (((struct fc_host_attrs *)(x)->shost_data)->next_target_id)
  330. /* The functions by which the transport class and the driver communicate */
  331. struct fc_function_template {
  332. void (*get_rport_dev_loss_tmo)(struct fc_rport *);
  333. void (*set_rport_dev_loss_tmo)(struct fc_rport *, u32);
  334. void (*get_starget_node_name)(struct scsi_target *);
  335. void (*get_starget_port_name)(struct scsi_target *);
  336. void (*get_starget_port_id)(struct scsi_target *);
  337. void (*get_host_port_id)(struct Scsi_Host *);
  338. void (*get_host_port_type)(struct Scsi_Host *);
  339. void (*get_host_port_state)(struct Scsi_Host *);
  340. void (*get_host_active_fc4s)(struct Scsi_Host *);
  341. void (*get_host_speed)(struct Scsi_Host *);
  342. void (*get_host_fabric_name)(struct Scsi_Host *);
  343. struct fc_host_statistics * (*get_fc_host_stats)(struct Scsi_Host *);
  344. void (*reset_fc_host_stats)(struct Scsi_Host *);
  345. int (*issue_fc_host_lip)(struct Scsi_Host *);
  346. /* allocation lengths for host-specific data */
  347. u32 dd_fcrport_size;
  348. /*
  349. * The driver sets these to tell the transport class it
  350. * wants the attributes displayed in sysfs. If the show_ flag
  351. * is not set, the attribute will be private to the transport
  352. * class
  353. */
  354. /* remote port fixed attributes */
  355. unsigned long show_rport_maxframe_size:1;
  356. unsigned long show_rport_supported_classes:1;
  357. unsigned long show_rport_dev_loss_tmo:1;
  358. /*
  359. * target dynamic attributes
  360. * These should all be "1" if the driver uses the remote port
  361. * add/delete functions (so attributes reflect rport values).
  362. */
  363. unsigned long show_starget_node_name:1;
  364. unsigned long show_starget_port_name:1;
  365. unsigned long show_starget_port_id:1;
  366. /* host fixed attributes */
  367. unsigned long show_host_node_name:1;
  368. unsigned long show_host_port_name:1;
  369. unsigned long show_host_supported_classes:1;
  370. unsigned long show_host_supported_fc4s:1;
  371. unsigned long show_host_symbolic_name:1;
  372. unsigned long show_host_supported_speeds:1;
  373. unsigned long show_host_maxframe_size:1;
  374. unsigned long show_host_serial_number:1;
  375. /* host dynamic attributes */
  376. unsigned long show_host_port_id:1;
  377. unsigned long show_host_port_type:1;
  378. unsigned long show_host_port_state:1;
  379. unsigned long show_host_active_fc4s:1;
  380. unsigned long show_host_speed:1;
  381. unsigned long show_host_fabric_name:1;
  382. };
  383. /**
  384. * fc_remote_port_chkready - called to validate the remote port state
  385. * prior to initiating io to the port.
  386. *
  387. * Returns a scsi result code that can be returned by the LLDD.
  388. *
  389. * @rport: remote port to be checked
  390. **/
  391. static inline int
  392. fc_remote_port_chkready(struct fc_rport *rport)
  393. {
  394. int result;
  395. switch (rport->port_state) {
  396. case FC_PORTSTATE_ONLINE:
  397. result = 0;
  398. break;
  399. case FC_PORTSTATE_BLOCKED:
  400. result = DID_BUS_BUSY << 16;
  401. break;
  402. default:
  403. result = DID_NO_CONNECT << 16;
  404. break;
  405. }
  406. return result;
  407. }
  408. struct scsi_transport_template *fc_attach_transport(
  409. struct fc_function_template *);
  410. void fc_release_transport(struct scsi_transport_template *);
  411. void fc_remove_host(struct Scsi_Host *);
  412. struct fc_rport *fc_remote_port_add(struct Scsi_Host *shost,
  413. int channel, struct fc_rport_identifiers *ids);
  414. void fc_remote_port_delete(struct fc_rport *rport);
  415. void fc_remote_port_rolechg(struct fc_rport *rport, u32 roles);
  416. int scsi_is_fc_rport(const struct device *);
  417. static inline u64 wwn_to_u64(u8 *wwn)
  418. {
  419. return (u64)wwn[0] << 56 | (u64)wwn[1] << 48 |
  420. (u64)wwn[2] << 40 | (u64)wwn[3] << 32 |
  421. (u64)wwn[4] << 24 | (u64)wwn[5] << 16 |
  422. (u64)wwn[6] << 8 | (u64)wwn[7];
  423. }
  424. #endif /* SCSI_TRANSPORT_FC_H */