qla_bsg.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205
  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_bsg_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_bsg *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. {
  267. DEBUG2(printk(KERN_INFO
  268. "dma mapping resulted in different sg counts \
  269. [request_sg_cnt: %x dma_request_sg_cnt: %x\
  270. reply_sg_cnt: %x dma_reply_sg_cnt: %x]\n",
  271. bsg_job->request_payload.sg_cnt, req_sg_cnt,
  272. bsg_job->reply_payload.sg_cnt, rsp_sg_cnt));
  273. rval = -EAGAIN;
  274. goto done_unmap_sg;
  275. }
  276. /* Alloc SRB structure */
  277. sp = qla2x00_get_ctx_bsg_sp(vha, fcport, sizeof(struct srb_bsg));
  278. if (!sp) {
  279. rval = -ENOMEM;
  280. goto done_unmap_sg;
  281. }
  282. els = sp->ctx;
  283. els->ctx.type =
  284. (bsg_job->request->msgcode == FC_BSG_RPT_ELS ?
  285. SRB_ELS_CMD_RPT : SRB_ELS_CMD_HST);
  286. els->bsg_job = bsg_job;
  287. DEBUG2(qla_printk(KERN_INFO, ha,
  288. "scsi(%ld:%x): bsg rqst type: %s els type: %x - loop-id=%x "
  289. "portid=%02x%02x%02x.\n", vha->host_no, sp->handle, type,
  290. bsg_job->request->rqst_data.h_els.command_code,
  291. fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
  292. fcport->d_id.b.al_pa));
  293. rval = qla2x00_start_sp(sp);
  294. if (rval != QLA_SUCCESS) {
  295. kfree(sp->ctx);
  296. mempool_free(sp, ha->srb_mempool);
  297. rval = -EIO;
  298. goto done_unmap_sg;
  299. }
  300. return rval;
  301. done_unmap_sg:
  302. dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  303. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  304. dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  305. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  306. goto done_free_fcport;
  307. done_free_fcport:
  308. if (bsg_job->request->msgcode == FC_BSG_HST_ELS_NOLOGIN)
  309. kfree(fcport);
  310. done:
  311. return rval;
  312. }
  313. static int
  314. qla2x00_process_ct(struct fc_bsg_job *bsg_job)
  315. {
  316. srb_t *sp;
  317. struct Scsi_Host *host = bsg_job->shost;
  318. scsi_qla_host_t *vha = shost_priv(host);
  319. struct qla_hw_data *ha = vha->hw;
  320. int rval = (DRIVER_ERROR << 16);
  321. int req_sg_cnt, rsp_sg_cnt;
  322. uint16_t loop_id;
  323. struct fc_port *fcport;
  324. char *type = "FC_BSG_HST_CT";
  325. struct srb_bsg *ct;
  326. /* pass through is supported only for ISP 4Gb or higher */
  327. if (!IS_FWI2_CAPABLE(ha)) {
  328. DEBUG2(qla_printk(KERN_INFO, ha,
  329. "scsi(%ld):Firmware is not capable to support FC "
  330. "CT pass thru\n", vha->host_no));
  331. rval = -EPERM;
  332. goto done;
  333. }
  334. req_sg_cnt =
  335. dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  336. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  337. if (!req_sg_cnt) {
  338. rval = -ENOMEM;
  339. goto done;
  340. }
  341. rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  342. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  343. if (!rsp_sg_cnt) {
  344. rval = -ENOMEM;
  345. goto done;
  346. }
  347. if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
  348. (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt))
  349. {
  350. DEBUG2(qla_printk(KERN_WARNING, ha,
  351. "[request_sg_cnt: %x dma_request_sg_cnt: %x\
  352. reply_sg_cnt: %x dma_reply_sg_cnt: %x]\n",
  353. bsg_job->request_payload.sg_cnt, req_sg_cnt,
  354. bsg_job->reply_payload.sg_cnt, rsp_sg_cnt));
  355. rval = -EAGAIN;
  356. goto done_unmap_sg;
  357. }
  358. if (!vha->flags.online) {
  359. DEBUG2(qla_printk(KERN_WARNING, ha,
  360. "host not online\n"));
  361. rval = -EIO;
  362. goto done_unmap_sg;
  363. }
  364. loop_id =
  365. (bsg_job->request->rqst_data.h_ct.preamble_word1 & 0xFF000000)
  366. >> 24;
  367. switch (loop_id) {
  368. case 0xFC:
  369. loop_id = cpu_to_le16(NPH_SNS);
  370. break;
  371. case 0xFA:
  372. loop_id = vha->mgmt_svr_loop_id;
  373. break;
  374. default:
  375. DEBUG2(qla_printk(KERN_INFO, ha,
  376. "Unknown loop id: %x\n", loop_id));
  377. rval = -EINVAL;
  378. goto done_unmap_sg;
  379. }
  380. /* Allocate a dummy fcport structure, since functions preparing the
  381. * IOCB and mailbox command retrieves port specific information
  382. * from fcport structure. For Host based ELS commands there will be
  383. * no fcport structure allocated
  384. */
  385. fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  386. if (!fcport)
  387. {
  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_bsg));
  400. if (!sp) {
  401. rval = -ENOMEM;
  402. goto done_free_fcport;
  403. }
  404. ct = sp->ctx;
  405. ct->ctx.type = SRB_CT_CMD;
  406. ct->bsg_job = bsg_job;
  407. DEBUG2(qla_printk(KERN_INFO, ha,
  408. "scsi(%ld:%x): bsg rqst type: %s els type: %x - loop-id=%x "
  409. "portid=%02x%02x%02x.\n", vha->host_no, sp->handle, type,
  410. (bsg_job->request->rqst_data.h_ct.preamble_word2 >> 16),
  411. fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
  412. fcport->d_id.b.al_pa));
  413. rval = qla2x00_start_sp(sp);
  414. if (rval != QLA_SUCCESS) {
  415. kfree(sp->ctx);
  416. mempool_free(sp, ha->srb_mempool);
  417. rval = -EIO;
  418. goto done_free_fcport;
  419. }
  420. return rval;
  421. done_free_fcport:
  422. kfree(fcport);
  423. done_unmap_sg:
  424. dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  425. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  426. dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  427. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  428. done:
  429. return rval;
  430. }
  431. static int
  432. qla2x00_process_loopback(struct fc_bsg_job *bsg_job)
  433. {
  434. struct Scsi_Host *host = bsg_job->shost;
  435. scsi_qla_host_t *vha = shost_priv(host);
  436. struct qla_hw_data *ha = vha->hw;
  437. int rval;
  438. uint8_t command_sent;
  439. char *type;
  440. struct msg_echo_lb elreq;
  441. uint16_t response[MAILBOX_REGISTER_COUNT];
  442. uint8_t* fw_sts_ptr;
  443. uint8_t *req_data = NULL;
  444. dma_addr_t req_data_dma;
  445. uint32_t req_data_len;
  446. uint8_t *rsp_data = NULL;
  447. dma_addr_t rsp_data_dma;
  448. uint32_t rsp_data_len;
  449. if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
  450. test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  451. test_bit(ISP_ABORT_RETRY, &vha->dpc_flags))
  452. return -EBUSY;
  453. if (!vha->flags.online) {
  454. DEBUG2(qla_printk(KERN_WARNING, ha, "host not online\n"));
  455. return -EIO;
  456. }
  457. elreq.req_sg_cnt = dma_map_sg(&ha->pdev->dev,
  458. bsg_job->request_payload.sg_list, bsg_job->request_payload.sg_cnt,
  459. DMA_TO_DEVICE);
  460. if (!elreq.req_sg_cnt)
  461. return -ENOMEM;
  462. elreq.rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
  463. bsg_job->reply_payload.sg_list, bsg_job->reply_payload.sg_cnt,
  464. DMA_FROM_DEVICE);
  465. if (!elreq.rsp_sg_cnt) {
  466. rval = -ENOMEM;
  467. goto done_unmap_req_sg;
  468. }
  469. if ((elreq.req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
  470. (elreq.rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
  471. DEBUG2(printk(KERN_INFO
  472. "dma mapping resulted in different sg counts "
  473. "[request_sg_cnt: %x dma_request_sg_cnt: %x "
  474. "reply_sg_cnt: %x dma_reply_sg_cnt: %x]\n",
  475. bsg_job->request_payload.sg_cnt, elreq.req_sg_cnt,
  476. bsg_job->reply_payload.sg_cnt, elreq.rsp_sg_cnt));
  477. rval = -EAGAIN;
  478. goto done_unmap_sg;
  479. }
  480. req_data_len = rsp_data_len = bsg_job->request_payload.payload_len;
  481. req_data = dma_alloc_coherent(&ha->pdev->dev, req_data_len,
  482. &req_data_dma, GFP_KERNEL);
  483. if (!req_data) {
  484. DEBUG2(printk(KERN_ERR "%s: dma alloc for req_data "
  485. "failed for host=%lu\n", __func__, vha->host_no));
  486. rval = -ENOMEM;
  487. goto done_unmap_sg;
  488. }
  489. rsp_data = dma_alloc_coherent(&ha->pdev->dev, rsp_data_len,
  490. &rsp_data_dma, GFP_KERNEL);
  491. if (!rsp_data) {
  492. DEBUG2(printk(KERN_ERR "%s: dma alloc for rsp_data "
  493. "failed for host=%lu\n", __func__, vha->host_no));
  494. rval = -ENOMEM;
  495. goto done_free_dma_req;
  496. }
  497. /* Copy the request buffer in req_data now */
  498. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  499. bsg_job->request_payload.sg_cnt, req_data, req_data_len);
  500. elreq.send_dma = req_data_dma;
  501. elreq.rcv_dma = rsp_data_dma;
  502. elreq.transfer_size = req_data_len;
  503. elreq.options = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
  504. if (ha->current_topology != ISP_CFG_F) {
  505. type = "FC_BSG_HST_VENDOR_LOOPBACK";
  506. DEBUG2(qla_printk(KERN_INFO, ha,
  507. "scsi(%ld) bsg rqst type: %s\n",
  508. vha->host_no, type));
  509. command_sent = INT_DEF_LB_LOOPBACK_CMD;
  510. rval = qla2x00_loopback_test(vha, &elreq, response);
  511. if (IS_QLA81XX(ha)) {
  512. if (response[0] == MBS_COMMAND_ERROR &&
  513. response[1] == MBS_LB_RESET) {
  514. DEBUG2(printk(KERN_ERR "%s(%ld): ABORTing "
  515. "ISP\n", __func__, vha->host_no));
  516. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  517. qla2xxx_wake_dpc(vha);
  518. }
  519. }
  520. } else {
  521. type = "FC_BSG_HST_VENDOR_ECHO_DIAG";
  522. DEBUG2(qla_printk(KERN_INFO, ha,
  523. "scsi(%ld) bsg rqst type: %s\n" ,vha->host_no, type));
  524. command_sent = INT_DEF_LB_ECHO_CMD;
  525. rval = qla2x00_echo_test(vha, &elreq, response);
  526. }
  527. if (rval) {
  528. DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld) Vendor "
  529. "request %s failed\n", vha->host_no, type));
  530. fw_sts_ptr = ((uint8_t *)bsg_job->req->sense) +
  531. sizeof(struct fc_bsg_reply);
  532. memcpy(fw_sts_ptr, response, sizeof(response));
  533. fw_sts_ptr += sizeof(response);
  534. *fw_sts_ptr = command_sent;
  535. rval = 0;
  536. bsg_job->reply->reply_payload_rcv_len = 0;
  537. bsg_job->reply->result = (DID_ERROR << 16);
  538. } else {
  539. DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld) Vendor "
  540. "request %s completed\n", vha->host_no, type));
  541. bsg_job->reply_len = sizeof(struct fc_bsg_reply) +
  542. sizeof(response) + sizeof(uint8_t);
  543. bsg_job->reply->reply_payload_rcv_len =
  544. bsg_job->reply_payload.payload_len;
  545. fw_sts_ptr = ((uint8_t *)bsg_job->req->sense) +
  546. sizeof(struct fc_bsg_reply);
  547. memcpy(fw_sts_ptr, response, sizeof(response));
  548. fw_sts_ptr += sizeof(response);
  549. *fw_sts_ptr = command_sent;
  550. bsg_job->reply->result = DID_OK;
  551. sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
  552. bsg_job->reply_payload.sg_cnt, rsp_data,
  553. rsp_data_len);
  554. }
  555. bsg_job->job_done(bsg_job);
  556. dma_free_coherent(&ha->pdev->dev, rsp_data_len,
  557. rsp_data, rsp_data_dma);
  558. done_free_dma_req:
  559. dma_free_coherent(&ha->pdev->dev, req_data_len,
  560. req_data, req_data_dma);
  561. done_unmap_sg:
  562. dma_unmap_sg(&ha->pdev->dev,
  563. bsg_job->reply_payload.sg_list,
  564. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  565. done_unmap_req_sg:
  566. dma_unmap_sg(&ha->pdev->dev,
  567. bsg_job->request_payload.sg_list,
  568. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  569. return rval;
  570. }
  571. static int
  572. qla84xx_reset(struct fc_bsg_job *bsg_job)
  573. {
  574. struct Scsi_Host *host = bsg_job->shost;
  575. scsi_qla_host_t *vha = shost_priv(host);
  576. struct qla_hw_data *ha = vha->hw;
  577. int rval = 0;
  578. uint32_t flag;
  579. if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
  580. test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  581. test_bit(ISP_ABORT_RETRY, &vha->dpc_flags))
  582. return -EBUSY;
  583. if (!IS_QLA84XX(ha)) {
  584. DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld): Not 84xx, "
  585. "exiting.\n", vha->host_no));
  586. return -EINVAL;
  587. }
  588. flag = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
  589. rval = qla84xx_reset_chip(vha, flag == A84_ISSUE_RESET_DIAG_FW);
  590. if (rval) {
  591. DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld) Vendor "
  592. "request 84xx reset failed\n", vha->host_no));
  593. rval = bsg_job->reply->reply_payload_rcv_len = 0;
  594. bsg_job->reply->result = (DID_ERROR << 16);
  595. } else {
  596. DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld) Vendor "
  597. "request 84xx reset completed\n", vha->host_no));
  598. bsg_job->reply->result = DID_OK;
  599. }
  600. bsg_job->job_done(bsg_job);
  601. return rval;
  602. }
  603. static int
  604. qla84xx_updatefw(struct fc_bsg_job *bsg_job)
  605. {
  606. struct Scsi_Host *host = bsg_job->shost;
  607. scsi_qla_host_t *vha = shost_priv(host);
  608. struct qla_hw_data *ha = vha->hw;
  609. struct verify_chip_entry_84xx *mn = NULL;
  610. dma_addr_t mn_dma, fw_dma;
  611. void *fw_buf = NULL;
  612. int rval = 0;
  613. uint32_t sg_cnt;
  614. uint32_t data_len;
  615. uint16_t options;
  616. uint32_t flag;
  617. uint32_t fw_ver;
  618. if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
  619. test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  620. test_bit(ISP_ABORT_RETRY, &vha->dpc_flags))
  621. return -EBUSY;
  622. if (!IS_QLA84XX(ha)) {
  623. DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld): Not 84xx, "
  624. "exiting.\n", vha->host_no));
  625. return -EINVAL;
  626. }
  627. sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  628. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  629. if (!sg_cnt)
  630. return -ENOMEM;
  631. if (sg_cnt != bsg_job->request_payload.sg_cnt) {
  632. DEBUG2(printk(KERN_INFO
  633. "dma mapping resulted in different sg counts "
  634. "request_sg_cnt: %x dma_request_sg_cnt: %x ",
  635. bsg_job->request_payload.sg_cnt, sg_cnt));
  636. rval = -EAGAIN;
  637. goto done_unmap_sg;
  638. }
  639. data_len = bsg_job->request_payload.payload_len;
  640. fw_buf = dma_alloc_coherent(&ha->pdev->dev, data_len,
  641. &fw_dma, GFP_KERNEL);
  642. if (!fw_buf) {
  643. DEBUG2(printk(KERN_ERR "%s: dma alloc for fw_buf "
  644. "failed for host=%lu\n", __func__, vha->host_no));
  645. rval = -ENOMEM;
  646. goto done_unmap_sg;
  647. }
  648. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  649. bsg_job->request_payload.sg_cnt, fw_buf, data_len);
  650. mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
  651. if (!mn) {
  652. DEBUG2(printk(KERN_ERR "%s: dma alloc for fw buffer "
  653. "failed for host=%lu\n", __func__, vha->host_no));
  654. rval = -ENOMEM;
  655. goto done_free_fw_buf;
  656. }
  657. flag = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
  658. fw_ver = le32_to_cpu(*((uint32_t *)((uint32_t *)fw_buf + 2)));
  659. memset(mn, 0, sizeof(struct access_chip_84xx));
  660. mn->entry_type = VERIFY_CHIP_IOCB_TYPE;
  661. mn->entry_count = 1;
  662. options = VCO_FORCE_UPDATE | VCO_END_OF_DATA;
  663. if (flag == A84_ISSUE_UPDATE_DIAGFW_CMD)
  664. options |= VCO_DIAG_FW;
  665. mn->options = cpu_to_le16(options);
  666. mn->fw_ver = cpu_to_le32(fw_ver);
  667. mn->fw_size = cpu_to_le32(data_len);
  668. mn->fw_seq_size = cpu_to_le32(data_len);
  669. mn->dseg_address[0] = cpu_to_le32(LSD(fw_dma));
  670. mn->dseg_address[1] = cpu_to_le32(MSD(fw_dma));
  671. mn->dseg_length = cpu_to_le32(data_len);
  672. mn->data_seg_cnt = cpu_to_le16(1);
  673. rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
  674. if (rval) {
  675. DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld) Vendor "
  676. "request 84xx updatefw failed\n", vha->host_no));
  677. rval = bsg_job->reply->reply_payload_rcv_len = 0;
  678. bsg_job->reply->result = (DID_ERROR << 16);
  679. } else {
  680. DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld) Vendor "
  681. "request 84xx updatefw completed\n", vha->host_no));
  682. bsg_job->reply_len = sizeof(struct fc_bsg_reply);
  683. bsg_job->reply->result = DID_OK;
  684. }
  685. bsg_job->job_done(bsg_job);
  686. dma_pool_free(ha->s_dma_pool, mn, mn_dma);
  687. done_free_fw_buf:
  688. dma_free_coherent(&ha->pdev->dev, data_len, fw_buf, fw_dma);
  689. done_unmap_sg:
  690. dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  691. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  692. return rval;
  693. }
  694. static int
  695. qla84xx_mgmt_cmd(struct fc_bsg_job *bsg_job)
  696. {
  697. struct Scsi_Host *host = bsg_job->shost;
  698. scsi_qla_host_t *vha = shost_priv(host);
  699. struct qla_hw_data *ha = vha->hw;
  700. struct access_chip_84xx *mn = NULL;
  701. dma_addr_t mn_dma, mgmt_dma;
  702. void *mgmt_b = NULL;
  703. int rval = 0;
  704. struct qla_bsg_a84_mgmt *ql84_mgmt;
  705. uint32_t sg_cnt;
  706. uint32_t data_len = 0;
  707. uint32_t dma_direction = DMA_NONE;
  708. if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
  709. test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  710. test_bit(ISP_ABORT_RETRY, &vha->dpc_flags))
  711. return -EBUSY;
  712. if (!IS_QLA84XX(ha)) {
  713. DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld): Not 84xx, "
  714. "exiting.\n", vha->host_no));
  715. return -EINVAL;
  716. }
  717. ql84_mgmt = (struct qla_bsg_a84_mgmt *)((char *)bsg_job->request +
  718. sizeof(struct fc_bsg_request));
  719. if (!ql84_mgmt) {
  720. DEBUG2(printk("%s(%ld): mgmt header not provided, exiting.\n",
  721. __func__, vha->host_no));
  722. return -EINVAL;
  723. }
  724. mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
  725. if (!mn) {
  726. DEBUG2(printk(KERN_ERR "%s: dma alloc for fw buffer "
  727. "failed for host=%lu\n", __func__, vha->host_no));
  728. return -ENOMEM;
  729. }
  730. memset(mn, 0, sizeof(struct access_chip_84xx));
  731. mn->entry_type = ACCESS_CHIP_IOCB_TYPE;
  732. mn->entry_count = 1;
  733. switch (ql84_mgmt->mgmt.cmd) {
  734. case QLA84_MGMT_READ_MEM:
  735. case QLA84_MGMT_GET_INFO:
  736. sg_cnt = dma_map_sg(&ha->pdev->dev,
  737. bsg_job->reply_payload.sg_list,
  738. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  739. if (!sg_cnt) {
  740. rval = -ENOMEM;
  741. goto exit_mgmt;
  742. }
  743. dma_direction = DMA_FROM_DEVICE;
  744. if (sg_cnt != bsg_job->reply_payload.sg_cnt) {
  745. DEBUG2(printk(KERN_INFO
  746. "dma mapping resulted in different sg counts "
  747. "reply_sg_cnt: %x dma_reply_sg_cnt: %x\n",
  748. bsg_job->reply_payload.sg_cnt, sg_cnt));
  749. rval = -EAGAIN;
  750. goto done_unmap_sg;
  751. }
  752. data_len = bsg_job->reply_payload.payload_len;
  753. mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len,
  754. &mgmt_dma, GFP_KERNEL);
  755. if (!mgmt_b) {
  756. DEBUG2(printk(KERN_ERR "%s: dma alloc for mgmt_b "
  757. "failed for host=%lu\n",
  758. __func__, vha->host_no));
  759. rval = -ENOMEM;
  760. goto done_unmap_sg;
  761. }
  762. if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) {
  763. mn->options = cpu_to_le16(ACO_DUMP_MEMORY);
  764. mn->parameter1 =
  765. cpu_to_le32(
  766. ql84_mgmt->mgmt.mgmtp.u.mem.start_addr);
  767. } else if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO) {
  768. mn->options = cpu_to_le16(ACO_REQUEST_INFO);
  769. mn->parameter1 =
  770. cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.info.type);
  771. mn->parameter2 =
  772. cpu_to_le32(
  773. ql84_mgmt->mgmt.mgmtp.u.info.context);
  774. }
  775. break;
  776. case QLA84_MGMT_WRITE_MEM:
  777. sg_cnt = dma_map_sg(&ha->pdev->dev,
  778. bsg_job->request_payload.sg_list,
  779. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  780. if (!sg_cnt) {
  781. rval = -ENOMEM;
  782. goto exit_mgmt;
  783. }
  784. dma_direction = DMA_TO_DEVICE;
  785. if (sg_cnt != bsg_job->request_payload.sg_cnt) {
  786. DEBUG2(printk(KERN_INFO
  787. "dma mapping resulted in different sg counts "
  788. "request_sg_cnt: %x dma_request_sg_cnt: %x ",
  789. bsg_job->request_payload.sg_cnt, sg_cnt));
  790. rval = -EAGAIN;
  791. goto done_unmap_sg;
  792. }
  793. data_len = bsg_job->request_payload.payload_len;
  794. mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len,
  795. &mgmt_dma, GFP_KERNEL);
  796. if (!mgmt_b) {
  797. DEBUG2(printk(KERN_ERR "%s: dma alloc for mgmt_b "
  798. "failed for host=%lu\n",
  799. __func__, vha->host_no));
  800. rval = -ENOMEM;
  801. goto done_unmap_sg;
  802. }
  803. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  804. bsg_job->request_payload.sg_cnt, mgmt_b, data_len);
  805. mn->options = cpu_to_le16(ACO_LOAD_MEMORY);
  806. mn->parameter1 =
  807. cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.mem.start_addr);
  808. break;
  809. case QLA84_MGMT_CHNG_CONFIG:
  810. mn->options = cpu_to_le16(ACO_CHANGE_CONFIG_PARAM);
  811. mn->parameter1 =
  812. cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.id);
  813. mn->parameter2 =
  814. cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param0);
  815. mn->parameter3 =
  816. cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param1);
  817. break;
  818. default:
  819. rval = -EIO;
  820. goto exit_mgmt;
  821. }
  822. if (ql84_mgmt->mgmt.cmd != QLA84_MGMT_CHNG_CONFIG) {
  823. mn->total_byte_cnt = cpu_to_le32(ql84_mgmt->mgmt.len);
  824. mn->dseg_count = cpu_to_le16(1);
  825. mn->dseg_address[0] = cpu_to_le32(LSD(mgmt_dma));
  826. mn->dseg_address[1] = cpu_to_le32(MSD(mgmt_dma));
  827. mn->dseg_length = cpu_to_le32(ql84_mgmt->mgmt.len);
  828. }
  829. rval = qla2x00_issue_iocb(vha, mn, mn_dma, 0);
  830. if (rval) {
  831. DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld) Vendor "
  832. "request 84xx mgmt failed\n", vha->host_no));
  833. rval = bsg_job->reply->reply_payload_rcv_len = 0;
  834. bsg_job->reply->result = (DID_ERROR << 16);
  835. } else {
  836. DEBUG2(qla_printk(KERN_WARNING, ha, "scsi(%ld) Vendor "
  837. "request 84xx mgmt completed\n", vha->host_no));
  838. bsg_job->reply_len = sizeof(struct fc_bsg_reply);
  839. bsg_job->reply->result = DID_OK;
  840. if ((ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) ||
  841. (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO)) {
  842. bsg_job->reply->reply_payload_rcv_len =
  843. bsg_job->reply_payload.payload_len;
  844. sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
  845. bsg_job->reply_payload.sg_cnt, mgmt_b, data_len);
  846. }
  847. }
  848. bsg_job->job_done(bsg_job);
  849. done_unmap_sg:
  850. if (mgmt_b)
  851. dma_free_coherent(&ha->pdev->dev, data_len, mgmt_b, mgmt_dma);
  852. if (dma_direction == DMA_TO_DEVICE)
  853. dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  854. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  855. else if (dma_direction == DMA_FROM_DEVICE)
  856. dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  857. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  858. exit_mgmt:
  859. dma_pool_free(ha->s_dma_pool, mn, mn_dma);
  860. return rval;
  861. }
  862. static int
  863. qla24xx_iidma(struct fc_bsg_job *bsg_job)
  864. {
  865. struct Scsi_Host *host = bsg_job->shost;
  866. scsi_qla_host_t *vha = shost_priv(host);
  867. struct qla_hw_data *ha = vha->hw;
  868. int rval = 0;
  869. struct qla_port_param *port_param = NULL;
  870. fc_port_t *fcport = NULL;
  871. uint16_t mb[MAILBOX_REGISTER_COUNT];
  872. uint8_t *rsp_ptr = NULL;
  873. bsg_job->reply->reply_payload_rcv_len = 0;
  874. if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
  875. test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  876. test_bit(ISP_ABORT_RETRY, &vha->dpc_flags))
  877. return -EBUSY;
  878. if (!IS_IIDMA_CAPABLE(vha->hw)) {
  879. DEBUG2(qla_printk(KERN_WARNING, ha, "%s(%lu): iiDMA not "
  880. "supported\n", __func__, vha->host_no));
  881. return -EINVAL;
  882. }
  883. port_param = (struct qla_port_param *)((char *)bsg_job->request +
  884. sizeof(struct fc_bsg_request));
  885. if (!port_param) {
  886. DEBUG2(printk("%s(%ld): port_param header not provided, "
  887. "exiting.\n", __func__, vha->host_no));
  888. return -EINVAL;
  889. }
  890. if (port_param->fc_scsi_addr.dest_type != EXT_DEF_TYPE_WWPN) {
  891. DEBUG2(printk(KERN_ERR "%s(%ld): Invalid destination type\n",
  892. __func__, vha->host_no));
  893. return -EINVAL;
  894. }
  895. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  896. if (fcport->port_type != FCT_TARGET)
  897. continue;
  898. if (memcmp(port_param->fc_scsi_addr.dest_addr.wwpn,
  899. fcport->port_name, sizeof(fcport->port_name)))
  900. continue;
  901. break;
  902. }
  903. if (!fcport) {
  904. DEBUG2(printk(KERN_ERR "%s(%ld): Failed to find port\n",
  905. __func__, vha->host_no));
  906. return -EINVAL;
  907. }
  908. if (port_param->mode)
  909. rval = qla2x00_set_idma_speed(vha, fcport->loop_id,
  910. port_param->speed, mb);
  911. else
  912. rval = qla2x00_get_idma_speed(vha, fcport->loop_id,
  913. &port_param->speed, mb);
  914. if (rval) {
  915. DEBUG16(printk(KERN_ERR "scsi(%ld): iIDMA cmd failed for "
  916. "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
  917. vha->host_no, fcport->port_name[0],
  918. fcport->port_name[1],
  919. fcport->port_name[2], fcport->port_name[3],
  920. fcport->port_name[4], fcport->port_name[5],
  921. fcport->port_name[6], fcport->port_name[7], rval,
  922. fcport->fp_speed, mb[0], mb[1]));
  923. rval = 0;
  924. bsg_job->reply->result = (DID_ERROR << 16);
  925. } else {
  926. if (!port_param->mode) {
  927. bsg_job->reply_len = sizeof(struct fc_bsg_reply) +
  928. sizeof(struct qla_port_param);
  929. rsp_ptr = ((uint8_t *)bsg_job->reply) +
  930. sizeof(struct fc_bsg_reply);
  931. memcpy(rsp_ptr, port_param,
  932. sizeof(struct qla_port_param));
  933. }
  934. bsg_job->reply->result = DID_OK;
  935. }
  936. bsg_job->job_done(bsg_job);
  937. return rval;
  938. }
  939. static int
  940. qla2x00_process_vendor_specific(struct fc_bsg_job *bsg_job)
  941. {
  942. switch (bsg_job->request->rqst_data.h_vendor.vendor_cmd[0]) {
  943. case QL_VND_LOOPBACK:
  944. return qla2x00_process_loopback(bsg_job);
  945. case QL_VND_A84_RESET:
  946. return qla84xx_reset(bsg_job);
  947. case QL_VND_A84_UPDATE_FW:
  948. return qla84xx_updatefw(bsg_job);
  949. case QL_VND_A84_MGMT_CMD:
  950. return qla84xx_mgmt_cmd(bsg_job);
  951. case QL_VND_IIDMA:
  952. return qla24xx_iidma(bsg_job);
  953. case QL_VND_FCP_PRIO_CFG_CMD:
  954. return qla24xx_proc_fcp_prio_cfg_cmd(bsg_job);
  955. default:
  956. bsg_job->reply->result = (DID_ERROR << 16);
  957. bsg_job->job_done(bsg_job);
  958. return -ENOSYS;
  959. }
  960. }
  961. int
  962. qla24xx_bsg_request(struct fc_bsg_job *bsg_job)
  963. {
  964. int ret = -EINVAL;
  965. switch (bsg_job->request->msgcode) {
  966. case FC_BSG_RPT_ELS:
  967. case FC_BSG_HST_ELS_NOLOGIN:
  968. ret = qla2x00_process_els(bsg_job);
  969. break;
  970. case FC_BSG_HST_CT:
  971. ret = qla2x00_process_ct(bsg_job);
  972. break;
  973. case FC_BSG_HST_VENDOR:
  974. ret = qla2x00_process_vendor_specific(bsg_job);
  975. break;
  976. case FC_BSG_HST_ADD_RPORT:
  977. case FC_BSG_HST_DEL_RPORT:
  978. case FC_BSG_RPT_CT:
  979. default:
  980. DEBUG2(printk("qla2xxx: unsupported BSG request\n"));
  981. break;
  982. }
  983. return ret;
  984. }
  985. int
  986. qla24xx_bsg_timeout(struct fc_bsg_job *bsg_job)
  987. {
  988. scsi_qla_host_t *vha = shost_priv(bsg_job->shost);
  989. struct qla_hw_data *ha = vha->hw;
  990. srb_t *sp;
  991. int cnt, que;
  992. unsigned long flags;
  993. struct req_que *req;
  994. struct srb_bsg *sp_bsg;
  995. /* find the bsg job from the active list of commands */
  996. spin_lock_irqsave(&ha->hardware_lock, flags);
  997. for (que = 0; que < ha->max_req_queues; que++) {
  998. req = ha->req_q_map[que];
  999. if (!req)
  1000. continue;
  1001. for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++ ) {
  1002. sp = req->outstanding_cmds[cnt];
  1003. if (sp) {
  1004. sp_bsg = (struct srb_bsg*)sp->ctx;
  1005. if (((sp_bsg->ctx.type == SRB_CT_CMD) ||
  1006. (sp_bsg->ctx.type == SRB_ELS_CMD_HST))
  1007. && (sp_bsg->bsg_job == bsg_job)) {
  1008. if (ha->isp_ops->abort_command(sp)) {
  1009. DEBUG2(qla_printk(KERN_INFO, ha,
  1010. "scsi(%ld): mbx abort_command failed\n", vha->host_no));
  1011. bsg_job->req->errors =
  1012. bsg_job->reply->result = -EIO;
  1013. } else {
  1014. DEBUG2(qla_printk(KERN_INFO, ha,
  1015. "scsi(%ld): mbx abort_command success\n", vha->host_no));
  1016. bsg_job->req->errors =
  1017. bsg_job->reply->result = 0;
  1018. }
  1019. goto done;
  1020. }
  1021. }
  1022. }
  1023. }
  1024. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1025. DEBUG2(qla_printk(KERN_INFO, ha,
  1026. "scsi(%ld) SRB not found to abort\n", vha->host_no));
  1027. bsg_job->req->errors = bsg_job->reply->result = -ENXIO;
  1028. return 0;
  1029. done:
  1030. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1031. if (bsg_job->request->msgcode == FC_BSG_HST_CT)
  1032. kfree(sp->fcport);
  1033. kfree(sp->ctx);
  1034. mempool_free(sp, ha->srb_mempool);
  1035. return 0;
  1036. }