scsi_transport_fc.h 15 KB

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