1679
* lpfc_idiag_baracc_read - idiag debugfs pci bar access read
1680
* @file: The file pointer to read from.
1681
* @buf: The buffer to copy the data to.
1682
* @nbytes: The number of bytes to read.
1683
* @ppos: The position in the file to start reading from.
1686
* This routine reads data from the @phba pci bar memory mapped space
1687
* according to the idiag command, and copies to user @buf.
1690
* This function returns the amount of data that was read (this could be less
1691
* than @nbytes if the end of the file was reached) or a negative error value.
1694
lpfc_idiag_baracc_read(struct file *file, char __user *buf, size_t nbytes,
1697
struct lpfc_debug *debug = file->private_data;
1698
struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1699
int offset_label, offset, offset_run, len = 0, index;
1700
int bar_num, acc_range, bar_size;
1702
void __iomem *mem_mapped_bar;
1704
struct pci_dev *pdev;
1707
pdev = phba->pcidev;
1711
/* This is a user read operation */
1712
debug->op = LPFC_IDIAG_OP_RD;
1715
debug->buffer = kmalloc(LPFC_PCI_BAR_RD_BUF_SIZE, GFP_KERNEL);
1718
pbuffer = debug->buffer;
1723
if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
1724
bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
1725
offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
1726
acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
1727
bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
1734
if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1735
if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
1736
if (bar_num == IDIAG_BARACC_BAR_0)
1737
mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1738
else if (bar_num == IDIAG_BARACC_BAR_1)
1739
mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
1740
else if (bar_num == IDIAG_BARACC_BAR_2)
1741
mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
1744
} else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
1745
if (bar_num == IDIAG_BARACC_BAR_0)
1746
mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1752
/* Read single PCI bar space register */
1753
if (acc_range == SINGLE_WORD) {
1754
offset_run = offset;
1755
u32val = readl(mem_mapped_bar + offset_run);
1756
len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
1757
"%05x: %08x\n", offset_run, u32val);
1761
return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1765
/* Browse all PCI bar space registers */
1766
offset_label = idiag.offset.last_rd;
1767
offset_run = offset_label;
1769
/* Read PCI bar memory mapped space */
1770
len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
1771
"%05x: ", offset_label);
1772
index = LPFC_PCI_BAR_RD_SIZE;
1774
u32val = readl(mem_mapped_bar + offset_run);
1775
len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
1777
offset_run += sizeof(uint32_t);
1778
if (acc_range == LPFC_PCI_BAR_BROWSE) {
1779
if (offset_run >= bar_size) {
1780
len += snprintf(pbuffer+len,
1781
LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
1785
if (offset_run >= offset +
1786
(acc_range * sizeof(uint32_t))) {
1787
len += snprintf(pbuffer+len,
1788
LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
1792
index -= sizeof(uint32_t);
1794
len += snprintf(pbuffer+len,
1795
LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
1796
else if (!(index % (8 * sizeof(uint32_t)))) {
1797
offset_label += (8 * sizeof(uint32_t));
1798
len += snprintf(pbuffer+len,
1799
LPFC_PCI_BAR_RD_BUF_SIZE-len,
1800
"\n%05x: ", offset_label);
1804
/* Set up the offset for next portion of pci bar read */
1806
idiag.offset.last_rd += LPFC_PCI_BAR_RD_SIZE;
1807
if (acc_range == LPFC_PCI_BAR_BROWSE) {
1808
if (idiag.offset.last_rd >= bar_size)
1809
idiag.offset.last_rd = 0;
1811
if (offset_run >= offset +
1812
(acc_range * sizeof(uint32_t)))
1813
idiag.offset.last_rd = offset;
1816
if (acc_range == LPFC_PCI_BAR_BROWSE)
1817
idiag.offset.last_rd = 0;
1819
idiag.offset.last_rd = offset;
1822
return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1826
* lpfc_idiag_baracc_write - Syntax check and set up idiag bar access commands
1827
* @file: The file pointer to read from.
1828
* @buf: The buffer to copy the user data from.
1829
* @nbytes: The number of bytes to get.
1830
* @ppos: The position in the file to start reading from.
1832
* This routine get the debugfs idiag command struct from user space and
1833
* then perform the syntax check for PCI bar memory mapped space read or
1834
* write command accordingly. In the case of PCI bar memory mapped space
1835
* read command, it sets up the command in the idiag command struct for
1836
* the debugfs read operation. In the case of PCI bar memorpy mapped space
1837
* write operation, it executes the write operation into the PCI bar memory
1838
* mapped space accordingly.
1840
* It returns the @nbytges passing in from debugfs user space when successful.
1841
* In case of error conditions, it returns proper error code back to the user
1845
lpfc_idiag_baracc_write(struct file *file, const char __user *buf,
1846
size_t nbytes, loff_t *ppos)
1848
struct lpfc_debug *debug = file->private_data;
1849
struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1850
uint32_t bar_num, bar_size, offset, value, acc_range;
1851
struct pci_dev *pdev;
1852
void __iomem *mem_mapped_bar;
1857
pdev = phba->pcidev;
1861
/* This is a user write operation */
1862
debug->op = LPFC_IDIAG_OP_WR;
1864
rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
1868
if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1869
bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
1871
if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
1872
if ((bar_num != IDIAG_BARACC_BAR_0) &&
1873
(bar_num != IDIAG_BARACC_BAR_1) &&
1874
(bar_num != IDIAG_BARACC_BAR_2))
1876
} else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
1877
if (bar_num != IDIAG_BARACC_BAR_0)
1882
if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
1883
if (bar_num == IDIAG_BARACC_BAR_0) {
1884
idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1885
LPFC_PCI_IF0_BAR0_SIZE;
1886
mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1887
} else if (bar_num == IDIAG_BARACC_BAR_1) {
1888
idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1889
LPFC_PCI_IF0_BAR1_SIZE;
1890
mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
1891
} else if (bar_num == IDIAG_BARACC_BAR_2) {
1892
idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1893
LPFC_PCI_IF0_BAR2_SIZE;
1894
mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
1897
} else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
1898
if (bar_num == IDIAG_BARACC_BAR_0) {
1899
idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1900
LPFC_PCI_IF2_BAR0_SIZE;
1901
mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1907
offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
1908
if (offset % sizeof(uint32_t))
1911
bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
1912
if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
1913
/* Sanity check on PCI config read command line arguments */
1914
if (rc != LPFC_PCI_BAR_RD_CMD_ARG)
1916
acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
1917
if (acc_range == LPFC_PCI_BAR_BROWSE) {
1918
if (offset > bar_size - sizeof(uint32_t))
1920
/* Starting offset to browse */
1921
idiag.offset.last_rd = offset;
1922
} else if (acc_range > SINGLE_WORD) {
1923
if (offset + acc_range * sizeof(uint32_t) > bar_size)
1925
/* Starting offset to browse */
1926
idiag.offset.last_rd = offset;
1927
} else if (acc_range != SINGLE_WORD)
1929
} else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR ||
1930
idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST ||
1931
idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
1932
/* Sanity check on PCI bar write command line arguments */
1933
if (rc != LPFC_PCI_BAR_WR_CMD_ARG)
1935
/* Write command to PCI bar space, read-modify-write */
1936
acc_range = SINGLE_WORD;
1937
value = idiag.cmd.data[IDIAG_BARACC_REG_VAL_INDX];
1938
if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR) {
1939
writel(value, mem_mapped_bar + offset);
1940
readl(mem_mapped_bar + offset);
1942
if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST) {
1943
u32val = readl(mem_mapped_bar + offset);
1945
writel(u32val, mem_mapped_bar + offset);
1946
readl(mem_mapped_bar + offset);
1948
if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
1949
u32val = readl(mem_mapped_bar + offset);
1951
writel(u32val, mem_mapped_bar + offset);
1952
readl(mem_mapped_bar + offset);
1955
/* All other opecodes are illegal for now */
1960
memset(&idiag, 0, sizeof(idiag));
1572
1965
* lpfc_idiag_queinfo_read - idiag debugfs read queue information
1573
1966
* @file: The file pointer to read from.
1574
1967
* @buf: The buffer to copy the data to.
2329
2722
return -EINVAL;
2726
* lpfc_idiag_ctlacc_read_reg - idiag debugfs read a control registers
2727
* @phba: The pointer to hba structure.
2728
* @pbuffer: The pointer to the buffer to copy the data to.
2729
* @len: The lenght of bytes to copied.
2730
* @drbregid: The id to doorbell registers.
2733
* This routine reads a control register and copies its content to the
2734
* user buffer pointed to by @pbuffer.
2737
* This function returns the amount of data that was copied into @pbuffer.
2740
lpfc_idiag_ctlacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
2741
int len, uint32_t ctlregid)
2748
case LPFC_CTL_PORT_SEM:
2749
len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2750
"Port SemReg: 0x%08x\n",
2751
readl(phba->sli4_hba.conf_regs_memmap_p +
2752
LPFC_CTL_PORT_SEM_OFFSET));
2754
case LPFC_CTL_PORT_STA:
2755
len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2756
"Port StaReg: 0x%08x\n",
2757
readl(phba->sli4_hba.conf_regs_memmap_p +
2758
LPFC_CTL_PORT_STA_OFFSET));
2760
case LPFC_CTL_PORT_CTL:
2761
len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2762
"Port CtlReg: 0x%08x\n",
2763
readl(phba->sli4_hba.conf_regs_memmap_p +
2764
LPFC_CTL_PORT_CTL_OFFSET));
2766
case LPFC_CTL_PORT_ER1:
2767
len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2768
"Port Er1Reg: 0x%08x\n",
2769
readl(phba->sli4_hba.conf_regs_memmap_p +
2770
LPFC_CTL_PORT_ER1_OFFSET));
2772
case LPFC_CTL_PORT_ER2:
2773
len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2774
"Port Er2Reg: 0x%08x\n",
2775
readl(phba->sli4_hba.conf_regs_memmap_p +
2776
LPFC_CTL_PORT_ER2_OFFSET));
2778
case LPFC_CTL_PDEV_CTL:
2779
len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2780
"PDev CtlReg: 0x%08x\n",
2781
readl(phba->sli4_hba.conf_regs_memmap_p +
2782
LPFC_CTL_PDEV_CTL_OFFSET));
2791
* lpfc_idiag_ctlacc_read - idiag debugfs read port and device control register
2792
* @file: The file pointer to read from.
2793
* @buf: The buffer to copy the data to.
2794
* @nbytes: The number of bytes to read.
2795
* @ppos: The position in the file to start reading from.
2798
* This routine reads data from the @phba port and device registers according
2799
* to the idiag command, and copies to user @buf.
2802
* This function returns the amount of data that was read (this could be less
2803
* than @nbytes if the end of the file was reached) or a negative error value.
2806
lpfc_idiag_ctlacc_read(struct file *file, char __user *buf, size_t nbytes,
2809
struct lpfc_debug *debug = file->private_data;
2810
struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2811
uint32_t ctl_reg_id, i;
2815
/* This is a user read operation */
2816
debug->op = LPFC_IDIAG_OP_RD;
2819
debug->buffer = kmalloc(LPFC_CTL_ACC_BUF_SIZE, GFP_KERNEL);
2822
pbuffer = debug->buffer;
2827
if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD)
2828
ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
2832
if (ctl_reg_id == LPFC_CTL_ACC_ALL)
2833
for (i = 1; i <= LPFC_CTL_MAX; i++)
2834
len = lpfc_idiag_ctlacc_read_reg(phba,
2837
len = lpfc_idiag_ctlacc_read_reg(phba,
2838
pbuffer, len, ctl_reg_id);
2840
return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2844
* lpfc_idiag_ctlacc_write - Syntax check and set up idiag ctlacc commands
2845
* @file: The file pointer to read from.
2846
* @buf: The buffer to copy the user data from.
2847
* @nbytes: The number of bytes to get.
2848
* @ppos: The position in the file to start reading from.
2850
* This routine get the debugfs idiag command struct from user space and then
2851
* perform the syntax check for port and device control register read (dump)
2852
* or write (set) command accordingly.
2854
* It returns the @nbytges passing in from debugfs user space when successful.
2855
* In case of error conditions, it returns proper error code back to the user
2859
lpfc_idiag_ctlacc_write(struct file *file, const char __user *buf,
2860
size_t nbytes, loff_t *ppos)
2862
struct lpfc_debug *debug = file->private_data;
2863
struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2864
uint32_t ctl_reg_id, value, reg_val = 0;
2865
void __iomem *ctl_reg;
2868
/* This is a user write operation */
2869
debug->op = LPFC_IDIAG_OP_WR;
2871
rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2875
/* Sanity check on command line arguments */
2876
ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
2877
value = idiag.cmd.data[IDIAG_CTLACC_VALUE_INDX];
2879
if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
2880
idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
2881
idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
2882
if (rc != LPFC_CTL_ACC_WR_CMD_ARG)
2884
if (ctl_reg_id > LPFC_CTL_MAX)
2886
} else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD) {
2887
if (rc != LPFC_CTL_ACC_RD_CMD_ARG)
2889
if ((ctl_reg_id > LPFC_CTL_MAX) &&
2890
(ctl_reg_id != LPFC_CTL_ACC_ALL))
2895
/* Perform the write access operation */
2896
if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
2897
idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
2898
idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
2899
switch (ctl_reg_id) {
2900
case LPFC_CTL_PORT_SEM:
2901
ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2902
LPFC_CTL_PORT_SEM_OFFSET;
2904
case LPFC_CTL_PORT_STA:
2905
ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2906
LPFC_CTL_PORT_STA_OFFSET;
2908
case LPFC_CTL_PORT_CTL:
2909
ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2910
LPFC_CTL_PORT_CTL_OFFSET;
2912
case LPFC_CTL_PORT_ER1:
2913
ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2914
LPFC_CTL_PORT_ER1_OFFSET;
2916
case LPFC_CTL_PORT_ER2:
2917
ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2918
LPFC_CTL_PORT_ER2_OFFSET;
2920
case LPFC_CTL_PDEV_CTL:
2921
ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2922
LPFC_CTL_PDEV_CTL_OFFSET;
2928
if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR)
2930
if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST) {
2931
reg_val = readl(ctl_reg);
2934
if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
2935
reg_val = readl(ctl_reg);
2938
writel(reg_val, ctl_reg);
2939
readl(ctl_reg); /* flush */
2944
/* Clean out command structure on command error out */
2945
memset(&idiag, 0, sizeof(idiag));
2950
* lpfc_idiag_mbxacc_get_setup - idiag debugfs get mailbox access setup
2951
* @phba: Pointer to HBA context object.
2952
* @pbuffer: Pointer to data buffer.
2955
* This routine gets the driver mailbox access debugfs setup information.
2958
* This function returns the amount of data that was read (this could be less
2959
* than @nbytes if the end of the file was reached) or a negative error value.
2962
lpfc_idiag_mbxacc_get_setup(struct lpfc_hba *phba, char *pbuffer)
2964
uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
2967
mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
2968
mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
2969
mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
2970
mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
2972
len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
2973
"mbx_dump_map: 0x%08x\n", mbx_dump_map);
2974
len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
2975
"mbx_dump_cnt: %04d\n", mbx_dump_cnt);
2976
len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
2977
"mbx_word_cnt: %04d\n", mbx_word_cnt);
2978
len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
2979
"mbx_mbox_cmd: 0x%02x\n", mbx_mbox_cmd);
2985
* lpfc_idiag_mbxacc_read - idiag debugfs read on mailbox access
2986
* @file: The file pointer to read from.
2987
* @buf: The buffer to copy the data to.
2988
* @nbytes: The number of bytes to read.
2989
* @ppos: The position in the file to start reading from.
2992
* This routine reads data from the @phba driver mailbox access debugfs setup
2996
* This function returns the amount of data that was read (this could be less
2997
* than @nbytes if the end of the file was reached) or a negative error value.
3000
lpfc_idiag_mbxacc_read(struct file *file, char __user *buf, size_t nbytes,
3003
struct lpfc_debug *debug = file->private_data;
3004
struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3008
/* This is a user read operation */
3009
debug->op = LPFC_IDIAG_OP_RD;
3012
debug->buffer = kmalloc(LPFC_MBX_ACC_BUF_SIZE, GFP_KERNEL);
3015
pbuffer = debug->buffer;
3020
if ((idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP) &&
3021
(idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP))
3024
len = lpfc_idiag_mbxacc_get_setup(phba, pbuffer);
3026
return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3030
* lpfc_idiag_mbxacc_write - Syntax check and set up idiag mbxacc commands
3031
* @file: The file pointer to read from.
3032
* @buf: The buffer to copy the user data from.
3033
* @nbytes: The number of bytes to get.
3034
* @ppos: The position in the file to start reading from.
3036
* This routine get the debugfs idiag command struct from user space and then
3037
* perform the syntax check for driver mailbox command (dump) and sets up the
3038
* necessary states in the idiag command struct accordingly.
3040
* It returns the @nbytges passing in from debugfs user space when successful.
3041
* In case of error conditions, it returns proper error code back to the user
3045
lpfc_idiag_mbxacc_write(struct file *file, const char __user *buf,
3046
size_t nbytes, loff_t *ppos)
3048
struct lpfc_debug *debug = file->private_data;
3049
uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
3052
/* This is a user write operation */
3053
debug->op = LPFC_IDIAG_OP_WR;
3055
rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
3059
/* Sanity check on command line arguments */
3060
mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
3061
mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
3062
mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
3063
mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
3065
if (idiag.cmd.opcode == LPFC_IDIAG_CMD_MBXACC_DP) {
3066
if (!(mbx_dump_map & LPFC_MBX_DMP_MBX_ALL))
3068
if ((mbx_dump_map & ~LPFC_MBX_DMP_MBX_ALL) &&
3069
(mbx_dump_map != LPFC_MBX_DMP_ALL))
3071
if (mbx_word_cnt > sizeof(MAILBOX_t))
3073
} else if (idiag.cmd.opcode == LPFC_IDIAG_BSG_MBXACC_DP) {
3074
if (!(mbx_dump_map & LPFC_BSG_DMP_MBX_ALL))
3076
if ((mbx_dump_map & ~LPFC_BSG_DMP_MBX_ALL) &&
3077
(mbx_dump_map != LPFC_MBX_DMP_ALL))
3079
if (mbx_word_cnt > (BSG_MBOX_SIZE)/4)
3081
if (mbx_mbox_cmd != 0x9b)
3086
if (mbx_word_cnt == 0)
3088
if (rc != LPFC_MBX_DMP_ARG)
3090
if (mbx_mbox_cmd & ~0xff)
3093
/* condition for stop mailbox dump */
3094
if (mbx_dump_cnt == 0)
3100
/* Clean out command structure on command error out */
3101
memset(&idiag, 0, sizeof(idiag));
3105
/* Clean out command structure on command error out */
3106
memset(&idiag, 0, sizeof(idiag));
3111
* lpfc_idiag_extacc_avail_get - get the available extents information
3112
* @phba: pointer to lpfc hba data structure.
3113
* @pbuffer: pointer to internal buffer.
3114
* @len: length into the internal buffer data has been copied.
3117
* This routine is to get the available extent information.
3120
* overall lenth of the data read into the internal buffer.
3123
lpfc_idiag_extacc_avail_get(struct lpfc_hba *phba, char *pbuffer, int len)
3125
uint16_t ext_cnt, ext_size;
3127
len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3128
"\nAvailable Extents Information:\n");
3130
len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3131
"\tPort Available VPI extents: ");
3132
lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VPI,
3133
&ext_cnt, &ext_size);
3134
len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3135
"Count %3d, Size %3d\n", ext_cnt, ext_size);
3137
len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3138
"\tPort Available VFI extents: ");
3139
lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VFI,
3140
&ext_cnt, &ext_size);
3141
len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3142
"Count %3d, Size %3d\n", ext_cnt, ext_size);
3144
len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3145
"\tPort Available RPI extents: ");
3146
lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_RPI,
3147
&ext_cnt, &ext_size);
3148
len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3149
"Count %3d, Size %3d\n", ext_cnt, ext_size);
3151
len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3152
"\tPort Available XRI extents: ");
3153
lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_XRI,
3154
&ext_cnt, &ext_size);
3155
len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3156
"Count %3d, Size %3d\n", ext_cnt, ext_size);
3162
* lpfc_idiag_extacc_alloc_get - get the allocated extents information
3163
* @phba: pointer to lpfc hba data structure.
3164
* @pbuffer: pointer to internal buffer.
3165
* @len: length into the internal buffer data has been copied.
3168
* This routine is to get the allocated extent information.
3171
* overall lenth of the data read into the internal buffer.
3174
lpfc_idiag_extacc_alloc_get(struct lpfc_hba *phba, char *pbuffer, int len)
3176
uint16_t ext_cnt, ext_size;
3179
len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3180
"\nAllocated Extents Information:\n");
3182
len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3183
"\tHost Allocated VPI extents: ");
3184
rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VPI,
3185
&ext_cnt, &ext_size);
3187
len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3188
"Port %d Extent %3d, Size %3d\n",
3189
phba->brd_no, ext_cnt, ext_size);
3191
len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3194
len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3195
"\tHost Allocated VFI extents: ");
3196
rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VFI,
3197
&ext_cnt, &ext_size);
3199
len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3200
"Port %d Extent %3d, Size %3d\n",
3201
phba->brd_no, ext_cnt, ext_size);
3203
len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3206
len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3207
"\tHost Allocated RPI extents: ");
3208
rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_RPI,
3209
&ext_cnt, &ext_size);
3211
len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3212
"Port %d Extent %3d, Size %3d\n",
3213
phba->brd_no, ext_cnt, ext_size);
3215
len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3218
len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3219
"\tHost Allocated XRI extents: ");
3220
rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_XRI,
3221
&ext_cnt, &ext_size);
3223
len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3224
"Port %d Extent %3d, Size %3d\n",
3225
phba->brd_no, ext_cnt, ext_size);
3227
len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3234
* lpfc_idiag_extacc_drivr_get - get driver extent information
3235
* @phba: pointer to lpfc hba data structure.
3236
* @pbuffer: pointer to internal buffer.
3237
* @len: length into the internal buffer data has been copied.
3240
* This routine is to get the driver extent information.
3243
* overall lenth of the data read into the internal buffer.
3246
lpfc_idiag_extacc_drivr_get(struct lpfc_hba *phba, char *pbuffer, int len)
3248
struct lpfc_rsrc_blks *rsrc_blks;
3251
len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3252
"\nDriver Extents Information:\n");
3254
len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3255
"\tVPI extents:\n");
3257
list_for_each_entry(rsrc_blks, &phba->lpfc_vpi_blk_list, list) {
3258
len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3259
"\t\tBlock %3d: Start %4d, Count %4d\n",
3260
index, rsrc_blks->rsrc_start,
3261
rsrc_blks->rsrc_size);
3264
len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3265
"\tVFI extents:\n");
3267
list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_vfi_blk_list,
3269
len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3270
"\t\tBlock %3d: Start %4d, Count %4d\n",
3271
index, rsrc_blks->rsrc_start,
3272
rsrc_blks->rsrc_size);
3276
len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3277
"\tRPI extents:\n");
3279
list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_rpi_blk_list,
3281
len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3282
"\t\tBlock %3d: Start %4d, Count %4d\n",
3283
index, rsrc_blks->rsrc_start,
3284
rsrc_blks->rsrc_size);
3288
len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3289
"\tXRI extents:\n");
3291
list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_xri_blk_list,
3293
len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3294
"\t\tBlock %3d: Start %4d, Count %4d\n",
3295
index, rsrc_blks->rsrc_start,
3296
rsrc_blks->rsrc_size);
3304
* lpfc_idiag_extacc_write - Syntax check and set up idiag extacc commands
3305
* @file: The file pointer to read from.
3306
* @buf: The buffer to copy the user data from.
3307
* @nbytes: The number of bytes to get.
3308
* @ppos: The position in the file to start reading from.
3310
* This routine get the debugfs idiag command struct from user space and then
3311
* perform the syntax check for extent information access commands and sets
3312
* up the necessary states in the idiag command struct accordingly.
3314
* It returns the @nbytges passing in from debugfs user space when successful.
3315
* In case of error conditions, it returns proper error code back to the user
3319
lpfc_idiag_extacc_write(struct file *file, const char __user *buf,
3320
size_t nbytes, loff_t *ppos)
3322
struct lpfc_debug *debug = file->private_data;
3326
/* This is a user write operation */
3327
debug->op = LPFC_IDIAG_OP_WR;
3329
rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
3333
ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
3335
if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
3337
if (rc != LPFC_EXT_ACC_CMD_ARG)
3339
if (!(ext_map & LPFC_EXT_ACC_ALL))
3344
/* Clean out command structure on command error out */
3345
memset(&idiag, 0, sizeof(idiag));
3350
* lpfc_idiag_extacc_read - idiag debugfs read access to extent information
3351
* @file: The file pointer to read from.
3352
* @buf: The buffer to copy the data to.
3353
* @nbytes: The number of bytes to read.
3354
* @ppos: The position in the file to start reading from.
3357
* This routine reads data from the proper extent information according to
3358
* the idiag command, and copies to user @buf.
3361
* This function returns the amount of data that was read (this could be less
3362
* than @nbytes if the end of the file was reached) or a negative error value.
3365
lpfc_idiag_extacc_read(struct file *file, char __user *buf, size_t nbytes,
3368
struct lpfc_debug *debug = file->private_data;
3369
struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3374
/* This is a user read operation */
3375
debug->op = LPFC_IDIAG_OP_RD;
3378
debug->buffer = kmalloc(LPFC_EXT_ACC_BUF_SIZE, GFP_KERNEL);
3381
pbuffer = debug->buffer;
3384
if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
3387
ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
3388
if (ext_map & LPFC_EXT_ACC_AVAIL)
3389
len = lpfc_idiag_extacc_avail_get(phba, pbuffer, len);
3390
if (ext_map & LPFC_EXT_ACC_ALLOC)
3391
len = lpfc_idiag_extacc_alloc_get(phba, pbuffer, len);
3392
if (ext_map & LPFC_EXT_ACC_DRIVR)
3393
len = lpfc_idiag_extacc_drivr_get(phba, pbuffer, len);
3395
return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2332
3398
#undef lpfc_debugfs_op_disc_trc
2333
3399
static const struct file_operations lpfc_debugfs_op_disc_trc = {
2334
3400
.owner = THIS_MODULE,
2447
3533
.release = lpfc_idiag_cmd_release,
3536
#undef lpfc_idiag_op_ctlAcc
3537
static const struct file_operations lpfc_idiag_op_ctlAcc = {
3538
.owner = THIS_MODULE,
3539
.open = lpfc_idiag_open,
3540
.llseek = lpfc_debugfs_lseek,
3541
.read = lpfc_idiag_ctlacc_read,
3542
.write = lpfc_idiag_ctlacc_write,
3543
.release = lpfc_idiag_cmd_release,
3546
#undef lpfc_idiag_op_mbxAcc
3547
static const struct file_operations lpfc_idiag_op_mbxAcc = {
3548
.owner = THIS_MODULE,
3549
.open = lpfc_idiag_open,
3550
.llseek = lpfc_debugfs_lseek,
3551
.read = lpfc_idiag_mbxacc_read,
3552
.write = lpfc_idiag_mbxacc_write,
3553
.release = lpfc_idiag_cmd_release,
3556
#undef lpfc_idiag_op_extAcc
3557
static const struct file_operations lpfc_idiag_op_extAcc = {
3558
.owner = THIS_MODULE,
3559
.open = lpfc_idiag_open,
3560
.llseek = lpfc_debugfs_lseek,
3561
.read = lpfc_idiag_extacc_read,
3562
.write = lpfc_idiag_extacc_write,
3563
.release = lpfc_idiag_cmd_release,
3568
/* lpfc_idiag_mbxacc_dump_bsg_mbox - idiag debugfs dump bsg mailbox command
3569
* @phba: Pointer to HBA context object.
3570
* @dmabuf: Pointer to a DMA buffer descriptor.
3573
* This routine dump a bsg pass-through non-embedded mailbox command with
3577
lpfc_idiag_mbxacc_dump_bsg_mbox(struct lpfc_hba *phba, enum nemb_type nemb_tp,
3578
enum mbox_type mbox_tp, enum dma_type dma_tp,
3579
enum sta_type sta_tp,
3580
struct lpfc_dmabuf *dmabuf, uint32_t ext_buf)
3582
#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3583
uint32_t *mbx_mbox_cmd, *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt;
3584
char line_buf[LPFC_MBX_ACC_LBUF_SZ];
3586
uint32_t do_dump = 0;
3590
if (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP)
3593
mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
3594
mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
3595
mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
3596
mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
3598
if (!(*mbx_dump_map & LPFC_MBX_DMP_ALL) ||
3599
(*mbx_dump_cnt == 0) ||
3600
(*mbx_word_cnt == 0))
3603
if (*mbx_mbox_cmd != 0x9B)
3606
if ((mbox_tp == mbox_rd) && (dma_tp == dma_mbox)) {
3607
if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_MBX) {
3608
do_dump |= LPFC_BSG_DMP_MBX_RD_MBX;
3609
printk(KERN_ERR "\nRead mbox command (x%x), "
3610
"nemb:0x%x, extbuf_cnt:%d:\n",
3611
sta_tp, nemb_tp, ext_buf);
3614
if ((mbox_tp == mbox_rd) && (dma_tp == dma_ebuf)) {
3615
if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_BUF) {
3616
do_dump |= LPFC_BSG_DMP_MBX_RD_BUF;
3617
printk(KERN_ERR "\nRead mbox buffer (x%x), "
3618
"nemb:0x%x, extbuf_seq:%d:\n",
3619
sta_tp, nemb_tp, ext_buf);
3622
if ((mbox_tp == mbox_wr) && (dma_tp == dma_mbox)) {
3623
if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_MBX) {
3624
do_dump |= LPFC_BSG_DMP_MBX_WR_MBX;
3625
printk(KERN_ERR "\nWrite mbox command (x%x), "
3626
"nemb:0x%x, extbuf_cnt:%d:\n",
3627
sta_tp, nemb_tp, ext_buf);
3630
if ((mbox_tp == mbox_wr) && (dma_tp == dma_ebuf)) {
3631
if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_BUF) {
3632
do_dump |= LPFC_BSG_DMP_MBX_WR_BUF;
3633
printk(KERN_ERR "\nWrite mbox buffer (x%x), "
3634
"nemb:0x%x, extbuf_seq:%d:\n",
3635
sta_tp, nemb_tp, ext_buf);
3639
/* dump buffer content */
3641
pword = (uint32_t *)dmabuf->virt;
3642
for (i = 0; i < *mbx_word_cnt; i++) {
3645
printk(KERN_ERR "%s\n", line_buf);
3647
len += snprintf(line_buf+len,
3648
LPFC_MBX_ACC_LBUF_SZ-len,
3651
len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
3652
"%08x ", (uint32_t)*pword);
3656
printk(KERN_ERR "%s\n", line_buf);
3660
/* Clean out command structure on reaching dump count */
3661
if (*mbx_dump_cnt == 0)
3662
memset(&idiag, 0, sizeof(idiag));
3667
/* lpfc_idiag_mbxacc_dump_issue_mbox - idiag debugfs dump issue mailbox command
3668
* @phba: Pointer to HBA context object.
3669
* @dmabuf: Pointer to a DMA buffer descriptor.
3672
* This routine dump a pass-through non-embedded mailbox command from issue
3676
lpfc_idiag_mbxacc_dump_issue_mbox(struct lpfc_hba *phba, MAILBOX_t *pmbox)
3678
#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3679
uint32_t *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt, *mbx_mbox_cmd;
3680
char line_buf[LPFC_MBX_ACC_LBUF_SZ];
3686
if (idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP)
3689
mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
3690
mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
3691
mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
3692
mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
3694
if (!(*mbx_dump_map & LPFC_MBX_DMP_MBX_ALL) ||
3695
(*mbx_dump_cnt == 0) ||
3696
(*mbx_word_cnt == 0))
3699
if ((*mbx_mbox_cmd != LPFC_MBX_ALL_CMD) &&
3700
(*mbx_mbox_cmd != pmbox->mbxCommand))
3703
/* dump buffer content */
3704
if (*mbx_dump_map & LPFC_MBX_DMP_MBX_WORD) {
3705
printk(KERN_ERR "Mailbox command:0x%x dump by word:\n",
3707
pword = (uint32_t *)pmbox;
3708
for (i = 0; i < *mbx_word_cnt; i++) {
3711
printk(KERN_ERR "%s\n", line_buf);
3713
memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
3714
len += snprintf(line_buf+len,
3715
LPFC_MBX_ACC_LBUF_SZ-len,
3718
len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
3720
((uint32_t)*pword) & 0xffffffff);
3724
printk(KERN_ERR "%s\n", line_buf);
3725
printk(KERN_ERR "\n");
3727
if (*mbx_dump_map & LPFC_MBX_DMP_MBX_BYTE) {
3728
printk(KERN_ERR "Mailbox command:0x%x dump by byte:\n",
3730
pbyte = (uint8_t *)pmbox;
3731
for (i = 0; i < *mbx_word_cnt; i++) {
3734
printk(KERN_ERR "%s\n", line_buf);
3736
memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
3737
len += snprintf(line_buf+len,
3738
LPFC_MBX_ACC_LBUF_SZ-len,
3741
for (j = 0; j < 4; j++) {
3742
len += snprintf(line_buf+len,
3743
LPFC_MBX_ACC_LBUF_SZ-len,
3745
((uint8_t)*pbyte) & 0xff);
3748
len += snprintf(line_buf+len,
3749
LPFC_MBX_ACC_LBUF_SZ-len, " ");
3752
printk(KERN_ERR "%s\n", line_buf);
3753
printk(KERN_ERR "\n");
3757
/* Clean out command structure on reaching dump count */
3758
if (*mbx_dump_cnt == 0)
3759
memset(&idiag, 0, sizeof(idiag));
2453
3765
* lpfc_debugfs_initialize - Initialize debugfs for a vport