qla_bsg.c 45 KB

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