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