]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/scsi/qla2xxx/tcm_qla2xxx.c
target: make the tpg_get_default_depth method optional
[mirror_ubuntu-artful-kernel.git] / drivers / scsi / qla2xxx / tcm_qla2xxx.c
CommitLineData
75f8c1f6
NB
1/*******************************************************************************
2 * This file contains tcm implementation using v4 configfs fabric infrastructure
3 * for QLogic target mode HBAs
4 *
4c76251e 5 * (c) Copyright 2010-2013 Datera, Inc.
75f8c1f6 6 *
4c76251e 7 * Author: Nicholas A. Bellinger <nab@daterainc.com>
75f8c1f6
NB
8 *
9 * tcm_qla2xxx_parse_wwn() and tcm_qla2xxx_format_wwn() contains code from
10 * the TCM_FC / Open-FCoE.org fabric module.
11 *
12 * Copyright (c) 2010 Cisco Systems, Inc
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 ****************************************************************************/
24
25
26#include <linux/module.h>
27#include <linux/moduleparam.h>
28#include <generated/utsrelease.h>
29#include <linux/utsname.h>
30#include <linux/init.h>
31#include <linux/list.h>
32#include <linux/slab.h>
33#include <linux/kthread.h>
34#include <linux/types.h>
35#include <linux/string.h>
36#include <linux/configfs.h>
37#include <linux/ctype.h>
75f8c1f6
NB
38#include <asm/unaligned.h>
39#include <scsi/scsi.h>
40#include <scsi/scsi_host.h>
41#include <scsi/scsi_device.h>
42#include <scsi/scsi_cmnd.h>
43#include <target/target_core_base.h>
44#include <target/target_core_fabric.h>
45#include <target/target_core_fabric_configfs.h>
46#include <target/target_core_configfs.h>
47#include <target/configfs_macros.h>
48
49#include "qla_def.h"
50#include "qla_target.h"
51#include "tcm_qla2xxx.h"
52
4d6609c4
HM
53static struct workqueue_struct *tcm_qla2xxx_free_wq;
54static struct workqueue_struct *tcm_qla2xxx_cmd_wq;
55
9ac8928e
CH
56static const struct target_core_fabric_ops tcm_qla2xxx_ops;
57static const struct target_core_fabric_ops tcm_qla2xxx_npiv_ops;
75f8c1f6 58
75f8c1f6
NB
59/*
60 * Parse WWN.
61 * If strict, we require lower-case hex and colon separators to be sure
62 * the name is the same as what would be generated by ft_format_wwn()
63 * so the name and wwn are mapped one-to-one.
64 */
65static ssize_t tcm_qla2xxx_parse_wwn(const char *name, u64 *wwn, int strict)
66{
67 const char *cp;
68 char c;
69 u32 nibble;
70 u32 byte = 0;
71 u32 pos = 0;
72 u32 err;
73
74 *wwn = 0;
75 for (cp = name; cp < &name[TCM_QLA2XXX_NAMELEN - 1]; cp++) {
76 c = *cp;
77 if (c == '\n' && cp[1] == '\0')
78 continue;
79 if (strict && pos++ == 2 && byte++ < 7) {
80 pos = 0;
81 if (c == ':')
82 continue;
83 err = 1;
84 goto fail;
85 }
86 if (c == '\0') {
87 err = 2;
88 if (strict && byte != 8)
89 goto fail;
90 return cp - name;
91 }
92 err = 3;
93 if (isdigit(c))
94 nibble = c - '0';
95 else if (isxdigit(c) && (islower(c) || !strict))
96 nibble = tolower(c) - 'a' + 10;
97 else
98 goto fail;
99 *wwn = (*wwn << 4) | nibble;
100 }
101 err = 4;
102fail:
103 pr_debug("err %u len %zu pos %u byte %u\n",
104 err, cp - name, pos, byte);
105 return -1;
106}
107
108static ssize_t tcm_qla2xxx_format_wwn(char *buf, size_t len, u64 wwn)
109{
110 u8 b[8];
111
112 put_unaligned_be64(wwn, b);
113 return snprintf(buf, len,
114 "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x",
115 b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7]);
116}
117
118static char *tcm_qla2xxx_get_fabric_name(void)
119{
120 return "qla2xxx";
121}
122
123/*
124 * From drivers/scsi/scsi_transport_fc.c:fc_parse_wwn
125 */
126static int tcm_qla2xxx_npiv_extract_wwn(const char *ns, u64 *nm)
127{
d4f75b56 128 unsigned int i, j;
75f8c1f6
NB
129 u8 wwn[8];
130
131 memset(wwn, 0, sizeof(wwn));
132
133 /* Validate and store the new name */
134 for (i = 0, j = 0; i < 16; i++) {
d4f75b56
RD
135 int value;
136
75f8c1f6
NB
137 value = hex_to_bin(*ns++);
138 if (value >= 0)
139 j = (j << 4) | value;
140 else
141 return -EINVAL;
142
143 if (i % 2) {
144 wwn[i/2] = j & 0xff;
145 j = 0;
146 }
147 }
148
149 *nm = wwn_to_u64(wwn);
150 return 0;
151}
152
153/*
154 * This parsing logic follows drivers/scsi/scsi_transport_fc.c:
155 * store_fc_host_vport_create()
156 */
157static int tcm_qla2xxx_npiv_parse_wwn(
158 const char *name,
159 size_t count,
160 u64 *wwpn,
161 u64 *wwnn)
162{
163 unsigned int cnt = count;
164 int rc;
165
166 *wwpn = 0;
167 *wwnn = 0;
168
169 /* count may include a LF at end of string */
0e8cd71c 170 if (name[cnt-1] == '\n' || name[cnt-1] == 0)
75f8c1f6
NB
171 cnt--;
172
173 /* validate we have enough characters for WWPN */
174 if ((cnt != (16+1+16)) || (name[16] != ':'))
175 return -EINVAL;
176
177 rc = tcm_qla2xxx_npiv_extract_wwn(&name[0], wwpn);
178 if (rc != 0)
179 return rc;
180
181 rc = tcm_qla2xxx_npiv_extract_wwn(&name[17], wwnn);
182 if (rc != 0)
183 return rc;
184
185 return 0;
186}
187
75f8c1f6
NB
188static char *tcm_qla2xxx_npiv_get_fabric_name(void)
189{
190 return "qla2xxx_npiv";
191}
192
193static u8 tcm_qla2xxx_get_fabric_proto_ident(struct se_portal_group *se_tpg)
194{
195 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
196 struct tcm_qla2xxx_tpg, se_tpg);
197 struct tcm_qla2xxx_lport *lport = tpg->lport;
198 u8 proto_id;
199
200 switch (lport->lport_proto_id) {
201 case SCSI_PROTOCOL_FCP:
202 default:
203 proto_id = fc_get_fabric_proto_ident(se_tpg);
204 break;
205 }
206
207 return proto_id;
208}
209
210static char *tcm_qla2xxx_get_fabric_wwn(struct se_portal_group *se_tpg)
211{
212 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
213 struct tcm_qla2xxx_tpg, se_tpg);
214 struct tcm_qla2xxx_lport *lport = tpg->lport;
215
c046aa0f 216 return lport->lport_naa_name;
75f8c1f6
NB
217}
218
75f8c1f6
NB
219static u16 tcm_qla2xxx_get_tag(struct se_portal_group *se_tpg)
220{
221 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
222 struct tcm_qla2xxx_tpg, se_tpg);
223 return tpg->lport_tpgt;
224}
225
75f8c1f6
NB
226static u32 tcm_qla2xxx_get_pr_transport_id(
227 struct se_portal_group *se_tpg,
228 struct se_node_acl *se_nacl,
229 struct t10_pr_registration *pr_reg,
230 int *format_code,
231 unsigned char *buf)
232{
233 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
234 struct tcm_qla2xxx_tpg, se_tpg);
235 struct tcm_qla2xxx_lport *lport = tpg->lport;
236 int ret = 0;
237
238 switch (lport->lport_proto_id) {
239 case SCSI_PROTOCOL_FCP:
240 default:
241 ret = fc_get_pr_transport_id(se_tpg, se_nacl, pr_reg,
242 format_code, buf);
243 break;
244 }
245
246 return ret;
247}
248
249static u32 tcm_qla2xxx_get_pr_transport_id_len(
250 struct se_portal_group *se_tpg,
251 struct se_node_acl *se_nacl,
252 struct t10_pr_registration *pr_reg,
253 int *format_code)
254{
255 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
256 struct tcm_qla2xxx_tpg, se_tpg);
257 struct tcm_qla2xxx_lport *lport = tpg->lport;
258 int ret = 0;
259
260 switch (lport->lport_proto_id) {
261 case SCSI_PROTOCOL_FCP:
262 default:
263 ret = fc_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,
264 format_code);
265 break;
266 }
267
268 return ret;
269}
270
271static char *tcm_qla2xxx_parse_pr_out_transport_id(
272 struct se_portal_group *se_tpg,
273 const char *buf,
274 u32 *out_tid_len,
275 char **port_nexus_ptr)
276{
277 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
278 struct tcm_qla2xxx_tpg, se_tpg);
279 struct tcm_qla2xxx_lport *lport = tpg->lport;
280 char *tid = NULL;
281
282 switch (lport->lport_proto_id) {
283 case SCSI_PROTOCOL_FCP:
284 default:
285 tid = fc_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,
286 port_nexus_ptr);
287 break;
288 }
289
290 return tid;
291}
292
293static int tcm_qla2xxx_check_demo_mode(struct se_portal_group *se_tpg)
294{
295 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
296 struct tcm_qla2xxx_tpg, se_tpg);
297
a309f489 298 return tpg->tpg_attrib.generate_node_acls;
75f8c1f6
NB
299}
300
301static int tcm_qla2xxx_check_demo_mode_cache(struct se_portal_group *se_tpg)
302{
303 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
304 struct tcm_qla2xxx_tpg, se_tpg);
305
a309f489 306 return tpg->tpg_attrib.cache_dynamic_acls;
75f8c1f6
NB
307}
308
309static int tcm_qla2xxx_check_demo_write_protect(struct se_portal_group *se_tpg)
310{
311 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
312 struct tcm_qla2xxx_tpg, se_tpg);
313
a309f489 314 return tpg->tpg_attrib.demo_mode_write_protect;
75f8c1f6
NB
315}
316
317static int tcm_qla2xxx_check_prod_write_protect(struct se_portal_group *se_tpg)
318{
319 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
320 struct tcm_qla2xxx_tpg, se_tpg);
321
a309f489 322 return tpg->tpg_attrib.prod_mode_write_protect;
75f8c1f6
NB
323}
324
de04a8aa
AG
325static int tcm_qla2xxx_check_demo_mode_login_only(struct se_portal_group *se_tpg)
326{
327 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
328 struct tcm_qla2xxx_tpg, se_tpg);
329
a309f489 330 return tpg->tpg_attrib.demo_mode_login_only;
de04a8aa
AG
331}
332
64b16887
NB
333static int tcm_qla2xxx_check_prot_fabric_only(struct se_portal_group *se_tpg)
334{
335 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
336 struct tcm_qla2xxx_tpg, se_tpg);
337
338 return tpg->tpg_attrib.fabric_prot_type;
339}
340
75f8c1f6
NB
341static struct se_node_acl *tcm_qla2xxx_alloc_fabric_acl(
342 struct se_portal_group *se_tpg)
343{
344 struct tcm_qla2xxx_nacl *nacl;
345
346 nacl = kzalloc(sizeof(struct tcm_qla2xxx_nacl), GFP_KERNEL);
347 if (!nacl) {
6efb3c0a 348 pr_err("Unable to allocate struct tcm_qla2xxx_nacl\n");
75f8c1f6
NB
349 return NULL;
350 }
351
352 return &nacl->se_node_acl;
353}
354
355static void tcm_qla2xxx_release_fabric_acl(
356 struct se_portal_group *se_tpg,
357 struct se_node_acl *se_nacl)
358{
359 struct tcm_qla2xxx_nacl *nacl = container_of(se_nacl,
360 struct tcm_qla2xxx_nacl, se_node_acl);
361 kfree(nacl);
362}
363
364static u32 tcm_qla2xxx_tpg_get_inst_index(struct se_portal_group *se_tpg)
365{
366 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
367 struct tcm_qla2xxx_tpg, se_tpg);
368
369 return tpg->lport_tpgt;
370}
371
372static void tcm_qla2xxx_complete_mcmd(struct work_struct *work)
373{
374 struct qla_tgt_mgmt_cmd *mcmd = container_of(work,
375 struct qla_tgt_mgmt_cmd, free_work);
376
377 transport_generic_free_cmd(&mcmd->se_cmd, 0);
378}
379
380/*
381 * Called from qla_target_template->free_mcmd(), and will call
382 * tcm_qla2xxx_release_cmd() via normal struct target_core_fabric_ops
383 * release callback. qla_hw_data->hardware_lock is expected to be held
384 */
385static void tcm_qla2xxx_free_mcmd(struct qla_tgt_mgmt_cmd *mcmd)
386{
387 INIT_WORK(&mcmd->free_work, tcm_qla2xxx_complete_mcmd);
388 queue_work(tcm_qla2xxx_free_wq, &mcmd->free_work);
389}
390
391static void tcm_qla2xxx_complete_free(struct work_struct *work)
392{
393 struct qla_tgt_cmd *cmd = container_of(work, struct qla_tgt_cmd, work);
394
e07f8f65
SK
395 cmd->cmd_in_wq = 0;
396
397 WARN_ON(cmd->cmd_flags & BIT_16);
398
399 cmd->cmd_flags |= BIT_16;
75f8c1f6
NB
400 transport_generic_free_cmd(&cmd->se_cmd, 0);
401}
402
403/*
404 * Called from qla_target_template->free_cmd(), and will call
405 * tcm_qla2xxx_release_cmd via normal struct target_core_fabric_ops
406 * release callback. qla_hw_data->hardware_lock is expected to be held
407 */
408static void tcm_qla2xxx_free_cmd(struct qla_tgt_cmd *cmd)
409{
e07f8f65 410 cmd->cmd_in_wq = 1;
75f8c1f6
NB
411 INIT_WORK(&cmd->work, tcm_qla2xxx_complete_free);
412 queue_work(tcm_qla2xxx_free_wq, &cmd->work);
413}
414
415/*
416 * Called from struct target_core_fabric_ops->check_stop_free() context
417 */
418static int tcm_qla2xxx_check_stop_free(struct se_cmd *se_cmd)
419{
e07f8f65
SK
420 struct qla_tgt_cmd *cmd;
421
422 if ((se_cmd->se_cmd_flags & SCF_SCSI_TMR_CDB) == 0) {
423 cmd = container_of(se_cmd, struct qla_tgt_cmd, se_cmd);
424 cmd->cmd_flags |= BIT_14;
425 }
426
afc16604 427 return target_put_sess_cmd(se_cmd);
75f8c1f6
NB
428}
429
430/* tcm_qla2xxx_release_cmd - Callback from TCM Core to release underlying
431 * fabric descriptor @se_cmd command to release
432 */
433static void tcm_qla2xxx_release_cmd(struct se_cmd *se_cmd)
434{
435 struct qla_tgt_cmd *cmd;
436
437 if (se_cmd->se_cmd_flags & SCF_SCSI_TMR_CDB) {
438 struct qla_tgt_mgmt_cmd *mcmd = container_of(se_cmd,
439 struct qla_tgt_mgmt_cmd, se_cmd);
440 qlt_free_mcmd(mcmd);
441 return;
442 }
443
444 cmd = container_of(se_cmd, struct qla_tgt_cmd, se_cmd);
445 qlt_free_cmd(cmd);
446}
447
448static int tcm_qla2xxx_shutdown_session(struct se_session *se_sess)
449{
450 struct qla_tgt_sess *sess = se_sess->fabric_sess_ptr;
451 struct scsi_qla_host *vha;
452 unsigned long flags;
453
454 BUG_ON(!sess);
455 vha = sess->vha;
456
457 spin_lock_irqsave(&vha->hw->hardware_lock, flags);
1c7b13fe 458 target_sess_cmd_list_set_waiting(se_sess);
75f8c1f6
NB
459 spin_unlock_irqrestore(&vha->hw->hardware_lock, flags);
460
461 return 1;
462}
463
464static void tcm_qla2xxx_close_session(struct se_session *se_sess)
465{
466 struct qla_tgt_sess *sess = se_sess->fabric_sess_ptr;
467 struct scsi_qla_host *vha;
468 unsigned long flags;
469
470 BUG_ON(!sess);
471 vha = sess->vha;
472
473 spin_lock_irqsave(&vha->hw->hardware_lock, flags);
474 qlt_unreg_sess(sess);
475 spin_unlock_irqrestore(&vha->hw->hardware_lock, flags);
476}
477
478static u32 tcm_qla2xxx_sess_get_index(struct se_session *se_sess)
479{
480 return 0;
481}
482
75f8c1f6
NB
483static int tcm_qla2xxx_write_pending(struct se_cmd *se_cmd)
484{
485 struct qla_tgt_cmd *cmd = container_of(se_cmd,
486 struct qla_tgt_cmd, se_cmd);
487
488 cmd->bufflen = se_cmd->data_length;
b3faa2e8 489 cmd->dma_data_direction = target_reverse_dma_direction(se_cmd);
75f8c1f6
NB
490
491 cmd->sg_cnt = se_cmd->t_data_nents;
492 cmd->sg = se_cmd->t_data_sg;
493
f83adb61
QT
494 cmd->prot_sg_cnt = se_cmd->t_prot_nents;
495 cmd->prot_sg = se_cmd->t_prot_sg;
496 cmd->blk_sz = se_cmd->se_dev->dev_attrib.block_size;
497 se_cmd->pi_err = 0;
498
75f8c1f6
NB
499 /*
500 * qla_target.c:qlt_rdy_to_xfer() will call pci_map_sg() to setup
501 * the SGL mappings into PCIe memory for incoming FCP WRITE data.
502 */
503 return qlt_rdy_to_xfer(cmd);
504}
505
506static int tcm_qla2xxx_write_pending_status(struct se_cmd *se_cmd)
507{
508 unsigned long flags;
509 /*
510 * Check for WRITE_PENDING status to determine if we need to wait for
511 * CTIO aborts to be posted via hardware in tcm_qla2xxx_handle_data().
512 */
513 spin_lock_irqsave(&se_cmd->t_state_lock, flags);
514 if (se_cmd->t_state == TRANSPORT_WRITE_PENDING ||
515 se_cmd->t_state == TRANSPORT_COMPLETE_QF_WP) {
516 spin_unlock_irqrestore(&se_cmd->t_state_lock, flags);
517 wait_for_completion_timeout(&se_cmd->t_transport_stop_comp,
518 3000);
519 return 0;
520 }
521 spin_unlock_irqrestore(&se_cmd->t_state_lock, flags);
522
523 return 0;
524}
525
526static void tcm_qla2xxx_set_default_node_attrs(struct se_node_acl *nacl)
527{
528 return;
529}
530
531static u32 tcm_qla2xxx_get_task_tag(struct se_cmd *se_cmd)
532{
dd9c4eff
HM
533 struct qla_tgt_cmd *cmd;
534
535 /* check for task mgmt cmd */
536 if (se_cmd->se_cmd_flags & SCF_SCSI_TMR_CDB)
537 return 0xffffffff;
538
539 cmd = container_of(se_cmd, struct qla_tgt_cmd, se_cmd);
75f8c1f6
NB
540
541 return cmd->tag;
542}
543
544static int tcm_qla2xxx_get_cmd_state(struct se_cmd *se_cmd)
545{
546 return 0;
547}
548
549/*
550 * Called from process context in qla_target.c:qlt_do_work() code
551 */
552static int tcm_qla2xxx_handle_cmd(scsi_qla_host_t *vha, struct qla_tgt_cmd *cmd,
553 unsigned char *cdb, uint32_t data_length, int fcp_task_attr,
554 int data_dir, int bidi)
555{
556 struct se_cmd *se_cmd = &cmd->se_cmd;
557 struct se_session *se_sess;
558 struct qla_tgt_sess *sess;
559 int flags = TARGET_SCF_ACK_KREF;
560
561 if (bidi)
562 flags |= TARGET_SCF_BIDI_OP;
563
564 sess = cmd->sess;
565 if (!sess) {
566 pr_err("Unable to locate struct qla_tgt_sess from qla_tgt_cmd\n");
567 return -EINVAL;
568 }
569
570 se_sess = sess->se_sess;
571 if (!se_sess) {
572 pr_err("Unable to locate active struct se_session\n");
573 return -EINVAL;
574 }
575
d6dfc868 576 return target_submit_cmd(se_cmd, se_sess, cdb, &cmd->sense_buffer[0],
75f8c1f6
NB
577 cmd->unpacked_lun, data_length, fcp_task_attr,
578 data_dir, flags);
75f8c1f6
NB
579}
580
43381ce8 581static void tcm_qla2xxx_handle_data_work(struct work_struct *work)
75f8c1f6
NB
582{
583 struct qla_tgt_cmd *cmd = container_of(work, struct qla_tgt_cmd, work);
75f8c1f6 584
75f8c1f6
NB
585 /*
586 * Ensure that the complete FCP WRITE payload has been received.
587 * Otherwise return an exception via CHECK_CONDITION status.
588 */
e07f8f65
SK
589 cmd->cmd_in_wq = 0;
590 cmd->cmd_flags |= BIT_11;
75f8c1f6
NB
591 if (!cmd->write_data_transferred) {
592 /*
593 * Check if se_cmd has already been aborted via LUN_RESET, and
594 * waiting upon completion in tcm_qla2xxx_write_pending_status()
595 */
43381ce8
CH
596 if (cmd->se_cmd.transport_state & CMD_T_ABORTED) {
597 complete(&cmd->se_cmd.t_transport_stop_comp);
598 return;
75f8c1f6 599 }
75f8c1f6 600
f83adb61
QT
601 if (cmd->se_cmd.pi_err)
602 transport_generic_request_failure(&cmd->se_cmd,
603 cmd->se_cmd.pi_err);
604 else
605 transport_generic_request_failure(&cmd->se_cmd,
606 TCM_CHECK_CONDITION_ABORT_CMD);
607
43381ce8 608 return;
75f8c1f6 609 }
43381ce8
CH
610
611 return target_execute_cmd(&cmd->se_cmd);
612}
613
614/*
615 * Called from qla_target.c:qlt_do_ctio_completion()
616 */
617static void tcm_qla2xxx_handle_data(struct qla_tgt_cmd *cmd)
618{
e07f8f65
SK
619 cmd->cmd_flags |= BIT_10;
620 cmd->cmd_in_wq = 1;
43381ce8
CH
621 INIT_WORK(&cmd->work, tcm_qla2xxx_handle_data_work);
622 queue_work(tcm_qla2xxx_free_wq, &cmd->work);
75f8c1f6
NB
623}
624
f83adb61
QT
625static void tcm_qla2xxx_handle_dif_work(struct work_struct *work)
626{
627 struct qla_tgt_cmd *cmd = container_of(work, struct qla_tgt_cmd, work);
628
629 /* take an extra kref to prevent cmd free too early.
630 * need to wait for SCSI status/check condition to
631 * finish responding generate by transport_generic_request_failure.
632 */
633 kref_get(&cmd->se_cmd.cmd_kref);
634 transport_generic_request_failure(&cmd->se_cmd, cmd->se_cmd.pi_err);
635}
636
637/*
638 * Called from qla_target.c:qlt_do_ctio_completion()
639 */
640static void tcm_qla2xxx_handle_dif_err(struct qla_tgt_cmd *cmd)
641{
642 INIT_WORK(&cmd->work, tcm_qla2xxx_handle_dif_work);
643 queue_work(tcm_qla2xxx_free_wq, &cmd->work);
644}
645
75f8c1f6
NB
646/*
647 * Called from qla_target.c:qlt_issue_task_mgmt()
648 */
9389c3c9
RD
649static int tcm_qla2xxx_handle_tmr(struct qla_tgt_mgmt_cmd *mcmd, uint32_t lun,
650 uint8_t tmr_func, uint32_t tag)
75f8c1f6
NB
651{
652 struct qla_tgt_sess *sess = mcmd->sess;
653 struct se_cmd *se_cmd = &mcmd->se_cmd;
654
655 return target_submit_tmr(se_cmd, sess->se_sess, NULL, lun, mcmd,
656 tmr_func, GFP_ATOMIC, tag, TARGET_SCF_ACK_KREF);
657}
658
659static int tcm_qla2xxx_queue_data_in(struct se_cmd *se_cmd)
660{
661 struct qla_tgt_cmd *cmd = container_of(se_cmd,
662 struct qla_tgt_cmd, se_cmd);
663
e07f8f65 664 cmd->cmd_flags |= BIT_4;
75f8c1f6 665 cmd->bufflen = se_cmd->data_length;
b3faa2e8 666 cmd->dma_data_direction = target_reverse_dma_direction(se_cmd);
75f8c1f6
NB
667 cmd->aborted = (se_cmd->transport_state & CMD_T_ABORTED);
668
669 cmd->sg_cnt = se_cmd->t_data_nents;
670 cmd->sg = se_cmd->t_data_sg;
671 cmd->offset = 0;
e07f8f65 672 cmd->cmd_flags |= BIT_3;
75f8c1f6 673
f83adb61
QT
674 cmd->prot_sg_cnt = se_cmd->t_prot_nents;
675 cmd->prot_sg = se_cmd->t_prot_sg;
676 cmd->blk_sz = se_cmd->se_dev->dev_attrib.block_size;
677 se_cmd->pi_err = 0;
678
75f8c1f6
NB
679 /*
680 * Now queue completed DATA_IN the qla2xxx LLD and response ring
681 */
682 return qlt_xmit_response(cmd, QLA_TGT_XMIT_DATA|QLA_TGT_XMIT_STATUS,
683 se_cmd->scsi_status);
684}
685
686static int tcm_qla2xxx_queue_status(struct se_cmd *se_cmd)
687{
688 struct qla_tgt_cmd *cmd = container_of(se_cmd,
689 struct qla_tgt_cmd, se_cmd);
690 int xmit_type = QLA_TGT_XMIT_STATUS;
691
692 cmd->bufflen = se_cmd->data_length;
693 cmd->sg = NULL;
694 cmd->sg_cnt = 0;
695 cmd->offset = 0;
b3faa2e8 696 cmd->dma_data_direction = target_reverse_dma_direction(se_cmd);
75f8c1f6 697 cmd->aborted = (se_cmd->transport_state & CMD_T_ABORTED);
e07f8f65
SK
698 if (cmd->cmd_flags & BIT_5) {
699 pr_crit("Bit_5 already set for cmd = %p.\n", cmd);
700 dump_stack();
701 }
702 cmd->cmd_flags |= BIT_5;
75f8c1f6
NB
703
704 if (se_cmd->data_direction == DMA_FROM_DEVICE) {
705 /*
706 * For FCP_READ with CHECK_CONDITION status, clear cmd->bufflen
707 * for qla_tgt_xmit_response LLD code
708 */
b5aff3d2
RD
709 if (se_cmd->se_cmd_flags & SCF_OVERFLOW_BIT) {
710 se_cmd->se_cmd_flags &= ~SCF_OVERFLOW_BIT;
711 se_cmd->residual_count = 0;
712 }
75f8c1f6 713 se_cmd->se_cmd_flags |= SCF_UNDERFLOW_BIT;
b5aff3d2 714 se_cmd->residual_count += se_cmd->data_length;
75f8c1f6
NB
715
716 cmd->bufflen = 0;
717 }
718 /*
719 * Now queue status response to qla2xxx LLD code and response ring
720 */
721 return qlt_xmit_response(cmd, xmit_type, se_cmd->scsi_status);
722}
723
b79fafac 724static void tcm_qla2xxx_queue_tm_rsp(struct se_cmd *se_cmd)
75f8c1f6
NB
725{
726 struct se_tmr_req *se_tmr = se_cmd->se_tmr_req;
727 struct qla_tgt_mgmt_cmd *mcmd = container_of(se_cmd,
728 struct qla_tgt_mgmt_cmd, se_cmd);
729
730 pr_debug("queue_tm_rsp: mcmd: %p func: 0x%02x response: 0x%02x\n",
731 mcmd, se_tmr->function, se_tmr->response);
732 /*
733 * Do translation between TCM TM response codes and
734 * QLA2xxx FC TM response codes.
735 */
736 switch (se_tmr->response) {
737 case TMR_FUNCTION_COMPLETE:
738 mcmd->fc_tm_rsp = FC_TM_SUCCESS;
739 break;
740 case TMR_TASK_DOES_NOT_EXIST:
741 mcmd->fc_tm_rsp = FC_TM_BAD_CMD;
742 break;
743 case TMR_FUNCTION_REJECTED:
744 mcmd->fc_tm_rsp = FC_TM_REJECT;
745 break;
746 case TMR_LUN_DOES_NOT_EXIST:
747 default:
748 mcmd->fc_tm_rsp = FC_TM_FAILED;
749 break;
750 }
751 /*
752 * Queue the TM response to QLA2xxx LLD to build a
753 * CTIO response packet.
754 */
755 qlt_xmit_tm_rsp(mcmd);
75f8c1f6
NB
756}
757
131e6abc
NB
758static void tcm_qla2xxx_aborted_task(struct se_cmd *se_cmd)
759{
760 struct qla_tgt_cmd *cmd = container_of(se_cmd,
761 struct qla_tgt_cmd, se_cmd);
762 struct scsi_qla_host *vha = cmd->vha;
763 struct qla_hw_data *ha = vha->hw;
764
765 if (!cmd->sg_mapped)
766 return;
767
768 pci_unmap_sg(ha->pdev, cmd->sg, cmd->sg_cnt, cmd->dma_data_direction);
769 cmd->sg_mapped = 0;
770}
771
f2d5d9b9
NB
772static void tcm_qla2xxx_clear_sess_lookup(struct tcm_qla2xxx_lport *,
773 struct tcm_qla2xxx_nacl *, struct qla_tgt_sess *);
75f8c1f6
NB
774/*
775 * Expected to be called with struct qla_hw_data->hardware_lock held
776 */
777static void tcm_qla2xxx_clear_nacl_from_fcport_map(struct qla_tgt_sess *sess)
778{
779 struct se_node_acl *se_nacl = sess->se_sess->se_node_acl;
780 struct se_portal_group *se_tpg = se_nacl->se_tpg;
781 struct se_wwn *se_wwn = se_tpg->se_tpg_wwn;
782 struct tcm_qla2xxx_lport *lport = container_of(se_wwn,
783 struct tcm_qla2xxx_lport, lport_wwn);
784 struct tcm_qla2xxx_nacl *nacl = container_of(se_nacl,
785 struct tcm_qla2xxx_nacl, se_node_acl);
786 void *node;
787
788 pr_debug("fc_rport domain: port_id 0x%06x\n", nacl->nport_id);
789
790 node = btree_remove32(&lport->lport_fcport_map, nacl->nport_id);
f4c24db1
JE
791 if (WARN_ON(node && (node != se_nacl))) {
792 /*
793 * The nacl no longer matches what we think it should be.
794 * Most likely a new dynamic acl has been added while
795 * someone dropped the hardware lock. It clearly is a
796 * bug elsewhere, but this bit can't make things worse.
797 */
798 btree_insert32(&lport->lport_fcport_map, nacl->nport_id,
799 node, GFP_ATOMIC);
800 }
75f8c1f6
NB
801
802 pr_debug("Removed from fcport_map: %p for WWNN: 0x%016LX, port_id: 0x%06x\n",
803 se_nacl, nacl->nport_wwnn, nacl->nport_id);
f2d5d9b9
NB
804 /*
805 * Now clear the se_nacl and session pointers from our HW lport lookup
806 * table mapping for this initiator's fabric S_ID and LOOP_ID entries.
807 *
808 * This is done ahead of callbacks into tcm_qla2xxx_free_session() ->
809 * target_wait_for_sess_cmds() before the session waits for outstanding
810 * I/O to complete, to avoid a race between session shutdown execution
811 * and incoming ATIOs or TMRs picking up a stale se_node_act reference.
812 */
813 tcm_qla2xxx_clear_sess_lookup(lport, nacl, sess);
75f8c1f6
NB
814}
815
aaf68b75
JE
816static void tcm_qla2xxx_release_session(struct kref *kref)
817{
818 struct se_session *se_sess = container_of(kref,
819 struct se_session, sess_kref);
820
821 qlt_unreg_sess(se_sess->fabric_sess_ptr);
822}
823
824static void tcm_qla2xxx_put_session(struct se_session *se_sess)
825{
826 struct qla_tgt_sess *sess = se_sess->fabric_sess_ptr;
827 struct qla_hw_data *ha = sess->vha->hw;
828 unsigned long flags;
829
830 spin_lock_irqsave(&ha->hardware_lock, flags);
831 kref_put(&se_sess->sess_kref, tcm_qla2xxx_release_session);
832 spin_unlock_irqrestore(&ha->hardware_lock, flags);
833}
834
75f8c1f6
NB
835static void tcm_qla2xxx_put_sess(struct qla_tgt_sess *sess)
836{
0e8cd71c
SK
837 if (!sess)
838 return;
839
08234e3a
JE
840 assert_spin_locked(&sess->vha->hw->hardware_lock);
841 kref_put(&sess->se_sess->sess_kref, tcm_qla2xxx_release_session);
75f8c1f6
NB
842}
843
844static void tcm_qla2xxx_shutdown_sess(struct qla_tgt_sess *sess)
845{
08234e3a
JE
846 assert_spin_locked(&sess->vha->hw->hardware_lock);
847 target_sess_cmd_list_set_waiting(sess->se_sess);
75f8c1f6
NB
848}
849
850static struct se_node_acl *tcm_qla2xxx_make_nodeacl(
851 struct se_portal_group *se_tpg,
852 struct config_group *group,
853 const char *name)
854{
75f8c1f6
NB
855 struct se_node_acl *se_nacl, *se_nacl_new;
856 struct tcm_qla2xxx_nacl *nacl;
857 u64 wwnn;
858 u32 qla2xxx_nexus_depth;
75f8c1f6
NB
859
860 if (tcm_qla2xxx_parse_wwn(name, &wwnn, 1) < 0)
861 return ERR_PTR(-EINVAL);
862
863 se_nacl_new = tcm_qla2xxx_alloc_fabric_acl(se_tpg);
864 if (!se_nacl_new)
865 return ERR_PTR(-ENOMEM);
866/* #warning FIXME: Hardcoded qla2xxx_nexus depth in tcm_qla2xxx_make_nodeacl */
867 qla2xxx_nexus_depth = 1;
868
869 /*
870 * se_nacl_new may be released by core_tpg_add_initiator_node_acl()
871 * when converting a NodeACL from demo mode -> explict
872 */
873 se_nacl = core_tpg_add_initiator_node_acl(se_tpg, se_nacl_new,
874 name, qla2xxx_nexus_depth);
875 if (IS_ERR(se_nacl)) {
876 tcm_qla2xxx_release_fabric_acl(se_tpg, se_nacl_new);
877 return se_nacl;
878 }
879 /*
880 * Locate our struct tcm_qla2xxx_nacl and set the FC Nport WWPN
881 */
882 nacl = container_of(se_nacl, struct tcm_qla2xxx_nacl, se_node_acl);
883 nacl->nport_wwnn = wwnn;
884 tcm_qla2xxx_format_wwn(&nacl->nport_name[0], TCM_QLA2XXX_NAMELEN, wwnn);
75f8c1f6
NB
885
886 return se_nacl;
887}
888
889static void tcm_qla2xxx_drop_nodeacl(struct se_node_acl *se_acl)
890{
891 struct se_portal_group *se_tpg = se_acl->se_tpg;
892 struct tcm_qla2xxx_nacl *nacl = container_of(se_acl,
893 struct tcm_qla2xxx_nacl, se_node_acl);
894
895 core_tpg_del_initiator_node_acl(se_tpg, se_acl, 1);
896 kfree(nacl);
897}
898
899/* Start items for tcm_qla2xxx_tpg_attrib_cit */
900
901#define DEF_QLA_TPG_ATTRIB(name) \
902 \
903static ssize_t tcm_qla2xxx_tpg_attrib_show_##name( \
904 struct se_portal_group *se_tpg, \
905 char *page) \
906{ \
907 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg, \
908 struct tcm_qla2xxx_tpg, se_tpg); \
909 \
a309f489 910 return sprintf(page, "%u\n", tpg->tpg_attrib.name); \
75f8c1f6
NB
911} \
912 \
913static ssize_t tcm_qla2xxx_tpg_attrib_store_##name( \
914 struct se_portal_group *se_tpg, \
915 const char *page, \
916 size_t count) \
917{ \
918 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg, \
919 struct tcm_qla2xxx_tpg, se_tpg); \
920 unsigned long val; \
921 int ret; \
922 \
923 ret = kstrtoul(page, 0, &val); \
924 if (ret < 0) { \
925 pr_err("kstrtoul() failed with" \
926 " ret: %d\n", ret); \
927 return -EINVAL; \
928 } \
929 ret = tcm_qla2xxx_set_attrib_##name(tpg, val); \
930 \
931 return (!ret) ? count : -EINVAL; \
932}
933
934#define DEF_QLA_TPG_ATTR_BOOL(_name) \
935 \
936static int tcm_qla2xxx_set_attrib_##_name( \
937 struct tcm_qla2xxx_tpg *tpg, \
938 unsigned long val) \
939{ \
940 struct tcm_qla2xxx_tpg_attrib *a = &tpg->tpg_attrib; \
941 \
942 if ((val != 0) && (val != 1)) { \
943 pr_err("Illegal boolean value %lu\n", val); \
944 return -EINVAL; \
945 } \
946 \
947 a->_name = val; \
948 return 0; \
949}
950
951#define QLA_TPG_ATTR(_name, _mode) \
952 TF_TPG_ATTRIB_ATTR(tcm_qla2xxx, _name, _mode);
953
954/*
955 * Define tcm_qla2xxx_tpg_attrib_s_generate_node_acls
956 */
957DEF_QLA_TPG_ATTR_BOOL(generate_node_acls);
958DEF_QLA_TPG_ATTRIB(generate_node_acls);
959QLA_TPG_ATTR(generate_node_acls, S_IRUGO | S_IWUSR);
960
961/*
962 Define tcm_qla2xxx_attrib_s_cache_dynamic_acls
963 */
964DEF_QLA_TPG_ATTR_BOOL(cache_dynamic_acls);
965DEF_QLA_TPG_ATTRIB(cache_dynamic_acls);
966QLA_TPG_ATTR(cache_dynamic_acls, S_IRUGO | S_IWUSR);
967
968/*
969 * Define tcm_qla2xxx_tpg_attrib_s_demo_mode_write_protect
970 */
971DEF_QLA_TPG_ATTR_BOOL(demo_mode_write_protect);
972DEF_QLA_TPG_ATTRIB(demo_mode_write_protect);
973QLA_TPG_ATTR(demo_mode_write_protect, S_IRUGO | S_IWUSR);
974
975/*
976 * Define tcm_qla2xxx_tpg_attrib_s_prod_mode_write_protect
977 */
978DEF_QLA_TPG_ATTR_BOOL(prod_mode_write_protect);
979DEF_QLA_TPG_ATTRIB(prod_mode_write_protect);
980QLA_TPG_ATTR(prod_mode_write_protect, S_IRUGO | S_IWUSR);
981
de04a8aa
AG
982/*
983 * Define tcm_qla2xxx_tpg_attrib_s_demo_mode_login_only
984 */
985DEF_QLA_TPG_ATTR_BOOL(demo_mode_login_only);
986DEF_QLA_TPG_ATTRIB(demo_mode_login_only);
987QLA_TPG_ATTR(demo_mode_login_only, S_IRUGO | S_IWUSR);
988
75f8c1f6
NB
989static struct configfs_attribute *tcm_qla2xxx_tpg_attrib_attrs[] = {
990 &tcm_qla2xxx_tpg_attrib_generate_node_acls.attr,
991 &tcm_qla2xxx_tpg_attrib_cache_dynamic_acls.attr,
992 &tcm_qla2xxx_tpg_attrib_demo_mode_write_protect.attr,
993 &tcm_qla2xxx_tpg_attrib_prod_mode_write_protect.attr,
de04a8aa 994 &tcm_qla2xxx_tpg_attrib_demo_mode_login_only.attr,
75f8c1f6
NB
995 NULL,
996};
997
998/* End items for tcm_qla2xxx_tpg_attrib_cit */
999
1000static ssize_t tcm_qla2xxx_tpg_show_enable(
1001 struct se_portal_group *se_tpg,
1002 char *page)
1003{
1004 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
1005 struct tcm_qla2xxx_tpg, se_tpg);
1006
1007 return snprintf(page, PAGE_SIZE, "%d\n",
1008 atomic_read(&tpg->lport_tpg_enabled));
1009}
1010
7474f52a
NB
1011static void tcm_qla2xxx_depend_tpg(struct work_struct *work)
1012{
1013 struct tcm_qla2xxx_tpg *base_tpg = container_of(work,
1014 struct tcm_qla2xxx_tpg, tpg_base_work);
1015 struct se_portal_group *se_tpg = &base_tpg->se_tpg;
1016 struct scsi_qla_host *base_vha = base_tpg->lport->qla_vha;
1017
d588cf8f 1018 if (!target_depend_item(&se_tpg->tpg_group.cg_item)) {
7474f52a
NB
1019 atomic_set(&base_tpg->lport_tpg_enabled, 1);
1020 qlt_enable_vha(base_vha);
1021 }
1022 complete(&base_tpg->tpg_base_comp);
1023}
1024
1025static void tcm_qla2xxx_undepend_tpg(struct work_struct *work)
1026{
1027 struct tcm_qla2xxx_tpg *base_tpg = container_of(work,
1028 struct tcm_qla2xxx_tpg, tpg_base_work);
1029 struct se_portal_group *se_tpg = &base_tpg->se_tpg;
1030 struct scsi_qla_host *base_vha = base_tpg->lport->qla_vha;
1031
1032 if (!qlt_stop_phase1(base_vha->vha_tgt.qla_tgt)) {
1033 atomic_set(&base_tpg->lport_tpg_enabled, 0);
d588cf8f 1034 target_undepend_item(&se_tpg->tpg_group.cg_item);
7474f52a
NB
1035 }
1036 complete(&base_tpg->tpg_base_comp);
1037}
1038
75f8c1f6
NB
1039static ssize_t tcm_qla2xxx_tpg_store_enable(
1040 struct se_portal_group *se_tpg,
1041 const char *page,
1042 size_t count)
1043{
75f8c1f6
NB
1044 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
1045 struct tcm_qla2xxx_tpg, se_tpg);
1046 unsigned long op;
1047 int rc;
1048
1049 rc = kstrtoul(page, 0, &op);
1050 if (rc < 0) {
1051 pr_err("kstrtoul() returned %d\n", rc);
1052 return -EINVAL;
1053 }
1054 if ((op != 1) && (op != 0)) {
1055 pr_err("Illegal value for tpg_enable: %lu\n", op);
1056 return -EINVAL;
1057 }
75f8c1f6 1058 if (op) {
7474f52a
NB
1059 if (atomic_read(&tpg->lport_tpg_enabled))
1060 return -EEXIST;
1061
1062 INIT_WORK(&tpg->tpg_base_work, tcm_qla2xxx_depend_tpg);
75f8c1f6 1063 } else {
7474f52a
NB
1064 if (!atomic_read(&tpg->lport_tpg_enabled))
1065 return count;
1066
1067 INIT_WORK(&tpg->tpg_base_work, tcm_qla2xxx_undepend_tpg);
75f8c1f6 1068 }
7474f52a
NB
1069 init_completion(&tpg->tpg_base_comp);
1070 schedule_work(&tpg->tpg_base_work);
1071 wait_for_completion(&tpg->tpg_base_comp);
75f8c1f6 1072
7474f52a
NB
1073 if (op) {
1074 if (!atomic_read(&tpg->lport_tpg_enabled))
1075 return -ENODEV;
1076 } else {
1077 if (atomic_read(&tpg->lport_tpg_enabled))
1078 return -EPERM;
1079 }
75f8c1f6
NB
1080 return count;
1081}
1082
1083TF_TPG_BASE_ATTR(tcm_qla2xxx, enable, S_IRUGO | S_IWUSR);
1084
d23dbaaa
NB
1085static ssize_t tcm_qla2xxx_tpg_show_dynamic_sessions(
1086 struct se_portal_group *se_tpg,
1087 char *page)
1088{
1089 return target_show_dynamic_sessions(se_tpg, page);
1090}
1091
1092TF_TPG_BASE_ATTR_RO(tcm_qla2xxx, dynamic_sessions);
1093
64b16887
NB
1094static ssize_t tcm_qla2xxx_tpg_store_fabric_prot_type(
1095 struct se_portal_group *se_tpg,
1096 const char *page,
1097 size_t count)
1098{
1099 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
1100 struct tcm_qla2xxx_tpg, se_tpg);
1101 unsigned long val;
1102 int ret = kstrtoul(page, 0, &val);
1103
1104 if (ret) {
1105 pr_err("kstrtoul() returned %d for fabric_prot_type\n", ret);
1106 return ret;
1107 }
1108 if (val != 0 && val != 1 && val != 3) {
1109 pr_err("Invalid qla2xxx fabric_prot_type: %lu\n", val);
1110 return -EINVAL;
1111 }
1112 tpg->tpg_attrib.fabric_prot_type = val;
1113
1114 return count;
1115}
1116
1117static ssize_t tcm_qla2xxx_tpg_show_fabric_prot_type(
1118 struct se_portal_group *se_tpg,
1119 char *page)
1120{
1121 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
1122 struct tcm_qla2xxx_tpg, se_tpg);
1123
1124 return sprintf(page, "%d\n", tpg->tpg_attrib.fabric_prot_type);
1125}
1126TF_TPG_BASE_ATTR(tcm_qla2xxx, fabric_prot_type, S_IRUGO | S_IWUSR);
1127
75f8c1f6
NB
1128static struct configfs_attribute *tcm_qla2xxx_tpg_attrs[] = {
1129 &tcm_qla2xxx_tpg_enable.attr,
d23dbaaa 1130 &tcm_qla2xxx_tpg_dynamic_sessions.attr,
64b16887 1131 &tcm_qla2xxx_tpg_fabric_prot_type.attr,
75f8c1f6
NB
1132 NULL,
1133};
1134
1135static struct se_portal_group *tcm_qla2xxx_make_tpg(
1136 struct se_wwn *wwn,
1137 struct config_group *group,
1138 const char *name)
1139{
1140 struct tcm_qla2xxx_lport *lport = container_of(wwn,
1141 struct tcm_qla2xxx_lport, lport_wwn);
1142 struct tcm_qla2xxx_tpg *tpg;
1143 unsigned long tpgt;
1144 int ret;
1145
1146 if (strstr(name, "tpgt_") != name)
1147 return ERR_PTR(-EINVAL);
1148 if (kstrtoul(name + 5, 10, &tpgt) || tpgt > USHRT_MAX)
1149 return ERR_PTR(-EINVAL);
1150
0e8cd71c 1151 if ((tpgt != 1)) {
75f8c1f6
NB
1152 pr_err("In non NPIV mode, a single TPG=1 is used for HW port mappings\n");
1153 return ERR_PTR(-ENOSYS);
1154 }
1155
1156 tpg = kzalloc(sizeof(struct tcm_qla2xxx_tpg), GFP_KERNEL);
1157 if (!tpg) {
1158 pr_err("Unable to allocate struct tcm_qla2xxx_tpg\n");
1159 return ERR_PTR(-ENOMEM);
1160 }
1161 tpg->lport = lport;
1162 tpg->lport_tpgt = tpgt;
1163 /*
1164 * By default allow READ-ONLY TPG demo-mode access w/ cached dynamic
1165 * NodeACLs
1166 */
a309f489
AG
1167 tpg->tpg_attrib.generate_node_acls = 1;
1168 tpg->tpg_attrib.demo_mode_write_protect = 1;
1169 tpg->tpg_attrib.cache_dynamic_acls = 1;
1170 tpg->tpg_attrib.demo_mode_login_only = 1;
75f8c1f6 1171
9ac8928e 1172 ret = core_tpg_register(&tcm_qla2xxx_ops, wwn,
75f8c1f6
NB
1173 &tpg->se_tpg, tpg, TRANSPORT_TPG_TYPE_NORMAL);
1174 if (ret < 0) {
1175 kfree(tpg);
1176 return NULL;
1177 }
0e8cd71c
SK
1178
1179 lport->tpg_1 = tpg;
75f8c1f6
NB
1180
1181 return &tpg->se_tpg;
1182}
1183
1184static void tcm_qla2xxx_drop_tpg(struct se_portal_group *se_tpg)
1185{
1186 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
1187 struct tcm_qla2xxx_tpg, se_tpg);
1188 struct tcm_qla2xxx_lport *lport = tpg->lport;
1189 struct scsi_qla_host *vha = lport->qla_vha;
75f8c1f6
NB
1190 /*
1191 * Call into qla2x_target.c LLD logic to shutdown the active
1192 * FC Nexuses and disable target mode operation for this qla_hw_data
1193 */
0e8cd71c
SK
1194 if (vha->vha_tgt.qla_tgt && !vha->vha_tgt.qla_tgt->tgt_stop)
1195 qlt_stop_phase1(vha->vha_tgt.qla_tgt);
75f8c1f6
NB
1196
1197 core_tpg_deregister(se_tpg);
1198 /*
1199 * Clear local TPG=1 pointer for non NPIV mode.
1200 */
394d62ba 1201 lport->tpg_1 = NULL;
75f8c1f6
NB
1202 kfree(tpg);
1203}
1204
394d62ba
NB
1205static ssize_t tcm_qla2xxx_npiv_tpg_show_enable(
1206 struct se_portal_group *se_tpg,
1207 char *page)
1208{
1209 return tcm_qla2xxx_tpg_show_enable(se_tpg, page);
1210}
1211
1212static ssize_t tcm_qla2xxx_npiv_tpg_store_enable(
1213 struct se_portal_group *se_tpg,
1214 const char *page,
1215 size_t count)
1216{
1217 struct se_wwn *se_wwn = se_tpg->se_tpg_wwn;
1218 struct tcm_qla2xxx_lport *lport = container_of(se_wwn,
1219 struct tcm_qla2xxx_lport, lport_wwn);
1220 struct scsi_qla_host *vha = lport->qla_vha;
1221 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
1222 struct tcm_qla2xxx_tpg, se_tpg);
1223 unsigned long op;
1224 int rc;
1225
1226 rc = kstrtoul(page, 0, &op);
1227 if (rc < 0) {
1228 pr_err("kstrtoul() returned %d\n", rc);
1229 return -EINVAL;
1230 }
1231 if ((op != 1) && (op != 0)) {
1232 pr_err("Illegal value for tpg_enable: %lu\n", op);
1233 return -EINVAL;
1234 }
1235 if (op) {
1236 if (atomic_read(&tpg->lport_tpg_enabled))
1237 return -EEXIST;
1238
1239 atomic_set(&tpg->lport_tpg_enabled, 1);
1240 qlt_enable_vha(vha);
1241 } else {
1242 if (!atomic_read(&tpg->lport_tpg_enabled))
1243 return count;
1244
1245 atomic_set(&tpg->lport_tpg_enabled, 0);
1246 qlt_stop_phase1(vha->vha_tgt.qla_tgt);
1247 }
1248
1249 return count;
1250}
1251
1252TF_TPG_BASE_ATTR(tcm_qla2xxx_npiv, enable, S_IRUGO | S_IWUSR);
1253
1254static struct configfs_attribute *tcm_qla2xxx_npiv_tpg_attrs[] = {
1255 &tcm_qla2xxx_npiv_tpg_enable.attr,
1256 NULL,
1257};
1258
75f8c1f6
NB
1259static struct se_portal_group *tcm_qla2xxx_npiv_make_tpg(
1260 struct se_wwn *wwn,
1261 struct config_group *group,
1262 const char *name)
1263{
1264 struct tcm_qla2xxx_lport *lport = container_of(wwn,
1265 struct tcm_qla2xxx_lport, lport_wwn);
1266 struct tcm_qla2xxx_tpg *tpg;
1267 unsigned long tpgt;
1268 int ret;
1269
1270 if (strstr(name, "tpgt_") != name)
1271 return ERR_PTR(-EINVAL);
1272 if (kstrtoul(name + 5, 10, &tpgt) || tpgt > USHRT_MAX)
1273 return ERR_PTR(-EINVAL);
1274
1275 tpg = kzalloc(sizeof(struct tcm_qla2xxx_tpg), GFP_KERNEL);
1276 if (!tpg) {
1277 pr_err("Unable to allocate struct tcm_qla2xxx_tpg\n");
1278 return ERR_PTR(-ENOMEM);
1279 }
1280 tpg->lport = lport;
1281 tpg->lport_tpgt = tpgt;
1282
0e8cd71c
SK
1283 /*
1284 * By default allow READ-ONLY TPG demo-mode access w/ cached dynamic
1285 * NodeACLs
1286 */
1287 tpg->tpg_attrib.generate_node_acls = 1;
1288 tpg->tpg_attrib.demo_mode_write_protect = 1;
1289 tpg->tpg_attrib.cache_dynamic_acls = 1;
1290 tpg->tpg_attrib.demo_mode_login_only = 1;
1291
9ac8928e 1292 ret = core_tpg_register(&tcm_qla2xxx_npiv_ops, wwn,
75f8c1f6
NB
1293 &tpg->se_tpg, tpg, TRANSPORT_TPG_TYPE_NORMAL);
1294 if (ret < 0) {
1295 kfree(tpg);
1296 return NULL;
1297 }
0e8cd71c 1298 lport->tpg_1 = tpg;
75f8c1f6
NB
1299 return &tpg->se_tpg;
1300}
1301
1302/*
1303 * Expected to be called with struct qla_hw_data->hardware_lock held
1304 */
1305static struct qla_tgt_sess *tcm_qla2xxx_find_sess_by_s_id(
1306 scsi_qla_host_t *vha,
1307 const uint8_t *s_id)
1308{
75f8c1f6
NB
1309 struct tcm_qla2xxx_lport *lport;
1310 struct se_node_acl *se_nacl;
1311 struct tcm_qla2xxx_nacl *nacl;
1312 u32 key;
1313
0e8cd71c 1314 lport = vha->vha_tgt.target_lport_ptr;
75f8c1f6
NB
1315 if (!lport) {
1316 pr_err("Unable to locate struct tcm_qla2xxx_lport\n");
1317 dump_stack();
1318 return NULL;
1319 }
1320
1321 key = (((unsigned long)s_id[0] << 16) |
1322 ((unsigned long)s_id[1] << 8) |
1323 (unsigned long)s_id[2]);
1324 pr_debug("find_sess_by_s_id: 0x%06x\n", key);
1325
1326 se_nacl = btree_lookup32(&lport->lport_fcport_map, key);
1327 if (!se_nacl) {
1328 pr_debug("Unable to locate s_id: 0x%06x\n", key);
1329 return NULL;
1330 }
1331 pr_debug("find_sess_by_s_id: located se_nacl: %p, initiatorname: %s\n",
1332 se_nacl, se_nacl->initiatorname);
1333
1334 nacl = container_of(se_nacl, struct tcm_qla2xxx_nacl, se_node_acl);
1335 if (!nacl->qla_tgt_sess) {
1336 pr_err("Unable to locate struct qla_tgt_sess\n");
1337 return NULL;
1338 }
1339
1340 return nacl->qla_tgt_sess;
1341}
1342
1343/*
1344 * Expected to be called with struct qla_hw_data->hardware_lock held
1345 */
1346static void tcm_qla2xxx_set_sess_by_s_id(
1347 struct tcm_qla2xxx_lport *lport,
1348 struct se_node_acl *new_se_nacl,
1349 struct tcm_qla2xxx_nacl *nacl,
1350 struct se_session *se_sess,
1351 struct qla_tgt_sess *qla_tgt_sess,
1352 uint8_t *s_id)
1353{
1354 u32 key;
1355 void *slot;
1356 int rc;
1357
1358 key = (((unsigned long)s_id[0] << 16) |
1359 ((unsigned long)s_id[1] << 8) |
1360 (unsigned long)s_id[2]);
1361 pr_debug("set_sess_by_s_id: %06x\n", key);
1362
1363 slot = btree_lookup32(&lport->lport_fcport_map, key);
1364 if (!slot) {
1365 if (new_se_nacl) {
1366 pr_debug("Setting up new fc_port entry to new_se_nacl\n");
1367 nacl->nport_id = key;
1368 rc = btree_insert32(&lport->lport_fcport_map, key,
1369 new_se_nacl, GFP_ATOMIC);
1370 if (rc)
1371 printk(KERN_ERR "Unable to insert s_id into fcport_map: %06x\n",
1372 (int)key);
1373 } else {
1374 pr_debug("Wiping nonexisting fc_port entry\n");
1375 }
1376
1377 qla_tgt_sess->se_sess = se_sess;
1378 nacl->qla_tgt_sess = qla_tgt_sess;
1379 return;
1380 }
1381
1382 if (nacl->qla_tgt_sess) {
1383 if (new_se_nacl == NULL) {
1384 pr_debug("Clearing existing nacl->qla_tgt_sess and fc_port entry\n");
1385 btree_remove32(&lport->lport_fcport_map, key);
1386 nacl->qla_tgt_sess = NULL;
1387 return;
1388 }
1389 pr_debug("Replacing existing nacl->qla_tgt_sess and fc_port entry\n");
1390 btree_update32(&lport->lport_fcport_map, key, new_se_nacl);
1391 qla_tgt_sess->se_sess = se_sess;
1392 nacl->qla_tgt_sess = qla_tgt_sess;
1393 return;
1394 }
1395
1396 if (new_se_nacl == NULL) {
1397 pr_debug("Clearing existing fc_port entry\n");
1398 btree_remove32(&lport->lport_fcport_map, key);
1399 return;
1400 }
1401
1402 pr_debug("Replacing existing fc_port entry w/o active nacl->qla_tgt_sess\n");
1403 btree_update32(&lport->lport_fcport_map, key, new_se_nacl);
1404 qla_tgt_sess->se_sess = se_sess;
1405 nacl->qla_tgt_sess = qla_tgt_sess;
1406
1407 pr_debug("Setup nacl->qla_tgt_sess %p by s_id for se_nacl: %p, initiatorname: %s\n",
1408 nacl->qla_tgt_sess, new_se_nacl, new_se_nacl->initiatorname);
1409}
1410
1411/*
1412 * Expected to be called with struct qla_hw_data->hardware_lock held
1413 */
1414static struct qla_tgt_sess *tcm_qla2xxx_find_sess_by_loop_id(
1415 scsi_qla_host_t *vha,
1416 const uint16_t loop_id)
1417{
75f8c1f6
NB
1418 struct tcm_qla2xxx_lport *lport;
1419 struct se_node_acl *se_nacl;
1420 struct tcm_qla2xxx_nacl *nacl;
1421 struct tcm_qla2xxx_fc_loopid *fc_loopid;
1422
0e8cd71c 1423 lport = vha->vha_tgt.target_lport_ptr;
75f8c1f6
NB
1424 if (!lport) {
1425 pr_err("Unable to locate struct tcm_qla2xxx_lport\n");
1426 dump_stack();
1427 return NULL;
1428 }
1429
1430 pr_debug("find_sess_by_loop_id: Using loop_id: 0x%04x\n", loop_id);
1431
1432 fc_loopid = lport->lport_loopid_map + loop_id;
1433 se_nacl = fc_loopid->se_nacl;
1434 if (!se_nacl) {
1435 pr_debug("Unable to locate se_nacl by loop_id: 0x%04x\n",
1436 loop_id);
1437 return NULL;
1438 }
1439
1440 nacl = container_of(se_nacl, struct tcm_qla2xxx_nacl, se_node_acl);
1441
1442 if (!nacl->qla_tgt_sess) {
1443 pr_err("Unable to locate struct qla_tgt_sess\n");
1444 return NULL;
1445 }
1446
1447 return nacl->qla_tgt_sess;
1448}
1449
1450/*
1451 * Expected to be called with struct qla_hw_data->hardware_lock held
1452 */
1453static void tcm_qla2xxx_set_sess_by_loop_id(
1454 struct tcm_qla2xxx_lport *lport,
1455 struct se_node_acl *new_se_nacl,
1456 struct tcm_qla2xxx_nacl *nacl,
1457 struct se_session *se_sess,
1458 struct qla_tgt_sess *qla_tgt_sess,
1459 uint16_t loop_id)
1460{
1461 struct se_node_acl *saved_nacl;
1462 struct tcm_qla2xxx_fc_loopid *fc_loopid;
1463
1464 pr_debug("set_sess_by_loop_id: Using loop_id: 0x%04x\n", loop_id);
1465
1466 fc_loopid = &((struct tcm_qla2xxx_fc_loopid *)
1467 lport->lport_loopid_map)[loop_id];
1468
1469 saved_nacl = fc_loopid->se_nacl;
1470 if (!saved_nacl) {
1471 pr_debug("Setting up new fc_loopid->se_nacl to new_se_nacl\n");
1472 fc_loopid->se_nacl = new_se_nacl;
1473 if (qla_tgt_sess->se_sess != se_sess)
1474 qla_tgt_sess->se_sess = se_sess;
1475 if (nacl->qla_tgt_sess != qla_tgt_sess)
1476 nacl->qla_tgt_sess = qla_tgt_sess;
1477 return;
1478 }
1479
1480 if (nacl->qla_tgt_sess) {
1481 if (new_se_nacl == NULL) {
1482 pr_debug("Clearing nacl->qla_tgt_sess and fc_loopid->se_nacl\n");
1483 fc_loopid->se_nacl = NULL;
1484 nacl->qla_tgt_sess = NULL;
1485 return;
1486 }
1487
1488 pr_debug("Replacing existing nacl->qla_tgt_sess and fc_loopid->se_nacl\n");
1489 fc_loopid->se_nacl = new_se_nacl;
1490 if (qla_tgt_sess->se_sess != se_sess)
1491 qla_tgt_sess->se_sess = se_sess;
1492 if (nacl->qla_tgt_sess != qla_tgt_sess)
1493 nacl->qla_tgt_sess = qla_tgt_sess;
1494 return;
1495 }
1496
1497 if (new_se_nacl == NULL) {
1498 pr_debug("Clearing fc_loopid->se_nacl\n");
1499 fc_loopid->se_nacl = NULL;
1500 return;
1501 }
1502
1503 pr_debug("Replacing existing fc_loopid->se_nacl w/o active nacl->qla_tgt_sess\n");
1504 fc_loopid->se_nacl = new_se_nacl;
1505 if (qla_tgt_sess->se_sess != se_sess)
1506 qla_tgt_sess->se_sess = se_sess;
1507 if (nacl->qla_tgt_sess != qla_tgt_sess)
1508 nacl->qla_tgt_sess = qla_tgt_sess;
1509
1510 pr_debug("Setup nacl->qla_tgt_sess %p by loop_id for se_nacl: %p, initiatorname: %s\n",
1511 nacl->qla_tgt_sess, new_se_nacl, new_se_nacl->initiatorname);
1512}
1513
f2d5d9b9
NB
1514/*
1515 * Should always be called with qla_hw_data->hardware_lock held.
1516 */
1517static void tcm_qla2xxx_clear_sess_lookup(struct tcm_qla2xxx_lport *lport,
1518 struct tcm_qla2xxx_nacl *nacl, struct qla_tgt_sess *sess)
1519{
1520 struct se_session *se_sess = sess->se_sess;
1521 unsigned char be_sid[3];
1522
1523 be_sid[0] = sess->s_id.b.domain;
1524 be_sid[1] = sess->s_id.b.area;
1525 be_sid[2] = sess->s_id.b.al_pa;
1526
1527 tcm_qla2xxx_set_sess_by_s_id(lport, NULL, nacl, se_sess,
1528 sess, be_sid);
1529 tcm_qla2xxx_set_sess_by_loop_id(lport, NULL, nacl, se_sess,
1530 sess, sess->loop_id);
1531}
1532
75f8c1f6
NB
1533static void tcm_qla2xxx_free_session(struct qla_tgt_sess *sess)
1534{
1535 struct qla_tgt *tgt = sess->tgt;
1536 struct qla_hw_data *ha = tgt->ha;
0e8cd71c 1537 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
75f8c1f6
NB
1538 struct se_session *se_sess;
1539 struct se_node_acl *se_nacl;
1540 struct tcm_qla2xxx_lport *lport;
1541 struct tcm_qla2xxx_nacl *nacl;
75f8c1f6
NB
1542
1543 BUG_ON(in_interrupt());
1544
1545 se_sess = sess->se_sess;
1546 if (!se_sess) {
1547 pr_err("struct qla_tgt_sess->se_sess is NULL\n");
1548 dump_stack();
1549 return;
1550 }
1551 se_nacl = se_sess->se_node_acl;
1552 nacl = container_of(se_nacl, struct tcm_qla2xxx_nacl, se_node_acl);
1553
0e8cd71c 1554 lport = vha->vha_tgt.target_lport_ptr;
75f8c1f6
NB
1555 if (!lport) {
1556 pr_err("Unable to locate struct tcm_qla2xxx_lport\n");
1557 dump_stack();
1558 return;
1559 }
be646c2d 1560 target_wait_for_sess_cmds(se_sess);
75f8c1f6
NB
1561
1562 transport_deregister_session_configfs(sess->se_sess);
1563 transport_deregister_session(sess->se_sess);
1564}
1565
1566/*
1567 * Called via qlt_create_sess():ha->qla2x_tmpl->check_initiator_node_acl()
1568 * to locate struct se_node_acl
1569 */
1570static int tcm_qla2xxx_check_initiator_node_acl(
1571 scsi_qla_host_t *vha,
1572 unsigned char *fc_wwpn,
1573 void *qla_tgt_sess,
1574 uint8_t *s_id,
1575 uint16_t loop_id)
1576{
1577 struct qla_hw_data *ha = vha->hw;
1578 struct tcm_qla2xxx_lport *lport;
1579 struct tcm_qla2xxx_tpg *tpg;
1580 struct tcm_qla2xxx_nacl *nacl;
1581 struct se_portal_group *se_tpg;
1582 struct se_node_acl *se_nacl;
1583 struct se_session *se_sess;
1584 struct qla_tgt_sess *sess = qla_tgt_sess;
1585 unsigned char port_name[36];
1586 unsigned long flags;
51a07f84
NB
1587 int num_tags = (ha->fw_xcb_count) ? ha->fw_xcb_count :
1588 TCM_QLA2XXX_DEFAULT_TAGS;
75f8c1f6 1589
0e8cd71c 1590 lport = vha->vha_tgt.target_lport_ptr;
75f8c1f6
NB
1591 if (!lport) {
1592 pr_err("Unable to locate struct tcm_qla2xxx_lport\n");
1593 dump_stack();
1594 return -EINVAL;
1595 }
1596 /*
1597 * Locate the TPG=1 reference..
1598 */
1599 tpg = lport->tpg_1;
1600 if (!tpg) {
1601 pr_err("Unable to lcoate struct tcm_qla2xxx_lport->tpg_1\n");
1602 return -EINVAL;
1603 }
1604 se_tpg = &tpg->se_tpg;
1605
51a07f84
NB
1606 se_sess = transport_init_session_tags(num_tags,
1607 sizeof(struct qla_tgt_cmd),
59bb0ff5 1608 TARGET_PROT_ALL);
75f8c1f6
NB
1609 if (IS_ERR(se_sess)) {
1610 pr_err("Unable to initialize struct se_session\n");
1611 return PTR_ERR(se_sess);
1612 }
1613 /*
1614 * Format the FCP Initiator port_name into colon seperated values to
1615 * match the format by tcm_qla2xxx explict ConfigFS NodeACLs.
1616 */
1617 memset(&port_name, 0, 36);
3c9786e5 1618 snprintf(port_name, sizeof(port_name), "%8phC", fc_wwpn);
75f8c1f6
NB
1619 /*
1620 * Locate our struct se_node_acl either from an explict NodeACL created
1621 * via ConfigFS, or via running in TPG demo mode.
1622 */
1623 se_sess->se_node_acl = core_tpg_check_initiator_node_acl(se_tpg,
1624 port_name);
1625 if (!se_sess->se_node_acl) {
1626 transport_free_session(se_sess);
1627 return -EINVAL;
1628 }
1629 se_nacl = se_sess->se_node_acl;
1630 nacl = container_of(se_nacl, struct tcm_qla2xxx_nacl, se_node_acl);
1631 /*
1632 * And now setup the new se_nacl and session pointers into our HW lport
1633 * mappings for fabric S_ID and LOOP_ID.
1634 */
1635 spin_lock_irqsave(&ha->hardware_lock, flags);
1636 tcm_qla2xxx_set_sess_by_s_id(lport, se_nacl, nacl, se_sess,
1637 qla_tgt_sess, s_id);
1638 tcm_qla2xxx_set_sess_by_loop_id(lport, se_nacl, nacl, se_sess,
1639 qla_tgt_sess, loop_id);
1640 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1641 /*
1642 * Finally register the new FC Nexus with TCM
1643 */
75c3d0bf 1644 transport_register_session(se_nacl->se_tpg, se_nacl, se_sess, sess);
75f8c1f6
NB
1645
1646 return 0;
1647}
1648
c8292d1d
RD
1649static void tcm_qla2xxx_update_sess(struct qla_tgt_sess *sess, port_id_t s_id,
1650 uint16_t loop_id, bool conf_compl_supported)
1651{
1652 struct qla_tgt *tgt = sess->tgt;
1653 struct qla_hw_data *ha = tgt->ha;
0e8cd71c
SK
1654 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
1655 struct tcm_qla2xxx_lport *lport = vha->vha_tgt.target_lport_ptr;
c8292d1d
RD
1656 struct se_node_acl *se_nacl = sess->se_sess->se_node_acl;
1657 struct tcm_qla2xxx_nacl *nacl = container_of(se_nacl,
1658 struct tcm_qla2xxx_nacl, se_node_acl);
1659 u32 key;
1660
1661
1662 if (sess->loop_id != loop_id || sess->s_id.b24 != s_id.b24)
7b833558
OK
1663 pr_info("Updating session %p from port %8phC loop_id %d -> %d s_id %x:%x:%x -> %x:%x:%x\n",
1664 sess, sess->port_name,
1665 sess->loop_id, loop_id, sess->s_id.b.domain,
1666 sess->s_id.b.area, sess->s_id.b.al_pa, s_id.b.domain,
1667 s_id.b.area, s_id.b.al_pa);
c8292d1d
RD
1668
1669 if (sess->loop_id != loop_id) {
1670 /*
1671 * Because we can shuffle loop IDs around and we
1672 * update different sessions non-atomically, we might
1673 * have overwritten this session's old loop ID
1674 * already, and we might end up overwriting some other
1675 * session that will be updated later. So we have to
1676 * be extra careful and we can't warn about those things...
1677 */
1678 if (lport->lport_loopid_map[sess->loop_id].se_nacl == se_nacl)
1679 lport->lport_loopid_map[sess->loop_id].se_nacl = NULL;
1680
1681 lport->lport_loopid_map[loop_id].se_nacl = se_nacl;
1682
1683 sess->loop_id = loop_id;
1684 }
1685
1686 if (sess->s_id.b24 != s_id.b24) {
1687 key = (((u32) sess->s_id.b.domain << 16) |
1688 ((u32) sess->s_id.b.area << 8) |
1689 ((u32) sess->s_id.b.al_pa));
1690
1691 if (btree_lookup32(&lport->lport_fcport_map, key))
1692 WARN(btree_remove32(&lport->lport_fcport_map, key) != se_nacl,
1693 "Found wrong se_nacl when updating s_id %x:%x:%x\n",
1694 sess->s_id.b.domain, sess->s_id.b.area, sess->s_id.b.al_pa);
1695 else
1696 WARN(1, "No lport_fcport_map entry for s_id %x:%x:%x\n",
1697 sess->s_id.b.domain, sess->s_id.b.area, sess->s_id.b.al_pa);
1698
1699 key = (((u32) s_id.b.domain << 16) |
1700 ((u32) s_id.b.area << 8) |
1701 ((u32) s_id.b.al_pa));
1702
1703 if (btree_lookup32(&lport->lport_fcport_map, key)) {
1704 WARN(1, "Already have lport_fcport_map entry for s_id %x:%x:%x\n",
1705 s_id.b.domain, s_id.b.area, s_id.b.al_pa);
1706 btree_update32(&lport->lport_fcport_map, key, se_nacl);
1707 } else {
1708 btree_insert32(&lport->lport_fcport_map, key, se_nacl, GFP_ATOMIC);
1709 }
1710
1711 sess->s_id = s_id;
1712 nacl->nport_id = key;
1713 }
1714
1715 sess->conf_compl_supported = conf_compl_supported;
1716}
1717
75f8c1f6
NB
1718/*
1719 * Calls into tcm_qla2xxx used by qla2xxx LLD I/O path.
1720 */
1721static struct qla_tgt_func_tmpl tcm_qla2xxx_template = {
1722 .handle_cmd = tcm_qla2xxx_handle_cmd,
1723 .handle_data = tcm_qla2xxx_handle_data,
f83adb61 1724 .handle_dif_err = tcm_qla2xxx_handle_dif_err,
75f8c1f6
NB
1725 .handle_tmr = tcm_qla2xxx_handle_tmr,
1726 .free_cmd = tcm_qla2xxx_free_cmd,
1727 .free_mcmd = tcm_qla2xxx_free_mcmd,
1728 .free_session = tcm_qla2xxx_free_session,
c8292d1d 1729 .update_sess = tcm_qla2xxx_update_sess,
75f8c1f6
NB
1730 .check_initiator_node_acl = tcm_qla2xxx_check_initiator_node_acl,
1731 .find_sess_by_s_id = tcm_qla2xxx_find_sess_by_s_id,
1732 .find_sess_by_loop_id = tcm_qla2xxx_find_sess_by_loop_id,
1733 .clear_nacl_from_fcport_map = tcm_qla2xxx_clear_nacl_from_fcport_map,
1734 .put_sess = tcm_qla2xxx_put_sess,
1735 .shutdown_sess = tcm_qla2xxx_shutdown_sess,
1736};
1737
1738static int tcm_qla2xxx_init_lport(struct tcm_qla2xxx_lport *lport)
1739{
1740 int rc;
1741
1742 rc = btree_init32(&lport->lport_fcport_map);
1743 if (rc) {
1744 pr_err("Unable to initialize lport->lport_fcport_map btree\n");
1745 return rc;
1746 }
1747
1748 lport->lport_loopid_map = vmalloc(sizeof(struct tcm_qla2xxx_fc_loopid) *
1749 65536);
1750 if (!lport->lport_loopid_map) {
1751 pr_err("Unable to allocate lport->lport_loopid_map of %zu bytes\n",
1752 sizeof(struct tcm_qla2xxx_fc_loopid) * 65536);
1753 btree_destroy32(&lport->lport_fcport_map);
1754 return -ENOMEM;
1755 }
1756 memset(lport->lport_loopid_map, 0, sizeof(struct tcm_qla2xxx_fc_loopid)
1757 * 65536);
1758 pr_debug("qla2xxx: Allocated lport_loopid_map of %zu bytes\n",
1759 sizeof(struct tcm_qla2xxx_fc_loopid) * 65536);
1760 return 0;
1761}
1762
49a47f2c
NB
1763static int tcm_qla2xxx_lport_register_cb(struct scsi_qla_host *vha,
1764 void *target_lport_ptr,
1765 u64 npiv_wwpn, u64 npiv_wwnn)
75f8c1f6 1766{
49a47f2c
NB
1767 struct qla_hw_data *ha = vha->hw;
1768 struct tcm_qla2xxx_lport *lport =
1769 (struct tcm_qla2xxx_lport *)target_lport_ptr;
75f8c1f6 1770 /*
49a47f2c 1771 * Setup tgt_ops, local pointer to vha and target_lport_ptr
75f8c1f6 1772 */
49a47f2c
NB
1773 ha->tgt.tgt_ops = &tcm_qla2xxx_template;
1774 vha->vha_tgt.target_lport_ptr = target_lport_ptr;
75f8c1f6
NB
1775 lport->qla_vha = vha;
1776
1777 return 0;
1778}
1779
1780static struct se_wwn *tcm_qla2xxx_make_lport(
1781 struct target_fabric_configfs *tf,
1782 struct config_group *group,
1783 const char *name)
1784{
1785 struct tcm_qla2xxx_lport *lport;
1786 u64 wwpn;
1787 int ret = -ENODEV;
1788
1789 if (tcm_qla2xxx_parse_wwn(name, &wwpn, 1) < 0)
1790 return ERR_PTR(-EINVAL);
1791
1792 lport = kzalloc(sizeof(struct tcm_qla2xxx_lport), GFP_KERNEL);
1793 if (!lport) {
1794 pr_err("Unable to allocate struct tcm_qla2xxx_lport\n");
1795 return ERR_PTR(-ENOMEM);
1796 }
1797 lport->lport_wwpn = wwpn;
1798 tcm_qla2xxx_format_wwn(&lport->lport_name[0], TCM_QLA2XXX_NAMELEN,
1799 wwpn);
c046aa0f 1800 sprintf(lport->lport_naa_name, "naa.%016llx", (unsigned long long) wwpn);
75f8c1f6
NB
1801
1802 ret = tcm_qla2xxx_init_lport(lport);
1803 if (ret != 0)
1804 goto out;
1805
49a47f2c
NB
1806 ret = qlt_lport_register(lport, wwpn, 0, 0,
1807 tcm_qla2xxx_lport_register_cb);
75f8c1f6
NB
1808 if (ret != 0)
1809 goto out_lport;
1810
1811 return &lport->lport_wwn;
1812out_lport:
1813 vfree(lport->lport_loopid_map);
1814 btree_destroy32(&lport->lport_fcport_map);
1815out:
1816 kfree(lport);
1817 return ERR_PTR(ret);
1818}
1819
1820static void tcm_qla2xxx_drop_lport(struct se_wwn *wwn)
1821{
1822 struct tcm_qla2xxx_lport *lport = container_of(wwn,
1823 struct tcm_qla2xxx_lport, lport_wwn);
1824 struct scsi_qla_host *vha = lport->qla_vha;
75f8c1f6
NB
1825 struct se_node_acl *node;
1826 u32 key = 0;
1827
1828 /*
1829 * Call into qla2x_target.c LLD logic to complete the
1830 * shutdown of struct qla_tgt after the call to
1831 * qlt_stop_phase1() from tcm_qla2xxx_drop_tpg() above..
1832 */
0e8cd71c
SK
1833 if (vha->vha_tgt.qla_tgt && !vha->vha_tgt.qla_tgt->tgt_stopped)
1834 qlt_stop_phase2(vha->vha_tgt.qla_tgt);
75f8c1f6
NB
1835
1836 qlt_lport_deregister(vha);
1837
1838 vfree(lport->lport_loopid_map);
1839 btree_for_each_safe32(&lport->lport_fcport_map, key, node)
1840 btree_remove32(&lport->lport_fcport_map, key);
1841 btree_destroy32(&lport->lport_fcport_map);
1842 kfree(lport);
1843}
1844
49a47f2c
NB
1845static int tcm_qla2xxx_lport_register_npiv_cb(struct scsi_qla_host *base_vha,
1846 void *target_lport_ptr,
1847 u64 npiv_wwpn, u64 npiv_wwnn)
1848{
1849 struct fc_vport *vport;
1850 struct Scsi_Host *sh = base_vha->host;
1851 struct scsi_qla_host *npiv_vha;
1852 struct tcm_qla2xxx_lport *lport =
1853 (struct tcm_qla2xxx_lport *)target_lport_ptr;
7474f52a
NB
1854 struct tcm_qla2xxx_lport *base_lport =
1855 (struct tcm_qla2xxx_lport *)base_vha->vha_tgt.target_lport_ptr;
1856 struct tcm_qla2xxx_tpg *base_tpg;
49a47f2c
NB
1857 struct fc_vport_identifiers vport_id;
1858
1859 if (!qla_tgt_mode_enabled(base_vha)) {
1860 pr_err("qla2xxx base_vha not enabled for target mode\n");
1861 return -EPERM;
1862 }
1863
7474f52a
NB
1864 if (!base_lport || !base_lport->tpg_1 ||
1865 !atomic_read(&base_lport->tpg_1->lport_tpg_enabled)) {
1866 pr_err("qla2xxx base_lport or tpg_1 not available\n");
1867 return -EPERM;
1868 }
1869 base_tpg = base_lport->tpg_1;
1870
49a47f2c
NB
1871 memset(&vport_id, 0, sizeof(vport_id));
1872 vport_id.port_name = npiv_wwpn;
1873 vport_id.node_name = npiv_wwnn;
1874 vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR;
1875 vport_id.vport_type = FC_PORTTYPE_NPIV;
1876 vport_id.disable = false;
1877
1878 vport = fc_vport_create(sh, 0, &vport_id);
1879 if (!vport) {
1880 pr_err("fc_vport_create failed for qla2xxx_npiv\n");
1881 return -ENODEV;
1882 }
1883 /*
1884 * Setup local pointer to NPIV vhba + target_lport_ptr
1885 */
1886 npiv_vha = (struct scsi_qla_host *)vport->dd_data;
1887 npiv_vha->vha_tgt.target_lport_ptr = target_lport_ptr;
1888 lport->qla_vha = npiv_vha;
49a47f2c
NB
1889 scsi_host_get(npiv_vha->host);
1890 return 0;
1891}
1892
1893
75f8c1f6
NB
1894static struct se_wwn *tcm_qla2xxx_npiv_make_lport(
1895 struct target_fabric_configfs *tf,
1896 struct config_group *group,
1897 const char *name)
1898{
1899 struct tcm_qla2xxx_lport *lport;
49a47f2c
NB
1900 u64 phys_wwpn, npiv_wwpn, npiv_wwnn;
1901 char *p, tmp[128];
75f8c1f6
NB
1902 int ret;
1903
49a47f2c
NB
1904 snprintf(tmp, 128, "%s", name);
1905
1906 p = strchr(tmp, '@');
1907 if (!p) {
1908 pr_err("Unable to locate NPIV '@' seperator\n");
1909 return ERR_PTR(-EINVAL);
1910 }
1911 *p++ = '\0';
1912
1913 if (tcm_qla2xxx_parse_wwn(tmp, &phys_wwpn, 1) < 0)
1914 return ERR_PTR(-EINVAL);
1915
1916 if (tcm_qla2xxx_npiv_parse_wwn(p, strlen(p)+1,
1917 &npiv_wwpn, &npiv_wwnn) < 0)
75f8c1f6
NB
1918 return ERR_PTR(-EINVAL);
1919
1920 lport = kzalloc(sizeof(struct tcm_qla2xxx_lport), GFP_KERNEL);
1921 if (!lport) {
1922 pr_err("Unable to allocate struct tcm_qla2xxx_lport for NPIV\n");
1923 return ERR_PTR(-ENOMEM);
1924 }
1925 lport->lport_npiv_wwpn = npiv_wwpn;
1926 lport->lport_npiv_wwnn = npiv_wwnn;
c046aa0f 1927 sprintf(lport->lport_naa_name, "naa.%016llx", (unsigned long long) npiv_wwpn);
75f8c1f6 1928
0e8cd71c 1929 ret = tcm_qla2xxx_init_lport(lport);
75f8c1f6
NB
1930 if (ret != 0)
1931 goto out;
1932
49a47f2c
NB
1933 ret = qlt_lport_register(lport, phys_wwpn, npiv_wwpn, npiv_wwnn,
1934 tcm_qla2xxx_lport_register_npiv_cb);
0e8cd71c
SK
1935 if (ret != 0)
1936 goto out_lport;
1937
75f8c1f6 1938 return &lport->lport_wwn;
0e8cd71c
SK
1939out_lport:
1940 vfree(lport->lport_loopid_map);
1941 btree_destroy32(&lport->lport_fcport_map);
75f8c1f6
NB
1942out:
1943 kfree(lport);
1944 return ERR_PTR(ret);
1945}
1946
1947static void tcm_qla2xxx_npiv_drop_lport(struct se_wwn *wwn)
1948{
1949 struct tcm_qla2xxx_lport *lport = container_of(wwn,
1950 struct tcm_qla2xxx_lport, lport_wwn);
49a47f2c
NB
1951 struct scsi_qla_host *npiv_vha = lport->qla_vha;
1952 struct qla_hw_data *ha = npiv_vha->hw;
1953 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1954
1955 scsi_host_put(npiv_vha->host);
75f8c1f6 1956 /*
0e8cd71c 1957 * Notify libfc that we want to release the vha->fc_vport
75f8c1f6 1958 */
49a47f2c
NB
1959 fc_vport_terminate(npiv_vha->fc_vport);
1960 scsi_host_put(base_vha->host);
75f8c1f6
NB
1961 kfree(lport);
1962}
1963
1964
1965static ssize_t tcm_qla2xxx_wwn_show_attr_version(
1966 struct target_fabric_configfs *tf,
1967 char *page)
1968{
1969 return sprintf(page,
1970 "TCM QLOGIC QLA2XXX NPIV capable fabric module %s on %s/%s on "
1971 UTS_RELEASE"\n", TCM_QLA2XXX_VERSION, utsname()->sysname,
1972 utsname()->machine);
1973}
1974
1975TF_WWN_ATTR_RO(tcm_qla2xxx, version);
1976
1977static struct configfs_attribute *tcm_qla2xxx_wwn_attrs[] = {
1978 &tcm_qla2xxx_wwn_version.attr,
1979 NULL,
1980};
1981
9ac8928e
CH
1982static const struct target_core_fabric_ops tcm_qla2xxx_ops = {
1983 .module = THIS_MODULE,
1984 .name = "qla2xxx",
75f8c1f6
NB
1985 .get_fabric_name = tcm_qla2xxx_get_fabric_name,
1986 .get_fabric_proto_ident = tcm_qla2xxx_get_fabric_proto_ident,
1987 .tpg_get_wwn = tcm_qla2xxx_get_fabric_wwn,
1988 .tpg_get_tag = tcm_qla2xxx_get_tag,
75f8c1f6
NB
1989 .tpg_get_pr_transport_id = tcm_qla2xxx_get_pr_transport_id,
1990 .tpg_get_pr_transport_id_len = tcm_qla2xxx_get_pr_transport_id_len,
1991 .tpg_parse_pr_out_transport_id = tcm_qla2xxx_parse_pr_out_transport_id,
1992 .tpg_check_demo_mode = tcm_qla2xxx_check_demo_mode,
1993 .tpg_check_demo_mode_cache = tcm_qla2xxx_check_demo_mode_cache,
1994 .tpg_check_demo_mode_write_protect =
1995 tcm_qla2xxx_check_demo_write_protect,
1996 .tpg_check_prod_mode_write_protect =
1997 tcm_qla2xxx_check_prod_write_protect,
64b16887 1998 .tpg_check_prot_fabric_only = tcm_qla2xxx_check_prot_fabric_only,
de04a8aa 1999 .tpg_check_demo_mode_login_only = tcm_qla2xxx_check_demo_mode_login_only,
75f8c1f6
NB
2000 .tpg_alloc_fabric_acl = tcm_qla2xxx_alloc_fabric_acl,
2001 .tpg_release_fabric_acl = tcm_qla2xxx_release_fabric_acl,
2002 .tpg_get_inst_index = tcm_qla2xxx_tpg_get_inst_index,
75f8c1f6
NB
2003 .check_stop_free = tcm_qla2xxx_check_stop_free,
2004 .release_cmd = tcm_qla2xxx_release_cmd,
aaf68b75 2005 .put_session = tcm_qla2xxx_put_session,
75f8c1f6
NB
2006 .shutdown_session = tcm_qla2xxx_shutdown_session,
2007 .close_session = tcm_qla2xxx_close_session,
2008 .sess_get_index = tcm_qla2xxx_sess_get_index,
2009 .sess_get_initiator_sid = NULL,
2010 .write_pending = tcm_qla2xxx_write_pending,
2011 .write_pending_status = tcm_qla2xxx_write_pending_status,
2012 .set_default_node_attributes = tcm_qla2xxx_set_default_node_attrs,
2013 .get_task_tag = tcm_qla2xxx_get_task_tag,
2014 .get_cmd_state = tcm_qla2xxx_get_cmd_state,
2015 .queue_data_in = tcm_qla2xxx_queue_data_in,
2016 .queue_status = tcm_qla2xxx_queue_status,
2017 .queue_tm_rsp = tcm_qla2xxx_queue_tm_rsp,
131e6abc 2018 .aborted_task = tcm_qla2xxx_aborted_task,
75f8c1f6
NB
2019 /*
2020 * Setup function pointers for generic logic in
2021 * target_core_fabric_configfs.c
2022 */
2023 .fabric_make_wwn = tcm_qla2xxx_make_lport,
2024 .fabric_drop_wwn = tcm_qla2xxx_drop_lport,
2025 .fabric_make_tpg = tcm_qla2xxx_make_tpg,
2026 .fabric_drop_tpg = tcm_qla2xxx_drop_tpg,
2027 .fabric_post_link = NULL,
2028 .fabric_pre_unlink = NULL,
2029 .fabric_make_np = NULL,
2030 .fabric_drop_np = NULL,
2031 .fabric_make_nodeacl = tcm_qla2xxx_make_nodeacl,
2032 .fabric_drop_nodeacl = tcm_qla2xxx_drop_nodeacl,
9ac8928e
CH
2033
2034 .tfc_wwn_attrs = tcm_qla2xxx_wwn_attrs,
2035 .tfc_tpg_base_attrs = tcm_qla2xxx_tpg_attrs,
2036 .tfc_tpg_attrib_attrs = tcm_qla2xxx_tpg_attrib_attrs,
75f8c1f6
NB
2037};
2038
9ac8928e
CH
2039static const struct target_core_fabric_ops tcm_qla2xxx_npiv_ops = {
2040 .module = THIS_MODULE,
2041 .name = "qla2xxx_npiv",
75f8c1f6
NB
2042 .get_fabric_name = tcm_qla2xxx_npiv_get_fabric_name,
2043 .get_fabric_proto_ident = tcm_qla2xxx_get_fabric_proto_ident,
84197a36 2044 .tpg_get_wwn = tcm_qla2xxx_get_fabric_wwn,
75f8c1f6 2045 .tpg_get_tag = tcm_qla2xxx_get_tag,
75f8c1f6
NB
2046 .tpg_get_pr_transport_id = tcm_qla2xxx_get_pr_transport_id,
2047 .tpg_get_pr_transport_id_len = tcm_qla2xxx_get_pr_transport_id_len,
2048 .tpg_parse_pr_out_transport_id = tcm_qla2xxx_parse_pr_out_transport_id,
0e8cd71c
SK
2049 .tpg_check_demo_mode = tcm_qla2xxx_check_demo_mode,
2050 .tpg_check_demo_mode_cache = tcm_qla2xxx_check_demo_mode_cache,
2051 .tpg_check_demo_mode_write_protect = tcm_qla2xxx_check_demo_mode,
2052 .tpg_check_prod_mode_write_protect =
2053 tcm_qla2xxx_check_prod_write_protect,
de04a8aa 2054 .tpg_check_demo_mode_login_only = tcm_qla2xxx_check_demo_mode_login_only,
75f8c1f6
NB
2055 .tpg_alloc_fabric_acl = tcm_qla2xxx_alloc_fabric_acl,
2056 .tpg_release_fabric_acl = tcm_qla2xxx_release_fabric_acl,
2057 .tpg_get_inst_index = tcm_qla2xxx_tpg_get_inst_index,
0e8cd71c 2058 .check_stop_free = tcm_qla2xxx_check_stop_free,
75f8c1f6 2059 .release_cmd = tcm_qla2xxx_release_cmd,
aaf68b75 2060 .put_session = tcm_qla2xxx_put_session,
75f8c1f6
NB
2061 .shutdown_session = tcm_qla2xxx_shutdown_session,
2062 .close_session = tcm_qla2xxx_close_session,
2063 .sess_get_index = tcm_qla2xxx_sess_get_index,
2064 .sess_get_initiator_sid = NULL,
2065 .write_pending = tcm_qla2xxx_write_pending,
2066 .write_pending_status = tcm_qla2xxx_write_pending_status,
2067 .set_default_node_attributes = tcm_qla2xxx_set_default_node_attrs,
2068 .get_task_tag = tcm_qla2xxx_get_task_tag,
2069 .get_cmd_state = tcm_qla2xxx_get_cmd_state,
2070 .queue_data_in = tcm_qla2xxx_queue_data_in,
2071 .queue_status = tcm_qla2xxx_queue_status,
2072 .queue_tm_rsp = tcm_qla2xxx_queue_tm_rsp,
131e6abc 2073 .aborted_task = tcm_qla2xxx_aborted_task,
75f8c1f6
NB
2074 /*
2075 * Setup function pointers for generic logic in
2076 * target_core_fabric_configfs.c
2077 */
2078 .fabric_make_wwn = tcm_qla2xxx_npiv_make_lport,
2079 .fabric_drop_wwn = tcm_qla2xxx_npiv_drop_lport,
2080 .fabric_make_tpg = tcm_qla2xxx_npiv_make_tpg,
2081 .fabric_drop_tpg = tcm_qla2xxx_drop_tpg,
2082 .fabric_post_link = NULL,
2083 .fabric_pre_unlink = NULL,
2084 .fabric_make_np = NULL,
2085 .fabric_drop_np = NULL,
2086 .fabric_make_nodeacl = tcm_qla2xxx_make_nodeacl,
2087 .fabric_drop_nodeacl = tcm_qla2xxx_drop_nodeacl,
9ac8928e
CH
2088
2089 .tfc_wwn_attrs = tcm_qla2xxx_wwn_attrs,
2090 .tfc_tpg_base_attrs = tcm_qla2xxx_npiv_tpg_attrs,
75f8c1f6
NB
2091};
2092
2093static int tcm_qla2xxx_register_configfs(void)
2094{
75f8c1f6
NB
2095 int ret;
2096
2097 pr_debug("TCM QLOGIC QLA2XXX fabric module %s on %s/%s on "
2098 UTS_RELEASE"\n", TCM_QLA2XXX_VERSION, utsname()->sysname,
2099 utsname()->machine);
9ac8928e
CH
2100
2101 ret = target_register_template(&tcm_qla2xxx_ops);
2102 if (ret)
75f8c1f6 2103 return ret;
75f8c1f6 2104
9ac8928e
CH
2105 ret = target_register_template(&tcm_qla2xxx_npiv_ops);
2106 if (ret)
75f8c1f6 2107 goto out_fabric;
75f8c1f6
NB
2108
2109 tcm_qla2xxx_free_wq = alloc_workqueue("tcm_qla2xxx_free",
2110 WQ_MEM_RECLAIM, 0);
2111 if (!tcm_qla2xxx_free_wq) {
2112 ret = -ENOMEM;
2113 goto out_fabric_npiv;
2114 }
2115
2116 tcm_qla2xxx_cmd_wq = alloc_workqueue("tcm_qla2xxx_cmd", 0, 0);
2117 if (!tcm_qla2xxx_cmd_wq) {
2118 ret = -ENOMEM;
2119 goto out_free_wq;
2120 }
2121
2122 return 0;
2123
2124out_free_wq:
2125 destroy_workqueue(tcm_qla2xxx_free_wq);
2126out_fabric_npiv:
9ac8928e 2127 target_unregister_template(&tcm_qla2xxx_npiv_ops);
75f8c1f6 2128out_fabric:
9ac8928e 2129 target_unregister_template(&tcm_qla2xxx_ops);
75f8c1f6
NB
2130 return ret;
2131}
2132
2133static void tcm_qla2xxx_deregister_configfs(void)
2134{
2135 destroy_workqueue(tcm_qla2xxx_cmd_wq);
2136 destroy_workqueue(tcm_qla2xxx_free_wq);
2137
9ac8928e
CH
2138 target_unregister_template(&tcm_qla2xxx_ops);
2139 target_unregister_template(&tcm_qla2xxx_npiv_ops);
75f8c1f6
NB
2140}
2141
2142static int __init tcm_qla2xxx_init(void)
2143{
2144 int ret;
2145
2146 ret = tcm_qla2xxx_register_configfs();
2147 if (ret < 0)
2148 return ret;
2149
2150 return 0;
2151}
2152
2153static void __exit tcm_qla2xxx_exit(void)
2154{
2155 tcm_qla2xxx_deregister_configfs();
2156}
2157
2158MODULE_DESCRIPTION("TCM QLA2XXX series NPIV enabled fabric driver");
2159MODULE_LICENSE("GPL");
2160module_init(tcm_qla2xxx_init);
2161module_exit(tcm_qla2xxx_exit);