qla_mid.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  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. /* Locate matching device in database. */
  64. list_for_each_entry(vha, &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;
  170. struct qla_hw_data *ha = rsp->hw;
  171. int i = 0;
  172. list_for_each_entry(vha, &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 (test_and_clear_bit(VP_IDX_ACQUIRED, &vha->vp_flags)) {
  220. /* VP acquired. complete port configuration */
  221. if (atomic_read(&base_vha->loop_state) == LOOP_READY) {
  222. qla24xx_configure_vp(vha);
  223. } else {
  224. set_bit(VP_IDX_ACQUIRED, &vha->vp_flags);
  225. set_bit(VP_DPC_NEEDED, &base_vha->dpc_flags);
  226. }
  227. return 0;
  228. }
  229. if (test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags)) {
  230. qla2x00_update_fcports(vha);
  231. clear_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags);
  232. }
  233. if ((test_and_clear_bit(RELOGIN_NEEDED, &vha->dpc_flags)) &&
  234. !test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) &&
  235. atomic_read(&vha->loop_state) != LOOP_DOWN) {
  236. DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
  237. vha->host_no));
  238. qla2x00_relogin(vha);
  239. DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
  240. vha->host_no));
  241. }
  242. if (test_and_clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) &&
  243. (!(test_and_set_bit(RESET_ACTIVE, &vha->dpc_flags)))) {
  244. clear_bit(RESET_ACTIVE, &vha->dpc_flags);
  245. }
  246. if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
  247. if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags))) {
  248. qla2x00_loop_resync(vha);
  249. clear_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags);
  250. }
  251. }
  252. return 0;
  253. }
  254. void
  255. qla2x00_do_dpc_all_vps(scsi_qla_host_t *vha)
  256. {
  257. int ret;
  258. struct qla_hw_data *ha = vha->hw;
  259. scsi_qla_host_t *vp;
  260. if (vha->vp_idx)
  261. return;
  262. if (list_empty(&ha->vp_list))
  263. return;
  264. clear_bit(VP_DPC_NEEDED, &vha->dpc_flags);
  265. list_for_each_entry(vp, &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 = &qla24xx_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. set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
  330. set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
  331. /*
  332. * To fix the issue of processing a parent's RSCN for the vport before
  333. * its SCR is complete.
  334. */
  335. set_bit(VP_SCR_NEEDED, &vha->vp_flags);
  336. atomic_set(&vha->loop_state, LOOP_DOWN);
  337. atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
  338. qla2x00_start_timer(vha, qla2x00_timer, WATCH_INTERVAL);
  339. memset(vha->req_ques, 0, sizeof(vha->req_ques) * QLA_MAX_HOST_QUES);
  340. vha->req_ques[0] = ha->req_q_map[0]->id;
  341. host->can_queue = ha->req_q_map[0]->length + 128;
  342. host->this_id = 255;
  343. host->cmd_per_lun = 3;
  344. host->max_cmd_len = MAX_CMDSZ;
  345. host->max_channel = MAX_BUSES - 1;
  346. host->max_lun = MAX_LUNS;
  347. host->unique_id = host->host_no;
  348. host->max_id = MAX_TARGETS_2200;
  349. host->transportt = qla2xxx_transport_vport_template;
  350. DEBUG15(printk("DEBUG: detect vport hba %ld at address = %p\n",
  351. vha->host_no, vha));
  352. vha->flags.init_done = 1;
  353. return vha;
  354. create_vhost_failed:
  355. return NULL;
  356. }
  357. static void
  358. qla25xx_free_req_que(struct scsi_qla_host *vha, struct req_que *req)
  359. {
  360. struct qla_hw_data *ha = vha->hw;
  361. uint16_t que_id = req->id;
  362. dma_free_coherent(&ha->pdev->dev, (req->length + 1) *
  363. sizeof(request_t), req->ring, req->dma);
  364. req->ring = NULL;
  365. req->dma = 0;
  366. if (que_id) {
  367. ha->req_q_map[que_id] = NULL;
  368. mutex_lock(&ha->vport_lock);
  369. clear_bit(que_id, ha->req_qid_map);
  370. mutex_unlock(&ha->vport_lock);
  371. }
  372. kfree(req);
  373. req = NULL;
  374. }
  375. static void
  376. qla25xx_free_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
  377. {
  378. struct qla_hw_data *ha = vha->hw;
  379. uint16_t que_id = rsp->id;
  380. if (rsp->msix && rsp->msix->have_irq) {
  381. free_irq(rsp->msix->vector, rsp);
  382. rsp->msix->have_irq = 0;
  383. rsp->msix->rsp = NULL;
  384. }
  385. dma_free_coherent(&ha->pdev->dev, (rsp->length + 1) *
  386. sizeof(response_t), rsp->ring, rsp->dma);
  387. rsp->ring = NULL;
  388. rsp->dma = 0;
  389. if (que_id) {
  390. ha->rsp_q_map[que_id] = NULL;
  391. mutex_lock(&ha->vport_lock);
  392. clear_bit(que_id, ha->rsp_qid_map);
  393. mutex_unlock(&ha->vport_lock);
  394. }
  395. kfree(rsp);
  396. rsp = NULL;
  397. }
  398. int
  399. qla25xx_delete_req_que(struct scsi_qla_host *vha, struct req_que *req)
  400. {
  401. int ret = -1;
  402. if (req) {
  403. req->options |= BIT_0;
  404. ret = qla25xx_init_req_que(vha, req, req->options);
  405. }
  406. if (ret == QLA_SUCCESS)
  407. qla25xx_free_req_que(vha, req);
  408. return ret;
  409. }
  410. int
  411. qla25xx_delete_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
  412. {
  413. int ret = -1;
  414. if (rsp) {
  415. rsp->options |= BIT_0;
  416. ret = qla25xx_init_rsp_que(vha, rsp, rsp->options);
  417. }
  418. if (ret == QLA_SUCCESS)
  419. qla25xx_free_rsp_que(vha, rsp);
  420. return ret;
  421. }
  422. int qla25xx_update_req_que(struct scsi_qla_host *vha, uint8_t que, uint8_t qos)
  423. {
  424. int ret = 0;
  425. struct qla_hw_data *ha = vha->hw;
  426. struct req_que *req = ha->req_q_map[que];
  427. req->options |= BIT_3;
  428. req->qos = qos;
  429. ret = qla25xx_init_req_que(vha, req, req->options);
  430. if (ret != QLA_SUCCESS)
  431. DEBUG2_17(printk(KERN_WARNING "%s failed\n", __func__));
  432. /* restore options bit */
  433. req->options &= ~BIT_3;
  434. return ret;
  435. }
  436. /* Delete all queues for a given vhost */
  437. int
  438. qla25xx_delete_queues(struct scsi_qla_host *vha, uint8_t que_no)
  439. {
  440. int cnt, ret = 0;
  441. struct req_que *req = NULL;
  442. struct rsp_que *rsp = NULL;
  443. struct qla_hw_data *ha = vha->hw;
  444. if (que_no) {
  445. /* Delete request queue */
  446. req = ha->req_q_map[que_no];
  447. if (req) {
  448. rsp = req->rsp;
  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", req->id);
  453. return ret;
  454. }
  455. /* Delete associated response queue */
  456. if (rsp) {
  457. ret = qla25xx_delete_rsp_que(vha, rsp);
  458. if (ret != QLA_SUCCESS) {
  459. qla_printk(KERN_WARNING, ha,
  460. "Couldn't delete rsp que %d\n",
  461. rsp->id);
  462. return ret;
  463. }
  464. }
  465. }
  466. } else { /* delete all queues of this host */
  467. for (cnt = 0; cnt < QLA_MAX_HOST_QUES; cnt++) {
  468. /* Delete request queues */
  469. req = ha->req_q_map[vha->req_ques[cnt]];
  470. if (req && req->id) {
  471. rsp = req->rsp;
  472. ret = qla25xx_delete_req_que(vha, req);
  473. if (ret != QLA_SUCCESS) {
  474. qla_printk(KERN_WARNING, ha,
  475. "Couldn't delete req que %d\n",
  476. vha->req_ques[cnt]);
  477. return ret;
  478. }
  479. vha->req_ques[cnt] = ha->req_q_map[0]->id;
  480. /* Delete associated response queue */
  481. if (rsp && rsp->id) {
  482. ret = qla25xx_delete_rsp_que(vha, rsp);
  483. if (ret != QLA_SUCCESS) {
  484. qla_printk(KERN_WARNING, ha,
  485. "Couldn't delete rsp que %d\n",
  486. rsp->id);
  487. return ret;
  488. }
  489. }
  490. }
  491. }
  492. }
  493. qla_printk(KERN_INFO, ha, "Queues deleted for vport:%d\n",
  494. vha->vp_idx);
  495. return ret;
  496. }
  497. int
  498. qla25xx_create_req_que(struct qla_hw_data *ha, uint16_t options,
  499. uint8_t vp_idx, uint16_t rid, uint8_t rsp_que, uint8_t qos)
  500. {
  501. int ret = 0;
  502. struct req_que *req = NULL;
  503. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  504. uint16_t que_id = 0;
  505. req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
  506. if (req == NULL) {
  507. qla_printk(KERN_WARNING, ha, "could not allocate memory"
  508. "for request que\n");
  509. goto que_failed;
  510. }
  511. req->length = REQUEST_ENTRY_CNT_24XX;
  512. req->ring = dma_alloc_coherent(&ha->pdev->dev,
  513. (req->length + 1) * sizeof(request_t),
  514. &req->dma, GFP_KERNEL);
  515. if (req->ring == NULL) {
  516. qla_printk(KERN_WARNING, ha,
  517. "Memory Allocation failed - request_ring\n");
  518. goto que_failed;
  519. }
  520. mutex_lock(&ha->vport_lock);
  521. que_id = find_first_zero_bit(ha->req_qid_map, ha->max_queues);
  522. if (que_id >= ha->max_queues) {
  523. mutex_unlock(&ha->vport_lock);
  524. qla_printk(KERN_INFO, ha, "No resources to create "
  525. "additional request queue\n");
  526. goto que_failed;
  527. }
  528. set_bit(que_id, ha->req_qid_map);
  529. ha->req_q_map[que_id] = req;
  530. req->rid = rid;
  531. req->vp_idx = vp_idx;
  532. req->qos = qos;
  533. if (ha->rsp_q_map[rsp_que])
  534. req->rsp = ha->rsp_q_map[rsp_que];
  535. /* Use alternate PCI bus number */
  536. if (MSB(req->rid))
  537. options |= BIT_4;
  538. /* Use alternate PCI devfn */
  539. if (LSB(req->rid))
  540. options |= BIT_5;
  541. req->options = options;
  542. req->ring_ptr = req->ring;
  543. req->ring_index = 0;
  544. req->cnt = req->length;
  545. req->id = que_id;
  546. mutex_unlock(&ha->vport_lock);
  547. ret = qla25xx_init_req_que(base_vha, req, options);
  548. if (ret != QLA_SUCCESS) {
  549. qla_printk(KERN_WARNING, ha, "%s failed\n", __func__);
  550. mutex_lock(&ha->vport_lock);
  551. clear_bit(que_id, ha->req_qid_map);
  552. mutex_unlock(&ha->vport_lock);
  553. goto que_failed;
  554. }
  555. return req->id;
  556. que_failed:
  557. qla25xx_free_req_que(base_vha, req);
  558. return 0;
  559. }
  560. /* create response queue */
  561. int
  562. qla25xx_create_rsp_que(struct qla_hw_data *ha, uint16_t options,
  563. uint8_t vp_idx, uint16_t rid)
  564. {
  565. int ret = 0;
  566. struct rsp_que *rsp = NULL;
  567. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  568. uint16_t que_id = 0;;
  569. rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
  570. if (rsp == NULL) {
  571. qla_printk(KERN_WARNING, ha, "could not allocate memory for"
  572. " response que\n");
  573. goto que_failed;
  574. }
  575. rsp->length = RESPONSE_ENTRY_CNT_2300;
  576. rsp->ring = dma_alloc_coherent(&ha->pdev->dev,
  577. (rsp->length + 1) * sizeof(response_t),
  578. &rsp->dma, GFP_KERNEL);
  579. if (rsp->ring == NULL) {
  580. qla_printk(KERN_WARNING, ha,
  581. "Memory Allocation failed - response_ring\n");
  582. goto que_failed;
  583. }
  584. mutex_lock(&ha->vport_lock);
  585. que_id = find_first_zero_bit(ha->rsp_qid_map, ha->max_queues);
  586. if (que_id >= ha->max_queues) {
  587. mutex_unlock(&ha->vport_lock);
  588. qla_printk(KERN_INFO, ha, "No resources to create "
  589. "additional response queue\n");
  590. goto que_failed;
  591. }
  592. set_bit(que_id, ha->rsp_qid_map);
  593. if (ha->flags.msix_enabled)
  594. rsp->msix = &ha->msix_entries[que_id + 1];
  595. else
  596. qla_printk(KERN_WARNING, ha, "msix not enabled\n");
  597. ha->rsp_q_map[que_id] = rsp;
  598. rsp->rid = rid;
  599. rsp->vp_idx = vp_idx;
  600. rsp->hw = ha;
  601. /* Use alternate PCI bus number */
  602. if (MSB(rsp->rid))
  603. options |= BIT_4;
  604. /* Use alternate PCI devfn */
  605. if (LSB(rsp->rid))
  606. options |= BIT_5;
  607. rsp->options = options;
  608. rsp->ring_ptr = rsp->ring;
  609. rsp->ring_index = 0;
  610. rsp->id = que_id;
  611. mutex_unlock(&ha->vport_lock);
  612. ret = qla25xx_request_irq(rsp);
  613. if (ret)
  614. goto que_failed;
  615. ret = qla25xx_init_rsp_que(base_vha, rsp, options);
  616. if (ret != QLA_SUCCESS) {
  617. qla_printk(KERN_WARNING, ha, "%s failed\n", __func__);
  618. mutex_lock(&ha->vport_lock);
  619. clear_bit(que_id, ha->rsp_qid_map);
  620. mutex_unlock(&ha->vport_lock);
  621. goto que_failed;
  622. }
  623. qla2x00_init_response_q_entries(rsp);
  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. options |= BIT_1;
  636. ret = qla25xx_create_rsp_que(ha, options, vha->vp_idx, 0);
  637. if (!ret) {
  638. qla_printk(KERN_WARNING, ha, "Response Que create failed\n");
  639. return ret;
  640. } else
  641. qla_printk(KERN_INFO, ha, "Response Que:%d created.\n", ret);
  642. options = 0;
  643. if (qos & BIT_7)
  644. options |= BIT_8;
  645. ret = qla25xx_create_req_que(ha, options, vha->vp_idx, 0, ret,
  646. qos & ~BIT_7);
  647. if (ret) {
  648. vha->req_ques[0] = ret;
  649. qla_printk(KERN_INFO, ha, "Request Que:%d created.\n", ret);
  650. } else
  651. qla_printk(KERN_WARNING, ha, "Request Que create failed\n");
  652. return ret;
  653. }