scsi_transport_iscsi.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  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 (*get_flashnode_param) (struct iscsi_bus_flash_session *fnode_sess,
  149. int param, char *buf);
  150. int (*set_flashnode_param) (struct iscsi_bus_flash_session *fnode_sess,
  151. struct iscsi_bus_flash_conn *fnode_conn,
  152. void *data, int len);
  153. int (*new_flashnode) (struct Scsi_Host *shost, const char *buf,
  154. int len);
  155. int (*del_flashnode) (struct iscsi_bus_flash_session *fnode_sess);
  156. int (*login_flashnode) (struct iscsi_bus_flash_session *fnode_sess,
  157. struct iscsi_bus_flash_conn *fnode_conn);
  158. int (*logout_flashnode) (struct iscsi_bus_flash_session *fnode_sess,
  159. struct iscsi_bus_flash_conn *fnode_conn);
  160. int (*logout_flashnode_sid) (struct iscsi_cls_session *cls_sess);
  161. };
  162. /*
  163. * transport registration upcalls
  164. */
  165. extern struct scsi_transport_template *iscsi_register_transport(struct iscsi_transport *tt);
  166. extern int iscsi_unregister_transport(struct iscsi_transport *tt);
  167. /*
  168. * control plane upcalls
  169. */
  170. extern void iscsi_conn_error_event(struct iscsi_cls_conn *conn,
  171. enum iscsi_err error);
  172. extern void iscsi_conn_login_event(struct iscsi_cls_conn *conn,
  173. enum iscsi_conn_state state);
  174. extern int iscsi_recv_pdu(struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr,
  175. char *data, uint32_t data_size);
  176. extern int iscsi_offload_mesg(struct Scsi_Host *shost,
  177. struct iscsi_transport *transport, uint32_t type,
  178. char *data, uint16_t data_size);
  179. extern void iscsi_post_host_event(uint32_t host_no,
  180. struct iscsi_transport *transport,
  181. enum iscsi_host_event_code code,
  182. uint32_t data_size,
  183. uint8_t *data);
  184. extern void iscsi_ping_comp_event(uint32_t host_no,
  185. struct iscsi_transport *transport,
  186. uint32_t status, uint32_t pid,
  187. uint32_t data_size, uint8_t *data);
  188. struct iscsi_cls_conn {
  189. struct list_head conn_list; /* item in connlist */
  190. void *dd_data; /* LLD private data */
  191. struct iscsi_transport *transport;
  192. uint32_t cid; /* connection id */
  193. struct mutex ep_mutex;
  194. struct iscsi_endpoint *ep;
  195. struct device dev; /* sysfs transport/container device */
  196. };
  197. #define iscsi_dev_to_conn(_dev) \
  198. container_of(_dev, struct iscsi_cls_conn, dev)
  199. #define transport_class_to_conn(_cdev) \
  200. iscsi_dev_to_conn(_cdev->parent)
  201. #define iscsi_conn_to_session(_conn) \
  202. iscsi_dev_to_session(_conn->dev.parent)
  203. /* iscsi class session state */
  204. enum {
  205. ISCSI_SESSION_LOGGED_IN,
  206. ISCSI_SESSION_FAILED,
  207. ISCSI_SESSION_FREE,
  208. };
  209. #define ISCSI_MAX_TARGET -1
  210. struct iscsi_cls_session {
  211. struct list_head sess_list; /* item in session_list */
  212. struct iscsi_transport *transport;
  213. spinlock_t lock;
  214. struct work_struct block_work;
  215. struct work_struct unblock_work;
  216. struct work_struct scan_work;
  217. struct work_struct unbind_work;
  218. /* recovery fields */
  219. int recovery_tmo;
  220. struct delayed_work recovery_work;
  221. unsigned int target_id;
  222. bool ida_used;
  223. /*
  224. * pid of userspace process that created session or -1 if
  225. * created by the kernel.
  226. */
  227. pid_t creator;
  228. int state;
  229. int sid; /* session id */
  230. void *dd_data; /* LLD private data */
  231. struct device dev; /* sysfs transport/container device */
  232. };
  233. #define iscsi_dev_to_session(_dev) \
  234. container_of(_dev, struct iscsi_cls_session, dev)
  235. #define transport_class_to_session(_cdev) \
  236. iscsi_dev_to_session(_cdev->parent)
  237. #define iscsi_session_to_shost(_session) \
  238. dev_to_shost(_session->dev.parent)
  239. #define starget_to_session(_stgt) \
  240. iscsi_dev_to_session(_stgt->dev.parent)
  241. struct iscsi_cls_host {
  242. atomic_t nr_scans;
  243. struct mutex mutex;
  244. struct request_queue *bsg_q;
  245. uint32_t port_speed;
  246. uint32_t port_state;
  247. };
  248. #define iscsi_job_to_shost(_job) \
  249. dev_to_shost(_job->dev)
  250. extern void iscsi_host_for_each_session(struct Scsi_Host *shost,
  251. void (*fn)(struct iscsi_cls_session *));
  252. struct iscsi_endpoint {
  253. void *dd_data; /* LLD private data */
  254. struct device dev;
  255. uint64_t id;
  256. struct iscsi_cls_conn *conn;
  257. };
  258. struct iscsi_iface {
  259. struct device dev;
  260. struct iscsi_transport *transport;
  261. uint32_t iface_type; /* IPv4 or IPv6 */
  262. uint32_t iface_num; /* iface number, 0 - n */
  263. void *dd_data; /* LLD private data */
  264. };
  265. #define iscsi_dev_to_iface(_dev) \
  266. container_of(_dev, struct iscsi_iface, dev)
  267. #define iscsi_iface_to_shost(_iface) \
  268. dev_to_shost(_iface->dev.parent)
  269. struct iscsi_bus_flash_conn {
  270. struct list_head conn_list; /* item in connlist */
  271. void *dd_data; /* LLD private data */
  272. struct iscsi_transport *transport;
  273. struct device dev; /* sysfs transport/container device */
  274. /* iscsi connection parameters */
  275. uint32_t exp_statsn;
  276. uint32_t statsn;
  277. unsigned max_recv_dlength; /* initiator_max_recv_dsl*/
  278. unsigned max_xmit_dlength; /* target_max_recv_dsl */
  279. unsigned max_segment_size;
  280. unsigned tcp_xmit_wsf;
  281. unsigned tcp_recv_wsf;
  282. int hdrdgst_en;
  283. int datadgst_en;
  284. int port;
  285. char *ipaddress;
  286. char *link_local_ipv6_addr;
  287. char *redirect_ipaddr;
  288. uint16_t keepalive_timeout;
  289. uint16_t local_port;
  290. uint8_t snack_req_en;
  291. /* tcp timestamp negotiation status */
  292. uint8_t tcp_timestamp_stat;
  293. uint8_t tcp_nagle_disable;
  294. /* tcp window scale factor */
  295. uint8_t tcp_wsf_disable;
  296. uint8_t tcp_timer_scale;
  297. uint8_t tcp_timestamp_en;
  298. uint8_t ipv4_tos;
  299. uint8_t ipv6_traffic_class;
  300. uint8_t ipv6_flow_label;
  301. uint8_t fragment_disable;
  302. /* Link local IPv6 address is assigned by firmware or driver */
  303. uint8_t is_fw_assigned_ipv6;
  304. };
  305. #define iscsi_dev_to_flash_conn(_dev) \
  306. container_of(_dev, struct iscsi_bus_flash_conn, dev)
  307. #define iscsi_flash_conn_to_flash_session(_conn) \
  308. iscsi_dev_to_flash_session(_conn->dev.parent)
  309. #define ISID_SIZE 6
  310. struct iscsi_bus_flash_session {
  311. struct list_head sess_list; /* item in session_list */
  312. struct iscsi_transport *transport;
  313. unsigned int target_id;
  314. int flash_state; /* persistent or non-persistent */
  315. void *dd_data; /* LLD private data */
  316. struct device dev; /* sysfs transport/container device */
  317. /* iscsi session parameters */
  318. unsigned first_burst;
  319. unsigned max_burst;
  320. unsigned short max_r2t;
  321. int default_taskmgmt_timeout;
  322. int initial_r2t_en;
  323. int imm_data_en;
  324. int time2wait;
  325. int time2retain;
  326. int pdu_inorder_en;
  327. int dataseq_inorder_en;
  328. int erl;
  329. int tpgt;
  330. char *username;
  331. char *username_in;
  332. char *password;
  333. char *password_in;
  334. char *targetname;
  335. char *targetalias;
  336. char *portal_type;
  337. uint16_t tsid;
  338. uint16_t chap_in_idx;
  339. uint16_t chap_out_idx;
  340. /* index of iSCSI discovery session if the entry is
  341. * discovered by iSCSI discovery session
  342. */
  343. uint16_t discovery_parent_idx;
  344. /* indicates if discovery was done through iSNS discovery service
  345. * or through sendTarget */
  346. uint16_t discovery_parent_type;
  347. /* Firmware auto sendtarget discovery disable */
  348. uint8_t auto_snd_tgt_disable;
  349. uint8_t discovery_sess;
  350. /* indicates if this flashnode entry is enabled or disabled */
  351. uint8_t entry_state;
  352. uint8_t chap_auth_en;
  353. /* enables firmware to auto logout the discovery session on discovery
  354. * completion
  355. */
  356. uint8_t discovery_logout_en;
  357. uint8_t bidi_chap_en;
  358. /* makes authentication for discovery session optional */
  359. uint8_t discovery_auth_optional;
  360. uint8_t isid[ISID_SIZE];
  361. uint8_t is_boot_target;
  362. };
  363. #define iscsi_dev_to_flash_session(_dev) \
  364. container_of(_dev, struct iscsi_bus_flash_session, dev)
  365. #define iscsi_flash_session_to_shost(_session) \
  366. dev_to_shost(_session->dev.parent)
  367. /*
  368. * session and connection functions that can be used by HW iSCSI LLDs
  369. */
  370. #define iscsi_cls_session_printk(prefix, _cls_session, fmt, a...) \
  371. dev_printk(prefix, &(_cls_session)->dev, fmt, ##a)
  372. #define iscsi_cls_conn_printk(prefix, _cls_conn, fmt, a...) \
  373. dev_printk(prefix, &(_cls_conn)->dev, fmt, ##a)
  374. extern int iscsi_session_chkready(struct iscsi_cls_session *session);
  375. extern int iscsi_is_session_online(struct iscsi_cls_session *session);
  376. extern struct iscsi_cls_session *iscsi_alloc_session(struct Scsi_Host *shost,
  377. struct iscsi_transport *transport, int dd_size);
  378. extern int iscsi_add_session(struct iscsi_cls_session *session,
  379. unsigned int target_id);
  380. extern int iscsi_session_event(struct iscsi_cls_session *session,
  381. enum iscsi_uevent_e event);
  382. extern struct iscsi_cls_session *iscsi_create_session(struct Scsi_Host *shost,
  383. struct iscsi_transport *t,
  384. int dd_size,
  385. unsigned int target_id);
  386. extern void iscsi_remove_session(struct iscsi_cls_session *session);
  387. extern void iscsi_free_session(struct iscsi_cls_session *session);
  388. extern int iscsi_destroy_session(struct iscsi_cls_session *session);
  389. extern struct iscsi_cls_conn *iscsi_create_conn(struct iscsi_cls_session *sess,
  390. int dd_size, uint32_t cid);
  391. extern int iscsi_destroy_conn(struct iscsi_cls_conn *conn);
  392. extern void iscsi_unblock_session(struct iscsi_cls_session *session);
  393. extern void iscsi_block_session(struct iscsi_cls_session *session);
  394. extern int iscsi_scan_finished(struct Scsi_Host *shost, unsigned long time);
  395. extern struct iscsi_endpoint *iscsi_create_endpoint(int dd_size);
  396. extern void iscsi_destroy_endpoint(struct iscsi_endpoint *ep);
  397. extern struct iscsi_endpoint *iscsi_lookup_endpoint(u64 handle);
  398. extern int iscsi_block_scsi_eh(struct scsi_cmnd *cmd);
  399. extern struct iscsi_iface *iscsi_create_iface(struct Scsi_Host *shost,
  400. struct iscsi_transport *t,
  401. uint32_t iface_type,
  402. uint32_t iface_num, int dd_size);
  403. extern void iscsi_destroy_iface(struct iscsi_iface *iface);
  404. extern struct iscsi_iface *iscsi_lookup_iface(int handle);
  405. extern char *iscsi_get_port_speed_name(struct Scsi_Host *shost);
  406. extern char *iscsi_get_port_state_name(struct Scsi_Host *shost);
  407. extern int iscsi_is_session_dev(const struct device *dev);
  408. extern char *iscsi_get_discovery_parent_name(int parent_type);
  409. extern struct device *
  410. iscsi_find_flashnode(struct Scsi_Host *shost, void *data,
  411. int (*fn)(struct device *dev, void *data));
  412. extern struct iscsi_bus_flash_session *
  413. iscsi_create_flashnode_sess(struct Scsi_Host *shost, int index,
  414. struct iscsi_transport *transport, int dd_size);
  415. extern struct iscsi_bus_flash_conn *
  416. iscsi_create_flashnode_conn(struct Scsi_Host *shost,
  417. struct iscsi_bus_flash_session *fnode_sess,
  418. struct iscsi_transport *transport, int dd_size);
  419. extern void
  420. iscsi_destroy_flashnode_sess(struct iscsi_bus_flash_session *fnode_sess);
  421. extern void iscsi_destroy_all_flashnode(struct Scsi_Host *shost);
  422. extern int iscsi_flashnode_bus_match(struct device *dev,
  423. struct device_driver *drv);
  424. extern struct device *
  425. iscsi_find_flashnode_sess(struct Scsi_Host *shost, void *data,
  426. int (*fn)(struct device *dev, void *data));
  427. extern struct device *
  428. iscsi_find_flashnode_conn(struct iscsi_bus_flash_session *fnode_sess);
  429. #endif