linux/drivers/staging/cxt1e1/sbeproc.c
<<
>>
Prefs
   1/* Copyright (C) 2004-2005  SBE, Inc.
   2 *
   3 *   This program is free software; you can redistribute it and/or modify
   4 *   it under the terms of the GNU General Public License as published by
   5 *   the Free Software Foundation; either version 2 of the License, or
   6 *   (at your option) any later version.
   7 *
   8 *   This program is distributed in the hope that it will be useful,
   9 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  10 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11 *   GNU General Public License for more details.
  12 */
  13
  14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  15
  16#include <linux/types.h>
  17#include <linux/module.h>
  18#include <linux/errno.h>
  19#include <linux/kernel.h>
  20#include <linux/init.h>
  21#include <linux/proc_fs.h>
  22#include <linux/seq_file.h>
  23#include <linux/sched.h>
  24#include <asm/uaccess.h>
  25#include "pmcc4_sysdep.h"
  26#include "sbecom_inline_linux.h"
  27#include "pmcc4_private.h"
  28#include "sbeproc.h"
  29
  30extern void sbecom_get_brdinfo(ci_t *, struct sbe_brd_info *, u_int8_t *);
  31extern struct s_hdw_info hdw_info[MAX_BOARDS];
  32
  33void sbecom_proc_brd_cleanup(ci_t *ci)
  34{
  35        if (ci->dir_dev) {
  36                char dir[7 + SBE_IFACETMPL_SIZE + 1];
  37                snprintf(dir, sizeof(dir), "driver/%s", ci->devname);
  38                remove_proc_entry("info", ci->dir_dev);
  39                remove_proc_entry(dir, NULL);
  40                ci->dir_dev = NULL;
  41        }
  42}
  43
  44static void sbecom_proc_get_brdinfo(ci_t *ci, struct sbe_brd_info *bip)
  45{
  46        hdw_info_t *hi = &hdw_info[ci->brdno];
  47        u_int8_t *bsn = NULL;
  48
  49        switch (hi->promfmt)
  50        {
  51        case PROM_FORMAT_TYPE1:
  52                bsn = (u_int8_t *) hi->mfg_info.pft1.Serial;
  53                break;
  54        case PROM_FORMAT_TYPE2:
  55                bsn = (u_int8_t *) hi->mfg_info.pft2.Serial;
  56                break;
  57        }
  58
  59        sbecom_get_brdinfo (ci, bip, bsn);
  60
  61        pr_devel(">> sbecom_get_brdinfo: returned, first_if %p <%s> last_if %p <%s>\n",
  62                 bip->first_iname, bip->first_iname,
  63                 bip->last_iname, bip->last_iname);
  64}
  65
  66/*
  67 * Describe the driver state through /proc
  68 */
  69static int sbecom_proc_get_sbe_info(struct seq_file *m, void *v)
  70{
  71        ci_t       *ci = m->private;
  72        char       *spd;
  73        struct sbe_brd_info *bip;
  74
  75        bip = OS_kmalloc(sizeof(struct sbe_brd_info));
  76        if (!bip)
  77                return -ENOMEM;
  78
  79        pr_devel(">> sbecom_proc_get_sbe_info: entered\n");
  80
  81        sbecom_proc_get_brdinfo(ci, bip);
  82
  83        seq_puts(m, "Board Type:    ");
  84        switch (bip->brd_id) {
  85        case SBE_BOARD_ID(PCI_VENDOR_ID_SBE, PCI_DEVICE_ID_WANPMC_C1T3):
  86                seq_puts(m, "wanPMC-C1T3");
  87                break;
  88        case SBE_BOARD_ID(PCI_VENDOR_ID_SBE, PCI_DEVICE_ID_WANPTMC_256T3_E1):
  89                seq_puts(m, "wanPTMC-256T3 <E1>");
  90                break;
  91        case SBE_BOARD_ID(PCI_VENDOR_ID_SBE, PCI_DEVICE_ID_WANPTMC_256T3_T1):
  92                seq_puts(m, "wanPTMC-256T3 <T1>");
  93                break;
  94        case SBE_BOARD_ID(PCI_VENDOR_ID_SBE, PCI_DEVICE_ID_WANPTMC_C24TE1):
  95                seq_puts(m, "wanPTMC-C24TE1");
  96                break;
  97
  98        case SBE_BOARD_ID(PCI_VENDOR_ID_SBE, PCI_DEVICE_ID_WANPMC_C4T1E1):
  99        case SBE_BOARD_ID(PCI_VENDOR_ID_SBE, PCI_DEVICE_ID_WANPMC_C4T1E1_L):
 100                seq_puts(m, "wanPMC-C4T1E1");
 101                break;
 102        case SBE_BOARD_ID(PCI_VENDOR_ID_SBE, PCI_DEVICE_ID_WANPMC_C2T1E1):
 103        case SBE_BOARD_ID(PCI_VENDOR_ID_SBE, PCI_DEVICE_ID_WANPMC_C2T1E1_L):
 104                seq_puts(m, "wanPMC-C2T1E1");
 105                break;
 106        case SBE_BOARD_ID(PCI_VENDOR_ID_SBE, PCI_DEVICE_ID_WANPMC_C1T1E1):
 107        case SBE_BOARD_ID(PCI_VENDOR_ID_SBE, PCI_DEVICE_ID_WANPMC_C1T1E1_L):
 108                seq_puts(m, "wanPMC-C1T1E1");
 109                break;
 110
 111        case SBE_BOARD_ID(PCI_VENDOR_ID_SBE, PCI_DEVICE_ID_WANPCI_C4T1E1):
 112                seq_puts(m, "wanPCI-C4T1E1");
 113                break;
 114        case SBE_BOARD_ID(PCI_VENDOR_ID_SBE, PCI_DEVICE_ID_WANPCI_C2T1E1):
 115                seq_puts(m, "wanPCI-C2T1E1");
 116                break;
 117        case SBE_BOARD_ID(PCI_VENDOR_ID_SBE, PCI_DEVICE_ID_WANPCI_C1T1E1):
 118                seq_puts(m, "wanPCI-C1T1E1");
 119                break;
 120
 121        default:
 122                seq_puts(m, "unknown");
 123                break;
 124        }
 125
 126        seq_printf(m, "  [%08X]\n", bip->brd_id);
 127
 128        seq_printf(m, "Board Number:  %d\n", bip->brdno);
 129        seq_printf(m, "Hardware ID:   0x%02X\n", ci->hdw_bid);
 130        seq_printf(m, "Board SN:      %06X\n", bip->brd_sn);
 131        seq_printf(m, "Board MAC:     %pMF\n", bip->brd_mac_addr);
 132        seq_printf(m, "Ports:         %d\n", ci->max_port);
 133        seq_printf(m, "Channels:      %d\n", bip->brd_chan_cnt);
 134#if 1
 135        seq_printf(m, "Interface:     %s -> %s\n",
 136                   bip->first_iname, bip->last_iname);
 137#else
 138        seq_printf(m, "Interface:     <not available> 1st %p lst %p\n",
 139                   bip->first_iname, bip->last_iname);
 140#endif
 141
 142        switch (bip->brd_pci_speed) {
 143        case BINFO_PCI_SPEED_33:
 144                spd = "33Mhz";
 145                break;
 146        case BINFO_PCI_SPEED_66:
 147                spd = "66Mhz";
 148                break;
 149        default:
 150                spd = "<not available>";
 151                break;
 152        }
 153        seq_printf(m, "PCI Bus Speed: %s\n", spd);
 154
 155#ifdef SBE_PMCC4_ENABLE
 156        {
 157                extern int cxt1e1_max_mru;
 158#if 0
 159                extern int max_chans_used;
 160                extern int cxt1e1_max_mtu;
 161#endif
 162                extern int max_rxdesc_used, max_txdesc_used;
 163
 164                seq_printf(m, "\ncxt1e1_max_mru:         %d\n", cxt1e1_max_mru);
 165#if 0
 166                seq_printf(m, "\nmax_chans_used:  %d\n", max_chans_used);
 167                seq_printf(m, "cxt1e1_max_mtu:         %d\n", cxt1e1_max_mtu);
 168#endif
 169                seq_printf(m, "max_rxdesc_used: %d\n", max_rxdesc_used);
 170                seq_printf(m, "max_txdesc_used: %d\n", max_txdesc_used);
 171        }
 172#endif
 173
 174        kfree(bip);
 175
 176        pr_devel(">> proc_fs: finished\n");
 177        return 0;
 178}
 179
 180/*
 181 * seq_file wrappers for procfile show routines.
 182 */
 183static int sbecom_proc_open(struct inode *inode, struct file *file)
 184{
 185        return single_open(file, sbecom_proc_get_sbe_info, PDE_DATA(inode));
 186}
 187
 188static const struct file_operations sbecom_proc_fops = {
 189        .open           = sbecom_proc_open,
 190        .read           = seq_read,
 191        .llseek         = seq_lseek,
 192        .release        = single_release,
 193};
 194
 195/*
 196 * Initialize the /proc subsystem for the specific SBE driver
 197 */
 198int __init sbecom_proc_brd_init(ci_t *ci)
 199{
 200        char dir[7 + SBE_IFACETMPL_SIZE + 1];
 201
 202        snprintf(dir, sizeof(dir), "driver/%s", ci->devname);
 203        ci->dir_dev = proc_mkdir(dir, NULL);
 204        if (!ci->dir_dev) {
 205                pr_err("Unable to create directory /proc/driver/%s\n", ci->devname);
 206                goto fail;
 207        }
 208
 209        if (!proc_create_data("info", S_IFREG | S_IRUGO, ci->dir_dev,
 210                              &sbecom_proc_fops, ci)) {
 211                pr_err("Unable to create entry /proc/driver/%s/info\n", ci->devname);
 212                goto fail;
 213        }
 214        return 0;
 215
 216fail:
 217        sbecom_proc_brd_cleanup(ci);
 218        return 1;
 219}
 220