Merge to Fedora kernel-2.6.17-1.2187_FC5 patched with stable patch-2.6.17.13-vs2...
[linux-2.6.git] / include / scsi / scsi_transport_iscsi.h
index 1b26a6c..b41cf07 100644 (file)
@@ -1,8 +1,10 @@
-/* 
+/*
  * iSCSI transport class definitions
  *
  * Copyright (C) IBM Corporation, 2004
- * Copyright (C) Mike Christie, 2004
+ * Copyright (C) Mike Christie, 2004 - 2005
+ * Copyright (C) Dmitry Yusupov, 2004 - 2005
+ * Copyright (C) Alex Aizman, 2004 - 2005
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 #ifndef SCSI_TRANSPORT_ISCSI_H
 #define SCSI_TRANSPORT_ISCSI_H
 
-#include <linux/config.h>
-#include <linux/in6.h>
-#include <linux/in.h>
+#include <linux/device.h>
+#include <scsi/iscsi_if.h>
 
 struct scsi_transport_template;
+struct Scsi_Host;
+struct mempool_zone;
+struct iscsi_cls_conn;
 
-struct iscsi_class_session {
-       uint8_t isid[6];
-       uint16_t tsih;
-       int header_digest;              /* 1 CRC32, 0 None */
-       int data_digest;                /* 1 CRC32, 0 None */
-       uint16_t tpgt;
-       union {
-               struct in6_addr sin6_addr;
-               struct in_addr sin_addr;
-       } u;
-       sa_family_t addr_type;          /* must be AF_INET or AF_INET6 */
-       uint16_t port;                  /* must be in network byte order */
-       int initial_r2t;                /* 1 Yes, 0 No */
-       int immediate_data;             /* 1 Yes, 0 No */
-       uint32_t max_recv_data_segment_len;
-       uint32_t max_burst_len;
-       uint32_t first_burst_len;
-       uint16_t def_time2wait;
-       uint16_t def_time2retain;
-       uint16_t max_outstanding_r2t;
-       int data_pdu_in_order;          /* 1 Yes, 0 No */
-       int data_sequence_in_order;     /* 1 Yes, 0 No */
-       int erl;
+/**
+ * struct iscsi_transport - iSCSI Transport template
+ *
+ * @name:              transport name
+ * @caps:              iSCSI Data-Path capabilities
+ * @create_session:    create new iSCSI session object
+ * @destroy_session:   destroy existing iSCSI session object
+ * @create_conn:       create new iSCSI connection
+ * @bind_conn:         associate this connection with existing iSCSI session
+ *                     and specified transport descriptor
+ * @destroy_conn:      destroy inactive iSCSI connection
+ * @set_param:         set iSCSI Data-Path operational parameter
+ * @start_conn:                set connection to be operational
+ * @stop_conn:         suspend/recover/terminate connection
+ * @send_pdu:          send iSCSI PDU, Login, Logout, NOP-Out, Reject, Text.
+ *
+ * Template API provided by iSCSI Transport
+ */
+struct iscsi_transport {
+       struct module *owner;
+       char *name;
+       unsigned int caps;
+       struct scsi_host_template *host_template;
+       /* LLD session/scsi_host data size */
+       int hostdata_size;
+       /* LLD iscsi_host data size */
+       int ihostdata_size;
+       /* LLD connection data size */
+       int conndata_size;
+       int max_lun;
+       unsigned int max_conn;
+       unsigned int max_cmd_len;
+       struct iscsi_cls_session *(*create_session)
+               (struct scsi_transport_template *t, uint32_t sn, uint32_t *sid);
+       void (*destroy_session) (struct iscsi_cls_session *session);
+       struct iscsi_cls_conn *(*create_conn) (struct iscsi_cls_session *sess,
+                               uint32_t cid);
+       int (*bind_conn) (struct iscsi_cls_session *session,
+                         struct iscsi_cls_conn *cls_conn,
+                         uint32_t transport_fd, int is_leading);
+       int (*start_conn) (struct iscsi_cls_conn *conn);
+       void (*stop_conn) (struct iscsi_cls_conn *conn, int flag);
+       void (*destroy_conn) (struct iscsi_cls_conn *conn);
+       int (*set_param) (struct iscsi_cls_conn *conn, enum iscsi_param param,
+                         uint32_t value);
+       int (*get_conn_param) (struct iscsi_cls_conn *conn,
+                              enum iscsi_param param,
+                              uint32_t *value);
+       int (*get_session_param) (struct iscsi_cls_session *session,
+                                 enum iscsi_param param, uint32_t *value);
+       int (*send_pdu) (struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr,
+                        char *data, uint32_t data_size);
+       void (*get_stats) (struct iscsi_cls_conn *conn,
+                          struct iscsi_stats *stats);
 };
 
 /*
- * accessor macros
+ * transport registration upcalls
  */
