cxgbit.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. /*
  2. * Copyright (c) 2016 Chelsio Communications, Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #ifndef __CXGBIT_H__
  9. #define __CXGBIT_H__
  10. #include <linux/mutex.h>
  11. #include <linux/list.h>
  12. #include <linux/spinlock.h>
  13. #include <linux/idr.h>
  14. #include <linux/completion.h>
  15. #include <linux/netdevice.h>
  16. #include <linux/sched.h>
  17. #include <linux/pci.h>
  18. #include <linux/dma-mapping.h>
  19. #include <linux/inet.h>
  20. #include <linux/wait.h>
  21. #include <linux/kref.h>
  22. #include <linux/timer.h>
  23. #include <linux/io.h>
  24. #include <asm/byteorder.h>
  25. #include <net/net_namespace.h>
  26. #include <target/iscsi/iscsi_transport.h>
  27. #include <iscsi_target_parameters.h>
  28. #include <iscsi_target_login.h>
  29. #include "t4_regs.h"
  30. #include "t4_msg.h"
  31. #include "cxgb4.h"
  32. #include "cxgb4_uld.h"
  33. #include "l2t.h"
  34. #include "libcxgb_ppm.h"
  35. #include "cxgbit_lro.h"
  36. extern struct mutex cdev_list_lock;
  37. extern struct list_head cdev_list_head;
  38. struct cxgbit_np;
  39. struct cxgbit_sock;
  40. struct cxgbit_cmd {
  41. struct scatterlist sg;
  42. struct cxgbi_task_tag_info ttinfo;
  43. bool setup_ddp;
  44. bool release;
  45. };
  46. #define CXGBIT_MAX_ISO_PAYLOAD \
  47. min_t(u32, MAX_SKB_FRAGS * PAGE_SIZE, 65535)
  48. struct cxgbit_iso_info {
  49. u8 flags;
  50. u32 mpdu;
  51. u32 len;
  52. u32 burst_len;
  53. };
  54. enum cxgbit_skcb_flags {
  55. SKCBF_TX_NEED_HDR = (1 << 0), /* packet needs a header */
  56. SKCBF_TX_FLAG_COMPL = (1 << 1), /* wr completion flag */
  57. SKCBF_TX_ISO = (1 << 2), /* iso cpl in tx skb */
  58. SKCBF_RX_LRO = (1 << 3), /* lro skb */
  59. };
  60. struct cxgbit_skb_rx_cb {
  61. u8 opcode;
  62. void *pdu_cb;
  63. void (*backlog_fn)(struct cxgbit_sock *, struct sk_buff *);
  64. };
  65. struct cxgbit_skb_tx_cb {
  66. u8 submode;
  67. u32 extra_len;
  68. };
  69. union cxgbit_skb_cb {
  70. struct {
  71. u8 flags;
  72. union {
  73. struct cxgbit_skb_tx_cb tx;
  74. struct cxgbit_skb_rx_cb rx;
  75. };
  76. };
  77. struct {
  78. /* This member must be first. */
  79. struct l2t_skb_cb l2t;
  80. struct sk_buff *wr_next;
  81. };
  82. };
  83. #define CXGBIT_SKB_CB(skb) ((union cxgbit_skb_cb *)&((skb)->cb[0]))
  84. #define cxgbit_skcb_flags(skb) (CXGBIT_SKB_CB(skb)->flags)
  85. #define cxgbit_skcb_submode(skb) (CXGBIT_SKB_CB(skb)->tx.submode)
  86. #define cxgbit_skcb_tx_wr_next(skb) (CXGBIT_SKB_CB(skb)->wr_next)
  87. #define cxgbit_skcb_tx_extralen(skb) (CXGBIT_SKB_CB(skb)->tx.extra_len)
  88. #define cxgbit_skcb_rx_opcode(skb) (CXGBIT_SKB_CB(skb)->rx.opcode)
  89. #define cxgbit_skcb_rx_backlog_fn(skb) (CXGBIT_SKB_CB(skb)->rx.backlog_fn)
  90. #define cxgbit_rx_pdu_cb(skb) (CXGBIT_SKB_CB(skb)->rx.pdu_cb)
  91. static inline void *cplhdr(struct sk_buff *skb)
  92. {
  93. return skb->data;
  94. }
  95. enum cxgbit_cdev_flags {
  96. CDEV_STATE_UP = 0,
  97. CDEV_ISO_ENABLE,
  98. CDEV_DDP_ENABLE,
  99. };
  100. #define NP_INFO_HASH_SIZE 32
  101. struct np_info {
  102. struct np_info *next;
  103. struct cxgbit_np *cnp;
  104. unsigned int stid;
  105. };
  106. struct cxgbit_list_head {
  107. struct list_head list;
  108. /* device lock */
  109. spinlock_t lock;
  110. };
  111. struct cxgbit_device {
  112. struct list_head list;
  113. struct cxgb4_lld_info lldi;
  114. struct np_info *np_hash_tab[NP_INFO_HASH_SIZE];
  115. /* np lock */
  116. spinlock_t np_lock;
  117. u8 selectq[MAX_NPORTS][2];
  118. struct cxgbit_list_head cskq;
  119. u32 mdsl;
  120. struct kref kref;
  121. unsigned long flags;
  122. };
  123. struct cxgbit_wr_wait {
  124. struct completion completion;
  125. int ret;
  126. };
  127. enum cxgbit_csk_state {
  128. CSK_STATE_IDLE = 0,
  129. CSK_STATE_LISTEN,
  130. CSK_STATE_CONNECTING,
  131. CSK_STATE_ESTABLISHED,
  132. CSK_STATE_ABORTING,
  133. CSK_STATE_CLOSING,
  134. CSK_STATE_MORIBUND,
  135. CSK_STATE_DEAD,
  136. };
  137. enum cxgbit_csk_flags {
  138. CSK_TX_DATA_SENT = 0,
  139. CSK_LOGIN_PDU_DONE,
  140. CSK_LOGIN_DONE,
  141. CSK_DDP_ENABLE,
  142. };
  143. struct cxgbit_sock_common {
  144. struct cxgbit_device *cdev;
  145. struct sockaddr_storage local_addr;
  146. struct sockaddr_storage remote_addr;
  147. struct cxgbit_wr_wait wr_wait;
  148. enum cxgbit_csk_state state;
  149. unsigned long flags;
  150. };
  151. struct cxgbit_np {
  152. struct cxgbit_sock_common com;
  153. wait_queue_head_t accept_wait;
  154. struct iscsi_np *np;
  155. struct completion accept_comp;
  156. struct list_head np_accept_list;
  157. /* np accept lock */
  158. spinlock_t np_accept_lock;
  159. struct kref kref;
  160. unsigned int stid;
  161. };
  162. struct cxgbit_sock {
  163. struct cxgbit_sock_common com;
  164. struct cxgbit_np *cnp;
  165. struct iscsi_conn *conn;
  166. struct l2t_entry *l2t;
  167. struct dst_entry *dst;
  168. struct list_head list;
  169. struct sk_buff_head rxq;
  170. struct sk_buff_head txq;
  171. struct sk_buff_head ppodq;
  172. struct sk_buff_head backlogq;
  173. struct sk_buff_head skbq;
  174. struct sk_buff *wr_pending_head;
  175. struct sk_buff *wr_pending_tail;
  176. struct sk_buff *skb;
  177. struct sk_buff *lro_skb;
  178. struct sk_buff *lro_hskb;
  179. struct list_head accept_node;
  180. /* socket lock */
  181. spinlock_t lock;
  182. wait_queue_head_t waitq;
  183. wait_queue_head_t ack_waitq;
  184. bool lock_owner;
  185. struct kref kref;
  186. u32 max_iso_npdu;
  187. u32 wr_cred;
  188. u32 wr_una_cred;
  189. u32 wr_max_cred;
  190. u32 snd_una;
  191. u32 tid;
  192. u32 snd_nxt;
  193. u32 rcv_nxt;
  194. u32 smac_idx;
  195. u32 tx_chan;
  196. u32 mtu;
  197. u32 write_seq;
  198. u32 rx_credits;
  199. u32 snd_win;
  200. u32 rcv_win;
  201. u16 mss;
  202. u16 emss;
  203. u16 plen;
  204. u16 rss_qid;
  205. u16 txq_idx;
  206. u16 ctrlq_idx;
  207. u8 tos;
  208. u8 port_id;
  209. #define CXGBIT_SUBMODE_HCRC 0x1
  210. #define CXGBIT_SUBMODE_DCRC 0x2
  211. u8 submode;
  212. #ifdef CONFIG_CHELSIO_T4_DCB
  213. u8 dcb_priority;
  214. #endif
  215. u8 snd_wscale;
  216. };
  217. void _cxgbit_free_cdev(struct kref *kref);
  218. void _cxgbit_free_csk(struct kref *kref);
  219. void _cxgbit_free_cnp(struct kref *kref);
  220. static inline void cxgbit_get_cdev(struct cxgbit_device *cdev)
  221. {
  222. kref_get(&cdev->kref);
  223. }
  224. static inline void cxgbit_put_cdev(struct cxgbit_device *cdev)
  225. {
  226. kref_put(&cdev->kref, _cxgbit_free_cdev);
  227. }
  228. static inline void cxgbit_get_csk(struct cxgbit_sock *csk)
  229. {
  230. kref_get(&csk->kref);
  231. }
  232. static inline void cxgbit_put_csk(struct cxgbit_sock *csk)
  233. {
  234. kref_put(&csk->kref, _cxgbit_free_csk);
  235. }
  236. static inline void cxgbit_get_cnp(struct cxgbit_np *cnp)
  237. {
  238. kref_get(&cnp->kref);
  239. }
  240. static inline void cxgbit_put_cnp(struct cxgbit_np *cnp)
  241. {
  242. kref_put(&cnp->kref, _cxgbit_free_cnp);
  243. }
  244. static inline void cxgbit_sock_reset_wr_list(struct cxgbit_sock *csk)
  245. {
  246. csk->wr_pending_tail = NULL;
  247. csk->wr_pending_head = NULL;
  248. }
  249. static inline struct sk_buff *cxgbit_sock_peek_wr(const struct cxgbit_sock *csk)
  250. {
  251. return csk->wr_pending_head;
  252. }
  253. static inline void
  254. cxgbit_sock_enqueue_wr(struct cxgbit_sock *csk, struct sk_buff *skb)
  255. {
  256. cxgbit_skcb_tx_wr_next(skb) = NULL;
  257. skb_get(skb);
  258. if (!csk->wr_pending_head)
  259. csk->wr_pending_head = skb;
  260. else
  261. cxgbit_skcb_tx_wr_next(csk->wr_pending_tail) = skb;
  262. csk->wr_pending_tail = skb;
  263. }
  264. static inline struct sk_buff *cxgbit_sock_dequeue_wr(struct cxgbit_sock *csk)
  265. {
  266. struct sk_buff *skb = csk->wr_pending_head;
  267. if (likely(skb)) {
  268. csk->wr_pending_head = cxgbit_skcb_tx_wr_next(skb);
  269. cxgbit_skcb_tx_wr_next(skb) = NULL;
  270. }
  271. return skb;
  272. }
  273. typedef void (*cxgbit_cplhandler_func)(struct cxgbit_device *,
  274. struct sk_buff *);
  275. int cxgbit_setup_np(struct iscsi_np *, struct sockaddr_storage *);
  276. int cxgbit_setup_conn_digest(struct cxgbit_sock *);
  277. int cxgbit_accept_np(struct iscsi_np *, struct iscsi_conn *);
  278. void cxgbit_free_np(struct iscsi_np *);
  279. void cxgbit_free_conn(struct iscsi_conn *);
  280. extern cxgbit_cplhandler_func cxgbit_cplhandlers[NUM_CPL_CMDS];
  281. int cxgbit_get_login_rx(struct iscsi_conn *, struct iscsi_login *);
  282. int cxgbit_rx_data_ack(struct cxgbit_sock *);
  283. int cxgbit_l2t_send(struct cxgbit_device *, struct sk_buff *,
  284. struct l2t_entry *);
  285. void cxgbit_push_tx_frames(struct cxgbit_sock *);
  286. int cxgbit_put_login_tx(struct iscsi_conn *, struct iscsi_login *, u32);
  287. int cxgbit_xmit_pdu(struct iscsi_conn *, struct iscsi_cmd *,
  288. struct iscsi_datain_req *, const void *, u32);
  289. void cxgbit_get_r2t_ttt(struct iscsi_conn *, struct iscsi_cmd *,
  290. struct iscsi_r2t *);
  291. u32 cxgbit_send_tx_flowc_wr(struct cxgbit_sock *);
  292. int cxgbit_ofld_send(struct cxgbit_device *, struct sk_buff *);
  293. void cxgbit_get_rx_pdu(struct iscsi_conn *);
  294. int cxgbit_validate_params(struct iscsi_conn *);
  295. struct cxgbit_device *cxgbit_find_device(struct net_device *, u8 *);
  296. /* DDP */
  297. int cxgbit_ddp_init(struct cxgbit_device *);
  298. int cxgbit_setup_conn_pgidx(struct cxgbit_sock *, u32);
  299. int cxgbit_reserve_ttt(struct cxgbit_sock *, struct iscsi_cmd *);
  300. void cxgbit_release_cmd(struct iscsi_conn *, struct iscsi_cmd *);
  301. static inline
  302. struct cxgbi_ppm *cdev2ppm(struct cxgbit_device *cdev)
  303. {
  304. return (struct cxgbi_ppm *)(*cdev->lldi.iscsi_ppm);
  305. }
  306. #endif /* __CXGBIT_H__ */