mv_init.c 21 KB

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