qla_mid.c 21 KB

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