-#define iscsi_isid(x) \
-       (((struct iscsi_class_session *)&(x)->starget_data)->isid)
-#define iscsi_tsih(x) \
-       (((struct iscsi_class_session *)&(x)->starget_data)->tsih)
-#define iscsi_header_digest(x) \
-       (((struct iscsi_class_session *)&(x)->starget_data)->header_digest)
-#define iscsi_data_digest(x) \
-       (((struct iscsi_class_session *)&(x)->starget_data)->data_digest)
-#define iscsi_port(x) \
-       (((struct iscsi_class_session *)&(x)->starget_data)->port)
-#define iscsi_addr_type(x) \
-       (((struct iscsi_class_session *)&(x)->starget_data)->addr_type)
-#define iscsi_sin_addr(x) \
-       (((struct iscsi_class_session *)&(x)->starget_data)->u.sin_addr)
-#define iscsi_sin6_addr(x) \
-       (((struct iscsi_class_session *)&(x)->starget_data)->u.sin6_addr)
-#define iscsi_tpgt(x) \
-       (((struct iscsi_class_session *)&(x)->starget_data)->tpgt)
-#define iscsi_initial_r2t(x) \
-       (((struct iscsi_class_session *)&(x)->starget_data)->initial_r2t)
-#define iscsi_immediate_data(x) \
-       (((struct iscsi_class_session *)&(x)->starget_data)->immediate_data)
-#define iscsi_max_recv_data_segment_len(x) \
-       (((struct iscsi_class_session *)&(x)->starget_data)->max_recv_data_segment_len)
-#define iscsi_max_burst_len(x) \
-       (((struct iscsi_class_session *)&(x)->starget_data)->max_burst_len)
-#define iscsi_first_burst_len(x) \
-       (((struct iscsi_class_session *)&(x)->starget_data)->first_burst_len)
-#define iscsi_def_time2wait(x) \
-       (((struct iscsi_class_session *)&(x)->starget_data)->def_time2wait)
-#define iscsi_def_time2retain(x) \
-       (((struct iscsi_class_session *)&(x)->starget_data)->def_time2retain)
-#define iscsi_max_outstanding_r2t(x) \
-       (((struct iscsi_class_session *)&(x)->starget_data)->max_outstanding_r2t)
-#define iscsi_data_pdu_in_order(x) \
-       (((struct iscsi_class_session *)&(x)->starget_data)->data_pdu_in_order)
-#define iscsi_data_sequence_in_order(x) \
-       (((struct iscsi_class_session *)&(x)->starget_data)->data_sequence_in_order)
-#define iscsi_erl(x) \
-       (((struct iscsi_class_session *)&(x)->starget_data)->erl)
+extern struct scsi_transport_template *iscsi_register_transport(struct iscsi_transport *tt);
+extern int iscsi_unregister_transport(struct iscsi_transport *tt);
 
 /*
- * The functions by which the transport class and the driver communicate
+ * control plane upcalls
  */
