iscsi_tcp.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151
  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 open-iscsi@googlegroups.com
  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 <trace/events/sock.h>
  39. #include "iscsi_tcp.h"
  40. MODULE_AUTHOR("Mike Christie <michaelc@cs.wisc.edu>, "
  41. "Dmitry Yusupov <dmitry_yus@yahoo.com>, "
  42. "Alex Aizman <itn780@yahoo.com>");
  43. MODULE_DESCRIPTION("iSCSI/TCP data-path");
  44. MODULE_LICENSE("GPL");
  45. static struct scsi_transport_template *iscsi_sw_tcp_scsi_transport;
  46. static const struct scsi_host_template iscsi_sw_tcp_sht;
  47. static struct iscsi_transport iscsi_sw_tcp_transport;
  48. static unsigned int iscsi_max_lun = ~0;
  49. module_param_named(max_lun, iscsi_max_lun, uint, S_IRUGO);
  50. static bool iscsi_recv_from_iscsi_q;
  51. module_param_named(recv_from_iscsi_q, iscsi_recv_from_iscsi_q, bool, 0644);
  52. 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.");
  53. static int iscsi_sw_tcp_dbg;
  54. module_param_named(debug_iscsi_tcp, iscsi_sw_tcp_dbg, int,
  55. S_IRUGO | S_IWUSR);
  56. MODULE_PARM_DESC(debug_iscsi_tcp, "Turn on debugging for iscsi_tcp module "
  57. "Set to 1 to turn on, and zero to turn off. Default is off.");
  58. #define ISCSI_SW_TCP_DBG(_conn, dbg_fmt, arg...) \
  59. do { \
  60. if (iscsi_sw_tcp_dbg) \
  61. iscsi_conn_printk(KERN_INFO, _conn, \
  62. "%s " dbg_fmt, \
  63. __func__, ##arg); \
  64. iscsi_dbg_trace(trace_iscsi_dbg_sw_tcp, \
  65. &(_conn)->cls_conn->dev, \
  66. "%s " dbg_fmt, __func__, ##arg);\
  67. } while (0);
  68. /**
  69. * iscsi_sw_tcp_recv - TCP receive in sendfile fashion
  70. * @rd_desc: read descriptor
  71. * @skb: socket buffer
  72. * @offset: offset in skb
  73. * @len: skb->len - offset
  74. */
  75. static int iscsi_sw_tcp_recv(read_descriptor_t *rd_desc, struct sk_buff *skb,
  76. unsigned int offset, size_t len)
  77. {
  78. struct iscsi_conn *conn = rd_desc->arg.data;
  79. unsigned int consumed, total_consumed = 0;
  80. int status;
  81. ISCSI_SW_TCP_DBG(conn, "in %d bytes\n", skb->len - offset);
  82. do {
  83. status = 0;
  84. consumed = iscsi_tcp_recv_skb(conn, skb, offset, 0, &status);
  85. offset += consumed;
  86. total_consumed += consumed;
  87. } while (consumed != 0 && status != ISCSI_TCP_SKB_DONE);
  88. ISCSI_SW_TCP_DBG(conn, "read %d bytes status %d\n",
  89. skb->len - offset, status);
  90. return total_consumed;
  91. }
  92. /**
  93. * iscsi_sw_sk_state_check - check socket state
  94. * @sk: socket
  95. *
  96. * If the socket is in CLOSE or CLOSE_WAIT we should
  97. * not close the connection if there is still some
  98. * data pending.
  99. *
  100. * Must be called with sk_callback_lock.
  101. */
  102. static inline int iscsi_sw_sk_state_check(struct sock *sk)
  103. {
  104. struct iscsi_conn *conn = sk->sk_user_data;
  105. if ((sk->sk_state == TCP_CLOSE_WAIT || sk->sk_state == TCP_CLOSE) &&
  106. (conn->session->state != ISCSI_STATE_LOGGING_OUT) &&
  107. !atomic_read(&sk->sk_rmem_alloc)) {
  108. ISCSI_SW_TCP_DBG(conn, "TCP_CLOSE|TCP_CLOSE_WAIT\n");
  109. iscsi_conn_failure(conn, ISCSI_ERR_TCP_CONN_CLOSE);
  110. return -ECONNRESET;
  111. }
  112. return 0;
  113. }
  114. static void iscsi_sw_tcp_recv_data(struct iscsi_conn *conn)
  115. {
  116. struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
  117. struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
  118. struct sock *sk = tcp_sw_conn->sock->sk;
  119. read_descriptor_t rd_desc;
  120. /*
  121. * Use rd_desc to pass 'conn' to iscsi_tcp_recv.
  122. * We set count to 1 because we want the network layer to
  123. * hand us all the skbs that are available. iscsi_tcp_recv
  124. * handled pdus that cross buffers or pdus that still need data.
  125. */
  126. rd_desc.arg.data = conn;
  127. rd_desc.count = 1;
  128. tcp_read_sock(sk, &rd_desc, iscsi_sw_tcp_recv);
  129. /* If we had to (atomically) map a highmem page,
  130. * unmap it now. */
  131. iscsi_tcp_segment_unmap(&tcp_conn->in.segment);
  132. iscsi_sw_sk_state_check(sk);
  133. }
  134. static void iscsi_sw_tcp_recv_data_work(struct work_struct *work)
  135. {
  136. struct iscsi_conn *conn = container_of(work, struct iscsi_conn,
  137. recvwork);
  138. struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
  139. struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
  140. struct sock *sk = tcp_sw_conn->sock->sk;
  141. lock_sock(sk);
  142. iscsi_sw_tcp_recv_data(conn);
  143. release_sock(sk);
  144. }
  145. static void iscsi_sw_tcp_data_ready(struct sock *sk)
  146. {
  147. struct iscsi_sw_tcp_conn *tcp_sw_conn;
  148. struct iscsi_tcp_conn *tcp_conn;
  149. struct iscsi_conn *conn;
  150. trace_sk_data_ready(sk);
  151. read_lock_bh(&sk->sk_callback_lock);
  152. conn = sk->sk_user_data;
  153. if (!conn) {
  154. read_unlock_bh(&sk->sk_callback_lock);
  155. return;
  156. }
  157. tcp_conn = conn->dd_data;
  158. tcp_sw_conn = tcp_conn->dd_data;
  159. if (tcp_sw_conn->queue_recv)
  160. iscsi_conn_queue_recv(conn);
  161. else
  162. iscsi_sw_tcp_recv_data(conn);
  163. read_unlock_bh(&sk->sk_callback_lock);
  164. }
  165. static void iscsi_sw_tcp_state_change(struct sock *sk)
  166. {
  167. struct iscsi_tcp_conn *tcp_conn;
  168. struct iscsi_sw_tcp_conn *tcp_sw_conn;
  169. struct iscsi_conn *conn;
  170. void (*old_state_change)(struct sock *);
  171. read_lock_bh(&sk->sk_callback_lock);
  172. conn = sk->sk_user_data;
  173. if (!conn) {
  174. read_unlock_bh(&sk->sk_callback_lock);
  175. return;
  176. }
  177. iscsi_sw_sk_state_check(sk);
  178. tcp_conn = conn->dd_data;
  179. tcp_sw_conn = tcp_conn->dd_data;
  180. old_state_change = tcp_sw_conn->old_state_change;
  181. read_unlock_bh(&sk->sk_callback_lock);
  182. old_state_change(sk);
  183. }
  184. /**
  185. * iscsi_sw_tcp_write_space - Called when more output buffer space is available
  186. * @sk: socket space is available for
  187. **/
  188. static void iscsi_sw_tcp_write_space(struct sock *sk)
  189. {
  190. struct iscsi_conn *conn;
  191. struct iscsi_tcp_conn *tcp_conn;
  192. struct iscsi_sw_tcp_conn *tcp_sw_conn;
  193. void (*old_write_space)(struct sock *);
  194. read_lock_bh(&sk->sk_callback_lock);
  195. conn = sk->sk_user_data;
  196. if (!conn) {
  197. read_unlock_bh(&sk->sk_callback_lock);
  198. return;
  199. }
  200. tcp_conn = conn->dd_data;
  201. tcp_sw_conn = tcp_conn->dd_data;
  202. old_write_space = tcp_sw_conn->old_write_space;
  203. read_unlock_bh(&sk->sk_callback_lock);
  204. old_write_space(sk);
  205. ISCSI_SW_TCP_DBG(conn, "iscsi_write_space\n");
  206. iscsi_conn_queue_xmit(conn);
  207. }
  208. static void iscsi_sw_tcp_conn_set_callbacks(struct iscsi_conn *conn)
  209. {
  210. struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
  211. struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
  212. struct sock *sk = tcp_sw_conn->sock->sk;
  213. /* assign new callbacks */
  214. write_lock_bh(&sk->sk_callback_lock);
  215. sk->sk_user_data = conn;
  216. tcp_sw_conn->old_data_ready = sk->sk_data_ready;
  217. tcp_sw_conn->old_state_change = sk->sk_state_change;
  218. tcp_sw_conn->old_write_space = sk->sk_write_space;
  219. sk->sk_data_ready = iscsi_sw_tcp_data_ready;
  220. sk->sk_state_change = iscsi_sw_tcp_state_change;
  221. sk->sk_write_space = iscsi_sw_tcp_write_space;
  222. write_unlock_bh(&sk->sk_callback_lock);
  223. }
  224. static void
  225. iscsi_sw_tcp_conn_restore_callbacks(struct iscsi_conn *conn)
  226. {
  227. struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
  228. struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
  229. struct sock *sk = tcp_sw_conn->sock->sk;
  230. /* restore socket callbacks, see also: iscsi_conn_set_callbacks() */
  231. write_lock_bh(&sk->sk_callback_lock);
  232. sk->sk_user_data = NULL;
  233. sk->sk_data_ready = tcp_sw_conn->old_data_ready;
  234. sk->sk_state_change = tcp_sw_conn->old_state_change;
  235. sk->sk_write_space = tcp_sw_conn->old_write_space;
  236. sk->sk_no_check_tx = 0;
  237. write_unlock_bh(&sk->sk_callback_lock);
  238. }
  239. /**
  240. * iscsi_sw_tcp_xmit_segment - transmit segment
  241. * @tcp_conn: the iSCSI TCP connection
  242. * @segment: the buffer to transmnit
  243. *
  244. * This function transmits as much of the buffer as
  245. * the network layer will accept, and returns the number of
  246. * bytes transmitted.
  247. *
  248. * If CRC hashing is enabled, the function will compute the
  249. * hash as it goes. When the entire segment has been transmitted,
  250. * it will retrieve the hash value and send it as well.
  251. */
  252. static int iscsi_sw_tcp_xmit_segment(struct iscsi_tcp_conn *tcp_conn,
  253. struct iscsi_segment *segment)
  254. {
  255. struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
  256. struct socket *sk = tcp_sw_conn->sock;
  257. unsigned int copied = 0;
  258. int r = 0;
  259. while (!iscsi_tcp_segment_done(tcp_conn, segment, 0, r)) {
  260. struct scatterlist *sg;
  261. struct msghdr msg = {};
  262. struct bio_vec bv;
  263. unsigned int offset, copy;
  264. r = 0;
  265. offset = segment->copied;
  266. copy = segment->size - offset;
  267. if (segment->total_copied + segment->size < segment->total_size)
  268. msg.msg_flags |= MSG_MORE;
  269. if (tcp_sw_conn->queue_recv)
  270. msg.msg_flags |= MSG_DONTWAIT;
  271. if (!segment->data) {
  272. if (!tcp_conn->iscsi_conn->datadgst_en)
  273. msg.msg_flags |= MSG_SPLICE_PAGES;
  274. sg = segment->sg;
  275. offset += segment->sg_offset + sg->offset;
  276. bvec_set_page(&bv, sg_page(sg), copy, offset);
  277. } else {
  278. bvec_set_virt(&bv, segment->data + offset, copy);
  279. }
  280. iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, &bv, 1, copy);
  281. r = sock_sendmsg(sk, &msg);
  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->sk_use_task_frag = false;
  626. sk_set_memalloc(sk);
  627. sock_no_linger(sk);
  628. iscsi_sw_tcp_conn_set_callbacks(conn);
  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. mutex_unlock(&tcp_sw_conn->sock_lock);
  657. break;
  658. case ISCSI_PARAM_MAX_R2T:
  659. return iscsi_tcp_set_max_r2t(conn, buf);
  660. default:
  661. return iscsi_set_param(cls_conn, param, buf, buflen);
  662. }
  663. return 0;
  664. }
  665. static int iscsi_sw_tcp_conn_get_param(struct iscsi_cls_conn *cls_conn,
  666. enum iscsi_param param, char *buf)
  667. {
  668. struct iscsi_conn *conn = cls_conn->dd_data;
  669. struct iscsi_sw_tcp_conn *tcp_sw_conn;
  670. struct iscsi_tcp_conn *tcp_conn;
  671. struct sockaddr_in6 addr;
  672. struct socket *sock;
  673. int rc;
  674. switch(param) {
  675. case ISCSI_PARAM_CONN_PORT:
  676. case ISCSI_PARAM_CONN_ADDRESS:
  677. case ISCSI_PARAM_LOCAL_PORT:
  678. spin_lock_bh(&conn->session->frwd_lock);
  679. if (!conn->session->leadconn) {
  680. spin_unlock_bh(&conn->session->frwd_lock);
  681. return -ENOTCONN;
  682. }
  683. /*
  684. * The conn has been setup and bound, so just grab a ref
  685. * incase a destroy runs while we are in the net layer.
  686. */
  687. iscsi_get_conn(conn->cls_conn);
  688. spin_unlock_bh(&conn->session->frwd_lock);
  689. tcp_conn = conn->dd_data;
  690. tcp_sw_conn = tcp_conn->dd_data;
  691. mutex_lock(&tcp_sw_conn->sock_lock);
  692. sock = tcp_sw_conn->sock;
  693. if (!sock) {
  694. rc = -ENOTCONN;
  695. goto sock_unlock;
  696. }
  697. if (param == ISCSI_PARAM_LOCAL_PORT)
  698. rc = kernel_getsockname(sock,
  699. (struct sockaddr *)&addr);
  700. else
  701. rc = kernel_getpeername(sock,
  702. (struct sockaddr *)&addr);
  703. sock_unlock:
  704. mutex_unlock(&tcp_sw_conn->sock_lock);
  705. iscsi_put_conn(conn->cls_conn);
  706. if (rc < 0)
  707. return rc;
  708. return iscsi_conn_get_addr_param((struct sockaddr_storage *)
  709. &addr, param, buf);
  710. default:
  711. return iscsi_conn_get_param(cls_conn, param, buf);
  712. }
  713. return 0;
  714. }
  715. static int iscsi_sw_tcp_host_get_param(struct Scsi_Host *shost,
  716. enum iscsi_host_param param, char *buf)
  717. {
  718. struct iscsi_sw_tcp_host *tcp_sw_host = iscsi_host_priv(shost);
  719. struct iscsi_session *session;
  720. struct iscsi_conn *conn;
  721. struct iscsi_tcp_conn *tcp_conn;
  722. struct iscsi_sw_tcp_conn *tcp_sw_conn;
  723. struct sockaddr_in6 addr;
  724. struct socket *sock;
  725. int rc;
  726. switch (param) {
  727. case ISCSI_HOST_PARAM_IPADDRESS:
  728. session = tcp_sw_host->session;
  729. if (!session)
  730. return -ENOTCONN;
  731. spin_lock_bh(&session->frwd_lock);
  732. conn = session->leadconn;
  733. if (!conn) {
  734. spin_unlock_bh(&session->frwd_lock);
  735. return -ENOTCONN;
  736. }
  737. tcp_conn = conn->dd_data;
  738. tcp_sw_conn = tcp_conn->dd_data;
  739. /*
  740. * The conn has been setup and bound, so just grab a ref
  741. * incase a destroy runs while we are in the net layer.
  742. */
  743. iscsi_get_conn(conn->cls_conn);
  744. spin_unlock_bh(&session->frwd_lock);
  745. mutex_lock(&tcp_sw_conn->sock_lock);
  746. sock = tcp_sw_conn->sock;
  747. if (!sock)
  748. rc = -ENOTCONN;
  749. else
  750. rc = kernel_getsockname(sock, (struct sockaddr *)&addr);
  751. mutex_unlock(&tcp_sw_conn->sock_lock);
  752. iscsi_put_conn(conn->cls_conn);
  753. if (rc < 0)
  754. return rc;
  755. return iscsi_conn_get_addr_param((struct sockaddr_storage *)
  756. &addr,
  757. (enum iscsi_param)param, buf);
  758. default:
  759. return iscsi_host_get_param(shost, param, buf);
  760. }
  761. return 0;
  762. }
  763. static void
  764. iscsi_sw_tcp_conn_get_stats(struct iscsi_cls_conn *cls_conn,
  765. struct iscsi_stats *stats)
  766. {
  767. struct iscsi_conn *conn = cls_conn->dd_data;
  768. struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
  769. struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
  770. stats->custom_length = 3;
  771. strcpy(stats->custom[0].desc, "tx_sendpage_failures");
  772. stats->custom[0].value = tcp_sw_conn->sendpage_failures_cnt;
  773. strcpy(stats->custom[1].desc, "rx_discontiguous_hdr");
  774. stats->custom[1].value = tcp_sw_conn->discontiguous_hdr_cnt;
  775. strcpy(stats->custom[2].desc, "eh_abort_cnt");
  776. stats->custom[2].value = conn->eh_abort_cnt;
  777. iscsi_tcp_conn_get_stats(cls_conn, stats);
  778. }
  779. static struct iscsi_cls_session *
  780. iscsi_sw_tcp_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max,
  781. uint16_t qdepth, uint32_t initial_cmdsn)
  782. {
  783. struct iscsi_cls_session *cls_session;
  784. struct iscsi_session *session;
  785. struct iscsi_sw_tcp_host *tcp_sw_host;
  786. struct Scsi_Host *shost;
  787. int rc;
  788. if (ep) {
  789. printk(KERN_ERR "iscsi_tcp: invalid ep %p.\n", ep);
  790. return NULL;
  791. }
  792. shost = iscsi_host_alloc(&iscsi_sw_tcp_sht,
  793. sizeof(struct iscsi_sw_tcp_host), 1);
  794. if (!shost)
  795. return NULL;
  796. shost->transportt = iscsi_sw_tcp_scsi_transport;
  797. shost->cmd_per_lun = qdepth;
  798. shost->max_lun = iscsi_max_lun;
  799. shost->max_id = 0;
  800. shost->max_channel = 0;
  801. shost->max_cmd_len = SCSI_MAX_VARLEN_CDB_SIZE;
  802. shost->dma_alignment = 0;
  803. rc = iscsi_host_get_max_scsi_cmds(shost, cmds_max);
  804. if (rc < 0)
  805. goto free_host;
  806. shost->can_queue = rc;
  807. if (iscsi_host_add(shost, NULL))
  808. goto free_host;
  809. cls_session = iscsi_session_setup(&iscsi_sw_tcp_transport, shost,
  810. cmds_max, 0,
  811. sizeof(struct iscsi_tcp_task) +
  812. sizeof(struct iscsi_sw_tcp_hdrbuf),
  813. initial_cmdsn, 0);
  814. if (!cls_session)
  815. goto remove_host;
  816. session = cls_session->dd_data;
  817. if (iscsi_tcp_r2tpool_alloc(session))
  818. goto remove_session;
  819. /* We are now fully setup so expose the session to sysfs. */
  820. tcp_sw_host = iscsi_host_priv(shost);
  821. tcp_sw_host->session = session;
  822. return cls_session;
  823. remove_session:
  824. iscsi_session_teardown(cls_session);
  825. remove_host:
  826. iscsi_host_remove(shost, false);
  827. free_host:
  828. iscsi_host_free(shost);
  829. return NULL;
  830. }
  831. static void iscsi_sw_tcp_session_destroy(struct iscsi_cls_session *cls_session)
  832. {
  833. struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
  834. struct iscsi_session *session = cls_session->dd_data;
  835. if (WARN_ON_ONCE(session->leadconn))
  836. return;
  837. iscsi_session_remove(cls_session);
  838. /*
  839. * Our get_host_param needs to access the session, so remove the
  840. * host from sysfs before freeing the session to make sure userspace
  841. * is no longer accessing the callout.
  842. */
  843. iscsi_host_remove(shost, false);
  844. iscsi_tcp_r2tpool_free(cls_session->dd_data);
  845. iscsi_session_free(cls_session);
  846. iscsi_host_free(shost);
  847. }
  848. static umode_t iscsi_sw_tcp_attr_is_visible(int param_type, int param)
  849. {
  850. switch (param_type) {
  851. case ISCSI_HOST_PARAM:
  852. switch (param) {
  853. case ISCSI_HOST_PARAM_NETDEV_NAME:
  854. case ISCSI_HOST_PARAM_HWADDRESS:
  855. case ISCSI_HOST_PARAM_IPADDRESS:
  856. case ISCSI_HOST_PARAM_INITIATOR_NAME:
  857. return S_IRUGO;
  858. default:
  859. return 0;
  860. }
  861. case ISCSI_PARAM:
  862. switch (param) {
  863. case ISCSI_PARAM_MAX_RECV_DLENGTH:
  864. case ISCSI_PARAM_MAX_XMIT_DLENGTH:
  865. case ISCSI_PARAM_HDRDGST_EN:
  866. case ISCSI_PARAM_DATADGST_EN:
  867. case ISCSI_PARAM_CONN_ADDRESS:
  868. case ISCSI_PARAM_CONN_PORT:
  869. case ISCSI_PARAM_LOCAL_PORT:
  870. case ISCSI_PARAM_EXP_STATSN:
  871. case ISCSI_PARAM_PERSISTENT_ADDRESS:
  872. case ISCSI_PARAM_PERSISTENT_PORT:
  873. case ISCSI_PARAM_PING_TMO:
  874. case ISCSI_PARAM_RECV_TMO:
  875. case ISCSI_PARAM_INITIAL_R2T_EN:
  876. case ISCSI_PARAM_MAX_R2T:
  877. case ISCSI_PARAM_IMM_DATA_EN:
  878. case ISCSI_PARAM_FIRST_BURST:
  879. case ISCSI_PARAM_MAX_BURST:
  880. case ISCSI_PARAM_PDU_INORDER_EN:
  881. case ISCSI_PARAM_DATASEQ_INORDER_EN:
  882. case ISCSI_PARAM_ERL:
  883. case ISCSI_PARAM_TARGET_NAME:
  884. case ISCSI_PARAM_TPGT:
  885. case ISCSI_PARAM_USERNAME:
  886. case ISCSI_PARAM_PASSWORD:
  887. case ISCSI_PARAM_USERNAME_IN:
  888. case ISCSI_PARAM_PASSWORD_IN:
  889. case ISCSI_PARAM_FAST_ABORT:
  890. case ISCSI_PARAM_ABORT_TMO:
  891. case ISCSI_PARAM_LU_RESET_TMO:
  892. case ISCSI_PARAM_TGT_RESET_TMO:
  893. case ISCSI_PARAM_IFACE_NAME:
  894. case ISCSI_PARAM_INITIATOR_NAME:
  895. return S_IRUGO;
  896. default:
  897. return 0;
  898. }
  899. }
  900. return 0;
  901. }
  902. static int iscsi_sw_tcp_device_configure(struct scsi_device *sdev,
  903. struct queue_limits *lim)
  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. lim->features |= BLK_FEAT_STABLE_WRITES;
  910. return 0;
  911. }
  912. static const struct scsi_host_template iscsi_sw_tcp_sht = {
  913. .module = THIS_MODULE,
  914. .name = "iSCSI Initiator over TCP/IP",
  915. .queuecommand = iscsi_queuecommand,
  916. .change_queue_depth = scsi_change_queue_depth,
  917. .can_queue = ISCSI_TOTAL_CMDS_MAX,
  918. .sg_tablesize = 4096,
  919. .max_sectors = 0xFFFF,
  920. .cmd_per_lun = ISCSI_DEF_CMD_PER_LUN,
  921. .eh_timed_out = iscsi_eh_cmd_timed_out,
  922. .eh_abort_handler = iscsi_eh_abort,
  923. .eh_device_reset_handler= iscsi_eh_device_reset,
  924. .eh_target_reset_handler = iscsi_eh_recover_target,
  925. .dma_boundary = PAGE_SIZE - 1,
  926. .device_configure = iscsi_sw_tcp_device_configure,
  927. .proc_name = "iscsi_tcp",
  928. .this_id = -1,
  929. .track_queue_depth = 1,
  930. .cmd_size = sizeof(struct iscsi_cmd),
  931. };
  932. static struct iscsi_transport iscsi_sw_tcp_transport = {
  933. .owner = THIS_MODULE,
  934. .name = "tcp",
  935. .caps = CAP_RECOVERY_L0 | CAP_MULTI_R2T | CAP_HDRDGST
  936. | CAP_DATADGST,
  937. /* session management */
  938. .create_session = iscsi_sw_tcp_session_create,
  939. .destroy_session = iscsi_sw_tcp_session_destroy,
  940. /* connection management */
  941. .create_conn = iscsi_sw_tcp_conn_create,
  942. .bind_conn = iscsi_sw_tcp_conn_bind,
  943. .destroy_conn = iscsi_sw_tcp_conn_destroy,
  944. .attr_is_visible = iscsi_sw_tcp_attr_is_visible,
  945. .set_param = iscsi_sw_tcp_conn_set_param,
  946. .get_conn_param = iscsi_sw_tcp_conn_get_param,
  947. .get_session_param = iscsi_session_get_param,
  948. .start_conn = iscsi_conn_start,
  949. .stop_conn = iscsi_sw_tcp_conn_stop,
  950. /* iscsi host params */
  951. .get_host_param = iscsi_sw_tcp_host_get_param,
  952. .set_host_param = iscsi_host_set_param,
  953. /* IO */
  954. .send_pdu = iscsi_conn_send_pdu,
  955. .get_stats = iscsi_sw_tcp_conn_get_stats,
  956. /* iscsi task/cmd helpers */
  957. .init_task = iscsi_tcp_task_init,
  958. .xmit_task = iscsi_tcp_task_xmit,
  959. .cleanup_task = iscsi_tcp_cleanup_task,
  960. /* low level pdu helpers */
  961. .xmit_pdu = iscsi_sw_tcp_pdu_xmit,
  962. .init_pdu = iscsi_sw_tcp_pdu_init,
  963. .alloc_pdu = iscsi_sw_tcp_pdu_alloc,
  964. /* recovery */
  965. .session_recovery_timedout = iscsi_session_recovery_timedout,
  966. };
  967. static int __init iscsi_sw_tcp_init(void)
  968. {
  969. if (iscsi_max_lun < 1) {
  970. printk(KERN_ERR "iscsi_tcp: Invalid max_lun value of %u\n",
  971. iscsi_max_lun);
  972. return -EINVAL;
  973. }
  974. iscsi_sw_tcp_scsi_transport = iscsi_register_transport(
  975. &iscsi_sw_tcp_transport);
  976. if (!iscsi_sw_tcp_scsi_transport)
  977. return -ENODEV;
  978. return 0;
  979. }
  980. static void __exit iscsi_sw_tcp_exit(void)
  981. {
  982. iscsi_unregister_transport(&iscsi_sw_tcp_transport);
  983. }
  984. module_init(iscsi_sw_tcp_init);
  985. module_exit(iscsi_sw_tcp_exit);