csio_init.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290
  1. /*
  2. * This file is part of the Chelsio FCoE driver for Linux.
  3. *
  4. * Copyright (c) 2008-2012 Chelsio Communications, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. */
  34. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  35. #include <linux/kernel.h>
  36. #include <linux/module.h>
  37. #include <linux/init.h>
  38. #include <linux/pci.h>
  39. #include <linux/aer.h>
  40. #include <linux/mm.h>
  41. #include <linux/notifier.h>
  42. #include <linux/kdebug.h>
  43. #include <linux/seq_file.h>
  44. #include <linux/debugfs.h>
  45. #include <linux/string.h>
  46. #include <linux/export.h>
  47. #include "csio_init.h"
  48. #include "csio_defs.h"
  49. #define CSIO_MIN_MEMPOOL_SZ 64
  50. static struct dentry *csio_debugfs_root;
  51. static struct scsi_transport_template *csio_fcoe_transport;
  52. static struct scsi_transport_template *csio_fcoe_transport_vport;
  53. /*
  54. * debugfs support
  55. */
  56. static ssize_t
  57. csio_mem_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
  58. {
  59. loff_t pos = *ppos;
  60. loff_t avail = file_inode(file)->i_size;
  61. unsigned int mem = (uintptr_t)file->private_data & 3;
  62. struct csio_hw *hw = file->private_data - mem;
  63. if (pos < 0)
  64. return -EINVAL;
  65. if (pos >= avail)
  66. return 0;
  67. if (count > avail - pos)
  68. count = avail - pos;
  69. while (count) {
  70. size_t len;
  71. int ret, ofst;
  72. __be32 data[16];
  73. if (mem == MEM_MC)
  74. ret = hw->chip_ops->chip_mc_read(hw, 0, pos,
  75. data, NULL);
  76. else
  77. ret = hw->chip_ops->chip_edc_read(hw, mem, pos,
  78. data, NULL);
  79. if (ret)
  80. return ret;
  81. ofst = pos % sizeof(data);
  82. len = min(count, sizeof(data) - ofst);
  83. if (copy_to_user(buf, (u8 *)data + ofst, len))
  84. return -EFAULT;
  85. buf += len;
  86. pos += len;
  87. count -= len;
  88. }
  89. count = pos - *ppos;
  90. *ppos = pos;
  91. return count;
  92. }
  93. static const struct file_operations csio_mem_debugfs_fops = {
  94. .owner = THIS_MODULE,
  95. .open = simple_open,
  96. .read = csio_mem_read,
  97. .llseek = default_llseek,
  98. };
  99. void csio_add_debugfs_mem(struct csio_hw *hw, const char *name,
  100. unsigned int idx, unsigned int size_mb)
  101. {
  102. struct dentry *de;
  103. de = debugfs_create_file(name, S_IRUSR, hw->debugfs_root,
  104. (void *)hw + idx, &csio_mem_debugfs_fops);
  105. if (de && de->d_inode)
  106. de->d_inode->i_size = size_mb << 20;
  107. }
  108. static int csio_setup_debugfs(struct csio_hw *hw)
  109. {
  110. int i;
  111. if (IS_ERR_OR_NULL(hw->debugfs_root))
  112. return -1;
  113. i = csio_rd_reg32(hw, MA_TARGET_MEM_ENABLE);
  114. if (i & EDRAM0_ENABLE)
  115. csio_add_debugfs_mem(hw, "edc0", MEM_EDC0, 5);
  116. if (i & EDRAM1_ENABLE)
  117. csio_add_debugfs_mem(hw, "edc1", MEM_EDC1, 5);
  118. hw->chip_ops->chip_dfs_create_ext_mem(hw);
  119. return 0;
  120. }
  121. /*
  122. * csio_dfs_create - Creates and sets up per-hw debugfs.
  123. *
  124. */
  125. static int
  126. csio_dfs_create(struct csio_hw *hw)
  127. {
  128. if (csio_debugfs_root) {
  129. hw->debugfs_root = debugfs_create_dir(pci_name(hw->pdev),
  130. csio_debugfs_root);
  131. csio_setup_debugfs(hw);
  132. }
  133. return 0;
  134. }
  135. /*
  136. * csio_dfs_destroy - Destroys per-hw debugfs.
  137. */
  138. static int
  139. csio_dfs_destroy(struct csio_hw *hw)
  140. {
  141. if (hw->debugfs_root)
  142. debugfs_remove_recursive(hw->debugfs_root);
  143. return 0;
  144. }
  145. /*
  146. * csio_dfs_init - Debug filesystem initialization for the module.
  147. *
  148. */
  149. static int
  150. csio_dfs_init(void)
  151. {
  152. csio_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
  153. if (!csio_debugfs_root)
  154. pr_warn("Could not create debugfs entry, continuing\n");
  155. return 0;
  156. }
  157. /*
  158. * csio_dfs_exit - debugfs cleanup for the module.
  159. */
  160. static void
  161. csio_dfs_exit(void)
  162. {
  163. debugfs_remove(csio_debugfs_root);
  164. }
  165. /*
  166. * csio_pci_init - PCI initialization.
  167. * @pdev: PCI device.
  168. * @bars: Bitmask of bars to be requested.
  169. *
  170. * Initializes the PCI function by enabling MMIO, setting bus
  171. * mastership and setting DMA mask.
  172. */
  173. static int
  174. csio_pci_init(struct pci_dev *pdev, int *bars)
  175. {
  176. int rv = -ENODEV;
  177. *bars = pci_select_bars(pdev, IORESOURCE_MEM);
  178. if (pci_enable_device_mem(pdev))
  179. goto err;
  180. if (pci_request_selected_regions(pdev, *bars, KBUILD_MODNAME))
  181. goto err_disable_device;
  182. pci_set_master(pdev);
  183. pci_try_set_mwi(pdev);
  184. if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
  185. pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
  186. } else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
  187. pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  188. } else {
  189. dev_err(&pdev->dev, "No suitable DMA available.\n");
  190. goto err_release_regions;
  191. }
  192. return 0;
  193. err_release_regions:
  194. pci_release_selected_regions(pdev, *bars);
  195. err_disable_device:
  196. pci_disable_device(pdev);
  197. err:
  198. return rv;
  199. }
  200. /*
  201. * csio_pci_exit - PCI unitialization.
  202. * @pdev: PCI device.
  203. * @bars: Bars to be released.
  204. *
  205. */
  206. static void
  207. csio_pci_exit(struct pci_dev *pdev, int *bars)
  208. {
  209. pci_release_selected_regions(pdev, *bars);
  210. pci_disable_device(pdev);
  211. }
  212. /*
  213. * csio_hw_init_workers - Initialize the HW module's worker threads.
  214. * @hw: HW module.
  215. *
  216. */
  217. static void
  218. csio_hw_init_workers(struct csio_hw *hw)
  219. {
  220. INIT_WORK(&hw->evtq_work, csio_evtq_worker);
  221. }
  222. static void
  223. csio_hw_exit_workers(struct csio_hw *hw)
  224. {
  225. cancel_work_sync(&hw->evtq_work);
  226. flush_scheduled_work();
  227. }
  228. static int
  229. csio_create_queues(struct csio_hw *hw)
  230. {
  231. int i, j;
  232. struct csio_mgmtm *mgmtm = csio_hw_to_mgmtm(hw);
  233. int rv;
  234. struct csio_scsi_cpu_info *info;
  235. if (hw->flags & CSIO_HWF_Q_FW_ALLOCED)
  236. return 0;
  237. if (hw->intr_mode != CSIO_IM_MSIX) {
  238. rv = csio_wr_iq_create(hw, NULL, hw->intr_iq_idx,
  239. 0, hw->pport[0].portid, false, NULL);
  240. if (rv != 0) {
  241. csio_err(hw, " Forward Interrupt IQ failed!: %d\n", rv);
  242. return rv;
  243. }
  244. }
  245. /* FW event queue */
  246. rv = csio_wr_iq_create(hw, NULL, hw->fwevt_iq_idx,
  247. csio_get_fwevt_intr_idx(hw),
  248. hw->pport[0].portid, true, NULL);
  249. if (rv != 0) {
  250. csio_err(hw, "FW event IQ config failed!: %d\n", rv);
  251. return rv;
  252. }
  253. /* Create mgmt queue */
  254. rv = csio_wr_eq_create(hw, NULL, mgmtm->eq_idx,
  255. mgmtm->iq_idx, hw->pport[0].portid, NULL);
  256. if (rv != 0) {
  257. csio_err(hw, "Mgmt EQ create failed!: %d\n", rv);
  258. goto err;
  259. }
  260. /* Create SCSI queues */
  261. for (i = 0; i < hw->num_pports; i++) {
  262. info = &hw->scsi_cpu_info[i];
  263. for (j = 0; j < info->max_cpus; j++) {
  264. struct csio_scsi_qset *sqset = &hw->sqset[i][j];
  265. rv = csio_wr_iq_create(hw, NULL, sqset->iq_idx,
  266. sqset->intr_idx, i, false, NULL);
  267. if (rv != 0) {
  268. csio_err(hw,
  269. "SCSI module IQ config failed [%d][%d]:%d\n",
  270. i, j, rv);
  271. goto err;
  272. }
  273. rv = csio_wr_eq_create(hw, NULL, sqset->eq_idx,
  274. sqset->iq_idx, i, NULL);
  275. if (rv != 0) {
  276. csio_err(hw,
  277. "SCSI module EQ config failed [%d][%d]:%d\n",
  278. i, j, rv);
  279. goto err;
  280. }
  281. } /* for all CPUs */
  282. } /* For all ports */
  283. hw->flags |= CSIO_HWF_Q_FW_ALLOCED;
  284. return 0;
  285. err:
  286. csio_wr_destroy_queues(hw, true);
  287. return -EINVAL;
  288. }
  289. /*
  290. * csio_config_queues - Configure the DMA queues.
  291. * @hw: HW module.
  292. *
  293. * Allocates memory for queues are registers them with FW.
  294. */
  295. int
  296. csio_config_queues(struct csio_hw *hw)
  297. {
  298. int i, j, idx, k = 0;
  299. int rv;
  300. struct csio_scsi_qset *sqset;
  301. struct csio_mgmtm *mgmtm = csio_hw_to_mgmtm(hw);
  302. struct csio_scsi_qset *orig;
  303. struct csio_scsi_cpu_info *info;
  304. if (hw->flags & CSIO_HWF_Q_MEM_ALLOCED)
  305. return csio_create_queues(hw);
  306. /* Calculate number of SCSI queues for MSIX we would like */
  307. hw->num_scsi_msix_cpus = num_online_cpus();
  308. hw->num_sqsets = num_online_cpus() * hw->num_pports;
  309. if (hw->num_sqsets > CSIO_MAX_SCSI_QSETS) {
  310. hw->num_sqsets = CSIO_MAX_SCSI_QSETS;
  311. hw->num_scsi_msix_cpus = CSIO_MAX_SCSI_CPU;
  312. }
  313. /* Initialize max_cpus, may get reduced during msix allocations */
  314. for (i = 0; i < hw->num_pports; i++)
  315. hw->scsi_cpu_info[i].max_cpus = hw->num_scsi_msix_cpus;
  316. csio_dbg(hw, "nsqsets:%d scpus:%d\n",
  317. hw->num_sqsets, hw->num_scsi_msix_cpus);
  318. csio_intr_enable(hw);
  319. if (hw->intr_mode != CSIO_IM_MSIX) {
  320. /* Allocate Forward interrupt iq. */
  321. hw->intr_iq_idx = csio_wr_alloc_q(hw, CSIO_INTR_IQSIZE,
  322. CSIO_INTR_WRSIZE, CSIO_INGRESS,
  323. (void *)hw, 0, 0, NULL);
  324. if (hw->intr_iq_idx == -1) {
  325. csio_err(hw,
  326. "Forward interrupt queue creation failed\n");
  327. goto intr_disable;
  328. }
  329. }
  330. /* Allocate the FW evt queue */
  331. hw->fwevt_iq_idx = csio_wr_alloc_q(hw, CSIO_FWEVT_IQSIZE,
  332. CSIO_FWEVT_WRSIZE,
  333. CSIO_INGRESS, (void *)hw,
  334. CSIO_FWEVT_FLBUFS, 0,
  335. csio_fwevt_intx_handler);
  336. if (hw->fwevt_iq_idx == -1) {
  337. csio_err(hw, "FW evt queue creation failed\n");
  338. goto intr_disable;
  339. }
  340. /* Allocate the mgmt queue */
  341. mgmtm->eq_idx = csio_wr_alloc_q(hw, CSIO_MGMT_EQSIZE,
  342. CSIO_MGMT_EQ_WRSIZE,
  343. CSIO_EGRESS, (void *)hw, 0, 0, NULL);
  344. if (mgmtm->eq_idx == -1) {
  345. csio_err(hw, "Failed to alloc egress queue for mgmt module\n");
  346. goto intr_disable;
  347. }
  348. /* Use FW IQ for MGMT req completion */
  349. mgmtm->iq_idx = hw->fwevt_iq_idx;
  350. /* Allocate SCSI queues */
  351. for (i = 0; i < hw->num_pports; i++) {
  352. info = &hw->scsi_cpu_info[i];
  353. for (j = 0; j < hw->num_scsi_msix_cpus; j++) {
  354. sqset = &hw->sqset[i][j];
  355. if (j >= info->max_cpus) {
  356. k = j % info->max_cpus;
  357. orig = &hw->sqset[i][k];
  358. sqset->eq_idx = orig->eq_idx;
  359. sqset->iq_idx = orig->iq_idx;
  360. continue;
  361. }
  362. idx = csio_wr_alloc_q(hw, csio_scsi_eqsize, 0,
  363. CSIO_EGRESS, (void *)hw, 0, 0,
  364. NULL);
  365. if (idx == -1) {
  366. csio_err(hw, "EQ creation failed for idx:%d\n",
  367. idx);
  368. goto intr_disable;
  369. }
  370. sqset->eq_idx = idx;
  371. idx = csio_wr_alloc_q(hw, CSIO_SCSI_IQSIZE,
  372. CSIO_SCSI_IQ_WRSZ, CSIO_INGRESS,
  373. (void *)hw, 0, 0,
  374. csio_scsi_intx_handler);
  375. if (idx == -1) {
  376. csio_err(hw, "IQ creation failed for idx:%d\n",
  377. idx);
  378. goto intr_disable;
  379. }
  380. sqset->iq_idx = idx;
  381. } /* for all CPUs */
  382. } /* For all ports */
  383. hw->flags |= CSIO_HWF_Q_MEM_ALLOCED;
  384. rv = csio_create_queues(hw);
  385. if (rv != 0)
  386. goto intr_disable;
  387. /*
  388. * Now request IRQs for the vectors. In the event of a failure,
  389. * cleanup is handled internally by this function.
  390. */
  391. rv = csio_request_irqs(hw);
  392. if (rv != 0)
  393. return -EINVAL;
  394. return 0;
  395. intr_disable:
  396. csio_intr_disable(hw, false);
  397. return -EINVAL;
  398. }
  399. static int
  400. csio_resource_alloc(struct csio_hw *hw)
  401. {
  402. struct csio_wrm *wrm = csio_hw_to_wrm(hw);
  403. int rv = -ENOMEM;
  404. wrm->num_q = ((CSIO_MAX_SCSI_QSETS * 2) + CSIO_HW_NIQ +
  405. CSIO_HW_NEQ + CSIO_HW_NFLQ + CSIO_HW_NINTXQ);
  406. hw->mb_mempool = mempool_create_kmalloc_pool(CSIO_MIN_MEMPOOL_SZ,
  407. sizeof(struct csio_mb));
  408. if (!hw->mb_mempool)
  409. goto err;
  410. hw->rnode_mempool = mempool_create_kmalloc_pool(CSIO_MIN_MEMPOOL_SZ,
  411. sizeof(struct csio_rnode));
  412. if (!hw->rnode_mempool)
  413. goto err_free_mb_mempool;
  414. hw->scsi_pci_pool = pci_pool_create("csio_scsi_pci_pool", hw->pdev,
  415. CSIO_SCSI_RSP_LEN, 8, 0);
  416. if (!hw->scsi_pci_pool)
  417. goto err_free_rn_pool;
  418. return 0;
  419. err_free_rn_pool:
  420. mempool_destroy(hw->rnode_mempool);
  421. hw->rnode_mempool = NULL;
  422. err_free_mb_mempool:
  423. mempool_destroy(hw->mb_mempool);
  424. hw->mb_mempool = NULL;
  425. err:
  426. return rv;
  427. }
  428. static void
  429. csio_resource_free(struct csio_hw *hw)
  430. {
  431. pci_pool_destroy(hw->scsi_pci_pool);
  432. hw->scsi_pci_pool = NULL;
  433. mempool_destroy(hw->rnode_mempool);
  434. hw->rnode_mempool = NULL;
  435. mempool_destroy(hw->mb_mempool);
  436. hw->mb_mempool = NULL;
  437. }
  438. /*
  439. * csio_hw_alloc - Allocate and initialize the HW module.
  440. * @pdev: PCI device.
  441. *
  442. * Allocates HW structure, DMA, memory resources, maps BARS to
  443. * host memory and initializes HW module.
  444. */
  445. static struct csio_hw *csio_hw_alloc(struct pci_dev *pdev)
  446. {
  447. struct csio_hw *hw;
  448. hw = kzalloc(sizeof(struct csio_hw), GFP_KERNEL);
  449. if (!hw)
  450. goto err;
  451. hw->pdev = pdev;
  452. strncpy(hw->drv_version, CSIO_DRV_VERSION, 32);
  453. /* memory pool/DMA pool allocation */
  454. if (csio_resource_alloc(hw))
  455. goto err_free_hw;
  456. /* Get the start address of registers from BAR 0 */
  457. hw->regstart = ioremap_nocache(pci_resource_start(pdev, 0),
  458. pci_resource_len(pdev, 0));
  459. if (!hw->regstart) {
  460. csio_err(hw, "Could not map BAR 0, regstart = %p\n",
  461. hw->regstart);
  462. goto err_resource_free;
  463. }
  464. csio_hw_init_workers(hw);
  465. if (csio_hw_init(hw))
  466. goto err_unmap_bar;
  467. csio_dfs_create(hw);
  468. csio_dbg(hw, "hw:%p\n", hw);
  469. return hw;
  470. err_unmap_bar:
  471. csio_hw_exit_workers(hw);
  472. iounmap(hw->regstart);
  473. err_resource_free:
  474. csio_resource_free(hw);
  475. err_free_hw:
  476. kfree(hw);
  477. err:
  478. return NULL;
  479. }
  480. /*
  481. * csio_hw_free - Uninitialize and free the HW module.
  482. * @hw: The HW module
  483. *
  484. * Disable interrupts, uninit the HW module, free resources, free hw.
  485. */
  486. static void
  487. csio_hw_free(struct csio_hw *hw)
  488. {
  489. csio_intr_disable(hw, true);
  490. csio_hw_exit_workers(hw);
  491. csio_hw_exit(hw);
  492. iounmap(hw->regstart);
  493. csio_dfs_destroy(hw);
  494. csio_resource_free(hw);
  495. kfree(hw);
  496. }
  497. /**
  498. * csio_shost_init - Create and initialize the lnode module.
  499. * @hw: The HW module.
  500. * @dev: The device associated with this invocation.
  501. * @probe: Called from probe context or not?
  502. * @os_pln: Parent lnode if any.
  503. *
  504. * Allocates lnode structure via scsi_host_alloc, initializes
  505. * shost, initializes lnode module and registers with SCSI ML
  506. * via scsi_host_add. This function is shared between physical and
  507. * virtual node ports.
  508. */
  509. struct csio_lnode *
  510. csio_shost_init(struct csio_hw *hw, struct device *dev,
  511. bool probe, struct csio_lnode *pln)
  512. {
  513. struct Scsi_Host *shost = NULL;
  514. struct csio_lnode *ln;
  515. csio_fcoe_shost_template.cmd_per_lun = csio_lun_qdepth;
  516. csio_fcoe_shost_vport_template.cmd_per_lun = csio_lun_qdepth;
  517. /*
  518. * hw->pdev is the physical port's PCI dev structure,
  519. * which will be different from the NPIV dev structure.
  520. */
  521. if (dev == &hw->pdev->dev)
  522. shost = scsi_host_alloc(
  523. &csio_fcoe_shost_template,
  524. sizeof(struct csio_lnode));
  525. else
  526. shost = scsi_host_alloc(
  527. &csio_fcoe_shost_vport_template,
  528. sizeof(struct csio_lnode));
  529. if (!shost)
  530. goto err;
  531. ln = shost_priv(shost);
  532. memset(ln, 0, sizeof(struct csio_lnode));
  533. /* Link common lnode to this lnode */
  534. ln->dev_num = (shost->host_no << 16);
  535. shost->can_queue = CSIO_MAX_QUEUE;
  536. shost->this_id = -1;
  537. shost->unique_id = shost->host_no;
  538. shost->max_cmd_len = 16; /* Max CDB length supported */
  539. shost->max_id = min_t(uint32_t, csio_fcoe_rnodes,
  540. hw->fres_info.max_ssns);
  541. shost->max_lun = CSIO_MAX_LUN;
  542. if (dev == &hw->pdev->dev)
  543. shost->transportt = csio_fcoe_transport;
  544. else
  545. shost->transportt = csio_fcoe_transport_vport;
  546. /* root lnode */
  547. if (!hw->rln)
  548. hw->rln = ln;
  549. /* Other initialization here: Common, Transport specific */
  550. if (csio_lnode_init(ln, hw, pln))
  551. goto err_shost_put;
  552. if (scsi_add_host(shost, dev))
  553. goto err_lnode_exit;
  554. return ln;
  555. err_lnode_exit:
  556. csio_lnode_exit(ln);
  557. err_shost_put:
  558. scsi_host_put(shost);
  559. err:
  560. return NULL;
  561. }
  562. /**
  563. * csio_shost_exit - De-instantiate the shost.
  564. * @ln: The lnode module corresponding to the shost.
  565. *
  566. */
  567. void
  568. csio_shost_exit(struct csio_lnode *ln)
  569. {
  570. struct Scsi_Host *shost = csio_ln_to_shost(ln);
  571. struct csio_hw *hw = csio_lnode_to_hw(ln);
  572. /* Inform transport */
  573. fc_remove_host(shost);
  574. /* Inform SCSI ML */
  575. scsi_remove_host(shost);
  576. /* Flush all the events, so that any rnode removal events
  577. * already queued are all handled, before we remove the lnode.
  578. */
  579. spin_lock_irq(&hw->lock);
  580. csio_evtq_flush(hw);
  581. spin_unlock_irq(&hw->lock);
  582. csio_lnode_exit(ln);
  583. scsi_host_put(shost);
  584. }
  585. struct csio_lnode *
  586. csio_lnode_alloc(struct csio_hw *hw)
  587. {
  588. return csio_shost_init(hw, &hw->pdev->dev, false, NULL);
  589. }
  590. void
  591. csio_lnodes_block_request(struct csio_hw *hw)
  592. {
  593. struct Scsi_Host *shost;
  594. struct csio_lnode *sln;
  595. struct csio_lnode *ln;
  596. struct list_head *cur_ln, *cur_cln;
  597. struct csio_lnode **lnode_list;
  598. int cur_cnt = 0, ii;
  599. lnode_list = kzalloc((sizeof(struct csio_lnode *) * hw->num_lns),
  600. GFP_KERNEL);
  601. if (!lnode_list) {
  602. csio_err(hw, "Failed to allocate lnodes_list");
  603. return;
  604. }
  605. spin_lock_irq(&hw->lock);
  606. /* Traverse sibling lnodes */
  607. list_for_each(cur_ln, &hw->sln_head) {
  608. sln = (struct csio_lnode *) cur_ln;
  609. lnode_list[cur_cnt++] = sln;
  610. /* Traverse children lnodes */
  611. list_for_each(cur_cln, &sln->cln_head)
  612. lnode_list[cur_cnt++] = (struct csio_lnode *) cur_cln;
  613. }
  614. spin_unlock_irq(&hw->lock);
  615. for (ii = 0; ii < cur_cnt; ii++) {
  616. csio_dbg(hw, "Blocking IOs on lnode: %p\n", lnode_list[ii]);
  617. ln = lnode_list[ii];
  618. shost = csio_ln_to_shost(ln);
  619. scsi_block_requests(shost);
  620. }
  621. kfree(lnode_list);
  622. }
  623. void
  624. csio_lnodes_unblock_request(struct csio_hw *hw)
  625. {
  626. struct csio_lnode *ln;
  627. struct Scsi_Host *shost;
  628. struct csio_lnode *sln;
  629. struct list_head *cur_ln, *cur_cln;
  630. struct csio_lnode **lnode_list;
  631. int cur_cnt = 0, ii;
  632. lnode_list = kzalloc((sizeof(struct csio_lnode *) * hw->num_lns),
  633. GFP_KERNEL);
  634. if (!lnode_list) {
  635. csio_err(hw, "Failed to allocate lnodes_list");
  636. return;
  637. }
  638. spin_lock_irq(&hw->lock);
  639. /* Traverse sibling lnodes */
  640. list_for_each(cur_ln, &hw->sln_head) {
  641. sln = (struct csio_lnode *) cur_ln;
  642. lnode_list[cur_cnt++] = sln;
  643. /* Traverse children lnodes */
  644. list_for_each(cur_cln, &sln->cln_head)
  645. lnode_list[cur_cnt++] = (struct csio_lnode *) cur_cln;
  646. }
  647. spin_unlock_irq(&hw->lock);
  648. for (ii = 0; ii < cur_cnt; ii++) {
  649. csio_dbg(hw, "unblocking IOs on lnode: %p\n", lnode_list[ii]);
  650. ln = lnode_list[ii];
  651. shost = csio_ln_to_shost(ln);
  652. scsi_unblock_requests(shost);
  653. }
  654. kfree(lnode_list);
  655. }
  656. void
  657. csio_lnodes_block_by_port(struct csio_hw *hw, uint8_t portid)
  658. {
  659. struct csio_lnode *ln;
  660. struct Scsi_Host *shost;
  661. struct csio_lnode *sln;
  662. struct list_head *cur_ln, *cur_cln;
  663. struct csio_lnode **lnode_list;
  664. int cur_cnt = 0, ii;
  665. lnode_list = kzalloc((sizeof(struct csio_lnode *) * hw->num_lns),
  666. GFP_KERNEL);
  667. if (!lnode_list) {
  668. csio_err(hw, "Failed to allocate lnodes_list");
  669. return;
  670. }
  671. spin_lock_irq(&hw->lock);
  672. /* Traverse sibling lnodes */
  673. list_for_each(cur_ln, &hw->sln_head) {
  674. sln = (struct csio_lnode *) cur_ln;
  675. if (sln->portid != portid)
  676. continue;
  677. lnode_list[cur_cnt++] = sln;
  678. /* Traverse children lnodes */
  679. list_for_each(cur_cln, &sln->cln_head)
  680. lnode_list[cur_cnt++] = (struct csio_lnode *) cur_cln;
  681. }
  682. spin_unlock_irq(&hw->lock);
  683. for (ii = 0; ii < cur_cnt; ii++) {
  684. csio_dbg(hw, "Blocking IOs on lnode: %p\n", lnode_list[ii]);
  685. ln = lnode_list[ii];
  686. shost = csio_ln_to_shost(ln);
  687. scsi_block_requests(shost);
  688. }
  689. kfree(lnode_list);
  690. }
  691. void
  692. csio_lnodes_unblock_by_port(struct csio_hw *hw, uint8_t portid)
  693. {
  694. struct csio_lnode *ln;
  695. struct Scsi_Host *shost;
  696. struct csio_lnode *sln;
  697. struct list_head *cur_ln, *cur_cln;
  698. struct csio_lnode **lnode_list;
  699. int cur_cnt = 0, ii;
  700. lnode_list = kzalloc((sizeof(struct csio_lnode *) * hw->num_lns),
  701. GFP_KERNEL);
  702. if (!lnode_list) {
  703. csio_err(hw, "Failed to allocate lnodes_list");
  704. return;
  705. }
  706. spin_lock_irq(&hw->lock);
  707. /* Traverse sibling lnodes */
  708. list_for_each(cur_ln, &hw->sln_head) {
  709. sln = (struct csio_lnode *) cur_ln;
  710. if (sln->portid != portid)
  711. continue;
  712. lnode_list[cur_cnt++] = sln;
  713. /* Traverse children lnodes */
  714. list_for_each(cur_cln, &sln->cln_head)
  715. lnode_list[cur_cnt++] = (struct csio_lnode *) cur_cln;
  716. }
  717. spin_unlock_irq(&hw->lock);
  718. for (ii = 0; ii < cur_cnt; ii++) {
  719. csio_dbg(hw, "unblocking IOs on lnode: %p\n", lnode_list[ii]);
  720. ln = lnode_list[ii];
  721. shost = csio_ln_to_shost(ln);
  722. scsi_unblock_requests(shost);
  723. }
  724. kfree(lnode_list);
  725. }
  726. void
  727. csio_lnodes_exit(struct csio_hw *hw, bool npiv)
  728. {
  729. struct csio_lnode *sln;
  730. struct csio_lnode *ln;
  731. struct list_head *cur_ln, *cur_cln;
  732. struct csio_lnode **lnode_list;
  733. int cur_cnt = 0, ii;
  734. lnode_list = kzalloc((sizeof(struct csio_lnode *) * hw->num_lns),
  735. GFP_KERNEL);
  736. if (!lnode_list) {
  737. csio_err(hw, "lnodes_exit: Failed to allocate lnodes_list.\n");
  738. return;
  739. }
  740. /* Get all child lnodes(NPIV ports) */
  741. spin_lock_irq(&hw->lock);
  742. list_for_each(cur_ln, &hw->sln_head) {
  743. sln = (struct csio_lnode *) cur_ln;
  744. /* Traverse children lnodes */
  745. list_for_each(cur_cln, &sln->cln_head)
  746. lnode_list[cur_cnt++] = (struct csio_lnode *) cur_cln;
  747. }
  748. spin_unlock_irq(&hw->lock);
  749. /* Delete NPIV lnodes */
  750. for (ii = 0; ii < cur_cnt; ii++) {
  751. csio_dbg(hw, "Deleting child lnode: %p\n", lnode_list[ii]);
  752. ln = lnode_list[ii];
  753. fc_vport_terminate(ln->fc_vport);
  754. }
  755. /* Delete only npiv lnodes */
  756. if (npiv)
  757. goto free_lnodes;
  758. cur_cnt = 0;
  759. /* Get all physical lnodes */
  760. spin_lock_irq(&hw->lock);
  761. /* Traverse sibling lnodes */
  762. list_for_each(cur_ln, &hw->sln_head) {
  763. sln = (struct csio_lnode *) cur_ln;
  764. lnode_list[cur_cnt++] = sln;
  765. }
  766. spin_unlock_irq(&hw->lock);
  767. /* Delete physical lnodes */
  768. for (ii = 0; ii < cur_cnt; ii++) {
  769. csio_dbg(hw, "Deleting parent lnode: %p\n", lnode_list[ii]);
  770. csio_shost_exit(lnode_list[ii]);
  771. }
  772. free_lnodes:
  773. kfree(lnode_list);
  774. }
  775. /*
  776. * csio_lnode_init_post: Set lnode attributes after starting HW.
  777. * @ln: lnode.
  778. *
  779. */
  780. static void
  781. csio_lnode_init_post(struct csio_lnode *ln)
  782. {
  783. struct Scsi_Host *shost = csio_ln_to_shost(ln);
  784. csio_fchost_attr_init(ln);
  785. scsi_scan_host(shost);
  786. }
  787. /*
  788. * csio_probe_one - Instantiate this function.
  789. * @pdev: PCI device
  790. * @id: Device ID
  791. *
  792. * This is the .probe() callback of the driver. This function:
  793. * - Initializes the PCI function by enabling MMIO, setting bus
  794. * mastership and setting DMA mask.
  795. * - Allocates HW structure, DMA, memory resources, maps BARS to
  796. * host memory and initializes HW module.
  797. * - Allocates lnode structure via scsi_host_alloc, initializes
  798. * shost, initialized lnode module and registers with SCSI ML
  799. * via scsi_host_add.
  800. * - Enables interrupts, and starts the chip by kicking off the
  801. * HW state machine.
  802. * - Once hardware is ready, initiated scan of the host via
  803. * scsi_scan_host.
  804. */
  805. static int csio_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
  806. {
  807. int rv;
  808. int bars;
  809. int i;
  810. struct csio_hw *hw;
  811. struct csio_lnode *ln;
  812. rv = csio_pci_init(pdev, &bars);
  813. if (rv)
  814. goto err;
  815. hw = csio_hw_alloc(pdev);
  816. if (!hw) {
  817. rv = -ENODEV;
  818. goto err_pci_exit;
  819. }
  820. pci_set_drvdata(pdev, hw);
  821. if (csio_hw_start(hw) != 0) {
  822. dev_err(&pdev->dev,
  823. "Failed to start FW, continuing in debug mode.\n");
  824. return 0;
  825. }
  826. sprintf(hw->fwrev_str, "%u.%u.%u.%u\n",
  827. FW_HDR_FW_VER_MAJOR_GET(hw->fwrev),
  828. FW_HDR_FW_VER_MINOR_GET(hw->fwrev),
  829. FW_HDR_FW_VER_MICRO_GET(hw->fwrev),
  830. FW_HDR_FW_VER_BUILD_GET(hw->fwrev));
  831. for (i = 0; i < hw->num_pports; i++) {
  832. ln = csio_shost_init(hw, &pdev->dev, true, NULL);
  833. if (!ln) {
  834. rv = -ENODEV;
  835. break;
  836. }
  837. /* Initialize portid */
  838. ln->portid = hw->pport[i].portid;
  839. spin_lock_irq(&hw->lock);
  840. if (csio_lnode_start(ln) != 0)
  841. rv = -ENODEV;
  842. spin_unlock_irq(&hw->lock);
  843. if (rv)
  844. break;
  845. csio_lnode_init_post(ln);
  846. }
  847. if (rv)
  848. goto err_lnode_exit;
  849. return 0;
  850. err_lnode_exit:
  851. csio_lnodes_block_request(hw);
  852. spin_lock_irq(&hw->lock);
  853. csio_hw_stop(hw);
  854. spin_unlock_irq(&hw->lock);
  855. csio_lnodes_unblock_request(hw);
  856. pci_set_drvdata(hw->pdev, NULL);
  857. csio_lnodes_exit(hw, 0);
  858. csio_hw_free(hw);
  859. err_pci_exit:
  860. csio_pci_exit(pdev, &bars);
  861. err:
  862. dev_err(&pdev->dev, "probe of device failed: %d\n", rv);
  863. return rv;
  864. }
  865. /*
  866. * csio_remove_one - Remove one instance of the driver at this PCI function.
  867. * @pdev: PCI device
  868. *
  869. * Used during hotplug operation.
  870. */
  871. static void csio_remove_one(struct pci_dev *pdev)
  872. {
  873. struct csio_hw *hw = pci_get_drvdata(pdev);
  874. int bars = pci_select_bars(pdev, IORESOURCE_MEM);
  875. csio_lnodes_block_request(hw);
  876. spin_lock_irq(&hw->lock);
  877. /* Stops lnode, Rnode s/m
  878. * Quiesce IOs.
  879. * All sessions with remote ports are unregistered.
  880. */
  881. csio_hw_stop(hw);
  882. spin_unlock_irq(&hw->lock);
  883. csio_lnodes_unblock_request(hw);
  884. csio_lnodes_exit(hw, 0);
  885. csio_hw_free(hw);
  886. pci_set_drvdata(pdev, NULL);
  887. csio_pci_exit(pdev, &bars);
  888. }
  889. /*
  890. * csio_pci_error_detected - PCI error was detected
  891. * @pdev: PCI device
  892. *
  893. */
  894. static pci_ers_result_t
  895. csio_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  896. {
  897. struct csio_hw *hw = pci_get_drvdata(pdev);
  898. csio_lnodes_block_request(hw);
  899. spin_lock_irq(&hw->lock);
  900. /* Post PCI error detected evt to HW s/m
  901. * HW s/m handles this evt by quiescing IOs, unregisters rports
  902. * and finally takes the device to offline.
  903. */
  904. csio_post_event(&hw->sm, CSIO_HWE_PCIERR_DETECTED);
  905. spin_unlock_irq(&hw->lock);
  906. csio_lnodes_unblock_request(hw);
  907. csio_lnodes_exit(hw, 0);
  908. csio_intr_disable(hw, true);
  909. pci_disable_device(pdev);
  910. return state == pci_channel_io_perm_failure ?
  911. PCI_ERS_RESULT_DISCONNECT : PCI_ERS_RESULT_NEED_RESET;
  912. }
  913. /*
  914. * csio_pci_slot_reset - PCI slot has been reset.
  915. * @pdev: PCI device
  916. *
  917. */
  918. static pci_ers_result_t
  919. csio_pci_slot_reset(struct pci_dev *pdev)
  920. {
  921. struct csio_hw *hw = pci_get_drvdata(pdev);
  922. int ready;
  923. if (pci_enable_device(pdev)) {
  924. dev_err(&pdev->dev, "cannot re-enable device in slot reset\n");
  925. return PCI_ERS_RESULT_DISCONNECT;
  926. }
  927. pci_set_master(pdev);
  928. pci_restore_state(pdev);
  929. pci_save_state(pdev);
  930. pci_cleanup_aer_uncorrect_error_status(pdev);
  931. /* Bring HW s/m to ready state.
  932. * but don't resume IOs.
  933. */
  934. spin_lock_irq(&hw->lock);
  935. csio_post_event(&hw->sm, CSIO_HWE_PCIERR_SLOT_RESET);
  936. ready = csio_is_hw_ready(hw);
  937. spin_unlock_irq(&hw->lock);
  938. if (ready) {
  939. return PCI_ERS_RESULT_RECOVERED;
  940. } else {
  941. dev_err(&pdev->dev, "Can't initialize HW when in slot reset\n");
  942. return PCI_ERS_RESULT_DISCONNECT;
  943. }
  944. }
  945. /*
  946. * csio_pci_resume - Resume normal operations
  947. * @pdev: PCI device
  948. *
  949. */
  950. static void
  951. csio_pci_resume(struct pci_dev *pdev)
  952. {
  953. struct csio_hw *hw = pci_get_drvdata(pdev);
  954. struct csio_lnode *ln;
  955. int rv = 0;
  956. int i;
  957. /* Bring the LINK UP and Resume IO */
  958. for (i = 0; i < hw->num_pports; i++) {
  959. ln = csio_shost_init(hw, &pdev->dev, true, NULL);
  960. if (!ln) {
  961. rv = -ENODEV;
  962. break;
  963. }
  964. /* Initialize portid */
  965. ln->portid = hw->pport[i].portid;
  966. spin_lock_irq(&hw->lock);
  967. if (csio_lnode_start(ln) != 0)
  968. rv = -ENODEV;
  969. spin_unlock_irq(&hw->lock);
  970. if (rv)
  971. break;
  972. csio_lnode_init_post(ln);
  973. }
  974. if (rv)
  975. goto err_resume_exit;
  976. return;
  977. err_resume_exit:
  978. csio_lnodes_block_request(hw);
  979. spin_lock_irq(&hw->lock);
  980. csio_hw_stop(hw);
  981. spin_unlock_irq(&hw->lock);
  982. csio_lnodes_unblock_request(hw);
  983. csio_lnodes_exit(hw, 0);
  984. csio_hw_free(hw);
  985. dev_err(&pdev->dev, "resume of device failed: %d\n", rv);
  986. }
  987. static struct pci_error_handlers csio_err_handler = {
  988. .error_detected = csio_pci_error_detected,
  989. .slot_reset = csio_pci_slot_reset,
  990. .resume = csio_pci_resume,
  991. };
  992. static DEFINE_PCI_DEVICE_TABLE(csio_pci_tbl) = {
  993. CSIO_DEVICE(CSIO_DEVID_T440DBG_FCOE, 0), /* T4 DEBUG FCOE */
  994. CSIO_DEVICE(CSIO_DEVID_T420CR_FCOE, 0), /* T420CR FCOE */
  995. CSIO_DEVICE(CSIO_DEVID_T422CR_FCOE, 0), /* T422CR FCOE */
  996. CSIO_DEVICE(CSIO_DEVID_T440CR_FCOE, 0), /* T440CR FCOE */
  997. CSIO_DEVICE(CSIO_DEVID_T420BCH_FCOE, 0), /* T420BCH FCOE */
  998. CSIO_DEVICE(CSIO_DEVID_T440BCH_FCOE, 0), /* T440BCH FCOE */
  999. CSIO_DEVICE(CSIO_DEVID_T440CH_FCOE, 0), /* T440CH FCOE */
  1000. CSIO_DEVICE(CSIO_DEVID_T420SO_FCOE, 0), /* T420SO FCOE */
  1001. CSIO_DEVICE(CSIO_DEVID_T420CX_FCOE, 0), /* T420CX FCOE */
  1002. CSIO_DEVICE(CSIO_DEVID_T420BT_FCOE, 0), /* T420BT FCOE */
  1003. CSIO_DEVICE(CSIO_DEVID_T404BT_FCOE, 0), /* T404BT FCOE */
  1004. CSIO_DEVICE(CSIO_DEVID_B420_FCOE, 0), /* B420 FCOE */
  1005. CSIO_DEVICE(CSIO_DEVID_B404_FCOE, 0), /* B404 FCOE */
  1006. CSIO_DEVICE(CSIO_DEVID_T480CR_FCOE, 0), /* T480 CR FCOE */
  1007. CSIO_DEVICE(CSIO_DEVID_T440LPCR_FCOE, 0), /* T440 LP-CR FCOE */
  1008. CSIO_DEVICE(CSIO_DEVID_AMSTERDAM_T4_FCOE, 0), /* AMSTERDAM T4 FCOE */
  1009. CSIO_DEVICE(CSIO_DEVID_HUAWEI_T480_FCOE, 0), /* HUAWEI T480 FCOE */
  1010. CSIO_DEVICE(CSIO_DEVID_HUAWEI_T440_FCOE, 0), /* HUAWEI T440 FCOE */
  1011. CSIO_DEVICE(CSIO_DEVID_HUAWEI_STG310_FCOE, 0), /* HUAWEI STG FCOE */
  1012. CSIO_DEVICE(CSIO_DEVID_ACROMAG_XMC_XAUI, 0), /* ACROMAG XAUI FCOE */
  1013. CSIO_DEVICE(CSIO_DEVID_QUANTA_MEZZ_SFP_FCOE, 0),/* QUANTA MEZZ FCOE */
  1014. CSIO_DEVICE(CSIO_DEVID_HUAWEI_10GT_FCOE, 0), /* HUAWEI 10GT FCOE */
  1015. CSIO_DEVICE(CSIO_DEVID_HUAWEI_T440_TOE_FCOE, 0),/* HUAWEI T4 TOE FCOE */
  1016. CSIO_DEVICE(CSIO_DEVID_T580DBG_FCOE, 0), /* T5 DEBUG FCOE */
  1017. CSIO_DEVICE(CSIO_DEVID_T520CR_FCOE, 0), /* T520CR FCOE */
  1018. CSIO_DEVICE(CSIO_DEVID_T522CR_FCOE, 0), /* T522CR FCOE */
  1019. CSIO_DEVICE(CSIO_DEVID_T540CR_FCOE, 0), /* T540CR FCOE */
  1020. CSIO_DEVICE(CSIO_DEVID_T520BCH_FCOE, 0), /* T520BCH FCOE */
  1021. CSIO_DEVICE(CSIO_DEVID_T540BCH_FCOE, 0), /* T540BCH FCOE */
  1022. CSIO_DEVICE(CSIO_DEVID_T540CH_FCOE, 0), /* T540CH FCOE */
  1023. CSIO_DEVICE(CSIO_DEVID_T520SO_FCOE, 0), /* T520SO FCOE */
  1024. CSIO_DEVICE(CSIO_DEVID_T520CX_FCOE, 0), /* T520CX FCOE */
  1025. CSIO_DEVICE(CSIO_DEVID_T520BT_FCOE, 0), /* T520BT FCOE */
  1026. CSIO_DEVICE(CSIO_DEVID_T504BT_FCOE, 0), /* T504BT FCOE */
  1027. CSIO_DEVICE(CSIO_DEVID_B520_FCOE, 0), /* B520 FCOE */
  1028. CSIO_DEVICE(CSIO_DEVID_B504_FCOE, 0), /* B504 FCOE */
  1029. CSIO_DEVICE(CSIO_DEVID_T580CR2_FCOE, 0), /* T580 CR FCOE */
  1030. CSIO_DEVICE(CSIO_DEVID_T540LPCR_FCOE, 0), /* T540 LP-CR FCOE */
  1031. CSIO_DEVICE(CSIO_DEVID_AMSTERDAM_T5_FCOE, 0), /* AMSTERDAM T5 FCOE */
  1032. CSIO_DEVICE(CSIO_DEVID_T580LPCR_FCOE, 0), /* T580 LP-CR FCOE */
  1033. CSIO_DEVICE(CSIO_DEVID_T520LLCR_FCOE, 0), /* T520 LL-CR FCOE */
  1034. CSIO_DEVICE(CSIO_DEVID_T560CR_FCOE, 0), /* T560 CR FCOE */
  1035. CSIO_DEVICE(CSIO_DEVID_T580CR_FCOE, 0), /* T580 CR FCOE */
  1036. { 0, 0, 0, 0, 0, 0, 0 }
  1037. };
  1038. static struct pci_driver csio_pci_driver = {
  1039. .name = KBUILD_MODNAME,
  1040. .driver = {
  1041. .owner = THIS_MODULE,
  1042. },
  1043. .id_table = csio_pci_tbl,
  1044. .probe = csio_probe_one,
  1045. .remove = csio_remove_one,
  1046. .err_handler = &csio_err_handler,
  1047. };
  1048. /*
  1049. * csio_init - Chelsio storage driver initialization function.
  1050. *
  1051. */
  1052. static int __init
  1053. csio_init(void)
  1054. {
  1055. int rv = -ENOMEM;
  1056. pr_info("%s %s\n", CSIO_DRV_DESC, CSIO_DRV_VERSION);
  1057. csio_dfs_init();
  1058. csio_fcoe_transport = fc_attach_transport(&csio_fc_transport_funcs);
  1059. if (!csio_fcoe_transport)
  1060. goto err;
  1061. csio_fcoe_transport_vport =
  1062. fc_attach_transport(&csio_fc_transport_vport_funcs);
  1063. if (!csio_fcoe_transport_vport)
  1064. goto err_vport;
  1065. rv = pci_register_driver(&csio_pci_driver);
  1066. if (rv)
  1067. goto err_pci;
  1068. return 0;
  1069. err_pci:
  1070. fc_release_transport(csio_fcoe_transport_vport);
  1071. err_vport:
  1072. fc_release_transport(csio_fcoe_transport);
  1073. err:
  1074. csio_dfs_exit();
  1075. return rv;
  1076. }
  1077. /*
  1078. * csio_exit - Chelsio storage driver uninitialization .
  1079. *
  1080. * Function that gets called in the unload path.
  1081. */
  1082. static void __exit
  1083. csio_exit(void)
  1084. {
  1085. pci_unregister_driver(&csio_pci_driver);
  1086. csio_dfs_exit();
  1087. fc_release_transport(csio_fcoe_transport_vport);
  1088. fc_release_transport(csio_fcoe_transport);
  1089. }
  1090. module_init(csio_init);
  1091. module_exit(csio_exit);
  1092. MODULE_AUTHOR(CSIO_DRV_AUTHOR);
  1093. MODULE_DESCRIPTION(CSIO_DRV_DESC);
  1094. MODULE_LICENSE(CSIO_DRV_LICENSE);
  1095. MODULE_DEVICE_TABLE(pci, csio_pci_tbl);
  1096. MODULE_VERSION(CSIO_DRV_VERSION);
  1097. MODULE_FIRMWARE(FW_FNAME_T4);
  1098. MODULE_FIRMWARE(FW_FNAME_T5);