FreeBSD/sys/dev/mrsas/mrsas.c
/*
 * mrsas_ioctl:	IOCtl commands entry point.
 *
 * This function is the entry point for IOCtls from the OS.  It calls the
 * appropriate function for processing depending on the command received.
 */
IOCtl commands entry point.
This function is the entry point for IOCtls from the OS.  It calls the
appropriate function for processing depending on the command received.
IOCtl commands entry point . This function is the entry point for IOCtls from the OS . It calls the appropriate function for processing depending on the command received .
static int
mrsas_ioctl(struct cdev *dev, u_long cmd, caddr_t arg, int flag,
    struct thread *td)
{
	struct mrsas_softc *sc;
	int ret = 0, i = 0;
	MRSAS_DRV_PCI_INFORMATION *pciDrvInfo;
	sc = mrsas_get_softc_instance(dev, cmd, arg);
	if (!sc)
		return ENOENT;
	if (sc->remove_in_progress) {
		mrsas_dprint(sc, MRSAS_INFO,
		    "Driver remove or shutdown called.\n");
		return ENOENT;
	}
	mtx_lock_spin(&sc->ioctl_lock);
	if (!sc->reset_in_progress) {
		mtx_unlock_spin(&sc->ioctl_lock);
		goto do_ioctl;
	}
	mtx_unlock_spin(&sc->ioctl_lock);
	while (sc->reset_in_progress) {
		i++;
		if (!(i % MRSAS_RESET_NOTICE_INTERVAL)) {
			mrsas_dprint(sc, MRSAS_INFO,
			    "[%2d]waiting for OCR to be finished from %s\n", i, __func__);
		}
		pause("mr_ioctl", hz);
	}
do_ioctl:
	switch (cmd) {
	case MRSAS_IOC_FIRMWARE_PASS_THROUGH64:
#ifdef COMPAT_FREEBSD32
	case MRSAS_IOC_FIRMWARE_PASS_THROUGH32:
#endif
		sema_wait(&sc->ioctl_count_sema);
		ret = mrsas_passthru(sc, (void *)arg, cmd);
		sema_post(&sc->ioctl_count_sema);
		break;
	case MRSAS_IOC_SCAN_BUS:
		ret = mrsas_bus_scan(sc);
		break;
	case MRSAS_IOC_GET_PCI_INFO:
		pciDrvInfo = (MRSAS_DRV_PCI_INFORMATION *) arg;
		memset(pciDrvInfo, 0, sizeof(MRSAS_DRV_PCI_INFORMATION));
		pciDrvInfo->busNumber = pci_get_bus(sc->mrsas_dev);
		pciDrvInfo->deviceNumber = pci_get_slot(sc->mrsas_dev);
		pciDrvInfo->functionNumber = pci_get_function(sc->mrsas_dev);
		pciDrvInfo->domainID = pci_get_domain(sc->mrsas_dev);
		mrsas_dprint(sc, MRSAS_INFO, "pci bus no: %d,"
		    "pci device no: %d, pci function no: %d,"
		    "pci domain ID: %d\n",
		    pciDrvInfo->busNumber, pciDrvInfo->deviceNumber,
		    pciDrvInfo->functionNumber, pciDrvInfo->domainID);
		ret = 0;
		break;
	default:
		mrsas_dprint(sc, MRSAS_TRACE, "IOCTL command 0x%lx is not handled\n", cmd);
		ret = ENOENT;
	}
	return (ret);
}
static int mrsas_ioctl ( struct cdev * dev , u_long cmd , caddr_t arg , int flag , struct thread * td ) { struct mrsas_softc * sc ; int ret = 0 , i = 0 ; MRSAS_DRV_PCI_INFORMATION * pciDrvInfo ; sc = mrsas_get_softc_instance ( dev , cmd , arg ) ; if ( ! sc ) return ENOENT ; if ( sc -> remove_in_progress ) { mrsas_dprint ( sc , MRSAS_INFO , " \n " ) ; return ENOENT ; } mtx_lock_spin ( & sc -> ioctl_lock ) ; if ( ! sc -> reset_in_progress ) { mtx_unlock_spin ( & sc -> ioctl_lock ) ; goto do_ioctl ; } mtx_unlock_spin ( & sc -> ioctl_lock ) ; while ( sc -> reset_in_progress ) { i ++ ; if ( ! ( i % MRSAS_RESET_NOTICE_INTERVAL ) ) { mrsas_dprint ( sc , MRSAS_INFO , " \n " , i , __func__ ) ; } pause ( " " , hz ) ; } do_ioctl : switch ( cmd ) { case MRSAS_IOC_FIRMWARE_PASS_THROUGH64 : #ifdef COMPAT_FREEBSD32 case MRSAS_IOC_FIRMWARE_PASS_THROUGH32 : #endif sema_wait ( & sc -> ioctl_count_sema ) ; ret = mrsas_passthru ( sc , ( void * ) arg , cmd ) ; sema_post ( & sc -> ioctl_count_sema ) ; break ; case MRSAS_IOC_SCAN_BUS : ret = mrsas_bus_scan ( sc ) ; break ; case MRSAS_IOC_GET_PCI_INFO : pciDrvInfo = ( MRSAS_DRV_PCI_INFORMATION * ) arg ; memset ( pciDrvInfo , 0 , sizeof ( MRSAS_DRV_PCI_INFORMATION ) ) ; pciDrvInfo -> busNumber = pci_get_bus ( sc -> mrsas_dev ) ; pciDrvInfo -> deviceNumber = pci_get_slot ( sc -> mrsas_dev ) ; pciDrvInfo -> functionNumber = pci_get_function ( sc -> mrsas_dev ) ; pciDrvInfo -> domainID = pci_get_domain ( sc -> mrsas_dev ) ; mrsas_dprint ( sc , MRSAS_INFO , " " " " " \n " , pciDrvInfo -> busNumber , pciDrvInfo -> deviceNumber , pciDrvInfo -> functionNumber , pciDrvInfo -> domainID ) ; ret = 0 ; break ; default : mrsas_dprint ( sc , MRSAS_TRACE , " \n " , cmd ) ; ret = ENOENT ; } return ( ret ) ; }
mrsas_ioctl: IOCtl commands entry point.
mrsas_ioctl : IOCtl commands entry point .
/*
		 * Decrement the Ioctl counting Semaphore before getting an
		 * mfi command
		 */ /* Increment the Ioctl counting semaphore value */