scsi_transport_fc.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  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/sched.h>
  30. #include <scsi/scsi.h>
  31. struct scsi_transport_template;
  32. /*
  33. * FC Port definitions - Following FC HBAAPI guidelines
  34. *
  35. * Note: Not all binary values for the different fields match HBAAPI.
  36. * Instead, we use densely packed ordinal values or enums.
  37. * We get away with this as we never present the actual binary values
  38. * externally. For sysfs, we always present the string that describes
  39. * the value. Thus, an admin doesn't need a magic HBAAPI decoder ring
  40. * to understand the values. The HBAAPI user-space library is free to
  41. * convert the strings into the HBAAPI-specified binary values.
  42. *
  43. * Note: Not all HBAAPI-defined values are contained in the definitions
  44. * below. Those not appropriate to an fc_host (e.g. FCP initiator) have
  45. * been removed.
  46. */
  47. /*
  48. * fc_port_type: If you alter this, you also need to alter scsi_transport_fc.c
  49. * (for the ascii descriptions).
  50. */
  51. enum fc_port_type {
  52. FC_PORTTYPE_UNKNOWN,
  53. FC_PORTTYPE_OTHER,
  54. FC_PORTTYPE_NOTPRESENT,
  55. FC_PORTTYPE_NPORT, /* Attached to FPort */
  56. FC_PORTTYPE_NLPORT, /* (Public) Loop w/ FLPort */
  57. FC_PORTTYPE_LPORT, /* (Private) Loop w/o FLPort */
  58. FC_PORTTYPE_PTP, /* Point to Point w/ another NPort */
  59. };
  60. /*
  61. * fc_port_state: If you alter this, you also need to alter scsi_transport_fc.c
  62. * (for the ascii descriptions).
  63. */
  64. enum fc_port_state {
  65. FC_PORTSTATE_UNKNOWN,
  66. FC_PORTSTATE_NOTPRESENT,
  67. FC_PORTSTATE_ONLINE,
  68. FC_PORTSTATE_OFFLINE, /* User has taken Port Offline */
  69. FC_PORTSTATE_BLOCKED,
  70. FC_PORTSTATE_BYPASSED,
  71. FC_PORTSTATE_DIAGNOSTICS,
  72. FC_PORTSTATE_LINKDOWN,
  73. FC_PORTSTATE_ERROR,
  74. FC_PORTSTATE_LOOPBACK,
  75. FC_PORTSTATE_DELETED,
  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. u8 flags;
  184. struct list_head peers;
  185. struct device dev;
  186. struct work_struct dev_loss_work;
  187. struct work_struct scan_work;
  188. struct work_struct stgt_delete_work;
  189. struct work_struct rport_delete_work;
  190. } __attribute__((aligned(sizeof(unsigned long))));
  191. /* bit field values for struct fc_rport "flags" field: */
  192. #define FC_RPORT_DEVLOSS_PENDING 0x01
  193. #define FC_RPORT_SCAN_PENDING 0x02
  194. #define dev_to_rport(d) \
  195. container_of(d, struct fc_rport, dev)
  196. #define transport_class_to_rport(classdev) \
  197. dev_to_rport(classdev->dev)
  198. #define rport_to_shost(r) \
  199. dev_to_shost(r->dev.parent)
  200. /*
  201. * FC SCSI Target Attributes
  202. *
  203. * The SCSI Target is considered an extention of a remote port (as
  204. * a remote port can be more than a SCSI Target). Within the scsi
  205. * subsystem, we leave the Target as a separate entity. Doing so
  206. * provides backward compatibility with prior FC transport api's,
  207. * and lets remote ports be handled entirely within the FC transport
  208. * and independently from the scsi subsystem. The drawback is that
  209. * some data will be duplicated.
  210. */
  211. struct fc_starget_attrs { /* aka fc_target_attrs */
  212. /* Dynamic Attributes */
  213. u64 node_name;
  214. u64 port_name;
  215. u32 port_id;
  216. };
  217. #define fc_starget_node_name(x) \
  218. (((struct fc_starget_attrs *)&(x)->starget_data)->node_name)
  219. #define fc_starget_port_name(x) \
  220. (((struct fc_starget_attrs *)&(x)->starget_data)->port_name)
  221. #define fc_starget_port_id(x) \
  222. (((struct fc_starget_attrs *)&(x)->starget_data)->port_id)
  223. #define starget_to_rport(s) \
  224. scsi_is_fc_rport(s->dev.parent) ? dev_to_rport(s->dev.parent) : NULL
  225. /*
  226. * FC Local Port (Host) Statistics
  227. */
  228. /* FC Statistics - Following FC HBAAPI v2.0 guidelines */
  229. struct fc_host_statistics {
  230. /* port statistics */
  231. u64 seconds_since_last_reset;
  232. u64 tx_frames;
  233. u64 tx_words;
  234. u64 rx_frames;
  235. u64 rx_words;
  236. u64 lip_count;
  237. u64 nos_count;
  238. u64 error_frames;
  239. u64 dumped_frames;
  240. u64 link_failure_count;
  241. u64 loss_of_sync_count;
  242. u64 loss_of_signal_count;
  243. u64 prim_seq_protocol_err_count;
  244. u64 invalid_tx_word_count;
  245. u64 invalid_crc_count;
  246. /* fc4 statistics (only FCP supported currently) */
  247. u64 fcp_input_requests;
  248. u64 fcp_output_requests;
  249. u64 fcp_control_requests;
  250. u64 fcp_input_megabytes;
  251. u64 fcp_output_megabytes;
  252. };
  253. /*
  254. * FC Local Port (Host) Attributes
  255. *
  256. * Attributes are based on HBAAPI V2.0 definitions.
  257. * Note: OSDeviceName is determined by user-space library
  258. *
  259. * Fixed attributes are not expected to change. The driver is
  260. * expected to set these values after successfully calling scsi_add_host().
  261. * The transport fully manages all get functions w/o driver interaction.
  262. *
  263. * Dynamic attributes are expected to change. The driver participates
  264. * in all get/set operations via functions provided by the driver.
  265. *
  266. * Private attributes are transport-managed values. They are fully
  267. * managed by the transport w/o driver interaction.
  268. */
  269. #define FC_FC4_LIST_SIZE 32
  270. #define FC_SYMBOLIC_NAME_SIZE 256
  271. #define FC_VERSION_STRING_SIZE 64
  272. #define FC_SERIAL_NUMBER_SIZE 80
  273. struct fc_host_attrs {
  274. /* Fixed Attributes */
  275. u64 node_name;
  276. u64 port_name;
  277. u64 permanent_port_name;
  278. u32 supported_classes;
  279. u8 supported_fc4s[FC_FC4_LIST_SIZE];
  280. char symbolic_name[FC_SYMBOLIC_NAME_SIZE];
  281. u32 supported_speeds;
  282. u32 maxframe_size;
  283. char serial_number[FC_SERIAL_NUMBER_SIZE];
  284. /* Dynamic Attributes */
  285. u32 port_id;
  286. enum fc_port_type port_type;
  287. enum fc_port_state port_state;
  288. u8 active_fc4s[FC_FC4_LIST_SIZE];
  289. u32 speed;
  290. u64 fabric_name;
  291. /* Private (Transport-managed) Attributes */
  292. enum fc_tgtid_binding_type tgtid_bind_type;
  293. /* internal data */
  294. struct list_head rports;
  295. struct list_head rport_bindings;
  296. u32 next_rport_number;
  297. u32 next_target_id;
  298. /* work queues for rport state manipulation */
  299. char work_q_name[KOBJ_NAME_LEN];
  300. struct workqueue_struct *work_q;
  301. char devloss_work_q_name[KOBJ_NAME_LEN];
  302. struct workqueue_struct *devloss_work_q;
  303. };
  304. #define shost_to_fc_host(x) \
  305. ((struct fc_host_attrs *)(x)->shost_data)
  306. #define fc_host_node_name(x) \
  307. (((struct fc_host_attrs *)(x)->shost_data)->node_name)
  308. #define fc_host_port_name(x) \
  309. (((struct fc_host_attrs *)(x)->shost_data)->port_name)
  310. #define fc_host_permanent_port_name(x) \
  311. (((struct fc_host_attrs *)(x)->shost_data)->permanent_port_name)
  312. #define fc_host_supported_classes(x) \
  313. (((struct fc_host_attrs *)(x)->shost_data)->supported_classes)
  314. #define fc_host_supported_fc4s(x) \
  315. (((struct fc_host_attrs *)(x)->shost_data)->supported_fc4s)
  316. #define fc_host_symbolic_name(x) \
  317. (((struct fc_host_attrs *)(x)->shost_data)->symbolic_name)
  318. #define fc_host_supported_speeds(x) \
  319. (((struct fc_host_attrs *)(x)->shost_data)->supported_speeds)
  320. #define fc_host_maxframe_size(x) \
  321. (((struct fc_host_attrs *)(x)->shost_data)->maxframe_size)
  322. #define fc_host_serial_number(x) \
  323. (((struct fc_host_attrs *)(x)->shost_data)->serial_number)
  324. #define fc_host_port_id(x) \
  325. (((struct fc_host_attrs *)(x)->shost_data)->port_id)
  326. #define fc_host_port_type(x) \
  327. (((struct fc_host_attrs *)(x)->shost_data)->port_type)
  328. #define fc_host_port_state(x) \
  329. (((struct fc_host_attrs *)(x)->shost_data)->port_state)
  330. #define fc_host_active_fc4s(x) \
  331. (((struct fc_host_attrs *)(x)->shost_data)->active_fc4s)
  332. #define fc_host_speed(x) \
  333. (((struct fc_host_attrs *)(x)->shost_data)->speed)
  334. #define fc_host_fabric_name(x) \
  335. (((struct fc_host_attrs *)(x)->shost_data)->fabric_name)
  336. #define fc_host_tgtid_bind_type(x) \
  337. (((struct fc_host_attrs *)(x)->shost_data)->tgtid_bind_type)
  338. #define fc_host_rports(x) \
  339. (((struct fc_host_attrs *)(x)->shost_data)->rports)
  340. #define fc_host_rport_bindings(x) \
  341. (((struct fc_host_attrs *)(x)->shost_data)->rport_bindings)
  342. #define fc_host_next_rport_number(x) \
  343. (((struct fc_host_attrs *)(x)->shost_data)->next_rport_number)
  344. #define fc_host_next_target_id(x) \
  345. (((struct fc_host_attrs *)(x)->shost_data)->next_target_id)
  346. #define fc_host_work_q_name(x) \
  347. (((struct fc_host_attrs *)(x)->shost_data)->work_q_name)
  348. #define fc_host_work_q(x) \
  349. (((struct fc_host_attrs *)(x)->shost_data)->work_q)
  350. #define fc_host_devloss_work_q_name(x) \
  351. (((struct fc_host_attrs *)(x)->shost_data)->devloss_work_q_name)
  352. #define fc_host_devloss_work_q(x) \
  353. (((struct fc_host_attrs *)(x)->shost_data)->devloss_work_q)
  354. /* The functions by which the transport class and the driver communicate */
  355. struct fc_function_template {
  356. void (*get_rport_dev_loss_tmo)(struct fc_rport *);
  357. void (*set_rport_dev_loss_tmo)(struct fc_rport *, u32);
  358. void (*get_starget_node_name)(struct scsi_target *);
  359. void (*get_starget_port_name)(struct scsi_target *);
  360. void (*get_starget_port_id)(struct scsi_target *);
  361. void (*get_host_port_id)(struct Scsi_Host *);
  362. void (*get_host_port_type)(struct Scsi_Host *);
  363. void (*get_host_port_state)(struct Scsi_Host *);
  364. void (*get_host_active_fc4s)(struct Scsi_Host *);
  365. void (*get_host_speed)(struct Scsi_Host *);
  366. void (*get_host_fabric_name)(struct Scsi_Host *);
  367. struct fc_host_statistics * (*get_fc_host_stats)(struct Scsi_Host *);
  368. void (*reset_fc_host_stats)(struct Scsi_Host *);
  369. int (*issue_fc_host_lip)(struct Scsi_Host *);
  370. /* allocation lengths for host-specific data */
  371. u32 dd_fcrport_size;
  372. /*
  373. * The driver sets these to tell the transport class it
  374. * wants the attributes displayed in sysfs. If the show_ flag
  375. * is not set, the attribute will be private to the transport
  376. * class
  377. */
  378. /* remote port fixed attributes */
  379. unsigned long show_rport_maxframe_size:1;
  380. unsigned long show_rport_supported_classes:1;
  381. unsigned long show_rport_dev_loss_tmo:1;
  382. /*
  383. * target dynamic attributes
  384. * These should all be "1" if the driver uses the remote port
  385. * add/delete functions (so attributes reflect rport values).
  386. */
  387. unsigned long show_starget_node_name:1;
  388. unsigned long show_starget_port_name:1;
  389. unsigned long show_starget_port_id:1;
  390. /* host fixed attributes */
  391. unsigned long show_host_node_name:1;
  392. unsigned long show_host_port_name:1;
  393. unsigned long show_host_permanent_port_name:1;
  394. unsigned long show_host_supported_classes:1;
  395. unsigned long show_host_supported_fc4s:1;
  396. unsigned long show_host_symbolic_name:1;
  397. unsigned long show_host_supported_speeds:1;
  398. unsigned long show_host_maxframe_size:1;
  399. unsigned long show_host_serial_number:1;
  400. /* host dynamic attributes */
  401. unsigned long show_host_port_id:1;
  402. unsigned long show_host_port_type:1;
  403. unsigned long show_host_port_state:1;
  404. unsigned long show_host_active_fc4s:1;
  405. unsigned long show_host_speed:1;
  406. unsigned long show_host_fabric_name:1;
  407. };
  408. /**
  409. * fc_remote_port_chkready - called to validate the remote port state
  410. * prior to initiating io to the port.
  411. *
  412. * Returns a scsi result code that can be returned by the LLDD.
  413. *
  414. * @rport: remote port to be checked
  415. **/
  416. static inline int
  417. fc_remote_port_chkready(struct fc_rport *rport)
  418. {
  419. int result;
  420. switch (rport->port_state) {
  421. case FC_PORTSTATE_ONLINE:
  422. if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
  423. result = 0;
  424. else if (rport->flags & FC_RPORT_DEVLOSS_PENDING)
  425. result = DID_IMM_RETRY << 16;
  426. else
  427. result = DID_NO_CONNECT << 16;
  428. break;
  429. case FC_PORTSTATE_BLOCKED:
  430. result = DID_IMM_RETRY << 16;
  431. break;
  432. default:
  433. result = DID_NO_CONNECT << 16;
  434. break;
  435. }
  436. return result;
  437. }
  438. struct scsi_transport_template *fc_attach_transport(
  439. struct fc_function_template *);
  440. void fc_release_transport(struct scsi_transport_template *);
  441. void fc_remove_host(struct Scsi_Host *);
  442. struct fc_rport *fc_remote_port_add(struct Scsi_Host *shost,
  443. int channel, struct fc_rport_identifiers *ids);
  444. void fc_remote_port_delete(struct fc_rport *rport);
  445. void fc_remote_port_rolechg(struct fc_rport *rport, u32 roles);
  446. int scsi_is_fc_rport(const struct device *);
  447. static inline u64 wwn_to_u64(u8 *wwn)
  448. {
  449. return (u64)wwn[0] << 56 | (u64)wwn[1] << 48 |
  450. (u64)wwn[2] << 40 | (u64)wwn[3] << 32 |
  451. (u64)wwn[4] << 24 | (u64)wwn[5] << 16 |
  452. (u64)wwn[6] << 8 | (u64)wwn[7];
  453. }
  454. #endif /* SCSI_TRANSPORT_FC_H */