scsi_transport_iscsi.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * iSCSI transport class definitions
  4. *
  5. * Copyright (C) IBM Corporation, 2004
  6. * Copyright (C) Mike Christie, 2004 - 2006
  7. * Copyright (C) Dmitry Yusupov, 2004 - 2005
  8. * Copyright (C) Alex Aizman, 2004 - 2005
  9. */
  10. #ifndef SCSI_TRANSPORT_ISCSI_H
  11. #define SCSI_TRANSPORT_ISCSI_H
  12. #include <linux/device.h>
  13. #include <linux/list.h>
  14. #include <linux/mutex.h>
  15. #include <scsi/iscsi_if.h>
  16. struct scsi_transport_template;
  17. struct iscsi_transport;
  18. struct iscsi_endpoint;
  19. struct Scsi_Host;
  20. struct scsi_cmnd;
  21. struct iscsi_cls_conn;
  22. struct iscsi_conn;
  23. struct iscsi_task;
  24. struct sockaddr;
  25. struct iscsi_iface;
  26. struct bsg_job;
  27. struct iscsi_bus_flash_session;
  28. struct iscsi_bus_flash_conn;
  29. /**
  30. * struct iscsi_transport - iSCSI Transport template
  31. *
  32. * @name: transport name
  33. * @caps: iSCSI Data-Path capabilities
  34. * @create_session: create new iSCSI session object
  35. * @destroy_session: destroy existing iSCSI session object
  36. * @create_conn: create new iSCSI connection
  37. * @bind_conn: associate this connection with existing iSCSI session
  38. * and specified transport descriptor
  39. * @destroy_conn: destroy inactive iSCSI connection
  40. * @set_param: set iSCSI parameter. Return 0 on success, -ENODATA
  41. * when param is not supported, and a -Exx value on other
  42. * error.
  43. * @get_param get iSCSI parameter. Must return number of bytes
  44. * copied to buffer on success, -ENODATA when param
  45. * is not supported, and a -Exx value on other error
  46. * @start_conn: set connection to be operational
  47. * @stop_conn: suspend/recover/terminate connection
  48. * @send_pdu: send iSCSI PDU, Login, Logout, NOP-Out, Reject, Text.
  49. * @session_recovery_timedout: notify LLD a block during recovery timed out
  50. * @init_task: Initialize a iscsi_task and any internal structs.
  51. * When offloading the data path, this is called from
  52. * queuecommand with the session lock, or from the
  53. * iscsi_conn_send_pdu context with the session lock.
  54. * When not offloading the data path, this is called
  55. * from the scsi work queue without the session lock.
  56. * @xmit_task Requests LLD to transfer cmd task. Returns 0 or the
  57. * number of bytes transferred on success, and -Exyz
  58. * value on error. When offloading the data path, this
  59. * is called from queuecommand with the session lock, or
  60. * from the iscsi_conn_send_pdu context with the session
  61. * lock. When not offloading the data path, this is called
  62. * from the scsi work queue without the session lock.
  63. * @cleanup_task: requests LLD to fail task. Called with session lock
  64. * and after the connection has been suspended and
  65. * terminated during recovery. If called
  66. * from abort task then connection is not suspended
  67. * or terminated but sk_callback_lock is held
  68. *
  69. * Template API provided by iSCSI Transport
  70. */
  71. struct iscsi_transport {
  72. struct module *owner;
  73. char *name;
  74. unsigned int caps;
  75. struct iscsi_cls_session *(*create_session) (struct iscsi_endpoint *ep,
  76. uint16_t cmds_max, uint16_t qdepth,
  77. uint32_t sn);
  78. void (*destroy_session) (struct iscsi_cls_session *session);
  79. struct iscsi_cls_conn *(*create_conn) (struct iscsi_cls_session *sess,
  80. uint32_t cid);
  81. void (*unbind_conn) (struct iscsi_cls_conn *conn, bool is_active);
  82. int (*bind_conn) (struct iscsi_cls_session *session,
  83. struct iscsi_cls_conn *cls_conn,
  84. uint64_t transport_eph, int is_leading);
  85. int (*start_conn) (struct iscsi_cls_conn *conn);
  86. void (*stop_conn) (struct iscsi_cls_conn *conn, int flag);
  87. void (*destroy_conn) (struct iscsi_cls_conn *conn);
  88. int (*set_param) (struct iscsi_cls_conn *conn, enum iscsi_param param,
  89. char *buf, int buflen);
  90. int (*get_ep_param) (struct iscsi_endpoint *ep, enum iscsi_param param,
  91. char *buf);
  92. int (*get_conn_param) (struct iscsi_cls_conn *conn,
  93. enum iscsi_param param, char *buf);
  94. int (*get_session_param) (struct iscsi_cls_session *session,
  95. enum iscsi_param param, char *buf);
  96. int (*get_host_param) (struct Scsi_Host *shost,
  97. enum iscsi_host_param param, char *buf);
  98. int (*set_host_param) (struct Scsi_Host *shost,
  99. enum iscsi_host_param param, char *buf,
  100. int buflen);
  101. int (*send_pdu) (struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr,
  102. char *data, uint32_t data_size);
  103. void (*get_stats) (struct iscsi_cls_conn *conn,
  104. struct iscsi_stats *stats);
  105. int (*init_task) (struct iscsi_task *task);
  106. int (*xmit_task) (struct iscsi_task *task);
  107. void (*cleanup_task) (struct iscsi_task *task);
  108. int (*alloc_pdu) (struct iscsi_task *task, uint8_t opcode);
  109. int (*xmit_pdu) (struct iscsi_task *task);
  110. int (*init_pdu) (struct iscsi_task *task, unsigned int offset,
  111. unsigned int count);
  112. void (*parse_pdu_itt) (struct iscsi_conn *conn, itt_t itt,
  113. int *index, int *age);
  114. void (*session_recovery_timedout) (struct iscsi_cls_session *session);
  115. struct iscsi_endpoint *(*ep_connect) (struct Scsi_Host *shost,
  116. struct sockaddr *dst_addr,
  117. int non_blocking);
  118. int (*ep_poll) (struct iscsi_endpoint *ep, int timeout_ms);
  119. void (*ep_disconnect) (struct iscsi_endpoint *ep);
  120. int (*tgt_dscvr) (struct Scsi_Host *shost, enum iscsi_tgt_dscvr type,
  121. uint32_t enable, struct sockaddr *dst_addr);
  122. int (*set_path) (struct Scsi_Host *shost, struct iscsi_path *params);
  123. int (*set_iface_param) (struct Scsi_Host *shost, void *data,
  124. uint32_t len);
  125. int (*get_iface_param) (struct iscsi_iface *iface,
  126. enum iscsi_param_type param_type,
  127. int param, char *buf);
  128. umode_t (*attr_is_visible)(int param_type, int param);
  129. int (*bsg_request)(struct bsg_job *job);
  130. int (*send_ping) (struct Scsi_Host *shost, uint32_t iface_num,
  131. uint32_t iface_type, uint32_t payload_size,
  132. uint32_t pid, struct sockaddr *dst_addr);
  133. int (*get_chap) (struct Scsi_Host *shost, uint16_t chap_tbl_idx,
  134. uint32_t *num_entries, char *buf);
  135. int (*delete_chap) (struct Scsi_Host *shost, uint16_t chap_tbl_idx);
  136. int (*set_chap) (struct Scsi_Host *shost, void *data, int len);
  137. int (*get_flashnode_param) (struct iscsi_bus_flash_session *fnode_sess,
  138. int param, char *buf);
  139. int (*set_flashnode_param) (struct iscsi_bus_flash_session *fnode_sess,
  140. struct iscsi_bus_flash_conn *fnode_conn,
  141. void *data, int len);
  142. int (*new_flashnode) (struct Scsi_Host *shost, const char *buf,
  143. int len);
  144. int (*del_flashnode) (struct iscsi_bus_flash_session *fnode_sess);
  145. int (*login_flashnode) (struct iscsi_bus_flash_session *fnode_sess,
  146. struct iscsi_bus_flash_conn *fnode_conn);
  147. int (*logout_flashnode) (struct iscsi_bus_flash_session *fnode_sess,
  148. struct iscsi_bus_flash_conn *fnode_conn);
  149. int (*logout_flashnode_sid) (struct iscsi_cls_session *cls_sess);
  150. int (*get_host_stats) (struct Scsi_Host *shost, char *buf, int len);
  151. u8 (*check_protection)(struct iscsi_task *task, sector_t *sector);
  152. };
  153. /*
  154. * transport registration upcalls
  155. */
  156. extern struct scsi_transport_template *iscsi_register_transport(struct iscsi_transport *tt);
  157. extern void iscsi_unregister_transport(struct iscsi_transport *tt);
  158. /*
  159. * control plane upcalls
  160. */
  161. extern void iscsi_conn_error_event(struct iscsi_cls_conn *conn,
  162. enum iscsi_err error);
  163. extern void iscsi_conn_login_event(struct iscsi_cls_conn *conn,
  164. enum iscsi_conn_state state);
  165. extern int iscsi_recv_pdu(struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr,
  166. char *data, uint32_t data_size);
  167. extern int iscsi_offload_mesg(struct Scsi_Host *shost,
  168. struct iscsi_transport *transport, uint32_t type,
  169. char *data, uint16_t data_size);
  170. extern void iscsi_post_host_event(uint32_t host_no,
  171. struct iscsi_transport *transport,
  172. enum iscsi_host_event_code code,
  173. uint32_t data_size,
  174. uint8_t *data);
  175. extern void iscsi_ping_comp_event(uint32_t host_no,
  176. struct iscsi_transport *transport,
  177. uint32_t status, uint32_t pid,
  178. uint32_t data_size, uint8_t *data);
  179. /* iscsi class connection state */
  180. enum iscsi_connection_state {
  181. ISCSI_CONN_UP = 0,
  182. ISCSI_CONN_DOWN,
  183. ISCSI_CONN_FAILED,
  184. ISCSI_CONN_BOUND,
  185. };
  186. #define ISCSI_CLS_CONN_BIT_CLEANUP 1
  187. struct iscsi_cls_conn {
  188. struct list_head conn_list; /* item in connlist */
  189. void *dd_data; /* LLD private data */
  190. struct iscsi_transport *transport;
  191. uint32_t cid; /* connection id */
  192. /*
  193. * This protects the conn startup and binding/unbinding of the ep to
  194. * the conn. Unbinding includes ep_disconnect and stop_conn.
  195. */
  196. struct mutex ep_mutex;
  197. struct iscsi_endpoint *ep;
  198. /* Used when accessing flags and queueing work. */
  199. spinlock_t lock;
  200. unsigned long flags;
  201. struct work_struct cleanup_work;
  202. struct device dev; /* sysfs transport/container device */
  203. enum iscsi_connection_state state;
  204. };
  205. #define iscsi_dev_to_conn(_dev) \
  206. container_of(_dev, struct iscsi_cls_conn, dev)
  207. #define transport_class_to_conn(_cdev) \
  208. iscsi_dev_to_conn(_cdev->parent)
  209. #define iscsi_conn_to_session(_conn) \
  210. iscsi_dev_to_session(_conn->dev.parent)
  211. /* iscsi class session state */
  212. enum {
  213. ISCSI_SESSION_LOGGED_IN,
  214. ISCSI_SESSION_FAILED,
  215. ISCSI_SESSION_FREE,
  216. };
  217. enum {
  218. ISCSI_SESSION_TARGET_UNBOUND,
  219. ISCSI_SESSION_TARGET_ALLOCATED,
  220. ISCSI_SESSION_TARGET_SCANNED,
  221. ISCSI_SESSION_TARGET_UNBINDING,
  222. ISCSI_SESSION_TARGET_MAX,
  223. };
  224. #define ISCSI_MAX_TARGET -1
  225. struct iscsi_cls_session {
  226. struct list_head sess_list; /* item in session_list */
  227. struct iscsi_transport *transport;
  228. spinlock_t lock;
  229. struct work_struct block_work;
  230. struct work_struct unblock_work;
  231. struct work_struct scan_work;
  232. struct work_struct unbind_work;
  233. struct work_struct destroy_work;
  234. /* recovery fields */
  235. int recovery_tmo;
  236. bool recovery_tmo_sysfs_override;
  237. struct delayed_work recovery_work;
  238. struct workqueue_struct *workq;
  239. unsigned int target_id;
  240. bool ida_used;
  241. /*
  242. * pid of userspace process that created session or -1 if
  243. * created by the kernel.
  244. */
  245. pid_t creator;
  246. int state;
  247. int target_state; /* session target bind state */
  248. int sid; /* session id */
  249. void *dd_data; /* LLD private data */
  250. struct device dev; /* sysfs transport/container device */
  251. };
  252. #define iscsi_dev_to_session(_dev) \
  253. container_of(_dev, struct iscsi_cls_session, dev)
  254. #define transport_class_to_session(_cdev) \
  255. iscsi_dev_to_session(_cdev->parent)
  256. #define iscsi_session_to_shost(_session) \
  257. dev_to_shost(_session->dev.parent)
  258. #define starget_to_session(_stgt) \
  259. iscsi_dev_to_session(_stgt->dev.parent)
  260. struct iscsi_cls_host {
  261. struct mutex mutex;
  262. struct request_queue *bsg_q;
  263. uint32_t port_speed;
  264. uint32_t port_state;
  265. };
  266. #define iscsi_job_to_shost(_job) \
  267. dev_to_shost(_job->dev)
  268. extern void iscsi_host_for_each_session(struct Scsi_Host *shost,
  269. void (*fn)(struct iscsi_cls_session *));
  270. struct iscsi_endpoint {
  271. void *dd_data; /* LLD private data */
  272. struct device dev;
  273. int id;
  274. struct iscsi_cls_conn *conn;
  275. };
  276. struct iscsi_iface {
  277. struct device dev;
  278. struct iscsi_transport *transport;
  279. uint32_t iface_type; /* IPv4 or IPv6 */
  280. uint32_t iface_num; /* iface number, 0 - n */
  281. void *dd_data; /* LLD private data */
  282. };
  283. #define iscsi_dev_to_iface(_dev) \
  284. container_of(_dev, struct iscsi_iface, dev)
  285. #define iscsi_iface_to_shost(_iface) \
  286. dev_to_shost(_iface->dev.parent)
  287. struct iscsi_bus_flash_conn {
  288. struct list_head conn_list; /* item in connlist */
  289. void *dd_data; /* LLD private data */
  290. struct iscsi_transport *transport;
  291. struct device dev; /* sysfs transport/container device */
  292. /* iscsi connection parameters */
  293. uint32_t exp_statsn;
  294. uint32_t statsn;
  295. unsigned max_recv_dlength; /* initiator_max_recv_dsl*/
  296. unsigned max_xmit_dlength; /* target_max_recv_dsl */
  297. unsigned max_segment_size;
  298. unsigned tcp_xmit_wsf;
  299. unsigned tcp_recv_wsf;
  300. int hdrdgst_en;
  301. int datadgst_en;
  302. int port;
  303. char *ipaddress;
  304. char *link_local_ipv6_addr;
  305. char *redirect_ipaddr;
  306. uint16_t keepalive_timeout;
  307. uint16_t local_port;
  308. uint8_t snack_req_en;
  309. /* tcp timestamp negotiation status */
  310. uint8_t tcp_timestamp_stat;
  311. uint8_t tcp_nagle_disable;
  312. /* tcp window scale factor */
  313. uint8_t tcp_wsf_disable;
  314. uint8_t tcp_timer_scale;
  315. uint8_t tcp_timestamp_en;
  316. uint8_t ipv4_tos;
  317. uint8_t ipv6_traffic_class;
  318. uint8_t ipv6_flow_label;
  319. uint8_t fragment_disable;
  320. /* Link local IPv6 address is assigned by firmware or driver */
  321. uint8_t is_fw_assigned_ipv6;
  322. };
  323. #define iscsi_dev_to_flash_conn(_dev) \
  324. container_of(_dev, struct iscsi_bus_flash_conn, dev)
  325. #define iscsi_flash_conn_to_flash_session(_conn) \
  326. iscsi_dev_to_flash_session(_conn->dev.parent)
  327. #define ISID_SIZE 6
  328. struct iscsi_bus_flash_session {
  329. struct list_head sess_list; /* item in session_list */
  330. struct iscsi_transport *transport;
  331. unsigned int target_id;
  332. int flash_state; /* persistent or non-persistent */
  333. void *dd_data; /* LLD private data */
  334. struct device dev; /* sysfs transport/container device */
  335. /* iscsi session parameters */
  336. unsigned first_burst;
  337. unsigned max_burst;
  338. unsigned short max_r2t;
  339. int default_taskmgmt_timeout;
  340. int initial_r2t_en;
  341. int imm_data_en;
  342. int time2wait;
  343. int time2retain;
  344. int pdu_inorder_en;
  345. int dataseq_inorder_en;
  346. int erl;
  347. int tpgt;
  348. char *username;
  349. char *username_in;
  350. char *password;
  351. char *password_in;
  352. char *targetname;
  353. char *targetalias;
  354. char *portal_type;
  355. uint16_t tsid;
  356. uint16_t chap_in_idx;
  357. uint16_t chap_out_idx;
  358. /* index of iSCSI discovery session if the entry is
  359. * discovered by iSCSI discovery session
  360. */
  361. uint16_t discovery_parent_idx;
  362. /* indicates if discovery was done through iSNS discovery service
  363. * or through sendTarget */
  364. uint16_t discovery_parent_type;
  365. /* Firmware auto sendtarget discovery disable */
  366. uint8_t auto_snd_tgt_disable;
  367. uint8_t discovery_sess;
  368. /* indicates if this flashnode entry is enabled or disabled */
  369. uint8_t entry_state;
  370. uint8_t chap_auth_en;
  371. /* enables firmware to auto logout the discovery session on discovery
  372. * completion
  373. */
  374. uint8_t discovery_logout_en;
  375. uint8_t bidi_chap_en;
  376. /* makes authentication for discovery session optional */
  377. uint8_t discovery_auth_optional;
  378. uint8_t isid[ISID_SIZE];
  379. uint8_t is_boot_target;
  380. };
  381. #define iscsi_dev_to_flash_session(_dev) \
  382. container_of(_dev, struct iscsi_bus_flash_session, dev)
  383. #define iscsi_flash_session_to_shost(_session) \
  384. dev_to_shost(_session->dev.parent)
  385. /*
  386. * session and connection functions that can be used by HW iSCSI LLDs
  387. */
  388. #define iscsi_cls_session_printk(prefix, _cls_session, fmt, a...) \
  389. dev_printk(prefix, &(_cls_session)->dev, fmt, ##a)
  390. #define iscsi_cls_conn_printk(prefix, _cls_conn, fmt, a...) \
  391. dev_printk(prefix, &(_cls_conn)->dev, fmt, ##a)
  392. extern int iscsi_session_chkready(struct iscsi_cls_session *session);
  393. extern int iscsi_is_session_online(struct iscsi_cls_session *session);
  394. extern struct iscsi_cls_session *iscsi_alloc_session(struct Scsi_Host *shost,
  395. struct iscsi_transport *transport, int dd_size);
  396. extern int iscsi_add_session(struct iscsi_cls_session *session,
  397. unsigned int target_id);
  398. extern int iscsi_session_event(struct iscsi_cls_session *session,
  399. enum iscsi_uevent_e event);
  400. extern struct iscsi_cls_session *iscsi_create_session(struct Scsi_Host *shost,
  401. struct iscsi_transport *t,
  402. int dd_size,
  403. unsigned int target_id);
  404. extern void iscsi_force_destroy_session(struct iscsi_cls_session *session);
  405. extern void iscsi_remove_session(struct iscsi_cls_session *session);
  406. extern void iscsi_free_session(struct iscsi_cls_session *session);
  407. extern struct iscsi_cls_conn *iscsi_alloc_conn(struct iscsi_cls_session *sess,
  408. int dd_size, uint32_t cid);
  409. extern int iscsi_add_conn(struct iscsi_cls_conn *conn);
  410. extern void iscsi_remove_conn(struct iscsi_cls_conn *conn);
  411. extern void iscsi_put_conn(struct iscsi_cls_conn *conn);
  412. extern void iscsi_get_conn(struct iscsi_cls_conn *conn);
  413. extern void iscsi_unblock_session(struct iscsi_cls_session *session);
  414. extern void iscsi_block_session(struct iscsi_cls_session *session);
  415. extern struct iscsi_endpoint *iscsi_create_endpoint(int dd_size);
  416. extern void iscsi_destroy_endpoint(struct iscsi_endpoint *ep);
  417. extern struct iscsi_endpoint *iscsi_lookup_endpoint(u64 handle);
  418. extern void iscsi_put_endpoint(struct iscsi_endpoint *ep);
  419. extern int iscsi_block_scsi_eh(struct scsi_cmnd *cmd);
  420. extern struct iscsi_iface *iscsi_create_iface(struct Scsi_Host *shost,
  421. struct iscsi_transport *t,
  422. uint32_t iface_type,
  423. uint32_t iface_num, int dd_size);
  424. extern void iscsi_destroy_iface(struct iscsi_iface *iface);
  425. extern struct iscsi_iface *iscsi_lookup_iface(int handle);
  426. extern char *iscsi_get_port_speed_name(struct Scsi_Host *shost);
  427. extern char *iscsi_get_port_state_name(struct Scsi_Host *shost);
  428. extern int iscsi_is_session_dev(const struct device *dev);
  429. extern char *iscsi_get_discovery_parent_name(int parent_type);
  430. extern struct device *
  431. iscsi_find_flashnode(struct Scsi_Host *shost, void *data,
  432. int (*fn)(struct device *dev, void *data));
  433. extern struct iscsi_bus_flash_session *
  434. iscsi_create_flashnode_sess(struct Scsi_Host *shost, int index,
  435. struct iscsi_transport *transport, int dd_size);
  436. extern struct iscsi_bus_flash_conn *
  437. iscsi_create_flashnode_conn(struct Scsi_Host *shost,
  438. struct iscsi_bus_flash_session *fnode_sess,
  439. struct iscsi_transport *transport, int dd_size);
  440. extern void
  441. iscsi_destroy_flashnode_sess(struct iscsi_bus_flash_session *fnode_sess);
  442. extern void iscsi_destroy_all_flashnode(struct Scsi_Host *shost);
  443. extern int iscsi_flashnode_bus_match(struct device *dev,
  444. struct device_driver *drv);
  445. extern struct device *
  446. iscsi_find_flashnode_sess(struct Scsi_Host *shost, void *data,
  447. int (*fn)(struct device *dev, void *data));
  448. extern struct device *
  449. iscsi_find_flashnode_conn(struct iscsi_bus_flash_session *fnode_sess);
  450. extern char *
  451. iscsi_get_ipaddress_state_name(enum iscsi_ipaddress_state port_state);
  452. extern char *iscsi_get_router_state_name(enum iscsi_router_state router_state);
  453. #endif