1fc58801cSScott Long /*- 2fc58801cSScott Long * Copyright (c) 2008 Yahoo!, Inc. 3fc58801cSScott Long * All rights reserved. 4fc58801cSScott Long * Written by: John Baldwin <jhb@FreeBSD.org> 5fc58801cSScott Long * 6fc58801cSScott Long * Redistribution and use in source and binary forms, with or without 7fc58801cSScott Long * modification, are permitted provided that the following conditions 8fc58801cSScott Long * are met: 9fc58801cSScott Long * 1. Redistributions of source code must retain the above copyright 10fc58801cSScott Long * notice, this list of conditions and the following disclaimer. 11fc58801cSScott Long * 2. Redistributions in binary form must reproduce the above copyright 12fc58801cSScott Long * notice, this list of conditions and the following disclaimer in the 13fc58801cSScott Long * documentation and/or other materials provided with the distribution. 14fc58801cSScott Long * 3. Neither the name of the author nor the names of any co-contributors 15fc58801cSScott Long * may be used to endorse or promote products derived from this software 16fc58801cSScott Long * without specific prior written permission. 17fc58801cSScott Long * 18fc58801cSScott Long * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19fc58801cSScott Long * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20fc58801cSScott Long * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21fc58801cSScott Long * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22fc58801cSScott Long * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23fc58801cSScott Long * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24fc58801cSScott Long * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25fc58801cSScott Long * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26fc58801cSScott Long * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27fc58801cSScott Long * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28fc58801cSScott Long * SUCH DAMAGE. 29fc58801cSScott Long * 30fc58801cSScott Long * $FreeBSD$ 31fc58801cSScott Long */ 32fc58801cSScott Long 33fc58801cSScott Long #ifndef __MPTUTIL_H__ 34fc58801cSScott Long #define __MPTUTIL_H__ 35fc58801cSScott Long 36fc58801cSScott Long #include <sys/cdefs.h> 37fc58801cSScott Long #include <sys/linker_set.h> 38fc58801cSScott Long 39fc58801cSScott Long #include <dev/mpt/mpilib/mpi_type.h> 40fc58801cSScott Long #include <dev/mpt/mpilib/mpi.h> 41fc58801cSScott Long #include <dev/mpt/mpilib/mpi_cnfg.h> 42fc58801cSScott Long #include <dev/mpt/mpilib/mpi_raid.h> 43fc58801cSScott Long 44fc58801cSScott Long #define IOC_STATUS_SUCCESS(status) \ 45fc58801cSScott Long (((status) & MPI_IOCSTATUS_MASK) == MPI_IOCSTATUS_SUCCESS) 46fc58801cSScott Long 47fc58801cSScott Long struct mpt_query_disk { 48fc58801cSScott Long char devname[SPECNAMELEN + 1]; 49fc58801cSScott Long }; 50fc58801cSScott Long 51fc58801cSScott Long struct mpt_standalone_disk { 52fc58801cSScott Long uint64_t maxlba; 53fc58801cSScott Long char inqstring[64]; 54fc58801cSScott Long char devname[SPECNAMELEN + 1]; 55fc58801cSScott Long u_int bus; 56fc58801cSScott Long u_int target; 57fc58801cSScott Long }; 58fc58801cSScott Long 59fc58801cSScott Long struct mpt_drive_list { 60fc58801cSScott Long int ndrives; 61fc58801cSScott Long CONFIG_PAGE_RAID_PHYS_DISK_0 *drives[0]; 62fc58801cSScott Long }; 63fc58801cSScott Long 64fc58801cSScott Long struct mptutil_command { 65fc58801cSScott Long const char *name; 66fc58801cSScott Long int (*handler)(int ac, char **av); 67fc58801cSScott Long }; 68fc58801cSScott Long 69fc58801cSScott Long #define MPT_DATASET(name) mptutil_ ## name ## _table 70fc58801cSScott Long 71fc58801cSScott Long #define MPT_COMMAND(set, name, function) \ 72fc58801cSScott Long static struct mptutil_command function ## _mptutil_command = \ 73fc58801cSScott Long { #name, function }; \ 74fc58801cSScott Long DATA_SET(MPT_DATASET(set), function ## _mptutil_command) 75fc58801cSScott Long 76fc58801cSScott Long #define MPT_TABLE(set, name) \ 77fc58801cSScott Long SET_DECLARE(MPT_DATASET(name), struct mptutil_command); \ 78fc58801cSScott Long \ 79fc58801cSScott Long static int \ 80fc58801cSScott Long mptutil_ ## name ## _table_handler(int ac, char **av) \ 81fc58801cSScott Long { \ 82fc58801cSScott Long return (mpt_table_handler(SET_BEGIN(MPT_DATASET(name)), \ 83fc58801cSScott Long SET_LIMIT(MPT_DATASET(name)), ac, av)); \ 84fc58801cSScott Long } \ 85fc58801cSScott Long MPT_COMMAND(set, name, mptutil_ ## name ## _table_handler) 86fc58801cSScott Long 87fc58801cSScott Long extern int mpt_unit; 88fc58801cSScott Long 89fc58801cSScott Long #ifdef DEBUG 90fc58801cSScott Long void hexdump(const void *ptr, int length, const char *hdr, int flags); 91fc58801cSScott Long #define HD_COLUMN_MASK 0xff 92fc58801cSScott Long #define HD_DELIM_MASK 0xff00 93fc58801cSScott Long #define HD_OMIT_COUNT (1 << 16) 94fc58801cSScott Long #define HD_OMIT_HEX (1 << 17) 95fc58801cSScott Long #define HD_OMIT_CHARS (1 << 18) 96fc58801cSScott Long #endif 97fc58801cSScott Long 98fc58801cSScott Long int mpt_table_handler(struct mptutil_command **start, 99fc58801cSScott Long struct mptutil_command **end, int ac, char **av); 100fc58801cSScott Long int mpt_read_config_page_header(int fd, U8 PageType, U8 PageNumber, 101fc58801cSScott Long U32 PageAddress, CONFIG_PAGE_HEADER *header, U16 *IOCStatus); 102fc58801cSScott Long void *mpt_read_config_page(int fd, U8 PageType, U8 PageNumber, 103fc58801cSScott Long U32 PageAddress, U16 *IOCStatus); 104fc58801cSScott Long void *mpt_read_extended_config_page(int fd, U8 ExtPageType, U8 PageVersion, 105fc58801cSScott Long U8 PageNumber, U32 PageAddress, U16 *IOCStatus); 106fc58801cSScott Long int mpt_write_config_page(int fd, void *buf, U16 *IOCStatus); 107fc58801cSScott Long const char *mpt_ioc_status(U16 IOCStatus); 108fc58801cSScott Long int mpt_raid_action(int fd, U8 Action, U8 VolumeBus, U8 VolumeID, 109fc58801cSScott Long U8 PhysDiskNum, U32 ActionDataWord, void *buf, int len, 110fc58801cSScott Long RAID_VOL0_STATUS *VolumeStatus, U32 *ActionData, int datalen, 111fc58801cSScott Long U16 *IOCStatus, U16 *ActionStatus, int write); 112fc58801cSScott Long const char *mpt_raid_status(U16 ActionStatus); 113fc58801cSScott Long int mpt_open(int unit); 114fc58801cSScott Long const char *mpt_raid_level(U8 VolumeType); 115fc58801cSScott Long const char *mpt_volstate(U8 State); 116fc58801cSScott Long const char *mpt_pdstate(CONFIG_PAGE_RAID_PHYS_DISK_0 *info); 117fc58801cSScott Long const char *mpt_pd_inq_string(CONFIG_PAGE_RAID_PHYS_DISK_0 *pd_info); 118fc58801cSScott Long struct mpt_drive_list *mpt_pd_list(int fd); 119fc58801cSScott Long void mpt_free_pd_list(struct mpt_drive_list *list); 120fc58801cSScott Long int mpt_query_disk(U8 VolumeBus, U8 VolumeID, struct mpt_query_disk *qd); 121fc58801cSScott Long const char *mpt_volume_name(U8 VolumeBus, U8 VolumeID); 122fc58801cSScott Long int mpt_fetch_disks(int fd, int *ndisks, 123fc58801cSScott Long struct mpt_standalone_disk **disksp); 124fc58801cSScott Long int mpt_lock_volume(U8 VolumeBus, U8 VolumeID); 125fc58801cSScott Long int mpt_lookup_drive(struct mpt_drive_list *list, const char *drive, 126fc58801cSScott Long U8 *PhysDiskNum); 127fc58801cSScott Long int mpt_lookup_volume(int fd, const char *name, U8 *VolumeBus, 128fc58801cSScott Long U8 *VolumeID); 129fc58801cSScott Long int mpt_rescan_bus(int bus, int id); 130fc58801cSScott Long 131fc58801cSScott Long static __inline void * 132fc58801cSScott Long mpt_read_man_page(int fd, U8 PageNumber, U16 *IOCStatus) 133fc58801cSScott Long { 134fc58801cSScott Long 135fc58801cSScott Long return (mpt_read_config_page(fd, MPI_CONFIG_PAGETYPE_MANUFACTURING, 136fc58801cSScott Long PageNumber, 0, IOCStatus)); 137fc58801cSScott Long } 138fc58801cSScott Long 139fc58801cSScott Long static __inline void * 140fc58801cSScott Long mpt_read_ioc_page(int fd, U8 PageNumber, U16 *IOCStatus) 141fc58801cSScott Long { 142fc58801cSScott Long 143fc58801cSScott Long return (mpt_read_config_page(fd, MPI_CONFIG_PAGETYPE_IOC, PageNumber, 144fc58801cSScott Long 0, IOCStatus)); 145fc58801cSScott Long } 146fc58801cSScott Long 147fc58801cSScott Long static __inline U32 148fc58801cSScott Long mpt_vol_pageaddr(U8 VolumeBus, U8 VolumeID) 149fc58801cSScott Long { 150fc58801cSScott Long 151fc58801cSScott Long return (VolumeBus << 8 | VolumeID); 152fc58801cSScott Long } 153fc58801cSScott Long 154fc58801cSScott Long static __inline CONFIG_PAGE_RAID_VOL_0 * 155fc58801cSScott Long mpt_vol_info(int fd, U8 VolumeBus, U8 VolumeID, U16 *IOCStatus) 156fc58801cSScott Long { 157fc58801cSScott Long 158fc58801cSScott Long return (mpt_read_config_page(fd, MPI_CONFIG_PAGETYPE_RAID_VOLUME, 0, 159fc58801cSScott Long mpt_vol_pageaddr(VolumeBus, VolumeID), IOCStatus)); 160fc58801cSScott Long } 161fc58801cSScott Long 162fc58801cSScott Long static __inline CONFIG_PAGE_RAID_VOL_1 * 163fc58801cSScott Long mpt_vol_names(int fd, U8 VolumeBus, U8 VolumeID, U16 *IOCStatus) 164fc58801cSScott Long { 165fc58801cSScott Long 166fc58801cSScott Long return (mpt_read_config_page(fd, MPI_CONFIG_PAGETYPE_RAID_VOLUME, 1, 167fc58801cSScott Long mpt_vol_pageaddr(VolumeBus, VolumeID), IOCStatus)); 168fc58801cSScott Long } 169fc58801cSScott Long 170fc58801cSScott Long static __inline CONFIG_PAGE_RAID_PHYS_DISK_0 * 171fc58801cSScott Long mpt_pd_info(int fd, U8 PhysDiskNum, U16 *IOCStatus) 172fc58801cSScott Long { 173fc58801cSScott Long 174fc58801cSScott Long return (mpt_read_config_page(fd, MPI_CONFIG_PAGETYPE_RAID_PHYSDISK, 0, 175fc58801cSScott Long PhysDiskNum, IOCStatus)); 176fc58801cSScott Long } 177fc58801cSScott Long 178fc58801cSScott Long #endif /* !__MPTUTIL_H__ */ 179