]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blobdiff - drivers/scsi/cxlflash/common.h
scsi: cxlflash: Hide FC internals behind common access routine
[mirror_ubuntu-zesty-kernel.git] / drivers / scsi / cxlflash / common.h
index 0e9de5d62da25f56bcb0645a35a98582896fc37b..e6a7c975c0dcad03c00732933718dd150962d0ee 100644 (file)
@@ -15,6 +15,7 @@
 #ifndef _CXLFLASH_COMMON_H
 #define _CXLFLASH_COMMON_H
 
+#include <linux/irq_poll.h>
 #include <linux/list.h>
 #include <linux/rwsem.h>
 #include <linux/types.h>
 
 extern const struct file_operations cxlflash_cxl_fops;
 
-#define MAX_CONTEXT  CXLFLASH_MAX_CONTEXT       /* num contexts per afu */
+#define MAX_CONTEXT    CXLFLASH_MAX_CONTEXT    /* num contexts per afu */
+#define NUM_FC_PORTS   CXLFLASH_NUM_FC_PORTS   /* ports per AFU */
+#define MAX_FC_PORTS   CXLFLASH_MAX_FC_PORTS   /* ports per AFU */
+
+#define CHAN2PORTMASK(_x)      (1 << (_x))     /* channel to port mask */
+#define PORTMASK2CHAN(_x)      (ilog2((_x)))   /* port mask to channel */
+#define PORTNUM2CHAN(_x)       ((_x) - 1)      /* port number to channel */
 
 #define CXLFLASH_BLOCK_SIZE    4096    /* 4K blocks */
 #define CXLFLASH_MAX_XFER_SIZE 16777216        /* 16MB transfer */
@@ -54,6 +61,9 @@ extern const struct file_operations cxlflash_cxl_fops;
 /* RRQ for master issued cmds */
 #define NUM_RRQ_ENTRY                   CXLFLASH_MAX_CMDS
 
+/* SQ for master issued cmds */
+#define NUM_SQ_ENTRY                   CXLFLASH_MAX_CMDS
+
 
 static inline void check_sizes(void)
 {
@@ -94,6 +104,7 @@ struct cxlflash_cfg {
        struct pci_dev *dev;
        struct pci_device_id *dev_id;
        struct Scsi_Host *host;
+       int num_fc_ports;
 
        ulong cxlflash_regs_pci;
 
@@ -114,7 +125,7 @@ struct cxlflash_cfg {
        struct file_operations cxl_fops;
 
        /* Parameters that are LUN table related */
-       int last_lun_index[CXLFLASH_NUM_FC_PORTS];
+       int last_lun_index[MAX_FC_PORTS];
        int promote_lun_index;
        struct list_head lluns; /* list of llun_info structs */
 
@@ -131,6 +142,7 @@ struct afu_cmd {
        struct afu *parent;
        struct scsi_cmnd *scp;
        struct completion cevent;
+       struct list_head queue;
 
        u8 cmd_tmf:1;
 
@@ -155,8 +167,8 @@ static inline struct afu_cmd *sc_to_afucz(struct scsi_cmnd *sc)
 
 struct afu {
        /* Stuff requiring alignment go first. */
-
-       u64 rrq_entry[NUM_RRQ_ENTRY];   /* 2K RRQ */
+       struct sisl_ioarcb sq[NUM_SQ_ENTRY];            /* 16K SQ */
+       u64 rrq_entry[NUM_RRQ_ENTRY];                   /* 2K RRQ */
 
        /* Beware of alignment till here. Preferably introduce new
         * fields after this point
@@ -171,9 +183,14 @@ struct afu {
        struct sisl_host_map __iomem *host_map;         /* MC host map */
        struct sisl_ctrl_map __iomem *ctrl_map;         /* MC control map */
 
-       struct kref mapcount;
-
        ctx_hndl_t ctx_hndl;    /* master's context handle */
+
+       atomic_t hsq_credits;
+       spinlock_t hsq_slock;
+       struct sisl_ioarcb *hsq_start;
+       struct sisl_ioarcb *hsq_end;
+       struct sisl_ioarcb *hsq_curr;
+       spinlock_t hrrq_slock;
        u64 *hrrq_start;
        u64 *hrrq_end;
        u64 *hrrq_curr;
@@ -187,10 +204,34 @@ struct afu {
        char version[16];
        u64 interface_version;
 
+       u32 irqpoll_weight;
+       struct irq_poll irqpoll;
        struct cxlflash_cfg *parent; /* Pointer back to parent cxlflash_cfg */
 
 };
 
+static inline bool afu_is_irqpoll_enabled(struct afu *afu)
+{
+       return !!afu->irqpoll_weight;
+}
+
+static inline bool afu_is_cmd_mode(struct afu *afu, u64 cmd_mode)
+{
+       u64 afu_cap = afu->interface_version >> SISL_INTVER_CAP_SHIFT;
+
+       return afu_cap & cmd_mode;
+}
+
+static inline bool afu_is_sq_cmd_mode(struct afu *afu)
+{
+       return afu_is_cmd_mode(afu, SISL_INTVER_CAP_SQ_CMD_MODE);
+}
+
+static inline bool afu_is_ioarrin_cmd_mode(struct afu *afu)
+{
+       return afu_is_cmd_mode(afu, SISL_INTVER_CAP_IOARRIN_CMD_MODE);
+}
+
 static inline u64 lun_to_lunid(u64 lun)
 {
        __be64 lun_id;
@@ -199,6 +240,20 @@ static inline u64 lun_to_lunid(u64 lun)
        return be64_to_cpu(lun_id);
 }
 
+static inline __be64 __iomem *get_fc_port_regs(struct cxlflash_cfg *cfg, int i)
+{
+       struct afu *afu = cfg->afu;
+
+       return &afu->afu_map->global.fc_regs[i][0];
+}
+
+static inline __be64 __iomem *get_fc_port_luns(struct cxlflash_cfg *cfg, int i)
+{
+       struct afu *afu = cfg->afu;
+
+       return &afu->afu_map->global.fc_port[i][0];
+}
+
 int cxlflash_afu_sync(struct afu *, ctx_hndl_t, res_hndl_t, u8);
 void cxlflash_list_init(void);
 void cxlflash_term_global_luns(void);