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 _SCI_HOST_H_
0056 #define _SCI_HOST_H_
0057 
0058 #include <scsi/sas_ata.h>
0059 #include "remote_device.h"
0060 #include "phy.h"
0061 #include "isci.h"
0062 #include "remote_node_table.h"
0063 #include "registers.h"
0064 #include "unsolicited_frame_control.h"
0065 #include "probe_roms.h"
0066 
0067 struct isci_request;
0068 struct scu_task_context;
0069 
0070 
0071 /**
0072  * struct sci_power_control -
0073  *
0074  * This structure defines the fields for managing power control for direct
0075  * attached disk devices.
0076  */
0077 struct sci_power_control {
0078     /**
0079      * This field is set when the power control timer is running and cleared when
0080      * it is not.
0081      */
0082     bool timer_started;
0083 
0084     /**
0085      * Timer to control when the directed attached disks can consume power.
0086      */
0087     struct sci_timer timer;
0088 
0089     /**
0090      * This field is used to keep track of how many phys are put into the
0091      * requesters field.
0092      */
0093     u8 phys_waiting;
0094 
0095     /**
0096      * This field is used to keep track of how many phys have been granted to consume power
0097      */
0098     u8 phys_granted_power;
0099 
0100     /**
0101      * This field is an array of phys that we are waiting on. The phys are direct
0102      * mapped into requesters via struct sci_phy.phy_index
0103      */
0104     struct isci_phy *requesters[SCI_MAX_PHYS];
0105 
0106 };
0107 
0108 struct sci_port_configuration_agent;
0109 typedef void (*port_config_fn)(struct isci_host *,
0110                    struct sci_port_configuration_agent *,
0111                    struct isci_port *, struct isci_phy *);
0112 bool is_port_config_apc(struct isci_host *ihost);
0113 bool is_controller_start_complete(struct isci_host *ihost);
0114 
0115 struct sci_port_configuration_agent {
0116     u16 phy_configured_mask;
0117     u16 phy_ready_mask;
0118     struct {
0119         u8 min_index;
0120         u8 max_index;
0121     } phy_valid_port_range[SCI_MAX_PHYS];
0122     bool timer_pending;
0123     port_config_fn link_up_handler;
0124     port_config_fn link_down_handler;
0125     struct sci_timer    timer;
0126 };
0127 
0128 /**
0129  * isci_host - primary host/controller object
0130  * @timer: timeout start/stop operations
0131  * @device_table: rni (hw remote node index) to remote device lookup table
0132  * @available_remote_nodes: rni allocator
0133  * @power_control: manage device spin up
0134  * @io_request_sequence: generation number for tci's (task contexts)
0135  * @task_context_table: hw task context table
0136  * @remote_node_context_table: hw remote node context table
0137  * @completion_queue: hw-producer driver-consumer communication ring
0138  * @completion_queue_get: tracks the driver 'head' of the ring to notify hw
0139  * @logical_port_entries: min({driver|silicon}-supported-port-count)
0140  * @remote_node_entries: min({driver|silicon}-supported-node-count)
0141  * @task_context_entries: min({driver|silicon}-supported-task-count)
0142  * @phy_timer: phy startup timer
0143  * @invalid_phy_mask: if an invalid_link_up notification is reported a bit for
0144  *            the phy index is set so further notifications are not
0145  *            made.  Once the phy reports link up and is made part of a
0146  *            port then this bit is cleared.
0147 
0148  */
0149 struct isci_host {
0150     struct sci_base_state_machine sm;
0151     /* XXX can we time this externally */
0152     struct sci_timer timer;
0153     /* XXX drop reference module params directly */
0154     struct sci_user_parameters user_parameters;
0155     /* XXX no need to be a union */
0156     struct sci_oem_params oem_parameters;
0157     struct sci_port_configuration_agent port_agent;
0158     struct isci_remote_device *device_table[SCI_MAX_REMOTE_DEVICES];
0159     struct sci_remote_node_table available_remote_nodes;
0160     struct sci_power_control power_control;
0161     u8 io_request_sequence[SCI_MAX_IO_REQUESTS];
0162     struct scu_task_context *task_context_table;
0163     dma_addr_t tc_dma;
0164     union scu_remote_node_context *remote_node_context_table;
0165     dma_addr_t rnc_dma;
0166     u32 *completion_queue;
0167     dma_addr_t cq_dma;
0168     u32 completion_queue_get;
0169     u32 logical_port_entries;
0170     u32 remote_node_entries;
0171     u32 task_context_entries;
0172     void *ufi_buf;
0173     dma_addr_t ufi_dma;
0174     struct sci_unsolicited_frame_control uf_control;
0175 
0176     /* phy startup */
0177     struct sci_timer phy_timer;
0178     /* XXX kill */
0179     bool phy_startup_timer_pending;
0180     u32 next_phy_to_start;
0181     /* XXX convert to unsigned long and use bitops */
0182     u8 invalid_phy_mask;
0183 
0184     /* TODO attempt dynamic interrupt coalescing scheme */
0185     u16 interrupt_coalesce_number;
0186     u32 interrupt_coalesce_timeout;
0187     struct smu_registers __iomem *smu_registers;
0188     struct scu_registers __iomem *scu_registers;
0189 
0190     u16 tci_head;
0191     u16 tci_tail;
0192     u16 tci_pool[SCI_MAX_IO_REQUESTS];
0193 
0194     int id; /* unique within a given pci device */
0195     struct isci_phy phys[SCI_MAX_PHYS];
0196     struct isci_port ports[SCI_MAX_PORTS + 1]; /* includes dummy port */
0197     struct asd_sas_port sas_ports[SCI_MAX_PORTS];
0198     struct sas_ha_struct sas_ha;
0199 
0200     struct pci_dev *pdev;
0201     #define IHOST_START_PENDING 0
0202     #define IHOST_STOP_PENDING 1
0203     #define IHOST_IRQ_ENABLED 2
0204     unsigned long flags;
0205     wait_queue_head_t eventq;
0206     struct tasklet_struct completion_tasklet;
0207     spinlock_t scic_lock;
0208     struct isci_request *reqs[SCI_MAX_IO_REQUESTS];
0209     struct isci_remote_device devices[SCI_MAX_REMOTE_DEVICES];
0210 };
0211 
0212 /**
0213  * enum sci_controller_states - This enumeration depicts all the states
0214  *    for the common controller state machine.
0215  */
0216 enum sci_controller_states {
0217     /**
0218      * Simply the initial state for the base controller state machine.
0219      */
0220     SCIC_INITIAL = 0,
0221 
0222     /**
0223      * This state indicates that the controller is reset.  The memory for
0224      * the controller is in it's initial state, but the controller requires
0225      * initialization.
0226      * This state is entered from the INITIAL state.
0227      * This state is entered from the RESETTING state.
0228      */
0229     SCIC_RESET,
0230 
0231     /**
0232      * This state is typically an action state that indicates the controller
0233      * is in the process of initialization.  In this state no new IO operations
0234      * are permitted.
0235      * This state is entered from the RESET state.
0236      */
0237     SCIC_INITIALIZING,
0238 
0239     /**
0240      * This state indicates that the controller has been successfully
0241      * initialized.  In this state no new IO operations are permitted.
0242      * This state is entered from the INITIALIZING state.
0243      */
0244     SCIC_INITIALIZED,
0245 
0246     /**
0247      * This state indicates the the controller is in the process of becoming
0248      * ready (i.e. starting).  In this state no new IO operations are permitted.
0249      * This state is entered from the INITIALIZED state.
0250      */
0251     SCIC_STARTING,
0252 
0253     /**
0254      * This state indicates the controller is now ready.  Thus, the user
0255      * is able to perform IO operations on the controller.
0256      * This state is entered from the STARTING state.
0257      */
0258     SCIC_READY,
0259 
0260     /**
0261      * This state is typically an action state that indicates the controller
0262      * is in the process of resetting.  Thus, the user is unable to perform
0263      * IO operations on the controller.  A reset is considered destructive in
0264      * most cases.
0265      * This state is entered from the READY state.
0266      * This state is entered from the FAILED state.
0267      * This state is entered from the STOPPED state.
0268      */
0269     SCIC_RESETTING,
0270 
0271     /**
0272      * This state indicates that the controller is in the process of stopping.
0273      * In this state no new IO operations are permitted, but existing IO
0274      * operations are allowed to complete.
0275      * This state is entered from the READY state.
0276      */
0277     SCIC_STOPPING,
0278 
0279     /**
0280      * This state indicates that the controller could not successfully be
0281      * initialized.  In this state no new IO operations are permitted.
0282      * This state is entered from the INITIALIZING state.
0283      * This state is entered from the STARTING state.
0284      * This state is entered from the STOPPING state.
0285      * This state is entered from the RESETTING state.
0286      */
0287     SCIC_FAILED,
0288 };
0289 
0290 /**
0291  * struct isci_pci_info - This class represents the pci function containing the
0292  *    controllers. Depending on PCI SKU, there could be up to 2 controllers in
0293  *    the PCI function.
0294  */
0295 #define SCI_MAX_MSIX_INT (SCI_NUM_MSI_X_INT*SCI_MAX_CONTROLLERS)
0296 
0297 struct isci_pci_info {
0298     struct isci_host *hosts[SCI_MAX_CONTROLLERS];
0299     struct isci_orom *orom;
0300 };
0301 
0302 static inline struct isci_pci_info *to_pci_info(struct pci_dev *pdev)
0303 {
0304     return pci_get_drvdata(pdev);
0305 }
0306 
0307 static inline struct Scsi_Host *to_shost(struct isci_host *ihost)
0308 {
0309     return ihost->sas_ha.core.shost;
0310 }
0311 
0312 #define for_each_isci_host(id, ihost, pdev) \
0313     for (id = 0; id < SCI_MAX_CONTROLLERS && \
0314          (ihost = to_pci_info(pdev)->hosts[id]); id++)
0315 
0316 static inline void wait_for_start(struct isci_host *ihost)
0317 {
0318     wait_event(ihost->eventq, !test_bit(IHOST_START_PENDING, &ihost->flags));
0319 }
0320 
0321 static inline void wait_for_stop(struct isci_host *ihost)
0322 {
0323     wait_event(ihost->eventq, !test_bit(IHOST_STOP_PENDING, &ihost->flags));
0324 }
0325 
0326 static inline void wait_for_device_start(struct isci_host *ihost, struct isci_remote_device *idev)
0327 {
0328     wait_event(ihost->eventq, !test_bit(IDEV_START_PENDING, &idev->flags));
0329 }
0330 
0331 static inline void wait_for_device_stop(struct isci_host *ihost, struct isci_remote_device *idev)
0332 {
0333     wait_event(ihost->eventq, !test_bit(IDEV_STOP_PENDING, &idev->flags));
0334 }
0335 
0336 static inline struct isci_host *dev_to_ihost(struct domain_device *dev)
0337 {
0338     return dev->port->ha->lldd_ha;
0339 }
0340 
0341 static inline struct isci_host *idev_to_ihost(struct isci_remote_device *idev)
0342 {
0343     return dev_to_ihost(idev->domain_dev);
0344 }
0345 
0346 /* we always use protocol engine group zero */
0347 #define ISCI_PEG 0
0348 
0349 /* see sci_controller_io_tag_allocate|free for how seq and tci are built */
0350 #define ISCI_TAG(seq, tci) (((u16) (seq)) << 12 | tci)
0351 
0352 /* these are returned by the hardware, so sanitize them */
0353 #define ISCI_TAG_SEQ(tag) (((tag) >> 12) & (SCI_MAX_SEQ-1))
0354 #define ISCI_TAG_TCI(tag) ((tag) & (SCI_MAX_IO_REQUESTS-1))
0355 
0356 /* interrupt coalescing baseline: 9 == 3 to 5us interrupt delay per command */
0357 #define ISCI_COALESCE_BASE 9
0358 
0359 /* expander attached sata devices require 3 rnc slots */
0360 static inline int sci_remote_device_node_count(struct isci_remote_device *idev)
0361 {
0362     struct domain_device *dev = idev->domain_dev;
0363 
0364     if (dev_is_sata(dev) && dev->parent)
0365         return SCU_STP_REMOTE_NODE_COUNT;
0366     return SCU_SSP_REMOTE_NODE_COUNT;
0367 }
0368 
0369 /**
0370  * sci_controller_clear_invalid_phy() -
0371  *
0372  * This macro will clear the bit in the invalid phy mask for this controller
0373  * object.  This is used to control messages reported for invalid link up
0374  * notifications.
0375  */
0376 #define sci_controller_clear_invalid_phy(controller, phy) \
0377     ((controller)->invalid_phy_mask &= ~(1 << (phy)->phy_index))
0378 
0379 static inline struct device *scirdev_to_dev(struct isci_remote_device *idev)
0380 {
0381     if (!idev || !idev->isci_port || !idev->isci_port->isci_host)
0382         return NULL;
0383 
0384     return &idev->isci_port->isci_host->pdev->dev;
0385 }
0386 
0387 static inline bool is_a2(struct pci_dev *pdev)
0388 {
0389     if (pdev->revision < 4)
0390         return true;
0391     return false;
0392 }
0393 
0394 static inline bool is_b0(struct pci_dev *pdev)
0395 {
0396     if (pdev->revision == 4)
0397         return true;
0398     return false;
0399 }
0400 
0401 static inline bool is_c0(struct pci_dev *pdev)
0402 {
0403     if (pdev->revision == 5)
0404         return true;
0405     return false;
0406 }
0407 
0408 static inline bool is_c1(struct pci_dev *pdev)
0409 {
0410     if (pdev->revision >= 6)
0411         return true;
0412     return false;
0413 }
0414 
0415 enum cable_selections {
0416     short_cable     = 0,
0417     long_cable      = 1,
0418     medium_cable    = 2,
0419     undefined_cable = 3
0420 };
0421 
0422 #define CABLE_OVERRIDE_DISABLED (0x10000)
0423 
0424 static inline int is_cable_select_overridden(void)
0425 {
0426     return cable_selection_override < CABLE_OVERRIDE_DISABLED;
0427 }
0428 
0429 enum cable_selections decode_cable_selection(struct isci_host *ihost, int phy);
0430 void validate_cable_selections(struct isci_host *ihost);
0431 char *lookup_cable_names(enum cable_selections);
0432 
0433 /* set hw control for 'activity', even though active enclosures seem to drive
0434  * the activity led on their own.  Skip setting FSENG control on 'status' due
0435  * to unexpected operation and 'error' due to not being a supported automatic
0436  * FSENG output
0437  */
0438 #define SGPIO_HW_CONTROL 0x00000443
0439 
0440 static inline int isci_gpio_count(struct isci_host *ihost)
0441 {
0442     return ARRAY_SIZE(ihost->scu_registers->peg0.sgpio.output_data_select);
0443 }
0444 
0445 void sci_controller_post_request(struct isci_host *ihost,
0446                       u32 request);
0447 void sci_controller_release_frame(struct isci_host *ihost,
0448                        u32 frame_index);
0449 void sci_controller_copy_sata_response(void *response_buffer,
0450                         void *frame_header,
0451                         void *frame_buffer);
0452 enum sci_status sci_controller_allocate_remote_node_context(struct isci_host *ihost,
0453                                  struct isci_remote_device *idev,
0454                                  u16 *node_id);
0455 void sci_controller_free_remote_node_context(
0456     struct isci_host *ihost,
0457     struct isci_remote_device *idev,
0458     u16 node_id);
0459 
0460 struct isci_request *sci_request_by_tag(struct isci_host *ihost, u16 io_tag);
0461 void sci_controller_power_control_queue_insert(struct isci_host *ihost,
0462                            struct isci_phy *iphy);
0463 void sci_controller_power_control_queue_remove(struct isci_host *ihost,
0464                            struct isci_phy *iphy);
0465 void sci_controller_link_up(struct isci_host *ihost, struct isci_port *iport,
0466                 struct isci_phy *iphy);
0467 void sci_controller_link_down(struct isci_host *ihost, struct isci_port *iport,
0468                   struct isci_phy *iphy);
0469 void sci_controller_remote_device_stopped(struct isci_host *ihost,
0470                       struct isci_remote_device *idev);
0471 
0472 enum sci_status sci_controller_continue_io(struct isci_request *ireq);
0473 int isci_host_scan_finished(struct Scsi_Host *, unsigned long);
0474 void isci_host_start(struct Scsi_Host *);
0475 u16 isci_alloc_tag(struct isci_host *ihost);
0476 enum sci_status isci_free_tag(struct isci_host *ihost, u16 io_tag);
0477 void isci_tci_free(struct isci_host *ihost, u16 tci);
0478 void ireq_done(struct isci_host *ihost, struct isci_request *ireq, struct sas_task *task);
0479 
0480 int isci_host_init(struct isci_host *);
0481 void isci_host_completion_routine(unsigned long data);
0482 void isci_host_deinit(struct isci_host *);
0483 void sci_controller_disable_interrupts(struct isci_host *ihost);
0484 bool sci_controller_has_remote_devices_stopping(struct isci_host *ihost);
0485 void sci_controller_transition_to_ready(struct isci_host *ihost, enum sci_status status);
0486 
0487 enum sci_status sci_controller_start_io(
0488     struct isci_host *ihost,
0489     struct isci_remote_device *idev,
0490     struct isci_request *ireq);
0491 
0492 enum sci_status sci_controller_start_task(
0493     struct isci_host *ihost,
0494     struct isci_remote_device *idev,
0495     struct isci_request *ireq);
0496 
0497 enum sci_status sci_controller_terminate_request(
0498     struct isci_host *ihost,
0499     struct isci_remote_device *idev,
0500     struct isci_request *ireq);
0501 
0502 enum sci_status sci_controller_complete_io(
0503     struct isci_host *ihost,
0504     struct isci_remote_device *idev,
0505     struct isci_request *ireq);
0506 
0507 void sci_port_configuration_agent_construct(
0508     struct sci_port_configuration_agent *port_agent);
0509 
0510 enum sci_status sci_port_configuration_agent_initialize(
0511     struct isci_host *ihost,
0512     struct sci_port_configuration_agent *port_agent);
0513 
0514 int isci_gpio_write(struct sas_ha_struct *, u8 reg_type, u8 reg_index,
0515             u8 reg_count, u8 *write_data);
0516 #endif