1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (c) 2010 Cisco Systems, Inc.
4  */
5 #ifndef __TCM_FC_H__
6 #define __TCM_FC_H__
7 
8 #include <linux/types.h>
9 #include <target/target_core_base.h>
10 
11 #define FT_VERSION "0.4"
12 
13 #define FT_NAMELEN 32		/* length of ASCII WWPNs including pad */
14 #define FT_TPG_NAMELEN 32	/* max length of TPG name */
15 #define FT_LUN_NAMELEN 32	/* max length of LUN name */
16 #define TCM_FC_DEFAULT_TAGS 512	/* tags used for per-session preallocation */
17 
18 struct ft_transport_id {
19 	__u8	format;
20 	__u8	__resvd1[7];
21 	__u8	wwpn[8];
22 	__u8	__resvd2[8];
23 } __attribute__((__packed__));
24 
25 /*
26  * Session (remote port).
27  */
28 struct ft_sess {
29 	u32 port_id;			/* for hash lookup use only */
30 	u32 params;
31 	u16 max_frame;			/* maximum frame size */
32 	u64 port_name;			/* port name for transport ID */
33 	struct ft_tport *tport;
34 	struct se_session *se_sess;
35 	struct hlist_node hash;		/* linkage in ft_sess_hash table */
36 	struct rcu_head rcu;
37 	struct kref kref;		/* ref for hash and outstanding I/Os */
38 };
39 
40 /*
41  * Hash table of sessions per local port.
42  * Hash lookup by remote port FC_ID.
43  */
44 #define	FT_SESS_HASH_BITS	6
45 #define	FT_SESS_HASH_SIZE	(1 << FT_SESS_HASH_BITS)
46 
47 /*
48  * Per local port data.
49  * This is created only after a TPG exists that allows target function
50  * for the local port.  If the TPG exists, this is allocated when
51  * we're notified that the local port has been created, or when
52  * the first PRLI provider callback is received.
53  */
54 struct ft_tport {
55 	struct fc_lport *lport;
56 	struct ft_tpg *tpg;		/* NULL if TPG deleted before tport */
57 	u32	sess_count;		/* number of sessions in hash */
58 	struct rcu_head rcu;
59 	struct hlist_head hash[FT_SESS_HASH_SIZE];	/* list of sessions */
60 };
61 
62 /*
63  * Node ID and authentication.
64  */
65 struct ft_node_auth {
66 	u64	port_name;
67 	u64	node_name;
68 };
69 
70 /*
71  * Node ACL for FC remote port session.
72  */
73 struct ft_node_acl {
74 	struct se_node_acl se_node_acl;
75 	struct ft_node_auth node_auth;
76 };
77 
78 struct ft_lun {
79 	u32 index;
80 	char name[FT_LUN_NAMELEN];
81 };
82 
83 /*
84  * Target portal group (local port).
85  */
86 struct ft_tpg {
87 	u32 index;
88 	struct ft_lport_wwn *lport_wwn;
89 	struct ft_tport *tport;		/* active tport or NULL */
90 	struct list_head lun_list;	/* head of LUNs */
91 	struct se_portal_group se_tpg;
92 	struct workqueue_struct *workqueue;
93 };
94 
95 struct ft_lport_wwn {
96 	u64 wwpn;
97 	char name[FT_NAMELEN];
98 	struct list_head ft_wwn_node;
99 	struct ft_tpg *tpg;
100 	struct se_wwn se_wwn;
101 };
102 
103 /*
104  * Commands
105  */
106 struct ft_cmd {
107 	struct ft_sess *sess;		/* session held for cmd */
108 	struct fc_seq *seq;		/* sequence in exchange mgr */
109 	struct se_cmd se_cmd;		/* Local TCM I/O descriptor */
110 	struct fc_frame *req_frame;
111 	u32 write_data_len;		/* data received on writes */
112 	struct work_struct work;
113 	/* Local sense buffer */
114 	unsigned char ft_sense_buffer[TRANSPORT_SENSE_BUFFER];
115 	u32 was_ddp_setup:1;		/* Set only if ddp is setup */
116 	u32 aborted:1;			/* Set if aborted by reset or timeout */
117 	struct scatterlist *sg;		/* Set only if DDP is setup */
118 	u32 sg_cnt;			/* No. of item in scatterlist */
119 };
120 
121 extern struct mutex ft_lport_lock;
122 extern struct fc4_prov ft_prov;
123 extern unsigned int ft_debug_logging;
124 
125 /*
126  * Fabric methods.
127  */
128 
129 /*
130  * Session ops.
131  */
132 void ft_sess_put(struct ft_sess *);
133 void ft_sess_close(struct se_session *);
134 u32 ft_sess_get_index(struct se_session *);
135 u32 ft_sess_get_port_name(struct se_session *, unsigned char *, u32);
136 
137 void ft_lport_add(struct fc_lport *, void *);
138 void ft_lport_del(struct fc_lport *, void *);
139 int ft_lport_notify(struct notifier_block *, unsigned long, void *);
140 
141 /*
142  * IO methods.
143  */
144 int ft_check_stop_free(struct se_cmd *);
145 void ft_release_cmd(struct se_cmd *);
146 int ft_queue_status(struct se_cmd *);
147 int ft_queue_data_in(struct se_cmd *);
148 int ft_write_pending(struct se_cmd *);
149 void ft_queue_tm_resp(struct se_cmd *);
150 void ft_aborted_task(struct se_cmd *);
151 
152 /*
153  * other internal functions.
154  */
155 void ft_recv_req(struct ft_sess *, struct fc_frame *);
156 struct ft_tpg *ft_lport_find_tpg(struct fc_lport *);
157 
158 void ft_recv_write_data(struct ft_cmd *, struct fc_frame *);
159 void ft_dump_cmd(struct ft_cmd *, const char *caller);
160 
161 ssize_t ft_format_wwn(char *, size_t, u64);
162 
163 /*
164  * Underlying HW specific helper function
165  */
166 void ft_invl_hw_context(struct ft_cmd *);
167 
168 #endif /* __TCM_FC_H__ */
169