qed_main.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759
  1. /* QLogic qed NIC Driver
  2. * Copyright (c) 2015-2017 QLogic Corporation
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and /or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #include <linux/stddef.h>
  33. #include <linux/pci.h>
  34. #include <linux/kernel.h>
  35. #include <linux/slab.h>
  36. #include <linux/delay.h>
  37. #include <asm/byteorder.h>
  38. #include <linux/dma-mapping.h>
  39. #include <linux/string.h>
  40. #include <linux/module.h>
  41. #include <linux/interrupt.h>
  42. #include <linux/workqueue.h>
  43. #include <linux/ethtool.h>
  44. #include <linux/etherdevice.h>
  45. #include <linux/vmalloc.h>
  46. #include <linux/crash_dump.h>
  47. #include <linux/qed/qed_if.h>
  48. #include <linux/qed/qed_ll2_if.h>
  49. #include "qed.h"
  50. #include "qed_sriov.h"
  51. #include "qed_sp.h"
  52. #include "qed_dev_api.h"
  53. #include "qed_ll2.h"
  54. #include "qed_fcoe.h"
  55. #include "qed_iscsi.h"
  56. #include "qed_mcp.h"
  57. #include "qed_hw.h"
  58. #include "qed_selftest.h"
  59. #include "qed_debug.h"
  60. #define QED_ROCE_QPS (8192)
  61. #define QED_ROCE_DPIS (8)
  62. static char version[] =
  63. "QLogic FastLinQ 4xxxx Core Module qed " DRV_MODULE_VERSION "\n";
  64. MODULE_DESCRIPTION("QLogic FastLinQ 4xxxx Core Module");
  65. MODULE_LICENSE("GPL");
  66. MODULE_VERSION(DRV_MODULE_VERSION);
  67. #define FW_FILE_VERSION \
  68. __stringify(FW_MAJOR_VERSION) "." \
  69. __stringify(FW_MINOR_VERSION) "." \
  70. __stringify(FW_REVISION_VERSION) "." \
  71. __stringify(FW_ENGINEERING_VERSION)
  72. #define QED_FW_FILE_NAME \
  73. "qed/qed_init_values_zipped-" FW_FILE_VERSION ".bin"
  74. MODULE_FIRMWARE(QED_FW_FILE_NAME);
  75. static int __init qed_init(void)
  76. {
  77. pr_info("%s", version);
  78. return 0;
  79. }
  80. static void __exit qed_cleanup(void)
  81. {
  82. pr_notice("qed_cleanup called\n");
  83. }
  84. module_init(qed_init);
  85. module_exit(qed_cleanup);
  86. /* Check if the DMA controller on the machine can properly handle the DMA
  87. * addressing required by the device.
  88. */
  89. static int qed_set_coherency_mask(struct qed_dev *cdev)
  90. {
  91. struct device *dev = &cdev->pdev->dev;
  92. if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
  93. if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
  94. DP_NOTICE(cdev,
  95. "Can't request 64-bit consistent allocations\n");
  96. return -EIO;
  97. }
  98. } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
  99. DP_NOTICE(cdev, "Can't request 64b/32b DMA addresses\n");
  100. return -EIO;
  101. }
  102. return 0;
  103. }
  104. static void qed_free_pci(struct qed_dev *cdev)
  105. {
  106. struct pci_dev *pdev = cdev->pdev;
  107. if (cdev->doorbells && cdev->db_size)
  108. iounmap(cdev->doorbells);
  109. if (cdev->regview)
  110. iounmap(cdev->regview);
  111. if (atomic_read(&pdev->enable_cnt) == 1)
  112. pci_release_regions(pdev);
  113. pci_disable_device(pdev);
  114. }
  115. #define PCI_REVISION_ID_ERROR_VAL 0xff
  116. /* Performs PCI initializations as well as initializing PCI-related parameters
  117. * in the device structrue. Returns 0 in case of success.
  118. */
  119. static int qed_init_pci(struct qed_dev *cdev, struct pci_dev *pdev)
  120. {
  121. u8 rev_id;
  122. int rc;
  123. cdev->pdev = pdev;
  124. rc = pci_enable_device(pdev);
  125. if (rc) {
  126. DP_NOTICE(cdev, "Cannot enable PCI device\n");
  127. goto err0;
  128. }
  129. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  130. DP_NOTICE(cdev, "No memory region found in bar #0\n");
  131. rc = -EIO;
  132. goto err1;
  133. }
  134. if (IS_PF(cdev) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  135. DP_NOTICE(cdev, "No memory region found in bar #2\n");
  136. rc = -EIO;
  137. goto err1;
  138. }
  139. if (atomic_read(&pdev->enable_cnt) == 1) {
  140. rc = pci_request_regions(pdev, "qed");
  141. if (rc) {
  142. DP_NOTICE(cdev,
  143. "Failed to request PCI memory resources\n");
  144. goto err1;
  145. }
  146. pci_set_master(pdev);
  147. pci_save_state(pdev);
  148. }
  149. pci_read_config_byte(pdev, PCI_REVISION_ID, &rev_id);
  150. if (rev_id == PCI_REVISION_ID_ERROR_VAL) {
  151. DP_NOTICE(cdev,
  152. "Detected PCI device error [rev_id 0x%x]. Probably due to prior indication. Aborting.\n",
  153. rev_id);
  154. rc = -ENODEV;
  155. goto err2;
  156. }
  157. if (!pci_is_pcie(pdev)) {
  158. DP_NOTICE(cdev, "The bus is not PCI Express\n");
  159. rc = -EIO;
  160. goto err2;
  161. }
  162. cdev->pci_params.pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  163. if (IS_PF(cdev) && !cdev->pci_params.pm_cap)
  164. DP_NOTICE(cdev, "Cannot find power management capability\n");
  165. rc = qed_set_coherency_mask(cdev);
  166. if (rc)
  167. goto err2;
  168. cdev->pci_params.mem_start = pci_resource_start(pdev, 0);
  169. cdev->pci_params.mem_end = pci_resource_end(pdev, 0);
  170. cdev->pci_params.irq = pdev->irq;
  171. cdev->regview = pci_ioremap_bar(pdev, 0);
  172. if (!cdev->regview) {
  173. DP_NOTICE(cdev, "Cannot map register space, aborting\n");
  174. rc = -ENOMEM;
  175. goto err2;
  176. }
  177. cdev->db_phys_addr = pci_resource_start(cdev->pdev, 2);
  178. cdev->db_size = pci_resource_len(cdev->pdev, 2);
  179. if (!cdev->db_size) {
  180. if (IS_PF(cdev)) {
  181. DP_NOTICE(cdev, "No Doorbell bar available\n");
  182. return -EINVAL;
  183. } else {
  184. return 0;
  185. }
  186. }
  187. cdev->doorbells = ioremap_wc(cdev->db_phys_addr, cdev->db_size);
  188. if (!cdev->doorbells) {
  189. DP_NOTICE(cdev, "Cannot map doorbell space\n");
  190. return -ENOMEM;
  191. }
  192. return 0;
  193. err2:
  194. pci_release_regions(pdev);
  195. err1:
  196. pci_disable_device(pdev);
  197. err0:
  198. return rc;
  199. }
  200. int qed_fill_dev_info(struct qed_dev *cdev,
  201. struct qed_dev_info *dev_info)
  202. {
  203. struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev);
  204. struct qed_hw_info *hw_info = &p_hwfn->hw_info;
  205. struct qed_tunnel_info *tun = &cdev->tunnel;
  206. struct qed_ptt *ptt;
  207. memset(dev_info, 0, sizeof(struct qed_dev_info));
  208. if (tun->vxlan.tun_cls == QED_TUNN_CLSS_MAC_VLAN &&
  209. tun->vxlan.b_mode_enabled)
  210. dev_info->vxlan_enable = true;
  211. if (tun->l2_gre.b_mode_enabled && tun->ip_gre.b_mode_enabled &&
  212. tun->l2_gre.tun_cls == QED_TUNN_CLSS_MAC_VLAN &&
  213. tun->ip_gre.tun_cls == QED_TUNN_CLSS_MAC_VLAN)
  214. dev_info->gre_enable = true;
  215. if (tun->l2_geneve.b_mode_enabled && tun->ip_geneve.b_mode_enabled &&
  216. tun->l2_geneve.tun_cls == QED_TUNN_CLSS_MAC_VLAN &&
  217. tun->ip_geneve.tun_cls == QED_TUNN_CLSS_MAC_VLAN)
  218. dev_info->geneve_enable = true;
  219. dev_info->num_hwfns = cdev->num_hwfns;
  220. dev_info->pci_mem_start = cdev->pci_params.mem_start;
  221. dev_info->pci_mem_end = cdev->pci_params.mem_end;
  222. dev_info->pci_irq = cdev->pci_params.irq;
  223. dev_info->rdma_supported = QED_IS_RDMA_PERSONALITY(p_hwfn);
  224. dev_info->is_mf_default = IS_MF_DEFAULT(&cdev->hwfns[0]);
  225. dev_info->dev_type = cdev->type;
  226. ether_addr_copy(dev_info->hw_mac, hw_info->hw_mac_addr);
  227. if (IS_PF(cdev)) {
  228. dev_info->fw_major = FW_MAJOR_VERSION;
  229. dev_info->fw_minor = FW_MINOR_VERSION;
  230. dev_info->fw_rev = FW_REVISION_VERSION;
  231. dev_info->fw_eng = FW_ENGINEERING_VERSION;
  232. dev_info->mf_mode = cdev->mf_mode;
  233. dev_info->tx_switching = true;
  234. if (hw_info->b_wol_support == QED_WOL_SUPPORT_PME)
  235. dev_info->wol_support = true;
  236. dev_info->abs_pf_id = QED_LEADING_HWFN(cdev)->abs_pf_id;
  237. } else {
  238. qed_vf_get_fw_version(&cdev->hwfns[0], &dev_info->fw_major,
  239. &dev_info->fw_minor, &dev_info->fw_rev,
  240. &dev_info->fw_eng);
  241. }
  242. if (IS_PF(cdev)) {
  243. ptt = qed_ptt_acquire(QED_LEADING_HWFN(cdev));
  244. if (ptt) {
  245. qed_mcp_get_mfw_ver(QED_LEADING_HWFN(cdev), ptt,
  246. &dev_info->mfw_rev, NULL);
  247. qed_mcp_get_mbi_ver(QED_LEADING_HWFN(cdev), ptt,
  248. &dev_info->mbi_version);
  249. qed_mcp_get_flash_size(QED_LEADING_HWFN(cdev), ptt,
  250. &dev_info->flash_size);
  251. qed_ptt_release(QED_LEADING_HWFN(cdev), ptt);
  252. }
  253. } else {
  254. qed_mcp_get_mfw_ver(QED_LEADING_HWFN(cdev), NULL,
  255. &dev_info->mfw_rev, NULL);
  256. }
  257. dev_info->mtu = hw_info->mtu;
  258. return 0;
  259. }
  260. static void qed_free_cdev(struct qed_dev *cdev)
  261. {
  262. kfree((void *)cdev);
  263. }
  264. static struct qed_dev *qed_alloc_cdev(struct pci_dev *pdev)
  265. {
  266. struct qed_dev *cdev;
  267. cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
  268. if (!cdev)
  269. return cdev;
  270. qed_init_struct(cdev);
  271. return cdev;
  272. }
  273. /* Sets the requested power state */
  274. static int qed_set_power_state(struct qed_dev *cdev, pci_power_t state)
  275. {
  276. if (!cdev)
  277. return -ENODEV;
  278. DP_VERBOSE(cdev, NETIF_MSG_DRV, "Omitting Power state change\n");
  279. return 0;
  280. }
  281. /* probing */
  282. static struct qed_dev *qed_probe(struct pci_dev *pdev,
  283. struct qed_probe_params *params)
  284. {
  285. struct qed_dev *cdev;
  286. int rc;
  287. cdev = qed_alloc_cdev(pdev);
  288. if (!cdev)
  289. goto err0;
  290. cdev->drv_type = DRV_ID_DRV_TYPE_LINUX;
  291. cdev->protocol = params->protocol;
  292. if (params->is_vf)
  293. cdev->b_is_vf = true;
  294. qed_init_dp(cdev, params->dp_module, params->dp_level);
  295. rc = qed_init_pci(cdev, pdev);
  296. if (rc) {
  297. DP_ERR(cdev, "init pci failed\n");
  298. goto err1;
  299. }
  300. DP_INFO(cdev, "PCI init completed successfully\n");
  301. rc = qed_hw_prepare(cdev, QED_PCI_DEFAULT);
  302. if (rc) {
  303. DP_ERR(cdev, "hw prepare failed\n");
  304. goto err2;
  305. }
  306. DP_INFO(cdev, "qed_probe completed successffuly\n");
  307. return cdev;
  308. err2:
  309. qed_free_pci(cdev);
  310. err1:
  311. qed_free_cdev(cdev);
  312. err0:
  313. return NULL;
  314. }
  315. static void qed_remove(struct qed_dev *cdev)
  316. {
  317. if (!cdev)
  318. return;
  319. qed_hw_remove(cdev);
  320. qed_free_pci(cdev);
  321. qed_set_power_state(cdev, PCI_D3hot);
  322. qed_free_cdev(cdev);
  323. }
  324. static void qed_disable_msix(struct qed_dev *cdev)
  325. {
  326. if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
  327. pci_disable_msix(cdev->pdev);
  328. kfree(cdev->int_params.msix_table);
  329. } else if (cdev->int_params.out.int_mode == QED_INT_MODE_MSI) {
  330. pci_disable_msi(cdev->pdev);
  331. }
  332. memset(&cdev->int_params.out, 0, sizeof(struct qed_int_param));
  333. }
  334. static int qed_enable_msix(struct qed_dev *cdev,
  335. struct qed_int_params *int_params)
  336. {
  337. int i, rc, cnt;
  338. cnt = int_params->in.num_vectors;
  339. for (i = 0; i < cnt; i++)
  340. int_params->msix_table[i].entry = i;
  341. rc = pci_enable_msix_range(cdev->pdev, int_params->msix_table,
  342. int_params->in.min_msix_cnt, cnt);
  343. if (rc < cnt && rc >= int_params->in.min_msix_cnt &&
  344. (rc % cdev->num_hwfns)) {
  345. pci_disable_msix(cdev->pdev);
  346. /* If fastpath is initialized, we need at least one interrupt
  347. * per hwfn [and the slow path interrupts]. New requested number
  348. * should be a multiple of the number of hwfns.
  349. */
  350. cnt = (rc / cdev->num_hwfns) * cdev->num_hwfns;
  351. DP_NOTICE(cdev,
  352. "Trying to enable MSI-X with less vectors (%d out of %d)\n",
  353. cnt, int_params->in.num_vectors);
  354. rc = pci_enable_msix_exact(cdev->pdev, int_params->msix_table,
  355. cnt);
  356. if (!rc)
  357. rc = cnt;
  358. }
  359. if (rc > 0) {
  360. /* MSI-x configuration was achieved */
  361. int_params->out.int_mode = QED_INT_MODE_MSIX;
  362. int_params->out.num_vectors = rc;
  363. rc = 0;
  364. } else {
  365. DP_NOTICE(cdev,
  366. "Failed to enable MSI-X [Requested %d vectors][rc %d]\n",
  367. cnt, rc);
  368. }
  369. return rc;
  370. }
  371. /* This function outputs the int mode and the number of enabled msix vector */
  372. static int qed_set_int_mode(struct qed_dev *cdev, bool force_mode)
  373. {
  374. struct qed_int_params *int_params = &cdev->int_params;
  375. struct msix_entry *tbl;
  376. int rc = 0, cnt;
  377. switch (int_params->in.int_mode) {
  378. case QED_INT_MODE_MSIX:
  379. /* Allocate MSIX table */
  380. cnt = int_params->in.num_vectors;
  381. int_params->msix_table = kcalloc(cnt, sizeof(*tbl), GFP_KERNEL);
  382. if (!int_params->msix_table) {
  383. rc = -ENOMEM;
  384. goto out;
  385. }
  386. /* Enable MSIX */
  387. rc = qed_enable_msix(cdev, int_params);
  388. if (!rc)
  389. goto out;
  390. DP_NOTICE(cdev, "Failed to enable MSI-X\n");
  391. kfree(int_params->msix_table);
  392. if (force_mode)
  393. goto out;
  394. /* Fallthrough */
  395. case QED_INT_MODE_MSI:
  396. if (cdev->num_hwfns == 1) {
  397. rc = pci_enable_msi(cdev->pdev);
  398. if (!rc) {
  399. int_params->out.int_mode = QED_INT_MODE_MSI;
  400. goto out;
  401. }
  402. DP_NOTICE(cdev, "Failed to enable MSI\n");
  403. if (force_mode)
  404. goto out;
  405. }
  406. /* Fallthrough */
  407. case QED_INT_MODE_INTA:
  408. int_params->out.int_mode = QED_INT_MODE_INTA;
  409. rc = 0;
  410. goto out;
  411. default:
  412. DP_NOTICE(cdev, "Unknown int_mode value %d\n",
  413. int_params->in.int_mode);
  414. rc = -EINVAL;
  415. }
  416. out:
  417. if (!rc)
  418. DP_INFO(cdev, "Using %s interrupts\n",
  419. int_params->out.int_mode == QED_INT_MODE_INTA ?
  420. "INTa" : int_params->out.int_mode == QED_INT_MODE_MSI ?
  421. "MSI" : "MSIX");
  422. cdev->int_coalescing_mode = QED_COAL_MODE_ENABLE;
  423. return rc;
  424. }
  425. static void qed_simd_handler_config(struct qed_dev *cdev, void *token,
  426. int index, void(*handler)(void *))
  427. {
  428. struct qed_hwfn *hwfn = &cdev->hwfns[index % cdev->num_hwfns];
  429. int relative_idx = index / cdev->num_hwfns;
  430. hwfn->simd_proto_handler[relative_idx].func = handler;
  431. hwfn->simd_proto_handler[relative_idx].token = token;
  432. }
  433. static void qed_simd_handler_clean(struct qed_dev *cdev, int index)
  434. {
  435. struct qed_hwfn *hwfn = &cdev->hwfns[index % cdev->num_hwfns];
  436. int relative_idx = index / cdev->num_hwfns;
  437. memset(&hwfn->simd_proto_handler[relative_idx], 0,
  438. sizeof(struct qed_simd_fp_handler));
  439. }
  440. static irqreturn_t qed_msix_sp_int(int irq, void *tasklet)
  441. {
  442. tasklet_schedule((struct tasklet_struct *)tasklet);
  443. return IRQ_HANDLED;
  444. }
  445. static irqreturn_t qed_single_int(int irq, void *dev_instance)
  446. {
  447. struct qed_dev *cdev = (struct qed_dev *)dev_instance;
  448. struct qed_hwfn *hwfn;
  449. irqreturn_t rc = IRQ_NONE;
  450. u64 status;
  451. int i, j;
  452. for (i = 0; i < cdev->num_hwfns; i++) {
  453. status = qed_int_igu_read_sisr_reg(&cdev->hwfns[i]);
  454. if (!status)
  455. continue;
  456. hwfn = &cdev->hwfns[i];
  457. /* Slowpath interrupt */
  458. if (unlikely(status & 0x1)) {
  459. tasklet_schedule(hwfn->sp_dpc);
  460. status &= ~0x1;
  461. rc = IRQ_HANDLED;
  462. }
  463. /* Fastpath interrupts */
  464. for (j = 0; j < 64; j++) {
  465. if ((0x2ULL << j) & status) {
  466. hwfn->simd_proto_handler[j].func(
  467. hwfn->simd_proto_handler[j].token);
  468. status &= ~(0x2ULL << j);
  469. rc = IRQ_HANDLED;
  470. }
  471. }
  472. if (unlikely(status))
  473. DP_VERBOSE(hwfn, NETIF_MSG_INTR,
  474. "got an unknown interrupt status 0x%llx\n",
  475. status);
  476. }
  477. return rc;
  478. }
  479. int qed_slowpath_irq_req(struct qed_hwfn *hwfn)
  480. {
  481. struct qed_dev *cdev = hwfn->cdev;
  482. u32 int_mode;
  483. int rc = 0;
  484. u8 id;
  485. int_mode = cdev->int_params.out.int_mode;
  486. if (int_mode == QED_INT_MODE_MSIX) {
  487. id = hwfn->my_id;
  488. snprintf(hwfn->name, NAME_SIZE, "sp-%d-%02x:%02x.%02x",
  489. id, cdev->pdev->bus->number,
  490. PCI_SLOT(cdev->pdev->devfn), hwfn->abs_pf_id);
  491. rc = request_irq(cdev->int_params.msix_table[id].vector,
  492. qed_msix_sp_int, 0, hwfn->name, hwfn->sp_dpc);
  493. } else {
  494. unsigned long flags = 0;
  495. snprintf(cdev->name, NAME_SIZE, "%02x:%02x.%02x",
  496. cdev->pdev->bus->number, PCI_SLOT(cdev->pdev->devfn),
  497. PCI_FUNC(cdev->pdev->devfn));
  498. if (cdev->int_params.out.int_mode == QED_INT_MODE_INTA)
  499. flags |= IRQF_SHARED;
  500. rc = request_irq(cdev->pdev->irq, qed_single_int,
  501. flags, cdev->name, cdev);
  502. }
  503. if (rc)
  504. DP_NOTICE(cdev, "request_irq failed, rc = %d\n", rc);
  505. else
  506. DP_VERBOSE(hwfn, (NETIF_MSG_INTR | QED_MSG_SP),
  507. "Requested slowpath %s\n",
  508. (int_mode == QED_INT_MODE_MSIX) ? "MSI-X" : "IRQ");
  509. return rc;
  510. }
  511. static void qed_slowpath_tasklet_flush(struct qed_hwfn *p_hwfn)
  512. {
  513. /* Calling the disable function will make sure that any
  514. * currently-running function is completed. The following call to the
  515. * enable function makes this sequence a flush-like operation.
  516. */
  517. if (p_hwfn->b_sp_dpc_enabled) {
  518. tasklet_disable(p_hwfn->sp_dpc);
  519. tasklet_enable(p_hwfn->sp_dpc);
  520. }
  521. }
  522. void qed_slowpath_irq_sync(struct qed_hwfn *p_hwfn)
  523. {
  524. struct qed_dev *cdev = p_hwfn->cdev;
  525. u8 id = p_hwfn->my_id;
  526. u32 int_mode;
  527. int_mode = cdev->int_params.out.int_mode;
  528. if (int_mode == QED_INT_MODE_MSIX)
  529. synchronize_irq(cdev->int_params.msix_table[id].vector);
  530. else
  531. synchronize_irq(cdev->pdev->irq);
  532. qed_slowpath_tasklet_flush(p_hwfn);
  533. }
  534. static void qed_slowpath_irq_free(struct qed_dev *cdev)
  535. {
  536. int i;
  537. if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
  538. for_each_hwfn(cdev, i) {
  539. if (!cdev->hwfns[i].b_int_requested)
  540. break;
  541. synchronize_irq(cdev->int_params.msix_table[i].vector);
  542. free_irq(cdev->int_params.msix_table[i].vector,
  543. cdev->hwfns[i].sp_dpc);
  544. }
  545. } else {
  546. if (QED_LEADING_HWFN(cdev)->b_int_requested)
  547. free_irq(cdev->pdev->irq, cdev);
  548. }
  549. qed_int_disable_post_isr_release(cdev);
  550. }
  551. static int qed_nic_stop(struct qed_dev *cdev)
  552. {
  553. int i, rc;
  554. rc = qed_hw_stop(cdev);
  555. for (i = 0; i < cdev->num_hwfns; i++) {
  556. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  557. if (p_hwfn->b_sp_dpc_enabled) {
  558. tasklet_disable(p_hwfn->sp_dpc);
  559. p_hwfn->b_sp_dpc_enabled = false;
  560. DP_VERBOSE(cdev, NETIF_MSG_IFDOWN,
  561. "Disabled sp taskelt [hwfn %d] at %p\n",
  562. i, p_hwfn->sp_dpc);
  563. }
  564. }
  565. qed_dbg_pf_exit(cdev);
  566. return rc;
  567. }
  568. static int qed_nic_setup(struct qed_dev *cdev)
  569. {
  570. int rc, i;
  571. /* Determine if interface is going to require LL2 */
  572. if (QED_LEADING_HWFN(cdev)->hw_info.personality != QED_PCI_ETH) {
  573. for (i = 0; i < cdev->num_hwfns; i++) {
  574. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  575. p_hwfn->using_ll2 = true;
  576. }
  577. }
  578. rc = qed_resc_alloc(cdev);
  579. if (rc)
  580. return rc;
  581. DP_INFO(cdev, "Allocated qed resources\n");
  582. qed_resc_setup(cdev);
  583. return rc;
  584. }
  585. static int qed_set_int_fp(struct qed_dev *cdev, u16 cnt)
  586. {
  587. int limit = 0;
  588. /* Mark the fastpath as free/used */
  589. cdev->int_params.fp_initialized = cnt ? true : false;
  590. if (cdev->int_params.out.int_mode != QED_INT_MODE_MSIX)
  591. limit = cdev->num_hwfns * 63;
  592. else if (cdev->int_params.fp_msix_cnt)
  593. limit = cdev->int_params.fp_msix_cnt;
  594. if (!limit)
  595. return -ENOMEM;
  596. return min_t(int, cnt, limit);
  597. }
  598. static int qed_get_int_fp(struct qed_dev *cdev, struct qed_int_info *info)
  599. {
  600. memset(info, 0, sizeof(struct qed_int_info));
  601. if (!cdev->int_params.fp_initialized) {
  602. DP_INFO(cdev,
  603. "Protocol driver requested interrupt information, but its support is not yet configured\n");
  604. return -EINVAL;
  605. }
  606. /* Need to expose only MSI-X information; Single IRQ is handled solely
  607. * by qed.
  608. */
  609. if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
  610. int msix_base = cdev->int_params.fp_msix_base;
  611. info->msix_cnt = cdev->int_params.fp_msix_cnt;
  612. info->msix = &cdev->int_params.msix_table[msix_base];
  613. }
  614. return 0;
  615. }
  616. static int qed_slowpath_setup_int(struct qed_dev *cdev,
  617. enum qed_int_mode int_mode)
  618. {
  619. struct qed_sb_cnt_info sb_cnt_info;
  620. int num_l2_queues = 0;
  621. int rc;
  622. int i;
  623. if ((int_mode == QED_INT_MODE_MSI) && (cdev->num_hwfns > 1)) {
  624. DP_NOTICE(cdev, "MSI mode is not supported for CMT devices\n");
  625. return -EINVAL;
  626. }
  627. memset(&cdev->int_params, 0, sizeof(struct qed_int_params));
  628. cdev->int_params.in.int_mode = int_mode;
  629. for_each_hwfn(cdev, i) {
  630. memset(&sb_cnt_info, 0, sizeof(sb_cnt_info));
  631. qed_int_get_num_sbs(&cdev->hwfns[i], &sb_cnt_info);
  632. cdev->int_params.in.num_vectors += sb_cnt_info.cnt;
  633. cdev->int_params.in.num_vectors++; /* slowpath */
  634. }
  635. /* We want a minimum of one slowpath and one fastpath vector per hwfn */
  636. cdev->int_params.in.min_msix_cnt = cdev->num_hwfns * 2;
  637. rc = qed_set_int_mode(cdev, false);
  638. if (rc) {
  639. DP_ERR(cdev, "qed_slowpath_setup_int ERR\n");
  640. return rc;
  641. }
  642. cdev->int_params.fp_msix_base = cdev->num_hwfns;
  643. cdev->int_params.fp_msix_cnt = cdev->int_params.out.num_vectors -
  644. cdev->num_hwfns;
  645. if (!IS_ENABLED(CONFIG_QED_RDMA) ||
  646. !QED_IS_RDMA_PERSONALITY(QED_LEADING_HWFN(cdev)))
  647. return 0;
  648. for_each_hwfn(cdev, i)
  649. num_l2_queues += FEAT_NUM(&cdev->hwfns[i], QED_PF_L2_QUE);
  650. DP_VERBOSE(cdev, QED_MSG_RDMA,
  651. "cdev->int_params.fp_msix_cnt=%d num_l2_queues=%d\n",
  652. cdev->int_params.fp_msix_cnt, num_l2_queues);
  653. if (cdev->int_params.fp_msix_cnt > num_l2_queues) {
  654. cdev->int_params.rdma_msix_cnt =
  655. (cdev->int_params.fp_msix_cnt - num_l2_queues)
  656. / cdev->num_hwfns;
  657. cdev->int_params.rdma_msix_base =
  658. cdev->int_params.fp_msix_base + num_l2_queues;
  659. cdev->int_params.fp_msix_cnt = num_l2_queues;
  660. } else {
  661. cdev->int_params.rdma_msix_cnt = 0;
  662. }
  663. DP_VERBOSE(cdev, QED_MSG_RDMA, "roce_msix_cnt=%d roce_msix_base=%d\n",
  664. cdev->int_params.rdma_msix_cnt,
  665. cdev->int_params.rdma_msix_base);
  666. return 0;
  667. }
  668. static int qed_slowpath_vf_setup_int(struct qed_dev *cdev)
  669. {
  670. int rc;
  671. memset(&cdev->int_params, 0, sizeof(struct qed_int_params));
  672. cdev->int_params.in.int_mode = QED_INT_MODE_MSIX;
  673. qed_vf_get_num_rxqs(QED_LEADING_HWFN(cdev),
  674. &cdev->int_params.in.num_vectors);
  675. if (cdev->num_hwfns > 1) {
  676. u8 vectors = 0;
  677. qed_vf_get_num_rxqs(&cdev->hwfns[1], &vectors);
  678. cdev->int_params.in.num_vectors += vectors;
  679. }
  680. /* We want a minimum of one fastpath vector per vf hwfn */
  681. cdev->int_params.in.min_msix_cnt = cdev->num_hwfns;
  682. rc = qed_set_int_mode(cdev, true);
  683. if (rc)
  684. return rc;
  685. cdev->int_params.fp_msix_base = 0;
  686. cdev->int_params.fp_msix_cnt = cdev->int_params.out.num_vectors;
  687. return 0;
  688. }
  689. u32 qed_unzip_data(struct qed_hwfn *p_hwfn, u32 input_len,
  690. u8 *input_buf, u32 max_size, u8 *unzip_buf)
  691. {
  692. int rc;
  693. p_hwfn->stream->next_in = input_buf;
  694. p_hwfn->stream->avail_in = input_len;
  695. p_hwfn->stream->next_out = unzip_buf;
  696. p_hwfn->stream->avail_out = max_size;
  697. rc = zlib_inflateInit2(p_hwfn->stream, MAX_WBITS);
  698. if (rc != Z_OK) {
  699. DP_VERBOSE(p_hwfn, NETIF_MSG_DRV, "zlib init failed, rc = %d\n",
  700. rc);
  701. return 0;
  702. }
  703. rc = zlib_inflate(p_hwfn->stream, Z_FINISH);
  704. zlib_inflateEnd(p_hwfn->stream);
  705. if (rc != Z_OK && rc != Z_STREAM_END) {
  706. DP_VERBOSE(p_hwfn, NETIF_MSG_DRV, "FW unzip error: %s, rc=%d\n",
  707. p_hwfn->stream->msg, rc);
  708. return 0;
  709. }
  710. return p_hwfn->stream->total_out / 4;
  711. }
  712. static int qed_alloc_stream_mem(struct qed_dev *cdev)
  713. {
  714. int i;
  715. void *workspace;
  716. for_each_hwfn(cdev, i) {
  717. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  718. p_hwfn->stream = kzalloc(sizeof(*p_hwfn->stream), GFP_KERNEL);
  719. if (!p_hwfn->stream)
  720. return -ENOMEM;
  721. workspace = vzalloc(zlib_inflate_workspacesize());
  722. if (!workspace)
  723. return -ENOMEM;
  724. p_hwfn->stream->workspace = workspace;
  725. }
  726. return 0;
  727. }
  728. static void qed_free_stream_mem(struct qed_dev *cdev)
  729. {
  730. int i;
  731. for_each_hwfn(cdev, i) {
  732. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  733. if (!p_hwfn->stream)
  734. return;
  735. vfree(p_hwfn->stream->workspace);
  736. kfree(p_hwfn->stream);
  737. }
  738. }
  739. static void qed_update_pf_params(struct qed_dev *cdev,
  740. struct qed_pf_params *params)
  741. {
  742. int i;
  743. if (IS_ENABLED(CONFIG_QED_RDMA)) {
  744. params->rdma_pf_params.num_qps = QED_ROCE_QPS;
  745. params->rdma_pf_params.min_dpis = QED_ROCE_DPIS;
  746. /* divide by 3 the MRs to avoid MF ILT overflow */
  747. params->rdma_pf_params.gl_pi = QED_ROCE_PROTOCOL_INDEX;
  748. }
  749. if (cdev->num_hwfns > 1 || IS_VF(cdev))
  750. params->eth_pf_params.num_arfs_filters = 0;
  751. /* In case we might support RDMA, don't allow qede to be greedy
  752. * with the L2 contexts. Allow for 64 queues [rx, tx, xdp] per hwfn.
  753. */
  754. if (QED_IS_RDMA_PERSONALITY(QED_LEADING_HWFN(cdev))) {
  755. u16 *num_cons;
  756. num_cons = &params->eth_pf_params.num_cons;
  757. *num_cons = min_t(u16, *num_cons, 192);
  758. }
  759. for (i = 0; i < cdev->num_hwfns; i++) {
  760. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  761. p_hwfn->pf_params = *params;
  762. }
  763. }
  764. static int qed_slowpath_start(struct qed_dev *cdev,
  765. struct qed_slowpath_params *params)
  766. {
  767. struct qed_drv_load_params drv_load_params;
  768. struct qed_hw_init_params hw_init_params;
  769. struct qed_mcp_drv_version drv_version;
  770. struct qed_tunnel_info tunn_info;
  771. const u8 *data = NULL;
  772. struct qed_hwfn *hwfn;
  773. struct qed_ptt *p_ptt;
  774. int rc = -EINVAL;
  775. if (qed_iov_wq_start(cdev))
  776. goto err;
  777. if (IS_PF(cdev)) {
  778. rc = request_firmware(&cdev->firmware, QED_FW_FILE_NAME,
  779. &cdev->pdev->dev);
  780. if (rc) {
  781. DP_NOTICE(cdev,
  782. "Failed to find fw file - /lib/firmware/%s\n",
  783. QED_FW_FILE_NAME);
  784. goto err;
  785. }
  786. if (cdev->num_hwfns == 1) {
  787. p_ptt = qed_ptt_acquire(QED_LEADING_HWFN(cdev));
  788. if (p_ptt) {
  789. QED_LEADING_HWFN(cdev)->p_arfs_ptt = p_ptt;
  790. } else {
  791. DP_NOTICE(cdev,
  792. "Failed to acquire PTT for aRFS\n");
  793. goto err;
  794. }
  795. }
  796. }
  797. cdev->rx_coalesce_usecs = QED_DEFAULT_RX_USECS;
  798. rc = qed_nic_setup(cdev);
  799. if (rc)
  800. goto err;
  801. if (IS_PF(cdev))
  802. rc = qed_slowpath_setup_int(cdev, params->int_mode);
  803. else
  804. rc = qed_slowpath_vf_setup_int(cdev);
  805. if (rc)
  806. goto err1;
  807. if (IS_PF(cdev)) {
  808. /* Allocate stream for unzipping */
  809. rc = qed_alloc_stream_mem(cdev);
  810. if (rc)
  811. goto err2;
  812. /* First Dword used to differentiate between various sources */
  813. data = cdev->firmware->data + sizeof(u32);
  814. qed_dbg_pf_init(cdev);
  815. }
  816. /* Start the slowpath */
  817. memset(&hw_init_params, 0, sizeof(hw_init_params));
  818. memset(&tunn_info, 0, sizeof(tunn_info));
  819. tunn_info.vxlan.b_mode_enabled = true;
  820. tunn_info.l2_gre.b_mode_enabled = true;
  821. tunn_info.ip_gre.b_mode_enabled = true;
  822. tunn_info.l2_geneve.b_mode_enabled = true;
  823. tunn_info.ip_geneve.b_mode_enabled = true;
  824. tunn_info.vxlan.tun_cls = QED_TUNN_CLSS_MAC_VLAN;
  825. tunn_info.l2_gre.tun_cls = QED_TUNN_CLSS_MAC_VLAN;
  826. tunn_info.ip_gre.tun_cls = QED_TUNN_CLSS_MAC_VLAN;
  827. tunn_info.l2_geneve.tun_cls = QED_TUNN_CLSS_MAC_VLAN;
  828. tunn_info.ip_geneve.tun_cls = QED_TUNN_CLSS_MAC_VLAN;
  829. hw_init_params.p_tunn = &tunn_info;
  830. hw_init_params.b_hw_start = true;
  831. hw_init_params.int_mode = cdev->int_params.out.int_mode;
  832. hw_init_params.allow_npar_tx_switch = true;
  833. hw_init_params.bin_fw_data = data;
  834. memset(&drv_load_params, 0, sizeof(drv_load_params));
  835. drv_load_params.is_crash_kernel = is_kdump_kernel();
  836. drv_load_params.mfw_timeout_val = QED_LOAD_REQ_LOCK_TO_DEFAULT;
  837. drv_load_params.avoid_eng_reset = false;
  838. drv_load_params.override_force_load = QED_OVERRIDE_FORCE_LOAD_NONE;
  839. hw_init_params.p_drv_load_params = &drv_load_params;
  840. rc = qed_hw_init(cdev, &hw_init_params);
  841. if (rc)
  842. goto err2;
  843. DP_INFO(cdev,
  844. "HW initialization and function start completed successfully\n");
  845. if (IS_PF(cdev)) {
  846. cdev->tunn_feature_mask = (BIT(QED_MODE_VXLAN_TUNN) |
  847. BIT(QED_MODE_L2GENEVE_TUNN) |
  848. BIT(QED_MODE_IPGENEVE_TUNN) |
  849. BIT(QED_MODE_L2GRE_TUNN) |
  850. BIT(QED_MODE_IPGRE_TUNN));
  851. }
  852. /* Allocate LL2 interface if needed */
  853. if (QED_LEADING_HWFN(cdev)->using_ll2) {
  854. rc = qed_ll2_alloc_if(cdev);
  855. if (rc)
  856. goto err3;
  857. }
  858. if (IS_PF(cdev)) {
  859. hwfn = QED_LEADING_HWFN(cdev);
  860. drv_version.version = (params->drv_major << 24) |
  861. (params->drv_minor << 16) |
  862. (params->drv_rev << 8) |
  863. (params->drv_eng);
  864. strlcpy(drv_version.name, params->name,
  865. MCP_DRV_VER_STR_SIZE - 4);
  866. rc = qed_mcp_send_drv_version(hwfn, hwfn->p_main_ptt,
  867. &drv_version);
  868. if (rc) {
  869. DP_NOTICE(cdev, "Failed sending drv version command\n");
  870. return rc;
  871. }
  872. }
  873. qed_reset_vport_stats(cdev);
  874. return 0;
  875. err3:
  876. qed_hw_stop(cdev);
  877. err2:
  878. qed_hw_timers_stop_all(cdev);
  879. if (IS_PF(cdev))
  880. qed_slowpath_irq_free(cdev);
  881. qed_free_stream_mem(cdev);
  882. qed_disable_msix(cdev);
  883. err1:
  884. qed_resc_free(cdev);
  885. err:
  886. if (IS_PF(cdev))
  887. release_firmware(cdev->firmware);
  888. if (IS_PF(cdev) && (cdev->num_hwfns == 1) &&
  889. QED_LEADING_HWFN(cdev)->p_arfs_ptt)
  890. qed_ptt_release(QED_LEADING_HWFN(cdev),
  891. QED_LEADING_HWFN(cdev)->p_arfs_ptt);
  892. qed_iov_wq_stop(cdev, false);
  893. return rc;
  894. }
  895. static int qed_slowpath_stop(struct qed_dev *cdev)
  896. {
  897. if (!cdev)
  898. return -ENODEV;
  899. qed_ll2_dealloc_if(cdev);
  900. if (IS_PF(cdev)) {
  901. if (cdev->num_hwfns == 1)
  902. qed_ptt_release(QED_LEADING_HWFN(cdev),
  903. QED_LEADING_HWFN(cdev)->p_arfs_ptt);
  904. qed_free_stream_mem(cdev);
  905. if (IS_QED_ETH_IF(cdev))
  906. qed_sriov_disable(cdev, true);
  907. }
  908. qed_nic_stop(cdev);
  909. if (IS_PF(cdev))
  910. qed_slowpath_irq_free(cdev);
  911. qed_disable_msix(cdev);
  912. qed_resc_free(cdev);
  913. qed_iov_wq_stop(cdev, true);
  914. if (IS_PF(cdev))
  915. release_firmware(cdev->firmware);
  916. return 0;
  917. }
  918. static void qed_set_name(struct qed_dev *cdev, char name[NAME_SIZE])
  919. {
  920. int i;
  921. memcpy(cdev->name, name, NAME_SIZE);
  922. for_each_hwfn(cdev, i)
  923. snprintf(cdev->hwfns[i].name, NAME_SIZE, "%s-%d", name, i);
  924. }
  925. static u32 qed_sb_init(struct qed_dev *cdev,
  926. struct qed_sb_info *sb_info,
  927. void *sb_virt_addr,
  928. dma_addr_t sb_phy_addr, u16 sb_id,
  929. enum qed_sb_type type)
  930. {
  931. struct qed_hwfn *p_hwfn;
  932. struct qed_ptt *p_ptt;
  933. int hwfn_index;
  934. u16 rel_sb_id;
  935. u8 n_hwfns;
  936. u32 rc;
  937. /* RoCE uses single engine and CMT uses two engines. When using both
  938. * we force only a single engine. Storage uses only engine 0 too.
  939. */
  940. if (type == QED_SB_TYPE_L2_QUEUE)
  941. n_hwfns = cdev->num_hwfns;
  942. else
  943. n_hwfns = 1;
  944. hwfn_index = sb_id % n_hwfns;
  945. p_hwfn = &cdev->hwfns[hwfn_index];
  946. rel_sb_id = sb_id / n_hwfns;
  947. DP_VERBOSE(cdev, NETIF_MSG_INTR,
  948. "hwfn [%d] <--[init]-- SB %04x [0x%04x upper]\n",
  949. hwfn_index, rel_sb_id, sb_id);
  950. if (IS_PF(p_hwfn->cdev)) {
  951. p_ptt = qed_ptt_acquire(p_hwfn);
  952. if (!p_ptt)
  953. return -EBUSY;
  954. rc = qed_int_sb_init(p_hwfn, p_ptt, sb_info, sb_virt_addr,
  955. sb_phy_addr, rel_sb_id);
  956. qed_ptt_release(p_hwfn, p_ptt);
  957. } else {
  958. rc = qed_int_sb_init(p_hwfn, NULL, sb_info, sb_virt_addr,
  959. sb_phy_addr, rel_sb_id);
  960. }
  961. return rc;
  962. }
  963. static u32 qed_sb_release(struct qed_dev *cdev,
  964. struct qed_sb_info *sb_info, u16 sb_id)
  965. {
  966. struct qed_hwfn *p_hwfn;
  967. int hwfn_index;
  968. u16 rel_sb_id;
  969. u32 rc;
  970. hwfn_index = sb_id % cdev->num_hwfns;
  971. p_hwfn = &cdev->hwfns[hwfn_index];
  972. rel_sb_id = sb_id / cdev->num_hwfns;
  973. DP_VERBOSE(cdev, NETIF_MSG_INTR,
  974. "hwfn [%d] <--[init]-- SB %04x [0x%04x upper]\n",
  975. hwfn_index, rel_sb_id, sb_id);
  976. rc = qed_int_sb_release(p_hwfn, sb_info, rel_sb_id);
  977. return rc;
  978. }
  979. static bool qed_can_link_change(struct qed_dev *cdev)
  980. {
  981. return true;
  982. }
  983. static int qed_set_link(struct qed_dev *cdev, struct qed_link_params *params)
  984. {
  985. struct qed_hwfn *hwfn;
  986. struct qed_mcp_link_params *link_params;
  987. struct qed_ptt *ptt;
  988. int rc;
  989. if (!cdev)
  990. return -ENODEV;
  991. /* The link should be set only once per PF */
  992. hwfn = &cdev->hwfns[0];
  993. /* When VF wants to set link, force it to read the bulletin instead.
  994. * This mimics the PF behavior, where a noitification [both immediate
  995. * and possible later] would be generated when changing properties.
  996. */
  997. if (IS_VF(cdev)) {
  998. qed_schedule_iov(hwfn, QED_IOV_WQ_VF_FORCE_LINK_QUERY_FLAG);
  999. return 0;
  1000. }
  1001. ptt = qed_ptt_acquire(hwfn);
  1002. if (!ptt)
  1003. return -EBUSY;
  1004. link_params = qed_mcp_get_link_params(hwfn);
  1005. if (params->override_flags & QED_LINK_OVERRIDE_SPEED_AUTONEG)
  1006. link_params->speed.autoneg = params->autoneg;
  1007. if (params->override_flags & QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS) {
  1008. link_params->speed.advertised_speeds = 0;
  1009. if ((params->adv_speeds & QED_LM_1000baseT_Half_BIT) ||
  1010. (params->adv_speeds & QED_LM_1000baseT_Full_BIT))
  1011. link_params->speed.advertised_speeds |=
  1012. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G;
  1013. if (params->adv_speeds & QED_LM_10000baseKR_Full_BIT)
  1014. link_params->speed.advertised_speeds |=
  1015. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G;
  1016. if (params->adv_speeds & QED_LM_25000baseKR_Full_BIT)
  1017. link_params->speed.advertised_speeds |=
  1018. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G;
  1019. if (params->adv_speeds & QED_LM_40000baseLR4_Full_BIT)
  1020. link_params->speed.advertised_speeds |=
  1021. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G;
  1022. if (params->adv_speeds & QED_LM_50000baseKR2_Full_BIT)
  1023. link_params->speed.advertised_speeds |=
  1024. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G;
  1025. if (params->adv_speeds & QED_LM_100000baseKR4_Full_BIT)
  1026. link_params->speed.advertised_speeds |=
  1027. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_BB_100G;
  1028. }
  1029. if (params->override_flags & QED_LINK_OVERRIDE_SPEED_FORCED_SPEED)
  1030. link_params->speed.forced_speed = params->forced_speed;
  1031. if (params->override_flags & QED_LINK_OVERRIDE_PAUSE_CONFIG) {
  1032. if (params->pause_config & QED_LINK_PAUSE_AUTONEG_ENABLE)
  1033. link_params->pause.autoneg = true;
  1034. else
  1035. link_params->pause.autoneg = false;
  1036. if (params->pause_config & QED_LINK_PAUSE_RX_ENABLE)
  1037. link_params->pause.forced_rx = true;
  1038. else
  1039. link_params->pause.forced_rx = false;
  1040. if (params->pause_config & QED_LINK_PAUSE_TX_ENABLE)
  1041. link_params->pause.forced_tx = true;
  1042. else
  1043. link_params->pause.forced_tx = false;
  1044. }
  1045. if (params->override_flags & QED_LINK_OVERRIDE_LOOPBACK_MODE) {
  1046. switch (params->loopback_mode) {
  1047. case QED_LINK_LOOPBACK_INT_PHY:
  1048. link_params->loopback_mode = ETH_LOOPBACK_INT_PHY;
  1049. break;
  1050. case QED_LINK_LOOPBACK_EXT_PHY:
  1051. link_params->loopback_mode = ETH_LOOPBACK_EXT_PHY;
  1052. break;
  1053. case QED_LINK_LOOPBACK_EXT:
  1054. link_params->loopback_mode = ETH_LOOPBACK_EXT;
  1055. break;
  1056. case QED_LINK_LOOPBACK_MAC:
  1057. link_params->loopback_mode = ETH_LOOPBACK_MAC;
  1058. break;
  1059. default:
  1060. link_params->loopback_mode = ETH_LOOPBACK_NONE;
  1061. break;
  1062. }
  1063. }
  1064. if (params->override_flags & QED_LINK_OVERRIDE_EEE_CONFIG)
  1065. memcpy(&link_params->eee, &params->eee,
  1066. sizeof(link_params->eee));
  1067. rc = qed_mcp_set_link(hwfn, ptt, params->link_up);
  1068. qed_ptt_release(hwfn, ptt);
  1069. return rc;
  1070. }
  1071. static int qed_get_port_type(u32 media_type)
  1072. {
  1073. int port_type;
  1074. switch (media_type) {
  1075. case MEDIA_SFPP_10G_FIBER:
  1076. case MEDIA_SFP_1G_FIBER:
  1077. case MEDIA_XFP_FIBER:
  1078. case MEDIA_MODULE_FIBER:
  1079. case MEDIA_KR:
  1080. port_type = PORT_FIBRE;
  1081. break;
  1082. case MEDIA_DA_TWINAX:
  1083. port_type = PORT_DA;
  1084. break;
  1085. case MEDIA_BASE_T:
  1086. port_type = PORT_TP;
  1087. break;
  1088. case MEDIA_NOT_PRESENT:
  1089. port_type = PORT_NONE;
  1090. break;
  1091. case MEDIA_UNSPECIFIED:
  1092. default:
  1093. port_type = PORT_OTHER;
  1094. break;
  1095. }
  1096. return port_type;
  1097. }
  1098. static int qed_get_link_data(struct qed_hwfn *hwfn,
  1099. struct qed_mcp_link_params *params,
  1100. struct qed_mcp_link_state *link,
  1101. struct qed_mcp_link_capabilities *link_caps)
  1102. {
  1103. void *p;
  1104. if (!IS_PF(hwfn->cdev)) {
  1105. qed_vf_get_link_params(hwfn, params);
  1106. qed_vf_get_link_state(hwfn, link);
  1107. qed_vf_get_link_caps(hwfn, link_caps);
  1108. return 0;
  1109. }
  1110. p = qed_mcp_get_link_params(hwfn);
  1111. if (!p)
  1112. return -ENXIO;
  1113. memcpy(params, p, sizeof(*params));
  1114. p = qed_mcp_get_link_state(hwfn);
  1115. if (!p)
  1116. return -ENXIO;
  1117. memcpy(link, p, sizeof(*link));
  1118. p = qed_mcp_get_link_capabilities(hwfn);
  1119. if (!p)
  1120. return -ENXIO;
  1121. memcpy(link_caps, p, sizeof(*link_caps));
  1122. return 0;
  1123. }
  1124. static void qed_fill_link(struct qed_hwfn *hwfn,
  1125. struct qed_link_output *if_link)
  1126. {
  1127. struct qed_mcp_link_params params;
  1128. struct qed_mcp_link_state link;
  1129. struct qed_mcp_link_capabilities link_caps;
  1130. u32 media_type;
  1131. memset(if_link, 0, sizeof(*if_link));
  1132. /* Prepare source inputs */
  1133. if (qed_get_link_data(hwfn, &params, &link, &link_caps)) {
  1134. dev_warn(&hwfn->cdev->pdev->dev, "no link data available\n");
  1135. return;
  1136. }
  1137. /* Set the link parameters to pass to protocol driver */
  1138. if (link.link_up)
  1139. if_link->link_up = true;
  1140. /* TODO - at the moment assume supported and advertised speed equal */
  1141. if_link->supported_caps = QED_LM_FIBRE_BIT;
  1142. if (link_caps.default_speed_autoneg)
  1143. if_link->supported_caps |= QED_LM_Autoneg_BIT;
  1144. if (params.pause.autoneg ||
  1145. (params.pause.forced_rx && params.pause.forced_tx))
  1146. if_link->supported_caps |= QED_LM_Asym_Pause_BIT;
  1147. if (params.pause.autoneg || params.pause.forced_rx ||
  1148. params.pause.forced_tx)
  1149. if_link->supported_caps |= QED_LM_Pause_BIT;
  1150. if_link->advertised_caps = if_link->supported_caps;
  1151. if (params.speed.autoneg)
  1152. if_link->advertised_caps |= QED_LM_Autoneg_BIT;
  1153. else
  1154. if_link->advertised_caps &= ~QED_LM_Autoneg_BIT;
  1155. if (params.speed.advertised_speeds &
  1156. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G)
  1157. if_link->advertised_caps |= QED_LM_1000baseT_Half_BIT |
  1158. QED_LM_1000baseT_Full_BIT;
  1159. if (params.speed.advertised_speeds &
  1160. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G)
  1161. if_link->advertised_caps |= QED_LM_10000baseKR_Full_BIT;
  1162. if (params.speed.advertised_speeds &
  1163. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G)
  1164. if_link->advertised_caps |= QED_LM_25000baseKR_Full_BIT;
  1165. if (params.speed.advertised_speeds &
  1166. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G)
  1167. if_link->advertised_caps |= QED_LM_40000baseLR4_Full_BIT;
  1168. if (params.speed.advertised_speeds &
  1169. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G)
  1170. if_link->advertised_caps |= QED_LM_50000baseKR2_Full_BIT;
  1171. if (params.speed.advertised_speeds &
  1172. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_BB_100G)
  1173. if_link->advertised_caps |= QED_LM_100000baseKR4_Full_BIT;
  1174. if (link_caps.speed_capabilities &
  1175. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G)
  1176. if_link->supported_caps |= QED_LM_1000baseT_Half_BIT |
  1177. QED_LM_1000baseT_Full_BIT;
  1178. if (link_caps.speed_capabilities &
  1179. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G)
  1180. if_link->supported_caps |= QED_LM_10000baseKR_Full_BIT;
  1181. if (link_caps.speed_capabilities &
  1182. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G)
  1183. if_link->supported_caps |= QED_LM_25000baseKR_Full_BIT;
  1184. if (link_caps.speed_capabilities &
  1185. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G)
  1186. if_link->supported_caps |= QED_LM_40000baseLR4_Full_BIT;
  1187. if (link_caps.speed_capabilities &
  1188. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G)
  1189. if_link->supported_caps |= QED_LM_50000baseKR2_Full_BIT;
  1190. if (link_caps.speed_capabilities &
  1191. NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_BB_100G)
  1192. if_link->supported_caps |= QED_LM_100000baseKR4_Full_BIT;
  1193. if (link.link_up)
  1194. if_link->speed = link.speed;
  1195. /* TODO - fill duplex properly */
  1196. if_link->duplex = DUPLEX_FULL;
  1197. qed_mcp_get_media_type(hwfn->cdev, &media_type);
  1198. if_link->port = qed_get_port_type(media_type);
  1199. if_link->autoneg = params.speed.autoneg;
  1200. if (params.pause.autoneg)
  1201. if_link->pause_config |= QED_LINK_PAUSE_AUTONEG_ENABLE;
  1202. if (params.pause.forced_rx)
  1203. if_link->pause_config |= QED_LINK_PAUSE_RX_ENABLE;
  1204. if (params.pause.forced_tx)
  1205. if_link->pause_config |= QED_LINK_PAUSE_TX_ENABLE;
  1206. /* Link partner capabilities */
  1207. if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_1G_HD)
  1208. if_link->lp_caps |= QED_LM_1000baseT_Half_BIT;
  1209. if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_1G_FD)
  1210. if_link->lp_caps |= QED_LM_1000baseT_Full_BIT;
  1211. if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_10G)
  1212. if_link->lp_caps |= QED_LM_10000baseKR_Full_BIT;
  1213. if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_25G)
  1214. if_link->lp_caps |= QED_LM_25000baseKR_Full_BIT;
  1215. if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_40G)
  1216. if_link->lp_caps |= QED_LM_40000baseLR4_Full_BIT;
  1217. if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_50G)
  1218. if_link->lp_caps |= QED_LM_50000baseKR2_Full_BIT;
  1219. if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_100G)
  1220. if_link->lp_caps |= QED_LM_100000baseKR4_Full_BIT;
  1221. if (link.an_complete)
  1222. if_link->lp_caps |= QED_LM_Autoneg_BIT;
  1223. if (link.partner_adv_pause)
  1224. if_link->lp_caps |= QED_LM_Pause_BIT;
  1225. if (link.partner_adv_pause == QED_LINK_PARTNER_ASYMMETRIC_PAUSE ||
  1226. link.partner_adv_pause == QED_LINK_PARTNER_BOTH_PAUSE)
  1227. if_link->lp_caps |= QED_LM_Asym_Pause_BIT;
  1228. if (link_caps.default_eee == QED_MCP_EEE_UNSUPPORTED) {
  1229. if_link->eee_supported = false;
  1230. } else {
  1231. if_link->eee_supported = true;
  1232. if_link->eee_active = link.eee_active;
  1233. if_link->sup_caps = link_caps.eee_speed_caps;
  1234. /* MFW clears adv_caps on eee disable; use configured value */
  1235. if_link->eee.adv_caps = link.eee_adv_caps ? link.eee_adv_caps :
  1236. params.eee.adv_caps;
  1237. if_link->eee.lp_adv_caps = link.eee_lp_adv_caps;
  1238. if_link->eee.enable = params.eee.enable;
  1239. if_link->eee.tx_lpi_enable = params.eee.tx_lpi_enable;
  1240. if_link->eee.tx_lpi_timer = params.eee.tx_lpi_timer;
  1241. }
  1242. }
  1243. static void qed_get_current_link(struct qed_dev *cdev,
  1244. struct qed_link_output *if_link)
  1245. {
  1246. int i;
  1247. qed_fill_link(&cdev->hwfns[0], if_link);
  1248. for_each_hwfn(cdev, i)
  1249. qed_inform_vf_link_state(&cdev->hwfns[i]);
  1250. }
  1251. void qed_link_update(struct qed_hwfn *hwfn)
  1252. {
  1253. void *cookie = hwfn->cdev->ops_cookie;
  1254. struct qed_common_cb_ops *op = hwfn->cdev->protocol_ops.common;
  1255. struct qed_link_output if_link;
  1256. qed_fill_link(hwfn, &if_link);
  1257. qed_inform_vf_link_state(hwfn);
  1258. if (IS_LEAD_HWFN(hwfn) && cookie)
  1259. op->link_update(cookie, &if_link);
  1260. }
  1261. static int qed_drain(struct qed_dev *cdev)
  1262. {
  1263. struct qed_hwfn *hwfn;
  1264. struct qed_ptt *ptt;
  1265. int i, rc;
  1266. if (IS_VF(cdev))
  1267. return 0;
  1268. for_each_hwfn(cdev, i) {
  1269. hwfn = &cdev->hwfns[i];
  1270. ptt = qed_ptt_acquire(hwfn);
  1271. if (!ptt) {
  1272. DP_NOTICE(hwfn, "Failed to drain NIG; No PTT\n");
  1273. return -EBUSY;
  1274. }
  1275. rc = qed_mcp_drain(hwfn, ptt);
  1276. if (rc)
  1277. return rc;
  1278. qed_ptt_release(hwfn, ptt);
  1279. }
  1280. return 0;
  1281. }
  1282. static int qed_nvm_get_image(struct qed_dev *cdev, enum qed_nvm_images type,
  1283. u8 *buf, u16 len)
  1284. {
  1285. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1286. struct qed_ptt *ptt = qed_ptt_acquire(hwfn);
  1287. int rc;
  1288. if (!ptt)
  1289. return -EAGAIN;
  1290. rc = qed_mcp_get_nvm_image(hwfn, ptt, type, buf, len);
  1291. qed_ptt_release(hwfn, ptt);
  1292. return rc;
  1293. }
  1294. static int qed_set_coalesce(struct qed_dev *cdev, u16 rx_coal, u16 tx_coal,
  1295. void *handle)
  1296. {
  1297. return qed_set_queue_coalesce(rx_coal, tx_coal, handle);
  1298. }
  1299. static int qed_set_led(struct qed_dev *cdev, enum qed_led_mode mode)
  1300. {
  1301. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1302. struct qed_ptt *ptt;
  1303. int status = 0;
  1304. ptt = qed_ptt_acquire(hwfn);
  1305. if (!ptt)
  1306. return -EAGAIN;
  1307. status = qed_mcp_set_led(hwfn, ptt, mode);
  1308. qed_ptt_release(hwfn, ptt);
  1309. return status;
  1310. }
  1311. static int qed_update_wol(struct qed_dev *cdev, bool enabled)
  1312. {
  1313. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1314. struct qed_ptt *ptt;
  1315. int rc = 0;
  1316. if (IS_VF(cdev))
  1317. return 0;
  1318. ptt = qed_ptt_acquire(hwfn);
  1319. if (!ptt)
  1320. return -EAGAIN;
  1321. rc = qed_mcp_ov_update_wol(hwfn, ptt, enabled ? QED_OV_WOL_ENABLED
  1322. : QED_OV_WOL_DISABLED);
  1323. if (rc)
  1324. goto out;
  1325. rc = qed_mcp_ov_update_current_config(hwfn, ptt, QED_OV_CLIENT_DRV);
  1326. out:
  1327. qed_ptt_release(hwfn, ptt);
  1328. return rc;
  1329. }
  1330. static int qed_update_drv_state(struct qed_dev *cdev, bool active)
  1331. {
  1332. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1333. struct qed_ptt *ptt;
  1334. int status = 0;
  1335. if (IS_VF(cdev))
  1336. return 0;
  1337. ptt = qed_ptt_acquire(hwfn);
  1338. if (!ptt)
  1339. return -EAGAIN;
  1340. status = qed_mcp_ov_update_driver_state(hwfn, ptt, active ?
  1341. QED_OV_DRIVER_STATE_ACTIVE :
  1342. QED_OV_DRIVER_STATE_DISABLED);
  1343. qed_ptt_release(hwfn, ptt);
  1344. return status;
  1345. }
  1346. static int qed_update_mac(struct qed_dev *cdev, u8 *mac)
  1347. {
  1348. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1349. struct qed_ptt *ptt;
  1350. int status = 0;
  1351. if (IS_VF(cdev))
  1352. return 0;
  1353. ptt = qed_ptt_acquire(hwfn);
  1354. if (!ptt)
  1355. return -EAGAIN;
  1356. status = qed_mcp_ov_update_mac(hwfn, ptt, mac);
  1357. if (status)
  1358. goto out;
  1359. status = qed_mcp_ov_update_current_config(hwfn, ptt, QED_OV_CLIENT_DRV);
  1360. out:
  1361. qed_ptt_release(hwfn, ptt);
  1362. return status;
  1363. }
  1364. static int qed_update_mtu(struct qed_dev *cdev, u16 mtu)
  1365. {
  1366. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1367. struct qed_ptt *ptt;
  1368. int status = 0;
  1369. if (IS_VF(cdev))
  1370. return 0;
  1371. ptt = qed_ptt_acquire(hwfn);
  1372. if (!ptt)
  1373. return -EAGAIN;
  1374. status = qed_mcp_ov_update_mtu(hwfn, ptt, mtu);
  1375. if (status)
  1376. goto out;
  1377. status = qed_mcp_ov_update_current_config(hwfn, ptt, QED_OV_CLIENT_DRV);
  1378. out:
  1379. qed_ptt_release(hwfn, ptt);
  1380. return status;
  1381. }
  1382. static struct qed_selftest_ops qed_selftest_ops_pass = {
  1383. .selftest_memory = &qed_selftest_memory,
  1384. .selftest_interrupt = &qed_selftest_interrupt,
  1385. .selftest_register = &qed_selftest_register,
  1386. .selftest_clock = &qed_selftest_clock,
  1387. .selftest_nvram = &qed_selftest_nvram,
  1388. };
  1389. const struct qed_common_ops qed_common_ops_pass = {
  1390. .selftest = &qed_selftest_ops_pass,
  1391. .probe = &qed_probe,
  1392. .remove = &qed_remove,
  1393. .set_power_state = &qed_set_power_state,
  1394. .set_name = &qed_set_name,
  1395. .update_pf_params = &qed_update_pf_params,
  1396. .slowpath_start = &qed_slowpath_start,
  1397. .slowpath_stop = &qed_slowpath_stop,
  1398. .set_fp_int = &qed_set_int_fp,
  1399. .get_fp_int = &qed_get_int_fp,
  1400. .sb_init = &qed_sb_init,
  1401. .sb_release = &qed_sb_release,
  1402. .simd_handler_config = &qed_simd_handler_config,
  1403. .simd_handler_clean = &qed_simd_handler_clean,
  1404. .dbg_grc = &qed_dbg_grc,
  1405. .dbg_grc_size = &qed_dbg_grc_size,
  1406. .can_link_change = &qed_can_link_change,
  1407. .set_link = &qed_set_link,
  1408. .get_link = &qed_get_current_link,
  1409. .drain = &qed_drain,
  1410. .update_msglvl = &qed_init_dp,
  1411. .dbg_all_data = &qed_dbg_all_data,
  1412. .dbg_all_data_size = &qed_dbg_all_data_size,
  1413. .chain_alloc = &qed_chain_alloc,
  1414. .chain_free = &qed_chain_free,
  1415. .nvm_get_image = &qed_nvm_get_image,
  1416. .set_coalesce = &qed_set_coalesce,
  1417. .set_led = &qed_set_led,
  1418. .update_drv_state = &qed_update_drv_state,
  1419. .update_mac = &qed_update_mac,
  1420. .update_mtu = &qed_update_mtu,
  1421. .update_wol = &qed_update_wol,
  1422. };
  1423. void qed_get_protocol_stats(struct qed_dev *cdev,
  1424. enum qed_mcp_protocol_type type,
  1425. union qed_mcp_protocol_stats *stats)
  1426. {
  1427. struct qed_eth_stats eth_stats;
  1428. memset(stats, 0, sizeof(*stats));
  1429. switch (type) {
  1430. case QED_MCP_LAN_STATS:
  1431. qed_get_vport_stats(cdev, &eth_stats);
  1432. stats->lan_stats.ucast_rx_pkts =
  1433. eth_stats.common.rx_ucast_pkts;
  1434. stats->lan_stats.ucast_tx_pkts =
  1435. eth_stats.common.tx_ucast_pkts;
  1436. stats->lan_stats.fcs_err = -1;
  1437. break;
  1438. case QED_MCP_FCOE_STATS:
  1439. qed_get_protocol_stats_fcoe(cdev, &stats->fcoe_stats);
  1440. break;
  1441. case QED_MCP_ISCSI_STATS:
  1442. qed_get_protocol_stats_iscsi(cdev, &stats->iscsi_stats);
  1443. break;
  1444. default:
  1445. DP_VERBOSE(cdev, QED_MSG_SP,
  1446. "Invalid protocol type = %d\n", type);
  1447. return;
  1448. }
  1449. }