vlun.h 2.8 KB

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