1*1cfa752fSRamaswamy Tummala /* 2*1cfa752fSRamaswamy Tummala * CDDL HEADER START 3*1cfa752fSRamaswamy Tummala * 4*1cfa752fSRamaswamy Tummala * The contents of this file are subject to the terms of the 5*1cfa752fSRamaswamy Tummala * Common Development and Distribution License (the "License"). 6*1cfa752fSRamaswamy Tummala * You may not use this file except in compliance with the License. 7*1cfa752fSRamaswamy Tummala * 8*1cfa752fSRamaswamy Tummala * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*1cfa752fSRamaswamy Tummala * or http://www.opensolaris.org/os/licensing. 10*1cfa752fSRamaswamy Tummala * See the License for the specific language governing permissions 11*1cfa752fSRamaswamy Tummala * and limitations under the License. 12*1cfa752fSRamaswamy Tummala * 13*1cfa752fSRamaswamy Tummala * When distributing Covered Code, include this CDDL HEADER in each 14*1cfa752fSRamaswamy Tummala * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*1cfa752fSRamaswamy Tummala * If applicable, add the following below this CDDL HEADER, with the 16*1cfa752fSRamaswamy Tummala * fields enclosed by brackets "[]" replaced with your own identifying 17*1cfa752fSRamaswamy Tummala * information: Portions Copyright [yyyy] [name of copyright owner] 18*1cfa752fSRamaswamy Tummala * 19*1cfa752fSRamaswamy Tummala * CDDL HEADER END 20*1cfa752fSRamaswamy Tummala */ 21*1cfa752fSRamaswamy Tummala /* 22*1cfa752fSRamaswamy Tummala * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 23*1cfa752fSRamaswamy Tummala */ 24*1cfa752fSRamaswamy Tummala 25*1cfa752fSRamaswamy Tummala #include <stdio.h> 26*1cfa752fSRamaswamy Tummala #include <libdevinfo.h> 27*1cfa752fSRamaswamy Tummala #include <sys/types.h> 28*1cfa752fSRamaswamy Tummala #include <sys/stat.h> 29*1cfa752fSRamaswamy Tummala #include <string.h> 30*1cfa752fSRamaswamy Tummala #include <fcntl.h> 31*1cfa752fSRamaswamy Tummala #include <unistd.h> 32*1cfa752fSRamaswamy Tummala #include <stropts.h> 33*1cfa752fSRamaswamy Tummala #include <stdlib.h> 34*1cfa752fSRamaswamy Tummala #include <errno.h> 35*1cfa752fSRamaswamy Tummala #include <strings.h> 36*1cfa752fSRamaswamy Tummala #include <libintl.h> 37*1cfa752fSRamaswamy Tummala #include <net/if_types.h> 38*1cfa752fSRamaswamy Tummala #include <net/if_dl.h> 39*1cfa752fSRamaswamy Tummala #include <sys/dld.h> 40*1cfa752fSRamaswamy Tummala #include <sys/ib/ib_types.h> 41*1cfa752fSRamaswamy Tummala #include <sys/ibpart.h> 42*1cfa752fSRamaswamy Tummala #include <libdllink.h> 43*1cfa752fSRamaswamy Tummala #include <libdladm.h> 44*1cfa752fSRamaswamy Tummala #include <libdlib.h> 45*1cfa752fSRamaswamy Tummala #include <libdladm_impl.h> 46*1cfa752fSRamaswamy Tummala 47*1cfa752fSRamaswamy Tummala /* 48*1cfa752fSRamaswamy Tummala * IP over IB administration API; see PSARC/2010/085 49*1cfa752fSRamaswamy Tummala */ 50*1cfa752fSRamaswamy Tummala 51*1cfa752fSRamaswamy Tummala /* 52*1cfa752fSRamaswamy Tummala * Function prototypes 53*1cfa752fSRamaswamy Tummala */ 54*1cfa752fSRamaswamy Tummala dladm_status_t dladm_part_create(dladm_handle_t, datalink_id_t, ib_pkey_t, 55*1cfa752fSRamaswamy Tummala uint32_t, char *, datalink_id_t *, dladm_arg_list_t *); 56*1cfa752fSRamaswamy Tummala static int dladm_ibd_get_instance(char *); 57*1cfa752fSRamaswamy Tummala static dladm_status_t i_dladm_part_create(dladm_handle_t, 58*1cfa752fSRamaswamy Tummala dladm_part_attr_t *); 59*1cfa752fSRamaswamy Tummala dladm_status_t dladm_part_persist_conf(dladm_handle_t, dladm_part_attr_t *); 60*1cfa752fSRamaswamy Tummala static dladm_status_t i_dladm_part_delete(dladm_handle_t, datalink_id_t); 61*1cfa752fSRamaswamy Tummala dladm_status_t dladm_part_delete(dladm_handle_t, datalink_id_t, int); 62*1cfa752fSRamaswamy Tummala static int i_dladm_part_up(dladm_handle_t, datalink_id_t, void *); 63*1cfa752fSRamaswamy Tummala dladm_status_t dladm_part_up(dladm_handle_t, datalink_id_t, uint32_t); 64*1cfa752fSRamaswamy Tummala 65*1cfa752fSRamaswamy Tummala /* 66*1cfa752fSRamaswamy Tummala * Convert a error status returned by the IP over IB kernel driver to a 67*1cfa752fSRamaswamy Tummala * valid dladm status. 68*1cfa752fSRamaswamy Tummala */ 69*1cfa752fSRamaswamy Tummala static dladm_status_t 70*1cfa752fSRamaswamy Tummala dladm_ib_ioctl_err2status(int err) 71*1cfa752fSRamaswamy Tummala { 72*1cfa752fSRamaswamy Tummala switch (err) { 73*1cfa752fSRamaswamy Tummala case 0: 74*1cfa752fSRamaswamy Tummala return (DLADM_STATUS_OK); 75*1cfa752fSRamaswamy Tummala case IBD_INVALID_PORT_INST: 76*1cfa752fSRamaswamy Tummala return (DLADM_STATUS_INVALID_PORT_INSTANCE); 77*1cfa752fSRamaswamy Tummala case IBD_PORT_IS_DOWN: 78*1cfa752fSRamaswamy Tummala return (DLADM_STATUS_PORT_IS_DOWN); 79*1cfa752fSRamaswamy Tummala case IBD_PKEY_NOT_PRESENT: 80*1cfa752fSRamaswamy Tummala return (DLADM_STATUS_PKEY_NOT_PRESENT); 81*1cfa752fSRamaswamy Tummala case IBD_PARTITION_EXISTS: 82*1cfa752fSRamaswamy Tummala return (DLADM_STATUS_PARTITION_EXISTS); 83*1cfa752fSRamaswamy Tummala case IBD_INVALID_PKEY: 84*1cfa752fSRamaswamy Tummala return (DLADM_STATUS_INVALID_PKEY); 85*1cfa752fSRamaswamy Tummala case IBD_NO_HW_RESOURCE: 86*1cfa752fSRamaswamy Tummala return (DLADM_STATUS_NO_IB_HW_RESOURCE); 87*1cfa752fSRamaswamy Tummala case IBD_INVALID_PKEY_TBL_SIZE: 88*1cfa752fSRamaswamy Tummala return (DLADM_STATUS_INVALID_PKEY_TBL_SIZE); 89*1cfa752fSRamaswamy Tummala default: 90*1cfa752fSRamaswamy Tummala return (DLADM_STATUS_FAILED); 91*1cfa752fSRamaswamy Tummala } 92*1cfa752fSRamaswamy Tummala } 93*1cfa752fSRamaswamy Tummala 94*1cfa752fSRamaswamy Tummala static dladm_status_t 95*1cfa752fSRamaswamy Tummala i_dladm_ib_ioctl(dladm_handle_t handle, int ioccmd, ibd_ioctl_t *iocp) 96*1cfa752fSRamaswamy Tummala { 97*1cfa752fSRamaswamy Tummala if (ioctl(dladm_dld_fd(handle), ioccmd, iocp) == 0) 98*1cfa752fSRamaswamy Tummala return (DLADM_STATUS_OK); 99*1cfa752fSRamaswamy Tummala 100*1cfa752fSRamaswamy Tummala if (iocp->ioc_status == 0) 101*1cfa752fSRamaswamy Tummala return (dladm_errno2status(errno)); 102*1cfa752fSRamaswamy Tummala 103*1cfa752fSRamaswamy Tummala return (dladm_ib_ioctl_err2status(iocp->ioc_status)); 104*1cfa752fSRamaswamy Tummala } 105*1cfa752fSRamaswamy Tummala 106*1cfa752fSRamaswamy Tummala /* 107*1cfa752fSRamaswamy Tummala * Get the active configuration information for the partition given by 108*1cfa752fSRamaswamy Tummala * the 'linkid'. 109*1cfa752fSRamaswamy Tummala */ 110*1cfa752fSRamaswamy Tummala static dladm_status_t 111*1cfa752fSRamaswamy Tummala i_dladm_part_info_active(dladm_handle_t handle, datalink_id_t linkid, 112*1cfa752fSRamaswamy Tummala dladm_part_attr_t *attrp) 113*1cfa752fSRamaswamy Tummala { 114*1cfa752fSRamaswamy Tummala ibpart_ioctl_t ioc; 115*1cfa752fSRamaswamy Tummala dladm_status_t status = DLADM_STATUS_OK; 116*1cfa752fSRamaswamy Tummala 117*1cfa752fSRamaswamy Tummala bzero(&ioc, sizeof (ioc)); 118*1cfa752fSRamaswamy Tummala bzero(attrp, sizeof (*attrp)); 119*1cfa752fSRamaswamy Tummala /* 120*1cfa752fSRamaswamy Tummala * The ioc_linkid here will contain the data link id of the IB partition 121*1cfa752fSRamaswamy Tummala * object. 122*1cfa752fSRamaswamy Tummala */ 123*1cfa752fSRamaswamy Tummala ioc.ibdioc.ioc_linkid = linkid; 124*1cfa752fSRamaswamy Tummala ioc.ibdioc.ioc_info_cmd = IBD_INFO_CMD_IBPART; 125*1cfa752fSRamaswamy Tummala 126*1cfa752fSRamaswamy Tummala status = i_dladm_ib_ioctl(handle, IBD_INFO_IBPART, (ibd_ioctl_t *)&ioc); 127*1cfa752fSRamaswamy Tummala if (status != DLADM_STATUS_OK) 128*1cfa752fSRamaswamy Tummala goto bail; 129*1cfa752fSRamaswamy Tummala 130*1cfa752fSRamaswamy Tummala /* 131*1cfa752fSRamaswamy Tummala * On return from the ioctl ioc_linkid field contains the IB port's 132*1cfa752fSRamaswamy Tummala * linkid. 133*1cfa752fSRamaswamy Tummala */ 134*1cfa752fSRamaswamy Tummala attrp->dia_physlinkid = ioc.ibdioc.ioc_linkid; 135*1cfa752fSRamaswamy Tummala attrp->dia_partlinkid = ioc.ioc_partid; 136*1cfa752fSRamaswamy Tummala attrp->dia_pkey = ioc.ioc_pkey; 137*1cfa752fSRamaswamy Tummala attrp->dia_portnum = ioc.ibdioc.ioc_portnum; 138*1cfa752fSRamaswamy Tummala attrp->dia_hca_guid = ioc.ibdioc.ioc_hcaguid; 139*1cfa752fSRamaswamy Tummala attrp->dia_port_guid = ioc.ibdioc.ioc_portguid; 140*1cfa752fSRamaswamy Tummala attrp->dia_instance = ioc.ibdioc.ioc_port_inst; 141*1cfa752fSRamaswamy Tummala 142*1cfa752fSRamaswamy Tummala /* 143*1cfa752fSRamaswamy Tummala * If the IP over IB driver reports that this partition was created 144*1cfa752fSRamaswamy Tummala * forcibly, then set the force create flag. 145*1cfa752fSRamaswamy Tummala */ 146*1cfa752fSRamaswamy Tummala if (ioc.ioc_force_create) 147*1cfa752fSRamaswamy Tummala attrp->dia_flags |= DLADM_IBPART_FORCE_CREATE; 148*1cfa752fSRamaswamy Tummala 149*1cfa752fSRamaswamy Tummala bail: 150*1cfa752fSRamaswamy Tummala return (status); 151*1cfa752fSRamaswamy Tummala } 152*1cfa752fSRamaswamy Tummala 153*1cfa752fSRamaswamy Tummala /* 154*1cfa752fSRamaswamy Tummala * Get the configuration information about the IB partition 'linkid' from the 155*1cfa752fSRamaswamy Tummala * persistent configuration. 156*1cfa752fSRamaswamy Tummala */ 157*1cfa752fSRamaswamy Tummala static dladm_status_t 158*1cfa752fSRamaswamy Tummala i_dladm_part_info_persist(dladm_handle_t handle, datalink_id_t linkid, 159*1cfa752fSRamaswamy Tummala dladm_part_attr_t *attrp) 160*1cfa752fSRamaswamy Tummala { 161*1cfa752fSRamaswamy Tummala dladm_conf_t conf; 162*1cfa752fSRamaswamy Tummala dladm_status_t status; 163*1cfa752fSRamaswamy Tummala char linkover[MAXLINKNAMELEN]; 164*1cfa752fSRamaswamy Tummala datalink_class_t class; 165*1cfa752fSRamaswamy Tummala boolean_t force = B_FALSE; 166*1cfa752fSRamaswamy Tummala 167*1cfa752fSRamaswamy Tummala /* Get the IB partition's datalink ID */ 168*1cfa752fSRamaswamy Tummala if ((status = dladm_datalink_id2info(handle, linkid, NULL, &class, 169*1cfa752fSRamaswamy Tummala NULL, NULL, 0)) != DLADM_STATUS_OK) 170*1cfa752fSRamaswamy Tummala goto done; 171*1cfa752fSRamaswamy Tummala 172*1cfa752fSRamaswamy Tummala bzero(attrp, sizeof (*attrp)); 173*1cfa752fSRamaswamy Tummala attrp->dia_partlinkid = linkid; 174*1cfa752fSRamaswamy Tummala if ((status = dladm_read_conf(handle, linkid, &conf)) != 175*1cfa752fSRamaswamy Tummala DLADM_STATUS_OK) 176*1cfa752fSRamaswamy Tummala return (status); 177*1cfa752fSRamaswamy Tummala 178*1cfa752fSRamaswamy Tummala /* 179*1cfa752fSRamaswamy Tummala * Get the name of the IB Phys link over which IB partition was 180*1cfa752fSRamaswamy Tummala * created. 181*1cfa752fSRamaswamy Tummala */ 182*1cfa752fSRamaswamy Tummala status = dladm_get_conf_field(handle, conf, FLINKOVER, linkover, 183*1cfa752fSRamaswamy Tummala sizeof (linkover)); 184*1cfa752fSRamaswamy Tummala if (status != DLADM_STATUS_OK) { 185*1cfa752fSRamaswamy Tummala attrp->dia_physlinkid = DATALINK_INVALID_LINKID; 186*1cfa752fSRamaswamy Tummala goto done; 187*1cfa752fSRamaswamy Tummala } else { 188*1cfa752fSRamaswamy Tummala /* Get the IB Phys link's datalink ID */ 189*1cfa752fSRamaswamy Tummala if ((status = dladm_name2info(handle, linkover, 190*1cfa752fSRamaswamy Tummala &attrp->dia_physlinkid, NULL, NULL, NULL)) != 191*1cfa752fSRamaswamy Tummala DLADM_STATUS_OK) 192*1cfa752fSRamaswamy Tummala goto done; 193*1cfa752fSRamaswamy Tummala } 194*1cfa752fSRamaswamy Tummala 195*1cfa752fSRamaswamy Tummala /* Get the IB partition's P_Key */ 196*1cfa752fSRamaswamy Tummala status = dladm_get_conf_field(handle, conf, FPORTPKEY, 197*1cfa752fSRamaswamy Tummala &attrp->dia_pkey, sizeof (uint64_t)); 198*1cfa752fSRamaswamy Tummala if (status != DLADM_STATUS_OK) 199*1cfa752fSRamaswamy Tummala goto done; 200*1cfa752fSRamaswamy Tummala 201*1cfa752fSRamaswamy Tummala if (class != DATALINK_CLASS_PART) { 202*1cfa752fSRamaswamy Tummala status = DLADM_STATUS_BADARG; 203*1cfa752fSRamaswamy Tummala goto done; 204*1cfa752fSRamaswamy Tummala } 205*1cfa752fSRamaswamy Tummala 206*1cfa752fSRamaswamy Tummala /* 207*1cfa752fSRamaswamy Tummala * If the FFORCE field is set in the persistent configuration database 208*1cfa752fSRamaswamy Tummala * set the force create flag in the partition attributes. 209*1cfa752fSRamaswamy Tummala */ 210*1cfa752fSRamaswamy Tummala status = dladm_get_conf_field(handle, conf, FFORCE, &force, 211*1cfa752fSRamaswamy Tummala sizeof (boolean_t)); 212*1cfa752fSRamaswamy Tummala if (status != DLADM_STATUS_OK) { 213*1cfa752fSRamaswamy Tummala if (status != DLADM_STATUS_NOTFOUND) 214*1cfa752fSRamaswamy Tummala goto done; 215*1cfa752fSRamaswamy Tummala } else if (force == B_TRUE) { 216*1cfa752fSRamaswamy Tummala attrp->dia_flags |= DLADM_IBPART_FORCE_CREATE; 217*1cfa752fSRamaswamy Tummala } 218*1cfa752fSRamaswamy Tummala 219*1cfa752fSRamaswamy Tummala status = DLADM_STATUS_OK; 220*1cfa752fSRamaswamy Tummala done: 221*1cfa752fSRamaswamy Tummala dladm_destroy_conf(handle, conf); 222*1cfa752fSRamaswamy Tummala return (status); 223*1cfa752fSRamaswamy Tummala } 224*1cfa752fSRamaswamy Tummala 225*1cfa752fSRamaswamy Tummala /* 226*1cfa752fSRamaswamy Tummala * Get the configuration information for the IB partition given by the datalink 227*1cfa752fSRamaswamy Tummala * ID 'linkid'. Based on the 'flags' field the information is either from the 228*1cfa752fSRamaswamy Tummala * active system (DLADM_OPT_ACTIVE) or from the persistent configuration 229*1cfa752fSRamaswamy Tummala * database. 230*1cfa752fSRamaswamy Tummala */ 231*1cfa752fSRamaswamy Tummala dladm_status_t 232*1cfa752fSRamaswamy Tummala dladm_part_info(dladm_handle_t handle, datalink_id_t linkid, 233*1cfa752fSRamaswamy Tummala dladm_part_attr_t *attrp, uint32_t flags) 234*1cfa752fSRamaswamy Tummala { 235*1cfa752fSRamaswamy Tummala if (flags == DLADM_OPT_ACTIVE) 236*1cfa752fSRamaswamy Tummala return (i_dladm_part_info_active(handle, linkid, attrp)); 237*1cfa752fSRamaswamy Tummala else if (flags == DLADM_OPT_PERSIST) 238*1cfa752fSRamaswamy Tummala return (i_dladm_part_info_persist(handle, linkid, attrp)); 239*1cfa752fSRamaswamy Tummala else 240*1cfa752fSRamaswamy Tummala return (DLADM_STATUS_BADARG); 241*1cfa752fSRamaswamy Tummala } 242*1cfa752fSRamaswamy Tummala 243*1cfa752fSRamaswamy Tummala /* 244*1cfa752fSRamaswamy Tummala * Get the configuration information for the IB Phys link given by the datalink 245*1cfa752fSRamaswamy Tummala * ID 'linkid'. 246*1cfa752fSRamaswamy Tummala */ 247*1cfa752fSRamaswamy Tummala /* ARGSUSED */ 248*1cfa752fSRamaswamy Tummala dladm_status_t 249*1cfa752fSRamaswamy Tummala dladm_ib_info(dladm_handle_t handle, datalink_id_t linkid, 250*1cfa752fSRamaswamy Tummala dladm_ib_attr_t *attrp, uint32_t flags) 251*1cfa752fSRamaswamy Tummala { 252*1cfa752fSRamaswamy Tummala int instance; 253*1cfa752fSRamaswamy Tummala ibport_ioctl_t ioc; 254*1cfa752fSRamaswamy Tummala dladm_phys_attr_t dpa; 255*1cfa752fSRamaswamy Tummala dladm_status_t status = DLADM_STATUS_OK; 256*1cfa752fSRamaswamy Tummala 257*1cfa752fSRamaswamy Tummala /* 258*1cfa752fSRamaswamy Tummala * We need to get the device name of the IB Phys link to get the 259*1cfa752fSRamaswamy Tummala * correct instance number of the IP over IB driver instance. 260*1cfa752fSRamaswamy Tummala */ 261*1cfa752fSRamaswamy Tummala if (dladm_phys_info(handle, linkid, &dpa, DLADM_OPT_ACTIVE) 262*1cfa752fSRamaswamy Tummala != DLADM_STATUS_OK) 263*1cfa752fSRamaswamy Tummala return (DLADM_STATUS_BADARG); 264*1cfa752fSRamaswamy Tummala 265*1cfa752fSRamaswamy Tummala /* 266*1cfa752fSRamaswamy Tummala * Get the instance number of the IP over IB driver instance which 267*1cfa752fSRamaswamy Tummala * represents this IB Phys link. 268*1cfa752fSRamaswamy Tummala */ 269*1cfa752fSRamaswamy Tummala instance = dladm_ibd_get_instance(dpa.dp_dev); 270*1cfa752fSRamaswamy Tummala if (instance == -1) 271*1cfa752fSRamaswamy Tummala return (DLADM_STATUS_FAILED); 272*1cfa752fSRamaswamy Tummala 273*1cfa752fSRamaswamy Tummala bzero(&ioc, sizeof (ioc)); 274*1cfa752fSRamaswamy Tummala /* 275*1cfa752fSRamaswamy Tummala * The ioc_linkid here will contain IB port linkid here. We make the 276*1cfa752fSRamaswamy Tummala * first ioctl call to get the P_Key table size for this HCA port. 277*1cfa752fSRamaswamy Tummala */ 278*1cfa752fSRamaswamy Tummala ioc.ibdioc.ioc_linkid = linkid; 279*1cfa752fSRamaswamy Tummala ioc.ibdioc.ioc_info_cmd = IBD_INFO_CMD_PKEYTBLSZ; 280*1cfa752fSRamaswamy Tummala ioc.ioc_pkey_tbl_sz = 0; 281*1cfa752fSRamaswamy Tummala ioc.ibdioc.ioc_port_inst = instance; 282*1cfa752fSRamaswamy Tummala 283*1cfa752fSRamaswamy Tummala status = i_dladm_ib_ioctl(handle, IBD_INFO_IBPART, (ibd_ioctl_t *)&ioc); 284*1cfa752fSRamaswamy Tummala if (status != DLADM_STATUS_OK) 285*1cfa752fSRamaswamy Tummala return (status); 286*1cfa752fSRamaswamy Tummala 287*1cfa752fSRamaswamy Tummala /* 288*1cfa752fSRamaswamy Tummala * Now allocate the memory for the P_Key table based on the table size 289*1cfa752fSRamaswamy Tummala * return by the ioctl. 290*1cfa752fSRamaswamy Tummala */ 291*1cfa752fSRamaswamy Tummala ioc.ioc_pkeys = calloc(sizeof (ib_pkey_t), ioc.ioc_pkey_tbl_sz); 292*1cfa752fSRamaswamy Tummala if (ioc.ioc_pkeys == NULL) { 293*1cfa752fSRamaswamy Tummala status = dladm_errno2status(errno); 294*1cfa752fSRamaswamy Tummala goto bail; 295*1cfa752fSRamaswamy Tummala } 296*1cfa752fSRamaswamy Tummala 297*1cfa752fSRamaswamy Tummala /* 298*1cfa752fSRamaswamy Tummala * Call the ioctl again to get the P_Key table and other IB Phys link 299*1cfa752fSRamaswamy Tummala * attributes. 300*1cfa752fSRamaswamy Tummala */ 301*1cfa752fSRamaswamy Tummala ioc.ibdioc.ioc_linkid = linkid; 302*1cfa752fSRamaswamy Tummala ioc.ibdioc.ioc_port_inst = instance; 303*1cfa752fSRamaswamy Tummala ioc.ibdioc.ioc_info_cmd = IBD_INFO_CMD_IBPORT; 304*1cfa752fSRamaswamy Tummala 305*1cfa752fSRamaswamy Tummala status = i_dladm_ib_ioctl(handle, IBD_INFO_IBPART, (ibd_ioctl_t *)&ioc); 306*1cfa752fSRamaswamy Tummala if (status != DLADM_STATUS_OK) 307*1cfa752fSRamaswamy Tummala goto bail; 308*1cfa752fSRamaswamy Tummala 309*1cfa752fSRamaswamy Tummala attrp->dia_physlinkid = ioc.ibdioc.ioc_linkid; 310*1cfa752fSRamaswamy Tummala attrp->dia_portnum = ioc.ibdioc.ioc_portnum; 311*1cfa752fSRamaswamy Tummala attrp->dia_port_pkey_tbl_sz = ioc.ioc_pkey_tbl_sz; 312*1cfa752fSRamaswamy Tummala attrp->dia_port_pkeys = ioc.ioc_pkeys; 313*1cfa752fSRamaswamy Tummala attrp->dia_hca_guid = ioc.ibdioc.ioc_hcaguid; 314*1cfa752fSRamaswamy Tummala attrp->dia_port_guid = ioc.ibdioc.ioc_portguid; 315*1cfa752fSRamaswamy Tummala attrp->dia_instance = ioc.ibdioc.ioc_port_inst; 316*1cfa752fSRamaswamy Tummala return (status); 317*1cfa752fSRamaswamy Tummala bail: 318*1cfa752fSRamaswamy Tummala free(ioc.ioc_pkeys); 319*1cfa752fSRamaswamy Tummala return (status); 320*1cfa752fSRamaswamy Tummala } 321*1cfa752fSRamaswamy Tummala 322*1cfa752fSRamaswamy Tummala /* 323*1cfa752fSRamaswamy Tummala * Free the memory allocated for the IB HCA port's P_Key table by 324*1cfa752fSRamaswamy Tummala * dladm_ib_info library call. 325*1cfa752fSRamaswamy Tummala */ 326*1cfa752fSRamaswamy Tummala void 327*1cfa752fSRamaswamy Tummala dladm_free_ib_info(dladm_ib_attr_t *attr) 328*1cfa752fSRamaswamy Tummala { 329*1cfa752fSRamaswamy Tummala if (attr && attr->dia_port_pkeys) 330*1cfa752fSRamaswamy Tummala free(attr->dia_port_pkeys); 331*1cfa752fSRamaswamy Tummala } 332*1cfa752fSRamaswamy Tummala 333*1cfa752fSRamaswamy Tummala /* 334*1cfa752fSRamaswamy Tummala * Call into the IP over IB driver to create a partition object. 335*1cfa752fSRamaswamy Tummala */ 336*1cfa752fSRamaswamy Tummala static dladm_status_t 337*1cfa752fSRamaswamy Tummala i_dladm_part_create(dladm_handle_t handle, dladm_part_attr_t *pattr) 338*1cfa752fSRamaswamy Tummala { 339*1cfa752fSRamaswamy Tummala ibpart_ioctl_t ioc; 340*1cfa752fSRamaswamy Tummala dladm_status_t status = DLADM_STATUS_OK; 341*1cfa752fSRamaswamy Tummala 342*1cfa752fSRamaswamy Tummala bzero(&ioc, sizeof (ioc)); 343*1cfa752fSRamaswamy Tummala 344*1cfa752fSRamaswamy Tummala /* IB Physical datalink ID */ 345*1cfa752fSRamaswamy Tummala ioc.ibdioc.ioc_linkid = pattr->dia_physlinkid; 346*1cfa752fSRamaswamy Tummala /* IB Partition datalink ID */ 347*1cfa752fSRamaswamy Tummala ioc.ioc_partid = pattr->dia_partlinkid; 348*1cfa752fSRamaswamy Tummala ioc.ioc_pkey = pattr->dia_pkey; 349*1cfa752fSRamaswamy Tummala ioc.ibdioc.ioc_port_inst = pattr->dia_instance; 350*1cfa752fSRamaswamy Tummala ioc.ioc_force_create = ((pattr->dia_flags & DLADM_OPT_FORCE) 351*1cfa752fSRamaswamy Tummala != 0); 352*1cfa752fSRamaswamy Tummala 353*1cfa752fSRamaswamy Tummala status = i_dladm_ib_ioctl(handle, IBD_CREATE_IBPART, 354*1cfa752fSRamaswamy Tummala (ibd_ioctl_t *)&ioc); 355*1cfa752fSRamaswamy Tummala return (status); 356*1cfa752fSRamaswamy Tummala } 357*1cfa752fSRamaswamy Tummala 358*1cfa752fSRamaswamy Tummala /* 359*1cfa752fSRamaswamy Tummala * Create an entry in the dladm persistent configuration database for the 360*1cfa752fSRamaswamy Tummala * partition specified by pattr. 361*1cfa752fSRamaswamy Tummala */ 362*1cfa752fSRamaswamy Tummala dladm_status_t 363*1cfa752fSRamaswamy Tummala dladm_part_persist_conf(dladm_handle_t handle, dladm_part_attr_t *pattr) 364*1cfa752fSRamaswamy Tummala { 365*1cfa752fSRamaswamy Tummala 366*1cfa752fSRamaswamy Tummala dladm_conf_t conf; 367*1cfa752fSRamaswamy Tummala dladm_status_t status; 368*1cfa752fSRamaswamy Tummala char linkover[MAXLINKNAMELEN]; 369*1cfa752fSRamaswamy Tummala uint64_t u64; 370*1cfa752fSRamaswamy Tummala 371*1cfa752fSRamaswamy Tummala status = dladm_create_conf(handle, pattr->dia_pname, 372*1cfa752fSRamaswamy Tummala pattr->dia_partlinkid, DATALINK_CLASS_PART, DL_IB, &conf); 373*1cfa752fSRamaswamy Tummala 374*1cfa752fSRamaswamy Tummala if (status != DLADM_STATUS_OK) 375*1cfa752fSRamaswamy Tummala return (status); 376*1cfa752fSRamaswamy Tummala 377*1cfa752fSRamaswamy Tummala /* 378*1cfa752fSRamaswamy Tummala * Get the name of the IB Phys link over which this partition was 379*1cfa752fSRamaswamy Tummala * created. 380*1cfa752fSRamaswamy Tummala */ 381*1cfa752fSRamaswamy Tummala status = dladm_datalink_id2info(handle, pattr->dia_physlinkid, 382*1cfa752fSRamaswamy Tummala NULL, NULL, NULL, linkover, sizeof (linkover)); 383*1cfa752fSRamaswamy Tummala if (status != DLADM_STATUS_OK) 384*1cfa752fSRamaswamy Tummala return (status); 385*1cfa752fSRamaswamy Tummala 386*1cfa752fSRamaswamy Tummala /* Store IB Phys link name (linkover) */ 387*1cfa752fSRamaswamy Tummala status = dladm_set_conf_field(handle, conf, FLINKOVER, DLADM_TYPE_STR, 388*1cfa752fSRamaswamy Tummala linkover); 389*1cfa752fSRamaswamy Tummala if (status != DLADM_STATUS_OK) 390*1cfa752fSRamaswamy Tummala return (status); 391*1cfa752fSRamaswamy Tummala 392*1cfa752fSRamaswamy Tummala u64 = pattr->dia_pkey; 393*1cfa752fSRamaswamy Tummala 394*1cfa752fSRamaswamy Tummala /* Store the IB Partitions P_Key */ 395*1cfa752fSRamaswamy Tummala status = dladm_set_conf_field(handle, conf, FPORTPKEY, 396*1cfa752fSRamaswamy Tummala DLADM_TYPE_UINT64, &u64); 397*1cfa752fSRamaswamy Tummala if (status != DLADM_STATUS_OK) 398*1cfa752fSRamaswamy Tummala return (status); 399*1cfa752fSRamaswamy Tummala 400*1cfa752fSRamaswamy Tummala if (pattr->dia_flags & DLADM_OPT_FORCE) { 401*1cfa752fSRamaswamy Tummala boolean_t force = B_TRUE; 402*1cfa752fSRamaswamy Tummala /* Store the force create flag. */ 403*1cfa752fSRamaswamy Tummala status = dladm_set_conf_field(handle, conf, FFORCE, 404*1cfa752fSRamaswamy Tummala DLADM_TYPE_BOOLEAN, &force); 405*1cfa752fSRamaswamy Tummala if (status != DLADM_STATUS_OK) 406*1cfa752fSRamaswamy Tummala goto done; 407*1cfa752fSRamaswamy Tummala } 408*1cfa752fSRamaswamy Tummala 409*1cfa752fSRamaswamy Tummala status = dladm_write_conf(handle, conf); 410*1cfa752fSRamaswamy Tummala if (status != DLADM_STATUS_OK) 411*1cfa752fSRamaswamy Tummala return (status); 412*1cfa752fSRamaswamy Tummala 413*1cfa752fSRamaswamy Tummala dladm_destroy_conf(handle, conf); 414*1cfa752fSRamaswamy Tummala done: 415*1cfa752fSRamaswamy Tummala return (status); 416*1cfa752fSRamaswamy Tummala } 417*1cfa752fSRamaswamy Tummala 418*1cfa752fSRamaswamy Tummala /* 419*1cfa752fSRamaswamy Tummala * Create a new IB Partition datalink of name 'pname' over the IB Physical link 420*1cfa752fSRamaswamy Tummala * given in 'physlinkid' with the P_key 'pkey' and return the datalink ID in 421*1cfa752fSRamaswamy Tummala * 'partlinkid'. If the 'force' option is set in the 'flags' argument, the 422*1cfa752fSRamaswamy Tummala * partition will be created even if the P_Key 'pkey' does not exist or if the 423*1cfa752fSRamaswamy Tummala * HCA port represented by the IB Phys link is down. If the 'temporary' flag is 424*1cfa752fSRamaswamy Tummala * set, then the configuration information is not added to the persistent 425*1cfa752fSRamaswamy Tummala * database. 426*1cfa752fSRamaswamy Tummala */ 427*1cfa752fSRamaswamy Tummala dladm_status_t 428*1cfa752fSRamaswamy Tummala dladm_part_create(dladm_handle_t handle, datalink_id_t physlinkid, 429*1cfa752fSRamaswamy Tummala ib_pkey_t pkey, uint32_t flags, char *pname, datalink_id_t *partlinkid, 430*1cfa752fSRamaswamy Tummala dladm_arg_list_t *proplist) 431*1cfa752fSRamaswamy Tummala { 432*1cfa752fSRamaswamy Tummala int i; 433*1cfa752fSRamaswamy Tummala dladm_status_t status; 434*1cfa752fSRamaswamy Tummala uint_t media; 435*1cfa752fSRamaswamy Tummala boolean_t part_created = B_FALSE; 436*1cfa752fSRamaswamy Tummala boolean_t conf_set = B_FALSE; 437*1cfa752fSRamaswamy Tummala dladm_phys_attr_t dpa; 438*1cfa752fSRamaswamy Tummala dladm_part_attr_t pattr; 439*1cfa752fSRamaswamy Tummala 440*1cfa752fSRamaswamy Tummala pattr.dia_pkey = pkey; 441*1cfa752fSRamaswamy Tummala pattr.dia_physlinkid = physlinkid; /* IB Phys link's datalink id */ 442*1cfa752fSRamaswamy Tummala pattr.dia_flags = flags; 443*1cfa752fSRamaswamy Tummala pattr.dia_pname = pname; 444*1cfa752fSRamaswamy Tummala 445*1cfa752fSRamaswamy Tummala flags &= ~DLADM_OPT_FORCE; 446*1cfa752fSRamaswamy Tummala 447*1cfa752fSRamaswamy Tummala /* 448*1cfa752fSRamaswamy Tummala * Check whether the PKEY is valid. If not, return immediately 449*1cfa752fSRamaswamy Tummala * Only full members are allowed as per the IPoIB specification 450*1cfa752fSRamaswamy Tummala */ 451*1cfa752fSRamaswamy Tummala if (pattr.dia_pkey <= IB_PKEY_INVALID_FULL) 452*1cfa752fSRamaswamy Tummala return (DLADM_STATUS_INVALID_PKEY); 453*1cfa752fSRamaswamy Tummala 454*1cfa752fSRamaswamy Tummala /* 455*1cfa752fSRamaswamy Tummala * Get the media type of the Phys link datalink ID provided and 456*1cfa752fSRamaswamy Tummala * make sure that it is Infiniband media DL_IB) 457*1cfa752fSRamaswamy Tummala */ 458*1cfa752fSRamaswamy Tummala if ((status = dladm_datalink_id2info(handle, pattr.dia_physlinkid, NULL, 459*1cfa752fSRamaswamy Tummala NULL, &media, NULL, 0)) != DLADM_STATUS_OK) 460*1cfa752fSRamaswamy Tummala return (status); 461*1cfa752fSRamaswamy Tummala 462*1cfa752fSRamaswamy Tummala if (media != DL_IB) 463*1cfa752fSRamaswamy Tummala return (dladm_errno2status(ENOTSUP)); 464*1cfa752fSRamaswamy Tummala 465*1cfa752fSRamaswamy Tummala /* 466*1cfa752fSRamaswamy Tummala * Get the instance number of the IP over IB driver instance which the 467*1cfa752fSRamaswamy Tummala * IB Phys link 'physlinkid' over which we will be creating our IB 468*1cfa752fSRamaswamy Tummala * partition. 469*1cfa752fSRamaswamy Tummala */ 470*1cfa752fSRamaswamy Tummala if ((status = dladm_phys_info(handle, pattr.dia_physlinkid, &dpa, 471*1cfa752fSRamaswamy Tummala DLADM_OPT_ACTIVE)) != DLADM_STATUS_OK) 472*1cfa752fSRamaswamy Tummala return (status); 473*1cfa752fSRamaswamy Tummala 474*1cfa752fSRamaswamy Tummala pattr.dia_instance = dladm_ibd_get_instance(dpa.dp_dev); 475*1cfa752fSRamaswamy Tummala if (pattr.dia_instance == -1) 476*1cfa752fSRamaswamy Tummala return (DLADM_STATUS_FAILED); 477*1cfa752fSRamaswamy Tummala 478*1cfa752fSRamaswamy Tummala 479*1cfa752fSRamaswamy Tummala if ((status = dladm_create_datalink_id(handle, pattr.dia_pname, 480*1cfa752fSRamaswamy Tummala DATALINK_CLASS_PART, DL_IB, flags, &pattr.dia_partlinkid)) != 481*1cfa752fSRamaswamy Tummala DLADM_STATUS_OK) 482*1cfa752fSRamaswamy Tummala return (status); 483*1cfa752fSRamaswamy Tummala 484*1cfa752fSRamaswamy Tummala /* 485*1cfa752fSRamaswamy Tummala * Create the IB partition object. 486*1cfa752fSRamaswamy Tummala */ 487*1cfa752fSRamaswamy Tummala status = i_dladm_part_create(handle, &pattr); 488*1cfa752fSRamaswamy Tummala if (status != DLADM_STATUS_OK) 489*1cfa752fSRamaswamy Tummala goto done; 490*1cfa752fSRamaswamy Tummala 491*1cfa752fSRamaswamy Tummala part_created = B_TRUE; 492*1cfa752fSRamaswamy Tummala 493*1cfa752fSRamaswamy Tummala /* 494*1cfa752fSRamaswamy Tummala * If the persist flag is set then write this partition information 495*1cfa752fSRamaswamy Tummala * to the persistent configuration. 496*1cfa752fSRamaswamy Tummala */ 497*1cfa752fSRamaswamy Tummala if (pattr.dia_flags & DLADM_OPT_PERSIST) { 498*1cfa752fSRamaswamy Tummala status = dladm_part_persist_conf(handle, &pattr); 499*1cfa752fSRamaswamy Tummala if (status != DLADM_STATUS_OK) 500*1cfa752fSRamaswamy Tummala goto done; 501*1cfa752fSRamaswamy Tummala conf_set = B_TRUE; 502*1cfa752fSRamaswamy Tummala } 503*1cfa752fSRamaswamy Tummala 504*1cfa752fSRamaswamy Tummala /* 505*1cfa752fSRamaswamy Tummala * If the name-value pair list of properties were provided set those 506*1cfa752fSRamaswamy Tummala * properties over the datalink. 507*1cfa752fSRamaswamy Tummala */ 508*1cfa752fSRamaswamy Tummala if (proplist != NULL) { 509*1cfa752fSRamaswamy Tummala for (i = 0; i < proplist->al_count; i++) { 510*1cfa752fSRamaswamy Tummala dladm_arg_info_t *aip = &proplist->al_info[i]; 511*1cfa752fSRamaswamy Tummala 512*1cfa752fSRamaswamy Tummala status = dladm_set_linkprop(handle, 513*1cfa752fSRamaswamy Tummala pattr.dia_partlinkid, aip->ai_name, aip->ai_val, 514*1cfa752fSRamaswamy Tummala aip->ai_count, pattr.dia_flags); 515*1cfa752fSRamaswamy Tummala if (status != DLADM_STATUS_OK) 516*1cfa752fSRamaswamy Tummala break; 517*1cfa752fSRamaswamy Tummala } 518*1cfa752fSRamaswamy Tummala } 519*1cfa752fSRamaswamy Tummala done: 520*1cfa752fSRamaswamy Tummala if (status != DLADM_STATUS_OK) { 521*1cfa752fSRamaswamy Tummala if (conf_set) 522*1cfa752fSRamaswamy Tummala (void) dladm_remove_conf(handle, pattr.dia_partlinkid); 523*1cfa752fSRamaswamy Tummala if (part_created) 524*1cfa752fSRamaswamy Tummala (void) i_dladm_part_delete(handle, 525*1cfa752fSRamaswamy Tummala pattr.dia_partlinkid); 526*1cfa752fSRamaswamy Tummala (void) dladm_destroy_datalink_id(handle, pattr.dia_partlinkid, 527*1cfa752fSRamaswamy Tummala flags); 528*1cfa752fSRamaswamy Tummala } 529*1cfa752fSRamaswamy Tummala 530*1cfa752fSRamaswamy Tummala if (partlinkid != NULL) 531*1cfa752fSRamaswamy Tummala *partlinkid = pattr.dia_partlinkid; 532*1cfa752fSRamaswamy Tummala 533*1cfa752fSRamaswamy Tummala return (status); 534*1cfa752fSRamaswamy Tummala } 535*1cfa752fSRamaswamy Tummala 536*1cfa752fSRamaswamy Tummala /* 537*1cfa752fSRamaswamy Tummala * Call into the IP over IB driver to delete the IB partition and free up all 538*1cfa752fSRamaswamy Tummala * the resources allocated for it. 539*1cfa752fSRamaswamy Tummala */ 540*1cfa752fSRamaswamy Tummala static dladm_status_t 541*1cfa752fSRamaswamy Tummala i_dladm_part_delete(dladm_handle_t handle, datalink_id_t partid) 542*1cfa752fSRamaswamy Tummala { 543*1cfa752fSRamaswamy Tummala ibpart_ioctl_t ioc; 544*1cfa752fSRamaswamy Tummala dladm_status_t status = DLADM_STATUS_OK; 545*1cfa752fSRamaswamy Tummala 546*1cfa752fSRamaswamy Tummala bzero(&ioc, sizeof (ioc)); 547*1cfa752fSRamaswamy Tummala ioc.ioc_partid = partid; 548*1cfa752fSRamaswamy Tummala status = i_dladm_ib_ioctl(handle, IBD_DELETE_IBPART, 549*1cfa752fSRamaswamy Tummala (ibd_ioctl_t *)&ioc); 550*1cfa752fSRamaswamy Tummala return (status); 551*1cfa752fSRamaswamy Tummala } 552*1cfa752fSRamaswamy Tummala 553*1cfa752fSRamaswamy Tummala /* 554*1cfa752fSRamaswamy Tummala * Delete an IB partition if 'flags' contains the active flag. Update the 555*1cfa752fSRamaswamy Tummala * persistent configuration if 'flags' contains the persist flag. 556*1cfa752fSRamaswamy Tummala */ 557*1cfa752fSRamaswamy Tummala dladm_status_t 558*1cfa752fSRamaswamy Tummala dladm_part_delete(dladm_handle_t handle, datalink_id_t partid, int flags) 559*1cfa752fSRamaswamy Tummala { 560*1cfa752fSRamaswamy Tummala dladm_status_t status = DLADM_STATUS_OK; 561*1cfa752fSRamaswamy Tummala datalink_class_t class; 562*1cfa752fSRamaswamy Tummala 563*1cfa752fSRamaswamy Tummala if (flags == 0) 564*1cfa752fSRamaswamy Tummala return (DLADM_STATUS_BADARG); 565*1cfa752fSRamaswamy Tummala 566*1cfa752fSRamaswamy Tummala /* 567*1cfa752fSRamaswamy Tummala * Make sure that the datalinkid provided is an IB partition class 568*1cfa752fSRamaswamy Tummala * datalink ID. 569*1cfa752fSRamaswamy Tummala */ 570*1cfa752fSRamaswamy Tummala if ((dladm_datalink_id2info(handle, partid, NULL, &class, NULL, NULL, 0) 571*1cfa752fSRamaswamy Tummala != DLADM_STATUS_OK)) 572*1cfa752fSRamaswamy Tummala return (DLADM_STATUS_BADARG); 573*1cfa752fSRamaswamy Tummala 574*1cfa752fSRamaswamy Tummala if (class != DATALINK_CLASS_PART) 575*1cfa752fSRamaswamy Tummala return (DLADM_STATUS_BADARG); 576*1cfa752fSRamaswamy Tummala 577*1cfa752fSRamaswamy Tummala if ((flags & DLADM_OPT_ACTIVE) != 0) { 578*1cfa752fSRamaswamy Tummala status = i_dladm_part_delete(handle, partid); 579*1cfa752fSRamaswamy Tummala if (status == DLADM_STATUS_OK) { 580*1cfa752fSRamaswamy Tummala (void) dladm_set_linkprop(handle, partid, NULL, NULL, 0, 581*1cfa752fSRamaswamy Tummala DLADM_OPT_ACTIVE); 582*1cfa752fSRamaswamy Tummala (void) dladm_destroy_datalink_id(handle, partid, 583*1cfa752fSRamaswamy Tummala DLADM_OPT_ACTIVE); 584*1cfa752fSRamaswamy Tummala } else if (status != DLADM_STATUS_NOTFOUND || 585*1cfa752fSRamaswamy Tummala !(flags & DLADM_OPT_PERSIST)) { 586*1cfa752fSRamaswamy Tummala return (status); 587*1cfa752fSRamaswamy Tummala } 588*1cfa752fSRamaswamy Tummala } 589*1cfa752fSRamaswamy Tummala 590*1cfa752fSRamaswamy Tummala if ((flags & DLADM_OPT_PERSIST) != 0) { 591*1cfa752fSRamaswamy Tummala dladm_status_t db_status; 592*1cfa752fSRamaswamy Tummala db_status = dladm_remove_conf(handle, partid); 593*1cfa752fSRamaswamy Tummala 594*1cfa752fSRamaswamy Tummala /* 595*1cfa752fSRamaswamy Tummala * A partition could have been temporarily deleted in which 596*1cfa752fSRamaswamy Tummala * case the delete of the active partition above would have 597*1cfa752fSRamaswamy Tummala * failed. In that case, we update the status to be returned 598*1cfa752fSRamaswamy Tummala * to that of the status returned for deleting the persistent 599*1cfa752fSRamaswamy Tummala * database entry. 600*1cfa752fSRamaswamy Tummala */ 601*1cfa752fSRamaswamy Tummala if (status == DLADM_STATUS_NOTFOUND) 602*1cfa752fSRamaswamy Tummala status = db_status; 603*1cfa752fSRamaswamy Tummala 604*1cfa752fSRamaswamy Tummala (void) dladm_destroy_datalink_id(handle, partid, 605*1cfa752fSRamaswamy Tummala DLADM_OPT_PERSIST); 606*1cfa752fSRamaswamy Tummala } 607*1cfa752fSRamaswamy Tummala 608*1cfa752fSRamaswamy Tummala return (status); 609*1cfa752fSRamaswamy Tummala } 610*1cfa752fSRamaswamy Tummala 611*1cfa752fSRamaswamy Tummala /* 612*1cfa752fSRamaswamy Tummala * Call into the IP over IB driver to create the active instances of one or all 613*1cfa752fSRamaswamy Tummala * IB partitions present in the persistent configuration. 614*1cfa752fSRamaswamy Tummala */ 615*1cfa752fSRamaswamy Tummala /* ARGSUSED */ 616*1cfa752fSRamaswamy Tummala static int 617*1cfa752fSRamaswamy Tummala i_dladm_part_up(dladm_handle_t handle, datalink_id_t plinkid, void *arg) 618*1cfa752fSRamaswamy Tummala { 619*1cfa752fSRamaswamy Tummala dladm_conf_t conf; 620*1cfa752fSRamaswamy Tummala datalink_id_t linkid; 621*1cfa752fSRamaswamy Tummala ib_pkey_t pkey; 622*1cfa752fSRamaswamy Tummala uint64_t u64; 623*1cfa752fSRamaswamy Tummala char linkover[MAXLINKNAMELEN]; 624*1cfa752fSRamaswamy Tummala dladm_status_t status; 625*1cfa752fSRamaswamy Tummala dladm_phys_attr_t dpa; 626*1cfa752fSRamaswamy Tummala dladm_part_attr_t pattr; 627*1cfa752fSRamaswamy Tummala 628*1cfa752fSRamaswamy Tummala /* 629*1cfa752fSRamaswamy Tummala * plinkid is the IB partition datalink's ID. Get an handle to the 630*1cfa752fSRamaswamy Tummala * persistent configuration entry for this datalink ID. If this datalink 631*1cfa752fSRamaswamy Tummala * ID is not present in the persistent configuration return. 632*1cfa752fSRamaswamy Tummala */ 633*1cfa752fSRamaswamy Tummala if ((status = dladm_read_conf(handle, plinkid, &conf)) != 634*1cfa752fSRamaswamy Tummala DLADM_STATUS_OK) 635*1cfa752fSRamaswamy Tummala return (status); 636*1cfa752fSRamaswamy Tummala 637*1cfa752fSRamaswamy Tummala /* 638*1cfa752fSRamaswamy Tummala * Get the name of the IB Phys link over which this partition was 639*1cfa752fSRamaswamy Tummala * created. 640*1cfa752fSRamaswamy Tummala */ 641*1cfa752fSRamaswamy Tummala status = dladm_get_conf_field(handle, conf, FLINKOVER, linkover, 642*1cfa752fSRamaswamy Tummala sizeof (linkover)); 643*1cfa752fSRamaswamy Tummala if (status != DLADM_STATUS_OK) 644*1cfa752fSRamaswamy Tummala goto done; 645*1cfa752fSRamaswamy Tummala 646*1cfa752fSRamaswamy Tummala if ((status = dladm_name2info(handle, linkover, &linkid, NULL, NULL, 647*1cfa752fSRamaswamy Tummala NULL)) != DLADM_STATUS_OK) 648*1cfa752fSRamaswamy Tummala goto done; 649*1cfa752fSRamaswamy Tummala 650*1cfa752fSRamaswamy Tummala /* 651*1cfa752fSRamaswamy Tummala * Get the phys attribute of the IB Phys link to get the device name 652*1cfa752fSRamaswamy Tummala * associated with the phys link. We need this to get the IP over IB 653*1cfa752fSRamaswamy Tummala * driver instance number. 654*1cfa752fSRamaswamy Tummala */ 655*1cfa752fSRamaswamy Tummala if (dladm_phys_info(handle, linkid, &dpa, DLADM_OPT_ACTIVE) 656*1cfa752fSRamaswamy Tummala != DLADM_STATUS_OK) 657*1cfa752fSRamaswamy Tummala goto done; 658*1cfa752fSRamaswamy Tummala 659*1cfa752fSRamaswamy Tummala /* Get the IB partition's P_key */ 660*1cfa752fSRamaswamy Tummala status = dladm_get_conf_field(handle, conf, FPORTPKEY, &u64, 661*1cfa752fSRamaswamy Tummala sizeof (u64)); 662*1cfa752fSRamaswamy Tummala if (status != DLADM_STATUS_OK) 663*1cfa752fSRamaswamy Tummala goto done; 664*1cfa752fSRamaswamy Tummala 665*1cfa752fSRamaswamy Tummala pkey = (ib_pkey_t)u64; 666*1cfa752fSRamaswamy Tummala 667*1cfa752fSRamaswamy Tummala /* 668*1cfa752fSRamaswamy Tummala * We always set the force flag during dladm_part_up because we want 669*1cfa752fSRamaswamy Tummala * the partition creation to succeed even if the IB HCA port over which 670*1cfa752fSRamaswamy Tummala * the partition is being created is still down. Since dladm_part_up 671*1cfa752fSRamaswamy Tummala * is usually invoked during early boot sequence, it is possible under 672*1cfa752fSRamaswamy Tummala * some IB subnet configurations for dladm_up_part to be called before 673*1cfa752fSRamaswamy Tummala * the IB link negotiation is completed and port state is set to active 674*1cfa752fSRamaswamy Tummala * and P_Key table is updated. 675*1cfa752fSRamaswamy Tummala */ 676*1cfa752fSRamaswamy Tummala pattr.dia_flags = DLADM_OPT_FORCE | DLADM_OPT_ACTIVE | 677*1cfa752fSRamaswamy Tummala DLADM_OPT_PERSIST; 678*1cfa752fSRamaswamy Tummala /* IB Phys link's datalink ID. */ 679*1cfa752fSRamaswamy Tummala pattr.dia_physlinkid = linkid; 680*1cfa752fSRamaswamy Tummala /* IB Partition's datalink ID. */ 681*1cfa752fSRamaswamy Tummala pattr.dia_partlinkid = plinkid; 682*1cfa752fSRamaswamy Tummala pattr.dia_pkey = pkey; 683*1cfa752fSRamaswamy Tummala pattr.dia_instance = dladm_ibd_get_instance(dpa.dp_dev); 684*1cfa752fSRamaswamy Tummala if (pattr.dia_instance == -1) 685*1cfa752fSRamaswamy Tummala return (DLADM_WALK_CONTINUE); 686*1cfa752fSRamaswamy Tummala 687*1cfa752fSRamaswamy Tummala /* Create the active IB Partition object. */ 688*1cfa752fSRamaswamy Tummala if (i_dladm_part_create(handle, &pattr) == DLADM_STATUS_OK && 689*1cfa752fSRamaswamy Tummala dladm_up_datalink_id(handle, plinkid) != DLADM_STATUS_OK) 690*1cfa752fSRamaswamy Tummala (void) i_dladm_part_delete(handle, linkid); 691*1cfa752fSRamaswamy Tummala 692*1cfa752fSRamaswamy Tummala done: 693*1cfa752fSRamaswamy Tummala dladm_destroy_conf(handle, conf); 694*1cfa752fSRamaswamy Tummala return (DLADM_WALK_CONTINUE); 695*1cfa752fSRamaswamy Tummala } 696*1cfa752fSRamaswamy Tummala 697*1cfa752fSRamaswamy Tummala /* 698*1cfa752fSRamaswamy Tummala * Bring up one or all IB partition(s) present in the persistent configuration 699*1cfa752fSRamaswamy Tummala * database. If we need to bring up one IB Partition, its datalink ID is 700*1cfa752fSRamaswamy Tummala * provided in 'linkid'. 701*1cfa752fSRamaswamy Tummala */ 702*1cfa752fSRamaswamy Tummala /* ARGSUSED */ 703*1cfa752fSRamaswamy Tummala dladm_status_t 704*1cfa752fSRamaswamy Tummala dladm_part_up(dladm_handle_t handle, datalink_id_t linkid, uint32_t flags) 705*1cfa752fSRamaswamy Tummala { 706*1cfa752fSRamaswamy Tummala dladm_status_t status = DLADM_STATUS_OK; 707*1cfa752fSRamaswamy Tummala 708*1cfa752fSRamaswamy Tummala if (linkid == DATALINK_ALL_LINKID) { 709*1cfa752fSRamaswamy Tummala (void) dladm_walk_datalink_id(i_dladm_part_up, handle, 710*1cfa752fSRamaswamy Tummala &status, DATALINK_CLASS_PART, DATALINK_ANY_MEDIATYPE, 711*1cfa752fSRamaswamy Tummala DLADM_OPT_PERSIST); 712*1cfa752fSRamaswamy Tummala return (DLADM_STATUS_OK); 713*1cfa752fSRamaswamy Tummala } else { 714*1cfa752fSRamaswamy Tummala (void) i_dladm_part_up(handle, linkid, &status); 715*1cfa752fSRamaswamy Tummala return (status); 716*1cfa752fSRamaswamy Tummala } 717*1cfa752fSRamaswamy Tummala } 718*1cfa752fSRamaswamy Tummala 719*1cfa752fSRamaswamy Tummala static int 720*1cfa752fSRamaswamy Tummala dladm_ibd_get_instance(char *devname) 721*1cfa752fSRamaswamy Tummala { 722*1cfa752fSRamaswamy Tummala int instance; 723*1cfa752fSRamaswamy Tummala 724*1cfa752fSRamaswamy Tummala /* 725*1cfa752fSRamaswamy Tummala * The devname contains the driver name followed by the instance 726*1cfa752fSRamaswamy Tummala * number. Lets just skip the driver name and get the instance. We use 727*1cfa752fSRamaswamy Tummala * strlen of ibp here to get the driver name length. 728*1cfa752fSRamaswamy Tummala */ 729*1cfa752fSRamaswamy Tummala instance = atoi(devname + strlen("ibp")); 730*1cfa752fSRamaswamy Tummala 731*1cfa752fSRamaswamy Tummala return (instance); 732*1cfa752fSRamaswamy Tummala } 733