xref: /illumos-gate/usr/src/uts/intel/io/dktp/controller/ata/capacity.notes.txt (revision 89b2a9fbeabf42fa54594df0e5927bcc50a07cc9)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22#
23# Copyright 1999 Sun Microsystems, Inc.  All rights reserved.
24# Use is subject to license terms.
25#
26
27#
28#ident	"%Z%%M%	%I%	%E% SMI"
29#
30
31Dan Mick, 2/16/1999
32
33I had to come up with some sort of synthetic device geometry in the
34case that a drive supports LBA access and therefore the BIOS's geometry
35may be wrong or too small.
36
37In despair at reading the specs, I asked the x3t13 reflector
38how one is supposed to calculate capacity:
39
40==
41X-Authentication-Warning: mage.dt.wdc.com: majordom set sender to owner-t13@dt.wdc.com using -f
42Date: Thu, 11 Feb 1999 19:16:39 -0800 (PST)
43From: Dan Mick <dan.mick@West>
44Subject: Capacity?
45To: t13@dt.wdc.com
46
47So, I'm sure I'm being naive in expecting there to be a way to
48reliably calculate the capacity of an ATA drive, but I can't make
49sense of the IDENTIFY DEVICE results, words
50
511,3,6,53,54-58,60-61
52
53Is the right algorithm for making sense of all this written down
54somewhere?  I *have* searched the specs and Hale's HIW docs and
55the "ATA FAQ" from Wehman and den Hahn, and I still don't understand
56how this can be so nondeterministic.
57
58Even assertions in the specs seem to be ignored; I have a drive for
59which words 57-58 do *not* represent the product of words 54, 55, and
6056, for instance...
61==
62
63Several responses came; one from curtis_stevens@phoenix.com said "just
64use LBA", which of course doesn't answer the question about non-LBA
65drives.  David_S_Thompson@notes.seagate.com said "read section
666.2.1 of ATA-4, rev 17 or above", which does help a bit.  But
67the best pragmatic answer came from Hale Landis.  I've tried to
68implement this algorithm in deriving the capacity and geometry
69for ata, without using "Init Drive Parameters", since the driver
70hasn't done that in recent incarnations, and I'm loath to mess
71with what the BIOS and the drive have figured out unless it
72becomes absolutely necessary.
73
74
75From: "Hale Landis" <hlandis@ibm.net>
76To: "T13 Reflector" <t13@dt.wdc.com>, "Dan Mick" <dan.mick@West>
77Date: Thu, 11 Feb 1999 23:46:59 -0700
78Subject: Re: Capacity?
79
80Dan Mick said...
81>So, I'm sure I'm being naive in expecting there to be a way to
82>reliably calculate the capacity of an ATA drive, but I can't make
83>sense of the IDENTIFY DEVICE results, words
84>
85>1,3,6,53,54-58,60-61
86>
87>Is the right algorithm for making sense of all this written down
88>somewhere?  I *have* searched the specs and Hale's HIW docs and
89>the "ATA FAQ" from Wehman and den Hahn, and I still don't understand
90>how this can be so nondeterministic.
91>
92>Even assertions in the specs seem to be ignored; I have a drive for
93>which words 57-58 do *not* represent the product of words 54, 55, and
94>56, for instance...
95
96If the words [54]*[55]*[56] don't match [57:58] then the drive is
97"broken".  Warning: some older drives have words 57:58 in big endian
98format (that is easy to verify!).
99
100Of course Read/Set Max do alter the drive's apparent capacity but assuming
101this feature is not being used or it is being used and implemented
102correctly...
103
104If you have no need to use CHS mode, then just ignore words 1, 3, 6 and
10553:58.  Words 60:61 are the drive capacity.  But even if you must use CHS
106mode, words 60:61 are still the true drive capacity but words 57:58 are
107the capacity that the current CHS geometry can address and [57:58] must be
108<= [60:61].  Oh yea, if you find that 57:58 are big endian then 60:61 are
109probably big endian too.
110
111An algorithm??? (I hope there aren't any typo's here)...
112
1131) If you are LBA only (don't use CHS) then words 60:61 are all you need,
114you are done.
115
1162) If you must use CHS then I suggest the following:
117
1182a) Check words 53:58...
119    does 53 indicate "valid",
120    is 1 <= [55] <= 16,
121    is 1 <= [56] <= 63,
122    and does [54]*[55]*[56] == [57:58]?
123
124   - Yes, you know that current CHS geometry of the drive, you are done.
125     If you don't like this geometry then issue an Init Drv Params with
126     a different heads and sectors and repeat this step.
127
128   - No, then go to 2b).
129
1302b) Does the drive support LBA and is [1]*[3]*[6] <= [60:61]?
131
132   - Yes, assume 60:61 are correct, and go to 2c)
133
134   - No, go to 2d)
135
1362c) Issue a Init Drv Params and set your favorite heads and sectors.
137    Compute the number of cylinders:
138
139    num-cyl = [60:61] / (favorite heads) * (favorite sectors)
140
141    The drive capacity is (num-cyl)*(favorite heads)*(favorite sectors).
142    And this value should be in 57:58 now.  You are done.
143
1442d) Now you got a problem... 60:61 are no good, 53:58 are no good.
145    You don't have much choice but to assume that [1]*[3]*[6] is the
146    drive capacity.  Issue an Init Drv Params to set the default geometry
147    from [3] and [6] -or- issue an Init Drv Params with your favorite
148    heads and sectors.  Compute the number of cylinders:
149
150    num-cyl = ([1]*[3]*[6]) / (num heads) * (num sectors)
151
152    The drive capacity is (num-cyl)*(num-head)*(num-sectors).
153
154    You are done.
155
156And one final thing... If you used Init Drv Params you must now verify
157that it worked.  Issue a read command and make sure you can read what you
158think is the last sector on the drive.  If this read fails with ABRT or
159IDNF, you are in *BIG* trouble.
160
161All we did here was find a CHS geometry and a drive capacity that should
162work.  If the drive has a Master Boot Record then this geometry may not
163have a CHS translation that matches the CHS translation that was used in
164that Master Boot Record.  But I'll not go into that here (I would probably
165have to say bad things about the documents published by some of my friends
166a few years ago!).
167
168I'll say "sorry" now to all you hardware folks that read these reflector
169messages but I'm sure this will begin a long series of messages on the
170reflector that will just bore you to near death!
171
172
173+---------------+---------------------------+
174| Hale Landis   | hlandis@ibm.net           |
175| Niwot, CO USA | hlandis@sugs.talisman.com |
176+---------------+---------------------------+
177| !! Coming soon: www.talisman.com/sugs  !! |
178+-------------------------------------------+
179