blob: decc0c05a3dd7714df3b74163389c1f45d3b5f0f [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
Dave Jiang4d07f7f2011-03-02 12:31:24 -080061struct scic_sds_phy;
62extern enum sci_status scic_sds_phy_start(struct scic_sds_phy *sci_phy);
63extern enum sci_status scic_sds_phy_stop(struct scic_sds_phy *sci_phy);
Dan Williams6f231dd2011-07-02 22:56:22 -070064
65/**
66 * isci_phy_init() - This function is called by the probe function to
67 * initialize the phy objects. This func assumes that the isci_port objects
68 * associated with the SCU have been initialized.
69 * @isci_phy: This parameter specifies the isci_phy object to initialize
70 * @isci_host: This parameter specifies the parent SCU host object for this
71 * isci_phy
72 * @index: This parameter specifies which SCU phy associates with this
73 * isci_phy. Generally, SCU phy 0 relates isci_phy 0, etc.
74 *
75 */
76void isci_phy_init(
77 struct isci_phy *phy,
78 struct isci_host *isci_host,
79 int index)
80{
Dan Williams150fc6f2011-02-25 10:25:21 -080081 struct scic_sds_controller *scic = isci_host->core_controller;
Dan Williams6f231dd2011-07-02 22:56:22 -070082 struct scic_sds_phy *scic_phy;
Dan Williams150fc6f2011-02-25 10:25:21 -080083 union scic_oem_parameters oem;
Dan Williams6f231dd2011-07-02 22:56:22 -070084 enum sci_status status = SCI_SUCCESS;
Dan Williams150fc6f2011-02-25 10:25:21 -080085 u64 sas_addr;
Dan Williams6f231dd2011-07-02 22:56:22 -070086
87 /*--------------- SCU_Phy Initialization Stuff -----------------------*/
88
Dan Williams150fc6f2011-02-25 10:25:21 -080089 status = scic_controller_get_phy_handle(scic, index, &scic_phy);
Dan Williams6f231dd2011-07-02 22:56:22 -070090 if (status == SCI_SUCCESS) {
91 sci_object_set_association(scic_phy, (void *)phy);
92 phy->sci_phy_handle = scic_phy;
93 } else
94 dev_err(&isci_host->pdev->dev,
95 "failed scic_controller_get_phy_handle\n");
96
Dan Williams150fc6f2011-02-25 10:25:21 -080097 scic_oem_parameters_get(scic, &oem);
98 sas_addr = oem.sds1.phys[index].sas_address.high;
99 sas_addr <<= 32;
100 sas_addr |= oem.sds1.phys[index].sas_address.low;
101 swab64s(&sas_addr);
Dan Williams6f231dd2011-07-02 22:56:22 -0700102
Dan Williams150fc6f2011-02-25 10:25:21 -0800103 memcpy(phy->sas_addr, &sas_addr, sizeof(sas_addr));
Dan Williams6f231dd2011-07-02 22:56:22 -0700104
105 phy->isci_port = NULL;
106 phy->sas_phy.enabled = 0;
107 phy->sas_phy.id = index;
108 phy->sas_phy.sas_addr = &phy->sas_addr[0];
109 phy->sas_phy.frame_rcvd = (u8 *)&phy->frame_rcvd;
110 phy->sas_phy.ha = &isci_host->sas_ha;
111 phy->sas_phy.lldd_phy = phy;
112 phy->sas_phy.enabled = 1;
113 phy->sas_phy.class = SAS;
114 phy->sas_phy.iproto = SAS_PROTOCOL_ALL;
115 phy->sas_phy.tproto = 0;
116 phy->sas_phy.type = PHY_TYPE_PHYSICAL;
117 phy->sas_phy.role = PHY_ROLE_INITIATOR;
118 phy->sas_phy.oob_mode = OOB_NOT_CONNECTED;
119 phy->sas_phy.linkrate = SAS_LINK_RATE_UNKNOWN;
120 memset((u8 *)&phy->frame_rcvd, 0, sizeof(phy->frame_rcvd));
121}
122
123
124/**
125 * isci_phy_control() - This function is one of the SAS Domain Template
126 * functions. This is a phy management function.
127 * @phy: This parameter specifies the sphy being controlled.
128 * @func: This parameter specifies the phy control function being invoked.
129 * @buf: This parameter is specific to the phy function being invoked.
130 *
131 * status, zero indicates success.
132 */
Dave Jiang4d07f7f2011-03-02 12:31:24 -0800133int isci_phy_control(struct asd_sas_phy *sas_phy,
134 enum phy_func func,
135 void *buf)
Dan Williams6f231dd2011-07-02 22:56:22 -0700136{
Dave Jiang4d07f7f2011-03-02 12:31:24 -0800137 int ret = 0;
138 struct isci_phy *iphy = sas_phy->lldd_phy;
139 struct isci_port *iport = iphy->isci_port;
140 struct isci_host *ihost = sas_phy->ha->lldd_ha;
141 unsigned long flags;
Dan Williams6f231dd2011-07-02 22:56:22 -0700142
Dave Jiang4d07f7f2011-03-02 12:31:24 -0800143 dev_dbg(&ihost->pdev->dev,
144 "%s: phy %p; func %d; buf %p; isci phy %p, port %p\n",
145 __func__, sas_phy, func, buf, iphy, iport);
Dan Williams6f231dd2011-07-02 22:56:22 -0700146
147 switch (func) {
Dave Jiang4d07f7f2011-03-02 12:31:24 -0800148 case PHY_FUNC_DISABLE:
149 spin_lock_irqsave(&ihost->scic_lock, flags);
150 scic_sds_phy_stop(iphy->sci_phy_handle);
151 spin_unlock_irqrestore(&ihost->scic_lock, flags);
152 break;
153
Dan Williams6f231dd2011-07-02 22:56:22 -0700154 case PHY_FUNC_LINK_RESET:
Dave Jiang4d07f7f2011-03-02 12:31:24 -0800155 spin_lock_irqsave(&ihost->scic_lock, flags);
156 scic_sds_phy_stop(iphy->sci_phy_handle);
157 scic_sds_phy_start(iphy->sci_phy_handle);
158 spin_unlock_irqrestore(&ihost->scic_lock, flags);
159 break;
160
161 case PHY_FUNC_HARD_RESET:
162 if (!iport)
163 return -ENODEV;
Dan Williams6f231dd2011-07-02 22:56:22 -0700164
165 /* Perform the port reset. */
Dave Jiang4d07f7f2011-03-02 12:31:24 -0800166 ret = isci_port_perform_hard_reset(iport, iphy);
Dan Williams6f231dd2011-07-02 22:56:22 -0700167
168 break;
169
Dan Williams6f231dd2011-07-02 22:56:22 -0700170 default:
Dave Jiang4d07f7f2011-03-02 12:31:24 -0800171 dev_dbg(&ihost->pdev->dev,
172 "%s: phy %p; func %d NOT IMPLEMENTED!\n",
173 __func__, sas_phy, func);
174 ret = -ENOSYS;
Dan Williams6f231dd2011-07-02 22:56:22 -0700175 break;
176 }
177 return ret;
178}