Intel Moorestown NAND driver patch for mainline
PATCH 1/2 Intel Moorestown NAND driver patch for mainline
Hi Greg,
This is the first Intel Moorestown NAND driver patch for mainline. I generated it and complie it against Linus' kernel tree, tag v2.6.30-rc8.
Thanks.
Rgds,
Yunpeng
Quoted 1 line
From
a2fee2ccfbc8d16baff04368294f208c88b89bb8Mon Sep 17 00:00:00 2001
From: Gao Yunpeng <[email protected]>
Date: Sat, 6 Jun 2009 21:27:42 +0800
Subject: [PATCH] First submission of Intel Moorestown platform NAND flash driver
This driver is a standalone linux block device driver. It acts as a normal hard disk. You can reference the README file for detail. The driver has been tested on Intel Moorestown platform (kernel 2.6.30-rc6).
This patch is generated against Linus' kernel tree (tag v2.6.30-rc8) and has passed compiling.
--- drivers/staging/Kconfig | 2 + drivers/staging/Makefile | 1 + drivers/staging/mrst_nand/Kconfig | 27 + drivers/staging/mrst_nand/Makefile | 7 + drivers/staging/mrst_nand/NAND_Regs_4.h | 619 ++++ drivers/staging/mrst_nand/README | 29 + drivers/staging/mrst_nand/ffsdefs.h | 58 + drivers/staging/mrst_nand/ffsport.c | 953 ++++++ drivers/staging/mrst_nand/ffsport.h | 89 + drivers/staging/mrst_nand/flash.c | 4150 +++++++++++++++++++++++++++ drivers/staging/mrst_nand/flash.h | 158 + drivers/staging/mrst_nand/lld.c | 492 ++++ drivers/staging/mrst_nand/lld.h | 123 + drivers/staging/mrst_nand/lld_cdma.c | 2736 ++++++++++++++++++ drivers/staging/mrst_nand/lld_cdma.h | 138 + drivers/staging/mrst_nand/lld_emu.c | 788 +++++ drivers/staging/mrst_nand/lld_emu.h | 51 + drivers/staging/mrst_nand/lld_nand.c | 3113 ++++++++++++++++++++ drivers/staging/mrst_nand/lld_nand.h | 116 + drivers/staging/mrst_nand/spectraswconfig.h | 86 + 20 files changed, 13736 insertions(+), 0 deletions(-) create mode 100644 drivers/staging/mrst_nand/Kconfig create mode 100644 drivers/staging/mrst_nand/Makefile create mode 100644 drivers/staging/mrst_nand/NAND_Regs_4.h create mode 100644 drivers/staging/mrst_nand/README create mode 100644 drivers/staging/mrst_nand/ffsdefs.h create mode 100644 drivers/staging/mrst_nand/ffsport.c create mode 100644 drivers/staging/mrst_nand/ffsport.h create mode 100644 drivers/staging/mrst_nand/flash.c create mode 100644 drivers/staging/mrst_nand/flash.h create mode 100644 drivers/staging/mrst_nand/lld.c create mode 100644 drivers/staging/mrst_nand/lld.h create mode 100644 drivers/staging/mrst_nand/lld_cdma.c create mode 100644 drivers/staging/mrst_nand/lld_cdma.h create mode 100644 drivers/staging/mrst_nand/lld_emu.c create mode 100644 drivers/staging/mrst_nand/lld_emu.h create mode 100644 drivers/staging/mrst_nand/lld_nand.c create mode 100644 drivers/staging/mrst_nand/lld_nand.h create mode 100644 drivers/staging/mrst_nand/spectraswconfig.h
drivers/staging/Kconfig +2 -0
@@ -115,5 +115,7 @@ source "drivers/staging/line6/Kconfig" source "drivers/staging/serqt_usb/Kconfig" +source "drivers/staging/mrst_nand/Kconfig" + endif # !STAGING_EXCLUDE_BUILD endif # STAGING
drivers/staging/Makefile +1 -0
@@ -40,3 +40,4 @@ obj-$(CONFIG_PLAN9AUTH) += p9auth/ obj-$(CONFIG_HECI) += heci/ obj-$(CONFIG_LINE6_USB) += line6/ obj-$(CONFIG_USB_SERIAL_QUATECH_ESU100) += serqt_usb/ +obj-$(CONFIG_MRST_NAND) += mrst_nand/
drivers/staging/mrst_nand/Kconfig new file +27 -0
@@ -0,0 +1,27 @@ + +menuconfig MRST_NAND + tristate "Moorestown NAND Flash controller" + depends on BLOCK + default n + ---help--- + Enable the driver for the NAND Flash controller in Intel Moorestown + Platform + +choice + prompt "Compile for" + depends on MRST_NAND + default MRST_NAND_HW + +config MRST_NAND_HW + bool "Actual hardware mode" + help + Driver communicates with the actual hardware's register interface. + in DMA mode. + +config MRST_NAND_EMU + bool "RAM emulator testing" + help + Driver emulates Flash on a RAM buffer and / or disk file. Useful to test the behavior of FTL layer. + +endchoice +
drivers/staging/mrst_nand/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# +# Makefile of Intel Moorestown NAND controller driver +# + +obj-$(CONFIG_MRST_NAND) += spectra.o +spectra-objs := ffsport.o flash.o lld.o lld_emu.o lld_nand.o lld_cdma.o +
drivers/staging/mrst_nand/NAND_Regs_4.h new file +619 -0
619 lines not on this page · raw message
drivers/staging/mrst_nand/README new file +29 -0
@@ -0,0 +1,29 @@ +This is a driver for NAND controller of Intel Moorestown platform. + +This driver is a standalone linux block device driver, it acts as if it's a normal hard disk. +It includes three layer: + block layer interface - file ffsport.c + Flash Translation Layer (FTL) - file flash.c (implement the NAND flash Translation Layer, includs address mapping, garbage collection, wear-leveling and so on) + Low level layer - file lld_nand.c/lld_cdma.c/lld_emu.c (which implements actual controller hardware registers access) + +This driver can be build as modules or build-in. + +Dependency: +This driver has dependency on IA Firmware of Intel Moorestown platform. +It need the IA Firmware to create the block table for the first time. +And to validate this driver code without IA Firmware, you can change the +macro AUTO_FORMAT_FLASH from 0 to 1 in file spectraswconfig.h. Thus the +driver will erase the whole nand flash and create a new block table. + +TODO: + - Enable Command DMA feature support + - lower the memory footprint + - Remove most of the unnecessary global variables + - Change all the upcase variable / functions name to lowercase + - Some other misc bugs + +Please send patches to: + Greg Kroah-Hartman <[email protected]> + +And Cc to: Gao Yunpeng <[email protected]> +
drivers/staging/mrst_nand/ffsdefs.h new file +58 -0
58 lines not on this page · raw message
drivers/staging/mrst_nand/ffsport.c new file +953 -0
953 lines not on this page · raw message
drivers/staging/mrst_nand/ffsport.h new file +89 -0
89 lines not on this page · raw message
drivers/staging/mrst_nand/flash.c new file +4150 -0
1,207 lines not on this page · raw message
drivers/staging/mrst_nand/flash.h new file +158 -0
158 lines not on this page · raw message
drivers/staging/mrst_nand/lld.c new file +492 -0
492 lines not on this page · raw message
drivers/staging/mrst_nand/lld.h new file +123 -0
123 lines not on this page · raw message
drivers/staging/mrst_nand/lld_cdma.c new file +2736 -0
2,736 lines not on this page · raw message
drivers/staging/mrst_nand/lld_cdma.h new file +138 -0
138 lines not on this page · raw message
drivers/staging/mrst_nand/lld_emu.c new file +788 -0
788 lines not on this page · raw message
drivers/staging/mrst_nand/lld_emu.h new file +51 -0
51 lines not on this page · raw message
drivers/staging/mrst_nand/lld_nand.c new file +3113 -0
3,113 lines not on this page · raw message
drivers/staging/mrst_nand/lld_nand.h new file +116 -0
116 lines not on this page · raw message
drivers/staging/mrst_nand/spectraswconfig.h new file +86 -0
86 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.5.4.5
Part of the diff is not shown here. View the raw message.
Quoted 6 lines · Yunpeng Gao
drivers/staging/mrst_nand/ffsport.c new file +0
-0
drivers/staging/mrst_nand/ffsport.c line 9
Quoted 9 lines
drivers/staging/mrst_nand/ffsport.c new file +9
-0@@ -0,0 +1,953 @@ +void glob_udelay (unsigned long usecs) +{ +udelay (usecs); +} + +void glob_mdelay (unsigned long msecs) +{ +mdelay (msecs); +}
Unneeded wrappers.
drivers/staging/mrst_nand/ffsport.c line 126
Quoted 4 lines
drivers/staging/mrst_nand/ffsport.c new file +4
-0+u32 *GLOB_MEMMAP_NOCACHE (unsigned long addr,unsigned long size) +{ +#if (FLASH_NAND ||FLASH_CDMA ) +return (u32 *)ioremap_nocache (addr, (size+0xfff )&(~0xfff ));
Use ALIGN() and no cast.
drivers/staging/mrst_nand/ffsport.c line 135
Quoted 9 lines
drivers/staging/mrst_nand/ffsport.c new file +9
-0+#else +return (u32 *)addr; +#endif +} + +u32 *GLOB_MEMMAP_TOBUS (u32 *ptr) +{ +#if (FLASH_NAND ||FLASH_CDMA ) +return (u32 *)virt_to_bus (ptr);
Aiee, virt_to_bus.
Quoted 4 lines
drivers/staging/mrst_nand/ffsport.c new file +4
-0+#else +return ptr; +#endif +}
...
drivers/staging/mrst_nand/ffsport.c line 159
Quoted 10 lines
drivers/staging/mrst_nand/ffsport.c new file +10
-0+#define GLOB_SBD_IOCTL_GC (0x7701) +#define GLOB_SBD_IOCTL_WL (0x7702) +#define GLOB_SBD_IOCTL_FORMAT (0x7703) +#define GLOB_SBD_IOCTL_ERASE_FLASH (0x7704) +#define GLOB_SBD_IOCTL_FLUSH_CACHE (0x7705) +#define GLOB_SBD_IOCTL_COPY_BLK_TABLE (0x7706) +#define GLOB_SBD_IOCTL_COPY_WEAR_LEVELING_TABLE (0x7707) +#define GLOB_SBD_IOCTL_GET_NAND_INFO (0x7708) +#define GLOB_SBD_IOCTL_WRITE_DATA (0x7709) +#define GLOB_SBD_IOCTL_READ_DATA (0x770A)
Could this be defined in an ioctl-standard way?
drivers/staging/mrst_nand/ffsport.c line 189
Quoted 3 lines
drivers/staging/mrst_nand/ffsport.c new file +3
-0+static int GLOB_SBD_majornum; + +static char *GLOB_version =GLOB_VERSION ;
You will save a pointer by char [] instead of char *. Also constify it.
drivers/staging/mrst_nand/ffsport.c line 198
Quoted 6 lines
drivers/staging/mrst_nand/ffsport.c new file +6
-0+/* Because the driver will allocate a lot of memory and kmalloc can not */ +/* allocat memory more than 4M bytes, here we use static array as */ +/* memory pool. This is simple but ugly. It should only be used during */ +/* development.*/ +#define LOCAL_MEM_POOL_SIZE (1024 * 1024 * 8) +static u8 local_mem_pool[LOCAL_MEM_POOL_SIZE ];
Bah. We have vmalloc.
drivers/staging/mrst_nand/ffsport.c line 244
Quoted 4 lines
drivers/staging/mrst_nand/ffsport.c new file +4
-0+struct ioctl_rw_page_info { +u8 *data; +unsigned int page; +};
32/64-bit incompatible.
drivers/staging/mrst_nand/ffsport.c line 694
Quoted 5 lines
drivers/staging/mrst_nand/ffsport.c new file +5
-0+static struct block_device_operations GLOB_SBD_ops = { + .owner =THIS_MODULE , + .open = GLOB_SBD_open, + .release = GLOB_SBD_release, + .locked_ioctl = GLOB_SBD_ioctl,
Could this be switched to an unlocked one first?
Quoted 30 lines
drivers/staging/mrst_nand/ffsport.c new file +30
-0+ .getgeo = GLOB_SBD_getgeo, +}; + +static int SBD_setup_device (struct spectra_nand_dev *dev,int which) +{ +int res_blks; +u32 sects; + +nand_dbg_print (NAND_DBG_TRACE ,"%s, Line %d, Function: %s\n" , + __FILE__, __LINE__, __func__); + +memset (dev,0 ,sizeof (struct spectra_nand_dev )); + +nand_dbg_print (NAND_DBG_WARN ,"Reserved %d blocks " +"for OS image, %d blocks for bad block replacement.\n" , +get_res_blk_num_os (), +get_res_blk_num_bad_blk ()); + + res_blks =get_res_blk_num_bad_blk () +get_res_blk_num_os (); + + dev->size = (u64 )IdentifyDeviceData.PageDataSize * + IdentifyDeviceData.PagesPerBlock * + (IdentifyDeviceData.wDataBlockNum - res_blks); + + res_blks_os =get_res_blk_num_os (); + +spin_lock_init (&dev->qlock); + + dev->tmp_buf =kmalloc (IdentifyDeviceData.PageDataSize,GFP_ATOMIC ); +if (!dev->tmp_buf) {
drivers/staging/mrst_nand/ffsport.c line 734
Quoted 10 lines
drivers/staging/mrst_nand/ffsport.c new file +10
-0+printk (KERN_ERR "Failed to kmalloc memory in %s Line %d, exit.\n" , + __FILE__, __LINE__); + goto out_vfree; + } + + dev->queue =blk_init_queue (GLOB_SBD_request, &dev->qlock); +if (dev->queue ==NULL ) { +printk (KERN_ERR +"Spectra: Request queue could not be initialized." +" Aborting\n " );
memleak? and further in that function.
Quoted 8 lines
drivers/staging/mrst_nand/ffsport.c new file +1
-0+ goto out_vfree;drivers/staging/mrst_nand/lld_cdma.c new file +0
-0@@ -0,0 +1,2736 @@
...
Quoted 8 lines
drivers/staging/mrst_nand/lld_cdma.c new file +8
-0+static u16 do_ecc_for_desc (u16 c,u8 *buf, +u16 page) +{ +u16 event =EVENT_NONE ; +u16 err_byte; +u8 err_sector; +u8 err_page =0 ; +u8 err_device;
drivers/staging/mrst_nand/lld_cdma.c line 1416
Quoted 10 lines
drivers/staging/mrst_nand/lld_cdma.c new file +10
-0+u16 ecc_correction_info; +u16 err_address; +u32 eccSectorSize; +u8 *err_pos; + + eccSectorSize =ECC_SECTOR_SIZE * (DeviceInfo.wDevicesConnected); + + do { + if (0 == c) + err_page = ioread32(FlashReg + ERR_PAGE_ADDR0);
FlashReg doesn't look like an iomap memory. Use readl/writel all over the driver.
Quoted 62 lines
drivers/staging/mrst_nand/lld_cdma.c new file +62
-0+static int check_for_ording (struct pending_cmd (*p)[MAX_CHANS +MAX_DESCS ], +int *chis,int *chMaxIndexes,int (*namb)[MAX_CHANS ]) +{ +int i, done, ch1, ch2, syncNum, syncNum2; +u8 indexchgd; + + indexchgd =0 ; +for (i =0 ; (i < totalUsedBanks) && !done && !indexchgd; i++) { +if (!EOLIST (i) && +get_sync_ch_pcmd (p, i, chis[i], &syncNum, &ch1)) { +debug_boundary_error (ch1, totalUsedBanks,0 ); +if (!EOLIST (ch1) &&get_sync_ch_pcmd (p, ch1, + chis[ch1], &syncNum2, &ch2)) { +debug_boundary_error (ch2, totalUsedBanks,0 ); +if ((syncNum == syncNum2) && + (syncNum !=FORCED_ORDERED_SYNC )) { +if (ch2 != i) { +nand_dbg_print (NAND_DBG_DEBUG , +"SYNCCHECK: ILLEGAL CASE: " +"Channel %d, cmdindx %d, " +"tag %d is waiting for " +"sync number %d " +"from channel %d, " +"which is waiting for " +"the same sync number " +"from channel %d. " +"Sync checking is aborting\n" , + i, chis[i], + p[i][chis[i]].Tag, + syncNum, ch1, ch2); + done =1 ; + }else { +if (!(debug_sync_cnt % +DBG_SNC_PRINTEVERY )) { +nand_dbg_print ( +NAND_DBG_DEBUG , +"SYNCCHECK: " +"syncnum %d " +"betn Ch %d, " +"cmdindx %d, " +"tag %d & Ch %d, " +"cmdindx %d, tag %d. " +"chis=" +"{%d, %d, %d, %d}\n" , + syncNum, i, + chis[i], + p[i][chis[i]].Tag, + ch1, chis[ch1], + p[ch1][chis[ch1]].Tag, + chis[0 ], chis[1 ], + chis[2 ], chis[3 ]); + } +if (!check_ordering (p, i, + namb[ch1][i]+1 , + chis[i], ch1, + namb[i][ch1]+1 , + chis[ch1])) +nand_dbg_print ( +NAND_DBG_DEBUG , +"Above problem " +"occured when " + "analyzing "
drivers/staging/mrst_nand/lld_cdma.c line 2640
Quoted 10 lines
drivers/staging/mrst_nand/lld_cdma.c new file +10
-0+"sync %d " +"between " +"(ch:%d, indx:%d, " +"tag:%d) & " +"(ch:%d, indx:%d, " +"tag:%d)\n" , + syncNum, i, chis[i], + p[i][chis[i]].Tag, + ch1, chis[ch1], + p[ch1][chis[ch1]].Tag);
Hmm, pretty unreadable. You seem to need to refactor the code.
Quoted 6 lines
drivers/staging/mrst_nand/lld_nand.c new file +0
-0@@ -0,0 +1,3113 @@
...
Quoted 1 line
+#define
CEIL_DIV(X, Y)(((X)%(Y)) ? ((X)/(Y)+1) : ((X)/(Y)))
Is this DIV_ROUND_UP?
Quoted 1 line
+u16 conf_parameters[] = {
const?
drivers/staging/mrst_nand/lld_nand.c line 312
Quoted 13 lines
drivers/staging/mrst_nand/lld_nand.c new file +13
-0+static u16 get_onfi_nand_para (void ) +{ +int i; +u16 blks_lun_l, blks_lun_h, n_of_luns; +u32 blockperlun, id; + +iowrite32 (DEVICE_RESET__BANK0 , FlashReg +DEVICE_RESET ); + +while (!((ioread32 (FlashReg +INTR_STATUS0 ) & +INTR_STATUS0__RST_COMP ) | + (ioread32 (FlashReg +INTR_STATUS0 ) & +INTR_STATUS0__TIME_OUT ))) + ;
cpu_relax(); And the same further in this function.
drivers/staging/mrst_nand/lld_nand.c line 2622
Quoted 6 lines
drivers/staging/mrst_nand/lld_nand.c new file +6
-0+static const struct pci_device_id nand_pci_ids[] = { + { + .vendor =0x8086 , + .device =0x0809 , + .subvendor =PCI_ANY_ID , + .subdevice =PCI_ANY_ID ,
PCI_DEVICE()
drivers/staging/mrst_nand/lld_nand.c line 2627
Quoted 5 lines
drivers/staging/mrst_nand/lld_nand.c new file +5
-0+ }, + {/* end: all zeroes */ } +}; + +static int dump_pci_config_register (struct pci_dev *dev)
What is this good for?
Quoted 1 line
+static struct
pci_drivernand_pci_driver= {
const
Quoted 8 lines
drivers/staging/mrst_nand/lld_nand.c new file +8
-0+ .name = SPECTRA_NAND_NAME, + .id_table = nand_pci_ids, + .probe = nand_pci_probe, + .remove = nand_pci_remove, +}; + +u16 NAND_Flash_Init (void ) +{
...
Quoted 4 lines
drivers/staging/mrst_nand/lld_nand.c new file +4
-0+ FlashReg =GLOB_MEMMAP_NOCACHE (GLOB_HWCTL_REG_BASE , +GLOB_HWCTL_REG_SIZE ); +if (!FlashReg) { +printk (KERN_ERR "Spectra: ioremap_nocache failed!" );
drivers/staging/mrst_nand/lld_nand.c line 3000
Quoted 10 lines
drivers/staging/mrst_nand/lld_nand.c new file +10
-0+return -ENOMEM ; + } +nand_dbg_print (NAND_DBG_WARN , +"Spectra: Remapped reg base address: " +"0x%p, len: %d\n" , + FlashReg,GLOB_HWCTL_REG_SIZE ); + + FlashMem =GLOB_MEMMAP_NOCACHE (GLOB_HWCTL_MEM_BASE , +GLOB_HWCTL_MEM_SIZE ); +if (!FlashMem) {
unmap?
Quoted 3 lines
drivers/staging/mrst_nand/lld_nand.c new file +3
-0+printk (KERN_ERR "Spectra: ioremap_nocache failed!" ); +return -ENOMEM ; + }
...
drivers/staging/mrst_nand/lld_nand.c line 3045
Quoted 9 lines
drivers/staging/mrst_nand/lld_nand.c new file +9
-0+/* Enable the 2 lines code will enable pipeline_rw_ahead feature */ +/* and improve performance for about 10%. But will also cause a */ +/* 1 or 2 bit error when do a 300MB+ file copy/compare testing. */ +/* Suspect it's an ECC FIFO overflow issue. -- Yunpeng 2009.03.26 */ +/* iowrite32(1, FlashReg + CACHE_WRITE_ENABLE); */ +/* iowrite32(1, FlashReg + CACHE_READ_ENABLE); */ + + retval =pci_register_driver (&nand_pci_driver); +if (retval)
unmap?
drivers/staging/mrst_nand/lld_nand.c line 3051
Quoted 6 lines
drivers/staging/mrst_nand/lld_nand.c new file +6
-0+return -ENOMEM ; + + return PASS; +} + +#endif
HTH.
Quoted 4 lines · On Sun, 7 Jun 2009 00:44:55 +0800 Yunpeng Gao <[email protected]> wrote:
Hi Greg,
This is the first Intel Moorestown NAND driver patch for mainline. I generated it and complie it against Linus' kernel tree, tag v2.6.30-rc8.
Flash drivers should go to David Woodhouse <[email protected]> as he maintains the mtd layer flash support code (which you don't seem to be using ?)
Quoted 10 lines · Jiri Slaby
Quoted 9 lines · Yunpeng Gao
drivers/staging/mrst_nand/ffsport.c new file +3
-0@@ -0,0 +1,953 @@ +void glob_udelay (unsigned long usecs) +{ +udelay (usecs);
Quoted 8 lines
drivers/staging/mrst_nand/ffsport.c line 121
Quoted 6 lines
drivers/staging/mrst_nand/ffsport.c new file +6
-0+} + +void glob_mdelay (unsigned long msecs) +{ +mdelay (msecs); +}Unneeded wrappers.
<snip>
Thanks for the review, this is one reason why it's in the staging directory :)
Hopefully someone can send follow-on patches implementing these fixups (hint...)
greg k-h
Quoted 344 lines
-----Original Message-----
From: Jiri Slaby [mailto:[email protected]]
Sent: 2009年6月6日 19:12
To: Gao, Yunpeng
Cc: [email protected]; [email protected]
Subject: Re: [PATCH 1/2]Intel Moorestown NAND driver patch for mainlineReview
Quoted 1 line · Yunpeng Gao
(quoted diff) +0
-0
b/drivers/staging/mrst_nand/ffsport.cQuoted 5 lines
new file mode 100644
index 0000000..5a919f4drivers/staging/mrst_nand/ffsport.c line 9
Quoted 9 lines
drivers/staging/mrst_nand/ffsport.c new file +9
-0@@ -0,0 +1,953 @@ +void glob_udelay (unsigned long usecs) +{ +udelay (usecs); +} + +void glob_mdelay (unsigned long msecs) +{ +mdelay (msecs); +}Unneeded wrappers.
drivers/staging/mrst_nand/ffsport.c line 126
Quoted 4 lines
drivers/staging/mrst_nand/ffsport.c new file +4
-0+u32 *GLOB_MEMMAP_NOCACHE (unsigned long addr,unsigned long size) +{ +#if (FLASH_NAND ||FLASH_CDMA ) +return (u32 *)ioremap_nocache (addr, (size+0xfff )&(~0xfff ));Use
ALIGN()and no cast.drivers/staging/mrst_nand/ffsport.c line 135
Quoted 9 lines
drivers/staging/mrst_nand/ffsport.c new file +9
-0+#else +return (u32 *)addr; +#endif +} + +u32 *GLOB_MEMMAP_TOBUS (u32 *ptr) +{ +#if (FLASH_NAND ||FLASH_CDMA ) +return (u32 *)virt_to_bus (ptr);Aiee,
virt_to_bus.Quoted 4 lines
drivers/staging/mrst_nand/ffsport.c new file +4
-0+#else +return ptr; +#endif +}...
Quoted 1 line
+#define
GLOB_SBD_IOCTL_GC(
0x7701)Quoted 1 line
+#define
GLOB_SBD_IOCTL_WL(
0x7702)Quoted 1 line
+#define
GLOB_SBD_IOCTL_FORMAT(
0x7703)drivers/staging/mrst_nand/ffsport.c line 159
Quoted 7 lines
drivers/staging/mrst_nand/ffsport.c new file +7
-0+#define GLOB_SBD_IOCTL_ERASE_FLASH (0x7704) +#define GLOB_SBD_IOCTL_FLUSH_CACHE (0x7705) +#define GLOB_SBD_IOCTL_COPY_BLK_TABLE (0x7706) +#define GLOB_SBD_IOCTL_COPY_WEAR_LEVELING_TABLE (0x7707) +#define GLOB_SBD_IOCTL_GET_NAND_INFO (0x7708) +#define GLOB_SBD_IOCTL_WRITE_DATA (0x7709) +#define GLOB_SBD_IOCTL_READ_DATA (0x770A)Could this be defined in an ioctl-standard way?
drivers/staging/mrst_nand/ffsport.c line 189
Quoted 3 lines
drivers/staging/mrst_nand/ffsport.c new file +3
-0+static int GLOB_SBD_majornum; + +static char *GLOB_version =GLOB_VERSION ;You will save a pointer by char [] instead of char *. Also constify it.
drivers/staging/mrst_nand/ffsport.c line 198
Quoted 6 lines
drivers/staging/mrst_nand/ffsport.c new file +6
-0+/* Because the driver will allocate a lot of memory and kmalloc can not */ +/* allocat memory more than 4M bytes, here we use static array as */ +/* memory pool. This is simple but ugly. It should only be used during */ +/* development.*/ +#define LOCAL_MEM_POOL_SIZE (1024 * 1024 * 8) +static u8 local_mem_pool[LOCAL_MEM_POOL_SIZE ];Bah. We have vmalloc.
drivers/staging/mrst_nand/ffsport.c line 244
Quoted 4 lines
drivers/staging/mrst_nand/ffsport.c new file +4
-0+struct ioctl_rw_page_info { +u8 *data; +unsigned int page; +};32/64-bit incompatible.
drivers/staging/mrst_nand/ffsport.c line 694
Quoted 5 lines
drivers/staging/mrst_nand/ffsport.c new file +5
-0+static struct block_device_operations GLOB_SBD_ops = { + .owner =THIS_MODULE , + .open = GLOB_SBD_open, + .release = GLOB_SBD_release, + .locked_ioctl = GLOB_SBD_ioctl,Could this be switched to an unlocked one first?
Quoted 30 lines
drivers/staging/mrst_nand/ffsport.c new file +30
-0+ .getgeo = GLOB_SBD_getgeo, +}; + +static int SBD_setup_device (struct spectra_nand_dev *dev,int which) +{ +int res_blks; +u32 sects; + +nand_dbg_print (NAND_DBG_TRACE ,"%s, Line %d, Function: %s\n" , + __FILE__, __LINE__, __func__); + +memset (dev,0 ,sizeof (struct spectra_nand_dev )); + +nand_dbg_print (NAND_DBG_WARN ,"Reserved %d blocks " +"for OS image, %d blocks for bad block replacement.\n" , +get_res_blk_num_os (), +get_res_blk_num_bad_blk ()); + + res_blks =get_res_blk_num_bad_blk () +get_res_blk_num_os (); + + dev->size = (u64 )IdentifyDeviceData.PageDataSize * + IdentifyDeviceData.PagesPerBlock * + (IdentifyDeviceData.wDataBlockNum - res_blks); + + res_blks_os =get_res_blk_num_os (); + +spin_lock_init (&dev->qlock); + + dev->tmp_buf =kmalloc (IdentifyDeviceData.PageDataSize,GFP_ATOMIC ); +if (!dev->tmp_buf) {drivers/staging/mrst_nand/ffsport.c line 734
Quoted 10 lines
drivers/staging/mrst_nand/ffsport.c new file +10
-0+printk (KERN_ERR "Failed to kmalloc memory in %s Line %d, exit.\n" , + __FILE__, __LINE__); + goto out_vfree; + } + + dev->queue =blk_init_queue (GLOB_SBD_request, &dev->qlock); +if (dev->queue ==NULL ) { +printk (KERN_ERR +"Spectra: Request queue could not be initialized." +" Aborting\n " );memleak? and further in that function.
Review
Quoted 3 lines
drivers/staging/mrst_nand/ffsport.c new file +1
-0+ goto out_vfree;(quoted diff) +0
-0
b/drivers/staging/mrst_nand/lld_cdma.cQuoted 5 lines
new file mode 100644
index 0000000..19650c2drivers/staging/mrst_nand/lld_cdma.c new file +0
-0@@ -0,0 +1,2736 @@...
Quoted 8 lines
drivers/staging/mrst_nand/lld_cdma.c new file +8
-0+static u16 do_ecc_for_desc (u16 c,u8 *buf, +u16 page) +{ +u16 event =EVENT_NONE ; +u16 err_byte; +u8 err_sector; +u8 err_page =0 ; +u8 err_device;drivers/staging/mrst_nand/lld_cdma.c line 1416
Quoted 10 lines
drivers/staging/mrst_nand/lld_cdma.c new file +10
-0+u16 ecc_correction_info; +u16 err_address; +u32 eccSectorSize; +u8 *err_pos; + + eccSectorSize =ECC_SECTOR_SIZE * (DeviceInfo.wDevicesConnected); + + do { + if (0 == c) + err_page = ioread32(FlashReg + ERR_PAGE_ADDR0);FlashReg doesn't look like an iomap memory. Use readl/writel all over the driver.
Quoted 62 lines
drivers/staging/mrst_nand/lld_cdma.c new file +62
-0+static int check_for_ording (struct pending_cmd (*p)[MAX_CHANS +MAX_DESCS ], +int *chis,int *chMaxIndexes,int (*namb)[MAX_CHANS ]) +{ +int i, done, ch1, ch2, syncNum, syncNum2; +u8 indexchgd; + + indexchgd =0 ; +for (i =0 ; (i < totalUsedBanks) && !done && !indexchgd; i++) { +if (!EOLIST (i) && +get_sync_ch_pcmd (p, i, chis[i], &syncNum, &ch1)) { +debug_boundary_error (ch1, totalUsedBanks,0 ); +if (!EOLIST (ch1) &&get_sync_ch_pcmd (p, ch1, + chis[ch1], &syncNum2, &ch2)) { +debug_boundary_error (ch2, totalUsedBanks,0 ); +if ((syncNum == syncNum2) && + (syncNum !=FORCED_ORDERED_SYNC )) { +if (ch2 != i) { +nand_dbg_print (NAND_DBG_DEBUG , +"SYNCCHECK: ILLEGAL CASE: " +"Channel %d, cmdindx %d, " +"tag %d is waiting for " +"sync number %d " +"from channel %d, " +"which is waiting for " +"the same sync number " +"from channel %d. " +"Sync checking is aborting\n" , + i, chis[i], + p[i][chis[i]].Tag, + syncNum, ch1, ch2); + done =1 ; + }else { +if (!(debug_sync_cnt % +DBG_SNC_PRINTEVERY )) { +nand_dbg_print ( +NAND_DBG_DEBUG , +"SYNCCHECK: " +"syncnum %d " +"betn Ch %d, " +"cmdindx %d, " +"tag %d & Ch %d, " +"cmdindx %d, tag %d. " +"chis=" +"{%d, %d, %d, %d}\n" , + syncNum, i, + chis[i], + p[i][chis[i]].Tag, + ch1, chis[ch1], + p[ch1][chis[ch1]].Tag, + chis[0 ], chis[1 ], + chis[2 ], chis[3 ]); + } +if (!check_ordering (p, i, + namb[ch1][i]+1 , + chis[i], ch1, + namb[i][ch1]+1 , + chis[ch1])) +nand_dbg_print ( +NAND_DBG_DEBUG , +"Above problem " +"occured when " + "analyzing "drivers/staging/mrst_nand/lld_cdma.c line 2640
Quoted 10 lines
drivers/staging/mrst_nand/lld_cdma.c new file +10
-0+"sync %d " +"between " +"(ch:%d, indx:%d, " +"tag:%d) & " +"(ch:%d, indx:%d, " +"tag:%d)\n" , + syncNum, i, chis[i], + p[i][chis[i]].Tag, + ch1, chis[ch1], + p[ch1][chis[ch1]].Tag);Hmm, pretty unreadable. You seem to need to refactor the code.
Review
Quoted 1 line
(quoted diff) +0
-0
b/drivers/staging/mrst_nand/lld_nand.cQuoted 5 lines
new file mode 100644
index 0000000..56ef843drivers/staging/mrst_nand/lld_nand.c new file +0
-0@@ -0,0 +1,3113 @@...
Quoted 1 line
+#define
CEIL_DIV(X, Y)(((X)%(Y)) ? ((X)/(Y)+1) : ((X)/(Y)))Is this
DIV_ROUND_UP?Quoted 1 line
+u16 conf_parameters[] = {
const?
drivers/staging/mrst_nand/lld_nand.c line 312
Quoted 13 lines
drivers/staging/mrst_nand/lld_nand.c new file +13
-0+static u16 get_onfi_nand_para (void ) +{ +int i; +u16 blks_lun_l, blks_lun_h, n_of_luns; +u32 blockperlun, id; + +iowrite32 (DEVICE_RESET__BANK0 , FlashReg +DEVICE_RESET ); + +while (!((ioread32 (FlashReg +INTR_STATUS0 ) & +INTR_STATUS0__RST_COMP ) | + (ioread32 (FlashReg +INTR_STATUS0 ) & +INTR_STATUS0__TIME_OUT ))) + ;
cpu_relax(); And the same further in this function.drivers/staging/mrst_nand/lld_nand.c line 2622
Quoted 6 lines
drivers/staging/mrst_nand/lld_nand.c new file +6
-0+static const struct pci_device_id nand_pci_ids[] = { + { + .vendor =0x8086 , + .device =0x0809 , + .subvendor =PCI_ANY_ID , + .subdevice =PCI_ANY_ID ,
PCI_DEVICE()drivers/staging/mrst_nand/lld_nand.c line 2627
Quoted 5 lines
drivers/staging/mrst_nand/lld_nand.c new file +5
-0+ }, + {/* end: all zeroes */ } +}; + +static int dump_pci_config_register (struct pci_dev *dev)What is this good for?
Quoted 1 line
+static struct
pci_drivernand_pci_driver= {const
Quoted 8 lines
drivers/staging/mrst_nand/lld_nand.c new file +8
-0+ .name = SPECTRA_NAND_NAME, + .id_table = nand_pci_ids, + .probe = nand_pci_probe, + .remove = nand_pci_remove, +}; + +u16 NAND_Flash_Init (void ) +{...
Quoted 4 lines
drivers/staging/mrst_nand/lld_nand.c new file +4
-0+ FlashReg =GLOB_MEMMAP_NOCACHE (GLOB_HWCTL_REG_BASE , +GLOB_HWCTL_REG_SIZE ); +if (!FlashReg) { +printk (KERN_ERR "Spectra: ioremap_nocache failed!" );drivers/staging/mrst_nand/lld_nand.c line 3000
Quoted 10 lines
drivers/staging/mrst_nand/lld_nand.c new file +10
-0+return -ENOMEM ; + } +nand_dbg_print (NAND_DBG_WARN , +"Spectra: Remapped reg base address: " +"0x%p, len: %d\n" , + FlashReg,GLOB_HWCTL_REG_SIZE ); + + FlashMem =GLOB_MEMMAP_NOCACHE (GLOB_HWCTL_MEM_BASE , +GLOB_HWCTL_MEM_SIZE ); +if (!FlashMem) {unmap?
Quoted 3 lines
drivers/staging/mrst_nand/lld_nand.c new file +3
-0+printk (KERN_ERR "Spectra: ioremap_nocache failed!" ); +return -ENOMEM ; + }...
drivers/staging/mrst_nand/lld_nand.c line 3045
Quoted 9 lines
drivers/staging/mrst_nand/lld_nand.c new file +9
-0+/* Enable the 2 lines code will enable pipeline_rw_ahead feature */ +/* and improve performance for about 10%. But will also cause a */ +/* 1 or 2 bit error when do a 300MB+ file copy/compare testing. */ +/* Suspect it's an ECC FIFO overflow issue. -- Yunpeng 2009.03.26 */ +/* iowrite32(1, FlashReg + CACHE_WRITE_ENABLE); */ +/* iowrite32(1, FlashReg + CACHE_READ_ENABLE); */ + + retval =pci_register_driver (&nand_pci_driver); +if (retval)unmap?
Quoted 8 lines
drivers/staging/mrst_nand/lld_nand.c line 3051
Quoted 6 lines
drivers/staging/mrst_nand/lld_nand.c new file +6
-0+return -ENOMEM ; + + return PASS; +} + +#endif HTH.
Thank you very much for the review. All the comments are very helpful to me. As this driver is still under development (some functional feature is not implemented yet), I'll address these comments after enable some new features and then submit new patches.
Thanks.
Rgds,
Yunpeng �翳簕.n�+壏煯壄�+%娝�遍荻w�簕.n�+壏{炳G珴�妠ay�蕠跈�,jf"穐殢飦�戧鐉_璁(殠娸"濟�m���G珴�⒏?櫒璀�&x忈秈O曟瑉窔v豝�m����鹅�⒏?朓�
Quoted 32 lines
-----Original Message-----
From: Greg KH [mailto:[email protected]]
Sent: 2009年6月6日 22:58
To: Jiri Slaby
Cc: Gao, Yunpeng; [email protected]; [email protected]
Subject: Re: [PATCH 1/2]Intel Moorestown NAND driver patch for mainlineQuoted 2 lines · Jiri Slaby
Review
Quoted 1 line · Yunpeng Gao
(quoted diff) +0
-0
b/drivers/staging/mrst_nand/ffsport.cQuoted 16 lines
Quoted 5 lines
new file mode 100644
index 0000000..5a919f4drivers/staging/mrst_nand/ffsport.c line 9
Quoted 9 lines
drivers/staging/mrst_nand/ffsport.c new file +9
-0@@ -0,0 +1,953 @@ +void glob_udelay (unsigned long usecs) +{ +udelay (usecs); +} + +void glob_mdelay (unsigned long msecs) +{ +mdelay (msecs); +}Unneeded wrappers.
<snip>
Quoted 7 lines
Thanks for the review, this is one reason why it's in the staging directory :)
Hopefully someone can send follow-on patches implementing these fixups (hint...)
greg k-h
Hi Greg,
Thanks a lot for all the comments and reviewing works of community. This NAND driver is still under development. Some functional features are not implemented yet. Also, I know that there's a lot of thing I can do to improve the quality of the driver code.
I plan to enable the new functional features, adjust the data structure, lower the memory footprint in later one or two months. And will submit follow-on patches after I finished those works. I'll try to address the comments of Jiri Slaby in those patches.
Thanks.
Rgds,
Yunpeng �翳簕.n�+壏煯壄�+%娝�遍荻w�簕.n�+壏{炳G珴�妠ay�蕠跈�,jf"穐殢飦�戧鐉_璁(殠娸"濟�m���G珴�⒏?櫒璀�&x忈秈O曟瑉窔v豝�m����鹅�⒏?朓�
Quoted 12 lines
-----Original Message-----
From: Alan Cox [mailto:[email protected]]
Sent: 2009年6月6日 23:04
To: Gao, Yunpeng
Cc: [email protected]; [email protected]
Subject: Re: [PATCH 1/2]Intel Moorestown NAND driver patch for mainlineOn Sun, 7 Jun 2009 00:44:55 +0800
Yunpeng Gao <[email protected]> wrote:
Quoted 8 lines
Quoted 4 lines
Hi Greg,
This is the first Intel Moorestown NAND driver patch for mainline. I generated it and complie it against Linus' kernel tree, tag v2.6.30-rc8.
Flash drivers should go to David Woodhouse <[email protected]> as he maintains the mtd layer flash support code (which you don't seem to be using ?)
Hi Alan,
The Moorestown NAND flash driver is licensed from the Moorestown NAND controller vendor. It's a standalone NAND driver. According to the vendor, this driver has some advanced features specific to the controller hardware and is difficult to port to MTD subsystem.
As the driver is still under development now and not ready for submitting to either block or MTD subsystem, I think it's better to first submit it to staging for widely review. Then after all features of the driver were enabled, we can discuss and decide which subsystem to submit it to.
Thanks.
Rgds,
Yunpeng �翳簕.n�+壏煯壄�+%娝�遍荻w�簕.n�+壏{炳G珴�妠ay�蕠跈�,jf"穐殢飦�戧鐉_璁(殠娸"濟�m���G珴�⒏?櫒璀�&x忈秈O曟瑉窔v豝�m����鹅�⒏?朓�
Quoted 4 lines · Yunpeng
The Moorestown NAND flash driver is licensed from the Moorestown NAND controller vendor. It's a standalone NAND driver. According to the vendor, this driver has some advanced features specific to the controller hardware and is difficult to port to MTD subsystem.
I don't believe it. If the MTD subsystem doesn't support certain features, the MTD subsystem needs to be updated to cope.
When can I have test hardware?
Signature · 2 lines
David Woodhouse Open Source Technology Centre [email protected] Intel Corporation
Quoted 8 lines · David Woodhouse
Quoted 4 lines · Yunpeng
The Moorestown NAND flash driver is licensed from the Moorestown NAND controller vendor. It's a standalone NAND driver. According to the vendor, this driver has some advanced features specific to the controller hardware and is difficult to port to MTD subsystem.
I don't believe it. If the MTD subsystem doesn't support certain features, the MTD subsystem needs to be updated to cope.
Based on this response, I am guessing that you do not want me to take this in the staging tree? :)
If so, please let me know and I'll drop it.
thanks,
greg k-h
Quoted 10 lines · Greg KH
Quoted 8 lines · David Woodhouse
Quoted 4 lines · Yunpeng
The Moorestown NAND flash driver is licensed from the Moorestown NAND controller vendor. It's a standalone NAND driver. According to the vendor, this driver has some advanced features specific to the controller hardware and is difficult to port to MTD subsystem.
I don't believe it. If the MTD subsystem doesn't support certain features, the MTD subsystem needs to be updated to cope.
Quoted 8 lines
Based on this response, I am guessing that you do not want me to take this in the staging tree? :)
If so, please let me know and I'll drop it.
thanks,
greg k-h
Hi Greg,
Thanks for the reminder. But I need to discuss with David first to get more info from him and then decide to submit to MTD or not. Before that, please hold this patch in staging tree and don't drop it. Thank you.
Rgds,
Yunpeng
Quoted 18 lines
-----Original Message-----
From: Greg KH [mailto:[email protected]]
Sent: 2009年6月9日 8:39
To: David Woodhouse
Cc: Gao, Yunpeng; Alan Cox; [email protected]
Subject: Re: [PATCH 1/2]Intel Moorestown NAND driver patch for mainlineQuoted 8 lines · David Woodhouse
Quoted 4 lines · Yunpeng
The Moorestown NAND flash driver is licensed from the Moorestown NAND controller vendor. It's a standalone NAND driver. According to the vendor, this driver has some advanced features specific to the controller hardware and is difficult to port to MTD subsystem.
I don't believe it. If the MTD subsystem doesn't support certain features, the MTD subsystem needs to be updated to cope.
Quoted 8 lines
Based on this response, I am guessing that you do not want me to take this in the staging tree? :)
If so, please let me know and I'll drop it.
thanks,
greg k-h
Hi Greg, David and Alan,
I have discussed with the architect of Moorestown NAND driver today, and we agreed that the Moorestown NAND driver can not be ported to MTD subsystem.
The reason is:
The NAND driver has to keep compatibility with Moorestown IA Firmware (which also operates on NAND device and is close source), and if the NAND driver is ported to MTD, the driver has to be changed much and thus will fail to keep the compatibility with Firmware.
As this is a standalone NAND driver, I think I can re-submit it to the block subsystem (maintained by Jens Axboe). Thus the NAND driver need not to change its architecture and can keep the compatibility with Firmware.
Also, it'll be better if the NAND driver can be in Greg's staging tree before the driver becomes 'good enough' and accepted by the block subsystem. Because some customers and partners want to get the latest NAND driver code from the kernel tree before the driver is accepted finally.
Does this suggestion make sense?
Thanks for your time.
Rgds,
Yunpeng Gao
�翳簕.n�+壏煯壄�+%娝�遍荻w�簕.n�+壏{炳G珴�妠ay�蕠跈�,jf"穐殢飦�戧鐉_璁(殠娸"濟�m���G珴�⒏?櫒璀�&x忈秈O曟瑉窔v豝�m����鹅�⒏?朓�
Quoted 16 lines · Yunpeng
Hi Greg, David and Alan,
I have discussed with the architect of Moorestown NAND driver today, and we agreed that the Moorestown NAND driver can not be ported to MTD subsystem.
The reason is:
The NAND driver has to keep compatibility with Moorestown IA Firmware (which also operates on NAND device and is close source), and if the NAND driver is ported to MTD, the driver has to be changed much and thus will fail to keep the compatibility with Firmware.As this is a standalone NAND driver, I think I can re-submit it to the block subsystem (maintained by Jens Axboe). Thus the NAND driver need not to change its architecture and can keep the compatibility with Firmware.
Quoted 7 lines
Also, it'll be better if the NAND driver can be in Greg's staging tree before the driver becomes 'good enough' and accepted by the block subsystem. Because some customers and partners want to get the latest NAND driver code from the kernel tree before the driver is accepted finally.
Does this suggestion make sense?
None whatsoever.
There is absolutely no reason why integrating properly with the MTD subsystem would prevent you from retaining on-medium compatibility with the firmware. We manage it for DiskOnChip devices, for example.
Signature · 2 lines
David Woodhouse Open Source Technology Centre [email protected] Intel Corporation