libcxgbi.h 20 KB

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