152d2369aSRobert Mustacchi.\" 252d2369aSRobert Mustacchi.\" This file and its contents are supplied under the terms of the 352d2369aSRobert Mustacchi.\" Common Development and Distribution License ("CDDL"), version 1.0. 452d2369aSRobert Mustacchi.\" You may only use this file in accordance with the terms of version 552d2369aSRobert Mustacchi.\" 1.0 of the CDDL. 652d2369aSRobert Mustacchi.\" 752d2369aSRobert Mustacchi.\" A full copy of the text of the CDDL should have accompanied this 852d2369aSRobert Mustacchi.\" source. A copy of the CDDL is also available via the Internet at 952d2369aSRobert Mustacchi.\" http://www.illumos.org/license/CDDL. 1052d2369aSRobert Mustacchi.\" 1152d2369aSRobert Mustacchi.\" 1252d2369aSRobert Mustacchi.\" Copyright 2016 Joyent, Inc. 1352d2369aSRobert Mustacchi.\" 1452892d1dSRobert Mustacchi.Dd November 15, 2016 1552d2369aSRobert Mustacchi.Dt MC_GETPROP 9E 1652d2369aSRobert Mustacchi.Os 1752d2369aSRobert Mustacchi.Sh NAME 1852d2369aSRobert Mustacchi.Nm mc_getprop 1952d2369aSRobert Mustacchi.Nd get device properties 2052d2369aSRobert Mustacchi.Sh SYNOPSIS 2152d2369aSRobert Mustacchi.In sys/mac_provider.h 2252d2369aSRobert Mustacchi.Ft int 2352d2369aSRobert Mustacchi.Fo prefix_m_getprop 2452d2369aSRobert Mustacchi.Fa "void *driver" 2552d2369aSRobert Mustacchi.Fa "const char *pr_name" 2652d2369aSRobert Mustacchi.Fa "mac_prop_id_t pr_num" 2752d2369aSRobert Mustacchi.Fa "uint_t pr_valsize" 2852d2369aSRobert Mustacchi.Fa "void *pr_val" 2952d2369aSRobert Mustacchi.Fc 3052d2369aSRobert Mustacchi.Sh INTERFACE LEVEL 3152d2369aSRobert Mustacchiillumos DDI specific 3252d2369aSRobert Mustacchi.Sh PARAMETERS 3352d2369aSRobert Mustacchi.Bl -tag -width Fa 3452d2369aSRobert Mustacchi.It Fa driver 3552d2369aSRobert MustacchiA pointer to the driver's private data that was passed in via the 3652d2369aSRobert Mustacchi.Sy m_pdata 3752d2369aSRobert Mustacchimember of the 3852d2369aSRobert Mustacchi.Xr mac_register 9S 3952d2369aSRobert Mustacchistructure to the 4052d2369aSRobert Mustacchi.Xr mac_register 9F 4152d2369aSRobert Mustacchifunction. 4252d2369aSRobert Mustacchi.It Fa pr_name 4352d2369aSRobert MustacchiA null-terminated string that contains the name of the property. 4452d2369aSRobert Mustacchi.It Fa pr_num 4552d2369aSRobert MustacchiA constant that is used to identify the property. 4652d2369aSRobert Mustacchi.It Fa pr_valsize 4752d2369aSRobert MustacchiA value that indicates the size in bytes of 4852d2369aSRobert Mustacchi.Fa pr_val . 4952d2369aSRobert Mustacchi.It Fa pr_val 5052d2369aSRobert MustacchiA pointer to a 5152d2369aSRobert Mustacchi.Fa pr_valsize 5252d2369aSRobert Mustacchibyte buffer that can store the property. 5352d2369aSRobert Mustacchi.El 5452d2369aSRobert Mustacchi.Sh DESCRIPTION 5552d2369aSRobert MustacchiThe 5652d2369aSRobert Mustacchi.Fn mc_getprop 5752d2369aSRobert Mustacchientry point is used to obtain the value of a given device's property and 5852d2369aSRobert Mustacchiplace it into 5952d2369aSRobert Mustacchi.Fa pr_val . 6052d2369aSRobert Mustacchi.Pp 6152d2369aSRobert MustacchiWhen the 6252d2369aSRobert Mustacchi.Fn mc_getprop 6352d2369aSRobert Mustacchientry point is called, the driver needs to first identify the property. 6452d2369aSRobert MustacchiThe set of possible properties and their meaning is listed in the 6552d2369aSRobert Mustacchi.Sx PROPERTIES 6652d2369aSRobert Mustacchisection of 6752d2369aSRobert Mustacchi.Xr mac 9E . 6852d2369aSRobert MustacchiIt should identify the property based on the value of 6952d2369aSRobert Mustacchi.Fa pr_num . 7052d2369aSRobert MustacchiMost drivers will use a 7152d2369aSRobert Mustacchi.Sy switch 7252d2369aSRobert Mustacchistatement and for any property that it supports it should then check if 7352d2369aSRobert Mustacchithe value in 7452d2369aSRobert Mustacchi.Fa pr_valsize 7552d2369aSRobert Mustacchiis sufficient for the property, comparing it to the minimum size 7652d2369aSRobert Mustacchilisted for the property in 7752d2369aSRobert Mustacchi.Xr mac 9E . 78*72d3dbb9SYuri PankovIf it is not, then it should return an error. 79*72d3dbb9SYuri PankovOtherwise, it should copy the property's value into 8052d2369aSRobert Mustacchi.Fa pr_val . 8152d2369aSRobert MustacchiWhen an unknown or unsupported 8252d2369aSRobert Mustacchiproperty is encountered, generally the 8352d2369aSRobert Mustacchi.Sy default 8452d2369aSRobert Mustacchicase of the switch statement, the device driver should return an error. 8552d2369aSRobert Mustacchi.Pp 8652d2369aSRobert MustacchiThe special property 8752d2369aSRobert Mustacchi.Sy MAC_PROP_PRIVATE 88*72d3dbb9SYuri Pankovindicates that this is a device driver specific private property. 89*72d3dbb9SYuri PankovThe device driver must then look at the value of the 9052d2369aSRobert Mustacchi.Fa pr_name 9152d2369aSRobert Mustacchiargument and use 9252d2369aSRobert Mustacchi.Xr strcmp 9F 9352d2369aSRobert Mustacchion it, comparing it to each of its private (bounded-size) properties to 9452d2369aSRobert Mustacchiidentify which one it is. 9552d2369aSRobert Mustacchi.Pp 96*72d3dbb9SYuri PankovAt this time, private properties are limited to being string based properties. 97*72d3dbb9SYuri PankovIf other types of property values are used, they will not be rendered 98*72d3dbb9SYuri Pankovcorrectly by 9952892d1dSRobert Mustacchi.Xr dladm 1M . 10052892d1dSRobert Mustacchi.Pp 10152d2369aSRobert MustacchiThe device 10252d2369aSRobert Mustacchidriver can access its device soft state by casting the 10352d2369aSRobert Mustacchi.Fa device 104*72d3dbb9SYuri Pankovpointer to the appropriate structure. 105*72d3dbb9SYuri PankovAs this may be called while other operations are ongoing, the device driver 106*72d3dbb9SYuri Pankovshould employ the appropriate locking while reading the properties. 10752d2369aSRobert Mustacchi.Sh CONTEXT 10852d2369aSRobert MustacchiThe 10952d2369aSRobert Mustacchi.Fn mc_getprop 11052d2369aSRobert Mustacchifunction is generally called from 11152d2369aSRobert Mustacchi.Sy kernel 11252d2369aSRobert Mustacchicontext. 11352d2369aSRobert Mustacchi.Sh RETURN VALUES 11452d2369aSRobert MustacchiUpon successful completion, the device driver should have copied the 11552d2369aSRobert Mustacchivalue of the property into 11652d2369aSRobert Mustacchi.Fa pr_val 11752d2369aSRobert Mustacchiand return 11852d2369aSRobert Mustacchi.Sy 0 . 11952d2369aSRobert MustacchiOtherwise, a positive error should be returned to indicate failure. 12052d2369aSRobert Mustacchi.Sh EXAMPLES 12152d2369aSRobert MustacchiThe following example shows how a device driver might structure its 12252d2369aSRobert Mustacchi.Fn mc_getprop 12352d2369aSRobert Mustacchientry point. 12452d2369aSRobert Mustacchi.Bd -literal 12552d2369aSRobert Mustacchi#include <sys/mac_provider.h> 12652d2369aSRobert Mustacchi 12752d2369aSRobert Mustacchi/* 12852d2369aSRobert Mustacchi * Note, this example merely shows the structure of this function. 12952d2369aSRobert Mustacchi * Different devices will manage their state in different ways. Like other 13052d2369aSRobert Mustacchi * examples, this assumes that the device has state in a structure called 13152d2369aSRobert Mustacchi * example_t and that there is a lock which keeps track of that state. 13252d2369aSRobert Mustacchi */ 13352d2369aSRobert Mustacchistatic char *example_priv_props[] = { 13452d2369aSRobert Mustacchi "_rx_intr_throttle", 13552d2369aSRobert Mustacchi "_tx_intr_throttle", 13652d2369aSRobert Mustacchi NULL 13752d2369aSRobert Mustacchi}; 13852d2369aSRobert Mustacchi 13952d2369aSRobert Mustacchistatic int 14052d2369aSRobert Mustacchiexample_m_getprop_private(example_t *ep, const char *pr_name, uint_t pr_valsize, 14152d2369aSRobert Mustacchi void *pr_val) 14252d2369aSRobert Mustacchi{ 14352d2369aSRobert Mustacchi uint32_t val; 14452d2369aSRobert Mustacchi 14552d2369aSRobert Mustacchi ASSERT(MUTEX_HELD(&ep->ep_lock)); 14652d2369aSRobert Mustacchi if (strcmp(pr_name, example_priv_props[0] == 0) { 14752d2369aSRobert Mustacchi val = ep->ep_rx_itr; 14852d2369aSRobert Mustacchi } else if (strcmp(pr_name, exampe_priv_props[1] == 0) { 14952d2369aSRobert Mustacchi val = ep->ep_tx_itr; 15052d2369aSRobert Mustacchi } else { 15152d2369aSRobert Mustacchi return (ENOTSUP); 15252d2369aSRobert Mustacchi } 15352d2369aSRobert Mustacchi 15452d2369aSRobert Mustacchi /* 15552d2369aSRobert Mustacchi * Due to issues in the GLDv3, these must be returned as string 15652d2369aSRobert Mustacchi * properties. 15752d2369aSRobert Mustacchi */ 15852d2369aSRobert Mustacchi if (snprintf(pr_val, pr_valsize, "%d", val) >= pr_valsize) 15952d2369aSRobert Mustacchi return (EOVERFLOW); 16052d2369aSRobert Mustacchi 16152d2369aSRobert Mustacchi return (0); 16252d2369aSRobert Mustacchi} 16352d2369aSRobert Mustacchi 16452d2369aSRobert Mustacchistatic int 16552d2369aSRobert Mustacchiexample_m_getprop(void *arg, const char *pr_name, mac_prop_id_t pr_num, 16652d2369aSRobert Mustacchi uint_t pr_valsize, void *pr_val) 16752d2369aSRobert Mustacchi{ 16852d2369aSRobert Mustacchi int ret = 0; 16952d2369aSRobert Mustacchi uint64_t speed; 17052d2369aSRobert Mustacchi example_t *ep = arg; 17152d2369aSRobert Mustacchi 17252d2369aSRobert Mustacchi mutex_enter(&ep->ep_lock); 17352d2369aSRobert Mustacchi 17452d2369aSRobert Mustacchi /* 17552d2369aSRobert Mustacchi * This only handles a subset of the properties that exist on the 17652d2369aSRobert Mustacchi * system. A proper driver will need to handle more. See mac(9E) for a 17752d2369aSRobert Mustacchi * full property list. 17852d2369aSRobert Mustacchi */ 17952d2369aSRobert Mustacchi switch (pr_num) { 18052d2369aSRobert Mustacchi case MAC_PROP_DUPLEX: 18152d2369aSRobert Mustacchi if (pr_valsize < sizeof (link_duplex_t)) { 18252d2369aSRobert Mustacchi ret = EOVERFLOW; 18352d2369aSRobert Mustacchi break; 18452d2369aSRobert Mustacchi } 18552d2369aSRobert Mustacchi bcopy(ep->ep_link_duplex, pr_val, sizeof (link_duplex_t)); 18652d2369aSRobert Mustacchi case MAC_PROP_SPEED: 18752d2369aSRobert Mustacchi if (pr_valsize < sizeof (uint64_t)) { 18852d2369aSRobert Mustacchi ret = EOVERFLOW; 18952d2369aSRobert Mustacchi break; 19052d2369aSRobert Mustacchi } 19152d2369aSRobert Mustacchi /* 19252d2369aSRobert Mustacchi * The link speed is stored in Mbits/s in this driver and is 19352d2369aSRobert Mustacchi * expected in bits/s. 19452d2369aSRobert Mustacchi */ 19552d2369aSRobert Mustacchi speed = ep->ep_link_speed * 1000000ULL; 19652d2369aSRobert Mustacchi bcopy(&speed, pr_val, sizeof (speed)); 19752d2369aSRobert Mustacchi break; 19852d2369aSRobert Mustacchi case MAC_PROP_MTU: 19952d2369aSRobert Mustacchi if (pr_valsize < sizeof (uint32_t)) { 20052d2369aSRobert Mustacchi ret = EOVERFLOW; 20152d2369aSRobert Mustacchi break; 20252d2369aSRobert Mustacchi } 20352d2369aSRobert Mustacchi bcopy(&ep->ep_mtu, pr_val, sizeof (speed)); 20452d2369aSRobert Mustacchi break; 20552d2369aSRobert Mustacchi case MAC_PROP_PRIVATE: 20652d2369aSRobert Mustacchi ret = example_m_getprop_private(ep, pr_name, pr_valsize, 20752d2369aSRobert Mustacchi pr_val); 20852d2369aSRobert Mustacchi break; 20952d2369aSRobert Mustacchi default: 21052d2369aSRobert Mustacchi ret = ENOTSUP; 21152d2369aSRobert Mustacchi break; 21252d2369aSRobert Mustacchi } 21352d2369aSRobert Mustacchi 21452d2369aSRobert Mustacchi mutex_exit(&ep->ep_lock); 21552d2369aSRobert Mustacchi 21652d2369aSRobert Mustacchi return (ret); 21752d2369aSRobert Mustacchi} 21852d2369aSRobert Mustacchi.Ed 21952d2369aSRobert Mustacchi.Sh ERRORS 220*72d3dbb9SYuri PankovThe device driver may return one of the following errors. 221*72d3dbb9SYuri PankovWhile this list is not intended to be exhaustive, it is recommended to use one 222*72d3dbb9SYuri Pankovof these if possible. 22352d2369aSRobert Mustacchi.Bl -tag -width Er 22452d2369aSRobert Mustacchi.It Er ENOTSUP 22552d2369aSRobert MustacchiThis error should be used whenever an unknown or unsupported property is 22652d2369aSRobert Mustacchiencountered. 22752d2369aSRobert Mustacchi.It Er EOVERFLOW 22852d2369aSRobert MustacchiThis error should be used when 22952d2369aSRobert Mustacchi.Fa pr_valsize 23052d2369aSRobert Mustacchiis smaller than the required size for a given value. 23152d2369aSRobert Mustacchi.El 23252d2369aSRobert Mustacchi.Sh SEE ALSO 23352d2369aSRobert Mustacchi.Xr mac 9E , 23452d2369aSRobert Mustacchi.Xr mac_register 9F , 23552d2369aSRobert Mustacchi.Xr strcmp 9F , 23652d2369aSRobert Mustacchi.Xr mac_register 9S 237