superpipe.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. #define CHAN2PORT(_x) ((_x) + 1)
  30. #define PORT2CHAN(_x) ((_x) - 1)
  31. enum lun_mode {
  32. MODE_NONE = 0,
  33. MODE_VIRTUAL,
  34. MODE_PHYSICAL
  35. };
  36. /* Global (entire driver, spans adapters) lun_info structure */
  37. struct glun_info {
  38. u64 max_lba; /* from read cap(16) */
  39. u32 blk_len; /* from read cap(16) */
  40. enum lun_mode mode; /* NONE, VIRTUAL, PHYSICAL */
  41. int users; /* Number of users w/ references to LUN */
  42. u8 wwid[16];
  43. struct mutex mutex;
  44. struct blka blka;
  45. struct list_head list;
  46. };
  47. /* Local (per-adapter) lun_info structure */
  48. struct llun_info {
  49. u64 lun_id[CXLFLASH_NUM_FC_PORTS]; /* from REPORT_LUNS */
  50. u32 lun_index; /* Index in the LUN table */
  51. u32 host_no; /* host_no from Scsi_host */
  52. u32 port_sel; /* What port to use for this LUN */
  53. bool in_table; /* Whether a LUN table entry was created */
  54. u8 wwid[16]; /* Keep a duplicate copy here? */
  55. struct glun_info *parent; /* Pointer to entry in global LUN structure */
  56. struct scsi_device *sdev;
  57. struct list_head list;
  58. };
  59. struct lun_access {
  60. struct llun_info *lli;
  61. struct scsi_device *sdev;
  62. struct list_head list;
  63. };
  64. enum ctx_ctrl {
  65. CTX_CTRL_CLONE = (1 << 1),
  66. CTX_CTRL_ERR = (1 << 2),
  67. CTX_CTRL_ERR_FALLBACK = (1 << 3),
  68. CTX_CTRL_NOPID = (1 << 4),
  69. CTX_CTRL_FILE = (1 << 5)
  70. };
  71. #define ENCODE_CTXID(_ctx, _id) (((((u64)_ctx) & 0xFFFFFFFF0ULL) << 28) | _id)
  72. #define DECODE_CTXID(_val) (_val & 0xFFFFFFFF)
  73. struct ctx_info {
  74. struct sisl_ctrl_map __iomem *ctrl_map; /* initialized at startup */
  75. struct sisl_rht_entry *rht_start; /* 1 page (req'd for alignment),
  76. alloc/free on attach/detach */
  77. u32 rht_out; /* Number of checked out RHT entries */
  78. u32 rht_perms; /* User-defined permissions for RHT entries */
  79. struct llun_info **rht_lun; /* Mapping of RHT entries to LUNs */
  80. u8 *rht_needs_ws; /* User-desired write-same function per RHTE */
  81. struct cxl_ioctl_start_work work;
  82. u64 ctxid;
  83. int lfd;
  84. pid_t pid;
  85. bool unavail;
  86. bool err_recovery_active;
  87. struct mutex mutex; /* Context protection */
  88. struct cxl_context *ctx;
  89. struct list_head luns; /* LUNs attached to this context */
  90. const struct vm_operations_struct *cxl_mmap_vmops;
  91. struct file *file;
  92. struct list_head list; /* Link contexts in error recovery */
  93. };
  94. struct cxlflash_global {
  95. struct mutex mutex;
  96. struct list_head gluns;/* list of glun_info structs */
  97. struct page *err_page; /* One page of all 0xF for error notification */
  98. };
  99. int cxlflash_vlun_resize(struct scsi_device *, struct dk_cxlflash_resize *);
  100. int _cxlflash_vlun_resize(struct scsi_device *, struct ctx_info *,
  101. struct dk_cxlflash_resize *);
  102. int cxlflash_disk_release(struct scsi_device *, struct dk_cxlflash_release *);
  103. int _cxlflash_disk_release(struct scsi_device *, struct ctx_info *,
  104. struct dk_cxlflash_release *);
  105. int cxlflash_disk_clone(struct scsi_device *, struct dk_cxlflash_clone *);
  106. int cxlflash_disk_virtual_open(struct scsi_device *, void *);
  107. int cxlflash_lun_attach(struct glun_info *, enum lun_mode, bool);
  108. void cxlflash_lun_detach(struct glun_info *);
  109. struct ctx_info *get_context(struct cxlflash_cfg *, u64, void *, enum ctx_ctrl);
  110. void put_context(struct ctx_info *);
  111. struct sisl_rht_entry *get_rhte(struct ctx_info *, res_hndl_t,
  112. struct llun_info *);
  113. struct sisl_rht_entry *rhte_checkout(struct ctx_info *, struct llun_info *);
  114. void rhte_checkin(struct ctx_info *, struct sisl_rht_entry *);
  115. void cxlflash_ba_terminate(struct ba_lun *);
  116. int cxlflash_manage_lun(struct scsi_device *, struct dk_cxlflash_manage_lun *);
  117. int check_state(struct cxlflash_cfg *);
  118. #endif /* ifndef _CXLFLASH_SUPERPIPE_H */