scsi_transport_fc.h 16 KB

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