1 /*
   2  * mr_sas.h: header for mr_sas
   3  *
   4  * Solaris MegaRAID driver for SAS2.0 controllers
   5  * Copyright (c) 2008-2012, LSI Logic Corporation.
   6  * All rights reserved.
   7  *
   8  * Version:
   9  * Author:
  10  *              Swaminathan K S
  11  *              Arun Chandrashekhar
  12  *              Manju R
  13  *              Rasheed
  14  *              Shakeel Bukhari
  15  */
  16 
  17 #ifndef _MR_SAS_H_
  18 #define _MR_SAS_H_
  19 
  20 #ifdef  __cplusplus
  21 extern "C" {
  22 #endif
  23 
  24 #include <sys/scsi/scsi.h>
  25 #include "mr_sas_list.h"
  26 #include "ld_pd_map.h"
  27 
  28 /*
  29  * MegaRAID SAS2.0 Driver meta data
  30  */
  31 #define MRSAS_VERSION                           "6.503.00.00JOYENT"
  32 #define MRSAS_RELDATE                           "July 30, 2012"
  33 
  34 #define MRSAS_TRUE                              1
  35 #define MRSAS_FALSE                             0
  36 
  37 #define ADAPTER_RESET_NOT_REQUIRED              0
  38 #define ADAPTER_RESET_REQUIRED                  1
  39 
  40 #define PDSUPPORT       1
  41 
  42 #define SWAP_BYTES(w)   ((((w)>>8)&0xFF) | (((w)&0xFF)<<8))
  43 #define BIG_ENDIAN(d)   (SWAP_BYTES((d) >> 16) | (SWAP_BYTES(d) << 16))
  44 /*
  45  * MegaRAID SAS2.0 device id conversion definitions.
  46  */
  47 #define INST2LSIRDCTL(x)                ((x) << INST_MINOR_SHIFT)
  48 #define MRSAS_GET_BOUNDARY_ALIGNED_LEN(len, new_len, boundary_len)  { \
  49         int rem; \
  50         rem = (len / boundary_len); \
  51         if ((rem * boundary_len) != len) { \
  52                 new_len = len + ((rem + 1) * boundary_len - len); \
  53          } else { \
  54                 new_len = len; \
  55         } \
  56 } \
  57 
  58 
  59 /*
  60  * MegaRAID SAS2.0 supported controllers
  61  */
  62 #define PCI_DEVICE_ID_LSI_2108VDE               0x0078
  63 #define PCI_DEVICE_ID_LSI_2108V                 0x0079
  64 #define PCI_DEVICE_ID_LSI_TBOLT                 0x005b
  65 #define PCI_DEVICE_ID_LSI_INVADER               0x005d
  66 
  67 /*
  68  * Register Index for 2108 Controllers.
  69  */
  70 #define REGISTER_SET_IO_2108                    (2)
  71 
  72 #define MRSAS_MAX_SGE_CNT                       0x50
  73 #define MRSAS_APP_RESERVED_CMDS                 32
  74 
  75 #define MRSAS_IOCTL_DRIVER                      0x12341234
  76 #define MRSAS_IOCTL_FIRMWARE                    0x12345678
 
 493         ddi_iblock_cookie_t     iblock_cookie;
 494         ddi_iblock_cookie_t     soft_iblock_cookie;
 495         ddi_softintr_t          soft_intr_id;
 496         uint8_t         softint_running;
 497         uint8_t         tbolt_softint_running;
 498         kmutex_t        completed_pool_mtx;
 499         mlist_t         completed_pool_list;
 500 
 501         caddr_t         internal_buf;
 502         uint32_t        internal_buf_dmac_add;
 503         uint32_t        internal_buf_size;
 504 
 505         uint16_t        vendor_id;
 506         uint16_t        device_id;
 507         uint16_t        subsysvid;
 508         uint16_t        subsysid;
 509         int             instance;
 510         int             baseaddress;
 511         char            iocnode[16];
 512 
 513         /*Driver resources unroll flags.
 514           The flag is set for resources that are needed to be free'd at detach() time */
 515 
 516         struct _unroll {                             
 517                 uint8_t softs;          // The software state was allocated.
 518                 uint8_t regs;           // Controller registers mapped.
 519                 uint8_t intr;           // Interrupt handler added.
 520                 uint8_t reqs;           // Request structs allocated.
 521                 uint8_t mutexs;         // Mutex's allocated.
 522                 uint8_t taskq;          // Task q's created.
 523                 uint8_t tran;           // Tran struct allocated
 524                 uint8_t tranSetup;      // Tran attached to the ddi.
 525                 uint8_t devctl;         // Device nodes for cfgadm created.
 526                 uint8_t scsictl;        // Device nodes for cfgadm created.
 527                 uint8_t ioctl;          // Device nodes for ioctl's created.
 528                 uint8_t timer;          // Timer started.
 529                 uint8_t aenPend;        // AEN cmd pending f/w.
 530                 uint8_t mapUpdate_pend; // LD MAP update cmd pending f/w.
 531                 uint8_t soft_isr;
 532                 uint8_t ldlist_buff;
 533                 uint8_t pdlist_buff;
 534                 uint8_t syncCmd;
 535                 uint8_t verBuff;
 536                 uint8_t alloc_space_mfi;
 537                 uint8_t alloc_space_mpi2;
 538         } unroll;
 539 
 540 
 541         /* function template pointer */
 542         struct mrsas_function_template *func_ptr;
 543 
 544 
 545         /* MSI interrupts specific */
 546         ddi_intr_handle_t *intr_htable;       //Interrupt handle array
 547         size_t          intr_htable_size;     //Interrupt handle array size
 548         int             intr_type;
 549         int             intr_cnt;
 550         uint_t          intr_pri;
 551         int             intr_cap;
 552 
 553         ddi_taskq_t     *taskq;
 554         struct mrsas_ld *mr_ld_list;
 555         kmutex_t        config_dev_mtx;
 556         /* ThunderBolt (TB) specific */
 557         ddi_softintr_t  tbolt_soft_intr_id;
 558 
 559 #ifdef PDSUPPORT
 560         uint32_t        mr_tbolt_pd_max;
 561         struct mrsas_tbolt_pd *mr_tbolt_pd_list;
 562 #endif
 563 
 564         uint8_t         fast_path_io;
 565 
 566         uint16_t        tbolt;
 567         uint16_t        reply_read_index;
 568         uint16_t        reply_size;             // Single Reply structure size
 569         uint16_t        raid_io_msg_size;       // Single message size
 570         uint32_t        io_request_frames_phy;
 571         uint8_t         *io_request_frames;
 572         MRSAS_REQUEST_DESCRIPTOR_UNION  *request_message_pool;   // Virtual address of request desc frame pool
 573         uint32_t        request_message_pool_phy;                // Physical address of request desc frame pool
 574         MPI2_REPLY_DESCRIPTORS_UNION    *reply_frame_pool;       // Virtual address of reply Frame
 575         uint32_t        reply_frame_pool_phy;                    // Physical address of reply Frame
 576         uint8_t         *reply_pool_limit;                       // Last reply frame address
 577         uint32_t        reply_pool_limit_phy;                    // Physical address of Last reply frame
 578         uint32_t        reply_q_depth;                           // Reply Queue Depth
 579         uint8_t         max_sge_in_main_msg;
 580         uint8_t         max_sge_in_chain;
 581         uint8_t         chain_offset_io_req;
 582         uint8_t         chain_offset_mpt_msg;
 583         MR_FW_RAID_MAP_ALL *ld_map[2];
 584         uint32_t        ld_map_phy[2];
 585         uint32_t        size_map_info;
 586         uint64_t        map_id;
 587         LD_LOAD_BALANCE_INFO load_balance_info[MAX_LOGICAL_DRIVES];
 588         struct mrsas_cmd *map_update_cmd;
 589         uint32_t        SyncRequired;
 590         kmutex_t        ocr_flags_mtx;
 591         dma_obj_t        drv_ver_dma_obj;
 592 } mrsas_t;
 593 
 594 
 595 /*
 596  * Function templates for various controller specific functions
 597  */
 598 struct mrsas_function_template {
 599         uint32_t (*read_fw_status_reg)(struct mrsas_instance *);
 600         void (*issue_cmd)(struct mrsas_cmd *, struct mrsas_instance *);
 601         int (*issue_cmd_in_sync_mode)(struct mrsas_instance *,
 602             struct mrsas_cmd *);
 603         int (*issue_cmd_in_poll_mode)(struct mrsas_instance *,
 604             struct mrsas_cmd *);
 605         void (*enable_intr)(struct mrsas_instance *);
 606         void (*disable_intr)(struct mrsas_instance *);
 607         int (*intr_ack)(struct mrsas_instance *);
 608         int (*init_adapter)(struct mrsas_instance *);
 609 //      int (*reset_adapter)(struct mrsas_instance *);
 610 };
 611 
 612 /*
 613  * ### Helper routines ###
 614  */
 615 
 616 /*
 617  * con_log() - console log routine
 618  * @param level         : indicates the severity of the message.
 619  * @fparam mt           : format string
 620  *
 621  * con_log displays the error messages on the console based on the current
 622  * debug level. Also it attaches the appropriate kernel severity level with
 623  * the message.
 624  *
 625  *
 626  * console messages debug levels
 627  */
 628 #define CL_NONE         0       /* No debug information */
 629 #define CL_ANN          1       /* print unconditionally, announcements */
 630 #define CL_ANN1         2       /* No o/p  */
 631 #define CL_DLEVEL1      3       /* debug level 1, informative */
 632 #define CL_DLEVEL2      4       /* debug level 2, verbose */
 633 #define CL_DLEVEL3      5       /* debug level 3, very verbose */
 634 
 635 #ifdef __SUNPRO_C
 636 #define __func__        __FUNCTION__    //""
 637 #endif
 638 
 639 #define con_log(level, fmt) { if (debug_level_g >= level) cmn_err fmt; }
 640 
 641 /*
 642  * ### SCSA definitions ###
 643  */
 644 #define PKT2TGT(pkt)    ((pkt)->pkt_address.a_target)
 645 #define PKT2LUN(pkt)    ((pkt)->pkt_address.a_lun)
 646 #define PKT2TRAN(pkt)   ((pkt)->pkt_adress.a_hba_tran)
 647 #define ADDR2TRAN(ap)   ((ap)->a_hba_tran)
 648 
 649 #define TRAN2MR(tran)   (struct mrsas_instance *)(tran)->tran_hba_private)
 650 #define ADDR2MR(ap)     (TRAN2MR(ADDR2TRAN(ap))
 651 
 652 #define PKT2CMD(pkt)    ((struct scsa_cmd *)(pkt)->pkt_ha_private)
 653 #define CMD2PKT(sp)     ((sp)->cmd_pkt)
 654 #define PKT2REQ(pkt)    (&(PKT2CMD(pkt)->request))
 655 
 656 #define CMD2ADDR(cmd)   (&CMD2PKT(cmd)->pkt_address)
 
