diff options
author | Stephen Rothwell <sfr@canb.auug.org.au> | 2018-09-11 13:02:51 +1000 |
---|---|---|
committer | Stephen Rothwell <sfr@canb.auug.org.au> | 2018-09-11 13:02:51 +1000 |
commit | 9988aa8a343f2d59ebf4efcb3ef4f1881572321f (patch) | |
tree | 031bee4e82e592bbeac912982d5cbbe0acdc51b7 | |
parent | fa22419848a4cdf5dd6cbb10a563cf34b9e08d9d (diff) | |
parent | 7aaaabd50d785e30b290054b3a1b115393927da3 (diff) |
Merge remote-tracking branch 'staging/staging-next'
92 files changed, 1869 insertions, 3622 deletions
diff --git a/drivers/staging/android/ion/ion.h b/drivers/staging/android/ion/ion.h index 16cbd38a7160..c006fc1e5a16 100644 --- a/drivers/staging/android/ion/ion.h +++ b/drivers/staging/android/ion/ion.h @@ -157,8 +157,6 @@ struct ion_heap_ops { * @lock: protects the free list * @waitqueue: queue to wait on from deferred free thread * @task: task struct of deferred free thread - * @debug_show: called when heap debug file is read to add any - * heap specific debug info to output * * Represents a pool of memory from which buffers can be made. In some * systems the only heap is regular system memory allocated via vmalloc. @@ -179,9 +177,6 @@ struct ion_heap { spinlock_t free_lock; wait_queue_head_t waitqueue; struct task_struct *task; - - int (*debug_show)(struct ion_heap *heap, struct seq_file *s, - void *unused); }; /** diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c index 701eb9f3b0f1..548bb02c0ca6 100644 --- a/drivers/staging/android/ion/ion_system_heap.c +++ b/drivers/staging/android/ion/ion_system_heap.c @@ -212,29 +212,6 @@ static struct ion_heap_ops system_heap_ops = { .shrink = ion_system_heap_shrink, }; -static int ion_system_heap_debug_show(struct ion_heap *heap, struct seq_file *s, - void *unused) -{ - struct ion_system_heap *sys_heap = container_of(heap, - struct ion_system_heap, - heap); - int i; - struct ion_page_pool *pool; - - for (i = 0; i < NUM_ORDERS; i++) { - pool = sys_heap->pools[i]; - - seq_printf(s, "%d order %u highmem pages %lu total\n", - pool->high_count, pool->order, - (PAGE_SIZE << pool->order) * pool->high_count); - seq_printf(s, "%d order %u lowmem pages %lu total\n", - pool->low_count, pool->order, - (PAGE_SIZE << pool->order) * pool->low_count); - } - - return 0; -} - static void ion_system_heap_destroy_pools(struct ion_page_pool **pools) { int i; @@ -281,7 +258,6 @@ static struct ion_heap *__ion_system_heap_create(void) if (ion_system_heap_create_pools(heap->pools)) goto free_heap; - heap->heap.debug_show = ion_system_heap_debug_show; return &heap->heap; free_heap: diff --git a/drivers/staging/erofs/Kconfig b/drivers/staging/erofs/Kconfig index 663b755bf2fb..c8521d71039b 100644 --- a/drivers/staging/erofs/Kconfig +++ b/drivers/staging/erofs/Kconfig @@ -78,6 +78,15 @@ config EROFS_FAULT_INJECTION Test EROFS to inject faults such as ENOMEM, EIO, and so on. If unsure, say N. +config EROFS_FS_IO_MAX_RETRIES + int "EROFS IO Maximum Retries" + depends on EROFS_FS + default "5" + help + Maximum retry count of IO Errors. + + If unsure, leave the default value (5 retries, 6 IOs at most). + config EROFS_FS_ZIP bool "EROFS Data Compresssion Support" depends on EROFS_FS diff --git a/drivers/staging/erofs/data.c b/drivers/staging/erofs/data.c index ac263a180253..3c0d9159514e 100644 --- a/drivers/staging/erofs/data.c +++ b/drivers/staging/erofs/data.c @@ -39,38 +39,50 @@ static inline void read_endio(struct bio *bio) } /* prio -- true is used for dir */ -struct page *erofs_get_meta_page(struct super_block *sb, - erofs_blk_t blkaddr, bool prio) +struct page *__erofs_get_meta_page(struct super_block *sb, + erofs_blk_t blkaddr, bool prio, bool nofail) { - struct inode *bd_inode = sb->s_bdev->bd_inode; - struct address_space *mapping = bd_inode->i_mapping; + struct inode *const bd_inode = sb->s_bdev->bd_inode; + struct address_space *const mapping = bd_inode->i_mapping; + /* prefer retrying in the allocator to blindly looping below */ + const gfp_t gfp = mapping_gfp_constraint(mapping, ~__GFP_FS) | + (nofail ? __GFP_NOFAIL : 0); + unsigned int io_retries = nofail ? EROFS_IO_MAX_RETRIES_NOFAIL : 0; struct page *page; + int err; repeat: - page = find_or_create_page(mapping, blkaddr, - /* - * Prefer looping in the allocator rather than here, - * at least that code knows what it's doing. - */ - mapping_gfp_constraint(mapping, ~__GFP_FS) | __GFP_NOFAIL); - - BUG_ON(!page || !PageLocked(page)); + page = find_or_create_page(mapping, blkaddr, gfp); + if (unlikely(page == NULL)) { + DBG_BUGON(nofail); + return ERR_PTR(-ENOMEM); + } + DBG_BUGON(!PageLocked(page)); if (!PageUptodate(page)) { struct bio *bio; - int err; - bio = prepare_bio(sb, blkaddr, 1, read_endio); + bio = erofs_grab_bio(sb, blkaddr, 1, read_endio, nofail); + if (IS_ERR(bio)) { + DBG_BUGON(nofail); + err = PTR_ERR(bio); + goto err_out; + } + err = bio_add_page(bio, page, PAGE_SIZE, 0); - BUG_ON(err != PAGE_SIZE); + if (unlikely(err != PAGE_SIZE)) { + err = -EFAULT; + goto err_out; + } __submit_bio(bio, REQ_OP_READ, REQ_META | (prio ? REQ_PRIO : 0)); lock_page(page); - /* the page has been truncated by others? */ + /* this page has been truncated by others */ if (unlikely(page->mapping != mapping)) { +unlock_repeat: unlock_page(page); put_page(page); goto repeat; @@ -78,13 +90,20 @@ repeat: /* more likely a read error */ if (unlikely(!PageUptodate(page))) { - unlock_page(page); - put_page(page); - - page = ERR_PTR(-EIO); + if (io_retries) { + --io_retries; + goto unlock_repeat; + } + err = -EIO; + goto err_out; } } return page; + +err_out: + unlock_page(page); + put_page(page); + return ERR_PTR(err); } static int erofs_map_blocks_flatmode(struct inode *inode, @@ -278,7 +297,14 @@ submit_bio_retry: if (nblocks > BIO_MAX_PAGES) nblocks = BIO_MAX_PAGES; - bio = prepare_bio(inode->i_sb, blknr, nblocks, read_endio); + bio = erofs_grab_bio(inode->i_sb, + blknr, nblocks, read_endio, false); + + if (IS_ERR(bio)) { + err = PTR_ERR(bio); + bio = NULL; + goto err_out; + } } err = bio_add_page(bio, page, PAGE_SIZE, 0); @@ -337,7 +363,7 @@ static int erofs_raw_access_readpage(struct file *file, struct page *page) static int erofs_raw_access_readpages(struct file *filp, struct address_space *mapping, - struct list_head *pages, unsigned nr_pages) + struct list_head *pages, unsigned int nr_pages) { erofs_off_t last_block; struct bio *bio = NULL; diff --git a/drivers/staging/erofs/erofs_fs.h b/drivers/staging/erofs/erofs_fs.h index 2f8e2bf70941..d4bffa2852b3 100644 --- a/drivers/staging/erofs/erofs_fs.h +++ b/drivers/staging/erofs/erofs_fs.h @@ -202,6 +202,14 @@ struct erofs_extent_header { * di_u.delta[1] = distance to its corresponding tail cluster * (di_advise could be 0, 1 or 2) */ +enum { + Z_EROFS_VLE_CLUSTER_TYPE_PLAIN, + Z_EROFS_VLE_CLUSTER_TYPE_HEAD, + Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD, + Z_EROFS_VLE_CLUSTER_TYPE_RESERVED, + Z_EROFS_VLE_CLUSTER_TYPE_MAX +}; + #define Z_EROFS_VLE_DI_CLUSTER_TYPE_BITS 2 #define Z_EROFS_VLE_DI_CLUSTER_TYPE_BIT 0 @@ -260,6 +268,9 @@ static inline void erofs_check_ondisk_layout_definitions(void) BUILD_BUG_ON(sizeof(struct erofs_extent_header) != 16); BUILD_BUG_ON(sizeof(struct z_erofs_vle_decompressed_index) != 8); BUILD_BUG_ON(sizeof(struct erofs_dirent) != 12); + + BUILD_BUG_ON(BIT(Z_EROFS_VLE_DI_CLUSTER_TYPE_BITS) < + Z_EROFS_VLE_CLUSTER_TYPE_MAX - 1); } #endif diff --git a/drivers/staging/erofs/internal.h b/drivers/staging/erofs/internal.h index 367b39fe46e5..f20c6e9b7471 100644 --- a/drivers/staging/erofs/internal.h +++ b/drivers/staging/erofs/internal.h @@ -420,30 +420,30 @@ struct erofs_map_blocks { #define EROFS_GET_BLOCKS_RAW 0x0001 /* data.c */ -static inline struct bio *prepare_bio( - struct super_block *sb, - erofs_blk_t blkaddr, unsigned nr_pages, - bio_end_io_t endio) +static inline struct bio * +erofs_grab_bio(struct super_block *sb, + erofs_blk_t blkaddr, unsigned int nr_pages, + bio_end_io_t endio, bool nofail) { - gfp_t gfp = GFP_NOIO; - struct bio *bio = bio_alloc(gfp, nr_pages); - - if (unlikely(bio == NULL) && - (current->flags & PF_MEMALLOC)) { - do { - nr_pages /= 2; - if (unlikely(!nr_pages)) { - bio = bio_alloc(gfp | __GFP_NOFAIL, 1); - BUG_ON(bio == NULL); - break; + const gfp_t gfp = GFP_NOIO; + struct bio *bio; + + do { + if (nr_pages == 1) { + bio = bio_alloc(gfp | (nofail ? __GFP_NOFAIL : 0), 1); + if (unlikely(bio == NULL)) { + DBG_BUGON(nofail); + return ERR_PTR(-ENOMEM); } - bio = bio_alloc(gfp, nr_pages); - } while (bio == NULL); - } + break; + } + bio = bio_alloc(gfp, nr_pages); + nr_pages /= 2; + } while (unlikely(bio == NULL)); bio->bi_end_io = endio; bio_set_dev(bio, sb->s_bdev); - bio->bi_iter.bi_sector = blkaddr << LOG_SECTORS_PER_BLOCK; + bio->bi_iter.bi_sector = (sector_t)blkaddr << LOG_SECTORS_PER_BLOCK; return bio; } @@ -453,8 +453,27 @@ static inline void __submit_bio(struct bio *bio, unsigned op, unsigned op_flags) submit_bio(bio); } -extern struct page *erofs_get_meta_page(struct super_block *sb, - erofs_blk_t blkaddr, bool prio); +#ifndef CONFIG_EROFS_FS_IO_MAX_RETRIES +#define EROFS_IO_MAX_RETRIES_NOFAIL 0 +#else +#define EROFS_IO_MAX_RETRIES_NOFAIL CONFIG_EROFS_FS_IO_MAX_RETRIES +#endif + +extern struct page *__erofs_get_meta_page(struct super_block *sb, + erofs_blk_t blkaddr, bool prio, bool nofail); + +static inline struct page *erofs_get_meta_page(struct super_block *sb, + erofs_blk_t blkaddr, bool prio) +{ + return __erofs_get_meta_page(sb, blkaddr, prio, false); +} + +static inline struct page *erofs_get_meta_page_nofail(struct super_block *sb, + erofs_blk_t blkaddr, bool prio) +{ + return __erofs_get_meta_page(sb, blkaddr, prio, true); +} + extern int erofs_map_blocks(struct inode *, struct erofs_map_blocks *, int); extern int erofs_map_blocks_iter(struct inode *, struct erofs_map_blocks *, struct page **, int); @@ -465,8 +484,9 @@ struct erofs_map_blocks_iter { }; -static inline struct page *erofs_get_inline_page(struct inode *inode, - erofs_blk_t blkaddr) +static inline struct page * +erofs_get_inline_page(struct inode *inode, + erofs_blk_t blkaddr) { return erofs_get_meta_page(inode->i_sb, blkaddr, S_ISDIR(inode->i_mode)); diff --git a/drivers/staging/erofs/unzip_vle.c b/drivers/staging/erofs/unzip_vle.c index 8721f0a41d15..22f9a02a75f9 100644 --- a/drivers/staging/erofs/unzip_vle.c +++ b/drivers/staging/erofs/unzip_vle.c @@ -271,36 +271,42 @@ retry: return true; /* lucky, I am the followee :) */ } +struct z_erofs_vle_work_finder { + struct super_block *sb; + pgoff_t idx; + unsigned pageofs; + + struct z_erofs_vle_workgroup **grp_ret; + enum z_erofs_vle_work_role *role; + z_erofs_vle_owned_workgrp_t *owned_head; + bool *hosted; +}; + static struct z_erofs_vle_work * -z_erofs_vle_work_lookup(struct super_block *sb, - pgoff_t idx, unsigned pageofs, - struct z_erofs_vle_workgroup **grp_ret, - enum z_erofs_vle_work_role *role, - z_erofs_vle_owned_workgrp_t *owned_head, - bool *hosted) +z_erofs_vle_work_lookup(const struct z_erofs_vle_work_finder *f) { bool tag, primary; struct erofs_workgroup *egrp; struct z_erofs_vle_workgroup *grp; struct z_erofs_vle_work *work; - egrp = erofs_find_workgroup(sb, idx, &tag); + egrp = erofs_find_workgroup(f->sb, f->idx, &tag); if (egrp == NULL) { - *grp_ret = NULL; + *f->grp_ret = NULL; return NULL; } - *grp_ret = grp = container_of(egrp, - struct z_erofs_vle_workgroup, obj); + grp = container_of(egrp, struct z_erofs_vle_workgroup, obj); + *f->grp_ret = grp; #ifndef CONFIG_EROFS_FS_ZIP_MULTIREF - work = z_erofs_vle_grab_work(grp, pageofs); + work = z_erofs_vle_grab_work(grp, f->pageofs); primary = true; #else BUG(); #endif - DBG_BUGON(work->pageofs != pageofs); + DBG_BUGON(work->pageofs != f->pageofs); /* * lock must be taken first to avoid grp->next == NIL between @@ -340,29 +346,24 @@ z_erofs_vle_work_lookup(struct super_block *sb, */ mutex_lock(&work->lock); - *hosted = false; + *f->hosted = false; if (!primary) - *role = Z_EROFS_VLE_WORK_SECONDARY; + *f->role = Z_EROFS_VLE_WORK_SECONDARY; /* claim the workgroup if possible */ - else if (try_to_claim_workgroup(grp, owned_head, hosted)) - *role = Z_EROFS_VLE_WORK_PRIMARY_FOLLOWED; + else if (try_to_claim_workgroup(grp, f->owned_head, f->hosted)) + *f->role = Z_EROFS_VLE_WORK_PRIMARY_FOLLOWED; else - *role = Z_EROFS_VLE_WORK_PRIMARY; + *f->role = Z_EROFS_VLE_WORK_PRIMARY; return work; } static struct z_erofs_vle_work * -z_erofs_vle_work_register(struct super_block *sb, - struct z_erofs_vle_workgroup **grp_ret, - struct erofs_map_blocks *map, - pgoff_t index, unsigned pageofs, - enum z_erofs_vle_work_role *role, - z_erofs_vle_owned_workgrp_t *owned_head, - bool *hosted) +z_erofs_vle_work_register(const struct z_erofs_vle_work_finder *f, + struct erofs_map_blocks *map) { - bool newgrp = false; - struct z_erofs_vle_workgroup *grp = *grp_ret; + bool gnew = false; + struct z_erofs_vle_workgroup *grp = *f->grp_ret; struct z_erofs_vle_work *work; #ifndef CONFIG_EROFS_FS_ZIP_MULTIREF @@ -376,7 +377,7 @@ z_erofs_vle_work_register(struct super_block *sb, if (unlikely(grp == NULL)) return ERR_PTR(-ENOMEM); - grp->obj.index = index; + grp->obj.index = f->idx; grp->llen = map->m_llen; z_erofs_vle_set_workgrp_fmt(grp, @@ -386,13 +387,13 @@ z_erofs_vle_work_register(struct super_block *sb, atomic_set(&grp->obj.refcount, 1); /* new workgrps have been claimed as type 1 */ - WRITE_ONCE(grp->next, *owned_head); + WRITE_ONCE(grp->next, *f->owned_head); /* primary and followed work for all new workgrps */ - *role = Z_EROFS_VLE_WORK_PRIMARY_FOLLOWED; + *f->role = Z_EROFS_VLE_WORK_PRIMARY_FOLLOWED; /* it should be submitted by ourselves */ - *hosted = true; + *f->hosted = true; - newgrp = true; + gnew = true; #ifdef CONFIG_EROFS_FS_ZIP_MULTIREF skip: /* currently unimplemented */ @@ -400,12 +401,12 @@ skip: #else work = z_erofs_vle_grab_primary_work(grp); #endif - work->pageofs = pageofs; + work->pageofs = f->pageofs; mutex_init(&work->lock); - if (newgrp) { - int err = erofs_register_workgroup(sb, &grp->obj, 0); + if (gnew) { + int err = erofs_register_workgroup(f->sb, &grp->obj, 0); if (err) { kmem_cache_free(z_erofs_workgroup_cachep, grp); @@ -413,7 +414,7 @@ skip: } } - *owned_head = *grp_ret = grp; + *f->owned_head = *f->grp_ret = grp; mutex_lock(&work->lock); return work; @@ -440,9 +441,16 @@ static int z_erofs_vle_work_iter_begin(struct z_erofs_vle_work_builder *builder, z_erofs_vle_owned_workgrp_t *owned_head) { const unsigned clusterpages = erofs_clusterpages(EROFS_SB(sb)); - const erofs_blk_t index = erofs_blknr(map->m_pa); - const unsigned pageofs = map->m_la & ~PAGE_MASK; struct z_erofs_vle_workgroup *grp; + const struct z_erofs_vle_work_finder finder = { + .sb = sb, + .idx = erofs_blknr(map->m_pa), + .pageofs = map->m_la & ~PAGE_MASK, + .grp_ret = &grp, + .role = &builder->role, + .owned_head = owned_head, + .hosted = &builder->hosted + }; struct z_erofs_vle_work *work; DBG_BUGON(builder->work != NULL); @@ -454,16 +462,13 @@ static int z_erofs_vle_work_iter_begin(struct z_erofs_vle_work_builder *builder, DBG_BUGON(erofs_blkoff(map->m_pa)); repeat: - work = z_erofs_vle_work_lookup(sb, index, - pageofs, &grp, &builder->role, owned_head, &builder->hosted); + work = z_erofs_vle_work_lookup(&finder); if (work != NULL) { __update_workgrp_llen(grp, map->m_llen); goto got_it; } - work = z_erofs_vle_work_register(sb, &grp, map, index, pageofs, - &builder->role, owned_head, &builder->hosted); - + work = z_erofs_vle_work_register(&finder, map); if (unlikely(work == ERR_PTR(-EAGAIN))) goto repeat; @@ -1213,8 +1218,8 @@ submit_bio_retry: } if (bio == NULL) { - bio = prepare_bio(sb, first_index + i, - BIO_MAX_PAGES, z_erofs_vle_read_endio); + bio = erofs_grab_bio(sb, first_index + i, + BIO_MAX_PAGES, z_erofs_vle_read_endio, true); bio->bi_private = tagptr_cast_ptr(bi_private); ++nr_bios; @@ -1309,7 +1314,7 @@ static int z_erofs_vle_normalaccess_readpage(struct file *file, LIST_HEAD(pagepool); #if (EROFS_FS_ZIP_CACHE_LVL >= 2) - f.cachedzone_la = page->index << PAGE_SHIFT; + f.cachedzone_la = (erofs_off_t)page->index << PAGE_SHIFT; #endif err = z_erofs_do_read_page(&f, page, &pagepool); (void)z_erofs_vle_work_iter_end(&f.builder); @@ -1342,7 +1347,7 @@ static inline int __z_erofs_vle_normalaccess_readpages( LIST_HEAD(pagepool); #if (EROFS_FS_ZIP_CACHE_LVL >= 2) - f.cachedzone_la = lru_to_page(pages)->index << PAGE_SHIFT; + f.cachedzone_la = (erofs_off_t)lru_to_page(pages)->index << PAGE_SHIFT; #endif for (; nr_pages; --nr_pages) { struct page *page = lru_to_page(pages); @@ -1411,35 +1416,27 @@ const struct address_space_operations z_erofs_vle_normalaccess_aops = { #define __vle_cluster_type(advise) __vle_cluster_advise(advise, \ Z_EROFS_VLE_DI_CLUSTER_TYPE_BIT, Z_EROFS_VLE_DI_CLUSTER_TYPE_BITS) -enum { - Z_EROFS_VLE_CLUSTER_TYPE_PLAIN, - Z_EROFS_VLE_CLUSTER_TYPE_HEAD, - Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD, - Z_EROFS_VLE_CLUSTER_TYPE_RESERVED, - Z_EROFS_VLE_CLUSTER_TYPE_MAX -}; - #define vle_cluster_type(di) \ __vle_cluster_type((di)->di_advise) -static inline unsigned -vle_compressed_index_clusterofs(unsigned clustersize, - struct z_erofs_vle_decompressed_index *di) +static int +vle_decompressed_index_clusterofs(unsigned int *clusterofs, + unsigned int clustersize, + struct z_erofs_vle_decompressed_index *di) { - debugln("%s, vle=%pK, advise=%x (type %u), clusterofs=%x blkaddr=%x", - __func__, di, di->di_advise, vle_cluster_type(di), - di->di_clusterofs, di->di_u.blkaddr); - switch (vle_cluster_type(di)) { case Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD: + *clusterofs = clustersize; break; case Z_EROFS_VLE_CLUSTER_TYPE_PLAIN: case Z_EROFS_VLE_CLUSTER_TYPE_HEAD: - return di->di_clusterofs; + *clusterofs = le16_to_cpu(di->di_clusterofs); + break; default: - BUG_ON(1); + DBG_BUGON(1); + return -EIO; } - return clustersize; + return 0; } static inline erofs_blk_t @@ -1488,7 +1485,8 @@ static erofs_off_t vle_get_logical_extent_head( erofs_blk_t blkaddr = vle_extent_blkaddr(inode, lcn); struct z_erofs_vle_decompressed_index *di; unsigned long long ofs; - const unsigned int clusterbits = EROFS_SB(inode->i_sb)->clusterbits; + struct super_block *const sb = inode->i_sb; + const unsigned int clusterbits = EROFS_SB(sb)->clusterbits; const unsigned int clustersize = 1 << clusterbits; if (page->index != blkaddr) { @@ -1496,8 +1494,8 @@ static erofs_off_t vle_get_logical_extent_head( unlock_page(page); put_page(page); - *page_iter = page = erofs_get_meta_page(inode->i_sb, - blkaddr, false); + page = erofs_get_meta_page_nofail(sb, blkaddr, false); + *page_iter = page; *kaddr_iter = kmap_atomic(page); } @@ -1515,7 +1513,7 @@ static erofs_off_t vle_get_logical_extent_head( *flags ^= EROFS_MAP_ZIPPED; case Z_EROFS_VLE_CLUSTER_TYPE_HEAD: /* clustersize should be a power of two */ - ofs = ((unsigned long long)lcn << clusterbits) + + ofs = ((u64)lcn << clusterbits) + (le16_to_cpu(di->di_clusterofs) & (clustersize - 1)); *pcn = le32_to_cpu(di->di_u.blkaddr); break; @@ -1538,7 +1536,8 @@ int z_erofs_map_blocks_iter(struct inode *inode, struct page *mpage = *mpage_ret; void *kaddr; bool initial; - const unsigned int clusterbits = EROFS_SB(inode->i_sb)->clusterbits; + struct super_block *const sb = inode->i_sb; + const unsigned int clusterbits = EROFS_SB(sb)->clusterbits; const unsigned int clustersize = 1 << clusterbits; int err = 0; @@ -1549,7 +1548,7 @@ int z_erofs_map_blocks_iter(struct inode *inode, if (unlikely(map->m_la >= inode->i_size)) { BUG_ON(!initial); map->m_llen = map->m_la + 1 - inode->i_size; - map->m_la = inode->i_size - 1; + map->m_la = inode->i_size; map->m_flags = 0; goto out; } @@ -1569,7 +1568,7 @@ int z_erofs_map_blocks_iter(struct inode *inode, if (mpage != NULL) put_page(mpage); - mpage = erofs_get_meta_page(inode->i_sb, e_blkaddr, false); + mpage = erofs_get_meta_page_nofail(sb, e_blkaddr, false); *mpage_ret = mpage; } else { lock_page(mpage); @@ -1582,7 +1581,11 @@ int z_erofs_map_blocks_iter(struct inode *inode, debugln("%s, lcn %u e_blkaddr %u e_blkoff %u", __func__, lcn, e_blkaddr, vle_extent_blkoff(inode, lcn)); - logical_cluster_ofs = vle_compressed_index_clusterofs(clustersize, di); + err = vle_decompressed_index_clusterofs(&logical_cluster_ofs, + clustersize, di); + if (unlikely(err)) + goto unmap_out; + if (!initial) { /* [walking mode] 'map' has been already initialized */ map->m_llen += logical_cluster_ofs; @@ -1592,7 +1595,7 @@ int z_erofs_map_blocks_iter(struct inode *inode, /* by default, compressed */ map->m_flags |= EROFS_MAP_ZIPPED; - end = (u64)(lcn + 1) * clustersize; + end = ((u64)lcn + 1) * clustersize; cluster_type = vle_cluster_type(di); @@ -1608,7 +1611,7 @@ int z_erofs_map_blocks_iter(struct inode *inode, } if (ofs_rem > logical_cluster_ofs) { - ofs = lcn * clustersize | logical_cluster_ofs; + ofs = (u64)lcn * clustersize | logical_cluster_ofs; pcn = le32_to_cpu(di->di_u.blkaddr); break; } @@ -1620,7 +1623,7 @@ int z_erofs_map_blocks_iter(struct inode *inode, err = -EIO; goto unmap_out; } - end = (lcn-- * clustersize) | logical_cluster_ofs; + end = ((u64)lcn-- * clustersize) | logical_cluster_ofs; /* fallthrough */ case Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD: /* get the correspoinding first chunk */ diff --git a/drivers/staging/erofs/unzip_vle_lz4.c b/drivers/staging/erofs/unzip_vle_lz4.c index f5b665f15be5..1a428658cbea 100644 --- a/drivers/staging/erofs/unzip_vle_lz4.c +++ b/drivers/staging/erofs/unzip_vle_lz4.c @@ -23,14 +23,14 @@ static struct { } erofs_pcpubuf[NR_CPUS]; int z_erofs_vle_plain_copy(struct page **compressed_pages, - unsigned clusterpages, + unsigned int clusterpages, struct page **pages, - unsigned nr_pages, + unsigned int nr_pages, unsigned short pageofs) { - unsigned i, j; + unsigned int i, j; void *src = NULL; - const unsigned righthalf = PAGE_SIZE - pageofs; + const unsigned int righthalf = PAGE_SIZE - pageofs; char *percpu_data; bool mirrored[Z_EROFS_CLUSTER_MAX_PAGES] = { 0 }; @@ -42,8 +42,8 @@ int z_erofs_vle_plain_copy(struct page **compressed_pages, struct page *page = pages[i]; void *dst; - if (page == NULL) { - if (src != NULL) { + if (!page) { + if (src) { if (!mirrored[j]) kunmap_atomic(src); src = NULL; @@ -64,14 +64,14 @@ int z_erofs_vle_plain_copy(struct page **compressed_pages, } if (i) { - if (src == NULL) - src = mirrored[i-1] ? - percpu_data + (i-1) * PAGE_SIZE : - kmap_atomic(compressed_pages[i-1]); + if (!src) + src = mirrored[i - 1] ? + percpu_data + (i - 1) * PAGE_SIZE : + kmap_atomic(compressed_pages[i - 1]); memcpy(dst, src + righthalf, pageofs); - if (!mirrored[i-1]) + if (!mirrored[i - 1]) kunmap_atomic(src); if (unlikely(i >= clusterpages)) { @@ -80,9 +80,9 @@ int z_erofs_vle_plain_copy(struct page **compressed_pages, } } - if (!righthalf) + if (!righthalf) { src = NULL; - else { + } else { src = mirrored[i] ? percpu_data + i * PAGE_SIZE : kmap_atomic(compressed_pages[i]); @@ -92,7 +92,7 @@ int z_erofs_vle_plain_copy(struct page **compressed_pages, kunmap_atomic(dst); } - if (src != NULL && !mirrored[j]) + if (src && !mirrored[j]) kunmap_atomic(src); preempt_enable(); @@ -102,14 +102,14 @@ int z_erofs_vle_plain_copy(struct page **compressed_pages, extern int z_erofs_unzip_lz4(void *in, void *out, size_t inlen, size_t outlen); int z_erofs_vle_unzip_fast_percpu(struct page **compressed_pages, - unsigned clusterpages, + unsigned int clusterpages, struct page **pages, - unsigned outlen, + unsigned int outlen, unsigned short pageofs, void (*endio)(struct page *)) { void *vin, *vout; - unsigned nr_pages, i, j; + unsigned int nr_pages, i, j; int ret; if (outlen + pageofs > EROFS_PERCPU_NR_PAGES * PAGE_SIZE) @@ -126,7 +126,7 @@ int z_erofs_vle_unzip_fast_percpu(struct page **compressed_pages, vout = erofs_pcpubuf[smp_processor_id()].data; ret = z_erofs_unzip_lz4(vin, vout + pageofs, - clusterpages * PAGE_SIZE, outlen); + clusterpages * PAGE_SIZE, outlen); if (ret >= 0) { outlen = ret; @@ -134,14 +134,15 @@ int z_erofs_vle_unzip_fast_percpu(struct page **compressed_pages, } for (i = 0; i < nr_pages; ++i) { - j = min((unsigned)PAGE_SIZE - pageofs, outlen); + j = min((unsigned int)PAGE_SIZE - pageofs, outlen); - if (pages[i] != NULL) { - if (ret < 0) + if (pages[i]) { + if (ret < 0) { SetPageError(pages[i]); - else if (clusterpages == 1 && pages[i] == compressed_pages[0]) + } else if (clusterpages == 1 && + pages[i] == compressed_pages[0]) { memcpy(vin + pageofs, vout + pageofs, j); - else { + } else { void *dst = kmap_atomic(pages[i]); memcpy(dst + pageofs, vout + pageofs, j); @@ -164,14 +165,14 @@ int z_erofs_vle_unzip_fast_percpu(struct page **compressed_pages, } int z_erofs_vle_unzip_vmap(struct page **compressed_pages, - unsigned clusterpages, + unsigned int clusterpages, void *vout, - unsigned llen, + unsigned int llen, unsigned short pageofs, bool overlapped) { void *vin; - unsigned i; + unsigned int i; int ret; if (overlapped) { @@ -181,29 +182,27 @@ int z_erofs_vle_unzip_vmap(struct page **compressed_pages, for (i = 0; i < clusterpages; ++i) { void *t = kmap_atomic(compressed_pages[i]); - memcpy(vin + PAGE_SIZE *i, t, PAGE_SIZE); + memcpy(vin + PAGE_SIZE * i, t, PAGE_SIZE); kunmap_atomic(t); } - } else if (clusterpages == 1) + } else if (clusterpages == 1) { vin = kmap_atomic(compressed_pages[0]); - else { + } else { vin = erofs_vmap(compressed_pages, clusterpages); } ret = z_erofs_unzip_lz4(vin, vout + pageofs, - clusterpages * PAGE_SIZE, llen); + clusterpages * PAGE_SIZE, llen); if (ret > 0) ret = 0; if (!overlapped) { if (clusterpages == 1) kunmap_atomic(vin); - else { + else erofs_vunmap(vin, clusterpages); - } - } else + } else { preempt_enable(); - + } return ret; } - diff --git a/drivers/staging/erofs/xattr.c b/drivers/staging/erofs/xattr.c index 0e9cfeccdf99..79d7fc8b7cc5 100644 --- a/drivers/staging/erofs/xattr.c +++ b/drivers/staging/erofs/xattr.c @@ -24,36 +24,48 @@ struct xattr_iter { static inline void xattr_iter_end(struct xattr_iter *it, bool atomic) { - /* only init_inode_xattrs use non-atomic once */ + /* the only user of kunmap() is 'init_inode_xattrs' */ if (unlikely(!atomic)) kunmap(it->page); else kunmap_atomic(it->kaddr); + unlock_page(it->page); put_page(it->page); } -static void init_inode_xattrs(struct inode *inode) +static inline void xattr_iter_end_final(struct xattr_iter *it) +{ + if (it->page == NULL) + return; + + xattr_iter_end(it, true); +} + +static int init_inode_xattrs(struct inode *inode) { struct xattr_iter it; unsigned i; struct erofs_xattr_ibody_header *ih; + struct super_block *sb; struct erofs_sb_info *sbi; struct erofs_vnode *vi; bool atomic_map; if (likely(inode_has_inited_xattr(inode))) - return; + return 0; vi = EROFS_V(inode); BUG_ON(!vi->xattr_isize); - sbi = EROFS_I_SB(inode); + sb = inode->i_sb; + sbi = EROFS_SB(sb); it.blkaddr = erofs_blknr(iloc(sbi, vi->nid) + vi->inode_isize); it.ofs = erofs_blkoff(iloc(sbi, vi->nid) + vi->inode_isize); it.page = erofs_get_inline_page(inode, it.blkaddr); - BUG_ON(IS_ERR(it.page)); + if (IS_ERR(it.page)) + return PTR_ERR(it.page); /* read in shared xattr array (non-atomic, see kmalloc below) */ it.kaddr = kmap(it.page); @@ -62,9 +74,12 @@ static void init_inode_xattrs(struct inode *inode) ih = (struct erofs_xattr_ibody_header *)(it.kaddr + it.ofs); vi->xattr_shared_count = ih->h_shared_count; - vi->xattr_shared_xattrs = (unsigned *)kmalloc_array( - vi->xattr_shared_count, sizeof(unsigned), - GFP_KERNEL | __GFP_NOFAIL); + vi->xattr_shared_xattrs = kmalloc_array(vi->xattr_shared_count, + sizeof(uint), GFP_KERNEL); + if (vi->xattr_shared_xattrs == NULL) { + xattr_iter_end(&it, atomic_map); + return -ENOMEM; + } /* let's skip ibody header */ it.ofs += sizeof(struct erofs_xattr_ibody_header); @@ -75,9 +90,10 @@ static void init_inode_xattrs(struct inode *inode) BUG_ON(it.ofs != EROFS_BLKSIZ); xattr_iter_end(&it, atomic_map); - it.page = erofs_get_meta_page(inode->i_sb, + it.page = erofs_get_meta_page(sb, ++it.blkaddr, S_ISDIR(inode->i_mode)); - BUG_ON(IS_ERR(it.page)); + if (IS_ERR(it.page)) + return PTR_ERR(it.page); it.kaddr = kmap_atomic(it.page); atomic_map = true; @@ -90,6 +106,7 @@ static void init_inode_xattrs(struct inode *inode) xattr_iter_end(&it, atomic_map); inode_set_inited_xattr(inode); + return 0; } struct xattr_iter_handlers { @@ -99,18 +116,26 @@ struct xattr_iter_handlers { void (*value)(struct xattr_iter *, unsigned, char *, unsigned); }; -static void xattr_iter_fixup(struct xattr_iter *it) +static inline int xattr_iter_fixup(struct xattr_iter *it) { - if (unlikely(it->ofs >= EROFS_BLKSIZ)) { - xattr_iter_end(it, true); + if (it->ofs < EROFS_BLKSIZ) + return 0; + + xattr_iter_end(it, true); - it->blkaddr += erofs_blknr(it->ofs); - it->page = erofs_get_meta_page(it->sb, it->blkaddr, false); - BUG_ON(IS_ERR(it->page)); + it->blkaddr += erofs_blknr(it->ofs); - it->kaddr = kmap_atomic(it->page); - it->ofs = erofs_blkoff(it->ofs); + it->page = erofs_get_meta_page(it->sb, it->blkaddr, false); + if (IS_ERR(it->page)) { + int err = PTR_ERR(it->page); + + it->page = NULL; + return err; } + + it->kaddr = kmap_atomic(it->page); + it->ofs = erofs_blkoff(it->ofs); + return 0; } static int inline_xattr_iter_begin(struct xattr_iter *it, @@ -132,21 +157,24 @@ static int inline_xattr_iter_begin(struct xattr_iter *it, it->ofs = erofs_blkoff(iloc(sbi, vi->nid) + inline_xattr_ofs); it->page = erofs_get_inline_page(inode, it->blkaddr); - BUG_ON(IS_ERR(it->page)); - it->kaddr = kmap_atomic(it->page); + if (IS_ERR(it->page)) + return PTR_ERR(it->page); + it->kaddr = kmap_atomic(it->page); return vi->xattr_isize - xattr_header_sz; } static int xattr_foreach(struct xattr_iter *it, - struct xattr_iter_handlers *op, unsigned *tlimit) + const struct xattr_iter_handlers *op, unsigned int *tlimit) { struct erofs_xattr_entry entry; unsigned value_sz, processed, slice; int err; /* 0. fixup blkaddr, ofs, ipage */ - xattr_iter_fixup(it); + err = xattr_iter_fixup(it); + if (err) + return err; /* * 1. read xattr entry to the memory, @@ -178,7 +206,9 @@ static int xattr_foreach(struct xattr_iter *it, if (it->ofs >= EROFS_BLKSIZ) { BUG_ON(it->ofs > EROFS_BLKSIZ); - xattr_iter_fixup(it); + err = xattr_iter_fixup(it); + if (err) + goto out; it->ofs = 0; } @@ -210,7 +240,10 @@ static int xattr_foreach(struct xattr_iter *it, while (processed < value_sz) { if (it->ofs >= EROFS_BLKSIZ) { BUG_ON(it->ofs > EROFS_BLKSIZ); - xattr_iter_fixup(it); + + err = xattr_iter_fixup(it); + if (err) + goto out; it->ofs = 0; } @@ -270,7 +303,7 @@ static void xattr_copyvalue(struct xattr_iter *_it, memcpy(it->buffer + processed, buf, len); } -static struct xattr_iter_handlers find_xattr_handlers = { +static const struct xattr_iter_handlers find_xattr_handlers = { .entry = xattr_entrymatch, .name = xattr_namematch, .alloc_buffer = xattr_checkbuffer, @@ -291,8 +324,11 @@ static int inline_getxattr(struct inode *inode, struct getxattr_iter *it) ret = xattr_foreach(&it->it, &find_xattr_handlers, &remaining); if (ret >= 0) break; + + if (ret != -ENOATTR) /* -ENOMEM, -EIO, etc. */ + break; } - xattr_iter_end(&it->it, true); + xattr_iter_end_final(&it->it); return ret < 0 ? ret : it->buffer_size; } @@ -300,7 +336,8 @@ static int inline_getxattr(struct inode *inode, struct getxattr_iter *it) static int shared_getxattr(struct inode *inode, struct getxattr_iter *it) { struct erofs_vnode *const vi = EROFS_V(inode); - struct erofs_sb_info *const sbi = EROFS_SB(inode->i_sb); + struct super_block *const sb = inode->i_sb; + struct erofs_sb_info *const sbi = EROFS_SB(sb); unsigned i; int ret = -ENOATTR; @@ -314,9 +351,10 @@ static int shared_getxattr(struct inode *inode, struct getxattr_iter *it) if (i) xattr_iter_end(&it->it, true); - it->it.page = erofs_get_meta_page(inode->i_sb, - blkaddr, false); - BUG_ON(IS_ERR(it->it.page)); + it->it.page = erofs_get_meta_page(sb, blkaddr, false); + if (IS_ERR(it->it.page)) + return PTR_ERR(it->it.page); + it->it.kaddr = kmap_atomic(it->it.page); it->it.blkaddr = blkaddr; } @@ -324,9 +362,12 @@ static int shared_getxattr(struct inode *inode, struct getxattr_iter *it) ret = xattr_foreach(&it->it, &find_xattr_handlers, NULL); if (ret >= 0) break; + + if (ret != -ENOATTR) /* -ENOMEM, -EIO, etc. */ + break; } if (vi->xattr_shared_count) - xattr_iter_end(&it->it, true); + xattr_iter_end_final(&it->it); return ret < 0 ? ret : it->buffer_size; } @@ -351,7 +392,9 @@ int erofs_getxattr(struct inode *inode, int index, if (unlikely(name == NULL)) return -EINVAL; - init_inode_xattrs(inode); + ret = init_inode_xattrs(inode); + if (ret) + return ret; it.index = index; @@ -494,7 +537,7 @@ static int xattr_skipvalue(struct xattr_iter *_it, return 1; } -static struct xattr_iter_handlers list_xattr_handlers = { +static const struct xattr_iter_handlers list_xattr_handlers = { .entry = xattr_entrylist, .name = xattr_namelist, .alloc_buffer = xattr_skipvalue, @@ -516,7 +559,7 @@ static int inline_listxattr(struct listxattr_iter *it) if (ret < 0) break; } - xattr_iter_end(&it->it, true); + xattr_iter_end_final(&it->it); return ret < 0 ? ret : it->buffer_ofs; } @@ -524,7 +567,8 @@ static int shared_listxattr(struct listxattr_iter *it) { struct inode *const inode = d_inode(it->dentry); struct erofs_vnode *const vi = EROFS_V(inode); - struct erofs_sb_info *const sbi = EROFS_I_SB(inode); + struct super_block *const sb = inode->i_sb; + struct erofs_sb_info *const sbi = EROFS_SB(sb); unsigned i; int ret = 0; @@ -537,9 +581,10 @@ static int shared_listxattr(struct listxattr_iter *it) if (i) xattr_iter_end(&it->it, true); - it->it.page = erofs_get_meta_page(inode->i_sb, - blkaddr, false); - BUG_ON(IS_ERR(it->it.page)); + it->it.page = erofs_get_meta_page(sb, blkaddr, false); + if (IS_ERR(it->it.page)) + return PTR_ERR(it->it.page); + it->it.kaddr = kmap_atomic(it->it.page); it->it.blkaddr = blkaddr; } @@ -549,7 +594,7 @@ static int shared_listxattr(struct listxattr_iter *it) break; } if (vi->xattr_shared_count) - xattr_iter_end(&it->it, true); + xattr_iter_end_final(&it->it); return ret < 0 ? ret : it->buffer_ofs; } @@ -560,7 +605,9 @@ ssize_t erofs_listxattr(struct dentry *dentry, int ret; struct listxattr_iter it; - init_inode_xattrs(d_inode(dentry)); + ret = init_inode_xattrs(d_inode(dentry)); + if (ret) + return ret; it.dentry = dentry; it.buffer = buffer; diff --git a/drivers/staging/fbtft/fbtft.h b/drivers/staging/fbtft/fbtft.h index 798a8fe98e95..25302ffc4000 100644 --- a/drivers/staging/fbtft/fbtft.h +++ b/drivers/staging/fbtft/fbtft.h @@ -232,7 +232,7 @@ struct fbtft_par { bool polarity; }; -#define NUMARGS(...) (sizeof((int[]){__VA_ARGS__})/sizeof(int)) +#define NUMARGS(...) (sizeof((int[]){__VA_ARGS__}) / sizeof(int)) #define write_reg(par, ...) \ ((par)->fbtftops.write_register(par, NUMARGS(__VA_ARGS__), __VA_ARGS__)) diff --git a/drivers/staging/fsl-dpaa2/ethsw/ethsw.c b/drivers/staging/fsl-dpaa2/ethsw/ethsw.c index ecdd3d84f956..7a7ca67822c5 100644 --- a/drivers/staging/fsl-dpaa2/ethsw/ethsw.c +++ b/drivers/staging/fsl-dpaa2/ethsw/ethsw.c @@ -717,7 +717,7 @@ static int port_vlans_add(struct net_device *netdev, struct switchdev_trans *trans) { struct ethsw_port_priv *port_priv = netdev_priv(netdev); - int vid, err; + int vid, err = 0; if (netif_is_bridge_master(vlan->obj.orig_dev)) return -EOPNOTSUPP; @@ -872,7 +872,7 @@ static int port_vlans_del(struct net_device *netdev, const struct switchdev_obj_port_vlan *vlan) { struct ethsw_port_priv *port_priv = netdev_priv(netdev); - int vid, err; + int vid, err = 0; if (netif_is_bridge_master(vlan->obj.orig_dev)) return -EOPNOTSUPP; @@ -1014,10 +1014,8 @@ static void ethsw_switchdev_event_work(struct work_struct *work) container_of(work, struct ethsw_switchdev_event_work, work); struct net_device *dev = switchdev_work->dev; struct switchdev_notifier_fdb_info *fdb_info; - struct ethsw_port_priv *port_priv; rtnl_lock(); - port_priv = netdev_priv(dev); fdb_info = &switchdev_work->fdb_info; switch (switchdev_work->event) { diff --git a/drivers/staging/gasket/apex_driver.c b/drivers/staging/gasket/apex_driver.c index c747e9ca4518..6dca3b177863 100644 --- a/drivers/staging/gasket/apex_driver.c +++ b/drivers/staging/gasket/apex_driver.c @@ -138,9 +138,6 @@ static const struct gasket_mappable_region mappable_regions[NUM_REGIONS] = { { 0x48000, 0x1000 }, }; -static const struct gasket_mappable_region cm_mappable_regions[1] = { { 0x0, - APEX_CH_MEM_BYTES } }; - /* Gasket device interrupts enums must be dense (i.e., no empty slots). */ enum apex_interrupt { APEX_INTERRUPT_INSTR_QUEUE = 0, diff --git a/drivers/staging/gasket/gasket_core.c b/drivers/staging/gasket/gasket_core.c index d12ab560411f..f230bec76ae4 100644 --- a/drivers/staging/gasket/gasket_core.c +++ b/drivers/staging/gasket/gasket_core.c @@ -189,26 +189,26 @@ static int gasket_find_dev_slot(struct gasket_internal_desc *internal_desc, * Returns 0 if successful, a negative error code otherwise. */ static int gasket_alloc_dev(struct gasket_internal_desc *internal_desc, - struct device *parent, struct gasket_dev **pdev, - const char *kobj_name) + struct device *parent, struct gasket_dev **pdev) { int dev_idx; const struct gasket_driver_desc *driver_desc = internal_desc->driver_desc; struct gasket_dev *gasket_dev; struct gasket_cdev_info *dev_info; + const char *parent_name = dev_name(parent); - pr_debug("Allocating a Gasket device %s.\n", kobj_name); + pr_debug("Allocating a Gasket device, parent %s.\n", parent_name); *pdev = NULL; - dev_idx = gasket_find_dev_slot(internal_desc, kobj_name); + dev_idx = gasket_find_dev_slot(internal_desc, parent_name); if (dev_idx < 0) return dev_idx; gasket_dev = *pdev = kzalloc(sizeof(*gasket_dev), GFP_KERNEL); if (!gasket_dev) { - pr_err("no memory for device %s\n", kobj_name); + pr_err("no memory for device, parent %s\n", parent_name); return -ENOMEM; } internal_desc->devs[dev_idx] = gasket_dev; @@ -217,7 +217,7 @@ static int gasket_alloc_dev(struct gasket_internal_desc *internal_desc, gasket_dev->internal_desc = internal_desc; gasket_dev->dev_idx = dev_idx; - snprintf(gasket_dev->kobj_name, GASKET_NAME_MAX, "%s", kobj_name); + snprintf(gasket_dev->kobj_name, GASKET_NAME_MAX, "%s", parent_name); gasket_dev->dev = get_device(parent); /* gasket_bar_data is uninitialized. */ gasket_dev->num_page_tables = driver_desc->num_page_tables; @@ -231,10 +231,9 @@ static int gasket_alloc_dev(struct gasket_internal_desc *internal_desc, dev_info->devt = MKDEV(driver_desc->major, driver_desc->minor + gasket_dev->dev_idx); - dev_info->device = device_create(internal_desc->class, parent, - dev_info->devt, gasket_dev, dev_info->name); - - dev_dbg(dev_info->device, "Gasket device allocated.\n"); + dev_info->device = + device_create(internal_desc->class, parent, dev_info->devt, + gasket_dev, dev_info->name); /* cdev has not yet been added; cdev_added is 0 */ dev_info->gasket_dev_ptr = gasket_dev; @@ -652,13 +651,13 @@ void gasket_disable_device(struct gasket_dev *gasket_dev) EXPORT_SYMBOL(gasket_disable_device); /* - * Registered descriptor lookup. + * Registered driver descriptor lookup for PCI devices. * * Precondition: Called with g_mutex held (to avoid a race on return). * Returns NULL if no matching device was found. */ static struct gasket_internal_desc * -lookup_internal_desc(struct pci_dev *pci_dev) +lookup_pci_internal_desc(struct pci_dev *pci_dev) { int i; @@ -1358,13 +1357,7 @@ int gasket_enable_device(struct gasket_dev *gasket_dev) const struct gasket_driver_desc *driver_desc = gasket_dev->internal_desc->driver_desc; - ret = gasket_interrupt_init(gasket_dev, driver_desc->name, - driver_desc->interrupt_type, - driver_desc->interrupts, - driver_desc->num_interrupts, - driver_desc->interrupt_pack_width, - driver_desc->interrupt_bar_index, - driver_desc->wire_interrupt_offsets); + ret = gasket_interrupt_init(gasket_dev); if (ret) { dev_err(gasket_dev->dev, "Critical failure to allocate interrupts: %d\n", ret); @@ -1420,6 +1413,56 @@ int gasket_enable_device(struct gasket_dev *gasket_dev) } EXPORT_SYMBOL(gasket_enable_device); +static int __gasket_add_device(struct device *parent_dev, + struct gasket_internal_desc *internal_desc, + struct gasket_dev **gasket_devp) +{ + int ret; + struct gasket_dev *gasket_dev; + const struct gasket_driver_desc *driver_desc = + internal_desc->driver_desc; + + ret = gasket_alloc_dev(internal_desc, parent_dev, &gasket_dev); + if (ret) + return ret; + if (IS_ERR(gasket_dev->dev_info.device)) { + dev_err(parent_dev, "Cannot create %s device %s [ret = %ld]\n", + driver_desc->name, gasket_dev->dev_info.name, + PTR_ERR(gasket_dev->dev_info.device)); + ret = -ENODEV; + goto free_gasket_dev; + } + + ret = gasket_sysfs_create_mapping(gasket_dev->dev_info.device, + gasket_dev); + if (ret) + goto remove_device; + + ret = gasket_sysfs_create_entries(gasket_dev->dev_info.device, + gasket_sysfs_generic_attrs); + if (ret) + goto remove_sysfs_mapping; + + *gasket_devp = gasket_dev; + return 0; + +remove_sysfs_mapping: + gasket_sysfs_remove_mapping(gasket_dev->dev_info.device); +remove_device: + device_destroy(internal_desc->class, gasket_dev->dev_info.devt); +free_gasket_dev: + gasket_free_dev(gasket_dev); + return ret; +} + +static void __gasket_remove_device(struct gasket_internal_desc *internal_desc, + struct gasket_dev *gasket_dev) +{ + gasket_sysfs_remove_mapping(gasket_dev->dev_info.device); + device_destroy(internal_desc->class, gasket_dev->dev_info.devt); + gasket_free_dev(gasket_dev); +} + /* * Add PCI gasket device. * @@ -1432,16 +1475,14 @@ int gasket_pci_add_device(struct pci_dev *pci_dev, struct gasket_dev **gasket_devp) { int ret; - const char *kobj_name = dev_name(&pci_dev->dev); struct gasket_internal_desc *internal_desc; struct gasket_dev *gasket_dev; - const struct gasket_driver_desc *driver_desc; struct device *parent; - pr_debug("add PCI device %s\n", kobj_name); + dev_dbg(&pci_dev->dev, "add PCI gasket device\n"); mutex_lock(&g_mutex); - internal_desc = lookup_internal_desc(pci_dev); + internal_desc = lookup_pci_internal_desc(pci_dev); mutex_unlock(&g_mutex); if (!internal_desc) { dev_err(&pci_dev->dev, @@ -1449,29 +1490,15 @@ int gasket_pci_add_device(struct pci_dev *pci_dev, return -ENODEV; } - driver_desc = internal_desc->driver_desc; - parent = &pci_dev->dev; - ret = gasket_alloc_dev(internal_desc, parent, &gasket_dev, kobj_name); + ret = __gasket_add_device(parent, internal_desc, &gasket_dev); if (ret) return ret; - gasket_dev->pci_dev = pci_dev; - if (IS_ERR_OR_NULL(gasket_dev->dev_info.device)) { - pr_err("Cannot create %s device %s [ret = %ld]\n", - driver_desc->name, gasket_dev->dev_info.name, - PTR_ERR(gasket_dev->dev_info.device)); - ret = -ENODEV; - goto fail1; - } + gasket_dev->pci_dev = pci_dev; ret = gasket_setup_pci(pci_dev, gasket_dev); if (ret) - goto fail2; - - ret = gasket_sysfs_create_mapping(gasket_dev->dev_info.device, - gasket_dev); - if (ret) - goto fail3; + goto cleanup_pci; /* * Once we've created the mapping structures successfully, attempt to @@ -1482,24 +1509,15 @@ int gasket_pci_add_device(struct pci_dev *pci_dev, if (ret) { dev_err(gasket_dev->dev, "Cannot create sysfs pci link: %d\n", ret); - goto fail3; + goto cleanup_pci; } - ret = gasket_sysfs_create_entries(gasket_dev->dev_info.device, - gasket_sysfs_generic_attrs); - if (ret) - goto fail4; *gasket_devp = gasket_dev; return 0; -fail4: -fail3: - gasket_sysfs_remove_mapping(gasket_dev->dev_info.device); -fail2: +cleanup_pci: gasket_cleanup_pci(gasket_dev); - device_destroy(internal_desc->class, gasket_dev->dev_info.devt); -fail1: - gasket_free_dev(gasket_dev); + __gasket_remove_device(internal_desc, gasket_dev); return ret; } EXPORT_SYMBOL(gasket_pci_add_device); @@ -1510,18 +1528,15 @@ void gasket_pci_remove_device(struct pci_dev *pci_dev) int i; struct gasket_internal_desc *internal_desc; struct gasket_dev *gasket_dev = NULL; - const struct gasket_driver_desc *driver_desc; /* Find the device desc. */ mutex_lock(&g_mutex); - internal_desc = lookup_internal_desc(pci_dev); + internal_desc = lookup_pci_internal_desc(pci_dev); if (!internal_desc) { mutex_unlock(&g_mutex); return; } mutex_unlock(&g_mutex); - driver_desc = internal_desc->driver_desc; - /* Now find the specific device */ mutex_lock(&internal_desc->mutex); for (i = 0; i < GASKET_DEV_MAX; i++) { @@ -1540,10 +1555,7 @@ void gasket_pci_remove_device(struct pci_dev *pci_dev) internal_desc->driver_desc->name); gasket_cleanup_pci(gasket_dev); - - gasket_sysfs_remove_mapping(gasket_dev->dev_info.device); - device_destroy(internal_desc->class, gasket_dev->dev_info.devt); - gasket_free_dev(gasket_dev); + __gasket_remove_device(internal_desc, gasket_dev); } EXPORT_SYMBOL(gasket_pci_remove_device); @@ -1791,7 +1803,6 @@ static int __init gasket_init(void) { int i; - pr_debug("%s\n", __func__); mutex_lock(&g_mutex); for (i = 0; i < GASKET_FRAMEWORK_DESC_MAX; i++) { g_descs[i].driver_desc = NULL; @@ -1804,13 +1815,8 @@ static int __init gasket_init(void) return 0; } -static void __exit gasket_exit(void) -{ - pr_debug("%s\n", __func__); -} MODULE_DESCRIPTION("Google Gasket driver framework"); MODULE_VERSION(GASKET_FRAMEWORK_VERSION); MODULE_LICENSE("GPL v2"); MODULE_AUTHOR("Rob Springer <rspringer@google.com>"); module_init(gasket_init); -module_exit(gasket_exit); diff --git a/drivers/staging/gasket/gasket_core.h b/drivers/staging/gasket/gasket_core.h index 275fd0b345b6..0203460f4895 100644 --- a/drivers/staging/gasket/gasket_core.h +++ b/drivers/staging/gasket/gasket_core.h @@ -50,8 +50,6 @@ enum gasket_interrupt_packing { /* Type of the interrupt supported by the device. */ enum gasket_interrupt_type { PCI_MSIX = 0, - PCI_MSI = 1, - PLATFORM_WIRE = 2, }; /* @@ -69,12 +67,6 @@ struct gasket_interrupt_desc { int packing; }; -/* Offsets to the wire interrupt handling registers */ -struct gasket_wire_interrupt_offsets { - u64 pending_bit_array; - u64 mask_array; -}; - /* * This enum is used to identify memory regions being part of the physical * memory that belongs to a device. @@ -384,9 +376,6 @@ struct gasket_driver_desc { */ struct gasket_coherent_buffer_desc coherent_buffer_description; - /* Offset of wire interrupt registers. */ - const struct gasket_wire_interrupt_offsets *wire_interrupt_offsets; - /* Interrupt type. (One of gasket_interrupt_type). */ int interrupt_type; @@ -590,25 +579,25 @@ const char *gasket_num_name_lookup(uint num, static inline ulong gasket_dev_read_64(struct gasket_dev *gasket_dev, int bar, ulong location) { - return readq(&gasket_dev->bar_data[bar].virt_base[location]); + return readq_relaxed(&gasket_dev->bar_data[bar].virt_base[location]); } static inline void gasket_dev_write_64(struct gasket_dev *dev, u64 value, int bar, ulong location) { - writeq(value, &dev->bar_data[bar].virt_base[location]); + writeq_relaxed(value, &dev->bar_data[bar].virt_base[location]); } static inline void gasket_dev_write_32(struct gasket_dev *dev, u32 value, int bar, ulong location) { - writel(value, &dev->bar_data[bar].virt_base[location]); + writel_relaxed(value, &dev->bar_data[bar].virt_base[location]); } static inline u32 gasket_dev_read_32(struct gasket_dev *dev, int bar, ulong location) { - return readl(&dev->bar_data[bar].virt_base[location]); + return readl_relaxed(&dev->bar_data[bar].virt_base[location]); } static inline void gasket_read_modify_write_64(struct gasket_dev *dev, int bar, diff --git a/drivers/staging/gasket/gasket_interrupt.c b/drivers/staging/gasket/gasket_interrupt.c index 1cfbc120f228..2cd262be65ca 100644 --- a/drivers/staging/gasket/gasket_interrupt.c +++ b/drivers/staging/gasket/gasket_interrupt.c @@ -45,9 +45,6 @@ struct gasket_interrupt_data { /* The width of a single interrupt in a packed interrupt register. */ int pack_width; - /* offset of wire interrupt registers */ - const struct gasket_wire_interrupt_offsets *wire_interrupt_offsets; - /* * Design-wise, these elements should be bundled together, but * pci_enable_msix's interface requires that they be managed @@ -92,19 +89,6 @@ static void gasket_interrupt_setup(struct gasket_dev *gasket_dev) dev_dbg(gasket_dev->dev, "Running interrupt setup\n"); - if (interrupt_data->type == PLATFORM_WIRE || - interrupt_data->type == PCI_MSI) { - /* Nothing needs to be done for platform or PCI devices. */ - return; - } - - if (interrupt_data->type != PCI_MSIX) { - dev_dbg(gasket_dev->dev, - "Cannot handle unsupported interrupt type %d\n", - interrupt_data->type); - return; - } - /* Setup the MSIX table. */ for (i = 0; i < interrupt_data->num_interrupts; i++) { @@ -157,9 +141,22 @@ static void gasket_interrupt_setup(struct gasket_dev *gasket_dev) } } -static irqreturn_t gasket_msix_interrupt_handler(int irq, void *dev_id) +static void +gasket_handle_interrupt(struct gasket_interrupt_data *interrupt_data, + int interrupt_index) { struct eventfd_ctx *ctx; + + trace_gasket_interrupt_event(interrupt_data->name, interrupt_index); + ctx = interrupt_data->eventfd_ctxs[interrupt_index]; + if (ctx) + eventfd_signal(ctx, 1); + + ++(interrupt_data->interrupt_counts[interrupt_index]); +} + +static irqreturn_t gasket_msix_interrupt_handler(int irq, void *dev_id) +{ struct gasket_interrupt_data *interrupt_data = dev_id; int interrupt = -1; int i; @@ -175,14 +172,7 @@ static irqreturn_t gasket_msix_interrupt_handler(int irq, void *dev_id) pr_err("Received unknown irq %d\n", irq); return IRQ_HANDLED; } - trace_gasket_interrupt_event(interrupt_data->name, interrupt); - - ctx = interrupt_data->eventfd_ctxs[interrupt]; - if (ctx) - eventfd_signal(ctx, 1); - - ++(interrupt_data->interrupt_counts[interrupt]); - + gasket_handle_interrupt(interrupt_data, interrupt); return IRQ_HANDLED; } @@ -192,6 +182,12 @@ gasket_interrupt_msix_init(struct gasket_interrupt_data *interrupt_data) int ret = 1; int i; + interrupt_data->msix_entries = + kcalloc(interrupt_data->num_interrupts, + sizeof(struct msix_entry), GFP_KERNEL); + if (!interrupt_data->msix_entries) + return -ENOMEM; + for (i = 0; i < interrupt_data->num_interrupts; i++) { interrupt_data->msix_entries[i].entry = i; interrupt_data->msix_entries[i].vector = 0; @@ -319,54 +315,40 @@ static struct gasket_sysfs_attribute interrupt_sysfs_attrs[] = { GASKET_END_OF_ATTR_ARRAY, }; -int gasket_interrupt_init(struct gasket_dev *gasket_dev, const char *name, - int type, - const struct gasket_interrupt_desc *interrupts, - int num_interrupts, int pack_width, int bar_index, - const struct gasket_wire_interrupt_offsets *wire_int_offsets) +int gasket_interrupt_init(struct gasket_dev *gasket_dev) { int ret; struct gasket_interrupt_data *interrupt_data; + const struct gasket_driver_desc *driver_desc = + gasket_get_driver_desc(gasket_dev); interrupt_data = kzalloc(sizeof(struct gasket_interrupt_data), GFP_KERNEL); if (!interrupt_data) return -ENOMEM; gasket_dev->interrupt_data = interrupt_data; - interrupt_data->name = name; - interrupt_data->type = type; + interrupt_data->name = driver_desc->name; + interrupt_data->type = driver_desc->interrupt_type; interrupt_data->pci_dev = gasket_dev->pci_dev; - interrupt_data->num_interrupts = num_interrupts; - interrupt_data->interrupts = interrupts; - interrupt_data->interrupt_bar_index = bar_index; - interrupt_data->pack_width = pack_width; + interrupt_data->num_interrupts = driver_desc->num_interrupts; + interrupt_data->interrupts = driver_desc->interrupts; + interrupt_data->interrupt_bar_index = driver_desc->interrupt_bar_index; + interrupt_data->pack_width = driver_desc->interrupt_pack_width; interrupt_data->num_configured = 0; - interrupt_data->wire_interrupt_offsets = wire_int_offsets; - /* Allocate all dynamic structures. */ - interrupt_data->msix_entries = kcalloc(num_interrupts, - sizeof(struct msix_entry), - GFP_KERNEL); - if (!interrupt_data->msix_entries) { - kfree(interrupt_data); - return -ENOMEM; - } - - interrupt_data->eventfd_ctxs = kcalloc(num_interrupts, + interrupt_data->eventfd_ctxs = kcalloc(driver_desc->num_interrupts, sizeof(struct eventfd_ctx *), GFP_KERNEL); if (!interrupt_data->eventfd_ctxs) { - kfree(interrupt_data->msix_entries); kfree(interrupt_data); return -ENOMEM; } - interrupt_data->interrupt_counts = kcalloc(num_interrupts, + interrupt_data->interrupt_counts = kcalloc(driver_desc->num_interrupts, sizeof(ulong), GFP_KERNEL); if (!interrupt_data->interrupt_counts) { kfree(interrupt_data->eventfd_ctxs); - kfree(interrupt_data->msix_entries); kfree(interrupt_data); return -ENOMEM; } @@ -379,12 +361,7 @@ int gasket_interrupt_init(struct gasket_dev *gasket_dev, const char *name, force_msix_interrupt_unmasking(gasket_dev); break; - case PCI_MSI: - case PLATFORM_WIRE: default: - dev_err(gasket_dev->dev, - "Cannot handle unsupported interrupt type %d\n", - interrupt_data->type); ret = -EINVAL; } @@ -417,6 +394,7 @@ gasket_interrupt_msix_cleanup(struct gasket_interrupt_data *interrupt_data) if (interrupt_data->msix_configured) pci_disable_msix(interrupt_data->pci_dev); interrupt_data->msix_configured = 0; + kfree(interrupt_data->msix_entries); } int gasket_interrupt_reinit(struct gasket_dev *gasket_dev) @@ -438,20 +416,16 @@ int gasket_interrupt_reinit(struct gasket_dev *gasket_dev) force_msix_interrupt_unmasking(gasket_dev); break; - case PCI_MSI: - case PLATFORM_WIRE: default: - dev_dbg(gasket_dev->dev, - "Cannot handle unsupported interrupt type %d\n", - gasket_dev->interrupt_data->type); ret = -EINVAL; } if (ret) { - /* Failing to setup MSIx will cause the device + /* Failing to setup interrupts will cause the device * to report GASKET_STATUS_LAMED, but is not fatal. */ - dev_warn(gasket_dev->dev, "Couldn't init msix: %d\n", ret); + dev_warn(gasket_dev->dev, "Couldn't reinit interrupts: %d\n", + ret); return 0; } @@ -487,17 +461,12 @@ void gasket_interrupt_cleanup(struct gasket_dev *gasket_dev) gasket_interrupt_msix_cleanup(interrupt_data); break; - case PCI_MSI: - case PLATFORM_WIRE: default: - dev_dbg(gasket_dev->dev, - "Cannot handle unsupported interrupt type %d\n", - interrupt_data->type); + break; } kfree(interrupt_data->interrupt_counts); kfree(interrupt_data->eventfd_ctxs); - kfree(interrupt_data->msix_entries); kfree(interrupt_data); gasket_dev->interrupt_data = NULL; } diff --git a/drivers/staging/gasket/gasket_interrupt.h b/drivers/staging/gasket/gasket_interrupt.h index 835af439e96a..85526a1374a1 100644 --- a/drivers/staging/gasket/gasket_interrupt.h +++ b/drivers/staging/gasket/gasket_interrupt.h @@ -24,30 +24,8 @@ struct gasket_interrupt_data; /* * Initialize the interrupt module. * @gasket_dev: The Gasket device structure for the device to be initted. - * @type: Type of the interrupt. (See gasket_interrupt_type). - * @name: The name to associate with these interrupts. - * @interrupts: An array of all interrupt descriptions for this device. - * @num_interrupts: The length of the @interrupts array. - * @pack_width: The width, in bits, of a single field in a packed interrupt reg. - * @bar_index: The bar containing all interrupt registers. - * - * Allocates and initializes data to track interrupt state for a device. - * After this call, no interrupts will be configured/delivered; call - * gasket_interrupt_set_vector[_packed] to associate each interrupt with an - * __iomem location, then gasket_interrupt_set_eventfd to associate an eventfd - * with an interrupt. - * - * If num_interrupts interrupts are not available, this call will return a - * negative error code. In that case, gasket_interrupt_cleanup should still be - * called. Returns 0 on success (which can include a device where interrupts - * are not possible to set up, but is otherwise OK; that device will report - * status LAMED.) */ -int gasket_interrupt_init(struct gasket_dev *gasket_dev, const char *name, - int type, - const struct gasket_interrupt_desc *interrupts, - int num_interrupts, int pack_width, int bar_index, - const struct gasket_wire_interrupt_offsets *wire_int_offsets); +int gasket_interrupt_init(struct gasket_dev *gasket_dev); /* * Clean up a device's interrupt structure. diff --git a/drivers/staging/gasket/gasket_page_table.c b/drivers/staging/gasket/gasket_page_table.c index d4c5f8aa7dd3..53492f4fad6a 100644 --- a/drivers/staging/gasket/gasket_page_table.c +++ b/drivers/staging/gasket/gasket_page_table.c @@ -317,8 +317,6 @@ static void gasket_free_extended_subtable(struct gasket_page_table *pg_tbl, /* Release the page table from the device */ writeq(0, slot); - /* Force sync around the address release. */ - mb(); if (pte->dma_addr) dma_unmap_page(pg_tbl->device, pte->dma_addr, PAGE_SIZE, @@ -493,7 +491,8 @@ static int gasket_perform_mapping(struct gasket_page_table *pg_tbl, (void *)page_to_pfn(page), (unsigned long long)ptes[i].dma_addr); - if (ptes[i].dma_addr == -1) { + if (dma_mapping_error(pg_tbl->device, + ptes[i].dma_addr)) { dev_dbg(pg_tbl->device, "%s i %d -> fail to map page %llx " "[pfn %p ohys %p]\n", @@ -503,8 +502,6 @@ static int gasket_perform_mapping(struct gasket_page_table *pg_tbl, (void *)page_to_phys(page)); return -1; } - /* Wait until the page is mapped. */ - mb(); } /* Make the DMA-space address available to the device. */ @@ -603,12 +600,13 @@ static void gasket_perform_unmapping(struct gasket_page_table *pg_tbl, */ for (i = 0; i < num_pages; i++) { /* release the address from the device, */ - if (is_simple_mapping || ptes[i].status == PTE_INUSE) + if (is_simple_mapping || ptes[i].status == PTE_INUSE) { writeq(0, &slots[i]); - else + } else { ((u64 __force *)slots)[i] = 0; - /* Force sync around the address release. */ - mb(); + /* sync above PTE update before updating mappings */ + wmb(); + } /* release the address from the driver, */ if (ptes[i].status == PTE_INUSE) { @@ -897,8 +895,6 @@ static int gasket_alloc_extended_subtable(struct gasket_page_table *pg_tbl, /* Map the page into DMA space. */ pte->dma_addr = dma_map_page(pg_tbl->device, pte->page, 0, PAGE_SIZE, DMA_BIDIRECTIONAL); - /* Wait until the page is mapped. */ - mb(); /* make the addresses available to the device */ dma_addr = (pte->dma_addr + pte->offset) | GASKET_VALID_SLOT_FLAG; @@ -1328,10 +1324,8 @@ nomem: num_pages * PAGE_SIZE, mem, handle); } - if (gasket_dev->page_table[index]->coherent_pages) { - kfree(gasket_dev->page_table[index]->coherent_pages); - gasket_dev->page_table[index]->coherent_pages = NULL; - } + kfree(gasket_dev->page_table[index]->coherent_pages); + gasket_dev->page_table[index]->coherent_pages = NULL; gasket_dev->page_table[index]->num_coherent_pages = 0; return -ENOMEM; } diff --git a/drivers/staging/media/imx/imx-media-dev.c b/drivers/staging/media/imx/imx-media-dev.c index b0be80f05767..3f48f5ceb6ea 100644 --- a/drivers/staging/media/imx/imx-media-dev.c +++ b/drivers/staging/media/imx/imx-media-dev.c @@ -89,8 +89,12 @@ int imx_media_add_async_subdev(struct imx_media_dev *imxmd, /* return -EEXIST if this asd already added */ if (find_async_subdev(imxmd, fwnode, devname)) { - dev_dbg(imxmd->md.dev, "%s: already added %s\n", - __func__, np ? np->name : devname); + if (np) + dev_dbg(imxmd->md.dev, "%s: already added %pOFn\n", + __func__, np); + else + dev_dbg(imxmd->md.dev, "%s: already added %s\n", + __func__, devname); ret = -EEXIST; goto out; } @@ -105,19 +109,20 @@ int imx_media_add_async_subdev(struct imx_media_dev *imxmd, if (fwnode) { asd->match_type = V4L2_ASYNC_MATCH_FWNODE; asd->match.fwnode = fwnode; + dev_dbg(imxmd->md.dev, "%s: added %pOFn, match type FWNODE\n", + __func__, np); } else { asd->match_type = V4L2_ASYNC_MATCH_DEVNAME; asd->match.device_name = devname; imxasd->pdev = pdev; + dev_dbg(imxmd->md.dev, "%s: added %s, match type DEVNAME\n", + __func__, devname); } list_add_tail(&imxasd->list, &imxmd->asd_list); imxmd->subdev_notifier.num_subdevs++; - dev_dbg(imxmd->md.dev, "%s: added %s, match type %s\n", - __func__, np ? np->name : devname, np ? "FWNODE" : "DEVNAME"); - out: mutex_unlock(&imxmd->mutex); return ret; diff --git a/drivers/staging/media/imx/imx-media-of.c b/drivers/staging/media/imx/imx-media-of.c index acde372c6795..163437e421c5 100644 --- a/drivers/staging/media/imx/imx-media-of.c +++ b/drivers/staging/media/imx/imx-media-of.c @@ -79,8 +79,8 @@ of_parse_subdev(struct imx_media_dev *imxmd, struct device_node *sd_np, int i, num_ports, ret; if (!of_device_is_available(sd_np)) { - dev_dbg(imxmd->md.dev, "%s: %s not enabled\n", __func__, - sd_np->name); + dev_dbg(imxmd->md.dev, "%s: %pOFn not enabled\n", __func__, + sd_np); /* unavailable is not an error */ return 0; } diff --git a/drivers/staging/most/core.c b/drivers/staging/most/core.c index f4c464625a67..dabe180ae432 100644 --- a/drivers/staging/most/core.c +++ b/drivers/staging/most/core.c @@ -442,6 +442,24 @@ static ssize_t set_dbr_size_store(struct device *dev, return count; } +#define to_dev_attr(a) container_of(a, struct device_attribute, attr) +static umode_t channel_attr_is_visible(struct kobject *kobj, + struct attribute *attr, int index) +{ + struct device_attribute *dev_attr = to_dev_attr(attr); + struct device *dev = kobj_to_dev(kobj); + struct most_channel *c = to_channel(dev); + + if (!strcmp(dev_attr->attr.name, "set_dbr_size") && + (c->iface->interface != ITYPE_MEDIALB_DIM2)) + return 0; + if (!strcmp(dev_attr->attr.name, "set_packets_per_xact") && + (c->iface->interface != ITYPE_USB)) + return 0; + + return attr->mode; +} + #define DEV_ATTR(_name) (&dev_attr_##_name.attr) static DEVICE_ATTR_RO(available_directions); @@ -479,6 +497,7 @@ static struct attribute *channel_attrs[] = { static struct attribute_group channel_attr_group = { .attrs = channel_attrs, + .is_visible = channel_attr_is_visible, }; static const struct attribute_group *channel_attr_groups[] = { @@ -1439,10 +1458,6 @@ int most_register_interface(struct most_interface *iface) c->dev.parent = &iface->dev; c->dev.groups = channel_attr_groups; c->dev.release = release_channel; - if (device_register(&c->dev)) { - pr_err("registering c->dev failed\n"); - goto free_instance_nodev; - } iface->p->channel[i] = c; c->is_starving = 0; c->iface = iface; @@ -1465,6 +1480,10 @@ int most_register_interface(struct most_interface *iface) mutex_init(&c->start_mutex); mutex_init(&c->nq_mutex); list_add_tail(&c->list, &iface->p->channel_list); + if (device_register(&c->dev)) { + pr_err("registering c->dev failed\n"); + goto free_instance_nodev; + } } pr_info("registered new device mdev%d (%s)\n", id, iface->description); diff --git a/drivers/staging/most/net/net.c b/drivers/staging/most/net/net.c index 30d816b7e165..e20584b1b112 100644 --- a/drivers/staging/most/net/net.c +++ b/drivers/staging/most/net/net.c @@ -75,7 +75,7 @@ static struct core_component comp; static int skb_to_mamac(const struct sk_buff *skb, struct mbo *mbo) { u8 *buff = mbo->virt_address; - const u8 broadcast[] = { 0x03, 0xFF }; + static const u8 broadcast[] = { 0x03, 0xFF }; const u8 *dest_addr = skb->data + 4; const u8 *eth_type = skb->data + 12; unsigned int payload_len = skb->len - ETH_HLEN; diff --git a/drivers/staging/most/video/video.c b/drivers/staging/most/video/video.c index cf342eb58e10..ad7e28ab9a4f 100644 --- a/drivers/staging/most/video/video.c +++ b/drivers/staging/most/video/video.c @@ -530,7 +530,7 @@ static int comp_disconnect_channel(struct most_interface *iface, return 0; } -static struct core_component comp_info = { +static struct core_component comp = { .name = "video", .probe_channel = comp_probe_channel, .disconnect_channel = comp_disconnect_channel, @@ -565,7 +565,7 @@ static void __exit comp_exit(void) } spin_unlock_irq(&list_lock); - most_deregister_component(&comp_info); + most_deregister_component(&comp); BUG_ON(!list_empty(&video_devices)); } diff --git a/drivers/staging/mt7621-eth/mdio.c b/drivers/staging/mt7621-eth/mdio.c index 7ad0c4141205..9ffa8f771235 100644 --- a/drivers/staging/mt7621-eth/mdio.c +++ b/drivers/staging/mt7621-eth/mdio.c @@ -70,7 +70,7 @@ int mtk_connect_phy_node(struct mtk_eth *eth, struct mtk_mac *mac, _port = of_get_property(phy_node, "reg", NULL); if (!_port || (be32_to_cpu(*_port) >= 0x20)) { - pr_err("%s: invalid port id\n", phy_node->name); + pr_err("%pOFn: invalid port id\n", phy_node); return -EINVAL; } port = be32_to_cpu(*_port); @@ -249,7 +249,7 @@ int mtk_mdio_init(struct mtk_eth *eth) eth->mii_bus->priv = eth; eth->mii_bus->parent = eth->dev; - snprintf(eth->mii_bus->id, MII_BUS_ID_SIZE, "%s", mii_np->name); + snprintf(eth->mii_bus->id, MII_BUS_ID_SIZE, "%pOFn", mii_np); err = of_mdiobus_register(eth->mii_bus, mii_np); if (err) goto err_free_bus; diff --git a/drivers/staging/mt7621-mmc/dbg.c b/drivers/staging/mt7621-mmc/dbg.c index 6e518dce9029..4fe4d2fd111e 100644 --- a/drivers/staging/mt7621-mmc/dbg.c +++ b/drivers/staging/mt7621-mmc/dbg.c @@ -249,7 +249,9 @@ static ssize_t msdc_debug_proc_write(struct file *file, cmd_buf[count] = '\0'; pr_debug("msdc Write %s\n", cmd_buf); - sscanf(cmd_buf, "%x %x %x", &cmd, &p1, &p2); + ret = sscanf(cmd_buf, "%x %x %x", &cmd, &p1, &p2); + if (ret != 3) + return -EINVAL; if (cmd == SD_TOOL_ZONE) { id = p1; diff --git a/drivers/staging/mt7621-mmc/dbg.h b/drivers/staging/mt7621-mmc/dbg.h index 2f2c56b73987..79914d98c573 100644 --- a/drivers/staging/mt7621-mmc/dbg.h +++ b/drivers/staging/mt7621-mmc/dbg.h @@ -102,33 +102,10 @@ do { \ } while (0) #endif /* end of +++ */ -#define N_MSG(evt, fmt, args...) -/* -do { \ - if ((DBG_EVT_##evt) & sd_debug_zone[host->id]) { \ - printk(KERN_ERR TAG"%d -> "fmt" <- %s() : L<%d> PID<%s><0x%x>\n", \ - host->id, ##args , __FUNCTION__, __LINE__, current->comm, current->pid); \ - } \ -} while(0) -*/ - -#define ERR_MSG(fmt, args...) \ -do { \ - printk(KERN_ERR TAG"%d -> "fmt" <- %s() : L<%d> PID<%s><0x%x>\n", \ - host->id, ##args, __FUNCTION__, __LINE__, current->comm, current->pid); \ -} while (0); - #if 1 //defined CONFIG_MTK_MMC_CD_POLL -#define INIT_MSG(fmt, args...) #define IRQ_MSG(fmt, args...) #else -#define INIT_MSG(fmt, args...) \ -do { \ - printk(KERN_ERR TAG"%d -> "fmt" <- %s() : L<%d> PID<%s><0x%x>\n", \ - host->id, ##args, __FUNCTION__, __LINE__, current->comm, current->pid); \ -} while (0); - /* PID in ISR in not corrent */ #define IRQ_MSG(fmt, args...) \ do { \ diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c index 04d23cc7cd4a..7474f9ed7b5b 100644 --- a/drivers/staging/mt7621-mmc/sd.c +++ b/drivers/staging/mt7621-mmc/sd.c @@ -187,12 +187,10 @@ static u32 hclks[] = {50000000}; /* +/- by chhung */ //============================================ #define msdc_vcore_on(host) \ do { \ - INIT_MSG("[+]VMC ref. count<%d>", ++host->pwr_ref); \ (void)hwPowerOn(MT65XX_POWER_LDO_VMC, VOL_3300, "SD"); \ } while (0) #define msdc_vcore_off(host) \ do { \ - INIT_MSG("[-]VMC ref. count<%d>", --host->pwr_ref); \ (void)hwPowerDown(MT65XX_POWER_LDO_VMC, "SD"); \ } while (0) @@ -232,144 +230,6 @@ static unsigned int msdc_do_command(struct msdc_host *host, static int msdc_tune_cmdrsp(struct msdc_host *host, struct mmc_command *cmd); -#ifdef MT6575_SD_DEBUG -static void msdc_dump_card_status(struct msdc_host *host, u32 status) -{ -/* N_MSG is currently a no-op */ -#if 0 - static char *state[] = { - "Idle", /* 0 */ - "Ready", /* 1 */ - "Ident", /* 2 */ - "Stby", /* 3 */ - "Tran", /* 4 */ - "Data", /* 5 */ - "Rcv", /* 6 */ - "Prg", /* 7 */ - "Dis", /* 8 */ - "Reserved", /* 9 */ - "Reserved", /* 10 */ - "Reserved", /* 11 */ - "Reserved", /* 12 */ - "Reserved", /* 13 */ - "Reserved", /* 14 */ - "I/O mode", /* 15 */ - }; -#endif - if (status & R1_OUT_OF_RANGE) - N_MSG(RSP, "[CARD_STATUS] Out of Range"); - if (status & R1_ADDRESS_ERROR) - N_MSG(RSP, "[CARD_STATUS] Address Error"); - if (status & R1_BLOCK_LEN_ERROR) - N_MSG(RSP, "[CARD_STATUS] Block Len Error"); - if (status & R1_ERASE_SEQ_ERROR) - N_MSG(RSP, "[CARD_STATUS] Erase Seq Error"); - if (status & R1_ERASE_PARAM) - N_MSG(RSP, "[CARD_STATUS] Erase Param"); - if (status & R1_WP_VIOLATION) - N_MSG(RSP, "[CARD_STATUS] WP Violation"); - if (status & R1_CARD_IS_LOCKED) - N_MSG(RSP, "[CARD_STATUS] Card is Locked"); - if (status & R1_LOCK_UNLOCK_FAILED) - N_MSG(RSP, "[CARD_STATUS] Lock/Unlock Failed"); - if (status & R1_COM_CRC_ERROR) - N_MSG(RSP, "[CARD_STATUS] Command CRC Error"); - if (status & R1_ILLEGAL_COMMAND) - N_MSG(RSP, "[CARD_STATUS] Illegal Command"); - if (status & R1_CARD_ECC_FAILED) - N_MSG(RSP, "[CARD_STATUS] Card ECC Failed"); - if (status & R1_CC_ERROR) - N_MSG(RSP, "[CARD_STATUS] CC Error"); - if (status & R1_ERROR) - N_MSG(RSP, "[CARD_STATUS] Error"); - if (status & R1_UNDERRUN) - N_MSG(RSP, "[CARD_STATUS] Underrun"); - if (status & R1_OVERRUN) - N_MSG(RSP, "[CARD_STATUS] Overrun"); - if (status & R1_CID_CSD_OVERWRITE) - N_MSG(RSP, "[CARD_STATUS] CID/CSD Overwrite"); - if (status & R1_WP_ERASE_SKIP) - N_MSG(RSP, "[CARD_STATUS] WP Eraser Skip"); - if (status & R1_CARD_ECC_DISABLED) - N_MSG(RSP, "[CARD_STATUS] Card ECC Disabled"); - if (status & R1_ERASE_RESET) - N_MSG(RSP, "[CARD_STATUS] Erase Reset"); - if (status & R1_READY_FOR_DATA) - N_MSG(RSP, "[CARD_STATUS] Ready for Data"); - if (status & R1_SWITCH_ERROR) - N_MSG(RSP, "[CARD_STATUS] Switch error"); - if (status & R1_APP_CMD) - N_MSG(RSP, "[CARD_STATUS] App Command"); - - N_MSG(RSP, "[CARD_STATUS] '%s' State", state[R1_CURRENT_STATE(status)]); -} - -static void msdc_dump_ocr_reg(struct msdc_host *host, u32 resp) -{ - if (resp & (1 << 7)) - N_MSG(RSP, "[OCR] Low Voltage Range"); - if (resp & (1 << 15)) - N_MSG(RSP, "[OCR] 2.7-2.8 volt"); - if (resp & (1 << 16)) - N_MSG(RSP, "[OCR] 2.8-2.9 volt"); - if (resp & (1 << 17)) - N_MSG(RSP, "[OCR] 2.9-3.0 volt"); - if (resp & (1 << 18)) - N_MSG(RSP, "[OCR] 3.0-3.1 volt"); - if (resp & (1 << 19)) - N_MSG(RSP, "[OCR] 3.1-3.2 volt"); - if (resp & (1 << 20)) - N_MSG(RSP, "[OCR] 3.2-3.3 volt"); - if (resp & (1 << 21)) - N_MSG(RSP, "[OCR] 3.3-3.4 volt"); - if (resp & (1 << 22)) - N_MSG(RSP, "[OCR] 3.4-3.5 volt"); - if (resp & (1 << 23)) - N_MSG(RSP, "[OCR] 3.5-3.6 volt"); - if (resp & (1 << 24)) - N_MSG(RSP, "[OCR] Switching to 1.8V Accepted (S18A)"); - if (resp & (1 << 30)) - N_MSG(RSP, "[OCR] Card Capacity Status (CCS)"); - if (resp & (1 << 31)) - N_MSG(RSP, "[OCR] Card Power Up Status (Idle)"); - else - N_MSG(RSP, "[OCR] Card Power Up Status (Busy)"); -} - -static void msdc_dump_rca_resp(struct msdc_host *host, u32 resp) -{ - u32 status = (((resp >> 15) & 0x1) << 23) | - (((resp >> 14) & 0x1) << 22) | - (((resp >> 13) & 0x1) << 19) | - (resp & 0x1fff); - - N_MSG(RSP, "[RCA] 0x%.4x", resp >> 16); - msdc_dump_card_status(host, status); -} - -static void msdc_dump_io_resp(struct msdc_host *host, u32 resp) -{ - u32 flags = (resp >> 8) & 0xFF; -#if 0 - char *state[] = {"DIS", "CMD", "TRN", "RFU"}; -#endif - if (flags & (1 << 7)) - N_MSG(RSP, "[IO] COM_CRC_ERR"); - if (flags & (1 << 6)) - N_MSG(RSP, "[IO] Illegal command"); - if (flags & (1 << 3)) - N_MSG(RSP, "[IO] Error"); - if (flags & (1 << 2)) - N_MSG(RSP, "[IO] RFU"); - if (flags & (1 << 1)) - N_MSG(RSP, "[IO] Function number error"); - if (flags & (1 << 0)) - N_MSG(RSP, "[IO] Out of range"); - - N_MSG(RSP, "[IO] State: %s, Data:0x%x", state[(resp >> 12) & 0x3], resp & 0xFF); -} -#endif - static void msdc_set_timeout(struct msdc_host *host, u32 ns, u32 clks) { u32 timeout, clk_ns; @@ -384,9 +244,6 @@ static void msdc_set_timeout(struct msdc_host *host, u32 ns, u32 clks) timeout = timeout > 255 ? 255 : timeout; sdr_set_field(host->base + SDC_CFG, SDC_CFG_DTOC, timeout); - - N_MSG(OPS, "Set read data timeout: %dns %dclks -> %d x 65536 cycles", - ns, clks, timeout + 1); } static void msdc_tasklet_card(struct work_struct *work) @@ -439,7 +296,6 @@ static void msdc_select_clksrc(struct msdc_host *host, unsigned char clksrc) u32 val; BUG_ON(clksrc > 3); - INIT_MSG("set clock source to <%d>", clksrc); val = readl(host->base + MSDC_CLKSRC_REG); if (readl(host->base + MSDC_ECO_VER) >= 4) { @@ -466,7 +322,6 @@ static void msdc_set_mclk(struct msdc_host *host, int ddr, unsigned int hz) //u8 clksrc = hw->clk_src; if (!hz) { // set mmc system clock to 0 ? - //ERR_MSG("set mclk to 0!!!"); msdc_reset_hw(host); return; } @@ -509,10 +364,6 @@ static void msdc_set_mclk(struct msdc_host *host, int ddr, unsigned int hz) host->mclk = hz; msdc_set_timeout(host, host->timeout_ns, host->timeout_clks); // need? - INIT_MSG("================"); - INIT_MSG("!!! Set<%dKHz> Source<%dKHz> -> sclk<%dKHz>", hz / 1000, hclk / 1000, sclk / 1000); - INIT_MSG("================"); - msdc_irq_restore(flags); } @@ -521,7 +372,7 @@ static void msdc_abort_data(struct msdc_host *host) { struct mmc_command *stop = host->mrq->stop; - ERR_MSG("Need to Abort."); + dev_err(mmc_dev(host->mmc), "%d -> Need to Abort.\n", host->id); msdc_reset_hw(host); msdc_clr_fifo(host); @@ -530,7 +381,8 @@ static void msdc_abort_data(struct msdc_host *host) // need to check FIFO count 0 ? if (stop) { /* try to stop, but may not success */ - ERR_MSG("stop when abort CMD<%d>", stop->opcode); + dev_err(mmc_dev(host->mmc), "%d -> stop when abort CMD<%d>\n", + host->id, stop->opcode); (void)msdc_do_command(host, stop, 0, CMD_TIMEOUT); } @@ -579,8 +431,6 @@ static void msdc_pin_config(struct msdc_host *host, int mode) break; } - N_MSG(CFG, "Pins mode(%d), down(%d), up(%d)", - mode, MSDC_PIN_PULL_DOWN, MSDC_PIN_PULL_UP); } void msdc_pin_reset(struct msdc_host *host, int mode) @@ -602,9 +452,6 @@ void msdc_pin_reset(struct msdc_host *host, int mode) static void msdc_core_power(struct msdc_host *host, int on) { - N_MSG(CFG, "Turn %s %s power (copower: %d -> %d)", - on ? "on" : "off", "core", host->core_power, on); - if (on && host->core_power == 0) { msdc_vcore_on(host); host->core_power = 1; @@ -618,8 +465,6 @@ static void msdc_core_power(struct msdc_host *host, int on) static void msdc_host_power(struct msdc_host *host, int on) { - N_MSG(CFG, "Turn %s %s power ", on ? "on" : "off", "host"); - if (on) { //msdc_core_power(host, 1); // need do card detection. msdc_pin_reset(host, MSDC_PIN_PULL_UP); @@ -631,8 +476,6 @@ static void msdc_host_power(struct msdc_host *host, int on) static void msdc_card_power(struct msdc_host *host, int on) { - N_MSG(CFG, "Turn %s %s power ", on ? "on" : "off", "card"); - if (on) { msdc_pin_config(host, MSDC_PIN_PULL_UP); //msdc_vdd_on(host); // need todo card detection. @@ -646,8 +489,6 @@ static void msdc_card_power(struct msdc_host *host, int on) static void msdc_set_power_mode(struct msdc_host *host, u8 mode) { - N_MSG(CFG, "Set power mode(%d)", mode); - if (host->power_mode == MMC_POWER_OFF && mode != MMC_POWER_OFF) { msdc_host_power(host, 1); msdc_card_power(host, 1); @@ -669,12 +510,6 @@ static void msdc_pm(pm_message_t state, void *data) struct msdc_host *host = (struct msdc_host *)data; int evt = state.event; - if (evt == PM_EVENT_USER_RESUME || evt == PM_EVENT_USER_SUSPEND) { - INIT_MSG("USR_%s: suspend<%d> power<%d>", - evt == PM_EVENT_USER_RESUME ? "EVENT_USER_RESUME" : "EVENT_USER_SUSPEND", - host->suspend, host->power_mode); - } - if (evt == PM_EVENT_SUSPEND || evt == PM_EVENT_USER_SUSPEND) { if (host->suspend) /* already suspend */ /* default 0*/ return; @@ -688,13 +523,14 @@ static void msdc_pm(pm_message_t state, void *data) } else if (evt == PM_EVENT_RESUME || evt == PM_EVENT_USER_RESUME) { if (!host->suspend) { - //ERR_MSG("warning: already resume"); return; } /* No PM resume when USR suspend */ if (evt == PM_EVENT_RESUME && host->pm_state.event == PM_EVENT_USER_SUSPEND) { - ERR_MSG("PM Resume when in USR Suspend"); /* won't happen. */ + dev_err(mmc_dev(host->mmc), + "%d -> PM Resume when in USR Suspend\n", + host->id); /* won't happen. */ return; } @@ -802,8 +638,6 @@ static unsigned int msdc_command_start(struct msdc_host *host, rawcmd &= ~(0x0FFF << 16); } - N_MSG(CMD, "CMD<%d><0x%.8x> Arg<0x%.8x>", opcode, rawcmd, cmd->arg); - tmo = jiffies + timeout; if (opcode == MMC_SEND_STATUS) { @@ -812,7 +646,9 @@ static unsigned int msdc_command_start(struct msdc_host *host, break; if (time_after(jiffies, tmo)) { - ERR_MSG("XXX cmd_busy timeout: before CMD<%d>", opcode); + dev_err(mmc_dev(host->mmc), + "%d -> XXX cmd_busy timeout: before CMD<%d>\n", + host->id, opcode); cmd->error = -ETIMEDOUT; msdc_reset_hw(host); goto end; @@ -823,7 +659,9 @@ static unsigned int msdc_command_start(struct msdc_host *host, if (!sdc_is_busy()) break; if (time_after(jiffies, tmo)) { - ERR_MSG("XXX sdc_busy timeout: before CMD<%d>", opcode); + dev_err(mmc_dev(host->mmc), + "%d -> XXX sdc_busy timeout: before CMD<%d>\n", + host->id, opcode); cmd->error = -ETIMEDOUT; msdc_reset_hw(host); goto end; @@ -862,7 +700,9 @@ static unsigned int msdc_command_resp(struct msdc_host *host, spin_unlock(&host->lock); if (!wait_for_completion_timeout(&host->cmd_done, 10 * timeout)) { - ERR_MSG("XXX CMD<%d> wait_for_completion timeout ARG<0x%.8x>", opcode, cmd->arg); + dev_err(mmc_dev(host->mmc), + "%d -> XXX CMD<%d> wait_for_completion timeout ARG<0x%.8x>\n", + host->id, opcode, cmd->arg); cmd->error = -ETIMEDOUT; msdc_reset_hw(host); } @@ -872,40 +712,6 @@ static unsigned int msdc_command_resp(struct msdc_host *host, host->cmd = NULL; //end: -#ifdef MT6575_SD_DEBUG - switch (resp) { - case RESP_NONE: - N_MSG(RSP, "CMD_RSP(%d): %d RSP(%d)", opcode, cmd->error, resp); - break; - case RESP_R2: - N_MSG(RSP, "CMD_RSP(%d): %d RSP(%d)= %.8x %.8x %.8x %.8x", - opcode, cmd->error, resp, cmd->resp[0], cmd->resp[1], - cmd->resp[2], cmd->resp[3]); - break; - default: /* Response types 1, 3, 4, 5, 6, 7(1b) */ - N_MSG(RSP, "CMD_RSP(%d): %d RSP(%d)= 0x%.8x", - opcode, cmd->error, resp, cmd->resp[0]); - if (cmd->error == 0) { - switch (resp) { - case RESP_R1: - case RESP_R1B: - msdc_dump_card_status(host, cmd->resp[0]); - break; - case RESP_R3: - msdc_dump_ocr_reg(host, cmd->resp[0]); - break; - case RESP_R5: - msdc_dump_io_resp(host, cmd->resp[0]); - break; - case RESP_R6: - msdc_dump_rca_resp(host, cmd->resp[0]); - break; - } - } - break; - } -#endif - /* do we need to save card's RCA when SD_SEND_RELATIVE_ADDR */ if (!tune) @@ -947,7 +753,6 @@ static unsigned int msdc_do_command(struct msdc_host *host, end: - N_MSG(CMD, " return<%d> resp<0x%.8x>", cmd->error, cmd->resp[0]); return cmd->error; } @@ -956,8 +761,6 @@ end: static void msdc_dma_resume(struct msdc_host *host) { sdr_set_field(host->base + MSDC_DMA_CTRL, MSDC_DMA_CTRL_RESUME, 1); - - N_MSG(DMA, "DMA resume"); } #endif /* end of --- */ @@ -968,8 +771,6 @@ static void msdc_dma_start(struct msdc_host *host) sdr_set_bits(host->base + MSDC_INTEN, wints); //dsb(); /* --- by chhung */ sdr_set_field(host->base + MSDC_DMA_CTRL, MSDC_DMA_CTRL_START, 1); - - N_MSG(DMA, "DMA start"); } static void msdc_dma_stop(struct msdc_host *host) @@ -977,7 +778,6 @@ static void msdc_dma_stop(struct msdc_host *host) //u32 retries=500; u32 wints = MSDC_INTEN_XFER_COMPL | MSDC_INTEN_DATTMO | MSDC_INTEN_DATCRCERR; - N_MSG(DMA, "DMA status: 0x%.8x", readl(host->base + MSDC_DMA_CFG)); //while (readl(host->base + MSDC_DMA_CFG) & MSDC_DMA_CFG_STS); sdr_set_field(host->base + MSDC_DMA_CTRL, MSDC_DMA_CTRL_STOP, 1); @@ -986,8 +786,6 @@ static void msdc_dma_stop(struct msdc_host *host) //dsb(); /* --- by chhung */ sdr_clr_bits(host->base + MSDC_INTEN, wints); /* Not just xfer_comp */ - - N_MSG(DMA, "DMA stop"); } /* calc checksum */ @@ -1010,8 +808,6 @@ static void msdc_dma_setup(struct msdc_host *host, struct msdc_dma *dma, BUG_ON(sglen > MAX_BD_NUM); /* not support currently */ - N_MSG(DMA, "DMA sglen<%d> xfersz<%d>", sglen, host->xfer_size); - gpd = dma->gpd; bd = dma->bd; @@ -1044,10 +840,6 @@ static void msdc_dma_setup(struct msdc_host *host, struct msdc_dma *dma, sdr_set_field(host->base + MSDC_DMA_CTRL, MSDC_DMA_CTRL_MODE, 1); writel(PHYSADDR((u32)dma->gpd_addr), host->base + MSDC_DMA_SA); - - N_MSG(DMA, "DMA_CTRL = 0x%x", readl(host->base + MSDC_DMA_CTRL)); - N_MSG(DMA, "DMA_CFG = 0x%x", readl(host->base + MSDC_DMA_CFG)); - N_MSG(DMA, "DMA_SA = 0x%x", readl(host->base + MSDC_DMA_SA)); } static int msdc_do_request(struct mmc_host *mmc, struct mmc_request *mrq) @@ -1072,7 +864,6 @@ static int msdc_do_request(struct mmc_host *mmc, struct mmc_request *mrq) #if 0 /* --- by chhung */ //if(host->id ==1){ - N_MSG(OPS, "enable clock!"); msdc_ungate_clock(host->id); //} #endif /* end of --- */ @@ -1125,15 +916,22 @@ static int msdc_do_request(struct mmc_host *mmc, struct mmc_request *mrq) spin_unlock(&host->lock); if (!wait_for_completion_timeout(&host->xfer_done, DAT_TIMEOUT)) { - ERR_MSG("XXX CMD<%d> wait xfer_done<%d> timeout!!", cmd->opcode, data->blocks * data->blksz); - ERR_MSG(" DMA_SA = 0x%x", - readl(host->base + MSDC_DMA_SA)); - ERR_MSG(" DMA_CA = 0x%x", - readl(host->base + MSDC_DMA_CA)); - ERR_MSG(" DMA_CTRL = 0x%x", - readl(host->base + MSDC_DMA_CTRL)); - ERR_MSG(" DMA_CFG = 0x%x", - readl(host->base + MSDC_DMA_CFG)); + dev_err(mmc_dev(host->mmc), + "%d -> XXX CMD<%d> wait xfer_done<%d> timeout!!\n", + host->id, cmd->opcode, + data->blocks * data->blksz); + dev_err(mmc_dev(host->mmc), + "%d -> DMA_SA = 0x%x\n", + host->id, readl(host->base + MSDC_DMA_SA)); + dev_err(mmc_dev(host->mmc), + "%d -> DMA_CA = 0x%x\n", + host->id, readl(host->base + MSDC_DMA_CA)); + dev_err(mmc_dev(host->mmc), + "%d -> DMA_CTRL = 0x%x\n", + host->id, readl(host->base + MSDC_DMA_CTRL)); + dev_err(mmc_dev(host->mmc), + "%d -> DMA_CFG = 0x%x\n", + host->id, readl(host->base + MSDC_DMA_CFG)); data->error = -ETIMEDOUT; msdc_reset_hw(host); @@ -1164,8 +962,6 @@ done: } #endif - N_MSG(OPS, "CMD<%d> data<%s %s> blksz<%d> block<%d> error<%d>", cmd->opcode, (dma ? "dma" : "pio"), - (read ? "read " : "write"), data->blksz, data->blocks, data->error); } #if 0 /* --- by chhung */ @@ -1174,16 +970,13 @@ done: if (send_type == SND_CMD) { if (cmd->opcode == MMC_SEND_STATUS) { if ((cmd->resp[0] & CARD_READY_FOR_DATA) || (CARD_CURRENT_STATE(cmd->resp[0]) != 7)) { - N_MSG(OPS, "disable clock, CMD13 IDLE"); msdc_gate_clock(host->id); } } else { - N_MSG(OPS, "disable clock, CMD<%d>", cmd->opcode); msdc_gate_clock(host->id); } } else { if (read) { - N_MSG(OPS, "disable clock!!! Read CMD<%d>", cmd->opcode); msdc_gate_clock(host->id); } } @@ -1200,8 +993,6 @@ done: if (mrq->stop && mrq->stop->error) host->error |= 0x100; - //if (host->error) ERR_MSG("host->error<%d>", host->error); - return host->error; } @@ -1260,19 +1051,27 @@ static int msdc_tune_cmdrsp(struct msdc_host *host, struct mmc_command *cmd) if (host->app_cmd) { result = msdc_app_cmd(host->mmc, host); if (result) { - ERR_MSG("TUNE_CMD app_cmd<%d> failed: RESP_RXDLY<%d>,R_SMPL<%d>", - host->mrq->cmd->opcode, cur_rrdly, cur_rsmpl); + dev_err(mmc_dev(host->mmc), + "%d -> TUNE_CMD app_cmd<%d> failed: RESP_RXDLY<%d>,R_SMPL<%d>\n", + host->id, + host->mrq->cmd->opcode, + cur_rrdly, cur_rsmpl); continue; } } result = msdc_do_command(host, cmd, 0, CMD_TIMEOUT); // not tune. - ERR_MSG("TUNE_CMD<%d> %s PAD_CMD_RESP_RXDLY[26:22]<%d> R_SMPL[1]<%d>", cmd->opcode, - (result == 0) ? "PASS" : "FAIL", cur_rrdly, cur_rsmpl); + dev_err(mmc_dev(host->mmc), + "%d -> TUNE_CMD<%d> %s PAD_CMD_RESP_RXDLY[26:22]<%d> R_SMPL[1]<%d>\n", + host->id, cmd->opcode, + (result == 0) ? "PASS" : "FAIL", cur_rrdly, + cur_rsmpl); if (result == 0) return 0; if (result != -EIO) { - ERR_MSG("TUNE_CMD<%d> Error<%d> not -EIO", cmd->opcode, result); + dev_err(mmc_dev(host->mmc), + "%d -> TUNE_CMD<%d> Error<%d> not -EIO\n", + host->id, cmd->opcode, result); return result; } @@ -1325,7 +1124,10 @@ static int msdc_tune_bread(struct mmc_host *mmc, struct mmc_request *mrq) if (host->app_cmd) { result = msdc_app_cmd(host->mmc, host); if (result) { - ERR_MSG("TUNE_BREAD app_cmd<%d> failed", host->mrq->cmd->opcode); + dev_err(mmc_dev(host->mmc), + "%d -> TUNE_BREAD app_cmd<%d> failed\n", + host->id, + host->mrq->cmd->opcode); continue; } } @@ -1336,10 +1138,13 @@ static int msdc_tune_bread(struct mmc_host *mmc, struct mmc_request *mrq) &dcrc); /* RO */ if (!ddr) dcrc &= ~SDC_DCRC_STS_NEG; - ERR_MSG("TUNE_BREAD<%s> dcrc<0x%x> DATRDDLY0/1<0x%x><0x%x> dsmpl<0x%x>", - (result == 0 && dcrc == 0) ? "PASS" : "FAIL", dcrc, - readl(host->base + MSDC_DAT_RDDLY0), - readl(host->base + MSDC_DAT_RDDLY1), cur_dsmpl); + dev_err(mmc_dev(host->mmc), + "%d -> TUNE_BREAD<%s> dcrc<0x%x> DATRDDLY0/1<0x%x><0x%x> dsmpl<0x%x>\n", + host->id, + (result == 0 && dcrc == 0) ? "PASS" : "FAIL", + dcrc, readl(host->base + MSDC_DAT_RDDLY0), + readl(host->base + MSDC_DAT_RDDLY1), + cur_dsmpl); /* Fix me: result is 0, but dcrc is still exist */ if (result == 0 && dcrc == 0) { @@ -1348,8 +1153,11 @@ static int msdc_tune_bread(struct mmc_host *mmc, struct mmc_request *mrq) /* there is a case: command timeout, and data phase not processed */ if (mrq->data->error != 0 && mrq->data->error != -EIO) { - ERR_MSG("TUNE_READ: result<0x%x> cmd_error<%d> data_error<%d>", - result, mrq->cmd->error, mrq->data->error); + dev_err(mmc_dev(host->mmc), + "%d -> TUNE_READ: result<0x%x> cmd_error<%d> data_error<%d>\n", + host->id, result, + mrq->cmd->error, + mrq->data->error); goto done; } } @@ -1458,13 +1266,18 @@ static int msdc_tune_bwrite(struct mmc_host *mmc, struct mmc_request *mrq) if (host->app_cmd) { result = msdc_app_cmd(host->mmc, host); if (result) { - ERR_MSG("TUNE_BWRITE app_cmd<%d> failed", host->mrq->cmd->opcode); + dev_err(mmc_dev(host->mmc), + "%d -> TUNE_BWRITE app_cmd<%d> failed\n", + host->id, + host->mrq->cmd->opcode); continue; } } result = msdc_do_request(mmc, mrq); - ERR_MSG("TUNE_BWRITE<%s> DSPL<%d> DATWRDLY<%d> MSDC_DAT_RDDLY0<0x%x>", + dev_err(mmc_dev(host->mmc), + "%d -> TUNE_BWRITE<%s> DSPL<%d> DATWRDLY<%d> MSDC_DAT_RDDLY0<0x%x>\n", + host->id, result == 0 ? "PASS" : "FAIL", cur_dsmpl, cur_wrrdly, cur_rxdly0); @@ -1473,8 +1286,11 @@ static int msdc_tune_bwrite(struct mmc_host *mmc, struct mmc_request *mrq) } else { /* there is a case: command timeout, and data phase not processed */ if (mrq->data->error != -EIO) { - ERR_MSG("TUNE_READ: result<0x%x> cmd_error<%d> data_error<%d>", - result, mrq->cmd->error, mrq->data->error); + dev_err(mmc_dev(host->mmc), + "%d -> TUNE_READ: result<0x%x> cmd_error<%d> data_error<%d>\n", + host->id, result, + mrq->cmd->error, + mrq->data->error); goto done; } } @@ -1508,7 +1324,8 @@ static int msdc_get_card_status(struct mmc_host *mmc, struct msdc_host *host, u3 if (mmc->card) { cmd.arg = mmc->card->rca << 16; } else { - ERR_MSG("cmd13 mmc card is null"); + dev_err(mmc_dev(host->mmc), "%d -> cmd13 mmc card is null\n", + host->id); cmd.arg = host->app_cmd_arg; } cmd.flags = MMC_RSP_SPI_R2 | MMC_RSP_R1 | MMC_CMD_AC; @@ -1535,7 +1352,8 @@ static int msdc_check_busy(struct mmc_host *mmc, struct msdc_host *host) if (err) return err; /* need cmd12? */ - ERR_MSG("cmd<13> resp<0x%x>", status); + dev_err(mmc_dev(host->mmc), "%d -> cmd<13> resp<0x%x>\n", + host->id, status); } while (R1_CURRENT_STATE(status) == 7); return err; @@ -1559,7 +1377,9 @@ static int msdc_tune_request(struct mmc_host *mmc, struct mmc_request *mrq) } else { ret = msdc_check_busy(mmc, host); if (ret) { - ERR_MSG("XXX cmd13 wait program done failed"); + dev_err(mmc_dev(host->mmc), + "%d -> XXX cmd13 wait program done failed\n", + host->id); return ret; } /* CRC and TO */ @@ -1659,8 +1479,6 @@ static void msdc_set_buswidth(struct msdc_host *host, u32 width) } writel(val, host->base + SDC_CFG); - - N_MSG(CFG, "Bus Width = %d", width); } /* ops.set_ios */ @@ -1711,7 +1529,6 @@ static void msdc_ops_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) if (host->mclk != ios->clock) { if (ios->clock > 25000000) { //if (!(host->hw->flags & MSDC_REMOVABLE)) { - INIT_MSG("SD data latch edge<%d>", MSDC_SMPL_FALLING); sdr_set_field(host->base + MSDC_IOCON, MSDC_IOCON_RSPL, MSDC_SMPL_FALLING); sdr_set_field(host->base + MSDC_IOCON, MSDC_IOCON_DSPL, @@ -1764,7 +1581,6 @@ static int msdc_ops_get_cd(struct mmc_host *mmc) return 1; #else host->card_inserted = (host->pm_state.event == PM_EVENT_USER_RESUME) ? 1 : 0; - INIT_MSG("sdio ops_get_cd<%d>", host->card_inserted); return host->card_inserted; #endif } @@ -1788,7 +1604,6 @@ static int msdc_ops_get_cd(struct mmc_host *mmc) present = 0; /* TODO? Check DAT3 pins for card detection */ } - INIT_MSG("ops_get_cd return<%d>", present); return present; } @@ -1906,34 +1721,6 @@ static irqreturn_t msdc_irq(int irq, void *dev_id) printk(KERN_INFO "msdc[%d] MMCIRQ: SDC_CSTS=0x%.8x\r\n", host->id, readl(host->base + SDC_CSTS)); -#ifdef MT6575_SD_DEBUG - { -/* msdc_int_reg *int_reg = (msdc_int_reg*)&intsts;*/ - N_MSG(INT, "IRQ_EVT(0x%x): MMCIRQ(%d) CDSC(%d), ACRDY(%d), ACTMO(%d), ACCRE(%d) AC19DN(%d)", - intsts, - int_reg->mmcirq, - int_reg->cdsc, - int_reg->atocmdrdy, - int_reg->atocmdtmo, - int_reg->atocmdcrc, - int_reg->atocmd19done); - N_MSG(INT, "IRQ_EVT(0x%x): SDIO(%d) CMDRDY(%d), CMDTMO(%d), RSPCRC(%d), CSTA(%d)", - intsts, - int_reg->sdioirq, - int_reg->cmdrdy, - int_reg->cmdtmo, - int_reg->rspcrc, - int_reg->csta); - N_MSG(INT, "IRQ_EVT(0x%x): XFCMP(%d) DXDONE(%d), DATTMO(%d), DATCRC(%d), DMAEMP(%d)", - intsts, - int_reg->xfercomp, - int_reg->dxferdone, - int_reg->dattmo, - int_reg->datcrc, - int_reg->dmaqempty); - } -#endif - return IRQ_HANDLED; } @@ -1958,8 +1745,6 @@ static void msdc_enable_cd_irq(struct msdc_host *host, int enable) return; } - N_MSG(CFG, "CD IRQ Enable(%d)", enable); - if (enable) { /* card detection circuit relies on the core power so that the core power * shouldn't be turned off. Here adds a reference count to keep @@ -2094,8 +1879,6 @@ static void msdc_init_hw(struct msdc_host *host) sdr_set_field(host->base + SDC_CFG, SDC_CFG_DTOC, DEFAULT_DTOC); msdc_set_buswidth(host, MMC_BUS_WIDTH_1); - - N_MSG(FUC, "init hardware done!"); } /* called by msdc_drv_remove */ @@ -2289,7 +2072,8 @@ static int msdc_drv_remove(struct platform_device *pdev) host = mmc_priv(mmc); BUG_ON(!host); - ERR_MSG("removed !!!"); + dev_err(mmc_dev(host->mmc), "%d -> removed !!!\n", + host->id); platform_set_drvdata(pdev, NULL); mmc_remove_host(host->mmc); diff --git a/drivers/staging/mt7621-pci/pci-mt7621.c b/drivers/staging/mt7621-pci/pci-mt7621.c index a49e2795af6b..ba1f117a47ce 100644 --- a/drivers/staging/mt7621-pci/pci-mt7621.c +++ b/drivers/staging/mt7621-pci/pci-mt7621.c @@ -214,7 +214,7 @@ write_config(struct mt7621_pcie *pcie, unsigned int dev, u32 reg, u32 val) pcie_write(pcie, val, RALINK_PCI_CONFIG_DATA); } -void +static void set_pcie_phy(struct mt7621_pcie *pcie, u32 offset, int start_b, int bits, int val) { @@ -225,7 +225,7 @@ set_pcie_phy(struct mt7621_pcie *pcie, u32 offset, pcie_write(pcie, reg, offset); } -void +static void bypass_pipe_rst(struct mt7621_pcie *pcie) { /* PCIe Port 0 */ @@ -239,7 +239,7 @@ bypass_pipe_rst(struct mt7621_pcie *pcie) set_pcie_phy(pcie, (RALINK_PCIEPHY_P2_CTL_OFFSET + 0x02c), 4, 1, 0x01); // rg_pe1_pipe_cmd_frc[4] } -void +static void set_phy_for_ssc(struct mt7621_pcie *pcie) { unsigned long reg = rt_sysc_r32(SYSC_REG_SYSTEM_CONFIG0); @@ -387,15 +387,8 @@ static int mt7621_pcie_parse_dt(struct mt7621_pcie *pcie) struct device *dev = pcie->dev; struct device_node *node = dev->of_node; struct resource regs; - const char *type; int err; - type = of_get_property(node, "device_type", NULL); - if (!type || strcmp(type, "pci") != 0) { - dev_err(dev, "invalid \"device_type\" %s\n", type); - return -EINVAL; - } - err = of_address_to_resource(node, 0, ®s); if (err) { dev_err(dev, "missing \"reg\" property\n"); @@ -500,14 +493,11 @@ static int mt7621_pci_probe(struct platform_device *pdev) bypass_pipe_rst(pcie); set_phy_for_ssc(pcie); - val = read_config(pcie, 0, 0x70c); - printk("Port 0 N_FTS = %x\n", (unsigned int)val); - - val = read_config(pcie, 1, 0x70c); - printk("Port 1 N_FTS = %x\n", (unsigned int)val); - - val = read_config(pcie, 2, 0x70c); - printk("Port 2 N_FTS = %x\n", (unsigned int)val); + list_for_each_entry_safe(port, tmp, &pcie->ports, list) { + u32 slot = port->slot; + val = read_config(pcie, slot, 0x70c); + dev_info(dev, "Port %d N_FTS = %x\n", (unsigned int)val, slot); + } rt_sysc_m32(0, RALINK_PCIE_RST, RALINK_RSTCTRL); rt_sysc_m32(0x30, 2 << 4, SYSC_REG_SYSTEM_CONFIG1); diff --git a/drivers/staging/octeon-usb/octeon-hcd.c b/drivers/staging/octeon-usb/octeon-hcd.c index cff5e790b196..f188e19c6fc1 100644 --- a/drivers/staging/octeon-usb/octeon-hcd.c +++ b/drivers/staging/octeon-usb/octeon-hcd.c @@ -377,29 +377,6 @@ struct octeon_hcd { struct cvmx_usb_tx_fifo nonperiodic; }; -/* This macro spins on a register waiting for it to reach a condition. */ -#define CVMX_WAIT_FOR_FIELD32(address, _union, cond, timeout_usec) \ - ({int result; \ - do { \ - u64 done = cvmx_get_cycle() + (u64)timeout_usec * \ - octeon_get_clock_rate() / 1000000; \ - union _union c; \ - \ - while (1) { \ - c.u32 = cvmx_usb_read_csr32(usb, address); \ - \ - if (cond) { \ - result = 0; \ - break; \ - } else if (cvmx_get_cycle() > done) { \ - result = -1; \ - break; \ - } else \ - __delay(100); \ - } \ - } while (0); \ - result; }) - /* * This macro logically sets a single field in a CSR. It does the sequence * read, modify, and write @@ -593,6 +570,33 @@ static inline int cvmx_usb_get_data_pid(struct cvmx_usb_pipe *pipe) return 0; /* Data0 */ } +/* Loops through register until txfflsh or rxfflsh become zero.*/ +static int cvmx_wait_tx_rx(struct octeon_hcd *usb, int fflsh_type) +{ + int result; + u64 address = CVMX_USBCX_GRSTCTL(usb->index); + u64 done = cvmx_get_cycle() + 100 * + (u64)octeon_get_clock_rate / 1000000; + union cvmx_usbcx_grstctl c; + + while (1) { + c.u32 = cvmx_usb_read_csr32(usb, address); + if (fflsh_type == 0 && c.s.txfflsh == 0) { + result = 0; + break; + } else if (fflsh_type == 1 && c.s.rxfflsh == 0) { + result = 0; + break; + } else if (cvmx_get_cycle() > done) { + result = -1; + break; + } + + __delay(100); + } + return result; +} + static void cvmx_fifo_setup(struct octeon_hcd *usb) { union cvmx_usbcx_ghwcfg3 usbcx_ghwcfg3; @@ -634,12 +638,10 @@ static void cvmx_fifo_setup(struct octeon_hcd *usb) cvmx_usbcx_grstctl, txfnum, 0x10); USB_SET_FIELD32(CVMX_USBCX_GRSTCTL(usb->index), cvmx_usbcx_grstctl, txfflsh, 1); - CVMX_WAIT_FOR_FIELD32(CVMX_USBCX_GRSTCTL(usb->index), - cvmx_usbcx_grstctl, c.s.txfflsh == 0, 100); + cvmx_wait_tx_rx(usb, 0); USB_SET_FIELD32(CVMX_USBCX_GRSTCTL(usb->index), cvmx_usbcx_grstctl, rxfflsh, 1); - CVMX_WAIT_FOR_FIELD32(CVMX_USBCX_GRSTCTL(usb->index), - cvmx_usbcx_grstctl, c.s.rxfflsh == 0, 100); + cvmx_wait_tx_rx(usb, 1); } /** diff --git a/drivers/staging/olpc_dcon/olpc_dcon.c b/drivers/staging/olpc_dcon/olpc_dcon.c index 2744c9f0920e..6b714f740ac3 100644 --- a/drivers/staging/olpc_dcon/olpc_dcon.c +++ b/drivers/staging/olpc_dcon/olpc_dcon.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0 /* * Mainly by David Woodhouse, somewhat modified by Jordan Crouse * @@ -5,10 +6,6 @@ * Copyright © 2006-2007 Advanced Micro Devices, Inc. * Copyright © 2009 VIA Technology, Inc. * Copyright (c) 2010-2011 Andres Salomon <dilinger@queued.net> - * - * This program is free software. You can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt diff --git a/drivers/staging/olpc_dcon/olpc_dcon_xo_1.c b/drivers/staging/olpc_dcon/olpc_dcon_xo_1.c index 633c58ce24ee..ff145d493e1b 100644 --- a/drivers/staging/olpc_dcon/olpc_dcon_xo_1.c +++ b/drivers/staging/olpc_dcon/olpc_dcon_xo_1.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0 /* * Mainly by David Woodhouse, somewhat modified by Jordan Crouse * @@ -5,10 +6,6 @@ * Copyright © 2006-2007 Advanced Micro Devices, Inc. * Copyright © 2009 VIA Technology, Inc. * Copyright (c) 2010 Andres Salomon <dilinger@queued.net> - * - * This program is free software. You can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt diff --git a/drivers/staging/olpc_dcon/olpc_dcon_xo_1_5.c b/drivers/staging/olpc_dcon/olpc_dcon_xo_1_5.c index 64584425b01c..838daa2be3ef 100644 --- a/drivers/staging/olpc_dcon/olpc_dcon_xo_1_5.c +++ b/drivers/staging/olpc_dcon/olpc_dcon_xo_1_5.c @@ -1,9 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0 /* * Copyright (c) 2009,2010 One Laptop per Child - * - * This program is free software. You can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt diff --git a/drivers/staging/pi433/rf69.c b/drivers/staging/pi433/rf69.c index 085272fb393f..4fa6c0237e59 100644 --- a/drivers/staging/pi433/rf69.c +++ b/drivers/staging/pi433/rf69.c @@ -853,7 +853,6 @@ int rf69_write_fifo(struct spi_device *spi, u8 *buffer, unsigned int size) #ifdef DEBUG_FIFO_ACCESS int i; #endif - char spi_address = REG_FIFO | WRITE_BIT; u8 local_buffer[FIFO_SIZE + 1]; if (size > FIFO_SIZE) { @@ -862,7 +861,7 @@ int rf69_write_fifo(struct spi_device *spi, u8 *buffer, unsigned int size) return -EMSGSIZE; } - local_buffer[0] = spi_address; + local_buffer[0] = REG_FIFO | WRITE_BIT; memcpy(&local_buffer[1], buffer, size); #ifdef DEBUG_FIFO_ACCESS diff --git a/drivers/staging/rtl8188eu/TODO b/drivers/staging/rtl8188eu/TODO index 7581e25f231d..5faa0a9bba25 100644 --- a/drivers/staging/rtl8188eu/TODO +++ b/drivers/staging/rtl8188eu/TODO @@ -1,5 +1,5 @@ TODO: -- find and remove remaining code valid only for 5 HGz. Most of the obvious +- find and remove remaining code valid only for 5 GHz. Most of the obvious ones have been removed, but things like channel > 14 still exist. - find and remove any code for other chips that is left over - convert any remaining unusual variable types diff --git a/drivers/staging/rtl8188eu/core/rtw_ap.c b/drivers/staging/rtl8188eu/core/rtw_ap.c index 676d549ef786..e611eda11b5f 100644 --- a/drivers/staging/rtl8188eu/core/rtw_ap.c +++ b/drivers/staging/rtl8188eu/core/rtw_ap.c @@ -36,7 +36,7 @@ void free_mlme_ap_info(struct adapter *padapter) struct sta_priv *pstapriv = &padapter->stapriv; struct mlme_priv *pmlmepriv = &padapter->mlmepriv; struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); + struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; pmlmepriv->update_bcn = false; pmlmeext->bstart_bss = false; diff --git a/drivers/staging/rtl8188eu/core/rtw_cmd.c b/drivers/staging/rtl8188eu/core/rtw_cmd.c index 59039211dad2..42bdbb6a23fe 100644 --- a/drivers/staging/rtl8188eu/core/rtw_cmd.c +++ b/drivers/staging/rtl8188eu/core/rtw_cmd.c @@ -745,7 +745,6 @@ u8 rtw_set_chplan_cmd(struct adapter *padapter, u8 chplan, u8 enqueue) kfree(setChannelPlan_param); } - /* do something based on res... */ if (res == _SUCCESS) padapter->mlmepriv.ChannelPlan = chplan; @@ -1064,13 +1063,13 @@ u8 rtw_chk_hi_queue_cmd(struct adapter *padapter) struct cmd_priv *pcmdpriv = &padapter->cmdpriv; u8 res = _SUCCESS; - ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL); + ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC); if (!ph2c) { res = _FAIL; goto exit; } - pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm), GFP_KERNEL); + pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm), GFP_ATOMIC); if (!pdrvextra_cmd_parm) { kfree(ph2c); res = _FAIL; diff --git a/drivers/staging/rtl8188eu/core/rtw_efuse.c b/drivers/staging/rtl8188eu/core/rtw_efuse.c index 0fd306a808c4..ddd7f67fe5a2 100644 --- a/drivers/staging/rtl8188eu/core/rtw_efuse.c +++ b/drivers/staging/rtl8188eu/core/rtw_efuse.c @@ -86,16 +86,20 @@ efuse_phymap_to_logical(u8 *phymap, u16 _offset, u16 _size_byte, u8 *pbuf) u16 **eFuseWord = NULL; u16 efuse_utilized = 0; u8 u1temp = 0; + void **tmp = NULL; efuseTbl = kzalloc(EFUSE_MAP_LEN_88E, GFP_KERNEL); if (!efuseTbl) return; - eFuseWord = (u16 **)rtw_malloc2d(EFUSE_MAX_SECTION_88E, EFUSE_MAX_WORD_UNIT, sizeof(u16)); - if (!eFuseWord) { + tmp = kzalloc(EFUSE_MAX_SECTION_88E * (sizeof(void *) + EFUSE_MAX_WORD_UNIT * sizeof(u16)), GFP_KERNEL); + if (!tmp) { DBG_88E("%s: alloc eFuseWord fail!\n", __func__); goto eFuseWord_failed; } + for (i = 0; i < EFUSE_MAX_SECTION_88E; i++) + tmp[i] = ((char *)(tmp + EFUSE_MAX_SECTION_88E)) + i * EFUSE_MAX_WORD_UNIT * sizeof(u16); + eFuseWord = (u16 **)tmp; /* 0. Refresh efuse init map as all oxFF. */ for (i = 0; i < EFUSE_MAX_SECTION_88E; i++) diff --git a/drivers/staging/rtl8188eu/core/rtw_ieee80211.c b/drivers/staging/rtl8188eu/core/rtw_ieee80211.c index 7d5cbaf50f1c..9e5c7e62d26f 100644 --- a/drivers/staging/rtl8188eu/core/rtw_ieee80211.c +++ b/drivers/staging/rtl8188eu/core/rtw_ieee80211.c @@ -100,19 +100,13 @@ bool rtw_is_cckratesonly_included(u8 *rate) int rtw_check_network_type(unsigned char *rate, int ratelen, int channel) { - if (channel > 14) { - if (rtw_is_cckrates_included(rate)) - return WIRELESS_INVALID; - else - return WIRELESS_11A; - } else { /* could be pure B, pure G, or B/G */ - if (rtw_is_cckratesonly_included(rate)) - return WIRELESS_11B; - else if (rtw_is_cckrates_included(rate)) - return WIRELESS_11BG; - else - return WIRELESS_11G; - } + /* could be pure B, pure G, or B/G */ + if (rtw_is_cckratesonly_included(rate)) + return WIRELESS_11B; + else if (rtw_is_cckrates_included(rate)) + return WIRELESS_11BG; + else + return WIRELESS_11G; } u8 *rtw_set_fixed_ie(void *pbuf, unsigned int len, void *source, diff --git a/drivers/staging/rtl8188eu/core/rtw_recv.c b/drivers/staging/rtl8188eu/core/rtw_recv.c index 17b4b9257b49..ab9638d618a9 100644 --- a/drivers/staging/rtl8188eu/core/rtw_recv.c +++ b/drivers/staging/rtl8188eu/core/rtw_recv.c @@ -233,7 +233,7 @@ static int recvframe_chkmic(struct adapter *adapter, /* calculate mic code */ if (stainfo) { - if (IS_MCAST(prxattrib->ra)) { + if (is_multicast_ether_addr(prxattrib->ra)) { if (!psecuritypriv) { res = _FAIL; RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, @@ -321,11 +321,11 @@ static int recvframe_chkmic(struct adapter *adapter, /* double check key_index for some timing issue , */ /* cannot compare with psecuritypriv->dot118021XGrpKeyid also cause timing issue */ - if ((IS_MCAST(prxattrib->ra) == true) && (prxattrib->key_index != pmlmeinfo->key_index)) + if (is_multicast_ether_addr(prxattrib->ra) && prxattrib->key_index != pmlmeinfo->key_index) brpt_micerror = false; if ((prxattrib->bdecrypted) && (brpt_micerror)) { - rtw_handle_tkip_mic_err(adapter, (u8)IS_MCAST(prxattrib->ra)); + rtw_handle_tkip_mic_err(adapter, (u8)is_multicast_ether_addr(prxattrib->ra)); RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" mic error :prxattrib->bdecrypted=%d ", prxattrib->bdecrypted)); DBG_88E(" mic error :prxattrib->bdecrypted=%d\n", prxattrib->bdecrypted); } else { @@ -335,7 +335,7 @@ static int recvframe_chkmic(struct adapter *adapter, res = _FAIL; } else { /* mic checked ok */ - if ((!psecuritypriv->bcheck_grpkey) && (IS_MCAST(prxattrib->ra))) { + if (!psecuritypriv->bcheck_grpkey && is_multicast_ether_addr(prxattrib->ra)) { psecuritypriv->bcheck_grpkey = true; RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("psecuritypriv->bcheck_grpkey = true")); } @@ -648,7 +648,7 @@ int sta2sta_data_frame(struct adapter *adapter, struct recv_frame *precv_frame, u8 *mybssid = get_bssid(pmlmepriv); u8 *myhwaddr = myid(&adapter->eeprompriv); u8 *sta_addr = NULL; - int bmcast = IS_MCAST(pattrib->dst); + bool mcast = is_multicast_ether_addr(pattrib->dst); if ((check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == true) || (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true)) { @@ -659,7 +659,7 @@ int sta2sta_data_frame(struct adapter *adapter, struct recv_frame *precv_frame, goto exit; } - if ((memcmp(myhwaddr, pattrib->dst, ETH_ALEN)) && (!bmcast)) { + if (memcmp(myhwaddr, pattrib->dst, ETH_ALEN) && !mcast) { ret = _FAIL; goto exit; } @@ -681,9 +681,9 @@ int sta2sta_data_frame(struct adapter *adapter, struct recv_frame *precv_frame, } sta_addr = pattrib->bssid; } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) { - if (bmcast) { + if (mcast) { /* For AP mode, if DA == MCAST, then BSSID should be also MCAST */ - if (!IS_MCAST(pattrib->bssid)) { + if (!is_multicast_ether_addr(pattrib->bssid)) { ret = _FAIL; goto exit; } @@ -700,7 +700,7 @@ int sta2sta_data_frame(struct adapter *adapter, struct recv_frame *precv_frame, ret = _FAIL; } - if (bmcast) + if (mcast) *psta = rtw_get_bcmc_stainfo(adapter); else *psta = rtw_get_stainfo(pstapriv, sta_addr); /* get ap_info */ @@ -727,7 +727,7 @@ static int ap2sta_data_frame( struct mlme_priv *pmlmepriv = &adapter->mlmepriv; u8 *mybssid = get_bssid(pmlmepriv); u8 *myhwaddr = myid(&adapter->eeprompriv); - int bmcast = IS_MCAST(pattrib->dst); + bool mcast = is_multicast_ether_addr(pattrib->dst); if ((check_fwstate(pmlmepriv, WIFI_STATION_STATE) == true) && (check_fwstate(pmlmepriv, _FW_LINKED) == true || @@ -740,7 +740,7 @@ static int ap2sta_data_frame( } /* da should be for me */ - if ((memcmp(myhwaddr, pattrib->dst, ETH_ALEN)) && (!bmcast)) { + if (memcmp(myhwaddr, pattrib->dst, ETH_ALEN) && !mcast) { RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, (" %s: compare DA fail; DA=%pM\n", __func__, (pattrib->dst))); ret = _FAIL; @@ -755,7 +755,7 @@ static int ap2sta_data_frame( (" %s: compare BSSID fail ; BSSID=%pM\n", __func__, (pattrib->bssid))); RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("mybssid=%pM\n", (mybssid))); - if (!bmcast) { + if (!mcast) { DBG_88E("issue_deauth to the nonassociated ap=%pM for the reason(7)\n", (pattrib->bssid)); issue_deauth(adapter, pattrib->bssid, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA); } @@ -764,7 +764,7 @@ static int ap2sta_data_frame( goto exit; } - if (bmcast) + if (mcast) *psta = rtw_get_bcmc_stainfo(adapter); else *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /* get ap_info */ @@ -789,7 +789,7 @@ static int ap2sta_data_frame( ret = RTW_RX_HANDLED; goto exit; } else { - if (!memcmp(myhwaddr, pattrib->dst, ETH_ALEN) && (!bmcast)) { + if (!memcmp(myhwaddr, pattrib->dst, ETH_ALEN) && !mcast) { *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /* get sta_info */ if (*psta == NULL) { DBG_88E("issue_deauth to the ap =%pM for the reason(7)\n", (pattrib->bssid)); @@ -1129,9 +1129,9 @@ static int validate_recv_data_frame(struct adapter *adapter, if (pattrib->privacy) { RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("%s:pattrib->privacy=%x\n", __func__, pattrib->privacy)); - RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("\n ^^^^^^^^^^^IS_MCAST(pattrib->ra(0x%02x))=%d^^^^^^^^^^^^^^^6\n", pattrib->ra[0], IS_MCAST(pattrib->ra))); + RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("\n ^^^^^^^^^^^is_multicast_ether_addr(pattrib->ra(0x%02x))=%d^^^^^^^^^^^^^^^6\n", pattrib->ra[0], is_multicast_ether_addr(pattrib->ra))); - GET_ENCRY_ALGO(psecuritypriv, psta, pattrib->encrypt, IS_MCAST(pattrib->ra)); + GET_ENCRY_ALGO(psecuritypriv, psta, pattrib->encrypt, is_multicast_ether_addr(pattrib->ra)); RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("\n pattrib->encrypt=%d\n", pattrib->encrypt)); @@ -1971,7 +1971,8 @@ static int recv_func(struct adapter *padapter, struct recv_frame *rframe) if (ret == _SUCCESS) { /* check if need to enqueue into uc_swdec_pending_queue*/ if (check_fwstate(mlmepriv, WIFI_STATION_STATE) && - !IS_MCAST(prxattrib->ra) && prxattrib->encrypt > 0 && + !is_multicast_ether_addr(prxattrib->ra) && + prxattrib->encrypt > 0 && prxattrib->bdecrypted == 0 && !is_wep_enc(psecuritypriv->dot11PrivacyAlgrthm) && !psecuritypriv->busetkipkey) { diff --git a/drivers/staging/rtl8188eu/core/rtw_security.c b/drivers/staging/rtl8188eu/core/rtw_security.c index 2a48b09ea9ae..a2ec0e403718 100644 --- a/drivers/staging/rtl8188eu/core/rtw_security.c +++ b/drivers/staging/rtl8188eu/core/rtw_security.c @@ -608,7 +608,7 @@ u32 rtw_tkip_encrypt(struct adapter *padapter, u8 *pxmitframe) if (stainfo != NULL) { RT_TRACE(_module_rtl871x_security_c_, _drv_err_, ("%s: stainfo!= NULL!!!\n", __func__)); - if (IS_MCAST(pattrib->ra)) + if (is_multicast_ether_addr(pattrib->ra)) prwskey = psecuritypriv->dot118021XGrpKey[psecuritypriv->dot118021XGrpKeyid].skey; else prwskey = &stainfo->dot118021x_UncstKey.skey[0]; @@ -678,7 +678,7 @@ u32 rtw_tkip_decrypt(struct adapter *padapter, u8 *precvframe) if (prxattrib->encrypt == _TKIP_) { stainfo = rtw_get_stainfo(&padapter->stapriv, &prxattrib->ta[0]); if (stainfo) { - if (IS_MCAST(prxattrib->ra)) { + if (is_multicast_ether_addr(prxattrib->ra)) { if (!psecuritypriv->binstallGrpkey) { res = _FAIL; DBG_88E("%s:rx bc/mc packets, but didn't install group key!!!!!!!!!!\n", __func__); @@ -1250,7 +1250,7 @@ u32 rtw_aes_encrypt(struct adapter *padapter, u8 *pxmitframe) if (stainfo) { RT_TRACE(_module_rtl871x_security_c_, _drv_err_, ("%s: stainfo!= NULL!!!\n", __func__)); - if (IS_MCAST(pattrib->ra)) + if (is_multicast_ether_addr(pattrib->ra)) prwskey = psecuritypriv->dot118021XGrpKey[psecuritypriv->dot118021XGrpKeyid].skey; else prwskey = &stainfo->dot118021x_UncstKey.skey[0]; @@ -1296,7 +1296,7 @@ u32 rtw_aes_decrypt(struct adapter *padapter, u8 *precvframe) struct security_priv *psecuritypriv = &padapter->securitypriv; char iv[8], icv[8]; - if (IS_MCAST(prxattrib->ra)) { + if (is_multicast_ether_addr(prxattrib->ra)) { /* in concurrent we should use sw descrypt in group key, so we remove this message */ if (!psecuritypriv->binstallGrpkey) { res = _FAIL; diff --git a/drivers/staging/rtl8188eu/core/rtw_wlan_util.c b/drivers/staging/rtl8188eu/core/rtw_wlan_util.c index b9406583e501..3e0801858737 100644 --- a/drivers/staging/rtl8188eu/core/rtw_wlan_util.c +++ b/drivers/staging/rtl8188eu/core/rtw_wlan_util.c @@ -107,26 +107,20 @@ unsigned char networktype_to_raid(unsigned char network_type) u8 judge_network_type(struct adapter *padapter, unsigned char *rate, int ratelen) { u8 network_type = 0; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); + struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; + struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; - if (pmlmeext->cur_channel > 14) { - if (pmlmeinfo->HT_enable) - network_type = WIRELESS_11_5N; + if (pmlmeinfo->HT_enable) + network_type = WIRELESS_11_24N; - network_type |= WIRELESS_11A; - } else { - if (pmlmeinfo->HT_enable) - network_type = WIRELESS_11_24N; - - if ((cckratesonly_included(rate, ratelen)) == true) - network_type |= WIRELESS_11B; - else if ((cckrates_included(rate, ratelen)) == true) - network_type |= WIRELESS_11BG; - else - network_type |= WIRELESS_11G; - } - return network_type; + if (cckratesonly_included(rate, ratelen)) + network_type |= WIRELESS_11B; + else if (cckrates_included(rate, ratelen)) + network_type |= WIRELESS_11BG; + else + network_type |= WIRELESS_11G; + + return network_type; } static unsigned char ratetbl_val_2wifirate(unsigned char rate) @@ -1419,32 +1413,25 @@ void update_wireless_mode(struct adapter *padapter) { int ratelen, network_type = 0; u32 SIFS_Timer; - struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; - struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); - struct wlan_bssid_ex *cur_network = &(pmlmeinfo->network); - unsigned char *rate = cur_network->SupportedRates; + struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; + struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; + struct wlan_bssid_ex *cur_network = &pmlmeinfo->network; + unsigned char *rate = cur_network->SupportedRates; ratelen = rtw_get_rateset_len(cur_network->SupportedRates); - if ((pmlmeinfo->HT_info_enable) && (pmlmeinfo->HT_caps_enable)) + if (pmlmeinfo->HT_info_enable && pmlmeinfo->HT_caps_enable) pmlmeinfo->HT_enable = 1; - if (pmlmeext->cur_channel > 14) { - if (pmlmeinfo->HT_enable) - network_type = WIRELESS_11_5N; + if (pmlmeinfo->HT_enable) + network_type = WIRELESS_11_24N; - network_type |= WIRELESS_11A; - } else { - if (pmlmeinfo->HT_enable) - network_type = WIRELESS_11_24N; - - if ((cckratesonly_included(rate, ratelen)) == true) - network_type |= WIRELESS_11B; - else if ((cckrates_included(rate, ratelen)) == true) - network_type |= WIRELESS_11BG; - else - network_type |= WIRELESS_11G; - } + if (cckratesonly_included(rate, ratelen)) + network_type |= WIRELESS_11B; + else if (cckrates_included(rate, ratelen)) + network_type |= WIRELESS_11BG; + else + network_type |= WIRELESS_11G; pmlmeext->cur_wireless_mode = network_type & padapter->registrypriv.wireless_mode; diff --git a/drivers/staging/rtl8188eu/core/rtw_xmit.c b/drivers/staging/rtl8188eu/core/rtw_xmit.c index 2130d78e0d9f..fc06a13a6ea1 100644 --- a/drivers/staging/rtl8188eu/core/rtw_xmit.c +++ b/drivers/staging/rtl8188eu/core/rtw_xmit.c @@ -399,7 +399,7 @@ static s32 update_attrib(struct adapter *padapter, struct sk_buff *pkt, struct p struct sta_info *psta = NULL; struct ethhdr etherhdr; - int bmcast; + bool mcast; struct sta_priv *pstapriv = &padapter->stapriv; struct security_priv *psecuritypriv = &padapter->securitypriv; struct mlme_priv *pmlmepriv = &padapter->mlmepriv; @@ -460,10 +460,10 @@ static s32 update_attrib(struct adapter *padapter, struct sk_buff *pkt, struct p if ((pattrib->ether_type == ETH_P_ARP) || (pattrib->ether_type == ETH_P_PAE) || (pattrib->dhcp_pkt == 1)) rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_SPECIAL_PACKET, 1); - bmcast = IS_MCAST(pattrib->ra); + mcast = is_multicast_ether_addr(pattrib->ra); /* get sta_info */ - if (bmcast) { + if (mcast) { psta = rtw_get_bcmc_stainfo(padapter); } else { psta = rtw_get_stainfo(pstapriv, pattrib->ra); @@ -517,7 +517,7 @@ static s32 update_attrib(struct adapter *padapter, struct sk_buff *pkt, struct p goto exit; } } else { - GET_ENCRY_ALGO(psecuritypriv, psta, pattrib->encrypt, bmcast); + GET_ENCRY_ALGO(psecuritypriv, psta, pattrib->encrypt, mcast); switch (psecuritypriv->dot11AuthAlgrthm) { case dot11AuthAlgrthm_Open: @@ -526,7 +526,7 @@ static s32 update_attrib(struct adapter *padapter, struct sk_buff *pkt, struct p pattrib->key_idx = (u8)psecuritypriv->dot11PrivacyKeyIndex; break; case dot11AuthAlgrthm_8021X: - if (bmcast) + if (mcast) pattrib->key_idx = (u8)psecuritypriv->dot118021XGrpKeyid; else pattrib->key_idx = 0; @@ -596,7 +596,6 @@ static s32 xmitframe_addmic(struct adapter *padapter, struct xmit_frame *pxmitfr struct xmit_priv *pxmitpriv = &padapter->xmitpriv; u8 priority[4] = {0x0, 0x0, 0x0, 0x0}; u8 hw_hdr_offset = 0; - int bmcst = IS_MCAST(pattrib->ra); if (pattrib->psta) stainfo = pattrib->psta; @@ -614,7 +613,7 @@ static s32 xmitframe_addmic(struct adapter *padapter, struct xmit_frame *pxmitfr pframe = pxmitframe->buf_addr + hw_hdr_offset; - if (bmcst) { + if (is_multicast_ether_addr(pattrib->ra)) { if (!memcmp(psecuritypriv->dot118021XGrptxmickey[psecuritypriv->dot118021XGrpKeyid].skey, null_key, 16)) return _FAIL; /* start to calculate the mic code */ @@ -743,12 +742,10 @@ s32 rtw_make_wlanhdr(struct adapter *padapter, u8 *hdr, struct pkt_attrib *pattr struct sta_info *psta; - int bmcst = IS_MCAST(pattrib->ra); - if (pattrib->psta) { psta = pattrib->psta; } else { - if (bmcst) + if (is_multicast_ether_addr(pattrib->ra)) psta = rtw_get_bcmc_stainfo(padapter); else psta = rtw_get_stainfo(&padapter->stapriv, pattrib->ra); @@ -914,7 +911,7 @@ s32 rtw_xmitframe_coalesce(struct adapter *padapter, struct sk_buff *pkt, struct struct xmit_priv *pxmitpriv = &padapter->xmitpriv; struct pkt_attrib *pattrib = &pxmitframe->attrib; u8 *pbuf_start; - s32 bmcst = IS_MCAST(pattrib->ra); + bool mcast = is_multicast_ether_addr(pattrib->ra); s32 res = _SUCCESS; size_t remainder = pkt->len - ETH_HLEN; @@ -964,13 +961,13 @@ s32 rtw_xmitframe_coalesce(struct adapter *padapter, struct sk_buff *pkt, struct WEP_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx); break; case _TKIP_: - if (bmcst) + if (mcast) TKIP_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx); else TKIP_IV(pattrib->iv, psta->dot11txpn, 0); break; case _AES_: - if (bmcst) + if (mcast) AES_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx); else AES_IV(pattrib->iv, psta->dot11txpn, 0); @@ -997,7 +994,7 @@ s32 rtw_xmitframe_coalesce(struct adapter *padapter, struct sk_buff *pkt, struct if ((pattrib->icv_len > 0) && (pattrib->bswenc)) mpdu_len -= pattrib->icv_len; - mem_sz = min_t(size_t, bmcst ? pattrib->pktlen : mpdu_len, remainder); + mem_sz = min_t(size_t, mcast ? pattrib->pktlen : mpdu_len, remainder); skb_copy_bits(pkt, pkt->len - remainder, pframe, mem_sz); remainder -= mem_sz; @@ -1010,7 +1007,7 @@ s32 rtw_xmitframe_coalesce(struct adapter *padapter, struct sk_buff *pkt, struct frg_inx++; - if (bmcst || remainder == 0) { + if (mcast || remainder == 0) { pattrib->nr_frags = frg_inx; pattrib->last_txcmdsz = pattrib->hdrlen + pattrib->iv_len + ((pattrib->nr_frags == 1) ? llc_sz : 0) + @@ -1041,7 +1038,7 @@ s32 rtw_xmitframe_coalesce(struct adapter *padapter, struct sk_buff *pkt, struct xmitframe_swencrypt(padapter, pxmitframe); - if (!bmcst) + if (!mcast) update_attrib_vcs_info(padapter, pxmitframe); else pattrib->vcs_mode = NONE_VCS; @@ -1632,7 +1629,7 @@ int xmitframe_enqueue_for_sleeping_sta(struct adapter *padapter, struct xmit_fra struct sta_priv *pstapriv = &padapter->stapriv; struct pkt_attrib *pattrib = &pxmitframe->attrib; struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - int bmcst = IS_MCAST(pattrib->ra); + bool mcast = is_multicast_ether_addr(pattrib->ra); if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == false) return ret; @@ -1646,12 +1643,12 @@ int xmitframe_enqueue_for_sleeping_sta(struct adapter *padapter, struct xmit_fra return ret; if (pattrib->triggered == 1) { - if (bmcst) + if (mcast) pattrib->qsel = 0x11;/* HIQ */ return ret; } - if (bmcst) { + if (mcast) { spin_lock_bh(&psta->sleep_q.lock); if (pstapriv->sta_dz_bitmap) {/* if any one sta is in ps mode */ diff --git a/drivers/staging/rtl8188eu/hal/odm.c b/drivers/staging/rtl8188eu/hal/odm.c index 9d567838a43a..48738f94cf88 100644 --- a/drivers/staging/rtl8188eu/hal/odm.c +++ b/drivers/staging/rtl8188eu/hal/odm.c @@ -768,22 +768,7 @@ u32 ODM_Get_Rate_Bitmap(struct odm_dm_struct *pDM_Odm, u32 macid, u32 ra_mask, u return rate_bitmap; } -/*----------------------------------------------------------------------------- - * Function: odm_RefreshRateAdaptiveMask() - * - * Overview: Update rate table mask according to rssi - * - * Input: NONE - * - * Output: NONE - * - * Return: NONE - * - * Revised History: - * When Who Remark - * 05/27/2009 hpfan Create Version 0. - * - *---------------------------------------------------------------------------*/ +/* Update rate table mask according to rssi */ void odm_RefreshRateAdaptiveMask(struct odm_dm_struct *pDM_Odm) { if (!(pDM_Odm->SupportAbility & ODM_BB_RA_MASK)) diff --git a/drivers/staging/rtl8188eu/include/odm_precomp.h b/drivers/staging/rtl8188eu/include/odm_precomp.h index 658a938df4c1..0cf7f82b805f 100644 --- a/drivers/staging/rtl8188eu/include/odm_precomp.h +++ b/drivers/staging/rtl8188eu/include/odm_precomp.h @@ -29,7 +29,7 @@ #include "hal8188e_rate_adaptive.h" /* for RA,Power training */ #include "rtl8188e_hal.h" -#include "odm_reg.h" +#include "../../rtlwifi/phydm/phydm_reg.h" #include "odm_rtl8188e.h" diff --git a/drivers/staging/rtl8188eu/include/odm_reg.h b/drivers/staging/rtl8188eu/include/odm_reg.h deleted file mode 100644 index b56549ba1256..000000000000 --- a/drivers/staging/rtl8188eu/include/odm_reg.h +++ /dev/null @@ -1,106 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - ******************************************************************************/ -/* */ -/* File Name: odm_reg.h */ -/* */ -/* Description: */ -/* */ -/* This file is for general register definition. */ -/* */ -/* */ -/* */ -#ifndef __HAL_ODM_REG_H__ -#define __HAL_ODM_REG_H__ - -/* */ -/* Register Definition */ -/* */ - -/* MAC REG */ -#define ODM_BB_RESET 0x002 -#define ODM_DUMMY 0x4fe -#define ODM_EDCA_VO_PARAM 0x500 -#define ODM_EDCA_VI_PARAM 0x504 -#define ODM_EDCA_BE_PARAM 0x508 -#define ODM_EDCA_BK_PARAM 0x50C -#define ODM_TXPAUSE 0x522 - -/* BB REG */ -#define ODM_FPGA_PHY0_PAGE8 0x800 -#define ODM_PSD_SETTING 0x808 -#define ODM_AFE_SETTING 0x818 -#define ODM_TXAGC_B_6_18 0x830 -#define ODM_TXAGC_B_24_54 0x834 -#define ODM_TXAGC_B_MCS32_5 0x838 -#define ODM_TXAGC_B_MCS0_MCS3 0x83c -#define ODM_TXAGC_B_MCS4_MCS7 0x848 -#define ODM_TXAGC_B_MCS8_MCS11 0x84c -#define ODM_ANALOG_REGISTER 0x85c -#define ODM_RF_INTERFACE_OUTPUT 0x860 -#define ODM_TXAGC_B_MCS12_MCS15 0x868 -#define ODM_TXAGC_B_11_A_2_11 0x86c -#define ODM_AD_DA_LSB_MASK 0x874 -#define ODM_ENABLE_3_WIRE 0x88c -#define ODM_PSD_REPORT 0x8b4 -#define ODM_R_ANT_SELECT 0x90c -#define ODM_CCK_ANT_SELECT 0xa07 -#define ODM_CCK_PD_THRESH 0xa0a -#define ODM_CCK_RF_REG1 0xa11 -#define ODM_CCK_MATCH_FILTER 0xa20 -#define ODM_CCK_RAKE_MAC 0xa2e -#define ODM_CCK_CNT_RESET 0xa2d -#define ODM_CCK_TX_DIVERSITY 0xa2f -#define ODM_CCK_FA_CNT_MSB 0xa5b -#define ODM_CCK_FA_CNT_LSB 0xa5c -#define ODM_CCK_NEW_FUNCTION 0xa75 -#define ODM_OFDM_PHY0_PAGE_C 0xc00 -#define ODM_OFDM_RX_ANT 0xc04 -#define ODM_R_A_RXIQI 0xc14 -#define ODM_R_A_AGC_CORE1 0xc50 -#define ODM_R_A_AGC_CORE2 0xc54 -#define ODM_R_B_AGC_CORE1 0xc58 -#define ODM_R_AGC_PAR 0xc70 -#define ODM_R_HTSTF_AGC_PAR 0xc7c -#define ODM_TX_PWR_TRAINING_A 0xc90 -#define ODM_TX_PWR_TRAINING_B 0xc98 -#define ODM_OFDM_FA_CNT1 0xcf0 -#define ODM_OFDM_PHY0_PAGE_D 0xd00 -#define ODM_OFDM_FA_CNT2 0xda0 -#define ODM_OFDM_FA_CNT3 0xda4 -#define ODM_OFDM_FA_CNT4 0xda8 -#define ODM_TXAGC_A_6_18 0xe00 -#define ODM_TXAGC_A_24_54 0xe04 -#define ODM_TXAGC_A_1_MCS32 0xe08 -#define ODM_TXAGC_A_MCS0_MCS3 0xe10 -#define ODM_TXAGC_A_MCS4_MCS7 0xe14 -#define ODM_TXAGC_A_MCS8_MCS11 0xe18 -#define ODM_TXAGC_A_MCS12_MCS15 0xe1c - -/* RF REG */ -#define ODM_GAIN_SETTING 0x00 -#define ODM_CHANNEL 0x18 - -/* Ant Detect Reg */ -#define ODM_DPDT 0x300 - -/* PSD Init */ -#define ODM_PSDREG 0x808 - -/* 92D Path Div */ -#define PATHDIV_REG 0xB30 -#define PATHDIV_TRI 0xBA0 - - -/* */ -/* Bitmap Definition */ -/* */ - -#define BIT_FA_RESET BIT(0) - - - -#endif diff --git a/drivers/staging/rtl8188eu/include/osdep_service.h b/drivers/staging/rtl8188eu/include/osdep_service.h index fbcba79a0927..cfe5698fbbb1 100644 --- a/drivers/staging/rtl8188eu/include/osdep_service.h +++ b/drivers/staging/rtl8188eu/include/osdep_service.h @@ -64,8 +64,6 @@ static inline int rtw_netif_queue_stopped(struct net_device *pnetdev) u8 *_rtw_malloc(u32 sz); #define rtw_malloc(sz) _rtw_malloc((sz)) -void *rtw_malloc2d(int h, int w, int size); - void _rtw_init_queue(struct __queue *pqueue); struct rtw_netdev_priv_indicator { diff --git a/drivers/staging/rtl8188eu/include/wifi.h b/drivers/staging/rtl8188eu/include/wifi.h index 259bf2cce2d5..0664d5f30a96 100644 --- a/drivers/staging/rtl8188eu/include/wifi.h +++ b/drivers/staging/rtl8188eu/include/wifi.h @@ -257,14 +257,6 @@ enum WIFI_REG_DOMAIN { #define GetAddr4Ptr(pbuf) ((unsigned char *)((size_t)(pbuf) + 24)) -static inline int IS_MCAST(unsigned char *da) -{ - if ((*da) & 0x01) - return true; - else - return false; -} - static inline unsigned char *get_da(unsigned char *pframe) { unsigned char *da; diff --git a/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c b/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c index bee3c3a7a7a9..4801345a2b57 100644 --- a/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c +++ b/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c @@ -1370,7 +1370,7 @@ static int rtw_wx_get_essid(struct net_device *dev, struct iw_request_info *a, union iwreq_data *wrqu, char *extra) { - u32 len, ret = 0; + u32 len; struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network; @@ -1388,7 +1388,7 @@ static int rtw_wx_get_essid(struct net_device *dev, wrqu->essid.length = len; wrqu->essid.flags = 1; - return ret; + return 0; } static int rtw_wx_set_rate(struct net_device *dev, diff --git a/drivers/staging/rtl8188eu/os_dep/osdep_service.c b/drivers/staging/rtl8188eu/os_dep/osdep_service.c index 78daef6704ac..105f3f21bdea 100644 --- a/drivers/staging/rtl8188eu/os_dep/osdep_service.c +++ b/drivers/staging/rtl8188eu/os_dep/osdep_service.c @@ -18,20 +18,6 @@ u8 *_rtw_malloc(u32 sz) return kmalloc(sz, in_interrupt() ? GFP_ATOMIC : GFP_KERNEL); } -void *rtw_malloc2d(int h, int w, int size) -{ - int j; - void **a = kzalloc(h * sizeof(void *) + h * w * size, GFP_KERNEL); - - if (!a) - goto out; - - for (j = 0; j < h; j++) - a[j] = ((char *)(a + h)) + j * w * size; -out: - return a; -} - void _rtw_init_queue(struct __queue *pqueue) { INIT_LIST_HEAD(&pqueue->queue); diff --git a/drivers/staging/rtl8192e/rtllib_softmac.c b/drivers/staging/rtl8192e/rtllib_softmac.c index 919231fec09c..287d0c11fa38 100644 --- a/drivers/staging/rtl8192e/rtllib_softmac.c +++ b/drivers/staging/rtl8192e/rtllib_softmac.c @@ -1680,19 +1680,19 @@ inline void rtllib_softmac_new_net(struct rtllib_device *ieee, (ssidbroad && !ssidset) || (!ssidbroad && ssidset))) || (!apset && ssidset && ssidbroad && ssidmatch) || (ieee->is_roaming && ssidset && ssidbroad && ssidmatch)) { - /* if the essid is hidden replace it with the - * essid provided by the user. + /* Save the essid so that if it is hidden, it is + * replaced with the essid provided by the user. */ if (!ssidbroad) { - strncpy(tmp_ssid, ieee->current_network.ssid, - IW_ESSID_MAX_SIZE); + memcpy(tmp_ssid, ieee->current_network.ssid, + ieee->current_network.ssid_len); tmp_ssid_len = ieee->current_network.ssid_len; } - memcpy(&ieee->current_network, net, - sizeof(struct rtllib_network)); + memcpy(&ieee->current_network, net, + sizeof(ieee->current_network)); if (!ssidbroad) { - strncpy(ieee->current_network.ssid, tmp_ssid, - IW_ESSID_MAX_SIZE); + memcpy(ieee->current_network.ssid, tmp_ssid, + tmp_ssid_len); ieee->current_network.ssid_len = tmp_ssid_len; } netdev_info(ieee->dev, diff --git a/drivers/staging/rtl8192u/ieee80211/dot11d.c b/drivers/staging/rtl8192u/ieee80211/dot11d.c index 2fb575a2b6ab..130ddfe9868f 100644 --- a/drivers/staging/rtl8192u/ieee80211/dot11d.c +++ b/drivers/staging/rtl8192u/ieee80211/dot11d.c @@ -3,42 +3,42 @@ #include "dot11d.h" -void Dot11d_Init(struct ieee80211_device *ieee) +void rtl8192u_dot11d_init(struct ieee80211_device *ieee) { - struct rt_dot11d_info *pDot11dInfo = GET_DOT11D_INFO(ieee); + struct rt_dot11d_info *dot11d_info = GET_DOT11D_INFO(ieee); - pDot11dInfo->enabled = false; + dot11d_info->dot11d_enabled = false; - pDot11dInfo->state = DOT11D_STATE_NONE; - pDot11dInfo->country_ie_len = 0; - memset(pDot11dInfo->channel_map, 0, MAX_CHANNEL_NUMBER + 1); - memset(pDot11dInfo->max_tx_pwr_dbm_list, 0xFF, MAX_CHANNEL_NUMBER+1); + dot11d_info->state = DOT11D_STATE_NONE; + dot11d_info->country_ie_len = 0; + memset(dot11d_info->channel_map, 0, MAX_CHANNEL_NUMBER + 1); + memset(dot11d_info->max_tx_pwr_dbm_list, 0xFF, MAX_CHANNEL_NUMBER+1); RESET_CIE_WATCHDOG(ieee); - netdev_info(ieee->dev, "Dot11d_Init()\n"); + netdev_info(ieee->dev, "rtl8192u_dot11d_init()\n"); } -EXPORT_SYMBOL(Dot11d_Init); +EXPORT_SYMBOL(rtl8192u_dot11d_init); /* Reset to the state as we are just entering a regulatory domain. */ -void Dot11d_Reset(struct ieee80211_device *ieee) +void dot11d_reset(struct ieee80211_device *ieee) { u32 i; - struct rt_dot11d_info *pDot11dInfo = GET_DOT11D_INFO(ieee); + struct rt_dot11d_info *dot11d_info = GET_DOT11D_INFO(ieee); /* Clear old channel map */ - memset(pDot11dInfo->channel_map, 0, MAX_CHANNEL_NUMBER+1); - memset(pDot11dInfo->max_tx_pwr_dbm_list, 0xFF, MAX_CHANNEL_NUMBER+1); + memset(dot11d_info->channel_map, 0, MAX_CHANNEL_NUMBER+1); + memset(dot11d_info->max_tx_pwr_dbm_list, 0xFF, MAX_CHANNEL_NUMBER+1); /* Set new channel map */ for (i = 1; i <= 11; i++) - (pDot11dInfo->channel_map)[i] = 1; + (dot11d_info->channel_map)[i] = 1; for (i = 12; i <= 14; i++) - (pDot11dInfo->channel_map)[i] = 2; + (dot11d_info->channel_map)[i] = 2; - pDot11dInfo->state = DOT11D_STATE_NONE; - pDot11dInfo->country_ie_len = 0; + dot11d_info->state = DOT11D_STATE_NONE; + dot11d_info->country_ie_len = 0; RESET_CIE_WATCHDOG(ieee); } -EXPORT_SYMBOL(Dot11d_Reset); +EXPORT_SYMBOL(dot11d_reset); /* * Update country IE from Beacon or Probe Resopnse and configure PHY for @@ -49,15 +49,15 @@ EXPORT_SYMBOL(Dot11d_Reset); * 1. IS_DOT11D_ENABLE() is TRUE. * 2. Input IE is an valid one. */ -void Dot11d_UpdateCountryIe(struct ieee80211_device *dev, u8 *pTaddr, +void dot11d_update_country_ie(struct ieee80211_device *dev, u8 *pTaddr, u16 CoutryIeLen, u8 *pCoutryIe) { - struct rt_dot11d_info *pDot11dInfo = GET_DOT11D_INFO(dev); + struct rt_dot11d_info *dot11d_info = GET_DOT11D_INFO(dev); u8 i, j, NumTriples, MaxChnlNum; struct chnl_txpower_triple *pTriple; - memset(pDot11dInfo->channel_map, 0, MAX_CHANNEL_NUMBER+1); - memset(pDot11dInfo->max_tx_pwr_dbm_list, 0xFF, MAX_CHANNEL_NUMBER+1); + memset(dot11d_info->channel_map, 0, MAX_CHANNEL_NUMBER+1); + memset(dot11d_info->max_tx_pwr_dbm_list, 0xFF, MAX_CHANNEL_NUMBER+1); MaxChnlNum = 0; NumTriples = (CoutryIeLen - 3) / 3; /* skip 3-byte country string. */ pTriple = (struct chnl_txpower_triple *)(pCoutryIe + 3); @@ -66,20 +66,20 @@ void Dot11d_UpdateCountryIe(struct ieee80211_device *dev, u8 *pTaddr, /* It is not in a monotonically increasing order, so * stop processing. */ - netdev_err(dev->dev, "Dot11d_UpdateCountryIe(): Invalid country IE, skip it........1\n"); + netdev_err(dev->dev, "dot11d_update_country_ie(): Invalid country IE, skip it........1\n"); return; } if (MAX_CHANNEL_NUMBER < (pTriple->first_channel + pTriple->num_channels)) { /* It is not a valid set of channel id, so stop * processing. */ - netdev_err(dev->dev, "Dot11d_UpdateCountryIe(): Invalid country IE, skip it........2\n"); + netdev_err(dev->dev, "dot11d_update_country_ie(): Invalid country IE, skip it........2\n"); return; } for (j = 0; j < pTriple->num_channels; j++) { - pDot11dInfo->channel_map[pTriple->first_channel + j] = 1; - pDot11dInfo->max_tx_pwr_dbm_list[pTriple->first_channel + j] = pTriple->max_tx_pwr_dbm; + dot11d_info->channel_map[pTriple->first_channel + j] = 1; + dot11d_info->max_tx_pwr_dbm_list[pTriple->first_channel + j] = pTriple->max_tx_pwr_dbm; MaxChnlNum = pTriple->first_channel + j; } @@ -87,90 +87,90 @@ void Dot11d_UpdateCountryIe(struct ieee80211_device *dev, u8 *pTaddr, } netdev_info(dev->dev, "Channel List:"); for (i = 1; i <= MAX_CHANNEL_NUMBER; i++) - if (pDot11dInfo->channel_map[i] > 0) + if (dot11d_info->channel_map[i] > 0) netdev_info(dev->dev, " %d", i); netdev_info(dev->dev, "\n"); UPDATE_CIE_SRC(dev, pTaddr); - pDot11dInfo->country_ie_len = CoutryIeLen; - memcpy(pDot11dInfo->country_ie_buf, pCoutryIe, CoutryIeLen); - pDot11dInfo->state = DOT11D_STATE_LEARNED; + dot11d_info->country_ie_len = CoutryIeLen; + memcpy(dot11d_info->country_ie_buf, pCoutryIe, CoutryIeLen); + dot11d_info->state = DOT11D_STATE_LEARNED; } -EXPORT_SYMBOL(Dot11d_UpdateCountryIe); +EXPORT_SYMBOL(dot11d_update_country_ie); -u8 DOT11D_GetMaxTxPwrInDbm(struct ieee80211_device *dev, u8 Channel) +u8 dot11d_get_max_tx_pwr_in_dbm(struct ieee80211_device *dev, u8 Channel) { - struct rt_dot11d_info *pDot11dInfo = GET_DOT11D_INFO(dev); + struct rt_dot11d_info *dot11d_info = GET_DOT11D_INFO(dev); u8 MaxTxPwrInDbm = 255; if (Channel > MAX_CHANNEL_NUMBER) { - netdev_err(dev->dev, "DOT11D_GetMaxTxPwrInDbm(): Invalid Channel\n"); + netdev_err(dev->dev, "dot11d_get_max_tx_pwr_in_dbm(): Invalid Channel\n"); return MaxTxPwrInDbm; } - if (pDot11dInfo->channel_map[Channel]) - MaxTxPwrInDbm = pDot11dInfo->max_tx_pwr_dbm_list[Channel]; + if (dot11d_info->channel_map[Channel]) + MaxTxPwrInDbm = dot11d_info->max_tx_pwr_dbm_list[Channel]; return MaxTxPwrInDbm; } -EXPORT_SYMBOL(DOT11D_GetMaxTxPwrInDbm); +EXPORT_SYMBOL(dot11d_get_max_tx_pwr_in_dbm); -void DOT11D_ScanComplete(struct ieee80211_device *dev) +void dot11d_scan_complete(struct ieee80211_device *dev) { - struct rt_dot11d_info *pDot11dInfo = GET_DOT11D_INFO(dev); + struct rt_dot11d_info *dot11d_info = GET_DOT11D_INFO(dev); - switch (pDot11dInfo->state) { + switch (dot11d_info->state) { case DOT11D_STATE_LEARNED: - pDot11dInfo->state = DOT11D_STATE_DONE; + dot11d_info->state = DOT11D_STATE_DONE; break; case DOT11D_STATE_DONE: if (GET_CIE_WATCHDOG(dev) == 0) { /* Reset country IE if previous one is gone. */ - Dot11d_Reset(dev); + dot11d_reset(dev); } break; case DOT11D_STATE_NONE: break; } } -EXPORT_SYMBOL(DOT11D_ScanComplete); +EXPORT_SYMBOL(dot11d_scan_complete); -int IsLegalChannel(struct ieee80211_device *dev, u8 channel) +int is_legal_channel(struct ieee80211_device *dev, u8 channel) { - struct rt_dot11d_info *pDot11dInfo = GET_DOT11D_INFO(dev); + struct rt_dot11d_info *dot11d_info = GET_DOT11D_INFO(dev); if (channel > MAX_CHANNEL_NUMBER) { - netdev_err(dev->dev, "IsLegalChannel(): Invalid Channel\n"); + netdev_err(dev->dev, "is_legal_channel(): Invalid Channel\n"); return 0; } - if (pDot11dInfo->channel_map[channel] > 0) + if (dot11d_info->channel_map[channel] > 0) return 1; return 0; } -EXPORT_SYMBOL(IsLegalChannel); +EXPORT_SYMBOL(is_legal_channel); -int ToLegalChannel(struct ieee80211_device *dev, u8 channel) +int to_legal_channel(struct ieee80211_device *dev, u8 channel) { - struct rt_dot11d_info *pDot11dInfo = GET_DOT11D_INFO(dev); + struct rt_dot11d_info *dot11d_info = GET_DOT11D_INFO(dev); u8 default_chn = 0; u32 i = 0; for (i = 1; i <= MAX_CHANNEL_NUMBER; i++) { - if (pDot11dInfo->channel_map[i] > 0) { + if (dot11d_info->channel_map[i] > 0) { default_chn = i; break; } } if (channel > MAX_CHANNEL_NUMBER) { - netdev_err(dev->dev, "IsLegalChannel(): Invalid Channel\n"); + netdev_err(dev->dev, "is_legal_channel(): Invalid Channel\n"); return default_chn; } - if (pDot11dInfo->channel_map[channel] > 0) + if (dot11d_info->channel_map[channel] > 0) return channel; return default_chn; } -EXPORT_SYMBOL(ToLegalChannel); +EXPORT_SYMBOL(to_legal_channel); diff --git a/drivers/staging/rtl8192u/ieee80211/dot11d.h b/drivers/staging/rtl8192u/ieee80211/dot11d.h index 363a6bed18dd..8b485fa18089 100644 --- a/drivers/staging/rtl8192u/ieee80211/dot11d.h +++ b/drivers/staging/rtl8192u/ieee80211/dot11d.h @@ -17,74 +17,41 @@ enum dot11d_state { }; struct rt_dot11d_info { - bool enabled; /* dot11MultiDomainCapabilityEnabled */ - u16 country_ie_len; /* > 0 if country_ie_buf[] contains valid country information element. */ + + /* country_ie_src_addr u16 aligned for comparison and copy */ + u8 country_ie_src_addr[ETH_ALEN]; /* Source AP of the country IE. */ u8 country_ie_buf[MAX_IE_LEN]; - u8 country_ie_src_addr[6]; /* Source AP of the country IE. */ u8 country_ie_watchdog; u8 channel_map[MAX_CHANNEL_NUMBER + 1]; /* !Value 0: Invalid, 1: Valid (active scan), 2: Valid (passive scan) */ u8 max_tx_pwr_dbm_list[MAX_CHANNEL_NUMBER + 1]; enum dot11d_state state; + u8 dot11d_enabled; /* dot11MultiDomainCapabilityEnabled */ }; -#define eqMacAddr(a, b) (((a)[0] == (b)[0] && \ - (a)[1] == (b)[1] && (a)[2] == (b)[2] && (a)[3] == (b)[3] && \ - (a)[4] == (b)[4] && (a)[5] == (b)[5]) ? 1 : 0) -#define cpMacAddr(des, src) ((des)[0] = (src)[0], \ - (des)[1] = (src)[1], (des)[2] = (src)[2], \ - (des)[3] = (src)[3], (des)[4] = (src)[4], \ - (des)[5] = (src)[5]) -#define GET_DOT11D_INFO(__pIeeeDev) ((struct rt_dot11d_info *)((__pIeeeDev)->pDot11dInfo)) - -#define IS_DOT11D_ENABLE(__pIeeeDev) (GET_DOT11D_INFO(__pIeeeDev)->enabled) -#define IS_COUNTRY_IE_VALID(__pIeeeDev) (GET_DOT11D_INFO(__pIeeeDev)->country_ie_len > 0) - -#define IS_EQUAL_CIE_SRC(__pIeeeDev, __pTa) eqMacAddr(GET_DOT11D_INFO(__pIeeeDev)->country_ie_src_addr, __pTa) -#define UPDATE_CIE_SRC(__pIeeeDev, __pTa) cpMacAddr(GET_DOT11D_INFO(__pIeeeDev)->country_ie_src_addr, __pTa) - -#define GET_CIE_WATCHDOG(__pIeeeDev) (GET_DOT11D_INFO(__pIeeeDev)->country_ie_watchdog) -#define RESET_CIE_WATCHDOG(__pIeeeDev) (GET_CIE_WATCHDOG(__pIeeeDev) = 0) -#define UPDATE_CIE_WATCHDOG(__pIeeeDev) (++GET_CIE_WATCHDOG(__pIeeeDev)) - -void -Dot11d_Init( - struct ieee80211_device *dev - ); - -void -Dot11d_Reset( - struct ieee80211_device *dev - ); +#define GET_DOT11D_INFO(ieee_dev) ((struct rt_dot11d_info *)((ieee_dev)->dot11d_info)) -void -Dot11d_UpdateCountryIe( - struct ieee80211_device *dev, - u8 *pTaddr, - u16 CoutryIeLen, - u8 *pCoutryIe - ); +#define IS_DOT11D_ENABLE(ieee_dev) (GET_DOT11D_INFO(ieee_dev)->dot11d_enabled) +#define IS_COUNTRY_IE_VALID(ieee_dev) (GET_DOT11D_INFO(ieee_dev)->country_ie_len > 0) -u8 -DOT11D_GetMaxTxPwrInDbm( - struct ieee80211_device *dev, - u8 Channel - ); +#define IS_EQUAL_CIE_SRC(ieee_dev, addr) ether_addr_equal(GET_DOT11D_INFO(ieee_dev)->country_ie_src_addr, addr) +#define UPDATE_CIE_SRC(ieee_dev, addr) ether_addr_copy(GET_DOT11D_INFO(ieee_dev)->country_ie_src_addr, addr) -void -DOT11D_ScanComplete( - struct ieee80211_device *dev - ); +#define GET_CIE_WATCHDOG(ieee_dev) (GET_DOT11D_INFO(ieee_dev)->country_ie_watchdog) +#define RESET_CIE_WATCHDOG(ieee_dev) (GET_CIE_WATCHDOG(ieee_dev) = 0) +#define UPDATE_CIE_WATCHDOG(ieee_dev) (++GET_CIE_WATCHDOG(ieee_dev)) -int IsLegalChannel( - struct ieee80211_device *dev, - u8 channel -); +void rtl8192u_dot11d_init(struct ieee80211_device *dev); +void dot11d_reset(struct ieee80211_device *dev); +void dot11d_update_country_ie(struct ieee80211_device *dev, + u8 *addr, + u16 coutry_ie_len, + u8 *coutry_ie); +u8 dot11d_get_max_tx_pwr_in_dbm(struct ieee80211_device *dev, u8 channel); +void dot11d_scan_complete(struct ieee80211_device *dev); +int is_legal_channel(struct ieee80211_device *dev, u8 channel); +int to_legal_channel(struct ieee80211_device *dev, u8 channel); -int ToLegalChannel( - struct ieee80211_device *dev, - u8 channel -); #endif /* #ifndef __INC_DOT11D_H */ diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211.h b/drivers/staging/rtl8192u/ieee80211/ieee80211.h index 3cfeac0d7214..b4e7ae60ac1c 100644 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211.h +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211.h @@ -1329,8 +1329,13 @@ typedef enum _erp_t { struct ieee80211_network { /* These entries are used to identify a unique network */ - u8 bssid[ETH_ALEN]; + u8 bssid[ETH_ALEN]; /* u16 aligned! */ u8 channel; + + // CCXv4 S59, MBSSID. + bool bMBssidValid; + u8 MBssid[ETH_ALEN]; /* u16 aligned! */ + u8 MBssidMask; /* Ensure null-terminated for any debug msgs */ u8 ssid[IW_ESSID_MAX_SIZE + 1]; u8 ssid_len; @@ -1341,10 +1346,6 @@ struct ieee80211_network { bool bCkipSupported; bool bCcxRmEnable; u16 CcxRmState[2]; - // CCXv4 S59, MBSSID. - bool bMBssidValid; - u8 MBssidMask; - u8 MBssid[6]; // CCX 2 S38, WLAN Device Version Number element. Annie, 2006-08-20. bool bWithCcxVerNum; u8 BssCcxVerNumber; @@ -1771,7 +1772,7 @@ struct ieee80211_device { /* map of allowed channels. 0 is dummy */ // FIXME: remember to default to a basic channel plan depending of the PHY type - void *pDot11dInfo; + void *dot11d_info; bool bGlobalDomain; int rate; /* current rate */ int basic_rate; @@ -2395,7 +2396,7 @@ void TsInitDelBA(struct ieee80211_device *ieee, void BaSetupTimeOut(struct timer_list *t); void TxBaInactTimeout(struct timer_list *t); void RxBaInactTimeout(struct timer_list *t); -void ResetBaEntry(PBA_RECORD pBA); +void ResetBaEntry(struct ba_record *pBA); //function in TS.c bool GetTs( struct ieee80211_device *ieee, diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c index 28cae82d795c..5147f7c01e31 100644 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c @@ -794,7 +794,7 @@ static u8 parse_subframe(struct sk_buff *skb, } if (rx_stats->bContainHTC) { - LLCOffset += sHTCLng; + LLCOffset += HTCLNG; } // Null packet, don't indicate it to upper layer ChkLength = LLCOffset;/* + (Frame_WEP(frame)!=0 ?Adapter->MgntInfo.SecurityInfo.EncryptionHeadOverhead:0);*/ @@ -1582,7 +1582,7 @@ static inline void ieee80211_extract_country_ie( if (!IS_COUNTRY_IE_VALID(ieee)) { - Dot11d_UpdateCountryIe(ieee, addr2, info_element->len, info_element->data); + dot11d_update_country_ie(ieee, addr2, info_element->len, info_element->data); } } @@ -1944,7 +1944,7 @@ int ieee80211_parse_info_param(struct ieee80211_device *ieee, { network->bMBssidValid = true; network->MBssidMask = 0xff << (network->MBssidMask); - cpMacAddr(network->MBssid, network->bssid); + ether_addr_copy(network->MBssid, network->bssid); network->MBssid[5] &= network->MBssidMask; } else @@ -2439,7 +2439,7 @@ static inline void ieee80211_process_probe_response( // then wireless adapter should do active scan from ch1~11 and // passive scan from ch12~14 - if (!IsLegalChannel(ieee, network->channel)) + if (!is_legal_channel(ieee, network->channel)) goto out; if (ieee->bGlobalDomain) { @@ -2448,7 +2448,7 @@ static inline void ieee80211_process_probe_response( // Case 1: Country code if(IS_COUNTRY_IE_VALID(ieee) ) { - if (!IsLegalChannel(ieee, network->channel)) { + if (!is_legal_channel(ieee, network->channel)) { printk("GetScanInfo(): For Country code, filter probe response at channel(%d).\n", network->channel); goto out; } @@ -2469,7 +2469,7 @@ static inline void ieee80211_process_probe_response( // Case 1: Country code if(IS_COUNTRY_IE_VALID(ieee) ) { - if (!IsLegalChannel(ieee, network->channel)) { + if (!is_legal_channel(ieee, network->channel)) { printk("GetScanInfo(): For Country code, filter beacon at channel(%d).\n",network->channel); goto out; } diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c index 212cc9ccbb96..8635faf84316 100644 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c @@ -464,7 +464,7 @@ out: } else { ieee->sync_scan_hurryup = 0; if (IS_DOT11D_ENABLE(ieee)) - DOT11D_ScanComplete(ieee); + dot11d_scan_complete(ieee); mutex_unlock(&ieee->scan_mutex); } } @@ -504,7 +504,7 @@ static void ieee80211_softmac_scan_wq(struct work_struct *work) return; out: if (IS_DOT11D_ENABLE(ieee)) - DOT11D_ScanComplete(ieee); + dot11d_scan_complete(ieee); ieee->actscanning = false; watchdog = 0; ieee->scanning = 0; @@ -2357,7 +2357,7 @@ void ieee80211_disassociate(struct ieee80211_device *ieee) if (ieee->data_hard_stop) ieee->data_hard_stop(ieee->dev); if (IS_DOT11D_ENABLE(ieee)) - Dot11d_Reset(ieee); + dot11d_reset(ieee); ieee->state = IEEE80211_NOLINK; ieee->is_set_key = false; ieee->link_change(ieee->dev); @@ -2542,8 +2542,8 @@ void ieee80211_softmac_init(struct ieee80211_device *ieee) for (i = 0; i < 5; i++) ieee->seq_ctrl[i] = 0; - ieee->pDot11dInfo = kzalloc(sizeof(struct rt_dot11d_info), GFP_KERNEL); - if (!ieee->pDot11dInfo) + ieee->dot11d_info = kzalloc(sizeof(struct rt_dot11d_info), GFP_KERNEL); + if (!ieee->dot11d_info) IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't alloc memory for DOT11D\n"); //added for AP roaming ieee->LinkDetectInfo.SlotNum = 2; @@ -2603,8 +2603,8 @@ void ieee80211_softmac_init(struct ieee80211_device *ieee) void ieee80211_softmac_free(struct ieee80211_device *ieee) { mutex_lock(&ieee->wx_mutex); - kfree(ieee->pDot11dInfo); - ieee->pDot11dInfo = NULL; + kfree(ieee->dot11d_info); + ieee->dot11d_info = NULL; del_timer_sync(&ieee->associate_timer); cancel_delayed_work(&ieee->associate_retry_wq); diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c index cc4049de975d..024fa2702546 100644 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c @@ -335,14 +335,14 @@ static void ieee80211_tx_query_agg_cap(struct ieee80211_device *ieee, printk("===>can't get TS\n"); return; } - if (!pTxTs->tx_admitted_ba_record.bValid) + if (!pTxTs->tx_admitted_ba_record.valid) { TsStartAddBaProcess(ieee, pTxTs); goto FORCED_AGG_SETTING; } else if (!pTxTs->using_ba) { - if (SN_LESS(pTxTs->tx_admitted_ba_record.BaStartSeqCtrl.field.SeqNum, (pTxTs->tx_cur_seq + 1) % 4096)) + if (SN_LESS(pTxTs->tx_admitted_ba_record.start_seq_ctrl.field.seq_num, (pTxTs->tx_cur_seq + 1) % 4096)) pTxTs->using_ba = true; else goto FORCED_AGG_SETTING; diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c index f2fcdec9bd17..fa59c712c74b 100644 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c @@ -147,13 +147,13 @@ static inline char *rtl819x_translate_scan(struct ieee80211_device *ieee, if (network->mode >= IEEE_N_24G)//add N rate here; { - PHT_CAPABILITY_ELE ht_cap = NULL; + struct ht_capability_ele *ht_cap = NULL; bool is40M = false, isShortGI = false; u8 max_mcs = 0; if (!memcmp(network->bssht.bdHTCapBuf, EWC11NHTCap, 4)) - ht_cap = (PHT_CAPABILITY_ELE)&network->bssht.bdHTCapBuf[4]; + ht_cap = (struct ht_capability_ele *)&network->bssht.bdHTCapBuf[4]; else - ht_cap = (PHT_CAPABILITY_ELE)&network->bssht.bdHTCapBuf[0]; + ht_cap = (struct ht_capability_ele *)&network->bssht.bdHTCapBuf[0]; is40M = (ht_cap->ChlWidth)?1:0; isShortGI = (ht_cap->ChlWidth)? ((ht_cap->ShortGI40Mhz)?1:0): diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_BA.h b/drivers/staging/rtl8192u/ieee80211/rtl819x_BA.h index b6a76aae4832..1a727856ba53 100644 --- a/drivers/staging/rtl8192u/ieee80211/rtl819x_BA.h +++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_BA.h @@ -2,67 +2,53 @@ #ifndef _BATYPE_H_ #define _BATYPE_H_ -#define TOTAL_TXBA_NUM 16 -#define TOTAL_RXBA_NUM 16 +#define BA_SETUP_TIMEOUT 200 -#define BA_SETUP_TIMEOUT 200 -#define BA_INACT_TIMEOUT 60000 +#define BA_POLICY_DELAYED 0 +#define BA_POLICY_IMMEDIATE 1 -#define BA_POLICY_DELAYED 0 -#define BA_POLICY_IMMEDIATE 1 - -#define ADDBA_STATUS_SUCCESS 0 +#define ADDBA_STATUS_SUCCESS 0 #define ADDBA_STATUS_REFUSED 37 #define ADDBA_STATUS_INVALID_PARAM 38 -#define DELBA_REASON_QSTA_LEAVING 36 -#define DELBA_REASON_END_BA 37 -#define DELBA_REASON_UNKNOWN_BA 38 -#define DELBA_REASON_TIMEOUT 39 -/* whether need define BA Action frames here? -struct ieee80211_ADDBA_Req{ - struct ieee80211_header_data header; - u8 category; - u8 -} __attribute__ ((packed)); -*/ -//Is this need?I put here just to make it easier to define structure BA_RECORD //WB -typedef union _SEQUENCE_CONTROL{ - u16 ShortData; +#define DELBA_REASON_END_BA 37 +#define DELBA_REASON_UNKNOWN_BA 38 +#define DELBA_REASON_TIMEOUT 39 + +union sequence_control { + u16 short_data; struct { - u16 FragNum:4; - u16 SeqNum:12; + u16 frag_num:4; + u16 seq_num:12; } field; -} SEQUENCE_CONTROL, *PSEQUENCE_CONTROL; +}; -typedef union _BA_PARAM_SET { - u8 charData[2]; - u16 shortData; +union ba_param_set { + u16 short_data; struct { - u16 AMSDU_Support:1; - u16 BAPolicy:1; - u16 TID:4; - u16 BufferSize:10; + u16 amsdu_support:1; + u16 ba_policy:1; + u16 tid:4; + u16 buffer_size:10; } field; -} BA_PARAM_SET, *PBA_PARAM_SET; +}; -typedef union _DELBA_PARAM_SET { - u8 charData[2]; - u16 shortData; +union delba_param_set { + u16 short_data; struct { - u16 Reserved:11; - u16 Initiator:1; - u16 TID:4; + u16 reserved:11; + u16 initiator:1; + u16 tid:4; } field; -} DELBA_PARAM_SET, *PDELBA_PARAM_SET; - -typedef struct _BA_RECORD { - struct timer_list Timer; - u8 bValid; - u8 DialogToken; - BA_PARAM_SET BaParamSet; - u16 BaTimeoutValue; - SEQUENCE_CONTROL BaStartSeqCtrl; -} BA_RECORD, *PBA_RECORD; +}; + +struct ba_record { + struct timer_list timer; + u8 valid; + u8 dialog_token; + union ba_param_set param_set; + u16 timeout_value; + union sequence_control start_seq_ctrl; +}; #endif //end _BATYPE_H_ diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_BAProc.c b/drivers/staging/rtl8192u/ieee80211/rtl819x_BAProc.c index 01b631c2a180..109445407cec 100644 --- a/drivers/staging/rtl8192u/ieee80211/rtl819x_BAProc.c +++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_BAProc.c @@ -12,26 +12,26 @@ /******************************************************************************************************************** *function: Activate BA entry. And if Time is nozero, start timer. - * input: PBA_RECORD pBA //BA entry to be enabled + * input: struct ba_record *pBA //BA entry to be enabled * u16 Time //indicate time delay. * output: none ********************************************************************************************************************/ -static void ActivateBAEntry(struct ieee80211_device *ieee, PBA_RECORD pBA, u16 Time) +static void ActivateBAEntry(struct ieee80211_device *ieee, struct ba_record *pBA, u16 Time) { - pBA->bValid = true; + pBA->valid = true; if (Time != 0) - mod_timer(&pBA->Timer, jiffies + msecs_to_jiffies(Time)); + mod_timer(&pBA->timer, jiffies + msecs_to_jiffies(Time)); } /******************************************************************************************************************** *function: deactivate BA entry, including its timer. - * input: PBA_RECORD pBA //BA entry to be disabled + * input: struct ba_record *pBA //BA entry to be disabled * output: none ********************************************************************************************************************/ -static void DeActivateBAEntry(struct ieee80211_device *ieee, PBA_RECORD pBA) +static void DeActivateBAEntry(struct ieee80211_device *ieee, struct ba_record *pBA) { - pBA->bValid = false; - del_timer_sync(&pBA->Timer); + pBA->valid = false; + del_timer_sync(&pBA->timer); } /******************************************************************************************************************** *function: deactivete BA entry in Tx Ts, and send DELBA. @@ -42,18 +42,18 @@ static void DeActivateBAEntry(struct ieee80211_device *ieee, PBA_RECORD pBA) ********************************************************************************************************************/ static u8 TxTsDeleteBA(struct ieee80211_device *ieee, struct tx_ts_record *pTxTs) { - PBA_RECORD pAdmittedBa = &pTxTs->tx_admitted_ba_record; //These two BA entries must exist in TS structure - PBA_RECORD pPendingBa = &pTxTs->tx_pending_ba_record; + struct ba_record *pAdmittedBa = &pTxTs->tx_admitted_ba_record; //These two BA entries must exist in TS structure + struct ba_record *pPendingBa = &pTxTs->tx_pending_ba_record; u8 bSendDELBA = false; // Delete pending BA - if (pPendingBa->bValid) { + if (pPendingBa->valid) { DeActivateBAEntry(ieee, pPendingBa); bSendDELBA = true; } // Delete admitted BA - if (pAdmittedBa->bValid) { + if (pAdmittedBa->valid) { DeActivateBAEntry(ieee, pAdmittedBa); bSendDELBA = true; } @@ -70,10 +70,10 @@ static u8 TxTsDeleteBA(struct ieee80211_device *ieee, struct tx_ts_record *pTxTs ********************************************************************************************************************/ static u8 RxTsDeleteBA(struct ieee80211_device *ieee, struct rx_ts_record *pRxTs) { - PBA_RECORD pBa = &pRxTs->rx_admitted_ba_record; + struct ba_record *pBa = &pRxTs->rx_admitted_ba_record; u8 bSendDELBA = false; - if (pBa->bValid) { + if (pBa->valid) { DeActivateBAEntry(ieee, pBa); bSendDELBA = true; } @@ -84,28 +84,28 @@ static u8 RxTsDeleteBA(struct ieee80211_device *ieee, struct rx_ts_record *pRxTs /******************************************************************************************************************** *function: reset BA entry * input: - * PBA_RECORD pBA //entry to be reset + * struct ba_record *pBA //entry to be reset * output: none ********************************************************************************************************************/ -void ResetBaEntry(PBA_RECORD pBA) +void ResetBaEntry(struct ba_record *pBA) { - pBA->bValid = false; - pBA->BaParamSet.shortData = 0; - pBA->BaTimeoutValue = 0; - pBA->DialogToken = 0; - pBA->BaStartSeqCtrl.ShortData = 0; + pBA->valid = false; + pBA->param_set.short_data = 0; + pBA->timeout_value = 0; + pBA->dialog_token = 0; + pBA->start_seq_ctrl.short_data = 0; } //These functions need porting here or not? /******************************************************************************************************************************* *function: construct ADDBAREQ and ADDBARSP frame here together. * input: u8* Dst //ADDBA frame's destination - * PBA_RECORD pBA //BA_RECORD entry which stores the necessary information for BA. + * struct ba_record *pBA //BA_RECORD entry which stores the necessary information for BA. * u16 StatusCode //status code in RSP and I will use it to indicate whether it's RSP or REQ(will I?) * u8 type //indicate whether it's RSP(ACT_ADDBARSP) ow REQ(ACT_ADDBAREQ) * output: none * return: sk_buff* skb //return constructed skb to xmit *******************************************************************************************************************************/ -static struct sk_buff *ieee80211_ADDBA(struct ieee80211_device *ieee, u8 *Dst, PBA_RECORD pBA, u16 StatusCode, u8 type) +static struct sk_buff *ieee80211_ADDBA(struct ieee80211_device *ieee, u8 *Dst, struct ba_record *pBA, u16 StatusCode, u8 type) { struct sk_buff *skb = NULL; struct rtl_80211_hdr_3addr *BAReq = NULL; @@ -140,7 +140,7 @@ static struct sk_buff *ieee80211_ADDBA(struct ieee80211_device *ieee, u8 *Dst, P *tag++ = ACT_CAT_BA; *tag++ = type; // Dialog Token - *tag++ = pBA->DialogToken; + *tag++ = pBA->dialog_token; if (ACT_ADDBARSP == type) { // Status Code @@ -151,16 +151,16 @@ static struct sk_buff *ieee80211_ADDBA(struct ieee80211_device *ieee, u8 *Dst, P } // BA Parameter Set - put_unaligned_le16(pBA->BaParamSet.shortData, tag); + put_unaligned_le16(pBA->param_set.short_data, tag); tag += 2; // BA Timeout Value - put_unaligned_le16(pBA->BaTimeoutValue, tag); + put_unaligned_le16(pBA->timeout_value, tag); tag += 2; if (ACT_ADDBAREQ == type) { // BA Start SeqCtrl - memcpy(tag, (u8 *)&(pBA->BaStartSeqCtrl), 2); + memcpy(tag, (u8 *)&(pBA->start_seq_ctrl), 2); tag += 2; } @@ -173,7 +173,7 @@ static struct sk_buff *ieee80211_ADDBA(struct ieee80211_device *ieee, u8 *Dst, P /******************************************************************************************************************** *function: construct DELBA frame * input: u8* dst //DELBA frame's destination - * PBA_RECORD pBA //BA_RECORD entry which stores the necessary information for BA + * struct ba_record *pBA //BA_RECORD entry which stores the necessary information for BA * enum tr_select TxRxSelect //TX RX direction * u16 ReasonCode //status code. * output: none @@ -182,12 +182,12 @@ static struct sk_buff *ieee80211_ADDBA(struct ieee80211_device *ieee, u8 *Dst, P static struct sk_buff *ieee80211_DELBA( struct ieee80211_device *ieee, u8 *dst, - PBA_RECORD pBA, + struct ba_record *pBA, enum tr_select TxRxSelect, u16 ReasonCode ) { - DELBA_PARAM_SET DelbaParamSet; + union delba_param_set DelbaParamSet; struct sk_buff *skb = NULL; struct rtl_80211_hdr_3addr *Delba = NULL; u8 *tag = NULL; @@ -201,8 +201,8 @@ static struct sk_buff *ieee80211_DELBA( memset(&DelbaParamSet, 0, 2); - DelbaParamSet.field.Initiator = (TxRxSelect == TX_DIR) ? 1 : 0; - DelbaParamSet.field.TID = pBA->BaParamSet.field.TID; + DelbaParamSet.field.initiator = (TxRxSelect == TX_DIR) ? 1 : 0; + DelbaParamSet.field.tid = pBA->param_set.field.tid; skb = dev_alloc_skb(len + sizeof(struct rtl_80211_hdr_3addr)); //need to add something others? FIXME if (!skb) { @@ -226,7 +226,7 @@ static struct sk_buff *ieee80211_DELBA( // DELBA Parameter Set - put_unaligned_le16(DelbaParamSet.shortData, tag); + put_unaligned_le16(DelbaParamSet.short_data, tag); tag += 2; // Reason Code @@ -243,12 +243,12 @@ static struct sk_buff *ieee80211_DELBA( /******************************************************************************************************************** *function: send ADDBAReq frame out * input: u8* dst //ADDBAReq frame's destination - * PBA_RECORD pBA //BA_RECORD entry which stores the necessary information for BA + * struct ba_record *pBA //BA_RECORD entry which stores the necessary information for BA * output: none * notice: If any possible, please hide pBA in ieee. And temporarily use Manage Queue as softmac_mgmt_xmit() usually does ********************************************************************************************************************/ static void ieee80211_send_ADDBAReq(struct ieee80211_device *ieee, - u8 *dst, PBA_RECORD pBA) + u8 *dst, struct ba_record *pBA) { struct sk_buff *skb; skb = ieee80211_ADDBA(ieee, dst, pBA, 0, ACT_ADDBAREQ); //construct ACT_ADDBAREQ frames so set statuscode zero. @@ -266,13 +266,13 @@ static void ieee80211_send_ADDBAReq(struct ieee80211_device *ieee, /******************************************************************************************************************** *function: send ADDBARSP frame out * input: u8* dst //DELBA frame's destination - * PBA_RECORD pBA //BA_RECORD entry which stores the necessary information for BA + * struct ba_record *pBA //BA_RECORD entry which stores the necessary information for BA * u16 StatusCode //RSP StatusCode * output: none * notice: If any possible, please hide pBA in ieee. And temporarily use Manage Queue as softmac_mgmt_xmit() usually does ********************************************************************************************************************/ static void ieee80211_send_ADDBARsp(struct ieee80211_device *ieee, u8 *dst, - PBA_RECORD pBA, u16 StatusCode) + struct ba_record *pBA, u16 StatusCode) { struct sk_buff *skb; skb = ieee80211_ADDBA(ieee, dst, pBA, StatusCode, ACT_ADDBARSP); //construct ACT_ADDBARSP frames @@ -289,7 +289,7 @@ static void ieee80211_send_ADDBARsp(struct ieee80211_device *ieee, u8 *dst, /******************************************************************************************************************** *function: send ADDBARSP frame out * input: u8* dst //DELBA frame's destination - * PBA_RECORD pBA //BA_RECORD entry which stores the necessary information for BA + * struct ba_record *pBA //BA_RECORD entry which stores the necessary information for BA * enum tr_select TxRxSelect //TX or RX * u16 ReasonCode //DEL ReasonCode * output: none @@ -297,7 +297,7 @@ static void ieee80211_send_ADDBARsp(struct ieee80211_device *ieee, u8 *dst, ********************************************************************************************************************/ static void ieee80211_send_DELBA(struct ieee80211_device *ieee, u8 *dst, - PBA_RECORD pBA, enum tr_select TxRxSelect, + struct ba_record *pBA, enum tr_select TxRxSelect, u16 ReasonCode) { struct sk_buff *skb; @@ -321,10 +321,10 @@ int ieee80211_rx_ADDBAReq(struct ieee80211_device *ieee, struct sk_buff *skb) struct rtl_80211_hdr_3addr *req = NULL; u16 rc = 0; u8 *dst = NULL, *pDialogToken = NULL, *tag = NULL; - PBA_RECORD pBA = NULL; - PBA_PARAM_SET pBaParamSet = NULL; + struct ba_record *pBA = NULL; + union ba_param_set *pBaParamSet = NULL; u16 *pBaTimeoutVal = NULL; - PSEQUENCE_CONTROL pBaStartSeqCtrl = NULL; + union sequence_control *pBaStartSeqCtrl = NULL; struct rx_ts_record *pTS = NULL; if (skb->len < sizeof(struct rtl_80211_hdr_3addr) + 9) { @@ -342,9 +342,9 @@ int ieee80211_rx_ADDBAReq(struct ieee80211_device *ieee, struct sk_buff *skb) dst = &req->addr2[0]; tag += sizeof(struct rtl_80211_hdr_3addr); pDialogToken = tag + 2; //category+action - pBaParamSet = (PBA_PARAM_SET)(tag + 3); //+DialogToken + pBaParamSet = (union ba_param_set *)(tag + 3); //+DialogToken pBaTimeoutVal = (u16 *)(tag + 5); - pBaStartSeqCtrl = (PSEQUENCE_CONTROL)(req + 7); + pBaStartSeqCtrl = (union sequence_control *)(req + 7); netdev_info(ieee->dev, "====================>rx ADDBAREQ from :%pM\n", dst); //some other capability is not ready now. @@ -362,7 +362,7 @@ int ieee80211_rx_ADDBAReq(struct ieee80211_device *ieee, struct sk_buff *skb) ieee, (struct ts_common_info **)(&pTS), dst, - (u8)(pBaParamSet->field.TID), + (u8)(pBaParamSet->field.tid), RX_DIR, true)) { rc = ADDBA_STATUS_REFUSED; @@ -371,10 +371,10 @@ int ieee80211_rx_ADDBAReq(struct ieee80211_device *ieee, struct sk_buff *skb) } pBA = &pTS->rx_admitted_ba_record; // To Determine the ADDBA Req content - // We can do much more check here, including BufferSize, AMSDU_Support, Policy, StartSeqCtrl... + // We can do much more check here, including buffer_size, AMSDU_Support, Policy, StartSeqCtrl... // I want to check StartSeqCtrl to make sure when we start aggregation!!! // - if (pBaParamSet->field.BAPolicy == BA_POLICY_DELAYED) { + if (pBaParamSet->field.ba_policy == BA_POLICY_DELAYED) { rc = ADDBA_STATUS_INVALID_PARAM; IEEE80211_DEBUG(IEEE80211_DL_ERR, "BA Policy is not correct in %s()\n", __func__); goto OnADDBAReq_Fail; @@ -382,16 +382,16 @@ int ieee80211_rx_ADDBAReq(struct ieee80211_device *ieee, struct sk_buff *skb) // Admit the ADDBA Request // DeActivateBAEntry(ieee, pBA); - pBA->DialogToken = *pDialogToken; - pBA->BaParamSet = *pBaParamSet; - pBA->BaTimeoutValue = *pBaTimeoutVal; - pBA->BaStartSeqCtrl = *pBaStartSeqCtrl; + pBA->dialog_token = *pDialogToken; + pBA->param_set = *pBaParamSet; + pBA->timeout_value = *pBaTimeoutVal; + pBA->start_seq_ctrl = *pBaStartSeqCtrl; //for half N mode we only aggregate 1 frame if (ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev)) - pBA->BaParamSet.field.BufferSize = 1; + pBA->param_set.field.buffer_size = 1; else - pBA->BaParamSet.field.BufferSize = 32; - ActivateBAEntry(ieee, pBA, pBA->BaTimeoutValue); + pBA->param_set.field.buffer_size = 32; + ActivateBAEntry(ieee, pBA, pBA->timeout_value); ieee80211_send_ADDBARsp(ieee, dst, pBA, ADDBA_STATUS_SUCCESS); // End of procedure. @@ -399,11 +399,11 @@ int ieee80211_rx_ADDBAReq(struct ieee80211_device *ieee, struct sk_buff *skb) OnADDBAReq_Fail: { - BA_RECORD BA; - BA.BaParamSet = *pBaParamSet; - BA.BaTimeoutValue = *pBaTimeoutVal; - BA.DialogToken = *pDialogToken; - BA.BaParamSet.field.BAPolicy = BA_POLICY_IMMEDIATE; + struct ba_record BA; + BA.param_set = *pBaParamSet; + BA.timeout_value = *pBaTimeoutVal; + BA.dialog_token = *pDialogToken; + BA.param_set.field.ba_policy = BA_POLICY_IMMEDIATE; ieee80211_send_ADDBARsp(ieee, dst, &BA, rc); return 0; //we send RSP out. } @@ -419,11 +419,11 @@ OnADDBAReq_Fail: int ieee80211_rx_ADDBARsp(struct ieee80211_device *ieee, struct sk_buff *skb) { struct rtl_80211_hdr_3addr *rsp = NULL; - PBA_RECORD pPendingBA, pAdmittedBA; + struct ba_record *pPendingBA, *pAdmittedBA; struct tx_ts_record *pTS = NULL; u8 *dst = NULL, *pDialogToken = NULL, *tag = NULL; u16 *pStatusCode = NULL, *pBaTimeoutVal = NULL; - PBA_PARAM_SET pBaParamSet = NULL; + union ba_param_set *pBaParamSet = NULL; u16 ReasonCode; if (skb->len < sizeof(struct rtl_80211_hdr_3addr) + 9) { @@ -439,7 +439,7 @@ int ieee80211_rx_ADDBARsp(struct ieee80211_device *ieee, struct sk_buff *skb) tag += sizeof(struct rtl_80211_hdr_3addr); pDialogToken = tag + 2; pStatusCode = (u16 *)(tag + 3); - pBaParamSet = (PBA_PARAM_SET)(tag + 5); + pBaParamSet = (union ba_param_set *)(tag + 5); pBaTimeoutVal = (u16 *)(tag + 7); // Check the capability @@ -461,7 +461,7 @@ int ieee80211_rx_ADDBARsp(struct ieee80211_device *ieee, struct sk_buff *skb) ieee, (struct ts_common_info **)(&pTS), dst, - (u8)(pBaParamSet->field.TID), + (u8)(pBaParamSet->field.tid), TX_DIR, false)) { IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't get TS in %s()\n", __func__); @@ -478,11 +478,11 @@ int ieee80211_rx_ADDBARsp(struct ieee80211_device *ieee, struct sk_buff *skb) // Check if related BA is waiting for setup. // If not, reject by sending DELBA frame. // - if (pAdmittedBA->bValid) { + if (pAdmittedBA->valid) { // Since BA is already setup, we ignore all other ADDBA Response. IEEE80211_DEBUG(IEEE80211_DL_BA, "OnADDBARsp(): Recv ADDBA Rsp. Drop because already admit it! \n"); return -1; - } else if ((!pPendingBA->bValid) || (*pDialogToken != pPendingBA->DialogToken)) { + } else if ((!pPendingBA->valid) || (*pDialogToken != pPendingBA->dialog_token)) { IEEE80211_DEBUG(IEEE80211_DL_ERR, "OnADDBARsp(): Recv ADDBA Rsp. BA invalid, DELBA! \n"); ReasonCode = DELBA_REASON_UNKNOWN_BA; goto OnADDBARsp_Reject; @@ -498,7 +498,7 @@ int ieee80211_rx_ADDBARsp(struct ieee80211_device *ieee, struct sk_buff *skb) // We can compare the value of BA parameter set that Peer returned and Self sent. // If it is OK, then admitted. Or we can send DELBA to cancel BA mechanism. // - if (pBaParamSet->field.BAPolicy == BA_POLICY_DELAYED) { + if (pBaParamSet->field.ba_policy == BA_POLICY_DELAYED) { // Since this is a kind of ADDBA failed, we delay next ADDBA process. pTS->add_ba_req_delayed = true; DeActivateBAEntry(ieee, pAdmittedBA); @@ -510,10 +510,10 @@ int ieee80211_rx_ADDBARsp(struct ieee80211_device *ieee, struct sk_buff *skb) // // Admitted condition // - pAdmittedBA->DialogToken = *pDialogToken; - pAdmittedBA->BaTimeoutValue = *pBaTimeoutVal; - pAdmittedBA->BaStartSeqCtrl = pPendingBA->BaStartSeqCtrl; - pAdmittedBA->BaParamSet = *pBaParamSet; + pAdmittedBA->dialog_token = *pDialogToken; + pAdmittedBA->timeout_value = *pBaTimeoutVal; + pAdmittedBA->start_seq_ctrl = pPendingBA->start_seq_ctrl; + pAdmittedBA->param_set = *pBaParamSet; DeActivateBAEntry(ieee, pAdmittedBA); ActivateBAEntry(ieee, pAdmittedBA, *pBaTimeoutVal); } else { @@ -526,8 +526,8 @@ int ieee80211_rx_ADDBARsp(struct ieee80211_device *ieee, struct sk_buff *skb) OnADDBARsp_Reject: { - BA_RECORD BA; - BA.BaParamSet = *pBaParamSet; + struct ba_record BA; + BA.param_set = *pBaParamSet; ieee80211_send_DELBA(ieee, dst, &BA, TX_DIR, ReasonCode); return 0; } @@ -543,7 +543,7 @@ OnADDBARsp_Reject: int ieee80211_rx_DELBA(struct ieee80211_device *ieee, struct sk_buff *skb) { struct rtl_80211_hdr_3addr *delba = NULL; - PDELBA_PARAM_SET pDelBaParamSet = NULL; + union delba_param_set *pDelBaParamSet = NULL; u8 *dst = NULL; if (skb->len < sizeof(struct rtl_80211_hdr_3addr) + 6) { @@ -563,16 +563,16 @@ int ieee80211_rx_DELBA(struct ieee80211_device *ieee, struct sk_buff *skb) IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA|IEEE80211_DL_BA, skb->data, skb->len); delba = (struct rtl_80211_hdr_3addr *)skb->data; dst = &delba->addr2[0]; - pDelBaParamSet = (PDELBA_PARAM_SET)&delba->payload[2]; + pDelBaParamSet = (union delba_param_set *)&delba->payload[2]; - if (pDelBaParamSet->field.Initiator == 1) { + if (pDelBaParamSet->field.initiator == 1) { struct rx_ts_record *pRxTs; if (!GetTs( ieee, (struct ts_common_info **)&pRxTs, dst, - (u8)pDelBaParamSet->field.TID, + (u8)pDelBaParamSet->field.tid, RX_DIR, false)) { IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't get TS for RXTS in %s()\n", __func__); @@ -587,7 +587,7 @@ int ieee80211_rx_DELBA(struct ieee80211_device *ieee, struct sk_buff *skb) ieee, (struct ts_common_info **)&pTxTs, dst, - (u8)pDelBaParamSet->field.TID, + (u8)pDelBaParamSet->field.tid, TX_DIR, false)) { IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't get TS for TXTS in %s()\n", __func__); @@ -615,22 +615,22 @@ TsInitAddBA( u8 bOverwritePending ) { - PBA_RECORD pBA = &pTS->tx_pending_ba_record; + struct ba_record *pBA = &pTS->tx_pending_ba_record; - if (pBA->bValid && !bOverwritePending) + if (pBA->valid && !bOverwritePending) return; // Set parameters to "Pending" variable set DeActivateBAEntry(ieee, pBA); - pBA->DialogToken++; // DialogToken: Only keep the latest dialog token - pBA->BaParamSet.field.AMSDU_Support = 0; // Do not support A-MSDU with A-MPDU now!! - pBA->BaParamSet.field.BAPolicy = Policy; // Policy: Delayed or Immediate - pBA->BaParamSet.field.TID = pTS->ts_common_info.t_spec.ts_info.uc_tsid; // TID - // BufferSize: This need to be set according to A-MPDU vector - pBA->BaParamSet.field.BufferSize = 32; // BufferSize: This need to be set according to A-MPDU vector - pBA->BaTimeoutValue = 0; // Timeout value: Set 0 to disable Timer - pBA->BaStartSeqCtrl.field.SeqNum = (pTS->tx_cur_seq + 3) % 4096; // Block Ack will start after 3 packets later. + pBA->dialog_token++; // DialogToken: Only keep the latest dialog token + pBA->param_set.field.amsdu_support = 0; // Do not support A-MSDU with A-MPDU now!! + pBA->param_set.field.ba_policy = Policy; // Policy: Delayed or Immediate + pBA->param_set.field.tid = pTS->ts_common_info.t_spec.ts_info.uc_tsid; // TID + // buffer_size: This need to be set according to A-MPDU vector + pBA->param_set.field.buffer_size = 32; // buffer_size: This need to be set according to A-MPDU vector + pBA->timeout_value = 0; // Timeout value: Set 0 to disable Timer + pBA->start_seq_ctrl.field.seq_num = (pTS->tx_cur_seq + 3) % 4096; // Block Ack will start after 3 packets later. ActivateBAEntry(ieee, pBA, BA_SETUP_TIMEOUT); @@ -647,7 +647,7 @@ TsInitDelBA(struct ieee80211_device *ieee, struct ts_common_info *pTsCommonInfo, ieee80211_send_DELBA( ieee, pTsCommonInfo->addr, - (pTxTs->tx_admitted_ba_record.bValid)?(&pTxTs->tx_admitted_ba_record):(&pTxTs->tx_pending_ba_record), + (pTxTs->tx_admitted_ba_record.valid)?(&pTxTs->tx_admitted_ba_record):(&pTxTs->tx_pending_ba_record), TxRxSelect, DELBA_REASON_END_BA); } else if (TxRxSelect == RX_DIR) { @@ -669,16 +669,16 @@ TsInitDelBA(struct ieee80211_device *ieee, struct ts_common_info *pTsCommonInfo, ********************************************************************************************************************/ void BaSetupTimeOut(struct timer_list *t) { - struct tx_ts_record *pTxTs = from_timer(pTxTs, t, tx_pending_ba_record.Timer); + struct tx_ts_record *pTxTs = from_timer(pTxTs, t, tx_pending_ba_record.timer); pTxTs->add_ba_req_in_progress = false; pTxTs->add_ba_req_delayed = true; - pTxTs->tx_pending_ba_record.bValid = false; + pTxTs->tx_pending_ba_record.valid = false; } void TxBaInactTimeout(struct timer_list *t) { - struct tx_ts_record *pTxTs = from_timer(pTxTs, t, tx_admitted_ba_record.Timer); + struct tx_ts_record *pTxTs = from_timer(pTxTs, t, tx_admitted_ba_record.timer); struct ieee80211_device *ieee = container_of(pTxTs, struct ieee80211_device, TxTsRecord[pTxTs->num]); TxTsDeleteBA(ieee, pTxTs); ieee80211_send_DELBA( @@ -691,7 +691,7 @@ void TxBaInactTimeout(struct timer_list *t) void RxBaInactTimeout(struct timer_list *t) { - struct rx_ts_record *pRxTs = from_timer(pRxTs, t, rx_admitted_ba_record.Timer); + struct rx_ts_record *pRxTs = from_timer(pRxTs, t, rx_admitted_ba_record.timer); struct ieee80211_device *ieee = container_of(pRxTs, struct ieee80211_device, RxTsRecord[pRxTs->num]); RxTsDeleteBA(ieee, pRxTs); diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_HT.h b/drivers/staging/rtl8192u/ieee80211/rtl819x_HT.h index 7d54a7cd9514..64d5359cf7e2 100644 --- a/drivers/staging/rtl8192u/ieee80211/rtl819x_HT.h +++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_HT.h @@ -2,40 +2,34 @@ #ifndef _RTL819XU_HTTYPE_H_ #define _RTL819XU_HTTYPE_H_ -//------------------------------------------------------------ -// The HT Capability element is present in beacons, association request, -// reassociation request and probe response frames -//------------------------------------------------------------ - -// -// MIMO Power Save Settings -// -#define MIMO_PS_STATIC 0 - -// -// There should be 128 bits to cover all of the MCS rates. However, since -// 8190 does not support too much rates, one integer is quite enough. -// - -#define sHTCLng 4 +/* + * The HT Capability element is present in beacons, association request, + * reassociation request and probe response frames + */ +/* + * MIMO Power Save Settings + */ +#define MIMO_PS_STATIC 0 -#define HT_SUPPORTED_MCS_1SS_BITMAP 0x000000ff -#define HT_SUPPORTED_MCS_2SS_BITMAP 0x0000ff00 -#define HT_SUPPORTED_MCS_1SS_2SS_BITMAP HT_MCS_1SS_BITMAP|HT_MCS_1SS_2SS_BITMAP +/* + * There should be 128 bits to cover all of the MCS rates. However, since + * 8190 does not support too much rates, one integer is quite enough. + */ +#define HTCLNG 4 -// -// Represent Channel Width in HT Capabilities -// +/* + * Represent Channel Width in HT Capabilities + */ enum ht_channel_width { HT_CHANNEL_WIDTH_20 = 0, HT_CHANNEL_WIDTH_20_40 = 1, }; -// -// Represent Extension Channel Offset in HT Capabilities -// This is available only in 40Mhz mode. -// +/* + * Represent Extension Channel Offset in HT Capabilities + * This is available only in 40Mhz mode. + */ enum ht_extension_chan_offset { HT_EXTCHNL_OFFSET_NO_EXT = 0, HT_EXTCHNL_OFFSET_UPPER = 1, @@ -43,53 +37,7 @@ enum ht_extension_chan_offset { HT_EXTCHNL_OFFSET_LOWER = 3, }; -typedef enum _CHNLOP { - CHNLOP_NONE = 0, // No Action now - CHNLOP_SCAN = 1, // Scan in progress - CHNLOP_SWBW = 2, // Bandwidth switching in progress - CHNLOP_SWCHNL = 3, // Software Channel switching in progress -} CHNLOP, *PCHNLOP; - -// Determine if the Channel Operation is in progress -#define CHHLOP_IN_PROGRESS(_pHTInfo) \ - ((_pHTInfo)->ChnlOp > CHNLOP_NONE) ? TRUE : FALSE - -/* -typedef union _HT_CAPABILITY{ - u16 ShortData; - u8 CharData[2]; - struct - { - u16 AdvCoding:1; - u16 ChlWidth:1; - u16 MimoPwrSave:2; - u16 GreenField:1; - u16 ShortGI20Mhz:1; - u16 ShortGI40Mhz:1; - u16 STBC:1; - u16 BeamForm:1; - u16 DelayBA:1; - u16 MaxAMSDUSize:1; - u16 DssCCk:1; - u16 PSMP:1; - u16 Rsvd:3; - }Field; -}HT_CAPABILITY, *PHT_CAPABILITY; - -typedef union _HT_CAPABILITY_MACPARA{ - u8 ShortData; - u8 CharData[1]; - struct - { - u8 MaxRxAMPDU:2; - u8 MPDUDensity:2; - u8 Rsvd:4; - }Field; -}HT_CAPABILITY_MACPARA, *PHT_CAPABILITY_MACPARA; -*/ - -typedef struct _HT_CAPABILITY_ELE { - +struct ht_capability_ele { //HT capability info u8 AdvCoding:1; u8 ChlWidth:1; @@ -114,7 +62,6 @@ typedef struct _HT_CAPABILITY_ELE { //Supported MCS set u8 MCS[16]; - //Extended HT Capability Info u16 ExtHTCapInfo; @@ -124,13 +71,12 @@ typedef struct _HT_CAPABILITY_ELE { //Antenna Selection Capabilities u8 ASCap; -} __attribute__ ((packed)) HT_CAPABILITY_ELE, *PHT_CAPABILITY_ELE; - -//------------------------------------------------------------ -// The HT Information element is present in beacons -// Only AP is required to include this element -//------------------------------------------------------------ +} __packed; +/* + * The HT Information element is present in beacons + * Only AP is required to include this element + */ typedef struct _HT_INFORMATION_ELE { u8 ControlChl; @@ -169,12 +115,11 @@ typedef enum _HT_AGGRE_MODE_E { HT_AGG_FORCE_DISABLE = 2, }HT_AGGRE_MODE_E, *PHT_AGGRE_MODE_E; -//------------------------------------------------------------ -// The Data structure is used to keep HT related variables when card is -// configured as non-AP STA mode. **Note** Current_xxx should be set -// to default value in HTInitializeHTInfo() -//------------------------------------------------------------ - +/* + * The Data structure is used to keep HT related variables when card is + * configured as non-AP STA mode. **Note** Current_xxx should be set + * to default value in HTInitializeHTInfo() + */ typedef struct _RT_HIGH_THROUGHPUT { u8 bEnableHT; u8 bCurrentHTSupport; @@ -194,23 +139,20 @@ typedef struct _RT_HIGH_THROUGHPUT { // 802.11n spec version for "peer" HT_SPEC_VER ePeerHTSpecVer; - // HT related information for "Self" - HT_CAPABILITY_ELE SelfHTCap; // This is HT cap element sent to peer STA, which also indicate HT Rx capabilities. + struct ht_capability_ele SelfHTCap; // This is HT cap element sent to peer STA, which also indicate HT Rx capabilities. HT_INFORMATION_ELE SelfHTInfo; // This is HT info element sent to peer STA, which also indicate HT Rx capabilities. // HT related information for "Peer" u8 PeerHTCapBuf[32]; u8 PeerHTInfoBuf[32]; - // A-MSDU related u8 bAMSDU_Support; // This indicates Tx A-MSDU capability u16 nAMSDU_MaxSize; // This indicates Tx A-MSDU capability u8 bCurrent_AMSDU_Support; // This indicates Tx A-MSDU capability u16 nCurrent_AMSDU_MaxSize; // This indicates Tx A-MSDU capability - // AMPDU related <2006.08.10 Emily> u8 bAMPDUEnable; // This indicate Tx A-MPDU capability u8 bCurrentAMPDUEnable; // This indicate Tx A-MPDU capability @@ -243,7 +185,6 @@ typedef struct _RT_HIGH_THROUGHPUT { // For Bandwidth Switching u8 bSwBwInProgress; - CHNLOP ChnlOp; // software switching channel in progress. By Bruce, 2008-02-15. u8 SwBwStep; //struct timer_list SwBwTimer; //moved to ieee80211_device. as timer_list need include some header file here. @@ -278,13 +219,11 @@ typedef struct _RT_HIGH_THROUGHPUT { u32 IOTAction; } __attribute__ ((packed)) RT_HIGH_THROUGHPUT, *PRT_HIGH_THROUGHPUT; -//------------------------------------------------------------ -// The Data structure is used to keep HT related variable for "each AP" -// when card is configured as "STA mode" -//------------------------------------------------------------ - +/* + * The Data structure is used to keep HT related variable for "each AP" + * when card is configured as "STA mode" + */ typedef struct _BSS_HT { - u8 bdSupportHT; // HT related elements @@ -294,7 +233,7 @@ typedef struct _BSS_HT { u16 bdHTInfoLen; HT_SPEC_VER bdHTSpecVer; - //HT_CAPABILITY_ELE bdHTCapEle; + //struct ht_capability_ele bdHTCapEle; //HT_INFORMATION_ELE bdHTInfoEle; u8 bdRT2RTAggregation; @@ -304,27 +243,27 @@ typedef struct _BSS_HT { extern u8 MCS_FILTER_ALL[16]; extern u8 MCS_FILTER_1SS[16]; -/* 2007/07/11 MH Modify the macro. Becaus STA may link with a N-AP. If we set - STA in A/B/G mode and AP is still in N mode. The macro will be wrong. We have - to add a macro to judge wireless mode. */ +/* + * 2007/07/11 MH Modify the macro. Becaus STA may link with a N-AP. If we set + * STA in A/B/G mode and AP is still in N mode. The macro will be wrong. We have + * to add a macro to judge wireless mode. + */ #define PICK_RATE(_nLegacyRate, _nMcsRate) \ - (_nMcsRate==0)?(_nLegacyRate&0x7f):(_nMcsRate) + (_nMcsRate == 0) ? (_nLegacyRate & 0x7f) : (_nMcsRate) /* 2007/07/12 MH We only define legacy and HT wireless mode now. */ #define LEGACY_WIRELESS_MODE IEEE_MODE_MASK #define CURRENT_RATE(WirelessMode, LegacyRate, HTRate) \ - ((WirelessMode & (LEGACY_WIRELESS_MODE))!=0)?\ - (LegacyRate):\ + ((WirelessMode & (LEGACY_WIRELESS_MODE)) != 0) ?\ + (LegacyRate) :\ (PICK_RATE(LegacyRate, HTRate)) - - // MCS Bw 40 {1~7, 12~15,32} #define RATE_ADPT_1SS_MASK 0xFF #define RATE_ADPT_2SS_MASK 0xF0 //Skip MCS8~11 because mcs7 > mcs6, 9, 10, 11. 2007.01.16 by Emily #define RATE_ADPT_MCS32_MASK 0x01 -#define IS_11N_MCS_RATE(rate) (rate&0x80) +#define IS_11N_MCS_RATE(rate) (rate & 0x80) typedef enum _HT_AGGRE_SIZE { HT_AGG_SIZE_8K = 0, @@ -341,13 +280,13 @@ typedef enum _HT_IOT_PEER HT_IOT_PEER_BROADCOM = 2, HT_IOT_PEER_RALINK = 3, HT_IOT_PEER_ATHEROS = 4, - HT_IOT_PEER_CISCO= 5, + HT_IOT_PEER_CISCO = 5, HT_IOT_PEER_MAX = 6 }HT_IOT_PEER_E, *PHTIOT_PEER_E; -// -// IOT Action for different AP -// +/* + * IOT Action for different AP + */ typedef enum _HT_IOT_ACTION { HT_IOT_ACT_TX_USE_AMSDU_4K = 0x00000001, HT_IOT_ACT_TX_USE_AMSDU_8K = 0x00000002, diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c b/drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c index b948eae5909d..9bf52cebe4cd 100644 --- a/drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c +++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c @@ -130,15 +130,15 @@ void HTUpdateDefaultSetting(struct ieee80211_device *ieee) */ void HTDebugHTCapability(u8 *CapIE, u8 *TitleString) { - static u8 EWC11NHTCap[] = {0x00, 0x90, 0x4c, 0x33}; // For 11n EWC definition, 2007.07.17, by Emily - PHT_CAPABILITY_ELE pCapELE; + static u8 EWC11NHTCap[] = {0x00, 0x90, 0x4c, 0x33}; // For 11n EWC definition, 2007.07.17, by Emily + struct ht_capability_ele *pCapELE; if (!memcmp(CapIE, EWC11NHTCap, sizeof(EWC11NHTCap))) { //EWC IE IEEE80211_DEBUG(IEEE80211_DL_HT, "EWC IE in %s()\n", __func__); - pCapELE = (PHT_CAPABILITY_ELE)(&CapIE[4]); + pCapELE = (struct ht_capability_ele *)(&CapIE[4]); } else { - pCapELE = (PHT_CAPABILITY_ELE)(&CapIE[0]); + pCapELE = (struct ht_capability_ele *)(&CapIE[0]); } IEEE80211_DEBUG(IEEE80211_DL_HT, "<Log HT Capability>. Called by %s\n", TitleString); @@ -230,7 +230,7 @@ static bool IsHTHalfNmode40Bandwidth(struct ieee80211_device *ieee) retValue = false; else if (!ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev)) // station in half n mode retValue = false; - else if (((PHT_CAPABILITY_ELE)(pHTInfo->PeerHTCapBuf))->ChlWidth) // ap support 40 bw + else if (((struct ht_capability_ele *)(pHTInfo->PeerHTCapBuf))->ChlWidth) // ap support 40 bw retValue = true; else retValue = false; @@ -248,12 +248,12 @@ static bool IsHTHalfNmodeSGI(struct ieee80211_device *ieee, bool is40MHz) else if (!ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev)) // station in half n mode retValue = false; else if (is40MHz) { // ap support 40 bw - if (((PHT_CAPABILITY_ELE)(pHTInfo->PeerHTCapBuf))->ShortGI40Mhz) // ap support 40 bw short GI + if (((struct ht_capability_ele *)(pHTInfo->PeerHTCapBuf))->ShortGI40Mhz) // ap support 40 bw short GI retValue = true; else retValue = false; } else { - if (((PHT_CAPABILITY_ELE)(pHTInfo->PeerHTCapBuf))->ShortGI20Mhz) // ap support 40 bw short GI + if (((struct ht_capability_ele *)(pHTInfo->PeerHTCapBuf))->ShortGI20Mhz) // ap support 40 bw short GI retValue = true; else retValue = false; @@ -530,7 +530,7 @@ void HTResetIOTSetting(PRT_HIGH_THROUGHPUT pHTInfo) void HTConstructCapabilityElement(struct ieee80211_device *ieee, u8 *posHTCap, u8 *len, u8 IsEncrypt) { PRT_HIGH_THROUGHPUT pHT = ieee->pHTInfo; - PHT_CAPABILITY_ELE pCapELE = NULL; + struct ht_capability_ele *pCapELE = NULL; //u8 bIsDeclareMCS13; if (!posHTCap || !pHT) { @@ -544,9 +544,9 @@ void HTConstructCapabilityElement(struct ieee80211_device *ieee, u8 *posHTCap, u u8 EWC11NHTCap[] = {0x00, 0x90, 0x4c, 0x33}; // For 11n EWC definition, 2007.07.17, by Emily memcpy(posHTCap, EWC11NHTCap, sizeof(EWC11NHTCap)); - pCapELE = (PHT_CAPABILITY_ELE)&posHTCap[4]; + pCapELE = (struct ht_capability_ele *)&posHTCap[4]; } else { - pCapELE = (PHT_CAPABILITY_ELE)posHTCap; + pCapELE = (struct ht_capability_ele *)posHTCap; } //HT capability info @@ -898,7 +898,7 @@ void HTSetConnectBwMode(struct ieee80211_device *ieee, enum ht_channel_width Ban void HTOnAssocRsp(struct ieee80211_device *ieee) { PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo; - PHT_CAPABILITY_ELE pPeerHTCap = NULL; + struct ht_capability_ele *pPeerHTCap = NULL; PHT_INFORMATION_ELE pPeerHTInfo = NULL; u16 nMaxAMSDUSize = 0; u8 *pMcsFilter = NULL; @@ -913,16 +913,16 @@ void HTOnAssocRsp(struct ieee80211_device *ieee) return; } IEEE80211_DEBUG(IEEE80211_DL_HT, "===> HTOnAssocRsp_wq(): HT_ENABLE\n"); -// IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, pHTInfo->PeerHTCapBuf, sizeof(HT_CAPABILITY_ELE)); +// IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, pHTInfo->PeerHTCapBuf, sizeof(struct ht_capability_ele)); // IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, pHTInfo->PeerHTInfoBuf, sizeof(HT_INFORMATION_ELE)); // HTDebugHTCapability(pHTInfo->PeerHTCapBuf,"HTOnAssocRsp_wq"); // HTDebugHTInfo(pHTInfo->PeerHTInfoBuf,"HTOnAssocRsp_wq"); // if (!memcmp(pHTInfo->PeerHTCapBuf, EWC11NHTCap, sizeof(EWC11NHTCap))) - pPeerHTCap = (PHT_CAPABILITY_ELE)(&pHTInfo->PeerHTCapBuf[4]); + pPeerHTCap = (struct ht_capability_ele *)(&pHTInfo->PeerHTCapBuf[4]); else - pPeerHTCap = (PHT_CAPABILITY_ELE)(pHTInfo->PeerHTCapBuf); + pPeerHTCap = (struct ht_capability_ele *)(pHTInfo->PeerHTCapBuf); if (!memcmp(pHTInfo->PeerHTInfoBuf, EWC11NHTInfo, sizeof(EWC11NHTInfo))) pPeerHTInfo = (PHT_INFORMATION_ELE)(&pHTInfo->PeerHTInfoBuf[4]); @@ -932,7 +932,7 @@ void HTOnAssocRsp(struct ieee80211_device *ieee) //////////////////////////////////////////////////////// // Configurations: //////////////////////////////////////////////////////// - IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA | IEEE80211_DL_HT, pPeerHTCap, sizeof(HT_CAPABILITY_ELE)); + IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA | IEEE80211_DL_HT, pPeerHTCap, sizeof(struct ht_capability_ele)); // IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA|IEEE80211_DL_HT, pPeerHTInfo, sizeof(HT_INFORMATION_ELE)); // Config Supported Channel Width setting // @@ -1122,7 +1122,6 @@ void HTInitializeHTInfo(struct ieee80211_device *ieee) memset(&pHTInfo->PeerHTInfoBuf, 0, sizeof(pHTInfo->PeerHTInfoBuf)); pHTInfo->bSwBwInProgress = false; - pHTInfo->ChnlOp = CHNLOP_NONE; // Set default IEEE spec for Draft N pHTInfo->ePeerHTSpecVer = HT_SPEC_VER_IEEE; @@ -1177,7 +1176,7 @@ void HTResetSelfAndSavePeerSetting(struct ieee80211_device *ieee, struct ieee802 { PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo; // u16 nMaxAMSDUSize; -// PHT_CAPABILITY_ELE pPeerHTCap = (PHT_CAPABILITY_ELE)pNetwork->bssht.bdHTCapBuf; +// struct ht_capability_ele *pPeerHTCap = (struct ht_capability_ele *)pNetwork->bssht.bdHTCapBuf; // PHT_INFORMATION_ELE pPeerHTInfo = (PHT_INFORMATION_ELE)pNetwork->bssht.bdHTInfoBuf; // u8* pMcsFilter; u8 bIOTAction = 0; @@ -1250,8 +1249,8 @@ void HTResetSelfAndSavePeerSetting(struct ieee80211_device *ieee, struct ieee802 void HTUpdateSelfAndPeerSetting(struct ieee80211_device *ieee, struct ieee80211_network *pNetwork) { - PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo; -// PHT_CAPABILITY_ELE pPeerHTCap = (PHT_CAPABILITY_ELE)pNetwork->bssht.bdHTCapBuf; + PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo; +// struct ht_capability_ele *pPeerHTCap = (struct ht_capability_ele *)pNetwork->bssht.bdHTCapBuf; PHT_INFORMATION_ELE pPeerHTInfo = (PHT_INFORMATION_ELE)pNetwork->bssht.bdHTInfoBuf; if (pHTInfo->bCurrentHTSupport) { diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_TS.h b/drivers/staging/rtl8192u/ieee80211/rtl819x_TS.h index 924d4b373099..7ed140009760 100644 --- a/drivers/staging/rtl8192u/ieee80211/rtl819x_TS.h +++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_TS.h @@ -78,8 +78,8 @@ struct ts_common_info { struct tx_ts_record { struct ts_common_info ts_common_info; u16 tx_cur_seq; - BA_RECORD tx_pending_ba_record; - BA_RECORD tx_admitted_ba_record; + struct ba_record tx_pending_ba_record; + struct ba_record tx_admitted_ba_record; u8 add_ba_req_in_progress; u8 add_ba_req_delayed; u8 using_ba; @@ -93,7 +93,7 @@ struct rx_ts_record { u16 rx_timeout_indicate_seq; struct list_head rx_pending_pkt_list; struct timer_list rx_pkt_pending_timer; - BA_RECORD rx_admitted_ba_record; + struct ba_record rx_admitted_ba_record; u16 rx_last_seq_num; u8 rx_last_frag_num; u8 num; diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c b/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c index d46d8f468671..c76715ffa08b 100644 --- a/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c +++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c @@ -36,11 +36,11 @@ static void RxPktPendingTimeout(struct timer_list *t) bool bPktInBuf = false; spin_lock_irqsave(&(ieee->reorder_spinlock), flags); - IEEE80211_DEBUG(IEEE80211_DL_REORDER,"==================>%s()\n",__func__); + IEEE80211_DEBUG(IEEE80211_DL_REORDER, "==================>%s()\n", __func__); if(pRxTs->rx_timeout_indicate_seq != 0xffff) { // Indicate the pending packets sequentially according to SeqNum until meet the gap. while(!list_empty(&pRxTs->rx_pending_pkt_list)) { - pReorderEntry = (PRX_REORDER_ENTRY)list_entry(pRxTs->rx_pending_pkt_list.prev,RX_REORDER_ENTRY,List); + pReorderEntry = (PRX_REORDER_ENTRY)list_entry(pRxTs->rx_pending_pkt_list.prev, RX_REORDER_ENTRY, List); if(index == 0) pRxTs->rx_indicate_seq = pReorderEntry->SeqNum; @@ -51,7 +51,7 @@ static void RxPktPendingTimeout(struct timer_list *t) if(SN_EQUAL(pReorderEntry->SeqNum, pRxTs->rx_indicate_seq)) pRxTs->rx_indicate_seq = (pRxTs->rx_indicate_seq + 1) % 4096; - IEEE80211_DEBUG(IEEE80211_DL_REORDER,"RxPktPendingTimeout(): IndicateSeq: %d\n", pReorderEntry->SeqNum); + IEEE80211_DEBUG(IEEE80211_DL_REORDER, "RxPktPendingTimeout(): IndicateSeq: %d\n", pReorderEntry->SeqNum); ieee->stats_IndicateArray[index] = pReorderEntry->prxb; index++; @@ -151,9 +151,9 @@ void TSInitialize(struct ieee80211_device *ieee) timer_setup(&pTxTS->ts_common_info.inact_timer, TsInactTimeout, 0); timer_setup(&pTxTS->ts_add_ba_timer, TsAddBaProcess, 0); - timer_setup(&pTxTS->tx_pending_ba_record.Timer, BaSetupTimeOut, + timer_setup(&pTxTS->tx_pending_ba_record.timer, BaSetupTimeOut, 0); - timer_setup(&pTxTS->tx_admitted_ba_record.Timer, + timer_setup(&pTxTS->tx_admitted_ba_record.timer, TxBaInactTimeout, 0); ResetTxTsEntry(pTxTS); list_add_tail(&pTxTS->ts_common_info.list, &ieee->Tx_TS_Unused_List); @@ -171,7 +171,7 @@ void TSInitialize(struct ieee80211_device *ieee) 0); timer_setup(&pRxTS->ts_common_info.inact_timer, TsInactTimeout, 0); - timer_setup(&pRxTS->rx_admitted_ba_record.Timer, + timer_setup(&pRxTS->rx_admitted_ba_record.timer, RxBaInactTimeout, 0); timer_setup(&pRxTS->rx_pkt_pending_timer, RxPktPendingTimeout, 0); ResetRxTsEntry(pRxTS); @@ -426,7 +426,7 @@ static void RemoveTsEntry(struct ieee80211_device *ieee, struct ts_common_info * while(!list_empty(&pRxTS->rx_pending_pkt_list)) { spin_lock_irqsave(&(ieee->reorder_spinlock), flags); //pRxReorderEntry = list_entry(&pRxTS->rx_pending_pkt_list.prev,RX_REORDER_ENTRY,List); - pRxReorderEntry = (PRX_REORDER_ENTRY)list_entry(pRxTS->rx_pending_pkt_list.prev,RX_REORDER_ENTRY,List); + pRxReorderEntry = (PRX_REORDER_ENTRY)list_entry(pRxTS->rx_pending_pkt_list.prev, RX_REORDER_ENTRY, List); list_del_init(&pRxReorderEntry->List); { int i = 0; @@ -529,7 +529,7 @@ void TsStartAddBaProcess(struct ieee80211_device *ieee, struct tx_ts_record *pTx mod_timer(&pTxTS->ts_add_ba_timer, jiffies + msecs_to_jiffies(TS_ADDBA_DELAY)); } else { - IEEE80211_DEBUG(IEEE80211_DL_BA,"TsStartAddBaProcess(): Immediately Start ADDBA now!!\n"); + IEEE80211_DEBUG(IEEE80211_DL_BA, "TsStartAddBaProcess(): Immediately Start ADDBA now!!\n"); mod_timer(&pTxTS->ts_add_ba_timer, jiffies+10); //set 10 ticks } } else { diff --git a/drivers/staging/rtl8192u/r8180_93cx6.h b/drivers/staging/rtl8192u/r8180_93cx6.h index 643d465e7105..0cdd00a4f7b8 100644 --- a/drivers/staging/rtl8192u/r8180_93cx6.h +++ b/drivers/staging/rtl8192u/r8180_93cx6.h @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: GPL-2.0 */ /* * This is part of rtl8187 OpenSource driver * Copyright (C) Andrea Merello 2004-2005 <andrea.merello@gmail.com> @@ -21,22 +22,4 @@ #define EPROM_DELAY 10 -#define EPROM_ANAPARAM_ADDRLWORD 0xd -#define EPROM_ANAPARAM_ADDRHWORD 0xe - -#define EPROM_RFCHIPID 0x6 -#define EPROM_TXPW_BASE 0x05 -#define EPROM_RFCHIPID_RTL8225U 5 -#define EPROM_RF_PARAM 0x4 -#define EPROM_CONFIG2 0xc - -#define EPROM_VERSION 0x1E -#define MAC_ADR 0x7 - -#define CIS 0x18 - -#define EPROM_TXPW0 0x16 -#define EPROM_TXPW2 0x1b -#define EPROM_TXPW1 0x3d - int eprom_read(struct net_device *dev, u32 addr); /* reads a 16 bits word */ diff --git a/drivers/staging/rtl8192u/r8190_rtl8256.c b/drivers/staging/rtl8192u/r8190_rtl8256.c index 9b7f822e9762..a8c8e8c0660d 100644 --- a/drivers/staging/rtl8192u/r8190_rtl8256.c +++ b/drivers/staging/rtl8192u/r8190_rtl8256.c @@ -14,6 +14,11 @@ #include "r819xU_phy.h" #include "r8190_rtl8256.h" +/* + * Forward declaration of local functions + */ +static void phy_rf8256_config_para_file(struct net_device *dev); + /*-------------------------------------------------------------------------- * Overview: set RF band width (20M or 40M) * Input: struct net_device* dev @@ -23,7 +28,7 @@ * Note: 8226 support both 20M and 40 MHz *-------------------------------------------------------------------------- */ -void PHY_SetRF8256Bandwidth(struct net_device *dev, enum ht_channel_width Bandwidth) +void phy_set_rf8256_bandwidth(struct net_device *dev, enum ht_channel_width Bandwidth) { u8 eRFPath; struct r8192_priv *priv = ieee80211_priv(dev); @@ -37,9 +42,9 @@ void PHY_SetRF8256Bandwidth(struct net_device *dev, enum ht_channel_width Bandwi switch (Bandwidth) { case HT_CHANNEL_WIDTH_20: - if (priv->card_8192_version == VERSION_819xU_A + if (priv->card_8192_version == VERSION_819XU_A || priv->card_8192_version - == VERSION_819xU_B) { /* 8256 D-cut, E-cut, xiong: consider it later! */ + == VERSION_819XU_B) { /* 8256 D-cut, E-cut, xiong: consider it later! */ rtl8192_phy_SetRFReg(dev, (enum rf90_radio_path_e)eRFPath, 0x0b, bMask12Bits, 0x100); /* phy para:1ba */ @@ -53,11 +58,11 @@ void PHY_SetRF8256Bandwidth(struct net_device *dev, enum ht_channel_width Bandwi (enum rf90_radio_path_e)eRFPath, 0x14, bMask12Bits, 0x5ab); } else { - RT_TRACE(COMP_ERR, "PHY_SetRF8256Bandwidth(): unknown hardware version\n"); + RT_TRACE(COMP_ERR, "phy_set_rf8256_bandwidth(): unknown hardware version\n"); } break; case HT_CHANNEL_WIDTH_20_40: - if (priv->card_8192_version == VERSION_819xU_A || priv->card_8192_version == VERSION_819xU_B) { /* 8256 D-cut, E-cut, xiong: consider it later! */ + if (priv->card_8192_version == VERSION_819XU_A || priv->card_8192_version == VERSION_819XU_B) { /* 8256 D-cut, E-cut, xiong: consider it later! */ rtl8192_phy_SetRFReg(dev, (enum rf90_radio_path_e)eRFPath, 0x0b, bMask12Bits, 0x300); /* phy para:3ba */ rtl8192_phy_SetRFReg(dev, (enum rf90_radio_path_e)eRFPath, 0x2c, bMask12Bits, 0x3df); rtl8192_phy_SetRFReg(dev, (enum rf90_radio_path_e)eRFPath, 0x0e, bMask12Bits, 0x0a1); @@ -68,11 +73,11 @@ void PHY_SetRF8256Bandwidth(struct net_device *dev, enum ht_channel_width Bandwi else rtl8192_phy_SetRFReg(dev, (enum rf90_radio_path_e)eRFPath, 0x14, bMask12Bits, 0x5ab); } else { - RT_TRACE(COMP_ERR, "PHY_SetRF8256Bandwidth(): unknown hardware version\n"); + RT_TRACE(COMP_ERR, "phy_set_rf8256_bandwidth(): unknown hardware version\n"); } break; default: - RT_TRACE(COMP_ERR, "PHY_SetRF8256Bandwidth(): unknown Bandwidth: %#X\n", Bandwidth); + RT_TRACE(COMP_ERR, "phy_set_rf8256_bandwidth(): unknown Bandwidth: %#X\n", Bandwidth); break; } @@ -85,7 +90,7 @@ void PHY_SetRF8256Bandwidth(struct net_device *dev, enum ht_channel_width Bandwi * Return: NONE *-------------------------------------------------------------------------- */ -void PHY_RF8256_Config(struct net_device *dev) +void phy_rf8256_config(struct net_device *dev) { struct r8192_priv *priv = ieee80211_priv(dev); /* Initialize general global value @@ -94,7 +99,7 @@ void PHY_RF8256_Config(struct net_device *dev) */ priv->NumTotalRFPath = RTL819X_TOTAL_RF_PATH; /* Config BB and RF */ - phy_RF8256_Config_ParaFile(dev); + phy_rf8256_config_para_file(dev); } /*-------------------------------------------------------------------------- * Overview: Interface to config 8256 @@ -103,7 +108,7 @@ void PHY_RF8256_Config(struct net_device *dev) * Return: NONE *-------------------------------------------------------------------------- */ -void phy_RF8256_Config_ParaFile(struct net_device *dev) +static void phy_rf8256_config_para_file(struct net_device *dev) { u32 u4RegValue = 0; u8 eRFPath; @@ -152,7 +157,7 @@ void phy_RF8256_Config_ParaFile(struct net_device *dev) * TODO: this function should be removed on ASIC , Emily 2007.2.2 */ if (rtl8192_phy_checkBBAndRF(dev, HW90_BLOCK_RF, (enum rf90_radio_path_e)eRFPath)) { - RT_TRACE(COMP_ERR, "PHY_RF8256_Config():Check Radio[%d] Fail!!\n", eRFPath); + RT_TRACE(COMP_ERR, "phy_rf8256_config():Check Radio[%d] Fail!!\n", eRFPath); goto phy_RF8256_Config_ParaFile_Fail; } @@ -207,7 +212,7 @@ void phy_RF8256_Config_ParaFile(struct net_device *dev) } if (ret) { - RT_TRACE(COMP_ERR, "phy_RF8256_Config_ParaFile():Radio[%d] Fail!!", eRFPath); + RT_TRACE(COMP_ERR, "phy_rf8256_config_para_file():Radio[%d] Fail!!", eRFPath); goto phy_RF8256_Config_ParaFile_Fail; } @@ -221,7 +226,7 @@ phy_RF8256_Config_ParaFile_Fail: } -void PHY_SetRF8256CCKTxPower(struct net_device *dev, u8 powerlevel) +void phy_set_rf8256_cck_tx_power(struct net_device *dev, u8 powerlevel) { u32 TxAGC = 0; struct r8192_priv *priv = ieee80211_priv(dev); @@ -240,7 +245,7 @@ void PHY_SetRF8256CCKTxPower(struct net_device *dev, u8 powerlevel) } -void PHY_SetRF8256OFDMTxPower(struct net_device *dev, u8 powerlevel) +void phy_set_rf8256_ofdm_tx_power(struct net_device *dev, u8 powerlevel) { struct r8192_priv *priv = ieee80211_priv(dev); /* Joseph TxPower for 8192 testing */ diff --git a/drivers/staging/rtl8192u/r8190_rtl8256.h b/drivers/staging/rtl8192u/r8190_rtl8256.h index 29b926cad14b..9ea67f86f911 100644 --- a/drivers/staging/rtl8192u/r8190_rtl8256.h +++ b/drivers/staging/rtl8192u/r8190_rtl8256.h @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: GPL-2.0 */ /* * This is part of the rtl8180-sa2400 driver * released under the GPL (See file COPYING for details). @@ -14,10 +15,10 @@ #define RTL8225H #define RTL819X_TOTAL_RF_PATH 2 /* for 8192U */ -void PHY_SetRF8256Bandwidth(struct net_device *dev, enum ht_channel_width Bandwidth); -void PHY_RF8256_Config(struct net_device *dev); -void phy_RF8256_Config_ParaFile(struct net_device *dev); -void PHY_SetRF8256CCKTxPower(struct net_device *dev, u8 powerlevel); -void PHY_SetRF8256OFDMTxPower(struct net_device *dev, u8 powerlevel); +void phy_set_rf8256_bandwidth(struct net_device *dev, + enum ht_channel_width bandwidth); +void phy_rf8256_config(struct net_device *dev); +void phy_set_rf8256_cck_tx_power(struct net_device *dev, u8 powerlevel); +void phy_set_rf8256_ofdm_tx_power(struct net_device *dev, u8 powerlevel); #endif diff --git a/drivers/staging/rtl8192u/r8192U.h b/drivers/staging/rtl8192u/r8192U.h index 94a148994069..e65a893fd084 100644 --- a/drivers/staging/rtl8192u/r8192U.h +++ b/drivers/staging/rtl8192u/r8192U.h @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: GPL-2.0 */ /* * This is part of rtl8187 OpenSource driver. * Copyright (C) Andrea Merello 2004-2005 <andrea.merello@gmail.com> @@ -39,19 +40,19 @@ #include "ieee80211/ieee80211.h" #define RTL8192U -#define RTL819xU_MODULE_NAME "rtl819xU" +#define RTL819XU_MODULE_NAME "rtl819xU" /* HW security */ #define MAX_KEY_LEN 61 #define KEY_BUF_SIZE 5 -#define Rx_Smooth_Factor 20 +#define RX_SMOOTH_FACTOR 20 #define DMESG(x, a...) #define DMESGW(x, a...) #define DMESGE(x, a...) extern u32 rt_global_debug_component; #define RT_TRACE(component, x, args...) \ do { \ - if (rt_global_debug_component & component) \ + if (rt_global_debug_component & (component)) \ pr_debug("RTL8192U: " x "\n", ##args); \ } while (0) @@ -111,7 +112,7 @@ extern u32 rt_global_debug_component; do { \ if ((rt_global_debug_component & (level)) == (level)) { \ int i; \ - u8 *pdata = (u8 *) data; \ + u8 *pdata = (u8 *)data; \ pr_debug("RTL8192U: %s()\n", __func__); \ for (i = 0; i < (int)(datalen); i++) { \ printk("%2x ", pdata[i]); \ @@ -798,6 +799,18 @@ typedef enum _tag_TxCmd_Config_Index { TXCMD_XXXX_CTRL, } DCMD_TXCMD_OP; +enum version_819xu { + VERSION_819XU_A, // A-cut + VERSION_819XU_B, // B-cut + VERSION_819XU_C,// C-cut +}; + +//added for different RF type +enum rt_rf_type { + RF_1T2R = 0, + RF_2T4R, +}; + typedef struct r8192_priv { struct usb_device *udev; /* For maintain info from eeprom */ @@ -815,7 +828,7 @@ typedef struct r8192_priv { /* O: rtl8192, 1: rtl8185 V B/C, 2: rtl8185 V D */ short card_8192; /* If TCR reports card V B/C, this discriminates */ - u8 card_8192_version; + enum version_819xu card_8192_version; short enable_gpio0; enum card_type { PCI, MINIPCI, CARDBUS, USB @@ -838,7 +851,7 @@ typedef struct r8192_priv { struct mutex wx_mutex; - u8 rf_type; /* 0: 1T2R, 1: 2T4R */ + enum rt_rf_type rf_type; /* 0: 1T2R, 1: 2T4R */ RT_RF_TYPE_819xU rf_chip; short (*rf_set_sens)(struct net_device *dev, short sens); @@ -864,9 +877,9 @@ typedef struct r8192_priv { int rx_inx; #endif - struct sk_buff_head rx_queue; - struct sk_buff_head skb_queue; - struct work_struct qos_activate; + struct sk_buff_head rx_queue; + struct sk_buff_head skb_queue; + struct work_struct qos_activate; short tx_urb_index; atomic_t tx_pending[0x10]; /* UART_PRIORITY + 1 */ @@ -1014,7 +1027,7 @@ typedef struct r8192_priv { u8 nrxAMPDU_aggr_num; /* For gpio */ - bool bHwRadioOff; + bool bHwRadioOff; u32 reset_count; bool bpbc_pressed; @@ -1079,9 +1092,6 @@ bool init_firmware(struct net_device *dev); short rtl819xU_tx_cmd(struct net_device *dev, struct sk_buff *skb); short rtl8192_tx(struct net_device *dev, struct sk_buff *skb); -u32 read_cam(struct net_device *dev, u8 addr); -void write_cam(struct net_device *dev, u8 addr, u32 data); - int read_nic_byte(struct net_device *dev, int x, u8 *data); int read_nic_byte_E(struct net_device *dev, int x, u8 *data); int read_nic_dword(struct net_device *dev, int x, u32 *data); @@ -1094,22 +1104,12 @@ void force_pci_posting(struct net_device *dev); void rtl8192_rtx_disable(struct net_device *dev); void rtl8192_rx_enable(struct net_device *dev); -void rtl8192_tx_enable(struct net_device *dev); - -void rtl8192_disassociate(struct net_device *dev); -void rtl8185_set_rf_pins_enable(struct net_device *dev, u32 a); -void rtl8192_set_anaparam(struct net_device *dev, u32 a); -void rtl8185_set_anaparam2(struct net_device *dev, u32 a); void rtl8192_update_msr(struct net_device *dev); int rtl8192_down(struct net_device *dev); int rtl8192_up(struct net_device *dev); void rtl8192_commit(struct net_device *dev); void rtl8192_set_chan(struct net_device *dev, short ch); -void write_phy(struct net_device *dev, u8 adr, u8 data); -void write_phy_cck(struct net_device *dev, u8 adr, u32 data); -void write_phy_ofdm(struct net_device *dev, u8 adr, u32 data); -void rtl8185_tx_antenna(struct net_device *dev, u8 ant); void rtl8192_set_rxconf(struct net_device *dev); void rtl819xusb_beacon_tx(struct net_device *dev, u16 tx_rate); diff --git a/drivers/staging/rtl8192u/r8192U_core.c b/drivers/staging/rtl8192u/r8192U_core.c index e218b5c20642..0ac0bbf7d923 100644 --- a/drivers/staging/rtl8192u/r8192U_core.c +++ b/drivers/staging/rtl8192u/r8192U_core.c @@ -128,7 +128,7 @@ static void rtl8192_usb_disconnect(struct usb_interface *intf); static struct usb_driver rtl8192_usb_driver = { - .name = RTL819xU_MODULE_NAME, /* Driver name */ + .name = RTL819XU_MODULE_NAME, /* Driver name */ .id_table = rtl8192_usb_id_tbl, /* PCI_ID table */ .probe = rtl8192_usb_probe, /* probe fn */ .disconnect = rtl8192_usb_disconnect, /* remove fn */ @@ -183,7 +183,7 @@ static void rtl819x_set_channel_map(u8 channel_plan, struct r8192_priv *priv) case COUNTRY_CODE_ISRAEL: case COUNTRY_CODE_TELEC: case COUNTRY_CODE_MIC: - Dot11d_Init(ieee); + rtl8192u_dot11d_init(ieee); ieee->bGlobalDomain = false; /* actually 8225 & 8256 rf chips only support B,G,24N mode */ if ((priv->rf_chip == RF_8225) || (priv->rf_chip == RF_8256)) { @@ -211,8 +211,8 @@ static void rtl819x_set_channel_map(u8 channel_plan, struct r8192_priv *priv) /* this flag enabled to follow 11d country IE setting, * otherwise, it shall follow global domain settings. */ - GET_DOT11D_INFO(ieee)->enabled = 0; - Dot11d_Reset(ieee); + GET_DOT11D_INFO(ieee)->dot11d_enabled = 0; + dot11d_reset(ieee); ieee->bGlobalDomain = true; break; @@ -237,22 +237,6 @@ static void CamResetAllEntry(struct net_device *dev) write_nic_dword(dev, RWCAM, ulcommand); } - -void write_cam(struct net_device *dev, u8 addr, u32 data) -{ - write_nic_dword(dev, WCAMI, data); - write_nic_dword(dev, RWCAM, BIT(31) | BIT(16) | (addr & 0xff)); -} - -u32 read_cam(struct net_device *dev, u8 addr) -{ - u32 data; - - write_nic_dword(dev, RWCAM, 0x80000000 | (addr & 0xff)); - read_nic_dword(dev, 0xa8, &data); - return data; -} - int write_nic_byte_E(struct net_device *dev, int indx, u8 data) { int status; @@ -643,7 +627,7 @@ static int __maybe_unused proc_get_stats_rx(struct seq_file *m, void *v) static void rtl8192_proc_module_init(void) { RT_TRACE(COMP_INIT, "Initializing proc filesystem"); - rtl8192_proc = proc_mkdir(RTL819xU_MODULE_NAME, init_net.proc_net); + rtl8192_proc = proc_mkdir(RTL819XU_MODULE_NAME, init_net.proc_net); } static void rtl8192_proc_init_one(struct net_device *dev) @@ -846,13 +830,6 @@ void rtl8192_rx_enable(struct net_device *dev) rtl8192_rx_initiate(dev); } - -void rtl8192_tx_enable(struct net_device *dev) -{ -} - - - void rtl8192_rtx_disable(struct net_device *dev) { u8 cmd; @@ -1997,7 +1974,7 @@ static void rtl8192_update_ratr_table(struct net_device *dev) break; case IEEE_N_24G: case IEEE_N_5G: - if (ieee->pHTInfo->PeerMimoPs == 0) { /* MIMO_PS_STATIC */ + if (ieee->pHTInfo->PeerMimoPs == MIMO_PS_STATIC) { ratr_value &= 0x0007F007; } else { if (priv->rf_type == RF_1T2R) @@ -2382,20 +2359,20 @@ static int rtl8192_read_eeprom_info(struct net_device *dev) if (ret < 0) return ret; priv->eeprom_pid = (u16)ret; - ret = eprom_read(dev, EEPROM_ChannelPlan >> 1); + ret = eprom_read(dev, EEPROM_CHANNEL_PLAN >> 1); if (ret < 0) return ret; tmpValue = (u16)ret; priv->eeprom_ChannelPlan = (tmpValue & 0xff00) >> 8; priv->btxpowerdata_readfromEEPORM = true; - ret = eprom_read(dev, (EEPROM_Customer_ID >> 1)) >> 8; + ret = eprom_read(dev, (EEPROM_CUSTOMER_ID >> 1)) >> 8; if (ret < 0) return ret; priv->eeprom_CustomerID = (u16)ret; } else { priv->eeprom_vid = 0; priv->eeprom_pid = 0; - priv->card_8192_version = VERSION_819xU_B; + priv->card_8192_version = VERSION_819XU_B; priv->eeprom_ChannelPlan = 0; priv->eeprom_CustomerID = 0; } @@ -2422,48 +2399,48 @@ static int rtl8192_read_eeprom_info(struct net_device *dev) priv->rf_type = RTL819X_DEFAULT_RF_TYPE; /* default 1T2R */ priv->rf_chip = RF_8256; - if (priv->card_8192_version == (u8)VERSION_819xU_A) { + if (priv->card_8192_version == VERSION_819XU_A) { /* read Tx power gain offset of legacy OFDM to HT rate */ if (bLoad_From_EEPOM) { - ret = eprom_read(dev, (EEPROM_TxPowerDiff >> 1)); + ret = eprom_read(dev, (EEPROM_TX_POWER_DIFF >> 1)); if (ret < 0) return ret; priv->EEPROMTxPowerDiff = ((u16)ret & 0xff00) >> 8; } else - priv->EEPROMTxPowerDiff = EEPROM_Default_TxPower; + priv->EEPROMTxPowerDiff = EEPROM_DEFAULT_TX_POWER; RT_TRACE(COMP_EPROM, "TxPowerDiff:%d\n", priv->EEPROMTxPowerDiff); /* read ThermalMeter from EEPROM */ if (bLoad_From_EEPOM) { - ret = eprom_read(dev, (EEPROM_ThermalMeter >> 1)); + ret = eprom_read(dev, (EEPROM_THERMAL_METER >> 1)); if (ret < 0) return ret; priv->EEPROMThermalMeter = (u8)((u16)ret & 0x00ff); } else - priv->EEPROMThermalMeter = EEPROM_Default_ThermalMeter; + priv->EEPROMThermalMeter = EEPROM_DEFAULT_THERNAL_METER; RT_TRACE(COMP_EPROM, "ThermalMeter:%d\n", priv->EEPROMThermalMeter); /* for tx power track */ priv->TSSI_13dBm = priv->EEPROMThermalMeter * 100; /* read antenna tx power offset of B/C/D to A from EEPROM */ if (bLoad_From_EEPOM) { - ret = eprom_read(dev, (EEPROM_PwDiff >> 1)); + ret = eprom_read(dev, (EEPROM_PW_DIFF >> 1)); if (ret < 0) return ret; priv->EEPROMPwDiff = ((u16)ret & 0x0f00) >> 8; } else - priv->EEPROMPwDiff = EEPROM_Default_PwDiff; + priv->EEPROMPwDiff = EEPROM_DEFAULT_PW_DIFF; RT_TRACE(COMP_EPROM, "TxPwDiff:%d\n", priv->EEPROMPwDiff); /* Read CrystalCap from EEPROM */ if (bLoad_From_EEPOM) { - ret = eprom_read(dev, (EEPROM_CrystalCap >> 1)); + ret = eprom_read(dev, (EEPROM_CRYSTAL_CAP >> 1)); if (ret < 0) return ret; priv->EEPROMCrystalCap = (u16)ret & 0x0f; } else - priv->EEPROMCrystalCap = EEPROM_Default_CrystalCap; + priv->EEPROMCrystalCap = EEPROM_DEFAULT_CRYSTAL_CAP; RT_TRACE(COMP_EPROM, "CrystalCap = %d\n", priv->EEPROMCrystalCap); /* get per-channel Tx power level */ if (bLoad_From_EEPOM) { - ret = eprom_read(dev, (EEPROM_TxPwIndex_Ver >> 1)); + ret = eprom_read(dev, (EEPROM_TX_PW_INDEX_VER >> 1)); if (ret < 0) return ret; priv->EEPROM_Def_Ver = ((u16)ret & 0xff00) >> 8; @@ -2474,7 +2451,7 @@ static int rtl8192_read_eeprom_info(struct net_device *dev) int i; if (bLoad_From_EEPOM) { - ret = eprom_read(dev, (EEPROM_TxPwIndex_CCK >> 1)); + ret = eprom_read(dev, (EEPROM_TX_PW_INDEX_CCK >> 1)); if (ret < 0) return ret; priv->EEPROMTxPowerLevelCCK = ((u16)ret & 0xff) >> 8; @@ -2483,10 +2460,10 @@ static int rtl8192_read_eeprom_info(struct net_device *dev) RT_TRACE(COMP_EPROM, "CCK Tx Power Levl: 0x%02x\n", priv->EEPROMTxPowerLevelCCK); for (i = 0; i < 3; i++) { if (bLoad_From_EEPOM) { - ret = eprom_read(dev, (EEPROM_TxPwIndex_OFDM_24G + i) >> 1); + ret = eprom_read(dev, (EEPROM_TX_PW_INDEX_OFDM_24G + i) >> 1); if (ret < 0) return ret; - if (((EEPROM_TxPwIndex_OFDM_24G + i) % 2) == 0) + if (((EEPROM_TX_PW_INDEX_OFDM_24G + i) % 2) == 0) tmpValue = (u16)ret & 0x00ff; else tmpValue = ((u16)ret & 0xff00) >> 8; @@ -2498,7 +2475,7 @@ static int rtl8192_read_eeprom_info(struct net_device *dev) } } else if (priv->EEPROM_Def_Ver == 1) { if (bLoad_From_EEPOM) { - ret = eprom_read(dev, EEPROM_TxPwIndex_CCK_V1 >> 1); + ret = eprom_read(dev, EEPROM_TX_PW_INDEX_CCK_V1 >> 1); if (ret < 0) return ret; tmpValue = ((u16)ret & 0xff00) >> 8; @@ -2508,7 +2485,7 @@ static int rtl8192_read_eeprom_info(struct net_device *dev) priv->EEPROMTxPowerLevelCCK_V1[0] = (u8)tmpValue; if (bLoad_From_EEPOM) { - ret = eprom_read(dev, (EEPROM_TxPwIndex_CCK_V1 + 2) >> 1); + ret = eprom_read(dev, (EEPROM_TX_PW_INDEX_CCK_V1 + 2) >> 1); if (ret < 0) return ret; tmpValue = (u16)ret; @@ -2517,12 +2494,12 @@ static int rtl8192_read_eeprom_info(struct net_device *dev) *((u16 *)(&priv->EEPROMTxPowerLevelCCK_V1[1])) = tmpValue; if (bLoad_From_EEPOM) tmpValue = eprom_read(dev, - EEPROM_TxPwIndex_OFDM_24G_V1 >> 1); + EEPROM_TX_PW_INDEX_OFDM_24G_V1 >> 1); else tmpValue = 0x1010; *((u16 *)(&priv->EEPROMTxPowerLevelOFDM24G[0])) = tmpValue; if (bLoad_From_EEPOM) - tmpValue = eprom_read(dev, (EEPROM_TxPwIndex_OFDM_24G_V1 + 2) >> 1); + tmpValue = eprom_read(dev, (EEPROM_TX_PW_INDEX_OFDM_24G_V1 + 2) >> 1); else tmpValue = 0x10; priv->EEPROMTxPowerLevelOFDM24G[2] = (u8)tmpValue; @@ -2567,7 +2544,7 @@ static int rtl8192_read_eeprom_info(struct net_device *dev) * 92U does not enable TX power tracking. */ priv->ThermalMeter[0] = priv->EEPROMThermalMeter; - } /* end if VersionID == VERSION_819xU_A */ + } /* end if VersionID == VERSION_819XU_A */ /* for dlink led */ switch (priv->eeprom_CustomerID) { @@ -2872,7 +2849,7 @@ static bool rtl8192_adapter_start(struct net_device *dev) rtl8192_phy_configmac(dev); - if (priv->card_8192_version == (u8)VERSION_819xU_A) { + if (priv->card_8192_version == VERSION_819XU_A) { rtl8192_phy_getTxPower(dev); rtl8192_phy_setTxPower(dev, priv->chan); } @@ -3998,13 +3975,13 @@ static void rtl8192_process_phyinfo(struct r8192_priv *priv, u8 *buffer, pprevious_stats->RxMIMOSignalStrength[rfpath]; if (pprevious_stats->RxMIMOSignalStrength[rfpath] > priv->stats.rx_rssi_percentage[rfpath]) { priv->stats.rx_rssi_percentage[rfpath] = - ((priv->stats.rx_rssi_percentage[rfpath] * (Rx_Smooth_Factor - 1)) + - (pprevious_stats->RxMIMOSignalStrength[rfpath])) / (Rx_Smooth_Factor); + ((priv->stats.rx_rssi_percentage[rfpath] * (RX_SMOOTH_FACTOR - 1)) + + (pprevious_stats->RxMIMOSignalStrength[rfpath])) / (RX_SMOOTH_FACTOR); priv->stats.rx_rssi_percentage[rfpath] = priv->stats.rx_rssi_percentage[rfpath] + 1; } else { priv->stats.rx_rssi_percentage[rfpath] = - ((priv->stats.rx_rssi_percentage[rfpath] * (Rx_Smooth_Factor - 1)) + - (pprevious_stats->RxMIMOSignalStrength[rfpath])) / (Rx_Smooth_Factor); + ((priv->stats.rx_rssi_percentage[rfpath] * (RX_SMOOTH_FACTOR - 1)) + + (pprevious_stats->RxMIMOSignalStrength[rfpath])) / (RX_SMOOTH_FACTOR); } RT_TRACE(COMP_DBG, "priv->stats.rx_rssi_percentage[rfPath] = %d\n", @@ -4049,13 +4026,13 @@ static void rtl8192_process_phyinfo(struct r8192_priv *priv, u8 *buffer, pprevious_stats->RxPWDBAll; if (pprevious_stats->RxPWDBAll > (u32)priv->undecorated_smoothed_pwdb) { priv->undecorated_smoothed_pwdb = - (((priv->undecorated_smoothed_pwdb) * (Rx_Smooth_Factor - 1)) + - (pprevious_stats->RxPWDBAll)) / (Rx_Smooth_Factor); + (((priv->undecorated_smoothed_pwdb) * (RX_SMOOTH_FACTOR - 1)) + + (pprevious_stats->RxPWDBAll)) / (RX_SMOOTH_FACTOR); priv->undecorated_smoothed_pwdb = priv->undecorated_smoothed_pwdb + 1; } else { priv->undecorated_smoothed_pwdb = - (((priv->undecorated_smoothed_pwdb) * (Rx_Smooth_Factor - 1)) + - (pprevious_stats->RxPWDBAll)) / (Rx_Smooth_Factor); + (((priv->undecorated_smoothed_pwdb) * (RX_SMOOTH_FACTOR - 1)) + + (pprevious_stats->RxPWDBAll)) / (RX_SMOOTH_FACTOR); } } @@ -4098,8 +4075,8 @@ static void rtl8192_process_phyinfo(struct r8192_priv *priv, u8 *buffer, if (priv->stats.rx_evm_percentage[nspatial_stream] == 0) /* initialize */ priv->stats.rx_evm_percentage[nspatial_stream] = pprevious_stats->RxMIMOSignalQuality[nspatial_stream]; priv->stats.rx_evm_percentage[nspatial_stream] = - ((priv->stats.rx_evm_percentage[nspatial_stream] * (Rx_Smooth_Factor - 1)) + - (pprevious_stats->RxMIMOSignalQuality[nspatial_stream] * 1)) / (Rx_Smooth_Factor); + ((priv->stats.rx_evm_percentage[nspatial_stream] * (RX_SMOOTH_FACTOR - 1)) + + (pprevious_stats->RxMIMOSignalQuality[nspatial_stream] * 1)) / (RX_SMOOTH_FACTOR); } } } @@ -4460,15 +4437,15 @@ static void TranslateRxSignalStuff819xUsb(struct sk_buff *skb, /* Check if the received packet is acceptable. */ bpacket_match_bssid = (type != IEEE80211_FTYPE_CTL) && - (eqMacAddr(priv->ieee80211->current_network.bssid, (fc & IEEE80211_FCTL_TODS) ? hdr->addr1 : (fc & IEEE80211_FCTL_FROMDS) ? hdr->addr2 : hdr->addr3)) + (ether_addr_equal(priv->ieee80211->current_network.bssid, (fc & IEEE80211_FCTL_TODS) ? hdr->addr1 : (fc & IEEE80211_FCTL_FROMDS) ? hdr->addr2 : hdr->addr3)) && (!pstats->bHwError) && (!pstats->bCRC) && (!pstats->bICV); bpacket_toself = bpacket_match_bssid & - (eqMacAddr(praddr, priv->ieee80211->dev->dev_addr)); + (ether_addr_equal(praddr, priv->ieee80211->dev->dev_addr)); if (WLAN_FC_GET_FRAMETYPE(fc) == IEEE80211_STYPE_BEACON) bPacketBeacon = true; if (WLAN_FC_GET_FRAMETYPE(fc) == IEEE80211_STYPE_BLOCKACK) { - if ((eqMacAddr(praddr, dev->dev_addr))) + if ((ether_addr_equal(praddr, dev->dev_addr))) bToSelfBA = true; } diff --git a/drivers/staging/rtl8192u/r8192U_hw.h b/drivers/staging/rtl8192u/r8192U_hw.h index 00a123d44207..5a958335681d 100644 --- a/drivers/staging/rtl8192u/r8192U_hw.h +++ b/drivers/staging/rtl8192u/r8192U_hw.h @@ -20,24 +20,6 @@ #ifndef R8192_HW #define R8192_HW -typedef enum _VERSION_819xU { - VERSION_819xU_A, // A-cut - VERSION_819xU_B, // B-cut - VERSION_819xU_C,// C-cut -} VERSION_819xU, *PVERSION_819xU; -//added for different RF type -typedef enum _RT_RF_TYPE_DEF { - RF_1T2R = 0, - RF_2T4R, - - RF_819X_MAX_TYPE -} RT_RF_TYPE_DEF; - - -typedef enum _BaseBand_Config_Type { - BaseBand_Config_PHY_REG = 0, //Radio Path A - BaseBand_Config_AGC_TAB = 1, //Radio Path B -} BaseBand_Config_Type, *PBaseBand_Config_Type; #define RTL8187_REQT_READ 0xc0 #define RTL8187_REQT_WRITE 0x40 #define RTL8187_REQ_GET_REGS 0x05 @@ -47,58 +29,33 @@ typedef enum _BaseBand_Config_Type { #define MAX_RX_URB 16 #define R8180_MAX_RETRY 255 -//#define MAX_RX_NORMAL_URB 3 -//#define MAX_RX_COMMAND_URB 2 -#define RX_URB_SIZE 9100 - -#define BB_ANTATTEN_CHAN14 0x0c -#define BB_ANTENNA_B 0x40 -#define BB_HOST_BANG BIT(30) -#define BB_HOST_BANG_EN BIT(2) -#define BB_HOST_BANG_CLK BIT(1) -#define BB_HOST_BANG_RW BIT(3) -#define BB_HOST_BANG_DATA 1 +#define RX_URB_SIZE 9100 -//#if (RTL819X_FPGA_VER & RTL819X_FPGA_VIVI_070920) -#define AFR 0x010 -#define AFR_CardBEn BIT(0) -#define AFR_CLKRUN_SEL BIT(1) -#define AFR_FuncRegEn BIT(2) #define RTL8190_EEPROM_ID 0x8129 #define EEPROM_VID 0x02 #define EEPROM_PID 0x04 #define EEPROM_NODE_ADDRESS_BYTE_0 0x0C -#define EEPROM_TxPowerDiff 0x1F -#define EEPROM_ThermalMeter 0x20 -#define EEPROM_PwDiff 0x21 //0x21 -#define EEPROM_CrystalCap 0x22 //0x22 +#define EEPROM_TX_POWER_DIFF 0x1F +#define EEPROM_THERMAL_METER 0x20 +#define EEPROM_PW_DIFF 0x21 //0x21 +#define EEPROM_CRYSTAL_CAP 0x22 //0x22 -#define EEPROM_TxPwIndex_CCK 0x23 //0x23 -#define EEPROM_TxPwIndex_OFDM_24G 0x24 //0x24~0x26 -#define EEPROM_TxPwIndex_CCK_V1 0x29 //0x29~0x2B -#define EEPROM_TxPwIndex_OFDM_24G_V1 0x2C //0x2C~0x2E -#define EEPROM_TxPwIndex_Ver 0x27 //0x27 +#define EEPROM_TX_PW_INDEX_CCK 0x23 //0x23 +#define EEPROM_TX_PW_INDEX_OFDM_24G 0x24 //0x24~0x26 +#define EEPROM_TX_PW_INDEX_CCK_V1 0x29 //0x29~0x2B +#define EEPROM_TX_PW_INDEX_OFDM_24G_V1 0x2C //0x2C~0x2E +#define EEPROM_TX_PW_INDEX_VER 0x27 //0x27 -#define EEPROM_Default_TxPowerDiff 0x0 -#define EEPROM_Default_ThermalMeter 0x7 -#define EEPROM_Default_PwDiff 0x4 -#define EEPROM_Default_CrystalCap 0x5 -#define EEPROM_Default_TxPower 0x1010 -#define EEPROM_Customer_ID 0x7B //0x7B:CustomerID -#define EEPROM_ChannelPlan 0x16 //0x7C -#define EEPROM_IC_VER 0x7d //0x7D -#define EEPROM_CRC 0x7e //0x7E~0x7F +#define EEPROM_DEFAULT_THERNAL_METER 0x7 +#define EEPROM_DEFAULT_PW_DIFF 0x4 +#define EEPROM_DEFAULT_CRYSTAL_CAP 0x5 +#define EEPROM_DEFAULT_TX_POWER 0x1010 +#define EEPROM_CUSTOMER_ID 0x7B //0x7B:CustomerID +#define EEPROM_CHANNEL_PLAN 0x16 //0x7C -#define EEPROM_CID_DEFAULT 0x0 -#define EEPROM_CID_CAMEO 0x1 #define EEPROM_CID_RUNTOP 0x2 -#define EEPROM_CID_Senao 0x3 -#define EEPROM_CID_TOSHIBA 0x4 // Toshiba setting, Merge by Jacken, 2008/01/31 -#define EEPROM_CID_NetCore 0x5 -#define EEPROM_CID_Nettronix 0x6 -#define EEPROM_CID_Pronet 0x7 #define EEPROM_CID_DLINK 0x8 #define AC_PARAM_TXOP_LIMIT_OFFSET 16 @@ -108,18 +65,16 @@ typedef enum _BaseBand_Config_Type { //#endif enum _RTL8192Usb_HW { + MAC0 = 0x000, + MAC4 = 0x004, - PCIF = 0x009, // PCI Function Register 0x0009h~0x000bh #define BB_GLOBAL_RESET_BIT 0x1 BB_GLOBAL_RESET = 0x020, // BasebandGlobal Reset Register BSSIDR = 0x02E, // BSSID Register CMDR = 0x037, // Command register -#define CR_RST 0x10 #define CR_RE 0x08 #define CR_TE 0x04 -#define CR_MulRW 0x01 SIFS = 0x03E, // SIFS register - TCR = 0x040, // Transmit Configuration Register #define TCR_MXDMA_2048 7 #define TCR_LRL_OFFSET 0 @@ -132,26 +87,16 @@ enum _RTL8192Usb_HW { BIT(22) | BIT(23)) #define RX_FIFO_THRESHOLD_MASK (BIT(13) | BIT(14) | BIT(15)) #define RX_FIFO_THRESHOLD_SHIFT 13 -#define RX_FIFO_THRESHOLD_128 3 -#define RX_FIFO_THRESHOLD_256 4 -#define RX_FIFO_THRESHOLD_512 5 -#define RX_FIFO_THRESHOLD_1024 6 #define RX_FIFO_THRESHOLD_NONE 7 #define MAX_RX_DMA_MASK (BIT(8) | BIT(9) | BIT(10)) #define RCR_MXDMA_OFFSET 8 #define RCR_FIFO_OFFSET 13 #define RCR_ONLYERLPKT BIT(31) // Early Receiving based on Packet Size. -#define RCR_ENCS2 BIT(30) // Enable Carrier Sense Detection Method 2 -#define RCR_ENCS1 BIT(29) // Enable Carrier Sense Detection Method 1 -#define RCR_ENMBID BIT(27) // Enable Multiple BssId. -#define RCR_ACKTXBW (BIT(24) | BIT(25)) // TXBW Setting of ACK frames #define RCR_CBSSID BIT(23) // Accept BSSID match packet #define RCR_APWRMGT BIT(22) // Accept power management packet -#define RCR_ADD3 BIT(21) // Accept address 3 match packet #define RCR_AMF BIT(20) // Accept management type frame #define RCR_ACF BIT(19) // Accept control type frame #define RCR_ADF BIT(18) // Accept data type frame -#define RCR_RXFTH BIT(13) // Rx FIFO Threshold #define RCR_AICV BIT(12) // Accept ICV error packet #define RCR_ACRC32 BIT(5) // Accept CRC32 error packet #define RCR_AB BIT(3) // Accept broadcast packet @@ -160,14 +105,10 @@ enum _RTL8192Usb_HW { #define RCR_AAP BIT(0) // Accept all unicast packet SLOT_TIME = 0x049, // Slot Time Register ACK_TIMEOUT = 0x04c, // Ack Timeout Register - PIFS_TIME = 0x04d, // PIFS time - USTIME = 0x04e, // Microsecond Tuning Register, Sets the microsecond time unit used by MAC clock. EDCAPARA_BE = 0x050, // EDCA Parameter of AC BE EDCAPARA_BK = 0x054, // EDCA Parameter of AC BK EDCAPARA_VO = 0x058, // EDCA Parameter of AC VO EDCAPARA_VI = 0x05C, // EDCA Parameter of AC VI - RFPC = 0x05F, // Rx FIFO Packet Count - CWRR = 0x060, // Contention Window Report Register BCN_TCFG = 0x062, // Beacon Time Configuration #define BCN_TCFG_CW_SHIFT 8 #define BCN_TCFG_IFS 0 @@ -178,7 +119,6 @@ enum _RTL8192Usb_HW { BCN_ERR_THRESH = 0x078, // Beacon Error Threshold RWCAM = 0x0A0, //IN 8190 Data Sheet is called CAMcmd WCAMI = 0x0A4, // Software write CAM input content - RCAMO = 0x0A8, // Software read/write CAM config SECR = 0x0B0, //Security Configuration Register #define SCR_TxUseDK BIT(0) //Force Tx Use Default Key #define SCR_RxUseDK BIT(1) //Force Rx Use Default Key @@ -186,21 +126,6 @@ enum _RTL8192Usb_HW { #define SCR_RxDecEnable BIT(3) //Enable Rx Decryption #define SCR_SKByA2 BIT(4) //Search kEY BY A2 #define SCR_NoSKMC BIT(5) //No Key Search for Multicast -#define SCR_UseDK 0x01 -#define SCR_TxSecEnable 0x02 -#define SCR_RxSecEnable 0x04 - TPPoll = 0x0fd, // Transmit priority polling register - PSR = 0x0ff, // Page Select Register -#define CPU_CCK_LOOPBACK 0x00030000 -#define CPU_GEN_SYSTEM_RESET 0x00000001 -#define CPU_GEN_FIRMWARE_RESET 0x00000008 -#define CPU_GEN_BOOT_RDY 0x00000010 -#define CPU_GEN_FIRM_RDY 0x00000020 -#define CPU_GEN_PUT_CODE_OK 0x00000080 -#define CPU_GEN_BB_RST 0x00000100 -#define CPU_GEN_PWR_STB_CPU 0x00000004 -#define CPU_GEN_NO_LOOPBACK_MSK 0xFFF8FFFF // Set bit18,17,16 to 0. Set bit19 -#define CPU_GEN_NO_LOOPBACK_SET 0x00080000 // Set BIT19 to 1 //---------------------------------------------------------------------------- // 8190 CPU General Register (offset 0x100, 4 byte) @@ -216,72 +141,20 @@ enum _RTL8192Usb_HW { #define CPU_GEN_NO_LOOPBACK_MSK 0xFFF8FFFF // Set bit18,17,16 to 0. Set bit19 #define CPU_GEN_NO_LOOPBACK_SET 0x00080000 // Set BIT19 to 1 CPU_GEN = 0x100, // CPU Reset Register - LED1Cfg = 0x154,// LED1 Configuration Register - LED0Cfg = 0x155,// LED0 Configuration Register - AcmAvg = 0x170, // ACM Average Period Register AcmHwCtrl = 0x171, // ACM Hardware Control Register //---------------------------------------------------------------------------- //// //// 8190 AcmHwCtrl bits (offset 0x171, 1 byte) ////---------------------------------------------------------------------------- // -#define AcmHw_HwEn BIT(0) #define AcmHw_BeqEn BIT(1) -#define AcmHw_ViqEn BIT(2) -#define AcmHw_VoqEn BIT(3) -#define AcmHw_BeqStatus BIT(4) -#define AcmHw_ViqStatus BIT(5) -#define AcmHw_VoqStatus BIT(6) - AcmFwCtrl = 0x172, // ACM Firmware Control Register - AES_11N_FIX = 0x173, - VOAdmTime = 0x174, // VO Queue Admitted Time Register - VIAdmTime = 0x178, // VI Queue Admitted Time Register - BEAdmTime = 0x17C, // BE Queue Admitted Time Register RQPN1 = 0x180, // Reserved Queue Page Number , Vo Vi, Be, Bk RQPN2 = 0x184, // Reserved Queue Page Number, HCCA, Cmd, Mgnt, High RQPN3 = 0x188, // Reserved Queue Page Number, Bcn, Public, -// QPRR = 0x1E0, // Queue Page Report per TID QPNR = 0x1D0, //0x1F0, // Queue Packet Number report per TID - BQDA = 0x200, // Beacon Queue Descriptor Address - HQDA = 0x204, // High Priority Queue Descriptor Address - CQDA = 0x208, // Command Queue Descriptor Address - MQDA = 0x20C, // Management Queue Descriptor Address - HCCAQDA = 0x210, // HCCA Queue Descriptor Address - VOQDA = 0x214, // VO Queue Descriptor Address - VIQDA = 0x218, // VI Queue Descriptor Address - BEQDA = 0x21C, // BE Queue Descriptor Address - BKQDA = 0x220, // BK Queue Descriptor Address - RCQDA = 0x224, // Receive command Queue Descriptor Address - RDQDA = 0x228, // Receive Queue Descriptor Start Address - - MAR0 = 0x240, // Multicast filter. - MAR4 = 0x244, - - CCX_PERIOD = 0x250, // CCX Measurement Period Register, in unit of TU. - CLM_RESULT = 0x251, // CCA Busy fraction register. - NHM_PERIOD = 0x252, // NHM Measurement Period register, in unit of TU. - NHM_THRESHOLD0 = 0x253, // Noise Histogram Meashorement0. - NHM_THRESHOLD1 = 0x254, // Noise Histogram Meashorement1. - NHM_THRESHOLD2 = 0x255, // Noise Histogram Meashorement2. - NHM_THRESHOLD3 = 0x256, // Noise Histogram Meashorement3. - NHM_THRESHOLD4 = 0x257, // Noise Histogram Meashorement4. - NHM_THRESHOLD5 = 0x258, // Noise Histogram Meashorement5. - NHM_THRESHOLD6 = 0x259, // Noise Histogram Meashorement6 - - MCTRL = 0x25A, // Measurement Control - - NHM_RPI_COUNTER0 = 0x264, // Noise Histogram RPI counter0, the fraction of signal strength < NHM_THRESHOLD0. - NHM_RPI_COUNTER1 = 0x265, // Noise Histogram RPI counter1, the fraction of signal strength in (NHM_THRESHOLD0, NHM_THRESHOLD1]. - NHM_RPI_COUNTER2 = 0x266, // Noise Histogram RPI counter2, the fraction of signal strength in (NHM_THRESHOLD1, NHM_THRESHOLD2]. - NHM_RPI_COUNTER3 = 0x267, // Noise Histogram RPI counter3, the fraction of signal strength in (NHM_THRESHOLD2, NHM_THRESHOLD3]. - NHM_RPI_COUNTER4 = 0x268, // Noise Histogram RPI counter4, the fraction of signal strength in (NHM_THRESHOLD3, NHM_THRESHOLD4]. - NHM_RPI_COUNTER5 = 0x269, // Noise Histogram RPI counter5, the fraction of signal strength in (NHM_THRESHOLD4, NHM_THRESHOLD5]. - NHM_RPI_COUNTER6 = 0x26A, // Noise Histogram RPI counter6, the fraction of signal strength in (NHM_THRESHOLD5, NHM_THRESHOLD6]. - NHM_RPI_COUNTER7 = 0x26B, // Noise Histogram RPI counter7, the fraction of signal strength in (NHM_THRESHOLD6, NHM_THRESHOLD7]. -#define BW_OPMODE_11J BIT(0) #define BW_OPMODE_5G BIT(1) #define BW_OPMODE_20MHZ BIT(2) BW_OPMODE = 0x300, // Bandwidth operation mode @@ -292,18 +165,10 @@ enum _RTL8192Usb_HW { #define MSR_LINK_SHIFT 0 #define MSR_LINK_ADHOC 1 #define MSR_LINK_MASTER 3 -#define MSR_LINK_ENEDCA BIT(4) RETRY_LIMIT = 0x304, // Retry Limit [15:8]-short, [7:0]-long #define RETRY_LIMIT_SHORT_SHIFT 8 #define RETRY_LIMIT_LONG_SHIFT 0 - TSFR = 0x308, RRSR = 0x310, // Response Rate Set -#define RRSR_RSC_OFFSET 21 -#define RRSR_SHORT_OFFSET 23 -#define RRSR_RSC_DUPLICATE 0x600000 -#define RRSR_RSC_LOWSUBCHNL 0x400000 -#define RRSR_RSC_UPSUBCHANL 0x200000 -#define RRSR_SHORT 0x800000 #define RRSR_1M BIT(0) #define RRSR_2M BIT(1) #define RRSR_5_5M BIT(2) @@ -316,17 +181,9 @@ enum _RTL8192Usb_HW { #define RRSR_36M BIT(9) #define RRSR_48M BIT(10) #define RRSR_54M BIT(11) -#define RRSR_MCS0 BIT(12) -#define RRSR_MCS1 BIT(13) -#define RRSR_MCS2 BIT(14) -#define RRSR_MCS3 BIT(15) -#define RRSR_MCS4 BIT(16) -#define RRSR_MCS5 BIT(17) -#define RRSR_MCS6 BIT(18) -#define RRSR_MCS7 BIT(19) #define BRSR_AckShortPmb BIT(23) // CCK ACK: use Short Preamble or not. - RATR0 = 0x320, // Rate Adaptive Table register1 UFWP = 0x318, + RATR0 = 0x320, // Rate Adaptive Table register1 DRIVER_RSSI = 0x32c, // Driver tell Firmware current RSSI //---------------------------------------------------------------------------- // 8190 Rate Adaptive Table Register (offset 0x320, 4 byte) @@ -372,41 +229,18 @@ enum _RTL8192Usb_HW { #define RATE_ALL_OFDM_2SS RATR_MCS8|RATR_MCS9 |RATR_MCS10|RATR_MCS11| \ RATR_MCS12|RATR_MCS13|RATR_MCS14|RATR_MCS15 - MCS_TXAGC = 0x340, // MCS AGC - CCK_TXAGC = 0x348, // CCK AGC -// ISR = 0x350, // Interrupt Status Register -// IMR = 0x354, // Interrupt Mask Register -// IMR_POLL = 0x360, - MacBlkCtrl = 0x403, // Mac block on/off control register - EPROM_CMD = 0xfe58, #define Cmd9346CR_9356SEL BIT(4) -#define EPROM_CMD_RESERVED_MASK BIT(5) #define EPROM_CMD_OPERATING_MODE_SHIFT 6 -#define EPROM_CMD_OPERATING_MODE_MASK (BIT(7) | BIT(6)) -#define EPROM_CMD_CONFIG 0x3 #define EPROM_CMD_NORMAL 0 -#define EPROM_CMD_LOAD 1 #define EPROM_CMD_PROGRAM 2 #define EPROM_CS_BIT BIT(3) #define EPROM_CK_BIT BIT(2) #define EPROM_W_BIT BIT(1) #define EPROM_R_BIT BIT(0) - - MAC0 = 0x000, - MAC1 = 0x001, - MAC2 = 0x002, - MAC3 = 0x003, - MAC4 = 0x004, - MAC5 = 0x005, - }; //---------------------------------------------------------------------------- // 818xB AnaParm & AnaParm2 Register //---------------------------------------------------------------------------- -//#define ANAPARM_ASIC_ON 0x45090658 -//#define ANAPARM2_ASIC_ON 0x727f3f52 #define GPI 0x108 -#define GPO 0x109 -#define GPE 0x10a #endif diff --git a/drivers/staging/rtl8192u/r819xU_firmware.c b/drivers/staging/rtl8192u/r819xU_firmware.c index 9c7e19aedff1..c3ea906f3af3 100644 --- a/drivers/staging/rtl8192u/r819xU_firmware.c +++ b/drivers/staging/rtl8192u/r819xU_firmware.c @@ -208,8 +208,8 @@ bool init_firmware(struct net_device *dev) u32 file_length = 0; u8 *mapped_file = NULL; u32 init_step = 0; - opt_rst_type_e rst_opt = OPT_SYSTEM_RESET; - firmware_init_step_e starting_state = FW_INIT_STEP0_BOOT; + enum opt_rst_type_e rst_opt = OPT_SYSTEM_RESET; + enum firmware_init_step_e starting_state = FW_INIT_STEP0_BOOT; rt_firmware *pfirmware = priv->pFirmware; const struct firmware *fw_entry; diff --git a/drivers/staging/rtl8192u/r819xU_firmware.h b/drivers/staging/rtl8192u/r819xU_firmware.h index cccd1c82ffe0..b84344c1e62b 100644 --- a/drivers/staging/rtl8192u/r819xU_firmware.h +++ b/drivers/staging/rtl8192u/r819xU_firmware.h @@ -2,19 +2,18 @@ #ifndef __INC_FIRMWARE_H #define __INC_FIRMWARE_H -#define RTL8190_CPU_START_OFFSET 0x80 #define GET_COMMAND_PACKET_FRAG_THRESHOLD(v) \ - (4*(v/4) - 8 - USB_HWDESC_HEADER_LEN) + (4 * ((v) / 4) - 8 - USB_HWDESC_HEADER_LEN) -typedef enum _firmware_init_step { +enum firmware_init_step_e { FW_INIT_STEP0_BOOT = 0, FW_INIT_STEP1_MAIN = 1, FW_INIT_STEP2_DATA = 2, -} firmware_init_step_e; +}; -typedef enum _opt_rst_type { +enum opt_rst_type_e { OPT_SYSTEM_RESET = 0, OPT_FIRMWARE_RESET = 1, -} opt_rst_type_e; +}; #endif diff --git a/drivers/staging/rtl8192u/r819xU_phy.c b/drivers/staging/rtl8192u/r819xU_phy.c index 7ee10d49894b..5f04afe53d69 100644 --- a/drivers/staging/rtl8192u/r819xU_phy.c +++ b/drivers/staging/rtl8192u/r819xU_phy.c @@ -511,7 +511,8 @@ void rtl8192_phy_configmac(struct net_device *dev) * notice: BB parameters may change all the time, so please make * sure it has been synced with the newest. *****************************************************************************/ -void rtl8192_phyConfigBB(struct net_device *dev, u8 ConfigType) +static void rtl8192_phyConfigBB(struct net_device *dev, + enum baseband_config_type ConfigType) { u32 i; @@ -525,7 +526,7 @@ void rtl8192_phyConfigBB(struct net_device *dev, u8 ConfigType) Rtl8190AGCTAB_Array_Table = Rtl819XAGCTAB_ArrayDTM; } #endif - if (ConfigType == BaseBand_Config_PHY_REG) { + if (ConfigType == BASEBAND_CONFIG_PHY_REG) { for (i = 0; i < PHY_REG_1T2RArrayLength; i += 2) { rtl8192_setBBreg(dev, Rtl8192UsbPHY_REG_1T2RArray[i], bMaskDWord, @@ -535,7 +536,7 @@ void rtl8192_phyConfigBB(struct net_device *dev, u8 ConfigType) i, Rtl8192UsbPHY_REG_1T2RArray[i], Rtl8192UsbPHY_REG_1T2RArray[i+1]); } - } else if (ConfigType == BaseBand_Config_AGC_TAB) { + } else if (ConfigType == BASEBAND_CONFIG_AGC_TAB) { for (i = 0; i < AGCTAB_ArrayLength; i += 2) { rtl8192_setBBreg(dev, Rtl8192UsbAGCTAB_Array[i], bMaskDWord, Rtl8192UsbAGCTAB_Array[i+1]); @@ -793,7 +794,7 @@ static void rtl8192_BB_Config_ParaFile(struct net_device *dev) (enum rf90_radio_path_e)0); if (status != 0) { RT_TRACE((COMP_ERR | COMP_PHY), - "PHY_RF8256_Config(): Check PHY%d Fail!!\n", + "phy_rf8256_config(): Check PHY%d Fail!!\n", eCheckItem-1); return; } @@ -802,7 +803,7 @@ static void rtl8192_BB_Config_ParaFile(struct net_device *dev) rtl8192_setBBreg(dev, rFPGA0_RFMOD, bCCKEn|bOFDMEn, 0x0); /* ----BB Register Initilazation---- */ /* ==m==>Set PHY REG From Header<==m== */ - rtl8192_phyConfigBB(dev, BaseBand_Config_PHY_REG); + rtl8192_phyConfigBB(dev, BASEBAND_CONFIG_PHY_REG); /* ----Set BB reset de-Active---- */ read_nic_dword(dev, CPU_GEN, ®_u32); @@ -810,11 +811,11 @@ static void rtl8192_BB_Config_ParaFile(struct net_device *dev) /* ----BB AGC table Initialization---- */ /* ==m==>Set PHY REG From Header<==m== */ - rtl8192_phyConfigBB(dev, BaseBand_Config_AGC_TAB); + rtl8192_phyConfigBB(dev, BASEBAND_CONFIG_AGC_TAB); /* ----Enable XSTAL ---- */ write_nic_byte_E(dev, 0x5e, 0x00); - if (priv->card_8192_version == (u8)VERSION_819xU_A) { + if (priv->card_8192_version == VERSION_819XU_A) { /* Antenna gain offset from B/C/D to A */ reg_u32 = priv->AntennaTxPwDiff[1]<<4 | priv->AntennaTxPwDiff[0]; @@ -917,8 +918,8 @@ void rtl8192_phy_setTxPower(struct net_device *dev, u8 channel) switch (priv->rf_chip) { case RF_8256: /* need further implement */ - PHY_SetRF8256CCKTxPower(dev, powerlevel); - PHY_SetRF8256OFDMTxPower(dev, powerlevelOFDM24G); + phy_set_rf8256_cck_tx_power(dev, powerlevel); + phy_set_rf8256_ofdm_tx_power(dev, powerlevelOFDM24G); break; default: RT_TRACE((COMP_PHY|COMP_ERR), @@ -940,7 +941,7 @@ void rtl8192_phy_RFConfig(struct net_device *dev) switch (priv->rf_chip) { case RF_8256: - PHY_RF8256_Config(dev); + phy_rf8256_config(dev); break; default: RT_TRACE(COMP_ERR, "error chip id\n"); @@ -1065,8 +1066,8 @@ static void rtl8192_SetTxPowerLevel(struct net_device *dev, u8 channel) break; case RF_8256: - PHY_SetRF8256CCKTxPower(dev, powerlevel); - PHY_SetRF8256OFDMTxPower(dev, powerlevelOFDM24G); + phy_set_rf8256_cck_tx_power(dev, powerlevel); + phy_set_rf8256_ofdm_tx_power(dev, powerlevelOFDM24G); break; case RF_8258: @@ -1271,7 +1272,7 @@ static u8 rtl8192_phy_SwChnlStepByStep(struct net_device *dev, u8 channel, RT_TRACE(COMP_CH, "%s() stage: %d, step: %d, channel: %d\n", __func__, *stage, *step, channel); - if (!IsLegalChannel(priv->ieee80211, channel)) { + if (!is_legal_channel(priv->ieee80211, channel)) { RT_TRACE(COMP_ERR, "set to illegal channel: %d\n", channel); /* return true to tell upper caller function this channel * setting is finished! Or it will in while loop. @@ -1367,7 +1368,7 @@ static u8 rtl8192_phy_SwChnlStepByStep(struct net_device *dev, u8 channel, switch (CurrentCmd->cmd_id) { case CMD_ID_SET_TX_PWR_LEVEL: - if (priv->card_8192_version == (u8)VERSION_819xU_A) + if (priv->card_8192_version == VERSION_819XU_A) /* consider it later! */ rtl8192_SetTxPowerLevel(dev, channel); break; @@ -1633,7 +1634,7 @@ void rtl8192_SetBWModeWorkItem(struct net_device *dev) break; case RF_8256: - PHY_SetRF8256Bandwidth(dev, priv->CurrentChannelBW); + phy_set_rf8256_bandwidth(dev, priv->CurrentChannelBW); break; case RF_8258: diff --git a/drivers/staging/rtl8192u/r819xU_phy.h b/drivers/staging/rtl8192u/r819xU_phy.h index c7ec3182857f..8c2933264407 100644 --- a/drivers/staging/rtl8192u/r819xU_phy.h +++ b/drivers/staging/rtl8192u/r819xU_phy.h @@ -7,6 +7,11 @@ #define MAX_RFDEPENDCMD_CNT 16 #define MAX_POSTCMD_CNT 16 +enum baseband_config_type { + BASEBAND_CONFIG_PHY_REG = 0, //Radio Path A + BASEBAND_CONFIG_AGC_TAB = 1, //Radio Path B +}; + enum switch_chan_cmd_id { CMD_ID_END, CMD_ID_SET_TX_PWR_LEVEL, @@ -52,7 +57,6 @@ u32 rtl8192_phy_QueryRFReg(struct net_device *dev, enum rf90_radio_path_e e_rfpath, u32 reg_addr, u32 bitmask); void rtl8192_phy_configmac(struct net_device *dev); -void rtl8192_phyConfigBB(struct net_device *dev, u8 ConfigType); u8 rtl8192_phy_checkBBAndRF(struct net_device *dev, enum hw90_block_e CheckBlock, enum rf90_radio_path_e e_rfpath); diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c index c3ff7c3e6681..08f7d1cc8ec1 100644 --- a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c +++ b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c @@ -67,11 +67,6 @@ static const long ieee80211_wlan_frequencies[] = { 2472, 2484 }; -static const char * const iw_operation_mode[] = { - "Auto", "Ad-Hoc", "Managed", "Master", "Repeater", "Secondary", - "Monitor" -}; - void r8712_indicate_wx_assoc_event(struct _adapter *padapter) { union iwreq_data wrqu; @@ -1789,7 +1784,7 @@ static int r871x_wx_set_enc_ext(struct net_device *dev, return -ENOMEM; param->cmd = IEEE_CMD_SET_ENCRYPTION; eth_broadcast_addr(param->sta_addr); - strncpy((char *)param->u.crypt.alg, alg_name, IEEE_CRYPT_ALG_NAME_LEN); + strlcpy((char *)param->u.crypt.alg, alg_name, IEEE_CRYPT_ALG_NAME_LEN); if (pext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) param->u.crypt.set_tx = 0; if (pext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) diff --git a/drivers/staging/rtl8712/rtl871x_xmit.c b/drivers/staging/rtl8712/rtl871x_xmit.c index a8ae14ce6613..e780d84dbb72 100644 --- a/drivers/staging/rtl8712/rtl871x_xmit.c +++ b/drivers/staging/rtl8712/rtl871x_xmit.c @@ -433,7 +433,7 @@ static sint xmitframe_addmic(struct _adapter *padapter, r8712_secmicappend(&micdata, payload, length); payload = payload + length; - } else{ + } else { length = pxmitpriv->frag_len - pattrib->hdrlen - pattrib->iv_len - ((psecuritypriv->sw_encrypt) ? diff --git a/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c b/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c index 0d2c61b67d0e..0833cce43dd3 100644 --- a/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c +++ b/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c @@ -2919,7 +2919,6 @@ int PHY_ConfigRFWithTxPwrTrackParaFile(struct adapter *Adapter, char *pFileName) struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); int rlen = 0, rtStatus = _FAIL; char *szLine, *ptmp; - u32 i = 0; if (!(Adapter->registrypriv.load_phy_file & LOAD_RF_TXPWR_TRACK_PARA_FILE)) return rtStatus; @@ -2958,8 +2957,10 @@ int PHY_ConfigRFWithTxPwrTrackParaFile(struct adapter *Adapter, char *pFileName) char band[5] = "", path[5] = "", sign[5] = ""; char chnl[5] = "", rate[10] = ""; char data[300] = ""; /* 100 is too small */ + const int len = strlen(szLine); + int i; - if (strlen(szLine) < 10 || szLine[0] != '[') + if (len < 10 || szLine[0] != '[') continue; strncpy(band, szLine+1, 2); @@ -2973,7 +2974,7 @@ int PHY_ConfigRFWithTxPwrTrackParaFile(struct adapter *Adapter, char *pFileName) if (!ParseQualifiedString(szLine, &i, chnl, '[', ']')) { /* DBG_871X("Fail to parse channel group!\n"); */ } - while (szLine[i] != '{' && i < strlen(szLine)) + while (i < len && szLine[i] != '{') i++; if (!ParseQualifiedString(szLine, &i, data, '{', '}')) { /* DBG_871X("Fail to parse data!\n"); */ diff --git a/drivers/staging/rtlwifi/efuse.c b/drivers/staging/rtlwifi/efuse.c index 1dc71455f270..abb0f720cf21 100644 --- a/drivers/staging/rtlwifi/efuse.c +++ b/drivers/staging/rtlwifi/efuse.c @@ -245,7 +245,8 @@ void read_efuse(struct ieee80211_hw *hw, u16 _offset, u16 _size_byte, u8 *pbuf) if (!efuse_word) goto out; for (i = 0; i < EFUSE_MAX_WORD_UNIT; i++) { - efuse_word[i] = kcalloc(efuse_max_section, sizeof(u16), GFP_ATOMIC); + efuse_word[i] = kcalloc(efuse_max_section, sizeof(u16), + GFP_ATOMIC); if (!efuse_word[i]) goto done; } diff --git a/drivers/staging/vboxvideo/vbox_main.c b/drivers/staging/vboxvideo/vbox_main.c index 429f6a453619..b6cff31903b3 100644 --- a/drivers/staging/vboxvideo/vbox_main.c +++ b/drivers/staging/vboxvideo/vbox_main.c @@ -490,9 +490,8 @@ static void vbox_bo_unref(struct vbox_bo **bo) return; tbo = &((*bo)->bo); - ttm_bo_unref(&tbo); - if (!tbo) - *bo = NULL; + ttm_bo_put(tbo); + *bo = NULL; } void vbox_gem_free_object(struct drm_gem_object *obj) diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-ctl.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-ctl.c index ec468d5719b1..a6ec72a5f0be 100644 --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-ctl.c +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-ctl.c @@ -1,23 +1,8 @@ // SPDX-License-Identifier: GPL-2.0 /* Copyright 2011 Broadcom Corporation. All rights reserved. */ -#include <linux/platform_device.h> -#include <linux/init.h> -#include <linux/io.h> -#include <linux/jiffies.h> -#include <linux/slab.h> -#include <linux/time.h> -#include <linux/wait.h> -#include <linux/delay.h> -#include <linux/moduleparam.h> -#include <linux/sched.h> - #include <sound/core.h> #include <sound/control.h> -#include <sound/pcm.h> -#include <sound/pcm_params.h> -#include <sound/rawmidi.h> -#include <sound/initval.h> #include <sound/tlv.h> #include <sound/asoundef.h> @@ -27,6 +12,21 @@ #define CTRL_VOL_MAX 400 #define CTRL_VOL_MIN -10239 /* originally -10240 */ +static int bcm2835_audio_set_chip_ctls(struct bcm2835_chip *chip) +{ + int i, err = 0; + + /* change ctls for all substreams */ + for (i = 0; i < MAX_SUBSTREAMS; i++) { + if (chip->alsa_stream[i]) { + err = bcm2835_audio_set_ctls(chip->alsa_stream[i]); + if (err < 0) + break; + } + } + return err; +} + static int snd_bcm2835_ctl_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { @@ -49,41 +49,15 @@ static int snd_bcm2835_ctl_info(struct snd_kcontrol *kcontrol, return 0; } -/* toggles mute on or off depending on the value of nmute, and returns - * 1 if the mute value was changed, otherwise 0 - */ -static int toggle_mute(struct bcm2835_chip *chip, int nmute) -{ - /* if settings are ok, just return 0 */ - if (chip->mute == nmute) - return 0; - - /* if the sound is muted then we need to unmute */ - if (chip->mute == CTRL_VOL_MUTE) { - chip->volume = chip->old_volume; /* copy the old volume back */ - audio_info("Unmuting, old_volume = %d, volume = %d ...\n", chip->old_volume, chip->volume); - } else /* otherwise we mute */ { - chip->old_volume = chip->volume; - chip->volume = 26214; /* set volume to minimum level AKA mute */ - audio_info("Muting, old_volume = %d, volume = %d ...\n", chip->old_volume, chip->volume); - } - - chip->mute = nmute; - return 1; -} - static int snd_bcm2835_ctl_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol); - if (mutex_lock_interruptible(&chip->audio_mutex)) - return -EINTR; - - BUG_ON(!chip && !(chip->avail_substreams & AVAIL_SUBSTREAMS_MASK)); + mutex_lock(&chip->audio_mutex); if (kcontrol->private_value == PCM_PLAYBACK_VOLUME) - ucontrol->value.integer.value[0] = chip2alsa(chip->volume); + ucontrol->value.integer.value[0] = chip->volume; else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) ucontrol->value.integer.value[0] = chip->mute; else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE) @@ -97,79 +71,60 @@ static int snd_bcm2835_ctl_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol); + int val, *valp; int changed = 0; - if (mutex_lock_interruptible(&chip->audio_mutex)) - return -EINTR; - - if (kcontrol->private_value == PCM_PLAYBACK_VOLUME) { - audio_info("Volume change attempted.. volume = %d new_volume = %d\n", chip->volume, (int)ucontrol->value.integer.value[0]); - if (chip->mute == CTRL_VOL_MUTE) { - /* changed = toggle_mute(chip, CTRL_VOL_UNMUTE); */ - changed = 1; /* should return 0 to signify no change but the mixer takes this as the opposite sign (no idea why) */ - goto unlock; - } - if (changed || (ucontrol->value.integer.value[0] != chip2alsa(chip->volume))) { - chip->volume = alsa2chip(ucontrol->value.integer.value[0]); - changed = 1; - } - - } else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) { - /* Now implemented */ - audio_info(" Mute attempted\n"); - changed = toggle_mute(chip, ucontrol->value.integer.value[0]); - - } else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE) { - if (ucontrol->value.integer.value[0] != chip->dest) { - chip->dest = ucontrol->value.integer.value[0]; - changed = 1; - } + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME) + valp = &chip->volume; + else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) + valp = &chip->mute; + else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE) + valp = &chip->dest; + else + return -EINVAL; + + val = ucontrol->value.integer.value[0]; + mutex_lock(&chip->audio_mutex); + if (val != *valp) { + *valp = val; + changed = 1; + if (bcm2835_audio_set_chip_ctls(chip)) + dev_err(chip->card->dev, "Failed to set ALSA controls..\n"); } - - if (changed && bcm2835_audio_set_ctls(chip)) - dev_err(chip->card->dev, "Failed to set ALSA controls..\n"); - -unlock: mutex_unlock(&chip->audio_mutex); return changed; } static DECLARE_TLV_DB_SCALE(snd_bcm2835_db_scale, CTRL_VOL_MIN, 1, 1); -static struct snd_kcontrol_new snd_bcm2835_ctl[] = { +static const struct snd_kcontrol_new snd_bcm2835_ctl[] = { { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "PCM Playback Volume", - .index = 0, .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, .private_value = PCM_PLAYBACK_VOLUME, .info = snd_bcm2835_ctl_info, .get = snd_bcm2835_ctl_get, .put = snd_bcm2835_ctl_put, - .count = 1, .tlv = {.p = snd_bcm2835_db_scale} }, { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "PCM Playback Switch", - .index = 0, .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, .private_value = PCM_PLAYBACK_MUTE, .info = snd_bcm2835_ctl_info, .get = snd_bcm2835_ctl_get, .put = snd_bcm2835_ctl_put, - .count = 1, }, { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "PCM Playback Route", - .index = 0, .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, .private_value = PCM_PLAYBACK_DEVICE, .info = snd_bcm2835_ctl_info, .get = snd_bcm2835_ctl_get, .put = snd_bcm2835_ctl_put, - .count = 1, }, }; @@ -187,8 +142,7 @@ static int snd_bcm2835_spdif_default_get(struct snd_kcontrol *kcontrol, struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol); int i; - if (mutex_lock_interruptible(&chip->audio_mutex)) - return -EINTR; + mutex_lock(&chip->audio_mutex); for (i = 0; i < 4; i++) ucontrol->value.iec958.status[i] = @@ -205,8 +159,7 @@ static int snd_bcm2835_spdif_default_put(struct snd_kcontrol *kcontrol, unsigned int val = 0; int i, change; - if (mutex_lock_interruptible(&chip->audio_mutex)) - return -EINTR; + mutex_lock(&chip->audio_mutex); for (i = 0; i < 4; i++) val |= (unsigned int)ucontrol->value.iec958.status[i] << (i * 8); @@ -237,51 +190,7 @@ static int snd_bcm2835_spdif_mask_get(struct snd_kcontrol *kcontrol, return 0; } -static int snd_bcm2835_spdif_stream_info(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_info *uinfo) -{ - uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; - uinfo->count = 1; - return 0; -} - -static int snd_bcm2835_spdif_stream_get(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) -{ - struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol); - int i; - - if (mutex_lock_interruptible(&chip->audio_mutex)) - return -EINTR; - - for (i = 0; i < 4; i++) - ucontrol->value.iec958.status[i] = - (chip->spdif_status >> (i * 8)) & 0xff; - - mutex_unlock(&chip->audio_mutex); - return 0; -} - -static int snd_bcm2835_spdif_stream_put(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) -{ - struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol); - unsigned int val = 0; - int i, change; - - if (mutex_lock_interruptible(&chip->audio_mutex)) - return -EINTR; - - for (i = 0; i < 4; i++) - val |= (unsigned int)ucontrol->value.iec958.status[i] << (i * 8); - change = val != chip->spdif_status; - chip->spdif_status = val; - - mutex_unlock(&chip->audio_mutex); - return change; -} - -static struct snd_kcontrol_new snd_bcm2835_spdif[] = { +static const struct snd_kcontrol_new snd_bcm2835_spdif[] = { { .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT), @@ -296,39 +205,34 @@ static struct snd_kcontrol_new snd_bcm2835_spdif[] = { .info = snd_bcm2835_spdif_mask_info, .get = snd_bcm2835_spdif_mask_get, }, - { - .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | - SNDRV_CTL_ELEM_ACCESS_INACTIVE, - .iface = SNDRV_CTL_ELEM_IFACE_PCM, - .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM), - .info = snd_bcm2835_spdif_stream_info, - .get = snd_bcm2835_spdif_stream_get, - .put = snd_bcm2835_spdif_stream_put, - }, }; -int snd_bcm2835_new_ctl(struct bcm2835_chip *chip) +static int create_ctls(struct bcm2835_chip *chip, size_t size, + const struct snd_kcontrol_new *kctls) { - int err; - unsigned int idx; + int i, err; - strcpy(chip->card->mixername, "Broadcom Mixer"); - for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_ctl); idx++) { - err = snd_ctl_add(chip->card, - snd_ctl_new1(&snd_bcm2835_ctl[idx], chip)); - if (err < 0) - return err; - } - for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_spdif); idx++) { - err = snd_ctl_add(chip->card, - snd_ctl_new1(&snd_bcm2835_spdif[idx], chip)); + for (i = 0; i < size; i++) { + err = snd_ctl_add(chip->card, snd_ctl_new1(&kctls[i], chip)); if (err < 0) return err; } return 0; } -static struct snd_kcontrol_new snd_bcm2835_headphones_ctl[] = { +int snd_bcm2835_new_ctl(struct bcm2835_chip *chip) +{ + int err; + + strcpy(chip->card->mixername, "Broadcom Mixer"); + err = create_ctls(chip, ARRAY_SIZE(snd_bcm2835_ctl), snd_bcm2835_ctl); + if (err < 0) + return err; + return create_ctls(chip, ARRAY_SIZE(snd_bcm2835_spdif), + snd_bcm2835_spdif); +} + +static const struct snd_kcontrol_new snd_bcm2835_headphones_ctl[] = { { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Headphone Playback Volume", @@ -357,21 +261,12 @@ static struct snd_kcontrol_new snd_bcm2835_headphones_ctl[] = { int snd_bcm2835_new_headphones_ctl(struct bcm2835_chip *chip) { - int err; - unsigned int idx; - strcpy(chip->card->mixername, "Broadcom Mixer"); - for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_headphones_ctl); idx++) { - err = snd_ctl_add(chip->card, - snd_ctl_new1(&snd_bcm2835_headphones_ctl[idx], - chip)); - if (err) - return err; - } - return 0; + return create_ctls(chip, ARRAY_SIZE(snd_bcm2835_headphones_ctl), + snd_bcm2835_headphones_ctl); } -static struct snd_kcontrol_new snd_bcm2835_hdmi[] = { +static const struct snd_kcontrol_new snd_bcm2835_hdmi[] = { { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "HDMI Playback Volume", @@ -400,16 +295,8 @@ static struct snd_kcontrol_new snd_bcm2835_hdmi[] = { int snd_bcm2835_new_hdmi_ctl(struct bcm2835_chip *chip) { - int err; - unsigned int idx; - strcpy(chip->card->mixername, "Broadcom Mixer"); - for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_hdmi); idx++) { - err = snd_ctl_add(chip->card, - snd_ctl_new1(&snd_bcm2835_hdmi[idx], chip)); - if (err) - return err; - } - return 0; + return create_ctls(chip, ARRAY_SIZE(snd_bcm2835_hdmi), + snd_bcm2835_hdmi); } diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c index 8359cf881bef..e66da11af5cf 100644 --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c @@ -11,7 +11,8 @@ /* hardware definition */ static const struct snd_pcm_hardware snd_bcm2835_playback_hw = { .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | - SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID), + SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | + SNDRV_PCM_INFO_DRAIN_TRIGGER | SNDRV_PCM_INFO_SYNC_APPLPTR), .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE, .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000, .rate_min = 8000, @@ -27,7 +28,8 @@ static const struct snd_pcm_hardware snd_bcm2835_playback_hw = { static const struct snd_pcm_hardware snd_bcm2835_playback_spdif_hw = { .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | - SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID), + SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | + SNDRV_PCM_INFO_DRAIN_TRIGGER | SNDRV_PCM_INFO_SYNC_APPLPTR), .formats = SNDRV_PCM_FMTBIT_S16_LE, .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000, @@ -44,48 +46,37 @@ static const struct snd_pcm_hardware snd_bcm2835_playback_spdif_hw = { static void snd_bcm2835_playback_free(struct snd_pcm_runtime *runtime) { - audio_info("Freeing up alsa stream here ..\n"); kfree(runtime->private_data); - runtime->private_data = NULL; } -void bcm2835_playback_fifo(struct bcm2835_alsa_stream *alsa_stream) +void bcm2835_playback_fifo(struct bcm2835_alsa_stream *alsa_stream, + unsigned int bytes) { - unsigned int consumed = 0; - int new_period = 0; - - audio_info("alsa_stream=%p substream=%p\n", alsa_stream, - alsa_stream ? alsa_stream->substream : 0); - - if (alsa_stream->open) - consumed = bcm2835_audio_retrieve_buffers(alsa_stream); - - /* We get called only if playback was triggered, So, the number of buffers we retrieve in - * each iteration are the buffers that have been played out already - */ - - if (alsa_stream->period_size) { - if ((alsa_stream->pos / alsa_stream->period_size) != - ((alsa_stream->pos + consumed) / alsa_stream->period_size)) - new_period = 1; - } - audio_debug("updating pos cur: %d + %d max:%d period_bytes:%d, hw_ptr: %d new_period:%d\n", - alsa_stream->pos, - consumed, - alsa_stream->buffer_size, - (int) (alsa_stream->period_size * alsa_stream->substream->runtime->periods), - frames_to_bytes(alsa_stream->substream->runtime, alsa_stream->substream->runtime->status->hw_ptr), - new_period); - if (alsa_stream->buffer_size) { - alsa_stream->pos += consumed & ~(1 << 30); - alsa_stream->pos %= alsa_stream->buffer_size; + struct snd_pcm_substream *substream = alsa_stream->substream; + unsigned int pos; + + if (!alsa_stream->period_size) + return; + + if (bytes >= alsa_stream->buffer_size) { + snd_pcm_stream_lock(substream); + snd_pcm_stop(substream, + alsa_stream->draining ? + SNDRV_PCM_STATE_SETUP : + SNDRV_PCM_STATE_XRUN); + snd_pcm_stream_unlock(substream); + return; } - if (alsa_stream->substream) { - if (new_period) - snd_pcm_period_elapsed(alsa_stream->substream); - } else { - audio_warning(" unexpected NULL substream\n"); + pos = atomic_read(&alsa_stream->pos); + pos += bytes; + pos %= alsa_stream->buffer_size; + atomic_set(&alsa_stream->pos, pos); + + alsa_stream->period_offset += bytes; + if (alsa_stream->period_offset >= alsa_stream->period_size) { + alsa_stream->period_offset %= alsa_stream->period_size; + snd_pcm_period_elapsed(substream); } } @@ -99,11 +90,7 @@ static int snd_bcm2835_playback_open_generic( int idx; int err; - if (mutex_lock_interruptible(&chip->audio_mutex)) { - audio_error("Interrupted whilst waiting for lock\n"); - return -EINTR; - } - audio_info("Alsa open (%d)\n", substream->number); + mutex_lock(&chip->audio_mutex); idx = substream->number; if (spdif && chip->opened) { @@ -114,21 +101,13 @@ static int snd_bcm2835_playback_open_generic( goto out; } if (idx >= MAX_SUBSTREAMS) { - audio_error - ("substream(%d) device doesn't exist max(%d) substreams allowed\n", + dev_err(chip->dev, + "substream(%d) device doesn't exist max(%d) substreams allowed\n", idx, MAX_SUBSTREAMS); err = -ENODEV; goto out; } - /* Check if we are ready */ - if (!(chip->avail_substreams & (1 << idx))) { - /* We are not ready yet */ - audio_error("substream(%d) device is not ready yet\n", idx); - err = -EAGAIN; - goto out; - } - alsa_stream = kzalloc(sizeof(*alsa_stream), GFP_KERNEL); if (!alsa_stream) { err = -ENOMEM; @@ -140,8 +119,6 @@ static int snd_bcm2835_playback_open_generic( alsa_stream->substream = substream; alsa_stream->idx = idx; - spin_lock_init(&alsa_stream->lock); - err = bcm2835_audio_open(alsa_stream); if (err) { kfree(alsa_stream); @@ -162,11 +139,14 @@ static int snd_bcm2835_playback_open_generic( SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 16); + /* position update is in 10ms order */ + snd_pcm_hw_constraint_minmax(runtime, + SNDRV_PCM_HW_PARAM_PERIOD_TIME, + 10 * 1000, UINT_MAX); + chip->alsa_stream[idx] = alsa_stream; chip->opened |= (1 << idx); - alsa_stream->open = 1; - alsa_stream->draining = 1; out: mutex_unlock(&chip->audio_mutex); @@ -194,37 +174,15 @@ static int snd_bcm2835_playback_close(struct snd_pcm_substream *substream) struct bcm2835_alsa_stream *alsa_stream; chip = snd_pcm_substream_chip(substream); - if (mutex_lock_interruptible(&chip->audio_mutex)) { - audio_error("Interrupted whilst waiting for lock\n"); - return -EINTR; - } + mutex_lock(&chip->audio_mutex); runtime = substream->runtime; alsa_stream = runtime->private_data; - audio_info("Alsa close\n"); - - /* - * Call stop if it's still running. This happens when app - * is force killed and we don't get a stop trigger. - */ - if (alsa_stream->running) { - int err; - - err = bcm2835_audio_stop(alsa_stream); - alsa_stream->running = 0; - if (err) - audio_error(" Failed to STOP alsa device\n"); - } - alsa_stream->period_size = 0; alsa_stream->buffer_size = 0; - if (alsa_stream->open) { - alsa_stream->open = 0; - bcm2835_audio_close(alsa_stream); - } - if (alsa_stream->chip) - alsa_stream->chip->alsa_stream[alsa_stream->idx] = NULL; + bcm2835_audio_close(alsa_stream); + alsa_stream->chip->alsa_stream[alsa_stream->idx] = NULL; /* * Do not free up alsa_stream here, it will be freed up by * runtime->private_free callback we registered in *_open above @@ -241,22 +199,7 @@ static int snd_bcm2835_playback_close(struct snd_pcm_substream *substream) static int snd_bcm2835_pcm_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) { - struct snd_pcm_runtime *runtime = substream->runtime; - struct bcm2835_alsa_stream *alsa_stream = runtime->private_data; - int err; - - err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params)); - if (err < 0) { - audio_error - (" pcm_lib_malloc failed to allocated pages for buffers\n"); - return err; - } - - alsa_stream->channels = params_channels(params); - alsa_stream->params_rate = params_rate(params); - alsa_stream->pcm_format_width = snd_pcm_format_width(params_format(params)); - - return err; + return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params)); } /* hw_free callback */ @@ -274,9 +217,6 @@ static int snd_bcm2835_pcm_prepare(struct snd_pcm_substream *substream) int channels; int err; - if (mutex_lock_interruptible(&chip->audio_mutex)) - return -EINTR; - /* notify the vchiq that it should enter spdif passthrough mode by * setting channels=0 (see * https://github.com/raspberrypi/linux/issues/528) @@ -284,18 +224,13 @@ static int snd_bcm2835_pcm_prepare(struct snd_pcm_substream *substream) if (chip->spdif_status & IEC958_AES0_NONAUDIO) channels = 0; else - channels = alsa_stream->channels; + channels = runtime->channels; err = bcm2835_audio_set_params(alsa_stream, channels, - alsa_stream->params_rate, - alsa_stream->pcm_format_width); + runtime->rate, + snd_pcm_format_width(runtime->format)); if (err < 0) - audio_error(" error setting hw params\n"); - - bcm2835_audio_setup(alsa_stream); - - /* in preparation of the stream, set the controls (volume level) of the stream */ - bcm2835_audio_set_ctls(alsa_stream->chip); + return err; memset(&alsa_stream->pcm_indirect, 0, sizeof(alsa_stream->pcm_indirect)); @@ -305,13 +240,10 @@ static int snd_bcm2835_pcm_prepare(struct snd_pcm_substream *substream) alsa_stream->buffer_size = snd_pcm_lib_buffer_bytes(substream); alsa_stream->period_size = snd_pcm_lib_period_bytes(substream); - alsa_stream->pos = 0; - - audio_debug("buffer_size=%d, period_size=%d pos=%d frame_bits=%d\n", - alsa_stream->buffer_size, alsa_stream->period_size, - alsa_stream->pos, runtime->frame_bits); + atomic_set(&alsa_stream->pos, 0); + alsa_stream->period_offset = 0; + alsa_stream->draining = false; - mutex_unlock(&chip->audio_mutex); return 0; } @@ -321,12 +253,8 @@ static void snd_bcm2835_pcm_transfer(struct snd_pcm_substream *substream, struct snd_pcm_runtime *runtime = substream->runtime; struct bcm2835_alsa_stream *alsa_stream = runtime->private_data; void *src = (void *) (substream->runtime->dma_area + rec->sw_data); - int err; - - err = bcm2835_audio_write(alsa_stream, bytes, src); - if (err) - audio_error(" Failed to transfer to alsa device (%d)\n", err); + bcm2835_audio_write(alsa_stream, bytes, src); } static int snd_bcm2835_pcm_ack(struct snd_pcm_substream *substream) @@ -335,7 +263,6 @@ static int snd_bcm2835_pcm_ack(struct snd_pcm_substream *substream) struct bcm2835_alsa_stream *alsa_stream = runtime->private_data; struct snd_pcm_indirect *pcm_indirect = &alsa_stream->pcm_indirect; - pcm_indirect->hw_queue_size = runtime->hw.buffer_bytes_max; return snd_pcm_indirect_playback_transfer(substream, pcm_indirect, snd_bcm2835_pcm_transfer); } @@ -345,50 +272,18 @@ static int snd_bcm2835_pcm_trigger(struct snd_pcm_substream *substream, int cmd) { struct snd_pcm_runtime *runtime = substream->runtime; struct bcm2835_alsa_stream *alsa_stream = runtime->private_data; - int err = 0; switch (cmd) { case SNDRV_PCM_TRIGGER_START: - audio_debug("bcm2835_AUDIO_TRIGGER_START running=%d\n", - alsa_stream->running); - if (!alsa_stream->running) { - err = bcm2835_audio_start(alsa_stream); - if (!err) { - alsa_stream->pcm_indirect.hw_io = - alsa_stream->pcm_indirect.hw_data = - bytes_to_frames(runtime, - alsa_stream->pos); - substream->ops->ack(substream); - alsa_stream->running = 1; - alsa_stream->draining = 1; - } else { - audio_error(" Failed to START alsa device (%d)\n", err); - } - } - break; + return bcm2835_audio_start(alsa_stream); + case SNDRV_PCM_TRIGGER_DRAIN: + alsa_stream->draining = true; + return bcm2835_audio_drain(alsa_stream); case SNDRV_PCM_TRIGGER_STOP: - audio_debug - ("bcm2835_AUDIO_TRIGGER_STOP running=%d draining=%d\n", - alsa_stream->running, runtime->status->state == SNDRV_PCM_STATE_DRAINING); - if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) { - audio_info("DRAINING\n"); - alsa_stream->draining = 1; - } else { - audio_info("DROPPING\n"); - alsa_stream->draining = 0; - } - if (alsa_stream->running) { - err = bcm2835_audio_stop(alsa_stream); - if (err != 0) - audio_error(" Failed to STOP alsa device (%d)\n", err); - alsa_stream->running = 0; - } - break; + return bcm2835_audio_stop(alsa_stream); default: - err = -EINVAL; + return -EINVAL; } - - return err; } /* pointer callback */ @@ -398,31 +293,16 @@ snd_bcm2835_pcm_pointer(struct snd_pcm_substream *substream) struct snd_pcm_runtime *runtime = substream->runtime; struct bcm2835_alsa_stream *alsa_stream = runtime->private_data; - audio_debug("pcm_pointer... (%d) hwptr=%d appl=%d pos=%d\n", 0, - frames_to_bytes(runtime, runtime->status->hw_ptr), - frames_to_bytes(runtime, runtime->control->appl_ptr), - alsa_stream->pos); - return snd_pcm_indirect_playback_pointer(substream, &alsa_stream->pcm_indirect, - alsa_stream->pos); -} - -static int snd_bcm2835_pcm_lib_ioctl(struct snd_pcm_substream *substream, - unsigned int cmd, void *arg) -{ - int ret = snd_pcm_lib_ioctl(substream, cmd, arg); - - audio_info(" .. substream=%p, cmd=%d, arg=%p (%x) ret=%d\n", substream, - cmd, arg, arg ? *(unsigned int *)arg : 0, ret); - return ret; + atomic_read(&alsa_stream->pos)); } /* operators */ static const struct snd_pcm_ops snd_bcm2835_playback_ops = { .open = snd_bcm2835_playback_open, .close = snd_bcm2835_playback_close, - .ioctl = snd_bcm2835_pcm_lib_ioctl, + .ioctl = snd_pcm_lib_ioctl, .hw_params = snd_bcm2835_pcm_hw_params, .hw_free = snd_bcm2835_pcm_hw_free, .prepare = snd_bcm2835_pcm_prepare, @@ -434,7 +314,7 @@ static const struct snd_pcm_ops snd_bcm2835_playback_ops = { static const struct snd_pcm_ops snd_bcm2835_playback_spdif_ops = { .open = snd_bcm2835_playback_spdif_open, .close = snd_bcm2835_playback_close, - .ioctl = snd_bcm2835_pcm_lib_ioctl, + .ioctl = snd_pcm_lib_ioctl, .hw_params = snd_bcm2835_pcm_hw_params, .hw_free = snd_bcm2835_pcm_hw_free, .prepare = snd_bcm2835_pcm_prepare, @@ -444,104 +324,36 @@ static const struct snd_pcm_ops snd_bcm2835_playback_spdif_ops = { }; /* create a pcm device */ -int snd_bcm2835_new_pcm(struct bcm2835_chip *chip, u32 numchannels) -{ - struct snd_pcm *pcm; - int err; - - mutex_init(&chip->audio_mutex); - if (mutex_lock_interruptible(&chip->audio_mutex)) { - audio_error("Interrupted whilst waiting for lock\n"); - return -EINTR; - } - err = snd_pcm_new(chip->card, "bcm2835 ALSA", 0, numchannels, 0, &pcm); - if (err < 0) - goto out; - pcm->private_data = chip; - strcpy(pcm->name, "bcm2835 ALSA"); - chip->pcm = pcm; - chip->dest = AUDIO_DEST_AUTO; - chip->volume = alsa2chip(0); - chip->mute = CTRL_VOL_UNMUTE; /*disable mute on startup */ - /* set operators */ - snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, - &snd_bcm2835_playback_ops); - - /* pre-allocation of buffers */ - /* NOTE: this may fail */ - snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS, - snd_dma_continuous_data(GFP_KERNEL), - snd_bcm2835_playback_hw.buffer_bytes_max, - snd_bcm2835_playback_hw.buffer_bytes_max); - -out: - mutex_unlock(&chip->audio_mutex); - - return 0; -} - -int snd_bcm2835_new_spdif_pcm(struct bcm2835_chip *chip) +int snd_bcm2835_new_pcm(struct bcm2835_chip *chip, const char *name, + int idx, enum snd_bcm2835_route route, + u32 numchannels, bool spdif) { struct snd_pcm *pcm; int err; - if (mutex_lock_interruptible(&chip->audio_mutex)) { - audio_error("Interrupted whilst waiting for lock\n"); - return -EINTR; - } - err = snd_pcm_new(chip->card, "bcm2835 ALSA", 1, 1, 0, &pcm); - if (err < 0) - goto out; - - pcm->private_data = chip; - strcpy(pcm->name, "bcm2835 IEC958/HDMI"); - chip->pcm_spdif = pcm; - snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, - &snd_bcm2835_playback_spdif_ops); - - /* pre-allocation of buffers */ - /* NOTE: this may fail */ - snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS, - snd_dma_continuous_data(GFP_KERNEL), - snd_bcm2835_playback_spdif_hw.buffer_bytes_max, snd_bcm2835_playback_spdif_hw.buffer_bytes_max); -out: - mutex_unlock(&chip->audio_mutex); - - return 0; -} - -int snd_bcm2835_new_simple_pcm(struct bcm2835_chip *chip, - const char *name, - enum snd_bcm2835_route route, - u32 numchannels) -{ - struct snd_pcm *pcm; - int err; - - mutex_init(&chip->audio_mutex); - - err = snd_pcm_new(chip->card, name, 0, numchannels, - 0, &pcm); + err = snd_pcm_new(chip->card, name, idx, numchannels, 0, &pcm); if (err) return err; pcm->private_data = chip; + pcm->nonatomic = true; strcpy(pcm->name, name); - chip->pcm = pcm; - chip->dest = route; - chip->volume = alsa2chip(0); - chip->mute = CTRL_VOL_UNMUTE; + if (!spdif) { + chip->dest = route; + chip->volume = 0; + chip->mute = CTRL_VOL_UNMUTE; + } snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, + spdif ? &snd_bcm2835_playback_spdif_ops : &snd_bcm2835_playback_ops); - snd_pcm_lib_preallocate_pages_for_all( - pcm, - SNDRV_DMA_TYPE_CONTINUOUS, - snd_dma_continuous_data(GFP_KERNEL), - snd_bcm2835_playback_hw.buffer_bytes_max, - snd_bcm2835_playback_hw.buffer_bytes_max); + snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, + chip->card->dev, 128 * 1024, 128 * 1024); + if (spdif) + chip->pcm_spdif = pcm; + else + chip->pcm = pcm; return 0; } - diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c index 868e2d6aaf1b..0bdaea1fdd77 100644 --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c @@ -1,190 +1,99 @@ // SPDX-License-Identifier: GPL-2.0 /* Copyright 2011 Broadcom Corporation. All rights reserved. */ -#include <linux/device.h> -#include <sound/core.h> -#include <sound/initval.h> -#include <sound/pcm.h> -#include <linux/io.h> -#include <linux/interrupt.h> -#include <linux/fs.h> -#include <linux/file.h> -#include <linux/mm.h> -#include <linux/syscalls.h> -#include <linux/uaccess.h> #include <linux/slab.h> -#include <linux/delay.h> -#include <linux/atomic.h> #include <linux/module.h> #include <linux/completion.h> - #include "bcm2835.h" - -/* ---- Include Files -------------------------------------------------------- */ - #include "vc_vchi_audioserv_defs.h" -/* ---- Private Constants and Types ------------------------------------------ */ - -#define BCM2835_AUDIO_STOP 0 -#define BCM2835_AUDIO_START 1 -#define BCM2835_AUDIO_WRITE 2 - -/* Logging macros (for remapping to other logging mechanisms, i.e., printf) */ -#ifdef AUDIO_DEBUG_ENABLE -#define LOG_ERR(fmt, arg...) pr_err("%s:%d " fmt, __func__, __LINE__, ##arg) -#define LOG_WARN(fmt, arg...) pr_info("%s:%d " fmt, __func__, __LINE__, ##arg) -#define LOG_INFO(fmt, arg...) pr_info("%s:%d " fmt, __func__, __LINE__, ##arg) -#define LOG_DBG(fmt, arg...) pr_info("%s:%d " fmt, __func__, __LINE__, ##arg) -#else -#define LOG_ERR(fmt, arg...) pr_err("%s:%d " fmt, __func__, __LINE__, ##arg) -#define LOG_WARN(fmt, arg...) no_printk(fmt, ##arg) -#define LOG_INFO(fmt, arg...) no_printk(fmt, ##arg) -#define LOG_DBG(fmt, arg...) no_printk(fmt, ##arg) -#endif - struct bcm2835_audio_instance { - unsigned int num_connections; - VCHI_SERVICE_HANDLE_T vchi_handle[VCHI_MAX_NUM_CONNECTIONS]; + struct device *dev; + VCHI_SERVICE_HANDLE_T vchi_handle; struct completion msg_avail_comp; struct mutex vchi_mutex; struct bcm2835_alsa_stream *alsa_stream; int result; + unsigned int max_packet; short peer_version; }; static bool force_bulk; +module_param(force_bulk, bool, 0444); +MODULE_PARM_DESC(force_bulk, "Force use of vchiq bulk for audio"); -/* ---- Private Variables ---------------------------------------------------- */ - -/* ---- Private Function Prototypes ------------------------------------------ */ - -/* ---- Private Functions ---------------------------------------------------- */ - -static int bcm2835_audio_stop_worker(struct bcm2835_alsa_stream *alsa_stream); -static int bcm2835_audio_start_worker(struct bcm2835_alsa_stream *alsa_stream); -static int bcm2835_audio_write_worker(struct bcm2835_alsa_stream *alsa_stream, - unsigned int count, void *src); - -// Routine to send a message across a service - -static int -bcm2835_vchi_msg_queue(VCHI_SERVICE_HANDLE_T handle, - void *data, - unsigned int size) +static void bcm2835_audio_lock(struct bcm2835_audio_instance *instance) { - return vchi_queue_kernel_message(handle, - data, - size); + mutex_lock(&instance->vchi_mutex); + vchi_service_use(instance->vchi_handle); } -static const u32 BCM2835_AUDIO_WRITE_COOKIE1 = ('B' << 24 | 'C' << 16 | - 'M' << 8 | 'A'); -static const u32 BCM2835_AUDIO_WRITE_COOKIE2 = ('D' << 24 | 'A' << 16 | - 'T' << 8 | 'A'); - -struct bcm2835_audio_work { - struct work_struct my_work; - struct bcm2835_alsa_stream *alsa_stream; - int cmd; - void *src; - unsigned int count; -}; - -static void my_wq_function(struct work_struct *work) +static void bcm2835_audio_unlock(struct bcm2835_audio_instance *instance) { - struct bcm2835_audio_work *w = - container_of(work, struct bcm2835_audio_work, my_work); - int ret = -9; - - switch (w->cmd) { - case BCM2835_AUDIO_START: - ret = bcm2835_audio_start_worker(w->alsa_stream); - break; - case BCM2835_AUDIO_STOP: - ret = bcm2835_audio_stop_worker(w->alsa_stream); - break; - case BCM2835_AUDIO_WRITE: - ret = bcm2835_audio_write_worker(w->alsa_stream, w->count, - w->src); - break; - default: - LOG_ERR(" Unexpected work: %p:%d\n", w->alsa_stream, w->cmd); - break; - } - kfree((void *)work); + vchi_service_release(instance->vchi_handle); + mutex_unlock(&instance->vchi_mutex); } -int bcm2835_audio_start(struct bcm2835_alsa_stream *alsa_stream) +static int bcm2835_audio_send_msg_locked(struct bcm2835_audio_instance *instance, + struct vc_audio_msg *m, bool wait) { - struct bcm2835_audio_work *work; + int status; - work = kmalloc(sizeof(*work), GFP_ATOMIC); - /*--- Queue some work (item 1) ---*/ - if (!work) { - LOG_ERR(" .. Error: NULL work kmalloc\n"); - return -ENOMEM; + if (wait) { + instance->result = -1; + init_completion(&instance->msg_avail_comp); } - INIT_WORK(&work->my_work, my_wq_function); - work->alsa_stream = alsa_stream; - work->cmd = BCM2835_AUDIO_START; - if (!queue_work(alsa_stream->my_wq, &work->my_work)) { - kfree(work); - return -EBUSY; - } - return 0; -} - -int bcm2835_audio_stop(struct bcm2835_alsa_stream *alsa_stream) -{ - struct bcm2835_audio_work *work; - work = kmalloc(sizeof(*work), GFP_ATOMIC); - /*--- Queue some work (item 1) ---*/ - if (!work) { - LOG_ERR(" .. Error: NULL work kmalloc\n"); - return -ENOMEM; + status = vchi_queue_kernel_message(instance->vchi_handle, + m, sizeof(*m)); + if (status) { + dev_err(instance->dev, + "vchi message queue failed: %d, msg=%d\n", + status, m->type); + return -EIO; } - INIT_WORK(&work->my_work, my_wq_function); - work->alsa_stream = alsa_stream; - work->cmd = BCM2835_AUDIO_STOP; - if (!queue_work(alsa_stream->my_wq, &work->my_work)) { - kfree(work); - return -EBUSY; + + if (wait) { + if (!wait_for_completion_timeout(&instance->msg_avail_comp, + msecs_to_jiffies(10 * 1000))) { + dev_err(instance->dev, + "vchi message timeout, msg=%d\n", m->type); + return -ETIMEDOUT; + } else if (instance->result) { + dev_err(instance->dev, + "vchi message response error:%d, msg=%d\n", + instance->result, m->type); + return -EIO; + } } + return 0; } -int bcm2835_audio_write(struct bcm2835_alsa_stream *alsa_stream, - unsigned int count, void *src) +static int bcm2835_audio_send_msg(struct bcm2835_audio_instance *instance, + struct vc_audio_msg *m, bool wait) { - struct bcm2835_audio_work *work; + int err; - work = kmalloc(sizeof(*work), GFP_ATOMIC); - /*--- Queue some work (item 1) ---*/ - if (!work) { - LOG_ERR(" .. Error: NULL work kmalloc\n"); - return -ENOMEM; - } - INIT_WORK(&work->my_work, my_wq_function); - work->alsa_stream = alsa_stream; - work->cmd = BCM2835_AUDIO_WRITE; - work->src = src; - work->count = count; - if (!queue_work(alsa_stream->my_wq, &work->my_work)) { - kfree(work); - return -EBUSY; - } - return 0; + bcm2835_audio_lock(instance); + err = bcm2835_audio_send_msg_locked(instance, m, wait); + bcm2835_audio_unlock(instance); + return err; } -static void my_workqueue_quit(struct bcm2835_alsa_stream *alsa_stream) +static int bcm2835_audio_send_simple(struct bcm2835_audio_instance *instance, + int type, bool wait) { - flush_workqueue(alsa_stream->my_wq); - destroy_workqueue(alsa_stream->my_wq); - alsa_stream->my_wq = NULL; + struct vc_audio_msg m = { .type = type }; + + return bcm2835_audio_send_msg(instance, &m, wait); } +static const u32 BCM2835_AUDIO_WRITE_COOKIE1 = ('B' << 24 | 'C' << 16 | + 'M' << 8 | 'A'); +static const u32 BCM2835_AUDIO_WRITE_COOKIE2 = ('D' << 24 | 'A' << 16 | + 'T' << 8 | 'A'); + static void audio_vchi_callback(void *param, const VCHI_CALLBACK_REASON_T reason, void *msg_handle) @@ -197,172 +106,94 @@ static void audio_vchi_callback(void *param, if (reason != VCHI_CALLBACK_MSG_AVAILABLE) return; - if (!instance) { - LOG_ERR(" .. instance is null\n"); - BUG(); - return; - } - if (!instance->vchi_handle[0]) { - LOG_ERR(" .. instance->vchi_handle[0] is null\n"); - BUG(); - return; - } - status = vchi_msg_dequeue(instance->vchi_handle[0], + status = vchi_msg_dequeue(instance->vchi_handle, &m, sizeof(m), &msg_len, VCHI_FLAGS_NONE); if (m.type == VC_AUDIO_MSG_TYPE_RESULT) { - LOG_DBG(" .. instance=%p, m.type=VC_AUDIO_MSG_TYPE_RESULT, success=%d\n", - instance, m.u.result.success); instance->result = m.u.result.success; complete(&instance->msg_avail_comp); } else if (m.type == VC_AUDIO_MSG_TYPE_COMPLETE) { - struct bcm2835_alsa_stream *alsa_stream = instance->alsa_stream; - - LOG_DBG(" .. instance=%p, m.type=VC_AUDIO_MSG_TYPE_COMPLETE, complete=%d\n", - instance, m.u.complete.count); if (m.u.complete.cookie1 != BCM2835_AUDIO_WRITE_COOKIE1 || m.u.complete.cookie2 != BCM2835_AUDIO_WRITE_COOKIE2) - LOG_ERR(" .. response is corrupt\n"); - else if (alsa_stream) { - atomic_add(m.u.complete.count, - &alsa_stream->retrieved); - bcm2835_playback_fifo(alsa_stream); - } else { - LOG_ERR(" .. unexpected alsa_stream=%p\n", - alsa_stream); - } + dev_err(instance->dev, "invalid cookie\n"); + else + bcm2835_playback_fifo(instance->alsa_stream, + m.u.complete.count); } else { - LOG_ERR(" .. unexpected m.type=%d\n", m.type); + dev_err(instance->dev, "unexpected callback type=%d\n", m.type); } } -static struct bcm2835_audio_instance * +static int vc_vchi_audio_init(VCHI_INSTANCE_T vchi_instance, - VCHI_CONNECTION_T **vchi_connections, - unsigned int num_connections) + VCHI_CONNECTION_T *vchi_connection, + struct bcm2835_audio_instance *instance) { - unsigned int i; - struct bcm2835_audio_instance *instance; + SERVICE_CREATION_T params = { + .version = VCHI_VERSION_EX(VC_AUDIOSERV_VER, VC_AUDIOSERV_MIN_VER), + .service_id = VC_AUDIO_SERVER_NAME, + .connection = vchi_connection, + .rx_fifo_size = 0, + .tx_fifo_size = 0, + .callback = audio_vchi_callback, + .callback_param = instance, + .want_unaligned_bulk_rx = 1, //TODO: remove VCOS_FALSE + .want_unaligned_bulk_tx = 1, //TODO: remove VCOS_FALSE + .want_crc = 0 + }; int status; - int ret; - - LOG_DBG("%s: start", __func__); - - if (num_connections > VCHI_MAX_NUM_CONNECTIONS) { - LOG_ERR("%s: unsupported number of connections %u (max=%u)\n", - __func__, num_connections, VCHI_MAX_NUM_CONNECTIONS); - return ERR_PTR(-EINVAL); - } - /* Allocate memory for this instance */ - instance = kzalloc(sizeof(*instance), GFP_KERNEL); - if (!instance) - return ERR_PTR(-ENOMEM); - - instance->num_connections = num_connections; - - /* Create a lock for exclusive, serialized VCHI connection access */ - mutex_init(&instance->vchi_mutex); /* Open the VCHI service connections */ - for (i = 0; i < num_connections; i++) { - SERVICE_CREATION_T params = { - .version = VCHI_VERSION_EX(VC_AUDIOSERV_VER, VC_AUDIOSERV_MIN_VER), - .service_id = VC_AUDIO_SERVER_NAME, - .connection = vchi_connections[i], - .rx_fifo_size = 0, - .tx_fifo_size = 0, - .callback = audio_vchi_callback, - .callback_param = instance, - .want_unaligned_bulk_rx = 1, //TODO: remove VCOS_FALSE - .want_unaligned_bulk_tx = 1, //TODO: remove VCOS_FALSE - .want_crc = 0 - }; - - LOG_DBG("%s: about to open %i\n", __func__, i); - status = vchi_service_open(vchi_instance, ¶ms, - &instance->vchi_handle[i]); - - LOG_DBG("%s: opened %i: %p=%d\n", __func__, i, instance->vchi_handle[i], status); - if (status) { - LOG_ERR("%s: failed to open VCHI service connection (status=%d)\n", - __func__, status); - ret = -EPERM; - goto err_close_services; - } - /* Finished with the service for now */ - vchi_service_release(instance->vchi_handle[i]); - } - - LOG_DBG("%s: okay\n", __func__); - return instance; + status = vchi_service_open(vchi_instance, ¶ms, + &instance->vchi_handle); -err_close_services: - for (i = 0; i < instance->num_connections; i++) { - LOG_ERR("%s: closing %i: %p\n", __func__, i, instance->vchi_handle[i]); - if (instance->vchi_handle[i]) - vchi_service_close(instance->vchi_handle[i]); + if (status) { + dev_err(instance->dev, + "failed to open VCHI service connection (status=%d)\n", + status); + kfree(instance); + return -EPERM; } - kfree(instance); - LOG_ERR("%s: error\n", __func__); + /* Finished with the service for now */ + vchi_service_release(instance->vchi_handle); - return ERR_PTR(ret); + return 0; } -static int vc_vchi_audio_deinit(struct bcm2835_audio_instance *instance) +static void vc_vchi_audio_deinit(struct bcm2835_audio_instance *instance) { - unsigned int i; - - if (!instance) { - LOG_ERR("%s: invalid handle %p\n", __func__, instance); + int status; - return -1; - } - - LOG_DBG(" .. about to lock (%d)\n", instance->num_connections); - if (mutex_lock_interruptible(&instance->vchi_mutex)) { - LOG_DBG("Interrupted whilst waiting for lock on (%d)\n", - instance->num_connections); - return -EINTR; - } + mutex_lock(&instance->vchi_mutex); + vchi_service_use(instance->vchi_handle); /* Close all VCHI service connections */ - for (i = 0; i < instance->num_connections; i++) { - int status; - - LOG_DBG(" .. %i:closing %p\n", i, instance->vchi_handle[i]); - vchi_service_use(instance->vchi_handle[i]); - - status = vchi_service_close(instance->vchi_handle[i]); - if (status) { - LOG_DBG("%s: failed to close VCHI service connection (status=%d)\n", - __func__, status); - } + status = vchi_service_close(instance->vchi_handle); + if (status) { + dev_err(instance->dev, + "failed to close VCHI service connection (status=%d)\n", + status); } mutex_unlock(&instance->vchi_mutex); - - kfree(instance); - - return 0; } -int bcm2835_new_vchi_ctx(struct bcm2835_vchi_ctx *vchi_ctx) +int bcm2835_new_vchi_ctx(struct device *dev, struct bcm2835_vchi_ctx *vchi_ctx) { int ret; /* Initialize and create a VCHI connection */ ret = vchi_initialise(&vchi_ctx->vchi_instance); if (ret) { - LOG_ERR("%s: failed to initialise VCHI instance (ret=%d)\n", - __func__, ret); - + dev_err(dev, "failed to initialise VCHI instance (ret=%d)\n", + ret); return -EIO; } ret = vchi_connect(NULL, 0, vchi_ctx->vchi_instance); if (ret) { - LOG_ERR("%s: failed to connect VCHI instance (ret=%d)\n", - __func__, ret); + dev_dbg(dev, "failed to connect VCHI instance (ret=%d)\n", + ret); kfree(vchi_ctx->vchi_instance); vchi_ctx->vchi_instance = NULL; @@ -381,473 +212,171 @@ void bcm2835_free_vchi_ctx(struct bcm2835_vchi_ctx *vchi_ctx) vchi_ctx->vchi_instance = NULL; } -static int bcm2835_audio_open_connection(struct bcm2835_alsa_stream *alsa_stream) -{ - struct bcm2835_audio_instance *instance = - (struct bcm2835_audio_instance *)alsa_stream->instance; - struct bcm2835_vchi_ctx *vhci_ctx = alsa_stream->chip->vchi_ctx; - - LOG_INFO("%s: start\n", __func__); - BUG_ON(instance); - if (instance) { - LOG_ERR("%s: VCHI instance already open (%p)\n", - __func__, instance); - instance->alsa_stream = alsa_stream; - alsa_stream->instance = instance; - return 0; - } - - /* Initialize an instance of the audio service */ - instance = vc_vchi_audio_init(vhci_ctx->vchi_instance, - &vhci_ctx->vchi_connection, 1); - - if (IS_ERR(instance)) { - LOG_ERR("%s: failed to initialize audio service\n", __func__); - - /* vchi_instance is retained for use the next time. */ - return PTR_ERR(instance); - } - - instance->alsa_stream = alsa_stream; - alsa_stream->instance = instance; - - LOG_DBG(" success !\n"); - - return 0; -} - int bcm2835_audio_open(struct bcm2835_alsa_stream *alsa_stream) { + struct bcm2835_vchi_ctx *vchi_ctx = alsa_stream->chip->vchi_ctx; struct bcm2835_audio_instance *instance; - struct vc_audio_msg m; - int status; - int ret; + int err; - alsa_stream->my_wq = alloc_workqueue("my_queue", WQ_HIGHPRI, 1); - if (!alsa_stream->my_wq) + /* Allocate memory for this instance */ + instance = kzalloc(sizeof(*instance), GFP_KERNEL); + if (!instance) return -ENOMEM; + mutex_init(&instance->vchi_mutex); + instance->dev = alsa_stream->chip->dev; + instance->alsa_stream = alsa_stream; + alsa_stream->instance = instance; - ret = bcm2835_audio_open_connection(alsa_stream); - if (ret) - goto free_wq; - - instance = alsa_stream->instance; - LOG_DBG(" instance (%p)\n", instance); - - if (mutex_lock_interruptible(&instance->vchi_mutex)) { - LOG_DBG("Interrupted whilst waiting for lock on (%d)\n", instance->num_connections); - ret = -EINTR; - goto free_wq; - } - vchi_service_use(instance->vchi_handle[0]); - - m.type = VC_AUDIO_MSG_TYPE_OPEN; - - /* Send the message to the videocore */ - status = bcm2835_vchi_msg_queue(instance->vchi_handle[0], - &m, sizeof(m)); - - if (status) { - LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n", - __func__, status); - - ret = -1; - goto unlock; - } - - ret = 0; - -unlock: - vchi_service_release(instance->vchi_handle[0]); - mutex_unlock(&instance->vchi_mutex); + err = vc_vchi_audio_init(vchi_ctx->vchi_instance, + vchi_ctx->vchi_connection, + instance); + if (err < 0) + goto free_instance; + + err = bcm2835_audio_send_simple(instance, VC_AUDIO_MSG_TYPE_OPEN, + false); + if (err < 0) + goto deinit; + + bcm2835_audio_lock(instance); + vchi_get_peer_version(instance->vchi_handle, &instance->peer_version); + bcm2835_audio_unlock(instance); + if (instance->peer_version < 2 || force_bulk) + instance->max_packet = 0; /* bulk transfer */ + else + instance->max_packet = 4000; -free_wq: - if (ret) - destroy_workqueue(alsa_stream->my_wq); + return 0; - return ret; + deinit: + vc_vchi_audio_deinit(instance); + free_instance: + alsa_stream->instance = NULL; + kfree(instance); + return err; } -static int bcm2835_audio_set_ctls_chan(struct bcm2835_alsa_stream *alsa_stream, - struct bcm2835_chip *chip) +int bcm2835_audio_set_ctls(struct bcm2835_alsa_stream *alsa_stream) { - struct vc_audio_msg m; - struct bcm2835_audio_instance *instance = alsa_stream->instance; - int status; - int ret; - - LOG_INFO(" Setting ALSA dest(%d), volume(%d)\n", - chip->dest, chip->volume); - - if (mutex_lock_interruptible(&instance->vchi_mutex)) { - LOG_DBG("Interrupted whilst waiting for lock on (%d)\n", - instance->num_connections); - return -EINTR; - } - vchi_service_use(instance->vchi_handle[0]); - - instance->result = -1; + struct bcm2835_chip *chip = alsa_stream->chip; + struct vc_audio_msg m = {}; m.type = VC_AUDIO_MSG_TYPE_CONTROL; m.u.control.dest = chip->dest; - m.u.control.volume = chip->volume; - - /* Create the message available completion */ - init_completion(&instance->msg_avail_comp); - - /* Send the message to the videocore */ - status = bcm2835_vchi_msg_queue(instance->vchi_handle[0], - &m, sizeof(m)); - - if (status) { - LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n", - __func__, status); - - ret = -1; - goto unlock; - } - - /* We are expecting a reply from the videocore */ - wait_for_completion(&instance->msg_avail_comp); - - if (instance->result) { - LOG_ERR("%s: result=%d\n", __func__, instance->result); - - ret = -1; - goto unlock; - } - - ret = 0; - -unlock: - vchi_service_release(instance->vchi_handle[0]); - mutex_unlock(&instance->vchi_mutex); - - return ret; -} + if (!chip->mute) + m.u.control.volume = CHIP_MIN_VOLUME; + else + m.u.control.volume = alsa2chip(chip->volume); -int bcm2835_audio_set_ctls(struct bcm2835_chip *chip) -{ - int i; - int ret = 0; - - LOG_DBG(" Setting ALSA dest(%d), volume(%d)\n", chip->dest, chip->volume); - - /* change ctls for all substreams */ - for (i = 0; i < MAX_SUBSTREAMS; i++) { - if (chip->avail_substreams & (1 << i)) { - if (!chip->alsa_stream[i]) { - LOG_DBG(" No ALSA stream available?! %i:%p (%x)\n", i, chip->alsa_stream[i], chip->avail_substreams); - ret = 0; - } else if (bcm2835_audio_set_ctls_chan(chip->alsa_stream[i], chip) != 0) { - LOG_ERR("Couldn't set the controls for stream %d\n", i); - ret = -1; - } else { - LOG_DBG(" Controls set for stream %d\n", i); - } - } - } - return ret; + return bcm2835_audio_send_msg(alsa_stream->instance, &m, true); } int bcm2835_audio_set_params(struct bcm2835_alsa_stream *alsa_stream, unsigned int channels, unsigned int samplerate, unsigned int bps) { - struct vc_audio_msg m; - struct bcm2835_audio_instance *instance = alsa_stream->instance; - int status; - int ret; - - LOG_INFO(" Setting ALSA channels(%d), samplerate(%d), bits-per-sample(%d)\n", - channels, samplerate, bps); + struct vc_audio_msg m = { + .type = VC_AUDIO_MSG_TYPE_CONFIG, + .u.config.channels = channels, + .u.config.samplerate = samplerate, + .u.config.bps = bps, + }; + int err; /* resend ctls - alsa_stream may not have been open when first send */ - ret = bcm2835_audio_set_ctls_chan(alsa_stream, alsa_stream->chip); - if (ret) { - LOG_ERR(" Alsa controls not supported\n"); - return -EINVAL; - } - - if (mutex_lock_interruptible(&instance->vchi_mutex)) { - LOG_DBG("Interrupted whilst waiting for lock on (%d)\n", instance->num_connections); - return -EINTR; - } - vchi_service_use(instance->vchi_handle[0]); - - instance->result = -1; - - m.type = VC_AUDIO_MSG_TYPE_CONFIG; - m.u.config.channels = channels; - m.u.config.samplerate = samplerate; - m.u.config.bps = bps; - - /* Create the message available completion */ - init_completion(&instance->msg_avail_comp); - - /* Send the message to the videocore */ - status = bcm2835_vchi_msg_queue(instance->vchi_handle[0], - &m, sizeof(m)); + err = bcm2835_audio_set_ctls(alsa_stream); + if (err) + return err; - if (status) { - LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n", - __func__, status); - - ret = -1; - goto unlock; - } - - /* We are expecting a reply from the videocore */ - wait_for_completion(&instance->msg_avail_comp); - - if (instance->result) { - LOG_ERR("%s: result=%d", __func__, instance->result); - - ret = -1; - goto unlock; - } - - ret = 0; - -unlock: - vchi_service_release(instance->vchi_handle[0]); - mutex_unlock(&instance->vchi_mutex); - - return ret; + return bcm2835_audio_send_msg(alsa_stream->instance, &m, true); } -int bcm2835_audio_setup(struct bcm2835_alsa_stream *alsa_stream) +int bcm2835_audio_start(struct bcm2835_alsa_stream *alsa_stream) { - - return 0; + return bcm2835_audio_send_simple(alsa_stream->instance, + VC_AUDIO_MSG_TYPE_START, false); } -static int bcm2835_audio_start_worker(struct bcm2835_alsa_stream *alsa_stream) +int bcm2835_audio_stop(struct bcm2835_alsa_stream *alsa_stream) { - struct vc_audio_msg m; - struct bcm2835_audio_instance *instance = alsa_stream->instance; - int status; - int ret; - - if (mutex_lock_interruptible(&instance->vchi_mutex)) { - LOG_DBG("Interrupted whilst waiting for lock on (%d)\n", - instance->num_connections); - return -EINTR; - } - vchi_service_use(instance->vchi_handle[0]); - - m.type = VC_AUDIO_MSG_TYPE_START; - - /* Send the message to the videocore */ - status = bcm2835_vchi_msg_queue(instance->vchi_handle[0], - &m, sizeof(m)); - - if (status) { - LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n", - __func__, status); - - ret = -1; - goto unlock; - } - - ret = 0; - -unlock: - vchi_service_release(instance->vchi_handle[0]); - mutex_unlock(&instance->vchi_mutex); - return ret; + return bcm2835_audio_send_simple(alsa_stream->instance, + VC_AUDIO_MSG_TYPE_STOP, false); } -static int bcm2835_audio_stop_worker(struct bcm2835_alsa_stream *alsa_stream) +int bcm2835_audio_drain(struct bcm2835_alsa_stream *alsa_stream) { - struct vc_audio_msg m; - struct bcm2835_audio_instance *instance = alsa_stream->instance; - int status; - int ret; - - if (mutex_lock_interruptible(&instance->vchi_mutex)) { - LOG_DBG("Interrupted whilst waiting for lock on (%d)\n", - instance->num_connections); - return -EINTR; - } - vchi_service_use(instance->vchi_handle[0]); - - m.type = VC_AUDIO_MSG_TYPE_STOP; - m.u.stop.draining = alsa_stream->draining; - - /* Send the message to the videocore */ - status = bcm2835_vchi_msg_queue(instance->vchi_handle[0], - &m, sizeof(m)); - - if (status) { - LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n", - __func__, status); + struct vc_audio_msg m = { + .type = VC_AUDIO_MSG_TYPE_STOP, + .u.stop.draining = 1, + }; - ret = -1; - goto unlock; - } - - ret = 0; - -unlock: - vchi_service_release(instance->vchi_handle[0]); - mutex_unlock(&instance->vchi_mutex); - return ret; + return bcm2835_audio_send_msg(alsa_stream->instance, &m, false); } int bcm2835_audio_close(struct bcm2835_alsa_stream *alsa_stream) { - struct vc_audio_msg m; struct bcm2835_audio_instance *instance = alsa_stream->instance; - int status; - int ret; + int err; - my_workqueue_quit(alsa_stream); - - if (mutex_lock_interruptible(&instance->vchi_mutex)) { - LOG_DBG("Interrupted whilst waiting for lock on (%d)\n", - instance->num_connections); - return -EINTR; - } - vchi_service_use(instance->vchi_handle[0]); - - m.type = VC_AUDIO_MSG_TYPE_CLOSE; - - /* Create the message available completion */ - init_completion(&instance->msg_avail_comp); - - /* Send the message to the videocore */ - status = bcm2835_vchi_msg_queue(instance->vchi_handle[0], - &m, sizeof(m)); - - if (status) { - LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n", - __func__, status); - ret = -1; - goto unlock; - } - - /* We are expecting a reply from the videocore */ - wait_for_completion(&instance->msg_avail_comp); - - if (instance->result) { - LOG_ERR("%s: failed result (result=%d)\n", - __func__, instance->result); - - ret = -1; - goto unlock; - } - - ret = 0; - -unlock: - vchi_service_release(instance->vchi_handle[0]); - mutex_unlock(&instance->vchi_mutex); + err = bcm2835_audio_send_simple(alsa_stream->instance, + VC_AUDIO_MSG_TYPE_CLOSE, true); /* Stop the audio service */ vc_vchi_audio_deinit(instance); alsa_stream->instance = NULL; + kfree(instance); - return ret; + return err; } -static int bcm2835_audio_write_worker(struct bcm2835_alsa_stream *alsa_stream, - unsigned int count, void *src) +int bcm2835_audio_write(struct bcm2835_alsa_stream *alsa_stream, + unsigned int size, void *src) { - struct vc_audio_msg m; struct bcm2835_audio_instance *instance = alsa_stream->instance; - int status; - int ret; - - LOG_INFO(" Writing %d bytes from %p\n", count, src); - - if (mutex_lock_interruptible(&instance->vchi_mutex)) { - LOG_DBG("Interrupted whilst waiting for lock on (%d)\n", - instance->num_connections); - return -EINTR; - } - vchi_service_use(instance->vchi_handle[0]); - - if (instance->peer_version == 0 && - vchi_get_peer_version(instance->vchi_handle[0], &instance->peer_version) == 0) - LOG_DBG("%s: client version %d connected\n", __func__, instance->peer_version); - - m.type = VC_AUDIO_MSG_TYPE_WRITE; - m.u.write.count = count; - // old version uses bulk, new version uses control - m.u.write.max_packet = instance->peer_version < 2 || force_bulk ? 0 : 4000; - m.u.write.cookie1 = BCM2835_AUDIO_WRITE_COOKIE1; - m.u.write.cookie2 = BCM2835_AUDIO_WRITE_COOKIE2; - m.u.write.silence = src == NULL; - - /* Send the message to the videocore */ - status = bcm2835_vchi_msg_queue(instance->vchi_handle[0], - &m, sizeof(m)); + struct vc_audio_msg m = { + .type = VC_AUDIO_MSG_TYPE_WRITE, + .u.write.count = size, + .u.write.max_packet = instance->max_packet, + .u.write.cookie1 = BCM2835_AUDIO_WRITE_COOKIE1, + .u.write.cookie2 = BCM2835_AUDIO_WRITE_COOKIE2, + }; + unsigned int count; + int err, status; - if (status) { - LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n", - __func__, status); + if (!size) + return 0; - ret = -1; + bcm2835_audio_lock(instance); + err = bcm2835_audio_send_msg_locked(instance, &m, false); + if (err < 0) goto unlock; - } - if (!m.u.write.silence) { - if (!m.u.write.max_packet) { - /* Send the message to the videocore */ - status = vchi_bulk_queue_transmit(instance->vchi_handle[0], - src, count, - 0 * VCHI_FLAGS_BLOCK_UNTIL_QUEUED - + - 1 * VCHI_FLAGS_BLOCK_UNTIL_DATA_READ, - NULL); - } else { - while (count > 0) { - int bytes = min_t(int, m.u.write.max_packet, count); - - status = bcm2835_vchi_msg_queue(instance->vchi_handle[0], - src, bytes); - src = (char *)src + bytes; - count -= bytes; - } - } - if (status) { - LOG_ERR("%s: failed on vchi_bulk_queue_transmit (status=%d)\n", - __func__, status); - ret = -1; - goto unlock; + count = size; + if (!instance->max_packet) { + /* Send the message to the videocore */ + status = vchi_bulk_queue_transmit(instance->vchi_handle, + src, count, + VCHI_FLAGS_BLOCK_UNTIL_DATA_READ, + NULL); + } else { + while (count > 0) { + int bytes = min(instance->max_packet, count); + + status = vchi_queue_kernel_message(instance->vchi_handle, + src, bytes); + src += bytes; + count -= bytes; } } - ret = 0; - -unlock: - vchi_service_release(instance->vchi_handle[0]); - mutex_unlock(&instance->vchi_mutex); - return ret; -} - -/** - * Returns all buffers from arm->vc - */ -void bcm2835_audio_flush_buffers(struct bcm2835_alsa_stream *alsa_stream) -{ -} - -/** - * Forces VC to flush(drop) its filled playback buffers and - * return them the us. (VC->ARM) - */ -void bcm2835_audio_flush_playback_buffers(struct bcm2835_alsa_stream *alsa_stream) -{ -} -unsigned int bcm2835_audio_retrieve_buffers(struct bcm2835_alsa_stream *alsa_stream) -{ - unsigned int count = atomic_read(&alsa_stream->retrieved); + if (status) { + dev_err(instance->dev, + "failed on %d bytes transfer (status=%d)\n", + size, status); + err = -EIO; + } - atomic_sub(count, &alsa_stream->retrieved); - return count; + unlock: + bcm2835_audio_unlock(instance); + return err; } - -module_param(force_bulk, bool, 0444); -MODULE_PARM_DESC(force_bulk, "Force use of vchiq bulk for audio"); diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c index da0fa34501fa..87d56ab1ffa0 100644 --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c @@ -22,38 +22,6 @@ module_param(enable_compat_alsa, bool, 0444); MODULE_PARM_DESC(enable_compat_alsa, "Enables ALSA compatibility virtual audio device"); -static void snd_devm_unregister_child(struct device *dev, void *res) -{ - struct device *childdev = *(struct device **)res; - struct bcm2835_chip *chip = dev_get_drvdata(childdev); - struct snd_card *card = chip->card; - - snd_card_free(card); - - device_unregister(childdev); -} - -static int snd_devm_add_child(struct device *dev, struct device *child) -{ - struct device **dr; - int ret; - - dr = devres_alloc(snd_devm_unregister_child, sizeof(*dr), GFP_KERNEL); - if (!dr) - return -ENOMEM; - - ret = device_add(child); - if (ret) { - devres_free(dr); - return ret; - } - - *dr = child; - devres_add(dev, dr); - - return 0; -} - static void bcm2835_devm_free_vchi_ctx(struct device *dev, void *res) { struct bcm2835_vchi_ctx *vchi_ctx = res; @@ -73,7 +41,7 @@ static int bcm2835_devm_add_vchi_ctx(struct device *dev) memset(vchi_ctx, 0, sizeof(*vchi_ctx)); - ret = bcm2835_new_vchi_ctx(vchi_ctx); + ret = bcm2835_new_vchi_ctx(dev, vchi_ctx); if (ret) { devres_free(vchi_ctx); return ret; @@ -84,101 +52,6 @@ static int bcm2835_devm_add_vchi_ctx(struct device *dev) return 0; } -static void snd_bcm2835_release(struct device *dev) -{ - struct bcm2835_chip *chip = dev_get_drvdata(dev); - - kfree(chip); -} - -static struct device * -snd_create_device(struct device *parent, - struct device_driver *driver, - const char *name) -{ - struct device *device; - int ret; - - device = devm_kzalloc(parent, sizeof(*device), GFP_KERNEL); - if (!device) - return ERR_PTR(-ENOMEM); - - device_initialize(device); - device->parent = parent; - device->driver = driver; - device->release = snd_bcm2835_release; - - dev_set_name(device, "%s", name); - - ret = snd_devm_add_child(parent, device); - if (ret) - return ERR_PTR(ret); - - return device; -} - -/* component-destructor - * (see "Management of Cards and Components") - */ -static int snd_bcm2835_dev_free(struct snd_device *device) -{ - struct bcm2835_chip *chip = device->device_data; - struct snd_card *card = chip->card; - - snd_device_free(card, chip); - - return 0; -} - -/* chip-specific constructor - * (see "Management of Cards and Components") - */ -static int snd_bcm2835_create(struct snd_card *card, - struct bcm2835_chip **rchip) -{ - struct bcm2835_chip *chip; - int err; - static struct snd_device_ops ops = { - .dev_free = snd_bcm2835_dev_free, - }; - - *rchip = NULL; - - chip = kzalloc(sizeof(*chip), GFP_KERNEL); - if (!chip) - return -ENOMEM; - - chip->card = card; - - chip->vchi_ctx = devres_find(card->dev->parent, - bcm2835_devm_free_vchi_ctx, NULL, NULL); - if (!chip->vchi_ctx) { - kfree(chip); - return -ENODEV; - } - - err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); - if (err) { - kfree(chip); - return err; - } - - *rchip = chip; - return 0; -} - -static struct snd_card *snd_bcm2835_card_new(struct device *dev) -{ - struct snd_card *card; - int ret; - - ret = snd_card_new(dev, -1, NULL, THIS_MODULE, 0, &card); - if (ret) - return ERR_PTR(ret); - - return card; -} - typedef int (*bcm2835_audio_newpcm_func)(struct bcm2835_chip *chip, const char *name, enum snd_bcm2835_route route, @@ -203,17 +76,26 @@ static int bcm2835_audio_alsa_newpcm(struct bcm2835_chip *chip, { int err; - err = snd_bcm2835_new_pcm(chip, numchannels - 1); + err = snd_bcm2835_new_pcm(chip, "bcm2835 ALSA", 0, AUDIO_DEST_AUTO, + numchannels - 1, false); if (err) return err; - err = snd_bcm2835_new_spdif_pcm(chip); + err = snd_bcm2835_new_pcm(chip, "bcm2835 IEC958/HDMI", 1, 0, 1, true); if (err) return err; return 0; } +static int bcm2835_audio_simple_newpcm(struct bcm2835_chip *chip, + const char *name, + enum snd_bcm2835_route route, + u32 numchannels) +{ + return snd_bcm2835_new_pcm(chip, name, 0, route, numchannels, false); +} + static struct bcm2835_audio_driver bcm2835_audio_alsa = { .driver = { .name = "bcm2835_alsa", @@ -234,7 +116,7 @@ static struct bcm2835_audio_driver bcm2835_audio_hdmi = { .shortname = "bcm2835 HDMI", .longname = "bcm2835 HDMI", .minchannels = 1, - .newpcm = snd_bcm2835_new_simple_pcm, + .newpcm = bcm2835_audio_simple_newpcm, .newctl = snd_bcm2835_new_hdmi_ctl, .route = AUDIO_DEST_HDMI }; @@ -247,7 +129,7 @@ static struct bcm2835_audio_driver bcm2835_audio_headphones = { .shortname = "bcm2835 Headphones", .longname = "bcm2835 Headphones", .minchannels = 1, - .newpcm = snd_bcm2835_new_simple_pcm, + .newpcm = bcm2835_audio_simple_newpcm, .newctl = snd_bcm2835_new_headphones_ctl, .route = AUDIO_DEST_HEADPHONES }; @@ -272,71 +154,75 @@ static struct bcm2835_audio_drivers children_devices[] = { }, }; -static int snd_add_child_device(struct device *device, +static void bcm2835_card_free(void *data) +{ + snd_card_free(data); +} + +static int snd_add_child_device(struct device *dev, struct bcm2835_audio_driver *audio_driver, u32 numchans) { struct snd_card *card; - struct device *child; struct bcm2835_chip *chip; - int err, i; - - child = snd_create_device(device, &audio_driver->driver, - audio_driver->driver.name); - if (IS_ERR(child)) { - dev_err(device, - "Unable to create child device %p, error %ld", - audio_driver->driver.name, - PTR_ERR(child)); - return PTR_ERR(child); + int err; + + err = snd_card_new(dev, -1, NULL, THIS_MODULE, sizeof(*chip), &card); + if (err < 0) { + dev_err(dev, "Failed to create card"); + return err; } - card = snd_bcm2835_card_new(child); - if (IS_ERR(card)) { - dev_err(child, "Failed to create card"); - return PTR_ERR(card); + chip = card->private_data; + chip->card = card; + chip->dev = dev; + mutex_init(&chip->audio_mutex); + + chip->vchi_ctx = devres_find(dev, + bcm2835_devm_free_vchi_ctx, NULL, NULL); + if (!chip->vchi_ctx) { + err = -ENODEV; + goto error; } - snd_card_set_dev(card, child); strcpy(card->driver, audio_driver->driver.name); strcpy(card->shortname, audio_driver->shortname); strcpy(card->longname, audio_driver->longname); - err = snd_bcm2835_create(card, &chip); - if (err) { - dev_err(child, "Failed to create chip, error %d\n", err); - return err; - } - - chip->dev = child; - err = audio_driver->newpcm(chip, audio_driver->shortname, audio_driver->route, numchans); if (err) { - dev_err(child, "Failed to create pcm, error %d\n", err); - return err; + dev_err(dev, "Failed to create pcm, error %d\n", err); + goto error; } err = audio_driver->newctl(chip); if (err) { - dev_err(child, "Failed to create controls, error %d\n", err); - return err; + dev_err(dev, "Failed to create controls, error %d\n", err); + goto error; } - for (i = 0; i < numchans; i++) - chip->avail_substreams |= (1 << i); - err = snd_card_register(card); if (err) { - dev_err(child, "Failed to register card, error %d\n", err); - return err; + dev_err(dev, "Failed to register card, error %d\n", err); + goto error; } - dev_set_drvdata(child, chip); - dev_info(child, "card created with %d channels\n", numchans); + dev_set_drvdata(dev, chip); + + err = devm_add_action(dev, bcm2835_card_free, card); + if (err < 0) { + dev_err(dev, "Failed to add devm action, err %d\n", err); + goto error; + } + dev_info(dev, "card created with %d channels\n", numchans); return 0; + + error: + snd_card_free(card); + return err; } static int snd_add_child_devices(struct device *device, u32 numchans) diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.h b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.h index 5dc427240a1d..e13435d1c205 100644 --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.h +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.h @@ -5,59 +5,12 @@ #define __SOUND_ARM_BCM2835_H #include <linux/device.h> -#include <linux/list.h> -#include <linux/interrupt.h> #include <linux/wait.h> #include <sound/core.h> -#include <sound/initval.h> #include <sound/pcm.h> -#include <sound/pcm_params.h> #include <sound/pcm-indirect.h> -#include <linux/workqueue.h> - #include "interface/vchi/vchi.h" -/* - * #define AUDIO_DEBUG_ENABLE - * #define AUDIO_VERBOSE_DEBUG_ENABLE - */ - -/* Debug macros */ - -#ifdef AUDIO_DEBUG_ENABLE -#ifdef AUDIO_VERBOSE_DEBUG_ENABLE - -#define audio_debug(fmt, arg...) \ - pr_info("%s:%d " fmt, __func__, __LINE__, ##arg) - -#define audio_info(fmt, arg...) \ - pr_info("%s:%d " fmt, __func__, __LINE__, ##arg) - -#else - -#define audio_debug(fmt, arg...) - -#define audio_info(fmt, arg...) - -#endif /* AUDIO_VERBOSE_DEBUG_ENABLE */ - -#else - -#define audio_debug(fmt, arg...) - -#define audio_info(fmt, arg...) - -#endif /* AUDIO_DEBUG_ENABLE */ - -#define audio_error(fmt, arg...) \ - pr_err("%s:%d " fmt, __func__, __LINE__, ##arg) - -#define audio_warning(fmt, arg...) \ - pr_warn("%s:%d " fmt, __func__, __LINE__, ##arg) - -#define audio_alert(fmt, arg...) \ - pr_alert("%s:%d " fmt, __func__, __LINE__, ##arg) - #define MAX_SUBSTREAMS (8) #define AVAIL_SUBSTREAMS_MASK (0xff) @@ -74,6 +27,8 @@ enum { // convert chip to alsa volume #define chip2alsa(vol) -(((vol) * 100) >> 8) +#define CHIP_MIN_VOLUME 26214 /* minimum level aka mute */ + /* Some constants for values .. */ enum snd_bcm2835_route { AUDIO_DEST_AUTO = 0, @@ -98,13 +53,10 @@ struct bcm2835_chip { struct snd_card *card; struct snd_pcm *pcm; struct snd_pcm *pcm_spdif; - /* Bitmat for valid reg_base and irq numbers */ - unsigned int avail_substreams; struct device *dev; struct bcm2835_alsa_stream *alsa_stream[MAX_SUBSTREAMS]; int volume; - int old_volume; /* stores the volume value whist muted */ int dest; int mute; @@ -120,38 +72,26 @@ struct bcm2835_alsa_stream { struct snd_pcm_substream *substream; struct snd_pcm_indirect pcm_indirect; - spinlock_t lock; - - int open; - int running; int draining; - int channels; - int params_rate; - int pcm_format_width; - - unsigned int pos; + atomic_t pos; + unsigned int period_offset; unsigned int buffer_size; unsigned int period_size; - atomic_t retrieved; struct bcm2835_audio_instance *instance; - struct workqueue_struct *my_wq; int idx; }; int snd_bcm2835_new_ctl(struct bcm2835_chip *chip); -int snd_bcm2835_new_pcm(struct bcm2835_chip *chip, u32 numchannels); -int snd_bcm2835_new_spdif_pcm(struct bcm2835_chip *chip); -int snd_bcm2835_new_simple_pcm(struct bcm2835_chip *chip, - const char *name, - enum snd_bcm2835_route route, - u32 numchannels); +int snd_bcm2835_new_pcm(struct bcm2835_chip *chip, const char *name, + int idx, enum snd_bcm2835_route route, + u32 numchannels, bool spdif); int snd_bcm2835_new_hdmi_ctl(struct bcm2835_chip *chip); int snd_bcm2835_new_headphones_ctl(struct bcm2835_chip *chip); -int bcm2835_new_vchi_ctx(struct bcm2835_vchi_ctx *vchi_ctx); +int bcm2835_new_vchi_ctx(struct device *dev, struct bcm2835_vchi_ctx *vchi_ctx); void bcm2835_free_vchi_ctx(struct bcm2835_vchi_ctx *vchi_ctx); int bcm2835_audio_open(struct bcm2835_alsa_stream *alsa_stream); @@ -159,16 +99,15 @@ int bcm2835_audio_close(struct bcm2835_alsa_stream *alsa_stream); int bcm2835_audio_set_params(struct bcm2835_alsa_stream *alsa_stream, unsigned int channels, unsigned int samplerate, unsigned int bps); -int bcm2835_audio_setup(struct bcm2835_alsa_stream *alsa_stream); int bcm2835_audio_start(struct bcm2835_alsa_stream *alsa_stream); int bcm2835_audio_stop(struct bcm2835_alsa_stream *alsa_stream); -int bcm2835_audio_set_ctls(struct bcm2835_chip *chip); +int bcm2835_audio_drain(struct bcm2835_alsa_stream *alsa_stream); +int bcm2835_audio_set_ctls(struct bcm2835_alsa_stream *alsa_stream); int bcm2835_audio_write(struct bcm2835_alsa_stream *alsa_stream, unsigned int count, void *src); -void bcm2835_playback_fifo(struct bcm2835_alsa_stream *alsa_stream); +void bcm2835_playback_fifo(struct bcm2835_alsa_stream *alsa_stream, + unsigned int size); unsigned int bcm2835_audio_retrieve_buffers(struct bcm2835_alsa_stream *alsa_stream); -void bcm2835_audio_flush_buffers(struct bcm2835_alsa_stream *alsa_stream); -void bcm2835_audio_flush_playback_buffers(struct bcm2835_alsa_stream *alsa_stream); #endif /* __SOUND_ARM_BCM2835_H */ diff --git a/drivers/staging/wilc1000/coreconfigurator.c b/drivers/staging/wilc1000/coreconfigurator.c index e5420676afb3..d6d3a971be43 100644 --- a/drivers/staging/wilc1000/coreconfigurator.c +++ b/drivers/staging/wilc1000/coreconfigurator.c @@ -116,7 +116,7 @@ static inline void get_address3(u8 *msa, u8 *addr) memcpy(addr, msa + 16, 6); } -static inline void get_BSSID(u8 *data, u8 *bssid) +static inline void get_bssid(u8 *data, u8 *bssid) { if (get_from_ds(data) == 1) get_address2(data, bssid); @@ -233,7 +233,7 @@ s32 wilc_parse_network_info(u8 *msg_buffer, network_info->tsf_hi = tsf_lo | ((u64)tsf_hi << 32); get_ssid(msa, network_info->ssid, &network_info->ssid_len); - get_BSSID(msa, network_info->bssid); + get_bssid(msa, network_info->bssid); network_info->ch = get_current_channel_802_11n(msa, rx_len + FCS_LEN); diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c index 42d8accb1f60..5388be906261 100644 --- a/drivers/staging/wilc1000/host_interface.c +++ b/drivers/staging/wilc1000/host_interface.c @@ -90,6 +90,7 @@ struct beacon_attr { struct set_multicast { bool enabled; u32 cnt; + u8 *mc_list; }; struct del_all_sta { @@ -186,23 +187,8 @@ struct join_bss_param { }; static struct host_if_drv *terminated_handle; -bool wilc_optaining_ip; -static u8 p2p_listen_state; -static struct workqueue_struct *hif_workqueue; static struct completion hif_driver_comp; static struct mutex hif_deinit_lock; -static struct timer_list periodic_rssi; -static struct wilc_vif *periodic_rssi_vif; - -u8 wilc_multicast_mac_addr_list[WILC_MULTICAST_TABLE_SIZE][ETH_ALEN]; - -static u8 rcv_assoc_resp[MAX_ASSOC_RESP_FRAME_SIZE]; - -static u8 set_ip[2][4]; -static u8 get_ip[2][4]; -static u32 clients_count; - -static int host_int_get_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx); /* 'msg' should be free by the caller for syc */ static struct host_if_msg* @@ -229,7 +215,11 @@ wilc_alloc_work(struct wilc_vif *vif, void (*work_fun)(struct work_struct *), static int wilc_enqueue_work(struct host_if_msg *msg) { INIT_WORK(&msg->work, msg->fn); - if (!hif_workqueue || !queue_work(hif_workqueue, &msg->work)) + + if (!msg->vif || !msg->vif->wilc || !msg->vif->wilc->hif_workqueue) + return -EINVAL; + + if (!queue_work(msg->vif->wilc->hif_workqueue, &msg->work)) return -EINVAL; return 0; @@ -352,64 +342,6 @@ static void handle_set_operation_mode(struct work_struct *work) kfree(msg); } -static void handle_set_ip_address(struct work_struct *work) -{ - struct host_if_msg *msg = container_of(work, struct host_if_msg, work); - struct wilc_vif *vif = msg->vif; - u8 *ip_addr = msg->body.ip_info.ip_addr; - u8 idx = msg->body.ip_info.idx; - int ret; - struct wid wid; - char firmware_ip_addr[4] = {0}; - - if (ip_addr[0] < 192) - ip_addr[0] = 0; - - memcpy(set_ip[idx], ip_addr, IP_ALEN); - - wid.id = WID_IP_ADDRESS; - wid.type = WID_STR; - wid.val = ip_addr; - wid.size = IP_ALEN; - - ret = wilc_send_config_pkt(vif, SET_CFG, &wid, 1, - wilc_get_vif_idx(vif)); - - host_int_get_ipaddress(vif, firmware_ip_addr, idx); - - if (ret) - netdev_err(vif->ndev, "Failed to set IP address\n"); - kfree(msg); -} - -static void handle_get_ip_address(struct work_struct *work) -{ - struct host_if_msg *msg = container_of(work, struct host_if_msg, work); - struct wilc_vif *vif = msg->vif; - u8 idx = msg->body.ip_info.idx; - int ret; - struct wid wid; - - wid.id = WID_IP_ADDRESS; - wid.type = WID_STR; - wid.val = kmalloc(IP_ALEN, GFP_KERNEL); - wid.size = IP_ALEN; - - ret = wilc_send_config_pkt(vif, GET_CFG, &wid, 1, - wilc_get_vif_idx(vif)); - - memcpy(get_ip[idx], wid.val, IP_ALEN); - - kfree(wid.val); - - if (memcmp(get_ip[idx], set_ip[idx], IP_ALEN) != 0) - wilc_setup_ipaddress(vif, set_ip[idx], idx); - - if (ret) - netdev_err(vif->ndev, "Failed to get IP address\n"); - kfree(msg); -} - static void handle_get_mac_address(struct work_struct *work) { struct host_if_msg *msg = container_of(work, struct host_if_msg, work); @@ -791,7 +723,7 @@ static void handle_scan(struct work_struct *work) goto error; } - if (wilc_optaining_ip || wilc_connecting) { + if (vif->obtaining_ip || vif->connecting) { netdev_err(vif->ndev, "Don't do obss scan\n"); result = -EBUSY; goto error; @@ -1504,16 +1436,16 @@ static inline void host_int_parse_assoc_resp_info(struct wilc_vif *vif, if (mac_status == MAC_STATUS_CONNECTED) { u32 assoc_resp_info_len; - memset(rcv_assoc_resp, 0, MAX_ASSOC_RESP_FRAME_SIZE); + memset(hif_drv->assoc_resp, 0, MAX_ASSOC_RESP_FRAME_SIZE); - host_int_get_assoc_res_info(vif, rcv_assoc_resp, + host_int_get_assoc_res_info(vif, hif_drv->assoc_resp, MAX_ASSOC_RESP_FRAME_SIZE, &assoc_resp_info_len); if (assoc_resp_info_len != 0) { s32 err = 0; - err = wilc_parse_assoc_resp_info(rcv_assoc_resp, + err = wilc_parse_assoc_resp_info(hif_drv->assoc_resp, assoc_resp_info_len, &conn_info); if (err) @@ -1562,8 +1494,8 @@ static inline void host_int_parse_assoc_resp_info(struct wilc_vif *vif, hif_drv->hif_state = HOST_IF_CONNECTED; - wilc_optaining_ip = true; - mod_timer(&wilc_during_ip_timer, + vif->obtaining_ip = true; + mod_timer(&vif->during_ip_timer, jiffies + msecs_to_jiffies(10000)); } else { hif_drv->hif_state = HOST_IF_IDLE; @@ -1595,7 +1527,7 @@ static inline void host_int_handle_disconnect(struct wilc_vif *vif) disconn_info.ie_len = 0; if (conn_result) { - wilc_optaining_ip = false; + vif->obtaining_ip = false; wilc_set_power_mgmt(vif, 0, 0); conn_result(CONN_DISCONN_EVENT_DISCONN_NOTIF, NULL, 0, @@ -1942,7 +1874,7 @@ static void handle_disconnect(struct work_struct *work) wid.val = (s8 *)&dummy_reason_code; wid.size = sizeof(char); - wilc_optaining_ip = false; + vif->obtaining_ip = false; wilc_set_power_mgmt(vif, 0, 0); eth_zero_addr(wilc_connected_ssid); @@ -2076,9 +2008,9 @@ static void handle_get_statistics(struct work_struct *work) if (stats->link_speed > TCP_ACK_FILTER_LINK_SPEED_THRESH && stats->link_speed != DEFAULT_LINK_SPEED) - wilc_enable_tcp_ack_filter(true); + wilc_enable_tcp_ack_filter(vif, true); else if (stats->link_speed != DEFAULT_LINK_SPEED) - wilc_enable_tcp_ack_filter(false); + wilc_enable_tcp_ack_filter(vif, false); /* free 'msg' for async command, for sync caller will free it */ if (msg->is_sync) @@ -2397,7 +2329,7 @@ static int handle_remain_on_chan(struct wilc_vif *vif, goto error; } - if (wilc_optaining_ip || wilc_connecting) { + if (vif->obtaining_ip || vif->connecting) { result = -EBUSY; goto error; } @@ -2422,7 +2354,6 @@ static int handle_remain_on_chan(struct wilc_vif *vif, netdev_err(vif->ndev, "Failed to set remain on channel\n"); error: - p2p_listen_state = 1; hif_drv->remain_on_ch_timer_vif = vif; mod_timer(&hif_drv->remain_on_ch_timer, jiffies + msecs_to_jiffies(hif_remain_ch->duration)); @@ -2478,8 +2409,9 @@ static void handle_listen_state_expired(struct work_struct *work) struct wid wid; int result; struct host_if_drv *hif_drv = vif->hif_drv; + struct wilc_priv *priv = wdev_priv(vif->ndev->ieee80211_ptr); - if (p2p_listen_state) { + if (priv->p2p_listen_state) { remain_on_chan_flag = false; wid.id = WID_REMAIN_ON_CHAN; wid.type = WID_STR; @@ -2504,7 +2436,6 @@ static void handle_listen_state_expired(struct work_struct *work) hif_drv->remain_on_ch.expired(hif_drv->remain_on_ch.arg, hif_remain_ch->id); } - p2p_listen_state = 0; } else { netdev_dbg(vif->ndev, "Not in listen state\n"); } @@ -2589,8 +2520,8 @@ static void handle_set_mcast_filter(struct work_struct *work) *cur_byte++ = ((hif_set_mc->cnt >> 16) & 0xFF); *cur_byte++ = ((hif_set_mc->cnt >> 24) & 0xFF); - if (hif_set_mc->cnt > 0) - memcpy(cur_byte, wilc_multicast_mac_addr_list, + if (hif_set_mc->cnt > 0 && hif_set_mc->mc_list) + memcpy(cur_byte, hif_set_mc->mc_list, ((hif_set_mc->cnt) * ETH_ALEN)); result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1, @@ -2599,6 +2530,7 @@ static void handle_set_mcast_filter(struct work_struct *work) netdev_err(vif->ndev, "Failed to send setup multicast\n"); error: + kfree(hif_set_mc->mc_list); kfree(wid.val); kfree(msg); } @@ -2661,14 +2593,6 @@ static void handle_remain_on_chan_work(struct work_struct *work) kfree(msg); } -static void handle_hif_exit_work(struct work_struct *work) -{ - struct host_if_msg *msg = container_of(work, struct host_if_msg, work); - - /* free 'msg' data in caller */ - complete(&msg->work_comp); -} - static void handle_scan_complete(struct work_struct *work) { struct host_if_msg *msg = container_of(work, struct host_if_msg, work); @@ -3421,9 +3345,9 @@ int wilc_hif_set_cfg(struct wilc_vif *vif, return result; } -static void get_periodic_rssi(struct timer_list *unused) +static void get_periodic_rssi(struct timer_list *t) { - struct wilc_vif *vif = periodic_rssi_vif; + struct wilc_vif *vif = from_timer(vif, t, periodic_rssi); if (!vif->hif_drv) { netdev_err(vif->ndev, "%s: hif driver is NULL", __func__); @@ -3431,9 +3355,9 @@ static void get_periodic_rssi(struct timer_list *unused) } if (vif->hif_drv->hif_state == HOST_IF_CONNECTED) - wilc_get_statistics(vif, &vif->wilc->dummy_statistics, false); + wilc_get_statistics(vif, &vif->periodic_stat, false); - mod_timer(&periodic_rssi, jiffies + msecs_to_jiffies(5000)); + mod_timer(&vif->periodic_rssi, jiffies + msecs_to_jiffies(5000)); } int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler) @@ -3455,25 +3379,15 @@ int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler) break; } - wilc_optaining_ip = false; + vif->obtaining_ip = false; - if (clients_count == 0) { + if (wilc->clients_count == 0) { init_completion(&hif_driver_comp); mutex_init(&hif_deinit_lock); } - if (clients_count == 0) { - hif_workqueue = create_singlethread_workqueue("WILC_wq"); - if (!hif_workqueue) { - netdev_err(vif->ndev, "Failed to create workqueue\n"); - kfree(hif_drv); - return -ENOMEM; - } - - periodic_rssi_vif = vif; - timer_setup(&periodic_rssi, get_periodic_rssi, 0); - mod_timer(&periodic_rssi, jiffies + msecs_to_jiffies(5000)); - } + timer_setup(&vif->periodic_rssi, get_periodic_rssi, 0); + mod_timer(&vif->periodic_rssi, jiffies + msecs_to_jiffies(5000)); timer_setup(&hif_drv->scan_timer, timer_scan_cb, 0); timer_setup(&hif_drv->connect_timer, timer_connect_cb, 0); @@ -3493,7 +3407,7 @@ int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler) mutex_unlock(&hif_drv->cfg_values_lock); - clients_count++; + wilc->clients_count++; return 0; } @@ -3514,7 +3428,7 @@ int wilc_deinit(struct wilc_vif *vif) del_timer_sync(&hif_drv->scan_timer); del_timer_sync(&hif_drv->connect_timer); - del_timer_sync(&periodic_rssi); + del_timer_sync(&vif->periodic_rssi); del_timer_sync(&hif_drv->remain_on_ch_timer); wilc_set_wfi_drv_handler(vif, 0, 0, 0); @@ -3529,25 +3443,9 @@ int wilc_deinit(struct wilc_vif *vif) hif_drv->hif_state = HOST_IF_IDLE; - if (clients_count == 1) { - struct host_if_msg *msg; - - msg = wilc_alloc_work(vif, handle_hif_exit_work, true); - if (!IS_ERR(msg)) { - result = wilc_enqueue_work(msg); - if (result) - netdev_err(vif->ndev, "deinit : Error(%d)\n", - result); - else - wait_for_completion(&msg->work_comp); - kfree(msg); - } - destroy_workqueue(hif_workqueue); - } - kfree(hif_drv); - clients_count--; + vif->wilc->clients_count--; terminated_handle = NULL; mutex_unlock(&hif_deinit_lock); return result; @@ -3992,8 +3890,8 @@ int wilc_set_power_mgmt(struct wilc_vif *vif, bool enabled, u32 timeout) return result; } -int wilc_setup_multicast_filter(struct wilc_vif *vif, bool enabled, - u32 count) +int wilc_setup_multicast_filter(struct wilc_vif *vif, bool enabled, u32 count, + u8 *mc_list) { int result; struct host_if_msg *msg; @@ -4004,6 +3902,7 @@ int wilc_setup_multicast_filter(struct wilc_vif *vif, bool enabled, msg->body.multicast_info.enabled = enabled; msg->body.multicast_info.cnt = count; + msg->body.multicast_info.mc_list = mc_list; result = wilc_enqueue_work(msg); if (result) { @@ -4013,48 +3912,6 @@ int wilc_setup_multicast_filter(struct wilc_vif *vif, bool enabled, return result; } -int wilc_setup_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx) -{ - int result; - struct host_if_msg *msg; - - msg = wilc_alloc_work(vif, handle_set_ip_address, false); - if (IS_ERR(msg)) - return PTR_ERR(msg); - - msg->body.ip_info.ip_addr = ip_addr; - msg->body.ip_info.idx = idx; - - result = wilc_enqueue_work(msg); - if (result) { - netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__); - kfree(msg); - } - - return result; -} - -static int host_int_get_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx) -{ - int result; - struct host_if_msg *msg; - - msg = wilc_alloc_work(vif, handle_get_ip_address, false); - if (IS_ERR(msg)) - return PTR_ERR(msg); - - msg->body.ip_info.ip_addr = ip_addr; - msg->body.ip_info.idx = idx; - - result = wilc_enqueue_work(msg); - if (result) { - netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__); - kfree(msg); - } - - return result; -} - int wilc_set_tx_power(struct wilc_vif *vif, u8 tx_power) { int ret; diff --git a/drivers/staging/wilc1000/host_interface.h b/drivers/staging/wilc1000/host_interface.h index 84866a62a4d4..a48818f6c4fc 100644 --- a/drivers/staging/wilc1000/host_interface.h +++ b/drivers/staging/wilc1000/host_interface.h @@ -9,8 +9,6 @@ #include <linux/ieee80211.h> #include "coreconfigurator.h" -#define IP_ALEN 4 - #define IDLE_MODE 0x00 #define AP_MODE 0x01 #define STATION_MODE 0x02 @@ -284,6 +282,7 @@ struct host_if_drv { bool ifc_up; int driver_handler_id; + u8 assoc_resp[MAX_ASSOC_RESP_FRAME_SIZE]; }; struct add_sta_param { @@ -341,9 +340,8 @@ int wilc_del_station(struct wilc_vif *vif, const u8 *mac_addr); int wilc_edit_station(struct wilc_vif *vif, struct add_sta_param *sta_param); int wilc_set_power_mgmt(struct wilc_vif *vif, bool enabled, u32 timeout); -int wilc_setup_multicast_filter(struct wilc_vif *vif, bool enabled, - u32 count); -int wilc_setup_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx); +int wilc_setup_multicast_filter(struct wilc_vif *vif, bool enabled, u32 count, + u8 *mc_list); int wilc_remain_on_channel(struct wilc_vif *vif, u32 session_id, u32 duration, u16 chan, wilc_remain_on_chan_expired expired, @@ -361,11 +359,6 @@ int wilc_get_vif_idx(struct wilc_vif *vif); int wilc_set_tx_power(struct wilc_vif *vif, u8 tx_power); int wilc_get_tx_power(struct wilc_vif *vif, u8 *tx_power); -extern bool wilc_optaining_ip; extern u8 wilc_connected_ssid[6]; -extern u8 wilc_multicast_mac_addr_list[WILC_MULTICAST_TABLE_SIZE][ETH_ALEN]; - -extern int wilc_connecting; -extern struct timer_list wilc_during_ip_timer; #endif diff --git a/drivers/staging/wilc1000/linux_wlan.c b/drivers/staging/wilc1000/linux_wlan.c index 3b8d237decbf..a498321c908b 100644 --- a/drivers/staging/wilc1000/linux_wlan.c +++ b/drivers/staging/wilc1000/linux_wlan.c @@ -12,8 +12,6 @@ #include "wilc_wfi_cfgoperations.h" -bool wilc_enable_ps = true; - static int dev_state_ev_handler(struct notifier_block *this, unsigned long event, void *ptr) { @@ -50,11 +48,11 @@ static int dev_state_ev_handler(struct notifier_block *this, case NETDEV_UP: if (vif->iftype == STATION_MODE || vif->iftype == CLIENT_MODE) { hif_drv->ifc_up = 1; - wilc_optaining_ip = false; - del_timer(&wilc_during_ip_timer); + vif->obtaining_ip = false; + del_timer(&vif->during_ip_timer); } - if (wilc_enable_ps) + if (vif->wilc->enable_ps) wilc_set_power_mgmt(vif, 1, 0); netdev_dbg(dev, "[%s] Up IP\n", dev_iface->ifa_label); @@ -63,14 +61,13 @@ static int dev_state_ev_handler(struct notifier_block *this, netdev_dbg(dev, "IP add=%d:%d:%d:%d\n", ip_addr_buf[0], ip_addr_buf[1], ip_addr_buf[2], ip_addr_buf[3]); - wilc_setup_ipaddress(vif, ip_addr_buf, vif->idx); break; case NETDEV_DOWN: if (vif->iftype == STATION_MODE || vif->iftype == CLIENT_MODE) { hif_drv->ifc_up = 0; - wilc_optaining_ip = false; + vif->obtaining_ip = false; } if (memcmp(dev_iface->ifa_label, wlan_dev_name, 5) == 0) @@ -85,8 +82,6 @@ static int dev_state_ev_handler(struct notifier_block *this, ip_addr_buf[0], ip_addr_buf[1], ip_addr_buf[2], ip_addr_buf[3]); - wilc_setup_ipaddress(vif, ip_addr_buf, vif->idx); - break; default: @@ -808,34 +803,38 @@ static void wilc_set_multicast_list(struct net_device *dev) struct netdev_hw_addr *ha; struct wilc_vif *vif = netdev_priv(dev); int i = 0; + u8 *mc_list; + int res; if (dev->flags & IFF_PROMISC) return; if (dev->flags & IFF_ALLMULTI || dev->mc.count > WILC_MULTICAST_TABLE_SIZE) { - wilc_setup_multicast_filter(vif, false, 0); + wilc_setup_multicast_filter(vif, false, 0, NULL); return; } if (dev->mc.count == 0) { - wilc_setup_multicast_filter(vif, true, 0); + wilc_setup_multicast_filter(vif, true, 0, NULL); return; } + mc_list = kmalloc(dev->mc.count * ETH_ALEN, GFP_KERNEL); + if (!mc_list) + return; + netdev_for_each_mc_addr(ha, dev) { - memcpy(wilc_multicast_mac_addr_list[i], ha->addr, ETH_ALEN); - netdev_dbg(dev, "Entry[%d]: %x:%x:%x:%x:%x:%x\n", i, - wilc_multicast_mac_addr_list[i][0], - wilc_multicast_mac_addr_list[i][1], - wilc_multicast_mac_addr_list[i][2], - wilc_multicast_mac_addr_list[i][3], - wilc_multicast_mac_addr_list[i][4], - wilc_multicast_mac_addr_list[i][5]); - i++; + memcpy(mc_list + i, ha->addr, ETH_ALEN); + netdev_dbg(dev, "Entry[%d]: %x:%x:%x:%x:%x:%x\n", i/ETH_ALEN, + mc_list[i], mc_list[i + 1], mc_list[i + 2], + mc_list[i + 3], mc_list[i + 4], mc_list[i + 5]); + i += ETH_ALEN; } - wilc_setup_multicast_filter(vif, true, (dev->mc.count)); + res = wilc_setup_multicast_filter(vif, true, dev->mc.count, mc_list); + if (res) + kfree(mc_list); } static void linux_wlan_tx_complete(void *priv, int status) @@ -1037,6 +1036,8 @@ void wilc_netdev_cleanup(struct wilc *wilc) } } + flush_workqueue(wilc->hif_workqueue); + destroy_workqueue(wilc->hif_workqueue); kfree(wilc); } EXPORT_SYMBOL_GPL(wilc_netdev_cleanup); @@ -1065,9 +1066,15 @@ int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type, *wilc = wl; wl->io_type = io_type; wl->hif_func = ops; + wl->enable_ps = true; + wl->chip_ps_state = CHIP_WAKEDUP; INIT_LIST_HEAD(&wl->txq_head.list); INIT_LIST_HEAD(&wl->rxq_head.list); + wl->hif_workqueue = create_singlethread_workqueue("WILC_wq"); + if (!wl->hif_workqueue) + goto free_wl; + register_inetaddr_notifier(&g_dev_notifier); for (i = 0; i < NUM_CONCURRENT_IFC; i++) { @@ -1075,7 +1082,7 @@ int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type, ndev = alloc_etherdev(sizeof(struct wilc_vif)); if (!ndev) - return -ENOMEM; + goto free_ndev; vif = netdev_priv(ndev); memset(vif, 0, sizeof(struct wilc_vif)); @@ -1096,15 +1103,13 @@ int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type, ndev->netdev_ops = &wilc_netdev_ops; wdev = wilc_create_wiphy(ndev, dev); - - if (dev) - SET_NETDEV_DEV(ndev, dev); - if (!wdev) { netdev_err(ndev, "Can't register WILC Wiphy\n"); - return -1; + goto free_ndev; } + SET_NETDEV_DEV(ndev, dev); + vif->ndev->ieee80211_ptr = wdev; vif->ndev->ml_priv = vif; wdev->netdev = vif->ndev; @@ -1115,13 +1120,31 @@ int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type, ret = register_netdev(ndev); if (ret) - return ret; + goto free_ndev; vif->iftype = STATION_MODE; vif->mac_opened = 0; } return 0; + +free_ndev: + for (; i >= 0; i--) { + if (wl->vif[i]) { + if (wl->vif[i]->iftype == STATION_MODE) + unregister_netdev(wl->vif[i]->ndev); + + if (wl->vif[i]->ndev) { + wilc_free_wiphy(wl->vif[i]->ndev); + free_netdev(wl->vif[i]->ndev); + } + } + } + unregister_inetaddr_notifier(&g_dev_notifier); + destroy_workqueue(wl->hif_workqueue); +free_wl: + kfree(wl); + return -ENOMEM; } EXPORT_SYMBOL_GPL(wilc_netdev_init); diff --git a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c index 7cd033004651..37c26d465bcf 100644 --- a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c +++ b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c @@ -82,12 +82,6 @@ static const struct wiphy_wowlan_support wowlan_support = { .flags = WIPHY_WOWLAN_ANY }; -static struct network_info last_scanned_shadow[MAX_NUM_SCANNED_NETWORKS_SHADOW]; -static u32 last_scanned_cnt; -struct timer_list wilc_during_ip_timer; -static struct timer_list aging_timer; -static u8 op_ifcs; - #define CHAN2G(_channel, _freq, _flags) { \ .band = NL80211_BAND_2GHZ, \ .center_freq = (_freq), \ @@ -158,25 +152,18 @@ static struct ieee80211_supported_band wilc_band_2ghz = { #define AGING_TIME (9 * 1000) #define DURING_IP_TIME_OUT 15000 -static void clear_shadow_scan(void) +static void clear_shadow_scan(struct wilc_priv *priv) { int i; - if (op_ifcs != 0) - return; - - del_timer_sync(&aging_timer); + for (i = 0; i < priv->scanned_cnt; i++) { + kfree(priv->scanned_shadow[i].ies); + priv->scanned_shadow[i].ies = NULL; - for (i = 0; i < last_scanned_cnt; i++) { - if (last_scanned_shadow[last_scanned_cnt].ies) { - kfree(last_scanned_shadow[i].ies); - last_scanned_shadow[last_scanned_cnt].ies = NULL; - } - - kfree(last_scanned_shadow[i].join_params); - last_scanned_shadow[i].join_params = NULL; + kfree(priv->scanned_shadow[i].join_params); + priv->scanned_shadow[i].join_params = NULL; } - last_scanned_cnt = 0; + priv->scanned_cnt = 0; } static u32 get_rssi_avg(struct network_info *network_info) @@ -198,14 +185,14 @@ static void refresh_scan(struct wilc_priv *priv, bool direct_scan) struct wiphy *wiphy = priv->dev->ieee80211_ptr->wiphy; int i; - for (i = 0; i < last_scanned_cnt; i++) { + for (i = 0; i < priv->scanned_cnt; i++) { struct network_info *network_info; s32 freq; struct ieee80211_channel *channel; int rssi; struct cfg80211_bss *bss; - network_info = &last_scanned_shadow[i]; + network_info = &priv->scanned_shadow[i]; if (!memcmp("DIRECT-", network_info->ssid, 7) && !direct_scan) continue; @@ -229,62 +216,68 @@ static void refresh_scan(struct wilc_priv *priv, bool direct_scan) } } -static void reset_shadow_found(void) +static void reset_shadow_found(struct wilc_priv *priv) { int i; - for (i = 0; i < last_scanned_cnt; i++) - last_scanned_shadow[i].found = 0; + for (i = 0; i < priv->scanned_cnt; i++) + priv->scanned_shadow[i].found = 0; } -static void update_scan_time(void) +static void update_scan_time(struct wilc_priv *priv) { int i; - for (i = 0; i < last_scanned_cnt; i++) - last_scanned_shadow[i].time_scan = jiffies; + for (i = 0; i < priv->scanned_cnt; i++) + priv->scanned_shadow[i].time_scan = jiffies; } -static void remove_network_from_shadow(struct timer_list *unused) +static void remove_network_from_shadow(struct timer_list *t) { + struct wilc_priv *priv = from_timer(priv, t, aging_timer); unsigned long now = jiffies; int i, j; - for (i = 0; i < last_scanned_cnt; i++) { - if (!time_after(now, last_scanned_shadow[i].time_scan + + for (i = 0; i < priv->scanned_cnt; i++) { + if (!time_after(now, priv->scanned_shadow[i].time_scan + (unsigned long)(SCAN_RESULT_EXPIRE))) continue; - kfree(last_scanned_shadow[i].ies); - last_scanned_shadow[i].ies = NULL; + kfree(priv->scanned_shadow[i].ies); + priv->scanned_shadow[i].ies = NULL; - kfree(last_scanned_shadow[i].join_params); + kfree(priv->scanned_shadow[i].join_params); - for (j = i; (j < last_scanned_cnt - 1); j++) - last_scanned_shadow[j] = last_scanned_shadow[j + 1]; + for (j = i; (j < priv->scanned_cnt - 1); j++) + priv->scanned_shadow[j] = priv->scanned_shadow[j + 1]; - last_scanned_cnt--; + priv->scanned_cnt--; } - if (last_scanned_cnt != 0) - mod_timer(&aging_timer, jiffies + msecs_to_jiffies(AGING_TIME)); + if (priv->scanned_cnt != 0) + mod_timer(&priv->aging_timer, + jiffies + msecs_to_jiffies(AGING_TIME)); } -static void clear_during_ip(struct timer_list *unused) +static void clear_during_ip(struct timer_list *t) { - wilc_optaining_ip = false; + struct wilc_vif *vif = from_timer(vif, t, during_ip_timer); + + vif->obtaining_ip = false; } -static int is_network_in_shadow(struct network_info *nw_info, void *user_void) +static int is_network_in_shadow(struct network_info *nw_info, + struct wilc_priv *priv) { int state = -1; int i; - if (last_scanned_cnt == 0) { - mod_timer(&aging_timer, jiffies + msecs_to_jiffies(AGING_TIME)); + if (priv->scanned_cnt == 0) { + mod_timer(&priv->aging_timer, + jiffies + msecs_to_jiffies(AGING_TIME)); state = -1; } else { - for (i = 0; i < last_scanned_cnt; i++) { - if (memcmp(last_scanned_shadow[i].bssid, + for (i = 0; i < priv->scanned_cnt; i++) { + if (memcmp(priv->scanned_shadow[i].bssid, nw_info->bssid, 6) == 0) { state = i; break; @@ -295,23 +288,23 @@ static int is_network_in_shadow(struct network_info *nw_info, void *user_void) } static void add_network_to_shadow(struct network_info *nw_info, - void *user_void, void *join_params) + struct wilc_priv *priv, void *join_params) { - int ap_found = is_network_in_shadow(nw_info, user_void); + int ap_found = is_network_in_shadow(nw_info, priv); u32 ap_index = 0; u8 rssi_index = 0; struct network_info *shadow_nw_info; - if (last_scanned_cnt >= MAX_NUM_SCANNED_NETWORKS_SHADOW) + if (priv->scanned_cnt >= MAX_NUM_SCANNED_NETWORKS_SHADOW) return; if (ap_found == -1) { - ap_index = last_scanned_cnt; - last_scanned_cnt++; + ap_index = priv->scanned_cnt; + priv->scanned_cnt++; } else { ap_index = ap_found; } - shadow_nw_info = &last_scanned_shadow[ap_index]; + shadow_nw_info = &priv->scanned_shadow[ap_index]; rssi_index = shadow_nw_info->rssi_history.index; shadow_nw_info->rssi_history.samples[rssi_index++] = nw_info->rssi; if (rssi_index == NUM_RSSI) { @@ -403,7 +396,7 @@ static void cfg_scan_result(enum scan_event scan_event, u32 i; for (i = 0; i < priv->rcvd_ch_cnt; i++) { - if (memcmp(last_scanned_shadow[i].bssid, + if (memcmp(priv->scanned_shadow[i].bssid, network_info->bssid, 6) == 0) break; } @@ -411,8 +404,8 @@ static void cfg_scan_result(enum scan_event scan_event, if (i >= priv->rcvd_ch_cnt) return; - last_scanned_shadow[i].rssi = network_info->rssi; - last_scanned_shadow[i].time_scan = jiffies; + priv->scanned_shadow[i].rssi = network_info->rssi; + priv->scanned_shadow[i].time_scan = jiffies; } } else if (scan_event == SCAN_EVENT_DONE) { refresh_scan(priv, false); @@ -438,7 +431,7 @@ static void cfg_scan_result(enum scan_event scan_event, .aborted = false, }; - update_scan_time(); + update_scan_time(priv); refresh_scan(priv, false); cfg80211_scan_done(priv->scan_req, &info); @@ -449,19 +442,17 @@ static void cfg_scan_result(enum scan_event scan_event, } } -static inline bool wilc_wfi_cfg_scan_time_expired(int i) +static inline bool wilc_cfg_scan_time_expired(struct wilc_priv *priv, int i) { unsigned long now = jiffies; - if (time_after(now, last_scanned_shadow[i].time_scan_cached + + if (time_after(now, priv->scanned_shadow[i].time_scan_cached + (unsigned long)(nl80211_SCAN_RESULT_EXPIRE - (1 * HZ)))) return true; else return false; } -int wilc_connecting; - static void cfg_connect_result(enum conn_event conn_disconn_evt, struct connect_info *conn_info, u8 mac_status, @@ -475,7 +466,7 @@ static void cfg_connect_result(enum conn_event conn_disconn_evt, struct host_if_drv *wfi_drv = priv->hif_drv; u8 null_bssid[ETH_ALEN] = {0}; - wilc_connecting = 0; + vif->connecting = false; if (conn_disconn_evt == CONN_DISCONN_EVENT_CONN_RESP) { u16 connect_status; @@ -502,11 +493,11 @@ static void cfg_connect_result(enum conn_event conn_disconn_evt, memcpy(priv->associated_bss, conn_info->bssid, ETH_ALEN); - for (i = 0; i < last_scanned_cnt; i++) { - if (memcmp(last_scanned_shadow[i].bssid, + for (i = 0; i < priv->scanned_cnt; i++) { + if (memcmp(priv->scanned_shadow[i].bssid, conn_info->bssid, ETH_ALEN) == 0) { - if (wilc_wfi_cfg_scan_time_expired(i)) + if (wilc_cfg_scan_time_expired(priv, i)) scan_refresh = true; break; @@ -524,7 +515,7 @@ static void cfg_connect_result(enum conn_event conn_disconn_evt, conn_info->resp_ies_len, connect_status, GFP_KERNEL); } else if (conn_disconn_evt == CONN_DISCONN_EVENT_DISCONN_NOTIF) { - wilc_optaining_ip = false; + vif->obtaining_ip = false; p2p_local_random = 0x01; p2p_recv_random = 0x00; wilc_ie = false; @@ -620,7 +611,7 @@ static int scan(struct wiphy *wiphy, struct cfg80211_scan_request *request) priv->rcvd_ch_cnt = 0; - reset_shadow_found(); + reset_shadow_found(priv); priv->cfg_scanning = true; if (request->n_channels <= MAX_NUM_SCANNED_NETWORKS) { @@ -673,25 +664,25 @@ static int connect(struct wiphy *wiphy, struct net_device *dev, enum authtype auth_type = ANY; u32 cipher_group; - wilc_connecting = 1; + vif->connecting = true; if (!(strncmp(sme->ssid, "DIRECT-", 7))) wfi_drv->p2p_connect = 1; else wfi_drv->p2p_connect = 0; - for (i = 0; i < last_scanned_cnt; i++) { - if (sme->ssid_len == last_scanned_shadow[i].ssid_len && - memcmp(last_scanned_shadow[i].ssid, + for (i = 0; i < priv->scanned_cnt; i++) { + if (sme->ssid_len == priv->scanned_shadow[i].ssid_len && + memcmp(priv->scanned_shadow[i].ssid, sme->ssid, sme->ssid_len) == 0) { if (!sme->bssid) { if (sel_bssi_idx == UINT_MAX || - last_scanned_shadow[i].rssi > - last_scanned_shadow[sel_bssi_idx].rssi) + priv->scanned_shadow[i].rssi > + priv->scanned_shadow[sel_bssi_idx].rssi) sel_bssi_idx = i; } else { - if (memcmp(last_scanned_shadow[i].bssid, + if (memcmp(priv->scanned_shadow[i].bssid, sme->bssid, ETH_ALEN) == 0) { sel_bssi_idx = i; @@ -701,11 +692,11 @@ static int connect(struct wiphy *wiphy, struct net_device *dev, } } - if (sel_bssi_idx < last_scanned_cnt) { - nw_info = &last_scanned_shadow[sel_bssi_idx]; + if (sel_bssi_idx < priv->scanned_cnt) { + nw_info = &priv->scanned_shadow[sel_bssi_idx]; } else { ret = -ENOENT; - wilc_connecting = 0; + vif->connecting = false; return ret; } @@ -748,7 +739,7 @@ static int connect(struct wiphy *wiphy, struct net_device *dev, ret = -ENOTSUPP; netdev_err(dev, "%s: Unsupported cipher\n", __func__); - wilc_connecting = 0; + vif->connecting = false; return ret; } } @@ -799,7 +790,7 @@ static int connect(struct wiphy *wiphy, struct net_device *dev, if (ret != 0) { netdev_err(dev, "wilc_set_join_req(): Error\n"); ret = -ENOENT; - wilc_connecting = 0; + vif->connecting = false; return ret; } @@ -816,7 +807,7 @@ static int disconnect(struct wiphy *wiphy, struct net_device *dev, int ret; u8 null_bssid[ETH_ALEN] = {0}; - wilc_connecting = 0; + vif->connecting = false; if (!wilc) return -EIO; @@ -1132,9 +1123,9 @@ static int get_station(struct wiphy *wiphy, struct net_device *dev, if (stats.link_speed > TCP_ACK_FILTER_LINK_SPEED_THRESH && stats.link_speed != DEFAULT_LINK_SPEED) - wilc_enable_tcp_ack_filter(true); + wilc_enable_tcp_ack_filter(vif, true); else if (stats.link_speed != DEFAULT_LINK_SPEED) - wilc_enable_tcp_ack_filter(false); + wilc_enable_tcp_ack_filter(vif, false); } return 0; } @@ -1732,7 +1723,7 @@ static int set_power_mgmt(struct wiphy *wiphy, struct net_device *dev, if (!priv->hif_drv) return -EIO; - if (wilc_enable_ps) + if (vif->wilc->enable_ps) wilc_set_power_mgmt(vif, enabled, timeout); return 0; @@ -1749,12 +1740,12 @@ static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev, p2p_local_random = 0x01; p2p_recv_random = 0x00; wilc_ie = false; - wilc_optaining_ip = false; - del_timer(&wilc_during_ip_timer); + vif->obtaining_ip = false; + del_timer(&vif->during_ip_timer); switch (type) { case NL80211_IFTYPE_STATION: - wilc_connecting = 0; + vif->connecting = false; dev->ieee80211_ptr->iftype = type; priv->wdev->iftype = type; vif->monitor_flag = 0; @@ -1764,24 +1755,24 @@ static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev, memset(priv->assoc_stainfo.sta_associated_bss, 0, MAX_NUM_STA * ETH_ALEN); - wilc_enable_ps = true; + wl->enable_ps = true; wilc_set_power_mgmt(vif, 1, 0); break; case NL80211_IFTYPE_P2P_CLIENT: - wilc_connecting = 0; + vif->connecting = false; dev->ieee80211_ptr->iftype = type; priv->wdev->iftype = type; vif->monitor_flag = 0; vif->iftype = CLIENT_MODE; wilc_set_operation_mode(vif, STATION_MODE); - wilc_enable_ps = false; + wl->enable_ps = false; wilc_set_power_mgmt(vif, 0, 0); break; case NL80211_IFTYPE_AP: - wilc_enable_ps = false; + wl->enable_ps = false; dev->ieee80211_ptr->iftype = type; priv->wdev->iftype = type; vif->iftype = AP_MODE; @@ -1795,15 +1786,15 @@ static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev, break; case NL80211_IFTYPE_P2P_GO: - wilc_optaining_ip = true; - mod_timer(&wilc_during_ip_timer, + vif->obtaining_ip = true; + mod_timer(&vif->during_ip_timer, jiffies + msecs_to_jiffies(DURING_IP_TIME_OUT)); wilc_set_operation_mode(vif, AP_MODE); dev->ieee80211_ptr->iftype = type; priv->wdev->iftype = type; vif->iftype = GO_MODE; - wilc_enable_ps = false; + wl->enable_ps = false; wilc_set_power_mgmt(vif, 0, 0); break; @@ -2154,8 +2145,12 @@ struct wireless_dev *wilc_create_wiphy(struct net_device *net, set_wiphy_dev(wdev->wiphy, dev); ret = wiphy_register(wdev->wiphy); - if (ret) + if (ret) { netdev_err(net, "Cannot register wiphy device\n"); + wiphy_free(wdev->wiphy); + kfree(wdev); + return NULL; + } priv->dev = net; return wdev; @@ -2165,12 +2160,10 @@ int wilc_init_host_int(struct net_device *net) { int ret; struct wilc_priv *priv = wdev_priv(net->ieee80211_ptr); + struct wilc_vif *vif = netdev_priv(priv->dev); - if (op_ifcs == 0) { - timer_setup(&aging_timer, remove_network_from_shadow, 0); - timer_setup(&wilc_during_ip_timer, clear_during_ip, 0); - } - op_ifcs++; + timer_setup(&priv->aging_timer, remove_network_from_shadow, 0); + timer_setup(&vif->during_ip_timer, clear_during_ip, 0); priv->p2p_listen_state = false; @@ -2190,14 +2183,12 @@ int wilc_deinit_host_int(struct net_device *net) priv->p2p_listen_state = false; - op_ifcs--; - mutex_destroy(&priv->scan_req_lock); ret = wilc_deinit(vif); - clear_shadow_scan(); - if (op_ifcs == 0) - del_timer_sync(&wilc_during_ip_timer); + del_timer_sync(&priv->aging_timer); + clear_shadow_scan(priv); + del_timer_sync(&vif->during_ip_timer); if (ret) netdev_err(net, "Error while deinitializing host interface\n"); diff --git a/drivers/staging/wilc1000/wilc_wfi_netdevice.h b/drivers/staging/wilc1000/wilc_wfi_netdevice.h index b7eee772f3fe..183780803314 100644 --- a/drivers/staging/wilc1000/wilc_wfi_netdevice.h +++ b/drivers/staging/wilc1000/wilc_wfi_netdevice.h @@ -94,7 +94,9 @@ struct wilc_priv { /* mutexes */ struct mutex scan_req_lock; bool p2p_listen_state; - + struct timer_list aging_timer; + struct network_info scanned_shadow[MAX_NUM_SCANNED_NETWORKS_SHADOW]; + int scanned_cnt; }; struct frame_reg { @@ -102,6 +104,32 @@ struct frame_reg { bool reg; }; +#define MAX_TCP_SESSION 25 +#define MAX_PENDING_ACKS 256 + +struct ack_session_info { + u32 seq_num; + u32 bigger_ack_num; + u16 src_port; + u16 dst_port; + u16 status; +}; + +struct pending_acks { + u32 ack_num; + u32 session_index; + struct txq_entry_t *txqe; +}; + +struct tcp_ack_filter { + struct ack_session_info ack_session_info[2 * MAX_TCP_SESSION]; + struct pending_acks pending_acks[MAX_PENDING_ACKS]; + u32 pending_base; + u32 tcp_session; + u32 pending_acks_idx; + bool enabled; +}; + struct wilc_vif { u8 idx; u8 iftype; @@ -116,6 +144,12 @@ struct wilc_vif { struct net_device *ndev; u8 mode; u8 ifc_id; + struct timer_list during_ip_timer; + bool obtaining_ip; + struct timer_list periodic_rssi; + struct rf_info periodic_stat; + struct tcp_ack_filter ack_filter; + bool connecting; }; struct wilc { @@ -165,7 +199,10 @@ struct wilc { struct device *dev; bool suspend_event; - struct rf_info dummy_statistics; + bool enable_ps; + int clients_count; + struct workqueue_struct *hif_workqueue; + enum chip_ps_states chip_ps_state; }; struct wilc_wfi_mon_priv { diff --git a/drivers/staging/wilc1000/wilc_wlan.c b/drivers/staging/wilc1000/wilc_wlan.c index 8b184aa30d25..590a51c52fd0 100644 --- a/drivers/staging/wilc1000/wilc_wlan.c +++ b/drivers/staging/wilc1000/wilc_wlan.c @@ -9,8 +9,6 @@ #include "wilc_wfi_netdevice.h" #include "wilc_wlan_cfg.h" -static enum chip_ps_states chip_ps_state = CHIP_WAKEDUP; - static inline bool is_wilc1000(u32 id) { return ((id & 0xfffff000) == 0x100000 ? true : false); @@ -93,63 +91,46 @@ static int wilc_wlan_txq_add_to_head(struct wilc_vif *vif, return 0; } -struct ack_session_info; -struct ack_session_info { - u32 seq_num; - u32 bigger_ack_num; - u16 src_port; - u16 dst_port; - u16 status; -}; - -struct pending_acks_info { - u32 ack_num; - u32 session_index; - struct txq_entry_t *txqe; -}; - #define NOT_TCP_ACK (-1) -#define MAX_TCP_SESSION 25 -#define MAX_PENDING_ACKS 256 -static struct ack_session_info ack_session_info[2 * MAX_TCP_SESSION]; -static struct pending_acks_info pending_acks_info[MAX_PENDING_ACKS]; - -static u32 pending_base; -static u32 tcp_session; -static u32 pending_acks; - -static inline int add_tcp_session(u32 src_prt, u32 dst_prt, u32 seq) +static inline int add_tcp_session(struct wilc_vif *vif, u32 src_prt, + u32 dst_prt, u32 seq) { - if (tcp_session < 2 * MAX_TCP_SESSION) { - ack_session_info[tcp_session].seq_num = seq; - ack_session_info[tcp_session].bigger_ack_num = 0; - ack_session_info[tcp_session].src_port = src_prt; - ack_session_info[tcp_session].dst_port = dst_prt; - tcp_session++; + struct tcp_ack_filter *f = &vif->ack_filter; + + if (f->tcp_session < 2 * MAX_TCP_SESSION) { + f->ack_session_info[f->tcp_session].seq_num = seq; + f->ack_session_info[f->tcp_session].bigger_ack_num = 0; + f->ack_session_info[f->tcp_session].src_port = src_prt; + f->ack_session_info[f->tcp_session].dst_port = dst_prt; + f->tcp_session++; } return 0; } -static inline int update_tcp_session(u32 index, u32 ack) +static inline int update_tcp_session(struct wilc_vif *vif, u32 index, u32 ack) { + struct tcp_ack_filter *f = &vif->ack_filter; + if (index < 2 * MAX_TCP_SESSION && - ack > ack_session_info[index].bigger_ack_num) - ack_session_info[index].bigger_ack_num = ack; + ack > f->ack_session_info[index].bigger_ack_num) + f->ack_session_info[index].bigger_ack_num = ack; return 0; } -static inline int add_tcp_pending_ack(u32 ack, u32 session_index, +static inline int add_tcp_pending_ack(struct wilc_vif *vif, u32 ack, + u32 session_index, struct txq_entry_t *txqe) { - u32 i = pending_base + pending_acks; + struct tcp_ack_filter *f = &vif->ack_filter; + u32 i = f->pending_base + f->pending_acks_idx; if (i < MAX_PENDING_ACKS) { - pending_acks_info[i].ack_num = ack; - pending_acks_info[i].txqe = txqe; - pending_acks_info[i].session_index = session_index; - txqe->tcp_pending_ack_idx = i; - pending_acks++; + f->pending_acks[i].ack_num = ack; + f->pending_acks[i].txqe = txqe; + f->pending_acks[i].session_index = session_index; + txqe->ack_idx = i; + f->pending_acks_idx++; } return 0; } @@ -162,42 +143,47 @@ static inline void tcp_process(struct net_device *dev, struct txq_entry_t *tqe) unsigned long flags; struct wilc_vif *vif = netdev_priv(dev); struct wilc *wilc = vif->wilc; + struct tcp_ack_filter *f = &vif->ack_filter; + const struct iphdr *ip_hdr_ptr; + const struct tcphdr *tcp_hdr_ptr; + u32 ihl, total_length, data_offset; spin_lock_irqsave(&wilc->txq_spinlock, flags); - if (eth_hdr_ptr->h_proto == htons(ETH_P_IP)) { - const struct iphdr *ip_hdr_ptr = buffer + ETH_HLEN; + if (eth_hdr_ptr->h_proto != htons(ETH_P_IP)) + goto out; - if (ip_hdr_ptr->protocol == IPPROTO_TCP) { - const struct tcphdr *tcp_hdr_ptr; - u32 IHL, total_length, data_offset; + ip_hdr_ptr = buffer + ETH_HLEN; - IHL = ip_hdr_ptr->ihl << 2; - tcp_hdr_ptr = buffer + ETH_HLEN + IHL; - total_length = ntohs(ip_hdr_ptr->tot_len); + if (ip_hdr_ptr->protocol != IPPROTO_TCP) + goto out; - data_offset = tcp_hdr_ptr->doff << 2; - if (total_length == (IHL + data_offset)) { - u32 seq_no, ack_no; + ihl = ip_hdr_ptr->ihl << 2; + tcp_hdr_ptr = buffer + ETH_HLEN + ihl; + total_length = ntohs(ip_hdr_ptr->tot_len); - seq_no = ntohl(tcp_hdr_ptr->seq); - ack_no = ntohl(tcp_hdr_ptr->ack_seq); - for (i = 0; i < tcp_session; i++) { - u32 j = ack_session_info[i].seq_num; + data_offset = tcp_hdr_ptr->doff << 2; + if (total_length == (ihl + data_offset)) { + u32 seq_no, ack_no; - if (i < 2 * MAX_TCP_SESSION && - j == seq_no) { - update_tcp_session(i, ack_no); - break; - } - } - if (i == tcp_session) - add_tcp_session(0, 0, seq_no); + seq_no = ntohl(tcp_hdr_ptr->seq); + ack_no = ntohl(tcp_hdr_ptr->ack_seq); + for (i = 0; i < f->tcp_session; i++) { + u32 j = f->ack_session_info[i].seq_num; - add_tcp_pending_ack(ack_no, i, tqe); + if (i < 2 * MAX_TCP_SESSION && + j == seq_no) { + update_tcp_session(vif, i, ack_no); + break; } } + if (i == f->tcp_session) + add_tcp_session(vif, 0, 0, seq_no); + + add_tcp_pending_ack(vif, ack_no, i, tqe); } + +out: spin_unlock_irqrestore(&wilc->txq_spinlock, flags); } @@ -205,29 +191,31 @@ static int wilc_wlan_txq_filter_dup_tcp_ack(struct net_device *dev) { struct wilc_vif *vif = netdev_priv(dev); struct wilc *wilc = vif->wilc; + struct tcp_ack_filter *f = &vif->ack_filter; u32 i = 0; u32 dropped = 0; unsigned long flags; spin_lock_irqsave(&wilc->txq_spinlock, flags); - for (i = pending_base; i < (pending_base + pending_acks); i++) { - u32 session_index; + for (i = f->pending_base; + i < (f->pending_base + f->pending_acks_idx); i++) { + u32 index; u32 bigger_ack_num; if (i >= MAX_PENDING_ACKS) break; - session_index = pending_acks_info[i].session_index; + index = f->pending_acks[i].session_index; - if (session_index >= 2 * MAX_TCP_SESSION) + if (index >= 2 * MAX_TCP_SESSION) break; - bigger_ack_num = ack_session_info[session_index].bigger_ack_num; + bigger_ack_num = f->ack_session_info[index].bigger_ack_num; - if (pending_acks_info[i].ack_num < bigger_ack_num) { + if (f->pending_acks[i].ack_num < bigger_ack_num) { struct txq_entry_t *tqe; - tqe = pending_acks_info[i].txqe; + tqe = f->pending_acks[i].txqe; if (tqe) { wilc_wlan_txq_remove(wilc, tqe); tqe->status = 1; @@ -239,13 +227,13 @@ static int wilc_wlan_txq_filter_dup_tcp_ack(struct net_device *dev) } } } - pending_acks = 0; - tcp_session = 0; + f->pending_acks_idx = 0; + f->tcp_session = 0; - if (pending_base == 0) - pending_base = MAX_TCP_SESSION; + if (f->pending_base == 0) + f->pending_base = MAX_TCP_SESSION; else - pending_base = 0; + f->pending_base = 0; spin_unlock_irqrestore(&wilc->txq_spinlock, flags); @@ -258,11 +246,9 @@ static int wilc_wlan_txq_filter_dup_tcp_ack(struct net_device *dev) return 1; } -static bool enabled; - -void wilc_enable_tcp_ack_filter(bool value) +void wilc_enable_tcp_ack_filter(struct wilc_vif *vif, bool value) { - enabled = value; + vif->ack_filter.enabled = value; } static int wilc_wlan_txq_add_cfg_pkt(struct wilc_vif *vif, u8 *buffer, @@ -287,7 +273,7 @@ static int wilc_wlan_txq_add_cfg_pkt(struct wilc_vif *vif, u8 *buffer, tqe->buffer_size = buffer_size; tqe->tx_complete_func = NULL; tqe->priv = NULL; - tqe->tcp_pending_ack_idx = NOT_TCP_ACK; + tqe->ack_idx = NOT_TCP_ACK; if (wilc_wlan_txq_add_to_head(vif, tqe)) { kfree(tqe); @@ -319,8 +305,8 @@ int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer, tqe->tx_complete_func = func; tqe->priv = priv; - tqe->tcp_pending_ack_idx = NOT_TCP_ACK; - if (enabled) + tqe->ack_idx = NOT_TCP_ACK; + if (vif->ack_filter.enabled) tcp_process(dev, tqe); wilc_wlan_txq_add_to_tail(dev, tqe); return wilc->txq_entries; @@ -347,7 +333,7 @@ int wilc_wlan_txq_add_mgmt_pkt(struct net_device *dev, void *priv, u8 *buffer, tqe->buffer_size = buffer_size; tqe->tx_complete_func = func; tqe->priv = priv; - tqe->tcp_pending_ack_idx = NOT_TCP_ACK; + tqe->ack_idx = NOT_TCP_ACK; wilc_wlan_txq_add_to_tail(dev, tqe); return 1; } @@ -457,7 +443,7 @@ void chip_wakeup(struct wilc *wilc) } while ((clk_status_reg & 0x1) == 0); } - if (chip_ps_state == CHIP_SLEEPING_MANUAL) { + if (wilc->chip_ps_state == CHIP_SLEEPING_MANUAL) { if (wilc_get_chipid(wilc, false) < 0x1002b0) { u32 val32; @@ -470,20 +456,20 @@ void chip_wakeup(struct wilc *wilc) wilc->hif_func->hif_write_reg(wilc, 0x1e9c, val32); } } - chip_ps_state = CHIP_WAKEDUP; + wilc->chip_ps_state = CHIP_WAKEDUP; } EXPORT_SYMBOL_GPL(chip_wakeup); void wilc_chip_sleep_manually(struct wilc *wilc) { - if (chip_ps_state != CHIP_WAKEDUP) + if (wilc->chip_ps_state != CHIP_WAKEDUP) return; acquire_bus(wilc, ACQUIRE_ONLY); chip_allow_sleep(wilc); wilc->hif_func->hif_write_reg(wilc, 0x10a8, 1); - chip_ps_state = CHIP_SLEEPING_MANUAL; + wilc->chip_ps_state = CHIP_SLEEPING_MANUAL; release_bus(wilc, RELEASE_ONLY); } EXPORT_SYMBOL_GPL(wilc_chip_sleep_manually); @@ -685,9 +671,9 @@ int wilc_wlan_handle_txq(struct net_device *dev, u32 *txq_count) tqe->status = 1; if (tqe->tx_complete_func) tqe->tx_complete_func(tqe->priv, tqe->status); - if (tqe->tcp_pending_ack_idx != NOT_TCP_ACK && - tqe->tcp_pending_ack_idx < MAX_PENDING_ACKS) - pending_acks_info[tqe->tcp_pending_ack_idx].txqe = NULL; + if (tqe->ack_idx != NOT_TCP_ACK && + tqe->ack_idx < MAX_PENDING_ACKS) + vif->ack_filter.pending_acks[tqe->ack_idx].txqe = NULL; kfree(tqe); } while (--entries); diff --git a/drivers/staging/wilc1000/wilc_wlan.h b/drivers/staging/wilc1000/wilc_wlan.h index 7467188dbf2f..8c49c0cdc4ac 100644 --- a/drivers/staging/wilc1000/wilc_wlan.h +++ b/drivers/staging/wilc1000/wilc_wlan.h @@ -212,7 +212,7 @@ struct txq_entry_t { struct list_head list; int type; - int tcp_pending_ack_idx; + int ack_idx; u8 *buffer; int buffer_size; void *priv; @@ -282,14 +282,13 @@ int wilc_wlan_txq_add_mgmt_pkt(struct net_device *dev, void *priv, u8 *buffer, u32 buffer_size, wilc_tx_complete_func_t func); void wilc_chip_sleep_manually(struct wilc *wilc); -void wilc_enable_tcp_ack_filter(bool value); +void wilc_enable_tcp_ack_filter(struct wilc_vif *vif, bool value); int wilc_wlan_get_num_conn_ifcs(struct wilc *wilc); netdev_tx_t wilc_mac_xmit(struct sk_buff *skb, struct net_device *dev); void wilc_wfi_p2p_rx(struct net_device *dev, u8 *buff, u32 size); void host_wakeup_notify(struct wilc *wilc); void host_sleep_notify(struct wilc *wilc); -extern bool wilc_enable_ps; void chip_allow_sleep(struct wilc *wilc); void chip_wakeup(struct wilc *wilc); int wilc_send_config_pkt(struct wilc_vif *vif, u8 mode, struct wid *wids, diff --git a/drivers/staging/wlan-ng/p80211netdev.c b/drivers/staging/wlan-ng/p80211netdev.c index 8258cb5a335d..ae98ac1dd434 100644 --- a/drivers/staging/wlan-ng/p80211netdev.c +++ b/drivers/staging/wlan-ng/p80211netdev.c @@ -927,10 +927,6 @@ static int p80211_rx_typedrop(struct wlandevice *wlandev, u16 fc) /* Classify frame, increment counter */ ftype = WLAN_GET_FC_FTYPE(fc); fstype = WLAN_GET_FC_FSTYPE(fc); -#if 0 - netdev_dbg(wlandev->netdev, "rx_typedrop : ftype=%d fstype=%d.\n", - ftype, fstype); -#endif switch (ftype) { case WLAN_FTYPE_MGMT: if ((wlandev->netdev->flags & IFF_PROMISC) || diff --git a/drivers/staging/wlan-ng/prism2fw.c b/drivers/staging/wlan-ng/prism2fw.c index 4fb91294570d..ddcaac648bd5 100644 --- a/drivers/staging/wlan-ng/prism2fw.c +++ b/drivers/staging/wlan-ng/prism2fw.c @@ -706,7 +706,7 @@ static int plugimage(struct imgchunk *fchunk, unsigned int nfchunks, pr_warn("warning: Failed to find PDR for plugrec 0x%04x.\n", s3plug[i].itemcode); continue; /* and move on to the next PDR */ -#if 0 + /* MSM: They swear that unless it's the MAC address, * the serial number, or the TX calibration records, * then there's reasonable defaults in the f/w @@ -714,9 +714,6 @@ static int plugimage(struct imgchunk *fchunk, unsigned int nfchunks, * should only be a warning, not fatal. * TODO: add fatals for the PDRs mentioned above. */ - result = 1; - continue; -#endif } /* Validate plug len against PDR len */ |