qla_bsg.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2011 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. inline srb_t *
  13. qla2x00_get_ctx_bsg_sp(scsi_qla_host_t *vha, fc_port_t *fcport, size_t size)
  14. {
  15. srb_t *sp;
  16. struct qla_hw_data *ha = vha->hw;
  17. struct srb_ctx *ctx;
  18. sp = mempool_alloc(ha->srb_mempool, GFP_KERNEL);
  19. if (!sp)
  20. goto done;
  21. ctx = kzalloc(size, GFP_KERNEL);
  22. if (!ctx) {
  23. mempool_free(sp, ha->srb_mempool);
  24. sp = NULL;
  25. goto done;
  26. }
  27. memset(sp, 0, sizeof(*sp));
  28. sp->fcport = fcport;
  29. sp->ctx = ctx;
  30. ctx->iocbs = 1;
  31. done:
  32. return sp;
  33. }
  34. int
  35. qla24xx_fcp_prio_cfg_valid(scsi_qla_host_t *vha,
  36. struct qla_fcp_prio_cfg *pri_cfg, uint8_t flag)
  37. {
  38. int i, ret, num_valid;
  39. uint8_t *bcode;
  40. struct qla_fcp_prio_entry *pri_entry;
  41. uint32_t *bcode_val_ptr, bcode_val;
  42. ret = 1;
  43. num_valid = 0;
  44. bcode = (uint8_t *)pri_cfg;
  45. bcode_val_ptr = (uint32_t *)pri_cfg;
  46. bcode_val = (uint32_t)(*bcode_val_ptr);
  47. if (bcode_val == 0xFFFFFFFF) {
  48. /* No FCP Priority config data in flash */
  49. ql_dbg(ql_dbg_user, vha, 0x7051,
  50. "No FCP Priority config data.\n");
  51. return 0;
  52. }
  53. if (bcode[0] != 'H' || bcode[1] != 'Q' || bcode[2] != 'O' ||
  54. bcode[3] != 'S') {
  55. /* Invalid FCP priority data header*/
  56. ql_dbg(ql_dbg_user, vha, 0x7052,
  57. "Invalid FCP Priority data header. bcode=0x%x.\n",
  58. bcode_val);
  59. return 0;
  60. }
  61. if (flag != 1)
  62. return ret;
  63. pri_entry = &pri_cfg->entry[0];
  64. for (i = 0; i < pri_cfg->num_entries; i++) {
  65. if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
  66. num_valid++;
  67. pri_entry++;
  68. }
  69. if (num_valid == 0) {
  70. /* No valid FCP priority data entries */
  71. ql_dbg(ql_dbg_user, vha, 0x7053,
  72. "No valid FCP Priority data entries.\n");
  73. ret = 0;
  74. } else {
  75. /* FCP priority data is valid */
  76. ql_dbg(ql_dbg_user, vha, 0x7054,
  77. "Valid FCP priority data. num entries = %d.\n",
  78. num_valid);
  79. }
  80. return ret;
  81. }
  82. static int
  83. qla24xx_proc_fcp_prio_cfg_cmd(struct fc_bsg_job *bsg_job)
  84. {
  85. struct Scsi_Host *host = bsg_job->shost;
  86. scsi_qla_host_t *vha = shost_priv(host);
  87. struct qla_hw_data *ha = vha->hw;
  88. int ret = 0;
  89. uint32_t len;
  90. uint32_t oper;
  91. bsg_job->reply->reply_payload_rcv_len = 0;
  92. if (!(IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) || IS_QLA82XX(ha))) {
  93. ret = -EINVAL;
  94. goto exit_fcp_prio_cfg;
  95. }
  96. /* Get the sub command */
  97. oper = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
  98. /* Only set config is allowed if config memory is not allocated */
  99. if (!ha->fcp_prio_cfg && (oper != QLFC_FCP_PRIO_SET_CONFIG)) {
  100. ret = -EINVAL;
  101. goto exit_fcp_prio_cfg;
  102. }
  103. switch (oper) {
  104. case QLFC_FCP_PRIO_DISABLE:
  105. if (ha->flags.fcp_prio_enabled) {
  106. ha->flags.fcp_prio_enabled = 0;
  107. ha->fcp_prio_cfg->attributes &=
  108. ~FCP_PRIO_ATTR_ENABLE;
  109. qla24xx_update_all_fcp_prio(vha);
  110. bsg_job->reply->result = DID_OK;
  111. } else {
  112. ret = -EINVAL;
  113. bsg_job->reply->result = (DID_ERROR << 16);
  114. goto exit_fcp_prio_cfg;
  115. }
  116. break;
  117. case QLFC_FCP_PRIO_ENABLE:
  118. if (!ha->flags.fcp_prio_enabled) {
  119. if (ha->fcp_prio_cfg) {
  120. ha->flags.fcp_prio_enabled = 1;
  121. ha->fcp_prio_cfg->attributes |=
  122. FCP_PRIO_ATTR_ENABLE;
  123. qla24xx_update_all_fcp_prio(vha);
  124. bsg_job->reply->result = DID_OK;
  125. } else {
  126. ret = -EINVAL;
  127. bsg_job->reply->result = (DID_ERROR << 16);
  128. goto exit_fcp_prio_cfg;
  129. }
  130. }
  131. break;
  132. case QLFC_FCP_PRIO_GET_CONFIG:
  133. len = bsg_job->reply_payload.payload_len;
  134. if (!len || len > FCP_PRIO_CFG_SIZE) {
  135. ret = -EINVAL;
  136. bsg_job->reply->result = (DID_ERROR << 16);
  137. goto exit_fcp_prio_cfg;
  138. }
  139. bsg_job->reply->result = DID_OK;
  140. bsg_job->reply->reply_payload_rcv_len =
  141. sg_copy_from_buffer(
  142. bsg_job->reply_payload.sg_list,
  143. bsg_job->reply_payload.sg_cnt, ha->fcp_prio_cfg,
  144. len);
  145. break;
  146. case QLFC_FCP_PRIO_SET_CONFIG:
  147. len = bsg_job->request_payload.payload_len;
  148. if (!len || len > FCP_PRIO_CFG_SIZE) {
  149. bsg_job->reply->result = (DID_ERROR << 16);
  150. ret = -EINVAL;
  151. goto exit_fcp_prio_cfg;
  152. }
  153. if (!ha->fcp_prio_cfg) {
  154. ha->fcp_prio_cfg = vmalloc(FCP_PRIO_CFG_SIZE);
  155. if (!ha->fcp_prio_cfg) {
  156. ql_log(ql_log_warn, vha, 0x7050,
  157. "Unable to allocate memory for fcp prio "
  158. "config data (%x).\n", FCP_PRIO_CFG_SIZE);
  159. bsg_job->reply->result = (DID_ERROR << 16);
  160. ret = -ENOMEM;
  161. goto exit_fcp_prio_cfg;
  162. }
  163. }
  164. memset(ha->fcp_prio_cfg, 0, FCP_PRIO_CFG_SIZE);
  165. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  166. bsg_job->request_payload.sg_cnt, ha->fcp_prio_cfg,
  167. FCP_PRIO_CFG_SIZE);
  168. /* validate fcp priority data */
  169. if (!qla24xx_fcp_prio_cfg_valid(vha,
  170. (struct qla_fcp_prio_cfg *) ha->fcp_prio_cfg, 1)) {
  171. bsg_job->reply->result = (DID_ERROR << 16);
  172. ret = -EINVAL;
  173. /* If buffer was invalidatic int
  174. * fcp_prio_cfg is of no use
  175. */
  176. vfree(ha->fcp_prio_cfg);
  177. ha->fcp_prio_cfg = NULL;
  178. goto exit_fcp_prio_cfg;
  179. }
  180. ha->flags.fcp_prio_enabled = 0;
  181. if (ha->fcp_prio_cfg->attributes & FCP_PRIO_ATTR_ENABLE)
  182. ha->flags.fcp_prio_enabled = 1;
  183. qla24xx_update_all_fcp_prio(vha);
  184. bsg_job->reply->result = DID_OK;
  185. break;
  186. default:
  187. ret = -EINVAL;
  188. break;
  189. }
  190. exit_fcp_prio_cfg:
  191. bsg_job->job_done(bsg_job);
  192. return ret;
  193. }
  194. static int
  195. qla2x00_process_els(struct fc_bsg_job *bsg_job)
  196. {
  197. struct fc_rport *rport;
  198. fc_port_t *fcport = NULL;
  199. struct Scsi_Host *host;
  200. scsi_qla_host_t *vha;
  201. struct qla_hw_data *ha;
  202. srb_t *sp;
  203. const char *type;
  204. int req_sg_cnt, rsp_sg_cnt;
  205. int rval = (DRIVER_ERROR << 16);
  206. uint16_t nextlid = 0;
  207. struct srb_ctx *els;
  208. if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) {
  209. rport = bsg_job->rport;
  210. fcport = *(fc_port_t **) rport->dd_data;
  211. host = rport_to_shost(rport);
  212. vha = shost_priv(host);
  213. ha = vha->hw;
  214. type = "FC_BSG_RPT_ELS";
  215. } else {
  216. host = bsg_job->shost;
  217. vha = shost_priv(host);
  218. ha = vha->hw;
  219. type = "FC_BSG_HST_ELS_NOLOGIN";
  220. }
  221. /* pass through is supported only for ISP 4Gb or higher */
  222. if (!IS_FWI2_CAPABLE(ha)) {
  223. ql_dbg(ql_dbg_user, vha, 0x7001,
  224. "ELS passthru not supported for ISP23xx based adapters.\n");
  225. rval = -EPERM;
  226. goto done;
  227. }
  228. /* Multiple SG's are not supported for ELS requests */
  229. if (bsg_job->request_payload.sg_cnt > 1 ||
  230. bsg_job->reply_payload.sg_cnt > 1) {
  231. ql_dbg(ql_dbg_user, vha, 0x7002,
  232. "Multiple SG's are not suppored for ELS requests, "
  233. "request_sg_cnt=%x reply_sg_cnt=%x.\n",
  234. bsg_job->request_payload.sg_cnt,
  235. bsg_job->reply_payload.sg_cnt);
  236. rval = -EPERM;
  237. goto done;
  238. }
  239. /* ELS request for rport */
  240. if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) {
  241. /* make sure the rport is logged in,
  242. * if not perform fabric login
  243. */
  244. if (qla2x00_fabric_login(vha, fcport, &nextlid)) {
  245. ql_dbg(ql_dbg_user, vha, 0x7003,
  246. "Failed to login port %06X for ELS passthru.\n",
  247. fcport->d_id.b24);
  248. rval = -EIO;
  249. goto done;
  250. }
  251. } else {
  252. /* Allocate a dummy fcport structure, since functions
  253. * preparing the IOCB and mailbox command retrieves port
  254. * specific information from fcport structure. For Host based
  255. * ELS commands there will be no fcport structure allocated
  256. */
  257. fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  258. if (!fcport) {
  259. rval = -ENOMEM;
  260. goto done;
  261. }
  262. /* Initialize all required fields of fcport */
  263. fcport->vha = vha;
  264. fcport->vp_idx = vha->vp_idx;
  265. fcport->d_id.b.al_pa =
  266. bsg_job->request->rqst_data.h_els.port_id[0];
  267. fcport->d_id.b.area =
  268. bsg_job->request->rqst_data.h_els.port_id[1];
  269. fcport->d_id.b.domain =
  270. bsg_job->request->rqst_data.h_els.port_id[2];
  271. fcport->loop_id =
  272. (fcport->d_id.b.al_pa == 0xFD) ?
  273. NPH_FABRIC_CONTROLLER : NPH_F_PORT;
  274. }
  275. if (!vha->flags.online) {
  276. ql_log(ql_log_warn, vha, 0x7005, "Host not online.\n");
  277. rval = -EIO;
  278. goto done;
  279. }
  280. req_sg_cnt =
  281. dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  282. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  283. if (!req_sg_cnt) {
  284. rval = -ENOMEM;
  285. goto done_free_fcport;
  286. }
  287. rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  288. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  289. if (!rsp_sg_cnt) {
  290. rval = -ENOMEM;
  291. goto done_free_fcport;
  292. }
  293. if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
  294. (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
  295. ql_log(ql_log_warn, vha, 0x7008,
  296. "dma mapping resulted in different sg counts, "
  297. "request_sg_cnt: %x dma_request_sg_cnt:%x reply_sg_cnt:%x "
  298. "dma_reply_sg_cnt:%x.\n", bsg_job->request_payload.sg_cnt,
  299. req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
  300. rval = -EAGAIN;
  301. goto done_unmap_sg;
  302. }
  303. /* Alloc SRB structure */
  304. sp = qla2x00_get_ctx_bsg_sp(vha, fcport, sizeof(struct srb_ctx));
  305. if (!sp) {
  306. rval = -ENOMEM;
  307. goto done_unmap_sg;
  308. }
  309. els = sp->ctx;
  310. els->type =
  311. (bsg_job->request->msgcode == FC_BSG_RPT_ELS ?
  312. SRB_ELS_CMD_RPT : SRB_ELS_CMD_HST);
  313. els->name =
  314. (bsg_job->request->msgcode == FC_BSG_RPT_ELS ?
  315. "bsg_els_rpt" : "bsg_els_hst");
  316. els->u.bsg_job = bsg_job;
  317. ql_dbg(ql_dbg_user, vha, 0x700a,
  318. "bsg rqst type: %s els type: %x - loop-id=%x "
  319. "portid=%-2x%02x%02x.\n", type,
  320. bsg_job->request->rqst_data.h_els.command_code, fcport->loop_id,
  321. fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa);
  322. rval = qla2x00_start_sp(sp);
  323. if (rval != QLA_SUCCESS) {
  324. ql_log(ql_log_warn, vha, 0x700e,
  325. "qla2x00_start_sp failed = %d\n", rval);
  326. kfree(sp->ctx);
  327. mempool_free(sp, ha->srb_mempool);
  328. rval = -EIO;
  329. goto done_unmap_sg;
  330. }
  331. return rval;
  332. done_unmap_sg:
  333. dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  334. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  335. dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  336. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  337. goto done_free_fcport;
  338. done_free_fcport:
  339. if (bsg_job->request->msgcode == FC_BSG_HST_ELS_NOLOGIN)
  340. kfree(fcport);
  341. done:
  342. return rval;
  343. }
  344. inline uint16_t
  345. qla24xx_calc_ct_iocbs(uint16_t dsds)
  346. {
  347. uint16_t iocbs;
  348. iocbs = 1;
  349. if (dsds > 2) {
  350. iocbs += (dsds - 2) / 5;
  351. if ((dsds - 2) % 5)
  352. iocbs++;
  353. }
  354. return iocbs;
  355. }
  356. static int
  357. qla2x00_process_ct(struct fc_bsg_job *bsg_job)
  358. {
  359. srb_t *sp;
  360. struct Scsi_Host *host = bsg_job->shost;
  361. scsi_qla_host_t *vha = shost_priv(host);
  362. struct qla_hw_data *ha = vha->hw;
  363. int rval = (DRIVER_ERROR << 16);
  364. int req_sg_cnt, rsp_sg_cnt;
  365. uint16_t loop_id;
  366. struct fc_port *fcport;
  367. char *type = "FC_BSG_HST_CT";
  368. struct srb_ctx *ct;
  369. req_sg_cnt =
  370. dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  371. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  372. if (!req_sg_cnt) {
  373. ql_log(ql_log_warn, vha, 0x700f,
  374. "dma_map_sg return %d for request\n", req_sg_cnt);
  375. rval = -ENOMEM;
  376. goto done;
  377. }
  378. rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  379. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  380. if (!rsp_sg_cnt) {
  381. ql_log(ql_log_warn, vha, 0x7010,
  382. "dma_map_sg return %d for reply\n", rsp_sg_cnt);
  383. rval = -ENOMEM;
  384. goto done;
  385. }
  386. if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
  387. (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
  388. ql_log(ql_log_warn, vha, 0x7011,
  389. "request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt:%x "
  390. "dma_reply_sg_cnt: %x\n", bsg_job->request_payload.sg_cnt,
  391. req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
  392. rval = -EAGAIN;
  393. goto done_unmap_sg;
  394. }
  395. if (!vha->flags.online) {
  396. ql_log(ql_log_warn, vha, 0x7012,
  397. "Host is not online.\n");
  398. rval = -EIO;
  399. goto done_unmap_sg;
  400. }
  401. loop_id =
  402. (bsg_job->request->rqst_data.h_ct.preamble_word1 & 0xFF000000)
  403. >> 24;
  404. switch (loop_id) {
  405. case 0xFC:
  406. loop_id = cpu_to_le16(NPH_SNS);
  407. break;
  408. case 0xFA:
  409. loop_id = vha->mgmt_svr_loop_id;
  410. break;
  411. default:
  412. ql_dbg(ql_dbg_user, vha, 0x7013,
  413. "Unknown loop id: %x.\n", loop_id);
  414. rval = -EINVAL;
  415. goto done_unmap_sg;
  416. }
  417. /* Allocate a dummy fcport structure, since functions preparing the
  418. * IOCB and mailbox command retrieves port specific information
  419. * from fcport structure. For Host based ELS commands there will be
  420. * no fcport structure allocated
  421. */
  422. fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  423. if (!fcport) {
  424. ql_log(ql_log_warn, vha, 0x7014,
  425. "Failed to allocate fcport.\n");
  426. rval = -ENOMEM;
  427. goto done_unmap_sg;
  428. }
  429. /* Initialize all required fields of fcport */
  430. fcport->vha = vha;
  431. fcport->vp_idx = vha->vp_idx;
  432. fcport->d_id.b.al_pa = bsg_job->request->rqst_data.h_ct.port_id[0];
  433. fcport->d_id.b.area = bsg_job->request->rqst_data.h_ct.port_id[1];
  434. fcport->d_id.b.domain = bsg_job->request->rqst_data.h_ct.port_id[2];
  435. fcport->loop_id = loop_id;
  436. /* Alloc SRB structure */
  437. sp = qla2x00_get_ctx_bsg_sp(vha, fcport, sizeof(struct srb_ctx));
  438. if (!sp) {
  439. ql_log(ql_log_warn, vha, 0x7015,
  440. "qla2x00_get_ctx_bsg_sp failed.\n");
  441. rval = -ENOMEM;
  442. goto done_free_fcport;
  443. }
  444. ct = sp->ctx;
  445. ct->type = SRB_CT_CMD;
  446. ct->name = "bsg_ct";
  447. ct->iocbs = qla24xx_calc_ct_iocbs(req_sg_cnt + rsp_sg_cnt);
  448. ct->u.bsg_job = bsg_job;
  449. ql_dbg(ql_dbg_user, vha, 0x7016,
  450. "bsg rqst type: %s else type: %x - "
  451. "loop-id=%x portid=%02x%02x%02x.\n", type,
  452. (bsg_job->request->rqst_data.h_ct.preamble_word2 >> 16),
  453. fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
  454. fcport->d_id.b.al_pa);
  455. rval = qla2x00_start_sp(sp);
  456. if (rval != QLA_SUCCESS) {
  457. ql_log(ql_log_warn, vha, 0x7017,
  458. "qla2x00_start_sp failed=%d.\n", rval);
  459. kfree(sp->ctx);
  460. mempool_free(sp, ha->srb_mempool);
  461. rval = -EIO;
  462. goto done_free_fcport;
  463. }
  464. return rval;
  465. done_free_fcport:
  466. kfree(fcport);
  467. done_unmap_sg:
  468. dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  469. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  470. dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  471. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  472. done:
  473. return rval;
  474. }
  475. /* Set the port configuration to enable the
  476. * internal loopback on ISP81XX
  477. */
  478. static inline int
  479. qla81xx_set_internal_loopback(scsi_qla_host_t *vha, uint16_t *config,
  480. uint16_t *new_config)
  481. {
  482. int ret = 0;
  483. int rval = 0;
  484. struct qla_hw_data *ha = vha->hw;
  485. if (!IS_QLA81XX(ha))
  486. goto done_set_internal;
  487. new_config[0] = config[0] | (ENABLE_INTERNAL_LOOPBACK << 1);
  488. memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3) ;
  489. ha->notify_dcbx_comp = 1;
  490. ret = qla81xx_set_port_config(vha, new_config);
  491. if (ret != QLA_SUCCESS) {
  492. ql_log(ql_log_warn, vha, 0x7021,
  493. "set port config failed.\n");
  494. ha->notify_dcbx_comp = 0;
  495. rval = -EINVAL;
  496. goto done_set_internal;
  497. }
  498. /* Wait for DCBX complete event */
  499. if (!wait_for_completion_timeout(&ha->dcbx_comp, (20 * HZ))) {
  500. ql_dbg(ql_dbg_user, vha, 0x7022,
  501. "State change notification not received.\n");
  502. } else
  503. ql_dbg(ql_dbg_user, vha, 0x7023,
  504. "State change received.\n");
  505. ha->notify_dcbx_comp = 0;
  506. done_set_internal:
  507. return rval;
  508. }
  509. /* Set the port configuration to disable the
  510. * internal loopback on ISP81XX
  511. */
  512. static inline int
  513. qla81xx_reset_internal_loopback(scsi_qla_host_t *vha, uint16_t *config,
  514. int wait)
  515. {
  516. int ret = 0;
  517. int rval = 0;
  518. uint16_t new_config[4];
  519. struct qla_hw_data *ha = vha->hw;
  520. if (!IS_QLA81XX(ha))
  521. goto done_reset_internal;
  522. memset(new_config, 0 , sizeof(new_config));
  523. if ((config[0] & INTERNAL_LOOPBACK_MASK) >> 1 ==
  524. ENABLE_INTERNAL_LOOPBACK) {
  525. new_config[0] = config[0] & ~INTERNAL_LOOPBACK_MASK;
  526. memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3) ;
  527. ha->notify_dcbx_comp = wait;
  528. ret = qla81xx_set_port_config(vha, new_config);
  529. if (ret != QLA_SUCCESS) {
  530. ql_log(ql_log_warn, vha, 0x7025,
  531. "Set port config failed.\n");
  532. ha->notify_dcbx_comp = 0;
  533. rval = -EINVAL;
  534. goto done_reset_internal;
  535. }
  536. /* Wait for DCBX complete event */
  537. if (wait && !wait_for_completion_timeout(&ha->dcbx_comp,
  538. (20 * HZ))) {
  539. ql_dbg(ql_dbg_user, vha, 0x7026,
  540. "State change notification not received.\n");
  541. ha->notify_dcbx_comp = 0;
  542. rval = -EINVAL;
  543. goto done_reset_internal;
  544. } else
  545. ql_dbg(ql_dbg_user, vha, 0x7027,
  546. "State change received.\n");
  547. ha->notify_dcbx_comp = 0;
  548. }
  549. done_reset_internal:
  550. return rval;
  551. }
  552. static int
  553. qla2x00_process_loopback(struct fc_bsg_job *bsg_job)
  554. {
  555. struct Scsi_Host *host = bsg_job->shost;
  556. scsi_qla_host_t *vha = shost_priv(host);
  557. struct qla_hw_data *ha = vha->hw;
  558. int rval;
  559. uint8_t command_sent;
  560. char *type;
  561. struct msg_echo_lb elreq;
  562. uint16_t response[MAILBOX_REGISTER_COUNT];
  563. uint16_t config[4], new_config[4];
  564. uint8_t *fw_sts_ptr;
  565. uint8_t *req_data = NULL;
  566. dma_addr_t req_data_dma;
  567. uint32_t req_data_len;
  568. uint8_t *rsp_data = NULL;
  569. dma_addr_t rsp_data_dma;
  570. uint32_t rsp_data_len;
  571. if (!vha->flags.online) {
  572. ql_log(ql_log_warn, vha, 0x7019, "Host is not online.\n");
  573. return -EIO;
  574. }
  575. elreq.req_sg_cnt = dma_map_sg(&ha->pdev->dev,
  576. bsg_job->request_payload.sg_list, bsg_job->request_payload.sg_cnt,
  577. DMA_TO_DEVICE);
  578. if (!elreq.req_sg_cnt) {
  579. ql_log(ql_log_warn, vha, 0x701a,
  580. "dma_map_sg returned %d for request.\n", elreq.req_sg_cnt);
  581. return -ENOMEM;
  582. }
  583. elreq.rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
  584. bsg_job->reply_payload.sg_list, bsg_job->reply_payload.sg_cnt,
  585. DMA_FROM_DEVICE);
  586. if (!elreq.rsp_sg_cnt) {
  587. ql_log(ql_log_warn, vha, 0x701b,
  588. "dma_map_sg returned %d for reply.\n", elreq.rsp_sg_cnt);
  589. rval = -ENOMEM;
  590. goto done_unmap_req_sg;
  591. }
  592. if ((elreq.req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
  593. (elreq.rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
  594. ql_log(ql_log_warn, vha, 0x701c,
  595. "dma mapping resulted in different sg counts, "
  596. "request_sg_cnt: %x dma_request_sg_cnt: %x "
  597. "reply_sg_cnt: %x dma_reply_sg_cnt: %x.\n",
  598. bsg_job->request_payload.sg_cnt, elreq.req_sg_cnt,
  599. bsg_job->reply_payload.sg_cnt, elreq.rsp_sg_cnt);
  600. rval = -EAGAIN;
  601. goto done_unmap_sg;
  602. }
  603. req_data_len = rsp_data_len = bsg_job->request_payload.payload_len;
  604. req_data = dma_alloc_coherent(&ha->pdev->dev, req_data_len,
  605. &req_data_dma, GFP_KERNEL);
  606. if (!req_data) {
  607. ql_log(ql_log_warn, vha, 0x701d,
  608. "dma alloc failed for req_data.\n");
  609. rval = -ENOMEM;
  610. goto done_unmap_sg;
  611. }
  612. rsp_data = dma_alloc_coherent(&ha->pdev->dev, rsp_data_len,
  613. &rsp_data_dma, GFP_KERNEL);
  614. if (!rsp_data) {
  615. ql_log(ql_log_warn, vha, 0x7004,
  616. "dma alloc failed for rsp_data.\n");
  617. rval = -ENOMEM;
  618. goto done_free_dma_req;
  619. }
  620. /* Copy the request buffer in req_data now */
  621. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  622. bsg_job->request_payload.sg_cnt, req_data, req_data_len);
  623. elreq.send_dma = req_data_dma;
  624. elreq.rcv_dma = rsp_data_dma;
  625. elreq.transfer_size = req_data_len;
  626. elreq.options = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
  627. if ((ha->current_topology == ISP_CFG_F ||
  628. (atomic_read(&vha->loop_state) == LOOP_DOWN) ||
  629. (IS_QLA81XX(ha) &&
  630. le32_to_cpu(*(uint32_t *)req_data) == ELS_OPCODE_BYTE
  631. && req_data_len == MAX_ELS_FRAME_PAYLOAD)) &&
  632. elreq.options == EXTERNAL_LOOPBACK) {
  633. type = "FC_BSG_HST_VENDOR_ECHO_DIAG";
  634. ql_dbg(ql_dbg_user, vha, 0x701e,
  635. "BSG request type: %s.\n", type);
  636. command_sent = INT_DEF_LB_ECHO_CMD;
  637. rval = qla2x00_echo_test(vha, &elreq, response);
  638. } else {
  639. if (IS_QLA81XX(ha)) {
  640. memset(config, 0, sizeof(config));
  641. memset(new_config, 0, sizeof(new_config));
  642. if (qla81xx_get_port_config(vha, config)) {
  643. ql_log(ql_log_warn, vha, 0x701f,
  644. "Get port config failed.\n");
  645. bsg_job->reply->reply_payload_rcv_len = 0;
  646. bsg_job->reply->result = (DID_ERROR << 16);
  647. rval = -EPERM;
  648. goto done_free_dma_req;
  649. }
  650. if (elreq.options != EXTERNAL_LOOPBACK) {
  651. ql_dbg(ql_dbg_user, vha, 0x7020,
  652. "Internal: curent port config = %x\n",
  653. config[0]);
  654. if (qla81xx_set_internal_loopback(vha, config,
  655. new_config)) {
  656. ql_log(ql_log_warn, vha, 0x7024,
  657. "Internal loopback failed.\n");
  658. bsg_job->reply->reply_payload_rcv_len =
  659. 0;
  660. bsg_job->reply->result =
  661. (DID_ERROR << 16);
  662. rval = -EPERM;
  663. goto done_free_dma_req;
  664. }
  665. } else {
  666. /* For external loopback to work
  667. * ensure internal loopback is disabled
  668. */
  669. if (qla81xx_reset_internal_loopback(vha,
  670. config, 1)) {
  671. bsg_job->reply->reply_payload_rcv_len =
  672. 0;
  673. bsg_job->reply->result =
  674. (DID_ERROR << 16);
  675. rval = -EPERM;
  676. goto done_free_dma_req;
  677. }
  678. }
  679. type = "FC_BSG_HST_VENDOR_LOOPBACK";
  680. ql_dbg(ql_dbg_user, vha, 0x7028,
  681. "BSG request type: %s.\n", type);
  682. command_sent = INT_DEF_LB_LOOPBACK_CMD;
  683. rval = qla2x00_loopback_test(vha, &elreq, response);
  684. if (new_config[0]) {
  685. /* Revert back to original port config
  686. * Also clear internal loopback
  687. */
  688. qla81xx_reset_internal_loopback(vha,
  689. new_config, 0);
  690. }
  691. if (response[0] == MBS_COMMAND_ERROR &&
  692. response[1] == MBS_LB_RESET) {
  693. ql_log(ql_log_warn, vha, 0x7029,
  694. "MBX command error, Aborting ISP.\n");
  695. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  696. qla2xxx_wake_dpc(vha);
  697. qla2x00_wait_for_chip_reset(vha);
  698. /* Also reset the MPI */
  699. if (qla81xx_restart_mpi_firmware(vha) !=
  700. QLA_SUCCESS) {
  701. ql_log(ql_log_warn, vha, 0x702a,
  702. "MPI reset failed.\n");
  703. }
  704. bsg_job->reply->reply_payload_rcv_len = 0;
  705. bsg_job->reply->result = (DID_ERROR << 16);
  706. rval = -EIO;
  707. goto done_free_dma_req;
  708. }
  709. } else {
  710. type = "FC_BSG_HST_VENDOR_LOOPBACK";
  711. ql_dbg(ql_dbg_user, vha, 0x702b,
  712. "BSG request type: %s.\n", type);
  713. command_sent = INT_DEF_LB_LOOPBACK_CMD;
  714. rval = qla2x00_loopback_test(vha, &elreq, response);
  715. }
  716. }
  717. if (rval) {
  718. ql_log(ql_log_warn, vha, 0x702c,
  719. "Vendor request %s failed.\n", type);
  720. fw_sts_ptr = ((uint8_t *)bsg_job->req->sense) +
  721. sizeof(struct fc_bsg_reply);
  722. memcpy(fw_sts_ptr, response, sizeof(response));
  723. fw_sts_ptr += sizeof(response);
  724. *fw_sts_ptr = command_sent;
  725. rval = 0;
  726. bsg_job->reply->reply_payload_rcv_len = 0;
  727. bsg_job->reply->result = (DID_ERROR << 16);
  728. } else {
  729. ql_dbg(ql_dbg_user, vha, 0x702d,
  730. "Vendor request %s completed.\n", type);
  731. bsg_job->reply_len = sizeof(struct fc_bsg_reply) +
  732. sizeof(response) + sizeof(uint8_t);
  733. bsg_job->reply->reply_payload_rcv_len =
  734. bsg_job->reply_payload.payload_len;
  735. fw_sts_ptr = ((uint8_t *)bsg_job->req->sense) +
  736. sizeof(struct fc_bsg_reply);
  737. memcpy(fw_sts_ptr, response, sizeof(response));
  738. fw_sts_ptr += sizeof(response);
  739. *fw_sts_ptr = command_sent;
  740. bsg_job->reply->result = DID_OK;
  741. sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
  742. bsg_job->reply_payload.sg_cnt, rsp_data,
  743. rsp_data_len);
  744. }
  745. bsg_job->job_done(bsg_job);
  746. dma_free_coherent(&ha->pdev->dev, rsp_data_len,
  747. rsp_data, rsp_data_dma);
  748. done_free_dma_req:
  749. dma_free_coherent(&ha->pdev->dev, req_data_len,
  750. req_data, req_data_dma);
  751. done_unmap_sg:
  752. dma_unmap_sg(&ha->pdev->dev,
  753. bsg_job->reply_payload.sg_list,
  754. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  755. done_unmap_req_sg:
  756. dma_unmap_sg(&ha->pdev->dev,
  757. bsg_job->request_payload.sg_list,
  758. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  759. return rval;
  760. }
  761. static int
  762. qla84xx_reset(struct fc_bsg_job *bsg_job)
  763. {
  764. struct Scsi_Host *host = bsg_job->shost;
  765. scsi_qla_host_t *vha = shost_priv(host);
  766. struct qla_hw_data *ha = vha->hw;
  767. int rval = 0;
  768. uint32_t flag;
  769. if (!IS_QLA84XX(ha)) {
  770. ql_dbg(ql_dbg_user, vha, 0x702f, "Not 84xx, exiting.\n");
  771. return -EINVAL;
  772. }
  773. flag = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
  774. rval = qla84xx_reset_chip(vha, flag == A84_ISSUE_RESET_DIAG_FW);
  775. if (rval) {
  776. ql_log(ql_log_warn, vha, 0x7030,
  777. "Vendor request 84xx reset failed.\n");
  778. rval = bsg_job->reply->reply_payload_rcv_len = 0;
  779. bsg_job->reply->result = (DID_ERROR << 16);
  780. } else {
  781. ql_dbg(ql_dbg_user, vha, 0x7031,
  782. "Vendor request 84xx reset completed.\n");
  783. bsg_job->reply->result = DID_OK;
  784. }
  785. bsg_job->job_done(bsg_job);
  786. return rval;
  787. }
  788. static int
  789. qla84xx_updatefw(struct fc_bsg_job *bsg_job)
  790. {
  791. struct Scsi_Host *host = bsg_job->shost;
  792. scsi_qla_host_t *vha = shost_priv(host);
  793. struct qla_hw_data *ha = vha->hw;
  794. struct verify_chip_entry_84xx *mn = NULL;
  795. dma_addr_t mn_dma, fw_dma;
  796. void *fw_buf = NULL;
  797. int rval = 0;
  798. uint32_t sg_cnt;
  799. uint32_t data_len;
  800. uint16_t options;
  801. uint32_t flag;
  802. uint32_t fw_ver;
  803. if (!IS_QLA84XX(ha)) {
  804. ql_dbg(ql_dbg_user, vha, 0x7032,
  805. "Not 84xx, exiting.\n");
  806. return -EINVAL;
  807. }
  808. sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  809. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  810. if (!sg_cnt) {
  811. ql_log(ql_log_warn, vha, 0x7033,
  812. "dma_map_sg returned %d for request.\n", sg_cnt);
  813. return -ENOMEM;
  814. }
  815. if (sg_cnt != bsg_job->request_payload.sg_cnt) {
  816. ql_log(ql_log_warn, vha, 0x7034,
  817. "DMA mapping resulted in different sg counts, "
  818. "request_sg_cnt: %x dma_request_sg_cnt: %x.\n",
  819. bsg_job->request_payload.sg_cnt, sg_cnt);
  820. rval = -EAGAIN;
  821. goto done_unmap_sg;
  822. }
  823. data_len = bsg_job->request_payload.payload_len;
  824. fw_buf = dma_alloc_coherent(&ha->pdev->dev, data_len,
  825. &fw_dma, GFP_KERNEL);
  826. if (!fw_buf) {
  827. ql_log(ql_log_warn, vha, 0x7035,
  828. "DMA alloc failed for fw_buf.\n");
  829. rval = -ENOMEM;
  830. goto done_unmap_sg;
  831. }
  832. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  833. bsg_job->request_payload.sg_cnt, fw_buf, data_len);
  834. mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
  835. if (!mn) {
  836. ql_log(ql_log_warn, vha, 0x7036,
  837. "DMA alloc failed for fw buffer.\n");
  838. rval = -ENOMEM;
  839. goto done_free_fw_buf;
  840. }
  841. flag = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
  842. fw_ver = le32_to_cpu(*((uint32_t *)((uint32_t *)fw_buf + 2)));
  843. memset(mn, 0, sizeof(struct access_chip_84xx));
  844. mn->entry_type = VERIFY_CHIP_IOCB_TYPE;
  845. mn->entry_count = 1;
  846. options = VCO_FORCE_UPDATE | VCO_END_OF_DATA;
  847. if (flag == A84_ISSUE_UPDATE_DIAGFW_CMD)
  848. options |= VCO_DIAG_FW;
  849. mn->options = cpu_to_le16(options);
  850. mn->fw_ver = cpu_to_le32(fw_ver);
  851. mn->fw_size = cpu_to_le32(data_len);
  852. mn->fw_seq_size = cpu_to_le32(data_len);
  853. mn->dseg_address[0] = cpu_to_le32(LSD(fw_dma));
  854. mn->dseg_address[1] = cpu_to_le32(MSD(fw_dma));
  855. mn->dseg_length = cpu_to_le32(data_len);
  856. mn->data_seg_cnt = cpu_to_le16(1);
  857. rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
  858. if (rval) {
  859. ql_log(ql_log_warn, vha, 0x7037,
  860. "Vendor request 84xx updatefw failed.\n");
  861. rval = bsg_job->reply->reply_payload_rcv_len = 0;
  862. bsg_job->reply->result = (DID_ERROR << 16);
  863. } else {
  864. ql_dbg(ql_dbg_user, vha, 0x7038,
  865. "Vendor request 84xx updatefw completed.\n");
  866. bsg_job->reply_len = sizeof(struct fc_bsg_reply);
  867. bsg_job->reply->result = DID_OK;
  868. }
  869. bsg_job->job_done(bsg_job);
  870. dma_pool_free(ha->s_dma_pool, mn, mn_dma);
  871. done_free_fw_buf:
  872. dma_free_coherent(&ha->pdev->dev, data_len, fw_buf, fw_dma);
  873. done_unmap_sg:
  874. dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  875. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  876. return rval;
  877. }
  878. static int
  879. qla84xx_mgmt_cmd(struct fc_bsg_job *bsg_job)
  880. {
  881. struct Scsi_Host *host = bsg_job->shost;
  882. scsi_qla_host_t *vha = shost_priv(host);
  883. struct qla_hw_data *ha = vha->hw;
  884. struct access_chip_84xx *mn = NULL;
  885. dma_addr_t mn_dma, mgmt_dma;
  886. void *mgmt_b = NULL;
  887. int rval = 0;
  888. struct qla_bsg_a84_mgmt *ql84_mgmt;
  889. uint32_t sg_cnt;
  890. uint32_t data_len = 0;
  891. uint32_t dma_direction = DMA_NONE;
  892. if (!IS_QLA84XX(ha)) {
  893. ql_log(ql_log_warn, vha, 0x703a,
  894. "Not 84xx, exiting.\n");
  895. return -EINVAL;
  896. }
  897. ql84_mgmt = (struct qla_bsg_a84_mgmt *)((char *)bsg_job->request +
  898. sizeof(struct fc_bsg_request));
  899. if (!ql84_mgmt) {
  900. ql_log(ql_log_warn, vha, 0x703b,
  901. "MGMT header not provided, exiting.\n");
  902. return -EINVAL;
  903. }
  904. mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
  905. if (!mn) {
  906. ql_log(ql_log_warn, vha, 0x703c,
  907. "DMA alloc failed for fw buffer.\n");
  908. return -ENOMEM;
  909. }
  910. memset(mn, 0, sizeof(struct access_chip_84xx));
  911. mn->entry_type = ACCESS_CHIP_IOCB_TYPE;
  912. mn->entry_count = 1;
  913. switch (ql84_mgmt->mgmt.cmd) {
  914. case QLA84_MGMT_READ_MEM:
  915. case QLA84_MGMT_GET_INFO:
  916. sg_cnt = dma_map_sg(&ha->pdev->dev,
  917. bsg_job->reply_payload.sg_list,
  918. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  919. if (!sg_cnt) {
  920. ql_log(ql_log_warn, vha, 0x703d,
  921. "dma_map_sg returned %d for reply.\n", sg_cnt);
  922. rval = -ENOMEM;
  923. goto exit_mgmt;
  924. }
  925. dma_direction = DMA_FROM_DEVICE;
  926. if (sg_cnt != bsg_job->reply_payload.sg_cnt) {
  927. ql_log(ql_log_warn, vha, 0x703e,
  928. "DMA mapping resulted in different sg counts, "
  929. "reply_sg_cnt: %x dma_reply_sg_cnt: %x.\n",
  930. bsg_job->reply_payload.sg_cnt, sg_cnt);
  931. rval = -EAGAIN;
  932. goto done_unmap_sg;
  933. }
  934. data_len = bsg_job->reply_payload.payload_len;
  935. mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len,
  936. &mgmt_dma, GFP_KERNEL);
  937. if (!mgmt_b) {
  938. ql_log(ql_log_warn, vha, 0x703f,
  939. "DMA alloc failed for mgmt_b.\n");
  940. rval = -ENOMEM;
  941. goto done_unmap_sg;
  942. }
  943. if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) {
  944. mn->options = cpu_to_le16(ACO_DUMP_MEMORY);
  945. mn->parameter1 =
  946. cpu_to_le32(
  947. ql84_mgmt->mgmt.mgmtp.u.mem.start_addr);
  948. } else if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO) {
  949. mn->options = cpu_to_le16(ACO_REQUEST_INFO);
  950. mn->parameter1 =
  951. cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.info.type);
  952. mn->parameter2 =
  953. cpu_to_le32(
  954. ql84_mgmt->mgmt.mgmtp.u.info.context);
  955. }
  956. break;
  957. case QLA84_MGMT_WRITE_MEM:
  958. sg_cnt = dma_map_sg(&ha->pdev->dev,
  959. bsg_job->request_payload.sg_list,
  960. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  961. if (!sg_cnt) {
  962. ql_log(ql_log_warn, vha, 0x7040,
  963. "dma_map_sg returned %d.\n", sg_cnt);
  964. rval = -ENOMEM;
  965. goto exit_mgmt;
  966. }
  967. dma_direction = DMA_TO_DEVICE;
  968. if (sg_cnt != bsg_job->request_payload.sg_cnt) {
  969. ql_log(ql_log_warn, vha, 0x7041,
  970. "DMA mapping resulted in different sg counts, "
  971. "request_sg_cnt: %x dma_request_sg_cnt: %x.\n",
  972. bsg_job->request_payload.sg_cnt, sg_cnt);
  973. rval = -EAGAIN;
  974. goto done_unmap_sg;
  975. }
  976. data_len = bsg_job->request_payload.payload_len;
  977. mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len,
  978. &mgmt_dma, GFP_KERNEL);
  979. if (!mgmt_b) {
  980. ql_log(ql_log_warn, vha, 0x7042,
  981. "DMA alloc failed for mgmt_b.\n");
  982. rval = -ENOMEM;
  983. goto done_unmap_sg;
  984. }
  985. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  986. bsg_job->request_payload.sg_cnt, mgmt_b, data_len);
  987. mn->options = cpu_to_le16(ACO_LOAD_MEMORY);
  988. mn->parameter1 =
  989. cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.mem.start_addr);
  990. break;
  991. case QLA84_MGMT_CHNG_CONFIG:
  992. mn->options = cpu_to_le16(ACO_CHANGE_CONFIG_PARAM);
  993. mn->parameter1 =
  994. cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.id);
  995. mn->parameter2 =
  996. cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param0);
  997. mn->parameter3 =
  998. cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param1);
  999. break;
  1000. default:
  1001. rval = -EIO;
  1002. goto exit_mgmt;
  1003. }
  1004. if (ql84_mgmt->mgmt.cmd != QLA84_MGMT_CHNG_CONFIG) {
  1005. mn->total_byte_cnt = cpu_to_le32(ql84_mgmt->mgmt.len);
  1006. mn->dseg_count = cpu_to_le16(1);
  1007. mn->dseg_address[0] = cpu_to_le32(LSD(mgmt_dma));
  1008. mn->dseg_address[1] = cpu_to_le32(MSD(mgmt_dma));
  1009. mn->dseg_length = cpu_to_le32(ql84_mgmt->mgmt.len);
  1010. }
  1011. rval = qla2x00_issue_iocb(vha, mn, mn_dma, 0);
  1012. if (rval) {
  1013. ql_log(ql_log_warn, vha, 0x7043,
  1014. "Vendor request 84xx mgmt failed.\n");
  1015. rval = bsg_job->reply->reply_payload_rcv_len = 0;
  1016. bsg_job->reply->result = (DID_ERROR << 16);
  1017. } else {
  1018. ql_dbg(ql_dbg_user, vha, 0x7044,
  1019. "Vendor request 84xx mgmt completed.\n");
  1020. bsg_job->reply_len = sizeof(struct fc_bsg_reply);
  1021. bsg_job->reply->result = DID_OK;
  1022. if ((ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) ||
  1023. (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO)) {
  1024. bsg_job->reply->reply_payload_rcv_len =
  1025. bsg_job->reply_payload.payload_len;
  1026. sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
  1027. bsg_job->reply_payload.sg_cnt, mgmt_b,
  1028. data_len);
  1029. }
  1030. }
  1031. bsg_job->job_done(bsg_job);
  1032. done_unmap_sg:
  1033. if (mgmt_b)
  1034. dma_free_coherent(&ha->pdev->dev, data_len, mgmt_b, mgmt_dma);
  1035. if (dma_direction == DMA_TO_DEVICE)
  1036. dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  1037. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1038. else if (dma_direction == DMA_FROM_DEVICE)
  1039. dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  1040. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1041. exit_mgmt:
  1042. dma_pool_free(ha->s_dma_pool, mn, mn_dma);
  1043. return rval;
  1044. }
  1045. static int
  1046. qla24xx_iidma(struct fc_bsg_job *bsg_job)
  1047. {
  1048. struct Scsi_Host *host = bsg_job->shost;
  1049. scsi_qla_host_t *vha = shost_priv(host);
  1050. int rval = 0;
  1051. struct qla_port_param *port_param = NULL;
  1052. fc_port_t *fcport = NULL;
  1053. uint16_t mb[MAILBOX_REGISTER_COUNT];
  1054. uint8_t *rsp_ptr = NULL;
  1055. bsg_job->reply->reply_payload_rcv_len = 0;
  1056. if (!IS_IIDMA_CAPABLE(vha->hw)) {
  1057. ql_log(ql_log_info, vha, 0x7046, "iiDMA not supported.\n");
  1058. return -EINVAL;
  1059. }
  1060. port_param = (struct qla_port_param *)((char *)bsg_job->request +
  1061. sizeof(struct fc_bsg_request));
  1062. if (!port_param) {
  1063. ql_log(ql_log_warn, vha, 0x7047,
  1064. "port_param header not provided.\n");
  1065. return -EINVAL;
  1066. }
  1067. if (port_param->fc_scsi_addr.dest_type != EXT_DEF_TYPE_WWPN) {
  1068. ql_log(ql_log_warn, vha, 0x7048,
  1069. "Invalid destination type.\n");
  1070. return -EINVAL;
  1071. }
  1072. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1073. if (fcport->port_type != FCT_TARGET)
  1074. continue;
  1075. if (memcmp(port_param->fc_scsi_addr.dest_addr.wwpn,
  1076. fcport->port_name, sizeof(fcport->port_name)))
  1077. continue;
  1078. break;
  1079. }
  1080. if (!fcport) {
  1081. ql_log(ql_log_warn, vha, 0x7049,
  1082. "Failed to find port.\n");
  1083. return -EINVAL;
  1084. }
  1085. if (atomic_read(&fcport->state) != FCS_ONLINE) {
  1086. ql_log(ql_log_warn, vha, 0x704a,
  1087. "Port is not online.\n");
  1088. return -EINVAL;
  1089. }
  1090. if (fcport->flags & FCF_LOGIN_NEEDED) {
  1091. ql_log(ql_log_warn, vha, 0x704b,
  1092. "Remote port not logged in flags = 0x%x.\n", fcport->flags);
  1093. return -EINVAL;
  1094. }
  1095. if (port_param->mode)
  1096. rval = qla2x00_set_idma_speed(vha, fcport->loop_id,
  1097. port_param->speed, mb);
  1098. else
  1099. rval = qla2x00_get_idma_speed(vha, fcport->loop_id,
  1100. &port_param->speed, mb);
  1101. if (rval) {
  1102. ql_log(ql_log_warn, vha, 0x704c,
  1103. "iIDMA cmd failed for %02x%02x%02x%02x%02x%02x%02x%02x -- "
  1104. "%04x %x %04x %04x.\n", fcport->port_name[0],
  1105. fcport->port_name[1], fcport->port_name[2],
  1106. fcport->port_name[3], fcport->port_name[4],
  1107. fcport->port_name[5], fcport->port_name[6],
  1108. fcport->port_name[7], rval, fcport->fp_speed, mb[0], mb[1]);
  1109. rval = 0;
  1110. bsg_job->reply->result = (DID_ERROR << 16);
  1111. } else {
  1112. if (!port_param->mode) {
  1113. bsg_job->reply_len = sizeof(struct fc_bsg_reply) +
  1114. sizeof(struct qla_port_param);
  1115. rsp_ptr = ((uint8_t *)bsg_job->reply) +
  1116. sizeof(struct fc_bsg_reply);
  1117. memcpy(rsp_ptr, port_param,
  1118. sizeof(struct qla_port_param));
  1119. }
  1120. bsg_job->reply->result = DID_OK;
  1121. }
  1122. bsg_job->job_done(bsg_job);
  1123. return rval;
  1124. }
  1125. static int
  1126. qla2x00_optrom_setup(struct fc_bsg_job *bsg_job, scsi_qla_host_t *vha,
  1127. uint8_t is_update)
  1128. {
  1129. uint32_t start = 0;
  1130. int valid = 0;
  1131. struct qla_hw_data *ha = vha->hw;
  1132. bsg_job->reply->reply_payload_rcv_len = 0;
  1133. if (unlikely(pci_channel_offline(ha->pdev)))
  1134. return -EINVAL;
  1135. start = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
  1136. if (start > ha->optrom_size) {
  1137. ql_log(ql_log_warn, vha, 0x7055,
  1138. "start %d > optrom_size %d.\n", start, ha->optrom_size);
  1139. return -EINVAL;
  1140. }
  1141. if (ha->optrom_state != QLA_SWAITING) {
  1142. ql_log(ql_log_info, vha, 0x7056,
  1143. "optrom_state %d.\n", ha->optrom_state);
  1144. return -EBUSY;
  1145. }
  1146. ha->optrom_region_start = start;
  1147. ql_dbg(ql_dbg_user, vha, 0x7057, "is_update=%d.\n", is_update);
  1148. if (is_update) {
  1149. if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
  1150. valid = 1;
  1151. else if (start == (ha->flt_region_boot * 4) ||
  1152. start == (ha->flt_region_fw * 4))
  1153. valid = 1;
  1154. else if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) ||
  1155. IS_QLA8XXX_TYPE(ha))
  1156. valid = 1;
  1157. if (!valid) {
  1158. ql_log(ql_log_warn, vha, 0x7058,
  1159. "Invalid start region 0x%x/0x%x.\n", start,
  1160. bsg_job->request_payload.payload_len);
  1161. return -EINVAL;
  1162. }
  1163. ha->optrom_region_size = start +
  1164. bsg_job->request_payload.payload_len > ha->optrom_size ?
  1165. ha->optrom_size - start :
  1166. bsg_job->request_payload.payload_len;
  1167. ha->optrom_state = QLA_SWRITING;
  1168. } else {
  1169. ha->optrom_region_size = start +
  1170. bsg_job->reply_payload.payload_len > ha->optrom_size ?
  1171. ha->optrom_size - start :
  1172. bsg_job->reply_payload.payload_len;
  1173. ha->optrom_state = QLA_SREADING;
  1174. }
  1175. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  1176. if (!ha->optrom_buffer) {
  1177. ql_log(ql_log_warn, vha, 0x7059,
  1178. "Read: Unable to allocate memory for optrom retrieval "
  1179. "(%x)\n", ha->optrom_region_size);
  1180. ha->optrom_state = QLA_SWAITING;
  1181. return -ENOMEM;
  1182. }
  1183. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  1184. return 0;
  1185. }
  1186. static int
  1187. qla2x00_read_optrom(struct fc_bsg_job *bsg_job)
  1188. {
  1189. struct Scsi_Host *host = bsg_job->shost;
  1190. scsi_qla_host_t *vha = shost_priv(host);
  1191. struct qla_hw_data *ha = vha->hw;
  1192. int rval = 0;
  1193. rval = qla2x00_optrom_setup(bsg_job, vha, 0);
  1194. if (rval)
  1195. return rval;
  1196. ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
  1197. ha->optrom_region_start, ha->optrom_region_size);
  1198. sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
  1199. bsg_job->reply_payload.sg_cnt, ha->optrom_buffer,
  1200. ha->optrom_region_size);
  1201. bsg_job->reply->reply_payload_rcv_len = ha->optrom_region_size;
  1202. bsg_job->reply->result = DID_OK;
  1203. vfree(ha->optrom_buffer);
  1204. ha->optrom_buffer = NULL;
  1205. ha->optrom_state = QLA_SWAITING;
  1206. bsg_job->job_done(bsg_job);
  1207. return rval;
  1208. }
  1209. static int
  1210. qla2x00_update_optrom(struct fc_bsg_job *bsg_job)
  1211. {
  1212. struct Scsi_Host *host = bsg_job->shost;
  1213. scsi_qla_host_t *vha = shost_priv(host);
  1214. struct qla_hw_data *ha = vha->hw;
  1215. int rval = 0;
  1216. rval = qla2x00_optrom_setup(bsg_job, vha, 1);
  1217. if (rval)
  1218. return rval;
  1219. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  1220. bsg_job->request_payload.sg_cnt, ha->optrom_buffer,
  1221. ha->optrom_region_size);
  1222. ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
  1223. ha->optrom_region_start, ha->optrom_region_size);
  1224. bsg_job->reply->result = DID_OK;
  1225. vfree(ha->optrom_buffer);
  1226. ha->optrom_buffer = NULL;
  1227. ha->optrom_state = QLA_SWAITING;
  1228. bsg_job->job_done(bsg_job);
  1229. return rval;
  1230. }
  1231. static int
  1232. qla2x00_update_fru_versions(struct fc_bsg_job *bsg_job)
  1233. {
  1234. struct Scsi_Host *host = bsg_job->shost;
  1235. scsi_qla_host_t *vha = shost_priv(host);
  1236. struct qla_hw_data *ha = vha->hw;
  1237. int rval = 0;
  1238. uint8_t bsg[DMA_POOL_SIZE];
  1239. struct qla_image_version_list *list = (void *)bsg;
  1240. struct qla_image_version *image;
  1241. uint32_t count;
  1242. dma_addr_t sfp_dma;
  1243. void *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
  1244. if (!sfp) {
  1245. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
  1246. EXT_STATUS_NO_MEMORY;
  1247. goto done;
  1248. }
  1249. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  1250. bsg_job->request_payload.sg_cnt, list, sizeof(bsg));
  1251. image = list->version;
  1252. count = list->count;
  1253. while (count--) {
  1254. memcpy(sfp, &image->field_info, sizeof(image->field_info));
  1255. rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
  1256. image->field_address.device, image->field_address.offset,
  1257. sizeof(image->field_info), image->field_address.option);
  1258. if (rval) {
  1259. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
  1260. EXT_STATUS_MAILBOX;
  1261. goto dealloc;
  1262. }
  1263. image++;
  1264. }
  1265. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
  1266. dealloc:
  1267. dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
  1268. done:
  1269. bsg_job->reply_len = sizeof(struct fc_bsg_reply);
  1270. bsg_job->reply->result = DID_OK << 16;
  1271. bsg_job->job_done(bsg_job);
  1272. return 0;
  1273. }
  1274. static int
  1275. qla2x00_read_fru_status(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_status_reg *sr = (void *)bsg;
  1283. dma_addr_t sfp_dma;
  1284. uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
  1285. if (!sfp) {
  1286. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
  1287. EXT_STATUS_NO_MEMORY;
  1288. goto done;
  1289. }
  1290. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  1291. bsg_job->request_payload.sg_cnt, sr, sizeof(*sr));
  1292. rval = qla2x00_read_sfp(vha, sfp_dma, sfp,
  1293. sr->field_address.device, sr->field_address.offset,
  1294. sizeof(sr->status_reg), sr->field_address.option);
  1295. sr->status_reg = *sfp;
  1296. if (rval) {
  1297. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
  1298. EXT_STATUS_MAILBOX;
  1299. goto dealloc;
  1300. }
  1301. sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
  1302. bsg_job->reply_payload.sg_cnt, sr, sizeof(*sr));
  1303. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
  1304. dealloc:
  1305. dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
  1306. done:
  1307. bsg_job->reply_len = sizeof(struct fc_bsg_reply);
  1308. bsg_job->reply->reply_payload_rcv_len = sizeof(*sr);
  1309. bsg_job->reply->result = DID_OK << 16;
  1310. bsg_job->job_done(bsg_job);
  1311. return 0;
  1312. }
  1313. static int
  1314. qla2x00_write_fru_status(struct fc_bsg_job *bsg_job)
  1315. {
  1316. struct Scsi_Host *host = bsg_job->shost;
  1317. scsi_qla_host_t *vha = shost_priv(host);
  1318. struct qla_hw_data *ha = vha->hw;
  1319. int rval = 0;
  1320. uint8_t bsg[DMA_POOL_SIZE];
  1321. struct qla_status_reg *sr = (void *)bsg;
  1322. dma_addr_t sfp_dma;
  1323. uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
  1324. if (!sfp) {
  1325. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
  1326. EXT_STATUS_NO_MEMORY;
  1327. goto done;
  1328. }
  1329. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  1330. bsg_job->request_payload.sg_cnt, sr, sizeof(*sr));
  1331. *sfp = sr->status_reg;
  1332. rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
  1333. sr->field_address.device, sr->field_address.offset,
  1334. sizeof(sr->status_reg), sr->field_address.option);
  1335. if (rval) {
  1336. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
  1337. EXT_STATUS_MAILBOX;
  1338. goto dealloc;
  1339. }
  1340. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
  1341. dealloc:
  1342. dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
  1343. done:
  1344. bsg_job->reply_len = sizeof(struct fc_bsg_reply);
  1345. bsg_job->reply->result = DID_OK << 16;
  1346. bsg_job->job_done(bsg_job);
  1347. return 0;
  1348. }
  1349. static int
  1350. qla2x00_process_vendor_specific(struct fc_bsg_job *bsg_job)
  1351. {
  1352. switch (bsg_job->request->rqst_data.h_vendor.vendor_cmd[0]) {
  1353. case QL_VND_LOOPBACK:
  1354. return qla2x00_process_loopback(bsg_job);
  1355. case QL_VND_A84_RESET:
  1356. return qla84xx_reset(bsg_job);
  1357. case QL_VND_A84_UPDATE_FW:
  1358. return qla84xx_updatefw(bsg_job);
  1359. case QL_VND_A84_MGMT_CMD:
  1360. return qla84xx_mgmt_cmd(bsg_job);
  1361. case QL_VND_IIDMA:
  1362. return qla24xx_iidma(bsg_job);
  1363. case QL_VND_FCP_PRIO_CFG_CMD:
  1364. return qla24xx_proc_fcp_prio_cfg_cmd(bsg_job);
  1365. case QL_VND_READ_FLASH:
  1366. return qla2x00_read_optrom(bsg_job);
  1367. case QL_VND_UPDATE_FLASH:
  1368. return qla2x00_update_optrom(bsg_job);
  1369. case QL_VND_SET_FRU_VERSION:
  1370. return qla2x00_update_fru_versions(bsg_job);
  1371. case QL_VND_READ_FRU_STATUS:
  1372. return qla2x00_read_fru_status(bsg_job);
  1373. case QL_VND_WRITE_FRU_STATUS:
  1374. return qla2x00_write_fru_status(bsg_job);
  1375. default:
  1376. bsg_job->reply->result = (DID_ERROR << 16);
  1377. bsg_job->job_done(bsg_job);
  1378. return -ENOSYS;
  1379. }
  1380. }
  1381. int
  1382. qla24xx_bsg_request(struct fc_bsg_job *bsg_job)
  1383. {
  1384. int ret = -EINVAL;
  1385. struct fc_rport *rport;
  1386. fc_port_t *fcport = NULL;
  1387. struct Scsi_Host *host;
  1388. scsi_qla_host_t *vha;
  1389. if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) {
  1390. rport = bsg_job->rport;
  1391. fcport = *(fc_port_t **) rport->dd_data;
  1392. host = rport_to_shost(rport);
  1393. vha = shost_priv(host);
  1394. } else {
  1395. host = bsg_job->shost;
  1396. vha = shost_priv(host);
  1397. }
  1398. if (qla2x00_reset_active(vha)) {
  1399. ql_dbg(ql_dbg_user, vha, 0x709f,
  1400. "BSG: ISP abort active/needed -- cmd=%d.\n",
  1401. bsg_job->request->msgcode);
  1402. bsg_job->reply->result = (DID_ERROR << 16);
  1403. bsg_job->job_done(bsg_job);
  1404. return -EBUSY;
  1405. }
  1406. ql_dbg(ql_dbg_user, vha, 0x7000,
  1407. "Entered %s msgcode=0x%x.\n", __func__, bsg_job->request->msgcode);
  1408. switch (bsg_job->request->msgcode) {
  1409. case FC_BSG_RPT_ELS:
  1410. case FC_BSG_HST_ELS_NOLOGIN:
  1411. ret = qla2x00_process_els(bsg_job);
  1412. break;
  1413. case FC_BSG_HST_CT:
  1414. ret = qla2x00_process_ct(bsg_job);
  1415. break;
  1416. case FC_BSG_HST_VENDOR:
  1417. ret = qla2x00_process_vendor_specific(bsg_job);
  1418. break;
  1419. case FC_BSG_HST_ADD_RPORT:
  1420. case FC_BSG_HST_DEL_RPORT:
  1421. case FC_BSG_RPT_CT:
  1422. default:
  1423. ql_log(ql_log_warn, vha, 0x705a, "Unsupported BSG request.\n");
  1424. break;
  1425. }
  1426. return ret;
  1427. }
  1428. int
  1429. qla24xx_bsg_timeout(struct fc_bsg_job *bsg_job)
  1430. {
  1431. scsi_qla_host_t *vha = shost_priv(bsg_job->shost);
  1432. struct qla_hw_data *ha = vha->hw;
  1433. srb_t *sp;
  1434. int cnt, que;
  1435. unsigned long flags;
  1436. struct req_que *req;
  1437. struct srb_ctx *sp_bsg;
  1438. /* find the bsg job from the active list of commands */
  1439. spin_lock_irqsave(&ha->hardware_lock, flags);
  1440. for (que = 0; que < ha->max_req_queues; que++) {
  1441. req = ha->req_q_map[que];
  1442. if (!req)
  1443. continue;
  1444. for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
  1445. sp = req->outstanding_cmds[cnt];
  1446. if (sp) {
  1447. sp_bsg = sp->ctx;
  1448. if (((sp_bsg->type == SRB_CT_CMD) ||
  1449. (sp_bsg->type == SRB_ELS_CMD_HST))
  1450. && (sp_bsg->u.bsg_job == bsg_job)) {
  1451. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1452. if (ha->isp_ops->abort_command(sp)) {
  1453. ql_log(ql_log_warn, vha, 0x7089,
  1454. "mbx abort_command "
  1455. "failed.\n");
  1456. bsg_job->req->errors =
  1457. bsg_job->reply->result = -EIO;
  1458. } else {
  1459. ql_dbg(ql_dbg_user, vha, 0x708a,
  1460. "mbx abort_command "
  1461. "success.\n");
  1462. bsg_job->req->errors =
  1463. bsg_job->reply->result = 0;
  1464. }
  1465. spin_lock_irqsave(&ha->hardware_lock, flags);
  1466. goto done;
  1467. }
  1468. }
  1469. }
  1470. }
  1471. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1472. ql_log(ql_log_info, vha, 0x708b, "SRB not found to abort.\n");
  1473. bsg_job->req->errors = bsg_job->reply->result = -ENXIO;
  1474. return 0;
  1475. done:
  1476. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1477. if (bsg_job->request->msgcode == FC_BSG_HST_CT)
  1478. kfree(sp->fcport);
  1479. kfree(sp->ctx);
  1480. mempool_free(sp, ha->srb_mempool);
  1481. return 0;
  1482. }