blob: efdcb9663a1a699520d3543b544ebac5c34ad860 [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/target_core_configfs.h>
Kiran Patil3699d922011-04-18 16:24:14 -070047#include <target/configfs_macros.h>
48
49#include "tcm_fc.h"
50
51struct target_fabric_configfs *ft_configfs;
52
Andy Grover705665d2014-04-04 16:54:13 -070053static LIST_HEAD(ft_wwn_list);
Kiran Patil3699d922011-04-18 16:24:14 -070054DEFINE_MUTEX(ft_lport_lock);
55
56unsigned int ft_debug_logging;
57module_param_named(debug_logging, ft_debug_logging, int, S_IRUGO|S_IWUSR);
58MODULE_PARM_DESC(debug_logging, "a bit mask of logging levels");
59
60/*
61 * Parse WWN.
62 * If strict, we require lower-case hex and colon separators to be sure
63 * the name is the same as what would be generated by ft_format_wwn()
64 * so the name and wwn are mapped one-to-one.
65 */
66static ssize_t ft_parse_wwn(const char *name, u64 *wwn, int strict)
67{
68 const char *cp;
69 char c;
Kiran Patil3699d922011-04-18 16:24:14 -070070 u32 byte = 0;
71 u32 pos = 0;
72 u32 err;
Andy Shevchenko635a2b32011-09-30 14:45:40 +030073 int val;
Kiran Patil3699d922011-04-18 16:24:14 -070074
75 *wwn = 0;
76 for (cp = name; cp < &name[FT_NAMELEN - 1]; cp++) {
77 c = *cp;
78 if (c == '\n' && cp[1] == '\0')
79 continue;
80 if (strict && pos++ == 2 && byte++ < 7) {
81 pos = 0;
82 if (c == ':')
83 continue;
84 err = 1;
85 goto fail;
86 }
87 if (c == '\0') {
88 err = 2;
89 if (strict && byte != 8)
90 goto fail;
91 return cp - name;
92 }
93 err = 3;
Andy Shevchenko635a2b32011-09-30 14:45:40 +030094 val = hex_to_bin(c);
95 if (val < 0 || (strict && isupper(c)))
Kiran Patil3699d922011-04-18 16:24:14 -070096 goto fail;
Andy Shevchenko635a2b32011-09-30 14:45:40 +030097 *wwn = (*wwn << 4) | val;
Kiran Patil3699d922011-04-18 16:24:14 -070098 }
99 err = 4;
100fail:
Andy Grover6708bb22011-06-08 10:36:43 -0700101 pr_debug("err %u len %zu pos %u byte %u\n",
Kiran Patil3699d922011-04-18 16:24:14 -0700102 err, cp - name, pos, byte);
103 return -1;
104}
105
106ssize_t ft_format_wwn(char *buf, size_t len, u64 wwn)
107{
108 u8 b[8];
109
110 put_unaligned_be64(wwn, b);
111 return snprintf(buf, len,
112 "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x",
113 b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7]);
114}
115
116static ssize_t ft_wwn_show(void *arg, char *buf)
117{
118 u64 *wwn = arg;
119 ssize_t len;
120
121 len = ft_format_wwn(buf, PAGE_SIZE - 2, *wwn);
122 buf[len++] = '\n';
123 return len;
124}
125
126static ssize_t ft_wwn_store(void *arg, const char *buf, size_t len)
127{
128 ssize_t ret;
129 u64 wwn;
130
131 ret = ft_parse_wwn(buf, &wwn, 0);
132 if (ret > 0)
133 *(u64 *)arg = wwn;
134 return ret;
135}
136
137/*
138 * ACL auth ops.
139 */
140
141static ssize_t ft_nacl_show_port_name(
142 struct se_node_acl *se_nacl,
143 char *page)
144{
145 struct ft_node_acl *acl = container_of(se_nacl,
146 struct ft_node_acl, se_node_acl);
147
148 return ft_wwn_show(&acl->node_auth.port_name, page);
149}
150
151static ssize_t ft_nacl_store_port_name(
152 struct se_node_acl *se_nacl,
153 const char *page,
154 size_t count)
155{
156 struct ft_node_acl *acl = container_of(se_nacl,
157 struct ft_node_acl, se_node_acl);
158
159 return ft_wwn_store(&acl->node_auth.port_name, page, count);
160}
161
162TF_NACL_BASE_ATTR(ft, port_name, S_IRUGO | S_IWUSR);
163
164static ssize_t ft_nacl_show_node_name(
165 struct se_node_acl *se_nacl,
166 char *page)
167{
168 struct ft_node_acl *acl = container_of(se_nacl,
169 struct ft_node_acl, se_node_acl);
170
171 return ft_wwn_show(&acl->node_auth.node_name, page);
172}
173
174static ssize_t ft_nacl_store_node_name(
175 struct se_node_acl *se_nacl,
176 const char *page,
177 size_t count)
178{
179 struct ft_node_acl *acl = container_of(se_nacl,
180 struct ft_node_acl, se_node_acl);
181
182 return ft_wwn_store(&acl->node_auth.node_name, page, count);
183}
184
185TF_NACL_BASE_ATTR(ft, node_name, S_IRUGO | S_IWUSR);
186
187static struct configfs_attribute *ft_nacl_base_attrs[] = {
188 &ft_nacl_port_name.attr,
189 &ft_nacl_node_name.attr,
190 NULL,
191};
192
193/*
194 * ACL ops.
195 */
196
197/*
198 * Add ACL for an initiator. The ACL is named arbitrarily.
199 * The port_name and/or node_name are attributes.
200 */
201static struct se_node_acl *ft_add_acl(
202 struct se_portal_group *se_tpg,
203 struct config_group *group,
204 const char *name)
205{
206 struct ft_node_acl *acl;
207 struct ft_tpg *tpg;
208 u64 wwpn;
209 u32 q_depth;
210
Andy Grover6708bb22011-06-08 10:36:43 -0700211 pr_debug("add acl %s\n", name);
Kiran Patil3699d922011-04-18 16:24:14 -0700212 tpg = container_of(se_tpg, struct ft_tpg, se_tpg);
213
214 if (ft_parse_wwn(name, &wwpn, 1) < 0)
215 return ERR_PTR(-EINVAL);
216
217 acl = kzalloc(sizeof(struct ft_node_acl), GFP_KERNEL);
Nicholas Bellinger2be18142011-05-27 13:58:48 -0700218 if (!acl)
Kiran Patil3699d922011-04-18 16:24:14 -0700219 return ERR_PTR(-ENOMEM);
220 acl->node_auth.port_name = wwpn;
221
222 q_depth = 32; /* XXX bogus default - get from tpg? */
223 return core_tpg_add_initiator_node_acl(&tpg->se_tpg,
224 &acl->se_node_acl, name, q_depth);
225}
226
227static void ft_del_acl(struct se_node_acl *se_acl)
228{
229 struct se_portal_group *se_tpg = se_acl->se_tpg;
230 struct ft_tpg *tpg;
231 struct ft_node_acl *acl = container_of(se_acl,
232 struct ft_node_acl, se_node_acl);
233
Andy Grover6708bb22011-06-08 10:36:43 -0700234 pr_debug("del acl %s\n",
Kiran Patil3699d922011-04-18 16:24:14 -0700235 config_item_name(&se_acl->acl_group.cg_item));
236
237 tpg = container_of(se_tpg, struct ft_tpg, se_tpg);
Andy Grover6708bb22011-06-08 10:36:43 -0700238 pr_debug("del acl %p se_acl %p tpg %p se_tpg %p\n",
Kiran Patil3699d922011-04-18 16:24:14 -0700239 acl, se_acl, tpg, &tpg->se_tpg);
240
241 core_tpg_del_initiator_node_acl(&tpg->se_tpg, se_acl, 1);
242 kfree(acl);
243}
244
245struct ft_node_acl *ft_acl_get(struct ft_tpg *tpg, struct fc_rport_priv *rdata)
246{
247 struct ft_node_acl *found = NULL;
248 struct ft_node_acl *acl;
249 struct se_portal_group *se_tpg = &tpg->se_tpg;
250 struct se_node_acl *se_acl;
251
Roland Dreier28638882011-08-16 09:40:01 -0700252 spin_lock_irq(&se_tpg->acl_node_lock);
Kiran Patil3699d922011-04-18 16:24:14 -0700253 list_for_each_entry(se_acl, &se_tpg->acl_node_list, acl_list) {
254 acl = container_of(se_acl, struct ft_node_acl, se_node_acl);
Andy Grover6708bb22011-06-08 10:36:43 -0700255 pr_debug("acl %p port_name %llx\n",
Kiran Patil3699d922011-04-18 16:24:14 -0700256 acl, (unsigned long long)acl->node_auth.port_name);
257 if (acl->node_auth.port_name == rdata->ids.port_name ||
258 acl->node_auth.node_name == rdata->ids.node_name) {
Andy Grover6708bb22011-06-08 10:36:43 -0700259 pr_debug("acl %p port_name %llx matched\n", acl,
Kiran Patil3699d922011-04-18 16:24:14 -0700260 (unsigned long long)rdata->ids.port_name);
261 found = acl;
262 /* XXX need to hold onto ACL */
263 break;
264 }
265 }
Roland Dreier28638882011-08-16 09:40:01 -0700266 spin_unlock_irq(&se_tpg->acl_node_lock);
Kiran Patil3699d922011-04-18 16:24:14 -0700267 return found;
268}
269
Rashika Kheria594c42e2013-12-19 00:05:59 +0530270static struct se_node_acl *ft_tpg_alloc_fabric_acl(struct se_portal_group *se_tpg)
Kiran Patil3699d922011-04-18 16:24:14 -0700271{
272 struct ft_node_acl *acl;
273
274 acl = kzalloc(sizeof(*acl), GFP_KERNEL);
Nicholas Bellinger2be18142011-05-27 13:58:48 -0700275 if (!acl) {
Andy Grover6708bb22011-06-08 10:36:43 -0700276 pr_err("Unable to allocate struct ft_node_acl\n");
Kiran Patil3699d922011-04-18 16:24:14 -0700277 return NULL;
278 }
Andy Grover6708bb22011-06-08 10:36:43 -0700279 pr_debug("acl %p\n", acl);
Kiran Patil3699d922011-04-18 16:24:14 -0700280 return &acl->se_node_acl;
281}
282
283static void ft_tpg_release_fabric_acl(struct se_portal_group *se_tpg,
284 struct se_node_acl *se_acl)
285{
286 struct ft_node_acl *acl = container_of(se_acl,
287 struct ft_node_acl, se_node_acl);
288
Andy Grover6708bb22011-06-08 10:36:43 -0700289 pr_debug("acl %p\n", acl);
Kiran Patil3699d922011-04-18 16:24:14 -0700290 kfree(acl);
291}
292
293/*
294 * local_port port_group (tpg) ops.
295 */
296static struct se_portal_group *ft_add_tpg(
297 struct se_wwn *wwn,
298 struct config_group *group,
299 const char *name)
300{
Andy Grover705665d2014-04-04 16:54:13 -0700301 struct ft_lport_wwn *ft_wwn;
Kiran Patil3699d922011-04-18 16:24:14 -0700302 struct ft_tpg *tpg;
Mark Rustad06383f12012-04-03 10:24:52 -0700303 struct workqueue_struct *wq;
Kiran Patil3699d922011-04-18 16:24:14 -0700304 unsigned long index;
305 int ret;
306
Andy Grover6708bb22011-06-08 10:36:43 -0700307 pr_debug("tcm_fc: add tpg %s\n", name);
Kiran Patil3699d922011-04-18 16:24:14 -0700308
309 /*
310 * Name must be "tpgt_" followed by the index.
311 */
312 if (strstr(name, "tpgt_") != name)
313 return NULL;
Jingoo Han57103d72013-07-19 16:22:19 +0900314
315 ret = kstrtoul(name + 5, 10, &index);
316 if (ret)
317 return NULL;
318 if (index > UINT_MAX)
Kiran Patil3699d922011-04-18 16:24:14 -0700319 return NULL;
320
Andy Groverd242c1d2014-04-04 16:54:12 -0700321 if ((index != 1)) {
322 pr_err("Error, a single TPG=1 is used for HW port mappings\n");
323 return ERR_PTR(-ENOSYS);
324 }
325
Andy Grover705665d2014-04-04 16:54:13 -0700326 ft_wwn = container_of(wwn, struct ft_lport_wwn, se_wwn);
Kiran Patil3699d922011-04-18 16:24:14 -0700327 tpg = kzalloc(sizeof(*tpg), GFP_KERNEL);
328 if (!tpg)
329 return NULL;
330 tpg->index = index;
Andy Grover705665d2014-04-04 16:54:13 -0700331 tpg->lport_wwn = ft_wwn;
Kiran Patil3699d922011-04-18 16:24:14 -0700332 INIT_LIST_HEAD(&tpg->lun_list);
Kiran Patil3699d922011-04-18 16:24:14 -0700333
Mark Rustad06383f12012-04-03 10:24:52 -0700334 wq = alloc_workqueue("tcm_fc", 0, 1);
335 if (!wq) {
Kiran Patil3699d922011-04-18 16:24:14 -0700336 kfree(tpg);
337 return NULL;
338 }
339
Mark Rustad06383f12012-04-03 10:24:52 -0700340 ret = core_tpg_register(&ft_configfs->tf_ops, wwn, &tpg->se_tpg,
341 tpg, TRANSPORT_TPG_TYPE_NORMAL);
342 if (ret < 0) {
343 destroy_workqueue(wq);
Kiran Patil3699d922011-04-18 16:24:14 -0700344 kfree(tpg);
345 return NULL;
346 }
Mark Rustad06383f12012-04-03 10:24:52 -0700347 tpg->workqueue = wq;
Kiran Patil3699d922011-04-18 16:24:14 -0700348
349 mutex_lock(&ft_lport_lock);
Andy Grover705665d2014-04-04 16:54:13 -0700350 ft_wwn->tpg = tpg;
Kiran Patil3699d922011-04-18 16:24:14 -0700351 mutex_unlock(&ft_lport_lock);
352
353 return &tpg->se_tpg;
354}
355
356static void ft_del_tpg(struct se_portal_group *se_tpg)
357{
358 struct ft_tpg *tpg = container_of(se_tpg, struct ft_tpg, se_tpg);
Andy Grover705665d2014-04-04 16:54:13 -0700359 struct ft_lport_wwn *ft_wwn = tpg->lport_wwn;
Kiran Patil3699d922011-04-18 16:24:14 -0700360
Andy Grover6708bb22011-06-08 10:36:43 -0700361 pr_debug("del tpg %s\n",
Kiran Patil3699d922011-04-18 16:24:14 -0700362 config_item_name(&tpg->se_tpg.tpg_group.cg_item));
363
Christoph Hellwig58fc73d2011-08-26 09:25:38 -0700364 destroy_workqueue(tpg->workqueue);
Kiran Patil3699d922011-04-18 16:24:14 -0700365
366 /* Wait for sessions to be freed thru RCU, for BUG_ON below */
367 synchronize_rcu();
368
369 mutex_lock(&ft_lport_lock);
Andy Grover705665d2014-04-04 16:54:13 -0700370 ft_wwn->tpg = NULL;
Kiran Patil3699d922011-04-18 16:24:14 -0700371 if (tpg->tport) {
372 tpg->tport->tpg = NULL;
373 tpg->tport = NULL;
374 }
375 mutex_unlock(&ft_lport_lock);
376
377 core_tpg_deregister(se_tpg);
378 kfree(tpg);
379}
380
381/*
382 * Verify that an lport is configured to use the tcm_fc module, and return
383 * the target port group that should be used.
384 *
385 * The caller holds ft_lport_lock.
386 */
387struct ft_tpg *ft_lport_find_tpg(struct fc_lport *lport)
388{
Andy Grover705665d2014-04-04 16:54:13 -0700389 struct ft_lport_wwn *ft_wwn;
Kiran Patil3699d922011-04-18 16:24:14 -0700390
Andy Grover705665d2014-04-04 16:54:13 -0700391 list_for_each_entry(ft_wwn, &ft_wwn_list, ft_wwn_node) {
392 if (ft_wwn->wwpn == lport->wwpn)
393 return ft_wwn->tpg;
Kiran Patil3699d922011-04-18 16:24:14 -0700394 }
395 return NULL;
396}
397
398/*
399 * target config instance ops.
400 */
401
402/*
403 * Add lport to allowed config.
404 * The name is the WWPN in lower-case ASCII, colon-separated bytes.
405 */
Andy Grover0d7cb932014-04-04 16:54:14 -0700406static struct se_wwn *ft_add_wwn(
Kiran Patil3699d922011-04-18 16:24:14 -0700407 struct target_fabric_configfs *tf,
408 struct config_group *group,
409 const char *name)
410{
Andy Grover705665d2014-04-04 16:54:13 -0700411 struct ft_lport_wwn *ft_wwn;
412 struct ft_lport_wwn *old_ft_wwn;
Kiran Patil3699d922011-04-18 16:24:14 -0700413 u64 wwpn;
414
Andy Grover0d7cb932014-04-04 16:54:14 -0700415 pr_debug("add wwn %s\n", name);
Kiran Patil3699d922011-04-18 16:24:14 -0700416 if (ft_parse_wwn(name, &wwpn, 1) < 0)
417 return NULL;
Andy Grover705665d2014-04-04 16:54:13 -0700418 ft_wwn = kzalloc(sizeof(*ft_wwn), GFP_KERNEL);
419 if (!ft_wwn)
Kiran Patil3699d922011-04-18 16:24:14 -0700420 return NULL;
Andy Grover705665d2014-04-04 16:54:13 -0700421 ft_wwn->wwpn = wwpn;
Kiran Patil3699d922011-04-18 16:24:14 -0700422
423 mutex_lock(&ft_lport_lock);
Andy Grover705665d2014-04-04 16:54:13 -0700424 list_for_each_entry(old_ft_wwn, &ft_wwn_list, ft_wwn_node) {
425 if (old_ft_wwn->wwpn == wwpn) {
Kiran Patil3699d922011-04-18 16:24:14 -0700426 mutex_unlock(&ft_lport_lock);
Andy Grover705665d2014-04-04 16:54:13 -0700427 kfree(ft_wwn);
Kiran Patil3699d922011-04-18 16:24:14 -0700428 return NULL;
429 }
430 }
Andy Grover705665d2014-04-04 16:54:13 -0700431 list_add_tail(&ft_wwn->ft_wwn_node, &ft_wwn_list);
432 ft_format_wwn(ft_wwn->name, sizeof(ft_wwn->name), wwpn);
Kiran Patil3699d922011-04-18 16:24:14 -0700433 mutex_unlock(&ft_lport_lock);
434
Andy Grover705665d2014-04-04 16:54:13 -0700435 return &ft_wwn->se_wwn;
Kiran Patil3699d922011-04-18 16:24:14 -0700436}
437
Andy Grover0d7cb932014-04-04 16:54:14 -0700438static void ft_del_wwn(struct se_wwn *wwn)
Kiran Patil3699d922011-04-18 16:24:14 -0700439{
Andy Grover705665d2014-04-04 16:54:13 -0700440 struct ft_lport_wwn *ft_wwn = container_of(wwn,
441 struct ft_lport_wwn, se_wwn);
Kiran Patil3699d922011-04-18 16:24:14 -0700442
Andy Grover0d7cb932014-04-04 16:54:14 -0700443 pr_debug("del wwn %s\n", ft_wwn->name);
Kiran Patil3699d922011-04-18 16:24:14 -0700444 mutex_lock(&ft_lport_lock);
Andy Grover705665d2014-04-04 16:54:13 -0700445 list_del(&ft_wwn->ft_wwn_node);
Kiran Patil3699d922011-04-18 16:24:14 -0700446 mutex_unlock(&ft_lport_lock);
447
Andy Grover705665d2014-04-04 16:54:13 -0700448 kfree(ft_wwn);
Kiran Patil3699d922011-04-18 16:24:14 -0700449}
450
451static ssize_t ft_wwn_show_attr_version(
452 struct target_fabric_configfs *tf,
453 char *page)
454{
455 return sprintf(page, "TCM FC " FT_VERSION " on %s/%s on "
456 ""UTS_RELEASE"\n", utsname()->sysname, utsname()->machine);
457}
458
459TF_WWN_ATTR_RO(ft, version);
460
461static struct configfs_attribute *ft_wwn_attrs[] = {
462 &ft_wwn_version.attr,
463 NULL,
464};
465
466static char *ft_get_fabric_name(void)
467{
468 return "fc";
469}
470
471static char *ft_get_fabric_wwn(struct se_portal_group *se_tpg)
472{
473 struct ft_tpg *tpg = se_tpg->se_tpg_fabric_ptr;
474
Andy Grover705665d2014-04-04 16:54:13 -0700475 return tpg->lport_wwn->name;
Kiran Patil3699d922011-04-18 16:24:14 -0700476}
477
478static u16 ft_get_tag(struct se_portal_group *se_tpg)
479{
480 struct ft_tpg *tpg = se_tpg->se_tpg_fabric_ptr;
481
482 /*
483 * This tag is used when forming SCSI Name identifier in EVPD=1 0x83
484 * to represent the SCSI Target Port.
485 */
486 return tpg->index;
487}
488
489static u32 ft_get_default_depth(struct se_portal_group *se_tpg)
490{
491 return 1;
492}
493
494static int ft_check_false(struct se_portal_group *se_tpg)
495{
496 return 0;
497}
498
499static void ft_set_default_node_attr(struct se_node_acl *se_nacl)
500{
501}
502
Kiran Patil3699d922011-04-18 16:24:14 -0700503static u32 ft_tpg_get_inst_index(struct se_portal_group *se_tpg)
504{
505 struct ft_tpg *tpg = se_tpg->se_tpg_fabric_ptr;
506
507 return tpg->index;
508}
509
Kiran Patil3699d922011-04-18 16:24:14 -0700510static struct target_core_fabric_ops ft_fabric_ops = {
511 .get_fabric_name = ft_get_fabric_name,
512 .get_fabric_proto_ident = fc_get_fabric_proto_ident,
513 .tpg_get_wwn = ft_get_fabric_wwn,
514 .tpg_get_tag = ft_get_tag,
515 .tpg_get_default_depth = ft_get_default_depth,
516 .tpg_get_pr_transport_id = fc_get_pr_transport_id,
517 .tpg_get_pr_transport_id_len = fc_get_pr_transport_id_len,
518 .tpg_parse_pr_out_transport_id = fc_parse_pr_out_transport_id,
519 .tpg_check_demo_mode = ft_check_false,
520 .tpg_check_demo_mode_cache = ft_check_false,
521 .tpg_check_demo_mode_write_protect = ft_check_false,
522 .tpg_check_prod_mode_write_protect = ft_check_false,
523 .tpg_alloc_fabric_acl = ft_tpg_alloc_fabric_acl,
524 .tpg_release_fabric_acl = ft_tpg_release_fabric_acl,
525 .tpg_get_inst_index = ft_tpg_get_inst_index,
526 .check_stop_free = ft_check_stop_free,
Christoph Hellwig35462972011-05-31 23:56:57 -0400527 .release_cmd = ft_release_cmd,
Kiran Patil3699d922011-04-18 16:24:14 -0700528 .shutdown_session = ft_sess_shutdown,
529 .close_session = ft_sess_close,
Kiran Patil3699d922011-04-18 16:24:14 -0700530 .sess_get_index = ft_sess_get_index,
531 .sess_get_initiator_sid = NULL,
532 .write_pending = ft_write_pending,
533 .write_pending_status = ft_write_pending_status,
534 .set_default_node_attributes = ft_set_default_node_attr,
535 .get_task_tag = ft_get_task_tag,
536 .get_cmd_state = ft_get_cmd_state,
Kiran Patil3699d922011-04-18 16:24:14 -0700537 .queue_data_in = ft_queue_data_in,
538 .queue_status = ft_queue_status,
539 .queue_tm_rsp = ft_queue_tm_resp,
Nicholas Bellinger131e6ab2014-03-22 14:55:56 -0700540 .aborted_task = ft_aborted_task,
Kiran Patil3699d922011-04-18 16:24:14 -0700541 /*
542 * Setup function pointers for generic logic in
543 * target_core_fabric_configfs.c
544 */
Andy Grover0d7cb932014-04-04 16:54:14 -0700545 .fabric_make_wwn = &ft_add_wwn,
546 .fabric_drop_wwn = &ft_del_wwn,
Kiran Patil3699d922011-04-18 16:24:14 -0700547 .fabric_make_tpg = &ft_add_tpg,
548 .fabric_drop_tpg = &ft_del_tpg,
549 .fabric_post_link = NULL,
550 .fabric_pre_unlink = NULL,
551 .fabric_make_np = NULL,
552 .fabric_drop_np = NULL,
553 .fabric_make_nodeacl = &ft_add_acl,
554 .fabric_drop_nodeacl = &ft_del_acl,
555};
556
Rashika Kheria594c42e2013-12-19 00:05:59 +0530557static int ft_register_configfs(void)
Kiran Patil3699d922011-04-18 16:24:14 -0700558{
559 struct target_fabric_configfs *fabric;
560 int ret;
561
562 /*
563 * Register the top level struct config_item_type with TCM core
564 */
565 fabric = target_fabric_configfs_init(THIS_MODULE, "fc");
Andy Grovere3d6f902011-07-19 08:55:10 +0000566 if (IS_ERR(fabric)) {
Andy Grover6708bb22011-06-08 10:36:43 -0700567 pr_err("%s: target_fabric_configfs_init() failed!\n",
Kiran Patil3699d922011-04-18 16:24:14 -0700568 __func__);
Andy Grovere3d6f902011-07-19 08:55:10 +0000569 return PTR_ERR(fabric);
Kiran Patil3699d922011-04-18 16:24:14 -0700570 }
571 fabric->tf_ops = ft_fabric_ops;
572
Kiran Patil3699d922011-04-18 16:24:14 -0700573 /*
574 * Setup default attribute lists for various fabric->tf_cit_tmpl
575 */
Andy Groverd80e224d2013-10-09 11:05:56 -0700576 fabric->tf_cit_tmpl.tfc_wwn_cit.ct_attrs = ft_wwn_attrs;
577 fabric->tf_cit_tmpl.tfc_tpg_base_cit.ct_attrs = NULL;
578 fabric->tf_cit_tmpl.tfc_tpg_attrib_cit.ct_attrs = NULL;
579 fabric->tf_cit_tmpl.tfc_tpg_param_cit.ct_attrs = NULL;
580 fabric->tf_cit_tmpl.tfc_tpg_np_base_cit.ct_attrs = NULL;
581 fabric->tf_cit_tmpl.tfc_tpg_nacl_base_cit.ct_attrs =
Kiran Patil3699d922011-04-18 16:24:14 -0700582 ft_nacl_base_attrs;
Andy Groverd80e224d2013-10-09 11:05:56 -0700583 fabric->tf_cit_tmpl.tfc_tpg_nacl_attrib_cit.ct_attrs = NULL;
584 fabric->tf_cit_tmpl.tfc_tpg_nacl_auth_cit.ct_attrs = NULL;
585 fabric->tf_cit_tmpl.tfc_tpg_nacl_param_cit.ct_attrs = NULL;
Kiran Patil3699d922011-04-18 16:24:14 -0700586 /*
587 * register the fabric for use within TCM
588 */
589 ret = target_fabric_configfs_register(fabric);
590 if (ret < 0) {
Andy Grover6708bb22011-06-08 10:36:43 -0700591 pr_debug("target_fabric_configfs_register() for"
Kiran Patil3699d922011-04-18 16:24:14 -0700592 " FC Target failed!\n");
Kiran Patil3699d922011-04-18 16:24:14 -0700593 target_fabric_configfs_free(fabric);
594 return -1;
595 }
596
597 /*
598 * Setup our local pointer to *fabric.
599 */
600 ft_configfs = fabric;
601 return 0;
602}
603
Rashika Kheria594c42e2013-12-19 00:05:59 +0530604static void ft_deregister_configfs(void)
Kiran Patil3699d922011-04-18 16:24:14 -0700605{
606 if (!ft_configfs)
607 return;
608 target_fabric_configfs_deregister(ft_configfs);
609 ft_configfs = NULL;
610}
611
612static struct notifier_block ft_notifier = {
613 .notifier_call = ft_lport_notify
614};
615
616static int __init ft_init(void)
617{
618 if (ft_register_configfs())
619 return -1;
620 if (fc_fc4_register_provider(FC_TYPE_FCP, &ft_prov)) {
621 ft_deregister_configfs();
622 return -1;
623 }
624 blocking_notifier_chain_register(&fc_lport_notifier_head, &ft_notifier);
625 fc_lport_iterate(ft_lport_add, NULL);
626 return 0;
627}
628
629static void __exit ft_exit(void)
630{
631 blocking_notifier_chain_unregister(&fc_lport_notifier_head,
632 &ft_notifier);
633 fc_fc4_deregister_provider(FC_TYPE_FCP, &ft_prov);
634 fc_lport_iterate(ft_lport_del, NULL);
635 ft_deregister_configfs();
636 synchronize_rcu();
637}
638
Kiran Patil3699d922011-04-18 16:24:14 -0700639MODULE_DESCRIPTION("FC TCM fabric driver " FT_VERSION);
640MODULE_LICENSE("GPL");
641module_init(ft_init);
642module_exit(ft_exit);