qed_main.c 44 KB

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