qed_main.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321
  1. /* QLogic qed NIC Driver
  2. * Copyright (c) 2015 QLogic Corporation
  3. *
  4. * This software is available under the terms of the GNU General Public License
  5. * (GPL) Version 2, available from the file COPYING in the main directory of
  6. * this source tree.
  7. */
  8. #include <linux/stddef.h>
  9. #include <linux/pci.h>
  10. #include <linux/kernel.h>
  11. #include <linux/slab.h>
  12. #include <linux/version.h>
  13. #include <linux/delay.h>
  14. #include <asm/byteorder.h>
  15. #include <linux/dma-mapping.h>
  16. #include <linux/string.h>
  17. #include <linux/module.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/workqueue.h>
  20. #include <linux/ethtool.h>
  21. #include <linux/etherdevice.h>
  22. #include <linux/vmalloc.h>
  23. #include <linux/qed/qed_if.h>
  24. #include "qed.h"
  25. #include "qed_sriov.h"
  26. #include "qed_sp.h"
  27. #include "qed_dev_api.h"
  28. #include "qed_mcp.h"
  29. #include "qed_hw.h"
  30. #include "qed_selftest.h"
  31. static char version[] =
  32. "QLogic FastLinQ 4xxxx Core Module qed " DRV_MODULE_VERSION "\n";
  33. MODULE_DESCRIPTION("QLogic FastLinQ 4xxxx Core Module");
  34. MODULE_LICENSE("GPL");
  35. MODULE_VERSION(DRV_MODULE_VERSION);
  36. #define FW_FILE_VERSION \
  37. __stringify(FW_MAJOR_VERSION) "." \
  38. __stringify(FW_MINOR_VERSION) "." \
  39. __stringify(FW_REVISION_VERSION) "." \
  40. __stringify(FW_ENGINEERING_VERSION)
  41. #define QED_FW_FILE_NAME \
  42. "qed/qed_init_values_zipped-" FW_FILE_VERSION ".bin"
  43. MODULE_FIRMWARE(QED_FW_FILE_NAME);
  44. static int __init qed_init(void)
  45. {
  46. pr_notice("qed_init called\n");
  47. pr_info("%s", version);
  48. return 0;
  49. }
  50. static void __exit qed_cleanup(void)
  51. {
  52. pr_notice("qed_cleanup called\n");
  53. }
  54. module_init(qed_init);
  55. module_exit(qed_cleanup);
  56. /* Check if the DMA controller on the machine can properly handle the DMA
  57. * addressing required by the device.
  58. */
  59. static int qed_set_coherency_mask(struct qed_dev *cdev)
  60. {
  61. struct device *dev = &cdev->pdev->dev;
  62. if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
  63. if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
  64. DP_NOTICE(cdev,
  65. "Can't request 64-bit consistent allocations\n");
  66. return -EIO;
  67. }
  68. } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
  69. DP_NOTICE(cdev, "Can't request 64b/32b DMA addresses\n");
  70. return -EIO;
  71. }
  72. return 0;
  73. }
  74. static void qed_free_pci(struct qed_dev *cdev)
  75. {
  76. struct pci_dev *pdev = cdev->pdev;
  77. if (cdev->doorbells)
  78. iounmap(cdev->doorbells);
  79. if (cdev->regview)
  80. iounmap(cdev->regview);
  81. if (atomic_read(&pdev->enable_cnt) == 1)
  82. pci_release_regions(pdev);
  83. pci_disable_device(pdev);
  84. }
  85. #define PCI_REVISION_ID_ERROR_VAL 0xff
  86. /* Performs PCI initializations as well as initializing PCI-related parameters
  87. * in the device structrue. Returns 0 in case of success.
  88. */
  89. static int qed_init_pci(struct qed_dev *cdev,
  90. struct pci_dev *pdev)
  91. {
  92. u8 rev_id;
  93. int rc;
  94. cdev->pdev = pdev;
  95. rc = pci_enable_device(pdev);
  96. if (rc) {
  97. DP_NOTICE(cdev, "Cannot enable PCI device\n");
  98. goto err0;
  99. }
  100. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  101. DP_NOTICE(cdev, "No memory region found in bar #0\n");
  102. rc = -EIO;
  103. goto err1;
  104. }
  105. if (IS_PF(cdev) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  106. DP_NOTICE(cdev, "No memory region found in bar #2\n");
  107. rc = -EIO;
  108. goto err1;
  109. }
  110. if (atomic_read(&pdev->enable_cnt) == 1) {
  111. rc = pci_request_regions(pdev, "qed");
  112. if (rc) {
  113. DP_NOTICE(cdev,
  114. "Failed to request PCI memory resources\n");
  115. goto err1;
  116. }
  117. pci_set_master(pdev);
  118. pci_save_state(pdev);
  119. }
  120. pci_read_config_byte(pdev, PCI_REVISION_ID, &rev_id);
  121. if (rev_id == PCI_REVISION_ID_ERROR_VAL) {
  122. DP_NOTICE(cdev,
  123. "Detected PCI device error [rev_id 0x%x]. Probably due to prior indication. Aborting.\n",
  124. rev_id);
  125. rc = -ENODEV;
  126. goto err2;
  127. }
  128. if (!pci_is_pcie(pdev)) {
  129. DP_NOTICE(cdev, "The bus is not PCI Express\n");
  130. rc = -EIO;
  131. goto err2;
  132. }
  133. cdev->pci_params.pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  134. if (IS_PF(cdev) && !cdev->pci_params.pm_cap)
  135. DP_NOTICE(cdev, "Cannot find power management capability\n");
  136. rc = qed_set_coherency_mask(cdev);
  137. if (rc)
  138. goto err2;
  139. cdev->pci_params.mem_start = pci_resource_start(pdev, 0);
  140. cdev->pci_params.mem_end = pci_resource_end(pdev, 0);
  141. cdev->pci_params.irq = pdev->irq;
  142. cdev->regview = pci_ioremap_bar(pdev, 0);
  143. if (!cdev->regview) {
  144. DP_NOTICE(cdev, "Cannot map register space, aborting\n");
  145. rc = -ENOMEM;
  146. goto err2;
  147. }
  148. if (IS_PF(cdev)) {
  149. cdev->db_phys_addr = pci_resource_start(cdev->pdev, 2);
  150. cdev->db_size = pci_resource_len(cdev->pdev, 2);
  151. cdev->doorbells = ioremap_wc(cdev->db_phys_addr, cdev->db_size);
  152. if (!cdev->doorbells) {
  153. DP_NOTICE(cdev, "Cannot map doorbell space\n");
  154. return -ENOMEM;
  155. }
  156. }
  157. return 0;
  158. err2:
  159. pci_release_regions(pdev);
  160. err1:
  161. pci_disable_device(pdev);
  162. err0:
  163. return rc;
  164. }
  165. int qed_fill_dev_info(struct qed_dev *cdev,
  166. struct qed_dev_info *dev_info)
  167. {
  168. struct qed_ptt *ptt;
  169. memset(dev_info, 0, sizeof(struct qed_dev_info));
  170. dev_info->num_hwfns = cdev->num_hwfns;
  171. dev_info->pci_mem_start = cdev->pci_params.mem_start;
  172. dev_info->pci_mem_end = cdev->pci_params.mem_end;
  173. dev_info->pci_irq = cdev->pci_params.irq;
  174. dev_info->is_mf_default = IS_MF_DEFAULT(&cdev->hwfns[0]);
  175. ether_addr_copy(dev_info->hw_mac, cdev->hwfns[0].hw_info.hw_mac_addr);
  176. if (IS_PF(cdev)) {
  177. dev_info->fw_major = FW_MAJOR_VERSION;
  178. dev_info->fw_minor = FW_MINOR_VERSION;
  179. dev_info->fw_rev = FW_REVISION_VERSION;
  180. dev_info->fw_eng = FW_ENGINEERING_VERSION;
  181. dev_info->mf_mode = cdev->mf_mode;
  182. dev_info->tx_switching = true;
  183. } else {
  184. qed_vf_get_fw_version(&cdev->hwfns[0], &dev_info->fw_major,
  185. &dev_info->fw_minor, &dev_info->fw_rev,
  186. &dev_info->fw_eng);
  187. }
  188. if (IS_PF(cdev)) {
  189. ptt = qed_ptt_acquire(QED_LEADING_HWFN(cdev));
  190. if (ptt) {
  191. qed_mcp_get_mfw_ver(QED_LEADING_HWFN(cdev), ptt,
  192. &dev_info->mfw_rev, NULL);
  193. qed_mcp_get_flash_size(QED_LEADING_HWFN(cdev), ptt,
  194. &dev_info->flash_size);
  195. qed_ptt_release(QED_LEADING_HWFN(cdev), ptt);
  196. }
  197. } else {
  198. qed_mcp_get_mfw_ver(QED_LEADING_HWFN(cdev), NULL,
  199. &dev_info->mfw_rev, NULL);
  200. }
  201. return 0;
  202. }
  203. static void qed_free_cdev(struct qed_dev *cdev)
  204. {
  205. kfree((void *)cdev);
  206. }
  207. static struct qed_dev *qed_alloc_cdev(struct pci_dev *pdev)
  208. {
  209. struct qed_dev *cdev;
  210. cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
  211. if (!cdev)
  212. return cdev;
  213. qed_init_struct(cdev);
  214. return cdev;
  215. }
  216. /* Sets the requested power state */
  217. static int qed_set_power_state(struct qed_dev *cdev,
  218. pci_power_t state)
  219. {
  220. if (!cdev)
  221. return -ENODEV;
  222. DP_VERBOSE(cdev, NETIF_MSG_DRV, "Omitting Power state change\n");
  223. return 0;
  224. }
  225. /* probing */
  226. static struct qed_dev *qed_probe(struct pci_dev *pdev,
  227. struct qed_probe_params *params)
  228. {
  229. struct qed_dev *cdev;
  230. int rc;
  231. cdev = qed_alloc_cdev(pdev);
  232. if (!cdev)
  233. goto err0;
  234. cdev->protocol = params->protocol;
  235. if (params->is_vf)
  236. cdev->b_is_vf = true;
  237. qed_init_dp(cdev, params->dp_module, params->dp_level);
  238. rc = qed_init_pci(cdev, pdev);
  239. if (rc) {
  240. DP_ERR(cdev, "init pci failed\n");
  241. goto err1;
  242. }
  243. DP_INFO(cdev, "PCI init completed successfully\n");
  244. rc = qed_hw_prepare(cdev, QED_PCI_DEFAULT);
  245. if (rc) {
  246. DP_ERR(cdev, "hw prepare failed\n");
  247. goto err2;
  248. }
  249. DP_INFO(cdev, "qed_probe completed successffuly\n");
  250. return cdev;
  251. err2:
  252. qed_free_pci(cdev);
  253. err1:
  254. qed_free_cdev(cdev);
  255. err0:
  256. return NULL;
  257. }
  258. static void qed_remove(struct qed_dev *cdev)
  259. {
  260. if (!cdev)
  261. return;
  262. qed_hw_remove(cdev);
  263. qed_free_pci(cdev);
  264. qed_set_power_state(cdev, PCI_D3hot);
  265. qed_free_cdev(cdev);
  266. }
  267. static void qed_disable_msix(struct qed_dev *cdev)
  268. {
  269. if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
  270. pci_disable_msix(cdev->pdev);
  271. kfree(cdev->int_params.msix_table);
  272. } else if (cdev->int_params.out.int_mode == QED_INT_MODE_MSI) {
  273. pci_disable_msi(cdev->pdev);
  274. }
  275. memset(&cdev->int_params.out, 0, sizeof(struct qed_int_param));
  276. }
  277. static int qed_enable_msix(struct qed_dev *cdev,
  278. struct qed_int_params *int_params)
  279. {
  280. int i, rc, cnt;
  281. cnt = int_params->in.num_vectors;
  282. for (i = 0; i < cnt; i++)
  283. int_params->msix_table[i].entry = i;
  284. rc = pci_enable_msix_range(cdev->pdev, int_params->msix_table,
  285. int_params->in.min_msix_cnt, cnt);
  286. if (rc < cnt && rc >= int_params->in.min_msix_cnt &&
  287. (rc % cdev->num_hwfns)) {
  288. pci_disable_msix(cdev->pdev);
  289. /* If fastpath is initialized, we need at least one interrupt
  290. * per hwfn [and the slow path interrupts]. New requested number
  291. * should be a multiple of the number of hwfns.
  292. */
  293. cnt = (rc / cdev->num_hwfns) * cdev->num_hwfns;
  294. DP_NOTICE(cdev,
  295. "Trying to enable MSI-X with less vectors (%d out of %d)\n",
  296. cnt, int_params->in.num_vectors);
  297. rc = pci_enable_msix_exact(cdev->pdev,
  298. int_params->msix_table, cnt);
  299. if (!rc)
  300. rc = cnt;
  301. }
  302. if (rc > 0) {
  303. /* MSI-x configuration was achieved */
  304. int_params->out.int_mode = QED_INT_MODE_MSIX;
  305. int_params->out.num_vectors = rc;
  306. rc = 0;
  307. } else {
  308. DP_NOTICE(cdev,
  309. "Failed to enable MSI-X [Requested %d vectors][rc %d]\n",
  310. cnt, rc);
  311. }
  312. return rc;
  313. }
  314. /* This function outputs the int mode and the number of enabled msix vector */
  315. static int qed_set_int_mode(struct qed_dev *cdev, bool force_mode)
  316. {
  317. struct qed_int_params *int_params = &cdev->int_params;
  318. struct msix_entry *tbl;
  319. int rc = 0, cnt;
  320. switch (int_params->in.int_mode) {
  321. case QED_INT_MODE_MSIX:
  322. /* Allocate MSIX table */
  323. cnt = int_params->in.num_vectors;
  324. int_params->msix_table = kcalloc(cnt, sizeof(*tbl), GFP_KERNEL);
  325. if (!int_params->msix_table) {
  326. rc = -ENOMEM;
  327. goto out;
  328. }
  329. /* Enable MSIX */
  330. rc = qed_enable_msix(cdev, int_params);
  331. if (!rc)
  332. goto out;
  333. DP_NOTICE(cdev, "Failed to enable MSI-X\n");
  334. kfree(int_params->msix_table);
  335. if (force_mode)
  336. goto out;
  337. /* Fallthrough */
  338. case QED_INT_MODE_MSI:
  339. rc = pci_enable_msi(cdev->pdev);
  340. if (!rc) {
  341. int_params->out.int_mode = QED_INT_MODE_MSI;
  342. goto out;
  343. }
  344. DP_NOTICE(cdev, "Failed to enable MSI\n");
  345. if (force_mode)
  346. goto out;
  347. /* Fallthrough */
  348. case QED_INT_MODE_INTA:
  349. int_params->out.int_mode = QED_INT_MODE_INTA;
  350. rc = 0;
  351. goto out;
  352. default:
  353. DP_NOTICE(cdev, "Unknown int_mode value %d\n",
  354. int_params->in.int_mode);
  355. rc = -EINVAL;
  356. }
  357. out:
  358. cdev->int_coalescing_mode = QED_COAL_MODE_ENABLE;
  359. return rc;
  360. }
  361. static void qed_simd_handler_config(struct qed_dev *cdev, void *token,
  362. int index, void(*handler)(void *))
  363. {
  364. struct qed_hwfn *hwfn = &cdev->hwfns[index % cdev->num_hwfns];
  365. int relative_idx = index / cdev->num_hwfns;
  366. hwfn->simd_proto_handler[relative_idx].func = handler;
  367. hwfn->simd_proto_handler[relative_idx].token = token;
  368. }
  369. static void qed_simd_handler_clean(struct qed_dev *cdev, int index)
  370. {
  371. struct qed_hwfn *hwfn = &cdev->hwfns[index % cdev->num_hwfns];
  372. int relative_idx = index / cdev->num_hwfns;
  373. memset(&hwfn->simd_proto_handler[relative_idx], 0,
  374. sizeof(struct qed_simd_fp_handler));
  375. }
  376. static irqreturn_t qed_msix_sp_int(int irq, void *tasklet)
  377. {
  378. tasklet_schedule((struct tasklet_struct *)tasklet);
  379. return IRQ_HANDLED;
  380. }
  381. static irqreturn_t qed_single_int(int irq, void *dev_instance)
  382. {
  383. struct qed_dev *cdev = (struct qed_dev *)dev_instance;
  384. struct qed_hwfn *hwfn;
  385. irqreturn_t rc = IRQ_NONE;
  386. u64 status;
  387. int i, j;
  388. for (i = 0; i < cdev->num_hwfns; i++) {
  389. status = qed_int_igu_read_sisr_reg(&cdev->hwfns[i]);
  390. if (!status)
  391. continue;
  392. hwfn = &cdev->hwfns[i];
  393. /* Slowpath interrupt */
  394. if (unlikely(status & 0x1)) {
  395. tasklet_schedule(hwfn->sp_dpc);
  396. status &= ~0x1;
  397. rc = IRQ_HANDLED;
  398. }
  399. /* Fastpath interrupts */
  400. for (j = 0; j < 64; j++) {
  401. if ((0x2ULL << j) & status) {
  402. hwfn->simd_proto_handler[j].func(
  403. hwfn->simd_proto_handler[j].token);
  404. status &= ~(0x2ULL << j);
  405. rc = IRQ_HANDLED;
  406. }
  407. }
  408. if (unlikely(status))
  409. DP_VERBOSE(hwfn, NETIF_MSG_INTR,
  410. "got an unknown interrupt status 0x%llx\n",
  411. status);
  412. }
  413. return rc;
  414. }
  415. int qed_slowpath_irq_req(struct qed_hwfn *hwfn)
  416. {
  417. struct qed_dev *cdev = hwfn->cdev;
  418. int rc = 0;
  419. u8 id;
  420. if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
  421. id = hwfn->my_id;
  422. snprintf(hwfn->name, NAME_SIZE, "sp-%d-%02x:%02x.%02x",
  423. id, cdev->pdev->bus->number,
  424. PCI_SLOT(cdev->pdev->devfn), hwfn->abs_pf_id);
  425. rc = request_irq(cdev->int_params.msix_table[id].vector,
  426. qed_msix_sp_int, 0, hwfn->name, hwfn->sp_dpc);
  427. if (!rc)
  428. DP_VERBOSE(hwfn, (NETIF_MSG_INTR | QED_MSG_SP),
  429. "Requested slowpath MSI-X\n");
  430. } else {
  431. unsigned long flags = 0;
  432. snprintf(cdev->name, NAME_SIZE, "%02x:%02x.%02x",
  433. cdev->pdev->bus->number, PCI_SLOT(cdev->pdev->devfn),
  434. PCI_FUNC(cdev->pdev->devfn));
  435. if (cdev->int_params.out.int_mode == QED_INT_MODE_INTA)
  436. flags |= IRQF_SHARED;
  437. rc = request_irq(cdev->pdev->irq, qed_single_int,
  438. flags, cdev->name, cdev);
  439. }
  440. return rc;
  441. }
  442. static void qed_slowpath_irq_free(struct qed_dev *cdev)
  443. {
  444. int i;
  445. if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
  446. for_each_hwfn(cdev, i) {
  447. if (!cdev->hwfns[i].b_int_requested)
  448. break;
  449. synchronize_irq(cdev->int_params.msix_table[i].vector);
  450. free_irq(cdev->int_params.msix_table[i].vector,
  451. cdev->hwfns[i].sp_dpc);
  452. }
  453. } else {
  454. if (QED_LEADING_HWFN(cdev)->b_int_requested)
  455. free_irq(cdev->pdev->irq, cdev);
  456. }
  457. qed_int_disable_post_isr_release(cdev);
  458. }
  459. static int qed_nic_stop(struct qed_dev *cdev)
  460. {
  461. int i, rc;
  462. rc = qed_hw_stop(cdev);
  463. for (i = 0; i < cdev->num_hwfns; i++) {
  464. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  465. if (p_hwfn->b_sp_dpc_enabled) {
  466. tasklet_disable(p_hwfn->sp_dpc);
  467. p_hwfn->b_sp_dpc_enabled = false;
  468. DP_VERBOSE(cdev, NETIF_MSG_IFDOWN,
  469. "Disabled sp taskelt [hwfn %d] at %p\n",
  470. i, p_hwfn->sp_dpc);
  471. }
  472. }
  473. return rc;
  474. }
  475. static int qed_nic_reset(struct qed_dev *cdev)
  476. {
  477. int rc;
  478. rc = qed_hw_reset(cdev);
  479. if (rc)
  480. return rc;
  481. qed_resc_free(cdev);
  482. return 0;
  483. }
  484. static int qed_nic_setup(struct qed_dev *cdev)
  485. {
  486. int rc;
  487. rc = qed_resc_alloc(cdev);
  488. if (rc)
  489. return rc;
  490. DP_INFO(cdev, "Allocated qed resources\n");
  491. qed_resc_setup(cdev);
  492. return rc;
  493. }
  494. static int qed_set_int_fp(struct qed_dev *cdev, u16 cnt)
  495. {
  496. int limit = 0;
  497. /* Mark the fastpath as free/used */
  498. cdev->int_params.fp_initialized = cnt ? true : false;
  499. if (cdev->int_params.out.int_mode != QED_INT_MODE_MSIX)
  500. limit = cdev->num_hwfns * 63;
  501. else if (cdev->int_params.fp_msix_cnt)
  502. limit = cdev->int_params.fp_msix_cnt;
  503. if (!limit)
  504. return -ENOMEM;
  505. return min_t(int, cnt, limit);
  506. }
  507. static int qed_get_int_fp(struct qed_dev *cdev, struct qed_int_info *info)
  508. {
  509. memset(info, 0, sizeof(struct qed_int_info));
  510. if (!cdev->int_params.fp_initialized) {
  511. DP_INFO(cdev,
  512. "Protocol driver requested interrupt information, but its support is not yet configured\n");
  513. return -EINVAL;
  514. }
  515. /* Need to expose only MSI-X information; Single IRQ is handled solely
  516. * by qed.
  517. */
  518. if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
  519. int msix_base = cdev->int_params.fp_msix_base;
  520. info->msix_cnt = cdev->int_params.fp_msix_cnt;
  521. info->msix = &cdev->int_params.msix_table[msix_base];
  522. }
  523. return 0;
  524. }
  525. static int qed_slowpath_setup_int(struct qed_dev *cdev,
  526. enum qed_int_mode int_mode)
  527. {
  528. struct qed_sb_cnt_info sb_cnt_info;
  529. int rc;
  530. int i;
  531. memset(&cdev->int_params, 0, sizeof(struct qed_int_params));
  532. cdev->int_params.in.int_mode = int_mode;
  533. for_each_hwfn(cdev, i) {
  534. memset(&sb_cnt_info, 0, sizeof(sb_cnt_info));
  535. qed_int_get_num_sbs(&cdev->hwfns[i], &sb_cnt_info);
  536. cdev->int_params.in.num_vectors += sb_cnt_info.sb_cnt;
  537. cdev->int_params.in.num_vectors++; /* slowpath */
  538. }
  539. /* We want a minimum of one slowpath and one fastpath vector per hwfn */
  540. cdev->int_params.in.min_msix_cnt = cdev->num_hwfns * 2;
  541. rc = qed_set_int_mode(cdev, false);
  542. if (rc) {
  543. DP_ERR(cdev, "qed_slowpath_setup_int ERR\n");
  544. return rc;
  545. }
  546. cdev->int_params.fp_msix_base = cdev->num_hwfns;
  547. cdev->int_params.fp_msix_cnt = cdev->int_params.out.num_vectors -
  548. cdev->num_hwfns;
  549. return 0;
  550. }
  551. static int qed_slowpath_vf_setup_int(struct qed_dev *cdev)
  552. {
  553. int rc;
  554. memset(&cdev->int_params, 0, sizeof(struct qed_int_params));
  555. cdev->int_params.in.int_mode = QED_INT_MODE_MSIX;
  556. qed_vf_get_num_rxqs(QED_LEADING_HWFN(cdev),
  557. &cdev->int_params.in.num_vectors);
  558. if (cdev->num_hwfns > 1) {
  559. u8 vectors = 0;
  560. qed_vf_get_num_rxqs(&cdev->hwfns[1], &vectors);
  561. cdev->int_params.in.num_vectors += vectors;
  562. }
  563. /* We want a minimum of one fastpath vector per vf hwfn */
  564. cdev->int_params.in.min_msix_cnt = cdev->num_hwfns;
  565. rc = qed_set_int_mode(cdev, true);
  566. if (rc)
  567. return rc;
  568. cdev->int_params.fp_msix_base = 0;
  569. cdev->int_params.fp_msix_cnt = cdev->int_params.out.num_vectors;
  570. return 0;
  571. }
  572. u32 qed_unzip_data(struct qed_hwfn *p_hwfn, u32 input_len,
  573. u8 *input_buf, u32 max_size, u8 *unzip_buf)
  574. {
  575. int rc;
  576. p_hwfn->stream->next_in = input_buf;
  577. p_hwfn->stream->avail_in = input_len;
  578. p_hwfn->stream->next_out = unzip_buf;
  579. p_hwfn->stream->avail_out = max_size;
  580. rc = zlib_inflateInit2(p_hwfn->stream, MAX_WBITS);
  581. if (rc != Z_OK) {
  582. DP_VERBOSE(p_hwfn, NETIF_MSG_DRV, "zlib init failed, rc = %d\n",
  583. rc);
  584. return 0;
  585. }
  586. rc = zlib_inflate(p_hwfn->stream, Z_FINISH);
  587. zlib_inflateEnd(p_hwfn->stream);
  588. if (rc != Z_OK && rc != Z_STREAM_END) {
  589. DP_VERBOSE(p_hwfn, NETIF_MSG_DRV, "FW unzip error: %s, rc=%d\n",
  590. p_hwfn->stream->msg, rc);
  591. return 0;
  592. }
  593. return p_hwfn->stream->total_out / 4;
  594. }
  595. static int qed_alloc_stream_mem(struct qed_dev *cdev)
  596. {
  597. int i;
  598. void *workspace;
  599. for_each_hwfn(cdev, i) {
  600. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  601. p_hwfn->stream = kzalloc(sizeof(*p_hwfn->stream), GFP_KERNEL);
  602. if (!p_hwfn->stream)
  603. return -ENOMEM;
  604. workspace = vzalloc(zlib_inflate_workspacesize());
  605. if (!workspace)
  606. return -ENOMEM;
  607. p_hwfn->stream->workspace = workspace;
  608. }
  609. return 0;
  610. }
  611. static void qed_free_stream_mem(struct qed_dev *cdev)
  612. {
  613. int i;
  614. for_each_hwfn(cdev, i) {
  615. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  616. if (!p_hwfn->stream)
  617. return;
  618. vfree(p_hwfn->stream->workspace);
  619. kfree(p_hwfn->stream);
  620. }
  621. }
  622. static void qed_update_pf_params(struct qed_dev *cdev,
  623. struct qed_pf_params *params)
  624. {
  625. int i;
  626. for (i = 0; i < cdev->num_hwfns; i++) {
  627. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  628. p_hwfn->pf_params = *params;
  629. }
  630. }
  631. static int qed_slowpath_start(struct qed_dev *cdev,
  632. struct qed_slowpath_params *params)
  633. {
  634. struct qed_tunn_start_params tunn_info;
  635. struct qed_mcp_drv_version drv_version;
  636. const u8 *data = NULL;
  637. struct qed_hwfn *hwfn;
  638. int rc = -EINVAL;
  639. if (qed_iov_wq_start(cdev))
  640. goto err;
  641. if (IS_PF(cdev)) {
  642. rc = request_firmware(&cdev->firmware, QED_FW_FILE_NAME,
  643. &cdev->pdev->dev);
  644. if (rc) {
  645. DP_NOTICE(cdev,
  646. "Failed to find fw file - /lib/firmware/%s\n",
  647. QED_FW_FILE_NAME);
  648. goto err;
  649. }
  650. }
  651. rc = qed_nic_setup(cdev);
  652. if (rc)
  653. goto err;
  654. if (IS_PF(cdev))
  655. rc = qed_slowpath_setup_int(cdev, params->int_mode);
  656. else
  657. rc = qed_slowpath_vf_setup_int(cdev);
  658. if (rc)
  659. goto err1;
  660. if (IS_PF(cdev)) {
  661. /* Allocate stream for unzipping */
  662. rc = qed_alloc_stream_mem(cdev);
  663. if (rc) {
  664. DP_NOTICE(cdev, "Failed to allocate stream memory\n");
  665. goto err2;
  666. }
  667. data = cdev->firmware->data;
  668. }
  669. memset(&tunn_info, 0, sizeof(tunn_info));
  670. tunn_info.tunn_mode |= 1 << QED_MODE_VXLAN_TUNN |
  671. 1 << QED_MODE_L2GRE_TUNN |
  672. 1 << QED_MODE_IPGRE_TUNN |
  673. 1 << QED_MODE_L2GENEVE_TUNN |
  674. 1 << QED_MODE_IPGENEVE_TUNN;
  675. tunn_info.tunn_clss_vxlan = QED_TUNN_CLSS_MAC_VLAN;
  676. tunn_info.tunn_clss_l2gre = QED_TUNN_CLSS_MAC_VLAN;
  677. tunn_info.tunn_clss_ipgre = QED_TUNN_CLSS_MAC_VLAN;
  678. /* Start the slowpath */
  679. rc = qed_hw_init(cdev, &tunn_info, true,
  680. cdev->int_params.out.int_mode,
  681. true, data);
  682. if (rc)
  683. goto err2;
  684. DP_INFO(cdev,
  685. "HW initialization and function start completed successfully\n");
  686. if (IS_PF(cdev)) {
  687. hwfn = QED_LEADING_HWFN(cdev);
  688. drv_version.version = (params->drv_major << 24) |
  689. (params->drv_minor << 16) |
  690. (params->drv_rev << 8) |
  691. (params->drv_eng);
  692. strlcpy(drv_version.name, params->name,
  693. MCP_DRV_VER_STR_SIZE - 4);
  694. rc = qed_mcp_send_drv_version(hwfn, hwfn->p_main_ptt,
  695. &drv_version);
  696. if (rc) {
  697. DP_NOTICE(cdev, "Failed sending drv version command\n");
  698. return rc;
  699. }
  700. }
  701. qed_reset_vport_stats(cdev);
  702. return 0;
  703. err2:
  704. qed_hw_timers_stop_all(cdev);
  705. if (IS_PF(cdev))
  706. qed_slowpath_irq_free(cdev);
  707. qed_free_stream_mem(cdev);
  708. qed_disable_msix(cdev);
  709. err1:
  710. qed_resc_free(cdev);
  711. err:
  712. if (IS_PF(cdev))
  713. release_firmware(cdev->firmware);
  714. qed_iov_wq_stop(cdev, false);
  715. return rc;
  716. }
  717. static int qed_slowpath_stop(struct qed_dev *cdev)
  718. {
  719. if (!cdev)
  720. return -ENODEV;
  721. if (IS_PF(cdev)) {
  722. qed_free_stream_mem(cdev);
  723. qed_sriov_disable(cdev, true);
  724. qed_nic_stop(cdev);
  725. qed_slowpath_irq_free(cdev);
  726. }
  727. qed_disable_msix(cdev);
  728. qed_nic_reset(cdev);
  729. qed_iov_wq_stop(cdev, true);
  730. if (IS_PF(cdev))
  731. release_firmware(cdev->firmware);
  732. return 0;
  733. }
  734. static void qed_set_id(struct qed_dev *cdev, char name[NAME_SIZE],
  735. char ver_str[VER_SIZE])
  736. {
  737. int i;
  738. memcpy(cdev->name, name, NAME_SIZE);
  739. for_each_hwfn(cdev, i)
  740. snprintf(cdev->hwfns[i].name, NAME_SIZE, "%s-%d", name, i);
  741. memcpy(cdev->ver_str, ver_str, VER_SIZE);
  742. cdev->drv_type = DRV_ID_DRV_TYPE_LINUX;
  743. }
  744. static u32 qed_sb_init(struct qed_dev *cdev,
  745. struct qed_sb_info *sb_info,
  746. void *sb_virt_addr,
  747. dma_addr_t sb_phy_addr, u16 sb_id,
  748. enum qed_sb_type type)
  749. {
  750. struct qed_hwfn *p_hwfn;
  751. int hwfn_index;
  752. u16 rel_sb_id;
  753. u8 n_hwfns;
  754. u32 rc;
  755. /* RoCE uses single engine and CMT uses two engines. When using both
  756. * we force only a single engine. Storage uses only engine 0 too.
  757. */
  758. if (type == QED_SB_TYPE_L2_QUEUE)
  759. n_hwfns = cdev->num_hwfns;
  760. else
  761. n_hwfns = 1;
  762. hwfn_index = sb_id % n_hwfns;
  763. p_hwfn = &cdev->hwfns[hwfn_index];
  764. rel_sb_id = sb_id / n_hwfns;
  765. DP_VERBOSE(cdev, NETIF_MSG_INTR,
  766. "hwfn [%d] <--[init]-- SB %04x [0x%04x upper]\n",
  767. hwfn_index, rel_sb_id, sb_id);
  768. rc = qed_int_sb_init(p_hwfn, p_hwfn->p_main_ptt, sb_info,
  769. sb_virt_addr, sb_phy_addr, rel_sb_id);
  770. return rc;
  771. }
  772. static u32 qed_sb_release(struct qed_dev *cdev,
  773. struct qed_sb_info *sb_info,
  774. u16 sb_id)
  775. {
  776. struct qed_hwfn *p_hwfn;
  777. int hwfn_index;
  778. u16 rel_sb_id;
  779. u32 rc;
  780. hwfn_index = sb_id % cdev->num_hwfns;
  781. p_hwfn = &cdev->hwfns[hwfn_index];
  782. rel_sb_id = sb_id / cdev->num_hwfns;
  783. DP_VERBOSE(cdev, NETIF_MSG_INTR,
  784. "hwfn [%d] <--[init]-- SB %04x [0x%04x upper]\n",
  785. hwfn_index, rel_sb_id, sb_id);
  786. rc = qed_int_sb_release(p_hwfn, sb_info, rel_sb_id);
  787. return rc;
  788. }
  789. static bool qed_can_link_change(struct qed_dev *cdev)
  790. {
  791. return true;
  792. }
  793. static int qed_set_link(struct qed_dev *cdev,
  794. struct qed_link_params *params)
  795. {
  796. struct qed_hwfn *hwfn;
  797. struct qed_mcp_link_params *link_params;
  798. struct qed_ptt *ptt;
  799. int rc;
  800. if (!cdev)
  801. return -ENODEV;
  802. if (IS_VF(cdev))
  803. return 0;
  804. /* The link should be set only once per PF */
  805. hwfn = &cdev->hwfns[0];
  806. ptt = qed_ptt_acquire(hwfn);
  807. if (!ptt)
  808. return -EBUSY;
  809. link_params = qed_mcp_get_link_params(hwfn);
  810. if (params->override_flags & QED_LINK_OVERRIDE_SPEED_AUTONEG)
  811. link_params->speed.autoneg = params->autoneg;
  812. if (params->override_flags & QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS) {
  813. link_params->speed.advertised_speeds = 0;
  814. if ((params->adv_speeds & SUPPORTED_1000baseT_Half) ||
  815. (params->adv_speeds & SUPPORTED_1000baseT_Full))
  816. link_params->speed.advertised_speeds |=
  817. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G;
  818. if (params->adv_speeds & SUPPORTED_10000baseKR_Full)
  819. link_params->speed.advertised_speeds |=
  820. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G;
  821. if (params->adv_speeds & SUPPORTED_40000baseLR4_Full)
  822. link_params->speed.advertised_speeds |=
  823. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G;
  824. if (params->adv_speeds & 0)
  825. link_params->speed.advertised_speeds |=
  826. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G;
  827. if (params->adv_speeds & 0)
  828. link_params->speed.advertised_speeds |=
  829. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_100G;
  830. }
  831. if (params->override_flags & QED_LINK_OVERRIDE_SPEED_FORCED_SPEED)
  832. link_params->speed.forced_speed = params->forced_speed;
  833. if (params->override_flags & QED_LINK_OVERRIDE_PAUSE_CONFIG) {
  834. if (params->pause_config & QED_LINK_PAUSE_AUTONEG_ENABLE)
  835. link_params->pause.autoneg = true;
  836. else
  837. link_params->pause.autoneg = false;
  838. if (params->pause_config & QED_LINK_PAUSE_RX_ENABLE)
  839. link_params->pause.forced_rx = true;
  840. else
  841. link_params->pause.forced_rx = false;
  842. if (params->pause_config & QED_LINK_PAUSE_TX_ENABLE)
  843. link_params->pause.forced_tx = true;
  844. else
  845. link_params->pause.forced_tx = false;
  846. }
  847. if (params->override_flags & QED_LINK_OVERRIDE_LOOPBACK_MODE) {
  848. switch (params->loopback_mode) {
  849. case QED_LINK_LOOPBACK_INT_PHY:
  850. link_params->loopback_mode = PMM_LOOPBACK_INT_PHY;
  851. break;
  852. case QED_LINK_LOOPBACK_EXT_PHY:
  853. link_params->loopback_mode = PMM_LOOPBACK_EXT_PHY;
  854. break;
  855. case QED_LINK_LOOPBACK_EXT:
  856. link_params->loopback_mode = PMM_LOOPBACK_EXT;
  857. break;
  858. case QED_LINK_LOOPBACK_MAC:
  859. link_params->loopback_mode = PMM_LOOPBACK_MAC;
  860. break;
  861. default:
  862. link_params->loopback_mode = PMM_LOOPBACK_NONE;
  863. break;
  864. }
  865. }
  866. rc = qed_mcp_set_link(hwfn, ptt, params->link_up);
  867. qed_ptt_release(hwfn, ptt);
  868. return rc;
  869. }
  870. static int qed_get_port_type(u32 media_type)
  871. {
  872. int port_type;
  873. switch (media_type) {
  874. case MEDIA_SFPP_10G_FIBER:
  875. case MEDIA_SFP_1G_FIBER:
  876. case MEDIA_XFP_FIBER:
  877. case MEDIA_KR:
  878. port_type = PORT_FIBRE;
  879. break;
  880. case MEDIA_DA_TWINAX:
  881. port_type = PORT_DA;
  882. break;
  883. case MEDIA_BASE_T:
  884. port_type = PORT_TP;
  885. break;
  886. case MEDIA_NOT_PRESENT:
  887. port_type = PORT_NONE;
  888. break;
  889. case MEDIA_UNSPECIFIED:
  890. default:
  891. port_type = PORT_OTHER;
  892. break;
  893. }
  894. return port_type;
  895. }
  896. static void qed_fill_link(struct qed_hwfn *hwfn,
  897. struct qed_link_output *if_link)
  898. {
  899. struct qed_mcp_link_params params;
  900. struct qed_mcp_link_state link;
  901. struct qed_mcp_link_capabilities link_caps;
  902. u32 media_type;
  903. memset(if_link, 0, sizeof(*if_link));
  904. /* Prepare source inputs */
  905. if (IS_PF(hwfn->cdev)) {
  906. memcpy(&params, qed_mcp_get_link_params(hwfn), sizeof(params));
  907. memcpy(&link, qed_mcp_get_link_state(hwfn), sizeof(link));
  908. memcpy(&link_caps, qed_mcp_get_link_capabilities(hwfn),
  909. sizeof(link_caps));
  910. } else {
  911. qed_vf_get_link_params(hwfn, &params);
  912. qed_vf_get_link_state(hwfn, &link);
  913. qed_vf_get_link_caps(hwfn, &link_caps);
  914. }
  915. /* Set the link parameters to pass to protocol driver */
  916. if (link.link_up)
  917. if_link->link_up = true;
  918. /* TODO - at the moment assume supported and advertised speed equal */
  919. if_link->supported_caps = SUPPORTED_FIBRE;
  920. if (params.speed.autoneg)
  921. if_link->supported_caps |= SUPPORTED_Autoneg;
  922. if (params.pause.autoneg ||
  923. (params.pause.forced_rx && params.pause.forced_tx))
  924. if_link->supported_caps |= SUPPORTED_Asym_Pause;
  925. if (params.pause.autoneg || params.pause.forced_rx ||
  926. params.pause.forced_tx)
  927. if_link->supported_caps |= SUPPORTED_Pause;
  928. if_link->advertised_caps = if_link->supported_caps;
  929. if (params.speed.advertised_speeds &
  930. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G)
  931. if_link->advertised_caps |= SUPPORTED_1000baseT_Half |
  932. SUPPORTED_1000baseT_Full;
  933. if (params.speed.advertised_speeds &
  934. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G)
  935. if_link->advertised_caps |= SUPPORTED_10000baseKR_Full;
  936. if (params.speed.advertised_speeds &
  937. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G)
  938. if_link->advertised_caps |= SUPPORTED_40000baseLR4_Full;
  939. if (params.speed.advertised_speeds &
  940. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G)
  941. if_link->advertised_caps |= 0;
  942. if (params.speed.advertised_speeds &
  943. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_100G)
  944. if_link->advertised_caps |= 0;
  945. if (link_caps.speed_capabilities &
  946. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G)
  947. if_link->supported_caps |= SUPPORTED_1000baseT_Half |
  948. SUPPORTED_1000baseT_Full;
  949. if (link_caps.speed_capabilities &
  950. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G)
  951. if_link->supported_caps |= SUPPORTED_10000baseKR_Full;
  952. if (link_caps.speed_capabilities &
  953. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G)
  954. if_link->supported_caps |= SUPPORTED_40000baseLR4_Full;
  955. if (link_caps.speed_capabilities &
  956. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G)
  957. if_link->supported_caps |= 0;
  958. if (link_caps.speed_capabilities &
  959. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_100G)
  960. if_link->supported_caps |= 0;
  961. if (link.link_up)
  962. if_link->speed = link.speed;
  963. /* TODO - fill duplex properly */
  964. if_link->duplex = DUPLEX_FULL;
  965. qed_mcp_get_media_type(hwfn->cdev, &media_type);
  966. if_link->port = qed_get_port_type(media_type);
  967. if_link->autoneg = params.speed.autoneg;
  968. if (params.pause.autoneg)
  969. if_link->pause_config |= QED_LINK_PAUSE_AUTONEG_ENABLE;
  970. if (params.pause.forced_rx)
  971. if_link->pause_config |= QED_LINK_PAUSE_RX_ENABLE;
  972. if (params.pause.forced_tx)
  973. if_link->pause_config |= QED_LINK_PAUSE_TX_ENABLE;
  974. /* Link partner capabilities */
  975. if (link.partner_adv_speed &
  976. QED_LINK_PARTNER_SPEED_1G_HD)
  977. if_link->lp_caps |= SUPPORTED_1000baseT_Half;
  978. if (link.partner_adv_speed &
  979. QED_LINK_PARTNER_SPEED_1G_FD)
  980. if_link->lp_caps |= SUPPORTED_1000baseT_Full;
  981. if (link.partner_adv_speed &
  982. QED_LINK_PARTNER_SPEED_10G)
  983. if_link->lp_caps |= SUPPORTED_10000baseKR_Full;
  984. if (link.partner_adv_speed &
  985. QED_LINK_PARTNER_SPEED_40G)
  986. if_link->lp_caps |= SUPPORTED_40000baseLR4_Full;
  987. if (link.partner_adv_speed &
  988. QED_LINK_PARTNER_SPEED_50G)
  989. if_link->lp_caps |= 0;
  990. if (link.partner_adv_speed &
  991. QED_LINK_PARTNER_SPEED_100G)
  992. if_link->lp_caps |= 0;
  993. if (link.an_complete)
  994. if_link->lp_caps |= SUPPORTED_Autoneg;
  995. if (link.partner_adv_pause)
  996. if_link->lp_caps |= SUPPORTED_Pause;
  997. if (link.partner_adv_pause == QED_LINK_PARTNER_ASYMMETRIC_PAUSE ||
  998. link.partner_adv_pause == QED_LINK_PARTNER_BOTH_PAUSE)
  999. if_link->lp_caps |= SUPPORTED_Asym_Pause;
  1000. }
  1001. static void qed_get_current_link(struct qed_dev *cdev,
  1002. struct qed_link_output *if_link)
  1003. {
  1004. int i;
  1005. qed_fill_link(&cdev->hwfns[0], if_link);
  1006. for_each_hwfn(cdev, i)
  1007. qed_inform_vf_link_state(&cdev->hwfns[i]);
  1008. }
  1009. void qed_link_update(struct qed_hwfn *hwfn)
  1010. {
  1011. void *cookie = hwfn->cdev->ops_cookie;
  1012. struct qed_common_cb_ops *op = hwfn->cdev->protocol_ops.common;
  1013. struct qed_link_output if_link;
  1014. qed_fill_link(hwfn, &if_link);
  1015. qed_inform_vf_link_state(hwfn);
  1016. if (IS_LEAD_HWFN(hwfn) && cookie)
  1017. op->link_update(cookie, &if_link);
  1018. }
  1019. static int qed_drain(struct qed_dev *cdev)
  1020. {
  1021. struct qed_hwfn *hwfn;
  1022. struct qed_ptt *ptt;
  1023. int i, rc;
  1024. if (IS_VF(cdev))
  1025. return 0;
  1026. for_each_hwfn(cdev, i) {
  1027. hwfn = &cdev->hwfns[i];
  1028. ptt = qed_ptt_acquire(hwfn);
  1029. if (!ptt) {
  1030. DP_NOTICE(hwfn, "Failed to drain NIG; No PTT\n");
  1031. return -EBUSY;
  1032. }
  1033. rc = qed_mcp_drain(hwfn, ptt);
  1034. if (rc)
  1035. return rc;
  1036. qed_ptt_release(hwfn, ptt);
  1037. }
  1038. return 0;
  1039. }
  1040. static int qed_set_led(struct qed_dev *cdev, enum qed_led_mode mode)
  1041. {
  1042. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1043. struct qed_ptt *ptt;
  1044. int status = 0;
  1045. ptt = qed_ptt_acquire(hwfn);
  1046. if (!ptt)
  1047. return -EAGAIN;
  1048. status = qed_mcp_set_led(hwfn, ptt, mode);
  1049. qed_ptt_release(hwfn, ptt);
  1050. return status;
  1051. }
  1052. struct qed_selftest_ops qed_selftest_ops_pass = {
  1053. .selftest_memory = &qed_selftest_memory,
  1054. .selftest_interrupt = &qed_selftest_interrupt,
  1055. .selftest_register = &qed_selftest_register,
  1056. .selftest_clock = &qed_selftest_clock,
  1057. };
  1058. const struct qed_common_ops qed_common_ops_pass = {
  1059. .selftest = &qed_selftest_ops_pass,
  1060. .probe = &qed_probe,
  1061. .remove = &qed_remove,
  1062. .set_power_state = &qed_set_power_state,
  1063. .set_id = &qed_set_id,
  1064. .update_pf_params = &qed_update_pf_params,
  1065. .slowpath_start = &qed_slowpath_start,
  1066. .slowpath_stop = &qed_slowpath_stop,
  1067. .set_fp_int = &qed_set_int_fp,
  1068. .get_fp_int = &qed_get_int_fp,
  1069. .sb_init = &qed_sb_init,
  1070. .sb_release = &qed_sb_release,
  1071. .simd_handler_config = &qed_simd_handler_config,
  1072. .simd_handler_clean = &qed_simd_handler_clean,
  1073. .can_link_change = &qed_can_link_change,
  1074. .set_link = &qed_set_link,
  1075. .get_link = &qed_get_current_link,
  1076. .drain = &qed_drain,
  1077. .update_msglvl = &qed_init_dp,
  1078. .chain_alloc = &qed_chain_alloc,
  1079. .chain_free = &qed_chain_free,
  1080. .set_led = &qed_set_led,
  1081. };