init.c 18 KB

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