superpipe.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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_SUPERPIPE_H
  11. #define _CXLFLASH_SUPERPIPE_H
  12. extern struct cxlflash_global global;
  13. /*
  14. * Terminology: use afu (and not adapter) to refer to the HW.
  15. * Adapter is the entire slot and includes PSL out of which
  16. * only the AFU is visible to user space.
  17. */
  18. /* Chunk size parms: note sislite minimum chunk size is
  19. * 0x10000 LBAs corresponding to a NMASK or 16.
  20. */
  21. #define MC_CHUNK_SIZE (1 << MC_RHT_NMASK) /* in LBAs */
  22. #define CMD_TIMEOUT 30 /* 30 secs */
  23. #define CMD_RETRIES 5 /* 5 retries for scsi_execute */
  24. #define MAX_SECTOR_UNIT 512 /* max_sector is in 512 byte multiples */
  25. enum lun_mode {
  26. MODE_NONE = 0,
  27. MODE_VIRTUAL,
  28. MODE_PHYSICAL
  29. };
  30. /* Global (entire driver, spans adapters) lun_info structure */
  31. struct glun_info {
  32. u64 max_lba; /* from read cap(16) */
  33. u32 blk_len; /* from read cap(16) */
  34. enum lun_mode mode; /* NONE, VIRTUAL, PHYSICAL */
  35. int users; /* Number of users w/ references to LUN */
  36. u8 wwid[16];
  37. struct mutex mutex;
  38. struct blka blka;
  39. struct list_head list;
  40. };
  41. /* Local (per-adapter) lun_info structure */
  42. struct llun_info {
  43. u64 lun_id[MAX_FC_PORTS]; /* from REPORT_LUNS */
  44. u32 lun_index; /* Index in the LUN table */
  45. u32 host_no; /* host_no from Scsi_host */
  46. u32 port_sel; /* What port to use for this LUN */
  47. bool in_table; /* Whether a LUN table entry was created */
  48. u8 wwid[16]; /* Keep a duplicate copy here? */
  49. struct glun_info *parent; /* Pointer to entry in global LUN structure */
  50. struct scsi_device *sdev;
  51. struct list_head list;
  52. };
  53. struct lun_access {
  54. struct llun_info *lli;
  55. struct scsi_device *sdev;
  56. struct list_head list;
  57. };
  58. enum ctx_ctrl {
  59. CTX_CTRL_CLONE = (1 << 1),
  60. CTX_CTRL_ERR = (1 << 2),
  61. CTX_CTRL_ERR_FALLBACK = (1 << 3),
  62. CTX_CTRL_NOPID = (1 << 4),
  63. CTX_CTRL_FILE = (1 << 5)
  64. };
  65. #define ENCODE_CTXID(_ctx, _id) (((((u64)_ctx) & 0xFFFFFFFF0ULL) << 28) | _id)
  66. #define DECODE_CTXID(_val) (_val & 0xFFFFFFFF)
  67. struct ctx_info {
  68. struct sisl_ctrl_map __iomem *ctrl_map; /* initialized at startup */
  69. struct sisl_rht_entry *rht_start; /* 1 page (req'd for alignment),
  70. * alloc/free on attach/detach
  71. */
  72. u32 rht_out; /* Number of checked out RHT entries */
  73. u32 rht_perms; /* User-defined permissions for RHT entries */
  74. struct llun_info **rht_lun; /* Mapping of RHT entries to LUNs */
  75. u8 *rht_needs_ws; /* User-desired write-same function per RHTE */
  76. u64 ctxid;
  77. u64 irqs; /* Number of interrupts requested for context */
  78. pid_t pid;
  79. bool initialized;
  80. bool unavail;
  81. bool err_recovery_active;
  82. struct mutex mutex; /* Context protection */
  83. struct kref kref;
  84. void *ctx;
  85. struct cxlflash_cfg *cfg;
  86. struct list_head luns; /* LUNs attached to this context */
  87. const struct vm_operations_struct *cxl_mmap_vmops;
  88. struct file *file;
  89. struct list_head list; /* Link contexts in error recovery */
  90. };
  91. struct cxlflash_global {
  92. struct mutex mutex;
  93. struct list_head gluns;/* list of glun_info structs */
  94. struct page *err_page; /* One page of all 0xF for error notification */
  95. };
  96. int cxlflash_vlun_resize(struct scsi_device *sdev,
  97. struct dk_cxlflash_resize *resize);
  98. int _cxlflash_vlun_resize(struct scsi_device *sdev, struct ctx_info *ctxi,
  99. struct dk_cxlflash_resize *resize);
  100. int cxlflash_disk_release(struct scsi_device *sdev,
  101. struct dk_cxlflash_release *release);
  102. int _cxlflash_disk_release(struct scsi_device *sdev, struct ctx_info *ctxi,
  103. struct dk_cxlflash_release *release);
  104. int cxlflash_disk_clone(struct scsi_device *sdev,
  105. struct dk_cxlflash_clone *clone);
  106. int cxlflash_disk_virtual_open(struct scsi_device *sdev, void *arg);
  107. int cxlflash_lun_attach(struct glun_info *gli, enum lun_mode mode, bool locked);
  108. void cxlflash_lun_detach(struct glun_info *gli);
  109. struct ctx_info *get_context(struct cxlflash_cfg *cfg, u64 rctxit, void *arg,
  110. enum ctx_ctrl ctrl);
  111. void put_context(struct ctx_info *ctxi);
  112. struct sisl_rht_entry *get_rhte(struct ctx_info *ctxi, res_hndl_t rhndl,
  113. struct llun_info *lli);
  114. struct sisl_rht_entry *rhte_checkout(struct ctx_info *ctxi,
  115. struct llun_info *lli);
  116. void rhte_checkin(struct ctx_info *ctxi, struct sisl_rht_entry *rhte);
  117. void cxlflash_ba_terminate(struct ba_lun *ba_lun);
  118. int cxlflash_manage_lun(struct scsi_device *sdev,
  119. struct dk_cxlflash_manage_lun *manage);
  120. int check_state(struct cxlflash_cfg *cfg);
  121. #endif /* ifndef _CXLFLASH_SUPERPIPE_H */