159138Smsmith/*- 259138Smsmith * Copyright (c) 1999 Michael Smith 359138Smsmith * All rights reserved. 459138Smsmith * 559138Smsmith * Redistribution and use in source and binary forms, with or without 659138Smsmith * modification, are permitted provided that the following conditions 759138Smsmith * are met: 859138Smsmith * 1. Redistributions of source code must retain the above copyright 959138Smsmith * notice, this list of conditions and the following disclaimer. 1059138Smsmith * 2. Redistributions in binary form must reproduce the above copyright 1159138Smsmith * notice, this list of conditions and the following disclaimer in the 1259138Smsmith * documentation and/or other materials provided with the distribution. 1359138Smsmith * 1459138Smsmith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1559138Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1659138Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1759138Smsmith * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1859138Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1959138Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2059138Smsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2159138Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2259138Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2359138Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2459138Smsmith * SUCH DAMAGE. 2559138Smsmith * 2659138Smsmith * $FreeBSD: releng/10.2/usr.sbin/mlxcontrol/util.c 59159 2000-04-11 23:04:17Z msmith $ 2759138Smsmith */ 2859138Smsmith 2959138Smsmith#include <sys/types.h> 3059138Smsmith#include <stdio.h> 3159138Smsmith#include <paths.h> 3259138Smsmith#include <string.h> 3359138Smsmith 3459159Smsmith#include <dev/mlx/mlxio.h> 3559159Smsmith#include <dev/mlx/mlxreg.h> 3659138Smsmith 3759138Smsmith#include "mlxcontrol.h" 3859138Smsmith 3959138Smsmith/******************************************************************************** 4059138Smsmith * Various name-producing and -parsing functions 4159138Smsmith */ 4259138Smsmith 4359138Smsmith/* return path of controller (unit) */ 4459138Smsmithchar * 4559138Smsmithctrlrpath(int unit) 4659138Smsmith{ 4759138Smsmith static char buf[32]; 4859138Smsmith 4959138Smsmith sprintf(buf, "%s%s", _PATH_DEV, ctrlrname(unit)); 5059138Smsmith return(buf); 5159138Smsmith} 5259138Smsmith 5359138Smsmith/* return name of controller (unit) */ 5459138Smsmithchar * 5559138Smsmithctrlrname(int unit) 5659138Smsmith{ 5759138Smsmith static char buf[32]; 5859138Smsmith 5959138Smsmith sprintf(buf, "mlx%d", unit); 6059138Smsmith return(buf); 6159138Smsmith} 6259138Smsmith 6359138Smsmith/* return path of drive (unit) */ 6459138Smsmithchar * 6559138Smsmithdrivepath(int unit) 6659138Smsmith{ 6759138Smsmith static char buf[32]; 6859138Smsmith 6959138Smsmith sprintf(buf, "%s%s", _PATH_DEV, drivename(unit)); 7059138Smsmith return(buf); 7159138Smsmith} 7259138Smsmith 7359138Smsmith/* return name of drive (unit) */ 7459138Smsmithchar * 7559138Smsmithdrivename(int unit) 7659138Smsmith{ 7759138Smsmith static char buf[32]; 7859138Smsmith 7959138Smsmith sprintf(buf, "mlxd%d", unit); 8059138Smsmith return(buf); 8159138Smsmith} 8259138Smsmith 8359138Smsmith/* get controller unit number from name in (str) */ 8459138Smsmithint 8559138Smsmithctrlrunit(char *str) 8659138Smsmith{ 8759138Smsmith int unit; 8859138Smsmith 8959138Smsmith if (sscanf(str, "mlx%d", &unit) == 1) 9059138Smsmith return(unit); 9159138Smsmith return(-1); 9259138Smsmith} 9359138Smsmith 9459138Smsmith/* get drive unit number from name in (str) */ 9559138Smsmithint 9659138Smsmithdriveunit(char *str) 9759138Smsmith{ 9859138Smsmith int unit; 9959138Smsmith 10059138Smsmith if (sscanf(str, "mlxd%d", &unit) == 1) 10159138Smsmith return(unit); 10259138Smsmith return(-1); 10359138Smsmith} 10459138Smsmith 10559138Smsmith/******************************************************************************** 10659138Smsmith * Standardised output of various data structures. 10759138Smsmith */ 10859138Smsmith 10959138Smsmithvoid 11059138Smsmithmlx_print_phys_drv(struct mlx_phys_drv *drv, int chn, int targ, char *prefix, int verbose) 11159138Smsmith{ 11259138Smsmith char *type, *device, *vendor, *revision; 11359138Smsmith 11459138Smsmith switch(drv->pd_flags2 & 0x03) { 11559138Smsmith case MLX_PHYS_DRV_DISK: 11659138Smsmith type = "disk"; 11759138Smsmith break; 11859138Smsmith case MLX_PHYS_DRV_SEQUENTIAL: 11959138Smsmith type = "tape"; 12059138Smsmith break; 12159138Smsmith case MLX_PHYS_DRV_CDROM: 12259138Smsmith type= "cdrom"; 12359138Smsmith break; 12459138Smsmith case MLX_PHYS_DRV_OTHER: 12559138Smsmith default: 12659138Smsmith type = "unknown"; 12759138Smsmith break; 12859138Smsmith } 12959138Smsmith printf("%s%s%02d%02d ", prefix, type, chn, targ); 13059138Smsmith switch(drv->pd_status) { 13159138Smsmith case MLX_PHYS_DRV_DEAD: 13259138Smsmith printf(" (dead) "); 13359138Smsmith break; 13459138Smsmith case MLX_PHYS_DRV_WRONLY: 13559138Smsmith printf(" (write-only) "); 13659138Smsmith break; 13759138Smsmith case MLX_PHYS_DRV_ONLINE: 13859138Smsmith printf(" (online) "); 13959138Smsmith break; 14059138Smsmith case MLX_PHYS_DRV_STANDBY: 14159138Smsmith printf(" (standby) "); 14259138Smsmith break; 14359138Smsmith default: 14459138Smsmith printf(" (0x%02x) ", drv->pd_status); 14559138Smsmith } 14659138Smsmith printf("\n"); 14759138Smsmith 14859138Smsmith if (verbose) { 14959138Smsmith 15059138Smsmith printf("%s ", prefix); 15159138Smsmith if (!mlx_scsi_inquiry(0, chn, targ, &vendor, &device, &revision)) { 15259138Smsmith printf("'%8.8s' '%16.16s' '%4.4s'", vendor, device, revision); 15359138Smsmith } else { 15459138Smsmith printf("<IDENTIFY FAILED>"); 15559138Smsmith } 15659138Smsmith 15759138Smsmith printf(" %dMB ", drv->pd_config_size / 2048); 15859138Smsmith 15959138Smsmith if (drv->pd_flags2 & MLX_PHYS_DRV_FAST20) { 16059138Smsmith printf(" fast20"); 16159138Smsmith } else if (drv->pd_flags2 & MLX_PHYS_DRV_FAST) { 16259138Smsmith printf(" fast"); 16359138Smsmith } 16459138Smsmith if (drv->pd_flags2 & MLX_PHYS_DRV_WIDE) 16559138Smsmith printf(" wide"); 16659138Smsmith if (drv->pd_flags2 & MLX_PHYS_DRV_SYNC) 16759138Smsmith printf(" sync"); 16859138Smsmith if (drv->pd_flags2 & MLX_PHYS_DRV_TAG) 16959138Smsmith printf(" tag-enabled"); 17059138Smsmith printf("\n"); 17159138Smsmith } 17259138Smsmith} 173