PageRenderTime 27ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/include/scsi/scsi_transport_fc.h

https://github.com/mstsirkin/kvm
C Header | 815 lines | 455 code | 93 blank | 267 comment | 8 complexity | c5c03d57abdc73fa9dfd781bddfede07 MD5 | raw file
  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 device_attribute dev_attr_vport_##_name = \
  150. __ATTR(_name,_mode,_show,_store)
  151. /*
  152. * fc_vport_identifiers: This set of data contains all elements
  153. * to uniquely identify and instantiate a FC virtual port.
  154. *
  155. * Notes:
  156. * symbolic_name: The driver is to append the symbolic_name string data
  157. * to the symbolic_node_name data that it generates by default.
  158. * the resulting combination should then be registered with the switch.
  159. * It is expected that things like Xen may stuff a VM title into
  160. * this field.
  161. */
  162. #define FC_VPORT_SYMBOLIC_NAMELEN 64
  163. struct fc_vport_identifiers {
  164. u64 node_name;
  165. u64 port_name;
  166. u32 roles;
  167. bool disable;
  168. enum fc_port_type vport_type; /* only FC_PORTTYPE_NPIV allowed */
  169. char symbolic_name[FC_VPORT_SYMBOLIC_NAMELEN];
  170. };
  171. /*
  172. * FC Virtual Port Attributes
  173. *
  174. * This structure exists for each FC port is a virtual FC port. Virtual
  175. * ports share the physical link with the Physical port. Each virtual
  176. * ports has a unique presence on the SAN, and may be instantiated via
  177. * NPIV, Virtual Fabrics, or via additional ALPAs. As the vport is a
  178. * unique presence, each vport has it's own view of the fabric,
  179. * authentication privilege, and priorities.
  180. *
  181. * A virtual port may support 1 or more FC4 roles. Typically it is a
  182. * FCP Initiator. It could be a FCP Target, or exist sole for an IP over FC
  183. * roles. FC port attributes for the vport will be reported on any
  184. * fc_host class object allocated for an FCP Initiator.
  185. *
  186. * --
  187. *
  188. * Fixed attributes are not expected to change. The driver is
  189. * expected to set these values after receiving the fc_vport structure
  190. * via the vport_create() call from the transport.
  191. * The transport fully manages all get functions w/o driver interaction.
  192. *
  193. * Dynamic attributes are expected to change. The driver participates
  194. * in all get/set operations via functions provided by the driver.
  195. *
  196. * Private attributes are transport-managed values. They are fully
  197. * managed by the transport w/o driver interaction.
  198. */
  199. struct fc_vport {
  200. /* Fixed Attributes */
  201. /* Dynamic Attributes */
  202. /* Private (Transport-managed) Attributes */
  203. enum fc_vport_state vport_state;
  204. enum fc_vport_state vport_last_state;
  205. u64 node_name;
  206. u64 port_name;
  207. u32 roles;
  208. u32 vport_id; /* Admin Identifier for the vport */
  209. enum fc_port_type vport_type;
  210. char symbolic_name[FC_VPORT_SYMBOLIC_NAMELEN];
  211. /* exported data */
  212. void *dd_data; /* Used for driver-specific storage */
  213. /* internal data */
  214. struct Scsi_Host *shost; /* Physical Port Parent */
  215. unsigned int channel;
  216. u32 number;
  217. u8 flags;
  218. struct list_head peers;
  219. struct device dev;
  220. struct work_struct vport_delete_work;
  221. } __attribute__((aligned(sizeof(unsigned long))));
  222. /* bit field values for struct fc_vport "flags" field: */
  223. #define FC_VPORT_CREATING 0x01
  224. #define FC_VPORT_DELETING 0x02
  225. #define FC_VPORT_DELETED 0x04
  226. #define FC_VPORT_DEL 0x06 /* Any DELETE state */
  227. #define dev_to_vport(d) \
  228. container_of(d, struct fc_vport, dev)
  229. #define transport_class_to_vport(dev) \
  230. dev_to_vport(dev->parent)
  231. #define vport_to_shost(v) \
  232. (v->shost)
  233. #define vport_to_shost_channel(v) \
  234. (v->channel)
  235. #define vport_to_parent(v) \
  236. (v->dev.parent)
  237. /* Error return codes for vport_create() callback */
  238. #define VPCERR_UNSUPPORTED -ENOSYS /* no driver/adapter
  239. support */
  240. #define VPCERR_BAD_WWN -ENOTUNIQ /* driver validation
  241. of WWNs failed */
  242. #define VPCERR_NO_FABRIC_SUPP -EOPNOTSUPP /* Fabric connection
  243. is loop or the
  244. Fabric Port does
  245. not support NPIV */
  246. /*
  247. * fc_rport_identifiers: This set of data contains all elements
  248. * to uniquely identify a remote FC port. The driver uses this data
  249. * to report the existence of a remote FC port in the topology. Internally,
  250. * the transport uses this data for attributes and to manage consistent
  251. * target id bindings.
  252. */
  253. struct fc_rport_identifiers {
  254. u64 node_name;
  255. u64 port_name;
  256. u32 port_id;
  257. u32 roles;
  258. };
  259. /* Macro for use in defining Remote Port attributes */
  260. #define FC_RPORT_ATTR(_name,_mode,_show,_store) \
  261. struct device_attribute dev_attr_rport_##_name = \
  262. __ATTR(_name,_mode,_show,_store)
  263. /*
  264. * FC Remote Port Attributes
  265. *
  266. * This structure exists for each remote FC port that a LLDD notifies
  267. * the subsystem of. A remote FC port may or may not be a SCSI Target,
  268. * also be a SCSI initiator, IP endpoint, etc. As such, the remote
  269. * port is considered a separate entity, independent of "role" (such
  270. * as scsi target).
  271. *
  272. * --
  273. *
  274. * Attributes are based on HBAAPI V2.0 definitions. Only those
  275. * attributes that are determinable by the local port (aka Host)
  276. * are contained.
  277. *
  278. * Fixed attributes are not expected to change. The driver is
  279. * expected to set these values after successfully calling
  280. * fc_remote_port_add(). The transport fully manages all get functions
  281. * w/o driver interaction.
  282. *
  283. * Dynamic attributes are expected to change. The driver participates
  284. * in all get/set operations via functions provided by the driver.
  285. *
  286. * Private attributes are transport-managed values. They are fully
  287. * managed by the transport w/o driver interaction.
  288. */
  289. struct fc_rport { /* aka fc_starget_attrs */
  290. /* Fixed Attributes */
  291. u32 maxframe_size;
  292. u32 supported_classes;
  293. /* Dynamic Attributes */
  294. u32 dev_loss_tmo; /* Remote Port loss timeout in seconds. */
  295. /* Private (Transport-managed) Attributes */
  296. u64 node_name;
  297. u64 port_name;
  298. u32 port_id;
  299. u32 roles;
  300. enum fc_port_state port_state; /* Will only be ONLINE or UNKNOWN */
  301. u32 scsi_target_id;
  302. u32 fast_io_fail_tmo;
  303. /* exported data */
  304. void *dd_data; /* Used for driver-specific storage */
  305. /* internal data */
  306. unsigned int channel;
  307. u32 number;
  308. u8 flags;
  309. struct list_head peers;
  310. struct device dev;
  311. struct delayed_work dev_loss_work;
  312. struct work_struct scan_work;
  313. struct delayed_work fail_io_work;
  314. struct work_struct stgt_delete_work;
  315. struct work_struct rport_delete_work;
  316. struct request_queue *rqst_q; /* bsg support */
  317. } __attribute__((aligned(sizeof(unsigned long))));
  318. /* bit field values for struct fc_rport "flags" field: */
  319. #define FC_RPORT_DEVLOSS_PENDING 0x01
  320. #define FC_RPORT_SCAN_PENDING 0x02
  321. #define FC_RPORT_FAST_FAIL_TIMEDOUT 0x04
  322. #define FC_RPORT_DEVLOSS_CALLBK_DONE 0x08
  323. #define dev_to_rport(d) \
  324. container_of(d, struct fc_rport, dev)
  325. #define transport_class_to_rport(dev) \
  326. dev_to_rport(dev->parent)
  327. #define rport_to_shost(r) \
  328. dev_to_shost(r->dev.parent)
  329. /*
  330. * FC SCSI Target Attributes
  331. *
  332. * The SCSI Target is considered an extension of a remote port (as
  333. * a remote port can be more than a SCSI Target). Within the scsi
  334. * subsystem, we leave the Target as a separate entity. Doing so
  335. * provides backward compatibility with prior FC transport api's,
  336. * and lets remote ports be handled entirely within the FC transport
  337. * and independently from the scsi subsystem. The drawback is that
  338. * some data will be duplicated.
  339. */
  340. struct fc_starget_attrs { /* aka fc_target_attrs */
  341. /* Dynamic Attributes */
  342. u64 node_name;
  343. u64 port_name;
  344. u32 port_id;
  345. };
  346. #define fc_starget_node_name(x) \
  347. (((struct fc_starget_attrs *)&(x)->starget_data)->node_name)
  348. #define fc_starget_port_name(x) \
  349. (((struct fc_starget_attrs *)&(x)->starget_data)->port_name)
  350. #define fc_starget_port_id(x) \
  351. (((struct fc_starget_attrs *)&(x)->starget_data)->port_id)
  352. #define starget_to_rport(s) \
  353. scsi_is_fc_rport(s->dev.parent) ? dev_to_rport(s->dev.parent) : NULL
  354. /*
  355. * FC Local Port (Host) Statistics
  356. */
  357. /* FC Statistics - Following FC HBAAPI v2.0 guidelines */
  358. struct fc_host_statistics {
  359. /* port statistics */
  360. u64 seconds_since_last_reset;
  361. u64 tx_frames;
  362. u64 tx_words;
  363. u64 rx_frames;
  364. u64 rx_words;
  365. u64 lip_count;
  366. u64 nos_count;
  367. u64 error_frames;
  368. u64 dumped_frames;
  369. u64 link_failure_count;
  370. u64 loss_of_sync_count;
  371. u64 loss_of_signal_count;
  372. u64 prim_seq_protocol_err_count;
  373. u64 invalid_tx_word_count;
  374. u64 invalid_crc_count;
  375. /* fc4 statistics (only FCP supported currently) */
  376. u64 fcp_input_requests;
  377. u64 fcp_output_requests;
  378. u64 fcp_control_requests;
  379. u64 fcp_input_megabytes;
  380. u64 fcp_output_megabytes;
  381. };
  382. /*
  383. * FC Event Codes - Polled and Async, following FC HBAAPI v2.0 guidelines
  384. */
  385. /*
  386. * fc_host_event_code: If you alter this, you also need to alter
  387. * scsi_transport_fc.c (for the ascii descriptions).
  388. */
  389. enum fc_host_event_code {
  390. FCH_EVT_LIP = 0x1,
  391. FCH_EVT_LINKUP = 0x2,
  392. FCH_EVT_LINKDOWN = 0x3,
  393. FCH_EVT_LIPRESET = 0x4,
  394. FCH_EVT_RSCN = 0x5,
  395. FCH_EVT_ADAPTER_CHANGE = 0x103,
  396. FCH_EVT_PORT_UNKNOWN = 0x200,
  397. FCH_EVT_PORT_OFFLINE = 0x201,
  398. FCH_EVT_PORT_ONLINE = 0x202,
  399. FCH_EVT_PORT_FABRIC = 0x204,
  400. FCH_EVT_LINK_UNKNOWN = 0x500,
  401. FCH_EVT_VENDOR_UNIQUE = 0xffff,
  402. };
  403. /*
  404. * FC Local Port (Host) Attributes
  405. *
  406. * Attributes are based on HBAAPI V2.0 definitions.
  407. * Note: OSDeviceName is determined by user-space library
  408. *
  409. * Fixed attributes are not expected to change. The driver is
  410. * expected to set these values after successfully calling scsi_add_host().
  411. * The transport fully manages all get functions w/o driver interaction.
  412. *
  413. * Dynamic attributes are expected to change. The driver participates
  414. * in all get/set operations via functions provided by the driver.
  415. *
  416. * Private attributes are transport-managed values. They are fully
  417. * managed by the transport w/o driver interaction.
  418. */
  419. #define FC_FC4_LIST_SIZE 32
  420. #define FC_SYMBOLIC_NAME_SIZE 256
  421. #define FC_VERSION_STRING_SIZE 64
  422. #define FC_SERIAL_NUMBER_SIZE 80
  423. struct fc_host_attrs {
  424. /* Fixed Attributes */
  425. u64 node_name;
  426. u64 port_name;
  427. u64 permanent_port_name;
  428. u32 supported_classes;
  429. u8 supported_fc4s[FC_FC4_LIST_SIZE];
  430. u32 supported_speeds;
  431. u32 maxframe_size;
  432. u16 max_npiv_vports;
  433. char serial_number[FC_SERIAL_NUMBER_SIZE];
  434. /* Dynamic Attributes */
  435. u32 port_id;
  436. enum fc_port_type port_type;
  437. enum fc_port_state port_state;
  438. u8 active_fc4s[FC_FC4_LIST_SIZE];
  439. u32 speed;
  440. u64 fabric_name;
  441. char symbolic_name[FC_SYMBOLIC_NAME_SIZE];
  442. char system_hostname[FC_SYMBOLIC_NAME_SIZE];
  443. u32 dev_loss_tmo;
  444. /* Private (Transport-managed) Attributes */
  445. enum fc_tgtid_binding_type tgtid_bind_type;
  446. /* internal data */
  447. struct list_head rports;
  448. struct list_head rport_bindings;
  449. struct list_head vports;
  450. u32 next_rport_number;
  451. u32 next_target_id;
  452. u32 next_vport_number;
  453. u16 npiv_vports_inuse;
  454. /* work queues for rport state manipulation */
  455. char work_q_name[20];
  456. struct workqueue_struct *work_q;
  457. char devloss_work_q_name[20];
  458. struct workqueue_struct *devloss_work_q;
  459. /* bsg support */
  460. struct request_queue *rqst_q;
  461. };
  462. #define shost_to_fc_host(x) \
  463. ((struct fc_host_attrs *)(x)->shost_data)
  464. #define fc_host_node_name(x) \
  465. (((struct fc_host_attrs *)(x)->shost_data)->node_name)
  466. #define fc_host_port_name(x) \
  467. (((struct fc_host_attrs *)(x)->shost_data)->port_name)
  468. #define fc_host_permanent_port_name(x) \
  469. (((struct fc_host_attrs *)(x)->shost_data)->permanent_port_name)
  470. #define fc_host_supported_classes(x) \
  471. (((struct fc_host_attrs *)(x)->shost_data)->supported_classes)
  472. #define fc_host_supported_fc4s(x) \
  473. (((struct fc_host_attrs *)(x)->shost_data)->supported_fc4s)
  474. #define fc_host_supported_speeds(x) \
  475. (((struct fc_host_attrs *)(x)->shost_data)->supported_speeds)
  476. #define fc_host_maxframe_size(x) \
  477. (((struct fc_host_attrs *)(x)->shost_data)->maxframe_size)
  478. #define fc_host_max_npiv_vports(x) \
  479. (((struct fc_host_attrs *)(x)->shost_data)->max_npiv_vports)
  480. #define fc_host_serial_number(x) \
  481. (((struct fc_host_attrs *)(x)->shost_data)->serial_number)
  482. #define fc_host_port_id(x) \
  483. (((struct fc_host_attrs *)(x)->shost_data)->port_id)
  484. #define fc_host_port_type(x) \
  485. (((struct fc_host_attrs *)(x)->shost_data)->port_type)
  486. #define fc_host_port_state(x) \
  487. (((struct fc_host_attrs *)(x)->shost_data)->port_state)
  488. #define fc_host_active_fc4s(x) \
  489. (((struct fc_host_attrs *)(x)->shost_data)->active_fc4s)
  490. #define fc_host_speed(x) \
  491. (((struct fc_host_attrs *)(x)->shost_data)->speed)
  492. #define fc_host_fabric_name(x) \
  493. (((struct fc_host_attrs *)(x)->shost_data)->fabric_name)
  494. #define fc_host_symbolic_name(x) \
  495. (((struct fc_host_attrs *)(x)->shost_data)->symbolic_name)
  496. #define fc_host_system_hostname(x) \
  497. (((struct fc_host_attrs *)(x)->shost_data)->system_hostname)
  498. #define fc_host_tgtid_bind_type(x) \
  499. (((struct fc_host_attrs *)(x)->shost_data)->tgtid_bind_type)
  500. #define fc_host_rports(x) \
  501. (((struct fc_host_attrs *)(x)->shost_data)->rports)
  502. #define fc_host_rport_bindings(x) \
  503. (((struct fc_host_attrs *)(x)->shost_data)->rport_bindings)
  504. #define fc_host_vports(x) \
  505. (((struct fc_host_attrs *)(x)->shost_data)->vports)
  506. #define fc_host_next_rport_number(x) \
  507. (((struct fc_host_attrs *)(x)->shost_data)->next_rport_number)
  508. #define fc_host_next_target_id(x) \
  509. (((struct fc_host_attrs *)(x)->shost_data)->next_target_id)
  510. #define fc_host_next_vport_number(x) \
  511. (((struct fc_host_attrs *)(x)->shost_data)->next_vport_number)
  512. #define fc_host_npiv_vports_inuse(x) \
  513. (((struct fc_host_attrs *)(x)->shost_data)->npiv_vports_inuse)
  514. #define fc_host_work_q_name(x) \
  515. (((struct fc_host_attrs *)(x)->shost_data)->work_q_name)
  516. #define fc_host_work_q(x) \
  517. (((struct fc_host_attrs *)(x)->shost_data)->work_q)
  518. #define fc_host_devloss_work_q_name(x) \
  519. (((struct fc_host_attrs *)(x)->shost_data)->devloss_work_q_name)
  520. #define fc_host_devloss_work_q(x) \
  521. (((struct fc_host_attrs *)(x)->shost_data)->devloss_work_q)
  522. #define fc_host_dev_loss_tmo(x) \
  523. (((struct fc_host_attrs *)(x)->shost_data)->dev_loss_tmo)
  524. struct fc_bsg_buffer {
  525. unsigned int payload_len;
  526. int sg_cnt;
  527. struct scatterlist *sg_list;
  528. };
  529. /* Values for fc_bsg_job->state_flags (bitflags) */
  530. #define FC_RQST_STATE_INPROGRESS 0
  531. #define FC_RQST_STATE_DONE 1
  532. struct fc_bsg_job {
  533. struct Scsi_Host *shost;
  534. struct fc_rport *rport;
  535. struct device *dev;
  536. struct request *req;
  537. spinlock_t job_lock;
  538. unsigned int state_flags;
  539. unsigned int ref_cnt;
  540. void (*job_done)(struct fc_bsg_job *);
  541. struct fc_bsg_request *request;
  542. struct fc_bsg_reply *reply;
  543. unsigned int request_len;
  544. unsigned int reply_len;
  545. /*
  546. * On entry : reply_len indicates the buffer size allocated for
  547. * the reply.
  548. *
  549. * Upon completion : the message handler must set reply_len
  550. * to indicates the size of the reply to be returned to the
  551. * caller.
  552. */
  553. /* DMA payloads for the request/response */
  554. struct fc_bsg_buffer request_payload;
  555. struct fc_bsg_buffer reply_payload;
  556. void *dd_data; /* Used for driver-specific storage */
  557. };
  558. /* The functions by which the transport class and the driver communicate */
  559. struct fc_function_template {
  560. void (*get_rport_dev_loss_tmo)(struct fc_rport *);
  561. void (*set_rport_dev_loss_tmo)(struct fc_rport *, u32);
  562. void (*get_starget_node_name)(struct scsi_target *);
  563. void (*get_starget_port_name)(struct scsi_target *);
  564. void (*get_starget_port_id)(struct scsi_target *);
  565. void (*get_host_port_id)(struct Scsi_Host *);
  566. void (*get_host_port_type)(struct Scsi_Host *);
  567. void (*get_host_port_state)(struct Scsi_Host *);
  568. void (*get_host_active_fc4s)(struct Scsi_Host *);
  569. void (*get_host_speed)(struct Scsi_Host *);
  570. void (*get_host_fabric_name)(struct Scsi_Host *);
  571. void (*get_host_symbolic_name)(struct Scsi_Host *);
  572. void (*set_host_system_hostname)(struct Scsi_Host *);
  573. struct fc_host_statistics * (*get_fc_host_stats)(struct Scsi_Host *);
  574. void (*reset_fc_host_stats)(struct Scsi_Host *);
  575. int (*issue_fc_host_lip)(struct Scsi_Host *);
  576. void (*dev_loss_tmo_callbk)(struct fc_rport *);
  577. void (*terminate_rport_io)(struct fc_rport *);
  578. void (*set_vport_symbolic_name)(struct fc_vport *);
  579. int (*vport_create)(struct fc_vport *, bool);
  580. int (*vport_disable)(struct fc_vport *, bool);
  581. int (*vport_delete)(struct fc_vport *);
  582. /* target-mode drivers' functions */
  583. int (* tsk_mgmt_response)(struct Scsi_Host *, u64, u64, int);
  584. int (* it_nexus_response)(struct Scsi_Host *, u64, int);
  585. /* bsg support */
  586. int (*bsg_request)(struct fc_bsg_job *);
  587. int (*bsg_timeout)(struct fc_bsg_job *);
  588. /* allocation lengths for host-specific data */
  589. u32 dd_fcrport_size;
  590. u32 dd_fcvport_size;
  591. u32 dd_bsg_size;
  592. /*
  593. * The driver sets these to tell the transport class it
  594. * wants the attributes displayed in sysfs. If the show_ flag
  595. * is not set, the attribute will be private to the transport
  596. * class
  597. */
  598. /* remote port fixed attributes */
  599. unsigned long show_rport_maxframe_size:1;
  600. unsigned long show_rport_supported_classes:1;
  601. unsigned long show_rport_dev_loss_tmo:1;
  602. /*
  603. * target dynamic attributes
  604. * These should all be "1" if the driver uses the remote port
  605. * add/delete functions (so attributes reflect rport values).
  606. */
  607. unsigned long show_starget_node_name:1;
  608. unsigned long show_starget_port_name:1;
  609. unsigned long show_starget_port_id:1;
  610. /* host fixed attributes */
  611. unsigned long show_host_node_name:1;
  612. unsigned long show_host_port_name:1;
  613. unsigned long show_host_permanent_port_name:1;
  614. unsigned long show_host_supported_classes:1;
  615. unsigned long show_host_supported_fc4s:1;
  616. unsigned long show_host_supported_speeds:1;
  617. unsigned long show_host_maxframe_size:1;
  618. unsigned long show_host_serial_number:1;
  619. /* host dynamic attributes */
  620. unsigned long show_host_port_id:1;
  621. unsigned long show_host_port_type:1;
  622. unsigned long show_host_port_state:1;
  623. unsigned long show_host_active_fc4s:1;
  624. unsigned long show_host_speed:1;
  625. unsigned long show_host_fabric_name:1;
  626. unsigned long show_host_symbolic_name:1;
  627. unsigned long show_host_system_hostname:1;
  628. unsigned long disable_target_scan:1;
  629. };
  630. /**
  631. * fc_remote_port_chkready - called to validate the remote port state
  632. * prior to initiating io to the port.
  633. *
  634. * Returns a scsi result code that can be returned by the LLDD.
  635. *
  636. * @rport: remote port to be checked
  637. **/
  638. static inline int
  639. fc_remote_port_chkready(struct fc_rport *rport)
  640. {
  641. int result;
  642. switch (rport->port_state) {
  643. case FC_PORTSTATE_ONLINE:
  644. if (rport->roles & FC_PORT_ROLE_FCP_TARGET)
  645. result = 0;
  646. else if (rport->flags & FC_RPORT_DEVLOSS_PENDING)
  647. result = DID_IMM_RETRY << 16;
  648. else
  649. result = DID_NO_CONNECT << 16;
  650. break;
  651. case FC_PORTSTATE_BLOCKED:
  652. if (rport->flags & FC_RPORT_FAST_FAIL_TIMEDOUT)
  653. result = DID_TRANSPORT_FAILFAST << 16;
  654. else
  655. result = DID_IMM_RETRY << 16;
  656. break;
  657. default:
  658. result = DID_NO_CONNECT << 16;
  659. break;
  660. }
  661. return result;
  662. }
  663. static inline u64 wwn_to_u64(u8 *wwn)
  664. {
  665. return (u64)wwn[0] << 56 | (u64)wwn[1] << 48 |
  666. (u64)wwn[2] << 40 | (u64)wwn[3] << 32 |
  667. (u64)wwn[4] << 24 | (u64)wwn[5] << 16 |
  668. (u64)wwn[6] << 8 | (u64)wwn[7];
  669. }
  670. static inline void u64_to_wwn(u64 inm, u8 *wwn)
  671. {
  672. wwn[0] = (inm >> 56) & 0xff;
  673. wwn[1] = (inm >> 48) & 0xff;
  674. wwn[2] = (inm >> 40) & 0xff;
  675. wwn[3] = (inm >> 32) & 0xff;
  676. wwn[4] = (inm >> 24) & 0xff;
  677. wwn[5] = (inm >> 16) & 0xff;
  678. wwn[6] = (inm >> 8) & 0xff;
  679. wwn[7] = inm & 0xff;
  680. }
  681. /**
  682. * fc_vport_set_state() - called to set a vport's state. Saves the old state,
  683. * excepting the transitory states of initializing and sending the ELS
  684. * traffic to instantiate the vport on the link.
  685. *
  686. * Assumes the driver has surrounded this with the proper locking to ensure
  687. * a coherent state change.
  688. *
  689. * @vport: virtual port whose state is changing
  690. * @new_state: new state
  691. **/
  692. static inline void
  693. fc_vport_set_state(struct fc_vport *vport, enum fc_vport_state new_state)
  694. {
  695. if ((new_state != FC_VPORT_UNKNOWN) &&
  696. (new_state != FC_VPORT_INITIALIZING))
  697. vport->vport_last_state = vport->vport_state;
  698. vport->vport_state = new_state;
  699. }
  700. struct scsi_transport_template *fc_attach_transport(
  701. struct fc_function_template *);
  702. void fc_release_transport(struct scsi_transport_template *);
  703. void fc_remove_host(struct Scsi_Host *);
  704. struct fc_rport *fc_remote_port_add(struct Scsi_Host *shost,
  705. int channel, struct fc_rport_identifiers *ids);
  706. void fc_remote_port_delete(struct fc_rport *rport);
  707. void fc_remote_port_rolechg(struct fc_rport *rport, u32 roles);
  708. int scsi_is_fc_rport(const struct device *);
  709. u32 fc_get_event_number(void);
  710. void fc_host_post_event(struct Scsi_Host *shost, u32 event_number,
  711. enum fc_host_event_code event_code, u32 event_data);
  712. void fc_host_post_vendor_event(struct Scsi_Host *shost, u32 event_number,
  713. u32 data_len, char * data_buf, u64 vendor_id);
  714. /* Note: when specifying vendor_id to fc_host_post_vendor_event()
  715. * be sure to read the Vendor Type and ID formatting requirements
  716. * specified in scsi_netlink.h
  717. */
  718. struct fc_vport *fc_vport_create(struct Scsi_Host *shost, int channel,
  719. struct fc_vport_identifiers *);
  720. int fc_vport_terminate(struct fc_vport *vport);
  721. int fc_block_scsi_eh(struct scsi_cmnd *cmnd);
  722. #endif /* SCSI_TRANSPORT_FC_H */