superpipe.h 4.7 KB

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