diff options
author | Tejun Heo <tj@kernel.org> | 2008-07-31 04:02:43 -0400 |
---|---|---|
committer | Jeff Garzik <jgarzik@redhat.com> | 2008-09-29 00:25:28 -0400 |
commit | b1c72916abbdd0a55015c87358536ca0ebaf6735 (patch) | |
tree | 1064fe92f2c3600dd6587c880d907020896b3348 /drivers/ata/libata-core.c | |
parent | b5b3fa386b8f96c7fa92e507e5deddc2637924b4 (diff) |
libata: implement slave_link
Explanation taken from the comment of ata_slave_link_init().
In libata, a port contains links and a link contains devices. There
is single host link but if a PMP is attached to it, there can be
multiple fan-out links. On SATA, there's usually a single device
connected to a link but PATA and SATA controllers emulating TF based
interface can have two - master and slave.
However, there are a few controllers which don't fit into this
abstraction too well - SATA controllers which emulate TF interface
with both master and slave devices but also have separate SCR
register sets for each device. These controllers need separate links
for physical link handling (e.g. onlineness, link speed) but should
be treated like a traditional M/S controller for everything else
(e.g. command issue, softreset).
slave_link is libata's way of handling this class of controllers
without impacting core layer too much. For anything other than
physical link handling, the default host link is used for both master
and slave. For physical link handling, separate @ap->slave_link is
used. All dirty details are implemented inside libata core layer.
From LLD's POV, the only difference is that prereset, hardreset and
postreset are called once more for the slave link, so the reset
sequence looks like the following.
prereset(M) -> prereset(S) -> hardreset(M) -> hardreset(S) ->
softreset(M) -> postreset(M) -> postreset(S)
Note that softreset is called only for the master. Softreset resets
both M/S by definition, so SRST on master should handle both (the
standard method will work just fine).
As slave_link excludes PMP support and only code paths which deal with
the attributes of physical link are affected, all the changes are
localized to libata.h, libata-core.c and libata-eh.c.
* ata_is_host_link() updated so that slave_link is considered as host
link too.
* iterator extended to iterate over the slave_link when using the
underbarred version.
* force param handling updated such that devno 16 is mapped to the
slave link/device.
* ata_link_on/offline() updated to return the combined result from
master and slave link. ata_phys_link_on/offline() are the direct
versions.
* EH autopsy and report are performed separately for master slave
links. Reset is udpated to implement the above described reset
sequence.
Except for reset update, most changes are minor, many of them just
modifying dev->link to ata_dev_phys_link(dev) or using phys online
test instead.
After this update, LLDs can take full advantage of per-dev SCR
registers by simply turning on slave link.
Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Jeff Garzik <jgarzik@redhat.com>
Diffstat (limited to 'drivers/ata/libata-core.c')
-rw-r--r-- | drivers/ata/libata-core.c | 202 |
1 files changed, 179 insertions, 23 deletions
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 71024e94c576..6eed58e35e12 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c | |||
@@ -179,13 +179,20 @@ struct ata_link *__ata_port_next_link(struct ata_port *ap, | |||
179 | return &ap->link; | 179 | return &ap->link; |
180 | } | 180 | } |
181 | 181 | ||
182 | /* we just iterated over the host link, what's next? */ | 182 | /* we just iterated over the host master link, what's next? */ |
183 | if (ata_is_host_link(link)) { | 183 | if (link == &ap->link) { |
184 | if (!sata_pmp_attached(ap)) | 184 | if (!sata_pmp_attached(ap)) { |
185 | if (unlikely(ap->slave_link) && !dev_only) | ||
186 | return ap->slave_link; | ||
185 | return NULL; | 187 | return NULL; |
188 | } | ||
186 | return ap->pmp_link; | 189 | return ap->pmp_link; |
187 | } | 190 | } |
188 | 191 | ||
192 | /* slave_link excludes PMP */ | ||
193 | if (unlikely(link == ap->slave_link)) | ||
194 | return NULL; | ||
195 | |||
189 | /* iterate to the next PMP link */ | 196 | /* iterate to the next PMP link */ |
190 | if (++link < ap->pmp_link + ap->nr_pmp_links) | 197 | if (++link < ap->pmp_link + ap->nr_pmp_links) |
191 | return link; | 198 | return link; |
@@ -193,6 +200,31 @@ struct ata_link *__ata_port_next_link(struct ata_port *ap, | |||
193 | } | 200 | } |
194 | 201 | ||
195 | /** | 202 | /** |
203 | * ata_dev_phys_link - find physical link for a device | ||
204 | * @dev: ATA device to look up physical link for | ||
205 | * | ||
206 | * Look up physical link which @dev is attached to. Note that | ||
207 | * this is different from @dev->link only when @dev is on slave | ||
208 | * link. For all other cases, it's the same as @dev->link. | ||
209 | * | ||
210 | * LOCKING: | ||
211 | * Don't care. | ||
212 | * | ||
213 | * RETURNS: | ||
214 | * Pointer to the found physical link. | ||
215 | */ | ||
216 | struct ata_link *ata_dev_phys_link(struct ata_device *dev) | ||
217 | { | ||
218 | struct ata_port *ap = dev->link->ap; | ||
219 | |||
220 | if (!ap->slave_link) | ||
221 | return dev->link; | ||
222 | if (!dev->devno) | ||
223 | return &ap->link; | ||
224 | return ap->slave_link; | ||
225 | } | ||
226 | |||
227 | /** | ||
196 | * ata_force_cbl - force cable type according to libata.force | 228 | * ata_force_cbl - force cable type according to libata.force |
197 | * @ap: ATA port of interest | 229 | * @ap: ATA port of interest |
198 | * | 230 | * |
@@ -235,7 +267,8 @@ void ata_force_cbl(struct ata_port *ap) | |||
235 | * the host link and all fan-out ports connected via PMP. If the | 267 | * the host link and all fan-out ports connected via PMP. If the |
236 | * device part is specified as 0 (e.g. 1.00:), it specifies the | 268 | * device part is specified as 0 (e.g. 1.00:), it specifies the |
237 | * first fan-out link not the host link. Device number 15 always | 269 | * first fan-out link not the host link. Device number 15 always |
238 | * points to the host link whether PMP is attached or not. | 270 | * points to the host link whether PMP is attached or not. If the |
271 | * controller has slave link, device number 16 points to it. | ||
239 | * | 272 | * |
240 | * LOCKING: | 273 | * LOCKING: |
241 | * EH context. | 274 | * EH context. |
@@ -243,12 +276,11 @@ void ata_force_cbl(struct ata_port *ap) | |||
243 | static void ata_force_link_limits(struct ata_link *link) | 276 | static void ata_force_link_limits(struct ata_link *link) |
244 | { | 277 | { |
245 | bool did_spd = false; | 278 | bool did_spd = false; |
246 | int linkno, i; | 279 | int linkno = link->pmp; |
280 | int i; | ||
247 | 281 | ||
248 | if (ata_is_host_link(link)) | 282 | if (ata_is_host_link(link)) |
249 | linkno = 15; | 283 | linkno += 15; |
250 | else | ||
251 | linkno = link->pmp; | ||
252 | 284 | ||
253 | for (i = ata_force_tbl_size - 1; i >= 0; i--) { | 285 | for (i = ata_force_tbl_size - 1; i >= 0; i--) { |
254 | const struct ata_force_ent *fe = &ata_force_tbl[i]; | 286 | const struct ata_force_ent *fe = &ata_force_tbl[i]; |
@@ -295,9 +327,9 @@ static void ata_force_xfermask(struct ata_device *dev) | |||
295 | int alt_devno = devno; | 327 | int alt_devno = devno; |
296 | int i; | 328 | int i; |
297 | 329 | ||
298 | /* allow n.15 for the first device attached to host port */ | 330 | /* allow n.15/16 for devices attached to host port */ |
299 | if (ata_is_host_link(dev->link) && devno == 0) | 331 | if (ata_is_host_link(dev->link)) |
300 | alt_devno = 15; | 332 | alt_devno += 15; |
301 | 333 | ||
302 | for (i = ata_force_tbl_size - 1; i >= 0; i--) { | 334 | for (i = ata_force_tbl_size - 1; i >= 0; i--) { |
303 | const struct ata_force_ent *fe = &ata_force_tbl[i]; | 335 | const struct ata_force_ent *fe = &ata_force_tbl[i]; |
@@ -349,9 +381,9 @@ static void ata_force_horkage(struct ata_device *dev) | |||
349 | int alt_devno = devno; | 381 | int alt_devno = devno; |
350 | int i; | 382 | int i; |
351 | 383 | ||
352 | /* allow n.15 for the first device attached to host port */ | 384 | /* allow n.15/16 for devices attached to host port */ |
353 | if (ata_is_host_link(dev->link) && devno == 0) | 385 | if (ata_is_host_link(dev->link)) |
354 | alt_devno = 15; | 386 | alt_devno += 15; |
355 | 387 | ||
356 | for (i = 0; i < ata_force_tbl_size; i++) { | 388 | for (i = 0; i < ata_force_tbl_size; i++) { |
357 | const struct ata_force_ent *fe = &ata_force_tbl[i]; | 389 | const struct ata_force_ent *fe = &ata_force_tbl[i]; |
@@ -2710,7 +2742,7 @@ static void sata_print_link_status(struct ata_link *link) | |||
2710 | return; | 2742 | return; |
2711 | sata_scr_read(link, SCR_CONTROL, &scontrol); | 2743 | sata_scr_read(link, SCR_CONTROL, &scontrol); |
2712 | 2744 | ||
2713 | if (ata_link_online(link)) { | 2745 | if (ata_phys_link_online(link)) { |
2714 | tmp = (sstatus >> 4) & 0xf; | 2746 | tmp = (sstatus >> 4) & 0xf; |
2715 | ata_link_printk(link, KERN_INFO, | 2747 | ata_link_printk(link, KERN_INFO, |
2716 | "SATA link up %s (SStatus %X SControl %X)\n", | 2748 | "SATA link up %s (SStatus %X SControl %X)\n", |
@@ -3401,6 +3433,12 @@ int ata_wait_ready(struct ata_link *link, unsigned long deadline, | |||
3401 | unsigned long nodev_deadline = ata_deadline(start, ATA_TMOUT_FF_WAIT); | 3433 | unsigned long nodev_deadline = ata_deadline(start, ATA_TMOUT_FF_WAIT); |
3402 | int warned = 0; | 3434 | int warned = 0; |
3403 | 3435 | ||
3436 | /* Slave readiness can't be tested separately from master. On | ||
3437 | * M/S emulation configuration, this function should be called | ||
3438 | * only on the master and it will handle both master and slave. | ||
3439 | */ | ||
3440 | WARN_ON(link == link->ap->slave_link); | ||
3441 | |||
3404 | if (time_after(nodev_deadline, deadline)) | 3442 | if (time_after(nodev_deadline, deadline)) |
3405 | nodev_deadline = deadline; | 3443 | nodev_deadline = deadline; |
3406 | 3444 | ||
@@ -3622,7 +3660,7 @@ int ata_std_prereset(struct ata_link *link, unsigned long deadline) | |||
3622 | } | 3660 | } |
3623 | 3661 | ||
3624 | /* no point in trying softreset on offline link */ | 3662 | /* no point in trying softreset on offline link */ |
3625 | if (ata_link_offline(link)) | 3663 | if (ata_phys_link_offline(link)) |
3626 | ehc->i.action &= ~ATA_EH_SOFTRESET; | 3664 | ehc->i.action &= ~ATA_EH_SOFTRESET; |
3627 | 3665 | ||
3628 | return 0; | 3666 | return 0; |
@@ -3700,7 +3738,7 @@ int sata_link_hardreset(struct ata_link *link, const unsigned long *timing, | |||
3700 | if (rc) | 3738 | if (rc) |
3701 | goto out; | 3739 | goto out; |
3702 | /* if link is offline nothing more to do */ | 3740 | /* if link is offline nothing more to do */ |
3703 | if (ata_link_offline(link)) | 3741 | if (ata_phys_link_offline(link)) |
3704 | goto out; | 3742 | goto out; |
3705 | 3743 | ||
3706 | /* Link is online. From this point, -ENODEV too is an error. */ | 3744 | /* Link is online. From this point, -ENODEV too is an error. */ |
@@ -4965,7 +5003,7 @@ int sata_scr_write_flush(struct ata_link *link, int reg, u32 val) | |||
4965 | } | 5003 | } |
4966 | 5004 | ||
4967 | /** | 5005 | /** |
4968 | * ata_link_online - test whether the given link is online | 5006 | * ata_phys_link_online - test whether the given link is online |
4969 | * @link: ATA link to test | 5007 | * @link: ATA link to test |
4970 | * | 5008 | * |
4971 | * Test whether @link is online. Note that this function returns | 5009 | * Test whether @link is online. Note that this function returns |
@@ -4978,7 +5016,7 @@ int sata_scr_write_flush(struct ata_link *link, int reg, u32 val) | |||
4978 | * RETURNS: | 5016 | * RETURNS: |
4979 | * True if the port online status is available and online. | 5017 | * True if the port online status is available and online. |
4980 | */ | 5018 | */ |
4981 | bool ata_link_online(struct ata_link *link) | 5019 | bool ata_phys_link_online(struct ata_link *link) |
4982 | { | 5020 | { |
4983 | u32 sstatus; | 5021 | u32 sstatus; |
4984 | 5022 | ||
@@ -4989,7 +5027,7 @@ bool ata_link_online(struct ata_link *link) | |||
4989 | } | 5027 | } |
4990 | 5028 | ||
4991 | /** | 5029 | /** |
4992 | * ata_link_offline - test whether the given link is offline | 5030 | * ata_phys_link_offline - test whether the given link is offline |
4993 | * @link: ATA link to test | 5031 | * @link: ATA link to test |
4994 | * | 5032 | * |
4995 | * Test whether @link is offline. Note that this function | 5033 | * Test whether @link is offline. Note that this function |
@@ -5002,7 +5040,7 @@ bool ata_link_online(struct ata_link *link) | |||
5002 | * RETURNS: | 5040 | * RETURNS: |
5003 | * True if the port offline status is available and offline. | 5041 | * True if the port offline status is available and offline. |
5004 | */ | 5042 | */ |
5005 | bool ata_link_offline(struct ata_link *link) | 5043 | bool ata_phys_link_offline(struct ata_link *link) |
5006 | { | 5044 | { |
5007 | u32 sstatus; | 5045 | u32 sstatus; |
5008 | 5046 | ||
@@ -5012,6 +5050,58 @@ bool ata_link_offline(struct ata_link *link) | |||
5012 | return false; | 5050 | return false; |
5013 | } | 5051 | } |
5014 | 5052 | ||
5053 | /** | ||
5054 | * ata_link_online - test whether the given link is online | ||
5055 | * @link: ATA link to test | ||
5056 | * | ||
5057 | * Test whether @link is online. This is identical to | ||
5058 | * ata_phys_link_online() when there's no slave link. When | ||
5059 | * there's a slave link, this function should only be called on | ||
5060 | * the master link and will return true if any of M/S links is | ||
5061 | * online. | ||
5062 | * | ||
5063 | * LOCKING: | ||
5064 | * None. | ||
5065 | * | ||
5066 | * RETURNS: | ||
5067 | * True if the port online status is available and online. | ||
5068 | */ | ||
5069 | bool ata_link_online(struct ata_link *link) | ||
5070 | { | ||
5071 | struct ata_link *slave = link->ap->slave_link; | ||
5072 | |||
5073 | WARN_ON(link == slave); /* shouldn't be called on slave link */ | ||
5074 | |||
5075 | return ata_phys_link_online(link) || | ||
5076 | (slave && ata_phys_link_online(slave)); | ||
5077 | } | ||
5078 | |||
5079 | /** | ||
5080 | * ata_link_offline - test whether the given link is offline | ||
5081 | * @link: ATA link to test | ||
5082 | * | ||
5083 | * Test whether @link is offline. This is identical to | ||
5084 | * ata_phys_link_offline() when there's no slave link. When | ||
5085 | * there's a slave link, this function should only be called on | ||
5086 | * the master link and will return true if both M/S links are | ||
5087 | * offline. | ||
5088 | * | ||
5089 | * LOCKING: | ||
5090 | * None. | ||
5091 | * | ||
5092 | * RETURNS: | ||
5093 | * True if the port offline status is available and offline. | ||
5094 | */ | ||
5095 | bool ata_link_offline(struct ata_link *link) | ||
5096 | { | ||
5097 | struct ata_link *slave = link->ap->slave_link; | ||
5098 | |||
5099 | WARN_ON(link == slave); /* shouldn't be called on slave link */ | ||
5100 | |||
5101 | return ata_phys_link_offline(link) && | ||
5102 | (!slave || ata_phys_link_offline(slave)); | ||
5103 | } | ||
5104 | |||
5015 | #ifdef CONFIG_PM | 5105 | #ifdef CONFIG_PM |
5016 | static int ata_host_request_pm(struct ata_host *host, pm_message_t mesg, | 5106 | static int ata_host_request_pm(struct ata_host *host, pm_message_t mesg, |
5017 | unsigned int action, unsigned int ehi_flags, | 5107 | unsigned int action, unsigned int ehi_flags, |
@@ -5151,11 +5241,11 @@ int ata_port_start(struct ata_port *ap) | |||
5151 | */ | 5241 | */ |
5152 | void ata_dev_init(struct ata_device *dev) | 5242 | void ata_dev_init(struct ata_device *dev) |
5153 | { | 5243 | { |
5154 | struct ata_link *link = dev->link; | 5244 | struct ata_link *link = ata_dev_phys_link(dev); |
5155 | struct ata_port *ap = link->ap; | 5245 | struct ata_port *ap = link->ap; |
5156 | unsigned long flags; | 5246 | unsigned long flags; |
5157 | 5247 | ||
5158 | /* SATA spd limit is bound to the first device */ | 5248 | /* SATA spd limit is bound to the attached device, reset together */ |
5159 | link->sata_spd_limit = link->hw_sata_spd_limit; | 5249 | link->sata_spd_limit = link->hw_sata_spd_limit; |
5160 | link->sata_spd = 0; | 5250 | link->sata_spd = 0; |
5161 | 5251 | ||
@@ -5318,6 +5408,7 @@ static void ata_host_release(struct device *gendev, void *res) | |||
5318 | scsi_host_put(ap->scsi_host); | 5408 | scsi_host_put(ap->scsi_host); |
5319 | 5409 | ||
5320 | kfree(ap->pmp_link); | 5410 | kfree(ap->pmp_link); |
5411 | kfree(ap->slave_link); | ||
5321 | kfree(ap); | 5412 | kfree(ap); |
5322 | host->ports[i] = NULL; | 5413 | host->ports[i] = NULL; |
5323 | } | 5414 | } |
@@ -5438,6 +5529,68 @@ struct ata_host *ata_host_alloc_pinfo(struct device *dev, | |||
5438 | return host; | 5529 | return host; |
5439 | } | 5530 | } |
5440 | 5531 | ||
5532 | /** | ||
5533 | * ata_slave_link_init - initialize slave link | ||
5534 | * @ap: port to initialize slave link for | ||
5535 | * | ||
5536 | * Create and initialize slave link for @ap. This enables slave | ||
5537 | * link handling on the port. | ||
5538 | * | ||
5539 | * In libata, a port contains links and a link contains devices. | ||
5540 | * There is single host link but if a PMP is attached to it, | ||
5541 | * there can be multiple fan-out links. On SATA, there's usually | ||
5542 | * a single device connected to a link but PATA and SATA | ||
5543 | * controllers emulating TF based interface can have two - master | ||
5544 | * and slave. | ||
5545 | * | ||
5546 | * However, there are a few controllers which don't fit into this | ||
5547 | * abstraction too well - SATA controllers which emulate TF | ||
5548 | * interface with both master and slave devices but also have | ||
5549 | * separate SCR register sets for each device. These controllers | ||
5550 | * need separate links for physical link handling | ||
5551 | * (e.g. onlineness, link speed) but should be treated like a | ||
5552 | * traditional M/S controller for everything else (e.g. command | ||
5553 | * issue, softreset). | ||
5554 | * | ||
5555 | * slave_link is libata's way of handling this class of | ||
5556 | * controllers without impacting core layer too much. For | ||
5557 | * anything other than physical link handling, the default host | ||
5558 | * link is used for both master and slave. For physical link | ||
5559 | * handling, separate @ap->slave_link is used. All dirty details | ||
5560 | * are implemented inside libata core layer. From LLD's POV, the | ||
5561 | * only difference is that prereset, hardreset and postreset are | ||
5562 | * called once more for the slave link, so the reset sequence | ||
5563 | * looks like the following. | ||
5564 | * | ||
5565 | * prereset(M) -> prereset(S) -> hardreset(M) -> hardreset(S) -> | ||
5566 | * softreset(M) -> postreset(M) -> postreset(S) | ||
5567 | * | ||
5568 | * Note that softreset is called only for the master. Softreset | ||
5569 | * resets both M/S by definition, so SRST on master should handle | ||
5570 | * both (the standard method will work just fine). | ||
5571 | * | ||
5572 | * LOCKING: | ||
5573 | * Should be called before host is registered. | ||
5574 | * | ||
5575 | * RETURNS: | ||
5576 | * 0 on success, -errno on failure. | ||
5577 | */ | ||
5578 | int ata_slave_link_init(struct ata_port *ap) | ||
5579 | { | ||
5580 | struct ata_link *link; | ||
5581 | |||
5582 | WARN_ON(ap->slave_link); | ||
5583 | WARN_ON(ap->flags & ATA_FLAG_PMP); | ||
5584 | |||
5585 | link = kzalloc(sizeof(*link), GFP_KERNEL); | ||
5586 | if (!link) | ||
5587 | return -ENOMEM; | ||
5588 | |||
5589 | ata_link_init(ap, link, 1); | ||
5590 | ap->slave_link = link; | ||
5591 | return 0; | ||
5592 | } | ||
5593 | |||
5441 | static void ata_host_stop(struct device *gendev, void *res) | 5594 | static void ata_host_stop(struct device *gendev, void *res) |
5442 | { | 5595 | { |
5443 | struct ata_host *host = dev_get_drvdata(gendev); | 5596 | struct ata_host *host = dev_get_drvdata(gendev); |
@@ -5664,6 +5817,8 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht) | |||
5664 | 5817 | ||
5665 | /* init sata_spd_limit to the current value */ | 5818 | /* init sata_spd_limit to the current value */ |
5666 | sata_link_init_spd(&ap->link); | 5819 | sata_link_init_spd(&ap->link); |
5820 | if (ap->slave_link) | ||
5821 | sata_link_init_spd(ap->slave_link); | ||
5667 | 5822 | ||
5668 | /* print per-port info to dmesg */ | 5823 | /* print per-port info to dmesg */ |
5669 | xfer_mask = ata_pack_xfermask(ap->pio_mask, ap->mwdma_mask, | 5824 | xfer_mask = ata_pack_xfermask(ap->pio_mask, ap->mwdma_mask, |
@@ -6289,6 +6444,7 @@ EXPORT_SYMBOL_GPL(ata_std_bios_param); | |||
6289 | EXPORT_SYMBOL_GPL(ata_host_init); | 6444 | EXPORT_SYMBOL_GPL(ata_host_init); |
6290 | EXPORT_SYMBOL_GPL(ata_host_alloc); | 6445 | EXPORT_SYMBOL_GPL(ata_host_alloc); |
6291 | EXPORT_SYMBOL_GPL(ata_host_alloc_pinfo); | 6446 | EXPORT_SYMBOL_GPL(ata_host_alloc_pinfo); |
6447 | EXPORT_SYMBOL_GPL(ata_slave_link_init); | ||
6292 | EXPORT_SYMBOL_GPL(ata_host_start); | 6448 | EXPORT_SYMBOL_GPL(ata_host_start); |
6293 | EXPORT_SYMBOL_GPL(ata_host_register); | 6449 | EXPORT_SYMBOL_GPL(ata_host_register); |
6294 | EXPORT_SYMBOL_GPL(ata_host_activate); | 6450 | EXPORT_SYMBOL_GPL(ata_host_activate); |