1165725Sscottl/*- 2165725Sscottl * Copyright (c) 2007 Scott Long 3165725Sscottl * 4165725Sscottl * Redistribution and use in source and binary forms, with or without 5165725Sscottl * modification, are permitted provided that the following conditions 6165725Sscottl * are met: 7165725Sscottl * 1. Redistributions of source code must retain the above copyright 8165725Sscottl * notice, this list of conditions and the following disclaimer. 9165725Sscottl * 2. Redistributions in binary form must reproduce the above copyright 10165725Sscottl * notice, this list of conditions and the following disclaimer in the 11165725Sscottl * documentation and/or other materials provided with the distribution. 12165725Sscottl * 13165725Sscottl * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14165725Sscottl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15165725Sscottl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16165725Sscottl * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17165725Sscottl * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18165725Sscottl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19165725Sscottl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20165725Sscottl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21165725Sscottl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22165725Sscottl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23165725Sscottl * SUCH DAMAGE. 24165725Sscottl */ 25165725Sscottl 26165725Sscottl#include <sys/cdefs.h> 27165725Sscottl__FBSDID("$FreeBSD$"); 28165725Sscottl 29165725Sscottl#include <sys/types.h> 30165725Sscottl#include <sys/fcntl.h> 31165725Sscottl#include <sys/ioctl.h> 32165725Sscottl#include <sys/uio.h> 33165725Sscottl 34165725Sscottl#include </sys/dev/mfi/mfireg.h> 35165725Sscottl#include </sys/dev/mfi/mfi_ioctl.h> 36165725Sscottl 37165725Sscottl#include <errno.h> 38165725Sscottl#include <stdio.h> 39165725Sscottl 40165725Sscottl/* 41165725Sscottl * Simple program to print out the queue stats on the given queue index. 42165725Sscottl * See /sys/sys/mfi_ioctl.h for the definitions of each queue index. 43165725Sscottl */ 44165725Sscottl 45165725Sscottlvoid 46165725Sscottlusage(void) 47165725Sscottl{ 48165725Sscottl printf("Usage: mfi_checkq <queue_number>\n"); 49165725Sscottl exit(1); 50165725Sscottl} 51165725Sscottl 52165725Sscottlint 53165725Sscottlmain(int argc, char **argv) 54165725Sscottl{ 55165725Sscottl union mfi_statrequest sr; 56165725Sscottl int fd, retval, queue; 57165725Sscottl 58165725Sscottl if (argc != 2) 59165725Sscottl usage(); 60165725Sscottl 61165725Sscottl fd = open("/dev/mfi0", O_RDWR); 62165725Sscottl if (fd == -1) { 63165725Sscottl printf("couldn't open mfi0: %s\n", strerror(errno)); 64165725Sscottl return (-1); 65165725Sscottl } 66165725Sscottl 67165725Sscottl queue = atoi(argv[1]); 68165725Sscottl printf("Getting stats for queue %d\n", queue); 69165725Sscottl bzero(&sr, sizeof(union mfi_statrequest)); 70165725Sscottl sr.ms_item = queue; 71165725Sscottl retval = ioctl(fd, MFIIO_STATS, &sr); 72165725Sscottl if (retval == -1) { 73165725Sscottl printf("error on ioctl: %s\n", strerror(errno)); 74165725Sscottl return (-1); 75165725Sscottl } 76165725Sscottl 77165725Sscottl printf("length= %d, max= %d\n",sr.ms_qstat.q_length, sr.ms_qstat.q_max); 78165725Sscottl 79165725Sscottl close(fd); 80165725Sscottl return 0; 81165725Sscottl} 82