1900         uint32_t        reserved_2[2];
1901         uint8_t         frame[64];
1902         union mrsas_sgl_frame sgl_frame;
1903         uint8_t         sense_buff[MRSAS_MAX_SENSE_LENGTH];
1904         uint8_t         data[1];
1905 };
1906 
1907 struct mrsas_aen {
1908         uint16_t        host_no;
1909         uint16_t        cmd_status;
1910         uint32_t        seq_num;
1911         uint32_t        class_locale_word;
1912 };
1913 
1914 #pragma pack()
1915 
1916 #ifndef DDI_VENDOR_LSI
1917 #define DDI_VENDOR_LSI          "LSI"
1918 #endif /* DDI_VENDOR_LSI */
1919 
1920 static int      mrsas_getinfo(dev_info_t *, ddi_info_cmd_t,  void *, void **);
1921 static int      mrsas_attach(dev_info_t *, ddi_attach_cmd_t);
1922 static int      mrsas_reset(dev_info_t *, ddi_reset_cmd_t);
1923 int     mrsas_quiesce(dev_info_t *);
1924 static int      mrsas_detach(dev_info_t *, ddi_detach_cmd_t);
1925 static int      mrsas_open(dev_t *, int, int, cred_t *);
1926 static int      mrsas_close(dev_t, int, int, cred_t *);
1927 static int      mrsas_ioctl(dev_t, int, intptr_t, int, cred_t *, int *);
1928 
1929 static int      mrsas_tran_tgt_init(dev_info_t *, dev_info_t *,
1930                     scsi_hba_tran_t *, struct scsi_device *);
1931 static struct scsi_pkt *mrsas_tran_init_pkt(struct scsi_address *, register
1932                     struct scsi_pkt *, struct buf *, int, int, int, int,
1933                     int (*)(), caddr_t);
1934 static int      mrsas_tran_start(struct scsi_address *,
1935                     register struct scsi_pkt *);
1936 static int      mrsas_tran_abort(struct scsi_address *, struct scsi_pkt *);
1937 static int      mrsas_tran_reset(struct scsi_address *, int);
1938 static int      mrsas_tran_bus_reset(dev_info_t *, int);
1939 static int      mrsas_tran_getcap(struct scsi_address *, char *, int);
1940 static int      mrsas_tran_setcap(struct scsi_address *, char *, int, int);
1941 static void     mrsas_tran_destroy_pkt(struct scsi_address *,
1942                     struct scsi_pkt *);
1943 static void     mrsas_tran_dmafree(struct scsi_address *, struct scsi_pkt *);
1944 static void     mrsas_tran_sync_pkt(struct scsi_address *, struct scsi_pkt *);
1945 static int      mrsas_tran_quiesce(dev_info_t *dip);
1946 static int      mrsas_tran_unquiesce(dev_info_t *dip);
1947 static uint_t   mrsas_isr();
1948 static uint_t   mrsas_softintr();
1949 
1950 static struct mrsas_cmd *get_mfi_pkt(struct mrsas_instance *);
1951 static void     return_mfi_pkt(struct mrsas_instance *,
1952                     struct mrsas_cmd *);
1953 
1954 static void     free_space_for_mfi(struct mrsas_instance *);
1955 static int      mrsas_tbolt_alloc_additional_dma_buffer
1956 (struct mrsas_instance *);
1957 int             mrsas_tbolt_sync_map_info(struct mrsas_instance *instance);
1958 static int      alloc_additional_dma_buffer(struct mrsas_instance *);
1959 static uint32_t read_fw_status_reg_ppc(struct mrsas_instance *);
1960 static void     issue_cmd_ppc(struct mrsas_cmd *, struct mrsas_instance *);
1961 static int      issue_cmd_in_poll_mode_ppc(struct mrsas_instance *,
1962                     struct mrsas_cmd *);
1963 static int      issue_cmd_in_sync_mode_ppc(struct mrsas_instance *,
1964                     struct mrsas_cmd *);
1965 static void     enable_intr_ppc(struct mrsas_instance *);
1966 static void     disable_intr_ppc(struct mrsas_instance *);
1967 static int      intr_ack_ppc(struct mrsas_instance *);
1968 int     mfi_state_transition_to_ready(struct mrsas_instance *);
1969 static void     flush_cache(struct mrsas_instance *instance);
1970 void    display_scsi_inquiry(caddr_t);
1971 static int      start_mfi_aen(struct mrsas_instance *instance);
1972 static int      handle_drv_ioctl(struct mrsas_instance *instance,
1973                     struct mrsas_ioctl *ioctl, int mode);
1974 static int      handle_mfi_ioctl(struct mrsas_instance *instance,
1975                     struct mrsas_ioctl *ioctl, int mode);
1976 static int      handle_mfi_aen(struct mrsas_instance *instance,
1977                     struct mrsas_aen *aen);
1978 void    fill_up_drv_ver(struct mrsas_drv_ver *dv);
1979 static struct mrsas_cmd *build_cmd(struct mrsas_instance *instance,
1980                     struct scsi_address *ap, struct scsi_pkt *pkt,
1981                     uchar_t *cmd_done);
1982 static struct mrsas_cmd *mrsas_tbolt_build_cmd(struct mrsas_instance *instance,
1983                     struct scsi_address *ap, struct scsi_pkt *pkt,
1984                     uchar_t *cmd_done);
1985 static int      wait_for_outstanding(struct mrsas_instance *instance);
1986 static int      register_mfi_aen(struct mrsas_instance *instance,
1987                     uint32_t seq_num, uint32_t class_locale_word);
1988 static int      issue_mfi_pthru(struct mrsas_instance *instance, struct
1989                     mrsas_ioctl *ioctl, struct mrsas_cmd *cmd, int mode);
1990 static int      issue_mfi_dcmd(struct mrsas_instance *instance, struct
1991                     mrsas_ioctl *ioctl, struct mrsas_cmd *cmd, int mode);
1992 static int      issue_mfi_smp(struct mrsas_instance *instance, struct
1993                     mrsas_ioctl *ioctl, struct mrsas_cmd *cmd, int mode);
1994 static int      issue_mfi_stp(struct mrsas_instance *instance, struct
1995                     mrsas_ioctl *ioctl, struct mrsas_cmd *cmd, int mode);
1996 static int      abort_aen_cmd(struct mrsas_instance *instance,
1997                     struct mrsas_cmd *cmd_to_abort);
1998 
1999 
2000 static void     mrsas_rem_intrs(struct mrsas_instance *instance);
2001 static int      mrsas_add_intrs(struct mrsas_instance *instance, int intr_type);
2002 
2003 static void     mrsas_tran_tgt_free(dev_info_t *, dev_info_t *,
2004                     scsi_hba_tran_t *, struct scsi_device *);
2005 static int      mrsas_tran_bus_config(dev_info_t *, uint_t,
2006                     ddi_bus_config_op_t, void *, dev_info_t **);
2007 static int      mrsas_parse_devname(char *, int *, int *);
2008 static int      mrsas_config_all_devices(struct mrsas_instance *);
2009 int     mrsas_config_scsi_device(struct mrsas_instance *,
2010                     struct scsi_device *, dev_info_t **);
2011 static int      mrsas_config_ld(struct mrsas_instance *, uint16_t,
2012                         uint8_t, dev_info_t **);
2013 
2014 #ifdef PDSUPPORT
2015 int     mrsas_tbolt_config_pd(struct mrsas_instance *, uint16_t,
2016                         uint8_t, dev_info_t **);
2017 static void     mrsas_tbolt_get_pd_info(struct mrsas_instance *,
2018                         struct mrsas_tbolt_pd_info *, int);
2019 #endif
2020 
2021 dev_info_t *mrsas_find_child(struct mrsas_instance *, uint16_t,
2022                         uint8_t);
2023 static int      mrsas_name_node(dev_info_t *, char *, int);
2024 static void     mrsas_issue_evt_taskq(struct mrsas_eventinfo *);
2025 int     mrsas_service_evt(struct mrsas_instance *, int, int, int,
2026                         uint64_t);
2027 static void     free_additional_dma_buffer(struct mrsas_instance *);
2028 
2029 struct mrsas_cmd *get_raid_msg_pkt(struct mrsas_instance *);
2030 void return_raid_msg_pkt(struct mrsas_instance *, struct mrsas_cmd *);
2031 struct mrsas_cmd *get_raid_msg_mfi_pkt(struct mrsas_instance *);
2032 void return_raid_msg_mfi_pkt(struct mrsas_instance *, struct mrsas_cmd *);
2033 
2034 int     alloc_space_for_mpi2(struct mrsas_instance *);
2035 int     alloc_additional_dma_buffer(struct mrsas_instance *);
2036 
2037 int     mrsas_issue_init_mpi2(struct mrsas_instance *);
2038 struct scsi_pkt *mrsas_tbolt_tran_init_pkt(struct scsi_address *, register
2039                     struct scsi_pkt *, struct buf *, int, int, int, int,
2040                     int (*)(), caddr_t);
2041 int     mrsas_tbolt_tran_start(struct scsi_address *,
2042                     register struct scsi_pkt *);
2043 uint32_t tbolt_read_fw_status_reg(struct mrsas_instance *);
2044 void    tbolt_issue_cmd(struct mrsas_cmd *, struct mrsas_instance *);
2045 int     tbolt_issue_cmd_in_poll_mode(struct mrsas_instance *,
2046                     struct mrsas_cmd *);
2047 int     tbolt_issue_cmd_in_sync_mode(struct mrsas_instance *,
2048                     struct mrsas_cmd *);
2049 void    tbolt_enable_intr(struct mrsas_instance *);
2050 void    tbolt_disable_intr(struct mrsas_instance *);
2051 int     tbolt_intr_ack(struct mrsas_instance *);
2052 uint_t  mr_sas_tbolt_process_outstanding_cmd(struct mrsas_instance *);
2053     uint_t tbolt_softintr();
2054 int     mrsas_tbolt_dma(struct mrsas_instance *, uint32_t, int, int (*)());
2055 int     mrsas_check_dma_handle(ddi_dma_handle_t handle);
2056 int     mrsas_check_acc_handle(ddi_acc_handle_t handle);
2057 int     mrsas_dma_alloc(struct mrsas_instance *, struct scsi_pkt *,
2058                     struct buf *, int, int (*)());
2059 int     mrsas_dma_move(struct mrsas_instance *,
2060                         struct scsi_pkt *, struct buf *);
2061 int     mrsas_alloc_dma_obj(struct mrsas_instance *, dma_obj_t *,
2062                     uchar_t);
2063 int     mrsas_tbolt_ioc_init(struct mrsas_instance *, dma_obj_t *,
2064         ddi_acc_handle_t);
2065 int     mrsas_tbolt_prepare_pkt(struct scsa_cmd *);
2066 void    mr_sas_tbolt_build_mfi_cmd(struct mrsas_instance *, struct mrsas_cmd *);
2067 int     mrsas_dma_alloc_dmd(struct mrsas_instance *, dma_obj_t *);
2068 int     mr_sas_tbolt_build_sgl(struct mrsas_instance *,
2069         struct scsa_cmd *,
2070         struct mrsas_cmd *,
2071         Mpi2RaidSCSIIORequest_t *,
2072         uint32_t *);
2073 void    tbolt_complete_cmd_in_sync_mode(struct mrsas_instance *,
2074         struct mrsas_cmd *);
2075 int     alloc_req_rep_desc(struct mrsas_instance *);
2076 static void     complete_cmd_in_sync_mode(struct mrsas_instance *,
2077                 struct mrsas_cmd *);
2078 static void     io_timeout_checker(void *instance);
2079 static int      mrsas_kill_adapter(struct mrsas_instance *);
2080 int             mrsas_mode_sense_build(struct scsi_pkt *);
2081 void            push_pending_mfi_pkt(struct mrsas_instance *,
2082                         struct mrsas_cmd *);
2083 static int      mrsas_issue_init_mfi(struct mrsas_instance *);
2084 int             mrsas_issue_pending_cmds(struct mrsas_instance *);
2085 int     mrsas_print_pending_cmds(struct mrsas_instance *);
2086 int     mrsas_complete_pending_cmds(struct mrsas_instance *);
2087 static int      mrsas_reset_ppc(struct mrsas_instance *);
2088 static uint32_t mrsas_initiate_ocr_if_fw_is_faulty(struct mrsas_instance *);
2089 
2090 MRSAS_REQUEST_DESCRIPTOR_UNION *\
2091         mr_sas_get_request_descriptor(struct mrsas_instance *,
2092         uint16_t, struct mrsas_cmd *);
2093 
2094 int     create_mfi_frame_pool(struct mrsas_instance *);
2095 void    destroy_mfi_frame_pool(struct mrsas_instance *);
2096 int     create_mfi_mpi_frame_pool(struct mrsas_instance *);
2097 void    destroy_mfi_mpi_frame_pool(struct mrsas_instance *);
2098 int     create_mpi2_frame_pool(struct mrsas_instance *);
2099 void    destroy_mpi2_frame_pool(struct mrsas_instance *);
2100 int     mrsas_free_dma_obj(struct mrsas_instance *, dma_obj_t);
2101 void    mrsas_tbolt_free_additional_dma_buffer(struct mrsas_instance *);
2102 void    free_req_desc_pool(struct mrsas_instance *);
2103 void    free_space_for_mpi2(struct mrsas_instance *);
2104 void    mrsas_dump_reply_desc(struct mrsas_instance *);
2105 void    tbolt_complete_cmd(struct mrsas_instance *, struct mrsas_cmd *);
2106 void    io_timeout_checker(void *);
2107 void    display_scsi_inquiry(caddr_t);
2108 void    service_mfi_aen(struct mrsas_instance *, struct mrsas_cmd *);
2109 int     mrsas_mode_sense_build(struct scsi_pkt *);
2110 int     mrsas_tbolt_get_ld_map_info(struct mrsas_instance *);
2111 void    mrsas_tbolt_set_pd_lba(U8 cdb[], uint8_t *cdb_len, U64 start_blk, U32 num_blocks, U8 DifCapable);
2112 U8      mrsas_tbolt_check_map_info(struct mrsas_instance *);
2113 struct mrsas_cmd *mrsas_tbolt_build_poll_cmd(struct mrsas_instance *,
2114         struct scsi_address *, struct scsi_pkt *, uchar_t *);
2115 int     mrsas_tbolt_reset_ppc(struct mrsas_instance *instance);
2116 int     mrsas_tbolt_kill_adapter(struct mrsas_instance *instance);
2117 int     abort_syncmap_cmd(struct mrsas_instance *, struct mrsas_cmd *);
2118 void    mrsas_tbolt_prepare_cdb(struct mrsas_instance *instance, U8 cdb[],struct IO_REQUEST_INFO *,
2119         Mpi2RaidSCSIIORequest_t *, U32);
2120 
2121 
2122 static int
2123 mrsas_undo_resources (dev_info_t *dip, struct mrsas_instance *instance);
2124 
2125 int mrsas_init_adapter_ppc (struct mrsas_instance *instance);
2126 int mrsas_init_adapter_tbolt (struct mrsas_instance *instance);
2127 int mrsas_init_adapter (struct mrsas_instance *instance);
2128 
2129 int mrsas_alloc_cmd_pool(struct mrsas_instance *instance);
2130 void mrsas_free_cmd_pool(struct mrsas_instance *instance);
2131 
2132 void mrsas_print_cmd_details(struct mrsas_instance *, struct mrsas_cmd *, int );
2133 
2134 #ifdef  __cplusplus
2135 }
2136 #endif
2137 
2138 #endif /* _MR_SAS_H_ */
 | 
   1 /*
   2  * mr_sas.h: header for mr_sas
   3  *
   4  * Solaris MegaRAID driver for SAS2.0 controllers
   5  * Copyright (c) 2008-2012, LSI Logic Corporation.
   6  * All rights reserved.
   7  *
   8  * Version:
   9  * Author:
  10  *              Swaminathan K S
  11  *              Arun Chandrashekhar
  12  *              Manju R
  13  *              Rasheed
  14  *              Shakeel Bukhari
  15  *
  16  * Redistribution and use in source and binary forms, with or without
  17  * modification, are permitted provided that the following conditions are met:
  18  *
  19  * 1. Redistributions of source code must retain the above copyright notice,
  20  *    this list of conditions and the following disclaimer.
  21  *
  22  * 2. Redistributions in binary form must reproduce the above copyright notice,
  23  *    this list of conditions and the following disclaimer in the documentation
  24  *    and/or other materials provided with the distribution.
  25  *
  26  * 3. Neither the name of the author nor the names of its contributors may be
  27  *    used to endorse or promote products derived from this software without
  28  *    specific prior written permission.
  29  *
  30  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  33  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  34  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  35  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  36  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  37  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  38  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  39  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  40  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  41  * DAMAGE.
  42  */
  43 
  44 /*
  45  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
  46  */
  47 
  48 #ifndef _MR_SAS_H_
  49 #define _MR_SAS_H_
  50 
  51 #ifdef  __cplusplus
  52 extern "C" {
  53 #endif
  54 
  55 #include <sys/scsi/scsi.h>
  56 #include "mr_sas_list.h"
  57 #include "ld_pd_map.h"
  58 
  59 /*
  60  * MegaRAID SAS2.0 Driver meta data
  61  */
  62 #define MRSAS_VERSION                           "6.503.00.00ILLUMOS"
  63 #define MRSAS_RELDATE                           "July 30, 2012"
  64 
  65 #define MRSAS_TRUE                              1
  66 #define MRSAS_FALSE                             0
  67 
  68 #define ADAPTER_RESET_NOT_REQUIRED              0
  69 #define ADAPTER_RESET_REQUIRED                  1
  70 
  71 #define PDSUPPORT       1
  72 
  73 /*
  74  * MegaRAID SAS2.0 device id conversion definitions.
  75  */
  76 #define INST2LSIRDCTL(x)                ((x) << INST_MINOR_SHIFT)
  77 #define MRSAS_GET_BOUNDARY_ALIGNED_LEN(len, new_len, boundary_len)  { \
  78         int rem; \
  79         rem = (len / boundary_len); \
  80         if ((rem * boundary_len) != len) { \
  81                 new_len = len + ((rem + 1) * boundary_len - len); \
  82         } else { \
  83                 new_len = len; \
  84         } \
  85 }
  86 
  87 
  88 /*
  89  * MegaRAID SAS2.0 supported controllers
  90  */
  91 #define PCI_DEVICE_ID_LSI_2108VDE               0x0078
  92 #define PCI_DEVICE_ID_LSI_2108V                 0x0079
  93 #define PCI_DEVICE_ID_LSI_TBOLT                 0x005b
  94 #define PCI_DEVICE_ID_LSI_INVADER               0x005d
  95 
  96 /*
  97  * Register Index for 2108 Controllers.
  98  */
  99 #define REGISTER_SET_IO_2108                    (2)
 100 
 101 #define MRSAS_MAX_SGE_CNT                       0x50
 102 #define MRSAS_APP_RESERVED_CMDS                 32
 103 
 104 #define MRSAS_IOCTL_DRIVER                      0x12341234
 105 #define MRSAS_IOCTL_FIRMWARE                    0x12345678
 
 522         ddi_iblock_cookie_t     iblock_cookie;
 523         ddi_iblock_cookie_t     soft_iblock_cookie;
 524         ddi_softintr_t          soft_intr_id;
 525         uint8_t         softint_running;
 526         uint8_t         tbolt_softint_running;
 527         kmutex_t        completed_pool_mtx;
 528         mlist_t         completed_pool_list;
 529 
 530         caddr_t         internal_buf;
 531         uint32_t        internal_buf_dmac_add;
 532         uint32_t        internal_buf_size;
 533 
 534         uint16_t        vendor_id;
 535         uint16_t        device_id;
 536         uint16_t        subsysvid;
 537         uint16_t        subsysid;
 538         int             instance;
 539         int             baseaddress;
 540         char            iocnode[16];
 541 
 542         int             fm_capabilities;
 543         /*
 544          * Driver resources unroll flags.  The flag is set for resources that
 545          * are needed to be free'd at detach() time.
 546          */
 547         struct _unroll {
 548                 uint8_t softs;          /* The software state was allocated. */
 549                 uint8_t regs;           /* Controller registers mapped. */
 550                 uint8_t intr;           /* Interrupt handler added. */
 551                 uint8_t reqs;           /* Request structs allocated. */
 552                 uint8_t mutexs;         /* Mutex's allocated. */
 553                 uint8_t taskq;          /* Task q's created. */
 554                 uint8_t tran;           /* Tran struct allocated */
 555                 uint8_t tranSetup;      /* Tran attached to the ddi. */
 556                 uint8_t devctl;         /* Device nodes for cfgadm created. */
 557                 uint8_t scsictl;        /* Device nodes for cfgadm created. */
 558                 uint8_t ioctl;          /* Device nodes for ioctl's created. */
 559                 uint8_t timer;          /* Timer started. */
 560                 uint8_t aenPend;        /* AEN cmd pending f/w. */
 561                 uint8_t mapUpdate_pend; /* LD MAP update cmd pending f/w. */
 562                 uint8_t soft_isr;       /* Soft interrupt handler allocated. */
 563                 uint8_t ldlist_buff;    /* Logical disk list allocated. */
 564                 uint8_t pdlist_buff;    /* Physical disk list allocated. */
 565                 uint8_t syncCmd;        /* Sync map command allocated. */
 566                 uint8_t verBuff;        /* 2108 MFI buffer allocated. */
 567                 uint8_t alloc_space_mfi;  /* Allocated space for 2108 MFI. */
 568                 uint8_t alloc_space_mpi2; /* Allocated space for 2208 MPI2. */
 569         } unroll;
 570 
 571 
 572         /* function template pointer */
 573         struct mrsas_function_template *func_ptr;
 574 
 575 
 576         /* MSI interrupts specific */
 577         ddi_intr_handle_t *intr_htable;         /* Interrupt handle array */
 578         size_t          intr_htable_size;       /* Int. handle array size */
 579         int             intr_type;
 580         int             intr_cnt;
 581         uint_t          intr_pri;
 582         int             intr_cap;
 583 
 584         ddi_taskq_t     *taskq;
 585         struct mrsas_ld *mr_ld_list;
 586         kmutex_t        config_dev_mtx;
 587         /* ThunderBolt (TB) specific */
 588         ddi_softintr_t  tbolt_soft_intr_id;
 589 
 590 #ifdef PDSUPPORT
 591         uint32_t        mr_tbolt_pd_max;
 592         struct mrsas_tbolt_pd *mr_tbolt_pd_list;
 593 #endif
 594 
 595         uint8_t         fast_path_io;
 596 
 597         uint16_t        tbolt;
 598         uint16_t        reply_read_index;
 599         uint16_t        reply_size;             /* Single Reply struct size */
 600         uint16_t        raid_io_msg_size;       /* Single message size */
 601         uint32_t        io_request_frames_phy;
 602         uint8_t         *io_request_frames;
 603         /* Virtual address of request desc frame pool */
 604         MRSAS_REQUEST_DESCRIPTOR_UNION  *request_message_pool;
 605         /* Physical address of request desc frame pool */
 606         uint32_t        request_message_pool_phy;
 607         /* Virtual address of reply Frame */
 608         MPI2_REPLY_DESCRIPTORS_UNION    *reply_frame_pool;
 609         /* Physical address of reply Frame */
 610         uint32_t        reply_frame_pool_phy;
 611         uint8_t         *reply_pool_limit;      /* Last reply frame address */
 612         /* Physical address of Last reply frame */
 613         uint32_t        reply_pool_limit_phy;
 614         uint32_t        reply_q_depth;          /* Reply Queue Depth */
 615         uint8_t         max_sge_in_main_msg;
 616         uint8_t         max_sge_in_chain;
 617         uint8_t         chain_offset_io_req;
 618         uint8_t         chain_offset_mpt_msg;
 619         MR_FW_RAID_MAP_ALL *ld_map[2];
 620         uint32_t        ld_map_phy[2];
 621         uint32_t        size_map_info;
 622         uint64_t        map_id;
 623         LD_LOAD_BALANCE_INFO load_balance_info[MAX_LOGICAL_DRIVES];
 624         struct mrsas_cmd *map_update_cmd;
 625         uint32_t        SyncRequired;
 626         kmutex_t        ocr_flags_mtx;
 627         dma_obj_t       drv_ver_dma_obj;
 628 } mrsas_t;
 629 
 630 
 631 /*
 632  * Function templates for various controller specific functions
 633  */
 634 struct mrsas_function_template {
 635         uint32_t (*read_fw_status_reg)(struct mrsas_instance *);
 636         void (*issue_cmd)(struct mrsas_cmd *, struct mrsas_instance *);
 637         int (*issue_cmd_in_sync_mode)(struct mrsas_instance *,
 638             struct mrsas_cmd *);
 639         int (*issue_cmd_in_poll_mode)(struct mrsas_instance *,
 640             struct mrsas_cmd *);
 641         void (*enable_intr)(struct mrsas_instance *);
 642         void (*disable_intr)(struct mrsas_instance *);
 643         int (*intr_ack)(struct mrsas_instance *);
 644         int (*init_adapter)(struct mrsas_instance *);
 645 /*      int (*reset_adapter)(struct mrsas_instance *); */
 646 };
 647 
 648 /*
 649  * ### Helper routines ###
 650  */
 651 
 652 /*
 653  * con_log() - console log routine
 654  * @param level         : indicates the severity of the message.
 655  * @fparam mt           : format string
 656  *
 657  * con_log displays the error messages on the console based on the current
 658  * debug level. Also it attaches the appropriate kernel severity level with
 659  * the message.
 660  *
 661  *
 662  * console messages debug levels
 663  */
 664 #define CL_NONE         0       /* No debug information */
 665 #define CL_ANN          1       /* print unconditionally, announcements */
 666 #define CL_ANN1         2       /* No-op  */
 667 #define CL_DLEVEL1      3       /* debug level 1, informative */
 668 #define CL_DLEVEL2      4       /* debug level 2, verbose */
 669 #define CL_DLEVEL3      5       /* debug level 3, very verbose */
 670 
 671 #ifdef __SUNPRO_C
 672 #define __func__ ""
 673 #endif
 674 
 675 #define con_log(level, fmt) { if (debug_level_g >= level) cmn_err fmt; }
 676 
 677 /*
 678  * ### SCSA definitions ###
 679  */
 680 #define PKT2TGT(pkt)    ((pkt)->pkt_address.a_target)
 681 #define PKT2LUN(pkt)    ((pkt)->pkt_address.a_lun)
 682 #define PKT2TRAN(pkt)   ((pkt)->pkt_adress.a_hba_tran)
 683 #define ADDR2TRAN(ap)   ((ap)->a_hba_tran)
 684 
 685 #define TRAN2MR(tran)   (struct mrsas_instance *)(tran)->tran_hba_private)
 686 #define ADDR2MR(ap)     (TRAN2MR(ADDR2TRAN(ap))
 687 
 688 #define PKT2CMD(pkt)    ((struct scsa_cmd *)(pkt)->pkt_ha_private)
 689 #define CMD2PKT(sp)     ((sp)->cmd_pkt)
 690 #define PKT2REQ(pkt)    (&(PKT2CMD(pkt)->request))
 691 
 692 #define CMD2ADDR(cmd)   (&CMD2PKT(cmd)->pkt_address)
 
