qla2x00_ioctl.c

来自「这个linux源代码是很全面的~基本完整了~使用c编译的~由于时间问题我没有亲自」· C语言 代码 · 共 2,436 行 · 第 1/5 页

C
2,436 行
字号
	case INT_CC_LOOPBACK:		rval = qla2x00_send_loopback(ha, pext, mode);		ret = (rval == QL_STATUS_SUCCESS) ?		    EXT_STATUS_OK : EXT_STATUS_ERR;		copy_to_user((void *)arg, (void *)pext, sizeof(EXT_IOCTL));		break;#endif /* INTAPI */	/* all others go here */	/*	   case EXT_CC_ELS_RNID_SEND:	   break;	   case EXT_CC_ELS_RTIN_SEND:	   break;	   case EXT_CC_PLATFORM_REG:	   break;	 */#if MPIO_SUPPORT	/* Failover IOCTLs */	case FO_CC_GET_PARAMS:	case FO_CC_SET_PARAMS:	case FO_CC_GET_PATHS:	case FO_CC_SET_CURRENT_PATH:	case FO_CC_RESET_HBA_STAT:	case FO_CC_GET_HBA_STAT:	case FO_CC_GET_LUN_DATA:	case FO_CC_SET_LUN_DATA:	case FO_CC_GET_TARGET_DATA:	case FO_CC_SET_TARGET_DATA:		DEBUG9(printk("qla2x00_ioctl: failover arg (%p):\n", arg);)		    qla2x00_fo_ioctl(ha,cmd, arg, mode);		copy_to_user((void *)arg, (void *)pext, sizeof(EXT_IOCTL));		break;#endif	default:		ret = EXT_STATUS_ERR;		break;	} /* end of CC decode switch */	DEBUG9(printk("qla2x00_ioctl: exiting. rval(%d) ret(%d)\n", rval, ret);)	qla2x00_release_ioctl_access(ha);	return ret;}/* * qla2x00_alloc_ioctl_mem *	Allocates memory needed by IOCTL code. * * Input: *	ha = adapter state pointer. * * Returns: *	qla2x00 local function return status code. * * Context: *	Kernel context. */STATIC intqla2x00_alloc_ioctl_mem(scsi_qla_host_t *ha){	DEBUG9(printk("qla2x00_alloc_ioctl_mem entered.\n");)	if (qla2x00_get_new_ioctl_dma_mem(ha, QLA_INITIAL_IOCTLMEM_SIZE) !=	    QL_STATUS_SUCCESS) {		printk(KERN_WARNING		    "qla2x00: ERROR in ioctl physical memory allocation\n");		return QL_STATUS_RESOURCE_ERROR;	}	/* Allocate context memory buffer */	ha->ioctl = KMEM_ZALLOC(sizeof(hba_ioctl_context), 11);	if (ha->ioctl == NULL) {		/* error */		printk(KERN_WARNING		    "qla2x00: ERROR in ioctl context allocation.\n");		return QL_STATUS_RESOURCE_ERROR;	}	/* Allocate AEN tracking buffer */	ha->ioctl->aen_tracking_queue =	    KMEM_ZALLOC(EXT_DEF_MAX_AEN_QUEUE * sizeof(EXT_ASYNC_EVENT), 12);	if (ha->ioctl->aen_tracking_queue == NULL) {		printk(KERN_WARNING		    "qla2x00: ERROR in ioctl aen_queue allocation.\n");		return QL_STATUS_RESOURCE_ERROR;	}	ha->ioctl->ioctl_tq = KMEM_ZALLOC(sizeof(os_tgt_t), 13);	if (ha->ioctl->ioctl_tq == NULL) {		printk(KERN_WARNING		    "qla2x00: ERROR in ioctl tgt queue allocation.\n");		return QL_STATUS_RESOURCE_ERROR;	}	ha->ioctl->ioctl_lq = KMEM_ZALLOC(sizeof(os_lun_t), 14);	if (ha->ioctl->ioctl_lq == NULL) {		printk(KERN_WARNING		    "qla2x00: ERROR in ioctl lun queue allocation.\n");		return QL_STATUS_RESOURCE_ERROR;	}	/*INIT_LIST_HEAD(&(ha->ioctl->ioctl_lq->cmd));*/	ha->ioctl->ioctl_lq->q_state = LUN_STATE_READY;	ha->ioctl->ioctl_lq->q_lock = SPIN_LOCK_UNLOCKED;	/* Init wait_q fields */	ha->ioctl->wait_q_lock = SPIN_LOCK_UNLOCKED;	DEBUG9(printk("qla2x00_alloc_ioctl_mem exiting.\n");)	return QLA2X00_SUCCESS;}/* * qla2x00_get_new_ioctl_dma_mem *	Allocates dma memory of the specified size. *	This is done to replace any previously allocated ioctl dma buffer. * * Input: *	ha = adapter state pointer. * * Returns: *	qla2x00 local function return status code. * * Context: *	Kernel context. */STATIC intqla2x00_get_new_ioctl_dma_mem(scsi_qla_host_t *ha, uint32_t size){	if (ha->ioctl_mem) {		DEBUG9(printk("qla2x00_get_new_ioctl_dma_mem: ioctl_mem "		    "was previously allocated. Dealloc old buffer.\n");)	 	/* free the memory first */	 	pci_free_consistent(ha->pdev, ha->ioctl_mem_size, ha->ioctl_mem,		    ha->ioctl_mem_phys);	}	/* Get consistent memory allocated for ioctl I/O operations. */	ha->ioctl_mem = pci_alloc_consistent(ha->pdev,	    size, &ha->ioctl_mem_phys);	if (ha->ioctl_mem == NULL) {		printk(KERN_WARNING		    "qla2x00_get_new_ioctl_dma_mem: ERROR in ioctl physical "		    "memory allocation. Requested length=%x.\n", size);		ha->ioctl_mem_size = 0;		return QL_STATUS_RESOURCE_ERROR;	}	ha->ioctl_mem_size = size;	return QL_STATUS_SUCCESS;}/* * qla2x00_free_ioctl_mem *	Frees memory used by IOCTL code for the specified ha. * * Input: *	ha = adapter state pointer. * * Context: *	Kernel context. */STATIC voidqla2x00_free_ioctl_mem(scsi_qla_host_t *ha){	DEBUG9(printk("qla2x00_free_ioctl_mem entered.\n");)	if (ha->ioctl != NULL) {		if (ha->ioctl->ioctl_tq != NULL) {			KMEM_FREE(ha->ioctl->ioctl_tq, sizeof(os_tgt_t));			ha->ioctl->ioctl_tq = NULL;		}		if (ha->ioctl->ioctl_lq != NULL) {			KMEM_FREE(ha->ioctl->ioctl_lq, sizeof(os_lun_t));			ha->ioctl->ioctl_lq = NULL;		}		if (ha->ioctl->aen_tracking_queue != NULL) {			KMEM_FREE(ha->ioctl->aen_tracking_queue,			    EXT_DEF_MAX_AEN_QUEUE * sizeof(EXT_ASYNC_EVENT));			ha->ioctl->aen_tracking_queue = NULL;		}		KMEM_FREE(ha->ioctl, sizeof(hba_ioctl_context));		ha->ioctl = NULL;	}	/* free memory allocated for ioctl operations */	pci_free_consistent(ha->pdev, ha->ioctl_mem_size, ha->ioctl_mem,	    ha->ioctl_mem_phys);	ha->ioctl_mem = NULL;	DEBUG9(printk("qla2x00_free_ioctl_mem exiting.\n");)}/* * qla2x00_find_curr_ha *	Searches and returns the pointer to the adapter instance specified. * * Input: *	inst = adapter instance number to search. *	ha = adapter state pointer of the instance requested. * * Returns: *	qla2x00 local function return status code. * * Context: *	Kernel context. */STATIC intqla2x00_find_curr_ha(int inst, scsi_qla_host_t **ret_ha){	int	rval = QL_STATUS_SUCCESS;	scsi_qla_host_t *search_ha = NULL;	/*	 * Check for valid apiHBAInstance (set previously by EXT_SETINSTANCE 	 * or default 0)  and set ha context for this IOCTL	 */	for (search_ha = qla2x00_hostlist;	    (search_ha != NULL) && search_ha->instance != inst;	    search_ha = search_ha->next)		continue;	if (search_ha == NULL) {		DEBUG10(printk("qla2x00_ioctl: ERROR matching apiHBAInstance "		    "%d to an HBA Instance.\n", apiHBAInstance);)		rval = QL_STATUS_ERROR;	} else {		*ret_ha = search_ha;	}	return rval;}/* * qla2x00_aen_reg *	IOCTL management server Asynchronous Event Tracking Enable/Disable. * * Input: *	ha = pointer to the adapter struct of the adapter to register. *	cmd = pointer to EXT_IOCTL structure containing values from user. *	mode = flags. not used. * * Returns: *	0 = success * * Context: *	Kernel context. */STATIC intqla2x00_aen_reg(scsi_qla_host_t *ha, EXT_IOCTL *cmd, int mode){	int		rval = 0;	EXT_REG_AEN	reg_struct;	DEBUG9(printk("qla2x00_aen_reg: entered.\n");)	rval = copy_from_user(&reg_struct, cmd->RequestAdr, cmd->RequestLen);	if (rval == 0) {		cmd->Status = EXT_STATUS_OK;		if (reg_struct.Enable) {			ha->ioctl->flags |= IOCTL_AEN_TRACKING_ENABLE;		} else {			ha->ioctl->flags &= ~IOCTL_AEN_TRACKING_ENABLE;		}	} else {		cmd->Status = EXT_STATUS_COPY_ERR;		rval = EFAULT;	}	DEBUG9(printk("qla2x00_aen_reg: reg_struct. Enable(%d) "	    "ha->ioctl_flag(%x) cmd->Status(%d) cmd->DetailStatus (%d).",	    reg_struct.Enable, ha->ioctl->flags, cmd->Status,	    cmd->DetailStatus);)	DEBUG9(printk("qla2x00_aen_reg: exiting.\n");)	return rval;}/* * qla2x00_aen_get *	Asynchronous Event Record Transfer to user. *	The entire queue will be emptied and transferred back. * * Input: *	ha = pointer to the adapter struct of the specified adapter. *	pext = pointer to EXT_IOCTL structure containing values from user. *	mode = flags. * * Returns: *	0 = success * * Context: *	Kernel context. * * NOTE: Need to use hardware lock to protect the queues from updates *	 via isr/enqueue_aen after we get rid of io_request_lock. */STATIC intqla2x00_aen_get(scsi_qla_host_t *ha, EXT_IOCTL *cmd, int mode){	int		rval = 0;	EXT_ASYNC_EVENT	*tmp_q;	static  EXT_ASYNC_EVENT	aen[EXT_DEF_MAX_AEN_QUEUE];	uint8_t		i;	uint8_t		queue_cnt;	uint8_t		request_cnt;	uint32_t	stat = EXT_STATUS_OK;	uint32_t	dstat = EXT_STATUS_OK;	uint32_t	ret_len = 0;	unsigned long   cpu_flags = 0;	DEBUG9(printk("qla2x00_aen_get: entered.\n");)	request_cnt = (uint8_t)(cmd->ResponseLen / sizeof(EXT_ASYNC_EVENT));	if (request_cnt < EXT_DEF_MAX_AEN_QUEUE) {		/* We require caller to alloc for the maximum request count */		cmd->Status       = EXT_STATUS_BUFFER_TOO_SMALL;		rval = 0;		DEBUG9_10(printk(		    "qla2x00_aen_get: Buffer too small. Exiting normally.");)		return rval;	}	/* 1st: Make a local copy of the entire queue content. */	tmp_q = (EXT_ASYNC_EVENT *)ha->ioctl->aen_tracking_queue;	queue_cnt = 0;	spin_lock_irqsave(&ha->hardware_lock, cpu_flags);	i = ha->ioctl->aen_q_head;	for (; queue_cnt < EXT_DEF_MAX_AEN_QUEUE;) {		if (tmp_q[i].AsyncEventCode != 0) {			memcpy(&aen[queue_cnt], &tmp_q[i],					sizeof(EXT_ASYNC_EVENT));			queue_cnt++;			tmp_q[i].AsyncEventCode = 0; /* empty out the slot */		}		if (i == ha->ioctl->aen_q_tail) {			/* done. */			break;		}		i++;		if (i == EXT_DEF_MAX_AEN_QUEUE) {			i = 0;		}	}	/* Empty the queue. */	ha->ioctl->aen_q_head = 0;	ha->ioctl->aen_q_tail = 0;	spin_unlock_irqrestore(&ha->hardware_lock, cpu_flags);	/* 2nd: Now transfer the queue content to user buffer */	/* Copy the entire queue to user's buffer. */	ret_len = (uint32_t)(queue_cnt * sizeof(EXT_ASYNC_EVENT));	if (queue_cnt != 0) {		copy_to_user(cmd->ResponseAdr, aen, ret_len);	}	cmd->ResponseLen = ret_len;	if (rval != 0) {		stat = EXT_STATUS_COPY_ERR;		rval = EFAULT;		DEBUG10(printk("qla2x00_aen_get: FAILED. error = %d\n", stat);)	} else {		stat = EXT_STATUS_OK;		rval = 0;		DEBUG9(printk("qla2x00_aen_get: exiting normally.\n");)	}	cmd->Status       = stat;	cmd->DetailStatus = dstat;	DEBUG9(printk("qla2x00_aen_get: exiting. rval= %d\n", rval);)	return rval;}/* * qla2x00_enqueue_aen * * Input: *	ha = adapter state pointer. *	event_code = async event code of the event to add to queue. *	payload = event payload for the queue. * * Context: *	Interrupt context. * NOTE: Need to hold the hardware lock to protect the queues from *	 aen_get after we get rid of the io_request_lock. */voidqla2x00_enqueue_aen(scsi_qla_host_t *ha, uint16_t event_code, void *payload){	uint8_t			new_entry; /* index to current entry */	uint16_t		*mbx;	EXT_ASYNC_EVENT		*aen_queue;	DEBUG9(printk("qla2x00_enqueue_aen: entered.\n");)	aen_queue = (EXT_ASYNC_EVENT *)ha->ioctl->aen_tracking_queue;	if (aen_queue[ha->ioctl->aen_q_tail].AsyncEventCode != 0) {		/* Need to change queue pointers to make room. */		/* Increment tail for adding new entry. */		ha->ioctl->aen_q_tail++;		if (ha->ioctl->aen_q_tail == EXT_DEF_MAX_AEN_QUEUE) {			ha->ioctl->aen_q_tail = 0;		}		if (ha->ioctl->aen_q_head == ha->ioctl->aen_q_tail) {			/*			 * We're overwriting the oldest entry, so need to			 * update the head pointer.			 */			ha->ioctl->aen_q_head++;			if (ha->ioctl->aen_q_head == EXT_DEF_MAX_AEN_QUEUE) {				ha->ioctl->aen_q_head = 0;			}		}	}	DEBUG(printk("qla2x00_enqueue_aen: Adding code 0x%x to aen_q %p @ %d\n",	    event_code, aen_queue, ha->ioctl->aen_q_tail);)	new_entry = ha->ioctl->aen_q_tail;	aen_queue[new_entry].AsyncEventCode = event_code;	DEBUG(printk("qla2x00_enqueue_aen: Adding code 0x%8x\n",	    aen_queue[new_entry].AsyncEventCode);)		/* Update payload */	switch (event_code) {	case MBA_LIP_OCCURRED:	case MBA_LOOP_UP:	case MBA_LOOP_DOWN:	case MBA_LIP_RESET:	case MBA_PORT_UPDATE:		/* empty */		break;	case MBA_SCR_UPDATE:		mbx = (uint16_t *)payload;		/* al_pa */		aen_queue[new_entry].Payload.RSCN.RSCNInfo[0] = LSB(mbx[2]);		/* area */		aen_queue[new_entry].Payload.RSCN.RSCNInfo[1] = MSB(mbx[2]);		/* domain */		aen_queue[new_entry].Payload.RSCN.RSCNInfo[2] = LSB(mbx[1]);		/* save in big endian */		BIG_ENDIAN_24(aen_queue[new_entry].Payload.RSCN.RSCNInfo[0]);		aen_queue[new_entry].Payload.RSCN.AddrFormat = MSB(mbx[1]);		break;	default:		/* Not supported */		aen_queue[new_entry].AsyncEventCode = 0;		break;	}	DEBUG9(printk("qla2x00_enqueue_aen: exiting.\n");)}STATIC intqla2x00_query(scsi_qla_host_t *ha, EXT_IOCTL *pext, int mode){	int rval;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?