qla_bsg.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2008 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(struct qla_fcp_prio_cfg *pri_cfg, uint8_t flag)
  35. {
  36. int i, ret, num_valid;
  37. uint8_t *bcode;
  38. struct qla_fcp_prio_entry *pri_entry;
  39. ret = 1;
  40. num_valid = 0;
  41. bcode = (uint8_t *)pri_cfg;
  42. if (bcode[0x0] != 'H' || bcode[0x1] != 'Q' || bcode[0x2] != 'O' ||
  43. bcode[0x3] != 'S') {
  44. return 0;
  45. }
  46. if (flag != 1)
  47. return ret;
  48. pri_entry = &pri_cfg->entry[0];
  49. for (i = 0; i < pri_cfg->num_entries; i++) {
  50. if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
  51. num_valid++;
  52. pri_entry++;
  53. }
  54. if (num_valid == 0)
  55. ret = 0;
  56. return ret;
  57. }
  58. static int
  59. qla24xx_proc_fcp_prio_cfg_cmd(struct fc_bsg_job *bsg_job)
  60. {
  61. struct Scsi_Host *host = bsg_job->shost;
  62. scsi_qla_host_t *vha = shost_priv(host);
  63. struct qla_hw_data *ha = vha->hw;
  64. int ret = 0;
  65. uint32_t len;
  66. uint32_t oper;
  67. bsg_job->reply->reply_payload_rcv_len = 0;
  68. if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
  69. test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  70. test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
  71. ret = -EBUSY;
  72. goto exit_fcp_prio_cfg;
  73. }
  74. /* Get the sub command */
  75. oper = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
  76. /* Only set config is allowed if config memory is not allocated */
  77. if (!ha->fcp_prio_cfg && (oper != QLFC_FCP_PRIO_SET_CONFIG)) {
  78. ret = -EINVAL;
  79. goto exit_fcp_prio_cfg;
  80. }
  81. switch (oper) {
  82. case QLFC_FCP_PRIO_DISABLE:
  83. if (ha->flags.fcp_prio_enabled) {
  84. ha->flags.fcp_prio_enabled = 0;
  85. ha->fcp_prio_cfg->attributes &=
  86. ~FCP_PRIO_ATTR_ENABLE;
  87. qla24xx_update_all_fcp_prio(vha);
  88. bsg_job->reply->result = DID_OK;
  89. } else {
  90. ret = -EINVAL;
  91. bsg_job->reply->result = (DID_ERROR << 16);
  92. goto exit_fcp_prio_cfg;
  93. }
  94. break;
  95. case QLFC_FCP_PRIO_ENABLE:
  96. if (!ha->flags.fcp_prio_enabled) {
  97. if (ha->fcp_prio_cfg) {
  98. ha->flags.fcp_prio_enabled = 1;
  99. ha->fcp_prio_cfg->attributes |=
  100. FCP_PRIO_ATTR_ENABLE;
  101. qla24xx_update_all_fcp_prio(vha);
  102. bsg_job->reply->result = DID_OK;
  103. } else {
  104. ret = -EINVAL;
  105. bsg_job->reply->result = (DID_ERROR << 16);
  106. goto exit_fcp_prio_cfg;
  107. }
  108. }
  109. break;
  110. case QLFC_FCP_PRIO_GET_CONFIG:
  111. len = bsg_job->reply_payload.payload_len;
  112. if (!len || len > FCP_PRIO_CFG_SIZE) {
  113. ret = -EINVAL;
  114. bsg_job->reply->result = (DID_ERROR << 16);
  115. goto exit_fcp_prio_cfg;
  116. }
  117. bsg_job->reply->result = DID_OK;
  118. bsg_job->reply->reply_payload_rcv_len =
  119. sg_copy_from_buffer(
  120. bsg_job->reply_payload.sg_list,
  121. bsg_job->reply_payload.sg_cnt, ha->fcp_prio_cfg,
  122. len);
  123. break;
  124. case QLFC_FCP_PRIO_SET_CONFIG:
  125. len = bsg_job->request_payload.payload_len;
  126. if (!len || len > FCP_PRIO_CFG_SIZE) {
  127. bsg_job->reply->result = (DID_ERROR << 16);
  128. ret = -EINVAL;
  129. goto exit_fcp_prio_cfg;
  130. }
  131. if (!ha->fcp_prio_cfg) {
  132. ha->fcp_prio_cfg = vmalloc(FCP_PRIO_CFG_SIZE);
  133. if (!ha->fcp_prio_cfg) {
  134. qla_printk(KERN_WARNING, ha,
  135. "Unable to allocate memory "
  136. "for fcp prio config data (%x).\n",
  137. FCP_PRIO_CFG_SIZE);
  138. bsg_job->reply->result = (DID_ERROR << 16);
  139. ret = -ENOMEM;
  140. goto exit_fcp_prio_cfg;
  141. }
  142. }
  143. memset(ha->fcp_prio_cfg, 0, FCP_PRIO_CFG_SIZE);
  144. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  145. bsg_job->request_payload.sg_cnt, ha->fcp_prio_cfg,
  146. FCP_PRIO_CFG_SIZE);
  147. /* validate fcp priority data */
  148. if (!qla24xx_fcp_prio_cfg_valid(
  149. (struct qla_fcp_prio_cfg *)
  150. ha->fcp_prio_cfg, 1)) {
  151. bsg_job->reply->result = (DID_ERROR << 16);
  152. ret = -EINVAL;
  153. /* If buffer was invalidatic int
  154. * fcp_prio_cfg is of no use
  155. */
  156. vfree(ha->fcp_prio_cfg);
  157. ha->fcp_prio_cfg = NULL;
  158. goto exit_fcp_prio_cfg;
  159. }
  160. ha->flags.fcp_prio_enabled = 0;
  161. if (ha->fcp_prio_cfg->attributes & FCP_PRIO_ATTR_ENABLE)
  162. ha->flags.fcp_prio_enabled = 1;
  163. qla24xx_update_all_fcp_prio(vha);
  164. bsg_job->reply->result = DID_OK;
  165. break;
  166. default:
  167. ret = -EINVAL;
  168. break;
  169. }
  170. exit_fcp_prio_cfg:
  171. bsg_job->job_done(bsg_job);
  172. return ret;
  173. }
  174. static int
  175. qla2x00_process_els(struct fc_bsg_job *bsg_job)
  176. {
  177. struct fc_rport *rport;
  178. fc_port_t *fcport;
  179. struct Scsi_Host *host;
  180. scsi_qla_host_t *vha;
  181. struct qla_hw_data *ha;
  182. srb_t *sp;
  183. const char *type;
  184. int req_sg_cnt, rsp_sg_cnt;
  185. int rval = (DRIVER_ERROR << 16);
  186. uint16_t nextlid = 0;
  187. struct srb_ctx *els;
  188. /* Multiple SG's are not supported for ELS requests */
  189. if (bsg_job->request_payload.sg_cnt > 1 ||
  190. bsg_job->reply_payload.sg_cnt > 1) {
  191. DEBUG2(printk(KERN_INFO
  192. "multiple SG's are not supported for ELS requests"
  193. " [request_sg_cnt: %x reply_sg_cnt: %x]\n",
  194. bsg_job->request_payload.sg_cnt,
  195. bsg_job->reply_payload.sg_cnt));
  196. rval = -EPERM;
  197. goto done;
  198. }
  199. /* ELS request for rport */
  200. if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) {
  201. rport = bsg_job->rport;
  202. fcport = *(fc_port_t **) rport->dd_data;
  203. host = rport_to_shost(rport);
  204. vha = shost_priv(host);
  205. ha = vha->hw;
  206. type = "FC_BSG_RPT_ELS";
  207. /* make sure the rport is logged in,
  208. * if not perform fabric login
  209. */
  210. if (qla2x00_fabric_login(vha, fcport, &nextlid)) {
  211. DEBUG2(qla_printk(KERN_WARNING, ha,
  212. "failed to login port %06X for ELS passthru\n",
  213. fcport->d_id.b24));
  214. rval = -EIO;
  215. goto done;
  216. }
  217. } else {
  218. host = bsg_job->shost;
  219. vha = shost_priv(host);
  220. ha = vha->hw;
  221. type = "FC_BSG_HST_ELS_NOLOGIN";
  222. /* Allocate a dummy fcport structure, since functions
  223. * preparing the IOCB and mailbox command retrieves port
  224. * specific information from fcport structure. For Host based
  225. * ELS commands there will be no fcport structure allocated
  226. */
  227. fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  228. if (!fcport) {
  229. rval = -ENOMEM;
  230. goto done;
  231. }
  232. /* Initialize all required fields of fcport */
  233. fcport->vha = vha;
  234. fcport->vp_idx = vha->vp_idx;
  235. fcport->d_id.b.al_pa =
  236. bsg_job->request->rqst_data.h_els.port_id[0];
  237. fcport->d_id.b.area =
  238. bsg_job->request->rqst_data.h_els.port_id[1];
  239. fcport->d_id.b.domain =
  240. bsg_job->request->rqst_data.h_els.port_id[2];
  241. fcport->loop_id =
  242. (fcport->d_id.b.al_pa == 0xFD) ?
  243. NPH_FABRIC_CONTROLLER : NPH_F_PORT;
  244. }
  245. if (!vha->flags.online) {
  246. DEBUG2(qla_printk(KERN_WARNING, ha,
  247. "host not online\n"));
  248. rval = -EIO;
  249. goto done;
  250. }
  251. req_sg_cnt =
  252. dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  253. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  254. if (!req_sg_cnt) {
  255. rval = -ENOMEM;
  256. goto done_free_fcport;
  257. }
  258. rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  259. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  260. if (!rsp_sg_cnt) {
  261. rval = -ENOMEM;
  262. goto done_free_fcport;
  263. }
  264. if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
  265. (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
  266. DEBUG2(printk(KERN_INFO
  267. "dma mapping resulted in different sg counts \
  268. [request_sg_cnt: %x dma_request_sg_cnt: %x\
  269. reply_sg_cnt: %x dma_reply_sg_cnt: %x]\n",
  270. bsg_job->request_payload.sg_cnt, req_sg_cnt,
  271. bsg_job->reply_payload.sg_cnt, rsp_sg_cnt));
  272. rval = -EAGAIN;
  273. goto done_unmap_sg;
  274. }
  275. /* Alloc SRB structure */
  276. sp = qla2x00_get_ctx_bsg_sp(vha, fcport, sizeof(struct srb_ctx));
  277. if (!sp) {
  278. rval = -ENOMEM;
  279. goto done_unmap_sg;
  280. }
  281. els = sp->ctx;
  282. els->type =
  283. (bsg_job->request->msgcode == FC_BSG_RPT_ELS ?
  284. SRB_ELS_CMD_RPT : SRB_ELS_CMD_HST);
  285. els->name =
  286. (bsg_job->request->msgcode == FC_BSG_RPT_ELS ?
  287. "bsg_els_rpt" : "bsg_els_hst");
  288. els->u.bsg_job = bsg_job;
  289. DEBUG2(qla_printk(KERN_INFO, ha,
  290. "scsi(%ld:%x): bsg rqst type: %s els type: %x - loop-id=%x "
  291. "portid=%02x%02x%02x.\n", vha->host_no, sp->handle, type,
  292. bsg_job->request->rqst_data.h_els.command_code,
  293. fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
  294. fcport->d_id.b.al_pa));
  295. rval = qla2x00_start_sp(sp);
  296. if (rval != QLA_SUCCESS) {
  297. kfree(sp->ctx);
  298. mempool_free(sp, ha->srb_mempool);
  299. rval = -EIO;
  300. goto done_unmap_sg;
  301. }
  302. return rval;
  303. done_unmap_sg:
  304. dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  305. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  306. dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  307. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  308. goto done_free_fcport;
  309. done_free_fcport:
  310. if (bsg_job->request->msgcode == FC_BSG_HST_ELS_NOLOGIN)
  311. kfree(fcport);
  312. done:
  313. return rval;
  314. }
  315. static int
  316. qla2x00_process_ct(struct fc_bsg_job *bsg_job)
  317. {
  318. srb_t *sp;
  319. struct Scsi_Host *host = bsg_job->shost;
  320. scsi_qla_host_t *vha = shost_priv(host);
  321. struct qla_hw_data *ha = vha->hw;
  322. int rval = (DRIVER_ERROR << 16);
  323. int req_sg_cnt, rsp_sg_cnt;
  324. uint16_t loop_id;
  325. struct fc_port *fcport;
  326. char *type = "FC_BSG_HST_CT";
  327. struct srb_ctx *ct;
  328. /* pass through is supported only for ISP 4Gb or higher */
  329. if (!IS_FWI2_CAPABLE(ha)) {
  330. DEBUG2(qla_printk(KERN_INFO, ha,
  331. "scsi(%ld):Firmware is not capable to support FC "
  332. "CT pass thru\n", vha->host_no));
  333. rval = -EPERM;
  334. goto done;
  335. }
  336. req_sg_cnt =
  337. dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  338. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  339. if (!req_sg_cnt) {
  340. rval = -ENOMEM;
  341. goto done;
  342. }
  343. rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  344. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  345. if (!rsp_sg_cnt) {
  346. rval = -ENOMEM;
  347. goto done;
  348. }
  349. if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
  350. (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
  351. DEBUG2(qla_printk(KERN_WARNING, ha,
  352. "[request_sg_cnt: %x dma_request_sg_cnt: %x\
  353. reply_sg_cnt: %x dma_reply_sg_cnt: %x]\n",
  354. bsg_job->request_payload.sg_cnt, req_sg_cnt,
  355. bsg_job->reply_payload.sg_cnt, rsp_sg_cnt));
  356. rval = -EAGAIN;
  357. goto done_unmap_sg;
  358. }
  359. if (!vha->flags.online) {
  360. DEBUG2(qla_printk(KERN_WARNING, ha,
  361. "host not online\n"));
  362. rval = -EIO;
  363. goto done_unmap_sg;
  364. }
  365. loop_id =
  366. (bsg_job->request->rqst_data.h_ct.preamble_word1 & 0xFF000000)
  367. >> 24;
  368. switch (loop_id) {
  369. case 0xFC:
  370. loop_id = cpu_to_le16(NPH_SNS);
  371. break;
  372. case 0xFA:
  373. loop_id = vha->mgmt_svr_loop_id;
  374. break;
  375. default:
  376. DEBUG2(qla_printk(KERN_INFO, ha,
  377. "Unknown loop id: %x\n", loop_id));
  378. rval = -EINVAL;
  379. goto done_unmap_sg;
  380. }
  381. /* Allocate a dummy fcport structure, since functions preparing the
  382. * IOCB and mailbox command retrieves port specific information
  383. * from fcport structure. For Host based ELS commands there will be
  384. * no fcport structure allocated
  385. */
  386. fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  387. if (!fcport) {
  388. rval = -ENOMEM;
  389. goto done_unmap_sg;
  390. }
  391. /* Initialize all required fields of fcport */
  392. fcport->vha = vha;
  393. fcport->vp_idx = vha->vp_idx;
  394. fcport->d_id.b.al_pa = bsg_job->request->rqst_data.h_ct.port_id[0];
  395. fcport->d_id.b.area = bsg_job->request->rqst_data.h_ct.port_id[1];
  396. fcport->d_id.b.domain = bsg_job->request->rqst_data.h_ct.port_id[2];
  397. fcport->loop_id = loop_id;
  398. /* Alloc SRB structure */
  399. sp = qla2x00_get_ctx_bsg_sp(vha, fcport, sizeof(struct srb_ctx));
  400. if (!sp) {
  401. rval = -ENOMEM;
  402. goto done_free_fcport;
  403. }
  404. ct = sp->ctx;
  405. ct->type = SRB_CT_CMD;
  406. ct->name = "bsg_ct";
  407. ct->u.bsg_job = bsg_job;
  408. DEBUG2(qla_printk(KERN_INFO, ha,
  409. "scsi(%ld:%x): bsg rqst type: %s els type: %x - loop-id=%x "
  410. "portid=%02x%02x%02x.\n", vha->host_no, sp->handle, type,
  411. (bsg_job->request->rqst_data.h_ct.preamble_word2 >> 16),
  412. fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
  413. fcport->d_id.b.al_pa));
  414. rval = qla2x00_start_sp(sp);
  415. if (rval != QLA_SUCCESS) {
  416. kfree(sp->ctx);
  417. mempool_free(sp, ha->srb_mempool);
  418. rval = -EIO;
  419. goto done_free_fcport;
  420. }
  421. return rval;
  422. done_free_fcport:
  423. kfree(fcport);
  424. done_unmap_sg:
  425. dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  426. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  427. dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  428. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  429. done:
  430. return rval;
  431. }
  432. /* Set the port configuration to enable the
  433. * internal loopback on ISP81XX
  434. */
  435. static inline int
  436. qla81xx_set_internal_loopback(scsi_qla_host_t *vha, uint16_t *config,
  437. uint16_t *new_config)
  438. {
  439. int ret = 0;
  440. int rval = 0;
  441. struct qla_hw_data *ha = vha->hw;
  442. if (!IS_QLA81XX(ha))
  443. goto done_set_internal;
  444. new_config[0] = config[0] | (ENABLE_INTERNAL_LOOPBACK << 1);
  445. memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3) ;
  446. ha->notify_dcbx_comp = 1;
  447. ret = qla81xx_set_port_config(vha, new_config);
  448. if (ret != QLA_SUCCESS) {
  449. DEBUG2(printk(KERN_ERR
  450. "%s(%lu): Set port config failed\n",
  451. __func__, vha->host_no));
  452. ha->notify_dcbx_comp = 0;
  453. rval = -EINVAL;
  454. goto done_set_internal;
  455. }
  456. /* Wait for DCBX complete event */
  457. if (!wait_for_completion_timeout(&ha->dcbx_comp, (20 * HZ))) {
  458. DEBUG2(qla_printk(KERN_WARNING, ha,
  459. "State change notificaition not received.\n"));
  460. } else
  461. DEBUG2(qla_printk(KERN_INFO, ha,
  462. "State change RECEIVED\n"));
  463. ha->notify_dcbx_comp = 0;
  464. done_set_internal:
  465. return rval;
  466. }
  467. /* Set the port configuration to disable the
  468. * internal loopback on ISP81XX
  469. */
  470. static inline int
  471. qla81xx_reset_internal_loopback(scsi_qla_host_t *vha, uint16_t *config,
  472. int wait)
  473. {
  474. int ret = 0;
  475. int rval = 0;
  476. uint16_t new_config[4];
  477. struct qla_hw_data *ha = vha->hw;
  478. if (!IS_QLA81XX(ha))
  479. goto done_reset_internal;
  480. memset(new_config, 0 , sizeof(new_config));
  481. if ((config[0] & INTERNAL_LOOPBACK_MASK) >> 1 ==
  482. ENABLE_INTERNAL_LOOPBACK) {
  483. new_config[0] = config[0] & ~INTERNAL_LOOPBACK_MASK;
  484. memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3) ;
  485. ha->notify_dcbx_comp = wait;
  486. ret = qla81xx_set_port_config(vha, new_config);
  487. if (ret != QLA_SUCCESS) {
  488. DEBUG2(printk(KERN_ERR
  489. "%s(%lu): Set port config failed\n",
  490. __func__, vha->host_no));
  491. ha->notify_dcbx_comp = 0;
  492. rval = -EINVAL;
  493. goto done_reset_internal;
  494. }
  495. /* Wait for DCBX complete event */
  496. if (wait && !wait_for_completion_timeout(&ha->dcbx_comp,
  497. (20 * HZ))) {
  498. DEBUG2(qla_printk(KERN_WARNING, ha,
  499. "State change notificaition not received.\n"));
  500. ha->notify_dcbx_comp = 0;
  501. rval = -EINVAL;
  502. goto done_reset_internal;
  503. } else
  504. DEBUG2(qla_printk(KERN_INFO, ha,
  505. "State change RECEIVED\n"));
  506. ha->notify_dcbx_comp = 0;
  507. }
  508. done_reset_internal:
  509. return rval;
  510. }
  511. static int
  512. qla2x00_process_loopback(struct fc_bsg_job *bsg_job)
  513. {
  514. struct Scsi_Host *host = bsg_job->shost;
  515. scsi_qla_host_t *vha = shost_priv(host);
  516. struct qla_hw_data *ha = vha->hw;
  517. int rval;
  518. uint8_t command_sent;
  519. char *type;
  520. struct msg_echo_lb elreq;
  521. uint16_t response[MAILBOX_REGISTER_COUNT];
  522. uint16_t config[4], new_config[4];
  523. uint8_t *fw_sts_ptr;
  524. uint8_t *req_data = NULL;
  525. dma_addr_t req_data_dma;
  526. uint32_t req_data_len;
  527. uint8_t *rsp_data = NULL;
  528. dma_addr_t rsp_data_dma;
  529. uint32_t rsp_data_len;
  530. if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
  531. test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  532. test_bit(ISP_ABORT_RETRY, &vha->dpc_flags))
  533. return -EBUSY;
  534. if (!vha->flags.online) {
  535. DEBUG2(qla_printk(KERN_WARNING, ha, "host not online\n"));
  536. return -EIO;
  537. }
  538. elreq.req_sg_cnt = dma_map_sg(&ha->pdev->dev,
  539. bsg_job->request_payload.sg_list, bsg_job->request_payload.sg_cnt,
  540. DMA_TO_DEVICE);
  541. if (!elreq.req_sg_cnt)
  542. return -ENOMEM;
  543. elreq.rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
  544. bsg_job->reply_payload.sg_list, bsg_job->reply_payload.sg_cnt,
  545. DMA_FROM_DEVICE);
  546. if (!elreq.rsp_sg_cnt) {
  547. rval = -ENOMEM;
  548. goto done_unmap_req_sg;
  549. }
  550. if ((elreq.req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
  551. (elreq.rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
  552. DEBUG2(printk(KERN_INFO
  553. "dma mapping resulted in different sg counts "
  554. "[request_sg_cnt: %x dma_request_sg_cnt: %x "
  555. "reply_sg_cnt: %x dma_reply_sg_cnt: %x]\n",
  556. bsg_job->request_payload.sg_cnt, elreq.req_sg_cnt,
  557. bsg_job->reply_payload.sg_cnt, elreq.rsp_sg_cnt));
  558. rval = -EAGAIN;
  559. goto done_unmap_sg;
  560. }
  561. req_data_len = rsp_data_len = bsg_job->request_payload.payload_len;
  562. req_data = dma_alloc_coherent(&ha->pdev->dev, req_data_len,
  563. &req_data_dma, GFP_KERNEL);
  564. if (!req_data) {
  565. DEBUG2(printk(KERN_ERR "%s: dma alloc for req_data "
  566. "failed for host=%lu\n", __func__, vha->host_no));
  567. rval = -ENOMEM;
  568. goto done_unmap_sg;
  569. }
  570. rsp_data = dma_alloc_coherent(&ha->pdev->dev, rsp_data_len,
  571. &rsp_data_dma, GFP_KERNEL);
  572. if (!rsp_data) {
  573. DEBUG2(printk(KERN_ERR "%s: dma alloc for rsp_data "
  574. "failed for host=%lu\n", __func__, vha->host_no));
  575. rval = -ENOMEM;
  576. goto done_free_dma_req;
  577. }
  578. /* Copy the request buffer in req_data now */
  579. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  580. bsg_job->request_payload.sg_cnt, req_data, req_data_len);
  581. elreq.send_dma = req_data_dma;
  582. elreq.rcv_dma = rsp_data_dma;
  583. elreq.transfer_size = req_data_len;
  584. elreq.options = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
  585. if ((ha->current_topology == ISP_CFG_F ||
  586. (IS_QLA81XX(ha) &&
  587. le32_to_cpu(*(uint32_t *)req_data) == ELS_OPCODE_BYTE
  588. && req_data_len == MAX_ELS_FRAME_PAYLOAD)) &&
  589. elreq.options == EXTERNAL_LOOPBACK) {
  590. type = "FC_BSG_HST_VENDOR_ECHO_DIAG";
  591. DEBUG2(qla_printk(KERN_INFO, ha,
  592. "scsi(%ld) bsg rqst type: %s\n", vha->host_no, type));
  593. command_sent = INT_DEF_LB_ECHO_CMD;
  594. rval = qla2x00_echo_test(vha, &elreq, response);
  595. } else {
  596. if (IS_QLA81XX(ha)) {
  597. memset(config, 0, sizeof(config));
  598. memset(new_config, 0, sizeof(new_config));
  599. if (qla81xx_get_port_config(vha, config)) {
  600. DEBUG2(printk(KERN_ERR
  601. "%s(%lu): Get port config failed\n",
  602. __func__, vha->host_no));
  603. bsg_job->reply->reply_payload_rcv_len = 0;
  604. bsg_job->reply->result = (DID_ERROR << 16);
  605. rval = -EPERM;
  606. goto done_free_dma_req;
  607. }
  608. if (elreq.options != EXTERNAL_LOOPBACK) {
  609. DEBUG2(qla_printk(KERN_INFO, ha,
  610. "Internal: current port config = %x\n",
  611. config[0]));
  612. if (qla81xx_set_internal_loopback(vha, config,
  613. new_config)) {
  614. bsg_job->reply->reply_payload_rcv_len =
  615. 0;
  616. bsg_job->reply->result =
  617. (DID_ERROR << 16);
  618. rval = -EPERM;
  619. goto done_free_dma_req;
  620. }
  621. } else {
  622. /* For external loopback to work
  623. * ensure internal loopback is disabled
  624. */
  625. if (qla81xx_reset_internal_loopback(vha,
  626. config, 1)) {
  627. bsg_job->reply->reply_payload_rcv_len =
  628. 0;
  629. bsg_job->reply->result =
  630. (DID_ERROR << 16);
  631. rval = -EPERM;
  632. goto done_free_dma_req;
  633. }
  634. }
  635. type = "FC_BSG_HST_VENDOR_LOOPBACK";
  636. DEBUG2(qla_printk(KERN_INFO, ha,
  637. "scsi(%ld) bsg rqst type: %s\n",
  638. vha->host_no, type));
  639. command_sent = INT_DEF_LB_LOOPBACK_CMD;
  640. rval = qla2x00_loopback_test(vha, &elreq, response);
  641. if (new_config[1]) {
  642. /* Revert back to original port config
  643. * Also clear internal loopback
  644. */
  645. qla81xx_reset_internal_loopback(vha,
  646. new_config, 0);
  647. }
  648. if (response[0] == MBS_COMMAND_ERROR &&
  649. response[1] == MBS_LB_RESET) {
  650. DEBUG2(printk(KERN_ERR "%s(%ld): ABORTing "
  651. "ISP\n", __func__, vha->host_no));
  652. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  653. qla2xxx_wake_dpc(vha);
  654. qla2x00_wait_for_chip_reset(vha);
  655. /* Also reset the MPI */
  656. if (qla81xx_restart_mpi_firmware(vha) !=
  657. QLA_SUCCESS) {
  658. qla_printk(KERN_INFO, ha,
  659. "MPI reset failed for host%ld.\n",
  660. vha->host_no);
  661. }
  662. bsg_job->reply->reply_payload_rcv_len = 0;
  663. bsg_job->reply->result = (DID_ERROR << 16);
  664. rval = -EIO;
  665. goto done_free_dma_req;
  666. }
  667. } else {
  668. type = "FC_BSG_HST_VENDOR_LOOPBACK";
  669. DEBUG2(qla_printk(KERN_INFO, ha,
  670. "scsi(%ld) bsg rqst type: %s\n",
  671. vha->host_no, type));
  672. command_sent = INT_DEF_LB_LOOPBACK_CMD;
  673. rval = qla2x00_loopback_test(vha, &elreq, response);
  674. }
  675. }
  676. if (rval) {
  677. DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld) Vendor "
  678. "request %s failed\n", vha->host_no, type));
  679. fw_sts_ptr = ((uint8_t *)bsg_job->req->sense) +
  680. sizeof(struct fc_bsg_reply);
  681. memcpy(fw_sts_ptr, response, sizeof(response));
  682. fw_sts_ptr += sizeof(response);
  683. *fw_sts_ptr = command_sent;
  684. rval = 0;
  685. bsg_job->reply->reply_payload_rcv_len = 0;
  686. bsg_job->reply->result = (DID_ERROR << 16);
  687. } else {
  688. DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld) Vendor "
  689. "request %s completed\n", vha->host_no, type));
  690. bsg_job->reply_len = sizeof(struct fc_bsg_reply) +
  691. sizeof(response) + sizeof(uint8_t);
  692. bsg_job->reply->reply_payload_rcv_len =
  693. bsg_job->reply_payload.payload_len;
  694. fw_sts_ptr = ((uint8_t *)bsg_job->req->sense) +
  695. sizeof(struct fc_bsg_reply);
  696. memcpy(fw_sts_ptr, response, sizeof(response));
  697. fw_sts_ptr += sizeof(response);
  698. *fw_sts_ptr = command_sent;
  699. bsg_job->reply->result = DID_OK;
  700. sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
  701. bsg_job->reply_payload.sg_cnt, rsp_data,
  702. rsp_data_len);
  703. }
  704. bsg_job->job_done(bsg_job);
  705. dma_free_coherent(&ha->pdev->dev, rsp_data_len,
  706. rsp_data, rsp_data_dma);
  707. done_free_dma_req:
  708. dma_free_coherent(&ha->pdev->dev, req_data_len,
  709. req_data, req_data_dma);
  710. done_unmap_sg:
  711. dma_unmap_sg(&ha->pdev->dev,
  712. bsg_job->reply_payload.sg_list,
  713. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  714. done_unmap_req_sg:
  715. dma_unmap_sg(&ha->pdev->dev,
  716. bsg_job->request_payload.sg_list,
  717. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  718. return rval;
  719. }
  720. static int
  721. qla84xx_reset(struct fc_bsg_job *bsg_job)
  722. {
  723. struct Scsi_Host *host = bsg_job->shost;
  724. scsi_qla_host_t *vha = shost_priv(host);
  725. struct qla_hw_data *ha = vha->hw;
  726. int rval = 0;
  727. uint32_t flag;
  728. if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
  729. test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  730. test_bit(ISP_ABORT_RETRY, &vha->dpc_flags))
  731. return -EBUSY;
  732. if (!IS_QLA84XX(ha)) {
  733. DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld): Not 84xx, "
  734. "exiting.\n", vha->host_no));
  735. return -EINVAL;
  736. }
  737. flag = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
  738. rval = qla84xx_reset_chip(vha, flag == A84_ISSUE_RESET_DIAG_FW);
  739. if (rval) {
  740. DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld) Vendor "
  741. "request 84xx reset failed\n", vha->host_no));
  742. rval = bsg_job->reply->reply_payload_rcv_len = 0;
  743. bsg_job->reply->result = (DID_ERROR << 16);
  744. } else {
  745. DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld) Vendor "
  746. "request 84xx reset completed\n", vha->host_no));
  747. bsg_job->reply->result = DID_OK;
  748. }
  749. bsg_job->job_done(bsg_job);
  750. return rval;
  751. }
  752. static int
  753. qla84xx_updatefw(struct fc_bsg_job *bsg_job)
  754. {
  755. struct Scsi_Host *host = bsg_job->shost;
  756. scsi_qla_host_t *vha = shost_priv(host);
  757. struct qla_hw_data *ha = vha->hw;
  758. struct verify_chip_entry_84xx *mn = NULL;
  759. dma_addr_t mn_dma, fw_dma;
  760. void *fw_buf = NULL;
  761. int rval = 0;
  762. uint32_t sg_cnt;
  763. uint32_t data_len;
  764. uint16_t options;
  765. uint32_t flag;
  766. uint32_t fw_ver;
  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. return -EBUSY;
  771. if (!IS_QLA84XX(ha)) {
  772. DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld): Not 84xx, "
  773. "exiting.\n", vha->host_no));
  774. return -EINVAL;
  775. }
  776. sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  777. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  778. if (!sg_cnt)
  779. return -ENOMEM;
  780. if (sg_cnt != bsg_job->request_payload.sg_cnt) {
  781. DEBUG2(printk(KERN_INFO
  782. "dma mapping resulted in different sg counts "
  783. "request_sg_cnt: %x dma_request_sg_cnt: %x ",
  784. bsg_job->request_payload.sg_cnt, sg_cnt));
  785. rval = -EAGAIN;
  786. goto done_unmap_sg;
  787. }
  788. data_len = bsg_job->request_payload.payload_len;
  789. fw_buf = dma_alloc_coherent(&ha->pdev->dev, data_len,
  790. &fw_dma, GFP_KERNEL);
  791. if (!fw_buf) {
  792. DEBUG2(printk(KERN_ERR "%s: dma alloc for fw_buf "
  793. "failed for host=%lu\n", __func__, vha->host_no));
  794. rval = -ENOMEM;
  795. goto done_unmap_sg;
  796. }
  797. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  798. bsg_job->request_payload.sg_cnt, fw_buf, data_len);
  799. mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
  800. if (!mn) {
  801. DEBUG2(printk(KERN_ERR "%s: dma alloc for fw buffer "
  802. "failed for host=%lu\n", __func__, vha->host_no));
  803. rval = -ENOMEM;
  804. goto done_free_fw_buf;
  805. }
  806. flag = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
  807. fw_ver = le32_to_cpu(*((uint32_t *)((uint32_t *)fw_buf + 2)));
  808. memset(mn, 0, sizeof(struct access_chip_84xx));
  809. mn->entry_type = VERIFY_CHIP_IOCB_TYPE;
  810. mn->entry_count = 1;
  811. options = VCO_FORCE_UPDATE | VCO_END_OF_DATA;
  812. if (flag == A84_ISSUE_UPDATE_DIAGFW_CMD)
  813. options |= VCO_DIAG_FW;
  814. mn->options = cpu_to_le16(options);
  815. mn->fw_ver = cpu_to_le32(fw_ver);
  816. mn->fw_size = cpu_to_le32(data_len);
  817. mn->fw_seq_size = cpu_to_le32(data_len);
  818. mn->dseg_address[0] = cpu_to_le32(LSD(fw_dma));
  819. mn->dseg_address[1] = cpu_to_le32(MSD(fw_dma));
  820. mn->dseg_length = cpu_to_le32(data_len);
  821. mn->data_seg_cnt = cpu_to_le16(1);
  822. rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
  823. if (rval) {
  824. DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld) Vendor "
  825. "request 84xx updatefw failed\n", vha->host_no));
  826. rval = bsg_job->reply->reply_payload_rcv_len = 0;
  827. bsg_job->reply->result = (DID_ERROR << 16);
  828. } else {
  829. DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld) Vendor "
  830. "request 84xx updatefw completed\n", vha->host_no));
  831. bsg_job->reply_len = sizeof(struct fc_bsg_reply);
  832. bsg_job->reply->result = DID_OK;
  833. }
  834. bsg_job->job_done(bsg_job);
  835. dma_pool_free(ha->s_dma_pool, mn, mn_dma);
  836. done_free_fw_buf:
  837. dma_free_coherent(&ha->pdev->dev, data_len, fw_buf, fw_dma);
  838. done_unmap_sg:
  839. dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  840. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  841. return rval;
  842. }
  843. static int
  844. qla84xx_mgmt_cmd(struct fc_bsg_job *bsg_job)
  845. {
  846. struct Scsi_Host *host = bsg_job->shost;
  847. scsi_qla_host_t *vha = shost_priv(host);
  848. struct qla_hw_data *ha = vha->hw;
  849. struct access_chip_84xx *mn = NULL;
  850. dma_addr_t mn_dma, mgmt_dma;
  851. void *mgmt_b = NULL;
  852. int rval = 0;
  853. struct qla_bsg_a84_mgmt *ql84_mgmt;
  854. uint32_t sg_cnt;
  855. uint32_t data_len = 0;
  856. uint32_t dma_direction = DMA_NONE;
  857. if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
  858. test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  859. test_bit(ISP_ABORT_RETRY, &vha->dpc_flags))
  860. return -EBUSY;
  861. if (!IS_QLA84XX(ha)) {
  862. DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld): Not 84xx, "
  863. "exiting.\n", vha->host_no));
  864. return -EINVAL;
  865. }
  866. ql84_mgmt = (struct qla_bsg_a84_mgmt *)((char *)bsg_job->request +
  867. sizeof(struct fc_bsg_request));
  868. if (!ql84_mgmt) {
  869. DEBUG2(printk("%s(%ld): mgmt header not provided, exiting.\n",
  870. __func__, vha->host_no));
  871. return -EINVAL;
  872. }
  873. mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
  874. if (!mn) {
  875. DEBUG2(printk(KERN_ERR "%s: dma alloc for fw buffer "
  876. "failed for host=%lu\n", __func__, vha->host_no));
  877. return -ENOMEM;
  878. }
  879. memset(mn, 0, sizeof(struct access_chip_84xx));
  880. mn->entry_type = ACCESS_CHIP_IOCB_TYPE;
  881. mn->entry_count = 1;
  882. switch (ql84_mgmt->mgmt.cmd) {
  883. case QLA84_MGMT_READ_MEM:
  884. case QLA84_MGMT_GET_INFO:
  885. sg_cnt = dma_map_sg(&ha->pdev->dev,
  886. bsg_job->reply_payload.sg_list,
  887. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  888. if (!sg_cnt) {
  889. rval = -ENOMEM;
  890. goto exit_mgmt;
  891. }
  892. dma_direction = DMA_FROM_DEVICE;
  893. if (sg_cnt != bsg_job->reply_payload.sg_cnt) {
  894. DEBUG2(printk(KERN_INFO
  895. "dma mapping resulted in different sg counts "
  896. "reply_sg_cnt: %x dma_reply_sg_cnt: %x\n",
  897. bsg_job->reply_payload.sg_cnt, sg_cnt));
  898. rval = -EAGAIN;
  899. goto done_unmap_sg;
  900. }
  901. data_len = bsg_job->reply_payload.payload_len;
  902. mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len,
  903. &mgmt_dma, GFP_KERNEL);
  904. if (!mgmt_b) {
  905. DEBUG2(printk(KERN_ERR "%s: dma alloc for mgmt_b "
  906. "failed for host=%lu\n",
  907. __func__, vha->host_no));
  908. rval = -ENOMEM;
  909. goto done_unmap_sg;
  910. }
  911. if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) {
  912. mn->options = cpu_to_le16(ACO_DUMP_MEMORY);
  913. mn->parameter1 =
  914. cpu_to_le32(
  915. ql84_mgmt->mgmt.mgmtp.u.mem.start_addr);
  916. } else if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO) {
  917. mn->options = cpu_to_le16(ACO_REQUEST_INFO);
  918. mn->parameter1 =
  919. cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.info.type);
  920. mn->parameter2 =
  921. cpu_to_le32(
  922. ql84_mgmt->mgmt.mgmtp.u.info.context);
  923. }
  924. break;
  925. case QLA84_MGMT_WRITE_MEM:
  926. sg_cnt = dma_map_sg(&ha->pdev->dev,
  927. bsg_job->request_payload.sg_list,
  928. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  929. if (!sg_cnt) {
  930. rval = -ENOMEM;
  931. goto exit_mgmt;
  932. }
  933. dma_direction = DMA_TO_DEVICE;
  934. if (sg_cnt != bsg_job->request_payload.sg_cnt) {
  935. DEBUG2(printk(KERN_INFO
  936. "dma mapping resulted in different sg counts "
  937. "request_sg_cnt: %x dma_request_sg_cnt: %x ",
  938. bsg_job->request_payload.sg_cnt, sg_cnt));
  939. rval = -EAGAIN;
  940. goto done_unmap_sg;
  941. }
  942. data_len = bsg_job->request_payload.payload_len;
  943. mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len,
  944. &mgmt_dma, GFP_KERNEL);
  945. if (!mgmt_b) {
  946. DEBUG2(printk(KERN_ERR "%s: dma alloc for mgmt_b "
  947. "failed for host=%lu\n",
  948. __func__, vha->host_no));
  949. rval = -ENOMEM;
  950. goto done_unmap_sg;
  951. }
  952. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  953. bsg_job->request_payload.sg_cnt, mgmt_b, data_len);
  954. mn->options = cpu_to_le16(ACO_LOAD_MEMORY);
  955. mn->parameter1 =
  956. cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.mem.start_addr);
  957. break;
  958. case QLA84_MGMT_CHNG_CONFIG:
  959. mn->options = cpu_to_le16(ACO_CHANGE_CONFIG_PARAM);
  960. mn->parameter1 =
  961. cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.id);
  962. mn->parameter2 =
  963. cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param0);
  964. mn->parameter3 =
  965. cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param1);
  966. break;
  967. default:
  968. rval = -EIO;
  969. goto exit_mgmt;
  970. }
  971. if (ql84_mgmt->mgmt.cmd != QLA84_MGMT_CHNG_CONFIG) {
  972. mn->total_byte_cnt = cpu_to_le32(ql84_mgmt->mgmt.len);
  973. mn->dseg_count = cpu_to_le16(1);
  974. mn->dseg_address[0] = cpu_to_le32(LSD(mgmt_dma));
  975. mn->dseg_address[1] = cpu_to_le32(MSD(mgmt_dma));
  976. mn->dseg_length = cpu_to_le32(ql84_mgmt->mgmt.len);
  977. }
  978. rval = qla2x00_issue_iocb(vha, mn, mn_dma, 0);
  979. if (rval) {
  980. DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld) Vendor "
  981. "request 84xx mgmt failed\n", vha->host_no));
  982. rval = bsg_job->reply->reply_payload_rcv_len = 0;
  983. bsg_job->reply->result = (DID_ERROR << 16);
  984. } else {
  985. DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld) Vendor "
  986. "request 84xx mgmt completed\n", vha->host_no));
  987. bsg_job->reply_len = sizeof(struct fc_bsg_reply);
  988. bsg_job->reply->result = DID_OK;
  989. if ((ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) ||
  990. (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO)) {
  991. bsg_job->reply->reply_payload_rcv_len =
  992. bsg_job->reply_payload.payload_len;
  993. sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
  994. bsg_job->reply_payload.sg_cnt, mgmt_b,
  995. data_len);
  996. }
  997. }
  998. bsg_job->job_done(bsg_job);
  999. done_unmap_sg:
  1000. if (mgmt_b)
  1001. dma_free_coherent(&ha->pdev->dev, data_len, mgmt_b, mgmt_dma);
  1002. if (dma_direction == DMA_TO_DEVICE)
  1003. dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  1004. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1005. else if (dma_direction == DMA_FROM_DEVICE)
  1006. dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  1007. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1008. exit_mgmt:
  1009. dma_pool_free(ha->s_dma_pool, mn, mn_dma);
  1010. return rval;
  1011. }
  1012. static int
  1013. qla24xx_iidma(struct fc_bsg_job *bsg_job)
  1014. {
  1015. struct Scsi_Host *host = bsg_job->shost;
  1016. scsi_qla_host_t *vha = shost_priv(host);
  1017. struct qla_hw_data *ha = vha->hw;
  1018. int rval = 0;
  1019. struct qla_port_param *port_param = NULL;
  1020. fc_port_t *fcport = NULL;
  1021. uint16_t mb[MAILBOX_REGISTER_COUNT];
  1022. uint8_t *rsp_ptr = NULL;
  1023. bsg_job->reply->reply_payload_rcv_len = 0;
  1024. if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
  1025. test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  1026. test_bit(ISP_ABORT_RETRY, &vha->dpc_flags))
  1027. return -EBUSY;
  1028. if (!IS_IIDMA_CAPABLE(vha->hw)) {
  1029. DEBUG2(qla_printk(KERN_WARNING, ha, "%s(%lu): iiDMA not "
  1030. "supported\n", __func__, vha->host_no));
  1031. return -EINVAL;
  1032. }
  1033. port_param = (struct qla_port_param *)((char *)bsg_job->request +
  1034. sizeof(struct fc_bsg_request));
  1035. if (!port_param) {
  1036. DEBUG2(printk("%s(%ld): port_param header not provided, "
  1037. "exiting.\n", __func__, vha->host_no));
  1038. return -EINVAL;
  1039. }
  1040. if (port_param->fc_scsi_addr.dest_type != EXT_DEF_TYPE_WWPN) {
  1041. DEBUG2(printk(KERN_ERR "%s(%ld): Invalid destination type\n",
  1042. __func__, vha->host_no));
  1043. return -EINVAL;
  1044. }
  1045. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1046. if (fcport->port_type != FCT_TARGET)
  1047. continue;
  1048. if (memcmp(port_param->fc_scsi_addr.dest_addr.wwpn,
  1049. fcport->port_name, sizeof(fcport->port_name)))
  1050. continue;
  1051. break;
  1052. }
  1053. if (!fcport) {
  1054. DEBUG2(printk(KERN_ERR "%s(%ld): Failed to find port\n",
  1055. __func__, vha->host_no));
  1056. return -EINVAL;
  1057. }
  1058. if (fcport->loop_id == FC_NO_LOOP_ID) {
  1059. DEBUG2(printk(KERN_ERR "%s(%ld): Invalid port loop id, "
  1060. "loop_id = 0x%x\n",
  1061. __func__, vha->host_no, fcport->loop_id));
  1062. return -EINVAL;
  1063. }
  1064. if (port_param->mode)
  1065. rval = qla2x00_set_idma_speed(vha, fcport->loop_id,
  1066. port_param->speed, mb);
  1067. else
  1068. rval = qla2x00_get_idma_speed(vha, fcport->loop_id,
  1069. &port_param->speed, mb);
  1070. if (rval) {
  1071. DEBUG16(printk(KERN_ERR "scsi(%ld): iIDMA cmd failed for "
  1072. "%02x%02x%02x%02x%02x%02x%02x%02x -- "
  1073. "%04x %x %04x %04x.\n",
  1074. vha->host_no, fcport->port_name[0],
  1075. fcport->port_name[1],
  1076. fcport->port_name[2], fcport->port_name[3],
  1077. fcport->port_name[4], fcport->port_name[5],
  1078. fcport->port_name[6], fcport->port_name[7], rval,
  1079. fcport->fp_speed, mb[0], mb[1]));
  1080. rval = 0;
  1081. bsg_job->reply->result = (DID_ERROR << 16);
  1082. } else {
  1083. if (!port_param->mode) {
  1084. bsg_job->reply_len = sizeof(struct fc_bsg_reply) +
  1085. sizeof(struct qla_port_param);
  1086. rsp_ptr = ((uint8_t *)bsg_job->reply) +
  1087. sizeof(struct fc_bsg_reply);
  1088. memcpy(rsp_ptr, port_param,
  1089. sizeof(struct qla_port_param));
  1090. }
  1091. bsg_job->reply->result = DID_OK;
  1092. }
  1093. bsg_job->job_done(bsg_job);
  1094. return rval;
  1095. }
  1096. static int
  1097. qla2x00_process_vendor_specific(struct fc_bsg_job *bsg_job)
  1098. {
  1099. switch (bsg_job->request->rqst_data.h_vendor.vendor_cmd[0]) {
  1100. case QL_VND_LOOPBACK:
  1101. return qla2x00_process_loopback(bsg_job);
  1102. case QL_VND_A84_RESET:
  1103. return qla84xx_reset(bsg_job);
  1104. case QL_VND_A84_UPDATE_FW:
  1105. return qla84xx_updatefw(bsg_job);
  1106. case QL_VND_A84_MGMT_CMD:
  1107. return qla84xx_mgmt_cmd(bsg_job);
  1108. case QL_VND_IIDMA:
  1109. return qla24xx_iidma(bsg_job);
  1110. case QL_VND_FCP_PRIO_CFG_CMD:
  1111. return qla24xx_proc_fcp_prio_cfg_cmd(bsg_job);
  1112. default:
  1113. bsg_job->reply->result = (DID_ERROR << 16);
  1114. bsg_job->job_done(bsg_job);
  1115. return -ENOSYS;
  1116. }
  1117. }
  1118. int
  1119. qla24xx_bsg_request(struct fc_bsg_job *bsg_job)
  1120. {
  1121. int ret = -EINVAL;
  1122. switch (bsg_job->request->msgcode) {
  1123. case FC_BSG_RPT_ELS:
  1124. case FC_BSG_HST_ELS_NOLOGIN:
  1125. ret = qla2x00_process_els(bsg_job);
  1126. break;
  1127. case FC_BSG_HST_CT:
  1128. ret = qla2x00_process_ct(bsg_job);
  1129. break;
  1130. case FC_BSG_HST_VENDOR:
  1131. ret = qla2x00_process_vendor_specific(bsg_job);
  1132. break;
  1133. case FC_BSG_HST_ADD_RPORT:
  1134. case FC_BSG_HST_DEL_RPORT:
  1135. case FC_BSG_RPT_CT:
  1136. default:
  1137. DEBUG2(printk("qla2xxx: unsupported BSG request\n"));
  1138. break;
  1139. }
  1140. return ret;
  1141. }
  1142. int
  1143. qla24xx_bsg_timeout(struct fc_bsg_job *bsg_job)
  1144. {
  1145. scsi_qla_host_t *vha = shost_priv(bsg_job->shost);
  1146. struct qla_hw_data *ha = vha->hw;
  1147. srb_t *sp;
  1148. int cnt, que;
  1149. unsigned long flags;
  1150. struct req_que *req;
  1151. struct srb_ctx *sp_bsg;
  1152. /* find the bsg job from the active list of commands */
  1153. spin_lock_irqsave(&ha->hardware_lock, flags);
  1154. for (que = 0; que < ha->max_req_queues; que++) {
  1155. req = ha->req_q_map[que];
  1156. if (!req)
  1157. continue;
  1158. for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
  1159. sp = req->outstanding_cmds[cnt];
  1160. if (sp) {
  1161. sp_bsg = sp->ctx;
  1162. if (((sp_bsg->type == SRB_CT_CMD) ||
  1163. (sp_bsg->type == SRB_ELS_CMD_HST))
  1164. && (sp_bsg->u.bsg_job == bsg_job)) {
  1165. if (ha->isp_ops->abort_command(sp)) {
  1166. DEBUG2(qla_printk(KERN_INFO, ha,
  1167. "scsi(%ld): mbx "
  1168. "abort_command failed\n",
  1169. vha->host_no));
  1170. bsg_job->req->errors =
  1171. bsg_job->reply->result = -EIO;
  1172. } else {
  1173. DEBUG2(qla_printk(KERN_INFO, ha,
  1174. "scsi(%ld): mbx "
  1175. "abort_command success\n",
  1176. vha->host_no));
  1177. bsg_job->req->errors =
  1178. bsg_job->reply->result = 0;
  1179. }
  1180. goto done;
  1181. }
  1182. }
  1183. }
  1184. }
  1185. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1186. DEBUG2(qla_printk(KERN_INFO, ha,
  1187. "scsi(%ld) SRB not found to abort\n", vha->host_no));
  1188. bsg_job->req->errors = bsg_job->reply->result = -ENXIO;
  1189. return 0;
  1190. done:
  1191. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1192. if (bsg_job->request->msgcode == FC_BSG_HST_CT)
  1193. kfree(sp->fcport);
  1194. kfree(sp->ctx);
  1195. mempool_free(sp, ha->srb_mempool);
  1196. return 0;
  1197. }