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