iscsi_tcp.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * iSCSI Initiator over TCP/IP Data-Path
  4. *
  5. * Copyright (C) 2004 Dmitry Yusupov
  6. * Copyright (C) 2004 Alex Aizman
  7. * Copyright (C) 2005 - 2006 Mike Christie
  8. * Copyright (C) 2006 Red Hat, Inc. All rights reserved.
  9. * maintained by [email protected]
  10. *
  11. * See the file COPYING included with this distribution for more details.
  12. *
  13. * Credits:
  14. * Christoph Hellwig
  15. * FUJITA Tomonori
  16. * Arne Redlich
  17. * Zhenyu Wang
  18. */
  19. #include <crypto/hash.h>
  20. #include <linux/types.h>
  21. #include <linux/inet.h>
  22. #include <linux/slab.h>
  23. #include <linux/sched/mm.h>
  24. #include <linux/file.h>
  25. #include <linux/blkdev.h>
  26. #include <linux/delay.h>
  27. #include <linux/kfifo.h>
  28. #include <linux/scatterlist.h>
  29. #include <linux/module.h>
  30. #include <linux/backing-dev.h>
  31. #include <net/tcp.h>
  32. #include <scsi/scsi_cmnd.h>
  33. #include <scsi/scsi_device.h>
  34. #include <scsi/scsi_host.h>
  35. #include <scsi/scsi.h>
  36. #include <scsi/scsi_transport_iscsi.h>
  37. #include <trace/events/iscsi.h>
  38. #include "iscsi_tcp.h"
  39. MODULE_AUTHOR("Mike Christie <[email protected]>, "
  40. "Dmitry Yusupov <[email protected]>, "
  41. "Alex Aizman <[email protected]>");
  42. MODULE_DESCRIPTION("iSCSI/TCP data-path");
  43. MODULE_LICENSE("GPL");
  44. static struct scsi_transport_template *iscsi_sw_tcp_scsi_transport;
  45. static struct scsi_host_template iscsi_sw_tcp_sht;
  46. static struct iscsi_transport iscsi_sw_tcp_transport;
  47. static unsigned int iscsi_max_lun = ~0;
  48. module_param_named(max_lun, iscsi_max_lun, uint, S_IRUGO);
  49. static bool iscsi_recv_from_iscsi_q;
  50. module_param_named(recv_from_iscsi_q, iscsi_recv_from_iscsi_q, bool, 0644);
  51. MODULE_PARM_DESC(recv_from_iscsi_q, "Set to true to read iSCSI data/headers from the iscsi_q workqueue. The default is false which will perform reads from the network softirq context.");
  52. static int iscsi_sw_tcp_dbg;
  53. module_param_named(debug_iscsi_tcp, iscsi_sw_tcp_dbg, int,
  54. S_IRUGO | S_IWUSR);
  55. MODULE_PARM_DESC(debug_iscsi_tcp, "Turn on debugging for iscsi_tcp module "
  56. "Set to 1 to turn on, and zero to turn off. Default is off.");
  57. #define ISCSI_SW_TCP_DBG(_conn, dbg_fmt, arg...) \
  58. do { \
  59. if (iscsi_sw_tcp_dbg) \
  60. iscsi_conn_printk(KERN_INFO, _conn, \
  61. "%s " dbg_fmt, \
  62. __func__, ##arg); \
  63. iscsi_dbg_trace(trace_iscsi_dbg_sw_tcp, \
  64. &(_conn)->cls_conn->dev, \
  65. "%s " dbg_fmt, __func__, ##arg);\
  66. } while (0);
  67. /**
  68. * iscsi_sw_tcp_recv - TCP receive in sendfile fashion
  69. * @rd_desc: read descriptor
  70. * @skb: socket buffer
  71. * @offset: offset in skb
  72. * @len: skb->len - offset
  73. */
  74. static int iscsi_sw_tcp_recv(read_descriptor_t *rd_desc, struct sk_buff *skb,
  75. unsigned int offset, size_t len)
  76. {
  77. struct iscsi_conn *conn = rd_desc->arg.data;
  78. unsigned int consumed, total_consumed = 0;
  79. int status;
  80. ISCSI_SW_TCP_DBG(conn, "in %d bytes\n", skb->len - offset);
  81. do {
  82. status = 0;
  83. consumed = iscsi_tcp_recv_skb(conn, skb, offset, 0, &status);
  84. offset += consumed;
  85. total_consumed += consumed;
  86. } while (consumed != 0 && status != ISCSI_TCP_SKB_DONE);
  87. ISCSI_SW_TCP_DBG(conn, "read %d bytes status %d\n",
  88. skb->len - offset, status);
  89. return total_consumed;
  90. }
  91. /**
  92. * iscsi_sw_sk_state_check - check socket state
  93. * @sk: socket
  94. *
  95. * If the socket is in CLOSE or CLOSE_WAIT we should
  96. * not close the connection if there is still some
  97. * data pending.
  98. *
  99. * Must be called with sk_callback_lock.
  100. */
  101. static inline int iscsi_sw_sk_state_check(struct sock *sk)
  102. {
  103. struct iscsi_conn *conn = sk->sk_user_data;
  104. if ((sk->sk_state == TCP_CLOSE_WAIT || sk->sk_state == TCP_CLOSE) &&
  105. (conn->session->state != ISCSI_STATE_LOGGING_OUT) &&
  106. !atomic_read(&sk->sk_rmem_alloc)) {
  107. ISCSI_SW_TCP_DBG(conn, "TCP_CLOSE|TCP_CLOSE_WAIT\n");
  108. iscsi_conn_failure(conn, ISCSI_ERR_TCP_CONN_CLOSE);
  109. return -ECONNRESET;
  110. }
  111. return 0;
  112. }
  113. static void iscsi_sw_tcp_recv_data(struct iscsi_conn *conn)
  114. {
  115. struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
  116. struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
  117. struct sock *sk = tcp_sw_conn->sock->sk;
  118. read_descriptor_t rd_desc;
  119. /*
  120. * Use rd_desc to pass 'conn' to iscsi_tcp_recv.
  121. * We set count to 1 because we want the network layer to
  122. * hand us all the skbs that are available. iscsi_tcp_recv
  123. * handled pdus that cross buffers or pdus that still need data.
  124. */
  125. rd_desc.arg.data = conn;
  126. rd_desc.count = 1;
  127. tcp_read_sock(sk, &rd_desc, iscsi_sw_tcp_recv);
  128. /* If we had to (atomically) map a highmem page,
  129. * unmap it now. */
  130. iscsi_tcp_segment_unmap(&tcp_conn->in.segment);
  131. iscsi_sw_sk_state_check(sk);
  132. }
  133. static void iscsi_sw_tcp_recv_data_work(struct work_struct *work)
  134. {
  135. struct iscsi_conn *conn = container_of(work, struct iscsi_conn,
  136. recvwork);
  137. struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
  138. struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
  139. struct sock *sk = tcp_sw_conn->sock->sk;
  140. lock_sock(sk);
  141. iscsi_sw_tcp_recv_data(conn);
  142. release_sock(sk);
  143. }
  144. static void iscsi_sw_tcp_data_ready(struct sock *sk)
  145. {
  146. struct iscsi_sw_tcp_conn *tcp_sw_conn;
  147. struct iscsi_tcp_conn *tcp_conn;
  148. struct iscsi_conn *conn;
  149. read_lock_bh(&sk->sk_callback_lock);
  150. conn = sk->sk_user_data;
  151. if (!conn) {
  152. read_unlock_bh(&sk->sk_callback_lock);
  153. return;
  154. }
  155. tcp_conn = conn->dd_data;
  156. tcp_sw_conn = tcp_conn->dd_data;
  157. if (tcp_sw_conn->queue_recv)
  158. iscsi_conn_queue_recv(conn);
  159. else
  160. iscsi_sw_tcp_recv_data(conn);
  161. read_unlock_bh(&sk->sk_callback_lock);
  162. }
  163. static void iscsi_sw_tcp_state_change(struct sock *sk)
  164. {
  165. struct iscsi_tcp_conn *tcp_conn;
  166. struct iscsi_sw_tcp_conn *tcp_sw_conn;
  167. struct iscsi_conn *conn;
  168. void (*old_state_change)(struct sock *);
  169. read_lock_bh(&sk->sk_callback_lock);
  170. conn = sk->sk_user_data;
  171. if (!conn) {
  172. read_unlock_bh(&sk->sk_callback_lock);
  173. return;
  174. }
  175. iscsi_sw_sk_state_check(sk);
  176. tcp_conn = conn->dd_data;
  177. tcp_sw_conn = tcp_conn->dd_data;
  178. old_state_change = tcp_sw_conn->old_state_change;
  179. read_unlock_bh(&sk->sk_callback_lock);
  180. old_state_change(sk);
  181. }
  182. /**
  183. * iscsi_sw_tcp_write_space - Called when more output buffer space is available
  184. * @sk: socket space is available for
  185. **/
  186. static void iscsi_sw_tcp_write_space(struct sock *sk)
  187. {
  188. struct iscsi_conn *conn;
  189. struct iscsi_tcp_conn *tcp_conn;
  190. struct iscsi_sw_tcp_conn *tcp_sw_conn;
  191. void (*old_write_space)(struct sock *);
  192. read_lock_bh(&sk->sk_callback_lock);
  193. conn = sk->sk_user_data;
  194. if (!conn) {
  195. read_unlock_bh(&sk->sk_callback_lock);
  196. return;
  197. }
  198. tcp_conn = conn->dd_data;
  199. tcp_sw_conn = tcp_conn->dd_data;
  200. old_write_space = tcp_sw_conn->old_write_space;
  201. read_unlock_bh(&sk->sk_callback_lock);
  202. old_write_space(sk);
  203. ISCSI_SW_TCP_DBG(conn, "iscsi_write_space\n");
  204. iscsi_conn_queue_xmit(conn);
  205. }
  206. static void iscsi_sw_tcp_conn_set_callbacks(struct iscsi_conn *conn)
  207. {
  208. struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
  209. struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
  210. struct sock *sk = tcp_sw_conn->sock->sk;
  211. /* assign new callbacks */
  212. write_lock_bh(&sk->sk_callback_lock);
  213. sk->sk_user_data = conn;
  214. tcp_sw_conn->old_data_ready = sk->sk_data_ready;
  215. tcp_sw_conn->old_state_change = sk->sk_state_change;
  216. tcp_sw_conn->old_write_space = sk->sk_write_space;
  217. sk->sk_data_ready = iscsi_sw_tcp_data_ready;
  218. sk->sk_state_change = iscsi_sw_tcp_state_change;
  219. sk->sk_write_space = iscsi_sw_tcp_write_space;
  220. write_unlock_bh(&sk->sk_callback_lock);
  221. }
  222. static void
  223. iscsi_sw_tcp_conn_restore_callbacks(struct iscsi_conn *conn)
  224. {
  225. struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
  226. struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
  227. struct sock *sk = tcp_sw_conn->sock->sk;
  228. /* restore socket callbacks, see also: iscsi_conn_set_callbacks() */
  229. write_lock_bh(&sk->sk_callback_lock);
  230. sk->sk_user_data = NULL;
  231. sk->sk_data_ready = tcp_sw_conn->old_data_ready;
  232. sk->sk_state_change = tcp_sw_conn->old_state_change;
  233. sk->sk_write_space = tcp_sw_conn->old_write_space;
  234. sk->sk_no_check_tx = 0;
  235. write_unlock_bh(&sk->sk_callback_lock);
  236. }
  237. /**
  238. * iscsi_sw_tcp_xmit_segment - transmit segment
  239. * @tcp_conn: the iSCSI TCP connection
  240. * @segment: the buffer to transmnit
  241. *
  242. * This function transmits as much of the buffer as
  243. * the network layer will accept, and returns the number of
  244. * bytes transmitted.
  245. *
  246. * If CRC hashing is enabled, the function will compute the
  247. * hash as it goes. When the entire segment has been transmitted,
  248. * it will retrieve the hash value and send it as well.
  249. */
  250. static int iscsi_sw_tcp_xmit_segment(struct iscsi_tcp_conn *tcp_conn,
  251. struct iscsi_segment *segment)
  252. {
  253. struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
  254. struct socket *sk = tcp_sw_conn->sock;
  255. unsigned int copied = 0;
  256. int r = 0;
  257. while (!iscsi_tcp_segment_done(tcp_conn, segment, 0, r)) {
  258. struct scatterlist *sg;
  259. unsigned int offset, copy;
  260. int flags = 0;
  261. r = 0;
  262. offset = segment->copied;
  263. copy = segment->size - offset;
  264. if (segment->total_copied + segment->size < segment->total_size)
  265. flags |= MSG_MORE | MSG_SENDPAGE_NOTLAST;
  266. if (tcp_sw_conn->queue_recv)
  267. flags |= MSG_DONTWAIT;
  268. /* Use sendpage if we can; else fall back to sendmsg */
  269. if (!segment->data) {
  270. sg = segment->sg;
  271. offset += segment->sg_offset + sg->offset;
  272. r = tcp_sw_conn->sendpage(sk, sg_page(sg), offset,
  273. copy, flags);
  274. } else {
  275. struct msghdr msg = { .msg_flags = flags };
  276. struct kvec iov = {
  277. .iov_base = segment->data + offset,
  278. .iov_len = copy
  279. };
  280. r = kernel_sendmsg(sk, &msg, &iov, 1, copy);
  281. }
  282. if (r < 0) {
  283. iscsi_tcp_segment_unmap(segment);
  284. return r;
  285. }
  286. copied += r;
  287. }
  288. return copied;
  289. }
  290. /**
  291. * iscsi_sw_tcp_xmit - TCP transmit
  292. * @conn: iscsi connection
  293. **/
  294. static int iscsi_sw_tcp_xmit(struct iscsi_conn *conn)
  295. {
  296. struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
  297. struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
  298. struct iscsi_segment *segment = &tcp_sw_conn->out.segment;
  299. unsigned int consumed = 0;
  300. int rc = 0;
  301. while (1) {
  302. rc = iscsi_sw_tcp_xmit_segment(tcp_conn, segment);
  303. /*
  304. * We may not have been able to send data because the conn
  305. * is getting stopped. libiscsi will know so propagate err
  306. * for it to do the right thing.
  307. */
  308. if (rc == -EAGAIN)
  309. return rc;
  310. else if (rc < 0) {
  311. rc = ISCSI_ERR_XMIT_FAILED;
  312. goto error;
  313. } else if (rc == 0)
  314. break;
  315. consumed += rc;
  316. if (segment->total_copied >= segment->total_size) {
  317. if (segment->done != NULL) {
  318. rc = segment->done(tcp_conn, segment);
  319. if (rc != 0)
  320. goto error;
  321. }
  322. }
  323. }
  324. ISCSI_SW_TCP_DBG(conn, "xmit %d bytes\n", consumed);
  325. conn->txdata_octets += consumed;
  326. return consumed;
  327. error:
  328. /* Transmit error. We could initiate error recovery
  329. * here. */
  330. ISCSI_SW_TCP_DBG(conn, "Error sending PDU, errno=%d\n", rc);
  331. iscsi_conn_failure(conn, rc);
  332. return -EIO;
  333. }
  334. /**
  335. * iscsi_sw_tcp_xmit_qlen - return the number of bytes queued for xmit
  336. * @conn: iscsi connection
  337. */
  338. static inline int iscsi_sw_tcp_xmit_qlen(struct iscsi_conn *conn)
  339. {
  340. struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
  341. struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
  342. struct iscsi_segment *segment = &tcp_sw_conn->out.segment;
  343. return segment->total_copied - segment->total_size;
  344. }
  345. static int iscsi_sw_tcp_pdu_xmit(struct iscsi_task *task)
  346. {
  347. struct iscsi_conn *conn = task->conn;
  348. unsigned int noreclaim_flag;
  349. struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
  350. struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
  351. int rc = 0;
  352. if (!tcp_sw_conn->sock) {
  353. iscsi_conn_printk(KERN_ERR, conn,
  354. "Transport not bound to socket!\n");
  355. return -EINVAL;
  356. }
  357. noreclaim_flag = memalloc_noreclaim_save();
  358. while (iscsi_sw_tcp_xmit_qlen(conn)) {
  359. rc = iscsi_sw_tcp_xmit(conn);
  360. if (rc == 0) {
  361. rc = -EAGAIN;
  362. break;
  363. }
  364. if (rc < 0)
  365. break;
  366. rc = 0;
  367. }
  368. memalloc_noreclaim_restore(noreclaim_flag);
  369. return rc;
  370. }
  371. /*
  372. * This is called when we're done sending the header.
  373. * Simply copy the data_segment to the send segment, and return.
  374. */
  375. static int iscsi_sw_tcp_send_hdr_done(struct iscsi_tcp_conn *tcp_conn,
  376. struct iscsi_segment *segment)
  377. {
  378. struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
  379. tcp_sw_conn->out.segment = tcp_sw_conn->out.data_segment;
  380. ISCSI_SW_TCP_DBG(tcp_conn->iscsi_conn,
  381. "Header done. Next segment size %u total_size %u\n",
  382. tcp_sw_conn->out.segment.size,
  383. tcp_sw_conn->out.segment.total_size);
  384. return 0;
  385. }
  386. static void iscsi_sw_tcp_send_hdr_prep(struct iscsi_conn *conn, void *hdr,
  387. size_t hdrlen)
  388. {
  389. struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
  390. struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
  391. ISCSI_SW_TCP_DBG(conn, "%s\n", conn->hdrdgst_en ?
  392. "digest enabled" : "digest disabled");
  393. /* Clear the data segment - needs to be filled in by the
  394. * caller using iscsi_tcp_send_data_prep() */
  395. memset(&tcp_sw_conn->out.data_segment, 0,
  396. sizeof(struct iscsi_segment));
  397. /* If header digest is enabled, compute the CRC and
  398. * place the digest into the same buffer. We make
  399. * sure that both iscsi_tcp_task and mtask have
  400. * sufficient room.
  401. */
  402. if (conn->hdrdgst_en) {
  403. iscsi_tcp_dgst_header(tcp_sw_conn->tx_hash, hdr, hdrlen,
  404. hdr + hdrlen);
  405. hdrlen += ISCSI_DIGEST_SIZE;
  406. }
  407. /* Remember header pointer for later, when we need
  408. * to decide whether there's a payload to go along
  409. * with the header. */
  410. tcp_sw_conn->out.hdr = hdr;
  411. iscsi_segment_init_linear(&tcp_sw_conn->out.segment, hdr, hdrlen,
  412. iscsi_sw_tcp_send_hdr_done, NULL);
  413. }
  414. /*
  415. * Prepare the send buffer for the payload data.
  416. * Padding and checksumming will all be taken care
  417. * of by the iscsi_segment routines.
  418. */
  419. static int
  420. iscsi_sw_tcp_send_data_prep(struct iscsi_conn *conn, struct scatterlist *sg,
  421. unsigned int count, unsigned int offset,
  422. unsigned int len)
  423. {
  424. struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
  425. struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
  426. struct ahash_request *tx_hash = NULL;
  427. unsigned int hdr_spec_len;
  428. ISCSI_SW_TCP_DBG(conn, "offset=%d, datalen=%d %s\n", offset, len,
  429. conn->datadgst_en ?
  430. "digest enabled" : "digest disabled");
  431. /* Make sure the datalen matches what the caller
  432. said he would send. */
  433. hdr_spec_len = ntoh24(tcp_sw_conn->out.hdr->dlength);
  434. WARN_ON(iscsi_padded(len) != iscsi_padded(hdr_spec_len));
  435. if (conn->datadgst_en)
  436. tx_hash = tcp_sw_conn->tx_hash;
  437. return iscsi_segment_seek_sg(&tcp_sw_conn->out.data_segment,
  438. sg, count, offset, len,
  439. NULL, tx_hash);
  440. }
  441. static void
  442. iscsi_sw_tcp_send_linear_data_prep(struct iscsi_conn *conn, void *data,
  443. size_t len)
  444. {
  445. struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
  446. struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
  447. struct ahash_request *tx_hash = NULL;
  448. unsigned int hdr_spec_len;
  449. ISCSI_SW_TCP_DBG(conn, "datalen=%zd %s\n", len, conn->datadgst_en ?
  450. "digest enabled" : "digest disabled");
  451. /* Make sure the datalen matches what the caller
  452. said he would send. */
  453. hdr_spec_len = ntoh24(tcp_sw_conn->out.hdr->dlength);
  454. WARN_ON(iscsi_padded(len) != iscsi_padded(hdr_spec_len));
  455. if (conn->datadgst_en)
  456. tx_hash = tcp_sw_conn->tx_hash;
  457. iscsi_segment_init_linear(&tcp_sw_conn->out.data_segment,
  458. data, len, NULL, tx_hash);
  459. }
  460. static int iscsi_sw_tcp_pdu_init(struct iscsi_task *task,
  461. unsigned int offset, unsigned int count)
  462. {
  463. struct iscsi_conn *conn = task->conn;
  464. int err = 0;
  465. iscsi_sw_tcp_send_hdr_prep(conn, task->hdr, task->hdr_len);
  466. if (!count)
  467. return 0;
  468. if (!task->sc)
  469. iscsi_sw_tcp_send_linear_data_prep(conn, task->data, count);
  470. else {
  471. struct scsi_data_buffer *sdb = &task->sc->sdb;
  472. err = iscsi_sw_tcp_send_data_prep(conn, sdb->table.sgl,
  473. sdb->table.nents, offset,
  474. count);
  475. }
  476. if (err) {
  477. /* got invalid offset/len */
  478. return -EIO;
  479. }
  480. return 0;
  481. }
  482. static int iscsi_sw_tcp_pdu_alloc(struct iscsi_task *task, uint8_t opcode)
  483. {
  484. struct iscsi_tcp_task *tcp_task = task->dd_data;
  485. task->hdr = task->dd_data + sizeof(*tcp_task);
  486. task->hdr_max = sizeof(struct iscsi_sw_tcp_hdrbuf) - ISCSI_DIGEST_SIZE;
  487. return 0;
  488. }
  489. static struct iscsi_cls_conn *
  490. iscsi_sw_tcp_conn_create(struct iscsi_cls_session *cls_session,
  491. uint32_t conn_idx)
  492. {
  493. struct iscsi_conn *conn;
  494. struct iscsi_cls_conn *cls_conn;
  495. struct iscsi_tcp_conn *tcp_conn;
  496. struct iscsi_sw_tcp_conn *tcp_sw_conn;
  497. struct crypto_ahash *tfm;
  498. cls_conn = iscsi_tcp_conn_setup(cls_session, sizeof(*tcp_sw_conn),
  499. conn_idx);
  500. if (!cls_conn)
  501. return NULL;
  502. conn = cls_conn->dd_data;
  503. tcp_conn = conn->dd_data;
  504. tcp_sw_conn = tcp_conn->dd_data;
  505. INIT_WORK(&conn->recvwork, iscsi_sw_tcp_recv_data_work);
  506. tcp_sw_conn->queue_recv = iscsi_recv_from_iscsi_q;
  507. mutex_init(&tcp_sw_conn->sock_lock);
  508. tfm = crypto_alloc_ahash("crc32c", 0, CRYPTO_ALG_ASYNC);
  509. if (IS_ERR(tfm))
  510. goto free_conn;
  511. tcp_sw_conn->tx_hash = ahash_request_alloc(tfm, GFP_KERNEL);
  512. if (!tcp_sw_conn->tx_hash)
  513. goto free_tfm;
  514. ahash_request_set_callback(tcp_sw_conn->tx_hash, 0, NULL, NULL);
  515. tcp_sw_conn->rx_hash = ahash_request_alloc(tfm, GFP_KERNEL);
  516. if (!tcp_sw_conn->rx_hash)
  517. goto free_tx_hash;
  518. ahash_request_set_callback(tcp_sw_conn->rx_hash, 0, NULL, NULL);
  519. tcp_conn->rx_hash = tcp_sw_conn->rx_hash;
  520. return cls_conn;
  521. free_tx_hash:
  522. ahash_request_free(tcp_sw_conn->tx_hash);
  523. free_tfm:
  524. crypto_free_ahash(tfm);
  525. free_conn:
  526. iscsi_conn_printk(KERN_ERR, conn,
  527. "Could not create connection due to crc32c "
  528. "loading error. Make sure the crc32c "
  529. "module is built as a module or into the "
  530. "kernel\n");
  531. iscsi_tcp_conn_teardown(cls_conn);
  532. return NULL;
  533. }
  534. static void iscsi_sw_tcp_release_conn(struct iscsi_conn *conn)
  535. {
  536. struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
  537. struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
  538. struct socket *sock = tcp_sw_conn->sock;
  539. /*
  540. * The iscsi transport class will make sure we are not called in
  541. * parallel with start, stop, bind and destroys. However, this can be
  542. * called twice if userspace does a stop then a destroy.
  543. */
  544. if (!sock)
  545. return;
  546. /*
  547. * Make sure we start socket shutdown now in case userspace is up
  548. * but delayed in releasing the socket.
  549. */
  550. kernel_sock_shutdown(sock, SHUT_RDWR);
  551. sock_hold(sock->sk);
  552. iscsi_sw_tcp_conn_restore_callbacks(conn);
  553. sock_put(sock->sk);
  554. iscsi_suspend_rx(conn);
  555. mutex_lock(&tcp_sw_conn->sock_lock);
  556. tcp_sw_conn->sock = NULL;
  557. mutex_unlock(&tcp_sw_conn->sock_lock);
  558. sockfd_put(sock);
  559. }
  560. static void iscsi_sw_tcp_conn_destroy(struct iscsi_cls_conn *cls_conn)
  561. {
  562. struct iscsi_conn *conn = cls_conn->dd_data;
  563. struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
  564. struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
  565. iscsi_sw_tcp_release_conn(conn);
  566. ahash_request_free(tcp_sw_conn->rx_hash);
  567. if (tcp_sw_conn->tx_hash) {
  568. struct crypto_ahash *tfm;
  569. tfm = crypto_ahash_reqtfm(tcp_sw_conn->tx_hash);
  570. ahash_request_free(tcp_sw_conn->tx_hash);
  571. crypto_free_ahash(tfm);
  572. }
  573. iscsi_tcp_conn_teardown(cls_conn);
  574. }
  575. static void iscsi_sw_tcp_conn_stop(struct iscsi_cls_conn *cls_conn, int flag)
  576. {
  577. struct iscsi_conn *conn = cls_conn->dd_data;
  578. struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
  579. struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
  580. struct socket *sock = tcp_sw_conn->sock;
  581. /* userspace may have goofed up and not bound us */
  582. if (!sock)
  583. return;
  584. sock->sk->sk_err = EIO;
  585. wake_up_interruptible(sk_sleep(sock->sk));
  586. /* stop xmit side */
  587. iscsi_suspend_tx(conn);
  588. /* stop recv side and release socket */
  589. iscsi_sw_tcp_release_conn(conn);
  590. iscsi_conn_stop(cls_conn, flag);
  591. }
  592. static int
  593. iscsi_sw_tcp_conn_bind(struct iscsi_cls_session *cls_session,
  594. struct iscsi_cls_conn *cls_conn, uint64_t transport_eph,
  595. int is_leading)
  596. {
  597. struct iscsi_conn *conn = cls_conn->dd_data;
  598. struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
  599. struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
  600. struct sock *sk;
  601. struct socket *sock;
  602. int err;
  603. /* lookup for existing socket */
  604. sock = sockfd_lookup((int)transport_eph, &err);
  605. if (!sock) {
  606. iscsi_conn_printk(KERN_ERR, conn,
  607. "sockfd_lookup failed %d\n", err);
  608. return -EEXIST;
  609. }
  610. err = -EINVAL;
  611. if (!sk_is_tcp(sock->sk))
  612. goto free_socket;
  613. err = iscsi_conn_bind(cls_session, cls_conn, is_leading);
  614. if (err)
  615. goto free_socket;
  616. mutex_lock(&tcp_sw_conn->sock_lock);
  617. /* bind iSCSI connection and socket */
  618. tcp_sw_conn->sock = sock;
  619. mutex_unlock(&tcp_sw_conn->sock_lock);
  620. /* setup Socket parameters */
  621. sk = sock->sk;
  622. sk->sk_reuse = SK_CAN_REUSE;
  623. sk->sk_sndtimeo = 15 * HZ; /* FIXME: make it configurable */
  624. sk->sk_allocation = GFP_ATOMIC;
  625. sk_set_memalloc(sk);
  626. sock_no_linger(sk);
  627. iscsi_sw_tcp_conn_set_callbacks(conn);
  628. tcp_sw_conn->sendpage = tcp_sw_conn->sock->ops->sendpage;
  629. /*
  630. * set receive state machine into initial state
  631. */
  632. iscsi_tcp_hdr_recv_prep(tcp_conn);
  633. return 0;
  634. free_socket:
  635. sockfd_put(sock);
  636. return err;
  637. }
  638. static int iscsi_sw_tcp_conn_set_param(struct iscsi_cls_conn *cls_conn,
  639. enum iscsi_param param, char *buf,
  640. int buflen)
  641. {
  642. struct iscsi_conn *conn = cls_conn->dd_data;
  643. struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
  644. struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
  645. switch(param) {
  646. case ISCSI_PARAM_HDRDGST_EN:
  647. iscsi_set_param(cls_conn, param, buf, buflen);
  648. break;
  649. case ISCSI_PARAM_DATADGST_EN:
  650. mutex_lock(&tcp_sw_conn->sock_lock);
  651. if (!tcp_sw_conn->sock) {
  652. mutex_unlock(&tcp_sw_conn->sock_lock);
  653. return -ENOTCONN;
  654. }
  655. iscsi_set_param(cls_conn, param, buf, buflen);
  656. tcp_sw_conn->sendpage = conn->datadgst_en ?
  657. sock_no_sendpage : tcp_sw_conn->sock->ops->sendpage;
  658. mutex_unlock(&tcp_sw_conn->sock_lock);
  659. break;
  660. case ISCSI_PARAM_MAX_R2T:
  661. return iscsi_tcp_set_max_r2t(conn, buf);
  662. default:
  663. return iscsi_set_param(cls_conn, param, buf, buflen);
  664. }
  665. return 0;
  666. }
  667. static int iscsi_sw_tcp_conn_get_param(struct iscsi_cls_conn *cls_conn,
  668. enum iscsi_param param, char *buf)
  669. {
  670. struct iscsi_conn *conn = cls_conn->dd_data;
  671. struct iscsi_sw_tcp_conn *tcp_sw_conn;
  672. struct iscsi_tcp_conn *tcp_conn;
  673. struct sockaddr_in6 addr;
  674. struct socket *sock;
  675. int rc;
  676. switch(param) {
  677. case ISCSI_PARAM_CONN_PORT:
  678. case ISCSI_PARAM_CONN_ADDRESS:
  679. case ISCSI_PARAM_LOCAL_PORT:
  680. spin_lock_bh(&conn->session->frwd_lock);
  681. if (!conn->session->leadconn) {
  682. spin_unlock_bh(&conn->session->frwd_lock);
  683. return -ENOTCONN;
  684. }
  685. /*
  686. * The conn has been setup and bound, so just grab a ref
  687. * incase a destroy runs while we are in the net layer.
  688. */
  689. iscsi_get_conn(conn->cls_conn);
  690. spin_unlock_bh(&conn->session->frwd_lock);
  691. tcp_conn = conn->dd_data;
  692. tcp_sw_conn = tcp_conn->dd_data;
  693. mutex_lock(&tcp_sw_conn->sock_lock);
  694. sock = tcp_sw_conn->sock;
  695. if (!sock) {
  696. rc = -ENOTCONN;
  697. goto sock_unlock;
  698. }
  699. if (param == ISCSI_PARAM_LOCAL_PORT)
  700. rc = kernel_getsockname(sock,
  701. (struct sockaddr *)&addr);
  702. else
  703. rc = kernel_getpeername(sock,
  704. (struct sockaddr *)&addr);
  705. sock_unlock:
  706. mutex_unlock(&tcp_sw_conn->sock_lock);
  707. iscsi_put_conn(conn->cls_conn);
  708. if (rc < 0)
  709. return rc;
  710. return iscsi_conn_get_addr_param((struct sockaddr_storage *)
  711. &addr, param, buf);
  712. default:
  713. return iscsi_conn_get_param(cls_conn, param, buf);
  714. }
  715. return 0;
  716. }
  717. static int iscsi_sw_tcp_host_get_param(struct Scsi_Host *shost,
  718. enum iscsi_host_param param, char *buf)
  719. {
  720. struct iscsi_sw_tcp_host *tcp_sw_host = iscsi_host_priv(shost);
  721. struct iscsi_session *session;
  722. struct iscsi_conn *conn;
  723. struct iscsi_tcp_conn *tcp_conn;
  724. struct iscsi_sw_tcp_conn *tcp_sw_conn;
  725. struct sockaddr_in6 addr;
  726. struct socket *sock;
  727. int rc;
  728. switch (param) {
  729. case ISCSI_HOST_PARAM_IPADDRESS:
  730. session = tcp_sw_host->session;
  731. if (!session)
  732. return -ENOTCONN;
  733. spin_lock_bh(&session->frwd_lock);
  734. conn = session->leadconn;
  735. if (!conn) {
  736. spin_unlock_bh(&session->frwd_lock);
  737. return -ENOTCONN;
  738. }
  739. tcp_conn = conn->dd_data;
  740. tcp_sw_conn = tcp_conn->dd_data;
  741. /*
  742. * The conn has been setup and bound, so just grab a ref
  743. * incase a destroy runs while we are in the net layer.
  744. */
  745. iscsi_get_conn(conn->cls_conn);
  746. spin_unlock_bh(&session->frwd_lock);
  747. mutex_lock(&tcp_sw_conn->sock_lock);
  748. sock = tcp_sw_conn->sock;
  749. if (!sock)
  750. rc = -ENOTCONN;
  751. else
  752. rc = kernel_getsockname(sock, (struct sockaddr *)&addr);
  753. mutex_unlock(&tcp_sw_conn->sock_lock);
  754. iscsi_put_conn(conn->cls_conn);
  755. if (rc < 0)
  756. return rc;
  757. return iscsi_conn_get_addr_param((struct sockaddr_storage *)
  758. &addr,
  759. (enum iscsi_param)param, buf);
  760. default:
  761. return iscsi_host_get_param(shost, param, buf);
  762. }
  763. return 0;
  764. }
  765. static void
  766. iscsi_sw_tcp_conn_get_stats(struct iscsi_cls_conn *cls_conn,
  767. struct iscsi_stats *stats)
  768. {
  769. struct iscsi_conn *conn = cls_conn->dd_data;
  770. struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
  771. struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
  772. stats->custom_length = 3;
  773. strcpy(stats->custom[0].desc, "tx_sendpage_failures");
  774. stats->custom[0].value = tcp_sw_conn->sendpage_failures_cnt;
  775. strcpy(stats->custom[1].desc, "rx_discontiguous_hdr");
  776. stats->custom[1].value = tcp_sw_conn->discontiguous_hdr_cnt;
  777. strcpy(stats->custom[2].desc, "eh_abort_cnt");
  778. stats->custom[2].value = conn->eh_abort_cnt;
  779. iscsi_tcp_conn_get_stats(cls_conn, stats);
  780. }
  781. static struct iscsi_cls_session *
  782. iscsi_sw_tcp_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max,
  783. uint16_t qdepth, uint32_t initial_cmdsn)
  784. {
  785. struct iscsi_cls_session *cls_session;
  786. struct iscsi_session *session;
  787. struct iscsi_sw_tcp_host *tcp_sw_host;
  788. struct Scsi_Host *shost;
  789. int rc;
  790. if (ep) {
  791. printk(KERN_ERR "iscsi_tcp: invalid ep %p.\n", ep);
  792. return NULL;
  793. }
  794. shost = iscsi_host_alloc(&iscsi_sw_tcp_sht,
  795. sizeof(struct iscsi_sw_tcp_host), 1);
  796. if (!shost)
  797. return NULL;
  798. shost->transportt = iscsi_sw_tcp_scsi_transport;
  799. shost->cmd_per_lun = qdepth;
  800. shost->max_lun = iscsi_max_lun;
  801. shost->max_id = 0;
  802. shost->max_channel = 0;
  803. shost->max_cmd_len = SCSI_MAX_VARLEN_CDB_SIZE;
  804. rc = iscsi_host_get_max_scsi_cmds(shost, cmds_max);
  805. if (rc < 0)
  806. goto free_host;
  807. shost->can_queue = rc;
  808. if (iscsi_host_add(shost, NULL))
  809. goto free_host;
  810. cls_session = iscsi_session_setup(&iscsi_sw_tcp_transport, shost,
  811. cmds_max, 0,
  812. sizeof(struct iscsi_tcp_task) +
  813. sizeof(struct iscsi_sw_tcp_hdrbuf),
  814. initial_cmdsn, 0);
  815. if (!cls_session)
  816. goto remove_host;
  817. session = cls_session->dd_data;
  818. if (iscsi_tcp_r2tpool_alloc(session))
  819. goto remove_session;
  820. /* We are now fully setup so expose the session to sysfs. */
  821. tcp_sw_host = iscsi_host_priv(shost);
  822. tcp_sw_host->session = session;
  823. return cls_session;
  824. remove_session:
  825. iscsi_session_teardown(cls_session);
  826. remove_host:
  827. iscsi_host_remove(shost, false);
  828. free_host:
  829. iscsi_host_free(shost);
  830. return NULL;
  831. }
  832. static void iscsi_sw_tcp_session_destroy(struct iscsi_cls_session *cls_session)
  833. {
  834. struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
  835. struct iscsi_session *session = cls_session->dd_data;
  836. if (WARN_ON_ONCE(session->leadconn))
  837. return;
  838. iscsi_session_remove(cls_session);
  839. /*
  840. * Our get_host_param needs to access the session, so remove the
  841. * host from sysfs before freeing the session to make sure userspace
  842. * is no longer accessing the callout.
  843. */
  844. iscsi_host_remove(shost, false);
  845. iscsi_tcp_r2tpool_free(cls_session->dd_data);
  846. iscsi_session_free(cls_session);
  847. iscsi_host_free(shost);
  848. }
  849. static umode_t iscsi_sw_tcp_attr_is_visible(int param_type, int param)
  850. {
  851. switch (param_type) {
  852. case ISCSI_HOST_PARAM:
  853. switch (param) {
  854. case ISCSI_HOST_PARAM_NETDEV_NAME:
  855. case ISCSI_HOST_PARAM_HWADDRESS:
  856. case ISCSI_HOST_PARAM_IPADDRESS:
  857. case ISCSI_HOST_PARAM_INITIATOR_NAME:
  858. return S_IRUGO;
  859. default:
  860. return 0;
  861. }
  862. case ISCSI_PARAM:
  863. switch (param) {
  864. case ISCSI_PARAM_MAX_RECV_DLENGTH:
  865. case ISCSI_PARAM_MAX_XMIT_DLENGTH:
  866. case ISCSI_PARAM_HDRDGST_EN:
  867. case ISCSI_PARAM_DATADGST_EN:
  868. case ISCSI_PARAM_CONN_ADDRESS:
  869. case ISCSI_PARAM_CONN_PORT:
  870. case ISCSI_PARAM_LOCAL_PORT:
  871. case ISCSI_PARAM_EXP_STATSN:
  872. case ISCSI_PARAM_PERSISTENT_ADDRESS:
  873. case ISCSI_PARAM_PERSISTENT_PORT:
  874. case ISCSI_PARAM_PING_TMO:
  875. case ISCSI_PARAM_RECV_TMO:
  876. case ISCSI_PARAM_INITIAL_R2T_EN:
  877. case ISCSI_PARAM_MAX_R2T:
  878. case ISCSI_PARAM_IMM_DATA_EN:
  879. case ISCSI_PARAM_FIRST_BURST:
  880. case ISCSI_PARAM_MAX_BURST:
  881. case ISCSI_PARAM_PDU_INORDER_EN:
  882. case ISCSI_PARAM_DATASEQ_INORDER_EN:
  883. case ISCSI_PARAM_ERL:
  884. case ISCSI_PARAM_TARGET_NAME:
  885. case ISCSI_PARAM_TPGT:
  886. case ISCSI_PARAM_USERNAME:
  887. case ISCSI_PARAM_PASSWORD:
  888. case ISCSI_PARAM_USERNAME_IN:
  889. case ISCSI_PARAM_PASSWORD_IN:
  890. case ISCSI_PARAM_FAST_ABORT:
  891. case ISCSI_PARAM_ABORT_TMO:
  892. case ISCSI_PARAM_LU_RESET_TMO:
  893. case ISCSI_PARAM_TGT_RESET_TMO:
  894. case ISCSI_PARAM_IFACE_NAME:
  895. case ISCSI_PARAM_INITIATOR_NAME:
  896. return S_IRUGO;
  897. default:
  898. return 0;
  899. }
  900. }
  901. return 0;
  902. }
  903. static int iscsi_sw_tcp_slave_configure(struct scsi_device *sdev)
  904. {
  905. struct iscsi_sw_tcp_host *tcp_sw_host = iscsi_host_priv(sdev->host);
  906. struct iscsi_session *session = tcp_sw_host->session;
  907. struct iscsi_conn *conn = session->leadconn;
  908. if (conn->datadgst_en)
  909. blk_queue_flag_set(QUEUE_FLAG_STABLE_WRITES,
  910. sdev->request_queue);
  911. blk_queue_dma_alignment(sdev->request_queue, 0);
  912. return 0;
  913. }
  914. static struct scsi_host_template iscsi_sw_tcp_sht = {
  915. .module = THIS_MODULE,
  916. .name = "iSCSI Initiator over TCP/IP",
  917. .queuecommand = iscsi_queuecommand,
  918. .change_queue_depth = scsi_change_queue_depth,
  919. .can_queue = ISCSI_TOTAL_CMDS_MAX,
  920. .sg_tablesize = 4096,
  921. .max_sectors = 0xFFFF,
  922. .cmd_per_lun = ISCSI_DEF_CMD_PER_LUN,
  923. .eh_timed_out = iscsi_eh_cmd_timed_out,
  924. .eh_abort_handler = iscsi_eh_abort,
  925. .eh_device_reset_handler= iscsi_eh_device_reset,
  926. .eh_target_reset_handler = iscsi_eh_recover_target,
  927. .dma_boundary = PAGE_SIZE - 1,
  928. .slave_configure = iscsi_sw_tcp_slave_configure,
  929. .proc_name = "iscsi_tcp",
  930. .this_id = -1,
  931. .track_queue_depth = 1,
  932. .cmd_size = sizeof(struct iscsi_cmd),
  933. };
  934. static struct iscsi_transport iscsi_sw_tcp_transport = {
  935. .owner = THIS_MODULE,
  936. .name = "tcp",
  937. .caps = CAP_RECOVERY_L0 | CAP_MULTI_R2T | CAP_HDRDGST
  938. | CAP_DATADGST,
  939. /* session management */
  940. .create_session = iscsi_sw_tcp_session_create,
  941. .destroy_session = iscsi_sw_tcp_session_destroy,
  942. /* connection management */
  943. .create_conn = iscsi_sw_tcp_conn_create,
  944. .bind_conn = iscsi_sw_tcp_conn_bind,
  945. .destroy_conn = iscsi_sw_tcp_conn_destroy,
  946. .attr_is_visible = iscsi_sw_tcp_attr_is_visible,
  947. .set_param = iscsi_sw_tcp_conn_set_param,
  948. .get_conn_param = iscsi_sw_tcp_conn_get_param,
  949. .get_session_param = iscsi_session_get_param,
  950. .start_conn = iscsi_conn_start,
  951. .stop_conn = iscsi_sw_tcp_conn_stop,
  952. /* iscsi host params */
  953. .get_host_param = iscsi_sw_tcp_host_get_param,
  954. .set_host_param = iscsi_host_set_param,
  955. /* IO */
  956. .send_pdu = iscsi_conn_send_pdu,
  957. .get_stats = iscsi_sw_tcp_conn_get_stats,
  958. /* iscsi task/cmd helpers */
  959. .init_task = iscsi_tcp_task_init,
  960. .xmit_task = iscsi_tcp_task_xmit,
  961. .cleanup_task = iscsi_tcp_cleanup_task,
  962. /* low level pdu helpers */
  963. .xmit_pdu = iscsi_sw_tcp_pdu_xmit,
  964. .init_pdu = iscsi_sw_tcp_pdu_init,
  965. .alloc_pdu = iscsi_sw_tcp_pdu_alloc,
  966. /* recovery */
  967. .session_recovery_timedout = iscsi_session_recovery_timedout,
  968. };
  969. static int __init iscsi_sw_tcp_init(void)
  970. {
  971. if (iscsi_max_lun < 1) {
  972. printk(KERN_ERR "iscsi_tcp: Invalid max_lun value of %u\n",
  973. iscsi_max_lun);
  974. return -EINVAL;
  975. }
  976. iscsi_sw_tcp_scsi_transport = iscsi_register_transport(
  977. &iscsi_sw_tcp_transport);
  978. if (!iscsi_sw_tcp_scsi_transport)
  979. return -ENODEV;
  980. return 0;
  981. }
  982. static void __exit iscsi_sw_tcp_exit(void)
  983. {
  984. iscsi_unregister_transport(&iscsi_sw_tcp_transport);
  985. }
  986. module_init(iscsi_sw_tcp_init);
  987. module_exit(iscsi_sw_tcp_exit);