mei: amthif: prefix cb list with amthif
[firefly-linux-kernel-4.4.55.git] / drivers / misc / mei / mei_dev.h
index d61c4ddfc80c3fa80f804f2c0a7528284b7b957a..ce246b0fb2d69f0366de707290110bcc7c7a07fe 100644 (file)
 /*
  * watch dog definition
  */
-#define MEI_WATCHDOG_DATA_SIZE         16
-#define MEI_START_WD_DATA_SIZE         20
-#define MEI_WD_PARAMS_SIZE             4
+#define MEI_WD_HDR_SIZE       4
+#define MEI_WD_STOP_MSG_SIZE  MEI_WD_HDR_SIZE
+#define MEI_WD_START_MSG_SIZE (MEI_WD_HDR_SIZE + 16)
+
+#define MEI_WD_DEFAULT_TIMEOUT   120  /* seconds */
+#define MEI_WD_MIN_TIMEOUT       120  /* seconds */
+#define MEI_WD_MAX_TIMEOUT     65535  /* seconds */
+
+#define MEI_WD_STOP_TIMEOUT      10 /* msecs */
+
 #define MEI_WD_STATE_INDEPENDENCE_MSG_SENT       (1 << 0)
 
 #define MEI_RD_MSG_BUF_SIZE           (128 * sizeof(u32))
 
-/*
- * MEI PCI Device object
- */
-extern struct pci_dev *mei_device;
-
 
 /*
  * AMTHI Client UUID
@@ -53,20 +55,22 @@ extern const uuid_le mei_wd_guid;
  */
 extern const u8 mei_wd_state_independence_msg[3][4];
 
+/*
+ * Number of Maximum MEI Clients
+ */
+#define MEI_CLIENTS_MAX 256
+
 /*
  * Number of File descriptors/handles
  * that can be opened to the driver.
  *
- * Limit to 253: 255 Total Clients
+ * Limit to 253: 256 Total Clients
+ * minus internal client for MEI Bus Messags
  * minus internal client for AMTHI
  * minus internal client for Watchdog
  */
-#define  MEI_MAX_OPEN_HANDLE_COUNT     253
+#define  MEI_MAX_OPEN_HANDLE_COUNT (MEI_CLIENTS_MAX - 3)
 
