Hariprasad Shenai | fd88b31 | 2014-11-07 09:35:23 +0530 | [diff] [blame] | 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 | |
| 35 | #include <linux/seq_file.h> |
| 36 | #include <linux/debugfs.h> |
| 37 | #include <linux/string_helpers.h> |
| 38 | #include <linux/sort.h> |
| 39 | |
| 40 | #include "cxgb4.h" |
| 41 | #include "t4_regs.h" |
| 42 | #include "t4fw_api.h" |
| 43 | #include "cxgb4_debugfs.h" |
Anish Bhatt | b5a02f5 | 2015-01-14 15:17:34 -0800 | [diff] [blame^] | 44 | #include "clip_tbl.h" |
Hariprasad Shenai | fd88b31 | 2014-11-07 09:35:23 +0530 | [diff] [blame] | 45 | #include "l2t.h" |
| 46 | |
Hariprasad Shenai | f1ff24a | 2015-01-07 08:48:01 +0530 | [diff] [blame] | 47 | /* generic seq_file support for showing a table of size rows x width. */ |
| 48 | static void *seq_tab_get_idx(struct seq_tab *tb, loff_t pos) |
| 49 | { |
| 50 | pos -= tb->skip_first; |
| 51 | return pos >= tb->rows ? NULL : &tb->data[pos * tb->width]; |
| 52 | } |
| 53 | |
| 54 | static void *seq_tab_start(struct seq_file *seq, loff_t *pos) |
| 55 | { |
| 56 | struct seq_tab *tb = seq->private; |
| 57 | |
| 58 | if (tb->skip_first && *pos == 0) |
| 59 | return SEQ_START_TOKEN; |
| 60 | |
| 61 | return seq_tab_get_idx(tb, *pos); |
| 62 | } |
| 63 | |
| 64 | static void *seq_tab_next(struct seq_file *seq, void *v, loff_t *pos) |
| 65 | { |
| 66 | v = seq_tab_get_idx(seq->private, *pos + 1); |
| 67 | if (v) |
| 68 | ++*pos; |
| 69 | return v; |
| 70 | } |
| 71 | |
| 72 | static void seq_tab_stop(struct seq_file *seq, void *v) |
| 73 | { |
| 74 | } |
| 75 | |
| 76 | static int seq_tab_show(struct seq_file *seq, void *v) |
| 77 | { |
| 78 | const struct seq_tab *tb = seq->private; |
| 79 | |
| 80 | return tb->show(seq, v, ((char *)v - tb->data) / tb->width); |
| 81 | } |
| 82 | |
| 83 | static const struct seq_operations seq_tab_ops = { |
| 84 | .start = seq_tab_start, |
| 85 | .next = seq_tab_next, |
| 86 | .stop = seq_tab_stop, |
| 87 | .show = seq_tab_show |
| 88 | }; |
| 89 | |
| 90 | struct seq_tab *seq_open_tab(struct file *f, unsigned int rows, |
| 91 | unsigned int width, unsigned int have_header, |
| 92 | int (*show)(struct seq_file *seq, void *v, int i)) |
| 93 | { |
| 94 | struct seq_tab *p; |
| 95 | |
| 96 | p = __seq_open_private(f, &seq_tab_ops, sizeof(*p) + rows * width); |
| 97 | if (p) { |
| 98 | p->show = show; |
| 99 | p->rows = rows; |
| 100 | p->width = width; |
| 101 | p->skip_first = have_header != 0; |
| 102 | } |
| 103 | return p; |
| 104 | } |
| 105 | |
| 106 | static int cim_la_show(struct seq_file *seq, void *v, int idx) |
| 107 | { |
| 108 | if (v == SEQ_START_TOKEN) |
| 109 | seq_puts(seq, "Status Data PC LS0Stat LS0Addr " |
| 110 | " LS0Data\n"); |
| 111 | else { |
| 112 | const u32 *p = v; |
| 113 | |
| 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 | |
| 123 | static int cim_la_show_3in1(struct seq_file *seq, void *v, int idx) |
| 124 | { |
| 125 | if (v == SEQ_START_TOKEN) { |
| 126 | seq_puts(seq, "Status Data PC\n"); |
| 127 | } else { |
| 128 | const u32 *p = v; |
| 129 | |
| 130 | seq_printf(seq, " %02x %08x %08x\n", p[5] & 0xff, p[6], |
| 131 | p[7]); |
| 132 | seq_printf(seq, " %02x %02x%06x %02x%06x\n", |
| 133 | (p[3] >> 8) & 0xff, p[3] & 0xff, p[4] >> 8, |
| 134 | p[4] & 0xff, p[5] >> 8); |
| 135 | seq_printf(seq, " %02x %x%07x %x%07x\n", (p[0] >> 4) & 0xff, |
| 136 | p[0] & 0xf, p[1] >> 4, p[1] & 0xf, p[2] >> 4); |
| 137 | } |
| 138 | return 0; |
| 139 | } |
| 140 | |
| 141 | static int cim_la_open(struct inode *inode, struct file *file) |
| 142 | { |
| 143 | int ret; |
| 144 | unsigned int cfg; |
| 145 | struct seq_tab *p; |
| 146 | struct adapter *adap = inode->i_private; |
| 147 | |
| 148 | ret = t4_cim_read(adap, UP_UP_DBG_LA_CFG_A, 1, &cfg); |
| 149 | if (ret) |
| 150 | return ret; |
| 151 | |
| 152 | p = seq_open_tab(file, adap->params.cim_la_size / 8, 8 * sizeof(u32), 1, |
| 153 | cfg & UPDBGLACAPTPCONLY_F ? |
| 154 | cim_la_show_3in1 : cim_la_show); |
| 155 | if (!p) |
| 156 | return -ENOMEM; |
| 157 | |
| 158 | ret = t4_cim_read_la(adap, (u32 *)p->data, NULL); |
| 159 | if (ret) |
| 160 | seq_release_private(inode, file); |
| 161 | return ret; |
| 162 | } |
| 163 | |
| 164 | static const struct file_operations cim_la_fops = { |
| 165 | .owner = THIS_MODULE, |
| 166 | .open = cim_la_open, |
| 167 | .read = seq_read, |
| 168 | .llseek = seq_lseek, |
| 169 | .release = seq_release_private |
| 170 | }; |
| 171 | |
Hariprasad Shenai | 74b3092 | 2015-01-07 08:48:02 +0530 | [diff] [blame] | 172 | static int cim_qcfg_show(struct seq_file *seq, void *v) |
| 173 | { |
| 174 | static const char * const qname[] = { |
| 175 | "TP0", "TP1", "ULP", "SGE0", "SGE1", "NC-SI", |
| 176 | "ULP0", "ULP1", "ULP2", "ULP3", "SGE", "NC-SI", |
| 177 | "SGE0-RX", "SGE1-RX" |
| 178 | }; |
| 179 | |
| 180 | int i; |
| 181 | struct adapter *adap = seq->private; |
| 182 | u16 base[CIM_NUM_IBQ + CIM_NUM_OBQ_T5]; |
| 183 | u16 size[CIM_NUM_IBQ + CIM_NUM_OBQ_T5]; |
| 184 | u32 stat[(4 * (CIM_NUM_IBQ + CIM_NUM_OBQ_T5))]; |
| 185 | u16 thres[CIM_NUM_IBQ]; |
| 186 | u32 obq_wr_t4[2 * CIM_NUM_OBQ], *wr; |
| 187 | u32 obq_wr_t5[2 * CIM_NUM_OBQ_T5]; |
| 188 | u32 *p = stat; |
| 189 | int cim_num_obq = is_t4(adap->params.chip) ? |
| 190 | CIM_NUM_OBQ : CIM_NUM_OBQ_T5; |
| 191 | |
| 192 | i = t4_cim_read(adap, is_t4(adap->params.chip) ? UP_IBQ_0_RDADDR_A : |
| 193 | UP_IBQ_0_SHADOW_RDADDR_A, |
| 194 | ARRAY_SIZE(stat), stat); |
| 195 | if (!i) { |
| 196 | if (is_t4(adap->params.chip)) { |
| 197 | i = t4_cim_read(adap, UP_OBQ_0_REALADDR_A, |
| 198 | ARRAY_SIZE(obq_wr_t4), obq_wr_t4); |
| 199 | wr = obq_wr_t4; |
| 200 | } else { |
| 201 | i = t4_cim_read(adap, UP_OBQ_0_SHADOW_REALADDR_A, |
| 202 | ARRAY_SIZE(obq_wr_t5), obq_wr_t5); |
| 203 | wr = obq_wr_t5; |
| 204 | } |
| 205 | } |
| 206 | if (i) |
| 207 | return i; |
| 208 | |
| 209 | t4_read_cimq_cfg(adap, base, size, thres); |
| 210 | |
| 211 | seq_printf(seq, |
| 212 | " Queue Base Size Thres RdPtr WrPtr SOP EOP Avail\n"); |
| 213 | for (i = 0; i < CIM_NUM_IBQ; i++, p += 4) |
| 214 | seq_printf(seq, "%7s %5x %5u %5u %6x %4x %4u %4u %5u\n", |
| 215 | qname[i], base[i], size[i], thres[i], |
| 216 | IBQRDADDR_G(p[0]), IBQWRADDR_G(p[1]), |
| 217 | QUESOPCNT_G(p[3]), QUEEOPCNT_G(p[3]), |
| 218 | QUEREMFLITS_G(p[2]) * 16); |
| 219 | for ( ; i < CIM_NUM_IBQ + cim_num_obq; i++, p += 4, wr += 2) |
| 220 | seq_printf(seq, "%7s %5x %5u %12x %4x %4u %4u %5u\n", |
| 221 | qname[i], base[i], size[i], |
| 222 | QUERDADDR_G(p[0]) & 0x3fff, wr[0] - base[i], |
| 223 | QUESOPCNT_G(p[3]), QUEEOPCNT_G(p[3]), |
| 224 | QUEREMFLITS_G(p[2]) * 16); |
| 225 | return 0; |
| 226 | } |
| 227 | |
| 228 | static int cim_qcfg_open(struct inode *inode, struct file *file) |
| 229 | { |
| 230 | return single_open(file, cim_qcfg_show, inode->i_private); |
| 231 | } |
| 232 | |
| 233 | static const struct file_operations cim_qcfg_fops = { |
| 234 | .owner = THIS_MODULE, |
| 235 | .open = cim_qcfg_open, |
| 236 | .read = seq_read, |
| 237 | .llseek = seq_lseek, |
| 238 | .release = single_release, |
| 239 | }; |
| 240 | |
Hariprasad Shenai | f1ff24a | 2015-01-07 08:48:01 +0530 | [diff] [blame] | 241 | /* Firmware Device Log dump. */ |
Hariprasad Shenai | 49aa284 | 2015-01-07 08:48:00 +0530 | [diff] [blame] | 242 | static const char * const devlog_level_strings[] = { |
| 243 | [FW_DEVLOG_LEVEL_EMERG] = "EMERG", |
| 244 | [FW_DEVLOG_LEVEL_CRIT] = "CRIT", |
| 245 | [FW_DEVLOG_LEVEL_ERR] = "ERR", |
| 246 | [FW_DEVLOG_LEVEL_NOTICE] = "NOTICE", |
| 247 | [FW_DEVLOG_LEVEL_INFO] = "INFO", |
| 248 | [FW_DEVLOG_LEVEL_DEBUG] = "DEBUG" |
| 249 | }; |
| 250 | |
| 251 | static const char * const devlog_facility_strings[] = { |
| 252 | [FW_DEVLOG_FACILITY_CORE] = "CORE", |
| 253 | [FW_DEVLOG_FACILITY_SCHED] = "SCHED", |
| 254 | [FW_DEVLOG_FACILITY_TIMER] = "TIMER", |
| 255 | [FW_DEVLOG_FACILITY_RES] = "RES", |
| 256 | [FW_DEVLOG_FACILITY_HW] = "HW", |
| 257 | [FW_DEVLOG_FACILITY_FLR] = "FLR", |
| 258 | [FW_DEVLOG_FACILITY_DMAQ] = "DMAQ", |
| 259 | [FW_DEVLOG_FACILITY_PHY] = "PHY", |
| 260 | [FW_DEVLOG_FACILITY_MAC] = "MAC", |
| 261 | [FW_DEVLOG_FACILITY_PORT] = "PORT", |
| 262 | [FW_DEVLOG_FACILITY_VI] = "VI", |
| 263 | [FW_DEVLOG_FACILITY_FILTER] = "FILTER", |
| 264 | [FW_DEVLOG_FACILITY_ACL] = "ACL", |
| 265 | [FW_DEVLOG_FACILITY_TM] = "TM", |
| 266 | [FW_DEVLOG_FACILITY_QFC] = "QFC", |
| 267 | [FW_DEVLOG_FACILITY_DCB] = "DCB", |
| 268 | [FW_DEVLOG_FACILITY_ETH] = "ETH", |
| 269 | [FW_DEVLOG_FACILITY_OFLD] = "OFLD", |
| 270 | [FW_DEVLOG_FACILITY_RI] = "RI", |
| 271 | [FW_DEVLOG_FACILITY_ISCSI] = "ISCSI", |
| 272 | [FW_DEVLOG_FACILITY_FCOE] = "FCOE", |
| 273 | [FW_DEVLOG_FACILITY_FOISCSI] = "FOISCSI", |
| 274 | [FW_DEVLOG_FACILITY_FOFCOE] = "FOFCOE" |
| 275 | }; |
| 276 | |
| 277 | /* Information gathered by Device Log Open routine for the display routine. |
| 278 | */ |
| 279 | struct devlog_info { |
| 280 | unsigned int nentries; /* number of entries in log[] */ |
| 281 | unsigned int first; /* first [temporal] entry in log[] */ |
| 282 | struct fw_devlog_e log[0]; /* Firmware Device Log */ |
| 283 | }; |
| 284 | |
| 285 | /* Dump a Firmaware Device Log entry. |
| 286 | */ |
| 287 | static int devlog_show(struct seq_file *seq, void *v) |
| 288 | { |
| 289 | if (v == SEQ_START_TOKEN) |
| 290 | seq_printf(seq, "%10s %15s %8s %8s %s\n", |
| 291 | "Seq#", "Tstamp", "Level", "Facility", "Message"); |
| 292 | else { |
| 293 | struct devlog_info *dinfo = seq->private; |
| 294 | int fidx = (uintptr_t)v - 2; |
| 295 | unsigned long index; |
| 296 | struct fw_devlog_e *e; |
| 297 | |
| 298 | /* Get a pointer to the log entry to display. Skip unused log |
| 299 | * entries. |
| 300 | */ |
| 301 | index = dinfo->first + fidx; |
| 302 | if (index >= dinfo->nentries) |
| 303 | index -= dinfo->nentries; |
| 304 | e = &dinfo->log[index]; |
| 305 | if (e->timestamp == 0) |
| 306 | return 0; |
| 307 | |
| 308 | /* Print the message. This depends on the firmware using |
| 309 | * exactly the same formating strings as the kernel so we may |
| 310 | * eventually have to put a format interpreter in here ... |
| 311 | */ |
| 312 | seq_printf(seq, "%10d %15llu %8s %8s ", |
| 313 | e->seqno, e->timestamp, |
| 314 | (e->level < ARRAY_SIZE(devlog_level_strings) |
| 315 | ? devlog_level_strings[e->level] |
| 316 | : "UNKNOWN"), |
| 317 | (e->facility < ARRAY_SIZE(devlog_facility_strings) |
| 318 | ? devlog_facility_strings[e->facility] |
| 319 | : "UNKNOWN")); |
| 320 | seq_printf(seq, e->fmt, e->params[0], e->params[1], |
| 321 | e->params[2], e->params[3], e->params[4], |
| 322 | e->params[5], e->params[6], e->params[7]); |
| 323 | } |
| 324 | return 0; |
| 325 | } |
| 326 | |
| 327 | /* Sequential File Operations for Device Log. |
| 328 | */ |
| 329 | static inline void *devlog_get_idx(struct devlog_info *dinfo, loff_t pos) |
| 330 | { |
| 331 | if (pos > dinfo->nentries) |
| 332 | return NULL; |
| 333 | |
| 334 | return (void *)(uintptr_t)(pos + 1); |
| 335 | } |
| 336 | |
| 337 | static void *devlog_start(struct seq_file *seq, loff_t *pos) |
| 338 | { |
| 339 | struct devlog_info *dinfo = seq->private; |
| 340 | |
| 341 | return (*pos |
| 342 | ? devlog_get_idx(dinfo, *pos) |
| 343 | : SEQ_START_TOKEN); |
| 344 | } |
| 345 | |
| 346 | static void *devlog_next(struct seq_file *seq, void *v, loff_t *pos) |
| 347 | { |
| 348 | struct devlog_info *dinfo = seq->private; |
| 349 | |
| 350 | (*pos)++; |
| 351 | return devlog_get_idx(dinfo, *pos); |
| 352 | } |
| 353 | |
| 354 | static void devlog_stop(struct seq_file *seq, void *v) |
| 355 | { |
| 356 | } |
| 357 | |
| 358 | static const struct seq_operations devlog_seq_ops = { |
| 359 | .start = devlog_start, |
| 360 | .next = devlog_next, |
| 361 | .stop = devlog_stop, |
| 362 | .show = devlog_show |
| 363 | }; |
| 364 | |
| 365 | /* Set up for reading the firmware's device log. We read the entire log here |
| 366 | * and then display it incrementally in devlog_show(). |
| 367 | */ |
| 368 | static int devlog_open(struct inode *inode, struct file *file) |
| 369 | { |
| 370 | struct adapter *adap = inode->i_private; |
| 371 | struct devlog_params *dparams = &adap->params.devlog; |
| 372 | struct devlog_info *dinfo; |
| 373 | unsigned int index; |
| 374 | u32 fseqno; |
| 375 | int ret; |
| 376 | |
| 377 | /* If we don't know where the log is we can't do anything. |
| 378 | */ |
| 379 | if (dparams->start == 0) |
| 380 | return -ENXIO; |
| 381 | |
| 382 | /* Allocate the space to read in the firmware's device log and set up |
| 383 | * for the iterated call to our display function. |
| 384 | */ |
| 385 | dinfo = __seq_open_private(file, &devlog_seq_ops, |
| 386 | sizeof(*dinfo) + dparams->size); |
| 387 | if (!dinfo) |
| 388 | return -ENOMEM; |
| 389 | |
| 390 | /* Record the basic log buffer information and read in the raw log. |
| 391 | */ |
| 392 | dinfo->nentries = (dparams->size / sizeof(struct fw_devlog_e)); |
| 393 | dinfo->first = 0; |
| 394 | spin_lock(&adap->win0_lock); |
| 395 | ret = t4_memory_rw(adap, adap->params.drv_memwin, dparams->memtype, |
| 396 | dparams->start, dparams->size, (__be32 *)dinfo->log, |
| 397 | T4_MEMORY_READ); |
| 398 | spin_unlock(&adap->win0_lock); |
| 399 | if (ret) { |
| 400 | seq_release_private(inode, file); |
| 401 | return ret; |
| 402 | } |
| 403 | |
| 404 | /* Translate log multi-byte integral elements into host native format |
| 405 | * and determine where the first entry in the log is. |
| 406 | */ |
| 407 | for (fseqno = ~((u32)0), index = 0; index < dinfo->nentries; index++) { |
| 408 | struct fw_devlog_e *e = &dinfo->log[index]; |
| 409 | int i; |
| 410 | __u32 seqno; |
| 411 | |
| 412 | if (e->timestamp == 0) |
| 413 | continue; |
| 414 | |
| 415 | e->timestamp = (__force __be64)be64_to_cpu(e->timestamp); |
| 416 | seqno = be32_to_cpu(e->seqno); |
| 417 | for (i = 0; i < 8; i++) |
| 418 | e->params[i] = |
| 419 | (__force __be32)be32_to_cpu(e->params[i]); |
| 420 | |
| 421 | if (seqno < fseqno) { |
| 422 | fseqno = seqno; |
| 423 | dinfo->first = index; |
| 424 | } |
| 425 | } |
| 426 | return 0; |
| 427 | } |
| 428 | |
| 429 | static const struct file_operations devlog_fops = { |
| 430 | .owner = THIS_MODULE, |
| 431 | .open = devlog_open, |
| 432 | .read = seq_read, |
| 433 | .llseek = seq_lseek, |
| 434 | .release = seq_release_private |
| 435 | }; |
| 436 | |
Hariprasad Shenai | ef82f66 | 2015-01-07 08:48:03 +0530 | [diff] [blame] | 437 | static inline void tcamxy2valmask(u64 x, u64 y, u8 *addr, u64 *mask) |
| 438 | { |
| 439 | *mask = x | y; |
| 440 | y = (__force u64)cpu_to_be64(y); |
| 441 | memcpy(addr, (char *)&y + 2, ETH_ALEN); |
| 442 | } |
| 443 | |
| 444 | static int mps_tcam_show(struct seq_file *seq, void *v) |
| 445 | { |
| 446 | if (v == SEQ_START_TOKEN) |
| 447 | seq_puts(seq, "Idx Ethernet address Mask Vld Ports PF" |
| 448 | " VF Replication " |
| 449 | "P0 P1 P2 P3 ML\n"); |
| 450 | else { |
| 451 | u64 mask; |
| 452 | u8 addr[ETH_ALEN]; |
| 453 | struct adapter *adap = seq->private; |
| 454 | unsigned int idx = (uintptr_t)v - 2; |
| 455 | u64 tcamy = t4_read_reg64(adap, MPS_CLS_TCAM_Y_L(idx)); |
| 456 | u64 tcamx = t4_read_reg64(adap, MPS_CLS_TCAM_X_L(idx)); |
| 457 | u32 cls_lo = t4_read_reg(adap, MPS_CLS_SRAM_L(idx)); |
| 458 | u32 cls_hi = t4_read_reg(adap, MPS_CLS_SRAM_H(idx)); |
| 459 | u32 rplc[4] = {0, 0, 0, 0}; |
| 460 | |
| 461 | if (tcamx & tcamy) { |
| 462 | seq_printf(seq, "%3u -\n", idx); |
| 463 | goto out; |
| 464 | } |
| 465 | |
| 466 | if (cls_lo & REPLICATE_F) { |
| 467 | struct fw_ldst_cmd ldst_cmd; |
| 468 | int ret; |
| 469 | |
| 470 | memset(&ldst_cmd, 0, sizeof(ldst_cmd)); |
| 471 | ldst_cmd.op_to_addrspace = |
| 472 | htonl(FW_CMD_OP_V(FW_LDST_CMD) | |
| 473 | FW_CMD_REQUEST_F | |
| 474 | FW_CMD_READ_F | |
| 475 | FW_LDST_CMD_ADDRSPACE_V( |
| 476 | FW_LDST_ADDRSPC_MPS)); |
| 477 | ldst_cmd.cycles_to_len16 = htonl(FW_LEN16(ldst_cmd)); |
| 478 | ldst_cmd.u.mps.fid_ctl = |
| 479 | htons(FW_LDST_CMD_FID_V(FW_LDST_MPS_RPLC) | |
| 480 | FW_LDST_CMD_CTL_V(idx)); |
| 481 | ret = t4_wr_mbox(adap, adap->mbox, &ldst_cmd, |
| 482 | sizeof(ldst_cmd), &ldst_cmd); |
| 483 | if (ret) |
| 484 | dev_warn(adap->pdev_dev, "Can't read MPS " |
| 485 | "replication map for idx %d: %d\n", |
| 486 | idx, -ret); |
| 487 | else { |
| 488 | rplc[0] = ntohl(ldst_cmd.u.mps.rplc31_0); |
| 489 | rplc[1] = ntohl(ldst_cmd.u.mps.rplc63_32); |
| 490 | rplc[2] = ntohl(ldst_cmd.u.mps.rplc95_64); |
| 491 | rplc[3] = ntohl(ldst_cmd.u.mps.rplc127_96); |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | tcamxy2valmask(tcamx, tcamy, addr, &mask); |
| 496 | seq_printf(seq, "%3u %02x:%02x:%02x:%02x:%02x:%02x %012llx" |
| 497 | "%3c %#x%4u%4d", |
| 498 | idx, addr[0], addr[1], addr[2], addr[3], addr[4], |
| 499 | addr[5], (unsigned long long)mask, |
| 500 | (cls_lo & SRAM_VLD_F) ? 'Y' : 'N', PORTMAP_G(cls_hi), |
| 501 | PF_G(cls_lo), |
| 502 | (cls_lo & VF_VALID_F) ? VF_G(cls_lo) : -1); |
| 503 | if (cls_lo & REPLICATE_F) |
| 504 | seq_printf(seq, " %08x %08x %08x %08x", |
| 505 | rplc[3], rplc[2], rplc[1], rplc[0]); |
| 506 | else |
| 507 | seq_printf(seq, "%36c", ' '); |
| 508 | seq_printf(seq, "%4u%3u%3u%3u %#x\n", |
| 509 | SRAM_PRIO0_G(cls_lo), SRAM_PRIO1_G(cls_lo), |
| 510 | SRAM_PRIO2_G(cls_lo), SRAM_PRIO3_G(cls_lo), |
| 511 | (cls_lo >> MULTILISTEN0_S) & 0xf); |
| 512 | } |
| 513 | out: return 0; |
| 514 | } |
| 515 | |
| 516 | static inline void *mps_tcam_get_idx(struct seq_file *seq, loff_t pos) |
| 517 | { |
| 518 | struct adapter *adap = seq->private; |
| 519 | int max_mac_addr = is_t4(adap->params.chip) ? |
| 520 | NUM_MPS_CLS_SRAM_L_INSTANCES : |
| 521 | NUM_MPS_T5_CLS_SRAM_L_INSTANCES; |
| 522 | return ((pos <= max_mac_addr) ? (void *)(uintptr_t)(pos + 1) : NULL); |
| 523 | } |
| 524 | |
| 525 | static void *mps_tcam_start(struct seq_file *seq, loff_t *pos) |
| 526 | { |
| 527 | return *pos ? mps_tcam_get_idx(seq, *pos) : SEQ_START_TOKEN; |
| 528 | } |
| 529 | |
| 530 | static void *mps_tcam_next(struct seq_file *seq, void *v, loff_t *pos) |
| 531 | { |
| 532 | ++*pos; |
| 533 | return mps_tcam_get_idx(seq, *pos); |
| 534 | } |
| 535 | |
| 536 | static void mps_tcam_stop(struct seq_file *seq, void *v) |
| 537 | { |
| 538 | } |
| 539 | |
| 540 | static const struct seq_operations mps_tcam_seq_ops = { |
| 541 | .start = mps_tcam_start, |
| 542 | .next = mps_tcam_next, |
| 543 | .stop = mps_tcam_stop, |
| 544 | .show = mps_tcam_show |
| 545 | }; |
| 546 | |
| 547 | static int mps_tcam_open(struct inode *inode, struct file *file) |
| 548 | { |
| 549 | int res = seq_open(file, &mps_tcam_seq_ops); |
| 550 | |
| 551 | if (!res) { |
| 552 | struct seq_file *seq = file->private_data; |
| 553 | |
| 554 | seq->private = inode->i_private; |
| 555 | } |
| 556 | return res; |
| 557 | } |
| 558 | |
| 559 | static const struct file_operations mps_tcam_debugfs_fops = { |
| 560 | .owner = THIS_MODULE, |
| 561 | .open = mps_tcam_open, |
| 562 | .read = seq_read, |
| 563 | .llseek = seq_lseek, |
| 564 | .release = seq_release, |
| 565 | }; |
| 566 | |
Anish Bhatt | b5a02f5 | 2015-01-14 15:17:34 -0800 | [diff] [blame^] | 567 | #if IS_ENABLED(CONFIG_IPV6) |
| 568 | static int clip_tbl_open(struct inode *inode, struct file *file) |
| 569 | { |
| 570 | return single_open(file, clip_tbl_show, PDE_DATA(inode)); |
| 571 | } |
| 572 | |
| 573 | static const struct file_operations clip_tbl_debugfs_fops = { |
| 574 | .owner = THIS_MODULE, |
| 575 | .open = clip_tbl_open, |
| 576 | .read = seq_read, |
| 577 | .llseek = seq_lseek, |
| 578 | .release = single_release |
| 579 | }; |
| 580 | #endif |
| 581 | |
Hariprasad Shenai | fd88b31 | 2014-11-07 09:35:23 +0530 | [diff] [blame] | 582 | static ssize_t mem_read(struct file *file, char __user *buf, size_t count, |
| 583 | loff_t *ppos) |
| 584 | { |
| 585 | loff_t pos = *ppos; |
| 586 | loff_t avail = file_inode(file)->i_size; |
| 587 | unsigned int mem = (uintptr_t)file->private_data & 3; |
| 588 | struct adapter *adap = file->private_data - mem; |
| 589 | __be32 *data; |
| 590 | int ret; |
| 591 | |
| 592 | if (pos < 0) |
| 593 | return -EINVAL; |
| 594 | if (pos >= avail) |
| 595 | return 0; |
| 596 | if (count > avail - pos) |
| 597 | count = avail - pos; |
| 598 | |
| 599 | data = t4_alloc_mem(count); |
| 600 | if (!data) |
| 601 | return -ENOMEM; |
| 602 | |
| 603 | spin_lock(&adap->win0_lock); |
| 604 | ret = t4_memory_rw(adap, 0, mem, pos, count, data, T4_MEMORY_READ); |
| 605 | spin_unlock(&adap->win0_lock); |
| 606 | if (ret) { |
| 607 | t4_free_mem(data); |
| 608 | return ret; |
| 609 | } |
| 610 | ret = copy_to_user(buf, data, count); |
| 611 | |
| 612 | t4_free_mem(data); |
| 613 | if (ret) |
| 614 | return -EFAULT; |
| 615 | |
| 616 | *ppos = pos + count; |
| 617 | return count; |
| 618 | } |
| 619 | |
| 620 | static const struct file_operations mem_debugfs_fops = { |
| 621 | .owner = THIS_MODULE, |
| 622 | .open = simple_open, |
| 623 | .read = mem_read, |
| 624 | .llseek = default_llseek, |
| 625 | }; |
| 626 | |
| 627 | static void add_debugfs_mem(struct adapter *adap, const char *name, |
| 628 | unsigned int idx, unsigned int size_mb) |
| 629 | { |
| 630 | struct dentry *de; |
| 631 | |
| 632 | de = debugfs_create_file(name, S_IRUSR, adap->debugfs_root, |
| 633 | (void *)adap + idx, &mem_debugfs_fops); |
| 634 | if (de && de->d_inode) |
| 635 | de->d_inode->i_size = size_mb << 20; |
| 636 | } |
| 637 | |
| 638 | /* Add an array of Debug FS files. |
| 639 | */ |
| 640 | void add_debugfs_files(struct adapter *adap, |
| 641 | struct t4_debugfs_entry *files, |
| 642 | unsigned int nfiles) |
| 643 | { |
| 644 | int i; |
| 645 | |
| 646 | /* debugfs support is best effort */ |
| 647 | for (i = 0; i < nfiles; i++) |
| 648 | debugfs_create_file(files[i].name, files[i].mode, |
| 649 | adap->debugfs_root, |
| 650 | (void *)adap + files[i].data, |
| 651 | files[i].ops); |
| 652 | } |
| 653 | |
| 654 | int t4_setup_debugfs(struct adapter *adap) |
| 655 | { |
| 656 | int i; |
| 657 | u32 size; |
| 658 | |
| 659 | static struct t4_debugfs_entry t4_debugfs_files[] = { |
Hariprasad Shenai | f1ff24a | 2015-01-07 08:48:01 +0530 | [diff] [blame] | 660 | { "cim_la", &cim_la_fops, S_IRUSR, 0 }, |
Hariprasad Shenai | 74b3092 | 2015-01-07 08:48:02 +0530 | [diff] [blame] | 661 | { "cim_qcfg", &cim_qcfg_fops, S_IRUSR, 0 }, |
Hariprasad Shenai | 49aa284 | 2015-01-07 08:48:00 +0530 | [diff] [blame] | 662 | { "devlog", &devlog_fops, S_IRUSR, 0 }, |
Hariprasad Shenai | fd88b31 | 2014-11-07 09:35:23 +0530 | [diff] [blame] | 663 | { "l2t", &t4_l2t_fops, S_IRUSR, 0}, |
Hariprasad Shenai | ef82f66 | 2015-01-07 08:48:03 +0530 | [diff] [blame] | 664 | { "mps_tcam", &mps_tcam_debugfs_fops, S_IRUSR, 0 }, |
Anish Bhatt | b5a02f5 | 2015-01-14 15:17:34 -0800 | [diff] [blame^] | 665 | #if IS_ENABLED(CONFIG_IPV6) |
| 666 | { "clip_tbl", &clip_tbl_debugfs_fops, S_IRUSR, 0 }, |
| 667 | #endif |
Hariprasad Shenai | fd88b31 | 2014-11-07 09:35:23 +0530 | [diff] [blame] | 668 | }; |
| 669 | |
| 670 | add_debugfs_files(adap, |
| 671 | t4_debugfs_files, |
| 672 | ARRAY_SIZE(t4_debugfs_files)); |
| 673 | |
Hariprasad Shenai | 6559a7e | 2014-11-07 09:35:24 +0530 | [diff] [blame] | 674 | i = t4_read_reg(adap, MA_TARGET_MEM_ENABLE_A); |
| 675 | if (i & EDRAM0_ENABLE_F) { |
| 676 | size = t4_read_reg(adap, MA_EDRAM0_BAR_A); |
| 677 | add_debugfs_mem(adap, "edc0", MEM_EDC0, EDRAM0_SIZE_G(size)); |
Hariprasad Shenai | fd88b31 | 2014-11-07 09:35:23 +0530 | [diff] [blame] | 678 | } |
Hariprasad Shenai | 6559a7e | 2014-11-07 09:35:24 +0530 | [diff] [blame] | 679 | if (i & EDRAM1_ENABLE_F) { |
| 680 | size = t4_read_reg(adap, MA_EDRAM1_BAR_A); |
| 681 | add_debugfs_mem(adap, "edc1", MEM_EDC1, EDRAM1_SIZE_G(size)); |
Hariprasad Shenai | fd88b31 | 2014-11-07 09:35:23 +0530 | [diff] [blame] | 682 | } |
| 683 | if (is_t4(adap->params.chip)) { |
Hariprasad Shenai | 6559a7e | 2014-11-07 09:35:24 +0530 | [diff] [blame] | 684 | size = t4_read_reg(adap, MA_EXT_MEMORY_BAR_A); |
| 685 | if (i & EXT_MEM_ENABLE_F) |
Hariprasad Shenai | fd88b31 | 2014-11-07 09:35:23 +0530 | [diff] [blame] | 686 | add_debugfs_mem(adap, "mc", MEM_MC, |
Hariprasad Shenai | 6559a7e | 2014-11-07 09:35:24 +0530 | [diff] [blame] | 687 | EXT_MEM_SIZE_G(size)); |
Hariprasad Shenai | fd88b31 | 2014-11-07 09:35:23 +0530 | [diff] [blame] | 688 | } else { |
Hariprasad Shenai | 6559a7e | 2014-11-07 09:35:24 +0530 | [diff] [blame] | 689 | if (i & EXT_MEM0_ENABLE_F) { |
| 690 | size = t4_read_reg(adap, MA_EXT_MEMORY0_BAR_A); |
Hariprasad Shenai | fd88b31 | 2014-11-07 09:35:23 +0530 | [diff] [blame] | 691 | add_debugfs_mem(adap, "mc0", MEM_MC0, |
Hariprasad Shenai | 6559a7e | 2014-11-07 09:35:24 +0530 | [diff] [blame] | 692 | EXT_MEM0_SIZE_G(size)); |
Hariprasad Shenai | fd88b31 | 2014-11-07 09:35:23 +0530 | [diff] [blame] | 693 | } |
Hariprasad Shenai | 6559a7e | 2014-11-07 09:35:24 +0530 | [diff] [blame] | 694 | if (i & EXT_MEM1_ENABLE_F) { |
| 695 | size = t4_read_reg(adap, MA_EXT_MEMORY1_BAR_A); |
Hariprasad Shenai | fd88b31 | 2014-11-07 09:35:23 +0530 | [diff] [blame] | 696 | add_debugfs_mem(adap, "mc1", MEM_MC1, |
Hariprasad Shenai | 6559a7e | 2014-11-07 09:35:24 +0530 | [diff] [blame] | 697 | EXT_MEM1_SIZE_G(size)); |
Hariprasad Shenai | fd88b31 | 2014-11-07 09:35:23 +0530 | [diff] [blame] | 698 | } |
| 699 | } |
| 700 | return 0; |
| 701 | } |