18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * iSCSI transport class definitions 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) IBM Corporation, 2004 68c2ecf20Sopenharmony_ci * Copyright (C) Mike Christie, 2004 - 2006 78c2ecf20Sopenharmony_ci * Copyright (C) Dmitry Yusupov, 2004 - 2005 88c2ecf20Sopenharmony_ci * Copyright (C) Alex Aizman, 2004 - 2005 98c2ecf20Sopenharmony_ci */ 108c2ecf20Sopenharmony_ci#ifndef SCSI_TRANSPORT_ISCSI_H 118c2ecf20Sopenharmony_ci#define SCSI_TRANSPORT_ISCSI_H 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include <linux/device.h> 148c2ecf20Sopenharmony_ci#include <linux/list.h> 158c2ecf20Sopenharmony_ci#include <linux/mutex.h> 168c2ecf20Sopenharmony_ci#include <scsi/iscsi_if.h> 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_cistruct scsi_transport_template; 198c2ecf20Sopenharmony_cistruct iscsi_transport; 208c2ecf20Sopenharmony_cistruct iscsi_endpoint; 218c2ecf20Sopenharmony_cistruct Scsi_Host; 228c2ecf20Sopenharmony_cistruct scsi_cmnd; 238c2ecf20Sopenharmony_cistruct iscsi_cls_conn; 248c2ecf20Sopenharmony_cistruct iscsi_conn; 258c2ecf20Sopenharmony_cistruct iscsi_task; 268c2ecf20Sopenharmony_cistruct sockaddr; 278c2ecf20Sopenharmony_cistruct iscsi_iface; 288c2ecf20Sopenharmony_cistruct bsg_job; 298c2ecf20Sopenharmony_cistruct iscsi_bus_flash_session; 308c2ecf20Sopenharmony_cistruct iscsi_bus_flash_conn; 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci/** 338c2ecf20Sopenharmony_ci * struct iscsi_transport - iSCSI Transport template 348c2ecf20Sopenharmony_ci * 358c2ecf20Sopenharmony_ci * @name: transport name 368c2ecf20Sopenharmony_ci * @caps: iSCSI Data-Path capabilities 378c2ecf20Sopenharmony_ci * @create_session: create new iSCSI session object 388c2ecf20Sopenharmony_ci * @destroy_session: destroy existing iSCSI session object 398c2ecf20Sopenharmony_ci * @create_conn: create new iSCSI connection 408c2ecf20Sopenharmony_ci * @bind_conn: associate this connection with existing iSCSI session 418c2ecf20Sopenharmony_ci * and specified transport descriptor 428c2ecf20Sopenharmony_ci * @destroy_conn: destroy inactive iSCSI connection 438c2ecf20Sopenharmony_ci * @set_param: set iSCSI parameter. Return 0 on success, -ENODATA 448c2ecf20Sopenharmony_ci * when param is not supported, and a -Exx value on other 458c2ecf20Sopenharmony_ci * error. 468c2ecf20Sopenharmony_ci * @get_param get iSCSI parameter. Must return number of bytes 478c2ecf20Sopenharmony_ci * copied to buffer on success, -ENODATA when param 488c2ecf20Sopenharmony_ci * is not supported, and a -Exx value on other error 498c2ecf20Sopenharmony_ci * @start_conn: set connection to be operational 508c2ecf20Sopenharmony_ci * @stop_conn: suspend/recover/terminate connection 518c2ecf20Sopenharmony_ci * @send_pdu: send iSCSI PDU, Login, Logout, NOP-Out, Reject, Text. 528c2ecf20Sopenharmony_ci * @session_recovery_timedout: notify LLD a block during recovery timed out 538c2ecf20Sopenharmony_ci * @init_task: Initialize a iscsi_task and any internal structs. 548c2ecf20Sopenharmony_ci * When offloading the data path, this is called from 558c2ecf20Sopenharmony_ci * queuecommand with the session lock, or from the 568c2ecf20Sopenharmony_ci * iscsi_conn_send_pdu context with the session lock. 578c2ecf20Sopenharmony_ci * When not offloading the data path, this is called 588c2ecf20Sopenharmony_ci * from the scsi work queue without the session lock. 598c2ecf20Sopenharmony_ci * @xmit_task Requests LLD to transfer cmd task. Returns 0 or the 608c2ecf20Sopenharmony_ci * number of bytes transferred on success, and -Exyz 618c2ecf20Sopenharmony_ci * value on error. When offloading the data path, this 628c2ecf20Sopenharmony_ci * is called from queuecommand with the session lock, or 638c2ecf20Sopenharmony_ci * from the iscsi_conn_send_pdu context with the session 648c2ecf20Sopenharmony_ci * lock. When not offloading the data path, this is called 658c2ecf20Sopenharmony_ci * from the scsi work queue without the session lock. 668c2ecf20Sopenharmony_ci * @cleanup_task: requests LLD to fail task. Called with session lock 678c2ecf20Sopenharmony_ci * and after the connection has been suspended and 688c2ecf20Sopenharmony_ci * terminated during recovery. If called 698c2ecf20Sopenharmony_ci * from abort task then connection is not suspended 708c2ecf20Sopenharmony_ci * or terminated but sk_callback_lock is held 718c2ecf20Sopenharmony_ci * 728c2ecf20Sopenharmony_ci * Template API provided by iSCSI Transport 738c2ecf20Sopenharmony_ci */ 748c2ecf20Sopenharmony_cistruct iscsi_transport { 758c2ecf20Sopenharmony_ci struct module *owner; 768c2ecf20Sopenharmony_ci char *name; 778c2ecf20Sopenharmony_ci unsigned int caps; 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci struct iscsi_cls_session *(*create_session) (struct iscsi_endpoint *ep, 808c2ecf20Sopenharmony_ci uint16_t cmds_max, uint16_t qdepth, 818c2ecf20Sopenharmony_ci uint32_t sn); 828c2ecf20Sopenharmony_ci void (*destroy_session) (struct iscsi_cls_session *session); 838c2ecf20Sopenharmony_ci struct iscsi_cls_conn *(*create_conn) (struct iscsi_cls_session *sess, 848c2ecf20Sopenharmony_ci uint32_t cid); 858c2ecf20Sopenharmony_ci void (*unbind_conn) (struct iscsi_cls_conn *conn, bool is_active); 868c2ecf20Sopenharmony_ci int (*bind_conn) (struct iscsi_cls_session *session, 878c2ecf20Sopenharmony_ci struct iscsi_cls_conn *cls_conn, 888c2ecf20Sopenharmony_ci uint64_t transport_eph, int is_leading); 898c2ecf20Sopenharmony_ci int (*start_conn) (struct iscsi_cls_conn *conn); 908c2ecf20Sopenharmony_ci void (*stop_conn) (struct iscsi_cls_conn *conn, int flag); 918c2ecf20Sopenharmony_ci void (*destroy_conn) (struct iscsi_cls_conn *conn); 928c2ecf20Sopenharmony_ci int (*set_param) (struct iscsi_cls_conn *conn, enum iscsi_param param, 938c2ecf20Sopenharmony_ci char *buf, int buflen); 948c2ecf20Sopenharmony_ci int (*get_ep_param) (struct iscsi_endpoint *ep, enum iscsi_param param, 958c2ecf20Sopenharmony_ci char *buf); 968c2ecf20Sopenharmony_ci int (*get_conn_param) (struct iscsi_cls_conn *conn, 978c2ecf20Sopenharmony_ci enum iscsi_param param, char *buf); 988c2ecf20Sopenharmony_ci int (*get_session_param) (struct iscsi_cls_session *session, 998c2ecf20Sopenharmony_ci enum iscsi_param param, char *buf); 1008c2ecf20Sopenharmony_ci int (*get_host_param) (struct Scsi_Host *shost, 1018c2ecf20Sopenharmony_ci enum iscsi_host_param param, char *buf); 1028c2ecf20Sopenharmony_ci int (*set_host_param) (struct Scsi_Host *shost, 1038c2ecf20Sopenharmony_ci enum iscsi_host_param param, char *buf, 1048c2ecf20Sopenharmony_ci int buflen); 1058c2ecf20Sopenharmony_ci int (*send_pdu) (struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr, 1068c2ecf20Sopenharmony_ci char *data, uint32_t data_size); 1078c2ecf20Sopenharmony_ci void (*get_stats) (struct iscsi_cls_conn *conn, 1088c2ecf20Sopenharmony_ci struct iscsi_stats *stats); 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci int (*init_task) (struct iscsi_task *task); 1118c2ecf20Sopenharmony_ci int (*xmit_task) (struct iscsi_task *task); 1128c2ecf20Sopenharmony_ci void (*cleanup_task) (struct iscsi_task *task); 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci int (*alloc_pdu) (struct iscsi_task *task, uint8_t opcode); 1158c2ecf20Sopenharmony_ci int (*xmit_pdu) (struct iscsi_task *task); 1168c2ecf20Sopenharmony_ci int (*init_pdu) (struct iscsi_task *task, unsigned int offset, 1178c2ecf20Sopenharmony_ci unsigned int count); 1188c2ecf20Sopenharmony_ci void (*parse_pdu_itt) (struct iscsi_conn *conn, itt_t itt, 1198c2ecf20Sopenharmony_ci int *index, int *age); 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci void (*session_recovery_timedout) (struct iscsi_cls_session *session); 1228c2ecf20Sopenharmony_ci struct iscsi_endpoint *(*ep_connect) (struct Scsi_Host *shost, 1238c2ecf20Sopenharmony_ci struct sockaddr *dst_addr, 1248c2ecf20Sopenharmony_ci int non_blocking); 1258c2ecf20Sopenharmony_ci int (*ep_poll) (struct iscsi_endpoint *ep, int timeout_ms); 1268c2ecf20Sopenharmony_ci void (*ep_disconnect) (struct iscsi_endpoint *ep); 1278c2ecf20Sopenharmony_ci int (*tgt_dscvr) (struct Scsi_Host *shost, enum iscsi_tgt_dscvr type, 1288c2ecf20Sopenharmony_ci uint32_t enable, struct sockaddr *dst_addr); 1298c2ecf20Sopenharmony_ci int (*set_path) (struct Scsi_Host *shost, struct iscsi_path *params); 1308c2ecf20Sopenharmony_ci int (*set_iface_param) (struct Scsi_Host *shost, void *data, 1318c2ecf20Sopenharmony_ci uint32_t len); 1328c2ecf20Sopenharmony_ci int (*get_iface_param) (struct iscsi_iface *iface, 1338c2ecf20Sopenharmony_ci enum iscsi_param_type param_type, 1348c2ecf20Sopenharmony_ci int param, char *buf); 1358c2ecf20Sopenharmony_ci umode_t (*attr_is_visible)(int param_type, int param); 1368c2ecf20Sopenharmony_ci int (*bsg_request)(struct bsg_job *job); 1378c2ecf20Sopenharmony_ci int (*send_ping) (struct Scsi_Host *shost, uint32_t iface_num, 1388c2ecf20Sopenharmony_ci uint32_t iface_type, uint32_t payload_size, 1398c2ecf20Sopenharmony_ci uint32_t pid, struct sockaddr *dst_addr); 1408c2ecf20Sopenharmony_ci int (*get_chap) (struct Scsi_Host *shost, uint16_t chap_tbl_idx, 1418c2ecf20Sopenharmony_ci uint32_t *num_entries, char *buf); 1428c2ecf20Sopenharmony_ci int (*delete_chap) (struct Scsi_Host *shost, uint16_t chap_tbl_idx); 1438c2ecf20Sopenharmony_ci int (*set_chap) (struct Scsi_Host *shost, void *data, int len); 1448c2ecf20Sopenharmony_ci int (*get_flashnode_param) (struct iscsi_bus_flash_session *fnode_sess, 1458c2ecf20Sopenharmony_ci int param, char *buf); 1468c2ecf20Sopenharmony_ci int (*set_flashnode_param) (struct iscsi_bus_flash_session *fnode_sess, 1478c2ecf20Sopenharmony_ci struct iscsi_bus_flash_conn *fnode_conn, 1488c2ecf20Sopenharmony_ci void *data, int len); 1498c2ecf20Sopenharmony_ci int (*new_flashnode) (struct Scsi_Host *shost, const char *buf, 1508c2ecf20Sopenharmony_ci int len); 1518c2ecf20Sopenharmony_ci int (*del_flashnode) (struct iscsi_bus_flash_session *fnode_sess); 1528c2ecf20Sopenharmony_ci int (*login_flashnode) (struct iscsi_bus_flash_session *fnode_sess, 1538c2ecf20Sopenharmony_ci struct iscsi_bus_flash_conn *fnode_conn); 1548c2ecf20Sopenharmony_ci int (*logout_flashnode) (struct iscsi_bus_flash_session *fnode_sess, 1558c2ecf20Sopenharmony_ci struct iscsi_bus_flash_conn *fnode_conn); 1568c2ecf20Sopenharmony_ci int (*logout_flashnode_sid) (struct iscsi_cls_session *cls_sess); 1578c2ecf20Sopenharmony_ci int (*get_host_stats) (struct Scsi_Host *shost, char *buf, int len); 1588c2ecf20Sopenharmony_ci u8 (*check_protection)(struct iscsi_task *task, sector_t *sector); 1598c2ecf20Sopenharmony_ci}; 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_ci/* 1628c2ecf20Sopenharmony_ci * transport registration upcalls 1638c2ecf20Sopenharmony_ci */ 1648c2ecf20Sopenharmony_ciextern struct scsi_transport_template *iscsi_register_transport(struct iscsi_transport *tt); 1658c2ecf20Sopenharmony_ciextern int iscsi_unregister_transport(struct iscsi_transport *tt); 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_ci/* 1688c2ecf20Sopenharmony_ci * control plane upcalls 1698c2ecf20Sopenharmony_ci */ 1708c2ecf20Sopenharmony_ciextern void iscsi_conn_error_event(struct iscsi_cls_conn *conn, 1718c2ecf20Sopenharmony_ci enum iscsi_err error); 1728c2ecf20Sopenharmony_ciextern void iscsi_conn_login_event(struct iscsi_cls_conn *conn, 1738c2ecf20Sopenharmony_ci enum iscsi_conn_state state); 1748c2ecf20Sopenharmony_ciextern int iscsi_recv_pdu(struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr, 1758c2ecf20Sopenharmony_ci char *data, uint32_t data_size); 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ciextern int iscsi_offload_mesg(struct Scsi_Host *shost, 1788c2ecf20Sopenharmony_ci struct iscsi_transport *transport, uint32_t type, 1798c2ecf20Sopenharmony_ci char *data, uint16_t data_size); 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_ciextern void iscsi_post_host_event(uint32_t host_no, 1828c2ecf20Sopenharmony_ci struct iscsi_transport *transport, 1838c2ecf20Sopenharmony_ci enum iscsi_host_event_code code, 1848c2ecf20Sopenharmony_ci uint32_t data_size, 1858c2ecf20Sopenharmony_ci uint8_t *data); 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ciextern void iscsi_ping_comp_event(uint32_t host_no, 1888c2ecf20Sopenharmony_ci struct iscsi_transport *transport, 1898c2ecf20Sopenharmony_ci uint32_t status, uint32_t pid, 1908c2ecf20Sopenharmony_ci uint32_t data_size, uint8_t *data); 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_ci/* iscsi class connection state */ 1938c2ecf20Sopenharmony_cienum iscsi_connection_state { 1948c2ecf20Sopenharmony_ci ISCSI_CONN_UP = 0, 1958c2ecf20Sopenharmony_ci ISCSI_CONN_DOWN, 1968c2ecf20Sopenharmony_ci ISCSI_CONN_FAILED, 1978c2ecf20Sopenharmony_ci ISCSI_CONN_BOUND, 1988c2ecf20Sopenharmony_ci}; 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ci#define ISCSI_CLS_CONN_BIT_CLEANUP 1 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_cistruct iscsi_cls_conn { 2038c2ecf20Sopenharmony_ci struct list_head conn_list; /* item in connlist */ 2048c2ecf20Sopenharmony_ci void *dd_data; /* LLD private data */ 2058c2ecf20Sopenharmony_ci struct iscsi_transport *transport; 2068c2ecf20Sopenharmony_ci uint32_t cid; /* connection id */ 2078c2ecf20Sopenharmony_ci /* 2088c2ecf20Sopenharmony_ci * This protects the conn startup and binding/unbinding of the ep to 2098c2ecf20Sopenharmony_ci * the conn. Unbinding includes ep_disconnect and stop_conn. 2108c2ecf20Sopenharmony_ci */ 2118c2ecf20Sopenharmony_ci struct mutex ep_mutex; 2128c2ecf20Sopenharmony_ci struct iscsi_endpoint *ep; 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_ci /* Used when accessing flags and queueing work. */ 2158c2ecf20Sopenharmony_ci spinlock_t lock; 2168c2ecf20Sopenharmony_ci unsigned long flags; 2178c2ecf20Sopenharmony_ci struct work_struct cleanup_work; 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_ci struct device dev; /* sysfs transport/container device */ 2208c2ecf20Sopenharmony_ci enum iscsi_connection_state state; 2218c2ecf20Sopenharmony_ci}; 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_ci#define iscsi_dev_to_conn(_dev) \ 2248c2ecf20Sopenharmony_ci container_of(_dev, struct iscsi_cls_conn, dev) 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_ci#define transport_class_to_conn(_cdev) \ 2278c2ecf20Sopenharmony_ci iscsi_dev_to_conn(_cdev->parent) 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_ci#define iscsi_conn_to_session(_conn) \ 2308c2ecf20Sopenharmony_ci iscsi_dev_to_session(_conn->dev.parent) 2318c2ecf20Sopenharmony_ci 2328c2ecf20Sopenharmony_ci/* iscsi class session state */ 2338c2ecf20Sopenharmony_cienum { 2348c2ecf20Sopenharmony_ci ISCSI_SESSION_LOGGED_IN, 2358c2ecf20Sopenharmony_ci ISCSI_SESSION_FAILED, 2368c2ecf20Sopenharmony_ci ISCSI_SESSION_FREE, 2378c2ecf20Sopenharmony_ci}; 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_cienum { 2408c2ecf20Sopenharmony_ci ISCSI_SESSION_TARGET_UNBOUND, 2418c2ecf20Sopenharmony_ci ISCSI_SESSION_TARGET_ALLOCATED, 2428c2ecf20Sopenharmony_ci ISCSI_SESSION_TARGET_SCANNED, 2438c2ecf20Sopenharmony_ci ISCSI_SESSION_TARGET_UNBINDING, 2448c2ecf20Sopenharmony_ci ISCSI_SESSION_TARGET_MAX, 2458c2ecf20Sopenharmony_ci}; 2468c2ecf20Sopenharmony_ci 2478c2ecf20Sopenharmony_ci#define ISCSI_MAX_TARGET -1 2488c2ecf20Sopenharmony_ci 2498c2ecf20Sopenharmony_cistruct iscsi_cls_session { 2508c2ecf20Sopenharmony_ci struct list_head sess_list; /* item in session_list */ 2518c2ecf20Sopenharmony_ci struct iscsi_transport *transport; 2528c2ecf20Sopenharmony_ci spinlock_t lock; 2538c2ecf20Sopenharmony_ci struct work_struct block_work; 2548c2ecf20Sopenharmony_ci struct work_struct unblock_work; 2558c2ecf20Sopenharmony_ci struct work_struct scan_work; 2568c2ecf20Sopenharmony_ci struct work_struct unbind_work; 2578c2ecf20Sopenharmony_ci struct work_struct destroy_work; 2588c2ecf20Sopenharmony_ci 2598c2ecf20Sopenharmony_ci /* recovery fields */ 2608c2ecf20Sopenharmony_ci int recovery_tmo; 2618c2ecf20Sopenharmony_ci bool recovery_tmo_sysfs_override; 2628c2ecf20Sopenharmony_ci struct delayed_work recovery_work; 2638c2ecf20Sopenharmony_ci 2648c2ecf20Sopenharmony_ci unsigned int target_id; 2658c2ecf20Sopenharmony_ci bool ida_used; 2668c2ecf20Sopenharmony_ci 2678c2ecf20Sopenharmony_ci /* 2688c2ecf20Sopenharmony_ci * pid of userspace process that created session or -1 if 2698c2ecf20Sopenharmony_ci * created by the kernel. 2708c2ecf20Sopenharmony_ci */ 2718c2ecf20Sopenharmony_ci pid_t creator; 2728c2ecf20Sopenharmony_ci int state; 2738c2ecf20Sopenharmony_ci int target_state; /* session target bind state */ 2748c2ecf20Sopenharmony_ci int sid; /* session id */ 2758c2ecf20Sopenharmony_ci void *dd_data; /* LLD private data */ 2768c2ecf20Sopenharmony_ci struct device dev; /* sysfs transport/container device */ 2778c2ecf20Sopenharmony_ci}; 2788c2ecf20Sopenharmony_ci 2798c2ecf20Sopenharmony_ci#define iscsi_dev_to_session(_dev) \ 2808c2ecf20Sopenharmony_ci container_of(_dev, struct iscsi_cls_session, dev) 2818c2ecf20Sopenharmony_ci 2828c2ecf20Sopenharmony_ci#define transport_class_to_session(_cdev) \ 2838c2ecf20Sopenharmony_ci iscsi_dev_to_session(_cdev->parent) 2848c2ecf20Sopenharmony_ci 2858c2ecf20Sopenharmony_ci#define iscsi_session_to_shost(_session) \ 2868c2ecf20Sopenharmony_ci dev_to_shost(_session->dev.parent) 2878c2ecf20Sopenharmony_ci 2888c2ecf20Sopenharmony_ci#define starget_to_session(_stgt) \ 2898c2ecf20Sopenharmony_ci iscsi_dev_to_session(_stgt->dev.parent) 2908c2ecf20Sopenharmony_ci 2918c2ecf20Sopenharmony_cistruct iscsi_cls_host { 2928c2ecf20Sopenharmony_ci atomic_t nr_scans; 2938c2ecf20Sopenharmony_ci struct mutex mutex; 2948c2ecf20Sopenharmony_ci struct request_queue *bsg_q; 2958c2ecf20Sopenharmony_ci uint32_t port_speed; 2968c2ecf20Sopenharmony_ci uint32_t port_state; 2978c2ecf20Sopenharmony_ci}; 2988c2ecf20Sopenharmony_ci 2998c2ecf20Sopenharmony_ci#define iscsi_job_to_shost(_job) \ 3008c2ecf20Sopenharmony_ci dev_to_shost(_job->dev) 3018c2ecf20Sopenharmony_ci 3028c2ecf20Sopenharmony_ciextern void iscsi_host_for_each_session(struct Scsi_Host *shost, 3038c2ecf20Sopenharmony_ci void (*fn)(struct iscsi_cls_session *)); 3048c2ecf20Sopenharmony_ci 3058c2ecf20Sopenharmony_cistruct iscsi_endpoint { 3068c2ecf20Sopenharmony_ci void *dd_data; /* LLD private data */ 3078c2ecf20Sopenharmony_ci struct device dev; 3088c2ecf20Sopenharmony_ci uint64_t id; 3098c2ecf20Sopenharmony_ci struct iscsi_cls_conn *conn; 3108c2ecf20Sopenharmony_ci}; 3118c2ecf20Sopenharmony_ci 3128c2ecf20Sopenharmony_cistruct iscsi_iface { 3138c2ecf20Sopenharmony_ci struct device dev; 3148c2ecf20Sopenharmony_ci struct iscsi_transport *transport; 3158c2ecf20Sopenharmony_ci uint32_t iface_type; /* IPv4 or IPv6 */ 3168c2ecf20Sopenharmony_ci uint32_t iface_num; /* iface number, 0 - n */ 3178c2ecf20Sopenharmony_ci void *dd_data; /* LLD private data */ 3188c2ecf20Sopenharmony_ci}; 3198c2ecf20Sopenharmony_ci 3208c2ecf20Sopenharmony_ci#define iscsi_dev_to_iface(_dev) \ 3218c2ecf20Sopenharmony_ci container_of(_dev, struct iscsi_iface, dev) 3228c2ecf20Sopenharmony_ci 3238c2ecf20Sopenharmony_ci#define iscsi_iface_to_shost(_iface) \ 3248c2ecf20Sopenharmony_ci dev_to_shost(_iface->dev.parent) 3258c2ecf20Sopenharmony_ci 3268c2ecf20Sopenharmony_ci 3278c2ecf20Sopenharmony_cistruct iscsi_bus_flash_conn { 3288c2ecf20Sopenharmony_ci struct list_head conn_list; /* item in connlist */ 3298c2ecf20Sopenharmony_ci void *dd_data; /* LLD private data */ 3308c2ecf20Sopenharmony_ci struct iscsi_transport *transport; 3318c2ecf20Sopenharmony_ci struct device dev; /* sysfs transport/container device */ 3328c2ecf20Sopenharmony_ci /* iscsi connection parameters */ 3338c2ecf20Sopenharmony_ci uint32_t exp_statsn; 3348c2ecf20Sopenharmony_ci uint32_t statsn; 3358c2ecf20Sopenharmony_ci unsigned max_recv_dlength; /* initiator_max_recv_dsl*/ 3368c2ecf20Sopenharmony_ci unsigned max_xmit_dlength; /* target_max_recv_dsl */ 3378c2ecf20Sopenharmony_ci unsigned max_segment_size; 3388c2ecf20Sopenharmony_ci unsigned tcp_xmit_wsf; 3398c2ecf20Sopenharmony_ci unsigned tcp_recv_wsf; 3408c2ecf20Sopenharmony_ci int hdrdgst_en; 3418c2ecf20Sopenharmony_ci int datadgst_en; 3428c2ecf20Sopenharmony_ci int port; 3438c2ecf20Sopenharmony_ci char *ipaddress; 3448c2ecf20Sopenharmony_ci char *link_local_ipv6_addr; 3458c2ecf20Sopenharmony_ci char *redirect_ipaddr; 3468c2ecf20Sopenharmony_ci uint16_t keepalive_timeout; 3478c2ecf20Sopenharmony_ci uint16_t local_port; 3488c2ecf20Sopenharmony_ci uint8_t snack_req_en; 3498c2ecf20Sopenharmony_ci /* tcp timestamp negotiation status */ 3508c2ecf20Sopenharmony_ci uint8_t tcp_timestamp_stat; 3518c2ecf20Sopenharmony_ci uint8_t tcp_nagle_disable; 3528c2ecf20Sopenharmony_ci /* tcp window scale factor */ 3538c2ecf20Sopenharmony_ci uint8_t tcp_wsf_disable; 3548c2ecf20Sopenharmony_ci uint8_t tcp_timer_scale; 3558c2ecf20Sopenharmony_ci uint8_t tcp_timestamp_en; 3568c2ecf20Sopenharmony_ci uint8_t ipv4_tos; 3578c2ecf20Sopenharmony_ci uint8_t ipv6_traffic_class; 3588c2ecf20Sopenharmony_ci uint8_t ipv6_flow_label; 3598c2ecf20Sopenharmony_ci uint8_t fragment_disable; 3608c2ecf20Sopenharmony_ci /* Link local IPv6 address is assigned by firmware or driver */ 3618c2ecf20Sopenharmony_ci uint8_t is_fw_assigned_ipv6; 3628c2ecf20Sopenharmony_ci}; 3638c2ecf20Sopenharmony_ci 3648c2ecf20Sopenharmony_ci#define iscsi_dev_to_flash_conn(_dev) \ 3658c2ecf20Sopenharmony_ci container_of(_dev, struct iscsi_bus_flash_conn, dev) 3668c2ecf20Sopenharmony_ci 3678c2ecf20Sopenharmony_ci#define iscsi_flash_conn_to_flash_session(_conn) \ 3688c2ecf20Sopenharmony_ci iscsi_dev_to_flash_session(_conn->dev.parent) 3698c2ecf20Sopenharmony_ci 3708c2ecf20Sopenharmony_ci#define ISID_SIZE 6 3718c2ecf20Sopenharmony_ci 3728c2ecf20Sopenharmony_cistruct iscsi_bus_flash_session { 3738c2ecf20Sopenharmony_ci struct list_head sess_list; /* item in session_list */ 3748c2ecf20Sopenharmony_ci struct iscsi_transport *transport; 3758c2ecf20Sopenharmony_ci unsigned int target_id; 3768c2ecf20Sopenharmony_ci int flash_state; /* persistent or non-persistent */ 3778c2ecf20Sopenharmony_ci void *dd_data; /* LLD private data */ 3788c2ecf20Sopenharmony_ci struct device dev; /* sysfs transport/container device */ 3798c2ecf20Sopenharmony_ci /* iscsi session parameters */ 3808c2ecf20Sopenharmony_ci unsigned first_burst; 3818c2ecf20Sopenharmony_ci unsigned max_burst; 3828c2ecf20Sopenharmony_ci unsigned short max_r2t; 3838c2ecf20Sopenharmony_ci int default_taskmgmt_timeout; 3848c2ecf20Sopenharmony_ci int initial_r2t_en; 3858c2ecf20Sopenharmony_ci int imm_data_en; 3868c2ecf20Sopenharmony_ci int time2wait; 3878c2ecf20Sopenharmony_ci int time2retain; 3888c2ecf20Sopenharmony_ci int pdu_inorder_en; 3898c2ecf20Sopenharmony_ci int dataseq_inorder_en; 3908c2ecf20Sopenharmony_ci int erl; 3918c2ecf20Sopenharmony_ci int tpgt; 3928c2ecf20Sopenharmony_ci char *username; 3938c2ecf20Sopenharmony_ci char *username_in; 3948c2ecf20Sopenharmony_ci char *password; 3958c2ecf20Sopenharmony_ci char *password_in; 3968c2ecf20Sopenharmony_ci char *targetname; 3978c2ecf20Sopenharmony_ci char *targetalias; 3988c2ecf20Sopenharmony_ci char *portal_type; 3998c2ecf20Sopenharmony_ci uint16_t tsid; 4008c2ecf20Sopenharmony_ci uint16_t chap_in_idx; 4018c2ecf20Sopenharmony_ci uint16_t chap_out_idx; 4028c2ecf20Sopenharmony_ci /* index of iSCSI discovery session if the entry is 4038c2ecf20Sopenharmony_ci * discovered by iSCSI discovery session 4048c2ecf20Sopenharmony_ci */ 4058c2ecf20Sopenharmony_ci uint16_t discovery_parent_idx; 4068c2ecf20Sopenharmony_ci /* indicates if discovery was done through iSNS discovery service 4078c2ecf20Sopenharmony_ci * or through sendTarget */ 4088c2ecf20Sopenharmony_ci uint16_t discovery_parent_type; 4098c2ecf20Sopenharmony_ci /* Firmware auto sendtarget discovery disable */ 4108c2ecf20Sopenharmony_ci uint8_t auto_snd_tgt_disable; 4118c2ecf20Sopenharmony_ci uint8_t discovery_sess; 4128c2ecf20Sopenharmony_ci /* indicates if this flashnode entry is enabled or disabled */ 4138c2ecf20Sopenharmony_ci uint8_t entry_state; 4148c2ecf20Sopenharmony_ci uint8_t chap_auth_en; 4158c2ecf20Sopenharmony_ci /* enables firmware to auto logout the discovery session on discovery 4168c2ecf20Sopenharmony_ci * completion 4178c2ecf20Sopenharmony_ci */ 4188c2ecf20Sopenharmony_ci uint8_t discovery_logout_en; 4198c2ecf20Sopenharmony_ci uint8_t bidi_chap_en; 4208c2ecf20Sopenharmony_ci /* makes authentication for discovery session optional */ 4218c2ecf20Sopenharmony_ci uint8_t discovery_auth_optional; 4228c2ecf20Sopenharmony_ci uint8_t isid[ISID_SIZE]; 4238c2ecf20Sopenharmony_ci uint8_t is_boot_target; 4248c2ecf20Sopenharmony_ci}; 4258c2ecf20Sopenharmony_ci 4268c2ecf20Sopenharmony_ci#define iscsi_dev_to_flash_session(_dev) \ 4278c2ecf20Sopenharmony_ci container_of(_dev, struct iscsi_bus_flash_session, dev) 4288c2ecf20Sopenharmony_ci 4298c2ecf20Sopenharmony_ci#define iscsi_flash_session_to_shost(_session) \ 4308c2ecf20Sopenharmony_ci dev_to_shost(_session->dev.parent) 4318c2ecf20Sopenharmony_ci 4328c2ecf20Sopenharmony_ci/* 4338c2ecf20Sopenharmony_ci * session and connection functions that can be used by HW iSCSI LLDs 4348c2ecf20Sopenharmony_ci */ 4358c2ecf20Sopenharmony_ci#define iscsi_cls_session_printk(prefix, _cls_session, fmt, a...) \ 4368c2ecf20Sopenharmony_ci dev_printk(prefix, &(_cls_session)->dev, fmt, ##a) 4378c2ecf20Sopenharmony_ci 4388c2ecf20Sopenharmony_ci#define iscsi_cls_conn_printk(prefix, _cls_conn, fmt, a...) \ 4398c2ecf20Sopenharmony_ci dev_printk(prefix, &(_cls_conn)->dev, fmt, ##a) 4408c2ecf20Sopenharmony_ci 4418c2ecf20Sopenharmony_ciextern int iscsi_session_chkready(struct iscsi_cls_session *session); 4428c2ecf20Sopenharmony_ciextern int iscsi_is_session_online(struct iscsi_cls_session *session); 4438c2ecf20Sopenharmony_ciextern struct iscsi_cls_session *iscsi_alloc_session(struct Scsi_Host *shost, 4448c2ecf20Sopenharmony_ci struct iscsi_transport *transport, int dd_size); 4458c2ecf20Sopenharmony_ciextern int iscsi_add_session(struct iscsi_cls_session *session, 4468c2ecf20Sopenharmony_ci unsigned int target_id); 4478c2ecf20Sopenharmony_ciextern int iscsi_session_event(struct iscsi_cls_session *session, 4488c2ecf20Sopenharmony_ci enum iscsi_uevent_e event); 4498c2ecf20Sopenharmony_ciextern struct iscsi_cls_session *iscsi_create_session(struct Scsi_Host *shost, 4508c2ecf20Sopenharmony_ci struct iscsi_transport *t, 4518c2ecf20Sopenharmony_ci int dd_size, 4528c2ecf20Sopenharmony_ci unsigned int target_id); 4538c2ecf20Sopenharmony_ciextern void iscsi_remove_session(struct iscsi_cls_session *session); 4548c2ecf20Sopenharmony_ciextern void iscsi_free_session(struct iscsi_cls_session *session); 4558c2ecf20Sopenharmony_ciextern struct iscsi_cls_conn *iscsi_create_conn(struct iscsi_cls_session *sess, 4568c2ecf20Sopenharmony_ci int dd_size, uint32_t cid); 4578c2ecf20Sopenharmony_ciextern void iscsi_put_conn(struct iscsi_cls_conn *conn); 4588c2ecf20Sopenharmony_ciextern void iscsi_get_conn(struct iscsi_cls_conn *conn); 4598c2ecf20Sopenharmony_ciextern int iscsi_destroy_conn(struct iscsi_cls_conn *conn); 4608c2ecf20Sopenharmony_ciextern void iscsi_unblock_session(struct iscsi_cls_session *session); 4618c2ecf20Sopenharmony_ciextern void iscsi_block_session(struct iscsi_cls_session *session); 4628c2ecf20Sopenharmony_ciextern int iscsi_scan_finished(struct Scsi_Host *shost, unsigned long time); 4638c2ecf20Sopenharmony_ciextern struct iscsi_endpoint *iscsi_create_endpoint(int dd_size); 4648c2ecf20Sopenharmony_ciextern void iscsi_destroy_endpoint(struct iscsi_endpoint *ep); 4658c2ecf20Sopenharmony_ciextern struct iscsi_endpoint *iscsi_lookup_endpoint(u64 handle); 4668c2ecf20Sopenharmony_ciextern void iscsi_put_endpoint(struct iscsi_endpoint *ep); 4678c2ecf20Sopenharmony_ciextern int iscsi_block_scsi_eh(struct scsi_cmnd *cmd); 4688c2ecf20Sopenharmony_ciextern struct iscsi_iface *iscsi_create_iface(struct Scsi_Host *shost, 4698c2ecf20Sopenharmony_ci struct iscsi_transport *t, 4708c2ecf20Sopenharmony_ci uint32_t iface_type, 4718c2ecf20Sopenharmony_ci uint32_t iface_num, int dd_size); 4728c2ecf20Sopenharmony_ciextern void iscsi_destroy_iface(struct iscsi_iface *iface); 4738c2ecf20Sopenharmony_ciextern struct iscsi_iface *iscsi_lookup_iface(int handle); 4748c2ecf20Sopenharmony_ciextern char *iscsi_get_port_speed_name(struct Scsi_Host *shost); 4758c2ecf20Sopenharmony_ciextern char *iscsi_get_port_state_name(struct Scsi_Host *shost); 4768c2ecf20Sopenharmony_ciextern int iscsi_is_session_dev(const struct device *dev); 4778c2ecf20Sopenharmony_ci 4788c2ecf20Sopenharmony_ciextern char *iscsi_get_discovery_parent_name(int parent_type); 4798c2ecf20Sopenharmony_ciextern struct device * 4808c2ecf20Sopenharmony_ciiscsi_find_flashnode(struct Scsi_Host *shost, void *data, 4818c2ecf20Sopenharmony_ci int (*fn)(struct device *dev, void *data)); 4828c2ecf20Sopenharmony_ci 4838c2ecf20Sopenharmony_ciextern struct iscsi_bus_flash_session * 4848c2ecf20Sopenharmony_ciiscsi_create_flashnode_sess(struct Scsi_Host *shost, int index, 4858c2ecf20Sopenharmony_ci struct iscsi_transport *transport, int dd_size); 4868c2ecf20Sopenharmony_ci 4878c2ecf20Sopenharmony_ciextern struct iscsi_bus_flash_conn * 4888c2ecf20Sopenharmony_ciiscsi_create_flashnode_conn(struct Scsi_Host *shost, 4898c2ecf20Sopenharmony_ci struct iscsi_bus_flash_session *fnode_sess, 4908c2ecf20Sopenharmony_ci struct iscsi_transport *transport, int dd_size); 4918c2ecf20Sopenharmony_ci 4928c2ecf20Sopenharmony_ciextern void 4938c2ecf20Sopenharmony_ciiscsi_destroy_flashnode_sess(struct iscsi_bus_flash_session *fnode_sess); 4948c2ecf20Sopenharmony_ci 4958c2ecf20Sopenharmony_ciextern void iscsi_destroy_all_flashnode(struct Scsi_Host *shost); 4968c2ecf20Sopenharmony_ciextern int iscsi_flashnode_bus_match(struct device *dev, 4978c2ecf20Sopenharmony_ci struct device_driver *drv); 4988c2ecf20Sopenharmony_ciextern struct device * 4998c2ecf20Sopenharmony_ciiscsi_find_flashnode_sess(struct Scsi_Host *shost, void *data, 5008c2ecf20Sopenharmony_ci int (*fn)(struct device *dev, void *data)); 5018c2ecf20Sopenharmony_ciextern struct device * 5028c2ecf20Sopenharmony_ciiscsi_find_flashnode_conn(struct iscsi_bus_flash_session *fnode_sess); 5038c2ecf20Sopenharmony_ci 5048c2ecf20Sopenharmony_ciextern char * 5058c2ecf20Sopenharmony_ciiscsi_get_ipaddress_state_name(enum iscsi_ipaddress_state port_state); 5068c2ecf20Sopenharmony_ciextern char *iscsi_get_router_state_name(enum iscsi_router_state router_state); 5078c2ecf20Sopenharmony_ci#endif 508