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