iscsi_iser.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. /*
  2. * iSER transport for the Open iSCSI Initiator & iSER transport internals
  3. *
  4. * Copyright (C) 2004 Dmitry Yusupov
  5. * Copyright (C) 2004 Alex Aizman
  6. * Copyright (C) 2005 Mike Christie
  7. * based on code maintained by open-iscsi@googlegroups.com
  8. *
  9. * Copyright (c) 2004, 2005, 2006 Voltaire, Inc. All rights reserved.
  10. * Copyright (c) 2005, 2006 Cisco Systems. All rights reserved.
  11. * Copyright (c) 2013-2014 Mellanox Technologies. All rights reserved.
  12. *
  13. * This software is available to you under a choice of one of two
  14. * licenses. You may choose to be licensed under the terms of the GNU
  15. * General Public License (GPL) Version 2, available from the file
  16. * COPYING in the main directory of this source tree, or the
  17. * OpenIB.org BSD license below:
  18. *
  19. * Redistribution and use in source and binary forms, with or
  20. * without modification, are permitted provided that the following
  21. * conditions are met:
  22. *
  23. * - Redistributions of source code must retain the above
  24. * copyright notice, this list of conditions and the following
  25. * disclaimer.
  26. *
  27. * - Redistributions in binary form must reproduce the above
  28. * copyright notice, this list of conditions and the following
  29. * disclaimer in the documentation and/or other materials
  30. * provided with the distribution.
  31. *
  32. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  33. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  34. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  35. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  36. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  37. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  38. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  39. * SOFTWARE.
  40. */
  41. #ifndef __ISCSI_ISER_H__
  42. #define __ISCSI_ISER_H__
  43. #include <linux/types.h>
  44. #include <linux/net.h>
  45. #include <linux/printk.h>
  46. #include <scsi/libiscsi.h>
  47. #include <scsi/scsi_transport_iscsi.h>
  48. #include <scsi/scsi_cmnd.h>
  49. #include <scsi/scsi_device.h>
  50. #include <scsi/iser.h>
  51. #include <linux/interrupt.h>
  52. #include <linux/wait.h>
  53. #include <linux/sched.h>
  54. #include <linux/list.h>
  55. #include <linux/slab.h>
  56. #include <linux/dma-mapping.h>
  57. #include <linux/mutex.h>
  58. #include <linux/mempool.h>
  59. #include <linux/uio.h>
  60. #include <linux/socket.h>
  61. #include <linux/in.h>
  62. #include <linux/in6.h>
  63. #include <rdma/ib_verbs.h>
  64. #include <rdma/ib_fmr_pool.h>
  65. #include <rdma/rdma_cm.h>
  66. #define DRV_NAME "iser"
  67. #define PFX DRV_NAME ": "
  68. #define DRV_VER "1.6"
  69. #define iser_dbg(fmt, arg...) \
  70. do { \
  71. if (unlikely(iser_debug_level > 2)) \
  72. printk(KERN_DEBUG PFX "%s: " fmt,\
  73. __func__ , ## arg); \
  74. } while (0)
  75. #define iser_warn(fmt, arg...) \
  76. do { \
  77. if (unlikely(iser_debug_level > 0)) \
  78. pr_warn(PFX "%s: " fmt, \
  79. __func__ , ## arg); \
  80. } while (0)
  81. #define iser_info(fmt, arg...) \
  82. do { \
  83. if (unlikely(iser_debug_level > 1)) \
  84. pr_info(PFX "%s: " fmt, \
  85. __func__ , ## arg); \
  86. } while (0)
  87. #define iser_err(fmt, arg...) \
  88. pr_err(PFX "%s: " fmt, __func__ , ## arg)
  89. #define SHIFT_4K 12
  90. #define SIZE_4K (1ULL << SHIFT_4K)
  91. #define MASK_4K (~(SIZE_4K-1))
  92. /* Default support is 512KB I/O size */
  93. #define ISER_DEF_MAX_SECTORS 1024
  94. #define ISCSI_ISER_DEF_SG_TABLESIZE ((ISER_DEF_MAX_SECTORS * 512) >> SHIFT_4K)
  95. /* Maximum support is 8MB I/O size */
  96. #define ISCSI_ISER_MAX_SG_TABLESIZE ((16384 * 512) >> SHIFT_4K)
  97. #define ISER_DEF_XMIT_CMDS_DEFAULT 512
  98. #if ISCSI_DEF_XMIT_CMDS_MAX > ISER_DEF_XMIT_CMDS_DEFAULT
  99. #define ISER_DEF_XMIT_CMDS_MAX ISCSI_DEF_XMIT_CMDS_MAX
  100. #else
  101. #define ISER_DEF_XMIT_CMDS_MAX ISER_DEF_XMIT_CMDS_DEFAULT
  102. #endif
  103. #define ISER_DEF_CMD_PER_LUN ISER_DEF_XMIT_CMDS_MAX
  104. /* QP settings */
  105. /* Maximal bounds on received asynchronous PDUs */
  106. #define ISER_MAX_RX_MISC_PDUS 4 /* NOOP_IN(2) , ASYNC_EVENT(2) */
  107. #define ISER_MAX_TX_MISC_PDUS 6 /* NOOP_OUT(2), TEXT(1), *
  108. * SCSI_TMFUNC(2), LOGOUT(1) */
  109. #define ISER_QP_MAX_RECV_DTOS (ISER_DEF_XMIT_CMDS_MAX)
  110. #define ISER_MIN_POSTED_RX (ISER_DEF_XMIT_CMDS_MAX >> 2)
  111. /* the max TX (send) WR supported by the iSER QP is defined by *
  112. * max_send_wr = T * (1 + D) + C ; D is how many inflight dataouts we expect *
  113. * to have at max for SCSI command. The tx posting & completion handling code *
  114. * supports -EAGAIN scheme where tx is suspended till the QP has room for more *
  115. * send WR. D=8 comes from 64K/8K */
  116. #define ISER_INFLIGHT_DATAOUTS 8
  117. #define ISER_QP_MAX_REQ_DTOS (ISER_DEF_XMIT_CMDS_MAX * \
  118. (1 + ISER_INFLIGHT_DATAOUTS) + \
  119. ISER_MAX_TX_MISC_PDUS + \
  120. ISER_MAX_RX_MISC_PDUS)
  121. /* Max registration work requests per command */
  122. #define ISER_MAX_REG_WR_PER_CMD 5
  123. /* For Signature we don't support DATAOUTs so no need to make room for them */
  124. #define ISER_QP_SIG_MAX_REQ_DTOS (ISER_DEF_XMIT_CMDS_MAX * \
  125. (1 + ISER_MAX_REG_WR_PER_CMD) + \
  126. ISER_MAX_TX_MISC_PDUS + \
  127. ISER_MAX_RX_MISC_PDUS)
  128. #define ISER_GET_MAX_XMIT_CMDS(send_wr) ((send_wr \
  129. - ISER_MAX_TX_MISC_PDUS \
  130. - ISER_MAX_RX_MISC_PDUS) / \
  131. (1 + ISER_INFLIGHT_DATAOUTS))
  132. #define ISER_SIGNAL_CMD_COUNT 32
  133. /* Constant PDU lengths calculations */
  134. #define ISER_HEADERS_LEN (sizeof(struct iser_ctrl) + sizeof(struct iscsi_hdr))
  135. #define ISER_RECV_DATA_SEG_LEN 128
  136. #define ISER_RX_PAYLOAD_SIZE (ISER_HEADERS_LEN + ISER_RECV_DATA_SEG_LEN)
  137. #define ISER_RX_LOGIN_SIZE (ISER_HEADERS_LEN + ISCSI_DEF_MAX_RECV_SEG_LEN)
  138. /* Length of an object name string */
  139. #define ISER_OBJECT_NAME_SIZE 64
  140. enum iser_conn_state {
  141. ISER_CONN_INIT, /* descriptor allocd, no conn */
  142. ISER_CONN_PENDING, /* in the process of being established */
  143. ISER_CONN_UP, /* up and running */
  144. ISER_CONN_TERMINATING, /* in the process of being terminated */
  145. ISER_CONN_DOWN, /* shut down */
  146. ISER_CONN_STATES_NUM
  147. };
  148. enum iser_task_status {
  149. ISER_TASK_STATUS_INIT = 0,
  150. ISER_TASK_STATUS_STARTED,
  151. ISER_TASK_STATUS_COMPLETED
  152. };
  153. enum iser_data_dir {
  154. ISER_DIR_IN = 0, /* to initiator */
  155. ISER_DIR_OUT, /* from initiator */
  156. ISER_DIRS_NUM
  157. };
  158. /**
  159. * struct iser_data_buf - iSER data buffer
  160. *
  161. * @sg: pointer to the sg list
  162. * @size: num entries of this sg
  163. * @data_len: total beffer byte len
  164. * @dma_nents: returned by dma_map_sg
  165. */
  166. struct iser_data_buf {
  167. struct scatterlist *sg;
  168. int size;
  169. unsigned long data_len;
  170. unsigned int dma_nents;
  171. };
  172. /* fwd declarations */
  173. struct iser_device;
  174. struct iscsi_iser_task;
  175. struct iscsi_endpoint;
  176. struct iser_reg_resources;
  177. /**
  178. * struct iser_mem_reg - iSER memory registration info
  179. *
  180. * @sge: memory region sg element
  181. * @rkey: memory region remote key
  182. * @mem_h: pointer to registration context (FMR/Fastreg)
  183. */
  184. struct iser_mem_reg {
  185. struct ib_sge sge;
  186. u32 rkey;
  187. void *mem_h;
  188. };
  189. enum iser_desc_type {
  190. ISCSI_TX_CONTROL ,
  191. ISCSI_TX_SCSI_COMMAND,
  192. ISCSI_TX_DATAOUT
  193. };
  194. /* Maximum number of work requests per task:
  195. * Data memory region local invalidate + fast registration
  196. * Protection memory region local invalidate + fast registration
  197. * Signature memory region local invalidate + fast registration
  198. * PDU send
  199. */
  200. #define ISER_MAX_WRS 7
  201. /**
  202. * struct iser_tx_desc - iSER TX descriptor
  203. *
  204. * @iser_header: iser header
  205. * @iscsi_header: iscsi header
  206. * @type: command/control/dataout
  207. * @dam_addr: header buffer dma_address
  208. * @tx_sg: sg[0] points to iser/iscsi headers
  209. * sg[1] optionally points to either of immediate data
  210. * unsolicited data-out or control
  211. * @num_sge: number sges used on this TX task
  212. * @mapped: Is the task header mapped
  213. * @wr_idx: Current WR index
  214. * @wrs: Array of WRs per task
  215. * @data_reg: Data buffer registration details
  216. * @prot_reg: Protection buffer registration details
  217. * @sig_attrs: Signature attributes
  218. */
  219. struct iser_tx_desc {
  220. struct iser_ctrl iser_header;
  221. struct iscsi_hdr iscsi_header;
  222. enum iser_desc_type type;
  223. u64 dma_addr;
  224. struct ib_sge tx_sg[2];
  225. int num_sge;
  226. struct ib_cqe cqe;
  227. bool mapped;
  228. u8 wr_idx;
  229. union iser_wr {
  230. struct ib_send_wr send;
  231. struct ib_reg_wr fast_reg;
  232. struct ib_sig_handover_wr sig;
  233. } wrs[ISER_MAX_WRS];
  234. struct iser_mem_reg data_reg;
  235. struct iser_mem_reg prot_reg;
  236. struct ib_sig_attrs sig_attrs;
  237. };
  238. #define ISER_RX_PAD_SIZE (256 - (ISER_RX_PAYLOAD_SIZE + \
  239. sizeof(u64) + sizeof(struct ib_sge) + \
  240. sizeof(struct ib_cqe)))
  241. /**
  242. * struct iser_rx_desc - iSER RX descriptor
  243. *
  244. * @iser_header: iser header
  245. * @iscsi_header: iscsi header
  246. * @data: received data segment
  247. * @dma_addr: receive buffer dma address
  248. * @rx_sg: ib_sge of receive buffer
  249. * @pad: for sense data TODO: Modify to maximum sense length supported
  250. */
  251. struct iser_rx_desc {
  252. struct iser_ctrl iser_header;
  253. struct iscsi_hdr iscsi_header;
  254. char data[ISER_RECV_DATA_SEG_LEN];
  255. u64 dma_addr;
  256. struct ib_sge rx_sg;
  257. struct ib_cqe cqe;
  258. char pad[ISER_RX_PAD_SIZE];
  259. } __packed;
  260. /**
  261. * struct iser_login_desc - iSER login descriptor
  262. *
  263. * @req: pointer to login request buffer
  264. * @resp: pointer to login response buffer
  265. * @req_dma: DMA address of login request buffer
  266. * @rsp_dma: DMA address of login response buffer
  267. * @sge: IB sge for login post recv
  268. * @cqe: completion handler
  269. */
  270. struct iser_login_desc {
  271. void *req;
  272. void *rsp;
  273. u64 req_dma;
  274. u64 rsp_dma;
  275. struct ib_sge sge;
  276. struct ib_cqe cqe;
  277. } __attribute__((packed));
  278. struct iser_conn;
  279. struct ib_conn;
  280. struct iscsi_iser_task;
  281. /**
  282. * struct iser_comp - iSER completion context
  283. *
  284. * @cq: completion queue
  285. * @active_qps: Number of active QPs attached
  286. * to completion context
  287. */
  288. struct iser_comp {
  289. struct ib_cq *cq;
  290. int active_qps;
  291. };
  292. /**
  293. * struct iser_device - Memory registration operations
  294. * per-device registration schemes
  295. *
  296. * @alloc_reg_res: Allocate registration resources
  297. * @free_reg_res: Free registration resources
  298. * @fast_reg_mem: Register memory buffers
  299. * @unreg_mem: Un-register memory buffers
  300. * @reg_desc_get: Get a registration descriptor for pool
  301. * @reg_desc_put: Get a registration descriptor to pool
  302. */
  303. struct iser_reg_ops {
  304. int (*alloc_reg_res)(struct ib_conn *ib_conn,
  305. unsigned cmds_max,
  306. unsigned int size);
  307. void (*free_reg_res)(struct ib_conn *ib_conn);
  308. int (*reg_mem)(struct iscsi_iser_task *iser_task,
  309. struct iser_data_buf *mem,
  310. struct iser_reg_resources *rsc,
  311. struct iser_mem_reg *reg);
  312. void (*unreg_mem)(struct iscsi_iser_task *iser_task,
  313. enum iser_data_dir cmd_dir);
  314. struct iser_fr_desc * (*reg_desc_get)(struct ib_conn *ib_conn);
  315. void (*reg_desc_put)(struct ib_conn *ib_conn,
  316. struct iser_fr_desc *desc);
  317. };
  318. /**
  319. * struct iser_device - iSER device handle
  320. *
  321. * @ib_device: RDMA device
  322. * @pd: Protection Domain for this device
  323. * @mr: Global DMA memory region
  324. * @event_handler: IB events handle routine
  325. * @ig_list: entry in devices list
  326. * @refcount: Reference counter, dominated by open iser connections
  327. * @comps_used: Number of completion contexts used, Min between online
  328. * cpus and device max completion vectors
  329. * @comps: Dinamically allocated array of completion handlers
  330. * @reg_ops: Registration ops
  331. * @remote_inv_sup: Remote invalidate is supported on this device
  332. */
  333. struct iser_device {
  334. struct ib_device *ib_device;
  335. struct ib_pd *pd;
  336. struct ib_event_handler event_handler;
  337. struct list_head ig_list;
  338. int refcount;
  339. int comps_used;
  340. struct iser_comp *comps;
  341. const struct iser_reg_ops *reg_ops;
  342. bool remote_inv_sup;
  343. };
  344. #define ISER_CHECK_GUARD 0xc0
  345. #define ISER_CHECK_REFTAG 0x0f
  346. #define ISER_CHECK_APPTAG 0x30
  347. /**
  348. * struct iser_reg_resources - Fast registration recources
  349. *
  350. * @mr: memory region
  351. * @fmr_pool: pool of fmrs
  352. * @page_vec: fast reg page list used by fmr pool
  353. * @mr_valid: is mr valid indicator
  354. */
  355. struct iser_reg_resources {
  356. union {
  357. struct ib_mr *mr;
  358. struct ib_fmr_pool *fmr_pool;
  359. };
  360. struct iser_page_vec *page_vec;
  361. u8 mr_valid:1;
  362. };
  363. /**
  364. * struct iser_pi_context - Protection information context
  365. *
  366. * @rsc: protection buffer registration resources
  367. * @sig_mr: signature enable memory region
  368. * @sig_mr_valid: is sig_mr valid indicator
  369. * @sig_protected: is region protected indicator
  370. */
  371. struct iser_pi_context {
  372. struct iser_reg_resources rsc;
  373. struct ib_mr *sig_mr;
  374. u8 sig_mr_valid:1;
  375. u8 sig_protected:1;
  376. };
  377. /**
  378. * struct iser_fr_desc - Fast registration descriptor
  379. *
  380. * @list: entry in connection fastreg pool
  381. * @rsc: data buffer registration resources
  382. * @pi_ctx: protection information context
  383. */
  384. struct iser_fr_desc {
  385. struct list_head list;
  386. struct iser_reg_resources rsc;
  387. struct iser_pi_context *pi_ctx;
  388. struct list_head all_list;
  389. };
  390. /**
  391. * struct iser_fr_pool: connection fast registration pool
  392. *
  393. * @list: list of fastreg descriptors
  394. * @lock: protects fmr/fastreg pool
  395. * @size: size of the pool
  396. */
  397. struct iser_fr_pool {
  398. struct list_head list;
  399. spinlock_t lock;
  400. int size;
  401. struct list_head all_list;
  402. };
  403. /**
  404. * struct ib_conn - Infiniband related objects
  405. *
  406. * @cma_id: rdma_cm connection maneger handle
  407. * @qp: Connection Queue-pair
  408. * @post_recv_buf_count: post receive counter
  409. * @sig_count: send work request signal count
  410. * @rx_wr: receive work request for batch posts
  411. * @device: reference to iser device
  412. * @comp: iser completion context
  413. * @fr_pool: connection fast registration poool
  414. * @pi_support: Indicate device T10-PI support
  415. */
  416. struct ib_conn {
  417. struct rdma_cm_id *cma_id;
  418. struct ib_qp *qp;
  419. int post_recv_buf_count;
  420. u8 sig_count;
  421. struct ib_recv_wr rx_wr[ISER_MIN_POSTED_RX];
  422. struct iser_device *device;
  423. struct iser_comp *comp;
  424. struct iser_fr_pool fr_pool;
  425. bool pi_support;
  426. struct ib_cqe reg_cqe;
  427. };
  428. /**
  429. * struct iser_conn - iSER connection context
  430. *
  431. * @ib_conn: connection RDMA resources
  432. * @iscsi_conn: link to matching iscsi connection
  433. * @ep: transport handle
  434. * @state: connection logical state
  435. * @qp_max_recv_dtos: maximum number of data outs, corresponds
  436. * to max number of post recvs
  437. * @qp_max_recv_dtos_mask: (qp_max_recv_dtos - 1)
  438. * @min_posted_rx: (qp_max_recv_dtos >> 2)
  439. * @max_cmds: maximum cmds allowed for this connection
  440. * @name: connection peer portal
  441. * @release_work: deffered work for release job
  442. * @state_mutex: protects iser onnection state
  443. * @stop_completion: conn_stop completion
  444. * @ib_completion: RDMA cleanup completion
  445. * @up_completion: connection establishment completed
  446. * (state is ISER_CONN_UP)
  447. * @conn_list: entry in ig conn list
  448. * @login_desc: login descriptor
  449. * @rx_desc_head: head of rx_descs cyclic buffer
  450. * @rx_descs: rx buffers array (cyclic buffer)
  451. * @num_rx_descs: number of rx descriptors
  452. * @scsi_sg_tablesize: scsi host sg_tablesize
  453. * @scsi_max_sectors: scsi host max sectors
  454. */
  455. struct iser_conn {
  456. struct ib_conn ib_conn;
  457. struct iscsi_conn *iscsi_conn;
  458. struct iscsi_endpoint *ep;
  459. enum iser_conn_state state;
  460. unsigned qp_max_recv_dtos;
  461. unsigned qp_max_recv_dtos_mask;
  462. unsigned min_posted_rx;
  463. u16 max_cmds;
  464. char name[ISER_OBJECT_NAME_SIZE];
  465. struct work_struct release_work;
  466. struct mutex state_mutex;
  467. struct completion stop_completion;
  468. struct completion ib_completion;
  469. struct completion up_completion;
  470. struct list_head conn_list;
  471. struct iser_login_desc login_desc;
  472. unsigned int rx_desc_head;
  473. struct iser_rx_desc *rx_descs;
  474. u32 num_rx_descs;
  475. unsigned short scsi_sg_tablesize;
  476. unsigned int scsi_max_sectors;
  477. bool snd_w_inv;
  478. };
  479. /**
  480. * struct iscsi_iser_task - iser task context
  481. *
  482. * @desc: TX descriptor
  483. * @iser_conn: link to iser connection
  484. * @status: current task status
  485. * @sc: link to scsi command
  486. * @command_sent: indicate if command was sent
  487. * @dir: iser data direction
  488. * @rdma_reg: task rdma registration desc
  489. * @data: iser data buffer desc
  490. * @prot: iser protection buffer desc
  491. */
  492. struct iscsi_iser_task {
  493. struct iser_tx_desc desc;
  494. struct iser_conn *iser_conn;
  495. enum iser_task_status status;
  496. struct scsi_cmnd *sc;
  497. int command_sent;
  498. int dir[ISER_DIRS_NUM];
  499. struct iser_mem_reg rdma_reg[ISER_DIRS_NUM];
  500. struct iser_data_buf data[ISER_DIRS_NUM];
  501. struct iser_data_buf prot[ISER_DIRS_NUM];
  502. };
  503. struct iser_page_vec {
  504. u64 *pages;
  505. int npages;
  506. struct ib_mr fake_mr;
  507. };
  508. /**
  509. * struct iser_global: iSER global context
  510. *
  511. * @device_list_mutex: protects device_list
  512. * @device_list: iser devices global list
  513. * @connlist_mutex: protects connlist
  514. * @connlist: iser connections global list
  515. * @desc_cache: kmem cache for tx dataout
  516. */
  517. struct iser_global {
  518. struct mutex device_list_mutex;
  519. struct list_head device_list;
  520. struct mutex connlist_mutex;
  521. struct list_head connlist;
  522. struct kmem_cache *desc_cache;
  523. };
  524. extern struct iser_global ig;
  525. extern int iser_debug_level;
  526. extern bool iser_pi_enable;
  527. extern int iser_pi_guard;
  528. extern unsigned int iser_max_sectors;
  529. extern bool iser_always_reg;
  530. int iser_assign_reg_ops(struct iser_device *device);
  531. int iser_send_control(struct iscsi_conn *conn,
  532. struct iscsi_task *task);
  533. int iser_send_command(struct iscsi_conn *conn,
  534. struct iscsi_task *task);
  535. int iser_send_data_out(struct iscsi_conn *conn,
  536. struct iscsi_task *task,
  537. struct iscsi_data *hdr);
  538. void iscsi_iser_recv(struct iscsi_conn *conn,
  539. struct iscsi_hdr *hdr,
  540. char *rx_data,
  541. int rx_data_len);
  542. void iser_conn_init(struct iser_conn *iser_conn);
  543. void iser_conn_release(struct iser_conn *iser_conn);
  544. int iser_conn_terminate(struct iser_conn *iser_conn);
  545. void iser_release_work(struct work_struct *work);
  546. void iser_err_comp(struct ib_wc *wc, const char *type);
  547. void iser_login_rsp(struct ib_cq *cq, struct ib_wc *wc);
  548. void iser_task_rsp(struct ib_cq *cq, struct ib_wc *wc);
  549. void iser_cmd_comp(struct ib_cq *cq, struct ib_wc *wc);
  550. void iser_ctrl_comp(struct ib_cq *cq, struct ib_wc *wc);
  551. void iser_dataout_comp(struct ib_cq *cq, struct ib_wc *wc);
  552. void iser_reg_comp(struct ib_cq *cq, struct ib_wc *wc);
  553. void iser_task_rdma_init(struct iscsi_iser_task *task);
  554. void iser_task_rdma_finalize(struct iscsi_iser_task *task);
  555. void iser_free_rx_descriptors(struct iser_conn *iser_conn);
  556. void iser_finalize_rdma_unaligned_sg(struct iscsi_iser_task *iser_task,
  557. struct iser_data_buf *mem,
  558. enum iser_data_dir cmd_dir);
  559. int iser_reg_rdma_mem(struct iscsi_iser_task *task,
  560. enum iser_data_dir dir,
  561. bool all_imm);
  562. void iser_unreg_rdma_mem(struct iscsi_iser_task *task,
  563. enum iser_data_dir dir);
  564. int iser_connect(struct iser_conn *iser_conn,
  565. struct sockaddr *src_addr,
  566. struct sockaddr *dst_addr,
  567. int non_blocking);
  568. void iser_unreg_mem_fmr(struct iscsi_iser_task *iser_task,
  569. enum iser_data_dir cmd_dir);
  570. void iser_unreg_mem_fastreg(struct iscsi_iser_task *iser_task,
  571. enum iser_data_dir cmd_dir);
  572. int iser_post_recvl(struct iser_conn *iser_conn);
  573. int iser_post_recvm(struct iser_conn *iser_conn, int count);
  574. int iser_post_send(struct ib_conn *ib_conn, struct iser_tx_desc *tx_desc,
  575. bool signal);
  576. int iser_dma_map_task_data(struct iscsi_iser_task *iser_task,
  577. struct iser_data_buf *data,
  578. enum iser_data_dir iser_dir,
  579. enum dma_data_direction dma_dir);
  580. void iser_dma_unmap_task_data(struct iscsi_iser_task *iser_task,
  581. struct iser_data_buf *data,
  582. enum dma_data_direction dir);
  583. int iser_initialize_task_headers(struct iscsi_task *task,
  584. struct iser_tx_desc *tx_desc);
  585. int iser_alloc_rx_descriptors(struct iser_conn *iser_conn,
  586. struct iscsi_session *session);
  587. int iser_alloc_fmr_pool(struct ib_conn *ib_conn,
  588. unsigned cmds_max,
  589. unsigned int size);
  590. void iser_free_fmr_pool(struct ib_conn *ib_conn);
  591. int iser_alloc_fastreg_pool(struct ib_conn *ib_conn,
  592. unsigned cmds_max,
  593. unsigned int size);
  594. void iser_free_fastreg_pool(struct ib_conn *ib_conn);
  595. u8 iser_check_task_pi_status(struct iscsi_iser_task *iser_task,
  596. enum iser_data_dir cmd_dir, sector_t *sector);
  597. struct iser_fr_desc *
  598. iser_reg_desc_get_fr(struct ib_conn *ib_conn);
  599. void
  600. iser_reg_desc_put_fr(struct ib_conn *ib_conn,
  601. struct iser_fr_desc *desc);
  602. struct iser_fr_desc *
  603. iser_reg_desc_get_fmr(struct ib_conn *ib_conn);
  604. void
  605. iser_reg_desc_put_fmr(struct ib_conn *ib_conn,
  606. struct iser_fr_desc *desc);
  607. static inline struct ib_send_wr *
  608. iser_tx_next_wr(struct iser_tx_desc *tx_desc)
  609. {
  610. struct ib_send_wr *cur_wr = &tx_desc->wrs[tx_desc->wr_idx].send;
  611. struct ib_send_wr *last_wr;
  612. if (tx_desc->wr_idx) {
  613. last_wr = &tx_desc->wrs[tx_desc->wr_idx - 1].send;
  614. last_wr->next = cur_wr;
  615. }
  616. tx_desc->wr_idx++;
  617. return cur_wr;
  618. }
  619. static inline struct iser_conn *
  620. to_iser_conn(struct ib_conn *ib_conn)
  621. {
  622. return container_of(ib_conn, struct iser_conn, ib_conn);
  623. }
  624. static inline struct iser_rx_desc *
  625. iser_rx(struct ib_cqe *cqe)
  626. {
  627. return container_of(cqe, struct iser_rx_desc, cqe);
  628. }
  629. static inline struct iser_tx_desc *
  630. iser_tx(struct ib_cqe *cqe)
  631. {
  632. return container_of(cqe, struct iser_tx_desc, cqe);
  633. }
  634. static inline struct iser_login_desc *
  635. iser_login(struct ib_cqe *cqe)
  636. {
  637. return container_of(cqe, struct iser_login_desc, cqe);
  638. }
  639. #endif