vlun.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * CXL Flash Device Driver
  4. *
  5. * Written by: Manoj N. Kumar <[email protected]>, IBM Corporation
  6. * Matthew R. Ochs <[email protected]>, IBM Corporation
  7. *
  8. * Copyright (C) 2015 IBM Corporation
  9. */
  10. #ifndef _CXLFLASH_VLUN_H
  11. #define _CXLFLASH_VLUN_H
  12. /* RHT - Resource Handle Table */
  13. #define MC_RHT_NMASK 16 /* in bits */
  14. #define MC_CHUNK_SHIFT MC_RHT_NMASK /* shift to go from LBA to chunk# */
  15. #define HIBIT (BITS_PER_LONG - 1)
  16. #define MAX_AUN_CLONE_CNT 0xFF
  17. /*
  18. * LXT - LBA Translation Table
  19. *
  20. * +-------+-------+-------+-------+-------+-------+-------+---+---+
  21. * | RLBA_BASE |LUN_IDX| P |SEL|
  22. * +-------+-------+-------+-------+-------+-------+-------+---+---+
  23. *
  24. * The LXT Entry contains the physical LBA where the chunk starts (RLBA_BASE).
  25. * AFU ORes the low order bits from the virtual LBA (offset into the chunk)
  26. * with RLBA_BASE. The result is the physical LBA to be sent to storage.
  27. * The LXT Entry also contains an index to a LUN TBL and a bitmask of which
  28. * outgoing (FC) * ports can be selected. The port select bit-mask is ANDed
  29. * with a global port select bit-mask maintained by the driver.
  30. * In addition, it has permission bits that are ANDed with the
  31. * RHT permissions to arrive at the final permissions for the chunk.
  32. *
  33. * LXT tables are allocated dynamically in groups. This is done to avoid
  34. * a malloc/free overhead each time the LXT has to grow or shrink.
  35. *
  36. * Based on the current lxt_cnt (used), it is always possible to know
  37. * how many are allocated (used+free). The number of allocated entries is
  38. * not stored anywhere.
  39. *
  40. * The LXT table is re-allocated whenever it needs to cross into another group.
  41. */
  42. #define LXT_GROUP_SIZE 8
  43. #define LXT_NUM_GROUPS(lxt_cnt) (((lxt_cnt) + 7)/8) /* alloc'ed groups */
  44. #define LXT_LUNIDX_SHIFT 8 /* LXT entry, shift for LUN index */
  45. #define LXT_PERM_SHIFT 4 /* LXT entry, shift for permission bits */
  46. struct ba_lun_info {
  47. u64 *lun_alloc_map;
  48. u32 lun_bmap_size;
  49. u32 total_aus;
  50. u64 free_aun_cnt;
  51. /* indices to be used for elevator lookup of free map */
  52. u32 free_low_idx;
  53. u32 free_curr_idx;
  54. u32 free_high_idx;
  55. u8 *aun_clone_map;
  56. };
  57. struct ba_lun {
  58. u64 lun_id;
  59. u64 wwpn;
  60. size_t lsize; /* LUN size in number of LBAs */
  61. size_t lba_size; /* LBA size in number of bytes */
  62. size_t au_size; /* Allocation Unit size in number of LBAs */
  63. struct ba_lun_info *ba_lun_handle;
  64. };
  65. /* Block Allocator */
  66. struct blka {
  67. struct ba_lun ba_lun;
  68. u64 nchunk; /* number of chunks */
  69. struct mutex mutex;
  70. };
  71. #endif /* ifndef _CXLFLASH_SUPERPIPE_H */