qla_mid.c 22 KB

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