^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright(c) 2009 Intel Corporation. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Maintained at www.Open-FCoE.org
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/scatterlist.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/crc32.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <scsi/libfc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <scsi/fc_encode.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "fc_libfc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) MODULE_AUTHOR("Open-FCoE.org");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) MODULE_DESCRIPTION("libfc");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) unsigned int fc_debug_logging;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) module_param_named(debug_logging, fc_debug_logging, int, S_IRUGO|S_IWUSR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) MODULE_PARM_DESC(debug_logging, "a bit mask of logging levels");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) DEFINE_MUTEX(fc_prov_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) static LIST_HEAD(fc_local_ports);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct blocking_notifier_head fc_lport_notifier_head =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) BLOCKING_NOTIFIER_INIT(fc_lport_notifier_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) EXPORT_SYMBOL(fc_lport_notifier_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * Providers which primarily send requests and PRLIs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct fc4_prov *fc_active_prov[FC_FC4_PROV_SIZE] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) [0] = &fc_rport_t0_prov,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) [FC_TYPE_FCP] = &fc_rport_fcp_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * Providers which receive requests.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct fc4_prov *fc_passive_prov[FC_FC4_PROV_SIZE] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) [FC_TYPE_ELS] = &fc_lport_els_prov,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * libfc_init() - Initialize libfc.ko
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) static int __init libfc_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) rc = fc_setup_fcp();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) rc = fc_setup_exch_mgr();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) goto destroy_pkt_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) rc = fc_setup_rport();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) goto destroy_em;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) destroy_em:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) fc_destroy_exch_mgr();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) destroy_pkt_cache:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) fc_destroy_fcp();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) module_init(libfc_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * libfc_exit() - Tear down libfc.ko
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) static void __exit libfc_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) fc_destroy_fcp();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) fc_destroy_exch_mgr();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) fc_destroy_rport();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) module_exit(libfc_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * fc_copy_buffer_to_sglist() - This routine copies the data of a buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * into a scatter-gather list (SG list).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * @buf: pointer to the data buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * @len: the byte-length of the data buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * @sg: pointer to the pointer of the SG list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * @nents: pointer to the remaining number of entries in the SG list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * @offset: pointer to the current offset in the SG list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) * @crc: pointer to the 32-bit crc value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * If crc is NULL, CRC is not calculated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) u32 fc_copy_buffer_to_sglist(void *buf, size_t len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) struct scatterlist *sg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) u32 *nents, size_t *offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) u32 *crc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) size_t remaining = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) u32 copy_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) while (remaining > 0 && sg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) size_t off, sg_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) void *page_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) if (*offset >= sg->length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * Check for end and drop resources
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * from the last iteration.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) if (!(*nents))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) --(*nents);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) *offset -= sg->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) sg = sg_next(sg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) sg_bytes = min(remaining, sg->length - *offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * The scatterlist item may be bigger than PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) * but we are limited to mapping PAGE_SIZE at a time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) off = *offset + sg->offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) sg_bytes = min(sg_bytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) (size_t)(PAGE_SIZE - (off & ~PAGE_MASK)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) page_addr = kmap_atomic(sg_page(sg) + (off >> PAGE_SHIFT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) if (crc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) *crc = crc32(*crc, buf, sg_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) memcpy((char *)page_addr + (off & ~PAGE_MASK), buf, sg_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) kunmap_atomic(page_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) buf += sg_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) *offset += sg_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) remaining -= sg_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) copy_len += sg_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) return copy_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) * fc_fill_hdr() - fill FC header fields based on request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) * @fp: reply frame containing header to be filled in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) * @in_fp: request frame containing header to use in filling in reply
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) * @r_ctl: R_CTL value for header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) * @f_ctl: F_CTL value for header, with 0 pad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * @seq_cnt: sequence count for the header, ignored if frame has a sequence
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) * @parm_offset: parameter / offset value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) void fc_fill_hdr(struct fc_frame *fp, const struct fc_frame *in_fp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) enum fc_rctl r_ctl, u32 f_ctl, u16 seq_cnt, u32 parm_offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) struct fc_frame_header *fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) struct fc_frame_header *in_fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) struct fc_seq *sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) u32 fill;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) fh = __fc_frame_header_get(fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) in_fh = __fc_frame_header_get(in_fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) if (f_ctl & FC_FC_END_SEQ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) fill = -fr_len(fp) & 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) if (fill) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) /* TODO, this may be a problem with fragmented skb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) skb_put_zero(fp_skb(fp), fill);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) f_ctl |= fill;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) fr_eof(fp) = FC_EOF_T;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) WARN_ON(fr_len(fp) % 4 != 0); /* no pad to non last frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) fr_eof(fp) = FC_EOF_N;
^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) fh->fh_r_ctl = r_ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) memcpy(fh->fh_d_id, in_fh->fh_s_id, sizeof(fh->fh_d_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) memcpy(fh->fh_s_id, in_fh->fh_d_id, sizeof(fh->fh_s_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) fh->fh_type = in_fh->fh_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) hton24(fh->fh_f_ctl, f_ctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) fh->fh_ox_id = in_fh->fh_ox_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) fh->fh_rx_id = in_fh->fh_rx_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) fh->fh_cs_ctl = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) fh->fh_df_ctl = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) fh->fh_parm_offset = htonl(parm_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) sp = fr_seq(in_fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) if (sp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) fr_seq(fp) = sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) fh->fh_seq_id = sp->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) seq_cnt = sp->cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) fh->fh_seq_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) fh->fh_seq_cnt = ntohs(seq_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) fr_sof(fp) = seq_cnt ? FC_SOF_N3 : FC_SOF_I3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) fr_encaps(fp) = fr_encaps(in_fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) EXPORT_SYMBOL(fc_fill_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) * fc_fill_reply_hdr() - fill FC reply header fields based on request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) * @fp: reply frame containing header to be filled in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) * @in_fp: request frame containing header to use in filling in reply
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) * @r_ctl: R_CTL value for reply
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) * @parm_offset: parameter / offset value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) void fc_fill_reply_hdr(struct fc_frame *fp, const struct fc_frame *in_fp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) enum fc_rctl r_ctl, u32 parm_offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) struct fc_seq *sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) sp = fr_seq(in_fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) if (sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) fr_seq(fp) = fc_seq_start_next(sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) fc_fill_hdr(fp, in_fp, r_ctl, FC_FCTL_RESP, 0, parm_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) EXPORT_SYMBOL(fc_fill_reply_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) * fc_fc4_conf_lport_params() - Modify "service_params" of specified lport
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * if there is service provider (target provider) registered with libfc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * for specified "fc_ft_type"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) * @lport: Local port which service_params needs to be modified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) * @type: FC-4 type, such as FC_TYPE_FCP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) void fc_fc4_conf_lport_params(struct fc_lport *lport, enum fc_fh_type type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) struct fc4_prov *prov_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) BUG_ON(type >= FC_FC4_PROV_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) BUG_ON(!lport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) prov_entry = fc_passive_prov[type];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) if (type == FC_TYPE_FCP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) if (prov_entry && prov_entry->recv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) lport->service_params |= FCP_SPPF_TARG_FCN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) void fc_lport_iterate(void (*notify)(struct fc_lport *, void *), void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) struct fc_lport *lport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) mutex_lock(&fc_prov_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) list_for_each_entry(lport, &fc_local_ports, lport_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) notify(lport, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) mutex_unlock(&fc_prov_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) EXPORT_SYMBOL(fc_lport_iterate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) * fc_fc4_register_provider() - register FC-4 upper-level provider.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) * @type: FC-4 type, such as FC_TYPE_FCP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) * @prov: structure describing provider including ops vector.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) * Returns 0 on success, negative error otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) int fc_fc4_register_provider(enum fc_fh_type type, struct fc4_prov *prov)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) struct fc4_prov **prov_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) if (type >= FC_FC4_PROV_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) mutex_lock(&fc_prov_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) prov_entry = (prov->recv ? fc_passive_prov : fc_active_prov) + type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) if (*prov_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) ret = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) *prov_entry = prov;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) mutex_unlock(&fc_prov_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) EXPORT_SYMBOL(fc_fc4_register_provider);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) * fc_fc4_deregister_provider() - deregister FC-4 upper-level provider.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) * @type: FC-4 type, such as FC_TYPE_FCP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) * @prov: structure describing provider including ops vector.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) void fc_fc4_deregister_provider(enum fc_fh_type type, struct fc4_prov *prov)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) BUG_ON(type >= FC_FC4_PROV_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) mutex_lock(&fc_prov_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) if (prov->recv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) RCU_INIT_POINTER(fc_passive_prov[type], NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) RCU_INIT_POINTER(fc_active_prov[type], NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) mutex_unlock(&fc_prov_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) synchronize_rcu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) EXPORT_SYMBOL(fc_fc4_deregister_provider);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) * fc_fc4_add_lport() - add new local port to list and run notifiers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) * @lport: The new local port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) void fc_fc4_add_lport(struct fc_lport *lport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) mutex_lock(&fc_prov_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) list_add_tail(&lport->lport_list, &fc_local_ports);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) blocking_notifier_call_chain(&fc_lport_notifier_head,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) FC_LPORT_EV_ADD, lport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) mutex_unlock(&fc_prov_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) * fc_fc4_del_lport() - remove local port from list and run notifiers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) * @lport: The new local port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) void fc_fc4_del_lport(struct fc_lport *lport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) mutex_lock(&fc_prov_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) list_del(&lport->lport_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) blocking_notifier_call_chain(&fc_lport_notifier_head,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) FC_LPORT_EV_DEL, lport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) mutex_unlock(&fc_prov_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }