qed_main.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736
  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_ERR(cdev, "Invalid protocol type = %d\n", type);
  1430. return;
  1431. }
  1432. }