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 /* 23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #include "bge_impl.h" 28 29 30 #define BGE_DBG BGE_DBG_NDD /* debug flag for this code */ 31 /* 32 * Property names 33 */ 34 static char transfer_speed_propname[] = "transfer-speed"; 35 static char speed_propname[] = "speed"; 36 static char duplex_propname[] = "full-duplex"; 37 static char supported_net[] = "supported-network-types"; 38 39 /* 40 * synchronize the adv* and en* parameters. 41 * 42 * See comments in <sys/dld.h> for details of the *_en_* 43 * parameters. The usage of ndd for setting adv parameters will 44 * synchronize all the en parameters with the bge parameters, 45 * implicitly disabling any settings made via dladm. 46 */ 47 static void 48 bge_param_sync(bge_t *bgep) 49 { 50 bgep->param_en_pause = bgep->param_adv_pause; 51 bgep->param_en_asym_pause = bgep->param_adv_asym_pause; 52 bgep->param_en_1000fdx = bgep->param_adv_1000fdx; 53 bgep->param_en_1000hdx = bgep->param_adv_1000hdx; 54 bgep->param_en_100fdx = bgep->param_adv_100fdx; 55 bgep->param_en_100hdx = bgep->param_adv_100hdx; 56 bgep->param_en_10fdx = bgep->param_adv_10fdx; 57 bgep->param_en_10hdx = bgep->param_adv_10hdx; 58 } 59 60 boolean_t 61 bge_nd_get_prop_val(dev_info_t *dip, char *nm, long min, long max, int *pval) 62 { 63 /* 64 * If there is a driver.conf setting for the prop, we use 65 * it to initialise the parameter. If it exists but is 66 * out of range, it's ignored. 67 */ 68 if (BGE_PROP_EXISTS(dip, nm)) { 69 *pval = BGE_PROP_GET_INT(dip, nm); 70 if (*pval >= min && *pval <= max) 71 return (B_TRUE); 72 } 73 return (B_FALSE); 74 } 75 76 #define BGE_INIT_PROP(propname, fieldname, initval) { \ 77 if (bge_nd_get_prop_val(dip, propname, 0, 1, &propval)) \ 78 bgep->fieldname = propval; \ 79 else \ 80 bgep->fieldname = initval; \ 81 } 82 83 static void 84 bge_nd_param_init(bge_t *bgep) 85 { 86 dev_info_t *dip; 87 int flags = bgep->chipid.flags; 88 int propval; 89 90 dip = bgep->devinfo; 91 92 /* 93 * initialize values to those from driver.conf (if available) 94 * or the default value otherwise. 95 */ 96 BGE_INIT_PROP("adv_autoneg_cap", param_adv_autoneg, 1); 97 BGE_INIT_PROP("adv_1000fdx_cap", param_adv_1000fdx, 1); 98 BGE_INIT_PROP("adv_1000hdx_cap", param_adv_1000hdx, 1); 99 BGE_INIT_PROP("adv_pause_cap", param_adv_pause, 1); 100 BGE_INIT_PROP("adv_asym_pause_cap", param_adv_asym_pause, 1); 101 102 if (flags & CHIP_FLAG_SERDES) { 103 bgep->param_adv_100fdx = 0; 104 bgep->param_adv_100hdx = 0; 105 bgep->param_adv_10fdx = 0; 106 bgep->param_adv_10hdx = 0; 107 } else { 108 BGE_INIT_PROP("adv_100fdx_cap", param_adv_100fdx, 1); 109 BGE_INIT_PROP("adv_100hdx_cap", param_adv_100hdx, 1); 110 BGE_INIT_PROP("adv_10fdx_cap", param_adv_10fdx, 1); 111 BGE_INIT_PROP("adv_10hdx_cap", param_adv_10hdx, 1); 112 } 113 114 } 115 116 int 117 bge_nd_init(bge_t *bgep) 118 { 119 dev_info_t *dip; 120 int duplex; 121 int speed; 122 char **options, *prop; 123 uint_t noptions; 124 125 BGE_TRACE(("bge_nd_init($%p)", (void *)bgep)); 126 bge_nd_param_init(bgep); 127 128 /* 129 * initialize from .conf file, if appropriate. 130 */ 131 132 /* 133 * check the OBP property "supported-network-types" 134 */ 135 if (BGE_PROP_EXISTS(bgep->devinfo, supported_net)) { 136 if (ddi_prop_lookup_string_array(DDI_DEV_T_ANY, bgep->devinfo, 137 DDI_PROP_DONTPASS, supported_net, 138 &options, &noptions) == DDI_PROP_SUCCESS) { 139 140 bgep->param_adv_autoneg = 0; 141 bgep->param_adv_1000fdx = 0; 142 bgep->param_adv_1000hdx = 0; 143 bgep->param_adv_100fdx = 0; 144 bgep->param_adv_100hdx = 0; 145 bgep->param_adv_10fdx = 0; 146 bgep->param_adv_10hdx = 0; 147 148 for (; noptions > 0; noptions--) { 149 prop = options[noptions-1]; 150 if (strstr(prop, "ethernet") == NULL) 151 continue; 152 if (strstr(prop, "1000")) { 153 if (strstr(prop, "auto")) { 154 bgep->param_adv_1000fdx = 1; 155 bgep->param_adv_1000hdx = 1; 156 bgep->param_adv_autoneg = 1; 157 } else if (strstr(prop, "full")) 158 bgep->param_adv_1000fdx = 1; 159 else if (strstr(prop, "half")) 160 bgep->param_adv_1000hdx = 1; 161 } else if (strstr(prop, "100")) { 162 if (strstr(prop, "auto")) { 163 bgep->param_adv_100fdx = 1; 164 bgep->param_adv_100hdx = 1; 165 bgep->param_adv_autoneg = 1; 166 } else if (strstr(prop, "full")) 167 bgep->param_adv_100fdx = 1; 168 else if (strstr(prop, "half")) 169 bgep->param_adv_100hdx = 1; 170 } else if (strstr(prop, "10")) { 171 if (strstr(prop, "auto")) { 172 bgep->param_adv_10fdx = 1; 173 bgep->param_adv_10hdx = 1; 174 bgep->param_adv_autoneg = 1; 175 } else if (strstr(prop, "full")) 176 bgep->param_adv_10fdx = 1; 177 else if (strstr(prop, "half")) 178 bgep->param_adv_10hdx = 1; 179 } 180 } 181 182 ddi_prop_free(options); 183 } 184 } 185 186 /* 187 * The link speed may be forced to 10, 100 or 1000 Mbps using 188 * the property "transfer-speed". This may be done in OBP by 189 * using the command "apply transfer-speed=<speed> <device>". 190 * The speed may be 10, 100 or 1000 - any other value will be 191 * ignored. Note that this does *enables* autonegotiation, but 192 * restricts it to the speed specified by the property. 193 */ 194 dip = bgep->devinfo; 195 if (BGE_PROP_EXISTS(dip, transfer_speed_propname)) { 196 197 speed = BGE_PROP_GET_INT(dip, transfer_speed_propname); 198 bge_log(bgep, "%s property is %d", 199 transfer_speed_propname, speed); 200 201 switch (speed) { 202 case 1000: 203 bgep->param_adv_autoneg = 1; 204 bgep->param_adv_1000fdx = 1; 205 bgep->param_adv_1000hdx = 1; 206 bgep->param_adv_100fdx = 0; 207 bgep->param_adv_100hdx = 0; 208 bgep->param_adv_10fdx = 0; 209 bgep->param_adv_10hdx = 0; 210 break; 211 212 case 100: 213 bgep->param_adv_autoneg = 1; 214 bgep->param_adv_1000fdx = 0; 215 bgep->param_adv_1000hdx = 0; 216 bgep->param_adv_100fdx = 1; 217 bgep->param_adv_100hdx = 1; 218 bgep->param_adv_10fdx = 0; 219 bgep->param_adv_10hdx = 0; 220 break; 221 222 case 10: 223 bgep->param_adv_autoneg = 1; 224 bgep->param_adv_1000fdx = 0; 225 bgep->param_adv_1000hdx = 0; 226 bgep->param_adv_100fdx = 0; 227 bgep->param_adv_100hdx = 0; 228 bgep->param_adv_10fdx = 1; 229 bgep->param_adv_10hdx = 1; 230 break; 231 232 default: 233 break; 234 } 235 } 236 237 /* 238 * Also check the "speed" and "full-duplex" properties. Setting 239 * these properties will override all other settings and *disable* 240 * autonegotiation, so both should be specified if either one is. 241 * Otherwise, the unspecified parameter will be set to a default 242 * value (1000Mb/s, full-duplex). 243 */ 244 if (BGE_PROP_EXISTS(dip, speed_propname) || 245 BGE_PROP_EXISTS(dip, duplex_propname)) { 246 247 bgep->param_adv_autoneg = 0; 248 bgep->param_adv_1000fdx = 1; 249 bgep->param_adv_1000hdx = 1; 250 bgep->param_adv_100fdx = 1; 251 bgep->param_adv_100hdx = 1; 252 bgep->param_adv_10fdx = 1; 253 bgep->param_adv_10hdx = 1; 254 255 speed = BGE_PROP_GET_INT(dip, speed_propname); 256 duplex = BGE_PROP_GET_INT(dip, duplex_propname); 257 bge_log(bgep, "%s property is %d", 258 speed_propname, speed); 259 bge_log(bgep, "%s property is %d", 260 duplex_propname, duplex); 261 262 switch (speed) { 263 case 1000: 264 default: 265 bgep->param_adv_100fdx = 0; 266 bgep->param_adv_100hdx = 0; 267 bgep->param_adv_10fdx = 0; 268 bgep->param_adv_10hdx = 0; 269 break; 270 271 case 100: 272 bgep->param_adv_1000fdx = 0; 273 bgep->param_adv_1000hdx = 0; 274 bgep->param_adv_10fdx = 0; 275 bgep->param_adv_10hdx = 0; 276 break; 277 278 case 10: 279 bgep->param_adv_1000fdx = 0; 280 bgep->param_adv_1000hdx = 0; 281 bgep->param_adv_100fdx = 0; 282 bgep->param_adv_100hdx = 0; 283 break; 284 } 285 286 switch (duplex) { 287 default: 288 case 1: 289 bgep->param_adv_1000hdx = 0; 290 bgep->param_adv_100hdx = 0; 291 bgep->param_adv_10hdx = 0; 292 break; 293 294 case 0: 295 bgep->param_adv_1000fdx = 0; 296 bgep->param_adv_100fdx = 0; 297 bgep->param_adv_10fdx = 0; 298 break; 299 } 300 } 301 302 bge_param_sync(bgep); 303 304 return (0); 305 } 306