Alex Aizman | 39e8479 | 2005-08-04 19:31:00 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * iSCSI transport class definitions |
| 3 | * |
| 4 | * Copyright (C) IBM Corporation, 2004 |
Alex Aizman | 39e8479 | 2005-08-04 19:31:00 -0700 | [diff] [blame] | 5 | * Copyright (C) Mike Christie, 2004 - 2005 |
| 6 | * Copyright (C) Dmitry Yusupov, 2004 - 2005 |
| 7 | * Copyright (C) Alex Aizman, 2004 - 2005 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 26 | #include <linux/device.h> |
Alex Aizman | 39e8479 | 2005-08-04 19:31:00 -0700 | [diff] [blame] | 27 | #include <scsi/iscsi_if.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 29 | struct scsi_transport_template; |
| 30 | struct Scsi_Host; |
| 31 | struct mempool_zone; |
| 32 | struct iscsi_cls_conn; |
| 33 | |
Alex Aizman | 39e8479 | 2005-08-04 19:31:00 -0700 | [diff] [blame] | 34 | /** |
| 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 | */ |
| 52 | struct iscsi_transport { |
| 53 | struct module *owner; |
| 54 | char *name; |
| 55 | unsigned int caps; |
| 56 | struct scsi_host_template *host_template; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 57 | /* LLD session/scsi_host data size */ |
Alex Aizman | 39e8479 | 2005-08-04 19:31:00 -0700 | [diff] [blame] | 58 | int hostdata_size; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 59 | /* LLD iscsi_host data size */ |
| 60 | int ihostdata_size; |
| 61 | /* LLD connection data size */ |
| 62 | int conndata_size; |
Alex Aizman | 39e8479 | 2005-08-04 19:31:00 -0700 | [diff] [blame] | 63 | int max_lun; |
| 64 | unsigned int max_conn; |
| 65 | unsigned int max_cmd_len; |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 66 | struct iscsi_cls_session *(*create_session) |
| 67 | (struct scsi_transport_template *t, uint32_t sn, uint32_t *sid); |
| 68 | void (*destroy_session) (struct iscsi_cls_session *session); |
| 69 | struct iscsi_cls_conn *(*create_conn) (struct iscsi_cls_session *sess, |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 70 | uint32_t cid); |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 71 | int (*bind_conn) (struct iscsi_cls_session *session, |
| 72 | struct iscsi_cls_conn *cls_conn, |
Alex Aizman | 39e8479 | 2005-08-04 19:31:00 -0700 | [diff] [blame] | 73 | uint32_t transport_fd, int is_leading); |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 74 | int (*start_conn) (struct iscsi_cls_conn *conn); |
| 75 | void (*stop_conn) (struct iscsi_cls_conn *conn, int flag); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 76 | void (*destroy_conn) (struct iscsi_cls_conn *conn); |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 77 | int (*set_param) (struct iscsi_cls_conn *conn, enum iscsi_param param, |
Alex Aizman | 39e8479 | 2005-08-04 19:31:00 -0700 | [diff] [blame] | 78 | uint32_t value); |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 79 | int (*get_conn_param) (struct iscsi_cls_conn *conn, |
| 80 | enum iscsi_param param, |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 81 | uint32_t *value); |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 82 | int (*get_session_param) (struct iscsi_cls_session *session, |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 83 | enum iscsi_param param, uint32_t *value); |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 84 | int (*send_pdu) (struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr, |
Alex Aizman | 39e8479 | 2005-08-04 19:31:00 -0700 | [diff] [blame] | 85 | char *data, uint32_t data_size); |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 86 | void (*get_stats) (struct iscsi_cls_conn *conn, |
| 87 | struct iscsi_stats *stats); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | /* |
Alex Aizman | 39e8479 | 2005-08-04 19:31:00 -0700 | [diff] [blame] | 91 | * transport registration upcalls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | */ |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 93 | extern struct scsi_transport_template *iscsi_register_transport(struct iscsi_transport *tt); |
Alex Aizman | 39e8479 | 2005-08-04 19:31:00 -0700 | [diff] [blame] | 94 | extern int iscsi_unregister_transport(struct iscsi_transport *tt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
| 96 | /* |
Alex Aizman | 39e8479 | 2005-08-04 19:31:00 -0700 | [diff] [blame] | 97 | * control plane upcalls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | */ |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 99 | extern void iscsi_conn_error(struct iscsi_cls_conn *conn, enum iscsi_err error); |
| 100 | extern int iscsi_recv_pdu(struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr, |
Alex Aizman | 39e8479 | 2005-08-04 19:31:00 -0700 | [diff] [blame] | 101 | char *data, uint32_t data_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 103 | struct iscsi_cls_conn { |
| 104 | struct list_head conn_list; /* item in connlist */ |
| 105 | void *dd_data; /* LLD private data */ |
| 106 | struct iscsi_transport *transport; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 107 | int active; /* must be accessed with the connlock */ |
| 108 | struct device dev; /* sysfs transport/container device */ |
| 109 | struct mempool_zone *z_error; |
| 110 | struct mempool_zone *z_pdu; |
| 111 | struct list_head freequeue; |
| 112 | }; |
| 113 | |
| 114 | #define iscsi_dev_to_conn(_dev) \ |
| 115 | container_of(_dev, struct iscsi_cls_conn, dev) |
| 116 | |
| 117 | struct iscsi_cls_session { |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 118 | struct list_head sess_list; /* item in session_list */ |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 119 | struct iscsi_transport *transport; |
| 120 | struct device dev; /* sysfs transport/container device */ |
| 121 | }; |
| 122 | |
| 123 | #define iscsi_dev_to_session(_dev) \ |
| 124 | container_of(_dev, struct iscsi_cls_session, dev) |
| 125 | |
| 126 | #define iscsi_session_to_shost(_session) \ |
| 127 | dev_to_shost(_session->dev.parent) |
| 128 | |
| 129 | /* |
| 130 | * session and connection functions that can be used by HW iSCSI LLDs |
| 131 | */ |
| 132 | extern struct iscsi_cls_session *iscsi_create_session(struct Scsi_Host *shost, |
| 133 | struct iscsi_transport *t); |
| 134 | extern int iscsi_destroy_session(struct iscsi_cls_session *session); |
| 135 | extern struct iscsi_cls_conn *iscsi_create_conn(struct iscsi_cls_session *sess, |
| 136 | uint32_t cid); |
| 137 | extern int iscsi_destroy_conn(struct iscsi_cls_conn *conn); |
| 138 | |
| 139 | /* |
| 140 | * session functions used by software iscsi |
| 141 | */ |
| 142 | extern struct Scsi_Host * |
| 143 | iscsi_transport_create_session(struct scsi_transport_template *scsit, |
| 144 | struct iscsi_transport *transport); |
| 145 | extern int iscsi_transport_destroy_session(struct Scsi_Host *shost); |
| 146 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | #endif |