^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Serial Attached SCSI (SAS) Discover process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2005 Adaptec, Inc. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/scatterlist.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/async.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <scsi/scsi_host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <scsi/scsi_eh.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "sas_internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <scsi/scsi_transport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <scsi/scsi_transport_sas.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <scsi/sas_ata.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include "../scsi_sas_internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) /* ---------- Basic task processing for discovery purposes ---------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) void sas_init_dev(struct domain_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) switch (dev->dev_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) case SAS_END_DEVICE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) INIT_LIST_HEAD(&dev->ssp_dev.eh_list_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) case SAS_EDGE_EXPANDER_DEVICE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) case SAS_FANOUT_EXPANDER_DEVICE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) INIT_LIST_HEAD(&dev->ex_dev.children);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) mutex_init(&dev->ex_dev.cmd_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) /* ---------- Domain device discovery ---------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * sas_get_port_device - Discover devices which caused port creation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * @port: pointer to struct sas_port of interest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * Devices directly attached to a HA port, have no parent. This is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * how we know they are (domain) "root" devices. All other devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * do, and should have their "parent" pointer set appropriately as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * soon as a child device is discovered.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) static int sas_get_port_device(struct asd_sas_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) struct asd_sas_phy *phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct sas_rphy *rphy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct domain_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) int rc = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) dev = sas_alloc_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) spin_lock_irq(&port->phy_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) if (list_empty(&port->phy_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) spin_unlock_irq(&port->phy_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) sas_put_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) phy = container_of(port->phy_list.next, struct asd_sas_phy, port_phy_el);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) spin_lock(&phy->frame_rcvd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) memcpy(dev->frame_rcvd, phy->frame_rcvd, min(sizeof(dev->frame_rcvd),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) (size_t)phy->frame_rcvd_size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) spin_unlock(&phy->frame_rcvd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) spin_unlock_irq(&port->phy_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) if (dev->frame_rcvd[0] == 0x34 && port->oob_mode == SATA_OOB_MODE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) struct dev_to_host_fis *fis =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) (struct dev_to_host_fis *) dev->frame_rcvd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) if (fis->interrupt_reason == 1 && fis->lbal == 1 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) fis->byte_count_low==0x69 && fis->byte_count_high == 0x96
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) && (fis->device & ~0x10) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) dev->dev_type = SAS_SATA_PM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) dev->dev_type = SAS_SATA_DEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) dev->tproto = SAS_PROTOCOL_SATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) } else if (port->oob_mode == SAS_OOB_MODE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct sas_identify_frame *id =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) (struct sas_identify_frame *) dev->frame_rcvd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) dev->dev_type = id->dev_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) dev->iproto = id->initiator_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) dev->tproto = id->target_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) /* If the oob mode is OOB_NOT_CONNECTED, the port is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * disconnected due to race with PHY down. We cannot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * continue to discover this port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) sas_put_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) pr_warn("Port %016llx is disconnected when discovering\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) SAS_ADDR(port->attached_sas_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) sas_init_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) dev->port = port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) switch (dev->dev_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) case SAS_SATA_DEV:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) rc = sas_ata_init(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) rphy = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) case SAS_END_DEVICE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) rphy = sas_end_device_alloc(port->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) case SAS_EDGE_EXPANDER_DEVICE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) rphy = sas_expander_alloc(port->port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) SAS_EDGE_EXPANDER_DEVICE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) case SAS_FANOUT_EXPANDER_DEVICE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) rphy = sas_expander_alloc(port->port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) SAS_FANOUT_EXPANDER_DEVICE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) pr_warn("ERROR: Unidentified device type %d\n", dev->dev_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) rphy = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) if (!rphy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) sas_put_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) rphy->identify.phy_identifier = phy->phy->identify.phy_identifier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) memcpy(dev->sas_addr, port->attached_sas_addr, SAS_ADDR_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) sas_fill_in_rphy(dev, rphy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) sas_hash_addr(dev->hashed_sas_addr, dev->sas_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) port->port_dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) dev->linkrate = port->linkrate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) dev->min_linkrate = port->linkrate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) dev->max_linkrate = port->linkrate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) dev->pathways = port->num_phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) memset(port->disc.fanout_sas_addr, 0, SAS_ADDR_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) memset(port->disc.eeds_a, 0, SAS_ADDR_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) memset(port->disc.eeds_b, 0, SAS_ADDR_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) port->disc.max_level = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) sas_device_set_phy(dev, port->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) dev->rphy = rphy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) get_device(&dev->rphy->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) if (dev_is_sata(dev) || dev->dev_type == SAS_END_DEVICE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) list_add_tail(&dev->disco_list_node, &port->disco_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) spin_lock_irq(&port->dev_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) list_add_tail(&dev->dev_list_node, &port->dev_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) spin_unlock_irq(&port->dev_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) spin_lock_irq(&port->phy_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) list_for_each_entry(phy, &port->phy_list, port_phy_el)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) sas_phy_set_target(phy, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) spin_unlock_irq(&port->phy_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) /* ---------- Discover and Revalidate ---------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) int sas_notify_lldd_dev_found(struct domain_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) int res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) struct sas_ha_struct *sas_ha = dev->port->ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) struct Scsi_Host *shost = sas_ha->core.shost;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) struct sas_internal *i = to_sas_internal(shost->transportt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) if (!i->dft->lldd_dev_found)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) res = i->dft->lldd_dev_found(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) if (res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) pr_warn("driver on host %s cannot handle device %016llx, error:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) dev_name(sas_ha->dev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) SAS_ADDR(dev->sas_addr), res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) set_bit(SAS_DEV_FOUND, &dev->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) kref_get(&dev->kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) void sas_notify_lldd_dev_gone(struct domain_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) struct sas_ha_struct *sas_ha = dev->port->ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) struct Scsi_Host *shost = sas_ha->core.shost;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) struct sas_internal *i = to_sas_internal(shost->transportt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) if (!i->dft->lldd_dev_gone)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) if (test_and_clear_bit(SAS_DEV_FOUND, &dev->state)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) i->dft->lldd_dev_gone(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) sas_put_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) static void sas_probe_devices(struct asd_sas_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) struct domain_device *dev, *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) /* devices must be domain members before link recovery and probe */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) list_for_each_entry(dev, &port->disco_list, disco_list_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) spin_lock_irq(&port->dev_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) list_add_tail(&dev->dev_list_node, &port->dev_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) spin_unlock_irq(&port->dev_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) sas_probe_sata(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) list_for_each_entry_safe(dev, n, &port->disco_list, disco_list_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) err = sas_rphy_add(dev->rphy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) sas_fail_probe(dev, __func__, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) list_del_init(&dev->disco_list_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) static void sas_suspend_devices(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) struct asd_sas_phy *phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) struct domain_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) struct sas_discovery_event *ev = to_sas_discovery_event(work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) struct asd_sas_port *port = ev->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) struct Scsi_Host *shost = port->ha->core.shost;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) struct sas_internal *si = to_sas_internal(shost->transportt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) clear_bit(DISCE_SUSPEND, &port->disc.pending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) sas_suspend_sata(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) /* lldd is free to forget the domain_device across the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) * suspension, we force the issue here to keep the reference
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) * counts aligned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) list_for_each_entry(dev, &port->dev_list, dev_list_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) sas_notify_lldd_dev_gone(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) /* we are suspending, so we know events are disabled and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) * phy_list is not being mutated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) list_for_each_entry(phy, &port->phy_list, port_phy_el) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) if (si->dft->lldd_port_deformed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) si->dft->lldd_port_deformed(phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) phy->suspended = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) port->suspended = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) static void sas_resume_devices(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) struct sas_discovery_event *ev = to_sas_discovery_event(work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) struct asd_sas_port *port = ev->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) clear_bit(DISCE_RESUME, &port->disc.pending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) sas_resume_sata(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) * sas_discover_end_dev - discover an end device (SSP, etc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) * @dev: pointer to domain device of interest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) * See comment in sas_discover_sata().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) int sas_discover_end_dev(struct domain_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) return sas_notify_lldd_dev_found(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) /* ---------- Device registration and unregistration ---------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) void sas_free_device(struct kref *kref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) struct domain_device *dev = container_of(kref, typeof(*dev), kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) put_device(&dev->rphy->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) dev->rphy = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) if (dev->parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) sas_put_device(dev->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) sas_port_put_phy(dev->phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) dev->phy = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) /* remove the phys and ports, everything else should be gone */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) if (dev_is_expander(dev->dev_type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) kfree(dev->ex_dev.ex_phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) if (dev_is_sata(dev) && dev->sata_dev.ap) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) ata_sas_tport_delete(dev->sata_dev.ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) ata_sas_port_destroy(dev->sata_dev.ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) ata_host_put(dev->sata_dev.ata_host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) dev->sata_dev.ata_host = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) dev->sata_dev.ap = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) kfree(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) static void sas_unregister_common_dev(struct asd_sas_port *port, struct domain_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) struct sas_ha_struct *ha = port->ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) sas_notify_lldd_dev_gone(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) if (!dev->parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) dev->port->port_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) list_del_init(&dev->siblings);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) spin_lock_irq(&port->dev_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) list_del_init(&dev->dev_list_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) if (dev_is_sata(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) sas_ata_end_eh(dev->sata_dev.ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) spin_unlock_irq(&port->dev_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) spin_lock_irq(&ha->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) if (dev->dev_type == SAS_END_DEVICE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) !list_empty(&dev->ssp_dev.eh_list_node)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) list_del_init(&dev->ssp_dev.eh_list_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) ha->eh_active--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) spin_unlock_irq(&ha->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) sas_put_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) void sas_destruct_devices(struct asd_sas_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) struct domain_device *dev, *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) list_for_each_entry_safe(dev, n, &port->destroy_list, disco_list_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) list_del_init(&dev->disco_list_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) sas_remove_children(&dev->rphy->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) sas_rphy_delete(dev->rphy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) sas_unregister_common_dev(port, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) static void sas_destruct_ports(struct asd_sas_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) struct sas_port *sas_port, *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) list_for_each_entry_safe(sas_port, p, &port->sas_port_del_list, del_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) list_del_init(&sas_port->del_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) sas_port_delete(sas_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) void sas_unregister_dev(struct asd_sas_port *port, struct domain_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) if (!test_bit(SAS_DEV_DESTROY, &dev->state) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) !list_empty(&dev->disco_list_node)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) /* this rphy never saw sas_rphy_add */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) list_del_init(&dev->disco_list_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) sas_rphy_free(dev->rphy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) sas_unregister_common_dev(port, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) if (!test_and_set_bit(SAS_DEV_DESTROY, &dev->state)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) sas_rphy_unlink(dev->rphy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) list_move_tail(&dev->disco_list_node, &port->destroy_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) void sas_unregister_domain_devices(struct asd_sas_port *port, int gone)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) struct domain_device *dev, *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) list_for_each_entry_safe_reverse(dev, n, &port->dev_list, dev_list_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) if (gone)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) set_bit(SAS_DEV_GONE, &dev->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) sas_unregister_dev(port, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) list_for_each_entry_safe(dev, n, &port->disco_list, disco_list_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) sas_unregister_dev(port, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) port->port->rphy = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) void sas_device_set_phy(struct domain_device *dev, struct sas_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) struct sas_ha_struct *ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) struct sas_phy *new_phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) ha = dev->port->ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) new_phy = sas_port_get_phy(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) /* pin and record last seen phy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) spin_lock_irq(&ha->phy_port_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) if (new_phy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) sas_port_put_phy(dev->phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) dev->phy = new_phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) spin_unlock_irq(&ha->phy_port_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) /* ---------- Discovery and Revalidation ---------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) * sas_discover_domain - discover the domain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) * @work: work structure embedded in port domain device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) * NOTE: this process _must_ quit (return) as soon as any connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) * errors are encountered. Connection recovery is done elsewhere.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) * Discover process only interrogates devices in order to discover the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) * domain.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) static void sas_discover_domain(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) struct domain_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) struct sas_discovery_event *ev = to_sas_discovery_event(work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) struct asd_sas_port *port = ev->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) clear_bit(DISCE_DISCOVER_DOMAIN, &port->disc.pending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) if (port->port_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) error = sas_get_port_device(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) dev = port->port_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) pr_debug("DOING DISCOVERY on port %d, pid:%d\n", port->id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) task_pid_nr(current));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) switch (dev->dev_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) case SAS_END_DEVICE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) error = sas_discover_end_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) case SAS_EDGE_EXPANDER_DEVICE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) case SAS_FANOUT_EXPANDER_DEVICE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) error = sas_discover_root_expander(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) case SAS_SATA_DEV:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) case SAS_SATA_PM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) #ifdef CONFIG_SCSI_SAS_ATA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) error = sas_discover_sata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) pr_notice("ATA device seen but CONFIG_SCSI_SAS_ATA=N so cannot attach\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) /* Fall through */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) /* Fall through - only for the #else condition above. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) error = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) pr_err("unhandled device %d\n", dev->dev_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) sas_rphy_free(dev->rphy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) list_del_init(&dev->disco_list_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) spin_lock_irq(&port->dev_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) list_del_init(&dev->dev_list_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) spin_unlock_irq(&port->dev_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) sas_put_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) port->port_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) sas_probe_devices(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) pr_debug("DONE DISCOVERY on port %d, pid:%d, result:%d\n", port->id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) task_pid_nr(current), error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) static void sas_revalidate_domain(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) int res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) struct sas_discovery_event *ev = to_sas_discovery_event(work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) struct asd_sas_port *port = ev->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) struct sas_ha_struct *ha = port->ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) struct domain_device *ddev = port->port_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) /* prevent revalidation from finding sata links in recovery */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) mutex_lock(&ha->disco_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) if (test_bit(SAS_HA_ATA_EH_ACTIVE, &ha->state)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) pr_debug("REVALIDATION DEFERRED on port %d, pid:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) port->id, task_pid_nr(current));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) clear_bit(DISCE_REVALIDATE_DOMAIN, &port->disc.pending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) pr_debug("REVALIDATING DOMAIN on port %d, pid:%d\n", port->id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) task_pid_nr(current));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) if (ddev && dev_is_expander(ddev->dev_type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) res = sas_ex_revalidate_domain(ddev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) pr_debug("done REVALIDATING DOMAIN on port %d, pid:%d, res 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) port->id, task_pid_nr(current), res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) mutex_unlock(&ha->disco_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) sas_destruct_devices(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) sas_destruct_ports(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) sas_probe_devices(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) /* ---------- Events ---------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) static void sas_chain_work(struct sas_ha_struct *ha, struct sas_work *sw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) /* chained work is not subject to SA_HA_DRAINING or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) * SAS_HA_REGISTERED, because it is either submitted in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) * workqueue, or known to be submitted from a context that is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) * not racing against draining
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) queue_work(ha->disco_q, &sw->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) static void sas_chain_event(int event, unsigned long *pending,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) struct sas_work *sw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) struct sas_ha_struct *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) if (!test_and_set_bit(event, pending)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) spin_lock_irqsave(&ha->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) sas_chain_work(ha, sw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) spin_unlock_irqrestore(&ha->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) int sas_discover_event(struct asd_sas_port *port, enum discover_event ev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) struct sas_discovery *disc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) if (!port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) disc = &port->disc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) BUG_ON(ev >= DISC_NUM_EVENTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) sas_chain_event(ev, &disc->pending, &disc->disc_work[ev].work, port->ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) * sas_init_disc - initialize the discovery struct in the port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) * @disc: port discovery structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) * @port: pointer to struct port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) * Called when the ports are being initialized.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) void sas_init_disc(struct sas_discovery *disc, struct asd_sas_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) static const work_func_t sas_event_fns[DISC_NUM_EVENTS] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) [DISCE_DISCOVER_DOMAIN] = sas_discover_domain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) [DISCE_REVALIDATE_DOMAIN] = sas_revalidate_domain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) [DISCE_SUSPEND] = sas_suspend_devices,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) [DISCE_RESUME] = sas_resume_devices,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) disc->pending = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) for (i = 0; i < DISC_NUM_EVENTS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) INIT_SAS_WORK(&disc->disc_work[i].work, sas_event_fns[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) disc->disc_work[i].port = port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) }