init.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  1. /*
  2. * This file is provided under a dual BSD/GPLv2 license. When using or
  3. * redistributing this file, you may do so under either license.
  4. *
  5. * GPL LICENSE SUMMARY
  6. *
  7. * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of version 2 of the GNU General Public License as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  21. * The full GNU General Public License is included in this distribution
  22. * in the file called LICENSE.GPL.
  23. *
  24. * BSD LICENSE
  25. *
  26. * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
  27. * All rights reserved.
  28. *
  29. * Redistribution and use in source and binary forms, with or without
  30. * modification, are permitted provided that the following conditions
  31. * are met:
  32. *
  33. * * Redistributions of source code must retain the above copyright
  34. * notice, this list of conditions and the following disclaimer.
  35. * * Redistributions in binary form must reproduce the above copyright
  36. * notice, this list of conditions and the following disclaimer in
  37. * the documentation and/or other materials provided with the
  38. * distribution.
  39. * * Neither the name of Intel Corporation nor the names of its
  40. * contributors may be used to endorse or promote products derived
  41. * from this software without specific prior written permission.
  42. *
  43. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  44. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  45. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  46. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  47. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  48. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  49. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  50. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  51. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  52. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  53. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  54. */
  55. #include <linux/kernel.h>
  56. #include <linux/init.h>
  57. #include <linux/module.h>
  58. #include <linux/firmware.h>
  59. #include <linux/efi.h>
  60. #include <asm/string.h>
  61. #include <scsi/scsi_host.h>
  62. #include "host.h"
  63. #include "isci.h"
  64. #include "task.h"
  65. #include "probe_roms.h"
  66. #define MAJ 1
  67. #define MIN 2
  68. #define BUILD 0
  69. #define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \
  70. __stringify(BUILD)
  71. MODULE_VERSION(DRV_VERSION);
  72. static struct scsi_transport_template *isci_transport_template;
  73. static const struct pci_device_id isci_id_table[] = {
  74. { PCI_VDEVICE(INTEL, 0x1D61),},
  75. { PCI_VDEVICE(INTEL, 0x1D63),},
  76. { PCI_VDEVICE(INTEL, 0x1D65),},
  77. { PCI_VDEVICE(INTEL, 0x1D67),},
  78. { PCI_VDEVICE(INTEL, 0x1D69),},
  79. { PCI_VDEVICE(INTEL, 0x1D6B),},
  80. { PCI_VDEVICE(INTEL, 0x1D60),},
  81. { PCI_VDEVICE(INTEL, 0x1D62),},
  82. { PCI_VDEVICE(INTEL, 0x1D64),},
  83. { PCI_VDEVICE(INTEL, 0x1D66),},
  84. { PCI_VDEVICE(INTEL, 0x1D68),},
  85. { PCI_VDEVICE(INTEL, 0x1D6A),},
  86. {}
  87. };
  88. MODULE_DEVICE_TABLE(pci, isci_id_table);
  89. /* linux isci specific settings */
  90. unsigned char no_outbound_task_to = 2;
  91. module_param(no_outbound_task_to, byte, 0);
  92. MODULE_PARM_DESC(no_outbound_task_to, "No Outbound Task Timeout (1us incr)");
  93. u16 ssp_max_occ_to = 20;
  94. module_param(ssp_max_occ_to, ushort, 0);
  95. MODULE_PARM_DESC(ssp_max_occ_to, "SSP Max occupancy timeout (100us incr)");
  96. u16 stp_max_occ_to = 5;
  97. module_param(stp_max_occ_to, ushort, 0);
  98. MODULE_PARM_DESC(stp_max_occ_to, "STP Max occupancy timeout (100us incr)");
  99. u16 ssp_inactive_to = 5;
  100. module_param(ssp_inactive_to, ushort, 0);
  101. MODULE_PARM_DESC(ssp_inactive_to, "SSP inactivity timeout (100us incr)");
  102. u16 stp_inactive_to = 5;
  103. module_param(stp_inactive_to, ushort, 0);
  104. MODULE_PARM_DESC(stp_inactive_to, "STP inactivity timeout (100us incr)");
  105. unsigned char phy_gen = SCIC_SDS_PARM_GEN2_SPEED;
  106. module_param(phy_gen, byte, 0);
  107. MODULE_PARM_DESC(phy_gen, "PHY generation (1: 1.5Gbps 2: 3.0Gbps 3: 6.0Gbps)");
  108. unsigned char max_concurr_spinup;
  109. module_param(max_concurr_spinup, byte, 0);
  110. MODULE_PARM_DESC(max_concurr_spinup, "Max concurrent device spinup");
  111. uint cable_selection_override = CABLE_OVERRIDE_DISABLED;
  112. module_param(cable_selection_override, uint, 0);
  113. MODULE_PARM_DESC(cable_selection_override,
  114. "This field indicates length of the SAS/SATA cable between "
  115. "host and device. If any bits > 15 are set (default) "
  116. "indicates \"use platform defaults\"");
  117. static ssize_t isci_show_id(struct device *dev, struct device_attribute *attr, char *buf)
  118. {
  119. struct Scsi_Host *shost = container_of(dev, typeof(*shost), shost_dev);
  120. struct sas_ha_struct *sas_ha = SHOST_TO_SAS_HA(shost);
  121. struct isci_host *ihost = container_of(sas_ha, typeof(*ihost), sas_ha);
  122. return snprintf(buf, PAGE_SIZE, "%d\n", ihost->id);
  123. }
  124. static DEVICE_ATTR(isci_id, S_IRUGO, isci_show_id, NULL);
  125. static struct attribute *isci_host_attrs[] = {
  126. &dev_attr_isci_id.attr,
  127. NULL
  128. };
  129. ATTRIBUTE_GROUPS(isci_host);
  130. static struct scsi_host_template isci_sht = {
  131. .module = THIS_MODULE,
  132. .name = DRV_NAME,
  133. .proc_name = DRV_NAME,
  134. .queuecommand = sas_queuecommand,
  135. .dma_need_drain = ata_scsi_dma_need_drain,
  136. .target_alloc = sas_target_alloc,
  137. .slave_configure = sas_slave_configure,
  138. .scan_finished = isci_host_scan_finished,
  139. .scan_start = isci_host_start,
  140. .change_queue_depth = sas_change_queue_depth,
  141. .bios_param = sas_bios_param,
  142. .can_queue = ISCI_CAN_QUEUE_VAL,
  143. .this_id = -1,
  144. .sg_tablesize = SG_ALL,
  145. .max_sectors = SCSI_DEFAULT_MAX_SECTORS,
  146. .eh_abort_handler = sas_eh_abort_handler,
  147. .eh_device_reset_handler = sas_eh_device_reset_handler,
  148. .eh_target_reset_handler = sas_eh_target_reset_handler,
  149. .slave_alloc = sas_slave_alloc,
  150. .target_destroy = sas_target_destroy,
  151. .ioctl = sas_ioctl,
  152. #ifdef CONFIG_COMPAT
  153. .compat_ioctl = sas_ioctl,
  154. #endif
  155. .shost_groups = isci_host_groups,
  156. .track_queue_depth = 1,
  157. };
  158. static struct sas_domain_function_template isci_transport_ops = {
  159. /* The class calls these to notify the LLDD of an event. */
  160. .lldd_port_formed = isci_port_formed,
  161. .lldd_port_deformed = isci_port_deformed,
  162. /* The class calls these when a device is found or gone. */
  163. .lldd_dev_found = isci_remote_device_found,
  164. .lldd_dev_gone = isci_remote_device_gone,
  165. .lldd_execute_task = isci_task_execute_task,
  166. /* Task Management Functions. Must be called from process context. */
  167. .lldd_abort_task = isci_task_abort_task,
  168. .lldd_abort_task_set = isci_task_abort_task_set,
  169. .lldd_clear_task_set = isci_task_clear_task_set,
  170. .lldd_I_T_nexus_reset = isci_task_I_T_nexus_reset,
  171. .lldd_lu_reset = isci_task_lu_reset,
  172. .lldd_query_task = isci_task_query_task,
  173. /* ata recovery called from ata-eh */
  174. .lldd_ata_check_ready = isci_ata_check_ready,
  175. /* Port and Adapter management */
  176. .lldd_clear_nexus_port = isci_task_clear_nexus_port,
  177. .lldd_clear_nexus_ha = isci_task_clear_nexus_ha,
  178. /* Phy management */
  179. .lldd_control_phy = isci_phy_control,
  180. /* GPIO support */
  181. .lldd_write_gpio = isci_gpio_write,
  182. };
  183. /******************************************************************************
  184. * P R O T E C T E D M E T H O D S
  185. ******************************************************************************/
  186. /**
  187. * isci_register_sas_ha() - This method initializes various lldd
  188. * specific members of the sas_ha struct and calls the libsas
  189. * sas_register_ha() function.
  190. * @isci_host: This parameter specifies the lldd specific wrapper for the
  191. * libsas sas_ha struct.
  192. *
  193. * This method returns an error code indicating success or failure. The user
  194. * should check for possible memory allocation error return otherwise, a zero
  195. * indicates success.
  196. */
  197. static int isci_register_sas_ha(struct isci_host *isci_host)
  198. {
  199. int i;
  200. struct sas_ha_struct *sas_ha = &(isci_host->sas_ha);
  201. struct asd_sas_phy **sas_phys;
  202. struct asd_sas_port **sas_ports;
  203. sas_phys = devm_kcalloc(&isci_host->pdev->dev,
  204. SCI_MAX_PHYS, sizeof(void *),
  205. GFP_KERNEL);
  206. if (!sas_phys)
  207. return -ENOMEM;
  208. sas_ports = devm_kcalloc(&isci_host->pdev->dev,
  209. SCI_MAX_PORTS, sizeof(void *),
  210. GFP_KERNEL);
  211. if (!sas_ports)
  212. return -ENOMEM;
  213. sas_ha->sas_ha_name = DRV_NAME;
  214. sas_ha->lldd_module = THIS_MODULE;
  215. sas_ha->sas_addr = &isci_host->phys[0].sas_addr[0];
  216. for (i = 0; i < SCI_MAX_PHYS; i++) {
  217. sas_phys[i] = &isci_host->phys[i].sas_phy;
  218. sas_ports[i] = &isci_host->sas_ports[i];
  219. }
  220. sas_ha->sas_phy = sas_phys;
  221. sas_ha->sas_port = sas_ports;
  222. sas_ha->num_phys = SCI_MAX_PHYS;
  223. sas_ha->strict_wide_ports = 1;
  224. sas_register_ha(sas_ha);
  225. return 0;
  226. }
  227. static void isci_unregister(struct isci_host *isci_host)
  228. {
  229. struct Scsi_Host *shost;
  230. if (!isci_host)
  231. return;
  232. shost = to_shost(isci_host);
  233. sas_unregister_ha(&isci_host->sas_ha);
  234. sas_remove_host(shost);
  235. scsi_host_put(shost);
  236. }
  237. static int isci_pci_init(struct pci_dev *pdev)
  238. {
  239. int err, bar_num, bar_mask = 0;
  240. void __iomem * const *iomap;
  241. err = pcim_enable_device(pdev);
  242. if (err) {
  243. dev_err(&pdev->dev,
  244. "failed enable PCI device %s!\n",
  245. pci_name(pdev));
  246. return err;
  247. }
  248. for (bar_num = 0; bar_num < SCI_PCI_BAR_COUNT; bar_num++)
  249. bar_mask |= 1 << (bar_num * 2);
  250. err = pcim_iomap_regions(pdev, bar_mask, DRV_NAME);
  251. if (err)
  252. return err;
  253. iomap = pcim_iomap_table(pdev);
  254. if (!iomap)
  255. return -ENOMEM;
  256. pci_set_master(pdev);
  257. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
  258. if (err)
  259. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  260. return err;
  261. }
  262. static int num_controllers(struct pci_dev *pdev)
  263. {
  264. /* bar size alone can tell us if we are running with a dual controller
  265. * part, no need to trust revision ids that might be under broken firmware
  266. * control
  267. */
  268. resource_size_t scu_bar_size = pci_resource_len(pdev, SCI_SCU_BAR*2);
  269. resource_size_t smu_bar_size = pci_resource_len(pdev, SCI_SMU_BAR*2);
  270. if (scu_bar_size >= SCI_SCU_BAR_SIZE*SCI_MAX_CONTROLLERS &&
  271. smu_bar_size >= SCI_SMU_BAR_SIZE*SCI_MAX_CONTROLLERS)
  272. return SCI_MAX_CONTROLLERS;
  273. else
  274. return 1;
  275. }
  276. static int isci_setup_interrupts(struct pci_dev *pdev)
  277. {
  278. int err, i, num_msix;
  279. struct isci_host *ihost;
  280. struct isci_pci_info *pci_info = to_pci_info(pdev);
  281. /*
  282. * Determine the number of vectors associated with this
  283. * PCI function.
  284. */
  285. num_msix = num_controllers(pdev) * SCI_NUM_MSI_X_INT;
  286. err = pci_alloc_irq_vectors(pdev, num_msix, num_msix, PCI_IRQ_MSIX);
  287. if (err < 0)
  288. goto intx;
  289. for (i = 0; i < num_msix; i++) {
  290. int id = i / SCI_NUM_MSI_X_INT;
  291. irq_handler_t isr;
  292. ihost = pci_info->hosts[id];
  293. /* odd numbered vectors are error interrupts */
  294. if (i & 1)
  295. isr = isci_error_isr;
  296. else
  297. isr = isci_msix_isr;
  298. err = devm_request_irq(&pdev->dev, pci_irq_vector(pdev, i),
  299. isr, 0, DRV_NAME"-msix", ihost);
  300. if (!err)
  301. continue;
  302. dev_info(&pdev->dev, "msix setup failed falling back to intx\n");
  303. while (i--) {
  304. id = i / SCI_NUM_MSI_X_INT;
  305. ihost = pci_info->hosts[id];
  306. devm_free_irq(&pdev->dev, pci_irq_vector(pdev, i),
  307. ihost);
  308. }
  309. pci_free_irq_vectors(pdev);
  310. goto intx;
  311. }
  312. return 0;
  313. intx:
  314. for_each_isci_host(i, ihost, pdev) {
  315. err = devm_request_irq(&pdev->dev, pci_irq_vector(pdev, 0),
  316. isci_intx_isr, IRQF_SHARED, DRV_NAME"-intx",
  317. ihost);
  318. if (err)
  319. break;
  320. }
  321. return err;
  322. }
  323. static void isci_user_parameters_get(struct sci_user_parameters *u)
  324. {
  325. int i;
  326. for (i = 0; i < SCI_MAX_PHYS; i++) {
  327. struct sci_phy_user_params *u_phy = &u->phys[i];
  328. u_phy->max_speed_generation = phy_gen;
  329. /* we are not exporting these for now */
  330. u_phy->align_insertion_frequency = 0x7f;
  331. u_phy->in_connection_align_insertion_frequency = 0xff;
  332. u_phy->notify_enable_spin_up_insertion_frequency = 0x33;
  333. }
  334. u->stp_inactivity_timeout = stp_inactive_to;
  335. u->ssp_inactivity_timeout = ssp_inactive_to;
  336. u->stp_max_occupancy_timeout = stp_max_occ_to;
  337. u->ssp_max_occupancy_timeout = ssp_max_occ_to;
  338. u->no_outbound_task_timeout = no_outbound_task_to;
  339. u->max_concurr_spinup = max_concurr_spinup;
  340. }
  341. static enum sci_status sci_user_parameters_set(struct isci_host *ihost,
  342. struct sci_user_parameters *sci_parms)
  343. {
  344. u16 index;
  345. /*
  346. * Validate the user parameters. If they are not legal, then
  347. * return a failure.
  348. */
  349. for (index = 0; index < SCI_MAX_PHYS; index++) {
  350. struct sci_phy_user_params *u;
  351. u = &sci_parms->phys[index];
  352. if (!((u->max_speed_generation <= SCIC_SDS_PARM_MAX_SPEED) &&
  353. (u->max_speed_generation > SCIC_SDS_PARM_NO_SPEED)))
  354. return SCI_FAILURE_INVALID_PARAMETER_VALUE;
  355. if ((u->in_connection_align_insertion_frequency < 3) ||
  356. (u->align_insertion_frequency == 0) ||
  357. (u->notify_enable_spin_up_insertion_frequency == 0))
  358. return SCI_FAILURE_INVALID_PARAMETER_VALUE;
  359. }
  360. if ((sci_parms->stp_inactivity_timeout == 0) ||
  361. (sci_parms->ssp_inactivity_timeout == 0) ||
  362. (sci_parms->stp_max_occupancy_timeout == 0) ||
  363. (sci_parms->ssp_max_occupancy_timeout == 0) ||
  364. (sci_parms->no_outbound_task_timeout == 0))
  365. return SCI_FAILURE_INVALID_PARAMETER_VALUE;
  366. memcpy(&ihost->user_parameters, sci_parms, sizeof(*sci_parms));
  367. return SCI_SUCCESS;
  368. }
  369. static void sci_oem_defaults(struct isci_host *ihost)
  370. {
  371. /* these defaults are overridden by the platform / firmware */
  372. struct sci_user_parameters *user = &ihost->user_parameters;
  373. struct sci_oem_params *oem = &ihost->oem_parameters;
  374. int i;
  375. /* Default to APC mode. */
  376. oem->controller.mode_type = SCIC_PORT_AUTOMATIC_CONFIGURATION_MODE;
  377. /* Default to APC mode. */
  378. oem->controller.max_concurr_spin_up = 1;
  379. /* Default to no SSC operation. */
  380. oem->controller.do_enable_ssc = false;
  381. /* Default to short cables on all phys. */
  382. oem->controller.cable_selection_mask = 0;
  383. /* Initialize all of the port parameter information to narrow ports. */
  384. for (i = 0; i < SCI_MAX_PORTS; i++)
  385. oem->ports[i].phy_mask = 0;
  386. /* Initialize all of the phy parameter information. */
  387. for (i = 0; i < SCI_MAX_PHYS; i++) {
  388. /* Default to 3G (i.e. Gen 2). */
  389. user->phys[i].max_speed_generation = SCIC_SDS_PARM_GEN2_SPEED;
  390. /* the frequencies cannot be 0 */
  391. user->phys[i].align_insertion_frequency = 0x7f;
  392. user->phys[i].in_connection_align_insertion_frequency = 0xff;
  393. user->phys[i].notify_enable_spin_up_insertion_frequency = 0x33;
  394. /* Previous Vitesse based expanders had a arbitration issue that
  395. * is worked around by having the upper 32-bits of SAS address
  396. * with a value greater then the Vitesse company identifier.
  397. * Hence, usage of 0x5FCFFFFF.
  398. */
  399. oem->phys[i].sas_address.low = 0x1 + ihost->id;
  400. oem->phys[i].sas_address.high = 0x5FCFFFFF;
  401. }
  402. user->stp_inactivity_timeout = 5;
  403. user->ssp_inactivity_timeout = 5;
  404. user->stp_max_occupancy_timeout = 5;
  405. user->ssp_max_occupancy_timeout = 20;
  406. user->no_outbound_task_timeout = 2;
  407. }
  408. static struct isci_host *isci_host_alloc(struct pci_dev *pdev, int id)
  409. {
  410. struct isci_orom *orom = to_pci_info(pdev)->orom;
  411. struct sci_user_parameters sci_user_params;
  412. u8 oem_version = ISCI_ROM_VER_1_0;
  413. struct isci_host *ihost;
  414. struct Scsi_Host *shost;
  415. int err, i;
  416. ihost = devm_kzalloc(&pdev->dev, sizeof(*ihost), GFP_KERNEL);
  417. if (!ihost)
  418. return NULL;
  419. ihost->pdev = pdev;
  420. ihost->id = id;
  421. spin_lock_init(&ihost->scic_lock);
  422. init_waitqueue_head(&ihost->eventq);
  423. ihost->sas_ha.dev = &ihost->pdev->dev;
  424. ihost->sas_ha.lldd_ha = ihost;
  425. tasklet_init(&ihost->completion_tasklet,
  426. isci_host_completion_routine, (unsigned long)ihost);
  427. /* validate module parameters */
  428. /* TODO: kill struct sci_user_parameters and reference directly */
  429. sci_oem_defaults(ihost);
  430. isci_user_parameters_get(&sci_user_params);
  431. if (sci_user_parameters_set(ihost, &sci_user_params)) {
  432. dev_warn(&pdev->dev,
  433. "%s: sci_user_parameters_set failed\n", __func__);
  434. return NULL;
  435. }
  436. /* sanity check platform (or 'firmware') oem parameters */
  437. if (orom) {
  438. if (id < 0 || id >= SCI_MAX_CONTROLLERS || id > orom->hdr.num_elements) {
  439. dev_warn(&pdev->dev, "parsing firmware oem parameters failed\n");
  440. return NULL;
  441. }
  442. ihost->oem_parameters = orom->ctrl[id];
  443. oem_version = orom->hdr.version;
  444. }
  445. /* validate oem parameters (platform, firmware, or built-in defaults) */
  446. if (sci_oem_parameters_validate(&ihost->oem_parameters, oem_version)) {
  447. dev_warn(&pdev->dev, "oem parameter validation failed\n");
  448. return NULL;
  449. }
  450. for (i = 0; i < SCI_MAX_PORTS; i++) {
  451. struct isci_port *iport = &ihost->ports[i];
  452. INIT_LIST_HEAD(&iport->remote_dev_list);
  453. iport->isci_host = ihost;
  454. }
  455. for (i = 0; i < SCI_MAX_PHYS; i++)
  456. isci_phy_init(&ihost->phys[i], ihost, i);
  457. for (i = 0; i < SCI_MAX_REMOTE_DEVICES; i++) {
  458. struct isci_remote_device *idev = &ihost->devices[i];
  459. INIT_LIST_HEAD(&idev->node);
  460. }
  461. shost = scsi_host_alloc(&isci_sht, sizeof(void *));
  462. if (!shost)
  463. return NULL;
  464. dev_info(&pdev->dev, "%sSCU controller %d: phy 3-0 cables: "
  465. "{%s, %s, %s, %s}\n",
  466. (is_cable_select_overridden() ? "* " : ""), ihost->id,
  467. lookup_cable_names(decode_cable_selection(ihost, 3)),
  468. lookup_cable_names(decode_cable_selection(ihost, 2)),
  469. lookup_cable_names(decode_cable_selection(ihost, 1)),
  470. lookup_cable_names(decode_cable_selection(ihost, 0)));
  471. err = isci_host_init(ihost);
  472. if (err)
  473. goto err_shost;
  474. SHOST_TO_SAS_HA(shost) = &ihost->sas_ha;
  475. ihost->sas_ha.core.shost = shost;
  476. shost->transportt = isci_transport_template;
  477. shost->max_id = ~0;
  478. shost->max_lun = ~0;
  479. shost->max_cmd_len = MAX_COMMAND_SIZE;
  480. /* turn on DIF support */
  481. scsi_host_set_prot(shost,
  482. SHOST_DIF_TYPE1_PROTECTION |
  483. SHOST_DIF_TYPE2_PROTECTION |
  484. SHOST_DIF_TYPE3_PROTECTION);
  485. scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
  486. err = scsi_add_host(shost, &pdev->dev);
  487. if (err)
  488. goto err_shost;
  489. err = isci_register_sas_ha(ihost);
  490. if (err)
  491. goto err_shost_remove;
  492. return ihost;
  493. err_shost_remove:
  494. scsi_remove_host(shost);
  495. err_shost:
  496. scsi_host_put(shost);
  497. return NULL;
  498. }
  499. static int isci_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  500. {
  501. struct isci_pci_info *pci_info;
  502. int err, i;
  503. struct isci_host *isci_host;
  504. const struct firmware *fw = NULL;
  505. struct isci_orom *orom = NULL;
  506. char *source = "(platform)";
  507. dev_info(&pdev->dev, "driver configured for rev: %d silicon\n",
  508. pdev->revision);
  509. pci_info = devm_kzalloc(&pdev->dev, sizeof(*pci_info), GFP_KERNEL);
  510. if (!pci_info)
  511. return -ENOMEM;
  512. pci_set_drvdata(pdev, pci_info);
  513. if (efi_rt_services_supported(EFI_RT_SUPPORTED_GET_VARIABLE))
  514. orom = isci_get_efi_var(pdev);
  515. if (!orom)
  516. orom = isci_request_oprom(pdev);
  517. for (i = 0; orom && i < num_controllers(pdev); i++) {
  518. if (sci_oem_parameters_validate(&orom->ctrl[i],
  519. orom->hdr.version)) {
  520. dev_warn(&pdev->dev,
  521. "[%d]: invalid oem parameters detected, falling back to firmware\n", i);
  522. orom = NULL;
  523. break;
  524. }
  525. }
  526. if (!orom) {
  527. source = "(firmware)";
  528. orom = isci_request_firmware(pdev, fw);
  529. if (!orom) {
  530. /* TODO convert this to WARN_TAINT_ONCE once the
  531. * orom/efi parameter support is widely available
  532. */
  533. dev_warn(&pdev->dev,
  534. "Loading user firmware failed, using default "
  535. "values\n");
  536. dev_warn(&pdev->dev,
  537. "Default OEM configuration being used: 4 "
  538. "narrow ports, and default SAS Addresses\n");
  539. }
  540. }
  541. if (orom)
  542. dev_info(&pdev->dev,
  543. "OEM SAS parameters (version: %u.%u) loaded %s\n",
  544. (orom->hdr.version & 0xf0) >> 4,
  545. (orom->hdr.version & 0xf), source);
  546. pci_info->orom = orom;
  547. err = isci_pci_init(pdev);
  548. if (err)
  549. return err;
  550. for (i = 0; i < num_controllers(pdev); i++) {
  551. struct isci_host *h = isci_host_alloc(pdev, i);
  552. if (!h) {
  553. err = -ENOMEM;
  554. goto err_host_alloc;
  555. }
  556. pci_info->hosts[i] = h;
  557. }
  558. err = isci_setup_interrupts(pdev);
  559. if (err)
  560. goto err_host_alloc;
  561. for_each_isci_host(i, isci_host, pdev)
  562. scsi_scan_host(to_shost(isci_host));
  563. return 0;
  564. err_host_alloc:
  565. for_each_isci_host(i, isci_host, pdev)
  566. isci_unregister(isci_host);
  567. return err;
  568. }
  569. static void isci_pci_remove(struct pci_dev *pdev)
  570. {
  571. struct isci_host *ihost;
  572. int i;
  573. for_each_isci_host(i, ihost, pdev) {
  574. wait_for_start(ihost);
  575. isci_unregister(ihost);
  576. isci_host_deinit(ihost);
  577. }
  578. }
  579. #ifdef CONFIG_PM_SLEEP
  580. static int isci_suspend(struct device *dev)
  581. {
  582. struct pci_dev *pdev = to_pci_dev(dev);
  583. struct isci_host *ihost;
  584. int i;
  585. for_each_isci_host(i, ihost, pdev) {
  586. sas_suspend_ha(&ihost->sas_ha);
  587. isci_host_deinit(ihost);
  588. }
  589. return 0;
  590. }
  591. static int isci_resume(struct device *dev)
  592. {
  593. struct pci_dev *pdev = to_pci_dev(dev);
  594. struct isci_host *ihost;
  595. int i;
  596. for_each_isci_host(i, ihost, pdev) {
  597. sas_prep_resume_ha(&ihost->sas_ha);
  598. isci_host_init(ihost);
  599. isci_host_start(ihost->sas_ha.core.shost);
  600. wait_for_start(ihost);
  601. sas_resume_ha(&ihost->sas_ha);
  602. }
  603. return 0;
  604. }
  605. #endif
  606. static SIMPLE_DEV_PM_OPS(isci_pm_ops, isci_suspend, isci_resume);
  607. static struct pci_driver isci_pci_driver = {
  608. .name = DRV_NAME,
  609. .id_table = isci_id_table,
  610. .probe = isci_pci_probe,
  611. .remove = isci_pci_remove,
  612. .driver.pm = &isci_pm_ops,
  613. };
  614. static __init int isci_init(void)
  615. {
  616. int err;
  617. pr_info("%s: Intel(R) C600 SAS Controller Driver - version %s\n",
  618. DRV_NAME, DRV_VERSION);
  619. isci_transport_template = sas_domain_attach_transport(&isci_transport_ops);
  620. if (!isci_transport_template)
  621. return -ENOMEM;
  622. err = pci_register_driver(&isci_pci_driver);
  623. if (err)
  624. sas_release_transport(isci_transport_template);
  625. return err;
  626. }
  627. static __exit void isci_exit(void)
  628. {
  629. pci_unregister_driver(&isci_pci_driver);
  630. sas_release_transport(isci_transport_template);
  631. }
  632. MODULE_LICENSE("Dual BSD/GPL");
  633. MODULE_FIRMWARE(ISCI_FW_NAME);
  634. module_init(isci_init);
  635. module_exit(isci_exit);