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