scsi_transport_fc.h 14 KB

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