12e21a3efSScott Long /*- 22e21a3efSScott Long * Copyright (c) 2006 IronPort Systems 32e21a3efSScott Long * All rights reserved. 42e21a3efSScott Long * 52e21a3efSScott Long * Redistribution and use in source and binary forms, with or without 62e21a3efSScott Long * modification, are permitted provided that the following conditions 72e21a3efSScott Long * are met: 82e21a3efSScott Long * 1. Redistributions of source code must retain the above copyright 92e21a3efSScott Long * notice, this list of conditions and the following disclaimer. 102e21a3efSScott Long * 2. Redistributions in binary form must reproduce the above copyright 112e21a3efSScott Long * notice, this list of conditions and the following disclaimer in the 122e21a3efSScott Long * documentation and/or other materials provided with the distribution. 132e21a3efSScott Long * 142e21a3efSScott Long * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 152e21a3efSScott Long * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 162e21a3efSScott Long * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 172e21a3efSScott Long * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 182e21a3efSScott Long * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 192e21a3efSScott Long * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 202e21a3efSScott Long * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 212e21a3efSScott Long * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 222e21a3efSScott Long * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 232e21a3efSScott Long * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 242e21a3efSScott Long * SUCH DAMAGE. 252e21a3efSScott Long */ 26610f2ef3SScott Long /*- 27610f2ef3SScott Long * Copyright (c) 2007 LSI Corp. 28610f2ef3SScott Long * Copyright (c) 2007 Rajesh Prabhakaran. 29610f2ef3SScott Long * All rights reserved. 30610f2ef3SScott Long * 31610f2ef3SScott Long * Redistribution and use in source and binary forms, with or without 32610f2ef3SScott Long * modification, are permitted provided that the following conditions 33610f2ef3SScott Long * are met: 34610f2ef3SScott Long * 1. Redistributions of source code must retain the above copyright 35610f2ef3SScott Long * notice, this list of conditions and the following disclaimer. 36610f2ef3SScott Long * 2. Redistributions in binary form must reproduce the above copyright 37610f2ef3SScott Long * notice, this list of conditions and the following disclaimer in the 38610f2ef3SScott Long * documentation and/or other materials provided with the distribution. 39610f2ef3SScott Long * 40610f2ef3SScott Long * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 41610f2ef3SScott Long * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42610f2ef3SScott Long * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43610f2ef3SScott Long * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 44610f2ef3SScott Long * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 45610f2ef3SScott Long * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 46610f2ef3SScott Long * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 47610f2ef3SScott Long * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 48610f2ef3SScott Long * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49610f2ef3SScott Long * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50610f2ef3SScott Long * SUCH DAMAGE. 51610f2ef3SScott Long */ 522e21a3efSScott Long 532e21a3efSScott Long #ifndef _MFIVAR_H 542e21a3efSScott Long #define _MFIVAR_H 552e21a3efSScott Long 562e21a3efSScott Long #include <sys/cdefs.h> 572e21a3efSScott Long __FBSDID("$FreeBSD$"); 582e21a3efSScott Long 598ec5c98bSJohn Baldwin #include <sys/lock.h> 608ec5c98bSJohn Baldwin #include <sys/sx.h> 618ec5c98bSJohn Baldwin 620d9a4ef3SDoug Ambrisko #include <sys/types.h> 63a6ba0fd6SDoug Ambrisko #include <sys/taskqueue.h> 64*cf72e893SSean Bruno #include "opt_mfi.h" 650d9a4ef3SDoug Ambrisko 662e21a3efSScott Long /* 672e21a3efSScott Long * SCSI structures and definitions are used from here, but no linking 682e21a3efSScott Long * requirements are made to CAM. 692e21a3efSScott Long */ 702e21a3efSScott Long #include <cam/scsi/scsi_all.h> 712e21a3efSScott Long 722e21a3efSScott Long struct mfi_hwcomms { 732e21a3efSScott Long uint32_t hw_pi; 742e21a3efSScott Long uint32_t hw_ci; 752e21a3efSScott Long uint32_t hw_reply_q[1]; 762e21a3efSScott Long }; 770d9a4ef3SDoug Ambrisko #define MEGASAS_MAX_NAME 32 780d9a4ef3SDoug Ambrisko #define MEGASAS_VERSION "4.23" 792e21a3efSScott Long 802e21a3efSScott Long struct mfi_softc; 81ddfae47bSScott Long struct disk; 8235ef86f2SScott Long struct ccb_hdr; 832e21a3efSScott Long 842e21a3efSScott Long struct mfi_command { 852e21a3efSScott Long TAILQ_ENTRY(mfi_command) cm_link; 865ba21ff1SScott Long time_t cm_timestamp; 872e21a3efSScott Long struct mfi_softc *cm_sc; 882e21a3efSScott Long union mfi_frame *cm_frame; 890d9a4ef3SDoug Ambrisko bus_addr_t cm_frame_busaddr; 902e21a3efSScott Long struct mfi_sense *cm_sense; 910d9a4ef3SDoug Ambrisko bus_addr_t cm_sense_busaddr; 922e21a3efSScott Long bus_dmamap_t cm_dmamap; 932e21a3efSScott Long union mfi_sgl *cm_sg; 942e21a3efSScott Long void *cm_data; 952e21a3efSScott Long int cm_len; 965f8ad41cSAlexander Motin int cm_stp_len; 972e21a3efSScott Long int cm_total_frame_size; 982e21a3efSScott Long int cm_extra_frames; 992e21a3efSScott Long int cm_flags; 1002e21a3efSScott Long #define MFI_CMD_MAPPED (1<<0) 1012e21a3efSScott Long #define MFI_CMD_DATAIN (1<<1) 1022e21a3efSScott Long #define MFI_CMD_DATAOUT (1<<2) 1032e21a3efSScott Long #define MFI_CMD_COMPLETED (1<<3) 1042e21a3efSScott Long #define MFI_CMD_POLLED (1<<4) 1052e21a3efSScott Long #define MFI_ON_MFIQ_FREE (1<<5) 1062e21a3efSScott Long #define MFI_ON_MFIQ_READY (1<<6) 1072e21a3efSScott Long #define MFI_ON_MFIQ_BUSY (1<<7) 1082e21a3efSScott Long #define MFI_ON_MFIQ_MASK ((1<<5)|(1<<6)|(1<<7)) 1090d9a4ef3SDoug Ambrisko uint8_t retry_for_fw_reset; 1102e21a3efSScott Long void (* cm_complete)(struct mfi_command *cm); 1112e21a3efSScott Long void *cm_private; 1125ba21ff1SScott Long int cm_index; 1135be25877SDoug Ambrisko int cm_error; 1142e21a3efSScott Long }; 1152e21a3efSScott Long 116ddfae47bSScott Long struct mfi_disk { 117ddfae47bSScott Long TAILQ_ENTRY(mfi_disk) ld_link; 118ddfae47bSScott Long device_t ld_dev; 1192e21a3efSScott Long int ld_id; 120ddfae47bSScott Long int ld_unit; 121ddfae47bSScott Long struct mfi_softc *ld_controller; 122ddfae47bSScott Long struct mfi_ld_info *ld_info; 123ddfae47bSScott Long struct disk *ld_disk; 124ddfae47bSScott Long int ld_flags; 125ddfae47bSScott Long #define MFI_DISK_FLAGS_OPEN 0x01 1268ec5c98bSJohn Baldwin #define MFI_DISK_FLAGS_DISABLED 0x02 1272e21a3efSScott Long }; 1282e21a3efSScott Long 1290d9a4ef3SDoug Ambrisko struct mfi_system_pd { 1300d9a4ef3SDoug Ambrisko TAILQ_ENTRY(mfi_system_pd) pd_link; 1310d9a4ef3SDoug Ambrisko device_t pd_dev; 1320d9a4ef3SDoug Ambrisko int pd_id; 1330d9a4ef3SDoug Ambrisko int pd_unit; 1340d9a4ef3SDoug Ambrisko struct mfi_softc *pd_controller; 1350d9a4ef3SDoug Ambrisko struct mfi_pd_info *pd_info; 1360d9a4ef3SDoug Ambrisko struct disk *pd_disk; 1370d9a4ef3SDoug Ambrisko int pd_flags; 1380d9a4ef3SDoug Ambrisko }; 139a6ba0fd6SDoug Ambrisko 140a6ba0fd6SDoug Ambrisko struct mfi_evt_queue_elm { 141a6ba0fd6SDoug Ambrisko TAILQ_ENTRY(mfi_evt_queue_elm) link; 142a6ba0fd6SDoug Ambrisko struct mfi_evt_detail detail; 143a6ba0fd6SDoug Ambrisko }; 144a6ba0fd6SDoug Ambrisko 145741367d5SDoug Ambrisko struct mfi_aen { 146741367d5SDoug Ambrisko TAILQ_ENTRY(mfi_aen) aen_link; 147741367d5SDoug Ambrisko struct proc *p; 148741367d5SDoug Ambrisko }; 149741367d5SDoug Ambrisko 1500d9a4ef3SDoug Ambrisko struct mfi_skinny_dma_info { 1510d9a4ef3SDoug Ambrisko bus_dma_tag_t dmat[514]; 1520d9a4ef3SDoug Ambrisko bus_dmamap_t dmamap[514]; 1530d9a4ef3SDoug Ambrisko uint32_t mem[514]; 1540d9a4ef3SDoug Ambrisko int noofmaps; 1550d9a4ef3SDoug Ambrisko }; 1560d9a4ef3SDoug Ambrisko 1577e4dd9e1SDoug Ambrisko struct megasas_sge 1587e4dd9e1SDoug Ambrisko { 1597e4dd9e1SDoug Ambrisko bus_addr_t phys_addr; 1607e4dd9e1SDoug Ambrisko uint32_t length; 1617e4dd9e1SDoug Ambrisko }; 1627e4dd9e1SDoug Ambrisko 1630d9a4ef3SDoug Ambrisko struct mfi_cmd_tbolt; 1640d9a4ef3SDoug Ambrisko 1652e21a3efSScott Long struct mfi_softc { 1662e21a3efSScott Long device_t mfi_dev; 1672e21a3efSScott Long int mfi_flags; 1682e21a3efSScott Long #define MFI_FLAGS_SG64 (1<<0) 1692e21a3efSScott Long #define MFI_FLAGS_QFRZN (1<<1) 1702e21a3efSScott Long #define MFI_FLAGS_OPEN (1<<2) 171441f6d5dSScott Long #define MFI_FLAGS_STOP (1<<3) 172610f2ef3SScott Long #define MFI_FLAGS_1064R (1<<4) 173610f2ef3SScott Long #define MFI_FLAGS_1078 (1<<5) 174fa1e6ef4SDoug Ambrisko #define MFI_FLAGS_GEN2 (1<<6) 1750d9a4ef3SDoug Ambrisko #define MFI_FLAGS_SKINNY (1<<7) 1760d9a4ef3SDoug Ambrisko #define MFI_FLAGS_TBOLT (1<<8) 1770d9a4ef3SDoug Ambrisko // Start: LSIP200113393 1780d9a4ef3SDoug Ambrisko bus_dma_tag_t verbuf_h_dmat; 1790d9a4ef3SDoug Ambrisko bus_dmamap_t verbuf_h_dmamap; 1809a4e738aSSean Bruno bus_addr_t verbuf_h_busaddr; 1810d9a4ef3SDoug Ambrisko uint32_t *verbuf; 1820d9a4ef3SDoug Ambrisko void *kbuff_arr[MAX_IOCTL_SGE]; 1830d9a4ef3SDoug Ambrisko bus_dma_tag_t mfi_kbuff_arr_dmat[2]; 1840d9a4ef3SDoug Ambrisko bus_dmamap_t mfi_kbuff_arr_dmamap[2]; 185a6ba0fd6SDoug Ambrisko bus_addr_t mfi_kbuff_arr_busaddr[2]; 1862e21a3efSScott Long 1872e21a3efSScott Long struct mfi_hwcomms *mfi_comms; 1882e21a3efSScott Long TAILQ_HEAD(,mfi_command) mfi_free; 1892e21a3efSScott Long TAILQ_HEAD(,mfi_command) mfi_ready; 1900d9a4ef3SDoug Ambrisko TAILQ_HEAD(BUSYQ,mfi_command) mfi_busy; 1912e21a3efSScott Long struct bio_queue_head mfi_bioq; 1922e21a3efSScott Long struct mfi_qstat mfi_qstat[MFIQ_COUNT]; 1932e21a3efSScott Long 1942e21a3efSScott Long struct resource *mfi_regs_resource; 1952e21a3efSScott Long bus_space_handle_t mfi_bhandle; 1962e21a3efSScott Long bus_space_tag_t mfi_btag; 1972e21a3efSScott Long int mfi_regs_rid; 1982e21a3efSScott Long 1992e21a3efSScott Long bus_dma_tag_t mfi_parent_dmat; 2002e21a3efSScott Long bus_dma_tag_t mfi_buffer_dmat; 2012e21a3efSScott Long 2022e21a3efSScott Long bus_dma_tag_t mfi_comms_dmat; 2032e21a3efSScott Long bus_dmamap_t mfi_comms_dmamap; 204a6ba0fd6SDoug Ambrisko bus_addr_t mfi_comms_busaddr; 2052e21a3efSScott Long 2062e21a3efSScott Long bus_dma_tag_t mfi_frames_dmat; 2072e21a3efSScott Long bus_dmamap_t mfi_frames_dmamap; 208a6ba0fd6SDoug Ambrisko bus_addr_t mfi_frames_busaddr; 2092e21a3efSScott Long union mfi_frame *mfi_frames; 2102e21a3efSScott Long 2110d9a4ef3SDoug Ambrisko bus_dma_tag_t mfi_tb_init_dmat; 2120d9a4ef3SDoug Ambrisko bus_dmamap_t mfi_tb_init_dmamap; 213a6ba0fd6SDoug Ambrisko bus_addr_t mfi_tb_init_busaddr; 214a6ba0fd6SDoug Ambrisko bus_addr_t mfi_tb_ioc_init_busaddr; 2150d9a4ef3SDoug Ambrisko union mfi_frame *mfi_tb_init; 2160d9a4ef3SDoug Ambrisko 217a6ba0fd6SDoug Ambrisko TAILQ_HEAD(,mfi_evt_queue_elm) mfi_evt_queue; 218a6ba0fd6SDoug Ambrisko struct task mfi_evt_task; 219ddbffe7fSDoug Ambrisko struct task mfi_map_sync_task; 220741367d5SDoug Ambrisko TAILQ_HEAD(,mfi_aen) mfi_aen_pids; 221741367d5SDoug Ambrisko struct mfi_command *mfi_aen_cm; 2220d9a4ef3SDoug Ambrisko struct mfi_command *mfi_skinny_cm; 223ddbffe7fSDoug Ambrisko struct mfi_command *mfi_map_sync_cm; 224ddbffe7fSDoug Ambrisko int cm_aen_abort; 225ddbffe7fSDoug Ambrisko int cm_map_abort; 226741367d5SDoug Ambrisko uint32_t mfi_aen_triggered; 227741367d5SDoug Ambrisko uint32_t mfi_poll_waiting; 228a6ba0fd6SDoug Ambrisko uint32_t mfi_boot_seq_num; 229741367d5SDoug Ambrisko struct selinfo mfi_select; 2308ec5c98bSJohn Baldwin int mfi_delete_busy_volumes; 2318ec5c98bSJohn Baldwin int mfi_keep_deleted_volumes; 2328ec5c98bSJohn Baldwin int mfi_detaching; 233741367d5SDoug Ambrisko 2342e21a3efSScott Long bus_dma_tag_t mfi_sense_dmat; 2352e21a3efSScott Long bus_dmamap_t mfi_sense_dmamap; 2369a4e738aSSean Bruno bus_addr_t mfi_sense_busaddr; 2372e21a3efSScott Long struct mfi_sense *mfi_sense; 2382e21a3efSScott Long 2392e21a3efSScott Long struct resource *mfi_irq; 2402e21a3efSScott Long void *mfi_intr; 2412e21a3efSScott Long int mfi_irq_rid; 2422e21a3efSScott Long 2432e21a3efSScott Long struct intr_config_hook mfi_ich; 2442e21a3efSScott Long eventhandler_tag eh; 2450d9a4ef3SDoug Ambrisko /* OCR flags */ 2460d9a4ef3SDoug Ambrisko uint8_t adpreset; 2470d9a4ef3SDoug Ambrisko uint8_t issuepend_done; 2480d9a4ef3SDoug Ambrisko uint8_t disableOnlineCtrlReset; 2490d9a4ef3SDoug Ambrisko uint32_t mfiStatus; 2500d9a4ef3SDoug Ambrisko uint32_t last_seq_num; 2510d9a4ef3SDoug Ambrisko uint32_t volatile hw_crit_error; 2522e21a3efSScott Long 2532e21a3efSScott Long /* 2542e21a3efSScott Long * Allocation for the command array. Used as an indexable array to 2552e21a3efSScott Long * recover completed commands. 2562e21a3efSScott Long */ 2572e21a3efSScott Long struct mfi_command *mfi_commands; 2582e21a3efSScott Long /* 2592e21a3efSScott Long * How many commands were actually allocated 2602e21a3efSScott Long */ 2612e21a3efSScott Long int mfi_total_cmds; 2622e21a3efSScott Long /* 2632e21a3efSScott Long * How many commands the firmware can handle. Also how big the reply 2642e21a3efSScott Long * queue is, minus 1. 2652e21a3efSScott Long */ 2662e21a3efSScott Long int mfi_max_fw_cmds; 2672e21a3efSScott Long /* 2682e21a3efSScott Long * How many S/G elements we'll ever actually use 2692e21a3efSScott Long */ 27078e36c27SScott Long int mfi_max_sge; 2712e21a3efSScott Long /* 2722e21a3efSScott Long * How many bytes a compound frame is, including all of the extra frames 2732e21a3efSScott Long * that are used for S/G elements. 2742e21a3efSScott Long */ 27578e36c27SScott Long int mfi_cmd_size; 2762e21a3efSScott Long /* 2772e21a3efSScott Long * How large an S/G element is. Used to calculate the number of single 2782e21a3efSScott Long * frames in a command. 2792e21a3efSScott Long */ 28078e36c27SScott Long int mfi_sge_size; 2812e21a3efSScott Long /* 2822e21a3efSScott Long * Max number of sectors that the firmware allows 2832e21a3efSScott Long */ 2842e21a3efSScott Long uint32_t mfi_max_io; 2852e21a3efSScott Long 286ddfae47bSScott Long TAILQ_HEAD(,mfi_disk) mfi_ld_tqh; 2870d9a4ef3SDoug Ambrisko TAILQ_HEAD(,mfi_system_pd) mfi_syspd_tqh; 2882e21a3efSScott Long eventhandler_tag mfi_eh; 2892e21a3efSScott Long struct cdev *mfi_cdev; 2902e21a3efSScott Long 29135ef86f2SScott Long TAILQ_HEAD(, ccb_hdr) mfi_cam_ccbq; 29235ef86f2SScott Long struct mfi_command * (* mfi_cam_start)(void *); 2935ba21ff1SScott Long struct callout mfi_watchdog_callout; 2942e21a3efSScott Long struct mtx mfi_io_lock; 2958ec5c98bSJohn Baldwin struct sx mfi_config_lock; 296610f2ef3SScott Long 297610f2ef3SScott Long /* Controller type specific interfaces */ 298610f2ef3SScott Long void (*mfi_enable_intr)(struct mfi_softc *sc); 2990d9a4ef3SDoug Ambrisko void (*mfi_disable_intr)(struct mfi_softc *sc); 300610f2ef3SScott Long int32_t (*mfi_read_fw_status)(struct mfi_softc *sc); 301610f2ef3SScott Long int (*mfi_check_clear_intr)(struct mfi_softc *sc); 302a6ba0fd6SDoug Ambrisko void (*mfi_issue_cmd)(struct mfi_softc *sc, bus_addr_t bus_add, 303a6ba0fd6SDoug Ambrisko uint32_t frame_cnt); 3040d9a4ef3SDoug Ambrisko int (*mfi_adp_reset)(struct mfi_softc *sc); 3050d9a4ef3SDoug Ambrisko int (*mfi_adp_check_reset)(struct mfi_softc *sc); 3060d9a4ef3SDoug Ambrisko 3070d9a4ef3SDoug Ambrisko /* ThunderBolt */ 3080d9a4ef3SDoug Ambrisko uint32_t mfi_tbolt; 3090d9a4ef3SDoug Ambrisko uint32_t MFA_enabled; 310a6ba0fd6SDoug Ambrisko /* Single Reply structure size */ 311a6ba0fd6SDoug Ambrisko uint16_t reply_size; 312a6ba0fd6SDoug Ambrisko /* Singler message size. */ 313a6ba0fd6SDoug Ambrisko uint16_t raid_io_msg_size; 3140d9a4ef3SDoug Ambrisko TAILQ_HEAD(TB, mfi_cmd_tbolt) mfi_cmd_tbolt_tqh; 315a6ba0fd6SDoug Ambrisko /* ThunderBolt base contiguous memory mapping. */ 316a6ba0fd6SDoug Ambrisko bus_dma_tag_t mfi_tb_dmat; 3170d9a4ef3SDoug Ambrisko bus_dmamap_t mfi_tb_dmamap; 318a6ba0fd6SDoug Ambrisko bus_addr_t mfi_tb_busaddr; 319a6ba0fd6SDoug Ambrisko /* ThunderBolt Contiguous DMA memory Mapping */ 320a6ba0fd6SDoug Ambrisko uint8_t * request_message_pool; 3210d9a4ef3SDoug Ambrisko uint8_t * request_message_pool_align; 3220d9a4ef3SDoug Ambrisko uint8_t * request_desc_pool; 323a6ba0fd6SDoug Ambrisko bus_addr_t request_msg_busaddr; 324a6ba0fd6SDoug Ambrisko bus_addr_t reply_frame_busaddr; 325a6ba0fd6SDoug Ambrisko bus_addr_t sg_frame_busaddr; 326a6ba0fd6SDoug Ambrisko /* ThunderBolt IOC Init Descriptor */ 327a6ba0fd6SDoug Ambrisko bus_dma_tag_t mfi_tb_ioc_init_dmat; 3280d9a4ef3SDoug Ambrisko bus_dmamap_t mfi_tb_ioc_init_dmamap; 3290d9a4ef3SDoug Ambrisko uint8_t * mfi_tb_ioc_init_desc; 3300d9a4ef3SDoug Ambrisko struct mfi_cmd_tbolt **mfi_cmd_pool_tbolt; 331a6ba0fd6SDoug Ambrisko /* Virtual address of reply Frame Pool */ 332a6ba0fd6SDoug Ambrisko struct mfi_mpi2_reply_header* reply_frame_pool; 3330d9a4ef3SDoug Ambrisko struct mfi_mpi2_reply_header* reply_frame_pool_align; 3340d9a4ef3SDoug Ambrisko 335a6ba0fd6SDoug Ambrisko /* Last reply frame address */ 336a6ba0fd6SDoug Ambrisko uint8_t * reply_pool_limit; 3370d9a4ef3SDoug Ambrisko uint16_t last_reply_idx; 3380d9a4ef3SDoug Ambrisko uint8_t max_SGEs_in_chain_message; 3390d9a4ef3SDoug Ambrisko uint8_t max_SGEs_in_main_message; 3400d9a4ef3SDoug Ambrisko uint8_t chain_offset_value_for_main_message; 3410d9a4ef3SDoug Ambrisko uint8_t chain_offset_value_for_mpt_ptmsg; 3420d9a4ef3SDoug Ambrisko }; 3430d9a4ef3SDoug Ambrisko 3440d9a4ef3SDoug Ambrisko union desc_value { 3450d9a4ef3SDoug Ambrisko uint64_t word; 3460d9a4ef3SDoug Ambrisko struct { 3470d9a4ef3SDoug Ambrisko uint32_t low; 3480d9a4ef3SDoug Ambrisko uint32_t high; 3490d9a4ef3SDoug Ambrisko }u; 3500d9a4ef3SDoug Ambrisko }; 3510d9a4ef3SDoug Ambrisko 3520d9a4ef3SDoug Ambrisko // TODO find the right definition 3530d9a4ef3SDoug Ambrisko #define XXX_MFI_CMD_OP_INIT2 0x9 3540d9a4ef3SDoug Ambrisko /* 3550d9a4ef3SDoug Ambrisko * Request descriptor types 3560d9a4ef3SDoug Ambrisko */ 3570d9a4ef3SDoug Ambrisko #define MFI_REQ_DESCRIPT_FLAGS_LD_IO 0x7 3580d9a4ef3SDoug Ambrisko #define MFI_REQ_DESCRIPT_FLAGS_MFA 0x1 3590d9a4ef3SDoug Ambrisko #define MFI_REQ_DESCRIPT_FLAGS_TYPE_SHIFT 0x1 3600d9a4ef3SDoug Ambrisko #define MFI_FUSION_FP_DEFAULT_TIMEOUT 0x14 3610d9a4ef3SDoug Ambrisko #define MFI_LOAD_BALANCE_FLAG 0x1 3620d9a4ef3SDoug Ambrisko #define MFI_DCMD_MBOX_PEND_FLAG 0x1 3630d9a4ef3SDoug Ambrisko 3640d9a4ef3SDoug Ambrisko //#define MR_PROT_INFO_TYPE_CONTROLLER 0x08 3650d9a4ef3SDoug Ambrisko #define MEGASAS_SCSI_VARIABLE_LENGTH_CMD 0x7f 3660d9a4ef3SDoug Ambrisko #define MEGASAS_SCSI_SERVICE_ACTION_READ32 0x9 3670d9a4ef3SDoug Ambrisko #define MEGASAS_SCSI_SERVICE_ACTION_WRITE32 0xB 3680d9a4ef3SDoug Ambrisko #define MEGASAS_SCSI_ADDL_CDB_LEN 0x18 3690d9a4ef3SDoug Ambrisko #define MEGASAS_RD_WR_PROTECT_CHECK_ALL 0x20 3700d9a4ef3SDoug Ambrisko #define MEGASAS_RD_WR_PROTECT_CHECK_NONE 0x60 3710d9a4ef3SDoug Ambrisko #define MEGASAS_EEDPBLOCKSIZE 512 3720d9a4ef3SDoug Ambrisko struct mfi_cmd_tbolt { 3730d9a4ef3SDoug Ambrisko union mfi_mpi2_request_descriptor *request_desc; 3740d9a4ef3SDoug Ambrisko struct mfi_mpi2_request_raid_scsi_io *io_request; 375a6ba0fd6SDoug Ambrisko bus_addr_t io_request_phys_addr; 376a6ba0fd6SDoug Ambrisko bus_addr_t sg_frame_phys_addr; 377a6ba0fd6SDoug Ambrisko bus_addr_t sense_phys_addr; 3780d9a4ef3SDoug Ambrisko MPI2_SGE_IO_UNION *sg_frame; 3790d9a4ef3SDoug Ambrisko uint8_t *sense; 3800d9a4ef3SDoug Ambrisko TAILQ_ENTRY(mfi_cmd_tbolt) next; 3810d9a4ef3SDoug Ambrisko /* 3820d9a4ef3SDoug Ambrisko * Context for a MFI frame. 3830d9a4ef3SDoug Ambrisko * Used to get the mfi cmd from list when a MFI cmd is completed 3840d9a4ef3SDoug Ambrisko */ 3850d9a4ef3SDoug Ambrisko uint32_t sync_cmd_idx; 3860d9a4ef3SDoug Ambrisko uint16_t index; 3870d9a4ef3SDoug Ambrisko uint8_t status; 3882e21a3efSScott Long }; 3892e21a3efSScott Long 3902e21a3efSScott Long extern int mfi_attach(struct mfi_softc *); 3912e21a3efSScott Long extern void mfi_free(struct mfi_softc *); 3922e21a3efSScott Long extern int mfi_shutdown(struct mfi_softc *); 3932e21a3efSScott Long extern void mfi_startio(struct mfi_softc *); 3942e21a3efSScott Long extern void mfi_disk_complete(struct bio *); 3958ec5c98bSJohn Baldwin extern int mfi_disk_disable(struct mfi_disk *); 3968ec5c98bSJohn Baldwin extern void mfi_disk_enable(struct mfi_disk *); 3972e21a3efSScott Long extern int mfi_dump_blocks(struct mfi_softc *, int id, uint64_t, void *, int); 3980d9a4ef3SDoug Ambrisko extern int mfi_syspd_disable(struct mfi_system_pd *); 3990d9a4ef3SDoug Ambrisko extern void mfi_syspd_enable(struct mfi_system_pd *); 4000d9a4ef3SDoug Ambrisko extern int mfi_dump_syspd_blocks(struct mfi_softc *, int id, uint64_t, void *, 4010d9a4ef3SDoug Ambrisko int); 4020d9a4ef3SDoug Ambrisko extern int mfi_transition_firmware(struct mfi_softc *sc); 4030d9a4ef3SDoug Ambrisko extern int mfi_aen_setup(struct mfi_softc *sc, uint32_t seq_start); 4040d9a4ef3SDoug Ambrisko extern void mfi_complete(struct mfi_softc *sc, struct mfi_command *cm); 4050d9a4ef3SDoug Ambrisko extern int mfi_mapcmd(struct mfi_softc *sc,struct mfi_command *cm); 4060d9a4ef3SDoug Ambrisko extern int mfi_wait_command(struct mfi_softc *sc, struct mfi_command *cm); 4070d9a4ef3SDoug Ambrisko extern void mfi_tbolt_enable_intr_ppc(struct mfi_softc *); 4080d9a4ef3SDoug Ambrisko extern void mfi_tbolt_disable_intr_ppc(struct mfi_softc *); 4090d9a4ef3SDoug Ambrisko extern int32_t mfi_tbolt_read_fw_status_ppc(struct mfi_softc *); 4100d9a4ef3SDoug Ambrisko extern int32_t mfi_tbolt_check_clear_intr_ppc(struct mfi_softc *); 4110d9a4ef3SDoug Ambrisko extern void mfi_tbolt_issue_cmd_ppc(struct mfi_softc *, bus_addr_t, uint32_t); 4120d9a4ef3SDoug Ambrisko extern void mfi_tbolt_init_globals(struct mfi_softc*); 4130d9a4ef3SDoug Ambrisko extern uint32_t mfi_tbolt_get_memory_requirement(struct mfi_softc *); 4140d9a4ef3SDoug Ambrisko extern int mfi_tbolt_init_desc_pool(struct mfi_softc *, uint8_t *, uint32_t); 4150d9a4ef3SDoug Ambrisko extern int mfi_tbolt_init_MFI_queue(struct mfi_softc *); 4160d9a4ef3SDoug Ambrisko extern void mfi_intr_tbolt(void *arg); 4170d9a4ef3SDoug Ambrisko extern int mfi_tbolt_alloc_cmd(struct mfi_softc *sc); 4180d9a4ef3SDoug Ambrisko extern int mfi_tbolt_send_frame(struct mfi_softc *sc, struct mfi_command *cm); 4190d9a4ef3SDoug Ambrisko extern int mfi_tbolt_adp_reset(struct mfi_softc *sc); 4200d9a4ef3SDoug Ambrisko extern int mfi_tbolt_reset(struct mfi_softc *sc); 421ddbffe7fSDoug Ambrisko extern void mfi_tbolt_sync_map_info(struct mfi_softc *sc); 422ddbffe7fSDoug Ambrisko extern void mfi_handle_map_sync(void *context, int pending); 423ddbffe7fSDoug Ambrisko extern int mfi_dcmd_command(struct mfi_softc *, struct mfi_command **, 424ddbffe7fSDoug Ambrisko uint32_t, void **, size_t); 4252e21a3efSScott Long 4262e21a3efSScott Long #define MFIQ_ADD(sc, qname) \ 4272e21a3efSScott Long do { \ 4282e21a3efSScott Long struct mfi_qstat *qs; \ 4292e21a3efSScott Long \ 4302e21a3efSScott Long qs = &(sc)->mfi_qstat[qname]; \ 4312e21a3efSScott Long qs->q_length++; \ 4322e21a3efSScott Long if (qs->q_length > qs->q_max) \ 4332e21a3efSScott Long qs->q_max = qs->q_length; \ 4342e21a3efSScott Long } while (0) 4352e21a3efSScott Long 4362e21a3efSScott Long #define MFIQ_REMOVE(sc, qname) (sc)->mfi_qstat[qname].q_length-- 4372e21a3efSScott Long 4382e21a3efSScott Long #define MFIQ_INIT(sc, qname) \ 4392e21a3efSScott Long do { \ 4402e21a3efSScott Long sc->mfi_qstat[qname].q_length = 0; \ 4412e21a3efSScott Long sc->mfi_qstat[qname].q_max = 0; \ 4422e21a3efSScott Long } while (0) 4432e21a3efSScott Long 4442e21a3efSScott Long #define MFIQ_COMMAND_QUEUE(name, index) \ 4452e21a3efSScott Long static __inline void \ 4462e21a3efSScott Long mfi_initq_ ## name (struct mfi_softc *sc) \ 4472e21a3efSScott Long { \ 4482e21a3efSScott Long TAILQ_INIT(&sc->mfi_ ## name); \ 4492e21a3efSScott Long MFIQ_INIT(sc, index); \ 4502e21a3efSScott Long } \ 4512e21a3efSScott Long static __inline void \ 4522e21a3efSScott Long mfi_enqueue_ ## name (struct mfi_command *cm) \ 4532e21a3efSScott Long { \ 4542e21a3efSScott Long if ((cm->cm_flags & MFI_ON_MFIQ_MASK) != 0) { \ 4552e21a3efSScott Long printf("command %p is on another queue, " \ 4562e21a3efSScott Long "flags = %#x\n", cm, cm->cm_flags); \ 4572e21a3efSScott Long panic("command is on another queue"); \ 4582e21a3efSScott Long } \ 4592e21a3efSScott Long TAILQ_INSERT_TAIL(&cm->cm_sc->mfi_ ## name, cm, cm_link); \ 4602e21a3efSScott Long cm->cm_flags |= MFI_ON_ ## index; \ 4612e21a3efSScott Long MFIQ_ADD(cm->cm_sc, index); \ 4622e21a3efSScott Long } \ 4632e21a3efSScott Long static __inline void \ 4642e21a3efSScott Long mfi_requeue_ ## name (struct mfi_command *cm) \ 4652e21a3efSScott Long { \ 4662e21a3efSScott Long if ((cm->cm_flags & MFI_ON_MFIQ_MASK) != 0) { \ 4672e21a3efSScott Long printf("command %p is on another queue, " \ 4682e21a3efSScott Long "flags = %#x\n", cm, cm->cm_flags); \ 4692e21a3efSScott Long panic("command is on another queue"); \ 4702e21a3efSScott Long } \ 4712e21a3efSScott Long TAILQ_INSERT_HEAD(&cm->cm_sc->mfi_ ## name, cm, cm_link); \ 4722e21a3efSScott Long cm->cm_flags |= MFI_ON_ ## index; \ 4732e21a3efSScott Long MFIQ_ADD(cm->cm_sc, index); \ 4742e21a3efSScott Long } \ 4752e21a3efSScott Long static __inline struct mfi_command * \ 4762e21a3efSScott Long mfi_dequeue_ ## name (struct mfi_softc *sc) \ 4772e21a3efSScott Long { \ 4782e21a3efSScott Long struct mfi_command *cm; \ 4792e21a3efSScott Long \ 4802e21a3efSScott Long if ((cm = TAILQ_FIRST(&sc->mfi_ ## name)) != NULL) { \ 4812e21a3efSScott Long if ((cm->cm_flags & MFI_ON_ ## index) == 0) { \ 4822e21a3efSScott Long printf("command %p not in queue, " \ 4832e21a3efSScott Long "flags = %#x, bit = %#x\n", cm, \ 4842e21a3efSScott Long cm->cm_flags, MFI_ON_ ## index); \ 4852e21a3efSScott Long panic("command not in queue"); \ 4862e21a3efSScott Long } \ 4872e21a3efSScott Long TAILQ_REMOVE(&sc->mfi_ ## name, cm, cm_link); \ 4882e21a3efSScott Long cm->cm_flags &= ~MFI_ON_ ## index; \ 4892e21a3efSScott Long MFIQ_REMOVE(sc, index); \ 4902e21a3efSScott Long } \ 4912e21a3efSScott Long return (cm); \ 4922e21a3efSScott Long } \ 4932e21a3efSScott Long static __inline void \ 4942e21a3efSScott Long mfi_remove_ ## name (struct mfi_command *cm) \ 4952e21a3efSScott Long { \ 4962e21a3efSScott Long if ((cm->cm_flags & MFI_ON_ ## index) == 0) { \ 4972e21a3efSScott Long printf("command %p not in queue, flags = %#x, " \ 4982e21a3efSScott Long "bit = %#x\n", cm, cm->cm_flags, \ 4992e21a3efSScott Long MFI_ON_ ## index); \ 5002e21a3efSScott Long panic("command not in queue"); \ 5012e21a3efSScott Long } \ 5022e21a3efSScott Long TAILQ_REMOVE(&cm->cm_sc->mfi_ ## name, cm, cm_link); \ 5032e21a3efSScott Long cm->cm_flags &= ~MFI_ON_ ## index; \ 5042e21a3efSScott Long MFIQ_REMOVE(cm->cm_sc, index); \ 5052e21a3efSScott Long } \ 5062e21a3efSScott Long struct hack 5072e21a3efSScott Long 5082e21a3efSScott Long MFIQ_COMMAND_QUEUE(free, MFIQ_FREE); 5092e21a3efSScott Long MFIQ_COMMAND_QUEUE(ready, MFIQ_READY); 5102e21a3efSScott Long MFIQ_COMMAND_QUEUE(busy, MFIQ_BUSY); 5112e21a3efSScott Long 5122e21a3efSScott Long static __inline void 5132e21a3efSScott Long mfi_initq_bio(struct mfi_softc *sc) 5142e21a3efSScott Long { 5152e21a3efSScott Long bioq_init(&sc->mfi_bioq); 5162e21a3efSScott Long MFIQ_INIT(sc, MFIQ_BIO); 5172e21a3efSScott Long } 5182e21a3efSScott Long 5192e21a3efSScott Long static __inline void 5202e21a3efSScott Long mfi_enqueue_bio(struct mfi_softc *sc, struct bio *bp) 5212e21a3efSScott Long { 5222e21a3efSScott Long bioq_insert_tail(&sc->mfi_bioq, bp); 5232e21a3efSScott Long MFIQ_ADD(sc, MFIQ_BIO); 5242e21a3efSScott Long } 5252e21a3efSScott Long 5262e21a3efSScott Long static __inline struct bio * 5272e21a3efSScott Long mfi_dequeue_bio(struct mfi_softc *sc) 5282e21a3efSScott Long { 5292e21a3efSScott Long struct bio *bp; 5302e21a3efSScott Long 5312e21a3efSScott Long if ((bp = bioq_first(&sc->mfi_bioq)) != NULL) { 5322e21a3efSScott Long bioq_remove(&sc->mfi_bioq, bp); 5332e21a3efSScott Long MFIQ_REMOVE(sc, MFIQ_BIO); 5342e21a3efSScott Long } 5352e21a3efSScott Long return (bp); 5362e21a3efSScott Long } 5372e21a3efSScott Long 53851550f82SScott Long /* 53951550f82SScott Long * This is from the original scsi_extract_sense() in CAM. It's copied 54051550f82SScott Long * here because CAM now uses a non-inline version that follows more complex 54151550f82SScott Long * additions to the SPC spec, and we don't want to force a dependency on 54251550f82SScott Long * the CAM module for such a trivial action. 54351550f82SScott Long */ 54451550f82SScott Long static __inline void 54551550f82SScott Long mfi_extract_sense(struct scsi_sense_data_fixed *sense, 54651550f82SScott Long int *error_code, int *sense_key, int *asc, int *ascq) 54751550f82SScott Long { 54851550f82SScott Long 54951550f82SScott Long *error_code = sense->error_code & SSD_ERRCODE; 55051550f82SScott Long *sense_key = sense->flags & SSD_KEY; 55151550f82SScott Long *asc = (sense->extra_len >= 5) ? sense->add_sense_code : 0; 55251550f82SScott Long *ascq = (sense->extra_len >= 6) ? sense->add_sense_code_qual : 0; 55351550f82SScott Long } 55451550f82SScott Long 5552e21a3efSScott Long static __inline void 5562e21a3efSScott Long mfi_print_sense(struct mfi_softc *sc, void *sense) 5572e21a3efSScott Long { 5582e21a3efSScott Long int error, key, asc, ascq; 5592e21a3efSScott Long 56051550f82SScott Long mfi_extract_sense((struct scsi_sense_data_fixed *)sense, 5612e21a3efSScott Long &error, &key, &asc, &ascq); 5622e21a3efSScott Long device_printf(sc->mfi_dev, "sense error %d, sense_key %d, " 5632e21a3efSScott Long "asc %d, ascq %d\n", error, key, asc, ascq); 5642e21a3efSScott Long } 5652e21a3efSScott Long 5662e21a3efSScott Long 5672e21a3efSScott Long #define MFI_WRITE4(sc, reg, val) bus_space_write_4((sc)->mfi_btag, \ 5682e21a3efSScott Long sc->mfi_bhandle, (reg), (val)) 5692e21a3efSScott Long #define MFI_READ4(sc, reg) bus_space_read_4((sc)->mfi_btag, \ 5702e21a3efSScott Long (sc)->mfi_bhandle, (reg)) 5712e21a3efSScott Long #define MFI_WRITE2(sc, reg, val) bus_space_write_2((sc)->mfi_btag, \ 5722e21a3efSScott Long sc->mfi_bhandle, (reg), (val)) 5732e21a3efSScott Long #define MFI_READ2(sc, reg) bus_space_read_2((sc)->mfi_btag, \ 5742e21a3efSScott Long (sc)->mfi_bhandle, (reg)) 5752e21a3efSScott Long #define MFI_WRITE1(sc, reg, val) bus_space_write_1((sc)->mfi_btag, \ 5762e21a3efSScott Long sc->mfi_bhandle, (reg), (val)) 5772e21a3efSScott Long #define MFI_READ1(sc, reg) bus_space_read_1((sc)->mfi_btag, \ 5782e21a3efSScott Long (sc)->mfi_bhandle, (reg)) 5792e21a3efSScott Long 5802e21a3efSScott Long MALLOC_DECLARE(M_MFIBUF); 581d1c5fc76SJohn Baldwin SYSCTL_DECL(_hw_mfi); 5822e21a3efSScott Long 5830d9a4ef3SDoug Ambrisko #define MFI_RESET_WAIT_TIME 180 5845ba21ff1SScott Long #define MFI_CMD_TIMEOUT 30 5850d9a4ef3SDoug Ambrisko #define MFI_SYS_PD_IO 0 5860d9a4ef3SDoug Ambrisko #define MFI_LD_IO 1 5877e4dd9e1SDoug Ambrisko #define MFI_SKINNY_MEMORY 0x02000000 58852c9ce25SScott Long #define MFI_MAXPHYS (128 * 1024) 5895ba21ff1SScott Long 5905ba21ff1SScott Long #ifdef MFI_DEBUG 5915ba21ff1SScott Long extern void mfi_print_cmd(struct mfi_command *cm); 5925ba21ff1SScott Long extern void mfi_dump_cmds(struct mfi_softc *sc); 593441f6d5dSScott Long extern void mfi_validate_sg(struct mfi_softc *, struct mfi_command *, const char *, int ); 5945ba21ff1SScott Long #define MFI_PRINT_CMD(cm) mfi_print_cmd(cm) 595441f6d5dSScott Long #define MFI_DUMP_CMDS(sc) mfi_dump_cmds(sc) 596441f6d5dSScott Long #define MFI_VALIDATE_CMD(sc, cm) mfi_validate_sg(sc, cm, __FUNCTION__, __LINE__) 5975ba21ff1SScott Long #else 5985ba21ff1SScott Long #define MFI_PRINT_CMD(cm) 5995ba21ff1SScott Long #define MFI_DUMP_CMDS(sc) 600441f6d5dSScott Long #define MFI_VALIDATE_CMD(sc, cm) 6015ba21ff1SScott Long #endif 6025ba21ff1SScott Long 60335ef86f2SScott Long extern void mfi_release_command(struct mfi_command *cm); 60435ef86f2SScott Long 6052e21a3efSScott Long #endif /* _MFIVAR_H */ 606