libiscsi_tcp.c 32 KB

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