qla_mid.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  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/smp_lock.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. ha->cur_vport_count++;
  41. vha->vp_idx = vp_id;
  42. list_add_tail(&vha->list, &ha->vp_list);
  43. mutex_unlock(&ha->vport_lock);
  44. return vp_id;
  45. }
  46. void
  47. qla24xx_deallocate_vp_id(scsi_qla_host_t *vha)
  48. {
  49. uint16_t vp_id;
  50. struct qla_hw_data *ha = vha->hw;
  51. mutex_lock(&ha->vport_lock);
  52. vp_id = vha->vp_idx;
  53. ha->num_vhosts--;
  54. ha->cur_vport_count--;
  55. clear_bit(vp_id, ha->vp_idx_map);
  56. list_del(&vha->list);
  57. mutex_unlock(&ha->vport_lock);
  58. }
  59. static scsi_qla_host_t *
  60. qla24xx_find_vhost_by_name(struct qla_hw_data *ha, uint8_t *port_name)
  61. {
  62. scsi_qla_host_t *vha;
  63. struct scsi_qla_host *tvha;
  64. /* Locate matching device in database. */
  65. list_for_each_entry_safe(vha, tvha, &ha->vp_list, list) {
  66. if (!memcmp(port_name, vha->port_name, WWN_SIZE))
  67. return vha;
  68. }
  69. return NULL;
  70. }
  71. /*
  72. * qla2x00_mark_vp_devices_dead
  73. * Updates fcport state when device goes offline.
  74. *
  75. * Input:
  76. * ha = adapter block pointer.
  77. * fcport = port structure pointer.
  78. *
  79. * Return:
  80. * None.
  81. *
  82. * Context:
  83. */
  84. static void
  85. qla2x00_mark_vp_devices_dead(scsi_qla_host_t *vha)
  86. {
  87. fc_port_t *fcport;
  88. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  89. DEBUG15(printk("scsi(%ld): Marking port dead, "
  90. "loop_id=0x%04x :%x\n",
  91. vha->host_no, fcport->loop_id, fcport->vp_idx));
  92. atomic_set(&fcport->state, FCS_DEVICE_DEAD);
  93. qla2x00_mark_device_lost(vha, fcport, 0, 0);
  94. atomic_set(&fcport->state, FCS_UNCONFIGURED);
  95. }
  96. }
  97. int
  98. qla24xx_disable_vp(scsi_qla_host_t *vha)
  99. {
  100. int ret;
  101. ret = qla24xx_control_vp(vha, VCE_COMMAND_DISABLE_VPS_LOGO_ALL);
  102. atomic_set(&vha->loop_state, LOOP_DOWN);
  103. atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
  104. qla2x00_mark_vp_devices_dead(vha);
  105. atomic_set(&vha->vp_state, VP_FAILED);
  106. vha->flags.management_server_logged_in = 0;
  107. if (ret == QLA_SUCCESS) {
  108. fc_vport_set_state(vha->fc_vport, FC_VPORT_DISABLED);
  109. } else {
  110. fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
  111. return -1;
  112. }
  113. return 0;
  114. }
  115. int
  116. qla24xx_enable_vp(scsi_qla_host_t *vha)
  117. {
  118. int ret;
  119. struct qla_hw_data *ha = vha->hw;
  120. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  121. /* Check if physical ha port is Up */
  122. if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
  123. atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  124. vha->vp_err_state = VP_ERR_PORTDWN;
  125. fc_vport_set_state(vha->fc_vport, FC_VPORT_LINKDOWN);
  126. goto enable_failed;
  127. }
  128. /* Initialize the new vport unless it is a persistent port */
  129. mutex_lock(&ha->vport_lock);
  130. ret = qla24xx_modify_vp_config(vha);
  131. mutex_unlock(&ha->vport_lock);
  132. if (ret != QLA_SUCCESS) {
  133. fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
  134. goto enable_failed;
  135. }
  136. DEBUG15(qla_printk(KERN_INFO, ha,
  137. "Virtual port with id: %d - Enabled\n", vha->vp_idx));
  138. return 0;
  139. enable_failed:
  140. DEBUG15(qla_printk(KERN_INFO, ha,
  141. "Virtual port with id: %d - Disabled\n", vha->vp_idx));
  142. return 1;
  143. }
  144. static void
  145. qla24xx_configure_vp(scsi_qla_host_t *vha)
  146. {
  147. struct fc_vport *fc_vport;
  148. int ret;
  149. fc_vport = vha->fc_vport;
  150. DEBUG15(printk("scsi(%ld): %s: change request #3 for this host.\n",
  151. vha->host_no, __func__));
  152. ret = qla2x00_send_change_request(vha, 0x3, vha->vp_idx);
  153. if (ret != QLA_SUCCESS) {
  154. DEBUG15(qla_printk(KERN_ERR, vha->hw, "Failed to enable "
  155. "receiving of RSCN requests: 0x%x\n", ret));
  156. return;
  157. } else {
  158. /* Corresponds to SCR enabled */
  159. clear_bit(VP_SCR_NEEDED, &vha->vp_flags);
  160. }
  161. vha->flags.online = 1;
  162. if (qla24xx_configure_vhba(vha))
  163. return;
  164. atomic_set(&vha->vp_state, VP_ACTIVE);
  165. fc_vport_set_state(fc_vport, FC_VPORT_ACTIVE);
  166. }
  167. void
  168. qla2x00_alert_all_vps(struct rsp_que *rsp, uint16_t *mb)
  169. {
  170. scsi_qla_host_t *vha, *tvha;
  171. struct qla_hw_data *ha = rsp->hw;
  172. int i = 0;
  173. list_for_each_entry_safe(vha, tvha, &ha->vp_list, list) {
  174. if (vha->vp_idx) {
  175. switch (mb[0]) {
  176. case MBA_LIP_OCCURRED:
  177. case MBA_LOOP_UP:
  178. case MBA_LOOP_DOWN:
  179. case MBA_LIP_RESET:
  180. case MBA_POINT_TO_POINT:
  181. case MBA_CHG_IN_CONNECTION:
  182. case MBA_PORT_UPDATE:
  183. case MBA_RSCN_UPDATE:
  184. DEBUG15(printk("scsi(%ld)%s: Async_event for"
  185. " VP[%d], mb = 0x%x, vha=%p\n",
  186. vha->host_no, __func__, i, *mb, vha));
  187. qla2x00_async_event(vha, rsp, mb);
  188. break;
  189. }
  190. }
  191. i++;
  192. }
  193. }
  194. int
  195. qla2x00_vp_abort_isp(scsi_qla_host_t *vha)
  196. {
  197. /*
  198. * Physical port will do most of the abort and recovery work. We can
  199. * just treat it as a loop down
  200. */
  201. if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
  202. atomic_set(&vha->loop_state, LOOP_DOWN);
  203. qla2x00_mark_all_devices_lost(vha, 0);
  204. } else {
  205. if (!atomic_read(&vha->loop_down_timer))
  206. atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
  207. }
  208. /* To exclusively reset vport, we need to log it out first.*/
  209. if (!test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))
  210. qla24xx_control_vp(vha, VCE_COMMAND_DISABLE_VPS_LOGO_ALL);
  211. DEBUG15(printk("scsi(%ld): Scheduling enable of Vport %d...\n",
  212. vha->host_no, vha->vp_idx));
  213. return qla24xx_enable_vp(vha);
  214. }
  215. static int
  216. qla2x00_do_dpc_vp(scsi_qla_host_t *vha)
  217. {
  218. struct qla_hw_data *ha = vha->hw;
  219. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  220. if (test_and_clear_bit(VP_IDX_ACQUIRED, &vha->vp_flags)) {
  221. /* VP acquired. complete port configuration */
  222. if (atomic_read(&base_vha->loop_state) == LOOP_READY) {
  223. qla24xx_configure_vp(vha);
  224. } else {
  225. set_bit(VP_IDX_ACQUIRED, &vha->vp_flags);
  226. set_bit(VP_DPC_NEEDED, &base_vha->dpc_flags);
  227. }
  228. return 0;
  229. }
  230. if (test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags)) {
  231. qla2x00_update_fcports(vha);
  232. clear_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags);
  233. }
  234. if ((test_and_clear_bit(RELOGIN_NEEDED, &vha->dpc_flags)) &&
  235. !test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) &&
  236. atomic_read(&vha->loop_state) != LOOP_DOWN) {
  237. DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
  238. vha->host_no));
  239. qla2x00_relogin(vha);
  240. DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
  241. vha->host_no));
  242. }
  243. if (test_and_clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) &&
  244. (!(test_and_set_bit(RESET_ACTIVE, &vha->dpc_flags)))) {
  245. clear_bit(RESET_ACTIVE, &vha->dpc_flags);
  246. }
  247. if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
  248. if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags))) {
  249. qla2x00_loop_resync(vha);
  250. clear_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags);
  251. }
  252. }
  253. return 0;
  254. }
  255. void
  256. qla2x00_do_dpc_all_vps(scsi_qla_host_t *vha)
  257. {
  258. int ret;
  259. struct qla_hw_data *ha = vha->hw;
  260. scsi_qla_host_t *vp;
  261. struct scsi_qla_host *tvp;
  262. if (vha->vp_idx)
  263. return;
  264. if (list_empty(&ha->vp_list))
  265. return;
  266. clear_bit(VP_DPC_NEEDED, &vha->dpc_flags);
  267. list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
  268. if (vp->vp_idx)
  269. ret = qla2x00_do_dpc_vp(vp);
  270. }
  271. }
  272. int
  273. qla24xx_vport_create_req_sanity_check(struct fc_vport *fc_vport)
  274. {
  275. scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
  276. struct qla_hw_data *ha = base_vha->hw;
  277. scsi_qla_host_t *vha;
  278. uint8_t port_name[WWN_SIZE];
  279. if (fc_vport->roles != FC_PORT_ROLE_FCP_INITIATOR)
  280. return VPCERR_UNSUPPORTED;
  281. /* Check up the F/W and H/W support NPIV */
  282. if (!ha->flags.npiv_supported)
  283. return VPCERR_UNSUPPORTED;
  284. /* Check up whether npiv supported switch presented */
  285. if (!(ha->switch_cap & FLOGI_MID_SUPPORT))
  286. return VPCERR_NO_FABRIC_SUPP;
  287. /* Check up unique WWPN */
  288. u64_to_wwn(fc_vport->port_name, port_name);
  289. if (!memcmp(port_name, base_vha->port_name, WWN_SIZE))
  290. return VPCERR_BAD_WWN;
  291. vha = qla24xx_find_vhost_by_name(ha, port_name);
  292. if (vha)
  293. return VPCERR_BAD_WWN;
  294. /* Check up max-npiv-supports */
  295. if (ha->num_vhosts > ha->max_npiv_vports) {
  296. DEBUG15(printk("scsi(%ld): num_vhosts %ud is bigger than "
  297. "max_npv_vports %ud.\n", base_vha->host_no,
  298. ha->num_vhosts, ha->max_npiv_vports));
  299. return VPCERR_UNSUPPORTED;
  300. }
  301. return 0;
  302. }
  303. scsi_qla_host_t *
  304. qla24xx_create_vhost(struct fc_vport *fc_vport)
  305. {
  306. scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
  307. struct qla_hw_data *ha = base_vha->hw;
  308. scsi_qla_host_t *vha;
  309. struct scsi_host_template *sht = &qla2xxx_driver_template;
  310. struct Scsi_Host *host;
  311. vha = qla2x00_create_host(sht, ha);
  312. if (!vha) {
  313. DEBUG(printk("qla2xxx: scsi_host_alloc() failed for vport\n"));
  314. return(NULL);
  315. }
  316. host = vha->host;
  317. fc_vport->dd_data = vha;
  318. /* New host info */
  319. u64_to_wwn(fc_vport->node_name, vha->node_name);
  320. u64_to_wwn(fc_vport->port_name, vha->port_name);
  321. vha->fc_vport = fc_vport;
  322. vha->device_flags = 0;
  323. vha->vp_idx = qla24xx_allocate_vp_id(vha);
  324. if (vha->vp_idx > ha->max_npiv_vports) {
  325. DEBUG15(printk("scsi(%ld): Couldn't allocate vp_id.\n",
  326. vha->host_no));
  327. goto create_vhost_failed;
  328. }
  329. vha->mgmt_svr_loop_id = 10 + vha->vp_idx;
  330. vha->dpc_flags = 0L;
  331. set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
  332. set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
  333. /*
  334. * To fix the issue of processing a parent's RSCN for the vport before
  335. * its SCR is complete.
  336. */
  337. set_bit(VP_SCR_NEEDED, &vha->vp_flags);
  338. atomic_set(&vha->loop_state, LOOP_DOWN);
  339. atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
  340. qla2x00_start_timer(vha, qla2x00_timer, WATCH_INTERVAL);
  341. vha->req = base_vha->req;
  342. host->can_queue = base_vha->req->length + 128;
  343. host->this_id = 255;
  344. host->cmd_per_lun = 3;
  345. host->max_cmd_len = MAX_CMDSZ;
  346. host->max_channel = MAX_BUSES - 1;
  347. host->max_lun = MAX_LUNS;
  348. host->unique_id = host->host_no;
  349. host->max_id = MAX_TARGETS_2200;
  350. host->transportt = qla2xxx_transport_vport_template;
  351. DEBUG15(printk("DEBUG: detect vport hba %ld at address = %p\n",
  352. vha->host_no, vha));
  353. vha->flags.init_done = 1;
  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 que_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. return 0;
  544. }
  545. static void qla_do_work(struct work_struct *work)
  546. {
  547. struct rsp_que *rsp = container_of(work, struct rsp_que, q_work);
  548. struct scsi_qla_host *vha;
  549. vha = qla25xx_get_host(rsp);
  550. qla24xx_process_response_queue(vha, rsp);
  551. }
  552. /* create response queue */
  553. int
  554. qla25xx_create_rsp_que(struct qla_hw_data *ha, uint16_t options,
  555. uint8_t vp_idx, uint16_t rid, int req)
  556. {
  557. int ret = 0;
  558. struct rsp_que *rsp = NULL;
  559. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  560. uint16_t que_id = 0;
  561. device_reg_t __iomem *reg;
  562. rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
  563. if (rsp == NULL) {
  564. qla_printk(KERN_WARNING, ha, "could not allocate memory for"
  565. " response que\n");
  566. goto que_failed;
  567. }
  568. rsp->length = RESPONSE_ENTRY_CNT_MQ;
  569. rsp->ring = dma_alloc_coherent(&ha->pdev->dev,
  570. (rsp->length + 1) * sizeof(response_t),
  571. &rsp->dma, GFP_KERNEL);
  572. if (rsp->ring == NULL) {
  573. qla_printk(KERN_WARNING, ha,
  574. "Memory Allocation failed - response_ring\n");
  575. goto que_failed;
  576. }
  577. mutex_lock(&ha->vport_lock);
  578. que_id = find_first_zero_bit(ha->rsp_qid_map, ha->max_rsp_queues);
  579. if (que_id >= ha->max_rsp_queues) {
  580. mutex_unlock(&ha->vport_lock);
  581. qla_printk(KERN_INFO, ha, "No resources to create "
  582. "additional response queue\n");
  583. goto que_failed;
  584. }
  585. set_bit(que_id, ha->rsp_qid_map);
  586. if (ha->flags.msix_enabled)
  587. rsp->msix = &ha->msix_entries[que_id + 1];
  588. else
  589. qla_printk(KERN_WARNING, ha, "msix not enabled\n");
  590. ha->rsp_q_map[que_id] = rsp;
  591. rsp->rid = rid;
  592. rsp->vp_idx = vp_idx;
  593. rsp->hw = ha;
  594. /* Use alternate PCI bus number */
  595. if (MSB(rsp->rid))
  596. options |= BIT_4;
  597. /* Use alternate PCI devfn */
  598. if (LSB(rsp->rid))
  599. options |= BIT_5;
  600. rsp->options = options;
  601. rsp->id = que_id;
  602. reg = ISP_QUE_REG(ha, que_id);
  603. rsp->rsp_q_in = &reg->isp25mq.rsp_q_in;
  604. rsp->rsp_q_out = &reg->isp25mq.rsp_q_out;
  605. mutex_unlock(&ha->vport_lock);
  606. ret = qla25xx_request_irq(rsp);
  607. if (ret)
  608. goto que_failed;
  609. ret = qla25xx_init_rsp_que(base_vha, rsp);
  610. if (ret != QLA_SUCCESS) {
  611. qla_printk(KERN_WARNING, ha, "%s failed\n", __func__);
  612. mutex_lock(&ha->vport_lock);
  613. clear_bit(que_id, ha->rsp_qid_map);
  614. mutex_unlock(&ha->vport_lock);
  615. goto que_failed;
  616. }
  617. if (req >= 0)
  618. rsp->req = ha->req_q_map[req];
  619. else
  620. rsp->req = NULL;
  621. qla2x00_init_response_q_entries(rsp);
  622. if (rsp->hw->wq)
  623. INIT_WORK(&rsp->q_work, qla_do_work);
  624. return rsp->id;
  625. que_failed:
  626. qla25xx_free_rsp_que(base_vha, rsp);
  627. return 0;
  628. }
  629. int
  630. qla25xx_create_queues(struct scsi_qla_host *vha, uint8_t qos)
  631. {
  632. uint16_t options = 0;
  633. uint8_t ret = 0;
  634. struct qla_hw_data *ha = vha->hw;
  635. struct rsp_que *rsp;
  636. options |= BIT_1;
  637. ret = qla25xx_create_rsp_que(ha, options, vha->vp_idx, 0, -1);
  638. if (!ret) {
  639. qla_printk(KERN_WARNING, ha, "Response Que create failed\n");
  640. return ret;
  641. } else
  642. qla_printk(KERN_INFO, ha, "Response Que:%d created.\n", ret);
  643. rsp = ha->rsp_q_map[ret];
  644. options = 0;
  645. if (qos & BIT_7)
  646. options |= BIT_8;
  647. ret = qla25xx_create_req_que(ha, options, vha->vp_idx, 0, ret,
  648. qos & ~BIT_7);
  649. if (ret) {
  650. vha->req = ha->req_q_map[ret];
  651. qla_printk(KERN_INFO, ha, "Request Que:%d created.\n", ret);
  652. } else
  653. qla_printk(KERN_WARNING, ha, "Request Que create failed\n");
  654. rsp->req = ha->req_q_map[ret];
  655. return ret;
  656. }