libcxgbi.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  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. /*
  137. * sge_opaque_hdr -
  138. * Opaque version of structure the SGE stores at skb->head of TX_DATA packets
  139. * and for which we must reserve space.
  140. */
  141. struct sge_opaque_hdr {
  142. void *dev;
  143. dma_addr_t addr[MAX_SKB_FRAGS + 1];
  144. };
  145. struct cxgbi_sock {
  146. struct cxgbi_device *cdev;
  147. int tid;
  148. int atid;
  149. unsigned long flags;
  150. unsigned int mtu;
  151. unsigned short rss_qid;
  152. unsigned short txq_idx;
  153. unsigned short advmss;
  154. unsigned int tx_chan;
  155. unsigned int rx_chan;
  156. unsigned int mss_idx;
  157. unsigned int smac_idx;
  158. unsigned char port_id;
  159. int wr_max_cred;
  160. int wr_cred;
  161. int wr_una_cred;
  162. unsigned char hcrc_len;
  163. unsigned char dcrc_len;
  164. void *l2t;
  165. struct sk_buff *wr_pending_head;
  166. struct sk_buff *wr_pending_tail;
  167. struct sk_buff *cpl_close;
  168. struct sk_buff *cpl_abort_req;
  169. struct sk_buff *cpl_abort_rpl;
  170. struct sk_buff *skb_ulp_lhdr;
  171. spinlock_t lock;
  172. struct kref refcnt;
  173. unsigned int state;
  174. struct sockaddr_in saddr;
  175. struct sockaddr_in daddr;
  176. struct dst_entry *dst;
  177. struct sk_buff_head receive_queue;
  178. struct sk_buff_head write_queue;
  179. struct timer_list retry_timer;
  180. int err;
  181. rwlock_t callback_lock;
  182. void *user_data;
  183. u32 rcv_nxt;
  184. u32 copied_seq;
  185. u32 rcv_wup;
  186. u32 snd_nxt;
  187. u32 snd_una;
  188. u32 write_seq;
  189. };
  190. /*
  191. * connection states
  192. */
  193. enum cxgbi_sock_states{
  194. CTP_CLOSED,
  195. CTP_CONNECTING,
  196. CTP_ACTIVE_OPEN,
  197. CTP_ESTABLISHED,
  198. CTP_ACTIVE_CLOSE,
  199. CTP_PASSIVE_CLOSE,
  200. CTP_CLOSE_WAIT_1,
  201. CTP_CLOSE_WAIT_2,
  202. CTP_ABORTING,
  203. };
  204. /*
  205. * Connection flags -- many to track some close related events.
  206. */
  207. enum cxgbi_sock_flags {
  208. CTPF_ABORT_RPL_RCVD, /*received one ABORT_RPL_RSS message */
  209. CTPF_ABORT_REQ_RCVD, /*received one ABORT_REQ_RSS message */
  210. CTPF_ABORT_RPL_PENDING, /* expecting an abort reply */
  211. CTPF_TX_DATA_SENT, /* already sent a TX_DATA WR */
  212. CTPF_ACTIVE_CLOSE_NEEDED,/* need to be closed */
  213. CTPF_HAS_ATID, /* reserved atid */
  214. CTPF_HAS_TID, /* reserved hw tid */
  215. CTPF_OFFLOAD_DOWN, /* offload function off */
  216. };
  217. struct cxgbi_skb_rx_cb {
  218. __u32 ddigest;
  219. __u32 pdulen;
  220. };
  221. struct cxgbi_skb_tx_cb {
  222. void *l2t;
  223. struct sk_buff *wr_next;
  224. };
  225. enum cxgbi_skcb_flags {
  226. SKCBF_TX_NEED_HDR, /* packet needs a header */
  227. SKCBF_RX_COALESCED, /* received whole pdu */
  228. SKCBF_RX_HDR, /* recieved pdu header */
  229. SKCBF_RX_DATA, /* recieved pdu payload */
  230. SKCBF_RX_STATUS, /* recieved ddp status */
  231. SKCBF_RX_DATA_DDPD, /* pdu payload ddp'd */
  232. SKCBF_RX_HCRC_ERR, /* header digest error */
  233. SKCBF_RX_DCRC_ERR, /* data digest error */
  234. SKCBF_RX_PAD_ERR, /* padding byte error */
  235. };
  236. struct cxgbi_skb_cb {
  237. unsigned char ulp_mode;
  238. unsigned long flags;
  239. unsigned int seq;
  240. union {
  241. struct cxgbi_skb_rx_cb rx;
  242. struct cxgbi_skb_tx_cb tx;
  243. };
  244. };
  245. #define CXGBI_SKB_CB(skb) ((struct cxgbi_skb_cb *)&((skb)->cb[0]))
  246. #define cxgbi_skcb_flags(skb) (CXGBI_SKB_CB(skb)->flags)
  247. #define cxgbi_skcb_ulp_mode(skb) (CXGBI_SKB_CB(skb)->ulp_mode)
  248. #define cxgbi_skcb_tcp_seq(skb) (CXGBI_SKB_CB(skb)->seq)
  249. #define cxgbi_skcb_rx_ddigest(skb) (CXGBI_SKB_CB(skb)->rx.ddigest)
  250. #define cxgbi_skcb_rx_pdulen(skb) (CXGBI_SKB_CB(skb)->rx.pdulen)
  251. #define cxgbi_skcb_tx_wr_next(skb) (CXGBI_SKB_CB(skb)->tx.wr_next)
  252. static inline void cxgbi_skcb_set_flag(struct sk_buff *skb,
  253. enum cxgbi_skcb_flags flag)
  254. {
  255. __set_bit(flag, &(cxgbi_skcb_flags(skb)));
  256. }
  257. static inline void cxgbi_skcb_clear_flag(struct sk_buff *skb,
  258. enum cxgbi_skcb_flags flag)
  259. {
  260. __clear_bit(flag, &(cxgbi_skcb_flags(skb)));
  261. }
  262. static inline int cxgbi_skcb_test_flag(struct sk_buff *skb,
  263. enum cxgbi_skcb_flags flag)
  264. {
  265. return test_bit(flag, &(cxgbi_skcb_flags(skb)));
  266. }
  267. static inline void cxgbi_sock_set_flag(struct cxgbi_sock *csk,
  268. enum cxgbi_sock_flags flag)
  269. {
  270. __set_bit(flag, &csk->flags);
  271. log_debug(1 << CXGBI_DBG_SOCK,
  272. "csk 0x%p,%u,0x%lx, bit %d.\n",
  273. csk, csk->state, csk->flags, flag);
  274. }
  275. static inline void cxgbi_sock_clear_flag(struct cxgbi_sock *csk,
  276. enum cxgbi_sock_flags flag)
  277. {
  278. __clear_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 int cxgbi_sock_flag(struct cxgbi_sock *csk,
  284. enum cxgbi_sock_flags flag)
  285. {
  286. if (csk == NULL)
  287. return 0;
  288. return test_bit(flag, &csk->flags);
  289. }
  290. static inline void cxgbi_sock_set_state(struct cxgbi_sock *csk, int state)
  291. {
  292. log_debug(1 << CXGBI_DBG_SOCK,
  293. "csk 0x%p,%u,0x%lx, state -> %u.\n",
  294. csk, csk->state, csk->flags, state);
  295. csk->state = state;
  296. }
  297. static inline void cxgbi_sock_free(struct kref *kref)
  298. {
  299. struct cxgbi_sock *csk = container_of(kref,
  300. struct cxgbi_sock,
  301. refcnt);
  302. if (csk) {
  303. log_debug(1 << CXGBI_DBG_SOCK,
  304. "free csk 0x%p, state %u, flags 0x%lx\n",
  305. csk, csk->state, csk->flags);
  306. kfree(csk);
  307. }
  308. }
  309. static inline void __cxgbi_sock_put(const char *fn, struct cxgbi_sock *csk)
  310. {
  311. log_debug(1 << CXGBI_DBG_SOCK,
  312. "%s, put csk 0x%p, ref %u-1.\n",
  313. fn, csk, atomic_read(&csk->refcnt.refcount));
  314. kref_put(&csk->refcnt, cxgbi_sock_free);
  315. }
  316. #define cxgbi_sock_put(csk) __cxgbi_sock_put(__func__, csk)
  317. static inline void __cxgbi_sock_get(const char *fn, struct cxgbi_sock *csk)
  318. {
  319. log_debug(1 << CXGBI_DBG_SOCK,
  320. "%s, get csk 0x%p, ref %u+1.\n",
  321. fn, csk, atomic_read(&csk->refcnt.refcount));
  322. kref_get(&csk->refcnt);
  323. }
  324. #define cxgbi_sock_get(csk) __cxgbi_sock_get(__func__, csk)
  325. static inline int cxgbi_sock_is_closing(struct cxgbi_sock *csk)
  326. {
  327. return csk->state >= CTP_ACTIVE_CLOSE;
  328. }
  329. static inline int cxgbi_sock_is_established(struct cxgbi_sock *csk)
  330. {
  331. return csk->state == CTP_ESTABLISHED;
  332. }
  333. static inline void cxgbi_sock_purge_write_queue(struct cxgbi_sock *csk)
  334. {
  335. struct sk_buff *skb;
  336. while ((skb = __skb_dequeue(&csk->write_queue)))
  337. __kfree_skb(skb);
  338. }
  339. static inline unsigned int cxgbi_sock_compute_wscale(unsigned int win)
  340. {
  341. unsigned int wscale = 0;
  342. while (wscale < 14 && (65535 << wscale) < win)
  343. wscale++;
  344. return wscale;
  345. }
  346. static inline struct sk_buff *alloc_wr(int wrlen, int dlen, gfp_t gfp)
  347. {
  348. struct sk_buff *skb = alloc_skb(wrlen + dlen, gfp);
  349. if (skb) {
  350. __skb_put(skb, wrlen);
  351. memset(skb->head, 0, wrlen + dlen);
  352. } else
  353. pr_info("alloc cpl wr skb %u+%u, OOM.\n", wrlen, dlen);
  354. return skb;
  355. }
  356. /*
  357. * The number of WRs needed for an skb depends on the number of fragments
  358. * in the skb and whether it has any payload in its main body. This maps the
  359. * length of the gather list represented by an skb into the # of necessary WRs.
  360. * The extra two fragments are for iscsi bhs and payload padding.
  361. */
  362. #define SKB_WR_LIST_SIZE (MAX_SKB_FRAGS + 2)
  363. static inline void cxgbi_sock_reset_wr_list(struct cxgbi_sock *csk)
  364. {
  365. csk->wr_pending_head = csk->wr_pending_tail = NULL;
  366. }
  367. static inline void cxgbi_sock_enqueue_wr(struct cxgbi_sock *csk,
  368. struct sk_buff *skb)
  369. {
  370. cxgbi_skcb_tx_wr_next(skb) = NULL;
  371. /*
  372. * We want to take an extra reference since both us and the driver
  373. * need to free the packet before it's really freed. We know there's
  374. * just one user currently so we use atomic_set rather than skb_get
  375. * to avoid the atomic op.
  376. */
  377. atomic_set(&skb->users, 2);
  378. if (!csk->wr_pending_head)
  379. csk->wr_pending_head = skb;
  380. else
  381. cxgbi_skcb_tx_wr_next(csk->wr_pending_tail) = skb;
  382. csk->wr_pending_tail = skb;
  383. }
  384. static inline int cxgbi_sock_count_pending_wrs(const struct cxgbi_sock *csk)
  385. {
  386. int n = 0;
  387. const struct sk_buff *skb = csk->wr_pending_head;
  388. while (skb) {
  389. n += skb->csum;
  390. skb = cxgbi_skcb_tx_wr_next(skb);
  391. }
  392. return n;
  393. }
  394. static inline struct sk_buff *cxgbi_sock_peek_wr(const struct cxgbi_sock *csk)
  395. {
  396. return csk->wr_pending_head;
  397. }
  398. static inline struct sk_buff *cxgbi_sock_dequeue_wr(struct cxgbi_sock *csk)
  399. {
  400. struct sk_buff *skb = csk->wr_pending_head;
  401. if (likely(skb)) {
  402. csk->wr_pending_head = cxgbi_skcb_tx_wr_next(skb);
  403. cxgbi_skcb_tx_wr_next(skb) = NULL;
  404. }
  405. return skb;
  406. }
  407. void cxgbi_sock_check_wr_invariants(const struct cxgbi_sock *);
  408. void cxgbi_sock_purge_wr_queue(struct cxgbi_sock *);
  409. void cxgbi_sock_skb_entail(struct cxgbi_sock *, struct sk_buff *);
  410. void cxgbi_sock_fail_act_open(struct cxgbi_sock *, int);
  411. void cxgbi_sock_act_open_req_arp_failure(void *, struct sk_buff *);
  412. void cxgbi_sock_closed(struct cxgbi_sock *);
  413. void cxgbi_sock_established(struct cxgbi_sock *, unsigned int, unsigned int);
  414. void cxgbi_sock_rcv_abort_rpl(struct cxgbi_sock *);
  415. void cxgbi_sock_rcv_peer_close(struct cxgbi_sock *);
  416. void cxgbi_sock_rcv_close_conn_rpl(struct cxgbi_sock *, u32);
  417. void cxgbi_sock_rcv_wr_ack(struct cxgbi_sock *, unsigned int, unsigned int,
  418. int);
  419. unsigned int cxgbi_sock_select_mss(struct cxgbi_sock *, unsigned int);
  420. void cxgbi_sock_free_cpl_skbs(struct cxgbi_sock *);
  421. struct cxgbi_hba {
  422. struct net_device *ndev;
  423. struct net_device *vdev; /* vlan dev */
  424. struct Scsi_Host *shost;
  425. struct cxgbi_device *cdev;
  426. __be32 ipv4addr;
  427. unsigned char port_id;
  428. };
  429. struct cxgbi_ports_map {
  430. unsigned int max_connect;
  431. unsigned int used;
  432. unsigned short sport_base;
  433. spinlock_t lock;
  434. unsigned int next;
  435. struct cxgbi_sock **port_csk;
  436. };
  437. #define CXGBI_FLAG_DEV_T3 0x1
  438. #define CXGBI_FLAG_DEV_T4 0x2
  439. #define CXGBI_FLAG_ADAPTER_RESET 0x4
  440. #define CXGBI_FLAG_IPV4_SET 0x10
  441. struct cxgbi_device {
  442. struct list_head list_head;
  443. unsigned int flags;
  444. struct net_device **ports;
  445. void *lldev;
  446. struct cxgbi_hba **hbas;
  447. const unsigned short *mtus;
  448. unsigned char nmtus;
  449. unsigned char nports;
  450. struct pci_dev *pdev;
  451. struct dentry *debugfs_root;
  452. struct iscsi_transport *itp;
  453. unsigned int pfvf;
  454. unsigned int snd_win;
  455. unsigned int rcv_win;
  456. unsigned int rx_credit_thres;
  457. unsigned int skb_tx_rsvd;
  458. unsigned int skb_rx_extra; /* for msg coalesced mode */
  459. unsigned int tx_max_size;
  460. unsigned int rx_max_size;
  461. struct cxgbi_ports_map pmap;
  462. struct cxgbi_tag_format tag_format;
  463. struct cxgbi_ddp_info *ddp;
  464. void (*dev_ddp_cleanup)(struct cxgbi_device *);
  465. void (*csk_ddp_free_gl_skb)(struct cxgbi_ddp_info *, int, int);
  466. int (*csk_ddp_alloc_gl_skb)(struct cxgbi_ddp_info *, int, int, gfp_t);
  467. int (*csk_ddp_set)(struct cxgbi_sock *, struct cxgbi_pagepod_hdr *,
  468. unsigned int, unsigned int,
  469. struct cxgbi_gather_list *);
  470. void (*csk_ddp_clear)(struct cxgbi_hba *,
  471. unsigned int, unsigned int, unsigned int);
  472. int (*csk_ddp_setup_digest)(struct cxgbi_sock *,
  473. unsigned int, int, int, int);
  474. int (*csk_ddp_setup_pgidx)(struct cxgbi_sock *,
  475. unsigned int, int, bool);
  476. void (*csk_release_offload_resources)(struct cxgbi_sock *);
  477. int (*csk_rx_pdu_ready)(struct cxgbi_sock *, struct sk_buff *);
  478. u32 (*csk_send_rx_credits)(struct cxgbi_sock *, u32);
  479. int (*csk_push_tx_frames)(struct cxgbi_sock *, int);
  480. void (*csk_send_abort_req)(struct cxgbi_sock *);
  481. void (*csk_send_close_req)(struct cxgbi_sock *);
  482. int (*csk_alloc_cpls)(struct cxgbi_sock *);
  483. int (*csk_init_act_open)(struct cxgbi_sock *);
  484. void *dd_data;
  485. };
  486. #define cxgbi_cdev_priv(cdev) ((cdev)->dd_data)
  487. struct cxgbi_conn {
  488. struct cxgbi_endpoint *cep;
  489. struct iscsi_conn *iconn;
  490. struct cxgbi_hba *chba;
  491. u32 task_idx_bits;
  492. };
  493. struct cxgbi_endpoint {
  494. struct cxgbi_conn *cconn;
  495. struct cxgbi_hba *chba;
  496. struct cxgbi_sock *csk;
  497. };
  498. #define MAX_PDU_FRAGS ((ULP2_MAX_PDU_PAYLOAD + 512 - 1) / 512)
  499. struct cxgbi_task_data {
  500. unsigned short nr_frags;
  501. skb_frag_t frags[MAX_PDU_FRAGS];
  502. struct sk_buff *skb;
  503. unsigned int offset;
  504. unsigned int count;
  505. unsigned int sgoffset;
  506. };
  507. #define iscsi_task_cxgbi_data(task) \
  508. ((task)->dd_data + sizeof(struct iscsi_tcp_task))
  509. static inline int cxgbi_is_ddp_tag(struct cxgbi_tag_format *tformat, u32 tag)
  510. {
  511. return !(tag & (1 << (tformat->rsvd_bits + tformat->rsvd_shift - 1)));
  512. }
  513. static inline int cxgbi_sw_tag_usable(struct cxgbi_tag_format *tformat,
  514. u32 sw_tag)
  515. {
  516. sw_tag >>= (32 - tformat->rsvd_bits);
  517. return !sw_tag;
  518. }
  519. static inline u32 cxgbi_set_non_ddp_tag(struct cxgbi_tag_format *tformat,
  520. u32 sw_tag)
  521. {
  522. unsigned char shift = tformat->rsvd_bits + tformat->rsvd_shift - 1;
  523. u32 mask = (1 << shift) - 1;
  524. if (sw_tag && (sw_tag & ~mask)) {
  525. u32 v1 = sw_tag & ((1 << shift) - 1);
  526. u32 v2 = (sw_tag >> (shift - 1)) << shift;
  527. return v2 | v1 | 1 << shift;
  528. }
  529. return sw_tag | 1 << shift;
  530. }
  531. static inline u32 cxgbi_ddp_tag_base(struct cxgbi_tag_format *tformat,
  532. u32 sw_tag)
  533. {
  534. u32 mask = (1 << tformat->rsvd_shift) - 1;
  535. if (sw_tag && (sw_tag & ~mask)) {
  536. u32 v1 = sw_tag & mask;
  537. u32 v2 = sw_tag >> tformat->rsvd_shift;
  538. v2 <<= tformat->rsvd_bits + tformat->rsvd_shift;
  539. return v2 | v1;
  540. }
  541. return sw_tag;
  542. }
  543. static inline u32 cxgbi_tag_rsvd_bits(struct cxgbi_tag_format *tformat,
  544. u32 tag)
  545. {
  546. if (cxgbi_is_ddp_tag(tformat, tag))
  547. return (tag >> tformat->rsvd_shift) & tformat->rsvd_mask;
  548. return 0;
  549. }
  550. static inline u32 cxgbi_tag_nonrsvd_bits(struct cxgbi_tag_format *tformat,
  551. u32 tag)
  552. {
  553. unsigned char shift = tformat->rsvd_bits + tformat->rsvd_shift - 1;
  554. u32 v1, v2;
  555. if (cxgbi_is_ddp_tag(tformat, tag)) {
  556. v1 = tag & ((1 << tformat->rsvd_shift) - 1);
  557. v2 = (tag >> (shift + 1)) << tformat->rsvd_shift;
  558. } else {
  559. u32 mask = (1 << shift) - 1;
  560. tag &= ~(1 << shift);
  561. v1 = tag & mask;
  562. v2 = (tag >> 1) & ~mask;
  563. }
  564. return v1 | v2;
  565. }
  566. static inline void *cxgbi_alloc_big_mem(unsigned int size,
  567. gfp_t gfp)
  568. {
  569. void *p = kmalloc(size, gfp);
  570. if (!p)
  571. p = vmalloc(size);
  572. if (p)
  573. memset(p, 0, size);
  574. return p;
  575. }
  576. static inline void cxgbi_free_big_mem(void *addr)
  577. {
  578. if (is_vmalloc_addr(addr))
  579. vfree(addr);
  580. else
  581. kfree(addr);
  582. }
  583. static inline void cxgbi_set_iscsi_ipv4(struct cxgbi_hba *chba, __be32 ipaddr)
  584. {
  585. if (chba->cdev->flags & CXGBI_FLAG_IPV4_SET)
  586. chba->ipv4addr = ipaddr;
  587. else
  588. pr_info("set iscsi ipv4 NOT supported, using %s ipv4.\n",
  589. chba->ndev->name);
  590. }
  591. static inline __be32 cxgbi_get_iscsi_ipv4(struct cxgbi_hba *chba)
  592. {
  593. return chba->ipv4addr;
  594. }
  595. struct cxgbi_device *cxgbi_device_register(unsigned int, unsigned int);
  596. void cxgbi_device_unregister(struct cxgbi_device *);
  597. void cxgbi_device_unregister_all(unsigned int flag);
  598. struct cxgbi_device *cxgbi_device_find_by_lldev(void *);
  599. int cxgbi_hbas_add(struct cxgbi_device *, unsigned int, unsigned int,
  600. struct scsi_host_template *,
  601. struct scsi_transport_template *);
  602. void cxgbi_hbas_remove(struct cxgbi_device *);
  603. int cxgbi_device_portmap_create(struct cxgbi_device *cdev, unsigned int base,
  604. unsigned int max_conn);
  605. void cxgbi_device_portmap_cleanup(struct cxgbi_device *cdev);
  606. void cxgbi_conn_tx_open(struct cxgbi_sock *);
  607. void cxgbi_conn_pdu_ready(struct cxgbi_sock *);
  608. int cxgbi_conn_alloc_pdu(struct iscsi_task *, u8);
  609. int cxgbi_conn_init_pdu(struct iscsi_task *, unsigned int , unsigned int);
  610. int cxgbi_conn_xmit_pdu(struct iscsi_task *);
  611. void cxgbi_cleanup_task(struct iscsi_task *task);
  612. void cxgbi_get_conn_stats(struct iscsi_cls_conn *, struct iscsi_stats *);
  613. int cxgbi_set_conn_param(struct iscsi_cls_conn *,
  614. enum iscsi_param, char *, int);
  615. int cxgbi_get_conn_param(struct iscsi_cls_conn *, enum iscsi_param, char *);
  616. struct iscsi_cls_conn *cxgbi_create_conn(struct iscsi_cls_session *, u32);
  617. int cxgbi_bind_conn(struct iscsi_cls_session *,
  618. struct iscsi_cls_conn *, u64, int);
  619. void cxgbi_destroy_session(struct iscsi_cls_session *);
  620. struct iscsi_cls_session *cxgbi_create_session(struct iscsi_endpoint *,
  621. u16, u16, u32);
  622. int cxgbi_set_host_param(struct Scsi_Host *,
  623. enum iscsi_host_param, char *, int);
  624. int cxgbi_get_host_param(struct Scsi_Host *, enum iscsi_host_param, char *);
  625. struct iscsi_endpoint *cxgbi_ep_connect(struct Scsi_Host *,
  626. struct sockaddr *, int);
  627. int cxgbi_ep_poll(struct iscsi_endpoint *, int);
  628. void cxgbi_ep_disconnect(struct iscsi_endpoint *);
  629. int cxgbi_iscsi_init(struct iscsi_transport *,
  630. struct scsi_transport_template **);
  631. void cxgbi_iscsi_cleanup(struct iscsi_transport *,
  632. struct scsi_transport_template **);
  633. void cxgbi_parse_pdu_itt(struct iscsi_conn *, itt_t, int *, int *);
  634. int cxgbi_ddp_init(struct cxgbi_device *, unsigned int, unsigned int,
  635. unsigned int, unsigned int);
  636. int cxgbi_ddp_cleanup(struct cxgbi_device *);
  637. void cxgbi_ddp_page_size_factor(int *);
  638. void cxgbi_ddp_ppod_clear(struct cxgbi_pagepod *);
  639. void cxgbi_ddp_ppod_set(struct cxgbi_pagepod *, struct cxgbi_pagepod_hdr *,
  640. struct cxgbi_gather_list *, unsigned int);
  641. #endif /*__LIBCXGBI_H__*/