cxgb3i_offload.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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 <net/tcp.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. };
  130. /**
  131. * cxgb3i_sdev_data - Per adapter data.
  132. * Linked off of each Ethernet device port on the adapter.
  133. * Also available via the t3cdev structure since we have pointers to our port
  134. * net_device's there ...
  135. *
  136. * @list: list head to link elements
  137. * @cdev: t3cdev adapter
  138. * @client: CPL client pointer
  139. * @ports: array of adapter ports
  140. * @sport_map_next: next index into the port map
  141. * @sport_map: source port map
  142. */
  143. struct cxgb3i_sdev_data {
  144. struct list_head list;
  145. struct t3cdev *cdev;
  146. struct cxgb3_client *client;
  147. struct adap_ports ports;
  148. unsigned int sport_map_next;
  149. unsigned long sport_map[0];
  150. };
  151. #define NDEV2CDATA(ndev) (*(struct cxgb3i_sdev_data **)&(ndev)->ec_ptr)
  152. #define CXGB3_SDEV_DATA(cdev) NDEV2CDATA((cdev)->lldev)
  153. void cxgb3i_sdev_cleanup(void);
  154. int cxgb3i_sdev_init(cxgb3_cpl_handler_func *);
  155. void cxgb3i_sdev_add(struct t3cdev *, struct cxgb3_client *);
  156. void cxgb3i_sdev_remove(struct t3cdev *);
  157. struct s3_conn *cxgb3i_c3cn_create(void);
  158. int cxgb3i_c3cn_connect(struct s3_conn *, struct sockaddr_in *);
  159. void cxgb3i_c3cn_rx_credits(struct s3_conn *, int);
  160. int cxgb3i_c3cn_send_pdus(struct s3_conn *, struct sk_buff *);
  161. void cxgb3i_c3cn_release(struct s3_conn *);
  162. /**
  163. * cxgb3_skb_cb - control block for received pdu state and ULP mode management.
  164. *
  165. * @flag: see C3CB_FLAG_* below
  166. * @ulp_mode: ULP mode/submode of sk_buff
  167. * @seq: tcp sequence number
  168. * @ddigest: pdu data digest
  169. * @pdulen: recovered pdu length
  170. * @wr_data: scratch area for tx wr
  171. */
  172. struct cxgb3_skb_cb {
  173. __u8 flags;
  174. __u8 ulp_mode;
  175. __u32 seq;
  176. __u32 ddigest;
  177. __u32 pdulen;
  178. struct sk_buff *wr_data;
  179. };
  180. #define CXGB3_SKB_CB(skb) ((struct cxgb3_skb_cb *)&((skb)->cb[0]))
  181. #define skb_ulp_mode(skb) (CXGB3_SKB_CB(skb)->ulp_mode)
  182. #define skb_ulp_ddigest(skb) (CXGB3_SKB_CB(skb)->ddigest)
  183. #define skb_ulp_pdulen(skb) (CXGB3_SKB_CB(skb)->pdulen)
  184. #define skb_wr_data(skb) (CXGB3_SKB_CB(skb)->wr_data)
  185. enum c3cb_flags {
  186. C3CB_FLAG_NEED_HDR = 1 << 0, /* packet needs a TX_DATA_WR header */
  187. C3CB_FLAG_NO_APPEND = 1 << 1, /* don't grow this skb */
  188. C3CB_FLAG_COMPL = 1 << 2, /* request WR completion */
  189. };
  190. /**
  191. * sge_opaque_hdr -
  192. * Opaque version of structure the SGE stores at skb->head of TX_DATA packets
  193. * and for which we must reserve space.
  194. */
  195. struct sge_opaque_hdr {
  196. void *dev;
  197. dma_addr_t addr[MAX_SKB_FRAGS + 1];
  198. };
  199. /* for TX: a skb must have a headroom of at least TX_HEADER_LEN bytes */
  200. #define TX_HEADER_LEN \
  201. (sizeof(struct tx_data_wr) + sizeof(struct sge_opaque_hdr))
  202. /*
  203. * get and set private ip for iscsi traffic
  204. */
  205. #define cxgb3i_get_private_ipv4addr(ndev) \
  206. (((struct port_info *)(netdev_priv(ndev)))->iscsi_ipv4addr)
  207. #define cxgb3i_set_private_ipv4addr(ndev, addr) \
  208. (((struct port_info *)(netdev_priv(ndev)))->iscsi_ipv4addr) = addr
  209. /* max. connections per adapter */
  210. #define CXGB3I_MAX_CONN 16384
  211. #endif /* _CXGB3_OFFLOAD_H */