mv_init.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829
  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, 9, &mvs_64xx_dispatch, },
  38. [chip_6440] = { 1, 4, 0x400, 17, 16, 9, &mvs_64xx_dispatch, },
  39. [chip_6485] = { 1, 8, 0x800, 33, 32, 10, &mvs_64xx_dispatch, },
  40. [chip_9180] = { 2, 4, 0x800, 17, 64, 9, &mvs_94xx_dispatch, },
  41. [chip_9480] = { 2, 4, 0x800, 17, 64, 9, &mvs_94xx_dispatch, },
  42. [chip_9445] = { 1, 4, 0x800, 17, 64, 11, &mvs_94xx_dispatch, },
  43. [chip_9485] = { 2, 4, 0x800, 17, 64, 11, &mvs_94xx_dispatch, },
  44. [chip_1300] = { 1, 4, 0x400, 17, 16, 9, &mvs_64xx_dispatch, },
  45. [chip_1320] = { 2, 4, 0x800, 17, 64, 9, &mvs_94xx_dispatch, },
  46. };
  47. struct device_attribute *mvst_host_attrs[];
  48. #define SOC_SAS_NUM 2
  49. #define SG_MX 64
  50. static struct scsi_host_template mvs_sht = {
  51. .module = THIS_MODULE,
  52. .name = DRV_NAME,
  53. .queuecommand = sas_queuecommand,
  54. .target_alloc = sas_target_alloc,
  55. .slave_configure = mvs_slave_configure,
  56. .slave_destroy = sas_slave_destroy,
  57. .scan_finished = mvs_scan_finished,
  58. .scan_start = mvs_scan_start,
  59. .change_queue_depth = sas_change_queue_depth,
  60. .change_queue_type = sas_change_queue_type,
  61. .bios_param = sas_bios_param,
  62. .can_queue = 1,
  63. .cmd_per_lun = 1,
  64. .this_id = -1,
  65. .sg_tablesize = SG_MX,
  66. .max_sectors = SCSI_DEFAULT_MAX_SECTORS,
  67. .use_clustering = ENABLE_CLUSTERING,
  68. .eh_device_reset_handler = sas_eh_device_reset_handler,
  69. .eh_bus_reset_handler = sas_eh_bus_reset_handler,
  70. .slave_alloc = mvs_slave_alloc,
  71. .target_destroy = sas_target_destroy,
  72. .ioctl = sas_ioctl,
  73. .shost_attrs = mvst_host_attrs,
  74. };
  75. static struct sas_domain_function_template mvs_transport_ops = {
  76. .lldd_dev_found = mvs_dev_found,
  77. .lldd_dev_gone = mvs_dev_gone,
  78. .lldd_execute_task = mvs_queue_command,
  79. .lldd_control_phy = mvs_phy_control,
  80. .lldd_abort_task = mvs_abort_task,
  81. .lldd_abort_task_set = mvs_abort_task_set,
  82. .lldd_clear_aca = mvs_clear_aca,
  83. .lldd_clear_task_set = mvs_clear_task_set,
  84. .lldd_I_T_nexus_reset = mvs_I_T_nexus_reset,
  85. .lldd_lu_reset = mvs_lu_reset,
  86. .lldd_query_task = mvs_query_task,
  87. .lldd_port_formed = mvs_port_formed,
  88. .lldd_port_deformed = mvs_port_deformed,
  89. };
  90. static void __devinit mvs_phy_init(struct mvs_info *mvi, int phy_id)
  91. {
  92. struct mvs_phy *phy = &mvi->phy[phy_id];
  93. struct asd_sas_phy *sas_phy = &phy->sas_phy;
  94. phy->mvi = mvi;
  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_SLOTS;
  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. #ifndef DISABLE_HOTPLUG_DMA_FIX
  138. if (mvi->bulk_buffer)
  139. dma_free_coherent(mvi->dev, TRASH_BUCKET_SIZE,
  140. mvi->bulk_buffer, mvi->bulk_buffer_dma);
  141. #endif
  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);
  148. }
  149. #ifdef MVS_USE_TASKLET
  150. struct tasklet_struct mv_tasklet;
  151. static void mvs_tasklet(unsigned long opaque)
  152. {
  153. unsigned long flags;
  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. for (i = 0; i < core_nr; i++) {
  163. mvi = ((struct mvs_prv_info *)sha->lldd_ha)->mvi[i];
  164. stat = MVS_CHIP_DISP->isr_status(mvi, mvi->irq);
  165. if (stat)
  166. MVS_CHIP_DISP->isr(mvi, mvi->irq, stat);
  167. }
  168. }
  169. #endif
  170. static irqreturn_t mvs_interrupt(int irq, void *opaque)
  171. {
  172. u32 core_nr, i = 0;
  173. u32 stat;
  174. struct mvs_info *mvi;
  175. struct sas_ha_struct *sha = opaque;
  176. core_nr = ((struct mvs_prv_info *)sha->lldd_ha)->n_host;
  177. mvi = ((struct mvs_prv_info *)sha->lldd_ha)->mvi[0];
  178. if (unlikely(!mvi))
  179. return IRQ_NONE;
  180. stat = MVS_CHIP_DISP->isr_status(mvi, irq);
  181. if (!stat)
  182. return IRQ_NONE;
  183. #ifdef MVS_USE_TASKLET
  184. tasklet_schedule(&mv_tasklet);
  185. #else
  186. for (i = 0; i < core_nr; i++) {
  187. mvi = ((struct mvs_prv_info *)sha->lldd_ha)->mvi[i];
  188. MVS_CHIP_DISP->isr(mvi, irq, stat);
  189. }
  190. #endif
  191. return IRQ_HANDLED;
  192. }
  193. static int __devinit mvs_alloc(struct mvs_info *mvi, struct Scsi_Host *shost)
  194. {
  195. int i = 0, slot_nr;
  196. char pool_name[32];
  197. if (mvi->flags & MVF_FLAG_SOC)
  198. slot_nr = MVS_SOC_SLOTS;
  199. else
  200. slot_nr = MVS_SLOTS;
  201. spin_lock_init(&mvi->lock);
  202. for (i = 0; i < mvi->chip->n_phy; i++) {
  203. mvs_phy_init(mvi, i);
  204. mvi->port[i].wide_port_phymap = 0;
  205. mvi->port[i].port_attached = 0;
  206. INIT_LIST_HEAD(&mvi->port[i].list);
  207. }
  208. for (i = 0; i < MVS_MAX_DEVICES; i++) {
  209. mvi->devices[i].taskfileset = MVS_ID_NOT_MAPPED;
  210. mvi->devices[i].dev_type = NO_DEVICE;
  211. mvi->devices[i].device_id = i;
  212. mvi->devices[i].dev_status = MVS_DEV_NORMAL;
  213. init_timer(&mvi->devices[i].timer);
  214. }
  215. /*
  216. * alloc and init our DMA areas
  217. */
  218. mvi->tx = dma_alloc_coherent(mvi->dev,
  219. sizeof(*mvi->tx) * MVS_CHIP_SLOT_SZ,
  220. &mvi->tx_dma, GFP_KERNEL);
  221. if (!mvi->tx)
  222. goto err_out;
  223. memset(mvi->tx, 0, sizeof(*mvi->tx) * MVS_CHIP_SLOT_SZ);
  224. mvi->rx_fis = dma_alloc_coherent(mvi->dev, MVS_RX_FISL_SZ,
  225. &mvi->rx_fis_dma, GFP_KERNEL);
  226. if (!mvi->rx_fis)
  227. goto err_out;
  228. memset(mvi->rx_fis, 0, MVS_RX_FISL_SZ);
  229. mvi->rx = dma_alloc_coherent(mvi->dev,
  230. sizeof(*mvi->rx) * (MVS_RX_RING_SZ + 1),
  231. &mvi->rx_dma, GFP_KERNEL);
  232. if (!mvi->rx)
  233. goto err_out;
  234. memset(mvi->rx, 0, sizeof(*mvi->rx) * (MVS_RX_RING_SZ + 1));
  235. mvi->rx[0] = cpu_to_le32(0xfff);
  236. mvi->rx_cons = 0xfff;
  237. mvi->slot = dma_alloc_coherent(mvi->dev,
  238. sizeof(*mvi->slot) * slot_nr,
  239. &mvi->slot_dma, GFP_KERNEL);
  240. if (!mvi->slot)
  241. goto err_out;
  242. memset(mvi->slot, 0, sizeof(*mvi->slot) * slot_nr);
  243. #ifndef DISABLE_HOTPLUG_DMA_FIX
  244. mvi->bulk_buffer = dma_alloc_coherent(mvi->dev,
  245. TRASH_BUCKET_SIZE,
  246. &mvi->bulk_buffer_dma, GFP_KERNEL);
  247. if (!mvi->bulk_buffer)
  248. goto err_out;
  249. #endif
  250. sprintf(pool_name, "%s%d", "mvs_dma_pool", mvi->id);
  251. mvi->dma_pool = pci_pool_create(pool_name, mvi->pdev, MVS_SLOT_BUF_SZ, 16, 0);
  252. if (!mvi->dma_pool) {
  253. printk(KERN_DEBUG "failed to create dma pool %s.\n", pool_name);
  254. goto err_out;
  255. }
  256. mvi->tags_num = slot_nr;
  257. /* Initialize tags */
  258. mvs_tag_init(mvi);
  259. return 0;
  260. err_out:
  261. return 1;
  262. }
  263. int mvs_ioremap(struct mvs_info *mvi, int bar, int bar_ex)
  264. {
  265. unsigned long res_start, res_len, res_flag, res_flag_ex = 0;
  266. struct pci_dev *pdev = mvi->pdev;
  267. if (bar_ex != -1) {
  268. /*
  269. * ioremap main and peripheral registers
  270. */
  271. res_start = pci_resource_start(pdev, bar_ex);
  272. res_len = pci_resource_len(pdev, bar_ex);
  273. if (!res_start || !res_len)
  274. goto err_out;
  275. res_flag_ex = pci_resource_flags(pdev, bar_ex);
  276. if (res_flag_ex & IORESOURCE_MEM) {
  277. if (res_flag_ex & IORESOURCE_CACHEABLE)
  278. mvi->regs_ex = ioremap(res_start, res_len);
  279. else
  280. mvi->regs_ex = ioremap_nocache(res_start,
  281. res_len);
  282. } else
  283. mvi->regs_ex = (void *)res_start;
  284. if (!mvi->regs_ex)
  285. goto err_out;
  286. }
  287. res_start = pci_resource_start(pdev, bar);
  288. res_len = pci_resource_len(pdev, bar);
  289. if (!res_start || !res_len)
  290. goto err_out;
  291. res_flag = pci_resource_flags(pdev, bar);
  292. if (res_flag & IORESOURCE_CACHEABLE)
  293. mvi->regs = ioremap(res_start, res_len);
  294. else
  295. mvi->regs = ioremap_nocache(res_start, res_len);
  296. if (!mvi->regs) {
  297. if (mvi->regs_ex && (res_flag_ex & IORESOURCE_MEM))
  298. iounmap(mvi->regs_ex);
  299. mvi->regs_ex = NULL;
  300. goto err_out;
  301. }
  302. return 0;
  303. err_out:
  304. return -1;
  305. }
  306. void mvs_iounmap(void __iomem *regs)
  307. {
  308. iounmap(regs);
  309. }
  310. static struct mvs_info *__devinit mvs_pci_alloc(struct pci_dev *pdev,
  311. const struct pci_device_id *ent,
  312. struct Scsi_Host *shost, unsigned int id)
  313. {
  314. struct mvs_info *mvi;
  315. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  316. mvi = kzalloc(sizeof(*mvi) + MVS_SLOTS * sizeof(struct mvs_slot_info),
  317. GFP_KERNEL);
  318. if (!mvi)
  319. return NULL;
  320. mvi->pdev = pdev;
  321. mvi->dev = &pdev->dev;
  322. mvi->chip_id = ent->driver_data;
  323. mvi->chip = &mvs_chips[mvi->chip_id];
  324. INIT_LIST_HEAD(&mvi->wq_list);
  325. mvi->irq = pdev->irq;
  326. ((struct mvs_prv_info *)sha->lldd_ha)->mvi[id] = mvi;
  327. ((struct mvs_prv_info *)sha->lldd_ha)->n_phy = mvi->chip->n_phy;
  328. mvi->id = id;
  329. mvi->sas = sha;
  330. mvi->shost = shost;
  331. #ifdef MVS_USE_TASKLET
  332. tasklet_init(&mv_tasklet, mvs_tasklet, (unsigned long)sha);
  333. #endif
  334. if (MVS_CHIP_DISP->chip_ioremap(mvi))
  335. goto err_out;
  336. if (!mvs_alloc(mvi, shost))
  337. return mvi;
  338. err_out:
  339. mvs_free(mvi);
  340. return NULL;
  341. }
  342. /* move to PCI layer or libata core? */
  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 __devinit 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 = 128;
  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 __devinit 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. sha->lldd_max_execute_num = lldd_max_execute_num;
  427. if (mvi->flags & MVF_FLAG_SOC)
  428. can_queue = MVS_SOC_CAN_QUEUE;
  429. else
  430. can_queue = MVS_CAN_QUEUE;
  431. sha->lldd_queue_size = can_queue;
  432. shost->can_queue = can_queue;
  433. mvi->shost->cmd_per_lun = MVS_SLOTS/sha->num_phys;
  434. sha->core.shost = mvi->shost;
  435. }
  436. static void mvs_init_sas_add(struct mvs_info *mvi)
  437. {
  438. u8 i;
  439. for (i = 0; i < mvi->chip->n_phy; i++) {
  440. mvi->phy[i].dev_sas_addr = 0x5005043011ab0000ULL;
  441. mvi->phy[i].dev_sas_addr =
  442. cpu_to_be64((u64)(*(u64 *)&mvi->phy[i].dev_sas_addr));
  443. }
  444. memcpy(mvi->sas_addr, &mvi->phy[0].dev_sas_addr, SAS_ADDR_SIZE);
  445. }
  446. static int __devinit mvs_pci_init(struct pci_dev *pdev,
  447. const struct pci_device_id *ent)
  448. {
  449. unsigned int rc, nhost = 0;
  450. struct mvs_info *mvi;
  451. irq_handler_t irq_handler = mvs_interrupt;
  452. struct Scsi_Host *shost = NULL;
  453. const struct mvs_chip_info *chip;
  454. dev_printk(KERN_INFO, &pdev->dev,
  455. "mvsas: driver version %s\n", DRV_VERSION);
  456. rc = pci_enable_device(pdev);
  457. if (rc)
  458. goto err_out_enable;
  459. pci_set_master(pdev);
  460. rc = pci_request_regions(pdev, DRV_NAME);
  461. if (rc)
  462. goto err_out_disable;
  463. rc = pci_go_64(pdev);
  464. if (rc)
  465. goto err_out_regions;
  466. shost = scsi_host_alloc(&mvs_sht, sizeof(void *));
  467. if (!shost) {
  468. rc = -ENOMEM;
  469. goto err_out_regions;
  470. }
  471. chip = &mvs_chips[ent->driver_data];
  472. SHOST_TO_SAS_HA(shost) =
  473. kcalloc(1, sizeof(struct sas_ha_struct), GFP_KERNEL);
  474. if (!SHOST_TO_SAS_HA(shost)) {
  475. kfree(shost);
  476. rc = -ENOMEM;
  477. goto err_out_regions;
  478. }
  479. rc = mvs_prep_sas_ha_init(shost, chip);
  480. if (rc) {
  481. kfree(shost);
  482. rc = -ENOMEM;
  483. goto err_out_regions;
  484. }
  485. pci_set_drvdata(pdev, SHOST_TO_SAS_HA(shost));
  486. do {
  487. mvi = mvs_pci_alloc(pdev, ent, shost, nhost);
  488. if (!mvi) {
  489. rc = -ENOMEM;
  490. goto err_out_regions;
  491. }
  492. memset(&mvi->hba_info_param, 0xFF,
  493. sizeof(struct hba_info_page));
  494. mvs_init_sas_add(mvi);
  495. mvi->instance = nhost;
  496. rc = MVS_CHIP_DISP->chip_init(mvi);
  497. if (rc) {
  498. mvs_free(mvi);
  499. goto err_out_regions;
  500. }
  501. nhost++;
  502. } while (nhost < chip->n_host);
  503. #ifdef MVS_USE_TASKLET
  504. tasklet_init(&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 __devexit 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 MVS_USE_TASKLET
  540. tasklet_kill(&mv_tasklet);
  541. #endif
  542. pci_set_drvdata(pdev, NULL);
  543. sas_unregister_ha(sha);
  544. sas_remove_host(mvi->shost);
  545. scsi_remove_host(mvi->shost);
  546. MVS_CHIP_DISP->interrupt_disable(mvi);
  547. free_irq(mvi->irq, sha);
  548. for (i = 0; i < core_nr; i++) {
  549. mvi = ((struct mvs_prv_info *)sha->lldd_ha)->mvi[i];
  550. mvs_free(mvi);
  551. }
  552. kfree(sha->sas_phy);
  553. kfree(sha->sas_port);
  554. kfree(sha);
  555. pci_release_regions(pdev);
  556. pci_disable_device(pdev);
  557. return;
  558. }
  559. static struct pci_device_id __devinitdata mvs_pci_table[] = {
  560. { PCI_VDEVICE(MARVELL, 0x6320), chip_6320 },
  561. { PCI_VDEVICE(MARVELL, 0x6340), chip_6440 },
  562. {
  563. .vendor = PCI_VENDOR_ID_MARVELL,
  564. .device = 0x6440,
  565. .subvendor = PCI_ANY_ID,
  566. .subdevice = 0x6480,
  567. .class = 0,
  568. .class_mask = 0,
  569. .driver_data = chip_6485,
  570. },
  571. { PCI_VDEVICE(MARVELL, 0x6440), chip_6440 },
  572. { PCI_VDEVICE(MARVELL, 0x6485), chip_6485 },
  573. { PCI_VDEVICE(MARVELL, 0x9480), chip_9480 },
  574. { PCI_VDEVICE(MARVELL, 0x9180), chip_9180 },
  575. { PCI_VDEVICE(ARECA, PCI_DEVICE_ID_ARECA_1300), chip_1300 },
  576. { PCI_VDEVICE(ARECA, PCI_DEVICE_ID_ARECA_1320), chip_1320 },
  577. { PCI_VDEVICE(ADAPTEC2, 0x0450), chip_6440 },
  578. { PCI_VDEVICE(TTI, 0x2710), chip_9480 },
  579. { PCI_VDEVICE(TTI, 0x2720), chip_9480 },
  580. { PCI_VDEVICE(TTI, 0x2721), chip_9480 },
  581. { PCI_VDEVICE(TTI, 0x2722), chip_9480 },
  582. { PCI_VDEVICE(TTI, 0x2740), chip_9480 },
  583. { PCI_VDEVICE(TTI, 0x2744), chip_9480 },
  584. { PCI_VDEVICE(TTI, 0x2760), chip_9480 },
  585. {
  586. .vendor = 0x1b4b,
  587. .device = 0x9445,
  588. .subvendor = PCI_ANY_ID,
  589. .subdevice = 0x9480,
  590. .class = 0,
  591. .class_mask = 0,
  592. .driver_data = chip_9445,
  593. },
  594. {
  595. .vendor = 0x1b4b,
  596. .device = 0x9485,
  597. .subvendor = PCI_ANY_ID,
  598. .subdevice = 0x9480,
  599. .class = 0,
  600. .class_mask = 0,
  601. .driver_data = chip_9485,
  602. },
  603. { } /* terminate list */
  604. };
  605. static struct pci_driver mvs_pci_driver = {
  606. .name = DRV_NAME,
  607. .id_table = mvs_pci_table,
  608. .probe = mvs_pci_init,
  609. .remove = __devexit_p(mvs_pci_remove),
  610. };
  611. static ssize_t
  612. mvs_show_driver_version(struct device *cdev,
  613. struct device_attribute *attr, char *buffer)
  614. {
  615. return snprintf(buffer, PAGE_SIZE, "%s\n", DRV_VERSION);
  616. }
  617. static DEVICE_ATTR(driver_version,
  618. S_IRUGO,
  619. mvs_show_driver_version,
  620. NULL);
  621. static ssize_t
  622. mvs_store_interrupt_coalescing(struct device *cdev,
  623. struct device_attribute *attr,
  624. const char *buffer, size_t size)
  625. {
  626. int val = 0;
  627. struct mvs_info *mvi = NULL;
  628. struct Scsi_Host *shost = class_to_shost(cdev);
  629. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  630. u8 i, core_nr;
  631. if (buffer == NULL)
  632. return size;
  633. if (sscanf(buffer, "%d", &val) != 1)
  634. return -EINVAL;
  635. if (val >= 0x10000) {
  636. mv_dprintk("interrupt coalescing timer %d us is"
  637. "too long\n", val);
  638. return strlen(buffer);
  639. }
  640. interrupt_coalescing = val;
  641. core_nr = ((struct mvs_prv_info *)sha->lldd_ha)->n_host;
  642. mvi = ((struct mvs_prv_info *)sha->lldd_ha)->mvi[0];
  643. if (unlikely(!mvi))
  644. return -EINVAL;
  645. for (i = 0; i < core_nr; i++) {
  646. mvi = ((struct mvs_prv_info *)sha->lldd_ha)->mvi[i];
  647. if (MVS_CHIP_DISP->tune_interrupt)
  648. MVS_CHIP_DISP->tune_interrupt(mvi,
  649. interrupt_coalescing);
  650. }
  651. mv_dprintk("set interrupt coalescing time to %d us\n",
  652. interrupt_coalescing);
  653. return strlen(buffer);
  654. }
  655. static ssize_t mvs_show_interrupt_coalescing(struct device *cdev,
  656. struct device_attribute *attr, char *buffer)
  657. {
  658. return snprintf(buffer, PAGE_SIZE, "%d\n", interrupt_coalescing);
  659. }
  660. static DEVICE_ATTR(interrupt_coalescing,
  661. S_IRUGO|S_IWUSR,
  662. mvs_show_interrupt_coalescing,
  663. mvs_store_interrupt_coalescing);
  664. /* task handler */
  665. struct task_struct *mvs_th;
  666. static int __init mvs_init(void)
  667. {
  668. int rc;
  669. mvs_stt = sas_domain_attach_transport(&mvs_transport_ops);
  670. if (!mvs_stt)
  671. return -ENOMEM;
  672. mvs_task_list_cache = kmem_cache_create("mvs_task_list", sizeof(struct mvs_task_list),
  673. 0, SLAB_HWCACHE_ALIGN, NULL);
  674. if (!mvs_task_list_cache) {
  675. rc = -ENOMEM;
  676. mv_printk("%s: mvs_task_list_cache alloc failed! \n", __func__);
  677. goto err_out;
  678. }
  679. rc = pci_register_driver(&mvs_pci_driver);
  680. if (rc)
  681. goto err_out;
  682. return 0;
  683. err_out:
  684. sas_release_transport(mvs_stt);
  685. return rc;
  686. }
  687. static void __exit mvs_exit(void)
  688. {
  689. pci_unregister_driver(&mvs_pci_driver);
  690. sas_release_transport(mvs_stt);
  691. kmem_cache_destroy(mvs_task_list_cache);
  692. }
  693. struct device_attribute *mvst_host_attrs[] = {
  694. &dev_attr_driver_version,
  695. &dev_attr_interrupt_coalescing,
  696. NULL,
  697. };
  698. module_init(mvs_init);
  699. module_exit(mvs_exit);
  700. MODULE_AUTHOR("Jeff Garzik <jgarzik@pobox.com>");
  701. MODULE_DESCRIPTION("Marvell 88SE6440 SAS/SATA controller driver");
  702. MODULE_VERSION(DRV_VERSION);
  703. MODULE_LICENSE("GPL");
  704. #ifdef CONFIG_PCI
  705. MODULE_DEVICE_TABLE(pci, mvs_pci_table);
  706. #endif