blob: 1eefaaeb11418b4f3f3e936fc03ab927d0909708 [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"
60
61
62/**
63 * isci_phy_init() - This function is called by the probe function to
64 * initialize the phy objects. This func assumes that the isci_port objects
65 * associated with the SCU have been initialized.
66 * @isci_phy: This parameter specifies the isci_phy object to initialize
67 * @isci_host: This parameter specifies the parent SCU host object for this
68 * isci_phy
69 * @index: This parameter specifies which SCU phy associates with this
70 * isci_phy. Generally, SCU phy 0 relates isci_phy 0, etc.
71 *
72 */
73void isci_phy_init(
74 struct isci_phy *phy,
75 struct isci_host *isci_host,
76 int index)
77{
Dan Williams150fc6f2011-02-25 10:25:21 -080078 struct scic_sds_controller *scic = isci_host->core_controller;
Dan Williams6f231dd2011-07-02 22:56:22 -070079 struct scic_sds_phy *scic_phy;
Dan Williams150fc6f2011-02-25 10:25:21 -080080 union scic_oem_parameters oem;
Dan Williams6f231dd2011-07-02 22:56:22 -070081 enum sci_status status = SCI_SUCCESS;
Dan Williams150fc6f2011-02-25 10:25:21 -080082 u64 sas_addr;
Dan Williams6f231dd2011-07-02 22:56:22 -070083
84 /*--------------- SCU_Phy Initialization Stuff -----------------------*/
85
Dan Williams150fc6f2011-02-25 10:25:21 -080086 status = scic_controller_get_phy_handle(scic, index, &scic_phy);
Dan Williams6f231dd2011-07-02 22:56:22 -070087 if (status == SCI_SUCCESS) {
88 sci_object_set_association(scic_phy, (void *)phy);
89 phy->sci_phy_handle = scic_phy;
90 } else
91 dev_err(&isci_host->pdev->dev,
92 "failed scic_controller_get_phy_handle\n");
93
Dan Williams150fc6f2011-02-25 10:25:21 -080094 scic_oem_parameters_get(scic, &oem);
95 sas_addr = oem.sds1.phys[index].sas_address.high;
96 sas_addr <<= 32;
97 sas_addr |= oem.sds1.phys[index].sas_address.low;
98 swab64s(&sas_addr);
Dan Williams6f231dd2011-07-02 22:56:22 -070099
Dan Williams150fc6f2011-02-25 10:25:21 -0800100 memcpy(phy->sas_addr, &sas_addr, sizeof(sas_addr));
Dan Williams6f231dd2011-07-02 22:56:22 -0700101
102 phy->isci_port = NULL;
103 phy->sas_phy.enabled = 0;
104 phy->sas_phy.id = index;
105 phy->sas_phy.sas_addr = &phy->sas_addr[0];
106 phy->sas_phy.frame_rcvd = (u8 *)&phy->frame_rcvd;
107 phy->sas_phy.ha = &isci_host->sas_ha;
108 phy->sas_phy.lldd_phy = phy;
109 phy->sas_phy.enabled = 1;
110 phy->sas_phy.class = SAS;
111 phy->sas_phy.iproto = SAS_PROTOCOL_ALL;
112 phy->sas_phy.tproto = 0;
113 phy->sas_phy.type = PHY_TYPE_PHYSICAL;
114 phy->sas_phy.role = PHY_ROLE_INITIATOR;
115 phy->sas_phy.oob_mode = OOB_NOT_CONNECTED;
116 phy->sas_phy.linkrate = SAS_LINK_RATE_UNKNOWN;
117 memset((u8 *)&phy->frame_rcvd, 0, sizeof(phy->frame_rcvd));
118}
119
120
121/**
122 * isci_phy_control() - This function is one of the SAS Domain Template
123 * functions. This is a phy management function.
124 * @phy: This parameter specifies the sphy being controlled.
125 * @func: This parameter specifies the phy control function being invoked.
126 * @buf: This parameter is specific to the phy function being invoked.
127 *
128 * status, zero indicates success.
129 */
130int isci_phy_control(
131 struct asd_sas_phy *phy,
132 enum phy_func func,
133 void *buf)
134{
135 int ret = TMF_RESP_FUNC_COMPLETE;
136 struct isci_phy *isci_phy_ptr = (struct isci_phy *)phy->lldd_phy;
137 struct isci_port *isci_port_ptr = NULL;
138
139 if (isci_phy_ptr != NULL)
140 isci_port_ptr = isci_phy_ptr->isci_port;
141
142 if ((isci_phy_ptr == NULL) || (isci_port_ptr == NULL)) {
143 pr_err("%s: asd_sas_phy %p: lldd_phy %p or "
144 "isci_port %p == NULL!\n",
145 __func__, phy, isci_phy_ptr, isci_port_ptr);
146 return TMF_RESP_FUNC_FAILED;
147 }
148
149 pr_debug("%s: phy %p; func %d; buf %p; isci phy %p, port %p\n",
150 __func__, phy, func, buf, isci_phy_ptr, isci_port_ptr);
151
152 switch (func) {
153 case PHY_FUNC_HARD_RESET:
154 case PHY_FUNC_LINK_RESET:
155
156 /* Perform the port reset. */
157 ret = isci_port_perform_hard_reset(isci_port_ptr, isci_phy_ptr);
158
159 break;
160
161 case PHY_FUNC_DISABLE:
162 default:
163 pr_debug("%s: phy %p; func %d NOT IMPLEMENTED!\n",
164 __func__, phy, func);
165 ret = TMF_RESP_FUNC_FAILED;
166 break;
167 }
168 return ret;
169}