Lines Matching defs:link

114 MODULE_PARM_DESC(force, "Force ATA configurations including cable type, link speed and transfer mode (see Documentation/admin-guide/kernel-parameters.rst for details)");
169 * ata_link_next - link iteration helper
170 * @link: the previous link, NULL to start
178 * Pointer to the next link.
180 struct ata_link *ata_link_next(struct ata_link *link, struct ata_port *ap,
186 /* NULL link indicates start of iteration */
187 if (!link)
195 return &ap->link;
198 /* we just iterated over the host link, what's next? */
199 if (link == &ap->link)
214 if (unlikely(link == ap->slave_link))
217 /* we were over a PMP link */
218 if (++link < ap->pmp_link + ap->nr_pmp_links)
219 return link;
222 return &ap->link;
231 * @link: ATA link containing devices to iterate
240 struct ata_device *ata_dev_next(struct ata_device *dev, struct ata_link *link,
251 dev = link->device;
255 dev = link->device + ata_link_max_devices(link) - 1;
264 if (++dev < link->device + ata_link_max_devices(link))
269 if (--dev >= link->device)
283 * ata_dev_phys_link - find physical link for a device
284 * @dev: ATA device to look up physical link for
286 * Look up physical link which @dev is attached to. Note that
287 * this is different from @dev->link only when @dev is on slave
288 * link. For all other cases, it's the same as @dev->link.
294 * Pointer to the found physical link.
298 struct ata_port *ap = dev->link->ap;
301 return dev->link;
303 return &ap->link;
341 * ata_force_link_limits - force link limits according to libata.force
342 * @link: ATA link of interest
344 * Force link flags and SATA spd limit according to libata.force
347 * the host link and all fan-out ports connected via PMP. If the
349 * first fan-out link not the host link. Device number 15 always
350 * points to the host link whether PMP is attached or not. If the
351 * controller has slave link, device number 16 points to it.
356 static void ata_force_link_limits(struct ata_link *link)
359 int linkno = link->pmp;
362 if (ata_is_host_link(link))
368 if (fe->port != -1 && fe->port != link->ap->print_id)
376 link->hw_sata_spd_limit = (1 << fe->param.spd_limit) - 1;
377 ata_link_notice(link, "FORCE: PHY spd limit set to %s\n",
384 link->flags |= fe->param.lflags;
385 ata_link_notice(link,
386 "FORCE: link flag 0x%x forced -> 0x%x\n",
387 fe->param.lflags, link->flags);
397 * For consistency with link selection, device number 15 selects
398 * the first device connected to the host link.
405 int devno = dev->link->pmp + dev->devno;
410 if (ata_is_host_link(dev->link))
417 if (fe->port != -1 && fe->port != dev->link->ap->print_id)
451 * For consistency with link selection, device number 15 selects
452 * the first device connected to the host link.
459 int devno = dev->link->pmp + dev->devno;
464 if (ata_is_host_link(dev->link))
470 if (fe->port != -1 && fe->port != dev->link->ap->print_id)
489 static inline void ata_force_link_limits(struct ata_link *link) { }
587 } else if (lba48 && (dev->link->ap->flags & ATA_FLAG_PIO_LBA48)) {
1269 struct ata_eh_context *ehc = &dev->link->eh_context;
1496 struct ata_link *link = dev->link;
1497 struct ata_port *ap = link->ap;
1528 preempted_tag = link->active_tag;
1529 preempted_sactive = link->sactive;
1532 link->active_tag = ATA_TAG_POISON;
1533 link->sactive = 0;
1635 link->active_tag = preempted_tag;
1636 link->sactive = preempted_sactive;
1699 if (adev->link->ap->pflags & ATA_PFLAG_RESETTING)
1704 if (adev->link->ap->flags & ATA_FLAG_NO_IORDY)
1785 struct ata_port *ap = dev->link->ap;
1991 unsigned long ap_flags = dev->link->ap->flags;
2038 struct ata_port *ap = dev->link->ap;
2047 struct ata_port *ap = dev->link->ap;
2097 /* Request another EH round by returning -EAGAIN if link is
2102 ata_dev_info(dev, "applying link speed limit horkage to %s\n",
2111 struct ata_port *ap = dev->link->ap;
2121 struct ata_port *ap = dev->link->ap;
2150 struct ata_port *ap = dev->link->ap;
2173 struct ata_port *ap = dev->link->ap;
2224 struct ata_port *ap = dev->link->ap;
2306 struct ata_port *ap = dev->link->ap;
2360 struct ata_port *ap = dev->link->ap;
2407 struct ata_port *ap = dev->link->ap;
2408 struct ata_eh_context *ehc = &dev->link->eh_context;
2459 dev->link->ap->target_lpm_policy = ATA_LPM_MAX_POWER;
2647 sata_scr_read(&ap->link, SCR_NOTIFICATION, &sntf) == 0)) {
2837 ata_for_each_dev(dev, &ap->link, ALL)
2841 ata_for_each_dev(dev, &ap->link, ALL) {
2864 ata_for_each_dev(dev, &ap->link, ALL) {
2877 ata_for_each_dev(dev, &ap->link, ALL_REVERSE) {
2897 * of the link the bridge is which is a problem.
2899 ata_for_each_dev(dev, &ap->link, ENABLED)
2906 ata_for_each_dev(dev, &ap->link, ENABLED) {
2907 ap->link.eh_context.i.flags |= ATA_EHI_PRINTINFO;
2909 ap->link.eh_context.i.flags &= ~ATA_EHI_PRINTINFO;
2915 rc = ata_set_mode(&ap->link, &dev);
2919 ata_for_each_dev(dev, &ap->link, ENABLED)
2942 sata_down_spd_limit(&ap->link, 0);
2954 * sata_print_link_status - Print SATA link status
2955 * @link: SATA link to printk link status about
2957 * This function prints link speed and status of a SATA link.
2962 static void sata_print_link_status(struct ata_link *link)
2966 if (sata_scr_read(link, SCR_STATUS, &sstatus))
2968 sata_scr_read(link, SCR_CONTROL, &scontrol);
2970 if (ata_phys_link_online(link)) {
2972 ata_link_info(link, "SATA link up %s (SStatus %X SControl %X)\n",
2975 ata_link_info(link, "SATA link down (SStatus %X SControl %X)\n",
2990 struct ata_link *link = adev->link;
2991 struct ata_device *pair = &link->device[1 - adev->devno];
3000 * @link: Link to adjust SATA spd limit for
3003 * Adjust SATA spd limit of @link downward. Note that this
3018 int sata_down_spd_limit(struct ata_link *link, u32 spd_limit)
3023 if (!sata_scr_valid(link))
3027 * If not, use cached value in link->sata_spd.
3029 rc = sata_scr_read(link, SCR_STATUS, &sstatus);
3033 spd = link->sata_spd;
3035 mask = link->sata_spd_limit;
3046 * recorded the link speed from SStatus, the driver has already
3048 * Otherwise, we should not force 1.5Gbps on a link where we have
3054 else if (link->sata_spd)
3070 link->sata_spd_limit = mask;
3072 ata_link_warn(link, "limiting SATA link speed to %s\n",
3222 struct ata_port *ap = dev->link->ap;
3223 struct ata_eh_context *ehc = &dev->link->eh_context;
3305 * @link: link on which timings will be programmed
3320 int ata_do_set_mode(struct ata_link *link, struct ata_device **r_failed_dev)
3322 struct ata_port *ap = link->ap;
3327 ata_for_each_dev(dev, link, ENABLED) {
3359 ata_for_each_dev(dev, link, ENABLED) {
3373 ata_for_each_dev(dev, link, ENABLED) {
3384 ata_for_each_dev(dev, link, ENABLED) {
3404 * ata_wait_ready - wait for link to become ready
3405 * @link: link to be waited on
3407 * @check_ready: callback to check link readiness
3409 * Wait for @link to become ready. @check_ready should return
3410 * positive number if @link is ready, 0 if it isn't, -ENODEV if
3411 * link doesn't seem to be occupied, other errno for other error
3421 * 0 if @link is ready before @deadline; otherwise, -errno.
3423 int ata_wait_ready(struct ata_link *link, unsigned long deadline,
3424 int (*check_ready)(struct ata_link *link))
3431 if (link->ap->host->flags & ATA_HOST_PARALLEL_SCAN)
3440 WARN_ON(link == link->ap->slave_link);
3449 ready = tmp = check_ready(link);
3454 * -ENODEV could be transient. Ignore -ENODEV if link
3457 * ATA_TMOUT_FF_WAIT[_LONG] on -ENODEV if link isn't
3465 if (ata_link_online(link))
3467 else if ((link->ap->flags & ATA_FLAG_SATA) &&
3468 !ata_link_offline(link) &&
3480 ata_link_warn(link,
3481 "link is slow to respond, please be patient "
3486 ata_msleep(link->ap, 50);
3491 * ata_wait_after_reset - wait for link to become ready after reset
3492 * @link: link to be waited on
3494 * @check_ready: callback to check link readiness
3496 * Wait for @link to become ready after reset.
3502 * 0 if @link is ready before @deadline; otherwise, -errno.
3504 int ata_wait_after_reset(struct ata_link *link, unsigned long deadline,
3505 int (*check_ready)(struct ata_link *link))
3507 ata_msleep(link->ap, ATA_WAIT_AFTER_RESET);
3509 return ata_wait_ready(link, deadline, check_ready);
3515 * @link: ATA link to be reset
3518 * @link is about to be reset. Initialize it. Failure from
3530 int ata_std_prereset(struct ata_link *link, unsigned long deadline)
3532 struct ata_port *ap = link->ap;
3533 struct ata_eh_context *ehc = &link->eh_context;
3541 /* if SATA, resume link */
3543 rc = sata_link_resume(link, timing, deadline);
3546 ata_link_warn(link,
3547 "failed to resume link for reset (errno=%d)\n",
3551 /* no point in trying softreset on offline link */
3552 if (ata_phys_link_offline(link))
3561 * @link: link to reset
3571 * 0 if link offline, -EAGAIN if link online, -errno on errors.
3573 int sata_std_hardreset(struct ata_link *link, unsigned int *class,
3576 const unsigned long *timing = sata_ehc_deb_timing(&link->eh_context);
3581 rc = sata_link_hardreset(link, timing, deadline, &online, NULL);
3588 * @link: the target ata_link
3598 void ata_std_postreset(struct ata_link *link, unsigned int *classes)
3605 if (!sata_scr_read(link, SCR_ERROR, &serror))
3606 sata_scr_write(link, SCR_ERROR, serror);
3608 /* print link status */
3609 sata_print_link_status(link);
3681 u16 *id = (void *)dev->link->ap->sector_buf;
3925 /* Devices which aren't very happy with higher link speeds */
4029 * Some WD SATA-I drives spin up and down erratically when the link
4076 if ((dev->link->ap->flags & ATA_FLAG_PIO_POLLING) &&
4112 struct ata_link *link;
4139 ata_for_each_link(link, ap, EDGE) {
4140 ata_for_each_dev(dev, link, ENABLED) {
4162 struct ata_link *link = dev->link;
4163 struct ata_port *ap = link->ap;
4404 struct ata_link *link = qc->dev->link;
4407 if (!ata_tag_valid(link->active_tag))
4410 if (!ata_tag_valid(link->active_tag) && !link->sactive)
4545 struct ata_port *ap = dev->link->ap;
4600 struct ata_link *link;
4605 link = qc->dev->link;
4612 link->sactive &= ~(1 << qc->hw_tag);
4613 if (!link->sactive)
4616 link->active_tag = ATA_TAG_POISON;
4622 ap->excl_link == link))
4694 struct ata_eh_info *ehi = &dev->link->eh_info;
4807 struct ata_link *link = qc->dev->link;
4814 WARN_ON_ONCE(ap->ops->error_handler && ata_tag_valid(link->active_tag));
4817 WARN_ON_ONCE(link->sactive & (1 << qc->hw_tag));
4819 if (!link->sactive)
4821 link->sactive |= 1 << qc->hw_tag;
4823 WARN_ON_ONCE(link->sactive);
4826 link->active_tag = qc->tag;
4844 /* if device is sleeping, schedule reset and abort the link */
4846 link->eh_info.action |= ATA_EH_RESET;
4847 ata_ehi_push_desc(&link->eh_info, "waking up from sleep");
4848 ata_link_abort(link);
4868 * ata_phys_link_online - test whether the given link is online
4869 * @link: ATA link to test
4871 * Test whether @link is online. Note that this function returns
4872 * 0 if online status of @link cannot be obtained, so
4873 * ata_link_online(link) != !ata_link_offline(link).
4881 bool ata_phys_link_online(struct ata_link *link)
4885 if (sata_scr_read(link, SCR_STATUS, &sstatus) == 0 &&
4892 * ata_phys_link_offline - test whether the given link is offline
4893 * @link: ATA link to test
4895 * Test whether @link is offline. Note that this function
4896 * returns 0 if offline status of @link cannot be obtained, so
4897 * ata_link_online(link) != !ata_link_offline(link).
4905 bool ata_phys_link_offline(struct ata_link *link)
4909 if (sata_scr_read(link, SCR_STATUS, &sstatus) == 0 &&
4916 * ata_link_online - test whether the given link is online
4917 * @link: ATA link to test
4919 * Test whether @link is online. This is identical to
4920 * ata_phys_link_online() when there's no slave link. When
4921 * there's a slave link, this function should only be called on
4922 * the master link and will return true if any of M/S links is
4931 bool ata_link_online(struct ata_link *link)
4933 struct ata_link *slave = link->ap->slave_link;
4935 WARN_ON(link == slave); /* shouldn't be called on slave link */
4937 return ata_phys_link_online(link) ||
4943 * ata_link_offline - test whether the given link is offline
4944 * @link: ATA link to test
4946 * Test whether @link is offline. This is identical to
4947 * ata_phys_link_offline() when there's no slave link. When
4948 * there's a slave link, this function should only be called on
4949 * the master link and will return true if both M/S links are
4958 bool ata_link_offline(struct ata_link *link)
4960 struct ata_link *slave = link->ap->slave_link;
4962 WARN_ON(link == slave); /* shouldn't be called on slave link */
4964 return ata_phys_link_offline(link) &&
4974 struct ata_link *link;
4992 ata_for_each_link(link, ap, HOST_FIRST) {
4993 link->eh_info.action |= action;
4994 link->eh_info.flags |= ehi_flags;
5087 struct ata_link *link;
5090 ata_for_each_link(link, ap, HOST_FIRST) {
5091 ata_for_each_dev(adev, link, ENABLED)
5187 struct ata_link *link = ata_dev_phys_link(dev);
5188 struct ata_port *ap = link->ap;
5192 link->sata_spd_limit = link->hw_sata_spd_limit;
5193 link->sata_spd = 0;
5213 * @ap: ATA port link is attached to
5214 * @link: Link structure to initialize
5217 * Initialize @link.
5222 void ata_link_init(struct ata_port *ap, struct ata_link *link, int pmp)
5227 memset((void *)link + ATA_LINK_CLEAR_BEGIN, 0,
5230 link->ap = ap;
5231 link->pmp = pmp;
5232 link->active_tag = ATA_TAG_POISON;
5233 link->hw_sata_spd_limit = UINT_MAX;
5237 struct ata_device *dev = &link->device[i];
5239 dev->link = link;
5240 dev->devno = dev - link->device;
5249 * sata_link_init_spd - Initialize link->sata_spd_limit
5250 * @link: Link to configure sata_spd_limit for
5252 * Initialize ``link->[hw_]sata_spd_limit`` to the currently
5261 int sata_link_init_spd(struct ata_link *link)
5266 rc = sata_scr_read(link, SCR_CONTROL, &link->saved_scontrol);
5270 spd = (link->saved_scontrol >> 4) & 0xf;
5272 link->hw_sata_spd_limit &= (1 << spd) - 1;
5274 ata_force_link_limits(link);
5276 link->sata_spd_limit = link->hw_sata_spd_limit;
5330 ata_link_init(ap, &ap->link, 0);
5503 ap->link.flags |= pi->link_flags;
5684 struct ata_eh_info *ehi = &ap->link.eh_info;
5803 sata_link_init_spd(&ap->link);
5815 ap->link.eh_info.desc);
5816 ata_ehi_clear_desc(&ap->link.eh_info);
5915 struct ata_link *link;
5928 ata_for_each_link(link, ap, HOST_FIRST) {
5929 ata_for_each_dev(dev, link, ALL) {
5956 ata_for_each_link(link, ap, HOST_FIRST) {
5957 ata_for_each_dev(dev, link, ALL) {
6255 *reason = "invalid port/link";
6517 void ata_link_printk(const struct ata_link *link, const char *level,
6528 if (sata_pmp_attached(link->ap) || link->ap->slave_link)
6530 level, link->ap->print_id, link->pmp, &vaf);
6533 level, link->ap->print_id, &vaf);
6551 level, dev->link->ap->print_id, dev->link->pmp + dev->devno,