1b6a7bef2SMike Smith /*- 2b6a7bef2SMike Smith * Copyright (c) 1999 Michael Smith 3b6a7bef2SMike Smith * All rights reserved. 4b6a7bef2SMike Smith * 5b6a7bef2SMike Smith * Redistribution and use in source and binary forms, with or without 6b6a7bef2SMike Smith * modification, are permitted provided that the following conditions 7b6a7bef2SMike Smith * are met: 8b6a7bef2SMike Smith * 1. Redistributions of source code must retain the above copyright 9b6a7bef2SMike Smith * notice, this list of conditions and the following disclaimer. 10b6a7bef2SMike Smith * 2. Redistributions in binary form must reproduce the above copyright 11b6a7bef2SMike Smith * notice, this list of conditions and the following disclaimer in the 12b6a7bef2SMike Smith * documentation and/or other materials provided with the distribution. 13b6a7bef2SMike Smith * 14b6a7bef2SMike Smith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15b6a7bef2SMike Smith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16b6a7bef2SMike Smith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17b6a7bef2SMike Smith * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18b6a7bef2SMike Smith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19b6a7bef2SMike Smith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20b6a7bef2SMike Smith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21b6a7bef2SMike Smith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22b6a7bef2SMike Smith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23b6a7bef2SMike Smith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24b6a7bef2SMike Smith * SUCH DAMAGE. 25b6a7bef2SMike Smith * 26b6a7bef2SMike Smith * $FreeBSD$ 27b6a7bef2SMike Smith */ 28b6a7bef2SMike Smith 29b6a7bef2SMike Smith #include <sys/types.h> 30b6a7bef2SMike Smith #include <stdio.h> 31b6a7bef2SMike Smith #include <paths.h> 32b6a7bef2SMike Smith #include <string.h> 33b6a7bef2SMike Smith 34b6a7bef2SMike Smith #if 0 35b6a7bef2SMike Smith #include <sys/mlxio.h> 36b6a7bef2SMike Smith #include <sys/mlxreg.h> 37b6a7bef2SMike Smith #else 38b6a7bef2SMike Smith #include "../sys/dev/mlx/mlxio.h" 39b6a7bef2SMike Smith #include "../sys/dev/mlx/mlxreg.h" 40b6a7bef2SMike Smith #endif 41b6a7bef2SMike Smith 42b6a7bef2SMike Smith #include "mlxcontrol.h" 43b6a7bef2SMike Smith 44b6a7bef2SMike Smith /******************************************************************************** 45b6a7bef2SMike Smith * Various name-producing and -parsing functions 46b6a7bef2SMike Smith */ 47b6a7bef2SMike Smith 48b6a7bef2SMike Smith /* return path of controller (unit) */ 49b6a7bef2SMike Smith char * 50b6a7bef2SMike Smith ctrlrpath(int unit) 51b6a7bef2SMike Smith { 52b6a7bef2SMike Smith static char buf[32]; 53b6a7bef2SMike Smith 54b6a7bef2SMike Smith sprintf(buf, "%s%s", _PATH_DEV, ctrlrname(unit)); 55b6a7bef2SMike Smith return(buf); 56b6a7bef2SMike Smith } 57b6a7bef2SMike Smith 58b6a7bef2SMike Smith /* return name of controller (unit) */ 59b6a7bef2SMike Smith char * 60b6a7bef2SMike Smith ctrlrname(int unit) 61b6a7bef2SMike Smith { 62b6a7bef2SMike Smith static char buf[32]; 63b6a7bef2SMike Smith 64b6a7bef2SMike Smith sprintf(buf, "mlx%d", unit); 65b6a7bef2SMike Smith return(buf); 66b6a7bef2SMike Smith } 67b6a7bef2SMike Smith 68b6a7bef2SMike Smith /* return path of drive (unit) */ 69b6a7bef2SMike Smith char * 70b6a7bef2SMike Smith drivepath(int unit) 71b6a7bef2SMike Smith { 72b6a7bef2SMike Smith static char buf[32]; 73b6a7bef2SMike Smith 74b6a7bef2SMike Smith sprintf(buf, "%s%s", _PATH_DEV, drivename(unit)); 75b6a7bef2SMike Smith return(buf); 76b6a7bef2SMike Smith } 77b6a7bef2SMike Smith 78b6a7bef2SMike Smith /* return name of drive (unit) */ 79b6a7bef2SMike Smith char * 80b6a7bef2SMike Smith drivename(int unit) 81b6a7bef2SMike Smith { 82b6a7bef2SMike Smith static char buf[32]; 83b6a7bef2SMike Smith 84b6a7bef2SMike Smith sprintf(buf, "mlxd%d", unit); 85b6a7bef2SMike Smith return(buf); 86b6a7bef2SMike Smith } 87b6a7bef2SMike Smith 88b6a7bef2SMike Smith /* get controller unit number from name in (str) */ 89b6a7bef2SMike Smith int 90b6a7bef2SMike Smith ctrlrunit(char *str) 91b6a7bef2SMike Smith { 92b6a7bef2SMike Smith int unit; 93b6a7bef2SMike Smith 94b6a7bef2SMike Smith if (sscanf(str, "mlx%d", &unit) == 1) 95b6a7bef2SMike Smith return(unit); 96b6a7bef2SMike Smith return(-1); 97b6a7bef2SMike Smith } 98b6a7bef2SMike Smith 99b6a7bef2SMike Smith /* get drive unit number from name in (str) */ 100b6a7bef2SMike Smith int 101b6a7bef2SMike Smith driveunit(char *str) 102b6a7bef2SMike Smith { 103b6a7bef2SMike Smith int unit; 104b6a7bef2SMike Smith 105b6a7bef2SMike Smith if (sscanf(str, "mlxd%d", &unit) == 1) 106b6a7bef2SMike Smith return(unit); 107b6a7bef2SMike Smith return(-1); 108b6a7bef2SMike Smith } 109b6a7bef2SMike Smith 110b6a7bef2SMike Smith /******************************************************************************** 111b6a7bef2SMike Smith * Standardised output of various data structures. 112b6a7bef2SMike Smith */ 113b6a7bef2SMike Smith 114b6a7bef2SMike Smith void 115b6a7bef2SMike Smith mlx_print_phys_drv(struct mlx_phys_drv *drv, int chn, int targ, char *prefix, int verbose) 116b6a7bef2SMike Smith { 117b6a7bef2SMike Smith char *type, *device, *vendor, *revision; 118b6a7bef2SMike Smith 119b6a7bef2SMike Smith switch(drv->pd_flags2 & 0x03) { 120b6a7bef2SMike Smith case MLX_PHYS_DRV_DISK: 121b6a7bef2SMike Smith type = "disk"; 122b6a7bef2SMike Smith break; 123b6a7bef2SMike Smith case MLX_PHYS_DRV_SEQUENTIAL: 124b6a7bef2SMike Smith type = "tape"; 125b6a7bef2SMike Smith break; 126b6a7bef2SMike Smith case MLX_PHYS_DRV_CDROM: 127b6a7bef2SMike Smith type= "cdrom"; 128b6a7bef2SMike Smith break; 129b6a7bef2SMike Smith case MLX_PHYS_DRV_OTHER: 130b6a7bef2SMike Smith default: 131b6a7bef2SMike Smith type = "unknown"; 132b6a7bef2SMike Smith break; 133b6a7bef2SMike Smith } 134b6a7bef2SMike Smith printf("%s%s%02d%02d ", prefix, type, chn, targ); 135b6a7bef2SMike Smith switch(drv->pd_status) { 136b6a7bef2SMike Smith case MLX_PHYS_DRV_DEAD: 137b6a7bef2SMike Smith printf(" (dead) "); 138b6a7bef2SMike Smith break; 139b6a7bef2SMike Smith case MLX_PHYS_DRV_WRONLY: 140b6a7bef2SMike Smith printf(" (write-only) "); 141b6a7bef2SMike Smith break; 142b6a7bef2SMike Smith case MLX_PHYS_DRV_ONLINE: 143b6a7bef2SMike Smith printf(" (online) "); 144b6a7bef2SMike Smith break; 145b6a7bef2SMike Smith case MLX_PHYS_DRV_STANDBY: 146b6a7bef2SMike Smith printf(" (standby) "); 147b6a7bef2SMike Smith break; 148b6a7bef2SMike Smith default: 149b6a7bef2SMike Smith printf(" (0x%02x) ", drv->pd_status); 150b6a7bef2SMike Smith } 151b6a7bef2SMike Smith printf("\n"); 152b6a7bef2SMike Smith 153b6a7bef2SMike Smith if (verbose) { 154b6a7bef2SMike Smith 155b6a7bef2SMike Smith printf("%s ", prefix); 156b6a7bef2SMike Smith if (!mlx_scsi_inquiry(0, chn, targ, &vendor, &device, &revision)) { 157b6a7bef2SMike Smith printf("'%8.8s' '%16.16s' '%4.4s'", vendor, device, revision); 158b6a7bef2SMike Smith } else { 159b6a7bef2SMike Smith printf("<IDENTIFY FAILED>"); 160b6a7bef2SMike Smith } 161b6a7bef2SMike Smith 162b6a7bef2SMike Smith printf(" %dMB ", drv->pd_config_size / 2048); 163b6a7bef2SMike Smith 164b6a7bef2SMike Smith if (drv->pd_flags2 & MLX_PHYS_DRV_FAST20) { 165b6a7bef2SMike Smith printf(" fast20"); 166b6a7bef2SMike Smith } else if (drv->pd_flags2 & MLX_PHYS_DRV_FAST) { 167b6a7bef2SMike Smith printf(" fast"); 168b6a7bef2SMike Smith } 169b6a7bef2SMike Smith if (drv->pd_flags2 & MLX_PHYS_DRV_WIDE) 170b6a7bef2SMike Smith printf(" wide"); 171b6a7bef2SMike Smith if (drv->pd_flags2 & MLX_PHYS_DRV_SYNC) 172b6a7bef2SMike Smith printf(" sync"); 173b6a7bef2SMike Smith if (drv->pd_flags2 & MLX_PHYS_DRV_TAG) 174b6a7bef2SMike Smith printf(" tag-enabled"); 175b6a7bef2SMike Smith printf("\n"); 176b6a7bef2SMike Smith } 177b6a7bef2SMike Smith } 178