tcm_fc.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2010 Cisco Systems, Inc.
  4. */
  5. #ifndef __TCM_FC_H__
  6. #define __TCM_FC_H__
  7. #include <linux/types.h>
  8. #include <target/target_core_base.h>
  9. #define FT_VERSION "0.4"
  10. #define FT_NAMELEN 32 /* length of ASCII WWPNs including pad */
  11. #define FT_TPG_NAMELEN 32 /* max length of TPG name */
  12. #define FT_LUN_NAMELEN 32 /* max length of LUN name */
  13. #define TCM_FC_DEFAULT_TAGS 512 /* tags used for per-session preallocation */
  14. struct ft_transport_id {
  15. __u8 format;
  16. __u8 __resvd1[7];
  17. __u8 wwpn[8];
  18. __u8 __resvd2[8];
  19. } __attribute__((__packed__));
  20. /*
  21. * Session (remote port).
  22. */
  23. struct ft_sess {
  24. u32 port_id; /* for hash lookup use only */
  25. u32 params;
  26. u16 max_frame; /* maximum frame size */
  27. u64 port_name; /* port name for transport ID */
  28. struct ft_tport *tport;
  29. struct se_session *se_sess;
  30. struct hlist_node hash; /* linkage in ft_sess_hash table */
  31. struct rcu_head rcu;
  32. struct kref kref; /* ref for hash and outstanding I/Os */
  33. };
  34. /*
  35. * Hash table of sessions per local port.
  36. * Hash lookup by remote port FC_ID.
  37. */
  38. #define FT_SESS_HASH_BITS 6
  39. #define FT_SESS_HASH_SIZE (1 << FT_SESS_HASH_BITS)
  40. /*
  41. * Per local port data.
  42. * This is created only after a TPG exists that allows target function
  43. * for the local port. If the TPG exists, this is allocated when
  44. * we're notified that the local port has been created, or when
  45. * the first PRLI provider callback is received.
  46. */
  47. struct ft_tport {
  48. struct fc_lport *lport;
  49. struct ft_tpg *tpg; /* NULL if TPG deleted before tport */
  50. u32 sess_count; /* number of sessions in hash */
  51. struct rcu_head rcu;
  52. struct hlist_head hash[FT_SESS_HASH_SIZE]; /* list of sessions */
  53. };
  54. /*
  55. * Node ID and authentication.
  56. */
  57. struct ft_node_auth {
  58. u64 port_name;
  59. u64 node_name;
  60. };
  61. /*
  62. * Node ACL for FC remote port session.
  63. */
  64. struct ft_node_acl {
  65. struct se_node_acl se_node_acl;
  66. struct ft_node_auth node_auth;
  67. };
  68. struct ft_lun {
  69. u32 index;
  70. char name[FT_LUN_NAMELEN];
  71. };
  72. /*
  73. * Target portal group (local port).
  74. */
  75. struct ft_tpg {
  76. u32 index;
  77. struct ft_lport_wwn *lport_wwn;
  78. struct ft_tport *tport; /* active tport or NULL */
  79. struct list_head lun_list; /* head of LUNs */
  80. struct se_portal_group se_tpg;
  81. struct workqueue_struct *workqueue;
  82. };
  83. struct ft_lport_wwn {
  84. u64 wwpn;
  85. char name[FT_NAMELEN];
  86. struct list_head ft_wwn_node;
  87. struct ft_tpg *tpg;
  88. struct se_wwn se_wwn;
  89. };
  90. /*
  91. * Commands
  92. */
  93. struct ft_cmd {
  94. struct ft_sess *sess; /* session held for cmd */
  95. struct fc_seq *seq; /* sequence in exchange mgr */
  96. struct se_cmd se_cmd; /* Local TCM I/O descriptor */
  97. struct fc_frame *req_frame;
  98. u32 write_data_len; /* data received on writes */
  99. struct work_struct work;
  100. /* Local sense buffer */
  101. unsigned char ft_sense_buffer[TRANSPORT_SENSE_BUFFER];
  102. u32 was_ddp_setup:1; /* Set only if ddp is setup */
  103. u32 aborted:1; /* Set if aborted by reset or timeout */
  104. struct scatterlist *sg; /* Set only if DDP is setup */
  105. u32 sg_cnt; /* No. of item in scatterlist */
  106. };
  107. extern struct mutex ft_lport_lock;
  108. extern struct fc4_prov ft_prov;
  109. extern unsigned int ft_debug_logging;
  110. /*
  111. * Fabric methods.
  112. */
  113. /*
  114. * Session ops.
  115. */
  116. void ft_sess_put(struct ft_sess *);
  117. void ft_sess_close(struct se_session *);
  118. u32 ft_sess_get_index(struct se_session *);
  119. u32 ft_sess_get_port_name(struct se_session *, unsigned char *, u32);
  120. void ft_lport_add(struct fc_lport *, void *);
  121. void ft_lport_del(struct fc_lport *, void *);
  122. int ft_lport_notify(struct notifier_block *, unsigned long, void *);
  123. /*
  124. * IO methods.
  125. */
  126. int ft_check_stop_free(struct se_cmd *);
  127. void ft_release_cmd(struct se_cmd *);
  128. int ft_queue_status(struct se_cmd *);
  129. int ft_queue_data_in(struct se_cmd *);
  130. int ft_write_pending(struct se_cmd *);
  131. int ft_get_cmd_state(struct se_cmd *);
  132. void ft_queue_tm_resp(struct se_cmd *);
  133. void ft_aborted_task(struct se_cmd *);
  134. /*
  135. * other internal functions.
  136. */
  137. void ft_recv_req(struct ft_sess *, struct fc_frame *);
  138. struct ft_tpg *ft_lport_find_tpg(struct fc_lport *);
  139. void ft_recv_write_data(struct ft_cmd *, struct fc_frame *);
  140. void ft_dump_cmd(struct ft_cmd *, const char *caller);
  141. ssize_t ft_format_wwn(char *, size_t, u64);
  142. /*
  143. * Underlying HW specific helper function
  144. */
  145. void ft_invl_hw_context(struct ft_cmd *);
  146. #endif /* __TCM_FC_H__ */