Loading...
1/*
2 * Serial Attached SCSI (SAS) Port class
3 *
4 * Copyright (C) 2005 Adaptec, Inc. All rights reserved.
5 * Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com>
6 *
7 * This file is licensed under GPLv2.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of the
12 * License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 *
23 */
24
25#include "sas_internal.h"
26
27#include <scsi/scsi_transport.h>
28#include <scsi/scsi_transport_sas.h>
29#include "../scsi_sas_internal.h"
30
31static bool phy_is_wideport_member(struct asd_sas_port *port, struct asd_sas_phy *phy)
32{
33 struct sas_ha_struct *sas_ha = phy->ha;
34
35 if (memcmp(port->attached_sas_addr, phy->attached_sas_addr,
36 SAS_ADDR_SIZE) != 0 || (sas_ha->strict_wide_ports &&
37 memcmp(port->sas_addr, phy->sas_addr, SAS_ADDR_SIZE) != 0))
38 return false;
39 return true;
40}
41
42static void sas_resume_port(struct asd_sas_phy *phy)
43{
44 struct domain_device *dev;
45 struct asd_sas_port *port = phy->port;
46 struct sas_ha_struct *sas_ha = phy->ha;
47 struct sas_internal *si = to_sas_internal(sas_ha->core.shost->transportt);
48
49 if (si->dft->lldd_port_formed)
50 si->dft->lldd_port_formed(phy);
51
52 if (port->suspended)
53 port->suspended = 0;
54 else {
55 /* we only need to handle "link returned" actions once */
56 return;
57 }
58
59 /* if the port came back:
60 * 1/ presume every device came back
61 * 2/ force the next revalidation to check all expander phys
62 */
63 list_for_each_entry(dev, &port->dev_list, dev_list_node) {
64 int i, rc;
65
66 rc = sas_notify_lldd_dev_found(dev);
67 if (rc) {
68 sas_unregister_dev(port, dev);
69 sas_destruct_devices(port);
70 continue;
71 }
72
73 if (dev->dev_type == SAS_EDGE_EXPANDER_DEVICE || dev->dev_type == SAS_FANOUT_EXPANDER_DEVICE) {
74 dev->ex_dev.ex_change_count = -1;
75 for (i = 0; i < dev->ex_dev.num_phys; i++) {
76 struct ex_phy *phy = &dev->ex_dev.ex_phy[i];
77
78 phy->phy_change_count = -1;
79 }
80 }
81 }
82
83 sas_discover_event(port, DISCE_RESUME);
84}
85
86/**
87 * sas_form_port - add this phy to a port
88 * @phy: the phy of interest
89 *
90 * This function adds this phy to an existing port, thus creating a wide
91 * port, or it creates a port and adds the phy to the port.
92 */
93static void sas_form_port(struct asd_sas_phy *phy)
94{
95 int i;
96 struct sas_ha_struct *sas_ha = phy->ha;
97 struct asd_sas_port *port = phy->port;
98 struct sas_internal *si =
99 to_sas_internal(sas_ha->core.shost->transportt);
100 unsigned long flags;
101
102 if (port) {
103 if (!phy_is_wideport_member(port, phy))
104 sas_deform_port(phy, 0);
105 else if (phy->suspended) {
106 phy->suspended = 0;
107 sas_resume_port(phy);
108
109 /* phy came back, try to cancel the timeout */
110 wake_up(&sas_ha->eh_wait_q);
111 return;
112 } else {
113 SAS_DPRINTK("%s: phy%d belongs to port%d already(%d)!\n",
114 __func__, phy->id, phy->port->id,
115 phy->port->num_phys);
116 return;
117 }
118 }
119
120 /* see if the phy should be part of a wide port */
121 spin_lock_irqsave(&sas_ha->phy_port_lock, flags);
122 for (i = 0; i < sas_ha->num_phys; i++) {
123 port = sas_ha->sas_port[i];
124 spin_lock(&port->phy_list_lock);
125 if (*(u64 *) port->sas_addr &&
126 phy_is_wideport_member(port, phy) && port->num_phys > 0) {
127 /* wide port */
128 SAS_DPRINTK("phy%d matched wide port%d\n", phy->id,
129 port->id);
130 break;
131 }
132 spin_unlock(&port->phy_list_lock);
133 }
134 /* The phy does not match any existing port, create a new one */
135 if (i == sas_ha->num_phys) {
136 for (i = 0; i < sas_ha->num_phys; i++) {
137 port = sas_ha->sas_port[i];
138 spin_lock(&port->phy_list_lock);
139 if (*(u64 *)port->sas_addr == 0
140 && port->num_phys == 0) {
141 memcpy(port->sas_addr, phy->sas_addr,
142 SAS_ADDR_SIZE);
143 break;
144 }
145 spin_unlock(&port->phy_list_lock);
146 }
147 }
148
149 if (i >= sas_ha->num_phys) {
150 printk(KERN_NOTICE "%s: couldn't find a free port, bug?\n",
151 __func__);
152 spin_unlock_irqrestore(&sas_ha->phy_port_lock, flags);
153 return;
154 }
155
156 /* add the phy to the port */
157 list_add_tail(&phy->port_phy_el, &port->phy_list);
158 sas_phy_set_target(phy, port->port_dev);
159 phy->port = port;
160 port->num_phys++;
161 port->phy_mask |= (1U << phy->id);
162
163 if (*(u64 *)port->attached_sas_addr == 0) {
164 port->class = phy->class;
165 memcpy(port->attached_sas_addr, phy->attached_sas_addr,
166 SAS_ADDR_SIZE);
167 port->iproto = phy->iproto;
168 port->tproto = phy->tproto;
169 port->oob_mode = phy->oob_mode;
170 port->linkrate = phy->linkrate;
171 } else
172 port->linkrate = max(port->linkrate, phy->linkrate);
173 spin_unlock(&port->phy_list_lock);
174 spin_unlock_irqrestore(&sas_ha->phy_port_lock, flags);
175
176 if (!port->port) {
177 port->port = sas_port_alloc(phy->phy->dev.parent, port->id);
178 BUG_ON(!port->port);
179 sas_port_add(port->port);
180 }
181 sas_port_add_phy(port->port, phy->phy);
182
183 SAS_DPRINTK("%s added to %s, phy_mask:0x%x (%16llx)\n",
184 dev_name(&phy->phy->dev), dev_name(&port->port->dev),
185 port->phy_mask,
186 SAS_ADDR(port->attached_sas_addr));
187
188 if (port->port_dev)
189 port->port_dev->pathways = port->num_phys;
190
191 /* Tell the LLDD about this port formation. */
192 if (si->dft->lldd_port_formed)
193 si->dft->lldd_port_formed(phy);
194
195 sas_discover_event(phy->port, DISCE_DISCOVER_DOMAIN);
196 flush_workqueue(sas_ha->disco_q);
197}
198
199/**
200 * sas_deform_port - remove this phy from the port it belongs to
201 * @phy: the phy of interest
202 * @gone: whether or not the PHY is gone
203 *
204 * This is called when the physical link to the other phy has been
205 * lost (on this phy), in Event thread context. We cannot delay here.
206 */
207void sas_deform_port(struct asd_sas_phy *phy, int gone)
208{
209 struct sas_ha_struct *sas_ha = phy->ha;
210 struct asd_sas_port *port = phy->port;
211 struct sas_internal *si =
212 to_sas_internal(sas_ha->core.shost->transportt);
213 struct domain_device *dev;
214 unsigned long flags;
215
216 if (!port)
217 return; /* done by a phy event */
218
219 dev = port->port_dev;
220 if (dev)
221 dev->pathways--;
222
223 if (port->num_phys == 1) {
224 sas_unregister_domain_devices(port, gone);
225 sas_destruct_devices(port);
226 sas_port_delete(port->port);
227 port->port = NULL;
228 } else {
229 sas_port_delete_phy(port->port, phy->phy);
230 sas_device_set_phy(dev, port->port);
231 }
232
233 if (si->dft->lldd_port_deformed)
234 si->dft->lldd_port_deformed(phy);
235
236 spin_lock_irqsave(&sas_ha->phy_port_lock, flags);
237 spin_lock(&port->phy_list_lock);
238
239 list_del_init(&phy->port_phy_el);
240 sas_phy_set_target(phy, NULL);
241 phy->port = NULL;
242 port->num_phys--;
243 port->phy_mask &= ~(1U << phy->id);
244
245 if (port->num_phys == 0) {
246 INIT_LIST_HEAD(&port->phy_list);
247 memset(port->sas_addr, 0, SAS_ADDR_SIZE);
248 memset(port->attached_sas_addr, 0, SAS_ADDR_SIZE);
249 port->class = 0;
250 port->iproto = 0;
251 port->tproto = 0;
252 port->oob_mode = 0;
253 port->phy_mask = 0;
254 }
255 spin_unlock(&port->phy_list_lock);
256 spin_unlock_irqrestore(&sas_ha->phy_port_lock, flags);
257
258 return;
259}
260
261/* ---------- SAS port events ---------- */
262
263void sas_porte_bytes_dmaed(struct work_struct *work)
264{
265 struct asd_sas_event *ev = to_asd_sas_event(work);
266 struct asd_sas_phy *phy = ev->phy;
267
268 sas_form_port(phy);
269}
270
271void sas_porte_broadcast_rcvd(struct work_struct *work)
272{
273 struct asd_sas_event *ev = to_asd_sas_event(work);
274 struct asd_sas_phy *phy = ev->phy;
275 unsigned long flags;
276 u32 prim;
277
278 spin_lock_irqsave(&phy->sas_prim_lock, flags);
279 prim = phy->sas_prim;
280 spin_unlock_irqrestore(&phy->sas_prim_lock, flags);
281
282 SAS_DPRINTK("broadcast received: %d\n", prim);
283 sas_discover_event(phy->port, DISCE_REVALIDATE_DOMAIN);
284
285 if (phy->port)
286 flush_workqueue(phy->port->ha->disco_q);
287}
288
289void sas_porte_link_reset_err(struct work_struct *work)
290{
291 struct asd_sas_event *ev = to_asd_sas_event(work);
292 struct asd_sas_phy *phy = ev->phy;
293
294 sas_deform_port(phy, 1);
295}
296
297void sas_porte_timer_event(struct work_struct *work)
298{
299 struct asd_sas_event *ev = to_asd_sas_event(work);
300 struct asd_sas_phy *phy = ev->phy;
301
302 sas_deform_port(phy, 1);
303}
304
305void sas_porte_hard_reset(struct work_struct *work)
306{
307 struct asd_sas_event *ev = to_asd_sas_event(work);
308 struct asd_sas_phy *phy = ev->phy;
309
310 sas_deform_port(phy, 1);
311}
312
313/* ---------- SAS port registration ---------- */
314
315static void sas_init_port(struct asd_sas_port *port,
316 struct sas_ha_struct *sas_ha, int i)
317{
318 memset(port, 0, sizeof(*port));
319 port->id = i;
320 INIT_LIST_HEAD(&port->dev_list);
321 INIT_LIST_HEAD(&port->disco_list);
322 INIT_LIST_HEAD(&port->destroy_list);
323 INIT_LIST_HEAD(&port->sas_port_del_list);
324 spin_lock_init(&port->phy_list_lock);
325 INIT_LIST_HEAD(&port->phy_list);
326 port->ha = sas_ha;
327
328 spin_lock_init(&port->dev_list_lock);
329}
330
331int sas_register_ports(struct sas_ha_struct *sas_ha)
332{
333 int i;
334
335 /* initialize the ports and discovery */
336 for (i = 0; i < sas_ha->num_phys; i++) {
337 struct asd_sas_port *port = sas_ha->sas_port[i];
338
339 sas_init_port(port, sas_ha, i);
340 sas_init_disc(&port->disc, port);
341 }
342 return 0;
343}
344
345void sas_unregister_ports(struct sas_ha_struct *sas_ha)
346{
347 int i;
348
349 for (i = 0; i < sas_ha->num_phys; i++)
350 if (sas_ha->sas_phy[i]->port)
351 sas_deform_port(sas_ha->sas_phy[i], 0);
352
353}
354
355const work_func_t sas_port_event_fns[PORT_NUM_EVENTS] = {
356 [PORTE_BYTES_DMAED] = sas_porte_bytes_dmaed,
357 [PORTE_BROADCAST_RCVD] = sas_porte_broadcast_rcvd,
358 [PORTE_LINK_RESET_ERR] = sas_porte_link_reset_err,
359 [PORTE_TIMER_EVENT] = sas_porte_timer_event,
360 [PORTE_HARD_RESET] = sas_porte_hard_reset,
361};
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Serial Attached SCSI (SAS) Port class
4 *
5 * Copyright (C) 2005 Adaptec, Inc. All rights reserved.
6 * Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com>
7 */
8
9#include "sas_internal.h"
10
11#include <scsi/scsi_transport.h>
12#include <scsi/scsi_transport_sas.h>
13#include "scsi_sas_internal.h"
14
15static bool phy_is_wideport_member(struct asd_sas_port *port, struct asd_sas_phy *phy)
16{
17 struct sas_ha_struct *sas_ha = phy->ha;
18
19 if (memcmp(port->attached_sas_addr, phy->attached_sas_addr,
20 SAS_ADDR_SIZE) != 0 || (sas_ha->strict_wide_ports &&
21 memcmp(port->sas_addr, phy->sas_addr, SAS_ADDR_SIZE) != 0))
22 return false;
23 return true;
24}
25
26static void sas_resume_port(struct asd_sas_phy *phy)
27{
28 struct domain_device *dev, *n;
29 struct asd_sas_port *port = phy->port;
30 struct sas_ha_struct *sas_ha = phy->ha;
31 struct sas_internal *si = to_sas_internal(sas_ha->shost->transportt);
32
33 if (si->dft->lldd_port_formed)
34 si->dft->lldd_port_formed(phy);
35
36 if (port->suspended)
37 port->suspended = 0;
38 else {
39 /* we only need to handle "link returned" actions once */
40 return;
41 }
42
43 /* if the port came back:
44 * 1/ presume every device came back
45 * 2/ force the next revalidation to check all expander phys
46 */
47 list_for_each_entry_safe(dev, n, &port->dev_list, dev_list_node) {
48 int i, rc;
49
50 rc = sas_notify_lldd_dev_found(dev);
51 if (rc) {
52 sas_unregister_dev(port, dev);
53 sas_destruct_devices(port);
54 continue;
55 }
56
57 if (dev_is_expander(dev->dev_type)) {
58 dev->ex_dev.ex_change_count = -1;
59 for (i = 0; i < dev->ex_dev.num_phys; i++) {
60 struct ex_phy *phy = &dev->ex_dev.ex_phy[i];
61
62 phy->phy_change_count = -1;
63 }
64 }
65 }
66
67 sas_discover_event(port, DISCE_RESUME);
68}
69
70static void sas_form_port_add_phy(struct asd_sas_port *port,
71 struct asd_sas_phy *phy, bool wideport)
72{
73 list_add_tail(&phy->port_phy_el, &port->phy_list);
74 sas_phy_set_target(phy, port->port_dev);
75 phy->port = port;
76 port->num_phys++;
77 port->phy_mask |= (1U << phy->id);
78
79 if (wideport)
80 pr_debug("phy%d matched wide port%d\n", phy->id,
81 port->id);
82 else
83 memcpy(port->sas_addr, phy->sas_addr, SAS_ADDR_SIZE);
84
85 if (*(u64 *)port->attached_sas_addr == 0) {
86 memcpy(port->attached_sas_addr, phy->attached_sas_addr,
87 SAS_ADDR_SIZE);
88 port->iproto = phy->iproto;
89 port->tproto = phy->tproto;
90 port->oob_mode = phy->oob_mode;
91 port->linkrate = phy->linkrate;
92 } else {
93 port->linkrate = max(port->linkrate, phy->linkrate);
94 }
95}
96
97/**
98 * sas_form_port - add this phy to a port
99 * @phy: the phy of interest
100 *
101 * This function adds this phy to an existing port, thus creating a wide
102 * port, or it creates a port and adds the phy to the port.
103 */
104static void sas_form_port(struct asd_sas_phy *phy)
105{
106 int i;
107 struct sas_ha_struct *sas_ha = phy->ha;
108 struct asd_sas_port *port = phy->port;
109 struct domain_device *port_dev = NULL;
110 struct sas_internal *si =
111 to_sas_internal(sas_ha->shost->transportt);
112 unsigned long flags;
113
114 if (port) {
115 if (!phy_is_wideport_member(port, phy))
116 sas_deform_port(phy, 0);
117 else if (phy->suspended) {
118 phy->suspended = 0;
119 sas_resume_port(phy);
120
121 /* phy came back, try to cancel the timeout */
122 wake_up(&sas_ha->eh_wait_q);
123 return;
124 } else {
125 pr_info("%s: phy%d belongs to port%d already(%d)!\n",
126 __func__, phy->id, phy->port->id,
127 phy->port->num_phys);
128 return;
129 }
130 }
131
132 /* see if the phy should be part of a wide port */
133 spin_lock_irqsave(&sas_ha->phy_port_lock, flags);
134 for (i = 0; i < sas_ha->num_phys; i++) {
135 port = sas_ha->sas_port[i];
136 spin_lock(&port->phy_list_lock);
137 if (*(u64 *) port->sas_addr &&
138 phy_is_wideport_member(port, phy) && port->num_phys > 0) {
139 /* wide port */
140 port_dev = port->port_dev;
141 sas_form_port_add_phy(port, phy, true);
142 spin_unlock(&port->phy_list_lock);
143 break;
144 }
145 spin_unlock(&port->phy_list_lock);
146 }
147 /* The phy does not match any existing port, create a new one */
148 if (i == sas_ha->num_phys) {
149 for (i = 0; i < sas_ha->num_phys; i++) {
150 port = sas_ha->sas_port[i];
151 spin_lock(&port->phy_list_lock);
152 if (*(u64 *)port->sas_addr == 0
153 && port->num_phys == 0) {
154 port_dev = port->port_dev;
155 sas_form_port_add_phy(port, phy, false);
156 spin_unlock(&port->phy_list_lock);
157 break;
158 }
159 spin_unlock(&port->phy_list_lock);
160 }
161
162 if (i >= sas_ha->num_phys) {
163 pr_err("%s: couldn't find a free port, bug?\n",
164 __func__);
165 spin_unlock_irqrestore(&sas_ha->phy_port_lock, flags);
166 return;
167 }
168 }
169 spin_unlock_irqrestore(&sas_ha->phy_port_lock, flags);
170
171 if (!port->port) {
172 port->port = sas_port_alloc(phy->phy->dev.parent, port->id);
173 BUG_ON(!port->port);
174 sas_port_add(port->port);
175 }
176 sas_port_add_phy(port->port, phy->phy);
177
178 pr_debug("%s added to %s, phy_mask:0x%x (%016llx)\n",
179 dev_name(&phy->phy->dev), dev_name(&port->port->dev),
180 port->phy_mask,
181 SAS_ADDR(port->attached_sas_addr));
182
183 if (port_dev)
184 port_dev->pathways = port->num_phys;
185
186 /* Tell the LLDD about this port formation. */
187 if (si->dft->lldd_port_formed)
188 si->dft->lldd_port_formed(phy);
189
190 sas_discover_event(phy->port, DISCE_DISCOVER_DOMAIN);
191 /* Only insert a revalidate event after initial discovery */
192 if (port_dev && dev_is_expander(port_dev->dev_type)) {
193 struct expander_device *ex_dev = &port_dev->ex_dev;
194
195 ex_dev->ex_change_count = -1;
196 sas_discover_event(port, DISCE_REVALIDATE_DOMAIN);
197 }
198 flush_workqueue(sas_ha->disco_q);
199}
200
201/**
202 * sas_deform_port - remove this phy from the port it belongs to
203 * @phy: the phy of interest
204 * @gone: whether or not the PHY is gone
205 *
206 * This is called when the physical link to the other phy has been
207 * lost (on this phy), in Event thread context. We cannot delay here.
208 */
209void sas_deform_port(struct asd_sas_phy *phy, int gone)
210{
211 struct sas_ha_struct *sas_ha = phy->ha;
212 struct asd_sas_port *port = phy->port;
213 struct sas_internal *si =
214 to_sas_internal(sas_ha->shost->transportt);
215 struct domain_device *dev;
216 unsigned long flags;
217
218 if (!port)
219 return; /* done by a phy event */
220
221 dev = port->port_dev;
222 if (dev)
223 dev->pathways--;
224
225 if (port->num_phys == 1) {
226 sas_unregister_domain_devices(port, gone);
227 sas_destruct_devices(port);
228 sas_port_delete(port->port);
229 port->port = NULL;
230 } else {
231 sas_port_delete_phy(port->port, phy->phy);
232 sas_device_set_phy(dev, port->port);
233 }
234
235 if (si->dft->lldd_port_deformed)
236 si->dft->lldd_port_deformed(phy);
237
238 spin_lock_irqsave(&sas_ha->phy_port_lock, flags);
239 spin_lock(&port->phy_list_lock);
240
241 list_del_init(&phy->port_phy_el);
242 sas_phy_set_target(phy, NULL);
243 phy->port = NULL;
244 port->num_phys--;
245 port->phy_mask &= ~(1U << phy->id);
246
247 if (port->num_phys == 0) {
248 INIT_LIST_HEAD(&port->phy_list);
249 memset(port->sas_addr, 0, SAS_ADDR_SIZE);
250 memset(port->attached_sas_addr, 0, SAS_ADDR_SIZE);
251 port->iproto = 0;
252 port->tproto = 0;
253 port->oob_mode = 0;
254 port->phy_mask = 0;
255 }
256 spin_unlock(&port->phy_list_lock);
257 spin_unlock_irqrestore(&sas_ha->phy_port_lock, flags);
258
259 /* Only insert revalidate event if the port still has members */
260 if (port->port && dev && dev_is_expander(dev->dev_type)) {
261 struct expander_device *ex_dev = &dev->ex_dev;
262
263 ex_dev->ex_change_count = -1;
264 sas_discover_event(port, DISCE_REVALIDATE_DOMAIN);
265 }
266 flush_workqueue(sas_ha->disco_q);
267
268 return;
269}
270
271/* ---------- SAS port events ---------- */
272
273void sas_porte_bytes_dmaed(struct work_struct *work)
274{
275 struct asd_sas_event *ev = to_asd_sas_event(work);
276 struct asd_sas_phy *phy = ev->phy;
277
278 sas_form_port(phy);
279}
280
281void sas_porte_broadcast_rcvd(struct work_struct *work)
282{
283 struct asd_sas_event *ev = to_asd_sas_event(work);
284 struct asd_sas_phy *phy = ev->phy;
285 unsigned long flags;
286 u32 prim;
287
288 spin_lock_irqsave(&phy->sas_prim_lock, flags);
289 prim = phy->sas_prim;
290 spin_unlock_irqrestore(&phy->sas_prim_lock, flags);
291
292 pr_debug("broadcast received: %d\n", prim);
293 sas_discover_event(phy->port, DISCE_REVALIDATE_DOMAIN);
294
295 if (phy->port)
296 flush_workqueue(phy->port->ha->disco_q);
297}
298
299void sas_porte_link_reset_err(struct work_struct *work)
300{
301 struct asd_sas_event *ev = to_asd_sas_event(work);
302 struct asd_sas_phy *phy = ev->phy;
303
304 sas_deform_port(phy, 1);
305}
306
307void sas_porte_timer_event(struct work_struct *work)
308{
309 struct asd_sas_event *ev = to_asd_sas_event(work);
310 struct asd_sas_phy *phy = ev->phy;
311
312 sas_deform_port(phy, 1);
313}
314
315void sas_porte_hard_reset(struct work_struct *work)
316{
317 struct asd_sas_event *ev = to_asd_sas_event(work);
318 struct asd_sas_phy *phy = ev->phy;
319
320 sas_deform_port(phy, 1);
321}
322
323/* ---------- SAS port registration ---------- */
324
325static void sas_init_port(struct asd_sas_port *port,
326 struct sas_ha_struct *sas_ha, int i)
327{
328 memset(port, 0, sizeof(*port));
329 port->id = i;
330 INIT_LIST_HEAD(&port->dev_list);
331 INIT_LIST_HEAD(&port->disco_list);
332 INIT_LIST_HEAD(&port->destroy_list);
333 INIT_LIST_HEAD(&port->sas_port_del_list);
334 spin_lock_init(&port->phy_list_lock);
335 INIT_LIST_HEAD(&port->phy_list);
336 port->ha = sas_ha;
337
338 spin_lock_init(&port->dev_list_lock);
339}
340
341int sas_register_ports(struct sas_ha_struct *sas_ha)
342{
343 int i;
344
345 /* initialize the ports and discovery */
346 for (i = 0; i < sas_ha->num_phys; i++) {
347 struct asd_sas_port *port = sas_ha->sas_port[i];
348
349 sas_init_port(port, sas_ha, i);
350 sas_init_disc(&port->disc, port);
351 }
352 return 0;
353}
354
355void sas_unregister_ports(struct sas_ha_struct *sas_ha)
356{
357 int i;
358
359 for (i = 0; i < sas_ha->num_phys; i++)
360 if (sas_ha->sas_phy[i]->port)
361 sas_deform_port(sas_ha->sas_phy[i], 0);
362
363}
364
365const work_func_t sas_port_event_fns[PORT_NUM_EVENTS] = {
366 [PORTE_BYTES_DMAED] = sas_porte_bytes_dmaed,
367 [PORTE_BROADCAST_RCVD] = sas_porte_broadcast_rcvd,
368 [PORTE_LINK_RESET_ERR] = sas_porte_link_reset_err,
369 [PORTE_TIMER_EVENT] = sas_porte_timer_event,
370 [PORTE_HARD_RESET] = sas_porte_hard_reset,
371};