libiscsi.c 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246
  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/kfifo.h>
  26. #include <linux/delay.h>
  27. #include <asm/unaligned.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. static void fail_command(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask,
  40. int err);
  41. struct iscsi_session *
  42. class_to_transport_session(struct iscsi_cls_session *cls_session)
  43. {
  44. struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
  45. return iscsi_hostdata(shost->hostdata);
  46. }
  47. EXPORT_SYMBOL_GPL(class_to_transport_session);
  48. /* Serial Number Arithmetic, 32 bits, less than, RFC1982 */
  49. #define SNA32_CHECK 2147483648UL
  50. static int iscsi_sna_lt(u32 n1, u32 n2)
  51. {
  52. return n1 != n2 && ((n1 < n2 && (n2 - n1 < SNA32_CHECK)) ||
  53. (n1 > n2 && (n2 - n1 < SNA32_CHECK)));
  54. }
  55. /* Serial Number Arithmetic, 32 bits, less than, RFC1982 */
  56. static int iscsi_sna_lte(u32 n1, u32 n2)
  57. {
  58. return n1 == n2 || ((n1 < n2 && (n2 - n1 < SNA32_CHECK)) ||
  59. (n1 > n2 && (n2 - n1 < SNA32_CHECK)));
  60. }
  61. void
  62. iscsi_update_cmdsn(struct iscsi_session *session, struct iscsi_nopin *hdr)
  63. {
  64. uint32_t max_cmdsn = be32_to_cpu(hdr->max_cmdsn);
  65. uint32_t exp_cmdsn = be32_to_cpu(hdr->exp_cmdsn);
  66. /*
  67. * standard specifies this check for when to update expected and
  68. * max sequence numbers
  69. */
  70. if (iscsi_sna_lt(max_cmdsn, exp_cmdsn - 1))
  71. return;
  72. if (exp_cmdsn != session->exp_cmdsn &&
  73. !iscsi_sna_lt(exp_cmdsn, session->exp_cmdsn))
  74. session->exp_cmdsn = exp_cmdsn;
  75. if (max_cmdsn != session->max_cmdsn &&
  76. !iscsi_sna_lt(max_cmdsn, session->max_cmdsn)) {
  77. session->max_cmdsn = max_cmdsn;
  78. /*
  79. * if the window closed with IO queued, then kick the
  80. * xmit thread
  81. */
  82. if (!list_empty(&session->leadconn->xmitqueue) ||
  83. !list_empty(&session->leadconn->mgmtqueue))
  84. scsi_queue_work(session->host,
  85. &session->leadconn->xmitwork);
  86. }
  87. }
  88. EXPORT_SYMBOL_GPL(iscsi_update_cmdsn);
  89. void iscsi_prep_unsolicit_data_pdu(struct iscsi_cmd_task *ctask,
  90. struct iscsi_data *hdr)
  91. {
  92. struct iscsi_conn *conn = ctask->conn;
  93. memset(hdr, 0, sizeof(struct iscsi_data));
  94. hdr->ttt = cpu_to_be32(ISCSI_RESERVED_TAG);
  95. hdr->datasn = cpu_to_be32(ctask->unsol_datasn);
  96. ctask->unsol_datasn++;
  97. hdr->opcode = ISCSI_OP_SCSI_DATA_OUT;
  98. memcpy(hdr->lun, ctask->hdr->lun, sizeof(hdr->lun));
  99. hdr->itt = ctask->hdr->itt;
  100. hdr->exp_statsn = cpu_to_be32(conn->exp_statsn);
  101. hdr->offset = cpu_to_be32(ctask->unsol_offset);
  102. if (ctask->unsol_count > conn->max_xmit_dlength) {
  103. hton24(hdr->dlength, conn->max_xmit_dlength);
  104. ctask->data_count = conn->max_xmit_dlength;
  105. ctask->unsol_offset += ctask->data_count;
  106. hdr->flags = 0;
  107. } else {
  108. hton24(hdr->dlength, ctask->unsol_count);
  109. ctask->data_count = ctask->unsol_count;
  110. hdr->flags = ISCSI_FLAG_CMD_FINAL;
  111. }
  112. }
  113. EXPORT_SYMBOL_GPL(iscsi_prep_unsolicit_data_pdu);
  114. static int iscsi_add_hdr(struct iscsi_cmd_task *ctask, unsigned len)
  115. {
  116. unsigned exp_len = ctask->hdr_len + len;
  117. if (exp_len > ctask->hdr_max) {
  118. WARN_ON(1);
  119. return -EINVAL;
  120. }
  121. WARN_ON(len & (ISCSI_PAD_LEN - 1)); /* caller must pad the AHS */
  122. ctask->hdr_len = exp_len;
  123. return 0;
  124. }
  125. /**
  126. * iscsi_prep_scsi_cmd_pdu - prep iscsi scsi cmd pdu
  127. * @ctask: iscsi cmd task
  128. *
  129. * Prep basic iSCSI PDU fields for a scsi cmd pdu. The LLD should set
  130. * fields like dlength or final based on how much data it sends
  131. */
  132. static int iscsi_prep_scsi_cmd_pdu(struct iscsi_cmd_task *ctask)
  133. {
  134. struct iscsi_conn *conn = ctask->conn;
  135. struct iscsi_session *session = conn->session;
  136. struct iscsi_cmd *hdr = ctask->hdr;
  137. struct scsi_cmnd *sc = ctask->sc;
  138. unsigned hdrlength;
  139. int rc;
  140. ctask->hdr_len = 0;
  141. rc = iscsi_add_hdr(ctask, sizeof(*hdr));
  142. if (rc)
  143. return rc;
  144. hdr->opcode = ISCSI_OP_SCSI_CMD;
  145. hdr->flags = ISCSI_ATTR_SIMPLE;
  146. int_to_scsilun(sc->device->lun, (struct scsi_lun *)hdr->lun);
  147. hdr->itt = build_itt(ctask->itt, conn->id, session->age);
  148. hdr->data_length = cpu_to_be32(scsi_bufflen(sc));
  149. hdr->cmdsn = cpu_to_be32(session->cmdsn);
  150. session->cmdsn++;
  151. hdr->exp_statsn = cpu_to_be32(conn->exp_statsn);
  152. memcpy(hdr->cdb, sc->cmnd, sc->cmd_len);
  153. if (sc->cmd_len < MAX_COMMAND_SIZE)
  154. memset(&hdr->cdb[sc->cmd_len], 0,
  155. MAX_COMMAND_SIZE - sc->cmd_len);
  156. ctask->data_count = 0;
  157. ctask->imm_count = 0;
  158. if (sc->sc_data_direction == DMA_TO_DEVICE) {
  159. hdr->flags |= ISCSI_FLAG_CMD_WRITE;
  160. /*
  161. * Write counters:
  162. *
  163. * imm_count bytes to be sent right after
  164. * SCSI PDU Header
  165. *
  166. * unsol_count bytes(as Data-Out) to be sent
  167. * without R2T ack right after
  168. * immediate data
  169. *
  170. * r2t_data_count bytes to be sent via R2T ack's
  171. *
  172. * pad_count bytes to be sent as zero-padding
  173. */
  174. ctask->unsol_count = 0;
  175. ctask->unsol_offset = 0;
  176. ctask->unsol_datasn = 0;
  177. if (session->imm_data_en) {
  178. if (scsi_bufflen(sc) >= session->first_burst)
  179. ctask->imm_count = min(session->first_burst,
  180. conn->max_xmit_dlength);
  181. else
  182. ctask->imm_count = min(scsi_bufflen(sc),
  183. conn->max_xmit_dlength);
  184. hton24(ctask->hdr->dlength, ctask->imm_count);
  185. } else
  186. zero_data(ctask->hdr->dlength);
  187. if (!session->initial_r2t_en) {
  188. ctask->unsol_count = min((session->first_burst),
  189. (scsi_bufflen(sc))) - ctask->imm_count;
  190. ctask->unsol_offset = ctask->imm_count;
  191. }
  192. if (!ctask->unsol_count)
  193. /* No unsolicit Data-Out's */
  194. ctask->hdr->flags |= ISCSI_FLAG_CMD_FINAL;
  195. } else {
  196. hdr->flags |= ISCSI_FLAG_CMD_FINAL;
  197. zero_data(hdr->dlength);
  198. if (sc->sc_data_direction == DMA_FROM_DEVICE)
  199. hdr->flags |= ISCSI_FLAG_CMD_READ;
  200. }
  201. /* calculate size of additional header segments (AHSs) */
  202. hdrlength = ctask->hdr_len - sizeof(*hdr);
  203. WARN_ON(hdrlength & (ISCSI_PAD_LEN-1));
  204. hdrlength /= ISCSI_PAD_LEN;
  205. WARN_ON(hdrlength >= 256);
  206. hdr->hlength = hdrlength & 0xFF;
  207. conn->scsicmd_pdus_cnt++;
  208. debug_scsi("iscsi prep [%s cid %d sc %p cdb 0x%x itt 0x%x len %d "
  209. "cmdsn %d win %d]\n",
  210. sc->sc_data_direction == DMA_TO_DEVICE ? "write" : "read",
  211. conn->id, sc, sc->cmnd[0], ctask->itt, scsi_bufflen(sc),
  212. session->cmdsn, session->max_cmdsn - session->exp_cmdsn + 1);
  213. return 0;
  214. }
  215. /**
  216. * iscsi_complete_command - return command back to scsi-ml
  217. * @ctask: iscsi cmd task
  218. *
  219. * Must be called with session lock.
  220. * This function returns the scsi command to scsi-ml and returns
  221. * the cmd task to the pool of available cmd tasks.
  222. */
  223. static void iscsi_complete_command(struct iscsi_cmd_task *ctask)
  224. {
  225. struct iscsi_session *session = ctask->conn->session;
  226. struct scsi_cmnd *sc = ctask->sc;
  227. ctask->state = ISCSI_TASK_COMPLETED;
  228. ctask->sc = NULL;
  229. /* SCSI eh reuses commands to verify us */
  230. sc->SCp.ptr = NULL;
  231. list_del_init(&ctask->running);
  232. __kfifo_put(session->cmdpool.queue, (void*)&ctask, sizeof(void*));
  233. sc->scsi_done(sc);
  234. }
  235. static void __iscsi_get_ctask(struct iscsi_cmd_task *ctask)
  236. {
  237. atomic_inc(&ctask->refcount);
  238. }
  239. static void __iscsi_put_ctask(struct iscsi_cmd_task *ctask)
  240. {
  241. if (atomic_dec_and_test(&ctask->refcount))
  242. iscsi_complete_command(ctask);
  243. }
  244. /**
  245. * iscsi_cmd_rsp - SCSI Command Response processing
  246. * @conn: iscsi connection
  247. * @hdr: iscsi header
  248. * @ctask: scsi command task
  249. * @data: cmd data buffer
  250. * @datalen: len of buffer
  251. *
  252. * iscsi_cmd_rsp sets up the scsi_cmnd fields based on the PDU and
  253. * then completes the command and task.
  254. **/
  255. static void iscsi_scsi_cmd_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
  256. struct iscsi_cmd_task *ctask, char *data,
  257. int datalen)
  258. {
  259. struct iscsi_cmd_rsp *rhdr = (struct iscsi_cmd_rsp *)hdr;
  260. struct iscsi_session *session = conn->session;
  261. struct scsi_cmnd *sc = ctask->sc;
  262. iscsi_update_cmdsn(session, (struct iscsi_nopin*)rhdr);
  263. conn->exp_statsn = be32_to_cpu(rhdr->statsn) + 1;
  264. sc->result = (DID_OK << 16) | rhdr->cmd_status;
  265. if (rhdr->response != ISCSI_STATUS_CMD_COMPLETED) {
  266. sc->result = DID_ERROR << 16;
  267. goto out;
  268. }
  269. if (rhdr->cmd_status == SAM_STAT_CHECK_CONDITION) {
  270. uint16_t senselen;
  271. if (datalen < 2) {
  272. invalid_datalen:
  273. printk(KERN_ERR "iscsi: Got CHECK_CONDITION but "
  274. "invalid data buffer size of %d\n", datalen);
  275. sc->result = DID_BAD_TARGET << 16;
  276. goto out;
  277. }
  278. senselen = be16_to_cpu(get_unaligned((__be16 *) data));
  279. if (datalen < senselen)
  280. goto invalid_datalen;
  281. memcpy(sc->sense_buffer, data + 2,
  282. min_t(uint16_t, senselen, SCSI_SENSE_BUFFERSIZE));
  283. debug_scsi("copied %d bytes of sense\n",
  284. min_t(uint16_t, senselen, SCSI_SENSE_BUFFERSIZE));
  285. }
  286. if (rhdr->flags & (ISCSI_FLAG_CMD_UNDERFLOW |
  287. ISCSI_FLAG_CMD_OVERFLOW)) {
  288. int res_count = be32_to_cpu(rhdr->residual_count);
  289. if (res_count > 0 &&
  290. (rhdr->flags & ISCSI_FLAG_CMD_OVERFLOW ||
  291. res_count <= scsi_bufflen(sc)))
  292. scsi_set_resid(sc, res_count);
  293. else
  294. sc->result = (DID_BAD_TARGET << 16) | rhdr->cmd_status;
  295. } else if (rhdr->flags & (ISCSI_FLAG_CMD_BIDI_UNDERFLOW |
  296. ISCSI_FLAG_CMD_BIDI_OVERFLOW))
  297. sc->result = (DID_BAD_TARGET << 16) | rhdr->cmd_status;
  298. out:
  299. debug_scsi("done [sc %lx res %d itt 0x%x]\n",
  300. (long)sc, sc->result, ctask->itt);
  301. conn->scsirsp_pdus_cnt++;
  302. __iscsi_put_ctask(ctask);
  303. }
  304. static void iscsi_tmf_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr)
  305. {
  306. struct iscsi_tm_rsp *tmf = (struct iscsi_tm_rsp *)hdr;
  307. conn->exp_statsn = be32_to_cpu(hdr->statsn) + 1;
  308. conn->tmfrsp_pdus_cnt++;
  309. if (conn->tmf_state != TMF_QUEUED)
  310. return;
  311. if (tmf->response == ISCSI_TMF_RSP_COMPLETE)
  312. conn->tmf_state = TMF_SUCCESS;
  313. else if (tmf->response == ISCSI_TMF_RSP_NO_TASK)
  314. conn->tmf_state = TMF_NOT_FOUND;
  315. else
  316. conn->tmf_state = TMF_FAILED;
  317. wake_up(&conn->ehwait);
  318. }
  319. static int iscsi_handle_reject(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
  320. char *data, int datalen)
  321. {
  322. struct iscsi_reject *reject = (struct iscsi_reject *)hdr;
  323. struct iscsi_hdr rejected_pdu;
  324. uint32_t itt;
  325. conn->exp_statsn = be32_to_cpu(reject->statsn) + 1;
  326. if (reject->reason == ISCSI_REASON_DATA_DIGEST_ERROR) {
  327. if (ntoh24(reject->dlength) > datalen)
  328. return ISCSI_ERR_PROTO;
  329. if (ntoh24(reject->dlength) >= sizeof(struct iscsi_hdr)) {
  330. memcpy(&rejected_pdu, data, sizeof(struct iscsi_hdr));
  331. itt = get_itt(rejected_pdu.itt);
  332. printk(KERN_ERR "itt 0x%x had pdu (op 0x%x) rejected "
  333. "due to DataDigest error.\n", itt,
  334. rejected_pdu.opcode);
  335. }
  336. }
  337. return 0;
  338. }
  339. /**
  340. * __iscsi_complete_pdu - complete pdu
  341. * @conn: iscsi conn
  342. * @hdr: iscsi header
  343. * @data: data buffer
  344. * @datalen: len of data buffer
  345. *
  346. * Completes pdu processing by freeing any resources allocated at
  347. * queuecommand or send generic. session lock must be held and verify
  348. * itt must have been called.
  349. */
  350. int __iscsi_complete_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
  351. char *data, int datalen)
  352. {
  353. struct iscsi_session *session = conn->session;
  354. int opcode = hdr->opcode & ISCSI_OPCODE_MASK, rc = 0;
  355. struct iscsi_cmd_task *ctask;
  356. struct iscsi_mgmt_task *mtask;
  357. uint32_t itt;
  358. if (hdr->itt != RESERVED_ITT)
  359. itt = get_itt(hdr->itt);
  360. else
  361. itt = ~0U;
  362. if (itt < session->cmds_max) {
  363. ctask = session->cmds[itt];
  364. debug_scsi("cmdrsp [op 0x%x cid %d itt 0x%x len %d]\n",
  365. opcode, conn->id, ctask->itt, datalen);
  366. switch(opcode) {
  367. case ISCSI_OP_SCSI_CMD_RSP:
  368. BUG_ON((void*)ctask != ctask->sc->SCp.ptr);
  369. iscsi_scsi_cmd_rsp(conn, hdr, ctask, data,
  370. datalen);
  371. break;
  372. case ISCSI_OP_SCSI_DATA_IN:
  373. BUG_ON((void*)ctask != ctask->sc->SCp.ptr);
  374. if (hdr->flags & ISCSI_FLAG_DATA_STATUS) {
  375. conn->scsirsp_pdus_cnt++;
  376. __iscsi_put_ctask(ctask);
  377. }
  378. break;
  379. case ISCSI_OP_R2T:
  380. /* LLD handles this for now */
  381. break;
  382. default:
  383. rc = ISCSI_ERR_BAD_OPCODE;
  384. break;
  385. }
  386. } else if (itt >= ISCSI_MGMT_ITT_OFFSET &&
  387. itt < ISCSI_MGMT_ITT_OFFSET + session->mgmtpool_max) {
  388. mtask = session->mgmt_cmds[itt - ISCSI_MGMT_ITT_OFFSET];
  389. debug_scsi("immrsp [op 0x%x cid %d itt 0x%x len %d]\n",
  390. opcode, conn->id, mtask->itt, datalen);
  391. iscsi_update_cmdsn(session, (struct iscsi_nopin*)hdr);
  392. switch(opcode) {
  393. case ISCSI_OP_LOGOUT_RSP:
  394. if (datalen) {
  395. rc = ISCSI_ERR_PROTO;
  396. break;
  397. }
  398. conn->exp_statsn = be32_to_cpu(hdr->statsn) + 1;
  399. /* fall through */
  400. case ISCSI_OP_LOGIN_RSP:
  401. case ISCSI_OP_TEXT_RSP:
  402. /*
  403. * login related PDU's exp_statsn is handled in
  404. * userspace
  405. */
  406. if (iscsi_recv_pdu(conn->cls_conn, hdr, data, datalen))
  407. rc = ISCSI_ERR_CONN_FAILED;
  408. list_del_init(&mtask->running);
  409. if (conn->login_mtask != mtask)
  410. __kfifo_put(session->mgmtpool.queue,
  411. (void*)&mtask, sizeof(void*));
  412. break;
  413. case ISCSI_OP_SCSI_TMFUNC_RSP:
  414. if (datalen) {
  415. rc = ISCSI_ERR_PROTO;
  416. break;
  417. }
  418. iscsi_tmf_rsp(conn, hdr);
  419. break;
  420. case ISCSI_OP_NOOP_IN:
  421. if (hdr->ttt != cpu_to_be32(ISCSI_RESERVED_TAG) || datalen) {
  422. rc = ISCSI_ERR_PROTO;
  423. break;
  424. }
  425. conn->exp_statsn = be32_to_cpu(hdr->statsn) + 1;
  426. if (iscsi_recv_pdu(conn->cls_conn, hdr, data, datalen))
  427. rc = ISCSI_ERR_CONN_FAILED;
  428. list_del_init(&mtask->running);
  429. __kfifo_put(session->mgmtpool.queue,
  430. (void*)&mtask, sizeof(void*));
  431. break;
  432. default:
  433. rc = ISCSI_ERR_BAD_OPCODE;
  434. break;
  435. }
  436. } else if (itt == ~0U) {
  437. iscsi_update_cmdsn(session, (struct iscsi_nopin*)hdr);
  438. switch(opcode) {
  439. case ISCSI_OP_NOOP_IN:
  440. if (datalen) {
  441. rc = ISCSI_ERR_PROTO;
  442. break;
  443. }
  444. if (hdr->ttt == cpu_to_be32(ISCSI_RESERVED_TAG))
  445. break;
  446. if (iscsi_recv_pdu(conn->cls_conn, hdr, NULL, 0))
  447. rc = ISCSI_ERR_CONN_FAILED;
  448. break;
  449. case ISCSI_OP_REJECT:
  450. rc = iscsi_handle_reject(conn, hdr, data, datalen);
  451. break;
  452. case ISCSI_OP_ASYNC_EVENT:
  453. conn->exp_statsn = be32_to_cpu(hdr->statsn) + 1;
  454. if (iscsi_recv_pdu(conn->cls_conn, hdr, data, datalen))
  455. rc = ISCSI_ERR_CONN_FAILED;
  456. break;
  457. default:
  458. rc = ISCSI_ERR_BAD_OPCODE;
  459. break;
  460. }
  461. } else
  462. rc = ISCSI_ERR_BAD_ITT;
  463. return rc;
  464. }
  465. EXPORT_SYMBOL_GPL(__iscsi_complete_pdu);
  466. int iscsi_complete_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
  467. char *data, int datalen)
  468. {
  469. int rc;
  470. spin_lock(&conn->session->lock);
  471. rc = __iscsi_complete_pdu(conn, hdr, data, datalen);
  472. spin_unlock(&conn->session->lock);
  473. return rc;
  474. }
  475. EXPORT_SYMBOL_GPL(iscsi_complete_pdu);
  476. /* verify itt (itt encoding: age+cid+itt) */
  477. int iscsi_verify_itt(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
  478. uint32_t *ret_itt)
  479. {
  480. struct iscsi_session *session = conn->session;
  481. struct iscsi_cmd_task *ctask;
  482. uint32_t itt;
  483. if (hdr->itt != RESERVED_ITT) {
  484. if (((__force u32)hdr->itt & ISCSI_AGE_MASK) !=
  485. (session->age << ISCSI_AGE_SHIFT)) {
  486. printk(KERN_ERR "iscsi: received itt %x expected "
  487. "session age (%x)\n", (__force u32)hdr->itt,
  488. session->age & ISCSI_AGE_MASK);
  489. return ISCSI_ERR_BAD_ITT;
  490. }
  491. if (((__force u32)hdr->itt & ISCSI_CID_MASK) !=
  492. (conn->id << ISCSI_CID_SHIFT)) {
  493. printk(KERN_ERR "iscsi: received itt %x, expected "
  494. "CID (%x)\n", (__force u32)hdr->itt, conn->id);
  495. return ISCSI_ERR_BAD_ITT;
  496. }
  497. itt = get_itt(hdr->itt);
  498. } else
  499. itt = ~0U;
  500. if (itt < session->cmds_max) {
  501. ctask = session->cmds[itt];
  502. if (!ctask->sc) {
  503. printk(KERN_INFO "iscsi: dropping ctask with "
  504. "itt 0x%x\n", ctask->itt);
  505. /* force drop */
  506. return ISCSI_ERR_NO_SCSI_CMD;
  507. }
  508. if (ctask->sc->SCp.phase != session->age) {
  509. printk(KERN_ERR "iscsi: ctask's session age %d, "
  510. "expected %d\n", ctask->sc->SCp.phase,
  511. session->age);
  512. return ISCSI_ERR_SESSION_FAILED;
  513. }
  514. }
  515. *ret_itt = itt;
  516. return 0;
  517. }
  518. EXPORT_SYMBOL_GPL(iscsi_verify_itt);
  519. void iscsi_conn_failure(struct iscsi_conn *conn, enum iscsi_err err)
  520. {
  521. struct iscsi_session *session = conn->session;
  522. unsigned long flags;
  523. spin_lock_irqsave(&session->lock, flags);
  524. if (session->state == ISCSI_STATE_FAILED) {
  525. spin_unlock_irqrestore(&session->lock, flags);
  526. return;
  527. }
  528. if (conn->stop_stage == 0)
  529. session->state = ISCSI_STATE_FAILED;
  530. spin_unlock_irqrestore(&session->lock, flags);
  531. set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx);
  532. set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_rx);
  533. iscsi_conn_error(conn->cls_conn, err);
  534. }
  535. EXPORT_SYMBOL_GPL(iscsi_conn_failure);
  536. static void iscsi_prep_mtask(struct iscsi_conn *conn,
  537. struct iscsi_mgmt_task *mtask)
  538. {
  539. struct iscsi_session *session = conn->session;
  540. struct iscsi_hdr *hdr = mtask->hdr;
  541. struct iscsi_nopout *nop = (struct iscsi_nopout *)hdr;
  542. if (hdr->opcode != (ISCSI_OP_LOGIN | ISCSI_OP_IMMEDIATE) &&
  543. hdr->opcode != (ISCSI_OP_TEXT | ISCSI_OP_IMMEDIATE))
  544. nop->exp_statsn = cpu_to_be32(conn->exp_statsn);
  545. /*
  546. * pre-format CmdSN for outgoing PDU.
  547. */
  548. nop->cmdsn = cpu_to_be32(session->cmdsn);
  549. if (hdr->itt != RESERVED_ITT) {
  550. hdr->itt = build_itt(mtask->itt, conn->id, session->age);
  551. /*
  552. * TODO: We always use immediate, so we never hit this.
  553. * If we start to send tmfs or nops as non-immediate then
  554. * we should start checking the cmdsn numbers for mgmt tasks.
  555. */
  556. if (conn->c_stage == ISCSI_CONN_STARTED &&
  557. !(hdr->opcode & ISCSI_OP_IMMEDIATE)) {
  558. session->queued_cmdsn++;
  559. session->cmdsn++;
  560. }
  561. }
  562. if (session->tt->init_mgmt_task)
  563. session->tt->init_mgmt_task(conn, mtask);
  564. debug_scsi("mgmtpdu [op 0x%x hdr->itt 0x%x datalen %d]\n",
  565. hdr->opcode & ISCSI_OPCODE_MASK, hdr->itt,
  566. mtask->data_count);
  567. }
  568. static int iscsi_xmit_mtask(struct iscsi_conn *conn)
  569. {
  570. struct iscsi_hdr *hdr = conn->mtask->hdr;
  571. int rc, was_logout = 0;
  572. spin_unlock_bh(&conn->session->lock);
  573. if ((hdr->opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGOUT) {
  574. conn->session->state = ISCSI_STATE_IN_RECOVERY;
  575. iscsi_block_session(session_to_cls(conn->session));
  576. was_logout = 1;
  577. }
  578. rc = conn->session->tt->xmit_mgmt_task(conn, conn->mtask);
  579. spin_lock_bh(&conn->session->lock);
  580. if (rc)
  581. return rc;
  582. /* done with this in-progress mtask */
  583. conn->mtask = NULL;
  584. if (was_logout) {
  585. set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx);
  586. return -ENODATA;
  587. }
  588. return 0;
  589. }
  590. static int iscsi_check_cmdsn_window_closed(struct iscsi_conn *conn)
  591. {
  592. struct iscsi_session *session = conn->session;
  593. /*
  594. * Check for iSCSI window and take care of CmdSN wrap-around
  595. */
  596. if (!iscsi_sna_lte(session->queued_cmdsn, session->max_cmdsn)) {
  597. debug_scsi("iSCSI CmdSN closed. ExpCmdSn %u MaxCmdSN %u "
  598. "CmdSN %u/%u\n", session->exp_cmdsn,
  599. session->max_cmdsn, session->cmdsn,
  600. session->queued_cmdsn);
  601. return -ENOSPC;
  602. }
  603. return 0;
  604. }
  605. static int iscsi_xmit_ctask(struct iscsi_conn *conn)
  606. {
  607. struct iscsi_cmd_task *ctask = conn->ctask;
  608. int rc;
  609. __iscsi_get_ctask(ctask);
  610. spin_unlock_bh(&conn->session->lock);
  611. rc = conn->session->tt->xmit_cmd_task(conn, ctask);
  612. spin_lock_bh(&conn->session->lock);
  613. __iscsi_put_ctask(ctask);
  614. if (!rc)
  615. /* done with this ctask */
  616. conn->ctask = NULL;
  617. return rc;
  618. }
  619. /**
  620. * iscsi_requeue_ctask - requeue ctask to run from session workqueue
  621. * @ctask: ctask to requeue
  622. *
  623. * LLDs that need to run a ctask from the session workqueue should call
  624. * this. The session lock must be held.
  625. */
  626. void iscsi_requeue_ctask(struct iscsi_cmd_task *ctask)
  627. {
  628. struct iscsi_conn *conn = ctask->conn;
  629. list_move_tail(&ctask->running, &conn->requeue);
  630. scsi_queue_work(conn->session->host, &conn->xmitwork);
  631. }
  632. EXPORT_SYMBOL_GPL(iscsi_requeue_ctask);
  633. /**
  634. * iscsi_data_xmit - xmit any command into the scheduled connection
  635. * @conn: iscsi connection
  636. *
  637. * Notes:
  638. * The function can return -EAGAIN in which case the caller must
  639. * re-schedule it again later or recover. '0' return code means
  640. * successful xmit.
  641. **/
  642. static int iscsi_data_xmit(struct iscsi_conn *conn)
  643. {
  644. int rc = 0;
  645. spin_lock_bh(&conn->session->lock);
  646. if (unlikely(conn->suspend_tx)) {
  647. debug_scsi("conn %d Tx suspended!\n", conn->id);
  648. spin_unlock_bh(&conn->session->lock);
  649. return -ENODATA;
  650. }
  651. if (conn->ctask) {
  652. rc = iscsi_xmit_ctask(conn);
  653. if (rc)
  654. goto again;
  655. }
  656. if (conn->mtask) {
  657. rc = iscsi_xmit_mtask(conn);
  658. if (rc)
  659. goto again;
  660. }
  661. /*
  662. * process mgmt pdus like nops before commands since we should
  663. * only have one nop-out as a ping from us and targets should not
  664. * overflow us with nop-ins
  665. */
  666. check_mgmt:
  667. while (!list_empty(&conn->mgmtqueue)) {
  668. conn->mtask = list_entry(conn->mgmtqueue.next,
  669. struct iscsi_mgmt_task, running);
  670. iscsi_prep_mtask(conn, conn->mtask);
  671. list_move_tail(conn->mgmtqueue.next, &conn->mgmt_run_list);
  672. rc = iscsi_xmit_mtask(conn);
  673. if (rc)
  674. goto again;
  675. }
  676. /* process pending command queue */
  677. while (!list_empty(&conn->xmitqueue)) {
  678. if (conn->tmf_state == TMF_QUEUED)
  679. break;
  680. conn->ctask = list_entry(conn->xmitqueue.next,
  681. struct iscsi_cmd_task, running);
  682. if (iscsi_prep_scsi_cmd_pdu(conn->ctask)) {
  683. fail_command(conn, conn->ctask, DID_ABORT << 16);
  684. continue;
  685. }
  686. conn->session->tt->init_cmd_task(conn->ctask);
  687. conn->ctask->state = ISCSI_TASK_RUNNING;
  688. list_move_tail(conn->xmitqueue.next, &conn->run_list);
  689. rc = iscsi_xmit_ctask(conn);
  690. if (rc)
  691. goto again;
  692. /*
  693. * we could continuously get new ctask requests so
  694. * we need to check the mgmt queue for nops that need to
  695. * be sent to aviod starvation
  696. */
  697. if (!list_empty(&conn->mgmtqueue))
  698. goto check_mgmt;
  699. }
  700. while (!list_empty(&conn->requeue)) {
  701. if (conn->session->fast_abort && conn->tmf_state != TMF_INITIAL)
  702. break;
  703. conn->ctask = list_entry(conn->requeue.next,
  704. struct iscsi_cmd_task, running);
  705. conn->ctask->state = ISCSI_TASK_RUNNING;
  706. list_move_tail(conn->requeue.next, &conn->run_list);
  707. rc = iscsi_xmit_ctask(conn);
  708. if (rc)
  709. goto again;
  710. if (!list_empty(&conn->mgmtqueue))
  711. goto check_mgmt;
  712. }
  713. spin_unlock_bh(&conn->session->lock);
  714. return -ENODATA;
  715. again:
  716. if (unlikely(conn->suspend_tx))
  717. rc = -ENODATA;
  718. spin_unlock_bh(&conn->session->lock);
  719. return rc;
  720. }
  721. static void iscsi_xmitworker(struct work_struct *work)
  722. {
  723. struct iscsi_conn *conn =
  724. container_of(work, struct iscsi_conn, xmitwork);
  725. int rc;
  726. /*
  727. * serialize Xmit worker on a per-connection basis.
  728. */
  729. do {
  730. rc = iscsi_data_xmit(conn);
  731. } while (rc >= 0 || rc == -EAGAIN);
  732. }
  733. enum {
  734. FAILURE_BAD_HOST = 1,
  735. FAILURE_SESSION_FAILED,
  736. FAILURE_SESSION_FREED,
  737. FAILURE_WINDOW_CLOSED,
  738. FAILURE_OOM,
  739. FAILURE_SESSION_TERMINATE,
  740. FAILURE_SESSION_IN_RECOVERY,
  741. FAILURE_SESSION_RECOVERY_TIMEOUT,
  742. };
  743. int iscsi_queuecommand(struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *))
  744. {
  745. struct Scsi_Host *host;
  746. int reason = 0;
  747. struct iscsi_session *session;
  748. struct iscsi_conn *conn;
  749. struct iscsi_cmd_task *ctask = NULL;
  750. sc->scsi_done = done;
  751. sc->result = 0;
  752. sc->SCp.ptr = NULL;
  753. host = sc->device->host;
  754. session = iscsi_hostdata(host->hostdata);
  755. spin_lock(&session->lock);
  756. /*
  757. * ISCSI_STATE_FAILED is a temp. state. The recovery
  758. * code will decide what is best to do with command queued
  759. * during this time
  760. */
  761. if (session->state != ISCSI_STATE_LOGGED_IN &&
  762. session->state != ISCSI_STATE_FAILED) {
  763. /*
  764. * to handle the race between when we set the recovery state
  765. * and block the session we requeue here (commands could
  766. * be entering our queuecommand while a block is starting
  767. * up because the block code is not locked)
  768. */
  769. if (session->state == ISCSI_STATE_IN_RECOVERY) {
  770. reason = FAILURE_SESSION_IN_RECOVERY;
  771. goto reject;
  772. }
  773. if (session->state == ISCSI_STATE_RECOVERY_FAILED)
  774. reason = FAILURE_SESSION_RECOVERY_TIMEOUT;
  775. else if (session->state == ISCSI_STATE_TERMINATE)
  776. reason = FAILURE_SESSION_TERMINATE;
  777. else
  778. reason = FAILURE_SESSION_FREED;
  779. goto fault;
  780. }
  781. conn = session->leadconn;
  782. if (!conn) {
  783. reason = FAILURE_SESSION_FREED;
  784. goto fault;
  785. }
  786. if (iscsi_check_cmdsn_window_closed(conn)) {
  787. reason = FAILURE_WINDOW_CLOSED;
  788. goto reject;
  789. }
  790. if (!__kfifo_get(session->cmdpool.queue, (void*)&ctask,
  791. sizeof(void*))) {
  792. reason = FAILURE_OOM;
  793. goto reject;
  794. }
  795. session->queued_cmdsn++;
  796. sc->SCp.phase = session->age;
  797. sc->SCp.ptr = (char *)ctask;
  798. atomic_set(&ctask->refcount, 1);
  799. ctask->state = ISCSI_TASK_PENDING;
  800. ctask->conn = conn;
  801. ctask->sc = sc;
  802. INIT_LIST_HEAD(&ctask->running);
  803. list_add_tail(&ctask->running, &conn->xmitqueue);
  804. spin_unlock(&session->lock);
  805. scsi_queue_work(host, &conn->xmitwork);
  806. return 0;
  807. reject:
  808. spin_unlock(&session->lock);
  809. debug_scsi("cmd 0x%x rejected (%d)\n", sc->cmnd[0], reason);
  810. return SCSI_MLQUEUE_HOST_BUSY;
  811. fault:
  812. spin_unlock(&session->lock);
  813. printk(KERN_ERR "iscsi: cmd 0x%x is not queued (%d)\n",
  814. sc->cmnd[0], reason);
  815. sc->result = (DID_NO_CONNECT << 16);
  816. scsi_set_resid(sc, scsi_bufflen(sc));
  817. sc->scsi_done(sc);
  818. return 0;
  819. }
  820. EXPORT_SYMBOL_GPL(iscsi_queuecommand);
  821. int iscsi_change_queue_depth(struct scsi_device *sdev, int depth)
  822. {
  823. if (depth > ISCSI_MAX_CMD_PER_LUN)
  824. depth = ISCSI_MAX_CMD_PER_LUN;
  825. scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth);
  826. return sdev->queue_depth;
  827. }
  828. EXPORT_SYMBOL_GPL(iscsi_change_queue_depth);
  829. static struct iscsi_mgmt_task *
  830. __iscsi_conn_send_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
  831. char *data, uint32_t data_size)
  832. {
  833. struct iscsi_session *session = conn->session;
  834. struct iscsi_mgmt_task *mtask;
  835. if (session->state == ISCSI_STATE_TERMINATE)
  836. return NULL;
  837. if (hdr->opcode == (ISCSI_OP_LOGIN | ISCSI_OP_IMMEDIATE) ||
  838. hdr->opcode == (ISCSI_OP_TEXT | ISCSI_OP_IMMEDIATE))
  839. /*
  840. * Login and Text are sent serially, in
  841. * request-followed-by-response sequence.
  842. * Same mtask can be used. Same ITT must be used.
  843. * Note that login_mtask is preallocated at conn_create().
  844. */
  845. mtask = conn->login_mtask;
  846. else {
  847. BUG_ON(conn->c_stage == ISCSI_CONN_INITIAL_STAGE);
  848. BUG_ON(conn->c_stage == ISCSI_CONN_STOPPED);
  849. if (!__kfifo_get(session->mgmtpool.queue,
  850. (void*)&mtask, sizeof(void*)))
  851. return NULL;
  852. }
  853. if (data_size) {
  854. memcpy(mtask->data, data, data_size);
  855. mtask->data_count = data_size;
  856. } else
  857. mtask->data_count = 0;
  858. memcpy(mtask->hdr, hdr, sizeof(struct iscsi_hdr));
  859. INIT_LIST_HEAD(&mtask->running);
  860. list_add_tail(&mtask->running, &conn->mgmtqueue);
  861. return mtask;
  862. }
  863. int iscsi_conn_send_pdu(struct iscsi_cls_conn *cls_conn, struct iscsi_hdr *hdr,
  864. char *data, uint32_t data_size)
  865. {
  866. struct iscsi_conn *conn = cls_conn->dd_data;
  867. struct iscsi_session *session = conn->session;
  868. int err = 0;
  869. spin_lock_bh(&session->lock);
  870. if (!__iscsi_conn_send_pdu(conn, hdr, data, data_size))
  871. err = -EPERM;
  872. spin_unlock_bh(&session->lock);
  873. scsi_queue_work(session->host, &conn->xmitwork);
  874. return err;
  875. }
  876. EXPORT_SYMBOL_GPL(iscsi_conn_send_pdu);
  877. void iscsi_session_recovery_timedout(struct iscsi_cls_session *cls_session)
  878. {
  879. struct iscsi_session *session = class_to_transport_session(cls_session);
  880. spin_lock_bh(&session->lock);
  881. if (session->state != ISCSI_STATE_LOGGED_IN) {
  882. session->state = ISCSI_STATE_RECOVERY_FAILED;
  883. if (session->leadconn)
  884. wake_up(&session->leadconn->ehwait);
  885. }
  886. spin_unlock_bh(&session->lock);
  887. }
  888. EXPORT_SYMBOL_GPL(iscsi_session_recovery_timedout);
  889. int iscsi_eh_host_reset(struct scsi_cmnd *sc)
  890. {
  891. struct Scsi_Host *host = sc->device->host;
  892. struct iscsi_session *session = iscsi_hostdata(host->hostdata);
  893. struct iscsi_conn *conn = session->leadconn;
  894. spin_lock_bh(&session->lock);
  895. if (session->state == ISCSI_STATE_TERMINATE) {
  896. failed:
  897. debug_scsi("failing host reset: session terminated "
  898. "[CID %d age %d]\n", conn->id, session->age);
  899. spin_unlock_bh(&session->lock);
  900. return FAILED;
  901. }
  902. spin_unlock_bh(&session->lock);
  903. /*
  904. * we drop the lock here but the leadconn cannot be destoyed while
  905. * we are in the scsi eh
  906. */
  907. iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
  908. debug_scsi("iscsi_eh_host_reset wait for relogin\n");
  909. wait_event_interruptible(conn->ehwait,
  910. session->state == ISCSI_STATE_TERMINATE ||
  911. session->state == ISCSI_STATE_LOGGED_IN ||
  912. session->state == ISCSI_STATE_RECOVERY_FAILED);
  913. if (signal_pending(current))
  914. flush_signals(current);
  915. spin_lock_bh(&session->lock);
  916. if (session->state == ISCSI_STATE_LOGGED_IN)
  917. printk(KERN_INFO "iscsi: host reset succeeded\n");
  918. else
  919. goto failed;
  920. spin_unlock_bh(&session->lock);
  921. return SUCCESS;
  922. }
  923. EXPORT_SYMBOL_GPL(iscsi_eh_host_reset);
  924. static void iscsi_tmf_timedout(unsigned long data)
  925. {
  926. struct iscsi_conn *conn = (struct iscsi_conn *)data;
  927. struct iscsi_session *session = conn->session;
  928. spin_lock(&session->lock);
  929. if (conn->tmf_state == TMF_QUEUED) {
  930. conn->tmf_state = TMF_TIMEDOUT;
  931. debug_scsi("tmf timedout\n");
  932. /* unblock eh_abort() */
  933. wake_up(&conn->ehwait);
  934. }
  935. spin_unlock(&session->lock);
  936. }
  937. static int iscsi_exec_task_mgmt_fn(struct iscsi_conn *conn,
  938. struct iscsi_tm *hdr, int age)
  939. {
  940. struct iscsi_session *session = conn->session;
  941. struct iscsi_mgmt_task *mtask;
  942. mtask = __iscsi_conn_send_pdu(conn, (struct iscsi_hdr *)hdr,
  943. NULL, 0);
  944. if (!mtask) {
  945. spin_unlock_bh(&session->lock);
  946. iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
  947. spin_lock_bh(&session->lock);
  948. debug_scsi("tmf exec failure\n");
  949. return -EPERM;
  950. }
  951. conn->tmfcmd_pdus_cnt++;
  952. conn->tmf_timer.expires = 30 * HZ + jiffies;
  953. conn->tmf_timer.function = iscsi_tmf_timedout;
  954. conn->tmf_timer.data = (unsigned long)conn;
  955. add_timer(&conn->tmf_timer);
  956. debug_scsi("tmf set timeout\n");
  957. spin_unlock_bh(&session->lock);
  958. mutex_unlock(&session->eh_mutex);
  959. scsi_queue_work(session->host, &conn->xmitwork);
  960. /*
  961. * block eh thread until:
  962. *
  963. * 1) tmf response
  964. * 2) tmf timeout
  965. * 3) session is terminated or restarted or userspace has
  966. * given up on recovery
  967. */
  968. wait_event_interruptible(conn->ehwait, age != session->age ||
  969. session->state != ISCSI_STATE_LOGGED_IN ||
  970. conn->tmf_state != TMF_QUEUED);
  971. if (signal_pending(current))
  972. flush_signals(current);
  973. del_timer_sync(&conn->tmf_timer);
  974. mutex_lock(&session->eh_mutex);
  975. spin_lock_bh(&session->lock);
  976. /* if the session drops it will clean up the mtask */
  977. if (age != session->age ||
  978. session->state != ISCSI_STATE_LOGGED_IN)
  979. return -ENOTCONN;
  980. if (!list_empty(&mtask->running)) {
  981. list_del_init(&mtask->running);
  982. __kfifo_put(session->mgmtpool.queue, (void*)&mtask,
  983. sizeof(void*));
  984. }
  985. return 0;
  986. }
  987. /*
  988. * session lock must be held
  989. */
  990. static void fail_command(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask,
  991. int err)
  992. {
  993. struct scsi_cmnd *sc;
  994. sc = ctask->sc;
  995. if (!sc)
  996. return;
  997. if (ctask->state == ISCSI_TASK_PENDING)
  998. /*
  999. * cmd never made it to the xmit thread, so we should not count
  1000. * the cmd in the sequencing
  1001. */
  1002. conn->session->queued_cmdsn--;
  1003. else
  1004. conn->session->tt->cleanup_cmd_task(conn, ctask);
  1005. sc->result = err;
  1006. scsi_set_resid(sc, scsi_bufflen(sc));
  1007. if (conn->ctask == ctask)
  1008. conn->ctask = NULL;
  1009. /* release ref from queuecommand */
  1010. __iscsi_put_ctask(ctask);
  1011. }
  1012. /*
  1013. * Fail commands. session lock held and recv side suspended and xmit
  1014. * thread flushed
  1015. */
  1016. static void fail_all_commands(struct iscsi_conn *conn, unsigned lun)
  1017. {
  1018. struct iscsi_cmd_task *ctask, *tmp;
  1019. if (conn->ctask && (conn->ctask->sc->device->lun == lun || lun == -1))
  1020. conn->ctask = NULL;
  1021. /* flush pending */
  1022. list_for_each_entry_safe(ctask, tmp, &conn->xmitqueue, running) {
  1023. if (lun == ctask->sc->device->lun || lun == -1) {
  1024. debug_scsi("failing pending sc %p itt 0x%x\n",
  1025. ctask->sc, ctask->itt);
  1026. fail_command(conn, ctask, DID_BUS_BUSY << 16);
  1027. }
  1028. }
  1029. list_for_each_entry_safe(ctask, tmp, &conn->requeue, running) {
  1030. if (lun == ctask->sc->device->lun || lun == -1) {
  1031. debug_scsi("failing requeued sc %p itt 0x%x\n",
  1032. ctask->sc, ctask->itt);
  1033. fail_command(conn, ctask, DID_BUS_BUSY << 16);
  1034. }
  1035. }
  1036. /* fail all other running */
  1037. list_for_each_entry_safe(ctask, tmp, &conn->run_list, running) {
  1038. if (lun == ctask->sc->device->lun || lun == -1) {
  1039. debug_scsi("failing in progress sc %p itt 0x%x\n",
  1040. ctask->sc, ctask->itt);
  1041. fail_command(conn, ctask, DID_BUS_BUSY << 16);
  1042. }
  1043. }
  1044. }
  1045. static void iscsi_suspend_tx(struct iscsi_conn *conn)
  1046. {
  1047. set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx);
  1048. scsi_flush_work(conn->session->host);
  1049. }
  1050. static void iscsi_start_tx(struct iscsi_conn *conn)
  1051. {
  1052. clear_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx);
  1053. scsi_queue_work(conn->session->host, &conn->xmitwork);
  1054. }
  1055. static void iscsi_prep_abort_task_pdu(struct iscsi_cmd_task *ctask,
  1056. struct iscsi_tm *hdr)
  1057. {
  1058. memset(hdr, 0, sizeof(*hdr));
  1059. hdr->opcode = ISCSI_OP_SCSI_TMFUNC | ISCSI_OP_IMMEDIATE;
  1060. hdr->flags = ISCSI_TM_FUNC_ABORT_TASK & ISCSI_FLAG_TM_FUNC_MASK;
  1061. hdr->flags |= ISCSI_FLAG_CMD_FINAL;
  1062. memcpy(hdr->lun, ctask->hdr->lun, sizeof(hdr->lun));
  1063. hdr->rtt = ctask->hdr->itt;
  1064. hdr->refcmdsn = ctask->hdr->cmdsn;
  1065. }
  1066. int iscsi_eh_abort(struct scsi_cmnd *sc)
  1067. {
  1068. struct Scsi_Host *host = sc->device->host;
  1069. struct iscsi_session *session = iscsi_hostdata(host->hostdata);
  1070. struct iscsi_conn *conn;
  1071. struct iscsi_cmd_task *ctask;
  1072. struct iscsi_tm *hdr;
  1073. int rc, age;
  1074. mutex_lock(&session->eh_mutex);
  1075. spin_lock_bh(&session->lock);
  1076. /*
  1077. * if session was ISCSI_STATE_IN_RECOVERY then we may not have
  1078. * got the command.
  1079. */
  1080. if (!sc->SCp.ptr) {
  1081. debug_scsi("sc never reached iscsi layer or it completed.\n");
  1082. spin_unlock_bh(&session->lock);
  1083. mutex_unlock(&session->eh_mutex);
  1084. return SUCCESS;
  1085. }
  1086. /*
  1087. * If we are not logged in or we have started a new session
  1088. * then let the host reset code handle this
  1089. */
  1090. if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN ||
  1091. sc->SCp.phase != session->age) {
  1092. spin_unlock_bh(&session->lock);
  1093. mutex_unlock(&session->eh_mutex);
  1094. return FAILED;
  1095. }
  1096. conn = session->leadconn;
  1097. conn->eh_abort_cnt++;
  1098. age = session->age;
  1099. ctask = (struct iscsi_cmd_task *)sc->SCp.ptr;
  1100. debug_scsi("aborting [sc %p itt 0x%x]\n", sc, ctask->itt);
  1101. /* ctask completed before time out */
  1102. if (!ctask->sc) {
  1103. debug_scsi("sc completed while abort in progress\n");
  1104. goto success;
  1105. }
  1106. if (ctask->state == ISCSI_TASK_PENDING) {
  1107. fail_command(conn, ctask, DID_ABORT << 16);
  1108. goto success;
  1109. }
  1110. /* only have one tmf outstanding at a time */
  1111. if (conn->tmf_state != TMF_INITIAL)
  1112. goto failed;
  1113. conn->tmf_state = TMF_QUEUED;
  1114. hdr = &conn->tmhdr;
  1115. iscsi_prep_abort_task_pdu(ctask, hdr);
  1116. if (iscsi_exec_task_mgmt_fn(conn, hdr, age)) {
  1117. rc = FAILED;
  1118. goto failed;
  1119. }
  1120. switch (conn->tmf_state) {
  1121. case TMF_SUCCESS:
  1122. spin_unlock_bh(&session->lock);
  1123. iscsi_suspend_tx(conn);
  1124. /*
  1125. * clean up task if aborted. grab the recv lock as a writer
  1126. */
  1127. write_lock_bh(conn->recv_lock);
  1128. spin_lock(&session->lock);
  1129. fail_command(conn, ctask, DID_ABORT << 16);
  1130. conn->tmf_state = TMF_INITIAL;
  1131. spin_unlock(&session->lock);
  1132. write_unlock_bh(conn->recv_lock);
  1133. iscsi_start_tx(conn);
  1134. goto success_unlocked;
  1135. case TMF_TIMEDOUT:
  1136. spin_unlock_bh(&session->lock);
  1137. iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
  1138. goto failed_unlocked;
  1139. case TMF_NOT_FOUND:
  1140. if (!sc->SCp.ptr) {
  1141. conn->tmf_state = TMF_INITIAL;
  1142. /* ctask completed before tmf abort response */
  1143. debug_scsi("sc completed while abort in progress\n");
  1144. goto success;
  1145. }
  1146. /* fall through */
  1147. default:
  1148. conn->tmf_state = TMF_INITIAL;
  1149. goto failed;
  1150. }
  1151. success:
  1152. spin_unlock_bh(&session->lock);
  1153. success_unlocked:
  1154. debug_scsi("abort success [sc %lx itt 0x%x]\n", (long)sc, ctask->itt);
  1155. mutex_unlock(&session->eh_mutex);
  1156. return SUCCESS;
  1157. failed:
  1158. spin_unlock_bh(&session->lock);
  1159. failed_unlocked:
  1160. debug_scsi("abort failed [sc %p itt 0x%x]\n", sc,
  1161. ctask ? ctask->itt : 0);
  1162. mutex_unlock(&session->eh_mutex);
  1163. return FAILED;
  1164. }
  1165. EXPORT_SYMBOL_GPL(iscsi_eh_abort);
  1166. static void iscsi_prep_lun_reset_pdu(struct scsi_cmnd *sc, struct iscsi_tm *hdr)
  1167. {
  1168. memset(hdr, 0, sizeof(*hdr));
  1169. hdr->opcode = ISCSI_OP_SCSI_TMFUNC | ISCSI_OP_IMMEDIATE;
  1170. hdr->flags = ISCSI_TM_FUNC_LOGICAL_UNIT_RESET & ISCSI_FLAG_TM_FUNC_MASK;
  1171. hdr->flags |= ISCSI_FLAG_CMD_FINAL;
  1172. int_to_scsilun(sc->device->lun, (struct scsi_lun *)hdr->lun);
  1173. hdr->rtt = ISCSI_RESERVED_TAG;
  1174. }
  1175. int iscsi_eh_device_reset(struct scsi_cmnd *sc)
  1176. {
  1177. struct Scsi_Host *host = sc->device->host;
  1178. struct iscsi_session *session = iscsi_hostdata(host->hostdata);
  1179. struct iscsi_conn *conn;
  1180. struct iscsi_tm *hdr;
  1181. int rc = FAILED;
  1182. debug_scsi("LU Reset [sc %p lun %u]\n", sc, sc->device->lun);
  1183. mutex_lock(&session->eh_mutex);
  1184. spin_lock_bh(&session->lock);
  1185. /*
  1186. * Just check if we are not logged in. We cannot check for
  1187. * the phase because the reset could come from a ioctl.
  1188. */
  1189. if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN)
  1190. goto unlock;
  1191. conn = session->leadconn;
  1192. /* only have one tmf outstanding at a time */
  1193. if (conn->tmf_state != TMF_INITIAL)
  1194. goto unlock;
  1195. conn->tmf_state = TMF_QUEUED;
  1196. hdr = &conn->tmhdr;
  1197. iscsi_prep_lun_reset_pdu(sc, hdr);
  1198. if (iscsi_exec_task_mgmt_fn(conn, hdr, session->age)) {
  1199. rc = FAILED;
  1200. goto unlock;
  1201. }
  1202. switch (conn->tmf_state) {
  1203. case TMF_SUCCESS:
  1204. break;
  1205. case TMF_TIMEDOUT:
  1206. spin_unlock_bh(&session->lock);
  1207. iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
  1208. goto done;
  1209. default:
  1210. conn->tmf_state = TMF_INITIAL;
  1211. goto unlock;
  1212. }
  1213. rc = SUCCESS;
  1214. spin_unlock_bh(&session->lock);
  1215. iscsi_suspend_tx(conn);
  1216. /* need to grab the recv lock then session lock */
  1217. write_lock_bh(conn->recv_lock);
  1218. spin_lock(&session->lock);
  1219. fail_all_commands(conn, sc->device->lun);
  1220. conn->tmf_state = TMF_INITIAL;
  1221. spin_unlock(&session->lock);
  1222. write_unlock_bh(conn->recv_lock);
  1223. iscsi_start_tx(conn);
  1224. goto done;
  1225. unlock:
  1226. spin_unlock_bh(&session->lock);
  1227. done:
  1228. debug_scsi("iscsi_eh_device_reset %s\n",
  1229. rc == SUCCESS ? "SUCCESS" : "FAILED");
  1230. mutex_unlock(&session->eh_mutex);
  1231. return rc;
  1232. }
  1233. EXPORT_SYMBOL_GPL(iscsi_eh_device_reset);
  1234. int
  1235. iscsi_pool_init(struct iscsi_queue *q, int max, void ***items, int item_size)
  1236. {
  1237. int i;
  1238. *items = kmalloc(max * sizeof(void*), GFP_KERNEL);
  1239. if (*items == NULL)
  1240. return -ENOMEM;
  1241. q->max = max;
  1242. q->pool = kmalloc(max * sizeof(void*), GFP_KERNEL);
  1243. if (q->pool == NULL) {
  1244. kfree(*items);
  1245. return -ENOMEM;
  1246. }
  1247. q->queue = kfifo_init((void*)q->pool, max * sizeof(void*),
  1248. GFP_KERNEL, NULL);
  1249. if (q->queue == ERR_PTR(-ENOMEM)) {
  1250. kfree(q->pool);
  1251. kfree(*items);
  1252. return -ENOMEM;
  1253. }
  1254. for (i = 0; i < max; i++) {
  1255. q->pool[i] = kmalloc(item_size, GFP_KERNEL);
  1256. if (q->pool[i] == NULL) {
  1257. int j;
  1258. for (j = 0; j < i; j++)
  1259. kfree(q->pool[j]);
  1260. kfifo_free(q->queue);
  1261. kfree(q->pool);
  1262. kfree(*items);
  1263. return -ENOMEM;
  1264. }
  1265. memset(q->pool[i], 0, item_size);
  1266. (*items)[i] = q->pool[i];
  1267. __kfifo_put(q->queue, (void*)&q->pool[i], sizeof(void*));
  1268. }
  1269. return 0;
  1270. }
  1271. EXPORT_SYMBOL_GPL(iscsi_pool_init);
  1272. void iscsi_pool_free(struct iscsi_queue *q, void **items)
  1273. {
  1274. int i;
  1275. for (i = 0; i < q->max; i++)
  1276. kfree(items[i]);
  1277. kfree(q->pool);
  1278. kfree(items);
  1279. }
  1280. EXPORT_SYMBOL_GPL(iscsi_pool_free);
  1281. /*
  1282. * iSCSI Session's hostdata organization:
  1283. *
  1284. * *------------------* <== hostdata_session(host->hostdata)
  1285. * | ptr to class sess|
  1286. * |------------------| <== iscsi_hostdata(host->hostdata)
  1287. * | iscsi_session |
  1288. * *------------------*
  1289. */
  1290. #define hostdata_privsize(_sz) (sizeof(unsigned long) + _sz + \
  1291. _sz % sizeof(unsigned long))
  1292. #define hostdata_session(_hostdata) (iscsi_ptr(*(unsigned long *)_hostdata))
  1293. /**
  1294. * iscsi_session_setup - create iscsi cls session and host and session
  1295. * @scsit: scsi transport template
  1296. * @iscsit: iscsi transport template
  1297. * @cmds_max: scsi host can queue
  1298. * @qdepth: scsi host cmds per lun
  1299. * @cmd_task_size: LLD ctask private data size
  1300. * @mgmt_task_size: LLD mtask private data size
  1301. * @initial_cmdsn: initial CmdSN
  1302. * @hostno: host no allocated
  1303. *
  1304. * This can be used by software iscsi_transports that allocate
  1305. * a session per scsi host.
  1306. **/
  1307. struct iscsi_cls_session *
  1308. iscsi_session_setup(struct iscsi_transport *iscsit,
  1309. struct scsi_transport_template *scsit,
  1310. uint16_t cmds_max, uint16_t qdepth,
  1311. int cmd_task_size, int mgmt_task_size,
  1312. uint32_t initial_cmdsn, uint32_t *hostno)
  1313. {
  1314. struct Scsi_Host *shost;
  1315. struct iscsi_session *session;
  1316. struct iscsi_cls_session *cls_session;
  1317. int cmd_i;
  1318. if (qdepth > ISCSI_MAX_CMD_PER_LUN || qdepth < 1) {
  1319. if (qdepth != 0)
  1320. printk(KERN_ERR "iscsi: invalid queue depth of %d. "
  1321. "Queue depth must be between 1 and %d.\n",
  1322. qdepth, ISCSI_MAX_CMD_PER_LUN);
  1323. qdepth = ISCSI_DEF_CMD_PER_LUN;
  1324. }
  1325. if (cmds_max < 2 || (cmds_max & (cmds_max - 1)) ||
  1326. cmds_max >= ISCSI_MGMT_ITT_OFFSET) {
  1327. if (cmds_max != 0)
  1328. printk(KERN_ERR "iscsi: invalid can_queue of %d. "
  1329. "can_queue must be a power of 2 and between "
  1330. "2 and %d - setting to %d.\n", cmds_max,
  1331. ISCSI_MGMT_ITT_OFFSET, ISCSI_DEF_XMIT_CMDS_MAX);
  1332. cmds_max = ISCSI_DEF_XMIT_CMDS_MAX;
  1333. }
  1334. shost = scsi_host_alloc(iscsit->host_template,
  1335. hostdata_privsize(sizeof(*session)));
  1336. if (!shost)
  1337. return NULL;
  1338. /* the iscsi layer takes one task for reserve */
  1339. shost->can_queue = cmds_max - 1;
  1340. shost->cmd_per_lun = qdepth;
  1341. shost->max_id = 1;
  1342. shost->max_channel = 0;
  1343. shost->max_lun = iscsit->max_lun;
  1344. shost->max_cmd_len = iscsit->max_cmd_len;
  1345. shost->transportt = scsit;
  1346. shost->transportt->create_work_queue = 1;
  1347. *hostno = shost->host_no;
  1348. session = iscsi_hostdata(shost->hostdata);
  1349. memset(session, 0, sizeof(struct iscsi_session));
  1350. session->host = shost;
  1351. session->state = ISCSI_STATE_FREE;
  1352. session->mgmtpool_max = ISCSI_MGMT_CMDS_MAX;
  1353. session->cmds_max = cmds_max;
  1354. session->queued_cmdsn = session->cmdsn = initial_cmdsn;
  1355. session->exp_cmdsn = initial_cmdsn + 1;
  1356. session->max_cmdsn = initial_cmdsn + 1;
  1357. session->max_r2t = 1;
  1358. session->tt = iscsit;
  1359. mutex_init(&session->eh_mutex);
  1360. /* initialize SCSI PDU commands pool */
  1361. if (iscsi_pool_init(&session->cmdpool, session->cmds_max,
  1362. (void***)&session->cmds,
  1363. cmd_task_size + sizeof(struct iscsi_cmd_task)))
  1364. goto cmdpool_alloc_fail;
  1365. /* pre-format cmds pool with ITT */
  1366. for (cmd_i = 0; cmd_i < session->cmds_max; cmd_i++) {
  1367. struct iscsi_cmd_task *ctask = session->cmds[cmd_i];
  1368. if (cmd_task_size)
  1369. ctask->dd_data = &ctask[1];
  1370. ctask->itt = cmd_i;
  1371. INIT_LIST_HEAD(&ctask->running);
  1372. }
  1373. spin_lock_init(&session->lock);
  1374. /* initialize immediate command pool */
  1375. if (iscsi_pool_init(&session->mgmtpool, session->mgmtpool_max,
  1376. (void***)&session->mgmt_cmds,
  1377. mgmt_task_size + sizeof(struct iscsi_mgmt_task)))
  1378. goto mgmtpool_alloc_fail;
  1379. /* pre-format immediate cmds pool with ITT */
  1380. for (cmd_i = 0; cmd_i < session->mgmtpool_max; cmd_i++) {
  1381. struct iscsi_mgmt_task *mtask = session->mgmt_cmds[cmd_i];
  1382. if (mgmt_task_size)
  1383. mtask->dd_data = &mtask[1];
  1384. mtask->itt = ISCSI_MGMT_ITT_OFFSET + cmd_i;
  1385. INIT_LIST_HEAD(&mtask->running);
  1386. }
  1387. if (scsi_add_host(shost, NULL))
  1388. goto add_host_fail;
  1389. if (!try_module_get(iscsit->owner))
  1390. goto cls_session_fail;
  1391. cls_session = iscsi_create_session(shost, iscsit, 0);
  1392. if (!cls_session)
  1393. goto module_put;
  1394. *(unsigned long*)shost->hostdata = (unsigned long)cls_session;
  1395. return cls_session;
  1396. module_put:
  1397. module_put(iscsit->owner);
  1398. cls_session_fail:
  1399. scsi_remove_host(shost);
  1400. add_host_fail:
  1401. iscsi_pool_free(&session->mgmtpool, (void**)session->mgmt_cmds);
  1402. mgmtpool_alloc_fail:
  1403. iscsi_pool_free(&session->cmdpool, (void**)session->cmds);
  1404. cmdpool_alloc_fail:
  1405. scsi_host_put(shost);
  1406. return NULL;
  1407. }
  1408. EXPORT_SYMBOL_GPL(iscsi_session_setup);
  1409. /**
  1410. * iscsi_session_teardown - destroy session, host, and cls_session
  1411. * shost: scsi host
  1412. *
  1413. * This can be used by software iscsi_transports that allocate
  1414. * a session per scsi host.
  1415. **/
  1416. void iscsi_session_teardown(struct iscsi_cls_session *cls_session)
  1417. {
  1418. struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
  1419. struct iscsi_session *session = iscsi_hostdata(shost->hostdata);
  1420. struct module *owner = cls_session->transport->owner;
  1421. iscsi_unblock_session(cls_session);
  1422. scsi_remove_host(shost);
  1423. iscsi_pool_free(&session->mgmtpool, (void**)session->mgmt_cmds);
  1424. iscsi_pool_free(&session->cmdpool, (void**)session->cmds);
  1425. kfree(session->password);
  1426. kfree(session->password_in);
  1427. kfree(session->username);
  1428. kfree(session->username_in);
  1429. kfree(session->targetname);
  1430. kfree(session->netdev);
  1431. kfree(session->hwaddress);
  1432. kfree(session->initiatorname);
  1433. iscsi_destroy_session(cls_session);
  1434. scsi_host_put(shost);
  1435. module_put(owner);
  1436. }
  1437. EXPORT_SYMBOL_GPL(iscsi_session_teardown);
  1438. /**
  1439. * iscsi_conn_setup - create iscsi_cls_conn and iscsi_conn
  1440. * @cls_session: iscsi_cls_session
  1441. * @conn_idx: cid
  1442. **/
  1443. struct iscsi_cls_conn *
  1444. iscsi_conn_setup(struct iscsi_cls_session *cls_session, uint32_t conn_idx)
  1445. {
  1446. struct iscsi_session *session = class_to_transport_session(cls_session);
  1447. struct iscsi_conn *conn;
  1448. struct iscsi_cls_conn *cls_conn;
  1449. char *data;
  1450. cls_conn = iscsi_create_conn(cls_session, conn_idx);
  1451. if (!cls_conn)
  1452. return NULL;
  1453. conn = cls_conn->dd_data;
  1454. memset(conn, 0, sizeof(*conn));
  1455. conn->session = session;
  1456. conn->cls_conn = cls_conn;
  1457. conn->c_stage = ISCSI_CONN_INITIAL_STAGE;
  1458. conn->id = conn_idx;
  1459. conn->exp_statsn = 0;
  1460. conn->tmf_state = TMF_INITIAL;
  1461. INIT_LIST_HEAD(&conn->run_list);
  1462. INIT_LIST_HEAD(&conn->mgmt_run_list);
  1463. INIT_LIST_HEAD(&conn->mgmtqueue);
  1464. INIT_LIST_HEAD(&conn->xmitqueue);
  1465. INIT_LIST_HEAD(&conn->requeue);
  1466. INIT_WORK(&conn->xmitwork, iscsi_xmitworker);
  1467. /* allocate login_mtask used for the login/text sequences */
  1468. spin_lock_bh(&session->lock);
  1469. if (!__kfifo_get(session->mgmtpool.queue,
  1470. (void*)&conn->login_mtask,
  1471. sizeof(void*))) {
  1472. spin_unlock_bh(&session->lock);
  1473. goto login_mtask_alloc_fail;
  1474. }
  1475. spin_unlock_bh(&session->lock);
  1476. data = kmalloc(ISCSI_DEF_MAX_RECV_SEG_LEN, GFP_KERNEL);
  1477. if (!data)
  1478. goto login_mtask_data_alloc_fail;
  1479. conn->login_mtask->data = conn->data = data;
  1480. init_timer(&conn->tmf_timer);
  1481. init_waitqueue_head(&conn->ehwait);
  1482. return cls_conn;
  1483. login_mtask_data_alloc_fail:
  1484. __kfifo_put(session->mgmtpool.queue, (void*)&conn->login_mtask,
  1485. sizeof(void*));
  1486. login_mtask_alloc_fail:
  1487. iscsi_destroy_conn(cls_conn);
  1488. return NULL;
  1489. }
  1490. EXPORT_SYMBOL_GPL(iscsi_conn_setup);
  1491. /**
  1492. * iscsi_conn_teardown - teardown iscsi connection
  1493. * cls_conn: iscsi class connection
  1494. *
  1495. * TODO: we may need to make this into a two step process
  1496. * like scsi-mls remove + put host
  1497. */
  1498. void iscsi_conn_teardown(struct iscsi_cls_conn *cls_conn)
  1499. {
  1500. struct iscsi_conn *conn = cls_conn->dd_data;
  1501. struct iscsi_session *session = conn->session;
  1502. unsigned long flags;
  1503. spin_lock_bh(&session->lock);
  1504. conn->c_stage = ISCSI_CONN_CLEANUP_WAIT;
  1505. if (session->leadconn == conn) {
  1506. /*
  1507. * leading connection? then give up on recovery.
  1508. */
  1509. session->state = ISCSI_STATE_TERMINATE;
  1510. wake_up(&conn->ehwait);
  1511. }
  1512. spin_unlock_bh(&session->lock);
  1513. /*
  1514. * Block until all in-progress commands for this connection
  1515. * time out or fail.
  1516. */
  1517. for (;;) {
  1518. spin_lock_irqsave(session->host->host_lock, flags);
  1519. if (!session->host->host_busy) { /* OK for ERL == 0 */
  1520. spin_unlock_irqrestore(session->host->host_lock, flags);
  1521. break;
  1522. }
  1523. spin_unlock_irqrestore(session->host->host_lock, flags);
  1524. msleep_interruptible(500);
  1525. printk(KERN_INFO "iscsi: scsi conn_destroy(): host_busy %d "
  1526. "host_failed %d\n", session->host->host_busy,
  1527. session->host->host_failed);
  1528. /*
  1529. * force eh_abort() to unblock
  1530. */
  1531. wake_up(&conn->ehwait);
  1532. }
  1533. /* flush queued up work because we free the connection below */
  1534. iscsi_suspend_tx(conn);
  1535. spin_lock_bh(&session->lock);
  1536. kfree(conn->data);
  1537. kfree(conn->persistent_address);
  1538. __kfifo_put(session->mgmtpool.queue, (void*)&conn->login_mtask,
  1539. sizeof(void*));
  1540. if (session->leadconn == conn)
  1541. session->leadconn = NULL;
  1542. spin_unlock_bh(&session->lock);
  1543. iscsi_destroy_conn(cls_conn);
  1544. }
  1545. EXPORT_SYMBOL_GPL(iscsi_conn_teardown);
  1546. int iscsi_conn_start(struct iscsi_cls_conn *cls_conn)
  1547. {
  1548. struct iscsi_conn *conn = cls_conn->dd_data;
  1549. struct iscsi_session *session = conn->session;
  1550. if (!session) {
  1551. printk(KERN_ERR "iscsi: can't start unbound connection\n");
  1552. return -EPERM;
  1553. }
  1554. if ((session->imm_data_en || !session->initial_r2t_en) &&
  1555. session->first_burst > session->max_burst) {
  1556. printk("iscsi: invalid burst lengths: "
  1557. "first_burst %d max_burst %d\n",
  1558. session->first_burst, session->max_burst);
  1559. return -EINVAL;
  1560. }
  1561. spin_lock_bh(&session->lock);
  1562. conn->c_stage = ISCSI_CONN_STARTED;
  1563. session->state = ISCSI_STATE_LOGGED_IN;
  1564. session->queued_cmdsn = session->cmdsn;
  1565. switch(conn->stop_stage) {
  1566. case STOP_CONN_RECOVER:
  1567. /*
  1568. * unblock eh_abort() if it is blocked. re-try all
  1569. * commands after successful recovery
  1570. */
  1571. conn->stop_stage = 0;
  1572. conn->tmf_state = TMF_INITIAL;
  1573. session->age++;
  1574. spin_unlock_bh(&session->lock);
  1575. iscsi_unblock_session(session_to_cls(session));
  1576. wake_up(&conn->ehwait);
  1577. return 0;
  1578. case STOP_CONN_TERM:
  1579. conn->stop_stage = 0;
  1580. break;
  1581. default:
  1582. break;
  1583. }
  1584. spin_unlock_bh(&session->lock);
  1585. return 0;
  1586. }
  1587. EXPORT_SYMBOL_GPL(iscsi_conn_start);
  1588. static void
  1589. flush_control_queues(struct iscsi_session *session, struct iscsi_conn *conn)
  1590. {
  1591. struct iscsi_mgmt_task *mtask, *tmp;
  1592. /* handle pending */
  1593. list_for_each_entry_safe(mtask, tmp, &conn->mgmtqueue, running) {
  1594. debug_scsi("flushing pending mgmt task itt 0x%x\n", mtask->itt);
  1595. list_del_init(&mtask->running);
  1596. if (mtask == conn->login_mtask)
  1597. continue;
  1598. __kfifo_put(session->mgmtpool.queue, (void*)&mtask,
  1599. sizeof(void*));
  1600. }
  1601. /* handle running */
  1602. list_for_each_entry_safe(mtask, tmp, &conn->mgmt_run_list, running) {
  1603. debug_scsi("flushing running mgmt task itt 0x%x\n", mtask->itt);
  1604. list_del_init(&mtask->running);
  1605. if (mtask == conn->login_mtask)
  1606. continue;
  1607. __kfifo_put(session->mgmtpool.queue, (void*)&mtask,
  1608. sizeof(void*));
  1609. }
  1610. conn->mtask = NULL;
  1611. }
  1612. static void iscsi_start_session_recovery(struct iscsi_session *session,
  1613. struct iscsi_conn *conn, int flag)
  1614. {
  1615. int old_stop_stage;
  1616. mutex_lock(&session->eh_mutex);
  1617. spin_lock_bh(&session->lock);
  1618. if (conn->stop_stage == STOP_CONN_TERM) {
  1619. spin_unlock_bh(&session->lock);
  1620. mutex_unlock(&session->eh_mutex);
  1621. return;
  1622. }
  1623. /*
  1624. * The LLD either freed/unset the lock on us, or userspace called
  1625. * stop but did not create a proper connection (connection was never
  1626. * bound or it was unbound then stop was called).
  1627. */
  1628. if (!conn->recv_lock) {
  1629. spin_unlock_bh(&session->lock);
  1630. mutex_unlock(&session->eh_mutex);
  1631. return;
  1632. }
  1633. /*
  1634. * When this is called for the in_login state, we only want to clean
  1635. * up the login task and connection. We do not need to block and set
  1636. * the recovery state again
  1637. */
  1638. if (flag == STOP_CONN_TERM)
  1639. session->state = ISCSI_STATE_TERMINATE;
  1640. else if (conn->stop_stage != STOP_CONN_RECOVER)
  1641. session->state = ISCSI_STATE_IN_RECOVERY;
  1642. old_stop_stage = conn->stop_stage;
  1643. conn->stop_stage = flag;
  1644. conn->c_stage = ISCSI_CONN_STOPPED;
  1645. spin_unlock_bh(&session->lock);
  1646. iscsi_suspend_tx(conn);
  1647. write_lock_bh(conn->recv_lock);
  1648. set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_rx);
  1649. write_unlock_bh(conn->recv_lock);
  1650. /*
  1651. * for connection level recovery we should not calculate
  1652. * header digest. conn->hdr_size used for optimization
  1653. * in hdr_extract() and will be re-negotiated at
  1654. * set_param() time.
  1655. */
  1656. if (flag == STOP_CONN_RECOVER) {
  1657. conn->hdrdgst_en = 0;
  1658. conn->datadgst_en = 0;
  1659. if (session->state == ISCSI_STATE_IN_RECOVERY &&
  1660. old_stop_stage != STOP_CONN_RECOVER) {
  1661. debug_scsi("blocking session\n");
  1662. iscsi_block_session(session_to_cls(session));
  1663. }
  1664. }
  1665. /*
  1666. * flush queues.
  1667. */
  1668. spin_lock_bh(&session->lock);
  1669. fail_all_commands(conn, -1);
  1670. flush_control_queues(session, conn);
  1671. spin_unlock_bh(&session->lock);
  1672. mutex_unlock(&session->eh_mutex);
  1673. }
  1674. void iscsi_conn_stop(struct iscsi_cls_conn *cls_conn, int flag)
  1675. {
  1676. struct iscsi_conn *conn = cls_conn->dd_data;
  1677. struct iscsi_session *session = conn->session;
  1678. switch (flag) {
  1679. case STOP_CONN_RECOVER:
  1680. case STOP_CONN_TERM:
  1681. iscsi_start_session_recovery(session, conn, flag);
  1682. break;
  1683. default:
  1684. printk(KERN_ERR "iscsi: invalid stop flag %d\n", flag);
  1685. }
  1686. }
  1687. EXPORT_SYMBOL_GPL(iscsi_conn_stop);
  1688. int iscsi_conn_bind(struct iscsi_cls_session *cls_session,
  1689. struct iscsi_cls_conn *cls_conn, int is_leading)
  1690. {
  1691. struct iscsi_session *session = class_to_transport_session(cls_session);
  1692. struct iscsi_conn *conn = cls_conn->dd_data;
  1693. spin_lock_bh(&session->lock);
  1694. if (is_leading)
  1695. session->leadconn = conn;
  1696. spin_unlock_bh(&session->lock);
  1697. /*
  1698. * Unblock xmitworker(), Login Phase will pass through.
  1699. */
  1700. clear_bit(ISCSI_SUSPEND_BIT, &conn->suspend_rx);
  1701. clear_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx);
  1702. return 0;
  1703. }
  1704. EXPORT_SYMBOL_GPL(iscsi_conn_bind);
  1705. int iscsi_set_param(struct iscsi_cls_conn *cls_conn,
  1706. enum iscsi_param param, char *buf, int buflen)
  1707. {
  1708. struct iscsi_conn *conn = cls_conn->dd_data;
  1709. struct iscsi_session *session = conn->session;
  1710. uint32_t value;
  1711. switch(param) {
  1712. case ISCSI_PARAM_FAST_ABORT:
  1713. sscanf(buf, "%d", &session->fast_abort);
  1714. break;
  1715. case ISCSI_PARAM_MAX_RECV_DLENGTH:
  1716. sscanf(buf, "%d", &conn->max_recv_dlength);
  1717. break;
  1718. case ISCSI_PARAM_MAX_XMIT_DLENGTH:
  1719. sscanf(buf, "%d", &conn->max_xmit_dlength);
  1720. break;
  1721. case ISCSI_PARAM_HDRDGST_EN:
  1722. sscanf(buf, "%d", &conn->hdrdgst_en);
  1723. break;
  1724. case ISCSI_PARAM_DATADGST_EN:
  1725. sscanf(buf, "%d", &conn->datadgst_en);
  1726. break;
  1727. case ISCSI_PARAM_INITIAL_R2T_EN:
  1728. sscanf(buf, "%d", &session->initial_r2t_en);
  1729. break;
  1730. case ISCSI_PARAM_MAX_R2T:
  1731. sscanf(buf, "%d", &session->max_r2t);
  1732. break;
  1733. case ISCSI_PARAM_IMM_DATA_EN:
  1734. sscanf(buf, "%d", &session->imm_data_en);
  1735. break;
  1736. case ISCSI_PARAM_FIRST_BURST:
  1737. sscanf(buf, "%d", &session->first_burst);
  1738. break;
  1739. case ISCSI_PARAM_MAX_BURST:
  1740. sscanf(buf, "%d", &session->max_burst);
  1741. break;
  1742. case ISCSI_PARAM_PDU_INORDER_EN:
  1743. sscanf(buf, "%d", &session->pdu_inorder_en);
  1744. break;
  1745. case ISCSI_PARAM_DATASEQ_INORDER_EN:
  1746. sscanf(buf, "%d", &session->dataseq_inorder_en);
  1747. break;
  1748. case ISCSI_PARAM_ERL:
  1749. sscanf(buf, "%d", &session->erl);
  1750. break;
  1751. case ISCSI_PARAM_IFMARKER_EN:
  1752. sscanf(buf, "%d", &value);
  1753. BUG_ON(value);
  1754. break;
  1755. case ISCSI_PARAM_OFMARKER_EN:
  1756. sscanf(buf, "%d", &value);
  1757. BUG_ON(value);
  1758. break;
  1759. case ISCSI_PARAM_EXP_STATSN:
  1760. sscanf(buf, "%u", &conn->exp_statsn);
  1761. break;
  1762. case ISCSI_PARAM_USERNAME:
  1763. kfree(session->username);
  1764. session->username = kstrdup(buf, GFP_KERNEL);
  1765. if (!session->username)
  1766. return -ENOMEM;
  1767. break;
  1768. case ISCSI_PARAM_USERNAME_IN:
  1769. kfree(session->username_in);
  1770. session->username_in = kstrdup(buf, GFP_KERNEL);
  1771. if (!session->username_in)
  1772. return -ENOMEM;
  1773. break;
  1774. case ISCSI_PARAM_PASSWORD:
  1775. kfree(session->password);
  1776. session->password = kstrdup(buf, GFP_KERNEL);
  1777. if (!session->password)
  1778. return -ENOMEM;
  1779. break;
  1780. case ISCSI_PARAM_PASSWORD_IN:
  1781. kfree(session->password_in);
  1782. session->password_in = kstrdup(buf, GFP_KERNEL);
  1783. if (!session->password_in)
  1784. return -ENOMEM;
  1785. break;
  1786. case ISCSI_PARAM_TARGET_NAME:
  1787. /* this should not change between logins */
  1788. if (session->targetname)
  1789. break;
  1790. session->targetname = kstrdup(buf, GFP_KERNEL);
  1791. if (!session->targetname)
  1792. return -ENOMEM;
  1793. break;
  1794. case ISCSI_PARAM_TPGT:
  1795. sscanf(buf, "%d", &session->tpgt);
  1796. break;
  1797. case ISCSI_PARAM_PERSISTENT_PORT:
  1798. sscanf(buf, "%d", &conn->persistent_port);
  1799. break;
  1800. case ISCSI_PARAM_PERSISTENT_ADDRESS:
  1801. /*
  1802. * this is the address returned in discovery so it should
  1803. * not change between logins.
  1804. */
  1805. if (conn->persistent_address)
  1806. break;
  1807. conn->persistent_address = kstrdup(buf, GFP_KERNEL);
  1808. if (!conn->persistent_address)
  1809. return -ENOMEM;
  1810. break;
  1811. default:
  1812. return -ENOSYS;
  1813. }
  1814. return 0;
  1815. }
  1816. EXPORT_SYMBOL_GPL(iscsi_set_param);
  1817. int iscsi_session_get_param(struct iscsi_cls_session *cls_session,
  1818. enum iscsi_param param, char *buf)
  1819. {
  1820. struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
  1821. struct iscsi_session *session = iscsi_hostdata(shost->hostdata);
  1822. int len;
  1823. switch(param) {
  1824. case ISCSI_PARAM_FAST_ABORT:
  1825. len = sprintf(buf, "%d\n", session->fast_abort);
  1826. break;
  1827. case ISCSI_PARAM_INITIAL_R2T_EN:
  1828. len = sprintf(buf, "%d\n", session->initial_r2t_en);
  1829. break;
  1830. case ISCSI_PARAM_MAX_R2T:
  1831. len = sprintf(buf, "%hu\n", session->max_r2t);
  1832. break;
  1833. case ISCSI_PARAM_IMM_DATA_EN:
  1834. len = sprintf(buf, "%d\n", session->imm_data_en);
  1835. break;
  1836. case ISCSI_PARAM_FIRST_BURST:
  1837. len = sprintf(buf, "%u\n", session->first_burst);
  1838. break;
  1839. case ISCSI_PARAM_MAX_BURST:
  1840. len = sprintf(buf, "%u\n", session->max_burst);
  1841. break;
  1842. case ISCSI_PARAM_PDU_INORDER_EN:
  1843. len = sprintf(buf, "%d\n", session->pdu_inorder_en);
  1844. break;
  1845. case ISCSI_PARAM_DATASEQ_INORDER_EN:
  1846. len = sprintf(buf, "%d\n", session->dataseq_inorder_en);
  1847. break;
  1848. case ISCSI_PARAM_ERL:
  1849. len = sprintf(buf, "%d\n", session->erl);
  1850. break;
  1851. case ISCSI_PARAM_TARGET_NAME:
  1852. len = sprintf(buf, "%s\n", session->targetname);
  1853. break;
  1854. case ISCSI_PARAM_TPGT:
  1855. len = sprintf(buf, "%d\n", session->tpgt);
  1856. break;
  1857. case ISCSI_PARAM_USERNAME:
  1858. len = sprintf(buf, "%s\n", session->username);
  1859. break;
  1860. case ISCSI_PARAM_USERNAME_IN:
  1861. len = sprintf(buf, "%s\n", session->username_in);
  1862. break;
  1863. case ISCSI_PARAM_PASSWORD:
  1864. len = sprintf(buf, "%s\n", session->password);
  1865. break;
  1866. case ISCSI_PARAM_PASSWORD_IN:
  1867. len = sprintf(buf, "%s\n", session->password_in);
  1868. break;
  1869. default:
  1870. return -ENOSYS;
  1871. }
  1872. return len;
  1873. }
  1874. EXPORT_SYMBOL_GPL(iscsi_session_get_param);
  1875. int iscsi_conn_get_param(struct iscsi_cls_conn *cls_conn,
  1876. enum iscsi_param param, char *buf)
  1877. {
  1878. struct iscsi_conn *conn = cls_conn->dd_data;
  1879. int len;
  1880. switch(param) {
  1881. case ISCSI_PARAM_MAX_RECV_DLENGTH:
  1882. len = sprintf(buf, "%u\n", conn->max_recv_dlength);
  1883. break;
  1884. case ISCSI_PARAM_MAX_XMIT_DLENGTH:
  1885. len = sprintf(buf, "%u\n", conn->max_xmit_dlength);
  1886. break;
  1887. case ISCSI_PARAM_HDRDGST_EN:
  1888. len = sprintf(buf, "%d\n", conn->hdrdgst_en);
  1889. break;
  1890. case ISCSI_PARAM_DATADGST_EN:
  1891. len = sprintf(buf, "%d\n", conn->datadgst_en);
  1892. break;
  1893. case ISCSI_PARAM_IFMARKER_EN:
  1894. len = sprintf(buf, "%d\n", conn->ifmarker_en);
  1895. break;
  1896. case ISCSI_PARAM_OFMARKER_EN:
  1897. len = sprintf(buf, "%d\n", conn->ofmarker_en);
  1898. break;
  1899. case ISCSI_PARAM_EXP_STATSN:
  1900. len = sprintf(buf, "%u\n", conn->exp_statsn);
  1901. break;
  1902. case ISCSI_PARAM_PERSISTENT_PORT:
  1903. len = sprintf(buf, "%d\n", conn->persistent_port);
  1904. break;
  1905. case ISCSI_PARAM_PERSISTENT_ADDRESS:
  1906. len = sprintf(buf, "%s\n", conn->persistent_address);
  1907. break;
  1908. default:
  1909. return -ENOSYS;
  1910. }
  1911. return len;
  1912. }
  1913. EXPORT_SYMBOL_GPL(iscsi_conn_get_param);
  1914. int iscsi_host_get_param(struct Scsi_Host *shost, enum iscsi_host_param param,
  1915. char *buf)
  1916. {
  1917. struct iscsi_session *session = iscsi_hostdata(shost->hostdata);
  1918. int len;
  1919. switch (param) {
  1920. case ISCSI_HOST_PARAM_NETDEV_NAME:
  1921. if (!session->netdev)
  1922. len = sprintf(buf, "%s\n", "default");
  1923. else
  1924. len = sprintf(buf, "%s\n", session->netdev);
  1925. break;
  1926. case ISCSI_HOST_PARAM_HWADDRESS:
  1927. if (!session->hwaddress)
  1928. len = sprintf(buf, "%s\n", "default");
  1929. else
  1930. len = sprintf(buf, "%s\n", session->hwaddress);
  1931. break;
  1932. case ISCSI_HOST_PARAM_INITIATOR_NAME:
  1933. if (!session->initiatorname)
  1934. len = sprintf(buf, "%s\n", "unknown");
  1935. else
  1936. len = sprintf(buf, "%s\n", session->initiatorname);
  1937. break;
  1938. default:
  1939. return -ENOSYS;
  1940. }
  1941. return len;
  1942. }
  1943. EXPORT_SYMBOL_GPL(iscsi_host_get_param);
  1944. int iscsi_host_set_param(struct Scsi_Host *shost, enum iscsi_host_param param,
  1945. char *buf, int buflen)
  1946. {
  1947. struct iscsi_session *session = iscsi_hostdata(shost->hostdata);
  1948. switch (param) {
  1949. case ISCSI_HOST_PARAM_NETDEV_NAME:
  1950. if (!session->netdev)
  1951. session->netdev = kstrdup(buf, GFP_KERNEL);
  1952. break;
  1953. case ISCSI_HOST_PARAM_HWADDRESS:
  1954. if (!session->hwaddress)
  1955. session->hwaddress = kstrdup(buf, GFP_KERNEL);
  1956. break;
  1957. case ISCSI_HOST_PARAM_INITIATOR_NAME:
  1958. if (!session->initiatorname)
  1959. session->initiatorname = kstrdup(buf, GFP_KERNEL);
  1960. break;
  1961. default:
  1962. return -ENOSYS;
  1963. }
  1964. return 0;
  1965. }
  1966. EXPORT_SYMBOL_GPL(iscsi_host_set_param);
  1967. MODULE_AUTHOR("Mike Christie");
  1968. MODULE_DESCRIPTION("iSCSI library functions");
  1969. MODULE_LICENSE("GPL");