2019-05-19 15:08:20 +03:00
// SPDX-License-Identifier: GPL-2.0-only
2010-05-29 13:03:44 +04:00
/*
2005-04-17 02:20:36 +04:00
* nicstar . c
*
* Device driver supporting CBR for IDT 77201 / 77211 " NICStAR " based cards .
*
* IMPORTANT : The included file nicstarmac . c was NOT WRITTEN BY ME .
* It was taken from the frle - 0.22 device driver .
* As the file doesn ' t have a copyright notice , in the file
* nicstarmac . copyright I put the copyright notice from the
* frle - 0.22 device driver .
* Some code is based on the nicstar driver by M . Welsh .
*
* Author : Rui Prior ( rprior @ inescn . pt )
* PowerPC support by Jay Talbott ( jay_talbott @ mcg . mot . com ) April 1999
*
*
* ( C ) INESC 1999
2010-05-29 13:03:44 +04:00
*/
2005-04-17 02:20:36 +04:00
2010-05-29 13:03:44 +04:00
/*
* IMPORTANT INFORMATION
2005-04-17 02:20:36 +04:00
*
* There are currently three types of spinlocks :
*
* 1 - Per card interrupt spinlock ( to protect structures and such )
* 2 - Per SCQ scq spinlock
* 3 - Per card resource spinlock ( to access registers , etc . )
*
* These must NEVER be grabbed in reverse order .
*
2010-05-29 13:03:44 +04:00
*/
2005-04-17 02:20:36 +04:00
2010-05-29 13:03:44 +04:00
/* Header files */
2005-04-17 02:20:36 +04:00
# include <linux/module.h>
# include <linux/kernel.h>
# include <linux/skbuff.h>
# include <linux/atmdev.h>
# include <linux/atm.h>
# include <linux/pci.h>
2010-05-29 13:04:25 +04:00
# include <linux/dma-mapping.h>
2005-04-17 02:20:36 +04:00
# include <linux/types.h>
# include <linux/string.h>
# include <linux/delay.h>
# include <linux/init.h>
# include <linux/sched.h>
# include <linux/timer.h>
# include <linux/interrupt.h>
# include <linux/bitops.h>
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 11:04:11 +03:00
# include <linux/slab.h>
2010-05-29 13:04:25 +04:00
# include <linux/idr.h>
2005-04-17 02:20:36 +04:00
# include <asm/io.h>
2016-12-24 22:46:01 +03:00
# include <linux/uaccess.h>
2011-07-27 03:09:06 +04:00
# include <linux/atomic.h>
2013-12-26 15:41:02 +04:00
# include <linux/etherdevice.h>
2005-04-17 02:20:36 +04:00
# include "nicstar.h"
# ifdef CONFIG_ATM_NICSTAR_USE_SUNI
# include "suni.h"
# endif /* CONFIG_ATM_NICSTAR_USE_SUNI */
# ifdef CONFIG_ATM_NICSTAR_USE_IDT77105
# include "idt77105.h"
# endif /* CONFIG_ATM_NICSTAR_USE_IDT77105 */
2010-05-29 13:03:44 +04:00
/* Additional code */
2005-04-17 02:20:36 +04:00
# include "nicstarmac.c"
2010-05-29 13:03:44 +04:00
/* Configurable parameters */
2005-04-17 02:20:36 +04:00
# undef PHY_LOOPBACK
# undef TX_DEBUG
# undef RX_DEBUG
# undef GENERAL_DEBUG
# undef EXTRA_DEBUG
2010-05-29 13:03:44 +04:00
/* Do not touch these */
2005-04-17 02:20:36 +04:00
# ifdef TX_DEBUG
# define TXPRINTK(args...) printk(args)
# else
# define TXPRINTK(args...)
# endif /* TX_DEBUG */
# ifdef RX_DEBUG
# define RXPRINTK(args...) printk(args)
# else
# define RXPRINTK(args...)
# endif /* RX_DEBUG */
# ifdef GENERAL_DEBUG
# define PRINTK(args...) printk(args)
# else
2020-02-28 05:09:44 +03:00
# define PRINTK(args...) do {} while (0)
2005-04-17 02:20:36 +04:00
# endif /* GENERAL_DEBUG */
# ifdef EXTRA_DEBUG
# define XPRINTK(args...) printk(args)
# else
# define XPRINTK(args...)
# endif /* EXTRA_DEBUG */
2010-05-29 13:03:44 +04:00
/* Macros */
2005-04-17 02:20:36 +04:00
# define CMD_BUSY(card) (readl((card)->membase + STAT) & NS_STAT_CMDBZ)
# define NS_DELAY mdelay(1)
2010-05-29 13:04:25 +04:00
# define PTR_DIFF(a, b) ((u32)((unsigned long)(a) - (unsigned long)(b)))
2005-04-17 02:20:36 +04:00
# ifndef ATM_SKB
# define ATM_SKB(s) (&(s)->atm)
# endif
2010-05-29 13:04:25 +04:00
# define scq_virt_to_bus(scq, p) \
( scq - > dma + ( ( unsigned long ) ( p ) - ( unsigned long ) ( scq ) - > org ) )
2010-05-29 13:03:44 +04:00
/* Function declarations */
2005-04-17 02:20:36 +04:00
2010-05-29 13:03:44 +04:00
static u32 ns_read_sram ( ns_dev * card , u32 sram_address ) ;
static void ns_write_sram ( ns_dev * card , u32 sram_address , u32 * value ,
int count ) ;
2012-12-22 01:25:04 +04:00
static int ns_init_card ( int i , struct pci_dev * pcidev ) ;
static void ns_init_card_error ( ns_dev * card , int error ) ;
2010-05-29 13:04:25 +04:00
static scq_info * get_scq ( ns_dev * card , int size , u32 scd ) ;
static void free_scq ( ns_dev * card , scq_info * scq , struct atm_vcc * vcc ) ;
2005-08-10 06:25:21 +04:00
static void push_rxbufs ( ns_dev * , struct sk_buff * ) ;
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 17:55:46 +04:00
static irqreturn_t ns_irq_handler ( int irq , void * dev_id ) ;
2005-04-17 02:20:36 +04:00
static int ns_open ( struct atm_vcc * vcc ) ;
static void ns_close ( struct atm_vcc * vcc ) ;
2010-05-29 13:03:44 +04:00
static void fill_tst ( ns_dev * card , int n , vc_map * vc ) ;
2005-04-17 02:20:36 +04:00
static int ns_send ( struct atm_vcc * vcc , struct sk_buff * skb ) ;
2020-11-16 19:21:15 +03:00
static int ns_send_bh ( struct atm_vcc * vcc , struct sk_buff * skb ) ;
2010-05-29 13:03:44 +04:00
static int push_scqe ( ns_dev * card , vc_map * vc , scq_info * scq , ns_scqe * tbd ,
2020-11-16 19:21:15 +03:00
struct sk_buff * skb , bool may_sleep ) ;
2010-05-29 13:03:44 +04:00
static void process_tsq ( ns_dev * card ) ;
static void drain_scq ( ns_dev * card , scq_info * scq , int pos ) ;
static void process_rsq ( ns_dev * card ) ;
static void dequeue_rx ( ns_dev * card , ns_rsqe * rsqe ) ;
static void recycle_rx_buf ( ns_dev * card , struct sk_buff * skb ) ;
static void recycle_iovec_rx_bufs ( ns_dev * card , struct iovec * iov , int count ) ;
static void recycle_iov_buf ( ns_dev * card , struct sk_buff * iovb ) ;
static void dequeue_sm_buf ( ns_dev * card , struct sk_buff * sb ) ;
static void dequeue_lg_buf ( ns_dev * card , struct sk_buff * lb ) ;
static int ns_proc_read ( struct atm_dev * dev , loff_t * pos , char * page ) ;
static int ns_ioctl ( struct atm_dev * dev , unsigned int cmd , void __user * arg ) ;
2010-05-29 13:04:25 +04:00
# ifdef EXTRA_DEBUG
2010-05-29 13:03:44 +04:00
static void which_list ( ns_dev * card , struct sk_buff * skb ) ;
2010-05-29 13:04:25 +04:00
# endif
treewide: setup_timer() -> timer_setup()
This converts all remaining cases of the old setup_timer() API into using
timer_setup(), where the callback argument is the structure already
holding the struct timer_list. These should have no behavioral changes,
since they just change which pointer is passed into the callback with
the same available pointers after conversion. It handles the following
examples, in addition to some other variations.
Casting from unsigned long:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
setup_timer(&ptr->my_timer, my_callback, ptr);
and forced object casts:
void my_callback(struct something *ptr)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, (unsigned long)ptr);
become:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
Direct function assignments:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
ptr->my_timer.function = my_callback;
have a temporary cast added, along with converting the args:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
ptr->my_timer.function = (TIMER_FUNC_TYPE)my_callback;
And finally, callbacks without a data assignment:
void my_callback(unsigned long data)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, 0);
have their argument renamed to verify they're unused during conversion:
void my_callback(struct timer_list *unused)
{
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
The conversion is done with the following Coccinelle script:
spatch --very-quiet --all-includes --include-headers \
-I ./arch/x86/include -I ./arch/x86/include/generated \
-I ./include -I ./arch/x86/include/uapi \
-I ./arch/x86/include/generated/uapi -I ./include/uapi \
-I ./include/generated/uapi --include ./include/linux/kconfig.h \
--dir . \
--cocci-file ~/src/data/timer_setup.cocci
@fix_address_of@
expression e;
@@
setup_timer(
-&(e)
+&e
, ...)
// Update any raw setup_timer() usages that have a NULL callback, but
// would otherwise match change_timer_function_usage, since the latter
// will update all function assignments done in the face of a NULL
// function initialization in setup_timer().
@change_timer_function_usage_NULL@
expression _E;
identifier _timer;
type _cast_data;
@@
(
-setup_timer(&_E->_timer, NULL, _E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E->_timer, NULL, (_cast_data)_E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, &_E);
+timer_setup(&_E._timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, (_cast_data)&_E);
+timer_setup(&_E._timer, NULL, 0);
)
@change_timer_function_usage@
expression _E;
identifier _timer;
struct timer_list _stl;
identifier _callback;
type _cast_func, _cast_data;
@@
(
-setup_timer(&_E->_timer, _callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
_E->_timer@_stl.function = _callback;
|
_E->_timer@_stl.function = &_callback;
|
_E->_timer@_stl.function = (_cast_func)_callback;
|
_E->_timer@_stl.function = (_cast_func)&_callback;
|
_E._timer@_stl.function = _callback;
|
_E._timer@_stl.function = &_callback;
|
_E._timer@_stl.function = (_cast_func)_callback;
|
_E._timer@_stl.function = (_cast_func)&_callback;
)
// callback(unsigned long arg)
@change_callback_handle_cast
depends on change_timer_function_usage@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
identifier _handle;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
(
... when != _origarg
_handletype *_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
)
}
// callback(unsigned long arg) without existing variable
@change_callback_handle_cast_no_arg
depends on change_timer_function_usage &&
!change_callback_handle_cast@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
+ _handletype *_origarg = from_timer(_origarg, t, _timer);
+
... when != _origarg
- (_handletype *)_origarg
+ _origarg
... when != _origarg
}
// Avoid already converted callbacks.
@match_callback_converted
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier t;
@@
void _callback(struct timer_list *t)
{ ... }
// callback(struct something *handle)
@change_callback_handle_arg
depends on change_timer_function_usage &&
!match_callback_converted &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
@@
void _callback(
-_handletype *_handle
+struct timer_list *t
)
{
+ _handletype *_handle = from_timer(_handle, t, _timer);
...
}
// If change_callback_handle_arg ran on an empty function, remove
// the added handler.
@unchange_callback_handle_arg
depends on change_timer_function_usage &&
change_callback_handle_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
identifier t;
@@
void _callback(struct timer_list *t)
{
- _handletype *_handle = from_timer(_handle, t, _timer);
}
// We only want to refactor the setup_timer() data argument if we've found
// the matching callback. This undoes changes in change_timer_function_usage.
@unchange_timer_function_usage
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg &&
!change_callback_handle_arg@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type change_timer_function_usage._cast_data;
@@
(
-timer_setup(&_E->_timer, _callback, 0);
+setup_timer(&_E->_timer, _callback, (_cast_data)_E);
|
-timer_setup(&_E._timer, _callback, 0);
+setup_timer(&_E._timer, _callback, (_cast_data)&_E);
)
// If we fixed a callback from a .function assignment, fix the
// assignment cast now.
@change_timer_function_assignment
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_func;
typedef TIMER_FUNC_TYPE;
@@
(
_E->_timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-&_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
)
// Sometimes timer functions are called directly. Replace matched args.
@change_timer_function_calls
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression _E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_data;
@@
_callback(
(
-(_cast_data)_E
+&_E->_timer
|
-(_cast_data)&_E
+&_E._timer
|
-_E
+&_E->_timer
)
)
// If a timer has been configured without a data argument, it can be
// converted without regard to the callback argument, since it is unused.
@match_timer_function_unused_data@
expression _E;
identifier _timer;
identifier _callback;
@@
(
-setup_timer(&_E->_timer, _callback, 0);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0L);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0UL);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0L);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0UL);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0L);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0UL);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0L);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0UL);
+timer_setup(_timer, _callback, 0);
)
@change_callback_unused_data
depends on match_timer_function_unused_data@
identifier match_timer_function_unused_data._callback;
type _origtype;
identifier _origarg;
@@
void _callback(
-_origtype _origarg
+struct timer_list *unused
)
{
... when != _origarg
}
Signed-off-by: Kees Cook <keescook@chromium.org>
2017-10-17 00:43:17 +03:00
static void ns_poll ( struct timer_list * unused ) ;
2005-04-17 02:20:36 +04:00
static void ns_phy_put ( struct atm_dev * dev , unsigned char value ,
2010-05-29 13:03:44 +04:00
unsigned long addr ) ;
2005-04-17 02:20:36 +04:00
static unsigned char ns_phy_get ( struct atm_dev * dev , unsigned long addr ) ;
2010-05-29 13:03:44 +04:00
/* Global variables */
2005-04-17 02:20:36 +04:00
static struct ns_dev * cards [ NS_MAX_CARDS ] ;
static unsigned num_cards ;
2017-08-09 12:19:15 +03:00
static const struct atmdev_ops atm_ops = {
2010-05-29 13:03:44 +04:00
. open = ns_open ,
. close = ns_close ,
. ioctl = ns_ioctl ,
. send = ns_send ,
2020-11-16 19:21:15 +03:00
. send_bh = ns_send_bh ,
2010-05-29 13:03:44 +04:00
. phy_put = ns_phy_put ,
. phy_get = ns_phy_get ,
. proc_read = ns_proc_read ,
. owner = THIS_MODULE ,
2005-04-17 02:20:36 +04:00
} ;
2010-05-29 13:03:44 +04:00
2005-04-17 02:20:36 +04:00
static struct timer_list ns_timer ;
static char * mac [ NS_MAX_CARDS ] ;
module_param_array ( mac , charp , NULL , 0 ) ;
MODULE_LICENSE ( " GPL " ) ;
2010-05-29 13:03:44 +04:00
/* Functions */
2005-04-17 02:20:36 +04:00
2012-12-22 01:25:04 +04:00
static int nicstar_init_one ( struct pci_dev * pcidev ,
const struct pci_device_id * ent )
2005-04-17 02:20:36 +04:00
{
2010-05-29 13:03:44 +04:00
static int index = - 1 ;
unsigned int error ;
2005-04-17 02:20:36 +04:00
2010-05-29 13:03:44 +04:00
index + + ;
cards [ index ] = NULL ;
2005-04-17 02:20:36 +04:00
2010-05-29 13:03:44 +04:00
error = ns_init_card ( index , pcidev ) ;
if ( error ) {
cards [ index - - ] = NULL ; /* don't increment index */
goto err_out ;
}
2005-04-17 02:20:36 +04:00
2010-05-29 13:03:44 +04:00
return 0 ;
2005-04-17 02:20:36 +04:00
err_out :
2010-05-29 13:03:44 +04:00
return - ENODEV ;
2005-04-17 02:20:36 +04:00
}
2012-12-22 01:25:04 +04:00
static void nicstar_remove_one ( struct pci_dev * pcidev )
2005-04-17 02:20:36 +04:00
{
2010-05-29 13:03:44 +04:00
int i , j ;
ns_dev * card = pci_get_drvdata ( pcidev ) ;
struct sk_buff * hb ;
struct sk_buff * iovb ;
struct sk_buff * lb ;
struct sk_buff * sb ;
i = card - > index ;
if ( cards [ i ] = = NULL )
return ;
if ( card - > atmdev - > phy & & card - > atmdev - > phy - > stop )
card - > atmdev - > phy - > stop ( card - > atmdev ) ;
/* Stop everything */
writel ( 0x00000000 , card - > membase + CFG ) ;
/* De-register device */
atm_dev_deregister ( card - > atmdev ) ;
/* Disable PCI device */
pci_disable_device ( pcidev ) ;
/* Free up resources */
j = 0 ;
PRINTK ( " nicstar%d: freeing %d huge buffers. \n " , i , card - > hbpool . count ) ;
while ( ( hb = skb_dequeue ( & card - > hbpool . queue ) ) ! = NULL ) {
dev_kfree_skb_any ( hb ) ;
j + + ;
}
PRINTK ( " nicstar%d: %d huge buffers freed. \n " , i , j ) ;
j = 0 ;
PRINTK ( " nicstar%d: freeing %d iovec buffers. \n " , i ,
card - > iovpool . count ) ;
while ( ( iovb = skb_dequeue ( & card - > iovpool . queue ) ) ! = NULL ) {
dev_kfree_skb_any ( iovb ) ;
j + + ;
}
PRINTK ( " nicstar%d: %d iovec buffers freed. \n " , i , j ) ;
while ( ( lb = skb_dequeue ( & card - > lbpool . queue ) ) ! = NULL )
dev_kfree_skb_any ( lb ) ;
while ( ( sb = skb_dequeue ( & card - > sbpool . queue ) ) ! = NULL )
dev_kfree_skb_any ( sb ) ;
2010-05-29 13:04:25 +04:00
free_scq ( card , card - > scq0 , NULL ) ;
2010-05-29 13:03:44 +04:00
for ( j = 0 ; j < NS_FRSCD_NUM ; j + + ) {
if ( card - > scd2vc [ j ] ! = NULL )
2010-05-29 13:04:25 +04:00
free_scq ( card , card - > scd2vc [ j ] - > scq , card - > scd2vc [ j ] - > tx_vcc ) ;
}
idr_destroy ( & card - > idr ) ;
2015-01-16 16:57:21 +03:00
dma_free_coherent ( & card - > pcidev - > dev , NS_RSQSIZE + NS_RSQ_ALIGNMENT ,
card - > rsq . org , card - > rsq . dma ) ;
dma_free_coherent ( & card - > pcidev - > dev , NS_TSQSIZE + NS_TSQ_ALIGNMENT ,
card - > tsq . org , card - > tsq . dma ) ;
2010-05-29 13:03:44 +04:00
free_irq ( card - > pcidev - > irq , card ) ;
iounmap ( card - > membase ) ;
kfree ( card ) ;
2005-04-17 02:20:36 +04:00
}
2017-07-16 12:32:32 +03:00
static const struct pci_device_id nicstar_pci_tbl [ ] = {
2010-07-15 12:48:26 +04:00
{ PCI_VDEVICE ( IDT , PCI_DEVICE_ID_IDT_IDT77201 ) , 0 } ,
2005-04-17 02:20:36 +04:00
{ 0 , } /* terminate list */
} ;
2010-05-29 13:03:44 +04:00
MODULE_DEVICE_TABLE ( pci , nicstar_pci_tbl ) ;
2005-04-17 02:20:36 +04:00
static struct pci_driver nicstar_driver = {
2010-05-29 13:03:44 +04:00
. name = " nicstar " ,
. id_table = nicstar_pci_tbl ,
. probe = nicstar_init_one ,
2012-12-22 01:25:04 +04:00
. remove = nicstar_remove_one ,
2005-04-17 02:20:36 +04:00
} ;
static int __init nicstar_init ( void )
{
2010-05-29 13:03:44 +04:00
unsigned error = 0 ; /* Initialized to remove compile warning */
2005-04-17 02:20:36 +04:00
2010-05-29 13:03:44 +04:00
XPRINTK ( " nicstar: nicstar_init() called. \n " ) ;
2005-04-17 02:20:36 +04:00
2010-05-29 13:03:44 +04:00
error = pci_register_driver ( & nicstar_driver ) ;
TXPRINTK ( " nicstar: TX debug enabled. \n " ) ;
RXPRINTK ( " nicstar: RX debug enabled. \n " ) ;
PRINTK ( " nicstar: General debug enabled. \n " ) ;
2005-04-17 02:20:36 +04:00
# ifdef PHY_LOOPBACK
2010-05-29 13:03:44 +04:00
printk ( " nicstar: using PHY loopback. \n " ) ;
2005-04-17 02:20:36 +04:00
# endif /* PHY_LOOPBACK */
2010-05-29 13:03:44 +04:00
XPRINTK ( " nicstar: nicstar_init() returned. \n " ) ;
2005-04-17 02:20:36 +04:00
2010-05-29 13:03:44 +04:00
if ( ! error ) {
treewide: setup_timer() -> timer_setup()
This converts all remaining cases of the old setup_timer() API into using
timer_setup(), where the callback argument is the structure already
holding the struct timer_list. These should have no behavioral changes,
since they just change which pointer is passed into the callback with
the same available pointers after conversion. It handles the following
examples, in addition to some other variations.
Casting from unsigned long:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
setup_timer(&ptr->my_timer, my_callback, ptr);
and forced object casts:
void my_callback(struct something *ptr)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, (unsigned long)ptr);
become:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
Direct function assignments:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
ptr->my_timer.function = my_callback;
have a temporary cast added, along with converting the args:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
ptr->my_timer.function = (TIMER_FUNC_TYPE)my_callback;
And finally, callbacks without a data assignment:
void my_callback(unsigned long data)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, 0);
have their argument renamed to verify they're unused during conversion:
void my_callback(struct timer_list *unused)
{
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
The conversion is done with the following Coccinelle script:
spatch --very-quiet --all-includes --include-headers \
-I ./arch/x86/include -I ./arch/x86/include/generated \
-I ./include -I ./arch/x86/include/uapi \
-I ./arch/x86/include/generated/uapi -I ./include/uapi \
-I ./include/generated/uapi --include ./include/linux/kconfig.h \
--dir . \
--cocci-file ~/src/data/timer_setup.cocci
@fix_address_of@
expression e;
@@
setup_timer(
-&(e)
+&e
, ...)
// Update any raw setup_timer() usages that have a NULL callback, but
// would otherwise match change_timer_function_usage, since the latter
// will update all function assignments done in the face of a NULL
// function initialization in setup_timer().
@change_timer_function_usage_NULL@
expression _E;
identifier _timer;
type _cast_data;
@@
(
-setup_timer(&_E->_timer, NULL, _E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E->_timer, NULL, (_cast_data)_E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, &_E);
+timer_setup(&_E._timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, (_cast_data)&_E);
+timer_setup(&_E._timer, NULL, 0);
)
@change_timer_function_usage@
expression _E;
identifier _timer;
struct timer_list _stl;
identifier _callback;
type _cast_func, _cast_data;
@@
(
-setup_timer(&_E->_timer, _callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
_E->_timer@_stl.function = _callback;
|
_E->_timer@_stl.function = &_callback;
|
_E->_timer@_stl.function = (_cast_func)_callback;
|
_E->_timer@_stl.function = (_cast_func)&_callback;
|
_E._timer@_stl.function = _callback;
|
_E._timer@_stl.function = &_callback;
|
_E._timer@_stl.function = (_cast_func)_callback;
|
_E._timer@_stl.function = (_cast_func)&_callback;
)
// callback(unsigned long arg)
@change_callback_handle_cast
depends on change_timer_function_usage@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
identifier _handle;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
(
... when != _origarg
_handletype *_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
)
}
// callback(unsigned long arg) without existing variable
@change_callback_handle_cast_no_arg
depends on change_timer_function_usage &&
!change_callback_handle_cast@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
+ _handletype *_origarg = from_timer(_origarg, t, _timer);
+
... when != _origarg
- (_handletype *)_origarg
+ _origarg
... when != _origarg
}
// Avoid already converted callbacks.
@match_callback_converted
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier t;
@@
void _callback(struct timer_list *t)
{ ... }
// callback(struct something *handle)
@change_callback_handle_arg
depends on change_timer_function_usage &&
!match_callback_converted &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
@@
void _callback(
-_handletype *_handle
+struct timer_list *t
)
{
+ _handletype *_handle = from_timer(_handle, t, _timer);
...
}
// If change_callback_handle_arg ran on an empty function, remove
// the added handler.
@unchange_callback_handle_arg
depends on change_timer_function_usage &&
change_callback_handle_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
identifier t;
@@
void _callback(struct timer_list *t)
{
- _handletype *_handle = from_timer(_handle, t, _timer);
}
// We only want to refactor the setup_timer() data argument if we've found
// the matching callback. This undoes changes in change_timer_function_usage.
@unchange_timer_function_usage
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg &&
!change_callback_handle_arg@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type change_timer_function_usage._cast_data;
@@
(
-timer_setup(&_E->_timer, _callback, 0);
+setup_timer(&_E->_timer, _callback, (_cast_data)_E);
|
-timer_setup(&_E._timer, _callback, 0);
+setup_timer(&_E._timer, _callback, (_cast_data)&_E);
)
// If we fixed a callback from a .function assignment, fix the
// assignment cast now.
@change_timer_function_assignment
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_func;
typedef TIMER_FUNC_TYPE;
@@
(
_E->_timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-&_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
)
// Sometimes timer functions are called directly. Replace matched args.
@change_timer_function_calls
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression _E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_data;
@@
_callback(
(
-(_cast_data)_E
+&_E->_timer
|
-(_cast_data)&_E
+&_E._timer
|
-_E
+&_E->_timer
)
)
// If a timer has been configured without a data argument, it can be
// converted without regard to the callback argument, since it is unused.
@match_timer_function_unused_data@
expression _E;
identifier _timer;
identifier _callback;
@@
(
-setup_timer(&_E->_timer, _callback, 0);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0L);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0UL);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0L);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0UL);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0L);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0UL);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0L);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0UL);
+timer_setup(_timer, _callback, 0);
)
@change_callback_unused_data
depends on match_timer_function_unused_data@
identifier match_timer_function_unused_data._callback;
type _origtype;
identifier _origarg;
@@
void _callback(
-_origtype _origarg
+struct timer_list *unused
)
{
... when != _origarg
}
Signed-off-by: Kees Cook <keescook@chromium.org>
2017-10-17 00:43:17 +03:00
timer_setup ( & ns_timer , ns_poll , 0 ) ;
2010-05-29 13:03:44 +04:00
ns_timer . expires = jiffies + NS_POLL_PERIOD ;
add_timer ( & ns_timer ) ;
}
2005-04-17 02:20:36 +04:00
2010-05-29 13:03:44 +04:00
return error ;
}
2005-04-17 02:20:36 +04:00
static void __exit nicstar_cleanup ( void )
{
2010-05-29 13:03:44 +04:00
XPRINTK ( " nicstar: nicstar_cleanup() called. \n " ) ;
2005-04-17 02:20:36 +04:00
2021-05-12 10:00:24 +03:00
del_timer_sync ( & ns_timer ) ;
2005-04-17 02:20:36 +04:00
2010-05-29 13:03:44 +04:00
pci_unregister_driver ( & nicstar_driver ) ;
2005-04-17 02:20:36 +04:00
2010-05-29 13:03:44 +04:00
XPRINTK ( " nicstar: nicstar_cleanup() returned. \n " ) ;
2005-04-17 02:20:36 +04:00
}
2010-05-29 13:03:44 +04:00
static u32 ns_read_sram ( ns_dev * card , u32 sram_address )
2005-04-17 02:20:36 +04:00
{
2010-05-29 13:03:44 +04:00
unsigned long flags ;
u32 data ;
sram_address < < = 2 ;
sram_address & = 0x0007FFFC ; /* address must be dword aligned */
sram_address | = 0x50000000 ; /* SRAM read command */
spin_lock_irqsave ( & card - > res_lock , flags ) ;
while ( CMD_BUSY ( card ) ) ;
writel ( sram_address , card - > membase + CMD ) ;
while ( CMD_BUSY ( card ) ) ;
data = readl ( card - > membase + DR0 ) ;
spin_unlock_irqrestore ( & card - > res_lock , flags ) ;
return data ;
2005-04-17 02:20:36 +04:00
}
2010-05-29 13:03:44 +04:00
static void ns_write_sram ( ns_dev * card , u32 sram_address , u32 * value ,
int count )
2005-04-17 02:20:36 +04:00
{
2010-05-29 13:03:44 +04:00
unsigned long flags ;
int i , c ;
count - - ; /* count range now is 0..3 instead of 1..4 */
c = count ;
c < < = 2 ; /* to use increments of 4 */
spin_lock_irqsave ( & card - > res_lock , flags ) ;
while ( CMD_BUSY ( card ) ) ;
for ( i = 0 ; i < = c ; i + = 4 )
writel ( * ( value + + ) , card - > membase + i ) ;
/* Note: DR# registers are the first 4 dwords in nicstar's memspace,
so card - > membase + DR0 = = card - > membase */
sram_address < < = 2 ;
sram_address & = 0x0007FFFC ;
sram_address | = ( 0x40000000 | count ) ;
writel ( sram_address , card - > membase + CMD ) ;
spin_unlock_irqrestore ( & card - > res_lock , flags ) ;
2005-04-17 02:20:36 +04:00
}
2012-12-22 01:25:04 +04:00
static int ns_init_card ( int i , struct pci_dev * pcidev )
2005-04-17 02:20:36 +04:00
{
2010-05-29 13:03:44 +04:00
int j ;
struct ns_dev * card = NULL ;
unsigned char pci_latency ;
unsigned error ;
u32 data ;
u32 u32d [ 4 ] ;
u32 ns_cfg_rctsize ;
int bcount ;
unsigned long membase ;
error = 0 ;
if ( pci_enable_device ( pcidev ) ) {
printk ( " nicstar%d: can't enable PCI device \n " , i ) ;
error = 2 ;
ns_init_card_error ( card , error ) ;
return error ;
}
2015-01-16 16:57:21 +03:00
if ( dma_set_mask_and_coherent ( & pcidev - > dev , DMA_BIT_MASK ( 32 ) ) ! = 0 ) {
2010-05-29 13:04:25 +04:00
printk ( KERN_WARNING
" nicstar%d: No suitable DMA available. \n " , i ) ;
error = 2 ;
ns_init_card_error ( card , error ) ;
return error ;
}
2010-05-29 13:03:44 +04:00
2016-09-10 09:48:17 +03:00
card = kmalloc ( sizeof ( * card ) , GFP_KERNEL ) ;
if ( ! card ) {
2010-05-29 13:03:44 +04:00
printk
( " nicstar%d: can't allocate memory for device structure. \n " ,
i ) ;
error = 2 ;
ns_init_card_error ( card , error ) ;
return error ;
}
cards [ i ] = card ;
spin_lock_init ( & card - > int_lock ) ;
spin_lock_init ( & card - > res_lock ) ;
pci_set_drvdata ( pcidev , card ) ;
card - > index = i ;
card - > atmdev = NULL ;
card - > pcidev = pcidev ;
membase = pci_resource_start ( pcidev , 1 ) ;
card - > membase = ioremap ( membase , NS_IOREMAP_SIZE ) ;
if ( ! card - > membase ) {
printk ( " nicstar%d: can't ioremap() membase. \n " , i ) ;
error = 3 ;
ns_init_card_error ( card , error ) ;
return error ;
}
2010-05-29 13:04:25 +04:00
PRINTK ( " nicstar%d: membase at 0x%p. \n " , i , card - > membase ) ;
2010-05-29 13:03:44 +04:00
pci_set_master ( pcidev ) ;
if ( pci_read_config_byte ( pcidev , PCI_LATENCY_TIMER , & pci_latency ) ! = 0 ) {
printk ( " nicstar%d: can't read PCI latency timer. \n " , i ) ;
error = 6 ;
ns_init_card_error ( card , error ) ;
return error ;
}
2005-04-17 02:20:36 +04:00
# ifdef NS_PCI_LATENCY
2010-05-29 13:03:44 +04:00
if ( pci_latency < NS_PCI_LATENCY ) {
PRINTK ( " nicstar%d: setting PCI latency timer to %d. \n " , i ,
NS_PCI_LATENCY ) ;
for ( j = 1 ; j < 4 ; j + + ) {
if ( pci_write_config_byte
( pcidev , PCI_LATENCY_TIMER , NS_PCI_LATENCY ) ! = 0 )
break ;
}
if ( j = = 4 ) {
printk
( " nicstar%d: can't set PCI latency timer to %d. \n " ,
i , NS_PCI_LATENCY ) ;
error = 7 ;
ns_init_card_error ( card , error ) ;
return error ;
}
}
2005-04-17 02:20:36 +04:00
# endif /* NS_PCI_LATENCY */
2010-05-29 13:03:44 +04:00
/* Clear timer overflow */
data = readl ( card - > membase + STAT ) ;
if ( data & NS_STAT_TMROF )
writel ( NS_STAT_TMROF , card - > membase + STAT ) ;
/* Software reset */
writel ( NS_CFG_SWRST , card - > membase + CFG ) ;
NS_DELAY ;
writel ( 0x00000000 , card - > membase + CFG ) ;
/* PHY reset */
writel ( 0x00000008 , card - > membase + GP ) ;
NS_DELAY ;
writel ( 0x00000001 , card - > membase + GP ) ;
NS_DELAY ;
while ( CMD_BUSY ( card ) ) ;
writel ( NS_CMD_WRITE_UTILITY | 0x00000100 , card - > membase + CMD ) ; /* Sync UTOPIA with SAR clock */
NS_DELAY ;
/* Detect PHY type */
while ( CMD_BUSY ( card ) ) ;
writel ( NS_CMD_READ_UTILITY | 0x00000200 , card - > membase + CMD ) ;
while ( CMD_BUSY ( card ) ) ;
data = readl ( card - > membase + DR0 ) ;
switch ( data ) {
case 0x00000009 :
printk ( " nicstar%d: PHY seems to be 25 Mbps. \n " , i ) ;
card - > max_pcr = ATM_25_PCR ;
while ( CMD_BUSY ( card ) ) ;
writel ( 0x00000008 , card - > membase + DR0 ) ;
writel ( NS_CMD_WRITE_UTILITY | 0x00000200 , card - > membase + CMD ) ;
/* Clear an eventual pending interrupt */
writel ( NS_STAT_SFBQF , card - > membase + STAT ) ;
2005-04-17 02:20:36 +04:00
# ifdef PHY_LOOPBACK
2010-05-29 13:03:44 +04:00
while ( CMD_BUSY ( card ) ) ;
writel ( 0x00000022 , card - > membase + DR0 ) ;
writel ( NS_CMD_WRITE_UTILITY | 0x00000202 , card - > membase + CMD ) ;
2005-04-17 02:20:36 +04:00
# endif /* PHY_LOOPBACK */
2010-05-29 13:03:44 +04:00
break ;
case 0x00000030 :
case 0x00000031 :
printk ( " nicstar%d: PHY seems to be 155 Mbps. \n " , i ) ;
card - > max_pcr = ATM_OC3_PCR ;
2005-04-17 02:20:36 +04:00
# ifdef PHY_LOOPBACK
2010-05-29 13:03:44 +04:00
while ( CMD_BUSY ( card ) ) ;
writel ( 0x00000002 , card - > membase + DR0 ) ;
writel ( NS_CMD_WRITE_UTILITY | 0x00000205 , card - > membase + CMD ) ;
2005-04-17 02:20:36 +04:00
# endif /* PHY_LOOPBACK */
2010-05-29 13:03:44 +04:00
break ;
default :
printk ( " nicstar%d: unknown PHY type (0x%08X). \n " , i , data ) ;
error = 8 ;
ns_init_card_error ( card , error ) ;
return error ;
}
writel ( 0x00000000 , card - > membase + GP ) ;
/* Determine SRAM size */
data = 0x76543210 ;
ns_write_sram ( card , 0x1C003 , & data , 1 ) ;
data = 0x89ABCDEF ;
ns_write_sram ( card , 0x14003 , & data , 1 ) ;
if ( ns_read_sram ( card , 0x14003 ) = = 0x89ABCDEF & &
ns_read_sram ( card , 0x1C003 ) = = 0x76543210 )
card - > sram_size = 128 ;
else
card - > sram_size = 32 ;
PRINTK ( " nicstar%d: %dK x 32bit SRAM size. \n " , i , card - > sram_size ) ;
card - > rct_size = NS_MAX_RCTSIZE ;
2005-04-17 02:20:36 +04:00
# if (NS_MAX_RCTSIZE == 4096)
2010-05-29 13:03:44 +04:00
if ( card - > sram_size = = 128 )
printk
( " nicstar%d: limiting maximum VCI. See NS_MAX_RCTSIZE in nicstar.h \n " ,
i ) ;
2005-04-17 02:20:36 +04:00
# elif (NS_MAX_RCTSIZE == 16384)
2010-05-29 13:03:44 +04:00
if ( card - > sram_size = = 32 ) {
printk
( " nicstar%d: wasting memory. See NS_MAX_RCTSIZE in nicstar.h \n " ,
i ) ;
card - > rct_size = 4096 ;
}
2005-04-17 02:20:36 +04:00
# else
# error NS_MAX_RCTSIZE must be either 4096 or 16384 in nicstar.c
# endif
2010-05-29 13:03:44 +04:00
card - > vpibits = NS_VPIBITS ;
if ( card - > rct_size = = 4096 )
card - > vcibits = 12 - NS_VPIBITS ;
else /* card->rct_size == 16384 */
card - > vcibits = 14 - NS_VPIBITS ;
/* Initialize the nicstar eeprom/eprom stuff, for the MAC addr */
if ( mac [ i ] = = NULL )
nicstar_init_eprom ( card - > membase ) ;
/* Set the VPI/VCI MSb mask to zero so we can receive OAM cells */
writel ( 0x00000000 , card - > membase + VPM ) ;
2021-06-20 18:24:15 +03:00
card - > intcnt = 0 ;
if ( request_irq
( pcidev - > irq , & ns_irq_handler , IRQF_SHARED , " nicstar " , card ) ! = 0 ) {
pr_err ( " nicstar%d: can't allocate IRQ %d. \n " , i , pcidev - > irq ) ;
error = 9 ;
ns_init_card_error ( card , error ) ;
return error ;
}
2010-05-29 13:03:44 +04:00
/* Initialize TSQ */
2015-01-16 16:57:21 +03:00
card - > tsq . org = dma_alloc_coherent ( & card - > pcidev - > dev ,
NS_TSQSIZE + NS_TSQ_ALIGNMENT ,
& card - > tsq . dma , GFP_KERNEL ) ;
2010-05-29 13:03:44 +04:00
if ( card - > tsq . org = = NULL ) {
printk ( " nicstar%d: can't allocate TSQ. \n " , i ) ;
error = 10 ;
ns_init_card_error ( card , error ) ;
return error ;
}
2010-05-29 13:04:25 +04:00
card - > tsq . base = PTR_ALIGN ( card - > tsq . org , NS_TSQ_ALIGNMENT ) ;
2010-05-29 13:03:44 +04:00
card - > tsq . next = card - > tsq . base ;
card - > tsq . last = card - > tsq . base + ( NS_TSQ_NUM_ENTRIES - 1 ) ;
for ( j = 0 ; j < NS_TSQ_NUM_ENTRIES ; j + + )
ns_tsi_init ( card - > tsq . base + j ) ;
writel ( 0x00000000 , card - > membase + TSQH ) ;
2010-05-29 13:04:25 +04:00
writel ( ALIGN ( card - > tsq . dma , NS_TSQ_ALIGNMENT ) , card - > membase + TSQB ) ;
PRINTK ( " nicstar%d: TSQ base at 0x%p. \n " , i , card - > tsq . base ) ;
2010-05-29 13:03:44 +04:00
/* Initialize RSQ */
2015-01-16 16:57:21 +03:00
card - > rsq . org = dma_alloc_coherent ( & card - > pcidev - > dev ,
NS_RSQSIZE + NS_RSQ_ALIGNMENT ,
& card - > rsq . dma , GFP_KERNEL ) ;
2010-05-29 13:03:44 +04:00
if ( card - > rsq . org = = NULL ) {
printk ( " nicstar%d: can't allocate RSQ. \n " , i ) ;
error = 11 ;
ns_init_card_error ( card , error ) ;
return error ;
}
2010-05-29 13:04:25 +04:00
card - > rsq . base = PTR_ALIGN ( card - > rsq . org , NS_RSQ_ALIGNMENT ) ;
2010-05-29 13:03:44 +04:00
card - > rsq . next = card - > rsq . base ;
card - > rsq . last = card - > rsq . base + ( NS_RSQ_NUM_ENTRIES - 1 ) ;
for ( j = 0 ; j < NS_RSQ_NUM_ENTRIES ; j + + )
ns_rsqe_init ( card - > rsq . base + j ) ;
writel ( 0x00000000 , card - > membase + RSQH ) ;
2010-05-29 13:04:25 +04:00
writel ( ALIGN ( card - > rsq . dma , NS_RSQ_ALIGNMENT ) , card - > membase + RSQB ) ;
PRINTK ( " nicstar%d: RSQ base at 0x%p. \n " , i , card - > rsq . base ) ;
2010-05-29 13:03:44 +04:00
/* Initialize SCQ0, the only VBR SCQ used */
card - > scq1 = NULL ;
card - > scq2 = NULL ;
2010-05-29 13:04:25 +04:00
card - > scq0 = get_scq ( card , VBR_SCQSIZE , NS_VRSCD0 ) ;
2010-05-29 13:03:44 +04:00
if ( card - > scq0 = = NULL ) {
printk ( " nicstar%d: can't get SCQ0. \n " , i ) ;
error = 12 ;
ns_init_card_error ( card , error ) ;
return error ;
}
2010-05-29 13:04:25 +04:00
u32d [ 0 ] = scq_virt_to_bus ( card - > scq0 , card - > scq0 - > base ) ;
2010-05-29 13:03:44 +04:00
u32d [ 1 ] = ( u32 ) 0x00000000 ;
u32d [ 2 ] = ( u32 ) 0xffffffff ;
u32d [ 3 ] = ( u32 ) 0x00000000 ;
ns_write_sram ( card , NS_VRSCD0 , u32d , 4 ) ;
ns_write_sram ( card , NS_VRSCD1 , u32d , 4 ) ; /* These last two won't be used */
ns_write_sram ( card , NS_VRSCD2 , u32d , 4 ) ; /* but are initialized, just in case... */
card - > scq0 - > scd = NS_VRSCD0 ;
2010-05-29 13:04:25 +04:00
PRINTK ( " nicstar%d: VBR-SCQ0 base at 0x%p. \n " , i , card - > scq0 - > base ) ;
2010-05-29 13:03:44 +04:00
/* Initialize TSTs */
card - > tst_addr = NS_TST0 ;
card - > tst_free_entries = NS_TST_NUM_ENTRIES ;
data = NS_TST_OPCODE_VARIABLE ;
for ( j = 0 ; j < NS_TST_NUM_ENTRIES ; j + + )
ns_write_sram ( card , NS_TST0 + j , & data , 1 ) ;
data = ns_tste_make ( NS_TST_OPCODE_END , NS_TST0 ) ;
ns_write_sram ( card , NS_TST0 + NS_TST_NUM_ENTRIES , & data , 1 ) ;
for ( j = 0 ; j < NS_TST_NUM_ENTRIES ; j + + )
ns_write_sram ( card , NS_TST1 + j , & data , 1 ) ;
data = ns_tste_make ( NS_TST_OPCODE_END , NS_TST1 ) ;
ns_write_sram ( card , NS_TST1 + NS_TST_NUM_ENTRIES , & data , 1 ) ;
for ( j = 0 ; j < NS_TST_NUM_ENTRIES ; j + + )
card - > tste2vc [ j ] = NULL ;
writel ( NS_TST0 < < 2 , card - > membase + TSTB ) ;
/* Initialize RCT. AAL type is set on opening the VC. */
2005-04-17 02:20:36 +04:00
# ifdef RCQ_SUPPORT
2010-05-29 13:03:44 +04:00
u32d [ 0 ] = NS_RCTE_RAWCELLINTEN ;
2005-04-17 02:20:36 +04:00
# else
2010-05-29 13:03:44 +04:00
u32d [ 0 ] = 0x00000000 ;
2005-04-17 02:20:36 +04:00
# endif /* RCQ_SUPPORT */
2010-05-29 13:03:44 +04:00
u32d [ 1 ] = 0x00000000 ;
u32d [ 2 ] = 0x00000000 ;
u32d [ 3 ] = 0xFFFFFFFF ;
for ( j = 0 ; j < card - > rct_size ; j + + )
ns_write_sram ( card , j * 4 , u32d , 4 ) ;
2016-09-10 09:30:09 +03:00
memset ( card - > vcmap , 0 , sizeof ( card - > vcmap ) ) ;
2010-05-29 13:03:44 +04:00
for ( j = 0 ; j < NS_FRSCD_NUM ; j + + )
card - > scd2vc [ j ] = NULL ;
/* Initialize buffer levels */
card - > sbnr . min = MIN_SB ;
card - > sbnr . init = NUM_SB ;
card - > sbnr . max = MAX_SB ;
card - > lbnr . min = MIN_LB ;
card - > lbnr . init = NUM_LB ;
card - > lbnr . max = MAX_LB ;
card - > iovnr . min = MIN_IOVB ;
card - > iovnr . init = NUM_IOVB ;
card - > iovnr . max = MAX_IOVB ;
card - > hbnr . min = MIN_HB ;
card - > hbnr . init = NUM_HB ;
card - > hbnr . max = MAX_HB ;
2014-02-19 05:10:11 +04:00
card - > sm_handle = NULL ;
2010-05-29 13:03:44 +04:00
card - > sm_addr = 0x00000000 ;
2014-02-19 05:10:11 +04:00
card - > lg_handle = NULL ;
2010-05-29 13:03:44 +04:00
card - > lg_addr = 0x00000000 ;
card - > efbie = 1 ; /* To prevent push_rxbufs from enabling the interrupt */
2010-05-29 13:04:25 +04:00
idr_init ( & card - > idr ) ;
2010-05-29 13:03:44 +04:00
/* Pre-allocate some huge buffers */
skb_queue_head_init ( & card - > hbpool . queue ) ;
card - > hbpool . count = 0 ;
for ( j = 0 ; j < NUM_HB ; j + + ) {
struct sk_buff * hb ;
hb = __dev_alloc_skb ( NS_HBUFSIZE , GFP_KERNEL ) ;
if ( hb = = NULL ) {
printk
( " nicstar%d: can't allocate %dth of %d huge buffers. \n " ,
i , j , NUM_HB ) ;
error = 13 ;
ns_init_card_error ( card , error ) ;
return error ;
}
2010-05-29 13:04:25 +04:00
NS_PRV_BUFTYPE ( hb ) = BUF_NONE ;
2010-05-29 13:03:44 +04:00
skb_queue_tail ( & card - > hbpool . queue , hb ) ;
card - > hbpool . count + + ;
}
/* Allocate large buffers */
skb_queue_head_init ( & card - > lbpool . queue ) ;
card - > lbpool . count = 0 ; /* Not used */
for ( j = 0 ; j < NUM_LB ; j + + ) {
struct sk_buff * lb ;
lb = __dev_alloc_skb ( NS_LGSKBSIZE , GFP_KERNEL ) ;
if ( lb = = NULL ) {
printk
( " nicstar%d: can't allocate %dth of %d large buffers. \n " ,
i , j , NUM_LB ) ;
error = 14 ;
ns_init_card_error ( card , error ) ;
return error ;
}
2010-05-29 13:04:25 +04:00
NS_PRV_BUFTYPE ( lb ) = BUF_LG ;
2010-05-29 13:03:44 +04:00
skb_queue_tail ( & card - > lbpool . queue , lb ) ;
skb_reserve ( lb , NS_SMBUFSIZE ) ;
push_rxbufs ( card , lb ) ;
/* Due to the implementation of push_rxbufs() this is 1, not 0 */
if ( j = = 1 ) {
card - > rcbuf = lb ;
2010-05-29 13:04:25 +04:00
card - > rawcell = ( struct ns_rcqe * ) lb - > data ;
card - > rawch = NS_PRV_DMA ( lb ) ;
2010-05-29 13:03:44 +04:00
}
}
/* Test for strange behaviour which leads to crashes */
if ( ( bcount =
ns_stat_lfbqc_get ( readl ( card - > membase + STAT ) ) ) < card - > lbnr . min ) {
printk
( " nicstar%d: Strange... Just allocated %d large buffers and lfbqc = %d. \n " ,
i , j , bcount ) ;
error = 14 ;
ns_init_card_error ( card , error ) ;
return error ;
}
/* Allocate small buffers */
skb_queue_head_init ( & card - > sbpool . queue ) ;
card - > sbpool . count = 0 ; /* Not used */
for ( j = 0 ; j < NUM_SB ; j + + ) {
struct sk_buff * sb ;
sb = __dev_alloc_skb ( NS_SMSKBSIZE , GFP_KERNEL ) ;
if ( sb = = NULL ) {
printk
( " nicstar%d: can't allocate %dth of %d small buffers. \n " ,
i , j , NUM_SB ) ;
error = 15 ;
ns_init_card_error ( card , error ) ;
return error ;
}
2010-05-29 13:04:25 +04:00
NS_PRV_BUFTYPE ( sb ) = BUF_SM ;
2010-05-29 13:03:44 +04:00
skb_queue_tail ( & card - > sbpool . queue , sb ) ;
skb_reserve ( sb , NS_AAL0_HEADER ) ;
push_rxbufs ( card , sb ) ;
}
/* Test for strange behaviour which leads to crashes */
if ( ( bcount =
ns_stat_sfbqc_get ( readl ( card - > membase + STAT ) ) ) < card - > sbnr . min ) {
printk
( " nicstar%d: Strange... Just allocated %d small buffers and sfbqc = %d. \n " ,
i , j , bcount ) ;
error = 15 ;
ns_init_card_error ( card , error ) ;
return error ;
}
/* Allocate iovec buffers */
skb_queue_head_init ( & card - > iovpool . queue ) ;
card - > iovpool . count = 0 ;
for ( j = 0 ; j < NUM_IOVB ; j + + ) {
struct sk_buff * iovb ;
iovb = alloc_skb ( NS_IOVBUFSIZE , GFP_KERNEL ) ;
if ( iovb = = NULL ) {
printk
( " nicstar%d: can't allocate %dth of %d iovec buffers. \n " ,
i , j , NUM_IOVB ) ;
error = 16 ;
ns_init_card_error ( card , error ) ;
return error ;
}
2010-05-29 13:04:25 +04:00
NS_PRV_BUFTYPE ( iovb ) = BUF_NONE ;
2010-05-29 13:03:44 +04:00
skb_queue_tail ( & card - > iovpool . queue , iovb ) ;
card - > iovpool . count + + ;
}
/* Configure NICStAR */
if ( card - > rct_size = = 4096 )
ns_cfg_rctsize = NS_CFG_RCTSIZE_4096_ENTRIES ;
else /* (card->rct_size == 16384) */
ns_cfg_rctsize = NS_CFG_RCTSIZE_16384_ENTRIES ;
card - > efbie = 1 ;
/* Register device */
2010-12-08 22:40:47 +03:00
card - > atmdev = atm_dev_register ( " nicstar " , & card - > pcidev - > dev , & atm_ops ,
- 1 , NULL ) ;
2010-05-29 13:03:44 +04:00
if ( card - > atmdev = = NULL ) {
printk ( " nicstar%d: can't register device. \n " , i ) ;
error = 17 ;
ns_init_card_error ( card , error ) ;
return error ;
}
2013-09-13 19:00:58 +04:00
if ( mac [ i ] = = NULL | | ! mac_pton ( mac [ i ] , card - > atmdev - > esi ) ) {
2010-05-29 13:03:44 +04:00
nicstar_read_eprom ( card - > membase , NICSTAR_EPROM_MAC_ADDR_OFFSET ,
card - > atmdev - > esi , 6 ) ;
2013-12-26 15:41:02 +04:00
if ( ether_addr_equal ( card - > atmdev - > esi , " \x00 \x00 \x00 \x00 \x00 \x00 " ) ) {
2010-05-29 13:03:44 +04:00
nicstar_read_eprom ( card - > membase ,
NICSTAR_EPROM_MAC_ADDR_OFFSET_ALT ,
card - > atmdev - > esi , 6 ) ;
}
}
printk ( " nicstar%d: MAC address %pM \n " , i , card - > atmdev - > esi ) ;
card - > atmdev - > dev_data = card ;
card - > atmdev - > ci_range . vpi_bits = card - > vpibits ;
card - > atmdev - > ci_range . vci_bits = card - > vcibits ;
card - > atmdev - > link_rate = card - > max_pcr ;
card - > atmdev - > phy = NULL ;
2005-04-17 02:20:36 +04:00
# ifdef CONFIG_ATM_NICSTAR_USE_SUNI
2010-05-29 13:03:44 +04:00
if ( card - > max_pcr = = ATM_OC3_PCR )
suni_init ( card - > atmdev ) ;
2005-04-17 02:20:36 +04:00
# endif /* CONFIG_ATM_NICSTAR_USE_SUNI */
# ifdef CONFIG_ATM_NICSTAR_USE_IDT77105
2010-05-29 13:03:44 +04:00
if ( card - > max_pcr = = ATM_25_PCR )
idt77105_init ( card - > atmdev ) ;
2005-04-17 02:20:36 +04:00
# endif /* CONFIG_ATM_NICSTAR_USE_IDT77105 */
2010-05-29 13:03:44 +04:00
if ( card - > atmdev - > phy & & card - > atmdev - > phy - > start )
card - > atmdev - > phy - > start ( card - > atmdev ) ;
2005-04-17 02:20:36 +04:00
2010-05-29 13:03:44 +04:00
writel ( NS_CFG_RXPATH | NS_CFG_SMBUFSIZE | NS_CFG_LGBUFSIZE | NS_CFG_EFBIE | NS_CFG_RSQSIZE | NS_CFG_VPIBITS | ns_cfg_rctsize | NS_CFG_RXINT_NODELAY | NS_CFG_RAWIE | /* Only enabled if RCQ_SUPPORT */
NS_CFG_RSQAFIE | NS_CFG_TXEN | NS_CFG_TXIE | NS_CFG_TSQFIE_OPT | /* Only enabled if ENABLE_TSQFIE */
NS_CFG_PHYIE , card - > membase + CFG ) ;
2005-04-17 02:20:36 +04:00
2010-05-29 13:03:44 +04:00
num_cards + + ;
2005-04-17 02:20:36 +04:00
2010-05-29 13:03:44 +04:00
return error ;
2005-04-17 02:20:36 +04:00
}
2012-12-22 01:25:04 +04:00
static void ns_init_card_error ( ns_dev * card , int error )
2010-05-29 13:03:44 +04:00
{
if ( error > = 17 ) {
writel ( 0x00000000 , card - > membase + CFG ) ;
}
if ( error > = 16 ) {
struct sk_buff * iovb ;
while ( ( iovb = skb_dequeue ( & card - > iovpool . queue ) ) ! = NULL )
dev_kfree_skb_any ( iovb ) ;
}
if ( error > = 15 ) {
struct sk_buff * sb ;
while ( ( sb = skb_dequeue ( & card - > sbpool . queue ) ) ! = NULL )
dev_kfree_skb_any ( sb ) ;
2010-05-29 13:04:25 +04:00
free_scq ( card , card - > scq0 , NULL ) ;
2010-05-29 13:03:44 +04:00
}
if ( error > = 14 ) {
struct sk_buff * lb ;
while ( ( lb = skb_dequeue ( & card - > lbpool . queue ) ) ! = NULL )
dev_kfree_skb_any ( lb ) ;
}
if ( error > = 13 ) {
struct sk_buff * hb ;
while ( ( hb = skb_dequeue ( & card - > hbpool . queue ) ) ! = NULL )
dev_kfree_skb_any ( hb ) ;
}
if ( error > = 12 ) {
2021-06-20 18:24:14 +03:00
dma_free_coherent ( & card - > pcidev - > dev , NS_RSQSIZE + NS_RSQ_ALIGNMENT ,
card - > rsq . org , card - > rsq . dma ) ;
2010-05-29 13:03:44 +04:00
}
if ( error > = 11 ) {
2021-06-20 18:24:14 +03:00
dma_free_coherent ( & card - > pcidev - > dev , NS_TSQSIZE + NS_TSQ_ALIGNMENT ,
card - > tsq . org , card - > tsq . dma ) ;
2010-05-29 13:03:44 +04:00
}
if ( error > = 10 ) {
free_irq ( card - > pcidev - > irq , card ) ;
}
if ( error > = 4 ) {
iounmap ( card - > membase ) ;
}
if ( error > = 3 ) {
pci_disable_device ( card - > pcidev ) ;
kfree ( card ) ;
}
}
2005-04-17 02:20:36 +04:00
2010-05-29 13:04:25 +04:00
static scq_info * get_scq ( ns_dev * card , int size , u32 scd )
2005-04-17 02:20:36 +04:00
{
2010-05-29 13:03:44 +04:00
scq_info * scq ;
int i ;
if ( size ! = VBR_SCQSIZE & & size ! = CBR_SCQSIZE )
return NULL ;
2016-09-10 09:18:10 +03:00
scq = kmalloc ( sizeof ( * scq ) , GFP_KERNEL ) ;
2010-05-29 13:04:25 +04:00
if ( ! scq )
2010-05-29 13:03:44 +04:00
return NULL ;
2015-01-16 16:57:21 +03:00
scq - > org = dma_alloc_coherent ( & card - > pcidev - > dev ,
2 * size , & scq - > dma , GFP_KERNEL ) ;
2010-05-29 13:04:25 +04:00
if ( ! scq - > org ) {
2010-05-29 13:03:44 +04:00
kfree ( scq ) ;
return NULL ;
}
2016-09-10 09:02:06 +03:00
scq - > skb = kmalloc_array ( size / NS_SCQE_SIZE ,
sizeof ( * scq - > skb ) ,
GFP_KERNEL ) ;
2010-05-29 13:04:25 +04:00
if ( ! scq - > skb ) {
2016-07-17 10:03:24 +03:00
dma_free_coherent ( & card - > pcidev - > dev ,
2 * size , scq - > org , scq - > dma ) ;
2010-05-29 13:03:44 +04:00
kfree ( scq ) ;
return NULL ;
}
scq - > num_entries = size / NS_SCQE_SIZE ;
2010-05-29 13:04:25 +04:00
scq - > base = PTR_ALIGN ( scq - > org , size ) ;
2010-05-29 13:03:44 +04:00
scq - > next = scq - > base ;
scq - > last = scq - > base + ( scq - > num_entries - 1 ) ;
scq - > tail = scq - > last ;
scq - > scd = scd ;
scq - > num_entries = size / NS_SCQE_SIZE ;
scq - > tbd_count = 0 ;
init_waitqueue_head ( & scq - > scqfull_waitq ) ;
scq - > full = 0 ;
spin_lock_init ( & scq - > lock ) ;
for ( i = 0 ; i < scq - > num_entries ; i + + )
scq - > skb [ i ] = NULL ;
return scq ;
2005-04-17 02:20:36 +04:00
}
/* For variable rate SCQ vcc must be NULL */
2010-05-29 13:04:25 +04:00
static void free_scq ( ns_dev * card , scq_info * scq , struct atm_vcc * vcc )
2005-04-17 02:20:36 +04:00
{
2010-05-29 13:03:44 +04:00
int i ;
if ( scq - > num_entries = = VBR_SCQ_NUM_ENTRIES )
for ( i = 0 ; i < scq - > num_entries ; i + + ) {
if ( scq - > skb [ i ] ! = NULL ) {
vcc = ATM_SKB ( scq - > skb [ i ] ) - > vcc ;
if ( vcc - > pop ! = NULL )
vcc - > pop ( vcc , scq - > skb [ i ] ) ;
else
dev_kfree_skb_any ( scq - > skb [ i ] ) ;
}
} else { /* vcc must be != NULL */
if ( vcc = = NULL ) {
printk
( " nicstar: free_scq() called with vcc == NULL for fixed rate scq. " ) ;
for ( i = 0 ; i < scq - > num_entries ; i + + )
dev_kfree_skb_any ( scq - > skb [ i ] ) ;
} else
for ( i = 0 ; i < scq - > num_entries ; i + + ) {
if ( scq - > skb [ i ] ! = NULL ) {
if ( vcc - > pop ! = NULL )
vcc - > pop ( vcc , scq - > skb [ i ] ) ;
else
dev_kfree_skb_any ( scq - > skb [ i ] ) ;
}
}
}
kfree ( scq - > skb ) ;
2015-01-16 16:57:21 +03:00
dma_free_coherent ( & card - > pcidev - > dev ,
2 * ( scq - > num_entries = = VBR_SCQ_NUM_ENTRIES ?
VBR_SCQSIZE : CBR_SCQSIZE ) ,
scq - > org , scq - > dma ) ;
2010-05-29 13:03:44 +04:00
kfree ( scq ) ;
2005-04-17 02:20:36 +04:00
}
/* The handles passed must be pointers to the sk_buff containing the small
or large buffer ( s ) cast to u32 . */
2010-05-29 13:03:44 +04:00
static void push_rxbufs ( ns_dev * card , struct sk_buff * skb )
2005-04-17 02:20:36 +04:00
{
2010-05-29 13:04:25 +04:00
struct sk_buff * handle1 , * handle2 ;
2013-02-28 05:04:00 +04:00
int id1 , id2 ;
2010-05-29 13:04:25 +04:00
u32 addr1 , addr2 ;
2010-05-29 13:03:44 +04:00
u32 stat ;
unsigned long flags ;
/* *BARF* */
2010-05-29 13:04:25 +04:00
handle2 = NULL ;
addr2 = 0 ;
handle1 = skb ;
2015-01-16 16:57:21 +03:00
addr1 = dma_map_single ( & card - > pcidev - > dev ,
2010-05-29 13:04:25 +04:00
skb - > data ,
( NS_PRV_BUFTYPE ( skb ) = = BUF_SM
? NS_SMSKBSIZE : NS_LGSKBSIZE ) ,
2015-01-16 16:57:21 +03:00
DMA_TO_DEVICE ) ;
2010-05-29 13:04:25 +04:00
NS_PRV_DMA ( skb ) = addr1 ; /* save so we can unmap later */
2005-04-17 02:20:36 +04:00
# ifdef GENERAL_DEBUG
2010-05-29 13:03:44 +04:00
if ( ! addr1 )
printk ( " nicstar%d: push_rxbufs called with addr1 = 0. \n " ,
card - > index ) ;
2005-04-17 02:20:36 +04:00
# endif /* GENERAL_DEBUG */
2010-05-29 13:03:44 +04:00
stat = readl ( card - > membase + STAT ) ;
card - > sbfqc = ns_stat_sfbqc_get ( stat ) ;
card - > lbfqc = ns_stat_lfbqc_get ( stat ) ;
2010-05-29 13:04:25 +04:00
if ( NS_PRV_BUFTYPE ( skb ) = = BUF_SM ) {
2010-05-29 13:03:44 +04:00
if ( ! addr2 ) {
if ( card - > sm_addr ) {
addr2 = card - > sm_addr ;
handle2 = card - > sm_handle ;
card - > sm_addr = 0x00000000 ;
2014-02-19 05:10:11 +04:00
card - > sm_handle = NULL ;
2010-05-29 13:03:44 +04:00
} else { /* (!sm_addr) */
card - > sm_addr = addr1 ;
card - > sm_handle = handle1 ;
}
}
} else { /* buf_type == BUF_LG */
if ( ! addr2 ) {
if ( card - > lg_addr ) {
addr2 = card - > lg_addr ;
handle2 = card - > lg_handle ;
card - > lg_addr = 0x00000000 ;
2014-02-19 05:10:11 +04:00
card - > lg_handle = NULL ;
2010-05-29 13:03:44 +04:00
} else { /* (!lg_addr) */
card - > lg_addr = addr1 ;
card - > lg_handle = handle1 ;
}
}
}
if ( addr2 ) {
2010-05-29 13:04:25 +04:00
if ( NS_PRV_BUFTYPE ( skb ) = = BUF_SM ) {
2010-05-29 13:03:44 +04:00
if ( card - > sbfqc > = card - > sbnr . max ) {
2010-05-29 13:04:25 +04:00
skb_unlink ( handle1 , & card - > sbpool . queue ) ;
dev_kfree_skb_any ( handle1 ) ;
skb_unlink ( handle2 , & card - > sbpool . queue ) ;
dev_kfree_skb_any ( handle2 ) ;
2010-05-29 13:03:44 +04:00
return ;
} else
card - > sbfqc + = 2 ;
} else { /* (buf_type == BUF_LG) */
if ( card - > lbfqc > = card - > lbnr . max ) {
2010-05-29 13:04:25 +04:00
skb_unlink ( handle1 , & card - > lbpool . queue ) ;
dev_kfree_skb_any ( handle1 ) ;
skb_unlink ( handle2 , & card - > lbpool . queue ) ;
dev_kfree_skb_any ( handle2 ) ;
2010-05-29 13:03:44 +04:00
return ;
} else
card - > lbfqc + = 2 ;
}
2013-02-28 05:04:00 +04:00
id1 = idr_alloc ( & card - > idr , handle1 , 0 , 0 , GFP_ATOMIC ) ;
if ( id1 < 0 )
goto out ;
2010-05-29 13:03:44 +04:00
2013-02-28 05:04:00 +04:00
id2 = idr_alloc ( & card - > idr , handle2 , 0 , 0 , GFP_ATOMIC ) ;
if ( id2 < 0 )
2010-05-29 13:04:25 +04:00
goto out ;
spin_lock_irqsave ( & card - > res_lock , flags ) ;
2010-05-29 13:03:44 +04:00
while ( CMD_BUSY ( card ) ) ;
writel ( addr2 , card - > membase + DR3 ) ;
2010-05-29 13:04:25 +04:00
writel ( id2 , card - > membase + DR2 ) ;
2010-05-29 13:03:44 +04:00
writel ( addr1 , card - > membase + DR1 ) ;
2010-05-29 13:04:25 +04:00
writel ( id1 , card - > membase + DR0 ) ;
writel ( NS_CMD_WRITE_FREEBUFQ | NS_PRV_BUFTYPE ( skb ) ,
2010-05-29 13:03:44 +04:00
card - > membase + CMD ) ;
spin_unlock_irqrestore ( & card - > res_lock , flags ) ;
XPRINTK ( " nicstar%d: Pushing %s buffers at 0x%x and 0x%x. \n " ,
card - > index ,
2010-05-29 13:04:25 +04:00
( NS_PRV_BUFTYPE ( skb ) = = BUF_SM ? " small " : " large " ) ,
addr1 , addr2 ) ;
2010-05-29 13:03:44 +04:00
}
if ( ! card - > efbie & & card - > sbfqc > = card - > sbnr . min & &
card - > lbfqc > = card - > lbnr . min ) {
card - > efbie = 1 ;
writel ( ( readl ( card - > membase + CFG ) | NS_CFG_EFBIE ) ,
card - > membase + CFG ) ;
}
2010-05-29 13:04:25 +04:00
out :
2010-05-29 13:03:44 +04:00
return ;
2005-04-17 02:20:36 +04:00
}
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 17:55:46 +04:00
static irqreturn_t ns_irq_handler ( int irq , void * dev_id )
2005-04-17 02:20:36 +04:00
{
2010-05-29 13:03:44 +04:00
u32 stat_r ;
ns_dev * card ;
struct atm_dev * dev ;
unsigned long flags ;
card = ( ns_dev * ) dev_id ;
dev = card - > atmdev ;
card - > intcnt + + ;
PRINTK ( " nicstar%d: NICStAR generated an interrupt \n " , card - > index ) ;
spin_lock_irqsave ( & card - > int_lock , flags ) ;
stat_r = readl ( card - > membase + STAT ) ;
/* Transmit Status Indicator has been written to T. S. Queue */
if ( stat_r & NS_STAT_TSIF ) {
TXPRINTK ( " nicstar%d: TSI interrupt \n " , card - > index ) ;
process_tsq ( card ) ;
writel ( NS_STAT_TSIF , card - > membase + STAT ) ;
}
/* Incomplete CS-PDU has been transmitted */
if ( stat_r & NS_STAT_TXICP ) {
writel ( NS_STAT_TXICP , card - > membase + STAT ) ;
TXPRINTK ( " nicstar%d: Incomplete CS-PDU transmitted. \n " ,
card - > index ) ;
}
/* Transmit Status Queue 7/8 full */
if ( stat_r & NS_STAT_TSQF ) {
writel ( NS_STAT_TSQF , card - > membase + STAT ) ;
PRINTK ( " nicstar%d: TSQ full. \n " , card - > index ) ;
process_tsq ( card ) ;
}
/* Timer overflow */
if ( stat_r & NS_STAT_TMROF ) {
writel ( NS_STAT_TMROF , card - > membase + STAT ) ;
PRINTK ( " nicstar%d: Timer overflow. \n " , card - > index ) ;
}
/* PHY device interrupt signal active */
if ( stat_r & NS_STAT_PHYI ) {
writel ( NS_STAT_PHYI , card - > membase + STAT ) ;
PRINTK ( " nicstar%d: PHY interrupt. \n " , card - > index ) ;
if ( dev - > phy & & dev - > phy - > interrupt ) {
dev - > phy - > interrupt ( dev ) ;
}
}
/* Small Buffer Queue is full */
if ( stat_r & NS_STAT_SFBQF ) {
writel ( NS_STAT_SFBQF , card - > membase + STAT ) ;
printk ( " nicstar%d: Small free buffer queue is full. \n " ,
card - > index ) ;
}
/* Large Buffer Queue is full */
if ( stat_r & NS_STAT_LFBQF ) {
writel ( NS_STAT_LFBQF , card - > membase + STAT ) ;
printk ( " nicstar%d: Large free buffer queue is full. \n " ,
card - > index ) ;
}
/* Receive Status Queue is full */
if ( stat_r & NS_STAT_RSQF ) {
writel ( NS_STAT_RSQF , card - > membase + STAT ) ;
printk ( " nicstar%d: RSQ full. \n " , card - > index ) ;
process_rsq ( card ) ;
}
/* Complete CS-PDU received */
if ( stat_r & NS_STAT_EOPDU ) {
RXPRINTK ( " nicstar%d: End of CS-PDU received. \n " , card - > index ) ;
process_rsq ( card ) ;
writel ( NS_STAT_EOPDU , card - > membase + STAT ) ;
}
/* Raw cell received */
if ( stat_r & NS_STAT_RAWCF ) {
writel ( NS_STAT_RAWCF , card - > membase + STAT ) ;
2005-04-17 02:20:36 +04:00
# ifndef RCQ_SUPPORT
2010-05-29 13:03:44 +04:00
printk ( " nicstar%d: Raw cell received and no support yet... \n " ,
card - > index ) ;
2005-04-17 02:20:36 +04:00
# endif /* RCQ_SUPPORT */
2010-05-29 13:03:44 +04:00
/* NOTE: the following procedure may keep a raw cell pending until the
next interrupt . As this preliminary support is only meant to
avoid buffer leakage , this is not an issue . */
while ( readl ( card - > membase + RAWCT ) ! = card - > rawch ) {
2010-05-29 13:04:25 +04:00
if ( ns_rcqe_islast ( card - > rawcell ) ) {
2010-05-29 13:03:44 +04:00
struct sk_buff * oldbuf ;
oldbuf = card - > rcbuf ;
2010-05-29 13:04:25 +04:00
card - > rcbuf = idr_find ( & card - > idr ,
ns_rcqe_nextbufhandle ( card - > rawcell ) ) ;
card - > rawch = NS_PRV_DMA ( card - > rcbuf ) ;
card - > rawcell = ( struct ns_rcqe * )
card - > rcbuf - > data ;
2010-05-29 13:03:44 +04:00
recycle_rx_buf ( card , oldbuf ) ;
2010-05-29 13:04:25 +04:00
} else {
2010-05-29 13:03:44 +04:00
card - > rawch + = NS_RCQE_SIZE ;
2010-05-29 13:04:25 +04:00
card - > rawcell + + ;
}
2010-05-29 13:03:44 +04:00
}
}
/* Small buffer queue is empty */
if ( stat_r & NS_STAT_SFBQE ) {
int i ;
struct sk_buff * sb ;
writel ( NS_STAT_SFBQE , card - > membase + STAT ) ;
printk ( " nicstar%d: Small free buffer queue empty. \n " ,
card - > index ) ;
for ( i = 0 ; i < card - > sbnr . min ; i + + ) {
sb = dev_alloc_skb ( NS_SMSKBSIZE ) ;
if ( sb = = NULL ) {
writel ( readl ( card - > membase + CFG ) &
~ NS_CFG_EFBIE , card - > membase + CFG ) ;
card - > efbie = 0 ;
break ;
}
2010-05-29 13:04:25 +04:00
NS_PRV_BUFTYPE ( sb ) = BUF_SM ;
2010-05-29 13:03:44 +04:00
skb_queue_tail ( & card - > sbpool . queue , sb ) ;
skb_reserve ( sb , NS_AAL0_HEADER ) ;
push_rxbufs ( card , sb ) ;
}
card - > sbfqc = i ;
process_rsq ( card ) ;
}
/* Large buffer queue empty */
if ( stat_r & NS_STAT_LFBQE ) {
int i ;
struct sk_buff * lb ;
writel ( NS_STAT_LFBQE , card - > membase + STAT ) ;
printk ( " nicstar%d: Large free buffer queue empty. \n " ,
card - > index ) ;
for ( i = 0 ; i < card - > lbnr . min ; i + + ) {
lb = dev_alloc_skb ( NS_LGSKBSIZE ) ;
if ( lb = = NULL ) {
writel ( readl ( card - > membase + CFG ) &
~ NS_CFG_EFBIE , card - > membase + CFG ) ;
card - > efbie = 0 ;
break ;
}
2010-05-29 13:04:25 +04:00
NS_PRV_BUFTYPE ( lb ) = BUF_LG ;
2010-05-29 13:03:44 +04:00
skb_queue_tail ( & card - > lbpool . queue , lb ) ;
skb_reserve ( lb , NS_SMBUFSIZE ) ;
push_rxbufs ( card , lb ) ;
}
card - > lbfqc = i ;
process_rsq ( card ) ;
}
/* Receive Status Queue is 7/8 full */
if ( stat_r & NS_STAT_RSQAF ) {
writel ( NS_STAT_RSQAF , card - > membase + STAT ) ;
RXPRINTK ( " nicstar%d: RSQ almost full. \n " , card - > index ) ;
process_rsq ( card ) ;
}
spin_unlock_irqrestore ( & card - > int_lock , flags ) ;
PRINTK ( " nicstar%d: end of interrupt service \n " , card - > index ) ;
return IRQ_HANDLED ;
2005-04-17 02:20:36 +04:00
}
static int ns_open ( struct atm_vcc * vcc )
{
2010-05-29 13:03:44 +04:00
ns_dev * card ;
vc_map * vc ;
unsigned long tmpl , modl ;
int tcr , tcra ; /* target cell rate, and absolute value */
int n = 0 ; /* Number of entries in the TST. Initialized to remove
the compiler warning . */
u32 u32d [ 4 ] ;
int frscdi = 0 ; /* Index of the SCD. Initialized to remove the compiler
warning . How I wish compilers were clever enough to
tell which variables can truly be used
uninitialized . . . */
int inuse ; /* tx or rx vc already in use by another vcc */
short vpi = vcc - > vpi ;
int vci = vcc - > vci ;
card = ( ns_dev * ) vcc - > dev - > dev_data ;
PRINTK ( " nicstar%d: opening vpi.vci %d.%d \n " , card - > index , ( int ) vpi ,
vci ) ;
if ( vcc - > qos . aal ! = ATM_AAL5 & & vcc - > qos . aal ! = ATM_AAL0 ) {
PRINTK ( " nicstar%d: unsupported AAL. \n " , card - > index ) ;
return - EINVAL ;
}
vc = & ( card - > vcmap [ vpi < < card - > vcibits | vci ] ) ;
vcc - > dev_data = vc ;
inuse = 0 ;
if ( vcc - > qos . txtp . traffic_class ! = ATM_NONE & & vc - > tx )
inuse = 1 ;
if ( vcc - > qos . rxtp . traffic_class ! = ATM_NONE & & vc - > rx )
inuse + = 2 ;
if ( inuse ) {
printk ( " nicstar%d: %s vci already in use. \n " , card - > index ,
inuse = = 1 ? " tx " : inuse = = 2 ? " rx " : " tx and rx " ) ;
return - EINVAL ;
}
set_bit ( ATM_VF_ADDR , & vcc - > flags ) ;
/* NOTE: You are not allowed to modify an open connection's QOS. To change
that , remove the ATM_VF_PARTIAL flag checking . There may be other changes
needed to do that . */
if ( ! test_bit ( ATM_VF_PARTIAL , & vcc - > flags ) ) {
scq_info * scq ;
set_bit ( ATM_VF_PARTIAL , & vcc - > flags ) ;
if ( vcc - > qos . txtp . traffic_class = = ATM_CBR ) {
/* Check requested cell rate and availability of SCD */
if ( vcc - > qos . txtp . max_pcr = = 0 & & vcc - > qos . txtp . pcr = = 0
& & vcc - > qos . txtp . min_pcr = = 0 ) {
PRINTK
( " nicstar%d: trying to open a CBR vc with cell rate = 0 \n " ,
card - > index ) ;
clear_bit ( ATM_VF_PARTIAL , & vcc - > flags ) ;
clear_bit ( ATM_VF_ADDR , & vcc - > flags ) ;
return - EINVAL ;
}
tcr = atm_pcr_goal ( & ( vcc - > qos . txtp ) ) ;
tcra = tcr > = 0 ? tcr : - tcr ;
PRINTK ( " nicstar%d: target cell rate = %d. \n " ,
card - > index , vcc - > qos . txtp . max_pcr ) ;
tmpl =
( unsigned long ) tcra * ( unsigned long )
NS_TST_NUM_ENTRIES ;
modl = tmpl % card - > max_pcr ;
n = ( int ) ( tmpl / card - > max_pcr ) ;
if ( tcr > 0 ) {
if ( modl > 0 )
n + + ;
} else if ( tcr = = 0 ) {
if ( ( n =
( card - > tst_free_entries -
NS_TST_RESERVED ) ) < = 0 ) {
PRINTK
( " nicstar%d: no CBR bandwidth free. \n " ,
card - > index ) ;
clear_bit ( ATM_VF_PARTIAL , & vcc - > flags ) ;
clear_bit ( ATM_VF_ADDR , & vcc - > flags ) ;
return - EINVAL ;
}
}
if ( n = = 0 ) {
printk
( " nicstar%d: selected bandwidth < granularity. \n " ,
card - > index ) ;
clear_bit ( ATM_VF_PARTIAL , & vcc - > flags ) ;
clear_bit ( ATM_VF_ADDR , & vcc - > flags ) ;
return - EINVAL ;
}
if ( n > ( card - > tst_free_entries - NS_TST_RESERVED ) ) {
PRINTK
( " nicstar%d: not enough free CBR bandwidth. \n " ,
card - > index ) ;
clear_bit ( ATM_VF_PARTIAL , & vcc - > flags ) ;
clear_bit ( ATM_VF_ADDR , & vcc - > flags ) ;
return - EINVAL ;
} else
card - > tst_free_entries - = n ;
XPRINTK ( " nicstar%d: writing %d tst entries. \n " ,
card - > index , n ) ;
for ( frscdi = 0 ; frscdi < NS_FRSCD_NUM ; frscdi + + ) {
if ( card - > scd2vc [ frscdi ] = = NULL ) {
card - > scd2vc [ frscdi ] = vc ;
break ;
}
}
if ( frscdi = = NS_FRSCD_NUM ) {
PRINTK
( " nicstar%d: no SCD available for CBR channel. \n " ,
card - > index ) ;
card - > tst_free_entries + = n ;
clear_bit ( ATM_VF_PARTIAL , & vcc - > flags ) ;
clear_bit ( ATM_VF_ADDR , & vcc - > flags ) ;
return - EBUSY ;
}
vc - > cbr_scd = NS_FRSCD + frscdi * NS_FRSCD_SIZE ;
2010-05-29 13:04:25 +04:00
scq = get_scq ( card , CBR_SCQSIZE , vc - > cbr_scd ) ;
2010-05-29 13:03:44 +04:00
if ( scq = = NULL ) {
PRINTK ( " nicstar%d: can't get fixed rate SCQ. \n " ,
card - > index ) ;
card - > scd2vc [ frscdi ] = NULL ;
card - > tst_free_entries + = n ;
clear_bit ( ATM_VF_PARTIAL , & vcc - > flags ) ;
clear_bit ( ATM_VF_ADDR , & vcc - > flags ) ;
return - ENOMEM ;
}
vc - > scq = scq ;
2010-05-29 13:04:25 +04:00
u32d [ 0 ] = scq_virt_to_bus ( scq , scq - > base ) ;
2010-05-29 13:03:44 +04:00
u32d [ 1 ] = ( u32 ) 0x00000000 ;
u32d [ 2 ] = ( u32 ) 0xffffffff ;
u32d [ 3 ] = ( u32 ) 0x00000000 ;
ns_write_sram ( card , vc - > cbr_scd , u32d , 4 ) ;
fill_tst ( card , n , vc ) ;
} else if ( vcc - > qos . txtp . traffic_class = = ATM_UBR ) {
vc - > cbr_scd = 0x00000000 ;
vc - > scq = card - > scq0 ;
}
if ( vcc - > qos . txtp . traffic_class ! = ATM_NONE ) {
vc - > tx = 1 ;
vc - > tx_vcc = vcc ;
vc - > tbd_count = 0 ;
}
if ( vcc - > qos . rxtp . traffic_class ! = ATM_NONE ) {
u32 status ;
vc - > rx = 1 ;
vc - > rx_vcc = vcc ;
vc - > rx_iov = NULL ;
/* Open the connection in hardware */
if ( vcc - > qos . aal = = ATM_AAL5 )
status = NS_RCTE_AAL5 | NS_RCTE_CONNECTOPEN ;
else /* vcc->qos.aal == ATM_AAL0 */
status = NS_RCTE_AAL0 | NS_RCTE_CONNECTOPEN ;
2005-04-17 02:20:36 +04:00
# ifdef RCQ_SUPPORT
2010-05-29 13:03:44 +04:00
status | = NS_RCTE_RAWCELLINTEN ;
2005-04-17 02:20:36 +04:00
# endif /* RCQ_SUPPORT */
2010-05-29 13:03:44 +04:00
ns_write_sram ( card ,
NS_RCT +
( vpi < < card - > vcibits | vci ) *
NS_RCT_ENTRY_SIZE , & status , 1 ) ;
}
2005-04-17 02:20:36 +04:00
2010-05-29 13:03:44 +04:00
}
2005-04-17 02:20:36 +04:00
2010-05-29 13:03:44 +04:00
set_bit ( ATM_VF_READY , & vcc - > flags ) ;
return 0 ;
}
2005-04-17 02:20:36 +04:00
static void ns_close ( struct atm_vcc * vcc )
{
2010-05-29 13:03:44 +04:00
vc_map * vc ;
ns_dev * card ;
u32 data ;
int i ;
vc = vcc - > dev_data ;
card = vcc - > dev - > dev_data ;
PRINTK ( " nicstar%d: closing vpi.vci %d.%d \n " , card - > index ,
( int ) vcc - > vpi , vcc - > vci ) ;
clear_bit ( ATM_VF_READY , & vcc - > flags ) ;
if ( vcc - > qos . rxtp . traffic_class ! = ATM_NONE ) {
u32 addr ;
unsigned long flags ;
addr =
NS_RCT +
( vcc - > vpi < < card - > vcibits | vcc - > vci ) * NS_RCT_ENTRY_SIZE ;
spin_lock_irqsave ( & card - > res_lock , flags ) ;
while ( CMD_BUSY ( card ) ) ;
writel ( NS_CMD_CLOSE_CONNECTION | addr < < 2 ,
card - > membase + CMD ) ;
spin_unlock_irqrestore ( & card - > res_lock , flags ) ;
vc - > rx = 0 ;
if ( vc - > rx_iov ! = NULL ) {
struct sk_buff * iovb ;
u32 stat ;
stat = readl ( card - > membase + STAT ) ;
card - > sbfqc = ns_stat_sfbqc_get ( stat ) ;
card - > lbfqc = ns_stat_lfbqc_get ( stat ) ;
PRINTK
( " nicstar%d: closing a VC with pending rx buffers. \n " ,
card - > index ) ;
iovb = vc - > rx_iov ;
recycle_iovec_rx_bufs ( card , ( struct iovec * ) iovb - > data ,
2010-05-29 13:04:25 +04:00
NS_PRV_IOVCNT ( iovb ) ) ;
NS_PRV_IOVCNT ( iovb ) = 0 ;
2010-05-29 13:03:44 +04:00
spin_lock_irqsave ( & card - > int_lock , flags ) ;
recycle_iov_buf ( card , iovb ) ;
spin_unlock_irqrestore ( & card - > int_lock , flags ) ;
vc - > rx_iov = NULL ;
}
}
if ( vcc - > qos . txtp . traffic_class ! = ATM_NONE ) {
vc - > tx = 0 ;
}
if ( vcc - > qos . txtp . traffic_class = = ATM_CBR ) {
unsigned long flags ;
ns_scqe * scqep ;
scq_info * scq ;
scq = vc - > scq ;
for ( ; ; ) {
spin_lock_irqsave ( & scq - > lock , flags ) ;
scqep = scq - > next ;
if ( scqep = = scq - > base )
scqep = scq - > last ;
else
scqep - - ;
if ( scqep = = scq - > tail ) {
spin_unlock_irqrestore ( & scq - > lock , flags ) ;
break ;
}
/* If the last entry is not a TSR, place one in the SCQ in order to
be able to completely drain it and then close . */
if ( ! ns_scqe_is_tsr ( scqep ) & & scq - > tail ! = scq - > next ) {
ns_scqe tsr ;
u32 scdi , scqi ;
u32 data ;
int index ;
tsr . word_1 = ns_tsr_mkword_1 ( NS_TSR_INTENABLE ) ;
scdi = ( vc - > cbr_scd - NS_FRSCD ) / NS_FRSCD_SIZE ;
scqi = scq - > next - scq - > base ;
tsr . word_2 = ns_tsr_mkword_2 ( scdi , scqi ) ;
tsr . word_3 = 0x00000000 ;
tsr . word_4 = 0x00000000 ;
* scq - > next = tsr ;
index = ( int ) scqi ;
scq - > skb [ index ] = NULL ;
if ( scq - > next = = scq - > last )
scq - > next = scq - > base ;
else
scq - > next + + ;
2010-05-29 13:04:25 +04:00
data = scq_virt_to_bus ( scq , scq - > next ) ;
2010-05-29 13:03:44 +04:00
ns_write_sram ( card , scq - > scd , & data , 1 ) ;
}
spin_unlock_irqrestore ( & scq - > lock , flags ) ;
schedule ( ) ;
}
/* Free all TST entries */
data = NS_TST_OPCODE_VARIABLE ;
for ( i = 0 ; i < NS_TST_NUM_ENTRIES ; i + + ) {
if ( card - > tste2vc [ i ] = = vc ) {
ns_write_sram ( card , card - > tst_addr + i , & data ,
1 ) ;
card - > tste2vc [ i ] = NULL ;
card - > tst_free_entries + + ;
}
}
card - > scd2vc [ ( vc - > cbr_scd - NS_FRSCD ) / NS_FRSCD_SIZE ] = NULL ;
2010-05-29 13:04:25 +04:00
free_scq ( card , vc - > scq , vcc ) ;
2010-05-29 13:03:44 +04:00
}
/* remove all references to vcc before deleting it */
if ( vcc - > qos . txtp . traffic_class ! = ATM_NONE ) {
unsigned long flags ;
scq_info * scq = card - > scq0 ;
spin_lock_irqsave ( & scq - > lock , flags ) ;
for ( i = 0 ; i < scq - > num_entries ; i + + ) {
if ( scq - > skb [ i ] & & ATM_SKB ( scq - > skb [ i ] ) - > vcc = = vcc ) {
ATM_SKB ( scq - > skb [ i ] ) - > vcc = NULL ;
atm_return ( vcc , scq - > skb [ i ] - > truesize ) ;
PRINTK
( " nicstar: deleted pending vcc mapping \n " ) ;
}
}
spin_unlock_irqrestore ( & scq - > lock , flags ) ;
}
vcc - > dev_data = NULL ;
clear_bit ( ATM_VF_PARTIAL , & vcc - > flags ) ;
clear_bit ( ATM_VF_ADDR , & vcc - > flags ) ;
2005-04-17 02:20:36 +04:00
# ifdef RX_DEBUG
2010-05-29 13:03:44 +04:00
{
u32 stat , cfg ;
stat = readl ( card - > membase + STAT ) ;
cfg = readl ( card - > membase + CFG ) ;
printk ( " STAT = 0x%08X CFG = 0x%08X \n " , stat , cfg ) ;
printk
2010-05-29 13:04:25 +04:00
( " TSQ: base = 0x%p next = 0x%p last = 0x%p TSQT = 0x%08X \n " ,
card - > tsq . base , card - > tsq . next ,
card - > tsq . last , readl ( card - > membase + TSQT ) ) ;
2010-05-29 13:03:44 +04:00
printk
2010-05-29 13:04:25 +04:00
( " RSQ: base = 0x%p next = 0x%p last = 0x%p RSQT = 0x%08X \n " ,
card - > rsq . base , card - > rsq . next ,
card - > rsq . last , readl ( card - > membase + RSQT ) ) ;
2010-05-29 13:03:44 +04:00
printk ( " Empty free buffer queue interrupt %s \n " ,
card - > efbie ? " enabled " : " disabled " ) ;
printk ( " SBCNT = %d count = %d LBCNT = %d count = %d \n " ,
ns_stat_sfbqc_get ( stat ) , card - > sbpool . count ,
ns_stat_lfbqc_get ( stat ) , card - > lbpool . count ) ;
printk ( " hbpool.count = %d iovpool.count = %d \n " ,
card - > hbpool . count , card - > iovpool . count ) ;
}
2005-04-17 02:20:36 +04:00
# endif /* RX_DEBUG */
}
2010-05-29 13:03:44 +04:00
static void fill_tst ( ns_dev * card , int n , vc_map * vc )
2005-04-17 02:20:36 +04:00
{
2010-05-29 13:03:44 +04:00
u32 new_tst ;
unsigned long cl ;
int e , r ;
u32 data ;
/* It would be very complicated to keep the two TSTs synchronized while
assuring that writes are only made to the inactive TST . So , for now I
will use only one TST . If problems occur , I will change this again */
new_tst = card - > tst_addr ;
/* Fill procedure */
for ( e = 0 ; e < NS_TST_NUM_ENTRIES ; e + + ) {
if ( card - > tste2vc [ e ] = = NULL )
break ;
}
if ( e = = NS_TST_NUM_ENTRIES ) {
printk ( " nicstar%d: No free TST entries found. \n " , card - > index ) ;
return ;
}
r = n ;
cl = NS_TST_NUM_ENTRIES ;
data = ns_tste_make ( NS_TST_OPCODE_FIXED , vc - > cbr_scd ) ;
while ( r > 0 ) {
if ( cl > = NS_TST_NUM_ENTRIES & & card - > tste2vc [ e ] = = NULL ) {
card - > tste2vc [ e ] = vc ;
ns_write_sram ( card , new_tst + e , & data , 1 ) ;
cl - = NS_TST_NUM_ENTRIES ;
r - - ;
}
if ( + + e = = NS_TST_NUM_ENTRIES ) {
e = 0 ;
}
cl + = n ;
}
/* End of fill procedure */
data = ns_tste_make ( NS_TST_OPCODE_END , new_tst ) ;
ns_write_sram ( card , new_tst + NS_TST_NUM_ENTRIES , & data , 1 ) ;
ns_write_sram ( card , card - > tst_addr + NS_TST_NUM_ENTRIES , & data , 1 ) ;
card - > tst_addr = new_tst ;
2005-04-17 02:20:36 +04:00
}
2020-11-16 19:21:15 +03:00
static int _ns_send ( struct atm_vcc * vcc , struct sk_buff * skb , bool may_sleep )
2005-04-17 02:20:36 +04:00
{
2010-05-29 13:03:44 +04:00
ns_dev * card ;
vc_map * vc ;
scq_info * scq ;
unsigned long buflen ;
ns_scqe scqe ;
u32 flags ; /* TBD flags, not CPU flags */
card = vcc - > dev - > dev_data ;
TXPRINTK ( " nicstar%d: ns_send() called. \n " , card - > index ) ;
if ( ( vc = ( vc_map * ) vcc - > dev_data ) = = NULL ) {
printk ( " nicstar%d: vcc->dev_data == NULL on ns_send(). \n " ,
card - > index ) ;
atomic_inc ( & vcc - > stats - > tx_err ) ;
dev_kfree_skb_any ( skb ) ;
return - EINVAL ;
}
2005-04-17 02:20:36 +04:00
2010-05-29 13:03:44 +04:00
if ( ! vc - > tx ) {
printk ( " nicstar%d: Trying to transmit on a non-tx VC. \n " ,
card - > index ) ;
atomic_inc ( & vcc - > stats - > tx_err ) ;
dev_kfree_skb_any ( skb ) ;
return - EINVAL ;
}
2005-04-17 02:20:36 +04:00
2010-05-29 13:03:44 +04:00
if ( vcc - > qos . aal ! = ATM_AAL5 & & vcc - > qos . aal ! = ATM_AAL0 ) {
printk ( " nicstar%d: Only AAL0 and AAL5 are supported. \n " ,
card - > index ) ;
atomic_inc ( & vcc - > stats - > tx_err ) ;
dev_kfree_skb_any ( skb ) ;
return - EINVAL ;
}
2005-04-17 02:20:36 +04:00
2010-05-29 13:03:44 +04:00
if ( skb_shinfo ( skb ) - > nr_frags ! = 0 ) {
printk ( " nicstar%d: No scatter-gather yet. \n " , card - > index ) ;
atomic_inc ( & vcc - > stats - > tx_err ) ;
dev_kfree_skb_any ( skb ) ;
return - EINVAL ;
}
ATM_SKB ( skb ) - > vcc = vcc ;
2015-01-16 16:57:21 +03:00
NS_PRV_DMA ( skb ) = dma_map_single ( & card - > pcidev - > dev , skb - > data ,
skb - > len , DMA_TO_DEVICE ) ;
2010-05-29 13:04:25 +04:00
2010-05-29 13:03:44 +04:00
if ( vcc - > qos . aal = = ATM_AAL5 ) {
buflen = ( skb - > len + 47 + 8 ) / 48 * 48 ; /* Multiple of 48 */
flags = NS_TBD_AAL5 ;
2010-05-29 13:04:25 +04:00
scqe . word_2 = cpu_to_le32 ( NS_PRV_DMA ( skb ) ) ;
scqe . word_3 = cpu_to_le32 ( skb - > len ) ;
2010-05-29 13:03:44 +04:00
scqe . word_4 =
ns_tbd_mkword_4 ( 0 , ( u32 ) vcc - > vpi , ( u32 ) vcc - > vci , 0 ,
ATM_SKB ( skb ) - >
atm_options & ATM_ATMOPT_CLP ? 1 : 0 ) ;
flags | = NS_TBD_EOPDU ;
} else { /* (vcc->qos.aal == ATM_AAL0) */
buflen = ATM_CELL_PAYLOAD ; /* i.e., 48 bytes */
flags = NS_TBD_AAL0 ;
2010-05-29 13:04:25 +04:00
scqe . word_2 = cpu_to_le32 ( NS_PRV_DMA ( skb ) + NS_AAL0_HEADER ) ;
2010-05-29 13:03:44 +04:00
scqe . word_3 = cpu_to_le32 ( 0x00000000 ) ;
if ( * skb - > data & 0x02 ) /* Payload type 1 - end of pdu */
flags | = NS_TBD_EOPDU ;
scqe . word_4 =
cpu_to_le32 ( * ( ( u32 * ) skb - > data ) & ~ NS_TBD_VC_MASK ) ;
/* Force the VPI/VCI to be the same as in VCC struct */
scqe . word_4 | =
cpu_to_le32 ( ( ( ( u32 ) vcc - >
vpi ) < < NS_TBD_VPI_SHIFT | ( ( u32 ) vcc - >
vci ) < <
NS_TBD_VCI_SHIFT ) & NS_TBD_VC_MASK ) ;
}
if ( vcc - > qos . txtp . traffic_class = = ATM_CBR ) {
scqe . word_1 = ns_tbd_mkword_1_novbr ( flags , ( u32 ) buflen ) ;
scq = ( ( vc_map * ) vcc - > dev_data ) - > scq ;
} else {
scqe . word_1 =
ns_tbd_mkword_1 ( flags , ( u32 ) 1 , ( u32 ) 1 , ( u32 ) buflen ) ;
scq = card - > scq0 ;
}
2020-11-16 19:21:15 +03:00
if ( push_scqe ( card , vc , scq , & scqe , skb , may_sleep ) ! = 0 ) {
2010-05-29 13:03:44 +04:00
atomic_inc ( & vcc - > stats - > tx_err ) ;
2020-11-16 19:21:14 +03:00
dma_unmap_single ( & card - > pcidev - > dev , NS_PRV_DMA ( skb ) , skb - > len ,
DMA_TO_DEVICE ) ;
2010-05-29 13:03:44 +04:00
dev_kfree_skb_any ( skb ) ;
return - EIO ;
}
atomic_inc ( & vcc - > stats - > tx ) ;
2005-04-17 02:20:36 +04:00
2010-05-29 13:03:44 +04:00
return 0 ;
}
2005-04-17 02:20:36 +04:00
2020-11-16 19:21:15 +03:00
static int ns_send ( struct atm_vcc * vcc , struct sk_buff * skb )
{
return _ns_send ( vcc , skb , true ) ;
}
static int ns_send_bh ( struct atm_vcc * vcc , struct sk_buff * skb )
{
return _ns_send ( vcc , skb , false ) ;
}
2010-05-29 13:03:44 +04:00
static int push_scqe ( ns_dev * card , vc_map * vc , scq_info * scq , ns_scqe * tbd ,
2020-11-16 19:21:15 +03:00
struct sk_buff * skb , bool may_sleep )
2005-04-17 02:20:36 +04:00
{
2010-05-29 13:03:44 +04:00
unsigned long flags ;
ns_scqe tsr ;
u32 scdi , scqi ;
int scq_is_vbr ;
u32 data ;
int index ;
spin_lock_irqsave ( & scq - > lock , flags ) ;
while ( scq - > tail = = scq - > next ) {
2020-11-16 19:21:15 +03:00
if ( ! may_sleep ) {
2010-05-29 13:03:44 +04:00
spin_unlock_irqrestore ( & scq - > lock , flags ) ;
printk ( " nicstar%d: Error pushing TBD. \n " , card - > index ) ;
return 1 ;
}
scq - > full = 1 ;
2014-02-27 22:51:54 +04:00
wait_event_interruptible_lock_irq_timeout ( scq - > scqfull_waitq ,
scq - > tail ! = scq - > next ,
scq - > lock ,
SCQFULL_TIMEOUT ) ;
2010-05-29 13:03:44 +04:00
if ( scq - > full ) {
spin_unlock_irqrestore ( & scq - > lock , flags ) ;
printk ( " nicstar%d: Timeout pushing TBD. \n " ,
card - > index ) ;
return 1 ;
}
}
* scq - > next = * tbd ;
index = ( int ) ( scq - > next - scq - > base ) ;
scq - > skb [ index ] = skb ;
2010-05-29 13:04:25 +04:00
XPRINTK ( " nicstar%d: sending skb at 0x%p (pos %d). \n " ,
card - > index , skb , index ) ;
XPRINTK ( " nicstar%d: TBD written: \n 0x%x \n 0x%x \n 0x%x \n 0x%x \n at 0x%p. \n " ,
2010-05-29 13:03:44 +04:00
card - > index , le32_to_cpu ( tbd - > word_1 ) , le32_to_cpu ( tbd - > word_2 ) ,
le32_to_cpu ( tbd - > word_3 ) , le32_to_cpu ( tbd - > word_4 ) ,
2010-05-29 13:04:25 +04:00
scq - > next ) ;
2010-05-29 13:03:44 +04:00
if ( scq - > next = = scq - > last )
scq - > next = scq - > base ;
else
scq - > next + + ;
vc - > tbd_count + + ;
if ( scq - > num_entries = = VBR_SCQ_NUM_ENTRIES ) {
scq - > tbd_count + + ;
scq_is_vbr = 1 ;
} else
scq_is_vbr = 0 ;
if ( vc - > tbd_count > = MAX_TBD_PER_VC
| | scq - > tbd_count > = MAX_TBD_PER_SCQ ) {
int has_run = 0 ;
while ( scq - > tail = = scq - > next ) {
2020-11-16 19:21:15 +03:00
if ( ! may_sleep ) {
2010-05-29 13:04:25 +04:00
data = scq_virt_to_bus ( scq , scq - > next ) ;
2010-05-29 13:03:44 +04:00
ns_write_sram ( card , scq - > scd , & data , 1 ) ;
spin_unlock_irqrestore ( & scq - > lock , flags ) ;
printk ( " nicstar%d: Error pushing TSR. \n " ,
card - > index ) ;
return 0 ;
}
scq - > full = 1 ;
if ( has_run + + )
break ;
2014-02-27 22:51:54 +04:00
wait_event_interruptible_lock_irq_timeout ( scq - > scqfull_waitq ,
scq - > tail ! = scq - > next ,
scq - > lock ,
SCQFULL_TIMEOUT ) ;
2010-05-29 13:03:44 +04:00
}
if ( ! scq - > full ) {
tsr . word_1 = ns_tsr_mkword_1 ( NS_TSR_INTENABLE ) ;
if ( scq_is_vbr )
scdi = NS_TSR_SCDISVBR ;
else
scdi = ( vc - > cbr_scd - NS_FRSCD ) / NS_FRSCD_SIZE ;
scqi = scq - > next - scq - > base ;
tsr . word_2 = ns_tsr_mkword_2 ( scdi , scqi ) ;
tsr . word_3 = 0x00000000 ;
tsr . word_4 = 0x00000000 ;
* scq - > next = tsr ;
index = ( int ) scqi ;
scq - > skb [ index ] = NULL ;
XPRINTK
2010-05-29 13:04:25 +04:00
( " nicstar%d: TSR written: \n 0x%x \n 0x%x \n 0x%x \n 0x%x \n at 0x%p. \n " ,
2010-05-29 13:03:44 +04:00
card - > index , le32_to_cpu ( tsr . word_1 ) ,
le32_to_cpu ( tsr . word_2 ) , le32_to_cpu ( tsr . word_3 ) ,
2010-05-29 13:04:25 +04:00
le32_to_cpu ( tsr . word_4 ) , scq - > next ) ;
2010-05-29 13:03:44 +04:00
if ( scq - > next = = scq - > last )
scq - > next = scq - > base ;
else
scq - > next + + ;
vc - > tbd_count = 0 ;
scq - > tbd_count = 0 ;
} else
PRINTK ( " nicstar%d: Timeout pushing TSR. \n " ,
card - > index ) ;
}
2010-05-29 13:04:25 +04:00
data = scq_virt_to_bus ( scq , scq - > next ) ;
2010-05-29 13:03:44 +04:00
ns_write_sram ( card , scq - > scd , & data , 1 ) ;
spin_unlock_irqrestore ( & scq - > lock , flags ) ;
return 0 ;
2005-04-17 02:20:36 +04:00
}
2010-05-29 13:03:44 +04:00
static void process_tsq ( ns_dev * card )
2005-04-17 02:20:36 +04:00
{
2010-05-29 13:03:44 +04:00
u32 scdi ;
scq_info * scq ;
ns_tsi * previous = NULL , * one_ahead , * two_ahead ;
int serviced_entries ; /* flag indicating at least on entry was serviced */
serviced_entries = 0 ;
if ( card - > tsq . next = = card - > tsq . last )
one_ahead = card - > tsq . base ;
else
one_ahead = card - > tsq . next + 1 ;
if ( one_ahead = = card - > tsq . last )
two_ahead = card - > tsq . base ;
else
two_ahead = one_ahead + 1 ;
while ( ! ns_tsi_isempty ( card - > tsq . next ) | | ! ns_tsi_isempty ( one_ahead ) | |
! ns_tsi_isempty ( two_ahead ) )
/* At most two empty, as stated in the 77201 errata */
{
serviced_entries = 1 ;
/* Skip the one or two possible empty entries */
while ( ns_tsi_isempty ( card - > tsq . next ) ) {
if ( card - > tsq . next = = card - > tsq . last )
card - > tsq . next = card - > tsq . base ;
else
card - > tsq . next + + ;
}
if ( ! ns_tsi_tmrof ( card - > tsq . next ) ) {
scdi = ns_tsi_getscdindex ( card - > tsq . next ) ;
if ( scdi = = NS_TSI_SCDISVBR )
scq = card - > scq0 ;
else {
if ( card - > scd2vc [ scdi ] = = NULL ) {
printk
( " nicstar%d: could not find VC from SCD index. \n " ,
card - > index ) ;
ns_tsi_init ( card - > tsq . next ) ;
return ;
}
scq = card - > scd2vc [ scdi ] - > scq ;
}
drain_scq ( card , scq , ns_tsi_getscqpos ( card - > tsq . next ) ) ;
scq - > full = 0 ;
wake_up_interruptible ( & ( scq - > scqfull_waitq ) ) ;
}
ns_tsi_init ( card - > tsq . next ) ;
previous = card - > tsq . next ;
if ( card - > tsq . next = = card - > tsq . last )
card - > tsq . next = card - > tsq . base ;
else
card - > tsq . next + + ;
if ( card - > tsq . next = = card - > tsq . last )
one_ahead = card - > tsq . base ;
else
one_ahead = card - > tsq . next + 1 ;
if ( one_ahead = = card - > tsq . last )
two_ahead = card - > tsq . base ;
else
two_ahead = one_ahead + 1 ;
}
2010-05-29 13:04:25 +04:00
if ( serviced_entries )
writel ( PTR_DIFF ( previous , card - > tsq . base ) ,
2010-05-29 13:03:44 +04:00
card - > membase + TSQH ) ;
2005-04-17 02:20:36 +04:00
}
2010-05-29 13:03:44 +04:00
static void drain_scq ( ns_dev * card , scq_info * scq , int pos )
2005-04-17 02:20:36 +04:00
{
2010-05-29 13:03:44 +04:00
struct atm_vcc * vcc ;
struct sk_buff * skb ;
int i ;
unsigned long flags ;
2010-05-29 13:04:25 +04:00
XPRINTK ( " nicstar%d: drain_scq() called, scq at 0x%p, pos %d. \n " ,
card - > index , scq , pos ) ;
2010-05-29 13:03:44 +04:00
if ( pos > = scq - > num_entries ) {
printk ( " nicstar%d: Bad index on drain_scq(). \n " , card - > index ) ;
return ;
}
spin_lock_irqsave ( & scq - > lock , flags ) ;
i = ( int ) ( scq - > tail - scq - > base ) ;
if ( + + i = = scq - > num_entries )
i = 0 ;
while ( i ! = pos ) {
skb = scq - > skb [ i ] ;
2010-05-29 13:04:25 +04:00
XPRINTK ( " nicstar%d: freeing skb at 0x%p (index %d). \n " ,
card - > index , skb , i ) ;
2010-05-29 13:03:44 +04:00
if ( skb ! = NULL ) {
2015-01-16 16:57:21 +03:00
dma_unmap_single ( & card - > pcidev - > dev ,
2010-05-29 13:04:25 +04:00
NS_PRV_DMA ( skb ) ,
skb - > len ,
2015-01-16 16:57:21 +03:00
DMA_TO_DEVICE ) ;
2010-05-29 13:03:44 +04:00
vcc = ATM_SKB ( skb ) - > vcc ;
if ( vcc & & vcc - > pop ! = NULL ) {
vcc - > pop ( vcc , skb ) ;
} else {
dev_kfree_skb_irq ( skb ) ;
}
scq - > skb [ i ] = NULL ;
}
if ( + + i = = scq - > num_entries )
i = 0 ;
}
scq - > tail = scq - > base + pos ;
spin_unlock_irqrestore ( & scq - > lock , flags ) ;
2005-04-17 02:20:36 +04:00
}
2010-05-29 13:03:44 +04:00
static void process_rsq ( ns_dev * card )
{
ns_rsqe * previous ;
if ( ! ns_rsqe_valid ( card - > rsq . next ) )
return ;
do {
dequeue_rx ( card , card - > rsq . next ) ;
ns_rsqe_init ( card - > rsq . next ) ;
previous = card - > rsq . next ;
if ( card - > rsq . next = = card - > rsq . last )
card - > rsq . next = card - > rsq . base ;
else
card - > rsq . next + + ;
} while ( ns_rsqe_valid ( card - > rsq . next ) ) ;
2010-05-29 13:04:25 +04:00
writel ( PTR_DIFF ( previous , card - > rsq . base ) , card - > membase + RSQH ) ;
2010-05-29 13:03:44 +04:00
}
2005-04-17 02:20:36 +04:00
2010-05-29 13:03:44 +04:00
static void dequeue_rx ( ns_dev * card , ns_rsqe * rsqe )
2005-04-17 02:20:36 +04:00
{
2010-05-29 13:03:44 +04:00
u32 vpi , vci ;
vc_map * vc ;
struct sk_buff * iovb ;
struct iovec * iov ;
struct atm_vcc * vcc ;
struct sk_buff * skb ;
unsigned short aal5_len ;
int len ;
u32 stat ;
2010-05-29 13:04:25 +04:00
u32 id ;
2010-05-29 13:03:44 +04:00
stat = readl ( card - > membase + STAT ) ;
card - > sbfqc = ns_stat_sfbqc_get ( stat ) ;
card - > lbfqc = ns_stat_lfbqc_get ( stat ) ;
2010-05-29 13:04:25 +04:00
id = le32_to_cpu ( rsqe - > buffer_handle ) ;
2016-12-22 21:30:22 +03:00
skb = idr_remove ( & card - > idr , id ) ;
2010-05-29 13:04:25 +04:00
if ( ! skb ) {
RXPRINTK ( KERN_ERR
2016-12-22 21:30:22 +03:00
" nicstar%d: skb not found! \n " , card - > index ) ;
2010-05-29 13:04:25 +04:00
return ;
}
2015-01-16 16:57:21 +03:00
dma_sync_single_for_cpu ( & card - > pcidev - > dev ,
NS_PRV_DMA ( skb ) ,
( NS_PRV_BUFTYPE ( skb ) = = BUF_SM
? NS_SMSKBSIZE : NS_LGSKBSIZE ) ,
DMA_FROM_DEVICE ) ;
dma_unmap_single ( & card - > pcidev - > dev ,
2010-05-29 13:04:25 +04:00
NS_PRV_DMA ( skb ) ,
( NS_PRV_BUFTYPE ( skb ) = = BUF_SM
? NS_SMSKBSIZE : NS_LGSKBSIZE ) ,
2015-01-16 16:57:21 +03:00
DMA_FROM_DEVICE ) ;
2010-05-29 13:03:44 +04:00
vpi = ns_rsqe_vpi ( rsqe ) ;
vci = ns_rsqe_vci ( rsqe ) ;
if ( vpi > = 1UL < < card - > vpibits | | vci > = 1UL < < card - > vcibits ) {
printk ( " nicstar%d: SDU received for out-of-range vc %d.%d. \n " ,
card - > index , vpi , vci ) ;
recycle_rx_buf ( card , skb ) ;
return ;
}
vc = & ( card - > vcmap [ vpi < < card - > vcibits | vci ] ) ;
if ( ! vc - > rx ) {
RXPRINTK ( " nicstar%d: SDU received on non-rx vc %d.%d. \n " ,
card - > index , vpi , vci ) ;
recycle_rx_buf ( card , skb ) ;
return ;
}
vcc = vc - > rx_vcc ;
if ( vcc - > qos . aal = = ATM_AAL0 ) {
struct sk_buff * sb ;
unsigned char * cell ;
int i ;
cell = skb - > data ;
for ( i = ns_rsqe_cellcount ( rsqe ) ; i ; i - - ) {
2016-09-10 09:56:03 +03:00
sb = dev_alloc_skb ( NS_SMSKBSIZE ) ;
if ( ! sb ) {
2010-05-29 13:03:44 +04:00
printk
( " nicstar%d: Can't allocate buffers for aal0. \n " ,
card - > index ) ;
atomic_add ( i , & vcc - > stats - > rx_drop ) ;
break ;
}
if ( ! atm_charge ( vcc , sb - > truesize ) ) {
RXPRINTK
( " nicstar%d: atm_charge() dropped aal0 packets. \n " ,
card - > index ) ;
atomic_add ( i - 1 , & vcc - > stats - > rx_drop ) ; /* already increased by 1 */
dev_kfree_skb_any ( sb ) ;
break ;
}
/* Rebuild the header */
* ( ( u32 * ) sb - > data ) = le32_to_cpu ( rsqe - > word_1 ) < < 4 |
( ns_rsqe_clp ( rsqe ) ? 0x00000001 : 0x00000000 ) ;
if ( i = = 1 & & ns_rsqe_eopdu ( rsqe ) )
* ( ( u32 * ) sb - > data ) | = 0x00000002 ;
skb_put ( sb , NS_AAL0_HEADER ) ;
memcpy ( skb_tail_pointer ( sb ) , cell , ATM_CELL_PAYLOAD ) ;
skb_put ( sb , ATM_CELL_PAYLOAD ) ;
ATM_SKB ( sb ) - > vcc = vcc ;
__net_timestamp ( sb ) ;
vcc - > push ( vcc , sb ) ;
atomic_inc ( & vcc - > stats - > rx ) ;
cell + = ATM_CELL_PAYLOAD ;
}
recycle_rx_buf ( card , skb ) ;
return ;
}
/* To reach this point, the AAL layer can only be AAL5 */
if ( ( iovb = vc - > rx_iov ) = = NULL ) {
iovb = skb_dequeue ( & ( card - > iovpool . queue ) ) ;
if ( iovb = = NULL ) { /* No buffers in the queue */
iovb = alloc_skb ( NS_IOVBUFSIZE , GFP_ATOMIC ) ;
if ( iovb = = NULL ) {
printk ( " nicstar%d: Out of iovec buffers. \n " ,
card - > index ) ;
atomic_inc ( & vcc - > stats - > rx_drop ) ;
recycle_rx_buf ( card , skb ) ;
return ;
}
2010-05-29 13:04:25 +04:00
NS_PRV_BUFTYPE ( iovb ) = BUF_NONE ;
2010-05-29 13:03:44 +04:00
} else if ( - - card - > iovpool . count < card - > iovnr . min ) {
struct sk_buff * new_iovb ;
if ( ( new_iovb =
alloc_skb ( NS_IOVBUFSIZE , GFP_ATOMIC ) ) ! = NULL ) {
2010-05-29 13:04:25 +04:00
NS_PRV_BUFTYPE ( iovb ) = BUF_NONE ;
2010-05-29 13:03:44 +04:00
skb_queue_tail ( & card - > iovpool . queue , new_iovb ) ;
card - > iovpool . count + + ;
}
}
vc - > rx_iov = iovb ;
2010-05-29 13:04:25 +04:00
NS_PRV_IOVCNT ( iovb ) = 0 ;
2010-05-29 13:03:44 +04:00
iovb - > len = 0 ;
iovb - > data = iovb - > head ;
skb_reset_tail_pointer ( iovb ) ;
/* IMPORTANT: a pointer to the sk_buff containing the small or large
buffer is stored as iovec base , NOT a pointer to the
small or large buffer itself . */
2010-05-29 13:04:25 +04:00
} else if ( NS_PRV_IOVCNT ( iovb ) > = NS_MAX_IOVECS ) {
2010-05-29 13:03:44 +04:00
printk ( " nicstar%d: received too big AAL5 SDU. \n " , card - > index ) ;
atomic_inc ( & vcc - > stats - > rx_err ) ;
recycle_iovec_rx_bufs ( card , ( struct iovec * ) iovb - > data ,
NS_MAX_IOVECS ) ;
2010-05-29 13:04:25 +04:00
NS_PRV_IOVCNT ( iovb ) = 0 ;
2010-05-29 13:03:44 +04:00
iovb - > len = 0 ;
iovb - > data = iovb - > head ;
skb_reset_tail_pointer ( iovb ) ;
}
2010-05-29 13:04:25 +04:00
iov = & ( ( struct iovec * ) iovb - > data ) [ NS_PRV_IOVCNT ( iovb ) + + ] ;
2010-05-29 13:03:44 +04:00
iov - > iov_base = ( void * ) skb ;
iov - > iov_len = ns_rsqe_cellcount ( rsqe ) * 48 ;
iovb - > len + = iov - > iov_len ;
2010-05-29 13:04:25 +04:00
# ifdef EXTRA_DEBUG
if ( NS_PRV_IOVCNT ( iovb ) = = 1 ) {
if ( NS_PRV_BUFTYPE ( skb ) ! = BUF_SM ) {
2010-05-29 13:03:44 +04:00
printk
( " nicstar%d: Expected a small buffer, and this is not one. \n " ,
card - > index ) ;
which_list ( card , skb ) ;
atomic_inc ( & vcc - > stats - > rx_err ) ;
recycle_rx_buf ( card , skb ) ;
vc - > rx_iov = NULL ;
recycle_iov_buf ( card , iovb ) ;
return ;
}
2010-05-29 13:04:25 +04:00
} else { /* NS_PRV_IOVCNT(iovb) >= 2 */
2010-05-29 13:03:44 +04:00
2010-05-29 13:04:25 +04:00
if ( NS_PRV_BUFTYPE ( skb ) ! = BUF_LG ) {
2010-05-29 13:03:44 +04:00
printk
( " nicstar%d: Expected a large buffer, and this is not one. \n " ,
card - > index ) ;
which_list ( card , skb ) ;
atomic_inc ( & vcc - > stats - > rx_err ) ;
recycle_iovec_rx_bufs ( card , ( struct iovec * ) iovb - > data ,
2010-05-29 13:04:25 +04:00
NS_PRV_IOVCNT ( iovb ) ) ;
2010-05-29 13:03:44 +04:00
vc - > rx_iov = NULL ;
recycle_iov_buf ( card , iovb ) ;
return ;
}
}
2010-05-29 13:04:25 +04:00
# endif /* EXTRA_DEBUG */
2010-05-29 13:03:44 +04:00
if ( ns_rsqe_eopdu ( rsqe ) ) {
/* This works correctly regardless of the endianness of the host */
2010-05-29 13:04:25 +04:00
unsigned char * L1L2 = ( unsigned char * )
( skb - > data + iov - > iov_len - 6 ) ;
2010-05-29 13:03:44 +04:00
aal5_len = L1L2 [ 0 ] < < 8 | L1L2 [ 1 ] ;
len = ( aal5_len = = 0x0000 ) ? 0x10000 : aal5_len ;
if ( ns_rsqe_crcerr ( rsqe ) | |
len + 8 > iovb - > len | | len + ( 47 + 8 ) < iovb - > len ) {
printk ( " nicstar%d: AAL5 CRC error " , card - > index ) ;
if ( len + 8 > iovb - > len | | len + ( 47 + 8 ) < iovb - > len )
printk ( " - PDU size mismatch. \n " ) ;
else
printk ( " . \n " ) ;
atomic_inc ( & vcc - > stats - > rx_err ) ;
recycle_iovec_rx_bufs ( card , ( struct iovec * ) iovb - > data ,
2010-05-29 13:04:25 +04:00
NS_PRV_IOVCNT ( iovb ) ) ;
2010-05-29 13:03:44 +04:00
vc - > rx_iov = NULL ;
recycle_iov_buf ( card , iovb ) ;
return ;
}
/* By this point we (hopefully) have a complete SDU without errors. */
2010-05-29 13:04:25 +04:00
if ( NS_PRV_IOVCNT ( iovb ) = = 1 ) { /* Just a small buffer */
2010-05-29 13:03:44 +04:00
/* skb points to a small buffer */
if ( ! atm_charge ( vcc , skb - > truesize ) ) {
push_rxbufs ( card , skb ) ;
atomic_inc ( & vcc - > stats - > rx_drop ) ;
} else {
skb_put ( skb , len ) ;
dequeue_sm_buf ( card , skb ) ;
ATM_SKB ( skb ) - > vcc = vcc ;
__net_timestamp ( skb ) ;
vcc - > push ( vcc , skb ) ;
atomic_inc ( & vcc - > stats - > rx ) ;
}
2010-05-29 13:04:25 +04:00
} else if ( NS_PRV_IOVCNT ( iovb ) = = 2 ) { /* One small plus one large buffer */
2010-05-29 13:03:44 +04:00
struct sk_buff * sb ;
sb = ( struct sk_buff * ) ( iov - 1 ) - > iov_base ;
/* skb points to a large buffer */
if ( len < = NS_SMBUFSIZE ) {
if ( ! atm_charge ( vcc , sb - > truesize ) ) {
push_rxbufs ( card , sb ) ;
atomic_inc ( & vcc - > stats - > rx_drop ) ;
} else {
skb_put ( sb , len ) ;
dequeue_sm_buf ( card , sb ) ;
ATM_SKB ( sb ) - > vcc = vcc ;
__net_timestamp ( sb ) ;
vcc - > push ( vcc , sb ) ;
atomic_inc ( & vcc - > stats - > rx ) ;
}
push_rxbufs ( card , skb ) ;
} else { /* len > NS_SMBUFSIZE, the usual case */
if ( ! atm_charge ( vcc , skb - > truesize ) ) {
push_rxbufs ( card , skb ) ;
atomic_inc ( & vcc - > stats - > rx_drop ) ;
} else {
dequeue_lg_buf ( card , skb ) ;
skb_push ( skb , NS_SMBUFSIZE ) ;
skb_copy_from_linear_data ( sb , skb - > data ,
NS_SMBUFSIZE ) ;
skb_put ( skb , len - NS_SMBUFSIZE ) ;
ATM_SKB ( skb ) - > vcc = vcc ;
__net_timestamp ( skb ) ;
vcc - > push ( vcc , skb ) ;
atomic_inc ( & vcc - > stats - > rx ) ;
}
push_rxbufs ( card , sb ) ;
}
} else { /* Must push a huge buffer */
struct sk_buff * hb , * sb , * lb ;
int remaining , tocopy ;
int j ;
hb = skb_dequeue ( & ( card - > hbpool . queue ) ) ;
if ( hb = = NULL ) { /* No buffers in the queue */
hb = dev_alloc_skb ( NS_HBUFSIZE ) ;
if ( hb = = NULL ) {
printk
( " nicstar%d: Out of huge buffers. \n " ,
card - > index ) ;
atomic_inc ( & vcc - > stats - > rx_drop ) ;
recycle_iovec_rx_bufs ( card ,
( struct iovec * )
iovb - > data ,
2010-05-29 13:04:25 +04:00
NS_PRV_IOVCNT ( iovb ) ) ;
2010-05-29 13:03:44 +04:00
vc - > rx_iov = NULL ;
recycle_iov_buf ( card , iovb ) ;
return ;
} else if ( card - > hbpool . count < card - > hbnr . min ) {
struct sk_buff * new_hb ;
if ( ( new_hb =
dev_alloc_skb ( NS_HBUFSIZE ) ) ! =
NULL ) {
skb_queue_tail ( & card - > hbpool .
queue , new_hb ) ;
card - > hbpool . count + + ;
}
}
2010-05-29 13:04:25 +04:00
NS_PRV_BUFTYPE ( hb ) = BUF_NONE ;
2010-05-29 13:03:44 +04:00
} else if ( - - card - > hbpool . count < card - > hbnr . min ) {
struct sk_buff * new_hb ;
if ( ( new_hb =
dev_alloc_skb ( NS_HBUFSIZE ) ) ! = NULL ) {
2010-05-29 13:04:25 +04:00
NS_PRV_BUFTYPE ( new_hb ) = BUF_NONE ;
2010-05-29 13:03:44 +04:00
skb_queue_tail ( & card - > hbpool . queue ,
new_hb ) ;
card - > hbpool . count + + ;
}
if ( card - > hbpool . count < card - > hbnr . min ) {
if ( ( new_hb =
dev_alloc_skb ( NS_HBUFSIZE ) ) ! =
NULL ) {
2010-05-29 13:04:25 +04:00
NS_PRV_BUFTYPE ( new_hb ) =
2010-05-29 13:03:44 +04:00
BUF_NONE ;
skb_queue_tail ( & card - > hbpool .
queue , new_hb ) ;
card - > hbpool . count + + ;
}
}
}
iov = ( struct iovec * ) iovb - > data ;
if ( ! atm_charge ( vcc , hb - > truesize ) ) {
recycle_iovec_rx_bufs ( card , iov ,
2010-05-29 13:04:25 +04:00
NS_PRV_IOVCNT ( iovb ) ) ;
2010-05-29 13:03:44 +04:00
if ( card - > hbpool . count < card - > hbnr . max ) {
skb_queue_tail ( & card - > hbpool . queue , hb ) ;
card - > hbpool . count + + ;
} else
dev_kfree_skb_any ( hb ) ;
atomic_inc ( & vcc - > stats - > rx_drop ) ;
} else {
/* Copy the small buffer to the huge buffer */
sb = ( struct sk_buff * ) iov - > iov_base ;
skb_copy_from_linear_data ( sb , hb - > data ,
iov - > iov_len ) ;
skb_put ( hb , iov - > iov_len ) ;
remaining = len - iov - > iov_len ;
iov + + ;
/* Free the small buffer */
push_rxbufs ( card , sb ) ;
/* Copy all large buffers to the huge buffer and free them */
2010-05-29 13:04:25 +04:00
for ( j = 1 ; j < NS_PRV_IOVCNT ( iovb ) ; j + + ) {
2010-05-29 13:03:44 +04:00
lb = ( struct sk_buff * ) iov - > iov_base ;
tocopy =
min_t ( int , remaining , iov - > iov_len ) ;
skb_copy_from_linear_data ( lb ,
skb_tail_pointer
( hb ) , tocopy ) ;
skb_put ( hb , tocopy ) ;
iov + + ;
remaining - = tocopy ;
push_rxbufs ( card , lb ) ;
}
2005-04-17 02:20:36 +04:00
# ifdef EXTRA_DEBUG
2010-05-29 13:03:44 +04:00
if ( remaining ! = 0 | | hb - > len ! = len )
printk
( " nicstar%d: Huge buffer len mismatch. \n " ,
card - > index ) ;
2005-04-17 02:20:36 +04:00
# endif /* EXTRA_DEBUG */
2010-05-29 13:03:44 +04:00
ATM_SKB ( hb ) - > vcc = vcc ;
__net_timestamp ( hb ) ;
vcc - > push ( vcc , hb ) ;
atomic_inc ( & vcc - > stats - > rx ) ;
}
}
2005-04-17 02:20:36 +04:00
2010-05-29 13:03:44 +04:00
vc - > rx_iov = NULL ;
recycle_iov_buf ( card , iovb ) ;
}
2005-04-17 02:20:36 +04:00
}
2010-05-29 13:03:44 +04:00
static void recycle_rx_buf ( ns_dev * card , struct sk_buff * skb )
2005-04-17 02:20:36 +04:00
{
2010-05-29 13:04:25 +04:00
if ( unlikely ( NS_PRV_BUFTYPE ( skb ) = = BUF_NONE ) ) {
2010-05-29 13:03:44 +04:00
printk ( " nicstar%d: What kind of rx buffer is this? \n " ,
card - > index ) ;
2005-08-10 06:25:21 +04:00
dev_kfree_skb_any ( skb ) ;
} else
push_rxbufs ( card , skb ) ;
}
2005-04-17 02:20:36 +04:00
2010-05-29 13:03:44 +04:00
static void recycle_iovec_rx_bufs ( ns_dev * card , struct iovec * iov , int count )
2005-04-17 02:20:36 +04:00
{
2005-08-10 06:25:21 +04:00
while ( count - - > 0 )
2010-05-29 13:03:44 +04:00
recycle_rx_buf ( card , ( struct sk_buff * ) ( iov + + ) - > iov_base ) ;
2005-04-17 02:20:36 +04:00
}
2010-05-29 13:03:44 +04:00
static void recycle_iov_buf ( ns_dev * card , struct sk_buff * iovb )
2005-04-17 02:20:36 +04:00
{
2010-05-29 13:03:44 +04:00
if ( card - > iovpool . count < card - > iovnr . max ) {
skb_queue_tail ( & card - > iovpool . queue , iovb ) ;
card - > iovpool . count + + ;
} else
dev_kfree_skb_any ( iovb ) ;
2005-04-17 02:20:36 +04:00
}
2010-05-29 13:03:44 +04:00
static void dequeue_sm_buf ( ns_dev * card , struct sk_buff * sb )
2005-04-17 02:20:36 +04:00
{
2010-05-29 13:03:44 +04:00
skb_unlink ( sb , & card - > sbpool . queue ) ;
if ( card - > sbfqc < card - > sbnr . init ) {
struct sk_buff * new_sb ;
if ( ( new_sb = dev_alloc_skb ( NS_SMSKBSIZE ) ) ! = NULL ) {
2010-05-29 13:04:25 +04:00
NS_PRV_BUFTYPE ( new_sb ) = BUF_SM ;
2010-05-29 13:03:44 +04:00
skb_queue_tail ( & card - > sbpool . queue , new_sb ) ;
skb_reserve ( new_sb , NS_AAL0_HEADER ) ;
push_rxbufs ( card , new_sb ) ;
}
}
if ( card - > sbfqc < card - > sbnr . init )
{
struct sk_buff * new_sb ;
if ( ( new_sb = dev_alloc_skb ( NS_SMSKBSIZE ) ) ! = NULL ) {
2010-05-29 13:04:25 +04:00
NS_PRV_BUFTYPE ( new_sb ) = BUF_SM ;
2010-05-29 13:03:44 +04:00
skb_queue_tail ( & card - > sbpool . queue , new_sb ) ;
skb_reserve ( new_sb , NS_AAL0_HEADER ) ;
push_rxbufs ( card , new_sb ) ;
}
}
2005-04-17 02:20:36 +04:00
}
2010-05-29 13:03:44 +04:00
static void dequeue_lg_buf ( ns_dev * card , struct sk_buff * lb )
2005-04-17 02:20:36 +04:00
{
2010-05-29 13:03:44 +04:00
skb_unlink ( lb , & card - > lbpool . queue ) ;
if ( card - > lbfqc < card - > lbnr . init ) {
struct sk_buff * new_lb ;
if ( ( new_lb = dev_alloc_skb ( NS_LGSKBSIZE ) ) ! = NULL ) {
2010-05-29 13:04:25 +04:00
NS_PRV_BUFTYPE ( new_lb ) = BUF_LG ;
2010-05-29 13:03:44 +04:00
skb_queue_tail ( & card - > lbpool . queue , new_lb ) ;
skb_reserve ( new_lb , NS_SMBUFSIZE ) ;
push_rxbufs ( card , new_lb ) ;
}
}
if ( card - > lbfqc < card - > lbnr . init )
{
struct sk_buff * new_lb ;
if ( ( new_lb = dev_alloc_skb ( NS_LGSKBSIZE ) ) ! = NULL ) {
2010-05-29 13:04:25 +04:00
NS_PRV_BUFTYPE ( new_lb ) = BUF_LG ;
2010-05-29 13:03:44 +04:00
skb_queue_tail ( & card - > lbpool . queue , new_lb ) ;
skb_reserve ( new_lb , NS_SMBUFSIZE ) ;
push_rxbufs ( card , new_lb ) ;
}
}
2005-04-17 02:20:36 +04:00
}
2010-05-29 13:03:44 +04:00
static int ns_proc_read ( struct atm_dev * dev , loff_t * pos , char * page )
2005-04-17 02:20:36 +04:00
{
2010-05-29 13:03:44 +04:00
u32 stat ;
ns_dev * card ;
int left ;
left = ( int ) * pos ;
card = ( ns_dev * ) dev - > dev_data ;
stat = readl ( card - > membase + STAT ) ;
if ( ! left - - )
return sprintf ( page , " Pool count min init max \n " ) ;
if ( ! left - - )
return sprintf ( page , " Small %5d %5d %5d %5d \n " ,
ns_stat_sfbqc_get ( stat ) , card - > sbnr . min ,
card - > sbnr . init , card - > sbnr . max ) ;
if ( ! left - - )
return sprintf ( page , " Large %5d %5d %5d %5d \n " ,
ns_stat_lfbqc_get ( stat ) , card - > lbnr . min ,
card - > lbnr . init , card - > lbnr . max ) ;
if ( ! left - - )
return sprintf ( page , " Huge %5d %5d %5d %5d \n " ,
card - > hbpool . count , card - > hbnr . min ,
card - > hbnr . init , card - > hbnr . max ) ;
if ( ! left - - )
return sprintf ( page , " Iovec %5d %5d %5d %5d \n " ,
card - > iovpool . count , card - > iovnr . min ,
card - > iovnr . init , card - > iovnr . max ) ;
if ( ! left - - ) {
int retval ;
retval =
sprintf ( page , " Interrupt counter: %u \n " , card - > intcnt ) ;
card - > intcnt = 0 ;
return retval ;
}
2005-04-17 02:20:36 +04:00
#if 0
2010-05-29 13:03:44 +04:00
/* Dump 25.6 Mbps PHY registers */
/* Now there's a 25.6 Mbps PHY driver this code isn't needed. I left it
here just in case it ' s needed for debugging . */
if ( card - > max_pcr = = ATM_25_PCR & & ! left - - ) {
u32 phy_regs [ 4 ] ;
u32 i ;
for ( i = 0 ; i < 4 ; i + + ) {
while ( CMD_BUSY ( card ) ) ;
writel ( NS_CMD_READ_UTILITY | 0x00000200 | i ,
card - > membase + CMD ) ;
while ( CMD_BUSY ( card ) ) ;
phy_regs [ i ] = readl ( card - > membase + DR0 ) & 0x000000FF ;
}
return sprintf ( page , " PHY regs: 0x%02X 0x%02X 0x%02X 0x%02X \n " ,
phy_regs [ 0 ] , phy_regs [ 1 ] , phy_regs [ 2 ] ,
phy_regs [ 3 ] ) ;
}
2005-04-17 02:20:36 +04:00
# endif /* 0 - Dump 25.6 Mbps PHY registers */
#if 0
2010-05-29 13:03:44 +04:00
/* Dump TST */
if ( left - - < NS_TST_NUM_ENTRIES ) {
if ( card - > tste2vc [ left + 1 ] = = NULL )
return sprintf ( page , " %5d - VBR/UBR \n " , left + 1 ) ;
else
return sprintf ( page , " %5d - %d %d \n " , left + 1 ,
card - > tste2vc [ left + 1 ] - > tx_vcc - > vpi ,
card - > tste2vc [ left + 1 ] - > tx_vcc - > vci ) ;
}
2005-04-17 02:20:36 +04:00
# endif /* 0 */
2010-05-29 13:03:44 +04:00
return 0 ;
2005-04-17 02:20:36 +04:00
}
2010-05-29 13:03:44 +04:00
static int ns_ioctl ( struct atm_dev * dev , unsigned int cmd , void __user * arg )
2005-04-17 02:20:36 +04:00
{
2010-05-29 13:03:44 +04:00
ns_dev * card ;
pool_levels pl ;
long btype ;
unsigned long flags ;
card = dev - > dev_data ;
switch ( cmd ) {
case NS_GETPSTAT :
if ( get_user
( pl . buftype , & ( ( pool_levels __user * ) arg ) - > buftype ) )
return - EFAULT ;
switch ( pl . buftype ) {
case NS_BUFTYPE_SMALL :
pl . count =
ns_stat_sfbqc_get ( readl ( card - > membase + STAT ) ) ;
pl . level . min = card - > sbnr . min ;
pl . level . init = card - > sbnr . init ;
pl . level . max = card - > sbnr . max ;
break ;
case NS_BUFTYPE_LARGE :
pl . count =
ns_stat_lfbqc_get ( readl ( card - > membase + STAT ) ) ;
pl . level . min = card - > lbnr . min ;
pl . level . init = card - > lbnr . init ;
pl . level . max = card - > lbnr . max ;
break ;
case NS_BUFTYPE_HUGE :
pl . count = card - > hbpool . count ;
pl . level . min = card - > hbnr . min ;
pl . level . init = card - > hbnr . init ;
pl . level . max = card - > hbnr . max ;
break ;
case NS_BUFTYPE_IOVEC :
pl . count = card - > iovpool . count ;
pl . level . min = card - > iovnr . min ;
pl . level . init = card - > iovnr . init ;
pl . level . max = card - > iovnr . max ;
break ;
default :
return - ENOIOCTLCMD ;
}
if ( ! copy_to_user ( ( pool_levels __user * ) arg , & pl , sizeof ( pl ) ) )
return ( sizeof ( pl ) ) ;
else
return - EFAULT ;
case NS_SETBUFLEV :
if ( ! capable ( CAP_NET_ADMIN ) )
return - EPERM ;
if ( copy_from_user ( & pl , ( pool_levels __user * ) arg , sizeof ( pl ) ) )
return - EFAULT ;
if ( pl . level . min > = pl . level . init
| | pl . level . init > = pl . level . max )
return - EINVAL ;
if ( pl . level . min = = 0 )
return - EINVAL ;
switch ( pl . buftype ) {
case NS_BUFTYPE_SMALL :
if ( pl . level . max > TOP_SB )
return - EINVAL ;
card - > sbnr . min = pl . level . min ;
card - > sbnr . init = pl . level . init ;
card - > sbnr . max = pl . level . max ;
break ;
case NS_BUFTYPE_LARGE :
if ( pl . level . max > TOP_LB )
return - EINVAL ;
card - > lbnr . min = pl . level . min ;
card - > lbnr . init = pl . level . init ;
card - > lbnr . max = pl . level . max ;
break ;
case NS_BUFTYPE_HUGE :
if ( pl . level . max > TOP_HB )
return - EINVAL ;
card - > hbnr . min = pl . level . min ;
card - > hbnr . init = pl . level . init ;
card - > hbnr . max = pl . level . max ;
break ;
case NS_BUFTYPE_IOVEC :
if ( pl . level . max > TOP_IOVB )
return - EINVAL ;
card - > iovnr . min = pl . level . min ;
card - > iovnr . init = pl . level . init ;
card - > iovnr . max = pl . level . max ;
break ;
default :
return - EINVAL ;
}
return 0 ;
case NS_ADJBUFLEV :
if ( ! capable ( CAP_NET_ADMIN ) )
return - EPERM ;
btype = ( long ) arg ; /* a long is the same size as a pointer or bigger */
switch ( btype ) {
case NS_BUFTYPE_SMALL :
while ( card - > sbfqc < card - > sbnr . init ) {
struct sk_buff * sb ;
sb = __dev_alloc_skb ( NS_SMSKBSIZE , GFP_KERNEL ) ;
if ( sb = = NULL )
return - ENOMEM ;
2010-05-29 13:04:25 +04:00
NS_PRV_BUFTYPE ( sb ) = BUF_SM ;
2010-05-29 13:03:44 +04:00
skb_queue_tail ( & card - > sbpool . queue , sb ) ;
skb_reserve ( sb , NS_AAL0_HEADER ) ;
push_rxbufs ( card , sb ) ;
}
break ;
case NS_BUFTYPE_LARGE :
while ( card - > lbfqc < card - > lbnr . init ) {
struct sk_buff * lb ;
lb = __dev_alloc_skb ( NS_LGSKBSIZE , GFP_KERNEL ) ;
if ( lb = = NULL )
return - ENOMEM ;
2010-05-29 13:04:25 +04:00
NS_PRV_BUFTYPE ( lb ) = BUF_LG ;
2010-05-29 13:03:44 +04:00
skb_queue_tail ( & card - > lbpool . queue , lb ) ;
skb_reserve ( lb , NS_SMBUFSIZE ) ;
push_rxbufs ( card , lb ) ;
}
break ;
case NS_BUFTYPE_HUGE :
while ( card - > hbpool . count > card - > hbnr . init ) {
struct sk_buff * hb ;
spin_lock_irqsave ( & card - > int_lock , flags ) ;
hb = skb_dequeue ( & card - > hbpool . queue ) ;
card - > hbpool . count - - ;
spin_unlock_irqrestore ( & card - > int_lock , flags ) ;
if ( hb = = NULL )
printk
( " nicstar%d: huge buffer count inconsistent. \n " ,
card - > index ) ;
else
dev_kfree_skb_any ( hb ) ;
}
while ( card - > hbpool . count < card - > hbnr . init ) {
struct sk_buff * hb ;
hb = __dev_alloc_skb ( NS_HBUFSIZE , GFP_KERNEL ) ;
if ( hb = = NULL )
return - ENOMEM ;
2010-05-29 13:04:25 +04:00
NS_PRV_BUFTYPE ( hb ) = BUF_NONE ;
2010-05-29 13:03:44 +04:00
spin_lock_irqsave ( & card - > int_lock , flags ) ;
skb_queue_tail ( & card - > hbpool . queue , hb ) ;
card - > hbpool . count + + ;
spin_unlock_irqrestore ( & card - > int_lock , flags ) ;
}
break ;
case NS_BUFTYPE_IOVEC :
while ( card - > iovpool . count > card - > iovnr . init ) {
struct sk_buff * iovb ;
spin_lock_irqsave ( & card - > int_lock , flags ) ;
iovb = skb_dequeue ( & card - > iovpool . queue ) ;
card - > iovpool . count - - ;
spin_unlock_irqrestore ( & card - > int_lock , flags ) ;
if ( iovb = = NULL )
printk
( " nicstar%d: iovec buffer count inconsistent. \n " ,
card - > index ) ;
else
dev_kfree_skb_any ( iovb ) ;
}
while ( card - > iovpool . count < card - > iovnr . init ) {
struct sk_buff * iovb ;
iovb = alloc_skb ( NS_IOVBUFSIZE , GFP_KERNEL ) ;
if ( iovb = = NULL )
return - ENOMEM ;
2010-05-29 13:04:25 +04:00
NS_PRV_BUFTYPE ( iovb ) = BUF_NONE ;
2010-05-29 13:03:44 +04:00
spin_lock_irqsave ( & card - > int_lock , flags ) ;
skb_queue_tail ( & card - > iovpool . queue , iovb ) ;
card - > iovpool . count + + ;
spin_unlock_irqrestore ( & card - > int_lock , flags ) ;
}
break ;
default :
return - EINVAL ;
}
return 0 ;
default :
if ( dev - > phy & & dev - > phy - > ioctl ) {
return dev - > phy - > ioctl ( dev , cmd , arg ) ;
} else {
printk ( " nicstar%d: %s == NULL \n " , card - > index ,
dev - > phy ? " dev->phy->ioctl " : " dev->phy " ) ;
return - ENOIOCTLCMD ;
}
}
2005-04-17 02:20:36 +04:00
}
2010-05-29 13:04:25 +04:00
# ifdef EXTRA_DEBUG
2010-05-29 13:03:44 +04:00
static void which_list ( ns_dev * card , struct sk_buff * skb )
2005-04-17 02:20:36 +04:00
{
2010-05-29 13:04:25 +04:00
printk ( " skb buf_type: 0x%08x \n " , NS_PRV_BUFTYPE ( skb ) ) ;
2005-04-17 02:20:36 +04:00
}
2010-05-29 13:04:25 +04:00
# endif /* EXTRA_DEBUG */
2005-04-17 02:20:36 +04:00
treewide: setup_timer() -> timer_setup()
This converts all remaining cases of the old setup_timer() API into using
timer_setup(), where the callback argument is the structure already
holding the struct timer_list. These should have no behavioral changes,
since they just change which pointer is passed into the callback with
the same available pointers after conversion. It handles the following
examples, in addition to some other variations.
Casting from unsigned long:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
setup_timer(&ptr->my_timer, my_callback, ptr);
and forced object casts:
void my_callback(struct something *ptr)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, (unsigned long)ptr);
become:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
Direct function assignments:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
ptr->my_timer.function = my_callback;
have a temporary cast added, along with converting the args:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
ptr->my_timer.function = (TIMER_FUNC_TYPE)my_callback;
And finally, callbacks without a data assignment:
void my_callback(unsigned long data)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, 0);
have their argument renamed to verify they're unused during conversion:
void my_callback(struct timer_list *unused)
{
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
The conversion is done with the following Coccinelle script:
spatch --very-quiet --all-includes --include-headers \
-I ./arch/x86/include -I ./arch/x86/include/generated \
-I ./include -I ./arch/x86/include/uapi \
-I ./arch/x86/include/generated/uapi -I ./include/uapi \
-I ./include/generated/uapi --include ./include/linux/kconfig.h \
--dir . \
--cocci-file ~/src/data/timer_setup.cocci
@fix_address_of@
expression e;
@@
setup_timer(
-&(e)
+&e
, ...)
// Update any raw setup_timer() usages that have a NULL callback, but
// would otherwise match change_timer_function_usage, since the latter
// will update all function assignments done in the face of a NULL
// function initialization in setup_timer().
@change_timer_function_usage_NULL@
expression _E;
identifier _timer;
type _cast_data;
@@
(
-setup_timer(&_E->_timer, NULL, _E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E->_timer, NULL, (_cast_data)_E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, &_E);
+timer_setup(&_E._timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, (_cast_data)&_E);
+timer_setup(&_E._timer, NULL, 0);
)
@change_timer_function_usage@
expression _E;
identifier _timer;
struct timer_list _stl;
identifier _callback;
type _cast_func, _cast_data;
@@
(
-setup_timer(&_E->_timer, _callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
_E->_timer@_stl.function = _callback;
|
_E->_timer@_stl.function = &_callback;
|
_E->_timer@_stl.function = (_cast_func)_callback;
|
_E->_timer@_stl.function = (_cast_func)&_callback;
|
_E._timer@_stl.function = _callback;
|
_E._timer@_stl.function = &_callback;
|
_E._timer@_stl.function = (_cast_func)_callback;
|
_E._timer@_stl.function = (_cast_func)&_callback;
)
// callback(unsigned long arg)
@change_callback_handle_cast
depends on change_timer_function_usage@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
identifier _handle;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
(
... when != _origarg
_handletype *_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
)
}
// callback(unsigned long arg) without existing variable
@change_callback_handle_cast_no_arg
depends on change_timer_function_usage &&
!change_callback_handle_cast@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
+ _handletype *_origarg = from_timer(_origarg, t, _timer);
+
... when != _origarg
- (_handletype *)_origarg
+ _origarg
... when != _origarg
}
// Avoid already converted callbacks.
@match_callback_converted
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier t;
@@
void _callback(struct timer_list *t)
{ ... }
// callback(struct something *handle)
@change_callback_handle_arg
depends on change_timer_function_usage &&
!match_callback_converted &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
@@
void _callback(
-_handletype *_handle
+struct timer_list *t
)
{
+ _handletype *_handle = from_timer(_handle, t, _timer);
...
}
// If change_callback_handle_arg ran on an empty function, remove
// the added handler.
@unchange_callback_handle_arg
depends on change_timer_function_usage &&
change_callback_handle_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
identifier t;
@@
void _callback(struct timer_list *t)
{
- _handletype *_handle = from_timer(_handle, t, _timer);
}
// We only want to refactor the setup_timer() data argument if we've found
// the matching callback. This undoes changes in change_timer_function_usage.
@unchange_timer_function_usage
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg &&
!change_callback_handle_arg@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type change_timer_function_usage._cast_data;
@@
(
-timer_setup(&_E->_timer, _callback, 0);
+setup_timer(&_E->_timer, _callback, (_cast_data)_E);
|
-timer_setup(&_E._timer, _callback, 0);
+setup_timer(&_E._timer, _callback, (_cast_data)&_E);
)
// If we fixed a callback from a .function assignment, fix the
// assignment cast now.
@change_timer_function_assignment
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_func;
typedef TIMER_FUNC_TYPE;
@@
(
_E->_timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-&_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
)
// Sometimes timer functions are called directly. Replace matched args.
@change_timer_function_calls
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression _E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_data;
@@
_callback(
(
-(_cast_data)_E
+&_E->_timer
|
-(_cast_data)&_E
+&_E._timer
|
-_E
+&_E->_timer
)
)
// If a timer has been configured without a data argument, it can be
// converted without regard to the callback argument, since it is unused.
@match_timer_function_unused_data@
expression _E;
identifier _timer;
identifier _callback;
@@
(
-setup_timer(&_E->_timer, _callback, 0);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0L);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0UL);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0L);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0UL);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0L);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0UL);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0L);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0UL);
+timer_setup(_timer, _callback, 0);
)
@change_callback_unused_data
depends on match_timer_function_unused_data@
identifier match_timer_function_unused_data._callback;
type _origtype;
identifier _origarg;
@@
void _callback(
-_origtype _origarg
+struct timer_list *unused
)
{
... when != _origarg
}
Signed-off-by: Kees Cook <keescook@chromium.org>
2017-10-17 00:43:17 +03:00
static void ns_poll ( struct timer_list * unused )
2005-04-17 02:20:36 +04:00
{
2010-05-29 13:03:44 +04:00
int i ;
ns_dev * card ;
unsigned long flags ;
u32 stat_r , stat_w ;
PRINTK ( " nicstar: Entering ns_poll(). \n " ) ;
for ( i = 0 ; i < num_cards ; i + + ) {
card = cards [ i ] ;
2018-10-04 10:46:57 +03:00
if ( ! spin_trylock_irqsave ( & card - > int_lock , flags ) ) {
2010-05-29 13:03:44 +04:00
/* Probably it isn't worth spinning */
continue ;
}
stat_w = 0 ;
stat_r = readl ( card - > membase + STAT ) ;
if ( stat_r & NS_STAT_TSIF )
stat_w | = NS_STAT_TSIF ;
if ( stat_r & NS_STAT_EOPDU )
stat_w | = NS_STAT_EOPDU ;
process_tsq ( card ) ;
process_rsq ( card ) ;
writel ( stat_w , card - > membase + STAT ) ;
spin_unlock_irqrestore ( & card - > int_lock , flags ) ;
}
mod_timer ( & ns_timer , jiffies + NS_POLL_PERIOD ) ;
PRINTK ( " nicstar: Leaving ns_poll(). \n " ) ;
2005-04-17 02:20:36 +04:00
}
static void ns_phy_put ( struct atm_dev * dev , unsigned char value ,
2010-05-29 13:03:44 +04:00
unsigned long addr )
2005-04-17 02:20:36 +04:00
{
2010-05-29 13:03:44 +04:00
ns_dev * card ;
unsigned long flags ;
card = dev - > dev_data ;
spin_lock_irqsave ( & card - > res_lock , flags ) ;
while ( CMD_BUSY ( card ) ) ;
2010-05-29 13:04:25 +04:00
writel ( ( u32 ) value , card - > membase + DR0 ) ;
2010-05-29 13:03:44 +04:00
writel ( NS_CMD_WRITE_UTILITY | 0x00000200 | ( addr & 0x000000FF ) ,
card - > membase + CMD ) ;
spin_unlock_irqrestore ( & card - > res_lock , flags ) ;
2005-04-17 02:20:36 +04:00
}
static unsigned char ns_phy_get ( struct atm_dev * dev , unsigned long addr )
{
2010-05-29 13:03:44 +04:00
ns_dev * card ;
unsigned long flags ;
2010-05-29 13:04:25 +04:00
u32 data ;
2010-05-29 13:03:44 +04:00
card = dev - > dev_data ;
spin_lock_irqsave ( & card - > res_lock , flags ) ;
while ( CMD_BUSY ( card ) ) ;
writel ( NS_CMD_READ_UTILITY | 0x00000200 | ( addr & 0x000000FF ) ,
card - > membase + CMD ) ;
while ( CMD_BUSY ( card ) ) ;
data = readl ( card - > membase + DR0 ) & 0x000000FF ;
spin_unlock_irqrestore ( & card - > res_lock , flags ) ;
return ( unsigned char ) data ;
2005-04-17 02:20:36 +04:00
}
module_init ( nicstar_init ) ;
module_exit ( nicstar_cleanup ) ;