Lines Matching refs:mdev
33 struct mctp_dev *mdev = rcu_dereference(dev->mctp_ptr); in __mctp_dev_get() local
38 if (mdev) in __mctp_dev_get()
39 if (!refcount_inc_not_zero(&mdev->refs)) in __mctp_dev_get()
41 return mdev; in __mctp_dev_get()
62 struct mctp_dev *mdev, mctp_eid_t eid, in mctp_fill_addrinfo() argument
78 hdr->ifa_index = mdev->dev->ifindex; in mctp_fill_addrinfo()
95 static int mctp_dump_dev_addrinfo(struct mctp_dev *mdev, struct sk_buff *skb, in mctp_dump_dev_addrinfo() argument
104 for (; mcb->a_idx < mdev->num_addrs; mcb->a_idx++) { in mctp_dump_dev_addrinfo()
105 rc = mctp_fill_addrinfo(skb, mdev, mdev->addrs[mcb->a_idx], in mctp_dump_dev_addrinfo()
121 struct mctp_dev *mdev; in mctp_dump_addrinfo() local
136 mdev = __mctp_dev_get(dev); in mctp_dump_addrinfo()
137 if (mdev) { in mctp_dump_addrinfo()
138 rc = mctp_dump_dev_addrinfo(mdev, in mctp_dump_addrinfo()
140 mctp_dev_put(mdev); in mctp_dump_addrinfo()
159 static void mctp_addr_notify(struct mctp_dev *mdev, mctp_eid_t eid, int msg_type, in mctp_addr_notify() argument
163 struct net *net = dev_net(mdev->dev); in mctp_addr_notify()
171 rc = mctp_fill_addrinfo(skb, mdev, eid, msg_type, in mctp_addr_notify()
197 struct mctp_dev *mdev; in mctp_rtm_newaddr() local
222 mdev = mctp_dev_get_rtnl(dev); in mctp_rtm_newaddr()
223 if (!mdev) in mctp_rtm_newaddr()
230 if (memchr(mdev->addrs, addr->s_addr, mdev->num_addrs)) in mctp_rtm_newaddr()
233 tmp_addrs = kmalloc(mdev->num_addrs + 1, GFP_KERNEL); in mctp_rtm_newaddr()
236 memcpy(tmp_addrs, mdev->addrs, mdev->num_addrs); in mctp_rtm_newaddr()
237 tmp_addrs[mdev->num_addrs] = addr->s_addr; in mctp_rtm_newaddr()
240 spin_lock_irqsave(&mdev->addrs_lock, flags); in mctp_rtm_newaddr()
241 mdev->num_addrs++; in mctp_rtm_newaddr()
242 swap(mdev->addrs, tmp_addrs); in mctp_rtm_newaddr()
243 spin_unlock_irqrestore(&mdev->addrs_lock, flags); in mctp_rtm_newaddr()
247 mctp_addr_notify(mdev, addr->s_addr, RTM_NEWADDR, skb, nlh); in mctp_rtm_newaddr()
248 mctp_route_add_local(mdev, addr->s_addr); in mctp_rtm_newaddr()
260 struct mctp_dev *mdev; in mctp_rtm_deladdr() local
285 mdev = mctp_dev_get_rtnl(dev); in mctp_rtm_deladdr()
286 if (!mdev) in mctp_rtm_deladdr()
289 pos = memchr(mdev->addrs, addr->s_addr, mdev->num_addrs); in mctp_rtm_deladdr()
293 rc = mctp_route_remove_local(mdev, addr->s_addr); in mctp_rtm_deladdr()
298 spin_lock_irqsave(&mdev->addrs_lock, flags); in mctp_rtm_deladdr()
299 memmove(pos, pos + 1, mdev->num_addrs - 1 - (pos - mdev->addrs)); in mctp_rtm_deladdr()
300 mdev->num_addrs--; in mctp_rtm_deladdr()
301 spin_unlock_irqrestore(&mdev->addrs_lock, flags); in mctp_rtm_deladdr()
303 mctp_addr_notify(mdev, addr->s_addr, RTM_DELADDR, skb, nlh); in mctp_rtm_deladdr()
308 void mctp_dev_hold(struct mctp_dev *mdev) in mctp_dev_hold() argument
310 refcount_inc(&mdev->refs); in mctp_dev_hold()
313 void mctp_dev_put(struct mctp_dev *mdev) in mctp_dev_put() argument
315 if (mdev && refcount_dec_and_test(&mdev->refs)) { in mctp_dev_put()
316 kfree(mdev->addrs); in mctp_dev_put()
317 dev_put(mdev->dev); in mctp_dev_put()
318 kfree_rcu(mdev, rcu); in mctp_dev_put()
342 struct mctp_dev *mdev; in mctp_add_dev() local
346 mdev = kzalloc(sizeof(*mdev), GFP_KERNEL); in mctp_add_dev()
347 if (!mdev) in mctp_add_dev()
350 spin_lock_init(&mdev->addrs_lock); in mctp_add_dev()
352 mdev->net = mctp_default_net(dev_net(dev)); in mctp_add_dev()
355 refcount_set(&mdev->refs, 1); in mctp_add_dev()
356 rcu_assign_pointer(dev->mctp_ptr, mdev); in mctp_add_dev()
359 mdev->dev = dev; in mctp_add_dev()
361 return mdev; in mctp_add_dev()
367 struct mctp_dev *mdev; in mctp_fill_link_af() local
369 mdev = mctp_dev_get_rtnl(dev); in mctp_fill_link_af()
370 if (!mdev) in mctp_fill_link_af()
372 if (nla_put_u32(skb, IFLA_MCTP_NET, mdev->net)) in mctp_fill_link_af()
380 struct mctp_dev *mdev; in mctp_get_link_af_size() local
384 mdev = __mctp_dev_get(dev); in mctp_get_link_af_size()
385 if (!mdev) in mctp_get_link_af_size()
388 mctp_dev_put(mdev); in mctp_get_link_af_size()
400 struct mctp_dev *mdev; in mctp_set_link_af() local
408 mdev = mctp_dev_get_rtnl(dev); in mctp_set_link_af()
409 if (!mdev) in mctp_set_link_af()
413 WRITE_ONCE(mdev->net, nla_get_u32(tb[IFLA_MCTP_NET])); in mctp_set_link_af()
429 struct mctp_dev *mdev; in mctp_unregister() local
431 mdev = mctp_dev_get_rtnl(dev); in mctp_unregister()
432 if (!mdev) in mctp_unregister()
435 RCU_INIT_POINTER(mdev->dev->mctp_ptr, NULL); in mctp_unregister()
437 mctp_route_remove_dev(mdev); in mctp_unregister()
438 mctp_neigh_remove_dev(mdev); in mctp_unregister()
440 mctp_dev_put(mdev); in mctp_unregister()
445 struct mctp_dev *mdev; in mctp_register() local
455 mdev = mctp_add_dev(dev); in mctp_register()
456 if (IS_ERR(mdev)) in mctp_register()
457 return PTR_ERR(mdev); in mctp_register()
485 struct mctp_dev *mdev; in mctp_register_netdevice() local
487 mdev = mctp_add_dev(dev); in mctp_register_netdevice()
488 if (IS_ERR(mdev)) in mctp_register_netdevice()
489 return PTR_ERR(mdev); in mctp_register_netdevice()
491 mdev->ops = ops; in mctp_register_netdevice()