/*------------------------------------------------------------------------------------------*\ * * Copyright (C) 2014 AVM GmbH * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA \*------------------------------------------------------------------------------------------*/ #ifndef _tffs_local_h_ #define _tffs_local_h_ #include #include #include #include /*-----------------------------------------------------------------------------------------------*\ \*-----------------------------------------------------------------------------------------------*/ /*--- #define TFFS_DEBUG ---*/ #if defined(TFFS_DEBUG) #define DBG(a) printk a #else /*--- #if defined(TFFS_DEBUG) ---*/ #define DBG(a) #endif /*--- #else ---*/ /*--- #if defined(TFFS_DEBUG) ---*/ /*-----------------------------------------------------------------------------------------------*\ \*-----------------------------------------------------------------------------------------------*/ #define MODULE_NAME "tffs3" #define MAX_ENV_ENTRY 256 #if defined(FLASH_ENV_ENTRY_SIZE) #undef FLASH_ENV_ENTRY_SIZE #endif /*--- #if defined(FLASH_ENV_ENTRY_SIZE) ---*/ #define FLASH_ENV_ENTRY_SIZE 256 /*------------------------------------------------------------------------------------------*\ \*------------------------------------------------------------------------------------------*/ enum _tffs3_thread_state { tffs3_thread_state_off, tffs3_thread_state_init, tffs3_thread_state_idle, tffs3_thread_state_process, tffs3_thread_state_down }; /*-----------------------------------------------------------------------------------------------*\ \*-----------------------------------------------------------------------------------------------*/ struct _tffs { int major; int minor; int count; dev_t device; struct cdev *cdev; struct cdev *cdev_ticfg; wait_queue_head_t event_wq; volatile unsigned long pending_events; volatile struct task_struct *kthread; enum _tffs3_thread_state thread_state; unsigned int request_count; }; extern struct _tffs tffs3; /*------------------------------------------------------------------------------------------*\ \*------------------------------------------------------------------------------------------*/ extern struct semaphore tffs3_sema; extern int tffs3_thread_event; extern enum _tffs3_thread_state tffs3_thread_state; extern unsigned int tffs3_request_count; extern int tffs_mtd[2]; extern unsigned int tffs3_spi_mode; #define PANIC_LOG_WRKSPC_SIZE 268000 extern char *panic_log_workspace; enum tffs3_handle_mode; /*------------------------------------------------------------------------------------------*\ \*------------------------------------------------------------------------------------------*/ struct _tffs_open { void *core_priv; unsigned int init_flag; unsigned int id; enum tffs3_handle_mode mode; unsigned char *z_Buffer; unsigned int z_length; z_stream stream; size_t max_segment_size; }; /*------------------------------------------------------------------------------------------*\ \*------------------------------------------------------------------------------------------*/ char *avm_urlader_env_get_value3(char *var); int avm_urlader_env_unset_variable3(char *var); int avm_urlader_env_set_variable3(char *var, char *val); int avm_urlader_env_defrag3(void); char *avm_urlader_env_get_value_by_id3(unsigned int id); char *avm_urlader_env_get_variable3(int idx); /*------------------------------------------------------------------------------------------*\ \*------------------------------------------------------------------------------------------*/ int tffs3_ioctl(struct inode *inode, struct file *filp, unsigned int ioctl_param, unsigned long argv); ssize_t tffs3_write_kern(struct _tffs_open *handle, const char *write_buffer, size_t write_length, loff_t *offp); ssize_t tffs3_write(struct file *filp, const char *write_buffer, size_t write_length, loff_t *offp); ssize_t tffs3_read_kern(struct _tffs_open *handle, char *read_buffer, size_t max_read_length, loff_t *offp); ssize_t tffs3_read(struct file *filp, char *read_buffer, size_t max_read_length, loff_t *offp); struct _tffs_open *tffs3_open_kern(unsigned int id, unsigned int wr_mode); struct _tffs_open *tffs3_open_panic(void); int tffs3_open(struct inode *inode, struct file *filp); int tffs3_flush(struct file *filp, fl_owner_t id); int tffs3_release_kern(struct _tffs_open *handle); int tffs3_release(struct inode *inode, struct file *filp); int tffs3_lock(void); void tffs3_unlock(void); /*------------------------------------------------------------------------------------------*\ \*------------------------------------------------------------------------------------------*/ #ifdef CONFIG_PROC_FS int tffs3_read_proc ( char *page, char **start, off_t off,int count, int *eof, void *data_unused); int tffs3_write_proc(struct file *file, const char *buffer, unsigned long count, void *data); /*--------------------------------------------------------------------------------*\ * collect statistic value * id: TFFS-ID * len: written/read len * mode: 0: read 1: write \*--------------------------------------------------------------------------------*/ void tffs3_write_statistic(unsigned int id, unsigned int len, unsigned int mode); #else #define tffs3_write_statistic(x, y, z) #endif /*--- #ifdef CONFIG_PROC_FS ---*/ /*------------------------------------------------------------------------------------------*\ \*------------------------------------------------------------------------------------------*/ #ifdef CONFIG_SYSCTL int avm_urlader_env_init3(void); #endif /* CONFIG_SYSCTL */ #include struct tffs_info { size_t size; union { struct mtd_info *mtd; struct file *file; } tffs; }; #define TFFS3_HDR_MAGIC 0x41564d5f54464653ULL // AVM_TFFS #define TFFS3_MAX_BADPAGES 0x4U #define TFFS3_VERSION TFFS_VERSION(3, 0) typedef struct __tffs_device tffs_device; struct __tffs_device { unsigned int initialised; unsigned int config_done; unsigned int setup_done; struct semaphore lock; unsigned int in_panic_mode; struct _tffs_open panic_handle; struct tffs3_nand_funcs nand_fn; struct tffs3_spinor_funcs mtdnor_fn; void *priv; int (*setup)(tffs_device *this); int (*read)(tffs_device *this, void *handle, enum _tffs_id Id, uint8_t *read_buffer, size_t *read_length); int (*write)(tffs_device *this, void *handle, enum _tffs_id Id, uint8_t *write_buffer, size_t write_length, size_t *retlen, unsigned int level); void *(*open)(tffs_device *this, struct _tffs_open *handle); int (*close)(tffs_device *this, void *handle); int (*cleanup)(tffs_device *this, void *handle); int (*reindex)(tffs_device *this); int (*info)(tffs_device *this, unsigned int *Fill); }; struct _tffs3_cfg_funcs { int (*legacy)(tffs_device *dev, int mtd_num0, int mtd_num1); int (*mtdnor)(tffs_device *dev, unsigned int mtd_number); int (*bdev)(tffs_device *dev, char *path); int (*mtdnand)(tffs_device *dev, unsigned int mtd_number, loff_t raw_offset); int (*cache)(tffs_device *dev); int (*remote)(tffs_device *dev); }; struct _TFFS_Block_Hdr_NAND { __be32 blkseq_nr; __be32 erase_cnt; __be32 sect_per_pg; __be32 num_bad_pages; __be64 bad_pages[TFFS3_MAX_BADPAGES]; } __attribute__((packed)); struct _TFFS_Block_Hdr { __be64 magic; __be32 version; __be32 type; union { struct _TFFS_Block_Hdr_NAND mtdnand; }; } __attribute__((packed)); #if defined(CONFIG_TFFS_DEV_MTDNOR) extern int TFFS3_NOR_Configure(tffs_device *tffs_dev, unsigned int mtd_num); #endif #if defined(CONFIG_TFFS_DEV_MTDNAND) extern int TFFS3_NAND_Configure(tffs_device *tffs_dev, unsigned int mtd_num, loff_t raw_offset); #endif #if defined(CONFIG_TFFS_DEV_BDEV) extern int TFFS3_BDEV_Configure(tffs_device *tffs_dev, char *path); #endif #if defined(CONFIG_TFFS_DEV_CACHE) extern int TFFS3_CACHE_Configure(tffs_device *tffs_dev); #endif #if defined(CONFIG_TFFS_DEV_REMOTE) extern int TFFS3_REMOTE_Configure(tffs_device *tffs_dev); #endif #if defined(CONFIG_TFFS_DEV_LEGACY) extern int TFFS3_LGCY_Configure(tffs_device *tffs_dev, int mtd_num1, int mtd_num2); #endif extern struct _tffs3_cfg_funcs tffs3_cfg_funcs; #if defined(CONFIG_TFFS) int tffs2_active(void); #else static inline int tffs2_active(void) { return 0; } #endif #endif /*--- #ifndef _tffs_local_h_ ---*/