qed_main.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393
  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->rdma_supported =
  175. (cdev->hwfns[0].hw_info.personality == QED_PCI_ETH_ROCE);
  176. dev_info->is_mf_default = IS_MF_DEFAULT(&cdev->hwfns[0]);
  177. ether_addr_copy(dev_info->hw_mac, cdev->hwfns[0].hw_info.hw_mac_addr);
  178. if (IS_PF(cdev)) {
  179. dev_info->fw_major = FW_MAJOR_VERSION;
  180. dev_info->fw_minor = FW_MINOR_VERSION;
  181. dev_info->fw_rev = FW_REVISION_VERSION;
  182. dev_info->fw_eng = FW_ENGINEERING_VERSION;
  183. dev_info->mf_mode = cdev->mf_mode;
  184. dev_info->tx_switching = true;
  185. } else {
  186. qed_vf_get_fw_version(&cdev->hwfns[0], &dev_info->fw_major,
  187. &dev_info->fw_minor, &dev_info->fw_rev,
  188. &dev_info->fw_eng);
  189. }
  190. if (IS_PF(cdev)) {
  191. ptt = qed_ptt_acquire(QED_LEADING_HWFN(cdev));
  192. if (ptt) {
  193. qed_mcp_get_mfw_ver(QED_LEADING_HWFN(cdev), ptt,
  194. &dev_info->mfw_rev, NULL);
  195. qed_mcp_get_flash_size(QED_LEADING_HWFN(cdev), ptt,
  196. &dev_info->flash_size);
  197. qed_ptt_release(QED_LEADING_HWFN(cdev), ptt);
  198. }
  199. } else {
  200. qed_mcp_get_mfw_ver(QED_LEADING_HWFN(cdev), NULL,
  201. &dev_info->mfw_rev, NULL);
  202. }
  203. return 0;
  204. }
  205. static void qed_free_cdev(struct qed_dev *cdev)
  206. {
  207. kfree((void *)cdev);
  208. }
  209. static struct qed_dev *qed_alloc_cdev(struct pci_dev *pdev)
  210. {
  211. struct qed_dev *cdev;
  212. cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
  213. if (!cdev)
  214. return cdev;
  215. qed_init_struct(cdev);
  216. return cdev;
  217. }
  218. /* Sets the requested power state */
  219. static int qed_set_power_state(struct qed_dev *cdev,
  220. pci_power_t state)
  221. {
  222. if (!cdev)
  223. return -ENODEV;
  224. DP_VERBOSE(cdev, NETIF_MSG_DRV, "Omitting Power state change\n");
  225. return 0;
  226. }
  227. /* probing */
  228. static struct qed_dev *qed_probe(struct pci_dev *pdev,
  229. struct qed_probe_params *params)
  230. {
  231. struct qed_dev *cdev;
  232. int rc;
  233. cdev = qed_alloc_cdev(pdev);
  234. if (!cdev)
  235. goto err0;
  236. cdev->protocol = params->protocol;
  237. if (params->is_vf)
  238. cdev->b_is_vf = true;
  239. qed_init_dp(cdev, params->dp_module, params->dp_level);
  240. rc = qed_init_pci(cdev, pdev);
  241. if (rc) {
  242. DP_ERR(cdev, "init pci failed\n");
  243. goto err1;
  244. }
  245. DP_INFO(cdev, "PCI init completed successfully\n");
  246. rc = qed_hw_prepare(cdev, QED_PCI_DEFAULT);
  247. if (rc) {
  248. DP_ERR(cdev, "hw prepare failed\n");
  249. goto err2;
  250. }
  251. DP_INFO(cdev, "qed_probe completed successffuly\n");
  252. return cdev;
  253. err2:
  254. qed_free_pci(cdev);
  255. err1:
  256. qed_free_cdev(cdev);
  257. err0:
  258. return NULL;
  259. }
  260. static void qed_remove(struct qed_dev *cdev)
  261. {
  262. if (!cdev)
  263. return;
  264. qed_hw_remove(cdev);
  265. qed_free_pci(cdev);
  266. qed_set_power_state(cdev, PCI_D3hot);
  267. qed_free_cdev(cdev);
  268. }
  269. static void qed_disable_msix(struct qed_dev *cdev)
  270. {
  271. if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
  272. pci_disable_msix(cdev->pdev);
  273. kfree(cdev->int_params.msix_table);
  274. } else if (cdev->int_params.out.int_mode == QED_INT_MODE_MSI) {
  275. pci_disable_msi(cdev->pdev);
  276. }
  277. memset(&cdev->int_params.out, 0, sizeof(struct qed_int_param));
  278. }
  279. static int qed_enable_msix(struct qed_dev *cdev,
  280. struct qed_int_params *int_params)
  281. {
  282. int i, rc, cnt;
  283. cnt = int_params->in.num_vectors;
  284. for (i = 0; i < cnt; i++)
  285. int_params->msix_table[i].entry = i;
  286. rc = pci_enable_msix_range(cdev->pdev, int_params->msix_table,
  287. int_params->in.min_msix_cnt, cnt);
  288. if (rc < cnt && rc >= int_params->in.min_msix_cnt &&
  289. (rc % cdev->num_hwfns)) {
  290. pci_disable_msix(cdev->pdev);
  291. /* If fastpath is initialized, we need at least one interrupt
  292. * per hwfn [and the slow path interrupts]. New requested number
  293. * should be a multiple of the number of hwfns.
  294. */
  295. cnt = (rc / cdev->num_hwfns) * cdev->num_hwfns;
  296. DP_NOTICE(cdev,
  297. "Trying to enable MSI-X with less vectors (%d out of %d)\n",
  298. cnt, int_params->in.num_vectors);
  299. rc = pci_enable_msix_exact(cdev->pdev,
  300. int_params->msix_table, cnt);
  301. if (!rc)
  302. rc = cnt;
  303. }
  304. if (rc > 0) {
  305. /* MSI-x configuration was achieved */
  306. int_params->out.int_mode = QED_INT_MODE_MSIX;
  307. int_params->out.num_vectors = rc;
  308. rc = 0;
  309. } else {
  310. DP_NOTICE(cdev,
  311. "Failed to enable MSI-X [Requested %d vectors][rc %d]\n",
  312. cnt, rc);
  313. }
  314. return rc;
  315. }
  316. /* This function outputs the int mode and the number of enabled msix vector */
  317. static int qed_set_int_mode(struct qed_dev *cdev, bool force_mode)
  318. {
  319. struct qed_int_params *int_params = &cdev->int_params;
  320. struct msix_entry *tbl;
  321. int rc = 0, cnt;
  322. switch (int_params->in.int_mode) {
  323. case QED_INT_MODE_MSIX:
  324. /* Allocate MSIX table */
  325. cnt = int_params->in.num_vectors;
  326. int_params->msix_table = kcalloc(cnt, sizeof(*tbl), GFP_KERNEL);
  327. if (!int_params->msix_table) {
  328. rc = -ENOMEM;
  329. goto out;
  330. }
  331. /* Enable MSIX */
  332. rc = qed_enable_msix(cdev, int_params);
  333. if (!rc)
  334. goto out;
  335. DP_NOTICE(cdev, "Failed to enable MSI-X\n");
  336. kfree(int_params->msix_table);
  337. if (force_mode)
  338. goto out;
  339. /* Fallthrough */
  340. case QED_INT_MODE_MSI:
  341. if (cdev->num_hwfns == 1) {
  342. rc = pci_enable_msi(cdev->pdev);
  343. if (!rc) {
  344. int_params->out.int_mode = QED_INT_MODE_MSI;
  345. goto out;
  346. }
  347. DP_NOTICE(cdev, "Failed to enable MSI\n");
  348. if (force_mode)
  349. goto out;
  350. }
  351. /* Fallthrough */
  352. case QED_INT_MODE_INTA:
  353. int_params->out.int_mode = QED_INT_MODE_INTA;
  354. rc = 0;
  355. goto out;
  356. default:
  357. DP_NOTICE(cdev, "Unknown int_mode value %d\n",
  358. int_params->in.int_mode);
  359. rc = -EINVAL;
  360. }
  361. out:
  362. cdev->int_coalescing_mode = QED_COAL_MODE_ENABLE;
  363. return rc;
  364. }
  365. static void qed_simd_handler_config(struct qed_dev *cdev, void *token,
  366. int index, void(*handler)(void *))
  367. {
  368. struct qed_hwfn *hwfn = &cdev->hwfns[index % cdev->num_hwfns];
  369. int relative_idx = index / cdev->num_hwfns;
  370. hwfn->simd_proto_handler[relative_idx].func = handler;
  371. hwfn->simd_proto_handler[relative_idx].token = token;
  372. }
  373. static void qed_simd_handler_clean(struct qed_dev *cdev, int index)
  374. {
  375. struct qed_hwfn *hwfn = &cdev->hwfns[index % cdev->num_hwfns];
  376. int relative_idx = index / cdev->num_hwfns;
  377. memset(&hwfn->simd_proto_handler[relative_idx], 0,
  378. sizeof(struct qed_simd_fp_handler));
  379. }
  380. static irqreturn_t qed_msix_sp_int(int irq, void *tasklet)
  381. {
  382. tasklet_schedule((struct tasklet_struct *)tasklet);
  383. return IRQ_HANDLED;
  384. }
  385. static irqreturn_t qed_single_int(int irq, void *dev_instance)
  386. {
  387. struct qed_dev *cdev = (struct qed_dev *)dev_instance;
  388. struct qed_hwfn *hwfn;
  389. irqreturn_t rc = IRQ_NONE;
  390. u64 status;
  391. int i, j;
  392. for (i = 0; i < cdev->num_hwfns; i++) {
  393. status = qed_int_igu_read_sisr_reg(&cdev->hwfns[i]);
  394. if (!status)
  395. continue;
  396. hwfn = &cdev->hwfns[i];
  397. /* Slowpath interrupt */
  398. if (unlikely(status & 0x1)) {
  399. tasklet_schedule(hwfn->sp_dpc);
  400. status &= ~0x1;
  401. rc = IRQ_HANDLED;
  402. }
  403. /* Fastpath interrupts */
  404. for (j = 0; j < 64; j++) {
  405. if ((0x2ULL << j) & status) {
  406. hwfn->simd_proto_handler[j].func(
  407. hwfn->simd_proto_handler[j].token);
  408. status &= ~(0x2ULL << j);
  409. rc = IRQ_HANDLED;
  410. }
  411. }
  412. if (unlikely(status))
  413. DP_VERBOSE(hwfn, NETIF_MSG_INTR,
  414. "got an unknown interrupt status 0x%llx\n",
  415. status);
  416. }
  417. return rc;
  418. }
  419. int qed_slowpath_irq_req(struct qed_hwfn *hwfn)
  420. {
  421. struct qed_dev *cdev = hwfn->cdev;
  422. int rc = 0;
  423. u8 id;
  424. if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
  425. id = hwfn->my_id;
  426. snprintf(hwfn->name, NAME_SIZE, "sp-%d-%02x:%02x.%02x",
  427. id, cdev->pdev->bus->number,
  428. PCI_SLOT(cdev->pdev->devfn), hwfn->abs_pf_id);
  429. rc = request_irq(cdev->int_params.msix_table[id].vector,
  430. qed_msix_sp_int, 0, hwfn->name, hwfn->sp_dpc);
  431. if (!rc)
  432. DP_VERBOSE(hwfn, (NETIF_MSG_INTR | QED_MSG_SP),
  433. "Requested slowpath MSI-X\n");
  434. } else {
  435. unsigned long flags = 0;
  436. snprintf(cdev->name, NAME_SIZE, "%02x:%02x.%02x",
  437. cdev->pdev->bus->number, PCI_SLOT(cdev->pdev->devfn),
  438. PCI_FUNC(cdev->pdev->devfn));
  439. if (cdev->int_params.out.int_mode == QED_INT_MODE_INTA)
  440. flags |= IRQF_SHARED;
  441. rc = request_irq(cdev->pdev->irq, qed_single_int,
  442. flags, cdev->name, cdev);
  443. }
  444. return rc;
  445. }
  446. static void qed_slowpath_irq_free(struct qed_dev *cdev)
  447. {
  448. int i;
  449. if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
  450. for_each_hwfn(cdev, i) {
  451. if (!cdev->hwfns[i].b_int_requested)
  452. break;
  453. synchronize_irq(cdev->int_params.msix_table[i].vector);
  454. free_irq(cdev->int_params.msix_table[i].vector,
  455. cdev->hwfns[i].sp_dpc);
  456. }
  457. } else {
  458. if (QED_LEADING_HWFN(cdev)->b_int_requested)
  459. free_irq(cdev->pdev->irq, cdev);
  460. }
  461. qed_int_disable_post_isr_release(cdev);
  462. }
  463. static int qed_nic_stop(struct qed_dev *cdev)
  464. {
  465. int i, rc;
  466. rc = qed_hw_stop(cdev);
  467. for (i = 0; i < cdev->num_hwfns; i++) {
  468. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  469. if (p_hwfn->b_sp_dpc_enabled) {
  470. tasklet_disable(p_hwfn->sp_dpc);
  471. p_hwfn->b_sp_dpc_enabled = false;
  472. DP_VERBOSE(cdev, NETIF_MSG_IFDOWN,
  473. "Disabled sp taskelt [hwfn %d] at %p\n",
  474. i, p_hwfn->sp_dpc);
  475. }
  476. }
  477. return rc;
  478. }
  479. static int qed_nic_reset(struct qed_dev *cdev)
  480. {
  481. int rc;
  482. rc = qed_hw_reset(cdev);
  483. if (rc)
  484. return rc;
  485. qed_resc_free(cdev);
  486. return 0;
  487. }
  488. static int qed_nic_setup(struct qed_dev *cdev)
  489. {
  490. int rc;
  491. rc = qed_resc_alloc(cdev);
  492. if (rc)
  493. return rc;
  494. DP_INFO(cdev, "Allocated qed resources\n");
  495. qed_resc_setup(cdev);
  496. return rc;
  497. }
  498. static int qed_set_int_fp(struct qed_dev *cdev, u16 cnt)
  499. {
  500. int limit = 0;
  501. /* Mark the fastpath as free/used */
  502. cdev->int_params.fp_initialized = cnt ? true : false;
  503. if (cdev->int_params.out.int_mode != QED_INT_MODE_MSIX)
  504. limit = cdev->num_hwfns * 63;
  505. else if (cdev->int_params.fp_msix_cnt)
  506. limit = cdev->int_params.fp_msix_cnt;
  507. if (!limit)
  508. return -ENOMEM;
  509. return min_t(int, cnt, limit);
  510. }
  511. static int qed_get_int_fp(struct qed_dev *cdev, struct qed_int_info *info)
  512. {
  513. memset(info, 0, sizeof(struct qed_int_info));
  514. if (!cdev->int_params.fp_initialized) {
  515. DP_INFO(cdev,
  516. "Protocol driver requested interrupt information, but its support is not yet configured\n");
  517. return -EINVAL;
  518. }
  519. /* Need to expose only MSI-X information; Single IRQ is handled solely
  520. * by qed.
  521. */
  522. if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
  523. int msix_base = cdev->int_params.fp_msix_base;
  524. info->msix_cnt = cdev->int_params.fp_msix_cnt;
  525. info->msix = &cdev->int_params.msix_table[msix_base];
  526. }
  527. return 0;
  528. }
  529. static int qed_slowpath_setup_int(struct qed_dev *cdev,
  530. enum qed_int_mode int_mode)
  531. {
  532. struct qed_sb_cnt_info sb_cnt_info;
  533. int rc;
  534. int i;
  535. if ((int_mode == QED_INT_MODE_MSI) && (cdev->num_hwfns > 1)) {
  536. DP_NOTICE(cdev, "MSI mode is not supported for CMT devices\n");
  537. return -EINVAL;
  538. }
  539. memset(&cdev->int_params, 0, sizeof(struct qed_int_params));
  540. cdev->int_params.in.int_mode = int_mode;
  541. for_each_hwfn(cdev, i) {
  542. memset(&sb_cnt_info, 0, sizeof(sb_cnt_info));
  543. qed_int_get_num_sbs(&cdev->hwfns[i], &sb_cnt_info);
  544. cdev->int_params.in.num_vectors += sb_cnt_info.sb_cnt;
  545. cdev->int_params.in.num_vectors++; /* slowpath */
  546. }
  547. /* We want a minimum of one slowpath and one fastpath vector per hwfn */
  548. cdev->int_params.in.min_msix_cnt = cdev->num_hwfns * 2;
  549. rc = qed_set_int_mode(cdev, false);
  550. if (rc) {
  551. DP_ERR(cdev, "qed_slowpath_setup_int ERR\n");
  552. return rc;
  553. }
  554. cdev->int_params.fp_msix_base = cdev->num_hwfns;
  555. cdev->int_params.fp_msix_cnt = cdev->int_params.out.num_vectors -
  556. cdev->num_hwfns;
  557. return 0;
  558. }
  559. static int qed_slowpath_vf_setup_int(struct qed_dev *cdev)
  560. {
  561. int rc;
  562. memset(&cdev->int_params, 0, sizeof(struct qed_int_params));
  563. cdev->int_params.in.int_mode = QED_INT_MODE_MSIX;
  564. qed_vf_get_num_rxqs(QED_LEADING_HWFN(cdev),
  565. &cdev->int_params.in.num_vectors);
  566. if (cdev->num_hwfns > 1) {
  567. u8 vectors = 0;
  568. qed_vf_get_num_rxqs(&cdev->hwfns[1], &vectors);
  569. cdev->int_params.in.num_vectors += vectors;
  570. }
  571. /* We want a minimum of one fastpath vector per vf hwfn */
  572. cdev->int_params.in.min_msix_cnt = cdev->num_hwfns;
  573. rc = qed_set_int_mode(cdev, true);
  574. if (rc)
  575. return rc;
  576. cdev->int_params.fp_msix_base = 0;
  577. cdev->int_params.fp_msix_cnt = cdev->int_params.out.num_vectors;
  578. return 0;
  579. }
  580. u32 qed_unzip_data(struct qed_hwfn *p_hwfn, u32 input_len,
  581. u8 *input_buf, u32 max_size, u8 *unzip_buf)
  582. {
  583. int rc;
  584. p_hwfn->stream->next_in = input_buf;
  585. p_hwfn->stream->avail_in = input_len;
  586. p_hwfn->stream->next_out = unzip_buf;
  587. p_hwfn->stream->avail_out = max_size;
  588. rc = zlib_inflateInit2(p_hwfn->stream, MAX_WBITS);
  589. if (rc != Z_OK) {
  590. DP_VERBOSE(p_hwfn, NETIF_MSG_DRV, "zlib init failed, rc = %d\n",
  591. rc);
  592. return 0;
  593. }
  594. rc = zlib_inflate(p_hwfn->stream, Z_FINISH);
  595. zlib_inflateEnd(p_hwfn->stream);
  596. if (rc != Z_OK && rc != Z_STREAM_END) {
  597. DP_VERBOSE(p_hwfn, NETIF_MSG_DRV, "FW unzip error: %s, rc=%d\n",
  598. p_hwfn->stream->msg, rc);
  599. return 0;
  600. }
  601. return p_hwfn->stream->total_out / 4;
  602. }
  603. static int qed_alloc_stream_mem(struct qed_dev *cdev)
  604. {
  605. int i;
  606. void *workspace;
  607. for_each_hwfn(cdev, i) {
  608. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  609. p_hwfn->stream = kzalloc(sizeof(*p_hwfn->stream), GFP_KERNEL);
  610. if (!p_hwfn->stream)
  611. return -ENOMEM;
  612. workspace = vzalloc(zlib_inflate_workspacesize());
  613. if (!workspace)
  614. return -ENOMEM;
  615. p_hwfn->stream->workspace = workspace;
  616. }
  617. return 0;
  618. }
  619. static void qed_free_stream_mem(struct qed_dev *cdev)
  620. {
  621. int i;
  622. for_each_hwfn(cdev, i) {
  623. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  624. if (!p_hwfn->stream)
  625. return;
  626. vfree(p_hwfn->stream->workspace);
  627. kfree(p_hwfn->stream);
  628. }
  629. }
  630. static void qed_update_pf_params(struct qed_dev *cdev,
  631. struct qed_pf_params *params)
  632. {
  633. int i;
  634. for (i = 0; i < cdev->num_hwfns; i++) {
  635. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  636. p_hwfn->pf_params = *params;
  637. }
  638. }
  639. static int qed_slowpath_start(struct qed_dev *cdev,
  640. struct qed_slowpath_params *params)
  641. {
  642. struct qed_tunn_start_params tunn_info;
  643. struct qed_mcp_drv_version drv_version;
  644. const u8 *data = NULL;
  645. struct qed_hwfn *hwfn;
  646. int rc = -EINVAL;
  647. if (qed_iov_wq_start(cdev))
  648. goto err;
  649. if (IS_PF(cdev)) {
  650. rc = request_firmware(&cdev->firmware, QED_FW_FILE_NAME,
  651. &cdev->pdev->dev);
  652. if (rc) {
  653. DP_NOTICE(cdev,
  654. "Failed to find fw file - /lib/firmware/%s\n",
  655. QED_FW_FILE_NAME);
  656. goto err;
  657. }
  658. }
  659. rc = qed_nic_setup(cdev);
  660. if (rc)
  661. goto err;
  662. if (IS_PF(cdev))
  663. rc = qed_slowpath_setup_int(cdev, params->int_mode);
  664. else
  665. rc = qed_slowpath_vf_setup_int(cdev);
  666. if (rc)
  667. goto err1;
  668. if (IS_PF(cdev)) {
  669. /* Allocate stream for unzipping */
  670. rc = qed_alloc_stream_mem(cdev);
  671. if (rc) {
  672. DP_NOTICE(cdev, "Failed to allocate stream memory\n");
  673. goto err2;
  674. }
  675. /* First Dword used to diffrentiate between various sources */
  676. data = cdev->firmware->data + sizeof(u32);
  677. }
  678. memset(&tunn_info, 0, sizeof(tunn_info));
  679. tunn_info.tunn_mode |= 1 << QED_MODE_VXLAN_TUNN |
  680. 1 << QED_MODE_L2GRE_TUNN |
  681. 1 << QED_MODE_IPGRE_TUNN |
  682. 1 << QED_MODE_L2GENEVE_TUNN |
  683. 1 << QED_MODE_IPGENEVE_TUNN;
  684. tunn_info.tunn_clss_vxlan = QED_TUNN_CLSS_MAC_VLAN;
  685. tunn_info.tunn_clss_l2gre = QED_TUNN_CLSS_MAC_VLAN;
  686. tunn_info.tunn_clss_ipgre = QED_TUNN_CLSS_MAC_VLAN;
  687. /* Start the slowpath */
  688. rc = qed_hw_init(cdev, &tunn_info, true,
  689. cdev->int_params.out.int_mode,
  690. true, data);
  691. if (rc)
  692. goto err2;
  693. DP_INFO(cdev,
  694. "HW initialization and function start completed successfully\n");
  695. if (IS_PF(cdev)) {
  696. hwfn = QED_LEADING_HWFN(cdev);
  697. drv_version.version = (params->drv_major << 24) |
  698. (params->drv_minor << 16) |
  699. (params->drv_rev << 8) |
  700. (params->drv_eng);
  701. strlcpy(drv_version.name, params->name,
  702. MCP_DRV_VER_STR_SIZE - 4);
  703. rc = qed_mcp_send_drv_version(hwfn, hwfn->p_main_ptt,
  704. &drv_version);
  705. if (rc) {
  706. DP_NOTICE(cdev, "Failed sending drv version command\n");
  707. return rc;
  708. }
  709. }
  710. qed_reset_vport_stats(cdev);
  711. return 0;
  712. err2:
  713. qed_hw_timers_stop_all(cdev);
  714. if (IS_PF(cdev))
  715. qed_slowpath_irq_free(cdev);
  716. qed_free_stream_mem(cdev);
  717. qed_disable_msix(cdev);
  718. err1:
  719. qed_resc_free(cdev);
  720. err:
  721. if (IS_PF(cdev))
  722. release_firmware(cdev->firmware);
  723. qed_iov_wq_stop(cdev, false);
  724. return rc;
  725. }
  726. static int qed_slowpath_stop(struct qed_dev *cdev)
  727. {
  728. if (!cdev)
  729. return -ENODEV;
  730. if (IS_PF(cdev)) {
  731. qed_free_stream_mem(cdev);
  732. if (IS_QED_ETH_IF(cdev))
  733. qed_sriov_disable(cdev, true);
  734. qed_nic_stop(cdev);
  735. qed_slowpath_irq_free(cdev);
  736. }
  737. qed_disable_msix(cdev);
  738. qed_nic_reset(cdev);
  739. qed_iov_wq_stop(cdev, true);
  740. if (IS_PF(cdev))
  741. release_firmware(cdev->firmware);
  742. return 0;
  743. }
  744. static void qed_set_id(struct qed_dev *cdev, char name[NAME_SIZE],
  745. char ver_str[VER_SIZE])
  746. {
  747. int i;
  748. memcpy(cdev->name, name, NAME_SIZE);
  749. for_each_hwfn(cdev, i)
  750. snprintf(cdev->hwfns[i].name, NAME_SIZE, "%s-%d", name, i);
  751. memcpy(cdev->ver_str, ver_str, VER_SIZE);
  752. cdev->drv_type = DRV_ID_DRV_TYPE_LINUX;
  753. }
  754. static u32 qed_sb_init(struct qed_dev *cdev,
  755. struct qed_sb_info *sb_info,
  756. void *sb_virt_addr,
  757. dma_addr_t sb_phy_addr, u16 sb_id,
  758. enum qed_sb_type type)
  759. {
  760. struct qed_hwfn *p_hwfn;
  761. int hwfn_index;
  762. u16 rel_sb_id;
  763. u8 n_hwfns;
  764. u32 rc;
  765. /* RoCE uses single engine and CMT uses two engines. When using both
  766. * we force only a single engine. Storage uses only engine 0 too.
  767. */
  768. if (type == QED_SB_TYPE_L2_QUEUE)
  769. n_hwfns = cdev->num_hwfns;
  770. else
  771. n_hwfns = 1;
  772. hwfn_index = sb_id % n_hwfns;
  773. p_hwfn = &cdev->hwfns[hwfn_index];
  774. rel_sb_id = sb_id / n_hwfns;
  775. DP_VERBOSE(cdev, NETIF_MSG_INTR,
  776. "hwfn [%d] <--[init]-- SB %04x [0x%04x upper]\n",
  777. hwfn_index, rel_sb_id, sb_id);
  778. rc = qed_int_sb_init(p_hwfn, p_hwfn->p_main_ptt, sb_info,
  779. sb_virt_addr, sb_phy_addr, rel_sb_id);
  780. return rc;
  781. }
  782. static u32 qed_sb_release(struct qed_dev *cdev,
  783. struct qed_sb_info *sb_info,
  784. u16 sb_id)
  785. {
  786. struct qed_hwfn *p_hwfn;
  787. int hwfn_index;
  788. u16 rel_sb_id;
  789. u32 rc;
  790. hwfn_index = sb_id % cdev->num_hwfns;
  791. p_hwfn = &cdev->hwfns[hwfn_index];
  792. rel_sb_id = sb_id / cdev->num_hwfns;
  793. DP_VERBOSE(cdev, NETIF_MSG_INTR,
  794. "hwfn [%d] <--[init]-- SB %04x [0x%04x upper]\n",
  795. hwfn_index, rel_sb_id, sb_id);
  796. rc = qed_int_sb_release(p_hwfn, sb_info, rel_sb_id);
  797. return rc;
  798. }
  799. static bool qed_can_link_change(struct qed_dev *cdev)
  800. {
  801. return true;
  802. }
  803. static int qed_set_link(struct qed_dev *cdev, struct qed_link_params *params)
  804. {
  805. struct qed_hwfn *hwfn;
  806. struct qed_mcp_link_params *link_params;
  807. struct qed_ptt *ptt;
  808. int rc;
  809. if (!cdev)
  810. return -ENODEV;
  811. if (IS_VF(cdev))
  812. return 0;
  813. /* The link should be set only once per PF */
  814. hwfn = &cdev->hwfns[0];
  815. ptt = qed_ptt_acquire(hwfn);
  816. if (!ptt)
  817. return -EBUSY;
  818. link_params = qed_mcp_get_link_params(hwfn);
  819. if (params->override_flags & QED_LINK_OVERRIDE_SPEED_AUTONEG)
  820. link_params->speed.autoneg = params->autoneg;
  821. if (params->override_flags & QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS) {
  822. link_params->speed.advertised_speeds = 0;
  823. if ((params->adv_speeds & SUPPORTED_1000baseT_Half) ||
  824. (params->adv_speeds & SUPPORTED_1000baseT_Full))
  825. link_params->speed.advertised_speeds |=
  826. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G;
  827. if (params->adv_speeds & SUPPORTED_10000baseKR_Full)
  828. link_params->speed.advertised_speeds |=
  829. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G;
  830. if (params->adv_speeds & SUPPORTED_40000baseLR4_Full)
  831. link_params->speed.advertised_speeds |=
  832. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G;
  833. if (params->adv_speeds & 0)
  834. link_params->speed.advertised_speeds |=
  835. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G;
  836. if (params->adv_speeds & 0)
  837. link_params->speed.advertised_speeds |=
  838. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_BB_100G;
  839. }
  840. if (params->override_flags & QED_LINK_OVERRIDE_SPEED_FORCED_SPEED)
  841. link_params->speed.forced_speed = params->forced_speed;
  842. if (params->override_flags & QED_LINK_OVERRIDE_PAUSE_CONFIG) {
  843. if (params->pause_config & QED_LINK_PAUSE_AUTONEG_ENABLE)
  844. link_params->pause.autoneg = true;
  845. else
  846. link_params->pause.autoneg = false;
  847. if (params->pause_config & QED_LINK_PAUSE_RX_ENABLE)
  848. link_params->pause.forced_rx = true;
  849. else
  850. link_params->pause.forced_rx = false;
  851. if (params->pause_config & QED_LINK_PAUSE_TX_ENABLE)
  852. link_params->pause.forced_tx = true;
  853. else
  854. link_params->pause.forced_tx = false;
  855. }
  856. if (params->override_flags & QED_LINK_OVERRIDE_LOOPBACK_MODE) {
  857. switch (params->loopback_mode) {
  858. case QED_LINK_LOOPBACK_INT_PHY:
  859. link_params->loopback_mode = ETH_LOOPBACK_INT_PHY;
  860. break;
  861. case QED_LINK_LOOPBACK_EXT_PHY:
  862. link_params->loopback_mode = ETH_LOOPBACK_EXT_PHY;
  863. break;
  864. case QED_LINK_LOOPBACK_EXT:
  865. link_params->loopback_mode = ETH_LOOPBACK_EXT;
  866. break;
  867. case QED_LINK_LOOPBACK_MAC:
  868. link_params->loopback_mode = ETH_LOOPBACK_MAC;
  869. break;
  870. default:
  871. link_params->loopback_mode = ETH_LOOPBACK_NONE;
  872. break;
  873. }
  874. }
  875. rc = qed_mcp_set_link(hwfn, ptt, params->link_up);
  876. qed_ptt_release(hwfn, ptt);
  877. return rc;
  878. }
  879. static int qed_get_port_type(u32 media_type)
  880. {
  881. int port_type;
  882. switch (media_type) {
  883. case MEDIA_SFPP_10G_FIBER:
  884. case MEDIA_SFP_1G_FIBER:
  885. case MEDIA_XFP_FIBER:
  886. case MEDIA_MODULE_FIBER:
  887. case MEDIA_KR:
  888. port_type = PORT_FIBRE;
  889. break;
  890. case MEDIA_DA_TWINAX:
  891. port_type = PORT_DA;
  892. break;
  893. case MEDIA_BASE_T:
  894. port_type = PORT_TP;
  895. break;
  896. case MEDIA_NOT_PRESENT:
  897. port_type = PORT_NONE;
  898. break;
  899. case MEDIA_UNSPECIFIED:
  900. default:
  901. port_type = PORT_OTHER;
  902. break;
  903. }
  904. return port_type;
  905. }
  906. static int qed_get_link_data(struct qed_hwfn *hwfn,
  907. struct qed_mcp_link_params *params,
  908. struct qed_mcp_link_state *link,
  909. struct qed_mcp_link_capabilities *link_caps)
  910. {
  911. void *p;
  912. if (!IS_PF(hwfn->cdev)) {
  913. qed_vf_get_link_params(hwfn, params);
  914. qed_vf_get_link_state(hwfn, link);
  915. qed_vf_get_link_caps(hwfn, link_caps);
  916. return 0;
  917. }
  918. p = qed_mcp_get_link_params(hwfn);
  919. if (!p)
  920. return -ENXIO;
  921. memcpy(params, p, sizeof(*params));
  922. p = qed_mcp_get_link_state(hwfn);
  923. if (!p)
  924. return -ENXIO;
  925. memcpy(link, p, sizeof(*link));
  926. p = qed_mcp_get_link_capabilities(hwfn);
  927. if (!p)
  928. return -ENXIO;
  929. memcpy(link_caps, p, sizeof(*link_caps));
  930. return 0;
  931. }
  932. static void qed_fill_link(struct qed_hwfn *hwfn,
  933. struct qed_link_output *if_link)
  934. {
  935. struct qed_mcp_link_params params;
  936. struct qed_mcp_link_state link;
  937. struct qed_mcp_link_capabilities link_caps;
  938. u32 media_type;
  939. memset(if_link, 0, sizeof(*if_link));
  940. /* Prepare source inputs */
  941. if (qed_get_link_data(hwfn, &params, &link, &link_caps)) {
  942. dev_warn(&hwfn->cdev->pdev->dev, "no link data available\n");
  943. return;
  944. }
  945. /* Set the link parameters to pass to protocol driver */
  946. if (link.link_up)
  947. if_link->link_up = true;
  948. /* TODO - at the moment assume supported and advertised speed equal */
  949. if_link->supported_caps = SUPPORTED_FIBRE;
  950. if (params.speed.autoneg)
  951. if_link->supported_caps |= SUPPORTED_Autoneg;
  952. if (params.pause.autoneg ||
  953. (params.pause.forced_rx && params.pause.forced_tx))
  954. if_link->supported_caps |= SUPPORTED_Asym_Pause;
  955. if (params.pause.autoneg || params.pause.forced_rx ||
  956. params.pause.forced_tx)
  957. if_link->supported_caps |= SUPPORTED_Pause;
  958. if_link->advertised_caps = if_link->supported_caps;
  959. if (params.speed.advertised_speeds &
  960. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G)
  961. if_link->advertised_caps |= SUPPORTED_1000baseT_Half |
  962. SUPPORTED_1000baseT_Full;
  963. if (params.speed.advertised_speeds &
  964. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G)
  965. if_link->advertised_caps |= SUPPORTED_10000baseKR_Full;
  966. if (params.speed.advertised_speeds &
  967. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G)
  968. if_link->advertised_caps |= SUPPORTED_40000baseLR4_Full;
  969. if (params.speed.advertised_speeds &
  970. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G)
  971. if_link->advertised_caps |= 0;
  972. if (params.speed.advertised_speeds &
  973. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_BB_100G)
  974. if_link->advertised_caps |= 0;
  975. if (link_caps.speed_capabilities &
  976. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G)
  977. if_link->supported_caps |= SUPPORTED_1000baseT_Half |
  978. SUPPORTED_1000baseT_Full;
  979. if (link_caps.speed_capabilities &
  980. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G)
  981. if_link->supported_caps |= SUPPORTED_10000baseKR_Full;
  982. if (link_caps.speed_capabilities &
  983. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G)
  984. if_link->supported_caps |= SUPPORTED_40000baseLR4_Full;
  985. if (link_caps.speed_capabilities &
  986. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G)
  987. if_link->supported_caps |= 0;
  988. if (link_caps.speed_capabilities &
  989. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_BB_100G)
  990. if_link->supported_caps |= 0;
  991. if (link.link_up)
  992. if_link->speed = link.speed;
  993. /* TODO - fill duplex properly */
  994. if_link->duplex = DUPLEX_FULL;
  995. qed_mcp_get_media_type(hwfn->cdev, &media_type);
  996. if_link->port = qed_get_port_type(media_type);
  997. if_link->autoneg = params.speed.autoneg;
  998. if (params.pause.autoneg)
  999. if_link->pause_config |= QED_LINK_PAUSE_AUTONEG_ENABLE;
  1000. if (params.pause.forced_rx)
  1001. if_link->pause_config |= QED_LINK_PAUSE_RX_ENABLE;
  1002. if (params.pause.forced_tx)
  1003. if_link->pause_config |= QED_LINK_PAUSE_TX_ENABLE;
  1004. /* Link partner capabilities */
  1005. if (link.partner_adv_speed &
  1006. QED_LINK_PARTNER_SPEED_1G_HD)
  1007. if_link->lp_caps |= SUPPORTED_1000baseT_Half;
  1008. if (link.partner_adv_speed &
  1009. QED_LINK_PARTNER_SPEED_1G_FD)
  1010. if_link->lp_caps |= SUPPORTED_1000baseT_Full;
  1011. if (link.partner_adv_speed &
  1012. QED_LINK_PARTNER_SPEED_10G)
  1013. if_link->lp_caps |= SUPPORTED_10000baseKR_Full;
  1014. if (link.partner_adv_speed &
  1015. QED_LINK_PARTNER_SPEED_40G)
  1016. if_link->lp_caps |= SUPPORTED_40000baseLR4_Full;
  1017. if (link.partner_adv_speed &
  1018. QED_LINK_PARTNER_SPEED_50G)
  1019. if_link->lp_caps |= 0;
  1020. if (link.partner_adv_speed &
  1021. QED_LINK_PARTNER_SPEED_100G)
  1022. if_link->lp_caps |= 0;
  1023. if (link.an_complete)
  1024. if_link->lp_caps |= SUPPORTED_Autoneg;
  1025. if (link.partner_adv_pause)
  1026. if_link->lp_caps |= SUPPORTED_Pause;
  1027. if (link.partner_adv_pause == QED_LINK_PARTNER_ASYMMETRIC_PAUSE ||
  1028. link.partner_adv_pause == QED_LINK_PARTNER_BOTH_PAUSE)
  1029. if_link->lp_caps |= SUPPORTED_Asym_Pause;
  1030. }
  1031. static void qed_get_current_link(struct qed_dev *cdev,
  1032. struct qed_link_output *if_link)
  1033. {
  1034. int i;
  1035. qed_fill_link(&cdev->hwfns[0], if_link);
  1036. for_each_hwfn(cdev, i)
  1037. qed_inform_vf_link_state(&cdev->hwfns[i]);
  1038. }
  1039. void qed_link_update(struct qed_hwfn *hwfn)
  1040. {
  1041. void *cookie = hwfn->cdev->ops_cookie;
  1042. struct qed_common_cb_ops *op = hwfn->cdev->protocol_ops.common;
  1043. struct qed_link_output if_link;
  1044. qed_fill_link(hwfn, &if_link);
  1045. qed_inform_vf_link_state(hwfn);
  1046. if (IS_LEAD_HWFN(hwfn) && cookie)
  1047. op->link_update(cookie, &if_link);
  1048. }
  1049. static int qed_drain(struct qed_dev *cdev)
  1050. {
  1051. struct qed_hwfn *hwfn;
  1052. struct qed_ptt *ptt;
  1053. int i, rc;
  1054. if (IS_VF(cdev))
  1055. return 0;
  1056. for_each_hwfn(cdev, i) {
  1057. hwfn = &cdev->hwfns[i];
  1058. ptt = qed_ptt_acquire(hwfn);
  1059. if (!ptt) {
  1060. DP_NOTICE(hwfn, "Failed to drain NIG; No PTT\n");
  1061. return -EBUSY;
  1062. }
  1063. rc = qed_mcp_drain(hwfn, ptt);
  1064. if (rc)
  1065. return rc;
  1066. qed_ptt_release(hwfn, ptt);
  1067. }
  1068. return 0;
  1069. }
  1070. static void qed_get_coalesce(struct qed_dev *cdev, u16 *rx_coal, u16 *tx_coal)
  1071. {
  1072. *rx_coal = cdev->rx_coalesce_usecs;
  1073. *tx_coal = cdev->tx_coalesce_usecs;
  1074. }
  1075. static int qed_set_coalesce(struct qed_dev *cdev, u16 rx_coal, u16 tx_coal,
  1076. u8 qid, u16 sb_id)
  1077. {
  1078. struct qed_hwfn *hwfn;
  1079. struct qed_ptt *ptt;
  1080. int hwfn_index;
  1081. int status = 0;
  1082. hwfn_index = qid % cdev->num_hwfns;
  1083. hwfn = &cdev->hwfns[hwfn_index];
  1084. ptt = qed_ptt_acquire(hwfn);
  1085. if (!ptt)
  1086. return -EAGAIN;
  1087. status = qed_set_rxq_coalesce(hwfn, ptt, rx_coal,
  1088. qid / cdev->num_hwfns, sb_id);
  1089. if (status)
  1090. goto out;
  1091. status = qed_set_txq_coalesce(hwfn, ptt, tx_coal,
  1092. qid / cdev->num_hwfns, sb_id);
  1093. out:
  1094. qed_ptt_release(hwfn, ptt);
  1095. return status;
  1096. }
  1097. static int qed_set_led(struct qed_dev *cdev, enum qed_led_mode mode)
  1098. {
  1099. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1100. struct qed_ptt *ptt;
  1101. int status = 0;
  1102. ptt = qed_ptt_acquire(hwfn);
  1103. if (!ptt)
  1104. return -EAGAIN;
  1105. status = qed_mcp_set_led(hwfn, ptt, mode);
  1106. qed_ptt_release(hwfn, ptt);
  1107. return status;
  1108. }
  1109. struct qed_selftest_ops qed_selftest_ops_pass = {
  1110. .selftest_memory = &qed_selftest_memory,
  1111. .selftest_interrupt = &qed_selftest_interrupt,
  1112. .selftest_register = &qed_selftest_register,
  1113. .selftest_clock = &qed_selftest_clock,
  1114. };
  1115. const struct qed_common_ops qed_common_ops_pass = {
  1116. .selftest = &qed_selftest_ops_pass,
  1117. .probe = &qed_probe,
  1118. .remove = &qed_remove,
  1119. .set_power_state = &qed_set_power_state,
  1120. .set_id = &qed_set_id,
  1121. .update_pf_params = &qed_update_pf_params,
  1122. .slowpath_start = &qed_slowpath_start,
  1123. .slowpath_stop = &qed_slowpath_stop,
  1124. .set_fp_int = &qed_set_int_fp,
  1125. .get_fp_int = &qed_get_int_fp,
  1126. .sb_init = &qed_sb_init,
  1127. .sb_release = &qed_sb_release,
  1128. .simd_handler_config = &qed_simd_handler_config,
  1129. .simd_handler_clean = &qed_simd_handler_clean,
  1130. .can_link_change = &qed_can_link_change,
  1131. .set_link = &qed_set_link,
  1132. .get_link = &qed_get_current_link,
  1133. .drain = &qed_drain,
  1134. .update_msglvl = &qed_init_dp,
  1135. .chain_alloc = &qed_chain_alloc,
  1136. .chain_free = &qed_chain_free,
  1137. .get_coalesce = &qed_get_coalesce,
  1138. .set_coalesce = &qed_set_coalesce,
  1139. .set_led = &qed_set_led,
  1140. };