The translation is temporarily closed for contributions due to maintenance, please come back later.

Translation

BecauseAs we are interested in writing a SCSI adapter driver here, from this point on we will consider everything from the SIM standpoint.
(itstool) path: sect1/para
English
As we are interested in writing a SCSI adapter driver here, from this point on we will consider everything from the SIM standpoint.
Context English Chinese (Simplified) (zh_CN) State
This document assumes that the reader has a general understanding of device drivers in FreeBSD and of the SCSI protocol. Much of the information in this document was extracted from the drivers: 本文档假定读者对FreeBSD的设备驱动程序和SCSI协议有大致了解,本文档中很多信息是从以下驱动程序中:
ncr (<filename>/sys/pci/ncr.c</filename>) by Wolfgang Stanglmeier and Stefan Esser ncr (<filename>/sys/pci/ncr.c</filename>) by Wolfgang Stanglmeier and Stefan Esser
sym (<filename>/sys/dev/sym/sym_hipd.c</filename>) by Gerard Roudier sym (<filename>/sys/dev/sym/sym_hipd.c</filename>) by Gerard Roudier
aic7xxx (<filename>/sys/dev/aic7xxx/aic7xxx.c</filename>) by Justin T. Gibbs aic7xxx (<filename>/sys/dev/aic7xxx/aic7xxx.c</filename>) by Justin T. Gibbs
and from the CAM code itself (by Justin T. Gibbs, see <filename>/sys/cam/*</filename>). When some solution looked the most logical and was essentially verbatim extracted from the code by Justin T. Gibbs, I marked it as <quote>recommended</quote>. 和从CAM的代码本身(作者 Justin T. Gibbs,见<filename>/sys/cam/*</filename>)中摘录。当一些解决方法看起来极具逻辑性,并且基本上是从 Justin T. Gibbs 的代码中一字不差地摘录时,我将其标记为<quote>recommended</quote>。
The document is illustrated with examples in pseudo-code. Although sometimes the examples have many details and look like real code, it is still pseudo-code. It was written to demonstrate the concepts in an understandable way. For a real driver other approaches may be more modular and efficient. It also abstracts from the hardware details, as well as issues that would cloud the demonstrated concepts or that are supposed to be described in the other chapters of the developers handbook. Such details are commonly shown as calls to functions with descriptive names, comments or pseudo-statements. Fortunately real life full-size examples with all the details can be found in the real drivers. 本文档以伪代码例子进行说明。尽管有时例子中包含很多细节,并且看起来很像真正代码,但它仍然只是伪代码。这样写是为了以一种可理解的方式来展示概念。对于真正的驱动程序,其它方法可能更模块化,并且更加高效。文档也对硬件细节进行抽象,对于那些会模糊我们所要展示的概念的问题,或被认为在开发者手册的其他章节中已有描述的问题也做同样处理。这些细节通常以调用具有描述性名字的函数、注释或伪语句的形式展现。幸运的是,具有实际价值的完整例子,包括所有细节,可以在真正的驱动程序中找到。
General Architecture 通用基础结构
<primary>Common Access Method (CAM)</primary> <primary>Common Access Method (CAM)</primary>
CAM stands for Common Access Method. It is a generic way to address the I/O buses in a SCSI-like way. This allows a separation of the generic device drivers from the drivers controlling the I/O bus: for example the disk driver becomes able to control disks on both SCSI, IDE, and/or any other bus so the disk driver portion does not have to be rewritten (or copied and modified) for every new I/O bus. Thus the two most important active entities are: CAM代表通用访问方法(Common Access Method)。它以类SCSI方式寻址I/O总线。这就允许将通用设备驱动程序和控制I/O总线的驱动程序分离开来:例如磁盘驱动程序能同时控制SCSI、IDE、且/或任何其他总线上的磁盘,这样磁盘驱动程序部分不必为每种新的I/O总线而重写(或拷贝修改)。这样,两个最重要的活动实体是:
<primary>CD-ROM</primary> <primary>CD-ROM</primary>
<primary>tape</primary> <primary>tape(磁带)</primary>
<primary>IDE</primary> <primary>IDE</primary>
<emphasis>Peripheral Modules</emphasis> - a driver for peripheral devices (disk, tape, CD-ROM, etc.) <emphasis>外围设备模块</emphasis> - 外围设备(磁盘,磁带, CD-ROM等)的驱动程序
<emphasis>SCSI Interface Modules </emphasis>(SIM) - a Host Bus Adapter drivers for connecting to an I/O bus such as SCSI or IDE. <emphasis>SCSI接口模块</emphasis>(SIM)- 连接到I/O总线,如SCSI或IDE,的主机总线适配器驱动程序。
A peripheral driver receives requests from the OS, converts them to a sequence of SCSI commands and passes these SCSI commands to a SCSI Interface Module. The SCSI Interface Module is responsible for passing these commands to the actual hardware (or if the actual hardware is not SCSI but, for example, IDE then also converting the SCSI commands to the native commands of the hardware). 外围设备驱动程序从OS接收请求,将它们转换为SCSI命令序列并将这些SCSI命令传递到SCSI接口模块。SCSI接口模块负责将这些命令传递给实际硬件(或者如果实际硬件不是SCSI,而是例如IDE,则也要将这些SCSI命令转换为硬件的native命令)。
As we are interested in writing a SCSI adapter driver here, from this point on we will consider everything from the SIM standpoint. 由于这儿我们感兴趣的是编写SCSI适配器驱动程序,从此处开始我们将从SIM的角度考虑所有的事情。
A typical SIM driver needs to include the following CAM-related header files: 典型的SIM驱动程序需要包括如下的CAM相关的头文件:
#include &lt;cam/cam.h&gt;
#include &lt;cam/cam_ccb.h&gt;
#include &lt;cam/cam_sim.h&gt;
#include &lt;cam/cam_xpt_sim.h&gt;
#include &lt;cam/cam_debug.h&gt;
#include &lt;cam/scsi/scsi_all.h&gt;
#include &lt;cam/cam.h&gt;
#include &lt;cam/cam_ccb.h&gt;
#include &lt;cam/cam_sim.h&gt;
#include &lt;cam/cam_xpt_sim.h&gt;
#include &lt;cam/cam_debug.h&gt;
#include &lt;cam/scsi/scsi_all.h&gt;
The first thing each SIM driver must do is register itself with the CAM subsystem. This is done during the driver's <function>xxx_attach()</function> function (here and further xxx_ is used to denote the unique driver name prefix). The <function>xxx_attach()</function> function itself is called by the system bus auto-configuration code which we do not describe here. 每个SIM驱动程序必须做的第一件事情是向CAM子系统注册它自己。这在驱动程序的<function>xxx_attach()</function>函数(此处和以后的xxx_用于指带唯一的驱动程序名字前缀)期间完成。<function>xxx_attach()</function>函数自身由系统总线自动配置代码调用,我们在此不描述这部分代码。
This is achieved in multiple steps: first it is necessary to allocate the queue of requests associated with this SIM: 这需要好几步来完成:首先需要分配与SIM关联的请求队列:
struct cam_devq *devq;

if(( devq = cam_simq_alloc(SIZE) )==NULL) {
error; /* some code to handle the error */
}
struct cam_devq *devq;

