mv_init.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  1. /*
  2. * Marvell 88SE64xx/88SE94xx pci init
  3. *
  4. * Copyright 2007 Red Hat, Inc.
  5. * Copyright 2008 Marvell. <kewei@marvell.com>
  6. *
  7. * This file is licensed under GPLv2.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; version 2 of the
  12. * License.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  22. * USA
  23. */
  24. #include "mv_sas.h"
  25. static struct scsi_transport_template *mvs_stt;
  26. static const struct mvs_chip_info mvs_chips[] = {
  27. [chip_6320] = { 1, 2, 0x400, 17, 16, 9, &mvs_64xx_dispatch, },
  28. [chip_6440] = { 1, 4, 0x400, 17, 16, 9, &mvs_64xx_dispatch, },
  29. [chip_6485] = { 1, 8, 0x800, 33, 32, 10, &mvs_64xx_dispatch, },
  30. [chip_9180] = { 2, 4, 0x800, 17, 64, 9, &mvs_94xx_dispatch, },
  31. [chip_9480] = { 2, 4, 0x800, 17, 64, 9, &mvs_94xx_dispatch, },
  32. [chip_1300] = { 1, 4, 0x400, 17, 16, 9, &mvs_64xx_dispatch, },
  33. [chip_1320] = { 2, 4, 0x800, 17, 64, 9, &mvs_94xx_dispatch, },
  34. };
  35. #define SOC_SAS_NUM 2
  36. static struct scsi_host_template mvs_sht = {
  37. .module = THIS_MODULE,
  38. .name = DRV_NAME,
  39. .queuecommand = sas_queuecommand,
  40. .target_alloc = sas_target_alloc,
  41. .slave_configure = mvs_slave_configure,
  42. .slave_destroy = sas_slave_destroy,
  43. .scan_finished = mvs_scan_finished,
  44. .scan_start = mvs_scan_start,
  45. .change_queue_depth = sas_change_queue_depth,
  46. .change_queue_type = sas_change_queue_type,
  47. .bios_param = sas_bios_param,
  48. .can_queue = 1,
  49. .cmd_per_lun = 1,
  50. .this_id = -1,
  51. .sg_tablesize = SG_ALL,
  52. .max_sectors = SCSI_DEFAULT_MAX_SECTORS,
  53. .use_clustering = ENABLE_CLUSTERING,
  54. .eh_device_reset_handler = sas_eh_device_reset_handler,
  55. .eh_bus_reset_handler = sas_eh_bus_reset_handler,
  56. .slave_alloc = mvs_slave_alloc,
  57. .target_destroy = sas_target_destroy,
  58. .ioctl = sas_ioctl,
  59. };
  60. static struct sas_domain_function_template mvs_transport_ops = {
  61. .lldd_dev_found = mvs_dev_found,
  62. .lldd_dev_gone = mvs_dev_gone,
  63. .lldd_execute_task = mvs_queue_command,
  64. .lldd_control_phy = mvs_phy_control,
  65. .lldd_abort_task = mvs_abort_task,
  66. .lldd_abort_task_set = mvs_abort_task_set,
  67. .lldd_clear_aca = mvs_clear_aca,
  68. .lldd_clear_task_set = mvs_clear_task_set,
  69. .lldd_I_T_nexus_reset = mvs_I_T_nexus_reset,
  70. .lldd_lu_reset = mvs_lu_reset,
  71. .lldd_query_task = mvs_query_task,
  72. .lldd_port_formed = mvs_port_formed,
  73. .lldd_port_deformed = mvs_port_deformed,
  74. };
  75. static void __devinit mvs_phy_init(struct mvs_info *mvi, int phy_id)
  76. {
  77. struct mvs_phy *phy = &mvi->phy[phy_id];
  78. struct asd_sas_phy *sas_phy = &phy->sas_phy;
  79. phy->mvi = mvi;
  80. init_timer(&phy->timer);
  81. sas_phy->enabled = (phy_id < mvi->chip->n_phy) ? 1 : 0;
  82. sas_phy->class = SAS;
  83. sas_phy->iproto = SAS_PROTOCOL_ALL;
  84. sas_phy->tproto = 0;
  85. sas_phy->type = PHY_TYPE_PHYSICAL;
  86. sas_phy->role = PHY_ROLE_INITIATOR;
  87. sas_phy->oob_mode = OOB_NOT_CONNECTED;
  88. sas_phy->linkrate = SAS_LINK_RATE_UNKNOWN;
  89. sas_phy->id = phy_id;
  90. sas_phy->sas_addr = &mvi->sas_addr[0];
  91. sas_phy->frame_rcvd = &phy->frame_rcvd[0];
  92. sas_phy->ha = (struct sas_ha_struct *)mvi->shost->hostdata;
  93. sas_phy->lldd_phy = phy;
  94. }
  95. static void mvs_free(struct mvs_info *mvi)
  96. {
  97. int i;
  98. struct mvs_wq *mwq;
  99. int slot_nr;
  100. if (!mvi)
  101. return;
  102. if (mvi->flags & MVF_FLAG_SOC)
  103. slot_nr = MVS_SOC_SLOTS;
  104. else
  105. slot_nr = MVS_SLOTS;
  106. for (i = 0; i < mvi->tags_num; i++) {
  107. struct mvs_slot_info *slot = &mvi->slot_info[i];
  108. if (slot->buf)
  109. dma_free_coherent(mvi->dev, MVS_SLOT_BUF_SZ,
  110. slot->buf, slot->buf_dma);
  111. }
  112. if (mvi->tx)
  113. dma_free_coherent(mvi->dev,
  114. sizeof(*mvi->tx) * MVS_CHIP_SLOT_SZ,
  115. mvi->tx, mvi->tx_dma);
  116. if (mvi->rx_fis)
  117. dma_free_coherent(mvi->dev, MVS_RX_FISL_SZ,
  118. mvi->rx_fis, mvi->rx_fis_dma);
  119. if (mvi->rx)
  120. dma_free_coherent(mvi->dev,
  121. sizeof(*mvi->rx) * (MVS_RX_RING_SZ + 1),
  122. mvi->rx, mvi->rx_dma);
  123. if (mvi->slot)
  124. dma_free_coherent(mvi->dev,
  125. sizeof(*mvi->slot) * slot_nr,
  126. mvi->slot, mvi->slot_dma);
  127. #ifndef DISABLE_HOTPLUG_DMA_FIX
  128. if (mvi->bulk_buffer)
  129. dma_free_coherent(mvi->dev, TRASH_BUCKET_SIZE,
  130. mvi->bulk_buffer, mvi->bulk_buffer_dma);
  131. #endif
  132. MVS_CHIP_DISP->chip_iounmap(mvi);
  133. if (mvi->shost)
  134. scsi_host_put(mvi->shost);
  135. list_for_each_entry(mwq, &mvi->wq_list, entry)
  136. cancel_delayed_work(&mwq->work_q);
  137. kfree(mvi);
  138. }
  139. #ifdef MVS_USE_TASKLET
  140. struct tasklet_struct mv_tasklet;
  141. static void mvs_tasklet(unsigned long opaque)
  142. {
  143. unsigned long flags;
  144. u32 stat;
  145. u16 core_nr, i = 0;
  146. struct mvs_info *mvi;
  147. struct sas_ha_struct *sha = (struct sas_ha_struct *)opaque;
  148. core_nr = ((struct mvs_prv_info *)sha->lldd_ha)->n_host;
  149. mvi = ((struct mvs_prv_info *)sha->lldd_ha)->mvi[0];
  150. if (unlikely(!mvi))
  151. BUG_ON(1);
  152. for (i = 0; i < core_nr; i++) {
  153. mvi = ((struct mvs_prv_info *)sha->lldd_ha)->mvi[i];
  154. stat = MVS_CHIP_DISP->isr_status(mvi, mvi->irq);
  155. if (stat)
  156. MVS_CHIP_DISP->isr(mvi, mvi->irq, stat);
  157. }
  158. }
  159. #endif
  160. static irqreturn_t mvs_interrupt(int irq, void *opaque)
  161. {
  162. u32 core_nr, i = 0;
  163. u32 stat;
  164. struct mvs_info *mvi;
  165. struct sas_ha_struct *sha = opaque;
  166. core_nr = ((struct mvs_prv_info *)sha->lldd_ha)->n_host;
  167. mvi = ((struct mvs_prv_info *)sha->lldd_ha)->mvi[0];
  168. if (unlikely(!mvi))
  169. return IRQ_NONE;
  170. stat = MVS_CHIP_DISP->isr_status(mvi, irq);
  171. if (!stat)
  172. return IRQ_NONE;
  173. #ifdef MVS_USE_TASKLET
  174. tasklet_schedule(&mv_tasklet);
  175. #else
  176. for (i = 0; i < core_nr; i++) {
  177. mvi = ((struct mvs_prv_info *)sha->lldd_ha)->mvi[i];
  178. MVS_CHIP_DISP->isr(mvi, irq, stat);
  179. }
  180. #endif
  181. return IRQ_HANDLED;
  182. }
  183. static int __devinit mvs_alloc(struct mvs_info *mvi, struct Scsi_Host *shost)
  184. {
  185. int i, slot_nr;
  186. if (mvi->flags & MVF_FLAG_SOC)
  187. slot_nr = MVS_SOC_SLOTS;
  188. else
  189. slot_nr = MVS_SLOTS;
  190. spin_lock_init(&mvi->lock);
  191. for (i = 0; i < mvi->chip->n_phy; i++) {
  192. mvs_phy_init(mvi, i);
  193. mvi->port[i].wide_port_phymap = 0;
  194. mvi->port[i].port_attached = 0;
  195. INIT_LIST_HEAD(&mvi->port[i].list);
  196. }
  197. for (i = 0; i < MVS_MAX_DEVICES; i++) {
  198. mvi->devices[i].taskfileset = MVS_ID_NOT_MAPPED;
  199. mvi->devices[i].dev_type = NO_DEVICE;
  200. mvi->devices[i].device_id = i;
  201. mvi->devices[i].dev_status = MVS_DEV_NORMAL;
  202. }
  203. /*
  204. * alloc and init our DMA areas
  205. */
  206. mvi->tx = dma_alloc_coherent(mvi->dev,
  207. sizeof(*mvi->tx) * MVS_CHIP_SLOT_SZ,
  208. &mvi->tx_dma, GFP_KERNEL);
  209. if (!mvi->tx)
  210. goto err_out;
  211. memset(mvi->tx, 0, sizeof(*mvi->tx) * MVS_CHIP_SLOT_SZ);
  212. mvi->rx_fis = dma_alloc_coherent(mvi->dev, MVS_RX_FISL_SZ,
  213. &mvi->rx_fis_dma, GFP_KERNEL);
  214. if (!mvi->rx_fis)
  215. goto err_out;
  216. memset(mvi->rx_fis, 0, MVS_RX_FISL_SZ);
  217. mvi->rx = dma_alloc_coherent(mvi->dev,
  218. sizeof(*mvi->rx) * (MVS_RX_RING_SZ + 1),
  219. &mvi->rx_dma, GFP_KERNEL);
  220. if (!mvi->rx)
  221. goto err_out;
  222. memset(mvi->rx, 0, sizeof(*mvi->rx) * (MVS_RX_RING_SZ + 1));
  223. mvi->rx[0] = cpu_to_le32(0xfff);
  224. mvi->rx_cons = 0xfff;
  225. mvi->slot = dma_alloc_coherent(mvi->dev,
  226. sizeof(*mvi->slot) * slot_nr,
  227. &mvi->slot_dma, GFP_KERNEL);
  228. if (!mvi->slot)
  229. goto err_out;
  230. memset(mvi->slot, 0, sizeof(*mvi->slot) * slot_nr);
  231. #ifndef DISABLE_HOTPLUG_DMA_FIX
  232. mvi->bulk_buffer = dma_alloc_coherent(mvi->dev,
  233. TRASH_BUCKET_SIZE,
  234. &mvi->bulk_buffer_dma, GFP_KERNEL);
  235. if (!mvi->bulk_buffer)
  236. goto err_out;
  237. #endif
  238. for (i = 0; i < slot_nr; i++) {
  239. struct mvs_slot_info *slot = &mvi->slot_info[i];
  240. slot->buf = dma_alloc_coherent(mvi->dev, MVS_SLOT_BUF_SZ,
  241. &slot->buf_dma, GFP_KERNEL);
  242. if (!slot->buf) {
  243. printk(KERN_DEBUG"failed to allocate slot->buf.\n");
  244. goto err_out;
  245. }
  246. memset(slot->buf, 0, MVS_SLOT_BUF_SZ);
  247. ++mvi->tags_num;
  248. }
  249. /* Initialize tags */
  250. mvs_tag_init(mvi);
  251. return 0;
  252. err_out:
  253. return 1;
  254. }
  255. int mvs_ioremap(struct mvs_info *mvi, int bar, int bar_ex)
  256. {
  257. unsigned long res_start, res_len, res_flag, res_flag_ex = 0;
  258. struct pci_dev *pdev = mvi->pdev;
  259. if (bar_ex != -1) {
  260. /*
  261. * ioremap main and peripheral registers
  262. */
  263. res_start = pci_resource_start(pdev, bar_ex);
  264. res_len = pci_resource_len(pdev, bar_ex);
  265. if (!res_start || !res_len)
  266. goto err_out;
  267. res_flag_ex = pci_resource_flags(pdev, bar_ex);
  268. if (res_flag_ex & IORESOURCE_MEM) {
  269. if (res_flag_ex & IORESOURCE_CACHEABLE)
  270. mvi->regs_ex = ioremap(res_start, res_len);
  271. else
  272. mvi->regs_ex = ioremap_nocache(res_start,
  273. res_len);
  274. } else
  275. mvi->regs_ex = (void *)res_start;
  276. if (!mvi->regs_ex)
  277. goto err_out;
  278. }
  279. res_start = pci_resource_start(pdev, bar);
  280. res_len = pci_resource_len(pdev, bar);
  281. if (!res_start || !res_len)
  282. goto err_out;
  283. res_flag = pci_resource_flags(pdev, bar);
  284. if (res_flag & IORESOURCE_CACHEABLE)
  285. mvi->regs = ioremap(res_start, res_len);
  286. else
  287. mvi->regs = ioremap_nocache(res_start, res_len);
  288. if (!mvi->regs) {
  289. if (mvi->regs_ex && (res_flag_ex & IORESOURCE_MEM))
  290. iounmap(mvi->regs_ex);
  291. mvi->regs_ex = NULL;
  292. goto err_out;
  293. }
  294. return 0;
  295. err_out:
  296. return -1;
  297. }
  298. void mvs_iounmap(void __iomem *regs)
  299. {
  300. iounmap(regs);
  301. }
  302. static struct mvs_info *__devinit mvs_pci_alloc(struct pci_dev *pdev,
  303. const struct pci_device_id *ent,
  304. struct Scsi_Host *shost, unsigned int id)
  305. {
  306. struct mvs_info *mvi;
  307. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  308. mvi = kzalloc(sizeof(*mvi) + MVS_SLOTS * sizeof(struct mvs_slot_info),
  309. GFP_KERNEL);
  310. if (!mvi)
  311. return NULL;
  312. mvi->pdev = pdev;
  313. mvi->dev = &pdev->dev;
  314. mvi->chip_id = ent->driver_data;
  315. mvi->chip = &mvs_chips[mvi->chip_id];
  316. INIT_LIST_HEAD(&mvi->wq_list);
  317. mvi->irq = pdev->irq;
  318. ((struct mvs_prv_info *)sha->lldd_ha)->mvi[id] = mvi;
  319. ((struct mvs_prv_info *)sha->lldd_ha)->n_phy = mvi->chip->n_phy;
  320. mvi->id = id;
  321. mvi->sas = sha;
  322. mvi->shost = shost;
  323. #ifdef MVS_USE_TASKLET
  324. tasklet_init(&mv_tasklet, mvs_tasklet, (unsigned long)sha);
  325. #endif
  326. if (MVS_CHIP_DISP->chip_ioremap(mvi))
  327. goto err_out;
  328. if (!mvs_alloc(mvi, shost))
  329. return mvi;
  330. err_out:
  331. mvs_free(mvi);
  332. return NULL;
  333. }
  334. /* move to PCI layer or libata core? */
  335. static int pci_go_64(struct pci_dev *pdev)
  336. {
  337. int rc;
  338. if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
  339. rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
  340. if (rc) {
  341. rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  342. if (rc) {
  343. dev_printk(KERN_ERR, &pdev->dev,
  344. "64-bit DMA enable failed\n");
  345. return rc;
  346. }
  347. }
  348. } else {
  349. rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  350. if (rc) {
  351. dev_printk(KERN_ERR, &pdev->dev,
  352. "32-bit DMA enable failed\n");
  353. return rc;
  354. }
  355. rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  356. if (rc) {
  357. dev_printk(KERN_ERR, &pdev->dev,
  358. "32-bit consistent DMA enable failed\n");
  359. return rc;
  360. }
  361. }
  362. return rc;
  363. }
  364. static int __devinit mvs_prep_sas_ha_init(struct Scsi_Host *shost,
  365. const struct mvs_chip_info *chip_info)
  366. {
  367. int phy_nr, port_nr; unsigned short core_nr;
  368. struct asd_sas_phy **arr_phy;
  369. struct asd_sas_port **arr_port;
  370. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  371. core_nr = chip_info->n_host;
  372. phy_nr = core_nr * chip_info->n_phy;
  373. port_nr = phy_nr;
  374. memset(sha, 0x00, sizeof(struct sas_ha_struct));
  375. arr_phy = kcalloc(phy_nr, sizeof(void *), GFP_KERNEL);
  376. arr_port = kcalloc(port_nr, sizeof(void *), GFP_KERNEL);
  377. if (!arr_phy || !arr_port)
  378. goto exit_free;
  379. sha->sas_phy = arr_phy;
  380. sha->sas_port = arr_port;
  381. sha->lldd_ha = kzalloc(sizeof(struct mvs_prv_info), GFP_KERNEL);
  382. if (!sha->lldd_ha)
  383. goto exit_free;
  384. ((struct mvs_prv_info *)sha->lldd_ha)->n_host = core_nr;
  385. shost->transportt = mvs_stt;
  386. shost->max_id = 128;
  387. shost->max_lun = ~0;
  388. shost->max_channel = 1;
  389. shost->max_cmd_len = 16;
  390. return 0;
  391. exit_free:
  392. kfree(arr_phy);
  393. kfree(arr_port);
  394. return -1;
  395. }
  396. static void __devinit mvs_post_sas_ha_init(struct Scsi_Host *shost,
  397. const struct mvs_chip_info *chip_info)
  398. {
  399. int can_queue, i = 0, j = 0;
  400. struct mvs_info *mvi = NULL;
  401. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  402. unsigned short nr_core = ((struct mvs_prv_info *)sha->lldd_ha)->n_host;
  403. for (j = 0; j < nr_core; j++) {
  404. mvi = ((struct mvs_prv_info *)sha->lldd_ha)->mvi[j];
  405. for (i = 0; i < chip_info->n_phy; i++) {
  406. sha->sas_phy[j * chip_info->n_phy + i] =
  407. &mvi->phy[i].sas_phy;
  408. sha->sas_port[j * chip_info->n_phy + i] =
  409. &mvi->port[i].sas_port;
  410. }
  411. }
  412. sha->sas_ha_name = DRV_NAME;
  413. sha->dev = mvi->dev;
  414. sha->lldd_module = THIS_MODULE;
  415. sha->sas_addr = &mvi->sas_addr[0];
  416. sha->num_phys = nr_core * chip_info->n_phy;
  417. sha->lldd_max_execute_num = 1;
  418. if (mvi->flags & MVF_FLAG_SOC)
  419. can_queue = MVS_SOC_CAN_QUEUE;
  420. else
  421. can_queue = MVS_CAN_QUEUE;
  422. sha->lldd_queue_size = can_queue;
  423. shost->can_queue = can_queue;
  424. mvi->shost->cmd_per_lun = MVS_SLOTS/sha->num_phys;
  425. sha->core.shost = mvi->shost;
  426. }
  427. static void mvs_init_sas_add(struct mvs_info *mvi)
  428. {
  429. u8 i;
  430. for (i = 0; i < mvi->chip->n_phy; i++) {
  431. mvi->phy[i].dev_sas_addr = 0x5005043011ab0000ULL;
  432. mvi->phy[i].dev_sas_addr =
  433. cpu_to_be64((u64)(*(u64 *)&mvi->phy[i].dev_sas_addr));
  434. }
  435. memcpy(mvi->sas_addr, &mvi->phy[0].dev_sas_addr, SAS_ADDR_SIZE);
  436. }
  437. static int __devinit mvs_pci_init(struct pci_dev *pdev,
  438. const struct pci_device_id *ent)
  439. {
  440. unsigned int rc, nhost = 0;
  441. struct mvs_info *mvi;
  442. irq_handler_t irq_handler = mvs_interrupt;
  443. struct Scsi_Host *shost = NULL;
  444. const struct mvs_chip_info *chip;
  445. dev_printk(KERN_INFO, &pdev->dev,
  446. "mvsas: driver version %s\n", DRV_VERSION);
  447. rc = pci_enable_device(pdev);
  448. if (rc)
  449. goto err_out_enable;
  450. pci_set_master(pdev);
  451. rc = pci_request_regions(pdev, DRV_NAME);
  452. if (rc)
  453. goto err_out_disable;
  454. rc = pci_go_64(pdev);
  455. if (rc)
  456. goto err_out_regions;
  457. shost = scsi_host_alloc(&mvs_sht, sizeof(void *));
  458. if (!shost) {
  459. rc = -ENOMEM;
  460. goto err_out_regions;
  461. }
  462. chip = &mvs_chips[ent->driver_data];
  463. SHOST_TO_SAS_HA(shost) =
  464. kcalloc(1, sizeof(struct sas_ha_struct), GFP_KERNEL);
  465. if (!SHOST_TO_SAS_HA(shost)) {
  466. kfree(shost);
  467. rc = -ENOMEM;
  468. goto err_out_regions;
  469. }
  470. rc = mvs_prep_sas_ha_init(shost, chip);
  471. if (rc) {
  472. kfree(shost);
  473. rc = -ENOMEM;
  474. goto err_out_regions;
  475. }
  476. pci_set_drvdata(pdev, SHOST_TO_SAS_HA(shost));
  477. do {
  478. mvi = mvs_pci_alloc(pdev, ent, shost, nhost);
  479. if (!mvi) {
  480. rc = -ENOMEM;
  481. goto err_out_regions;
  482. }
  483. mvs_init_sas_add(mvi);
  484. mvi->instance = nhost;
  485. rc = MVS_CHIP_DISP->chip_init(mvi);
  486. if (rc) {
  487. mvs_free(mvi);
  488. goto err_out_regions;
  489. }
  490. nhost++;
  491. } while (nhost < chip->n_host);
  492. mvs_post_sas_ha_init(shost, chip);
  493. rc = scsi_add_host(shost, &pdev->dev);
  494. if (rc)
  495. goto err_out_shost;
  496. rc = sas_register_ha(SHOST_TO_SAS_HA(shost));
  497. if (rc)
  498. goto err_out_shost;
  499. rc = request_irq(pdev->irq, irq_handler, IRQF_SHARED,
  500. DRV_NAME, SHOST_TO_SAS_HA(shost));
  501. if (rc)
  502. goto err_not_sas;
  503. MVS_CHIP_DISP->interrupt_enable(mvi);
  504. scsi_scan_host(mvi->shost);
  505. return 0;
  506. err_not_sas:
  507. sas_unregister_ha(SHOST_TO_SAS_HA(shost));
  508. err_out_shost:
  509. scsi_remove_host(mvi->shost);
  510. err_out_regions:
  511. pci_release_regions(pdev);
  512. err_out_disable:
  513. pci_disable_device(pdev);
  514. err_out_enable:
  515. return rc;
  516. }
  517. static void __devexit mvs_pci_remove(struct pci_dev *pdev)
  518. {
  519. unsigned short core_nr, i = 0;
  520. struct sas_ha_struct *sha = pci_get_drvdata(pdev);
  521. struct mvs_info *mvi = NULL;
  522. core_nr = ((struct mvs_prv_info *)sha->lldd_ha)->n_host;
  523. mvi = ((struct mvs_prv_info *)sha->lldd_ha)->mvi[0];
  524. #ifdef MVS_USE_TASKLET
  525. tasklet_kill(&mv_tasklet);
  526. #endif
  527. pci_set_drvdata(pdev, NULL);
  528. sas_unregister_ha(sha);
  529. sas_remove_host(mvi->shost);
  530. scsi_remove_host(mvi->shost);
  531. MVS_CHIP_DISP->interrupt_disable(mvi);
  532. free_irq(mvi->irq, sha);
  533. for (i = 0; i < core_nr; i++) {
  534. mvi = ((struct mvs_prv_info *)sha->lldd_ha)->mvi[i];
  535. mvs_free(mvi);
  536. }
  537. kfree(sha->sas_phy);
  538. kfree(sha->sas_port);
  539. kfree(sha);
  540. pci_release_regions(pdev);
  541. pci_disable_device(pdev);
  542. return;
  543. }
  544. static struct pci_device_id __devinitdata mvs_pci_table[] = {
  545. { PCI_VDEVICE(MARVELL, 0x6320), chip_6320 },
  546. { PCI_VDEVICE(MARVELL, 0x6340), chip_6440 },
  547. {
  548. .vendor = PCI_VENDOR_ID_MARVELL,
  549. .device = 0x6440,
  550. .subvendor = PCI_ANY_ID,
  551. .subdevice = 0x6480,
  552. .class = 0,
  553. .class_mask = 0,
  554. .driver_data = chip_6485,
  555. },
  556. { PCI_VDEVICE(MARVELL, 0x6440), chip_6440 },
  557. { PCI_VDEVICE(MARVELL, 0x6485), chip_6485 },
  558. { PCI_VDEVICE(MARVELL, 0x9480), chip_9480 },
  559. { PCI_VDEVICE(MARVELL, 0x9180), chip_9180 },
  560. { PCI_VDEVICE(ARECA, PCI_DEVICE_ID_ARECA_1300), chip_1300 },
  561. { PCI_VDEVICE(ARECA, PCI_DEVICE_ID_ARECA_1320), chip_1320 },
  562. { PCI_VDEVICE(ADAPTEC2, 0x0450), chip_6440 },
  563. { } /* terminate list */
  564. };
  565. static struct pci_driver mvs_pci_driver = {
  566. .name = DRV_NAME,
  567. .id_table = mvs_pci_table,
  568. .probe = mvs_pci_init,
  569. .remove = __devexit_p(mvs_pci_remove),
  570. };
  571. /* task handler */
  572. struct task_struct *mvs_th;
  573. static int __init mvs_init(void)
  574. {
  575. int rc;
  576. mvs_stt = sas_domain_attach_transport(&mvs_transport_ops);
  577. if (!mvs_stt)
  578. return -ENOMEM;
  579. rc = pci_register_driver(&mvs_pci_driver);
  580. if (rc)
  581. goto err_out;
  582. return 0;
  583. err_out:
  584. sas_release_transport(mvs_stt);
  585. return rc;
  586. }
  587. static void __exit mvs_exit(void)
  588. {
  589. pci_unregister_driver(&mvs_pci_driver);
  590. sas_release_transport(mvs_stt);
  591. }
  592. module_init(mvs_init);
  593. module_exit(mvs_exit);
  594. MODULE_AUTHOR("Jeff Garzik <jgarzik@pobox.com>");
  595. MODULE_DESCRIPTION("Marvell 88SE6440 SAS/SATA controller driver");
  596. MODULE_VERSION(DRV_VERSION);
  597. MODULE_LICENSE("GPL");
  598. #ifdef CONFIG_PCI
  599. MODULE_DEVICE_TABLE(pci, mvs_pci_table);
  600. #endif