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 
0056 #include <linux/kernel.h>
0057 #include <linux/init.h>
0058 #include <linux/module.h>
0059 #include <linux/firmware.h>
0060 #include <linux/efi.h>
0061 #include <asm/string.h>
0062 #include <scsi/scsi_host.h>
0063 #include "host.h"
0064 #include "isci.h"
0065 #include "task.h"
0066 #include "probe_roms.h"
0067 
0068 #define MAJ 1
0069 #define MIN 2
0070 #define BUILD 0
0071 #define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \
0072     __stringify(BUILD)
0073 
0074 MODULE_VERSION(DRV_VERSION);
0075 
0076 static struct scsi_transport_template *isci_transport_template;
0077 
0078 static const struct pci_device_id isci_id_table[] = {
0079     { PCI_VDEVICE(INTEL, 0x1D61),},
0080     { PCI_VDEVICE(INTEL, 0x1D63),},
0081     { PCI_VDEVICE(INTEL, 0x1D65),},
0082     { PCI_VDEVICE(INTEL, 0x1D67),},
0083     { PCI_VDEVICE(INTEL, 0x1D69),},
0084     { PCI_VDEVICE(INTEL, 0x1D6B),},
0085     { PCI_VDEVICE(INTEL, 0x1D60),},
0086     { PCI_VDEVICE(INTEL, 0x1D62),},
0087     { PCI_VDEVICE(INTEL, 0x1D64),},
0088     { PCI_VDEVICE(INTEL, 0x1D66),},
0089     { PCI_VDEVICE(INTEL, 0x1D68),},
0090     { PCI_VDEVICE(INTEL, 0x1D6A),},
0091     {}
0092 };
0093 
0094 MODULE_DEVICE_TABLE(pci, isci_id_table);
0095 
0096 /* linux isci specific settings */
0097 
0098 unsigned char no_outbound_task_to = 2;
0099 module_param(no_outbound_task_to, byte, 0);
0100 MODULE_PARM_DESC(no_outbound_task_to, "No Outbound Task Timeout (1us incr)");
0101 
0102 u16 ssp_max_occ_to = 20;
0103 module_param(ssp_max_occ_to, ushort, 0);
0104 MODULE_PARM_DESC(ssp_max_occ_to, "SSP Max occupancy timeout (100us incr)");
0105 
0106 u16 stp_max_occ_to = 5;
0107 module_param(stp_max_occ_to, ushort, 0);
0108 MODULE_PARM_DESC(stp_max_occ_to, "STP Max occupancy timeout (100us incr)");
0109 
0110 u16 ssp_inactive_to = 5;
0111 module_param(ssp_inactive_to, ushort, 0);
0112 MODULE_PARM_DESC(ssp_inactive_to, "SSP inactivity timeout (100us incr)");
0113 
0114 u16 stp_inactive_to = 5;
0115 module_param(stp_inactive_to, ushort, 0);
0116 MODULE_PARM_DESC(stp_inactive_to, "STP inactivity timeout (100us incr)");
0117 
0118 unsigned char phy_gen = SCIC_SDS_PARM_GEN2_SPEED;
0119 module_param(phy_gen, byte, 0);
0120 MODULE_PARM_DESC(phy_gen, "PHY generation (1: 1.5Gbps 2: 3.0Gbps 3: 6.0Gbps)");
0121 
0122 unsigned char max_concurr_spinup;
0123 module_param(max_concurr_spinup, byte, 0);
0124 MODULE_PARM_DESC(max_concurr_spinup, "Max concurrent device spinup");
0125 
0126 uint cable_selection_override = CABLE_OVERRIDE_DISABLED;
0127 module_param(cable_selection_override, uint, 0);
0128 
0129 MODULE_PARM_DESC(cable_selection_override,
0130          "This field indicates length of the SAS/SATA cable between "
0131          "host and device. If any bits > 15 are set (default) "
0132          "indicates \"use platform defaults\"");
0133 
0134 static ssize_t isci_show_id(struct device *dev, struct device_attribute *attr, char *buf)
0135 {
0136     struct Scsi_Host *shost = container_of(dev, typeof(*shost), shost_dev);
0137     struct sas_ha_struct *sas_ha = SHOST_TO_SAS_HA(shost);
0138     struct isci_host *ihost = container_of(sas_ha, typeof(*ihost), sas_ha);
0139 
0140     return snprintf(buf, PAGE_SIZE, "%d\n", ihost->id);
0141 }
0142 
0143 static DEVICE_ATTR(isci_id, S_IRUGO, isci_show_id, NULL);
0144 
0145 static struct attribute *isci_host_attrs[] = {
0146     &dev_attr_isci_id.attr,
0147     NULL
0148 };
0149 
0150 ATTRIBUTE_GROUPS(isci_host);
0151 
0152 static struct scsi_host_template isci_sht = {
0153 
0154     .module             = THIS_MODULE,
0155     .name               = DRV_NAME,
0156     .proc_name          = DRV_NAME,
0157     .queuecommand           = sas_queuecommand,
0158     .dma_need_drain         = ata_scsi_dma_need_drain,
0159     .target_alloc           = sas_target_alloc,
0160     .slave_configure        = sas_slave_configure,
0161     .scan_finished          = isci_host_scan_finished,
0162     .scan_start         = isci_host_start,
0163     .change_queue_depth     = sas_change_queue_depth,
0164     .bios_param         = sas_bios_param,
0165     .can_queue          = ISCI_CAN_QUEUE_VAL,
0166     .this_id            = -1,
0167     .sg_tablesize           = SG_ALL,
0168     .max_sectors            = SCSI_DEFAULT_MAX_SECTORS,
0169     .eh_abort_handler       = sas_eh_abort_handler,
0170     .eh_device_reset_handler        = sas_eh_device_reset_handler,
0171     .eh_target_reset_handler        = sas_eh_target_reset_handler,
0172     .slave_alloc            = sas_slave_alloc,
0173     .target_destroy         = sas_target_destroy,
0174     .ioctl              = sas_ioctl,
0175 #ifdef CONFIG_COMPAT
0176     .compat_ioctl           = sas_ioctl,
0177 #endif
0178     .shost_groups           = isci_host_groups,
0179     .track_queue_depth      = 1,
0180 };
0181 
0182 static struct sas_domain_function_template isci_transport_ops  = {
0183 
0184     /* The class calls these to notify the LLDD of an event. */
0185     .lldd_port_formed   = isci_port_formed,
0186     .lldd_port_deformed = isci_port_deformed,
0187 
0188     /* The class calls these when a device is found or gone. */
0189     .lldd_dev_found     = isci_remote_device_found,
0190     .lldd_dev_gone      = isci_remote_device_gone,
0191 
0192     .lldd_execute_task  = isci_task_execute_task,
0193     /* Task Management Functions. Must be called from process context. */
0194     .lldd_abort_task    = isci_task_abort_task,
0195     .lldd_abort_task_set    = isci_task_abort_task_set,
0196     .lldd_clear_task_set    = isci_task_clear_task_set,
0197     .lldd_I_T_nexus_reset   = isci_task_I_T_nexus_reset,
0198     .lldd_lu_reset      = isci_task_lu_reset,
0199     .lldd_query_task    = isci_task_query_task,
0200 
0201     /* ata recovery called from ata-eh */
0202     .lldd_ata_check_ready   = isci_ata_check_ready,
0203 
0204     /* Port and Adapter management */
0205     .lldd_clear_nexus_port  = isci_task_clear_nexus_port,
0206     .lldd_clear_nexus_ha    = isci_task_clear_nexus_ha,
0207 
0208     /* Phy management */
0209     .lldd_control_phy   = isci_phy_control,
0210 
0211     /* GPIO support */
0212     .lldd_write_gpio    = isci_gpio_write,
0213 };
0214 
0215 
0216 /******************************************************************************
0217 * P R O T E C T E D  M E T H O D S
0218 ******************************************************************************/
0219 
0220 
0221 
0222 /**
0223  * isci_register_sas_ha() - This method initializes various lldd
0224  *    specific members of the sas_ha struct and calls the libsas
0225  *    sas_register_ha() function.
0226  * @isci_host: This parameter specifies the lldd specific wrapper for the
0227  *    libsas sas_ha struct.
0228  *
0229  * This method returns an error code indicating success or failure. The user
0230  * should check for possible memory allocation error return otherwise, a zero
0231  * indicates success.
0232  */
0233 static int isci_register_sas_ha(struct isci_host *isci_host)
0234 {
0235     int i;
0236     struct sas_ha_struct *sas_ha = &(isci_host->sas_ha);
0237     struct asd_sas_phy **sas_phys;
0238     struct asd_sas_port **sas_ports;
0239 
0240     sas_phys = devm_kcalloc(&isci_host->pdev->dev,
0241                 SCI_MAX_PHYS, sizeof(void *),
0242                 GFP_KERNEL);
0243     if (!sas_phys)
0244         return -ENOMEM;
0245 
0246     sas_ports = devm_kcalloc(&isci_host->pdev->dev,
0247                  SCI_MAX_PORTS, sizeof(void *),
0248                  GFP_KERNEL);
0249     if (!sas_ports)
0250         return -ENOMEM;
0251 
0252     sas_ha->sas_ha_name = DRV_NAME;
0253     sas_ha->lldd_module = THIS_MODULE;
0254     sas_ha->sas_addr    = &isci_host->phys[0].sas_addr[0];
0255 
0256     for (i = 0; i < SCI_MAX_PHYS; i++) {
0257         sas_phys[i] = &isci_host->phys[i].sas_phy;
0258         sas_ports[i] = &isci_host->sas_ports[i];
0259     }
0260 
0261     sas_ha->sas_phy  = sas_phys;
0262     sas_ha->sas_port = sas_ports;
0263     sas_ha->num_phys = SCI_MAX_PHYS;
0264 
0265     sas_ha->strict_wide_ports = 1;
0266 
0267     sas_register_ha(sas_ha);
0268 
0269     return 0;
0270 }
0271 
0272 static void isci_unregister(struct isci_host *isci_host)
0273 {
0274     struct Scsi_Host *shost;
0275 
0276     if (!isci_host)
0277         return;
0278 
0279     shost = to_shost(isci_host);
0280     sas_unregister_ha(&isci_host->sas_ha);
0281 
0282     sas_remove_host(shost);
0283     scsi_host_put(shost);
0284 }
0285 
0286 static int isci_pci_init(struct pci_dev *pdev)
0287 {
0288     int err, bar_num, bar_mask = 0;
0289     void __iomem * const *iomap;
0290 
0291     err = pcim_enable_device(pdev);
0292     if (err) {
0293         dev_err(&pdev->dev,
0294             "failed enable PCI device %s!\n",
0295             pci_name(pdev));
0296         return err;
0297     }
0298 
0299     for (bar_num = 0; bar_num < SCI_PCI_BAR_COUNT; bar_num++)
0300         bar_mask |= 1 << (bar_num * 2);
0301 
0302     err = pcim_iomap_regions(pdev, bar_mask, DRV_NAME);
0303     if (err)
0304         return err;
0305 
0306     iomap = pcim_iomap_table(pdev);
0307     if (!iomap)
0308         return -ENOMEM;
0309 
0310     pci_set_master(pdev);
0311 
0312     err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
0313     if (err)
0314         err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
0315     return err;
0316 }
0317 
0318 static int num_controllers(struct pci_dev *pdev)
0319 {
0320     /* bar size alone can tell us if we are running with a dual controller
0321      * part, no need to trust revision ids that might be under broken firmware
0322      * control
0323      */
0324     resource_size_t scu_bar_size = pci_resource_len(pdev, SCI_SCU_BAR*2);
0325     resource_size_t smu_bar_size = pci_resource_len(pdev, SCI_SMU_BAR*2);
0326 
0327     if (scu_bar_size >= SCI_SCU_BAR_SIZE*SCI_MAX_CONTROLLERS &&
0328         smu_bar_size >= SCI_SMU_BAR_SIZE*SCI_MAX_CONTROLLERS)
0329         return SCI_MAX_CONTROLLERS;
0330     else
0331         return 1;
0332 }
0333 
0334 static int isci_setup_interrupts(struct pci_dev *pdev)
0335 {
0336     int err, i, num_msix;
0337     struct isci_host *ihost;
0338     struct isci_pci_info *pci_info = to_pci_info(pdev);
0339 
0340     /*
0341      *  Determine the number of vectors associated with this
0342      *  PCI function.
0343      */
0344     num_msix = num_controllers(pdev) * SCI_NUM_MSI_X_INT;
0345 
0346     err = pci_alloc_irq_vectors(pdev, num_msix, num_msix, PCI_IRQ_MSIX);
0347     if (err < 0)
0348         goto intx;
0349 
0350     for (i = 0; i < num_msix; i++) {
0351         int id = i / SCI_NUM_MSI_X_INT;
0352         irq_handler_t isr;
0353 
0354         ihost = pci_info->hosts[id];
0355         /* odd numbered vectors are error interrupts */
0356         if (i & 1)
0357             isr = isci_error_isr;
0358         else
0359             isr = isci_msix_isr;
0360 
0361         err = devm_request_irq(&pdev->dev, pci_irq_vector(pdev, i),
0362                 isr, 0, DRV_NAME"-msix", ihost);
0363         if (!err)
0364             continue;
0365 
0366         dev_info(&pdev->dev, "msix setup failed falling back to intx\n");
0367         while (i--) {
0368             id = i / SCI_NUM_MSI_X_INT;
0369             ihost = pci_info->hosts[id];
0370             devm_free_irq(&pdev->dev, pci_irq_vector(pdev, i),
0371                     ihost);
0372         }
0373         pci_free_irq_vectors(pdev);
0374         goto intx;
0375     }
0376     return 0;
0377 
0378  intx:
0379     for_each_isci_host(i, ihost, pdev) {
0380         err = devm_request_irq(&pdev->dev, pci_irq_vector(pdev, 0),
0381                 isci_intx_isr, IRQF_SHARED, DRV_NAME"-intx",
0382                 ihost);
0383         if (err)
0384             break;
0385     }
0386     return err;
0387 }
0388 
0389 static void isci_user_parameters_get(struct sci_user_parameters *u)
0390 {
0391     int i;
0392 
0393     for (i = 0; i < SCI_MAX_PHYS; i++) {
0394         struct sci_phy_user_params *u_phy = &u->phys[i];
0395 
0396         u_phy->max_speed_generation = phy_gen;
0397 
0398         /* we are not exporting these for now */
0399         u_phy->align_insertion_frequency = 0x7f;
0400         u_phy->in_connection_align_insertion_frequency = 0xff;
0401         u_phy->notify_enable_spin_up_insertion_frequency = 0x33;
0402     }
0403 
0404     u->stp_inactivity_timeout = stp_inactive_to;
0405     u->ssp_inactivity_timeout = ssp_inactive_to;
0406     u->stp_max_occupancy_timeout = stp_max_occ_to;
0407     u->ssp_max_occupancy_timeout = ssp_max_occ_to;
0408     u->no_outbound_task_timeout = no_outbound_task_to;
0409     u->max_concurr_spinup = max_concurr_spinup;
0410 }
0411 
0412 static enum sci_status sci_user_parameters_set(struct isci_host *ihost,
0413                            struct sci_user_parameters *sci_parms)
0414 {
0415     u16 index;
0416 
0417     /*
0418      * Validate the user parameters.  If they are not legal, then
0419      * return a failure.
0420      */
0421     for (index = 0; index < SCI_MAX_PHYS; index++) {
0422         struct sci_phy_user_params *u;
0423 
0424         u = &sci_parms->phys[index];
0425 
0426         if (!((u->max_speed_generation <= SCIC_SDS_PARM_MAX_SPEED) &&
0427               (u->max_speed_generation > SCIC_SDS_PARM_NO_SPEED)))
0428             return SCI_FAILURE_INVALID_PARAMETER_VALUE;
0429 
0430         if ((u->in_connection_align_insertion_frequency < 3) ||
0431             (u->align_insertion_frequency == 0) ||
0432             (u->notify_enable_spin_up_insertion_frequency == 0))
0433             return SCI_FAILURE_INVALID_PARAMETER_VALUE;
0434     }
0435 
0436     if ((sci_parms->stp_inactivity_timeout == 0) ||
0437         (sci_parms->ssp_inactivity_timeout == 0) ||
0438         (sci_parms->stp_max_occupancy_timeout == 0) ||
0439         (sci_parms->ssp_max_occupancy_timeout == 0) ||
0440         (sci_parms->no_outbound_task_timeout == 0))
0441         return SCI_FAILURE_INVALID_PARAMETER_VALUE;
0442 
0443     memcpy(&ihost->user_parameters, sci_parms, sizeof(*sci_parms));
0444 
0445     return SCI_SUCCESS;
0446 }
0447 
0448 static void sci_oem_defaults(struct isci_host *ihost)
0449 {
0450     /* these defaults are overridden by the platform / firmware */
0451     struct sci_user_parameters *user = &ihost->user_parameters;
0452     struct sci_oem_params *oem = &ihost->oem_parameters;
0453     int i;
0454 
0455     /* Default to APC mode. */
0456     oem->controller.mode_type = SCIC_PORT_AUTOMATIC_CONFIGURATION_MODE;
0457 
0458     /* Default to APC mode. */
0459     oem->controller.max_concurr_spin_up = 1;
0460 
0461     /* Default to no SSC operation. */
0462     oem->controller.do_enable_ssc = false;
0463 
0464     /* Default to short cables on all phys. */
0465     oem->controller.cable_selection_mask = 0;
0466 
0467     /* Initialize all of the port parameter information to narrow ports. */
0468     for (i = 0; i < SCI_MAX_PORTS; i++)
0469         oem->ports[i].phy_mask = 0;
0470 
0471     /* Initialize all of the phy parameter information. */
0472     for (i = 0; i < SCI_MAX_PHYS; i++) {
0473         /* Default to 3G (i.e. Gen 2). */
0474         user->phys[i].max_speed_generation = SCIC_SDS_PARM_GEN2_SPEED;
0475 
0476         /* the frequencies cannot be 0 */
0477         user->phys[i].align_insertion_frequency = 0x7f;
0478         user->phys[i].in_connection_align_insertion_frequency = 0xff;
0479         user->phys[i].notify_enable_spin_up_insertion_frequency = 0x33;
0480 
0481         /* Previous Vitesse based expanders had a arbitration issue that
0482          * is worked around by having the upper 32-bits of SAS address
0483          * with a value greater then the Vitesse company identifier.
0484          * Hence, usage of 0x5FCFFFFF.
0485          */
0486         oem->phys[i].sas_address.low = 0x1 + ihost->id;
0487         oem->phys[i].sas_address.high = 0x5FCFFFFF;
0488     }
0489 
0490     user->stp_inactivity_timeout = 5;
0491     user->ssp_inactivity_timeout = 5;
0492     user->stp_max_occupancy_timeout = 5;
0493     user->ssp_max_occupancy_timeout = 20;
0494     user->no_outbound_task_timeout = 2;
0495 }
0496 
0497 static struct isci_host *isci_host_alloc(struct pci_dev *pdev, int id)
0498 {
0499     struct isci_orom *orom = to_pci_info(pdev)->orom;
0500     struct sci_user_parameters sci_user_params;
0501     u8 oem_version = ISCI_ROM_VER_1_0;
0502     struct isci_host *ihost;
0503     struct Scsi_Host *shost;
0504     int err, i;
0505 
0506     ihost = devm_kzalloc(&pdev->dev, sizeof(*ihost), GFP_KERNEL);
0507     if (!ihost)
0508         return NULL;
0509 
0510     ihost->pdev = pdev;
0511     ihost->id = id;
0512     spin_lock_init(&ihost->scic_lock);
0513     init_waitqueue_head(&ihost->eventq);
0514     ihost->sas_ha.dev = &ihost->pdev->dev;
0515     ihost->sas_ha.lldd_ha = ihost;
0516     tasklet_init(&ihost->completion_tasklet,
0517              isci_host_completion_routine, (unsigned long)ihost);
0518 
0519     /* validate module parameters */
0520     /* TODO: kill struct sci_user_parameters and reference directly */
0521     sci_oem_defaults(ihost);
0522     isci_user_parameters_get(&sci_user_params);
0523     if (sci_user_parameters_set(ihost, &sci_user_params)) {
0524         dev_warn(&pdev->dev,
0525              "%s: sci_user_parameters_set failed\n", __func__);
0526         return NULL;
0527     }
0528 
0529     /* sanity check platform (or 'firmware') oem parameters */
0530     if (orom) {
0531         if (id < 0 || id >= SCI_MAX_CONTROLLERS || id > orom->hdr.num_elements) {
0532             dev_warn(&pdev->dev, "parsing firmware oem parameters failed\n");
0533             return NULL;
0534         }
0535         ihost->oem_parameters = orom->ctrl[id];
0536         oem_version = orom->hdr.version;
0537     }
0538 
0539     /* validate oem parameters (platform, firmware, or built-in defaults) */
0540     if (sci_oem_parameters_validate(&ihost->oem_parameters, oem_version)) {
0541         dev_warn(&pdev->dev, "oem parameter validation failed\n");
0542         return NULL;
0543     }
0544 
0545     for (i = 0; i < SCI_MAX_PORTS; i++) {
0546         struct isci_port *iport = &ihost->ports[i];
0547 
0548         INIT_LIST_HEAD(&iport->remote_dev_list);
0549         iport->isci_host = ihost;
0550     }
0551 
0552     for (i = 0; i < SCI_MAX_PHYS; i++)
0553         isci_phy_init(&ihost->phys[i], ihost, i);
0554 
0555     for (i = 0; i < SCI_MAX_REMOTE_DEVICES; i++) {
0556         struct isci_remote_device *idev = &ihost->devices[i];
0557 
0558         INIT_LIST_HEAD(&idev->node);
0559     }
0560 
0561     shost = scsi_host_alloc(&isci_sht, sizeof(void *));
0562     if (!shost)
0563         return NULL;
0564 
0565     dev_info(&pdev->dev, "%sSCU controller %d: phy 3-0 cables: "
0566          "{%s, %s, %s, %s}\n",
0567          (is_cable_select_overridden() ? "* " : ""), ihost->id,
0568          lookup_cable_names(decode_cable_selection(ihost, 3)),
0569          lookup_cable_names(decode_cable_selection(ihost, 2)),
0570          lookup_cable_names(decode_cable_selection(ihost, 1)),
0571          lookup_cable_names(decode_cable_selection(ihost, 0)));
0572 
0573     err = isci_host_init(ihost);
0574     if (err)
0575         goto err_shost;
0576 
0577     SHOST_TO_SAS_HA(shost) = &ihost->sas_ha;
0578     ihost->sas_ha.core.shost = shost;
0579     shost->transportt = isci_transport_template;
0580 
0581     shost->max_id = ~0;
0582     shost->max_lun = ~0;
0583     shost->max_cmd_len = MAX_COMMAND_SIZE;
0584 
0585     /* turn on DIF support */
0586     scsi_host_set_prot(shost,
0587                SHOST_DIF_TYPE1_PROTECTION |
0588                SHOST_DIF_TYPE2_PROTECTION |
0589                SHOST_DIF_TYPE3_PROTECTION);
0590     scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
0591 
0592     err = scsi_add_host(shost, &pdev->dev);
0593     if (err)
0594         goto err_shost;
0595 
0596     err = isci_register_sas_ha(ihost);
0597     if (err)
0598         goto err_shost_remove;
0599 
0600     return ihost;
0601 
0602  err_shost_remove:
0603     scsi_remove_host(shost);
0604  err_shost:
0605     scsi_host_put(shost);
0606 
0607     return NULL;
0608 }
0609 
0610 static int isci_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
0611 {
0612     struct isci_pci_info *pci_info;
0613     int err, i;
0614     struct isci_host *isci_host;
0615     const struct firmware *fw = NULL;
0616     struct isci_orom *orom = NULL;
0617     char *source = "(platform)";
0618 
0619     dev_info(&pdev->dev, "driver configured for rev: %d silicon\n",
0620          pdev->revision);
0621 
0622     pci_info = devm_kzalloc(&pdev->dev, sizeof(*pci_info), GFP_KERNEL);
0623     if (!pci_info)
0624         return -ENOMEM;
0625     pci_set_drvdata(pdev, pci_info);
0626 
0627     if (efi_rt_services_supported(EFI_RT_SUPPORTED_GET_VARIABLE))
0628         orom = isci_get_efi_var(pdev);
0629 
0630     if (!orom)
0631         orom = isci_request_oprom(pdev);
0632 
0633     for (i = 0; orom && i < num_controllers(pdev); i++) {
0634         if (sci_oem_parameters_validate(&orom->ctrl[i],
0635                         orom->hdr.version)) {
0636             dev_warn(&pdev->dev,
0637                  "[%d]: invalid oem parameters detected, falling back to firmware\n", i);
0638             orom = NULL;
0639             break;
0640         }
0641     }
0642 
0643     if (!orom) {
0644         source = "(firmware)";
0645         orom = isci_request_firmware(pdev, fw);
0646         if (!orom) {
0647             /* TODO convert this to WARN_TAINT_ONCE once the
0648              * orom/efi parameter support is widely available
0649              */
0650             dev_warn(&pdev->dev,
0651                  "Loading user firmware failed, using default "
0652                  "values\n");
0653             dev_warn(&pdev->dev,
0654                  "Default OEM configuration being used: 4 "
0655                  "narrow ports, and default SAS Addresses\n");
0656         }
0657     }
0658 
0659     if (orom)
0660         dev_info(&pdev->dev,
0661              "OEM SAS parameters (version: %u.%u) loaded %s\n",
0662              (orom->hdr.version & 0xf0) >> 4,
0663              (orom->hdr.version & 0xf), source);
0664 
0665     pci_info->orom = orom;
0666 
0667     err = isci_pci_init(pdev);
0668     if (err)
0669         return err;
0670 
0671     for (i = 0; i < num_controllers(pdev); i++) {
0672         struct isci_host *h = isci_host_alloc(pdev, i);
0673 
0674         if (!h) {
0675             err = -ENOMEM;
0676             goto err_host_alloc;
0677         }
0678         pci_info->hosts[i] = h;
0679     }
0680 
0681     err = isci_setup_interrupts(pdev);
0682     if (err)
0683         goto err_host_alloc;
0684 
0685     for_each_isci_host(i, isci_host, pdev)
0686         scsi_scan_host(to_shost(isci_host));
0687 
0688     return 0;
0689 
0690  err_host_alloc:
0691     for_each_isci_host(i, isci_host, pdev)
0692         isci_unregister(isci_host);
0693     return err;
0694 }
0695 
0696 static void isci_pci_remove(struct pci_dev *pdev)
0697 {
0698     struct isci_host *ihost;
0699     int i;
0700 
0701     for_each_isci_host(i, ihost, pdev) {
0702         wait_for_start(ihost);
0703         isci_unregister(ihost);
0704         isci_host_deinit(ihost);
0705     }
0706 }
0707 
0708 #ifdef CONFIG_PM_SLEEP
0709 static int isci_suspend(struct device *dev)
0710 {
0711     struct pci_dev *pdev = to_pci_dev(dev);
0712     struct isci_host *ihost;
0713     int i;
0714 
0715     for_each_isci_host(i, ihost, pdev) {
0716         sas_suspend_ha(&ihost->sas_ha);
0717         isci_host_deinit(ihost);
0718     }
0719 
0720     return 0;
0721 }
0722 
0723 static int isci_resume(struct device *dev)
0724 {
0725     struct pci_dev *pdev = to_pci_dev(dev);
0726     struct isci_host *ihost;
0727     int i;
0728 
0729     for_each_isci_host(i, ihost, pdev) {
0730         sas_prep_resume_ha(&ihost->sas_ha);
0731 
0732         isci_host_init(ihost);
0733         isci_host_start(ihost->sas_ha.core.shost);
0734         wait_for_start(ihost);
0735 
0736         sas_resume_ha(&ihost->sas_ha);
0737     }
0738 
0739     return 0;
0740 }
0741 #endif
0742 
0743 static SIMPLE_DEV_PM_OPS(isci_pm_ops, isci_suspend, isci_resume);
0744 
0745 static struct pci_driver isci_pci_driver = {
0746     .name       = DRV_NAME,
0747     .id_table   = isci_id_table,
0748     .probe      = isci_pci_probe,
0749     .remove     = isci_pci_remove,
0750     .driver.pm      = &isci_pm_ops,
0751 };
0752 
0753 static __init int isci_init(void)
0754 {
0755     int err;
0756 
0757     pr_info("%s: Intel(R) C600 SAS Controller Driver - version %s\n",
0758         DRV_NAME, DRV_VERSION);
0759 
0760     isci_transport_template = sas_domain_attach_transport(&isci_transport_ops);
0761     if (!isci_transport_template)
0762         return -ENOMEM;
0763 
0764     err = pci_register_driver(&isci_pci_driver);
0765     if (err)
0766         sas_release_transport(isci_transport_template);
0767 
0768     return err;
0769 }
0770 
0771 static __exit void isci_exit(void)
0772 {
0773     pci_unregister_driver(&isci_pci_driver);
0774     sas_release_transport(isci_transport_template);
0775 }
0776 
0777 MODULE_LICENSE("Dual BSD/GPL");
0778 MODULE_FIRMWARE(ISCI_FW_NAME);
0779 module_init(isci_init);
0780 module_exit(isci_exit);