PageRenderTime 63ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c

http://github.com/mirrors/linux-2.6
C | 3751 lines | 3110 code | 468 blank | 173 comment | 361 complexity | 3676bcd3035bf02ae526d9d1ca1afd41 MD5 | raw file
Possible License(s): LGPL-2.0, AGPL-1.0, GPL-2.0
  1. /*
  2. * This file is part of the Chelsio T4 Ethernet driver for Linux.
  3. *
  4. * Copyright (c) 2003-2014 Chelsio Communications, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. */
  34. #include <linux/seq_file.h>
  35. #include <linux/debugfs.h>
  36. #include <linux/string_helpers.h>
  37. #include <linux/sort.h>
  38. #include <linux/ctype.h>
  39. #include "cxgb4.h"
  40. #include "t4_regs.h"
  41. #include "t4_values.h"
  42. #include "t4fw_api.h"
  43. #include "cxgb4_debugfs.h"
  44. #include "clip_tbl.h"
  45. #include "l2t.h"
  46. #include "cudbg_if.h"
  47. #include "cudbg_lib_common.h"
  48. #include "cudbg_entity.h"
  49. #include "cudbg_lib.h"
  50. /* generic seq_file support for showing a table of size rows x width. */
  51. static void *seq_tab_get_idx(struct seq_tab *tb, loff_t pos)
  52. {
  53. pos -= tb->skip_first;
  54. return pos >= tb->rows ? NULL : &tb->data[pos * tb->width];
  55. }
  56. static void *seq_tab_start(struct seq_file *seq, loff_t *pos)
  57. {
  58. struct seq_tab *tb = seq->private;
  59. if (tb->skip_first && *pos == 0)
  60. return SEQ_START_TOKEN;
  61. return seq_tab_get_idx(tb, *pos);
  62. }
  63. static void *seq_tab_next(struct seq_file *seq, void *v, loff_t *pos)
  64. {
  65. v = seq_tab_get_idx(seq->private, *pos + 1);
  66. ++(*pos);
  67. return v;
  68. }
  69. static void seq_tab_stop(struct seq_file *seq, void *v)
  70. {
  71. }
  72. static int seq_tab_show(struct seq_file *seq, void *v)
  73. {
  74. const struct seq_tab *tb = seq->private;
  75. return tb->show(seq, v, ((char *)v - tb->data) / tb->width);
  76. }
  77. static const struct seq_operations seq_tab_ops = {
  78. .start = seq_tab_start,
  79. .next = seq_tab_next,
  80. .stop = seq_tab_stop,
  81. .show = seq_tab_show
  82. };
  83. struct seq_tab *seq_open_tab(struct file *f, unsigned int rows,
  84. unsigned int width, unsigned int have_header,
  85. int (*show)(struct seq_file *seq, void *v, int i))
  86. {
  87. struct seq_tab *p;
  88. p = __seq_open_private(f, &seq_tab_ops, sizeof(*p) + rows * width);
  89. if (p) {
  90. p->show = show;
  91. p->rows = rows;
  92. p->width = width;
  93. p->skip_first = have_header != 0;
  94. }
  95. return p;
  96. }
  97. /* Trim the size of a seq_tab to the supplied number of rows. The operation is
  98. * irreversible.
  99. */
  100. static int seq_tab_trim(struct seq_tab *p, unsigned int new_rows)
  101. {
  102. if (new_rows > p->rows)
  103. return -EINVAL;
  104. p->rows = new_rows;
  105. return 0;
  106. }
  107. static int cim_la_show(struct seq_file *seq, void *v, int idx)
  108. {
  109. if (v == SEQ_START_TOKEN)
  110. seq_puts(seq, "Status Data PC LS0Stat LS0Addr "
  111. " LS0Data\n");
  112. else {
  113. const u32 *p = v;
  114. seq_printf(seq,
  115. " %02x %x%07x %x%07x %08x %08x %08x%08x%08x%08x\n",
  116. (p[0] >> 4) & 0xff, p[0] & 0xf, p[1] >> 4,
  117. p[1] & 0xf, p[2] >> 4, p[2] & 0xf, p[3], p[4], p[5],
  118. p[6], p[7]);
  119. }
  120. return 0;
  121. }
  122. static int cim_la_show_3in1(struct seq_file *seq, void *v, int idx)
  123. {
  124. if (v == SEQ_START_TOKEN) {
  125. seq_puts(seq, "Status Data PC\n");
  126. } else {
  127. const u32 *p = v;
  128. seq_printf(seq, " %02x %08x %08x\n", p[5] & 0xff, p[6],
  129. p[7]);
  130. seq_printf(seq, " %02x %02x%06x %02x%06x\n",
  131. (p[3] >> 8) & 0xff, p[3] & 0xff, p[4] >> 8,
  132. p[4] & 0xff, p[5] >> 8);
  133. seq_printf(seq, " %02x %x%07x %x%07x\n", (p[0] >> 4) & 0xff,
  134. p[0] & 0xf, p[1] >> 4, p[1] & 0xf, p[2] >> 4);
  135. }
  136. return 0;
  137. }
  138. static int cim_la_show_t6(struct seq_file *seq, void *v, int idx)
  139. {
  140. if (v == SEQ_START_TOKEN) {
  141. seq_puts(seq, "Status Inst Data PC LS0Stat "
  142. "LS0Addr LS0Data LS1Stat LS1Addr LS1Data\n");
  143. } else {
  144. const u32 *p = v;
  145. seq_printf(seq, " %02x %04x%04x %04x%04x %04x%04x %08x %08x %08x %08x %08x %08x\n",
  146. (p[9] >> 16) & 0xff, /* Status */
  147. p[9] & 0xffff, p[8] >> 16, /* Inst */
  148. p[8] & 0xffff, p[7] >> 16, /* Data */
  149. p[7] & 0xffff, p[6] >> 16, /* PC */
  150. p[2], p[1], p[0], /* LS0 Stat, Addr and Data */
  151. p[5], p[4], p[3]); /* LS1 Stat, Addr and Data */
  152. }
  153. return 0;
  154. }
  155. static int cim_la_show_pc_t6(struct seq_file *seq, void *v, int idx)
  156. {
  157. if (v == SEQ_START_TOKEN) {
  158. seq_puts(seq, "Status Inst Data PC\n");
  159. } else {
  160. const u32 *p = v;
  161. seq_printf(seq, " %02x %08x %08x %08x\n",
  162. p[3] & 0xff, p[2], p[1], p[0]);
  163. seq_printf(seq, " %02x %02x%06x %02x%06x %02x%06x\n",
  164. (p[6] >> 8) & 0xff, p[6] & 0xff, p[5] >> 8,
  165. p[5] & 0xff, p[4] >> 8, p[4] & 0xff, p[3] >> 8);
  166. seq_printf(seq, " %02x %04x%04x %04x%04x %04x%04x\n",
  167. (p[9] >> 16) & 0xff, p[9] & 0xffff, p[8] >> 16,
  168. p[8] & 0xffff, p[7] >> 16, p[7] & 0xffff,
  169. p[6] >> 16);
  170. }
  171. return 0;
  172. }
  173. static int cim_la_open(struct inode *inode, struct file *file)
  174. {
  175. int ret;
  176. unsigned int cfg;
  177. struct seq_tab *p;
  178. struct adapter *adap = inode->i_private;
  179. ret = t4_cim_read(adap, UP_UP_DBG_LA_CFG_A, 1, &cfg);
  180. if (ret)
  181. return ret;
  182. if (is_t6(adap->params.chip)) {
  183. /* +1 to account for integer division of CIMLA_SIZE/10 */
  184. p = seq_open_tab(file, (adap->params.cim_la_size / 10) + 1,
  185. 10 * sizeof(u32), 1,
  186. cfg & UPDBGLACAPTPCONLY_F ?
  187. cim_la_show_pc_t6 : cim_la_show_t6);
  188. } else {
  189. p = seq_open_tab(file, adap->params.cim_la_size / 8,
  190. 8 * sizeof(u32), 1,
  191. cfg & UPDBGLACAPTPCONLY_F ? cim_la_show_3in1 :
  192. cim_la_show);
  193. }
  194. if (!p)
  195. return -ENOMEM;
  196. ret = t4_cim_read_la(adap, (u32 *)p->data, NULL);
  197. if (ret)
  198. seq_release_private(inode, file);
  199. return ret;
  200. }
  201. static const struct file_operations cim_la_fops = {
  202. .owner = THIS_MODULE,
  203. .open = cim_la_open,
  204. .read = seq_read,
  205. .llseek = seq_lseek,
  206. .release = seq_release_private
  207. };
  208. static int cim_pif_la_show(struct seq_file *seq, void *v, int idx)
  209. {
  210. const u32 *p = v;
  211. if (v == SEQ_START_TOKEN) {
  212. seq_puts(seq, "Cntl ID DataBE Addr Data\n");
  213. } else if (idx < CIM_PIFLA_SIZE) {
  214. seq_printf(seq, " %02x %02x %04x %08x %08x%08x%08x%08x\n",
  215. (p[5] >> 22) & 0xff, (p[5] >> 16) & 0x3f,
  216. p[5] & 0xffff, p[4], p[3], p[2], p[1], p[0]);
  217. } else {
  218. if (idx == CIM_PIFLA_SIZE)
  219. seq_puts(seq, "\nCntl ID Data\n");
  220. seq_printf(seq, " %02x %02x %08x%08x%08x%08x\n",
  221. (p[4] >> 6) & 0xff, p[4] & 0x3f,
  222. p[3], p[2], p[1], p[0]);
  223. }
  224. return 0;
  225. }
  226. static int cim_pif_la_open(struct inode *inode, struct file *file)
  227. {
  228. struct seq_tab *p;
  229. struct adapter *adap = inode->i_private;
  230. p = seq_open_tab(file, 2 * CIM_PIFLA_SIZE, 6 * sizeof(u32), 1,
  231. cim_pif_la_show);
  232. if (!p)
  233. return -ENOMEM;
  234. t4_cim_read_pif_la(adap, (u32 *)p->data,
  235. (u32 *)p->data + 6 * CIM_PIFLA_SIZE, NULL, NULL);
  236. return 0;
  237. }
  238. static const struct file_operations cim_pif_la_fops = {
  239. .owner = THIS_MODULE,
  240. .open = cim_pif_la_open,
  241. .read = seq_read,
  242. .llseek = seq_lseek,
  243. .release = seq_release_private
  244. };
  245. static int cim_ma_la_show(struct seq_file *seq, void *v, int idx)
  246. {
  247. const u32 *p = v;
  248. if (v == SEQ_START_TOKEN) {
  249. seq_puts(seq, "\n");
  250. } else if (idx < CIM_MALA_SIZE) {
  251. seq_printf(seq, "%02x%08x%08x%08x%08x\n",
  252. p[4], p[3], p[2], p[1], p[0]);
  253. } else {
  254. if (idx == CIM_MALA_SIZE)
  255. seq_puts(seq,
  256. "\nCnt ID Tag UE Data RDY VLD\n");
  257. seq_printf(seq, "%3u %2u %x %u %08x%08x %u %u\n",
  258. (p[2] >> 10) & 0xff, (p[2] >> 7) & 7,
  259. (p[2] >> 3) & 0xf, (p[2] >> 2) & 1,
  260. (p[1] >> 2) | ((p[2] & 3) << 30),
  261. (p[0] >> 2) | ((p[1] & 3) << 30), (p[0] >> 1) & 1,
  262. p[0] & 1);
  263. }
  264. return 0;
  265. }
  266. static int cim_ma_la_open(struct inode *inode, struct file *file)
  267. {
  268. struct seq_tab *p;
  269. struct adapter *adap = inode->i_private;
  270. p = seq_open_tab(file, 2 * CIM_MALA_SIZE, 5 * sizeof(u32), 1,
  271. cim_ma_la_show);
  272. if (!p)
  273. return -ENOMEM;
  274. t4_cim_read_ma_la(adap, (u32 *)p->data,
  275. (u32 *)p->data + 5 * CIM_MALA_SIZE);
  276. return 0;
  277. }
  278. static const struct file_operations cim_ma_la_fops = {
  279. .owner = THIS_MODULE,
  280. .open = cim_ma_la_open,
  281. .read = seq_read,
  282. .llseek = seq_lseek,
  283. .release = seq_release_private
  284. };
  285. static int cim_qcfg_show(struct seq_file *seq, void *v)
  286. {
  287. static const char * const qname[] = {
  288. "TP0", "TP1", "ULP", "SGE0", "SGE1", "NC-SI",
  289. "ULP0", "ULP1", "ULP2", "ULP3", "SGE", "NC-SI",
  290. "SGE0-RX", "SGE1-RX"
  291. };
  292. int i;
  293. struct adapter *adap = seq->private;
  294. u16 base[CIM_NUM_IBQ + CIM_NUM_OBQ_T5];
  295. u16 size[CIM_NUM_IBQ + CIM_NUM_OBQ_T5];
  296. u32 stat[(4 * (CIM_NUM_IBQ + CIM_NUM_OBQ_T5))];
  297. u16 thres[CIM_NUM_IBQ];
  298. u32 obq_wr_t4[2 * CIM_NUM_OBQ], *wr;
  299. u32 obq_wr_t5[2 * CIM_NUM_OBQ_T5];
  300. u32 *p = stat;
  301. int cim_num_obq = is_t4(adap->params.chip) ?
  302. CIM_NUM_OBQ : CIM_NUM_OBQ_T5;
  303. i = t4_cim_read(adap, is_t4(adap->params.chip) ? UP_IBQ_0_RDADDR_A :
  304. UP_IBQ_0_SHADOW_RDADDR_A,
  305. ARRAY_SIZE(stat), stat);
  306. if (!i) {
  307. if (is_t4(adap->params.chip)) {
  308. i = t4_cim_read(adap, UP_OBQ_0_REALADDR_A,
  309. ARRAY_SIZE(obq_wr_t4), obq_wr_t4);
  310. wr = obq_wr_t4;
  311. } else {
  312. i = t4_cim_read(adap, UP_OBQ_0_SHADOW_REALADDR_A,
  313. ARRAY_SIZE(obq_wr_t5), obq_wr_t5);
  314. wr = obq_wr_t5;
  315. }
  316. }
  317. if (i)
  318. return i;
  319. t4_read_cimq_cfg(adap, base, size, thres);
  320. seq_printf(seq,
  321. " Queue Base Size Thres RdPtr WrPtr SOP EOP Avail\n");
  322. for (i = 0; i < CIM_NUM_IBQ; i++, p += 4)
  323. seq_printf(seq, "%7s %5x %5u %5u %6x %4x %4u %4u %5u\n",
  324. qname[i], base[i], size[i], thres[i],
  325. IBQRDADDR_G(p[0]), IBQWRADDR_G(p[1]),
  326. QUESOPCNT_G(p[3]), QUEEOPCNT_G(p[3]),
  327. QUEREMFLITS_G(p[2]) * 16);
  328. for ( ; i < CIM_NUM_IBQ + cim_num_obq; i++, p += 4, wr += 2)
  329. seq_printf(seq, "%7s %5x %5u %12x %4x %4u %4u %5u\n",
  330. qname[i], base[i], size[i],
  331. QUERDADDR_G(p[0]) & 0x3fff, wr[0] - base[i],
  332. QUESOPCNT_G(p[3]), QUEEOPCNT_G(p[3]),
  333. QUEREMFLITS_G(p[2]) * 16);
  334. return 0;
  335. }
  336. DEFINE_SHOW_ATTRIBUTE(cim_qcfg);
  337. static int cimq_show(struct seq_file *seq, void *v, int idx)
  338. {
  339. const u32 *p = v;
  340. seq_printf(seq, "%#06x: %08x %08x %08x %08x\n", idx * 16, p[0], p[1],
  341. p[2], p[3]);
  342. return 0;
  343. }
  344. static int cim_ibq_open(struct inode *inode, struct file *file)
  345. {
  346. int ret;
  347. struct seq_tab *p;
  348. unsigned int qid = (uintptr_t)inode->i_private & 7;
  349. struct adapter *adap = inode->i_private - qid;
  350. p = seq_open_tab(file, CIM_IBQ_SIZE, 4 * sizeof(u32), 0, cimq_show);
  351. if (!p)
  352. return -ENOMEM;
  353. ret = t4_read_cim_ibq(adap, qid, (u32 *)p->data, CIM_IBQ_SIZE * 4);
  354. if (ret < 0)
  355. seq_release_private(inode, file);
  356. else
  357. ret = 0;
  358. return ret;
  359. }
  360. static const struct file_operations cim_ibq_fops = {
  361. .owner = THIS_MODULE,
  362. .open = cim_ibq_open,
  363. .read = seq_read,
  364. .llseek = seq_lseek,
  365. .release = seq_release_private
  366. };
  367. static int cim_obq_open(struct inode *inode, struct file *file)
  368. {
  369. int ret;
  370. struct seq_tab *p;
  371. unsigned int qid = (uintptr_t)inode->i_private & 7;
  372. struct adapter *adap = inode->i_private - qid;
  373. p = seq_open_tab(file, 6 * CIM_OBQ_SIZE, 4 * sizeof(u32), 0, cimq_show);
  374. if (!p)
  375. return -ENOMEM;
  376. ret = t4_read_cim_obq(adap, qid, (u32 *)p->data, 6 * CIM_OBQ_SIZE * 4);
  377. if (ret < 0) {
  378. seq_release_private(inode, file);
  379. } else {
  380. seq_tab_trim(p, ret / 4);
  381. ret = 0;
  382. }
  383. return ret;
  384. }
  385. static const struct file_operations cim_obq_fops = {
  386. .owner = THIS_MODULE,
  387. .open = cim_obq_open,
  388. .read = seq_read,
  389. .llseek = seq_lseek,
  390. .release = seq_release_private
  391. };
  392. struct field_desc {
  393. const char *name;
  394. unsigned int start;
  395. unsigned int width;
  396. };
  397. static void field_desc_show(struct seq_file *seq, u64 v,
  398. const struct field_desc *p)
  399. {
  400. char buf[32];
  401. int line_size = 0;
  402. while (p->name) {
  403. u64 mask = (1ULL << p->width) - 1;
  404. int len = scnprintf(buf, sizeof(buf), "%s: %llu", p->name,
  405. ((unsigned long long)v >> p->start) & mask);
  406. if (line_size + len >= 79) {
  407. line_size = 8;
  408. seq_puts(seq, "\n ");
  409. }
  410. seq_printf(seq, "%s ", buf);
  411. line_size += len + 1;
  412. p++;
  413. }
  414. seq_putc(seq, '\n');
  415. }
  416. static struct field_desc tp_la0[] = {
  417. { "RcfOpCodeOut", 60, 4 },
  418. { "State", 56, 4 },
  419. { "WcfState", 52, 4 },
  420. { "RcfOpcSrcOut", 50, 2 },
  421. { "CRxError", 49, 1 },
  422. { "ERxError", 48, 1 },
  423. { "SanityFailed", 47, 1 },
  424. { "SpuriousMsg", 46, 1 },
  425. { "FlushInputMsg", 45, 1 },
  426. { "FlushInputCpl", 44, 1 },
  427. { "RssUpBit", 43, 1 },
  428. { "RssFilterHit", 42, 1 },
  429. { "Tid", 32, 10 },
  430. { "InitTcb", 31, 1 },
  431. { "LineNumber", 24, 7 },
  432. { "Emsg", 23, 1 },
  433. { "EdataOut", 22, 1 },
  434. { "Cmsg", 21, 1 },
  435. { "CdataOut", 20, 1 },
  436. { "EreadPdu", 19, 1 },
  437. { "CreadPdu", 18, 1 },
  438. { "TunnelPkt", 17, 1 },
  439. { "RcfPeerFin", 16, 1 },
  440. { "RcfReasonOut", 12, 4 },
  441. { "TxCchannel", 10, 2 },
  442. { "RcfTxChannel", 8, 2 },
  443. { "RxEchannel", 6, 2 },
  444. { "RcfRxChannel", 5, 1 },
  445. { "RcfDataOutSrdy", 4, 1 },
  446. { "RxDvld", 3, 1 },
  447. { "RxOoDvld", 2, 1 },
  448. { "RxCongestion", 1, 1 },
  449. { "TxCongestion", 0, 1 },
  450. { NULL }
  451. };
  452. static int tp_la_show(struct seq_file *seq, void *v, int idx)
  453. {
  454. const u64 *p = v;
  455. field_desc_show(seq, *p, tp_la0);
  456. return 0;
  457. }
  458. static int tp_la_show2(struct seq_file *seq, void *v, int idx)
  459. {
  460. const u64 *p = v;
  461. if (idx)
  462. seq_putc(seq, '\n');
  463. field_desc_show(seq, p[0], tp_la0);
  464. if (idx < (TPLA_SIZE / 2 - 1) || p[1] != ~0ULL)
  465. field_desc_show(seq, p[1], tp_la0);
  466. return 0;
  467. }
  468. static int tp_la_show3(struct seq_file *seq, void *v, int idx)
  469. {
  470. static struct field_desc tp_la1[] = {
  471. { "CplCmdIn", 56, 8 },
  472. { "CplCmdOut", 48, 8 },
  473. { "ESynOut", 47, 1 },
  474. { "EAckOut", 46, 1 },
  475. { "EFinOut", 45, 1 },
  476. { "ERstOut", 44, 1 },
  477. { "SynIn", 43, 1 },
  478. { "AckIn", 42, 1 },
  479. { "FinIn", 41, 1 },
  480. { "RstIn", 40, 1 },
  481. { "DataIn", 39, 1 },
  482. { "DataInVld", 38, 1 },
  483. { "PadIn", 37, 1 },
  484. { "RxBufEmpty", 36, 1 },
  485. { "RxDdp", 35, 1 },
  486. { "RxFbCongestion", 34, 1 },
  487. { "TxFbCongestion", 33, 1 },
  488. { "TxPktSumSrdy", 32, 1 },
  489. { "RcfUlpType", 28, 4 },
  490. { "Eread", 27, 1 },
  491. { "Ebypass", 26, 1 },
  492. { "Esave", 25, 1 },
  493. { "Static0", 24, 1 },
  494. { "Cread", 23, 1 },
  495. { "Cbypass", 22, 1 },
  496. { "Csave", 21, 1 },
  497. { "CPktOut", 20, 1 },
  498. { "RxPagePoolFull", 18, 2 },
  499. { "RxLpbkPkt", 17, 1 },
  500. { "TxLpbkPkt", 16, 1 },
  501. { "RxVfValid", 15, 1 },
  502. { "SynLearned", 14, 1 },
  503. { "SetDelEntry", 13, 1 },
  504. { "SetInvEntry", 12, 1 },
  505. { "CpcmdDvld", 11, 1 },
  506. { "CpcmdSave", 10, 1 },
  507. { "RxPstructsFull", 8, 2 },
  508. { "EpcmdDvld", 7, 1 },
  509. { "EpcmdFlush", 6, 1 },
  510. { "EpcmdTrimPrefix", 5, 1 },
  511. { "EpcmdTrimPostfix", 4, 1 },
  512. { "ERssIp4Pkt", 3, 1 },
  513. { "ERssIp6Pkt", 2, 1 },
  514. { "ERssTcpUdpPkt", 1, 1 },
  515. { "ERssFceFipPkt", 0, 1 },
  516. { NULL }
  517. };
  518. static struct field_desc tp_la2[] = {
  519. { "CplCmdIn", 56, 8 },
  520. { "MpsVfVld", 55, 1 },
  521. { "MpsPf", 52, 3 },
  522. { "MpsVf", 44, 8 },
  523. { "SynIn", 43, 1 },
  524. { "AckIn", 42, 1 },
  525. { "FinIn", 41, 1 },
  526. { "RstIn", 40, 1 },
  527. { "DataIn", 39, 1 },
  528. { "DataInVld", 38, 1 },
  529. { "PadIn", 37, 1 },
  530. { "RxBufEmpty", 36, 1 },
  531. { "RxDdp", 35, 1 },
  532. { "RxFbCongestion", 34, 1 },
  533. { "TxFbCongestion", 33, 1 },
  534. { "TxPktSumSrdy", 32, 1 },
  535. { "RcfUlpType", 28, 4 },
  536. { "Eread", 27, 1 },
  537. { "Ebypass", 26, 1 },
  538. { "Esave", 25, 1 },
  539. { "Static0", 24, 1 },
  540. { "Cread", 23, 1 },
  541. { "Cbypass", 22, 1 },
  542. { "Csave", 21, 1 },
  543. { "CPktOut", 20, 1 },
  544. { "RxPagePoolFull", 18, 2 },
  545. { "RxLpbkPkt", 17, 1 },
  546. { "TxLpbkPkt", 16, 1 },
  547. { "RxVfValid", 15, 1 },
  548. { "SynLearned", 14, 1 },
  549. { "SetDelEntry", 13, 1 },
  550. { "SetInvEntry", 12, 1 },
  551. { "CpcmdDvld", 11, 1 },
  552. { "CpcmdSave", 10, 1 },
  553. { "RxPstructsFull", 8, 2 },
  554. { "EpcmdDvld", 7, 1 },
  555. { "EpcmdFlush", 6, 1 },
  556. { "EpcmdTrimPrefix", 5, 1 },
  557. { "EpcmdTrimPostfix", 4, 1 },
  558. { "ERssIp4Pkt", 3, 1 },
  559. { "ERssIp6Pkt", 2, 1 },
  560. { "ERssTcpUdpPkt", 1, 1 },
  561. { "ERssFceFipPkt", 0, 1 },
  562. { NULL }
  563. };
  564. const u64 *p = v;
  565. if (idx)
  566. seq_putc(seq, '\n');
  567. field_desc_show(seq, p[0], tp_la0);
  568. if (idx < (TPLA_SIZE / 2 - 1) || p[1] != ~0ULL)
  569. field_desc_show(seq, p[1], (p[0] & BIT(17)) ? tp_la2 : tp_la1);
  570. return 0;
  571. }
  572. static int tp_la_open(struct inode *inode, struct file *file)
  573. {
  574. struct seq_tab *p;
  575. struct adapter *adap = inode->i_private;
  576. switch (DBGLAMODE_G(t4_read_reg(adap, TP_DBG_LA_CONFIG_A))) {
  577. case 2:
  578. p = seq_open_tab(file, TPLA_SIZE / 2, 2 * sizeof(u64), 0,
  579. tp_la_show2);
  580. break;
  581. case 3:
  582. p = seq_open_tab(file, TPLA_SIZE / 2, 2 * sizeof(u64), 0,
  583. tp_la_show3);
  584. break;
  585. default:
  586. p = seq_open_tab(file, TPLA_SIZE, sizeof(u64), 0, tp_la_show);
  587. }
  588. if (!p)
  589. return -ENOMEM;
  590. t4_tp_read_la(adap, (u64 *)p->data, NULL);
  591. return 0;
  592. }
  593. static ssize_t tp_la_write(struct file *file, const char __user *buf,
  594. size_t count, loff_t *pos)
  595. {
  596. int err;
  597. char s[32];
  598. unsigned long val;
  599. size_t size = min(sizeof(s) - 1, count);
  600. struct adapter *adap = file_inode(file)->i_private;
  601. if (copy_from_user(s, buf, size))
  602. return -EFAULT;
  603. s[size] = '\0';
  604. err = kstrtoul(s, 0, &val);
  605. if (err)
  606. return err;
  607. if (val > 0xffff)
  608. return -EINVAL;
  609. adap->params.tp.la_mask = val << 16;
  610. t4_set_reg_field(adap, TP_DBG_LA_CONFIG_A, 0xffff0000U,
  611. adap->params.tp.la_mask);
  612. return count;
  613. }
  614. static const struct file_operations tp_la_fops = {
  615. .owner = THIS_MODULE,
  616. .open = tp_la_open,
  617. .read = seq_read,
  618. .llseek = seq_lseek,
  619. .release = seq_release_private,
  620. .write = tp_la_write
  621. };
  622. static int ulprx_la_show(struct seq_file *seq, void *v, int idx)
  623. {
  624. const u32 *p = v;
  625. if (v == SEQ_START_TOKEN)
  626. seq_puts(seq, " Pcmd Type Message"
  627. " Data\n");
  628. else
  629. seq_printf(seq, "%08x%08x %4x %08x %08x%08x%08x%08x\n",
  630. p[1], p[0], p[2], p[3], p[7], p[6], p[5], p[4]);
  631. return 0;
  632. }
  633. static int ulprx_la_open(struct inode *inode, struct file *file)
  634. {
  635. struct seq_tab *p;
  636. struct adapter *adap = inode->i_private;
  637. p = seq_open_tab(file, ULPRX_LA_SIZE, 8 * sizeof(u32), 1,
  638. ulprx_la_show);
  639. if (!p)
  640. return -ENOMEM;
  641. t4_ulprx_read_la(adap, (u32 *)p->data);
  642. return 0;
  643. }
  644. static const struct file_operations ulprx_la_fops = {
  645. .owner = THIS_MODULE,
  646. .open = ulprx_la_open,
  647. .read = seq_read,
  648. .llseek = seq_lseek,
  649. .release = seq_release_private
  650. };
  651. /* Show the PM memory stats. These stats include:
  652. *
  653. * TX:
  654. * Read: memory read operation
  655. * Write Bypass: cut-through
  656. * Bypass + mem: cut-through and save copy
  657. *
  658. * RX:
  659. * Read: memory read
  660. * Write Bypass: cut-through
  661. * Flush: payload trim or drop
  662. */
  663. static int pm_stats_show(struct seq_file *seq, void *v)
  664. {
  665. static const char * const tx_pm_stats[] = {
  666. "Read:", "Write bypass:", "Write mem:", "Bypass + mem:"
  667. };
  668. static const char * const rx_pm_stats[] = {
  669. "Read:", "Write bypass:", "Write mem:", "Flush:"
  670. };
  671. int i;
  672. u32 tx_cnt[T6_PM_NSTATS], rx_cnt[T6_PM_NSTATS];
  673. u64 tx_cyc[T6_PM_NSTATS], rx_cyc[T6_PM_NSTATS];
  674. struct adapter *adap = seq->private;
  675. t4_pmtx_get_stats(adap, tx_cnt, tx_cyc);
  676. t4_pmrx_get_stats(adap, rx_cnt, rx_cyc);
  677. seq_printf(seq, "%13s %10s %20s\n", " ", "Tx pcmds", "Tx bytes");
  678. for (i = 0; i < PM_NSTATS - 1; i++)
  679. seq_printf(seq, "%-13s %10u %20llu\n",
  680. tx_pm_stats[i], tx_cnt[i], tx_cyc[i]);
  681. seq_printf(seq, "%13s %10s %20s\n", " ", "Rx pcmds", "Rx bytes");
  682. for (i = 0; i < PM_NSTATS - 1; i++)
  683. seq_printf(seq, "%-13s %10u %20llu\n",
  684. rx_pm_stats[i], rx_cnt[i], rx_cyc[i]);
  685. if (CHELSIO_CHIP_VERSION(adap->params.chip) > CHELSIO_T5) {
  686. /* In T5 the granularity of the total wait is too fine.
  687. * It is not useful as it reaches the max value too fast.
  688. * Hence display this Input FIFO wait for T6 onwards.
  689. */
  690. seq_printf(seq, "%13s %10s %20s\n",
  691. " ", "Total wait", "Total Occupancy");
  692. seq_printf(seq, "Tx FIFO wait %10u %20llu\n",
  693. tx_cnt[i], tx_cyc[i]);
  694. seq_printf(seq, "Rx FIFO wait %10u %20llu\n",
  695. rx_cnt[i], rx_cyc[i]);
  696. /* Skip index 6 as there is nothing useful ihere */
  697. i += 2;
  698. /* At index 7, a new stat for read latency (count, total wait)
  699. * is added.
  700. */
  701. seq_printf(seq, "%13s %10s %20s\n",
  702. " ", "Reads", "Total wait");
  703. seq_printf(seq, "Tx latency %10u %20llu\n",
  704. tx_cnt[i], tx_cyc[i]);
  705. seq_printf(seq, "Rx latency %10u %20llu\n",
  706. rx_cnt[i], rx_cyc[i]);
  707. }
  708. return 0;
  709. }
  710. static int pm_stats_open(struct inode *inode, struct file *file)
  711. {
  712. return single_open(file, pm_stats_show, inode->i_private);
  713. }
  714. static ssize_t pm_stats_clear(struct file *file, const char __user *buf,
  715. size_t count, loff_t *pos)
  716. {
  717. struct adapter *adap = file_inode(file)->i_private;
  718. t4_write_reg(adap, PM_RX_STAT_CONFIG_A, 0);
  719. t4_write_reg(adap, PM_TX_STAT_CONFIG_A, 0);
  720. return count;
  721. }
  722. static const struct file_operations pm_stats_debugfs_fops = {
  723. .owner = THIS_MODULE,
  724. .open = pm_stats_open,
  725. .read = seq_read,
  726. .llseek = seq_lseek,
  727. .release = single_release,
  728. .write = pm_stats_clear
  729. };
  730. static int tx_rate_show(struct seq_file *seq, void *v)
  731. {
  732. u64 nrate[NCHAN], orate[NCHAN];
  733. struct adapter *adap = seq->private;
  734. t4_get_chan_txrate(adap, nrate, orate);
  735. if (adap->params.arch.nchan == NCHAN) {
  736. seq_puts(seq, " channel 0 channel 1 "
  737. "channel 2 channel 3\n");
  738. seq_printf(seq, "NIC B/s: %10llu %10llu %10llu %10llu\n",
  739. (unsigned long long)nrate[0],
  740. (unsigned long long)nrate[1],
  741. (unsigned long long)nrate[2],
  742. (unsigned long long)nrate[3]);
  743. seq_printf(seq, "Offload B/s: %10llu %10llu %10llu %10llu\n",
  744. (unsigned long long)orate[0],
  745. (unsigned long long)orate[1],
  746. (unsigned long long)orate[2],
  747. (unsigned long long)orate[3]);
  748. } else {
  749. seq_puts(seq, " channel 0 channel 1\n");
  750. seq_printf(seq, "NIC B/s: %10llu %10llu\n",
  751. (unsigned long long)nrate[0],
  752. (unsigned long long)nrate[1]);
  753. seq_printf(seq, "Offload B/s: %10llu %10llu\n",
  754. (unsigned long long)orate[0],
  755. (unsigned long long)orate[1]);
  756. }
  757. return 0;
  758. }
  759. DEFINE_SHOW_ATTRIBUTE(tx_rate);
  760. static int cctrl_tbl_show(struct seq_file *seq, void *v)
  761. {
  762. static const char * const dec_fac[] = {
  763. "0.5", "0.5625", "0.625", "0.6875", "0.75", "0.8125", "0.875",
  764. "0.9375" };
  765. int i;
  766. u16 (*incr)[NCCTRL_WIN];
  767. struct adapter *adap = seq->private;
  768. incr = kmalloc_array(NMTUS, sizeof(*incr), GFP_KERNEL);
  769. if (!incr)
  770. return -ENOMEM;
  771. t4_read_cong_tbl(adap, incr);
  772. for (i = 0; i < NCCTRL_WIN; ++i) {
  773. seq_printf(seq, "%2d: %4u %4u %4u %4u %4u %4u %4u %4u\n", i,
  774. incr[0][i], incr[1][i], incr[2][i], incr[3][i],
  775. incr[4][i], incr[5][i], incr[6][i], incr[7][i]);
  776. seq_printf(seq, "%8u %4u %4u %4u %4u %4u %4u %4u %5u %s\n",
  777. incr[8][i], incr[9][i], incr[10][i], incr[11][i],
  778. incr[12][i], incr[13][i], incr[14][i], incr[15][i],
  779. adap->params.a_wnd[i],
  780. dec_fac[adap->params.b_wnd[i]]);
  781. }
  782. kfree(incr);
  783. return 0;
  784. }
  785. DEFINE_SHOW_ATTRIBUTE(cctrl_tbl);
  786. /* Format a value in a unit that differs from the value's native unit by the
  787. * given factor.
  788. */
  789. static char *unit_conv(char *buf, size_t len, unsigned int val,
  790. unsigned int factor)
  791. {
  792. unsigned int rem = val % factor;
  793. if (rem == 0) {
  794. snprintf(buf, len, "%u", val / factor);
  795. } else {
  796. while (rem % 10 == 0)
  797. rem /= 10;
  798. snprintf(buf, len, "%u.%u", val / factor, rem);
  799. }
  800. return buf;
  801. }
  802. static int clk_show(struct seq_file *seq, void *v)
  803. {
  804. char buf[32];
  805. struct adapter *adap = seq->private;
  806. unsigned int cclk_ps = 1000000000 / adap->params.vpd.cclk; /* in ps */
  807. u32 res = t4_read_reg(adap, TP_TIMER_RESOLUTION_A);
  808. unsigned int tre = TIMERRESOLUTION_G(res);
  809. unsigned int dack_re = DELAYEDACKRESOLUTION_G(res);
  810. unsigned long long tp_tick_us = (cclk_ps << tre) / 1000000; /* in us */
  811. seq_printf(seq, "Core clock period: %s ns\n",
  812. unit_conv(buf, sizeof(buf), cclk_ps, 1000));
  813. seq_printf(seq, "TP timer tick: %s us\n",
  814. unit_conv(buf, sizeof(buf), (cclk_ps << tre), 1000000));
  815. seq_printf(seq, "TCP timestamp tick: %s us\n",
  816. unit_conv(buf, sizeof(buf),
  817. (cclk_ps << TIMESTAMPRESOLUTION_G(res)), 1000000));
  818. seq_printf(seq, "DACK tick: %s us\n",
  819. unit_conv(buf, sizeof(buf), (cclk_ps << dack_re), 1000000));
  820. seq_printf(seq, "DACK timer: %u us\n",
  821. ((cclk_ps << dack_re) / 1000000) *
  822. t4_read_reg(adap, TP_DACK_TIMER_A));
  823. seq_printf(seq, "Retransmit min: %llu us\n",
  824. tp_tick_us * t4_read_reg(adap, TP_RXT_MIN_A));
  825. seq_printf(seq, "Retransmit max: %llu us\n",
  826. tp_tick_us * t4_read_reg(adap, TP_RXT_MAX_A));
  827. seq_printf(seq, "Persist timer min: %llu us\n",
  828. tp_tick_us * t4_read_reg(adap, TP_PERS_MIN_A));
  829. seq_printf(seq, "Persist timer max: %llu us\n",
  830. tp_tick_us * t4_read_reg(adap, TP_PERS_MAX_A));
  831. seq_printf(seq, "Keepalive idle timer: %llu us\n",
  832. tp_tick_us * t4_read_reg(adap, TP_KEEP_IDLE_A));
  833. seq_printf(seq, "Keepalive interval: %llu us\n",
  834. tp_tick_us * t4_read_reg(adap, TP_KEEP_INTVL_A));
  835. seq_printf(seq, "Initial SRTT: %llu us\n",
  836. tp_tick_us * INITSRTT_G(t4_read_reg(adap, TP_INIT_SRTT_A)));
  837. seq_printf(seq, "FINWAIT2 timer: %llu us\n",
  838. tp_tick_us * t4_read_reg(adap, TP_FINWAIT2_TIMER_A));
  839. return 0;
  840. }
  841. DEFINE_SHOW_ATTRIBUTE(clk);
  842. /* Firmware Device Log dump. */
  843. static const char * const devlog_level_strings[] = {
  844. [FW_DEVLOG_LEVEL_EMERG] = "EMERG",
  845. [FW_DEVLOG_LEVEL_CRIT] = "CRIT",
  846. [FW_DEVLOG_LEVEL_ERR] = "ERR",
  847. [FW_DEVLOG_LEVEL_NOTICE] = "NOTICE",
  848. [FW_DEVLOG_LEVEL_INFO] = "INFO",
  849. [FW_DEVLOG_LEVEL_DEBUG] = "DEBUG"
  850. };
  851. static const char * const devlog_facility_strings[] = {
  852. [FW_DEVLOG_FACILITY_CORE] = "CORE",
  853. [FW_DEVLOG_FACILITY_CF] = "CF",
  854. [FW_DEVLOG_FACILITY_SCHED] = "SCHED",
  855. [FW_DEVLOG_FACILITY_TIMER] = "TIMER",
  856. [FW_DEVLOG_FACILITY_RES] = "RES",
  857. [FW_DEVLOG_FACILITY_HW] = "HW",
  858. [FW_DEVLOG_FACILITY_FLR] = "FLR",
  859. [FW_DEVLOG_FACILITY_DMAQ] = "DMAQ",
  860. [FW_DEVLOG_FACILITY_PHY] = "PHY",
  861. [FW_DEVLOG_FACILITY_MAC] = "MAC",
  862. [FW_DEVLOG_FACILITY_PORT] = "PORT",
  863. [FW_DEVLOG_FACILITY_VI] = "VI",
  864. [FW_DEVLOG_FACILITY_FILTER] = "FILTER",
  865. [FW_DEVLOG_FACILITY_ACL] = "ACL",
  866. [FW_DEVLOG_FACILITY_TM] = "TM",
  867. [FW_DEVLOG_FACILITY_QFC] = "QFC",
  868. [FW_DEVLOG_FACILITY_DCB] = "DCB",
  869. [FW_DEVLOG_FACILITY_ETH] = "ETH",
  870. [FW_DEVLOG_FACILITY_OFLD] = "OFLD",
  871. [FW_DEVLOG_FACILITY_RI] = "RI",
  872. [FW_DEVLOG_FACILITY_ISCSI] = "ISCSI",
  873. [FW_DEVLOG_FACILITY_FCOE] = "FCOE",
  874. [FW_DEVLOG_FACILITY_FOISCSI] = "FOISCSI",
  875. [FW_DEVLOG_FACILITY_FOFCOE] = "FOFCOE"
  876. };
  877. /* Information gathered by Device Log Open routine for the display routine.
  878. */
  879. struct devlog_info {
  880. unsigned int nentries; /* number of entries in log[] */
  881. unsigned int first; /* first [temporal] entry in log[] */
  882. struct fw_devlog_e log[]; /* Firmware Device Log */
  883. };
  884. /* Dump a Firmaware Device Log entry.
  885. */
  886. static int devlog_show(struct seq_file *seq, void *v)
  887. {
  888. if (v == SEQ_START_TOKEN)
  889. seq_printf(seq, "%10s %15s %8s %8s %s\n",
  890. "Seq#", "Tstamp", "Level", "Facility", "Message");
  891. else {
  892. struct devlog_info *dinfo = seq->private;
  893. int fidx = (uintptr_t)v - 2;
  894. unsigned long index;
  895. struct fw_devlog_e *e;
  896. /* Get a pointer to the log entry to display. Skip unused log
  897. * entries.
  898. */
  899. index = dinfo->first + fidx;
  900. if (index >= dinfo->nentries)
  901. index -= dinfo->nentries;
  902. e = &dinfo->log[index];
  903. if (e->timestamp == 0)
  904. return 0;
  905. /* Print the message. This depends on the firmware using
  906. * exactly the same formating strings as the kernel so we may
  907. * eventually have to put a format interpreter in here ...
  908. */
  909. seq_printf(seq, "%10d %15llu %8s %8s ",
  910. be32_to_cpu(e->seqno),
  911. be64_to_cpu(e->timestamp),
  912. (e->level < ARRAY_SIZE(devlog_level_strings)
  913. ? devlog_level_strings[e->level]
  914. : "UNKNOWN"),
  915. (e->facility < ARRAY_SIZE(devlog_facility_strings)
  916. ? devlog_facility_strings[e->facility]
  917. : "UNKNOWN"));
  918. seq_printf(seq, e->fmt,
  919. be32_to_cpu(e->params[0]),
  920. be32_to_cpu(e->params[1]),
  921. be32_to_cpu(e->params[2]),
  922. be32_to_cpu(e->params[3]),
  923. be32_to_cpu(e->params[4]),
  924. be32_to_cpu(e->params[5]),
  925. be32_to_cpu(e->params[6]),
  926. be32_to_cpu(e->params[7]));
  927. }
  928. return 0;
  929. }
  930. /* Sequential File Operations for Device Log.
  931. */
  932. static inline void *devlog_get_idx(struct devlog_info *dinfo, loff_t pos)
  933. {
  934. if (pos > dinfo->nentries)
  935. return NULL;
  936. return (void *)(uintptr_t)(pos + 1);
  937. }
  938. static void *devlog_start(struct seq_file *seq, loff_t *pos)
  939. {
  940. struct devlog_info *dinfo = seq->private;
  941. return (*pos
  942. ? devlog_get_idx(dinfo, *pos)
  943. : SEQ_START_TOKEN);
  944. }
  945. static void *devlog_next(struct seq_file *seq, void *v, loff_t *pos)
  946. {
  947. struct devlog_info *dinfo = seq->private;
  948. (*pos)++;
  949. return devlog_get_idx(dinfo, *pos);
  950. }
  951. static void devlog_stop(struct seq_file *seq, void *v)
  952. {
  953. }
  954. static const struct seq_operations devlog_seq_ops = {
  955. .start = devlog_start,
  956. .next = devlog_next,
  957. .stop = devlog_stop,
  958. .show = devlog_show
  959. };
  960. /* Set up for reading the firmware's device log. We read the entire log here
  961. * and then display it incrementally in devlog_show().
  962. */
  963. static int devlog_open(struct inode *inode, struct file *file)
  964. {
  965. struct adapter *adap = inode->i_private;
  966. struct devlog_params *dparams = &adap->params.devlog;
  967. struct devlog_info *dinfo;
  968. unsigned int index;
  969. u32 fseqno;
  970. int ret;
  971. /* If we don't know where the log is we can't do anything.
  972. */
  973. if (dparams->start == 0)
  974. return -ENXIO;
  975. /* Allocate the space to read in the firmware's device log and set up
  976. * for the iterated call to our display function.
  977. */
  978. dinfo = __seq_open_private(file, &devlog_seq_ops,
  979. sizeof(*dinfo) + dparams->size);
  980. if (!dinfo)
  981. return -ENOMEM;
  982. /* Record the basic log buffer information and read in the raw log.
  983. */
  984. dinfo->nentries = (dparams->size / sizeof(struct fw_devlog_e));
  985. dinfo->first = 0;
  986. spin_lock(&adap->win0_lock);
  987. ret = t4_memory_rw(adap, adap->params.drv_memwin, dparams->memtype,
  988. dparams->start, dparams->size, (__be32 *)dinfo->log,
  989. T4_MEMORY_READ);
  990. spin_unlock(&adap->win0_lock);
  991. if (ret) {
  992. seq_release_private(inode, file);
  993. return ret;
  994. }
  995. /* Find the earliest (lowest Sequence Number) log entry in the
  996. * circular Device Log.
  997. */
  998. for (fseqno = ~((u32)0), index = 0; index < dinfo->nentries; index++) {
  999. struct fw_devlog_e *e = &dinfo->log[index];
  1000. __u32 seqno;
  1001. if (e->timestamp == 0)
  1002. continue;
  1003. seqno = be32_to_cpu(e->seqno);
  1004. if (seqno < fseqno) {
  1005. fseqno = seqno;
  1006. dinfo->first = index;
  1007. }
  1008. }
  1009. return 0;
  1010. }
  1011. static const struct file_operations devlog_fops = {
  1012. .owner = THIS_MODULE,
  1013. .open = devlog_open,
  1014. .read = seq_read,
  1015. .llseek = seq_lseek,
  1016. .release = seq_release_private
  1017. };
  1018. /* Show Firmware Mailbox Command/Reply Log
  1019. *
  1020. * Note that we don't do any locking when dumping the Firmware Mailbox Log so
  1021. * it's possible that we can catch things during a log update and therefore
  1022. * see partially corrupted log entries. But it's probably Good Enough(tm).
  1023. * If we ever decide that we want to make sure that we're dumping a coherent
  1024. * log, we'd need to perform locking in the mailbox logging and in
  1025. * mboxlog_open() where we'd need to grab the entire mailbox log in one go
  1026. * like we do for the Firmware Device Log.
  1027. */
  1028. static int mboxlog_show(struct seq_file *seq, void *v)
  1029. {
  1030. struct adapter *adapter = seq->private;
  1031. struct mbox_cmd_log *log = adapter->mbox_log;
  1032. struct mbox_cmd *entry;
  1033. int entry_idx, i;
  1034. if (v == SEQ_START_TOKEN) {
  1035. seq_printf(seq,
  1036. "%10s %15s %5s %5s %s\n",
  1037. "Seq#", "Tstamp", "Atime", "Etime",
  1038. "Command/Reply");
  1039. return 0;
  1040. }
  1041. entry_idx = log->cursor + ((uintptr_t)v - 2);
  1042. if (entry_idx >= log->size)
  1043. entry_idx -= log->size;
  1044. entry = mbox_cmd_log_entry(log, entry_idx);
  1045. /* skip over unused entries */
  1046. if (entry->timestamp == 0)
  1047. return 0;
  1048. seq_printf(seq, "%10u %15llu %5d %5d",
  1049. entry->seqno, entry->timestamp,
  1050. entry->access, entry->execute);
  1051. for (i = 0; i < MBOX_LEN / 8; i++) {
  1052. u64 flit = entry->cmd[i];
  1053. u32 hi = (u32)(flit >> 32);
  1054. u32 lo = (u32)flit;
  1055. seq_printf(seq, " %08x %08x", hi, lo);
  1056. }
  1057. seq_puts(seq, "\n");
  1058. return 0;
  1059. }
  1060. static inline void *mboxlog_get_idx(struct seq_file *seq, loff_t pos)
  1061. {
  1062. struct adapter *adapter = seq->private;
  1063. struct mbox_cmd_log *log = adapter->mbox_log;
  1064. return ((pos <= log->size) ? (void *)(uintptr_t)(pos + 1) : NULL);
  1065. }
  1066. static void *mboxlog_start(struct seq_file *seq, loff_t *pos)
  1067. {
  1068. return *pos ? mboxlog_get_idx(seq, *pos) : SEQ_START_TOKEN;
  1069. }
  1070. static void *mboxlog_next(struct seq_file *seq, void *v, loff_t *pos)
  1071. {
  1072. ++*pos;
  1073. return mboxlog_get_idx(seq, *pos);
  1074. }
  1075. static void mboxlog_stop(struct seq_file *seq, void *v)
  1076. {
  1077. }
  1078. static const struct seq_operations mboxlog_seq_ops = {
  1079. .start = mboxlog_start,
  1080. .next = mboxlog_next,
  1081. .stop = mboxlog_stop,
  1082. .show = mboxlog_show
  1083. };
  1084. static int mboxlog_open(struct inode *inode, struct file *file)
  1085. {
  1086. int res = seq_open(file, &mboxlog_seq_ops);
  1087. if (!res) {
  1088. struct seq_file *seq = file->private_data;
  1089. seq->private = inode->i_private;
  1090. }
  1091. return res;
  1092. }
  1093. static const struct file_operations mboxlog_fops = {
  1094. .owner = THIS_MODULE,
  1095. .open = mboxlog_open,
  1096. .read = seq_read,
  1097. .llseek = seq_lseek,
  1098. .release = seq_release,
  1099. };
  1100. static int mbox_show(struct seq_file *seq, void *v)
  1101. {
  1102. static const char * const owner[] = { "none", "FW", "driver",
  1103. "unknown", "<unread>" };
  1104. int i;
  1105. unsigned int mbox = (uintptr_t)seq->private & 7;
  1106. struct adapter *adap = seq->private - mbox;
  1107. void __iomem *addr = adap->regs + PF_REG(mbox, CIM_PF_MAILBOX_DATA_A);
  1108. /* For T4 we don't have a shadow copy of the Mailbox Control register.
  1109. * And since reading that real register causes a side effect of
  1110. * granting ownership, we're best of simply not reading it at all.
  1111. */
  1112. if (is_t4(adap->params.chip)) {
  1113. i = 4; /* index of "<unread>" */
  1114. } else {
  1115. unsigned int ctrl_reg = CIM_PF_MAILBOX_CTRL_SHADOW_COPY_A;
  1116. void __iomem *ctrl = adap->regs + PF_REG(mbox, ctrl_reg);
  1117. i = MBOWNER_G(readl(ctrl));
  1118. }
  1119. seq_printf(seq, "mailbox owned by %s\n\n", owner[i]);
  1120. for (i = 0; i < MBOX_LEN; i += 8)
  1121. seq_printf(seq, "%016llx\n",
  1122. (unsigned long long)readq(addr + i));
  1123. return 0;
  1124. }
  1125. static int mbox_open(struct inode *inode, struct file *file)
  1126. {
  1127. return single_open(file, mbox_show, inode->i_private);
  1128. }
  1129. static ssize_t mbox_write(struct file *file, const char __user *buf,
  1130. size_t count, loff_t *pos)
  1131. {
  1132. int i;
  1133. char c = '\n', s[256];
  1134. unsigned long long data[8];
  1135. const struct inode *ino;
  1136. unsigned int mbox;
  1137. struct adapter *adap;
  1138. void __iomem *addr;
  1139. void __iomem *ctrl;
  1140. if (count > sizeof(s) - 1 || !count)
  1141. return -EINVAL;
  1142. if (copy_from_user(s, buf, count))
  1143. return -EFAULT;
  1144. s[count] = '\0';
  1145. if (sscanf(s, "%llx %llx %llx %llx %llx %llx %llx %llx%c", &data[0],
  1146. &data[1], &data[2], &data[3], &data[4], &data[5], &data[6],
  1147. &data[7], &c) < 8 || c != '\n')
  1148. return -EINVAL;
  1149. ino = file_inode(file);
  1150. mbox = (uintptr_t)ino->i_private & 7;
  1151. adap = ino->i_private - mbox;
  1152. addr = adap->regs + PF_REG(mbox, CIM_PF_MAILBOX_DATA_A);
  1153. ctrl = addr + MBOX_LEN;
  1154. if (MBOWNER_G(readl(ctrl)) != X_MBOWNER_PL)
  1155. return -EBUSY;
  1156. for (i = 0; i < 8; i++)
  1157. writeq(data[i], addr + 8 * i);
  1158. writel(MBMSGVALID_F | MBOWNER_V(X_MBOWNER_FW), ctrl);
  1159. return count;
  1160. }
  1161. static const struct file_operations mbox_debugfs_fops = {
  1162. .owner = THIS_MODULE,
  1163. .open = mbox_open,
  1164. .read = seq_read,
  1165. .llseek = seq_lseek,
  1166. .release = single_release,
  1167. .write = mbox_write
  1168. };
  1169. static int mps_trc_show(struct seq_file *seq, void *v)
  1170. {
  1171. int enabled, i;
  1172. struct trace_params tp;
  1173. unsigned int trcidx = (uintptr_t)seq->private & 3;
  1174. struct adapter *adap = seq->private - trcidx;
  1175. t4_get_trace_filter(adap, &tp, trcidx, &enabled);
  1176. if (!enabled) {
  1177. seq_puts(seq, "tracer is disabled\n");
  1178. return 0;
  1179. }
  1180. if (tp.skip_ofst * 8 >= TRACE_LEN) {
  1181. dev_err(adap->pdev_dev, "illegal trace pattern skip offset\n");
  1182. return -EINVAL;
  1183. }
  1184. if (tp.port < 8) {
  1185. i = adap->chan_map[tp.port & 3];
  1186. if (i >= MAX_NPORTS) {
  1187. dev_err(adap->pdev_dev, "tracer %u is assigned "
  1188. "to non-existing port\n", trcidx);
  1189. return -EINVAL;
  1190. }
  1191. seq_printf(seq, "tracer is capturing %s %s, ",
  1192. adap->port[i]->name, tp.port < 4 ? "Rx" : "Tx");
  1193. } else
  1194. seq_printf(seq, "tracer is capturing loopback %d, ",
  1195. tp.port - 8);
  1196. seq_printf(seq, "snap length: %u, min length: %u\n", tp.snap_len,
  1197. tp.min_len);
  1198. seq_printf(seq, "packets captured %smatch filter\n",
  1199. tp.invert ? "do not " : "");
  1200. if (tp.skip_ofst) {
  1201. seq_puts(seq, "filter pattern: ");
  1202. for (i = 0; i < tp.skip_ofst * 2; i += 2)
  1203. seq_printf(seq, "%08x%08x", tp.data[i], tp.data[i + 1]);
  1204. seq_putc(seq, '/');
  1205. for (i = 0; i < tp.skip_ofst * 2; i += 2)
  1206. seq_printf(seq, "%08x%08x", tp.mask[i], tp.mask[i + 1]);
  1207. seq_puts(seq, "@0\n");
  1208. }
  1209. seq_puts(seq, "filter pattern: ");
  1210. for (i = tp.skip_ofst * 2; i < TRACE_LEN / 4; i += 2)
  1211. seq_printf(seq, "%08x%08x", tp.data[i], tp.data[i + 1]);
  1212. seq_putc(seq, '/');
  1213. for (i = tp.skip_ofst * 2; i < TRACE_LEN / 4; i += 2)
  1214. seq_printf(seq, "%08x%08x", tp.mask[i], tp.mask[i + 1]);
  1215. seq_printf(seq, "@%u\n", (tp.skip_ofst + tp.skip_len) * 8);
  1216. return 0;
  1217. }
  1218. static int mps_trc_open(struct inode *inode, struct file *file)
  1219. {
  1220. return single_open(file, mps_trc_show, inode->i_private);
  1221. }
  1222. static unsigned int xdigit2int(unsigned char c)
  1223. {
  1224. return isdigit(c) ? c - '0' : tolower(c) - 'a' + 10;
  1225. }
  1226. #define TRC_PORT_NONE 0xff
  1227. #define TRC_RSS_ENABLE 0x33
  1228. #define TRC_RSS_DISABLE 0x13
  1229. /* Set an MPS trace filter. Syntax is:
  1230. *
  1231. * disable
  1232. *
  1233. * to disable tracing, or
  1234. *
  1235. * interface qid=<qid no> [snaplen=<val>] [minlen=<val>] [not] [<pattern>]...
  1236. *
  1237. * where interface is one of rxN, txN, or loopbackN, N = 0..3, qid can be one
  1238. * of the NIC's response qid obtained from sge_qinfo and pattern has the form
  1239. *
  1240. * <pattern data>[/<pattern mask>][@<anchor>]
  1241. *
  1242. * Up to 2 filter patterns can be specified. If 2 are supplied the first one
  1243. * must be anchored at 0. An omitted mask is taken as a mask of 1s, an omitted
  1244. * anchor is taken as 0.
  1245. */
  1246. static ssize_t mps_trc_write(struct file *file, const char __user *buf,
  1247. size_t count, loff_t *pos)
  1248. {
  1249. int i, enable, ret;
  1250. u32 *data, *mask;
  1251. struct trace_params tp;
  1252. const struct inode *ino;
  1253. unsigned int trcidx;
  1254. char *s, *p, *word, *end;
  1255. struct adapter *adap;
  1256. u32 j;
  1257. ino = file_inode(file);
  1258. trcidx = (uintptr_t)ino->i_private & 3;
  1259. adap = ino->i_private - trcidx;
  1260. /* Don't accept input more than 1K, can't be anything valid except lots
  1261. * of whitespace. Well, use less.
  1262. */
  1263. if (count > 1024)
  1264. return -EFBIG;
  1265. p = s = kzalloc(count + 1, GFP_USER);
  1266. if (!s)
  1267. return -ENOMEM;
  1268. if (copy_from_user(s, buf, count)) {
  1269. count = -EFAULT;
  1270. goto out;
  1271. }
  1272. if (s[count - 1] == '\n')
  1273. s[count - 1] = '\0';
  1274. enable = strcmp("disable", s) != 0;
  1275. if (!enable)
  1276. goto apply;
  1277. /* enable or disable trace multi rss filter */
  1278. if (adap->trace_rss)
  1279. t4_write_reg(adap, MPS_TRC_CFG_A, TRC_RSS_ENABLE);
  1280. else
  1281. t4_write_reg(adap, MPS_TRC_CFG_A, TRC_RSS_DISABLE);
  1282. memset(&tp, 0, sizeof(tp));
  1283. tp.port = TRC_PORT_NONE;
  1284. i = 0; /* counts pattern nibbles */
  1285. while (p) {
  1286. while (isspace(*p))
  1287. p++;
  1288. word = strsep(&p, " ");
  1289. if (!*word)
  1290. break;
  1291. if (!strncmp(word, "qid=", 4)) {
  1292. end = (char *)word + 4;
  1293. ret = kstrtouint(end, 10, &j);
  1294. if (ret)
  1295. goto out;
  1296. if (!adap->trace_rss) {
  1297. t4_write_reg(adap, MPS_T5_TRC_RSS_CONTROL_A, j);
  1298. continue;
  1299. }
  1300. switch (trcidx) {
  1301. case 0:
  1302. t4_write_reg(adap, MPS_TRC_RSS_CONTROL_A, j);
  1303. break;
  1304. case 1:
  1305. t4_write_reg(adap,
  1306. MPS_TRC_FILTER1_RSS_CONTROL_A, j);
  1307. break;
  1308. case 2:
  1309. t4_write_reg(adap,
  1310. MPS_TRC_FILTER2_RSS_CONTROL_A, j);
  1311. break;
  1312. case 3:
  1313. t4_write_reg(adap,
  1314. MPS_TRC_FILTER3_RSS_CONTROL_A, j);
  1315. break;
  1316. }
  1317. continue;
  1318. }
  1319. if (!strncmp(word, "snaplen=", 8)) {
  1320. end = (char *)word + 8;
  1321. ret = kstrtouint(end, 10, &j);
  1322. if (ret || j > 9600) {
  1323. inval: count = -EINVAL;
  1324. goto out;
  1325. }
  1326. tp.snap_len = j;
  1327. continue;
  1328. }
  1329. if (!strncmp(word, "minlen=", 7)) {
  1330. end = (char *)word + 7;
  1331. ret = kstrtouint(end, 10, &j);
  1332. if (ret || j > TFMINPKTSIZE_M)
  1333. goto inval;
  1334. tp.min_len = j;
  1335. continue;
  1336. }
  1337. if (!strcmp(word, "not")) {
  1338. tp.invert = !tp.invert;
  1339. continue;
  1340. }
  1341. if (!strncmp(word, "loopback", 8) && tp.port == TRC_PORT_NONE) {
  1342. if (word[8] < '0' || word[8] > '3' || word[9])
  1343. goto inval;
  1344. tp.port = word[8] - '0' + 8;
  1345. continue;
  1346. }
  1347. if (!strncmp(word, "tx", 2) && tp.port == TRC_PORT_NONE) {
  1348. if (word[2] < '0' || word[2] > '3' || word[3])
  1349. goto inval;
  1350. tp.port = word[2] - '0' + 4;
  1351. if (adap->chan_map[tp.port & 3] >= MAX_NPORTS)
  1352. goto inval;
  1353. continue;
  1354. }
  1355. if (!strncmp(word, "rx", 2) && tp.port == TRC_PORT_NONE) {
  1356. if (word[2] < '0' || word[2] > '3' || word[3])
  1357. goto inval;
  1358. tp.port = word[2] - '0';
  1359. if (adap->chan_map[tp.port] >= MAX_NPORTS)
  1360. goto inval;
  1361. continue;
  1362. }
  1363. if (!isxdigit(*word))
  1364. goto inval;
  1365. /* we have found a trace pattern */
  1366. if (i) { /* split pattern */
  1367. if (tp.skip_len) /* too many splits */
  1368. goto inval;
  1369. tp.skip_ofst = i / 16;
  1370. }
  1371. data = &tp.data[i / 8];
  1372. mask = &tp.mask[i / 8];
  1373. j = i;
  1374. while (isxdigit(*word)) {
  1375. if (i >= TRACE_LEN * 2) {
  1376. count = -EFBIG;
  1377. goto out;
  1378. }
  1379. *data = (*data << 4) + xdigit2int(*word++);
  1380. if (++i % 8 == 0)
  1381. data++;
  1382. }
  1383. if (*word == '/') {
  1384. word++;
  1385. while (isxdigit(*word)) {
  1386. if (j >= i) /* mask longer than data */
  1387. goto inval;
  1388. *mask = (*mask << 4) + xdigit2int(*word++);
  1389. if (++j % 8 == 0)
  1390. mask++;
  1391. }
  1392. if (i != j) /* mask shorter than data */
  1393. goto inval;
  1394. } else { /* no mask, use all 1s */
  1395. for ( ; i - j >= 8; j += 8)
  1396. *mask++ = 0xffffffff;
  1397. if (i % 8)
  1398. *mask = (1 << (i % 8) * 4) - 1;
  1399. }
  1400. if (*word == '@') {
  1401. end = (char *)word + 1;
  1402. ret = kstrtouint(end, 10, &j);
  1403. if (*end && *end != '\n')
  1404. goto inval;
  1405. if (j & 7) /* doesn't start at multiple of 8 */
  1406. goto inval;
  1407. j /= 8;
  1408. if (j < tp.skip_ofst) /* overlaps earlier pattern */
  1409. goto inval;
  1410. if (j - tp.skip_ofst > 31) /* skip too big */
  1411. goto inval;
  1412. tp.skip_len = j - tp.skip_ofst;
  1413. }
  1414. if (i % 8) {
  1415. *data <<= (8 - i % 8) * 4;
  1416. *mask <<= (8 - i % 8) * 4;
  1417. i = (i + 15) & ~15; /* 8-byte align */
  1418. }
  1419. }
  1420. if (tp.port == TRC_PORT_NONE)
  1421. goto inval;
  1422. apply:
  1423. i = t4_set_trace_filter(adap, &tp, trcidx, enable);
  1424. if (i)
  1425. count = i;
  1426. out:
  1427. kfree(s);
  1428. return count;
  1429. }
  1430. static const struct file_operations mps_trc_debugfs_fops = {
  1431. .owner = THIS_MODULE,
  1432. .open = mps_trc_open,
  1433. .read = seq_read,
  1434. .llseek = seq_lseek,
  1435. .release = single_release,
  1436. .write = mps_trc_write
  1437. };
  1438. static ssize_t flash_read(struct file *file, char __user *buf, size_t count,
  1439. loff_t *ppos)
  1440. {
  1441. loff_t pos = *ppos;
  1442. loff_t avail = file_inode(file)->i_size;
  1443. struct adapter *adap = file->private_data;
  1444. if (pos < 0)
  1445. return -EINVAL;
  1446. if (pos >= avail)
  1447. return 0;
  1448. if (count > avail - pos)
  1449. count = avail - pos;
  1450. while (count) {
  1451. size_t len;
  1452. int ret, ofst;
  1453. u8 data[256];
  1454. ofst = pos & 3;
  1455. len = min(count + ofst, sizeof(data));
  1456. ret = t4_read_flash(adap, pos - ofst, (len + 3) / 4,
  1457. (u32 *)data, 1);
  1458. if (ret)
  1459. return ret;
  1460. len -= ofst;
  1461. if (copy_to_user(buf, data + ofst, len))
  1462. return -EFAULT;
  1463. buf += len;
  1464. pos += len;
  1465. count -= len;
  1466. }
  1467. count = pos - *ppos;
  1468. *ppos = pos;
  1469. return count;
  1470. }
  1471. static const struct file_operations flash_debugfs_fops = {
  1472. .owner = THIS_MODULE,
  1473. .open = mem_open,
  1474. .read = flash_read,
  1475. .llseek = default_llseek,
  1476. };
  1477. static inline void tcamxy2valmask(u64 x, u64 y, u8 *addr, u64 *mask)
  1478. {
  1479. *mask = x | y;
  1480. y = (__force u64)cpu_to_be64(y);
  1481. memcpy(addr, (char *)&y + 2, ETH_ALEN);
  1482. }
  1483. static int mps_tcam_show(struct seq_file *seq, void *v)
  1484. {
  1485. struct adapter *adap = seq->private;
  1486. unsigned int chip_ver = CHELSIO_CHIP_VERSION(adap->params.chip);
  1487. if (v == SEQ_START_TOKEN) {
  1488. if (chip_ver > CHELSIO_T5) {
  1489. seq_puts(seq, "Idx Ethernet address Mask "
  1490. " VNI Mask IVLAN Vld "
  1491. "DIP_Hit Lookup Port "
  1492. "Vld Ports PF VF "
  1493. "Replication "
  1494. " P0 P1 P2 P3 ML\n");
  1495. } else {
  1496. if (adap->params.arch.mps_rplc_size > 128)
  1497. seq_puts(seq, "Idx Ethernet address Mask "
  1498. "Vld Ports PF VF "
  1499. "Replication "
  1500. " P0 P1 P2 P3 ML\n");
  1501. else
  1502. seq_puts(seq, "Idx Ethernet address Mask "
  1503. "Vld Ports PF VF Replication"
  1504. " P0 P1 P2 P3 ML\n");
  1505. }
  1506. } else {
  1507. u64 mask;
  1508. u8 addr[ETH_ALEN];
  1509. bool replicate, dip_hit = false, vlan_vld = false;
  1510. unsigned int idx = (uintptr_t)v - 2;
  1511. u64 tcamy, tcamx, val;
  1512. u32 cls_lo, cls_hi, ctl, data2, vnix = 0, vniy = 0;
  1513. u32 rplc[8] = {0};
  1514. u8 lookup_type = 0, port_num = 0;
  1515. u16 ivlan = 0;
  1516. if (chip_ver > CHELSIO_T5) {
  1517. /* CtlCmdType - 0: Read, 1: Write
  1518. * CtlTcamSel - 0: TCAM0, 1: TCAM1
  1519. * CtlXYBitSel- 0: Y bit, 1: X bit
  1520. */
  1521. /* Read tcamy */
  1522. ctl = CTLCMDTYPE_V(0) | CTLXYBITSEL_V(0);
  1523. if (idx < 256)
  1524. ctl |= CTLTCAMINDEX_V(idx) | CTLTCAMSEL_V(0);
  1525. else
  1526. ctl |= CTLTCAMINDEX_V(idx - 256) |
  1527. CTLTCAMSEL_V(1);
  1528. t4_write_reg(adap, MPS_CLS_TCAM_DATA2_CTL_A, ctl);
  1529. val = t4_read_reg(adap, MPS_CLS_TCAM_DATA1_A);
  1530. tcamy = DMACH_G(val) << 32;
  1531. tcamy |= t4_read_reg(adap, MPS_CLS_TCAM_DATA0_A);
  1532. data2 = t4_read_reg(adap, MPS_CLS_TCAM_DATA2_CTL_A);
  1533. lookup_type = DATALKPTYPE_G(data2);
  1534. /* 0 - Outer header, 1 - Inner header
  1535. * [71:48] bit locations are overloaded for
  1536. * outer vs. inner lookup types.
  1537. */
  1538. if (lookup_type && (lookup_type != DATALKPTYPE_M)) {
  1539. /* Inner header VNI */
  1540. vniy = (data2 & DATAVIDH2_F) |
  1541. (DATAVIDH1_G(data2) << 16) | VIDL_G(val);
  1542. dip_hit = data2 & DATADIPHIT_F;
  1543. } else {
  1544. vlan_vld = data2 & DATAVIDH2_F;
  1545. ivlan = VIDL_G(val);
  1546. }
  1547. port_num = DATAPORTNUM_G(data2);
  1548. /* Read tcamx. Change the control param */
  1549. vnix = 0;
  1550. ctl |= CTLXYBITSEL_V(1);
  1551. t4_write_reg(adap, MPS_CLS_TCAM_DATA2_CTL_A, ctl);
  1552. val = t4_read_reg(adap, MPS_CLS_TCAM_DATA1_A);
  1553. tcamx = DMACH_G(val) << 32;
  1554. tcamx |= t4_read_reg(adap, MPS_CLS_TCAM_DATA0_A);
  1555. data2 = t4_read_reg(adap, MPS_CLS_TCAM_DATA2_CTL_A);
  1556. if (lookup_type && (lookup_type != DATALKPTYPE_M)) {
  1557. /* Inner header VNI mask */
  1558. vnix = (data2 & DATAVIDH2_F) |
  1559. (DATAVIDH1_G(data2) << 16) | VIDL_G(val);
  1560. }
  1561. } else {
  1562. tcamy = t4_read_reg64(adap, MPS_CLS_TCAM_Y_L(idx));
  1563. tcamx = t4_read_reg64(adap, MPS_CLS_TCAM_X_L(idx));
  1564. }
  1565. cls_lo = t4_read_reg(adap, MPS_CLS_SRAM_L(idx));
  1566. cls_hi = t4_read_reg(adap, MPS_CLS_SRAM_H(idx));
  1567. if (tcamx & tcamy) {
  1568. seq_printf(seq, "%3u -\n", idx);
  1569. goto out;
  1570. }
  1571. rplc[0] = rplc[1] = rplc[2] = rplc[3] = 0;
  1572. if (chip_ver > CHELSIO_T5)
  1573. replicate = (cls_lo & T6_REPLICATE_F);
  1574. else
  1575. replicate = (cls_lo & REPLICATE_F);
  1576. if (replicate) {
  1577. struct fw_ldst_cmd ldst_cmd;
  1578. int ret;
  1579. struct fw_ldst_mps_rplc mps_rplc;
  1580. u32 ldst_addrspc;
  1581. memset(&ldst_cmd, 0, sizeof(ldst_cmd));
  1582. ldst_addrspc =
  1583. FW_LDST_CMD_ADDRSPACE_V(FW_LDST_ADDRSPC_MPS);
  1584. ldst_cmd.op_to_addrspace =
  1585. htonl(FW_CMD_OP_V(FW_LDST_CMD) |
  1586. FW_CMD_REQUEST_F |
  1587. FW_CMD_READ_F |
  1588. ldst_addrspc);
  1589. ldst_cmd.cycles_to_len16 = htonl(FW_LEN16(ldst_cmd));
  1590. ldst_cmd.u.mps.rplc.fid_idx =
  1591. htons(FW_LDST_CMD_FID_V(FW_LDST_MPS_RPLC) |
  1592. FW_LDST_CMD_IDX_V(idx));
  1593. ret = t4_wr_mbox(adap, adap->mbox, &ldst_cmd,
  1594. sizeof(ldst_cmd), &ldst_cmd);
  1595. if (ret)
  1596. dev_warn(adap->pdev_dev, "Can't read MPS "
  1597. "replication map for idx %d: %d\n",
  1598. idx, -ret);
  1599. else {
  1600. mps_rplc = ldst_cmd.u.mps.rplc;
  1601. rplc[0] = ntohl(mps_rplc.rplc31_0);
  1602. rplc[1] = ntohl(mps_rplc.rplc63_32);
  1603. rplc[2] = ntohl(mps_rplc.rplc95_64);
  1604. rplc[3] = ntohl(mps_rplc.rplc127_96);
  1605. if (adap->params.arch.mps_rplc_size > 128) {
  1606. rplc[4] = ntohl(mps_rplc.rplc159_128);
  1607. rplc[5] = ntohl(mps_rplc.rplc191_160);
  1608. rplc[6] = ntohl(mps_rplc.rplc223_192);
  1609. rplc[7] = ntohl(mps_rplc.rplc255_224);
  1610. }
  1611. }
  1612. }
  1613. tcamxy2valmask(tcamx, tcamy, addr, &mask);
  1614. if (chip_ver > CHELSIO_T5) {
  1615. /* Inner header lookup */
  1616. if (lookup_type && (lookup_type != DATALKPTYPE_M)) {
  1617. seq_printf(seq,
  1618. "%3u %02x:%02x:%02x:%02x:%02x:%02x "
  1619. "%012llx %06x %06x - - %3c"
  1620. " 'I' %4x "
  1621. "%3c %#x%4u%4d", idx, addr[0],
  1622. addr[1], addr[2], addr[3],
  1623. addr[4], addr[5],
  1624. (unsigned long long)mask,
  1625. vniy, (vnix | vniy),
  1626. dip_hit ? 'Y' : 'N',
  1627. port_num,
  1628. (cls_lo & T6_SRAM_VLD_F) ? 'Y' : 'N',
  1629. PORTMAP_G(cls_hi),
  1630. T6_PF_G(cls_lo),
  1631. (cls_lo & T6_VF_VALID_F) ?
  1632. T6_VF_G(cls_lo) : -1);
  1633. } else {
  1634. seq_printf(seq,
  1635. "%3u %02x:%02x:%02x:%02x:%02x:%02x "
  1636. "%012llx - - ",
  1637. idx, addr[0], addr[1], addr[2],
  1638. addr[3], addr[4], addr[5],
  1639. (unsigned long long)mask);
  1640. if (vlan_vld)
  1641. seq_printf(seq, "%4u Y ", ivlan);
  1642. else
  1643. seq_puts(seq, " - N ");
  1644. seq_printf(seq,
  1645. "- %3c %4x %3c %#x%4u%4d",
  1646. lookup_type ? 'I' : 'O', port_num,
  1647. (cls_lo & T6_SRAM_VLD_F) ? 'Y' : 'N',
  1648. PORTMAP_G(cls_hi),
  1649. T6_PF_G(cls_lo),
  1650. (cls_lo & T6_VF_VALID_F) ?
  1651. T6_VF_G(cls_lo) : -1);
  1652. }
  1653. } else
  1654. seq_printf(seq, "%3u %02x:%02x:%02x:%02x:%02x:%02x "
  1655. "%012llx%3c %#x%4u%4d",
  1656. idx, addr[0], addr[1], addr[2], addr[3],
  1657. addr[4], addr[5], (unsigned long long)mask,
  1658. (cls_lo & SRAM_VLD_F) ? 'Y' : 'N',
  1659. PORTMAP_G(cls_hi),
  1660. PF_G(cls_lo),
  1661. (cls_lo & VF_VALID_F) ? VF_G(cls_lo) : -1);
  1662. if (replicate) {
  1663. if (adap->params.arch.mps_rplc_size > 128)
  1664. seq_printf(seq, " %08x %08x %08x %08x "
  1665. "%08x %08x %08x %08x",
  1666. rplc[7], rplc[6], rplc[5], rplc[4],
  1667. rplc[3], rplc[2], rplc[1], rplc[0]);
  1668. else
  1669. seq_printf(seq, " %08x %08x %08x %08x",
  1670. rplc[3], rplc[2], rplc[1], rplc[0]);
  1671. } else {
  1672. if (adap->params.arch.mps_rplc_size > 128)
  1673. seq_printf(seq, "%72c", ' ');
  1674. else
  1675. seq_printf(seq, "%36c", ' ');
  1676. }
  1677. if (chip_ver > CHELSIO_T5)
  1678. seq_printf(seq, "%4u%3u%3u%3u %#x\n",
  1679. T6_SRAM_PRIO0_G(cls_lo),
  1680. T6_SRAM_PRIO1_G(cls_lo),
  1681. T6_SRAM_PRIO2_G(cls_lo),
  1682. T6_SRAM_PRIO3_G(cls_lo),
  1683. (cls_lo >> T6_MULTILISTEN0_S) & 0xf);
  1684. else
  1685. seq_printf(seq, "%4u%3u%3u%3u %#x\n",
  1686. SRAM_PRIO0_G(cls_lo), SRAM_PRIO1_G(cls_lo),
  1687. SRAM_PRIO2_G(cls_lo), SRAM_PRIO3_G(cls_lo),
  1688. (cls_lo >> MULTILISTEN0_S) & 0xf);
  1689. }
  1690. out: return 0;
  1691. }
  1692. static inline void *mps_tcam_get_idx(struct seq_file *seq, loff_t pos)
  1693. {
  1694. struct adapter *adap = seq->private;
  1695. int max_mac_addr = is_t4(adap->params.chip) ?
  1696. NUM_MPS_CLS_SRAM_L_INSTANCES :
  1697. NUM_MPS_T5_CLS_SRAM_L_INSTANCES;
  1698. return ((pos <= max_mac_addr) ? (void *)(uintptr_t)(pos + 1) : NULL);
  1699. }
  1700. static void *mps_tcam_start(struct seq_file *seq, loff_t *pos)
  1701. {
  1702. return *pos ? mps_tcam_get_idx(seq, *pos) : SEQ_START_TOKEN;
  1703. }
  1704. static void *mps_tcam_next(struct seq_file *seq, void *v, loff_t *pos)
  1705. {
  1706. ++*pos;
  1707. return mps_tcam_get_idx(seq, *pos);
  1708. }
  1709. static void mps_tcam_stop(struct seq_file *seq, void *v)
  1710. {
  1711. }
  1712. static const struct seq_operations mps_tcam_seq_ops = {
  1713. .start = mps_tcam_start,
  1714. .next = mps_tcam_next,
  1715. .stop = mps_tcam_stop,
  1716. .show = mps_tcam_show
  1717. };
  1718. static int mps_tcam_open(struct inode *inode, struct file *file)
  1719. {
  1720. int res = seq_open(file, &mps_tcam_seq_ops);
  1721. if (!res) {
  1722. struct seq_file *seq = file->private_data;
  1723. seq->private = inode->i_private;
  1724. }
  1725. return res;
  1726. }
  1727. static const struct file_operations mps_tcam_debugfs_fops = {
  1728. .owner = THIS_MODULE,
  1729. .open = mps_tcam_open,
  1730. .read = seq_read,
  1731. .llseek = seq_lseek,
  1732. .release = seq_release,
  1733. };
  1734. /* Display various sensor information.
  1735. */
  1736. static int sensors_show(struct seq_file *seq, void *v)
  1737. {
  1738. struct adapter *adap = seq->private;
  1739. u32 param[7], val[7];
  1740. int ret;
  1741. /* Note that if the sensors haven't been initialized and turned on
  1742. * we'll get values of 0, so treat those as "<unknown>" ...
  1743. */
  1744. param[0] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  1745. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_DIAG) |
  1746. FW_PARAMS_PARAM_Y_V(FW_PARAM_DEV_DIAG_TMP));
  1747. param[1] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  1748. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_DIAG) |
  1749. FW_PARAMS_PARAM_Y_V(FW_PARAM_DEV_DIAG_VDD));
  1750. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2,
  1751. param, val);
  1752. if (ret < 0 || val[0] == 0)
  1753. seq_puts(seq, "Temperature: <unknown>\n");
  1754. else
  1755. seq_printf(seq, "Temperature: %dC\n", val[0]);
  1756. if (ret < 0 || val[1] == 0)
  1757. seq_puts(seq, "Core VDD: <unknown>\n");
  1758. else
  1759. seq_printf(seq, "Core VDD: %dmV\n", val[1]);
  1760. return 0;
  1761. }
  1762. DEFINE_SHOW_ATTRIBUTE(sensors);
  1763. #if IS_ENABLED(CONFIG_IPV6)
  1764. DEFINE_SHOW_ATTRIBUTE(clip_tbl);
  1765. #endif
  1766. /*RSS Table.
  1767. */
  1768. static int rss_show(struct seq_file *seq, void *v, int idx)
  1769. {
  1770. u16 *entry = v;
  1771. seq_printf(seq, "%4d: %4u %4u %4u %4u %4u %4u %4u %4u\n",
  1772. idx * 8, entry[0], entry[1], entry[2], entry[3], entry[4],
  1773. entry[5], entry[6], entry[7]);
  1774. return 0;
  1775. }
  1776. static int rss_open(struct inode *inode, struct file *file)
  1777. {
  1778. struct adapter *adap = inode->i_private;
  1779. int ret, nentries;
  1780. struct seq_tab *p;
  1781. nentries = t4_chip_rss_size(adap);
  1782. p = seq_open_tab(file, nentries / 8, 8 * sizeof(u16), 0, rss_show);
  1783. if (!p)
  1784. return -ENOMEM;
  1785. ret = t4_read_rss(adap, (u16 *)p->data);
  1786. if (ret)
  1787. seq_release_private(inode, file);
  1788. return ret;
  1789. }
  1790. static const struct file_operations rss_debugfs_fops = {
  1791. .owner = THIS_MODULE,
  1792. .open = rss_open,
  1793. .read = seq_read,
  1794. .llseek = seq_lseek,
  1795. .release = seq_release_private
  1796. };
  1797. /* RSS Configuration.
  1798. */
  1799. /* Small utility function to return the strings "yes" or "no" if the supplied
  1800. * argument is non-zero.
  1801. */
  1802. static const char *yesno(int x)
  1803. {
  1804. static const char *yes = "yes";
  1805. static const char *no = "no";
  1806. return x ? yes : no;
  1807. }
  1808. static int rss_config_show(struct seq_file *seq, void *v)
  1809. {
  1810. struct adapter *adapter = seq->private;
  1811. static const char * const keymode[] = {
  1812. "global",
  1813. "global and per-VF scramble",
  1814. "per-PF and per-VF scramble",
  1815. "per-VF and per-VF scramble",
  1816. };
  1817. u32 rssconf;
  1818. rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_A);
  1819. seq_printf(seq, "TP_RSS_CONFIG: %#x\n", rssconf);
  1820. seq_printf(seq, " Tnl4TupEnIpv6: %3s\n", yesno(rssconf &
  1821. TNL4TUPENIPV6_F));
  1822. seq_printf(seq, " Tnl2TupEnIpv6: %3s\n", yesno(rssconf &
  1823. TNL2TUPENIPV6_F));
  1824. seq_printf(seq, " Tnl4TupEnIpv4: %3s\n", yesno(rssconf &
  1825. TNL4TUPENIPV4_F));
  1826. seq_printf(seq, " Tnl2TupEnIpv4: %3s\n", yesno(rssconf &
  1827. TNL2TUPENIPV4_F));
  1828. seq_printf(seq, " TnlTcpSel: %3s\n", yesno(rssconf & TNLTCPSEL_F));
  1829. seq_printf(seq, " TnlIp6Sel: %3s\n", yesno(rssconf & TNLIP6SEL_F));
  1830. seq_printf(seq, " TnlVrtSel: %3s\n", yesno(rssconf & TNLVRTSEL_F));
  1831. seq_printf(seq, " TnlMapEn: %3s\n", yesno(rssconf & TNLMAPEN_F));
  1832. seq_printf(seq, " OfdHashSave: %3s\n", yesno(rssconf &
  1833. OFDHASHSAVE_F));
  1834. seq_printf(seq, " OfdVrtSel: %3s\n", yesno(rssconf & OFDVRTSEL_F));
  1835. seq_printf(seq, " OfdMapEn: %3s\n", yesno(rssconf & OFDMAPEN_F));
  1836. seq_printf(seq, " OfdLkpEn: %3s\n", yesno(rssconf & OFDLKPEN_F));
  1837. seq_printf(seq, " Syn4TupEnIpv6: %3s\n", yesno(rssconf &
  1838. SYN4TUPENIPV6_F));
  1839. seq_printf(seq, " Syn2TupEnIpv6: %3s\n", yesno(rssconf &
  1840. SYN2TUPENIPV6_F));
  1841. seq_printf(seq, " Syn4TupEnIpv4: %3s\n", yesno(rssconf &
  1842. SYN4TUPENIPV4_F));
  1843. seq_printf(seq, " Syn2TupEnIpv4: %3s\n", yesno(rssconf &
  1844. SYN2TUPENIPV4_F));
  1845. seq_printf(seq, " Syn4TupEnIpv6: %3s\n", yesno(rssconf &
  1846. SYN4TUPENIPV6_F));
  1847. seq_printf(seq, " SynIp6Sel: %3s\n", yesno(rssconf & SYNIP6SEL_F));
  1848. seq_printf(seq, " SynVrt6Sel: %3s\n", yesno(rssconf & SYNVRTSEL_F));
  1849. seq_printf(seq, " SynMapEn: %3s\n", yesno(rssconf & SYNMAPEN_F));
  1850. seq_printf(seq, " SynLkpEn: %3s\n", yesno(rssconf & SYNLKPEN_F));
  1851. seq_printf(seq, " ChnEn: %3s\n", yesno(rssconf &
  1852. CHANNELENABLE_F));
  1853. seq_printf(seq, " PrtEn: %3s\n", yesno(rssconf &
  1854. PORTENABLE_F));
  1855. seq_printf(seq, " TnlAllLkp: %3s\n", yesno(rssconf &
  1856. TNLALLLOOKUP_F));
  1857. seq_printf(seq, " VrtEn: %3s\n", yesno(rssconf &
  1858. VIRTENABLE_F));
  1859. seq_printf(seq, " CngEn: %3s\n", yesno(rssconf &
  1860. CONGESTIONENABLE_F));
  1861. seq_printf(seq, " HashToeplitz: %3s\n", yesno(rssconf &
  1862. HASHTOEPLITZ_F));
  1863. seq_printf(seq, " Udp4En: %3s\n", yesno(rssconf & UDPENABLE_F));
  1864. seq_printf(seq, " Disable: %3s\n", yesno(rssconf & DISABLE_F));
  1865. seq_puts(seq, "\n");
  1866. rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_TNL_A);
  1867. seq_printf(seq, "TP_RSS_CONFIG_TNL: %#x\n", rssconf);
  1868. seq_printf(seq, " MaskSize: %3d\n", MASKSIZE_G(rssconf));
  1869. seq_printf(seq, " MaskFilter: %3d\n", MASKFILTER_G(rssconf));
  1870. if (CHELSIO_CHIP_VERSION(adapter->params.chip) > CHELSIO_T5) {
  1871. seq_printf(seq, " HashAll: %3s\n",
  1872. yesno(rssconf & HASHALL_F));
  1873. seq_printf(seq, " HashEth: %3s\n",
  1874. yesno(rssconf & HASHETH_F));
  1875. }
  1876. seq_printf(seq, " UseWireCh: %3s\n", yesno(rssconf & USEWIRECH_F));
  1877. seq_puts(seq, "\n");
  1878. rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_OFD_A);
  1879. seq_printf(seq, "TP_RSS_CONFIG_OFD: %#x\n", rssconf);
  1880. seq_printf(seq, " MaskSize: %3d\n", MASKSIZE_G(rssconf));
  1881. seq_printf(seq, " RRCplMapEn: %3s\n", yesno(rssconf &
  1882. RRCPLMAPEN_F));
  1883. seq_printf(seq, " RRCplQueWidth: %3d\n", RRCPLQUEWIDTH_G(rssconf));
  1884. seq_puts(seq, "\n");
  1885. rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_SYN_A);
  1886. seq_printf(seq, "TP_RSS_CONFIG_SYN: %#x\n", rssconf);
  1887. seq_printf(seq, " MaskSize: %3d\n", MASKSIZE_G(rssconf));
  1888. seq_printf(seq, " UseWireCh: %3s\n", yesno(rssconf & USEWIRECH_F));
  1889. seq_puts(seq, "\n");
  1890. rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_VRT_A);
  1891. seq_printf(seq, "TP_RSS_CONFIG_VRT: %#x\n", rssconf);
  1892. if (CHELSIO_CHIP_VERSION(adapter->params.chip) > CHELSIO_T5) {
  1893. seq_printf(seq, " KeyWrAddrX: %3d\n",
  1894. KEYWRADDRX_G(rssconf));
  1895. seq_printf(seq, " KeyExtend: %3s\n",
  1896. yesno(rssconf & KEYEXTEND_F));
  1897. }
  1898. seq_printf(seq, " VfRdRg: %3s\n", yesno(rssconf & VFRDRG_F));
  1899. seq_printf(seq, " VfRdEn: %3s\n", yesno(rssconf & VFRDEN_F));
  1900. seq_printf(seq, " VfPerrEn: %3s\n", yesno(rssconf & VFPERREN_F));
  1901. seq_printf(seq, " KeyPerrEn: %3s\n", yesno(rssconf & KEYPERREN_F));
  1902. seq_printf(seq, " DisVfVlan: %3s\n", yesno(rssconf &
  1903. DISABLEVLAN_F));
  1904. seq_printf(seq, " EnUpSwt: %3s\n", yesno(rssconf & ENABLEUP0_F));
  1905. seq_printf(seq, " HashDelay: %3d\n", HASHDELAY_G(rssconf));
  1906. if (CHELSIO_CHIP_VERSION(adapter->params.chip) <= CHELSIO_T5)
  1907. seq_printf(seq, " VfWrAddr: %3d\n", VFWRADDR_G(rssconf));
  1908. else
  1909. seq_printf(seq, " VfWrAddr: %3d\n",
  1910. T6_VFWRADDR_G(rssconf));
  1911. seq_printf(seq, " KeyMode: %s\n", keymode[KEYMODE_G(rssconf)]);
  1912. seq_printf(seq, " VfWrEn: %3s\n", yesno(rssconf & VFWREN_F));
  1913. seq_printf(seq, " KeyWrEn: %3s\n", yesno(rssconf & KEYWREN_F));
  1914. seq_printf(seq, " KeyWrAddr: %3d\n", KEYWRADDR_G(rssconf));
  1915. seq_puts(seq, "\n");
  1916. rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_CNG_A);
  1917. seq_printf(seq, "TP_RSS_CONFIG_CNG: %#x\n", rssconf);
  1918. seq_printf(seq, " ChnCount3: %3s\n", yesno(rssconf & CHNCOUNT3_F));
  1919. seq_printf(seq, " ChnCount2: %3s\n", yesno(rssconf & CHNCOUNT2_F));
  1920. seq_printf(seq, " ChnCount1: %3s\n", yesno(rssconf & CHNCOUNT1_F));
  1921. seq_printf(seq, " ChnCount0: %3s\n", yesno(rssconf & CHNCOUNT0_F));
  1922. seq_printf(seq, " ChnUndFlow3: %3s\n", yesno(rssconf &
  1923. CHNUNDFLOW3_F));
  1924. seq_printf(seq, " ChnUndFlow2: %3s\n", yesno(rssconf &
  1925. CHNUNDFLOW2_F));
  1926. seq_printf(seq, " ChnUndFlow1: %3s\n", yesno(rssconf &
  1927. CHNUNDFLOW1_F));
  1928. seq_printf(seq, " ChnUndFlow0: %3s\n", yesno(rssconf &
  1929. CHNUNDFLOW0_F));
  1930. seq_printf(seq, " RstChn3: %3s\n", yesno(rssconf & RSTCHN3_F));
  1931. seq_printf(seq, " RstChn2: %3s\n", yesno(rssconf & RSTCHN2_F));
  1932. seq_printf(seq, " RstChn1: %3s\n", yesno(rssconf & RSTCHN1_F));
  1933. seq_printf(seq, " RstChn0: %3s\n", yesno(rssconf & RSTCHN0_F));
  1934. seq_printf(seq, " UpdVld: %3s\n", yesno(rssconf & UPDVLD_F));
  1935. seq_printf(seq, " Xoff: %3s\n", yesno(rssconf & XOFF_F));
  1936. seq_printf(seq, " UpdChn3: %3s\n", yesno(rssconf & UPDCHN3_F));
  1937. seq_printf(seq, " UpdChn2: %3s\n", yesno(rssconf & UPDCHN2_F));
  1938. seq_printf(seq, " UpdChn1: %3s\n", yesno(rssconf & UPDCHN1_F));
  1939. seq_printf(seq, " UpdChn0: %3s\n", yesno(rssconf & UPDCHN0_F));
  1940. seq_printf(seq, " Queue: %3d\n", QUEUE_G(rssconf));
  1941. return 0;
  1942. }
  1943. DEFINE_SHOW_ATTRIBUTE(rss_config);
  1944. /* RSS Secret Key.
  1945. */
  1946. static int rss_key_show(struct seq_file *seq, void *v)
  1947. {
  1948. u32 key[10];
  1949. t4_read_rss_key(seq->private, key, true);
  1950. seq_printf(seq, "%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x\n",
  1951. key[9], key[8], key[7], key[6], key[5], key[4], key[3],
  1952. key[2], key[1], key[0]);
  1953. return 0;
  1954. }
  1955. static int rss_key_open(struct inode *inode, struct file *file)
  1956. {
  1957. return single_open(file, rss_key_show, inode->i_private);
  1958. }
  1959. static ssize_t rss_key_write(struct file *file, const char __user *buf,
  1960. size_t count, loff_t *pos)
  1961. {
  1962. int i, j;
  1963. u32 key[10];
  1964. char s[100], *p;
  1965. struct adapter *adap = file_inode(file)->i_private;
  1966. if (count > sizeof(s) - 1)
  1967. return -EINVAL;
  1968. if (copy_from_user(s, buf, count))
  1969. return -EFAULT;
  1970. for (i = count; i > 0 && isspace(s[i - 1]); i--)
  1971. ;
  1972. s[i] = '\0';
  1973. for (p = s, i = 9; i >= 0; i--) {
  1974. key[i] = 0;
  1975. for (j = 0; j < 8; j++, p++) {
  1976. if (!isxdigit(*p))
  1977. return -EINVAL;
  1978. key[i] = (key[i] << 4) | hex2val(*p);
  1979. }
  1980. }
  1981. t4_write_rss_key(adap, key, -1, true);
  1982. return count;
  1983. }
  1984. static const struct file_operations rss_key_debugfs_fops = {
  1985. .owner = THIS_MODULE,
  1986. .open = rss_key_open,
  1987. .read = seq_read,
  1988. .llseek = seq_lseek,
  1989. .release = single_release,
  1990. .write = rss_key_write
  1991. };
  1992. /* PF RSS Configuration.
  1993. */
  1994. struct rss_pf_conf {
  1995. u32 rss_pf_map;
  1996. u32 rss_pf_mask;
  1997. u32 rss_pf_config;
  1998. };
  1999. static int rss_pf_config_show(struct seq_file *seq, void *v, int idx)
  2000. {
  2001. struct rss_pf_conf *pfconf;
  2002. if (v == SEQ_START_TOKEN) {
  2003. /* use the 0th entry to dump the PF Map Index Size */
  2004. pfconf = seq->private + offsetof(struct seq_tab, data);
  2005. seq_printf(seq, "PF Map Index Size = %d\n\n",
  2006. LKPIDXSIZE_G(pfconf->rss_pf_map));
  2007. seq_puts(seq, " RSS PF VF Hash Tuple Enable Default\n");
  2008. seq_puts(seq, " Enable IPF Mask Mask IPv6 IPv4 UDP Queue\n");
  2009. seq_puts(seq, " PF Map Chn Prt Map Size Size Four Two Four Two Four Ch1 Ch0\n");
  2010. } else {
  2011. #define G_PFnLKPIDX(map, n) \
  2012. (((map) >> PF1LKPIDX_S*(n)) & PF0LKPIDX_M)
  2013. #define G_PFnMSKSIZE(mask, n) \
  2014. (((mask) >> PF1MSKSIZE_S*(n)) & PF1MSKSIZE_M)
  2015. pfconf = v;
  2016. seq_printf(seq, "%3d %3s %3s %3s %3d %3d %3d %3s %3s %3s %3s %3s %3d %3d\n",
  2017. idx,
  2018. yesno(pfconf->rss_pf_config & MAPENABLE_F),
  2019. yesno(pfconf->rss_pf_config & CHNENABLE_F),
  2020. yesno(pfconf->rss_pf_config & PRTENABLE_F),
  2021. G_PFnLKPIDX(pfconf->rss_pf_map, idx),
  2022. G_PFnMSKSIZE(pfconf->rss_pf_mask, idx),
  2023. IVFWIDTH_G(pfconf->rss_pf_config),
  2024. yesno(pfconf->rss_pf_config & IP6FOURTUPEN_F),
  2025. yesno(pfconf->rss_pf_config & IP6TWOTUPEN_F),
  2026. yesno(pfconf->rss_pf_config & IP4FOURTUPEN_F),
  2027. yesno(pfconf->rss_pf_config & IP4TWOTUPEN_F),
  2028. yesno(pfconf->rss_pf_config & UDPFOURTUPEN_F),
  2029. CH1DEFAULTQUEUE_G(pfconf->rss_pf_config),
  2030. CH0DEFAULTQUEUE_G(pfconf->rss_pf_config));
  2031. #undef G_PFnLKPIDX
  2032. #undef G_PFnMSKSIZE
  2033. }
  2034. return 0;
  2035. }
  2036. static int rss_pf_config_open(struct inode *inode, struct file *file)
  2037. {
  2038. struct adapter *adapter = inode->i_private;
  2039. struct seq_tab *p;
  2040. u32 rss_pf_map, rss_pf_mask;
  2041. struct rss_pf_conf *pfconf;
  2042. int pf;
  2043. p = seq_open_tab(file, 8, sizeof(*pfconf), 1, rss_pf_config_show);
  2044. if (!p)
  2045. return -ENOMEM;
  2046. pfconf = (struct rss_pf_conf *)p->data;
  2047. rss_pf_map = t4_read_rss_pf_map(adapter, true);
  2048. rss_pf_mask = t4_read_rss_pf_mask(adapter, true);
  2049. for (pf = 0; pf < 8; pf++) {
  2050. pfconf[pf].rss_pf_map = rss_pf_map;
  2051. pfconf[pf].rss_pf_mask = rss_pf_mask;
  2052. t4_read_rss_pf_config(adapter, pf, &pfconf[pf].rss_pf_config,
  2053. true);
  2054. }
  2055. return 0;
  2056. }
  2057. static const struct file_operations rss_pf_config_debugfs_fops = {
  2058. .owner = THIS_MODULE,
  2059. .open = rss_pf_config_open,
  2060. .read = seq_read,
  2061. .llseek = seq_lseek,
  2062. .release = seq_release_private
  2063. };
  2064. /* VF RSS Configuration.
  2065. */
  2066. struct rss_vf_conf {
  2067. u32 rss_vf_vfl;
  2068. u32 rss_vf_vfh;
  2069. };
  2070. static int rss_vf_config_show(struct seq_file *seq, void *v, int idx)
  2071. {
  2072. if (v == SEQ_START_TOKEN) {
  2073. seq_puts(seq, " RSS Hash Tuple Enable\n");
  2074. seq_puts(seq, " Enable IVF Dis Enb IPv6 IPv4 UDP Def Secret Key\n");
  2075. seq_puts(seq, " VF Chn Prt Map VLAN uP Four Two Four Two Four Que Idx Hash\n");
  2076. } else {
  2077. struct rss_vf_conf *vfconf = v;
  2078. seq_printf(seq, "%3d %3s %3s %3d %3s %3s %3s %3s %3s %3s %3s %4d %3d %#10x\n",
  2079. idx,
  2080. yesno(vfconf->rss_vf_vfh & VFCHNEN_F),
  2081. yesno(vfconf->rss_vf_vfh & VFPRTEN_F),
  2082. VFLKPIDX_G(vfconf->rss_vf_vfh),
  2083. yesno(vfconf->rss_vf_vfh & VFVLNEX_F),
  2084. yesno(vfconf->rss_vf_vfh & VFUPEN_F),
  2085. yesno(vfconf->rss_vf_vfh & VFIP4FOURTUPEN_F),
  2086. yesno(vfconf->rss_vf_vfh & VFIP6TWOTUPEN_F),
  2087. yesno(vfconf->rss_vf_vfh & VFIP4FOURTUPEN_F),
  2088. yesno(vfconf->rss_vf_vfh & VFIP4TWOTUPEN_F),
  2089. yesno(vfconf->rss_vf_vfh & ENABLEUDPHASH_F),
  2090. DEFAULTQUEUE_G(vfconf->rss_vf_vfh),
  2091. KEYINDEX_G(vfconf->rss_vf_vfh),
  2092. vfconf->rss_vf_vfl);
  2093. }
  2094. return 0;
  2095. }
  2096. static int rss_vf_config_open(struct inode *inode, struct file *file)
  2097. {
  2098. struct adapter *adapter = inode->i_private;
  2099. struct seq_tab *p;
  2100. struct rss_vf_conf *vfconf;
  2101. int vf, vfcount = adapter->params.arch.vfcount;
  2102. p = seq_open_tab(file, vfcount, sizeof(*vfconf), 1, rss_vf_config_show);
  2103. if (!p)
  2104. return -ENOMEM;
  2105. vfconf = (struct rss_vf_conf *)p->data;
  2106. for (vf = 0; vf < vfcount; vf++) {
  2107. t4_read_rss_vf_config(adapter, vf, &vfconf[vf].rss_vf_vfl,
  2108. &vfconf[vf].rss_vf_vfh, true);
  2109. }
  2110. return 0;
  2111. }
  2112. static const struct file_operations rss_vf_config_debugfs_fops = {
  2113. .owner = THIS_MODULE,
  2114. .open = rss_vf_config_open,
  2115. .read = seq_read,
  2116. .llseek = seq_lseek,
  2117. .release = seq_release_private
  2118. };
  2119. #ifdef CONFIG_CHELSIO_T4_DCB
  2120. extern char *dcb_ver_array[];
  2121. /* Data Center Briging information for each port.
  2122. */
  2123. static int dcb_info_show(struct seq_file *seq, void *v)
  2124. {
  2125. struct adapter *adap = seq->private;
  2126. if (v == SEQ_START_TOKEN) {
  2127. seq_puts(seq, "Data Center Bridging Information\n");
  2128. } else {
  2129. int port = (uintptr_t)v - 2;
  2130. struct net_device *dev = adap->port[port];
  2131. struct port_info *pi = netdev2pinfo(dev);
  2132. struct port_dcb_info *dcb = &pi->dcb;
  2133. seq_puts(seq, "\n");
  2134. seq_printf(seq, "Port: %d (DCB negotiated: %s)\n",
  2135. port,
  2136. cxgb4_dcb_enabled(dev) ? "yes" : "no");
  2137. if (cxgb4_dcb_enabled(dev))
  2138. seq_printf(seq, "[ DCBx Version %s ]\n",
  2139. dcb_ver_array[dcb->dcb_version]);
  2140. if (dcb->msgs) {
  2141. int i;
  2142. seq_puts(seq, "\n Index\t\t\t :\t");
  2143. for (i = 0; i < 8; i++)
  2144. seq_printf(seq, " %3d", i);
  2145. seq_puts(seq, "\n\n");
  2146. }
  2147. if (dcb->msgs & CXGB4_DCB_FW_PGID) {
  2148. int prio, pgid;
  2149. seq_puts(seq, " Priority Group IDs\t :\t");
  2150. for (prio = 0; prio < 8; prio++) {
  2151. pgid = (dcb->pgid >> 4 * (7 - prio)) & 0xf;
  2152. seq_printf(seq, " %3d", pgid);
  2153. }
  2154. seq_puts(seq, "\n");
  2155. }
  2156. if (dcb->msgs & CXGB4_DCB_FW_PGRATE) {
  2157. int pg;
  2158. seq_puts(seq, " Priority Group BW(%)\t :\t");
  2159. for (pg = 0; pg < 8; pg++)
  2160. seq_printf(seq, " %3d", dcb->pgrate[pg]);
  2161. seq_puts(seq, "\n");
  2162. if (dcb->dcb_version == FW_PORT_DCB_VER_IEEE) {
  2163. seq_puts(seq, " TSA Algorithm\t\t :\t");
  2164. for (pg = 0; pg < 8; pg++)
  2165. seq_printf(seq, " %3d", dcb->tsa[pg]);
  2166. seq_puts(seq, "\n");
  2167. }
  2168. seq_printf(seq, " Max PG Traffic Classes [%3d ]\n",
  2169. dcb->pg_num_tcs_supported);
  2170. seq_puts(seq, "\n");
  2171. }
  2172. if (dcb->msgs & CXGB4_DCB_FW_PRIORATE) {
  2173. int prio;
  2174. seq_puts(seq, " Priority Rate\t:\t");
  2175. for (prio = 0; prio < 8; prio++)
  2176. seq_printf(seq, " %3d", dcb->priorate[prio]);
  2177. seq_puts(seq, "\n");
  2178. }
  2179. if (dcb->msgs & CXGB4_DCB_FW_PFC) {
  2180. int prio;
  2181. seq_puts(seq, " Priority Flow Control :\t");
  2182. for (prio = 0; prio < 8; prio++) {
  2183. int pfcen = (dcb->pfcen >> 1 * (7 - prio))
  2184. & 0x1;
  2185. seq_printf(seq, " %3d", pfcen);
  2186. }
  2187. seq_puts(seq, "\n");
  2188. seq_printf(seq, " Max PFC Traffic Classes [%3d ]\n",
  2189. dcb->pfc_num_tcs_supported);
  2190. seq_puts(seq, "\n");
  2191. }
  2192. if (dcb->msgs & CXGB4_DCB_FW_APP_ID) {
  2193. int app, napps;
  2194. seq_puts(seq, " Application Information:\n");
  2195. seq_puts(seq, " App Priority Selection Protocol\n");
  2196. seq_puts(seq, " Index Map Field ID\n");
  2197. for (app = 0, napps = 0;
  2198. app < CXGB4_MAX_DCBX_APP_SUPPORTED; app++) {
  2199. struct app_priority *ap;
  2200. static const char * const sel_names[] = {
  2201. "Ethertype",
  2202. "Socket TCP",
  2203. "Socket UDP",
  2204. "Socket All",
  2205. };
  2206. const char *sel_name;
  2207. ap = &dcb->app_priority[app];
  2208. /* skip empty slots */
  2209. if (ap->protocolid == 0)
  2210. continue;
  2211. napps++;
  2212. if (ap->sel_field < ARRAY_SIZE(sel_names))
  2213. sel_name = sel_names[ap->sel_field];
  2214. else
  2215. sel_name = "UNKNOWN";
  2216. seq_printf(seq, " %3d %#04x %-10s (%d) %#06x (%d)\n",
  2217. app,
  2218. ap->user_prio_map,
  2219. sel_name, ap->sel_field,
  2220. ap->protocolid, ap->protocolid);
  2221. }
  2222. if (napps == 0)
  2223. seq_puts(seq, " --- None ---\n");
  2224. }
  2225. }
  2226. return 0;
  2227. }
  2228. static inline void *dcb_info_get_idx(struct adapter *adap, loff_t pos)
  2229. {
  2230. return (pos <= adap->params.nports
  2231. ? (void *)((uintptr_t)pos + 1)
  2232. : NULL);
  2233. }
  2234. static void *dcb_info_start(struct seq_file *seq, loff_t *pos)
  2235. {
  2236. struct adapter *adap = seq->private;
  2237. return (*pos
  2238. ? dcb_info_get_idx(adap, *pos)
  2239. : SEQ_START_TOKEN);
  2240. }
  2241. static void dcb_info_stop(struct seq_file *seq, void *v)
  2242. {
  2243. }
  2244. static void *dcb_info_next(struct seq_file *seq, void *v, loff_t *pos)
  2245. {
  2246. struct adapter *adap = seq->private;
  2247. (*pos)++;
  2248. return dcb_info_get_idx(adap, *pos);
  2249. }
  2250. static const struct seq_operations dcb_info_seq_ops = {
  2251. .start = dcb_info_start,
  2252. .next = dcb_info_next,
  2253. .stop = dcb_info_stop,
  2254. .show = dcb_info_show
  2255. };
  2256. static int dcb_info_open(struct inode *inode, struct file *file)
  2257. {
  2258. int res = seq_open(file, &dcb_info_seq_ops);
  2259. if (!res) {
  2260. struct seq_file *seq = file->private_data;
  2261. seq->private = inode->i_private;
  2262. }
  2263. return res;
  2264. }
  2265. static const struct file_operations dcb_info_debugfs_fops = {
  2266. .owner = THIS_MODULE,
  2267. .open = dcb_info_open,
  2268. .read = seq_read,
  2269. .llseek = seq_lseek,
  2270. .release = seq_release,
  2271. };
  2272. #endif /* CONFIG_CHELSIO_T4_DCB */
  2273. static int resources_show(struct seq_file *seq, void *v)
  2274. {
  2275. struct adapter *adapter = seq->private;
  2276. struct pf_resources *pfres = &adapter->params.pfres;
  2277. #define S(desc, fmt, var) \
  2278. seq_printf(seq, "%-60s " fmt "\n", \
  2279. desc " (" #var "):", pfres->var)
  2280. S("Virtual Interfaces", "%d", nvi);
  2281. S("Egress Queues", "%d", neq);
  2282. S("Ethernet Control", "%d", nethctrl);
  2283. S("Ingress Queues/w Free Lists/Interrupts", "%d", niqflint);
  2284. S("Ingress Queues", "%d", niq);
  2285. S("Traffic Class", "%d", tc);
  2286. S("Port Access Rights Mask", "%#x", pmask);
  2287. S("MAC Address Filters", "%d", nexactf);
  2288. S("Firmware Command Read Capabilities", "%#x", r_caps);
  2289. S("Firmware Command Write/Execute Capabilities", "%#x", wx_caps);
  2290. #undef S
  2291. return 0;
  2292. }
  2293. DEFINE_SHOW_ATTRIBUTE(resources);
  2294. /**
  2295. * ethqset2pinfo - return port_info of an Ethernet Queue Set
  2296. * @adap: the adapter
  2297. * @qset: Ethernet Queue Set
  2298. */
  2299. static inline struct port_info *ethqset2pinfo(struct adapter *adap, int qset)
  2300. {
  2301. int pidx;
  2302. for_each_port(adap, pidx) {
  2303. struct port_info *pi = adap2pinfo(adap, pidx);
  2304. if (qset >= pi->first_qset &&
  2305. qset < pi->first_qset + pi->nqsets)
  2306. return pi;
  2307. }
  2308. /* should never happen! */
  2309. BUG();
  2310. return NULL;
  2311. }
  2312. static int sge_qinfo_uld_txq_entries(const struct adapter *adap, int uld)
  2313. {
  2314. const struct sge_uld_txq_info *utxq_info = adap->sge.uld_txq_info[uld];
  2315. if (!utxq_info)
  2316. return 0;
  2317. return DIV_ROUND_UP(utxq_info->ntxq, 4);
  2318. }
  2319. static int sge_qinfo_uld_rspq_entries(const struct adapter *adap, int uld,
  2320. bool ciq)
  2321. {
  2322. const struct sge_uld_rxq_info *urxq_info = adap->sge.uld_rxq_info[uld];
  2323. if (!urxq_info)
  2324. return 0;
  2325. return ciq ? DIV_ROUND_UP(urxq_info->nciq, 4) :
  2326. DIV_ROUND_UP(urxq_info->nrxq, 4);
  2327. }
  2328. static int sge_qinfo_uld_rxq_entries(const struct adapter *adap, int uld)
  2329. {
  2330. return sge_qinfo_uld_rspq_entries(adap, uld, false);
  2331. }
  2332. static int sge_qinfo_uld_ciq_entries(const struct adapter *adap, int uld)
  2333. {
  2334. return sge_qinfo_uld_rspq_entries(adap, uld, true);
  2335. }
  2336. static int sge_qinfo_show(struct seq_file *seq, void *v)
  2337. {
  2338. int eth_entries, ctrl_entries, eo_entries = 0;
  2339. int uld_rxq_entries[CXGB4_ULD_MAX] = { 0 };
  2340. int uld_ciq_entries[CXGB4_ULD_MAX] = { 0 };
  2341. int uld_txq_entries[CXGB4_TX_MAX] = { 0 };
  2342. const struct sge_uld_txq_info *utxq_info;
  2343. const struct sge_uld_rxq_info *urxq_info;
  2344. struct adapter *adap = seq->private;
  2345. int i, n, r = (uintptr_t)v - 1;
  2346. struct sge *s = &adap->sge;
  2347. eth_entries = DIV_ROUND_UP(adap->sge.ethqsets, 4);
  2348. ctrl_entries = DIV_ROUND_UP(MAX_CTRL_QUEUES, 4);
  2349. if (adap->sge.eohw_txq)
  2350. eo_entries = DIV_ROUND_UP(adap->sge.eoqsets, 4);
  2351. mutex_lock(&uld_mutex);
  2352. if (s->uld_txq_info)
  2353. for (i = 0; i < ARRAY_SIZE(uld_txq_entries); i++)
  2354. uld_txq_entries[i] = sge_qinfo_uld_txq_entries(adap, i);
  2355. if (s->uld_rxq_info) {
  2356. for (i = 0; i < ARRAY_SIZE(uld_rxq_entries); i++) {
  2357. uld_rxq_entries[i] = sge_qinfo_uld_rxq_entries(adap, i);
  2358. uld_ciq_entries[i] = sge_qinfo_uld_ciq_entries(adap, i);
  2359. }
  2360. }
  2361. if (r)
  2362. seq_putc(seq, '\n');
  2363. #define S3(fmt_spec, s, v) \
  2364. do { \
  2365. seq_printf(seq, "%-12s", s); \
  2366. for (i = 0; i < n; ++i) \
  2367. seq_printf(seq, " %16" fmt_spec, v); \
  2368. seq_putc(seq, '\n'); \
  2369. } while (0)
  2370. #define S(s, v) S3("s", s, v)
  2371. #define T3(fmt_spec, s, v) S3(fmt_spec, s, tx[i].v)
  2372. #define T(s, v) S3("u", s, tx[i].v)
  2373. #define TL(s, v) T3("lu", s, v)
  2374. #define R3(fmt_spec, s, v) S3(fmt_spec, s, rx[i].v)
  2375. #define R(s, v) S3("u", s, rx[i].v)
  2376. #define RL(s, v) R3("lu", s, v)
  2377. if (r < eth_entries) {
  2378. int base_qset = r * 4;
  2379. const struct sge_eth_rxq *rx = &s->ethrxq[base_qset];
  2380. const struct sge_eth_txq *tx = &s->ethtxq[base_qset];
  2381. n = min(4, s->ethqsets - 4 * r);
  2382. S("QType:", "Ethernet");
  2383. S("Interface:",
  2384. rx[i].rspq.netdev ? rx[i].rspq.netdev->name : "N/A");
  2385. T("TxQ ID:", q.cntxt_id);
  2386. T("TxQ size:", q.size);
  2387. T("TxQ inuse:", q.in_use);
  2388. T("TxQ CIDX:", q.cidx);
  2389. T("TxQ PIDX:", q.pidx);
  2390. #ifdef CONFIG_CHELSIO_T4_DCB
  2391. T("DCB Prio:", dcb_prio);
  2392. S3("u", "DCB PGID:",
  2393. (ethqset2pinfo(adap, base_qset + i)->dcb.pgid >>
  2394. 4*(7-tx[i].dcb_prio)) & 0xf);
  2395. S3("u", "DCB PFC:",
  2396. (ethqset2pinfo(adap, base_qset + i)->dcb.pfcen >>
  2397. 1*(7-tx[i].dcb_prio)) & 0x1);
  2398. #endif
  2399. R("RspQ ID:", rspq.abs_id);
  2400. R("RspQ size:", rspq.size);
  2401. R("RspQE size:", rspq.iqe_len);
  2402. R("RspQ CIDX:", rspq.cidx);
  2403. R("RspQ Gen:", rspq.gen);
  2404. S3("u", "Intr delay:", qtimer_val(adap, &rx[i].rspq));
  2405. S3("u", "Intr pktcnt:", s->counter_val[rx[i].rspq.pktcnt_idx]);
  2406. R("FL ID:", fl.cntxt_id);
  2407. R("FL size:", fl.size - 8);
  2408. R("FL pend:", fl.pend_cred);
  2409. R("FL avail:", fl.avail);
  2410. R("FL PIDX:", fl.pidx);
  2411. R("FL CIDX:", fl.cidx);
  2412. RL("RxPackets:", stats.pkts);
  2413. RL("RxCSO:", stats.rx_cso);
  2414. RL("VLANxtract:", stats.vlan_ex);
  2415. RL("LROmerged:", stats.lro_merged);
  2416. RL("LROpackets:", stats.lro_pkts);
  2417. RL("RxDrops:", stats.rx_drops);
  2418. RL("RxBadPkts:", stats.bad_rx_pkts);
  2419. TL("TSO:", tso);
  2420. TL("USO:", uso);
  2421. TL("TxCSO:", tx_cso);
  2422. TL("VLANins:", vlan_ins);
  2423. TL("TxQFull:", q.stops);
  2424. TL("TxQRestarts:", q.restarts);
  2425. TL("TxMapErr:", mapping_err);
  2426. RL("FLAllocErr:", fl.alloc_failed);
  2427. RL("FLLrgAlcErr:", fl.large_alloc_failed);
  2428. RL("FLMapErr:", fl.mapping_err);
  2429. RL("FLLow:", fl.low);
  2430. RL("FLStarving:", fl.starving);
  2431. goto unlock;
  2432. }
  2433. r -= eth_entries;
  2434. if (r < eo_entries) {
  2435. int base_qset = r * 4;
  2436. const struct sge_ofld_rxq *rx = &s->eohw_rxq[base_qset];
  2437. const struct sge_eohw_txq *tx = &s->eohw_txq[base_qset];
  2438. n = min(4, s->eoqsets - 4 * r);
  2439. S("QType:", "ETHOFLD");
  2440. S("Interface:",
  2441. rx[i].rspq.netdev ? rx[i].rspq.netdev->name : "N/A");
  2442. T("TxQ ID:", q.cntxt_id);
  2443. T("TxQ size:", q.size);
  2444. T("TxQ inuse:", q.in_use);
  2445. T("TxQ CIDX:", q.cidx);
  2446. T("TxQ PIDX:", q.pidx);
  2447. R("RspQ ID:", rspq.abs_id);
  2448. R("RspQ size:", rspq.size);
  2449. R("RspQE size:", rspq.iqe_len);
  2450. R("RspQ CIDX:", rspq.cidx);
  2451. R("RspQ Gen:", rspq.gen);
  2452. S3("u", "Intr delay:", qtimer_val(adap, &rx[i].rspq));
  2453. S3("u", "Intr pktcnt:", s->counter_val[rx[i].rspq.pktcnt_idx]);
  2454. R("FL ID:", fl.cntxt_id);
  2455. S3("u", "FL size:", rx->fl.size ? rx->fl.size - 8 : 0);
  2456. R("FL pend:", fl.pend_cred);
  2457. R("FL avail:", fl.avail);
  2458. R("FL PIDX:", fl.pidx);
  2459. R("FL CIDX:", fl.cidx);
  2460. RL("RxPackets:", stats.pkts);
  2461. RL("RxImm:", stats.imm);
  2462. RL("RxAN", stats.an);
  2463. RL("RxNoMem", stats.nomem);
  2464. TL("TSO:", tso);
  2465. TL("USO:", uso);
  2466. TL("TxCSO:", tx_cso);
  2467. TL("VLANins:", vlan_ins);
  2468. TL("TxQFull:", q.stops);
  2469. TL("TxQRestarts:", q.restarts);
  2470. TL("TxMapErr:", mapping_err);
  2471. RL("FLAllocErr:", fl.alloc_failed);
  2472. RL("FLLrgAlcErr:", fl.large_alloc_failed);
  2473. RL("FLMapErr:", fl.mapping_err);
  2474. RL("FLLow:", fl.low);
  2475. RL("FLStarving:", fl.starving);
  2476. goto unlock;
  2477. }
  2478. r -= eo_entries;
  2479. if (r < uld_txq_entries[CXGB4_TX_OFLD]) {
  2480. const struct sge_uld_txq *tx;
  2481. utxq_info = s->uld_txq_info[CXGB4_TX_OFLD];
  2482. tx = &utxq_info->uldtxq[r * 4];
  2483. n = min(4, utxq_info->ntxq - 4 * r);
  2484. S("QType:", "OFLD-TXQ");
  2485. T("TxQ ID:", q.cntxt_id);
  2486. T("TxQ size:", q.size);
  2487. T("TxQ inuse:", q.in_use);
  2488. T("TxQ CIDX:", q.cidx);
  2489. T("TxQ PIDX:", q.pidx);
  2490. goto unlock;
  2491. }
  2492. r -= uld_txq_entries[CXGB4_TX_OFLD];
  2493. if (r < uld_rxq_entries[CXGB4_ULD_RDMA]) {
  2494. const struct sge_ofld_rxq *rx;
  2495. urxq_info = s->uld_rxq_info[CXGB4_ULD_RDMA];
  2496. rx = &urxq_info->uldrxq[r * 4];
  2497. n = min(4, urxq_info->nrxq - 4 * r);
  2498. S("QType:", "RDMA-CPL");
  2499. S("Interface:",
  2500. rx[i].rspq.netdev ? rx[i].rspq.netdev->name : "N/A");
  2501. R("RspQ ID:", rspq.abs_id);
  2502. R("RspQ size:", rspq.size);
  2503. R("RspQE size:", rspq.iqe_len);
  2504. R("RspQ CIDX:", rspq.cidx);
  2505. R("RspQ Gen:", rspq.gen);
  2506. S3("u", "Intr delay:", qtimer_val(adap, &rx[i].rspq));
  2507. S3("u", "Intr pktcnt:", s->counter_val[rx[i].rspq.pktcnt_idx]);
  2508. R("FL ID:", fl.cntxt_id);
  2509. R("FL size:", fl.size - 8);
  2510. R("FL pend:", fl.pend_cred);
  2511. R("FL avail:", fl.avail);
  2512. R("FL PIDX:", fl.pidx);
  2513. R("FL CIDX:", fl.cidx);
  2514. goto unlock;
  2515. }
  2516. r -= uld_rxq_entries[CXGB4_ULD_RDMA];
  2517. if (r < uld_ciq_entries[CXGB4_ULD_RDMA]) {
  2518. const struct sge_ofld_rxq *rx;
  2519. int ciq_idx = 0;
  2520. urxq_info = s->uld_rxq_info[CXGB4_ULD_RDMA];
  2521. ciq_idx = urxq_info->nrxq + (r * 4);
  2522. rx = &urxq_info->uldrxq[ciq_idx];
  2523. n = min(4, urxq_info->nciq - 4 * r);
  2524. S("QType:", "RDMA-CIQ");
  2525. S("Interface:",
  2526. rx[i].rspq.netdev ? rx[i].rspq.netdev->name : "N/A");
  2527. R("RspQ ID:", rspq.abs_id);
  2528. R("RspQ size:", rspq.size);
  2529. R("RspQE size:", rspq.iqe_len);
  2530. R("RspQ CIDX:", rspq.cidx);
  2531. R("RspQ Gen:", rspq.gen);
  2532. S3("u", "Intr delay:", qtimer_val(adap, &rx[i].rspq));
  2533. S3("u", "Intr pktcnt:", s->counter_val[rx[i].rspq.pktcnt_idx]);
  2534. goto unlock;
  2535. }
  2536. r -= uld_ciq_entries[CXGB4_ULD_RDMA];
  2537. if (r < uld_rxq_entries[CXGB4_ULD_ISCSI]) {
  2538. const struct sge_ofld_rxq *rx;
  2539. urxq_info = s->uld_rxq_info[CXGB4_ULD_ISCSI];
  2540. rx = &urxq_info->uldrxq[r * 4];
  2541. n = min(4, urxq_info->nrxq - 4 * r);
  2542. S("QType:", "iSCSI");
  2543. R("RspQ ID:", rspq.abs_id);
  2544. R("RspQ size:", rspq.size);
  2545. R("RspQE size:", rspq.iqe_len);
  2546. R("RspQ CIDX:", rspq.cidx);
  2547. R("RspQ Gen:", rspq.gen);
  2548. S3("u", "Intr delay:", qtimer_val(adap, &rx[i].rspq));
  2549. S3("u", "Intr pktcnt:", s->counter_val[rx[i].rspq.pktcnt_idx]);
  2550. R("FL ID:", fl.cntxt_id);
  2551. R("FL size:", fl.size - 8);
  2552. R("FL pend:", fl.pend_cred);
  2553. R("FL avail:", fl.avail);
  2554. R("FL PIDX:", fl.pidx);
  2555. R("FL CIDX:", fl.cidx);
  2556. goto unlock;
  2557. }
  2558. r -= uld_rxq_entries[CXGB4_ULD_ISCSI];
  2559. if (r < uld_rxq_entries[CXGB4_ULD_ISCSIT]) {
  2560. const struct sge_ofld_rxq *rx;
  2561. urxq_info = s->uld_rxq_info[CXGB4_ULD_ISCSIT];
  2562. rx = &urxq_info->uldrxq[r * 4];
  2563. n = min(4, urxq_info->nrxq - 4 * r);
  2564. S("QType:", "iSCSIT");
  2565. R("RspQ ID:", rspq.abs_id);
  2566. R("RspQ size:", rspq.size);
  2567. R("RspQE size:", rspq.iqe_len);
  2568. R("RspQ CIDX:", rspq.cidx);
  2569. R("RspQ Gen:", rspq.gen);
  2570. S3("u", "Intr delay:", qtimer_val(adap, &rx[i].rspq));
  2571. S3("u", "Intr pktcnt:", s->counter_val[rx[i].rspq.pktcnt_idx]);
  2572. R("FL ID:", fl.cntxt_id);
  2573. R("FL size:", fl.size - 8);
  2574. R("FL pend:", fl.pend_cred);
  2575. R("FL avail:", fl.avail);
  2576. R("FL PIDX:", fl.pidx);
  2577. R("FL CIDX:", fl.cidx);
  2578. goto unlock;
  2579. }
  2580. r -= uld_rxq_entries[CXGB4_ULD_ISCSIT];
  2581. if (r < uld_rxq_entries[CXGB4_ULD_TLS]) {
  2582. const struct sge_ofld_rxq *rx;
  2583. urxq_info = s->uld_rxq_info[CXGB4_ULD_TLS];
  2584. rx = &urxq_info->uldrxq[r * 4];
  2585. n = min(4, urxq_info->nrxq - 4 * r);
  2586. S("QType:", "TLS");
  2587. R("RspQ ID:", rspq.abs_id);
  2588. R("RspQ size:", rspq.size);
  2589. R("RspQE size:", rspq.iqe_len);
  2590. R("RspQ CIDX:", rspq.cidx);
  2591. R("RspQ Gen:", rspq.gen);
  2592. S3("u", "Intr delay:", qtimer_val(adap, &rx[i].rspq));
  2593. S3("u", "Intr pktcnt:", s->counter_val[rx[i].rspq.pktcnt_idx]);
  2594. R("FL ID:", fl.cntxt_id);
  2595. R("FL size:", fl.size - 8);
  2596. R("FL pend:", fl.pend_cred);
  2597. R("FL avail:", fl.avail);
  2598. R("FL PIDX:", fl.pidx);
  2599. R("FL CIDX:", fl.cidx);
  2600. goto unlock;
  2601. }
  2602. r -= uld_rxq_entries[CXGB4_ULD_TLS];
  2603. if (r < uld_txq_entries[CXGB4_TX_CRYPTO]) {
  2604. const struct sge_ofld_rxq *rx;
  2605. const struct sge_uld_txq *tx;
  2606. utxq_info = s->uld_txq_info[CXGB4_TX_CRYPTO];
  2607. urxq_info = s->uld_rxq_info[CXGB4_ULD_CRYPTO];
  2608. tx = &utxq_info->uldtxq[r * 4];
  2609. rx = &urxq_info->uldrxq[r * 4];
  2610. n = min(4, utxq_info->ntxq - 4 * r);
  2611. S("QType:", "Crypto");
  2612. T("TxQ ID:", q.cntxt_id);
  2613. T("TxQ size:", q.size);
  2614. T("TxQ inuse:", q.in_use);
  2615. T("TxQ CIDX:", q.cidx);
  2616. T("TxQ PIDX:", q.pidx);
  2617. R("RspQ ID:", rspq.abs_id);
  2618. R("RspQ size:", rspq.size);
  2619. R("RspQE size:", rspq.iqe_len);
  2620. R("RspQ CIDX:", rspq.cidx);
  2621. R("RspQ Gen:", rspq.gen);
  2622. S3("u", "Intr delay:", qtimer_val(adap, &rx[i].rspq));
  2623. S3("u", "Intr pktcnt:", s->counter_val[rx[i].rspq.pktcnt_idx]);
  2624. R("FL ID:", fl.cntxt_id);
  2625. R("FL size:", fl.size - 8);
  2626. R("FL pend:", fl.pend_cred);
  2627. R("FL avail:", fl.avail);
  2628. R("FL PIDX:", fl.pidx);
  2629. R("FL CIDX:", fl.cidx);
  2630. goto unlock;
  2631. }
  2632. r -= uld_txq_entries[CXGB4_TX_CRYPTO];
  2633. if (r < ctrl_entries) {
  2634. const struct sge_ctrl_txq *tx = &s->ctrlq[r * 4];
  2635. n = min(4, adap->params.nports - 4 * r);
  2636. S("QType:", "Control");
  2637. T("TxQ ID:", q.cntxt_id);
  2638. T("TxQ size:", q.size);
  2639. T("TxQ inuse:", q.in_use);
  2640. T("TxQ CIDX:", q.cidx);
  2641. T("TxQ PIDX:", q.pidx);
  2642. TL("TxQFull:", q.stops);
  2643. TL("TxQRestarts:", q.restarts);
  2644. goto unlock;
  2645. }
  2646. r -= ctrl_entries;
  2647. if (r < 1) {
  2648. const struct sge_rspq *evtq = &s->fw_evtq;
  2649. seq_printf(seq, "%-12s %16s\n", "QType:", "FW event queue");
  2650. seq_printf(seq, "%-12s %16u\n", "RspQ ID:", evtq->abs_id);
  2651. seq_printf(seq, "%-12s %16u\n", "RspQ size:", evtq->size);
  2652. seq_printf(seq, "%-12s %16u\n", "RspQE size:", evtq->iqe_len);
  2653. seq_printf(seq, "%-12s %16u\n", "RspQ CIDX:", evtq->cidx);
  2654. seq_printf(seq, "%-12s %16u\n", "RspQ Gen:", evtq->gen);
  2655. seq_printf(seq, "%-12s %16u\n", "Intr delay:",
  2656. qtimer_val(adap, evtq));
  2657. seq_printf(seq, "%-12s %16u\n", "Intr pktcnt:",
  2658. s->counter_val[evtq->pktcnt_idx]);
  2659. goto unlock;
  2660. }
  2661. unlock:
  2662. mutex_unlock(&uld_mutex);
  2663. #undef R
  2664. #undef RL
  2665. #undef T
  2666. #undef TL
  2667. #undef S
  2668. #undef R3
  2669. #undef T3
  2670. #undef S3
  2671. return 0;
  2672. }
  2673. static int sge_queue_entries(const struct adapter *adap)
  2674. {
  2675. int tot_uld_entries = 0;
  2676. int i;
  2677. if (!is_uld(adap))
  2678. goto lld_only;
  2679. mutex_lock(&uld_mutex);
  2680. for (i = 0; i < CXGB4_TX_MAX; i++)
  2681. tot_uld_entries += sge_qinfo_uld_txq_entries(adap, i);
  2682. for (i = 0; i < CXGB4_ULD_MAX; i++) {
  2683. tot_uld_entries += sge_qinfo_uld_rxq_entries(adap, i);
  2684. tot_uld_entries += sge_qinfo_uld_ciq_entries(adap, i);
  2685. }
  2686. mutex_unlock(&uld_mutex);
  2687. lld_only:
  2688. return DIV_ROUND_UP(adap->sge.ethqsets, 4) +
  2689. (adap->sge.eohw_txq ? DIV_ROUND_UP(adap->sge.eoqsets, 4) : 0) +
  2690. tot_uld_entries +
  2691. DIV_ROUND_UP(MAX_CTRL_QUEUES, 4) + 1;
  2692. }
  2693. static void *sge_queue_start(struct seq_file *seq, loff_t *pos)
  2694. {
  2695. int entries = sge_queue_entries(seq->private);
  2696. return *pos < entries ? (void *)((uintptr_t)*pos + 1) : NULL;
  2697. }
  2698. static void sge_queue_stop(struct seq_file *seq, void *v)
  2699. {
  2700. }
  2701. static void *sge_queue_next(struct seq_file *seq, void *v, loff_t *pos)
  2702. {
  2703. int entries = sge_queue_entries(seq->private);
  2704. ++*pos;
  2705. return *pos < entries ? (void *)((uintptr_t)*pos + 1) : NULL;
  2706. }
  2707. static const struct seq_operations sge_qinfo_seq_ops = {
  2708. .start = sge_queue_start,
  2709. .next = sge_queue_next,
  2710. .stop = sge_queue_stop,
  2711. .show = sge_qinfo_show
  2712. };
  2713. static int sge_qinfo_open(struct inode *inode, struct file *file)
  2714. {
  2715. int res = seq_open(file, &sge_qinfo_seq_ops);
  2716. if (!res) {
  2717. struct seq_file *seq = file->private_data;
  2718. seq->private = inode->i_private;
  2719. }
  2720. return res;
  2721. }
  2722. static const struct file_operations sge_qinfo_debugfs_fops = {
  2723. .owner = THIS_MODULE,
  2724. .open = sge_qinfo_open,
  2725. .read = seq_read,
  2726. .llseek = seq_lseek,
  2727. .release = seq_release,
  2728. };
  2729. int mem_open(struct inode *inode, struct file *file)
  2730. {
  2731. unsigned int mem;
  2732. struct adapter *adap;
  2733. file->private_data = inode->i_private;
  2734. mem = (uintptr_t)file->private_data & 0x7;
  2735. adap = file->private_data - mem;
  2736. (void)t4_fwcache(adap, FW_PARAM_DEV_FWCACHE_FLUSH);
  2737. return 0;
  2738. }
  2739. static ssize_t mem_read(struct file *file, char __user *buf, size_t count,
  2740. loff_t *ppos)
  2741. {
  2742. loff_t pos = *ppos;
  2743. loff_t avail = file_inode(file)->i_size;
  2744. unsigned int mem = (uintptr_t)file->private_data & 0x7;
  2745. struct adapter *adap = file->private_data - mem;
  2746. __be32 *data;
  2747. int ret;
  2748. if (pos < 0)
  2749. return -EINVAL;
  2750. if (pos >= avail)
  2751. return 0;
  2752. if (count > avail - pos)
  2753. count = avail - pos;
  2754. data = kvzalloc(count, GFP_KERNEL);
  2755. if (!data)
  2756. return -ENOMEM;
  2757. spin_lock(&adap->win0_lock);
  2758. ret = t4_memory_rw(adap, 0, mem, pos, count, data, T4_MEMORY_READ);
  2759. spin_unlock(&adap->win0_lock);
  2760. if (ret) {
  2761. kvfree(data);
  2762. return ret;
  2763. }
  2764. ret = copy_to_user(buf, data, count);
  2765. kvfree(data);
  2766. if (ret)
  2767. return -EFAULT;
  2768. *ppos = pos + count;
  2769. return count;
  2770. }
  2771. static const struct file_operations mem_debugfs_fops = {
  2772. .owner = THIS_MODULE,
  2773. .open = simple_open,
  2774. .read = mem_read,
  2775. .llseek = default_llseek,
  2776. };
  2777. static int tid_info_show(struct seq_file *seq, void *v)
  2778. {
  2779. struct adapter *adap = seq->private;
  2780. const struct tid_info *t;
  2781. enum chip_type chip;
  2782. t = &adap->tids;
  2783. chip = CHELSIO_CHIP_VERSION(adap->params.chip);
  2784. if (t4_read_reg(adap, LE_DB_CONFIG_A) & HASHEN_F) {
  2785. unsigned int sb;
  2786. seq_printf(seq, "Connections in use: %u\n",
  2787. atomic_read(&t->conns_in_use));
  2788. if (chip <= CHELSIO_T5)
  2789. sb = t4_read_reg(adap, LE_DB_SERVER_INDEX_A) / 4;
  2790. else
  2791. sb = t4_read_reg(adap, LE_DB_SRVR_START_INDEX_A);
  2792. if (sb) {
  2793. seq_printf(seq, "TID range: %u..%u/%u..%u", t->tid_base,
  2794. sb - 1, adap->tids.hash_base,
  2795. t->tid_base + t->ntids - 1);
  2796. seq_printf(seq, ", in use: %u/%u\n",
  2797. atomic_read(&t->tids_in_use),
  2798. atomic_read(&t->hash_tids_in_use));
  2799. } else if (adap->flags & CXGB4_FW_OFLD_CONN) {
  2800. seq_printf(seq, "TID range: %u..%u/%u..%u",
  2801. t->aftid_base,
  2802. t->aftid_end,
  2803. adap->tids.hash_base,
  2804. t->tid_base + t->ntids - 1);
  2805. seq_printf(seq, ", in use: %u/%u\n",
  2806. atomic_read(&t->tids_in_use),
  2807. atomic_read(&t->hash_tids_in_use));
  2808. } else {
  2809. seq_printf(seq, "TID range: %u..%u",
  2810. adap->tids.hash_base,
  2811. t->tid_base + t->ntids - 1);
  2812. seq_printf(seq, ", in use: %u\n",
  2813. atomic_read(&t->hash_tids_in_use));
  2814. }
  2815. } else if (t->ntids) {
  2816. seq_printf(seq, "Connections in use: %u\n",
  2817. atomic_read(&t->conns_in_use));
  2818. seq_printf(seq, "TID range: %u..%u", t->tid_base,
  2819. t->tid_base + t->ntids - 1);
  2820. seq_printf(seq, ", in use: %u\n",
  2821. atomic_read(&t->tids_in_use));
  2822. }
  2823. if (t->nstids)
  2824. seq_printf(seq, "STID range: %u..%u, in use-IPv4/IPv6: %u/%u\n",
  2825. (!t->stid_base &&
  2826. (chip <= CHELSIO_T5)) ?
  2827. t->stid_base + 1 : t->stid_base,
  2828. t->stid_base + t->nstids - 1,
  2829. t->stids_in_use - t->v6_stids_in_use,
  2830. t->v6_stids_in_use);
  2831. if (t->natids)
  2832. seq_printf(seq, "ATID range: 0..%u, in use: %u\n",
  2833. t->natids - 1, t->atids_in_use);
  2834. seq_printf(seq, "FTID range: %u..%u\n", t->ftid_base,
  2835. t->ftid_base + t->nftids - 1);
  2836. if (t->nsftids)
  2837. seq_printf(seq, "SFTID range: %u..%u in use: %u\n",
  2838. t->sftid_base, t->sftid_base + t->nsftids - 2,
  2839. t->sftids_in_use);
  2840. if (t->nhpftids)
  2841. seq_printf(seq, "HPFTID range: %u..%u\n", t->hpftid_base,
  2842. t->hpftid_base + t->nhpftids - 1);
  2843. if (t->ntids)
  2844. seq_printf(seq, "HW TID usage: %u IP users, %u IPv6 users\n",
  2845. t4_read_reg(adap, LE_DB_ACT_CNT_IPV4_A),
  2846. t4_read_reg(adap, LE_DB_ACT_CNT_IPV6_A));
  2847. return 0;
  2848. }
  2849. DEFINE_SHOW_ATTRIBUTE(tid_info);
  2850. static void add_debugfs_mem(struct adapter *adap, const char *name,
  2851. unsigned int idx, unsigned int size_mb)
  2852. {
  2853. debugfs_create_file_size(name, 0400, adap->debugfs_root,
  2854. (void *)adap + idx, &mem_debugfs_fops,
  2855. size_mb << 20);
  2856. }
  2857. static ssize_t blocked_fl_read(struct file *filp, char __user *ubuf,
  2858. size_t count, loff_t *ppos)
  2859. {
  2860. int len;
  2861. const struct adapter *adap = filp->private_data;
  2862. char *buf;
  2863. ssize_t size = (adap->sge.egr_sz + 3) / 4 +
  2864. adap->sge.egr_sz / 32 + 2; /* includes ,/\n/\0 */
  2865. buf = kzalloc(size, GFP_KERNEL);
  2866. if (!buf)
  2867. return -ENOMEM;
  2868. len = snprintf(buf, size - 1, "%*pb\n",
  2869. adap->sge.egr_sz, adap->sge.blocked_fl);
  2870. len += sprintf(buf + len, "\n");
  2871. size = simple_read_from_buffer(ubuf, count, ppos, buf, len);
  2872. kvfree(buf);
  2873. return size;
  2874. }
  2875. static ssize_t blocked_fl_write(struct file *filp, const char __user *ubuf,
  2876. size_t count, loff_t *ppos)
  2877. {
  2878. int err;
  2879. unsigned long *t;
  2880. struct adapter *adap = filp->private_data;
  2881. t = kcalloc(BITS_TO_LONGS(adap->sge.egr_sz), sizeof(long), GFP_KERNEL);
  2882. if (!t)
  2883. return -ENOMEM;
  2884. err = bitmap_parse_user(ubuf, count, t, adap->sge.egr_sz);
  2885. if (err) {
  2886. kvfree(t);
  2887. return err;
  2888. }
  2889. bitmap_copy(adap->sge.blocked_fl, t, adap->sge.egr_sz);
  2890. kvfree(t);
  2891. return count;
  2892. }
  2893. static const struct file_operations blocked_fl_fops = {
  2894. .owner = THIS_MODULE,
  2895. .open = simple_open,
  2896. .read = blocked_fl_read,
  2897. .write = blocked_fl_write,
  2898. .llseek = generic_file_llseek,
  2899. };
  2900. static void mem_region_show(struct seq_file *seq, const char *name,
  2901. unsigned int from, unsigned int to)
  2902. {
  2903. char buf[40];
  2904. string_get_size((u64)to - from + 1, 1, STRING_UNITS_2, buf,
  2905. sizeof(buf));
  2906. seq_printf(seq, "%-15s %#x-%#x [%s]\n", name, from, to, buf);
  2907. }
  2908. static int meminfo_show(struct seq_file *seq, void *v)
  2909. {
  2910. static const char * const memory[] = { "EDC0:", "EDC1:", "MC:",
  2911. "MC0:", "MC1:", "HMA:"};
  2912. struct adapter *adap = seq->private;
  2913. struct cudbg_meminfo meminfo;
  2914. int i, rc;
  2915. memset(&meminfo, 0, sizeof(struct cudbg_meminfo));
  2916. rc = cudbg_fill_meminfo(adap, &meminfo);
  2917. if (rc)
  2918. return -ENXIO;
  2919. for (i = 0; i < meminfo.avail_c; i++)
  2920. mem_region_show(seq, memory[meminfo.avail[i].idx],
  2921. meminfo.avail[i].base,
  2922. meminfo.avail[i].limit - 1);
  2923. seq_putc(seq, '\n');
  2924. for (i = 0; i < meminfo.mem_c; i++) {
  2925. if (meminfo.mem[i].idx >= ARRAY_SIZE(cudbg_region))
  2926. continue; /* skip holes */
  2927. if (!meminfo.mem[i].limit)
  2928. meminfo.mem[i].limit =
  2929. i < meminfo.mem_c - 1 ?
  2930. meminfo.mem[i + 1].base - 1 : ~0;
  2931. mem_region_show(seq, cudbg_region[meminfo.mem[i].idx],
  2932. meminfo.mem[i].base, meminfo.mem[i].limit);
  2933. }
  2934. seq_putc(seq, '\n');
  2935. mem_region_show(seq, "uP RAM:", meminfo.up_ram_lo, meminfo.up_ram_hi);
  2936. mem_region_show(seq, "uP Extmem2:", meminfo.up_extmem2_lo,
  2937. meminfo.up_extmem2_hi);
  2938. seq_printf(seq, "\n%u Rx pages (%u free) of size %uKiB for %u channels\n",
  2939. meminfo.rx_pages_data[0], meminfo.free_rx_cnt,
  2940. meminfo.rx_pages_data[1], meminfo.rx_pages_data[2]);
  2941. seq_printf(seq, "%u Tx pages (%u free) of size %u%ciB for %u channels\n",
  2942. meminfo.tx_pages_data[0], meminfo.free_tx_cnt,
  2943. meminfo.tx_pages_data[1], meminfo.tx_pages_data[2],
  2944. meminfo.tx_pages_data[3]);
  2945. seq_printf(seq, "%u p-structs (%u free)\n\n",
  2946. meminfo.p_structs, meminfo.p_structs_free_cnt);
  2947. for (i = 0; i < 4; i++)
  2948. /* For T6 these are MAC buffer groups */
  2949. seq_printf(seq, "Port %d using %u pages out of %u allocated\n",
  2950. i, meminfo.port_used[i], meminfo.port_alloc[i]);
  2951. for (i = 0; i < adap->params.arch.nchan; i++)
  2952. /* For T6 these are MAC buffer groups */
  2953. seq_printf(seq,
  2954. "Loopback %d using %u pages out of %u allocated\n",
  2955. i, meminfo.loopback_used[i],
  2956. meminfo.loopback_alloc[i]);
  2957. return 0;
  2958. }
  2959. DEFINE_SHOW_ATTRIBUTE(meminfo);
  2960. static int chcr_stats_show(struct seq_file *seq, void *v)
  2961. {
  2962. struct adapter *adap = seq->private;
  2963. seq_puts(seq, "Chelsio Crypto Accelerator Stats \n");
  2964. seq_printf(seq, "Cipher Ops: %10u \n",
  2965. atomic_read(&adap->chcr_stats.cipher_rqst));
  2966. seq_printf(seq, "Digest Ops: %10u \n",
  2967. atomic_read(&adap->chcr_stats.digest_rqst));
  2968. seq_printf(seq, "Aead Ops: %10u \n",
  2969. atomic_read(&adap->chcr_stats.aead_rqst));
  2970. seq_printf(seq, "Completion: %10u \n",
  2971. atomic_read(&adap->chcr_stats.complete));
  2972. seq_printf(seq, "Error: %10u \n",
  2973. atomic_read(&adap->chcr_stats.error));
  2974. seq_printf(seq, "Fallback: %10u \n",
  2975. atomic_read(&adap->chcr_stats.fallback));
  2976. seq_printf(seq, "IPSec PDU: %10u\n",
  2977. atomic_read(&adap->chcr_stats.ipsec_cnt));
  2978. seq_printf(seq, "TLS PDU Tx: %10u\n",
  2979. atomic_read(&adap->chcr_stats.tls_pdu_tx));
  2980. seq_printf(seq, "TLS PDU Rx: %10u\n",
  2981. atomic_read(&adap->chcr_stats.tls_pdu_rx));
  2982. seq_printf(seq, "TLS Keys (DDR) Count: %10u\n",
  2983. atomic_read(&adap->chcr_stats.tls_key));
  2984. #ifdef CONFIG_CHELSIO_TLS_DEVICE
  2985. seq_puts(seq, "\nChelsio KTLS Crypto Accelerator Stats\n");
  2986. seq_printf(seq, "Tx HW offload contexts added: %20llu\n",
  2987. atomic64_read(&adap->chcr_stats.ktls_tx_ctx));
  2988. seq_printf(seq, "Tx connection created: %20llu\n",
  2989. atomic64_read(&adap->chcr_stats.ktls_tx_connection_open));
  2990. seq_printf(seq, "Tx connection failed: %20llu\n",
  2991. atomic64_read(&adap->chcr_stats.ktls_tx_connection_fail));
  2992. seq_printf(seq, "Tx connection closed: %20llu\n",
  2993. atomic64_read(&adap->chcr_stats.ktls_tx_connection_close));
  2994. seq_printf(seq, "Packets passed for encryption : %20llu\n",
  2995. atomic64_read(&adap->chcr_stats.ktls_tx_encrypted_packets));
  2996. seq_printf(seq, "Bytes passed for encryption : %20llu\n",
  2997. atomic64_read(&adap->chcr_stats.ktls_tx_encrypted_bytes));
  2998. seq_printf(seq, "Tx records send: %20llu\n",
  2999. atomic64_read(&adap->chcr_stats.ktls_tx_send_records));
  3000. seq_printf(seq, "Tx partial start of records: %20llu\n",
  3001. atomic64_read(&adap->chcr_stats.ktls_tx_start_pkts));
  3002. seq_printf(seq, "Tx partial middle of records: %20llu\n",
  3003. atomic64_read(&adap->chcr_stats.ktls_tx_middle_pkts));
  3004. seq_printf(seq, "Tx partial end of record: %20llu\n",
  3005. atomic64_read(&adap->chcr_stats.ktls_tx_end_pkts));
  3006. seq_printf(seq, "Tx complete records: %20llu\n",
  3007. atomic64_read(&adap->chcr_stats.ktls_tx_complete_pkts));
  3008. seq_printf(seq, "TX trim pkts : %20llu\n",
  3009. atomic64_read(&adap->chcr_stats.ktls_tx_trimmed_pkts));
  3010. seq_printf(seq, "Tx out of order packets: %20llu\n",
  3011. atomic64_read(&adap->chcr_stats.ktls_tx_ooo));
  3012. seq_printf(seq, "Tx drop pkts before HW offload: %20llu\n",
  3013. atomic64_read(&adap->chcr_stats.ktls_tx_skip_no_sync_data));
  3014. seq_printf(seq, "Tx drop not synced packets: %20llu\n",
  3015. atomic64_read(&adap->chcr_stats.ktls_tx_drop_no_sync_data));
  3016. seq_printf(seq, "Tx drop bypass req: %20llu\n",
  3017. atomic64_read(&adap->chcr_stats.ktls_tx_drop_bypass_req));
  3018. #endif
  3019. return 0;
  3020. }
  3021. DEFINE_SHOW_ATTRIBUTE(chcr_stats);
  3022. #define PRINT_ADAP_STATS(string, value) \
  3023. seq_printf(seq, "%-25s %-20llu\n", (string), \
  3024. (unsigned long long)(value))
  3025. #define PRINT_CH_STATS(string, value) \
  3026. do { \
  3027. seq_printf(seq, "%-25s ", (string)); \
  3028. for (i = 0; i < adap->params.arch.nchan; i++) \
  3029. seq_printf(seq, "%-20llu ", \
  3030. (unsigned long long)stats.value[i]); \
  3031. seq_printf(seq, "\n"); \
  3032. } while (0)
  3033. #define PRINT_CH_STATS2(string, value) \
  3034. do { \
  3035. seq_printf(seq, "%-25s ", (string)); \
  3036. for (i = 0; i < adap->params.arch.nchan; i++) \
  3037. seq_printf(seq, "%-20llu ", \
  3038. (unsigned long long)stats[i].value); \
  3039. seq_printf(seq, "\n"); \
  3040. } while (0)
  3041. static void show_tcp_stats(struct seq_file *seq)
  3042. {
  3043. struct adapter *adap = seq->private;
  3044. struct tp_tcp_stats v4, v6;
  3045. spin_lock(&adap->stats_lock);
  3046. t4_tp_get_tcp_stats(adap, &v4, &v6, false);
  3047. spin_unlock(&adap->stats_lock);
  3048. PRINT_ADAP_STATS("tcp_ipv4_out_rsts:", v4.tcp_out_rsts);
  3049. PRINT_ADAP_STATS("tcp_ipv4_in_segs:", v4.tcp_in_segs);
  3050. PRINT_ADAP_STATS("tcp_ipv4_out_segs:", v4.tcp_out_segs);
  3051. PRINT_ADAP_STATS("tcp_ipv4_retrans_segs:", v4.tcp_retrans_segs);
  3052. PRINT_ADAP_STATS("tcp_ipv6_out_rsts:", v6.tcp_out_rsts);
  3053. PRINT_ADAP_STATS("tcp_ipv6_in_segs:", v6.tcp_in_segs);
  3054. PRINT_ADAP_STATS("tcp_ipv6_out_segs:", v6.tcp_out_segs);
  3055. PRINT_ADAP_STATS("tcp_ipv6_retrans_segs:", v6.tcp_retrans_segs);
  3056. }
  3057. static void show_ddp_stats(struct seq_file *seq)
  3058. {
  3059. struct adapter *adap = seq->private;
  3060. struct tp_usm_stats stats;
  3061. spin_lock(&adap->stats_lock);
  3062. t4_get_usm_stats(adap, &stats, false);
  3063. spin_unlock(&adap->stats_lock);
  3064. PRINT_ADAP_STATS("usm_ddp_frames:", stats.frames);
  3065. PRINT_ADAP_STATS("usm_ddp_octets:", stats.octets);
  3066. PRINT_ADAP_STATS("usm_ddp_drops:", stats.drops);
  3067. }
  3068. static void show_rdma_stats(struct seq_file *seq)
  3069. {
  3070. struct adapter *adap = seq->private;
  3071. struct tp_rdma_stats stats;
  3072. spin_lock(&adap->stats_lock);
  3073. t4_tp_get_rdma_stats(adap, &stats, false);
  3074. spin_unlock(&adap->stats_lock);
  3075. PRINT_ADAP_STATS("rdma_no_rqe_mod_defer:", stats.rqe_dfr_mod);
  3076. PRINT_ADAP_STATS("rdma_no_rqe_pkt_defer:", stats.rqe_dfr_pkt);
  3077. }
  3078. static void show_tp_err_adapter_stats(struct seq_file *seq)
  3079. {
  3080. struct adapter *adap = seq->private;
  3081. struct tp_err_stats stats;
  3082. spin_lock(&adap->stats_lock);
  3083. t4_tp_get_err_stats(adap, &stats, false);
  3084. spin_unlock(&adap->stats_lock);
  3085. PRINT_ADAP_STATS("tp_err_ofld_no_neigh:", stats.ofld_no_neigh);
  3086. PRINT_ADAP_STATS("tp_err_ofld_cong_defer:", stats.ofld_cong_defer);
  3087. }
  3088. static void show_cpl_stats(struct seq_file *seq)
  3089. {
  3090. struct adapter *adap = seq->private;
  3091. struct tp_cpl_stats stats;
  3092. u8 i;
  3093. spin_lock(&adap->stats_lock);
  3094. t4_tp_get_cpl_stats(adap, &stats, false);
  3095. spin_unlock(&adap->stats_lock);
  3096. PRINT_CH_STATS("tp_cpl_requests:", req);
  3097. PRINT_CH_STATS("tp_cpl_responses:", rsp);
  3098. }
  3099. static void show_tp_err_channel_stats(struct seq_file *seq)
  3100. {
  3101. struct adapter *adap = seq->private;
  3102. struct tp_err_stats stats;
  3103. u8 i;
  3104. spin_lock(&adap->stats_lock);
  3105. t4_tp_get_err_stats(adap, &stats, false);
  3106. spin_unlock(&adap->stats_lock);
  3107. PRINT_CH_STATS("tp_mac_in_errs:", mac_in_errs);
  3108. PRINT_CH_STATS("tp_hdr_in_errs:", hdr_in_errs);
  3109. PRINT_CH_STATS("tp_tcp_in_errs:", tcp_in_errs);
  3110. PRINT_CH_STATS("tp_tcp6_in_errs:", tcp6_in_errs);
  3111. PRINT_CH_STATS("tp_tnl_cong_drops:", tnl_cong_drops);
  3112. PRINT_CH_STATS("tp_tnl_tx_drops:", tnl_tx_drops);
  3113. PRINT_CH_STATS("tp_ofld_vlan_drops:", ofld_vlan_drops);
  3114. PRINT_CH_STATS("tp_ofld_chan_drops:", ofld_chan_drops);
  3115. }
  3116. static void show_fcoe_stats(struct seq_file *seq)
  3117. {
  3118. struct adapter *adap = seq->private;
  3119. struct tp_fcoe_stats stats[NCHAN];
  3120. u8 i;
  3121. spin_lock(&adap->stats_lock);
  3122. for (i = 0; i < adap->params.arch.nchan; i++)
  3123. t4_get_fcoe_stats(adap, i, &stats[i], false);
  3124. spin_unlock(&adap->stats_lock);
  3125. PRINT_CH_STATS2("fcoe_octets_ddp", octets_ddp);
  3126. PRINT_CH_STATS2("fcoe_frames_ddp", frames_ddp);
  3127. PRINT_CH_STATS2("fcoe_frames_drop", frames_drop);
  3128. }
  3129. #undef PRINT_CH_STATS2
  3130. #undef PRINT_CH_STATS
  3131. #undef PRINT_ADAP_STATS
  3132. static int tp_stats_show(struct seq_file *seq, void *v)
  3133. {
  3134. struct adapter *adap = seq->private;
  3135. seq_puts(seq, "\n--------Adapter Stats--------\n");
  3136. show_tcp_stats(seq);
  3137. show_ddp_stats(seq);
  3138. show_rdma_stats(seq);
  3139. show_tp_err_adapter_stats(seq);
  3140. seq_puts(seq, "\n-------- Channel Stats --------\n");
  3141. if (adap->params.arch.nchan == NCHAN)
  3142. seq_printf(seq, "%-25s %-20s %-20s %-20s %-20s\n",
  3143. " ", "channel 0", "channel 1",
  3144. "channel 2", "channel 3");
  3145. else
  3146. seq_printf(seq, "%-25s %-20s %-20s\n",
  3147. " ", "channel 0", "channel 1");
  3148. show_cpl_stats(seq);
  3149. show_tp_err_channel_stats(seq);
  3150. show_fcoe_stats(seq);
  3151. return 0;
  3152. }
  3153. DEFINE_SHOW_ATTRIBUTE(tp_stats);
  3154. /* Add an array of Debug FS files.
  3155. */
  3156. void add_debugfs_files(struct adapter *adap,
  3157. struct t4_debugfs_entry *files,
  3158. unsigned int nfiles)
  3159. {
  3160. int i;
  3161. /* debugfs support is best effort */
  3162. for (i = 0; i < nfiles; i++)
  3163. debugfs_create_file(files[i].name, files[i].mode,
  3164. adap->debugfs_root,
  3165. (void *)adap + files[i].data,
  3166. files[i].ops);
  3167. }
  3168. int t4_setup_debugfs(struct adapter *adap)
  3169. {
  3170. int i;
  3171. u32 size = 0;
  3172. static struct t4_debugfs_entry t4_debugfs_files[] = {
  3173. { "cim_la", &cim_la_fops, 0400, 0 },
  3174. { "cim_pif_la", &cim_pif_la_fops, 0400, 0 },
  3175. { "cim_ma_la", &cim_ma_la_fops, 0400, 0 },
  3176. { "cim_qcfg", &cim_qcfg_fops, 0400, 0 },
  3177. { "clk", &clk_fops, 0400, 0 },
  3178. { "devlog", &devlog_fops, 0400, 0 },
  3179. { "mboxlog", &mboxlog_fops, 0400, 0 },
  3180. { "mbox0", &mbox_debugfs_fops, 0600, 0 },
  3181. { "mbox1", &mbox_debugfs_fops, 0600, 1 },
  3182. { "mbox2", &mbox_debugfs_fops, 0600, 2 },
  3183. { "mbox3", &mbox_debugfs_fops, 0600, 3 },
  3184. { "mbox4", &mbox_debugfs_fops, 0600, 4 },
  3185. { "mbox5", &mbox_debugfs_fops, 0600, 5 },
  3186. { "mbox6", &mbox_debugfs_fops, 0600, 6 },
  3187. { "mbox7", &mbox_debugfs_fops, 0600, 7 },
  3188. { "trace0", &mps_trc_debugfs_fops, 0600, 0 },
  3189. { "trace1", &mps_trc_debugfs_fops, 0600, 1 },
  3190. { "trace2", &mps_trc_debugfs_fops, 0600, 2 },
  3191. { "trace3", &mps_trc_debugfs_fops, 0600, 3 },
  3192. { "l2t", &t4_l2t_fops, 0400, 0},
  3193. { "mps_tcam", &mps_tcam_debugfs_fops, 0400, 0 },
  3194. { "rss", &rss_debugfs_fops, 0400, 0 },
  3195. { "rss_config", &rss_config_fops, 0400, 0 },
  3196. { "rss_key", &rss_key_debugfs_fops, 0400, 0 },
  3197. { "rss_pf_config", &rss_pf_config_debugfs_fops, 0400, 0 },
  3198. { "rss_vf_config", &rss_vf_config_debugfs_fops, 0400, 0 },
  3199. { "resources", &resources_fops, 0400, 0 },
  3200. #ifdef CONFIG_CHELSIO_T4_DCB
  3201. { "dcb_info", &dcb_info_debugfs_fops, 0400, 0 },
  3202. #endif
  3203. { "sge_qinfo", &sge_qinfo_debugfs_fops, 0400, 0 },
  3204. { "ibq_tp0", &cim_ibq_fops, 0400, 0 },
  3205. { "ibq_tp1", &cim_ibq_fops, 0400, 1 },
  3206. { "ibq_ulp", &cim_ibq_fops, 0400, 2 },
  3207. { "ibq_sge0", &cim_ibq_fops, 0400, 3 },
  3208. { "ibq_sge1", &cim_ibq_fops, 0400, 4 },
  3209. { "ibq_ncsi", &cim_ibq_fops, 0400, 5 },
  3210. { "obq_ulp0", &cim_obq_fops, 0400, 0 },
  3211. { "obq_ulp1", &cim_obq_fops, 0400, 1 },
  3212. { "obq_ulp2", &cim_obq_fops, 0400, 2 },
  3213. { "obq_ulp3", &cim_obq_fops, 0400, 3 },
  3214. { "obq_sge", &cim_obq_fops, 0400, 4 },
  3215. { "obq_ncsi", &cim_obq_fops, 0400, 5 },
  3216. { "tp_la", &tp_la_fops, 0400, 0 },
  3217. { "ulprx_la", &ulprx_la_fops, 0400, 0 },
  3218. { "sensors", &sensors_fops, 0400, 0 },
  3219. { "pm_stats", &pm_stats_debugfs_fops, 0400, 0 },
  3220. { "tx_rate", &tx_rate_fops, 0400, 0 },
  3221. { "cctrl", &cctrl_tbl_fops, 0400, 0 },
  3222. #if IS_ENABLED(CONFIG_IPV6)
  3223. { "clip_tbl", &clip_tbl_fops, 0400, 0 },
  3224. #endif
  3225. { "tids", &tid_info_fops, 0400, 0},
  3226. { "blocked_fl", &blocked_fl_fops, 0600, 0 },
  3227. { "meminfo", &meminfo_fops, 0400, 0 },
  3228. { "crypto", &chcr_stats_fops, 0400, 0 },
  3229. { "tp_stats", &tp_stats_fops, 0400, 0 },
  3230. };
  3231. /* Debug FS nodes common to all T5 and later adapters.
  3232. */
  3233. static struct t4_debugfs_entry t5_debugfs_files[] = {
  3234. { "obq_sge_rx_q0", &cim_obq_fops, 0400, 6 },
  3235. { "obq_sge_rx_q1", &cim_obq_fops, 0400, 7 },
  3236. };
  3237. add_debugfs_files(adap,
  3238. t4_debugfs_files,
  3239. ARRAY_SIZE(t4_debugfs_files));
  3240. if (!is_t4(adap->params.chip))
  3241. add_debugfs_files(adap,
  3242. t5_debugfs_files,
  3243. ARRAY_SIZE(t5_debugfs_files));
  3244. i = t4_read_reg(adap, MA_TARGET_MEM_ENABLE_A);
  3245. if (i & EDRAM0_ENABLE_F) {
  3246. size = t4_read_reg(adap, MA_EDRAM0_BAR_A);
  3247. add_debugfs_mem(adap, "edc0", MEM_EDC0, EDRAM0_SIZE_G(size));
  3248. }
  3249. if (i & EDRAM1_ENABLE_F) {
  3250. size = t4_read_reg(adap, MA_EDRAM1_BAR_A);
  3251. add_debugfs_mem(adap, "edc1", MEM_EDC1, EDRAM1_SIZE_G(size));
  3252. }
  3253. if (is_t5(adap->params.chip)) {
  3254. if (i & EXT_MEM0_ENABLE_F) {
  3255. size = t4_read_reg(adap, MA_EXT_MEMORY0_BAR_A);
  3256. add_debugfs_mem(adap, "mc0", MEM_MC0,
  3257. EXT_MEM0_SIZE_G(size));
  3258. }
  3259. if (i & EXT_MEM1_ENABLE_F) {
  3260. size = t4_read_reg(adap, MA_EXT_MEMORY1_BAR_A);
  3261. add_debugfs_mem(adap, "mc1", MEM_MC1,
  3262. EXT_MEM1_SIZE_G(size));
  3263. }
  3264. } else {
  3265. if (i & EXT_MEM_ENABLE_F) {
  3266. size = t4_read_reg(adap, MA_EXT_MEMORY_BAR_A);
  3267. add_debugfs_mem(adap, "mc", MEM_MC,
  3268. EXT_MEM_SIZE_G(size));
  3269. }
  3270. if (i & HMA_MUX_F) {
  3271. size = t4_read_reg(adap, MA_EXT_MEMORY1_BAR_A);
  3272. add_debugfs_mem(adap, "hma", MEM_HMA,
  3273. EXT_MEM1_SIZE_G(size));
  3274. }
  3275. }
  3276. debugfs_create_file_size("flash", 0400, adap->debugfs_root, adap,
  3277. &flash_debugfs_fops, adap->params.sf_size);
  3278. debugfs_create_bool("use_backdoor", 0600,
  3279. adap->debugfs_root, &adap->use_bd);
  3280. debugfs_create_bool("trace_rss", 0600,
  3281. adap->debugfs_root, &adap->trace_rss);
  3282. return 0;
  3283. }