init.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  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 int num_controllers(struct pci_dev *pdev)
  244. {
  245. /* bar size alone can tell us if we are running with a dual controller
  246. * part, no need to trust revision ids that might be under broken firmware
  247. * control
  248. */
  249. resource_size_t scu_bar_size = pci_resource_len(pdev, SCI_SCU_BAR*2);
  250. resource_size_t smu_bar_size = pci_resource_len(pdev, SCI_SMU_BAR*2);
  251. if (scu_bar_size >= SCI_SCU_BAR_SIZE*SCI_MAX_CONTROLLERS &&
  252. smu_bar_size >= SCI_SMU_BAR_SIZE*SCI_MAX_CONTROLLERS)
  253. return SCI_MAX_CONTROLLERS;
  254. else
  255. return 1;
  256. }
  257. static int isci_setup_interrupts(struct pci_dev *pdev)
  258. {
  259. int err, i, num_msix;
  260. struct isci_pci_info *pci_info = to_pci_info(pdev);
  261. /*
  262. * Determine the number of vectors associated with this
  263. * PCI function.
  264. */
  265. num_msix = num_controllers(pdev) * SCI_NUM_MSI_X_INT;
  266. for (i = 0; i < num_msix; i++)
  267. pci_info->msix_entries[i].entry = i;
  268. err = pci_enable_msix(pdev, pci_info->msix_entries, num_msix);
  269. if (err)
  270. goto intx;
  271. for (i = 0; i < num_msix; i++) {
  272. int id = i / SCI_NUM_MSI_X_INT;
  273. struct msix_entry *msix = &pci_info->msix_entries[i];
  274. struct isci_host *isci_host = pci_info->hosts[id];
  275. irq_handler_t isr;
  276. /* odd numbered vectors are error interrupts */
  277. if (i & 1)
  278. isr = isci_error_isr;
  279. else
  280. isr = isci_msix_isr;
  281. BUG_ON(!isci_host);
  282. err = devm_request_irq(&pdev->dev, msix->vector, isr, 0,
  283. DRV_NAME"-msix", isci_host);
  284. if (!err)
  285. continue;
  286. dev_info(&pdev->dev, "msix setup failed falling back to intx\n");
  287. while (i--) {
  288. id = i / SCI_NUM_MSI_X_INT;
  289. isci_host = pci_info->hosts[id];
  290. msix = &pci_info->msix_entries[i];
  291. devm_free_irq(&pdev->dev, msix->vector, isci_host);
  292. }
  293. pci_disable_msix(pdev);
  294. goto intx;
  295. }
  296. return 0;
  297. intx:
  298. err = devm_request_irq(&pdev->dev, pdev->irq, isci_intx_isr,
  299. IRQF_SHARED, DRV_NAME"-intx", pdev);
  300. return err;
  301. }
  302. /**
  303. * isci_parse_oem_parameters() - This method will take OEM parameters
  304. * from the module init parameters and copy them to oem_params. This will
  305. * only copy values that are not set to the module parameter default values
  306. * @oem_parameters: This parameter specifies the controller default OEM
  307. * parameters. It is expected that this has been initialized to the default
  308. * parameters for the controller
  309. *
  310. *
  311. */
  312. enum sci_status isci_parse_oem_parameters(union scic_oem_parameters *oem_params,
  313. int scu_index,
  314. struct isci_firmware *fw)
  315. {
  316. int i;
  317. /* check for valid inputs */
  318. if (!(scu_index >= 0
  319. && scu_index < SCI_MAX_CONTROLLERS
  320. && oem_params != NULL)) {
  321. return SCI_FAILURE;
  322. }
  323. for (i = 0; i < SCI_MAX_PHYS; i++) {
  324. int array_idx = i + (SCI_MAX_PHYS * scu_index);
  325. u64 sas_addr = fw->sas_addrs[array_idx];
  326. if (sas_addr != 0) {
  327. oem_params->sds1.phys[i].sas_address.low =
  328. (u32)(sas_addr & 0xffffffff);
  329. oem_params->sds1.phys[i].sas_address.high =
  330. (u32)((sas_addr >> 32) & 0xffffffff);
  331. }
  332. }
  333. for (i = 0; i < SCI_MAX_PORTS; i++) {
  334. int array_idx = i + (SCI_MAX_PORTS * scu_index);
  335. u32 pmask = fw->phy_masks[array_idx];
  336. oem_params->sds1.ports[i].phy_mask = pmask;
  337. }
  338. return SCI_SUCCESS;
  339. }
  340. /**
  341. * isci_parse_user_parameters() - This method will take user parameters
  342. * from the module init parameters and copy them to user_params. This will
  343. * only copy values that are not set to the module parameter default values
  344. * @user_parameters: This parameter specifies the controller default user
  345. * parameters. It is expected that this has been initialized to the default
  346. * parameters for the controller
  347. *
  348. *
  349. */
  350. enum sci_status isci_parse_user_parameters(
  351. union scic_user_parameters *user_params,
  352. int scu_index,
  353. struct isci_firmware *fw)
  354. {
  355. int i;
  356. if (!(scu_index >= 0
  357. && scu_index < SCI_MAX_CONTROLLERS
  358. && user_params != NULL)) {
  359. return SCI_FAILURE;
  360. }
  361. for (i = 0; i < SCI_MAX_PORTS; i++) {
  362. int array_idx = i + (SCI_MAX_PORTS * scu_index);
  363. u32 gen = fw->phy_gens[array_idx];
  364. user_params->sds1.phys[i].max_speed_generation = gen;
  365. }
  366. return SCI_SUCCESS;
  367. }
  368. static struct isci_host *isci_host_alloc(struct pci_dev *pdev, int id)
  369. {
  370. struct isci_host *isci_host;
  371. struct Scsi_Host *shost;
  372. int err;
  373. isci_host = devm_kzalloc(&pdev->dev, sizeof(*isci_host), GFP_KERNEL);
  374. if (!isci_host)
  375. return NULL;
  376. isci_host->pdev = pdev;
  377. isci_host->id = id;
  378. shost = scsi_host_alloc(&isci_sht, sizeof(void *));
  379. if (!shost)
  380. return NULL;
  381. isci_host->shost = shost;
  382. err = isci_host_init(isci_host);
  383. if (err)
  384. goto err_shost;
  385. SHOST_TO_SAS_HA(shost) = &isci_host->sas_ha;
  386. isci_host->sas_ha.core.shost = shost;
  387. shost->transportt = isci_transport_template;
  388. shost->max_id = ~0;
  389. shost->max_lun = ~0;
  390. shost->max_cmd_len = MAX_COMMAND_SIZE;
  391. err = scsi_add_host(shost, &pdev->dev);
  392. if (err)
  393. goto err_shost;
  394. err = isci_register_sas_ha(isci_host);
  395. if (err)
  396. goto err_shost_remove;
  397. return isci_host;
  398. err_shost_remove:
  399. scsi_remove_host(shost);
  400. err_shost:
  401. scsi_host_put(shost);
  402. return NULL;
  403. }
  404. static void check_si_rev(struct pci_dev *pdev)
  405. {
  406. if (num_controllers(pdev) > 1)
  407. isci_si_rev = ISCI_SI_REVB0;
  408. else {
  409. switch (pdev->revision) {
  410. case 0:
  411. case 1:
  412. /* if the id is ambiguous don't update isci_si_rev */
  413. break;
  414. case 3:
  415. isci_si_rev = ISCI_SI_REVA2;
  416. break;
  417. default:
  418. case 4:
  419. isci_si_rev = ISCI_SI_REVB0;
  420. break;
  421. }
  422. }
  423. dev_info(&pdev->dev, "driver configured for %s silicon (rev: %d)\n",
  424. isci_si_rev == ISCI_SI_REVA0 ? "A0" :
  425. isci_si_rev == ISCI_SI_REVA2 ? "A2" : "B0", pdev->revision);
  426. }
  427. static int isci_verify_firmware(const struct firmware *fw,
  428. struct isci_firmware *isci_fw)
  429. {
  430. const u8 *tmp;
  431. if (fw->size < ISCI_FIRMWARE_MIN_SIZE)
  432. return -EINVAL;
  433. tmp = fw->data;
  434. /* 12th char should be the NULL terminate for the ID string */
  435. if (tmp[11] != '\0')
  436. return -EINVAL;
  437. if (strncmp("#SCU MAGIC#", tmp, 11) != 0)
  438. return -EINVAL;
  439. isci_fw->id = tmp;
  440. isci_fw->version = fw->data[ISCI_FW_VER_OFS];
  441. isci_fw->subversion = fw->data[ISCI_FW_SUBVER_OFS];
  442. tmp = fw->data + ISCI_FW_DATA_OFS;
  443. while (*tmp != ISCI_FW_HDR_EOF) {
  444. switch (*tmp) {
  445. case ISCI_FW_HDR_PHYMASK:
  446. tmp++;
  447. isci_fw->phy_masks_size = *tmp;
  448. tmp++;
  449. isci_fw->phy_masks = (const u32 *)tmp;
  450. tmp += sizeof(u32) * isci_fw->phy_masks_size;
  451. break;
  452. case ISCI_FW_HDR_PHYGEN:
  453. tmp++;
  454. isci_fw->phy_gens_size = *tmp;
  455. tmp++;
  456. isci_fw->phy_gens = (const u32 *)tmp;
  457. tmp += sizeof(u32) * isci_fw->phy_gens_size;
  458. break;
  459. case ISCI_FW_HDR_SASADDR:
  460. tmp++;
  461. isci_fw->sas_addrs_size = *tmp;
  462. tmp++;
  463. isci_fw->sas_addrs = (const u64 *)tmp;
  464. tmp += sizeof(u64) * isci_fw->sas_addrs_size;
  465. break;
  466. default:
  467. pr_err("bad field in firmware binary blob\n");
  468. return -EINVAL;
  469. }
  470. }
  471. pr_info("isci firmware v%u.%u loaded.\n",
  472. isci_fw->version, isci_fw->subversion);
  473. return SCI_SUCCESS;
  474. }
  475. static int __devinit isci_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  476. {
  477. struct isci_pci_info *pci_info;
  478. int err, i;
  479. struct isci_host *isci_host;
  480. const struct firmware *fw = NULL;
  481. check_si_rev(pdev);
  482. pci_info = devm_kzalloc(&pdev->dev, sizeof(*pci_info), GFP_KERNEL);
  483. if (!pci_info)
  484. return -ENOMEM;
  485. pci_set_drvdata(pdev, pci_info);
  486. err = request_firmware(&fw, ISCI_FW_NAME, &pdev->dev);
  487. if (err) {
  488. dev_warn(&pdev->dev,
  489. "Loading firmware failed, using default values\n");
  490. dev_warn(&pdev->dev,
  491. "Default OEM configuration being used:"
  492. " 4 narrow ports, and default SAS Addresses\n");
  493. } else {
  494. isci_firmware = devm_kzalloc(&pdev->dev,
  495. sizeof(struct isci_firmware),
  496. GFP_KERNEL);
  497. if (isci_firmware) {
  498. err = isci_verify_firmware(fw, isci_firmware);
  499. if (err != SCI_SUCCESS) {
  500. dev_warn(&pdev->dev,
  501. "firmware verification failed\n");
  502. dev_warn(&pdev->dev,
  503. "Default OEM configuration being used:"
  504. " 4 narrow ports, and default SAS "
  505. "Addresses\n");
  506. devm_kfree(&pdev->dev, isci_firmware);
  507. isci_firmware = NULL;
  508. }
  509. }
  510. release_firmware(fw);
  511. }
  512. err = isci_pci_init(pdev);
  513. if (err)
  514. return err;
  515. for (i = 0; i < num_controllers(pdev); i++) {
  516. struct isci_host *h = isci_host_alloc(pdev, i);
  517. if (!h) {
  518. err = -ENOMEM;
  519. goto err_host_alloc;
  520. }
  521. pci_info->hosts[i] = h;
  522. }
  523. err = isci_setup_interrupts(pdev);
  524. if (err)
  525. goto err_host_alloc;
  526. for_each_isci_host(i, isci_host, pdev)
  527. scsi_scan_host(isci_host->shost);
  528. return 0;
  529. err_host_alloc:
  530. for_each_isci_host(i, isci_host, pdev)
  531. isci_unregister_sas_ha(isci_host);
  532. return err;
  533. }
  534. static void __devexit isci_pci_remove(struct pci_dev *pdev)
  535. {
  536. struct isci_host *isci_host;
  537. int i;
  538. for_each_isci_host(i, isci_host, pdev) {
  539. isci_unregister_sas_ha(isci_host);
  540. isci_host_deinit(isci_host);
  541. scic_controller_disable_interrupts(isci_host->core_controller);
  542. }
  543. }
  544. static __init int isci_init(void)
  545. {
  546. int err = -ENOMEM;
  547. pr_info("%s: Intel(R) C600 SAS Controller Driver\n", DRV_NAME);
  548. isci_kmem_cache = kmem_cache_create(DRV_NAME,
  549. sizeof(struct isci_remote_device) +
  550. scic_remote_device_get_object_size(),
  551. 0, 0, NULL);
  552. if (!isci_kmem_cache)
  553. return err;
  554. isci_transport_template = sas_domain_attach_transport(&isci_transport_ops);
  555. if (!isci_transport_template)
  556. goto err_kmem;
  557. err = pci_register_driver(&isci_pci_driver);
  558. if (err)
  559. goto err_sas;
  560. return 0;
  561. err_sas:
  562. sas_release_transport(isci_transport_template);
  563. err_kmem:
  564. kmem_cache_destroy(isci_kmem_cache);
  565. return err;
  566. }
  567. static __exit void isci_exit(void)
  568. {
  569. pci_unregister_driver(&isci_pci_driver);
  570. sas_release_transport(isci_transport_template);
  571. kmem_cache_destroy(isci_kmem_cache);
  572. }
  573. MODULE_LICENSE("Dual BSD/GPL");
  574. MODULE_FIRMWARE(ISCI_FW_NAME);
  575. module_init(isci_init);
  576. module_exit(isci_exit);