xref: /freebsd/sys/dev/qlxgb/qla_ioctl.c (revision 685dc743dc3b5645e34836464128e1c0558b404b)
1718cf2ccSPedro F. Giffuni /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni  *
4088fc971SDavid C Somayajulu  * Copyright (c) 2011-2013 Qlogic Corporation
50bc7cf6fSBjoern A. Zeeb  * All rights reserved.
60bc7cf6fSBjoern A. Zeeb  *
70bc7cf6fSBjoern A. Zeeb  *  Redistribution and use in source and binary forms, with or without
80bc7cf6fSBjoern A. Zeeb  *  modification, are permitted provided that the following conditions
90bc7cf6fSBjoern A. Zeeb  *  are met:
100bc7cf6fSBjoern A. Zeeb  *
110bc7cf6fSBjoern A. Zeeb  *  1. Redistributions of source code must retain the above copyright
120bc7cf6fSBjoern A. Zeeb  *     notice, this list of conditions and the following disclaimer.
130bc7cf6fSBjoern A. Zeeb  *  2. Redistributions in binary form must reproduce the above copyright
140bc7cf6fSBjoern A. Zeeb  *     notice, this list of conditions and the following disclaimer in the
150bc7cf6fSBjoern A. Zeeb  *     documentation and/or other materials provided with the distribution.
160bc7cf6fSBjoern A. Zeeb  *
170bc7cf6fSBjoern A. Zeeb  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
180bc7cf6fSBjoern A. Zeeb  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
190bc7cf6fSBjoern A. Zeeb  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
200bc7cf6fSBjoern A. Zeeb  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
210bc7cf6fSBjoern A. Zeeb  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
220bc7cf6fSBjoern A. Zeeb  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
230bc7cf6fSBjoern A. Zeeb  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
240bc7cf6fSBjoern A. Zeeb  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
250bc7cf6fSBjoern A. Zeeb  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
260bc7cf6fSBjoern A. Zeeb  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
270bc7cf6fSBjoern A. Zeeb  *  POSSIBILITY OF SUCH DAMAGE.
280bc7cf6fSBjoern A. Zeeb  */
290bc7cf6fSBjoern A. Zeeb /*
300bc7cf6fSBjoern A. Zeeb  * File: qla_ioctl.c
310bc7cf6fSBjoern A. Zeeb  * Author : David C Somayajulu, Qlogic Corporation, Aliso Viejo, CA 92656.
320bc7cf6fSBjoern A. Zeeb  */
330bc7cf6fSBjoern A. Zeeb 
340bc7cf6fSBjoern A. Zeeb #include <sys/cdefs.h>
350bc7cf6fSBjoern A. Zeeb #include "qla_os.h"
360bc7cf6fSBjoern A. Zeeb #include "qla_reg.h"
370bc7cf6fSBjoern A. Zeeb #include "qla_hw.h"
380bc7cf6fSBjoern A. Zeeb #include "qla_def.h"
390bc7cf6fSBjoern A. Zeeb #include "qla_reg.h"
400bc7cf6fSBjoern A. Zeeb #include "qla_inline.h"
410bc7cf6fSBjoern A. Zeeb #include "qla_glbl.h"
420bc7cf6fSBjoern A. Zeeb #include "qla_ioctl.h"
430bc7cf6fSBjoern A. Zeeb 
440bc7cf6fSBjoern A. Zeeb static struct cdevsw qla_cdevsw = {
450bc7cf6fSBjoern A. Zeeb 	.d_version = D_VERSION,
460bc7cf6fSBjoern A. Zeeb 	.d_ioctl = qla_eioctl,
470bc7cf6fSBjoern A. Zeeb 	.d_name = "qlcnic",
480bc7cf6fSBjoern A. Zeeb };
490bc7cf6fSBjoern A. Zeeb 
500bc7cf6fSBjoern A. Zeeb int
qla_make_cdev(qla_host_t * ha)510bc7cf6fSBjoern A. Zeeb qla_make_cdev(qla_host_t *ha)
520bc7cf6fSBjoern A. Zeeb {
530bc7cf6fSBjoern A. Zeeb         ha->ioctl_dev = make_dev(&qla_cdevsw,
545b587352SJustin Hibbits 				if_getdunit(ha->ifp),
550bc7cf6fSBjoern A. Zeeb                                 UID_ROOT,
560bc7cf6fSBjoern A. Zeeb                                 GID_WHEEL,
570bc7cf6fSBjoern A. Zeeb                                 0600,
580bc7cf6fSBjoern A. Zeeb                                 "%s",
590bc7cf6fSBjoern A. Zeeb                                 if_name(ha->ifp));
600bc7cf6fSBjoern A. Zeeb 
610bc7cf6fSBjoern A. Zeeb 	if (ha->ioctl_dev == NULL)
620bc7cf6fSBjoern A. Zeeb 		return (-1);
630bc7cf6fSBjoern A. Zeeb 
640bc7cf6fSBjoern A. Zeeb         ha->ioctl_dev->si_drv1 = ha;
650bc7cf6fSBjoern A. Zeeb 
660bc7cf6fSBjoern A. Zeeb 	return (0);
670bc7cf6fSBjoern A. Zeeb }
680bc7cf6fSBjoern A. Zeeb 
690bc7cf6fSBjoern A. Zeeb void
qla_del_cdev(qla_host_t * ha)700bc7cf6fSBjoern A. Zeeb qla_del_cdev(qla_host_t *ha)
710bc7cf6fSBjoern A. Zeeb {
720bc7cf6fSBjoern A. Zeeb 	if (ha->ioctl_dev != NULL)
730bc7cf6fSBjoern A. Zeeb 		destroy_dev(ha->ioctl_dev);
740bc7cf6fSBjoern A. Zeeb 	return;
750bc7cf6fSBjoern A. Zeeb }
760bc7cf6fSBjoern A. Zeeb 
770bc7cf6fSBjoern A. Zeeb int
qla_eioctl(struct cdev * dev,u_long cmd,caddr_t data,int fflag,struct thread * td)780bc7cf6fSBjoern A. Zeeb qla_eioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag,
790bc7cf6fSBjoern A. Zeeb         struct thread *td)
800bc7cf6fSBjoern A. Zeeb {
810bc7cf6fSBjoern A. Zeeb         qla_host_t *ha;
820bc7cf6fSBjoern A. Zeeb         int rval = 0;
830bc7cf6fSBjoern A. Zeeb         qla_reg_val_t *rv;
840bc7cf6fSBjoern A. Zeeb         qla_rd_flash_t *rdf;
85088fc971SDavid C Somayajulu 	qla_wr_flash_t *wrf;
86088fc971SDavid C Somayajulu 	qla_rd_pci_ids_t *pci_ids;
87088fc971SDavid C Somayajulu 	device_t pci_dev;
880bc7cf6fSBjoern A. Zeeb 
890bc7cf6fSBjoern A. Zeeb         if ((ha = (qla_host_t *)dev->si_drv1) == NULL)
900bc7cf6fSBjoern A. Zeeb                 return ENXIO;
910bc7cf6fSBjoern A. Zeeb 
92088fc971SDavid C Somayajulu 	pci_dev= ha->pci_dev;
93088fc971SDavid C Somayajulu 
940bc7cf6fSBjoern A. Zeeb         switch(cmd) {
950bc7cf6fSBjoern A. Zeeb         case QLA_RDWR_REG:
960bc7cf6fSBjoern A. Zeeb 
970bc7cf6fSBjoern A. Zeeb                 rv = (qla_reg_val_t *)data;
980bc7cf6fSBjoern A. Zeeb 
990bc7cf6fSBjoern A. Zeeb                 if (rv->direct) {
1000bc7cf6fSBjoern A. Zeeb                         if (rv->rd) {
1010bc7cf6fSBjoern A. Zeeb                                 rv->val = READ_OFFSET32(ha, rv->reg);
1020bc7cf6fSBjoern A. Zeeb                         } else {
1030bc7cf6fSBjoern A. Zeeb                                 WRITE_OFFSET32(ha, rv->reg, rv->val);
1040bc7cf6fSBjoern A. Zeeb                         }
1050bc7cf6fSBjoern A. Zeeb                 } else {
1060bc7cf6fSBjoern A. Zeeb                         if ((rval = qla_rdwr_indreg32(ha, rv->reg, &rv->val,
1070bc7cf6fSBjoern A. Zeeb                                 rv->rd)))
1080bc7cf6fSBjoern A. Zeeb                                 rval = ENXIO;
1090bc7cf6fSBjoern A. Zeeb                 }
1100bc7cf6fSBjoern A. Zeeb                 break;
1110bc7cf6fSBjoern A. Zeeb 
1120bc7cf6fSBjoern A. Zeeb         case QLA_RD_FLASH:
1130bc7cf6fSBjoern A. Zeeb                 rdf = (qla_rd_flash_t *)data;
1140bc7cf6fSBjoern A. Zeeb                 if ((rval = qla_rd_flash32(ha, rdf->off, &rdf->data)))
1150bc7cf6fSBjoern A. Zeeb                         rval = ENXIO;
1160bc7cf6fSBjoern A. Zeeb                 break;
117088fc971SDavid C Somayajulu 
118088fc971SDavid C Somayajulu         case QLA_WR_FLASH:
119088fc971SDavid C Somayajulu                 wrf = (qla_wr_flash_t *)data;
120088fc971SDavid C Somayajulu                 if ((rval = qla_wr_flash_buffer(ha, wrf->off, wrf->size,
121088fc971SDavid C Somayajulu 					wrf->buffer, wrf->pattern)))
122088fc971SDavid C Somayajulu                         rval = ENXIO;
123088fc971SDavid C Somayajulu                 break;
124088fc971SDavid C Somayajulu 
125088fc971SDavid C Somayajulu 	case QLA_ERASE_FLASH:
126088fc971SDavid C Somayajulu 		if (qla_erase_flash(ha, ((qla_erase_flash_t *)data)->off,
127088fc971SDavid C Somayajulu 			((qla_erase_flash_t *)data)->size))
128088fc971SDavid C Somayajulu 			rval = ENXIO;
129088fc971SDavid C Somayajulu 		break;
130088fc971SDavid C Somayajulu 
131088fc971SDavid C Somayajulu 	case QLA_RD_PCI_IDS:
132088fc971SDavid C Somayajulu 		pci_ids = (qla_rd_pci_ids_t *)data;
133088fc971SDavid C Somayajulu 		pci_ids->ven_id = pci_get_vendor(pci_dev);
134088fc971SDavid C Somayajulu 		pci_ids->dev_id = pci_get_device(pci_dev);
135088fc971SDavid C Somayajulu 		pci_ids->subsys_ven_id = pci_get_subvendor(pci_dev);
136088fc971SDavid C Somayajulu 		pci_ids->subsys_dev_id = pci_get_subdevice(pci_dev);
137088fc971SDavid C Somayajulu 		pci_ids->rev_id = pci_read_config(pci_dev, PCIR_REVID, 1);
138088fc971SDavid C Somayajulu 		break;
139088fc971SDavid C Somayajulu 
1400bc7cf6fSBjoern A. Zeeb         default:
1410bc7cf6fSBjoern A. Zeeb                 break;
1420bc7cf6fSBjoern A. Zeeb         }
1430bc7cf6fSBjoern A. Zeeb 
1440bc7cf6fSBjoern A. Zeeb         return rval;
1450bc7cf6fSBjoern A. Zeeb }
146