qla2x00_ioctl.c

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

C
2,436 行
字号
		driver_prop.DmaBitAddresses = 32;	if (pext->ResponseLen < sizeof(EXT_DRIVER))		transfer_size = pext->ResponseLen;	else		transfer_size = sizeof(EXT_DRIVER);	ret = verify_area(VERIFY_WRITE, (void *)pext->ResponseAdr ,	    transfer_size);	if (ret) {		pext->Status = EXT_STATUS_COPY_ERR;		DEBUG10(printk(		    "qla2x00_query_driver: ERROR verify WRITE rsp buf.\n");)		return pext->Status;	}	/* now copy up the ISP to user */	usr_temp   = (uint8_t *)pext->ResponseAdr;	kernel_tmp = (uint8_t *)&driver_prop;	copy_to_user(usr_temp, kernel_tmp, transfer_size);	pext->Status       = EXT_STATUS_OK;	pext->DetailStatus = EXT_STATUS_OK;	DEBUG9(printk("qla2x00_query_driver: exiting.\n");)	return pext->Status;}STATIC intqla2x00_query_fw(scsi_qla_host_t *ha, EXT_IOCTL *pext, int mode){	int		ret = EINVAL;	qla_boards_t	*bdp;	uint8_t		*usr_temp, *kernel_tmp;	uint32_t	transfer_size;	EXT_FW		fw_prop;	DEBUG9(printk("qla2x00_query_fw: entered.\n");)	memset(&fw_prop, 0, sizeof(EXT_FW));	bdp = &QLBoardTbl_fc[ha->devnum];	fw_prop.Version[0] = bdp->fwver[0];	fw_prop.Version[1] = bdp->fwver[1];	fw_prop.Version[2] = bdp->fwver[2];	transfer_size = sizeof(EXT_FW);	ret = verify_area(VERIFY_WRITE, (void *)pext->ResponseAdr ,	    transfer_size);	if (ret) {		pext->Status = EXT_STATUS_COPY_ERR;		DEBUG10(printk(		    "qla2x00_query_fw: ERROR verify WRITE rsp buf.\n");)		return pext->Status;	}	usr_temp   = (uint8_t *)pext->ResponseAdr;	kernel_tmp = (uint8_t *)&fw_prop;	copy_to_user(usr_temp, kernel_tmp, transfer_size);	pext->Status       = EXT_STATUS_OK;	pext->DetailStatus = EXT_STATUS_OK;	DEBUG9(printk("qla2x00_query_fw: exiting.\n");)	return pext->Status;}STATIC intqla2x00_send_fcct(scsi_qla_host_t *ha, EXT_IOCTL *pext, int mode){	int		ret = 0;	uint16_t	mb[MAILBOX_REGISTER_COUNT];	static fc_lun_t		temp_fclun;	fc_lun_t		*fclun;	static fc_port_t	tmp_fcport;	os_lun_t		*lq;	os_tgt_t		*tq;	static Scsi_Cmnd scsi_cmd;	Scsi_Cmnd	*pscsi_cmd = &scsi_cmd;	srb_t		*sp = NULL;	DEBUG9(printk("qla2x00_send_fcct(%ld): entered.\n", ha->host_no);)	/* check on current topology */	if ((ha->current_topology != ISP_CFG_F) &&	    (ha->current_topology != ISP_CFG_FL)) {		pext->Status = EXT_STATUS_DEV_NOT_FOUND;		DEBUG9_10(printk("qla2x00_send_fcct(%ld): ERROR not in F or FL"		    "mode.\n",ha->host_no);)		return ret;	}	if (ha->ioctl_mem_size <= 0) {		if (qla2x00_get_new_ioctl_dma_mem(ha,		    QLA_INITIAL_IOCTLMEM_SIZE) != QL_STATUS_SUCCESS) {			DEBUG9_10(printk("qla2x00_send_fcct: ERROR cannot "			    "alloc DMA buffer size=%lx.\n",			    QLA_INITIAL_IOCTLMEM_SIZE);)			pext->Status = EXT_STATUS_NO_MEMORY;			return pext->Status;		}	}	if (pext->ResponseLen > ha->ioctl_mem_size) {		if (qla2x00_get_new_ioctl_dma_mem(ha, pext->ResponseLen) !=		    QL_STATUS_SUCCESS) {			DEBUG9_10(printk("qla2x00_send_fcct: ERROR "			    "cannot alloc requested"			    "DMA buffer size %x.\n",			    pext->ResponseLen);)			pext->Status = EXT_STATUS_NO_MEMORY;			return pext->Status;		}		DEBUG9(printk("qla2x00_send_fcct(%ld): rsp buf length larger "		    "than existing size. Additional"		    "mem alloc successful.\n",		    ha->host_no);)	}	if (pext->RequestLen > ha->ioctl_mem_size) {		pext->Status = EXT_STATUS_INVALID_PARAM;		DEBUG9_10(printk("qla2x00_send_fcct(%ld): ERROR RequestLen"		    "too big=%x.\n",		    ha->host_no, pext->RequestLen);)		return pext->Status;	}	ret = verify_area(VERIFY_READ, (void *)pext->RequestAdr,	    pext->RequestLen);	if (ret) {		pext->Status = EXT_STATUS_COPY_ERR;		DEBUG9_10(printk("qla2x00_send_fcct(%ld): ERROR"		    "verify read request buf.\n",		    ha->host_no);)		return ret;	}	DEBUG9(printk("qla2x00_send_fcct(%ld): req buf verified.\n",	    ha->host_no);)	if ((sp = qla2x00_get_new_sp(ha)) == NULL) {		DEBUG9_10(printk("qla2x00_send_fcct: ERROR "		    "cannot alloc sp %p.\n", sp);)		pext->Status = EXT_STATUS_NO_MEMORY;		return pext->Status;	}	DEBUG9(printk("qla2x00_send_fcct(%ld): after alloc sp.\n",	    ha->host_no);)	/* clear scsi_cmd to be used */	memset(&scsi_cmd, 0, sizeof(Scsi_Cmnd));	memset(ha->ioctl_mem, 0, ha->ioctl_mem_size);	/* copy request buffer */	ret = copy_from_user(ha->ioctl_mem, pext->RequestAdr, pext->RequestLen);	if (ret) {		pext->Status = EXT_STATUS_COPY_ERR;		DEBUG9_10(printk("qla2x00_send_fcct(%ld): ERROR"		    "copy_from_user() failed (%d).\n",		    ha->host_no, ret);)		return ret;	}	DEBUG9(printk("qla2x00_send_fcct(%ld): after copy request.\n",	    ha->host_no);)	/* setup sp for this command */	tq = ha->ioctl->ioctl_tq;	lq = ha->ioctl->ioctl_lq;	sp->cmd = pscsi_cmd;	sp->flags = SRB_IOCTL;	sp->lun_queue = lq;	sp->tgt_queue = tq;	fclun = &temp_fclun;	fclun->fcport = &tmp_fcport;	fclun->lun = 0;	fclun->flags = 0;	fclun->next = NULL;	lq->fclun = fclun;	lq->fclun->fcport->ha = ha;	/* init scsi_cmd */	scsi_cmd.host = ha->host;	scsi_cmd.scsi_done = qla2x00_fcct_done;	/* check on management server login status */	if (ha->flags.management_server_logged_in == 0) {		/* login to management server device */		ret = qla2x00_login_fabric(ha, MANAGEMENT_SERVER, 0xff, 0xff,		    0xfa, &mb[0], BIT_1);		if (ret != 0 || mb[0] != 0x4000) {			pext->Status = EXT_STATUS_DEV_NOT_FOUND;	 		DEBUG10(printk("qla2x00_send_fcct(%ld): ERROR"			    "login to MS.\n",			    ha->host_no);)			atomic_set(&sp->ref_count, 0);			add_to_free_queue (ha, sp);			return pext->Status;		}		ha->flags.management_server_logged_in = 1;	}	DEBUG9(printk("qla2x00_send_fcct(%ld): success login to MS.\n",	    ha->host_no);)	/* check on loop down */	if (ha->loop_state != LOOP_READY || 		test_bit(CFG_ACTIVE, &ha->cfg_flags) ||	    (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) ||	    ABORTS_ACTIVE) {		pext->Status = EXT_STATUS_BUSY;		DEBUG10(printk("qla2x00_send_fcct(%ld): loop not ready.\n",		    ha->host_no);)		atomic_set(&sp->ref_count, 0);		add_to_free_queue (ha, sp);		return pext->Status;	}	DEBUG9(printk("qla2x00_send_fcct(%ld): going to issue command.\n",	    ha->host_no);)	ret = qla2x00_start_ms_cmd(ha, pext, sp);	DEBUG9(printk("qla2x00_send_fcct(%ld): after issue command.\n",	    ha->host_no);)	if (ret != 0) {		/* We waited and post function did not get called */		DEBUG9_10(printk("qla2x00_send_fcct(%ld): command timed out.\n",		    ha->host_no);)		pext->Status = EXT_STATUS_MS_NO_RESPONSE;		atomic_set(&sp->ref_count, 0);		add_to_free_queue (ha, sp);		return pext->Status;	}	if (CMD_COMPL_STATUS(pscsi_cmd) != 0 ||	    CMD_ENTRY_STATUS(pscsi_cmd) != 0) {		DEBUG9_10(printk(		    "qla2x00_send_fcct(%ld): command returned error=%x.\n",		    ha->host_no, CMD_COMPL_STATUS(pscsi_cmd));)		pext->Status = EXT_STATUS_ERR;		return pext->Status;	}	/* getting device data and putting in pext->ResponseAdr */	ret = verify_area(VERIFY_WRITE, (void *)pext->ResponseAdr ,	    pext->ResponseLen);	if (ret) {		pext->Status = EXT_STATUS_COPY_ERR;		DEBUG9_10(printk("qla2x00_send_fcct(%ld): ERROR verify write "		    "response buffer. ha=%p.\n",		    ha->host_no, ha);)		return ret;	}	/* sending back data returned from Management Server */	copy_to_user((uint8_t *)pext->ResponseAdr,	    (uint8_t *)ha->ioctl_mem, pext->ResponseLen);	DEBUG9(printk("qla2x00_send_fcct(%ld): exiting normally.\n",	    ha->host_no);)	return 0;}STATIC intqla2x00_start_ms_cmd(scsi_qla_host_t *ha, EXT_IOCTL *pext, srb_t *sp){	ms_iocb_entry_t	*pkt;	unsigned long cpu_flags = 0;	/* get spin lock for this operation */	spin_lock_irqsave(&ha->hardware_lock, cpu_flags);	/* Get MS request packet. */	pkt = (ms_iocb_entry_t *)qla2x00_ms_req_pkt(ha, sp);	if (pkt == NULL) {		/* release spin lock and return error. */		spin_unlock_irqrestore(&ha->hardware_lock, cpu_flags);		pext->Status = EXT_STATUS_NO_MEMORY;		DEBUG10(printk("qla2x00_ioctl: FCCT_PASSTHRU - could not get "		    "Request Packet.\n");)		return pext->Status;	}	pkt->entry_type  = MS_IOCB_TYPE;	pkt->entry_count = 1;	pkt->loop_id     = MANAGEMENT_SERVER;	pkt->timeout     = QLA_PT_CMD_TOV;	pkt->DSDcount    = 1;	pkt->RespDSDcount = 2;	pkt->Response_bytecount = pext->ResponseLen;	pkt->Request_bytecount  = pext->RequestLen;	/* loading command payload address */	pkt->dseg_req_address[0] = LS_64BITS(ha->ioctl_mem_phys);	pkt->dseg_req_address[1] = MS_64BITS(ha->ioctl_mem_phys);	pkt->dseg_req_length = pext->RequestLen;	/* loading command response address */	pkt->dseg_rsp_address[0] = LS_64BITS(ha->ioctl_mem_phys);	pkt->dseg_rsp_address[1] = MS_64BITS(ha->ioctl_mem_phys);	pkt->dseg_rsp_length = pext->ResponseLen;	/* set flag to indicate IOCTL FCCT PassThru in progress */	ha->ioctl->FCCT_InProgress = 1;	ha->ioctl->ioctl_tov = pkt->timeout + 1; /* 1 second more */	/* prepare for receiving completion. */	qla2x00_ioctl_sem_init(ha);	/* Issue command to ISP */	qla2x00_isp_cmd(ha);	ha->ioctl->cmpl_timer.expires = jiffies + ha->ioctl->ioctl_tov * HZ;	add_timer(&ha->ioctl->cmpl_timer);	DEBUG9(printk("qla2x00_start_ms_cmd: releasing hardware_lock.\n");)	spin_unlock_irqrestore(&ha->hardware_lock, cpu_flags);	DEBUG9(printk("qla2x00_start_ms_cmd: sleep for completion.\n");)	down(&ha->ioctl->cmpl_sem);	del_timer(&ha->ioctl->cmpl_timer);	if (ha->ioctl->FCCT_InProgress == 1) {	 	DEBUG9_10(printk("qla2x00_start_ms_cmd: timed out. exiting.\n");)		return 1;	}	DEBUG9(printk("qla2x00_start_ms_cmd: done. exiting.\n");)	return 0;}STATIC intqla2x00_wwpn_to_scsiaddr(scsi_qla_host_t *ha, EXT_IOCTL *pext, int mode){	int		rval;	fc_port_t	*tgt_fcport;	os_tgt_t	*tq;	uint8_t		tmp_wwpn[EXT_DEF_WWN_NAME_SIZE];	uint32_t	b, tgt, l;	EXT_SCSI_ADDR	tmp_addr;	DEBUG9(printk("qla2x00_wwpn_to_scsiaddr(%ld): entered.\n",	    ha->host_no);)	if (pext->RequestLen != EXT_DEF_WWN_NAME_SIZE ||	    pext->ResponseLen < sizeof(EXT_SCSI_ADDR)) {		/* error */		DEBUG9_10(printk("qla2x00_wwpn_to_scsiaddr(%ld): invalid WWN "		    "buffer size %d received.\n",		    ha->host_no, pext->ResponseLen);)		pext->Status = EXT_STATUS_INVALID_PARAM;		return pext->Status;	}	rval = verify_area(VERIFY_READ, (void *)pext->RequestAdr,			pext->RequestLen);	if (rval) {		DEBUG9_10(printk("qla2x00_wwpn_to_scsiaddr(%ld): ERROR "		    "VERIFY_READ request buf.\n", ha->host_no);)		pext->Status = EXT_STATUS_COPY_ERR;		return pext->Status;	}	rval = copy_from_user(tmp_wwpn, pext->RequestAdr, pext->RequestLen);	if (rval) {		DEBUG9_10(printk("qla2x00_wwpn_to_scsiaddr(%ld): ERROR "		    "copy_from_user failed (%d) request buf.\n",		    ha->host_no, rval);)		pext->Status = EXT_STATUS_COPY_ERR;		return pext->Status;	}	tq = NULL;	for (tgt = 0; tgt < MAX_TARGETS; tgt++) {		if (ha->otgt[tgt] == NULL) {			continue;		}		tq = ha->otgt[tgt];		if (tq->vis_port == NULL) {			break;		}		tgt_fcport = tq->vis_port;		if (memcmp(tmp_wwpn,				tgt_fcport->port_name,				EXT_DEF_WWN_NAME_SIZE) == 0) {			break;		}	}	if (tq == NULL || tgt >= MAX_TARGETS) {		DEBUG9_10(printk("qla2x00_query_disc_tgt: target dev not "		    "found. tq=%p, tgt=%x.\n", tq, tgt);)		pext->Status = EXT_STATUS_DEV_NOT_FOUND;		return pext->Status;	}	if (tq->vis_port == NULL) { 	/* dg 08/14/01 */		DEBUG9_10(printk("qla2x00_query_disc_tgt: target port not "		    "found. tq=%p, tgt=%x.\n", tq, tgt);)		pext->Status = EXT_STATUS_BUSY;		return pext->Status;	}		/* Currently we only have bus 0 and no translation on LUN */	b = 0;	l = 0;	/*	 * Return SCSI address. Currently no translation is done for	 * LUN.	 */	tmp_addr.Bus = b;	tmp_addr.Target = tgt;	tmp_addr.Lun = l;	if (pext->ResponseLen > sizeof(EXT_SCSI_ADDR))		pext->ResponseLen = sizeof(EXT_SCSI_ADDR);	rval = verify_area(VERIFY_WRITE, (void *)pext->ResponseAdr,	    pext->ResponseLen);	if (rval) {		pext->Status = EXT_STATUS_COPY_ERR;		DEBUG9_10(printk("qla2x00_wwpn_to_scsiaddr(%ld): ERROR "		    "VERIFY_WRITE response buf.\n", ha->host_no);)		return pext->Status;	}	copy_to_user((uint8_t *)pext->ResponseAdr, &tmp_addr,	    pext->ResponseLen);	DEBUG9(printk(KERN_INFO	    "qla2x00_wwpn_to_scsiaddr: Found t%d l%d for %02x%02x%02x%02x"	    "%02x%02x%02x%02x.\n",	    tmp_addr.Target, tmp_addr.Lun,	    tmp_wwpn[0], tmp_wwpn[1], tmp_wwpn[2], tmp_wwpn[3],	    tmp_wwpn[4], tmp_wwpn[5], tmp_wwpn[6], tmp_wwpn[7]);)	pext->Status = EXT_STATUS_OK;	DEBUG9(printk("qla2x00_wwpn_to_scsiaddr(%ld): exiting.\n",	    ha->host_no);)	return pext->Status;}STATIC intqla2x00_scsi_passthru(scsi_qla_host_t *ha, EXT_IOCTL *pext, int mode){	int tmp_rval = 0;	switch(pext->SubCode) {	case EXT_SC_SEND_SCSI_PASSTHRU:		tmp_rval = qla2x00_sc_scsi_passthru(ha, pext, mode);		br

⌨️ 快捷键说明

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