qla_bsg.c 32 KB

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