⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qla2x00.c

📁 QL2000卡的驱动程序,可以学习驱动的编程. 对于UNIX的I/O操作有帮助!
💻 C
📖 第 1 页 / 共 5 页
字号:
#define	CMD_SNSP(Cmnd)		(Cmnd)->sense_buffer#define	CMD_SNSLEN(Cmnd)	(sizeof (Cmnd)->sense_buffer)#define	CMD_RESULT(Cmnd)	((Cmnd)->result)#define	CMD_HANDLE(Cmnd)	((Cmnd)->host_scribble)#define	CMD_TIMEOUT(Cmnd)	((Cmnd)->timeout_per_command)#define DID_RETRY		DID_ERROR/** Macros use for debugging the driver.*/#ifdef QL_DEBUG_LEVEL_3#define ENTER(x)	sprintf(debug_buff,"qla2100 : Entering %s()\n\r", x); \ qla2100_print(debug_buff);#define LEAVE(x)	sprintf(debug_buff,"qla2100 : Leaving %s()\n\r", x); \ qla2100_print(debug_buff);#define ENTER_INTR(x)	sprintf(debug_buff,"qla2100 : Entering %s()\n\r", x); \ qla2100_print(debug_buff);#define LEAVE_INTR(x)	sprintf(debug_buff,"qla2100 : Leaving %s()\n\r", x); \ qla2100_print(debug_buff);#define DEBUG3(x)	x#else#define ENTER(x)#define LEAVE(x)#define ENTER_INTR(x)#define LEAVE_INTR(x)#define DEBUG3(x)#endif#if  QLA2100_COMTRACE#define COMTRACE(x)     qla2100_putc(x);#else#define COMTRACE(x)#endif#if  DEBUG_QLA2100#define DEBUG(x)	x#define DEBUG4(x)#else#define DEBUG(x)#define DEBUG4(x)#endif#ifdef QL_DEBUG_LEVEL_2#define DEBUG2(x)          x#else#define DEBUG2(x)#endif#ifdef QL_DEBUG_LEVEL_5#define DEBUG5(x)          x#else#define DEBUG5(x)#endif/****************************************************************************//*  LINUX -  Loadable Module Functions.                                     *//****************************************************************************//*****************************************//*   ISP Boards supported by this driver *//*****************************************/#define QLA2100_VENDOR_ID   0x1077#define QLA2100_DEVICE_ID   0x2100#define QLA2200_DEVICE_ID   0x2200#define QLA2200A_DEVICE_ID  0x2200A#define QLA2200A_RISC_ROM_VER  4#define NUM_OF_ISP_DEVICES        3typedef struct _qlaboards{unsigned char   bdName[9];       /* Board ID String             */unsigned long   device_id;       /* Device ID                   */int   numPorts;                  /* number of loops on adapter  */unsigned short   *fwcode;        /* pointer to FW array         */unsigned long    *fwlen;         /* number of words in array    */unsigned short   *fwstart;       /* start address for F/W       */unsigned char   *fwver;          /* Ptr to F/W version array    */} qla_boards_t;struct _qlaboards   QLBoardTbl[NUM_OF_ISP_DEVICES] ={/* Name ,  Board PCI Device ID,         Number of ports */{"QLA2100 ", QLA2100_DEVICE_ID,           MAX_BUSES,&fw2100ef_code01[0],  (unsigned long *)&fw2100ef_length01,&fw2100ef_addr01, &fw2100ef_version_str[0] },{"QLA2200 ", QLA2200_DEVICE_ID,           MAX_BUSES,#ifdef FC_IP_SUPPORT&fw2200ip_code01[0],  (unsigned long *)&fw2200ip_length01, &fw2200ip_addr01, &fw2200ip_version_str[0] },#else&fw2200ef_code01[0],  (unsigned long *)&fw2200ef_length01, &fw2200ef_addr01, &fw2200ef_version_str[0] },#endif{"        ",                 0,           0}};/** Stat info*/static struct _qla2100stats  {unsigned long   mboxtout;            /* mailbox timeouts */unsigned long   mboxerr;             /* mailbox errors */unsigned long   ispAbort;            /* ISP aborts */unsigned long   debugNo;unsigned long   loop_resync;unsigned long   outarray_full;unsigned long   retry_q_cnt;unsigned long   done_q_cnt;scsi_qla_host_t *irqhba;} qla2100_stats;/** Command line options*/static unsigned long qla2100_verbose = 1L;static unsigned long qla2100_reinit = 1L;static unsigned long qla2100_req_dmp = 0L;static scsi_qla_host_t *qla2100_hostlist = NULL;/**************************************************************************   qla2100_set_info** Description:*   Set parameters for the driver from the /proc filesystem.** Returns:*************************************************************************/intqla2100_set_info(char *buffer, int length, struct Scsi_Host *HBAptr) {    return (-ENOSYS);  /* Currently this is a no-op */}/**************************************************************************   qla2100_ioctl** Description:*   Performs ioctl requests not satified by the upper levels.** Returns:*************************************************************************/intqla2100_ioctl(Scsi_Device *dev, int cmd, void *arg) {    /* Not implemented */    return 0;}/************************************************************************** qla2100_proc_info** Description:*   Return information to handle /proc support for the driver.** inout : decides on the direction of the dataflow and the meaning of the*         variables* buffer: If inout==FALSE data is being written to it else read from it*         (ptrs to a page buffer)* *start: If inout==FALSE start of the valid data in the buffer* offset: If inout==FALSE offset from the beginning of the imaginary file*         from which we start writing into the buffer* length: If inout==FALSE max number of bytes to be written into the buffer*         else number of bytes in the buffer* Returns:*************************************************************************/#define	PROC_BUF	(&qla2100_buffer[len])intqla2100_proc_info( char *buffer, char **start, off_t offset, int length,int hostno, int inout) {#if QLA2100_PROFILE    struct Scsi_Host *host;    scsi_qla_host_t *ha;    int    size = 0;    scsi_lu_t  *up;    int   len = 0;    qla_boards_t   *bdp;    uint32_t        t, l;#if REQ_TRACE    Scsi_Cmnd       *cp;    srb_t           *sp;    int i;#endif        DEBUG5(printk("Entering proc_info 0x%x,0x%lx,0x%x,0x%x\n",(int)buffer,offset,length,hostno);)    host = NULL;    /* Find the host that was specified */    for( ha=qla2100_hostlist; (ha != NULL) && ha->host->host_no != hostno; ha=ha->next )        ;    /* if host wasn't found then exit */    if( !ha ) {        size = sprintf(buffer, "Can't find adapter for host number %d\n", hostno);        if( size > length ) {            return (size);        } else {            return (0);        }    }    host = ha->host;    if( inout == TRUE ) /* Has data been written to the file? */    {        printk("qla2100_proc: has data been written to the file. \n");        return (qla2100_set_info(buffer, length, host));    }    /*    * if our old buffer is the right size use it otherwise    * allocate a new one.    */    size = 4096;  /* get a page */    if( qla2100_buffer_size != size ) {        /* deallocate this buffer and get a new one */        if( qla2100_buffer != NULL ) {            kfree(qla2100_buffer);            qla2100_buffer_size = 0;        }        qla2100_buffer = kmalloc(size, GFP_KERNEL);    }    if( qla2100_buffer == NULL ) {        size = sprintf(buffer, "qla2100 - kmalloc error at line %d\n",        __LINE__);        return size;    }    /* save the size of our buffer */    qla2100_buffer_size = size;    /* start building the print buffer */    bdp = &QLBoardTbl[ha->devnum];    qla2100_lip = 1;    size =  sprintf(PROC_BUF,    "QLogic PCI to Fibre Channel Host Adapter for ISP2100/ISP2200/ISP2200A:\n"     /* 72 */    "        Firmware version: %2d.%02d.%02d, Driver version %s\n",                /* 66 */    bdp->fwver[0], bdp->fwver[1], bdp->fwver[2], QLA2100_VERSION);    len += size;    size = sprintf(PROC_BUF, "SCSI Host Adapter Information: %s\n", bdp->bdName);    len += size;    size = sprintf(PROC_BUF, "Request Queue = 0x%lx, Response Queue = 0x%lx\n",    (long unsigned int)ha->request_dma,    (long unsigned int)ha->response_dma);    len += size;    size = sprintf(PROC_BUF, "Request Queue count= %ld, Response Queue count= %ld\n",    (long)REQUEST_ENTRY_CNT,    (long)RESPONSE_ENTRY_CNT);    len += size;    size = sprintf(PROC_BUF, "Number of pending commands = 0x%lx\n", ha->actthreads);    len += size;    size = sprintf(PROC_BUF, "Number of queued commands = 0x%lx\n", ha->qthreads);    len += size;    size = sprintf(PROC_BUF, "Number of free request entries = %d\n",ha->req_q_cnt);    len += size;    size = sprintf(PROC_BUF, "Number of mailbox timeouts = %ld\n",qla2100_stats.mboxtout);    len += size;    size = sprintf(PROC_BUF, "Number of ISP aborts = %ld\n",qla2100_stats.ispAbort);    len += size;    size = sprintf(PROC_BUF, "Number of loop resyncs = %ld\n",qla2100_stats.ispAbort);    len += size;    size = sprintf(PROC_BUF, "Number of retries for empty slots = %ld\n",qla2100_stats.outarray_full);    len += size;    size = sprintf(PROC_BUF, "Number of reqs in retry_q = %ld\n",qla2100_stats.retry_q_cnt);    len += size;    size = sprintf(PROC_BUF, "Number of reqs in done_q = %ld\n",qla2100_stats.done_q_cnt);    len += size;    size = sprintf(PROC_BUF, "\n");    len += size;#if REQ_TRACE    if ( qla2100_req_dmp ) {    	size  = sprintf(PROC_BUF,"Outstanding Commands on controller:\n");    	len += size;    	for( i=0; i < MAX_OUTSTANDING_COMMANDS; i++ ) {      	if( (sp = ha->outstanding_cmds[i]) == NULL )                 	continue;      	if( (cp = sp->cmd) == NULL )               continue;      	size = sprintf(PROC_BUF,"(%d): Pid=%d, sp flags=0x%lx, cmd=0x%x, state=%d\r", i, (int)sp->cmd->pid, (long)sp->flags,(int)CMD_SP(sp->cmd),(int)sp->state);      	len += size;        if( len >= qla2100_buffer_size )                goto profile_stop;    	}    }#endif    size = sprintf(PROC_BUF, "SCSI device Information:\n");    len += size;    size = sprintf(PROC_BUF, "(Id:Lun)\n");    len += size;    /* scan for all equipment stats */    for (t = 0; t < MAX_FIBRE_DEVICES; t++) {        /* valid target */        if (ha->fc_db[t].loop_id == PORT_UNUSED)            continue;        /* scan all luns */        for( l = 0; l < ha->max_luns; l++ ) {            up = (scsi_lu_t *) GET_LU_Q(ha, 0, t, l);            if( up == NULL )                continue;            if( up->io_cnt == 0 || up->io_cnt < 5)                continue;            /* total reads since boot */            /* total writes since boot */            /* total requests since boot  */            size = sprintf(PROC_BUF, "(%2d:%2d): Total reqs %ld,",t,l,up->io_cnt);            len += size;            /* current number of pending requests */            size = sprintf(PROC_BUF, " Pending reqs %d,",up->q_outcnt);            len += size;            /* current number of pending requests */            size = sprintf(PROC_BUF, " Queued reqs %d,",up->q_incnt);            len += size;#if 0            /* avg response time */            size = sprintf(PROC_BUF, " Avg resp time %d(s),",(up->resp_time/up->io_cnt)/HZ);            len += size;            /* avg active time */            size = sprintf(PROC_BUF, " Avg disk time %d(s)\n",(up->act_time/up->io_cnt)/HZ);            len += size;#endif            size = sprintf(PROC_BUF, "\n");            len += size;            if( len >= qla2100_buffer_size )                goto profile_stop;        }        if( len >= qla2100_buffer_size )            break;    }    profile_stop:    if( len >= qla2100_buffer_size ) {        printk(KERN_WARNING "qla2100: Overflow buffer in qla2100_proc.c\n");    }    if( offset > len - 1 ) {        kfree(qla2100_buffer);        qla2100_buffer = NULL;        qla2100_buffer_size = length = 0;        *start = NULL;    } else {        *start = &qla2100_buffer[offset];   /* Start of wanted data */        if( len - offset < length ) {            length = len - offset;        }    }    return (length);#else    return (0);#endif}/**************************************************************************

⌨️ 快捷键说明

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