Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * iSCSI transport class definitions
0004  *
0005  * Copyright (C) IBM Corporation, 2004
0006  * Copyright (C) Mike Christie, 2004 - 2006
0007  * Copyright (C) Dmitry Yusupov, 2004 - 2005
0008  * Copyright (C) Alex Aizman, 2004 - 2005
0009  */
0010 #ifndef SCSI_TRANSPORT_ISCSI_H
0011 #define SCSI_TRANSPORT_ISCSI_H
0012 
0013 #include <linux/device.h>
0014 #include <linux/list.h>
0015 #include <linux/mutex.h>
0016 #include <scsi/iscsi_if.h>
0017 
0018 struct scsi_transport_template;
0019 struct iscsi_transport;
0020 struct iscsi_endpoint;
0021 struct Scsi_Host;
0022 struct scsi_cmnd;
0023 struct iscsi_cls_conn;
0024 struct iscsi_conn;
0025 struct iscsi_task;
0026 struct sockaddr;
0027 struct iscsi_iface;
0028 struct bsg_job;
0029 struct iscsi_bus_flash_session;
0030 struct iscsi_bus_flash_conn;
0031 
0032 /**
0033  * struct iscsi_transport - iSCSI Transport template
0034  *
0035  * @name:       transport name
0036  * @caps:       iSCSI Data-Path capabilities
0037  * @create_session: create new iSCSI session object
0038  * @destroy_session:    destroy existing iSCSI session object
0039  * @create_conn:    create new iSCSI connection
0040  * @bind_conn:      associate this connection with existing iSCSI session
0041  *          and specified transport descriptor
0042  * @destroy_conn:   destroy inactive iSCSI connection
0043  * @set_param:      set iSCSI parameter. Return 0 on success, -ENODATA
0044  *          when param is not supported, and a -Exx value on other
0045  *          error.
0046  * @get_param       get iSCSI parameter. Must return number of bytes
0047  *          copied to buffer on success, -ENODATA when param
0048  *          is not supported, and a -Exx value on other error
0049  * @start_conn:     set connection to be operational
0050  * @stop_conn:      suspend/recover/terminate connection
0051  * @send_pdu:       send iSCSI PDU, Login, Logout, NOP-Out, Reject, Text.
0052  * @session_recovery_timedout: notify LLD a block during recovery timed out
0053  * @init_task:      Initialize a iscsi_task and any internal structs.
0054  *          When offloading the data path, this is called from
0055  *          queuecommand with the session lock, or from the
0056  *          iscsi_conn_send_pdu context with the session lock.
0057  *          When not offloading the data path, this is called
0058  *          from the scsi work queue without the session lock.
0059  * @xmit_task       Requests LLD to transfer cmd task. Returns 0 or the
0060  *          number of bytes transferred on success, and -Exyz
0061  *          value on error. When offloading the data path, this
0062  *          is called from queuecommand with the session lock, or
0063  *          from the iscsi_conn_send_pdu context with the session
0064  *          lock. When not offloading the data path, this is called
0065  *          from the scsi work queue without the session lock.
0066  * @cleanup_task:   requests LLD to fail task. Called with session lock
0067  *          and after the connection has been suspended and
0068  *          terminated during recovery. If called
0069  *          from abort task then connection is not suspended
0070  *          or terminated but sk_callback_lock is held
0071  *
0072  * Template API provided by iSCSI Transport
0073  */
0074 struct iscsi_transport {
0075     struct module *owner;
0076     char *name;
0077     unsigned int caps;
0078 
0079     struct iscsi_cls_session *(*create_session) (struct iscsi_endpoint *ep,
0080                     uint16_t cmds_max, uint16_t qdepth,
0081                     uint32_t sn);
0082     void (*destroy_session) (struct iscsi_cls_session *session);
0083     struct iscsi_cls_conn *(*create_conn) (struct iscsi_cls_session *sess,
0084                 uint32_t cid);
0085     void (*unbind_conn) (struct iscsi_cls_conn *conn, bool is_active);
0086     int (*bind_conn) (struct iscsi_cls_session *session,
0087               struct iscsi_cls_conn *cls_conn,
0088               uint64_t transport_eph, int is_leading);
0089     int (*start_conn) (struct iscsi_cls_conn *conn);
0090     void (*stop_conn) (struct iscsi_cls_conn *conn, int flag);
0091     void (*destroy_conn) (struct iscsi_cls_conn *conn);
0092     int (*set_param) (struct iscsi_cls_conn *conn, enum iscsi_param param,
0093               char *buf, int buflen);
0094     int (*get_ep_param) (struct iscsi_endpoint *ep, enum iscsi_param param,
0095                  char *buf);
0096     int (*get_conn_param) (struct iscsi_cls_conn *conn,
0097                    enum iscsi_param param, char *buf);
0098     int (*get_session_param) (struct iscsi_cls_session *session,
0099                   enum iscsi_param param, char *buf);
0100     int (*get_host_param) (struct Scsi_Host *shost,
0101                 enum iscsi_host_param param, char *buf);
0102     int (*set_host_param) (struct Scsi_Host *shost,
0103                    enum iscsi_host_param param, char *buf,
0104                    int buflen);
0105     int (*send_pdu) (struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr,
0106              char *data, uint32_t data_size);
0107     void (*get_stats) (struct iscsi_cls_conn *conn,
0108                struct iscsi_stats *stats);
0109 
0110     int (*init_task) (struct iscsi_task *task);
0111     int (*xmit_task) (struct iscsi_task *task);
0112     void (*cleanup_task) (struct iscsi_task *task);
0113 
0114     int (*alloc_pdu) (struct iscsi_task *task, uint8_t opcode);
0115     int (*xmit_pdu) (struct iscsi_task *task);
0116     int (*init_pdu) (struct iscsi_task *task, unsigned int offset,
0117              unsigned int count);
0118     void (*parse_pdu_itt) (struct iscsi_conn *conn, itt_t itt,
0119                    int *index, int *age);
0120 
0121     void (*session_recovery_timedout) (struct iscsi_cls_session *session);
0122     struct iscsi_endpoint *(*ep_connect) (struct Scsi_Host *shost,
0123                           struct sockaddr *dst_addr,
0124                           int non_blocking);
0125     int (*ep_poll) (struct iscsi_endpoint *ep, int timeout_ms);
0126     void (*ep_disconnect) (struct iscsi_endpoint *ep);
0127     int (*tgt_dscvr) (struct Scsi_Host *shost, enum iscsi_tgt_dscvr type,
0128               uint32_t enable, struct sockaddr *dst_addr);
0129     int (*set_path) (struct Scsi_Host *shost, struct iscsi_path *params);
0130     int (*set_iface_param) (struct Scsi_Host *shost, void *data,
0131                 uint32_t len);
0132     int (*get_iface_param) (struct iscsi_iface *iface,
0133                 enum iscsi_param_type param_type,
0134                 int param, char *buf);
0135     umode_t (*attr_is_visible)(int param_type, int param);
0136     int (*bsg_request)(struct bsg_job *job);
0137     int (*send_ping) (struct Scsi_Host *shost, uint32_t iface_num,
0138               uint32_t iface_type, uint32_t payload_size,
0139               uint32_t pid, struct sockaddr *dst_addr);
0140     int (*get_chap) (struct Scsi_Host *shost, uint16_t chap_tbl_idx,
0141              uint32_t *num_entries, char *buf);
0142     int (*delete_chap) (struct Scsi_Host *shost, uint16_t chap_tbl_idx);
0143     int (*set_chap) (struct Scsi_Host *shost, void *data, int len);
0144     int (*get_flashnode_param) (struct iscsi_bus_flash_session *fnode_sess,
0145                     int param, char *buf);
0146     int (*set_flashnode_param) (struct iscsi_bus_flash_session *fnode_sess,
0147                     struct iscsi_bus_flash_conn *fnode_conn,
0148                     void *data, int len);
0149     int (*new_flashnode) (struct Scsi_Host *shost, const char *buf,
0150                   int len);
0151     int (*del_flashnode) (struct iscsi_bus_flash_session *fnode_sess);
0152     int (*login_flashnode) (struct iscsi_bus_flash_session *fnode_sess,
0153                 struct iscsi_bus_flash_conn *fnode_conn);
0154     int (*logout_flashnode) (struct iscsi_bus_flash_session *fnode_sess,
0155                  struct iscsi_bus_flash_conn *fnode_conn);
0156     int (*logout_flashnode_sid) (struct iscsi_cls_session *cls_sess);
0157     int (*get_host_stats) (struct Scsi_Host *shost, char *buf, int len);
0158     u8 (*check_protection)(struct iscsi_task *task, sector_t *sector);
0159 };
0160 
0161 /*
0162  * transport registration upcalls
0163  */
0164 extern struct scsi_transport_template *iscsi_register_transport(struct iscsi_transport *tt);
0165 extern void iscsi_unregister_transport(struct iscsi_transport *tt);
0166 
0167 /*
0168  * control plane upcalls
0169  */
0170 extern void iscsi_conn_error_event(struct iscsi_cls_conn *conn,
0171                    enum iscsi_err error);
0172 extern void iscsi_conn_login_event(struct iscsi_cls_conn *conn,
0173                    enum iscsi_conn_state state);
0174 extern int iscsi_recv_pdu(struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr,
0175               char *data, uint32_t data_size);
0176 
0177 extern int iscsi_offload_mesg(struct Scsi_Host *shost,
0178                   struct iscsi_transport *transport, uint32_t type,
0179                   char *data, uint16_t data_size);
0180 
0181 extern void iscsi_post_host_event(uint32_t host_no,
0182                   struct iscsi_transport *transport,
0183                   enum iscsi_host_event_code code,
0184                   uint32_t data_size,
0185                   uint8_t *data);
0186 
0187 extern void iscsi_ping_comp_event(uint32_t host_no,
0188                   struct iscsi_transport *transport,
0189                   uint32_t status, uint32_t pid,
0190                   uint32_t data_size, uint8_t *data);
0191 
0192 /* iscsi class connection state */
0193 enum iscsi_connection_state {
0194     ISCSI_CONN_UP = 0,
0195     ISCSI_CONN_DOWN,
0196     ISCSI_CONN_FAILED,
0197     ISCSI_CONN_BOUND,
0198 };
0199 
0200 #define ISCSI_CLS_CONN_BIT_CLEANUP  1
0201 
0202 struct iscsi_cls_conn {
0203     struct list_head conn_list; /* item in connlist */
0204     void *dd_data;          /* LLD private data */
0205     struct iscsi_transport *transport;
0206     uint32_t cid;           /* connection id */
0207     /*
0208      * This protects the conn startup and binding/unbinding of the ep to
0209      * the conn. Unbinding includes ep_disconnect and stop_conn.
0210      */
0211     struct mutex ep_mutex;
0212     struct iscsi_endpoint *ep;
0213 
0214     /* Used when accessing flags and queueing work. */
0215     spinlock_t lock;
0216     unsigned long flags;
0217     struct work_struct cleanup_work;
0218 
0219     struct device dev;      /* sysfs transport/container device */
0220     enum iscsi_connection_state state;
0221 };
0222 
0223 #define iscsi_dev_to_conn(_dev) \
0224     container_of(_dev, struct iscsi_cls_conn, dev)
0225 
0226 #define transport_class_to_conn(_cdev) \
0227     iscsi_dev_to_conn(_cdev->parent)
0228 
0229 #define iscsi_conn_to_session(_conn) \
0230     iscsi_dev_to_session(_conn->dev.parent)
0231 
0232 /* iscsi class session state */
0233 enum {
0234     ISCSI_SESSION_LOGGED_IN,
0235     ISCSI_SESSION_FAILED,
0236     ISCSI_SESSION_FREE,
0237 };
0238 
0239 #define ISCSI_MAX_TARGET -1
0240 
0241 struct iscsi_cls_session {
0242     struct list_head sess_list;     /* item in session_list */
0243     struct iscsi_transport *transport;
0244     spinlock_t lock;
0245     struct work_struct block_work;
0246     struct work_struct unblock_work;
0247     struct work_struct scan_work;
0248     struct work_struct unbind_work;
0249     struct work_struct destroy_work;
0250 
0251     /* recovery fields */
0252     int recovery_tmo;
0253     bool recovery_tmo_sysfs_override;
0254     struct delayed_work recovery_work;
0255 
0256     struct workqueue_struct *workq;
0257 
0258     unsigned int target_id;
0259     bool ida_used;
0260 
0261     /*
0262      * pid of userspace process that created session or -1 if
0263      * created by the kernel.
0264      */
0265     pid_t creator;
0266     int state;
0267     int sid;                /* session id */
0268     void *dd_data;              /* LLD private data */
0269     struct device dev;  /* sysfs transport/container device */
0270 };
0271 
0272 #define iscsi_dev_to_session(_dev) \
0273     container_of(_dev, struct iscsi_cls_session, dev)
0274 
0275 #define transport_class_to_session(_cdev) \
0276     iscsi_dev_to_session(_cdev->parent)
0277 
0278 #define iscsi_session_to_shost(_session) \
0279     dev_to_shost(_session->dev.parent)
0280 
0281 #define starget_to_session(_stgt) \
0282     iscsi_dev_to_session(_stgt->dev.parent)
0283 
0284 struct iscsi_cls_host {
0285     struct mutex mutex;
0286     struct request_queue *bsg_q;
0287     uint32_t port_speed;
0288     uint32_t port_state;
0289 };
0290 
0291 #define iscsi_job_to_shost(_job) \
0292         dev_to_shost(_job->dev)
0293 
0294 extern void iscsi_host_for_each_session(struct Scsi_Host *shost,
0295                 void (*fn)(struct iscsi_cls_session *));
0296 
0297 struct iscsi_endpoint {
0298     void *dd_data;          /* LLD private data */
0299     struct device dev;
0300     int id;
0301     struct iscsi_cls_conn *conn;
0302 };
0303 
0304 struct iscsi_iface {
0305     struct device dev;
0306     struct iscsi_transport *transport;
0307     uint32_t iface_type;    /* IPv4 or IPv6 */
0308     uint32_t iface_num; /* iface number, 0 - n */
0309     void *dd_data;      /* LLD private data */
0310 };
0311 
0312 #define iscsi_dev_to_iface(_dev) \
0313     container_of(_dev, struct iscsi_iface, dev)
0314 
0315 #define iscsi_iface_to_shost(_iface) \
0316     dev_to_shost(_iface->dev.parent)
0317 
0318 
0319 struct iscsi_bus_flash_conn {
0320     struct list_head conn_list; /* item in connlist */
0321     void *dd_data;          /* LLD private data */
0322     struct iscsi_transport *transport;
0323     struct device dev;      /* sysfs transport/container device */
0324     /* iscsi connection parameters */
0325     uint32_t        exp_statsn;
0326     uint32_t        statsn;
0327     unsigned        max_recv_dlength; /* initiator_max_recv_dsl*/
0328     unsigned        max_xmit_dlength; /* target_max_recv_dsl */
0329     unsigned        max_segment_size;
0330     unsigned        tcp_xmit_wsf;
0331     unsigned        tcp_recv_wsf;
0332     int         hdrdgst_en;
0333     int         datadgst_en;
0334     int         port;
0335     char            *ipaddress;
0336     char            *link_local_ipv6_addr;
0337     char            *redirect_ipaddr;
0338     uint16_t        keepalive_timeout;
0339     uint16_t        local_port;
0340     uint8_t         snack_req_en;
0341     /* tcp timestamp negotiation status */
0342     uint8_t         tcp_timestamp_stat;
0343     uint8_t         tcp_nagle_disable;
0344     /* tcp window scale factor */
0345     uint8_t         tcp_wsf_disable;
0346     uint8_t         tcp_timer_scale;
0347     uint8_t         tcp_timestamp_en;
0348     uint8_t         ipv4_tos;
0349     uint8_t         ipv6_traffic_class;
0350     uint8_t         ipv6_flow_label;
0351     uint8_t         fragment_disable;
0352     /* Link local IPv6 address is assigned by firmware or driver */
0353     uint8_t         is_fw_assigned_ipv6;
0354 };
0355 
0356 #define iscsi_dev_to_flash_conn(_dev) \
0357     container_of(_dev, struct iscsi_bus_flash_conn, dev)
0358 
0359 #define iscsi_flash_conn_to_flash_session(_conn) \
0360     iscsi_dev_to_flash_session(_conn->dev.parent)
0361 
0362 #define ISID_SIZE 6
0363 
0364 struct iscsi_bus_flash_session {
0365     struct list_head sess_list;     /* item in session_list */
0366     struct iscsi_transport *transport;
0367     unsigned int target_id;
0368     int flash_state;    /* persistent or non-persistent */
0369     void *dd_data;              /* LLD private data */
0370     struct device dev;  /* sysfs transport/container device */
0371     /* iscsi session parameters */
0372     unsigned        first_burst;
0373     unsigned        max_burst;
0374     unsigned short      max_r2t;
0375     int         default_taskmgmt_timeout;
0376     int         initial_r2t_en;
0377     int         imm_data_en;
0378     int         time2wait;
0379     int         time2retain;
0380     int         pdu_inorder_en;
0381     int         dataseq_inorder_en;
0382     int         erl;
0383     int         tpgt;
0384     char            *username;
0385     char            *username_in;
0386     char            *password;
0387     char            *password_in;
0388     char            *targetname;
0389     char            *targetalias;
0390     char            *portal_type;
0391     uint16_t        tsid;
0392     uint16_t        chap_in_idx;
0393     uint16_t        chap_out_idx;
0394     /* index of iSCSI discovery session if the entry is
0395      * discovered by iSCSI discovery session
0396      */
0397     uint16_t        discovery_parent_idx;
0398     /* indicates if discovery was done through iSNS discovery service
0399      * or through sendTarget */
0400     uint16_t        discovery_parent_type;
0401     /* Firmware auto sendtarget discovery disable */
0402     uint8_t         auto_snd_tgt_disable;
0403     uint8_t         discovery_sess;
0404     /* indicates if this flashnode entry is enabled or disabled */
0405     uint8_t         entry_state;
0406     uint8_t         chap_auth_en;
0407     /* enables firmware to auto logout the discovery session on discovery
0408      * completion
0409      */
0410     uint8_t         discovery_logout_en;
0411     uint8_t         bidi_chap_en;
0412     /* makes authentication for discovery session optional */
0413     uint8_t         discovery_auth_optional;
0414     uint8_t         isid[ISID_SIZE];
0415     uint8_t         is_boot_target;
0416 };
0417 
0418 #define iscsi_dev_to_flash_session(_dev) \
0419     container_of(_dev, struct iscsi_bus_flash_session, dev)
0420 
0421 #define iscsi_flash_session_to_shost(_session) \
0422     dev_to_shost(_session->dev.parent)
0423 
0424 /*
0425  * session and connection functions that can be used by HW iSCSI LLDs
0426  */
0427 #define iscsi_cls_session_printk(prefix, _cls_session, fmt, a...) \
0428     dev_printk(prefix, &(_cls_session)->dev, fmt, ##a)
0429 
0430 #define iscsi_cls_conn_printk(prefix, _cls_conn, fmt, a...) \
0431     dev_printk(prefix, &(_cls_conn)->dev, fmt, ##a)
0432 
0433 extern int iscsi_session_chkready(struct iscsi_cls_session *session);
0434 extern int iscsi_is_session_online(struct iscsi_cls_session *session);
0435 extern struct iscsi_cls_session *iscsi_alloc_session(struct Scsi_Host *shost,
0436                 struct iscsi_transport *transport, int dd_size);
0437 extern int iscsi_add_session(struct iscsi_cls_session *session,
0438                  unsigned int target_id);
0439 extern int iscsi_session_event(struct iscsi_cls_session *session,
0440                    enum iscsi_uevent_e event);
0441 extern struct iscsi_cls_session *iscsi_create_session(struct Scsi_Host *shost,
0442                         struct iscsi_transport *t,
0443                         int dd_size,
0444                         unsigned int target_id);
0445 extern void iscsi_force_destroy_session(struct iscsi_cls_session *session);
0446 extern void iscsi_remove_session(struct iscsi_cls_session *session);
0447 extern void iscsi_free_session(struct iscsi_cls_session *session);
0448 extern struct iscsi_cls_conn *iscsi_alloc_conn(struct iscsi_cls_session *sess,
0449                         int dd_size, uint32_t cid);
0450 extern int iscsi_add_conn(struct iscsi_cls_conn *conn);
0451 extern void iscsi_remove_conn(struct iscsi_cls_conn *conn);
0452 extern void iscsi_put_conn(struct iscsi_cls_conn *conn);
0453 extern void iscsi_get_conn(struct iscsi_cls_conn *conn);
0454 extern void iscsi_unblock_session(struct iscsi_cls_session *session);
0455 extern void iscsi_block_session(struct iscsi_cls_session *session);
0456 extern struct iscsi_endpoint *iscsi_create_endpoint(int dd_size);
0457 extern void iscsi_destroy_endpoint(struct iscsi_endpoint *ep);
0458 extern struct iscsi_endpoint *iscsi_lookup_endpoint(u64 handle);
0459 extern void iscsi_put_endpoint(struct iscsi_endpoint *ep);
0460 extern int iscsi_block_scsi_eh(struct scsi_cmnd *cmd);
0461 extern struct iscsi_iface *iscsi_create_iface(struct Scsi_Host *shost,
0462                           struct iscsi_transport *t,
0463                           uint32_t iface_type,
0464                           uint32_t iface_num, int dd_size);
0465 extern void iscsi_destroy_iface(struct iscsi_iface *iface);
0466 extern struct iscsi_iface *iscsi_lookup_iface(int handle);
0467 extern char *iscsi_get_port_speed_name(struct Scsi_Host *shost);
0468 extern char *iscsi_get_port_state_name(struct Scsi_Host *shost);
0469 extern int iscsi_is_session_dev(const struct device *dev);
0470 
0471 extern char *iscsi_get_discovery_parent_name(int parent_type);
0472 extern struct device *
0473 iscsi_find_flashnode(struct Scsi_Host *shost, void *data,
0474              int (*fn)(struct device *dev, void *data));
0475 
0476 extern struct iscsi_bus_flash_session *
0477 iscsi_create_flashnode_sess(struct Scsi_Host *shost, int index,
0478                 struct iscsi_transport *transport, int dd_size);
0479 
0480 extern struct iscsi_bus_flash_conn *
0481 iscsi_create_flashnode_conn(struct Scsi_Host *shost,
0482                 struct iscsi_bus_flash_session *fnode_sess,
0483                 struct iscsi_transport *transport, int dd_size);
0484 
0485 extern void
0486 iscsi_destroy_flashnode_sess(struct iscsi_bus_flash_session *fnode_sess);
0487 
0488 extern void iscsi_destroy_all_flashnode(struct Scsi_Host *shost);
0489 extern int iscsi_flashnode_bus_match(struct device *dev,
0490                      struct device_driver *drv);
0491 extern struct device *
0492 iscsi_find_flashnode_sess(struct Scsi_Host *shost, void *data,
0493               int (*fn)(struct device *dev, void *data));
0494 extern struct device *
0495 iscsi_find_flashnode_conn(struct iscsi_bus_flash_session *fnode_sess);
0496 
0497 extern char *
0498 iscsi_get_ipaddress_state_name(enum iscsi_ipaddress_state port_state);
0499 extern char *iscsi_get_router_state_name(enum iscsi_router_state router_state);
0500 #endif