tcm_fc.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. * Copyright (c) 2010 Cisco Systems, Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along with
  14. * this program; if not, write to the Free Software Foundation, Inc.,
  15. * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  16. */
  17. #ifndef __TCM_FC_H__
  18. #define __TCM_FC_H__
  19. #define FT_VERSION "0.4"
  20. #define FT_NAMELEN 32 /* length of ASCII WWPNs including pad */
  21. #define FT_TPG_NAMELEN 32 /* max length of TPG name */
  22. #define FT_LUN_NAMELEN 32 /* max length of LUN name */
  23. struct ft_transport_id {
  24. __u8 format;
  25. __u8 __resvd1[7];
  26. __u8 wwpn[8];
  27. __u8 __resvd2[8];
  28. } __attribute__((__packed__));
  29. /*
  30. * Session (remote port).
  31. */
  32. struct ft_sess {
  33. u32 port_id; /* for hash lookup use only */
  34. u32 params;
  35. u16 max_frame; /* maximum frame size */
  36. u64 port_name; /* port name for transport ID */
  37. struct ft_tport *tport;
  38. struct se_session *se_sess;
  39. struct hlist_node hash; /* linkage in ft_sess_hash table */
  40. struct rcu_head rcu;
  41. struct kref kref; /* ref for hash and outstanding I/Os */
  42. };
  43. /*
  44. * Hash table of sessions per local port.
  45. * Hash lookup by remote port FC_ID.
  46. */
  47. #define FT_SESS_HASH_BITS 6
  48. #define FT_SESS_HASH_SIZE (1 << FT_SESS_HASH_BITS)
  49. /*
  50. * Per local port data.
  51. * This is created only after a TPG exists that allows target function
  52. * for the local port. If the TPG exists, this is allocated when
  53. * we're notified that the local port has been created, or when
  54. * the first PRLI provider callback is received.
  55. */
  56. struct ft_tport {
  57. struct fc_lport *lport;
  58. struct ft_tpg *tpg; /* NULL if TPG deleted before tport */
  59. u32 sess_count; /* number of sessions in hash */
  60. struct rcu_head rcu;
  61. struct hlist_head hash[FT_SESS_HASH_SIZE]; /* list of sessions */
  62. };
  63. /*
  64. * Node ID and authentication.
  65. */
  66. struct ft_node_auth {
  67. u64 port_name;
  68. u64 node_name;
  69. };
  70. /*
  71. * Node ACL for FC remote port session.
  72. */
  73. struct ft_node_acl {
  74. struct ft_node_auth node_auth;
  75. struct se_node_acl se_node_acl;
  76. };
  77. struct ft_lun {
  78. u32 index;
  79. char name[FT_LUN_NAMELEN];
  80. };
  81. /*
  82. * Target portal group (local port).
  83. */
  84. struct ft_tpg {
  85. u32 index;
  86. struct ft_lport_acl *lport_acl;
  87. struct ft_tport *tport; /* active tport or NULL */
  88. struct list_head list; /* linkage in ft_lport_acl tpg_list */
  89. struct list_head lun_list; /* head of LUNs */
  90. struct se_portal_group se_tpg;
  91. struct workqueue_struct *workqueue;
  92. };
  93. struct ft_lport_acl {
  94. u64 wwpn;
  95. char name[FT_NAMELEN];
  96. struct list_head list;
  97. struct list_head tpg_list;
  98. struct se_wwn fc_lport_wwn;
  99. };
  100. /*
  101. * Commands
  102. */
  103. struct ft_cmd {
  104. struct ft_sess *sess; /* session held for cmd */
  105. struct fc_seq *seq; /* sequence in exchange mgr */
  106. struct se_cmd se_cmd; /* Local TCM I/O descriptor */
  107. struct fc_frame *req_frame;
  108. u32 write_data_len; /* data received on writes */
  109. struct work_struct work;
  110. /* Local sense buffer */
  111. unsigned char ft_sense_buffer[TRANSPORT_SENSE_BUFFER];
  112. u32 was_ddp_setup:1; /* Set only if ddp is setup */
  113. u32 aborted:1; /* Set if aborted by reset or timeout */
  114. struct scatterlist *sg; /* Set only if DDP is setup */
  115. u32 sg_cnt; /* No. of item in scatterlist */
  116. };
  117. extern struct list_head ft_lport_list;
  118. extern struct mutex ft_lport_lock;
  119. extern struct fc4_prov ft_prov;
  120. extern struct target_fabric_configfs *ft_configfs;
  121. /*
  122. * Fabric methods.
  123. */
  124. /*
  125. * Session ops.
  126. */
  127. void ft_sess_put(struct ft_sess *);
  128. int ft_sess_shutdown(struct se_session *);
  129. void ft_sess_close(struct se_session *);
  130. u32 ft_sess_get_index(struct se_session *);
  131. u32 ft_sess_get_port_name(struct se_session *, unsigned char *, u32);
  132. void ft_lport_add(struct fc_lport *, void *);
  133. void ft_lport_del(struct fc_lport *, void *);
  134. int ft_lport_notify(struct notifier_block *, unsigned long, void *);
  135. /*
  136. * IO methods.
  137. */
  138. int ft_check_stop_free(struct se_cmd *);
  139. void ft_release_cmd(struct se_cmd *);
  140. int ft_queue_status(struct se_cmd *);
  141. int ft_queue_data_in(struct se_cmd *);
  142. int ft_write_pending(struct se_cmd *);
  143. int ft_write_pending_status(struct se_cmd *);
  144. u32 ft_get_task_tag(struct se_cmd *);
  145. int ft_get_cmd_state(struct se_cmd *);
  146. int ft_queue_tm_resp(struct se_cmd *);
  147. /*
  148. * other internal functions.
  149. */
  150. void ft_recv_req(struct ft_sess *, struct fc_frame *);
  151. struct ft_tpg *ft_lport_find_tpg(struct fc_lport *);
  152. struct ft_node_acl *ft_acl_get(struct ft_tpg *, struct fc_rport_priv *);
  153. void ft_recv_write_data(struct ft_cmd *, struct fc_frame *);
  154. void ft_dump_cmd(struct ft_cmd *, const char *caller);
  155. ssize_t ft_format_wwn(char *, size_t, u64);
  156. /*
  157. * Underlying HW specific helper function
  158. */
  159. void ft_invl_hw_context(struct ft_cmd *);
  160. #endif /* __TCM_FC_H__ */