efclib.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2021 Broadcom. All Rights Reserved. The term
  4. * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
  5. */
  6. /*
  7. * LIBEFC LOCKING
  8. *
  9. * The critical sections protected by the efc's spinlock are quite broad and
  10. * may be improved upon in the future. The libefc code and its locking doesn't
  11. * influence the I/O path, so excessive locking doesn't impact I/O performance.
  12. *
  13. * The strategy is to lock whenever processing a request from user driver. This
  14. * means that the entry points into the libefc library are protected by efc
  15. * lock. So all the state machine transitions are protected.
  16. */
  17. #include <linux/module.h>
  18. #include <linux/kernel.h>
  19. #include "efc.h"
  20. int efcport_init(struct efc *efc)
  21. {
  22. u32 rc = 0;
  23. spin_lock_init(&efc->lock);
  24. INIT_LIST_HEAD(&efc->vport_list);
  25. efc->hold_frames = false;
  26. spin_lock_init(&efc->pend_frames_lock);
  27. INIT_LIST_HEAD(&efc->pend_frames);
  28. /* Create Node pool */
  29. efc->node_pool = mempool_create_kmalloc_pool(EFC_MAX_REMOTE_NODES,
  30. sizeof(struct efc_node));
  31. if (!efc->node_pool) {
  32. efc_log_err(efc, "Can't allocate node pool\n");
  33. return -ENOMEM;
  34. }
  35. efc->node_dma_pool = dma_pool_create("node_dma_pool", &efc->pci->dev,
  36. NODE_SPARAMS_SIZE, 0, 0);
  37. if (!efc->node_dma_pool) {
  38. efc_log_err(efc, "Can't allocate node dma pool\n");
  39. mempool_destroy(efc->node_pool);
  40. return -ENOMEM;
  41. }
  42. efc->els_io_pool = mempool_create_kmalloc_pool(EFC_ELS_IO_POOL_SZ,
  43. sizeof(struct efc_els_io_req));
  44. if (!efc->els_io_pool) {
  45. efc_log_err(efc, "Can't allocate els io pool\n");
  46. return -ENOMEM;
  47. }
  48. return rc;
  49. }
  50. static void
  51. efc_purge_pending(struct efc *efc)
  52. {
  53. struct efc_hw_sequence *frame, *next;
  54. unsigned long flags = 0;
  55. spin_lock_irqsave(&efc->pend_frames_lock, flags);
  56. list_for_each_entry_safe(frame, next, &efc->pend_frames, list_entry) {
  57. list_del(&frame->list_entry);
  58. efc->tt.hw_seq_free(efc, frame);
  59. }
  60. spin_unlock_irqrestore(&efc->pend_frames_lock, flags);
  61. }
  62. void efcport_destroy(struct efc *efc)
  63. {
  64. efc_purge_pending(efc);
  65. mempool_destroy(efc->els_io_pool);
  66. mempool_destroy(efc->node_pool);
  67. dma_pool_destroy(efc->node_dma_pool);
  68. }