qla_mid.c 21 KB

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