libiscsi_tcp.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184
  1. /*
  2. * iSCSI over TCP/IP Data-Path lib
  3. *
  4. * Copyright (C) 2004 Dmitry Yusupov
  5. * Copyright (C) 2004 Alex Aizman
  6. * Copyright (C) 2005 - 2006 Mike Christie
  7. * Copyright (C) 2006 Red Hat, Inc. All rights reserved.
  8. * maintained by open-iscsi@googlegroups.com
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published
  12. * by the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * See the file COPYING included with this distribution for more details.
  21. *
  22. * Credits:
  23. * Christoph Hellwig
  24. * FUJITA Tomonori
  25. * Arne Redlich
  26. * Zhenyu Wang
  27. */
  28. #include <linux/types.h>
  29. #include <linux/list.h>
  30. #include <linux/inet.h>
  31. #include <linux/slab.h>
  32. #include <linux/file.h>
  33. #include <linux/blkdev.h>
  34. #include <linux/crypto.h>
  35. #include <linux/delay.h>
  36. #include <linux/kfifo.h>
  37. #include <linux/scatterlist.h>
  38. #include <net/tcp.h>
  39. #include <scsi/scsi_cmnd.h>
  40. #include <scsi/scsi_device.h>
  41. #include <scsi/scsi_host.h>
  42. #include <scsi/scsi.h>
  43. #include <scsi/scsi_transport_iscsi.h>
  44. #include "iscsi_tcp.h"
  45. MODULE_AUTHOR("Mike Christie <michaelc@cs.wisc.edu>, "
  46. "Dmitry Yusupov <dmitry_yus@yahoo.com>, "
  47. "Alex Aizman <itn780@yahoo.com>");
  48. MODULE_DESCRIPTION("iSCSI/TCP data-path");
  49. MODULE_LICENSE("GPL");
  50. static int iscsi_dbg_libtcp;
  51. module_param_named(debug_libiscsi_tcp, iscsi_dbg_libtcp, int,
  52. S_IRUGO | S_IWUSR);
  53. MODULE_PARM_DESC(debug_libiscsi_tcp, "Turn on debugging for libiscsi_tcp "
  54. "module. Set to 1 to turn on, and zero to turn off. Default "
  55. "is off.");
  56. #define ISCSI_DBG_TCP(_conn, dbg_fmt, arg...) \
  57. do { \
  58. if (iscsi_dbg_libtcp) \
  59. iscsi_conn_printk(KERN_INFO, _conn, \
  60. "%s " dbg_fmt, \
  61. __func__, ##arg); \
  62. } while (0);
  63. static int iscsi_tcp_hdr_recv_done(struct iscsi_tcp_conn *tcp_conn,
  64. struct iscsi_segment *segment);
  65. /*
  66. * Scatterlist handling: inside the iscsi_segment, we
  67. * remember an index into the scatterlist, and set data/size
  68. * to the current scatterlist entry. For highmem pages, we
  69. * kmap as needed.
  70. *
  71. * Note that the page is unmapped when we return from
  72. * TCP's data_ready handler, so we may end up mapping and
  73. * unmapping the same page repeatedly. The whole reason
  74. * for this is that we shouldn't keep the page mapped
  75. * outside the softirq.
  76. */
  77. /**
  78. * iscsi_tcp_segment_init_sg - init indicated scatterlist entry
  79. * @segment: the buffer object
  80. * @sg: scatterlist
  81. * @offset: byte offset into that sg entry
  82. *
  83. * This function sets up the segment so that subsequent
  84. * data is copied to the indicated sg entry, at the given
  85. * offset.
  86. */
  87. static inline void
  88. iscsi_tcp_segment_init_sg(struct iscsi_segment *segment,
  89. struct scatterlist *sg, unsigned int offset)
  90. {
  91. segment->sg = sg;
  92. segment->sg_offset = offset;
  93. segment->size = min(sg->length - offset,
  94. segment->total_size - segment->total_copied);
  95. segment->data = NULL;
  96. }
  97. /**
  98. * iscsi_tcp_segment_map - map the current S/G page
  99. * @segment: iscsi_segment
  100. * @recv: 1 if called from recv path
  101. *
  102. * We only need to possibly kmap data if scatter lists are being used,
  103. * because the iscsi passthrough and internal IO paths will never use high
  104. * mem pages.
  105. */
  106. static void iscsi_tcp_segment_map(struct iscsi_segment *segment, int recv)
  107. {
  108. struct scatterlist *sg;
  109. if (segment->data != NULL || !segment->sg)
  110. return;
  111. sg = segment->sg;
  112. BUG_ON(segment->sg_mapped);
  113. BUG_ON(sg->length == 0);
  114. /*
  115. * If the page count is greater than one it is ok to send
  116. * to the network layer's zero copy send path. If not we
  117. * have to go the slow sendmsg path. We always map for the
  118. * recv path.
  119. */
  120. if (page_count(sg_page(sg)) >= 1 && !recv)
  121. return;
  122. segment->sg_mapped = kmap_atomic(sg_page(sg), KM_SOFTIRQ0);
  123. segment->data = segment->sg_mapped + sg->offset + segment->sg_offset;
  124. }
  125. void iscsi_tcp_segment_unmap(struct iscsi_segment *segment)
  126. {
  127. if (segment->sg_mapped) {
  128. kunmap_atomic(segment->sg_mapped, KM_SOFTIRQ0);
  129. segment->sg_mapped = NULL;
  130. segment->data = NULL;
  131. }
  132. }
  133. EXPORT_SYMBOL_GPL(iscsi_tcp_segment_unmap);
  134. /*
  135. * Splice the digest buffer into the buffer
  136. */
  137. static inline void
  138. iscsi_tcp_segment_splice_digest(struct iscsi_segment *segment, void *digest)
  139. {
  140. segment->data = digest;
  141. segment->digest_len = ISCSI_DIGEST_SIZE;
  142. segment->total_size += ISCSI_DIGEST_SIZE;
  143. segment->size = ISCSI_DIGEST_SIZE;
  144. segment->copied = 0;
  145. segment->sg = NULL;
  146. segment->hash = NULL;
  147. }
  148. /**
  149. * iscsi_tcp_segment_done - check whether the segment is complete
  150. * @tcp_conn: iscsi tcp connection
  151. * @segment: iscsi segment to check
  152. * @recv: set to one of this is called from the recv path
  153. * @copied: number of bytes copied
  154. *
  155. * Check if we're done receiving this segment. If the receive
  156. * buffer is full but we expect more data, move on to the
  157. * next entry in the scatterlist.
  158. *
  159. * If the amount of data we received isn't a multiple of 4,
  160. * we will transparently receive the pad bytes, too.
  161. *
  162. * This function must be re-entrant.
  163. */
  164. int iscsi_tcp_segment_done(struct iscsi_tcp_conn *tcp_conn,
  165. struct iscsi_segment *segment, int recv,
  166. unsigned copied)
  167. {
  168. struct scatterlist sg;
  169. unsigned int pad;
  170. ISCSI_DBG_TCP(tcp_conn->iscsi_conn, "copied %u %u size %u %s\n",
  171. segment->copied, copied, segment->size,
  172. recv ? "recv" : "xmit");
  173. if (segment->hash && copied) {
  174. /*
  175. * If a segment is kmapd we must unmap it before sending
  176. * to the crypto layer since that will try to kmap it again.
  177. */
  178. iscsi_tcp_segment_unmap(segment);
  179. if (!segment->data) {
  180. sg_init_table(&sg, 1);
  181. sg_set_page(&sg, sg_page(segment->sg), copied,
  182. segment->copied + segment->sg_offset +
  183. segment->sg->offset);
  184. } else
  185. sg_init_one(&sg, segment->data + segment->copied,
  186. copied);
  187. crypto_hash_update(segment->hash, &sg, copied);
  188. }
  189. segment->copied += copied;
  190. if (segment->copied < segment->size) {
  191. iscsi_tcp_segment_map(segment, recv);
  192. return 0;
  193. }
  194. segment->total_copied += segment->copied;
  195. segment->copied = 0;
  196. segment->size = 0;
  197. /* Unmap the current scatterlist page, if there is one. */
  198. iscsi_tcp_segment_unmap(segment);
  199. /* Do we have more scatterlist entries? */
  200. ISCSI_DBG_TCP(tcp_conn->iscsi_conn, "total copied %u total size %u\n",
  201. segment->total_copied, segment->total_size);
  202. if (segment->total_copied < segment->total_size) {
  203. /* Proceed to the next entry in the scatterlist. */
  204. iscsi_tcp_segment_init_sg(segment, sg_next(segment->sg),
  205. 0);
  206. iscsi_tcp_segment_map(segment, recv);
  207. BUG_ON(segment->size == 0);
  208. return 0;
  209. }
  210. /* Do we need to handle padding? */
  211. if (!(tcp_conn->iscsi_conn->session->tt->caps & CAP_PADDING_OFFLOAD)) {
  212. pad = iscsi_padding(segment->total_copied);
  213. if (pad != 0) {
  214. ISCSI_DBG_TCP(tcp_conn->iscsi_conn,
  215. "consume %d pad bytes\n", pad);
  216. segment->total_size += pad;
  217. segment->size = pad;
  218. segment->data = segment->padbuf;
  219. return 0;
  220. }
  221. }
  222. /*
  223. * Set us up for transferring the data digest. hdr digest
  224. * is completely handled in hdr done function.
  225. */
  226. if (segment->hash) {
  227. crypto_hash_final(segment->hash, segment->digest);
  228. iscsi_tcp_segment_splice_digest(segment,
  229. recv ? segment->recv_digest : segment->digest);
  230. return 0;
  231. }
  232. return 1;
  233. }
  234. EXPORT_SYMBOL_GPL(iscsi_tcp_segment_done);
  235. /**
  236. * iscsi_tcp_segment_recv - copy data to segment
  237. * @tcp_conn: the iSCSI TCP connection
  238. * @segment: the buffer to copy to
  239. * @ptr: data pointer
  240. * @len: amount of data available
  241. *
  242. * This function copies up to @len bytes to the
  243. * given buffer, and returns the number of bytes
  244. * consumed, which can actually be less than @len.
  245. *
  246. * If hash digest is enabled, the function will update the
  247. * hash while copying.
  248. * Combining these two operations doesn't buy us a lot (yet),
  249. * but in the future we could implement combined copy+crc,
  250. * just way we do for network layer checksums.
  251. */
  252. static int
  253. iscsi_tcp_segment_recv(struct iscsi_tcp_conn *tcp_conn,
  254. struct iscsi_segment *segment, const void *ptr,
  255. unsigned int len)
  256. {
  257. unsigned int copy = 0, copied = 0;
  258. while (!iscsi_tcp_segment_done(tcp_conn, segment, 1, copy)) {
  259. if (copied == len) {
  260. ISCSI_DBG_TCP(tcp_conn->iscsi_conn,
  261. "copied %d bytes\n", len);
  262. break;
  263. }
  264. copy = min(len - copied, segment->size - segment->copied);
  265. ISCSI_DBG_TCP(tcp_conn->iscsi_conn, "copying %d\n", copy);
  266. memcpy(segment->data + segment->copied, ptr + copied, copy);
  267. copied += copy;
  268. }
  269. return copied;
  270. }
  271. inline void
  272. iscsi_tcp_dgst_header(struct hash_desc *hash, const void *hdr, size_t hdrlen,
  273. unsigned char digest[ISCSI_DIGEST_SIZE])
  274. {
  275. struct scatterlist sg;
  276. sg_init_one(&sg, hdr, hdrlen);
  277. crypto_hash_digest(hash, &sg, hdrlen, digest);
  278. }
  279. EXPORT_SYMBOL_GPL(iscsi_tcp_dgst_header);
  280. static inline int
  281. iscsi_tcp_dgst_verify(struct iscsi_tcp_conn *tcp_conn,
  282. struct iscsi_segment *segment)
  283. {
  284. if (!segment->digest_len)
  285. return 1;
  286. if (memcmp(segment->recv_digest, segment->digest,
  287. segment->digest_len)) {
  288. ISCSI_DBG_TCP(tcp_conn->iscsi_conn, "digest mismatch\n");
  289. return 0;
  290. }
  291. return 1;
  292. }
  293. /*
  294. * Helper function to set up segment buffer
  295. */
  296. static inline void
  297. __iscsi_segment_init(struct iscsi_segment *segment, size_t size,
  298. iscsi_segment_done_fn_t *done, struct hash_desc *hash)
  299. {
  300. memset(segment, 0, sizeof(*segment));
  301. segment->total_size = size;
  302. segment->done = done;
  303. if (hash) {
  304. segment->hash = hash;
  305. crypto_hash_init(hash);
  306. }
  307. }
  308. inline void
  309. iscsi_segment_init_linear(struct iscsi_segment *segment, void *data,
  310. size_t size, iscsi_segment_done_fn_t *done,
  311. struct hash_desc *hash)
  312. {
  313. __iscsi_segment_init(segment, size, done, hash);
  314. segment->data = data;
  315. segment->size = size;
  316. }
  317. EXPORT_SYMBOL_GPL(iscsi_segment_init_linear);
  318. inline int
  319. iscsi_segment_seek_sg(struct iscsi_segment *segment,
  320. struct scatterlist *sg_list, unsigned int sg_count,
  321. unsigned int offset, size_t size,
  322. iscsi_segment_done_fn_t *done, struct hash_desc *hash)
  323. {
  324. struct scatterlist *sg;
  325. unsigned int i;
  326. __iscsi_segment_init(segment, size, done, hash);
  327. for_each_sg(sg_list, sg, sg_count, i) {
  328. if (offset < sg->length) {
  329. iscsi_tcp_segment_init_sg(segment, sg, offset);
  330. return 0;
  331. }
  332. offset -= sg->length;
  333. }
  334. return ISCSI_ERR_DATA_OFFSET;
  335. }
  336. EXPORT_SYMBOL_GPL(iscsi_segment_seek_sg);
  337. /**
  338. * iscsi_tcp_hdr_recv_prep - prep segment for hdr reception
  339. * @tcp_conn: iscsi connection to prep for
  340. *
  341. * This function always passes NULL for the hash argument, because when this
  342. * function is called we do not yet know the final size of the header and want
  343. * to delay the digest processing until we know that.
  344. */
  345. void iscsi_tcp_hdr_recv_prep(struct iscsi_tcp_conn *tcp_conn)
  346. {
  347. ISCSI_DBG_TCP(tcp_conn->iscsi_conn,
  348. "(%s)\n", tcp_conn->iscsi_conn->hdrdgst_en ?
  349. "digest enabled" : "digest disabled");
  350. iscsi_segment_init_linear(&tcp_conn->in.segment,
  351. tcp_conn->in.hdr_buf, sizeof(struct iscsi_hdr),
  352. iscsi_tcp_hdr_recv_done, NULL);
  353. }
  354. EXPORT_SYMBOL_GPL(iscsi_tcp_hdr_recv_prep);
  355. /*
  356. * Handle incoming reply to any other type of command
  357. */
  358. static int
  359. iscsi_tcp_data_recv_done(struct iscsi_tcp_conn *tcp_conn,
  360. struct iscsi_segment *segment)
  361. {
  362. struct iscsi_conn *conn = tcp_conn->iscsi_conn;
  363. int rc = 0;
  364. if (!iscsi_tcp_dgst_verify(tcp_conn, segment))
  365. return ISCSI_ERR_DATA_DGST;
  366. rc = iscsi_complete_pdu(conn, tcp_conn->in.hdr,
  367. conn->data, tcp_conn->in.datalen);
  368. if (rc)
  369. return rc;
  370. iscsi_tcp_hdr_recv_prep(tcp_conn);
  371. return 0;
  372. }
  373. static void
  374. iscsi_tcp_data_recv_prep(struct iscsi_tcp_conn *tcp_conn)
  375. {
  376. struct iscsi_conn *conn = tcp_conn->iscsi_conn;
  377. struct hash_desc *rx_hash = NULL;
  378. if (conn->datadgst_en &&
  379. !(conn->session->tt->caps & CAP_DIGEST_OFFLOAD))
  380. rx_hash = tcp_conn->rx_hash;
  381. iscsi_segment_init_linear(&tcp_conn->in.segment,
  382. conn->data, tcp_conn->in.datalen,
  383. iscsi_tcp_data_recv_done, rx_hash);
  384. }
  385. /**
  386. * iscsi_tcp_cleanup_task - free tcp_task resources
  387. * @task: iscsi task
  388. *
  389. * must be called with session lock
  390. */
  391. void iscsi_tcp_cleanup_task(struct iscsi_task *task)
  392. {
  393. struct iscsi_tcp_task *tcp_task = task->dd_data;
  394. struct iscsi_r2t_info *r2t;
  395. /* nothing to do for mgmt */
  396. if (!task->sc)
  397. return;
  398. /* flush task's r2t queues */
  399. while (kfifo_out(&tcp_task->r2tqueue, (void*)&r2t, sizeof(void*))) {
  400. kfifo_in(&tcp_task->r2tpool.queue, (void*)&r2t,
  401. sizeof(void*));
  402. ISCSI_DBG_TCP(task->conn, "pending r2t dropped\n");
  403. }
  404. r2t = tcp_task->r2t;
  405. if (r2t != NULL) {
  406. kfifo_in(&tcp_task->r2tpool.queue, (void*)&r2t,
  407. sizeof(void*));
  408. tcp_task->r2t = NULL;
  409. }
  410. }
  411. EXPORT_SYMBOL_GPL(iscsi_tcp_cleanup_task);
  412. /**
  413. * iscsi_tcp_data_in - SCSI Data-In Response processing
  414. * @conn: iscsi connection
  415. * @task: scsi command task
  416. */
  417. static int iscsi_tcp_data_in(struct iscsi_conn *conn, struct iscsi_task *task)
  418. {
  419. struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
  420. struct iscsi_tcp_task *tcp_task = task->dd_data;
  421. struct iscsi_data_rsp *rhdr = (struct iscsi_data_rsp *)tcp_conn->in.hdr;
  422. int datasn = be32_to_cpu(rhdr->datasn);
  423. unsigned total_in_length = scsi_in(task->sc)->length;
  424. /*
  425. * lib iscsi will update this in the completion handling if there
  426. * is status.
  427. */
  428. if (!(rhdr->flags & ISCSI_FLAG_DATA_STATUS))
  429. iscsi_update_cmdsn(conn->session, (struct iscsi_nopin*)rhdr);
  430. if (tcp_conn->in.datalen == 0)
  431. return 0;
  432. if (tcp_task->exp_datasn != datasn) {
  433. ISCSI_DBG_TCP(conn, "task->exp_datasn(%d) != rhdr->datasn(%d)"
  434. "\n", tcp_task->exp_datasn, datasn);
  435. return ISCSI_ERR_DATASN;
  436. }
  437. tcp_task->exp_datasn++;
  438. tcp_task->data_offset = be32_to_cpu(rhdr->offset);
  439. if (tcp_task->data_offset + tcp_conn->in.datalen > total_in_length) {
  440. ISCSI_DBG_TCP(conn, "data_offset(%d) + data_len(%d) > "
  441. "total_length_in(%d)\n", tcp_task->data_offset,
  442. tcp_conn->in.datalen, total_in_length);
  443. return ISCSI_ERR_DATA_OFFSET;
  444. }
  445. conn->datain_pdus_cnt++;
  446. return 0;
  447. }
  448. /**
  449. * iscsi_tcp_r2t_rsp - iSCSI R2T Response processing
  450. * @conn: iscsi connection
  451. * @task: scsi command task
  452. */
  453. static int iscsi_tcp_r2t_rsp(struct iscsi_conn *conn, struct iscsi_task *task)
  454. {
  455. struct iscsi_session *session = conn->session;
  456. struct iscsi_tcp_task *tcp_task = task->dd_data;
  457. struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
  458. struct iscsi_r2t_rsp *rhdr = (struct iscsi_r2t_rsp *)tcp_conn->in.hdr;
  459. struct iscsi_r2t_info *r2t;
  460. int r2tsn = be32_to_cpu(rhdr->r2tsn);
  461. int rc;
  462. if (tcp_conn->in.datalen) {
  463. iscsi_conn_printk(KERN_ERR, conn,
  464. "invalid R2t with datalen %d\n",
  465. tcp_conn->in.datalen);
  466. return ISCSI_ERR_DATALEN;
  467. }
  468. if (tcp_task->exp_datasn != r2tsn){
  469. ISCSI_DBG_TCP(conn, "task->exp_datasn(%d) != rhdr->r2tsn(%d)\n",
  470. tcp_task->exp_datasn, r2tsn);
  471. return ISCSI_ERR_R2TSN;
  472. }
  473. /* fill-in new R2T associated with the task */
  474. iscsi_update_cmdsn(session, (struct iscsi_nopin*)rhdr);
  475. if (!task->sc || session->state != ISCSI_STATE_LOGGED_IN) {
  476. iscsi_conn_printk(KERN_INFO, conn,
  477. "dropping R2T itt %d in recovery.\n",
  478. task->itt);
  479. return 0;
  480. }
  481. rc = kfifo_out(&tcp_task->r2tpool.queue, (void*)&r2t, sizeof(void*));
  482. if (!rc) {
  483. iscsi_conn_printk(KERN_ERR, conn, "Could not allocate R2T. "
  484. "Target has sent more R2Ts than it "
  485. "negotiated for or driver has has leaked.\n");
  486. return ISCSI_ERR_PROTO;
  487. }
  488. r2t->exp_statsn = rhdr->statsn;
  489. r2t->data_length = be32_to_cpu(rhdr->data_length);
  490. if (r2t->data_length == 0) {
  491. iscsi_conn_printk(KERN_ERR, conn,
  492. "invalid R2T with zero data len\n");
  493. kfifo_in(&tcp_task->r2tpool.queue, (void*)&r2t,
  494. sizeof(void*));
  495. return ISCSI_ERR_DATALEN;
  496. }
  497. if (r2t->data_length > session->max_burst)
  498. ISCSI_DBG_TCP(conn, "invalid R2T with data len %u and max "
  499. "burst %u. Attempting to execute request.\n",
  500. r2t->data_length, session->max_burst);
  501. r2t->data_offset = be32_to_cpu(rhdr->data_offset);
  502. if (r2t->data_offset + r2t->data_length > scsi_out(task->sc)->length) {
  503. iscsi_conn_printk(KERN_ERR, conn,
  504. "invalid R2T with data len %u at offset %u "
  505. "and total length %d\n", r2t->data_length,
  506. r2t->data_offset, scsi_out(task->sc)->length);
  507. kfifo_in(&tcp_task->r2tpool.queue, (void*)&r2t,
  508. sizeof(void*));
  509. return ISCSI_ERR_DATALEN;
  510. }
  511. r2t->ttt = rhdr->ttt; /* no flip */
  512. r2t->datasn = 0;
  513. r2t->sent = 0;
  514. tcp_task->exp_datasn = r2tsn + 1;
  515. kfifo_in(&tcp_task->r2tqueue, (void*)&r2t, sizeof(void*));
  516. conn->r2t_pdus_cnt++;
  517. iscsi_requeue_task(task);
  518. return 0;
  519. }
  520. /*
  521. * Handle incoming reply to DataIn command
  522. */
  523. static int
  524. iscsi_tcp_process_data_in(struct iscsi_tcp_conn *tcp_conn,
  525. struct iscsi_segment *segment)
  526. {
  527. struct iscsi_conn *conn = tcp_conn->iscsi_conn;
  528. struct iscsi_hdr *hdr = tcp_conn->in.hdr;
  529. int rc;
  530. if (!iscsi_tcp_dgst_verify(tcp_conn, segment))
  531. return ISCSI_ERR_DATA_DGST;
  532. /* check for non-exceptional status */
  533. if (hdr->flags & ISCSI_FLAG_DATA_STATUS) {
  534. rc = iscsi_complete_pdu(conn, tcp_conn->in.hdr, NULL, 0);
  535. if (rc)
  536. return rc;
  537. }
  538. iscsi_tcp_hdr_recv_prep(tcp_conn);
  539. return 0;
  540. }
  541. /**
  542. * iscsi_tcp_hdr_dissect - process PDU header
  543. * @conn: iSCSI connection
  544. * @hdr: PDU header
  545. *
  546. * This function analyzes the header of the PDU received,
  547. * and performs several sanity checks. If the PDU is accompanied
  548. * by data, the receive buffer is set up to copy the incoming data
  549. * to the correct location.
  550. */
  551. static int
  552. iscsi_tcp_hdr_dissect(struct iscsi_conn *conn, struct iscsi_hdr *hdr)
  553. {
  554. int rc = 0, opcode, ahslen;
  555. struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
  556. struct iscsi_task *task;
  557. /* verify PDU length */
  558. tcp_conn->in.datalen = ntoh24(hdr->dlength);
  559. if (tcp_conn->in.datalen > conn->max_recv_dlength) {
  560. iscsi_conn_printk(KERN_ERR, conn,
  561. "iscsi_tcp: datalen %d > %d\n",
  562. tcp_conn->in.datalen, conn->max_recv_dlength);
  563. return ISCSI_ERR_DATALEN;
  564. }
  565. /* Additional header segments. So far, we don't
  566. * process additional headers.
  567. */
  568. ahslen = hdr->hlength << 2;
  569. opcode = hdr->opcode & ISCSI_OPCODE_MASK;
  570. /* verify itt (itt encoding: age+cid+itt) */
  571. rc = iscsi_verify_itt(conn, hdr->itt);
  572. if (rc)
  573. return rc;
  574. ISCSI_DBG_TCP(conn, "opcode 0x%x ahslen %d datalen %d\n",
  575. opcode, ahslen, tcp_conn->in.datalen);
  576. switch(opcode) {
  577. case ISCSI_OP_SCSI_DATA_IN:
  578. spin_lock(&conn->session->lock);
  579. task = iscsi_itt_to_ctask(conn, hdr->itt);
  580. if (!task)
  581. rc = ISCSI_ERR_BAD_ITT;
  582. else
  583. rc = iscsi_tcp_data_in(conn, task);
  584. if (rc) {
  585. spin_unlock(&conn->session->lock);
  586. break;
  587. }
  588. if (tcp_conn->in.datalen) {
  589. struct iscsi_tcp_task *tcp_task = task->dd_data;
  590. struct hash_desc *rx_hash = NULL;
  591. struct scsi_data_buffer *sdb = scsi_in(task->sc);
  592. /*
  593. * Setup copy of Data-In into the Scsi_Cmnd
  594. * Scatterlist case:
  595. * We set up the iscsi_segment to point to the next
  596. * scatterlist entry to copy to. As we go along,
  597. * we move on to the next scatterlist entry and
  598. * update the digest per-entry.
  599. */
  600. if (conn->datadgst_en &&
  601. !(conn->session->tt->caps & CAP_DIGEST_OFFLOAD))
  602. rx_hash = tcp_conn->rx_hash;
  603. ISCSI_DBG_TCP(conn, "iscsi_tcp_begin_data_in( "
  604. "offset=%d, datalen=%d)\n",
  605. tcp_task->data_offset,
  606. tcp_conn->in.datalen);
  607. task->last_xfer = jiffies;
  608. rc = iscsi_segment_seek_sg(&tcp_conn->in.segment,
  609. sdb->table.sgl,
  610. sdb->table.nents,
  611. tcp_task->data_offset,
  612. tcp_conn->in.datalen,
  613. iscsi_tcp_process_data_in,
  614. rx_hash);
  615. spin_unlock(&conn->session->lock);
  616. return rc;
  617. }
  618. rc = __iscsi_complete_pdu(conn, hdr, NULL, 0);
  619. spin_unlock(&conn->session->lock);
  620. break;
  621. case ISCSI_OP_SCSI_CMD_RSP:
  622. if (tcp_conn->in.datalen) {
  623. iscsi_tcp_data_recv_prep(tcp_conn);
  624. return 0;
  625. }
  626. rc = iscsi_complete_pdu(conn, hdr, NULL, 0);
  627. break;
  628. case ISCSI_OP_R2T:
  629. spin_lock(&conn->session->lock);
  630. task = iscsi_itt_to_ctask(conn, hdr->itt);
  631. if (!task)
  632. rc = ISCSI_ERR_BAD_ITT;
  633. else if (ahslen)
  634. rc = ISCSI_ERR_AHSLEN;
  635. else if (task->sc->sc_data_direction == DMA_TO_DEVICE) {
  636. task->last_xfer = jiffies;
  637. rc = iscsi_tcp_r2t_rsp(conn, task);
  638. } else
  639. rc = ISCSI_ERR_PROTO;
  640. spin_unlock(&conn->session->lock);
  641. break;
  642. case ISCSI_OP_LOGIN_RSP:
  643. case ISCSI_OP_TEXT_RSP:
  644. case ISCSI_OP_REJECT:
  645. case ISCSI_OP_ASYNC_EVENT:
  646. /*
  647. * It is possible that we could get a PDU with a buffer larger
  648. * than 8K, but there are no targets that currently do this.
  649. * For now we fail until we find a vendor that needs it
  650. */
  651. if (ISCSI_DEF_MAX_RECV_SEG_LEN < tcp_conn->in.datalen) {
  652. iscsi_conn_printk(KERN_ERR, conn,
  653. "iscsi_tcp: received buffer of "
  654. "len %u but conn buffer is only %u "
  655. "(opcode %0x)\n",
  656. tcp_conn->in.datalen,
  657. ISCSI_DEF_MAX_RECV_SEG_LEN, opcode);
  658. rc = ISCSI_ERR_PROTO;
  659. break;
  660. }
  661. /* If there's data coming in with the response,
  662. * receive it to the connection's buffer.
  663. */
  664. if (tcp_conn->in.datalen) {
  665. iscsi_tcp_data_recv_prep(tcp_conn);
  666. return 0;
  667. }
  668. /* fall through */
  669. case ISCSI_OP_LOGOUT_RSP:
  670. case ISCSI_OP_NOOP_IN:
  671. case ISCSI_OP_SCSI_TMFUNC_RSP:
  672. rc = iscsi_complete_pdu(conn, hdr, NULL, 0);
  673. break;
  674. default:
  675. rc = ISCSI_ERR_BAD_OPCODE;
  676. break;
  677. }
  678. if (rc == 0) {
  679. /* Anything that comes with data should have
  680. * been handled above. */
  681. if (tcp_conn->in.datalen)
  682. return ISCSI_ERR_PROTO;
  683. iscsi_tcp_hdr_recv_prep(tcp_conn);
  684. }
  685. return rc;
  686. }
  687. /**
  688. * iscsi_tcp_hdr_recv_done - process PDU header
  689. *
  690. * This is the callback invoked when the PDU header has
  691. * been received. If the header is followed by additional
  692. * header segments, we go back for more data.
  693. */
  694. static int
  695. iscsi_tcp_hdr_recv_done(struct iscsi_tcp_conn *tcp_conn,
  696. struct iscsi_segment *segment)
  697. {
  698. struct iscsi_conn *conn = tcp_conn->iscsi_conn;
  699. struct iscsi_hdr *hdr;
  700. /* Check if there are additional header segments
  701. * *prior* to computing the digest, because we
  702. * may need to go back to the caller for more.
  703. */
  704. hdr = (struct iscsi_hdr *) tcp_conn->in.hdr_buf;
  705. if (segment->copied == sizeof(struct iscsi_hdr) && hdr->hlength) {
  706. /* Bump the header length - the caller will
  707. * just loop around and get the AHS for us, and
  708. * call again. */
  709. unsigned int ahslen = hdr->hlength << 2;
  710. /* Make sure we don't overflow */
  711. if (sizeof(*hdr) + ahslen > sizeof(tcp_conn->in.hdr_buf))
  712. return ISCSI_ERR_AHSLEN;
  713. segment->total_size += ahslen;
  714. segment->size += ahslen;
  715. return 0;
  716. }
  717. /* We're done processing the header. See if we're doing
  718. * header digests; if so, set up the recv_digest buffer
  719. * and go back for more. */
  720. if (conn->hdrdgst_en &&
  721. !(conn->session->tt->caps & CAP_DIGEST_OFFLOAD)) {
  722. if (segment->digest_len == 0) {
  723. /*
  724. * Even if we offload the digest processing we
  725. * splice it in so we can increment the skb/segment
  726. * counters in preparation for the data segment.
  727. */
  728. iscsi_tcp_segment_splice_digest(segment,
  729. segment->recv_digest);
  730. return 0;
  731. }
  732. iscsi_tcp_dgst_header(tcp_conn->rx_hash, hdr,
  733. segment->total_copied - ISCSI_DIGEST_SIZE,
  734. segment->digest);
  735. if (!iscsi_tcp_dgst_verify(tcp_conn, segment))
  736. return ISCSI_ERR_HDR_DGST;
  737. }
  738. tcp_conn->in.hdr = hdr;
  739. return iscsi_tcp_hdr_dissect(conn, hdr);
  740. }
  741. /**
  742. * iscsi_tcp_recv_segment_is_hdr - tests if we are reading in a header
  743. * @tcp_conn: iscsi tcp conn
  744. *
  745. * returns non zero if we are currently processing or setup to process
  746. * a header.
  747. */
  748. inline int iscsi_tcp_recv_segment_is_hdr(struct iscsi_tcp_conn *tcp_conn)
  749. {
  750. return tcp_conn->in.segment.done == iscsi_tcp_hdr_recv_done;
  751. }
  752. EXPORT_SYMBOL_GPL(iscsi_tcp_recv_segment_is_hdr);
  753. /**
  754. * iscsi_tcp_recv_skb - Process skb
  755. * @conn: iscsi connection
  756. * @skb: network buffer with header and/or data segment
  757. * @offset: offset in skb
  758. * @offload: bool indicating if transfer was offloaded
  759. *
  760. * Will return status of transfer in status. And will return
  761. * number of bytes copied.
  762. */
  763. int iscsi_tcp_recv_skb(struct iscsi_conn *conn, struct sk_buff *skb,
  764. unsigned int offset, bool offloaded, int *status)
  765. {
  766. struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
  767. struct iscsi_segment *segment = &tcp_conn->in.segment;
  768. struct skb_seq_state seq;
  769. unsigned int consumed = 0;
  770. int rc = 0;
  771. ISCSI_DBG_TCP(conn, "in %d bytes\n", skb->len - offset);
  772. /*
  773. * Update for each skb instead of pdu, because over slow networks a
  774. * data_in's data could take a while to read in. We also want to
  775. * account for r2ts.
  776. */
  777. conn->last_recv = jiffies;
  778. if (unlikely(conn->suspend_rx)) {
  779. ISCSI_DBG_TCP(conn, "Rx suspended!\n");
  780. *status = ISCSI_TCP_SUSPENDED;
  781. return 0;
  782. }
  783. if (offloaded) {
  784. segment->total_copied = segment->total_size;
  785. goto segment_done;
  786. }
  787. skb_prepare_seq_read(skb, offset, skb->len, &seq);
  788. while (1) {
  789. unsigned int avail;
  790. const u8 *ptr;
  791. avail = skb_seq_read(consumed, &ptr, &seq);
  792. if (avail == 0) {
  793. ISCSI_DBG_TCP(conn, "no more data avail. Consumed %d\n",
  794. consumed);
  795. *status = ISCSI_TCP_SKB_DONE;
  796. skb_abort_seq_read(&seq);
  797. goto skb_done;
  798. }
  799. BUG_ON(segment->copied >= segment->size);
  800. ISCSI_DBG_TCP(conn, "skb %p ptr=%p avail=%u\n", skb, ptr,
  801. avail);
  802. rc = iscsi_tcp_segment_recv(tcp_conn, segment, ptr, avail);
  803. BUG_ON(rc == 0);
  804. consumed += rc;
  805. if (segment->total_copied >= segment->total_size) {
  806. skb_abort_seq_read(&seq);
  807. goto segment_done;
  808. }
  809. }
  810. segment_done:
  811. *status = ISCSI_TCP_SEGMENT_DONE;
  812. ISCSI_DBG_TCP(conn, "segment done\n");
  813. rc = segment->done(tcp_conn, segment);
  814. if (rc != 0) {
  815. *status = ISCSI_TCP_CONN_ERR;
  816. ISCSI_DBG_TCP(conn, "Error receiving PDU, errno=%d\n", rc);
  817. iscsi_conn_failure(conn, rc);
  818. return 0;
  819. }
  820. /* The done() functions sets up the next segment. */
  821. skb_done:
  822. conn->rxdata_octets += consumed;
  823. return consumed;
  824. }
  825. EXPORT_SYMBOL_GPL(iscsi_tcp_recv_skb);
  826. /**
  827. * iscsi_tcp_task_init - Initialize iSCSI SCSI_READ or SCSI_WRITE commands
  828. * @conn: iscsi connection
  829. * @task: scsi command task
  830. * @sc: scsi command
  831. */
  832. int iscsi_tcp_task_init(struct iscsi_task *task)
  833. {
  834. struct iscsi_tcp_task *tcp_task = task->dd_data;
  835. struct iscsi_conn *conn = task->conn;
  836. struct scsi_cmnd *sc = task->sc;
  837. int err;
  838. if (!sc) {
  839. /*
  840. * mgmt tasks do not have a scatterlist since they come
  841. * in from the iscsi interface.
  842. */
  843. ISCSI_DBG_TCP(conn, "mtask deq [itt 0x%x]\n", task->itt);
  844. return conn->session->tt->init_pdu(task, 0, task->data_count);
  845. }
  846. BUG_ON(kfifo_len(&tcp_task->r2tqueue));
  847. tcp_task->exp_datasn = 0;
  848. /* Prepare PDU, optionally w/ immediate data */
  849. ISCSI_DBG_TCP(conn, "task deq [itt 0x%x imm %d unsol %d]\n",
  850. task->itt, task->imm_count, task->unsol_r2t.data_length);
  851. err = conn->session->tt->init_pdu(task, 0, task->imm_count);
  852. if (err)
  853. return err;
  854. task->imm_count = 0;
  855. return 0;
  856. }
  857. EXPORT_SYMBOL_GPL(iscsi_tcp_task_init);
  858. static struct iscsi_r2t_info *iscsi_tcp_get_curr_r2t(struct iscsi_task *task)
  859. {
  860. struct iscsi_session *session = task->conn->session;
  861. struct iscsi_tcp_task *tcp_task = task->dd_data;
  862. struct iscsi_r2t_info *r2t = NULL;
  863. if (iscsi_task_has_unsol_data(task))
  864. r2t = &task->unsol_r2t;
  865. else {
  866. spin_lock_bh(&session->lock);
  867. if (tcp_task->r2t) {
  868. r2t = tcp_task->r2t;
  869. /* Continue with this R2T? */
  870. if (r2t->data_length <= r2t->sent) {
  871. ISCSI_DBG_TCP(task->conn,
  872. " done with r2t %p\n", r2t);
  873. kfifo_in(&tcp_task->r2tpool.queue,
  874. (void *)&tcp_task->r2t,
  875. sizeof(void *));
  876. tcp_task->r2t = r2t = NULL;
  877. }
  878. }
  879. if (r2t == NULL) {
  880. if (kfifo_out(&tcp_task->r2tqueue,
  881. (void *)&tcp_task->r2t, sizeof(void *)) !=
  882. sizeof(void *))
  883. r2t = NULL;
  884. else
  885. r2t = tcp_task->r2t;
  886. }
  887. spin_unlock_bh(&session->lock);
  888. }
  889. return r2t;
  890. }
  891. /**
  892. * iscsi_tcp_task_xmit - xmit normal PDU task
  893. * @task: iscsi command task
  894. *
  895. * We're expected to return 0 when everything was transmitted successfully,
  896. * -EAGAIN if there's still data in the queue, or != 0 for any other kind
  897. * of error.
  898. */
  899. int iscsi_tcp_task_xmit(struct iscsi_task *task)
  900. {
  901. struct iscsi_conn *conn = task->conn;
  902. struct iscsi_session *session = conn->session;
  903. struct iscsi_r2t_info *r2t;
  904. int rc = 0;
  905. flush:
  906. /* Flush any pending data first. */
  907. rc = session->tt->xmit_pdu(task);
  908. if (rc < 0)
  909. return rc;
  910. /* mgmt command */
  911. if (!task->sc) {
  912. if (task->hdr->itt == RESERVED_ITT)
  913. iscsi_put_task(task);
  914. return 0;
  915. }
  916. /* Are we done already? */
  917. if (task->sc->sc_data_direction != DMA_TO_DEVICE)
  918. return 0;
  919. r2t = iscsi_tcp_get_curr_r2t(task);
  920. if (r2t == NULL) {
  921. /* Waiting for more R2Ts to arrive. */
  922. ISCSI_DBG_TCP(conn, "no R2Ts yet\n");
  923. return 0;
  924. }
  925. rc = conn->session->tt->alloc_pdu(task, ISCSI_OP_SCSI_DATA_OUT);
  926. if (rc)
  927. return rc;
  928. iscsi_prep_data_out_pdu(task, r2t, (struct iscsi_data *) task->hdr);
  929. ISCSI_DBG_TCP(conn, "sol dout %p [dsn %d itt 0x%x doff %d dlen %d]\n",
  930. r2t, r2t->datasn - 1, task->hdr->itt,
  931. r2t->data_offset + r2t->sent, r2t->data_count);
  932. rc = conn->session->tt->init_pdu(task, r2t->data_offset + r2t->sent,
  933. r2t->data_count);
  934. if (rc) {
  935. iscsi_conn_failure(conn, ISCSI_ERR_XMIT_FAILED);
  936. return rc;
  937. }
  938. r2t->sent += r2t->data_count;
  939. goto flush;
  940. }
  941. EXPORT_SYMBOL_GPL(iscsi_tcp_task_xmit);
  942. struct iscsi_cls_conn *
  943. iscsi_tcp_conn_setup(struct iscsi_cls_session *cls_session, int dd_data_size,
  944. uint32_t conn_idx)
  945. {
  946. struct iscsi_conn *conn;
  947. struct iscsi_cls_conn *cls_conn;
  948. struct iscsi_tcp_conn *tcp_conn;
  949. cls_conn = iscsi_conn_setup(cls_session, sizeof(*tcp_conn), conn_idx);
  950. if (!cls_conn)
  951. return NULL;
  952. conn = cls_conn->dd_data;
  953. /*
  954. * due to strange issues with iser these are not set
  955. * in iscsi_conn_setup
  956. */
  957. conn->max_recv_dlength = ISCSI_DEF_MAX_RECV_SEG_LEN;
  958. tcp_conn = conn->dd_data;
  959. tcp_conn->iscsi_conn = conn;
  960. tcp_conn->dd_data = kzalloc(dd_data_size, GFP_KERNEL);
  961. if (!tcp_conn->dd_data) {
  962. iscsi_conn_teardown(cls_conn);
  963. return NULL;
  964. }
  965. return cls_conn;
  966. }
  967. EXPORT_SYMBOL_GPL(iscsi_tcp_conn_setup);
  968. void iscsi_tcp_conn_teardown(struct iscsi_cls_conn *cls_conn)
  969. {
  970. struct iscsi_conn *conn = cls_conn->dd_data;
  971. struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
  972. kfree(tcp_conn->dd_data);
  973. iscsi_conn_teardown(cls_conn);
  974. }
  975. EXPORT_SYMBOL_GPL(iscsi_tcp_conn_teardown);
  976. int iscsi_tcp_r2tpool_alloc(struct iscsi_session *session)
  977. {
  978. int i;
  979. int cmd_i;
  980. /*
  981. * initialize per-task: R2T pool and xmit queue
  982. */
  983. for (cmd_i = 0; cmd_i < session->cmds_max; cmd_i++) {
  984. struct iscsi_task *task = session->cmds[cmd_i];
  985. struct iscsi_tcp_task *tcp_task = task->dd_data;
  986. /*
  987. * pre-allocated x2 as much r2ts to handle race when
  988. * target acks DataOut faster than we data_xmit() queues
  989. * could replenish r2tqueue.
  990. */
  991. /* R2T pool */
  992. if (iscsi_pool_init(&tcp_task->r2tpool,
  993. session->max_r2t * 2, NULL,
  994. sizeof(struct iscsi_r2t_info))) {
  995. goto r2t_alloc_fail;
  996. }
  997. /* R2T xmit queue */
  998. if (kfifo_alloc(&tcp_task->r2tqueue,
  999. session->max_r2t * 4 * sizeof(void*), GFP_KERNEL)) {
  1000. iscsi_pool_free(&tcp_task->r2tpool);
  1001. goto r2t_alloc_fail;
  1002. }
  1003. }
  1004. return 0;
  1005. r2t_alloc_fail:
  1006. for (i = 0; i < cmd_i; i++) {
  1007. struct iscsi_task *task = session->cmds[i];
  1008. struct iscsi_tcp_task *tcp_task = task->dd_data;
  1009. kfifo_free(&tcp_task->r2tqueue);
  1010. iscsi_pool_free(&tcp_task->r2tpool);
  1011. }
  1012. return -ENOMEM;
  1013. }
  1014. EXPORT_SYMBOL_GPL(iscsi_tcp_r2tpool_alloc);
  1015. void iscsi_tcp_r2tpool_free(struct iscsi_session *session)
  1016. {
  1017. int i;
  1018. for (i = 0; i < session->cmds_max; i++) {
  1019. struct iscsi_task *task = session->cmds[i];
  1020. struct iscsi_tcp_task *tcp_task = task->dd_data;
  1021. kfifo_free(&tcp_task->r2tqueue);
  1022. iscsi_pool_free(&tcp_task->r2tpool);
  1023. }
  1024. }
  1025. EXPORT_SYMBOL_GPL(iscsi_tcp_r2tpool_free);
  1026. void iscsi_tcp_conn_get_stats(struct iscsi_cls_conn *cls_conn,
  1027. struct iscsi_stats *stats)
  1028. {
  1029. struct iscsi_conn *conn = cls_conn->dd_data;
  1030. stats->txdata_octets = conn->txdata_octets;
  1031. stats->rxdata_octets = conn->rxdata_octets;
  1032. stats->scsicmd_pdus = conn->scsicmd_pdus_cnt;
  1033. stats->dataout_pdus = conn->dataout_pdus_cnt;
  1034. stats->scsirsp_pdus = conn->scsirsp_pdus_cnt;
  1035. stats->datain_pdus = conn->datain_pdus_cnt;
  1036. stats->r2t_pdus = conn->r2t_pdus_cnt;
  1037. stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt;
  1038. stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt;
  1039. }
  1040. EXPORT_SYMBOL_GPL(iscsi_tcp_conn_get_stats);