Skip to content

Commit 3e33359

Browse files
Jakub Kicinskidavem330
authored andcommitted
nfp: register a notifier handler in a central location for the device
Code interested in networking events registers its own notifier handlers. Create one device-wide notifier instance. Signed-off-by: Jakub Kicinski <[email protected]> Reviewed-by: John Hurley <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 659bb40 commit 3e33359

File tree

2 files changed

+57
-15
lines changed

2 files changed

+57
-15
lines changed

drivers/net/ethernet/netronome/nfp/nfp_app.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,53 @@ nfp_app_reprs_set(struct nfp_app *app, enum nfp_repr_type type,
136136
return old;
137137
}
138138

139+
static int
140+
nfp_app_netdev_event(struct notifier_block *nb, unsigned long event, void *ptr)
141+
{
142+
struct net_device *netdev;
143+
struct nfp_app *app;
144+
145+
netdev = netdev_notifier_info_to_dev(ptr);
146+
app = container_of(nb, struct nfp_app, netdev_nb);
147+
148+
if (app->type->netdev_event)
149+
return app->type->netdev_event(app, netdev, event, ptr);
150+
return NOTIFY_DONE;
151+
}
152+
153+
int nfp_app_start(struct nfp_app *app, struct nfp_net *ctrl)
154+
{
155+
int err;
156+
157+
app->ctrl = ctrl;
158+
159+
if (app->type->start) {
160+
err = app->type->start(app);
161+
if (err)
162+
return err;
163+
}
164+
165+
app->netdev_nb.notifier_call = nfp_app_netdev_event;
166+
err = register_netdevice_notifier(&app->netdev_nb);
167+
if (err)
168+
goto err_app_stop;
169+
170+
return 0;
171+
172+
err_app_stop:
173+
if (app->type->stop)
174+
app->type->stop(app);
175+
return err;
176+
}
177+
178+
void nfp_app_stop(struct nfp_app *app)
179+
{
180+
unregister_netdevice_notifier(&app->netdev_nb);
181+
182+
if (app->type->stop)
183+
app->type->stop(app);
184+
}
185+
139186
struct nfp_app *nfp_app_alloc(struct nfp_pf *pf, enum nfp_app_id id)
140187
{
141188
struct nfp_app *app;

drivers/net/ethernet/netronome/nfp/nfp_app.h

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ extern const struct nfp_app_type app_abm;
6969
* @port_get_stats_strings: get strings for extra statistics
7070
* @start: start application logic
7171
* @stop: stop application logic
72+
* @netdev_event: Netdevice notifier event
7273
* @ctrl_msg_rx: control message handler
7374
* @ctrl_msg_rx_raw: handler for control messages from data queues
7475
* @setup_tc: setup TC ndo
@@ -122,6 +123,9 @@ struct nfp_app_type {
122123
int (*start)(struct nfp_app *app);
123124
void (*stop)(struct nfp_app *app);
124125

126+
int (*netdev_event)(struct nfp_app *app, struct net_device *netdev,
127+
unsigned long event, void *ptr);
128+
125129
void (*ctrl_msg_rx)(struct nfp_app *app, struct sk_buff *skb);
126130
void (*ctrl_msg_rx_raw)(struct nfp_app *app, const void *data,
127131
unsigned int len);
@@ -151,6 +155,7 @@ struct nfp_app_type {
151155
* @reprs: array of pointers to representors
152156
* @type: pointer to const application ops and info
153157
* @ctrl_mtu: MTU to set on the control vNIC (set in .init())
158+
* @netdev_nb: Netdevice notifier block
154159
* @priv: app-specific priv data
155160
*/
156161
struct nfp_app {
@@ -163,6 +168,9 @@ struct nfp_app {
163168

164169
const struct nfp_app_type *type;
165170
unsigned int ctrl_mtu;
171+
172+
struct notifier_block netdev_nb;
173+
166174
void *priv;
167175
};
168176

@@ -264,21 +272,6 @@ nfp_app_repr_change_mtu(struct nfp_app *app, struct net_device *netdev,
264272
return app->type->repr_change_mtu(app, netdev, new_mtu);
265273
}
266274

267-
static inline int nfp_app_start(struct nfp_app *app, struct nfp_net *ctrl)
268-
{
269-
app->ctrl = ctrl;
270-
if (!app->type->start)
271-
return 0;
272-
return app->type->start(app);
273-
}
274-
275-
static inline void nfp_app_stop(struct nfp_app *app)
276-
{
277-
if (!app->type->stop)
278-
return;
279-
app->type->stop(app);
280-
}
281-
282275
static inline const char *nfp_app_name(struct nfp_app *app)
283276
{
284277
if (!app)
@@ -430,6 +423,8 @@ nfp_app_ctrl_msg_alloc(struct nfp_app *app, unsigned int size, gfp_t priority);
430423

431424
struct nfp_app *nfp_app_alloc(struct nfp_pf *pf, enum nfp_app_id id);
432425
void nfp_app_free(struct nfp_app *app);
426+
int nfp_app_start(struct nfp_app *app, struct nfp_net *ctrl);
427+
void nfp_app_stop(struct nfp_app *app);
433428

434429
/* Callbacks shared between apps */
435430

0 commit comments

Comments
 (0)