tcm_fc.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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.3"
  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. /*
  24. * Debug options.
  25. */
  26. #define FT_DEBUG_CONF 0x01 /* configuration messages */
  27. #define FT_DEBUG_SESS 0x02 /* session messages */
  28. #define FT_DEBUG_TM 0x04 /* TM operations */
  29. #define FT_DEBUG_IO 0x08 /* I/O commands */
  30. #define FT_DEBUG_DATA 0x10 /* Data transfer */
  31. extern unsigned int ft_debug_logging; /* debug options */
  32. #define FT_DEBUG(mask, fmt, args...) \
  33. do { \
  34. if (ft_debug_logging & (mask)) \
  35. printk(KERN_INFO "tcm_fc: %s: " fmt, \
  36. __func__, ##args); \
  37. } while (0)
  38. #define FT_CONF_DBG(fmt, args...) FT_DEBUG(FT_DEBUG_CONF, fmt, ##args)
  39. #define FT_SESS_DBG(fmt, args...) FT_DEBUG(FT_DEBUG_SESS, fmt, ##args)
  40. #define FT_TM_DBG(fmt, args...) FT_DEBUG(FT_DEBUG_TM, fmt, ##args)
  41. #define FT_IO_DBG(fmt, args...) FT_DEBUG(FT_DEBUG_IO, fmt, ##args)
  42. #define FT_DATA_DBG(fmt, args...) FT_DEBUG(FT_DEBUG_DATA, fmt, ##args)
  43. struct ft_transport_id {
  44. __u8 format;
  45. __u8 __resvd1[7];
  46. __u8 wwpn[8];
  47. __u8 __resvd2[8];
  48. } __attribute__((__packed__));
  49. /*
  50. * Session (remote port).
  51. */
  52. struct ft_sess {
  53. u32 port_id; /* for hash lookup use only */
  54. u32 params;
  55. u16 max_frame; /* maximum frame size */
  56. u64 port_name; /* port name for transport ID */
  57. struct ft_tport *tport;
  58. struct se_session *se_sess;
  59. struct hlist_node hash; /* linkage in ft_sess_hash table */
  60. struct rcu_head rcu;
  61. struct kref kref; /* ref for hash and outstanding I/Os */
  62. };
  63. /*
  64. * Hash table of sessions per local port.
  65. * Hash lookup by remote port FC_ID.
  66. */
  67. #define FT_SESS_HASH_BITS 6
  68. #define FT_SESS_HASH_SIZE (1 << FT_SESS_HASH_BITS)
  69. /*
  70. * Per local port data.
  71. * This is created only after a TPG exists that allows target function
  72. * for the local port. If the TPG exists, this is allocated when
  73. * we're notified that the local port has been created, or when
  74. * the first PRLI provider callback is received.
  75. */
  76. struct ft_tport {
  77. struct fc_lport *lport;
  78. struct ft_tpg *tpg; /* NULL if TPG deleted before tport */
  79. u32 sess_count; /* number of sessions in hash */
  80. struct rcu_head rcu;
  81. struct hlist_head hash[FT_SESS_HASH_SIZE]; /* list of sessions */
  82. };
  83. /*
  84. * Node ID and authentication.
  85. */
  86. struct ft_node_auth {
  87. u64 port_name;
  88. u64 node_name;
  89. };
  90. /*
  91. * Node ACL for FC remote port session.
  92. */
  93. struct ft_node_acl {
  94. struct ft_node_auth node_auth;
  95. struct se_node_acl se_node_acl;
  96. };
  97. struct ft_lun {
  98. u32 index;
  99. char name[FT_LUN_NAMELEN];
  100. };
  101. /*
  102. * Target portal group (local port).
  103. */
  104. struct ft_tpg {
  105. u32 index;
  106. struct ft_lport_acl *lport_acl;
  107. struct ft_tport *tport; /* active tport or NULL */
  108. struct list_head list; /* linkage in ft_lport_acl tpg_list */
  109. struct list_head lun_list; /* head of LUNs */
  110. struct se_portal_group se_tpg;
  111. struct task_struct *thread; /* processing thread */
  112. struct se_queue_obj qobj; /* queue for processing thread */
  113. };
  114. struct ft_lport_acl {
  115. u64 wwpn;
  116. char name[FT_NAMELEN];
  117. struct list_head list;
  118. struct list_head tpg_list;
  119. struct se_wwn fc_lport_wwn;
  120. };
  121. enum ft_cmd_state {
  122. FC_CMD_ST_NEW = 0,
  123. FC_CMD_ST_REJ
  124. };
  125. /*
  126. * Commands
  127. */
  128. struct ft_cmd {
  129. enum ft_cmd_state state;
  130. u16 lun; /* LUN from request */
  131. struct ft_sess *sess; /* session held for cmd */
  132. struct fc_seq *seq; /* sequence in exchange mgr */
  133. struct se_cmd se_cmd; /* Local TCM I/O descriptor */
  134. struct fc_frame *req_frame;
  135. unsigned char *cdb; /* pointer to CDB inside frame */
  136. u32 write_data_len; /* data received on writes */
  137. struct se_queue_req se_req;
  138. /* Local sense buffer */
  139. unsigned char ft_sense_buffer[TRANSPORT_SENSE_BUFFER];
  140. u32 was_ddp_setup:1; /* Set only if ddp is setup */
  141. struct scatterlist *sg; /* Set only if DDP is setup */
  142. u32 sg_cnt; /* No. of item in scatterlist */
  143. };
  144. extern struct list_head ft_lport_list;
  145. extern struct mutex ft_lport_lock;
  146. extern struct fc4_prov ft_prov;
  147. extern struct target_fabric_configfs *ft_configfs;
  148. /*
  149. * Fabric methods.
  150. */
  151. /*
  152. * Session ops.
  153. */
  154. void ft_sess_put(struct ft_sess *);
  155. int ft_sess_shutdown(struct se_session *);
  156. void ft_sess_close(struct se_session *);
  157. void ft_sess_stop(struct se_session *, int, int);
  158. int ft_sess_logged_in(struct se_session *);
  159. u32 ft_sess_get_index(struct se_session *);
  160. u32 ft_sess_get_port_name(struct se_session *, unsigned char *, u32);
  161. void ft_sess_set_erl0(struct se_session *);
  162. void ft_lport_add(struct fc_lport *, void *);
  163. void ft_lport_del(struct fc_lport *, void *);
  164. int ft_lport_notify(struct notifier_block *, unsigned long, void *);
  165. /*
  166. * IO methods.
  167. */
  168. void ft_check_stop_free(struct se_cmd *);
  169. void ft_release_cmd(struct se_cmd *);
  170. int ft_queue_status(struct se_cmd *);
  171. int ft_queue_data_in(struct se_cmd *);
  172. int ft_write_pending(struct se_cmd *);
  173. int ft_write_pending_status(struct se_cmd *);
  174. u32 ft_get_task_tag(struct se_cmd *);
  175. int ft_get_cmd_state(struct se_cmd *);
  176. void ft_new_cmd_failure(struct se_cmd *);
  177. int ft_queue_tm_resp(struct se_cmd *);
  178. int ft_is_state_remove(struct se_cmd *);
  179. /*
  180. * other internal functions.
  181. */
  182. int ft_thread(void *);
  183. void ft_recv_req(struct ft_sess *, struct fc_frame *);
  184. struct ft_tpg *ft_lport_find_tpg(struct fc_lport *);
  185. struct ft_node_acl *ft_acl_get(struct ft_tpg *, struct fc_rport_priv *);
  186. void ft_recv_write_data(struct ft_cmd *, struct fc_frame *);
  187. void ft_dump_cmd(struct ft_cmd *, const char *caller);
  188. ssize_t ft_format_wwn(char *, size_t, u64);
  189. #endif /* __TCM_FC_H__ */