James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 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 | |
Dan Williams | 00f0254 | 2010-10-01 13:55:52 -0700 | [diff] [blame] | 31 | static 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 | |
Dan Williams | 303694e | 2012-06-21 23:41:51 -0700 | [diff] [blame] | 42 | static 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); |
Jason Yan | 0558f33 | 2017-12-08 17:42:09 +0800 | [diff] [blame] | 69 | sas_destruct_devices(port); |
Dan Williams | 303694e | 2012-06-21 23:41:51 -0700 | [diff] [blame] | 70 | continue; |
| 71 | } |
| 72 | |
James Bottomley | aa9f832 | 2013-05-07 14:44:06 -0700 | [diff] [blame] | 73 | if (dev->dev_type == SAS_EDGE_EXPANDER_DEVICE || dev->dev_type == SAS_FANOUT_EXPANDER_DEVICE) { |
Dan Williams | 303694e | 2012-06-21 23:41:51 -0700 | [diff] [blame] | 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 | |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 86 | /** |
Bart Van Assche | 121246a | 2018-02-22 13:49:59 -0800 | [diff] [blame] | 87 | * sas_form_port - add this phy to a port |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 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 | */ |
| 93 | static 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); |
Darrick J. Wong | 980fa2f | 2007-01-11 14:15:40 -0800 | [diff] [blame] | 100 | unsigned long flags; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 101 | |
| 102 | if (port) { |
Dan Williams | 00f0254 | 2010-10-01 13:55:52 -0700 | [diff] [blame] | 103 | if (!phy_is_wideport_member(port, phy)) |
Dan Williams | 90f1e10 | 2011-05-24 13:17:53 -0700 | [diff] [blame] | 104 | sas_deform_port(phy, 0); |
Dan Williams | 303694e | 2012-06-21 23:41:51 -0700 | [diff] [blame] | 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 { |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 113 | SAS_DPRINTK("%s: phy%d belongs to port%d already(%d)!\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 114 | __func__, phy->id, phy->port->id, |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 115 | phy->port->num_phys); |
| 116 | return; |
| 117 | } |
| 118 | } |
| 119 | |
Tom Peng | 5381837 | 2009-07-01 20:37:26 +0800 | [diff] [blame] | 120 | /* see if the phy should be part of a wide port */ |
Darrick J. Wong | 980fa2f | 2007-01-11 14:15:40 -0800 | [diff] [blame] | 121 | spin_lock_irqsave(&sas_ha->phy_port_lock, flags); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 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 && |
Dan Williams | 00f0254 | 2010-10-01 13:55:52 -0700 | [diff] [blame] | 126 | phy_is_wideport_member(port, phy) && port->num_phys > 0) { |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 127 | /* wide port */ |
| 128 | SAS_DPRINTK("phy%d matched wide port%d\n", phy->id, |
| 129 | port->id); |
| 130 | break; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 131 | } |
| 132 | spin_unlock(&port->phy_list_lock); |
| 133 | } |
Tom Peng | 5381837 | 2009-07-01 20:37:26 +0800 | [diff] [blame] | 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 | } |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 148 | |
| 149 | if (i >= sas_ha->num_phys) { |
| 150 | printk(KERN_NOTICE "%s: couldn't find a free port, bug?\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 151 | __func__); |
Darrick J. Wong | 980fa2f | 2007-01-11 14:15:40 -0800 | [diff] [blame] | 152 | spin_unlock_irqrestore(&sas_ha->phy_port_lock, flags); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 153 | return; |
| 154 | } |
| 155 | |
| 156 | /* add the phy to the port */ |
| 157 | list_add_tail(&phy->port_phy_el, &port->phy_list); |
Dan Williams | 899fcf4 | 2012-01-28 17:24:40 -0800 | [diff] [blame] | 158 | sas_phy_set_target(phy, port->port_dev); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 159 | phy->port = port; |
| 160 | port->num_phys++; |
| 161 | port->phy_mask |= (1U << phy->id); |
| 162 | |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 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); |
Darrick J. Wong | 980fa2f | 2007-01-11 14:15:40 -0800 | [diff] [blame] | 174 | spin_unlock_irqrestore(&sas_ha->phy_port_lock, flags); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 175 | |
| 176 | if (!port->port) { |
Dan Williams | b4698d88 | 2012-04-19 23:48:12 -0700 | [diff] [blame] | 177 | port->port = sas_port_alloc(phy->phy->dev.parent, port->id); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 178 | BUG_ON(!port->port); |
| 179 | sas_port_add(port->port); |
| 180 | } |
| 181 | sas_port_add_phy(port->port, phy->phy); |
| 182 | |
James Bottomley | a29c051 | 2008-02-23 23:38:44 -0600 | [diff] [blame] | 183 | SAS_DPRINTK("%s added to %s, phy_mask:0x%x (%16llx)\n", |
Kay Sievers | 71610f5 | 2008-12-03 22:41:36 +0100 | [diff] [blame] | 184 | dev_name(&phy->phy->dev), dev_name(&port->port->dev), |
James Bottomley | a29c051 | 2008-02-23 23:38:44 -0600 | [diff] [blame] | 185 | port->phy_mask, |
| 186 | SAS_ADDR(port->attached_sas_addr)); |
| 187 | |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 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); |
Jason Yan | 517e515 | 2017-12-08 17:42:08 +0800 | [diff] [blame] | 196 | flush_workqueue(sas_ha->disco_q); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | /** |
Bart Van Assche | 121246a | 2018-02-22 13:49:59 -0800 | [diff] [blame] | 200 | * sas_deform_port - remove this phy from the port it belongs to |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 201 | * @phy: the phy of interest |
Bart Van Assche | 121246a | 2018-02-22 13:49:59 -0800 | [diff] [blame] | 202 | * @gone: whether or not the PHY is gone |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 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 | */ |
Dan Williams | 90f1e10 | 2011-05-24 13:17:53 -0700 | [diff] [blame] | 207 | void sas_deform_port(struct asd_sas_phy *phy, int gone) |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 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); |
Dan Williams | 90f1e10 | 2011-05-24 13:17:53 -0700 | [diff] [blame] | 213 | struct domain_device *dev; |
Darrick J. Wong | 980fa2f | 2007-01-11 14:15:40 -0800 | [diff] [blame] | 214 | unsigned long flags; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 215 | |
| 216 | if (!port) |
| 217 | return; /* done by a phy event */ |
| 218 | |
Dan Williams | 90f1e10 | 2011-05-24 13:17:53 -0700 | [diff] [blame] | 219 | dev = port->port_dev; |
| 220 | if (dev) |
| 221 | dev->pathways--; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 222 | |
| 223 | if (port->num_phys == 1) { |
Dan Williams | 7d05919 | 2012-01-10 14:39:13 -0800 | [diff] [blame] | 224 | sas_unregister_domain_devices(port, gone); |
Jason Yan | 0558f33 | 2017-12-08 17:42:09 +0800 | [diff] [blame] | 225 | sas_destruct_devices(port); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 226 | sas_port_delete(port->port); |
| 227 | port->port = NULL; |
Dan Williams | f41a0c4 | 2011-12-21 21:33:17 -0800 | [diff] [blame] | 228 | } else { |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 229 | sas_port_delete_phy(port->port, phy->phy); |
Dan Williams | f41a0c4 | 2011-12-21 21:33:17 -0800 | [diff] [blame] | 230 | sas_device_set_phy(dev, port->port); |
| 231 | } |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 232 | |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 233 | if (si->dft->lldd_port_deformed) |
| 234 | si->dft->lldd_port_deformed(phy); |
| 235 | |
Darrick J. Wong | 980fa2f | 2007-01-11 14:15:40 -0800 | [diff] [blame] | 236 | spin_lock_irqsave(&sas_ha->phy_port_lock, flags); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 237 | spin_lock(&port->phy_list_lock); |
| 238 | |
| 239 | list_del_init(&phy->port_phy_el); |
Dan Williams | 899fcf4 | 2012-01-28 17:24:40 -0800 | [diff] [blame] | 240 | sas_phy_set_target(phy, NULL); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 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); |
Darrick J. Wong | 980fa2f | 2007-01-11 14:15:40 -0800 | [diff] [blame] | 256 | spin_unlock_irqrestore(&sas_ha->phy_port_lock, flags); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 257 | |
| 258 | return; |
| 259 | } |
| 260 | |
| 261 | /* ---------- SAS port events ---------- */ |
| 262 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 263 | void sas_porte_bytes_dmaed(struct work_struct *work) |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 264 | { |
Dan Williams | 22b9153 | 2012-03-09 11:00:06 -0800 | [diff] [blame] | 265 | struct asd_sas_event *ev = to_asd_sas_event(work); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 266 | struct asd_sas_phy *phy = ev->phy; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 267 | |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 268 | sas_form_port(phy); |
| 269 | } |
| 270 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 271 | void sas_porte_broadcast_rcvd(struct work_struct *work) |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 272 | { |
Dan Williams | 22b9153 | 2012-03-09 11:00:06 -0800 | [diff] [blame] | 273 | struct asd_sas_event *ev = to_asd_sas_event(work); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 274 | struct asd_sas_phy *phy = ev->phy; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 275 | unsigned long flags; |
| 276 | u32 prim; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 277 | |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 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); |
Jason Yan | 517e515 | 2017-12-08 17:42:08 +0800 | [diff] [blame] | 284 | |
| 285 | if (phy->port) |
| 286 | flush_workqueue(phy->port->ha->disco_q); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 287 | } |
| 288 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 289 | void sas_porte_link_reset_err(struct work_struct *work) |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 290 | { |
Dan Williams | 22b9153 | 2012-03-09 11:00:06 -0800 | [diff] [blame] | 291 | struct asd_sas_event *ev = to_asd_sas_event(work); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 292 | struct asd_sas_phy *phy = ev->phy; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 293 | |
Dan Williams | 90f1e10 | 2011-05-24 13:17:53 -0700 | [diff] [blame] | 294 | sas_deform_port(phy, 1); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 295 | } |
| 296 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 297 | void sas_porte_timer_event(struct work_struct *work) |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 298 | { |
Dan Williams | 22b9153 | 2012-03-09 11:00:06 -0800 | [diff] [blame] | 299 | struct asd_sas_event *ev = to_asd_sas_event(work); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 300 | struct asd_sas_phy *phy = ev->phy; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 301 | |
Dan Williams | 90f1e10 | 2011-05-24 13:17:53 -0700 | [diff] [blame] | 302 | sas_deform_port(phy, 1); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 303 | } |
| 304 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 305 | void sas_porte_hard_reset(struct work_struct *work) |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 306 | { |
Dan Williams | 22b9153 | 2012-03-09 11:00:06 -0800 | [diff] [blame] | 307 | struct asd_sas_event *ev = to_asd_sas_event(work); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 308 | struct asd_sas_phy *phy = ev->phy; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 309 | |
Dan Williams | 90f1e10 | 2011-05-24 13:17:53 -0700 | [diff] [blame] | 310 | sas_deform_port(phy, 1); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | /* ---------- SAS port registration ---------- */ |
| 314 | |
| 315 | static void sas_init_port(struct asd_sas_port *port, |
| 316 | struct sas_ha_struct *sas_ha, int i) |
| 317 | { |
James Bottomley | a29c051 | 2008-02-23 23:38:44 -0600 | [diff] [blame] | 318 | memset(port, 0, sizeof(*port)); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 319 | port->id = i; |
| 320 | INIT_LIST_HEAD(&port->dev_list); |
Dan Williams | 87c8331 | 2011-11-17 17:59:51 -0800 | [diff] [blame] | 321 | INIT_LIST_HEAD(&port->disco_list); |
| 322 | INIT_LIST_HEAD(&port->destroy_list); |
Jason Yan | 0558f33 | 2017-12-08 17:42:09 +0800 | [diff] [blame] | 323 | INIT_LIST_HEAD(&port->sas_port_del_list); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 324 | spin_lock_init(&port->phy_list_lock); |
| 325 | INIT_LIST_HEAD(&port->phy_list); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 326 | port->ha = sas_ha; |
| 327 | |
| 328 | spin_lock_init(&port->dev_list_lock); |
| 329 | } |
| 330 | |
| 331 | int 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 | |
| 345 | void 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) |
Dan Williams | 90f1e10 | 2011-05-24 13:17:53 -0700 | [diff] [blame] | 351 | sas_deform_port(sas_ha->sas_phy[i], 0); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 352 | |
| 353 | } |
Jason Yan | 1c393b9 | 2017-12-08 17:42:04 +0800 | [diff] [blame] | 354 | |
| 355 | const 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 | }; |