⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qla_iocb.c

📁 h内核
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************** *                  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>#include <scsi/scsi_tcq.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 *);static request_t *qla2x00_req_pkt(scsi_qla_host_t *ha);/** * 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);	}}

⌨️ 快捷键说明

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