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