qla_bsg.c 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179
  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_QLA82XX(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. /* pass through is supported only for ISP 4Gb or higher */
  240. if (!IS_FWI2_CAPABLE(ha)) {
  241. ql_dbg(ql_dbg_user, vha, 0x7001,
  242. "ELS passthru not supported for ISP23xx based adapters.\n");
  243. rval = -EPERM;
  244. goto done;
  245. }
  246. /* Multiple SG's are not supported for ELS requests */
  247. if (bsg_job->request_payload.sg_cnt > 1 ||
  248. bsg_job->reply_payload.sg_cnt > 1) {
  249. ql_dbg(ql_dbg_user, vha, 0x7002,
  250. "Multiple SG's are not suppored for ELS requests, "
  251. "request_sg_cnt=%x reply_sg_cnt=%x.\n",
  252. bsg_job->request_payload.sg_cnt,
  253. bsg_job->reply_payload.sg_cnt);
  254. rval = -EPERM;
  255. goto done;
  256. }
  257. /* ELS request for rport */
  258. if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) {
  259. /* make sure the rport is logged in,
  260. * if not perform fabric login
  261. */
  262. if (qla2x00_fabric_login(vha, fcport, &nextlid)) {
  263. ql_dbg(ql_dbg_user, vha, 0x7003,
  264. "Failed to login port %06X for ELS passthru.\n",
  265. fcport->d_id.b24);
  266. rval = -EIO;
  267. goto done;
  268. }
  269. } else {
  270. /* Allocate a dummy fcport structure, since functions
  271. * preparing the IOCB and mailbox command retrieves port
  272. * specific information from fcport structure. For Host based
  273. * ELS commands there will be no fcport structure allocated
  274. */
  275. fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  276. if (!fcport) {
  277. rval = -ENOMEM;
  278. goto done;
  279. }
  280. /* Initialize all required fields of fcport */
  281. fcport->vha = vha;
  282. fcport->d_id.b.al_pa =
  283. bsg_job->request->rqst_data.h_els.port_id[0];
  284. fcport->d_id.b.area =
  285. bsg_job->request->rqst_data.h_els.port_id[1];
  286. fcport->d_id.b.domain =
  287. bsg_job->request->rqst_data.h_els.port_id[2];
  288. fcport->loop_id =
  289. (fcport->d_id.b.al_pa == 0xFD) ?
  290. NPH_FABRIC_CONTROLLER : NPH_F_PORT;
  291. }
  292. if (!vha->flags.online) {
  293. ql_log(ql_log_warn, vha, 0x7005, "Host not online.\n");
  294. rval = -EIO;
  295. goto done;
  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_HST_ELS_NOLOGIN)
  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))
  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))
  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)) &&
  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)) {
  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))
  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. ql84_mgmt = (struct qla_bsg_a84_mgmt *)((char *)bsg_job->request +
  953. sizeof(struct fc_bsg_request));
  954. if (!ql84_mgmt) {
  955. ql_log(ql_log_warn, vha, 0x703b,
  956. "MGMT header not provided, exiting.\n");
  957. return -EINVAL;
  958. }
  959. mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
  960. if (!mn) {
  961. ql_log(ql_log_warn, vha, 0x703c,
  962. "DMA alloc failed for fw buffer.\n");
  963. return -ENOMEM;
  964. }
  965. memset(mn, 0, sizeof(struct access_chip_84xx));
  966. mn->entry_type = ACCESS_CHIP_IOCB_TYPE;
  967. mn->entry_count = 1;
  968. switch (ql84_mgmt->mgmt.cmd) {
  969. case QLA84_MGMT_READ_MEM:
  970. case QLA84_MGMT_GET_INFO:
  971. sg_cnt = dma_map_sg(&ha->pdev->dev,
  972. bsg_job->reply_payload.sg_list,
  973. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  974. if (!sg_cnt) {
  975. ql_log(ql_log_warn, vha, 0x703d,
  976. "dma_map_sg returned %d for reply.\n", sg_cnt);
  977. rval = -ENOMEM;
  978. goto exit_mgmt;
  979. }
  980. dma_direction = DMA_FROM_DEVICE;
  981. if (sg_cnt != bsg_job->reply_payload.sg_cnt) {
  982. ql_log(ql_log_warn, vha, 0x703e,
  983. "DMA mapping resulted in different sg counts, "
  984. "reply_sg_cnt: %x dma_reply_sg_cnt: %x.\n",
  985. bsg_job->reply_payload.sg_cnt, sg_cnt);
  986. rval = -EAGAIN;
  987. goto done_unmap_sg;
  988. }
  989. data_len = bsg_job->reply_payload.payload_len;
  990. mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len,
  991. &mgmt_dma, GFP_KERNEL);
  992. if (!mgmt_b) {
  993. ql_log(ql_log_warn, vha, 0x703f,
  994. "DMA alloc failed for mgmt_b.\n");
  995. rval = -ENOMEM;
  996. goto done_unmap_sg;
  997. }
  998. if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) {
  999. mn->options = cpu_to_le16(ACO_DUMP_MEMORY);
  1000. mn->parameter1 =
  1001. cpu_to_le32(
  1002. ql84_mgmt->mgmt.mgmtp.u.mem.start_addr);
  1003. } else if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO) {
  1004. mn->options = cpu_to_le16(ACO_REQUEST_INFO);
  1005. mn->parameter1 =
  1006. cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.info.type);
  1007. mn->parameter2 =
  1008. cpu_to_le32(
  1009. ql84_mgmt->mgmt.mgmtp.u.info.context);
  1010. }
  1011. break;
  1012. case QLA84_MGMT_WRITE_MEM:
  1013. sg_cnt = dma_map_sg(&ha->pdev->dev,
  1014. bsg_job->request_payload.sg_list,
  1015. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1016. if (!sg_cnt) {
  1017. ql_log(ql_log_warn, vha, 0x7040,
  1018. "dma_map_sg returned %d.\n", sg_cnt);
  1019. rval = -ENOMEM;
  1020. goto exit_mgmt;
  1021. }
  1022. dma_direction = DMA_TO_DEVICE;
  1023. if (sg_cnt != bsg_job->request_payload.sg_cnt) {
  1024. ql_log(ql_log_warn, vha, 0x7041,
  1025. "DMA mapping resulted in different sg counts, "
  1026. "request_sg_cnt: %x dma_request_sg_cnt: %x.\n",
  1027. bsg_job->request_payload.sg_cnt, sg_cnt);
  1028. rval = -EAGAIN;
  1029. goto done_unmap_sg;
  1030. }
  1031. data_len = bsg_job->request_payload.payload_len;
  1032. mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len,
  1033. &mgmt_dma, GFP_KERNEL);
  1034. if (!mgmt_b) {
  1035. ql_log(ql_log_warn, vha, 0x7042,
  1036. "DMA alloc failed for mgmt_b.\n");
  1037. rval = -ENOMEM;
  1038. goto done_unmap_sg;
  1039. }
  1040. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  1041. bsg_job->request_payload.sg_cnt, mgmt_b, data_len);
  1042. mn->options = cpu_to_le16(ACO_LOAD_MEMORY);
  1043. mn->parameter1 =
  1044. cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.mem.start_addr);
  1045. break;
  1046. case QLA84_MGMT_CHNG_CONFIG:
  1047. mn->options = cpu_to_le16(ACO_CHANGE_CONFIG_PARAM);
  1048. mn->parameter1 =
  1049. cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.id);
  1050. mn->parameter2 =
  1051. cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param0);
  1052. mn->parameter3 =
  1053. cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param1);
  1054. break;
  1055. default:
  1056. rval = -EIO;
  1057. goto exit_mgmt;
  1058. }
  1059. if (ql84_mgmt->mgmt.cmd != QLA84_MGMT_CHNG_CONFIG) {
  1060. mn->total_byte_cnt = cpu_to_le32(ql84_mgmt->mgmt.len);
  1061. mn->dseg_count = cpu_to_le16(1);
  1062. mn->dseg_address[0] = cpu_to_le32(LSD(mgmt_dma));
  1063. mn->dseg_address[1] = cpu_to_le32(MSD(mgmt_dma));
  1064. mn->dseg_length = cpu_to_le32(ql84_mgmt->mgmt.len);
  1065. }
  1066. rval = qla2x00_issue_iocb(vha, mn, mn_dma, 0);
  1067. if (rval) {
  1068. ql_log(ql_log_warn, vha, 0x7043,
  1069. "Vendor request 84xx mgmt failed.\n");
  1070. rval = (DID_ERROR << 16);
  1071. } else {
  1072. ql_dbg(ql_dbg_user, vha, 0x7044,
  1073. "Vendor request 84xx mgmt completed.\n");
  1074. bsg_job->reply_len = sizeof(struct fc_bsg_reply);
  1075. bsg_job->reply->result = DID_OK;
  1076. if ((ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) ||
  1077. (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO)) {
  1078. bsg_job->reply->reply_payload_rcv_len =
  1079. bsg_job->reply_payload.payload_len;
  1080. sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
  1081. bsg_job->reply_payload.sg_cnt, mgmt_b,
  1082. data_len);
  1083. }
  1084. }
  1085. done_unmap_sg:
  1086. if (mgmt_b)
  1087. dma_free_coherent(&ha->pdev->dev, data_len, mgmt_b, mgmt_dma);
  1088. if (dma_direction == DMA_TO_DEVICE)
  1089. dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  1090. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1091. else if (dma_direction == DMA_FROM_DEVICE)
  1092. dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  1093. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1094. exit_mgmt:
  1095. dma_pool_free(ha->s_dma_pool, mn, mn_dma);
  1096. if (!rval)
  1097. bsg_job->job_done(bsg_job);
  1098. return rval;
  1099. }
  1100. static int
  1101. qla24xx_iidma(struct fc_bsg_job *bsg_job)
  1102. {
  1103. struct Scsi_Host *host = bsg_job->shost;
  1104. scsi_qla_host_t *vha = shost_priv(host);
  1105. int rval = 0;
  1106. struct qla_port_param *port_param = NULL;
  1107. fc_port_t *fcport = NULL;
  1108. uint16_t mb[MAILBOX_REGISTER_COUNT];
  1109. uint8_t *rsp_ptr = NULL;
  1110. if (!IS_IIDMA_CAPABLE(vha->hw)) {
  1111. ql_log(ql_log_info, vha, 0x7046, "iiDMA not supported.\n");
  1112. return -EINVAL;
  1113. }
  1114. port_param = (void *)bsg_job->request + sizeof(struct fc_bsg_request);
  1115. if (port_param->fc_scsi_addr.dest_type != EXT_DEF_TYPE_WWPN) {
  1116. ql_log(ql_log_warn, vha, 0x7048,
  1117. "Invalid destination type.\n");
  1118. return -EINVAL;
  1119. }
  1120. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1121. if (fcport->port_type != FCT_TARGET)
  1122. continue;
  1123. if (memcmp(port_param->fc_scsi_addr.dest_addr.wwpn,
  1124. fcport->port_name, sizeof(fcport->port_name)))
  1125. continue;
  1126. break;
  1127. }
  1128. if (!fcport) {
  1129. ql_log(ql_log_warn, vha, 0x7049,
  1130. "Failed to find port.\n");
  1131. return -EINVAL;
  1132. }
  1133. if (atomic_read(&fcport->state) != FCS_ONLINE) {
  1134. ql_log(ql_log_warn, vha, 0x704a,
  1135. "Port is not online.\n");
  1136. return -EINVAL;
  1137. }
  1138. if (fcport->flags & FCF_LOGIN_NEEDED) {
  1139. ql_log(ql_log_warn, vha, 0x704b,
  1140. "Remote port not logged in flags = 0x%x.\n", fcport->flags);
  1141. return -EINVAL;
  1142. }
  1143. if (port_param->mode)
  1144. rval = qla2x00_set_idma_speed(vha, fcport->loop_id,
  1145. port_param->speed, mb);
  1146. else
  1147. rval = qla2x00_get_idma_speed(vha, fcport->loop_id,
  1148. &port_param->speed, mb);
  1149. if (rval) {
  1150. ql_log(ql_log_warn, vha, 0x704c,
  1151. "iIDMA cmd failed for %02x%02x%02x%02x%02x%02x%02x%02x -- "
  1152. "%04x %x %04x %04x.\n", fcport->port_name[0],
  1153. fcport->port_name[1], fcport->port_name[2],
  1154. fcport->port_name[3], fcport->port_name[4],
  1155. fcport->port_name[5], fcport->port_name[6],
  1156. fcport->port_name[7], rval, fcport->fp_speed, mb[0], mb[1]);
  1157. rval = (DID_ERROR << 16);
  1158. } else {
  1159. if (!port_param->mode) {
  1160. bsg_job->reply_len = sizeof(struct fc_bsg_reply) +
  1161. sizeof(struct qla_port_param);
  1162. rsp_ptr = ((uint8_t *)bsg_job->reply) +
  1163. sizeof(struct fc_bsg_reply);
  1164. memcpy(rsp_ptr, port_param,
  1165. sizeof(struct qla_port_param));
  1166. }
  1167. bsg_job->reply->result = DID_OK;
  1168. bsg_job->job_done(bsg_job);
  1169. }
  1170. return rval;
  1171. }
  1172. static int
  1173. qla2x00_optrom_setup(struct fc_bsg_job *bsg_job, scsi_qla_host_t *vha,
  1174. uint8_t is_update)
  1175. {
  1176. uint32_t start = 0;
  1177. int valid = 0;
  1178. struct qla_hw_data *ha = vha->hw;
  1179. if (unlikely(pci_channel_offline(ha->pdev)))
  1180. return -EINVAL;
  1181. start = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
  1182. if (start > ha->optrom_size) {
  1183. ql_log(ql_log_warn, vha, 0x7055,
  1184. "start %d > optrom_size %d.\n", start, ha->optrom_size);
  1185. return -EINVAL;
  1186. }
  1187. if (ha->optrom_state != QLA_SWAITING) {
  1188. ql_log(ql_log_info, vha, 0x7056,
  1189. "optrom_state %d.\n", ha->optrom_state);
  1190. return -EBUSY;
  1191. }
  1192. ha->optrom_region_start = start;
  1193. ql_dbg(ql_dbg_user, vha, 0x7057, "is_update=%d.\n", is_update);
  1194. if (is_update) {
  1195. if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
  1196. valid = 1;
  1197. else if (start == (ha->flt_region_boot * 4) ||
  1198. start == (ha->flt_region_fw * 4))
  1199. valid = 1;
  1200. else if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) ||
  1201. IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
  1202. valid = 1;
  1203. if (!valid) {
  1204. ql_log(ql_log_warn, vha, 0x7058,
  1205. "Invalid start region 0x%x/0x%x.\n", start,
  1206. bsg_job->request_payload.payload_len);
  1207. return -EINVAL;
  1208. }
  1209. ha->optrom_region_size = start +
  1210. bsg_job->request_payload.payload_len > ha->optrom_size ?
  1211. ha->optrom_size - start :
  1212. bsg_job->request_payload.payload_len;
  1213. ha->optrom_state = QLA_SWRITING;
  1214. } else {
  1215. ha->optrom_region_size = start +
  1216. bsg_job->reply_payload.payload_len > ha->optrom_size ?
  1217. ha->optrom_size - start :
  1218. bsg_job->reply_payload.payload_len;
  1219. ha->optrom_state = QLA_SREADING;
  1220. }
  1221. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  1222. if (!ha->optrom_buffer) {
  1223. ql_log(ql_log_warn, vha, 0x7059,
  1224. "Read: Unable to allocate memory for optrom retrieval "
  1225. "(%x)\n", ha->optrom_region_size);
  1226. ha->optrom_state = QLA_SWAITING;
  1227. return -ENOMEM;
  1228. }
  1229. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  1230. return 0;
  1231. }
  1232. static int
  1233. qla2x00_read_optrom(struct fc_bsg_job *bsg_job)
  1234. {
  1235. struct Scsi_Host *host = bsg_job->shost;
  1236. scsi_qla_host_t *vha = shost_priv(host);
  1237. struct qla_hw_data *ha = vha->hw;
  1238. int rval = 0;
  1239. if (ha->flags.nic_core_reset_hdlr_active)
  1240. return -EBUSY;
  1241. rval = qla2x00_optrom_setup(bsg_job, vha, 0);
  1242. if (rval)
  1243. return rval;
  1244. ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
  1245. ha->optrom_region_start, ha->optrom_region_size);
  1246. sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
  1247. bsg_job->reply_payload.sg_cnt, ha->optrom_buffer,
  1248. ha->optrom_region_size);
  1249. bsg_job->reply->reply_payload_rcv_len = ha->optrom_region_size;
  1250. bsg_job->reply->result = DID_OK;
  1251. vfree(ha->optrom_buffer);
  1252. ha->optrom_buffer = NULL;
  1253. ha->optrom_state = QLA_SWAITING;
  1254. bsg_job->job_done(bsg_job);
  1255. return rval;
  1256. }
  1257. static int
  1258. qla2x00_update_optrom(struct fc_bsg_job *bsg_job)
  1259. {
  1260. struct Scsi_Host *host = bsg_job->shost;
  1261. scsi_qla_host_t *vha = shost_priv(host);
  1262. struct qla_hw_data *ha = vha->hw;
  1263. int rval = 0;
  1264. rval = qla2x00_optrom_setup(bsg_job, vha, 1);
  1265. if (rval)
  1266. return rval;
  1267. /* Set the isp82xx_no_md_cap not to capture minidump */
  1268. ha->flags.isp82xx_no_md_cap = 1;
  1269. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  1270. bsg_job->request_payload.sg_cnt, ha->optrom_buffer,
  1271. ha->optrom_region_size);
  1272. ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
  1273. ha->optrom_region_start, ha->optrom_region_size);
  1274. bsg_job->reply->result = DID_OK;
  1275. vfree(ha->optrom_buffer);
  1276. ha->optrom_buffer = NULL;
  1277. ha->optrom_state = QLA_SWAITING;
  1278. bsg_job->job_done(bsg_job);
  1279. return rval;
  1280. }
  1281. static int
  1282. qla2x00_update_fru_versions(struct fc_bsg_job *bsg_job)
  1283. {
  1284. struct Scsi_Host *host = bsg_job->shost;
  1285. scsi_qla_host_t *vha = shost_priv(host);
  1286. struct qla_hw_data *ha = vha->hw;
  1287. int rval = 0;
  1288. uint8_t bsg[DMA_POOL_SIZE];
  1289. struct qla_image_version_list *list = (void *)bsg;
  1290. struct qla_image_version *image;
  1291. uint32_t count;
  1292. dma_addr_t sfp_dma;
  1293. void *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
  1294. if (!sfp) {
  1295. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
  1296. EXT_STATUS_NO_MEMORY;
  1297. goto done;
  1298. }
  1299. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  1300. bsg_job->request_payload.sg_cnt, list, sizeof(bsg));
  1301. image = list->version;
  1302. count = list->count;
  1303. while (count--) {
  1304. memcpy(sfp, &image->field_info, sizeof(image->field_info));
  1305. rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
  1306. image->field_address.device, image->field_address.offset,
  1307. sizeof(image->field_info), image->field_address.option);
  1308. if (rval) {
  1309. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
  1310. EXT_STATUS_MAILBOX;
  1311. goto dealloc;
  1312. }
  1313. image++;
  1314. }
  1315. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
  1316. dealloc:
  1317. dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
  1318. done:
  1319. bsg_job->reply_len = sizeof(struct fc_bsg_reply);
  1320. bsg_job->reply->result = DID_OK << 16;
  1321. bsg_job->job_done(bsg_job);
  1322. return 0;
  1323. }
  1324. static int
  1325. qla2x00_read_fru_status(struct fc_bsg_job *bsg_job)
  1326. {
  1327. struct Scsi_Host *host = bsg_job->shost;
  1328. scsi_qla_host_t *vha = shost_priv(host);
  1329. struct qla_hw_data *ha = vha->hw;
  1330. int rval = 0;
  1331. uint8_t bsg[DMA_POOL_SIZE];
  1332. struct qla_status_reg *sr = (void *)bsg;
  1333. dma_addr_t sfp_dma;
  1334. uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
  1335. if (!sfp) {
  1336. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
  1337. EXT_STATUS_NO_MEMORY;
  1338. goto done;
  1339. }
  1340. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  1341. bsg_job->request_payload.sg_cnt, sr, sizeof(*sr));
  1342. rval = qla2x00_read_sfp(vha, sfp_dma, sfp,
  1343. sr->field_address.device, sr->field_address.offset,
  1344. sizeof(sr->status_reg), sr->field_address.option);
  1345. sr->status_reg = *sfp;
  1346. if (rval) {
  1347. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
  1348. EXT_STATUS_MAILBOX;
  1349. goto dealloc;
  1350. }
  1351. sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
  1352. bsg_job->reply_payload.sg_cnt, sr, sizeof(*sr));
  1353. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
  1354. dealloc:
  1355. dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
  1356. done:
  1357. bsg_job->reply_len = sizeof(struct fc_bsg_reply);
  1358. bsg_job->reply->reply_payload_rcv_len = sizeof(*sr);
  1359. bsg_job->reply->result = DID_OK << 16;
  1360. bsg_job->job_done(bsg_job);
  1361. return 0;
  1362. }
  1363. static int
  1364. qla2x00_write_fru_status(struct fc_bsg_job *bsg_job)
  1365. {
  1366. struct Scsi_Host *host = bsg_job->shost;
  1367. scsi_qla_host_t *vha = shost_priv(host);
  1368. struct qla_hw_data *ha = vha->hw;
  1369. int rval = 0;
  1370. uint8_t bsg[DMA_POOL_SIZE];
  1371. struct qla_status_reg *sr = (void *)bsg;
  1372. dma_addr_t sfp_dma;
  1373. uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
  1374. if (!sfp) {
  1375. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
  1376. EXT_STATUS_NO_MEMORY;
  1377. goto done;
  1378. }
  1379. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  1380. bsg_job->request_payload.sg_cnt, sr, sizeof(*sr));
  1381. *sfp = sr->status_reg;
  1382. rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
  1383. sr->field_address.device, sr->field_address.offset,
  1384. sizeof(sr->status_reg), sr->field_address.option);
  1385. if (rval) {
  1386. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
  1387. EXT_STATUS_MAILBOX;
  1388. goto dealloc;
  1389. }
  1390. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
  1391. dealloc:
  1392. dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
  1393. done:
  1394. bsg_job->reply_len = sizeof(struct fc_bsg_reply);
  1395. bsg_job->reply->result = DID_OK << 16;
  1396. bsg_job->job_done(bsg_job);
  1397. return 0;
  1398. }
  1399. static int
  1400. qla2x00_write_i2c(struct fc_bsg_job *bsg_job)
  1401. {
  1402. struct Scsi_Host *host = bsg_job->shost;
  1403. scsi_qla_host_t *vha = shost_priv(host);
  1404. struct qla_hw_data *ha = vha->hw;
  1405. int rval = 0;
  1406. uint8_t bsg[DMA_POOL_SIZE];
  1407. struct qla_i2c_access *i2c = (void *)bsg;
  1408. dma_addr_t sfp_dma;
  1409. uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
  1410. if (!sfp) {
  1411. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
  1412. EXT_STATUS_NO_MEMORY;
  1413. goto done;
  1414. }
  1415. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  1416. bsg_job->request_payload.sg_cnt, i2c, sizeof(*i2c));
  1417. memcpy(sfp, i2c->buffer, i2c->length);
  1418. rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
  1419. i2c->device, i2c->offset, i2c->length, i2c->option);
  1420. if (rval) {
  1421. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
  1422. EXT_STATUS_MAILBOX;
  1423. goto dealloc;
  1424. }
  1425. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
  1426. dealloc:
  1427. dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
  1428. done:
  1429. bsg_job->reply_len = sizeof(struct fc_bsg_reply);
  1430. bsg_job->reply->result = DID_OK << 16;
  1431. bsg_job->job_done(bsg_job);
  1432. return 0;
  1433. }
  1434. static int
  1435. qla2x00_read_i2c(struct fc_bsg_job *bsg_job)
  1436. {
  1437. struct Scsi_Host *host = bsg_job->shost;
  1438. scsi_qla_host_t *vha = shost_priv(host);
  1439. struct qla_hw_data *ha = vha->hw;
  1440. int rval = 0;
  1441. uint8_t bsg[DMA_POOL_SIZE];
  1442. struct qla_i2c_access *i2c = (void *)bsg;
  1443. dma_addr_t sfp_dma;
  1444. uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
  1445. if (!sfp) {
  1446. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
  1447. EXT_STATUS_NO_MEMORY;
  1448. goto done;
  1449. }
  1450. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  1451. bsg_job->request_payload.sg_cnt, i2c, sizeof(*i2c));
  1452. rval = qla2x00_read_sfp(vha, sfp_dma, sfp,
  1453. i2c->device, i2c->offset, i2c->length, i2c->option);
  1454. if (rval) {
  1455. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
  1456. EXT_STATUS_MAILBOX;
  1457. goto dealloc;
  1458. }
  1459. memcpy(i2c->buffer, sfp, i2c->length);
  1460. sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
  1461. bsg_job->reply_payload.sg_cnt, i2c, sizeof(*i2c));
  1462. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
  1463. dealloc:
  1464. dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
  1465. done:
  1466. bsg_job->reply_len = sizeof(struct fc_bsg_reply);
  1467. bsg_job->reply->reply_payload_rcv_len = sizeof(*i2c);
  1468. bsg_job->reply->result = DID_OK << 16;
  1469. bsg_job->job_done(bsg_job);
  1470. return 0;
  1471. }
  1472. static int
  1473. qla24xx_process_bidir_cmd(struct fc_bsg_job *bsg_job)
  1474. {
  1475. struct Scsi_Host *host = bsg_job->shost;
  1476. scsi_qla_host_t *vha = shost_priv(host);
  1477. struct qla_hw_data *ha = vha->hw;
  1478. uint16_t thread_id;
  1479. uint32_t rval = EXT_STATUS_OK;
  1480. uint16_t req_sg_cnt = 0;
  1481. uint16_t rsp_sg_cnt = 0;
  1482. uint16_t nextlid = 0;
  1483. uint32_t tot_dsds;
  1484. srb_t *sp = NULL;
  1485. uint32_t req_data_len = 0;
  1486. uint32_t rsp_data_len = 0;
  1487. /* Check the type of the adapter */
  1488. if (!IS_BIDI_CAPABLE(ha)) {
  1489. ql_log(ql_log_warn, vha, 0x70a0,
  1490. "This adapter is not supported\n");
  1491. rval = EXT_STATUS_NOT_SUPPORTED;
  1492. goto done;
  1493. }
  1494. if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
  1495. test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  1496. test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
  1497. rval = EXT_STATUS_BUSY;
  1498. goto done;
  1499. }
  1500. /* Check if host is online */
  1501. if (!vha->flags.online) {
  1502. ql_log(ql_log_warn, vha, 0x70a1,
  1503. "Host is not online\n");
  1504. rval = EXT_STATUS_DEVICE_OFFLINE;
  1505. goto done;
  1506. }
  1507. /* Check if cable is plugged in or not */
  1508. if (vha->device_flags & DFLG_NO_CABLE) {
  1509. ql_log(ql_log_warn, vha, 0x70a2,
  1510. "Cable is unplugged...\n");
  1511. rval = EXT_STATUS_INVALID_CFG;
  1512. goto done;
  1513. }
  1514. /* Check if the switch is connected or not */
  1515. if (ha->current_topology != ISP_CFG_F) {
  1516. ql_log(ql_log_warn, vha, 0x70a3,
  1517. "Host is not connected to the switch\n");
  1518. rval = EXT_STATUS_INVALID_CFG;
  1519. goto done;
  1520. }
  1521. /* Check if operating mode is P2P */
  1522. if (ha->operating_mode != P2P) {
  1523. ql_log(ql_log_warn, vha, 0x70a4,
  1524. "Host is operating mode is not P2p\n");
  1525. rval = EXT_STATUS_INVALID_CFG;
  1526. goto done;
  1527. }
  1528. thread_id = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
  1529. mutex_lock(&ha->selflogin_lock);
  1530. if (vha->self_login_loop_id == 0) {
  1531. /* Initialize all required fields of fcport */
  1532. vha->bidir_fcport.vha = vha;
  1533. vha->bidir_fcport.d_id.b.al_pa = vha->d_id.b.al_pa;
  1534. vha->bidir_fcport.d_id.b.area = vha->d_id.b.area;
  1535. vha->bidir_fcport.d_id.b.domain = vha->d_id.b.domain;
  1536. vha->bidir_fcport.loop_id = vha->loop_id;
  1537. if (qla2x00_fabric_login(vha, &(vha->bidir_fcport), &nextlid)) {
  1538. ql_log(ql_log_warn, vha, 0x70a7,
  1539. "Failed to login port %06X for bidirectional IOCB\n",
  1540. vha->bidir_fcport.d_id.b24);
  1541. mutex_unlock(&ha->selflogin_lock);
  1542. rval = EXT_STATUS_MAILBOX;
  1543. goto done;
  1544. }
  1545. vha->self_login_loop_id = nextlid - 1;
  1546. }
  1547. /* Assign the self login loop id to fcport */
  1548. mutex_unlock(&ha->selflogin_lock);
  1549. vha->bidir_fcport.loop_id = vha->self_login_loop_id;
  1550. req_sg_cnt = dma_map_sg(&ha->pdev->dev,
  1551. bsg_job->request_payload.sg_list,
  1552. bsg_job->request_payload.sg_cnt,
  1553. DMA_TO_DEVICE);
  1554. if (!req_sg_cnt) {
  1555. rval = EXT_STATUS_NO_MEMORY;
  1556. goto done;
  1557. }
  1558. rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
  1559. bsg_job->reply_payload.sg_list, bsg_job->reply_payload.sg_cnt,
  1560. DMA_FROM_DEVICE);
  1561. if (!rsp_sg_cnt) {
  1562. rval = EXT_STATUS_NO_MEMORY;
  1563. goto done_unmap_req_sg;
  1564. }
  1565. if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
  1566. (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
  1567. ql_dbg(ql_dbg_user, vha, 0x70a9,
  1568. "Dma mapping resulted in different sg counts "
  1569. "[request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt: "
  1570. "%x dma_reply_sg_cnt: %x]\n",
  1571. bsg_job->request_payload.sg_cnt, req_sg_cnt,
  1572. bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
  1573. rval = EXT_STATUS_NO_MEMORY;
  1574. goto done_unmap_sg;
  1575. }
  1576. if (req_data_len != rsp_data_len) {
  1577. rval = EXT_STATUS_BUSY;
  1578. ql_log(ql_log_warn, vha, 0x70aa,
  1579. "req_data_len != rsp_data_len\n");
  1580. goto done_unmap_sg;
  1581. }
  1582. req_data_len = bsg_job->request_payload.payload_len;
  1583. rsp_data_len = bsg_job->reply_payload.payload_len;
  1584. /* Alloc SRB structure */
  1585. sp = qla2x00_get_sp(vha, &(vha->bidir_fcport), GFP_KERNEL);
  1586. if (!sp) {
  1587. ql_dbg(ql_dbg_user, vha, 0x70ac,
  1588. "Alloc SRB structure failed\n");
  1589. rval = EXT_STATUS_NO_MEMORY;
  1590. goto done_unmap_sg;
  1591. }
  1592. /*Populate srb->ctx with bidir ctx*/
  1593. sp->u.bsg_job = bsg_job;
  1594. sp->free = qla2x00_bsg_sp_free;
  1595. sp->type = SRB_BIDI_CMD;
  1596. sp->done = qla2x00_bsg_job_done;
  1597. /* Add the read and write sg count */
  1598. tot_dsds = rsp_sg_cnt + req_sg_cnt;
  1599. rval = qla2x00_start_bidir(sp, vha, tot_dsds);
  1600. if (rval != EXT_STATUS_OK)
  1601. goto done_free_srb;
  1602. /* the bsg request will be completed in the interrupt handler */
  1603. return rval;
  1604. done_free_srb:
  1605. mempool_free(sp, ha->srb_mempool);
  1606. done_unmap_sg:
  1607. dma_unmap_sg(&ha->pdev->dev,
  1608. bsg_job->reply_payload.sg_list,
  1609. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1610. done_unmap_req_sg:
  1611. dma_unmap_sg(&ha->pdev->dev,
  1612. bsg_job->request_payload.sg_list,
  1613. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1614. done:
  1615. /* Return an error vendor specific response
  1616. * and complete the bsg request
  1617. */
  1618. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = rval;
  1619. bsg_job->reply_len = sizeof(struct fc_bsg_reply);
  1620. bsg_job->reply->reply_payload_rcv_len = 0;
  1621. bsg_job->reply->result = (DID_OK) << 16;
  1622. bsg_job->job_done(bsg_job);
  1623. /* Always retrun success, vendor rsp carries correct status */
  1624. return 0;
  1625. }
  1626. static int
  1627. qlafx00_mgmt_cmd(struct fc_bsg_job *bsg_job)
  1628. {
  1629. struct Scsi_Host *host = bsg_job->shost;
  1630. scsi_qla_host_t *vha = shost_priv(host);
  1631. struct qla_hw_data *ha = vha->hw;
  1632. int rval = (DRIVER_ERROR << 16);
  1633. struct qla_mt_iocb_rqst_fx00 *piocb_rqst;
  1634. srb_t *sp;
  1635. int req_sg_cnt = 0, rsp_sg_cnt = 0;
  1636. struct fc_port *fcport;
  1637. char *type = "FC_BSG_HST_FX_MGMT";
  1638. /* Copy the IOCB specific information */
  1639. piocb_rqst = (struct qla_mt_iocb_rqst_fx00 *)
  1640. &bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
  1641. /* Dump the vendor information */
  1642. ql_dump_buffer(ql_dbg_user + ql_dbg_verbose , vha, 0x70cf,
  1643. (uint8_t *)piocb_rqst, sizeof(struct qla_mt_iocb_rqst_fx00));
  1644. if (!vha->flags.online) {
  1645. ql_log(ql_log_warn, vha, 0x70d0,
  1646. "Host is not online.\n");
  1647. rval = -EIO;
  1648. goto done;
  1649. }
  1650. if (piocb_rqst->flags & SRB_FXDISC_REQ_DMA_VALID) {
  1651. req_sg_cnt = dma_map_sg(&ha->pdev->dev,
  1652. bsg_job->request_payload.sg_list,
  1653. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1654. if (!req_sg_cnt) {
  1655. ql_log(ql_log_warn, vha, 0x70c7,
  1656. "dma_map_sg return %d for request\n", req_sg_cnt);
  1657. rval = -ENOMEM;
  1658. goto done;
  1659. }
  1660. }
  1661. if (piocb_rqst->flags & SRB_FXDISC_RESP_DMA_VALID) {
  1662. rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
  1663. bsg_job->reply_payload.sg_list,
  1664. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1665. if (!rsp_sg_cnt) {
  1666. ql_log(ql_log_warn, vha, 0x70c8,
  1667. "dma_map_sg return %d for reply\n", rsp_sg_cnt);
  1668. rval = -ENOMEM;
  1669. goto done_unmap_req_sg;
  1670. }
  1671. }
  1672. ql_dbg(ql_dbg_user, vha, 0x70c9,
  1673. "request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt:%x "
  1674. "dma_reply_sg_cnt: %x\n", bsg_job->request_payload.sg_cnt,
  1675. req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
  1676. /* Allocate a dummy fcport structure, since functions preparing the
  1677. * IOCB and mailbox command retrieves port specific information
  1678. * from fcport structure. For Host based ELS commands there will be
  1679. * no fcport structure allocated
  1680. */
  1681. fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  1682. if (!fcport) {
  1683. ql_log(ql_log_warn, vha, 0x70ca,
  1684. "Failed to allocate fcport.\n");
  1685. rval = -ENOMEM;
  1686. goto done_unmap_rsp_sg;
  1687. }
  1688. /* Alloc SRB structure */
  1689. sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
  1690. if (!sp) {
  1691. ql_log(ql_log_warn, vha, 0x70cb,
  1692. "qla2x00_get_sp failed.\n");
  1693. rval = -ENOMEM;
  1694. goto done_free_fcport;
  1695. }
  1696. /* Initialize all required fields of fcport */
  1697. fcport->vha = vha;
  1698. fcport->loop_id = piocb_rqst->dataword;
  1699. sp->type = SRB_FXIOCB_BCMD;
  1700. sp->name = "bsg_fx_mgmt";
  1701. sp->iocbs = qla24xx_calc_ct_iocbs(req_sg_cnt + rsp_sg_cnt);
  1702. sp->u.bsg_job = bsg_job;
  1703. sp->free = qla2x00_bsg_sp_free;
  1704. sp->done = qla2x00_bsg_job_done;
  1705. ql_dbg(ql_dbg_user, vha, 0x70cc,
  1706. "bsg rqst type: %s fx_mgmt_type: %x id=%x\n",
  1707. type, piocb_rqst->func_type, fcport->loop_id);
  1708. rval = qla2x00_start_sp(sp);
  1709. if (rval != QLA_SUCCESS) {
  1710. ql_log(ql_log_warn, vha, 0x70cd,
  1711. "qla2x00_start_sp failed=%d.\n", rval);
  1712. mempool_free(sp, ha->srb_mempool);
  1713. rval = -EIO;
  1714. goto done_free_fcport;
  1715. }
  1716. return rval;
  1717. done_free_fcport:
  1718. kfree(fcport);
  1719. done_unmap_rsp_sg:
  1720. if (piocb_rqst->flags & SRB_FXDISC_RESP_DMA_VALID)
  1721. dma_unmap_sg(&ha->pdev->dev,
  1722. bsg_job->reply_payload.sg_list,
  1723. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1724. done_unmap_req_sg:
  1725. if (piocb_rqst->flags & SRB_FXDISC_REQ_DMA_VALID)
  1726. dma_unmap_sg(&ha->pdev->dev,
  1727. bsg_job->request_payload.sg_list,
  1728. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1729. done:
  1730. return rval;
  1731. }
  1732. static int
  1733. qla2x00_process_vendor_specific(struct fc_bsg_job *bsg_job)
  1734. {
  1735. switch (bsg_job->request->rqst_data.h_vendor.vendor_cmd[0]) {
  1736. case QL_VND_LOOPBACK:
  1737. return qla2x00_process_loopback(bsg_job);
  1738. case QL_VND_A84_RESET:
  1739. return qla84xx_reset(bsg_job);
  1740. case QL_VND_A84_UPDATE_FW:
  1741. return qla84xx_updatefw(bsg_job);
  1742. case QL_VND_A84_MGMT_CMD:
  1743. return qla84xx_mgmt_cmd(bsg_job);
  1744. case QL_VND_IIDMA:
  1745. return qla24xx_iidma(bsg_job);
  1746. case QL_VND_FCP_PRIO_CFG_CMD:
  1747. return qla24xx_proc_fcp_prio_cfg_cmd(bsg_job);
  1748. case QL_VND_READ_FLASH:
  1749. return qla2x00_read_optrom(bsg_job);
  1750. case QL_VND_UPDATE_FLASH:
  1751. return qla2x00_update_optrom(bsg_job);
  1752. case QL_VND_SET_FRU_VERSION:
  1753. return qla2x00_update_fru_versions(bsg_job);
  1754. case QL_VND_READ_FRU_STATUS:
  1755. return qla2x00_read_fru_status(bsg_job);
  1756. case QL_VND_WRITE_FRU_STATUS:
  1757. return qla2x00_write_fru_status(bsg_job);
  1758. case QL_VND_WRITE_I2C:
  1759. return qla2x00_write_i2c(bsg_job);
  1760. case QL_VND_READ_I2C:
  1761. return qla2x00_read_i2c(bsg_job);
  1762. case QL_VND_DIAG_IO_CMD:
  1763. return qla24xx_process_bidir_cmd(bsg_job);
  1764. case QL_VND_FX00_MGMT_CMD:
  1765. return qlafx00_mgmt_cmd(bsg_job);
  1766. default:
  1767. return -ENOSYS;
  1768. }
  1769. }
  1770. int
  1771. qla24xx_bsg_request(struct fc_bsg_job *bsg_job)
  1772. {
  1773. int ret = -EINVAL;
  1774. struct fc_rport *rport;
  1775. fc_port_t *fcport = NULL;
  1776. struct Scsi_Host *host;
  1777. scsi_qla_host_t *vha;
  1778. /* In case no data transferred. */
  1779. bsg_job->reply->reply_payload_rcv_len = 0;
  1780. if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) {
  1781. rport = bsg_job->rport;
  1782. fcport = *(fc_port_t **) rport->dd_data;
  1783. host = rport_to_shost(rport);
  1784. vha = shost_priv(host);
  1785. } else {
  1786. host = bsg_job->shost;
  1787. vha = shost_priv(host);
  1788. }
  1789. if (qla2x00_reset_active(vha)) {
  1790. ql_dbg(ql_dbg_user, vha, 0x709f,
  1791. "BSG: ISP abort active/needed -- cmd=%d.\n",
  1792. bsg_job->request->msgcode);
  1793. return -EBUSY;
  1794. }
  1795. ql_dbg(ql_dbg_user, vha, 0x7000,
  1796. "Entered %s msgcode=0x%x.\n", __func__, bsg_job->request->msgcode);
  1797. switch (bsg_job->request->msgcode) {
  1798. case FC_BSG_RPT_ELS:
  1799. case FC_BSG_HST_ELS_NOLOGIN:
  1800. ret = qla2x00_process_els(bsg_job);
  1801. break;
  1802. case FC_BSG_HST_CT:
  1803. ret = qla2x00_process_ct(bsg_job);
  1804. break;
  1805. case FC_BSG_HST_VENDOR:
  1806. ret = qla2x00_process_vendor_specific(bsg_job);
  1807. break;
  1808. case FC_BSG_HST_ADD_RPORT:
  1809. case FC_BSG_HST_DEL_RPORT:
  1810. case FC_BSG_RPT_CT:
  1811. default:
  1812. ql_log(ql_log_warn, vha, 0x705a, "Unsupported BSG request.\n");
  1813. break;
  1814. }
  1815. return ret;
  1816. }
  1817. int
  1818. qla24xx_bsg_timeout(struct fc_bsg_job *bsg_job)
  1819. {
  1820. scsi_qla_host_t *vha = shost_priv(bsg_job->shost);
  1821. struct qla_hw_data *ha = vha->hw;
  1822. srb_t *sp;
  1823. int cnt, que;
  1824. unsigned long flags;
  1825. struct req_que *req;
  1826. /* find the bsg job from the active list of commands */
  1827. spin_lock_irqsave(&ha->hardware_lock, flags);
  1828. for (que = 0; que < ha->max_req_queues; que++) {
  1829. req = ha->req_q_map[que];
  1830. if (!req)
  1831. continue;
  1832. for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
  1833. sp = req->outstanding_cmds[cnt];
  1834. if (sp) {
  1835. if (((sp->type == SRB_CT_CMD) ||
  1836. (sp->type == SRB_ELS_CMD_HST) ||
  1837. (sp->type == SRB_FXIOCB_BCMD))
  1838. && (sp->u.bsg_job == bsg_job)) {
  1839. req->outstanding_cmds[cnt] = NULL;
  1840. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1841. if (ha->isp_ops->abort_command(sp)) {
  1842. ql_log(ql_log_warn, vha, 0x7089,
  1843. "mbx abort_command "
  1844. "failed.\n");
  1845. bsg_job->req->errors =
  1846. bsg_job->reply->result = -EIO;
  1847. } else {
  1848. ql_dbg(ql_dbg_user, vha, 0x708a,
  1849. "mbx abort_command "
  1850. "success.\n");
  1851. bsg_job->req->errors =
  1852. bsg_job->reply->result = 0;
  1853. }
  1854. spin_lock_irqsave(&ha->hardware_lock, flags);
  1855. goto done;
  1856. }
  1857. }
  1858. }
  1859. }
  1860. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1861. ql_log(ql_log_info, vha, 0x708b, "SRB not found to abort.\n");
  1862. bsg_job->req->errors = bsg_job->reply->result = -ENXIO;
  1863. return 0;
  1864. done:
  1865. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1866. sp->free(vha, sp);
  1867. return 0;
  1868. }