1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #pragma ident "%Z%%M% %I% %E% SMI" 27 28 #include <sys/types.h> 29 #include <sys/ddi.h> 30 #include <sys/sunddi.h> 31 #include <sys/stropts.h> 32 #include <sys/stream.h> 33 #include <sys/strsun.h> 34 #include <sys/strsubr.h> 35 #include <sys/socket.h> 36 #include <sys/stat.h> 37 #include <net/if_arp.h> 38 #include <sys/file.h> 39 #include <sys/sockio.h> 40 #include <sys/pathname.h> 41 #include <inet/arp.h> 42 #include <sys/modctl.h> 43 44 #include <sys/ib/mgt/ibcm/ibcm_arp.h> 45 46 #include <sys/kstr.h> 47 #include <sys/tiuser.h> 48 #include <sys/t_kuser.h> 49 50 extern char cmlog[]; 51 52 extern int ibcm_arp_pr_lookup(ibcm_arp_streams_t *ib_s, ibt_ip_addr_t *dst_addr, 53 ibt_ip_addr_t *src_addr, uint8_t localroute, uint32_t bound_dev_if, 54 ibcm_arp_pr_comp_func_t func); 55 extern void ibcm_arp_pr_arp_ack(mblk_t *mp); 56 extern void ibcm_arp_prwqn_delete(ibcm_arp_prwqn_t *wqnp); 57 58 _NOTE(SCHEME_PROTECTS_DATA("Unshared data", datab)) 59 _NOTE(SCHEME_PROTECTS_DATA("Unshared data", ibt_ip_addr_s)) 60 _NOTE(SCHEME_PROTECTS_DATA("Unshared data", ibcm_arp_ip_t)) 61 _NOTE(SCHEME_PROTECTS_DATA("Unshared data", ibcm_arp_ibd_insts_t)) 62 _NOTE(SCHEME_PROTECTS_DATA("Unshared data", ibcm_arp_prwqn_t)) 63 _NOTE(SCHEME_PROTECTS_DATA("Unshared data", iocblk)) 64 _NOTE(SCHEME_PROTECTS_DATA("Unshared data", msgb)) 65 _NOTE(SCHEME_PROTECTS_DATA("Unshared data", queue)) 66 _NOTE(SCHEME_PROTECTS_DATA("Unshared data", sockaddr_in)) 67 _NOTE(SCHEME_PROTECTS_DATA("Unshared data", sockaddr_in6)) 68 69 /* 70 * ibcm_arp_get_ibaddr_cb 71 */ 72 static int 73 ibcm_arp_get_ibaddr_cb(void *arg, int status) 74 { 75 ibcm_arp_prwqn_t *wqnp = (ibcm_arp_prwqn_t *)arg; 76 ibcm_arp_streams_t *ib_s = (ibcm_arp_streams_t *)wqnp->arg; 77 78 IBTF_DPRINTF_L4(cmlog, "ibcm_arp_get_ibaddr_cb(ib_s: %p wqnp: %p)", 79 ib_s, wqnp); 80 81 mutex_enter(&ib_s->lock); 82 ib_s->status = status; 83 ib_s->done = B_TRUE; 84 85 IBTF_DPRINTF_L3(cmlog, "ibcm_arp_get_ibaddr_cb: SGID %llX:%llX " 86 "DGID: %llX:%llX", wqnp->sgid.gid_prefix, wqnp->sgid.gid_guid, 87 wqnp->dgid.gid_prefix, wqnp->dgid.gid_guid); 88 89 /* lock is held by the caller. */ 90 cv_signal(&ib_s->cv); 91 mutex_exit(&ib_s->lock); 92 return (0); 93 } 94 95 /* 96 * Lower read service procedure (messages coming back from arp/ip). 97 * Process messages based on queue type. 98 */ 99 static int 100 ibcm_arp_lrsrv(queue_t *q) 101 { 102 mblk_t *mp; 103 ibcm_arp_streams_t *ib_s = q->q_ptr; 104 105 IBTF_DPRINTF_L4(cmlog, "ibcm_arp_lrsrv(%p, ibd_s: 0x%p)", q, ib_s); 106 107 if (WR(q) == ib_s->arpqueue) { 108 while (mp = getq(q)) { 109 ibcm_arp_pr_arp_ack(mp); 110 } 111 } else { 112 freemsg(mp); 113 } 114 115 return (0); 116 } 117 118 /* 119 * Lower write service procedure. 120 * Used when lower streams are flow controlled. 121 */ 122 static int 123 ibcm_arp_lwsrv(queue_t *q) 124 { 125 mblk_t *mp; 126 127 IBTF_DPRINTF_L4(cmlog, "ibcm_arp_lwsrv(%p)", q); 128 129 while (mp = getq(q)) { 130 if (canputnext(q)) { 131 putnext(q, mp); 132 } else { 133 (void) putbq(q, mp); 134 qenable(q); 135 break; 136 } 137 } 138 139 return (0); 140 } 141 142 /* 143 * Lower read put procedure. Arp/ip messages come here. 144 */ 145 static int 146 ibcm_arp_lrput(queue_t *q, mblk_t *mp) 147 { 148 IBTF_DPRINTF_L4(cmlog, "ibcm_arp_lrput(0x%p, db_type: %d)", 149 q, DB_TYPE(mp)); 150 151 switch (DB_TYPE(mp)) { 152 case M_FLUSH: 153 /* 154 * Turn around 155 */ 156 if (*mp->b_rptr & FLUSHW) { 157 *mp->b_rptr &= ~FLUSHR; 158 qreply(q, mp); 159 return (0); 160 } 161 freemsg(mp); 162 break; 163 case M_IOCACK: 164 case M_IOCNAK: 165 case M_DATA: 166 /* 167 * This could be in interrupt context. 168 * Some of the ibt calls cannot be called in 169 * interrupt context, so 170 * put it in the queue and the message will be 171 * processed by service proccedure 172 */ 173 (void) putq(q, mp); 174 qenable(q); 175 break; 176 default: 177 IBTF_DPRINTF_L2(cmlog, "ibcm_arp_lrput: " 178 "got unknown msg <0x%x>\n", mp->b_datap->db_type); 179 ASSERT(0); 180 break; 181 } 182 183 return (0); 184 } 185 186 /* 187 * Streams write queue module info 188 */ 189 static struct module_info ibcm_arp_winfo = { 190 0, /* module ID number */ 191 "ibcm", /* module name */ 192 0, /* min packet size */ 193 INFPSZ, 194 49152, /* STREAM queue high water mark -- 49152 */ 195 12 /* STREAM queue low water mark -- 12 */ 196 }; 197 198 /* 199 * Streams lower write queue, for ibcm/ip requests. 200 */ 201 static struct qinit ibcm_arp_lwinit = { 202 NULL, /* qi_putp */ 203 ibcm_arp_lwsrv, /* qi_srvp */ 204 NULL, /* qi_qopen */ 205 NULL, /* qi_qclose */ 206 NULL, /* qi_qadmin */ 207 &ibcm_arp_winfo, /* module info */ 208 NULL, /* module statistics struct */ 209 NULL, 210 NULL, 211 STRUIOT_NONE /* stream uio type is standard uiomove() */ 212 }; 213 214 /* 215 * Streams lower read queue: read reply messages from ibcm/ip. 216 */ 217 static struct qinit ibcm_arp_lrinit = { 218 ibcm_arp_lrput, /* qi_putp */ 219 ibcm_arp_lrsrv, /* qi_srvp */ 220 NULL, /* qi_qopen */ 221 NULL, /* qi_qclose */ 222 NULL, /* qi_qadmin */ 223 &ibcm_arp_winfo, /* module info */ 224 NULL, /* module statistics struct */ 225 NULL, 226 NULL, 227 STRUIOT_NONE /* stream uio type is standard uiomove() */ 228 }; 229 230 231 static int 232 ibcm_arp_link_driver(ibcm_arp_streams_t *ib_s, char *path, queue_t **q, 233 vnode_t **dev_vp) 234 { 235 struct stdata *dev_stp; 236 vnode_t *vp; 237 int error; 238 queue_t *rq; 239 240 IBTF_DPRINTF_L4(cmlog, "ibcm_arp_link_driver: Enter: %s", path); 241 242 /* open the driver from inside the kernel */ 243 error = vn_open(path, UIO_SYSSPACE, FREAD|FWRITE, 0, &vp, 244 0, NULL); 245 if (error) { 246 IBTF_DPRINTF_L2(cmlog, "ibcm_arp_link_driver: " 247 "vn_open('%s') failed\n", path); 248 return (error); 249 } 250 *dev_vp = vp; 251 252 dev_stp = vp->v_stream; 253 *q = dev_stp->sd_wrq; 254 255 VN_HOLD(vp); 256 257 rq = RD(dev_stp->sd_wrq); 258 RD(rq)->q_ptr = WR(rq)->q_ptr = ib_s; 259 setq(rq, &ibcm_arp_lrinit, &ibcm_arp_lwinit, NULL, QMTSAFE, 260 SQ_CI|SQ_CO, B_FALSE); 261 262 return (0); 263 } 264 265 extern struct qinit strdata; 266 extern struct qinit stwdata; 267 268 /* 269 * Unlink ip, ibcm, icmp6 drivers 270 */ 271 /* ARGSUSED */ 272 static int 273 ibcm_arp_unlink_driver(queue_t **q, vnode_t **dev_vp) 274 { 275 vnode_t *vp = *dev_vp; 276 struct stdata *dev_stp = vp->v_stream; 277 queue_t *wrq, *rq; 278 int rc; 279 280 IBTF_DPRINTF_L4(cmlog, "ibcm_arp_unlink_driver: Enter: 0x%p", q); 281 282 wrq = dev_stp->sd_wrq; 283 rq = RD(wrq); 284 285 disable_svc(rq); 286 wait_svc(rq); 287 flushq(rq, FLUSHALL); 288 flushq(WR(rq), FLUSHALL); 289 290 rq->q_ptr = wrq->q_ptr = dev_stp; 291 292 setq(rq, &strdata, &stwdata, NULL, QMTSAFE, SQ_CI|SQ_CO, B_TRUE); 293 294 if ((rc = VOP_CLOSE(vp, FREAD, 1, (offset_t)0, CRED(), NULL)) != 0) { 295 IBTF_DPRINTF_L2(cmlog, "ibcm_arp_unlink_driver: VOP_CLOSE " 296 "failed %d\n", rc); 297 } 298 vn_rele(vp); 299 300 return (0); 301 } 302 303 static int 304 ibcm_arp_unlink_drivers(ibcm_arp_streams_t *ib_s) 305 { 306 IBTF_DPRINTF_L4(cmlog, "ibcm_arp_unlink_drivers(%p)", ib_s); 307 308 if (ib_s->arpqueue) { 309 (void) ibcm_arp_unlink_driver(&ib_s->arpqueue, &ib_s->arp_vp); 310 } 311 312 return (0); 313 } 314 315 /* 316 * Link ip, ibtl drivers below ibtl 317 */ 318 static int 319 ibcm_arp_link_drivers(ibcm_arp_streams_t *ib_s) 320 { 321 int rc; 322 323 IBTF_DPRINTF_L4(cmlog, "ibcm_arp_link_drivers(%p)", ib_s); 324 325 if ((rc = ibcm_arp_link_driver(ib_s, "/dev/arp", &ib_s->arpqueue, 326 &ib_s->arp_vp)) != 0) { 327 IBTF_DPRINTF_L2(cmlog, "ibcm_arp_link_drivers: " 328 "ibcm_arp_link_driver failed: %d\n", rc); 329 return (rc); 330 } 331 332 return (0); 333 } 334 335 ibt_status_t 336 ibcm_arp_get_ibaddr(ipaddr_t srcip, ipaddr_t destip, ib_gid_t *sgid, 337 ib_gid_t *dgid) 338 { 339 ibcm_arp_streams_t *ib_s; 340 ibt_ip_addr_t srcaddr, destaddr; 341 int ret = 0; 342 343 IBTF_DPRINTF_L4(cmlog, "ibcm_arp_get_ibaddr(%lX, %lX, %p, %p)", 344 htonl(srcip), htonl(destip), sgid, dgid); 345 346 ib_s = (ibcm_arp_streams_t *)kmem_zalloc(sizeof (ibcm_arp_streams_t), 347 KM_SLEEP); 348 349 mutex_init(&ib_s->lock, NULL, MUTEX_DEFAULT, NULL); 350 cv_init(&ib_s->cv, NULL, CV_DRIVER, NULL); 351 352 ret = ibcm_arp_link_drivers(ib_s); 353 if (ret != 0) { 354 IBTF_DPRINTF_L3(cmlog, "ibcm_arp_get_ibaddr: " 355 "ibcm_arp_link_drivers failed %d", ret); 356 goto arp_ibaddr_error; 357 } 358 359 bzero(&destaddr, sizeof (ibt_ip_addr_t)); 360 bzero(&srcaddr, sizeof (ibt_ip_addr_t)); 361 362 mutex_enter(&ib_s->lock); 363 ib_s->done = B_FALSE; 364 mutex_exit(&ib_s->lock); 365 366 destaddr.family = AF_INET_OFFLOAD; 367 destaddr.un.ip4addr = htonl(destip); 368 srcaddr.family = AF_INET_OFFLOAD; 369 srcaddr.un.ip4addr = htonl(srcip); 370 371 IBTF_DPRINTF_L3(cmlog, "ibcm_arp_get_ibaddr: SrcIP %lX, DstIP %lX", 372 srcaddr.un.ip4addr, destaddr.un.ip4addr); 373 ret = ibcm_arp_pr_lookup(ib_s, &destaddr, &srcaddr, 0, NULL, 374 ibcm_arp_get_ibaddr_cb); 375 376 IBTF_DPRINTF_L3(cmlog, "ibcm_arp_get_ibaddr: ibcm_arp_pr_lookup " 377 "returned: %d", ret); 378 if (ret == 0) { 379 mutex_enter(&ib_s->lock); 380 while (ib_s->done != B_TRUE) 381 cv_wait(&ib_s->cv, &ib_s->lock); 382 mutex_exit(&ib_s->lock); 383 } 384 385 (void) ibcm_arp_unlink_drivers(ib_s); 386 mutex_enter(&ib_s->lock); 387 ret = ib_s->status; 388 if (ret == 0) { 389 ibcm_arp_prwqn_t *wqnp = ib_s->wqnp; 390 if (sgid) 391 *sgid = ib_s->wqnp->sgid; 392 if (dgid) 393 *dgid = ib_s->wqnp->dgid; 394 395 IBTF_DPRINTF_L4(cmlog, "ibcm_arp_get_ibaddr: SGID: %llX:%llX" 396 " DGID: %llX:%llX", 397 ib_s->wqnp->sgid.gid_prefix, ib_s->wqnp->sgid.gid_guid, 398 ib_s->wqnp->dgid.gid_prefix, ib_s->wqnp->dgid.gid_guid); 399 400 mutex_exit(&ib_s->lock); 401 ibcm_arp_prwqn_delete(wqnp); 402 mutex_enter(&ib_s->lock); 403 } 404 mutex_exit(&ib_s->lock); 405 406 arp_ibaddr_error: 407 408 mutex_destroy(&ib_s->lock); 409 cv_destroy(&ib_s->cv); 410 kmem_free(ib_s, sizeof (ibcm_arp_streams_t)); 411 412 if (ret) 413 return (IBT_FAILURE); 414 else 415 return (IBT_SUCCESS); 416 } 417 418 419 /* 420 * Routine to get list of "local" IP-ADDR to GID/P_KEY mapping information. 421 * Optionally, if "gid" and/or "p_key" info are specified, then retrieve the 422 * IP-ADDR info for that attribute only. 423 */ 424 425 static ibcm_arp_ip_t * 426 ibcm_arp_ibd_gid2mac(ib_gid_t *gid, ib_pkey_t pkey, ibcm_arp_ibd_insts_t *ibdp) 427 { 428 ibcm_arp_ip_t *ipp; 429 int i; 430 431 for (i = 0, ipp = ibdp->ibcm_arp_ip; i < ibdp->ibcm_arp_ibd_cnt; 432 i++, ipp++) { 433 if ((ipp->ip_port_gid.gid_prefix == gid->gid_prefix) && 434 (ipp->ip_port_gid.gid_guid == gid->gid_guid)) { 435 if (pkey) { 436 if (ipp->ip_pkey == pkey) 437 return (ipp); 438 else 439 continue; 440 } 441 return (ipp); 442 } 443 } 444 return (NULL); 445 } 446 447 static ibt_status_t 448 ibcm_arp_ibd_mac2gid(ibcm_arp_ibd_insts_t *ibdp, ipaddr_t srcip, 449 ib_gid_t *sgid) 450 { 451 ibcm_arp_ip_t *ipp; 452 int i; 453 454 for (i = 0, ipp = ibdp->ibcm_arp_ip; i < ibdp->ibcm_arp_ibd_cnt; 455 i++, ipp++) { 456 457 IBTF_DPRINTF_L4(cmlog, "ibcm_arp_ibd_mac2gid: Is %lX == %lX " 458 "GID %llX:%llX", srcip, ipp->ip_cm_sin.sin_addr, 459 ipp->ip_port_gid.gid_prefix, ipp->ip_port_gid.gid_guid); 460 461 if (bcmp(&srcip, &ipp->ip_cm_sin.sin_addr, sizeof (in_addr_t)) 462 == 0) { 463 *sgid = ipp->ip_port_gid; 464 465 IBTF_DPRINTF_L4(cmlog, "ibcm_arp_ibd_mac2gid: Found " 466 "GID %llX:%llX", sgid->gid_prefix, sgid->gid_guid); 467 return (IBT_SUCCESS); 468 } 469 } 470 IBTF_DPRINTF_L3(cmlog, "ibcm_arp_ibd_mac2gid: Matching SRC info " 471 "NOT Found"); 472 return (IBT_SRC_IP_NOT_FOUND); 473 } 474 475 static int 476 ibcm_arp_get_ibd_insts_cb(dev_info_t *dip, void *arg) 477 { 478 ibcm_arp_ibd_insts_t *ibds = (ibcm_arp_ibd_insts_t *)arg; 479 ibcm_arp_ip_t *ipp; 480 ib_pkey_t pkey; 481 uint8_t port; 482 ib_guid_t hca_guid; 483 ib_gid_t port_gid; 484 485 if (i_ddi_devi_attached(dip) && 486 (strcmp(ddi_node_name(dip), "ibport") == 0) && 487 (strstr(ddi_get_name_addr(dip), "ipib") != NULL)) { 488 489 if (ibds->ibcm_arp_ibd_cnt >= ibds->ibcm_arp_ibd_alloc) { 490 ibcm_arp_ip_t *tmp = NULL; 491 int new_count = 0; 492 493 new_count = ibds->ibcm_arp_ibd_alloc + 494 IBCM_ARP_IBD_INSTANCES; 495 496 tmp = (ibcm_arp_ip_t *)kmem_zalloc( 497 new_count * sizeof (ibcm_arp_ip_t), KM_SLEEP); 498 bcopy(ibds->ibcm_arp_ip, tmp, 499 ibds->ibcm_arp_ibd_alloc * sizeof (ibcm_arp_ip_t)); 500 kmem_free(ibds->ibcm_arp_ip, 501 ibds->ibcm_arp_ibd_alloc * sizeof (ibcm_arp_ip_t)); 502 ibds->ibcm_arp_ibd_alloc = new_count; 503 ibds->ibcm_arp_ip = tmp; 504 } 505 506 if (((hca_guid = ddi_prop_get_int64(DDI_DEV_T_ANY, dip, 0, 507 "hca-guid", 0)) == 0) || 508 ((port = ddi_prop_get_int(DDI_DEV_T_ANY, dip, 0, 509 "port-number", 0)) == 0) || 510 (ibt_get_port_state_byguid(hca_guid, port, &port_gid, 511 NULL) != IBT_SUCCESS) || 512 ((pkey = ddi_prop_get_int(DDI_DEV_T_ANY, dip, 0, 513 "port-pkey", IB_PKEY_INVALID_LIMITED)) <= 514 IB_PKEY_INVALID_FULL)) { 515 return (DDI_WALK_CONTINUE); 516 } 517 518 ipp = &ibds->ibcm_arp_ip[ibds->ibcm_arp_ibd_cnt]; 519 ipp->ip_inst = ddi_get_instance(dip); 520 ipp->ip_pkey = pkey; 521 ipp->ip_hca_guid = hca_guid; 522 ipp->ip_port_gid = port_gid; 523 ibds->ibcm_arp_ibd_cnt++; 524 } 525 return (DDI_WALK_CONTINUE); 526 } 527 528 static void 529 ibcm_arp_get_ibd_insts(ibcm_arp_ibd_insts_t *ibds) 530 { 531 ddi_walk_devs(ddi_root_node(), ibcm_arp_get_ibd_insts_cb, ibds); 532 } 533 534 /* 535 * Return ibd interfaces and ibd instances. 536 */ 537 static int 538 ibcm_arp_get_ibd_ipaddr(ibcm_arp_ibd_insts_t *ibds) 539 { 540 TIUSER *tiptr; 541 vnode_t *kvp; 542 vnode_t *vp = NULL; 543 struct strioctl iocb; 544 struct lifreq lif_req; 545 int k, ip_cnt; 546 ibcm_arp_ip_t *ipp; 547 548 if (lookupname("/dev/udp", UIO_SYSSPACE, FOLLOW, NULLVPP, &kvp) == 0) { 549 if (t_kopen((file_t *)NULL, kvp->v_rdev, FREAD|FWRITE, 550 &tiptr, CRED()) == 0) { 551 vp = tiptr->fp->f_vnode; 552 } else { 553 VN_RELE(kvp); 554 } 555 } 556 557 if (vp == NULL) 558 return (-1); 559 560 /* Get ibd ip's */ 561 ip_cnt = 0; 562 for (k = 0, ipp = ibds->ibcm_arp_ip; k < ibds->ibcm_arp_ibd_cnt; 563 k++, ipp++) { 564 565 (void) bzero((void *)&lif_req, sizeof (struct lifreq)); 566 (void) snprintf(lif_req.lifr_name, sizeof (lif_req.lifr_name), 567 "%s%d", IBCM_ARP_IBD_NAME, ipp->ip_inst); 568 569 (void) bzero((void *)&iocb, sizeof (struct strioctl)); 570 iocb.ic_cmd = SIOCGLIFADDR; 571 iocb.ic_timout = 0; 572 iocb.ic_len = sizeof (struct lifreq); 573 iocb.ic_dp = (caddr_t)&lif_req; 574 575 if (kstr_ioctl(vp, I_STR, (intptr_t)&iocb) == 0) { 576 ipp->ip_inet_family = AF_INET; 577 bcopy(&lif_req.lifr_addr, &ipp->ip_cm_sin, 578 sizeof (struct sockaddr_in)); 579 ip_cnt++; 580 continue; 581 } 582 } 583 584 (void) t_kclose(tiptr, 0); 585 VN_RELE(kvp); 586 587 if (ip_cnt == 0) 588 return (-1); 589 else 590 return (0); 591 } 592 593 ibt_status_t 594 ibcm_arp_get_ibds(ibcm_arp_ibd_insts_t *ibdp) 595 { 596 IBTF_DPRINTF_L4(cmlog, "ibcm_arp_get_ibds(%p)", ibdp); 597 598 ibcm_arp_get_ibd_insts(ibdp); 599 600 IBTF_DPRINTF_L3(cmlog, "ibcm_arp_get_ibds: Found %d ibd instances", 601 ibdp->ibcm_arp_ibd_cnt); 602 603 if (ibdp->ibcm_arp_ibd_cnt == 0) 604 return (IBT_SRC_IP_NOT_FOUND); 605 606 /* Get the IP addresses of active ports. */ 607 if (ibcm_arp_get_ibd_ipaddr(ibdp) != 0) { 608 IBTF_DPRINTF_L2(cmlog, "ibcm_arp_get_ibds: failed to get " 609 "ibd instance: IBT_SRC_IP_NOT_FOUND"); 610 return (IBT_SRC_IP_NOT_FOUND); 611 } 612 613 return (IBT_SUCCESS); 614 } 615 616 _NOTE(SCHEME_PROTECTS_DATA("Unshared data", ibtl_cm_port_list_t)) 617 618 ibt_status_t 619 ibcm_arp_get_srcip_plist(ibt_ip_path_attr_t *ipattr, ibt_path_flags_t flags, 620 ibtl_cm_port_list_t **port_list_p) 621 { 622 ibt_path_attr_t attr; 623 ibt_status_t ret; 624 ibcm_arp_ibd_insts_t ibds; 625 ibcm_arp_ip_t *ipp; 626 ibtl_cm_port_list_t *plistp; 627 ib_gid_t sgid; 628 629 IBTF_DPRINTF_L4(cmlog, "ibcm_arp_get_srcip_plist(%p, %llX)", 630 ipattr, flags); 631 632 sgid.gid_prefix = sgid.gid_guid = 0; 633 bzero(&ibds, sizeof (ibcm_arp_ibd_insts_t)); 634 ibds.ibcm_arp_ibd_alloc = IBCM_ARP_IBD_INSTANCES; 635 ibds.ibcm_arp_ibd_cnt = 0; 636 ibds.ibcm_arp_ip = (ibcm_arp_ip_t *)kmem_zalloc( 637 ibds.ibcm_arp_ibd_alloc * sizeof (ibcm_arp_ip_t), KM_SLEEP); 638 639 ret = ibcm_arp_get_ibds(&ibds); 640 if (ret != IBT_SUCCESS) { 641 IBTF_DPRINTF_L2(cmlog, "ibcm_arp_get_srcip_plist: " 642 "ibcm_arp_get_ibds failed : 0x%x", ret); 643 goto srcip_plist_end; 644 } 645 646 if (ipattr->ipa_src_ip.family != AF_UNSPEC) { 647 ret = ibcm_arp_ibd_mac2gid(&ibds, 648 htonl(ipattr->ipa_src_ip.un.ip4addr), &sgid); 649 if (ret != IBT_SUCCESS) { 650 IBTF_DPRINTF_L2(cmlog, "ibcm_arp_get_srcip_plist: " 651 "SGID for the specified SRCIP Not found %X", ret); 652 goto srcip_plist_end; 653 } 654 IBTF_DPRINTF_L4(cmlog, "ibcm_arp_get_srcip_plist: SGID " 655 "%llX:%llX", sgid.gid_prefix, sgid.gid_guid); 656 } 657 658 bzero(&attr, sizeof (ibt_path_attr_t)); 659 attr.pa_hca_guid = ipattr->ipa_hca_guid; 660 attr.pa_hca_port_num = ipattr->ipa_hca_port_num; 661 attr.pa_sgid = sgid; 662 bcopy(&ipattr->ipa_mtu, &attr.pa_mtu, sizeof (ibt_mtu_req_t)); 663 bcopy(&ipattr->ipa_srate, &attr.pa_srate, sizeof (ibt_srate_req_t)); 664 bcopy(&ipattr->ipa_pkt_lt, &attr.pa_pkt_lt, sizeof (ibt_pkt_lt_req_t)); 665 666 ret = ibtl_cm_get_active_plist(&attr, flags, port_list_p); 667 if (ret == IBT_SUCCESS) { 668 int i; 669 670 plistp = port_list_p[0]; 671 for (i = 0; i < plistp->p_count; i++, plistp++) { 672 ipp = ibcm_arp_ibd_gid2mac(&plistp->p_sgid, 0, &ibds); 673 if (ipp == NULL) 674 plistp->p_src_ip.family = AF_UNSPEC; 675 else { 676 IBTF_DPRINTF_L4(cmlog, 677 "ibcm_arp_get_srcip_plist: GID %llX:%llX", 678 plistp->p_sgid.gid_prefix, 679 plistp->p_sgid.gid_guid); 680 if (ipp->ip_inet_family == AF_INET) { 681 plistp->p_src_ip.family = AF_INET; 682 bcopy(&ipp->ip_cm_sin.sin_addr, 683 &plistp->p_src_ip.un.ip4addr, 684 sizeof (in_addr_t)); 685 686 IBTF_DPRINTF_L4(cmlog, 687 "ibcm_arp_get_srcip_plist: SrcIP: " 688 "%lX", plistp->p_src_ip.un.ip4addr); 689 } else if (ipp->ip_inet_family == AF_INET6) { 690 plistp->p_src_ip.family = AF_INET6; 691 bcopy(&ipp->ip_cm_sin6.sin6_addr, 692 &plistp->p_src_ip.un.ip6addr, 693 sizeof (in6_addr_t)); 694 } 695 } 696 } 697 } 698 699 srcip_plist_end: 700 if (ibds.ibcm_arp_ip) 701 kmem_free(ibds.ibcm_arp_ip, ibds.ibcm_arp_ibd_alloc * 702 sizeof (ibcm_arp_ip_t)); 703 704 return (ret); 705 } 706 /* Routines for warlock */ 707 708 /* ARGSUSED */ 709 static int 710 ibcm_arp_dummy_ibaddr_hdl(void *arg, int status) 711 { 712 ibcm_arp_prwqn_t dummy_wqn1; 713 ibcm_arp_prwqn_t dummy_wqn2; 714 715 dummy_wqn1.func = ibcm_arp_get_ibaddr_cb; 716 dummy_wqn2.func = ibcm_arp_dummy_ibaddr_hdl; 717 718 IBTF_DPRINTF_L5(cmlog, "ibcm_arp_dummy_ibaddr_hdl: " 719 "dummy_wqn1.func %p %p", dummy_wqn1.func, dummy_wqn2.func); 720 721 return (0); 722 } 723