qla_bsg.c 45 KB

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