blob: 328004918329eb21260bdff0b1b4dfe700a0cd3d [file] [log] [blame]
Dan Williams6f231dd2011-07-02 22:56:22 -07001/*
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 "phy.h"
58#include "scic_port.h"
59#include "scic_config_parameters.h"
Maciej Patelczyke1e72a02011-04-28 22:06:11 +000060#include "core/scic_sds_phy.h"
Dan Williams6f231dd2011-07-02 22:56:22 -070061
Dave Jiang4d07f7f2011-03-02 12:31:24 -080062struct scic_sds_phy;
63extern enum sci_status scic_sds_phy_start(struct scic_sds_phy *sci_phy);
64extern enum sci_status scic_sds_phy_stop(struct scic_sds_phy *sci_phy);
Dan Williams6f231dd2011-07-02 22:56:22 -070065
Dan Williams4b339812011-05-06 17:36:38 -070066void isci_phy_init(struct isci_phy *iphy, struct isci_host *ihost, int index)
Dan Williams6f231dd2011-07-02 22:56:22 -070067{
Dan Williams150fc6f2011-02-25 10:25:21 -080068 union scic_oem_parameters oem;
Dan Williams4b339812011-05-06 17:36:38 -070069 u64 sci_sas_addr;
70 __be64 sas_addr;
Dan Williams6f231dd2011-07-02 22:56:22 -070071
Dan Williams4b339812011-05-06 17:36:38 -070072 scic_oem_parameters_get(&ihost->sci, &oem);
73 sci_sas_addr = oem.sds1.phys[index].sas_address.high;
74 sci_sas_addr <<= 32;
75 sci_sas_addr |= oem.sds1.phys[index].sas_address.low;
76 sas_addr = cpu_to_be64(sci_sas_addr);
77 memcpy(iphy->sas_addr, &sas_addr, sizeof(sas_addr));
Dan Williams6f231dd2011-07-02 22:56:22 -070078
Dan Williams4b339812011-05-06 17:36:38 -070079 iphy->isci_port = NULL;
80 iphy->sas_phy.enabled = 0;
81 iphy->sas_phy.id = index;
82 iphy->sas_phy.sas_addr = &iphy->sas_addr[0];
83 iphy->sas_phy.frame_rcvd = (u8 *)&iphy->frame_rcvd;
84 iphy->sas_phy.ha = &ihost->sas_ha;
85 iphy->sas_phy.lldd_phy = iphy;
86 iphy->sas_phy.enabled = 1;
87 iphy->sas_phy.class = SAS;
88 iphy->sas_phy.iproto = SAS_PROTOCOL_ALL;
89 iphy->sas_phy.tproto = 0;
90 iphy->sas_phy.type = PHY_TYPE_PHYSICAL;
91 iphy->sas_phy.role = PHY_ROLE_INITIATOR;
92 iphy->sas_phy.oob_mode = OOB_NOT_CONNECTED;
93 iphy->sas_phy.linkrate = SAS_LINK_RATE_UNKNOWN;
94 memset(&iphy->frame_rcvd, 0, sizeof(iphy->frame_rcvd));
Dan Williams6f231dd2011-07-02 22:56:22 -070095}
96
97
98/**
99 * isci_phy_control() - This function is one of the SAS Domain Template
100 * functions. This is a phy management function.
101 * @phy: This parameter specifies the sphy being controlled.
102 * @func: This parameter specifies the phy control function being invoked.
103 * @buf: This parameter is specific to the phy function being invoked.
104 *
105 * status, zero indicates success.
106 */
Dave Jiang4d07f7f2011-03-02 12:31:24 -0800107int isci_phy_control(struct asd_sas_phy *sas_phy,
108 enum phy_func func,
109 void *buf)
Dan Williams6f231dd2011-07-02 22:56:22 -0700110{
Dave Jiang4d07f7f2011-03-02 12:31:24 -0800111 int ret = 0;
112 struct isci_phy *iphy = sas_phy->lldd_phy;
113 struct isci_port *iport = iphy->isci_port;
114 struct isci_host *ihost = sas_phy->ha->lldd_ha;
115 unsigned long flags;
Dan Williams6f231dd2011-07-02 22:56:22 -0700116
Dave Jiang4d07f7f2011-03-02 12:31:24 -0800117 dev_dbg(&ihost->pdev->dev,
118 "%s: phy %p; func %d; buf %p; isci phy %p, port %p\n",
119 __func__, sas_phy, func, buf, iphy, iport);
Dan Williams6f231dd2011-07-02 22:56:22 -0700120
121 switch (func) {
Dave Jiang4d07f7f2011-03-02 12:31:24 -0800122 case PHY_FUNC_DISABLE:
123 spin_lock_irqsave(&ihost->scic_lock, flags);
Dan Williams4b339812011-05-06 17:36:38 -0700124 scic_sds_phy_stop(&iphy->sci);
Dave Jiang4d07f7f2011-03-02 12:31:24 -0800125 spin_unlock_irqrestore(&ihost->scic_lock, flags);
126 break;
127
Dan Williams6f231dd2011-07-02 22:56:22 -0700128 case PHY_FUNC_LINK_RESET:
Dave Jiang4d07f7f2011-03-02 12:31:24 -0800129 spin_lock_irqsave(&ihost->scic_lock, flags);
Dan Williams4b339812011-05-06 17:36:38 -0700130 scic_sds_phy_stop(&iphy->sci);
131 scic_sds_phy_start(&iphy->sci);
Dave Jiang4d07f7f2011-03-02 12:31:24 -0800132 spin_unlock_irqrestore(&ihost->scic_lock, flags);
133 break;
134
135 case PHY_FUNC_HARD_RESET:
136 if (!iport)
137 return -ENODEV;
Dan Williams6f231dd2011-07-02 22:56:22 -0700138
139 /* Perform the port reset. */
Dan Williams4393aa42011-03-31 13:10:44 -0700140 ret = isci_port_perform_hard_reset(ihost, iport, iphy);
Dan Williams6f231dd2011-07-02 22:56:22 -0700141
142 break;
143
Dan Williams6f231dd2011-07-02 22:56:22 -0700144 default:
Dave Jiang4d07f7f2011-03-02 12:31:24 -0800145 dev_dbg(&ihost->pdev->dev,
146 "%s: phy %p; func %d NOT IMPLEMENTED!\n",
147 __func__, sas_phy, func);
148 ret = -ENOSYS;
Dan Williams6f231dd2011-07-02 22:56:22 -0700149 break;
150 }
151 return ret;
152}