qla_iocb.c

来自「优龙2410linux2.6.8内核源代码」· C语言 代码 · 共 724 行 · 第 1/2 页

C
724
字号
/****************************************************************************** *                  QLOGIC LINUX SOFTWARE * * QLogic ISP2x00 device driver for Linux 2.6.x * Copyright (C) 2003-2004 QLogic Corporation * (www.qlogic.com) * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * General Public License for more details. * ******************************************************************************/#include "qla_def.h"#include <linux/blkdev.h>#include <linux/delay.h>static inline uint16_t qla2x00_get_cmd_direction(struct scsi_cmnd *cmd);static inline cont_entry_t *qla2x00_prep_cont_type0_iocb(scsi_qla_host_t *);static inline cont_a64_entry_t *qla2x00_prep_cont_type1_iocb(scsi_qla_host_t *);/** * qla2x00_get_cmd_direction() - Determine control_flag data direction. * @cmd: SCSI command * * Returns the proper CF_* direction based on CDB. */static inline uint16_tqla2x00_get_cmd_direction(struct scsi_cmnd *cmd){	uint16_t cflags;	cflags = 0;	/* Set transfer direction */	if (cmd->sc_data_direction == DMA_TO_DEVICE)		cflags = CF_WRITE;	else if (cmd->sc_data_direction == DMA_FROM_DEVICE)		cflags = CF_READ;	return (cflags);}/** * qla2x00_calc_iocbs_32() - Determine number of Command Type 2 and * Continuation Type 0 IOCBs to allocate. * * @dsds: number of data segment decriptors needed * * Returns the number of IOCB entries needed to store @dsds. */uint16_tqla2x00_calc_iocbs_32(uint16_t dsds){	uint16_t iocbs;	iocbs = 1;	if (dsds > 3) {		iocbs += (dsds - 3) / 7;		if ((dsds - 3) % 7)			iocbs++;	}	return (iocbs);}/** * qla2x00_calc_iocbs_64() - Determine number of Command Type 3 and * Continuation Type 1 IOCBs to allocate. * * @dsds: number of data segment decriptors needed * * Returns the number of IOCB entries needed to store @dsds. */uint16_tqla2x00_calc_iocbs_64(uint16_t dsds){	uint16_t iocbs;	iocbs = 1;	if (dsds > 2) {		iocbs += (dsds - 2) / 5;		if ((dsds - 2) % 5)			iocbs++;	}	return (iocbs);}/** * qla2x00_prep_cont_type0_iocb() - Initialize a Continuation Type 0 IOCB. * @ha: HA context * * Returns a pointer to the Continuation Type 0 IOCB packet. */static inline cont_entry_t *qla2x00_prep_cont_type0_iocb(scsi_qla_host_t *ha){	cont_entry_t *cont_pkt;	/* Adjust ring index. */	ha->req_ring_index++;	if (ha->req_ring_index == ha->request_q_length) {		ha->req_ring_index = 0;		ha->request_ring_ptr = ha->request_ring;	} else {		ha->request_ring_ptr++;	}	cont_pkt = (cont_entry_t *)ha->request_ring_ptr;	/* Load packet defaults. */	*((uint32_t *)(&cont_pkt->entry_type)) =	    __constant_cpu_to_le32(CONTINUE_TYPE);	return (cont_pkt);}/** * qla2x00_prep_cont_type1_iocb() - Initialize a Continuation Type 1 IOCB. * @ha: HA context * * Returns a pointer to the continuation type 1 IOCB packet. */static inline cont_a64_entry_t *qla2x00_prep_cont_type1_iocb(scsi_qla_host_t *ha){	cont_a64_entry_t *cont_pkt;	/* Adjust ring index. */	ha->req_ring_index++;	if (ha->req_ring_index == ha->request_q_length) {		ha->req_ring_index = 0;		ha->request_ring_ptr = ha->request_ring;	} else {		ha->request_ring_ptr++;	}	cont_pkt = (cont_a64_entry_t *)ha->request_ring_ptr;	/* Load packet defaults. */	*((uint32_t *)(&cont_pkt->entry_type)) =	    __constant_cpu_to_le32(CONTINUE_A64_TYPE);	return (cont_pkt);}/** * qla2x00_build_scsi_iocbs_32() - Build IOCB command utilizing 32bit * capable IOCB types. * * @sp: SRB command to process * @cmd_pkt: Command type 2 IOCB * @tot_dsds: Total number of segments to transfer */void qla2x00_build_scsi_iocbs_32(srb_t *sp, cmd_entry_t *cmd_pkt,    uint16_t tot_dsds){	uint16_t	avail_dsds;	uint32_t	*cur_dsd;	scsi_qla_host_t	*ha;	struct scsi_cmnd *cmd;	cmd = sp->cmd;	/* Update entry type to indicate Command Type 2 IOCB */	*((uint32_t *)(&cmd_pkt->entry_type)) =	    __constant_cpu_to_le32(COMMAND_TYPE);	/* No data transfer */	if (cmd->request_bufflen == 0 || cmd->sc_data_direction == DMA_NONE) {		cmd_pkt->byte_count = __constant_cpu_to_le32(0);		return;	}	ha = sp->ha;	cmd_pkt->control_flags |= cpu_to_le16(qla2x00_get_cmd_direction(cmd));	/* Three DSDs are available in the Command Type 2 IOCB */	avail_dsds = 3;	cur_dsd = (uint32_t *)&cmd_pkt->dseg_0_address;	/* Load data segments */	if (cmd->use_sg != 0) {		struct	scatterlist *cur_seg;		struct	scatterlist *end_seg;		cur_seg = (struct scatterlist *)cmd->request_buffer;		end_seg = cur_seg + tot_dsds;		while (cur_seg < end_seg) {			cont_entry_t	*cont_pkt;			/* Allocate additional continuation packets? */			if (avail_dsds == 0) {				/*				 * Seven DSDs are available in the Continuation				 * Type 0 IOCB.				 */				cont_pkt = qla2x00_prep_cont_type0_iocb(ha);				cur_dsd = (uint32_t *)&cont_pkt->dseg_0_address;				avail_dsds = 7;			}			*cur_dsd++ = cpu_to_le32(sg_dma_address(cur_seg));			*cur_dsd++ = cpu_to_le32(sg_dma_len(cur_seg));			avail_dsds--;			cur_seg++;		}	} else {		dma_addr_t	req_dma;		struct page	*page;		unsigned long	offset;		page = virt_to_page(cmd->request_buffer);		offset = ((unsigned long)cmd->request_buffer & ~PAGE_MASK);		req_dma = pci_map_page(ha->pdev, page, offset,		    cmd->request_bufflen, cmd->sc_data_direction);		sp->dma_handle = req_dma;		*cur_dsd++ = cpu_to_le32(req_dma);		*cur_dsd++ = cpu_to_le32(cmd->request_bufflen);	}}/** * qla2x00_build_scsi_iocbs_64() - Build IOCB command utilizing 64bit * capable IOCB types. * * @sp: SRB command to process * @cmd_pkt: Command type 3 IOCB * @tot_dsds: Total number of segments to transfer */void qla2x00_build_scsi_iocbs_64(srb_t *sp, cmd_entry_t *cmd_pkt,    uint16_t tot_dsds){	uint16_t	avail_dsds;	uint32_t	*cur_dsd;	scsi_qla_host_t	*ha;	struct scsi_cmnd *cmd;	cmd = sp->cmd;	/* Update entry type to indicate Command Type 3 IOCB */	*((uint32_t *)(&cmd_pkt->entry_type)) =	    __constant_cpu_to_le32(COMMAND_A64_TYPE);	/* No data transfer */	if (cmd->request_bufflen == 0 || cmd->sc_data_direction == DMA_NONE) {		cmd_pkt->byte_count = __constant_cpu_to_le32(0);		return;	}	ha = sp->ha;	cmd_pkt->control_flags |= cpu_to_le16(qla2x00_get_cmd_direction(cmd));	/* Two DSDs are available in the Command Type 3 IOCB */	avail_dsds = 2;	cur_dsd = (uint32_t *)&cmd_pkt->dseg_0_address;	/* Load data segments */	if (cmd->use_sg != 0) {		struct	scatterlist *cur_seg;		struct	scatterlist *end_seg;		cur_seg = (struct scatterlist *)cmd->request_buffer;		end_seg = cur_seg + tot_dsds;		while (cur_seg < end_seg) {			dma_addr_t	sle_dma;			cont_a64_entry_t *cont_pkt;			/* Allocate additional continuation packets? */			if (avail_dsds == 0) {				/*				 * Five DSDs are available in the Continuation				 * Type 1 IOCB.				 */				cont_pkt = qla2x00_prep_cont_type1_iocb(ha);				cur_dsd = (uint32_t *)cont_pkt->dseg_0_address;				avail_dsds = 5;			}			sle_dma = sg_dma_address(cur_seg);			*cur_dsd++ = cpu_to_le32(LSD(sle_dma));			*cur_dsd++ = cpu_to_le32(MSD(sle_dma));			*cur_dsd++ = cpu_to_le32(sg_dma_len(cur_seg));			avail_dsds--;			cur_seg++;		}	} else {		dma_addr_t	req_dma;		struct page	*page;		unsigned long	offset;		page = virt_to_page(cmd->request_buffer);		offset = ((unsigned long)cmd->request_buffer & ~PAGE_MASK);		req_dma = pci_map_page(ha->pdev, page, offset,		    cmd->request_bufflen, cmd->sc_data_direction);		sp->dma_handle = req_dma;		*cur_dsd++ = cpu_to_le32(LSD(req_dma));		*cur_dsd++ = cpu_to_le32(MSD(req_dma));		*cur_dsd++ = cpu_to_le32(cmd->request_bufflen);	}}/** * qla2x00_start_scsi() - Send a SCSI command to the ISP * @sp: command to send to the ISP * * Returns non-zero if a failure occured, else zero. */intqla2x00_start_scsi(srb_t *sp){	int		ret;	unsigned long   flags;	scsi_qla_host_t	*ha;	fc_lun_t	*fclun;	struct scsi_cmnd *cmd;	uint32_t	*clr_ptr;	uint32_t        index;	uint32_t	handle;	cmd_entry_t	*cmd_pkt;	uint32_t        timeout;	struct scatterlist *sg;	uint16_t	cnt;	uint16_t	req_cnt;	uint16_t	tot_dsds;	device_reg_t	*reg;	/* Setup device pointers. */	ret = 0;	fclun = sp->lun_queue->fclun;	ha = fclun->fcport->ha;	cmd = sp->cmd;	reg = ha->iobase;	/* Send marker if required */	if (ha->marker_needed != 0) {		if (qla2x00_marker(ha, 0, 0, MK_SYNC_ALL) != QLA_SUCCESS) {			return (QLA_FUNCTION_FAILED);		}		ha->marker_needed = 0;	}	/* Acquire ring specific lock */	spin_lock_irqsave(&ha->hardware_lock, flags);	/* Check for room in outstanding command list. */	handle = ha->current_outstanding_cmd;	for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) {		handle++;

⌨️ 快捷键说明

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