libcxgbi.h 19 KB

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