scsi_transport_iscsi.h 17 KB

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