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