isci: Intel(R) C600 Series Chipset Storage Control Unit Driver
[deliverable/linux.git] / drivers / scsi / isci / phy.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 "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 */
73 void isci_phy_init(
74 struct isci_phy *phy,
75 struct isci_host *isci_host,
76 int index)
77 {
78 struct scic_sds_controller *controller = isci_host->core_controller;
79 struct scic_sds_phy *scic_phy;
80 union scic_oem_parameters oem_parameters;
81 enum sci_status status = SCI_SUCCESS;
82
83 /*--------------- SCU_Phy Initialization Stuff -----------------------*/
84
85 status = scic_controller_get_phy_handle(controller, index, &scic_phy);
86 if (status == SCI_SUCCESS) {
87 sci_object_set_association(scic_phy, (void *)phy);
88 phy->sci_phy_handle = scic_phy;
89 } else
90 dev_err(&isci_host->pdev->dev,
91 "failed scic_controller_get_phy_handle\n");
92
93 scic_oem_parameters_get(controller, &oem_parameters);
94
95 phy->sas_addr[0] = oem_parameters.sds1.phys[index].sas_address.low
96 & 0xFF;
97 phy->sas_addr[1] = (oem_parameters.sds1.phys[index].sas_address.low
98 >> 8) & 0xFF;
99 phy->sas_addr[2] = (oem_parameters.sds1.phys[index].sas_address.low
100 >> 16) & 0xFF;
101 phy->sas_addr[3] = (oem_parameters.sds1.phys[index].sas_address.low
102 >> 24) & 0xFF;
103 phy->sas_addr[4] = oem_parameters.sds1.phys[index].sas_address.high
104 & 0xFF;
105 phy->sas_addr[5] = (oem_parameters.sds1.phys[index].sas_address.high
106 >> 8) & 0xFF;
107 phy->sas_addr[6] = (oem_parameters.sds1.phys[index].sas_address.high
108 >> 16) & 0xFF;
109 phy->sas_addr[7] = (oem_parameters.sds1.phys[index].sas_address.high
110 >> 24) & 0xFF;
111
112 phy->isci_port = NULL;
113 phy->sas_phy.enabled = 0;
114 phy->sas_phy.id = index;
115 phy->sas_phy.sas_addr = &phy->sas_addr[0];
116 phy->sas_phy.frame_rcvd = (u8 *)&phy->frame_rcvd;
117 phy->sas_phy.ha = &isci_host->sas_ha;
118 phy->sas_phy.lldd_phy = phy;
119 phy->sas_phy.enabled = 1;
120 phy->sas_phy.class = SAS;
121 phy->sas_phy.iproto = SAS_PROTOCOL_ALL;
122 phy->sas_phy.tproto = 0;
123 phy->sas_phy.type = PHY_TYPE_PHYSICAL;
124 phy->sas_phy.role = PHY_ROLE_INITIATOR;
125 phy->sas_phy.oob_mode = OOB_NOT_CONNECTED;
126 phy->sas_phy.linkrate = SAS_LINK_RATE_UNKNOWN;
127 memset((u8 *)&phy->frame_rcvd, 0, sizeof(phy->frame_rcvd));
128 }
129
130
131 /**
132 * isci_phy_control() - This function is one of the SAS Domain Template
133 * functions. This is a phy management function.
134 * @phy: This parameter specifies the sphy being controlled.
135 * @func: This parameter specifies the phy control function being invoked.
136 * @buf: This parameter is specific to the phy function being invoked.
137 *
138 * status, zero indicates success.
139 */
140 int isci_phy_control(
141 struct asd_sas_phy *phy,
142 enum phy_func func,
143 void *buf)
144 {
145 int ret = TMF_RESP_FUNC_COMPLETE;
146 struct isci_phy *isci_phy_ptr = (struct isci_phy *)phy->lldd_phy;
147 struct isci_port *isci_port_ptr = NULL;
148
149 if (isci_phy_ptr != NULL)
150 isci_port_ptr = isci_phy_ptr->isci_port;
151
152 if ((isci_phy_ptr == NULL) || (isci_port_ptr == NULL)) {
153 pr_err("%s: asd_sas_phy %p: lldd_phy %p or "
154 "isci_port %p == NULL!\n",
155 __func__, phy, isci_phy_ptr, isci_port_ptr);
156 return TMF_RESP_FUNC_FAILED;
157 }
158
159 pr_debug("%s: phy %p; func %d; buf %p; isci phy %p, port %p\n",
160 __func__, phy, func, buf, isci_phy_ptr, isci_port_ptr);
161
162 switch (func) {
163 case PHY_FUNC_HARD_RESET:
164 case PHY_FUNC_LINK_RESET:
165
166 /* Perform the port reset. */
167 ret = isci_port_perform_hard_reset(isci_port_ptr, isci_phy_ptr);
168
169 break;
170
171 case PHY_FUNC_DISABLE:
172 default:
173 pr_debug("%s: phy %p; func %d NOT IMPLEMENTED!\n",
174 __func__, phy, func);
175 ret = TMF_RESP_FUNC_FAILED;
176 break;
177 }
178 return ret;
179 }
This page took 0.043013 seconds and 5 git commands to generate.