xref: /linux/net/ncsi/ncsi-rsp.c (revision 9771b8ccdfa6dcb1ac5128ca7fe8649f3092d392)
1 /*
2  * Copyright Gavin Shan, IBM Corporation 2016.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  */
9 
10 #include <linux/module.h>
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/netdevice.h>
14 #include <linux/skbuff.h>
15 
16 #include <net/ncsi.h>
17 #include <net/net_namespace.h>
18 #include <net/sock.h>
19 #include <net/genetlink.h>
20 
21 #include "internal.h"
22 #include "ncsi-pkt.h"
23 #include "ncsi-netlink.h"
24 
25 static int ncsi_validate_rsp_pkt(struct ncsi_request *nr,
26 				 unsigned short payload)
27 {
28 	struct ncsi_rsp_pkt_hdr *h;
29 	u32 checksum;
30 	__be32 *pchecksum;
31 
32 	/* Check NCSI packet header. We don't need validate
33 	 * the packet type, which should have been checked
34 	 * before calling this function.
35 	 */
36 	h = (struct ncsi_rsp_pkt_hdr *)skb_network_header(nr->rsp);
37 
38 	if (h->common.revision != NCSI_PKT_REVISION) {
39 		netdev_dbg(nr->ndp->ndev.dev,
40 			   "NCSI: unsupported header revision\n");
41 		return -EINVAL;
42 	}
43 	if (ntohs(h->common.length) != payload) {
44 		netdev_dbg(nr->ndp->ndev.dev,
45 			   "NCSI: payload length mismatched\n");
46 		return -EINVAL;
47 	}
48 
49 	/* Check on code and reason */
50 	if (ntohs(h->code) != NCSI_PKT_RSP_C_COMPLETED ||
51 	    ntohs(h->reason) != NCSI_PKT_RSP_R_NO_ERROR) {
52 		netdev_dbg(nr->ndp->ndev.dev,
53 			   "NCSI: non zero response/reason code\n");
54 		return -EPERM;
55 	}
56 
57 	/* Validate checksum, which might be zeroes if the
58 	 * sender doesn't support checksum according to NCSI
59 	 * specification.
60 	 */
61 	pchecksum = (__be32 *)((void *)(h + 1) + payload - 4);
62 	if (ntohl(*pchecksum) == 0)
63 		return 0;
64 
65 	checksum = ncsi_calculate_checksum((unsigned char *)h,
66 					   sizeof(*h) + payload - 4);
67 
68 	if (*pchecksum != htonl(checksum)) {
69 		netdev_dbg(nr->ndp->ndev.dev, "NCSI: checksum mismatched\n");
70 		return -EINVAL;
71 	}
72 
73 	return 0;
74 }
75 
76 static int ncsi_rsp_handler_cis(struct ncsi_request *nr)
77 {
78 	struct ncsi_rsp_pkt *rsp;
79 	struct ncsi_dev_priv *ndp = nr->ndp;
80 	struct ncsi_package *np;
81 	struct ncsi_channel *nc;
82 	unsigned char id;
83 
84 	rsp = (struct ncsi_rsp_pkt *)skb_network_header(nr->rsp);
85 	ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel, &np, &nc);
86 	if (!nc) {
87 		if (ndp->flags & NCSI_DEV_PROBED)
88 			return -ENXIO;
89 
90 		id = NCSI_CHANNEL_INDEX(rsp->rsp.common.channel);
91 		nc = ncsi_add_channel(np, id);
92 	}
93 
94 	return nc ? 0 : -ENODEV;
95 }
96 
97 static int ncsi_rsp_handler_sp(struct ncsi_request *nr)
98 {
99 	struct ncsi_rsp_pkt *rsp;
100 	struct ncsi_dev_priv *ndp = nr->ndp;
101 	struct ncsi_package *np;
102 	unsigned char id;
103 
104 	/* Add the package if it's not existing. Otherwise,
105 	 * to change the state of its child channels.
106 	 */
107 	rsp = (struct ncsi_rsp_pkt *)skb_network_header(nr->rsp);
108 	ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
109 				      &np, NULL);
110 	if (!np) {
111 		if (ndp->flags & NCSI_DEV_PROBED)
112 			return -ENXIO;
113 
114 		id = NCSI_PACKAGE_INDEX(rsp->rsp.common.channel);
115 		np = ncsi_add_package(ndp, id);
116 		if (!np)
117 			return -ENODEV;
118 	}
119 
120 	return 0;
121 }
122 
123 static int ncsi_rsp_handler_dp(struct ncsi_request *nr)
124 {
125 	struct ncsi_rsp_pkt *rsp;
126 	struct ncsi_dev_priv *ndp = nr->ndp;
127 	struct ncsi_package *np;
128 	struct ncsi_channel *nc;
129 	unsigned long flags;
130 
131 	/* Find the package */
132 	rsp = (struct ncsi_rsp_pkt *)skb_network_header(nr->rsp);
133 	ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
134 				      &np, NULL);
135 	if (!np)
136 		return -ENODEV;
137 
138 	/* Change state of all channels attached to the package */
139 	NCSI_FOR_EACH_CHANNEL(np, nc) {
140 		spin_lock_irqsave(&nc->lock, flags);
141 		nc->state = NCSI_CHANNEL_INACTIVE;
142 		spin_unlock_irqrestore(&nc->lock, flags);
143 	}
144 
145 	return 0;
146 }
147 
148 static int ncsi_rsp_handler_ec(struct ncsi_request *nr)
149 {
150 	struct ncsi_rsp_pkt *rsp;
151 	struct ncsi_dev_priv *ndp = nr->ndp;
152 	struct ncsi_channel *nc;
153 	struct ncsi_channel_mode *ncm;
154 
155 	/* Find the package and channel */
156 	rsp = (struct ncsi_rsp_pkt *)skb_network_header(nr->rsp);
157 	ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
158 				      NULL, &nc);
159 	if (!nc)
160 		return -ENODEV;
161 
162 	ncm = &nc->modes[NCSI_MODE_ENABLE];
163 	if (ncm->enable)
164 		return 0;
165 
166 	ncm->enable = 1;
167 	return 0;
168 }
169 
170 static int ncsi_rsp_handler_dc(struct ncsi_request *nr)
171 {
172 	struct ncsi_rsp_pkt *rsp;
173 	struct ncsi_dev_priv *ndp = nr->ndp;
174 	struct ncsi_channel *nc;
175 	struct ncsi_channel_mode *ncm;
176 	int ret;
177 
178 	ret = ncsi_validate_rsp_pkt(nr, 4);
179 	if (ret)
180 		return ret;
181 
182 	/* Find the package and channel */
183 	rsp = (struct ncsi_rsp_pkt *)skb_network_header(nr->rsp);
184 	ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
185 				      NULL, &nc);
186 	if (!nc)
187 		return -ENODEV;
188 
189 	ncm = &nc->modes[NCSI_MODE_ENABLE];
190 	if (!ncm->enable)
191 		return 0;
192 
193 	ncm->enable = 0;
194 	return 0;
195 }
196 
197 static int ncsi_rsp_handler_rc(struct ncsi_request *nr)
198 {
199 	struct ncsi_rsp_pkt *rsp;
200 	struct ncsi_dev_priv *ndp = nr->ndp;
201 	struct ncsi_channel *nc;
202 	unsigned long flags;
203 
204 	/* Find the package and channel */
205 	rsp = (struct ncsi_rsp_pkt *)skb_network_header(nr->rsp);
206 	ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
207 				      NULL, &nc);
208 	if (!nc)
209 		return -ENODEV;
210 
211 	/* Update state for the specified channel */
212 	spin_lock_irqsave(&nc->lock, flags);
213 	nc->state = NCSI_CHANNEL_INACTIVE;
214 	spin_unlock_irqrestore(&nc->lock, flags);
215 
216 	return 0;
217 }
218 
219 static int ncsi_rsp_handler_ecnt(struct ncsi_request *nr)
220 {
221 	struct ncsi_rsp_pkt *rsp;
222 	struct ncsi_dev_priv *ndp = nr->ndp;
223 	struct ncsi_channel *nc;
224 	struct ncsi_channel_mode *ncm;
225 
226 	/* Find the package and channel */
227 	rsp = (struct ncsi_rsp_pkt *)skb_network_header(nr->rsp);
228 	ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
229 				      NULL, &nc);
230 	if (!nc)
231 		return -ENODEV;
232 
233 	ncm = &nc->modes[NCSI_MODE_TX_ENABLE];
234 	if (ncm->enable)
235 		return 0;
236 
237 	ncm->enable = 1;
238 	return 0;
239 }
240 
241 static int ncsi_rsp_handler_dcnt(struct ncsi_request *nr)
242 {
243 	struct ncsi_rsp_pkt *rsp;
244 	struct ncsi_dev_priv *ndp = nr->ndp;
245 	struct ncsi_channel *nc;
246 	struct ncsi_channel_mode *ncm;
247 
248 	/* Find the package and channel */
249 	rsp = (struct ncsi_rsp_pkt *)skb_network_header(nr->rsp);
250 	ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
251 				      NULL, &nc);
252 	if (!nc)
253 		return -ENODEV;
254 
255 	ncm = &nc->modes[NCSI_MODE_TX_ENABLE];
256 	if (!ncm->enable)
257 		return 0;
258 
259 	ncm->enable = 1;
260 	return 0;
261 }
262 
263 static int ncsi_rsp_handler_ae(struct ncsi_request *nr)
264 {
265 	struct ncsi_cmd_ae_pkt *cmd;
266 	struct ncsi_rsp_pkt *rsp;
267 	struct ncsi_dev_priv *ndp = nr->ndp;
268 	struct ncsi_channel *nc;
269 	struct ncsi_channel_mode *ncm;
270 
271 	/* Find the package and channel */
272 	rsp = (struct ncsi_rsp_pkt *)skb_network_header(nr->rsp);
273 	ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
274 				      NULL, &nc);
275 	if (!nc)
276 		return -ENODEV;
277 
278 	/* Check if the AEN has been enabled */
279 	ncm = &nc->modes[NCSI_MODE_AEN];
280 	if (ncm->enable)
281 		return 0;
282 
283 	/* Update to AEN configuration */
284 	cmd = (struct ncsi_cmd_ae_pkt *)skb_network_header(nr->cmd);
285 	ncm->enable = 1;
286 	ncm->data[0] = cmd->mc_id;
287 	ncm->data[1] = ntohl(cmd->mode);
288 
289 	return 0;
290 }
291 
292 static int ncsi_rsp_handler_sl(struct ncsi_request *nr)
293 {
294 	struct ncsi_cmd_sl_pkt *cmd;
295 	struct ncsi_rsp_pkt *rsp;
296 	struct ncsi_dev_priv *ndp = nr->ndp;
297 	struct ncsi_channel *nc;
298 	struct ncsi_channel_mode *ncm;
299 
300 	/* Find the package and channel */
301 	rsp = (struct ncsi_rsp_pkt *)skb_network_header(nr->rsp);
302 	ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
303 				      NULL, &nc);
304 	if (!nc)
305 		return -ENODEV;
306 
307 	cmd = (struct ncsi_cmd_sl_pkt *)skb_network_header(nr->cmd);
308 	ncm = &nc->modes[NCSI_MODE_LINK];
309 	ncm->data[0] = ntohl(cmd->mode);
310 	ncm->data[1] = ntohl(cmd->oem_mode);
311 
312 	return 0;
313 }
314 
315 static int ncsi_rsp_handler_gls(struct ncsi_request *nr)
316 {
317 	struct ncsi_rsp_gls_pkt *rsp;
318 	struct ncsi_dev_priv *ndp = nr->ndp;
319 	struct ncsi_channel *nc;
320 	struct ncsi_channel_mode *ncm;
321 	unsigned long flags;
322 
323 	/* Find the package and channel */
324 	rsp = (struct ncsi_rsp_gls_pkt *)skb_network_header(nr->rsp);
325 	ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
326 				      NULL, &nc);
327 	if (!nc)
328 		return -ENODEV;
329 
330 	ncm = &nc->modes[NCSI_MODE_LINK];
331 	ncm->data[2] = ntohl(rsp->status);
332 	ncm->data[3] = ntohl(rsp->other);
333 	ncm->data[4] = ntohl(rsp->oem_status);
334 
335 	if (nr->flags & NCSI_REQ_FLAG_EVENT_DRIVEN)
336 		return 0;
337 
338 	/* Reset the channel monitor if it has been enabled */
339 	spin_lock_irqsave(&nc->lock, flags);
340 	nc->monitor.state = NCSI_CHANNEL_MONITOR_START;
341 	spin_unlock_irqrestore(&nc->lock, flags);
342 
343 	return 0;
344 }
345 
346 static int ncsi_rsp_handler_svf(struct ncsi_request *nr)
347 {
348 	struct ncsi_cmd_svf_pkt *cmd;
349 	struct ncsi_rsp_pkt *rsp;
350 	struct ncsi_dev_priv *ndp = nr->ndp;
351 	struct ncsi_channel *nc;
352 	struct ncsi_channel_vlan_filter *ncf;
353 	unsigned long flags;
354 	void *bitmap;
355 
356 	/* Find the package and channel */
357 	rsp = (struct ncsi_rsp_pkt *)skb_network_header(nr->rsp);
358 	ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
359 				      NULL, &nc);
360 	if (!nc)
361 		return -ENODEV;
362 
363 	cmd = (struct ncsi_cmd_svf_pkt *)skb_network_header(nr->cmd);
364 	ncf = &nc->vlan_filter;
365 	if (cmd->index == 0 || cmd->index > ncf->n_vids)
366 		return -ERANGE;
367 
368 	/* Add or remove the VLAN filter. Remember HW indexes from 1 */
369 	spin_lock_irqsave(&nc->lock, flags);
370 	bitmap = &ncf->bitmap;
371 	if (!(cmd->enable & 0x1)) {
372 		if (test_and_clear_bit(cmd->index - 1, bitmap))
373 			ncf->vids[cmd->index - 1] = 0;
374 	} else {
375 		set_bit(cmd->index - 1, bitmap);
376 		ncf->vids[cmd->index - 1] = ntohs(cmd->vlan);
377 	}
378 	spin_unlock_irqrestore(&nc->lock, flags);
379 
380 	return 0;
381 }
382 
383 static int ncsi_rsp_handler_ev(struct ncsi_request *nr)
384 {
385 	struct ncsi_cmd_ev_pkt *cmd;
386 	struct ncsi_rsp_pkt *rsp;
387 	struct ncsi_dev_priv *ndp = nr->ndp;
388 	struct ncsi_channel *nc;
389 	struct ncsi_channel_mode *ncm;
390 
391 	/* Find the package and channel */
392 	rsp = (struct ncsi_rsp_pkt *)skb_network_header(nr->rsp);
393 	ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
394 				      NULL, &nc);
395 	if (!nc)
396 		return -ENODEV;
397 
398 	/* Check if VLAN mode has been enabled */
399 	ncm = &nc->modes[NCSI_MODE_VLAN];
400 	if (ncm->enable)
401 		return 0;
402 
403 	/* Update to VLAN mode */
404 	cmd = (struct ncsi_cmd_ev_pkt *)skb_network_header(nr->cmd);
405 	ncm->enable = 1;
406 	ncm->data[0] = ntohl(cmd->mode);
407 
408 	return 0;
409 }
410 
411 static int ncsi_rsp_handler_dv(struct ncsi_request *nr)
412 {
413 	struct ncsi_rsp_pkt *rsp;
414 	struct ncsi_dev_priv *ndp = nr->ndp;
415 	struct ncsi_channel *nc;
416 	struct ncsi_channel_mode *ncm;
417 
418 	/* Find the package and channel */
419 	rsp = (struct ncsi_rsp_pkt *)skb_network_header(nr->rsp);
420 	ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
421 				      NULL, &nc);
422 	if (!nc)
423 		return -ENODEV;
424 
425 	/* Check if VLAN mode has been enabled */
426 	ncm = &nc->modes[NCSI_MODE_VLAN];
427 	if (!ncm->enable)
428 		return 0;
429 
430 	/* Update to VLAN mode */
431 	ncm->enable = 0;
432 	return 0;
433 }
434 
435 static int ncsi_rsp_handler_sma(struct ncsi_request *nr)
436 {
437 	struct ncsi_cmd_sma_pkt *cmd;
438 	struct ncsi_rsp_pkt *rsp;
439 	struct ncsi_dev_priv *ndp = nr->ndp;
440 	struct ncsi_channel *nc;
441 	struct ncsi_channel_mac_filter *ncf;
442 	unsigned long flags;
443 	void *bitmap;
444 	bool enabled;
445 	int index;
446 
447 
448 	/* Find the package and channel */
449 	rsp = (struct ncsi_rsp_pkt *)skb_network_header(nr->rsp);
450 	ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
451 				      NULL, &nc);
452 	if (!nc)
453 		return -ENODEV;
454 
455 	/* According to NCSI spec 1.01, the mixed filter table
456 	 * isn't supported yet.
457 	 */
458 	cmd = (struct ncsi_cmd_sma_pkt *)skb_network_header(nr->cmd);
459 	enabled = cmd->at_e & 0x1;
460 	ncf = &nc->mac_filter;
461 	bitmap = &ncf->bitmap;
462 
463 	if (cmd->index == 0 ||
464 	    cmd->index > ncf->n_uc + ncf->n_mc + ncf->n_mixed)
465 		return -ERANGE;
466 
467 	index = (cmd->index - 1) * ETH_ALEN;
468 	spin_lock_irqsave(&nc->lock, flags);
469 	if (enabled) {
470 		set_bit(cmd->index - 1, bitmap);
471 		memcpy(&ncf->addrs[index], cmd->mac, ETH_ALEN);
472 	} else {
473 		clear_bit(cmd->index - 1, bitmap);
474 		memset(&ncf->addrs[index], 0, ETH_ALEN);
475 	}
476 	spin_unlock_irqrestore(&nc->lock, flags);
477 
478 	return 0;
479 }
480 
481 static int ncsi_rsp_handler_ebf(struct ncsi_request *nr)
482 {
483 	struct ncsi_cmd_ebf_pkt *cmd;
484 	struct ncsi_rsp_pkt *rsp;
485 	struct ncsi_dev_priv *ndp = nr->ndp;
486 	struct ncsi_channel *nc;
487 	struct ncsi_channel_mode *ncm;
488 
489 	/* Find the package and channel */
490 	rsp = (struct ncsi_rsp_pkt *)skb_network_header(nr->rsp);
491 	ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel, NULL, &nc);
492 	if (!nc)
493 		return -ENODEV;
494 
495 	/* Check if broadcast filter has been enabled */
496 	ncm = &nc->modes[NCSI_MODE_BC];
497 	if (ncm->enable)
498 		return 0;
499 
500 	/* Update to broadcast filter mode */
501 	cmd = (struct ncsi_cmd_ebf_pkt *)skb_network_header(nr->cmd);
502 	ncm->enable = 1;
503 	ncm->data[0] = ntohl(cmd->mode);
504 
505 	return 0;
506 }
507 
508 static int ncsi_rsp_handler_dbf(struct ncsi_request *nr)
509 {
510 	struct ncsi_rsp_pkt *rsp;
511 	struct ncsi_dev_priv *ndp = nr->ndp;
512 	struct ncsi_channel *nc;
513 	struct ncsi_channel_mode *ncm;
514 
515 	rsp = (struct ncsi_rsp_pkt *)skb_network_header(nr->rsp);
516 	ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
517 				      NULL, &nc);
518 	if (!nc)
519 		return -ENODEV;
520 
521 	/* Check if broadcast filter isn't enabled */
522 	ncm = &nc->modes[NCSI_MODE_BC];
523 	if (!ncm->enable)
524 		return 0;
525 
526 	/* Update to broadcast filter mode */
527 	ncm->enable = 0;
528 	ncm->data[0] = 0;
529 
530 	return 0;
531 }
532 
533 static int ncsi_rsp_handler_egmf(struct ncsi_request *nr)
534 {
535 	struct ncsi_cmd_egmf_pkt *cmd;
536 	struct ncsi_rsp_pkt *rsp;
537 	struct ncsi_dev_priv *ndp = nr->ndp;
538 	struct ncsi_channel *nc;
539 	struct ncsi_channel_mode *ncm;
540 
541 	/* Find the channel */
542 	rsp = (struct ncsi_rsp_pkt *)skb_network_header(nr->rsp);
543 	ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
544 				      NULL, &nc);
545 	if (!nc)
546 		return -ENODEV;
547 
548 	/* Check if multicast filter has been enabled */
549 	ncm = &nc->modes[NCSI_MODE_MC];
550 	if (ncm->enable)
551 		return 0;
552 
553 	/* Update to multicast filter mode */
554 	cmd = (struct ncsi_cmd_egmf_pkt *)skb_network_header(nr->cmd);
555 	ncm->enable = 1;
556 	ncm->data[0] = ntohl(cmd->mode);
557 
558 	return 0;
559 }
560 
561 static int ncsi_rsp_handler_dgmf(struct ncsi_request *nr)
562 {
563 	struct ncsi_rsp_pkt *rsp;
564 	struct ncsi_dev_priv *ndp = nr->ndp;
565 	struct ncsi_channel *nc;
566 	struct ncsi_channel_mode *ncm;
567 
568 	rsp = (struct ncsi_rsp_pkt *)skb_network_header(nr->rsp);
569 	ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
570 				      NULL, &nc);
571 	if (!nc)
572 		return -ENODEV;
573 
574 	/* Check if multicast filter has been enabled */
575 	ncm = &nc->modes[NCSI_MODE_MC];
576 	if (!ncm->enable)
577 		return 0;
578 
579 	/* Update to multicast filter mode */
580 	ncm->enable = 0;
581 	ncm->data[0] = 0;
582 
583 	return 0;
584 }
585 
586 static int ncsi_rsp_handler_snfc(struct ncsi_request *nr)
587 {
588 	struct ncsi_cmd_snfc_pkt *cmd;
589 	struct ncsi_rsp_pkt *rsp;
590 	struct ncsi_dev_priv *ndp = nr->ndp;
591 	struct ncsi_channel *nc;
592 	struct ncsi_channel_mode *ncm;
593 
594 	/* Find the channel */
595 	rsp = (struct ncsi_rsp_pkt *)skb_network_header(nr->rsp);
596 	ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
597 				      NULL, &nc);
598 	if (!nc)
599 		return -ENODEV;
600 
601 	/* Check if flow control has been enabled */
602 	ncm = &nc->modes[NCSI_MODE_FC];
603 	if (ncm->enable)
604 		return 0;
605 
606 	/* Update to flow control mode */
607 	cmd = (struct ncsi_cmd_snfc_pkt *)skb_network_header(nr->cmd);
608 	ncm->enable = 1;
609 	ncm->data[0] = cmd->mode;
610 
611 	return 0;
612 }
613 
614 static struct ncsi_rsp_oem_handler {
615 	unsigned int	mfr_id;
616 	int		(*handler)(struct ncsi_request *nr);
617 } ncsi_rsp_oem_handlers[] = {
618 	{ NCSI_OEM_MFR_MLX_ID, NULL },
619 	{ NCSI_OEM_MFR_BCM_ID, NULL }
620 };
621 
622 /* Response handler for OEM command */
623 static int ncsi_rsp_handler_oem(struct ncsi_request *nr)
624 {
625 	struct ncsi_rsp_oem_pkt *rsp;
626 	struct ncsi_rsp_oem_handler *nrh = NULL;
627 	unsigned int mfr_id, i;
628 
629 	/* Get the response header */
630 	rsp = (struct ncsi_rsp_oem_pkt *)skb_network_header(nr->rsp);
631 	mfr_id = ntohl(rsp->mfr_id);
632 
633 	/* Check for manufacturer id and Find the handler */
634 	for (i = 0; i < ARRAY_SIZE(ncsi_rsp_oem_handlers); i++) {
635 		if (ncsi_rsp_oem_handlers[i].mfr_id == mfr_id) {
636 			if (ncsi_rsp_oem_handlers[i].handler)
637 				nrh = &ncsi_rsp_oem_handlers[i];
638 			else
639 				nrh = NULL;
640 
641 			break;
642 		}
643 	}
644 
645 	if (!nrh) {
646 		netdev_err(nr->ndp->ndev.dev, "Received unrecognized OEM packet with MFR-ID (0x%x)\n",
647 			   mfr_id);
648 		return -ENOENT;
649 	}
650 
651 	/* Process the packet */
652 	return nrh->handler(nr);
653 }
654 
655 static int ncsi_rsp_handler_gvi(struct ncsi_request *nr)
656 {
657 	struct ncsi_rsp_gvi_pkt *rsp;
658 	struct ncsi_dev_priv *ndp = nr->ndp;
659 	struct ncsi_channel *nc;
660 	struct ncsi_channel_version *ncv;
661 	int i;
662 
663 	/* Find the channel */
664 	rsp = (struct ncsi_rsp_gvi_pkt *)skb_network_header(nr->rsp);
665 	ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
666 				      NULL, &nc);
667 	if (!nc)
668 		return -ENODEV;
669 
670 	/* Update to channel's version info */
671 	ncv = &nc->version;
672 	ncv->version = ntohl(rsp->ncsi_version);
673 	ncv->alpha2 = rsp->alpha2;
674 	memcpy(ncv->fw_name, rsp->fw_name, 12);
675 	ncv->fw_version = ntohl(rsp->fw_version);
676 	for (i = 0; i < ARRAY_SIZE(ncv->pci_ids); i++)
677 		ncv->pci_ids[i] = ntohs(rsp->pci_ids[i]);
678 	ncv->mf_id = ntohl(rsp->mf_id);
679 
680 	return 0;
681 }
682 
683 static int ncsi_rsp_handler_gc(struct ncsi_request *nr)
684 {
685 	struct ncsi_rsp_gc_pkt *rsp;
686 	struct ncsi_dev_priv *ndp = nr->ndp;
687 	struct ncsi_channel *nc;
688 	size_t size;
689 
690 	/* Find the channel */
691 	rsp = (struct ncsi_rsp_gc_pkt *)skb_network_header(nr->rsp);
692 	ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
693 				      NULL, &nc);
694 	if (!nc)
695 		return -ENODEV;
696 
697 	/* Update channel's capabilities */
698 	nc->caps[NCSI_CAP_GENERIC].cap = ntohl(rsp->cap) &
699 					 NCSI_CAP_GENERIC_MASK;
700 	nc->caps[NCSI_CAP_BC].cap = ntohl(rsp->bc_cap) &
701 				    NCSI_CAP_BC_MASK;
702 	nc->caps[NCSI_CAP_MC].cap = ntohl(rsp->mc_cap) &
703 				    NCSI_CAP_MC_MASK;
704 	nc->caps[NCSI_CAP_BUFFER].cap = ntohl(rsp->buf_cap);
705 	nc->caps[NCSI_CAP_AEN].cap = ntohl(rsp->aen_cap) &
706 				     NCSI_CAP_AEN_MASK;
707 	nc->caps[NCSI_CAP_VLAN].cap = rsp->vlan_mode &
708 				      NCSI_CAP_VLAN_MASK;
709 
710 	size = (rsp->uc_cnt + rsp->mc_cnt + rsp->mixed_cnt) * ETH_ALEN;
711 	nc->mac_filter.addrs = kzalloc(size, GFP_ATOMIC);
712 	if (!nc->mac_filter.addrs)
713 		return -ENOMEM;
714 	nc->mac_filter.n_uc = rsp->uc_cnt;
715 	nc->mac_filter.n_mc = rsp->mc_cnt;
716 	nc->mac_filter.n_mixed = rsp->mixed_cnt;
717 
718 	nc->vlan_filter.vids = kcalloc(rsp->vlan_cnt,
719 				       sizeof(*nc->vlan_filter.vids),
720 				       GFP_ATOMIC);
721 	if (!nc->vlan_filter.vids)
722 		return -ENOMEM;
723 	/* Set VLAN filters active so they are cleared in the first
724 	 * configuration state
725 	 */
726 	nc->vlan_filter.bitmap = U64_MAX;
727 	nc->vlan_filter.n_vids = rsp->vlan_cnt;
728 
729 	return 0;
730 }
731 
732 static int ncsi_rsp_handler_gp(struct ncsi_request *nr)
733 {
734 	struct ncsi_channel_vlan_filter *ncvf;
735 	struct ncsi_channel_mac_filter *ncmf;
736 	struct ncsi_dev_priv *ndp = nr->ndp;
737 	struct ncsi_rsp_gp_pkt *rsp;
738 	struct ncsi_channel *nc;
739 	unsigned short enable;
740 	unsigned char *pdata;
741 	unsigned long flags;
742 	void *bitmap;
743 	int i;
744 
745 	/* Find the channel */
746 	rsp = (struct ncsi_rsp_gp_pkt *)skb_network_header(nr->rsp);
747 	ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
748 				      NULL, &nc);
749 	if (!nc)
750 		return -ENODEV;
751 
752 	/* Modes with explicit enabled indications */
753 	if (ntohl(rsp->valid_modes) & 0x1) {	/* BC filter mode */
754 		nc->modes[NCSI_MODE_BC].enable = 1;
755 		nc->modes[NCSI_MODE_BC].data[0] = ntohl(rsp->bc_mode);
756 	}
757 	if (ntohl(rsp->valid_modes) & 0x2)	/* Channel enabled */
758 		nc->modes[NCSI_MODE_ENABLE].enable = 1;
759 	if (ntohl(rsp->valid_modes) & 0x4)	/* Channel Tx enabled */
760 		nc->modes[NCSI_MODE_TX_ENABLE].enable = 1;
761 	if (ntohl(rsp->valid_modes) & 0x8)	/* MC filter mode */
762 		nc->modes[NCSI_MODE_MC].enable = 1;
763 
764 	/* Modes without explicit enabled indications */
765 	nc->modes[NCSI_MODE_LINK].enable = 1;
766 	nc->modes[NCSI_MODE_LINK].data[0] = ntohl(rsp->link_mode);
767 	nc->modes[NCSI_MODE_VLAN].enable = 1;
768 	nc->modes[NCSI_MODE_VLAN].data[0] = rsp->vlan_mode;
769 	nc->modes[NCSI_MODE_FC].enable = 1;
770 	nc->modes[NCSI_MODE_FC].data[0] = rsp->fc_mode;
771 	nc->modes[NCSI_MODE_AEN].enable = 1;
772 	nc->modes[NCSI_MODE_AEN].data[0] = ntohl(rsp->aen_mode);
773 
774 	/* MAC addresses filter table */
775 	pdata = (unsigned char *)rsp + 48;
776 	enable = rsp->mac_enable;
777 	ncmf = &nc->mac_filter;
778 	spin_lock_irqsave(&nc->lock, flags);
779 	bitmap = &ncmf->bitmap;
780 	for (i = 0; i < rsp->mac_cnt; i++, pdata += 6) {
781 		if (!(enable & (0x1 << i)))
782 			clear_bit(i, bitmap);
783 		else
784 			set_bit(i, bitmap);
785 
786 		memcpy(&ncmf->addrs[i * ETH_ALEN], pdata, ETH_ALEN);
787 	}
788 	spin_unlock_irqrestore(&nc->lock, flags);
789 
790 	/* VLAN filter table */
791 	enable = ntohs(rsp->vlan_enable);
792 	ncvf = &nc->vlan_filter;
793 	bitmap = &ncvf->bitmap;
794 	spin_lock_irqsave(&nc->lock, flags);
795 	for (i = 0; i < rsp->vlan_cnt; i++, pdata += 2) {
796 		if (!(enable & (0x1 << i)))
797 			clear_bit(i, bitmap);
798 		else
799 			set_bit(i, bitmap);
800 
801 		ncvf->vids[i] = ntohs(*(__be16 *)pdata);
802 	}
803 	spin_unlock_irqrestore(&nc->lock, flags);
804 
805 	return 0;
806 }
807 
808 static int ncsi_rsp_handler_gcps(struct ncsi_request *nr)
809 {
810 	struct ncsi_rsp_gcps_pkt *rsp;
811 	struct ncsi_dev_priv *ndp = nr->ndp;
812 	struct ncsi_channel *nc;
813 	struct ncsi_channel_stats *ncs;
814 
815 	/* Find the channel */
816 	rsp = (struct ncsi_rsp_gcps_pkt *)skb_network_header(nr->rsp);
817 	ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
818 				      NULL, &nc);
819 	if (!nc)
820 		return -ENODEV;
821 
822 	/* Update HNC's statistics */
823 	ncs = &nc->stats;
824 	ncs->hnc_cnt_hi         = ntohl(rsp->cnt_hi);
825 	ncs->hnc_cnt_lo         = ntohl(rsp->cnt_lo);
826 	ncs->hnc_rx_bytes       = ntohl(rsp->rx_bytes);
827 	ncs->hnc_tx_bytes       = ntohl(rsp->tx_bytes);
828 	ncs->hnc_rx_uc_pkts     = ntohl(rsp->rx_uc_pkts);
829 	ncs->hnc_rx_mc_pkts     = ntohl(rsp->rx_mc_pkts);
830 	ncs->hnc_rx_bc_pkts     = ntohl(rsp->rx_bc_pkts);
831 	ncs->hnc_tx_uc_pkts     = ntohl(rsp->tx_uc_pkts);
832 	ncs->hnc_tx_mc_pkts     = ntohl(rsp->tx_mc_pkts);
833 	ncs->hnc_tx_bc_pkts     = ntohl(rsp->tx_bc_pkts);
834 	ncs->hnc_fcs_err        = ntohl(rsp->fcs_err);
835 	ncs->hnc_align_err      = ntohl(rsp->align_err);
836 	ncs->hnc_false_carrier  = ntohl(rsp->false_carrier);
837 	ncs->hnc_runt_pkts      = ntohl(rsp->runt_pkts);
838 	ncs->hnc_jabber_pkts    = ntohl(rsp->jabber_pkts);
839 	ncs->hnc_rx_pause_xon   = ntohl(rsp->rx_pause_xon);
840 	ncs->hnc_rx_pause_xoff  = ntohl(rsp->rx_pause_xoff);
841 	ncs->hnc_tx_pause_xon   = ntohl(rsp->tx_pause_xon);
842 	ncs->hnc_tx_pause_xoff  = ntohl(rsp->tx_pause_xoff);
843 	ncs->hnc_tx_s_collision = ntohl(rsp->tx_s_collision);
844 	ncs->hnc_tx_m_collision = ntohl(rsp->tx_m_collision);
845 	ncs->hnc_l_collision    = ntohl(rsp->l_collision);
846 	ncs->hnc_e_collision    = ntohl(rsp->e_collision);
847 	ncs->hnc_rx_ctl_frames  = ntohl(rsp->rx_ctl_frames);
848 	ncs->hnc_rx_64_frames   = ntohl(rsp->rx_64_frames);
849 	ncs->hnc_rx_127_frames  = ntohl(rsp->rx_127_frames);
850 	ncs->hnc_rx_255_frames  = ntohl(rsp->rx_255_frames);
851 	ncs->hnc_rx_511_frames  = ntohl(rsp->rx_511_frames);
852 	ncs->hnc_rx_1023_frames = ntohl(rsp->rx_1023_frames);
853 	ncs->hnc_rx_1522_frames = ntohl(rsp->rx_1522_frames);
854 	ncs->hnc_rx_9022_frames = ntohl(rsp->rx_9022_frames);
855 	ncs->hnc_tx_64_frames   = ntohl(rsp->tx_64_frames);
856 	ncs->hnc_tx_127_frames  = ntohl(rsp->tx_127_frames);
857 	ncs->hnc_tx_255_frames  = ntohl(rsp->tx_255_frames);
858 	ncs->hnc_tx_511_frames  = ntohl(rsp->tx_511_frames);
859 	ncs->hnc_tx_1023_frames = ntohl(rsp->tx_1023_frames);
860 	ncs->hnc_tx_1522_frames = ntohl(rsp->tx_1522_frames);
861 	ncs->hnc_tx_9022_frames = ntohl(rsp->tx_9022_frames);
862 	ncs->hnc_rx_valid_bytes = ntohl(rsp->rx_valid_bytes);
863 	ncs->hnc_rx_runt_pkts   = ntohl(rsp->rx_runt_pkts);
864 	ncs->hnc_rx_jabber_pkts = ntohl(rsp->rx_jabber_pkts);
865 
866 	return 0;
867 }
868 
869 static int ncsi_rsp_handler_gns(struct ncsi_request *nr)
870 {
871 	struct ncsi_rsp_gns_pkt *rsp;
872 	struct ncsi_dev_priv *ndp = nr->ndp;
873 	struct ncsi_channel *nc;
874 	struct ncsi_channel_stats *ncs;
875 
876 	/* Find the channel */
877 	rsp = (struct ncsi_rsp_gns_pkt *)skb_network_header(nr->rsp);
878 	ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
879 				      NULL, &nc);
880 	if (!nc)
881 		return -ENODEV;
882 
883 	/* Update HNC's statistics */
884 	ncs = &nc->stats;
885 	ncs->ncsi_rx_cmds       = ntohl(rsp->rx_cmds);
886 	ncs->ncsi_dropped_cmds  = ntohl(rsp->dropped_cmds);
887 	ncs->ncsi_cmd_type_errs = ntohl(rsp->cmd_type_errs);
888 	ncs->ncsi_cmd_csum_errs = ntohl(rsp->cmd_csum_errs);
889 	ncs->ncsi_rx_pkts       = ntohl(rsp->rx_pkts);
890 	ncs->ncsi_tx_pkts       = ntohl(rsp->tx_pkts);
891 	ncs->ncsi_tx_aen_pkts   = ntohl(rsp->tx_aen_pkts);
892 
893 	return 0;
894 }
895 
896 static int ncsi_rsp_handler_gnpts(struct ncsi_request *nr)
897 {
898 	struct ncsi_rsp_gnpts_pkt *rsp;
899 	struct ncsi_dev_priv *ndp = nr->ndp;
900 	struct ncsi_channel *nc;
901 	struct ncsi_channel_stats *ncs;
902 
903 	/* Find the channel */
904 	rsp = (struct ncsi_rsp_gnpts_pkt *)skb_network_header(nr->rsp);
905 	ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
906 				      NULL, &nc);
907 	if (!nc)
908 		return -ENODEV;
909 
910 	/* Update HNC's statistics */
911 	ncs = &nc->stats;
912 	ncs->pt_tx_pkts        = ntohl(rsp->tx_pkts);
913 	ncs->pt_tx_dropped     = ntohl(rsp->tx_dropped);
914 	ncs->pt_tx_channel_err = ntohl(rsp->tx_channel_err);
915 	ncs->pt_tx_us_err      = ntohl(rsp->tx_us_err);
916 	ncs->pt_rx_pkts        = ntohl(rsp->rx_pkts);
917 	ncs->pt_rx_dropped     = ntohl(rsp->rx_dropped);
918 	ncs->pt_rx_channel_err = ntohl(rsp->rx_channel_err);
919 	ncs->pt_rx_us_err      = ntohl(rsp->rx_us_err);
920 	ncs->pt_rx_os_err      = ntohl(rsp->rx_os_err);
921 
922 	return 0;
923 }
924 
925 static int ncsi_rsp_handler_gps(struct ncsi_request *nr)
926 {
927 	struct ncsi_rsp_gps_pkt *rsp;
928 	struct ncsi_dev_priv *ndp = nr->ndp;
929 	struct ncsi_package *np;
930 
931 	/* Find the package */
932 	rsp = (struct ncsi_rsp_gps_pkt *)skb_network_header(nr->rsp);
933 	ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
934 				      &np, NULL);
935 	if (!np)
936 		return -ENODEV;
937 
938 	return 0;
939 }
940 
941 static int ncsi_rsp_handler_gpuuid(struct ncsi_request *nr)
942 {
943 	struct ncsi_rsp_gpuuid_pkt *rsp;
944 	struct ncsi_dev_priv *ndp = nr->ndp;
945 	struct ncsi_package *np;
946 
947 	/* Find the package */
948 	rsp = (struct ncsi_rsp_gpuuid_pkt *)skb_network_header(nr->rsp);
949 	ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
950 				      &np, NULL);
951 	if (!np)
952 		return -ENODEV;
953 
954 	memcpy(np->uuid, rsp->uuid, sizeof(rsp->uuid));
955 
956 	return 0;
957 }
958 
959 static int ncsi_rsp_handler_netlink(struct ncsi_request *nr)
960 {
961 	struct ncsi_dev_priv *ndp = nr->ndp;
962 	struct ncsi_rsp_pkt *rsp;
963 	struct ncsi_package *np;
964 	struct ncsi_channel *nc;
965 	int ret;
966 
967 	/* Find the package */
968 	rsp = (struct ncsi_rsp_pkt *)skb_network_header(nr->rsp);
969 	ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
970 				      &np, &nc);
971 	if (!np)
972 		return -ENODEV;
973 
974 	ret = ncsi_send_netlink_rsp(nr, np, nc);
975 
976 	return ret;
977 }
978 
979 static struct ncsi_rsp_handler {
980 	unsigned char	type;
981 	int             payload;
982 	int		(*handler)(struct ncsi_request *nr);
983 } ncsi_rsp_handlers[] = {
984 	{ NCSI_PKT_RSP_CIS,     4, ncsi_rsp_handler_cis     },
985 	{ NCSI_PKT_RSP_SP,      4, ncsi_rsp_handler_sp      },
986 	{ NCSI_PKT_RSP_DP,      4, ncsi_rsp_handler_dp      },
987 	{ NCSI_PKT_RSP_EC,      4, ncsi_rsp_handler_ec      },
988 	{ NCSI_PKT_RSP_DC,      4, ncsi_rsp_handler_dc      },
989 	{ NCSI_PKT_RSP_RC,      4, ncsi_rsp_handler_rc      },
990 	{ NCSI_PKT_RSP_ECNT,    4, ncsi_rsp_handler_ecnt    },
991 	{ NCSI_PKT_RSP_DCNT,    4, ncsi_rsp_handler_dcnt    },
992 	{ NCSI_PKT_RSP_AE,      4, ncsi_rsp_handler_ae      },
993 	{ NCSI_PKT_RSP_SL,      4, ncsi_rsp_handler_sl      },
994 	{ NCSI_PKT_RSP_GLS,    16, ncsi_rsp_handler_gls     },
995 	{ NCSI_PKT_RSP_SVF,     4, ncsi_rsp_handler_svf     },
996 	{ NCSI_PKT_RSP_EV,      4, ncsi_rsp_handler_ev      },
997 	{ NCSI_PKT_RSP_DV,      4, ncsi_rsp_handler_dv      },
998 	{ NCSI_PKT_RSP_SMA,     4, ncsi_rsp_handler_sma     },
999 	{ NCSI_PKT_RSP_EBF,     4, ncsi_rsp_handler_ebf     },
1000 	{ NCSI_PKT_RSP_DBF,     4, ncsi_rsp_handler_dbf     },
1001 	{ NCSI_PKT_RSP_EGMF,    4, ncsi_rsp_handler_egmf    },
1002 	{ NCSI_PKT_RSP_DGMF,    4, ncsi_rsp_handler_dgmf    },
1003 	{ NCSI_PKT_RSP_SNFC,    4, ncsi_rsp_handler_snfc    },
1004 	{ NCSI_PKT_RSP_GVI,    40, ncsi_rsp_handler_gvi     },
1005 	{ NCSI_PKT_RSP_GC,     32, ncsi_rsp_handler_gc      },
1006 	{ NCSI_PKT_RSP_GP,     -1, ncsi_rsp_handler_gp      },
1007 	{ NCSI_PKT_RSP_GCPS,  172, ncsi_rsp_handler_gcps    },
1008 	{ NCSI_PKT_RSP_GNS,   172, ncsi_rsp_handler_gns     },
1009 	{ NCSI_PKT_RSP_GNPTS, 172, ncsi_rsp_handler_gnpts   },
1010 	{ NCSI_PKT_RSP_GPS,     8, ncsi_rsp_handler_gps     },
1011 	{ NCSI_PKT_RSP_OEM,    -1, ncsi_rsp_handler_oem     },
1012 	{ NCSI_PKT_RSP_PLDM,    0, NULL                     },
1013 	{ NCSI_PKT_RSP_GPUUID, 20, ncsi_rsp_handler_gpuuid  }
1014 };
1015 
1016 int ncsi_rcv_rsp(struct sk_buff *skb, struct net_device *dev,
1017 		 struct packet_type *pt, struct net_device *orig_dev)
1018 {
1019 	struct ncsi_rsp_handler *nrh = NULL;
1020 	struct ncsi_dev *nd;
1021 	struct ncsi_dev_priv *ndp;
1022 	struct ncsi_request *nr;
1023 	struct ncsi_pkt_hdr *hdr;
1024 	unsigned long flags;
1025 	int payload, i, ret;
1026 
1027 	/* Find the NCSI device */
1028 	nd = ncsi_find_dev(dev);
1029 	ndp = nd ? TO_NCSI_DEV_PRIV(nd) : NULL;
1030 	if (!ndp)
1031 		return -ENODEV;
1032 
1033 	/* Check if it is AEN packet */
1034 	hdr = (struct ncsi_pkt_hdr *)skb_network_header(skb);
1035 	if (hdr->type == NCSI_PKT_AEN)
1036 		return ncsi_aen_handler(ndp, skb);
1037 
1038 	/* Find the handler */
1039 	for (i = 0; i < ARRAY_SIZE(ncsi_rsp_handlers); i++) {
1040 		if (ncsi_rsp_handlers[i].type == hdr->type) {
1041 			if (ncsi_rsp_handlers[i].handler)
1042 				nrh = &ncsi_rsp_handlers[i];
1043 			else
1044 				nrh = NULL;
1045 
1046 			break;
1047 		}
1048 	}
1049 
1050 	if (!nrh) {
1051 		netdev_err(nd->dev, "Received unrecognized packet (0x%x)\n",
1052 			   hdr->type);
1053 		return -ENOENT;
1054 	}
1055 
1056 	/* Associate with the request */
1057 	spin_lock_irqsave(&ndp->lock, flags);
1058 	nr = &ndp->requests[hdr->id];
1059 	if (!nr->used) {
1060 		spin_unlock_irqrestore(&ndp->lock, flags);
1061 		return -ENODEV;
1062 	}
1063 
1064 	nr->rsp = skb;
1065 	if (!nr->enabled) {
1066 		spin_unlock_irqrestore(&ndp->lock, flags);
1067 		ret = -ENOENT;
1068 		goto out;
1069 	}
1070 
1071 	/* Validate the packet */
1072 	spin_unlock_irqrestore(&ndp->lock, flags);
1073 	payload = nrh->payload;
1074 	if (payload < 0)
1075 		payload = ntohs(hdr->length);
1076 	ret = ncsi_validate_rsp_pkt(nr, payload);
1077 	if (ret) {
1078 		netdev_warn(ndp->ndev.dev,
1079 			    "NCSI: 'bad' packet ignored for type 0x%x\n",
1080 			    hdr->type);
1081 
1082 		if (nr->flags == NCSI_REQ_FLAG_NETLINK_DRIVEN) {
1083 			if (ret == -EPERM)
1084 				goto out_netlink;
1085 			else
1086 				ncsi_send_netlink_err(ndp->ndev.dev,
1087 						      nr->snd_seq,
1088 						      nr->snd_portid,
1089 						      &nr->nlhdr,
1090 						      ret);
1091 		}
1092 		goto out;
1093 	}
1094 
1095 	/* Process the packet */
1096 	ret = nrh->handler(nr);
1097 	if (ret)
1098 		netdev_err(ndp->ndev.dev,
1099 			   "NCSI: Handler for packet type 0x%x returned %d\n",
1100 			   hdr->type, ret);
1101 
1102 out_netlink:
1103 	if (nr->flags == NCSI_REQ_FLAG_NETLINK_DRIVEN) {
1104 		ret = ncsi_rsp_handler_netlink(nr);
1105 		if (ret) {
1106 			netdev_err(ndp->ndev.dev,
1107 				   "NCSI: Netlink handler for packet type 0x%x returned %d\n",
1108 				   hdr->type, ret);
1109 		}
1110 	}
1111 
1112 out:
1113 	ncsi_free_request(nr);
1114 	return ret;
1115 }
1116