mv_init.c 21 KB

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