libiscsi.c 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712
  1. /*
  2. * iSCSI lib functions
  3. *
  4. * Copyright (C) 2006 Red Hat, Inc. All rights reserved.
  5. * Copyright (C) 2004 - 2006 Mike Christie
  6. * Copyright (C) 2004 - 2005 Dmitry Yusupov
  7. * Copyright (C) 2004 - 2005 Alex Aizman
  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 by
  12. * 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,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  23. */
  24. #include <linux/types.h>
  25. #include <linux/mutex.h>
  26. #include <linux/kfifo.h>
  27. #include <linux/delay.h>
  28. #include <net/tcp.h>
  29. #include <scsi/scsi_cmnd.h>
  30. #include <scsi/scsi_device.h>
  31. #include <scsi/scsi_eh.h>
  32. #include <scsi/scsi_tcq.h>
  33. #include <scsi/scsi_host.h>
  34. #include <scsi/scsi.h>
  35. #include <scsi/iscsi_proto.h>
  36. #include <scsi/scsi_transport.h>
  37. #include <scsi/scsi_transport_iscsi.h>
  38. #include <scsi/libiscsi.h>
  39. struct iscsi_session *
  40. class_to_transport_session(struct iscsi_cls_session *cls_session)
  41. {
  42. struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
  43. return iscsi_hostdata(shost->hostdata);
  44. }
  45. EXPORT_SYMBOL_GPL(class_to_transport_session);
  46. #define INVALID_SN_DELTA 0xffff
  47. int
  48. iscsi_check_assign_cmdsn(struct iscsi_session *session, struct iscsi_nopin *hdr)
  49. {
  50. uint32_t max_cmdsn = be32_to_cpu(hdr->max_cmdsn);
  51. uint32_t exp_cmdsn = be32_to_cpu(hdr->exp_cmdsn);
  52. if (max_cmdsn < exp_cmdsn -1 &&
  53. max_cmdsn > exp_cmdsn - INVALID_SN_DELTA)
  54. return ISCSI_ERR_MAX_CMDSN;
  55. if (max_cmdsn > session->max_cmdsn ||
  56. max_cmdsn < session->max_cmdsn - INVALID_SN_DELTA)
  57. session->max_cmdsn = max_cmdsn;
  58. if (exp_cmdsn > session->exp_cmdsn ||
  59. exp_cmdsn < session->exp_cmdsn - INVALID_SN_DELTA)
  60. session->exp_cmdsn = exp_cmdsn;
  61. return 0;
  62. }
  63. EXPORT_SYMBOL_GPL(iscsi_check_assign_cmdsn);
  64. void iscsi_prep_unsolicit_data_pdu(struct iscsi_cmd_task *ctask,
  65. struct iscsi_data *hdr,
  66. int transport_data_cnt)
  67. {
  68. struct iscsi_conn *conn = ctask->conn;
  69. memset(hdr, 0, sizeof(struct iscsi_data));
  70. hdr->ttt = cpu_to_be32(ISCSI_RESERVED_TAG);
  71. hdr->datasn = cpu_to_be32(ctask->unsol_datasn);
  72. ctask->unsol_datasn++;
  73. hdr->opcode = ISCSI_OP_SCSI_DATA_OUT;
  74. memcpy(hdr->lun, ctask->hdr->lun, sizeof(hdr->lun));
  75. hdr->itt = ctask->hdr->itt;
  76. hdr->exp_statsn = cpu_to_be32(conn->exp_statsn);
  77. hdr->offset = cpu_to_be32(ctask->total_length -
  78. transport_data_cnt -
  79. ctask->unsol_count);
  80. if (ctask->unsol_count > conn->max_xmit_dlength) {
  81. hton24(hdr->dlength, conn->max_xmit_dlength);
  82. ctask->data_count = conn->max_xmit_dlength;
  83. hdr->flags = 0;
  84. } else {
  85. hton24(hdr->dlength, ctask->unsol_count);
  86. ctask->data_count = ctask->unsol_count;
  87. hdr->flags = ISCSI_FLAG_CMD_FINAL;
  88. }
  89. }
  90. EXPORT_SYMBOL_GPL(iscsi_prep_unsolicit_data_pdu);
  91. /**
  92. * iscsi_prep_scsi_cmd_pdu - prep iscsi scsi cmd pdu
  93. * @ctask: iscsi cmd task
  94. *
  95. * Prep basic iSCSI PDU fields for a scsi cmd pdu. The LLD should set
  96. * fields like dlength or final based on how much data it sends
  97. */
  98. static void iscsi_prep_scsi_cmd_pdu(struct iscsi_cmd_task *ctask)
  99. {
  100. struct iscsi_conn *conn = ctask->conn;
  101. struct iscsi_session *session = conn->session;
  102. struct iscsi_cmd *hdr = ctask->hdr;
  103. struct scsi_cmnd *sc = ctask->sc;
  104. hdr->opcode = ISCSI_OP_SCSI_CMD;
  105. hdr->flags = ISCSI_ATTR_SIMPLE;
  106. int_to_scsilun(sc->device->lun, (struct scsi_lun *)hdr->lun);
  107. hdr->itt = ctask->itt | (conn->id << ISCSI_CID_SHIFT) |
  108. (session->age << ISCSI_AGE_SHIFT);
  109. hdr->data_length = cpu_to_be32(sc->request_bufflen);
  110. hdr->cmdsn = cpu_to_be32(session->cmdsn);
  111. session->cmdsn++;
  112. hdr->exp_statsn = cpu_to_be32(conn->exp_statsn);
  113. memcpy(hdr->cdb, sc->cmnd, sc->cmd_len);
  114. memset(&hdr->cdb[sc->cmd_len], 0, MAX_COMMAND_SIZE - sc->cmd_len);
  115. if (sc->sc_data_direction == DMA_TO_DEVICE) {
  116. hdr->flags |= ISCSI_FLAG_CMD_WRITE;
  117. /*
  118. * Write counters:
  119. *
  120. * imm_count bytes to be sent right after
  121. * SCSI PDU Header
  122. *
  123. * unsol_count bytes(as Data-Out) to be sent
  124. * without R2T ack right after
  125. * immediate data
  126. *
  127. * r2t_data_count bytes to be sent via R2T ack's
  128. *
  129. * pad_count bytes to be sent as zero-padding
  130. */
  131. ctask->imm_count = 0;
  132. ctask->unsol_count = 0;
  133. ctask->unsol_datasn = 0;
  134. if (session->imm_data_en) {
  135. if (ctask->total_length >= session->first_burst)
  136. ctask->imm_count = min(session->first_burst,
  137. conn->max_xmit_dlength);
  138. else
  139. ctask->imm_count = min(ctask->total_length,
  140. conn->max_xmit_dlength);
  141. hton24(ctask->hdr->dlength, ctask->imm_count);
  142. } else
  143. zero_data(ctask->hdr->dlength);
  144. if (!session->initial_r2t_en)
  145. ctask->unsol_count = min(session->first_burst,
  146. ctask->total_length) - ctask->imm_count;
  147. if (!ctask->unsol_count)
  148. /* No unsolicit Data-Out's */
  149. ctask->hdr->flags |= ISCSI_FLAG_CMD_FINAL;
  150. } else {
  151. ctask->datasn = 0;
  152. hdr->flags |= ISCSI_FLAG_CMD_FINAL;
  153. zero_data(hdr->dlength);
  154. if (sc->sc_data_direction == DMA_FROM_DEVICE)
  155. hdr->flags |= ISCSI_FLAG_CMD_READ;
  156. }
  157. conn->scsicmd_pdus_cnt++;
  158. }
  159. EXPORT_SYMBOL_GPL(iscsi_prep_scsi_cmd_pdu);
  160. /**
  161. * iscsi_complete_command - return command back to scsi-ml
  162. * @session: iscsi session
  163. * @ctask: iscsi cmd task
  164. *
  165. * Must be called with session lock.
  166. * This function returns the scsi command to scsi-ml and returns
  167. * the cmd task to the pool of available cmd tasks.
  168. */
  169. static void iscsi_complete_command(struct iscsi_session *session,
  170. struct iscsi_cmd_task *ctask)
  171. {
  172. struct scsi_cmnd *sc = ctask->sc;
  173. ctask->sc = NULL;
  174. list_del_init(&ctask->running);
  175. __kfifo_put(session->cmdpool.queue, (void*)&ctask, sizeof(void*));
  176. sc->scsi_done(sc);
  177. }
  178. /**
  179. * iscsi_cmd_rsp - SCSI Command Response processing
  180. * @conn: iscsi connection
  181. * @hdr: iscsi header
  182. * @ctask: scsi command task
  183. * @data: cmd data buffer
  184. * @datalen: len of buffer
  185. *
  186. * iscsi_cmd_rsp sets up the scsi_cmnd fields based on the PDU and
  187. * then completes the command and task.
  188. **/
  189. static int iscsi_scsi_cmd_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
  190. struct iscsi_cmd_task *ctask, char *data,
  191. int datalen)
  192. {
  193. int rc;
  194. struct iscsi_cmd_rsp *rhdr = (struct iscsi_cmd_rsp *)hdr;
  195. struct iscsi_session *session = conn->session;
  196. struct scsi_cmnd *sc = ctask->sc;
  197. rc = iscsi_check_assign_cmdsn(session, (struct iscsi_nopin*)rhdr);
  198. if (rc) {
  199. sc->result = DID_ERROR << 16;
  200. goto out;
  201. }
  202. conn->exp_statsn = be32_to_cpu(rhdr->statsn) + 1;
  203. sc->result = (DID_OK << 16) | rhdr->cmd_status;
  204. if (rhdr->response != ISCSI_STATUS_CMD_COMPLETED) {
  205. sc->result = DID_ERROR << 16;
  206. goto out;
  207. }
  208. if (rhdr->cmd_status == SAM_STAT_CHECK_CONDITION) {
  209. int senselen;
  210. if (datalen < 2) {
  211. invalid_datalen:
  212. printk(KERN_ERR "Got CHECK_CONDITION but invalid "
  213. "data buffer size of %d\n", datalen);
  214. sc->result = DID_BAD_TARGET << 16;
  215. goto out;
  216. }
  217. senselen = (data[0] << 8) | data[1];
  218. if (datalen < senselen)
  219. goto invalid_datalen;
  220. memcpy(sc->sense_buffer, data + 2,
  221. min(senselen, SCSI_SENSE_BUFFERSIZE));
  222. debug_scsi("copied %d bytes of sense\n",
  223. min(senselen, SCSI_SENSE_BUFFERSIZE));
  224. }
  225. if (sc->sc_data_direction == DMA_TO_DEVICE)
  226. goto out;
  227. if (rhdr->flags & ISCSI_FLAG_CMD_UNDERFLOW) {
  228. int res_count = be32_to_cpu(rhdr->residual_count);
  229. if (res_count > 0 && res_count <= sc->request_bufflen)
  230. sc->resid = res_count;
  231. else
  232. sc->result = (DID_BAD_TARGET << 16) | rhdr->cmd_status;
  233. } else if (rhdr->flags & ISCSI_FLAG_CMD_BIDI_UNDERFLOW)
  234. sc->result = (DID_BAD_TARGET << 16) | rhdr->cmd_status;
  235. else if (rhdr->flags & ISCSI_FLAG_CMD_OVERFLOW)
  236. sc->resid = be32_to_cpu(rhdr->residual_count);
  237. out:
  238. debug_scsi("done [sc %lx res %d itt 0x%x]\n",
  239. (long)sc, sc->result, ctask->itt);
  240. conn->scsirsp_pdus_cnt++;
  241. iscsi_complete_command(conn->session, ctask);
  242. return rc;
  243. }
  244. /**
  245. * __iscsi_complete_pdu - complete pdu
  246. * @conn: iscsi conn
  247. * @hdr: iscsi header
  248. * @data: data buffer
  249. * @datalen: len of data buffer
  250. *
  251. * Completes pdu processing by freeing any resources allocated at
  252. * queuecommand or send generic. session lock must be held and verify
  253. * itt must have been called.
  254. */
  255. int __iscsi_complete_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
  256. char *data, int datalen)
  257. {
  258. struct iscsi_session *session = conn->session;
  259. int opcode = hdr->opcode & ISCSI_OPCODE_MASK, rc = 0;
  260. struct iscsi_cmd_task *ctask;
  261. struct iscsi_mgmt_task *mtask;
  262. uint32_t itt;
  263. if (hdr->itt != cpu_to_be32(ISCSI_RESERVED_TAG))
  264. itt = hdr->itt & ISCSI_ITT_MASK;
  265. else
  266. itt = hdr->itt;
  267. if (itt < session->cmds_max) {
  268. ctask = session->cmds[itt];
  269. debug_scsi("cmdrsp [op 0x%x cid %d itt 0x%x len %d]\n",
  270. opcode, conn->id, ctask->itt, datalen);
  271. switch(opcode) {
  272. case ISCSI_OP_SCSI_CMD_RSP:
  273. BUG_ON((void*)ctask != ctask->sc->SCp.ptr);
  274. rc = iscsi_scsi_cmd_rsp(conn, hdr, ctask, data,
  275. datalen);
  276. break;
  277. case ISCSI_OP_SCSI_DATA_IN:
  278. BUG_ON((void*)ctask != ctask->sc->SCp.ptr);
  279. if (hdr->flags & ISCSI_FLAG_DATA_STATUS) {
  280. conn->scsirsp_pdus_cnt++;
  281. iscsi_complete_command(session, ctask);
  282. }
  283. break;
  284. case ISCSI_OP_R2T:
  285. /* LLD handles this for now */
  286. break;
  287. default:
  288. rc = ISCSI_ERR_BAD_OPCODE;
  289. break;
  290. }
  291. } else if (itt >= ISCSI_MGMT_ITT_OFFSET &&
  292. itt < ISCSI_MGMT_ITT_OFFSET + session->mgmtpool_max) {
  293. mtask = session->mgmt_cmds[itt - ISCSI_MGMT_ITT_OFFSET];
  294. debug_scsi("immrsp [op 0x%x cid %d itt 0x%x len %d]\n",
  295. opcode, conn->id, mtask->itt, datalen);
  296. switch(opcode) {
  297. case ISCSI_OP_LOGIN_RSP:
  298. case ISCSI_OP_TEXT_RSP:
  299. case ISCSI_OP_LOGOUT_RSP:
  300. rc = iscsi_check_assign_cmdsn(session,
  301. (struct iscsi_nopin*)hdr);
  302. if (rc)
  303. break;
  304. rc = iscsi_recv_pdu(conn->cls_conn, hdr, data, datalen);
  305. list_del(&mtask->running);
  306. if (conn->login_mtask != mtask)
  307. __kfifo_put(session->mgmtpool.queue,
  308. (void*)&mtask, sizeof(void*));
  309. break;
  310. case ISCSI_OP_SCSI_TMFUNC_RSP:
  311. rc = iscsi_check_assign_cmdsn(session,
  312. (struct iscsi_nopin*)hdr);
  313. if (rc)
  314. break;
  315. if (datalen) {
  316. rc = ISCSI_ERR_PROTO;
  317. break;
  318. }
  319. conn->tmfrsp_pdus_cnt++;
  320. if (conn->tmabort_state == TMABORT_INITIAL) {
  321. conn->tmabort_state =
  322. ((struct iscsi_tm_rsp *)hdr)->
  323. response == ISCSI_TMF_RSP_COMPLETE ?
  324. TMABORT_SUCCESS:TMABORT_FAILED;
  325. /* unblock eh_abort() */
  326. wake_up(&conn->ehwait);
  327. }
  328. break;
  329. case ISCSI_OP_NOOP_IN:
  330. if (hdr->ttt != ISCSI_RESERVED_TAG) {
  331. rc = ISCSI_ERR_PROTO;
  332. break;
  333. }
  334. rc = iscsi_check_assign_cmdsn(session,
  335. (struct iscsi_nopin*)hdr);
  336. if (rc)
  337. break;
  338. conn->exp_statsn = be32_to_cpu(hdr->statsn) + 1;
  339. rc = iscsi_recv_pdu(conn->cls_conn, hdr, data, datalen);
  340. list_del(&mtask->running);
  341. if (conn->login_mtask != mtask)
  342. __kfifo_put(session->mgmtpool.queue,
  343. (void*)&mtask, sizeof(void*));
  344. break;
  345. default:
  346. rc = ISCSI_ERR_BAD_OPCODE;
  347. break;
  348. }
  349. } else if (itt == ISCSI_RESERVED_TAG) {
  350. switch(opcode) {
  351. case ISCSI_OP_NOOP_IN:
  352. if (!datalen) {
  353. rc = iscsi_check_assign_cmdsn(session,
  354. (struct iscsi_nopin*)hdr);
  355. if (!rc && hdr->ttt != ISCSI_RESERVED_TAG)
  356. rc = iscsi_recv_pdu(conn->cls_conn,
  357. hdr, NULL, 0);
  358. } else
  359. rc = ISCSI_ERR_PROTO;
  360. break;
  361. case ISCSI_OP_REJECT:
  362. /* we need sth like iscsi_reject_rsp()*/
  363. case ISCSI_OP_ASYNC_EVENT:
  364. /* we need sth like iscsi_async_event_rsp() */
  365. rc = ISCSI_ERR_BAD_OPCODE;
  366. break;
  367. default:
  368. rc = ISCSI_ERR_BAD_OPCODE;
  369. break;
  370. }
  371. } else
  372. rc = ISCSI_ERR_BAD_ITT;
  373. return rc;
  374. }
  375. EXPORT_SYMBOL_GPL(__iscsi_complete_pdu);
  376. int iscsi_complete_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
  377. char *data, int datalen)
  378. {
  379. int rc;
  380. spin_lock(&conn->session->lock);
  381. rc = __iscsi_complete_pdu(conn, hdr, data, datalen);
  382. spin_unlock(&conn->session->lock);
  383. return rc;
  384. }
  385. EXPORT_SYMBOL_GPL(iscsi_complete_pdu);
  386. /* verify itt (itt encoding: age+cid+itt) */
  387. int iscsi_verify_itt(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
  388. uint32_t *ret_itt)
  389. {
  390. struct iscsi_session *session = conn->session;
  391. struct iscsi_cmd_task *ctask;
  392. uint32_t itt;
  393. if (hdr->itt != cpu_to_be32(ISCSI_RESERVED_TAG)) {
  394. if ((hdr->itt & ISCSI_AGE_MASK) !=
  395. (session->age << ISCSI_AGE_SHIFT)) {
  396. printk(KERN_ERR "iscsi_tcp: received itt %x expected "
  397. "session age (%x)\n", hdr->itt,
  398. session->age & ISCSI_AGE_MASK);
  399. return ISCSI_ERR_BAD_ITT;
  400. }
  401. if ((hdr->itt & ISCSI_CID_MASK) !=
  402. (conn->id << ISCSI_CID_SHIFT)) {
  403. printk(KERN_ERR "iscsi_tcp: received itt %x, expected "
  404. "CID (%x)\n", hdr->itt, conn->id);
  405. return ISCSI_ERR_BAD_ITT;
  406. }
  407. itt = hdr->itt & ISCSI_ITT_MASK;
  408. } else
  409. itt = hdr->itt;
  410. if (itt < session->cmds_max) {
  411. ctask = session->cmds[itt];
  412. if (!ctask->sc) {
  413. printk(KERN_INFO "iscsi_tcp: dropping ctask with "
  414. "itt 0x%x\n", ctask->itt);
  415. /* force drop */
  416. return ISCSI_ERR_NO_SCSI_CMD;
  417. }
  418. if (ctask->sc->SCp.phase != session->age) {
  419. printk(KERN_ERR "iscsi_tcp: ctask's session age %d, "
  420. "expected %d\n", ctask->sc->SCp.phase,
  421. session->age);
  422. return ISCSI_ERR_SESSION_FAILED;
  423. }
  424. }
  425. *ret_itt = itt;
  426. return 0;
  427. }
  428. EXPORT_SYMBOL_GPL(iscsi_verify_itt);
  429. void iscsi_conn_failure(struct iscsi_conn *conn, enum iscsi_err err)
  430. {
  431. struct iscsi_session *session = conn->session;
  432. unsigned long flags;
  433. spin_lock_irqsave(&session->lock, flags);
  434. if (session->conn_cnt == 1 || session->leadconn == conn)
  435. session->state = ISCSI_STATE_FAILED;
  436. spin_unlock_irqrestore(&session->lock, flags);
  437. set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx);
  438. set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_rx);
  439. iscsi_conn_error(conn->cls_conn, err);
  440. }
  441. EXPORT_SYMBOL_GPL(iscsi_conn_failure);
  442. /**
  443. * iscsi_data_xmit - xmit any command into the scheduled connection
  444. * @conn: iscsi connection
  445. *
  446. * Notes:
  447. * The function can return -EAGAIN in which case the caller must
  448. * re-schedule it again later or recover. '0' return code means
  449. * successful xmit.
  450. **/
  451. static int iscsi_data_xmit(struct iscsi_conn *conn)
  452. {
  453. struct iscsi_transport *tt;
  454. if (unlikely(conn->suspend_tx)) {
  455. debug_scsi("conn %d Tx suspended!\n", conn->id);
  456. return 0;
  457. }
  458. tt = conn->session->tt;
  459. /*
  460. * Transmit in the following order:
  461. *
  462. * 1) un-finished xmit (ctask or mtask)
  463. * 2) immediate control PDUs
  464. * 3) write data
  465. * 4) SCSI commands
  466. * 5) non-immediate control PDUs
  467. *
  468. * No need to lock around __kfifo_get as long as
  469. * there's one producer and one consumer.
  470. */
  471. BUG_ON(conn->ctask && conn->mtask);
  472. if (conn->ctask) {
  473. if (tt->xmit_cmd_task(conn, conn->ctask))
  474. goto again;
  475. /* done with this in-progress ctask */
  476. conn->ctask = NULL;
  477. }
  478. if (conn->mtask) {
  479. if (tt->xmit_mgmt_task(conn, conn->mtask))
  480. goto again;
  481. /* done with this in-progress mtask */
  482. conn->mtask = NULL;
  483. }
  484. /* process immediate first */
  485. if (unlikely(__kfifo_len(conn->immqueue))) {
  486. while (__kfifo_get(conn->immqueue, (void*)&conn->mtask,
  487. sizeof(void*))) {
  488. list_add_tail(&conn->mtask->running,
  489. &conn->mgmt_run_list);
  490. if (tt->xmit_mgmt_task(conn, conn->mtask))
  491. goto again;
  492. }
  493. /* done with this mtask */
  494. conn->mtask = NULL;
  495. }
  496. /* process command queue */
  497. while (__kfifo_get(conn->xmitqueue, (void*)&conn->ctask,
  498. sizeof(void*))) {
  499. /*
  500. * iscsi tcp may readd the task to the xmitqueue to send
  501. * write data
  502. */
  503. if (list_empty(&conn->ctask->running))
  504. list_add_tail(&conn->ctask->running, &conn->run_list);
  505. if (tt->xmit_cmd_task(conn, conn->ctask))
  506. goto again;
  507. }
  508. /* done with this ctask */
  509. conn->ctask = NULL;
  510. /* process the rest control plane PDUs, if any */
  511. if (unlikely(__kfifo_len(conn->mgmtqueue))) {
  512. while (__kfifo_get(conn->mgmtqueue, (void*)&conn->mtask,
  513. sizeof(void*))) {
  514. list_add_tail(&conn->mtask->running,
  515. &conn->mgmt_run_list);
  516. if (tt->xmit_mgmt_task(conn, conn->mtask))
  517. goto again;
  518. }
  519. /* done with this mtask */
  520. conn->mtask = NULL;
  521. }
  522. return 0;
  523. again:
  524. if (unlikely(conn->suspend_tx))
  525. return 0;
  526. return -EAGAIN;
  527. }
  528. static void iscsi_xmitworker(void *data)
  529. {
  530. struct iscsi_conn *conn = data;
  531. /*
  532. * serialize Xmit worker on a per-connection basis.
  533. */
  534. mutex_lock(&conn->xmitmutex);
  535. if (iscsi_data_xmit(conn))
  536. scsi_queue_work(conn->session->host, &conn->xmitwork);
  537. mutex_unlock(&conn->xmitmutex);
  538. }
  539. enum {
  540. FAILURE_BAD_HOST = 1,
  541. FAILURE_SESSION_FAILED,
  542. FAILURE_SESSION_FREED,
  543. FAILURE_WINDOW_CLOSED,
  544. FAILURE_SESSION_TERMINATE,
  545. FAILURE_SESSION_RECOVERY_TIMEOUT,
  546. };
  547. int iscsi_queuecommand(struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *))
  548. {
  549. struct Scsi_Host *host;
  550. int reason = 0;
  551. struct iscsi_session *session;
  552. struct iscsi_conn *conn;
  553. struct iscsi_cmd_task *ctask = NULL;
  554. sc->scsi_done = done;
  555. sc->result = 0;
  556. host = sc->device->host;
  557. session = iscsi_hostdata(host->hostdata);
  558. spin_lock(&session->lock);
  559. if (session->state != ISCSI_STATE_LOGGED_IN) {
  560. if (session->recovery_failed) {
  561. reason = FAILURE_SESSION_RECOVERY_TIMEOUT;
  562. goto fault;
  563. } else if (session->state == ISCSI_STATE_FAILED) {
  564. reason = FAILURE_SESSION_FAILED;
  565. goto reject;
  566. } else if (session->state == ISCSI_STATE_TERMINATE) {
  567. reason = FAILURE_SESSION_TERMINATE;
  568. goto fault;
  569. }
  570. reason = FAILURE_SESSION_FREED;
  571. goto fault;
  572. }
  573. /*
  574. * Check for iSCSI window and take care of CmdSN wrap-around
  575. */
  576. if ((int)(session->max_cmdsn - session->cmdsn) < 0) {
  577. reason = FAILURE_WINDOW_CLOSED;
  578. goto reject;
  579. }
  580. conn = session->leadconn;
  581. __kfifo_get(session->cmdpool.queue, (void*)&ctask, sizeof(void*));
  582. sc->SCp.phase = session->age;
  583. sc->SCp.ptr = (char *)ctask;
  584. ctask->mtask = NULL;
  585. ctask->conn = conn;
  586. ctask->sc = sc;
  587. INIT_LIST_HEAD(&ctask->running);
  588. ctask->total_length = sc->request_bufflen;
  589. iscsi_prep_scsi_cmd_pdu(ctask);
  590. session->tt->init_cmd_task(ctask);
  591. __kfifo_put(conn->xmitqueue, (void*)&ctask, sizeof(void*));
  592. debug_scsi(
  593. "ctask enq [%s cid %d sc %lx itt 0x%x len %d cmdsn %d win %d]\n",
  594. sc->sc_data_direction == DMA_TO_DEVICE ? "write" : "read",
  595. conn->id, (long)sc, ctask->itt, sc->request_bufflen,
  596. session->cmdsn, session->max_cmdsn - session->exp_cmdsn + 1);
  597. spin_unlock(&session->lock);
  598. scsi_queue_work(host, &conn->xmitwork);
  599. return 0;
  600. reject:
  601. spin_unlock(&session->lock);
  602. debug_scsi("cmd 0x%x rejected (%d)\n", sc->cmnd[0], reason);
  603. return SCSI_MLQUEUE_HOST_BUSY;
  604. fault:
  605. spin_unlock(&session->lock);
  606. printk(KERN_ERR "iscsi_tcp: cmd 0x%x is not queued (%d)\n",
  607. sc->cmnd[0], reason);
  608. sc->result = (DID_NO_CONNECT << 16);
  609. sc->resid = sc->request_bufflen;
  610. sc->scsi_done(sc);
  611. return 0;
  612. }
  613. EXPORT_SYMBOL_GPL(iscsi_queuecommand);
  614. int iscsi_change_queue_depth(struct scsi_device *sdev, int depth)
  615. {
  616. if (depth > ISCSI_MAX_CMD_PER_LUN)
  617. depth = ISCSI_MAX_CMD_PER_LUN;
  618. scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth);
  619. return sdev->queue_depth;
  620. }
  621. EXPORT_SYMBOL_GPL(iscsi_change_queue_depth);
  622. static int
  623. iscsi_conn_send_generic(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
  624. char *data, uint32_t data_size)
  625. {
  626. struct iscsi_session *session = conn->session;
  627. struct iscsi_nopout *nop = (struct iscsi_nopout *)hdr;
  628. struct iscsi_mgmt_task *mtask;
  629. spin_lock_bh(&session->lock);
  630. if (session->state == ISCSI_STATE_TERMINATE) {
  631. spin_unlock_bh(&session->lock);
  632. return -EPERM;
  633. }
  634. if (hdr->opcode == (ISCSI_OP_LOGIN | ISCSI_OP_IMMEDIATE) ||
  635. hdr->opcode == (ISCSI_OP_TEXT | ISCSI_OP_IMMEDIATE))
  636. /*
  637. * Login and Text are sent serially, in
  638. * request-followed-by-response sequence.
  639. * Same mtask can be used. Same ITT must be used.
  640. * Note that login_mtask is preallocated at conn_create().
  641. */
  642. mtask = conn->login_mtask;
  643. else {
  644. BUG_ON(conn->c_stage == ISCSI_CONN_INITIAL_STAGE);
  645. BUG_ON(conn->c_stage == ISCSI_CONN_STOPPED);
  646. if (!__kfifo_get(session->mgmtpool.queue,
  647. (void*)&mtask, sizeof(void*))) {
  648. spin_unlock_bh(&session->lock);
  649. return -ENOSPC;
  650. }
  651. }
  652. /*
  653. * pre-format CmdSN and ExpStatSN for outgoing PDU.
  654. */
  655. if (hdr->itt != cpu_to_be32(ISCSI_RESERVED_TAG)) {
  656. hdr->itt = mtask->itt | (conn->id << ISCSI_CID_SHIFT) |
  657. (session->age << ISCSI_AGE_SHIFT);
  658. nop->cmdsn = cpu_to_be32(session->cmdsn);
  659. if (conn->c_stage == ISCSI_CONN_STARTED &&
  660. !(hdr->opcode & ISCSI_OP_IMMEDIATE))
  661. session->cmdsn++;
  662. } else
  663. /* do not advance CmdSN */
  664. nop->cmdsn = cpu_to_be32(session->cmdsn);
  665. nop->exp_statsn = cpu_to_be32(conn->exp_statsn);
  666. if (data_size) {
  667. memcpy(mtask->data, data, data_size);
  668. mtask->data_count = data_size;
  669. } else
  670. mtask->data_count = 0;
  671. INIT_LIST_HEAD(&mtask->running);
  672. memcpy(mtask->hdr, hdr, sizeof(struct iscsi_hdr));
  673. if (session->tt->init_mgmt_task)
  674. session->tt->init_mgmt_task(conn, mtask, data, data_size);
  675. spin_unlock_bh(&session->lock);
  676. debug_scsi("mgmtpdu [op 0x%x hdr->itt 0x%x datalen %d]\n",
  677. hdr->opcode, hdr->itt, data_size);
  678. /*
  679. * since send_pdu() could be called at least from two contexts,
  680. * we need to serialize __kfifo_put, so we don't have to take
  681. * additional lock on fast data-path
  682. */
  683. if (hdr->opcode & ISCSI_OP_IMMEDIATE)
  684. __kfifo_put(conn->immqueue, (void*)&mtask, sizeof(void*));
  685. else
  686. __kfifo_put(conn->mgmtqueue, (void*)&mtask, sizeof(void*));
  687. scsi_queue_work(session->host, &conn->xmitwork);
  688. return 0;
  689. }
  690. int iscsi_conn_send_pdu(struct iscsi_cls_conn *cls_conn, struct iscsi_hdr *hdr,
  691. char *data, uint32_t data_size)
  692. {
  693. struct iscsi_conn *conn = cls_conn->dd_data;
  694. int rc;
  695. mutex_lock(&conn->xmitmutex);
  696. rc = iscsi_conn_send_generic(conn, hdr, data, data_size);
  697. mutex_unlock(&conn->xmitmutex);
  698. return rc;
  699. }
  700. EXPORT_SYMBOL_GPL(iscsi_conn_send_pdu);
  701. void iscsi_session_recovery_timedout(struct iscsi_cls_session *cls_session)
  702. {
  703. struct iscsi_session *session = class_to_transport_session(cls_session);
  704. struct iscsi_conn *conn = session->leadconn;
  705. spin_lock_bh(&session->lock);
  706. if (session->state != ISCSI_STATE_LOGGED_IN) {
  707. session->recovery_failed = 1;
  708. if (conn)
  709. wake_up(&conn->ehwait);
  710. }
  711. spin_unlock_bh(&session->lock);
  712. }
  713. EXPORT_SYMBOL_GPL(iscsi_session_recovery_timedout);
  714. int iscsi_eh_host_reset(struct scsi_cmnd *sc)
  715. {
  716. struct Scsi_Host *host = sc->device->host;
  717. struct iscsi_session *session = iscsi_hostdata(host->hostdata);
  718. struct iscsi_conn *conn = session->leadconn;
  719. int fail_session = 0;
  720. spin_lock_bh(&session->lock);
  721. if (session->state == ISCSI_STATE_TERMINATE) {
  722. failed:
  723. debug_scsi("failing host reset: session terminated "
  724. "[CID %d age %d]", conn->id, session->age);
  725. spin_unlock_bh(&session->lock);
  726. return FAILED;
  727. }
  728. if (sc->SCp.phase == session->age) {
  729. debug_scsi("failing connection CID %d due to SCSI host reset",
  730. conn->id);
  731. fail_session = 1;
  732. }
  733. spin_unlock_bh(&session->lock);
  734. /*
  735. * we drop the lock here but the leadconn cannot be destoyed while
  736. * we are in the scsi eh
  737. */
  738. if (fail_session) {
  739. iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
  740. /*
  741. * if userspace cannot respond then we must kick this off
  742. * here for it
  743. */
  744. iscsi_start_session_recovery(session, conn, STOP_CONN_RECOVER);
  745. }
  746. debug_scsi("iscsi_eh_host_reset wait for relogin\n");
  747. wait_event_interruptible(conn->ehwait,
  748. session->state == ISCSI_STATE_TERMINATE ||
  749. session->state == ISCSI_STATE_LOGGED_IN ||
  750. session->recovery_failed);
  751. if (signal_pending(current))
  752. flush_signals(current);
  753. spin_lock_bh(&session->lock);
  754. if (session->state == ISCSI_STATE_LOGGED_IN)
  755. printk(KERN_INFO "host reset succeeded\n");
  756. else
  757. goto failed;
  758. spin_unlock_bh(&session->lock);
  759. return SUCCESS;
  760. }
  761. EXPORT_SYMBOL_GPL(iscsi_eh_host_reset);
  762. static void iscsi_tmabort_timedout(unsigned long data)
  763. {
  764. struct iscsi_cmd_task *ctask = (struct iscsi_cmd_task *)data;
  765. struct iscsi_conn *conn = ctask->conn;
  766. struct iscsi_session *session = conn->session;
  767. spin_lock(&session->lock);
  768. if (conn->tmabort_state == TMABORT_INITIAL) {
  769. conn->tmabort_state = TMABORT_TIMEDOUT;
  770. debug_scsi("tmabort timedout [sc %p itt 0x%x]\n",
  771. ctask->sc, ctask->itt);
  772. /* unblock eh_abort() */
  773. wake_up(&conn->ehwait);
  774. }
  775. spin_unlock(&session->lock);
  776. }
  777. /* must be called with the mutex lock */
  778. static int iscsi_exec_abort_task(struct scsi_cmnd *sc,
  779. struct iscsi_cmd_task *ctask)
  780. {
  781. struct iscsi_conn *conn = ctask->conn;
  782. struct iscsi_session *session = conn->session;
  783. struct iscsi_tm *hdr = &conn->tmhdr;
  784. int rc;
  785. /*
  786. * ctask timed out but session is OK requests must be serialized.
  787. */
  788. memset(hdr, 0, sizeof(struct iscsi_tm));
  789. hdr->opcode = ISCSI_OP_SCSI_TMFUNC | ISCSI_OP_IMMEDIATE;
  790. hdr->flags = ISCSI_TM_FUNC_ABORT_TASK;
  791. hdr->flags |= ISCSI_FLAG_CMD_FINAL;
  792. memcpy(hdr->lun, ctask->hdr->lun, sizeof(hdr->lun));
  793. hdr->rtt = ctask->hdr->itt;
  794. hdr->refcmdsn = ctask->hdr->cmdsn;
  795. rc = iscsi_conn_send_generic(conn, (struct iscsi_hdr *)hdr,
  796. NULL, 0);
  797. if (rc) {
  798. iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
  799. debug_scsi("abort sent failure [itt 0x%x] %d", ctask->itt, rc);
  800. return rc;
  801. }
  802. debug_scsi("abort sent [itt 0x%x]\n", ctask->itt);
  803. spin_lock_bh(&session->lock);
  804. ctask->mtask = (struct iscsi_mgmt_task *)
  805. session->mgmt_cmds[(hdr->itt & ISCSI_ITT_MASK) -
  806. ISCSI_MGMT_ITT_OFFSET];
  807. if (conn->tmabort_state == TMABORT_INITIAL) {
  808. conn->tmfcmd_pdus_cnt++;
  809. conn->tmabort_timer.expires = 10*HZ + jiffies;
  810. conn->tmabort_timer.function = iscsi_tmabort_timedout;
  811. conn->tmabort_timer.data = (unsigned long)ctask;
  812. add_timer(&conn->tmabort_timer);
  813. debug_scsi("abort set timeout [itt 0x%x]", ctask->itt);
  814. }
  815. spin_unlock_bh(&session->lock);
  816. mutex_unlock(&conn->xmitmutex);
  817. /*
  818. * block eh thread until:
  819. *
  820. * 1) abort response
  821. * 2) abort timeout
  822. * 3) session is terminated or restarted or userspace has
  823. * given up on recovery
  824. */
  825. wait_event_interruptible(conn->ehwait,
  826. sc->SCp.phase != session->age ||
  827. session->state != ISCSI_STATE_LOGGED_IN ||
  828. conn->tmabort_state != TMABORT_INITIAL ||
  829. session->recovery_failed);
  830. if (signal_pending(current))
  831. flush_signals(current);
  832. del_timer_sync(&conn->tmabort_timer);
  833. mutex_lock(&conn->xmitmutex);
  834. return 0;
  835. }
  836. /*
  837. * xmit mutex and session lock must be held
  838. */
  839. #define iscsi_remove_task(tasktype) \
  840. static struct iscsi_##tasktype * \
  841. iscsi_remove_##tasktype(struct kfifo *fifo, uint32_t itt) \
  842. { \
  843. int i, nr_tasks = __kfifo_len(fifo) / sizeof(void*); \
  844. struct iscsi_##tasktype *task; \
  845. \
  846. debug_scsi("searching %d tasks\n", nr_tasks); \
  847. \
  848. for (i = 0; i < nr_tasks; i++) { \
  849. __kfifo_get(fifo, (void*)&task, sizeof(void*)); \
  850. debug_scsi("check task %u\n", task->itt); \
  851. \
  852. if (task->itt == itt) { \
  853. debug_scsi("matched task\n"); \
  854. break; \
  855. } \
  856. \
  857. __kfifo_put(fifo, (void*)&task, sizeof(void*)); \
  858. } \
  859. return NULL; \
  860. }
  861. iscsi_remove_task(mgmt_task);
  862. iscsi_remove_task(cmd_task);
  863. static int iscsi_ctask_mtask_cleanup(struct iscsi_cmd_task *ctask)
  864. {
  865. struct iscsi_conn *conn = ctask->conn;
  866. struct iscsi_session *session = conn->session;
  867. if (!ctask->mtask)
  868. return -EINVAL;
  869. if (!iscsi_remove_mgmt_task(conn->immqueue, ctask->mtask->itt))
  870. list_del(&ctask->mtask->running);
  871. __kfifo_put(session->mgmtpool.queue, (void*)&ctask->mtask,
  872. sizeof(void*));
  873. ctask->mtask = NULL;
  874. return 0;
  875. }
  876. /*
  877. * session lock and xmitmutex must be held
  878. */
  879. static void fail_command(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask,
  880. int err)
  881. {
  882. struct scsi_cmnd *sc;
  883. conn->session->tt->cleanup_cmd_task(conn, ctask);
  884. iscsi_ctask_mtask_cleanup(ctask);
  885. sc = ctask->sc;
  886. if (!sc)
  887. return;
  888. sc->result = err;
  889. sc->resid = sc->request_bufflen;
  890. iscsi_complete_command(conn->session, ctask);
  891. }
  892. int iscsi_eh_abort(struct scsi_cmnd *sc)
  893. {
  894. struct iscsi_cmd_task *ctask = (struct iscsi_cmd_task *)sc->SCp.ptr;
  895. struct iscsi_conn *conn = ctask->conn;
  896. struct iscsi_session *session = conn->session;
  897. struct iscsi_cmd_task *pending_ctask;
  898. int rc;
  899. conn->eh_abort_cnt++;
  900. debug_scsi("aborting [sc %p itt 0x%x]\n", sc, ctask->itt);
  901. mutex_lock(&conn->xmitmutex);
  902. spin_lock_bh(&session->lock);
  903. /*
  904. * If we are not logged in or we have started a new session
  905. * then let the host reset code handle this
  906. */
  907. if (session->state != ISCSI_STATE_LOGGED_IN ||
  908. sc->SCp.phase != session->age)
  909. goto failed;
  910. /* ctask completed before time out */
  911. if (!ctask->sc)
  912. goto success;
  913. /* what should we do here ? */
  914. if (conn->ctask == ctask) {
  915. printk(KERN_INFO "sc %p itt 0x%x partially sent. Failing "
  916. "abort\n", sc, ctask->itt);
  917. goto failed;
  918. }
  919. /* check for the easy pending cmd abort */
  920. pending_ctask = iscsi_remove_cmd_task(conn->xmitqueue, ctask->itt);
  921. if (pending_ctask) {
  922. /* iscsi_tcp queues write transfers on the xmitqueue */
  923. if (list_empty(&pending_ctask->running)) {
  924. debug_scsi("found pending task\n");
  925. goto success;
  926. } else
  927. __kfifo_put(conn->xmitqueue, (void*)&pending_ctask,
  928. sizeof(void*));
  929. }
  930. conn->tmabort_state = TMABORT_INITIAL;
  931. spin_unlock_bh(&session->lock);
  932. rc = iscsi_exec_abort_task(sc, ctask);
  933. spin_lock_bh(&session->lock);
  934. iscsi_ctask_mtask_cleanup(ctask);
  935. if (rc || sc->SCp.phase != session->age ||
  936. session->state != ISCSI_STATE_LOGGED_IN)
  937. goto failed;
  938. /* ctask completed before tmf abort response */
  939. if (!ctask->sc) {
  940. debug_scsi("sc completed while abort in progress\n");
  941. goto success;
  942. }
  943. if (conn->tmabort_state != TMABORT_SUCCESS) {
  944. spin_unlock_bh(&session->lock);
  945. iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
  946. spin_lock_bh(&session->lock);
  947. goto failed;
  948. }
  949. success:
  950. debug_scsi("abort success [sc %lx itt 0x%x]\n", (long)sc, ctask->itt);
  951. spin_unlock_bh(&session->lock);
  952. /*
  953. * clean up task if aborted. we have the xmitmutex so grab
  954. * the recv lock as a writer
  955. */
  956. write_lock_bh(conn->recv_lock);
  957. spin_lock(&session->lock);
  958. fail_command(conn, ctask, DID_ABORT << 16);
  959. spin_unlock(&session->lock);
  960. write_unlock_bh(conn->recv_lock);
  961. mutex_unlock(&conn->xmitmutex);
  962. return SUCCESS;
  963. failed:
  964. spin_unlock_bh(&session->lock);
  965. mutex_unlock(&conn->xmitmutex);
  966. debug_scsi("abort failed [sc %lx itt 0x%x]\n", (long)sc, ctask->itt);
  967. return FAILED;
  968. }
  969. EXPORT_SYMBOL_GPL(iscsi_eh_abort);
  970. int
  971. iscsi_pool_init(struct iscsi_queue *q, int max, void ***items, int item_size)
  972. {
  973. int i;
  974. *items = kmalloc(max * sizeof(void*), GFP_KERNEL);
  975. if (*items == NULL)
  976. return -ENOMEM;
  977. q->max = max;
  978. q->pool = kmalloc(max * sizeof(void*), GFP_KERNEL);
  979. if (q->pool == NULL) {
  980. kfree(*items);
  981. return -ENOMEM;
  982. }
  983. q->queue = kfifo_init((void*)q->pool, max * sizeof(void*),
  984. GFP_KERNEL, NULL);
  985. if (q->queue == ERR_PTR(-ENOMEM)) {
  986. kfree(q->pool);
  987. kfree(*items);
  988. return -ENOMEM;
  989. }
  990. for (i = 0; i < max; i++) {
  991. q->pool[i] = kmalloc(item_size, GFP_KERNEL);
  992. if (q->pool[i] == NULL) {
  993. int j;
  994. for (j = 0; j < i; j++)
  995. kfree(q->pool[j]);
  996. kfifo_free(q->queue);
  997. kfree(q->pool);
  998. kfree(*items);
  999. return -ENOMEM;
  1000. }
  1001. memset(q->pool[i], 0, item_size);
  1002. (*items)[i] = q->pool[i];
  1003. __kfifo_put(q->queue, (void*)&q->pool[i], sizeof(void*));
  1004. }
  1005. return 0;
  1006. }
  1007. EXPORT_SYMBOL_GPL(iscsi_pool_init);
  1008. void iscsi_pool_free(struct iscsi_queue *q, void **items)
  1009. {
  1010. int i;
  1011. for (i = 0; i < q->max; i++)
  1012. kfree(items[i]);
  1013. kfree(q->pool);
  1014. kfree(items);
  1015. }
  1016. EXPORT_SYMBOL_GPL(iscsi_pool_free);
  1017. /*
  1018. * iSCSI Session's hostdata organization:
  1019. *
  1020. * *------------------* <== hostdata_session(host->hostdata)
  1021. * | ptr to class sess|
  1022. * |------------------| <== iscsi_hostdata(host->hostdata)
  1023. * | iscsi_session |
  1024. * *------------------*
  1025. */
  1026. #define hostdata_privsize(_sz) (sizeof(unsigned long) + _sz + \
  1027. _sz % sizeof(unsigned long))
  1028. #define hostdata_session(_hostdata) (iscsi_ptr(*(unsigned long *)_hostdata))
  1029. /**
  1030. * iscsi_session_setup - create iscsi cls session and host and session
  1031. * @scsit: scsi transport template
  1032. * @iscsit: iscsi transport template
  1033. * @initial_cmdsn: initial CmdSN
  1034. * @hostno: host no allocated
  1035. *
  1036. * This can be used by software iscsi_transports that allocate
  1037. * a session per scsi host.
  1038. **/
  1039. struct iscsi_cls_session *
  1040. iscsi_session_setup(struct iscsi_transport *iscsit,
  1041. struct scsi_transport_template *scsit,
  1042. int cmd_task_size, int mgmt_task_size,
  1043. uint32_t initial_cmdsn, uint32_t *hostno)
  1044. {
  1045. struct Scsi_Host *shost;
  1046. struct iscsi_session *session;
  1047. struct iscsi_cls_session *cls_session;
  1048. int cmd_i;
  1049. shost = scsi_host_alloc(iscsit->host_template,
  1050. hostdata_privsize(sizeof(*session)));
  1051. if (!shost)
  1052. return NULL;
  1053. shost->max_id = 1;
  1054. shost->max_channel = 0;
  1055. shost->max_lun = iscsit->max_lun;
  1056. shost->max_cmd_len = iscsit->max_cmd_len;
  1057. shost->transportt = scsit;
  1058. shost->transportt->create_work_queue = 1;
  1059. *hostno = shost->host_no;
  1060. session = iscsi_hostdata(shost->hostdata);
  1061. memset(session, 0, sizeof(struct iscsi_session));
  1062. session->host = shost;
  1063. session->state = ISCSI_STATE_FREE;
  1064. session->mgmtpool_max = ISCSI_MGMT_CMDS_MAX;
  1065. session->cmds_max = ISCSI_XMIT_CMDS_MAX;
  1066. session->cmdsn = initial_cmdsn;
  1067. session->exp_cmdsn = initial_cmdsn + 1;
  1068. session->max_cmdsn = initial_cmdsn + 1;
  1069. session->max_r2t = 1;
  1070. session->tt = iscsit;
  1071. /* initialize SCSI PDU commands pool */
  1072. if (iscsi_pool_init(&session->cmdpool, session->cmds_max,
  1073. (void***)&session->cmds,
  1074. cmd_task_size + sizeof(struct iscsi_cmd_task)))
  1075. goto cmdpool_alloc_fail;
  1076. /* pre-format cmds pool with ITT */
  1077. for (cmd_i = 0; cmd_i < session->cmds_max; cmd_i++) {
  1078. struct iscsi_cmd_task *ctask = session->cmds[cmd_i];
  1079. if (cmd_task_size)
  1080. ctask->dd_data = &ctask[1];
  1081. ctask->itt = cmd_i;
  1082. }
  1083. spin_lock_init(&session->lock);
  1084. INIT_LIST_HEAD(&session->connections);
  1085. /* initialize immediate command pool */
  1086. if (iscsi_pool_init(&session->mgmtpool, session->mgmtpool_max,
  1087. (void***)&session->mgmt_cmds,
  1088. mgmt_task_size + sizeof(struct iscsi_mgmt_task)))
  1089. goto mgmtpool_alloc_fail;
  1090. /* pre-format immediate cmds pool with ITT */
  1091. for (cmd_i = 0; cmd_i < session->mgmtpool_max; cmd_i++) {
  1092. struct iscsi_mgmt_task *mtask = session->mgmt_cmds[cmd_i];
  1093. if (mgmt_task_size)
  1094. mtask->dd_data = &mtask[1];
  1095. mtask->itt = ISCSI_MGMT_ITT_OFFSET + cmd_i;
  1096. mtask->data = kmalloc(DEFAULT_MAX_RECV_DATA_SEGMENT_LENGTH,
  1097. GFP_KERNEL);
  1098. if (!mtask->data) {
  1099. int j;
  1100. for (j = 0; j < cmd_i; j++)
  1101. kfree(session->mgmt_cmds[j]->data);
  1102. goto immdata_alloc_fail;
  1103. }
  1104. }
  1105. if (scsi_add_host(shost, NULL))
  1106. goto add_host_fail;
  1107. cls_session = iscsi_create_session(shost, iscsit, 0);
  1108. if (!cls_session)
  1109. goto cls_session_fail;
  1110. *(unsigned long*)shost->hostdata = (unsigned long)cls_session;
  1111. return cls_session;
  1112. cls_session_fail:
  1113. scsi_remove_host(shost);
  1114. add_host_fail:
  1115. for (cmd_i = 0; cmd_i < session->mgmtpool_max; cmd_i++)
  1116. kfree(session->mgmt_cmds[cmd_i]->data);
  1117. immdata_alloc_fail:
  1118. iscsi_pool_free(&session->mgmtpool, (void**)session->mgmt_cmds);
  1119. mgmtpool_alloc_fail:
  1120. iscsi_pool_free(&session->cmdpool, (void**)session->cmds);
  1121. cmdpool_alloc_fail:
  1122. scsi_host_put(shost);
  1123. return NULL;
  1124. }
  1125. EXPORT_SYMBOL_GPL(iscsi_session_setup);
  1126. /**
  1127. * iscsi_session_teardown - destroy session, host, and cls_session
  1128. * shost: scsi host
  1129. *
  1130. * This can be used by software iscsi_transports that allocate
  1131. * a session per scsi host.
  1132. **/
  1133. void iscsi_session_teardown(struct iscsi_cls_session *cls_session)
  1134. {
  1135. struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
  1136. struct iscsi_session *session = iscsi_hostdata(shost->hostdata);
  1137. int cmd_i;
  1138. scsi_remove_host(shost);
  1139. for (cmd_i = 0; cmd_i < session->mgmtpool_max; cmd_i++)
  1140. kfree(session->mgmt_cmds[cmd_i]->data);
  1141. iscsi_pool_free(&session->mgmtpool, (void**)session->mgmt_cmds);
  1142. iscsi_pool_free(&session->cmdpool, (void**)session->cmds);
  1143. iscsi_destroy_session(cls_session);
  1144. scsi_host_put(shost);
  1145. }
  1146. EXPORT_SYMBOL_GPL(iscsi_session_teardown);
  1147. /**
  1148. * iscsi_conn_setup - create iscsi_cls_conn and iscsi_conn
  1149. * @cls_session: iscsi_cls_session
  1150. * @conn_idx: cid
  1151. **/
  1152. struct iscsi_cls_conn *
  1153. iscsi_conn_setup(struct iscsi_cls_session *cls_session, uint32_t conn_idx)
  1154. {
  1155. struct iscsi_session *session = class_to_transport_session(cls_session);
  1156. struct iscsi_conn *conn;
  1157. struct iscsi_cls_conn *cls_conn;
  1158. cls_conn = iscsi_create_conn(cls_session, conn_idx);
  1159. if (!cls_conn)
  1160. return NULL;
  1161. conn = cls_conn->dd_data;
  1162. memset(conn, 0, sizeof(*conn));
  1163. conn->session = session;
  1164. conn->cls_conn = cls_conn;
  1165. conn->c_stage = ISCSI_CONN_INITIAL_STAGE;
  1166. conn->id = conn_idx;
  1167. conn->exp_statsn = 0;
  1168. conn->tmabort_state = TMABORT_INITIAL;
  1169. INIT_LIST_HEAD(&conn->run_list);
  1170. INIT_LIST_HEAD(&conn->mgmt_run_list);
  1171. /* initialize general xmit PDU commands queue */
  1172. conn->xmitqueue = kfifo_alloc(session->cmds_max * sizeof(void*),
  1173. GFP_KERNEL, NULL);
  1174. if (conn->xmitqueue == ERR_PTR(-ENOMEM))
  1175. goto xmitqueue_alloc_fail;
  1176. /* initialize general immediate & non-immediate PDU commands queue */
  1177. conn->immqueue = kfifo_alloc(session->mgmtpool_max * sizeof(void*),
  1178. GFP_KERNEL, NULL);
  1179. if (conn->immqueue == ERR_PTR(-ENOMEM))
  1180. goto immqueue_alloc_fail;
  1181. conn->mgmtqueue = kfifo_alloc(session->mgmtpool_max * sizeof(void*),
  1182. GFP_KERNEL, NULL);
  1183. if (conn->mgmtqueue == ERR_PTR(-ENOMEM))
  1184. goto mgmtqueue_alloc_fail;
  1185. INIT_WORK(&conn->xmitwork, iscsi_xmitworker, conn);
  1186. /* allocate login_mtask used for the login/text sequences */
  1187. spin_lock_bh(&session->lock);
  1188. if (!__kfifo_get(session->mgmtpool.queue,
  1189. (void*)&conn->login_mtask,
  1190. sizeof(void*))) {
  1191. spin_unlock_bh(&session->lock);
  1192. goto login_mtask_alloc_fail;
  1193. }
  1194. spin_unlock_bh(&session->lock);
  1195. init_timer(&conn->tmabort_timer);
  1196. mutex_init(&conn->xmitmutex);
  1197. init_waitqueue_head(&conn->ehwait);
  1198. return cls_conn;
  1199. login_mtask_alloc_fail:
  1200. kfifo_free(conn->mgmtqueue);
  1201. mgmtqueue_alloc_fail:
  1202. kfifo_free(conn->immqueue);
  1203. immqueue_alloc_fail:
  1204. kfifo_free(conn->xmitqueue);
  1205. xmitqueue_alloc_fail:
  1206. iscsi_destroy_conn(cls_conn);
  1207. return NULL;
  1208. }
  1209. EXPORT_SYMBOL_GPL(iscsi_conn_setup);
  1210. /**
  1211. * iscsi_conn_teardown - teardown iscsi connection
  1212. * cls_conn: iscsi class connection
  1213. *
  1214. * TODO: we may need to make this into a two step process
  1215. * like scsi-mls remove + put host
  1216. */
  1217. void iscsi_conn_teardown(struct iscsi_cls_conn *cls_conn)
  1218. {
  1219. struct iscsi_conn *conn = cls_conn->dd_data;
  1220. struct iscsi_session *session = conn->session;
  1221. unsigned long flags;
  1222. mutex_lock(&conn->xmitmutex);
  1223. set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx);
  1224. if (conn->c_stage == ISCSI_CONN_INITIAL_STAGE) {
  1225. if (session->tt->suspend_conn_recv)
  1226. session->tt->suspend_conn_recv(conn);
  1227. session->tt->terminate_conn(conn);
  1228. }
  1229. spin_lock_bh(&session->lock);
  1230. conn->c_stage = ISCSI_CONN_CLEANUP_WAIT;
  1231. if (session->leadconn == conn) {
  1232. /*
  1233. * leading connection? then give up on recovery.
  1234. */
  1235. session->state = ISCSI_STATE_TERMINATE;
  1236. wake_up(&conn->ehwait);
  1237. }
  1238. spin_unlock_bh(&session->lock);
  1239. mutex_unlock(&conn->xmitmutex);
  1240. /*
  1241. * Block until all in-progress commands for this connection
  1242. * time out or fail.
  1243. */
  1244. for (;;) {
  1245. spin_lock_irqsave(session->host->host_lock, flags);
  1246. if (!session->host->host_busy) { /* OK for ERL == 0 */
  1247. spin_unlock_irqrestore(session->host->host_lock, flags);
  1248. break;
  1249. }
  1250. spin_unlock_irqrestore(session->host->host_lock, flags);
  1251. msleep_interruptible(500);
  1252. printk("conn_destroy(): host_busy %d host_failed %d\n",
  1253. session->host->host_busy, session->host->host_failed);
  1254. /*
  1255. * force eh_abort() to unblock
  1256. */
  1257. wake_up(&conn->ehwait);
  1258. }
  1259. spin_lock_bh(&session->lock);
  1260. __kfifo_put(session->mgmtpool.queue, (void*)&conn->login_mtask,
  1261. sizeof(void*));
  1262. list_del(&conn->item);
  1263. if (list_empty(&session->connections))
  1264. session->leadconn = NULL;
  1265. if (session->leadconn && session->leadconn == conn)
  1266. session->leadconn = container_of(session->connections.next,
  1267. struct iscsi_conn, item);
  1268. if (session->leadconn == NULL)
  1269. /* no connections exits.. reset sequencing */
  1270. session->cmdsn = session->max_cmdsn = session->exp_cmdsn = 1;
  1271. spin_unlock_bh(&session->lock);
  1272. kfifo_free(conn->xmitqueue);
  1273. kfifo_free(conn->immqueue);
  1274. kfifo_free(conn->mgmtqueue);
  1275. iscsi_destroy_conn(cls_conn);
  1276. }
  1277. EXPORT_SYMBOL_GPL(iscsi_conn_teardown);
  1278. int iscsi_conn_start(struct iscsi_cls_conn *cls_conn)
  1279. {
  1280. struct iscsi_conn *conn = cls_conn->dd_data;
  1281. struct iscsi_session *session = conn->session;
  1282. if (session == NULL) {
  1283. printk(KERN_ERR "iscsi: can't start unbound connection\n");
  1284. return -EPERM;
  1285. }
  1286. spin_lock_bh(&session->lock);
  1287. conn->c_stage = ISCSI_CONN_STARTED;
  1288. session->state = ISCSI_STATE_LOGGED_IN;
  1289. switch(conn->stop_stage) {
  1290. case STOP_CONN_RECOVER:
  1291. /*
  1292. * unblock eh_abort() if it is blocked. re-try all
  1293. * commands after successful recovery
  1294. */
  1295. session->conn_cnt++;
  1296. conn->stop_stage = 0;
  1297. conn->tmabort_state = TMABORT_INITIAL;
  1298. session->age++;
  1299. session->recovery_failed = 0;
  1300. spin_unlock_bh(&session->lock);
  1301. iscsi_unblock_session(session_to_cls(session));
  1302. wake_up(&conn->ehwait);
  1303. return 0;
  1304. case STOP_CONN_TERM:
  1305. session->conn_cnt++;
  1306. conn->stop_stage = 0;
  1307. break;
  1308. case STOP_CONN_SUSPEND:
  1309. conn->stop_stage = 0;
  1310. clear_bit(ISCSI_SUSPEND_BIT, &conn->suspend_rx);
  1311. clear_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx);
  1312. break;
  1313. default:
  1314. break;
  1315. }
  1316. spin_unlock_bh(&session->lock);
  1317. return 0;
  1318. }
  1319. EXPORT_SYMBOL_GPL(iscsi_conn_start);
  1320. static void
  1321. flush_control_queues(struct iscsi_session *session, struct iscsi_conn *conn)
  1322. {
  1323. struct iscsi_mgmt_task *mtask, *tmp;
  1324. /* handle pending */
  1325. while (__kfifo_get(conn->immqueue, (void*)&mtask, sizeof(void*)) ||
  1326. __kfifo_get(conn->mgmtqueue, (void*)&mtask, sizeof(void*))) {
  1327. if (mtask == conn->login_mtask)
  1328. continue;
  1329. debug_scsi("flushing pending mgmt task itt 0x%x\n", mtask->itt);
  1330. __kfifo_put(session->mgmtpool.queue, (void*)&mtask,
  1331. sizeof(void*));
  1332. }
  1333. /* handle running */
  1334. list_for_each_entry_safe(mtask, tmp, &conn->mgmt_run_list, running) {
  1335. debug_scsi("flushing running mgmt task itt 0x%x\n", mtask->itt);
  1336. list_del(&mtask->running);
  1337. if (mtask == conn->login_mtask)
  1338. continue;
  1339. __kfifo_put(session->mgmtpool.queue, (void*)&mtask,
  1340. sizeof(void*));
  1341. }
  1342. conn->mtask = NULL;
  1343. }
  1344. /* Fail commands. Mutex and session lock held and recv side suspended */
  1345. static void fail_all_commands(struct iscsi_conn *conn)
  1346. {
  1347. struct iscsi_cmd_task *ctask, *tmp;
  1348. /* flush pending */
  1349. while (__kfifo_get(conn->xmitqueue, (void*)&ctask, sizeof(void*))) {
  1350. debug_scsi("failing pending sc %p itt 0x%x\n", ctask->sc,
  1351. ctask->itt);
  1352. fail_command(conn, ctask, DID_BUS_BUSY << 16);
  1353. }
  1354. /* fail all other running */
  1355. list_for_each_entry_safe(ctask, tmp, &conn->run_list, running) {
  1356. debug_scsi("failing in progress sc %p itt 0x%x\n",
  1357. ctask->sc, ctask->itt);
  1358. fail_command(conn, ctask, DID_BUS_BUSY << 16);
  1359. }
  1360. conn->ctask = NULL;
  1361. }
  1362. void iscsi_start_session_recovery(struct iscsi_session *session,
  1363. struct iscsi_conn *conn, int flag)
  1364. {
  1365. int old_stop_stage;
  1366. spin_lock_bh(&session->lock);
  1367. if (conn->stop_stage == STOP_CONN_TERM) {
  1368. spin_unlock_bh(&session->lock);
  1369. return;
  1370. }
  1371. /*
  1372. * When this is called for the in_login state, we only want to clean
  1373. * up the login task and connection.
  1374. */
  1375. if (conn->stop_stage != STOP_CONN_RECOVER)
  1376. session->conn_cnt--;
  1377. old_stop_stage = conn->stop_stage;
  1378. conn->stop_stage = flag;
  1379. spin_unlock_bh(&session->lock);
  1380. if (session->tt->suspend_conn_recv)
  1381. session->tt->suspend_conn_recv(conn);
  1382. mutex_lock(&conn->xmitmutex);
  1383. spin_lock_bh(&session->lock);
  1384. conn->c_stage = ISCSI_CONN_STOPPED;
  1385. set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx);
  1386. if (session->conn_cnt == 0 || session->leadconn == conn)
  1387. session->state = ISCSI_STATE_FAILED;
  1388. spin_unlock_bh(&session->lock);
  1389. session->tt->terminate_conn(conn);
  1390. /*
  1391. * flush queues.
  1392. */
  1393. spin_lock_bh(&session->lock);
  1394. fail_all_commands(conn);
  1395. flush_control_queues(session, conn);
  1396. spin_unlock_bh(&session->lock);
  1397. /*
  1398. * for connection level recovery we should not calculate
  1399. * header digest. conn->hdr_size used for optimization
  1400. * in hdr_extract() and will be re-negotiated at
  1401. * set_param() time.
  1402. */
  1403. if (flag == STOP_CONN_RECOVER) {
  1404. conn->hdrdgst_en = 0;
  1405. conn->datadgst_en = 0;
  1406. /*
  1407. * if this is called from the eh and and from userspace
  1408. * then we only need to block once.
  1409. */
  1410. if (session->state == ISCSI_STATE_FAILED &&
  1411. old_stop_stage != STOP_CONN_RECOVER)
  1412. iscsi_block_session(session_to_cls(session));
  1413. }
  1414. mutex_unlock(&conn->xmitmutex);
  1415. }
  1416. EXPORT_SYMBOL_GPL(iscsi_start_session_recovery);
  1417. void iscsi_conn_stop(struct iscsi_cls_conn *cls_conn, int flag)
  1418. {
  1419. struct iscsi_conn *conn = cls_conn->dd_data;
  1420. struct iscsi_session *session = conn->session;
  1421. switch (flag) {
  1422. case STOP_CONN_RECOVER:
  1423. case STOP_CONN_TERM:
  1424. iscsi_start_session_recovery(session, conn, flag);
  1425. return;
  1426. case STOP_CONN_SUSPEND:
  1427. if (session->tt->suspend_conn_recv)
  1428. session->tt->suspend_conn_recv(conn);
  1429. mutex_lock(&conn->xmitmutex);
  1430. spin_lock_bh(&session->lock);
  1431. conn->stop_stage = flag;
  1432. conn->c_stage = ISCSI_CONN_STOPPED;
  1433. set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx);
  1434. spin_unlock_bh(&session->lock);
  1435. mutex_unlock(&conn->xmitmutex);
  1436. break;
  1437. default:
  1438. printk(KERN_ERR "invalid stop flag %d\n", flag);
  1439. }
  1440. }
  1441. EXPORT_SYMBOL_GPL(iscsi_conn_stop);
  1442. int iscsi_conn_bind(struct iscsi_cls_session *cls_session,
  1443. struct iscsi_cls_conn *cls_conn, int is_leading)
  1444. {
  1445. struct iscsi_session *session = class_to_transport_session(cls_session);
  1446. struct iscsi_conn *tmp = ERR_PTR(-EEXIST), *conn = cls_conn->dd_data;
  1447. /* lookup for existing connection */
  1448. spin_lock_bh(&session->lock);
  1449. list_for_each_entry(tmp, &session->connections, item) {
  1450. if (tmp == conn) {
  1451. if (conn->c_stage != ISCSI_CONN_STOPPED ||
  1452. conn->stop_stage == STOP_CONN_TERM) {
  1453. printk(KERN_ERR "iscsi_tcp: can't bind "
  1454. "non-stopped connection (%d:%d)\n",
  1455. conn->c_stage, conn->stop_stage);
  1456. spin_unlock_bh(&session->lock);
  1457. return -EIO;
  1458. }
  1459. break;
  1460. }
  1461. }
  1462. if (tmp != conn) {
  1463. /* bind new iSCSI connection to session */
  1464. conn->session = session;
  1465. list_add(&conn->item, &session->connections);
  1466. }
  1467. spin_unlock_bh(&session->lock);
  1468. if (is_leading)
  1469. session->leadconn = conn;
  1470. /*
  1471. * Unblock xmitworker(), Login Phase will pass through.
  1472. */
  1473. clear_bit(ISCSI_SUSPEND_BIT, &conn->suspend_rx);
  1474. clear_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx);
  1475. return 0;
  1476. }
  1477. EXPORT_SYMBOL_GPL(iscsi_conn_bind);
  1478. MODULE_AUTHOR("Mike Christie");
  1479. MODULE_DESCRIPTION("iSCSI library functions");
  1480. MODULE_LICENSE("GPL");