qla_mid.c 18 KB

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