mv_init.c 17 KB

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