scsi_transport_fc.h 26 KB

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