isci: remove usage of sci_sas_address in scic_sds_remote_device
[deliverable/linux.git] / drivers / scsi / isci / port.c
1 /*
2 * This file is provided under a dual BSD/GPLv2 license. When using or
3 * redistributing this file, you may do so under either license.
4 *
5 * GPL LICENSE SUMMARY
6 *
7 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
23 *
24 * BSD LICENSE
25 *
26 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27 * All rights reserved.
28 *
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
31 * are met:
32 *
33 * * Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * * Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in
37 * the documentation and/or other materials provided with the
38 * distribution.
39 * * Neither the name of Intel Corporation nor the names of its
40 * contributors may be used to endorse or promote products derived
41 * from this software without specific prior written permission.
42 *
43 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
44 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
45 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
46 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
47 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
49 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
50 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
51 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
52 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
53 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54 */
55
56 /**
57 * This file contains the isci port implementation.
58 *
59 *
60 */
61
62
63 #include <linux/workqueue.h>
64 #include "isci.h"
65 #include "scic_io_request.h"
66 #include "scic_phy.h"
67 #include "scic_sds_phy.h"
68 #include "scic_port.h"
69 #include "port.h"
70 #include "request.h"
71
72 static void isci_port_change_state(
73 struct isci_port *isci_port,
74 enum isci_status status);
75
76
77
78 /**
79 * isci_port_init() - This function initializes the given isci_port object.
80 * @isci_port: This parameter specifies the port object to be initialized.
81 * @isci_host: This parameter specifies parent controller object for the port.
82 * @index: This parameter specifies which SCU port the isci_port associates
83 * with. Generally, SCU port 0 relates to isci_port 0, etc.
84 *
85 */
86 void isci_port_init(
87 struct isci_port *isci_port,
88 struct isci_host *isci_host,
89 int index)
90 {
91 struct scic_sds_port *scic_port;
92 struct scic_sds_controller *controller = isci_host->core_controller;
93
94 INIT_LIST_HEAD(&isci_port->remote_dev_list);
95 INIT_LIST_HEAD(&isci_port->domain_dev_list);
96 spin_lock_init(&isci_port->state_lock);
97 init_completion(&isci_port->start_complete);
98 isci_port->isci_host = isci_host;
99 isci_port_change_state(isci_port, isci_freed);
100
101 (void)scic_controller_get_port_handle(controller, index, &scic_port);
102 sci_object_set_association(scic_port, isci_port);
103 isci_port->sci_port_handle = scic_port;
104 }
105
106
107 /**
108 * isci_port_get_state() - This function gets the status of the port object.
109 * @isci_port: This parameter points to the isci_port object
110 *
111 * status of the object as a isci_status enum.
112 */
113 enum isci_status isci_port_get_state(
114 struct isci_port *isci_port)
115 {
116 return isci_port->status;
117 }
118
119 static void isci_port_change_state(
120 struct isci_port *isci_port,
121 enum isci_status status)
122 {
123 unsigned long flags;
124
125 dev_dbg(&isci_port->isci_host->pdev->dev,
126 "%s: isci_port = %p, state = 0x%x\n",
127 __func__, isci_port, status);
128
129 spin_lock_irqsave(&isci_port->state_lock, flags);
130 isci_port->status = status;
131 spin_unlock_irqrestore(&isci_port->state_lock, flags);
132 }
133
134 void isci_port_bc_change_received(
135 struct isci_host *isci_host,
136 struct scic_sds_port *port,
137 struct scic_sds_phy *phy)
138 {
139 struct isci_phy *isci_phy =
140 (struct isci_phy *)sci_object_get_association(phy);
141
142 dev_dbg(&isci_host->pdev->dev,
143 "%s: isci_phy = %p, sas_phy = %p\n",
144 __func__,
145 isci_phy,
146 &isci_phy->sas_phy);
147
148 isci_host->sas_ha.notify_port_event(
149 &isci_phy->sas_phy,
150 PORTE_BROADCAST_RCVD
151 );
152
153 scic_port_enable_broadcast_change_notification(port);
154 }
155
156 /**
157 * isci_port_link_up() - This function is called by the sci core when a link
158 * becomes active. the identify address frame is retrieved from the core and
159 * a notify port event is sent to libsas.
160 * @isci_host: This parameter specifies the isci host object.
161 * @port: This parameter specifies the sci port with the active link.
162 * @phy: This parameter specifies the sci phy with the active link.
163 *
164 */
165 void isci_port_link_up(
166 struct isci_host *isci_host,
167 struct scic_sds_port *port,
168 struct scic_sds_phy *phy)
169 {
170 unsigned long flags;
171 struct scic_port_properties properties;
172 struct isci_phy *isci_phy
173 = (struct isci_phy *)sci_object_get_association(phy);
174 struct isci_port *isci_port
175 = (struct isci_port *)sci_object_get_association(port);
176 enum sci_status call_status;
177 unsigned long success = true;
178
179 BUG_ON(isci_phy->isci_port != NULL);
180
181 isci_phy->isci_port = isci_port;
182
183 dev_dbg(&isci_host->pdev->dev,
184 "%s: isci_port = %p\n",
185 __func__, isci_port);
186
187 spin_lock_irqsave(&isci_phy->sas_phy.frame_rcvd_lock, flags);
188
189 isci_port_change_state(isci_phy->isci_port, isci_starting);
190
191 scic_port_get_properties(port, &properties);
192
193 if (properties.remote.protocols.u.bits.stp_target) {
194 u64 attached_sas_address;
195
196 struct scic_sata_phy_properties sata_phy_properties;
197
198 isci_phy->sas_phy.oob_mode = SATA_OOB_MODE;
199
200 /* Get a copy of the signature fis for libsas */
201 call_status = scic_sata_phy_get_properties(phy,
202 &sata_phy_properties);
203
204 /*
205 * XXX I am concerned about this "assert". shouldn't we
206 * handle the return appropriately?
207 */
208 BUG_ON(call_status != SCI_SUCCESS);
209
210 memcpy(isci_phy->frame_rcvd.fis,
211 &sata_phy_properties.signature_fis,
212 sizeof(struct sata_fis_reg_d2h));
213
214 isci_phy->sas_phy.frame_rcvd_size = sizeof(struct sata_fis_reg_d2h);
215
216 /*
217 * For direct-attached SATA devices, the SCI core will
218 * automagically assign a SAS address to the end device
219 * for the purpose of creating a port. This SAS address
220 * will not be the same as assigned to the PHY and needs
221 * to be obtained from struct scic_port_properties properties.
222 */
223 attached_sas_address = properties.remote.sas_address.high;
224 attached_sas_address <<= 32;
225 attached_sas_address |= properties.remote.sas_address.low;
226 swab64s(&attached_sas_address);
227
228 memcpy(&isci_phy->sas_phy.attached_sas_addr,
229 &attached_sas_address, sizeof(attached_sas_address));
230
231 } else if (properties.remote.protocols.u.bits.ssp_target ||
232 properties.remote.protocols.u.bits.smp_target) {
233
234 struct scic_sas_phy_properties sas_phy_properties;
235
236 isci_phy->sas_phy.oob_mode = SAS_OOB_MODE;
237
238 /* Get a copy of the identify address frame for libsas */
239 call_status = scic_sas_phy_get_properties(phy,
240 &sas_phy_properties);
241
242 BUG_ON(call_status != SCI_SUCCESS);
243
244 memcpy(isci_phy->frame_rcvd.aif,
245 &(sas_phy_properties.received_iaf),
246 sizeof(struct sci_sas_identify_address_frame));
247
248 isci_phy->sas_phy.frame_rcvd_size
249 = sizeof(struct sci_sas_identify_address_frame);
250
251 /* Copy the attached SAS address from the IAF */
252 memcpy(isci_phy->sas_phy.attached_sas_addr,
253 ((struct sas_identify_frame *)
254 (&isci_phy->frame_rcvd.aif))->sas_addr,
255 SAS_ADDR_SIZE);
256
257 } else {
258 dev_err(&isci_host->pdev->dev, "%s: unkown target\n", __func__);
259 success = false;
260 }
261
262 isci_phy->sas_phy.phy->negotiated_linkrate = sci_phy_linkrate(phy);
263
264 spin_unlock_irqrestore(&isci_phy->sas_phy.frame_rcvd_lock, flags);
265
266 /* Notify libsas that we have an address frame, if indeed
267 * we've found an SSP, SMP, or STP target */
268 if (success)
269 isci_host->sas_ha.notify_port_event(&isci_phy->sas_phy,
270 PORTE_BYTES_DMAED);
271 }
272
273
274 /**
275 * isci_port_link_down() - This function is called by the sci core when a link
276 * becomes inactive.
277 * @isci_host: This parameter specifies the isci host object.
278 * @phy: This parameter specifies the isci phy with the active link.
279 * @port: This parameter specifies the isci port with the active link.
280 *
281 */
282 void isci_port_link_down(struct isci_host *isci_host, struct isci_phy *isci_phy,
283 struct isci_port *isci_port)
284 {
285 struct isci_remote_device *isci_device;
286
287 dev_dbg(&isci_host->pdev->dev,
288 "%s: isci_port = %p\n", __func__, isci_port);
289
290 if (isci_port) {
291
292 /* check to see if this is the last phy on this port. */
293 if (isci_phy->sas_phy.port
294 && isci_phy->sas_phy.port->num_phys == 1) {
295
296 /* change the state for all devices on this port.
297 * The next task sent to this device will be returned
298 * as SAS_TASK_UNDELIVERED, and the scsi mid layer
299 * will remove the target
300 */
301 list_for_each_entry(isci_device,
302 &isci_port->remote_dev_list,
303 node) {
304 dev_dbg(&isci_host->pdev->dev,
305 "%s: isci_device = %p\n",
306 __func__, isci_device);
307 isci_remote_device_change_state(isci_device,
308 isci_stopping);
309 }
310 }
311 isci_port_change_state(isci_port, isci_stopping);
312 }
313
314 /* Notify libsas of the borken link, this will trigger calls to our
315 * isci_port_deformed and isci_dev_gone functions.
316 */
317 sas_phy_disconnected(&isci_phy->sas_phy);
318 isci_host->sas_ha.notify_phy_event(&isci_phy->sas_phy,
319 PHYE_LOSS_OF_SIGNAL);
320
321 isci_phy->isci_port = NULL;
322
323 dev_dbg(&isci_host->pdev->dev,
324 "%s: isci_port = %p - Done\n", __func__, isci_port);
325 }
326
327
328 /**
329 * isci_port_deformed() - This function is called by libsas when a port becomes
330 * inactive.
331 * @phy: This parameter specifies the libsas phy with the inactive port.
332 *
333 */
334 void isci_port_deformed(
335 struct asd_sas_phy *phy)
336 {
337 pr_debug("%s: sas_phy = %p\n", __func__, phy);
338 }
339
340 /**
341 * isci_port_formed() - This function is called by libsas when a port becomes
342 * active.
343 * @phy: This parameter specifies the libsas phy with the active port.
344 *
345 */
346 void isci_port_formed(
347 struct asd_sas_phy *phy)
348 {
349 pr_debug("%s: sas_phy = %p, sas_port = %p\n", __func__, phy, phy->port);
350 }
351
352 /**
353 * isci_port_ready() - This function is called by the sci core when a link
354 * becomes ready.
355 * @isci_host: This parameter specifies the isci host object.
356 * @port: This parameter specifies the sci port with the active link.
357 *
358 */
359 void isci_port_ready(struct isci_host *isci_host, struct isci_port *isci_port)
360 {
361 dev_dbg(&isci_host->pdev->dev,
362 "%s: isci_port = %p\n", __func__, isci_port);
363
364 complete_all(&isci_port->start_complete);
365 isci_port_change_state(isci_port, isci_ready);
366 return;
367 }
368
369 /**
370 * isci_port_not_ready() - This function is called by the sci core when a link
371 * is not ready. All remote devices on this link will be removed if they are
372 * in the stopping state.
373 * @isci_host: This parameter specifies the isci host object.
374 * @port: This parameter specifies the sci port with the active link.
375 *
376 */
377 void isci_port_not_ready(struct isci_host *isci_host, struct isci_port *isci_port)
378 {
379 dev_dbg(&isci_host->pdev->dev,
380 "%s: isci_port = %p\n", __func__, isci_port);
381 }
382
383 /**
384 * isci_port_hard_reset_complete() - This function is called by the sci core
385 * when the hard reset complete notification has been received.
386 * @port: This parameter specifies the sci port with the active link.
387 * @completion_status: This parameter specifies the core status for the reset
388 * process.
389 *
390 */
391 void isci_port_hard_reset_complete(struct isci_port *isci_port,
392 enum sci_status completion_status)
393 {
394 dev_dbg(&isci_port->isci_host->pdev->dev,
395 "%s: isci_port = %p, completion_status=%x\n",
396 __func__, isci_port, completion_status);
397
398 /* Save the status of the hard reset from the port. */
399 isci_port->hard_reset_status = completion_status;
400
401 complete_all(&isci_port->hard_reset_complete);
402 }
403
404 int isci_port_perform_hard_reset(struct isci_host *ihost, struct isci_port *iport,
405 struct isci_phy *iphy)
406 {
407 unsigned long flags;
408 enum sci_status status;
409 int ret = TMF_RESP_FUNC_COMPLETE;
410
411 dev_dbg(&ihost->pdev->dev, "%s: iport = %p\n",
412 __func__, iport);
413
414 init_completion(&iport->hard_reset_complete);
415
416 spin_lock_irqsave(&ihost->scic_lock, flags);
417
418 #define ISCI_PORT_RESET_TIMEOUT SCIC_SDS_SIGNATURE_FIS_TIMEOUT
419 status = scic_port_hard_reset(iport->sci_port_handle,
420 ISCI_PORT_RESET_TIMEOUT);
421
422 spin_unlock_irqrestore(&ihost->scic_lock, flags);
423
424 if (status == SCI_SUCCESS) {
425 wait_for_completion(&iport->hard_reset_complete);
426
427 dev_dbg(&ihost->pdev->dev,
428 "%s: iport = %p; hard reset completion\n",
429 __func__, iport);
430
431 if (iport->hard_reset_status != SCI_SUCCESS)
432 ret = TMF_RESP_FUNC_FAILED;
433 } else {
434 ret = TMF_RESP_FUNC_FAILED;
435
436 dev_err(&ihost->pdev->dev,
437 "%s: iport = %p; scic_port_hard_reset call"
438 " failed 0x%x\n",
439 __func__, iport, status);
440
441 }
442
443 /* If the hard reset for the port has failed, consider this
444 * the same as link failures on all phys in the port.
445 */
446 if (ret != TMF_RESP_FUNC_COMPLETE) {
447 dev_err(&ihost->pdev->dev,
448 "%s: iport = %p; hard reset failed "
449 "(0x%x) - sending link down to libsas for phy %p\n",
450 __func__, iport, iport->hard_reset_status, iphy);
451
452 isci_port_link_down(ihost, iphy, iport);
453 }
454
455 return ret;
456 }
457
458 /**
459 * isci_port_invalid_link_up() - This function informs the SCI Core user that
460 * a phy/link became ready, but the phy is not allowed in the port. In some
461 * situations the underlying hardware only allows for certain phy to port
462 * mappings. If these mappings are violated, then this API is invoked.
463 * @controller: This parameter represents the controller which contains the
464 * port.
465 * @port: This parameter specifies the SCI port object for which the callback
466 * is being invoked.
467 * @phy: This parameter specifies the phy that came ready, but the phy can't be
468 * a valid member of the port.
469 *
470 */
471 void isci_port_invalid_link_up(struct scic_sds_controller *scic,
472 struct scic_sds_port *sci_port,
473 struct scic_sds_phy *phy)
474 {
475 struct isci_host *ihost = sci_object_get_association(scic);
476
477 dev_warn(&ihost->pdev->dev, "Invalid link up!\n");
478 }
479
480 void isci_port_stop_complete(struct scic_sds_controller *scic,
481 struct scic_sds_port *sci_port,
482 enum sci_status completion_status)
483 {
484 struct isci_host *ihost = sci_object_get_association(scic);
485
486 dev_dbg(&ihost->pdev->dev, "Port stop complete\n");
487 }
This page took 0.040761 seconds and 5 git commands to generate.