]>
Commit | Line | Data |
---|---|---|
2908d778 JB |
1 | /* |
2 | * Serial Attached SCSI (SAS) Phy 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 | #include <scsi/scsi_host.h> | |
27 | #include <scsi/scsi_transport.h> | |
28 | #include <scsi/scsi_transport_sas.h> | |
29 | #include "../scsi_sas_internal.h" | |
30 | ||
31 | /* ---------- Phy events ---------- */ | |
32 | ||
c4028958 | 33 | static void sas_phye_loss_of_signal(struct work_struct *work) |
2908d778 | 34 | { |
22b9153f | 35 | struct asd_sas_event *ev = to_asd_sas_event(work); |
c4028958 | 36 | struct asd_sas_phy *phy = ev->phy; |
2908d778 | 37 | |
ef84e289 | 38 | phy->in_shutdown = 0; |
2908d778 | 39 | phy->error = 0; |
90f1e10d | 40 | sas_deform_port(phy, 1); |
2908d778 JB |
41 | } |
42 | ||
c4028958 | 43 | static void sas_phye_oob_done(struct work_struct *work) |
2908d778 | 44 | { |
22b9153f | 45 | struct asd_sas_event *ev = to_asd_sas_event(work); |
c4028958 | 46 | struct asd_sas_phy *phy = ev->phy; |
2908d778 | 47 | |
ef84e289 | 48 | phy->in_shutdown = 0; |
2908d778 JB |
49 | phy->error = 0; |
50 | } | |
51 | ||
c4028958 | 52 | static void sas_phye_oob_error(struct work_struct *work) |
2908d778 | 53 | { |
22b9153f | 54 | struct asd_sas_event *ev = to_asd_sas_event(work); |
c4028958 | 55 | struct asd_sas_phy *phy = ev->phy; |
2908d778 JB |
56 | struct sas_ha_struct *sas_ha = phy->ha; |
57 | struct asd_sas_port *port = phy->port; | |
58 | struct sas_internal *i = | |
59 | to_sas_internal(sas_ha->core.shost->transportt); | |
60 | ||
90f1e10d | 61 | sas_deform_port(phy, 1); |
2908d778 JB |
62 | |
63 | if (!port && phy->enabled && i->dft->lldd_control_phy) { | |
64 | phy->error++; | |
65 | switch (phy->error) { | |
66 | case 1: | |
67 | case 2: | |
a01e70e5 JB |
68 | i->dft->lldd_control_phy(phy, PHY_FUNC_HARD_RESET, |
69 | NULL); | |
2908d778 JB |
70 | break; |
71 | case 3: | |
72 | default: | |
73 | phy->error = 0; | |
74 | phy->enabled = 0; | |
a01e70e5 | 75 | i->dft->lldd_control_phy(phy, PHY_FUNC_DISABLE, NULL); |
2908d778 JB |
76 | break; |
77 | } | |
78 | } | |
79 | } | |
80 | ||
c4028958 | 81 | static void sas_phye_spinup_hold(struct work_struct *work) |
2908d778 | 82 | { |
22b9153f | 83 | struct asd_sas_event *ev = to_asd_sas_event(work); |
c4028958 | 84 | struct asd_sas_phy *phy = ev->phy; |
2908d778 JB |
85 | struct sas_ha_struct *sas_ha = phy->ha; |
86 | struct sas_internal *i = | |
87 | to_sas_internal(sas_ha->core.shost->transportt); | |
88 | ||
2908d778 | 89 | phy->error = 0; |
a01e70e5 | 90 | i->dft->lldd_control_phy(phy, PHY_FUNC_RELEASE_SPINUP_HOLD, NULL); |
2908d778 JB |
91 | } |
92 | ||
303694ee DW |
93 | static void sas_phye_resume_timeout(struct work_struct *work) |
94 | { | |
95 | struct asd_sas_event *ev = to_asd_sas_event(work); | |
96 | struct asd_sas_phy *phy = ev->phy; | |
97 | ||
303694ee DW |
98 | /* phew, lldd got the phy back in the nick of time */ |
99 | if (!phy->suspended) { | |
100 | dev_info(&phy->phy->dev, "resume timeout cancelled\n"); | |
101 | return; | |
102 | } | |
103 | ||
104 | phy->error = 0; | |
105 | phy->suspended = 0; | |
106 | sas_deform_port(phy, 1); | |
107 | } | |
108 | ||
109 | ||
ef84e289 JY |
110 | static void sas_phye_shutdown(struct work_struct *work) |
111 | { | |
112 | struct asd_sas_event *ev = to_asd_sas_event(work); | |
113 | struct asd_sas_phy *phy = ev->phy; | |
114 | struct sas_ha_struct *sas_ha = phy->ha; | |
115 | struct sas_internal *i = | |
116 | to_sas_internal(sas_ha->core.shost->transportt); | |
117 | ||
118 | if (phy->enabled) { | |
119 | int ret; | |
120 | ||
121 | phy->error = 0; | |
122 | phy->enabled = 0; | |
123 | ret = i->dft->lldd_control_phy(phy, PHY_FUNC_DISABLE, NULL); | |
124 | if (ret) | |
125 | sas_printk("lldd disable phy%02d returned %d\n", | |
126 | phy->id, ret); | |
127 | } else | |
128 | sas_printk("phy%02d is not enabled, cannot shutdown\n", | |
129 | phy->id); | |
130 | } | |
131 | ||
2908d778 JB |
132 | /* ---------- Phy class registration ---------- */ |
133 | ||
134 | int sas_register_phys(struct sas_ha_struct *sas_ha) | |
135 | { | |
136 | int i; | |
137 | ||
2908d778 JB |
138 | /* Now register the phys. */ |
139 | for (i = 0; i < sas_ha->num_phys; i++) { | |
2908d778 JB |
140 | struct asd_sas_phy *phy = sas_ha->sas_phy[i]; |
141 | ||
142 | phy->error = 0; | |
ef84e289 | 143 | atomic_set(&phy->event_nr, 0); |
2908d778 | 144 | INIT_LIST_HEAD(&phy->port_phy_el); |
2908d778 | 145 | |
2908d778 JB |
146 | phy->port = NULL; |
147 | phy->ha = sas_ha; | |
148 | spin_lock_init(&phy->frame_rcvd_lock); | |
149 | spin_lock_init(&phy->sas_prim_lock); | |
150 | phy->frame_rcvd_size = 0; | |
151 | ||
22b9153f | 152 | phy->phy = sas_phy_alloc(&sas_ha->core.shost->shost_gendev, i); |
2908d778 JB |
153 | if (!phy->phy) |
154 | return -ENOMEM; | |
155 | ||
156 | phy->phy->identify.initiator_port_protocols = | |
157 | phy->iproto; | |
158 | phy->phy->identify.target_port_protocols = phy->tproto; | |
159 | phy->phy->identify.sas_address = SAS_ADDR(sas_ha->sas_addr); | |
160 | phy->phy->identify.phy_identifier = i; | |
a01e70e5 JB |
161 | phy->phy->minimum_linkrate_hw = SAS_LINK_RATE_UNKNOWN; |
162 | phy->phy->maximum_linkrate_hw = SAS_LINK_RATE_UNKNOWN; | |
163 | phy->phy->minimum_linkrate = SAS_LINK_RATE_UNKNOWN; | |
164 | phy->phy->maximum_linkrate = SAS_LINK_RATE_UNKNOWN; | |
2908d778 JB |
165 | phy->phy->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN; |
166 | ||
167 | sas_phy_add(phy->phy); | |
168 | } | |
169 | ||
170 | return 0; | |
171 | } | |
6bd9033a JY |
172 | |
173 | const work_func_t sas_phy_event_fns[PHY_NUM_EVENTS] = { | |
174 | [PHYE_LOSS_OF_SIGNAL] = sas_phye_loss_of_signal, | |
175 | [PHYE_OOB_DONE] = sas_phye_oob_done, | |
176 | [PHYE_OOB_ERROR] = sas_phye_oob_error, | |
177 | [PHYE_SPINUP_HOLD] = sas_phye_spinup_hold, | |
178 | [PHYE_RESUME_TIMEOUT] = sas_phye_resume_timeout, | |
ef84e289 | 179 | [PHYE_SHUTDOWN] = sas_phye_shutdown, |
6bd9033a | 180 | }; |