qla_bsg.c 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2012 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. #include "qla_def.h"
  8. #include <linux/kthread.h>
  9. #include <linux/vmalloc.h>
  10. #include <linux/delay.h>
  11. /* BSG support for ELS/CT pass through */
  12. void
  13. qla2x00_bsg_job_done(void *data, void *ptr, int res)
  14. {
  15. srb_t *sp = (srb_t *)ptr;
  16. struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
  17. struct fc_bsg_job *bsg_job = sp->u.bsg_job;
  18. bsg_job->reply->result = res;
  19. bsg_job->job_done(bsg_job);
  20. sp->free(vha, sp);
  21. }
  22. void
  23. qla2x00_bsg_sp_free(void *data, void *ptr)
  24. {
  25. srb_t *sp = (srb_t *)ptr;
  26. struct scsi_qla_host *vha = sp->fcport->vha;
  27. struct fc_bsg_job *bsg_job = sp->u.bsg_job;
  28. struct qla_hw_data *ha = vha->hw;
  29. struct qla_mt_iocb_rqst_fx00 *piocb_rqst;
  30. if (sp->type == SRB_FXIOCB_BCMD) {
  31. piocb_rqst = (struct qla_mt_iocb_rqst_fx00 *)
  32. &bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
  33. if (piocb_rqst->flags & SRB_FXDISC_REQ_DMA_VALID)
  34. dma_unmap_sg(&ha->pdev->dev,
  35. bsg_job->request_payload.sg_list,
  36. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  37. if (piocb_rqst->flags & SRB_FXDISC_RESP_DMA_VALID)
  38. dma_unmap_sg(&ha->pdev->dev,
  39. bsg_job->reply_payload.sg_list,
  40. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  41. } else {
  42. dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  43. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  44. dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  45. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  46. }
  47. if (sp->type == SRB_CT_CMD ||
  48. sp->type == SRB_FXIOCB_BCMD ||
  49. sp->type == SRB_ELS_CMD_HST)
  50. kfree(sp->fcport);
  51. qla2x00_rel_sp(vha, sp);
  52. }
  53. int
  54. qla24xx_fcp_prio_cfg_valid(scsi_qla_host_t *vha,
  55. struct qla_fcp_prio_cfg *pri_cfg, uint8_t flag)
  56. {
  57. int i, ret, num_valid;
  58. uint8_t *bcode;
  59. struct qla_fcp_prio_entry *pri_entry;
  60. uint32_t *bcode_val_ptr, bcode_val;
  61. ret = 1;
  62. num_valid = 0;
  63. bcode = (uint8_t *)pri_cfg;
  64. bcode_val_ptr = (uint32_t *)pri_cfg;
  65. bcode_val = (uint32_t)(*bcode_val_ptr);
  66. if (bcode_val == 0xFFFFFFFF) {
  67. /* No FCP Priority config data in flash */
  68. ql_dbg(ql_dbg_user, vha, 0x7051,
  69. "No FCP Priority config data.\n");
  70. return 0;
  71. }
  72. if (bcode[0] != 'H' || bcode[1] != 'Q' || bcode[2] != 'O' ||
  73. bcode[3] != 'S') {
  74. /* Invalid FCP priority data header*/
  75. ql_dbg(ql_dbg_user, vha, 0x7052,
  76. "Invalid FCP Priority data header. bcode=0x%x.\n",
  77. bcode_val);
  78. return 0;
  79. }
  80. if (flag != 1)
  81. return ret;
  82. pri_entry = &pri_cfg->entry[0];
  83. for (i = 0; i < pri_cfg->num_entries; i++) {
  84. if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
  85. num_valid++;
  86. pri_entry++;
  87. }
  88. if (num_valid == 0) {
  89. /* No valid FCP priority data entries */
  90. ql_dbg(ql_dbg_user, vha, 0x7053,
  91. "No valid FCP Priority data entries.\n");
  92. ret = 0;
  93. } else {
  94. /* FCP priority data is valid */
  95. ql_dbg(ql_dbg_user, vha, 0x7054,
  96. "Valid FCP priority data. num entries = %d.\n",
  97. num_valid);
  98. }
  99. return ret;
  100. }
  101. static int
  102. qla24xx_proc_fcp_prio_cfg_cmd(struct fc_bsg_job *bsg_job)
  103. {
  104. struct Scsi_Host *host = bsg_job->shost;
  105. scsi_qla_host_t *vha = shost_priv(host);
  106. struct qla_hw_data *ha = vha->hw;
  107. int ret = 0;
  108. uint32_t len;
  109. uint32_t oper;
  110. if (!(IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) || IS_P3P_TYPE(ha))) {
  111. ret = -EINVAL;
  112. goto exit_fcp_prio_cfg;
  113. }
  114. /* Get the sub command */
  115. oper = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
  116. /* Only set config is allowed if config memory is not allocated */
  117. if (!ha->fcp_prio_cfg && (oper != QLFC_FCP_PRIO_SET_CONFIG)) {
  118. ret = -EINVAL;
  119. goto exit_fcp_prio_cfg;
  120. }
  121. switch (oper) {
  122. case QLFC_FCP_PRIO_DISABLE:
  123. if (ha->flags.fcp_prio_enabled) {
  124. ha->flags.fcp_prio_enabled = 0;
  125. ha->fcp_prio_cfg->attributes &=
  126. ~FCP_PRIO_ATTR_ENABLE;
  127. qla24xx_update_all_fcp_prio(vha);
  128. bsg_job->reply->result = DID_OK;
  129. } else {
  130. ret = -EINVAL;
  131. bsg_job->reply->result = (DID_ERROR << 16);
  132. goto exit_fcp_prio_cfg;
  133. }
  134. break;
  135. case QLFC_FCP_PRIO_ENABLE:
  136. if (!ha->flags.fcp_prio_enabled) {
  137. if (ha->fcp_prio_cfg) {
  138. ha->flags.fcp_prio_enabled = 1;
  139. ha->fcp_prio_cfg->attributes |=
  140. FCP_PRIO_ATTR_ENABLE;
  141. qla24xx_update_all_fcp_prio(vha);
  142. bsg_job->reply->result = DID_OK;
  143. } else {
  144. ret = -EINVAL;
  145. bsg_job->reply->result = (DID_ERROR << 16);
  146. goto exit_fcp_prio_cfg;
  147. }
  148. }
  149. break;
  150. case QLFC_FCP_PRIO_GET_CONFIG:
  151. len = bsg_job->reply_payload.payload_len;
  152. if (!len || len > FCP_PRIO_CFG_SIZE) {
  153. ret = -EINVAL;
  154. bsg_job->reply->result = (DID_ERROR << 16);
  155. goto exit_fcp_prio_cfg;
  156. }
  157. bsg_job->reply->result = DID_OK;
  158. bsg_job->reply->reply_payload_rcv_len =
  159. sg_copy_from_buffer(
  160. bsg_job->reply_payload.sg_list,
  161. bsg_job->reply_payload.sg_cnt, ha->fcp_prio_cfg,
  162. len);
  163. break;
  164. case QLFC_FCP_PRIO_SET_CONFIG:
  165. len = bsg_job->request_payload.payload_len;
  166. if (!len || len > FCP_PRIO_CFG_SIZE) {
  167. bsg_job->reply->result = (DID_ERROR << 16);
  168. ret = -EINVAL;
  169. goto exit_fcp_prio_cfg;
  170. }
  171. if (!ha->fcp_prio_cfg) {
  172. ha->fcp_prio_cfg = vmalloc(FCP_PRIO_CFG_SIZE);
  173. if (!ha->fcp_prio_cfg) {
  174. ql_log(ql_log_warn, vha, 0x7050,
  175. "Unable to allocate memory for fcp prio "
  176. "config data (%x).\n", FCP_PRIO_CFG_SIZE);
  177. bsg_job->reply->result = (DID_ERROR << 16);
  178. ret = -ENOMEM;
  179. goto exit_fcp_prio_cfg;
  180. }
  181. }
  182. memset(ha->fcp_prio_cfg, 0, FCP_PRIO_CFG_SIZE);
  183. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  184. bsg_job->request_payload.sg_cnt, ha->fcp_prio_cfg,
  185. FCP_PRIO_CFG_SIZE);
  186. /* validate fcp priority data */
  187. if (!qla24xx_fcp_prio_cfg_valid(vha,
  188. (struct qla_fcp_prio_cfg *) ha->fcp_prio_cfg, 1)) {
  189. bsg_job->reply->result = (DID_ERROR << 16);
  190. ret = -EINVAL;
  191. /* If buffer was invalidatic int
  192. * fcp_prio_cfg is of no use
  193. */
  194. vfree(ha->fcp_prio_cfg);
  195. ha->fcp_prio_cfg = NULL;
  196. goto exit_fcp_prio_cfg;
  197. }
  198. ha->flags.fcp_prio_enabled = 0;
  199. if (ha->fcp_prio_cfg->attributes & FCP_PRIO_ATTR_ENABLE)
  200. ha->flags.fcp_prio_enabled = 1;
  201. qla24xx_update_all_fcp_prio(vha);
  202. bsg_job->reply->result = DID_OK;
  203. break;
  204. default:
  205. ret = -EINVAL;
  206. break;
  207. }
  208. exit_fcp_prio_cfg:
  209. if (!ret)
  210. bsg_job->job_done(bsg_job);
  211. return ret;
  212. }
  213. static int
  214. qla2x00_process_els(struct fc_bsg_job *bsg_job)
  215. {
  216. struct fc_rport *rport;
  217. fc_port_t *fcport = NULL;
  218. struct Scsi_Host *host;
  219. scsi_qla_host_t *vha;
  220. struct qla_hw_data *ha;
  221. srb_t *sp;
  222. const char *type;
  223. int req_sg_cnt, rsp_sg_cnt;
  224. int rval = (DRIVER_ERROR << 16);
  225. uint16_t nextlid = 0;
  226. if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) {
  227. rport = bsg_job->rport;
  228. fcport = *(fc_port_t **) rport->dd_data;
  229. host = rport_to_shost(rport);
  230. vha = shost_priv(host);
  231. ha = vha->hw;
  232. type = "FC_BSG_RPT_ELS";
  233. } else {
  234. host = bsg_job->shost;
  235. vha = shost_priv(host);
  236. ha = vha->hw;
  237. type = "FC_BSG_HST_ELS_NOLOGIN";
  238. }
  239. if (!vha->flags.online) {
  240. ql_log(ql_log_warn, vha, 0x7005, "Host not online.\n");
  241. rval = -EIO;
  242. goto done;
  243. }
  244. /* pass through is supported only for ISP 4Gb or higher */
  245. if (!IS_FWI2_CAPABLE(ha)) {
  246. ql_dbg(ql_dbg_user, vha, 0x7001,
  247. "ELS passthru not supported for ISP23xx based adapters.\n");
  248. rval = -EPERM;
  249. goto done;
  250. }
  251. /* Multiple SG's are not supported for ELS requests */
  252. if (bsg_job->request_payload.sg_cnt > 1 ||
  253. bsg_job->reply_payload.sg_cnt > 1) {
  254. ql_dbg(ql_dbg_user, vha, 0x7002,
  255. "Multiple SG's are not suppored for ELS requests, "
  256. "request_sg_cnt=%x reply_sg_cnt=%x.\n",
  257. bsg_job->request_payload.sg_cnt,
  258. bsg_job->reply_payload.sg_cnt);
  259. rval = -EPERM;
  260. goto done;
  261. }
  262. /* ELS request for rport */
  263. if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) {
  264. /* make sure the rport is logged in,
  265. * if not perform fabric login
  266. */
  267. if (qla2x00_fabric_login(vha, fcport, &nextlid)) {
  268. ql_dbg(ql_dbg_user, vha, 0x7003,
  269. "Failed to login port %06X for ELS passthru.\n",
  270. fcport->d_id.b24);
  271. rval = -EIO;
  272. goto done;
  273. }
  274. } else {
  275. /* Allocate a dummy fcport structure, since functions
  276. * preparing the IOCB and mailbox command retrieves port
  277. * specific information from fcport structure. For Host based
  278. * ELS commands there will be no fcport structure allocated
  279. */
  280. fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  281. if (!fcport) {
  282. rval = -ENOMEM;
  283. goto done;
  284. }
  285. /* Initialize all required fields of fcport */
  286. fcport->vha = vha;
  287. fcport->d_id.b.al_pa =
  288. bsg_job->request->rqst_data.h_els.port_id[0];
  289. fcport->d_id.b.area =
  290. bsg_job->request->rqst_data.h_els.port_id[1];
  291. fcport->d_id.b.domain =
  292. bsg_job->request->rqst_data.h_els.port_id[2];
  293. fcport->loop_id =
  294. (fcport->d_id.b.al_pa == 0xFD) ?
  295. NPH_FABRIC_CONTROLLER : NPH_F_PORT;
  296. }
  297. req_sg_cnt =
  298. dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  299. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  300. if (!req_sg_cnt) {
  301. rval = -ENOMEM;
  302. goto done_free_fcport;
  303. }
  304. rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  305. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  306. if (!rsp_sg_cnt) {
  307. rval = -ENOMEM;
  308. goto done_free_fcport;
  309. }
  310. if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
  311. (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
  312. ql_log(ql_log_warn, vha, 0x7008,
  313. "dma mapping resulted in different sg counts, "
  314. "request_sg_cnt: %x dma_request_sg_cnt:%x reply_sg_cnt:%x "
  315. "dma_reply_sg_cnt:%x.\n", bsg_job->request_payload.sg_cnt,
  316. req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
  317. rval = -EAGAIN;
  318. goto done_unmap_sg;
  319. }
  320. /* Alloc SRB structure */
  321. sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
  322. if (!sp) {
  323. rval = -ENOMEM;
  324. goto done_unmap_sg;
  325. }
  326. sp->type =
  327. (bsg_job->request->msgcode == FC_BSG_RPT_ELS ?
  328. SRB_ELS_CMD_RPT : SRB_ELS_CMD_HST);
  329. sp->name =
  330. (bsg_job->request->msgcode == FC_BSG_RPT_ELS ?
  331. "bsg_els_rpt" : "bsg_els_hst");
  332. sp->u.bsg_job = bsg_job;
  333. sp->free = qla2x00_bsg_sp_free;
  334. sp->done = qla2x00_bsg_job_done;
  335. ql_dbg(ql_dbg_user, vha, 0x700a,
  336. "bsg rqst type: %s els type: %x - loop-id=%x "
  337. "portid=%-2x%02x%02x.\n", type,
  338. bsg_job->request->rqst_data.h_els.command_code, fcport->loop_id,
  339. fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa);
  340. rval = qla2x00_start_sp(sp);
  341. if (rval != QLA_SUCCESS) {
  342. ql_log(ql_log_warn, vha, 0x700e,
  343. "qla2x00_start_sp failed = %d\n", rval);
  344. qla2x00_rel_sp(vha, sp);
  345. rval = -EIO;
  346. goto done_unmap_sg;
  347. }
  348. return rval;
  349. done_unmap_sg:
  350. dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  351. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  352. dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  353. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  354. goto done_free_fcport;
  355. done_free_fcport:
  356. if (bsg_job->request->msgcode == FC_BSG_RPT_ELS)
  357. kfree(fcport);
  358. done:
  359. return rval;
  360. }
  361. inline uint16_t
  362. qla24xx_calc_ct_iocbs(uint16_t dsds)
  363. {
  364. uint16_t iocbs;
  365. iocbs = 1;
  366. if (dsds > 2) {
  367. iocbs += (dsds - 2) / 5;
  368. if ((dsds - 2) % 5)
  369. iocbs++;
  370. }
  371. return iocbs;
  372. }
  373. static int
  374. qla2x00_process_ct(struct fc_bsg_job *bsg_job)
  375. {
  376. srb_t *sp;
  377. struct Scsi_Host *host = bsg_job->shost;
  378. scsi_qla_host_t *vha = shost_priv(host);
  379. struct qla_hw_data *ha = vha->hw;
  380. int rval = (DRIVER_ERROR << 16);
  381. int req_sg_cnt, rsp_sg_cnt;
  382. uint16_t loop_id;
  383. struct fc_port *fcport;
  384. char *type = "FC_BSG_HST_CT";
  385. req_sg_cnt =
  386. dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  387. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  388. if (!req_sg_cnt) {
  389. ql_log(ql_log_warn, vha, 0x700f,
  390. "dma_map_sg return %d for request\n", req_sg_cnt);
  391. rval = -ENOMEM;
  392. goto done;
  393. }
  394. rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  395. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  396. if (!rsp_sg_cnt) {
  397. ql_log(ql_log_warn, vha, 0x7010,
  398. "dma_map_sg return %d for reply\n", rsp_sg_cnt);
  399. rval = -ENOMEM;
  400. goto done;
  401. }
  402. if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
  403. (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
  404. ql_log(ql_log_warn, vha, 0x7011,
  405. "request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt:%x "
  406. "dma_reply_sg_cnt: %x\n", bsg_job->request_payload.sg_cnt,
  407. req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
  408. rval = -EAGAIN;
  409. goto done_unmap_sg;
  410. }
  411. if (!vha->flags.online) {
  412. ql_log(ql_log_warn, vha, 0x7012,
  413. "Host is not online.\n");
  414. rval = -EIO;
  415. goto done_unmap_sg;
  416. }
  417. loop_id =
  418. (bsg_job->request->rqst_data.h_ct.preamble_word1 & 0xFF000000)
  419. >> 24;
  420. switch (loop_id) {
  421. case 0xFC:
  422. loop_id = cpu_to_le16(NPH_SNS);
  423. break;
  424. case 0xFA:
  425. loop_id = vha->mgmt_svr_loop_id;
  426. break;
  427. default:
  428. ql_dbg(ql_dbg_user, vha, 0x7013,
  429. "Unknown loop id: %x.\n", loop_id);
  430. rval = -EINVAL;
  431. goto done_unmap_sg;
  432. }
  433. /* Allocate a dummy fcport structure, since functions preparing the
  434. * IOCB and mailbox command retrieves port specific information
  435. * from fcport structure. For Host based ELS commands there will be
  436. * no fcport structure allocated
  437. */
  438. fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  439. if (!fcport) {
  440. ql_log(ql_log_warn, vha, 0x7014,
  441. "Failed to allocate fcport.\n");
  442. rval = -ENOMEM;
  443. goto done_unmap_sg;
  444. }
  445. /* Initialize all required fields of fcport */
  446. fcport->vha = vha;
  447. fcport->d_id.b.al_pa = bsg_job->request->rqst_data.h_ct.port_id[0];
  448. fcport->d_id.b.area = bsg_job->request->rqst_data.h_ct.port_id[1];
  449. fcport->d_id.b.domain = bsg_job->request->rqst_data.h_ct.port_id[2];
  450. fcport->loop_id = loop_id;
  451. /* Alloc SRB structure */
  452. sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
  453. if (!sp) {
  454. ql_log(ql_log_warn, vha, 0x7015,
  455. "qla2x00_get_sp failed.\n");
  456. rval = -ENOMEM;
  457. goto done_free_fcport;
  458. }
  459. sp->type = SRB_CT_CMD;
  460. sp->name = "bsg_ct";
  461. sp->iocbs = qla24xx_calc_ct_iocbs(req_sg_cnt + rsp_sg_cnt);
  462. sp->u.bsg_job = bsg_job;
  463. sp->free = qla2x00_bsg_sp_free;
  464. sp->done = qla2x00_bsg_job_done;
  465. ql_dbg(ql_dbg_user, vha, 0x7016,
  466. "bsg rqst type: %s else type: %x - "
  467. "loop-id=%x portid=%02x%02x%02x.\n", type,
  468. (bsg_job->request->rqst_data.h_ct.preamble_word2 >> 16),
  469. fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
  470. fcport->d_id.b.al_pa);
  471. rval = qla2x00_start_sp(sp);
  472. if (rval != QLA_SUCCESS) {
  473. ql_log(ql_log_warn, vha, 0x7017,
  474. "qla2x00_start_sp failed=%d.\n", rval);
  475. qla2x00_rel_sp(vha, sp);
  476. rval = -EIO;
  477. goto done_free_fcport;
  478. }
  479. return rval;
  480. done_free_fcport:
  481. kfree(fcport);
  482. done_unmap_sg:
  483. dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  484. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  485. dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  486. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  487. done:
  488. return rval;
  489. }
  490. /* Disable loopback mode */
  491. static inline int
  492. qla81xx_reset_loopback_mode(scsi_qla_host_t *vha, uint16_t *config,
  493. int wait, int wait2)
  494. {
  495. int ret = 0;
  496. int rval = 0;
  497. uint16_t new_config[4];
  498. struct qla_hw_data *ha = vha->hw;
  499. if (!IS_QLA81XX(ha) && !IS_QLA8031(ha) && !IS_QLA8044(ha))
  500. goto done_reset_internal;
  501. memset(new_config, 0 , sizeof(new_config));
  502. if ((config[0] & INTERNAL_LOOPBACK_MASK) >> 1 ==
  503. ENABLE_INTERNAL_LOOPBACK ||
  504. (config[0] & INTERNAL_LOOPBACK_MASK) >> 1 ==
  505. ENABLE_EXTERNAL_LOOPBACK) {
  506. new_config[0] = config[0] & ~INTERNAL_LOOPBACK_MASK;
  507. ql_dbg(ql_dbg_user, vha, 0x70bf, "new_config[0]=%02x\n",
  508. (new_config[0] & INTERNAL_LOOPBACK_MASK));
  509. memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3) ;
  510. ha->notify_dcbx_comp = wait;
  511. ha->notify_lb_portup_comp = wait2;
  512. ret = qla81xx_set_port_config(vha, new_config);
  513. if (ret != QLA_SUCCESS) {
  514. ql_log(ql_log_warn, vha, 0x7025,
  515. "Set port config failed.\n");
  516. ha->notify_dcbx_comp = 0;
  517. ha->notify_lb_portup_comp = 0;
  518. rval = -EINVAL;
  519. goto done_reset_internal;
  520. }
  521. /* Wait for DCBX complete event */
  522. if (wait && !wait_for_completion_timeout(&ha->dcbx_comp,
  523. (DCBX_COMP_TIMEOUT * HZ))) {
  524. ql_dbg(ql_dbg_user, vha, 0x7026,
  525. "DCBX completion not received.\n");
  526. ha->notify_dcbx_comp = 0;
  527. ha->notify_lb_portup_comp = 0;
  528. rval = -EINVAL;
  529. goto done_reset_internal;
  530. } else
  531. ql_dbg(ql_dbg_user, vha, 0x7027,
  532. "DCBX completion received.\n");
  533. if (wait2 &&
  534. !wait_for_completion_timeout(&ha->lb_portup_comp,
  535. (LB_PORTUP_COMP_TIMEOUT * HZ))) {
  536. ql_dbg(ql_dbg_user, vha, 0x70c5,
  537. "Port up completion not received.\n");
  538. ha->notify_lb_portup_comp = 0;
  539. rval = -EINVAL;
  540. goto done_reset_internal;
  541. } else
  542. ql_dbg(ql_dbg_user, vha, 0x70c6,
  543. "Port up completion received.\n");
  544. ha->notify_dcbx_comp = 0;
  545. ha->notify_lb_portup_comp = 0;
  546. }
  547. done_reset_internal:
  548. return rval;
  549. }
  550. /*
  551. * Set the port configuration to enable the internal or external loopback
  552. * depending on the loopback mode.
  553. */
  554. static inline int
  555. qla81xx_set_loopback_mode(scsi_qla_host_t *vha, uint16_t *config,
  556. uint16_t *new_config, uint16_t mode)
  557. {
  558. int ret = 0;
  559. int rval = 0;
  560. struct qla_hw_data *ha = vha->hw;
  561. if (!IS_QLA81XX(ha) && !IS_QLA8031(ha) && !IS_QLA8044(ha))
  562. goto done_set_internal;
  563. if (mode == INTERNAL_LOOPBACK)
  564. new_config[0] = config[0] | (ENABLE_INTERNAL_LOOPBACK << 1);
  565. else if (mode == EXTERNAL_LOOPBACK)
  566. new_config[0] = config[0] | (ENABLE_EXTERNAL_LOOPBACK << 1);
  567. ql_dbg(ql_dbg_user, vha, 0x70be,
  568. "new_config[0]=%02x\n", (new_config[0] & INTERNAL_LOOPBACK_MASK));
  569. memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3);
  570. ha->notify_dcbx_comp = 1;
  571. ret = qla81xx_set_port_config(vha, new_config);
  572. if (ret != QLA_SUCCESS) {
  573. ql_log(ql_log_warn, vha, 0x7021,
  574. "set port config failed.\n");
  575. ha->notify_dcbx_comp = 0;
  576. rval = -EINVAL;
  577. goto done_set_internal;
  578. }
  579. /* Wait for DCBX complete event */
  580. if (!wait_for_completion_timeout(&ha->dcbx_comp,
  581. (DCBX_COMP_TIMEOUT * HZ))) {
  582. ql_dbg(ql_dbg_user, vha, 0x7022,
  583. "DCBX completion not received.\n");
  584. ret = qla81xx_reset_loopback_mode(vha, new_config, 0, 0);
  585. /*
  586. * If the reset of the loopback mode doesn't work take a FCoE
  587. * dump and reset the chip.
  588. */
  589. if (ret) {
  590. ha->isp_ops->fw_dump(vha, 0);
  591. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  592. }
  593. rval = -EINVAL;
  594. } else {
  595. if (ha->flags.idc_compl_status) {
  596. ql_dbg(ql_dbg_user, vha, 0x70c3,
  597. "Bad status in IDC Completion AEN\n");
  598. rval = -EINVAL;
  599. ha->flags.idc_compl_status = 0;
  600. } else
  601. ql_dbg(ql_dbg_user, vha, 0x7023,
  602. "DCBX completion received.\n");
  603. }
  604. ha->notify_dcbx_comp = 0;
  605. done_set_internal:
  606. return rval;
  607. }
  608. static int
  609. qla2x00_process_loopback(struct fc_bsg_job *bsg_job)
  610. {
  611. struct Scsi_Host *host = bsg_job->shost;
  612. scsi_qla_host_t *vha = shost_priv(host);
  613. struct qla_hw_data *ha = vha->hw;
  614. int rval;
  615. uint8_t command_sent;
  616. char *type;
  617. struct msg_echo_lb elreq;
  618. uint16_t response[MAILBOX_REGISTER_COUNT];
  619. uint16_t config[4], new_config[4];
  620. uint8_t *fw_sts_ptr;
  621. uint8_t *req_data = NULL;
  622. dma_addr_t req_data_dma;
  623. uint32_t req_data_len;
  624. uint8_t *rsp_data = NULL;
  625. dma_addr_t rsp_data_dma;
  626. uint32_t rsp_data_len;
  627. if (!vha->flags.online) {
  628. ql_log(ql_log_warn, vha, 0x7019, "Host is not online.\n");
  629. return -EIO;
  630. }
  631. elreq.req_sg_cnt = dma_map_sg(&ha->pdev->dev,
  632. bsg_job->request_payload.sg_list, bsg_job->request_payload.sg_cnt,
  633. DMA_TO_DEVICE);
  634. if (!elreq.req_sg_cnt) {
  635. ql_log(ql_log_warn, vha, 0x701a,
  636. "dma_map_sg returned %d for request.\n", elreq.req_sg_cnt);
  637. return -ENOMEM;
  638. }
  639. elreq.rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
  640. bsg_job->reply_payload.sg_list, bsg_job->reply_payload.sg_cnt,
  641. DMA_FROM_DEVICE);
  642. if (!elreq.rsp_sg_cnt) {
  643. ql_log(ql_log_warn, vha, 0x701b,
  644. "dma_map_sg returned %d for reply.\n", elreq.rsp_sg_cnt);
  645. rval = -ENOMEM;
  646. goto done_unmap_req_sg;
  647. }
  648. if ((elreq.req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
  649. (elreq.rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
  650. ql_log(ql_log_warn, vha, 0x701c,
  651. "dma mapping resulted in different sg counts, "
  652. "request_sg_cnt: %x dma_request_sg_cnt: %x "
  653. "reply_sg_cnt: %x dma_reply_sg_cnt: %x.\n",
  654. bsg_job->request_payload.sg_cnt, elreq.req_sg_cnt,
  655. bsg_job->reply_payload.sg_cnt, elreq.rsp_sg_cnt);
  656. rval = -EAGAIN;
  657. goto done_unmap_sg;
  658. }
  659. req_data_len = rsp_data_len = bsg_job->request_payload.payload_len;
  660. req_data = dma_alloc_coherent(&ha->pdev->dev, req_data_len,
  661. &req_data_dma, GFP_KERNEL);
  662. if (!req_data) {
  663. ql_log(ql_log_warn, vha, 0x701d,
  664. "dma alloc failed for req_data.\n");
  665. rval = -ENOMEM;
  666. goto done_unmap_sg;
  667. }
  668. rsp_data = dma_alloc_coherent(&ha->pdev->dev, rsp_data_len,
  669. &rsp_data_dma, GFP_KERNEL);
  670. if (!rsp_data) {
  671. ql_log(ql_log_warn, vha, 0x7004,
  672. "dma alloc failed for rsp_data.\n");
  673. rval = -ENOMEM;
  674. goto done_free_dma_req;
  675. }
  676. /* Copy the request buffer in req_data now */
  677. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  678. bsg_job->request_payload.sg_cnt, req_data, req_data_len);
  679. elreq.send_dma = req_data_dma;
  680. elreq.rcv_dma = rsp_data_dma;
  681. elreq.transfer_size = req_data_len;
  682. elreq.options = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
  683. elreq.iteration_count =
  684. bsg_job->request->rqst_data.h_vendor.vendor_cmd[2];
  685. if (atomic_read(&vha->loop_state) == LOOP_READY &&
  686. (ha->current_topology == ISP_CFG_F ||
  687. ((IS_QLA81XX(ha) || IS_QLA8031(ha) || IS_QLA8044(ha)) &&
  688. le32_to_cpu(*(uint32_t *)req_data) == ELS_OPCODE_BYTE
  689. && req_data_len == MAX_ELS_FRAME_PAYLOAD)) &&
  690. elreq.options == EXTERNAL_LOOPBACK) {
  691. type = "FC_BSG_HST_VENDOR_ECHO_DIAG";
  692. ql_dbg(ql_dbg_user, vha, 0x701e,
  693. "BSG request type: %s.\n", type);
  694. command_sent = INT_DEF_LB_ECHO_CMD;
  695. rval = qla2x00_echo_test(vha, &elreq, response);
  696. } else {
  697. if (IS_QLA81XX(ha) || IS_QLA8031(ha) || IS_QLA8044(ha)) {
  698. memset(config, 0, sizeof(config));
  699. memset(new_config, 0, sizeof(new_config));
  700. if (qla81xx_get_port_config(vha, config)) {
  701. ql_log(ql_log_warn, vha, 0x701f,
  702. "Get port config failed.\n");
  703. rval = -EPERM;
  704. goto done_free_dma_rsp;
  705. }
  706. if ((config[0] & INTERNAL_LOOPBACK_MASK) != 0) {
  707. ql_dbg(ql_dbg_user, vha, 0x70c4,
  708. "Loopback operation already in "
  709. "progress.\n");
  710. rval = -EAGAIN;
  711. goto done_free_dma_rsp;
  712. }
  713. ql_dbg(ql_dbg_user, vha, 0x70c0,
  714. "elreq.options=%04x\n", elreq.options);
  715. if (elreq.options == EXTERNAL_LOOPBACK)
  716. if (IS_QLA8031(ha) || IS_QLA8044(ha))
  717. rval = qla81xx_set_loopback_mode(vha,
  718. config, new_config, elreq.options);
  719. else
  720. rval = qla81xx_reset_loopback_mode(vha,
  721. config, 1, 0);
  722. else
  723. rval = qla81xx_set_loopback_mode(vha, config,
  724. new_config, elreq.options);
  725. if (rval) {
  726. rval = -EPERM;
  727. goto done_free_dma_rsp;
  728. }
  729. type = "FC_BSG_HST_VENDOR_LOOPBACK";
  730. ql_dbg(ql_dbg_user, vha, 0x7028,
  731. "BSG request type: %s.\n", type);
  732. command_sent = INT_DEF_LB_LOOPBACK_CMD;
  733. rval = qla2x00_loopback_test(vha, &elreq, response);
  734. if (response[0] == MBS_COMMAND_ERROR &&
  735. response[1] == MBS_LB_RESET) {
  736. ql_log(ql_log_warn, vha, 0x7029,
  737. "MBX command error, Aborting ISP.\n");
  738. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  739. qla2xxx_wake_dpc(vha);
  740. qla2x00_wait_for_chip_reset(vha);
  741. /* Also reset the MPI */
  742. if (IS_QLA81XX(ha)) {
  743. if (qla81xx_restart_mpi_firmware(vha) !=
  744. QLA_SUCCESS) {
  745. ql_log(ql_log_warn, vha, 0x702a,
  746. "MPI reset failed.\n");
  747. }
  748. }
  749. rval = -EIO;
  750. goto done_free_dma_rsp;
  751. }
  752. if (new_config[0]) {
  753. int ret;
  754. /* Revert back to original port config
  755. * Also clear internal loopback
  756. */
  757. ret = qla81xx_reset_loopback_mode(vha,
  758. new_config, 0, 1);
  759. if (ret) {
  760. /*
  761. * If the reset of the loopback mode
  762. * doesn't work take FCoE dump and then
  763. * reset the chip.
  764. */
  765. ha->isp_ops->fw_dump(vha, 0);
  766. set_bit(ISP_ABORT_NEEDED,
  767. &vha->dpc_flags);
  768. }
  769. }
  770. } else {
  771. type = "FC_BSG_HST_VENDOR_LOOPBACK";
  772. ql_dbg(ql_dbg_user, vha, 0x702b,
  773. "BSG request type: %s.\n", type);
  774. command_sent = INT_DEF_LB_LOOPBACK_CMD;
  775. rval = qla2x00_loopback_test(vha, &elreq, response);
  776. }
  777. }
  778. if (rval) {
  779. ql_log(ql_log_warn, vha, 0x702c,
  780. "Vendor request %s failed.\n", type);
  781. rval = 0;
  782. bsg_job->reply->result = (DID_ERROR << 16);
  783. bsg_job->reply->reply_payload_rcv_len = 0;
  784. } else {
  785. ql_dbg(ql_dbg_user, vha, 0x702d,
  786. "Vendor request %s completed.\n", type);
  787. bsg_job->reply->result = (DID_OK << 16);
  788. sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
  789. bsg_job->reply_payload.sg_cnt, rsp_data,
  790. rsp_data_len);
  791. }
  792. bsg_job->reply_len = sizeof(struct fc_bsg_reply) +
  793. sizeof(response) + sizeof(uint8_t);
  794. fw_sts_ptr = ((uint8_t *)bsg_job->req->sense) +
  795. sizeof(struct fc_bsg_reply);
  796. memcpy(fw_sts_ptr, response, sizeof(response));
  797. fw_sts_ptr += sizeof(response);
  798. *fw_sts_ptr = command_sent;
  799. done_free_dma_rsp:
  800. dma_free_coherent(&ha->pdev->dev, rsp_data_len,
  801. rsp_data, rsp_data_dma);
  802. done_free_dma_req:
  803. dma_free_coherent(&ha->pdev->dev, req_data_len,
  804. req_data, req_data_dma);
  805. done_unmap_sg:
  806. dma_unmap_sg(&ha->pdev->dev,
  807. bsg_job->reply_payload.sg_list,
  808. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  809. done_unmap_req_sg:
  810. dma_unmap_sg(&ha->pdev->dev,
  811. bsg_job->request_payload.sg_list,
  812. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  813. if (!rval)
  814. bsg_job->job_done(bsg_job);
  815. return rval;
  816. }
  817. static int
  818. qla84xx_reset(struct fc_bsg_job *bsg_job)
  819. {
  820. struct Scsi_Host *host = bsg_job->shost;
  821. scsi_qla_host_t *vha = shost_priv(host);
  822. struct qla_hw_data *ha = vha->hw;
  823. int rval = 0;
  824. uint32_t flag;
  825. if (!IS_QLA84XX(ha)) {
  826. ql_dbg(ql_dbg_user, vha, 0x702f, "Not 84xx, exiting.\n");
  827. return -EINVAL;
  828. }
  829. flag = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
  830. rval = qla84xx_reset_chip(vha, flag == A84_ISSUE_RESET_DIAG_FW);
  831. if (rval) {
  832. ql_log(ql_log_warn, vha, 0x7030,
  833. "Vendor request 84xx reset failed.\n");
  834. rval = (DID_ERROR << 16);
  835. } else {
  836. ql_dbg(ql_dbg_user, vha, 0x7031,
  837. "Vendor request 84xx reset completed.\n");
  838. bsg_job->reply->result = DID_OK;
  839. bsg_job->job_done(bsg_job);
  840. }
  841. return rval;
  842. }
  843. static int
  844. qla84xx_updatefw(struct fc_bsg_job *bsg_job)
  845. {
  846. struct Scsi_Host *host = bsg_job->shost;
  847. scsi_qla_host_t *vha = shost_priv(host);
  848. struct qla_hw_data *ha = vha->hw;
  849. struct verify_chip_entry_84xx *mn = NULL;
  850. dma_addr_t mn_dma, fw_dma;
  851. void *fw_buf = NULL;
  852. int rval = 0;
  853. uint32_t sg_cnt;
  854. uint32_t data_len;
  855. uint16_t options;
  856. uint32_t flag;
  857. uint32_t fw_ver;
  858. if (!IS_QLA84XX(ha)) {
  859. ql_dbg(ql_dbg_user, vha, 0x7032,
  860. "Not 84xx, exiting.\n");
  861. return -EINVAL;
  862. }
  863. sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  864. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  865. if (!sg_cnt) {
  866. ql_log(ql_log_warn, vha, 0x7033,
  867. "dma_map_sg returned %d for request.\n", sg_cnt);
  868. return -ENOMEM;
  869. }
  870. if (sg_cnt != bsg_job->request_payload.sg_cnt) {
  871. ql_log(ql_log_warn, vha, 0x7034,
  872. "DMA mapping resulted in different sg counts, "
  873. "request_sg_cnt: %x dma_request_sg_cnt: %x.\n",
  874. bsg_job->request_payload.sg_cnt, sg_cnt);
  875. rval = -EAGAIN;
  876. goto done_unmap_sg;
  877. }
  878. data_len = bsg_job->request_payload.payload_len;
  879. fw_buf = dma_alloc_coherent(&ha->pdev->dev, data_len,
  880. &fw_dma, GFP_KERNEL);
  881. if (!fw_buf) {
  882. ql_log(ql_log_warn, vha, 0x7035,
  883. "DMA alloc failed for fw_buf.\n");
  884. rval = -ENOMEM;
  885. goto done_unmap_sg;
  886. }
  887. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  888. bsg_job->request_payload.sg_cnt, fw_buf, data_len);
  889. mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
  890. if (!mn) {
  891. ql_log(ql_log_warn, vha, 0x7036,
  892. "DMA alloc failed for fw buffer.\n");
  893. rval = -ENOMEM;
  894. goto done_free_fw_buf;
  895. }
  896. flag = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
  897. fw_ver = le32_to_cpu(*((uint32_t *)((uint32_t *)fw_buf + 2)));
  898. memset(mn, 0, sizeof(struct access_chip_84xx));
  899. mn->entry_type = VERIFY_CHIP_IOCB_TYPE;
  900. mn->entry_count = 1;
  901. options = VCO_FORCE_UPDATE | VCO_END_OF_DATA;
  902. if (flag == A84_ISSUE_UPDATE_DIAGFW_CMD)
  903. options |= VCO_DIAG_FW;
  904. mn->options = cpu_to_le16(options);
  905. mn->fw_ver = cpu_to_le32(fw_ver);
  906. mn->fw_size = cpu_to_le32(data_len);
  907. mn->fw_seq_size = cpu_to_le32(data_len);
  908. mn->dseg_address[0] = cpu_to_le32(LSD(fw_dma));
  909. mn->dseg_address[1] = cpu_to_le32(MSD(fw_dma));
  910. mn->dseg_length = cpu_to_le32(data_len);
  911. mn->data_seg_cnt = cpu_to_le16(1);
  912. rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
  913. if (rval) {
  914. ql_log(ql_log_warn, vha, 0x7037,
  915. "Vendor request 84xx updatefw failed.\n");
  916. rval = (DID_ERROR << 16);
  917. } else {
  918. ql_dbg(ql_dbg_user, vha, 0x7038,
  919. "Vendor request 84xx updatefw completed.\n");
  920. bsg_job->reply_len = sizeof(struct fc_bsg_reply);
  921. bsg_job->reply->result = DID_OK;
  922. }
  923. dma_pool_free(ha->s_dma_pool, mn, mn_dma);
  924. done_free_fw_buf:
  925. dma_free_coherent(&ha->pdev->dev, data_len, fw_buf, fw_dma);
  926. done_unmap_sg:
  927. dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  928. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  929. if (!rval)
  930. bsg_job->job_done(bsg_job);
  931. return rval;
  932. }
  933. static int
  934. qla84xx_mgmt_cmd(struct fc_bsg_job *bsg_job)
  935. {
  936. struct Scsi_Host *host = bsg_job->shost;
  937. scsi_qla_host_t *vha = shost_priv(host);
  938. struct qla_hw_data *ha = vha->hw;
  939. struct access_chip_84xx *mn = NULL;
  940. dma_addr_t mn_dma, mgmt_dma;
  941. void *mgmt_b = NULL;
  942. int rval = 0;
  943. struct qla_bsg_a84_mgmt *ql84_mgmt;
  944. uint32_t sg_cnt;
  945. uint32_t data_len = 0;
  946. uint32_t dma_direction = DMA_NONE;
  947. if (!IS_QLA84XX(ha)) {
  948. ql_log(ql_log_warn, vha, 0x703a,
  949. "Not 84xx, exiting.\n");
  950. return -EINVAL;
  951. }
  952. mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
  953. if (!mn) {
  954. ql_log(ql_log_warn, vha, 0x703c,
  955. "DMA alloc failed for fw buffer.\n");
  956. return -ENOMEM;
  957. }
  958. memset(mn, 0, sizeof(struct access_chip_84xx));
  959. mn->entry_type = ACCESS_CHIP_IOCB_TYPE;
  960. mn->entry_count = 1;
  961. ql84_mgmt = (void *)bsg_job->request + sizeof(struct fc_bsg_request);
  962. switch (ql84_mgmt->mgmt.cmd) {
  963. case QLA84_MGMT_READ_MEM:
  964. case QLA84_MGMT_GET_INFO:
  965. sg_cnt = dma_map_sg(&ha->pdev->dev,
  966. bsg_job->reply_payload.sg_list,
  967. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  968. if (!sg_cnt) {
  969. ql_log(ql_log_warn, vha, 0x703d,
  970. "dma_map_sg returned %d for reply.\n", sg_cnt);
  971. rval = -ENOMEM;
  972. goto exit_mgmt;
  973. }
  974. dma_direction = DMA_FROM_DEVICE;
  975. if (sg_cnt != bsg_job->reply_payload.sg_cnt) {
  976. ql_log(ql_log_warn, vha, 0x703e,
  977. "DMA mapping resulted in different sg counts, "
  978. "reply_sg_cnt: %x dma_reply_sg_cnt: %x.\n",
  979. bsg_job->reply_payload.sg_cnt, sg_cnt);
  980. rval = -EAGAIN;
  981. goto done_unmap_sg;
  982. }
  983. data_len = bsg_job->reply_payload.payload_len;
  984. mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len,
  985. &mgmt_dma, GFP_KERNEL);
  986. if (!mgmt_b) {
  987. ql_log(ql_log_warn, vha, 0x703f,
  988. "DMA alloc failed for mgmt_b.\n");
  989. rval = -ENOMEM;
  990. goto done_unmap_sg;
  991. }
  992. if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) {
  993. mn->options = cpu_to_le16(ACO_DUMP_MEMORY);
  994. mn->parameter1 =
  995. cpu_to_le32(
  996. ql84_mgmt->mgmt.mgmtp.u.mem.start_addr);
  997. } else if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO) {
  998. mn->options = cpu_to_le16(ACO_REQUEST_INFO);
  999. mn->parameter1 =
  1000. cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.info.type);
  1001. mn->parameter2 =
  1002. cpu_to_le32(
  1003. ql84_mgmt->mgmt.mgmtp.u.info.context);
  1004. }
  1005. break;
  1006. case QLA84_MGMT_WRITE_MEM:
  1007. sg_cnt = dma_map_sg(&ha->pdev->dev,
  1008. bsg_job->request_payload.sg_list,
  1009. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1010. if (!sg_cnt) {
  1011. ql_log(ql_log_warn, vha, 0x7040,
  1012. "dma_map_sg returned %d.\n", sg_cnt);
  1013. rval = -ENOMEM;
  1014. goto exit_mgmt;
  1015. }
  1016. dma_direction = DMA_TO_DEVICE;
  1017. if (sg_cnt != bsg_job->request_payload.sg_cnt) {
  1018. ql_log(ql_log_warn, vha, 0x7041,
  1019. "DMA mapping resulted in different sg counts, "
  1020. "request_sg_cnt: %x dma_request_sg_cnt: %x.\n",
  1021. bsg_job->request_payload.sg_cnt, sg_cnt);
  1022. rval = -EAGAIN;
  1023. goto done_unmap_sg;
  1024. }
  1025. data_len = bsg_job->request_payload.payload_len;
  1026. mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len,
  1027. &mgmt_dma, GFP_KERNEL);
  1028. if (!mgmt_b) {
  1029. ql_log(ql_log_warn, vha, 0x7042,
  1030. "DMA alloc failed for mgmt_b.\n");
  1031. rval = -ENOMEM;
  1032. goto done_unmap_sg;
  1033. }
  1034. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  1035. bsg_job->request_payload.sg_cnt, mgmt_b, data_len);
  1036. mn->options = cpu_to_le16(ACO_LOAD_MEMORY);
  1037. mn->parameter1 =
  1038. cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.mem.start_addr);
  1039. break;
  1040. case QLA84_MGMT_CHNG_CONFIG:
  1041. mn->options = cpu_to_le16(ACO_CHANGE_CONFIG_PARAM);
  1042. mn->parameter1 =
  1043. cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.id);
  1044. mn->parameter2 =
  1045. cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param0);
  1046. mn->parameter3 =
  1047. cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param1);
  1048. break;
  1049. default:
  1050. rval = -EIO;
  1051. goto exit_mgmt;
  1052. }
  1053. if (ql84_mgmt->mgmt.cmd != QLA84_MGMT_CHNG_CONFIG) {
  1054. mn->total_byte_cnt = cpu_to_le32(ql84_mgmt->mgmt.len);
  1055. mn->dseg_count = cpu_to_le16(1);
  1056. mn->dseg_address[0] = cpu_to_le32(LSD(mgmt_dma));
  1057. mn->dseg_address[1] = cpu_to_le32(MSD(mgmt_dma));
  1058. mn->dseg_length = cpu_to_le32(ql84_mgmt->mgmt.len);
  1059. }
  1060. rval = qla2x00_issue_iocb(vha, mn, mn_dma, 0);
  1061. if (rval) {
  1062. ql_log(ql_log_warn, vha, 0x7043,
  1063. "Vendor request 84xx mgmt failed.\n");
  1064. rval = (DID_ERROR << 16);
  1065. } else {
  1066. ql_dbg(ql_dbg_user, vha, 0x7044,
  1067. "Vendor request 84xx mgmt completed.\n");
  1068. bsg_job->reply_len = sizeof(struct fc_bsg_reply);
  1069. bsg_job->reply->result = DID_OK;
  1070. if ((ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) ||
  1071. (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO)) {
  1072. bsg_job->reply->reply_payload_rcv_len =
  1073. bsg_job->reply_payload.payload_len;
  1074. sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
  1075. bsg_job->reply_payload.sg_cnt, mgmt_b,
  1076. data_len);
  1077. }
  1078. }
  1079. done_unmap_sg:
  1080. if (mgmt_b)
  1081. dma_free_coherent(&ha->pdev->dev, data_len, mgmt_b, mgmt_dma);
  1082. if (dma_direction == DMA_TO_DEVICE)
  1083. dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  1084. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1085. else if (dma_direction == DMA_FROM_DEVICE)
  1086. dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  1087. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1088. exit_mgmt:
  1089. dma_pool_free(ha->s_dma_pool, mn, mn_dma);
  1090. if (!rval)
  1091. bsg_job->job_done(bsg_job);
  1092. return rval;
  1093. }
  1094. static int
  1095. qla24xx_iidma(struct fc_bsg_job *bsg_job)
  1096. {
  1097. struct Scsi_Host *host = bsg_job->shost;
  1098. scsi_qla_host_t *vha = shost_priv(host);
  1099. int rval = 0;
  1100. struct qla_port_param *port_param = NULL;
  1101. fc_port_t *fcport = NULL;
  1102. int found = 0;
  1103. uint16_t mb[MAILBOX_REGISTER_COUNT];
  1104. uint8_t *rsp_ptr = NULL;
  1105. if (!IS_IIDMA_CAPABLE(vha->hw)) {
  1106. ql_log(ql_log_info, vha, 0x7046, "iiDMA not supported.\n");
  1107. return -EINVAL;
  1108. }
  1109. port_param = (void *)bsg_job->request + sizeof(struct fc_bsg_request);
  1110. if (port_param->fc_scsi_addr.dest_type != EXT_DEF_TYPE_WWPN) {
  1111. ql_log(ql_log_warn, vha, 0x7048,
  1112. "Invalid destination type.\n");
  1113. return -EINVAL;
  1114. }
  1115. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1116. if (fcport->port_type != FCT_TARGET)
  1117. continue;
  1118. if (memcmp(port_param->fc_scsi_addr.dest_addr.wwpn,
  1119. fcport->port_name, sizeof(fcport->port_name)))
  1120. continue;
  1121. found = 1;
  1122. break;
  1123. }
  1124. if (!found) {
  1125. ql_log(ql_log_warn, vha, 0x7049,
  1126. "Failed to find port.\n");
  1127. return -EINVAL;
  1128. }
  1129. if (atomic_read(&fcport->state) != FCS_ONLINE) {
  1130. ql_log(ql_log_warn, vha, 0x704a,
  1131. "Port is not online.\n");
  1132. return -EINVAL;
  1133. }
  1134. if (fcport->flags & FCF_LOGIN_NEEDED) {
  1135. ql_log(ql_log_warn, vha, 0x704b,
  1136. "Remote port not logged in flags = 0x%x.\n", fcport->flags);
  1137. return -EINVAL;
  1138. }
  1139. if (port_param->mode)
  1140. rval = qla2x00_set_idma_speed(vha, fcport->loop_id,
  1141. port_param->speed, mb);
  1142. else
  1143. rval = qla2x00_get_idma_speed(vha, fcport->loop_id,
  1144. &port_param->speed, mb);
  1145. if (rval) {
  1146. ql_log(ql_log_warn, vha, 0x704c,
  1147. "iIDMA cmd failed for %8phN -- "
  1148. "%04x %x %04x %04x.\n", fcport->port_name,
  1149. rval, fcport->fp_speed, mb[0], mb[1]);
  1150. rval = (DID_ERROR << 16);
  1151. } else {
  1152. if (!port_param->mode) {
  1153. bsg_job->reply_len = sizeof(struct fc_bsg_reply) +
  1154. sizeof(struct qla_port_param);
  1155. rsp_ptr = ((uint8_t *)bsg_job->reply) +
  1156. sizeof(struct fc_bsg_reply);
  1157. memcpy(rsp_ptr, port_param,
  1158. sizeof(struct qla_port_param));
  1159. }
  1160. bsg_job->reply->result = DID_OK;
  1161. bsg_job->job_done(bsg_job);
  1162. }
  1163. return rval;
  1164. }
  1165. static int
  1166. qla2x00_optrom_setup(struct fc_bsg_job *bsg_job, scsi_qla_host_t *vha,
  1167. uint8_t is_update)
  1168. {
  1169. uint32_t start = 0;
  1170. int valid = 0;
  1171. struct qla_hw_data *ha = vha->hw;
  1172. if (unlikely(pci_channel_offline(ha->pdev)))
  1173. return -EINVAL;
  1174. start = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
  1175. if (start > ha->optrom_size) {
  1176. ql_log(ql_log_warn, vha, 0x7055,
  1177. "start %d > optrom_size %d.\n", start, ha->optrom_size);
  1178. return -EINVAL;
  1179. }
  1180. if (ha->optrom_state != QLA_SWAITING) {
  1181. ql_log(ql_log_info, vha, 0x7056,
  1182. "optrom_state %d.\n", ha->optrom_state);
  1183. return -EBUSY;
  1184. }
  1185. ha->optrom_region_start = start;
  1186. ql_dbg(ql_dbg_user, vha, 0x7057, "is_update=%d.\n", is_update);
  1187. if (is_update) {
  1188. if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
  1189. valid = 1;
  1190. else if (start == (ha->flt_region_boot * 4) ||
  1191. start == (ha->flt_region_fw * 4))
  1192. valid = 1;
  1193. else if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) ||
  1194. IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
  1195. valid = 1;
  1196. if (!valid) {
  1197. ql_log(ql_log_warn, vha, 0x7058,
  1198. "Invalid start region 0x%x/0x%x.\n", start,
  1199. bsg_job->request_payload.payload_len);
  1200. return -EINVAL;
  1201. }
  1202. ha->optrom_region_size = start +
  1203. bsg_job->request_payload.payload_len > ha->optrom_size ?
  1204. ha->optrom_size - start :
  1205. bsg_job->request_payload.payload_len;
  1206. ha->optrom_state = QLA_SWRITING;
  1207. } else {
  1208. ha->optrom_region_size = start +
  1209. bsg_job->reply_payload.payload_len > ha->optrom_size ?
  1210. ha->optrom_size - start :
  1211. bsg_job->reply_payload.payload_len;
  1212. ha->optrom_state = QLA_SREADING;
  1213. }
  1214. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  1215. if (!ha->optrom_buffer) {
  1216. ql_log(ql_log_warn, vha, 0x7059,
  1217. "Read: Unable to allocate memory for optrom retrieval "
  1218. "(%x)\n", ha->optrom_region_size);
  1219. ha->optrom_state = QLA_SWAITING;
  1220. return -ENOMEM;
  1221. }
  1222. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  1223. return 0;
  1224. }
  1225. static int
  1226. qla2x00_read_optrom(struct fc_bsg_job *bsg_job)
  1227. {
  1228. struct Scsi_Host *host = bsg_job->shost;
  1229. scsi_qla_host_t *vha = shost_priv(host);
  1230. struct qla_hw_data *ha = vha->hw;
  1231. int rval = 0;
  1232. if (ha->flags.nic_core_reset_hdlr_active)
  1233. return -EBUSY;
  1234. rval = qla2x00_optrom_setup(bsg_job, vha, 0);
  1235. if (rval)
  1236. return rval;
  1237. ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
  1238. ha->optrom_region_start, ha->optrom_region_size);
  1239. sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
  1240. bsg_job->reply_payload.sg_cnt, ha->optrom_buffer,
  1241. ha->optrom_region_size);
  1242. bsg_job->reply->reply_payload_rcv_len = ha->optrom_region_size;
  1243. bsg_job->reply->result = DID_OK;
  1244. vfree(ha->optrom_buffer);
  1245. ha->optrom_buffer = NULL;
  1246. ha->optrom_state = QLA_SWAITING;
  1247. bsg_job->job_done(bsg_job);
  1248. return rval;
  1249. }
  1250. static int
  1251. qla2x00_update_optrom(struct fc_bsg_job *bsg_job)
  1252. {
  1253. struct Scsi_Host *host = bsg_job->shost;
  1254. scsi_qla_host_t *vha = shost_priv(host);
  1255. struct qla_hw_data *ha = vha->hw;
  1256. int rval = 0;
  1257. rval = qla2x00_optrom_setup(bsg_job, vha, 1);
  1258. if (rval)
  1259. return rval;
  1260. /* Set the isp82xx_no_md_cap not to capture minidump */
  1261. ha->flags.isp82xx_no_md_cap = 1;
  1262. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  1263. bsg_job->request_payload.sg_cnt, ha->optrom_buffer,
  1264. ha->optrom_region_size);
  1265. ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
  1266. ha->optrom_region_start, ha->optrom_region_size);
  1267. bsg_job->reply->result = DID_OK;
  1268. vfree(ha->optrom_buffer);
  1269. ha->optrom_buffer = NULL;
  1270. ha->optrom_state = QLA_SWAITING;
  1271. bsg_job->job_done(bsg_job);
  1272. return rval;
  1273. }
  1274. static int
  1275. qla2x00_update_fru_versions(struct fc_bsg_job *bsg_job)
  1276. {
  1277. struct Scsi_Host *host = bsg_job->shost;
  1278. scsi_qla_host_t *vha = shost_priv(host);
  1279. struct qla_hw_data *ha = vha->hw;
  1280. int rval = 0;
  1281. uint8_t bsg[DMA_POOL_SIZE];
  1282. struct qla_image_version_list *list = (void *)bsg;
  1283. struct qla_image_version *image;
  1284. uint32_t count;
  1285. dma_addr_t sfp_dma;
  1286. void *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
  1287. if (!sfp) {
  1288. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
  1289. EXT_STATUS_NO_MEMORY;
  1290. goto done;
  1291. }
  1292. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  1293. bsg_job->request_payload.sg_cnt, list, sizeof(bsg));
  1294. image = list->version;
  1295. count = list->count;
  1296. while (count--) {
  1297. memcpy(sfp, &image->field_info, sizeof(image->field_info));
  1298. rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
  1299. image->field_address.device, image->field_address.offset,
  1300. sizeof(image->field_info), image->field_address.option);
  1301. if (rval) {
  1302. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
  1303. EXT_STATUS_MAILBOX;
  1304. goto dealloc;
  1305. }
  1306. image++;
  1307. }
  1308. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
  1309. dealloc:
  1310. dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
  1311. done:
  1312. bsg_job->reply_len = sizeof(struct fc_bsg_reply);
  1313. bsg_job->reply->result = DID_OK << 16;
  1314. bsg_job->job_done(bsg_job);
  1315. return 0;
  1316. }
  1317. static int
  1318. qla2x00_read_fru_status(struct fc_bsg_job *bsg_job)
  1319. {
  1320. struct Scsi_Host *host = bsg_job->shost;
  1321. scsi_qla_host_t *vha = shost_priv(host);
  1322. struct qla_hw_data *ha = vha->hw;
  1323. int rval = 0;
  1324. uint8_t bsg[DMA_POOL_SIZE];
  1325. struct qla_status_reg *sr = (void *)bsg;
  1326. dma_addr_t sfp_dma;
  1327. uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
  1328. if (!sfp) {
  1329. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
  1330. EXT_STATUS_NO_MEMORY;
  1331. goto done;
  1332. }
  1333. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  1334. bsg_job->request_payload.sg_cnt, sr, sizeof(*sr));
  1335. rval = qla2x00_read_sfp(vha, sfp_dma, sfp,
  1336. sr->field_address.device, sr->field_address.offset,
  1337. sizeof(sr->status_reg), sr->field_address.option);
  1338. sr->status_reg = *sfp;
  1339. if (rval) {
  1340. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
  1341. EXT_STATUS_MAILBOX;
  1342. goto dealloc;
  1343. }
  1344. sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
  1345. bsg_job->reply_payload.sg_cnt, sr, sizeof(*sr));
  1346. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
  1347. dealloc:
  1348. dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
  1349. done:
  1350. bsg_job->reply_len = sizeof(struct fc_bsg_reply);
  1351. bsg_job->reply->reply_payload_rcv_len = sizeof(*sr);
  1352. bsg_job->reply->result = DID_OK << 16;
  1353. bsg_job->job_done(bsg_job);
  1354. return 0;
  1355. }
  1356. static int
  1357. qla2x00_write_fru_status(struct fc_bsg_job *bsg_job)
  1358. {
  1359. struct Scsi_Host *host = bsg_job->shost;
  1360. scsi_qla_host_t *vha = shost_priv(host);
  1361. struct qla_hw_data *ha = vha->hw;
  1362. int rval = 0;
  1363. uint8_t bsg[DMA_POOL_SIZE];
  1364. struct qla_status_reg *sr = (void *)bsg;
  1365. dma_addr_t sfp_dma;
  1366. uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
  1367. if (!sfp) {
  1368. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
  1369. EXT_STATUS_NO_MEMORY;
  1370. goto done;
  1371. }
  1372. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  1373. bsg_job->request_payload.sg_cnt, sr, sizeof(*sr));
  1374. *sfp = sr->status_reg;
  1375. rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
  1376. sr->field_address.device, sr->field_address.offset,
  1377. sizeof(sr->status_reg), sr->field_address.option);
  1378. if (rval) {
  1379. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
  1380. EXT_STATUS_MAILBOX;
  1381. goto dealloc;
  1382. }
  1383. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
  1384. dealloc:
  1385. dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
  1386. done:
  1387. bsg_job->reply_len = sizeof(struct fc_bsg_reply);
  1388. bsg_job->reply->result = DID_OK << 16;
  1389. bsg_job->job_done(bsg_job);
  1390. return 0;
  1391. }
  1392. static int
  1393. qla2x00_write_i2c(struct fc_bsg_job *bsg_job)
  1394. {
  1395. struct Scsi_Host *host = bsg_job->shost;
  1396. scsi_qla_host_t *vha = shost_priv(host);
  1397. struct qla_hw_data *ha = vha->hw;
  1398. int rval = 0;
  1399. uint8_t bsg[DMA_POOL_SIZE];
  1400. struct qla_i2c_access *i2c = (void *)bsg;
  1401. dma_addr_t sfp_dma;
  1402. uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
  1403. if (!sfp) {
  1404. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
  1405. EXT_STATUS_NO_MEMORY;
  1406. goto done;
  1407. }
  1408. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  1409. bsg_job->request_payload.sg_cnt, i2c, sizeof(*i2c));
  1410. memcpy(sfp, i2c->buffer, i2c->length);
  1411. rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
  1412. i2c->device, i2c->offset, i2c->length, i2c->option);
  1413. if (rval) {
  1414. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
  1415. EXT_STATUS_MAILBOX;
  1416. goto dealloc;
  1417. }
  1418. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
  1419. dealloc:
  1420. dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
  1421. done:
  1422. bsg_job->reply_len = sizeof(struct fc_bsg_reply);
  1423. bsg_job->reply->result = DID_OK << 16;
  1424. bsg_job->job_done(bsg_job);
  1425. return 0;
  1426. }
  1427. static int
  1428. qla2x00_read_i2c(struct fc_bsg_job *bsg_job)
  1429. {
  1430. struct Scsi_Host *host = bsg_job->shost;
  1431. scsi_qla_host_t *vha = shost_priv(host);
  1432. struct qla_hw_data *ha = vha->hw;
  1433. int rval = 0;
  1434. uint8_t bsg[DMA_POOL_SIZE];
  1435. struct qla_i2c_access *i2c = (void *)bsg;
  1436. dma_addr_t sfp_dma;
  1437. uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
  1438. if (!sfp) {
  1439. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
  1440. EXT_STATUS_NO_MEMORY;
  1441. goto done;
  1442. }
  1443. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  1444. bsg_job->request_payload.sg_cnt, i2c, sizeof(*i2c));
  1445. rval = qla2x00_read_sfp(vha, sfp_dma, sfp,
  1446. i2c->device, i2c->offset, i2c->length, i2c->option);
  1447. if (rval) {
  1448. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
  1449. EXT_STATUS_MAILBOX;
  1450. goto dealloc;
  1451. }
  1452. memcpy(i2c->buffer, sfp, i2c->length);
  1453. sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
  1454. bsg_job->reply_payload.sg_cnt, i2c, sizeof(*i2c));
  1455. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
  1456. dealloc:
  1457. dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
  1458. done:
  1459. bsg_job->reply_len = sizeof(struct fc_bsg_reply);
  1460. bsg_job->reply->reply_payload_rcv_len = sizeof(*i2c);
  1461. bsg_job->reply->result = DID_OK << 16;
  1462. bsg_job->job_done(bsg_job);
  1463. return 0;
  1464. }
  1465. static int
  1466. qla24xx_process_bidir_cmd(struct fc_bsg_job *bsg_job)
  1467. {
  1468. struct Scsi_Host *host = bsg_job->shost;
  1469. scsi_qla_host_t *vha = shost_priv(host);
  1470. struct qla_hw_data *ha = vha->hw;
  1471. uint16_t thread_id;
  1472. uint32_t rval = EXT_STATUS_OK;
  1473. uint16_t req_sg_cnt = 0;
  1474. uint16_t rsp_sg_cnt = 0;
  1475. uint16_t nextlid = 0;
  1476. uint32_t tot_dsds;
  1477. srb_t *sp = NULL;
  1478. uint32_t req_data_len = 0;
  1479. uint32_t rsp_data_len = 0;
  1480. /* Check the type of the adapter */
  1481. if (!IS_BIDI_CAPABLE(ha)) {
  1482. ql_log(ql_log_warn, vha, 0x70a0,
  1483. "This adapter is not supported\n");
  1484. rval = EXT_STATUS_NOT_SUPPORTED;
  1485. goto done;
  1486. }
  1487. if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
  1488. test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  1489. test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
  1490. rval = EXT_STATUS_BUSY;
  1491. goto done;
  1492. }
  1493. /* Check if host is online */
  1494. if (!vha->flags.online) {
  1495. ql_log(ql_log_warn, vha, 0x70a1,
  1496. "Host is not online\n");
  1497. rval = EXT_STATUS_DEVICE_OFFLINE;
  1498. goto done;
  1499. }
  1500. /* Check if cable is plugged in or not */
  1501. if (vha->device_flags & DFLG_NO_CABLE) {
  1502. ql_log(ql_log_warn, vha, 0x70a2,
  1503. "Cable is unplugged...\n");
  1504. rval = EXT_STATUS_INVALID_CFG;
  1505. goto done;
  1506. }
  1507. /* Check if the switch is connected or not */
  1508. if (ha->current_topology != ISP_CFG_F) {
  1509. ql_log(ql_log_warn, vha, 0x70a3,
  1510. "Host is not connected to the switch\n");
  1511. rval = EXT_STATUS_INVALID_CFG;
  1512. goto done;
  1513. }
  1514. /* Check if operating mode is P2P */
  1515. if (ha->operating_mode != P2P) {
  1516. ql_log(ql_log_warn, vha, 0x70a4,
  1517. "Host is operating mode is not P2p\n");
  1518. rval = EXT_STATUS_INVALID_CFG;
  1519. goto done;
  1520. }
  1521. thread_id = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
  1522. mutex_lock(&ha->selflogin_lock);
  1523. if (vha->self_login_loop_id == 0) {
  1524. /* Initialize all required fields of fcport */
  1525. vha->bidir_fcport.vha = vha;
  1526. vha->bidir_fcport.d_id.b.al_pa = vha->d_id.b.al_pa;
  1527. vha->bidir_fcport.d_id.b.area = vha->d_id.b.area;
  1528. vha->bidir_fcport.d_id.b.domain = vha->d_id.b.domain;
  1529. vha->bidir_fcport.loop_id = vha->loop_id;
  1530. if (qla2x00_fabric_login(vha, &(vha->bidir_fcport), &nextlid)) {
  1531. ql_log(ql_log_warn, vha, 0x70a7,
  1532. "Failed to login port %06X for bidirectional IOCB\n",
  1533. vha->bidir_fcport.d_id.b24);
  1534. mutex_unlock(&ha->selflogin_lock);
  1535. rval = EXT_STATUS_MAILBOX;
  1536. goto done;
  1537. }
  1538. vha->self_login_loop_id = nextlid - 1;
  1539. }
  1540. /* Assign the self login loop id to fcport */
  1541. mutex_unlock(&ha->selflogin_lock);
  1542. vha->bidir_fcport.loop_id = vha->self_login_loop_id;
  1543. req_sg_cnt = dma_map_sg(&ha->pdev->dev,
  1544. bsg_job->request_payload.sg_list,
  1545. bsg_job->request_payload.sg_cnt,
  1546. DMA_TO_DEVICE);
  1547. if (!req_sg_cnt) {
  1548. rval = EXT_STATUS_NO_MEMORY;
  1549. goto done;
  1550. }
  1551. rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
  1552. bsg_job->reply_payload.sg_list, bsg_job->reply_payload.sg_cnt,
  1553. DMA_FROM_DEVICE);
  1554. if (!rsp_sg_cnt) {
  1555. rval = EXT_STATUS_NO_MEMORY;
  1556. goto done_unmap_req_sg;
  1557. }
  1558. if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
  1559. (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
  1560. ql_dbg(ql_dbg_user, vha, 0x70a9,
  1561. "Dma mapping resulted in different sg counts "
  1562. "[request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt: "
  1563. "%x dma_reply_sg_cnt: %x]\n",
  1564. bsg_job->request_payload.sg_cnt, req_sg_cnt,
  1565. bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
  1566. rval = EXT_STATUS_NO_MEMORY;
  1567. goto done_unmap_sg;
  1568. }
  1569. if (req_data_len != rsp_data_len) {
  1570. rval = EXT_STATUS_BUSY;
  1571. ql_log(ql_log_warn, vha, 0x70aa,
  1572. "req_data_len != rsp_data_len\n");
  1573. goto done_unmap_sg;
  1574. }
  1575. req_data_len = bsg_job->request_payload.payload_len;
  1576. rsp_data_len = bsg_job->reply_payload.payload_len;
  1577. /* Alloc SRB structure */
  1578. sp = qla2x00_get_sp(vha, &(vha->bidir_fcport), GFP_KERNEL);
  1579. if (!sp) {
  1580. ql_dbg(ql_dbg_user, vha, 0x70ac,
  1581. "Alloc SRB structure failed\n");
  1582. rval = EXT_STATUS_NO_MEMORY;
  1583. goto done_unmap_sg;
  1584. }
  1585. /*Populate srb->ctx with bidir ctx*/
  1586. sp->u.bsg_job = bsg_job;
  1587. sp->free = qla2x00_bsg_sp_free;
  1588. sp->type = SRB_BIDI_CMD;
  1589. sp->done = qla2x00_bsg_job_done;
  1590. /* Add the read and write sg count */
  1591. tot_dsds = rsp_sg_cnt + req_sg_cnt;
  1592. rval = qla2x00_start_bidir(sp, vha, tot_dsds);
  1593. if (rval != EXT_STATUS_OK)
  1594. goto done_free_srb;
  1595. /* the bsg request will be completed in the interrupt handler */
  1596. return rval;
  1597. done_free_srb:
  1598. mempool_free(sp, ha->srb_mempool);
  1599. done_unmap_sg:
  1600. dma_unmap_sg(&ha->pdev->dev,
  1601. bsg_job->reply_payload.sg_list,
  1602. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1603. done_unmap_req_sg:
  1604. dma_unmap_sg(&ha->pdev->dev,
  1605. bsg_job->request_payload.sg_list,
  1606. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1607. done:
  1608. /* Return an error vendor specific response
  1609. * and complete the bsg request
  1610. */
  1611. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = rval;
  1612. bsg_job->reply_len = sizeof(struct fc_bsg_reply);
  1613. bsg_job->reply->reply_payload_rcv_len = 0;
  1614. bsg_job->reply->result = (DID_OK) << 16;
  1615. bsg_job->job_done(bsg_job);
  1616. /* Always retrun success, vendor rsp carries correct status */
  1617. return 0;
  1618. }
  1619. static int
  1620. qlafx00_mgmt_cmd(struct fc_bsg_job *bsg_job)
  1621. {
  1622. struct Scsi_Host *host = bsg_job->shost;
  1623. scsi_qla_host_t *vha = shost_priv(host);
  1624. struct qla_hw_data *ha = vha->hw;
  1625. int rval = (DRIVER_ERROR << 16);
  1626. struct qla_mt_iocb_rqst_fx00 *piocb_rqst;
  1627. srb_t *sp;
  1628. int req_sg_cnt = 0, rsp_sg_cnt = 0;
  1629. struct fc_port *fcport;
  1630. char *type = "FC_BSG_HST_FX_MGMT";
  1631. /* Copy the IOCB specific information */
  1632. piocb_rqst = (struct qla_mt_iocb_rqst_fx00 *)
  1633. &bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
  1634. /* Dump the vendor information */
  1635. ql_dump_buffer(ql_dbg_user + ql_dbg_verbose , vha, 0x70cf,
  1636. (uint8_t *)piocb_rqst, sizeof(struct qla_mt_iocb_rqst_fx00));
  1637. if (!vha->flags.online) {
  1638. ql_log(ql_log_warn, vha, 0x70d0,
  1639. "Host is not online.\n");
  1640. rval = -EIO;
  1641. goto done;
  1642. }
  1643. if (piocb_rqst->flags & SRB_FXDISC_REQ_DMA_VALID) {
  1644. req_sg_cnt = dma_map_sg(&ha->pdev->dev,
  1645. bsg_job->request_payload.sg_list,
  1646. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1647. if (!req_sg_cnt) {
  1648. ql_log(ql_log_warn, vha, 0x70c7,
  1649. "dma_map_sg return %d for request\n", req_sg_cnt);
  1650. rval = -ENOMEM;
  1651. goto done;
  1652. }
  1653. }
  1654. if (piocb_rqst->flags & SRB_FXDISC_RESP_DMA_VALID) {
  1655. rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
  1656. bsg_job->reply_payload.sg_list,
  1657. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1658. if (!rsp_sg_cnt) {
  1659. ql_log(ql_log_warn, vha, 0x70c8,
  1660. "dma_map_sg return %d for reply\n", rsp_sg_cnt);
  1661. rval = -ENOMEM;
  1662. goto done_unmap_req_sg;
  1663. }
  1664. }
  1665. ql_dbg(ql_dbg_user, vha, 0x70c9,
  1666. "request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt:%x "
  1667. "dma_reply_sg_cnt: %x\n", bsg_job->request_payload.sg_cnt,
  1668. req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
  1669. /* Allocate a dummy fcport structure, since functions preparing the
  1670. * IOCB and mailbox command retrieves port specific information
  1671. * from fcport structure. For Host based ELS commands there will be
  1672. * no fcport structure allocated
  1673. */
  1674. fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  1675. if (!fcport) {
  1676. ql_log(ql_log_warn, vha, 0x70ca,
  1677. "Failed to allocate fcport.\n");
  1678. rval = -ENOMEM;
  1679. goto done_unmap_rsp_sg;
  1680. }
  1681. /* Alloc SRB structure */
  1682. sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
  1683. if (!sp) {
  1684. ql_log(ql_log_warn, vha, 0x70cb,
  1685. "qla2x00_get_sp failed.\n");
  1686. rval = -ENOMEM;
  1687. goto done_free_fcport;
  1688. }
  1689. /* Initialize all required fields of fcport */
  1690. fcport->vha = vha;
  1691. fcport->loop_id = piocb_rqst->dataword;
  1692. sp->type = SRB_FXIOCB_BCMD;
  1693. sp->name = "bsg_fx_mgmt";
  1694. sp->iocbs = qla24xx_calc_ct_iocbs(req_sg_cnt + rsp_sg_cnt);
  1695. sp->u.bsg_job = bsg_job;
  1696. sp->free = qla2x00_bsg_sp_free;
  1697. sp->done = qla2x00_bsg_job_done;
  1698. ql_dbg(ql_dbg_user, vha, 0x70cc,
  1699. "bsg rqst type: %s fx_mgmt_type: %x id=%x\n",
  1700. type, piocb_rqst->func_type, fcport->loop_id);
  1701. rval = qla2x00_start_sp(sp);
  1702. if (rval != QLA_SUCCESS) {
  1703. ql_log(ql_log_warn, vha, 0x70cd,
  1704. "qla2x00_start_sp failed=%d.\n", rval);
  1705. mempool_free(sp, ha->srb_mempool);
  1706. rval = -EIO;
  1707. goto done_free_fcport;
  1708. }
  1709. return rval;
  1710. done_free_fcport:
  1711. kfree(fcport);
  1712. done_unmap_rsp_sg:
  1713. if (piocb_rqst->flags & SRB_FXDISC_RESP_DMA_VALID)
  1714. dma_unmap_sg(&ha->pdev->dev,
  1715. bsg_job->reply_payload.sg_list,
  1716. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1717. done_unmap_req_sg:
  1718. if (piocb_rqst->flags & SRB_FXDISC_REQ_DMA_VALID)
  1719. dma_unmap_sg(&ha->pdev->dev,
  1720. bsg_job->request_payload.sg_list,
  1721. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1722. done:
  1723. return rval;
  1724. }
  1725. static int
  1726. qla2x00_process_vendor_specific(struct fc_bsg_job *bsg_job)
  1727. {
  1728. switch (bsg_job->request->rqst_data.h_vendor.vendor_cmd[0]) {
  1729. case QL_VND_LOOPBACK:
  1730. return qla2x00_process_loopback(bsg_job);
  1731. case QL_VND_A84_RESET:
  1732. return qla84xx_reset(bsg_job);
  1733. case QL_VND_A84_UPDATE_FW:
  1734. return qla84xx_updatefw(bsg_job);
  1735. case QL_VND_A84_MGMT_CMD:
  1736. return qla84xx_mgmt_cmd(bsg_job);
  1737. case QL_VND_IIDMA:
  1738. return qla24xx_iidma(bsg_job);
  1739. case QL_VND_FCP_PRIO_CFG_CMD:
  1740. return qla24xx_proc_fcp_prio_cfg_cmd(bsg_job);
  1741. case QL_VND_READ_FLASH:
  1742. return qla2x00_read_optrom(bsg_job);
  1743. case QL_VND_UPDATE_FLASH:
  1744. return qla2x00_update_optrom(bsg_job);
  1745. case QL_VND_SET_FRU_VERSION:
  1746. return qla2x00_update_fru_versions(bsg_job);
  1747. case QL_VND_READ_FRU_STATUS:
  1748. return qla2x00_read_fru_status(bsg_job);
  1749. case QL_VND_WRITE_FRU_STATUS:
  1750. return qla2x00_write_fru_status(bsg_job);
  1751. case QL_VND_WRITE_I2C:
  1752. return qla2x00_write_i2c(bsg_job);
  1753. case QL_VND_READ_I2C:
  1754. return qla2x00_read_i2c(bsg_job);
  1755. case QL_VND_DIAG_IO_CMD:
  1756. return qla24xx_process_bidir_cmd(bsg_job);
  1757. case QL_VND_FX00_MGMT_CMD:
  1758. return qlafx00_mgmt_cmd(bsg_job);
  1759. default:
  1760. return -ENOSYS;
  1761. }
  1762. }
  1763. int
  1764. qla24xx_bsg_request(struct fc_bsg_job *bsg_job)
  1765. {
  1766. int ret = -EINVAL;
  1767. struct fc_rport *rport;
  1768. fc_port_t *fcport = NULL;
  1769. struct Scsi_Host *host;
  1770. scsi_qla_host_t *vha;
  1771. /* In case no data transferred. */
  1772. bsg_job->reply->reply_payload_rcv_len = 0;
  1773. if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) {
  1774. rport = bsg_job->rport;
  1775. fcport = *(fc_port_t **) rport->dd_data;
  1776. host = rport_to_shost(rport);
  1777. vha = shost_priv(host);
  1778. } else {
  1779. host = bsg_job->shost;
  1780. vha = shost_priv(host);
  1781. }
  1782. if (qla2x00_reset_active(vha)) {
  1783. ql_dbg(ql_dbg_user, vha, 0x709f,
  1784. "BSG: ISP abort active/needed -- cmd=%d.\n",
  1785. bsg_job->request->msgcode);
  1786. return -EBUSY;
  1787. }
  1788. ql_dbg(ql_dbg_user, vha, 0x7000,
  1789. "Entered %s msgcode=0x%x.\n", __func__, bsg_job->request->msgcode);
  1790. switch (bsg_job->request->msgcode) {
  1791. case FC_BSG_RPT_ELS:
  1792. case FC_BSG_HST_ELS_NOLOGIN:
  1793. ret = qla2x00_process_els(bsg_job);
  1794. break;
  1795. case FC_BSG_HST_CT:
  1796. ret = qla2x00_process_ct(bsg_job);
  1797. break;
  1798. case FC_BSG_HST_VENDOR:
  1799. ret = qla2x00_process_vendor_specific(bsg_job);
  1800. break;
  1801. case FC_BSG_HST_ADD_RPORT:
  1802. case FC_BSG_HST_DEL_RPORT:
  1803. case FC_BSG_RPT_CT:
  1804. default:
  1805. ql_log(ql_log_warn, vha, 0x705a, "Unsupported BSG request.\n");
  1806. break;
  1807. }
  1808. return ret;
  1809. }
  1810. int
  1811. qla24xx_bsg_timeout(struct fc_bsg_job *bsg_job)
  1812. {
  1813. scsi_qla_host_t *vha = shost_priv(bsg_job->shost);
  1814. struct qla_hw_data *ha = vha->hw;
  1815. srb_t *sp;
  1816. int cnt, que;
  1817. unsigned long flags;
  1818. struct req_que *req;
  1819. /* find the bsg job from the active list of commands */
  1820. spin_lock_irqsave(&ha->hardware_lock, flags);
  1821. for (que = 0; que < ha->max_req_queues; que++) {
  1822. req = ha->req_q_map[que];
  1823. if (!req)
  1824. continue;
  1825. for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
  1826. sp = req->outstanding_cmds[cnt];
  1827. if (sp) {
  1828. if (((sp->type == SRB_CT_CMD) ||
  1829. (sp->type == SRB_ELS_CMD_HST) ||
  1830. (sp->type == SRB_FXIOCB_BCMD))
  1831. && (sp->u.bsg_job == bsg_job)) {
  1832. req->outstanding_cmds[cnt] = NULL;
  1833. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1834. if (ha->isp_ops->abort_command(sp)) {
  1835. ql_log(ql_log_warn, vha, 0x7089,
  1836. "mbx abort_command "
  1837. "failed.\n");
  1838. bsg_job->req->errors =
  1839. bsg_job->reply->result = -EIO;
  1840. } else {
  1841. ql_dbg(ql_dbg_user, vha, 0x708a,
  1842. "mbx abort_command "
  1843. "success.\n");
  1844. bsg_job->req->errors =
  1845. bsg_job->reply->result = 0;
  1846. }
  1847. spin_lock_irqsave(&ha->hardware_lock, flags);
  1848. goto done;
  1849. }
  1850. }
  1851. }
  1852. }
  1853. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1854. ql_log(ql_log_info, vha, 0x708b, "SRB not found to abort.\n");
  1855. bsg_job->req->errors = bsg_job->reply->result = -ENXIO;
  1856. return 0;
  1857. done:
  1858. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1859. sp->free(vha, sp);
  1860. return 0;
  1861. }