11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * iSCSI transport class definitions 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Copyright (C) IBM Corporation, 2004 57996a778SMike Christie * Copyright (C) Mike Christie, 2004 - 2006 639e84790SAlex Aizman * Copyright (C) Dmitry Yusupov, 2004 - 2005 739e84790SAlex Aizman * Copyright (C) Alex Aizman, 2004 - 2005 81da177e4SLinus Torvalds * 91da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify 101da177e4SLinus Torvalds * it under the terms of the GNU General Public License as published by 111da177e4SLinus Torvalds * the Free Software Foundation; either version 2 of the License, or 121da177e4SLinus Torvalds * (at your option) any later version. 131da177e4SLinus Torvalds * 141da177e4SLinus Torvalds * This program is distributed in the hope that it will be useful, 151da177e4SLinus Torvalds * but WITHOUT ANY WARRANTY; without even the implied warranty of 161da177e4SLinus Torvalds * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 171da177e4SLinus Torvalds * GNU General Public License for more details. 181da177e4SLinus Torvalds * 191da177e4SLinus Torvalds * You should have received a copy of the GNU General Public License 201da177e4SLinus Torvalds * along with this program; if not, write to the Free Software 211da177e4SLinus Torvalds * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 221da177e4SLinus Torvalds */ 231da177e4SLinus Torvalds #ifndef SCSI_TRANSPORT_ISCSI_H 241da177e4SLinus Torvalds #define SCSI_TRANSPORT_ISCSI_H 251da177e4SLinus Torvalds 267b8631b5SMike Christie #include <linux/device.h> 27d773c082SMichael S. Tsirkin #include <linux/list.h> 28d773c082SMichael S. Tsirkin #include <linux/mutex.h> 2939e84790SAlex Aizman #include <scsi/iscsi_if.h> 301da177e4SLinus Torvalds 317b8631b5SMike Christie struct scsi_transport_template; 327996a778SMike Christie struct iscsi_transport; 33d82ff9beSMike Christie struct iscsi_endpoint; 347b8631b5SMike Christie struct Scsi_Host; 357b8631b5SMike Christie struct iscsi_cls_conn; 367996a778SMike Christie struct iscsi_conn; 379c19a7d0SMike Christie struct iscsi_task; 38a54a52caSMike Christie struct sockaddr; 397b8631b5SMike Christie 4039e84790SAlex Aizman /** 4139e84790SAlex Aizman * struct iscsi_transport - iSCSI Transport template 4239e84790SAlex Aizman * 4339e84790SAlex Aizman * @name: transport name 4439e84790SAlex Aizman * @caps: iSCSI Data-Path capabilities 4539e84790SAlex Aizman * @create_session: create new iSCSI session object 4639e84790SAlex Aizman * @destroy_session: destroy existing iSCSI session object 4739e84790SAlex Aizman * @create_conn: create new iSCSI connection 4839e84790SAlex Aizman * @bind_conn: associate this connection with existing iSCSI session 4939e84790SAlex Aizman * and specified transport descriptor 5039e84790SAlex Aizman * @destroy_conn: destroy inactive iSCSI connection 51a54a52caSMike Christie * @set_param: set iSCSI parameter. Return 0 on success, -ENODATA 52a54a52caSMike Christie * when param is not supported, and a -Exx value on other 53a54a52caSMike Christie * error. 54a54a52caSMike Christie * @get_param get iSCSI parameter. Must return number of bytes 55a54a52caSMike Christie * copied to buffer on success, -ENODATA when param 56a54a52caSMike Christie * is not supported, and a -Exx value on other error 5739e84790SAlex Aizman * @start_conn: set connection to be operational 5839e84790SAlex Aizman * @stop_conn: suspend/recover/terminate connection 5939e84790SAlex Aizman * @send_pdu: send iSCSI PDU, Login, Logout, NOP-Out, Reject, Text. 607996a778SMike Christie * @session_recovery_timedout: notify LLD a block during recovery timed out 613e5c28adSMike Christie * @init_task: Initialize a iscsi_task and any internal structs. 623e5c28adSMike Christie * When offloading the data path, this is called from 633e5c28adSMike Christie * queuecommand with the session lock, or from the 643e5c28adSMike Christie * iscsi_conn_send_pdu context with the session lock. 653e5c28adSMike Christie * When not offloading the data path, this is called 663e5c28adSMike Christie * from the scsi work queue without the session lock. 673e5c28adSMike Christie * @xmit_task Requests LLD to transfer cmd task. Returns 0 or the 683219e529SMike Christie * the number of bytes transferred on success, and -Exyz 693e5c28adSMike Christie * value on error. When offloading the data path, this 703e5c28adSMike Christie * is called from queuecommand with the session lock, or 713e5c28adSMike Christie * from the iscsi_conn_send_pdu context with the session 723e5c28adSMike Christie * lock. When not offloading the data path, this is called 733e5c28adSMike Christie * from the scsi work queue without the session lock. 743e5c28adSMike Christie * @cleanup_task: requests LLD to fail task. Called with session lock 753e5c28adSMike Christie * and after the connection has been suspended and 763e5c28adSMike Christie * terminated during recovery. If called 777996a778SMike Christie * from abort task then connection is not suspended 787996a778SMike Christie * or terminated but sk_callback_lock is held 7939e84790SAlex Aizman * 8039e84790SAlex Aizman * Template API provided by iSCSI Transport 8139e84790SAlex Aizman */ 8239e84790SAlex Aizman struct iscsi_transport { 8339e84790SAlex Aizman struct module *owner; 8439e84790SAlex Aizman char *name; 8539e84790SAlex Aizman unsigned int caps; 86fd7255f5SMike Christie /* LLD sets this to indicate what values it can export to sysfs */ 871819dc81SMike Christie uint64_t param_mask; 881819dc81SMike Christie uint64_t host_param_mask; 89d82ff9beSMike Christie struct iscsi_cls_session *(*create_session) (struct iscsi_endpoint *ep, 9075613521SMike Christie uint16_t cmds_max, uint16_t qdepth, 915e7facb7SMike Christie uint32_t sn); 927b7232f3SMike Christie void (*destroy_session) (struct iscsi_cls_session *session); 937b7232f3SMike Christie struct iscsi_cls_conn *(*create_conn) (struct iscsi_cls_session *sess, 947b8631b5SMike Christie uint32_t cid); 957b7232f3SMike Christie int (*bind_conn) (struct iscsi_cls_session *session, 967b7232f3SMike Christie struct iscsi_cls_conn *cls_conn, 97264faaaaSOr Gerlitz uint64_t transport_eph, int is_leading); 987b7232f3SMike Christie int (*start_conn) (struct iscsi_cls_conn *conn); 997b7232f3SMike Christie void (*stop_conn) (struct iscsi_cls_conn *conn, int flag); 1007b8631b5SMike Christie void (*destroy_conn) (struct iscsi_cls_conn *conn); 1017b7232f3SMike Christie int (*set_param) (struct iscsi_cls_conn *conn, enum iscsi_param param, 102a54a52caSMike Christie char *buf, int buflen); 1037b7232f3SMike Christie int (*get_conn_param) (struct iscsi_cls_conn *conn, 104fd7255f5SMike Christie enum iscsi_param param, char *buf); 105a54a52caSMike Christie int (*get_session_param) (struct iscsi_cls_session *session, 106fd7255f5SMike Christie enum iscsi_param param, char *buf); 1071819dc81SMike Christie int (*get_host_param) (struct Scsi_Host *shost, 1081819dc81SMike Christie enum iscsi_host_param param, char *buf); 1091d9bf13aSMike Christie int (*set_host_param) (struct Scsi_Host *shost, 1101d9bf13aSMike Christie enum iscsi_host_param param, char *buf, 1111d9bf13aSMike Christie int buflen); 1127b7232f3SMike Christie int (*send_pdu) (struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr, 11339e84790SAlex Aizman char *data, uint32_t data_size); 1147b7232f3SMike Christie void (*get_stats) (struct iscsi_cls_conn *conn, 1157b7232f3SMike Christie struct iscsi_stats *stats); 116577577daSMike Christie 1179c19a7d0SMike Christie int (*init_task) (struct iscsi_task *task); 1189c19a7d0SMike Christie int (*xmit_task) (struct iscsi_task *task); 119577577daSMike Christie void (*cleanup_task) (struct iscsi_task *task); 120577577daSMike Christie 1212ff79d52SMike Christie int (*alloc_pdu) (struct iscsi_task *task, uint8_t opcode); 122577577daSMike Christie int (*xmit_pdu) (struct iscsi_task *task); 123577577daSMike Christie int (*init_pdu) (struct iscsi_task *task, unsigned int offset, 124577577daSMike Christie unsigned int count); 125262ef636SMike Christie void (*parse_pdu_itt) (struct iscsi_conn *conn, itt_t itt, 126262ef636SMike Christie int *index, int *age); 127262ef636SMike Christie 12830a6c652SMike Christie void (*session_recovery_timedout) (struct iscsi_cls_session *session); 12910eb0f01SMike Christie struct iscsi_endpoint *(*ep_connect) (struct Scsi_Host *shost, 13010eb0f01SMike Christie struct sockaddr *dst_addr, 131d82ff9beSMike Christie int non_blocking); 132d82ff9beSMike Christie int (*ep_poll) (struct iscsi_endpoint *ep, int timeout_ms); 133d82ff9beSMike Christie void (*ep_disconnect) (struct iscsi_endpoint *ep); 1342174a04eSMike Christie int (*tgt_dscvr) (struct Scsi_Host *shost, enum iscsi_tgt_dscvr type, 13501cb225dSMike Christie uint32_t enable, struct sockaddr *dst_addr); 1361da177e4SLinus Torvalds }; 1371da177e4SLinus Torvalds 1381da177e4SLinus Torvalds /* 13939e84790SAlex Aizman * transport registration upcalls 1401da177e4SLinus Torvalds */ 1417b8631b5SMike Christie extern struct scsi_transport_template *iscsi_register_transport(struct iscsi_transport *tt); 14239e84790SAlex Aizman extern int iscsi_unregister_transport(struct iscsi_transport *tt); 1431da177e4SLinus Torvalds 1441da177e4SLinus Torvalds /* 14539e84790SAlex Aizman * control plane upcalls 1461da177e4SLinus Torvalds */ 147e5bd7b54SMike Christie extern void iscsi_conn_error_event(struct iscsi_cls_conn *conn, 148e5bd7b54SMike Christie enum iscsi_err error); 1497b7232f3SMike Christie extern int iscsi_recv_pdu(struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr, 15039e84790SAlex Aizman char *data, uint32_t data_size); 1511da177e4SLinus Torvalds 1527b8631b5SMike Christie struct iscsi_cls_conn { 1537b8631b5SMike Christie struct list_head conn_list; /* item in connlist */ 1547b8631b5SMike Christie void *dd_data; /* LLD private data */ 1557b8631b5SMike Christie struct iscsi_transport *transport; 156b5c7a12dSMike Christie uint32_t cid; /* connection id */ 157fd7255f5SMike Christie 1587b8631b5SMike Christie int active; /* must be accessed with the connlock */ 1597b8631b5SMike Christie struct device dev; /* sysfs transport/container device */ 1607b8631b5SMike Christie }; 1617b8631b5SMike Christie 1627b8631b5SMike Christie #define iscsi_dev_to_conn(_dev) \ 1637b8631b5SMike Christie container_of(_dev, struct iscsi_cls_conn, dev) 1647b8631b5SMike Christie 1656eabafbeSMike Christie #define iscsi_conn_to_session(_conn) \ 1666eabafbeSMike Christie iscsi_dev_to_session(_conn->dev.parent) 1676eabafbeSMike Christie 1686eabafbeSMike Christie /* iscsi class session state */ 1696eabafbeSMike Christie enum { 1706eabafbeSMike Christie ISCSI_SESSION_LOGGED_IN, 1716eabafbeSMike Christie ISCSI_SESSION_FAILED, 1726eabafbeSMike Christie ISCSI_SESSION_FREE, 1736eabafbeSMike Christie }; 1747996a778SMike Christie 1757970634bSMike Christie #define ISCSI_MAX_TARGET -1 1767970634bSMike Christie 1777b8631b5SMike Christie struct iscsi_cls_session { 1787b7232f3SMike Christie struct list_head sess_list; /* item in session_list */ 1797b8631b5SMike Christie struct iscsi_transport *transport; 1806eabafbeSMike Christie spinlock_t lock; 18145ab33b6SMike Christie struct work_struct block_work; 18245ab33b6SMike Christie struct work_struct unblock_work; 183bd976f62SMike Christie struct work_struct scan_work; 184bd976f62SMike Christie struct work_struct unbind_work; 185fd7255f5SMike Christie 18630a6c652SMike Christie /* recovery fields */ 18730a6c652SMike Christie int recovery_tmo; 188c4028958SDavid Howells struct delayed_work recovery_work; 18930a6c652SMike Christie 1907970634bSMike Christie unsigned int target_id; 19130a6c652SMike Christie 1926eabafbeSMike Christie int state; 193b5c7a12dSMike Christie int sid; /* session id */ 194b5c7a12dSMike Christie void *dd_data; /* LLD private data */ 1957b8631b5SMike Christie struct device dev; /* sysfs transport/container device */ 1967b8631b5SMike Christie }; 1977b8631b5SMike Christie 1987b8631b5SMike Christie #define iscsi_dev_to_session(_dev) \ 1997b8631b5SMike Christie container_of(_dev, struct iscsi_cls_session, dev) 2007b8631b5SMike Christie 2017b8631b5SMike Christie #define iscsi_session_to_shost(_session) \ 2027b8631b5SMike Christie dev_to_shost(_session->dev.parent) 2037b8631b5SMike Christie 2048434aa8bSMike Christie #define starget_to_session(_stgt) \ 2058434aa8bSMike Christie iscsi_dev_to_session(_stgt->dev.parent) 2068434aa8bSMike Christie 20732c6e1b9SMike Christie struct iscsi_cls_host { 2088aae18adSMike Christie atomic_t nr_scans; 20930a6c652SMike Christie struct mutex mutex; 21030a6c652SMike Christie }; 21130a6c652SMike Christie 212a4804cd6SMike Christie extern void iscsi_host_for_each_session(struct Scsi_Host *shost, 213a4804cd6SMike Christie void (*fn)(struct iscsi_cls_session *)); 214a4804cd6SMike Christie 215d82ff9beSMike Christie struct iscsi_endpoint { 216d82ff9beSMike Christie void *dd_data; /* LLD private data */ 217d82ff9beSMike Christie struct device dev; 21821536062SMike Christie uint64_t id; 219d82ff9beSMike Christie }; 220a4804cd6SMike Christie 2217b8631b5SMike Christie /* 2227b8631b5SMike Christie * session and connection functions that can be used by HW iSCSI LLDs 2237b8631b5SMike Christie */ 224322d739dSMike Christie #define iscsi_cls_session_printk(prefix, _cls_session, fmt, a...) \ 225322d739dSMike Christie dev_printk(prefix, &(_cls_session)->dev, fmt, ##a) 226322d739dSMike Christie 227322d739dSMike Christie #define iscsi_cls_conn_printk(prefix, _cls_conn, fmt, a...) \ 228322d739dSMike Christie dev_printk(prefix, &(_cls_conn)->dev, fmt, ##a) 229322d739dSMike Christie 2306eabafbeSMike Christie extern int iscsi_session_chkready(struct iscsi_cls_session *session); 2318434aa8bSMike Christie extern struct iscsi_cls_session *iscsi_alloc_session(struct Scsi_Host *shost, 2325d91e209SMike Christie struct iscsi_transport *transport, int dd_size); 2336a8a0d36SMike Christie extern int iscsi_add_session(struct iscsi_cls_session *session, 2346a8a0d36SMike Christie unsigned int target_id); 23526974789SMike Christie extern int iscsi_session_event(struct iscsi_cls_session *session, 23626974789SMike Christie enum iscsi_uevent_e event); 2377b8631b5SMike Christie extern struct iscsi_cls_session *iscsi_create_session(struct Scsi_Host *shost, 2386a8a0d36SMike Christie struct iscsi_transport *t, 2395d91e209SMike Christie int dd_size, 2406a8a0d36SMike Christie unsigned int target_id); 2418434aa8bSMike Christie extern void iscsi_remove_session(struct iscsi_cls_session *session); 2428434aa8bSMike Christie extern void iscsi_free_session(struct iscsi_cls_session *session); 2437b8631b5SMike Christie extern int iscsi_destroy_session(struct iscsi_cls_session *session); 2447b8631b5SMike Christie extern struct iscsi_cls_conn *iscsi_create_conn(struct iscsi_cls_session *sess, 2455d91e209SMike Christie int dd_size, uint32_t cid); 2467b8631b5SMike Christie extern int iscsi_destroy_conn(struct iscsi_cls_conn *conn); 24730a6c652SMike Christie extern void iscsi_unblock_session(struct iscsi_cls_session *session); 24830a6c652SMike Christie extern void iscsi_block_session(struct iscsi_cls_session *session); 2498aae18adSMike Christie extern int iscsi_scan_finished(struct Scsi_Host *shost, unsigned long time); 250d82ff9beSMike Christie extern struct iscsi_endpoint *iscsi_create_endpoint(int dd_size); 251d82ff9beSMike Christie extern void iscsi_destroy_endpoint(struct iscsi_endpoint *ep); 252d82ff9beSMike Christie extern struct iscsi_endpoint *iscsi_lookup_endpoint(u64 handle); 25353cb8a1fSMike Christie 2541da177e4SLinus Torvalds #endif 255