Lines Matching defs:vswp

78 static int vsw_set_if_hw_addr(vsw_t *vswp);
80 static int vsw_maccl_open(vsw_t *vswp, vsw_port_t *port, int type);
81 static void vsw_maccl_close(vsw_t *vswp, vsw_port_t *port, int type);
82 static void vsw_mac_multicast_add_all(vsw_t *vswp, vsw_port_t *portp, int type);
83 static void vsw_mac_multicast_remove_all(vsw_t *vswp,
85 static void vsw_mac_add_vlans(vsw_t *vswp, mac_client_handle_t mch,
89 static void vsw_mac_set_mtu(vsw_t *vswp, uint32_t mtu);
90 static void vsw_maccl_set_bandwidth(vsw_t *vswp, vsw_port_t *port, int type,
92 static int vsw_notify_add(vsw_t *vswp);
93 static int vsw_notify_rem(vsw_t *vswp);
95 static void vsw_notify_link(vsw_t *vswp);
101 int vsw_mac_open(vsw_t *vswp);
102 void vsw_mac_close(vsw_t *vswp);
103 int vsw_mac_multicast_add(vsw_t *vswp, vsw_port_t *port, mcst_addr_t *mcst_p,
105 void vsw_mac_multicast_remove(vsw_t *vswp, vsw_port_t *port,
107 int vsw_mac_client_init(vsw_t *vswp, vsw_port_t *port, int type);
108 void vsw_mac_client_cleanup(vsw_t *vswp, vsw_port_t *port, int type);
109 void vsw_mac_cleanup_ports(vsw_t *vswp);
110 void vsw_unset_addrs(vsw_t *vswp);
111 void vsw_set_addrs(vsw_t *vswp);
113 void vsw_publish_macaddr(vsw_t *vswp, vsw_port_t *portp);
118 void vsw_if_mac_reconfig(vsw_t *vswp, boolean_t update_vlans,
120 void vsw_update_bandwidth(vsw_t *vswp, vsw_port_t *port, int type,
132 extern void vsw_physlink_state_update(vsw_t *vswp);
140 #define WRITE_MACCL_ENTER(vswp, port, type) \
141 (type == VSW_LOCALDEV) ? rw_enter(&vswp->maccl_rwlock, RW_WRITER) :\
144 #define READ_MACCL_ENTER(vswp, port, type) \
145 (type == VSW_LOCALDEV) ? rw_enter(&vswp->maccl_rwlock, RW_READER) :\
148 #define RW_MACCL_EXIT(vswp, port, type) \
149 (type == VSW_LOCALDEV) ? rw_exit(&vswp->maccl_rwlock) : \
155 * - A global lock(vswp->mac_lock) is used to protect the
179 vsw_set_addrs(vsw_t *vswp)
181 vsw_port_list_t *plist = &vswp->plist;
185 READ_ENTER(&vswp->if_lockrw);
187 if (vswp->if_state & VSW_IF_UP) {
190 rv = vsw_mac_client_init(vswp, NULL, VSW_LOCALDEV);
194 "unicast address\n", vswp->instance);
201 mac_unicst_update(vswp->if_mh,
202 (uint8_t *)&vswp->if_addr);
207 RW_EXIT(&vswp->if_lockrw);
217 rv = vsw_mac_client_init(vswp, port, VSW_VNETPORT);
221 "unicast address\n", vswp->instance,
228 vsw_publish_macaddr(vswp, port);
240 vsw_unset_addrs(vsw_t *vswp)
242 READ_ENTER(&vswp->if_lockrw);
243 if (vswp->if_state & VSW_IF_UP) {
246 vsw_mac_client_cleanup(vswp, NULL, VSW_LOCALDEV);
248 RW_EXIT(&vswp->if_lockrw);
251 vsw_mac_cleanup_ports(vswp);
262 vsw_mac_open(vsw_t *vswp)
266 ASSERT(MUTEX_HELD(&vswp->mac_lock));
268 if (vswp->mh != NULL) {
273 if (vswp->mac_open_retries++ >= vsw_mac_open_retries) {
278 if ((rv = mac_open_by_linkname(vswp->physname, &vswp->mh)) != 0) {
291 vswp->instance, vswp->physname, rv);
295 vswp->mac_open_retries = 0;
297 vsw_mac_set_mtu(vswp, vswp->mtu);
299 rv = vsw_notify_add(vswp);
302 vswp->instance, vswp->physname, rv);
312 vsw_mac_close(vsw_t *vswp)
314 ASSERT(MUTEX_HELD(&vswp->mac_lock));
316 if (vswp->mh != NULL) {
317 if (vswp->mnh != 0) {
318 (void) vsw_notify_rem(vswp);
319 vswp->mnh = 0;
321 if (vswp->mtu != vswp->mtu_physdev_orig) {
322 vsw_mac_set_mtu(vswp, vswp->mtu_physdev_orig);
324 mac_close(vswp->mh);
325 vswp->mh = NULL;
333 vsw_mac_multicast_add(vsw_t *vswp, vsw_port_t *port, mcst_addr_t *mcst_p,
339 WRITE_MACCL_ENTER(vswp, port, type);
341 mch = (type == VSW_LOCALDEV) ? vswp->mch : port->p_mch;
348 vswp->instance,
350 RW_MACCL_EXIT(vswp, port, type);
356 RW_MACCL_EXIT(vswp, port, type);
364 vsw_mac_multicast_remove(vsw_t *vswp, vsw_port_t *port, mcst_addr_t *mcst_p,
369 WRITE_MACCL_ENTER(vswp, port, type);
370 mch = (type == VSW_LOCALDEV) ? vswp->mch : port->p_mch;
376 RW_MACCL_EXIT(vswp, port, type);
384 vsw_mac_multicast_add_all(vsw_t *vswp, vsw_port_t *portp, int type)
393 ASSERT(RW_WRITE_HELD(&vswp->maccl_rwlock));
394 mch = vswp->mch;
395 mcap = vswp->mcap;
396 mca_lockp = &vswp->mca_lock;
416 "multicast address(%s) err=%d", vswp->instance,
427 vsw_mac_multicast_remove_all(vsw_t *vswp, vsw_port_t *portp, int type)
435 ASSERT(RW_WRITE_HELD(&vswp->maccl_rwlock));
436 mch = vswp->mch;
437 mcap = vswp->mcap;
438 mca_lockp = &vswp->mca_lock;
460 vsw_update_bandwidth(vsw_t *vswp, vsw_port_t *port, int type, uint64_t maxbw)
464 WRITE_MACCL_ENTER(vswp, port, type);
465 vsw_maccl_set_bandwidth(vswp, port, type, maxbw);
466 RW_MACCL_EXIT(vswp, port, type);
477 vsw_mac_client_init(vsw_t *vswp, vsw_port_t *port, int type)
481 mutex_enter(&vswp->mac_lock);
482 WRITE_MACCL_ENTER(vswp, port, type);
483 rv = vsw_maccl_open(vswp, port, type);
486 mutex_exit(&vswp->mac_lock);
489 (void) vsw_set_hw(vswp, port, type);
490 vsw_mac_multicast_add_all(vswp, port, type);
492 RW_MACCL_EXIT(vswp, port, type);
516 vsw_maccl_open(vsw_t *vswp, vsw_port_t *port, int type)
525 ASSERT(MUTEX_HELD(&vswp->mac_lock));
526 if (vswp->mh == NULL) {
535 mchp = (type == VSW_LOCALDEV) ? &vswp->mch : &port->p_mch;
540 dev_name = ddi_driver_name(vswp->dip);
541 instance = ddi_get_instance(vswp->dip);
552 rv = mac_client_open(vswp->mh, mchp, mac_cl_name, flags);
555 vswp->instance, mac_cl_name);
569 vsw_mac_client_cleanup(vsw_t *vswp, vsw_port_t *port, int type)
571 WRITE_MACCL_ENTER(vswp, port, type);
572 vsw_mac_multicast_remove_all(vswp, port, type);
573 vsw_unset_hw(vswp, port, type);
574 vsw_maccl_close(vswp, port, type);
575 RW_MACCL_EXIT(vswp, port, type);
582 vsw_maccl_close(vsw_t *vswp, vsw_port_t *port, int type)
588 mchp = (type == VSW_LOCALDEV) ? &vswp->mch : &port->p_mch;
599 vsw_mac_cleanup_ports(vsw_t *vswp)
601 vsw_port_list_t *plist = &vswp->plist;
606 vsw_mac_client_cleanup(vswp, port, VSW_VNETPORT);
624 vsw_set_hw(vsw_t *vswp, vsw_port_t *port, int type)
628 D1(vswp, "%s: enter", __func__);
632 if (vswp->smode == VSW_LAYER3)
639 err = vsw_set_if_hw_addr(vswp);
642 D1(vswp, "%s: exit", __func__);
657 vsw_unset_hw(vsw_t *vswp, vsw_port_t *port, int type)
659 D1(vswp, "%s: enter", __func__);
663 if (vswp->smode == VSW_LAYER3)
668 vsw_unset_hw_addr(vswp, port, type);
670 vsw_unset_hw_addr(vswp, NULL, type);
673 D1(vswp, "%s: exit", __func__);
684 vsw_t *vswp = port->p_vswp;
692 D1(vswp, "%s: enter", __func__);
703 if (port->pvid != vswp->default_vlan_id) {
708 if (!(vswp->smode & VSW_LAYER2_PROMISC)) {
720 vswp->instance, ether_sprintf((void *)macaddr),
726 D2(vswp, "%s:programmed macaddr(%s) vid(%d) into device %s",
728 vswp->physname);
732 vsw_mac_add_vlans(vswp, port->p_mch, macaddr,
740 D1(vswp, "%s: exit", __func__);
750 vsw_set_if_hw_addr(vsw_t *vswp)
760 D1(vswp, "%s: enter", __func__);
762 ASSERT(RW_WRITE_HELD(&vswp->maccl_rwlock));
763 if (vswp->mch == NULL)
766 macaddr = (uint8_t *)vswp->if_addr.ether_addr_octet;
769 mac_unicast_primary_get(vswp->mh, primary_addr);
779 if (vswp->pvid != vswp->default_vlan_id) {
780 vid = vswp->pvid;
783 if (!(vswp->smode & VSW_LAYER2_PROMISC)) {
787 if (vswp->addr_set == B_FALSE) {
788 vswp->muh = NULL;
789 rv = mac_unicast_add(vswp->mch, macaddr, mac_flags,
790 &vswp->muh, vid, &diag);
795 vswp->instance, ether_sprintf((void *)macaddr),
799 vswp->addr_set = B_TRUE;
801 D2(vswp, "%s:programmed macaddr(%s) vid(%d) into device %s",
803 vswp->physname);
806 vsw_mac_add_vlans(vswp, vswp->mch, macaddr, mac_flags,
807 vswp->vids, vswp->nvids);
809 vsw_maccl_set_bandwidth(vswp, NULL, VSW_LOCALDEV, vswp->bandwidth);
811 mac_rx_set(vswp->mch, vsw_if_rx_cb, (void *)vswp);
813 D1(vswp, "%s: exit", __func__);
824 vsw_unset_hw_addr(vsw_t *vswp, vsw_port_t *port, int type)
830 D1(vswp, "%s: enter", __func__);
840 ASSERT(RW_WRITE_HELD(&vswp->maccl_rwlock));
841 vids = vswp->vids;
842 nvids = vswp->nvids;
847 mch = vswp->mch;
862 if ((type == VSW_LOCALDEV) && (vswp->addr_set == B_TRUE)) {
863 (void) mac_unicast_remove(vswp->mch, vswp->muh);
864 vswp->muh = NULL;
865 D2(vswp, "removed vsw interface mac-addr from "
866 "the device %s", vswp->physname);
867 vswp->addr_set = B_FALSE;
872 D2(vswp, "removed port(0x%p) mac-addr from "
873 "the device %s", port, vswp->physname);
877 D1(vswp, "%s: exit", __func__);
891 vsw_t *vswp = (vsw_t *)arg;
895 ASSERT(vswp != NULL);
897 D1(vswp, "%s: enter", __func__);
899 READ_ENTER(&vswp->if_lockrw);
900 if (vswp->if_state & VSW_IF_UP) {
901 RW_EXIT(&vswp->if_lockrw);
902 count = vsw_vlan_frame_untag(vswp, VSW_LOCALDEV, &mp, &mpt);
904 mac_rx(vswp->if_mh, NULL, mp);
907 RW_EXIT(&vswp->if_lockrw);
911 D1(vswp, "%s: exit", __func__);
925 vsw_t *vswp;
930 vswp = port->p_vswp;
932 D1(vswp, "vsw_port_rx_cb: enter");
939 D1(vswp, "vsw_port_rx_cb: exit");
949 vsw_tx_msg(vsw_t *vswp, mblk_t *mp, int caller, vsw_port_t *port)
954 READ_MACCL_ENTER(vswp, port, caller);
956 mch = (caller == VSW_LOCALDEV) ? vswp->mch : port->p_mch;
957 muh = (caller == VSW_LOCALDEV) ? vswp->muh : port->p_muh;
960 RW_MACCL_EXIT(vswp, port, caller);
966 RW_MACCL_EXIT(vswp, port, caller);
990 vsw_t *vswp = portp->p_vswp;
993 D1(vswp, "%s: enter", __func__);
998 mutex_enter(&vswp->mac_lock);
1000 vsw_mac_multicast_remove_all(vswp, portp, VSW_VNETPORT);
1001 vsw_unset_hw(vswp, portp, VSW_VNETPORT);
1002 vsw_maccl_close(vswp, portp, VSW_VNETPORT);
1020 rv = vsw_maccl_open(vswp, portp, VSW_VNETPORT);
1025 if (vsw_set_hw(vswp, portp, VSW_VNETPORT)) {
1027 "set unicast address\n", vswp->instance, portp->p_instance);
1031 vsw_mac_multicast_add_all(vswp, portp, VSW_VNETPORT);
1035 mutex_exit(&vswp->mac_lock);
1036 D1(vswp, "%s: exit", __func__);
1048 vsw_if_mac_reconfig(vsw_t *vswp, boolean_t update_vlans,
1053 D1(vswp, "%s: enter", __func__);
1058 mutex_enter(&vswp->mac_lock);
1059 WRITE_ENTER(&vswp->maccl_rwlock);
1060 vsw_mac_multicast_remove_all(vswp, NULL, VSW_LOCALDEV);
1061 vsw_unset_hw(vswp, NULL, VSW_LOCALDEV);
1062 vsw_maccl_close(vswp, NULL, VSW_LOCALDEV);
1065 if (vswp->nvids != 0) {
1066 kmem_free(vswp->vids,
1067 sizeof (vsw_vlanid_t) * vswp->nvids);
1068 vswp->vids = NULL;
1069 vswp->nvids = 0;
1071 vswp->vids = new_vids;
1072 vswp->nvids = new_nvids;
1073 vswp->pvid = new_pvid;
1080 rv = vsw_maccl_open(vswp, NULL, VSW_LOCALDEV);
1085 if (vsw_set_hw(vswp, NULL, VSW_LOCALDEV)) {
1087 vswp->instance);
1091 vsw_mac_multicast_add_all(vswp, NULL, VSW_LOCALDEV);
1094 RW_EXIT(&vswp->maccl_rwlock);
1095 mutex_exit(&vswp->mac_lock);
1096 D1(vswp, "%s: exit", __func__);
1130 vsw_mac_add_vlans(vsw_t *vswp, mac_client_handle_t mch, uint8_t *macaddr,
1153 vswp->instance, ether_sprintf((void *)macaddr),
1157 D2(vswp, "%s:programmed macaddr(%s) vid(%d) "
1160 vidp->vl_vid, vswp->physname);
1198 vsw_publish_macaddr(vsw_t *vswp, vsw_port_t *portp)
1253 bp = vsw_tx_msg(vswp, bp, VSW_VNETPORT, portp);
1263 vsw_mac_set_mtu(vsw_t *vswp, uint32_t mtu)
1268 rv = mac_set_mtu(vswp->mh, mtu, &mtu_orig);
1273 vswp->instance, mtu, vswp->physname);
1278 vswp->mtu_physdev_orig = mtu_orig;
1286 vsw_notify_add(vsw_t *vswp)
1294 note = mac_no_notification(vswp->mh);
1296 vswp->phys_no_link_update = B_TRUE;
1298 vswp->phys_no_link_update = B_FALSE;
1304 vswp->phys_link_state = vswp->phys_no_link_update ? LINK_STATE_UP :
1305 mac_stat_get(vswp->mh, MAC_STAT_LINK_STATE);
1310 if (vswp->phys_no_link_update == B_TRUE) {
1314 mnh = mac_notify_add(vswp->mh, vsw_notify_cb, vswp);
1320 vswp->mnh = mnh;
1328 vsw_notify_rem(vsw_t *vswp)
1332 rv = mac_notify_remove(vswp->mnh, B_FALSE);
1343 vsw_t *vswp = arg;
1348 vsw_notify_link(vswp);
1362 vsw_notify_link(vsw_t *vswp)
1367 link_state = mac_stat_get(vswp->mh, MAC_STAT_LINK_STATE);
1369 if (vswp->phys_link_state != link_state) {
1370 D3(vswp, "%s: phys_link_state(%d)\n",
1371 __func__, vswp->phys_link_state);
1373 vswp->phys_link_state = link_state;
1374 vsw_physlink_state_update(vswp);
1385 vsw_maccl_set_bandwidth(vsw_t *vswp, vsw_port_t *port, int type, uint64_t maxbw)
1399 ASSERT(RW_WRITE_HELD(&vswp->maccl_rwlock));
1400 mch = vswp->mch;
1401 bw = &vswp->bandwidth;
1426 vswp->instance, maxbw, rv);