mv_init.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Marvell 88SE64xx/88SE94xx pci init
  4. *
  5. * Copyright 2007 Red Hat, Inc.
  6. * Copyright 2008 Marvell. <kewei@marvell.com>
  7. * Copyright 2009-2011 Marvell. <yuxiangl@marvell.com>
  8. */
  9. #include "mv_sas.h"
  10. int interrupt_coalescing = 0x80;
  11. static struct scsi_transport_template *mvs_stt;
  12. static const struct mvs_chip_info mvs_chips[] = {
  13. [chip_6320] = { 1, 2, 0x400, 17, 16, 6, 9, &mvs_64xx_dispatch, },
  14. [chip_6440] = { 1, 4, 0x400, 17, 16, 6, 9, &mvs_64xx_dispatch, },
  15. [chip_6485] = { 1, 8, 0x800, 33, 32, 6, 10, &mvs_64xx_dispatch, },
  16. [chip_9180] = { 2, 4, 0x800, 17, 64, 8, 9, &mvs_94xx_dispatch, },
  17. [chip_9480] = { 2, 4, 0x800, 17, 64, 8, 9, &mvs_94xx_dispatch, },
  18. [chip_9445] = { 1, 4, 0x800, 17, 64, 8, 11, &mvs_94xx_dispatch, },
  19. [chip_9485] = { 2, 4, 0x800, 17, 64, 8, 11, &mvs_94xx_dispatch, },
  20. [chip_1300] = { 1, 4, 0x400, 17, 16, 6, 9, &mvs_64xx_dispatch, },
  21. [chip_1320] = { 2, 4, 0x800, 17, 64, 8, 9, &mvs_94xx_dispatch, },
  22. };
  23. static const struct attribute_group *mvst_host_groups[];
  24. static const struct attribute_group *mvst_sdev_groups[];
  25. #define SOC_SAS_NUM 2
  26. static const struct scsi_host_template mvs_sht = {
  27. LIBSAS_SHT_BASE
  28. .scan_finished = mvs_scan_finished,
  29. .scan_start = mvs_scan_start,
  30. .can_queue = 1,
  31. .sg_tablesize = SG_ALL,
  32. .shost_groups = mvst_host_groups,
  33. .sdev_groups = mvst_sdev_groups,
  34. .track_queue_depth = 1,
  35. };
  36. static struct sas_domain_function_template mvs_transport_ops = {
  37. .lldd_dev_found = mvs_dev_found,
  38. .lldd_dev_gone = mvs_dev_gone,
  39. .lldd_execute_task = mvs_queue_command,
  40. .lldd_control_phy = mvs_phy_control,
  41. .lldd_abort_task = mvs_abort_task,
  42. .lldd_abort_task_set = sas_abort_task_set,
  43. .lldd_clear_task_set = sas_clear_task_set,
  44. .lldd_I_T_nexus_reset = mvs_I_T_nexus_reset,
  45. .lldd_lu_reset = mvs_lu_reset,
  46. .lldd_query_task = mvs_query_task,
  47. .lldd_port_formed = mvs_port_formed,
  48. .lldd_port_deformed = mvs_port_deformed,
  49. .lldd_write_gpio = mvs_gpio_write,
  50. };
  51. static void mvs_phy_init(struct mvs_info *mvi, int phy_id)
  52. {
  53. struct mvs_phy *phy = &mvi->phy[phy_id];
  54. struct asd_sas_phy *sas_phy = &phy->sas_phy;
  55. phy->mvi = mvi;
  56. phy->port = NULL;
  57. timer_setup(&phy->timer, NULL, 0);
  58. sas_phy->enabled = (phy_id < mvi->chip->n_phy) ? 1 : 0;
  59. sas_phy->iproto = SAS_PROTOCOL_ALL;
  60. sas_phy->tproto = 0;
  61. sas_phy->role = PHY_ROLE_INITIATOR;
  62. sas_phy->oob_mode = OOB_NOT_CONNECTED;
  63. sas_phy->linkrate = SAS_LINK_RATE_UNKNOWN;
  64. sas_phy->id = phy_id;
  65. sas_phy->sas_addr = &mvi->sas_addr[0];
  66. sas_phy->frame_rcvd = &phy->frame_rcvd[0];
  67. sas_phy->ha = (struct sas_ha_struct *)mvi->shost->hostdata;
  68. sas_phy->lldd_phy = phy;
  69. }
  70. static void mvs_free(struct mvs_info *mvi)
  71. {
  72. struct mvs_wq *mwq;
  73. int slot_nr;
  74. if (!mvi)
  75. return;
  76. if (mvi->flags & MVF_FLAG_SOC)
  77. slot_nr = MVS_SOC_SLOTS;
  78. else
  79. slot_nr = MVS_CHIP_SLOT_SZ;
  80. dma_pool_destroy(mvi->dma_pool);
  81. if (mvi->tx)
  82. dma_free_coherent(mvi->dev,
  83. sizeof(*mvi->tx) * MVS_CHIP_SLOT_SZ,
  84. mvi->tx, mvi->tx_dma);
  85. if (mvi->rx_fis)
  86. dma_free_coherent(mvi->dev, MVS_RX_FISL_SZ,
  87. mvi->rx_fis, mvi->rx_fis_dma);
  88. if (mvi->rx)
  89. dma_free_coherent(mvi->dev,
  90. sizeof(*mvi->rx) * (MVS_RX_RING_SZ + 1),
  91. mvi->rx, mvi->rx_dma);
  92. if (mvi->slot)
  93. dma_free_coherent(mvi->dev,
  94. sizeof(*mvi->slot) * slot_nr,
  95. mvi->slot, mvi->slot_dma);
  96. if (mvi->bulk_buffer)
  97. dma_free_coherent(mvi->dev, TRASH_BUCKET_SIZE,
  98. mvi->bulk_buffer, mvi->bulk_buffer_dma);
  99. if (mvi->bulk_buffer1)
  100. dma_free_coherent(mvi->dev, TRASH_BUCKET_SIZE,
  101. mvi->bulk_buffer1, mvi->bulk_buffer_dma1);
  102. MVS_CHIP_DISP->chip_iounmap(mvi);
  103. if (mvi->shost)
  104. scsi_host_put(mvi->shost);
  105. list_for_each_entry(mwq, &mvi->wq_list, entry)
  106. cancel_delayed_work_sync(&mwq->work_q);
  107. kfree(mvi->rsvd_tags);
  108. kfree(mvi);
  109. }
  110. #ifdef CONFIG_SCSI_MVSAS_TASKLET
  111. static void mvs_tasklet(unsigned long opaque)
  112. {
  113. u32 stat;
  114. u16 core_nr, i = 0;
  115. struct mvs_info *mvi;
  116. struct sas_ha_struct *sha = (struct sas_ha_struct *)opaque;
  117. core_nr = ((struct mvs_prv_info *)sha->lldd_ha)->n_host;
  118. mvi = ((struct mvs_prv_info *)sha->lldd_ha)->mvi[0];
  119. if (unlikely(!mvi))
  120. BUG_ON(1);
  121. stat = MVS_CHIP_DISP->isr_status(mvi, mvi->pdev->irq);
  122. if (!stat)
  123. goto out;
  124. for (i = 0; i < core_nr; i++) {
  125. mvi = ((struct mvs_prv_info *)sha->lldd_ha)->mvi[i];
  126. MVS_CHIP_DISP->isr(mvi, mvi->pdev->irq, stat);
  127. }
  128. out:
  129. MVS_CHIP_DISP->interrupt_enable(mvi);
  130. }
  131. #endif
  132. static irqreturn_t mvs_interrupt(int irq, void *opaque)
  133. {
  134. u32 stat;
  135. struct mvs_info *mvi;
  136. struct sas_ha_struct *sha = opaque;
  137. #ifndef CONFIG_SCSI_MVSAS_TASKLET
  138. u32 i;
  139. u32 core_nr;
  140. core_nr = ((struct mvs_prv_info *)sha->lldd_ha)->n_host;
  141. #endif
  142. mvi = ((struct mvs_prv_info *)sha->lldd_ha)->mvi[0];
  143. if (unlikely(!mvi))
  144. return IRQ_NONE;
  145. #ifdef CONFIG_SCSI_MVSAS_TASKLET
  146. MVS_CHIP_DISP->interrupt_disable(mvi);
  147. #endif
  148. stat = MVS_CHIP_DISP->isr_status(mvi, irq);
  149. if (!stat) {
  150. #ifdef CONFIG_SCSI_MVSAS_TASKLET
  151. MVS_CHIP_DISP->interrupt_enable(mvi);
  152. #endif
  153. return IRQ_NONE;
  154. }
  155. #ifdef CONFIG_SCSI_MVSAS_TASKLET
  156. tasklet_schedule(&((struct mvs_prv_info *)sha->lldd_ha)->mv_tasklet);
  157. #else
  158. for (i = 0; i < core_nr; i++) {
  159. mvi = ((struct mvs_prv_info *)sha->lldd_ha)->mvi[i];
  160. MVS_CHIP_DISP->isr(mvi, irq, stat);
  161. }
  162. #endif
  163. return IRQ_HANDLED;
  164. }
  165. static int mvs_alloc(struct mvs_info *mvi, struct Scsi_Host *shost)
  166. {
  167. int i = 0, slot_nr;
  168. char pool_name[32];
  169. if (mvi->flags & MVF_FLAG_SOC)
  170. slot_nr = MVS_SOC_SLOTS;
  171. else
  172. slot_nr = MVS_CHIP_SLOT_SZ;
  173. spin_lock_init(&mvi->lock);
  174. for (i = 0; i < mvi->chip->n_phy; i++) {
  175. mvs_phy_init(mvi, i);
  176. mvi->port[i].wide_port_phymap = 0;
  177. mvi->port[i].port_attached = 0;
  178. INIT_LIST_HEAD(&mvi->port[i].list);
  179. }
  180. for (i = 0; i < MVS_MAX_DEVICES; i++) {
  181. mvi->devices[i].taskfileset = MVS_ID_NOT_MAPPED;
  182. mvi->devices[i].dev_type = SAS_PHY_UNUSED;
  183. mvi->devices[i].device_id = i;
  184. mvi->devices[i].dev_status = MVS_DEV_NORMAL;
  185. }
  186. /*
  187. * alloc and init our DMA areas
  188. */
  189. mvi->tx = dma_alloc_coherent(mvi->dev,
  190. sizeof(*mvi->tx) * MVS_CHIP_SLOT_SZ,
  191. &mvi->tx_dma, GFP_KERNEL);
  192. if (!mvi->tx)
  193. goto err_out;
  194. mvi->rx_fis = dma_alloc_coherent(mvi->dev, MVS_RX_FISL_SZ,
  195. &mvi->rx_fis_dma, GFP_KERNEL);
  196. if (!mvi->rx_fis)
  197. goto err_out;
  198. mvi->rx = dma_alloc_coherent(mvi->dev,
  199. sizeof(*mvi->rx) * (MVS_RX_RING_SZ + 1),
  200. &mvi->rx_dma, GFP_KERNEL);
  201. if (!mvi->rx)
  202. goto err_out;
  203. mvi->rx[0] = cpu_to_le32(0xfff);
  204. mvi->rx_cons = 0xfff;
  205. mvi->slot = dma_alloc_coherent(mvi->dev,
  206. sizeof(*mvi->slot) * slot_nr,
  207. &mvi->slot_dma, GFP_KERNEL);
  208. if (!mvi->slot)
  209. goto err_out;
  210. mvi->bulk_buffer = dma_alloc_coherent(mvi->dev,
  211. TRASH_BUCKET_SIZE,
  212. &mvi->bulk_buffer_dma, GFP_KERNEL);
  213. if (!mvi->bulk_buffer)
  214. goto err_out;
  215. mvi->bulk_buffer1 = dma_alloc_coherent(mvi->dev,
  216. TRASH_BUCKET_SIZE,
  217. &mvi->bulk_buffer_dma1, GFP_KERNEL);
  218. if (!mvi->bulk_buffer1)
  219. goto err_out;
  220. sprintf(pool_name, "%s%d", "mvs_dma_pool", mvi->id);
  221. mvi->dma_pool = dma_pool_create(pool_name, &mvi->pdev->dev,
  222. MVS_SLOT_BUF_SZ, 16, 0);
  223. if (!mvi->dma_pool) {
  224. printk(KERN_DEBUG "failed to create dma pool %s.\n", pool_name);
  225. goto err_out;
  226. }
  227. return 0;
  228. err_out:
  229. return 1;
  230. }
  231. int mvs_ioremap(struct mvs_info *mvi, int bar, int bar_ex)
  232. {
  233. unsigned long res_start, res_len, res_flag_ex = 0;
  234. struct pci_dev *pdev = mvi->pdev;
  235. if (bar_ex != -1) {
  236. /*
  237. * ioremap main and peripheral registers
  238. */
  239. res_start = pci_resource_start(pdev, bar_ex);
  240. res_len = pci_resource_len(pdev, bar_ex);
  241. if (!res_start || !res_len)
  242. goto err_out;
  243. res_flag_ex = pci_resource_flags(pdev, bar_ex);
  244. if (res_flag_ex & IORESOURCE_MEM)
  245. mvi->regs_ex = ioremap(res_start, res_len);
  246. else
  247. mvi->regs_ex = (void *)res_start;
  248. if (!mvi->regs_ex)
  249. goto err_out;
  250. }
  251. res_start = pci_resource_start(pdev, bar);
  252. res_len = pci_resource_len(pdev, bar);
  253. if (!res_start || !res_len) {
  254. iounmap(mvi->regs_ex);
  255. mvi->regs_ex = NULL;
  256. goto err_out;
  257. }
  258. mvi->regs = ioremap(res_start, res_len);
  259. if (!mvi->regs) {
  260. if (mvi->regs_ex && (res_flag_ex & IORESOURCE_MEM))
  261. iounmap(mvi->regs_ex);
  262. mvi->regs_ex = NULL;
  263. goto err_out;
  264. }
  265. return 0;
  266. err_out:
  267. return -1;
  268. }
  269. void mvs_iounmap(void __iomem *regs)
  270. {
  271. iounmap(regs);
  272. }
  273. static struct mvs_info *mvs_pci_alloc(struct pci_dev *pdev,
  274. const struct pci_device_id *ent,
  275. struct Scsi_Host *shost, unsigned int id)
  276. {
  277. struct mvs_info *mvi = NULL;
  278. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  279. mvi = kzalloc(sizeof(*mvi) +
  280. (1L << mvs_chips[ent->driver_data].slot_width) *
  281. sizeof(struct mvs_slot_info), GFP_KERNEL);
  282. if (!mvi)
  283. return NULL;
  284. mvi->pdev = pdev;
  285. mvi->dev = &pdev->dev;
  286. mvi->chip_id = ent->driver_data;
  287. mvi->chip = &mvs_chips[mvi->chip_id];
  288. INIT_LIST_HEAD(&mvi->wq_list);
  289. ((struct mvs_prv_info *)sha->lldd_ha)->mvi[id] = mvi;
  290. ((struct mvs_prv_info *)sha->lldd_ha)->n_phy = mvi->chip->n_phy;
  291. mvi->id = id;
  292. mvi->sas = sha;
  293. mvi->shost = shost;
  294. mvi->rsvd_tags = bitmap_zalloc(MVS_RSVD_SLOTS, GFP_KERNEL);
  295. if (!mvi->rsvd_tags)
  296. goto err_out;
  297. if (MVS_CHIP_DISP->chip_ioremap(mvi))
  298. goto err_out;
  299. if (!mvs_alloc(mvi, shost))
  300. return mvi;
  301. err_out:
  302. mvs_free(mvi);
  303. return NULL;
  304. }
  305. static int pci_go_64(struct pci_dev *pdev)
  306. {
  307. int rc;
  308. rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
  309. if (rc) {
  310. rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  311. if (rc) {
  312. dev_printk(KERN_ERR, &pdev->dev,
  313. "32-bit DMA enable failed\n");
  314. return rc;
  315. }
  316. }
  317. return rc;
  318. }
  319. static int mvs_prep_sas_ha_init(struct Scsi_Host *shost,
  320. const struct mvs_chip_info *chip_info)
  321. {
  322. int phy_nr, port_nr; unsigned short core_nr;
  323. struct asd_sas_phy **arr_phy;
  324. struct asd_sas_port **arr_port;
  325. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  326. core_nr = chip_info->n_host;
  327. phy_nr = core_nr * chip_info->n_phy;
  328. port_nr = phy_nr;
  329. memset(sha, 0x00, sizeof(struct sas_ha_struct));
  330. arr_phy = kcalloc(phy_nr, sizeof(void *), GFP_KERNEL);
  331. arr_port = kcalloc(port_nr, sizeof(void *), GFP_KERNEL);
  332. if (!arr_phy || !arr_port)
  333. goto exit_free;
  334. sha->sas_phy = arr_phy;
  335. sha->sas_port = arr_port;
  336. sha->shost = shost;
  337. sha->lldd_ha = kzalloc_obj(struct mvs_prv_info);
  338. if (!sha->lldd_ha)
  339. goto exit_free;
  340. ((struct mvs_prv_info *)sha->lldd_ha)->n_host = core_nr;
  341. shost->transportt = mvs_stt;
  342. shost->max_id = MVS_MAX_DEVICES;
  343. shost->max_lun = ~0;
  344. shost->max_channel = 1;
  345. shost->max_cmd_len = 16;
  346. return 0;
  347. exit_free:
  348. kfree(arr_phy);
  349. kfree(arr_port);
  350. return -1;
  351. }
  352. static void mvs_post_sas_ha_init(struct Scsi_Host *shost,
  353. const struct mvs_chip_info *chip_info)
  354. {
  355. int can_queue, i = 0, j = 0;
  356. struct mvs_info *mvi = NULL;
  357. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  358. unsigned short nr_core = ((struct mvs_prv_info *)sha->lldd_ha)->n_host;
  359. for (j = 0; j < nr_core; j++) {
  360. mvi = ((struct mvs_prv_info *)sha->lldd_ha)->mvi[j];
  361. for (i = 0; i < chip_info->n_phy; i++) {
  362. sha->sas_phy[j * chip_info->n_phy + i] =
  363. &mvi->phy[i].sas_phy;
  364. sha->sas_port[j * chip_info->n_phy + i] =
  365. &mvi->port[i].sas_port;
  366. }
  367. }
  368. sha->sas_ha_name = DRV_NAME;
  369. sha->dev = mvi->dev;
  370. sha->sas_addr = &mvi->sas_addr[0];
  371. sha->num_phys = nr_core * chip_info->n_phy;
  372. if (mvi->flags & MVF_FLAG_SOC)
  373. can_queue = MVS_SOC_CAN_QUEUE;
  374. else
  375. can_queue = MVS_CHIP_SLOT_SZ;
  376. can_queue -= MVS_RSVD_SLOTS;
  377. shost->sg_tablesize = min_t(u16, SG_ALL, MVS_MAX_SG);
  378. shost->can_queue = can_queue;
  379. mvi->shost->cmd_per_lun = MVS_QUEUE_SIZE;
  380. sha->shost = mvi->shost;
  381. }
  382. static void mvs_init_sas_add(struct mvs_info *mvi)
  383. {
  384. u8 i;
  385. for (i = 0; i < mvi->chip->n_phy; i++) {
  386. mvi->phy[i].dev_sas_addr = 0x5005043011ab0000ULL;
  387. mvi->phy[i].dev_sas_addr =
  388. cpu_to_be64((u64)(*(u64 *)&mvi->phy[i].dev_sas_addr));
  389. }
  390. memcpy(mvi->sas_addr, &mvi->phy[0].dev_sas_addr, SAS_ADDR_SIZE);
  391. }
  392. static int mvs_pci_init(struct pci_dev *pdev, const struct pci_device_id *ent)
  393. {
  394. unsigned int rc, nhost = 0;
  395. struct mvs_info *mvi;
  396. irq_handler_t irq_handler = mvs_interrupt;
  397. struct Scsi_Host *shost = NULL;
  398. const struct mvs_chip_info *chip;
  399. dev_printk(KERN_INFO, &pdev->dev,
  400. "mvsas: driver version %s\n", DRV_VERSION);
  401. rc = pci_enable_device(pdev);
  402. if (rc)
  403. goto err_out_enable;
  404. pci_set_master(pdev);
  405. rc = pci_request_regions(pdev, DRV_NAME);
  406. if (rc)
  407. goto err_out_disable;
  408. rc = pci_go_64(pdev);
  409. if (rc)
  410. goto err_out_regions;
  411. shost = scsi_host_alloc(&mvs_sht, sizeof(void *));
  412. if (!shost) {
  413. rc = -ENOMEM;
  414. goto err_out_regions;
  415. }
  416. chip = &mvs_chips[ent->driver_data];
  417. SHOST_TO_SAS_HA(shost) =
  418. kzalloc_objs(struct sas_ha_struct, 1);
  419. if (!SHOST_TO_SAS_HA(shost)) {
  420. scsi_host_put(shost);
  421. rc = -ENOMEM;
  422. goto err_out_regions;
  423. }
  424. rc = mvs_prep_sas_ha_init(shost, chip);
  425. if (rc) {
  426. scsi_host_put(shost);
  427. rc = -ENOMEM;
  428. goto err_out_regions;
  429. }
  430. pci_set_drvdata(pdev, SHOST_TO_SAS_HA(shost));
  431. do {
  432. mvi = mvs_pci_alloc(pdev, ent, shost, nhost);
  433. if (!mvi) {
  434. rc = -ENOMEM;
  435. goto err_out_regions;
  436. }
  437. memset(&mvi->hba_info_param, 0xFF,
  438. sizeof(struct hba_info_page));
  439. mvs_init_sas_add(mvi);
  440. mvi->instance = nhost;
  441. rc = MVS_CHIP_DISP->chip_init(mvi);
  442. if (rc) {
  443. mvs_free(mvi);
  444. goto err_out_regions;
  445. }
  446. nhost++;
  447. } while (nhost < chip->n_host);
  448. #ifdef CONFIG_SCSI_MVSAS_TASKLET
  449. {
  450. struct mvs_prv_info *mpi = SHOST_TO_SAS_HA(shost)->lldd_ha;
  451. tasklet_init(&(mpi->mv_tasklet), mvs_tasklet,
  452. (unsigned long)SHOST_TO_SAS_HA(shost));
  453. }
  454. #endif
  455. mvs_post_sas_ha_init(shost, chip);
  456. rc = scsi_add_host(shost, &pdev->dev);
  457. if (rc)
  458. goto err_out_shost;
  459. rc = sas_register_ha(SHOST_TO_SAS_HA(shost));
  460. if (rc)
  461. goto err_out_shost;
  462. rc = request_irq(pdev->irq, irq_handler, IRQF_SHARED,
  463. DRV_NAME, SHOST_TO_SAS_HA(shost));
  464. if (rc)
  465. goto err_not_sas;
  466. MVS_CHIP_DISP->interrupt_enable(mvi);
  467. scsi_scan_host(mvi->shost);
  468. return 0;
  469. err_not_sas:
  470. sas_unregister_ha(SHOST_TO_SAS_HA(shost));
  471. err_out_shost:
  472. scsi_remove_host(mvi->shost);
  473. err_out_regions:
  474. pci_release_regions(pdev);
  475. err_out_disable:
  476. pci_disable_device(pdev);
  477. err_out_enable:
  478. return rc;
  479. }
  480. static void mvs_pci_remove(struct pci_dev *pdev)
  481. {
  482. unsigned short core_nr, i = 0;
  483. struct sas_ha_struct *sha = pci_get_drvdata(pdev);
  484. struct mvs_info *mvi = NULL;
  485. core_nr = ((struct mvs_prv_info *)sha->lldd_ha)->n_host;
  486. mvi = ((struct mvs_prv_info *)sha->lldd_ha)->mvi[0];
  487. #ifdef CONFIG_SCSI_MVSAS_TASKLET
  488. tasklet_kill(&((struct mvs_prv_info *)sha->lldd_ha)->mv_tasklet);
  489. #endif
  490. sas_unregister_ha(sha);
  491. sas_remove_host(mvi->shost);
  492. MVS_CHIP_DISP->interrupt_disable(mvi);
  493. free_irq(mvi->pdev->irq, sha);
  494. for (i = 0; i < core_nr; i++) {
  495. mvi = ((struct mvs_prv_info *)sha->lldd_ha)->mvi[i];
  496. mvs_free(mvi);
  497. }
  498. kfree(sha->sas_phy);
  499. kfree(sha->sas_port);
  500. kfree(sha);
  501. pci_release_regions(pdev);
  502. pci_disable_device(pdev);
  503. return;
  504. }
  505. static const struct pci_device_id mvs_pci_table[] = {
  506. { PCI_VDEVICE(MARVELL, 0x6320), chip_6320 },
  507. { PCI_VDEVICE(MARVELL, 0x6340), chip_6440 },
  508. {
  509. .vendor = PCI_VENDOR_ID_MARVELL,
  510. .device = 0x6440,
  511. .subvendor = PCI_ANY_ID,
  512. .subdevice = 0x6480,
  513. .class = 0,
  514. .class_mask = 0,
  515. .driver_data = chip_6485,
  516. },
  517. { PCI_VDEVICE(MARVELL, 0x6440), chip_6440 },
  518. { PCI_VDEVICE(MARVELL, 0x6485), chip_6485 },
  519. { PCI_VDEVICE(MARVELL, 0x9480), chip_9480 },
  520. { PCI_VDEVICE(MARVELL, 0x9180), chip_9180 },
  521. { PCI_VDEVICE(ARECA, PCI_DEVICE_ID_ARECA_1300), chip_1300 },
  522. { PCI_VDEVICE(ARECA, PCI_DEVICE_ID_ARECA_1320), chip_1320 },
  523. { PCI_VDEVICE(ADAPTEC2, 0x0450), chip_6440 },
  524. { PCI_VDEVICE(TTI, 0x2640), chip_6440 },
  525. { PCI_VDEVICE(TTI, 0x2710), chip_9480 },
  526. { PCI_VDEVICE(TTI, 0x2720), chip_9480 },
  527. { PCI_VDEVICE(TTI, 0x2721), chip_9480 },
  528. { PCI_VDEVICE(TTI, 0x2722), chip_9480 },
  529. { PCI_VDEVICE(TTI, 0x2740), chip_9480 },
  530. { PCI_VDEVICE(TTI, 0x2744), chip_9480 },
  531. { PCI_VDEVICE(TTI, 0x2760), chip_9480 },
  532. {
  533. .vendor = PCI_VENDOR_ID_MARVELL_EXT,
  534. .device = 0x9480,
  535. .subvendor = PCI_ANY_ID,
  536. .subdevice = 0x9480,
  537. .class = 0,
  538. .class_mask = 0,
  539. .driver_data = chip_9480,
  540. },
  541. {
  542. .vendor = PCI_VENDOR_ID_MARVELL_EXT,
  543. .device = 0x9445,
  544. .subvendor = PCI_ANY_ID,
  545. .subdevice = 0x9480,
  546. .class = 0,
  547. .class_mask = 0,
  548. .driver_data = chip_9445,
  549. },
  550. { PCI_VDEVICE(MARVELL_EXT, 0x9485), chip_9485 }, /* Marvell 9480/9485 (any vendor/model) */
  551. { PCI_VDEVICE(OCZ, 0x1021), chip_9485}, /* OCZ RevoDrive3 */
  552. { PCI_VDEVICE(OCZ, 0x1022), chip_9485}, /* OCZ RevoDrive3/zDriveR4 (exact model unknown) */
  553. { PCI_VDEVICE(OCZ, 0x1040), chip_9485}, /* OCZ RevoDrive3/zDriveR4 (exact model unknown) */
  554. { PCI_VDEVICE(OCZ, 0x1041), chip_9485}, /* OCZ RevoDrive3/zDriveR4 (exact model unknown) */
  555. { PCI_VDEVICE(OCZ, 0x1042), chip_9485}, /* OCZ RevoDrive3/zDriveR4 (exact model unknown) */
  556. { PCI_VDEVICE(OCZ, 0x1043), chip_9485}, /* OCZ RevoDrive3/zDriveR4 (exact model unknown) */
  557. { PCI_VDEVICE(OCZ, 0x1044), chip_9485}, /* OCZ RevoDrive3/zDriveR4 (exact model unknown) */
  558. { PCI_VDEVICE(OCZ, 0x1080), chip_9485}, /* OCZ RevoDrive3/zDriveR4 (exact model unknown) */
  559. { PCI_VDEVICE(OCZ, 0x1083), chip_9485}, /* OCZ RevoDrive3/zDriveR4 (exact model unknown) */
  560. { PCI_VDEVICE(OCZ, 0x1084), chip_9485}, /* OCZ RevoDrive3/zDriveR4 (exact model unknown) */
  561. { } /* terminate list */
  562. };
  563. static struct pci_driver mvs_pci_driver = {
  564. .name = DRV_NAME,
  565. .id_table = mvs_pci_table,
  566. .probe = mvs_pci_init,
  567. .remove = mvs_pci_remove,
  568. };
  569. static DEVICE_STRING_ATTR_RO(driver_version, 0444, DRV_VERSION);
  570. static ssize_t interrupt_coalescing_store(struct device *cdev,
  571. struct device_attribute *attr,
  572. const char *buffer, size_t size)
  573. {
  574. unsigned int val = 0;
  575. struct mvs_info *mvi = NULL;
  576. struct Scsi_Host *shost = class_to_shost(cdev);
  577. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  578. u8 i, core_nr;
  579. if (buffer == NULL)
  580. return size;
  581. if (sscanf(buffer, "%u", &val) != 1)
  582. return -EINVAL;
  583. if (val >= 0x10000) {
  584. mv_dprintk("interrupt coalescing timer %d us is"
  585. "too long\n", val);
  586. return strlen(buffer);
  587. }
  588. interrupt_coalescing = val;
  589. core_nr = ((struct mvs_prv_info *)sha->lldd_ha)->n_host;
  590. mvi = ((struct mvs_prv_info *)sha->lldd_ha)->mvi[0];
  591. if (unlikely(!mvi))
  592. return -EINVAL;
  593. for (i = 0; i < core_nr; i++) {
  594. mvi = ((struct mvs_prv_info *)sha->lldd_ha)->mvi[i];
  595. if (MVS_CHIP_DISP->tune_interrupt)
  596. MVS_CHIP_DISP->tune_interrupt(mvi,
  597. interrupt_coalescing);
  598. }
  599. mv_dprintk("set interrupt coalescing time to %d us\n",
  600. interrupt_coalescing);
  601. return strlen(buffer);
  602. }
  603. static ssize_t interrupt_coalescing_show(struct device *cdev,
  604. struct device_attribute *attr, char *buffer)
  605. {
  606. return sysfs_emit(buffer, "%d\n", interrupt_coalescing);
  607. }
  608. static DEVICE_ATTR_RW(interrupt_coalescing);
  609. static int __init mvs_init(void)
  610. {
  611. int rc;
  612. mvs_stt = sas_domain_attach_transport(&mvs_transport_ops);
  613. if (!mvs_stt)
  614. return -ENOMEM;
  615. rc = pci_register_driver(&mvs_pci_driver);
  616. if (rc)
  617. goto err_out;
  618. return 0;
  619. err_out:
  620. sas_release_transport(mvs_stt);
  621. return rc;
  622. }
  623. static void __exit mvs_exit(void)
  624. {
  625. pci_unregister_driver(&mvs_pci_driver);
  626. sas_release_transport(mvs_stt);
  627. }
  628. static struct attribute *mvst_host_attrs[] = {
  629. &dev_attr_driver_version.attr.attr,
  630. &dev_attr_interrupt_coalescing.attr,
  631. NULL,
  632. };
  633. ATTRIBUTE_GROUPS(mvst_host);
  634. static const struct attribute_group *mvst_sdev_groups[] = {
  635. &sas_ata_sdev_attr_group,
  636. NULL
  637. };
  638. module_init(mvs_init);
  639. module_exit(mvs_exit);
  640. MODULE_AUTHOR("Jeff Garzik <jgarzik@pobox.com>");
  641. MODULE_DESCRIPTION("Marvell 88SE6440 SAS/SATA controller driver");
  642. MODULE_VERSION(DRV_VERSION);
  643. MODULE_LICENSE("GPL");
  644. #ifdef CONFIG_PCI
  645. MODULE_DEVICE_TABLE(pci, mvs_pci_table);
  646. #endif