Lines Matching +full:- +full:phy

1 // SPDX-License-Identifier: GPL-2.0
15 static bool phy_is_wideport_member(struct asd_sas_port *port, struct asd_sas_phy *phy) in phy_is_wideport_member() argument
17 struct sas_ha_struct *sas_ha = phy->ha; in phy_is_wideport_member()
19 if (memcmp(port->attached_sas_addr, phy->attached_sas_addr, in phy_is_wideport_member()
20 SAS_ADDR_SIZE) != 0 || (sas_ha->strict_wide_ports && in phy_is_wideport_member()
21 memcmp(port->sas_addr, phy->sas_addr, SAS_ADDR_SIZE) != 0)) in phy_is_wideport_member()
26 static void sas_resume_port(struct asd_sas_phy *phy) in sas_resume_port() argument
29 struct asd_sas_port *port = phy->port; in sas_resume_port()
30 struct sas_ha_struct *sas_ha = phy->ha; in sas_resume_port()
31 struct sas_internal *si = to_sas_internal(sas_ha->core.shost->transportt); in sas_resume_port()
33 if (si->dft->lldd_port_formed) in sas_resume_port()
34 si->dft->lldd_port_formed(phy); in sas_resume_port()
36 if (port->suspended) in sas_resume_port()
37 port->suspended = 0; in sas_resume_port()
47 list_for_each_entry_safe(dev, n, &port->dev_list, dev_list_node) { in sas_resume_port()
57 if (dev_is_expander(dev->dev_type)) { in sas_resume_port()
58 dev->ex_dev.ex_change_count = -1; in sas_resume_port()
59 for (i = 0; i < dev->ex_dev.num_phys; i++) { in sas_resume_port()
60 struct ex_phy *phy = &dev->ex_dev.ex_phy[i]; in sas_resume_port() local
62 phy->phy_change_count = -1; in sas_resume_port()
71 struct asd_sas_phy *phy, bool wideport) in sas_form_port_add_phy() argument
73 list_add_tail(&phy->port_phy_el, &port->phy_list); in sas_form_port_add_phy()
74 sas_phy_set_target(phy, port->port_dev); in sas_form_port_add_phy()
75 phy->port = port; in sas_form_port_add_phy()
76 port->num_phys++; in sas_form_port_add_phy()
77 port->phy_mask |= (1U << phy->id); in sas_form_port_add_phy()
80 pr_debug("phy%d matched wide port%d\n", phy->id, in sas_form_port_add_phy()
81 port->id); in sas_form_port_add_phy()
83 memcpy(port->sas_addr, phy->sas_addr, SAS_ADDR_SIZE); in sas_form_port_add_phy()
85 if (*(u64 *)port->attached_sas_addr == 0) { in sas_form_port_add_phy()
86 port->class = phy->class; in sas_form_port_add_phy()
87 memcpy(port->attached_sas_addr, phy->attached_sas_addr, in sas_form_port_add_phy()
89 port->iproto = phy->iproto; in sas_form_port_add_phy()
90 port->tproto = phy->tproto; in sas_form_port_add_phy()
91 port->oob_mode = phy->oob_mode; in sas_form_port_add_phy()
92 port->linkrate = phy->linkrate; in sas_form_port_add_phy()
94 port->linkrate = max(port->linkrate, phy->linkrate); in sas_form_port_add_phy()
99 * sas_form_port - add this phy to a port
100 * @phy: the phy of interest
102 * This function adds this phy to an existing port, thus creating a wide
103 * port, or it creates a port and adds the phy to the port.
105 static void sas_form_port(struct asd_sas_phy *phy) in sas_form_port() argument
108 struct sas_ha_struct *sas_ha = phy->ha; in sas_form_port()
109 struct asd_sas_port *port = phy->port; in sas_form_port()
112 to_sas_internal(sas_ha->core.shost->transportt); in sas_form_port()
116 if (!phy_is_wideport_member(port, phy)) in sas_form_port()
117 sas_deform_port(phy, 0); in sas_form_port()
118 else if (phy->suspended) { in sas_form_port()
119 phy->suspended = 0; in sas_form_port()
120 sas_resume_port(phy); in sas_form_port()
122 /* phy came back, try to cancel the timeout */ in sas_form_port()
123 wake_up(&sas_ha->eh_wait_q); in sas_form_port()
126 pr_info("%s: phy%d belongs to port%d already(%d)!\n", in sas_form_port()
127 __func__, phy->id, phy->port->id, in sas_form_port()
128 phy->port->num_phys); in sas_form_port()
133 /* see if the phy should be part of a wide port */ in sas_form_port()
134 spin_lock_irqsave(&sas_ha->phy_port_lock, flags); in sas_form_port()
135 for (i = 0; i < sas_ha->num_phys; i++) { in sas_form_port()
136 port = sas_ha->sas_port[i]; in sas_form_port()
137 spin_lock(&port->phy_list_lock); in sas_form_port()
138 if (*(u64 *) port->sas_addr && in sas_form_port()
139 phy_is_wideport_member(port, phy) && port->num_phys > 0) { in sas_form_port()
141 port_dev = port->port_dev; in sas_form_port()
142 sas_form_port_add_phy(port, phy, true); in sas_form_port()
143 spin_unlock(&port->phy_list_lock); in sas_form_port()
146 spin_unlock(&port->phy_list_lock); in sas_form_port()
148 /* The phy does not match any existing port, create a new one */ in sas_form_port()
149 if (i == sas_ha->num_phys) { in sas_form_port()
150 for (i = 0; i < sas_ha->num_phys; i++) { in sas_form_port()
151 port = sas_ha->sas_port[i]; in sas_form_port()
152 spin_lock(&port->phy_list_lock); in sas_form_port()
153 if (*(u64 *)port->sas_addr == 0 in sas_form_port()
154 && port->num_phys == 0) { in sas_form_port()
155 port_dev = port->port_dev; in sas_form_port()
156 sas_form_port_add_phy(port, phy, false); in sas_form_port()
157 spin_unlock(&port->phy_list_lock); in sas_form_port()
160 spin_unlock(&port->phy_list_lock); in sas_form_port()
163 if (i >= sas_ha->num_phys) { in sas_form_port()
166 spin_unlock_irqrestore(&sas_ha->phy_port_lock, flags); in sas_form_port()
170 spin_unlock_irqrestore(&sas_ha->phy_port_lock, flags); in sas_form_port()
172 if (!port->port) { in sas_form_port()
173 port->port = sas_port_alloc(phy->phy->dev.parent, port->id); in sas_form_port()
174 BUG_ON(!port->port); in sas_form_port()
175 sas_port_add(port->port); in sas_form_port()
177 sas_port_add_phy(port->port, phy->phy); in sas_form_port()
180 dev_name(&phy->phy->dev), dev_name(&port->port->dev), in sas_form_port()
181 port->phy_mask, in sas_form_port()
182 SAS_ADDR(port->attached_sas_addr)); in sas_form_port()
185 port_dev->pathways = port->num_phys; in sas_form_port()
188 if (si->dft->lldd_port_formed) in sas_form_port()
189 si->dft->lldd_port_formed(phy); in sas_form_port()
191 sas_discover_event(phy->port, DISCE_DISCOVER_DOMAIN); in sas_form_port()
193 if (port_dev && dev_is_expander(port_dev->dev_type)) { in sas_form_port()
194 struct expander_device *ex_dev = &port_dev->ex_dev; in sas_form_port()
196 ex_dev->ex_change_count = -1; in sas_form_port()
199 flush_workqueue(sas_ha->disco_q); in sas_form_port()
203 * sas_deform_port - remove this phy from the port it belongs to
204 * @phy: the phy of interest
205 * @gone: whether or not the PHY is gone
207 * This is called when the physical link to the other phy has been
208 * lost (on this phy), in Event thread context. We cannot delay here.
210 void sas_deform_port(struct asd_sas_phy *phy, int gone) in sas_deform_port() argument
212 struct sas_ha_struct *sas_ha = phy->ha; in sas_deform_port()
213 struct asd_sas_port *port = phy->port; in sas_deform_port()
215 to_sas_internal(sas_ha->core.shost->transportt); in sas_deform_port()
220 return; /* done by a phy event */ in sas_deform_port()
222 dev = port->port_dev; in sas_deform_port()
224 dev->pathways--; in sas_deform_port()
226 if (port->num_phys == 1) { in sas_deform_port()
229 sas_port_delete(port->port); in sas_deform_port()
230 port->port = NULL; in sas_deform_port()
232 sas_port_delete_phy(port->port, phy->phy); in sas_deform_port()
233 sas_device_set_phy(dev, port->port); in sas_deform_port()
236 if (si->dft->lldd_port_deformed) in sas_deform_port()
237 si->dft->lldd_port_deformed(phy); in sas_deform_port()
239 spin_lock_irqsave(&sas_ha->phy_port_lock, flags); in sas_deform_port()
240 spin_lock(&port->phy_list_lock); in sas_deform_port()
242 list_del_init(&phy->port_phy_el); in sas_deform_port()
243 sas_phy_set_target(phy, NULL); in sas_deform_port()
244 phy->port = NULL; in sas_deform_port()
245 port->num_phys--; in sas_deform_port()
246 port->phy_mask &= ~(1U << phy->id); in sas_deform_port()
248 if (port->num_phys == 0) { in sas_deform_port()
249 INIT_LIST_HEAD(&port->phy_list); in sas_deform_port()
250 memset(port->sas_addr, 0, SAS_ADDR_SIZE); in sas_deform_port()
251 memset(port->attached_sas_addr, 0, SAS_ADDR_SIZE); in sas_deform_port()
252 port->class = 0; in sas_deform_port()
253 port->iproto = 0; in sas_deform_port()
254 port->tproto = 0; in sas_deform_port()
255 port->oob_mode = 0; in sas_deform_port()
256 port->phy_mask = 0; in sas_deform_port()
258 spin_unlock(&port->phy_list_lock); in sas_deform_port()
259 spin_unlock_irqrestore(&sas_ha->phy_port_lock, flags); in sas_deform_port()
262 if (port->port && dev && dev_is_expander(dev->dev_type)) { in sas_deform_port()
263 struct expander_device *ex_dev = &dev->ex_dev; in sas_deform_port()
265 ex_dev->ex_change_count = -1; in sas_deform_port()
268 flush_workqueue(sas_ha->disco_q); in sas_deform_port()
273 /* ---------- SAS port events ---------- */
278 struct asd_sas_phy *phy = ev->phy; in sas_porte_bytes_dmaed() local
280 sas_form_port(phy); in sas_porte_bytes_dmaed()
286 struct asd_sas_phy *phy = ev->phy; in sas_porte_broadcast_rcvd() local
290 spin_lock_irqsave(&phy->sas_prim_lock, flags); in sas_porte_broadcast_rcvd()
291 prim = phy->sas_prim; in sas_porte_broadcast_rcvd()
292 spin_unlock_irqrestore(&phy->sas_prim_lock, flags); in sas_porte_broadcast_rcvd()
295 sas_discover_event(phy->port, DISCE_REVALIDATE_DOMAIN); in sas_porte_broadcast_rcvd()
297 if (phy->port) in sas_porte_broadcast_rcvd()
298 flush_workqueue(phy->port->ha->disco_q); in sas_porte_broadcast_rcvd()
304 struct asd_sas_phy *phy = ev->phy; in sas_porte_link_reset_err() local
306 sas_deform_port(phy, 1); in sas_porte_link_reset_err()
312 struct asd_sas_phy *phy = ev->phy; in sas_porte_timer_event() local
314 sas_deform_port(phy, 1); in sas_porte_timer_event()
320 struct asd_sas_phy *phy = ev->phy; in sas_porte_hard_reset() local
322 sas_deform_port(phy, 1); in sas_porte_hard_reset()
325 /* ---------- SAS port registration ---------- */
331 port->id = i; in sas_init_port()
332 INIT_LIST_HEAD(&port->dev_list); in sas_init_port()
333 INIT_LIST_HEAD(&port->disco_list); in sas_init_port()
334 INIT_LIST_HEAD(&port->destroy_list); in sas_init_port()
335 INIT_LIST_HEAD(&port->sas_port_del_list); in sas_init_port()
336 spin_lock_init(&port->phy_list_lock); in sas_init_port()
337 INIT_LIST_HEAD(&port->phy_list); in sas_init_port()
338 port->ha = sas_ha; in sas_init_port()
340 spin_lock_init(&port->dev_list_lock); in sas_init_port()
348 for (i = 0; i < sas_ha->num_phys; i++) { in sas_register_ports()
349 struct asd_sas_port *port = sas_ha->sas_port[i]; in sas_register_ports()
352 sas_init_disc(&port->disc, port); in sas_register_ports()
361 for (i = 0; i < sas_ha->num_phys; i++) in sas_unregister_ports()
362 if (sas_ha->sas_phy[i]->port) in sas_unregister_ports()
363 sas_deform_port(sas_ha->sas_phy[i], 0); in sas_unregister_ports()