2 * Copyright (c) 2011-2013 Qlogic Corporation
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
29 * Author : David C Somayajulu, Qlogic Corporation, Aliso Viejo, CA 92656.
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
40 #include "qla_inline.h"
42 #include "qla_ioctl.h"
44 static struct cdevsw qla_cdevsw = {
45 .d_version = D_VERSION,
46 .d_ioctl = qla_eioctl,
51 qla_make_cdev(qla_host_t *ha)
53 ha->ioctl_dev = make_dev(&qla_cdevsw,
61 if (ha->ioctl_dev == NULL)
64 ha->ioctl_dev->si_drv1 = ha;
70 qla_del_cdev(qla_host_t *ha)
72 if (ha->ioctl_dev != NULL)
73 destroy_dev(ha->ioctl_dev);
78 qla_eioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag,
86 qla_rd_pci_ids_t *pci_ids;
89 if ((ha = (qla_host_t *)dev->si_drv1) == NULL)
98 rv = (qla_reg_val_t *)data;
102 rv->val = READ_OFFSET32(ha, rv->reg);
104 WRITE_OFFSET32(ha, rv->reg, rv->val);
107 if ((rval = qla_rdwr_indreg32(ha, rv->reg, &rv->val,
114 rdf = (qla_rd_flash_t *)data;
115 if ((rval = qla_rd_flash32(ha, rdf->off, &rdf->data)))
120 wrf = (qla_wr_flash_t *)data;
121 if ((rval = qla_wr_flash_buffer(ha, wrf->off, wrf->size,
122 wrf->buffer, wrf->pattern)))
127 case QLA_ERASE_FLASH:
128 if (qla_erase_flash(ha, ((qla_erase_flash_t *)data)->off,
129 ((qla_erase_flash_t *)data)->size))
134 pci_ids = (qla_rd_pci_ids_t *)data;
135 pci_ids->ven_id = pci_get_vendor(pci_dev);
136 pci_ids->dev_id = pci_get_device(pci_dev);
137 pci_ids->subsys_ven_id = pci_get_subvendor(pci_dev);
138 pci_ids->subsys_dev_id = pci_get_subdevice(pci_dev);
139 pci_ids->rev_id = pci_read_config(pci_dev, PCIR_REVID, 1);