qed_main.c 35 KB

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