scsi_bsg_fc.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. //
  2. // Copyright 2026 Aarav Ravindra Kharade
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
  17. /*
  18. * FC Transport BSG Interface
  19. *
  20. * Copyright (C) 2008 James Smart, Emulex Corporation
  21. */
  22. #ifndef SCSI_BSG_FC_H
  23. #define SCSI_BSG_FC_H
  24. #include <linux/types.h>
  25. /*
  26. * This file intended to be included by both kernel and user space
  27. */
  28. /*
  29. * FC Transport SGIO v4 BSG Message Support
  30. */
  31. /* Default BSG request timeout (in seconds) */
  32. #define FC_DEFAULT_BSG_TIMEOUT (10 * HZ)
  33. /*
  34. * Request Message Codes supported by the FC Transport
  35. */
  36. /* define the class masks for the message codes */
  37. #define FC_BSG_CLS_MASK 0xF0000000 /* find object class */
  38. #define FC_BSG_HST_MASK 0x80000000 /* fc host class */
  39. #define FC_BSG_RPT_MASK 0x40000000 /* fc rport class */
  40. /* fc_host Message Codes */
  41. #define FC_BSG_HST_ADD_RPORT (FC_BSG_HST_MASK | 0x00000001)
  42. #define FC_BSG_HST_DEL_RPORT (FC_BSG_HST_MASK | 0x00000002)
  43. #define FC_BSG_HST_ELS_NOLOGIN (FC_BSG_HST_MASK | 0x00000003)
  44. #define FC_BSG_HST_CT (FC_BSG_HST_MASK | 0x00000004)
  45. #define FC_BSG_HST_VENDOR (FC_BSG_HST_MASK | 0x000000FF)
  46. /* fc_rport Message Codes */
  47. #define FC_BSG_RPT_ELS (FC_BSG_RPT_MASK | 0x00000001)
  48. #define FC_BSG_RPT_CT (FC_BSG_RPT_MASK | 0x00000002)
  49. /*
  50. * FC Address Identifiers in Message Structures :
  51. *
  52. * Whenever a command payload contains a FC Address Identifier
  53. * (aka port_id), the value is effectively in big-endian
  54. * order, thus the array elements are decoded as follows:
  55. * element [0] is bits 23:16 of the FC Address Identifier
  56. * element [1] is bits 15:8 of the FC Address Identifier
  57. * element [2] is bits 7:0 of the FC Address Identifier
  58. */
  59. /*
  60. * FC Host Messages
  61. */
  62. /* FC_BSG_HST_ADDR_PORT : */
  63. /* Request:
  64. * This message requests the FC host to login to the remote port
  65. * at the specified N_Port_Id. The remote port is to be enumerated
  66. * with the transport upon completion of the login.
  67. */
  68. struct fc_bsg_host_add_rport {
  69. __u8 reserved;
  70. /* FC Address Identier of the remote port to login to */
  71. __u8 port_id[3];
  72. };
  73. /* Response:
  74. * There is no additional response data - fc_bsg_reply->result is sufficient
  75. */
  76. /* FC_BSG_HST_DEL_RPORT : */
  77. /* Request:
  78. * This message requests the FC host to remove an enumerated
  79. * remote port and to terminate the login to it.
  80. *
  81. * Note: The driver is free to reject this request if it desires to
  82. * remain logged in with the remote port.
  83. */
  84. struct fc_bsg_host_del_rport {
  85. __u8 reserved;
  86. /* FC Address Identier of the remote port to logout of */
  87. __u8 port_id[3];
  88. };
  89. /* Response:
  90. * There is no additional response data - fc_bsg_reply->result is sufficient
  91. */
  92. /* FC_BSG_HST_ELS_NOLOGIN : */
  93. /* Request:
  94. * This message requests the FC_Host to send an ELS to a specific
  95. * N_Port_ID. The host does not need to log into the remote port,
  96. * nor does it need to enumerate the rport for further traffic
  97. * (although, the FC host is free to do so if it desires).
  98. */
  99. struct fc_bsg_host_els {
  100. /*
  101. * ELS Command Code being sent (must be the same as byte 0
  102. * of the payload)
  103. */
  104. __u8 command_code;
  105. /* FC Address Identier of the remote port to send the ELS to */
  106. __u8 port_id[3];
  107. };
  108. /* Response:
  109. */
  110. /* fc_bsg_ctels_reply->status values */
  111. #define FC_CTELS_STATUS_OK 0x00000000
  112. #define FC_CTELS_STATUS_REJECT 0x00000001
  113. #define FC_CTELS_STATUS_P_RJT 0x00000002
  114. #define FC_CTELS_STATUS_F_RJT 0x00000003
  115. #define FC_CTELS_STATUS_P_BSY 0x00000004
  116. #define FC_CTELS_STATUS_F_BSY 0x00000006
  117. struct fc_bsg_ctels_reply {
  118. /*
  119. * Note: An ELS LS_RJT may be reported in 2 ways:
  120. * a) A status of FC_CTELS_STATUS_OK is returned. The caller
  121. * is to look into the ELS receive payload to determine
  122. * LS_ACC or LS_RJT (by contents of word 0). The reject
  123. * data will be in word 1.
  124. * b) A status of FC_CTELS_STATUS_REJECT is returned, The
  125. * rjt_data field will contain valid data.
  126. *
  127. * Note: ELS LS_ACC is determined by an FC_CTELS_STATUS_OK, and
  128. * the receive payload word 0 indicates LS_ACC
  129. * (e.g. value is 0x02xxxxxx).
  130. *
  131. * Note: Similarly, a CT Reject may be reported in 2 ways:
  132. * a) A status of FC_CTELS_STATUS_OK is returned. The caller
  133. * is to look into the CT receive payload to determine
  134. * Accept or Reject (by contents of word 2). The reject
  135. * data will be in word 3.
  136. * b) A status of FC_CTELS_STATUS_REJECT is returned, The
  137. * rjt_data field will contain valid data.
  138. *
  139. * Note: x_RJT/BSY status will indicae that the rjt_data field
  140. * is valid and contains the reason/explanation values.
  141. */
  142. __u32 status; /* See FC_CTELS_STATUS_xxx */
  143. /* valid if status is not FC_CTELS_STATUS_OK */
  144. struct {
  145. __u8 action; /* fragment_id for CT REJECT */
  146. __u8 reason_code;
  147. __u8 reason_explanation;
  148. __u8 vendor_unique;
  149. } rjt_data;
  150. };
  151. /* FC_BSG_HST_CT : */
  152. /* Request:
  153. * This message requests that a CT Request be performed with the
  154. * indicated N_Port_ID. The driver is responsible for logging in with
  155. * the fabric and/or N_Port_ID, etc as per FC rules. This request does
  156. * not mandate that the driver must enumerate the destination in the
  157. * transport. The driver is allowed to decide whether to enumerate it,
  158. * and whether to tear it down after the request.
  159. */
  160. struct fc_bsg_host_ct {
  161. __u8 reserved;
  162. /* FC Address Identier of the remote port to send the ELS to */
  163. __u8 port_id[3];
  164. /*
  165. * We need words 0-2 of the generic preamble for the LLD's
  166. */
  167. __u32 preamble_word0; /* revision & IN_ID */
  168. __u32 preamble_word1; /* GS_Type, GS_SubType, Options, Rsvd */
  169. __u32 preamble_word2; /* Cmd Code, Max Size */
  170. };
  171. /* Response:
  172. *
  173. * The reply structure is an fc_bsg_ctels_reply structure
  174. */
  175. /* FC_BSG_HST_VENDOR : */
  176. /* Request:
  177. * Note: When specifying vendor_id, be sure to read the Vendor Type and ID
  178. * formatting requirements specified in scsi_netlink.h
  179. */
  180. struct fc_bsg_host_vendor {
  181. /*
  182. * Identifies the vendor that the message is formatted for. This
  183. * should be the recipient of the message.
  184. */
  185. __u64 vendor_id;
  186. /* start of vendor command area */
  187. __u32 vendor_cmd[];
  188. };
  189. /* Response:
  190. */
  191. struct fc_bsg_host_vendor_reply {
  192. /* start of vendor response area */
  193. __DECLARE_FLEX_ARRAY(__u32, vendor_rsp);
  194. };
  195. /*
  196. * FC Remote Port Messages
  197. */
  198. /* FC_BSG_RPT_ELS : */
  199. /* Request:
  200. * This message requests that an ELS be performed with the rport.
  201. */
  202. struct fc_bsg_rport_els {
  203. /*
  204. * ELS Command Code being sent (must be the same as
  205. * byte 0 of the payload)
  206. */
  207. __u8 els_code;
  208. };
  209. /* Response:
  210. *
  211. * The reply structure is an fc_bsg_ctels_reply structure
  212. */
  213. /* FC_BSG_RPT_CT : */
  214. /* Request:
  215. * This message requests that a CT Request be performed with the rport.
  216. */
  217. struct fc_bsg_rport_ct {
  218. /*
  219. * We need words 0-2 of the generic preamble for the LLD's
  220. */
  221. __u32 preamble_word0; /* revision & IN_ID */
  222. __u32 preamble_word1; /* GS_Type, GS_SubType, Options, Rsvd */
  223. __u32 preamble_word2; /* Cmd Code, Max Size */
  224. };
  225. /* Response:
  226. *
  227. * The reply structure is an fc_bsg_ctels_reply structure
  228. */
  229. /* request (CDB) structure of the sg_io_v4 */
  230. struct fc_bsg_request {
  231. __u32 msgcode;
  232. union {
  233. struct fc_bsg_host_add_rport h_addrport;
  234. struct fc_bsg_host_del_rport h_delrport;
  235. struct fc_bsg_host_els h_els;
  236. struct fc_bsg_host_ct h_ct;
  237. struct fc_bsg_host_vendor h_vendor;
  238. struct fc_bsg_rport_els r_els;
  239. struct fc_bsg_rport_ct r_ct;
  240. } rqst_data;
  241. } __attribute__((packed));
  242. /* response (request sense data) structure of the sg_io_v4 */
  243. struct fc_bsg_reply {
  244. /*
  245. * The completion result. Result exists in two forms:
  246. * if negative, it is an -Exxx system errno value. There will
  247. * be no further reply information supplied.
  248. * else, it's the 4-byte scsi error result, with driver, host,
  249. * msg and status fields. The per-msgcode reply structure
  250. * will contain valid data.
  251. */
  252. __u32 result;
  253. /* If there was reply_payload, how much was recevied ? */
  254. __u32 reply_payload_rcv_len;
  255. union {
  256. struct fc_bsg_host_vendor_reply vendor_reply;
  257. struct fc_bsg_ctels_reply ctels_reply;
  258. } reply_data;
  259. };
  260. #endif /* SCSI_BSG_FC_H */