libcxgbi.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  1. /*
  2. * libcxgbi.h: Chelsio common library for T3/T4 iSCSI driver.
  3. *
  4. * Copyright (c) 2010 Chelsio Communications, Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation.
  9. *
  10. * Written by: Karen Xie (kxie@chelsio.com)
  11. * Written by: Rakesh Ranjan (rranjan@chelsio.com)
  12. */
  13. #ifndef __LIBCXGBI_H__
  14. #define __LIBCXGBI_H__
  15. #include <linux/kernel.h>
  16. #include <linux/errno.h>
  17. #include <linux/types.h>
  18. #include <linux/debugfs.h>
  19. #include <linux/list.h>
  20. #include <linux/netdevice.h>
  21. #include <linux/if_vlan.h>
  22. #include <linux/scatterlist.h>
  23. #include <linux/skbuff.h>
  24. #include <linux/vmalloc.h>
  25. #include <scsi/scsi_device.h>
  26. #include <scsi/libiscsi_tcp.h>
  27. enum cxgbi_dbg_flag {
  28. CXGBI_DBG_ISCSI,
  29. CXGBI_DBG_DDP,
  30. CXGBI_DBG_TOE,
  31. CXGBI_DBG_SOCK,
  32. CXGBI_DBG_PDU_TX,
  33. CXGBI_DBG_PDU_RX,
  34. CXGBI_DBG_DEV,
  35. };
  36. #define log_debug(level, fmt, ...) \
  37. do { \
  38. if (dbg_level & (level)) \
  39. pr_info(fmt, ##__VA_ARGS__); \
  40. } while (0)
  41. /* max. connections per adapter */
  42. #define CXGBI_MAX_CONN 16384
  43. /* always allocate rooms for AHS */
  44. #define SKB_TX_ISCSI_PDU_HEADER_MAX \
  45. (sizeof(struct iscsi_hdr) + ISCSI_MAX_AHS_SIZE)
  46. #define ISCSI_PDU_NONPAYLOAD_LEN 312 /* bhs(48) + ahs(256) + digest(8)*/
  47. /*
  48. * align pdu size to multiple of 512 for better performance
  49. */
  50. #define cxgbi_align_pdu_size(n) do { n = (n) & (~511); } while (0)
  51. #define ULP2_MODE_ISCSI 2
  52. #define ULP2_MAX_PKT_SIZE 16224
  53. #define ULP2_MAX_PDU_PAYLOAD \
  54. (ULP2_MAX_PKT_SIZE - ISCSI_PDU_NONPAYLOAD_LEN)
  55. /*
  56. * For iscsi connections HW may inserts digest bytes into the pdu. Those digest
  57. * bytes are not sent by the host but are part of the TCP payload and therefore
  58. * consume TCP sequence space.
  59. */
  60. static const unsigned int ulp2_extra_len[] = { 0, 4, 4, 8 };
  61. static inline unsigned int cxgbi_ulp_extra_len(int submode)
  62. {
  63. return ulp2_extra_len[submode & 3];
  64. }
  65. /*
  66. * struct pagepod_hdr, pagepod - pagepod format
  67. */
  68. #define CPL_RX_DDP_STATUS_DDP_SHIFT 16 /* ddp'able */
  69. #define CPL_RX_DDP_STATUS_PAD_SHIFT 19 /* pad error */
  70. #define CPL_RX_DDP_STATUS_HCRC_SHIFT 20 /* hcrc error */
  71. #define CPL_RX_DDP_STATUS_DCRC_SHIFT 21 /* dcrc error */
  72. struct cxgbi_pagepod_hdr {
  73. u32 vld_tid;
  74. u32 pgsz_tag_clr;
  75. u32 max_offset;
  76. u32 page_offset;
  77. u64 rsvd;
  78. };
  79. #define PPOD_PAGES_MAX 4
  80. struct cxgbi_pagepod {
  81. struct cxgbi_pagepod_hdr hdr;
  82. u64 addr[PPOD_PAGES_MAX + 1];
  83. };
  84. struct cxgbi_tag_format {
  85. unsigned char sw_bits;
  86. unsigned char rsvd_bits;
  87. unsigned char rsvd_shift;
  88. unsigned char filler[1];
  89. u32 rsvd_mask;
  90. };
  91. struct cxgbi_gather_list {
  92. unsigned int tag;
  93. unsigned int length;
  94. unsigned int offset;
  95. unsigned int nelem;
  96. struct page **pages;
  97. dma_addr_t phys_addr[0];
  98. };
  99. struct cxgbi_ddp_info {
  100. struct kref refcnt;
  101. struct cxgbi_device *cdev;
  102. struct pci_dev *pdev;
  103. unsigned int max_txsz;
  104. unsigned int max_rxsz;
  105. unsigned int llimit;
  106. unsigned int ulimit;
  107. unsigned int nppods;
  108. unsigned int idx_last;
  109. unsigned char idx_bits;
  110. unsigned char filler[3];
  111. unsigned int idx_mask;
  112. unsigned int rsvd_tag_mask;
  113. spinlock_t map_lock;
  114. struct cxgbi_gather_list **gl_map;
  115. struct sk_buff **gl_skb;
  116. };
  117. #define DDP_PGIDX_MAX 4
  118. #define DDP_THRESHOLD 2048
  119. #define PPOD_PAGES_SHIFT 2 /* 4 pages per pod */
  120. #define PPOD_SIZE sizeof(struct cxgbi_pagepod) /* 64 */
  121. #define PPOD_SIZE_SHIFT 6
  122. #define ULPMEM_DSGL_MAX_NPPODS 16 /* 1024/PPOD_SIZE */
  123. #define ULPMEM_IDATA_MAX_NPPODS 4 /* 256/PPOD_SIZE */
  124. #define PCIE_MEMWIN_MAX_NPPODS 16 /* 1024/PPOD_SIZE */
  125. #define PPOD_COLOR_SHIFT 0
  126. #define PPOD_COLOR(x) ((x) << PPOD_COLOR_SHIFT)
  127. #define PPOD_IDX_SHIFT 6
  128. #define PPOD_IDX_MAX_SIZE 24
  129. #define PPOD_TID_SHIFT 0
  130. #define PPOD_TID(x) ((x) << PPOD_TID_SHIFT)
  131. #define PPOD_TAG_SHIFT 6
  132. #define PPOD_TAG(x) ((x) << PPOD_TAG_SHIFT)
  133. #define PPOD_VALID_SHIFT 24
  134. #define PPOD_VALID(x) ((x) << PPOD_VALID_SHIFT)
  135. #define PPOD_VALID_FLAG PPOD_VALID(1U)
  136. #define W_TCB_ULP_TYPE 0
  137. #define TCB_ULP_TYPE_SHIFT 0
  138. #define TCB_ULP_TYPE_MASK 0xfULL
  139. #define TCB_ULP_TYPE(x) ((x) << TCB_ULP_TYPE_SHIFT)
  140. #define W_TCB_ULP_RAW 0
  141. #define TCB_ULP_RAW_SHIFT 4
  142. #define TCB_ULP_RAW_MASK 0xffULL
  143. #define TCB_ULP_RAW(x) ((x) << TCB_ULP_RAW_SHIFT)
  144. /*
  145. * sge_opaque_hdr -
  146. * Opaque version of structure the SGE stores at skb->head of TX_DATA packets
  147. * and for which we must reserve space.
  148. */
  149. struct sge_opaque_hdr {
  150. void *dev;
  151. dma_addr_t addr[MAX_SKB_FRAGS + 1];
  152. };
  153. struct cxgbi_sock {
  154. struct cxgbi_device *cdev;
  155. int tid;
  156. int atid;
  157. unsigned long flags;
  158. unsigned int mtu;
  159. unsigned short rss_qid;
  160. unsigned short txq_idx;
  161. unsigned short advmss;
  162. unsigned int tx_chan;
  163. unsigned int rx_chan;
  164. unsigned int mss_idx;
  165. unsigned int smac_idx;
  166. unsigned char port_id;
  167. int wr_max_cred;
  168. int wr_cred;
  169. int wr_una_cred;
  170. unsigned char hcrc_len;
  171. unsigned char dcrc_len;
  172. void *l2t;
  173. struct sk_buff *wr_pending_head;
  174. struct sk_buff *wr_pending_tail;
  175. struct sk_buff *cpl_close;
  176. struct sk_buff *cpl_abort_req;
  177. struct sk_buff *cpl_abort_rpl;
  178. struct sk_buff *skb_ulp_lhdr;
  179. spinlock_t lock;
  180. struct kref refcnt;
  181. unsigned int state;
  182. struct sockaddr_in saddr;
  183. struct sockaddr_in daddr;
  184. struct dst_entry *dst;
  185. struct sk_buff_head receive_queue;
  186. struct sk_buff_head write_queue;
  187. struct timer_list retry_timer;
  188. int err;
  189. rwlock_t callback_lock;
  190. void *user_data;
  191. u32 rcv_nxt;
  192. u32 copied_seq;
  193. u32 rcv_wup;
  194. u32 snd_nxt;
  195. u32 snd_una;
  196. u32 write_seq;
  197. };
  198. /*
  199. * connection states
  200. */
  201. enum cxgbi_sock_states{
  202. CTP_CLOSED,
  203. CTP_CONNECTING,
  204. CTP_ACTIVE_OPEN,
  205. CTP_ESTABLISHED,
  206. CTP_ACTIVE_CLOSE,
  207. CTP_PASSIVE_CLOSE,
  208. CTP_CLOSE_WAIT_1,
  209. CTP_CLOSE_WAIT_2,
  210. CTP_ABORTING,
  211. };
  212. /*
  213. * Connection flags -- many to track some close related events.
  214. */
  215. enum cxgbi_sock_flags {
  216. CTPF_ABORT_RPL_RCVD, /*received one ABORT_RPL_RSS message */
  217. CTPF_ABORT_REQ_RCVD, /*received one ABORT_REQ_RSS message */
  218. CTPF_ABORT_RPL_PENDING, /* expecting an abort reply */
  219. CTPF_TX_DATA_SENT, /* already sent a TX_DATA WR */
  220. CTPF_ACTIVE_CLOSE_NEEDED,/* need to be closed */
  221. CTPF_HAS_ATID, /* reserved atid */
  222. CTPF_HAS_TID, /* reserved hw tid */
  223. CTPF_OFFLOAD_DOWN, /* offload function off */
  224. };
  225. struct cxgbi_skb_rx_cb {
  226. __u32 ddigest;
  227. __u32 pdulen;
  228. };
  229. struct cxgbi_skb_tx_cb {
  230. void *l2t;
  231. struct sk_buff *wr_next;
  232. };
  233. enum cxgbi_skcb_flags {
  234. SKCBF_TX_NEED_HDR, /* packet needs a header */
  235. SKCBF_RX_COALESCED, /* received whole pdu */
  236. SKCBF_RX_HDR, /* recieved pdu header */
  237. SKCBF_RX_DATA, /* recieved pdu payload */
  238. SKCBF_RX_STATUS, /* recieved ddp status */
  239. SKCBF_RX_DATA_DDPD, /* pdu payload ddp'd */
  240. SKCBF_RX_HCRC_ERR, /* header digest error */
  241. SKCBF_RX_DCRC_ERR, /* data digest error */
  242. SKCBF_RX_PAD_ERR, /* padding byte error */
  243. };
  244. struct cxgbi_skb_cb {
  245. unsigned char ulp_mode;
  246. unsigned long flags;
  247. unsigned int seq;
  248. union {
  249. struct cxgbi_skb_rx_cb rx;
  250. struct cxgbi_skb_tx_cb tx;
  251. };
  252. };
  253. #define CXGBI_SKB_CB(skb) ((struct cxgbi_skb_cb *)&((skb)->cb[0]))
  254. #define cxgbi_skcb_flags(skb) (CXGBI_SKB_CB(skb)->flags)
  255. #define cxgbi_skcb_ulp_mode(skb) (CXGBI_SKB_CB(skb)->ulp_mode)
  256. #define cxgbi_skcb_tcp_seq(skb) (CXGBI_SKB_CB(skb)->seq)
  257. #define cxgbi_skcb_rx_ddigest(skb) (CXGBI_SKB_CB(skb)->rx.ddigest)
  258. #define cxgbi_skcb_rx_pdulen(skb) (CXGBI_SKB_CB(skb)->rx.pdulen)
  259. #define cxgbi_skcb_tx_wr_next(skb) (CXGBI_SKB_CB(skb)->tx.wr_next)
  260. static inline void cxgbi_skcb_set_flag(struct sk_buff *skb,
  261. enum cxgbi_skcb_flags flag)
  262. {
  263. __set_bit(flag, &(cxgbi_skcb_flags(skb)));
  264. }
  265. static inline void cxgbi_skcb_clear_flag(struct sk_buff *skb,
  266. enum cxgbi_skcb_flags flag)
  267. {
  268. __clear_bit(flag, &(cxgbi_skcb_flags(skb)));
  269. }
  270. static inline int cxgbi_skcb_test_flag(struct sk_buff *skb,
  271. enum cxgbi_skcb_flags flag)
  272. {
  273. return test_bit(flag, &(cxgbi_skcb_flags(skb)));
  274. }
  275. static inline void cxgbi_sock_set_flag(struct cxgbi_sock *csk,
  276. enum cxgbi_sock_flags flag)
  277. {
  278. __set_bit(flag, &csk->flags);
  279. log_debug(1 << CXGBI_DBG_SOCK,
  280. "csk 0x%p,%u,0x%lx, bit %d.\n",
  281. csk, csk->state, csk->flags, flag);
  282. }
  283. static inline void cxgbi_sock_clear_flag(struct cxgbi_sock *csk,
  284. enum cxgbi_sock_flags flag)
  285. {
  286. __clear_bit(flag, &csk->flags);
  287. log_debug(1 << CXGBI_DBG_SOCK,
  288. "csk 0x%p,%u,0x%lx, bit %d.\n",
  289. csk, csk->state, csk->flags, flag);
  290. }
  291. static inline int cxgbi_sock_flag(struct cxgbi_sock *csk,
  292. enum cxgbi_sock_flags flag)
  293. {
  294. if (csk == NULL)
  295. return 0;
  296. return test_bit(flag, &csk->flags);
  297. }
  298. static inline void cxgbi_sock_set_state(struct cxgbi_sock *csk, int state)
  299. {
  300. log_debug(1 << CXGBI_DBG_SOCK,
  301. "csk 0x%p,%u,0x%lx, state -> %u.\n",
  302. csk, csk->state, csk->flags, state);
  303. csk->state = state;
  304. }
  305. static inline void cxgbi_sock_free(struct kref *kref)
  306. {
  307. struct cxgbi_sock *csk = container_of(kref,
  308. struct cxgbi_sock,
  309. refcnt);
  310. if (csk) {
  311. log_debug(1 << CXGBI_DBG_SOCK,
  312. "free csk 0x%p, state %u, flags 0x%lx\n",
  313. csk, csk->state, csk->flags);
  314. kfree(csk);
  315. }
  316. }
  317. static inline void __cxgbi_sock_put(const char *fn, struct cxgbi_sock *csk)
  318. {
  319. log_debug(1 << CXGBI_DBG_SOCK,
  320. "%s, put csk 0x%p, ref %u-1.\n",
  321. fn, csk, atomic_read(&csk->refcnt.refcount));
  322. kref_put(&csk->refcnt, cxgbi_sock_free);
  323. }
  324. #define cxgbi_sock_put(csk) __cxgbi_sock_put(__func__, csk)
  325. static inline void __cxgbi_sock_get(const char *fn, struct cxgbi_sock *csk)
  326. {
  327. log_debug(1 << CXGBI_DBG_SOCK,
  328. "%s, get csk 0x%p, ref %u+1.\n",
  329. fn, csk, atomic_read(&csk->refcnt.refcount));
  330. kref_get(&csk->refcnt);
  331. }
  332. #define cxgbi_sock_get(csk) __cxgbi_sock_get(__func__, csk)
  333. static inline int cxgbi_sock_is_closing(struct cxgbi_sock *csk)
  334. {
  335. return csk->state >= CTP_ACTIVE_CLOSE;
  336. }
  337. static inline int cxgbi_sock_is_established(struct cxgbi_sock *csk)
  338. {
  339. return csk->state == CTP_ESTABLISHED;
  340. }
  341. static inline void cxgbi_sock_purge_write_queue(struct cxgbi_sock *csk)
  342. {
  343. struct sk_buff *skb;
  344. while ((skb = __skb_dequeue(&csk->write_queue)))
  345. __kfree_skb(skb);
  346. }
  347. static inline unsigned int cxgbi_sock_compute_wscale(unsigned int win)
  348. {
  349. unsigned int wscale = 0;
  350. while (wscale < 14 && (65535 << wscale) < win)
  351. wscale++;
  352. return wscale;
  353. }
  354. static inline struct sk_buff *alloc_wr(int wrlen, int dlen, gfp_t gfp)
  355. {
  356. struct sk_buff *skb = alloc_skb(wrlen + dlen, gfp);
  357. if (skb) {
  358. __skb_put(skb, wrlen);
  359. memset(skb->head, 0, wrlen + dlen);
  360. } else
  361. pr_info("alloc cpl wr skb %u+%u, OOM.\n", wrlen, dlen);
  362. return skb;
  363. }
  364. /*
  365. * The number of WRs needed for an skb depends on the number of fragments
  366. * in the skb and whether it has any payload in its main body. This maps the
  367. * length of the gather list represented by an skb into the # of necessary WRs.
  368. * The extra two fragments are for iscsi bhs and payload padding.
  369. */
  370. #define SKB_WR_LIST_SIZE (MAX_SKB_FRAGS + 2)
  371. static inline void cxgbi_sock_reset_wr_list(struct cxgbi_sock *csk)
  372. {
  373. csk->wr_pending_head = csk->wr_pending_tail = NULL;
  374. }
  375. static inline void cxgbi_sock_enqueue_wr(struct cxgbi_sock *csk,
  376. struct sk_buff *skb)
  377. {
  378. cxgbi_skcb_tx_wr_next(skb) = NULL;
  379. /*
  380. * We want to take an extra reference since both us and the driver
  381. * need to free the packet before it's really freed. We know there's
  382. * just one user currently so we use atomic_set rather than skb_get
  383. * to avoid the atomic op.
  384. */
  385. atomic_set(&skb->users, 2);
  386. if (!csk->wr_pending_head)
  387. csk->wr_pending_head = skb;
  388. else
  389. cxgbi_skcb_tx_wr_next(csk->wr_pending_tail) = skb;
  390. csk->wr_pending_tail = skb;
  391. }
  392. static inline int cxgbi_sock_count_pending_wrs(const struct cxgbi_sock *csk)
  393. {
  394. int n = 0;
  395. const struct sk_buff *skb = csk->wr_pending_head;
  396. while (skb) {
  397. n += skb->csum;
  398. skb = cxgbi_skcb_tx_wr_next(skb);
  399. }
  400. return n;
  401. }
  402. static inline struct sk_buff *cxgbi_sock_peek_wr(const struct cxgbi_sock *csk)
  403. {
  404. return csk->wr_pending_head;
  405. }
  406. static inline struct sk_buff *cxgbi_sock_dequeue_wr(struct cxgbi_sock *csk)
  407. {
  408. struct sk_buff *skb = csk->wr_pending_head;
  409. if (likely(skb)) {
  410. csk->wr_pending_head = cxgbi_skcb_tx_wr_next(skb);
  411. cxgbi_skcb_tx_wr_next(skb) = NULL;
  412. }
  413. return skb;
  414. }
  415. void cxgbi_sock_check_wr_invariants(const struct cxgbi_sock *);
  416. void cxgbi_sock_purge_wr_queue(struct cxgbi_sock *);
  417. void cxgbi_sock_skb_entail(struct cxgbi_sock *, struct sk_buff *);
  418. void cxgbi_sock_fail_act_open(struct cxgbi_sock *, int);
  419. void cxgbi_sock_act_open_req_arp_failure(void *, struct sk_buff *);
  420. void cxgbi_sock_closed(struct cxgbi_sock *);
  421. void cxgbi_sock_established(struct cxgbi_sock *, unsigned int, unsigned int);
  422. void cxgbi_sock_rcv_abort_rpl(struct cxgbi_sock *);
  423. void cxgbi_sock_rcv_peer_close(struct cxgbi_sock *);
  424. void cxgbi_sock_rcv_close_conn_rpl(struct cxgbi_sock *, u32);
  425. void cxgbi_sock_rcv_wr_ack(struct cxgbi_sock *, unsigned int, unsigned int,
  426. int);
  427. unsigned int cxgbi_sock_select_mss(struct cxgbi_sock *, unsigned int);
  428. void cxgbi_sock_free_cpl_skbs(struct cxgbi_sock *);
  429. struct cxgbi_hba {
  430. struct net_device *ndev;
  431. struct Scsi_Host *shost;
  432. struct cxgbi_device *cdev;
  433. __be32 ipv4addr;
  434. unsigned char port_id;
  435. };
  436. struct cxgbi_ports_map {
  437. unsigned int max_connect;
  438. unsigned int used;
  439. unsigned short sport_base;
  440. spinlock_t lock;
  441. unsigned int next;
  442. struct cxgbi_sock **port_csk;
  443. };
  444. #define CXGBI_FLAG_DEV_T3 0x1
  445. #define CXGBI_FLAG_DEV_T4 0x2
  446. #define CXGBI_FLAG_ADAPTER_RESET 0x4
  447. #define CXGBI_FLAG_IPV4_SET 0x10
  448. struct cxgbi_device {
  449. struct list_head list_head;
  450. unsigned int flags;
  451. struct net_device **ports;
  452. void *lldev;
  453. struct cxgbi_hba **hbas;
  454. const unsigned short *mtus;
  455. unsigned char nmtus;
  456. unsigned char nports;
  457. struct pci_dev *pdev;
  458. struct dentry *debugfs_root;
  459. struct iscsi_transport *itp;
  460. unsigned int pfvf;
  461. unsigned int snd_win;
  462. unsigned int rcv_win;
  463. unsigned int rx_credit_thres;
  464. unsigned int skb_tx_rsvd;
  465. unsigned int skb_rx_extra; /* for msg coalesced mode */
  466. unsigned int tx_max_size;
  467. unsigned int rx_max_size;
  468. struct cxgbi_ports_map pmap;
  469. struct cxgbi_tag_format tag_format;
  470. struct cxgbi_ddp_info *ddp;
  471. void (*dev_ddp_cleanup)(struct cxgbi_device *);
  472. void (*csk_ddp_free_gl_skb)(struct cxgbi_ddp_info *, int, int);
  473. int (*csk_ddp_alloc_gl_skb)(struct cxgbi_ddp_info *, int, int, gfp_t);
  474. int (*csk_ddp_set)(struct cxgbi_sock *, struct cxgbi_pagepod_hdr *,
  475. unsigned int, unsigned int,
  476. struct cxgbi_gather_list *);
  477. void (*csk_ddp_clear)(struct cxgbi_hba *,
  478. unsigned int, unsigned int, unsigned int);
  479. int (*csk_ddp_setup_digest)(struct cxgbi_sock *,
  480. unsigned int, int, int, int);
  481. int (*csk_ddp_setup_pgidx)(struct cxgbi_sock *,
  482. unsigned int, int, bool);
  483. void (*csk_release_offload_resources)(struct cxgbi_sock *);
  484. int (*csk_rx_pdu_ready)(struct cxgbi_sock *, struct sk_buff *);
  485. u32 (*csk_send_rx_credits)(struct cxgbi_sock *, u32);
  486. int (*csk_push_tx_frames)(struct cxgbi_sock *, int);
  487. void (*csk_send_abort_req)(struct cxgbi_sock *);
  488. void (*csk_send_close_req)(struct cxgbi_sock *);
  489. int (*csk_alloc_cpls)(struct cxgbi_sock *);
  490. int (*csk_init_act_open)(struct cxgbi_sock *);
  491. void *dd_data;
  492. };
  493. #define cxgbi_cdev_priv(cdev) ((cdev)->dd_data)
  494. struct cxgbi_conn {
  495. struct cxgbi_endpoint *cep;
  496. struct iscsi_conn *iconn;
  497. struct cxgbi_hba *chba;
  498. u32 task_idx_bits;
  499. };
  500. struct cxgbi_endpoint {
  501. struct cxgbi_conn *cconn;
  502. struct cxgbi_hba *chba;
  503. struct cxgbi_sock *csk;
  504. };
  505. #define MAX_PDU_FRAGS ((ULP2_MAX_PDU_PAYLOAD + 512 - 1) / 512)
  506. struct cxgbi_task_data {
  507. unsigned short nr_frags;
  508. skb_frag_t frags[MAX_PDU_FRAGS];
  509. struct sk_buff *skb;
  510. unsigned int offset;
  511. unsigned int count;
  512. unsigned int sgoffset;
  513. };
  514. #define iscsi_task_cxgbi_data(task) \
  515. ((task)->dd_data + sizeof(struct iscsi_tcp_task))
  516. static inline int cxgbi_is_ddp_tag(struct cxgbi_tag_format *tformat, u32 tag)
  517. {
  518. return !(tag & (1 << (tformat->rsvd_bits + tformat->rsvd_shift - 1)));
  519. }
  520. static inline int cxgbi_sw_tag_usable(struct cxgbi_tag_format *tformat,
  521. u32 sw_tag)
  522. {
  523. sw_tag >>= (32 - tformat->rsvd_bits);
  524. return !sw_tag;
  525. }
  526. static inline u32 cxgbi_set_non_ddp_tag(struct cxgbi_tag_format *tformat,
  527. u32 sw_tag)
  528. {
  529. unsigned char shift = tformat->rsvd_bits + tformat->rsvd_shift - 1;
  530. u32 mask = (1 << shift) - 1;
  531. if (sw_tag && (sw_tag & ~mask)) {
  532. u32 v1 = sw_tag & ((1 << shift) - 1);
  533. u32 v2 = (sw_tag >> (shift - 1)) << shift;
  534. return v2 | v1 | 1 << shift;
  535. }
  536. return sw_tag | 1 << shift;
  537. }
  538. static inline u32 cxgbi_ddp_tag_base(struct cxgbi_tag_format *tformat,
  539. u32 sw_tag)
  540. {
  541. u32 mask = (1 << tformat->rsvd_shift) - 1;
  542. if (sw_tag && (sw_tag & ~mask)) {
  543. u32 v1 = sw_tag & mask;
  544. u32 v2 = sw_tag >> tformat->rsvd_shift;
  545. v2 <<= tformat->rsvd_bits + tformat->rsvd_shift;
  546. return v2 | v1;
  547. }
  548. return sw_tag;
  549. }
  550. static inline u32 cxgbi_tag_rsvd_bits(struct cxgbi_tag_format *tformat,
  551. u32 tag)
  552. {
  553. if (cxgbi_is_ddp_tag(tformat, tag))
  554. return (tag >> tformat->rsvd_shift) & tformat->rsvd_mask;
  555. return 0;
  556. }
  557. static inline u32 cxgbi_tag_nonrsvd_bits(struct cxgbi_tag_format *tformat,
  558. u32 tag)
  559. {
  560. unsigned char shift = tformat->rsvd_bits + tformat->rsvd_shift - 1;
  561. u32 v1, v2;
  562. if (cxgbi_is_ddp_tag(tformat, tag)) {
  563. v1 = tag & ((1 << tformat->rsvd_shift) - 1);
  564. v2 = (tag >> (shift + 1)) << tformat->rsvd_shift;
  565. } else {
  566. u32 mask = (1 << shift) - 1;
  567. tag &= ~(1 << shift);
  568. v1 = tag & mask;
  569. v2 = (tag >> 1) & ~mask;
  570. }
  571. return v1 | v2;
  572. }
  573. static inline void *cxgbi_alloc_big_mem(unsigned int size,
  574. gfp_t gfp)
  575. {
  576. void *p = kmalloc(size, gfp);
  577. if (!p)
  578. p = vmalloc(size);
  579. if (p)
  580. memset(p, 0, size);
  581. return p;
  582. }
  583. static inline void cxgbi_free_big_mem(void *addr)
  584. {
  585. if (is_vmalloc_addr(addr))
  586. vfree(addr);
  587. else
  588. kfree(addr);
  589. }
  590. static inline void cxgbi_set_iscsi_ipv4(struct cxgbi_hba *chba, __be32 ipaddr)
  591. {
  592. if (chba->cdev->flags & CXGBI_FLAG_IPV4_SET)
  593. chba->ipv4addr = ipaddr;
  594. else
  595. pr_info("set iscsi ipv4 NOT supported, using %s ipv4.\n",
  596. chba->ndev->name);
  597. }
  598. static inline __be32 cxgbi_get_iscsi_ipv4(struct cxgbi_hba *chba)
  599. {
  600. return chba->ipv4addr;
  601. }
  602. struct cxgbi_device *cxgbi_device_register(unsigned int, unsigned int);
  603. void cxgbi_device_unregister(struct cxgbi_device *);
  604. void cxgbi_device_unregister_all(unsigned int flag);
  605. struct cxgbi_device *cxgbi_device_find_by_lldev(void *);
  606. int cxgbi_hbas_add(struct cxgbi_device *, unsigned int, unsigned int,
  607. struct scsi_host_template *,
  608. struct scsi_transport_template *);
  609. void cxgbi_hbas_remove(struct cxgbi_device *);
  610. int cxgbi_device_portmap_create(struct cxgbi_device *cdev, unsigned int base,
  611. unsigned int max_conn);
  612. void cxgbi_device_portmap_cleanup(struct cxgbi_device *cdev);
  613. void cxgbi_conn_tx_open(struct cxgbi_sock *);
  614. void cxgbi_conn_pdu_ready(struct cxgbi_sock *);
  615. int cxgbi_conn_alloc_pdu(struct iscsi_task *, u8);
  616. int cxgbi_conn_init_pdu(struct iscsi_task *, unsigned int , unsigned int);
  617. int cxgbi_conn_xmit_pdu(struct iscsi_task *);
  618. void cxgbi_cleanup_task(struct iscsi_task *task);
  619. void cxgbi_get_conn_stats(struct iscsi_cls_conn *, struct iscsi_stats *);
  620. int cxgbi_set_conn_param(struct iscsi_cls_conn *,
  621. enum iscsi_param, char *, int);
  622. int cxgbi_get_conn_param(struct iscsi_cls_conn *, enum iscsi_param, char *);
  623. struct iscsi_cls_conn *cxgbi_create_conn(struct iscsi_cls_session *, u32);
  624. int cxgbi_bind_conn(struct iscsi_cls_session *,
  625. struct iscsi_cls_conn *, u64, int);
  626. void cxgbi_destroy_session(struct iscsi_cls_session *);
  627. struct iscsi_cls_session *cxgbi_create_session(struct iscsi_endpoint *,
  628. u16, u16, u32);
  629. int cxgbi_set_host_param(struct Scsi_Host *,
  630. enum iscsi_host_param, char *, int);
  631. int cxgbi_get_host_param(struct Scsi_Host *, enum iscsi_host_param, char *);
  632. struct iscsi_endpoint *cxgbi_ep_connect(struct Scsi_Host *,
  633. struct sockaddr *, int);
  634. int cxgbi_ep_poll(struct iscsi_endpoint *, int);
  635. void cxgbi_ep_disconnect(struct iscsi_endpoint *);
  636. int cxgbi_iscsi_init(struct iscsi_transport *,
  637. struct scsi_transport_template **);
  638. void cxgbi_iscsi_cleanup(struct iscsi_transport *,
  639. struct scsi_transport_template **);
  640. void cxgbi_parse_pdu_itt(struct iscsi_conn *, itt_t, int *, int *);
  641. int cxgbi_ddp_init(struct cxgbi_device *, unsigned int, unsigned int,
  642. unsigned int, unsigned int);
  643. int cxgbi_ddp_cleanup(struct cxgbi_device *);
  644. void cxgbi_ddp_page_size_factor(int *);
  645. void cxgbi_ddp_ppod_clear(struct cxgbi_pagepod *);
  646. void cxgbi_ddp_ppod_set(struct cxgbi_pagepod *, struct cxgbi_pagepod_hdr *,
  647. struct cxgbi_gather_list *, unsigned int);
  648. #endif /*__LIBCXGBI_H__*/