mv_init.c 18 KB

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