1 /* 2 * Copyright (c) 2010-2011 Qlogic Corporation 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 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * POSSIBILITY OF SUCH DAMAGE. 26 */ 27 /* 28 * File: qla_ioctl.c 29 * Author : David C Somayajulu, Qlogic Corporation, Aliso Viejo, CA 92656. 30 */ 31 32 #include <sys/cdefs.h> 33 __FBSDID("$FreeBSD$"); 34 35 #include "qla_os.h" 36 #include "qla_reg.h" 37 #include "qla_hw.h" 38 #include "qla_def.h" 39 #include "qla_reg.h" 40 #include "qla_inline.h" 41 #include "qla_glbl.h" 42 #include "qla_ioctl.h" 43 44 static struct cdevsw qla_cdevsw = { 45 .d_version = D_VERSION, 46 .d_ioctl = qla_eioctl, 47 .d_name = "qlcnic", 48 }; 49 50 int 51 qla_make_cdev(qla_host_t *ha) 52 { 53 ha->ioctl_dev = make_dev(&qla_cdevsw, 54 ha->ifp->if_dunit, 55 UID_ROOT, 56 GID_WHEEL, 57 0600, 58 "%s", 59 if_name(ha->ifp)); 60 61 if (ha->ioctl_dev == NULL) 62 return (-1); 63 64 ha->ioctl_dev->si_drv1 = ha; 65 66 return (0); 67 } 68 69 void 70 qla_del_cdev(qla_host_t *ha) 71 { 72 if (ha->ioctl_dev != NULL) 73 destroy_dev(ha->ioctl_dev); 74 return; 75 } 76 77 int 78 qla_eioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag, 79 struct thread *td) 80 { 81 qla_host_t *ha; 82 int rval = 0; 83 qla_reg_val_t *rv; 84 qla_rd_flash_t *rdf; 85 86 if ((ha = (qla_host_t *)dev->si_drv1) == NULL) 87 return ENXIO; 88 89 switch(cmd) { 90 91 case QLA_RDWR_REG: 92 93 rv = (qla_reg_val_t *)data; 94 95 if (rv->direct) { 96 if (rv->rd) { 97 rv->val = READ_OFFSET32(ha, rv->reg); 98 } else { 99 WRITE_OFFSET32(ha, rv->reg, rv->val); 100 } 101 } else { 102 if ((rval = qla_rdwr_indreg32(ha, rv->reg, &rv->val, 103 rv->rd))) 104 rval = ENXIO; 105 } 106 break; 107 108 case QLA_RD_FLASH: 109 rdf = (qla_rd_flash_t *)data; 110 if ((rval = qla_rd_flash32(ha, rdf->off, &rdf->data))) 111 rval = ENXIO; 112 break; 113 default: 114 break; 115 } 116 117 return rval; 118 } 119 120