aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/isci/port.c
diff options
context:
space:
mode:
authorDan Williams <dan.j.williams@intel.com>2011-06-28 18:05:53 -0400
committerDan Williams <dan.j.williams@intel.com>2011-07-03 07:04:52 -0400
commit852809559e4680ba4768262a6c3d21454fcd460e (patch)
treea67170a9dd2a4c9f15d215f4b96e890cdb53a7e7 /drivers/scsi/isci/port.c
parent5076a1a97e2fa61c847a5fdd4b1991faf7716da6 (diff)
isci: unify isci_phy and scic_sds_phy
They are one in the same object so remove the distinction. The near duplicate fields (owning_port, and isci_port) will be cleaned up after the scic_sds_port isci_port unification. Reported-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Diffstat (limited to 'drivers/scsi/isci/port.c')
-rw-r--r--drivers/scsi/isci/port.c299
1 files changed, 119 insertions, 180 deletions
diff --git a/drivers/scsi/isci/port.c b/drivers/scsi/isci/port.c
index bd091549b4f7..d53c0b1748e7 100644
--- a/drivers/scsi/isci/port.c
+++ b/drivers/scsi/isci/port.c
@@ -154,17 +154,17 @@ static enum sci_status scic_port_get_properties(struct scic_sds_port *port,
154 154
155static void scic_port_bcn_enable(struct scic_sds_port *sci_port) 155static void scic_port_bcn_enable(struct scic_sds_port *sci_port)
156{ 156{
157 struct scic_sds_phy *sci_phy; 157 struct isci_phy *iphy;
158 u32 val; 158 u32 val;
159 int i; 159 int i;
160 160
161 for (i = 0; i < ARRAY_SIZE(sci_port->phy_table); i++) { 161 for (i = 0; i < ARRAY_SIZE(sci_port->phy_table); i++) {
162 sci_phy = sci_port->phy_table[i]; 162 iphy = sci_port->phy_table[i];
163 if (!sci_phy) 163 if (!iphy)
164 continue; 164 continue;
165 val = readl(&sci_phy->link_layer_registers->link_layer_control); 165 val = readl(&iphy->link_layer_registers->link_layer_control);
166 /* clear the bit by writing 1. */ 166 /* clear the bit by writing 1. */
167 writel(val, &sci_phy->link_layer_registers->link_layer_control); 167 writel(val, &iphy->link_layer_registers->link_layer_control);
168 } 168 }
169} 169}
170 170
@@ -180,10 +180,9 @@ void isci_port_bcn_enable(struct isci_host *ihost, struct isci_port *iport)
180 return; 180 return;
181 181
182 for (i = 0; i < ARRAY_SIZE(iport->sci.phy_table); i++) { 182 for (i = 0; i < ARRAY_SIZE(iport->sci.phy_table); i++) {
183 struct scic_sds_phy *sci_phy = iport->sci.phy_table[i]; 183 struct isci_phy *iphy = iport->sci.phy_table[i];
184 struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
185 184
186 if (!sci_phy) 185 if (!iphy)
187 continue; 186 continue;
188 187
189 ihost->sas_ha.notify_port_event(&iphy->sas_phy, 188 ihost->sas_ha.notify_port_event(&iphy->sas_phy,
@@ -194,9 +193,8 @@ void isci_port_bcn_enable(struct isci_host *ihost, struct isci_port *iport)
194 193
195void isci_port_bc_change_received(struct isci_host *ihost, 194void isci_port_bc_change_received(struct isci_host *ihost,
196 struct scic_sds_port *sci_port, 195 struct scic_sds_port *sci_port,
197 struct scic_sds_phy *sci_phy) 196 struct isci_phy *iphy)
198{ 197{
199 struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
200 struct isci_port *iport = iphy->isci_port; 198 struct isci_port *iport = iphy->isci_port;
201 199
202 if (iport && test_bit(IPORT_BCN_BLOCKED, &iport->flags)) { 200 if (iport && test_bit(IPORT_BCN_BLOCKED, &iport->flags)) {
@@ -219,33 +217,32 @@ void isci_port_bc_change_received(struct isci_host *ihost,
219 217
220static void isci_port_link_up(struct isci_host *isci_host, 218static void isci_port_link_up(struct isci_host *isci_host,
221 struct scic_sds_port *port, 219 struct scic_sds_port *port,
222 struct scic_sds_phy *phy) 220 struct isci_phy *iphy)
223{ 221{
224 unsigned long flags; 222 unsigned long flags;
225 struct scic_port_properties properties; 223 struct scic_port_properties properties;
226 struct isci_phy *isci_phy = sci_phy_to_iphy(phy);
227 struct isci_port *isci_port = sci_port_to_iport(port); 224 struct isci_port *isci_port = sci_port_to_iport(port);
228 unsigned long success = true; 225 unsigned long success = true;
229 226
230 BUG_ON(isci_phy->isci_port != NULL); 227 BUG_ON(iphy->isci_port != NULL);
231 228
232 isci_phy->isci_port = isci_port; 229 iphy->isci_port = isci_port;
233 230
234 dev_dbg(&isci_host->pdev->dev, 231 dev_dbg(&isci_host->pdev->dev,
235 "%s: isci_port = %p\n", 232 "%s: isci_port = %p\n",
236 __func__, isci_port); 233 __func__, isci_port);
237 234
238 spin_lock_irqsave(&isci_phy->sas_phy.frame_rcvd_lock, flags); 235 spin_lock_irqsave(&iphy->sas_phy.frame_rcvd_lock, flags);
239 236
240 isci_port_change_state(isci_phy->isci_port, isci_starting); 237 isci_port_change_state(iphy->isci_port, isci_starting);
241 238
242 scic_port_get_properties(port, &properties); 239 scic_port_get_properties(port, &properties);
243 240
244 if (phy->protocol == SCIC_SDS_PHY_PROTOCOL_SATA) { 241 if (iphy->protocol == SCIC_SDS_PHY_PROTOCOL_SATA) {
245 u64 attached_sas_address; 242 u64 attached_sas_address;
246 243
247 isci_phy->sas_phy.oob_mode = SATA_OOB_MODE; 244 iphy->sas_phy.oob_mode = SATA_OOB_MODE;
248 isci_phy->sas_phy.frame_rcvd_size = sizeof(struct dev_to_host_fis); 245 iphy->sas_phy.frame_rcvd_size = sizeof(struct dev_to_host_fis);
249 246
250 /* 247 /*
251 * For direct-attached SATA devices, the SCI core will 248 * For direct-attached SATA devices, the SCI core will
@@ -259,28 +256,28 @@ static void isci_port_link_up(struct isci_host *isci_host,
259 attached_sas_address |= properties.remote.sas_address.low; 256 attached_sas_address |= properties.remote.sas_address.low;
260 swab64s(&attached_sas_address); 257 swab64s(&attached_sas_address);
261 258
262 memcpy(&isci_phy->sas_phy.attached_sas_addr, 259 memcpy(&iphy->sas_phy.attached_sas_addr,
263 &attached_sas_address, sizeof(attached_sas_address)); 260 &attached_sas_address, sizeof(attached_sas_address));
264 } else if (phy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) { 261 } else if (iphy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) {
265 isci_phy->sas_phy.oob_mode = SAS_OOB_MODE; 262 iphy->sas_phy.oob_mode = SAS_OOB_MODE;
266 isci_phy->sas_phy.frame_rcvd_size = sizeof(struct sas_identify_frame); 263 iphy->sas_phy.frame_rcvd_size = sizeof(struct sas_identify_frame);
267 264
268 /* Copy the attached SAS address from the IAF */ 265 /* Copy the attached SAS address from the IAF */
269 memcpy(isci_phy->sas_phy.attached_sas_addr, 266 memcpy(iphy->sas_phy.attached_sas_addr,
270 isci_phy->frame_rcvd.iaf.sas_addr, SAS_ADDR_SIZE); 267 iphy->frame_rcvd.iaf.sas_addr, SAS_ADDR_SIZE);
271 } else { 268 } else {
272 dev_err(&isci_host->pdev->dev, "%s: unkown target\n", __func__); 269 dev_err(&isci_host->pdev->dev, "%s: unkown target\n", __func__);
273 success = false; 270 success = false;
274 } 271 }
275 272
276 isci_phy->sas_phy.phy->negotiated_linkrate = sci_phy_linkrate(phy); 273 iphy->sas_phy.phy->negotiated_linkrate = sci_phy_linkrate(iphy);
277 274
278 spin_unlock_irqrestore(&isci_phy->sas_phy.frame_rcvd_lock, flags); 275 spin_unlock_irqrestore(&iphy->sas_phy.frame_rcvd_lock, flags);
279 276
280 /* Notify libsas that we have an address frame, if indeed 277 /* Notify libsas that we have an address frame, if indeed
281 * we've found an SSP, SMP, or STP target */ 278 * we've found an SSP, SMP, or STP target */
282 if (success) 279 if (success)
283 isci_host->sas_ha.notify_port_event(&isci_phy->sas_phy, 280 isci_host->sas_ha.notify_port_event(&iphy->sas_phy,
284 PORTE_BYTES_DMAED); 281 PORTE_BYTES_DMAED);
285} 282}
286 283
@@ -495,11 +492,7 @@ static bool scic_sds_port_is_phy_mask_valid(
495 return false; 492 return false;
496} 493}
497 494
498/** 495/*
499 *
500 * @sci_port: This parameter specifies the port from which to return a
501 * connected phy.
502 *
503 * This method retrieves a currently active (i.e. connected) phy contained in 496 * This method retrieves a currently active (i.e. connected) phy contained in
504 * the port. Currently, the lowest order phy that is connected is returned. 497 * the port. Currently, the lowest order phy that is connected is returned.
505 * This method returns a pointer to a SCIS_SDS_PHY object. NULL This value is 498 * This method returns a pointer to a SCIS_SDS_PHY object. NULL This value is
@@ -507,58 +500,38 @@ static bool scic_sds_port_is_phy_mask_valid(
507 * point) phys contained in the port. All other values specify a struct scic_sds_phy 500 * point) phys contained in the port. All other values specify a struct scic_sds_phy
508 * object that is active in the port. 501 * object that is active in the port.
509 */ 502 */
510static struct scic_sds_phy *scic_sds_port_get_a_connected_phy( 503static struct isci_phy *scic_sds_port_get_a_connected_phy(struct scic_sds_port *sci_port)
511 struct scic_sds_port *sci_port 504{
512 ) {
513 u32 index; 505 u32 index;
514 struct scic_sds_phy *phy; 506 struct isci_phy *iphy;
515 507
516 for (index = 0; index < SCI_MAX_PHYS; index++) { 508 for (index = 0; index < SCI_MAX_PHYS; index++) {
517 /* 509 /* Ensure that the phy is both part of the port and currently
518 * Ensure that the phy is both part of the port and currently 510 * connected to the remote end-point.
519 * connected to the remote end-point. */ 511 */
520 phy = sci_port->phy_table[index]; 512 iphy = sci_port->phy_table[index];
521 if ( 513 if (iphy && scic_sds_port_active_phy(sci_port, iphy))
522 (phy != NULL) 514 return iphy;
523 && scic_sds_port_active_phy(sci_port, phy)
524 ) {
525 return phy;
526 }
527 } 515 }
528 516
529 return NULL; 517 return NULL;
530} 518}
531 519
532/** 520static enum sci_status scic_sds_port_set_phy(struct scic_sds_port *port, struct isci_phy *iphy)
533 * scic_sds_port_set_phy() -
534 * @out]: port The port object to which the phy assignement is being made.
535 * @out]: phy The phy which is being assigned to the port.
536 *
537 * This method attempts to make the assignment of the phy to the port. If
538 * successful the phy is assigned to the ports phy table. bool true if the phy
539 * assignment can be made. false if the phy assignement can not be made. This
540 * is a functional test that only fails if the phy is currently assigned to a
541 * different port.
542 */
543static enum sci_status scic_sds_port_set_phy(
544 struct scic_sds_port *port,
545 struct scic_sds_phy *phy)
546{ 521{
547 /* 522 /* Check to see if we can add this phy to a port
548 * Check to see if we can add this phy to a port
549 * that means that the phy is not part of a port and that the port does 523 * that means that the phy is not part of a port and that the port does
550 * not already have a phy assinged to the phy index. */ 524 * not already have a phy assinged to the phy index.
551 if ( 525 */
552 (port->phy_table[phy->phy_index] == NULL) 526 if (!port->phy_table[iphy->phy_index] &&
553 && (phy_get_non_dummy_port(phy) == NULL) 527 !phy_get_non_dummy_port(iphy) &&
554 && scic_sds_port_is_valid_phy_assignment(port, phy->phy_index) 528 scic_sds_port_is_valid_phy_assignment(port, iphy->phy_index)) {
555 ) { 529 /* Phy is being added in the stopped state so we are in MPC mode
556 /* 530 * make logical port index = physical port index
557 * Phy is being added in the stopped state so we are in MPC mode 531 */
558 * make logical port index = physical port index */
559 port->logical_port_index = port->physical_port_index; 532 port->logical_port_index = port->physical_port_index;
560 port->phy_table[phy->phy_index] = phy; 533 port->phy_table[iphy->phy_index] = iphy;
561 scic_sds_phy_set_port(phy, port); 534 scic_sds_phy_set_port(iphy, port);
562 535
563 return SCI_SUCCESS; 536 return SCI_SUCCESS;
564 } 537 }
@@ -566,28 +539,18 @@ static enum sci_status scic_sds_port_set_phy(
566 return SCI_FAILURE; 539 return SCI_FAILURE;
567} 540}
568 541
569/** 542static enum sci_status scic_sds_port_clear_phy(struct scic_sds_port *port,
570 * scic_sds_port_clear_phy() - 543 struct isci_phy *iphy)
571 * @out]: port The port from which the phy is being cleared.
572 * @out]: phy The phy being cleared from the port.
573 *
574 * This method will clear the phy assigned to this port. This method fails if
575 * this phy is not currently assinged to this port. bool true if the phy is
576 * removed from the port. false if this phy is not assined to this port.
577 */
578static enum sci_status scic_sds_port_clear_phy(
579 struct scic_sds_port *port,
580 struct scic_sds_phy *phy)
581{ 544{
582 /* Make sure that this phy is part of this port */ 545 /* Make sure that this phy is part of this port */
583 if (port->phy_table[phy->phy_index] == phy && 546 if (port->phy_table[iphy->phy_index] == iphy &&
584 phy_get_non_dummy_port(phy) == port) { 547 phy_get_non_dummy_port(iphy) == port) {
585 struct scic_sds_controller *scic = port->owning_controller; 548 struct scic_sds_controller *scic = port->owning_controller;
586 struct isci_host *ihost = scic_to_ihost(scic); 549 struct isci_host *ihost = scic_to_ihost(scic);
587 550
588 /* Yep it is assigned to this port so remove it */ 551 /* Yep it is assigned to this port so remove it */
589 scic_sds_phy_set_port(phy, &ihost->ports[SCI_MAX_PORTS].sci); 552 scic_sds_phy_set_port(iphy, &ihost->ports[SCI_MAX_PORTS].sci);
590 port->phy_table[phy->phy_index] = NULL; 553 port->phy_table[iphy->phy_index] = NULL;
591 return SCI_SUCCESS; 554 return SCI_SUCCESS;
592 } 555 }
593 556
@@ -634,20 +597,20 @@ void scic_sds_port_get_attached_sas_address(
634 struct scic_sds_port *sci_port, 597 struct scic_sds_port *sci_port,
635 struct sci_sas_address *sas_address) 598 struct sci_sas_address *sas_address)
636{ 599{
637 struct scic_sds_phy *sci_phy; 600 struct isci_phy *iphy;
638 601
639 /* 602 /*
640 * Ensure that the phy is both part of the port and currently 603 * Ensure that the phy is both part of the port and currently
641 * connected to the remote end-point. 604 * connected to the remote end-point.
642 */ 605 */
643 sci_phy = scic_sds_port_get_a_connected_phy(sci_port); 606 iphy = scic_sds_port_get_a_connected_phy(sci_port);
644 if (sci_phy) { 607 if (iphy) {
645 if (sci_phy->protocol != SCIC_SDS_PHY_PROTOCOL_SATA) { 608 if (iphy->protocol != SCIC_SDS_PHY_PROTOCOL_SATA) {
646 scic_sds_phy_get_attached_sas_address(sci_phy, 609 scic_sds_phy_get_attached_sas_address(iphy,
647 sas_address); 610 sas_address);
648 } else { 611 } else {
649 scic_sds_phy_get_sas_address(sci_phy, sas_address); 612 scic_sds_phy_get_sas_address(iphy, sas_address);
650 sas_address->low += sci_phy->phy_index; 613 sas_address->low += iphy->phy_index;
651 } 614 }
652 } else { 615 } else {
653 sas_address->high = 0; 616 sas_address->high = 0;
@@ -787,39 +750,38 @@ void scic_sds_port_setup_transports(
787 * notifying the user that the link is up. none 750 * notifying the user that the link is up. none
788 */ 751 */
789static void scic_sds_port_activate_phy(struct scic_sds_port *sci_port, 752static void scic_sds_port_activate_phy(struct scic_sds_port *sci_port,
790 struct scic_sds_phy *sci_phy, 753 struct isci_phy *iphy,
791 bool do_notify_user) 754 bool do_notify_user)
792{ 755{
793 struct scic_sds_controller *scic = sci_port->owning_controller; 756 struct scic_sds_controller *scic = sci_port->owning_controller;
794 struct isci_host *ihost = scic_to_ihost(scic); 757 struct isci_host *ihost = scic_to_ihost(scic);
795 758
796 if (sci_phy->protocol != SCIC_SDS_PHY_PROTOCOL_SATA) 759 if (iphy->protocol != SCIC_SDS_PHY_PROTOCOL_SATA)
797 scic_sds_phy_resume(sci_phy); 760 scic_sds_phy_resume(iphy);
798 761
799 sci_port->active_phy_mask |= 1 << sci_phy->phy_index; 762 sci_port->active_phy_mask |= 1 << iphy->phy_index;
800 763
801 scic_sds_controller_clear_invalid_phy(scic, sci_phy); 764 scic_sds_controller_clear_invalid_phy(scic, iphy);
802 765
803 if (do_notify_user == true) 766 if (do_notify_user == true)
804 isci_port_link_up(ihost, sci_port, sci_phy); 767 isci_port_link_up(ihost, sci_port, iphy);
805} 768}
806 769
807void scic_sds_port_deactivate_phy(struct scic_sds_port *sci_port, 770void scic_sds_port_deactivate_phy(struct scic_sds_port *sci_port,
808 struct scic_sds_phy *sci_phy, 771 struct isci_phy *iphy,
809 bool do_notify_user) 772 bool do_notify_user)
810{ 773{
811 struct scic_sds_controller *scic = scic_sds_port_get_controller(sci_port); 774 struct scic_sds_controller *scic = scic_sds_port_get_controller(sci_port);
812 struct isci_port *iport = sci_port_to_iport(sci_port); 775 struct isci_port *iport = sci_port_to_iport(sci_port);
813 struct isci_host *ihost = scic_to_ihost(scic); 776 struct isci_host *ihost = scic_to_ihost(scic);
814 struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
815 777
816 sci_port->active_phy_mask &= ~(1 << sci_phy->phy_index); 778 sci_port->active_phy_mask &= ~(1 << iphy->phy_index);
817 779
818 sci_phy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN; 780 iphy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN;
819 781
820 /* Re-assign the phy back to the LP as if it were a narrow port */ 782 /* Re-assign the phy back to the LP as if it were a narrow port */
821 writel(sci_phy->phy_index, 783 writel(iphy->phy_index,
822 &sci_port->port_pe_configuration_register[sci_phy->phy_index]); 784 &sci_port->port_pe_configuration_register[iphy->phy_index]);
823 785
824 if (do_notify_user == true) 786 if (do_notify_user == true)
825 isci_port_link_down(ihost, iphy, iport); 787 isci_port_link_down(ihost, iphy, iport);
@@ -834,7 +796,7 @@ void scic_sds_port_deactivate_phy(struct scic_sds_port *sci_port,
834 * this port object. None 796 * this port object. None
835 */ 797 */
836static void scic_sds_port_invalid_link_up(struct scic_sds_port *sci_port, 798static void scic_sds_port_invalid_link_up(struct scic_sds_port *sci_port,
837 struct scic_sds_phy *sci_phy) 799 struct isci_phy *iphy)
838{ 800{
839 struct scic_sds_controller *scic = sci_port->owning_controller; 801 struct scic_sds_controller *scic = sci_port->owning_controller;
840 802
@@ -843,8 +805,8 @@ static void scic_sds_port_invalid_link_up(struct scic_sds_port *sci_port,
843 * not go ahead and tell the SCI_USER that we have discovered an 805 * not go ahead and tell the SCI_USER that we have discovered an
844 * invalid link. 806 * invalid link.
845 */ 807 */
846 if ((scic->invalid_phy_mask & (1 << sci_phy->phy_index)) == 0) { 808 if ((scic->invalid_phy_mask & (1 << iphy->phy_index)) == 0) {
847 scic_sds_controller_set_invalid_phy(scic, sci_phy); 809 scic_sds_controller_set_invalid_phy(scic, iphy);
848 dev_warn(&scic_to_ihost(scic)->pdev->dev, "Invalid link up!\n"); 810 dev_warn(&scic_to_ihost(scic)->pdev->dev, "Invalid link up!\n");
849 } 811 }
850} 812}
@@ -879,7 +841,7 @@ static void port_state_machine_change(struct scic_sds_port *sci_port,
879/** 841/**
880 * scic_sds_port_general_link_up_handler - phy can be assigned to port? 842 * scic_sds_port_general_link_up_handler - phy can be assigned to port?
881 * @sci_port: scic_sds_port object for which has a phy that has gone link up. 843 * @sci_port: scic_sds_port object for which has a phy that has gone link up.
882 * @sci_phy: This is the struct scic_sds_phy object that has gone link up. 844 * @sci_phy: This is the struct isci_phy object that has gone link up.
883 * @do_notify_user: This parameter specifies whether to inform the user (via 845 * @do_notify_user: This parameter specifies whether to inform the user (via
884 * scic_cb_port_link_up()) as to the fact that a new phy as become ready. 846 * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
885 * 847 *
@@ -890,14 +852,14 @@ static void port_state_machine_change(struct scic_sds_port *sci_port,
890 * the same port. none 852 * the same port. none
891 */ 853 */
892static void scic_sds_port_general_link_up_handler(struct scic_sds_port *sci_port, 854static void scic_sds_port_general_link_up_handler(struct scic_sds_port *sci_port,
893 struct scic_sds_phy *sci_phy, 855 struct isci_phy *iphy,
894 bool do_notify_user) 856 bool do_notify_user)
895{ 857{
896 struct sci_sas_address port_sas_address; 858 struct sci_sas_address port_sas_address;
897 struct sci_sas_address phy_sas_address; 859 struct sci_sas_address phy_sas_address;
898 860
899 scic_sds_port_get_attached_sas_address(sci_port, &port_sas_address); 861 scic_sds_port_get_attached_sas_address(sci_port, &port_sas_address);
900 scic_sds_phy_get_attached_sas_address(sci_phy, &phy_sas_address); 862 scic_sds_phy_get_attached_sas_address(iphy, &phy_sas_address);
901 863
902 /* If the SAS address of the new phy matches the SAS address of 864 /* If the SAS address of the new phy matches the SAS address of
903 * other phys in the port OR this is the first phy in the port, 865 * other phys in the port OR this is the first phy in the port,
@@ -909,11 +871,11 @@ static void scic_sds_port_general_link_up_handler(struct scic_sds_port *sci_port
909 sci_port->active_phy_mask == 0) { 871 sci_port->active_phy_mask == 0) {
910 struct sci_base_state_machine *sm = &sci_port->sm; 872 struct sci_base_state_machine *sm = &sci_port->sm;
911 873
912 scic_sds_port_activate_phy(sci_port, sci_phy, do_notify_user); 874 scic_sds_port_activate_phy(sci_port, iphy, do_notify_user);
913 if (sm->current_state_id == SCI_PORT_RESETTING) 875 if (sm->current_state_id == SCI_PORT_RESETTING)
914 port_state_machine_change(sci_port, SCI_PORT_READY); 876 port_state_machine_change(sci_port, SCI_PORT_READY);
915 } else 877 } else
916 scic_sds_port_invalid_link_up(sci_port, sci_phy); 878 scic_sds_port_invalid_link_up(sci_port, iphy);
917} 879}
918 880
919 881
@@ -957,12 +919,12 @@ static bool scic_sds_port_is_wide(struct scic_sds_port *sci_port)
957 */ 919 */
958bool scic_sds_port_link_detected( 920bool scic_sds_port_link_detected(
959 struct scic_sds_port *sci_port, 921 struct scic_sds_port *sci_port,
960 struct scic_sds_phy *sci_phy) 922 struct isci_phy *iphy)
961{ 923{
962 if ((sci_port->logical_port_index != SCIC_SDS_DUMMY_PORT) && 924 if ((sci_port->logical_port_index != SCIC_SDS_DUMMY_PORT) &&
963 (sci_phy->protocol == SCIC_SDS_PHY_PROTOCOL_SATA) && 925 (iphy->protocol == SCIC_SDS_PHY_PROTOCOL_SATA) &&
964 scic_sds_port_is_wide(sci_port)) { 926 scic_sds_port_is_wide(sci_port)) {
965 scic_sds_port_invalid_link_up(sci_port, sci_phy); 927 scic_sds_port_invalid_link_up(sci_port, iphy);
966 928
967 return false; 929 return false;
968 } 930 }
@@ -1045,47 +1007,26 @@ static void scic_sds_port_update_viit_entry(struct scic_sds_port *sci_port)
1045 &sci_port->viit_registers->status); 1007 &sci_port->viit_registers->status);
1046} 1008}
1047 1009
1048/** 1010enum sas_linkrate scic_sds_port_get_max_allowed_speed(struct scic_sds_port *sci_port)
1049 * This method returns the maximum allowed speed for data transfers on this
1050 * port. This maximum allowed speed evaluates to the maximum speed of the
1051 * slowest phy in the port.
1052 * @sci_port: This parameter specifies the port for which to retrieve the
1053 * maximum allowed speed.
1054 *
1055 * This method returns the maximum negotiated speed of the slowest phy in the
1056 * port.
1057 */
1058enum sas_linkrate scic_sds_port_get_max_allowed_speed(
1059 struct scic_sds_port *sci_port)
1060{ 1011{
1061 u16 index; 1012 u16 index;
1013 struct isci_phy *iphy;
1062 enum sas_linkrate max_allowed_speed = SAS_LINK_RATE_6_0_GBPS; 1014 enum sas_linkrate max_allowed_speed = SAS_LINK_RATE_6_0_GBPS;
1063 struct scic_sds_phy *phy = NULL;
1064 1015
1065 /* 1016 /*
1066 * Loop through all of the phys in this port and find the phy with the 1017 * Loop through all of the phys in this port and find the phy with the
1067 * lowest maximum link rate. */ 1018 * lowest maximum link rate. */
1068 for (index = 0; index < SCI_MAX_PHYS; index++) { 1019 for (index = 0; index < SCI_MAX_PHYS; index++) {
1069 phy = sci_port->phy_table[index]; 1020 iphy = sci_port->phy_table[index];
1070 if ( 1021 if (iphy && scic_sds_port_active_phy(sci_port, iphy) &&
1071 (phy != NULL) 1022 iphy->max_negotiated_speed < max_allowed_speed)
1072 && (scic_sds_port_active_phy(sci_port, phy) == true) 1023 max_allowed_speed = iphy->max_negotiated_speed;
1073 && (phy->max_negotiated_speed < max_allowed_speed)
1074 )
1075 max_allowed_speed = phy->max_negotiated_speed;
1076 } 1024 }
1077 1025
1078 return max_allowed_speed; 1026 return max_allowed_speed;
1079} 1027}
1080 1028
1081/** 1029static void scic_sds_port_suspend_port_task_scheduler(struct scic_sds_port *port)
1082 *
1083 * @sci_port: This is the struct scic_sds_port object to suspend.
1084 *
1085 * This method will susped the port task scheduler for this port object. none
1086 */
1087static void
1088scic_sds_port_suspend_port_task_scheduler(struct scic_sds_port *port)
1089{ 1030{
1090 u32 pts_control_value; 1031 u32 pts_control_value;
1091 1032
@@ -1377,7 +1318,7 @@ enum sci_status scic_sds_port_stop(struct scic_sds_port *sci_port)
1377static enum sci_status scic_port_hard_reset(struct scic_sds_port *sci_port, u32 timeout) 1318static enum sci_status scic_port_hard_reset(struct scic_sds_port *sci_port, u32 timeout)
1378{ 1319{
1379 enum sci_status status = SCI_FAILURE_INVALID_PHY; 1320 enum sci_status status = SCI_FAILURE_INVALID_PHY;
1380 struct scic_sds_phy *selected_phy = NULL; 1321 struct isci_phy *iphy = NULL;
1381 enum scic_sds_port_states state; 1322 enum scic_sds_port_states state;
1382 u32 phy_index; 1323 u32 phy_index;
1383 1324
@@ -1389,22 +1330,21 @@ static enum sci_status scic_port_hard_reset(struct scic_sds_port *sci_port, u32
1389 } 1330 }
1390 1331
1391 /* Select a phy on which we can send the hard reset request. */ 1332 /* Select a phy on which we can send the hard reset request. */
1392 for (phy_index = 0; phy_index < SCI_MAX_PHYS && !selected_phy; phy_index++) { 1333 for (phy_index = 0; phy_index < SCI_MAX_PHYS && !iphy; phy_index++) {
1393 selected_phy = sci_port->phy_table[phy_index]; 1334 iphy = sci_port->phy_table[phy_index];
1394 if (selected_phy && 1335 if (iphy && !scic_sds_port_active_phy(sci_port, iphy)) {
1395 !scic_sds_port_active_phy(sci_port, selected_phy)) {
1396 /* 1336 /*
1397 * We found a phy but it is not ready select 1337 * We found a phy but it is not ready select
1398 * different phy 1338 * different phy
1399 */ 1339 */
1400 selected_phy = NULL; 1340 iphy = NULL;
1401 } 1341 }
1402 } 1342 }
1403 1343
1404 /* If we have a phy then go ahead and start the reset procedure */ 1344 /* If we have a phy then go ahead and start the reset procedure */
1405 if (!selected_phy) 1345 if (!iphy)
1406 return status; 1346 return status;
1407 status = scic_sds_phy_reset(selected_phy); 1347 status = scic_sds_phy_reset(iphy);
1408 1348
1409 if (status != SCI_SUCCESS) 1349 if (status != SCI_SUCCESS)
1410 return status; 1350 return status;
@@ -1412,8 +1352,7 @@ static enum sci_status scic_port_hard_reset(struct scic_sds_port *sci_port, u32
1412 sci_mod_timer(&sci_port->timer, timeout); 1352 sci_mod_timer(&sci_port->timer, timeout);
1413 sci_port->not_ready_reason = SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED; 1353 sci_port->not_ready_reason = SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED;
1414 1354
1415 port_state_machine_change(sci_port, 1355 port_state_machine_change(sci_port, SCI_PORT_RESETTING);
1416 SCI_PORT_RESETTING);
1417 return SCI_SUCCESS; 1356 return SCI_SUCCESS;
1418} 1357}
1419 1358
@@ -1427,7 +1366,7 @@ static enum sci_status scic_port_hard_reset(struct scic_sds_port *sci_port, u32
1427 * status is a failure to add the phy to the port. 1366 * status is a failure to add the phy to the port.
1428 */ 1367 */
1429enum sci_status scic_sds_port_add_phy(struct scic_sds_port *sci_port, 1368enum sci_status scic_sds_port_add_phy(struct scic_sds_port *sci_port,
1430 struct scic_sds_phy *sci_phy) 1369 struct isci_phy *iphy)
1431{ 1370{
1432 enum sci_status status; 1371 enum sci_status status;
1433 enum scic_sds_port_states state; 1372 enum scic_sds_port_states state;
@@ -1446,32 +1385,32 @@ enum sci_status scic_sds_port_add_phy(struct scic_sds_port *sci_port,
1446 /* Make sure that the PHY SAS Address matches the SAS Address 1385 /* Make sure that the PHY SAS Address matches the SAS Address
1447 * for this port 1386 * for this port
1448 */ 1387 */
1449 scic_sds_phy_get_sas_address(sci_phy, &phy_sas_address); 1388 scic_sds_phy_get_sas_address(iphy, &phy_sas_address);
1450 1389
1451 if (port_sas_address.high != phy_sas_address.high || 1390 if (port_sas_address.high != phy_sas_address.high ||
1452 port_sas_address.low != phy_sas_address.low) 1391 port_sas_address.low != phy_sas_address.low)
1453 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION; 1392 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
1454 } 1393 }
1455 return scic_sds_port_set_phy(sci_port, sci_phy); 1394 return scic_sds_port_set_phy(sci_port, iphy);
1456 } 1395 }
1457 case SCI_PORT_SUB_WAITING: 1396 case SCI_PORT_SUB_WAITING:
1458 case SCI_PORT_SUB_OPERATIONAL: 1397 case SCI_PORT_SUB_OPERATIONAL:
1459 status = scic_sds_port_set_phy(sci_port, sci_phy); 1398 status = scic_sds_port_set_phy(sci_port, iphy);
1460 1399
1461 if (status != SCI_SUCCESS) 1400 if (status != SCI_SUCCESS)
1462 return status; 1401 return status;
1463 1402
1464 scic_sds_port_general_link_up_handler(sci_port, sci_phy, true); 1403 scic_sds_port_general_link_up_handler(sci_port, iphy, true);
1465 sci_port->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING; 1404 sci_port->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
1466 port_state_machine_change(sci_port, SCI_PORT_SUB_CONFIGURING); 1405 port_state_machine_change(sci_port, SCI_PORT_SUB_CONFIGURING);
1467 1406
1468 return status; 1407 return status;
1469 case SCI_PORT_SUB_CONFIGURING: 1408 case SCI_PORT_SUB_CONFIGURING:
1470 status = scic_sds_port_set_phy(sci_port, sci_phy); 1409 status = scic_sds_port_set_phy(sci_port, iphy);
1471 1410
1472 if (status != SCI_SUCCESS) 1411 if (status != SCI_SUCCESS)
1473 return status; 1412 return status;
1474 scic_sds_port_general_link_up_handler(sci_port, sci_phy, true); 1413 scic_sds_port_general_link_up_handler(sci_port, iphy, true);
1475 1414
1476 /* Re-enter the configuring state since this may be the last phy in 1415 /* Re-enter the configuring state since this may be the last phy in
1477 * the port. 1416 * the port.
@@ -1496,7 +1435,7 @@ enum sci_status scic_sds_port_add_phy(struct scic_sds_port *sci_port,
1496 * other status is a failure to add the phy to the port. 1435 * other status is a failure to add the phy to the port.
1497 */ 1436 */
1498enum sci_status scic_sds_port_remove_phy(struct scic_sds_port *sci_port, 1437enum sci_status scic_sds_port_remove_phy(struct scic_sds_port *sci_port,
1499 struct scic_sds_phy *sci_phy) 1438 struct isci_phy *iphy)
1500{ 1439{
1501 enum sci_status status; 1440 enum sci_status status;
1502 enum scic_sds_port_states state; 1441 enum scic_sds_port_states state;
@@ -1505,23 +1444,23 @@ enum sci_status scic_sds_port_remove_phy(struct scic_sds_port *sci_port,
1505 1444
1506 switch (state) { 1445 switch (state) {
1507 case SCI_PORT_STOPPED: 1446 case SCI_PORT_STOPPED:
1508 return scic_sds_port_clear_phy(sci_port, sci_phy); 1447 return scic_sds_port_clear_phy(sci_port, iphy);
1509 case SCI_PORT_SUB_OPERATIONAL: 1448 case SCI_PORT_SUB_OPERATIONAL:
1510 status = scic_sds_port_clear_phy(sci_port, sci_phy); 1449 status = scic_sds_port_clear_phy(sci_port, iphy);
1511 if (status != SCI_SUCCESS) 1450 if (status != SCI_SUCCESS)
1512 return status; 1451 return status;
1513 1452
1514 scic_sds_port_deactivate_phy(sci_port, sci_phy, true); 1453 scic_sds_port_deactivate_phy(sci_port, iphy, true);
1515 sci_port->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING; 1454 sci_port->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
1516 port_state_machine_change(sci_port, 1455 port_state_machine_change(sci_port,
1517 SCI_PORT_SUB_CONFIGURING); 1456 SCI_PORT_SUB_CONFIGURING);
1518 return SCI_SUCCESS; 1457 return SCI_SUCCESS;
1519 case SCI_PORT_SUB_CONFIGURING: 1458 case SCI_PORT_SUB_CONFIGURING:
1520 status = scic_sds_port_clear_phy(sci_port, sci_phy); 1459 status = scic_sds_port_clear_phy(sci_port, iphy);
1521 1460
1522 if (status != SCI_SUCCESS) 1461 if (status != SCI_SUCCESS)
1523 return status; 1462 return status;
1524 scic_sds_port_deactivate_phy(sci_port, sci_phy, true); 1463 scic_sds_port_deactivate_phy(sci_port, iphy, true);
1525 1464
1526 /* Re-enter the configuring state since this may be the last phy in 1465 /* Re-enter the configuring state since this may be the last phy in
1527 * the port 1466 * the port
@@ -1537,7 +1476,7 @@ enum sci_status scic_sds_port_remove_phy(struct scic_sds_port *sci_port,
1537} 1476}
1538 1477
1539enum sci_status scic_sds_port_link_up(struct scic_sds_port *sci_port, 1478enum sci_status scic_sds_port_link_up(struct scic_sds_port *sci_port,
1540 struct scic_sds_phy *sci_phy) 1479 struct isci_phy *iphy)
1541{ 1480{
1542 enum scic_sds_port_states state; 1481 enum scic_sds_port_states state;
1543 1482
@@ -1547,13 +1486,13 @@ enum sci_status scic_sds_port_link_up(struct scic_sds_port *sci_port,
1547 /* Since this is the first phy going link up for the port we 1486 /* Since this is the first phy going link up for the port we
1548 * can just enable it and continue 1487 * can just enable it and continue
1549 */ 1488 */
1550 scic_sds_port_activate_phy(sci_port, sci_phy, true); 1489 scic_sds_port_activate_phy(sci_port, iphy, true);
1551 1490
1552 port_state_machine_change(sci_port, 1491 port_state_machine_change(sci_port,
1553 SCI_PORT_SUB_OPERATIONAL); 1492 SCI_PORT_SUB_OPERATIONAL);
1554 return SCI_SUCCESS; 1493 return SCI_SUCCESS;
1555 case SCI_PORT_SUB_OPERATIONAL: 1494 case SCI_PORT_SUB_OPERATIONAL:
1556 scic_sds_port_general_link_up_handler(sci_port, sci_phy, true); 1495 scic_sds_port_general_link_up_handler(sci_port, iphy, true);
1557 return SCI_SUCCESS; 1496 return SCI_SUCCESS;
1558 case SCI_PORT_RESETTING: 1497 case SCI_PORT_RESETTING:
1559 /* TODO We should make sure that the phy that has gone 1498 /* TODO We should make sure that the phy that has gone
@@ -1570,7 +1509,7 @@ enum sci_status scic_sds_port_link_up(struct scic_sds_port *sci_port,
1570 /* In the resetting state we don't notify the user regarding 1509 /* In the resetting state we don't notify the user regarding
1571 * link up and link down notifications. 1510 * link up and link down notifications.
1572 */ 1511 */
1573 scic_sds_port_general_link_up_handler(sci_port, sci_phy, false); 1512 scic_sds_port_general_link_up_handler(sci_port, iphy, false);
1574 return SCI_SUCCESS; 1513 return SCI_SUCCESS;
1575 default: 1514 default:
1576 dev_warn(sciport_to_dev(sci_port), 1515 dev_warn(sciport_to_dev(sci_port),
@@ -1580,14 +1519,14 @@ enum sci_status scic_sds_port_link_up(struct scic_sds_port *sci_port,
1580} 1519}
1581 1520
1582enum sci_status scic_sds_port_link_down(struct scic_sds_port *sci_port, 1521enum sci_status scic_sds_port_link_down(struct scic_sds_port *sci_port,
1583 struct scic_sds_phy *sci_phy) 1522 struct isci_phy *iphy)
1584{ 1523{
1585 enum scic_sds_port_states state; 1524 enum scic_sds_port_states state;
1586 1525
1587 state = sci_port->sm.current_state_id; 1526 state = sci_port->sm.current_state_id;
1588 switch (state) { 1527 switch (state) {
1589 case SCI_PORT_SUB_OPERATIONAL: 1528 case SCI_PORT_SUB_OPERATIONAL:
1590 scic_sds_port_deactivate_phy(sci_port, sci_phy, true); 1529 scic_sds_port_deactivate_phy(sci_port, iphy, true);
1591 1530
1592 /* If there are no active phys left in the port, then 1531 /* If there are no active phys left in the port, then
1593 * transition the port to the WAITING state until such time 1532 * transition the port to the WAITING state until such time
@@ -1600,7 +1539,7 @@ enum sci_status scic_sds_port_link_down(struct scic_sds_port *sci_port,
1600 case SCI_PORT_RESETTING: 1539 case SCI_PORT_RESETTING:
1601 /* In the resetting state we don't notify the user regarding 1540 /* In the resetting state we don't notify the user regarding
1602 * link up and link down notifications. */ 1541 * link up and link down notifications. */
1603 scic_sds_port_deactivate_phy(sci_port, sci_phy, false); 1542 scic_sds_port_deactivate_phy(sci_port, iphy, false);
1604 return SCI_SUCCESS; 1543 return SCI_SUCCESS;
1605 default: 1544 default:
1606 dev_warn(sciport_to_dev(sci_port), 1545 dev_warn(sciport_to_dev(sci_port),
@@ -1879,13 +1818,13 @@ enum isci_status isci_port_get_state(
1879 1818
1880void scic_sds_port_broadcast_change_received( 1819void scic_sds_port_broadcast_change_received(
1881 struct scic_sds_port *sci_port, 1820 struct scic_sds_port *sci_port,
1882 struct scic_sds_phy *sci_phy) 1821 struct isci_phy *iphy)
1883{ 1822{
1884 struct scic_sds_controller *scic = sci_port->owning_controller; 1823 struct scic_sds_controller *scic = sci_port->owning_controller;
1885 struct isci_host *ihost = scic_to_ihost(scic); 1824 struct isci_host *ihost = scic_to_ihost(scic);
1886 1825
1887 /* notify the user. */ 1826 /* notify the user. */
1888 isci_port_bc_change_received(ihost, sci_port, sci_phy); 1827 isci_port_bc_change_received(ihost, sci_port, iphy);
1889} 1828}
1890 1829
1891int isci_port_perform_hard_reset(struct isci_host *ihost, struct isci_port *iport, 1830int isci_port_perform_hard_reset(struct isci_host *ihost, struct isci_port *iport,