qla_bsg.c 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2014 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 = sp->fcport->vha;
  27. struct fc_bsg_job *bsg_job = sp->u.bsg_job;
  28. struct qla_hw_data *ha = vha->hw;
  29. struct qla_mt_iocb_rqst_fx00 *piocb_rqst;
  30. if (sp->type == SRB_FXIOCB_BCMD) {
  31. piocb_rqst = (struct qla_mt_iocb_rqst_fx00 *)
  32. &bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
  33. if (piocb_rqst->flags & SRB_FXDISC_REQ_DMA_VALID)
  34. dma_unmap_sg(&ha->pdev->dev,
  35. bsg_job->request_payload.sg_list,
  36. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  37. if (piocb_rqst->flags & SRB_FXDISC_RESP_DMA_VALID)
  38. dma_unmap_sg(&ha->pdev->dev,
  39. bsg_job->reply_payload.sg_list,
  40. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  41. } else {
  42. dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  43. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  44. dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  45. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  46. }
  47. if (sp->type == SRB_CT_CMD ||
  48. sp->type == SRB_FXIOCB_BCMD ||
  49. sp->type == SRB_ELS_CMD_HST)
  50. kfree(sp->fcport);
  51. qla2x00_rel_sp(vha, sp);
  52. }
  53. int
  54. qla24xx_fcp_prio_cfg_valid(scsi_qla_host_t *vha,
  55. struct qla_fcp_prio_cfg *pri_cfg, uint8_t flag)
  56. {
  57. int i, ret, num_valid;
  58. uint8_t *bcode;
  59. struct qla_fcp_prio_entry *pri_entry;
  60. uint32_t *bcode_val_ptr, bcode_val;
  61. ret = 1;
  62. num_valid = 0;
  63. bcode = (uint8_t *)pri_cfg;
  64. bcode_val_ptr = (uint32_t *)pri_cfg;
  65. bcode_val = (uint32_t)(*bcode_val_ptr);
  66. if (bcode_val == 0xFFFFFFFF) {
  67. /* No FCP Priority config data in flash */
  68. ql_dbg(ql_dbg_user, vha, 0x7051,
  69. "No FCP Priority config data.\n");
  70. return 0;
  71. }
  72. if (bcode[0] != 'H' || bcode[1] != 'Q' || bcode[2] != 'O' ||
  73. bcode[3] != 'S') {
  74. /* Invalid FCP priority data header*/
  75. ql_dbg(ql_dbg_user, vha, 0x7052,
  76. "Invalid FCP Priority data header. bcode=0x%x.\n",
  77. bcode_val);
  78. return 0;
  79. }
  80. if (flag != 1)
  81. return ret;
  82. pri_entry = &pri_cfg->entry[0];
  83. for (i = 0; i < pri_cfg->num_entries; i++) {
  84. if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
  85. num_valid++;
  86. pri_entry++;
  87. }
  88. if (num_valid == 0) {
  89. /* No valid FCP priority data entries */
  90. ql_dbg(ql_dbg_user, vha, 0x7053,
  91. "No valid FCP Priority data entries.\n");
  92. ret = 0;
  93. } else {
  94. /* FCP priority data is valid */
  95. ql_dbg(ql_dbg_user, vha, 0x7054,
  96. "Valid FCP priority data. num entries = %d.\n",
  97. num_valid);
  98. }
  99. return ret;
  100. }
  101. static int
  102. qla24xx_proc_fcp_prio_cfg_cmd(struct fc_bsg_job *bsg_job)
  103. {
  104. struct Scsi_Host *host = bsg_job->shost;
  105. scsi_qla_host_t *vha = shost_priv(host);
  106. struct qla_hw_data *ha = vha->hw;
  107. int ret = 0;
  108. uint32_t len;
  109. uint32_t oper;
  110. if (!(IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) || IS_P3P_TYPE(ha))) {
  111. ret = -EINVAL;
  112. goto exit_fcp_prio_cfg;
  113. }
  114. /* Get the sub command */
  115. oper = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
  116. /* Only set config is allowed if config memory is not allocated */
  117. if (!ha->fcp_prio_cfg && (oper != QLFC_FCP_PRIO_SET_CONFIG)) {
  118. ret = -EINVAL;
  119. goto exit_fcp_prio_cfg;
  120. }
  121. switch (oper) {
  122. case QLFC_FCP_PRIO_DISABLE:
  123. if (ha->flags.fcp_prio_enabled) {
  124. ha->flags.fcp_prio_enabled = 0;
  125. ha->fcp_prio_cfg->attributes &=
  126. ~FCP_PRIO_ATTR_ENABLE;
  127. qla24xx_update_all_fcp_prio(vha);
  128. bsg_job->reply->result = DID_OK;
  129. } else {
  130. ret = -EINVAL;
  131. bsg_job->reply->result = (DID_ERROR << 16);
  132. goto exit_fcp_prio_cfg;
  133. }
  134. break;
  135. case QLFC_FCP_PRIO_ENABLE:
  136. if (!ha->flags.fcp_prio_enabled) {
  137. if (ha->fcp_prio_cfg) {
  138. ha->flags.fcp_prio_enabled = 1;
  139. ha->fcp_prio_cfg->attributes |=
  140. FCP_PRIO_ATTR_ENABLE;
  141. qla24xx_update_all_fcp_prio(vha);
  142. bsg_job->reply->result = DID_OK;
  143. } else {
  144. ret = -EINVAL;
  145. bsg_job->reply->result = (DID_ERROR << 16);
  146. goto exit_fcp_prio_cfg;
  147. }
  148. }
  149. break;
  150. case QLFC_FCP_PRIO_GET_CONFIG:
  151. len = bsg_job->reply_payload.payload_len;
  152. if (!len || len > FCP_PRIO_CFG_SIZE) {
  153. ret = -EINVAL;
  154. bsg_job->reply->result = (DID_ERROR << 16);
  155. goto exit_fcp_prio_cfg;
  156. }
  157. bsg_job->reply->result = DID_OK;
  158. bsg_job->reply->reply_payload_rcv_len =
  159. sg_copy_from_buffer(
  160. bsg_job->reply_payload.sg_list,
  161. bsg_job->reply_payload.sg_cnt, ha->fcp_prio_cfg,
  162. len);
  163. break;
  164. case QLFC_FCP_PRIO_SET_CONFIG:
  165. len = bsg_job->request_payload.payload_len;
  166. if (!len || len > FCP_PRIO_CFG_SIZE) {
  167. bsg_job->reply->result = (DID_ERROR << 16);
  168. ret = -EINVAL;
  169. goto exit_fcp_prio_cfg;
  170. }
  171. if (!ha->fcp_prio_cfg) {
  172. ha->fcp_prio_cfg = vmalloc(FCP_PRIO_CFG_SIZE);
  173. if (!ha->fcp_prio_cfg) {
  174. ql_log(ql_log_warn, vha, 0x7050,
  175. "Unable to allocate memory for fcp prio "
  176. "config data (%x).\n", FCP_PRIO_CFG_SIZE);
  177. bsg_job->reply->result = (DID_ERROR << 16);
  178. ret = -ENOMEM;
  179. goto exit_fcp_prio_cfg;
  180. }
  181. }
  182. memset(ha->fcp_prio_cfg, 0, FCP_PRIO_CFG_SIZE);
  183. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  184. bsg_job->request_payload.sg_cnt, ha->fcp_prio_cfg,
  185. FCP_PRIO_CFG_SIZE);
  186. /* validate fcp priority data */
  187. if (!qla24xx_fcp_prio_cfg_valid(vha,
  188. (struct qla_fcp_prio_cfg *) ha->fcp_prio_cfg, 1)) {
  189. bsg_job->reply->result = (DID_ERROR << 16);
  190. ret = -EINVAL;
  191. /* If buffer was invalidatic int
  192. * fcp_prio_cfg is of no use
  193. */
  194. vfree(ha->fcp_prio_cfg);
  195. ha->fcp_prio_cfg = NULL;
  196. goto exit_fcp_prio_cfg;
  197. }
  198. ha->flags.fcp_prio_enabled = 0;
  199. if (ha->fcp_prio_cfg->attributes & FCP_PRIO_ATTR_ENABLE)
  200. ha->flags.fcp_prio_enabled = 1;
  201. qla24xx_update_all_fcp_prio(vha);
  202. bsg_job->reply->result = DID_OK;
  203. break;
  204. default:
  205. ret = -EINVAL;
  206. break;
  207. }
  208. exit_fcp_prio_cfg:
  209. if (!ret)
  210. bsg_job->job_done(bsg_job);
  211. return ret;
  212. }
  213. static int
  214. qla2x00_process_els(struct fc_bsg_job *bsg_job)
  215. {
  216. struct fc_rport *rport;
  217. fc_port_t *fcport = NULL;
  218. struct Scsi_Host *host;
  219. scsi_qla_host_t *vha;
  220. struct qla_hw_data *ha;
  221. srb_t *sp;
  222. const char *type;
  223. int req_sg_cnt, rsp_sg_cnt;
  224. int rval = (DRIVER_ERROR << 16);
  225. uint16_t nextlid = 0;
  226. if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) {
  227. rport = bsg_job->rport;
  228. fcport = *(fc_port_t **) rport->dd_data;
  229. host = rport_to_shost(rport);
  230. vha = shost_priv(host);
  231. ha = vha->hw;
  232. type = "FC_BSG_RPT_ELS";
  233. } else {
  234. host = bsg_job->shost;
  235. vha = shost_priv(host);
  236. ha = vha->hw;
  237. type = "FC_BSG_HST_ELS_NOLOGIN";
  238. }
  239. if (!vha->flags.online) {
  240. ql_log(ql_log_warn, vha, 0x7005, "Host not online.\n");
  241. rval = -EIO;
  242. goto done;
  243. }
  244. /* pass through is supported only for ISP 4Gb or higher */
  245. if (!IS_FWI2_CAPABLE(ha)) {
  246. ql_dbg(ql_dbg_user, vha, 0x7001,
  247. "ELS passthru not supported for ISP23xx based adapters.\n");
  248. rval = -EPERM;
  249. goto done;
  250. }
  251. /* Multiple SG's are not supported for ELS requests */
  252. if (bsg_job->request_payload.sg_cnt > 1 ||
  253. bsg_job->reply_payload.sg_cnt > 1) {
  254. ql_dbg(ql_dbg_user, vha, 0x7002,
  255. "Multiple SG's are not suppored for ELS requests, "
  256. "request_sg_cnt=%x reply_sg_cnt=%x.\n",
  257. bsg_job->request_payload.sg_cnt,
  258. bsg_job->reply_payload.sg_cnt);
  259. rval = -EPERM;
  260. goto done;
  261. }
  262. /* ELS request for rport */
  263. if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) {
  264. /* make sure the rport is logged in,
  265. * if not perform fabric login
  266. */
  267. if (qla2x00_fabric_login(vha, fcport, &nextlid)) {
  268. ql_dbg(ql_dbg_user, vha, 0x7003,
  269. "Failed to login port %06X for ELS passthru.\n",
  270. fcport->d_id.b24);
  271. rval = -EIO;
  272. goto done;
  273. }
  274. } else {
  275. /* Allocate a dummy fcport structure, since functions
  276. * preparing the IOCB and mailbox command retrieves port
  277. * specific information from fcport structure. For Host based
  278. * ELS commands there will be no fcport structure allocated
  279. */
  280. fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  281. if (!fcport) {
  282. rval = -ENOMEM;
  283. goto done;
  284. }
  285. /* Initialize all required fields of fcport */
  286. fcport->vha = vha;
  287. fcport->d_id.b.al_pa =
  288. bsg_job->request->rqst_data.h_els.port_id[0];
  289. fcport->d_id.b.area =
  290. bsg_job->request->rqst_data.h_els.port_id[1];
  291. fcport->d_id.b.domain =
  292. bsg_job->request->rqst_data.h_els.port_id[2];
  293. fcport->loop_id =
  294. (fcport->d_id.b.al_pa == 0xFD) ?
  295. NPH_FABRIC_CONTROLLER : NPH_F_PORT;
  296. }
  297. req_sg_cnt =
  298. dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  299. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  300. if (!req_sg_cnt) {
  301. rval = -ENOMEM;
  302. goto done_free_fcport;
  303. }
  304. rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  305. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  306. if (!rsp_sg_cnt) {
  307. rval = -ENOMEM;
  308. goto done_free_fcport;
  309. }
  310. if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
  311. (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
  312. ql_log(ql_log_warn, vha, 0x7008,
  313. "dma mapping resulted in different sg counts, "
  314. "request_sg_cnt: %x dma_request_sg_cnt:%x reply_sg_cnt:%x "
  315. "dma_reply_sg_cnt:%x.\n", bsg_job->request_payload.sg_cnt,
  316. req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
  317. rval = -EAGAIN;
  318. goto done_unmap_sg;
  319. }
  320. /* Alloc SRB structure */
  321. sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
  322. if (!sp) {
  323. rval = -ENOMEM;
  324. goto done_unmap_sg;
  325. }
  326. sp->type =
  327. (bsg_job->request->msgcode == FC_BSG_RPT_ELS ?
  328. SRB_ELS_CMD_RPT : SRB_ELS_CMD_HST);
  329. sp->name =
  330. (bsg_job->request->msgcode == FC_BSG_RPT_ELS ?
  331. "bsg_els_rpt" : "bsg_els_hst");
  332. sp->u.bsg_job = bsg_job;
  333. sp->free = qla2x00_bsg_sp_free;
  334. sp->done = qla2x00_bsg_job_done;
  335. ql_dbg(ql_dbg_user, vha, 0x700a,
  336. "bsg rqst type: %s els type: %x - loop-id=%x "
  337. "portid=%-2x%02x%02x.\n", type,
  338. bsg_job->request->rqst_data.h_els.command_code, fcport->loop_id,
  339. fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa);
  340. rval = qla2x00_start_sp(sp);
  341. if (rval != QLA_SUCCESS) {
  342. ql_log(ql_log_warn, vha, 0x700e,
  343. "qla2x00_start_sp failed = %d\n", rval);
  344. qla2x00_rel_sp(vha, sp);
  345. rval = -EIO;
  346. goto done_unmap_sg;
  347. }
  348. return rval;
  349. done_unmap_sg:
  350. dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  351. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  352. dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  353. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  354. goto done_free_fcport;
  355. done_free_fcport:
  356. if (bsg_job->request->msgcode == FC_BSG_RPT_ELS)
  357. kfree(fcport);
  358. done:
  359. return rval;
  360. }
  361. static inline uint16_t
  362. qla24xx_calc_ct_iocbs(uint16_t dsds)
  363. {
  364. uint16_t iocbs;
  365. iocbs = 1;
  366. if (dsds > 2) {
  367. iocbs += (dsds - 2) / 5;
  368. if ((dsds - 2) % 5)
  369. iocbs++;
  370. }
  371. return iocbs;
  372. }
  373. static int
  374. qla2x00_process_ct(struct fc_bsg_job *bsg_job)
  375. {
  376. srb_t *sp;
  377. struct Scsi_Host *host = bsg_job->shost;
  378. scsi_qla_host_t *vha = shost_priv(host);
  379. struct qla_hw_data *ha = vha->hw;
  380. int rval = (DRIVER_ERROR << 16);
  381. int req_sg_cnt, rsp_sg_cnt;
  382. uint16_t loop_id;
  383. struct fc_port *fcport;
  384. char *type = "FC_BSG_HST_CT";
  385. req_sg_cnt =
  386. dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  387. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  388. if (!req_sg_cnt) {
  389. ql_log(ql_log_warn, vha, 0x700f,
  390. "dma_map_sg return %d for request\n", req_sg_cnt);
  391. rval = -ENOMEM;
  392. goto done;
  393. }
  394. rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  395. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  396. if (!rsp_sg_cnt) {
  397. ql_log(ql_log_warn, vha, 0x7010,
  398. "dma_map_sg return %d for reply\n", rsp_sg_cnt);
  399. rval = -ENOMEM;
  400. goto done;
  401. }
  402. if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
  403. (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
  404. ql_log(ql_log_warn, vha, 0x7011,
  405. "request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt:%x "
  406. "dma_reply_sg_cnt: %x\n", bsg_job->request_payload.sg_cnt,
  407. req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
  408. rval = -EAGAIN;
  409. goto done_unmap_sg;
  410. }
  411. if (!vha->flags.online) {
  412. ql_log(ql_log_warn, vha, 0x7012,
  413. "Host is not online.\n");
  414. rval = -EIO;
  415. goto done_unmap_sg;
  416. }
  417. loop_id =
  418. (bsg_job->request->rqst_data.h_ct.preamble_word1 & 0xFF000000)
  419. >> 24;
  420. switch (loop_id) {
  421. case 0xFC:
  422. loop_id = cpu_to_le16(NPH_SNS);
  423. break;
  424. case 0xFA:
  425. loop_id = vha->mgmt_svr_loop_id;
  426. break;
  427. default:
  428. ql_dbg(ql_dbg_user, vha, 0x7013,
  429. "Unknown loop id: %x.\n", loop_id);
  430. rval = -EINVAL;
  431. goto done_unmap_sg;
  432. }
  433. /* Allocate a dummy fcport structure, since functions preparing the
  434. * IOCB and mailbox command retrieves port specific information
  435. * from fcport structure. For Host based ELS commands there will be
  436. * no fcport structure allocated
  437. */
  438. fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  439. if (!fcport) {
  440. ql_log(ql_log_warn, vha, 0x7014,
  441. "Failed to allocate fcport.\n");
  442. rval = -ENOMEM;
  443. goto done_unmap_sg;
  444. }
  445. /* Initialize all required fields of fcport */
  446. fcport->vha = vha;
  447. fcport->d_id.b.al_pa = bsg_job->request->rqst_data.h_ct.port_id[0];
  448. fcport->d_id.b.area = bsg_job->request->rqst_data.h_ct.port_id[1];
  449. fcport->d_id.b.domain = bsg_job->request->rqst_data.h_ct.port_id[2];
  450. fcport->loop_id = loop_id;
  451. /* Alloc SRB structure */
  452. sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
  453. if (!sp) {
  454. ql_log(ql_log_warn, vha, 0x7015,
  455. "qla2x00_get_sp failed.\n");
  456. rval = -ENOMEM;
  457. goto done_free_fcport;
  458. }
  459. sp->type = SRB_CT_CMD;
  460. sp->name = "bsg_ct";
  461. sp->iocbs = qla24xx_calc_ct_iocbs(req_sg_cnt + rsp_sg_cnt);
  462. sp->u.bsg_job = bsg_job;
  463. sp->free = qla2x00_bsg_sp_free;
  464. sp->done = qla2x00_bsg_job_done;
  465. ql_dbg(ql_dbg_user, vha, 0x7016,
  466. "bsg rqst type: %s else type: %x - "
  467. "loop-id=%x portid=%02x%02x%02x.\n", type,
  468. (bsg_job->request->rqst_data.h_ct.preamble_word2 >> 16),
  469. fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
  470. fcport->d_id.b.al_pa);
  471. rval = qla2x00_start_sp(sp);
  472. if (rval != QLA_SUCCESS) {
  473. ql_log(ql_log_warn, vha, 0x7017,
  474. "qla2x00_start_sp failed=%d.\n", rval);
  475. qla2x00_rel_sp(vha, sp);
  476. rval = -EIO;
  477. goto done_free_fcport;
  478. }
  479. return rval;
  480. done_free_fcport:
  481. kfree(fcport);
  482. done_unmap_sg:
  483. dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  484. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  485. dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  486. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  487. done:
  488. return rval;
  489. }
  490. /* Disable loopback mode */
  491. static inline int
  492. qla81xx_reset_loopback_mode(scsi_qla_host_t *vha, uint16_t *config,
  493. int wait, int wait2)
  494. {
  495. int ret = 0;
  496. int rval = 0;
  497. uint16_t new_config[4];
  498. struct qla_hw_data *ha = vha->hw;
  499. if (!IS_QLA81XX(ha) && !IS_QLA8031(ha) && !IS_QLA8044(ha))
  500. goto done_reset_internal;
  501. memset(new_config, 0 , sizeof(new_config));
  502. if ((config[0] & INTERNAL_LOOPBACK_MASK) >> 1 ==
  503. ENABLE_INTERNAL_LOOPBACK ||
  504. (config[0] & INTERNAL_LOOPBACK_MASK) >> 1 ==
  505. ENABLE_EXTERNAL_LOOPBACK) {
  506. new_config[0] = config[0] & ~INTERNAL_LOOPBACK_MASK;
  507. ql_dbg(ql_dbg_user, vha, 0x70bf, "new_config[0]=%02x\n",
  508. (new_config[0] & INTERNAL_LOOPBACK_MASK));
  509. memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3) ;
  510. ha->notify_dcbx_comp = wait;
  511. ha->notify_lb_portup_comp = wait2;
  512. ret = qla81xx_set_port_config(vha, new_config);
  513. if (ret != QLA_SUCCESS) {
  514. ql_log(ql_log_warn, vha, 0x7025,
  515. "Set port config failed.\n");
  516. ha->notify_dcbx_comp = 0;
  517. ha->notify_lb_portup_comp = 0;
  518. rval = -EINVAL;
  519. goto done_reset_internal;
  520. }
  521. /* Wait for DCBX complete event */
  522. if (wait && !wait_for_completion_timeout(&ha->dcbx_comp,
  523. (DCBX_COMP_TIMEOUT * HZ))) {
  524. ql_dbg(ql_dbg_user, vha, 0x7026,
  525. "DCBX completion not received.\n");
  526. ha->notify_dcbx_comp = 0;
  527. ha->notify_lb_portup_comp = 0;
  528. rval = -EINVAL;
  529. goto done_reset_internal;
  530. } else
  531. ql_dbg(ql_dbg_user, vha, 0x7027,
  532. "DCBX completion received.\n");
  533. if (wait2 &&
  534. !wait_for_completion_timeout(&ha->lb_portup_comp,
  535. (LB_PORTUP_COMP_TIMEOUT * HZ))) {
  536. ql_dbg(ql_dbg_user, vha, 0x70c5,
  537. "Port up completion not received.\n");
  538. ha->notify_lb_portup_comp = 0;
  539. rval = -EINVAL;
  540. goto done_reset_internal;
  541. } else
  542. ql_dbg(ql_dbg_user, vha, 0x70c6,
  543. "Port up completion received.\n");
  544. ha->notify_dcbx_comp = 0;
  545. ha->notify_lb_portup_comp = 0;
  546. }
  547. done_reset_internal:
  548. return rval;
  549. }
  550. /*
  551. * Set the port configuration to enable the internal or external loopback
  552. * depending on the loopback mode.
  553. */
  554. static inline int
  555. qla81xx_set_loopback_mode(scsi_qla_host_t *vha, uint16_t *config,
  556. uint16_t *new_config, uint16_t mode)
  557. {
  558. int ret = 0;
  559. int rval = 0;
  560. unsigned long rem_tmo = 0, current_tmo = 0;
  561. struct qla_hw_data *ha = vha->hw;
  562. if (!IS_QLA81XX(ha) && !IS_QLA8031(ha) && !IS_QLA8044(ha))
  563. goto done_set_internal;
  564. if (mode == INTERNAL_LOOPBACK)
  565. new_config[0] = config[0] | (ENABLE_INTERNAL_LOOPBACK << 1);
  566. else if (mode == EXTERNAL_LOOPBACK)
  567. new_config[0] = config[0] | (ENABLE_EXTERNAL_LOOPBACK << 1);
  568. ql_dbg(ql_dbg_user, vha, 0x70be,
  569. "new_config[0]=%02x\n", (new_config[0] & INTERNAL_LOOPBACK_MASK));
  570. memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3);
  571. ha->notify_dcbx_comp = 1;
  572. ret = qla81xx_set_port_config(vha, new_config);
  573. if (ret != QLA_SUCCESS) {
  574. ql_log(ql_log_warn, vha, 0x7021,
  575. "set port config failed.\n");
  576. ha->notify_dcbx_comp = 0;
  577. rval = -EINVAL;
  578. goto done_set_internal;
  579. }
  580. /* Wait for DCBX complete event */
  581. current_tmo = DCBX_COMP_TIMEOUT * HZ;
  582. while (1) {
  583. rem_tmo = wait_for_completion_timeout(&ha->dcbx_comp,
  584. current_tmo);
  585. if (!ha->idc_extend_tmo || rem_tmo) {
  586. ha->idc_extend_tmo = 0;
  587. break;
  588. }
  589. current_tmo = ha->idc_extend_tmo * HZ;
  590. ha->idc_extend_tmo = 0;
  591. }
  592. if (!rem_tmo) {
  593. ql_dbg(ql_dbg_user, vha, 0x7022,
  594. "DCBX completion not received.\n");
  595. ret = qla81xx_reset_loopback_mode(vha, new_config, 0, 0);
  596. /*
  597. * If the reset of the loopback mode doesn't work take a FCoE
  598. * dump and reset the chip.
  599. */
  600. if (ret) {
  601. ha->isp_ops->fw_dump(vha, 0);
  602. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  603. }
  604. rval = -EINVAL;
  605. } else {
  606. if (ha->flags.idc_compl_status) {
  607. ql_dbg(ql_dbg_user, vha, 0x70c3,
  608. "Bad status in IDC Completion AEN\n");
  609. rval = -EINVAL;
  610. ha->flags.idc_compl_status = 0;
  611. } else
  612. ql_dbg(ql_dbg_user, vha, 0x7023,
  613. "DCBX completion received.\n");
  614. }
  615. ha->notify_dcbx_comp = 0;
  616. ha->idc_extend_tmo = 0;
  617. done_set_internal:
  618. return rval;
  619. }
  620. static int
  621. qla2x00_process_loopback(struct fc_bsg_job *bsg_job)
  622. {
  623. struct Scsi_Host *host = bsg_job->shost;
  624. scsi_qla_host_t *vha = shost_priv(host);
  625. struct qla_hw_data *ha = vha->hw;
  626. int rval;
  627. uint8_t command_sent;
  628. char *type;
  629. struct msg_echo_lb elreq;
  630. uint16_t response[MAILBOX_REGISTER_COUNT];
  631. uint16_t config[4], new_config[4];
  632. uint8_t *fw_sts_ptr;
  633. uint8_t *req_data = NULL;
  634. dma_addr_t req_data_dma;
  635. uint32_t req_data_len;
  636. uint8_t *rsp_data = NULL;
  637. dma_addr_t rsp_data_dma;
  638. uint32_t rsp_data_len;
  639. if (!vha->flags.online) {
  640. ql_log(ql_log_warn, vha, 0x7019, "Host is not online.\n");
  641. return -EIO;
  642. }
  643. elreq.req_sg_cnt = dma_map_sg(&ha->pdev->dev,
  644. bsg_job->request_payload.sg_list, bsg_job->request_payload.sg_cnt,
  645. DMA_TO_DEVICE);
  646. if (!elreq.req_sg_cnt) {
  647. ql_log(ql_log_warn, vha, 0x701a,
  648. "dma_map_sg returned %d for request.\n", elreq.req_sg_cnt);
  649. return -ENOMEM;
  650. }
  651. elreq.rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
  652. bsg_job->reply_payload.sg_list, bsg_job->reply_payload.sg_cnt,
  653. DMA_FROM_DEVICE);
  654. if (!elreq.rsp_sg_cnt) {
  655. ql_log(ql_log_warn, vha, 0x701b,
  656. "dma_map_sg returned %d for reply.\n", elreq.rsp_sg_cnt);
  657. rval = -ENOMEM;
  658. goto done_unmap_req_sg;
  659. }
  660. if ((elreq.req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
  661. (elreq.rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
  662. ql_log(ql_log_warn, vha, 0x701c,
  663. "dma mapping resulted in different sg counts, "
  664. "request_sg_cnt: %x dma_request_sg_cnt: %x "
  665. "reply_sg_cnt: %x dma_reply_sg_cnt: %x.\n",
  666. bsg_job->request_payload.sg_cnt, elreq.req_sg_cnt,
  667. bsg_job->reply_payload.sg_cnt, elreq.rsp_sg_cnt);
  668. rval = -EAGAIN;
  669. goto done_unmap_sg;
  670. }
  671. req_data_len = rsp_data_len = bsg_job->request_payload.payload_len;
  672. req_data = dma_alloc_coherent(&ha->pdev->dev, req_data_len,
  673. &req_data_dma, GFP_KERNEL);
  674. if (!req_data) {
  675. ql_log(ql_log_warn, vha, 0x701d,
  676. "dma alloc failed for req_data.\n");
  677. rval = -ENOMEM;
  678. goto done_unmap_sg;
  679. }
  680. rsp_data = dma_alloc_coherent(&ha->pdev->dev, rsp_data_len,
  681. &rsp_data_dma, GFP_KERNEL);
  682. if (!rsp_data) {
  683. ql_log(ql_log_warn, vha, 0x7004,
  684. "dma alloc failed for rsp_data.\n");
  685. rval = -ENOMEM;
  686. goto done_free_dma_req;
  687. }
  688. /* Copy the request buffer in req_data now */
  689. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  690. bsg_job->request_payload.sg_cnt, req_data, req_data_len);
  691. elreq.send_dma = req_data_dma;
  692. elreq.rcv_dma = rsp_data_dma;
  693. elreq.transfer_size = req_data_len;
  694. elreq.options = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
  695. elreq.iteration_count =
  696. bsg_job->request->rqst_data.h_vendor.vendor_cmd[2];
  697. if (atomic_read(&vha->loop_state) == LOOP_READY &&
  698. (ha->current_topology == ISP_CFG_F ||
  699. ((IS_QLA81XX(ha) || IS_QLA8031(ha) || IS_QLA8044(ha)) &&
  700. le32_to_cpu(*(uint32_t *)req_data) == ELS_OPCODE_BYTE
  701. && req_data_len == MAX_ELS_FRAME_PAYLOAD)) &&
  702. elreq.options == EXTERNAL_LOOPBACK) {
  703. type = "FC_BSG_HST_VENDOR_ECHO_DIAG";
  704. ql_dbg(ql_dbg_user, vha, 0x701e,
  705. "BSG request type: %s.\n", type);
  706. command_sent = INT_DEF_LB_ECHO_CMD;
  707. rval = qla2x00_echo_test(vha, &elreq, response);
  708. } else {
  709. if (IS_QLA81XX(ha) || IS_QLA8031(ha) || IS_QLA8044(ha)) {
  710. memset(config, 0, sizeof(config));
  711. memset(new_config, 0, sizeof(new_config));
  712. if (qla81xx_get_port_config(vha, config)) {
  713. ql_log(ql_log_warn, vha, 0x701f,
  714. "Get port config failed.\n");
  715. rval = -EPERM;
  716. goto done_free_dma_rsp;
  717. }
  718. if ((config[0] & INTERNAL_LOOPBACK_MASK) != 0) {
  719. ql_dbg(ql_dbg_user, vha, 0x70c4,
  720. "Loopback operation already in "
  721. "progress.\n");
  722. rval = -EAGAIN;
  723. goto done_free_dma_rsp;
  724. }
  725. ql_dbg(ql_dbg_user, vha, 0x70c0,
  726. "elreq.options=%04x\n", elreq.options);
  727. if (elreq.options == EXTERNAL_LOOPBACK)
  728. if (IS_QLA8031(ha) || IS_QLA8044(ha))
  729. rval = qla81xx_set_loopback_mode(vha,
  730. config, new_config, elreq.options);
  731. else
  732. rval = qla81xx_reset_loopback_mode(vha,
  733. config, 1, 0);
  734. else
  735. rval = qla81xx_set_loopback_mode(vha, config,
  736. new_config, elreq.options);
  737. if (rval) {
  738. rval = -EPERM;
  739. goto done_free_dma_rsp;
  740. }
  741. type = "FC_BSG_HST_VENDOR_LOOPBACK";
  742. ql_dbg(ql_dbg_user, vha, 0x7028,
  743. "BSG request type: %s.\n", type);
  744. command_sent = INT_DEF_LB_LOOPBACK_CMD;
  745. rval = qla2x00_loopback_test(vha, &elreq, response);
  746. if (response[0] == MBS_COMMAND_ERROR &&
  747. response[1] == MBS_LB_RESET) {
  748. ql_log(ql_log_warn, vha, 0x7029,
  749. "MBX command error, Aborting ISP.\n");
  750. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  751. qla2xxx_wake_dpc(vha);
  752. qla2x00_wait_for_chip_reset(vha);
  753. /* Also reset the MPI */
  754. if (IS_QLA81XX(ha)) {
  755. if (qla81xx_restart_mpi_firmware(vha) !=
  756. QLA_SUCCESS) {
  757. ql_log(ql_log_warn, vha, 0x702a,
  758. "MPI reset failed.\n");
  759. }
  760. }
  761. rval = -EIO;
  762. goto done_free_dma_rsp;
  763. }
  764. if (new_config[0]) {
  765. int ret;
  766. /* Revert back to original port config
  767. * Also clear internal loopback
  768. */
  769. ret = qla81xx_reset_loopback_mode(vha,
  770. new_config, 0, 1);
  771. if (ret) {
  772. /*
  773. * If the reset of the loopback mode
  774. * doesn't work take FCoE dump and then
  775. * reset the chip.
  776. */
  777. ha->isp_ops->fw_dump(vha, 0);
  778. set_bit(ISP_ABORT_NEEDED,
  779. &vha->dpc_flags);
  780. }
  781. }
  782. } else {
  783. type = "FC_BSG_HST_VENDOR_LOOPBACK";
  784. ql_dbg(ql_dbg_user, vha, 0x702b,
  785. "BSG request type: %s.\n", type);
  786. command_sent = INT_DEF_LB_LOOPBACK_CMD;
  787. rval = qla2x00_loopback_test(vha, &elreq, response);
  788. }
  789. }
  790. if (rval) {
  791. ql_log(ql_log_warn, vha, 0x702c,
  792. "Vendor request %s failed.\n", type);
  793. rval = 0;
  794. bsg_job->reply->result = (DID_ERROR << 16);
  795. bsg_job->reply->reply_payload_rcv_len = 0;
  796. } else {
  797. ql_dbg(ql_dbg_user, vha, 0x702d,
  798. "Vendor request %s completed.\n", type);
  799. bsg_job->reply->result = (DID_OK << 16);
  800. sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
  801. bsg_job->reply_payload.sg_cnt, rsp_data,
  802. rsp_data_len);
  803. }
  804. bsg_job->reply_len = sizeof(struct fc_bsg_reply) +
  805. sizeof(response) + sizeof(uint8_t);
  806. fw_sts_ptr = ((uint8_t *)bsg_job->req->sense) +
  807. sizeof(struct fc_bsg_reply);
  808. memcpy(fw_sts_ptr, response, sizeof(response));
  809. fw_sts_ptr += sizeof(response);
  810. *fw_sts_ptr = command_sent;
  811. done_free_dma_rsp:
  812. dma_free_coherent(&ha->pdev->dev, rsp_data_len,
  813. rsp_data, rsp_data_dma);
  814. done_free_dma_req:
  815. dma_free_coherent(&ha->pdev->dev, req_data_len,
  816. req_data, req_data_dma);
  817. done_unmap_sg:
  818. dma_unmap_sg(&ha->pdev->dev,
  819. bsg_job->reply_payload.sg_list,
  820. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  821. done_unmap_req_sg:
  822. dma_unmap_sg(&ha->pdev->dev,
  823. bsg_job->request_payload.sg_list,
  824. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  825. if (!rval)
  826. bsg_job->job_done(bsg_job);
  827. return rval;
  828. }
  829. static int
  830. qla84xx_reset(struct fc_bsg_job *bsg_job)
  831. {
  832. struct Scsi_Host *host = bsg_job->shost;
  833. scsi_qla_host_t *vha = shost_priv(host);
  834. struct qla_hw_data *ha = vha->hw;
  835. int rval = 0;
  836. uint32_t flag;
  837. if (!IS_QLA84XX(ha)) {
  838. ql_dbg(ql_dbg_user, vha, 0x702f, "Not 84xx, exiting.\n");
  839. return -EINVAL;
  840. }
  841. flag = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
  842. rval = qla84xx_reset_chip(vha, flag == A84_ISSUE_RESET_DIAG_FW);
  843. if (rval) {
  844. ql_log(ql_log_warn, vha, 0x7030,
  845. "Vendor request 84xx reset failed.\n");
  846. rval = (DID_ERROR << 16);
  847. } else {
  848. ql_dbg(ql_dbg_user, vha, 0x7031,
  849. "Vendor request 84xx reset completed.\n");
  850. bsg_job->reply->result = DID_OK;
  851. bsg_job->job_done(bsg_job);
  852. }
  853. return rval;
  854. }
  855. static int
  856. qla84xx_updatefw(struct fc_bsg_job *bsg_job)
  857. {
  858. struct Scsi_Host *host = bsg_job->shost;
  859. scsi_qla_host_t *vha = shost_priv(host);
  860. struct qla_hw_data *ha = vha->hw;
  861. struct verify_chip_entry_84xx *mn = NULL;
  862. dma_addr_t mn_dma, fw_dma;
  863. void *fw_buf = NULL;
  864. int rval = 0;
  865. uint32_t sg_cnt;
  866. uint32_t data_len;
  867. uint16_t options;
  868. uint32_t flag;
  869. uint32_t fw_ver;
  870. if (!IS_QLA84XX(ha)) {
  871. ql_dbg(ql_dbg_user, vha, 0x7032,
  872. "Not 84xx, exiting.\n");
  873. return -EINVAL;
  874. }
  875. sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  876. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  877. if (!sg_cnt) {
  878. ql_log(ql_log_warn, vha, 0x7033,
  879. "dma_map_sg returned %d for request.\n", sg_cnt);
  880. return -ENOMEM;
  881. }
  882. if (sg_cnt != bsg_job->request_payload.sg_cnt) {
  883. ql_log(ql_log_warn, vha, 0x7034,
  884. "DMA mapping resulted in different sg counts, "
  885. "request_sg_cnt: %x dma_request_sg_cnt: %x.\n",
  886. bsg_job->request_payload.sg_cnt, sg_cnt);
  887. rval = -EAGAIN;
  888. goto done_unmap_sg;
  889. }
  890. data_len = bsg_job->request_payload.payload_len;
  891. fw_buf = dma_alloc_coherent(&ha->pdev->dev, data_len,
  892. &fw_dma, GFP_KERNEL);
  893. if (!fw_buf) {
  894. ql_log(ql_log_warn, vha, 0x7035,
  895. "DMA alloc failed for fw_buf.\n");
  896. rval = -ENOMEM;
  897. goto done_unmap_sg;
  898. }
  899. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  900. bsg_job->request_payload.sg_cnt, fw_buf, data_len);
  901. mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
  902. if (!mn) {
  903. ql_log(ql_log_warn, vha, 0x7036,
  904. "DMA alloc failed for fw buffer.\n");
  905. rval = -ENOMEM;
  906. goto done_free_fw_buf;
  907. }
  908. flag = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
  909. fw_ver = le32_to_cpu(*((uint32_t *)((uint32_t *)fw_buf + 2)));
  910. memset(mn, 0, sizeof(struct access_chip_84xx));
  911. mn->entry_type = VERIFY_CHIP_IOCB_TYPE;
  912. mn->entry_count = 1;
  913. options = VCO_FORCE_UPDATE | VCO_END_OF_DATA;
  914. if (flag == A84_ISSUE_UPDATE_DIAGFW_CMD)
  915. options |= VCO_DIAG_FW;
  916. mn->options = cpu_to_le16(options);
  917. mn->fw_ver = cpu_to_le32(fw_ver);
  918. mn->fw_size = cpu_to_le32(data_len);
  919. mn->fw_seq_size = cpu_to_le32(data_len);
  920. mn->dseg_address[0] = cpu_to_le32(LSD(fw_dma));
  921. mn->dseg_address[1] = cpu_to_le32(MSD(fw_dma));
  922. mn->dseg_length = cpu_to_le32(data_len);
  923. mn->data_seg_cnt = cpu_to_le16(1);
  924. rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
  925. if (rval) {
  926. ql_log(ql_log_warn, vha, 0x7037,
  927. "Vendor request 84xx updatefw failed.\n");
  928. rval = (DID_ERROR << 16);
  929. } else {
  930. ql_dbg(ql_dbg_user, vha, 0x7038,
  931. "Vendor request 84xx updatefw completed.\n");
  932. bsg_job->reply_len = sizeof(struct fc_bsg_reply);
  933. bsg_job->reply->result = DID_OK;
  934. }
  935. dma_pool_free(ha->s_dma_pool, mn, mn_dma);
  936. done_free_fw_buf:
  937. dma_free_coherent(&ha->pdev->dev, data_len, fw_buf, fw_dma);
  938. done_unmap_sg:
  939. dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  940. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  941. if (!rval)
  942. bsg_job->job_done(bsg_job);
  943. return rval;
  944. }
  945. static int
  946. qla84xx_mgmt_cmd(struct fc_bsg_job *bsg_job)
  947. {
  948. struct Scsi_Host *host = bsg_job->shost;
  949. scsi_qla_host_t *vha = shost_priv(host);
  950. struct qla_hw_data *ha = vha->hw;
  951. struct access_chip_84xx *mn = NULL;
  952. dma_addr_t mn_dma, mgmt_dma;
  953. void *mgmt_b = NULL;
  954. int rval = 0;
  955. struct qla_bsg_a84_mgmt *ql84_mgmt;
  956. uint32_t sg_cnt;
  957. uint32_t data_len = 0;
  958. uint32_t dma_direction = DMA_NONE;
  959. if (!IS_QLA84XX(ha)) {
  960. ql_log(ql_log_warn, vha, 0x703a,
  961. "Not 84xx, exiting.\n");
  962. return -EINVAL;
  963. }
  964. mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
  965. if (!mn) {
  966. ql_log(ql_log_warn, vha, 0x703c,
  967. "DMA alloc failed for fw buffer.\n");
  968. return -ENOMEM;
  969. }
  970. memset(mn, 0, sizeof(struct access_chip_84xx));
  971. mn->entry_type = ACCESS_CHIP_IOCB_TYPE;
  972. mn->entry_count = 1;
  973. ql84_mgmt = (void *)bsg_job->request + sizeof(struct fc_bsg_request);
  974. switch (ql84_mgmt->mgmt.cmd) {
  975. case QLA84_MGMT_READ_MEM:
  976. case QLA84_MGMT_GET_INFO:
  977. sg_cnt = dma_map_sg(&ha->pdev->dev,
  978. bsg_job->reply_payload.sg_list,
  979. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  980. if (!sg_cnt) {
  981. ql_log(ql_log_warn, vha, 0x703d,
  982. "dma_map_sg returned %d for reply.\n", sg_cnt);
  983. rval = -ENOMEM;
  984. goto exit_mgmt;
  985. }
  986. dma_direction = DMA_FROM_DEVICE;
  987. if (sg_cnt != bsg_job->reply_payload.sg_cnt) {
  988. ql_log(ql_log_warn, vha, 0x703e,
  989. "DMA mapping resulted in different sg counts, "
  990. "reply_sg_cnt: %x dma_reply_sg_cnt: %x.\n",
  991. bsg_job->reply_payload.sg_cnt, sg_cnt);
  992. rval = -EAGAIN;
  993. goto done_unmap_sg;
  994. }
  995. data_len = bsg_job->reply_payload.payload_len;
  996. mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len,
  997. &mgmt_dma, GFP_KERNEL);
  998. if (!mgmt_b) {
  999. ql_log(ql_log_warn, vha, 0x703f,
  1000. "DMA alloc failed for mgmt_b.\n");
  1001. rval = -ENOMEM;
  1002. goto done_unmap_sg;
  1003. }
  1004. if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) {
  1005. mn->options = cpu_to_le16(ACO_DUMP_MEMORY);
  1006. mn->parameter1 =
  1007. cpu_to_le32(
  1008. ql84_mgmt->mgmt.mgmtp.u.mem.start_addr);
  1009. } else if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO) {
  1010. mn->options = cpu_to_le16(ACO_REQUEST_INFO);
  1011. mn->parameter1 =
  1012. cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.info.type);
  1013. mn->parameter2 =
  1014. cpu_to_le32(
  1015. ql84_mgmt->mgmt.mgmtp.u.info.context);
  1016. }
  1017. break;
  1018. case QLA84_MGMT_WRITE_MEM:
  1019. sg_cnt = dma_map_sg(&ha->pdev->dev,
  1020. bsg_job->request_payload.sg_list,
  1021. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1022. if (!sg_cnt) {
  1023. ql_log(ql_log_warn, vha, 0x7040,
  1024. "dma_map_sg returned %d.\n", sg_cnt);
  1025. rval = -ENOMEM;
  1026. goto exit_mgmt;
  1027. }
  1028. dma_direction = DMA_TO_DEVICE;
  1029. if (sg_cnt != bsg_job->request_payload.sg_cnt) {
  1030. ql_log(ql_log_warn, vha, 0x7041,
  1031. "DMA mapping resulted in different sg counts, "
  1032. "request_sg_cnt: %x dma_request_sg_cnt: %x.\n",
  1033. bsg_job->request_payload.sg_cnt, sg_cnt);
  1034. rval = -EAGAIN;
  1035. goto done_unmap_sg;
  1036. }
  1037. data_len = bsg_job->request_payload.payload_len;
  1038. mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len,
  1039. &mgmt_dma, GFP_KERNEL);
  1040. if (!mgmt_b) {
  1041. ql_log(ql_log_warn, vha, 0x7042,
  1042. "DMA alloc failed for mgmt_b.\n");
  1043. rval = -ENOMEM;
  1044. goto done_unmap_sg;
  1045. }
  1046. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  1047. bsg_job->request_payload.sg_cnt, mgmt_b, data_len);
  1048. mn->options = cpu_to_le16(ACO_LOAD_MEMORY);
  1049. mn->parameter1 =
  1050. cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.mem.start_addr);
  1051. break;
  1052. case QLA84_MGMT_CHNG_CONFIG:
  1053. mn->options = cpu_to_le16(ACO_CHANGE_CONFIG_PARAM);
  1054. mn->parameter1 =
  1055. cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.id);
  1056. mn->parameter2 =
  1057. cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param0);
  1058. mn->parameter3 =
  1059. cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param1);
  1060. break;
  1061. default:
  1062. rval = -EIO;
  1063. goto exit_mgmt;
  1064. }
  1065. if (ql84_mgmt->mgmt.cmd != QLA84_MGMT_CHNG_CONFIG) {
  1066. mn->total_byte_cnt = cpu_to_le32(ql84_mgmt->mgmt.len);
  1067. mn->dseg_count = cpu_to_le16(1);
  1068. mn->dseg_address[0] = cpu_to_le32(LSD(mgmt_dma));
  1069. mn->dseg_address[1] = cpu_to_le32(MSD(mgmt_dma));
  1070. mn->dseg_length = cpu_to_le32(ql84_mgmt->mgmt.len);
  1071. }
  1072. rval = qla2x00_issue_iocb(vha, mn, mn_dma, 0);
  1073. if (rval) {
  1074. ql_log(ql_log_warn, vha, 0x7043,
  1075. "Vendor request 84xx mgmt failed.\n");
  1076. rval = (DID_ERROR << 16);
  1077. } else {
  1078. ql_dbg(ql_dbg_user, vha, 0x7044,
  1079. "Vendor request 84xx mgmt completed.\n");
  1080. bsg_job->reply_len = sizeof(struct fc_bsg_reply);
  1081. bsg_job->reply->result = DID_OK;
  1082. if ((ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) ||
  1083. (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO)) {
  1084. bsg_job->reply->reply_payload_rcv_len =
  1085. bsg_job->reply_payload.payload_len;
  1086. sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
  1087. bsg_job->reply_payload.sg_cnt, mgmt_b,
  1088. data_len);
  1089. }
  1090. }
  1091. done_unmap_sg:
  1092. if (mgmt_b)
  1093. dma_free_coherent(&ha->pdev->dev, data_len, mgmt_b, mgmt_dma);
  1094. if (dma_direction == DMA_TO_DEVICE)
  1095. dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  1096. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1097. else if (dma_direction == DMA_FROM_DEVICE)
  1098. dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  1099. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1100. exit_mgmt:
  1101. dma_pool_free(ha->s_dma_pool, mn, mn_dma);
  1102. if (!rval)
  1103. bsg_job->job_done(bsg_job);
  1104. return rval;
  1105. }
  1106. static int
  1107. qla24xx_iidma(struct fc_bsg_job *bsg_job)
  1108. {
  1109. struct Scsi_Host *host = bsg_job->shost;
  1110. scsi_qla_host_t *vha = shost_priv(host);
  1111. int rval = 0;
  1112. struct qla_port_param *port_param = NULL;
  1113. fc_port_t *fcport = NULL;
  1114. int found = 0;
  1115. uint16_t mb[MAILBOX_REGISTER_COUNT];
  1116. uint8_t *rsp_ptr = NULL;
  1117. if (!IS_IIDMA_CAPABLE(vha->hw)) {
  1118. ql_log(ql_log_info, vha, 0x7046, "iiDMA not supported.\n");
  1119. return -EINVAL;
  1120. }
  1121. port_param = (void *)bsg_job->request + sizeof(struct fc_bsg_request);
  1122. if (port_param->fc_scsi_addr.dest_type != EXT_DEF_TYPE_WWPN) {
  1123. ql_log(ql_log_warn, vha, 0x7048,
  1124. "Invalid destination type.\n");
  1125. return -EINVAL;
  1126. }
  1127. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1128. if (fcport->port_type != FCT_TARGET)
  1129. continue;
  1130. if (memcmp(port_param->fc_scsi_addr.dest_addr.wwpn,
  1131. fcport->port_name, sizeof(fcport->port_name)))
  1132. continue;
  1133. found = 1;
  1134. break;
  1135. }
  1136. if (!found) {
  1137. ql_log(ql_log_warn, vha, 0x7049,
  1138. "Failed to find port.\n");
  1139. return -EINVAL;
  1140. }
  1141. if (atomic_read(&fcport->state) != FCS_ONLINE) {
  1142. ql_log(ql_log_warn, vha, 0x704a,
  1143. "Port is not online.\n");
  1144. return -EINVAL;
  1145. }
  1146. if (fcport->flags & FCF_LOGIN_NEEDED) {
  1147. ql_log(ql_log_warn, vha, 0x704b,
  1148. "Remote port not logged in flags = 0x%x.\n", fcport->flags);
  1149. return -EINVAL;
  1150. }
  1151. if (port_param->mode)
  1152. rval = qla2x00_set_idma_speed(vha, fcport->loop_id,
  1153. port_param->speed, mb);
  1154. else
  1155. rval = qla2x00_get_idma_speed(vha, fcport->loop_id,
  1156. &port_param->speed, mb);
  1157. if (rval) {
  1158. ql_log(ql_log_warn, vha, 0x704c,
  1159. "iIDMA cmd failed for %8phN -- "
  1160. "%04x %x %04x %04x.\n", fcport->port_name,
  1161. rval, fcport->fp_speed, mb[0], mb[1]);
  1162. rval = (DID_ERROR << 16);
  1163. } else {
  1164. if (!port_param->mode) {
  1165. bsg_job->reply_len = sizeof(struct fc_bsg_reply) +
  1166. sizeof(struct qla_port_param);
  1167. rsp_ptr = ((uint8_t *)bsg_job->reply) +
  1168. sizeof(struct fc_bsg_reply);
  1169. memcpy(rsp_ptr, port_param,
  1170. sizeof(struct qla_port_param));
  1171. }
  1172. bsg_job->reply->result = DID_OK;
  1173. bsg_job->job_done(bsg_job);
  1174. }
  1175. return rval;
  1176. }
  1177. static int
  1178. qla2x00_optrom_setup(struct fc_bsg_job *bsg_job, scsi_qla_host_t *vha,
  1179. uint8_t is_update)
  1180. {
  1181. uint32_t start = 0;
  1182. int valid = 0;
  1183. struct qla_hw_data *ha = vha->hw;
  1184. if (unlikely(pci_channel_offline(ha->pdev)))
  1185. return -EINVAL;
  1186. start = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
  1187. if (start > ha->optrom_size) {
  1188. ql_log(ql_log_warn, vha, 0x7055,
  1189. "start %d > optrom_size %d.\n", start, ha->optrom_size);
  1190. return -EINVAL;
  1191. }
  1192. if (ha->optrom_state != QLA_SWAITING) {
  1193. ql_log(ql_log_info, vha, 0x7056,
  1194. "optrom_state %d.\n", ha->optrom_state);
  1195. return -EBUSY;
  1196. }
  1197. ha->optrom_region_start = start;
  1198. ql_dbg(ql_dbg_user, vha, 0x7057, "is_update=%d.\n", is_update);
  1199. if (is_update) {
  1200. if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
  1201. valid = 1;
  1202. else if (start == (ha->flt_region_boot * 4) ||
  1203. start == (ha->flt_region_fw * 4))
  1204. valid = 1;
  1205. else if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) ||
  1206. IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha))
  1207. valid = 1;
  1208. if (!valid) {
  1209. ql_log(ql_log_warn, vha, 0x7058,
  1210. "Invalid start region 0x%x/0x%x.\n", start,
  1211. bsg_job->request_payload.payload_len);
  1212. return -EINVAL;
  1213. }
  1214. ha->optrom_region_size = start +
  1215. bsg_job->request_payload.payload_len > ha->optrom_size ?
  1216. ha->optrom_size - start :
  1217. bsg_job->request_payload.payload_len;
  1218. ha->optrom_state = QLA_SWRITING;
  1219. } else {
  1220. ha->optrom_region_size = start +
  1221. bsg_job->reply_payload.payload_len > ha->optrom_size ?
  1222. ha->optrom_size - start :
  1223. bsg_job->reply_payload.payload_len;
  1224. ha->optrom_state = QLA_SREADING;
  1225. }
  1226. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  1227. if (!ha->optrom_buffer) {
  1228. ql_log(ql_log_warn, vha, 0x7059,
  1229. "Read: Unable to allocate memory for optrom retrieval "
  1230. "(%x)\n", ha->optrom_region_size);
  1231. ha->optrom_state = QLA_SWAITING;
  1232. return -ENOMEM;
  1233. }
  1234. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  1235. return 0;
  1236. }
  1237. static int
  1238. qla2x00_read_optrom(struct fc_bsg_job *bsg_job)
  1239. {
  1240. struct Scsi_Host *host = bsg_job->shost;
  1241. scsi_qla_host_t *vha = shost_priv(host);
  1242. struct qla_hw_data *ha = vha->hw;
  1243. int rval = 0;
  1244. if (ha->flags.nic_core_reset_hdlr_active)
  1245. return -EBUSY;
  1246. mutex_lock(&ha->optrom_mutex);
  1247. rval = qla2x00_optrom_setup(bsg_job, vha, 0);
  1248. if (rval) {
  1249. mutex_unlock(&ha->optrom_mutex);
  1250. return rval;
  1251. }
  1252. ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
  1253. ha->optrom_region_start, ha->optrom_region_size);
  1254. sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
  1255. bsg_job->reply_payload.sg_cnt, ha->optrom_buffer,
  1256. ha->optrom_region_size);
  1257. bsg_job->reply->reply_payload_rcv_len = ha->optrom_region_size;
  1258. bsg_job->reply->result = DID_OK;
  1259. vfree(ha->optrom_buffer);
  1260. ha->optrom_buffer = NULL;
  1261. ha->optrom_state = QLA_SWAITING;
  1262. mutex_unlock(&ha->optrom_mutex);
  1263. bsg_job->job_done(bsg_job);
  1264. return rval;
  1265. }
  1266. static int
  1267. qla2x00_update_optrom(struct fc_bsg_job *bsg_job)
  1268. {
  1269. struct Scsi_Host *host = bsg_job->shost;
  1270. scsi_qla_host_t *vha = shost_priv(host);
  1271. struct qla_hw_data *ha = vha->hw;
  1272. int rval = 0;
  1273. mutex_lock(&ha->optrom_mutex);
  1274. rval = qla2x00_optrom_setup(bsg_job, vha, 1);
  1275. if (rval) {
  1276. mutex_unlock(&ha->optrom_mutex);
  1277. return rval;
  1278. }
  1279. /* Set the isp82xx_no_md_cap not to capture minidump */
  1280. ha->flags.isp82xx_no_md_cap = 1;
  1281. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  1282. bsg_job->request_payload.sg_cnt, ha->optrom_buffer,
  1283. ha->optrom_region_size);
  1284. ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
  1285. ha->optrom_region_start, ha->optrom_region_size);
  1286. bsg_job->reply->result = DID_OK;
  1287. vfree(ha->optrom_buffer);
  1288. ha->optrom_buffer = NULL;
  1289. ha->optrom_state = QLA_SWAITING;
  1290. mutex_unlock(&ha->optrom_mutex);
  1291. bsg_job->job_done(bsg_job);
  1292. return rval;
  1293. }
  1294. static int
  1295. qla2x00_update_fru_versions(struct fc_bsg_job *bsg_job)
  1296. {
  1297. struct Scsi_Host *host = bsg_job->shost;
  1298. scsi_qla_host_t *vha = shost_priv(host);
  1299. struct qla_hw_data *ha = vha->hw;
  1300. int rval = 0;
  1301. uint8_t bsg[DMA_POOL_SIZE];
  1302. struct qla_image_version_list *list = (void *)bsg;
  1303. struct qla_image_version *image;
  1304. uint32_t count;
  1305. dma_addr_t sfp_dma;
  1306. void *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
  1307. if (!sfp) {
  1308. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
  1309. EXT_STATUS_NO_MEMORY;
  1310. goto done;
  1311. }
  1312. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  1313. bsg_job->request_payload.sg_cnt, list, sizeof(bsg));
  1314. image = list->version;
  1315. count = list->count;
  1316. while (count--) {
  1317. memcpy(sfp, &image->field_info, sizeof(image->field_info));
  1318. rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
  1319. image->field_address.device, image->field_address.offset,
  1320. sizeof(image->field_info), image->field_address.option);
  1321. if (rval) {
  1322. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
  1323. EXT_STATUS_MAILBOX;
  1324. goto dealloc;
  1325. }
  1326. image++;
  1327. }
  1328. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
  1329. dealloc:
  1330. dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
  1331. done:
  1332. bsg_job->reply_len = sizeof(struct fc_bsg_reply);
  1333. bsg_job->reply->result = DID_OK << 16;
  1334. bsg_job->job_done(bsg_job);
  1335. return 0;
  1336. }
  1337. static int
  1338. qla2x00_read_fru_status(struct fc_bsg_job *bsg_job)
  1339. {
  1340. struct Scsi_Host *host = bsg_job->shost;
  1341. scsi_qla_host_t *vha = shost_priv(host);
  1342. struct qla_hw_data *ha = vha->hw;
  1343. int rval = 0;
  1344. uint8_t bsg[DMA_POOL_SIZE];
  1345. struct qla_status_reg *sr = (void *)bsg;
  1346. dma_addr_t sfp_dma;
  1347. uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
  1348. if (!sfp) {
  1349. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
  1350. EXT_STATUS_NO_MEMORY;
  1351. goto done;
  1352. }
  1353. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  1354. bsg_job->request_payload.sg_cnt, sr, sizeof(*sr));
  1355. rval = qla2x00_read_sfp(vha, sfp_dma, sfp,
  1356. sr->field_address.device, sr->field_address.offset,
  1357. sizeof(sr->status_reg), sr->field_address.option);
  1358. sr->status_reg = *sfp;
  1359. if (rval) {
  1360. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
  1361. EXT_STATUS_MAILBOX;
  1362. goto dealloc;
  1363. }
  1364. sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
  1365. bsg_job->reply_payload.sg_cnt, sr, sizeof(*sr));
  1366. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
  1367. dealloc:
  1368. dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
  1369. done:
  1370. bsg_job->reply_len = sizeof(struct fc_bsg_reply);
  1371. bsg_job->reply->reply_payload_rcv_len = sizeof(*sr);
  1372. bsg_job->reply->result = DID_OK << 16;
  1373. bsg_job->job_done(bsg_job);
  1374. return 0;
  1375. }
  1376. static int
  1377. qla2x00_write_fru_status(struct fc_bsg_job *bsg_job)
  1378. {
  1379. struct Scsi_Host *host = bsg_job->shost;
  1380. scsi_qla_host_t *vha = shost_priv(host);
  1381. struct qla_hw_data *ha = vha->hw;
  1382. int rval = 0;
  1383. uint8_t bsg[DMA_POOL_SIZE];
  1384. struct qla_status_reg *sr = (void *)bsg;
  1385. dma_addr_t sfp_dma;
  1386. uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
  1387. if (!sfp) {
  1388. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
  1389. EXT_STATUS_NO_MEMORY;
  1390. goto done;
  1391. }
  1392. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  1393. bsg_job->request_payload.sg_cnt, sr, sizeof(*sr));
  1394. *sfp = sr->status_reg;
  1395. rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
  1396. sr->field_address.device, sr->field_address.offset,
  1397. sizeof(sr->status_reg), sr->field_address.option);
  1398. if (rval) {
  1399. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
  1400. EXT_STATUS_MAILBOX;
  1401. goto dealloc;
  1402. }
  1403. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
  1404. dealloc:
  1405. dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
  1406. done:
  1407. bsg_job->reply_len = sizeof(struct fc_bsg_reply);
  1408. bsg_job->reply->result = DID_OK << 16;
  1409. bsg_job->job_done(bsg_job);
  1410. return 0;
  1411. }
  1412. static int
  1413. qla2x00_write_i2c(struct fc_bsg_job *bsg_job)
  1414. {
  1415. struct Scsi_Host *host = bsg_job->shost;
  1416. scsi_qla_host_t *vha = shost_priv(host);
  1417. struct qla_hw_data *ha = vha->hw;
  1418. int rval = 0;
  1419. uint8_t bsg[DMA_POOL_SIZE];
  1420. struct qla_i2c_access *i2c = (void *)bsg;
  1421. dma_addr_t sfp_dma;
  1422. uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
  1423. if (!sfp) {
  1424. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
  1425. EXT_STATUS_NO_MEMORY;
  1426. goto done;
  1427. }
  1428. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  1429. bsg_job->request_payload.sg_cnt, i2c, sizeof(*i2c));
  1430. memcpy(sfp, i2c->buffer, i2c->length);
  1431. rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
  1432. i2c->device, i2c->offset, i2c->length, i2c->option);
  1433. if (rval) {
  1434. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
  1435. EXT_STATUS_MAILBOX;
  1436. goto dealloc;
  1437. }
  1438. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
  1439. dealloc:
  1440. dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
  1441. done:
  1442. bsg_job->reply_len = sizeof(struct fc_bsg_reply);
  1443. bsg_job->reply->result = DID_OK << 16;
  1444. bsg_job->job_done(bsg_job);
  1445. return 0;
  1446. }
  1447. static int
  1448. qla2x00_read_i2c(struct fc_bsg_job *bsg_job)
  1449. {
  1450. struct Scsi_Host *host = bsg_job->shost;
  1451. scsi_qla_host_t *vha = shost_priv(host);
  1452. struct qla_hw_data *ha = vha->hw;
  1453. int rval = 0;
  1454. uint8_t bsg[DMA_POOL_SIZE];
  1455. struct qla_i2c_access *i2c = (void *)bsg;
  1456. dma_addr_t sfp_dma;
  1457. uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
  1458. if (!sfp) {
  1459. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
  1460. EXT_STATUS_NO_MEMORY;
  1461. goto done;
  1462. }
  1463. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  1464. bsg_job->request_payload.sg_cnt, i2c, sizeof(*i2c));
  1465. rval = qla2x00_read_sfp(vha, sfp_dma, sfp,
  1466. i2c->device, i2c->offset, i2c->length, i2c->option);
  1467. if (rval) {
  1468. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
  1469. EXT_STATUS_MAILBOX;
  1470. goto dealloc;
  1471. }
  1472. memcpy(i2c->buffer, sfp, i2c->length);
  1473. sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
  1474. bsg_job->reply_payload.sg_cnt, i2c, sizeof(*i2c));
  1475. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
  1476. dealloc:
  1477. dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
  1478. done:
  1479. bsg_job->reply_len = sizeof(struct fc_bsg_reply);
  1480. bsg_job->reply->reply_payload_rcv_len = sizeof(*i2c);
  1481. bsg_job->reply->result = DID_OK << 16;
  1482. bsg_job->job_done(bsg_job);
  1483. return 0;
  1484. }
  1485. static int
  1486. qla24xx_process_bidir_cmd(struct fc_bsg_job *bsg_job)
  1487. {
  1488. struct Scsi_Host *host = bsg_job->shost;
  1489. scsi_qla_host_t *vha = shost_priv(host);
  1490. struct qla_hw_data *ha = vha->hw;
  1491. uint32_t rval = EXT_STATUS_OK;
  1492. uint16_t req_sg_cnt = 0;
  1493. uint16_t rsp_sg_cnt = 0;
  1494. uint16_t nextlid = 0;
  1495. uint32_t tot_dsds;
  1496. srb_t *sp = NULL;
  1497. uint32_t req_data_len = 0;
  1498. uint32_t rsp_data_len = 0;
  1499. /* Check the type of the adapter */
  1500. if (!IS_BIDI_CAPABLE(ha)) {
  1501. ql_log(ql_log_warn, vha, 0x70a0,
  1502. "This adapter is not supported\n");
  1503. rval = EXT_STATUS_NOT_SUPPORTED;
  1504. goto done;
  1505. }
  1506. if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
  1507. test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  1508. test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
  1509. rval = EXT_STATUS_BUSY;
  1510. goto done;
  1511. }
  1512. /* Check if host is online */
  1513. if (!vha->flags.online) {
  1514. ql_log(ql_log_warn, vha, 0x70a1,
  1515. "Host is not online\n");
  1516. rval = EXT_STATUS_DEVICE_OFFLINE;
  1517. goto done;
  1518. }
  1519. /* Check if cable is plugged in or not */
  1520. if (vha->device_flags & DFLG_NO_CABLE) {
  1521. ql_log(ql_log_warn, vha, 0x70a2,
  1522. "Cable is unplugged...\n");
  1523. rval = EXT_STATUS_INVALID_CFG;
  1524. goto done;
  1525. }
  1526. /* Check if the switch is connected or not */
  1527. if (ha->current_topology != ISP_CFG_F) {
  1528. ql_log(ql_log_warn, vha, 0x70a3,
  1529. "Host is not connected to the switch\n");
  1530. rval = EXT_STATUS_INVALID_CFG;
  1531. goto done;
  1532. }
  1533. /* Check if operating mode is P2P */
  1534. if (ha->operating_mode != P2P) {
  1535. ql_log(ql_log_warn, vha, 0x70a4,
  1536. "Host is operating mode is not P2p\n");
  1537. rval = EXT_STATUS_INVALID_CFG;
  1538. goto done;
  1539. }
  1540. mutex_lock(&ha->selflogin_lock);
  1541. if (vha->self_login_loop_id == 0) {
  1542. /* Initialize all required fields of fcport */
  1543. vha->bidir_fcport.vha = vha;
  1544. vha->bidir_fcport.d_id.b.al_pa = vha->d_id.b.al_pa;
  1545. vha->bidir_fcport.d_id.b.area = vha->d_id.b.area;
  1546. vha->bidir_fcport.d_id.b.domain = vha->d_id.b.domain;
  1547. vha->bidir_fcport.loop_id = vha->loop_id;
  1548. if (qla2x00_fabric_login(vha, &(vha->bidir_fcport), &nextlid)) {
  1549. ql_log(ql_log_warn, vha, 0x70a7,
  1550. "Failed to login port %06X for bidirectional IOCB\n",
  1551. vha->bidir_fcport.d_id.b24);
  1552. mutex_unlock(&ha->selflogin_lock);
  1553. rval = EXT_STATUS_MAILBOX;
  1554. goto done;
  1555. }
  1556. vha->self_login_loop_id = nextlid - 1;
  1557. }
  1558. /* Assign the self login loop id to fcport */
  1559. mutex_unlock(&ha->selflogin_lock);
  1560. vha->bidir_fcport.loop_id = vha->self_login_loop_id;
  1561. req_sg_cnt = dma_map_sg(&ha->pdev->dev,
  1562. bsg_job->request_payload.sg_list,
  1563. bsg_job->request_payload.sg_cnt,
  1564. DMA_TO_DEVICE);
  1565. if (!req_sg_cnt) {
  1566. rval = EXT_STATUS_NO_MEMORY;
  1567. goto done;
  1568. }
  1569. rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
  1570. bsg_job->reply_payload.sg_list, bsg_job->reply_payload.sg_cnt,
  1571. DMA_FROM_DEVICE);
  1572. if (!rsp_sg_cnt) {
  1573. rval = EXT_STATUS_NO_MEMORY;
  1574. goto done_unmap_req_sg;
  1575. }
  1576. if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
  1577. (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
  1578. ql_dbg(ql_dbg_user, vha, 0x70a9,
  1579. "Dma mapping resulted in different sg counts "
  1580. "[request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt: "
  1581. "%x dma_reply_sg_cnt: %x]\n",
  1582. bsg_job->request_payload.sg_cnt, req_sg_cnt,
  1583. bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
  1584. rval = EXT_STATUS_NO_MEMORY;
  1585. goto done_unmap_sg;
  1586. }
  1587. if (req_data_len != rsp_data_len) {
  1588. rval = EXT_STATUS_BUSY;
  1589. ql_log(ql_log_warn, vha, 0x70aa,
  1590. "req_data_len != rsp_data_len\n");
  1591. goto done_unmap_sg;
  1592. }
  1593. req_data_len = bsg_job->request_payload.payload_len;
  1594. rsp_data_len = bsg_job->reply_payload.payload_len;
  1595. /* Alloc SRB structure */
  1596. sp = qla2x00_get_sp(vha, &(vha->bidir_fcport), GFP_KERNEL);
  1597. if (!sp) {
  1598. ql_dbg(ql_dbg_user, vha, 0x70ac,
  1599. "Alloc SRB structure failed\n");
  1600. rval = EXT_STATUS_NO_MEMORY;
  1601. goto done_unmap_sg;
  1602. }
  1603. /*Populate srb->ctx with bidir ctx*/
  1604. sp->u.bsg_job = bsg_job;
  1605. sp->free = qla2x00_bsg_sp_free;
  1606. sp->type = SRB_BIDI_CMD;
  1607. sp->done = qla2x00_bsg_job_done;
  1608. /* Add the read and write sg count */
  1609. tot_dsds = rsp_sg_cnt + req_sg_cnt;
  1610. rval = qla2x00_start_bidir(sp, vha, tot_dsds);
  1611. if (rval != EXT_STATUS_OK)
  1612. goto done_free_srb;
  1613. /* the bsg request will be completed in the interrupt handler */
  1614. return rval;
  1615. done_free_srb:
  1616. mempool_free(sp, ha->srb_mempool);
  1617. done_unmap_sg:
  1618. dma_unmap_sg(&ha->pdev->dev,
  1619. bsg_job->reply_payload.sg_list,
  1620. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1621. done_unmap_req_sg:
  1622. dma_unmap_sg(&ha->pdev->dev,
  1623. bsg_job->request_payload.sg_list,
  1624. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1625. done:
  1626. /* Return an error vendor specific response
  1627. * and complete the bsg request
  1628. */
  1629. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = rval;
  1630. bsg_job->reply_len = sizeof(struct fc_bsg_reply);
  1631. bsg_job->reply->reply_payload_rcv_len = 0;
  1632. bsg_job->reply->result = (DID_OK) << 16;
  1633. bsg_job->job_done(bsg_job);
  1634. /* Always return success, vendor rsp carries correct status */
  1635. return 0;
  1636. }
  1637. static int
  1638. qlafx00_mgmt_cmd(struct fc_bsg_job *bsg_job)
  1639. {
  1640. struct Scsi_Host *host = bsg_job->shost;
  1641. scsi_qla_host_t *vha = shost_priv(host);
  1642. struct qla_hw_data *ha = vha->hw;
  1643. int rval = (DRIVER_ERROR << 16);
  1644. struct qla_mt_iocb_rqst_fx00 *piocb_rqst;
  1645. srb_t *sp;
  1646. int req_sg_cnt = 0, rsp_sg_cnt = 0;
  1647. struct fc_port *fcport;
  1648. char *type = "FC_BSG_HST_FX_MGMT";
  1649. /* Copy the IOCB specific information */
  1650. piocb_rqst = (struct qla_mt_iocb_rqst_fx00 *)
  1651. &bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
  1652. /* Dump the vendor information */
  1653. ql_dump_buffer(ql_dbg_user + ql_dbg_verbose , vha, 0x70cf,
  1654. (uint8_t *)piocb_rqst, sizeof(struct qla_mt_iocb_rqst_fx00));
  1655. if (!vha->flags.online) {
  1656. ql_log(ql_log_warn, vha, 0x70d0,
  1657. "Host is not online.\n");
  1658. rval = -EIO;
  1659. goto done;
  1660. }
  1661. if (piocb_rqst->flags & SRB_FXDISC_REQ_DMA_VALID) {
  1662. req_sg_cnt = dma_map_sg(&ha->pdev->dev,
  1663. bsg_job->request_payload.sg_list,
  1664. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1665. if (!req_sg_cnt) {
  1666. ql_log(ql_log_warn, vha, 0x70c7,
  1667. "dma_map_sg return %d for request\n", req_sg_cnt);
  1668. rval = -ENOMEM;
  1669. goto done;
  1670. }
  1671. }
  1672. if (piocb_rqst->flags & SRB_FXDISC_RESP_DMA_VALID) {
  1673. rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
  1674. bsg_job->reply_payload.sg_list,
  1675. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1676. if (!rsp_sg_cnt) {
  1677. ql_log(ql_log_warn, vha, 0x70c8,
  1678. "dma_map_sg return %d for reply\n", rsp_sg_cnt);
  1679. rval = -ENOMEM;
  1680. goto done_unmap_req_sg;
  1681. }
  1682. }
  1683. ql_dbg(ql_dbg_user, vha, 0x70c9,
  1684. "request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt:%x "
  1685. "dma_reply_sg_cnt: %x\n", bsg_job->request_payload.sg_cnt,
  1686. req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
  1687. /* Allocate a dummy fcport structure, since functions preparing the
  1688. * IOCB and mailbox command retrieves port specific information
  1689. * from fcport structure. For Host based ELS commands there will be
  1690. * no fcport structure allocated
  1691. */
  1692. fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  1693. if (!fcport) {
  1694. ql_log(ql_log_warn, vha, 0x70ca,
  1695. "Failed to allocate fcport.\n");
  1696. rval = -ENOMEM;
  1697. goto done_unmap_rsp_sg;
  1698. }
  1699. /* Alloc SRB structure */
  1700. sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
  1701. if (!sp) {
  1702. ql_log(ql_log_warn, vha, 0x70cb,
  1703. "qla2x00_get_sp failed.\n");
  1704. rval = -ENOMEM;
  1705. goto done_free_fcport;
  1706. }
  1707. /* Initialize all required fields of fcport */
  1708. fcport->vha = vha;
  1709. fcport->loop_id = piocb_rqst->dataword;
  1710. sp->type = SRB_FXIOCB_BCMD;
  1711. sp->name = "bsg_fx_mgmt";
  1712. sp->iocbs = qla24xx_calc_ct_iocbs(req_sg_cnt + rsp_sg_cnt);
  1713. sp->u.bsg_job = bsg_job;
  1714. sp->free = qla2x00_bsg_sp_free;
  1715. sp->done = qla2x00_bsg_job_done;
  1716. ql_dbg(ql_dbg_user, vha, 0x70cc,
  1717. "bsg rqst type: %s fx_mgmt_type: %x id=%x\n",
  1718. type, piocb_rqst->func_type, fcport->loop_id);
  1719. rval = qla2x00_start_sp(sp);
  1720. if (rval != QLA_SUCCESS) {
  1721. ql_log(ql_log_warn, vha, 0x70cd,
  1722. "qla2x00_start_sp failed=%d.\n", rval);
  1723. mempool_free(sp, ha->srb_mempool);
  1724. rval = -EIO;
  1725. goto done_free_fcport;
  1726. }
  1727. return rval;
  1728. done_free_fcport:
  1729. kfree(fcport);
  1730. done_unmap_rsp_sg:
  1731. if (piocb_rqst->flags & SRB_FXDISC_RESP_DMA_VALID)
  1732. dma_unmap_sg(&ha->pdev->dev,
  1733. bsg_job->reply_payload.sg_list,
  1734. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1735. done_unmap_req_sg:
  1736. if (piocb_rqst->flags & SRB_FXDISC_REQ_DMA_VALID)
  1737. dma_unmap_sg(&ha->pdev->dev,
  1738. bsg_job->request_payload.sg_list,
  1739. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1740. done:
  1741. return rval;
  1742. }
  1743. static int
  1744. qla26xx_serdes_op(struct fc_bsg_job *bsg_job)
  1745. {
  1746. struct Scsi_Host *host = bsg_job->shost;
  1747. scsi_qla_host_t *vha = shost_priv(host);
  1748. int rval = 0;
  1749. struct qla_serdes_reg sr;
  1750. memset(&sr, 0, sizeof(sr));
  1751. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  1752. bsg_job->request_payload.sg_cnt, &sr, sizeof(sr));
  1753. switch (sr.cmd) {
  1754. case INT_SC_SERDES_WRITE_REG:
  1755. rval = qla2x00_write_serdes_word(vha, sr.addr, sr.val);
  1756. bsg_job->reply->reply_payload_rcv_len = 0;
  1757. break;
  1758. case INT_SC_SERDES_READ_REG:
  1759. rval = qla2x00_read_serdes_word(vha, sr.addr, &sr.val);
  1760. sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
  1761. bsg_job->reply_payload.sg_cnt, &sr, sizeof(sr));
  1762. bsg_job->reply->reply_payload_rcv_len = sizeof(sr);
  1763. break;
  1764. default:
  1765. ql_dbg(ql_dbg_user, vha, 0x708c,
  1766. "Unknown serdes cmd %x.\n", sr.cmd);
  1767. rval = -EINVAL;
  1768. break;
  1769. }
  1770. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
  1771. rval ? EXT_STATUS_MAILBOX : 0;
  1772. bsg_job->reply_len = sizeof(struct fc_bsg_reply);
  1773. bsg_job->reply->result = DID_OK << 16;
  1774. bsg_job->job_done(bsg_job);
  1775. return 0;
  1776. }
  1777. static int
  1778. qla8044_serdes_op(struct fc_bsg_job *bsg_job)
  1779. {
  1780. struct Scsi_Host *host = bsg_job->shost;
  1781. scsi_qla_host_t *vha = shost_priv(host);
  1782. int rval = 0;
  1783. struct qla_serdes_reg_ex sr;
  1784. memset(&sr, 0, sizeof(sr));
  1785. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  1786. bsg_job->request_payload.sg_cnt, &sr, sizeof(sr));
  1787. switch (sr.cmd) {
  1788. case INT_SC_SERDES_WRITE_REG:
  1789. rval = qla8044_write_serdes_word(vha, sr.addr, sr.val);
  1790. bsg_job->reply->reply_payload_rcv_len = 0;
  1791. break;
  1792. case INT_SC_SERDES_READ_REG:
  1793. rval = qla8044_read_serdes_word(vha, sr.addr, &sr.val);
  1794. sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
  1795. bsg_job->reply_payload.sg_cnt, &sr, sizeof(sr));
  1796. bsg_job->reply->reply_payload_rcv_len = sizeof(sr);
  1797. break;
  1798. default:
  1799. ql_dbg(ql_dbg_user, vha, 0x70cf,
  1800. "Unknown serdes cmd %x.\n", sr.cmd);
  1801. rval = -EINVAL;
  1802. break;
  1803. }
  1804. bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
  1805. rval ? EXT_STATUS_MAILBOX : 0;
  1806. bsg_job->reply_len = sizeof(struct fc_bsg_reply);
  1807. bsg_job->reply->result = DID_OK << 16;
  1808. bsg_job->job_done(bsg_job);
  1809. return 0;
  1810. }
  1811. static int
  1812. qla2x00_process_vendor_specific(struct fc_bsg_job *bsg_job)
  1813. {
  1814. switch (bsg_job->request->rqst_data.h_vendor.vendor_cmd[0]) {
  1815. case QL_VND_LOOPBACK:
  1816. return qla2x00_process_loopback(bsg_job);
  1817. case QL_VND_A84_RESET:
  1818. return qla84xx_reset(bsg_job);
  1819. case QL_VND_A84_UPDATE_FW:
  1820. return qla84xx_updatefw(bsg_job);
  1821. case QL_VND_A84_MGMT_CMD:
  1822. return qla84xx_mgmt_cmd(bsg_job);
  1823. case QL_VND_IIDMA:
  1824. return qla24xx_iidma(bsg_job);
  1825. case QL_VND_FCP_PRIO_CFG_CMD:
  1826. return qla24xx_proc_fcp_prio_cfg_cmd(bsg_job);
  1827. case QL_VND_READ_FLASH:
  1828. return qla2x00_read_optrom(bsg_job);
  1829. case QL_VND_UPDATE_FLASH:
  1830. return qla2x00_update_optrom(bsg_job);
  1831. case QL_VND_SET_FRU_VERSION:
  1832. return qla2x00_update_fru_versions(bsg_job);
  1833. case QL_VND_READ_FRU_STATUS:
  1834. return qla2x00_read_fru_status(bsg_job);
  1835. case QL_VND_WRITE_FRU_STATUS:
  1836. return qla2x00_write_fru_status(bsg_job);
  1837. case QL_VND_WRITE_I2C:
  1838. return qla2x00_write_i2c(bsg_job);
  1839. case QL_VND_READ_I2C:
  1840. return qla2x00_read_i2c(bsg_job);
  1841. case QL_VND_DIAG_IO_CMD:
  1842. return qla24xx_process_bidir_cmd(bsg_job);
  1843. case QL_VND_FX00_MGMT_CMD:
  1844. return qlafx00_mgmt_cmd(bsg_job);
  1845. case QL_VND_SERDES_OP:
  1846. return qla26xx_serdes_op(bsg_job);
  1847. case QL_VND_SERDES_OP_EX:
  1848. return qla8044_serdes_op(bsg_job);
  1849. default:
  1850. return -ENOSYS;
  1851. }
  1852. }
  1853. int
  1854. qla24xx_bsg_request(struct fc_bsg_job *bsg_job)
  1855. {
  1856. int ret = -EINVAL;
  1857. struct fc_rport *rport;
  1858. struct Scsi_Host *host;
  1859. scsi_qla_host_t *vha;
  1860. /* In case no data transferred. */
  1861. bsg_job->reply->reply_payload_rcv_len = 0;
  1862. if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) {
  1863. rport = bsg_job->rport;
  1864. host = rport_to_shost(rport);
  1865. vha = shost_priv(host);
  1866. } else {
  1867. host = bsg_job->shost;
  1868. vha = shost_priv(host);
  1869. }
  1870. if (qla2x00_reset_active(vha)) {
  1871. ql_dbg(ql_dbg_user, vha, 0x709f,
  1872. "BSG: ISP abort active/needed -- cmd=%d.\n",
  1873. bsg_job->request->msgcode);
  1874. return -EBUSY;
  1875. }
  1876. ql_dbg(ql_dbg_user, vha, 0x7000,
  1877. "Entered %s msgcode=0x%x.\n", __func__, bsg_job->request->msgcode);
  1878. switch (bsg_job->request->msgcode) {
  1879. case FC_BSG_RPT_ELS:
  1880. case FC_BSG_HST_ELS_NOLOGIN:
  1881. ret = qla2x00_process_els(bsg_job);
  1882. break;
  1883. case FC_BSG_HST_CT:
  1884. ret = qla2x00_process_ct(bsg_job);
  1885. break;
  1886. case FC_BSG_HST_VENDOR:
  1887. ret = qla2x00_process_vendor_specific(bsg_job);
  1888. break;
  1889. case FC_BSG_HST_ADD_RPORT:
  1890. case FC_BSG_HST_DEL_RPORT:
  1891. case FC_BSG_RPT_CT:
  1892. default:
  1893. ql_log(ql_log_warn, vha, 0x705a, "Unsupported BSG request.\n");
  1894. break;
  1895. }
  1896. return ret;
  1897. }
  1898. int
  1899. qla24xx_bsg_timeout(struct fc_bsg_job *bsg_job)
  1900. {
  1901. scsi_qla_host_t *vha = shost_priv(bsg_job->shost);
  1902. struct qla_hw_data *ha = vha->hw;
  1903. srb_t *sp;
  1904. int cnt, que;
  1905. unsigned long flags;
  1906. struct req_que *req;
  1907. /* find the bsg job from the active list of commands */
  1908. spin_lock_irqsave(&ha->hardware_lock, flags);
  1909. for (que = 0; que < ha->max_req_queues; que++) {
  1910. req = ha->req_q_map[que];
  1911. if (!req)
  1912. continue;
  1913. for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
  1914. sp = req->outstanding_cmds[cnt];
  1915. if (sp) {
  1916. if (((sp->type == SRB_CT_CMD) ||
  1917. (sp->type == SRB_ELS_CMD_HST) ||
  1918. (sp->type == SRB_FXIOCB_BCMD))
  1919. && (sp->u.bsg_job == bsg_job)) {
  1920. req->outstanding_cmds[cnt] = NULL;
  1921. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1922. if (ha->isp_ops->abort_command(sp)) {
  1923. ql_log(ql_log_warn, vha, 0x7089,
  1924. "mbx abort_command "
  1925. "failed.\n");
  1926. bsg_job->req->errors =
  1927. bsg_job->reply->result = -EIO;
  1928. } else {
  1929. ql_dbg(ql_dbg_user, vha, 0x708a,
  1930. "mbx abort_command "
  1931. "success.\n");
  1932. bsg_job->req->errors =
  1933. bsg_job->reply->result = 0;
  1934. }
  1935. spin_lock_irqsave(&ha->hardware_lock, flags);
  1936. goto done;
  1937. }
  1938. }
  1939. }
  1940. }
  1941. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1942. ql_log(ql_log_info, vha, 0x708b, "SRB not found to abort.\n");
  1943. bsg_job->req->errors = bsg_job->reply->result = -ENXIO;
  1944. return 0;
  1945. done:
  1946. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1947. sp->free(vha, sp);
  1948. return 0;
  1949. }