linux/drivers/scsi/hisi_sas/hisi_sas.h
<<
>>
Prefs
   1/*
   2 * Copyright (c) 2015 Linaro Ltd.
   3 * Copyright (c) 2015 Hisilicon Limited.
   4 *
   5 * This program is free software; you can redistribute it and/or modify
   6 * it under the terms of the GNU General Public License as published by
   7 * the Free Software Foundation; either version 2 of the License, or
   8 * (at your option) any later version.
   9 *
  10 */
  11
  12#ifndef _HISI_SAS_H_
  13#define _HISI_SAS_H_
  14
  15#include <linux/acpi.h>
  16#include <linux/clk.h>
  17#include <linux/dmapool.h>
  18#include <linux/iopoll.h>
  19#include <linux/mfd/syscon.h>
  20#include <linux/module.h>
  21#include <linux/of_address.h>
  22#include <linux/pci.h>
  23#include <linux/platform_device.h>
  24#include <linux/property.h>
  25#include <linux/regmap.h>
  26#include <scsi/sas_ata.h>
  27#include <scsi/libsas.h>
  28
  29#define HISI_SAS_MAX_PHYS       9
  30#define HISI_SAS_MAX_QUEUES     32
  31#define HISI_SAS_QUEUE_SLOTS 512
  32#define HISI_SAS_MAX_ITCT_ENTRIES 1024
  33#define HISI_SAS_MAX_DEVICES HISI_SAS_MAX_ITCT_ENTRIES
  34#define HISI_SAS_RESET_BIT      0
  35#define HISI_SAS_REJECT_CMD_BIT 1
  36
  37#define HISI_SAS_STATUS_BUF_SZ (sizeof(struct hisi_sas_status_buffer))
  38#define HISI_SAS_COMMAND_TABLE_SZ (sizeof(union hisi_sas_command_table))
  39
  40#define hisi_sas_status_buf_addr(buf) \
  41        (buf + offsetof(struct hisi_sas_slot_buf_table, status_buffer))
  42#define hisi_sas_status_buf_addr_mem(slot) hisi_sas_status_buf_addr(slot->buf)
  43#define hisi_sas_status_buf_addr_dma(slot) \
  44        hisi_sas_status_buf_addr(slot->buf_dma)
  45
  46#define hisi_sas_cmd_hdr_addr(buf) \
  47        (buf + offsetof(struct hisi_sas_slot_buf_table, command_header))
  48#define hisi_sas_cmd_hdr_addr_mem(slot) hisi_sas_cmd_hdr_addr(slot->buf)
  49#define hisi_sas_cmd_hdr_addr_dma(slot) hisi_sas_cmd_hdr_addr(slot->buf_dma)
  50
  51#define hisi_sas_sge_addr(buf) \
  52        (buf + offsetof(struct hisi_sas_slot_buf_table, sge_page))
  53#define hisi_sas_sge_addr_mem(slot) hisi_sas_sge_addr(slot->buf)
  54#define hisi_sas_sge_addr_dma(slot) hisi_sas_sge_addr(slot->buf_dma)
  55
  56#define HISI_SAS_MAX_SSP_RESP_SZ (sizeof(struct ssp_frame_hdr) + 1024)
  57#define HISI_SAS_MAX_SMP_RESP_SZ 1028
  58#define HISI_SAS_MAX_STP_RESP_SZ 28
  59
  60#define DEV_IS_EXPANDER(type) \
  61        ((type == SAS_EDGE_EXPANDER_DEVICE) || \
  62        (type == SAS_FANOUT_EXPANDER_DEVICE))
  63
  64#define HISI_SAS_SATA_PROTOCOL_NONDATA          0x1
  65#define HISI_SAS_SATA_PROTOCOL_PIO                      0x2
  66#define HISI_SAS_SATA_PROTOCOL_DMA                      0x4
  67#define HISI_SAS_SATA_PROTOCOL_FPDMA            0x8
  68#define HISI_SAS_SATA_PROTOCOL_ATAPI            0x10
  69
  70struct hisi_hba;
  71
  72enum {
  73        PORT_TYPE_SAS = (1U << 1),
  74        PORT_TYPE_SATA = (1U << 0),
  75};
  76
  77enum dev_status {
  78        HISI_SAS_DEV_NORMAL,
  79        HISI_SAS_DEV_EH,
  80};
  81
  82enum {
  83        HISI_SAS_INT_ABT_CMD = 0,
  84        HISI_SAS_INT_ABT_DEV = 1,
  85};
  86
  87enum hisi_sas_dev_type {
  88        HISI_SAS_DEV_TYPE_STP = 0,
  89        HISI_SAS_DEV_TYPE_SSP,
  90        HISI_SAS_DEV_TYPE_SATA,
  91};
  92
  93struct hisi_sas_hw_error {
  94        u32 irq_msk;
  95        u32 msk;
  96        int shift;
  97        const char *msg;
  98        int reg;
  99        const struct hisi_sas_hw_error *sub;
 100};
 101
 102struct hisi_sas_phy {
 103        struct hisi_hba *hisi_hba;
 104        struct hisi_sas_port    *port;
 105        struct asd_sas_phy      sas_phy;
 106        struct sas_identify     identify;
 107        struct work_struct      phyup_ws;
 108        u64             port_id; /* from hw */
 109        u64             dev_sas_addr;
 110        u64             frame_rcvd_size;
 111        u8              frame_rcvd[32];
 112        u8              phy_attached;
 113        u8              reserved[3];
 114        u32             phy_type;
 115        enum sas_linkrate       minimum_linkrate;
 116        enum sas_linkrate       maximum_linkrate;
 117};
 118
 119struct hisi_sas_port {
 120        struct asd_sas_port     sas_port;
 121        u8      port_attached;
 122        u8      id; /* from hw */
 123};
 124
 125struct hisi_sas_cq {
 126        struct hisi_hba *hisi_hba;
 127        struct tasklet_struct tasklet;
 128        int     rd_point;
 129        int     id;
 130};
 131
 132struct hisi_sas_dq {
 133        struct hisi_hba *hisi_hba;
 134        struct hisi_sas_slot    *slot_prep;
 135        spinlock_t lock;
 136        int     wr_point;
 137        int     id;
 138};
 139
 140struct hisi_sas_device {
 141        struct hisi_hba         *hisi_hba;
 142        struct domain_device    *sas_device;
 143        struct completion *completion;
 144        struct hisi_sas_dq      *dq;
 145        struct list_head        list;
 146        u64 attached_phy;
 147        atomic64_t running_req;
 148        enum sas_device_type    dev_type;
 149        int device_id;
 150        int sata_idx;
 151        u8 dev_status;
 152};
 153
 154struct hisi_sas_slot {
 155        struct list_head entry;
 156        struct sas_task *task;
 157        struct hisi_sas_port    *port;
 158        u64     n_elem;
 159        int     dlvry_queue;
 160        int     dlvry_queue_slot;
 161        int     cmplt_queue;
 162        int     cmplt_queue_slot;
 163        int     idx;
 164        int     abort;
 165        void    *buf;
 166        dma_addr_t buf_dma;
 167        void    *cmd_hdr;
 168        dma_addr_t cmd_hdr_dma;
 169        struct work_struct abort_slot;
 170        struct timer_list internal_abort_timer;
 171};
 172
 173struct hisi_sas_tmf_task {
 174        u8 tmf;
 175        u16 tag_of_task_to_be_managed;
 176};
 177
 178struct hisi_sas_hw {
 179        int (*hw_init)(struct hisi_hba *hisi_hba);
 180        void (*setup_itct)(struct hisi_hba *hisi_hba,
 181                           struct hisi_sas_device *device);
 182        int (*slot_index_alloc)(struct hisi_hba *hisi_hba, int *slot_idx,
 183                                struct domain_device *device);
 184        struct hisi_sas_device *(*alloc_dev)(struct domain_device *device);
 185        void (*sl_notify)(struct hisi_hba *hisi_hba, int phy_no);
 186        int (*get_free_slot)(struct hisi_hba *hisi_hba, struct hisi_sas_dq *dq);
 187        void (*start_delivery)(struct hisi_sas_dq *dq);
 188        int (*prep_ssp)(struct hisi_hba *hisi_hba,
 189                        struct hisi_sas_slot *slot, int is_tmf,
 190                        struct hisi_sas_tmf_task *tmf);
 191        int (*prep_smp)(struct hisi_hba *hisi_hba,
 192                        struct hisi_sas_slot *slot);
 193        int (*prep_stp)(struct hisi_hba *hisi_hba,
 194                        struct hisi_sas_slot *slot);
 195        int (*prep_abort)(struct hisi_hba *hisi_hba,
 196                          struct hisi_sas_slot *slot,
 197                          int device_id, int abort_flag, int tag_to_abort);
 198        int (*slot_complete)(struct hisi_hba *hisi_hba,
 199                             struct hisi_sas_slot *slot);
 200        void (*phys_init)(struct hisi_hba *hisi_hba);
 201        void (*phy_start)(struct hisi_hba *hisi_hba, int phy_no);
 202        void (*phy_disable)(struct hisi_hba *hisi_hba, int phy_no);
 203        void (*phy_hard_reset)(struct hisi_hba *hisi_hba, int phy_no);
 204        void (*get_events)(struct hisi_hba *hisi_hba, int phy_no);
 205        void (*phy_set_linkrate)(struct hisi_hba *hisi_hba, int phy_no,
 206                        struct sas_phy_linkrates *linkrates);
 207        enum sas_linkrate (*phy_get_max_linkrate)(void);
 208        void (*free_device)(struct hisi_hba *hisi_hba,
 209                            struct hisi_sas_device *dev);
 210        int (*get_wideport_bitmap)(struct hisi_hba *hisi_hba, int port_id);
 211        void (*dereg_device)(struct hisi_hba *hisi_hba,
 212                                struct domain_device *device);
 213        int (*soft_reset)(struct hisi_hba *hisi_hba);
 214        u32 (*get_phys_state)(struct hisi_hba *hisi_hba);
 215        int max_command_entries;
 216        int complete_hdr_size;
 217};
 218
 219struct hisi_hba {
 220        /* This must be the first element, used by SHOST_TO_SAS_HA */
 221        struct sas_ha_struct *p;
 222
 223        struct platform_device *platform_dev;
 224        struct pci_dev *pci_dev;
 225        struct device *dev;
 226
 227        void __iomem *regs;
 228        struct regmap *ctrl;
 229        u32 ctrl_reset_reg;
 230        u32 ctrl_reset_sts_reg;
 231        u32 ctrl_clock_ena_reg;
 232        u32 refclk_frequency_mhz;
 233        u8 sas_addr[SAS_ADDR_SIZE];
 234
 235        int n_phy;
 236        spinlock_t lock;
 237
 238        struct timer_list timer;
 239        struct workqueue_struct *wq;
 240
 241        int slot_index_count;
 242        unsigned long *slot_index_tags;
 243        unsigned long reject_stp_links_msk;
 244
 245        /* SCSI/SAS glue */
 246        struct sas_ha_struct sha;
 247        struct Scsi_Host *shost;
 248
 249        struct hisi_sas_cq cq[HISI_SAS_MAX_QUEUES];
 250        struct hisi_sas_dq dq[HISI_SAS_MAX_QUEUES];
 251        struct hisi_sas_phy phy[HISI_SAS_MAX_PHYS];
 252        struct hisi_sas_port port[HISI_SAS_MAX_PHYS];
 253
 254        int     queue_count;
 255
 256        struct dma_pool *buffer_pool;
 257        struct hisi_sas_device  devices[HISI_SAS_MAX_DEVICES];
 258        struct hisi_sas_cmd_hdr *cmd_hdr[HISI_SAS_MAX_QUEUES];
 259        dma_addr_t cmd_hdr_dma[HISI_SAS_MAX_QUEUES];
 260        void *complete_hdr[HISI_SAS_MAX_QUEUES];
 261        dma_addr_t complete_hdr_dma[HISI_SAS_MAX_QUEUES];
 262        struct hisi_sas_initial_fis *initial_fis;
 263        dma_addr_t initial_fis_dma;
 264        struct hisi_sas_itct *itct;
 265        dma_addr_t itct_dma;
 266        struct hisi_sas_iost *iost;
 267        dma_addr_t iost_dma;
 268        struct hisi_sas_breakpoint *breakpoint;
 269        dma_addr_t breakpoint_dma;
 270        struct hisi_sas_breakpoint *sata_breakpoint;
 271        dma_addr_t sata_breakpoint_dma;
 272        struct hisi_sas_slot    *slot_info;
 273        unsigned long flags;
 274        const struct hisi_sas_hw *hw;   /* Low level hw interface */
 275        unsigned long sata_dev_bitmap[BITS_TO_LONGS(HISI_SAS_MAX_DEVICES)];
 276        struct work_struct rst_work;
 277};
 278
 279/* Generic HW DMA host memory structures */
 280/* Delivery queue header */
 281struct hisi_sas_cmd_hdr {
 282        /* dw0 */
 283        __le32 dw0;
 284
 285        /* dw1 */
 286        __le32 dw1;
 287
 288        /* dw2 */
 289        __le32 dw2;
 290
 291        /* dw3 */
 292        __le32 transfer_tags;
 293
 294        /* dw4 */
 295        __le32 data_transfer_len;
 296
 297        /* dw5 */
 298        __le32 first_burst_num;
 299
 300        /* dw6 */
 301        __le32 sg_len;
 302
 303        /* dw7 */
 304        __le32 dw7;
 305
 306        /* dw8-9 */
 307        __le64 cmd_table_addr;
 308
 309        /* dw10-11 */
 310        __le64 sts_buffer_addr;
 311
 312        /* dw12-13 */
 313        __le64 prd_table_addr;
 314
 315        /* dw14-15 */
 316        __le64 dif_prd_table_addr;
 317};
 318
 319struct hisi_sas_itct {
 320        __le64 qw0;
 321        __le64 sas_addr;
 322        __le64 qw2;
 323        __le64 qw3;
 324        __le64 qw4_15[12];
 325};
 326
 327struct hisi_sas_iost {
 328        __le64 qw0;
 329        __le64 qw1;
 330        __le64 qw2;
 331        __le64 qw3;
 332};
 333
 334struct hisi_sas_err_record {
 335        u32     data[4];
 336};
 337
 338struct hisi_sas_initial_fis {
 339        struct hisi_sas_err_record err_record;
 340        struct dev_to_host_fis fis;
 341        u32 rsvd[3];
 342};
 343
 344struct hisi_sas_breakpoint {
 345        u8      data[128];
 346};
 347
 348struct hisi_sas_sata_breakpoint {
 349        struct hisi_sas_breakpoint tag[32];
 350};
 351
 352struct hisi_sas_sge {
 353        __le64 addr;
 354        __le32 page_ctrl_0;
 355        __le32 page_ctrl_1;
 356        __le32 data_len;
 357        __le32 data_off;
 358};
 359
 360struct hisi_sas_command_table_smp {
 361        u8 bytes[44];
 362};
 363
 364struct hisi_sas_command_table_stp {
 365        struct  host_to_dev_fis command_fis;
 366        u8      dummy[12];
 367        u8      atapi_cdb[ATAPI_CDB_LEN];
 368};
 369
 370#define HISI_SAS_SGE_PAGE_CNT SG_CHUNK_SIZE
 371struct hisi_sas_sge_page {
 372        struct hisi_sas_sge sge[HISI_SAS_SGE_PAGE_CNT];
 373}  __aligned(16);
 374
 375struct hisi_sas_command_table_ssp {
 376        struct ssp_frame_hdr hdr;
 377        union {
 378                struct {
 379                        struct ssp_command_iu task;
 380                        u32 prot[6];
 381                };
 382                struct ssp_tmf_iu ssp_task;
 383                struct xfer_rdy_iu xfer_rdy;
 384                struct ssp_response_iu ssp_res;
 385        } u;
 386};
 387
 388union hisi_sas_command_table {
 389        struct hisi_sas_command_table_ssp ssp;
 390        struct hisi_sas_command_table_smp smp;
 391        struct hisi_sas_command_table_stp stp;
 392}  __aligned(16);
 393
 394struct hisi_sas_status_buffer {
 395        struct hisi_sas_err_record err;
 396        u8      iu[1024];
 397}  __aligned(16);
 398
 399struct hisi_sas_slot_buf_table {
 400        struct hisi_sas_status_buffer status_buffer;
 401        union hisi_sas_command_table command_header;
 402        struct hisi_sas_sge_page sge_page;
 403};
 404
 405extern struct scsi_transport_template *hisi_sas_stt;
 406extern struct scsi_host_template *hisi_sas_sht;
 407
 408extern void hisi_sas_stop_phys(struct hisi_hba *hisi_hba);
 409extern void hisi_sas_init_add(struct hisi_hba *hisi_hba);
 410extern int hisi_sas_alloc(struct hisi_hba *hisi_hba, struct Scsi_Host *shost);
 411extern void hisi_sas_free(struct hisi_hba *hisi_hba);
 412extern u8 hisi_sas_get_ata_protocol(u8 cmd, int direction);
 413extern struct hisi_sas_port *to_hisi_sas_port(struct asd_sas_port *sas_port);
 414extern void hisi_sas_sata_done(struct sas_task *task,
 415                            struct hisi_sas_slot *slot);
 416extern int hisi_sas_get_ncq_tag(struct sas_task *task, u32 *tag);
 417extern int hisi_sas_get_fw_info(struct hisi_hba *hisi_hba);
 418extern int hisi_sas_probe(struct platform_device *pdev,
 419                          const struct hisi_sas_hw *ops);
 420extern int hisi_sas_remove(struct platform_device *pdev);
 421
 422extern void hisi_sas_phy_down(struct hisi_hba *hisi_hba, int phy_no, int rdy);
 423extern void hisi_sas_slot_task_free(struct hisi_hba *hisi_hba,
 424                                    struct sas_task *task,
 425                                    struct hisi_sas_slot *slot);
 426extern void hisi_sas_init_mem(struct hisi_hba *hisi_hba);
 427extern void hisi_sas_rst_work_handler(struct work_struct *work);
 428extern void hisi_sas_kill_tasklets(struct hisi_hba *hisi_hba);
 429#endif
 430