2015-10-20 03:40:36 +08:00
|
|
|
/* bnx2fc_tgt.c: QLogic Linux FCoE offload driver.
|
2011-02-05 04:10:34 +08:00
|
|
|
* Handles operations such as session offload/upload etc, and manages
|
|
|
|
* session resources such as connection id and qp resources.
|
|
|
|
*
|
2015-10-20 03:40:35 +08:00
|
|
|
* Copyright (c) 2008-2013 Broadcom Corporation
|
2017-06-26 23:59:34 +08:00
|
|
|
* Copyright (c) 2014-2016 QLogic Corporation
|
|
|
|
* Copyright (c) 2016-2017 Cavium Inc.
|
2011-02-05 04:10:34 +08:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* Written by: Bhanu Prakash Gollapudi (bprakash@broadcom.com)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "bnx2fc.h"
|
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 05:43:17 +08:00
|
|
|
static void bnx2fc_upld_timer(struct timer_list *t);
|
|
|
|
static void bnx2fc_ofld_timer(struct timer_list *t);
|
2011-02-05 04:10:34 +08:00
|
|
|
static int bnx2fc_init_tgt(struct bnx2fc_rport *tgt,
|
|
|
|
struct fcoe_port *port,
|
|
|
|
struct fc_rport_priv *rdata);
|
|
|
|
static u32 bnx2fc_alloc_conn_id(struct bnx2fc_hba *hba,
|
|
|
|
struct bnx2fc_rport *tgt);
|
|
|
|
static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
|
|
|
|
struct bnx2fc_rport *tgt);
|
|
|
|
static void bnx2fc_free_session_resc(struct bnx2fc_hba *hba,
|
|
|
|
struct bnx2fc_rport *tgt);
|
|
|
|
static void bnx2fc_free_conn_id(struct bnx2fc_hba *hba, u32 conn_id);
|
|
|
|
|
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 05:43:17 +08:00
|
|
|
static void bnx2fc_upld_timer(struct timer_list *t)
|
2011-02-05 04:10:34 +08: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 05:43:17 +08:00
|
|
|
struct bnx2fc_rport *tgt = from_timer(tgt, t, upld_timer);
|
2011-02-05 04:10:34 +08:00
|
|
|
|
|
|
|
BNX2FC_TGT_DBG(tgt, "upld_timer - Upload compl not received!!\n");
|
|
|
|
/* fake upload completion */
|
|
|
|
clear_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags);
|
2012-12-22 11:40:31 +08:00
|
|
|
clear_bit(BNX2FC_FLAG_ENABLED, &tgt->flags);
|
2011-02-05 04:10:34 +08:00
|
|
|
set_bit(BNX2FC_FLAG_UPLD_REQ_COMPL, &tgt->flags);
|
|
|
|
wake_up_interruptible(&tgt->upld_wait);
|
|
|
|
}
|
|
|
|
|
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 05:43:17 +08:00
|
|
|
static void bnx2fc_ofld_timer(struct timer_list *t)
|
2011-02-05 04:10:34 +08: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 05:43:17 +08:00
|
|
|
struct bnx2fc_rport *tgt = from_timer(tgt, t, ofld_timer);
|
2011-02-05 04:10:34 +08:00
|
|
|
|
|
|
|
BNX2FC_TGT_DBG(tgt, "entered bnx2fc_ofld_timer\n");
|
|
|
|
/* NOTE: This function should never be called, as
|
|
|
|
* offload should never timeout
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* If the timer has expired, this session is dead
|
|
|
|
* Clear offloaded flag and logout of this device.
|
|
|
|
* Since OFFLOADED flag is cleared, this case
|
|
|
|
* will be considered as offload error and the
|
|
|
|
* port will be logged off, and conn_id, session
|
|
|
|
* resources are freed up in bnx2fc_offload_session
|
|
|
|
*/
|
|
|
|
clear_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags);
|
2012-12-22 11:40:31 +08:00
|
|
|
clear_bit(BNX2FC_FLAG_ENABLED, &tgt->flags);
|
2011-02-05 04:10:34 +08:00
|
|
|
set_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags);
|
|
|
|
wake_up_interruptible(&tgt->ofld_wait);
|
|
|
|
}
|
|
|
|
|
2012-12-22 11:40:30 +08:00
|
|
|
static void bnx2fc_ofld_wait(struct bnx2fc_rport *tgt)
|
|
|
|
{
|
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 05:43:17 +08:00
|
|
|
timer_setup(&tgt->ofld_timer, bnx2fc_ofld_timer, 0);
|
2012-12-22 11:40:30 +08:00
|
|
|
mod_timer(&tgt->ofld_timer, jiffies + BNX2FC_FW_TIMEOUT);
|
|
|
|
|
|
|
|
wait_event_interruptible(tgt->ofld_wait,
|
|
|
|
(test_bit(
|
|
|
|
BNX2FC_FLAG_OFLD_REQ_CMPL,
|
|
|
|
&tgt->flags)));
|
|
|
|
if (signal_pending(current))
|
|
|
|
flush_signals(current);
|
|
|
|
del_timer_sync(&tgt->ofld_timer);
|
|
|
|
}
|
|
|
|
|
2011-02-05 04:10:34 +08:00
|
|
|
static void bnx2fc_offload_session(struct fcoe_port *port,
|
|
|
|
struct bnx2fc_rport *tgt,
|
|
|
|
struct fc_rport_priv *rdata)
|
|
|
|
{
|
|
|
|
struct fc_rport *rport = rdata->rport;
|
2011-07-27 05:51:39 +08:00
|
|
|
struct bnx2fc_interface *interface = port->priv;
|
|
|
|
struct bnx2fc_hba *hba = interface->hba;
|
2011-02-05 04:10:34 +08:00
|
|
|
int rval;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
/* Initialize bnx2fc_rport */
|
|
|
|
/* NOTE: tgt is already bzero'd */
|
|
|
|
rval = bnx2fc_init_tgt(tgt, port, rdata);
|
|
|
|
if (rval) {
|
|
|
|
printk(KERN_ERR PFX "Failed to allocate conn id for "
|
|
|
|
"port_id (%6x)\n", rport->port_id);
|
2011-08-05 08:38:47 +08:00
|
|
|
goto tgt_init_err;
|
2011-02-05 04:10:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate session resources */
|
|
|
|
rval = bnx2fc_alloc_session_resc(hba, tgt);
|
|
|
|
if (rval) {
|
|
|
|
printk(KERN_ERR PFX "Failed to allocate resources\n");
|
|
|
|
goto ofld_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize FCoE session offload process.
|
|
|
|
* Upon completion of offload process add
|
|
|
|
* rport to list of rports
|
|
|
|
*/
|
|
|
|
retry_ofld:
|
|
|
|
clear_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags);
|
|
|
|
rval = bnx2fc_send_session_ofld_req(port, tgt);
|
|
|
|
if (rval) {
|
|
|
|
printk(KERN_ERR PFX "ofld_req failed\n");
|
|
|
|
goto ofld_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* wait for the session is offloaded and enabled. 3 Secs
|
|
|
|
* should be ample time for this process to complete.
|
|
|
|
*/
|
2012-12-22 11:40:30 +08:00
|
|
|
bnx2fc_ofld_wait(tgt);
|
2011-02-05 04:10:34 +08:00
|
|
|
|
|
|
|
if (!(test_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags))) {
|
|
|
|
if (test_and_clear_bit(BNX2FC_FLAG_CTX_ALLOC_FAILURE,
|
|
|
|
&tgt->flags)) {
|
|
|
|
BNX2FC_TGT_DBG(tgt, "ctx_alloc_failure, "
|
|
|
|
"retry ofld..%d\n", i++);
|
|
|
|
msleep_interruptible(1000);
|
|
|
|
if (i > 3) {
|
|
|
|
i = 0;
|
|
|
|
goto ofld_err;
|
|
|
|
}
|
|
|
|
goto retry_ofld;
|
|
|
|
}
|
|
|
|
goto ofld_err;
|
|
|
|
}
|
|
|
|
if (bnx2fc_map_doorbell(tgt)) {
|
|
|
|
printk(KERN_ERR PFX "map doorbell failed - no mem\n");
|
2012-12-22 11:40:31 +08:00
|
|
|
goto ofld_err;
|
|
|
|
}
|
|
|
|
clear_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags);
|
|
|
|
rval = bnx2fc_send_session_enable_req(port, tgt);
|
|
|
|
if (rval) {
|
|
|
|
pr_err(PFX "enable session failed\n");
|
|
|
|
goto ofld_err;
|
2011-08-31 06:54:53 +08:00
|
|
|
}
|
2012-12-22 11:40:31 +08:00
|
|
|
bnx2fc_ofld_wait(tgt);
|
|
|
|
if (!(test_bit(BNX2FC_FLAG_ENABLED, &tgt->flags)))
|
|
|
|
goto ofld_err;
|
2011-02-05 04:10:34 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
ofld_err:
|
|
|
|
/* couldn't offload the session. log off from this rport */
|
|
|
|
BNX2FC_TGT_DBG(tgt, "bnx2fc_offload_session - offload error\n");
|
2012-12-22 11:40:31 +08:00
|
|
|
clear_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags);
|
2011-02-05 04:10:34 +08:00
|
|
|
/* Free session resources */
|
|
|
|
bnx2fc_free_session_resc(hba, tgt);
|
2011-08-05 08:38:47 +08:00
|
|
|
tgt_init_err:
|
2011-02-05 04:10:34 +08:00
|
|
|
if (tgt->fcoe_conn_id != -1)
|
|
|
|
bnx2fc_free_conn_id(hba, tgt->fcoe_conn_id);
|
2016-10-18 16:01:44 +08:00
|
|
|
fc_rport_logoff(rdata);
|
2011-02-05 04:10:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void bnx2fc_flush_active_ios(struct bnx2fc_rport *tgt)
|
|
|
|
{
|
|
|
|
struct bnx2fc_cmd *io_req;
|
2012-06-07 17:19:36 +08:00
|
|
|
struct bnx2fc_cmd *tmp;
|
2011-02-05 04:10:34 +08:00
|
|
|
int rc;
|
|
|
|
int i = 0;
|
|
|
|
BNX2FC_TGT_DBG(tgt, "Entered flush_active_ios - %d\n",
|
|
|
|
tgt->num_active_ios.counter);
|
|
|
|
|
|
|
|
spin_lock_bh(&tgt->tgt_lock);
|
|
|
|
tgt->flush_in_prog = 1;
|
|
|
|
|
2012-06-07 17:19:36 +08:00
|
|
|
list_for_each_entry_safe(io_req, tmp, &tgt->active_cmd_queue, link) {
|
2011-02-05 04:10:34 +08:00
|
|
|
i++;
|
|
|
|
list_del_init(&io_req->link);
|
|
|
|
io_req->on_active_queue = 0;
|
|
|
|
BNX2FC_IO_DBG(io_req, "cmd_queue cleanup\n");
|
|
|
|
|
|
|
|
if (cancel_delayed_work(&io_req->timeout_work)) {
|
|
|
|
if (test_and_clear_bit(BNX2FC_FLAG_EH_ABORT,
|
|
|
|
&io_req->req_flags)) {
|
|
|
|
/* Handle eh_abort timeout */
|
|
|
|
BNX2FC_IO_DBG(io_req, "eh_abort for IO "
|
|
|
|
"cleaned up\n");
|
2019-06-24 16:29:57 +08:00
|
|
|
complete(&io_req->abts_done);
|
2011-02-05 04:10:34 +08:00
|
|
|
}
|
|
|
|
kref_put(&io_req->refcount,
|
|
|
|
bnx2fc_cmd_release); /* drop timer hold */
|
|
|
|
}
|
|
|
|
|
|
|
|
set_bit(BNX2FC_FLAG_IO_COMPL, &io_req->req_flags);
|
|
|
|
set_bit(BNX2FC_FLAG_IO_CLEANUP, &io_req->req_flags);
|
2012-06-07 17:19:35 +08:00
|
|
|
|
|
|
|
/* Do not issue cleanup when disable request failed */
|
|
|
|
if (test_bit(BNX2FC_FLAG_DISABLE_FAILED, &tgt->flags))
|
|
|
|
bnx2fc_process_cleanup_compl(io_req, io_req->task, 0);
|
|
|
|
else {
|
|
|
|
rc = bnx2fc_initiate_cleanup(io_req);
|
|
|
|
BUG_ON(rc);
|
|
|
|
}
|
2011-02-05 04:10:34 +08:00
|
|
|
}
|
|
|
|
|
2012-06-07 17:19:36 +08:00
|
|
|
list_for_each_entry_safe(io_req, tmp, &tgt->active_tm_queue, link) {
|
2012-04-25 06:26:03 +08:00
|
|
|
i++;
|
|
|
|
list_del_init(&io_req->link);
|
|
|
|
io_req->on_tmf_queue = 0;
|
|
|
|
BNX2FC_IO_DBG(io_req, "tm_queue cleanup\n");
|
2019-06-24 16:29:57 +08:00
|
|
|
if (io_req->wait_for_abts_comp)
|
|
|
|
complete(&io_req->abts_done);
|
2012-04-25 06:26:03 +08:00
|
|
|
}
|
|
|
|
|
2012-06-07 17:19:36 +08:00
|
|
|
list_for_each_entry_safe(io_req, tmp, &tgt->els_queue, link) {
|
2011-02-05 04:10:34 +08:00
|
|
|
i++;
|
|
|
|
list_del_init(&io_req->link);
|
|
|
|
io_req->on_active_queue = 0;
|
|
|
|
|
|
|
|
BNX2FC_IO_DBG(io_req, "els_queue cleanup\n");
|
|
|
|
|
|
|
|
if (cancel_delayed_work(&io_req->timeout_work))
|
|
|
|
kref_put(&io_req->refcount,
|
|
|
|
bnx2fc_cmd_release); /* drop timer hold */
|
|
|
|
|
|
|
|
if ((io_req->cb_func) && (io_req->cb_arg)) {
|
|
|
|
io_req->cb_func(io_req->cb_arg);
|
|
|
|
io_req->cb_arg = NULL;
|
|
|
|
}
|
|
|
|
|
2012-06-07 17:19:35 +08:00
|
|
|
/* Do not issue cleanup when disable request failed */
|
|
|
|
if (test_bit(BNX2FC_FLAG_DISABLE_FAILED, &tgt->flags))
|
|
|
|
bnx2fc_process_cleanup_compl(io_req, io_req->task, 0);
|
|
|
|
else {
|
|
|
|
rc = bnx2fc_initiate_cleanup(io_req);
|
|
|
|
BUG_ON(rc);
|
|
|
|
}
|
2011-02-05 04:10:34 +08:00
|
|
|
}
|
|
|
|
|
2012-06-07 17:19:36 +08:00
|
|
|
list_for_each_entry_safe(io_req, tmp, &tgt->io_retire_queue, link) {
|
2011-02-05 04:10:34 +08:00
|
|
|
i++;
|
|
|
|
list_del_init(&io_req->link);
|
|
|
|
|
|
|
|
BNX2FC_IO_DBG(io_req, "retire_queue flush\n");
|
|
|
|
|
2012-04-25 06:26:02 +08:00
|
|
|
if (cancel_delayed_work(&io_req->timeout_work)) {
|
|
|
|
if (test_and_clear_bit(BNX2FC_FLAG_EH_ABORT,
|
|
|
|
&io_req->req_flags)) {
|
|
|
|
/* Handle eh_abort timeout */
|
|
|
|
BNX2FC_IO_DBG(io_req, "eh_abort for IO "
|
|
|
|
"in retire_q\n");
|
2019-06-24 16:29:57 +08:00
|
|
|
if (io_req->wait_for_abts_comp)
|
|
|
|
complete(&io_req->abts_done);
|
2012-04-25 06:26:02 +08:00
|
|
|
}
|
2011-02-05 04:10:34 +08:00
|
|
|
kref_put(&io_req->refcount, bnx2fc_cmd_release);
|
2012-04-25 06:26:02 +08:00
|
|
|
}
|
2011-02-05 04:10:34 +08:00
|
|
|
|
|
|
|
clear_bit(BNX2FC_FLAG_ISSUE_RRQ, &io_req->req_flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
BNX2FC_TGT_DBG(tgt, "IOs flushed = %d\n", i);
|
|
|
|
i = 0;
|
|
|
|
spin_unlock_bh(&tgt->tgt_lock);
|
|
|
|
/* wait for active_ios to go to 0 */
|
|
|
|
while ((tgt->num_active_ios.counter != 0) && (i++ < BNX2FC_WAIT_CNT))
|
|
|
|
msleep(25);
|
|
|
|
if (tgt->num_active_ios.counter != 0)
|
|
|
|
printk(KERN_ERR PFX "CLEANUP on port 0x%x:"
|
|
|
|
" active_ios = %d\n",
|
|
|
|
tgt->rdata->ids.port_id, tgt->num_active_ios.counter);
|
|
|
|
spin_lock_bh(&tgt->tgt_lock);
|
|
|
|
tgt->flush_in_prog = 0;
|
|
|
|
spin_unlock_bh(&tgt->tgt_lock);
|
|
|
|
}
|
|
|
|
|
2012-12-22 11:40:30 +08:00
|
|
|
static void bnx2fc_upld_wait(struct bnx2fc_rport *tgt)
|
|
|
|
{
|
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 05:43:17 +08:00
|
|
|
timer_setup(&tgt->upld_timer, bnx2fc_upld_timer, 0);
|
2012-12-22 11:40:30 +08:00
|
|
|
mod_timer(&tgt->upld_timer, jiffies + BNX2FC_FW_TIMEOUT);
|
|
|
|
wait_event_interruptible(tgt->upld_wait,
|
|
|
|
(test_bit(
|
|
|
|
BNX2FC_FLAG_UPLD_REQ_COMPL,
|
|
|
|
&tgt->flags)));
|
|
|
|
if (signal_pending(current))
|
|
|
|
flush_signals(current);
|
|
|
|
del_timer_sync(&tgt->upld_timer);
|
|
|
|
}
|
|
|
|
|
2011-02-05 04:10:34 +08:00
|
|
|
static void bnx2fc_upload_session(struct fcoe_port *port,
|
|
|
|
struct bnx2fc_rport *tgt)
|
|
|
|
{
|
2011-07-27 05:51:39 +08:00
|
|
|
struct bnx2fc_interface *interface = port->priv;
|
|
|
|
struct bnx2fc_hba *hba = interface->hba;
|
2011-02-05 04:10:34 +08:00
|
|
|
|
|
|
|
BNX2FC_TGT_DBG(tgt, "upload_session: active_ios = %d\n",
|
|
|
|
tgt->num_active_ios.counter);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called with hba->hba_mutex held.
|
|
|
|
* This is a blocking call
|
|
|
|
*/
|
|
|
|
clear_bit(BNX2FC_FLAG_UPLD_REQ_COMPL, &tgt->flags);
|
|
|
|
bnx2fc_send_session_disable_req(port, tgt);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* wait for upload to complete. 3 Secs
|
|
|
|
* should be sufficient time for this process to complete.
|
|
|
|
*/
|
|
|
|
BNX2FC_TGT_DBG(tgt, "waiting for disable compl\n");
|
2012-12-22 11:40:30 +08:00
|
|
|
bnx2fc_upld_wait(tgt);
|
2011-02-05 04:10:34 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* traverse thru the active_q and tmf_q and cleanup
|
|
|
|
* IOs in these lists
|
|
|
|
*/
|
|
|
|
BNX2FC_TGT_DBG(tgt, "flush/upload - disable wait flags = 0x%lx\n",
|
|
|
|
tgt->flags);
|
|
|
|
bnx2fc_flush_active_ios(tgt);
|
|
|
|
|
|
|
|
/* Issue destroy KWQE */
|
|
|
|
if (test_bit(BNX2FC_FLAG_DISABLED, &tgt->flags)) {
|
|
|
|
BNX2FC_TGT_DBG(tgt, "send destroy req\n");
|
|
|
|
clear_bit(BNX2FC_FLAG_UPLD_REQ_COMPL, &tgt->flags);
|
|
|
|
bnx2fc_send_session_destroy_req(hba, tgt);
|
|
|
|
|
|
|
|
/* wait for destroy to complete */
|
2012-12-22 11:40:30 +08:00
|
|
|
bnx2fc_upld_wait(tgt);
|
2011-02-05 04:10:34 +08:00
|
|
|
|
|
|
|
if (!(test_bit(BNX2FC_FLAG_DESTROYED, &tgt->flags)))
|
|
|
|
printk(KERN_ERR PFX "ERROR!! destroy timed out\n");
|
|
|
|
|
|
|
|
BNX2FC_TGT_DBG(tgt, "destroy wait complete flags = 0x%lx\n",
|
|
|
|
tgt->flags);
|
|
|
|
|
2012-06-07 17:19:35 +08:00
|
|
|
} else if (test_bit(BNX2FC_FLAG_DISABLE_FAILED, &tgt->flags)) {
|
|
|
|
printk(KERN_ERR PFX "ERROR!! DISABLE req failed, destroy"
|
|
|
|
" not sent to FW\n");
|
|
|
|
} else {
|
2011-02-05 04:10:34 +08:00
|
|
|
printk(KERN_ERR PFX "ERROR!! DISABLE req timed out, destroy"
|
|
|
|
" not sent to FW\n");
|
2012-06-07 17:19:35 +08:00
|
|
|
}
|
2011-02-05 04:10:34 +08:00
|
|
|
|
|
|
|
/* Free session resources */
|
|
|
|
bnx2fc_free_session_resc(hba, tgt);
|
|
|
|
bnx2fc_free_conn_id(hba, tgt->fcoe_conn_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bnx2fc_init_tgt(struct bnx2fc_rport *tgt,
|
|
|
|
struct fcoe_port *port,
|
|
|
|
struct fc_rport_priv *rdata)
|
|
|
|
{
|
|
|
|
|
|
|
|
struct fc_rport *rport = rdata->rport;
|
2011-07-27 05:51:39 +08:00
|
|
|
struct bnx2fc_interface *interface = port->priv;
|
|
|
|
struct bnx2fc_hba *hba = interface->hba;
|
2011-06-14 19:33:44 +08:00
|
|
|
struct b577xx_doorbell_set_prod *sq_db = &tgt->sq_db;
|
|
|
|
struct b577xx_fcoe_rx_doorbell *rx_db = &tgt->rx_db;
|
2011-02-05 04:10:34 +08:00
|
|
|
|
|
|
|
tgt->rport = rport;
|
|
|
|
tgt->rdata = rdata;
|
|
|
|
tgt->port = port;
|
|
|
|
|
|
|
|
if (hba->num_ofld_sess >= BNX2FC_NUM_MAX_SESS) {
|
|
|
|
BNX2FC_TGT_DBG(tgt, "exceeded max sessions. logoff this tgt\n");
|
|
|
|
tgt->fcoe_conn_id = -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
tgt->fcoe_conn_id = bnx2fc_alloc_conn_id(hba, tgt);
|
|
|
|
if (tgt->fcoe_conn_id == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
BNX2FC_TGT_DBG(tgt, "init_tgt - conn_id = 0x%x\n", tgt->fcoe_conn_id);
|
|
|
|
|
|
|
|
tgt->max_sqes = BNX2FC_SQ_WQES_MAX;
|
|
|
|
tgt->max_rqes = BNX2FC_RQ_WQES_MAX;
|
|
|
|
tgt->max_cqes = BNX2FC_CQ_WQES_MAX;
|
2011-06-14 19:33:44 +08:00
|
|
|
atomic_set(&tgt->free_sqes, BNX2FC_SQ_WQES_MAX);
|
2011-02-05 04:10:34 +08:00
|
|
|
|
|
|
|
/* Initialize the toggle bit */
|
|
|
|
tgt->sq_curr_toggle_bit = 1;
|
|
|
|
tgt->cq_curr_toggle_bit = 1;
|
|
|
|
tgt->sq_prod_idx = 0;
|
|
|
|
tgt->cq_cons_idx = 0;
|
|
|
|
tgt->rq_prod_idx = 0x8000;
|
|
|
|
tgt->rq_cons_idx = 0;
|
|
|
|
atomic_set(&tgt->num_active_ios, 0);
|
2013-12-12 07:30:22 +08:00
|
|
|
tgt->retry_delay_timestamp = 0;
|
2011-02-05 04:10:34 +08:00
|
|
|
|
2013-01-11 15:59:38 +08:00
|
|
|
if (rdata->flags & FC_RP_FLAGS_RETRY &&
|
|
|
|
rdata->ids.roles & FC_RPORT_ROLE_FCP_TARGET &&
|
|
|
|
!(rdata->ids.roles & FC_RPORT_ROLE_FCP_INITIATOR)) {
|
2011-07-27 05:51:40 +08:00
|
|
|
tgt->dev_type = TYPE_TAPE;
|
|
|
|
tgt->io_timeout = 0; /* use default ULP timeout */
|
|
|
|
} else {
|
|
|
|
tgt->dev_type = TYPE_DISK;
|
|
|
|
tgt->io_timeout = BNX2FC_IO_TIMEOUT;
|
|
|
|
}
|
|
|
|
|
2011-06-14 19:33:44 +08:00
|
|
|
/* initialize sq doorbell */
|
|
|
|
sq_db->header.header = B577XX_DOORBELL_HDR_DB_TYPE;
|
|
|
|
sq_db->header.header |= B577XX_FCOE_CONNECTION_TYPE <<
|
|
|
|
B577XX_DOORBELL_HDR_CONN_TYPE_SHIFT;
|
|
|
|
/* initialize rx doorbell */
|
|
|
|
rx_db->hdr.header = ((0x1 << B577XX_DOORBELL_HDR_RX_SHIFT) |
|
|
|
|
(0x1 << B577XX_DOORBELL_HDR_DB_TYPE_SHIFT) |
|
|
|
|
(B577XX_FCOE_CONNECTION_TYPE <<
|
|
|
|
B577XX_DOORBELL_HDR_CONN_TYPE_SHIFT));
|
|
|
|
rx_db->params = (0x2 << B577XX_FCOE_RX_DOORBELL_NEGATIVE_ARM_SHIFT) |
|
|
|
|
(0x3 << B577XX_FCOE_RX_DOORBELL_OPCODE_SHIFT);
|
2011-02-05 04:10:34 +08:00
|
|
|
|
|
|
|
spin_lock_init(&tgt->tgt_lock);
|
|
|
|
spin_lock_init(&tgt->cq_lock);
|
|
|
|
|
|
|
|
/* Initialize active_cmd_queue list */
|
|
|
|
INIT_LIST_HEAD(&tgt->active_cmd_queue);
|
|
|
|
|
|
|
|
/* Initialize IO retire queue */
|
|
|
|
INIT_LIST_HEAD(&tgt->io_retire_queue);
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&tgt->els_queue);
|
|
|
|
|
|
|
|
/* Initialize active_tm_queue list */
|
|
|
|
INIT_LIST_HEAD(&tgt->active_tm_queue);
|
|
|
|
|
|
|
|
init_waitqueue_head(&tgt->ofld_wait);
|
|
|
|
init_waitqueue_head(&tgt->upld_wait);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-13 15:46:33 +08:00
|
|
|
/*
|
2011-02-05 04:10:34 +08:00
|
|
|
* This event_callback is called after successful completion of libfc
|
|
|
|
* initiated target login. bnx2fc can proceed with initiating the session
|
|
|
|
* establishment.
|
|
|
|
*/
|
|
|
|
void bnx2fc_rport_event_handler(struct fc_lport *lport,
|
|
|
|
struct fc_rport_priv *rdata,
|
|
|
|
enum fc_rport_event event)
|
|
|
|
{
|
|
|
|
struct fcoe_port *port = lport_priv(lport);
|
2011-07-27 05:51:39 +08:00
|
|
|
struct bnx2fc_interface *interface = port->priv;
|
|
|
|
struct bnx2fc_hba *hba = interface->hba;
|
2011-02-05 04:10:34 +08:00
|
|
|
struct fc_rport *rport = rdata->rport;
|
|
|
|
struct fc_rport_libfc_priv *rp;
|
|
|
|
struct bnx2fc_rport *tgt;
|
|
|
|
u32 port_id;
|
|
|
|
|
|
|
|
BNX2FC_HBA_DBG(lport, "rport_event_hdlr: event = %d, port_id = 0x%x\n",
|
|
|
|
event, rdata->ids.port_id);
|
|
|
|
switch (event) {
|
|
|
|
case RPORT_EV_READY:
|
|
|
|
if (!rport) {
|
2011-06-28 14:30:53 +08:00
|
|
|
printk(KERN_ERR PFX "rport is NULL: ERROR!\n");
|
2011-02-05 04:10:34 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
rp = rport->dd_data;
|
|
|
|
if (rport->port_id == FC_FID_DIR_SERV) {
|
|
|
|
/*
|
2011-03-31 09:57:33 +08:00
|
|
|
* bnx2fc_rport structure doesn't exist for
|
2011-02-05 04:10:34 +08:00
|
|
|
* directory server.
|
|
|
|
* We should not come here, as lport will
|
|
|
|
* take care of fabric login
|
|
|
|
*/
|
2011-06-28 14:30:53 +08:00
|
|
|
printk(KERN_ERR PFX "%x - rport_event_handler ERROR\n",
|
2011-02-05 04:10:34 +08:00
|
|
|
rdata->ids.port_id);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rdata->spp_type != FC_TYPE_FCP) {
|
|
|
|
BNX2FC_HBA_DBG(lport, "not FCP type target."
|
|
|
|
" not offloading\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!(rdata->ids.roles & FC_RPORT_ROLE_FCP_TARGET)) {
|
|
|
|
BNX2FC_HBA_DBG(lport, "not FCP_TARGET"
|
|
|
|
" not offloading\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2022-01-28 14:31:01 +08:00
|
|
|
* Offload process is protected with hba mutex.
|
2011-02-05 04:10:34 +08:00
|
|
|
* Use the same mutex_lock for upload process too
|
|
|
|
*/
|
|
|
|
mutex_lock(&hba->hba_mutex);
|
|
|
|
tgt = (struct bnx2fc_rport *)&rp[1];
|
|
|
|
|
|
|
|
/* This can happen when ADISC finds the same target */
|
2012-12-22 11:40:31 +08:00
|
|
|
if (test_bit(BNX2FC_FLAG_ENABLED, &tgt->flags)) {
|
2011-02-05 04:10:34 +08:00
|
|
|
BNX2FC_TGT_DBG(tgt, "already offloaded\n");
|
|
|
|
mutex_unlock(&hba->hba_mutex);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Offload the session. This is a blocking call, and will
|
|
|
|
* wait until the session is offloaded.
|
|
|
|
*/
|
|
|
|
bnx2fc_offload_session(port, tgt, rdata);
|
|
|
|
|
|
|
|
BNX2FC_TGT_DBG(tgt, "OFFLOAD num_ofld_sess = %d\n",
|
|
|
|
hba->num_ofld_sess);
|
|
|
|
|
2012-12-22 11:40:31 +08:00
|
|
|
if (test_bit(BNX2FC_FLAG_ENABLED, &tgt->flags)) {
|
|
|
|
/* Session is offloaded and enabled. */
|
2011-02-05 04:10:34 +08:00
|
|
|
BNX2FC_TGT_DBG(tgt, "sess offloaded\n");
|
|
|
|
/* This counter is protected with hba mutex */
|
|
|
|
hba->num_ofld_sess++;
|
|
|
|
|
|
|
|
set_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Offload or enable would have failed.
|
|
|
|
* In offload/enable completion path, the
|
|
|
|
* rport would have already been removed
|
|
|
|
*/
|
|
|
|
BNX2FC_TGT_DBG(tgt, "Port is being logged off as "
|
|
|
|
"offloaded flag not set\n");
|
|
|
|
}
|
|
|
|
mutex_unlock(&hba->hba_mutex);
|
|
|
|
break;
|
|
|
|
case RPORT_EV_LOGO:
|
|
|
|
case RPORT_EV_FAILED:
|
|
|
|
case RPORT_EV_STOP:
|
|
|
|
port_id = rdata->ids.port_id;
|
|
|
|
if (port_id == FC_FID_DIR_SERV)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!rport) {
|
2011-06-28 14:30:53 +08:00
|
|
|
printk(KERN_INFO PFX "%x - rport not created Yet!!\n",
|
2011-02-05 04:10:34 +08:00
|
|
|
port_id);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rp = rport->dd_data;
|
|
|
|
mutex_lock(&hba->hba_mutex);
|
|
|
|
/*
|
|
|
|
* Perform session upload. Note that rdata->peers is already
|
|
|
|
* removed from disc->rports list before we get this event.
|
|
|
|
*/
|
|
|
|
tgt = (struct bnx2fc_rport *)&rp[1];
|
|
|
|
|
2012-12-22 11:40:31 +08:00
|
|
|
if (!(test_bit(BNX2FC_FLAG_ENABLED, &tgt->flags))) {
|
2011-02-05 04:10:34 +08:00
|
|
|
mutex_unlock(&hba->hba_mutex);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
clear_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags);
|
|
|
|
|
|
|
|
bnx2fc_upload_session(port, tgt);
|
|
|
|
hba->num_ofld_sess--;
|
|
|
|
BNX2FC_TGT_DBG(tgt, "UPLOAD num_ofld_sess = %d\n",
|
|
|
|
hba->num_ofld_sess);
|
|
|
|
/*
|
|
|
|
* Try to wake up the linkdown wait thread. If num_ofld_sess
|
|
|
|
* is 0, the waiting therad wakes up
|
|
|
|
*/
|
|
|
|
if ((hba->wait_for_link_down) &&
|
|
|
|
(hba->num_ofld_sess == 0)) {
|
|
|
|
wake_up_interruptible(&hba->shutdown_wait);
|
|
|
|
}
|
|
|
|
mutex_unlock(&hba->hba_mutex);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RPORT_EV_NONE:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* bnx2fc_tgt_lookup() - Lookup a bnx2fc_rport by port_id
|
|
|
|
*
|
|
|
|
* @port: fcoe_port struct to lookup the target port on
|
|
|
|
* @port_id: The remote port ID to look up
|
|
|
|
*/
|
|
|
|
struct bnx2fc_rport *bnx2fc_tgt_lookup(struct fcoe_port *port,
|
|
|
|
u32 port_id)
|
|
|
|
{
|
2011-07-27 05:51:39 +08:00
|
|
|
struct bnx2fc_interface *interface = port->priv;
|
|
|
|
struct bnx2fc_hba *hba = interface->hba;
|
2011-02-05 04:10:34 +08:00
|
|
|
struct bnx2fc_rport *tgt;
|
|
|
|
struct fc_rport_priv *rdata;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < BNX2FC_NUM_MAX_SESS; i++) {
|
|
|
|
tgt = hba->tgt_ofld_list[i];
|
|
|
|
if ((tgt) && (tgt->port == port)) {
|
|
|
|
rdata = tgt->rdata;
|
|
|
|
if (rdata->ids.port_id == port_id) {
|
|
|
|
if (rdata->rp_state != RPORT_ST_DELETE) {
|
|
|
|
BNX2FC_TGT_DBG(tgt, "rport "
|
|
|
|
"obtained\n");
|
|
|
|
return tgt;
|
|
|
|
} else {
|
2011-07-27 05:51:39 +08:00
|
|
|
BNX2FC_TGT_DBG(tgt, "rport 0x%x "
|
2011-02-05 04:10:34 +08:00
|
|
|
"is in DELETED state\n",
|
|
|
|
rdata->ids.port_id);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* bnx2fc_alloc_conn_id - allocates FCOE Connection id
|
|
|
|
*
|
|
|
|
* @hba: pointer to adapter structure
|
|
|
|
* @tgt: pointer to bnx2fc_rport structure
|
|
|
|
*/
|
|
|
|
static u32 bnx2fc_alloc_conn_id(struct bnx2fc_hba *hba,
|
|
|
|
struct bnx2fc_rport *tgt)
|
|
|
|
{
|
|
|
|
u32 conn_id, next;
|
|
|
|
|
|
|
|
/* called with hba mutex held */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* tgt_ofld_list access is synchronized using
|
|
|
|
* both hba mutex and hba lock. Atleast hba mutex or
|
|
|
|
* hba lock needs to be held for read access.
|
|
|
|
*/
|
|
|
|
|
|
|
|
spin_lock_bh(&hba->hba_lock);
|
|
|
|
next = hba->next_conn_id;
|
|
|
|
conn_id = hba->next_conn_id++;
|
|
|
|
if (hba->next_conn_id == BNX2FC_NUM_MAX_SESS)
|
|
|
|
hba->next_conn_id = 0;
|
|
|
|
|
|
|
|
while (hba->tgt_ofld_list[conn_id] != NULL) {
|
|
|
|
conn_id++;
|
|
|
|
if (conn_id == BNX2FC_NUM_MAX_SESS)
|
|
|
|
conn_id = 0;
|
|
|
|
|
|
|
|
if (conn_id == next) {
|
|
|
|
/* No free conn_ids are available */
|
|
|
|
spin_unlock_bh(&hba->hba_lock);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
hba->tgt_ofld_list[conn_id] = tgt;
|
|
|
|
tgt->fcoe_conn_id = conn_id;
|
|
|
|
spin_unlock_bh(&hba->hba_lock);
|
|
|
|
return conn_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bnx2fc_free_conn_id(struct bnx2fc_hba *hba, u32 conn_id)
|
|
|
|
{
|
|
|
|
/* called with hba mutex held */
|
|
|
|
spin_lock_bh(&hba->hba_lock);
|
|
|
|
hba->tgt_ofld_list[conn_id] = NULL;
|
|
|
|
spin_unlock_bh(&hba->hba_lock);
|
|
|
|
}
|
|
|
|
|
2020-07-13 15:46:33 +08:00
|
|
|
/*
|
|
|
|
* bnx2fc_alloc_session_resc - Allocate qp resources for the session
|
2011-02-05 04:10:34 +08:00
|
|
|
*/
|
|
|
|
static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
|
|
|
|
struct bnx2fc_rport *tgt)
|
|
|
|
{
|
|
|
|
dma_addr_t page;
|
|
|
|
int num_pages;
|
|
|
|
u32 *pbl;
|
|
|
|
|
|
|
|
/* Allocate and map SQ */
|
|
|
|
tgt->sq_mem_size = tgt->max_sqes * BNX2FC_SQ_WQE_SIZE;
|
2014-03-18 11:19:07 +08:00
|
|
|
tgt->sq_mem_size = (tgt->sq_mem_size + (CNIC_PAGE_SIZE - 1)) &
|
|
|
|
CNIC_PAGE_MASK;
|
2011-02-05 04:10:34 +08:00
|
|
|
|
cross-tree: phase out dma_zalloc_coherent()
We already need to zero out memory for dma_alloc_coherent(), as such
using dma_zalloc_coherent() is superflous. Phase it out.
This change was generated with the following Coccinelle SmPL patch:
@ replace_dma_zalloc_coherent @
expression dev, size, data, handle, flags;
@@
-dma_zalloc_coherent(dev, size, handle, flags)
+dma_alloc_coherent(dev, size, handle, flags)
Suggested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
[hch: re-ran the script on the latest tree]
Signed-off-by: Christoph Hellwig <hch@lst.de>
2019-01-04 16:23:09 +08:00
|
|
|
tgt->sq = dma_alloc_coherent(&hba->pcidev->dev, tgt->sq_mem_size,
|
|
|
|
&tgt->sq_dma, GFP_KERNEL);
|
2011-02-05 04:10:34 +08:00
|
|
|
if (!tgt->sq) {
|
2011-06-28 14:30:53 +08:00
|
|
|
printk(KERN_ERR PFX "unable to allocate SQ memory %d\n",
|
2011-02-05 04:10:34 +08:00
|
|
|
tgt->sq_mem_size);
|
|
|
|
goto mem_alloc_failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate and map CQ */
|
|
|
|
tgt->cq_mem_size = tgt->max_cqes * BNX2FC_CQ_WQE_SIZE;
|
2014-03-18 11:19:07 +08:00
|
|
|
tgt->cq_mem_size = (tgt->cq_mem_size + (CNIC_PAGE_SIZE - 1)) &
|
|
|
|
CNIC_PAGE_MASK;
|
2011-02-05 04:10:34 +08:00
|
|
|
|
cross-tree: phase out dma_zalloc_coherent()
We already need to zero out memory for dma_alloc_coherent(), as such
using dma_zalloc_coherent() is superflous. Phase it out.
This change was generated with the following Coccinelle SmPL patch:
@ replace_dma_zalloc_coherent @
expression dev, size, data, handle, flags;
@@
-dma_zalloc_coherent(dev, size, handle, flags)
+dma_alloc_coherent(dev, size, handle, flags)
Suggested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
[hch: re-ran the script on the latest tree]
Signed-off-by: Christoph Hellwig <hch@lst.de>
2019-01-04 16:23:09 +08:00
|
|
|
tgt->cq = dma_alloc_coherent(&hba->pcidev->dev, tgt->cq_mem_size,
|
|
|
|
&tgt->cq_dma, GFP_KERNEL);
|
2011-02-05 04:10:34 +08:00
|
|
|
if (!tgt->cq) {
|
2011-06-28 14:30:53 +08:00
|
|
|
printk(KERN_ERR PFX "unable to allocate CQ memory %d\n",
|
2011-02-05 04:10:34 +08:00
|
|
|
tgt->cq_mem_size);
|
|
|
|
goto mem_alloc_failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate and map RQ and RQ PBL */
|
|
|
|
tgt->rq_mem_size = tgt->max_rqes * BNX2FC_RQ_WQE_SIZE;
|
2014-03-18 11:19:07 +08:00
|
|
|
tgt->rq_mem_size = (tgt->rq_mem_size + (CNIC_PAGE_SIZE - 1)) &
|
|
|
|
CNIC_PAGE_MASK;
|
2011-02-05 04:10:34 +08:00
|
|
|
|
cross-tree: phase out dma_zalloc_coherent()
We already need to zero out memory for dma_alloc_coherent(), as such
using dma_zalloc_coherent() is superflous. Phase it out.
This change was generated with the following Coccinelle SmPL patch:
@ replace_dma_zalloc_coherent @
expression dev, size, data, handle, flags;
@@
-dma_zalloc_coherent(dev, size, handle, flags)
+dma_alloc_coherent(dev, size, handle, flags)
Suggested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
[hch: re-ran the script on the latest tree]
Signed-off-by: Christoph Hellwig <hch@lst.de>
2019-01-04 16:23:09 +08:00
|
|
|
tgt->rq = dma_alloc_coherent(&hba->pcidev->dev, tgt->rq_mem_size,
|
|
|
|
&tgt->rq_dma, GFP_KERNEL);
|
2011-02-05 04:10:34 +08:00
|
|
|
if (!tgt->rq) {
|
2011-06-28 14:30:53 +08:00
|
|
|
printk(KERN_ERR PFX "unable to allocate RQ memory %d\n",
|
2011-02-05 04:10:34 +08:00
|
|
|
tgt->rq_mem_size);
|
|
|
|
goto mem_alloc_failure;
|
|
|
|
}
|
|
|
|
|
2014-03-18 11:19:07 +08:00
|
|
|
tgt->rq_pbl_size = (tgt->rq_mem_size / CNIC_PAGE_SIZE) * sizeof(void *);
|
|
|
|
tgt->rq_pbl_size = (tgt->rq_pbl_size + (CNIC_PAGE_SIZE - 1)) &
|
|
|
|
CNIC_PAGE_MASK;
|
2011-02-05 04:10:34 +08:00
|
|
|
|
cross-tree: phase out dma_zalloc_coherent()
We already need to zero out memory for dma_alloc_coherent(), as such
using dma_zalloc_coherent() is superflous. Phase it out.
This change was generated with the following Coccinelle SmPL patch:
@ replace_dma_zalloc_coherent @
expression dev, size, data, handle, flags;
@@
-dma_zalloc_coherent(dev, size, handle, flags)
+dma_alloc_coherent(dev, size, handle, flags)
Suggested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
[hch: re-ran the script on the latest tree]
Signed-off-by: Christoph Hellwig <hch@lst.de>
2019-01-04 16:23:09 +08:00
|
|
|
tgt->rq_pbl = dma_alloc_coherent(&hba->pcidev->dev, tgt->rq_pbl_size,
|
|
|
|
&tgt->rq_pbl_dma, GFP_KERNEL);
|
2011-02-05 04:10:34 +08:00
|
|
|
if (!tgt->rq_pbl) {
|
2011-06-28 14:30:53 +08:00
|
|
|
printk(KERN_ERR PFX "unable to allocate RQ PBL %d\n",
|
2011-02-05 04:10:34 +08:00
|
|
|
tgt->rq_pbl_size);
|
|
|
|
goto mem_alloc_failure;
|
|
|
|
}
|
|
|
|
|
2014-03-18 11:19:07 +08:00
|
|
|
num_pages = tgt->rq_mem_size / CNIC_PAGE_SIZE;
|
2011-02-05 04:10:34 +08:00
|
|
|
page = tgt->rq_dma;
|
|
|
|
pbl = (u32 *)tgt->rq_pbl;
|
|
|
|
|
|
|
|
while (num_pages--) {
|
|
|
|
*pbl = (u32)page;
|
|
|
|
pbl++;
|
|
|
|
*pbl = (u32)((u64)page >> 32);
|
|
|
|
pbl++;
|
2014-03-18 11:19:07 +08:00
|
|
|
page += CNIC_PAGE_SIZE;
|
2011-02-05 04:10:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate and map XFERQ */
|
|
|
|
tgt->xferq_mem_size = tgt->max_sqes * BNX2FC_XFERQ_WQE_SIZE;
|
2014-03-18 11:19:07 +08:00
|
|
|
tgt->xferq_mem_size = (tgt->xferq_mem_size + (CNIC_PAGE_SIZE - 1)) &
|
|
|
|
CNIC_PAGE_MASK;
|
2011-02-05 04:10:34 +08:00
|
|
|
|
cross-tree: phase out dma_zalloc_coherent()
We already need to zero out memory for dma_alloc_coherent(), as such
using dma_zalloc_coherent() is superflous. Phase it out.
This change was generated with the following Coccinelle SmPL patch:
@ replace_dma_zalloc_coherent @
expression dev, size, data, handle, flags;
@@
-dma_zalloc_coherent(dev, size, handle, flags)
+dma_alloc_coherent(dev, size, handle, flags)
Suggested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
[hch: re-ran the script on the latest tree]
Signed-off-by: Christoph Hellwig <hch@lst.de>
2019-01-04 16:23:09 +08:00
|
|
|
tgt->xferq = dma_alloc_coherent(&hba->pcidev->dev,
|
|
|
|
tgt->xferq_mem_size, &tgt->xferq_dma,
|
|
|
|
GFP_KERNEL);
|
2011-02-05 04:10:34 +08:00
|
|
|
if (!tgt->xferq) {
|
2011-06-28 14:30:53 +08:00
|
|
|
printk(KERN_ERR PFX "unable to allocate XFERQ %d\n",
|
2011-02-05 04:10:34 +08:00
|
|
|
tgt->xferq_mem_size);
|
|
|
|
goto mem_alloc_failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate and map CONFQ & CONFQ PBL */
|
|
|
|
tgt->confq_mem_size = tgt->max_sqes * BNX2FC_CONFQ_WQE_SIZE;
|
2014-03-18 11:19:07 +08:00
|
|
|
tgt->confq_mem_size = (tgt->confq_mem_size + (CNIC_PAGE_SIZE - 1)) &
|
|
|
|
CNIC_PAGE_MASK;
|
2011-02-05 04:10:34 +08:00
|
|
|
|
cross-tree: phase out dma_zalloc_coherent()
We already need to zero out memory for dma_alloc_coherent(), as such
using dma_zalloc_coherent() is superflous. Phase it out.
This change was generated with the following Coccinelle SmPL patch:
@ replace_dma_zalloc_coherent @
expression dev, size, data, handle, flags;
@@
-dma_zalloc_coherent(dev, size, handle, flags)
+dma_alloc_coherent(dev, size, handle, flags)
Suggested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
[hch: re-ran the script on the latest tree]
Signed-off-by: Christoph Hellwig <hch@lst.de>
2019-01-04 16:23:09 +08:00
|
|
|
tgt->confq = dma_alloc_coherent(&hba->pcidev->dev,
|
|
|
|
tgt->confq_mem_size, &tgt->confq_dma,
|
|
|
|
GFP_KERNEL);
|
2011-02-05 04:10:34 +08:00
|
|
|
if (!tgt->confq) {
|
2011-06-28 14:30:53 +08:00
|
|
|
printk(KERN_ERR PFX "unable to allocate CONFQ %d\n",
|
2011-02-05 04:10:34 +08:00
|
|
|
tgt->confq_mem_size);
|
|
|
|
goto mem_alloc_failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
tgt->confq_pbl_size =
|
2014-03-18 11:19:07 +08:00
|
|
|
(tgt->confq_mem_size / CNIC_PAGE_SIZE) * sizeof(void *);
|
2011-02-05 04:10:34 +08:00
|
|
|
tgt->confq_pbl_size =
|
2014-03-18 11:19:07 +08:00
|
|
|
(tgt->confq_pbl_size + (CNIC_PAGE_SIZE - 1)) & CNIC_PAGE_MASK;
|
2011-02-05 04:10:34 +08:00
|
|
|
|
cross-tree: phase out dma_zalloc_coherent()
We already need to zero out memory for dma_alloc_coherent(), as such
using dma_zalloc_coherent() is superflous. Phase it out.
This change was generated with the following Coccinelle SmPL patch:
@ replace_dma_zalloc_coherent @
expression dev, size, data, handle, flags;
@@
-dma_zalloc_coherent(dev, size, handle, flags)
+dma_alloc_coherent(dev, size, handle, flags)
Suggested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
[hch: re-ran the script on the latest tree]
Signed-off-by: Christoph Hellwig <hch@lst.de>
2019-01-04 16:23:09 +08:00
|
|
|
tgt->confq_pbl = dma_alloc_coherent(&hba->pcidev->dev,
|
|
|
|
tgt->confq_pbl_size,
|
|
|
|
&tgt->confq_pbl_dma, GFP_KERNEL);
|
2011-02-05 04:10:34 +08:00
|
|
|
if (!tgt->confq_pbl) {
|
2011-06-28 14:30:53 +08:00
|
|
|
printk(KERN_ERR PFX "unable to allocate CONFQ PBL %d\n",
|
2011-02-05 04:10:34 +08:00
|
|
|
tgt->confq_pbl_size);
|
|
|
|
goto mem_alloc_failure;
|
|
|
|
}
|
|
|
|
|
2014-03-18 11:19:07 +08:00
|
|
|
num_pages = tgt->confq_mem_size / CNIC_PAGE_SIZE;
|
2011-02-05 04:10:34 +08:00
|
|
|
page = tgt->confq_dma;
|
|
|
|
pbl = (u32 *)tgt->confq_pbl;
|
|
|
|
|
|
|
|
while (num_pages--) {
|
|
|
|
*pbl = (u32)page;
|
|
|
|
pbl++;
|
|
|
|
*pbl = (u32)((u64)page >> 32);
|
|
|
|
pbl++;
|
2014-03-18 11:19:07 +08:00
|
|
|
page += CNIC_PAGE_SIZE;
|
2011-02-05 04:10:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate and map ConnDB */
|
|
|
|
tgt->conn_db_mem_size = sizeof(struct fcoe_conn_db);
|
|
|
|
|
cross-tree: phase out dma_zalloc_coherent()
We already need to zero out memory for dma_alloc_coherent(), as such
using dma_zalloc_coherent() is superflous. Phase it out.
This change was generated with the following Coccinelle SmPL patch:
@ replace_dma_zalloc_coherent @
expression dev, size, data, handle, flags;
@@
-dma_zalloc_coherent(dev, size, handle, flags)
+dma_alloc_coherent(dev, size, handle, flags)
Suggested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
[hch: re-ran the script on the latest tree]
Signed-off-by: Christoph Hellwig <hch@lst.de>
2019-01-04 16:23:09 +08:00
|
|
|
tgt->conn_db = dma_alloc_coherent(&hba->pcidev->dev,
|
|
|
|
tgt->conn_db_mem_size,
|
|
|
|
&tgt->conn_db_dma, GFP_KERNEL);
|
2011-02-05 04:10:34 +08:00
|
|
|
if (!tgt->conn_db) {
|
2011-06-28 14:30:53 +08:00
|
|
|
printk(KERN_ERR PFX "unable to allocate conn_db %d\n",
|
2011-02-05 04:10:34 +08:00
|
|
|
tgt->conn_db_mem_size);
|
|
|
|
goto mem_alloc_failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Allocate and map LCQ */
|
|
|
|
tgt->lcq_mem_size = (tgt->max_sqes + 8) * BNX2FC_SQ_WQE_SIZE;
|
2014-03-18 11:19:07 +08:00
|
|
|
tgt->lcq_mem_size = (tgt->lcq_mem_size + (CNIC_PAGE_SIZE - 1)) &
|
|
|
|
CNIC_PAGE_MASK;
|
2011-02-05 04:10:34 +08:00
|
|
|
|
cross-tree: phase out dma_zalloc_coherent()
We already need to zero out memory for dma_alloc_coherent(), as such
using dma_zalloc_coherent() is superflous. Phase it out.
This change was generated with the following Coccinelle SmPL patch:
@ replace_dma_zalloc_coherent @
expression dev, size, data, handle, flags;
@@
-dma_zalloc_coherent(dev, size, handle, flags)
+dma_alloc_coherent(dev, size, handle, flags)
Suggested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
[hch: re-ran the script on the latest tree]
Signed-off-by: Christoph Hellwig <hch@lst.de>
2019-01-04 16:23:09 +08:00
|
|
|
tgt->lcq = dma_alloc_coherent(&hba->pcidev->dev, tgt->lcq_mem_size,
|
|
|
|
&tgt->lcq_dma, GFP_KERNEL);
|
2011-02-05 04:10:34 +08:00
|
|
|
|
|
|
|
if (!tgt->lcq) {
|
2011-06-28 14:30:53 +08:00
|
|
|
printk(KERN_ERR PFX "unable to allocate lcq %d\n",
|
2011-02-05 04:10:34 +08:00
|
|
|
tgt->lcq_mem_size);
|
|
|
|
goto mem_alloc_failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
tgt->conn_db->rq_prod = 0x8000;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
mem_alloc_failure:
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-03-03 22:46:21 +08:00
|
|
|
* bnx2fc_free_session_resc - free qp resources for the session
|
2011-02-05 04:10:34 +08:00
|
|
|
*
|
|
|
|
* @hba: adapter structure pointer
|
|
|
|
* @tgt: bnx2fc_rport structure pointer
|
|
|
|
*
|
|
|
|
* Free QP resources - SQ/RQ/CQ/XFERQ memory and PBL
|
|
|
|
*/
|
|
|
|
static void bnx2fc_free_session_resc(struct bnx2fc_hba *hba,
|
|
|
|
struct bnx2fc_rport *tgt)
|
|
|
|
{
|
2011-08-05 08:38:46 +08:00
|
|
|
void __iomem *ctx_base_ptr;
|
2011-02-05 04:10:34 +08:00
|
|
|
|
2011-08-05 08:38:46 +08:00
|
|
|
BNX2FC_TGT_DBG(tgt, "Freeing up session resources\n");
|
2011-06-14 19:33:44 +08:00
|
|
|
|
|
|
|
spin_lock_bh(&tgt->cq_lock);
|
2011-08-05 08:38:46 +08:00
|
|
|
ctx_base_ptr = tgt->ctx_base;
|
|
|
|
tgt->ctx_base = NULL;
|
|
|
|
|
2011-02-05 04:10:34 +08:00
|
|
|
/* Free LCQ */
|
|
|
|
if (tgt->lcq) {
|
|
|
|
dma_free_coherent(&hba->pcidev->dev, tgt->lcq_mem_size,
|
|
|
|
tgt->lcq, tgt->lcq_dma);
|
|
|
|
tgt->lcq = NULL;
|
|
|
|
}
|
|
|
|
/* Free connDB */
|
|
|
|
if (tgt->conn_db) {
|
|
|
|
dma_free_coherent(&hba->pcidev->dev, tgt->conn_db_mem_size,
|
|
|
|
tgt->conn_db, tgt->conn_db_dma);
|
|
|
|
tgt->conn_db = NULL;
|
|
|
|
}
|
|
|
|
/* Free confq and confq pbl */
|
|
|
|
if (tgt->confq_pbl) {
|
|
|
|
dma_free_coherent(&hba->pcidev->dev, tgt->confq_pbl_size,
|
|
|
|
tgt->confq_pbl, tgt->confq_pbl_dma);
|
|
|
|
tgt->confq_pbl = NULL;
|
|
|
|
}
|
|
|
|
if (tgt->confq) {
|
|
|
|
dma_free_coherent(&hba->pcidev->dev, tgt->confq_mem_size,
|
|
|
|
tgt->confq, tgt->confq_dma);
|
|
|
|
tgt->confq = NULL;
|
|
|
|
}
|
|
|
|
/* Free XFERQ */
|
|
|
|
if (tgt->xferq) {
|
|
|
|
dma_free_coherent(&hba->pcidev->dev, tgt->xferq_mem_size,
|
|
|
|
tgt->xferq, tgt->xferq_dma);
|
|
|
|
tgt->xferq = NULL;
|
|
|
|
}
|
|
|
|
/* Free RQ PBL and RQ */
|
|
|
|
if (tgt->rq_pbl) {
|
|
|
|
dma_free_coherent(&hba->pcidev->dev, tgt->rq_pbl_size,
|
|
|
|
tgt->rq_pbl, tgt->rq_pbl_dma);
|
|
|
|
tgt->rq_pbl = NULL;
|
|
|
|
}
|
|
|
|
if (tgt->rq) {
|
|
|
|
dma_free_coherent(&hba->pcidev->dev, tgt->rq_mem_size,
|
|
|
|
tgt->rq, tgt->rq_dma);
|
|
|
|
tgt->rq = NULL;
|
|
|
|
}
|
|
|
|
/* Free CQ */
|
|
|
|
if (tgt->cq) {
|
|
|
|
dma_free_coherent(&hba->pcidev->dev, tgt->cq_mem_size,
|
|
|
|
tgt->cq, tgt->cq_dma);
|
|
|
|
tgt->cq = NULL;
|
|
|
|
}
|
|
|
|
/* Free SQ */
|
|
|
|
if (tgt->sq) {
|
|
|
|
dma_free_coherent(&hba->pcidev->dev, tgt->sq_mem_size,
|
|
|
|
tgt->sq, tgt->sq_dma);
|
|
|
|
tgt->sq = NULL;
|
|
|
|
}
|
2011-06-14 19:33:44 +08:00
|
|
|
spin_unlock_bh(&tgt->cq_lock);
|
2011-08-05 08:38:46 +08:00
|
|
|
|
|
|
|
if (ctx_base_ptr)
|
|
|
|
iounmap(ctx_base_ptr);
|
2011-02-05 04:10:34 +08:00
|
|
|
}
|