gdth_proc.c

来自「Linux Kernel 2.6.9 for OMAP1710」· C语言 代码 · 共 1,112 行 · 第 1/3 页

C
1,112
字号
/* gdth_proc.c  * $Id: gdth_proc.c,v 1.42 2004/03/05 15:50:20 achim Exp $ */#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,7)#include <linux/completion.h>#endif#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)int gdth_proc_info(struct Scsi_Host *host, char *buffer,char **start,off_t offset,int length,                      int inout){    int hanum,busnum;    TRACE2(("gdth_proc_info() length %d offs %d inout %d\n",            length,(int)offset,inout));    hanum = NUMDATA(host)->hanum;    busnum= NUMDATA(host)->busnum;    if (inout)        return(gdth_set_info(buffer,length,host,hanum,busnum));    else        return(gdth_get_info(buffer,start,offset,length,host,hanum,busnum));}#elseint gdth_proc_info(char *buffer,char **start,off_t offset,int length,int hostno,                      int inout){    int hanum,busnum,i;    TRACE2(("gdth_proc_info() length %d offs %d inout %d\n",            length,(int)offset,inout));    for (i = 0; i < gdth_ctr_vcount; ++i) {        if (gdth_ctr_vtab[i]->host_no == hostno)            break;    }    if (i == gdth_ctr_vcount)        return(-EINVAL);    hanum = NUMDATA(gdth_ctr_vtab[i])->hanum;    busnum= NUMDATA(gdth_ctr_vtab[i])->busnum;    if (inout)        return(gdth_set_info(buffer,length,gdth_ctr_vtab[i],hanum,busnum));    else        return(gdth_get_info(buffer,start,offset,length,                             gdth_ctr_vtab[i],hanum,busnum));}#endifstatic int gdth_set_info(char *buffer,int length,struct Scsi_Host *host,                         int hanum,int busnum){    int             ret_val = -EINVAL;#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)    Scsi_Request    *scp;    Scsi_Device     *sdev;#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)    Scsi_Cmnd       *scp;    Scsi_Device     *sdev;#else    Scsi_Cmnd       scp;    Scsi_Device     sdev;#endif    TRACE2(("gdth_set_info() ha %d bus %d\n",hanum,busnum));#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)    sdev = scsi_get_host_dev(host);    scp  = scsi_allocate_request(sdev, GFP_KERNEL);    if (!scp)        return -ENOMEM;    scp->sr_cmd_len = 12;    scp->sr_use_sg = 0;#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)    sdev = scsi_get_host_dev(host);    scp  = scsi_allocate_device(sdev, 1, FALSE);    if (!scp)        return -ENOMEM;    scp->cmd_len = 12;    scp->use_sg = 0;#else    memset(&sdev,0,sizeof(Scsi_Device));    memset(&scp, 0,sizeof(Scsi_Cmnd));    sdev.host = scp.host = host;    sdev.id = scp.target = sdev.host->this_id;    scp.device = &sdev;#endif    if (length >= 4) {        if (strncmp(buffer,"gdth",4) == 0) {            buffer += 5;            length -= 5;            ret_val = gdth_set_asc_info( buffer, length, hanum, scp );        }    }#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)    scsi_release_request(scp);    scsi_free_host_dev(sdev);#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)    scsi_release_command(scp);    scsi_free_host_dev(sdev);#endif    return ret_val;}         #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)static int gdth_set_asc_info(char *buffer,int length,int hanum,Scsi_Request *scp)#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)static int gdth_set_asc_info(char *buffer,int length,int hanum,Scsi_Cmnd *scp)#elsestatic int gdth_set_asc_info(char *buffer,int length,int hanum,Scsi_Cmnd scp)#endif{    int             orig_length, drive, wb_mode;    int             i, found;    gdth_ha_str     *ha;    gdth_cmd_str    gdtcmd;    gdth_cpar_str   *pcpar;    ulong64         paddr;    char            cmnd[MAX_COMMAND_SIZE];    memset(cmnd, 0xff, 12);    memset(&gdtcmd, 0, sizeof(gdth_cmd_str));    TRACE2(("gdth_set_asc_info() ha %d\n",hanum));    ha = HADATA(gdth_ctr_tab[hanum]);    orig_length = length + 5;    drive = -1;    wb_mode = 0;    found = FALSE;    if (length >= 5 && strncmp(buffer,"flush",5)==0) {        buffer += 6;        length -= 6;        if (length && *buffer>='0' && *buffer<='9') {            drive = (int)(*buffer-'0');            ++buffer; --length;            if (length && *buffer>='0' && *buffer<='9') {                drive = drive*10 + (int)(*buffer-'0');                ++buffer; --length;            }            printk("GDT: Flushing host drive %d .. ",drive);        } else {            printk("GDT: Flushing all host drives .. ");        }        for (i = 0; i < MAX_HDRIVES; ++i) {            if (ha->hdr[i].present) {                if (drive != -1 && i != drive)                    continue;                found = TRUE;                gdtcmd.Service = CACHESERVICE;                gdtcmd.OpCode = GDT_FLUSH;                if (ha->cache_feat & GDT_64BIT) {                    gdtcmd.u.cache64.DeviceNo = i;                    gdtcmd.u.cache64.BlockNo = 1;                } else {                    gdtcmd.u.cache.DeviceNo = i;                    gdtcmd.u.cache.BlockNo = 1;                }#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)                gdth_do_req(scp, &gdtcmd, cmnd, 30);#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)                gdth_do_cmd(scp, &gdtcmd, cmnd, 30);#else                gdth_do_cmd(&scp, &gdtcmd, cmnd, 30);#endif            }        }        if (!found)            printk("\nNo host drive found !\n");        else            printk("Done.\n");        return(orig_length);    }    if (length >= 7 && strncmp(buffer,"wbp_off",7)==0) {        buffer += 8;        length -= 8;        printk("GDT: Disabling write back permanently .. ");        wb_mode = 1;    } else if (length >= 6 && strncmp(buffer,"wbp_on",6)==0) {        buffer += 7;        length -= 7;        printk("GDT: Enabling write back permanently .. ");        wb_mode = 2;    } else if (length >= 6 && strncmp(buffer,"wb_off",6)==0) {        buffer += 7;        length -= 7;        printk("GDT: Disabling write back commands .. ");        if (ha->cache_feat & GDT_WR_THROUGH) {            gdth_write_through = TRUE;            printk("Done.\n");        } else {            printk("Not supported !\n");        }        return(orig_length);    } else if (length >= 5 && strncmp(buffer,"wb_on",5)==0) {        buffer += 6;        length -= 6;        printk("GDT: Enabling write back commands .. ");        gdth_write_through = FALSE;        printk("Done.\n");        return(orig_length);    }    if (wb_mode) {        if (!gdth_ioctl_alloc(hanum, sizeof(gdth_cpar_str), TRUE, &paddr))            return(-EBUSY);        pcpar = (gdth_cpar_str *)ha->pscratch;        memcpy( pcpar, &ha->cpar, sizeof(gdth_cpar_str) );        gdtcmd.Service = CACHESERVICE;        gdtcmd.OpCode = GDT_IOCTL;        gdtcmd.u.ioctl.p_param = paddr;        gdtcmd.u.ioctl.param_size = sizeof(gdth_cpar_str);        gdtcmd.u.ioctl.subfunc = CACHE_CONFIG;        gdtcmd.u.ioctl.channel = INVALID_CHANNEL;        pcpar->write_back = wb_mode==1 ? 0:1;#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)        gdth_do_req(scp, &gdtcmd, cmnd, 30);#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)        gdth_do_cmd(scp, &gdtcmd, cmnd, 30);#else        gdth_do_cmd(&scp, &gdtcmd, cmnd, 30);#endif        gdth_ioctl_free(hanum, GDTH_SCRATCH, ha->pscratch, paddr);        printk("Done.\n");        return(orig_length);    }    printk("GDT: Unknown command: %s  Length: %d\n",buffer,length);    return(-EINVAL);}static int gdth_get_info(char *buffer,char **start,off_t offset,int length,                         struct Scsi_Host *host,int hanum,int busnum){    int size = 0,len = 0;    off_t begin = 0,pos = 0;    gdth_ha_str *ha;    int id, i, j, k, sec, flag;    int no_mdrv = 0, drv_no, is_mirr;    ulong32 cnt;    ulong64 paddr;    gdth_cmd_str gdtcmd;    gdth_evt_str estr;#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)    Scsi_Request *scp;    Scsi_Device *sdev; #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)    Scsi_Cmnd *scp;    Scsi_Device *sdev;#else    Scsi_Cmnd scp;    Scsi_Device sdev;#endif    char hrec[161];    struct timeval tv;    char *buf;    gdth_dskstat_str *pds;    gdth_diskinfo_str *pdi;    gdth_arrayinf_str *pai;    gdth_defcnt_str *pdef;    gdth_cdrinfo_str *pcdi;    gdth_hget_str *phg;    char cmnd[MAX_COMMAND_SIZE];    memset(cmnd, 0xff, 12);    memset(&gdtcmd, 0, sizeof(gdth_cmd_str));    TRACE2(("gdth_get_info() ha %d bus %d\n",hanum,busnum));    ha = HADATA(gdth_ctr_tab[hanum]);#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)    sdev = scsi_get_host_dev(host);    scp  = scsi_allocate_request(sdev, GFP_KERNEL);    if (!scp)        return -ENOMEM;    scp->sr_cmd_len = 12;    scp->sr_use_sg = 0;#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)    sdev = scsi_get_host_dev(host);    scp  = scsi_allocate_device(sdev, 1, FALSE);    if (!scp)        return -ENOMEM;    scp->cmd_len = 12;    scp->use_sg = 0;#else    memset(&sdev,0,sizeof(Scsi_Device));    memset(&scp, 0,sizeof(Scsi_Cmnd));    sdev.host = scp.host = host;    sdev.id = scp.target = sdev.host->this_id;    scp.device = &sdev;#endif            /* request is i.e. "cat /proc/scsi/gdth/0" */     /* format: %-15s\t%-10s\t%-15s\t%s */    /* driver parameters */    size = sprintf(buffer+len,"Driver Parameters:\n");    len += size;  pos = begin + len;    if (reserve_list[0] == 0xff)        strcpy(hrec, "--");    else {        sprintf(hrec, "%d", reserve_list[0]);        for (i = 1;  i < MAX_RES_ARGS; i++) {            if (reserve_list[i] == 0xff)                 break;            sprintf(hrec,"%s,%d", hrec, reserve_list[i]);        }    }    size = sprintf(buffer+len,                   " reserve_mode: \t%d         \treserve_list:  \t%s\n",                   reserve_mode, hrec);    len += size;  pos = begin + len;    size = sprintf(buffer+len,                   " max_ids:      \t%-3d       \thdr_channel:   \t%d\n",                   max_ids, hdr_channel);    len += size;  pos = begin + len;    /* controller information */    size = sprintf(buffer+len,"\nDisk Array Controller Information:\n");    len += size;  pos = begin + len;    if (virt_ctr)        sprintf(hrec, "%s (Bus %d)", ha->binfo.type_string, busnum);    else        strcpy(hrec, ha->binfo.type_string);    size = sprintf(buffer+len,                   " Number:       \t%d         \tName:          \t%s\n",                   hanum, hrec);    len += size;  pos = begin + len;    if (ha->more_proc)        sprintf(hrec, "%d.%02d.%02d-%c%03X",                 (unchar)(ha->binfo.upd_fw_ver>>24),                (unchar)(ha->binfo.upd_fw_ver>>16),                (unchar)(ha->binfo.upd_fw_ver),                ha->bfeat.raid ? 'R':'N',                ha->binfo.upd_revision);    else        sprintf(hrec, "%d.%02d", (unchar)(ha->cpar.version>>8),                (unchar)(ha->cpar.version));    size = sprintf(buffer+len,                   " Driver Ver.:  \t%-10s\tFirmware Ver.: \t%s\n",                   GDTH_VERSION_STR, hrec);    len += size;  pos = begin + len;     if (ha->more_proc) {        /* more information: 1. about controller */        size = sprintf(buffer+len,                       " Serial No.:   \t0x%8X\tCache RAM size:\t%d KB\n",                       ha->binfo.ser_no, ha->binfo.memsize / 1024);        len += size;  pos = begin + len;    }#ifdef GDTH_DMA_STATISTICS    /* controller statistics */    size = sprintf(buffer+len,"\nController Statistics:\n");    len += size;  pos = begin + len;    size = sprintf(buffer+len,                   " 32-bit DMA buffer:\t%lu\t64-bit DMA buffer:\t%lu\n",                   ha->dma32_cnt, ha->dma64_cnt);    len += size;  pos = begin + len;#endif    if (pos < offset) {        len = 0;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?