init.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  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 <asm/string.h>
  59. #include "isci.h"
  60. #include "task.h"
  61. #include "sci_controller_constants.h"
  62. #include "scic_remote_device.h"
  63. #include "sci_environment.h"
  64. static struct scsi_transport_template *isci_transport_template;
  65. static DEFINE_PCI_DEVICE_TABLE(isci_id_table) = {
  66. { PCI_VDEVICE(INTEL, 0x1D61),},
  67. { PCI_VDEVICE(INTEL, 0x1D63),},
  68. { PCI_VDEVICE(INTEL, 0x1D65),},
  69. { PCI_VDEVICE(INTEL, 0x1D67),},
  70. { PCI_VDEVICE(INTEL, 0x1D69),},
  71. { PCI_VDEVICE(INTEL, 0x1D6B),},
  72. { PCI_VDEVICE(INTEL, 0x1D60),},
  73. { PCI_VDEVICE(INTEL, 0x1D62),},
  74. { PCI_VDEVICE(INTEL, 0x1D64),},
  75. { PCI_VDEVICE(INTEL, 0x1D66),},
  76. { PCI_VDEVICE(INTEL, 0x1D68),},
  77. { PCI_VDEVICE(INTEL, 0x1D6A),},
  78. {}
  79. };
  80. struct isci_firmware *isci_firmware;
  81. static int __devinit isci_pci_probe(
  82. struct pci_dev *pdev,
  83. const struct pci_device_id *device_id_p);
  84. static void __devexit isci_pci_remove(struct pci_dev *pdev);
  85. MODULE_DEVICE_TABLE(pci, isci_id_table);
  86. static struct pci_driver isci_pci_driver = {
  87. .name = DRV_NAME,
  88. .id_table = isci_id_table,
  89. .probe = isci_pci_probe,
  90. .remove = __devexit_p(isci_pci_remove),
  91. };
  92. /* linux isci specific settings */
  93. #if defined(CONFIG_PBG_HBA_A0)
  94. int isci_si_rev = ISCI_SI_REVA0;
  95. #elif defined(CONFIG_PBG_HBA_A2)
  96. int isci_si_rev = ISCI_SI_REVA2;
  97. #else
  98. int isci_si_rev = ISCI_SI_REVB0;
  99. #endif
  100. module_param(isci_si_rev, int, S_IRUGO | S_IWUSR);
  101. MODULE_PARM_DESC(isci_si_rev, "override default si rev (0: A0 1: A2 2: B0)");
  102. static struct scsi_host_template isci_sht = {
  103. .module = THIS_MODULE,
  104. .name = DRV_NAME,
  105. .proc_name = DRV_NAME,
  106. .queuecommand = sas_queuecommand,
  107. .target_alloc = sas_target_alloc,
  108. .slave_configure = sas_slave_configure,
  109. .slave_destroy = sas_slave_destroy,
  110. .scan_finished = isci_host_scan_finished,
  111. .scan_start = isci_host_scan_start,
  112. .change_queue_depth = sas_change_queue_depth,
  113. .change_queue_type = sas_change_queue_type,
  114. .bios_param = sas_bios_param,
  115. .can_queue = ISCI_CAN_QUEUE_VAL,
  116. .cmd_per_lun = 1,
  117. .this_id = -1,
  118. .sg_tablesize = SG_ALL,
  119. .max_sectors = SCSI_DEFAULT_MAX_SECTORS,
  120. .use_clustering = ENABLE_CLUSTERING,
  121. .eh_device_reset_handler = sas_eh_device_reset_handler,
  122. .eh_bus_reset_handler = isci_bus_reset_handler,
  123. .slave_alloc = sas_slave_alloc,
  124. .target_destroy = sas_target_destroy,
  125. .ioctl = sas_ioctl,
  126. };
  127. static struct sas_domain_function_template isci_transport_ops = {
  128. /* The class calls these to notify the LLDD of an event. */
  129. .lldd_port_formed = isci_port_formed,
  130. .lldd_port_deformed = isci_port_deformed,
  131. /* The class calls these when a device is found or gone. */
  132. .lldd_dev_found = isci_remote_device_found,
  133. .lldd_dev_gone = isci_remote_device_gone,
  134. .lldd_execute_task = isci_task_execute_task,
  135. /* Task Management Functions. Must be called from process context. */
  136. .lldd_abort_task = isci_task_abort_task,
  137. .lldd_abort_task_set = isci_task_abort_task_set,
  138. .lldd_clear_aca = isci_task_clear_aca,
  139. .lldd_clear_task_set = isci_task_clear_task_set,
  140. .lldd_I_T_nexus_reset = isci_task_I_T_nexus_reset,
  141. .lldd_lu_reset = isci_task_lu_reset,
  142. .lldd_query_task = isci_task_query_task,
  143. /* Port and Adapter management */
  144. .lldd_clear_nexus_port = isci_task_clear_nexus_port,
  145. .lldd_clear_nexus_ha = isci_task_clear_nexus_ha,
  146. /* Phy management */
  147. .lldd_control_phy = isci_phy_control,
  148. };
  149. /******************************************************************************
  150. * P R O T E C T E D M E T H O D S
  151. ******************************************************************************/
  152. /**
  153. * isci_register_sas_ha() - This method initializes various lldd
  154. * specific members of the sas_ha struct and calls the libsas
  155. * sas_register_ha() function.
  156. * @isci_host: This parameter specifies the lldd specific wrapper for the
  157. * libsas sas_ha struct.
  158. *
  159. * This method returns an error code indicating sucess or failure. The user
  160. * should check for possible memory allocation error return otherwise, a zero
  161. * indicates success.
  162. */
  163. static int isci_register_sas_ha(struct isci_host *isci_host)
  164. {
  165. int i;
  166. struct sas_ha_struct *sas_ha = &(isci_host->sas_ha);
  167. struct asd_sas_phy **sas_phys;
  168. struct asd_sas_port **sas_ports;
  169. sas_phys = devm_kzalloc(&isci_host->pdev->dev,
  170. SCI_MAX_PHYS * sizeof(void *),
  171. GFP_KERNEL);
  172. if (!sas_phys)
  173. return -ENOMEM;
  174. sas_ports = devm_kzalloc(&isci_host->pdev->dev,
  175. SCI_MAX_PORTS * sizeof(void *),
  176. GFP_KERNEL);
  177. if (!sas_ports)
  178. return -ENOMEM;
  179. /*----------------- Libsas Initialization Stuff----------------------
  180. * Set various fields in the sas_ha struct:
  181. */
  182. sas_ha->sas_ha_name = DRV_NAME;
  183. sas_ha->lldd_module = THIS_MODULE;
  184. sas_ha->sas_addr = &isci_host->phys[0].sas_addr[0];
  185. /* set the array of phy and port structs. */
  186. for (i = 0; i < SCI_MAX_PHYS; i++) {
  187. sas_phys[i] = &(isci_host->phys[i].sas_phy);
  188. sas_ports[i] = &(isci_host->sas_ports[i]);
  189. }
  190. sas_ha->sas_phy = sas_phys;
  191. sas_ha->sas_port = sas_ports;
  192. sas_ha->num_phys = SCI_MAX_PHYS;
  193. sas_ha->lldd_queue_size = ISCI_CAN_QUEUE_VAL;
  194. sas_ha->lldd_max_execute_num = 1;
  195. sas_ha->strict_wide_ports = 1;
  196. sas_register_ha(sas_ha);
  197. return 0;
  198. }
  199. static ssize_t isci_show_id(struct device *dev, struct device_attribute *attr, char *buf)
  200. {
  201. struct Scsi_Host *shost = container_of(dev, typeof(*shost), shost_dev);
  202. struct sas_ha_struct *sas_ha = SHOST_TO_SAS_HA(shost);
  203. struct isci_host *ihost = container_of(sas_ha, typeof(*ihost), sas_ha);
  204. return snprintf(buf, PAGE_SIZE, "%d\n", ihost->id);
  205. }
  206. static DEVICE_ATTR(isci_id, S_IRUGO, isci_show_id, NULL);
  207. static void isci_unregister(struct isci_host *isci_host)
  208. {
  209. struct Scsi_Host *shost;
  210. if (!isci_host)
  211. return;
  212. shost = isci_host->shost;
  213. device_remove_file(&shost->shost_dev, &dev_attr_isci_id);
  214. sas_unregister_ha(&isci_host->sas_ha);
  215. sas_remove_host(isci_host->shost);
  216. scsi_remove_host(isci_host->shost);
  217. scsi_host_put(isci_host->shost);
  218. }
  219. static int __devinit isci_pci_init(struct pci_dev *pdev)
  220. {
  221. int err, bar_num, bar_mask;
  222. void __iomem * const *iomap;
  223. err = pcim_enable_device(pdev);
  224. if (err) {
  225. dev_err(&pdev->dev,
  226. "failed enable PCI device %s!\n",
  227. pci_name(pdev));
  228. return err;
  229. }
  230. for (bar_num = 0; bar_num < SCI_PCI_BAR_COUNT; bar_num++)
  231. bar_mask |= 1 << (bar_num * 2);
  232. err = pcim_iomap_regions(pdev, bar_mask, DRV_NAME);
  233. if (err)
  234. return err;
  235. iomap = pcim_iomap_table(pdev);
  236. if (!iomap)
  237. return -ENOMEM;
  238. pci_set_master(pdev);
  239. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
  240. if (err) {
  241. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  242. if (err)
  243. return err;
  244. }
  245. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
  246. if (err) {
  247. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  248. if (err)
  249. return err;
  250. }
  251. return 0;
  252. }
  253. static int num_controllers(struct pci_dev *pdev)
  254. {
  255. /* bar size alone can tell us if we are running with a dual controller
  256. * part, no need to trust revision ids that might be under broken firmware
  257. * control
  258. */
  259. resource_size_t scu_bar_size = pci_resource_len(pdev, SCI_SCU_BAR*2);
  260. resource_size_t smu_bar_size = pci_resource_len(pdev, SCI_SMU_BAR*2);
  261. if (scu_bar_size >= SCI_SCU_BAR_SIZE*SCI_MAX_CONTROLLERS &&
  262. smu_bar_size >= SCI_SMU_BAR_SIZE*SCI_MAX_CONTROLLERS)
  263. return SCI_MAX_CONTROLLERS;
  264. else
  265. return 1;
  266. }
  267. static int isci_setup_interrupts(struct pci_dev *pdev)
  268. {
  269. int err, i, num_msix;
  270. struct isci_pci_info *pci_info = to_pci_info(pdev);
  271. /*
  272. * Determine the number of vectors associated with this
  273. * PCI function.
  274. */
  275. num_msix = num_controllers(pdev) * SCI_NUM_MSI_X_INT;
  276. for (i = 0; i < num_msix; i++)
  277. pci_info->msix_entries[i].entry = i;
  278. err = pci_enable_msix(pdev, pci_info->msix_entries, num_msix);
  279. if (err)
  280. goto intx;
  281. for (i = 0; i < num_msix; i++) {
  282. int id = i / SCI_NUM_MSI_X_INT;
  283. struct msix_entry *msix = &pci_info->msix_entries[i];
  284. struct isci_host *isci_host = pci_info->hosts[id];
  285. irq_handler_t isr;
  286. /* odd numbered vectors are error interrupts */
  287. if (i & 1)
  288. isr = isci_error_isr;
  289. else
  290. isr = isci_msix_isr;
  291. BUG_ON(!isci_host);
  292. err = devm_request_irq(&pdev->dev, msix->vector, isr, 0,
  293. DRV_NAME"-msix", isci_host);
  294. if (!err)
  295. continue;
  296. dev_info(&pdev->dev, "msix setup failed falling back to intx\n");
  297. while (i--) {
  298. id = i / SCI_NUM_MSI_X_INT;
  299. isci_host = pci_info->hosts[id];
  300. msix = &pci_info->msix_entries[i];
  301. devm_free_irq(&pdev->dev, msix->vector, isci_host);
  302. }
  303. pci_disable_msix(pdev);
  304. goto intx;
  305. }
  306. return 0;
  307. intx:
  308. err = devm_request_irq(&pdev->dev, pdev->irq, isci_intx_isr,
  309. IRQF_SHARED, DRV_NAME"-intx", pdev);
  310. return err;
  311. }
  312. /**
  313. * isci_parse_oem_parameters() - This method will take OEM parameters
  314. * from the module init parameters and copy them to oem_params. This will
  315. * only copy values that are not set to the module parameter default values
  316. * @oem_parameters: This parameter specifies the controller default OEM
  317. * parameters. It is expected that this has been initialized to the default
  318. * parameters for the controller
  319. *
  320. *
  321. */
  322. enum sci_status isci_parse_oem_parameters(union scic_oem_parameters *oem_params,
  323. int scu_index,
  324. struct isci_firmware *fw)
  325. {
  326. int i;
  327. /* check for valid inputs */
  328. if (!(scu_index >= 0
  329. && scu_index < SCI_MAX_CONTROLLERS
  330. && oem_params != NULL)) {
  331. return SCI_FAILURE;
  332. }
  333. for (i = 0; i < SCI_MAX_PHYS; i++) {
  334. int array_idx = i + (SCI_MAX_PHYS * scu_index);
  335. u64 sas_addr = fw->sas_addrs[array_idx];
  336. if (sas_addr != 0) {
  337. oem_params->sds1.phys[i].sas_address.low =
  338. (u32)(sas_addr & 0xffffffff);
  339. oem_params->sds1.phys[i].sas_address.high =
  340. (u32)((sas_addr >> 32) & 0xffffffff);
  341. }
  342. }
  343. for (i = 0; i < SCI_MAX_PORTS; i++) {
  344. int array_idx = i + (SCI_MAX_PORTS * scu_index);
  345. u32 pmask = fw->phy_masks[array_idx];
  346. oem_params->sds1.ports[i].phy_mask = pmask;
  347. }
  348. return SCI_SUCCESS;
  349. }
  350. /**
  351. * isci_parse_user_parameters() - This method will take user parameters
  352. * from the module init parameters and copy them to user_params. This will
  353. * only copy values that are not set to the module parameter default values
  354. * @user_parameters: This parameter specifies the controller default user
  355. * parameters. It is expected that this has been initialized to the default
  356. * parameters for the controller
  357. *
  358. *
  359. */
  360. enum sci_status isci_parse_user_parameters(
  361. union scic_user_parameters *user_params,
  362. int scu_index,
  363. struct isci_firmware *fw)
  364. {
  365. int i;
  366. if (!(scu_index >= 0
  367. && scu_index < SCI_MAX_CONTROLLERS
  368. && user_params != NULL)) {
  369. return SCI_FAILURE;
  370. }
  371. for (i = 0; i < SCI_MAX_PORTS; i++) {
  372. int array_idx = i + (SCI_MAX_PORTS * scu_index);
  373. u32 gen = fw->phy_gens[array_idx];
  374. user_params->sds1.phys[i].max_speed_generation = gen;
  375. }
  376. return SCI_SUCCESS;
  377. }
  378. static struct isci_host *isci_host_alloc(struct pci_dev *pdev, int id)
  379. {
  380. struct isci_host *isci_host;
  381. struct Scsi_Host *shost;
  382. int err;
  383. isci_host = devm_kzalloc(&pdev->dev, sizeof(*isci_host) +
  384. SCI_MAX_REMOTE_DEVICES *
  385. (sizeof(struct isci_remote_device) +
  386. scic_remote_device_get_object_size()), GFP_KERNEL);
  387. if (!isci_host)
  388. return NULL;
  389. isci_host->pdev = pdev;
  390. isci_host->id = id;
  391. shost = scsi_host_alloc(&isci_sht, sizeof(void *));
  392. if (!shost)
  393. return NULL;
  394. isci_host->shost = shost;
  395. err = isci_host_init(isci_host);
  396. if (err)
  397. goto err_shost;
  398. SHOST_TO_SAS_HA(shost) = &isci_host->sas_ha;
  399. isci_host->sas_ha.core.shost = shost;
  400. shost->transportt = isci_transport_template;
  401. shost->max_id = ~0;
  402. shost->max_lun = ~0;
  403. shost->max_cmd_len = MAX_COMMAND_SIZE;
  404. err = scsi_add_host(shost, &pdev->dev);
  405. if (err)
  406. goto err_shost;
  407. err = isci_register_sas_ha(isci_host);
  408. if (err)
  409. goto err_shost_remove;
  410. err = device_create_file(&shost->shost_dev, &dev_attr_isci_id);
  411. if (err)
  412. goto err_unregister_ha;
  413. return isci_host;
  414. err_unregister_ha:
  415. sas_unregister_ha(&(isci_host->sas_ha));
  416. err_shost_remove:
  417. scsi_remove_host(shost);
  418. err_shost:
  419. scsi_host_put(shost);
  420. return NULL;
  421. }
  422. static void check_si_rev(struct pci_dev *pdev)
  423. {
  424. if (num_controllers(pdev) > 1)
  425. isci_si_rev = ISCI_SI_REVB0;
  426. else {
  427. switch (pdev->revision) {
  428. case 0:
  429. case 1:
  430. /* if the id is ambiguous don't update isci_si_rev */
  431. break;
  432. case 3:
  433. isci_si_rev = ISCI_SI_REVA2;
  434. break;
  435. default:
  436. case 4:
  437. isci_si_rev = ISCI_SI_REVB0;
  438. break;
  439. }
  440. }
  441. dev_info(&pdev->dev, "driver configured for %s silicon (rev: %d)\n",
  442. isci_si_rev == ISCI_SI_REVA0 ? "A0" :
  443. isci_si_rev == ISCI_SI_REVA2 ? "A2" : "B0", pdev->revision);
  444. }
  445. static int isci_verify_firmware(const struct firmware *fw,
  446. struct isci_firmware *isci_fw)
  447. {
  448. const u8 *tmp;
  449. if (fw->size < ISCI_FIRMWARE_MIN_SIZE)
  450. return -EINVAL;
  451. tmp = fw->data;
  452. /* 12th char should be the NULL terminate for the ID string */
  453. if (tmp[11] != '\0')
  454. return -EINVAL;
  455. if (strncmp("#SCU MAGIC#", tmp, 11) != 0)
  456. return -EINVAL;
  457. isci_fw->id = tmp;
  458. isci_fw->version = fw->data[ISCI_FW_VER_OFS];
  459. isci_fw->subversion = fw->data[ISCI_FW_SUBVER_OFS];
  460. tmp = fw->data + ISCI_FW_DATA_OFS;
  461. while (*tmp != ISCI_FW_HDR_EOF) {
  462. switch (*tmp) {
  463. case ISCI_FW_HDR_PHYMASK:
  464. tmp++;
  465. isci_fw->phy_masks_size = *tmp;
  466. tmp++;
  467. isci_fw->phy_masks = (const u32 *)tmp;
  468. tmp += sizeof(u32) * isci_fw->phy_masks_size;
  469. break;
  470. case ISCI_FW_HDR_PHYGEN:
  471. tmp++;
  472. isci_fw->phy_gens_size = *tmp;
  473. tmp++;
  474. isci_fw->phy_gens = (const u32 *)tmp;
  475. tmp += sizeof(u32) * isci_fw->phy_gens_size;
  476. break;
  477. case ISCI_FW_HDR_SASADDR:
  478. tmp++;
  479. isci_fw->sas_addrs_size = *tmp;
  480. tmp++;
  481. isci_fw->sas_addrs = (const u64 *)tmp;
  482. tmp += sizeof(u64) * isci_fw->sas_addrs_size;
  483. break;
  484. default:
  485. pr_err("bad field in firmware binary blob\n");
  486. return -EINVAL;
  487. }
  488. }
  489. pr_info("isci firmware v%u.%u loaded.\n",
  490. isci_fw->version, isci_fw->subversion);
  491. return SCI_SUCCESS;
  492. }
  493. static int __devinit isci_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  494. {
  495. struct isci_pci_info *pci_info;
  496. int err, i;
  497. struct isci_host *isci_host;
  498. const struct firmware *fw = NULL;
  499. check_si_rev(pdev);
  500. pci_info = devm_kzalloc(&pdev->dev, sizeof(*pci_info), GFP_KERNEL);
  501. if (!pci_info)
  502. return -ENOMEM;
  503. pci_set_drvdata(pdev, pci_info);
  504. err = request_firmware(&fw, ISCI_FW_NAME, &pdev->dev);
  505. if (err) {
  506. dev_warn(&pdev->dev,
  507. "Loading firmware failed, using default values\n");
  508. dev_warn(&pdev->dev,
  509. "Default OEM configuration being used:"
  510. " 4 narrow ports, and default SAS Addresses\n");
  511. } else {
  512. isci_firmware = devm_kzalloc(&pdev->dev,
  513. sizeof(struct isci_firmware),
  514. GFP_KERNEL);
  515. if (isci_firmware) {
  516. err = isci_verify_firmware(fw, isci_firmware);
  517. if (err != SCI_SUCCESS) {
  518. dev_warn(&pdev->dev,
  519. "firmware verification failed\n");
  520. dev_warn(&pdev->dev,
  521. "Default OEM configuration being used:"
  522. " 4 narrow ports, and default SAS "
  523. "Addresses\n");
  524. devm_kfree(&pdev->dev, isci_firmware);
  525. isci_firmware = NULL;
  526. }
  527. }
  528. release_firmware(fw);
  529. }
  530. err = isci_pci_init(pdev);
  531. if (err)
  532. return err;
  533. for (i = 0; i < num_controllers(pdev); i++) {
  534. struct isci_host *h = isci_host_alloc(pdev, i);
  535. if (!h) {
  536. err = -ENOMEM;
  537. goto err_host_alloc;
  538. }
  539. pci_info->hosts[i] = h;
  540. }
  541. err = isci_setup_interrupts(pdev);
  542. if (err)
  543. goto err_host_alloc;
  544. for_each_isci_host(i, isci_host, pdev)
  545. scsi_scan_host(isci_host->shost);
  546. return 0;
  547. err_host_alloc:
  548. for_each_isci_host(i, isci_host, pdev)
  549. isci_unregister(isci_host);
  550. return err;
  551. }
  552. static void __devexit isci_pci_remove(struct pci_dev *pdev)
  553. {
  554. struct isci_host *isci_host;
  555. int i;
  556. for_each_isci_host(i, isci_host, pdev) {
  557. isci_unregister(isci_host);
  558. isci_host_deinit(isci_host);
  559. scic_controller_disable_interrupts(isci_host->core_controller);
  560. }
  561. }
  562. static __init int isci_init(void)
  563. {
  564. int err;
  565. pr_info("%s: Intel(R) C600 SAS Controller Driver\n", DRV_NAME);
  566. isci_transport_template = sas_domain_attach_transport(&isci_transport_ops);
  567. if (!isci_transport_template)
  568. return -ENOMEM;
  569. err = pci_register_driver(&isci_pci_driver);
  570. if (err)
  571. sas_release_transport(isci_transport_template);
  572. return err;
  573. }
  574. static __exit void isci_exit(void)
  575. {
  576. pci_unregister_driver(&isci_pci_driver);
  577. sas_release_transport(isci_transport_template);
  578. }
  579. MODULE_LICENSE("Dual BSD/GPL");
  580. MODULE_FIRMWARE(ISCI_FW_NAME);
  581. module_init(isci_init);
  582. module_exit(isci_exit);