Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 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" |
Maciej Patelczyk | e1e72a0 | 2011-04-28 22:06:11 +0000 | [diff] [blame] | 60 | #include "core/scic_sds_phy.h" |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 61 | |
Dave Jiang | 4d07f7f | 2011-03-02 12:31:24 -0800 | [diff] [blame] | 62 | struct scic_sds_phy; |
| 63 | extern enum sci_status scic_sds_phy_start(struct scic_sds_phy *sci_phy); |
| 64 | extern enum sci_status scic_sds_phy_stop(struct scic_sds_phy *sci_phy); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 65 | |
Dan Williams | 4b33981 | 2011-05-06 17:36:38 -0700 | [diff] [blame^] | 66 | void isci_phy_init(struct isci_phy *iphy, struct isci_host *ihost, int index) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 67 | { |
Dan Williams | 150fc6f | 2011-02-25 10:25:21 -0800 | [diff] [blame] | 68 | union scic_oem_parameters oem; |
Dan Williams | 4b33981 | 2011-05-06 17:36:38 -0700 | [diff] [blame^] | 69 | u64 sci_sas_addr; |
| 70 | __be64 sas_addr; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 71 | |
Dan Williams | 4b33981 | 2011-05-06 17:36:38 -0700 | [diff] [blame^] | 72 | 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 Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 78 | |
Dan Williams | 4b33981 | 2011-05-06 17:36:38 -0700 | [diff] [blame^] | 79 | 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 Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 95 | } |
| 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 Jiang | 4d07f7f | 2011-03-02 12:31:24 -0800 | [diff] [blame] | 107 | int isci_phy_control(struct asd_sas_phy *sas_phy, |
| 108 | enum phy_func func, |
| 109 | void *buf) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 110 | { |
Dave Jiang | 4d07f7f | 2011-03-02 12:31:24 -0800 | [diff] [blame] | 111 | 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 Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 116 | |
Dave Jiang | 4d07f7f | 2011-03-02 12:31:24 -0800 | [diff] [blame] | 117 | 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 Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 120 | |
| 121 | switch (func) { |
Dave Jiang | 4d07f7f | 2011-03-02 12:31:24 -0800 | [diff] [blame] | 122 | case PHY_FUNC_DISABLE: |
| 123 | spin_lock_irqsave(&ihost->scic_lock, flags); |
Dan Williams | 4b33981 | 2011-05-06 17:36:38 -0700 | [diff] [blame^] | 124 | scic_sds_phy_stop(&iphy->sci); |
Dave Jiang | 4d07f7f | 2011-03-02 12:31:24 -0800 | [diff] [blame] | 125 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
| 126 | break; |
| 127 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 128 | case PHY_FUNC_LINK_RESET: |
Dave Jiang | 4d07f7f | 2011-03-02 12:31:24 -0800 | [diff] [blame] | 129 | spin_lock_irqsave(&ihost->scic_lock, flags); |
Dan Williams | 4b33981 | 2011-05-06 17:36:38 -0700 | [diff] [blame^] | 130 | scic_sds_phy_stop(&iphy->sci); |
| 131 | scic_sds_phy_start(&iphy->sci); |
Dave Jiang | 4d07f7f | 2011-03-02 12:31:24 -0800 | [diff] [blame] | 132 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
| 133 | break; |
| 134 | |
| 135 | case PHY_FUNC_HARD_RESET: |
| 136 | if (!iport) |
| 137 | return -ENODEV; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 138 | |
| 139 | /* Perform the port reset. */ |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 140 | ret = isci_port_perform_hard_reset(ihost, iport, iphy); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 141 | |
| 142 | break; |
| 143 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 144 | default: |
Dave Jiang | 4d07f7f | 2011-03-02 12:31:24 -0800 | [diff] [blame] | 145 | dev_dbg(&ihost->pdev->dev, |
| 146 | "%s: phy %p; func %d NOT IMPLEMENTED!\n", |
| 147 | __func__, sas_phy, func); |
| 148 | ret = -ENOSYS; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 149 | break; |
| 150 | } |
| 151 | return ret; |
| 152 | } |