if(( devq = cam_simq_alloc(SIZE) )==NULL) {
error; /* some code to handle the error */
}
Here <literal>SIZE</literal> is the size of the queue to be allocated, maximal number of requests it could contain. It is the number of requests that the SIM driver can handle in parallel on one SCSI card. Commonly it can be calculated as: 此处 <literal>SIZE</literal> 为要分配的队列的大小,它能包含的最大请求数目。 它是 SIM驱动程序在 SCSI 卡上能够并行处理的请求的数目。一般可以如下估算:
SIZE = NUMBER_OF_SUPPORTED_TARGETS * MAX_SIMULTANEOUS_COMMANDS_PER_TARGET SIZE = NUMBER_OF_SUPPORTED_TARGETS * MAX_SIMULTANEOUS_COMMANDS_PER_TARGET
Next we create a descriptor of our SIM: 下一步为我们的SIM创建描述符:
struct cam_sim *sim;

if(( sim = cam_sim_alloc(action_func, poll_func, driver_name,
softc, unit, mtx, max_dev_transactions,
max_tagged_dev_transactions, devq) )==NULL) {
cam_simq_free(devq);
error; /* some code to handle the error */
}
struct cam_sim *sim;

if(( sim = cam_sim_alloc(action_func, poll_func, driver_name,
softc, unit, mtx, max_dev_transactions,
max_tagged_dev_transactions, devq) )==NULL) {
cam_simq_free(devq);
error; /* some code to handle the error */
}
Note that if we are not able to create a SIM descriptor we free the <varname remap="structname">devq</varname> also because we can do nothing else with it and we want to conserve memory. 注意如果我们不能创建SIM描述符,我们也释放<varname remap="structname">devq</varname>,因为我们对其无法做任何其他事情,而且我们想节约内存。
<primary>SCSI</primary><secondary>bus</secondary> <primary>SCSI</primary><secondary>bus</secondary>
If a SCSI card has multiple SCSI buses<_:indexterm-1/> on it then each bus requires its own <varname remap="structname">cam_sim</varname> structure. 如果SCSI卡上有多条SCSI总线,则每条总线需要它自己的<varname remap="structname">cam_sim</varname> 结构。
An interesting question is what to do if a SCSI card has more than one SCSI bus, do we need one <varname remap="structname">devq</varname> structure per card or per SCSI bus? The answer given in the comments to the CAM code is: either way, as the driver's author prefers. 一个有趣的问题是,如果SCSI卡有不只一条SCSI总线我们该怎么做,每个卡需要一个<varname remap="structname">devq</varname>结构还是每条SCSI总线?在CAM代码的注释中给出的答案是:任一方式均可,由驱动程序的作者选择。
The arguments are: 参量为:
<funcdef>static void <function>xxx_action</function> </funcdef> <paramdef> <parameter>struct cam_sim *sim</parameter>, <parameter>union ccb *ccb</parameter> </paramdef> <funcdef>static void <function>xxx_action</function> </funcdef> <paramdef> <parameter>struct cam_sim *sim</parameter>, <parameter>union ccb *ccb</parameter> </paramdef>

Loading…

BecauseAs we are interested in writing a SCSI adapter driver here, from this point on we will consider everything from the SIM standpoint.
a month ago
Browse all component changes

Glossary

English Chinese (Simplified) (zh_CN)
No related strings found in the glossary.

Source information

Source string comment
(itstool) path: sect1/para
Source string location
book.translate.xml:19566
String age
a month ago
Source string age
a month ago
Translation file
books/zh_CN/arch-handbook.po, string 2124