scsi_transport_fc.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  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-2007 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. #include <scsi/scsi_netlink.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. FC_PORTTYPE_NPIV, /* VPORT based on NPIV */
  61. };
  62. /*
  63. * fc_port_state: If you alter this, you also need to alter scsi_transport_fc.c
  64. * (for the ascii descriptions).
  65. */
  66. enum fc_port_state {
  67. FC_PORTSTATE_UNKNOWN,
  68. FC_PORTSTATE_NOTPRESENT,
  69. FC_PORTSTATE_ONLINE,
  70. FC_PORTSTATE_OFFLINE, /* User has taken Port Offline */
  71. FC_PORTSTATE_BLOCKED,
  72. FC_PORTSTATE_BYPASSED,
  73. FC_PORTSTATE_DIAGNOSTICS,
  74. FC_PORTSTATE_LINKDOWN,
  75. FC_PORTSTATE_ERROR,
  76. FC_PORTSTATE_LOOPBACK,
  77. FC_PORTSTATE_DELETED,
  78. };
  79. /*
  80. * fc_vport_state: If you alter this, you also need to alter
  81. * scsi_transport_fc.c (for the ascii descriptions).
  82. */
  83. enum fc_vport_state {
  84. FC_VPORT_UNKNOWN,
  85. FC_VPORT_ACTIVE,
  86. FC_VPORT_DISABLED,
  87. FC_VPORT_LINKDOWN,
  88. FC_VPORT_INITIALIZING,
  89. FC_VPORT_NO_FABRIC_SUPP,
  90. FC_VPORT_NO_FABRIC_RSCS,
  91. FC_VPORT_FABRIC_LOGOUT,
  92. FC_VPORT_FABRIC_REJ_WWN,
  93. FC_VPORT_FAILED,
  94. };
  95. /*
  96. * FC Classes of Service
  97. * Note: values are not enumerated, as they can be "or'd" together
  98. * for reporting (e.g. report supported_classes). If you alter this list,
  99. * you also need to alter scsi_transport_fc.c (for the ascii descriptions).
  100. */
  101. #define FC_COS_UNSPECIFIED 0
  102. #define FC_COS_CLASS1 2
  103. #define FC_COS_CLASS2 4
  104. #define FC_COS_CLASS3 8
  105. #define FC_COS_CLASS4 0x10
  106. #define FC_COS_CLASS6 0x40
  107. /*
  108. * FC Port Speeds
  109. * Note: values are not enumerated, as they can be "or'd" together
  110. * for reporting (e.g. report supported_speeds). If you alter this list,
  111. * you also need to alter scsi_transport_fc.c (for the ascii descriptions).
  112. */
  113. #define FC_PORTSPEED_UNKNOWN 0 /* Unknown - transceiver
  114. incapable of reporting */
  115. #define FC_PORTSPEED_1GBIT 1
  116. #define FC_PORTSPEED_2GBIT 2
  117. #define FC_PORTSPEED_4GBIT 4
  118. #define FC_PORTSPEED_10GBIT 8
  119. #define FC_PORTSPEED_8GBIT 0x10
  120. #define FC_PORTSPEED_16GBIT 0x20
  121. #define FC_PORTSPEED_NOT_NEGOTIATED (1 << 15) /* Speed not established */
  122. /*
  123. * fc_tgtid_binding_type: If you alter this, you also need to alter
  124. * scsi_transport_fc.c (for the ascii descriptions).
  125. */
  126. enum fc_tgtid_binding_type {
  127. FC_TGTID_BIND_NONE,
  128. FC_TGTID_BIND_BY_WWPN,
  129. FC_TGTID_BIND_BY_WWNN,
  130. FC_TGTID_BIND_BY_ID,
  131. };
  132. /*
  133. * FC Port Roles
  134. * Note: values are not enumerated, as they can be "or'd" together
  135. * for reporting (e.g. report roles). If you alter this list,
  136. * you also need to alter scsi_transport_fc.c (for the ascii descriptions).
  137. */
  138. #define FC_PORT_ROLE_UNKNOWN 0x00
  139. #define FC_PORT_ROLE_FCP_TARGET 0x01
  140. #define FC_PORT_ROLE_FCP_INITIATOR 0x02
  141. #define FC_PORT_ROLE_IP_PORT 0x04
  142. /* The following are for compatibility */
  143. #define FC_RPORT_ROLE_UNKNOWN FC_PORT_ROLE_UNKNOWN
  144. #define FC_RPORT_ROLE_FCP_TARGET FC_PORT_ROLE_FCP_TARGET
  145. #define FC_RPORT_ROLE_FCP_INITIATOR FC_PORT_ROLE_FCP_INITIATOR
  146. #define FC_RPORT_ROLE_IP_PORT FC_PORT_ROLE_IP_PORT
  147. /* Macro for use in defining Virtual Port attributes */
  148. #define FC_VPORT_ATTR(_name,_mode,_show,_store) \
  149. struct class_device_attribute class_device_attr_vport_##_name = \
  150. __ATTR(_name,_mode,_show,_store)
  151. /*
  152. * FC Virtual Port Attributes
  153. *
  154. * This structure exists for each FC port is a virtual FC port. Virtual
  155. * ports share the physical link with the Physical port. Each virtual
  156. * ports has a unique presense on the SAN, and may be instantiated via
  157. * NPIV, Virtual Fabrics, or via additional ALPAs. As the vport is a
  158. * unique presense, each vport has it's own view of the fabric,
  159. * authentication priviledge, and priorities.
  160. *
  161. * A virtual port may support 1 or more FC4 roles. Typically it is a
  162. * FCP Initiator. It could be a FCP Target, or exist sole for an IP over FC
  163. * roles. FC port attributes for the vport will be reported on any
  164. * fc_host class object allocated for an FCP Initiator.
  165. *
  166. * --
  167. *
  168. * Fixed attributes are not expected to change. The driver is
  169. * expected to set these values after receiving the fc_vport structure
  170. * via the vport_create() call from the transport.
  171. * The transport fully manages all get functions w/o driver interaction.
  172. *
  173. * Dynamic attributes are expected to change. The driver participates
  174. * in all get/set operations via functions provided by the driver.
  175. *
  176. * Private attributes are transport-managed values. They are fully
  177. * managed by the transport w/o driver interaction.
  178. */
  179. #define FC_VPORT_SYMBOLIC_NAMELEN 64
  180. struct fc_vport {
  181. /* Fixed Attributes */
  182. /* Dynamic Attributes */
  183. /* Private (Transport-managed) Attributes */
  184. enum fc_vport_state vport_state;
  185. enum fc_vport_state vport_last_state;
  186. u64 node_name;
  187. u64 port_name;
  188. u32 roles;
  189. u32 vport_id; /* Admin Identifier for the vport */
  190. enum fc_port_type vport_type;
  191. char symbolic_name[FC_VPORT_SYMBOLIC_NAMELEN];
  192. /* exported data */
  193. void *dd_data; /* Used for driver-specific storage */
  194. /* internal data */
  195. struct Scsi_Host *shost; /* Physical Port Parent */
  196. unsigned int channel;
  197. u32 number;
  198. u8 flags;
  199. struct list_head peers;
  200. struct device dev;
  201. struct work_struct vport_delete_work;
  202. } __attribute__((aligned(sizeof(unsigned long))));
  203. /* bit field values for struct fc_vport "flags" field: */
  204. #define FC_VPORT_CREATING 0x01
  205. #define FC_VPORT_DELETING 0x02
  206. #define FC_VPORT_DELETED 0x04
  207. #define FC_VPORT_DEL 0x06 /* Any DELETE state */
  208. #define dev_to_vport(d) \
  209. container_of(d, struct fc_vport, dev)
  210. #define transport_class_to_vport(classdev) \
  211. dev_to_vport(classdev->dev)
  212. #define vport_to_shost(v) \
  213. (v->shost)
  214. #define vport_to_shost_channel(v) \
  215. (v->channel)
  216. #define vport_to_parent(v) \
  217. (v->dev.parent)
  218. /* Error return codes for vport_create() callback */
  219. #define VPCERR_UNSUPPORTED -ENOSYS /* no driver/adapter
  220. support */
  221. #define VPCERR_BAD_WWN -ENOTUNIQ /* driver validation
  222. of WWNs failed */
  223. #define VPCERR_NO_FABRIC_SUPP -EOPNOTSUPP /* Fabric connection
  224. is loop or the
  225. Fabric Port does
  226. not support NPIV */
  227. /*
  228. * fc_rport_identifiers: This set of data contains all elements
  229. * to uniquely identify a remote FC port. The driver uses this data
  230. * to report the existence of a remote FC port in the topology. Internally,
  231. * the transport uses this data for attributes and to manage consistent
  232. * target id bindings.
  233. */
  234. struct fc_rport_identifiers {
  235. u64 node_name;
  236. u64 port_name;
  237. u32 port_id;
  238. u32 roles;
  239. };
  240. /* Macro for use in defining Remote Port attributes */
  241. #define FC_RPORT_ATTR(_name,_mode,_show,_store) \
  242. struct class_device_attribute class_device_attr_rport_##_name = \
  243. __ATTR(_name,_mode,_show,_store)
  244. /*
  245. * FC Remote Port Attributes
  246. *
  247. * This structure exists for each remote FC port that a LLDD notifies
  248. * the subsystem of. A remote FC port may or may not be a SCSI Target,
  249. * also be a SCSI initiator, IP endpoint, etc. As such, the remote
  250. * port is considered a separate entity, independent of "role" (such
  251. * as scsi target).
  252. *
  253. * --
  254. *
  255. * Attributes are based on HBAAPI V2.0 definitions. Only those
  256. * attributes that are determinable by the local port (aka Host)
  257. * are contained.
  258. *
  259. * Fixed attributes are not expected to change. The driver is
  260. * expected to set these values after successfully calling
  261. * fc_remote_port_add(). The transport fully manages all get functions
  262. * 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. struct fc_rport { /* aka fc_starget_attrs */
  271. /* Fixed Attributes */
  272. u32 maxframe_size;
  273. u32 supported_classes;
  274. /* Dynamic Attributes */
  275. u32 dev_loss_tmo; /* Remote Port loss timeout in seconds. */
  276. /* Private (Transport-managed) Attributes */
  277. u64 node_name;
  278. u64 port_name;
  279. u32 port_id;
  280. u32 roles;
  281. enum fc_port_state port_state; /* Will only be ONLINE or UNKNOWN */
  282. u32 scsi_target_id;
  283. u32 fast_io_fail_tmo;
  284. /* exported data */
  285. void *dd_data; /* Used for driver-specific storage */
  286. /* internal data */
  287. unsigned int channel;
  288. u32 number;
  289. u8 flags;
  290. struct list_head peers;
  291. struct device dev;
  292. struct delayed_work dev_loss_work;
  293. struct work_struct scan_work;
  294. struct delayed_work fail_io_work;
  295. struct work_struct stgt_delete_work;
  296. struct work_struct rport_delete_work;
  297. } __attribute__((aligned(sizeof(unsigned long))));
  298. /* bit field values for struct fc_rport "flags" field: */
  299. #define FC_RPORT_DEVLOSS_PENDING 0x01
  300. #define FC_RPORT_SCAN_PENDING 0x02
  301. #define dev_to_rport(d) \
  302. container_of(d, struct fc_rport, dev)
  303. #define transport_class_to_rport(classdev) \
  304. dev_to_rport(classdev->dev)
  305. #define rport_to_shost(r) \
  306. dev_to_shost(r->dev.parent)
  307. /*
  308. * FC SCSI Target Attributes
  309. *
  310. * The SCSI Target is considered an extention of a remote port (as
  311. * a remote port can be more than a SCSI Target). Within the scsi
  312. * subsystem, we leave the Target as a separate entity. Doing so
  313. * provides backward compatibility with prior FC transport api's,
  314. * and lets remote ports be handled entirely within the FC transport
  315. * and independently from the scsi subsystem. The drawback is that
  316. * some data will be duplicated.
  317. */
  318. struct fc_starget_attrs { /* aka fc_target_attrs */
  319. /* Dynamic Attributes */
  320. u64 node_name;
  321. u64 port_name;
  322. u32 port_id;
  323. };
  324. #define fc_starget_node_name(x) \
  325. (((struct fc_starget_attrs *)&(x)->starget_data)->node_name)
  326. #define fc_starget_port_name(x) \
  327. (((struct fc_starget_attrs *)&(x)->starget_data)->port_name)
  328. #define fc_starget_port_id(x) \
  329. (((struct fc_starget_attrs *)&(x)->starget_data)->port_id)
  330. #define starget_to_rport(s) \
  331. scsi_is_fc_rport(s->dev.parent) ? dev_to_rport(s->dev.parent) : NULL
  332. /*
  333. * FC Local Port (Host) Statistics
  334. */
  335. /* FC Statistics - Following FC HBAAPI v2.0 guidelines */
  336. struct fc_host_statistics {
  337. /* port statistics */
  338. u64 seconds_since_last_reset;
  339. u64 tx_frames;
  340. u64 tx_words;
  341. u64 rx_frames;
  342. u64 rx_words;
  343. u64 lip_count;
  344. u64 nos_count;
  345. u64 error_frames;
  346. u64 dumped_frames;
  347. u64 link_failure_count;
  348. u64 loss_of_sync_count;
  349. u64 loss_of_signal_count;
  350. u64 prim_seq_protocol_err_count;
  351. u64 invalid_tx_word_count;
  352. u64 invalid_crc_count;
  353. /* fc4 statistics (only FCP supported currently) */
  354. u64 fcp_input_requests;
  355. u64 fcp_output_requests;
  356. u64 fcp_control_requests;
  357. u64 fcp_input_megabytes;
  358. u64 fcp_output_megabytes;
  359. };
  360. /*
  361. * FC Event Codes - Polled and Async, following FC HBAAPI v2.0 guidelines
  362. */
  363. /*
  364. * fc_host_event_code: If you alter this, you also need to alter
  365. * scsi_transport_fc.c (for the ascii descriptions).
  366. */
  367. enum fc_host_event_code {
  368. FCH_EVT_LIP = 0x1,
  369. FCH_EVT_LINKUP = 0x2,
  370. FCH_EVT_LINKDOWN = 0x3,
  371. FCH_EVT_LIPRESET = 0x4,
  372. FCH_EVT_RSCN = 0x5,
  373. FCH_EVT_ADAPTER_CHANGE = 0x103,
  374. FCH_EVT_PORT_UNKNOWN = 0x200,
  375. FCH_EVT_PORT_OFFLINE = 0x201,
  376. FCH_EVT_PORT_ONLINE = 0x202,
  377. FCH_EVT_PORT_FABRIC = 0x204,
  378. FCH_EVT_LINK_UNKNOWN = 0x500,
  379. FCH_EVT_VENDOR_UNIQUE = 0xffff,
  380. };
  381. /*
  382. * FC Local Port (Host) Attributes
  383. *
  384. * Attributes are based on HBAAPI V2.0 definitions.
  385. * Note: OSDeviceName is determined by user-space library
  386. *
  387. * Fixed attributes are not expected to change. The driver is
  388. * expected to set these values after successfully calling scsi_add_host().
  389. * The transport fully manages all get functions w/o driver interaction.
  390. *
  391. * Dynamic attributes are expected to change. The driver participates
  392. * in all get/set operations via functions provided by the driver.
  393. *
  394. * Private attributes are transport-managed values. They are fully
  395. * managed by the transport w/o driver interaction.
  396. */
  397. #define FC_FC4_LIST_SIZE 32
  398. #define FC_SYMBOLIC_NAME_SIZE 256
  399. #define FC_VERSION_STRING_SIZE 64
  400. #define FC_SERIAL_NUMBER_SIZE 80
  401. struct fc_host_attrs {
  402. /* Fixed Attributes */
  403. u64 node_name;
  404. u64 port_name;
  405. u64 permanent_port_name;
  406. u32 supported_classes;
  407. u8 supported_fc4s[FC_FC4_LIST_SIZE];
  408. u32 supported_speeds;
  409. u32 maxframe_size;
  410. u16 max_npiv_vports;
  411. char serial_number[FC_SERIAL_NUMBER_SIZE];
  412. /* Dynamic Attributes */
  413. u32 port_id;
  414. enum fc_port_type port_type;
  415. enum fc_port_state port_state;
  416. u8 active_fc4s[FC_FC4_LIST_SIZE];
  417. u32 speed;
  418. u64 fabric_name;
  419. char symbolic_name[FC_SYMBOLIC_NAME_SIZE];
  420. char system_hostname[FC_SYMBOLIC_NAME_SIZE];
  421. /* Private (Transport-managed) Attributes */
  422. enum fc_tgtid_binding_type tgtid_bind_type;
  423. /* internal data */
  424. struct list_head rports;
  425. struct list_head rport_bindings;
  426. struct list_head vports;
  427. u32 next_rport_number;
  428. u32 next_target_id;
  429. u32 next_vport_number;
  430. u16 npiv_vports_inuse;
  431. /* work queues for rport state manipulation */
  432. char work_q_name[KOBJ_NAME_LEN];
  433. struct workqueue_struct *work_q;
  434. char devloss_work_q_name[KOBJ_NAME_LEN];
  435. struct workqueue_struct *devloss_work_q;
  436. };
  437. #define shost_to_fc_host(x) \
  438. ((struct fc_host_attrs *)(x)->shost_data)
  439. #define fc_host_node_name(x) \
  440. (((struct fc_host_attrs *)(x)->shost_data)->node_name)
  441. #define fc_host_port_name(x) \
  442. (((struct fc_host_attrs *)(x)->shost_data)->port_name)
  443. #define fc_host_permanent_port_name(x) \
  444. (((struct fc_host_attrs *)(x)->shost_data)->permanent_port_name)
  445. #define fc_host_supported_classes(x) \
  446. (((struct fc_host_attrs *)(x)->shost_data)->supported_classes)
  447. #define fc_host_supported_fc4s(x) \
  448. (((struct fc_host_attrs *)(x)->shost_data)->supported_fc4s)
  449. #define fc_host_supported_speeds(x) \
  450. (((struct fc_host_attrs *)(x)->shost_data)->supported_speeds)
  451. #define fc_host_maxframe_size(x) \
  452. (((struct fc_host_attrs *)(x)->shost_data)->maxframe_size)
  453. #define fc_host_max_npiv_vports(x) \
  454. (((struct fc_host_attrs *)(x)->shost_data)->max_npiv_vports)
  455. #define fc_host_serial_number(x) \
  456. (((struct fc_host_attrs *)(x)->shost_data)->serial_number)
  457. #define fc_host_port_id(x) \
  458. (((struct fc_host_attrs *)(x)->shost_data)->port_id)
  459. #define fc_host_port_type(x) \
  460. (((struct fc_host_attrs *)(x)->shost_data)->port_type)
  461. #define fc_host_port_state(x) \
  462. (((struct fc_host_attrs *)(x)->shost_data)->port_state)
  463. #define fc_host_active_fc4s(x) \
  464. (((struct fc_host_attrs *)(x)->shost_data)->active_fc4s)
  465. #define fc_host_speed(x) \
  466. (((struct fc_host_attrs *)(x)->shost_data)->speed)
  467. #define fc_host_fabric_name(x) \
  468. (((struct fc_host_attrs *)(x)->shost_data)->fabric_name)
  469. #define fc_host_symbolic_name(x) \
  470. (((struct fc_host_attrs *)(x)->shost_data)->symbolic_name)
  471. #define fc_host_system_hostname(x) \
  472. (((struct fc_host_attrs *)(x)->shost_data)->system_hostname)
  473. #define fc_host_tgtid_bind_type(x) \
  474. (((struct fc_host_attrs *)(x)->shost_data)->tgtid_bind_type)
  475. #define fc_host_rports(x) \
  476. (((struct fc_host_attrs *)(x)->shost_data)->rports)
  477. #define fc_host_rport_bindings(x) \
  478. (((struct fc_host_attrs *)(x)->shost_data)->rport_bindings)
  479. #define fc_host_vports(x) \
  480. (((struct fc_host_attrs *)(x)->shost_data)->vports)
  481. #define fc_host_next_rport_number(x) \
  482. (((struct fc_host_attrs *)(x)->shost_data)->next_rport_number)
  483. #define fc_host_next_target_id(x) \
  484. (((struct fc_host_attrs *)(x)->shost_data)->next_target_id)
  485. #define fc_host_next_vport_number(x) \
  486. (((struct fc_host_attrs *)(x)->shost_data)->next_vport_number)
  487. #define fc_host_npiv_vports_inuse(x) \
  488. (((struct fc_host_attrs *)(x)->shost_data)->npiv_vports_inuse)
  489. #define fc_host_work_q_name(x) \
  490. (((struct fc_host_attrs *)(x)->shost_data)->work_q_name)
  491. #define fc_host_work_q(x) \
  492. (((struct fc_host_attrs *)(x)->shost_data)->work_q)
  493. #define fc_host_devloss_work_q_name(x) \
  494. (((struct fc_host_attrs *)(x)->shost_data)->devloss_work_q_name)
  495. #define fc_host_devloss_work_q(x) \
  496. (((struct fc_host_attrs *)(x)->shost_data)->devloss_work_q)
  497. /* The functions by which the transport class and the driver communicate */
  498. struct fc_function_template {
  499. void (*get_rport_dev_loss_tmo)(struct fc_rport *);
  500. void (*set_rport_dev_loss_tmo)(struct fc_rport *, u32);
  501. void (*get_starget_node_name)(struct scsi_target *);
  502. void (*get_starget_port_name)(struct scsi_target *);
  503. void (*get_starget_port_id)(struct scsi_target *);
  504. void (*get_host_port_id)(struct Scsi_Host *);
  505. void (*get_host_port_type)(struct Scsi_Host *);
  506. void (*get_host_port_state)(struct Scsi_Host *);
  507. void (*get_host_active_fc4s)(struct Scsi_Host *);
  508. void (*get_host_speed)(struct Scsi_Host *);
  509. void (*get_host_fabric_name)(struct Scsi_Host *);
  510. void (*get_host_symbolic_name)(struct Scsi_Host *);
  511. void (*set_host_system_hostname)(struct Scsi_Host *);
  512. struct fc_host_statistics * (*get_fc_host_stats)(struct Scsi_Host *);
  513. void (*reset_fc_host_stats)(struct Scsi_Host *);
  514. int (*issue_fc_host_lip)(struct Scsi_Host *);
  515. void (*dev_loss_tmo_callbk)(struct fc_rport *);
  516. void (*terminate_rport_io)(struct fc_rport *);
  517. void (*set_vport_symbolic_name)(struct fc_vport *);
  518. int (*vport_create)(struct fc_vport *, bool);
  519. int (*vport_disable)(struct fc_vport *, bool);
  520. int (*vport_delete)(struct fc_vport *);
  521. /* allocation lengths for host-specific data */
  522. u32 dd_fcrport_size;
  523. u32 dd_fcvport_size;
  524. /*
  525. * The driver sets these to tell the transport class it
  526. * wants the attributes displayed in sysfs. If the show_ flag
  527. * is not set, the attribute will be private to the transport
  528. * class
  529. */
  530. /* remote port fixed attributes */
  531. unsigned long show_rport_maxframe_size:1;
  532. unsigned long show_rport_supported_classes:1;
  533. unsigned long show_rport_dev_loss_tmo:1;
  534. /*
  535. * target dynamic attributes
  536. * These should all be "1" if the driver uses the remote port
  537. * add/delete functions (so attributes reflect rport values).
  538. */
  539. unsigned long show_starget_node_name:1;
  540. unsigned long show_starget_port_name:1;
  541. unsigned long show_starget_port_id:1;
  542. /* host fixed attributes */
  543. unsigned long show_host_node_name:1;
  544. unsigned long show_host_port_name:1;
  545. unsigned long show_host_permanent_port_name:1;
  546. unsigned long show_host_supported_classes:1;
  547. unsigned long show_host_supported_fc4s:1;
  548. unsigned long show_host_supported_speeds:1;
  549. unsigned long show_host_maxframe_size:1;
  550. unsigned long show_host_serial_number:1;
  551. /* host dynamic attributes */
  552. unsigned long show_host_port_id:1;
  553. unsigned long show_host_port_type:1;
  554. unsigned long show_host_port_state:1;
  555. unsigned long show_host_active_fc4s:1;
  556. unsigned long show_host_speed:1;
  557. unsigned long show_host_fabric_name:1;
  558. unsigned long show_host_symbolic_name:1;
  559. unsigned long show_host_system_hostname:1;
  560. };
  561. /**
  562. * fc_remote_port_chkready - called to validate the remote port state
  563. * prior to initiating io to the port.
  564. *
  565. * Returns a scsi result code that can be returned by the LLDD.
  566. *
  567. * @rport: remote port to be checked
  568. **/
  569. static inline int
  570. fc_remote_port_chkready(struct fc_rport *rport)
  571. {
  572. int result;
  573. switch (rport->port_state) {
  574. case FC_PORTSTATE_ONLINE:
  575. if (rport->roles & FC_PORT_ROLE_FCP_TARGET)
  576. result = 0;
  577. else if (rport->flags & FC_RPORT_DEVLOSS_PENDING)
  578. result = DID_IMM_RETRY << 16;
  579. else
  580. result = DID_NO_CONNECT << 16;
  581. break;
  582. case FC_PORTSTATE_BLOCKED:
  583. result = DID_IMM_RETRY << 16;
  584. break;
  585. default:
  586. result = DID_NO_CONNECT << 16;
  587. break;
  588. }
  589. return result;
  590. }
  591. static inline u64 wwn_to_u64(u8 *wwn)
  592. {
  593. return (u64)wwn[0] << 56 | (u64)wwn[1] << 48 |
  594. (u64)wwn[2] << 40 | (u64)wwn[3] << 32 |
  595. (u64)wwn[4] << 24 | (u64)wwn[5] << 16 |
  596. (u64)wwn[6] << 8 | (u64)wwn[7];
  597. }
  598. static inline void u64_to_wwn(u64 inm, u8 *wwn)
  599. {
  600. wwn[0] = (inm >> 56) & 0xff;
  601. wwn[1] = (inm >> 48) & 0xff;
  602. wwn[2] = (inm >> 40) & 0xff;
  603. wwn[3] = (inm >> 32) & 0xff;
  604. wwn[4] = (inm >> 24) & 0xff;
  605. wwn[5] = (inm >> 16) & 0xff;
  606. wwn[6] = (inm >> 8) & 0xff;
  607. wwn[7] = inm & 0xff;
  608. }
  609. /**
  610. * fc_vport_set_state() - called to set a vport's state. Saves the old state,
  611. * excepting the transitory states of initializing and sending the ELS
  612. * traffic to instantiate the vport on the link.
  613. *
  614. * Assumes the driver has surrounded this with the proper locking to ensure
  615. * a coherent state change.
  616. *
  617. * @vport: virtual port whose state is changing
  618. * @new_state: new state
  619. **/
  620. static inline void
  621. fc_vport_set_state(struct fc_vport *vport, enum fc_vport_state new_state)
  622. {
  623. if ((new_state != FC_VPORT_UNKNOWN) &&
  624. (new_state != FC_VPORT_INITIALIZING))
  625. vport->vport_last_state = vport->vport_state;
  626. vport->vport_state = new_state;
  627. }
  628. struct scsi_transport_template *fc_attach_transport(
  629. struct fc_function_template *);
  630. void fc_release_transport(struct scsi_transport_template *);
  631. void fc_remove_host(struct Scsi_Host *);
  632. struct fc_rport *fc_remote_port_add(struct Scsi_Host *shost,
  633. int channel, struct fc_rport_identifiers *ids);
  634. void fc_remote_port_delete(struct fc_rport *rport);
  635. void fc_remote_port_rolechg(struct fc_rport *rport, u32 roles);
  636. int scsi_is_fc_rport(const struct device *);
  637. u32 fc_get_event_number(void);
  638. void fc_host_post_event(struct Scsi_Host *shost, u32 event_number,
  639. enum fc_host_event_code event_code, u32 event_data);
  640. void fc_host_post_vendor_event(struct Scsi_Host *shost, u32 event_number,
  641. u32 data_len, char * data_buf, u64 vendor_id);
  642. /* Note: when specifying vendor_id to fc_host_post_vendor_event()
  643. * be sure to read the Vendor Type and ID formatting requirements
  644. * specified in scsi_netlink.h
  645. */
  646. int fc_vport_terminate(struct fc_vport *vport);
  647. #endif /* SCSI_TRANSPORT_FC_H */