13699d92aSKiran Patil /* 23699d92aSKiran Patil * Copyright (c) 2010 Cisco Systems, Inc. 33699d92aSKiran Patil * 43699d92aSKiran Patil * This program is free software; you can redistribute it and/or modify it 53699d92aSKiran Patil * under the terms and conditions of the GNU General Public License, 63699d92aSKiran Patil * version 2, as published by the Free Software Foundation. 73699d92aSKiran Patil * 83699d92aSKiran Patil * This program is distributed in the hope it will be useful, but WITHOUT 93699d92aSKiran Patil * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 103699d92aSKiran Patil * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 113699d92aSKiran Patil * more details. 123699d92aSKiran Patil * 133699d92aSKiran Patil * You should have received a copy of the GNU General Public License along with 143699d92aSKiran Patil * this program; if not, write to the Free Software Foundation, Inc., 153699d92aSKiran Patil * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. 163699d92aSKiran Patil */ 173699d92aSKiran Patil #ifndef __TCM_FC_H__ 183699d92aSKiran Patil #define __TCM_FC_H__ 193699d92aSKiran Patil 203699d92aSKiran Patil #define FT_VERSION "0.3" 213699d92aSKiran Patil 223699d92aSKiran Patil #define FT_NAMELEN 32 /* length of ASCII WWPNs including pad */ 233699d92aSKiran Patil #define FT_TPG_NAMELEN 32 /* max length of TPG name */ 243699d92aSKiran Patil #define FT_LUN_NAMELEN 32 /* max length of LUN name */ 253699d92aSKiran Patil 263699d92aSKiran Patil struct ft_transport_id { 273699d92aSKiran Patil __u8 format; 283699d92aSKiran Patil __u8 __resvd1[7]; 293699d92aSKiran Patil __u8 wwpn[8]; 303699d92aSKiran Patil __u8 __resvd2[8]; 313699d92aSKiran Patil } __attribute__((__packed__)); 323699d92aSKiran Patil 333699d92aSKiran Patil /* 343699d92aSKiran Patil * Session (remote port). 353699d92aSKiran Patil */ 363699d92aSKiran Patil struct ft_sess { 373699d92aSKiran Patil u32 port_id; /* for hash lookup use only */ 383699d92aSKiran Patil u32 params; 393699d92aSKiran Patil u16 max_frame; /* maximum frame size */ 403699d92aSKiran Patil u64 port_name; /* port name for transport ID */ 413699d92aSKiran Patil struct ft_tport *tport; 423699d92aSKiran Patil struct se_session *se_sess; 433699d92aSKiran Patil struct hlist_node hash; /* linkage in ft_sess_hash table */ 443699d92aSKiran Patil struct rcu_head rcu; 453699d92aSKiran Patil struct kref kref; /* ref for hash and outstanding I/Os */ 463699d92aSKiran Patil }; 473699d92aSKiran Patil 483699d92aSKiran Patil /* 493699d92aSKiran Patil * Hash table of sessions per local port. 503699d92aSKiran Patil * Hash lookup by remote port FC_ID. 513699d92aSKiran Patil */ 523699d92aSKiran Patil #define FT_SESS_HASH_BITS 6 533699d92aSKiran Patil #define FT_SESS_HASH_SIZE (1 << FT_SESS_HASH_BITS) 543699d92aSKiran Patil 553699d92aSKiran Patil /* 563699d92aSKiran Patil * Per local port data. 573699d92aSKiran Patil * This is created only after a TPG exists that allows target function 583699d92aSKiran Patil * for the local port. If the TPG exists, this is allocated when 593699d92aSKiran Patil * we're notified that the local port has been created, or when 603699d92aSKiran Patil * the first PRLI provider callback is received. 613699d92aSKiran Patil */ 623699d92aSKiran Patil struct ft_tport { 633699d92aSKiran Patil struct fc_lport *lport; 643699d92aSKiran Patil struct ft_tpg *tpg; /* NULL if TPG deleted before tport */ 653699d92aSKiran Patil u32 sess_count; /* number of sessions in hash */ 663699d92aSKiran Patil struct rcu_head rcu; 673699d92aSKiran Patil struct hlist_head hash[FT_SESS_HASH_SIZE]; /* list of sessions */ 683699d92aSKiran Patil }; 693699d92aSKiran Patil 703699d92aSKiran Patil /* 713699d92aSKiran Patil * Node ID and authentication. 723699d92aSKiran Patil */ 733699d92aSKiran Patil struct ft_node_auth { 743699d92aSKiran Patil u64 port_name; 753699d92aSKiran Patil u64 node_name; 763699d92aSKiran Patil }; 773699d92aSKiran Patil 783699d92aSKiran Patil /* 793699d92aSKiran Patil * Node ACL for FC remote port session. 803699d92aSKiran Patil */ 813699d92aSKiran Patil struct ft_node_acl { 823699d92aSKiran Patil struct ft_node_auth node_auth; 833699d92aSKiran Patil struct se_node_acl se_node_acl; 843699d92aSKiran Patil }; 853699d92aSKiran Patil 863699d92aSKiran Patil struct ft_lun { 873699d92aSKiran Patil u32 index; 883699d92aSKiran Patil char name[FT_LUN_NAMELEN]; 893699d92aSKiran Patil }; 903699d92aSKiran Patil 913699d92aSKiran Patil /* 923699d92aSKiran Patil * Target portal group (local port). 933699d92aSKiran Patil */ 943699d92aSKiran Patil struct ft_tpg { 953699d92aSKiran Patil u32 index; 963699d92aSKiran Patil struct ft_lport_acl *lport_acl; 973699d92aSKiran Patil struct ft_tport *tport; /* active tport or NULL */ 983699d92aSKiran Patil struct list_head list; /* linkage in ft_lport_acl tpg_list */ 993699d92aSKiran Patil struct list_head lun_list; /* head of LUNs */ 1003699d92aSKiran Patil struct se_portal_group se_tpg; 10158fc73d1SChristoph Hellwig struct workqueue_struct *workqueue; 1023699d92aSKiran Patil }; 1033699d92aSKiran Patil 1043699d92aSKiran Patil struct ft_lport_acl { 1053699d92aSKiran Patil u64 wwpn; 1063699d92aSKiran Patil char name[FT_NAMELEN]; 1073699d92aSKiran Patil struct list_head list; 1083699d92aSKiran Patil struct list_head tpg_list; 1093699d92aSKiran Patil struct se_wwn fc_lport_wwn; 1103699d92aSKiran Patil }; 1113699d92aSKiran Patil 1123699d92aSKiran Patil /* 1133699d92aSKiran Patil * Commands 1143699d92aSKiran Patil */ 1153699d92aSKiran Patil struct ft_cmd { 11661db9527SKiran Patil u32 lun; /* LUN from request */ 1173699d92aSKiran Patil struct ft_sess *sess; /* session held for cmd */ 1183699d92aSKiran Patil struct fc_seq *seq; /* sequence in exchange mgr */ 1193699d92aSKiran Patil struct se_cmd se_cmd; /* Local TCM I/O descriptor */ 1203699d92aSKiran Patil struct fc_frame *req_frame; 1213699d92aSKiran Patil unsigned char *cdb; /* pointer to CDB inside frame */ 1223699d92aSKiran Patil u32 write_data_len; /* data received on writes */ 12358fc73d1SChristoph Hellwig struct work_struct work; 1243699d92aSKiran Patil /* Local sense buffer */ 1253699d92aSKiran Patil unsigned char ft_sense_buffer[TRANSPORT_SENSE_BUFFER]; 1263699d92aSKiran Patil u32 was_ddp_setup:1; /* Set only if ddp is setup */ 1273699d92aSKiran Patil struct scatterlist *sg; /* Set only if DDP is setup */ 1283699d92aSKiran Patil u32 sg_cnt; /* No. of item in scatterlist */ 1293699d92aSKiran Patil }; 1303699d92aSKiran Patil 1313699d92aSKiran Patil extern struct list_head ft_lport_list; 1323699d92aSKiran Patil extern struct mutex ft_lport_lock; 1333699d92aSKiran Patil extern struct fc4_prov ft_prov; 1343699d92aSKiran Patil extern struct target_fabric_configfs *ft_configfs; 1353699d92aSKiran Patil 1363699d92aSKiran Patil /* 1373699d92aSKiran Patil * Fabric methods. 1383699d92aSKiran Patil */ 1393699d92aSKiran Patil 1403699d92aSKiran Patil /* 1413699d92aSKiran Patil * Session ops. 1423699d92aSKiran Patil */ 1433699d92aSKiran Patil void ft_sess_put(struct ft_sess *); 1443699d92aSKiran Patil int ft_sess_shutdown(struct se_session *); 1453699d92aSKiran Patil void ft_sess_close(struct se_session *); 1463699d92aSKiran Patil void ft_sess_stop(struct se_session *, int, int); 1473699d92aSKiran Patil int ft_sess_logged_in(struct se_session *); 1483699d92aSKiran Patil u32 ft_sess_get_index(struct se_session *); 1493699d92aSKiran Patil u32 ft_sess_get_port_name(struct se_session *, unsigned char *, u32); 1503699d92aSKiran Patil void ft_sess_set_erl0(struct se_session *); 1513699d92aSKiran Patil 1523699d92aSKiran Patil void ft_lport_add(struct fc_lport *, void *); 1533699d92aSKiran Patil void ft_lport_del(struct fc_lport *, void *); 1543699d92aSKiran Patil int ft_lport_notify(struct notifier_block *, unsigned long, void *); 1553699d92aSKiran Patil 1563699d92aSKiran Patil /* 1573699d92aSKiran Patil * IO methods. 1583699d92aSKiran Patil */ 1593699d92aSKiran Patil void ft_check_stop_free(struct se_cmd *); 1603699d92aSKiran Patil void ft_release_cmd(struct se_cmd *); 1613699d92aSKiran Patil int ft_queue_status(struct se_cmd *); 1623699d92aSKiran Patil int ft_queue_data_in(struct se_cmd *); 1633699d92aSKiran Patil int ft_write_pending(struct se_cmd *); 1643699d92aSKiran Patil int ft_write_pending_status(struct se_cmd *); 1653699d92aSKiran Patil u32 ft_get_task_tag(struct se_cmd *); 1663699d92aSKiran Patil int ft_get_cmd_state(struct se_cmd *); 1673699d92aSKiran Patil int ft_queue_tm_resp(struct se_cmd *); 1683699d92aSKiran Patil int ft_is_state_remove(struct se_cmd *); 1693699d92aSKiran Patil 1703699d92aSKiran Patil /* 1713699d92aSKiran Patil * other internal functions. 1723699d92aSKiran Patil */ 1733699d92aSKiran Patil void ft_recv_req(struct ft_sess *, struct fc_frame *); 1743699d92aSKiran Patil struct ft_tpg *ft_lport_find_tpg(struct fc_lport *); 1753699d92aSKiran Patil struct ft_node_acl *ft_acl_get(struct ft_tpg *, struct fc_rport_priv *); 1763699d92aSKiran Patil 1773699d92aSKiran Patil void ft_recv_write_data(struct ft_cmd *, struct fc_frame *); 1783699d92aSKiran Patil void ft_dump_cmd(struct ft_cmd *, const char *caller); 1793699d92aSKiran Patil 1803699d92aSKiran Patil ssize_t ft_format_wwn(char *, size_t, u64); 1813699d92aSKiran Patil 182dcd998ccSKiran Patil /* 183dcd998ccSKiran Patil * Underlying HW specific helper function 184dcd998ccSKiran Patil */ 185dcd998ccSKiran Patil void ft_invl_hw_context(struct ft_cmd *); 186dcd998ccSKiran Patil 1873699d92aSKiran Patil #endif /* __TCM_FC_H__ */ 188