From owner-freebsd-drivers@FreeBSD.ORG Tue Oct 25 01:52:04 2005 Return-Path: X-Original-To: freebsd-drivers@freebsd.org Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3564616A41F for ; Tue, 25 Oct 2005 01:52:04 +0000 (GMT) (envelope-from hpxchan@gmail.com) Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.194]) by mx1.FreeBSD.org (Postfix) with ESMTP id BE75443D45 for ; Tue, 25 Oct 2005 01:52:03 +0000 (GMT) (envelope-from hpxchan@gmail.com) Received: by xproxy.gmail.com with SMTP id t7so323514wxc for ; Mon, 24 Oct 2005 18:52:03 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=GhN/VOZW+SGWKRuGSShQb2MLnHZQ7d4MF7U82GrN8svQcB+2hvQkCLGV50xuCdumF1pk4DRSjL8oR1jKsIv9se/jNjDnd0IRvnulPOkv0iK5N4npnJDCvkcDmjLNWStdibvzT48TJ7GE9k9Yf+Q/c6WI2y6LM3nBXEVeZhKZj6M= Received: by 10.70.54.3 with SMTP id c3mr3972042wxa; Mon, 24 Oct 2005 18:52:03 -0700 (PDT) Received: by 10.70.103.4 with HTTP; Mon, 24 Oct 2005 18:52:03 -0700 (PDT) Message-ID: <6f77d3330510241852n55f87ddfi99a090b232fe46f3@mail.gmail.com> Date: Mon, 24 Oct 2005 20:52:03 -0500 From: Chandler May To: freebsd-drivers@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Subject: Places to start...? X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Oct 2005 01:52:04 -0000 Hi all, I've been working with Unix for a couple of years (mostly BSD), and I'm fairly competent in C, so I think I'd like to try my luck at device drivers. I have an HP L2000 notebook, and I'm interested in writing a driver for the sound card (all I know at the moment is that it has a Conexant AC'97 codec). Would you be kind enough to share a few links and/or pearls of wisdom to get me started? Chandler May From owner-freebsd-drivers@FreeBSD.ORG Wed Oct 26 03:19:26 2005 Return-Path: X-Original-To: freebsd-drivers@freebsd.org Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 50C0516A41F for ; Wed, 26 Oct 2005 03:19:26 +0000 (GMT) (envelope-from mayong@mail.com) Received: from webmail-outgoing.us4.outblaze.com (webmail-outgoing2.us4.outblaze.com [205.158.62.67]) by mx1.FreeBSD.org (Postfix) with ESMTP id E0FB243D46 for ; Wed, 26 Oct 2005 03:19:25 +0000 (GMT) (envelope-from mayong@mail.com) Received: from unknown (unknown [192.168.9.180]) by webmail-outgoing.us4.outblaze.com (Postfix) with QMQP id B71BF1800287 for ; Wed, 26 Oct 2005 03:19:22 +0000 (GMT) X-OB-Received: from unknown (205.158.62.49) by wfilter.us4.outblaze.com; 26 Oct 2005 03:19:21 -0000 Received: by ws1-1.us4.outblaze.com (Postfix, from userid 1001) id 11BC983C03; Wed, 26 Oct 2005 03:19:20 +0000 (GMT) Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="big5" MIME-Version: 1.0 From: "Yong Ma" To: freebsd-drivers@freebsd.org Date: Tue, 25 Oct 2005 22:19:19 -0500 Received: from [159.226.5.225] by ws1-1.us4.outblaze.com with http for mayong@mail.com; Tue, 25 Oct 2005 22:19:19 -0500 X-Originating-Ip: 159.226.5.225 X-Originating-Server: ws1-1.us4.outblaze.com Message-Id: <20051026031920.11BC983C03@ws1-1.us4.outblaze.com> Subject: Cryptography Driver (Help !!!!) X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Oct 2005 03:19:26 -0000 Dear colleagues,=20 Cry for help!!!! The cryptography card driver (polling mode, not interrupt mode) works well= =20 under linux-2.4, but not working under FreeBSD-5.4. The DMA buffer just keep intact under FreeBSD-5.4 after the Random value generation command=20 has been issued. Every thing is compared, but it still not working. Thanks alot Following is the Linux and FreeBSD files: The cryptography card driver under Linux 2.4: ///////////////////////////////////////////////////////////// #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "sjy22bdrv.h" /* lilin changed*/ u_char *dma_buffer; struct pci_dev *pdev =3D NULL; dma_addr_t dma_addr; /* time out vars and function */// lilin adding volatile unsigned long isdmatimeout=3D0; volatile unsigned long iscardtimeout=3D0; struct timer_list timer_dma,timer_card; void dma_timeout(unsigned long ptr); void card_timeout(unsigned long ptr); /* */ =09=09 #define WORD unsigned short int #define HInD(port) inl(card_base[card_no]+port) #define HOutD(port,val) outl( val,card_base[card_no]+port) #define YhOutW(port,val) outw( val,port) #define YhOutB(port,val) outb( val,port) WORD basePort=3D0,dataPort,addrPort; static int jmkmajor; //lilin adding=20 #define DMA_BUFFER_SIZE 4*1024 =09 void * card_clea[CARD_NUM]; ulong card_stat[CARD_NUM]; ulong card_use[CARD_NUM];/*added */ ulong card_base[CARD_NUM]; ulong card_addr[CARD_NUM]; ulong card_data[CARD_NUM]; int leftPort[CARD_NUM]; int rightPort[CARD_NUM]; spinlock_t sjy22_lock; int DMAOpen( int card_no ); //=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D /******* hhw changed 2000 12 28 ************/ /******* lilin changed 2002 5 *************/ int close_jmk(struct inode *inode , struct file *file) { return 0; } int open_jmk(struct inode *inode, struct file *file) { return 0; } void SendCmdToF206( PARAM_INFO *MI,int card_no ) { int i1; memcpy(dma_buffer+4, (char *)MI->inp, MI->inlen ); for (i1 =3D 0; i1 < MI->inlen + 14; i1 ++) printk("%x ", (unsigned char )*((unsigned char *)dma_buffer + i1)= ); printk("\n"); HOutD( 0x08c, MI->inlen+4); //sent data HOutD( 0x090, 0 ); i1 =3D HInD(0xA8); HOutD( 0x0A8, i1 | (1<<0) ); HOutD( 0x0A8, i1 | ((1<<0)|(1<<1)) ); i1 =3D 0; while(i1 =3D=3D 0)=20 { =09 i1 =3D HInD(0xA8) & (1<<4); } writel ( 0, card_clea[0]); return; } int RcvDataFromF206( PARAM_INFO *MI,int card_no) { int i1; char *chp; chp=3D(char *)MI->outp; HOutD( 0x08c, MI->outlen+4); HOutD( 0x090, (1<<3) ); i1 =3D HInD(0xA8); HOutD( 0x0A8, i1 | (1<<0) ); HOutD( 0x0A8, i1 | ((1<<0)|(1<<1)) ); =20=20=20=20=20=20=20 /* init_timer(&timer_dma);//init timer struct timer_dma.function =3D dma_timeout; timer_dma.expires =3D jiffies+120*HZ;//120 seconds add_timer(&timer_dma); */ i1 =3D 0; while(i1 =3D=3D 0)=20 { if (isdmatimeout =3D=3D0)//if timeout ,del timer and return i1 =3D HInD(0xA8) & (1<<4); /* else {=20=20=20 del_timer(&timer_dma); card_use[card_no] =3D CARD_READY; isdmatimeout =3D 0; chp[0]=3D0x29; chp[1]=3D0; chp[2]=3D0; chp[3]=3D0; return -1; }*/ } // del_timer(&timer_dma); /* for (i1 =3D 0; i1 < 16; i1++) printk("%x ", *((unsigned char *)dma_buffer + 4 +i1));*/ memcpy((char *)MI->outp, dma_buffer+4 ,MI->outlen ); return 0;=09 } int F206Function(PARAM_INFO *MI ,int card_no) { unsigned long RegValue; unsigned long lock_flag; int i; char *chp; chp=3D(char *)MI->outp; spin_lock_irqsave(&sjy22_lock,lock_flag); if( card_use[card_no] =3D=3D CARD_BUSY) { spin_unlock_irqrestore(&sjy22_lock,lock_flag); chp[0] =3D 0x2A; chp[1] =3D 0; chp[2] =3D 0; chp[2] =3D 0; return -EBUSY; } card_use[card_no] =3D CARD_BUSY; spin_unlock_irqrestore(&sjy22_lock,lock_flag); SendCmdToF206(MI, card_no); // init_timer(&timer_card);//init timer struct // timer_card.function =3D card_timeout; // timer_card.expires =3D jiffies+120*HZ;//120 second:s =20=20=20=20=20=20 // add_timer(&timer_card); RegValue =3D 0x3; while( RegValue !=3D 0) { if (iscardtimeout =3D=3D0) RegValue =3D readl ( card_clea[0] ) & 0x3; /* else { del_timer(&timer_card); iscardtimeout =3D 0;=20=20=20=20=20=20=20=20 card_use[card_no] =3D CARD_READY; chp[0]=3D0x29; chp[1]=3D0; chp[2]=3D0; chp[3]=3D0; return -1; }*/ } printk("request RegValue =3D %x\n", RegValue);=20 // del_timer(&timer_card); =20=20=20=20=20=20 RegValue =3D 0x3; while(RegValue !=3D 0) { RegValue =3D readl(card_clea[0]) & 0x3; } RegValue =3D readl( card_clea[0]); /* It's neccessary! Two read(0x1000 0000) operation needed.*/ printk("RegValue =3D %x\n", RegValue);=20 i=3DRcvDataFromF206( MI, card_no ); if (i =3D=3D -1) { card_use[0] =3D CARD_READY; return -1; } if(card_no=3D=3D0) card_use[0]=3DCARD_READY;=09 return 0; } int ioctl_jmk(struct inode * inode, struct file * file, unsigned int cmd, unsigned long arg) { int card_no =3D 0; int ioadd; unsigned long ii1; PARAM_INFO MMI; switch( cmd ) { case Ioctl_F206_Reset: ioadd =3D card_base[card_no] + 0x6c;=20=20=20=20=20=20=20=20=20=20=20=20= =20 ii1 =3D inl( ioadd ); ii1 |=3D ( 1 << 30 ); outl( ii1, ioadd ); ii1 &=3D ~( 1 << 30 ); outl( ii1, ioadd ); HOutD(0x00, 0xfffe0000 ); HOutD(0xf0, 0xfffe0000 ); DMAOpen( card_no ); return 0; break; case Ioctl_F206_Function: copy_from_user(&MMI,(PARAM_INFO *)arg,sizeof(MMI) ); =09=09=09 F206Function( &MMI,card_no); =09=09=09 copy_to_user((PARAM_INFO *)arg,&MMI,sizeof(MMI) ); return 0; =09=09=09 default: break;=09=09=09=09=09 } return 0; } struct file_operations jmk_fops =3D { ioctl: ioctl_jmk,=20=20=20=20=20=20 open: open_jmk,=09 release: close_jmk,=09 }; int init_sjy22b(void) { unsigned long k; int card_no; card_no =3D 0; if (pci_present()) { =09=09 u32 pio_start, pio_end, pio_flags, pio_len;=09 unsigned long mmio_start, mmio_end, mmio_flags, mmio_len; void *map_addr;=09 =09=09=09 pdev =3D pci_find_device (0x10b5, 0x5406,pdev); if (!pdev) return 1; pci_write_config_word(pdev, PCI_COMMAND, 7); pio_start =3D pci_resource_start (pdev, 1); pio_end =3D pci_resource_end (pdev, 1); pio_flags =3D pci_resource_flags (pdev, 1); pio_len =3D pci_resource_len (pdev, 1); mmio_start =3D pci_resource_start (pdev, 3); mmio_end =3D pci_resource_end (pdev, 3); mmio_flags =3D pci_resource_flags (pdev, 3); mmio_len =3D pci_resource_len (pdev, 3); if(pci_request_regions (pdev, "sjy22bdrv")){ printk("<1>%s: region resource error, aborting\n",pdev->slot_name); return 1; }=09 /* enable PCI bus-mastering */ // pci_set_master (pdev); card_base[0] =3D pio_start ; k =3D inl( card_base[0]+0x04 ); printk("Base_address[04] =3D %lxH\n",k); k =3D inl( card_base[0]+0x0f4 ); printk("Base_address[f4] =3D %lxH\n",k); HOutD(0x00, 0xfffe0000 ); HOutD(0xf0, 0xfffe0000 ); outl( 0x20000000, card_base[0]+0x04 ); outl( 0x10000000, (card_base[0]+0x0f4) ); /* ioremap MMIO region */ map_addr =3D ioremap (mmio_start, mmio_len); if (map_addr =3D=3D NULL) { printk("%s: cannot remao mmiom,aborting\n",pdev->slot_name); return 1; } =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 (void *)card_clea[0] =3D map_addr; =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 // dma_buffer =3D pci_alloc_consistent(pdev,DMA_BUFFER_SIZE,&dma_addr); dma_buffer =3D kmalloc(4096,GFP_KERNEL); dma_addr =3D dma_buffer - 0xc0000000;=20 if(dma_buffer =3D=3D NULL) { printk("allock dma buffer error\n");=09=09 return 1;=09 }=09 card_stat[0]=3DCARD_READY;=09 card_use[0]=3DCARD_READY;=09 card_stat[1]=3DCARD_BUSY; card_use[1]=3DCARD_BUSY;=09 =09 k =3D inl(card_base[0] + 0x0c);=20=20=20=20=20=20=20=20=20=20=20= =20=20 k &=3D 0xffffff00; outl(k, card_base[0] + 0x0c);=20=20=20=20=20=20=20=20=20=20=20=20=20 DMAOpen( 0 ); spin_lock_init(&sjy22_lock); printk("(C)Copyright Duanxuejiang, 2002, Beijing(V1.42.1).\n"); printk("Welcome to use BOCO SJY22 PCI CARD!\n"); jmkmajor=3Dregister_chrdev(0,"jmk",&jmk_fops); printk("PCI Major=3D%d.\n",jmkmajor); printk("SJY22 is Ok\n"); return 0;=09=09 }=09 printk("No SJY22 device!");=09 return 1; } int init_jmk(void) { int temp; temp =3D init_sjy22b(); return temp; } /*-------------------------------------------------------------*/ #ifdef MODULE int init_module(void) { int temp; temp =3D init_sjy22b(); return temp; } void cleanup_module(void) { unregister_chrdev(jmkmajor,"jmk"); pci_free_consistent(pdev,DMA_BUFFER_SIZE,dma_buffer,dma_addr); iounmap ((void *)card_addr[0]); /* it's ok to call this even if we have no regions to free */ pci_release_regions (pdev); printk("clean up!\n"); } #endif int DMAOpen( int card_no ) { unsigned long RegValue; =20=20=20=20=20=20=20=20 HOutD(0x004, 0x20000001 ); HOutD(0x0f4, 0x10000001 ); =09 RegValue =3D HInD(0x008); RegValue &=3D ~(1 << 20); RegValue |=3D (1 << 19); HOutD(0x008, RegValue ); RegValue =3D HInD(0x0B0); =09 HOutD(0x0B0, (RegValue & 0xffff0000)); HOutD(0x080, 0x0001c3 ); RegValue =3D HInD(0x068); RegValue &=3D ~(1 << 18); RegValue &=3D ~(1 << 8); HOutD(0x068, RegValue ); //dma_buffer2 =3D virt_to_phys(dma_buffer); RegValue =3D dma_addr;=20 HOutD(0x084, RegValue ); RegValue =3D 0x20000000; HOutD( 0x088, RegValue ); HOutD( 0x08c, 16 ); //sent data HOutD( 0x090, (1<<3) ); HOutD( 0x0B4, 0 ); HOutD( 0x0A8, (1<<0) ); return 0; } void dma_timeout(unsigned long ptr) { isdmatimeout=3D1; } void card_timeout(unsigned long ptr) { iscardtimeout=3D1; } ///////////////////////////////////////////////////////////////////// Device Driver under FreeBSD-5.4 ///////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// /* Ma Yong, Zhouyi Zhou Infrastructure Software Center=20 Institute of Software Chinese Academy of Sciences */ //#define MIN(a,b) (((a) < (b)) ? (a) : (b)) #include =20=20 #include #include #include #include =20 #include =20=20=20 #include =20=20=20=20 #include #include =20=20 #include #include #include #include #include #include #include #include #include "sjy22bdrv.h" #define WORD unsigned short int #define DWORD unsigned long #define BYTE unsigned char #define HInD(port) inl(card_base[0]+port) #define HOutD(port,val) outl( val,card_base[0]+port) #define Debug 0 #define YhOutW(port,val) outw( val,port) #define YhOutB(port,val) outb( val,port) typedef struct { volatile unsigned long lock; volatile unsigned int babble; const char *module; } spinlock_t; #define save_flags(x) __asm__ __volatile__("pushfl ; popl %0":"=3Dg= " (x): /* no input */) #define restore_flags(x) __asm__ __volatile__("pushl %0 ; popfl": /* n= o output */ :"g" (x):"memory", "cc") #define local_irq_save(x) __asm__ __volatile__("pushfl ; popl %0 ; cl= i":"=3Dg" (x): /* no input */ :"memory") #define LOCK_SECTION_NAME \ ".text.lock.sjy22bdrv"=20 #define LOCK_SECTION_START(extra) \ ".subsection 1\n\t" \ extra \ ".ifndef " LOCK_SECTION_NAME "\n\t" \ LOCK_SECTION_NAME ":\n\t" \ ".endif\n\t" =20 #define LOCK_SECTION_END \ ".previous\n\t" #define spin_lock_string \ "\n1:\t" \ "lock ; decb %0\n\t" \ "js 2f\n" \ LOCK_SECTION_START("") \ "2:\t" \ "cmpb $0,%0\n\t" \ "rep;nop\n\t" \ "jle 2b\n\t" \ "jmp 1b\n" \ LOCK_SECTION_END static inline void spin_lock(spinlock_t *lock) { __asm__ __volatile__( spin_lock_string :"=3Dm" (lock->lock) : : "memory"); } #define spin_lock_irqsave(lock, flags) do { local_irq_save(flags);= spin_lock(lock); } while (0) #define spin_unlock_string \ "movb $1,%0" \ :"=3Dm" (lock->lock) : : "memory" =20 =20 static inline void spin_unlock(spinlock_t *lock) { __asm__ __volatile__( spin_unlock_string ); } #define __restore_flags(x) __asm__ __volatile__("pushl %0 ; popfl": /*= no output */ :"g" (x):"memory", "cc") #define local_irq_restore(x) __restore_flags(x) #define spin_unlock_irqrestore(lock, flags) do { spin_unlock(lock); lo= cal_irq_restore(flags); } while (0) spinlock_t sjy22_lock; typedef struct=20=20=09=09=09=09 { BYTE Code;=09=09=09=09 BYTE Unused; WORD Length;=09=09=09=09 BYTE *Data;=09=09=09=09 } DSP_CMD_INFO, *pDSP_CMD_INFO; typedef struct=09=09=09=09=09 { DSP_CMD_INFO info; BYTE Buffer[1024*16];=09=09 } DSP_CMD, *PDSP_CMD; #define DSP_CMD_SELECT_KEY 0x62 #define DSP_CMD_SELECT_KW_GET_KS 0x3B #define DSP_CMD_SELECT_KW_SET_KS 0x3C #define DSP_CMD_BCA 0x63 #define DSP_CMD_HASH 0x64 #define DSP_CMD_GET_HASH 0x65 #define DSP_CMD_BCA_HASH 0x66 #define DSP_CMD_BCA_HASH_EN 0x67 #define DSP_CMD_BCA_HASH_DE 0x68 #define DSP_CMD_ENCRYPT_BLOCK 0x95 #define DSP_CMD_ENCRYPT_HASH 0x96 #define DSP_CMD_HASH_BLOCK 0x97 #define DSP_CMD_IPSEC_ENCRYPT 0x98 #define DSP_CMD_IPSEC_DECRYPT 0x99 // 纡�#define DSP_CMD_GEN_RANDOM 0x80 DSP_CMD inPara,outPara; void SendDspCmd(DWORD , DSP_CMD *,DSP_CMD *); WORD dspReadRandom( BYTE *); #define SPINLOCK_MAGIC_INIT=20=20=20 #define SPIN_LOCK_UNLOCKED (spinlock_t) { 1 SPINLOCK_MAGIC_INIT } #define spin_lock_init(x) do { *(x) =3D SPIN_LOCK_UNLOCKED; } while(0) int DMAOpen( int ); int self_lock=3D0; /*added for pci*/ int self_lock_myself=3D0; #define MAJOR 199 #define MAXMSGLEN 128 #define Nmypci CARD_NUM #define DMA_BUFFER_SIZE 4*1024 bus_space_tag_t card_clea[CARD_NUM]; bus_space_tag_t card_stat[CARD_NUM]; bus_space_tag_t card_use[CARD_NUM];/*added */ bus_space_tag_t card_base[CARD_NUM]; bus_space_tag_t card_addr[CARD_NUM]; bus_space_tag_t card_data[CARD_NUM]; bus_space_tag_t card_irq[CARD_NUM]; u_char *dma_buffer; unsigned dma_addr; int leftPort[CARD_NUM]; int rightPort[CARD_NUM]; //int * test =3D 3;=20 struct mypci_softc=20 { bus_space_tag_t bst; bus_space_handle_t bsh; device_t sc_dev;=20 u_int32_t open_mask; u_int32_t read_mask; struct resource *res0,*res1; struct resource *rl_irq; void *rl_intrhand; int rid; bus_dma_tag_t rl_tag; struct cdev *dev; }; static inline unsigned long m_sleep(unsigned long time)=20 { int mm_i1; int mm_i2; if( time !=3D 1) { self_lock_myself=3D1; self_lock=3D0; } mm_i1 =3D 0; mm_i2 =3D 0; while(self_lock!=3D1) { __asm __volatile("sti" : : : "memory"); // __asm __volatile("sti"); { int loop_i,counter=3D0; for(loop_i=3D0;loop_i<10;loop_i++) {counter++;} } __asm __volatile("cli" : : : "memory"); // cli(); mm_i1++; if(mm_i1>50000000){ mm_i2 =3D 1; break; } }//end while return mm_i2; } void SendCmdToF206( PARAM_INFO *,int ); int RcvDataFromF206( PARAM_INFO *,int ); int F206Function(PARAM_INFO * ,int ); void SendCmdToF206( PARAM_INFO *MI,int card_no ) { int i1; // memcpy(dma_buffer+4, (char *)MI->inp, MI->inlen ); *((unsigned char *) dma_buffer + 0) =3D 0x73; *((unsigned char *) dma_buffer + 1) =3D 0x6a; *((unsigned char *) dma_buffer + 2) =3D 0x79; *((unsigned char *) dma_buffer + 3) =3D 0x32; *((unsigned char *) dma_buffer + 4) =3D 0x80; *((unsigned char *) dma_buffer + 5) =3D 0x0; *((unsigned char *) dma_buffer + 6) =3D 0x1; *((unsigned char *) dma_buffer + 7) =3D 0x0; *((unsigned char *) dma_buffer + 8) =3D 0x3c; *((unsigned char *) dma_buffer + 9) =3D 0xb7; *((unsigned char *) dma_buffer + 10) =3D 0xff; *((unsigned char *) dma_buffer + 11) =3D 0xbf; *((unsigned char *) dma_buffer + 12) =3D 0x8; *((unsigned char *) dma_buffer + 13) =3D 0x0; i1 =3D readl(card_clea[0]); HOutD( 0x08c, MI->inlen+4); //sent data HOutD( 0x090, 0 ); i1 =3D HInD(0xA8); HOutD( 0x0A8, i1 | (1<<0) ); HOutD( 0x0A8, i1 | ((1<<0)|(1<<1)) ); i1 =3D 0; while(i1 =3D=3D 0)=20 { =09 i1 =3D HInD(0xA8) & (1<<4); } writel (card_clea[0],0); return; } int RcvDataFromF206( PARAM_INFO *MI,int card_no) { int i1; char *chp; chp=3D(char *)MI->outp; HOutD( 0x08c, MI->outlen+4); HOutD( 0x090, (1<<3) ); i1 =3D HInD(0xA8); HOutD( 0x0A8, i1 | (1<<0) ); HOutD( 0x0A8, i1 | ((1<<0)|(1<<1)) ); =20=20=20=20=20=20=20 /* init_timer(&timer_dma);//init timer struct timer_dma.function =3D dma_timeout; timer_dma.expires =3D jiffies+120*HZ;//120 seconds add_timer(&timer_dma);*/ i1 =3D 0; while(i1 =3D=3D 0)=20 { // if (isdmatimeout =3D=3D0)//if timeout ,del timer and return i1 =3D HInD(0xA8) & (1<<4); /* else {=20=20=20 del_timer(&timer_dma); card_use[card_no] =3D CARD_READY; isdmatimeout =3D 0; chp[0]=3D0x29; chp[1]=3D0; chp[2]=3D0; chp[3]=3D0; return -1; }*/ } // del_timer(&timer_dma); printf("Zhouyi Zhou After:\n"); for (int i =3D 0; i < 16 + 10; i++) printf("%x ", *((unsigned char *) dma_buffer + 4 +i)); memcpy((char *)MI->outp, dma_buffer+4 ,MI->outlen ); return 0;=09 } /*---------------------------------------------------------------------*/ /* =A7g=ADa碛塄F206=BC=AF=AF=FB� = / / 脍: 潆=AB=A1� / / 鲒: 0=3D=B7k�=D2=D7 = / /----------------------------------------------------------------------*/ int F206Function(PARAM_INFO *MI ,int card_no) { unsigned long RegValue; unsigned long lock_flag; int i; char *chp; chp=3D(char *)MI->outp; spin_lock_irqsave(&sjy22_lock,lock_flag); if( card_use[card_no] =3D=3D CARD_BUSY) { spin_unlock_irqrestore(&sjy22_lock,lock_flag); chp[0] =3D 0x2A; chp[1] =3D 0; chp[2] =3D 0; chp[2] =3D 0; return -EBUSY; } card_use[card_no] =3D CARD_BUSY; spin_unlock_irqrestore(&sjy22_lock,lock_flag); SendCmdToF206(MI, card_no); // init_timer(&timer_card);//init timer struct //timer_card.function =3D card_timeout; //timer_card.expires =3D jiffies+120*HZ;//120 second:s =20=20=20=20=20=20 //add_timer(&timer_card); RegValue =3D 0x3; while( RegValue !=3D 0) { // if (iscardtimeout =3D=3D0) RegValue =3D readl ( card_clea[0] ) & 0x3; /* else { del_timer(&timer_card); iscardtimeout =3D 0;=20=20=20=20=20=20=20=20 card_use[card_no] =3D CARD_READY; chp[0]=3D0x29; chp[1]=3D0; chp[2]=3D0; chp[3]=3D0; return -1; }*/ } =20=20=20=20=20=20=20 // del_timer(&timer_card); =20=20=20=20=20=20 RegValue =3D 0x3; while(RegValue !=3D 0) { RegValue =3D readl(card_clea[0]) & 0x3; } RegValue =3D readl( card_clea[0]); /* It's neccessary! Two read(0x1000 0000) operation needed.*/ printf("RegValue =3D %x\n", RegValue); =20=20=20=20=20=20=20 i=3DRcvDataFromF206( MI, card_no ); if (i =3D=3D -1) { card_use[0] =3D CARD_READY; return -1; } if(card_no=3D=3D0) card_use[0]=3DCARD_READY;=09 return 0; } /* Function prototypes */ static d_open_t mypci_open; static d_close_t mypci_close; static d_read_t mypci_read; static d_write_t mypci_write; static d_ioctl_t mypci_ioctl; static struct cdevsw mypci_cdevsw =3D { .d_version=3D D_VERSION, .d_open =3D mypci_open, .d_close =3D mypci_close, .d_ioctl =3D mypci_ioctl, .d_read =3D mypci_read, .d_write =3D mypci_write, .d_name =3D "mypci", }; //static dev_t sdev; static devclass_t mypci_devclass; static int mypci_open(struct cdev *dev, int oflags, int devtype, d_thread_t *td) { return 0; } static int mypci_close(struct cdev *dev, int fflag, int devtype, d_thread_t *td) { /* int i1; int ioadd; int card_no =3D 0; ioadd =3D card_base[card_no] + 0x3a;=20=20=20=20=20=20=20=20=20=20=20=20= =20 YhOutW( ioadd, 0x0); ioadd =3D card_base[card_no] + 0x38;=20=20=20=20=20=20=20=20=20=20=20=20= =20 YhOutW( ioadd, 0x0); ioadd =3D card_base[card_no] + 0x10;=20=20=20=20=20=20=20=20=20=20=20=20= =20 i1 =3D inw( ioadd );*/ return 0; } char teststr[128]; static int mypci_read(struct cdev *dev, struct uio *uio, int ioflag) { printf("Read\n"); int resid =3D MAXMSGLEN; int error =3D 0; do { if (uio->uio_resid < resid) resid =3D uio->uio_resid; error =3D uiomove(teststr, resid, uio);=09 } while (resid > 0 && error =3D=3D 0); printf("mypci reads!\n"); printf("mypci read!\n"); return (error); } static int mypci_write(struct cdev *dev, struct uio *uio, int ioflag) { printf("write\n"); int resid =3D MAXMSGLEN; int error =3D 0; do { if (uio->uio_resid < resid) resid =3D uio->uio_resid; error =3D uiomove(teststr, resid, uio);=09 } while (resid > 0 && error =3D=3D 0); printf("mypci writed!\n"); return (error); } static int mypci_probe(device_t dev) { device_printf(dev, "MyPCI Probe\nVendor ID : 0x%x\nDevice ID : 0x%x\n", pci_get_vendor(dev), pci_get_device(dev)); if (pci_get_vendor(dev) =3D=3D 0x10b5) { printf("We've got the Cryptgraphic Card!\n"); return (0); } return (ENXIO); } static int mypci_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct th= read *td) // mypci_ioctl(struct inode *inode,struct file *file,unsigned int cmd,= unsigned long arg ) { int card_no =3D 0; int ioadd; unsigned long ii1; //PARAM_INFO MMI; cmd -=3D 0x20000000; BYTE outStr[16]; switch( cmd ) { case 2: /*Ioctl_F206_Reset:*/ ioadd =3D card_base[0] + 0x6c;=20=20=20=20=20=20=20=20=20=20=20=20=20 ii1 =3D inl( ioadd ); ii1 |=3D ( 1 << 30 ); outl( ii1, ioadd ); ii1 &=3D ~( 1 << 30 ); outl( ii1, ioadd ); HOutD(0x00, 0xfffe0000 ); HOutD(0xf0, 0xfffe0000 ); DMAOpen( card_no ); printf("mypci ioctl got called, F206 reset!\n"); break; case 3: //Ioctl_F206_Function: // copy_from_user((char *)&MMI,(char *)arg,sizeof(MMI) ); // F206Function( &MMI,card_no); break; case 4: dspReadRandom(outStr); =20=20=20=20=20=20=20=20 break; default: break;=09=09=09=09=09 } return 0; } static void sjy_interrupt(void * args) { int i1, ioadd; int card_no =3D 0; unsigned long reg; i1 =3D 0; ioadd =3D card_base[0] + 0x68;=20=20=20=20=20=20=20=20=20=20=20=20=20 // *test =3D 5; reg =3D inl( ioadd ); =20=20=20=20=20=20=20 if((reg & (1<<8)) =3D=3D 0) { =09 reg =3D inl( ioadd ); if((reg & (1<<8)) =3D=3D 0){ return; } }=20 printf("my pci0 interrupt got called!\n"); if(reg & 0x00e0e000) { =09=09 outl((reg & ~(1<<8)), card_base[0] + 0x68); reg =3D inl( card_base[card_no] + 0x68); if(reg & (1 << 15)) { HOutD(0xA8,0x8); if(self_lock_myself=3D=3D1) { self_lock=3D1; self_lock_myself=3D0; } =09=09 } if(reg & (1 << 21)) { HOutD(0x068, 0x0B00); if(self_lock_myself=3D=3D1) { self_lock=3D1; self_lock_myself=3D0; } readl(card_clea[0]); } return; } reg =3D inl( card_base[0] + 0x30); if( reg & ( 1<<3) ) { outl((reg & ~(1<<8)), card_base[0] + 0x68); } } int DMAOpen( int card_no ) { unsigned long RegValue; =20=20=20=20=20=20=20=20 HOutD(0x004, 0x20000001 ); HOutD(0x0f4, 0x10000001 ); =09 RegValue =3D HInD(0x008); RegValue &=3D ~(1 << 20); RegValue |=3D (1 << 19); HOutD(0x008, RegValue ); RegValue =3D HInD(0x0B0); =09 HOutD(0x0B0, (RegValue & 0xffff0000)); HOutD(0x080, 0x0001c3 ); RegValue =3D HInD(0x068); RegValue &=3D ~(1 << 18); RegValue &=3D ~(1 << 8); HOutD(0x068, RegValue ); //dma_buffer2 =3D virt_to_phys(dma_buffer); RegValue =3D pmap_kextract((unsigned long)dma_buffer);=20 HOutD(0x084, RegValue ); RegValue =3D 0x20000000; HOutD( 0x088, RegValue ); HOutD( 0x08c, 16 ); //sent data HOutD( 0x090, (1<<3) ); HOutD( 0x0B4, 0 ); HOutD( 0x0A8, (1<<0) ); return 0; } struct mypci_softc *sc; int rid; static int mypci_attach(device_t dev) { unsigned long k; int error =3D 0; printf("Mypci device loading..."); rid=3D0x14; struct resource *res; unsigned map_addr;=09=09 u_long mmio_flags, mmio_len;=09 u_int32_t cmd;=20=20=20=20=20=20=20 sc =3D (struct mypci_softc *) device_get_softc(dev); bzero(sc, sizeof (*sc)); sc->sc_dev =3D dev;=09 pci_enable_busmaster(dev); // pci_set_powerstate(dev, 0); cmd =3D pci_read_config(dev,PCIR_COMMAND,4); cmd |=3D PCIM_CMD_MEMEN|PCIM_CMD_BUSMASTEREN|PCIM_CMD_PORTEN; // pci_write_config(dev,PCIR_COMMAND,cmd,4);=20=20=20=20=20=20= =20=20 sc->rid =3D rid; res =3D bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE); card_base[0]=3D rman_get_bushandle(res); sc->res0 =3D res; =20=20=20=20=20=20=20=20=20=20 rid =3D 28; res =3D bus_alloc_resource_any(dev,SYS_RES_MEMORY, &rid,RF_ACTIVE= ); sc->res1 =3D res; mmio_flags =3D rman_get_flags(res); map_addr =3D rman_get_bushandle(res); mmio_len =3D bus_get_resource_count(dev, SYS_RES_MEMORY, rid);=20= =20=20=20=20 card_clea[0] =3D (unsigned )map_addr; //dma_buffer =3D contigmalloc(4096, M_DEVBUF, 1, 0, 0xffffffff, 4096, 0); dma_buffer =3D malloc(4096, M_DEVBUF,M_NOWAIT|M_ZERO); card_stat[0]=3DCARD_READY;=09 card_use[0]=3DCARD_READY;=09 card_stat[1]=3DCARD_BUSY; card_use[1]=3DCARD_BUSY;=09 k =3D inl( card_base[0]+0x04 ); k =3D inl (card_base[0]+0x0f4); outl(0xfffe0000, card_base[0] + 0x00); outl(0xfffe0000, card_base[0] + 0x04); outl( 0x20000000, card_base[0]+0x04 ); outl( 0x10000000, (card_base[0]+0x0f4) ); k =3D inl(card_base[0] + 0x0c);=20=20=20=20=20=20=20=20=20=20=20=20= =20 k &=3D 0xffffff00; outl(k, card_base[0] + 0x0c);=20=20=20 self_lock=3D0; self_lock_myself=3D0; DMAOpen( 0 ); =09 spin_lock_init(&sjy22_lock);=09 sc->dev =3D make_dev(&mypci_cdevsw, 0, UID_ROOT, GID_WHEEL, 0644, "= mypci0"); =09 =20=20=20=20=20=20=20 /////////////////////////////////////////////////////=20=20=20=20=20=20=20= =20=20=20 printf("Attach successfully!\n"); return (0); } static int mypci_detach(device_t dev) { bus_release_resource(dev, SYS_RES_MEMORY, rid, sc->res1); bus_release_resource(dev, SYS_RES_IOPORT, 0x14, sc->res0); destroy_dev(sc->dev); free(dma_buffer, M_DEVBUF); free(sc, M_DEVBUF); return (0); } static int mypci_shutdown(device_t dev) { return 0; } static int mypci_suspend(device_t dev) { printf("Mypci suspend!\n"); return (0); } static int mypci_resume(device_t dev) { printf("Mypci resume!\n"); return (0); } static device_method_t mypci_methods[] =3D { DEVMETHOD(device_probe, mypci_probe), DEVMETHOD(device_attach, mypci_attach), DEVMETHOD(device_detach, mypci_detach), DEVMETHOD(device_shutdown, mypci_shutdown), DEVMETHOD(device_suspend, mypci_suspend), DEVMETHOD(device_resume, mypci_resume), DEVMETHOD(bus_print_child, bus_generic_print_child), DEVMETHOD(bus_driver_added, bus_generic_driver_added), { 0, 0 } }; static driver_t mypci_driver =3D { "mypci", mypci_methods, //0, sizeof(struct mypci_softc),=20 }; void SendDspCmd(DWORD CardID, DSP_CMD *pInPara,DSP_CMD *pOutPara) { PARAM_INFO param; pInPara->info.Length /=3D 2; pInPara->info.Data =3D pInPara->Buffer; pOutPara->info.Length /=3D2; pOutPara->info.Data =3D pOutPara->Buffer; =09 param.inp =3D (char *)pInPara; param.inlen =3D sizeof(DSP_CMD_INFO) + pInPara->info.Length*2; param.outp =3D (char *)pOutPara; param.outlen =3D sizeof(DSP_CMD_INFO) + pOutPara->info.Length*2; F206Function(¶m,CardID); } WORD dspReadRandom( BYTE *outStr) { // DWORD CardID =3D 0; WORD len =3D 8; int i; inPara.info.Code =3D DSP_CMD_GEN_RANDOM; inPara.info.Length =3D 2; outPara.info.Length =3D 16; memcpy(inPara.Buffer,&len,2); SendDspCmd(0, &inPara,&outPara); printf("\n"); for (i =3D 0; i < 16; i++) printf("%x ",*((char *)outPara.Buffer + i)); printf("\n"); // memcpy(outStr,outPara.Buffer,16); return outPara.info.Code; } DRIVER_MODULE(mypci, pci, mypci_driver, mypci_devclass, 0, 0); --=20 ___________________________________________________ Play 100s of games for FREE! http://games.mail.com/ From owner-freebsd-drivers@FreeBSD.ORG Wed Oct 26 15:46:49 2005 Return-Path: X-Original-To: freebsd-drivers@freebsd.org Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8015016A421 for ; Wed, 26 Oct 2005 15:46:49 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from mv.twc.weather.com (mv.twc.weather.com [65.212.71.225]) by mx1.FreeBSD.org (Postfix) with ESMTP id 18BCC43D45 for ; Wed, 26 Oct 2005 15:46:49 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from [10.50.41.234] (Not Verified[10.50.41.234]) by mv.twc.weather.com with NetIQ MailMarshal (v6, 0, 3, 8) id ; Wed, 26 Oct 2005 12:03:32 -0400 From: John Baldwin To: freebsd-drivers@freebsd.org Date: Wed, 26 Oct 2005 11:24:15 -0400 User-Agent: KMail/1.8.2 References: <20051026031920.11BC983C03@ws1-1.us4.outblaze.com> In-Reply-To: <20051026031920.11BC983C03@ws1-1.us4.outblaze.com> MIME-Version: 1.0 Content-Type: text/plain; charset="big5" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200510261124.16956.jhb@freebsd.org> Cc: Subject: Re: Cryptography Driver (Help !!!!) X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Oct 2005 15:46:49 -0000 On Tuesday 25 October 2005 11:19 pm, Yong Ma wrote: > Dear colleagues, > Cry for help!!!! > The cryptography card driver (polling mode, not interrupt mode) works well > under linux-2.4, but not working under FreeBSD-5.4. The DMA buffer just > keep intact under FreeBSD-5.4 after the Random value generation command > has been issued. > > Every thing is compared, but it still not working. First off, I don't really understand your question. Secondly, your driver might work better if you use the locking primitives we provide such as mutexes and condition variables. It looks like your home-grown lock might suffer from a deadlock condition if the current thread is preempted in m_sleep() for example and another thread tries to get the lock. -- John Baldwin <>< http://www.FreeBSD.org/~jhb/ "Power Users Use the Power to Serve" = http://www.FreeBSD.org From owner-freebsd-drivers@FreeBSD.ORG Fri Oct 28 07:30:21 2005 Return-Path: X-Original-To: freebsd-drivers@freebsd.org Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id AD18316A41F for ; Fri, 28 Oct 2005 07:30:21 +0000 (GMT) (envelope-from mayong@mail.com) Received: from webmail-outgoing.us4.outblaze.com (webmail-outgoing.us4.outblaze.com [205.158.62.67]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3D51843D45 for ; Fri, 28 Oct 2005 07:30:21 +0000 (GMT) (envelope-from mayong@mail.com) Received: from unknown (unknown [192.168.9.180]) by webmail-outgoing.us4.outblaze.com (Postfix) with QMQP id BB4F4180012E for ; Fri, 28 Oct 2005 07:30:20 +0000 (GMT) X-OB-Received: from unknown (205.158.62.182) by wfilter.us4.outblaze.com; 28 Oct 2005 07:30:20 -0000 Received: by ws1-6.us4.outblaze.com (Postfix, from userid 1001) id B39A81CE305; Fri, 28 Oct 2005 07:30:20 +0000 (GMT) Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="big5" MIME-Version: 1.0 From: "Yong Ma" To: freebsd-drivers@freebsd.org Date: Fri, 28 Oct 2005 02:30:20 -0500 Received: from [159.226.5.225] by ws1-6.us4.outblaze.com with http for mayong@mail.com; Fri, 28 Oct 2005 02:30:20 -0500 X-Originating-Ip: 159.226.5.225 X-Originating-Server: ws1-6.us4.outblaze.com Message-Id: <20051028073020.B39A81CE305@ws1-6.us4.outblaze.com> Subject: Problem resolved !!!Cryptography Driver X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Oct 2005 07:30:21 -0000 We have find the reason, it is because the definition of outl(port,val) in = FreeBSD and outl(val, port) in Linux are not the same. --=20 ___________________________________________________ Play 100s of games for FREE! http://games.mail.com/ From owner-freebsd-drivers@FreeBSD.ORG Fri Oct 28 15:49:00 2005 Return-Path: X-Original-To: freebsd-drivers@freebsd.org Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 28DC716A41F for ; Fri, 28 Oct 2005 15:49:00 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from mv.twc.weather.com (mv.twc.weather.com [65.212.71.225]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8DE7843D48 for ; Fri, 28 Oct 2005 15:48:59 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from [10.50.41.234] (Not Verified[10.50.41.234]) by mv.twc.weather.com with NetIQ MailMarshal (v6, 0, 3, 8) id ; Fri, 28 Oct 2005 12:05:46 -0400 From: John Baldwin To: freebsd-drivers@freebsd.org Date: Fri, 28 Oct 2005 11:50:13 -0400 User-Agent: KMail/1.8.2 References: <20051028073020.B39A81CE305@ws1-6.us4.outblaze.com> In-Reply-To: <20051028073020.B39A81CE305@ws1-6.us4.outblaze.com> MIME-Version: 1.0 Content-Type: text/plain; charset="big5" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200510281150.14675.jhb@freebsd.org> Cc: Subject: Re: Problem resolved !!!Cryptography Driver X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Oct 2005 15:49:00 -0000 On Friday 28 October 2005 03:30 am, Yong Ma wrote: > We have find the reason, it is because the definition of outl(port,val) in > FreeBSD and outl(val, port) in Linux are not the same. If you want your driver to be portable to other architectures than i386, you should be using bus_space_write_4() instead of outl() anyway. :) -- John Baldwin <>< http://www.FreeBSD.org/~jhb/ "Power Users Use the Power to Serve" = http://www.FreeBSD.org From owner-freebsd-drivers@FreeBSD.ORG Fri Oct 28 22:57:16 2005 Return-Path: X-Original-To: freebsd-drivers@freebsd.org Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C940916A420 for ; Fri, 28 Oct 2005 22:57:16 +0000 (GMT) (envelope-from bharmaji@gmail.com) Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.197]) by mx1.FreeBSD.org (Postfix) with ESMTP id D680D43D4C for ; Fri, 28 Oct 2005 22:57:15 +0000 (GMT) (envelope-from bharmaji@gmail.com) Received: by xproxy.gmail.com with SMTP id t14so423897wxc for ; Fri, 28 Oct 2005 15:57:15 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=fSel9wR2bJk/74vgEBtvIU4J5Ed5W9EW1ydlIGod8caIJPF7bVVnU8z4jlfLbx8S9KAcPOt+TBuh9iufMNCRpV1cmStL7nVr9XNc7nIs2yxdsolt3AcirkQ6ksqAluI68OaLgnNuNCyMWC8ReOoLryL0mb8grGWhZNcocE5m9CI= Received: by 10.65.96.7 with SMTP id y7mr468877qbl; Fri, 28 Oct 2005 15:57:15 -0700 (PDT) Received: by 10.65.124.10 with HTTP; Fri, 28 Oct 2005 15:57:15 -0700 (PDT) Message-ID: <67beabb0510281557k5d237a0br9b586bdde35c6971@mail.gmail.com> Date: Fri, 28 Oct 2005 15:57:15 -0700 From: Bharma Ji To: freebsd-drivers@freebsd.org In-Reply-To: <20051017.210955.104032631.imp@bsdimp.com> MIME-Version: 1.0 References: <67beabb0510171825q1e124bf6v2adbe0c9f235a6ae@mail.gmail.com> <20051017.210955.104032631.imp@bsdimp.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Subject: Re: Recommended ways to log driver operations X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Oct 2005 22:57:16 -0000 Resurrecting a recent thread... Thanks for your resposne. ktr and alq are unfortunately not availabe on the freebsd version that I am using. I have reduced my requirements for the logging facility. Now all I require is that the log be persistent. The problem that I face is that in the event of a kernel panic - the driver messages are all lost.Is there a way to writ= e the messages to the disk while the driver is executing.(seems to much to as= k probably - but someone somewhere would have thought of a way around it) On 10/17/05, M. Warner Losh wrote: > > In message: <67beabb0510171825q1e124bf6v2adbe0c9f235a6ae@mail.gmail.com> > Bharma Ji writes: > : I recently wrote a driver for a chip. I am wondering if there are any > : standard recommended ways of logging the driver operations. I have used > : printf in the driver and I look at it using dmesg so far. Am wondering > if it > : is possible to create a driver specific log file so that it is easy to > : debug. Also, if the driver emits copious output then the log buffer wil= l > : overflow and some messages may be truncated. Writing to a specific log > file > : may help in that case. However, I have no idea if this is worth > : investigating. Any suggestions appreciated > > printf(9) doesn't give you much of a chance to segregate the logs. You > can also use log(9), but that just adds the ability to give a priority > to the log message, which can help. > > If you want to debug the driver to find out what's going on at a high > rate, you might want to look at ktr(9) and alq(9). These facilities > are more for debugging and performance tuning, rather than day to day > operations. In general, FreeBSD drivers follow the unix tradition of > only complaining when there are problems. > > Warner > From owner-freebsd-drivers@FreeBSD.ORG Fri Oct 28 23:06:48 2005 Return-Path: X-Original-To: freebsd-drivers@freebsd.org Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 737C516A41F for ; Fri, 28 Oct 2005 23:06:48 +0000 (GMT) (envelope-from imp@bsdimp.com) Received: from harmony.bsdimp.com (vc4-2-0-87.dsl.netrack.net [199.45.160.85]) by mx1.FreeBSD.org (Postfix) with ESMTP id BF9CB43D48 for ; Fri, 28 Oct 2005 23:06:47 +0000 (GMT) (envelope-from imp@bsdimp.com) Received: from localhost (localhost.village.org [127.0.0.1] (may be forged)) by harmony.bsdimp.com (8.13.3/8.13.3) with ESMTP id j9SN6AFN063829; Fri, 28 Oct 2005 17:06:11 -0600 (MDT) (envelope-from imp@bsdimp.com) Date: Fri, 28 Oct 2005 17:06:14 -0600 (MDT) Message-Id: <20051028.170614.58438314.imp@bsdimp.com> To: bharmaji@gmail.com From: "M. Warner Losh" In-Reply-To: <67beabb0510281557k5d237a0br9b586bdde35c6971@mail.gmail.com> References: <67beabb0510171825q1e124bf6v2adbe0c9f235a6ae@mail.gmail.com> <20051017.210955.104032631.imp@bsdimp.com> <67beabb0510281557k5d237a0br9b586bdde35c6971@mail.gmail.com> X-Mailer: Mew version 3.3 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.0 (harmony.bsdimp.com [127.0.0.1]); Fri, 28 Oct 2005 17:06:11 -0600 (MDT) Cc: freebsd-drivers@freebsd.org Subject: Re: Recommended ways to log driver operations X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Oct 2005 23:06:48 -0000 In message: <67beabb0510281557k5d237a0br9b586bdde35c6971@mail.gmail.com> Bharma Ji writes: : Resurrecting a recent thread... : Thanks for your resposne. ktr and alq are unfortunately not availabe on the : freebsd version that I am using. : I have reduced my requirements for the logging facility. Now all I require : is that the log be persistent. The problem that I face is that in the event : of a kernel panic - the driver messages are all lost.Is there a way to write : the messages to the disk while the driver is executing.(seems to much to ask : probably - but someone somewhere would have thought of a way around it) If all you want is for them to be persistant, then printf will put them into the dmesg buffer which you can extract via the debugger from either a core file or a live system that's paniced. If there's sufficient time between the last printf and a panic, then syslog will have flushed it to disk... Warner