mv_init.c 19 KB

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