28 #include <linux/module.h>
34 #include <linux/netdevice.h>
52 static union ib_gid ocrdma_zero_sgid;
54 static int ocrdma_get_instance(
void)
71 guid[0] = mac_addr[0] ^ 2;
72 guid[1] = mac_addr[1];
73 guid[2] = mac_addr[2];
76 guid[5] = mac_addr[3];
77 guid[6] = mac_addr[4];
78 guid[7] = mac_addr[5];
81 static void ocrdma_build_sgid_mac(
union ib_gid *sgid,
unsigned char *
mac_addr,
85 sgid->
raw[8] = mac_addr[0] ^ 2;
86 sgid->
raw[9] = mac_addr[1];
87 sgid->
raw[10] = mac_addr[2];
89 sgid->
raw[11] = vlan_id >> 8;
90 sgid->
raw[12] = vlan_id & 0xff;
95 sgid->
raw[13] = mac_addr[3];
96 sgid->
raw[14] = mac_addr[4];
97 sgid->
raw[15] = mac_addr[5];
100 static bool ocrdma_add_sgid(
struct ocrdma_dev *
dev,
unsigned char *mac_addr,
101 bool is_vlan,
u16 vlan_id)
109 ocrdma_build_sgid_mac(&new_sgid, mac_addr, is_vlan, vlan_id);
118 spin_unlock_irqrestore(&dev->
sgid_lock, flags);
123 spin_unlock_irqrestore(&dev->
sgid_lock, flags);
127 spin_unlock_irqrestore(&dev->
sgid_lock, flags);
131 static bool ocrdma_del_sgid(
struct ocrdma_dev *dev,
unsigned char *mac_addr,
132 bool is_vlan,
u16 vlan_id)
139 ocrdma_build_sgid_mac(&sgid, mac_addr, is_vlan, vlan_id);
151 spin_unlock_irqrestore(&dev->
sgid_lock, flags);
155 static void ocrdma_add_default_sgid(
struct ocrdma_dev *dev)
164 #if IS_ENABLED(CONFIG_VLAN_8021Q)
165 static void ocrdma_add_vlan_sgids(
struct ocrdma_dev *dev)
176 if (!netif_running(tmp) || !netif_oper_up(tmp))
186 ocrdma_add_sgid(dev, tmp->
dev_addr, is_vlan, vlan_id);
192 static void ocrdma_add_vlan_sgids(
struct ocrdma_dev *dev)
198 static int ocrdma_build_sgid_tbl(
struct ocrdma_dev *dev)
200 ocrdma_add_default_sgid(dev);
201 ocrdma_add_vlan_sgids(dev);
205 #if IS_ENABLED(CONFIG_IPV6)
207 static int ocrdma_inet6addr_event(
struct notifier_block *notifier,
215 bool updated =
false;
216 bool is_vlan =
false;
226 list_for_each_entry_rcu(dev, &ocrdma_dev_list,
entry) {
227 if (dev->
nic_info.netdev == netdev) {
236 if (!rdma_link_local_addr((
struct in6_addr *)&ifa->
addr))
242 updated = ocrdma_add_sgid(dev, netdev->
dev_addr, is_vlan, vid);
245 updated = ocrdma_del_sgid(dev, netdev->
dev_addr, is_vlan, vid);
252 gid_event.device = &dev->
ibdev;
253 gid_event.element.port_num = 1;
273 static int ocrdma_register_device(
struct ocrdma_dev *dev)
280 dev->
ibdev.uverbs_cmd_mask =
301 dev->
ibdev.uverbs_cmd_mask |=
308 dev->
ibdev.phys_port_cnt = 1;
309 dev->
ibdev.num_comp_vectors = 1;
316 dev->
ibdev.get_link_layer = ocrdma_link_layer;
353 dev->
ibdev.uverbs_cmd_mask |=
369 static int ocrdma_alloc_resources(
struct ocrdma_dev *dev)
383 if (dev->
attr.max_qp) {
397 static void ocrdma_free_resources(
struct ocrdma_dev *dev)
419 dev->
id = ocrdma_get_instance();
427 status = ocrdma_alloc_resources(dev);
431 status = ocrdma_build_sgid_tbl(dev);
435 status = ocrdma_register_device(dev);
439 spin_lock(&ocrdma_devlist_lock);
440 list_add_tail_rcu(&dev->
entry, &ocrdma_dev_list);
441 spin_unlock(&ocrdma_devlist_lock);
445 ocrdma_free_resources(dev);
452 ocrdma_err(
"%s() leaving. ret=%d\n", __func__, status);
456 static void ocrdma_remove_free(
struct rcu_head *
rcu)
460 ocrdma_free_resources(dev);
468 static void ocrdma_remove(
struct ocrdma_dev *dev)
475 spin_lock(&ocrdma_devlist_lock);
476 list_del_rcu(&dev->
entry);
477 spin_unlock(&ocrdma_devlist_lock);
481 static int ocrdma_open(
struct ocrdma_dev *dev)
492 static int ocrdma_close(
struct ocrdma_dev *dev)
511 err_event.element.qp = &qp->
ibqp;
512 err_event.device = &dev->
ibdev;
520 err_event.element.port_num = 1;
521 err_event.device = &dev->
ibdev;
530 static void ocrdma_event_handler(
struct ocrdma_dev *dev,
u32 event)
543 .name =
"ocrdma_driver",
545 .remove = ocrdma_remove,
546 .state_change_handler = ocrdma_event_handler,
549 static void ocrdma_unregister_inet6addr_notifier(
void)
551 #if IS_ENABLED(CONFIG_IPV6)
556 static int __init ocrdma_init_module(
void)
560 #if IS_ENABLED(CONFIG_IPV6)
568 ocrdma_unregister_inet6addr_notifier();
573 static void __exit ocrdma_exit_module(
void)
576 ocrdma_unregister_inet6addr_notifier();