1936         uint32_t        reserved_2[2];
1937         uint8_t         frame[64];
1938         union mrsas_sgl_frame sgl_frame;
1939         uint8_t         sense_buff[MRSAS_MAX_SENSE_LENGTH];
1940         uint8_t         data[1];
1941 };
1942 
1943 struct mrsas_aen {
1944         uint16_t        host_no;
1945         uint16_t        cmd_status;
1946         uint32_t        seq_num;
1947         uint32_t        class_locale_word;
1948 };
1949 
1950 #pragma pack()
1951 
1952 #ifndef DDI_VENDOR_LSI
1953 #define DDI_VENDOR_LSI          "LSI"
1954 #endif /* DDI_VENDOR_LSI */
1955 
1956 int mrsas_config_scsi_device(struct mrsas_instance *,
1957     struct scsi_device *, dev_info_t **);
1958 
1959 #ifdef PDSUPPORT
1960 int mrsas_tbolt_config_pd(struct mrsas_instance *, uint16_t,
1961     uint8_t, dev_info_t **);
1962 #endif
1963 
1964 dev_info_t *mrsas_find_child(struct mrsas_instance *, uint16_t, uint8_t);
1965 int mrsas_service_evt(struct mrsas_instance *, int, int, int, uint64_t);
1966 void return_raid_msg_pkt(struct mrsas_instance *, struct mrsas_cmd *);
1967 struct mrsas_cmd *get_raid_msg_mfi_pkt(struct mrsas_instance *);
1968 void return_raid_msg_mfi_pkt(struct mrsas_instance *, struct mrsas_cmd *);
1969 
1970 int     alloc_space_for_mpi2(struct mrsas_instance *);
1971 void    fill_up_drv_ver(struct mrsas_drv_ver *dv);
1972 
1973 int     mrsas_issue_init_mpi2(struct mrsas_instance *);
1974 struct scsi_pkt *mrsas_tbolt_tran_init_pkt(struct scsi_address *, register
1975                     struct scsi_pkt *, struct buf *, int, int, int, int,
1976                     int (*)(), caddr_t);
1977 int     mrsas_tbolt_tran_start(struct scsi_address *,
1978                     register struct scsi_pkt *);
1979 uint32_t tbolt_read_fw_status_reg(struct mrsas_instance *);
1980 void    tbolt_issue_cmd(struct mrsas_cmd *, struct mrsas_instance *);
1981 int     tbolt_issue_cmd_in_poll_mode(struct mrsas_instance *,
1982                     struct mrsas_cmd *);
1983 int     tbolt_issue_cmd_in_sync_mode(struct mrsas_instance *,
1984                     struct mrsas_cmd *);
1985 void    tbolt_enable_intr(struct mrsas_instance *);
1986 void    tbolt_disable_intr(struct mrsas_instance *);
1987 int     tbolt_intr_ack(struct mrsas_instance *);
1988 uint_t  mr_sas_tbolt_process_outstanding_cmd(struct mrsas_instance *);
1989     uint_t tbolt_softintr();
1990 int     mrsas_tbolt_dma(struct mrsas_instance *, uint32_t, int, int (*)());
1991 int     mrsas_check_dma_handle(ddi_dma_handle_t handle);
1992 int     mrsas_check_acc_handle(ddi_acc_handle_t handle);
1993 int     mrsas_dma_alloc(struct mrsas_instance *, struct scsi_pkt *,
1994                     struct buf *, int, int (*)());
1995 int     mrsas_dma_move(struct mrsas_instance *,
1996                         struct scsi_pkt *, struct buf *);
1997 int     mrsas_alloc_dma_obj(struct mrsas_instance *, dma_obj_t *,
1998                     uchar_t);
1999 void    mr_sas_tbolt_build_mfi_cmd(struct mrsas_instance *, struct mrsas_cmd *);
2000 int     mrsas_dma_alloc_dmd(struct mrsas_instance *, dma_obj_t *);
2001 void    tbolt_complete_cmd_in_sync_mode(struct mrsas_instance *,
2002         struct mrsas_cmd *);
2003 int     alloc_req_rep_desc(struct mrsas_instance *);
2004 int             mrsas_mode_sense_build(struct scsi_pkt *);
2005 void            push_pending_mfi_pkt(struct mrsas_instance *,
2006                         struct mrsas_cmd *);
2007 int     mrsas_issue_pending_cmds(struct mrsas_instance *);
2008 int     mrsas_print_pending_cmds(struct mrsas_instance *);
2009 int     mrsas_complete_pending_cmds(struct mrsas_instance *);
2010 
2011 int     create_mfi_frame_pool(struct mrsas_instance *);
2012 void    destroy_mfi_frame_pool(struct mrsas_instance *);
2013 int     create_mfi_mpi_frame_pool(struct mrsas_instance *);
2014 void    destroy_mfi_mpi_frame_pool(struct mrsas_instance *);
2015 int     create_mpi2_frame_pool(struct mrsas_instance *);
2016 void    destroy_mpi2_frame_pool(struct mrsas_instance *);
2017 int     mrsas_free_dma_obj(struct mrsas_instance *, dma_obj_t);
2018 void    mrsas_tbolt_free_additional_dma_buffer(struct mrsas_instance *);
2019 void    free_req_desc_pool(struct mrsas_instance *);
2020 void    free_space_for_mpi2(struct mrsas_instance *);
2021 void    mrsas_dump_reply_desc(struct mrsas_instance *);
2022 void    tbolt_complete_cmd(struct mrsas_instance *, struct mrsas_cmd *);
2023 void    display_scsi_inquiry(caddr_t);
2024 void    service_mfi_aen(struct mrsas_instance *, struct mrsas_cmd *);
2025 int     mrsas_mode_sense_build(struct scsi_pkt *);
2026 int     mrsas_tbolt_get_ld_map_info(struct mrsas_instance *);
2027 struct mrsas_cmd *mrsas_tbolt_build_poll_cmd(struct mrsas_instance *,
2028         struct scsi_address *, struct scsi_pkt *, uchar_t *);
2029 int     mrsas_tbolt_reset_ppc(struct mrsas_instance *instance);
2030 void    mrsas_tbolt_kill_adapter(struct mrsas_instance *instance);
2031 int     abort_syncmap_cmd(struct mrsas_instance *, struct mrsas_cmd *);
2032 void    mrsas_tbolt_prepare_cdb(struct mrsas_instance *instance, U8 cdb[],
2033     struct IO_REQUEST_INFO *, Mpi2RaidSCSIIORequest_t *, U32);
2034 
2035 
2036 int mrsas_init_adapter_ppc(struct mrsas_instance *instance);
2037 int mrsas_init_adapter_tbolt(struct mrsas_instance *instance);
2038 int mrsas_init_adapter(struct mrsas_instance *instance);
2039 
2040 int mrsas_alloc_cmd_pool(struct mrsas_instance *instance);
2041 void mrsas_free_cmd_pool(struct mrsas_instance *instance);
2042 
2043 void mrsas_print_cmd_details(struct mrsas_instance *, struct mrsas_cmd *, int);
2044 struct mrsas_cmd *get_raid_msg_pkt(struct mrsas_instance *);
2045 
2046 int mfi_state_transition_to_ready(struct mrsas_instance *);
2047 
2048 
2049 /* FMA functions. */
2050 int mrsas_common_check(struct mrsas_instance *, struct  mrsas_cmd *);
2051 void mrsas_fm_ereport(struct mrsas_instance *, char *);
2052 
2053 
2054 #ifdef  __cplusplus
2055 }
2056 #endif
2057 
2058 #endif /* _MR_SAS_H_ */
 |