blob: 9d2b99159ee76dcf4bb09b665d58bcacf7ce4dd5 [file] [log] [blame]
Alex Aizman39e84792005-08-04 19:31:00 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * iSCSI transport class definitions
3 *
4 * Copyright (C) IBM Corporation, 2004
Alex Aizman39e84792005-08-04 19:31:00 -07005 * Copyright (C) Mike Christie, 2004 - 2005
6 * Copyright (C) Dmitry Yusupov, 2004 - 2005
7 * Copyright (C) Alex Aizman, 2004 - 2005
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
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
Mike Christie7b8631b2006-01-13 18:05:50 -060026#include <linux/device.h>
Alex Aizman39e84792005-08-04 19:31:00 -070027#include <scsi/iscsi_if.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Mike Christie7b8631b2006-01-13 18:05:50 -060029struct scsi_transport_template;
30struct Scsi_Host;
31struct mempool_zone;
32struct iscsi_cls_conn;
33
Alex Aizman39e84792005-08-04 19:31:00 -070034/**
35 * struct iscsi_transport - iSCSI Transport template
36 *
37 * @name: transport name
38 * @caps: iSCSI Data-Path capabilities
39 * @create_session: create new iSCSI session object
40 * @destroy_session: destroy existing iSCSI session object
41 * @create_conn: create new iSCSI connection
42 * @bind_conn: associate this connection with existing iSCSI session
43 * and specified transport descriptor
44 * @destroy_conn: destroy inactive iSCSI connection
45 * @set_param: set iSCSI Data-Path operational parameter
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 *
50 * Template API provided by iSCSI Transport
51 */
52struct iscsi_transport {
53 struct module *owner;
54 char *name;
55 unsigned int caps;
Mike Christiefd7255f2006-04-06 21:13:36 -050056 /* LLD sets this to indicate what values it can export to sysfs */
57 unsigned int param_mask;
Alex Aizman39e84792005-08-04 19:31:00 -070058 struct scsi_host_template *host_template;
Mike Christie7b8631b2006-01-13 18:05:50 -060059 /* LLD session/scsi_host data size */
Alex Aizman39e84792005-08-04 19:31:00 -070060 int hostdata_size;
Mike Christie7b8631b2006-01-13 18:05:50 -060061 /* LLD connection data size */
62 int conndata_size;
Mike Christieb5c7a122006-04-06 21:13:33 -050063 /* LLD session data size */
64 int sessiondata_size;
Alex Aizman39e84792005-08-04 19:31:00 -070065 int max_lun;
66 unsigned int max_conn;
67 unsigned int max_cmd_len;
Mike Christie7b7232f2006-02-01 21:06:49 -060068 struct iscsi_cls_session *(*create_session)
Mike Christieb5c7a122006-04-06 21:13:33 -050069 (struct scsi_transport_template *t, uint32_t sn, uint32_t *hn);
Mike Christie7b7232f2006-02-01 21:06:49 -060070 void (*destroy_session) (struct iscsi_cls_session *session);
71 struct iscsi_cls_conn *(*create_conn) (struct iscsi_cls_session *sess,
Mike Christie7b8631b2006-01-13 18:05:50 -060072 uint32_t cid);
Mike Christie7b7232f2006-02-01 21:06:49 -060073 int (*bind_conn) (struct iscsi_cls_session *session,
74 struct iscsi_cls_conn *cls_conn,
Alex Aizman39e84792005-08-04 19:31:00 -070075 uint32_t transport_fd, int is_leading);
Mike Christie7b7232f2006-02-01 21:06:49 -060076 int (*start_conn) (struct iscsi_cls_conn *conn);
77 void (*stop_conn) (struct iscsi_cls_conn *conn, int flag);
Mike Christie7b8631b2006-01-13 18:05:50 -060078 void (*destroy_conn) (struct iscsi_cls_conn *conn);
Mike Christie7b7232f2006-02-01 21:06:49 -060079 int (*set_param) (struct iscsi_cls_conn *conn, enum iscsi_param param,
Alex Aizman39e84792005-08-04 19:31:00 -070080 uint32_t value);
Mike Christie7b7232f2006-02-01 21:06:49 -060081 int (*get_conn_param) (struct iscsi_cls_conn *conn,
Mike Christiefd7255f2006-04-06 21:13:36 -050082 enum iscsi_param param, uint32_t *value);
Mike Christie7b7232f2006-02-01 21:06:49 -060083 int (*get_session_param) (struct iscsi_cls_session *session,
Mike Christie7b8631b2006-01-13 18:05:50 -060084 enum iscsi_param param, uint32_t *value);
Mike Christiefd7255f2006-04-06 21:13:36 -050085 int (*get_conn_str_param) (struct iscsi_cls_conn *conn,
86 enum iscsi_param param, char *buf);
87 int (*get_session_str_param) (struct iscsi_cls_session *session,
88 enum iscsi_param param, char *buf);
Mike Christie7b7232f2006-02-01 21:06:49 -060089 int (*send_pdu) (struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr,
Alex Aizman39e84792005-08-04 19:31:00 -070090 char *data, uint32_t data_size);
Mike Christie7b7232f2006-02-01 21:06:49 -060091 void (*get_stats) (struct iscsi_cls_conn *conn,
92 struct iscsi_stats *stats);
Mike Christie30a6c652006-04-06 21:13:39 -050093 void (*session_recovery_timedout) (struct iscsi_cls_session *session);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094};
95
96/*
Alex Aizman39e84792005-08-04 19:31:00 -070097 * transport registration upcalls
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 */
Mike Christie7b8631b2006-01-13 18:05:50 -060099extern struct scsi_transport_template *iscsi_register_transport(struct iscsi_transport *tt);
Alex Aizman39e84792005-08-04 19:31:00 -0700100extern int iscsi_unregister_transport(struct iscsi_transport *tt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
102/*
Alex Aizman39e84792005-08-04 19:31:00 -0700103 * control plane upcalls
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 */
Mike Christie7b7232f2006-02-01 21:06:49 -0600105extern void iscsi_conn_error(struct iscsi_cls_conn *conn, enum iscsi_err error);
106extern int iscsi_recv_pdu(struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr,
Alex Aizman39e84792005-08-04 19:31:00 -0700107 char *data, uint32_t data_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Mike Christie7b8631b2006-01-13 18:05:50 -0600109struct iscsi_cls_conn {
110 struct list_head conn_list; /* item in connlist */
111 void *dd_data; /* LLD private data */
112 struct iscsi_transport *transport;
Mike Christieb5c7a122006-04-06 21:13:33 -0500113 uint32_t cid; /* connection id */
Mike Christiefd7255f2006-04-06 21:13:36 -0500114
115 /* portal/group values we got during discovery */
116 char *persistent_address;
117 int persistent_port;
118 /* portal/group values we are currently using */
119 char *address;
120 int port;
121
Mike Christie7b8631b2006-01-13 18:05:50 -0600122 int active; /* must be accessed with the connlock */
123 struct device dev; /* sysfs transport/container device */
124 struct mempool_zone *z_error;
125 struct mempool_zone *z_pdu;
126 struct list_head freequeue;
127};
128
129#define iscsi_dev_to_conn(_dev) \
130 container_of(_dev, struct iscsi_cls_conn, dev)
131
132struct iscsi_cls_session {
Mike Christie7b7232f2006-02-01 21:06:49 -0600133 struct list_head sess_list; /* item in session_list */
Mike Christie30a6c652006-04-06 21:13:39 -0500134 struct list_head host_list;
Mike Christie7b8631b2006-01-13 18:05:50 -0600135 struct iscsi_transport *transport;
Mike Christiefd7255f2006-04-06 21:13:36 -0500136
137 /* iSCSI values used as unique id by userspace. */
138 char *targetname;
139 int tpgt;
140
Mike Christie30a6c652006-04-06 21:13:39 -0500141 /* recovery fields */
142 int recovery_tmo;
143 struct work_struct recovery_work;
144
145 int target_id;
146 int channel;
147
Mike Christieb5c7a122006-04-06 21:13:33 -0500148 int sid; /* session id */
149 void *dd_data; /* LLD private data */
Mike Christie7b8631b2006-01-13 18:05:50 -0600150 struct device dev; /* sysfs transport/container device */
151};
152
153#define iscsi_dev_to_session(_dev) \
154 container_of(_dev, struct iscsi_cls_session, dev)
155
156#define iscsi_session_to_shost(_session) \
157 dev_to_shost(_session->dev.parent)
158
Mike Christie30a6c652006-04-06 21:13:39 -0500159struct iscsi_host {
160 int next_target_id;
161 struct list_head sessions;
162 struct mutex mutex;
163};
164
Mike Christie7b8631b2006-01-13 18:05:50 -0600165/*
166 * session and connection functions that can be used by HW iSCSI LLDs
167 */
168extern struct iscsi_cls_session *iscsi_create_session(struct Scsi_Host *shost,
Mike Christie30a6c652006-04-06 21:13:39 -0500169 struct iscsi_transport *t, int channel);
Mike Christie7b8631b2006-01-13 18:05:50 -0600170extern int iscsi_destroy_session(struct iscsi_cls_session *session);
171extern struct iscsi_cls_conn *iscsi_create_conn(struct iscsi_cls_session *sess,
172 uint32_t cid);
173extern int iscsi_destroy_conn(struct iscsi_cls_conn *conn);
Mike Christie30a6c652006-04-06 21:13:39 -0500174extern void iscsi_unblock_session(struct iscsi_cls_session *session);
175extern void iscsi_block_session(struct iscsi_cls_session *session);
Mike Christie7b8631b2006-01-13 18:05:50 -0600176
177/*
178 * session functions used by software iscsi
179 */
180extern struct Scsi_Host *
181iscsi_transport_create_session(struct scsi_transport_template *scsit,
182 struct iscsi_transport *transport);
183extern int iscsi_transport_destroy_session(struct Scsi_Host *shost);
184
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185#endif