lpfc_mem.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2014 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/mempool.h>
  22. #include <linux/slab.h>
  23. #include <linux/pci.h>
  24. #include <linux/interrupt.h>
  25. #include <scsi/scsi_device.h>
  26. #include <scsi/scsi_transport_fc.h>
  27. #include <scsi/scsi.h>
  28. #include "lpfc_hw4.h"
  29. #include "lpfc_hw.h"
  30. #include "lpfc_sli.h"
  31. #include "lpfc_sli4.h"
  32. #include "lpfc_nl.h"
  33. #include "lpfc_disc.h"
  34. #include "lpfc_scsi.h"
  35. #include "lpfc.h"
  36. #include "lpfc_crtn.h"
  37. #include "lpfc_logmsg.h"
  38. #define LPFC_MBUF_POOL_SIZE 64 /* max elements in MBUF safety pool */
  39. #define LPFC_MEM_POOL_SIZE 64 /* max elem in non-DMA safety pool */
  40. #define LPFC_DEVICE_DATA_POOL_SIZE 64 /* max elements in device data pool */
  41. int
  42. lpfc_mem_alloc_active_rrq_pool_s4(struct lpfc_hba *phba) {
  43. size_t bytes;
  44. int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
  45. if (max_xri <= 0)
  46. return -ENOMEM;
  47. bytes = ((BITS_PER_LONG - 1 + max_xri) / BITS_PER_LONG) *
  48. sizeof(unsigned long);
  49. phba->cfg_rrq_xri_bitmap_sz = bytes;
  50. phba->active_rrq_pool = mempool_create_kmalloc_pool(LPFC_MEM_POOL_SIZE,
  51. bytes);
  52. if (!phba->active_rrq_pool)
  53. return -ENOMEM;
  54. else
  55. return 0;
  56. }
  57. /**
  58. * lpfc_mem_alloc - create and allocate all PCI and memory pools
  59. * @phba: HBA to allocate pools for
  60. *
  61. * Description: Creates and allocates PCI pools lpfc_scsi_dma_buf_pool,
  62. * lpfc_mbuf_pool, lpfc_hrb_pool. Creates and allocates kmalloc-backed mempools
  63. * for LPFC_MBOXQ_t and lpfc_nodelist. Also allocates the VPI bitmask.
  64. *
  65. * Notes: Not interrupt-safe. Must be called with no locks held. If any
  66. * allocation fails, frees all successfully allocated memory before returning.
  67. *
  68. * Returns:
  69. * 0 on success
  70. * -ENOMEM on failure (if any memory allocations fail)
  71. **/
  72. int
  73. lpfc_mem_alloc(struct lpfc_hba *phba, int align)
  74. {
  75. struct lpfc_dma_pool *pool = &phba->lpfc_mbuf_safety_pool;
  76. int i;
  77. if (phba->sli_rev == LPFC_SLI_REV4) {
  78. /* Calculate alignment */
  79. if (phba->cfg_sg_dma_buf_size < SLI4_PAGE_SIZE)
  80. i = phba->cfg_sg_dma_buf_size;
  81. else
  82. i = SLI4_PAGE_SIZE;
  83. phba->lpfc_scsi_dma_buf_pool =
  84. pci_pool_create("lpfc_scsi_dma_buf_pool",
  85. phba->pcidev,
  86. phba->cfg_sg_dma_buf_size,
  87. i,
  88. 0);
  89. } else {
  90. phba->lpfc_scsi_dma_buf_pool =
  91. pci_pool_create("lpfc_scsi_dma_buf_pool",
  92. phba->pcidev, phba->cfg_sg_dma_buf_size,
  93. align, 0);
  94. }
  95. if (!phba->lpfc_scsi_dma_buf_pool)
  96. goto fail;
  97. phba->lpfc_mbuf_pool = pci_pool_create("lpfc_mbuf_pool", phba->pcidev,
  98. LPFC_BPL_SIZE,
  99. align, 0);
  100. if (!phba->lpfc_mbuf_pool)
  101. goto fail_free_dma_buf_pool;
  102. pool->elements = kmalloc(sizeof(struct lpfc_dmabuf) *
  103. LPFC_MBUF_POOL_SIZE, GFP_KERNEL);
  104. if (!pool->elements)
  105. goto fail_free_lpfc_mbuf_pool;
  106. pool->max_count = 0;
  107. pool->current_count = 0;
  108. for ( i = 0; i < LPFC_MBUF_POOL_SIZE; i++) {
  109. pool->elements[i].virt = pci_pool_alloc(phba->lpfc_mbuf_pool,
  110. GFP_KERNEL, &pool->elements[i].phys);
  111. if (!pool->elements[i].virt)
  112. goto fail_free_mbuf_pool;
  113. pool->max_count++;
  114. pool->current_count++;
  115. }
  116. phba->mbox_mem_pool = mempool_create_kmalloc_pool(LPFC_MEM_POOL_SIZE,
  117. sizeof(LPFC_MBOXQ_t));
  118. if (!phba->mbox_mem_pool)
  119. goto fail_free_mbuf_pool;
  120. phba->nlp_mem_pool = mempool_create_kmalloc_pool(LPFC_MEM_POOL_SIZE,
  121. sizeof(struct lpfc_nodelist));
  122. if (!phba->nlp_mem_pool)
  123. goto fail_free_mbox_pool;
  124. if (phba->sli_rev == LPFC_SLI_REV4) {
  125. phba->rrq_pool =
  126. mempool_create_kmalloc_pool(LPFC_MEM_POOL_SIZE,
  127. sizeof(struct lpfc_node_rrq));
  128. if (!phba->rrq_pool)
  129. goto fail_free_nlp_mem_pool;
  130. phba->lpfc_hrb_pool = pci_pool_create("lpfc_hrb_pool",
  131. phba->pcidev,
  132. LPFC_HDR_BUF_SIZE, align, 0);
  133. if (!phba->lpfc_hrb_pool)
  134. goto fail_free_rrq_mem_pool;
  135. phba->lpfc_drb_pool = pci_pool_create("lpfc_drb_pool",
  136. phba->pcidev,
  137. LPFC_DATA_BUF_SIZE, align, 0);
  138. if (!phba->lpfc_drb_pool)
  139. goto fail_free_hrb_pool;
  140. phba->lpfc_hbq_pool = NULL;
  141. } else {
  142. phba->lpfc_hbq_pool = pci_pool_create("lpfc_hbq_pool",
  143. phba->pcidev, LPFC_BPL_SIZE, align, 0);
  144. if (!phba->lpfc_hbq_pool)
  145. goto fail_free_nlp_mem_pool;
  146. phba->lpfc_hrb_pool = NULL;
  147. phba->lpfc_drb_pool = NULL;
  148. }
  149. if (phba->cfg_EnableXLane) {
  150. phba->device_data_mem_pool = mempool_create_kmalloc_pool(
  151. LPFC_DEVICE_DATA_POOL_SIZE,
  152. sizeof(struct lpfc_device_data));
  153. if (!phba->device_data_mem_pool)
  154. goto fail_free_hrb_pool;
  155. } else {
  156. phba->device_data_mem_pool = NULL;
  157. }
  158. return 0;
  159. fail_free_hrb_pool:
  160. pci_pool_destroy(phba->lpfc_hrb_pool);
  161. phba->lpfc_hrb_pool = NULL;
  162. fail_free_rrq_mem_pool:
  163. mempool_destroy(phba->rrq_pool);
  164. phba->rrq_pool = NULL;
  165. fail_free_nlp_mem_pool:
  166. mempool_destroy(phba->nlp_mem_pool);
  167. phba->nlp_mem_pool = NULL;
  168. fail_free_mbox_pool:
  169. mempool_destroy(phba->mbox_mem_pool);
  170. phba->mbox_mem_pool = NULL;
  171. fail_free_mbuf_pool:
  172. while (i--)
  173. pci_pool_free(phba->lpfc_mbuf_pool, pool->elements[i].virt,
  174. pool->elements[i].phys);
  175. kfree(pool->elements);
  176. fail_free_lpfc_mbuf_pool:
  177. pci_pool_destroy(phba->lpfc_mbuf_pool);
  178. phba->lpfc_mbuf_pool = NULL;
  179. fail_free_dma_buf_pool:
  180. pci_pool_destroy(phba->lpfc_scsi_dma_buf_pool);
  181. phba->lpfc_scsi_dma_buf_pool = NULL;
  182. fail:
  183. return -ENOMEM;
  184. }
  185. /**
  186. * lpfc_mem_free - Frees memory allocated by lpfc_mem_alloc
  187. * @phba: HBA to free memory for
  188. *
  189. * Description: Free the memory allocated by lpfc_mem_alloc routine. This
  190. * routine is a the counterpart of lpfc_mem_alloc.
  191. *
  192. * Returns: None
  193. **/
  194. void
  195. lpfc_mem_free(struct lpfc_hba *phba)
  196. {
  197. int i;
  198. struct lpfc_dma_pool *pool = &phba->lpfc_mbuf_safety_pool;
  199. struct lpfc_device_data *device_data;
  200. /* Free HBQ pools */
  201. lpfc_sli_hbqbuf_free_all(phba);
  202. if (phba->lpfc_drb_pool)
  203. pci_pool_destroy(phba->lpfc_drb_pool);
  204. phba->lpfc_drb_pool = NULL;
  205. if (phba->lpfc_hrb_pool)
  206. pci_pool_destroy(phba->lpfc_hrb_pool);
  207. phba->lpfc_hrb_pool = NULL;
  208. if (phba->lpfc_hbq_pool)
  209. pci_pool_destroy(phba->lpfc_hbq_pool);
  210. phba->lpfc_hbq_pool = NULL;
  211. if (phba->rrq_pool)
  212. mempool_destroy(phba->rrq_pool);
  213. phba->rrq_pool = NULL;
  214. /* Free NLP memory pool */
  215. mempool_destroy(phba->nlp_mem_pool);
  216. phba->nlp_mem_pool = NULL;
  217. if (phba->sli_rev == LPFC_SLI_REV4 && phba->active_rrq_pool) {
  218. mempool_destroy(phba->active_rrq_pool);
  219. phba->active_rrq_pool = NULL;
  220. }
  221. /* Free mbox memory pool */
  222. mempool_destroy(phba->mbox_mem_pool);
  223. phba->mbox_mem_pool = NULL;
  224. /* Free MBUF memory pool */
  225. for (i = 0; i < pool->current_count; i++)
  226. pci_pool_free(phba->lpfc_mbuf_pool, pool->elements[i].virt,
  227. pool->elements[i].phys);
  228. kfree(pool->elements);
  229. pci_pool_destroy(phba->lpfc_mbuf_pool);
  230. phba->lpfc_mbuf_pool = NULL;
  231. /* Free DMA buffer memory pool */
  232. pci_pool_destroy(phba->lpfc_scsi_dma_buf_pool);
  233. phba->lpfc_scsi_dma_buf_pool = NULL;
  234. /* Free Device Data memory pool */
  235. if (phba->device_data_mem_pool) {
  236. /* Ensure all objects have been returned to the pool */
  237. while (!list_empty(&phba->luns)) {
  238. device_data = list_first_entry(&phba->luns,
  239. struct lpfc_device_data,
  240. listentry);
  241. list_del(&device_data->listentry);
  242. mempool_free(device_data, phba->device_data_mem_pool);
  243. }
  244. mempool_destroy(phba->device_data_mem_pool);
  245. }
  246. phba->device_data_mem_pool = NULL;
  247. return;
  248. }
  249. /**
  250. * lpfc_mem_free_all - Frees all PCI and driver memory
  251. * @phba: HBA to free memory for
  252. *
  253. * Description: Free memory from PCI and driver memory pools and also those
  254. * used : lpfc_scsi_dma_buf_pool, lpfc_mbuf_pool, lpfc_hrb_pool. Frees
  255. * kmalloc-backed mempools for LPFC_MBOXQ_t and lpfc_nodelist. Also frees
  256. * the VPI bitmask.
  257. *
  258. * Returns: None
  259. **/
  260. void
  261. lpfc_mem_free_all(struct lpfc_hba *phba)
  262. {
  263. struct lpfc_sli *psli = &phba->sli;
  264. LPFC_MBOXQ_t *mbox, *next_mbox;
  265. struct lpfc_dmabuf *mp;
  266. /* Free memory used in mailbox queue back to mailbox memory pool */
  267. list_for_each_entry_safe(mbox, next_mbox, &psli->mboxq, list) {
  268. mp = (struct lpfc_dmabuf *) (mbox->context1);
  269. if (mp) {
  270. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  271. kfree(mp);
  272. }
  273. list_del(&mbox->list);
  274. mempool_free(mbox, phba->mbox_mem_pool);
  275. }
  276. /* Free memory used in mailbox cmpl list back to mailbox memory pool */
  277. list_for_each_entry_safe(mbox, next_mbox, &psli->mboxq_cmpl, list) {
  278. mp = (struct lpfc_dmabuf *) (mbox->context1);
  279. if (mp) {
  280. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  281. kfree(mp);
  282. }
  283. list_del(&mbox->list);
  284. mempool_free(mbox, phba->mbox_mem_pool);
  285. }
  286. /* Free the active mailbox command back to the mailbox memory pool */
  287. spin_lock_irq(&phba->hbalock);
  288. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  289. spin_unlock_irq(&phba->hbalock);
  290. if (psli->mbox_active) {
  291. mbox = psli->mbox_active;
  292. mp = (struct lpfc_dmabuf *) (mbox->context1);
  293. if (mp) {
  294. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  295. kfree(mp);
  296. }
  297. mempool_free(mbox, phba->mbox_mem_pool);
  298. psli->mbox_active = NULL;
  299. }
  300. /* Free and destroy all the allocated memory pools */
  301. lpfc_mem_free(phba);
  302. /* Free the iocb lookup array */
  303. kfree(psli->iocbq_lookup);
  304. psli->iocbq_lookup = NULL;
  305. return;
  306. }
  307. /**
  308. * lpfc_mbuf_alloc - Allocate an mbuf from the lpfc_mbuf_pool PCI pool
  309. * @phba: HBA which owns the pool to allocate from
  310. * @mem_flags: indicates if this is a priority (MEM_PRI) allocation
  311. * @handle: used to return the DMA-mapped address of the mbuf
  312. *
  313. * Description: Allocates a DMA-mapped buffer from the lpfc_mbuf_pool PCI pool.
  314. * Allocates from generic pci_pool_alloc function first and if that fails and
  315. * mem_flags has MEM_PRI set (the only defined flag), returns an mbuf from the
  316. * HBA's pool.
  317. *
  318. * Notes: Not interrupt-safe. Must be called with no locks held. Takes
  319. * phba->hbalock.
  320. *
  321. * Returns:
  322. * pointer to the allocated mbuf on success
  323. * NULL on failure
  324. **/
  325. void *
  326. lpfc_mbuf_alloc(struct lpfc_hba *phba, int mem_flags, dma_addr_t *handle)
  327. {
  328. struct lpfc_dma_pool *pool = &phba->lpfc_mbuf_safety_pool;
  329. unsigned long iflags;
  330. void *ret;
  331. ret = pci_pool_alloc(phba->lpfc_mbuf_pool, GFP_KERNEL, handle);
  332. spin_lock_irqsave(&phba->hbalock, iflags);
  333. if (!ret && (mem_flags & MEM_PRI) && pool->current_count) {
  334. pool->current_count--;
  335. ret = pool->elements[pool->current_count].virt;
  336. *handle = pool->elements[pool->current_count].phys;
  337. }
  338. spin_unlock_irqrestore(&phba->hbalock, iflags);
  339. return ret;
  340. }
  341. /**
  342. * __lpfc_mbuf_free - Free an mbuf from the lpfc_mbuf_pool PCI pool (locked)
  343. * @phba: HBA which owns the pool to return to
  344. * @virt: mbuf to free
  345. * @dma: the DMA-mapped address of the lpfc_mbuf_pool to be freed
  346. *
  347. * Description: Returns an mbuf lpfc_mbuf_pool to the lpfc_mbuf_safety_pool if
  348. * it is below its max_count, frees the mbuf otherwise.
  349. *
  350. * Notes: Must be called with phba->hbalock held to synchronize access to
  351. * lpfc_mbuf_safety_pool.
  352. *
  353. * Returns: None
  354. **/
  355. void
  356. __lpfc_mbuf_free(struct lpfc_hba * phba, void *virt, dma_addr_t dma)
  357. {
  358. struct lpfc_dma_pool *pool = &phba->lpfc_mbuf_safety_pool;
  359. if (pool->current_count < pool->max_count) {
  360. pool->elements[pool->current_count].virt = virt;
  361. pool->elements[pool->current_count].phys = dma;
  362. pool->current_count++;
  363. } else {
  364. pci_pool_free(phba->lpfc_mbuf_pool, virt, dma);
  365. }
  366. return;
  367. }
  368. /**
  369. * lpfc_mbuf_free - Free an mbuf from the lpfc_mbuf_pool PCI pool (unlocked)
  370. * @phba: HBA which owns the pool to return to
  371. * @virt: mbuf to free
  372. * @dma: the DMA-mapped address of the lpfc_mbuf_pool to be freed
  373. *
  374. * Description: Returns an mbuf lpfc_mbuf_pool to the lpfc_mbuf_safety_pool if
  375. * it is below its max_count, frees the mbuf otherwise.
  376. *
  377. * Notes: Takes phba->hbalock. Can be called with or without other locks held.
  378. *
  379. * Returns: None
  380. **/
  381. void
  382. lpfc_mbuf_free(struct lpfc_hba * phba, void *virt, dma_addr_t dma)
  383. {
  384. unsigned long iflags;
  385. spin_lock_irqsave(&phba->hbalock, iflags);
  386. __lpfc_mbuf_free(phba, virt, dma);
  387. spin_unlock_irqrestore(&phba->hbalock, iflags);
  388. return;
  389. }
  390. /**
  391. * lpfc_els_hbq_alloc - Allocate an HBQ buffer
  392. * @phba: HBA to allocate HBQ buffer for
  393. *
  394. * Description: Allocates a DMA-mapped HBQ buffer from the lpfc_hrb_pool PCI
  395. * pool along a non-DMA-mapped container for it.
  396. *
  397. * Notes: Not interrupt-safe. Must be called with no locks held.
  398. *
  399. * Returns:
  400. * pointer to HBQ on success
  401. * NULL on failure
  402. **/
  403. struct hbq_dmabuf *
  404. lpfc_els_hbq_alloc(struct lpfc_hba *phba)
  405. {
  406. struct hbq_dmabuf *hbqbp;
  407. hbqbp = kzalloc(sizeof(struct hbq_dmabuf), GFP_KERNEL);
  408. if (!hbqbp)
  409. return NULL;
  410. hbqbp->dbuf.virt = pci_pool_alloc(phba->lpfc_hbq_pool, GFP_KERNEL,
  411. &hbqbp->dbuf.phys);
  412. if (!hbqbp->dbuf.virt) {
  413. kfree(hbqbp);
  414. return NULL;
  415. }
  416. hbqbp->size = LPFC_BPL_SIZE;
  417. return hbqbp;
  418. }
  419. /**
  420. * lpfc_els_hbq_free - Frees an HBQ buffer allocated with lpfc_els_hbq_alloc
  421. * @phba: HBA buffer was allocated for
  422. * @hbqbp: HBQ container returned by lpfc_els_hbq_alloc
  423. *
  424. * Description: Frees both the container and the DMA-mapped buffer returned by
  425. * lpfc_els_hbq_alloc.
  426. *
  427. * Notes: Can be called with or without locks held.
  428. *
  429. * Returns: None
  430. **/
  431. void
  432. lpfc_els_hbq_free(struct lpfc_hba *phba, struct hbq_dmabuf *hbqbp)
  433. {
  434. pci_pool_free(phba->lpfc_hbq_pool, hbqbp->dbuf.virt, hbqbp->dbuf.phys);
  435. kfree(hbqbp);
  436. return;
  437. }
  438. /**
  439. * lpfc_sli4_rb_alloc - Allocate an SLI4 Receive buffer
  440. * @phba: HBA to allocate a receive buffer for
  441. *
  442. * Description: Allocates a DMA-mapped receive buffer from the lpfc_hrb_pool PCI
  443. * pool along a non-DMA-mapped container for it.
  444. *
  445. * Notes: Not interrupt-safe. Must be called with no locks held.
  446. *
  447. * Returns:
  448. * pointer to HBQ on success
  449. * NULL on failure
  450. **/
  451. struct hbq_dmabuf *
  452. lpfc_sli4_rb_alloc(struct lpfc_hba *phba)
  453. {
  454. struct hbq_dmabuf *dma_buf;
  455. dma_buf = kzalloc(sizeof(struct hbq_dmabuf), GFP_KERNEL);
  456. if (!dma_buf)
  457. return NULL;
  458. dma_buf->hbuf.virt = pci_pool_alloc(phba->lpfc_hrb_pool, GFP_KERNEL,
  459. &dma_buf->hbuf.phys);
  460. if (!dma_buf->hbuf.virt) {
  461. kfree(dma_buf);
  462. return NULL;
  463. }
  464. dma_buf->dbuf.virt = pci_pool_alloc(phba->lpfc_drb_pool, GFP_KERNEL,
  465. &dma_buf->dbuf.phys);
  466. if (!dma_buf->dbuf.virt) {
  467. pci_pool_free(phba->lpfc_hrb_pool, dma_buf->hbuf.virt,
  468. dma_buf->hbuf.phys);
  469. kfree(dma_buf);
  470. return NULL;
  471. }
  472. dma_buf->size = LPFC_BPL_SIZE;
  473. return dma_buf;
  474. }
  475. /**
  476. * lpfc_sli4_rb_free - Frees a receive buffer
  477. * @phba: HBA buffer was allocated for
  478. * @dmab: DMA Buffer container returned by lpfc_sli4_hbq_alloc
  479. *
  480. * Description: Frees both the container and the DMA-mapped buffers returned by
  481. * lpfc_sli4_rb_alloc.
  482. *
  483. * Notes: Can be called with or without locks held.
  484. *
  485. * Returns: None
  486. **/
  487. void
  488. lpfc_sli4_rb_free(struct lpfc_hba *phba, struct hbq_dmabuf *dmab)
  489. {
  490. pci_pool_free(phba->lpfc_hrb_pool, dmab->hbuf.virt, dmab->hbuf.phys);
  491. pci_pool_free(phba->lpfc_drb_pool, dmab->dbuf.virt, dmab->dbuf.phys);
  492. kfree(dmab);
  493. return;
  494. }
  495. /**
  496. * lpfc_in_buf_free - Free a DMA buffer
  497. * @phba: HBA buffer is associated with
  498. * @mp: Buffer to free
  499. *
  500. * Description: Frees the given DMA buffer in the appropriate way given if the
  501. * HBA is running in SLI3 mode with HBQs enabled.
  502. *
  503. * Notes: Takes phba->hbalock. Can be called with or without other locks held.
  504. *
  505. * Returns: None
  506. **/
  507. void
  508. lpfc_in_buf_free(struct lpfc_hba *phba, struct lpfc_dmabuf *mp)
  509. {
  510. struct hbq_dmabuf *hbq_entry;
  511. unsigned long flags;
  512. if (!mp)
  513. return;
  514. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  515. /* Check whether HBQ is still in use */
  516. spin_lock_irqsave(&phba->hbalock, flags);
  517. if (!phba->hbq_in_use) {
  518. spin_unlock_irqrestore(&phba->hbalock, flags);
  519. return;
  520. }
  521. hbq_entry = container_of(mp, struct hbq_dmabuf, dbuf);
  522. list_del(&hbq_entry->dbuf.list);
  523. if (hbq_entry->tag == -1) {
  524. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  525. (phba, hbq_entry);
  526. } else {
  527. lpfc_sli_free_hbq(phba, hbq_entry);
  528. }
  529. spin_unlock_irqrestore(&phba->hbalock, flags);
  530. } else {
  531. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  532. kfree(mp);
  533. }
  534. return;
  535. }