blob: 80a4477fa7ee135a503345cc5f618dd66975931a [file] [log] [blame]
Kiran Patil3699d922011-04-18 16:24:14 -07001/*******************************************************************************
2 * Filename: tcm_fc.c
3 *
4 * This file contains the configfs implementation for TCM_fc fabric node.
5 * Based on tcm_loop_configfs.c
6 *
7 * Copyright (c) 2010 Cisco Systems, Inc.
8 * Copyright (c) 2009,2010 Rising Tide, Inc.
9 * Copyright (c) 2009,2010 Linux-iSCSI.org
10 *
11 * Copyright (c) 2009,2010 Nicholas A. Bellinger <nab@linux-iscsi.org>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 ****************************************************************************/
23
24#include <linux/module.h>
25#include <linux/moduleparam.h>
Kiran Patil3699d922011-04-18 16:24:14 -070026#include <generated/utsrelease.h>
27#include <linux/utsname.h>
28#include <linux/init.h>
29#include <linux/slab.h>
30#include <linux/kthread.h>
31#include <linux/types.h>
32#include <linux/string.h>
33#include <linux/configfs.h>
Andy Shevchenko635a2b32011-09-30 14:45:40 +030034#include <linux/kernel.h>
Kiran Patil3699d922011-04-18 16:24:14 -070035#include <linux/ctype.h>
36#include <asm/unaligned.h>
37#include <scsi/scsi.h>
38#include <scsi/scsi_host.h>
39#include <scsi/scsi_device.h>
40#include <scsi/scsi_cmnd.h>
41#include <scsi/libfc.h>
42
43#include <target/target_core_base.h>
Christoph Hellwigc4795fb2011-11-16 09:46:48 -050044#include <target/target_core_fabric.h>
Kiran Patil3699d922011-04-18 16:24:14 -070045#include <target/target_core_fabric_configfs.h>
Kiran Patil3699d922011-04-18 16:24:14 -070046#include <target/configfs_macros.h>
47
48#include "tcm_fc.h"
49
Andy Grover705665d2014-04-04 16:54:13 -070050static LIST_HEAD(ft_wwn_list);
Kiran Patil3699d922011-04-18 16:24:14 -070051DEFINE_MUTEX(ft_lport_lock);
52
53unsigned int ft_debug_logging;
54module_param_named(debug_logging, ft_debug_logging, int, S_IRUGO|S_IWUSR);
55MODULE_PARM_DESC(debug_logging, "a bit mask of logging levels");
56
57/*
58 * Parse WWN.
59 * If strict, we require lower-case hex and colon separators to be sure
60 * the name is the same as what would be generated by ft_format_wwn()
61 * so the name and wwn are mapped one-to-one.
62 */
63static ssize_t ft_parse_wwn(const char *name, u64 *wwn, int strict)
64{
65 const char *cp;
66 char c;
Kiran Patil3699d922011-04-18 16:24:14 -070067 u32 byte = 0;
68 u32 pos = 0;
69 u32 err;
Andy Shevchenko635a2b32011-09-30 14:45:40 +030070 int val;
Kiran Patil3699d922011-04-18 16:24:14 -070071
72 *wwn = 0;
73 for (cp = name; cp < &name[FT_NAMELEN - 1]; cp++) {
74 c = *cp;
75 if (c == '\n' && cp[1] == '\0')
76 continue;
77 if (strict && pos++ == 2 && byte++ < 7) {
78 pos = 0;
79 if (c == ':')
80 continue;
81 err = 1;
82 goto fail;
83 }
84 if (c == '\0') {
85 err = 2;
86 if (strict && byte != 8)
87 goto fail;
88 return cp - name;
89 }
90 err = 3;
Andy Shevchenko635a2b32011-09-30 14:45:40 +030091 val = hex_to_bin(c);
92 if (val < 0 || (strict && isupper(c)))
Kiran Patil3699d922011-04-18 16:24:14 -070093 goto fail;
Andy Shevchenko635a2b32011-09-30 14:45:40 +030094 *wwn = (*wwn << 4) | val;
Kiran Patil3699d922011-04-18 16:24:14 -070095 }
96 err = 4;
97fail:
Andy Grover6708bb22011-06-08 10:36:43 -070098 pr_debug("err %u len %zu pos %u byte %u\n",
Kiran Patil3699d922011-04-18 16:24:14 -070099 err, cp - name, pos, byte);
100 return -1;
101}
102
103ssize_t ft_format_wwn(char *buf, size_t len, u64 wwn)
104{
105 u8 b[8];
106
107 put_unaligned_be64(wwn, b);
108 return snprintf(buf, len,
109 "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x",
110 b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7]);
111}
112
113static ssize_t ft_wwn_show(void *arg, char *buf)
114{
115 u64 *wwn = arg;
116 ssize_t len;
117
118 len = ft_format_wwn(buf, PAGE_SIZE - 2, *wwn);
119 buf[len++] = '\n';
120 return len;
121}
122
123static ssize_t ft_wwn_store(void *arg, const char *buf, size_t len)
124{
125 ssize_t ret;
126 u64 wwn;
127
128 ret = ft_parse_wwn(buf, &wwn, 0);
129 if (ret > 0)
130 *(u64 *)arg = wwn;
131 return ret;
132}
133
134/*
135 * ACL auth ops.
136 */
137
138static ssize_t ft_nacl_show_port_name(
139 struct se_node_acl *se_nacl,
140 char *page)
141{
142 struct ft_node_acl *acl = container_of(se_nacl,
143 struct ft_node_acl, se_node_acl);
144
145 return ft_wwn_show(&acl->node_auth.port_name, page);
146}
147
148static ssize_t ft_nacl_store_port_name(
149 struct se_node_acl *se_nacl,
150 const char *page,
151 size_t count)
152{
153 struct ft_node_acl *acl = container_of(se_nacl,
154 struct ft_node_acl, se_node_acl);
155
156 return ft_wwn_store(&acl->node_auth.port_name, page, count);
157}
158
159TF_NACL_BASE_ATTR(ft, port_name, S_IRUGO | S_IWUSR);
160
161static ssize_t ft_nacl_show_node_name(
162 struct se_node_acl *se_nacl,
163 char *page)
164{
165 struct ft_node_acl *acl = container_of(se_nacl,
166 struct ft_node_acl, se_node_acl);
167
168 return ft_wwn_show(&acl->node_auth.node_name, page);
169}
170
171static ssize_t ft_nacl_store_node_name(
172 struct se_node_acl *se_nacl,
173 const char *page,
174 size_t count)
175{
176 struct ft_node_acl *acl = container_of(se_nacl,
177 struct ft_node_acl, se_node_acl);
178
179 return ft_wwn_store(&acl->node_auth.node_name, page, count);
180}
181
182TF_NACL_BASE_ATTR(ft, node_name, S_IRUGO | S_IWUSR);
183
184static struct configfs_attribute *ft_nacl_base_attrs[] = {
185 &ft_nacl_port_name.attr,
186 &ft_nacl_node_name.attr,
187 NULL,
188};
189
190/*
191 * ACL ops.
192 */
193
194/*
195 * Add ACL for an initiator. The ACL is named arbitrarily.
196 * The port_name and/or node_name are attributes.
197 */
Christoph Hellwigc7d6a802015-04-13 19:51:14 +0200198static int ft_init_nodeacl(struct se_node_acl *nacl, const char *name)
Kiran Patil3699d922011-04-18 16:24:14 -0700199{
Christoph Hellwigc7d6a802015-04-13 19:51:14 +0200200 struct ft_node_acl *acl =
201 container_of(nacl, struct ft_node_acl, se_node_acl);
Kiran Patil3699d922011-04-18 16:24:14 -0700202 u64 wwpn;
Kiran Patil3699d922011-04-18 16:24:14 -0700203
204 if (ft_parse_wwn(name, &wwpn, 1) < 0)
Christoph Hellwigc7d6a802015-04-13 19:51:14 +0200205 return -EINVAL;
Kiran Patil3699d922011-04-18 16:24:14 -0700206
Kiran Patil3699d922011-04-18 16:24:14 -0700207 acl->node_auth.port_name = wwpn;
Christoph Hellwigc7d6a802015-04-13 19:51:14 +0200208 return 0;
Kiran Patil3699d922011-04-18 16:24:14 -0700209}
210
211struct ft_node_acl *ft_acl_get(struct ft_tpg *tpg, struct fc_rport_priv *rdata)
212{
213 struct ft_node_acl *found = NULL;
214 struct ft_node_acl *acl;
215 struct se_portal_group *se_tpg = &tpg->se_tpg;
216 struct se_node_acl *se_acl;
217
Nicholas Bellinger403edd72015-03-08 22:33:47 +0000218 mutex_lock(&se_tpg->acl_node_mutex);
Kiran Patil3699d922011-04-18 16:24:14 -0700219 list_for_each_entry(se_acl, &se_tpg->acl_node_list, acl_list) {
220 acl = container_of(se_acl, struct ft_node_acl, se_node_acl);
Andy Grover6708bb22011-06-08 10:36:43 -0700221 pr_debug("acl %p port_name %llx\n",
Kiran Patil3699d922011-04-18 16:24:14 -0700222 acl, (unsigned long long)acl->node_auth.port_name);
223 if (acl->node_auth.port_name == rdata->ids.port_name ||
224 acl->node_auth.node_name == rdata->ids.node_name) {
Andy Grover6708bb22011-06-08 10:36:43 -0700225 pr_debug("acl %p port_name %llx matched\n", acl,
Kiran Patil3699d922011-04-18 16:24:14 -0700226 (unsigned long long)rdata->ids.port_name);
227 found = acl;
228 /* XXX need to hold onto ACL */
229 break;
230 }
231 }
Nicholas Bellinger403edd72015-03-08 22:33:47 +0000232 mutex_unlock(&se_tpg->acl_node_mutex);
Kiran Patil3699d922011-04-18 16:24:14 -0700233 return found;
234}
235
Kiran Patil3699d922011-04-18 16:24:14 -0700236/*
237 * local_port port_group (tpg) ops.
238 */
239static struct se_portal_group *ft_add_tpg(
240 struct se_wwn *wwn,
241 struct config_group *group,
242 const char *name)
243{
Andy Grover705665d2014-04-04 16:54:13 -0700244 struct ft_lport_wwn *ft_wwn;
Kiran Patil3699d922011-04-18 16:24:14 -0700245 struct ft_tpg *tpg;
Mark Rustad06383f12012-04-03 10:24:52 -0700246 struct workqueue_struct *wq;
Kiran Patil3699d922011-04-18 16:24:14 -0700247 unsigned long index;
248 int ret;
249
Andy Grover6708bb22011-06-08 10:36:43 -0700250 pr_debug("tcm_fc: add tpg %s\n", name);
Kiran Patil3699d922011-04-18 16:24:14 -0700251
252 /*
253 * Name must be "tpgt_" followed by the index.
254 */
255 if (strstr(name, "tpgt_") != name)
256 return NULL;
Jingoo Han57103d72013-07-19 16:22:19 +0900257
258 ret = kstrtoul(name + 5, 10, &index);
259 if (ret)
260 return NULL;
261 if (index > UINT_MAX)
Kiran Patil3699d922011-04-18 16:24:14 -0700262 return NULL;
263
Andy Groverd242c1d2014-04-04 16:54:12 -0700264 if ((index != 1)) {
265 pr_err("Error, a single TPG=1 is used for HW port mappings\n");
266 return ERR_PTR(-ENOSYS);
267 }
268
Andy Grover705665d2014-04-04 16:54:13 -0700269 ft_wwn = container_of(wwn, struct ft_lport_wwn, se_wwn);
Kiran Patil3699d922011-04-18 16:24:14 -0700270 tpg = kzalloc(sizeof(*tpg), GFP_KERNEL);
271 if (!tpg)
272 return NULL;
273 tpg->index = index;
Andy Grover705665d2014-04-04 16:54:13 -0700274 tpg->lport_wwn = ft_wwn;
Kiran Patil3699d922011-04-18 16:24:14 -0700275 INIT_LIST_HEAD(&tpg->lun_list);
Kiran Patil3699d922011-04-18 16:24:14 -0700276
Mark Rustad06383f12012-04-03 10:24:52 -0700277 wq = alloc_workqueue("tcm_fc", 0, 1);
278 if (!wq) {
Kiran Patil3699d922011-04-18 16:24:14 -0700279 kfree(tpg);
280 return NULL;
281 }
282
Nicholas Bellingerbc0c94b2015-05-20 21:48:03 -0700283 ret = core_tpg_register(wwn, &tpg->se_tpg, SCSI_PROTOCOL_FCP);
Mark Rustad06383f12012-04-03 10:24:52 -0700284 if (ret < 0) {
285 destroy_workqueue(wq);
Kiran Patil3699d922011-04-18 16:24:14 -0700286 kfree(tpg);
287 return NULL;
288 }
Mark Rustad06383f12012-04-03 10:24:52 -0700289 tpg->workqueue = wq;
Kiran Patil3699d922011-04-18 16:24:14 -0700290
291 mutex_lock(&ft_lport_lock);
Andy Grover705665d2014-04-04 16:54:13 -0700292 ft_wwn->tpg = tpg;
Kiran Patil3699d922011-04-18 16:24:14 -0700293 mutex_unlock(&ft_lport_lock);
294
295 return &tpg->se_tpg;
296}
297
298static void ft_del_tpg(struct se_portal_group *se_tpg)
299{
300 struct ft_tpg *tpg = container_of(se_tpg, struct ft_tpg, se_tpg);
Andy Grover705665d2014-04-04 16:54:13 -0700301 struct ft_lport_wwn *ft_wwn = tpg->lport_wwn;
Kiran Patil3699d922011-04-18 16:24:14 -0700302
Andy Grover6708bb22011-06-08 10:36:43 -0700303 pr_debug("del tpg %s\n",
Kiran Patil3699d922011-04-18 16:24:14 -0700304 config_item_name(&tpg->se_tpg.tpg_group.cg_item));
305
Christoph Hellwig58fc73d2011-08-26 09:25:38 -0700306 destroy_workqueue(tpg->workqueue);
Kiran Patil3699d922011-04-18 16:24:14 -0700307
308 /* Wait for sessions to be freed thru RCU, for BUG_ON below */
309 synchronize_rcu();
310
311 mutex_lock(&ft_lport_lock);
Andy Grover705665d2014-04-04 16:54:13 -0700312 ft_wwn->tpg = NULL;
Kiran Patil3699d922011-04-18 16:24:14 -0700313 if (tpg->tport) {
314 tpg->tport->tpg = NULL;
315 tpg->tport = NULL;
316 }
317 mutex_unlock(&ft_lport_lock);
318
319 core_tpg_deregister(se_tpg);
320 kfree(tpg);
321}
322
323/*
324 * Verify that an lport is configured to use the tcm_fc module, and return
325 * the target port group that should be used.
326 *
327 * The caller holds ft_lport_lock.
328 */
329struct ft_tpg *ft_lport_find_tpg(struct fc_lport *lport)
330{
Andy Grover705665d2014-04-04 16:54:13 -0700331 struct ft_lport_wwn *ft_wwn;
Kiran Patil3699d922011-04-18 16:24:14 -0700332
Andy Grover705665d2014-04-04 16:54:13 -0700333 list_for_each_entry(ft_wwn, &ft_wwn_list, ft_wwn_node) {
334 if (ft_wwn->wwpn == lport->wwpn)
335 return ft_wwn->tpg;
Kiran Patil3699d922011-04-18 16:24:14 -0700336 }
337 return NULL;
338}
339
340/*
341 * target config instance ops.
342 */
343
344/*
345 * Add lport to allowed config.
346 * The name is the WWPN in lower-case ASCII, colon-separated bytes.
347 */
Andy Grover0d7cb932014-04-04 16:54:14 -0700348static struct se_wwn *ft_add_wwn(
Kiran Patil3699d922011-04-18 16:24:14 -0700349 struct target_fabric_configfs *tf,
350 struct config_group *group,
351 const char *name)
352{
Andy Grover705665d2014-04-04 16:54:13 -0700353 struct ft_lport_wwn *ft_wwn;
354 struct ft_lport_wwn *old_ft_wwn;
Kiran Patil3699d922011-04-18 16:24:14 -0700355 u64 wwpn;
356
Andy Grover0d7cb932014-04-04 16:54:14 -0700357 pr_debug("add wwn %s\n", name);
Kiran Patil3699d922011-04-18 16:24:14 -0700358 if (ft_parse_wwn(name, &wwpn, 1) < 0)
359 return NULL;
Andy Grover705665d2014-04-04 16:54:13 -0700360 ft_wwn = kzalloc(sizeof(*ft_wwn), GFP_KERNEL);
361 if (!ft_wwn)
Kiran Patil3699d922011-04-18 16:24:14 -0700362 return NULL;
Andy Grover705665d2014-04-04 16:54:13 -0700363 ft_wwn->wwpn = wwpn;
Kiran Patil3699d922011-04-18 16:24:14 -0700364
365 mutex_lock(&ft_lport_lock);
Andy Grover705665d2014-04-04 16:54:13 -0700366 list_for_each_entry(old_ft_wwn, &ft_wwn_list, ft_wwn_node) {
367 if (old_ft_wwn->wwpn == wwpn) {
Kiran Patil3699d922011-04-18 16:24:14 -0700368 mutex_unlock(&ft_lport_lock);
Andy Grover705665d2014-04-04 16:54:13 -0700369 kfree(ft_wwn);
Kiran Patil3699d922011-04-18 16:24:14 -0700370 return NULL;
371 }
372 }
Andy Grover705665d2014-04-04 16:54:13 -0700373 list_add_tail(&ft_wwn->ft_wwn_node, &ft_wwn_list);
374 ft_format_wwn(ft_wwn->name, sizeof(ft_wwn->name), wwpn);
Kiran Patil3699d922011-04-18 16:24:14 -0700375 mutex_unlock(&ft_lport_lock);
376
Andy Grover705665d2014-04-04 16:54:13 -0700377 return &ft_wwn->se_wwn;
Kiran Patil3699d922011-04-18 16:24:14 -0700378}
379
Andy Grover0d7cb932014-04-04 16:54:14 -0700380static void ft_del_wwn(struct se_wwn *wwn)
Kiran Patil3699d922011-04-18 16:24:14 -0700381{
Andy Grover705665d2014-04-04 16:54:13 -0700382 struct ft_lport_wwn *ft_wwn = container_of(wwn,
383 struct ft_lport_wwn, se_wwn);
Kiran Patil3699d922011-04-18 16:24:14 -0700384
Andy Grover0d7cb932014-04-04 16:54:14 -0700385 pr_debug("del wwn %s\n", ft_wwn->name);
Kiran Patil3699d922011-04-18 16:24:14 -0700386 mutex_lock(&ft_lport_lock);
Andy Grover705665d2014-04-04 16:54:13 -0700387 list_del(&ft_wwn->ft_wwn_node);
Kiran Patil3699d922011-04-18 16:24:14 -0700388 mutex_unlock(&ft_lport_lock);
389
Andy Grover705665d2014-04-04 16:54:13 -0700390 kfree(ft_wwn);
Kiran Patil3699d922011-04-18 16:24:14 -0700391}
392
393static ssize_t ft_wwn_show_attr_version(
394 struct target_fabric_configfs *tf,
395 char *page)
396{
397 return sprintf(page, "TCM FC " FT_VERSION " on %s/%s on "
398 ""UTS_RELEASE"\n", utsname()->sysname, utsname()->machine);
399}
400
401TF_WWN_ATTR_RO(ft, version);
402
403static struct configfs_attribute *ft_wwn_attrs[] = {
404 &ft_wwn_version.attr,
405 NULL,
406};
407
Christoph Hellwig3868e432015-05-01 17:47:55 +0200408static inline struct ft_tpg *ft_tpg(struct se_portal_group *se_tpg)
409{
410 return container_of(se_tpg, struct ft_tpg, se_tpg);
411}
412
Kiran Patil3699d922011-04-18 16:24:14 -0700413static char *ft_get_fabric_name(void)
414{
415 return "fc";
416}
417
418static char *ft_get_fabric_wwn(struct se_portal_group *se_tpg)
419{
Christoph Hellwig3868e432015-05-01 17:47:55 +0200420 return ft_tpg(se_tpg)->lport_wwn->name;
Kiran Patil3699d922011-04-18 16:24:14 -0700421}
422
423static u16 ft_get_tag(struct se_portal_group *se_tpg)
424{
Kiran Patil3699d922011-04-18 16:24:14 -0700425 /*
426 * This tag is used when forming SCSI Name identifier in EVPD=1 0x83
427 * to represent the SCSI Target Port.
428 */
Christoph Hellwig3868e432015-05-01 17:47:55 +0200429 return ft_tpg(se_tpg)->index;
Kiran Patil3699d922011-04-18 16:24:14 -0700430}
431
Kiran Patil3699d922011-04-18 16:24:14 -0700432static int ft_check_false(struct se_portal_group *se_tpg)
433{
434 return 0;
435}
436
437static void ft_set_default_node_attr(struct se_node_acl *se_nacl)
438{
439}
440
Kiran Patil3699d922011-04-18 16:24:14 -0700441static u32 ft_tpg_get_inst_index(struct se_portal_group *se_tpg)
442{
Christoph Hellwig3868e432015-05-01 17:47:55 +0200443 return ft_tpg(se_tpg)->index;
Kiran Patil3699d922011-04-18 16:24:14 -0700444}
445
Christoph Hellwig9ac89282015-04-08 20:01:35 +0200446static const struct target_core_fabric_ops ft_fabric_ops = {
447 .module = THIS_MODULE,
448 .name = "fc",
Christoph Hellwig144bc4c2015-04-13 19:51:16 +0200449 .node_acl_size = sizeof(struct ft_node_acl),
Kiran Patil3699d922011-04-18 16:24:14 -0700450 .get_fabric_name = ft_get_fabric_name,
Kiran Patil3699d922011-04-18 16:24:14 -0700451 .tpg_get_wwn = ft_get_fabric_wwn,
452 .tpg_get_tag = ft_get_tag,
Kiran Patil3699d922011-04-18 16:24:14 -0700453 .tpg_check_demo_mode = ft_check_false,
454 .tpg_check_demo_mode_cache = ft_check_false,
455 .tpg_check_demo_mode_write_protect = ft_check_false,
456 .tpg_check_prod_mode_write_protect = ft_check_false,
Kiran Patil3699d922011-04-18 16:24:14 -0700457 .tpg_get_inst_index = ft_tpg_get_inst_index,
458 .check_stop_free = ft_check_stop_free,
Christoph Hellwig35462972011-05-31 23:56:57 -0400459 .release_cmd = ft_release_cmd,
Kiran Patil3699d922011-04-18 16:24:14 -0700460 .shutdown_session = ft_sess_shutdown,
461 .close_session = ft_sess_close,
Kiran Patil3699d922011-04-18 16:24:14 -0700462 .sess_get_index = ft_sess_get_index,
463 .sess_get_initiator_sid = NULL,
464 .write_pending = ft_write_pending,
465 .write_pending_status = ft_write_pending_status,
466 .set_default_node_attributes = ft_set_default_node_attr,
Kiran Patil3699d922011-04-18 16:24:14 -0700467 .get_cmd_state = ft_get_cmd_state,
Kiran Patil3699d922011-04-18 16:24:14 -0700468 .queue_data_in = ft_queue_data_in,
469 .queue_status = ft_queue_status,
470 .queue_tm_rsp = ft_queue_tm_resp,
Nicholas Bellinger131e6ab2014-03-22 14:55:56 -0700471 .aborted_task = ft_aborted_task,
Kiran Patil3699d922011-04-18 16:24:14 -0700472 /*
473 * Setup function pointers for generic logic in
474 * target_core_fabric_configfs.c
475 */
Andy Grover0d7cb932014-04-04 16:54:14 -0700476 .fabric_make_wwn = &ft_add_wwn,
477 .fabric_drop_wwn = &ft_del_wwn,
Kiran Patil3699d922011-04-18 16:24:14 -0700478 .fabric_make_tpg = &ft_add_tpg,
479 .fabric_drop_tpg = &ft_del_tpg,
Christoph Hellwigc7d6a802015-04-13 19:51:14 +0200480 .fabric_init_nodeacl = &ft_init_nodeacl,
Christoph Hellwig9ac89282015-04-08 20:01:35 +0200481
482 .tfc_wwn_attrs = ft_wwn_attrs,
483 .tfc_tpg_nacl_base_attrs = ft_nacl_base_attrs,
Kiran Patil3699d922011-04-18 16:24:14 -0700484};
485
Kiran Patil3699d922011-04-18 16:24:14 -0700486static struct notifier_block ft_notifier = {
487 .notifier_call = ft_lport_notify
488};
489
490static int __init ft_init(void)
491{
Christoph Hellwig9ac89282015-04-08 20:01:35 +0200492 int ret;
493
494 ret = target_register_template(&ft_fabric_ops);
495 if (ret)
496 goto out;
497
498 ret = fc_fc4_register_provider(FC_TYPE_FCP, &ft_prov);
499 if (ret)
500 goto out_unregister_template;
501
Kiran Patil3699d922011-04-18 16:24:14 -0700502 blocking_notifier_chain_register(&fc_lport_notifier_head, &ft_notifier);
503 fc_lport_iterate(ft_lport_add, NULL);
504 return 0;
Christoph Hellwig9ac89282015-04-08 20:01:35 +0200505
506out_unregister_template:
507 target_unregister_template(&ft_fabric_ops);
508out:
509 return ret;
Kiran Patil3699d922011-04-18 16:24:14 -0700510}
511
512static void __exit ft_exit(void)
513{
514 blocking_notifier_chain_unregister(&fc_lport_notifier_head,
515 &ft_notifier);
516 fc_fc4_deregister_provider(FC_TYPE_FCP, &ft_prov);
517 fc_lport_iterate(ft_lport_del, NULL);
Christoph Hellwig9ac89282015-04-08 20:01:35 +0200518 target_unregister_template(&ft_fabric_ops);
Kiran Patil3699d922011-04-18 16:24:14 -0700519 synchronize_rcu();
520}
521
Kiran Patil3699d922011-04-18 16:24:14 -0700522MODULE_DESCRIPTION("FC TCM fabric driver " FT_VERSION);
523MODULE_LICENSE("GPL");
524module_init(ft_init);
525module_exit(ft_exit);