-struct iscsi_function_template {
-       /*
-        * target attrs
-        */
-       void (*get_isid)(struct scsi_target *);
-       void (*get_tsih)(struct scsi_target *);
-       void (*get_header_digest)(struct scsi_target *);
-       void (*get_data_digest)(struct scsi_target *);
-       void (*get_port)(struct scsi_target *);
-       void (*get_tpgt)(struct scsi_target *);
-       /*
-        * In get_ip_address the lld must set the address and
-        * the address type
-        */
-       void (*get_ip_address)(struct scsi_target *);
-       /*
-        * The lld should snprintf the name or alias to the buffer
-        */
-       ssize_t (*get_target_name)(struct scsi_target *, char *, ssize_t);
-       ssize_t (*get_target_alias)(struct scsi_target *, char *, ssize_t);
-       void (*get_initial_r2t)(struct scsi_target *);
-       void (*get_immediate_data)(struct scsi_target *);
-       void (*get_max_recv_data_segment_len)(struct scsi_target *);
-       void (*get_max_burst_len)(struct scsi_target *);
-       void (*get_first_burst_len)(struct scsi_target *);
-       void (*get_def_time2wait)(struct scsi_target *);
-       void (*get_def_time2retain)(struct scsi_target *);
-       void (*get_max_outstanding_r2t)(struct scsi_target *);
-       void (*get_data_pdu_in_order)(struct scsi_target *);
-       void (*get_data_sequence_in_order)(struct scsi_target *);
-       void (*get_erl)(struct scsi_target *);
+extern void iscsi_conn_error(struct iscsi_cls_conn *conn, enum iscsi_err error);
+extern int iscsi_recv_pdu(struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr,
+                         char *data, uint32_t data_size);
 
-       /*
-        * host atts
-        */
+struct iscsi_cls_conn {
+       struct list_head conn_list;     /* item in connlist */
+       void *dd_data;                  /* LLD private data */
+       struct iscsi_transport *transport;
+       int active;                     /* must be accessed with the connlock */
+       struct device dev;              /* sysfs transport/container device */
+       struct mempool_zone *z_error;
+       struct mempool_zone *z_pdu;
+       struct list_head freequeue;
+};
+
+#define iscsi_dev_to_conn(_dev) \
+       container_of(_dev, struct iscsi_cls_conn, dev)
 
-       /*
-        * The lld should snprintf the name or alias to the buffer
-        */
-       ssize_t (*get_initiator_alias)(struct Scsi_Host *, char *, ssize_t);
-       ssize_t (*get_initiator_name)(struct Scsi_Host *, char *, ssize_t);
-       /*
-        * The driver sets these to tell the transport class it
-        * wants the attributes displayed in sysfs.  If the show_ flag
-        * is not set, the attribute will be private to the transport
-        * class. We could probably just test if a get_ fn was set
-        * since we only use the values for sysfs but this is how
-        * fc does it too.
-        */
-       unsigned long show_isid:1;
-       unsigned long show_tsih:1;
-       unsigned long show_header_digest:1;
-       unsigned long show_data_digest:1;
-       unsigned long show_port:1;
-       unsigned long show_tpgt:1;
-       unsigned long show_ip_address:1;
-       unsigned long show_target_name:1;
-       unsigned long show_target_alias:1;
-       unsigned long show_initial_r2t:1;
-       unsigned long show_immediate_data:1;
-       unsigned long show_max_recv_data_segment_len:1;
-       unsigned long show_max_burst_len:1;
-       unsigned long show_first_burst_len:1;
-       unsigned long show_def_time2wait:1;
-       unsigned long show_def_time2retain:1;
-       unsigned long show_max_outstanding_r2t:1;
-       unsigned long show_data_pdu_in_order:1;
-       unsigned long show_data_sequence_in_order:1;
-       unsigned long show_erl:1;
-       unsigned long show_initiator_name:1;
-       unsigned long show_initiator_alias:1;
+struct iscsi_cls_session {
+       struct list_head sess_list;             /* item in session_list */
+       struct iscsi_transport *transport;
+       struct device dev;      /* sysfs transport/container device */
 };
 
-struct scsi_transport_template *iscsi_attach_transport(struct iscsi_function_template *);
-void iscsi_release_transport(struct scsi_transport_template *);
+#define iscsi_dev_to_session(_dev) \
+       container_of(_dev, struct iscsi_cls_session, dev)
+
+#define iscsi_session_to_shost(_session) \
+       dev_to_shost(_session->dev.parent)
+
+/*
+ * session and connection functions that can be used by HW iSCSI LLDs
+ */
+extern struct iscsi_cls_session *iscsi_create_session(struct Scsi_Host *shost,
+                               struct iscsi_transport *t);
+extern int iscsi_destroy_session(struct iscsi_cls_session *session);
+extern struct iscsi_cls_conn *iscsi_create_conn(struct iscsi_cls_session *sess,
+                                           uint32_t cid);
+extern int iscsi_destroy_conn(struct iscsi_cls_conn *conn);
+
+/*
+ * session functions used by software iscsi
+ */
+extern struct Scsi_Host *
+iscsi_transport_create_session(struct scsi_transport_template *scsit,
+                               struct iscsi_transport *transport);
+extern int iscsi_transport_destroy_session(struct Scsi_Host *shost);
 
 #endif