qla_bsg.c 46 KB

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