qla_bsg.c 46 KB

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