Notes on Linux's SG driver version 2.1.36
-----------------------------------------
20000110
Introduction
============
The SCSI Generic driver (sg) is one of the four "high level" SCSI device
drivers along with sd, st and sr (disk, tape and CDROM respectively). Sg
is more generalized (but lower level) than its siblings and tends to be
used on SCSI devices that don't fit into the already serviced categories.
Thus sg is used for scanners, cd writers and reading audio cds digitally
amongst other things.
These are notes on the Linux SCSI generic packet device driver (sg)
describing version 2.1.36 . The original driver was written by Lawrence
Foard and remained in place with minimal changes since circa 1992.
Version 2 of this driver remains backward compatible (binary and
source **) with the original. It adds scatter gather, command queuing,
per file descriptor sequencing, asynchronous notification and better
error reporting.
This is an abridged version of the sg documentation that is targeted
at the linux/Documentation directory. The full document can be found
at http://www.torque.net/sg/p/scsi-generic_long.txt .
The interface and usage of the original sg driver have been documented
by Heiko Eissfeldt in a HOWTO called SCSI-Programming-HOWTO. My copy
of the document is version 1.5 dated 7th May 1996. It can found at
ftp://sunsite.unc.edu/pub/Linux/docs/HOWTO-SCSI-Programming-HOWTO .
A copy of this document can be found at:
http://www.torque.net/sg/p/original/HOWTO-SCSI-Programming-HOWTO.txt .
** It is possible to write applications that perform differently
depending on whether they are using the original or this version of
the sg device driver. The author is not aware of any useful
pre-existing applications that have problems with version 2.
Architecture
============
The SCSI generic packet device driver (sg) is a character based device.
It is one of the four high level device driver in the SCSI sub-system;
the others are sd (for direct-access devices - disks), st (for tapes)
and sr (for data cdroms). The other three devices are block devices.
The unifying layer of the SCSI sub-system is the so-called mid-level.
Below that are the "low level" drivers which are the drivers for the
various adapters supported by Linux. Also at this level are pseudo
adapter drivers such as ide-scsi which converts the SCSI protocol to
ATAPI (which are similar to one another) for use by IDE devices.
Since sg is a character device it supports the traditional Unix
system calls of open(), close(), read(), write() and ioctl(). Two other
related system calls: poll() and fcntl() are added to this list and
how they interact with the sg device driver is documented later.
An SG device is accessed by write()ing SCSI commands plus any associated
outgoing data to it; the resulting status codes and any incoming data are
then obtained by a read() call. The device can be opened O_NONBLOCK
(non-blocking) and poll() used to monitor its progress. The device may be
opened O_EXCL which excludes other "sg" users from this device (but not
"sd", "st" or "sr" users). The buffer given to the write() call is made
up as follows:
- struct sg_header image (see below)
- scsi command (6, 10 or 12 bytes long)
- data to be written to the device (if any)
The buffer received from the corresponding read() call contains:
- struct sg_header image (check status/errors + sense_buffer)
- data read back from device (if any)
The given SCSI command has its LUN field overwritten by the LUN value of
the associated sg device that has been open()ed.
SCSI commands are only attempted once (i.e. there are no internal
retries). If appropriate (e.g. a SCSI READ) the data buffer is copied back
to user space irrespective of the values of the various SCSI related
error/status codes. [Some adapters that use an old error interface in
the SCSI mid level ignore the retry count and retry certain errors.]
sg_header
=========
This is the name of the control structure that conveys information
about the length of data to be read/written by the associated SCSI
command. It also conveys error and status information from the
read() call. An instance of this structure is the first thing that
is placed in the data buffers of both write() and read().
In its original form it looked like this:
struct sg_header {
int pack_len;
int reply_len;
int pack_id;
int result;
unsigned int twelve_byte:1;
unsigned int other_flags:31;
unsigned char sense_buffer[16];
}; /* this structure is 36 bytes long */
The 'pack_len' is bizarre and ends up having the 'reply_len' put in it
(perhaps it had a use at some stage). Even though it looks like an
input variable, it is not read by sg internally (only written).
The 'reply_len' is the length of the data the corresponding read()
will/should request (including the sg_header).
The 'pack_id' is not acted upon by the sg device driver but is conveyed
back to the corresponding read() so it can be used for sequencing by an
application.
The 'result' is also bizarre, turning certain types of host codes to 0 (no
error), EBUSY or EIO. With better error reporting now available, the
'result' is best ignored.
The 'twelve_byte' field overrides the internal SCSI command length detection
algorithm for group 6 and 7 commands (ie when 1st byte >= 0xc0) and forces
a command length of 12 bytes.
The command length detection algorithm is as follows:
Group: 0 1 2 3 4 5 6 7
Length: 6 10 10 12 12 12 10 10
'other_flags' was originally documented as "not used" but some current
applications assume it has 0 placed in it.
The 'sense_buffer' is the first 16 bytes of SCSI sense buffer that is
returned when the target returns a SCSI status code of CHECK_CONDITION
or COMMAND_TERMINATED [or (driver_status & DRIVER_SENSE) is true]. This
buffer should be at least 18 bytes long and arguably 32 bytes; unfortunately
this is unlikely to happen in the 2.2.x series of kernels.
The new sg_header offered in this driver is:
#define SG_MAX_SENSE 16
struct sg_header
{
int pack_len; /* [o] reply_len (ie useless) ignored as input */
int reply_len; /* [i] max length of expected reply (inc. sg_header) */
int pack_id; /* [io] id number of packet (use ints >= 0) */
int result; /* [o] 0==ok, else (+ve) Unix errno (best ignored) */
unsigned int twelve_byte:1;
/* [i] Force 12 byte command length for group 6 & 7 commands */
unsigned int target_status:5; /* [o] scsi status from target */
unsigned int host_status:8; /* [o] host status (see "DID" codes) */
unsigned int driver_status:8; /* [o] driver status+suggestion */
unsigned int other_flags:10; /* unused */
unsigned char sense_buffer[SG_MAX_SENSE]; /* [o] Output in 3 cases:
when target_status is CHECK_CONDITION or
when target_status is COMMAND_TERMINATED or
when (driver_status & DRIVER_SENSE) is true. */
}; /* This structure is 36 bytes long on i386 */
Firstly the new header is binary compatible with the original. This is
important for keeping existing apps working without recompilation.
Only those elements (or fields) that are new or in some way different
from the original are documented below.
'pack_id' becomes input to a read() when ioctl(sg_fd, SG_SET_FORCE_PACK_ID,
&one) is active. A 'pack_id' of -1 is interpreted as fetch the oldest
waiting packet; any other value will cause the read() to wait (or yield
EAGAIN) until a packet with that 'pack_id' becomes available. In all cases
the value of 'pack_id' available after a read() is the value given to that
variable in the prior, corresponding write().
The SCSI command length can now be given directly using the SG_NEXT_CMD_LEN
ioctl().
The 'target_status' field is always output and is the (masked and shifted
1 bit right) SCSI status code from the target devic
没有合适的资源?快使用搜索试试~ 我知道了~
NUC972-FreeRTOS+littleVGL--800x480或480x272.rar
共1407个文件
h:455个
c:390个
mk:109个
需积分: 49 17 下载量 123 浏览量
2021-07-19
13:51:53
上传
评论 1
收藏 18.29MB RAR 举报
温馨提示
这个是新塘开发板上运行的例程, 原来的程序是480的, 现在改成通过宏来切换800的屏还是480的屏.
资源推荐
资源详情
资源评论
收起资源包目录
NUC972-FreeRTOS+littleVGL--800x480或480x272.rar (1407个子文件)
03c17a08cbcbd44a65706d5f3077c86eba2649 173B
04fa85ec5b7d88710e7573b71543180659c243 391B
05ad6e6862797842a4106e968e5b50f70eeb37 3KB
05e68128741fe9d591c6c8d439729100b30988 386B
0c0fcc9402ac638931e96362fdf56e5bd5a003 7KB
0c7721b3f86ffbbabbc247c2482e7a155e0969 17KB
0fbe21b0369d26de23b9a258e51668a0a2bd21 390B
v5.1.1 41B
11607df4b5f51ed07cdb3096ccea4901213bbd 2KB
1331f7facc56632908658a38f53cec55eaa880 2KB
176da9ed641cb55e00b77c097d60cebfc965c8 144B
188be25e66780f236854726e4640d6e58fe6d9 5KB
1ef2612145936f31747ffb60888b24df4b656e 386B
244c2f1cad85e56491adeb9549f864ecf4a054 822B
24928580d6eeb25fa4b5e937beac7e47a53d91 5KB
2613344b0acbf098aaa0df6a099ca7278ac16e 488B
28572328b457a682cc5de62a6d1aaaca4cd332 332B
30f9739ba7951ca40b0d55574c2b869ca903bd 562B
3219ba1a9d6cf3d13fda8aa982c965d9bc206d 2KB
33e24ee5f2bd79bf125215aff216d4b0f6d4b5 454B
354dbbce3b3ce5aac3ae37bd22e2c5c4182bfc 3KB
3cdd791b8a13e6295a69acc0527af4c690cbd5 177B
4050685838ecf8368ac3e0f9291e8d208ddece 236B
41676a643a9a41d2dff69a8855e6f4b80a7a7b 7KB
42d32a5efb5f95d98d5d01a812257a9c00f03e 4KB
45c469af9b648e874397854cc4eec4b494aec3 455B
495438ed799e05e7c7dda79441544e8f78d028 2KB
4a7d791a027c08a4574c88b3e18112ec8c5ea6 391B
4c2883fe952a229f476c9f856251628c648b65 391B
4eea631f059316756d39d9800cabd9c60b4f50 10KB
4fcdb2a40fe121a3d5ce254187e3a226ab20d5 6KB
50df3da779e5da3d7fbe8c9bf663330e074f1d 199B
517e317107be5b3e579f27b988f29ad4fa3a93 391B
524dc9fc220b234ba4b81e757d018ae88985da 2KB
53f4c5bc2932bced5fdff4e6cbbc1634cdbe48 391B
54020b8b70c9ce80b6a15ade45abea81fc3b75 204B
540bb9ecf8531954fdaff6983f0411072b3d87 390B
541452c549c5b0f5a950abeb7ca5b69f31bcf2 2KB
5515e2507c069cb2d797194d2fedfb48731191 1KB
5555afcfdf51a5a6f7094c9d04e0a7255348ed 171B
5593d667caf576d83ed08216a05d58f9b3fb43 5KB
56a3a6d7792a709a6c0bb991dd1938de0e8d85 4KB
5977e57414613f306784c6906b54803cbca035 215B
5d37d7025c8e37b0fda8d887684d82157d9981 1KB
614fa7add3d156fd572b5ef72f853ce92b9973 390B
63098138f4cf749029caa16e5fba9e06f44a9a 8KB
6d1148935b19de1cd30b4876da36cfec69b260 562B
6fb3003b17516d60c10570f114e7c81b669e0d 11KB
71bfcd0a1a3c4452f264c571fc12c8b512fc49 340B
7273280cce966da173a8fc3436db8348c0c196 7KB
72efd227ec8d79d976597a7f1e814e33f52144 6KB
7583baef2b19416846b63bcad31d6e2feb1543 391B
789d02022bf8d68ec52df8bf165c19a6b4eff6 392B
79ba99f4e81dada2a79da3a1181d28bb6e3eb1 391B
819d1d2b8322617091d5fadc4135a73e2e4f9d 173B
81c81ae3aba9463f2a682360d064b6b97732bd 5KB
8623e7a6b7a527e8769d9400ded163a9222c78 390B
876fd348d4b8df2169e9b9e2761238ed29b748 229B
8cc011146bd942f89f5c6fba87accbf3c26158 5KB
8e869f300008f60103b554b9a84403839f3937 5KB
8ee11955962b8d801cf309b49816093d0a3133 228B
91b3306a09a8a5fabd6003e9792581f1549268 192B
938995c362b97cd0771d603ee7ae901f520740 3KB
96eac14ca2095b1da5b0dc546e1e0d5d93855d 3KB
97824a223e4f3788414e893ad8441da16302f2 454B
9bbbe2c50df538d18930333809b7767aeed700 1KB
9e33c17d164bc12cb7378aa918c0265a76d5fb 5KB
a2cb08cb016923f5e7bb1ec0be933cc6196282 325B
a8b12121adeea989611daaa83a89aa5f3d3b68 171B
a91ef8f5cbb9408b34e3b18614b2db5225c567 1KB
abaef27f84b6aefeedbf14975442e9469f2b0e 192B
ad4b361636024161c8d8beb3c2c299b66f431d 220B
afb3a0c316a35f76b283310a5d6caae250b37f 495B
b0ba93d99c10aa688284caf555dcae3daf4145 1KB
b4820b9374d5848d1e11629590ed1b8987b7ee 168B
b7eac1bed33c9082d1f87b5963db1f5251b7bd 4KB
bac13527ece3940fd5ba68969ee0c197bbd899 839B
beta 2KB
beta 791B
beta 186B
beta 186B
beta 41B
beta 41B
beta 41B
beta 41B
blue_flower_24.bin 29KB
blue_flower_16.bin 15KB
blue_flower_8.bin 7KB
img_bubble_pattern.c 4.5MB
lv_font_symbol_40.c 1.11MB
lv_font_dejavu_40_latin_sup.c 1.09MB
lv_font_dejavu_40.c 1.02MB
lv_font_dejavu_40_cyrillic.c 867KB
cc936.c 697KB
lv_font_dejavu_30_latin_sup.c 676KB
lv_font_symbol_30.c 660KB
lv_font_dejavu_30.c 648KB
cc949.c 546KB
lv_font_dejavu_30_cyrillic.c 524KB
cc950.c 433KB
共 1407 条
- 1
- 2
- 3
- 4
- 5
- 6
- 15
资源评论
快乐的老鼠
- 粉丝: 205
- 资源: 25
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Screenshot_20240430_144340_com.ss.android.ugc.live.jpg
- 回到山沟沟.mp3
- 基于matlab实现自适应波束形成RLS及LMS算法仿真源程序1.rar
- 基于matlab实现自己编写的基于卡尔曼滤波的利用加速度传感器的计步器,测试数据是传感器放在腰部和手臂 .rar
- 基于matlab实现阵列信号处理,波束形成.rar
- 111111111111111111
- 基于matlab实现计步器编程;对当前的计步器装置的数值算法模拟 .rar
- Mdb学习查看PW;access;mdb;pw;password;patch
- 基于matlab实现关于语音信号声源定位DOA估计所用的一些传统算法.rar
- 基于ultralytics-yolov8, 将其检测/分类/分割/姿态等任务移植到rk3588上
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功