16f231ddaSDan Williams /* 26f231ddaSDan Williams * This file is provided under a dual BSD/GPLv2 license. When using or 36f231ddaSDan Williams * redistributing this file, you may do so under either license. 46f231ddaSDan Williams * 56f231ddaSDan Williams * GPL LICENSE SUMMARY 66f231ddaSDan Williams * 76f231ddaSDan Williams * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. 86f231ddaSDan Williams * 96f231ddaSDan Williams * This program is free software; you can redistribute it and/or modify 106f231ddaSDan Williams * it under the terms of version 2 of the GNU General Public License as 116f231ddaSDan Williams * published by the Free Software Foundation. 126f231ddaSDan Williams * 136f231ddaSDan Williams * This program is distributed in the hope that it will be useful, but 146f231ddaSDan Williams * WITHOUT ANY WARRANTY; without even the implied warranty of 156f231ddaSDan Williams * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 166f231ddaSDan Williams * General Public License for more details. 176f231ddaSDan Williams * 186f231ddaSDan Williams * You should have received a copy of the GNU General Public License 196f231ddaSDan Williams * along with this program; if not, write to the Free Software 206f231ddaSDan Williams * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. 216f231ddaSDan Williams * The full GNU General Public License is included in this distribution 226f231ddaSDan Williams * in the file called LICENSE.GPL. 236f231ddaSDan Williams * 246f231ddaSDan Williams * BSD LICENSE 256f231ddaSDan Williams * 266f231ddaSDan Williams * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. 276f231ddaSDan Williams * All rights reserved. 286f231ddaSDan Williams * 296f231ddaSDan Williams * Redistribution and use in source and binary forms, with or without 306f231ddaSDan Williams * modification, are permitted provided that the following conditions 316f231ddaSDan Williams * are met: 326f231ddaSDan Williams * 336f231ddaSDan Williams * * Redistributions of source code must retain the above copyright 346f231ddaSDan Williams * notice, this list of conditions and the following disclaimer. 356f231ddaSDan Williams * * Redistributions in binary form must reproduce the above copyright 366f231ddaSDan Williams * notice, this list of conditions and the following disclaimer in 376f231ddaSDan Williams * the documentation and/or other materials provided with the 386f231ddaSDan Williams * distribution. 396f231ddaSDan Williams * * Neither the name of Intel Corporation nor the names of its 406f231ddaSDan Williams * contributors may be used to endorse or promote products derived 416f231ddaSDan Williams * from this software without specific prior written permission. 426f231ddaSDan Williams * 436f231ddaSDan Williams * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 446f231ddaSDan Williams * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 456f231ddaSDan Williams * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 466f231ddaSDan Williams * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 476f231ddaSDan Williams * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 486f231ddaSDan Williams * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 496f231ddaSDan Williams * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 506f231ddaSDan Williams * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 516f231ddaSDan Williams * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 526f231ddaSDan Williams * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 536f231ddaSDan Williams * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 546f231ddaSDan Williams */ 55ce2b3261SDan Williams #ifndef _SCI_HOST_H_ 566f231ddaSDan Williams #define _SCI_HOST_H_ 576f231ddaSDan Williams 5811cc5183SDan Williams #include <scsi/sas_ata.h> 596f231ddaSDan Williams #include "remote_device.h" 60ce2b3261SDan Williams #include "phy.h" 6112ef6544SEdmund Nadolski #include "isci.h" 62cc9203bfSDan Williams #include "remote_node_table.h" 6363a3a15fSDan Williams #include "registers.h" 6463a3a15fSDan Williams #include "unsolicited_frame_control.h" 65e2f8db50SDan Williams #include "probe_roms.h" 66cc9203bfSDan Williams 675076a1a9SDan Williams struct isci_request; 68cc9203bfSDan Williams struct scu_task_context; 69cc9203bfSDan Williams 70e2f8db50SDan Williams 71cc9203bfSDan Williams /** 7289a7301fSDan Williams * struct sci_power_control - 73cc9203bfSDan Williams * 74cc9203bfSDan Williams * This structure defines the fields for managing power control for direct 75cc9203bfSDan Williams * attached disk devices. 76cc9203bfSDan Williams */ 7789a7301fSDan Williams struct sci_power_control { 78cc9203bfSDan Williams /** 79cc9203bfSDan Williams * This field is set when the power control timer is running and cleared when 80cc9203bfSDan Williams * it is not. 81cc9203bfSDan Williams */ 82cc9203bfSDan Williams bool timer_started; 83cc9203bfSDan Williams 84cc9203bfSDan Williams /** 850473661aSEdmund Nadolski * Timer to control when the directed attached disks can consume power. 86cc9203bfSDan Williams */ 870473661aSEdmund Nadolski struct sci_timer timer; 88cc9203bfSDan Williams 89cc9203bfSDan Williams /** 90cc9203bfSDan Williams * This field is used to keep track of how many phys are put into the 91cc9203bfSDan Williams * requesters field. 92cc9203bfSDan Williams */ 93cc9203bfSDan Williams u8 phys_waiting; 94cc9203bfSDan Williams 95cc9203bfSDan Williams /** 96cc9203bfSDan Williams * This field is used to keep track of how many phys have been granted to consume power 97cc9203bfSDan Williams */ 98cc9203bfSDan Williams u8 phys_granted_power; 99cc9203bfSDan Williams 100cc9203bfSDan Williams /** 101cc9203bfSDan Williams * This field is an array of phys that we are waiting on. The phys are direct 10289a7301fSDan Williams * mapped into requesters via struct sci_phy.phy_index 103cc9203bfSDan Williams */ 10485280955SDan Williams struct isci_phy *requesters[SCI_MAX_PHYS]; 105cc9203bfSDan Williams 106cc9203bfSDan Williams }; 107cc9203bfSDan Williams 10889a7301fSDan Williams struct sci_port_configuration_agent; 109d9dcb4baSDan Williams typedef void (*port_config_fn)(struct isci_host *, 11089a7301fSDan Williams struct sci_port_configuration_agent *, 111ffe191c9SDan Williams struct isci_port *, struct isci_phy *); 11250a92d93SDan Williams bool is_port_config_apc(struct isci_host *ihost); 11350a92d93SDan Williams bool is_controller_start_complete(struct isci_host *ihost); 114e2f8db50SDan Williams 11589a7301fSDan Williams struct sci_port_configuration_agent { 116e2f8db50SDan Williams u16 phy_configured_mask; 117e2f8db50SDan Williams u16 phy_ready_mask; 118e2f8db50SDan Williams struct { 119e2f8db50SDan Williams u8 min_index; 120e2f8db50SDan Williams u8 max_index; 121e2f8db50SDan Williams } phy_valid_port_range[SCI_MAX_PHYS]; 122e2f8db50SDan Williams bool timer_pending; 123e2f8db50SDan Williams port_config_fn link_up_handler; 124e2f8db50SDan Williams port_config_fn link_down_handler; 125ac0eeb4fSEdmund Nadolski struct sci_timer timer; 126e2f8db50SDan Williams }; 127e2f8db50SDan Williams 128cc9203bfSDan Williams /** 129d9dcb4baSDan Williams * isci_host - primary host/controller object 130d9dcb4baSDan Williams * @timer: timeout start/stop operations 131d9dcb4baSDan Williams * @device_table: rni (hw remote node index) to remote device lookup table 132d9dcb4baSDan Williams * @available_remote_nodes: rni allocator 133d9dcb4baSDan Williams * @power_control: manage device spin up 134d9dcb4baSDan Williams * @io_request_sequence: generation number for tci's (task contexts) 135d9dcb4baSDan Williams * @task_context_table: hw task context table 136d9dcb4baSDan Williams * @remote_node_context_table: hw remote node context table 137d9dcb4baSDan Williams * @completion_queue: hw-producer driver-consumer communication ring 138d9dcb4baSDan Williams * @completion_queue_get: tracks the driver 'head' of the ring to notify hw 139d9dcb4baSDan Williams * @logical_port_entries: min({driver|silicon}-supported-port-count) 140d9dcb4baSDan Williams * @remote_node_entries: min({driver|silicon}-supported-node-count) 141d9dcb4baSDan Williams * @task_context_entries: min({driver|silicon}-supported-task-count) 142d9dcb4baSDan Williams * @phy_timer: phy startup timer 143d9dcb4baSDan Williams * @invalid_phy_mask: if an invalid_link_up notification is reported a bit for 144d9dcb4baSDan Williams * the phy index is set so further notifications are not 145d9dcb4baSDan Williams * made. Once the phy reports link up and is made part of a 146d9dcb4baSDan Williams * port then this bit is cleared. 147d9dcb4baSDan Williams 148cc9203bfSDan Williams */ 149d9dcb4baSDan Williams struct isci_host { 150e301370aSEdmund Nadolski struct sci_base_state_machine sm; 151d9dcb4baSDan Williams /* XXX can we time this externally */ 1526cb5853dSEdmund Nadolski struct sci_timer timer; 153d9dcb4baSDan Williams /* XXX drop reference module params directly */ 15489a7301fSDan Williams struct sci_user_parameters user_parameters; 155d9dcb4baSDan Williams /* XXX no need to be a union */ 15689a7301fSDan Williams struct sci_oem_params oem_parameters; 15789a7301fSDan Williams struct sci_port_configuration_agent port_agent; 15878a6f06eSDan Williams struct isci_remote_device *device_table[SCI_MAX_REMOTE_DEVICES]; 15989a7301fSDan Williams struct sci_remote_node_table available_remote_nodes; 16089a7301fSDan Williams struct sci_power_control power_control; 161dd047c8eSDan Williams u8 io_request_sequence[SCI_MAX_IO_REQUESTS]; 162cc9203bfSDan Williams struct scu_task_context *task_context_table; 163abec912dSDan Williams dma_addr_t tc_dma; 164cc9203bfSDan Williams union scu_remote_node_context *remote_node_context_table; 165abec912dSDan Williams dma_addr_t rnc_dma; 166cc9203bfSDan Williams u32 *completion_queue; 167abec912dSDan Williams dma_addr_t cq_dma; 168cc9203bfSDan Williams u32 completion_queue_get; 169cc9203bfSDan Williams u32 logical_port_entries; 170cc9203bfSDan Williams u32 remote_node_entries; 171cc9203bfSDan Williams u32 task_context_entries; 172abec912dSDan Williams void *ufi_buf; 173abec912dSDan Williams dma_addr_t ufi_dma; 17489a7301fSDan Williams struct sci_unsolicited_frame_control uf_control; 175cc9203bfSDan Williams 176d9dcb4baSDan Williams /* phy startup */ 177bb3dbdf6SEdmund Nadolski struct sci_timer phy_timer; 178d9dcb4baSDan Williams /* XXX kill */ 179cc9203bfSDan Williams bool phy_startup_timer_pending; 180cc9203bfSDan Williams u32 next_phy_to_start; 18134a99158SDan Williams /* XXX convert to unsigned long and use bitops */ 182cc9203bfSDan Williams u8 invalid_phy_mask; 183cc9203bfSDan Williams 184d9dcb4baSDan Williams /* TODO attempt dynamic interrupt coalescing scheme */ 185cc9203bfSDan Williams u16 interrupt_coalesce_number; 186cc9203bfSDan Williams u32 interrupt_coalesce_timeout; 187cc9203bfSDan Williams struct smu_registers __iomem *smu_registers; 188cc9203bfSDan Williams struct scu_registers __iomem *scu_registers; 189cc9203bfSDan Williams 190ac668c69SDan Williams u16 tci_head; 191ac668c69SDan Williams u16 tci_tail; 192ac668c69SDan Williams u16 tci_pool[SCI_MAX_IO_REQUESTS]; 193ac668c69SDan Williams 1946f231ddaSDan Williams int id; /* unique within a given pci device */ 1956f231ddaSDan Williams struct isci_phy phys[SCI_MAX_PHYS]; 196e531381eSDan Williams struct isci_port ports[SCI_MAX_PORTS + 1]; /* includes dummy port */ 197c132f692SDan Williams struct asd_sas_port sas_ports[SCI_MAX_PORTS]; 1986f231ddaSDan Williams struct sas_ha_struct sas_ha; 1996f231ddaSDan Williams 2006f231ddaSDan Williams struct pci_dev *pdev; 2010cf89d1dSDan Williams #define IHOST_START_PENDING 0 2020cf89d1dSDan Williams #define IHOST_STOP_PENDING 1 2032396a265SDan Williams #define IHOST_IRQ_ENABLED 2 2040cf89d1dSDan Williams unsigned long flags; 2050cf89d1dSDan Williams wait_queue_head_t eventq; 2066f231ddaSDan Williams struct tasklet_struct completion_tasklet; 2076f231ddaSDan Williams spinlock_t scic_lock; 208db056250SDan Williams struct isci_request *reqs[SCI_MAX_IO_REQUESTS]; 20957f20f4eSDan Williams struct isci_remote_device devices[SCI_MAX_REMOTE_DEVICES]; 2106f231ddaSDan Williams }; 2116f231ddaSDan Williams 2126f231ddaSDan Williams /** 21389a7301fSDan Williams * enum sci_controller_states - This enumeration depicts all the states 214cc9203bfSDan Williams * for the common controller state machine. 215cc9203bfSDan Williams */ 21689a7301fSDan Williams enum sci_controller_states { 217cc9203bfSDan Williams /** 218cc9203bfSDan Williams * Simply the initial state for the base controller state machine. 219cc9203bfSDan Williams */ 220e301370aSEdmund Nadolski SCIC_INITIAL = 0, 221cc9203bfSDan Williams 222cc9203bfSDan Williams /** 223cc9203bfSDan Williams * This state indicates that the controller is reset. The memory for 224cc9203bfSDan Williams * the controller is in it's initial state, but the controller requires 225cc9203bfSDan Williams * initialization. 226cc9203bfSDan Williams * This state is entered from the INITIAL state. 227cc9203bfSDan Williams * This state is entered from the RESETTING state. 228cc9203bfSDan Williams */ 229e301370aSEdmund Nadolski SCIC_RESET, 230cc9203bfSDan Williams 231cc9203bfSDan Williams /** 232cc9203bfSDan Williams * This state is typically an action state that indicates the controller 233cc9203bfSDan Williams * is in the process of initialization. In this state no new IO operations 234cc9203bfSDan Williams * are permitted. 235cc9203bfSDan Williams * This state is entered from the RESET state. 236cc9203bfSDan Williams */ 237e301370aSEdmund Nadolski SCIC_INITIALIZING, 238cc9203bfSDan Williams 239cc9203bfSDan Williams /** 240cc9203bfSDan Williams * This state indicates that the controller has been successfully 241cc9203bfSDan Williams * initialized. In this state no new IO operations are permitted. 242cc9203bfSDan Williams * This state is entered from the INITIALIZING state. 243cc9203bfSDan Williams */ 244e301370aSEdmund Nadolski SCIC_INITIALIZED, 245cc9203bfSDan Williams 246cc9203bfSDan Williams /** 247cc9203bfSDan Williams * This state indicates the the controller is in the process of becoming 248cc9203bfSDan Williams * ready (i.e. starting). In this state no new IO operations are permitted. 249cc9203bfSDan Williams * This state is entered from the INITIALIZED state. 250cc9203bfSDan Williams */ 251e301370aSEdmund Nadolski SCIC_STARTING, 252cc9203bfSDan Williams 253cc9203bfSDan Williams /** 254cc9203bfSDan Williams * This state indicates the controller is now ready. Thus, the user 255cc9203bfSDan Williams * is able to perform IO operations on the controller. 256cc9203bfSDan Williams * This state is entered from the STARTING state. 257cc9203bfSDan Williams */ 258e301370aSEdmund Nadolski SCIC_READY, 259cc9203bfSDan Williams 260cc9203bfSDan Williams /** 261cc9203bfSDan Williams * This state is typically an action state that indicates the controller 262cc9203bfSDan Williams * is in the process of resetting. Thus, the user is unable to perform 263cc9203bfSDan Williams * IO operations on the controller. A reset is considered destructive in 264cc9203bfSDan Williams * most cases. 265cc9203bfSDan Williams * This state is entered from the READY state. 266cc9203bfSDan Williams * This state is entered from the FAILED state. 267cc9203bfSDan Williams * This state is entered from the STOPPED state. 268cc9203bfSDan Williams */ 269e301370aSEdmund Nadolski SCIC_RESETTING, 270cc9203bfSDan Williams 271cc9203bfSDan Williams /** 272cc9203bfSDan Williams * This state indicates that the controller is in the process of stopping. 273cc9203bfSDan Williams * In this state no new IO operations are permitted, but existing IO 274cc9203bfSDan Williams * operations are allowed to complete. 275cc9203bfSDan Williams * This state is entered from the READY state. 276cc9203bfSDan Williams */ 277e301370aSEdmund Nadolski SCIC_STOPPING, 278cc9203bfSDan Williams 279cc9203bfSDan Williams /** 280cc9203bfSDan Williams * This state indicates that the controller could not successfully be 281cc9203bfSDan Williams * initialized. In this state no new IO operations are permitted. 282cc9203bfSDan Williams * This state is entered from the INITIALIZING state. 283cc9203bfSDan Williams * This state is entered from the STARTING state. 284cc9203bfSDan Williams * This state is entered from the STOPPING state. 285cc9203bfSDan Williams * This state is entered from the RESETTING state. 286cc9203bfSDan Williams */ 287e301370aSEdmund Nadolski SCIC_FAILED, 288cc9203bfSDan Williams }; 289cc9203bfSDan Williams 290cc9203bfSDan Williams /** 2916f231ddaSDan Williams * struct isci_pci_info - This class represents the pci function containing the 2926f231ddaSDan Williams * controllers. Depending on PCI SKU, there could be up to 2 controllers in 2936f231ddaSDan Williams * the PCI function. 2946f231ddaSDan Williams */ 2956f231ddaSDan Williams #define SCI_MAX_MSIX_INT (SCI_NUM_MSI_X_INT*SCI_MAX_CONTROLLERS) 2966f231ddaSDan Williams 2976f231ddaSDan Williams struct isci_pci_info { 2986f231ddaSDan Williams struct msix_entry msix_entries[SCI_MAX_MSIX_INT]; 299b329aff1SDan Williams struct isci_host *hosts[SCI_MAX_CONTROLLERS]; 300d044af17SDan Williams struct isci_orom *orom; 3016f231ddaSDan Williams }; 3026f231ddaSDan Williams 3036f231ddaSDan Williams static inline struct isci_pci_info *to_pci_info(struct pci_dev *pdev) 3046f231ddaSDan Williams { 3056f231ddaSDan Williams return pci_get_drvdata(pdev); 3066f231ddaSDan Williams } 3076f231ddaSDan Williams 308d1dc5e2dSDan Williams static inline struct Scsi_Host *to_shost(struct isci_host *ihost) 309d1dc5e2dSDan Williams { 310d1dc5e2dSDan Williams return ihost->sas_ha.core.shost; 311d1dc5e2dSDan Williams } 312d1dc5e2dSDan Williams 313b329aff1SDan Williams #define for_each_isci_host(id, ihost, pdev) \ 314b329aff1SDan Williams for (id = 0, ihost = to_pci_info(pdev)->hosts[id]; \ 315b329aff1SDan Williams id < ARRAY_SIZE(to_pci_info(pdev)->hosts) && ihost; \ 316b329aff1SDan Williams ihost = to_pci_info(pdev)->hosts[++id]) 3176f231ddaSDan Williams 3180cf89d1dSDan Williams static inline void wait_for_start(struct isci_host *ihost) 3190cf89d1dSDan Williams { 3200cf89d1dSDan Williams wait_event(ihost->eventq, !test_bit(IHOST_START_PENDING, &ihost->flags)); 3210cf89d1dSDan Williams } 3220cf89d1dSDan Williams 3230cf89d1dSDan Williams static inline void wait_for_stop(struct isci_host *ihost) 3240cf89d1dSDan Williams { 3250cf89d1dSDan Williams wait_event(ihost->eventq, !test_bit(IHOST_STOP_PENDING, &ihost->flags)); 3260cf89d1dSDan Williams } 3270cf89d1dSDan Williams 3286ad31fecSDan Williams static inline void wait_for_device_start(struct isci_host *ihost, struct isci_remote_device *idev) 3296ad31fecSDan Williams { 3306ad31fecSDan Williams wait_event(ihost->eventq, !test_bit(IDEV_START_PENDING, &idev->flags)); 3316ad31fecSDan Williams } 3326ad31fecSDan Williams 3336ad31fecSDan Williams static inline void wait_for_device_stop(struct isci_host *ihost, struct isci_remote_device *idev) 3346ad31fecSDan Williams { 335d9c37390SDan Williams wait_event(ihost->eventq, !test_bit(IDEV_STOP_PENDING, &idev->flags)); 3366ad31fecSDan Williams } 3370cf89d1dSDan Williams 3384393aa4eSDan Williams static inline struct isci_host *dev_to_ihost(struct domain_device *dev) 3394393aa4eSDan Williams { 3404393aa4eSDan Williams return dev->port->ha->lldd_ha; 3414393aa4eSDan Williams } 3426f231ddaSDan Williams 343de2eb4d5SJeff Skirvin static inline struct isci_host *idev_to_ihost(struct isci_remote_device *idev) 344de2eb4d5SJeff Skirvin { 345de2eb4d5SJeff Skirvin return dev_to_ihost(idev->domain_dev); 346de2eb4d5SJeff Skirvin } 347de2eb4d5SJeff Skirvin 34834a99158SDan Williams /* we always use protocol engine group zero */ 34934a99158SDan Williams #define ISCI_PEG 0 3506f231ddaSDan Williams 35189a7301fSDan Williams /* see sci_controller_io_tag_allocate|free for how seq and tci are built */ 352dd047c8eSDan Williams #define ISCI_TAG(seq, tci) (((u16) (seq)) << 12 | tci) 353cc9203bfSDan Williams 354dd047c8eSDan Williams /* these are returned by the hardware, so sanitize them */ 355dd047c8eSDan Williams #define ISCI_TAG_SEQ(tag) (((tag) >> 12) & (SCI_MAX_SEQ-1)) 356dd047c8eSDan Williams #define ISCI_TAG_TCI(tag) ((tag) & (SCI_MAX_IO_REQUESTS-1)) 357cc9203bfSDan Williams 3589b4be528SDan Williams /* interrupt coalescing baseline: 9 == 3 to 5us interrupt delay per command */ 3599b4be528SDan Williams #define ISCI_COALESCE_BASE 9 3609b4be528SDan Williams 361cc9203bfSDan Williams /* expander attached sata devices require 3 rnc slots */ 36289a7301fSDan Williams static inline int sci_remote_device_node_count(struct isci_remote_device *idev) 363cc9203bfSDan Williams { 36478a6f06eSDan Williams struct domain_device *dev = idev->domain_dev; 365cc9203bfSDan Williams 36611cc5183SDan Williams if (dev_is_sata(dev) && dev->parent) 367cc9203bfSDan Williams return SCU_STP_REMOTE_NODE_COUNT; 368cc9203bfSDan Williams return SCU_SSP_REMOTE_NODE_COUNT; 369cc9203bfSDan Williams } 370cc9203bfSDan Williams 371cc9203bfSDan Williams /** 37289a7301fSDan Williams * sci_controller_clear_invalid_phy() - 373cc9203bfSDan Williams * 374cc9203bfSDan Williams * This macro will clear the bit in the invalid phy mask for this controller 375cc9203bfSDan Williams * object. This is used to control messages reported for invalid link up 376cc9203bfSDan Williams * notifications. 377cc9203bfSDan Williams */ 37889a7301fSDan Williams #define sci_controller_clear_invalid_phy(controller, phy) \ 379cc9203bfSDan Williams ((controller)->invalid_phy_mask &= ~(1 << (phy)->phy_index)) 380cc9203bfSDan Williams 38178a6f06eSDan Williams static inline struct device *scirdev_to_dev(struct isci_remote_device *idev) 382cc9203bfSDan Williams { 383cc9203bfSDan Williams if (!idev || !idev->isci_port || !idev->isci_port->isci_host) 384cc9203bfSDan Williams return NULL; 385cc9203bfSDan Williams 386cc9203bfSDan Williams return &idev->isci_port->isci_host->pdev->dev; 387cc9203bfSDan Williams } 388cc9203bfSDan Williams 389dc00c8b6SDan Williams static inline bool is_a2(struct pci_dev *pdev) 390cc9203bfSDan Williams { 391dc00c8b6SDan Williams if (pdev->revision < 4) 392dc00c8b6SDan Williams return true; 393dc00c8b6SDan Williams return false; 394cc9203bfSDan Williams } 395cc9203bfSDan Williams 396dc00c8b6SDan Williams static inline bool is_b0(struct pci_dev *pdev) 397cc9203bfSDan Williams { 398dc00c8b6SDan Williams if (pdev->revision == 4) 399dc00c8b6SDan Williams return true; 400dc00c8b6SDan Williams return false; 401cc9203bfSDan Williams } 402cc9203bfSDan Williams 403dc00c8b6SDan Williams static inline bool is_c0(struct pci_dev *pdev) 404cc9203bfSDan Williams { 405afd13a1fSJeff Skirvin if (pdev->revision == 5) 406afd13a1fSJeff Skirvin return true; 407afd13a1fSJeff Skirvin return false; 408afd13a1fSJeff Skirvin } 409afd13a1fSJeff Skirvin 410afd13a1fSJeff Skirvin static inline bool is_c1(struct pci_dev *pdev) 411afd13a1fSJeff Skirvin { 412afd13a1fSJeff Skirvin if (pdev->revision >= 6) 413dc00c8b6SDan Williams return true; 414dc00c8b6SDan Williams return false; 415cc9203bfSDan Williams } 416cc9203bfSDan Williams 4179fee607fSJeff Skirvin enum cable_selections { 4189fee607fSJeff Skirvin short_cable = 0, 4199fee607fSJeff Skirvin long_cable = 1, 4209fee607fSJeff Skirvin medium_cable = 2, 4219fee607fSJeff Skirvin undefined_cable = 3 4229fee607fSJeff Skirvin }; 4239fee607fSJeff Skirvin 4249fee607fSJeff Skirvin #define CABLE_OVERRIDE_DISABLED (0x10000) 4259fee607fSJeff Skirvin 4269fee607fSJeff Skirvin static inline int is_cable_select_overridden(void) 4279fee607fSJeff Skirvin { 4289fee607fSJeff Skirvin return cable_selection_override < CABLE_OVERRIDE_DISABLED; 4299fee607fSJeff Skirvin } 4309fee607fSJeff Skirvin 4319fee607fSJeff Skirvin enum cable_selections decode_cable_selection(struct isci_host *ihost, int phy); 4329fee607fSJeff Skirvin void validate_cable_selections(struct isci_host *ihost); 4339fee607fSJeff Skirvin char *lookup_cable_names(enum cable_selections); 4349fee607fSJeff Skirvin 435ad4f4c1dSDan Williams /* set hw control for 'activity', even though active enclosures seem to drive 436ad4f4c1dSDan Williams * the activity led on their own. Skip setting FSENG control on 'status' due 437ad4f4c1dSDan Williams * to unexpected operation and 'error' due to not being a supported automatic 438ad4f4c1dSDan Williams * FSENG output 439ad4f4c1dSDan Williams */ 440ad4f4c1dSDan Williams #define SGPIO_HW_CONTROL 0x00000443 441ad4f4c1dSDan Williams 442ad4f4c1dSDan Williams static inline int isci_gpio_count(struct isci_host *ihost) 443ad4f4c1dSDan Williams { 444ad4f4c1dSDan Williams return ARRAY_SIZE(ihost->scu_registers->peg0.sgpio.output_data_select); 445ad4f4c1dSDan Williams } 446ad4f4c1dSDan Williams 44789a7301fSDan Williams void sci_controller_post_request(struct isci_host *ihost, 448cc9203bfSDan Williams u32 request); 44989a7301fSDan Williams void sci_controller_release_frame(struct isci_host *ihost, 450cc9203bfSDan Williams u32 frame_index); 45189a7301fSDan Williams void sci_controller_copy_sata_response(void *response_buffer, 452cc9203bfSDan Williams void *frame_header, 453cc9203bfSDan Williams void *frame_buffer); 45489a7301fSDan Williams enum sci_status sci_controller_allocate_remote_node_context(struct isci_host *ihost, 45578a6f06eSDan Williams struct isci_remote_device *idev, 456cc9203bfSDan Williams u16 *node_id); 45789a7301fSDan Williams void sci_controller_free_remote_node_context( 458d9dcb4baSDan Williams struct isci_host *ihost, 45978a6f06eSDan Williams struct isci_remote_device *idev, 460cc9203bfSDan Williams u16 node_id); 461cc9203bfSDan Williams 462abec912dSDan Williams struct isci_request *sci_request_by_tag(struct isci_host *ihost, u16 io_tag); 463abec912dSDan Williams void sci_controller_power_control_queue_insert(struct isci_host *ihost, 46485280955SDan Williams struct isci_phy *iphy); 465abec912dSDan Williams void sci_controller_power_control_queue_remove(struct isci_host *ihost, 46685280955SDan Williams struct isci_phy *iphy); 467abec912dSDan Williams void sci_controller_link_up(struct isci_host *ihost, struct isci_port *iport, 46885280955SDan Williams struct isci_phy *iphy); 469abec912dSDan Williams void sci_controller_link_down(struct isci_host *ihost, struct isci_port *iport, 47085280955SDan Williams struct isci_phy *iphy); 471abec912dSDan Williams void sci_controller_remote_device_stopped(struct isci_host *ihost, 47278a6f06eSDan Williams struct isci_remote_device *idev); 473cc9203bfSDan Williams 47489a7301fSDan Williams enum sci_status sci_controller_continue_io(struct isci_request *ireq); 475cc9203bfSDan Williams int isci_host_scan_finished(struct Scsi_Host *, unsigned long); 476e468dc11SArtur Wojcik void isci_host_start(struct Scsi_Host *); 477312e0c24SDan Williams u16 isci_alloc_tag(struct isci_host *ihost); 478312e0c24SDan Williams enum sci_status isci_free_tag(struct isci_host *ihost, u16 io_tag); 479312e0c24SDan Williams void isci_tci_free(struct isci_host *ihost, u16 tci); 480f8381807SJeff Skirvin void ireq_done(struct isci_host *ihost, struct isci_request *ireq, struct sas_task *task); 4816f231ddaSDan Williams 4826f231ddaSDan Williams int isci_host_init(struct isci_host *); 483abec912dSDan Williams void isci_host_completion_routine(unsigned long data); 484abec912dSDan Williams void isci_host_deinit(struct isci_host *); 485abec912dSDan Williams void sci_controller_disable_interrupts(struct isci_host *ihost); 486eb608c3cSDan Williams bool sci_controller_has_remote_devices_stopping(struct isci_host *ihost); 48750a92d93SDan Williams void sci_controller_transition_to_ready(struct isci_host *ihost, enum sci_status status); 488cc9203bfSDan Williams 48989a7301fSDan Williams enum sci_status sci_controller_start_io( 490d9dcb4baSDan Williams struct isci_host *ihost, 49178a6f06eSDan Williams struct isci_remote_device *idev, 4925076a1a9SDan Williams struct isci_request *ireq); 493cc9203bfSDan Williams 49489a7301fSDan Williams enum sci_task_status sci_controller_start_task( 495d9dcb4baSDan Williams struct isci_host *ihost, 49678a6f06eSDan Williams struct isci_remote_device *idev, 4975076a1a9SDan Williams struct isci_request *ireq); 498cc9203bfSDan Williams 49989a7301fSDan Williams enum sci_status sci_controller_terminate_request( 500d9dcb4baSDan Williams struct isci_host *ihost, 50178a6f06eSDan Williams struct isci_remote_device *idev, 5025076a1a9SDan Williams struct isci_request *ireq); 503cc9203bfSDan Williams 50489a7301fSDan Williams enum sci_status sci_controller_complete_io( 505d9dcb4baSDan Williams struct isci_host *ihost, 50678a6f06eSDan Williams struct isci_remote_device *idev, 5075076a1a9SDan Williams struct isci_request *ireq); 508cc9203bfSDan Williams 50989a7301fSDan Williams void sci_port_configuration_agent_construct( 51089a7301fSDan Williams struct sci_port_configuration_agent *port_agent); 511e2f8db50SDan Williams 51289a7301fSDan Williams enum sci_status sci_port_configuration_agent_initialize( 513d9dcb4baSDan Williams struct isci_host *ihost, 51489a7301fSDan Williams struct sci_port_configuration_agent *port_agent); 515ad4f4c1dSDan Williams 516ad4f4c1dSDan Williams int isci_gpio_write(struct sas_ha_struct *, u8 reg_type, u8 reg_index, 517ad4f4c1dSDan Williams u8 reg_count, u8 *write_data); 518cc9203bfSDan Williams #endif 519