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