-/*
- * Number of Maximum MEI Clients
- */
-#define MEI_CLIENTS_MAX 255
 
 /* File state */
 enum file_state {
@@ -78,17 +82,19 @@ enum file_state {
 };
 
 /* MEI device states */
-enum mei_states {
-       MEI_INITIALIZING = 0,
-       MEI_INIT_CLIENTS,
-       MEI_ENABLED,
-       MEI_RESETING,
-       MEI_DISABLED,
-       MEI_RECOVERING_FROM_RESET,
-       MEI_POWER_DOWN,
-       MEI_POWER_UP
+enum mei_dev_state {
+       MEI_DEV_INITIALIZING = 0,
+       MEI_DEV_INIT_CLIENTS,
+       MEI_DEV_ENABLED,
+       MEI_DEV_RESETING,
+       MEI_DEV_DISABLED,
+       MEI_DEV_RECOVERING_FROM_RESET,
+       MEI_DEV_POWER_DOWN,
+       MEI_DEV_POWER_UP
 };
 
+const char *mei_dev_state_str(int state);
+
 /* init clients states*/
 enum mei_init_clients_states {
        MEI_START_MESSAGE = 0,
@@ -113,6 +119,12 @@ enum mei_file_transaction_states {
        MEI_READ_COMPLETE
 };
 
+enum mei_wd_states {
+       MEI_WD_IDLE,
+       MEI_WD_RUNNING,
+       MEI_WD_STOPPING,
+};
+
 /* MEI CB */
 enum mei_cb_major_types {
        MEI_READ = 0,
@@ -128,16 +140,16 @@ enum mei_cb_major_types {
 struct mei_message_data {
        u32 size;
        unsigned char *data;
-} __packed;
+};
 
 
 struct mei_cl_cb {
-       struct list_head cb_list;
+       struct list_head list;
        enum mei_cb_major_types major_file_operations;
        void *file_private;
        struct mei_message_data request_buffer;
        struct mei_message_data response_buffer;
-       unsigned long information;
+       unsigned long buf_idx;
        unsigned long read_time;
        struct file *file_object;
 };
@@ -163,10 +175,6 @@ struct mei_cl {
        struct mei_cl_cb *read_cb;
 };
 
-struct mei_io_list {
-       struct mei_cl_cb mei_cb;
-};
-
 /**
  * struct mei_deive -  MEI private device struct
  * @hbuf_depth - depth of host(write) buffer
@@ -176,16 +184,13 @@ struct mei_device {
        /*
         * lists of queues
         */
-        /* array of pointers to aio lists */
-       struct mei_io_list read_list;           /* driver read queue */
-       struct mei_io_list write_list;          /* driver write queue */
-       struct mei_io_list write_waiting_list;  /* write waiting queue */
-       struct mei_io_list ctrl_wr_list;        /* managed write IOCTL list */
-       struct mei_io_list ctrl_rd_list;        /* managed read IOCTL list */
-       struct mei_io_list amthi_cmd_list;      /* amthi list for cmd waiting */
-
-       /* driver managed amthi list for reading completed amthi cmd data */
-       struct mei_io_list amthi_read_complete_list;
+       /* array of pointers to aio lists */
+       struct mei_cl_cb read_list;             /* driver read queue */
+       struct mei_cl_cb write_list;            /* driver write queue */
+       struct mei_cl_cb write_waiting_list;    /* write waiting queue */
+       struct mei_cl_cb ctrl_wr_list;          /* managed write IOCTL list */
+       struct mei_cl_cb ctrl_rd_list;          /* managed read IOCTL list */
+
        /*
         * list of files
         */
@@ -218,10 +223,9 @@ struct mei_device {
        /*
         * mei device  states
         */
-       enum mei_states mei_state;
+       enum mei_dev_state dev_state;
        enum mei_init_clients_states init_clients_state;
        u16 init_clients_timer;
-       bool stop;
        bool need_reset;
 
        u32 extra_write_index;
@@ -241,14 +245,16 @@ struct mei_device {
        bool mei_host_buffer_is_empty;
 
        struct mei_cl wd_cl;
-       bool wd_interface_reg;
+       enum mei_wd_states wd_state;
        bool wd_pending;
-       bool wd_stopped;
-       bool wd_bypass; /* if false, don't refresh watchdog ME client */
-       u16 wd_timeout; /* seconds ((wd_data[1] << 8) + wd_data[0]) */
-       unsigned char wd_data[MEI_START_WD_DATA_SIZE];
+       u16 wd_timeout;
+       unsigned char wd_data[MEI_WD_START_MSG_SIZE];
 
 
+       /* amthif list for cmd waiting */
+       struct mei_cl_cb amthif_cmd_list;
+       /* driver managed amthif list for reading completed amthif cmd data */
+       struct mei_cl_cb amthif_rd_complete_list;
        struct file *iamthif_file_object;
        struct mei_cl iamthif_cl;
        struct mei_cl_cb *iamthif_current_cb;
@@ -264,6 +270,11 @@ struct mei_device {
        bool iamthif_canceled;
 };
 
+static inline unsigned long mei_secs_to_jiffies(unsigned long sec)
+{
+       return msecs_to_jiffies(sec * MSEC_PER_SEC);
+}
+
 
 /*
  * mei init function prototypes
@@ -275,19 +286,33 @@ int mei_task_initialize_clients(void *data);
 int mei_initialize_clients(struct mei_device *dev);
 int mei_disconnect_host_client(struct mei_device *dev, struct mei_cl *cl);
 void mei_remove_client_from_file_list(struct mei_device *dev, u8 host_client_id);
-void mei_host_init_iamthif(struct mei_device *dev);
 void mei_allocate_me_clients_storage(struct mei_device *dev);
 
 
-u8 mei_find_me_client_update_filext(struct mei_device *dev,
-                               struct mei_cl *priv,
-                               const uuid_le *cguid, u8 client_id);
+int mei_me_cl_update_filext(struct mei_device *dev, struct mei_cl *cl,
+                       const uuid_le *cguid, u8 host_client_id);
+int mei_me_cl_by_uuid(const struct mei_device *dev, const uuid_le *cuuid);
+int mei_me_cl_by_id(struct mei_device *dev, u8 client_id);
 
 /*
- * MEI IO List Functions
+ * MEI IO Functions
+ */
+struct mei_cl_cb *mei_io_cb_init(struct mei_cl *cl, struct file *fp);
+void mei_io_cb_free(struct mei_cl_cb *priv_cb);
+int mei_io_cb_alloc_req_buf(struct mei_cl_cb *cb, size_t length);
+int mei_io_cb_alloc_resp_buf(struct mei_cl_cb *cb, size_t length);
+
+
+/**
+ * mei_io_list_init - Sets up a queue list.
+ *
+ * @list: An instance cl callback structure
  */
-void mei_io_list_init(struct mei_io_list *list);
-void mei_io_list_flush(struct mei_io_list *list, struct mei_cl *cl);
+static inline void mei_io_list_init(struct mei_cl_cb *list)
+{
+       INIT_LIST_HEAD(&list->list);
+}
+void mei_io_list_flush(struct mei_cl_cb *list, struct mei_cl *cl);
 
 /*
  * MEI ME Client Functions
@@ -336,19 +361,37 @@ int mei_ioctl_connect_client(struct file *file,
 
 int mei_start_read(struct mei_device *dev, struct mei_cl *cl);
 
-int amthi_write(struct mei_device *dev, struct mei_cl_cb *priv_cb);
 
-int amthi_read(struct mei_device *dev, struct file *file,
+/*
+ * AMTHIF - AMT Host Interface Functions
+ */
+void mei_amthif_reset_params(struct mei_device *dev);
+
+void mei_amthif_host_init(struct mei_device *dev);
+
+int mei_amthif_write(struct mei_device *dev, struct mei_cl_cb *priv_cb);
+
+int mei_amthif_read(struct mei_device *dev, struct file *file,
              char __user *ubuf, size_t length, loff_t *offset);
 
-struct mei_cl_cb *find_amthi_read_list_entry(struct mei_device *dev,
+struct mei_cl_cb *mei_amthif_find_read_list_entry(struct mei_device *dev,
                                                struct file *file);
 
-void mei_run_next_iamthif_cmd(struct mei_device *dev);
+void mei_amthif_run_next_cmd(struct mei_device *dev);
+
+
+int mei_amthif_read_message(struct mei_cl_cb *complete_list,
+               struct mei_device *dev, struct mei_msg_hdr *mei_hdr);
 
-void mei_free_cb_private(struct mei_cl_cb *priv_cb);
+int mei_amthif_irq_process_completed(struct mei_device *dev, s32 *slots,
+                       struct mei_cl_cb *cb_pos,
+                       struct mei_cl *cl,
+                       struct mei_cl_cb *cmpl_list);
 
-int mei_find_me_client_index(const struct mei_device *dev, uuid_le cuuid);
+void mei_amthif_complete(struct mei_device *dev, struct mei_cl_cb *cb);
+int mei_amthif_irq_read_message(struct mei_cl_cb *complete_list,
+               struct mei_device *dev, struct mei_msg_hdr *mei_hdr);
+int mei_amthif_irq_read(struct mei_device *dev, s32 *slots);
 
 /*
  * Register Access Function