cxgb3i_offload.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /*
  2. * cxgb3i_offload.h: Chelsio S3xx iscsi offloaded tcp connection management
  3. *
  4. * Copyright (C) 2003-2008 Chelsio Communications. All rights reserved.
  5. *
  6. * This program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  8. * FITNESS FOR A PARTICULAR PURPOSE. See the LICENSE file included in this
  9. * release for licensing terms and conditions.
  10. *
  11. * Written by: Dimitris Michailidis (dm@chelsio.com)
  12. * Karen Xie (kxie@chelsio.com)
  13. */
  14. #ifndef _CXGB3I_OFFLOAD_H
  15. #define _CXGB3I_OFFLOAD_H
  16. #include <linux/skbuff.h>
  17. #include <linux/in.h>
  18. #include "common.h"
  19. #include "adapter.h"
  20. #include "t3cdev.h"
  21. #include "cxgb3_offload.h"
  22. #define cxgb3i_log_error(fmt...) printk(KERN_ERR "cxgb3i: ERR! " fmt)
  23. #define cxgb3i_log_warn(fmt...) printk(KERN_WARNING "cxgb3i: WARN! " fmt)
  24. #define cxgb3i_log_info(fmt...) printk(KERN_INFO "cxgb3i: " fmt)
  25. #define cxgb3i_log_debug(fmt, args...) \
  26. printk(KERN_INFO "cxgb3i: %s - " fmt, __func__ , ## args)
  27. /**
  28. * struct s3_conn - an iscsi tcp connection structure
  29. *
  30. * @dev: net device of with connection
  31. * @cdev: adapter t3cdev for net device
  32. * @flags: see c3cn_flags below
  33. * @tid: connection id assigned by the h/w
  34. * @qset: queue set used by connection
  35. * @mss_idx: Maximum Segment Size table index
  36. * @l2t: ARP resolution entry for offload packets
  37. * @wr_max: maximum in-flight writes
  38. * @wr_avail: number of writes available
  39. * @wr_unacked: writes since last request for completion notification
  40. * @wr_pending_head: head of pending write queue
  41. * @wr_pending_tail: tail of pending write queue
  42. * @cpl_close: skb for cpl_close_req
  43. * @cpl_abort_req: skb for cpl_abort_req
  44. * @cpl_abort_rpl: skb for cpl_abort_rpl
  45. * @lock: connection status lock
  46. * @refcnt: reference count on connection
  47. * @state: connection state
  48. * @saddr: source ip/port address
  49. * @daddr: destination ip/port address
  50. * @dst_cache: reference to destination route
  51. * @receive_queue: received PDUs
  52. * @write_queue: un-pushed pending writes
  53. * @retry_timer: retry timer for various operations
  54. * @err: connection error status
  55. * @callback_lock: lock for opaque user context
  56. * @user_data: opaque user context
  57. * @rcv_nxt: next receive seq. #
  58. * @copied_seq: head of yet unread data
  59. * @rcv_wup: rcv_nxt on last window update sent
  60. * @snd_nxt: next sequence we send
  61. * @snd_una: first byte we want an ack for
  62. * @write_seq: tail+1 of data held in send buffer
  63. */
  64. struct s3_conn {
  65. struct net_device *dev;
  66. struct t3cdev *cdev;
  67. unsigned long flags;
  68. int tid;
  69. int qset;
  70. int mss_idx;
  71. struct l2t_entry *l2t;
  72. int wr_max;
  73. int wr_avail;
  74. int wr_unacked;
  75. struct sk_buff *wr_pending_head;
  76. struct sk_buff *wr_pending_tail;
  77. struct sk_buff *cpl_close;
  78. struct sk_buff *cpl_abort_req;
  79. struct sk_buff *cpl_abort_rpl;
  80. spinlock_t lock;
  81. atomic_t refcnt;
  82. volatile unsigned int state;
  83. struct sockaddr_in saddr;
  84. struct sockaddr_in daddr;
  85. struct dst_entry *dst_cache;
  86. struct sk_buff_head receive_queue;
  87. struct sk_buff_head write_queue;
  88. struct timer_list retry_timer;
  89. int err;
  90. rwlock_t callback_lock;
  91. void *user_data;
  92. u32 rcv_nxt;
  93. u32 copied_seq;
  94. u32 rcv_wup;
  95. u32 snd_nxt;
  96. u32 snd_una;
  97. u32 write_seq;
  98. };
  99. /*
  100. * connection state
  101. */
  102. enum conn_states {
  103. C3CN_STATE_CONNECTING = 1,
  104. C3CN_STATE_ESTABLISHED,
  105. C3CN_STATE_ACTIVE_CLOSE,
  106. C3CN_STATE_PASSIVE_CLOSE,
  107. C3CN_STATE_CLOSE_WAIT_1,
  108. C3CN_STATE_CLOSE_WAIT_2,
  109. C3CN_STATE_ABORTING,
  110. C3CN_STATE_CLOSED,
  111. };
  112. static inline unsigned int c3cn_is_closing(const struct s3_conn *c3cn)
  113. {
  114. return c3cn->state >= C3CN_STATE_ACTIVE_CLOSE;
  115. }
  116. static inline unsigned int c3cn_is_established(const struct s3_conn *c3cn)
  117. {
  118. return c3cn->state == C3CN_STATE_ESTABLISHED;
  119. }
  120. /*
  121. * Connection flags -- many to track some close related events.
  122. */
  123. enum c3cn_flags {
  124. C3CN_ABORT_RPL_RCVD, /* received one ABORT_RPL_RSS message */
  125. C3CN_ABORT_REQ_RCVD, /* received one ABORT_REQ_RSS message */
  126. C3CN_ABORT_RPL_PENDING, /* expecting an abort reply */
  127. C3CN_TX_DATA_SENT, /* already sent a TX_DATA WR */
  128. C3CN_ACTIVE_CLOSE_NEEDED, /* need to be closed */
  129. C3CN_OFFLOAD_DOWN /* offload function off */
  130. };
  131. /**
  132. * cxgb3i_sdev_data - Per adapter data.
  133. * Linked off of each Ethernet device port on the adapter.
  134. * Also available via the t3cdev structure since we have pointers to our port
  135. * net_device's there ...
  136. *
  137. * @list: list head to link elements
  138. * @cdev: t3cdev adapter
  139. * @client: CPL client pointer
  140. * @ports: array of adapter ports
  141. * @sport_next: next port
  142. * @sport_conn: source port connection
  143. */
  144. struct cxgb3i_sdev_data {
  145. struct list_head list;
  146. struct t3cdev *cdev;
  147. struct cxgb3_client *client;
  148. struct adap_ports ports;
  149. spinlock_t lock;
  150. unsigned int sport_next;
  151. struct s3_conn *sport_conn[0];
  152. };
  153. #define NDEV2CDATA(ndev) (*(struct cxgb3i_sdev_data **)&(ndev)->ec_ptr)
  154. #define CXGB3_SDEV_DATA(cdev) NDEV2CDATA((cdev)->lldev)
  155. void cxgb3i_sdev_cleanup(void);
  156. int cxgb3i_sdev_init(cxgb3_cpl_handler_func *);
  157. void cxgb3i_sdev_add(struct t3cdev *, struct cxgb3_client *);
  158. void cxgb3i_sdev_remove(struct t3cdev *);
  159. struct s3_conn *cxgb3i_c3cn_create(void);
  160. int cxgb3i_c3cn_connect(struct net_device *, struct s3_conn *,
  161. struct sockaddr_in *);
  162. void cxgb3i_c3cn_rx_credits(struct s3_conn *, int);
  163. int cxgb3i_c3cn_send_pdus(struct s3_conn *, struct sk_buff *);
  164. void cxgb3i_c3cn_release(struct s3_conn *);
  165. /**
  166. * cxgb3_skb_cb - control block for received pdu state and ULP mode management.
  167. *
  168. * @flag: see C3CB_FLAG_* below
  169. * @ulp_mode: ULP mode/submode of sk_buff
  170. * @seq: tcp sequence number
  171. */
  172. struct cxgb3_skb_rx_cb {
  173. __u32 ddigest; /* data digest */
  174. __u32 pdulen; /* recovered pdu length */
  175. };
  176. struct cxgb3_skb_tx_cb {
  177. struct sk_buff *wr_next; /* next wr */
  178. };
  179. struct cxgb3_skb_cb {
  180. __u8 flags;
  181. __u8 ulp_mode;
  182. __u32 seq;
  183. union {
  184. struct cxgb3_skb_rx_cb rx;
  185. struct cxgb3_skb_tx_cb tx;
  186. };
  187. };
  188. #define CXGB3_SKB_CB(skb) ((struct cxgb3_skb_cb *)&((skb)->cb[0]))
  189. #define skb_flags(skb) (CXGB3_SKB_CB(skb)->flags)
  190. #define skb_ulp_mode(skb) (CXGB3_SKB_CB(skb)->ulp_mode)
  191. #define skb_tcp_seq(skb) (CXGB3_SKB_CB(skb)->seq)
  192. #define skb_rx_ddigest(skb) (CXGB3_SKB_CB(skb)->rx.ddigest)
  193. #define skb_rx_pdulen(skb) (CXGB3_SKB_CB(skb)->rx.pdulen)
  194. #define skb_tx_wr_next(skb) (CXGB3_SKB_CB(skb)->tx.wr_next)
  195. enum c3cb_flags {
  196. C3CB_FLAG_NEED_HDR = 1 << 0, /* packet needs a TX_DATA_WR header */
  197. C3CB_FLAG_NO_APPEND = 1 << 1, /* don't grow this skb */
  198. C3CB_FLAG_COMPL = 1 << 2, /* request WR completion */
  199. };
  200. /**
  201. * sge_opaque_hdr -
  202. * Opaque version of structure the SGE stores at skb->head of TX_DATA packets
  203. * and for which we must reserve space.
  204. */
  205. struct sge_opaque_hdr {
  206. void *dev;
  207. dma_addr_t addr[MAX_SKB_FRAGS + 1];
  208. };
  209. /* for TX: a skb must have a headroom of at least TX_HEADER_LEN bytes */
  210. #define TX_HEADER_LEN \
  211. (sizeof(struct tx_data_wr) + sizeof(struct sge_opaque_hdr))
  212. #define SKB_TX_HEADROOM SKB_MAX_HEAD(TX_HEADER_LEN)
  213. /*
  214. * get and set private ip for iscsi traffic
  215. */
  216. #define cxgb3i_get_private_ipv4addr(ndev) \
  217. (((struct port_info *)(netdev_priv(ndev)))->iscsi_ipv4addr)
  218. #define cxgb3i_set_private_ipv4addr(ndev, addr) \
  219. (((struct port_info *)(netdev_priv(ndev)))->iscsi_ipv4addr) = addr
  220. /* max. connections per adapter */
  221. #define CXGB3I_MAX_CONN 16384
  222. #endif /* _CXGB3_OFFLOAD_H */