Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * This file is provided under a dual BSD/GPLv2 license.  When using or
0003  * redistributing this file, you may do so under either license.
0004  *
0005  * GPL LICENSE SUMMARY
0006  *
0007  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
0008  *
0009  * This program is free software; you can redistribute it and/or modify
0010  * it under the terms of version 2 of the GNU General Public License as
0011  * published by the Free Software Foundation.
0012  *
0013  * This program is distributed in the hope that it will be useful, but
0014  * WITHOUT ANY WARRANTY; without even the implied warranty of
0015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0016  * General Public License for more details.
0017  *
0018  * You should have received a copy of the GNU General Public License
0019  * along with this program; if not, write to the Free Software
0020  * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
0021  * The full GNU General Public License is included in this distribution
0022  * in the file called LICENSE.GPL.
0023  *
0024  * BSD LICENSE
0025  *
0026  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
0027  * All rights reserved.
0028  *
0029  * Redistribution and use in source and binary forms, with or without
0030  * modification, are permitted provided that the following conditions
0031  * are met:
0032  *
0033  *   * Redistributions of source code must retain the above copyright
0034  *     notice, this list of conditions and the following disclaimer.
0035  *   * Redistributions in binary form must reproduce the above copyright
0036  *     notice, this list of conditions and the following disclaimer in
0037  *     the documentation and/or other materials provided with the
0038  *     distribution.
0039  *   * Neither the name of Intel Corporation nor the names of its
0040  *     contributors may be used to endorse or promote products derived
0041  *     from this software without specific prior written permission.
0042  *
0043  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0044  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0045  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0046  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0047  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0048  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0049  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0050  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0051  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0052  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0053  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0054  */
0055 #ifndef _ISCI_PHY_H_
0056 #define _ISCI_PHY_H_
0057 
0058 #include <scsi/sas.h>
0059 #include <scsi/libsas.h>
0060 #include "isci.h"
0061 #include "sas.h"
0062 
0063 /* This is the timeout value for the SATA phy to wait for a SIGNATURE FIS
0064  * before restarting the starting state machine.  Technically, the old parallel
0065  * ATA specification required up to 30 seconds for a device to issue its
0066  * signature FIS as a result of a soft reset.  Now we see that devices respond
0067  * generally within 15 seconds, but we'll use 25 for now.
0068  */
0069 #define SCIC_SDS_SIGNATURE_FIS_TIMEOUT    25000
0070 
0071 /* This is the timeout for the SATA OOB/SN because the hardware does not
0072  * recognize a hot plug after OOB signal but before the SN signals.  We need to
0073  * make sure after a hotplug timeout if we have not received the speed event
0074  * notification from the hardware that we restart the hardware OOB state
0075  * machine.
0076  */
0077 #define SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT  250
0078 
0079 /**
0080  * isci_phy - hba local phy infrastructure
0081  * @sm:
0082  * @protocol: attached device protocol
0083  * @phy_index: physical index relative to the controller (0-3)
0084  * @bcn_received_while_port_unassigned: bcn to report after port association
0085  * @sata_timer: timeout SATA signature FIS arrival
0086  */
0087 struct isci_phy {
0088     struct sci_base_state_machine sm;
0089     struct isci_port *owning_port;
0090     enum sas_linkrate max_negotiated_speed;
0091     enum sas_protocol protocol;
0092     u8 phy_index;
0093     bool bcn_received_while_port_unassigned;
0094     bool is_in_link_training;
0095     struct sci_timer sata_timer;
0096     struct scu_transport_layer_registers __iomem *transport_layer_registers;
0097     struct scu_link_layer_registers __iomem *link_layer_registers;
0098     struct asd_sas_phy sas_phy;
0099     u8 sas_addr[SAS_ADDR_SIZE];
0100     union {
0101         struct sas_identify_frame iaf;
0102         struct dev_to_host_fis fis;
0103     } frame_rcvd;
0104 };
0105 
0106 static inline struct isci_phy *to_iphy(struct asd_sas_phy *sas_phy)
0107 {
0108     struct isci_phy *iphy = container_of(sas_phy, typeof(*iphy), sas_phy);
0109 
0110     return iphy;
0111 }
0112 
0113 struct sci_phy_cap {
0114     union {
0115         struct {
0116             /*
0117              * The SAS specification indicates the start bit shall
0118              * always be set to
0119              * 1.  This implementation will have the start bit set
0120              * to 0 if the PHY CAPABILITIES were either not
0121              * received or speed negotiation failed.
0122              */
0123             u8 start:1;
0124             u8 tx_ssc_type:1;
0125             u8 res1:2;
0126             u8 req_logical_linkrate:4;
0127 
0128             u32 gen1_no_ssc:1;
0129             u32 gen1_ssc:1;
0130             u32 gen2_no_ssc:1;
0131             u32 gen2_ssc:1;
0132             u32 gen3_no_ssc:1;
0133             u32 gen3_ssc:1;
0134             u32 res2:17;
0135             u32 parity:1;
0136         };
0137         u32 all;
0138     };
0139 }  __packed;
0140 
0141 /* this data structure reflects the link layer transmit identification reg */
0142 struct sci_phy_proto {
0143     union {
0144         struct {
0145             u16 _r_a:1;
0146             u16 smp_iport:1;
0147             u16 stp_iport:1;
0148             u16 ssp_iport:1;
0149             u16 _r_b:4;
0150             u16 _r_c:1;
0151             u16 smp_tport:1;
0152             u16 stp_tport:1;
0153             u16 ssp_tport:1;
0154             u16 _r_d:4;
0155         };
0156         u16 all;
0157     };
0158 } __packed;
0159 
0160 
0161 /**
0162  * struct sci_phy_properties - This structure defines the properties common to
0163  *    all phys that can be retrieved.
0164  *
0165  *
0166  */
0167 struct sci_phy_properties {
0168     /**
0169      * This field specifies the port that currently contains the
0170      * supplied phy.  This field may be set to NULL
0171      * if the phy is not currently contained in a port.
0172      */
0173     struct isci_port *iport;
0174 
0175     /**
0176      * This field specifies the link rate at which the phy is
0177      * currently operating.
0178      */
0179     enum sas_linkrate negotiated_link_rate;
0180 
0181     /**
0182      * This field specifies the index of the phy in relation to other
0183      * phys within the controller.  This index is zero relative.
0184      */
0185     u8 index;
0186 };
0187 
0188 /**
0189  * struct sci_sas_phy_properties - This structure defines the properties,
0190  *    specific to a SAS phy, that can be retrieved.
0191  *
0192  *
0193  */
0194 struct sci_sas_phy_properties {
0195     /**
0196      * This field delineates the Identify Address Frame received
0197      * from the remote end point.
0198      */
0199     struct sas_identify_frame rcvd_iaf;
0200 
0201     /**
0202      * This field delineates the Phy capabilities structure received
0203      * from the remote end point.
0204      */
0205     struct sci_phy_cap rcvd_cap;
0206 
0207 };
0208 
0209 /**
0210  * struct sci_sata_phy_properties - This structure defines the properties,
0211  *    specific to a SATA phy, that can be retrieved.
0212  *
0213  *
0214  */
0215 struct sci_sata_phy_properties {
0216     /**
0217      * This field delineates the signature FIS received from the
0218      * attached target.
0219      */
0220     struct dev_to_host_fis signature_fis;
0221 
0222     /**
0223      * This field specifies to the user if a port selector is connected
0224      * on the specified phy.
0225      */
0226     bool is_port_selector_present;
0227 
0228 };
0229 
0230 /**
0231  * enum sci_phy_counter_id - This enumeration depicts the various pieces of
0232  *    optional information that can be retrieved for a specific phy.
0233  *
0234  *
0235  */
0236 enum sci_phy_counter_id {
0237     /**
0238      * This PHY information field tracks the number of frames received.
0239      */
0240     SCIC_PHY_COUNTER_RECEIVED_FRAME,
0241 
0242     /**
0243      * This PHY information field tracks the number of frames transmitted.
0244      */
0245     SCIC_PHY_COUNTER_TRANSMITTED_FRAME,
0246 
0247     /**
0248      * This PHY information field tracks the number of DWORDs received.
0249      */
0250     SCIC_PHY_COUNTER_RECEIVED_FRAME_WORD,
0251 
0252     /**
0253      * This PHY information field tracks the number of DWORDs transmitted.
0254      */
0255     SCIC_PHY_COUNTER_TRANSMITTED_FRAME_DWORD,
0256 
0257     /**
0258      * This PHY information field tracks the number of times DWORD
0259      * synchronization was lost.
0260      */
0261     SCIC_PHY_COUNTER_LOSS_OF_SYNC_ERROR,
0262 
0263     /**
0264      * This PHY information field tracks the number of received DWORDs with
0265      * running disparity errors.
0266      */
0267     SCIC_PHY_COUNTER_RECEIVED_DISPARITY_ERROR,
0268 
0269     /**
0270      * This PHY information field tracks the number of received frames with a
0271      * CRC error (not including short or truncated frames).
0272      */
0273     SCIC_PHY_COUNTER_RECEIVED_FRAME_CRC_ERROR,
0274 
0275     /**
0276      * This PHY information field tracks the number of DONE (ACK/NAK TIMEOUT)
0277      * primitives received.
0278      */
0279     SCIC_PHY_COUNTER_RECEIVED_DONE_ACK_NAK_TIMEOUT,
0280 
0281     /**
0282      * This PHY information field tracks the number of DONE (ACK/NAK TIMEOUT)
0283      * primitives transmitted.
0284      */
0285     SCIC_PHY_COUNTER_TRANSMITTED_DONE_ACK_NAK_TIMEOUT,
0286 
0287     /**
0288      * This PHY information field tracks the number of times the inactivity
0289      * timer for connections on the phy has been utilized.
0290      */
0291     SCIC_PHY_COUNTER_INACTIVITY_TIMER_EXPIRED,
0292 
0293     /**
0294      * This PHY information field tracks the number of DONE (CREDIT TIMEOUT)
0295      * primitives received.
0296      */
0297     SCIC_PHY_COUNTER_RECEIVED_DONE_CREDIT_TIMEOUT,
0298 
0299     /**
0300      * This PHY information field tracks the number of DONE (CREDIT TIMEOUT)
0301      * primitives transmitted.
0302      */
0303     SCIC_PHY_COUNTER_TRANSMITTED_DONE_CREDIT_TIMEOUT,
0304 
0305     /**
0306      * This PHY information field tracks the number of CREDIT BLOCKED
0307      * primitives received.
0308      * @note Depending on remote device implementation, credit blocks
0309      *       may occur regularly.
0310      */
0311     SCIC_PHY_COUNTER_RECEIVED_CREDIT_BLOCKED,
0312 
0313     /**
0314      * This PHY information field contains the number of short frames
0315      * received.  A short frame is simply a frame smaller then what is
0316      * allowed by either the SAS or SATA specification.
0317      */
0318     SCIC_PHY_COUNTER_RECEIVED_SHORT_FRAME,
0319 
0320     /**
0321      * This PHY information field contains the number of frames received after
0322      * credit has been exhausted.
0323      */
0324     SCIC_PHY_COUNTER_RECEIVED_FRAME_WITHOUT_CREDIT,
0325 
0326     /**
0327      * This PHY information field contains the number of frames received after
0328      * a DONE has been received.
0329      */
0330     SCIC_PHY_COUNTER_RECEIVED_FRAME_AFTER_DONE,
0331 
0332     /**
0333      * This PHY information field contains the number of times the phy
0334      * failed to achieve DWORD synchronization during speed negotiation.
0335      */
0336     SCIC_PHY_COUNTER_SN_DWORD_SYNC_ERROR
0337 };
0338 
0339 /**
0340  * enum sci_phy_states - phy state machine states
0341  * @SCI_PHY_INITIAL: Simply the initial state for the base domain state
0342  *           machine.
0343  * @SCI_PHY_STOPPED: phy has successfully been stopped.  In this state
0344  *           no new IO operations are permitted on this phy.
0345  * @SCI_PHY_STARTING: the phy is in the process of becomming ready.  In
0346  *            this state no new IO operations are permitted on
0347  *            this phy.
0348  * @SCI_PHY_SUB_INITIAL: Initial state
0349  * @SCI_PHY_SUB_AWAIT_OSSP_EN: Wait state for the hardware OSSP event
0350  *                 type notification
0351  * @SCI_PHY_SUB_AWAIT_SAS_SPEED_EN: Wait state for the PHY speed
0352  *                  notification
0353  * @SCI_PHY_SUB_AWAIT_IAF_UF: Wait state for the IAF Unsolicited frame
0354  *                notification
0355  * @SCI_PHY_SUB_AWAIT_SAS_POWER: Wait state for the request to consume
0356  *               power
0357  * @SCI_PHY_SUB_AWAIT_SATA_POWER: Wait state for request to consume
0358  *                power
0359  * @SCI_PHY_SUB_AWAIT_SATA_PHY_EN: Wait state for the SATA PHY
0360  *                 notification
0361  * @SCI_PHY_SUB_AWAIT_SATA_SPEED_EN: Wait for the SATA PHY speed
0362  *                   notification
0363  * @SCI_PHY_SUB_AWAIT_SIG_FIS_UF: Wait state for the SIGNATURE FIS
0364  *                unsolicited frame notification
0365  * @SCI_PHY_SUB_FINAL: Exit state for this state machine
0366  * @SCI_PHY_READY: phy is now ready.  Thus, the user is able to perform
0367  *         IO operations utilizing this phy as long as it is
0368  *         currently part of a valid port.  This state is
0369  *         entered from the STARTING state.
0370  * @SCI_PHY_RESETTING: phy is in the process of being reset.  In this
0371  *             state no new IO operations are permitted on this
0372  *             phy.  This state is entered from the READY state.
0373  * @SCI_PHY_FINAL: Simply the final state for the base phy state
0374  *         machine.
0375  */
0376 #define PHY_STATES {\
0377     C(PHY_INITIAL),\
0378     C(PHY_STOPPED),\
0379     C(PHY_STARTING),\
0380     C(PHY_SUB_INITIAL),\
0381     C(PHY_SUB_AWAIT_OSSP_EN),\
0382     C(PHY_SUB_AWAIT_SAS_SPEED_EN),\
0383     C(PHY_SUB_AWAIT_IAF_UF),\
0384     C(PHY_SUB_AWAIT_SAS_POWER),\
0385     C(PHY_SUB_AWAIT_SATA_POWER),\
0386     C(PHY_SUB_AWAIT_SATA_PHY_EN),\
0387     C(PHY_SUB_AWAIT_SATA_SPEED_EN),\
0388     C(PHY_SUB_AWAIT_SIG_FIS_UF),\
0389     C(PHY_SUB_FINAL),\
0390     C(PHY_READY),\
0391     C(PHY_RESETTING),\
0392     C(PHY_FINAL),\
0393     }
0394 #undef C
0395 #define C(a) SCI_##a
0396 enum sci_phy_states PHY_STATES;
0397 #undef C
0398 
0399 void sci_phy_construct(
0400     struct isci_phy *iphy,
0401     struct isci_port *iport,
0402     u8 phy_index);
0403 
0404 struct isci_port *phy_get_non_dummy_port(struct isci_phy *iphy);
0405 
0406 void sci_phy_set_port(
0407     struct isci_phy *iphy,
0408     struct isci_port *iport);
0409 
0410 enum sci_status sci_phy_initialize(
0411     struct isci_phy *iphy,
0412     struct scu_transport_layer_registers __iomem *transport_layer_registers,
0413     struct scu_link_layer_registers __iomem *link_layer_registers);
0414 
0415 enum sci_status sci_phy_start(
0416     struct isci_phy *iphy);
0417 
0418 enum sci_status sci_phy_stop(
0419     struct isci_phy *iphy);
0420 
0421 enum sci_status sci_phy_reset(
0422     struct isci_phy *iphy);
0423 
0424 void sci_phy_resume(
0425     struct isci_phy *iphy);
0426 
0427 void sci_phy_setup_transport(
0428     struct isci_phy *iphy,
0429     u32 device_id);
0430 
0431 enum sci_status sci_phy_event_handler(
0432     struct isci_phy *iphy,
0433     u32 event_code);
0434 
0435 enum sci_status sci_phy_frame_handler(
0436     struct isci_phy *iphy,
0437     u32 frame_index);
0438 
0439 enum sci_status sci_phy_consume_power_handler(
0440     struct isci_phy *iphy);
0441 
0442 void sci_phy_get_sas_address(
0443     struct isci_phy *iphy,
0444     struct sci_sas_address *sas_address);
0445 
0446 void sci_phy_get_attached_sas_address(
0447     struct isci_phy *iphy,
0448     struct sci_sas_address *sas_address);
0449 
0450 void sci_phy_get_protocols(
0451     struct isci_phy *iphy,
0452     struct sci_phy_proto *protocols);
0453 enum sas_linkrate sci_phy_linkrate(struct isci_phy *iphy);
0454 
0455 struct isci_host;
0456 void isci_phy_init(struct isci_phy *iphy, struct isci_host *ihost, int index);
0457 int isci_phy_control(struct asd_sas_phy *phy, enum phy_func func, void *buf);
0458 
0459 #endif /* !defined(_ISCI_PHY_H_) */