brintos

brintos / linux-shallow public Read only

0
0
Text · 4.4 KiB · fe8c975 Raw
151 lines · c
1/* SPDX-License-Identifier: GPL-2.0-or-later */2/*3 * CXL Flash Device Driver4 *5 * Written by: Manoj N. Kumar <manoj@linux.vnet.ibm.com>, IBM Corporation6 *             Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation7 *8 * Copyright (C) 2015 IBM Corporation9 */10 11#ifndef _CXLFLASH_SUPERPIPE_H12#define _CXLFLASH_SUPERPIPE_H13 14extern struct cxlflash_global global;15 16/*17 * Terminology: use afu (and not adapter) to refer to the HW.18 * Adapter is the entire slot and includes PSL out of which19 * only the AFU is visible to user space.20 */21 22/* Chunk size parms: note sislite minimum chunk size is23 * 0x10000 LBAs corresponding to a NMASK or 16.24 */25#define MC_CHUNK_SIZE     (1 << MC_RHT_NMASK)	/* in LBAs */26 27#define CMD_TIMEOUT 30  /* 30 secs */28#define CMD_RETRIES 5   /* 5 retries for scsi_execute */29 30#define MAX_SECTOR_UNIT  512 /* max_sector is in 512 byte multiples */31 32enum lun_mode {33	MODE_NONE = 0,34	MODE_VIRTUAL,35	MODE_PHYSICAL36};37 38/* Global (entire driver, spans adapters) lun_info structure */39struct glun_info {40	u64 max_lba;		/* from read cap(16) */41	u32 blk_len;		/* from read cap(16) */42	enum lun_mode mode;	/* NONE, VIRTUAL, PHYSICAL */43	int users;		/* Number of users w/ references to LUN */44 45	u8 wwid[16];46 47	struct mutex mutex;48 49	struct blka blka;50	struct list_head list;51};52 53/* Local (per-adapter) lun_info structure */54struct llun_info {55	u64 lun_id[MAX_FC_PORTS]; /* from REPORT_LUNS */56	u32 lun_index;		/* Index in the LUN table */57	u32 host_no;		/* host_no from Scsi_host */58	u32 port_sel;		/* What port to use for this LUN */59	bool in_table;		/* Whether a LUN table entry was created */60 61	u8 wwid[16];		/* Keep a duplicate copy here? */62 63	struct glun_info *parent; /* Pointer to entry in global LUN structure */64	struct scsi_device *sdev;65	struct list_head list;66};67 68struct lun_access {69	struct llun_info *lli;70	struct scsi_device *sdev;71	struct list_head list;72};73 74enum ctx_ctrl {75	CTX_CTRL_CLONE		= (1 << 1),76	CTX_CTRL_ERR		= (1 << 2),77	CTX_CTRL_ERR_FALLBACK	= (1 << 3),78	CTX_CTRL_NOPID		= (1 << 4),79	CTX_CTRL_FILE		= (1 << 5)80};81 82#define ENCODE_CTXID(_ctx, _id)	(((((u64)_ctx) & 0xFFFFFFFF0ULL) << 28) | _id)83#define DECODE_CTXID(_val)	(_val & 0xFFFFFFFF)84 85struct ctx_info {86	struct sisl_ctrl_map __iomem *ctrl_map; /* initialized at startup */87	struct sisl_rht_entry *rht_start; /* 1 page (req'd for alignment),88					   * alloc/free on attach/detach89					   */90	u32 rht_out;		/* Number of checked out RHT entries */91	u32 rht_perms;		/* User-defined permissions for RHT entries */92	struct llun_info **rht_lun;       /* Mapping of RHT entries to LUNs */93	u8 *rht_needs_ws;	/* User-desired write-same function per RHTE */94 95	u64 ctxid;96	u64 irqs; /* Number of interrupts requested for context */97	pid_t pid;98	bool initialized;99	bool unavail;100	bool err_recovery_active;101	struct mutex mutex; /* Context protection */102	struct kref kref;103	void *ctx;104	struct cxlflash_cfg *cfg;105	struct list_head luns;	/* LUNs attached to this context */106	const struct vm_operations_struct *cxl_mmap_vmops;107	struct file *file;108	struct list_head list; /* Link contexts in error recovery */109};110 111struct cxlflash_global {112	struct mutex mutex;113	struct list_head gluns;/* list of glun_info structs */114	struct page *err_page; /* One page of all 0xF for error notification */115};116 117int cxlflash_vlun_resize(struct scsi_device *sdev, void *resize);118int _cxlflash_vlun_resize(struct scsi_device *sdev, struct ctx_info *ctxi,119			  struct dk_cxlflash_resize *resize);120 121int cxlflash_disk_release(struct scsi_device *sdev,122			  void *release);123int _cxlflash_disk_release(struct scsi_device *sdev, struct ctx_info *ctxi,124			   struct dk_cxlflash_release *release);125 126int cxlflash_disk_clone(struct scsi_device *sdev, void *arg);127 128int cxlflash_disk_virtual_open(struct scsi_device *sdev, void *arg);129 130int cxlflash_lun_attach(struct glun_info *gli, enum lun_mode mode, bool locked);131void cxlflash_lun_detach(struct glun_info *gli);132 133struct ctx_info *get_context(struct cxlflash_cfg *cfg, u64 rctxit, void *arg,134			     enum ctx_ctrl ctrl);135void put_context(struct ctx_info *ctxi);136 137struct sisl_rht_entry *get_rhte(struct ctx_info *ctxi, res_hndl_t rhndl,138				struct llun_info *lli);139 140struct sisl_rht_entry *rhte_checkout(struct ctx_info *ctxi,141				     struct llun_info *lli);142void rhte_checkin(struct ctx_info *ctxi, struct sisl_rht_entry *rhte);143 144void cxlflash_ba_terminate(struct ba_lun *ba_lun);145 146int cxlflash_manage_lun(struct scsi_device *sdev, void *manage);147 148int check_state(struct cxlflash_cfg *cfg);149 150#endif /* ifndef _CXLFLASH_SUPERPIPE_H */151