qla_bsg.c 45 KB

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