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