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