scsi_transport_iscsi.h 17 KB

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