mv_init.c 22 KB

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