drm/tests: hdmi: Fix memory leaks in drm_display_mode_from_cea_vic()
[drm/drm-misc.git] / net / ncsi / ncsi-netlink.c
blob2f872d064396df55c2e213c525bae7740c12f62e
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright Samuel Mendoza-Jonas, IBM Corporation 2018.
4 */
6 #include <linux/module.h>
7 #include <linux/kernel.h>
8 #include <linux/if_arp.h>
9 #include <linux/rtnetlink.h>
10 #include <linux/etherdevice.h>
11 #include <net/genetlink.h>
12 #include <net/ncsi.h>
13 #include <linux/skbuff.h>
14 #include <net/sock.h>
15 #include <uapi/linux/ncsi.h>
17 #include "internal.h"
18 #include "ncsi-pkt.h"
19 #include "ncsi-netlink.h"
21 static struct genl_family ncsi_genl_family;
23 static const struct nla_policy ncsi_genl_policy[NCSI_ATTR_MAX + 1] = {
24 [NCSI_ATTR_IFINDEX] = { .type = NLA_U32 },
25 [NCSI_ATTR_PACKAGE_LIST] = { .type = NLA_NESTED },
26 [NCSI_ATTR_PACKAGE_ID] = { .type = NLA_U32 },
27 [NCSI_ATTR_CHANNEL_ID] = { .type = NLA_U32 },
28 [NCSI_ATTR_DATA] = { .type = NLA_BINARY, .len = 2048 },
29 [NCSI_ATTR_MULTI_FLAG] = { .type = NLA_FLAG },
30 [NCSI_ATTR_PACKAGE_MASK] = { .type = NLA_U32 },
31 [NCSI_ATTR_CHANNEL_MASK] = { .type = NLA_U32 },
34 static struct ncsi_dev_priv *ndp_from_ifindex(struct net *net, u32 ifindex)
36 struct ncsi_dev_priv *ndp;
37 struct net_device *dev;
38 struct ncsi_dev *nd;
39 struct ncsi_dev;
41 if (!net)
42 return NULL;
44 dev = dev_get_by_index(net, ifindex);
45 if (!dev) {
46 pr_err("NCSI netlink: No device for ifindex %u\n", ifindex);
47 return NULL;
50 nd = ncsi_find_dev(dev);
51 ndp = nd ? TO_NCSI_DEV_PRIV(nd) : NULL;
53 dev_put(dev);
54 return ndp;
57 static int ncsi_write_channel_info(struct sk_buff *skb,
58 struct ncsi_dev_priv *ndp,
59 struct ncsi_channel *nc)
61 struct ncsi_channel_vlan_filter *ncf;
62 struct ncsi_channel_mode *m;
63 struct nlattr *vid_nest;
64 int i;
66 nla_put_u32(skb, NCSI_CHANNEL_ATTR_ID, nc->id);
67 m = &nc->modes[NCSI_MODE_LINK];
68 nla_put_u32(skb, NCSI_CHANNEL_ATTR_LINK_STATE, m->data[2]);
69 if (nc->state == NCSI_CHANNEL_ACTIVE)
70 nla_put_flag(skb, NCSI_CHANNEL_ATTR_ACTIVE);
71 if (nc == nc->package->preferred_channel)
72 nla_put_flag(skb, NCSI_CHANNEL_ATTR_FORCED);
74 nla_put_u32(skb, NCSI_CHANNEL_ATTR_VERSION_MAJOR, nc->version.major);
75 nla_put_u32(skb, NCSI_CHANNEL_ATTR_VERSION_MINOR, nc->version.minor);
76 nla_put_string(skb, NCSI_CHANNEL_ATTR_VERSION_STR, nc->version.fw_name);
78 vid_nest = nla_nest_start_noflag(skb, NCSI_CHANNEL_ATTR_VLAN_LIST);
79 if (!vid_nest)
80 return -ENOMEM;
81 ncf = &nc->vlan_filter;
82 i = -1;
83 while ((i = find_next_bit((void *)&ncf->bitmap, ncf->n_vids,
84 i + 1)) < ncf->n_vids) {
85 if (ncf->vids[i])
86 nla_put_u16(skb, NCSI_CHANNEL_ATTR_VLAN_ID,
87 ncf->vids[i]);
89 nla_nest_end(skb, vid_nest);
91 return 0;
94 static int ncsi_write_package_info(struct sk_buff *skb,
95 struct ncsi_dev_priv *ndp, unsigned int id)
97 struct nlattr *pnest, *cnest, *nest;
98 struct ncsi_package *np;
99 struct ncsi_channel *nc;
100 bool found;
101 int rc;
103 if (id > ndp->package_num - 1) {
104 netdev_info(ndp->ndev.dev, "NCSI: No package with id %u\n", id);
105 return -ENODEV;
108 found = false;
109 NCSI_FOR_EACH_PACKAGE(ndp, np) {
110 if (np->id != id)
111 continue;
112 pnest = nla_nest_start_noflag(skb, NCSI_PKG_ATTR);
113 if (!pnest)
114 return -ENOMEM;
115 rc = nla_put_u32(skb, NCSI_PKG_ATTR_ID, np->id);
116 if (rc) {
117 nla_nest_cancel(skb, pnest);
118 return rc;
120 if ((0x1 << np->id) == ndp->package_whitelist)
121 nla_put_flag(skb, NCSI_PKG_ATTR_FORCED);
122 cnest = nla_nest_start_noflag(skb, NCSI_PKG_ATTR_CHANNEL_LIST);
123 if (!cnest) {
124 nla_nest_cancel(skb, pnest);
125 return -ENOMEM;
127 NCSI_FOR_EACH_CHANNEL(np, nc) {
128 nest = nla_nest_start_noflag(skb, NCSI_CHANNEL_ATTR);
129 if (!nest) {
130 nla_nest_cancel(skb, cnest);
131 nla_nest_cancel(skb, pnest);
132 return -ENOMEM;
134 rc = ncsi_write_channel_info(skb, ndp, nc);
135 if (rc) {
136 nla_nest_cancel(skb, nest);
137 nla_nest_cancel(skb, cnest);
138 nla_nest_cancel(skb, pnest);
139 return rc;
141 nla_nest_end(skb, nest);
143 nla_nest_end(skb, cnest);
144 nla_nest_end(skb, pnest);
145 found = true;
148 if (!found)
149 return -ENODEV;
151 return 0;
154 static int ncsi_pkg_info_nl(struct sk_buff *msg, struct genl_info *info)
156 struct ncsi_dev_priv *ndp;
157 unsigned int package_id;
158 struct sk_buff *skb;
159 struct nlattr *attr;
160 void *hdr;
161 int rc;
163 if (!info || !info->attrs)
164 return -EINVAL;
166 if (!info->attrs[NCSI_ATTR_IFINDEX])
167 return -EINVAL;
169 if (!info->attrs[NCSI_ATTR_PACKAGE_ID])
170 return -EINVAL;
172 ndp = ndp_from_ifindex(genl_info_net(info),
173 nla_get_u32(info->attrs[NCSI_ATTR_IFINDEX]));
174 if (!ndp)
175 return -ENODEV;
177 skb = genlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
178 if (!skb)
179 return -ENOMEM;
181 hdr = genlmsg_put(skb, info->snd_portid, info->snd_seq,
182 &ncsi_genl_family, 0, NCSI_CMD_PKG_INFO);
183 if (!hdr) {
184 kfree_skb(skb);
185 return -EMSGSIZE;
188 package_id = nla_get_u32(info->attrs[NCSI_ATTR_PACKAGE_ID]);
190 attr = nla_nest_start_noflag(skb, NCSI_ATTR_PACKAGE_LIST);
191 if (!attr) {
192 kfree_skb(skb);
193 return -EMSGSIZE;
195 rc = ncsi_write_package_info(skb, ndp, package_id);
197 if (rc) {
198 nla_nest_cancel(skb, attr);
199 goto err;
202 nla_nest_end(skb, attr);
204 genlmsg_end(skb, hdr);
205 return genlmsg_reply(skb, info);
207 err:
208 kfree_skb(skb);
209 return rc;
212 static int ncsi_pkg_info_all_nl(struct sk_buff *skb,
213 struct netlink_callback *cb)
215 struct nlattr *attrs[NCSI_ATTR_MAX + 1];
216 struct ncsi_package *np, *package;
217 struct ncsi_dev_priv *ndp;
218 unsigned int package_id;
219 struct nlattr *attr;
220 void *hdr;
221 int rc;
223 rc = genlmsg_parse_deprecated(cb->nlh, &ncsi_genl_family, attrs, NCSI_ATTR_MAX,
224 ncsi_genl_policy, NULL);
225 if (rc)
226 return rc;
228 if (!attrs[NCSI_ATTR_IFINDEX])
229 return -EINVAL;
231 ndp = ndp_from_ifindex(get_net(sock_net(skb->sk)),
232 nla_get_u32(attrs[NCSI_ATTR_IFINDEX]));
234 if (!ndp)
235 return -ENODEV;
237 package_id = cb->args[0];
238 package = NULL;
239 NCSI_FOR_EACH_PACKAGE(ndp, np)
240 if (np->id == package_id)
241 package = np;
243 if (!package)
244 return 0; /* done */
246 hdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
247 &ncsi_genl_family, NLM_F_MULTI, NCSI_CMD_PKG_INFO);
248 if (!hdr) {
249 rc = -EMSGSIZE;
250 goto err;
253 attr = nla_nest_start_noflag(skb, NCSI_ATTR_PACKAGE_LIST);
254 if (!attr) {
255 rc = -EMSGSIZE;
256 goto err;
258 rc = ncsi_write_package_info(skb, ndp, package->id);
259 if (rc) {
260 nla_nest_cancel(skb, attr);
261 goto err;
264 nla_nest_end(skb, attr);
265 genlmsg_end(skb, hdr);
267 cb->args[0] = package_id + 1;
269 return skb->len;
270 err:
271 genlmsg_cancel(skb, hdr);
272 return rc;
275 static int ncsi_set_interface_nl(struct sk_buff *msg, struct genl_info *info)
277 struct ncsi_package *np, *package;
278 struct ncsi_channel *nc, *channel;
279 u32 package_id, channel_id;
280 struct ncsi_dev_priv *ndp;
281 unsigned long flags;
283 if (!info || !info->attrs)
284 return -EINVAL;
286 if (!info->attrs[NCSI_ATTR_IFINDEX])
287 return -EINVAL;
289 if (!info->attrs[NCSI_ATTR_PACKAGE_ID])
290 return -EINVAL;
292 ndp = ndp_from_ifindex(get_net(sock_net(msg->sk)),
293 nla_get_u32(info->attrs[NCSI_ATTR_IFINDEX]));
294 if (!ndp)
295 return -ENODEV;
297 package_id = nla_get_u32(info->attrs[NCSI_ATTR_PACKAGE_ID]);
298 package = NULL;
300 NCSI_FOR_EACH_PACKAGE(ndp, np)
301 if (np->id == package_id)
302 package = np;
303 if (!package) {
304 /* The user has set a package that does not exist */
305 return -ERANGE;
308 channel = NULL;
309 if (info->attrs[NCSI_ATTR_CHANNEL_ID]) {
310 channel_id = nla_get_u32(info->attrs[NCSI_ATTR_CHANNEL_ID]);
311 NCSI_FOR_EACH_CHANNEL(package, nc)
312 if (nc->id == channel_id) {
313 channel = nc;
314 break;
316 if (!channel) {
317 netdev_info(ndp->ndev.dev,
318 "NCSI: Channel %u does not exist!\n",
319 channel_id);
320 return -ERANGE;
324 spin_lock_irqsave(&ndp->lock, flags);
325 ndp->package_whitelist = 0x1 << package->id;
326 ndp->multi_package = false;
327 spin_unlock_irqrestore(&ndp->lock, flags);
329 spin_lock_irqsave(&package->lock, flags);
330 package->multi_channel = false;
331 if (channel) {
332 package->channel_whitelist = 0x1 << channel->id;
333 package->preferred_channel = channel;
334 } else {
335 /* Allow any channel */
336 package->channel_whitelist = UINT_MAX;
337 package->preferred_channel = NULL;
339 spin_unlock_irqrestore(&package->lock, flags);
341 if (channel)
342 netdev_info(ndp->ndev.dev,
343 "Set package 0x%x, channel 0x%x as preferred\n",
344 package_id, channel_id);
345 else
346 netdev_info(ndp->ndev.dev, "Set package 0x%x as preferred\n",
347 package_id);
349 /* Update channel configuration */
350 if (!(ndp->flags & NCSI_DEV_RESET))
351 ncsi_reset_dev(&ndp->ndev);
353 return 0;
356 static int ncsi_clear_interface_nl(struct sk_buff *msg, struct genl_info *info)
358 struct ncsi_dev_priv *ndp;
359 struct ncsi_package *np;
360 unsigned long flags;
362 if (!info || !info->attrs)
363 return -EINVAL;
365 if (!info->attrs[NCSI_ATTR_IFINDEX])
366 return -EINVAL;
368 ndp = ndp_from_ifindex(get_net(sock_net(msg->sk)),
369 nla_get_u32(info->attrs[NCSI_ATTR_IFINDEX]));
370 if (!ndp)
371 return -ENODEV;
373 /* Reset any whitelists and disable multi mode */
374 spin_lock_irqsave(&ndp->lock, flags);
375 ndp->package_whitelist = UINT_MAX;
376 ndp->multi_package = false;
377 spin_unlock_irqrestore(&ndp->lock, flags);
379 NCSI_FOR_EACH_PACKAGE(ndp, np) {
380 spin_lock_irqsave(&np->lock, flags);
381 np->multi_channel = false;
382 np->channel_whitelist = UINT_MAX;
383 np->preferred_channel = NULL;
384 spin_unlock_irqrestore(&np->lock, flags);
386 netdev_info(ndp->ndev.dev, "NCSI: Cleared preferred package/channel\n");
388 /* Update channel configuration */
389 if (!(ndp->flags & NCSI_DEV_RESET))
390 ncsi_reset_dev(&ndp->ndev);
392 return 0;
395 static int ncsi_send_cmd_nl(struct sk_buff *msg, struct genl_info *info)
397 struct ncsi_dev_priv *ndp;
398 struct ncsi_pkt_hdr *hdr;
399 struct ncsi_cmd_arg nca;
400 unsigned char *data;
401 u32 package_id;
402 u32 channel_id;
403 int len, ret;
405 if (!info || !info->attrs) {
406 ret = -EINVAL;
407 goto out;
410 if (!info->attrs[NCSI_ATTR_IFINDEX]) {
411 ret = -EINVAL;
412 goto out;
415 if (!info->attrs[NCSI_ATTR_PACKAGE_ID]) {
416 ret = -EINVAL;
417 goto out;
420 if (!info->attrs[NCSI_ATTR_CHANNEL_ID]) {
421 ret = -EINVAL;
422 goto out;
425 if (!info->attrs[NCSI_ATTR_DATA]) {
426 ret = -EINVAL;
427 goto out;
430 ndp = ndp_from_ifindex(get_net(sock_net(msg->sk)),
431 nla_get_u32(info->attrs[NCSI_ATTR_IFINDEX]));
432 if (!ndp) {
433 ret = -ENODEV;
434 goto out;
437 package_id = nla_get_u32(info->attrs[NCSI_ATTR_PACKAGE_ID]);
438 channel_id = nla_get_u32(info->attrs[NCSI_ATTR_CHANNEL_ID]);
440 if (package_id >= NCSI_MAX_PACKAGE || channel_id >= NCSI_MAX_CHANNEL) {
441 ret = -ERANGE;
442 goto out_netlink;
445 len = nla_len(info->attrs[NCSI_ATTR_DATA]);
446 if (len < sizeof(struct ncsi_pkt_hdr)) {
447 netdev_info(ndp->ndev.dev, "NCSI: no command to send %u\n",
448 package_id);
449 ret = -EINVAL;
450 goto out_netlink;
451 } else {
452 data = (unsigned char *)nla_data(info->attrs[NCSI_ATTR_DATA]);
455 hdr = (struct ncsi_pkt_hdr *)data;
457 nca.ndp = ndp;
458 nca.package = (unsigned char)package_id;
459 nca.channel = (unsigned char)channel_id;
460 nca.type = hdr->type;
461 nca.req_flags = NCSI_REQ_FLAG_NETLINK_DRIVEN;
462 nca.info = info;
463 nca.payload = ntohs(hdr->length);
464 nca.data = data + sizeof(*hdr);
466 ret = ncsi_xmit_cmd(&nca);
467 out_netlink:
468 if (ret != 0) {
469 netdev_err(ndp->ndev.dev,
470 "NCSI: Error %d sending command\n",
471 ret);
472 ncsi_send_netlink_err(ndp->ndev.dev,
473 info->snd_seq,
474 info->snd_portid,
475 info->nlhdr,
476 ret);
478 out:
479 return ret;
482 int ncsi_send_netlink_rsp(struct ncsi_request *nr,
483 struct ncsi_package *np,
484 struct ncsi_channel *nc)
486 struct sk_buff *skb;
487 struct net *net;
488 void *hdr;
489 int rc;
491 net = dev_net(nr->rsp->dev);
493 skb = genlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
494 if (!skb)
495 return -ENOMEM;
497 hdr = genlmsg_put(skb, nr->snd_portid, nr->snd_seq,
498 &ncsi_genl_family, 0, NCSI_CMD_SEND_CMD);
499 if (!hdr) {
500 kfree_skb(skb);
501 return -EMSGSIZE;
504 nla_put_u32(skb, NCSI_ATTR_IFINDEX, nr->rsp->dev->ifindex);
505 if (np)
506 nla_put_u32(skb, NCSI_ATTR_PACKAGE_ID, np->id);
507 if (nc)
508 nla_put_u32(skb, NCSI_ATTR_CHANNEL_ID, nc->id);
509 else
510 nla_put_u32(skb, NCSI_ATTR_CHANNEL_ID, NCSI_RESERVED_CHANNEL);
512 rc = nla_put(skb, NCSI_ATTR_DATA, nr->rsp->len, (void *)nr->rsp->data);
513 if (rc)
514 goto err;
516 genlmsg_end(skb, hdr);
517 return genlmsg_unicast(net, skb, nr->snd_portid);
519 err:
520 kfree_skb(skb);
521 return rc;
524 int ncsi_send_netlink_timeout(struct ncsi_request *nr,
525 struct ncsi_package *np,
526 struct ncsi_channel *nc)
528 struct sk_buff *skb;
529 struct net *net;
530 void *hdr;
532 skb = genlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
533 if (!skb)
534 return -ENOMEM;
536 hdr = genlmsg_put(skb, nr->snd_portid, nr->snd_seq,
537 &ncsi_genl_family, 0, NCSI_CMD_SEND_CMD);
538 if (!hdr) {
539 kfree_skb(skb);
540 return -EMSGSIZE;
543 net = dev_net(nr->cmd->dev);
545 nla_put_u32(skb, NCSI_ATTR_IFINDEX, nr->cmd->dev->ifindex);
547 if (np)
548 nla_put_u32(skb, NCSI_ATTR_PACKAGE_ID, np->id);
549 else
550 nla_put_u32(skb, NCSI_ATTR_PACKAGE_ID,
551 NCSI_PACKAGE_INDEX((((struct ncsi_pkt_hdr *)
552 nr->cmd->data)->channel)));
554 if (nc)
555 nla_put_u32(skb, NCSI_ATTR_CHANNEL_ID, nc->id);
556 else
557 nla_put_u32(skb, NCSI_ATTR_CHANNEL_ID, NCSI_RESERVED_CHANNEL);
559 genlmsg_end(skb, hdr);
560 return genlmsg_unicast(net, skb, nr->snd_portid);
563 int ncsi_send_netlink_err(struct net_device *dev,
564 u32 snd_seq,
565 u32 snd_portid,
566 const struct nlmsghdr *nlhdr,
567 int err)
569 struct nlmsghdr *nlh;
570 struct nlmsgerr *nle;
571 struct sk_buff *skb;
572 struct net *net;
574 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
575 if (!skb)
576 return -ENOMEM;
578 net = dev_net(dev);
580 nlh = nlmsg_put(skb, snd_portid, snd_seq,
581 NLMSG_ERROR, sizeof(*nle), 0);
582 nle = (struct nlmsgerr *)nlmsg_data(nlh);
583 nle->error = err;
584 memcpy(&nle->msg, nlhdr, sizeof(*nlh));
586 nlmsg_end(skb, nlh);
588 return nlmsg_unicast(net->genl_sock, skb, snd_portid);
591 static int ncsi_set_package_mask_nl(struct sk_buff *msg,
592 struct genl_info *info)
594 struct ncsi_dev_priv *ndp;
595 unsigned long flags;
596 int rc;
598 if (!info || !info->attrs)
599 return -EINVAL;
601 if (!info->attrs[NCSI_ATTR_IFINDEX])
602 return -EINVAL;
604 if (!info->attrs[NCSI_ATTR_PACKAGE_MASK])
605 return -EINVAL;
607 ndp = ndp_from_ifindex(get_net(sock_net(msg->sk)),
608 nla_get_u32(info->attrs[NCSI_ATTR_IFINDEX]));
609 if (!ndp)
610 return -ENODEV;
612 spin_lock_irqsave(&ndp->lock, flags);
613 if (nla_get_flag(info->attrs[NCSI_ATTR_MULTI_FLAG])) {
614 if (ndp->flags & NCSI_DEV_HWA) {
615 ndp->multi_package = true;
616 rc = 0;
617 } else {
618 netdev_err(ndp->ndev.dev,
619 "NCSI: Can't use multiple packages without HWA\n");
620 rc = -EPERM;
622 } else {
623 ndp->multi_package = false;
624 rc = 0;
627 if (!rc)
628 ndp->package_whitelist =
629 nla_get_u32(info->attrs[NCSI_ATTR_PACKAGE_MASK]);
630 spin_unlock_irqrestore(&ndp->lock, flags);
632 if (!rc) {
633 /* Update channel configuration */
634 if (!(ndp->flags & NCSI_DEV_RESET))
635 ncsi_reset_dev(&ndp->ndev);
638 return rc;
641 static int ncsi_set_channel_mask_nl(struct sk_buff *msg,
642 struct genl_info *info)
644 struct ncsi_package *np, *package;
645 struct ncsi_channel *nc, *channel;
646 u32 package_id, channel_id;
647 struct ncsi_dev_priv *ndp;
648 unsigned long flags;
650 if (!info || !info->attrs)
651 return -EINVAL;
653 if (!info->attrs[NCSI_ATTR_IFINDEX])
654 return -EINVAL;
656 if (!info->attrs[NCSI_ATTR_PACKAGE_ID])
657 return -EINVAL;
659 if (!info->attrs[NCSI_ATTR_CHANNEL_MASK])
660 return -EINVAL;
662 ndp = ndp_from_ifindex(get_net(sock_net(msg->sk)),
663 nla_get_u32(info->attrs[NCSI_ATTR_IFINDEX]));
664 if (!ndp)
665 return -ENODEV;
667 package_id = nla_get_u32(info->attrs[NCSI_ATTR_PACKAGE_ID]);
668 package = NULL;
669 NCSI_FOR_EACH_PACKAGE(ndp, np)
670 if (np->id == package_id) {
671 package = np;
672 break;
674 if (!package)
675 return -ERANGE;
677 spin_lock_irqsave(&package->lock, flags);
679 channel = NULL;
680 if (info->attrs[NCSI_ATTR_CHANNEL_ID]) {
681 channel_id = nla_get_u32(info->attrs[NCSI_ATTR_CHANNEL_ID]);
682 NCSI_FOR_EACH_CHANNEL(np, nc)
683 if (nc->id == channel_id) {
684 channel = nc;
685 break;
687 if (!channel) {
688 spin_unlock_irqrestore(&package->lock, flags);
689 return -ERANGE;
691 netdev_dbg(ndp->ndev.dev,
692 "NCSI: Channel %u set as preferred channel\n",
693 channel->id);
696 package->channel_whitelist =
697 nla_get_u32(info->attrs[NCSI_ATTR_CHANNEL_MASK]);
698 if (package->channel_whitelist == 0)
699 netdev_dbg(ndp->ndev.dev,
700 "NCSI: Package %u set to all channels disabled\n",
701 package->id);
703 package->preferred_channel = channel;
705 if (nla_get_flag(info->attrs[NCSI_ATTR_MULTI_FLAG])) {
706 package->multi_channel = true;
707 netdev_info(ndp->ndev.dev,
708 "NCSI: Multi-channel enabled on package %u\n",
709 package_id);
710 } else {
711 package->multi_channel = false;
714 spin_unlock_irqrestore(&package->lock, flags);
716 /* Update channel configuration */
717 if (!(ndp->flags & NCSI_DEV_RESET))
718 ncsi_reset_dev(&ndp->ndev);
720 return 0;
723 static const struct genl_small_ops ncsi_ops[] = {
725 .cmd = NCSI_CMD_PKG_INFO,
726 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
727 .doit = ncsi_pkg_info_nl,
728 .dumpit = ncsi_pkg_info_all_nl,
729 .flags = 0,
732 .cmd = NCSI_CMD_SET_INTERFACE,
733 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
734 .doit = ncsi_set_interface_nl,
735 .flags = GENL_ADMIN_PERM,
738 .cmd = NCSI_CMD_CLEAR_INTERFACE,
739 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
740 .doit = ncsi_clear_interface_nl,
741 .flags = GENL_ADMIN_PERM,
744 .cmd = NCSI_CMD_SEND_CMD,
745 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
746 .doit = ncsi_send_cmd_nl,
747 .flags = GENL_ADMIN_PERM,
750 .cmd = NCSI_CMD_SET_PACKAGE_MASK,
751 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
752 .doit = ncsi_set_package_mask_nl,
753 .flags = GENL_ADMIN_PERM,
756 .cmd = NCSI_CMD_SET_CHANNEL_MASK,
757 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
758 .doit = ncsi_set_channel_mask_nl,
759 .flags = GENL_ADMIN_PERM,
763 static struct genl_family ncsi_genl_family __ro_after_init = {
764 .name = "NCSI",
765 .version = 0,
766 .maxattr = NCSI_ATTR_MAX,
767 .policy = ncsi_genl_policy,
768 .module = THIS_MODULE,
769 .small_ops = ncsi_ops,
770 .n_small_ops = ARRAY_SIZE(ncsi_ops),
771 .resv_start_op = NCSI_CMD_SET_CHANNEL_MASK + 1,
774 static int __init ncsi_init_netlink(void)
776 return genl_register_family(&ncsi_genl_family);
778 subsys_initcall(ncsi_init_netlink);