isci: unify isci_host and scic_sds_controller
[pandora-kernel.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 #include "isci.h"
57 #include "port.h"
58 #include "request.h"
59
60 #define SCIC_SDS_PORT_HARD_RESET_TIMEOUT  (1000)
61 #define SCU_DUMMY_INDEX    (0xFFFF)
62
63 static void isci_port_change_state(struct isci_port *iport, enum isci_status status)
64 {
65         unsigned long flags;
66
67         dev_dbg(&iport->isci_host->pdev->dev,
68                 "%s: iport = %p, state = 0x%x\n",
69                 __func__, iport, status);
70
71         /* XXX pointless lock */
72         spin_lock_irqsave(&iport->state_lock, flags);
73         iport->status = status;
74         spin_unlock_irqrestore(&iport->state_lock, flags);
75 }
76
77 /*
78  * This function will indicate which protocols are supported by this port.
79  * @sci_port: a handle corresponding to the SAS port for which to return the
80  *    supported protocols.
81  * @protocols: This parameter specifies a pointer to a data structure
82  *    which the core will copy the protocol values for the port from the
83  *    transmit_identification register.
84  */
85 static void
86 scic_sds_port_get_protocols(struct isci_port *iport,
87                             struct scic_phy_proto *protocols)
88 {
89         u8 index;
90
91         protocols->all = 0;
92
93         for (index = 0; index < SCI_MAX_PHYS; index++) {
94                 if (iport->phy_table[index] != NULL) {
95                         scic_sds_phy_get_protocols(iport->phy_table[index],
96                                                    protocols);
97                 }
98         }
99 }
100
101 /**
102  * This method requests a list (mask) of the phys contained in the supplied SAS
103  *    port.
104  * @sci_port: a handle corresponding to the SAS port for which to return the
105  *    phy mask.
106  *
107  * Return a bit mask indicating which phys are a part of this port. Each bit
108  * corresponds to a phy identifier (e.g. bit 0 = phy id 0).
109  */
110 static u32 scic_sds_port_get_phys(struct isci_port *iport)
111 {
112         u32 index;
113         u32 mask;
114
115         mask = 0;
116
117         for (index = 0; index < SCI_MAX_PHYS; index++) {
118                 if (iport->phy_table[index] != NULL) {
119                         mask |= (1 << index);
120                 }
121         }
122
123         return mask;
124 }
125
126 /**
127  * scic_port_get_properties() - This method simply returns the properties
128  *    regarding the port, such as: physical index, protocols, sas address, etc.
129  * @port: this parameter specifies the port for which to retrieve the physical
130  *    index.
131  * @properties: This parameter specifies the properties structure into which to
132  *    copy the requested information.
133  *
134  * Indicate if the user specified a valid port. SCI_SUCCESS This value is
135  * returned if the specified port was valid. SCI_FAILURE_INVALID_PORT This
136  * value is returned if the specified port is not valid.  When this value is
137  * returned, no data is copied to the properties output parameter.
138  */
139 static enum sci_status scic_port_get_properties(struct isci_port *iport,
140                                                 struct scic_port_properties *prop)
141 {
142         if (!iport || iport->logical_port_index == SCIC_SDS_DUMMY_PORT)
143                 return SCI_FAILURE_INVALID_PORT;
144
145         prop->index    = iport->logical_port_index;
146         prop->phy_mask = scic_sds_port_get_phys(iport);
147         scic_sds_port_get_sas_address(iport, &prop->local.sas_address);
148         scic_sds_port_get_protocols(iport, &prop->local.protocols);
149         scic_sds_port_get_attached_sas_address(iport, &prop->remote.sas_address);
150
151         return SCI_SUCCESS;
152 }
153
154 static void scic_port_bcn_enable(struct isci_port *iport)
155 {
156         struct isci_phy *iphy;
157         u32 val;
158         int i;
159
160         for (i = 0; i < ARRAY_SIZE(iport->phy_table); i++) {
161                 iphy = iport->phy_table[i];
162                 if (!iphy)
163                         continue;
164                 val = readl(&iphy->link_layer_registers->link_layer_control);
165                 /* clear the bit by writing 1. */
166                 writel(val, &iphy->link_layer_registers->link_layer_control);
167         }
168 }
169
170 /* called under scic_lock to stabilize phy:port associations */
171 void isci_port_bcn_enable(struct isci_host *ihost, struct isci_port *iport)
172 {
173         int i;
174
175         clear_bit(IPORT_BCN_BLOCKED, &iport->flags);
176         wake_up(&ihost->eventq);
177
178         if (!test_and_clear_bit(IPORT_BCN_PENDING, &iport->flags))
179                 return;
180
181         for (i = 0; i < ARRAY_SIZE(iport->phy_table); i++) {
182                 struct isci_phy *iphy = iport->phy_table[i];
183
184                 if (!iphy)
185                         continue;
186
187                 ihost->sas_ha.notify_port_event(&iphy->sas_phy,
188                                                 PORTE_BROADCAST_RCVD);
189                 break;
190         }
191 }
192
193 static void isci_port_bc_change_received(struct isci_host *ihost,
194                                          struct isci_port *iport,
195                                          struct isci_phy *iphy)
196 {
197         if (iport && test_bit(IPORT_BCN_BLOCKED, &iport->flags)) {
198                 dev_dbg(&ihost->pdev->dev,
199                         "%s: disabled BCN; isci_phy = %p, sas_phy = %p\n",
200                         __func__, iphy, &iphy->sas_phy);
201                 set_bit(IPORT_BCN_PENDING, &iport->flags);
202                 atomic_inc(&iport->event);
203                 wake_up(&ihost->eventq);
204         } else {
205                 dev_dbg(&ihost->pdev->dev,
206                         "%s: isci_phy = %p, sas_phy = %p\n",
207                         __func__, iphy, &iphy->sas_phy);
208
209                 ihost->sas_ha.notify_port_event(&iphy->sas_phy,
210                                                 PORTE_BROADCAST_RCVD);
211         }
212         scic_port_bcn_enable(iport);
213 }
214
215 static void isci_port_link_up(struct isci_host *isci_host,
216                               struct isci_port *iport,
217                               struct isci_phy *iphy)
218 {
219         unsigned long flags;
220         struct scic_port_properties properties;
221         unsigned long success = true;
222
223         BUG_ON(iphy->isci_port != NULL);
224
225         iphy->isci_port = iport;
226
227         dev_dbg(&isci_host->pdev->dev,
228                 "%s: isci_port = %p\n",
229                 __func__, iport);
230
231         spin_lock_irqsave(&iphy->sas_phy.frame_rcvd_lock, flags);
232
233         isci_port_change_state(iphy->isci_port, isci_starting);
234
235         scic_port_get_properties(iport, &properties);
236
237         if (iphy->protocol == SCIC_SDS_PHY_PROTOCOL_SATA) {
238                 u64 attached_sas_address;
239
240                 iphy->sas_phy.oob_mode = SATA_OOB_MODE;
241                 iphy->sas_phy.frame_rcvd_size = sizeof(struct dev_to_host_fis);
242
243                 /*
244                  * For direct-attached SATA devices, the SCI core will
245                  * automagically assign a SAS address to the end device
246                  * for the purpose of creating a port. This SAS address
247                  * will not be the same as assigned to the PHY and needs
248                  * to be obtained from struct scic_port_properties properties.
249                  */
250                 attached_sas_address = properties.remote.sas_address.high;
251                 attached_sas_address <<= 32;
252                 attached_sas_address |= properties.remote.sas_address.low;
253                 swab64s(&attached_sas_address);
254
255                 memcpy(&iphy->sas_phy.attached_sas_addr,
256                        &attached_sas_address, sizeof(attached_sas_address));
257         } else if (iphy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) {
258                 iphy->sas_phy.oob_mode = SAS_OOB_MODE;
259                 iphy->sas_phy.frame_rcvd_size = sizeof(struct sas_identify_frame);
260
261                 /* Copy the attached SAS address from the IAF */
262                 memcpy(iphy->sas_phy.attached_sas_addr,
263                        iphy->frame_rcvd.iaf.sas_addr, SAS_ADDR_SIZE);
264         } else {
265                 dev_err(&isci_host->pdev->dev, "%s: unkown target\n", __func__);
266                 success = false;
267         }
268
269         iphy->sas_phy.phy->negotiated_linkrate = sci_phy_linkrate(iphy);
270
271         spin_unlock_irqrestore(&iphy->sas_phy.frame_rcvd_lock, flags);
272
273         /* Notify libsas that we have an address frame, if indeed
274          * we've found an SSP, SMP, or STP target */
275         if (success)
276                 isci_host->sas_ha.notify_port_event(&iphy->sas_phy,
277                                                     PORTE_BYTES_DMAED);
278 }
279
280
281 /**
282  * isci_port_link_down() - This function is called by the sci core when a link
283  *    becomes inactive.
284  * @isci_host: This parameter specifies the isci host object.
285  * @phy: This parameter specifies the isci phy with the active link.
286  * @port: This parameter specifies the isci port with the active link.
287  *
288  */
289 static void isci_port_link_down(struct isci_host *isci_host,
290                                 struct isci_phy *isci_phy,
291                                 struct isci_port *isci_port)
292 {
293         struct isci_remote_device *isci_device;
294
295         dev_dbg(&isci_host->pdev->dev,
296                 "%s: isci_port = %p\n", __func__, isci_port);
297
298         if (isci_port) {
299
300                 /* check to see if this is the last phy on this port. */
301                 if (isci_phy->sas_phy.port &&
302                     isci_phy->sas_phy.port->num_phys == 1) {
303                         atomic_inc(&isci_port->event);
304                         isci_port_bcn_enable(isci_host, isci_port);
305
306                         /* change the state for all devices on this port.  The
307                          * next task sent to this device will be returned as
308                          * SAS_TASK_UNDELIVERED, and the scsi mid layer will
309                          * remove the target
310                          */
311                         list_for_each_entry(isci_device,
312                                             &isci_port->remote_dev_list,
313                                             node) {
314                                 dev_dbg(&isci_host->pdev->dev,
315                                         "%s: isci_device = %p\n",
316                                         __func__, isci_device);
317                                 set_bit(IDEV_GONE, &isci_device->flags);
318                         }
319                 }
320                 isci_port_change_state(isci_port, isci_stopping);
321         }
322
323         /* Notify libsas of the borken link, this will trigger calls to our
324          * isci_port_deformed and isci_dev_gone functions.
325          */
326         sas_phy_disconnected(&isci_phy->sas_phy);
327         isci_host->sas_ha.notify_phy_event(&isci_phy->sas_phy,
328                                            PHYE_LOSS_OF_SIGNAL);
329
330         isci_phy->isci_port = NULL;
331
332         dev_dbg(&isci_host->pdev->dev,
333                 "%s: isci_port = %p - Done\n", __func__, isci_port);
334 }
335
336
337 /**
338  * isci_port_ready() - This function is called by the sci core when a link
339  *    becomes ready.
340  * @isci_host: This parameter specifies the isci host object.
341  * @port: This parameter specifies the sci port with the active link.
342  *
343  */
344 static void isci_port_ready(struct isci_host *isci_host, struct isci_port *isci_port)
345 {
346         dev_dbg(&isci_host->pdev->dev,
347                 "%s: isci_port = %p\n", __func__, isci_port);
348
349         complete_all(&isci_port->start_complete);
350         isci_port_change_state(isci_port, isci_ready);
351         return;
352 }
353
354 /**
355  * isci_port_not_ready() - This function is called by the sci core when a link
356  *    is not ready. All remote devices on this link will be removed if they are
357  *    in the stopping state.
358  * @isci_host: This parameter specifies the isci host object.
359  * @port: This parameter specifies the sci port with the active link.
360  *
361  */
362 static void isci_port_not_ready(struct isci_host *isci_host, struct isci_port *isci_port)
363 {
364         dev_dbg(&isci_host->pdev->dev,
365                 "%s: isci_port = %p\n", __func__, isci_port);
366 }
367
368 static void isci_port_stop_complete(struct isci_host *ihost,
369                                     struct isci_port *iport,
370                                     enum sci_status completion_status)
371 {
372         dev_dbg(&ihost->pdev->dev, "Port stop complete\n");
373 }
374
375 /**
376  * isci_port_hard_reset_complete() - This function is called by the sci core
377  *    when the hard reset complete notification has been received.
378  * @port: This parameter specifies the sci port with the active link.
379  * @completion_status: This parameter specifies the core status for the reset
380  *    process.
381  *
382  */
383 static void isci_port_hard_reset_complete(struct isci_port *isci_port,
384                                           enum sci_status completion_status)
385 {
386         dev_dbg(&isci_port->isci_host->pdev->dev,
387                 "%s: isci_port = %p, completion_status=%x\n",
388                      __func__, isci_port, completion_status);
389
390         /* Save the status of the hard reset from the port. */
391         isci_port->hard_reset_status = completion_status;
392
393         complete_all(&isci_port->hard_reset_complete);
394 }
395
396 /* This method will return a true value if the specified phy can be assigned to
397  * this port The following is a list of phys for each port that are allowed: -
398  * Port 0 - 3 2 1 0 - Port 1 -     1 - Port 2 - 3 2 - Port 3 - 3 This method
399  * doesn't preclude all configurations.  It merely ensures that a phy is part
400  * of the allowable set of phy identifiers for that port.  For example, one
401  * could assign phy 3 to port 0 and no other phys.  Please refer to
402  * scic_sds_port_is_phy_mask_valid() for information regarding whether the
403  * phy_mask for a port can be supported. bool true if this is a valid phy
404  * assignment for the port false if this is not a valid phy assignment for the
405  * port
406  */
407 bool scic_sds_port_is_valid_phy_assignment(struct isci_port *iport,
408                                            u32 phy_index)
409 {
410         /* Initialize to invalid value. */
411         u32 existing_phy_index = SCI_MAX_PHYS;
412         u32 index;
413
414         if ((iport->physical_port_index == 1) && (phy_index != 1)) {
415                 return false;
416         }
417
418         if (iport->physical_port_index == 3 && phy_index != 3) {
419                 return false;
420         }
421
422         if (
423                 (iport->physical_port_index == 2)
424                 && ((phy_index == 0) || (phy_index == 1))
425                 ) {
426                 return false;
427         }
428
429         for (index = 0; index < SCI_MAX_PHYS; index++) {
430                 if ((iport->phy_table[index] != NULL)
431                     && (index != phy_index)) {
432                         existing_phy_index = index;
433                 }
434         }
435
436         /*
437          * Ensure that all of the phys in the port are capable of
438          * operating at the same maximum link rate. */
439         if (
440                 (existing_phy_index < SCI_MAX_PHYS)
441                 && (iport->owning_controller->user_parameters.sds1.phys[
442                             phy_index].max_speed_generation !=
443                     iport->owning_controller->user_parameters.sds1.phys[
444                             existing_phy_index].max_speed_generation)
445                 )
446                 return false;
447
448         return true;
449 }
450
451 /**
452  *
453  * @sci_port: This is the port object for which to determine if the phy mask
454  *    can be supported.
455  *
456  * This method will return a true value if the port's phy mask can be supported
457  * by the SCU. The following is a list of valid PHY mask configurations for
458  * each port: - Port 0 - [[3  2] 1] 0 - Port 1 -        [1] - Port 2 - [[3] 2]
459  * - Port 3 -  [3] This method returns a boolean indication specifying if the
460  * phy mask can be supported. true if this is a valid phy assignment for the
461  * port false if this is not a valid phy assignment for the port
462  */
463 static bool scic_sds_port_is_phy_mask_valid(
464         struct isci_port *iport,
465         u32 phy_mask)
466 {
467         if (iport->physical_port_index == 0) {
468                 if (((phy_mask & 0x0F) == 0x0F)
469                     || ((phy_mask & 0x03) == 0x03)
470                     || ((phy_mask & 0x01) == 0x01)
471                     || (phy_mask == 0))
472                         return true;
473         } else if (iport->physical_port_index == 1) {
474                 if (((phy_mask & 0x02) == 0x02)
475                     || (phy_mask == 0))
476                         return true;
477         } else if (iport->physical_port_index == 2) {
478                 if (((phy_mask & 0x0C) == 0x0C)
479                     || ((phy_mask & 0x04) == 0x04)
480                     || (phy_mask == 0))
481                         return true;
482         } else if (iport->physical_port_index == 3) {
483                 if (((phy_mask & 0x08) == 0x08)
484                     || (phy_mask == 0))
485                         return true;
486         }
487
488         return false;
489 }
490
491 /*
492  * This method retrieves a currently active (i.e. connected) phy contained in
493  * the port.  Currently, the lowest order phy that is connected is returned.
494  * This method returns a pointer to a SCIS_SDS_PHY object. NULL This value is
495  * returned if there are no currently active (i.e. connected to a remote end
496  * point) phys contained in the port. All other values specify a struct scic_sds_phy
497  * object that is active in the port.
498  */
499 static struct isci_phy *scic_sds_port_get_a_connected_phy(struct isci_port *iport)
500 {
501         u32 index;
502         struct isci_phy *iphy;
503
504         for (index = 0; index < SCI_MAX_PHYS; index++) {
505                 /* Ensure that the phy is both part of the port and currently
506                  * connected to the remote end-point.
507                  */
508                 iphy = iport->phy_table[index];
509                 if (iphy && scic_sds_port_active_phy(iport, iphy))
510                         return iphy;
511         }
512
513         return NULL;
514 }
515
516 static enum sci_status scic_sds_port_set_phy(struct isci_port *iport, struct isci_phy *iphy)
517 {
518         /* Check to see if we can add this phy to a port
519          * that means that the phy is not part of a port and that the port does
520          * not already have a phy assinged to the phy index.
521          */
522         if (!iport->phy_table[iphy->phy_index] &&
523             !phy_get_non_dummy_port(iphy) &&
524             scic_sds_port_is_valid_phy_assignment(iport, iphy->phy_index)) {
525                 /* Phy is being added in the stopped state so we are in MPC mode
526                  * make logical port index = physical port index
527                  */
528                 iport->logical_port_index = iport->physical_port_index;
529                 iport->phy_table[iphy->phy_index] = iphy;
530                 scic_sds_phy_set_port(iphy, iport);
531
532                 return SCI_SUCCESS;
533         }
534
535         return SCI_FAILURE;
536 }
537
538 static enum sci_status scic_sds_port_clear_phy(struct isci_port *iport,
539                                                struct isci_phy *iphy)
540 {
541         /* Make sure that this phy is part of this port */
542         if (iport->phy_table[iphy->phy_index] == iphy &&
543             phy_get_non_dummy_port(iphy) == iport) {
544                 struct isci_host *ihost = iport->owning_controller;
545
546                 /* Yep it is assigned to this port so remove it */
547                 scic_sds_phy_set_port(iphy, &ihost->ports[SCI_MAX_PORTS]);
548                 iport->phy_table[iphy->phy_index] = NULL;
549                 return SCI_SUCCESS;
550         }
551
552         return SCI_FAILURE;
553 }
554
555
556 /**
557  * This method requests the SAS address for the supplied SAS port from the SCI
558  *    implementation.
559  * @sci_port: a handle corresponding to the SAS port for which to return the
560  *    SAS address.
561  * @sas_address: This parameter specifies a pointer to a SAS address structure
562  *    into which the core will copy the SAS address for the port.
563  *
564  */
565 void scic_sds_port_get_sas_address(
566         struct isci_port *iport,
567         struct sci_sas_address *sas_address)
568 {
569         u32 index;
570
571         sas_address->high = 0;
572         sas_address->low  = 0;
573
574         for (index = 0; index < SCI_MAX_PHYS; index++) {
575                 if (iport->phy_table[index] != NULL) {
576                         scic_sds_phy_get_sas_address(iport->phy_table[index], sas_address);
577                 }
578         }
579 }
580
581 /*
582  * This function requests the SAS address for the device directly attached to
583  *    this SAS port.
584  * @sci_port: a handle corresponding to the SAS port for which to return the
585  *    SAS address.
586  * @sas_address: This parameter specifies a pointer to a SAS address structure
587  *    into which the core will copy the SAS address for the device directly
588  *    attached to the port.
589  *
590  */
591 void scic_sds_port_get_attached_sas_address(
592         struct isci_port *iport,
593         struct sci_sas_address *sas_address)
594 {
595         struct isci_phy *iphy;
596
597         /*
598          * Ensure that the phy is both part of the port and currently
599          * connected to the remote end-point.
600          */
601         iphy = scic_sds_port_get_a_connected_phy(iport);
602         if (iphy) {
603                 if (iphy->protocol != SCIC_SDS_PHY_PROTOCOL_SATA) {
604                         scic_sds_phy_get_attached_sas_address(iphy,
605                                                               sas_address);
606                 } else {
607                         scic_sds_phy_get_sas_address(iphy, sas_address);
608                         sas_address->low += iphy->phy_index;
609                 }
610         } else {
611                 sas_address->high = 0;
612                 sas_address->low  = 0;
613         }
614 }
615
616 /**
617  * scic_sds_port_construct_dummy_rnc() - create dummy rnc for si workaround
618  *
619  * @sci_port: logical port on which we need to create the remote node context
620  * @rni: remote node index for this remote node context.
621  *
622  * This routine will construct a dummy remote node context data structure
623  * This structure will be posted to the hardware to work around a scheduler
624  * error in the hardware.
625  */
626 static void scic_sds_port_construct_dummy_rnc(struct isci_port *iport, u16 rni)
627 {
628         union scu_remote_node_context *rnc;
629
630         rnc = &iport->owning_controller->remote_node_context_table[rni];
631
632         memset(rnc, 0, sizeof(union scu_remote_node_context));
633
634         rnc->ssp.remote_sas_address_hi = 0;
635         rnc->ssp.remote_sas_address_lo = 0;
636
637         rnc->ssp.remote_node_index = rni;
638         rnc->ssp.remote_node_port_width = 1;
639         rnc->ssp.logical_port_index = iport->physical_port_index;
640
641         rnc->ssp.nexus_loss_timer_enable = false;
642         rnc->ssp.check_bit = false;
643         rnc->ssp.is_valid = true;
644         rnc->ssp.is_remote_node_context = true;
645         rnc->ssp.function_number = 0;
646         rnc->ssp.arbitration_wait_time = 0;
647 }
648
649 /*
650  * construct a dummy task context data structure.  This
651  * structure will be posted to the hardwre to work around a scheduler error
652  * in the hardware.
653  */
654 static void scic_sds_port_construct_dummy_task(struct isci_port *iport, u16 tag)
655 {
656         struct isci_host *ihost = iport->owning_controller;
657         struct scu_task_context *task_context;
658
659         task_context = &ihost->task_context_table[ISCI_TAG_TCI(tag)];
660         memset(task_context, 0, sizeof(struct scu_task_context));
661
662         task_context->initiator_request = 1;
663         task_context->connection_rate = 1;
664         task_context->logical_port_index = iport->physical_port_index;
665         task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SSP;
666         task_context->task_index = ISCI_TAG_TCI(tag);
667         task_context->valid = SCU_TASK_CONTEXT_VALID;
668         task_context->context_type = SCU_TASK_CONTEXT_TYPE;
669         task_context->remote_node_index = iport->reserved_rni;
670         task_context->do_not_dma_ssp_good_response = 1;
671         task_context->task_phase = 0x01;
672 }
673
674 static void scic_sds_port_destroy_dummy_resources(struct isci_port *iport)
675 {
676         struct isci_host *ihost = iport->owning_controller;
677
678         if (iport->reserved_tag != SCI_CONTROLLER_INVALID_IO_TAG)
679                 isci_free_tag(ihost, iport->reserved_tag);
680
681         if (iport->reserved_rni != SCU_DUMMY_INDEX)
682                 scic_sds_remote_node_table_release_remote_node_index(&ihost->available_remote_nodes,
683                                                                      1, iport->reserved_rni);
684
685         iport->reserved_rni = SCU_DUMMY_INDEX;
686         iport->reserved_tag = SCI_CONTROLLER_INVALID_IO_TAG;
687 }
688
689 /**
690  * This method performs initialization of the supplied port. Initialization
691  *    includes: - state machine initialization - member variable initialization
692  *    - configuring the phy_mask
693  * @sci_port:
694  * @transport_layer_registers:
695  * @port_task_scheduler_registers:
696  * @port_configuration_regsiter:
697  *
698  * enum sci_status SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION This value is returned
699  * if the phy being added to the port
700  */
701 enum sci_status scic_sds_port_initialize(
702         struct isci_port *iport,
703         void __iomem *port_task_scheduler_registers,
704         void __iomem *port_configuration_regsiter,
705         void __iomem *viit_registers)
706 {
707         iport->port_task_scheduler_registers  = port_task_scheduler_registers;
708         iport->port_pe_configuration_register = port_configuration_regsiter;
709         iport->viit_registers                 = viit_registers;
710
711         return SCI_SUCCESS;
712 }
713
714
715 /**
716  * This method assigns the direct attached device ID for this port.
717  *
718  * @param[in] iport The port for which the direct attached device id is to
719  *       be assigned.
720  * @param[in] device_id The direct attached device ID to assign to the port.
721  *       This will be the RNi for the device
722  */
723 void scic_sds_port_setup_transports(
724         struct isci_port *iport,
725         u32 device_id)
726 {
727         u8 index;
728
729         for (index = 0; index < SCI_MAX_PHYS; index++) {
730                 if (iport->active_phy_mask & (1 << index))
731                         scic_sds_phy_setup_transport(iport->phy_table[index], device_id);
732         }
733 }
734
735 /**
736  *
737  * @sci_port: This is the port on which the phy should be enabled.
738  * @sci_phy: This is the specific phy which to enable.
739  * @do_notify_user: This parameter specifies whether to inform the user (via
740  *    scic_cb_port_link_up()) as to the fact that a new phy as become ready.
741  *
742  * This function will activate the phy in the port.
743  * Activation includes: - adding
744  * the phy to the port - enabling the Protocol Engine in the silicon. -
745  * notifying the user that the link is up. none
746  */
747 static void scic_sds_port_activate_phy(struct isci_port *iport,
748                                        struct isci_phy *iphy,
749                                        bool do_notify_user)
750 {
751         struct isci_host *ihost = iport->owning_controller;
752
753         if (iphy->protocol != SCIC_SDS_PHY_PROTOCOL_SATA)
754                 scic_sds_phy_resume(iphy);
755
756         iport->active_phy_mask |= 1 << iphy->phy_index;
757
758         scic_sds_controller_clear_invalid_phy(ihost, iphy);
759
760         if (do_notify_user == true)
761                 isci_port_link_up(ihost, iport, iphy);
762 }
763
764 void scic_sds_port_deactivate_phy(struct isci_port *iport,
765                                   struct isci_phy *iphy,
766                                   bool do_notify_user)
767 {
768         struct isci_host *ihost = scic_sds_port_get_controller(iport);
769
770         iport->active_phy_mask &= ~(1 << iphy->phy_index);
771
772         iphy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN;
773
774         /* Re-assign the phy back to the LP as if it were a narrow port */
775         writel(iphy->phy_index,
776                 &iport->port_pe_configuration_register[iphy->phy_index]);
777
778         if (do_notify_user == true)
779                 isci_port_link_down(ihost, iphy, iport);
780 }
781
782 /**
783  *
784  * @sci_port: This is the port on which the phy should be disabled.
785  * @sci_phy: This is the specific phy which to disabled.
786  *
787  * This function will disable the phy and report that the phy is not valid for
788  * this port object. None
789  */
790 static void scic_sds_port_invalid_link_up(struct isci_port *iport,
791                                           struct isci_phy *iphy)
792 {
793         struct isci_host *ihost = iport->owning_controller;
794
795         /*
796          * Check to see if we have alreay reported this link as bad and if
797          * not go ahead and tell the SCI_USER that we have discovered an
798          * invalid link.
799          */
800         if ((ihost->invalid_phy_mask & (1 << iphy->phy_index)) == 0) {
801                 scic_sds_controller_set_invalid_phy(ihost, iphy);
802                 dev_warn(&ihost->pdev->dev, "Invalid link up!\n");
803         }
804 }
805
806 static bool is_port_ready_state(enum scic_sds_port_states state)
807 {
808         switch (state) {
809         case SCI_PORT_READY:
810         case SCI_PORT_SUB_WAITING:
811         case SCI_PORT_SUB_OPERATIONAL:
812         case SCI_PORT_SUB_CONFIGURING:
813                 return true;
814         default:
815                 return false;
816         }
817 }
818
819 /* flag dummy rnc hanling when exiting a ready state */
820 static void port_state_machine_change(struct isci_port *iport,
821                                       enum scic_sds_port_states state)
822 {
823         struct sci_base_state_machine *sm = &iport->sm;
824         enum scic_sds_port_states old_state = sm->current_state_id;
825
826         if (is_port_ready_state(old_state) && !is_port_ready_state(state))
827                 iport->ready_exit = true;
828
829         sci_change_state(sm, state);
830         iport->ready_exit = false;
831 }
832
833 /**
834  * scic_sds_port_general_link_up_handler - phy can be assigned to port?
835  * @sci_port: scic_sds_port object for which has a phy that has gone link up.
836  * @sci_phy: This is the struct isci_phy object that has gone link up.
837  * @do_notify_user: This parameter specifies whether to inform the user (via
838  *    scic_cb_port_link_up()) as to the fact that a new phy as become ready.
839  *
840  * Determine if this phy can be assigned to this
841  * port . If the phy is not a valid PHY for
842  * this port then the function will notify the user. A PHY can only be
843  * part of a port if it's attached SAS ADDRESS is the same as all other PHYs in
844  * the same port. none
845  */
846 static void scic_sds_port_general_link_up_handler(struct isci_port *iport,
847                                                   struct isci_phy *iphy,
848                                                   bool do_notify_user)
849 {
850         struct sci_sas_address port_sas_address;
851         struct sci_sas_address phy_sas_address;
852
853         scic_sds_port_get_attached_sas_address(iport, &port_sas_address);
854         scic_sds_phy_get_attached_sas_address(iphy, &phy_sas_address);
855
856         /* If the SAS address of the new phy matches the SAS address of
857          * other phys in the port OR this is the first phy in the port,
858          * then activate the phy and allow it to be used for operations
859          * in this port.
860          */
861         if ((phy_sas_address.high == port_sas_address.high &&
862              phy_sas_address.low  == port_sas_address.low) ||
863             iport->active_phy_mask == 0) {
864                 struct sci_base_state_machine *sm = &iport->sm;
865
866                 scic_sds_port_activate_phy(iport, iphy, do_notify_user);
867                 if (sm->current_state_id == SCI_PORT_RESETTING)
868                         port_state_machine_change(iport, SCI_PORT_READY);
869         } else
870                 scic_sds_port_invalid_link_up(iport, iphy);
871 }
872
873
874
875 /**
876  * This method returns false if the port only has a single phy object assigned.
877  *     If there are no phys or more than one phy then the method will return
878  *    true.
879  * @sci_port: The port for which the wide port condition is to be checked.
880  *
881  * bool true Is returned if this is a wide ported port. false Is returned if
882  * this is a narrow port.
883  */
884 static bool scic_sds_port_is_wide(struct isci_port *iport)
885 {
886         u32 index;
887         u32 phy_count = 0;
888
889         for (index = 0; index < SCI_MAX_PHYS; index++) {
890                 if (iport->phy_table[index] != NULL) {
891                         phy_count++;
892                 }
893         }
894
895         return phy_count != 1;
896 }
897
898 /**
899  * This method is called by the PHY object when the link is detected. if the
900  *    port wants the PHY to continue on to the link up state then the port
901  *    layer must return true.  If the port object returns false the phy object
902  *    must halt its attempt to go link up.
903  * @sci_port: The port associated with the phy object.
904  * @sci_phy: The phy object that is trying to go link up.
905  *
906  * true if the phy object can continue to the link up condition. true Is
907  * returned if this phy can continue to the ready state. false Is returned if
908  * can not continue on to the ready state. This notification is in place for
909  * wide ports and direct attached phys.  Since there are no wide ported SATA
910  * devices this could become an invalid port configuration.
911  */
912 bool scic_sds_port_link_detected(
913         struct isci_port *iport,
914         struct isci_phy *iphy)
915 {
916         if ((iport->logical_port_index != SCIC_SDS_DUMMY_PORT) &&
917             (iphy->protocol == SCIC_SDS_PHY_PROTOCOL_SATA) &&
918             scic_sds_port_is_wide(iport)) {
919                 scic_sds_port_invalid_link_up(iport, iphy);
920
921                 return false;
922         }
923
924         return true;
925 }
926
927 static void port_timeout(unsigned long data)
928 {
929         struct sci_timer *tmr = (struct sci_timer *)data;
930         struct isci_port *iport = container_of(tmr, typeof(*iport), timer);
931         struct isci_host *ihost = iport->owning_controller;
932         unsigned long flags;
933         u32 current_state;
934
935         spin_lock_irqsave(&ihost->scic_lock, flags);
936
937         if (tmr->cancel)
938                 goto done;
939
940         current_state = iport->sm.current_state_id;
941
942         if (current_state == SCI_PORT_RESETTING) {
943                 /* if the port is still in the resetting state then the timeout
944                  * fired before the reset completed.
945                  */
946                 port_state_machine_change(iport, SCI_PORT_FAILED);
947         } else if (current_state == SCI_PORT_STOPPED) {
948                 /* if the port is stopped then the start request failed In this
949                  * case stay in the stopped state.
950                  */
951                 dev_err(sciport_to_dev(iport),
952                         "%s: SCIC Port 0x%p failed to stop before tiemout.\n",
953                         __func__,
954                         iport);
955         } else if (current_state == SCI_PORT_STOPPING) {
956                 /* if the port is still stopping then the stop has not completed */
957                 isci_port_stop_complete(iport->owning_controller,
958                                         iport,
959                                         SCI_FAILURE_TIMEOUT);
960         } else {
961                 /* The port is in the ready state and we have a timer
962                  * reporting a timeout this should not happen.
963                  */
964                 dev_err(sciport_to_dev(iport),
965                         "%s: SCIC Port 0x%p is processing a timeout operation "
966                         "in state %d.\n", __func__, iport, current_state);
967         }
968
969 done:
970         spin_unlock_irqrestore(&ihost->scic_lock, flags);
971 }
972
973 /* --------------------------------------------------------------------------- */
974
975 /**
976  * This function updates the hardwares VIIT entry for this port.
977  *
978  *
979  */
980 static void scic_sds_port_update_viit_entry(struct isci_port *iport)
981 {
982         struct sci_sas_address sas_address;
983
984         scic_sds_port_get_sas_address(iport, &sas_address);
985
986         writel(sas_address.high,
987                 &iport->viit_registers->initiator_sas_address_hi);
988         writel(sas_address.low,
989                 &iport->viit_registers->initiator_sas_address_lo);
990
991         /* This value get cleared just in case its not already cleared */
992         writel(0, &iport->viit_registers->reserved);
993
994         /* We are required to update the status register last */
995         writel(SCU_VIIT_ENTRY_ID_VIIT |
996                SCU_VIIT_IPPT_INITIATOR |
997                ((1 << iport->physical_port_index) << SCU_VIIT_ENTRY_LPVIE_SHIFT) |
998                SCU_VIIT_STATUS_ALL_VALID,
999                &iport->viit_registers->status);
1000 }
1001
1002 enum sas_linkrate scic_sds_port_get_max_allowed_speed(struct isci_port *iport)
1003 {
1004         u16 index;
1005         struct isci_phy *iphy;
1006         enum sas_linkrate max_allowed_speed = SAS_LINK_RATE_6_0_GBPS;
1007
1008         /*
1009          * Loop through all of the phys in this port and find the phy with the
1010          * lowest maximum link rate. */
1011         for (index = 0; index < SCI_MAX_PHYS; index++) {
1012                 iphy = iport->phy_table[index];
1013                 if (iphy && scic_sds_port_active_phy(iport, iphy) &&
1014                     iphy->max_negotiated_speed < max_allowed_speed)
1015                         max_allowed_speed = iphy->max_negotiated_speed;
1016         }
1017
1018         return max_allowed_speed;
1019 }
1020
1021 static void scic_sds_port_suspend_port_task_scheduler(struct isci_port *iport)
1022 {
1023         u32 pts_control_value;
1024
1025         pts_control_value = readl(&iport->port_task_scheduler_registers->control);
1026         pts_control_value |= SCU_PTSxCR_GEN_BIT(SUSPEND);
1027         writel(pts_control_value, &iport->port_task_scheduler_registers->control);
1028 }
1029
1030 /**
1031  * scic_sds_port_post_dummy_request() - post dummy/workaround request
1032  * @sci_port: port to post task
1033  *
1034  * Prevent the hardware scheduler from posting new requests to the front
1035  * of the scheduler queue causing a starvation problem for currently
1036  * ongoing requests.
1037  *
1038  */
1039 static void scic_sds_port_post_dummy_request(struct isci_port *iport)
1040 {
1041         struct isci_host *ihost = iport->owning_controller;
1042         u16 tag = iport->reserved_tag;
1043         struct scu_task_context *tc;
1044         u32 command;
1045
1046         tc = &ihost->task_context_table[ISCI_TAG_TCI(tag)];
1047         tc->abort = 0;
1048
1049         command = SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
1050                   iport->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT |
1051                   ISCI_TAG_TCI(tag);
1052
1053         scic_sds_controller_post_request(ihost, command);
1054 }
1055
1056 /**
1057  * This routine will abort the dummy request.  This will alow the hardware to
1058  * power down parts of the silicon to save power.
1059  *
1060  * @sci_port: The port on which the task must be aborted.
1061  *
1062  */
1063 static void scic_sds_port_abort_dummy_request(struct isci_port *iport)
1064 {
1065         struct isci_host *ihost = iport->owning_controller;
1066         u16 tag = iport->reserved_tag;
1067         struct scu_task_context *tc;
1068         u32 command;
1069
1070         tc = &ihost->task_context_table[ISCI_TAG_TCI(tag)];
1071         tc->abort = 1;
1072
1073         command = SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT |
1074                   iport->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT |
1075                   ISCI_TAG_TCI(tag);
1076
1077         scic_sds_controller_post_request(ihost, command);
1078 }
1079
1080 /**
1081  *
1082  * @sci_port: This is the struct isci_port object to resume.
1083  *
1084  * This method will resume the port task scheduler for this port object. none
1085  */
1086 static void
1087 scic_sds_port_resume_port_task_scheduler(struct isci_port *iport)
1088 {
1089         u32 pts_control_value;
1090
1091         pts_control_value = readl(&iport->port_task_scheduler_registers->control);
1092         pts_control_value &= ~SCU_PTSxCR_GEN_BIT(SUSPEND);
1093         writel(pts_control_value, &iport->port_task_scheduler_registers->control);
1094 }
1095
1096 static void scic_sds_port_ready_substate_waiting_enter(struct sci_base_state_machine *sm)
1097 {
1098         struct isci_port *iport = container_of(sm, typeof(*iport), sm);
1099
1100         scic_sds_port_suspend_port_task_scheduler(iport);
1101
1102         iport->not_ready_reason = SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS;
1103
1104         if (iport->active_phy_mask != 0) {
1105                 /* At least one of the phys on the port is ready */
1106                 port_state_machine_change(iport,
1107                                           SCI_PORT_SUB_OPERATIONAL);
1108         }
1109 }
1110
1111 static void scic_sds_port_ready_substate_operational_enter(struct sci_base_state_machine *sm)
1112 {
1113         u32 index;
1114         struct isci_port *iport = container_of(sm, typeof(*iport), sm);
1115         struct isci_host *ihost = iport->owning_controller;
1116
1117         isci_port_ready(ihost, iport);
1118
1119         for (index = 0; index < SCI_MAX_PHYS; index++) {
1120                 if (iport->phy_table[index]) {
1121                         writel(iport->physical_port_index,
1122                                 &iport->port_pe_configuration_register[
1123                                         iport->phy_table[index]->phy_index]);
1124                 }
1125         }
1126
1127         scic_sds_port_update_viit_entry(iport);
1128
1129         scic_sds_port_resume_port_task_scheduler(iport);
1130
1131         /*
1132          * Post the dummy task for the port so the hardware can schedule
1133          * io correctly
1134          */
1135         scic_sds_port_post_dummy_request(iport);
1136 }
1137
1138 static void scic_sds_port_invalidate_dummy_remote_node(struct isci_port *iport)
1139 {
1140         struct isci_host *ihost = iport->owning_controller;
1141         u8 phys_index = iport->physical_port_index;
1142         union scu_remote_node_context *rnc;
1143         u16 rni = iport->reserved_rni;
1144         u32 command;
1145
1146         rnc = &ihost->remote_node_context_table[rni];
1147
1148         rnc->ssp.is_valid = false;
1149
1150         /* ensure the preceding tc abort request has reached the
1151          * controller and give it ample time to act before posting the rnc
1152          * invalidate
1153          */
1154         readl(&ihost->smu_registers->interrupt_status); /* flush */
1155         udelay(10);
1156
1157         command = SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE |
1158                   phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
1159
1160         scic_sds_controller_post_request(ihost, command);
1161 }
1162
1163 /**
1164  *
1165  * @object: This is the object which is cast to a struct isci_port object.
1166  *
1167  * This method will perform the actions required by the struct isci_port on
1168  * exiting the SCI_PORT_SUB_OPERATIONAL. This function reports
1169  * the port not ready and suspends the port task scheduler. none
1170  */
1171 static void scic_sds_port_ready_substate_operational_exit(struct sci_base_state_machine *sm)
1172 {
1173         struct isci_port *iport = container_of(sm, typeof(*iport), sm);
1174         struct isci_host *ihost = iport->owning_controller;
1175
1176         /*
1177          * Kill the dummy task for this port if it has not yet posted
1178          * the hardware will treat this as a NOP and just return abort
1179          * complete.
1180          */
1181         scic_sds_port_abort_dummy_request(iport);
1182
1183         isci_port_not_ready(ihost, iport);
1184
1185         if (iport->ready_exit)
1186                 scic_sds_port_invalidate_dummy_remote_node(iport);
1187 }
1188
1189 static void scic_sds_port_ready_substate_configuring_enter(struct sci_base_state_machine *sm)
1190 {
1191         struct isci_port *iport = container_of(sm, typeof(*iport), sm);
1192         struct isci_host *ihost = iport->owning_controller;
1193
1194         if (iport->active_phy_mask == 0) {
1195                 isci_port_not_ready(ihost, iport);
1196
1197                 port_state_machine_change(iport,
1198                                           SCI_PORT_SUB_WAITING);
1199         } else if (iport->started_request_count == 0)
1200                 port_state_machine_change(iport,
1201                                           SCI_PORT_SUB_OPERATIONAL);
1202 }
1203
1204 static void scic_sds_port_ready_substate_configuring_exit(struct sci_base_state_machine *sm)
1205 {
1206         struct isci_port *iport = container_of(sm, typeof(*iport), sm);
1207
1208         scic_sds_port_suspend_port_task_scheduler(iport);
1209         if (iport->ready_exit)
1210                 scic_sds_port_invalidate_dummy_remote_node(iport);
1211 }
1212
1213 enum sci_status scic_sds_port_start(struct isci_port *iport)
1214 {
1215         struct isci_host *ihost = iport->owning_controller;
1216         enum sci_status status = SCI_SUCCESS;
1217         enum scic_sds_port_states state;
1218         u32 phy_mask;
1219
1220         state = iport->sm.current_state_id;
1221         if (state != SCI_PORT_STOPPED) {
1222                 dev_warn(sciport_to_dev(iport),
1223                          "%s: in wrong state: %d\n", __func__, state);
1224                 return SCI_FAILURE_INVALID_STATE;
1225         }
1226
1227         if (iport->assigned_device_count > 0) {
1228                 /* TODO This is a start failure operation because
1229                  * there are still devices assigned to this port.
1230                  * There must be no devices assigned to a port on a
1231                  * start operation.
1232                  */
1233                 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
1234         }
1235
1236         if (iport->reserved_rni == SCU_DUMMY_INDEX) {
1237                 u16 rni = scic_sds_remote_node_table_allocate_remote_node(
1238                                 &ihost->available_remote_nodes, 1);
1239
1240                 if (rni != SCU_DUMMY_INDEX)
1241                         scic_sds_port_construct_dummy_rnc(iport, rni);
1242                 else
1243                         status = SCI_FAILURE_INSUFFICIENT_RESOURCES;
1244                 iport->reserved_rni = rni;
1245         }
1246
1247         if (iport->reserved_tag == SCI_CONTROLLER_INVALID_IO_TAG) {
1248                 u16 tag;
1249
1250                 tag = isci_alloc_tag(ihost);
1251                 if (tag == SCI_CONTROLLER_INVALID_IO_TAG)
1252                         status = SCI_FAILURE_INSUFFICIENT_RESOURCES;
1253                 else
1254                         scic_sds_port_construct_dummy_task(iport, tag);
1255                 iport->reserved_tag = tag;
1256         }
1257
1258         if (status == SCI_SUCCESS) {
1259                 phy_mask = scic_sds_port_get_phys(iport);
1260
1261                 /*
1262                  * There are one or more phys assigned to this port.  Make sure
1263                  * the port's phy mask is in fact legal and supported by the
1264                  * silicon.
1265                  */
1266                 if (scic_sds_port_is_phy_mask_valid(iport, phy_mask) == true) {
1267                         port_state_machine_change(iport,
1268                                                   SCI_PORT_READY);
1269
1270                         return SCI_SUCCESS;
1271                 }
1272                 status = SCI_FAILURE;
1273         }
1274
1275         if (status != SCI_SUCCESS)
1276                 scic_sds_port_destroy_dummy_resources(iport);
1277
1278         return status;
1279 }
1280
1281 enum sci_status scic_sds_port_stop(struct isci_port *iport)
1282 {
1283         enum scic_sds_port_states state;
1284
1285         state = iport->sm.current_state_id;
1286         switch (state) {
1287         case SCI_PORT_STOPPED:
1288                 return SCI_SUCCESS;
1289         case SCI_PORT_SUB_WAITING:
1290         case SCI_PORT_SUB_OPERATIONAL:
1291         case SCI_PORT_SUB_CONFIGURING:
1292         case SCI_PORT_RESETTING:
1293                 port_state_machine_change(iport,
1294                                           SCI_PORT_STOPPING);
1295                 return SCI_SUCCESS;
1296         default:
1297                 dev_warn(sciport_to_dev(iport),
1298                          "%s: in wrong state: %d\n", __func__, state);
1299                 return SCI_FAILURE_INVALID_STATE;
1300         }
1301 }
1302
1303 static enum sci_status scic_port_hard_reset(struct isci_port *iport, u32 timeout)
1304 {
1305         enum sci_status status = SCI_FAILURE_INVALID_PHY;
1306         struct isci_phy *iphy = NULL;
1307         enum scic_sds_port_states state;
1308         u32 phy_index;
1309
1310         state = iport->sm.current_state_id;
1311         if (state != SCI_PORT_SUB_OPERATIONAL) {
1312                 dev_warn(sciport_to_dev(iport),
1313                          "%s: in wrong state: %d\n", __func__, state);
1314                 return SCI_FAILURE_INVALID_STATE;
1315         }
1316
1317         /* Select a phy on which we can send the hard reset request. */
1318         for (phy_index = 0; phy_index < SCI_MAX_PHYS && !iphy; phy_index++) {
1319                 iphy = iport->phy_table[phy_index];
1320                 if (iphy && !scic_sds_port_active_phy(iport, iphy)) {
1321                         /*
1322                          * We found a phy but it is not ready select
1323                          * different phy
1324                          */
1325                         iphy = NULL;
1326                 }
1327         }
1328
1329         /* If we have a phy then go ahead and start the reset procedure */
1330         if (!iphy)
1331                 return status;
1332         status = scic_sds_phy_reset(iphy);
1333
1334         if (status != SCI_SUCCESS)
1335                 return status;
1336
1337         sci_mod_timer(&iport->timer, timeout);
1338         iport->not_ready_reason = SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED;
1339
1340         port_state_machine_change(iport, SCI_PORT_RESETTING);
1341         return SCI_SUCCESS;
1342 }
1343
1344 /**
1345  * scic_sds_port_add_phy() -
1346  * @sci_port: This parameter specifies the port in which the phy will be added.
1347  * @sci_phy: This parameter is the phy which is to be added to the port.
1348  *
1349  * This method will add a PHY to the selected port. This method returns an
1350  * enum sci_status. SCI_SUCCESS the phy has been added to the port. Any other
1351  * status is a failure to add the phy to the port.
1352  */
1353 enum sci_status scic_sds_port_add_phy(struct isci_port *iport,
1354                                       struct isci_phy *iphy)
1355 {
1356         enum sci_status status;
1357         enum scic_sds_port_states state;
1358
1359         state = iport->sm.current_state_id;
1360         switch (state) {
1361         case SCI_PORT_STOPPED: {
1362                 struct sci_sas_address port_sas_address;
1363
1364                 /* Read the port assigned SAS Address if there is one */
1365                 scic_sds_port_get_sas_address(iport, &port_sas_address);
1366
1367                 if (port_sas_address.high != 0 && port_sas_address.low != 0) {
1368                         struct sci_sas_address phy_sas_address;
1369
1370                         /* Make sure that the PHY SAS Address matches the SAS Address
1371                          * for this port
1372                          */
1373                         scic_sds_phy_get_sas_address(iphy, &phy_sas_address);
1374
1375                         if (port_sas_address.high != phy_sas_address.high ||
1376                             port_sas_address.low  != phy_sas_address.low)
1377                                 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
1378                 }
1379                 return scic_sds_port_set_phy(iport, iphy);
1380         }
1381         case SCI_PORT_SUB_WAITING:
1382         case SCI_PORT_SUB_OPERATIONAL:
1383                 status = scic_sds_port_set_phy(iport, iphy);
1384
1385                 if (status != SCI_SUCCESS)
1386                         return status;
1387
1388                 scic_sds_port_general_link_up_handler(iport, iphy, true);
1389                 iport->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
1390                 port_state_machine_change(iport, SCI_PORT_SUB_CONFIGURING);
1391
1392                 return status;
1393         case SCI_PORT_SUB_CONFIGURING:
1394                 status = scic_sds_port_set_phy(iport, iphy);
1395
1396                 if (status != SCI_SUCCESS)
1397                         return status;
1398                 scic_sds_port_general_link_up_handler(iport, iphy, true);
1399
1400                 /* Re-enter the configuring state since this may be the last phy in
1401                  * the port.
1402                  */
1403                 port_state_machine_change(iport,
1404                                           SCI_PORT_SUB_CONFIGURING);
1405                 return SCI_SUCCESS;
1406         default:
1407                 dev_warn(sciport_to_dev(iport),
1408                          "%s: in wrong state: %d\n", __func__, state);
1409                 return SCI_FAILURE_INVALID_STATE;
1410         }
1411 }
1412
1413 /**
1414  * scic_sds_port_remove_phy() -
1415  * @sci_port: This parameter specifies the port in which the phy will be added.
1416  * @sci_phy: This parameter is the phy which is to be added to the port.
1417  *
1418  * This method will remove the PHY from the selected PORT. This method returns
1419  * an enum sci_status. SCI_SUCCESS the phy has been removed from the port. Any
1420  * other status is a failure to add the phy to the port.
1421  */
1422 enum sci_status scic_sds_port_remove_phy(struct isci_port *iport,
1423                                          struct isci_phy *iphy)
1424 {
1425         enum sci_status status;
1426         enum scic_sds_port_states state;
1427
1428         state = iport->sm.current_state_id;
1429
1430         switch (state) {
1431         case SCI_PORT_STOPPED:
1432                 return scic_sds_port_clear_phy(iport, iphy);
1433         case SCI_PORT_SUB_OPERATIONAL:
1434                 status = scic_sds_port_clear_phy(iport, iphy);
1435                 if (status != SCI_SUCCESS)
1436                         return status;
1437
1438                 scic_sds_port_deactivate_phy(iport, iphy, true);
1439                 iport->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
1440                 port_state_machine_change(iport,
1441                                           SCI_PORT_SUB_CONFIGURING);
1442                 return SCI_SUCCESS;
1443         case SCI_PORT_SUB_CONFIGURING:
1444                 status = scic_sds_port_clear_phy(iport, iphy);
1445
1446                 if (status != SCI_SUCCESS)
1447                         return status;
1448                 scic_sds_port_deactivate_phy(iport, iphy, true);
1449
1450                 /* Re-enter the configuring state since this may be the last phy in
1451                  * the port
1452                  */
1453                 port_state_machine_change(iport,
1454                                           SCI_PORT_SUB_CONFIGURING);
1455                 return SCI_SUCCESS;
1456         default:
1457                 dev_warn(sciport_to_dev(iport),
1458                          "%s: in wrong state: %d\n", __func__, state);
1459                 return SCI_FAILURE_INVALID_STATE;
1460         }
1461 }
1462
1463 enum sci_status scic_sds_port_link_up(struct isci_port *iport,
1464                                       struct isci_phy *iphy)
1465 {
1466         enum scic_sds_port_states state;
1467
1468         state = iport->sm.current_state_id;
1469         switch (state) {
1470         case SCI_PORT_SUB_WAITING:
1471                 /* Since this is the first phy going link up for the port we
1472                  * can just enable it and continue
1473                  */
1474                 scic_sds_port_activate_phy(iport, iphy, true);
1475
1476                 port_state_machine_change(iport,
1477                                           SCI_PORT_SUB_OPERATIONAL);
1478                 return SCI_SUCCESS;
1479         case SCI_PORT_SUB_OPERATIONAL:
1480                 scic_sds_port_general_link_up_handler(iport, iphy, true);
1481                 return SCI_SUCCESS;
1482         case SCI_PORT_RESETTING:
1483                 /* TODO We should  make  sure  that  the phy  that  has gone
1484                  * link up is the same one on which we sent the reset.  It is
1485                  * possible that the phy on which we sent  the reset is not the
1486                  * one that has  gone  link up  and we  want to make sure that
1487                  * phy being reset  comes  back.  Consider the case where a
1488                  * reset is sent but before the hardware processes the reset it
1489                  * get a link up on  the  port because of a hot plug event.
1490                  * because  of  the reset request this phy will go link down
1491                  * almost immediately.
1492                  */
1493
1494                 /* In the resetting state we don't notify the user regarding
1495                  * link up and link down notifications.
1496                  */
1497                 scic_sds_port_general_link_up_handler(iport, iphy, false);
1498                 return SCI_SUCCESS;
1499         default:
1500                 dev_warn(sciport_to_dev(iport),
1501                          "%s: in wrong state: %d\n", __func__, state);
1502                 return SCI_FAILURE_INVALID_STATE;
1503         }
1504 }
1505
1506 enum sci_status scic_sds_port_link_down(struct isci_port *iport,
1507                                         struct isci_phy *iphy)
1508 {
1509         enum scic_sds_port_states state;
1510
1511         state = iport->sm.current_state_id;
1512         switch (state) {
1513         case SCI_PORT_SUB_OPERATIONAL:
1514                 scic_sds_port_deactivate_phy(iport, iphy, true);
1515
1516                 /* If there are no active phys left in the port, then
1517                  * transition the port to the WAITING state until such time
1518                  * as a phy goes link up
1519                  */
1520                 if (iport->active_phy_mask == 0)
1521                         port_state_machine_change(iport,
1522                                                   SCI_PORT_SUB_WAITING);
1523                 return SCI_SUCCESS;
1524         case SCI_PORT_RESETTING:
1525                 /* In the resetting state we don't notify the user regarding
1526                  * link up and link down notifications. */
1527                 scic_sds_port_deactivate_phy(iport, iphy, false);
1528                 return SCI_SUCCESS;
1529         default:
1530                 dev_warn(sciport_to_dev(iport),
1531                          "%s: in wrong state: %d\n", __func__, state);
1532                 return SCI_FAILURE_INVALID_STATE;
1533         }
1534 }
1535
1536 enum sci_status scic_sds_port_start_io(struct isci_port *iport,
1537                                        struct isci_remote_device *idev,
1538                                        struct isci_request *ireq)
1539 {
1540         enum scic_sds_port_states state;
1541
1542         state = iport->sm.current_state_id;
1543         switch (state) {
1544         case SCI_PORT_SUB_WAITING:
1545                 return SCI_FAILURE_INVALID_STATE;
1546         case SCI_PORT_SUB_OPERATIONAL:
1547                 iport->started_request_count++;
1548                 return SCI_SUCCESS;
1549         default:
1550                 dev_warn(sciport_to_dev(iport),
1551                          "%s: in wrong state: %d\n", __func__, state);
1552                 return SCI_FAILURE_INVALID_STATE;
1553         }
1554 }
1555
1556 enum sci_status scic_sds_port_complete_io(struct isci_port *iport,
1557                                           struct isci_remote_device *idev,
1558                                           struct isci_request *ireq)
1559 {
1560         enum scic_sds_port_states state;
1561
1562         state = iport->sm.current_state_id;
1563         switch (state) {
1564         case SCI_PORT_STOPPED:
1565                 dev_warn(sciport_to_dev(iport),
1566                          "%s: in wrong state: %d\n", __func__, state);
1567                 return SCI_FAILURE_INVALID_STATE;
1568         case SCI_PORT_STOPPING:
1569                 scic_sds_port_decrement_request_count(iport);
1570
1571                 if (iport->started_request_count == 0)
1572                         port_state_machine_change(iport,
1573                                                   SCI_PORT_STOPPED);
1574                 break;
1575         case SCI_PORT_READY:
1576         case SCI_PORT_RESETTING:
1577         case SCI_PORT_FAILED:
1578         case SCI_PORT_SUB_WAITING:
1579         case SCI_PORT_SUB_OPERATIONAL:
1580                 scic_sds_port_decrement_request_count(iport);
1581                 break;
1582         case SCI_PORT_SUB_CONFIGURING:
1583                 scic_sds_port_decrement_request_count(iport);
1584                 if (iport->started_request_count == 0) {
1585                         port_state_machine_change(iport,
1586                                                   SCI_PORT_SUB_OPERATIONAL);
1587                 }
1588                 break;
1589         }
1590         return SCI_SUCCESS;
1591 }
1592
1593 /**
1594  *
1595  * @sci_port: This is the port object which to suspend.
1596  *
1597  * This method will enable the SCU Port Task Scheduler for this port object but
1598  * will leave the port task scheduler in a suspended state. none
1599  */
1600 static void
1601 scic_sds_port_enable_port_task_scheduler(struct isci_port *iport)
1602 {
1603         u32 pts_control_value;
1604
1605         pts_control_value = readl(&iport->port_task_scheduler_registers->control);
1606         pts_control_value |= SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND);
1607         writel(pts_control_value, &iport->port_task_scheduler_registers->control);
1608 }
1609
1610 /**
1611  *
1612  * @sci_port: This is the port object which to resume.
1613  *
1614  * This method will disable the SCU port task scheduler for this port object.
1615  * none
1616  */
1617 static void
1618 scic_sds_port_disable_port_task_scheduler(struct isci_port *iport)
1619 {
1620         u32 pts_control_value;
1621
1622         pts_control_value = readl(&iport->port_task_scheduler_registers->control);
1623         pts_control_value &=
1624                 ~(SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND));
1625         writel(pts_control_value, &iport->port_task_scheduler_registers->control);
1626 }
1627
1628 static void scic_sds_port_post_dummy_remote_node(struct isci_port *iport)
1629 {
1630         struct isci_host *ihost = iport->owning_controller;
1631         u8 phys_index = iport->physical_port_index;
1632         union scu_remote_node_context *rnc;
1633         u16 rni = iport->reserved_rni;
1634         u32 command;
1635
1636         rnc = &ihost->remote_node_context_table[rni];
1637         rnc->ssp.is_valid = true;
1638
1639         command = SCU_CONTEXT_COMMAND_POST_RNC_32 |
1640                   phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
1641
1642         scic_sds_controller_post_request(ihost, command);
1643
1644         /* ensure hardware has seen the post rnc command and give it
1645          * ample time to act before sending the suspend
1646          */
1647         readl(&ihost->smu_registers->interrupt_status); /* flush */
1648         udelay(10);
1649
1650         command = SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX_RX |
1651                   phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
1652
1653         scic_sds_controller_post_request(ihost, command);
1654 }
1655
1656 static void scic_sds_port_stopped_state_enter(struct sci_base_state_machine *sm)
1657 {
1658         struct isci_port *iport = container_of(sm, typeof(*iport), sm);
1659
1660         if (iport->sm.previous_state_id == SCI_PORT_STOPPING) {
1661                 /*
1662                  * If we enter this state becasuse of a request to stop
1663                  * the port then we want to disable the hardwares port
1664                  * task scheduler. */
1665                 scic_sds_port_disable_port_task_scheduler(iport);
1666         }
1667 }
1668
1669 static void scic_sds_port_stopped_state_exit(struct sci_base_state_machine *sm)
1670 {
1671         struct isci_port *iport = container_of(sm, typeof(*iport), sm);
1672
1673         /* Enable and suspend the port task scheduler */
1674         scic_sds_port_enable_port_task_scheduler(iport);
1675 }
1676
1677 static void scic_sds_port_ready_state_enter(struct sci_base_state_machine *sm)
1678 {
1679         struct isci_port *iport = container_of(sm, typeof(*iport), sm);
1680         struct isci_host *ihost = iport->owning_controller;
1681         u32 prev_state;
1682
1683         prev_state = iport->sm.previous_state_id;
1684         if (prev_state  == SCI_PORT_RESETTING)
1685                 isci_port_hard_reset_complete(iport, SCI_SUCCESS);
1686         else
1687                 isci_port_not_ready(ihost, iport);
1688
1689         /* Post and suspend the dummy remote node context for this port. */
1690         scic_sds_port_post_dummy_remote_node(iport);
1691
1692         /* Start the ready substate machine */
1693         port_state_machine_change(iport,
1694                                   SCI_PORT_SUB_WAITING);
1695 }
1696
1697 static void scic_sds_port_resetting_state_exit(struct sci_base_state_machine *sm)
1698 {
1699         struct isci_port *iport = container_of(sm, typeof(*iport), sm);
1700
1701         sci_del_timer(&iport->timer);
1702 }
1703
1704 static void scic_sds_port_stopping_state_exit(struct sci_base_state_machine *sm)
1705 {
1706         struct isci_port *iport = container_of(sm, typeof(*iport), sm);
1707
1708         sci_del_timer(&iport->timer);
1709
1710         scic_sds_port_destroy_dummy_resources(iport);
1711 }
1712
1713 static void scic_sds_port_failed_state_enter(struct sci_base_state_machine *sm)
1714 {
1715         struct isci_port *iport = container_of(sm, typeof(*iport), sm);
1716
1717         isci_port_hard_reset_complete(iport, SCI_FAILURE_TIMEOUT);
1718 }
1719
1720 /* --------------------------------------------------------------------------- */
1721
1722 static const struct sci_base_state scic_sds_port_state_table[] = {
1723         [SCI_PORT_STOPPED] = {
1724                 .enter_state = scic_sds_port_stopped_state_enter,
1725                 .exit_state  = scic_sds_port_stopped_state_exit
1726         },
1727         [SCI_PORT_STOPPING] = {
1728                 .exit_state  = scic_sds_port_stopping_state_exit
1729         },
1730         [SCI_PORT_READY] = {
1731                 .enter_state = scic_sds_port_ready_state_enter,
1732         },
1733         [SCI_PORT_SUB_WAITING] = {
1734                 .enter_state = scic_sds_port_ready_substate_waiting_enter,
1735         },
1736         [SCI_PORT_SUB_OPERATIONAL] = {
1737                 .enter_state = scic_sds_port_ready_substate_operational_enter,
1738                 .exit_state  = scic_sds_port_ready_substate_operational_exit
1739         },
1740         [SCI_PORT_SUB_CONFIGURING] = {
1741                 .enter_state = scic_sds_port_ready_substate_configuring_enter,
1742                 .exit_state  = scic_sds_port_ready_substate_configuring_exit
1743         },
1744         [SCI_PORT_RESETTING] = {
1745                 .exit_state  = scic_sds_port_resetting_state_exit
1746         },
1747         [SCI_PORT_FAILED] = {
1748                 .enter_state = scic_sds_port_failed_state_enter,
1749         }
1750 };
1751
1752 void scic_sds_port_construct(struct isci_port *iport, u8 index,
1753                              struct isci_host *ihost)
1754 {
1755         sci_init_sm(&iport->sm, scic_sds_port_state_table, SCI_PORT_STOPPED);
1756
1757         iport->logical_port_index  = SCIC_SDS_DUMMY_PORT;
1758         iport->physical_port_index = index;
1759         iport->active_phy_mask     = 0;
1760         iport->ready_exit             = false;
1761
1762         iport->owning_controller = ihost;
1763
1764         iport->started_request_count = 0;
1765         iport->assigned_device_count = 0;
1766
1767         iport->reserved_rni = SCU_DUMMY_INDEX;
1768         iport->reserved_tag = SCI_CONTROLLER_INVALID_IO_TAG;
1769
1770         sci_init_timer(&iport->timer, port_timeout);
1771
1772         iport->port_task_scheduler_registers = NULL;
1773
1774         for (index = 0; index < SCI_MAX_PHYS; index++)
1775                 iport->phy_table[index] = NULL;
1776 }
1777
1778 void isci_port_init(struct isci_port *iport, struct isci_host *ihost, int index)
1779 {
1780         INIT_LIST_HEAD(&iport->remote_dev_list);
1781         INIT_LIST_HEAD(&iport->domain_dev_list);
1782         spin_lock_init(&iport->state_lock);
1783         init_completion(&iport->start_complete);
1784         iport->isci_host = ihost;
1785         isci_port_change_state(iport, isci_freed);
1786         atomic_set(&iport->event, 0);
1787 }
1788
1789 /**
1790  * isci_port_get_state() - This function gets the status of the port object.
1791  * @isci_port: This parameter points to the isci_port object
1792  *
1793  * status of the object as a isci_status enum.
1794  */
1795 enum isci_status isci_port_get_state(
1796         struct isci_port *isci_port)
1797 {
1798         return isci_port->status;
1799 }
1800
1801 void scic_sds_port_broadcast_change_received(
1802         struct isci_port *iport,
1803         struct isci_phy *iphy)
1804 {
1805         struct isci_host *ihost = iport->owning_controller;
1806
1807         /* notify the user. */
1808         isci_port_bc_change_received(ihost, iport, iphy);
1809 }
1810
1811 int isci_port_perform_hard_reset(struct isci_host *ihost, struct isci_port *iport,
1812                                  struct isci_phy *iphy)
1813 {
1814         unsigned long flags;
1815         enum sci_status status;
1816         int idx, ret = TMF_RESP_FUNC_COMPLETE;
1817
1818         dev_dbg(&ihost->pdev->dev, "%s: iport = %p\n",
1819                 __func__, iport);
1820
1821         init_completion(&iport->hard_reset_complete);
1822
1823         spin_lock_irqsave(&ihost->scic_lock, flags);
1824
1825         #define ISCI_PORT_RESET_TIMEOUT SCIC_SDS_SIGNATURE_FIS_TIMEOUT
1826         status = scic_port_hard_reset(iport, ISCI_PORT_RESET_TIMEOUT);
1827
1828         spin_unlock_irqrestore(&ihost->scic_lock, flags);
1829
1830         if (status == SCI_SUCCESS) {
1831                 wait_for_completion(&iport->hard_reset_complete);
1832
1833                 dev_dbg(&ihost->pdev->dev,
1834                         "%s: iport = %p; hard reset completion\n",
1835                         __func__, iport);
1836
1837                 if (iport->hard_reset_status != SCI_SUCCESS)
1838                         ret = TMF_RESP_FUNC_FAILED;
1839         } else {
1840                 ret = TMF_RESP_FUNC_FAILED;
1841
1842                 dev_err(&ihost->pdev->dev,
1843                         "%s: iport = %p; scic_port_hard_reset call"
1844                         " failed 0x%x\n",
1845                         __func__, iport, status);
1846
1847         }
1848
1849         /* If the hard reset for the port has failed, consider this
1850          * the same as link failures on all phys in the port.
1851          */
1852         if (ret != TMF_RESP_FUNC_COMPLETE) {
1853
1854                 dev_err(&ihost->pdev->dev,
1855                         "%s: iport = %p; hard reset failed "
1856                         "(0x%x) - driving explicit link fail for all phys\n",
1857                         __func__, iport, iport->hard_reset_status);
1858
1859                 /* Down all phys in the port. */
1860                 spin_lock_irqsave(&ihost->scic_lock, flags);
1861                 for (idx = 0; idx < SCI_MAX_PHYS; ++idx) {
1862                         struct isci_phy *iphy = iport->phy_table[idx];
1863
1864                         if (!iphy)
1865                                 continue;
1866                         scic_sds_phy_stop(iphy);
1867                         scic_sds_phy_start(iphy);
1868                 }
1869                 spin_unlock_irqrestore(&ihost->scic_lock, flags);
1870         }
1871         return ret;
1872 }
1873
1874 /**
1875  * isci_port_deformed() - This function is called by libsas when a port becomes
1876  *    inactive.
1877  * @phy: This parameter specifies the libsas phy with the inactive port.
1878  *
1879  */
1880 void isci_port_deformed(struct asd_sas_phy *phy)
1881 {
1882         pr_debug("%s: sas_phy = %p\n", __func__, phy);
1883 }
1884
1885 /**
1886  * isci_port_formed() - This function is called by libsas when a port becomes
1887  *    active.
1888  * @phy: This parameter specifies the libsas phy with the active port.
1889  *
1890  */
1891 void isci_port_formed(struct asd_sas_phy *phy)
1892 {
1893         pr_debug("%s: sas_phy = %p, sas_port = %p\n", __func__, phy, phy->port);
1894 }