qed_main.c 39 KB

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