blob: f7fff7ed63c36ac98fa5eaa01439a3d20d1afb37 [file] [log] [blame]
Kiran Patil3699d922011-04-18 16:24:14 -07001/*
2 * Copyright (c) 2010 Cisco Systems, Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17#ifndef __TCM_FC_H__
18#define __TCM_FC_H__
19
20#define FT_VERSION "0.3"
21
22#define FT_NAMELEN 32 /* length of ASCII WWPNs including pad */
23#define FT_TPG_NAMELEN 32 /* max length of TPG name */
24#define FT_LUN_NAMELEN 32 /* max length of LUN name */
25
Kiran Patil3699d922011-04-18 16:24:14 -070026struct ft_transport_id {
27 __u8 format;
28 __u8 __resvd1[7];
29 __u8 wwpn[8];
30 __u8 __resvd2[8];
31} __attribute__((__packed__));
32
33/*
34 * Session (remote port).
35 */
36struct ft_sess {
37 u32 port_id; /* for hash lookup use only */
38 u32 params;
39 u16 max_frame; /* maximum frame size */
40 u64 port_name; /* port name for transport ID */
41 struct ft_tport *tport;
42 struct se_session *se_sess;
43 struct hlist_node hash; /* linkage in ft_sess_hash table */
44 struct rcu_head rcu;
45 struct kref kref; /* ref for hash and outstanding I/Os */
46};
47
48/*
49 * Hash table of sessions per local port.
50 * Hash lookup by remote port FC_ID.
51 */
52#define FT_SESS_HASH_BITS 6
53#define FT_SESS_HASH_SIZE (1 << FT_SESS_HASH_BITS)
54
55/*
56 * Per local port data.
57 * This is created only after a TPG exists that allows target function
58 * for the local port. If the TPG exists, this is allocated when
59 * we're notified that the local port has been created, or when
60 * the first PRLI provider callback is received.
61 */
62struct ft_tport {
63 struct fc_lport *lport;
64 struct ft_tpg *tpg; /* NULL if TPG deleted before tport */
65 u32 sess_count; /* number of sessions in hash */
66 struct rcu_head rcu;
67 struct hlist_head hash[FT_SESS_HASH_SIZE]; /* list of sessions */
68};
69
70/*
71 * Node ID and authentication.
72 */
73struct ft_node_auth {
74 u64 port_name;
75 u64 node_name;
76};
77
78/*
79 * Node ACL for FC remote port session.
80 */
81struct ft_node_acl {
82 struct ft_node_auth node_auth;
83 struct se_node_acl se_node_acl;
84};
85
86struct ft_lun {
87 u32 index;
88 char name[FT_LUN_NAMELEN];
89};
90
91/*
92 * Target portal group (local port).
93 */
94struct ft_tpg {
95 u32 index;
96 struct ft_lport_acl *lport_acl;
97 struct ft_tport *tport; /* active tport or NULL */
98 struct list_head list; /* linkage in ft_lport_acl tpg_list */
99 struct list_head lun_list; /* head of LUNs */
100 struct se_portal_group se_tpg;
101 struct task_struct *thread; /* processing thread */
102 struct se_queue_obj qobj; /* queue for processing thread */
103};
104
105struct ft_lport_acl {
106 u64 wwpn;
107 char name[FT_NAMELEN];
108 struct list_head list;
109 struct list_head tpg_list;
110 struct se_wwn fc_lport_wwn;
111};
112
113enum ft_cmd_state {
114 FC_CMD_ST_NEW = 0,
115 FC_CMD_ST_REJ
116};
117
118/*
119 * Commands
120 */
121struct ft_cmd {
122 enum ft_cmd_state state;
Kiran Patil61db9522011-06-22 16:30:22 -0700123 u32 lun; /* LUN from request */
Kiran Patil3699d922011-04-18 16:24:14 -0700124 struct ft_sess *sess; /* session held for cmd */
125 struct fc_seq *seq; /* sequence in exchange mgr */
126 struct se_cmd se_cmd; /* Local TCM I/O descriptor */
127 struct fc_frame *req_frame;
128 unsigned char *cdb; /* pointer to CDB inside frame */
129 u32 write_data_len; /* data received on writes */
130 struct se_queue_req se_req;
131 /* Local sense buffer */
132 unsigned char ft_sense_buffer[TRANSPORT_SENSE_BUFFER];
133 u32 was_ddp_setup:1; /* Set only if ddp is setup */
134 struct scatterlist *sg; /* Set only if DDP is setup */
135 u32 sg_cnt; /* No. of item in scatterlist */
136};
137
138extern struct list_head ft_lport_list;
139extern struct mutex ft_lport_lock;
140extern struct fc4_prov ft_prov;
141extern struct target_fabric_configfs *ft_configfs;
142
143/*
144 * Fabric methods.
145 */
146
147/*
148 * Session ops.
149 */
150void ft_sess_put(struct ft_sess *);
151int ft_sess_shutdown(struct se_session *);
152void ft_sess_close(struct se_session *);
153void ft_sess_stop(struct se_session *, int, int);
154int ft_sess_logged_in(struct se_session *);
155u32 ft_sess_get_index(struct se_session *);
156u32 ft_sess_get_port_name(struct se_session *, unsigned char *, u32);
157void ft_sess_set_erl0(struct se_session *);
158
159void ft_lport_add(struct fc_lport *, void *);
160void ft_lport_del(struct fc_lport *, void *);
161int ft_lport_notify(struct notifier_block *, unsigned long, void *);
162
163/*
164 * IO methods.
165 */
166void ft_check_stop_free(struct se_cmd *);
167void ft_release_cmd(struct se_cmd *);
168int ft_queue_status(struct se_cmd *);
169int ft_queue_data_in(struct se_cmd *);
170int ft_write_pending(struct se_cmd *);
171int ft_write_pending_status(struct se_cmd *);
172u32 ft_get_task_tag(struct se_cmd *);
173int ft_get_cmd_state(struct se_cmd *);
Kiran Patil3699d922011-04-18 16:24:14 -0700174int ft_queue_tm_resp(struct se_cmd *);
175int ft_is_state_remove(struct se_cmd *);
176
177/*
178 * other internal functions.
179 */
180int ft_thread(void *);
181void ft_recv_req(struct ft_sess *, struct fc_frame *);
182struct ft_tpg *ft_lport_find_tpg(struct fc_lport *);
183struct ft_node_acl *ft_acl_get(struct ft_tpg *, struct fc_rport_priv *);
184
185void ft_recv_write_data(struct ft_cmd *, struct fc_frame *);
186void ft_dump_cmd(struct ft_cmd *, const char *caller);
187
188ssize_t ft_format_wwn(char *, size_t, u64);
189
190#endif /* __TCM_FC_H__ */