/drivers/scsi/qla2xxx/qla_mid.c

https://bitbucket.org/abioy/linux · C · 773 lines · 612 code · 108 blank · 53 comment · 91 complexity · 4d7fde08d20bcc880baa9484ab205ee3 MD5 · raw file

  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 "qla_gbl.h"
  9. #include <linux/moduleparam.h>
  10. #include <linux/vmalloc.h>
  11. #include <linux/slab.h>
  12. #include <linux/list.h>
  13. #include <scsi/scsi_tcq.h>
  14. #include <scsi/scsicam.h>
  15. #include <linux/delay.h>
  16. void
  17. qla2x00_vp_stop_timer(scsi_qla_host_t *vha)
  18. {
  19. if (vha->vp_idx && vha->timer_active) {
  20. del_timer_sync(&vha->timer);
  21. vha->timer_active = 0;
  22. }
  23. }
  24. static uint32_t
  25. qla24xx_allocate_vp_id(scsi_qla_host_t *vha)
  26. {
  27. uint32_t vp_id;
  28. struct qla_hw_data *ha = vha->hw;
  29. /* Find an empty slot and assign an vp_id */
  30. mutex_lock(&ha->vport_lock);
  31. vp_id = find_first_zero_bit(ha->vp_idx_map, ha->max_npiv_vports + 1);
  32. if (vp_id > ha->max_npiv_vports) {
  33. DEBUG15(printk ("vp_id %d is bigger than max-supported %d.\n",
  34. vp_id, ha->max_npiv_vports));
  35. mutex_unlock(&ha->vport_lock);
  36. return vp_id;
  37. }
  38. set_bit(vp_id, ha->vp_idx_map);
  39. ha->num_vhosts++;
  40. vha->vp_idx = vp_id;
  41. list_add_tail(&vha->list, &ha->vp_list);
  42. mutex_unlock(&ha->vport_lock);
  43. return vp_id;
  44. }
  45. void
  46. qla24xx_deallocate_vp_id(scsi_qla_host_t *vha)
  47. {
  48. uint16_t vp_id;
  49. struct qla_hw_data *ha = vha->hw;
  50. mutex_lock(&ha->vport_lock);
  51. vp_id = vha->vp_idx;
  52. ha->num_vhosts--;
  53. clear_bit(vp_id, ha->vp_idx_map);
  54. list_del(&vha->list);
  55. mutex_unlock(&ha->vport_lock);
  56. }
  57. static scsi_qla_host_t *
  58. qla24xx_find_vhost_by_name(struct qla_hw_data *ha, uint8_t *port_name)
  59. {
  60. scsi_qla_host_t *vha;
  61. struct scsi_qla_host *tvha;
  62. /* Locate matching device in database. */
  63. list_for_each_entry_safe(vha, tvha, &ha->vp_list, list) {
  64. if (!memcmp(port_name, vha->port_name, WWN_SIZE))
  65. return vha;
  66. }
  67. return NULL;
  68. }
  69. /*
  70. * qla2x00_mark_vp_devices_dead
  71. * Updates fcport state when device goes offline.
  72. *
  73. * Input:
  74. * ha = adapter block pointer.
  75. * fcport = port structure pointer.
  76. *
  77. * Return:
  78. * None.
  79. *
  80. * Context:
  81. */
  82. static void
  83. qla2x00_mark_vp_devices_dead(scsi_qla_host_t *vha)
  84. {
  85. fc_port_t *fcport;
  86. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  87. DEBUG15(printk("scsi(%ld): Marking port dead, "
  88. "loop_id=0x%04x :%x\n",
  89. vha->host_no, fcport->loop_id, fcport->vp_idx));
  90. atomic_set(&fcport->state, FCS_DEVICE_DEAD);
  91. qla2x00_mark_device_lost(vha, fcport, 0, 0);
  92. atomic_set(&fcport->state, FCS_UNCONFIGURED);
  93. }
  94. }
  95. int
  96. qla24xx_disable_vp(scsi_qla_host_t *vha)
  97. {
  98. int ret;
  99. ret = qla24xx_control_vp(vha, VCE_COMMAND_DISABLE_VPS_LOGO_ALL);
  100. atomic_set(&vha->loop_state, LOOP_DOWN);
  101. atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
  102. qla2x00_mark_vp_devices_dead(vha);
  103. atomic_set(&vha->vp_state, VP_FAILED);
  104. vha->flags.management_server_logged_in = 0;
  105. if (ret == QLA_SUCCESS) {
  106. fc_vport_set_state(vha->fc_vport, FC_VPORT_DISABLED);
  107. } else {
  108. fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
  109. return -1;
  110. }
  111. return 0;
  112. }
  113. int
  114. qla24xx_enable_vp(scsi_qla_host_t *vha)
  115. {
  116. int ret;
  117. struct qla_hw_data *ha = vha->hw;
  118. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  119. /* Check if physical ha port is Up */
  120. if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
  121. atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  122. vha->vp_err_state = VP_ERR_PORTDWN;
  123. fc_vport_set_state(vha->fc_vport, FC_VPORT_LINKDOWN);
  124. goto enable_failed;
  125. }
  126. /* Initialize the new vport unless it is a persistent port */
  127. mutex_lock(&ha->vport_lock);
  128. ret = qla24xx_modify_vp_config(vha);
  129. mutex_unlock(&ha->vport_lock);
  130. if (ret != QLA_SUCCESS) {
  131. fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
  132. goto enable_failed;
  133. }
  134. DEBUG15(qla_printk(KERN_INFO, ha,
  135. "Virtual port with id: %d - Enabled\n", vha->vp_idx));
  136. return 0;
  137. enable_failed:
  138. DEBUG15(qla_printk(KERN_INFO, ha,
  139. "Virtual port with id: %d - Disabled\n", vha->vp_idx));
  140. return 1;
  141. }
  142. static void
  143. qla24xx_configure_vp(scsi_qla_host_t *vha)
  144. {
  145. struct fc_vport *fc_vport;
  146. int ret;
  147. fc_vport = vha->fc_vport;
  148. DEBUG15(printk("scsi(%ld): %s: change request #3 for this host.\n",
  149. vha->host_no, __func__));
  150. ret = qla2x00_send_change_request(vha, 0x3, vha->vp_idx);
  151. if (ret != QLA_SUCCESS) {
  152. DEBUG15(qla_printk(KERN_ERR, vha->hw, "Failed to enable "
  153. "receiving of RSCN requests: 0x%x\n", ret));
  154. return;
  155. } else {
  156. /* Corresponds to SCR enabled */
  157. clear_bit(VP_SCR_NEEDED, &vha->vp_flags);
  158. }
  159. vha->flags.online = 1;
  160. if (qla24xx_configure_vhba(vha))
  161. return;
  162. atomic_set(&vha->vp_state, VP_ACTIVE);
  163. fc_vport_set_state(fc_vport, FC_VPORT_ACTIVE);
  164. }
  165. void
  166. qla2x00_alert_all_vps(struct rsp_que *rsp, uint16_t *mb)
  167. {
  168. scsi_qla_host_t *vha, *tvha;
  169. struct qla_hw_data *ha = rsp->hw;
  170. int i = 0;
  171. list_for_each_entry_safe(vha, tvha, &ha->vp_list, list) {
  172. if (vha->vp_idx) {
  173. switch (mb[0]) {
  174. case MBA_LIP_OCCURRED:
  175. case MBA_LOOP_UP:
  176. case MBA_LOOP_DOWN:
  177. case MBA_LIP_RESET:
  178. case MBA_POINT_TO_POINT:
  179. case MBA_CHG_IN_CONNECTION:
  180. case MBA_PORT_UPDATE:
  181. case MBA_RSCN_UPDATE:
  182. DEBUG15(printk("scsi(%ld)%s: Async_event for"
  183. " VP[%d], mb = 0x%x, vha=%p\n",
  184. vha->host_no, __func__, i, *mb, vha));
  185. qla2x00_async_event(vha, rsp, mb);
  186. break;
  187. }
  188. }
  189. i++;
  190. }
  191. }
  192. int
  193. qla2x00_vp_abort_isp(scsi_qla_host_t *vha)
  194. {
  195. /*
  196. * Physical port will do most of the abort and recovery work. We can
  197. * just treat it as a loop down
  198. */
  199. if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
  200. atomic_set(&vha->loop_state, LOOP_DOWN);
  201. qla2x00_mark_all_devices_lost(vha, 0);
  202. } else {
  203. if (!atomic_read(&vha->loop_down_timer))
  204. atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
  205. }
  206. /*
  207. * To exclusively reset vport, we need to log it out first. Note: this
  208. * control_vp can fail if ISP reset is already issued, this is
  209. * expected, as the vp would be already logged out due to ISP reset.
  210. */
  211. if (!test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))
  212. qla24xx_control_vp(vha, VCE_COMMAND_DISABLE_VPS_LOGO_ALL);
  213. DEBUG15(printk("scsi(%ld): Scheduling enable of Vport %d...\n",
  214. vha->host_no, vha->vp_idx));
  215. return qla24xx_enable_vp(vha);
  216. }
  217. static int
  218. qla2x00_do_dpc_vp(scsi_qla_host_t *vha)
  219. {
  220. qla2x00_do_work(vha);
  221. if (test_and_clear_bit(VP_IDX_ACQUIRED, &vha->vp_flags)) {
  222. /* VP acquired. complete port configuration */
  223. qla24xx_configure_vp(vha);
  224. return 0;
  225. }
  226. if (test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags)) {
  227. qla2x00_update_fcports(vha);
  228. clear_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags);
  229. }
  230. if ((test_and_clear_bit(RELOGIN_NEEDED, &vha->dpc_flags)) &&
  231. !test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) &&
  232. atomic_read(&vha->loop_state) != LOOP_DOWN) {
  233. DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
  234. vha->host_no));
  235. qla2x00_relogin(vha);
  236. DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
  237. vha->host_no));
  238. }
  239. if (test_and_clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) &&
  240. (!(test_and_set_bit(RESET_ACTIVE, &vha->dpc_flags)))) {
  241. clear_bit(RESET_ACTIVE, &vha->dpc_flags);
  242. }
  243. if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
  244. if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags))) {
  245. qla2x00_loop_resync(vha);
  246. clear_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags);
  247. }
  248. }
  249. return 0;
  250. }
  251. void
  252. qla2x00_do_dpc_all_vps(scsi_qla_host_t *vha)
  253. {
  254. int ret;
  255. struct qla_hw_data *ha = vha->hw;
  256. scsi_qla_host_t *vp;
  257. struct scsi_qla_host *tvp;
  258. if (vha->vp_idx)
  259. return;
  260. if (list_empty(&ha->vp_list))
  261. return;
  262. clear_bit(VP_DPC_NEEDED, &vha->dpc_flags);
  263. if (!(ha->current_topology & ISP_CFG_F))
  264. return;
  265. list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
  266. if (vp->vp_idx)
  267. ret = qla2x00_do_dpc_vp(vp);
  268. }
  269. }
  270. int
  271. qla24xx_vport_create_req_sanity_check(struct fc_vport *fc_vport)
  272. {
  273. scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
  274. struct qla_hw_data *ha = base_vha->hw;
  275. scsi_qla_host_t *vha;
  276. uint8_t port_name[WWN_SIZE];
  277. if (fc_vport->roles != FC_PORT_ROLE_FCP_INITIATOR)
  278. return VPCERR_UNSUPPORTED;
  279. /* Check up the F/W and H/W support NPIV */
  280. if (!ha->flags.npiv_supported)
  281. return VPCERR_UNSUPPORTED;
  282. /* Check up whether npiv supported switch presented */
  283. if (!(ha->switch_cap & FLOGI_MID_SUPPORT))
  284. return VPCERR_NO_FABRIC_SUPP;
  285. /* Check up unique WWPN */
  286. u64_to_wwn(fc_vport->port_name, port_name);
  287. if (!memcmp(port_name, base_vha->port_name, WWN_SIZE))
  288. return VPCERR_BAD_WWN;
  289. vha = qla24xx_find_vhost_by_name(ha, port_name);
  290. if (vha)
  291. return VPCERR_BAD_WWN;
  292. /* Check up max-npiv-supports */
  293. if (ha->num_vhosts > ha->max_npiv_vports) {
  294. DEBUG15(printk("scsi(%ld): num_vhosts %ud is bigger than "
  295. "max_npv_vports %ud.\n", base_vha->host_no,
  296. ha->num_vhosts, ha->max_npiv_vports));
  297. return VPCERR_UNSUPPORTED;
  298. }
  299. return 0;
  300. }
  301. scsi_qla_host_t *
  302. qla24xx_create_vhost(struct fc_vport *fc_vport)
  303. {
  304. scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
  305. struct qla_hw_data *ha = base_vha->hw;
  306. scsi_qla_host_t *vha;
  307. struct scsi_host_template *sht = &qla2xxx_driver_template;
  308. struct Scsi_Host *host;
  309. vha = qla2x00_create_host(sht, ha);
  310. if (!vha) {
  311. DEBUG(printk("qla2xxx: scsi_host_alloc() failed for vport\n"));
  312. return(NULL);
  313. }
  314. host = vha->host;
  315. fc_vport->dd_data = vha;
  316. /* New host info */
  317. u64_to_wwn(fc_vport->node_name, vha->node_name);
  318. u64_to_wwn(fc_vport->port_name, vha->port_name);
  319. vha->fc_vport = fc_vport;
  320. vha->device_flags = 0;
  321. vha->vp_idx = qla24xx_allocate_vp_id(vha);
  322. if (vha->vp_idx > ha->max_npiv_vports) {
  323. DEBUG15(printk("scsi(%ld): Couldn't allocate vp_id.\n",
  324. vha->host_no));
  325. goto create_vhost_failed;
  326. }
  327. vha->mgmt_svr_loop_id = 10 + vha->vp_idx;
  328. vha->dpc_flags = 0L;
  329. /*
  330. * To fix the issue of processing a parent's RSCN for the vport before
  331. * its SCR is complete.
  332. */
  333. set_bit(VP_SCR_NEEDED, &vha->vp_flags);
  334. atomic_set(&vha->loop_state, LOOP_DOWN);
  335. atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
  336. qla2x00_start_timer(vha, qla2x00_timer, WATCH_INTERVAL);
  337. vha->req = base_vha->req;
  338. host->can_queue = base_vha->req->length + 128;
  339. host->this_id = 255;
  340. host->cmd_per_lun = 3;
  341. host->max_cmd_len = MAX_CMDSZ;
  342. host->max_channel = MAX_BUSES - 1;
  343. host->max_lun = MAX_LUNS;
  344. host->unique_id = host->host_no;
  345. host->max_id = MAX_TARGETS_2200;
  346. host->transportt = qla2xxx_transport_vport_template;
  347. DEBUG15(printk("DEBUG: detect vport hba %ld at address = %p\n",
  348. vha->host_no, vha));
  349. vha->flags.init_done = 1;
  350. mutex_lock(&ha->vport_lock);
  351. set_bit(vha->vp_idx, ha->vp_idx_map);
  352. ha->cur_vport_count++;
  353. mutex_unlock(&ha->vport_lock);
  354. return vha;
  355. create_vhost_failed:
  356. return NULL;
  357. }
  358. static void
  359. qla25xx_free_req_que(struct scsi_qla_host *vha, struct req_que *req)
  360. {
  361. struct qla_hw_data *ha = vha->hw;
  362. uint16_t que_id = req->id;
  363. dma_free_coherent(&ha->pdev->dev, (req->length + 1) *
  364. sizeof(request_t), req->ring, req->dma);
  365. req->ring = NULL;
  366. req->dma = 0;
  367. if (que_id) {
  368. ha->req_q_map[que_id] = NULL;
  369. mutex_lock(&ha->vport_lock);
  370. clear_bit(que_id, ha->req_qid_map);
  371. mutex_unlock(&ha->vport_lock);
  372. }
  373. kfree(req);
  374. req = NULL;
  375. }
  376. static void
  377. qla25xx_free_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
  378. {
  379. struct qla_hw_data *ha = vha->hw;
  380. uint16_t que_id = rsp->id;
  381. if (rsp->msix && rsp->msix->have_irq) {
  382. free_irq(rsp->msix->vector, rsp);
  383. rsp->msix->have_irq = 0;
  384. rsp->msix->rsp = NULL;
  385. }
  386. dma_free_coherent(&ha->pdev->dev, (rsp->length + 1) *
  387. sizeof(response_t), rsp->ring, rsp->dma);
  388. rsp->ring = NULL;
  389. rsp->dma = 0;
  390. if (que_id) {
  391. ha->rsp_q_map[que_id] = NULL;
  392. mutex_lock(&ha->vport_lock);
  393. clear_bit(que_id, ha->rsp_qid_map);
  394. mutex_unlock(&ha->vport_lock);
  395. }
  396. kfree(rsp);
  397. rsp = NULL;
  398. }
  399. int
  400. qla25xx_delete_req_que(struct scsi_qla_host *vha, struct req_que *req)
  401. {
  402. int ret = -1;
  403. if (req) {
  404. req->options |= BIT_0;
  405. ret = qla25xx_init_req_que(vha, req);
  406. }
  407. if (ret == QLA_SUCCESS)
  408. qla25xx_free_req_que(vha, req);
  409. return ret;
  410. }
  411. int
  412. qla25xx_delete_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
  413. {
  414. int ret = -1;
  415. if (rsp) {
  416. rsp->options |= BIT_0;
  417. ret = qla25xx_init_rsp_que(vha, rsp);
  418. }
  419. if (ret == QLA_SUCCESS)
  420. qla25xx_free_rsp_que(vha, rsp);
  421. return ret;
  422. }
  423. int qla25xx_update_req_que(struct scsi_qla_host *vha, uint8_t que, uint8_t qos)
  424. {
  425. int ret = 0;
  426. struct qla_hw_data *ha = vha->hw;
  427. struct req_que *req = ha->req_q_map[que];
  428. req->options |= BIT_3;
  429. req->qos = qos;
  430. ret = qla25xx_init_req_que(vha, req);
  431. if (ret != QLA_SUCCESS)
  432. DEBUG2_17(printk(KERN_WARNING "%s failed\n", __func__));
  433. /* restore options bit */
  434. req->options &= ~BIT_3;
  435. return ret;
  436. }
  437. /* Delete all queues for a given vhost */
  438. int
  439. qla25xx_delete_queues(struct scsi_qla_host *vha)
  440. {
  441. int cnt, ret = 0;
  442. struct req_que *req = NULL;
  443. struct rsp_que *rsp = NULL;
  444. struct qla_hw_data *ha = vha->hw;
  445. /* Delete request queues */
  446. for (cnt = 1; cnt < ha->max_req_queues; cnt++) {
  447. req = ha->req_q_map[cnt];
  448. if (req) {
  449. ret = qla25xx_delete_req_que(vha, req);
  450. if (ret != QLA_SUCCESS) {
  451. qla_printk(KERN_WARNING, ha,
  452. "Couldn't delete req que %d\n",
  453. req->id);
  454. return ret;
  455. }
  456. }
  457. }
  458. /* Delete response queues */
  459. for (cnt = 1; cnt < ha->max_rsp_queues; cnt++) {
  460. rsp = ha->rsp_q_map[cnt];
  461. if (rsp) {
  462. ret = qla25xx_delete_rsp_que(vha, rsp);
  463. if (ret != QLA_SUCCESS) {
  464. qla_printk(KERN_WARNING, ha,
  465. "Couldn't delete rsp que %d\n",
  466. rsp->id);
  467. return ret;
  468. }
  469. }
  470. }
  471. return ret;
  472. }
  473. int
  474. qla25xx_create_req_que(struct qla_hw_data *ha, uint16_t options,
  475. uint8_t vp_idx, uint16_t rid, int rsp_que, uint8_t qos)
  476. {
  477. int ret = 0;
  478. struct req_que *req = NULL;
  479. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  480. uint16_t que_id = 0;
  481. device_reg_t __iomem *reg;
  482. uint32_t cnt;
  483. req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
  484. if (req == NULL) {
  485. qla_printk(KERN_WARNING, ha, "could not allocate memory"
  486. "for request que\n");
  487. goto failed;
  488. }
  489. req->length = REQUEST_ENTRY_CNT_24XX;
  490. req->ring = dma_alloc_coherent(&ha->pdev->dev,
  491. (req->length + 1) * sizeof(request_t),
  492. &req->dma, GFP_KERNEL);
  493. if (req->ring == NULL) {
  494. qla_printk(KERN_WARNING, ha,
  495. "Memory Allocation failed - request_ring\n");
  496. goto que_failed;
  497. }
  498. mutex_lock(&ha->vport_lock);
  499. que_id = find_first_zero_bit(ha->req_qid_map, ha->max_req_queues);
  500. if (que_id >= ha->max_req_queues) {
  501. mutex_unlock(&ha->vport_lock);
  502. qla_printk(KERN_INFO, ha, "No resources to create "
  503. "additional request queue\n");
  504. goto que_failed;
  505. }
  506. set_bit(que_id, ha->req_qid_map);
  507. ha->req_q_map[que_id] = req;
  508. req->rid = rid;
  509. req->vp_idx = vp_idx;
  510. req->qos = qos;
  511. if (rsp_que < 0)
  512. req->rsp = NULL;
  513. else
  514. req->rsp = ha->rsp_q_map[rsp_que];
  515. /* Use alternate PCI bus number */
  516. if (MSB(req->rid))
  517. options |= BIT_4;
  518. /* Use alternate PCI devfn */
  519. if (LSB(req->rid))
  520. options |= BIT_5;
  521. req->options = options;
  522. for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
  523. req->outstanding_cmds[cnt] = NULL;
  524. req->current_outstanding_cmd = 1;
  525. req->ring_ptr = req->ring;
  526. req->ring_index = 0;
  527. req->cnt = req->length;
  528. req->id = que_id;
  529. reg = ISP_QUE_REG(ha, que_id);
  530. req->max_q_depth = ha->req_q_map[0]->max_q_depth;
  531. mutex_unlock(&ha->vport_lock);
  532. ret = qla25xx_init_req_que(base_vha, req);
  533. if (ret != QLA_SUCCESS) {
  534. qla_printk(KERN_WARNING, ha, "%s failed\n", __func__);
  535. mutex_lock(&ha->vport_lock);
  536. clear_bit(que_id, ha->req_qid_map);
  537. mutex_unlock(&ha->vport_lock);
  538. goto que_failed;
  539. }
  540. return req->id;
  541. que_failed:
  542. qla25xx_free_req_que(base_vha, req);
  543. failed:
  544. return 0;
  545. }
  546. static void qla_do_work(struct work_struct *work)
  547. {
  548. unsigned long flags;
  549. struct rsp_que *rsp = container_of(work, struct rsp_que, q_work);
  550. struct scsi_qla_host *vha;
  551. struct qla_hw_data *ha = rsp->hw;
  552. spin_lock_irqsave(&rsp->hw->hardware_lock, flags);
  553. vha = pci_get_drvdata(ha->pdev);
  554. qla24xx_process_response_queue(vha, rsp);
  555. spin_unlock_irqrestore(&rsp->hw->hardware_lock, flags);
  556. }
  557. /* create response queue */
  558. int
  559. qla25xx_create_rsp_que(struct qla_hw_data *ha, uint16_t options,
  560. uint8_t vp_idx, uint16_t rid, int req)
  561. {
  562. int ret = 0;
  563. struct rsp_que *rsp = NULL;
  564. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  565. uint16_t que_id = 0;
  566. device_reg_t __iomem *reg;
  567. rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
  568. if (rsp == NULL) {
  569. qla_printk(KERN_WARNING, ha, "could not allocate memory for"
  570. " response que\n");
  571. goto failed;
  572. }
  573. rsp->length = RESPONSE_ENTRY_CNT_MQ;
  574. rsp->ring = dma_alloc_coherent(&ha->pdev->dev,
  575. (rsp->length + 1) * sizeof(response_t),
  576. &rsp->dma, GFP_KERNEL);
  577. if (rsp->ring == NULL) {
  578. qla_printk(KERN_WARNING, ha,
  579. "Memory Allocation failed - response_ring\n");
  580. goto que_failed;
  581. }
  582. mutex_lock(&ha->vport_lock);
  583. que_id = find_first_zero_bit(ha->rsp_qid_map, ha->max_rsp_queues);
  584. if (que_id >= ha->max_rsp_queues) {
  585. mutex_unlock(&ha->vport_lock);
  586. qla_printk(KERN_INFO, ha, "No resources to create "
  587. "additional response queue\n");
  588. goto que_failed;
  589. }
  590. set_bit(que_id, ha->rsp_qid_map);
  591. if (ha->flags.msix_enabled)
  592. rsp->msix = &ha->msix_entries[que_id + 1];
  593. else
  594. qla_printk(KERN_WARNING, ha, "msix not enabled\n");
  595. ha->rsp_q_map[que_id] = rsp;
  596. rsp->rid = rid;
  597. rsp->vp_idx = vp_idx;
  598. rsp->hw = ha;
  599. /* Use alternate PCI bus number */
  600. if (MSB(rsp->rid))
  601. options |= BIT_4;
  602. /* Use alternate PCI devfn */
  603. if (LSB(rsp->rid))
  604. options |= BIT_5;
  605. /* Enable MSIX handshake mode on for uncapable adapters */
  606. if (!IS_MSIX_NACK_CAPABLE(ha))
  607. options |= BIT_6;
  608. rsp->options = options;
  609. rsp->id = que_id;
  610. reg = ISP_QUE_REG(ha, que_id);
  611. rsp->rsp_q_in = &reg->isp25mq.rsp_q_in;
  612. rsp->rsp_q_out = &reg->isp25mq.rsp_q_out;
  613. mutex_unlock(&ha->vport_lock);
  614. ret = qla25xx_request_irq(rsp);
  615. if (ret)
  616. goto que_failed;
  617. ret = qla25xx_init_rsp_que(base_vha, rsp);
  618. if (ret != QLA_SUCCESS) {
  619. qla_printk(KERN_WARNING, ha, "%s failed\n", __func__);
  620. mutex_lock(&ha->vport_lock);
  621. clear_bit(que_id, ha->rsp_qid_map);
  622. mutex_unlock(&ha->vport_lock);
  623. goto que_failed;
  624. }
  625. if (req >= 0)
  626. rsp->req = ha->req_q_map[req];
  627. else
  628. rsp->req = NULL;
  629. qla2x00_init_response_q_entries(rsp);
  630. if (rsp->hw->wq)
  631. INIT_WORK(&rsp->q_work, qla_do_work);
  632. return rsp->id;
  633. que_failed:
  634. qla25xx_free_rsp_que(base_vha, rsp);
  635. failed:
  636. return 0;
  637. }
  638. int
  639. qla25xx_create_queues(struct scsi_qla_host *vha, uint8_t qos)
  640. {
  641. uint16_t options = 0;
  642. uint8_t ret = 0;
  643. struct qla_hw_data *ha = vha->hw;
  644. struct rsp_que *rsp;
  645. options |= BIT_1;
  646. ret = qla25xx_create_rsp_que(ha, options, vha->vp_idx, 0, -1);
  647. if (!ret) {
  648. qla_printk(KERN_WARNING, ha, "Response Que create failed\n");
  649. return ret;
  650. } else
  651. qla_printk(KERN_INFO, ha, "Response Que:%d created.\n", ret);
  652. rsp = ha->rsp_q_map[ret];
  653. options = 0;
  654. if (qos & BIT_7)
  655. options |= BIT_8;
  656. ret = qla25xx_create_req_que(ha, options, vha->vp_idx, 0, ret,
  657. qos & ~BIT_7);
  658. if (ret) {
  659. vha->req = ha->req_q_map[ret];
  660. qla_printk(KERN_INFO, ha, "Request Que:%d created.\n", ret);
  661. } else
  662. qla_printk(KERN_WARNING, ha, "Request Que create failed\n");
  663. rsp->req = ha->req_q_map[ret];
  664. return ret;
  665. }