19c384ee3SSasha Neftin // SPDX-License-Identifier: GPL-2.0
29c384ee3SSasha Neftin /* Copyright (c) 2018 Intel Corporation */
39c384ee3SSasha Neftin
49c384ee3SSasha Neftin #include "igc.h"
59c384ee3SSasha Neftin
69c384ee3SSasha Neftin struct igc_reg_info {
79c384ee3SSasha Neftin u32 ofs;
89c384ee3SSasha Neftin char *name;
99c384ee3SSasha Neftin };
109c384ee3SSasha Neftin
119c384ee3SSasha Neftin static const struct igc_reg_info igc_reg_info_tbl[] = {
129c384ee3SSasha Neftin /* General Registers */
139c384ee3SSasha Neftin {IGC_CTRL, "CTRL"},
149c384ee3SSasha Neftin {IGC_STATUS, "STATUS"},
159c384ee3SSasha Neftin {IGC_CTRL_EXT, "CTRL_EXT"},
169c384ee3SSasha Neftin {IGC_MDIC, "MDIC"},
179c384ee3SSasha Neftin
189c384ee3SSasha Neftin /* Interrupt Registers */
199c384ee3SSasha Neftin {IGC_ICR, "ICR"},
209c384ee3SSasha Neftin
219c384ee3SSasha Neftin /* RX Registers */
229c384ee3SSasha Neftin {IGC_RCTL, "RCTL"},
239c384ee3SSasha Neftin {IGC_RDLEN(0), "RDLEN"},
249c384ee3SSasha Neftin {IGC_RDH(0), "RDH"},
259c384ee3SSasha Neftin {IGC_RDT(0), "RDT"},
269c384ee3SSasha Neftin {IGC_RXDCTL(0), "RXDCTL"},
279c384ee3SSasha Neftin {IGC_RDBAL(0), "RDBAL"},
289c384ee3SSasha Neftin {IGC_RDBAH(0), "RDBAH"},
299c384ee3SSasha Neftin
309c384ee3SSasha Neftin /* TX Registers */
319c384ee3SSasha Neftin {IGC_TCTL, "TCTL"},
329c384ee3SSasha Neftin {IGC_TDBAL(0), "TDBAL"},
339c384ee3SSasha Neftin {IGC_TDBAH(0), "TDBAH"},
349c384ee3SSasha Neftin {IGC_TDLEN(0), "TDLEN"},
359c384ee3SSasha Neftin {IGC_TDH(0), "TDH"},
369c384ee3SSasha Neftin {IGC_TDT(0), "TDT"},
379c384ee3SSasha Neftin {IGC_TXDCTL(0), "TXDCTL"},
389c384ee3SSasha Neftin
399c384ee3SSasha Neftin /* List Terminator */
409c384ee3SSasha Neftin {}
419c384ee3SSasha Neftin };
429c384ee3SSasha Neftin
439c384ee3SSasha Neftin /* igc_regdump - register printout routine */
igc_regdump(struct igc_hw * hw,struct igc_reg_info * reginfo)449c384ee3SSasha Neftin static void igc_regdump(struct igc_hw *hw, struct igc_reg_info *reginfo)
459c384ee3SSasha Neftin {
465c32bac9SAndre Guedes struct net_device *dev = igc_get_hw_dev(hw);
479c384ee3SSasha Neftin int n = 0;
489c384ee3SSasha Neftin char rname[16];
499c384ee3SSasha Neftin u32 regs[8];
509c384ee3SSasha Neftin
519c384ee3SSasha Neftin switch (reginfo->ofs) {
529c384ee3SSasha Neftin case IGC_RDLEN(0):
539c384ee3SSasha Neftin for (n = 0; n < 4; n++)
549c384ee3SSasha Neftin regs[n] = rd32(IGC_RDLEN(n));
559c384ee3SSasha Neftin break;
569c384ee3SSasha Neftin case IGC_RDH(0):
579c384ee3SSasha Neftin for (n = 0; n < 4; n++)
589c384ee3SSasha Neftin regs[n] = rd32(IGC_RDH(n));
599c384ee3SSasha Neftin break;
609c384ee3SSasha Neftin case IGC_RDT(0):
619c384ee3SSasha Neftin for (n = 0; n < 4; n++)
629c384ee3SSasha Neftin regs[n] = rd32(IGC_RDT(n));
639c384ee3SSasha Neftin break;
649c384ee3SSasha Neftin case IGC_RXDCTL(0):
659c384ee3SSasha Neftin for (n = 0; n < 4; n++)
669c384ee3SSasha Neftin regs[n] = rd32(IGC_RXDCTL(n));
679c384ee3SSasha Neftin break;
689c384ee3SSasha Neftin case IGC_RDBAL(0):
699c384ee3SSasha Neftin for (n = 0; n < 4; n++)
709c384ee3SSasha Neftin regs[n] = rd32(IGC_RDBAL(n));
719c384ee3SSasha Neftin break;
729c384ee3SSasha Neftin case IGC_RDBAH(0):
739c384ee3SSasha Neftin for (n = 0; n < 4; n++)
749c384ee3SSasha Neftin regs[n] = rd32(IGC_RDBAH(n));
759c384ee3SSasha Neftin break;
769c384ee3SSasha Neftin case IGC_TDBAL(0):
779c384ee3SSasha Neftin for (n = 0; n < 4; n++)
789660ef25SSasha Neftin regs[n] = rd32(IGC_TDBAL(n));
799c384ee3SSasha Neftin break;
809c384ee3SSasha Neftin case IGC_TDBAH(0):
819c384ee3SSasha Neftin for (n = 0; n < 4; n++)
829c384ee3SSasha Neftin regs[n] = rd32(IGC_TDBAH(n));
839c384ee3SSasha Neftin break;
849c384ee3SSasha Neftin case IGC_TDLEN(0):
859c384ee3SSasha Neftin for (n = 0; n < 4; n++)
869c384ee3SSasha Neftin regs[n] = rd32(IGC_TDLEN(n));
879c384ee3SSasha Neftin break;
889c384ee3SSasha Neftin case IGC_TDH(0):
899c384ee3SSasha Neftin for (n = 0; n < 4; n++)
909c384ee3SSasha Neftin regs[n] = rd32(IGC_TDH(n));
919c384ee3SSasha Neftin break;
929c384ee3SSasha Neftin case IGC_TDT(0):
939c384ee3SSasha Neftin for (n = 0; n < 4; n++)
949c384ee3SSasha Neftin regs[n] = rd32(IGC_TDT(n));
959c384ee3SSasha Neftin break;
969c384ee3SSasha Neftin case IGC_TXDCTL(0):
979c384ee3SSasha Neftin for (n = 0; n < 4; n++)
989c384ee3SSasha Neftin regs[n] = rd32(IGC_TXDCTL(n));
999c384ee3SSasha Neftin break;
1009c384ee3SSasha Neftin default:
1015c32bac9SAndre Guedes netdev_info(dev, "%-15s %08x\n", reginfo->name,
1025c32bac9SAndre Guedes rd32(reginfo->ofs));
1039c384ee3SSasha Neftin return;
1049c384ee3SSasha Neftin }
1059c384ee3SSasha Neftin
1069c384ee3SSasha Neftin snprintf(rname, 16, "%s%s", reginfo->name, "[0-3]");
1075c32bac9SAndre Guedes netdev_info(dev, "%-15s %08x %08x %08x %08x\n", rname, regs[0], regs[1],
1089c384ee3SSasha Neftin regs[2], regs[3]);
1099c384ee3SSasha Neftin }
1109c384ee3SSasha Neftin
1119c384ee3SSasha Neftin /* igc_rings_dump - Tx-rings and Rx-rings */
igc_rings_dump(struct igc_adapter * adapter)1129c384ee3SSasha Neftin void igc_rings_dump(struct igc_adapter *adapter)
1139c384ee3SSasha Neftin {
1149c384ee3SSasha Neftin struct net_device *netdev = adapter->netdev;
115*88c228b2SJesse Brandeburg struct my_u0 { __le64 a; __le64 b; } *u0;
1169c384ee3SSasha Neftin union igc_adv_tx_desc *tx_desc;
1179c384ee3SSasha Neftin union igc_adv_rx_desc *rx_desc;
1189c384ee3SSasha Neftin struct igc_ring *tx_ring;
1199c384ee3SSasha Neftin struct igc_ring *rx_ring;
1209c384ee3SSasha Neftin u32 staterr;
1219c384ee3SSasha Neftin u16 i, n;
1229c384ee3SSasha Neftin
1239c384ee3SSasha Neftin if (!netif_msg_hw(adapter))
1249c384ee3SSasha Neftin return;
1259c384ee3SSasha Neftin
1265c32bac9SAndre Guedes netdev_info(netdev, "Device info: state %016lX trans_start %016lX\n",
1279c384ee3SSasha Neftin netdev->state, dev_trans_start(netdev));
1289c384ee3SSasha Neftin
1299c384ee3SSasha Neftin /* Print TX Ring Summary */
1305c32bac9SAndre Guedes if (!netif_running(netdev))
1319c384ee3SSasha Neftin goto exit;
1329c384ee3SSasha Neftin
1335c32bac9SAndre Guedes netdev_info(netdev, "TX Rings Summary\n");
1345c32bac9SAndre Guedes netdev_info(netdev, "Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
1359c384ee3SSasha Neftin for (n = 0; n < adapter->num_tx_queues; n++) {
1369c384ee3SSasha Neftin struct igc_tx_buffer *buffer_info;
1379c384ee3SSasha Neftin
1389c384ee3SSasha Neftin tx_ring = adapter->tx_ring[n];
1399c384ee3SSasha Neftin buffer_info = &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
1409c384ee3SSasha Neftin
1415c32bac9SAndre Guedes netdev_info(netdev, "%5d %5X %5X %016llX %04X %p %016llX\n",
1429c384ee3SSasha Neftin n, tx_ring->next_to_use, tx_ring->next_to_clean,
1439c384ee3SSasha Neftin (u64)dma_unmap_addr(buffer_info, dma),
1449c384ee3SSasha Neftin dma_unmap_len(buffer_info, len),
1459c384ee3SSasha Neftin buffer_info->next_to_watch,
1469c384ee3SSasha Neftin (u64)buffer_info->time_stamp);
1479c384ee3SSasha Neftin }
1489c384ee3SSasha Neftin
1499c384ee3SSasha Neftin /* Print TX Rings */
1509c384ee3SSasha Neftin if (!netif_msg_tx_done(adapter))
1519c384ee3SSasha Neftin goto rx_ring_summary;
1529c384ee3SSasha Neftin
1535c32bac9SAndre Guedes netdev_info(netdev, "TX Rings Dump\n");
1549c384ee3SSasha Neftin
1559c384ee3SSasha Neftin /* Transmit Descriptor Formats
1569c384ee3SSasha Neftin *
1579c384ee3SSasha Neftin * Advanced Transmit Descriptor
1589c384ee3SSasha Neftin * +--------------------------------------------------------------+
1599c384ee3SSasha Neftin * 0 | Buffer Address [63:0] |
1609c384ee3SSasha Neftin * +--------------------------------------------------------------+
1619c384ee3SSasha Neftin * 8 | PAYLEN | PORTS |CC|IDX | STA | DCMD |DTYP|MAC|RSV| DTALEN |
1629c384ee3SSasha Neftin * +--------------------------------------------------------------+
1639c384ee3SSasha Neftin * 63 46 45 40 39 38 36 35 32 31 24 15 0
1649c384ee3SSasha Neftin */
1659c384ee3SSasha Neftin
1669c384ee3SSasha Neftin for (n = 0; n < adapter->num_tx_queues; n++) {
1679c384ee3SSasha Neftin tx_ring = adapter->tx_ring[n];
1685c32bac9SAndre Guedes netdev_info(netdev, "------------------------------------\n");
1695c32bac9SAndre Guedes netdev_info(netdev, "TX QUEUE INDEX = %d\n",
1705c32bac9SAndre Guedes tx_ring->queue_index);
1715c32bac9SAndre Guedes netdev_info(netdev, "------------------------------------\n");
1725c32bac9SAndre Guedes netdev_info(netdev, "T [desc] [address 63:0 ] [PlPOCIStDDM Ln] [bi->dma ] leng ntw timestamp bi->skb\n");
1739c384ee3SSasha Neftin
1749c384ee3SSasha Neftin for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
1759c384ee3SSasha Neftin const char *next_desc;
1769c384ee3SSasha Neftin struct igc_tx_buffer *buffer_info;
1779c384ee3SSasha Neftin
1789c384ee3SSasha Neftin tx_desc = IGC_TX_DESC(tx_ring, i);
1799c384ee3SSasha Neftin buffer_info = &tx_ring->tx_buffer_info[i];
1809c384ee3SSasha Neftin u0 = (struct my_u0 *)tx_desc;
1819c384ee3SSasha Neftin if (i == tx_ring->next_to_use &&
1829c384ee3SSasha Neftin i == tx_ring->next_to_clean)
1839c384ee3SSasha Neftin next_desc = " NTC/U";
1849c384ee3SSasha Neftin else if (i == tx_ring->next_to_use)
1859c384ee3SSasha Neftin next_desc = " NTU";
1869c384ee3SSasha Neftin else if (i == tx_ring->next_to_clean)
1879c384ee3SSasha Neftin next_desc = " NTC";
1889c384ee3SSasha Neftin else
1899c384ee3SSasha Neftin next_desc = "";
1909c384ee3SSasha Neftin
1915c32bac9SAndre Guedes netdev_info(netdev, "T [0x%03X] %016llX %016llX %016llX %04X %p %016llX %p%s\n",
1929c384ee3SSasha Neftin i, le64_to_cpu(u0->a),
1939c384ee3SSasha Neftin le64_to_cpu(u0->b),
1949c384ee3SSasha Neftin (u64)dma_unmap_addr(buffer_info, dma),
1959c384ee3SSasha Neftin dma_unmap_len(buffer_info, len),
1969c384ee3SSasha Neftin buffer_info->next_to_watch,
1979c384ee3SSasha Neftin (u64)buffer_info->time_stamp,
1989c384ee3SSasha Neftin buffer_info->skb, next_desc);
1999c384ee3SSasha Neftin
2009c384ee3SSasha Neftin if (netif_msg_pktdata(adapter) && buffer_info->skb)
2019c384ee3SSasha Neftin print_hex_dump(KERN_INFO, "",
2029c384ee3SSasha Neftin DUMP_PREFIX_ADDRESS,
2039c384ee3SSasha Neftin 16, 1, buffer_info->skb->data,
2049c384ee3SSasha Neftin dma_unmap_len(buffer_info, len),
2059c384ee3SSasha Neftin true);
2069c384ee3SSasha Neftin }
2079c384ee3SSasha Neftin }
2089c384ee3SSasha Neftin
2099c384ee3SSasha Neftin /* Print RX Rings Summary */
2109c384ee3SSasha Neftin rx_ring_summary:
2115c32bac9SAndre Guedes netdev_info(netdev, "RX Rings Summary\n");
2125c32bac9SAndre Guedes netdev_info(netdev, "Queue [NTU] [NTC]\n");
2139c384ee3SSasha Neftin for (n = 0; n < adapter->num_rx_queues; n++) {
2149c384ee3SSasha Neftin rx_ring = adapter->rx_ring[n];
2155c32bac9SAndre Guedes netdev_info(netdev, "%5d %5X %5X\n", n, rx_ring->next_to_use,
2165c32bac9SAndre Guedes rx_ring->next_to_clean);
2179c384ee3SSasha Neftin }
2189c384ee3SSasha Neftin
2199c384ee3SSasha Neftin /* Print RX Rings */
2209c384ee3SSasha Neftin if (!netif_msg_rx_status(adapter))
2219c384ee3SSasha Neftin goto exit;
2229c384ee3SSasha Neftin
2235c32bac9SAndre Guedes netdev_info(netdev, "RX Rings Dump\n");
2249c384ee3SSasha Neftin
2259c384ee3SSasha Neftin /* Advanced Receive Descriptor (Read) Format
2269c384ee3SSasha Neftin * 63 1 0
2279c384ee3SSasha Neftin * +-----------------------------------------------------+
2289c384ee3SSasha Neftin * 0 | Packet Buffer Address [63:1] |A0/NSE|
2299c384ee3SSasha Neftin * +----------------------------------------------+------+
2309c384ee3SSasha Neftin * 8 | Header Buffer Address [63:1] | DD |
2319c384ee3SSasha Neftin * +-----------------------------------------------------+
2329c384ee3SSasha Neftin *
2339c384ee3SSasha Neftin *
2349c384ee3SSasha Neftin * Advanced Receive Descriptor (Write-Back) Format
2359c384ee3SSasha Neftin *
2369c384ee3SSasha Neftin * 63 48 47 32 31 30 21 20 17 16 4 3 0
2379c384ee3SSasha Neftin * +------------------------------------------------------+
2389c384ee3SSasha Neftin * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS |
2399c384ee3SSasha Neftin * | Checksum Ident | | | | Type | Type |
2409c384ee3SSasha Neftin * +------------------------------------------------------+
2419c384ee3SSasha Neftin * 8 | VLAN Tag | Length | Extended Error | Extended Status |
2429c384ee3SSasha Neftin * +------------------------------------------------------+
2439c384ee3SSasha Neftin * 63 48 47 32 31 20 19 0
2449c384ee3SSasha Neftin */
2459c384ee3SSasha Neftin
2469c384ee3SSasha Neftin for (n = 0; n < adapter->num_rx_queues; n++) {
2479c384ee3SSasha Neftin rx_ring = adapter->rx_ring[n];
2485c32bac9SAndre Guedes netdev_info(netdev, "------------------------------------\n");
2495c32bac9SAndre Guedes netdev_info(netdev, "RX QUEUE INDEX = %d\n",
2505c32bac9SAndre Guedes rx_ring->queue_index);
2515c32bac9SAndre Guedes netdev_info(netdev, "------------------------------------\n");
2525c32bac9SAndre Guedes netdev_info(netdev, "R [desc] [ PktBuf A0] [ HeadBuf DD] [bi->dma ] [bi->skb] <-- Adv Rx Read format\n");
2535c32bac9SAndre Guedes netdev_info(netdev, "RWB[desc] [PcsmIpSHl PtRs] [vl er S cks ln] ---------------- [bi->skb] <-- Adv Rx Write-Back format\n");
2549c384ee3SSasha Neftin
2559c384ee3SSasha Neftin for (i = 0; i < rx_ring->count; i++) {
2569c384ee3SSasha Neftin const char *next_desc;
2579c384ee3SSasha Neftin struct igc_rx_buffer *buffer_info;
2589c384ee3SSasha Neftin
2599c384ee3SSasha Neftin buffer_info = &rx_ring->rx_buffer_info[i];
2609c384ee3SSasha Neftin rx_desc = IGC_RX_DESC(rx_ring, i);
2619c384ee3SSasha Neftin u0 = (struct my_u0 *)rx_desc;
2629c384ee3SSasha Neftin staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
2639c384ee3SSasha Neftin
2649c384ee3SSasha Neftin if (i == rx_ring->next_to_use)
2659c384ee3SSasha Neftin next_desc = " NTU";
2669c384ee3SSasha Neftin else if (i == rx_ring->next_to_clean)
2679c384ee3SSasha Neftin next_desc = " NTC";
2689c384ee3SSasha Neftin else
2699c384ee3SSasha Neftin next_desc = "";
2709c384ee3SSasha Neftin
2719c384ee3SSasha Neftin if (staterr & IGC_RXD_STAT_DD) {
2729c384ee3SSasha Neftin /* Descriptor Done */
2735c32bac9SAndre Guedes netdev_info(netdev, "%s[0x%03X] %016llX %016llX ---------------- %s\n",
2749c384ee3SSasha Neftin "RWB", i,
2759c384ee3SSasha Neftin le64_to_cpu(u0->a),
2769c384ee3SSasha Neftin le64_to_cpu(u0->b),
2779c384ee3SSasha Neftin next_desc);
2789c384ee3SSasha Neftin } else {
2795c32bac9SAndre Guedes netdev_info(netdev, "%s[0x%03X] %016llX %016llX %016llX %s\n",
2809c384ee3SSasha Neftin "R ", i,
2819c384ee3SSasha Neftin le64_to_cpu(u0->a),
2829c384ee3SSasha Neftin le64_to_cpu(u0->b),
2839c384ee3SSasha Neftin (u64)buffer_info->dma,
2849c384ee3SSasha Neftin next_desc);
2859c384ee3SSasha Neftin
2869c384ee3SSasha Neftin if (netif_msg_pktdata(adapter) &&
2879c384ee3SSasha Neftin buffer_info->dma && buffer_info->page) {
2889c384ee3SSasha Neftin print_hex_dump(KERN_INFO, "",
2899c384ee3SSasha Neftin DUMP_PREFIX_ADDRESS,
2909c384ee3SSasha Neftin 16, 1,
2919c384ee3SSasha Neftin page_address
2929c384ee3SSasha Neftin (buffer_info->page) +
2939c384ee3SSasha Neftin buffer_info->page_offset,
2949c384ee3SSasha Neftin igc_rx_bufsz(rx_ring),
2959c384ee3SSasha Neftin true);
2969c384ee3SSasha Neftin }
2979c384ee3SSasha Neftin }
2989c384ee3SSasha Neftin }
2999c384ee3SSasha Neftin }
3009c384ee3SSasha Neftin
3019c384ee3SSasha Neftin exit:
3029c384ee3SSasha Neftin return;
3039c384ee3SSasha Neftin }
3049c384ee3SSasha Neftin
3059c384ee3SSasha Neftin /* igc_regs_dump - registers dump */
igc_regs_dump(struct igc_adapter * adapter)3069c384ee3SSasha Neftin void igc_regs_dump(struct igc_adapter *adapter)
3079c384ee3SSasha Neftin {
3089c384ee3SSasha Neftin struct igc_hw *hw = &adapter->hw;
3099c384ee3SSasha Neftin struct igc_reg_info *reginfo;
3109c384ee3SSasha Neftin
3119c384ee3SSasha Neftin /* Print Registers */
3125c32bac9SAndre Guedes netdev_info(adapter->netdev, "Register Dump\n");
3135c32bac9SAndre Guedes netdev_info(adapter->netdev, "Register Name Value\n");
3149c384ee3SSasha Neftin for (reginfo = (struct igc_reg_info *)igc_reg_info_tbl;
3159c384ee3SSasha Neftin reginfo->name; reginfo++) {
3169c384ee3SSasha Neftin igc_regdump(hw, reginfo);
3179c384ee3SSasha Neftin }
3189c384ee3SSasha Neftin }
319