Path: blob/master/drivers/infiniband/hw/ipath/ipath_sysfs.c
15112 views
/*1* Copyright (c) 2006, 2007, 2008 QLogic Corporation. All rights reserved.2* Copyright (c) 2006 PathScale, Inc. All rights reserved.3*4* This software is available to you under a choice of one of two5* licenses. You may choose to be licensed under the terms of the GNU6* General Public License (GPL) Version 2, available from the file7* COPYING in the main directory of this source tree, or the8* OpenIB.org BSD license below:9*10* Redistribution and use in source and binary forms, with or11* without modification, are permitted provided that the following12* conditions are met:13*14* - Redistributions of source code must retain the above15* copyright notice, this list of conditions and the following16* disclaimer.17*18* - Redistributions in binary form must reproduce the above19* copyright notice, this list of conditions and the following20* disclaimer in the documentation and/or other materials21* provided with the distribution.22*23* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,24* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF25* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND26* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS27* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN28* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN29* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE30* SOFTWARE.31*/3233#include <linux/ctype.h>3435#include "ipath_kernel.h"36#include "ipath_verbs.h"37#include "ipath_common.h"3839/**40* ipath_parse_ushort - parse an unsigned short value in an arbitrary base41* @str: the string containing the number42* @valp: where to put the result43*44* returns the number of bytes consumed, or negative value on error45*/46int ipath_parse_ushort(const char *str, unsigned short *valp)47{48unsigned long val;49char *end;50int ret;5152if (!isdigit(str[0])) {53ret = -EINVAL;54goto bail;55}5657val = simple_strtoul(str, &end, 0);5859if (val > 0xffff) {60ret = -EINVAL;61goto bail;62}6364*valp = val;6566ret = end + 1 - str;67if (ret == 0)68ret = -EINVAL;6970bail:71return ret;72}7374static ssize_t show_version(struct device_driver *dev, char *buf)75{76/* The string printed here is already newline-terminated. */77return scnprintf(buf, PAGE_SIZE, "%s", ib_ipath_version);78}7980static ssize_t show_num_units(struct device_driver *dev, char *buf)81{82return scnprintf(buf, PAGE_SIZE, "%d\n",83ipath_count_units(NULL, NULL, NULL));84}8586static ssize_t show_status(struct device *dev,87struct device_attribute *attr,88char *buf)89{90struct ipath_devdata *dd = dev_get_drvdata(dev);91ssize_t ret;9293if (!dd->ipath_statusp) {94ret = -EINVAL;95goto bail;96}9798ret = scnprintf(buf, PAGE_SIZE, "0x%llx\n",99(unsigned long long) *(dd->ipath_statusp));100101bail:102return ret;103}104105static const char *ipath_status_str[] = {106"Initted",107"Disabled",108"Admin_Disabled",109"", /* This used to be the old "OIB_SMA" status. */110"", /* This used to be the old "SMA" status. */111"Present",112"IB_link_up",113"IB_configured",114"NoIBcable",115"Fatal_Hardware_Error",116NULL,117};118119static ssize_t show_status_str(struct device *dev,120struct device_attribute *attr,121char *buf)122{123struct ipath_devdata *dd = dev_get_drvdata(dev);124int i, any;125u64 s;126ssize_t ret;127128if (!dd->ipath_statusp) {129ret = -EINVAL;130goto bail;131}132133s = *(dd->ipath_statusp);134*buf = '\0';135for (any = i = 0; s && ipath_status_str[i]; i++) {136if (s & 1) {137if (any && strlcat(buf, " ", PAGE_SIZE) >=138PAGE_SIZE)139/* overflow */140break;141if (strlcat(buf, ipath_status_str[i],142PAGE_SIZE) >= PAGE_SIZE)143break;144any = 1;145}146s >>= 1;147}148if (any)149strlcat(buf, "\n", PAGE_SIZE);150151ret = strlen(buf);152153bail:154return ret;155}156157static ssize_t show_boardversion(struct device *dev,158struct device_attribute *attr,159char *buf)160{161struct ipath_devdata *dd = dev_get_drvdata(dev);162/* The string printed here is already newline-terminated. */163return scnprintf(buf, PAGE_SIZE, "%s", dd->ipath_boardversion);164}165166static ssize_t show_localbus_info(struct device *dev,167struct device_attribute *attr,168char *buf)169{170struct ipath_devdata *dd = dev_get_drvdata(dev);171/* The string printed here is already newline-terminated. */172return scnprintf(buf, PAGE_SIZE, "%s", dd->ipath_lbus_info);173}174175static ssize_t show_lmc(struct device *dev,176struct device_attribute *attr,177char *buf)178{179struct ipath_devdata *dd = dev_get_drvdata(dev);180181return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_lmc);182}183184static ssize_t store_lmc(struct device *dev,185struct device_attribute *attr,186const char *buf,187size_t count)188{189struct ipath_devdata *dd = dev_get_drvdata(dev);190u16 lmc = 0;191int ret;192193ret = ipath_parse_ushort(buf, &lmc);194if (ret < 0)195goto invalid;196197if (lmc > 7) {198ret = -EINVAL;199goto invalid;200}201202ipath_set_lid(dd, dd->ipath_lid, lmc);203204goto bail;205invalid:206ipath_dev_err(dd, "attempt to set invalid LMC %u\n", lmc);207bail:208return ret;209}210211static ssize_t show_lid(struct device *dev,212struct device_attribute *attr,213char *buf)214{215struct ipath_devdata *dd = dev_get_drvdata(dev);216217return scnprintf(buf, PAGE_SIZE, "0x%x\n", dd->ipath_lid);218}219220static ssize_t store_lid(struct device *dev,221struct device_attribute *attr,222const char *buf,223size_t count)224{225struct ipath_devdata *dd = dev_get_drvdata(dev);226u16 lid = 0;227int ret;228229ret = ipath_parse_ushort(buf, &lid);230if (ret < 0)231goto invalid;232233if (lid == 0 || lid >= IPATH_MULTICAST_LID_BASE) {234ret = -EINVAL;235goto invalid;236}237238ipath_set_lid(dd, lid, dd->ipath_lmc);239240goto bail;241invalid:242ipath_dev_err(dd, "attempt to set invalid LID 0x%x\n", lid);243bail:244return ret;245}246247static ssize_t show_mlid(struct device *dev,248struct device_attribute *attr,249char *buf)250{251struct ipath_devdata *dd = dev_get_drvdata(dev);252253return scnprintf(buf, PAGE_SIZE, "0x%x\n", dd->ipath_mlid);254}255256static ssize_t store_mlid(struct device *dev,257struct device_attribute *attr,258const char *buf,259size_t count)260{261struct ipath_devdata *dd = dev_get_drvdata(dev);262u16 mlid;263int ret;264265ret = ipath_parse_ushort(buf, &mlid);266if (ret < 0 || mlid < IPATH_MULTICAST_LID_BASE)267goto invalid;268269dd->ipath_mlid = mlid;270271goto bail;272invalid:273ipath_dev_err(dd, "attempt to set invalid MLID\n");274bail:275return ret;276}277278static ssize_t show_guid(struct device *dev,279struct device_attribute *attr,280char *buf)281{282struct ipath_devdata *dd = dev_get_drvdata(dev);283u8 *guid;284285guid = (u8 *) & (dd->ipath_guid);286287return scnprintf(buf, PAGE_SIZE,288"%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",289guid[0], guid[1], guid[2], guid[3],290guid[4], guid[5], guid[6], guid[7]);291}292293static ssize_t store_guid(struct device *dev,294struct device_attribute *attr,295const char *buf,296size_t count)297{298struct ipath_devdata *dd = dev_get_drvdata(dev);299ssize_t ret;300unsigned short guid[8];301__be64 new_guid;302u8 *ng;303int i;304305if (sscanf(buf, "%hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx",306&guid[0], &guid[1], &guid[2], &guid[3],307&guid[4], &guid[5], &guid[6], &guid[7]) != 8)308goto invalid;309310ng = (u8 *) &new_guid;311312for (i = 0; i < 8; i++) {313if (guid[i] > 0xff)314goto invalid;315ng[i] = guid[i];316}317318if (new_guid == 0)319goto invalid;320321dd->ipath_guid = new_guid;322dd->ipath_nguid = 1;323if (dd->verbs_dev)324dd->verbs_dev->ibdev.node_guid = new_guid;325326ret = strlen(buf);327goto bail;328329invalid:330ipath_dev_err(dd, "attempt to set invalid GUID\n");331ret = -EINVAL;332333bail:334return ret;335}336337static ssize_t show_nguid(struct device *dev,338struct device_attribute *attr,339char *buf)340{341struct ipath_devdata *dd = dev_get_drvdata(dev);342343return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_nguid);344}345346static ssize_t show_nports(struct device *dev,347struct device_attribute *attr,348char *buf)349{350struct ipath_devdata *dd = dev_get_drvdata(dev);351352/* Return the number of user ports available. */353return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_cfgports - 1);354}355356static ssize_t show_serial(struct device *dev,357struct device_attribute *attr,358char *buf)359{360struct ipath_devdata *dd = dev_get_drvdata(dev);361362buf[sizeof dd->ipath_serial] = '\0';363memcpy(buf, dd->ipath_serial, sizeof dd->ipath_serial);364strcat(buf, "\n");365return strlen(buf);366}367368static ssize_t show_unit(struct device *dev,369struct device_attribute *attr,370char *buf)371{372struct ipath_devdata *dd = dev_get_drvdata(dev);373374return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_unit);375}376377static ssize_t show_jint_max_packets(struct device *dev,378struct device_attribute *attr,379char *buf)380{381struct ipath_devdata *dd = dev_get_drvdata(dev);382383return scnprintf(buf, PAGE_SIZE, "%hu\n", dd->ipath_jint_max_packets);384}385386static ssize_t store_jint_max_packets(struct device *dev,387struct device_attribute *attr,388const char *buf,389size_t count)390{391struct ipath_devdata *dd = dev_get_drvdata(dev);392u16 v = 0;393int ret;394395ret = ipath_parse_ushort(buf, &v);396if (ret < 0)397ipath_dev_err(dd, "invalid jint_max_packets.\n");398else399dd->ipath_f_config_jint(dd, dd->ipath_jint_idle_ticks, v);400401return ret;402}403404static ssize_t show_jint_idle_ticks(struct device *dev,405struct device_attribute *attr,406char *buf)407{408struct ipath_devdata *dd = dev_get_drvdata(dev);409410return scnprintf(buf, PAGE_SIZE, "%hu\n", dd->ipath_jint_idle_ticks);411}412413static ssize_t store_jint_idle_ticks(struct device *dev,414struct device_attribute *attr,415const char *buf,416size_t count)417{418struct ipath_devdata *dd = dev_get_drvdata(dev);419u16 v = 0;420int ret;421422ret = ipath_parse_ushort(buf, &v);423if (ret < 0)424ipath_dev_err(dd, "invalid jint_idle_ticks.\n");425else426dd->ipath_f_config_jint(dd, v, dd->ipath_jint_max_packets);427428return ret;429}430431#define DEVICE_COUNTER(name, attr) \432static ssize_t show_counter_##name(struct device *dev, \433struct device_attribute *attr, \434char *buf) \435{ \436struct ipath_devdata *dd = dev_get_drvdata(dev); \437return scnprintf(\438buf, PAGE_SIZE, "%llu\n", (unsigned long long) \439ipath_snap_cntr( \440dd, offsetof(struct infinipath_counters, \441attr) / sizeof(u64))); \442} \443static DEVICE_ATTR(name, S_IRUGO, show_counter_##name, NULL);444445DEVICE_COUNTER(ib_link_downeds, IBLinkDownedCnt);446DEVICE_COUNTER(ib_link_err_recoveries, IBLinkErrRecoveryCnt);447DEVICE_COUNTER(ib_status_changes, IBStatusChangeCnt);448DEVICE_COUNTER(ib_symbol_errs, IBSymbolErrCnt);449DEVICE_COUNTER(lb_flow_stalls, LBFlowStallCnt);450DEVICE_COUNTER(lb_ints, LBIntCnt);451DEVICE_COUNTER(rx_bad_formats, RxBadFormatCnt);452DEVICE_COUNTER(rx_buf_ovfls, RxBufOvflCnt);453DEVICE_COUNTER(rx_data_pkts, RxDataPktCnt);454DEVICE_COUNTER(rx_dropped_pkts, RxDroppedPktCnt);455DEVICE_COUNTER(rx_dwords, RxDwordCnt);456DEVICE_COUNTER(rx_ebps, RxEBPCnt);457DEVICE_COUNTER(rx_flow_ctrl_errs, RxFlowCtrlErrCnt);458DEVICE_COUNTER(rx_flow_pkts, RxFlowPktCnt);459DEVICE_COUNTER(rx_icrc_errs, RxICRCErrCnt);460DEVICE_COUNTER(rx_len_errs, RxLenErrCnt);461DEVICE_COUNTER(rx_link_problems, RxLinkProblemCnt);462DEVICE_COUNTER(rx_lpcrc_errs, RxLPCRCErrCnt);463DEVICE_COUNTER(rx_max_min_len_errs, RxMaxMinLenErrCnt);464DEVICE_COUNTER(rx_p0_hdr_egr_ovfls, RxP0HdrEgrOvflCnt);465DEVICE_COUNTER(rx_p1_hdr_egr_ovfls, RxP1HdrEgrOvflCnt);466DEVICE_COUNTER(rx_p2_hdr_egr_ovfls, RxP2HdrEgrOvflCnt);467DEVICE_COUNTER(rx_p3_hdr_egr_ovfls, RxP3HdrEgrOvflCnt);468DEVICE_COUNTER(rx_p4_hdr_egr_ovfls, RxP4HdrEgrOvflCnt);469DEVICE_COUNTER(rx_p5_hdr_egr_ovfls, RxP5HdrEgrOvflCnt);470DEVICE_COUNTER(rx_p6_hdr_egr_ovfls, RxP6HdrEgrOvflCnt);471DEVICE_COUNTER(rx_p7_hdr_egr_ovfls, RxP7HdrEgrOvflCnt);472DEVICE_COUNTER(rx_p8_hdr_egr_ovfls, RxP8HdrEgrOvflCnt);473DEVICE_COUNTER(rx_pkey_mismatches, RxPKeyMismatchCnt);474DEVICE_COUNTER(rx_tid_full_errs, RxTIDFullErrCnt);475DEVICE_COUNTER(rx_tid_valid_errs, RxTIDValidErrCnt);476DEVICE_COUNTER(rx_vcrc_errs, RxVCRCErrCnt);477DEVICE_COUNTER(tx_data_pkts, TxDataPktCnt);478DEVICE_COUNTER(tx_dropped_pkts, TxDroppedPktCnt);479DEVICE_COUNTER(tx_dwords, TxDwordCnt);480DEVICE_COUNTER(tx_flow_pkts, TxFlowPktCnt);481DEVICE_COUNTER(tx_flow_stalls, TxFlowStallCnt);482DEVICE_COUNTER(tx_len_errs, TxLenErrCnt);483DEVICE_COUNTER(tx_max_min_len_errs, TxMaxMinLenErrCnt);484DEVICE_COUNTER(tx_underruns, TxUnderrunCnt);485DEVICE_COUNTER(tx_unsup_vl_errs, TxUnsupVLErrCnt);486487static struct attribute *dev_counter_attributes[] = {488&dev_attr_ib_link_downeds.attr,489&dev_attr_ib_link_err_recoveries.attr,490&dev_attr_ib_status_changes.attr,491&dev_attr_ib_symbol_errs.attr,492&dev_attr_lb_flow_stalls.attr,493&dev_attr_lb_ints.attr,494&dev_attr_rx_bad_formats.attr,495&dev_attr_rx_buf_ovfls.attr,496&dev_attr_rx_data_pkts.attr,497&dev_attr_rx_dropped_pkts.attr,498&dev_attr_rx_dwords.attr,499&dev_attr_rx_ebps.attr,500&dev_attr_rx_flow_ctrl_errs.attr,501&dev_attr_rx_flow_pkts.attr,502&dev_attr_rx_icrc_errs.attr,503&dev_attr_rx_len_errs.attr,504&dev_attr_rx_link_problems.attr,505&dev_attr_rx_lpcrc_errs.attr,506&dev_attr_rx_max_min_len_errs.attr,507&dev_attr_rx_p0_hdr_egr_ovfls.attr,508&dev_attr_rx_p1_hdr_egr_ovfls.attr,509&dev_attr_rx_p2_hdr_egr_ovfls.attr,510&dev_attr_rx_p3_hdr_egr_ovfls.attr,511&dev_attr_rx_p4_hdr_egr_ovfls.attr,512&dev_attr_rx_p5_hdr_egr_ovfls.attr,513&dev_attr_rx_p6_hdr_egr_ovfls.attr,514&dev_attr_rx_p7_hdr_egr_ovfls.attr,515&dev_attr_rx_p8_hdr_egr_ovfls.attr,516&dev_attr_rx_pkey_mismatches.attr,517&dev_attr_rx_tid_full_errs.attr,518&dev_attr_rx_tid_valid_errs.attr,519&dev_attr_rx_vcrc_errs.attr,520&dev_attr_tx_data_pkts.attr,521&dev_attr_tx_dropped_pkts.attr,522&dev_attr_tx_dwords.attr,523&dev_attr_tx_flow_pkts.attr,524&dev_attr_tx_flow_stalls.attr,525&dev_attr_tx_len_errs.attr,526&dev_attr_tx_max_min_len_errs.attr,527&dev_attr_tx_underruns.attr,528&dev_attr_tx_unsup_vl_errs.attr,529NULL530};531532static struct attribute_group dev_counter_attr_group = {533.name = "counters",534.attrs = dev_counter_attributes535};536537static ssize_t store_reset(struct device *dev,538struct device_attribute *attr,539const char *buf,540size_t count)541{542struct ipath_devdata *dd = dev_get_drvdata(dev);543int ret;544545if (count < 5 || memcmp(buf, "reset", 5)) {546ret = -EINVAL;547goto bail;548}549550if (dd->ipath_flags & IPATH_DISABLED) {551/*552* post-reset init would re-enable interrupts, etc.553* so don't allow reset on disabled devices. Not554* perfect error, but about the best choice.555*/556dev_info(dev,"Unit %d is disabled, can't reset\n",557dd->ipath_unit);558ret = -EINVAL;559goto bail;560}561ret = ipath_reset_device(dd->ipath_unit);562bail:563return ret<0 ? ret : count;564}565566static ssize_t store_link_state(struct device *dev,567struct device_attribute *attr,568const char *buf,569size_t count)570{571struct ipath_devdata *dd = dev_get_drvdata(dev);572int ret, r;573u16 state;574575ret = ipath_parse_ushort(buf, &state);576if (ret < 0)577goto invalid;578579r = ipath_set_linkstate(dd, state);580if (r < 0) {581ret = r;582goto bail;583}584585goto bail;586invalid:587ipath_dev_err(dd, "attempt to set invalid link state\n");588bail:589return ret;590}591592static ssize_t show_mtu(struct device *dev,593struct device_attribute *attr,594char *buf)595{596struct ipath_devdata *dd = dev_get_drvdata(dev);597return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_ibmtu);598}599600static ssize_t store_mtu(struct device *dev,601struct device_attribute *attr,602const char *buf,603size_t count)604{605struct ipath_devdata *dd = dev_get_drvdata(dev);606ssize_t ret;607u16 mtu = 0;608int r;609610ret = ipath_parse_ushort(buf, &mtu);611if (ret < 0)612goto invalid;613614r = ipath_set_mtu(dd, mtu);615if (r < 0)616ret = r;617618goto bail;619invalid:620ipath_dev_err(dd, "attempt to set invalid MTU\n");621bail:622return ret;623}624625static ssize_t show_enabled(struct device *dev,626struct device_attribute *attr,627char *buf)628{629struct ipath_devdata *dd = dev_get_drvdata(dev);630return scnprintf(buf, PAGE_SIZE, "%u\n",631(dd->ipath_flags & IPATH_DISABLED) ? 0 : 1);632}633634static ssize_t store_enabled(struct device *dev,635struct device_attribute *attr,636const char *buf,637size_t count)638{639struct ipath_devdata *dd = dev_get_drvdata(dev);640ssize_t ret;641u16 enable = 0;642643ret = ipath_parse_ushort(buf, &enable);644if (ret < 0) {645ipath_dev_err(dd, "attempt to use non-numeric on enable\n");646goto bail;647}648649if (enable) {650if (!(dd->ipath_flags & IPATH_DISABLED))651goto bail;652653dev_info(dev, "Enabling unit %d\n", dd->ipath_unit);654/* same as post-reset */655ret = ipath_init_chip(dd, 1);656if (ret)657ipath_dev_err(dd, "Failed to enable unit %d\n",658dd->ipath_unit);659else {660dd->ipath_flags &= ~IPATH_DISABLED;661*dd->ipath_statusp &= ~IPATH_STATUS_ADMIN_DISABLED;662}663}664else if (!(dd->ipath_flags & IPATH_DISABLED)) {665dev_info(dev, "Disabling unit %d\n", dd->ipath_unit);666ipath_shutdown_device(dd);667dd->ipath_flags |= IPATH_DISABLED;668*dd->ipath_statusp |= IPATH_STATUS_ADMIN_DISABLED;669}670671bail:672return ret;673}674675static ssize_t store_rx_pol_inv(struct device *dev,676struct device_attribute *attr,677const char *buf,678size_t count)679{680struct ipath_devdata *dd = dev_get_drvdata(dev);681int ret, r;682u16 val;683684ret = ipath_parse_ushort(buf, &val);685if (ret < 0)686goto invalid;687688r = ipath_set_rx_pol_inv(dd, val);689if (r < 0) {690ret = r;691goto bail;692}693694goto bail;695invalid:696ipath_dev_err(dd, "attempt to set invalid Rx Polarity invert\n");697bail:698return ret;699}700701static ssize_t store_led_override(struct device *dev,702struct device_attribute *attr,703const char *buf,704size_t count)705{706struct ipath_devdata *dd = dev_get_drvdata(dev);707int ret;708u16 val;709710ret = ipath_parse_ushort(buf, &val);711if (ret > 0)712ipath_set_led_override(dd, val);713else714ipath_dev_err(dd, "attempt to set invalid LED override\n");715return ret;716}717718static ssize_t show_logged_errs(struct device *dev,719struct device_attribute *attr,720char *buf)721{722struct ipath_devdata *dd = dev_get_drvdata(dev);723int idx, count;724725/* force consistency with actual EEPROM */726if (ipath_update_eeprom_log(dd) != 0)727return -ENXIO;728729count = 0;730for (idx = 0; idx < IPATH_EEP_LOG_CNT; ++idx) {731count += scnprintf(buf + count, PAGE_SIZE - count, "%d%c",732dd->ipath_eep_st_errs[idx],733idx == (IPATH_EEP_LOG_CNT - 1) ? '\n' : ' ');734}735736return count;737}738739/*740* New sysfs entries to control various IB config. These all turn into741* accesses via ipath_f_get/set_ib_cfg.742*743* Get/Set heartbeat enable. Or of 1=enabled, 2=auto744*/745static ssize_t show_hrtbt_enb(struct device *dev,746struct device_attribute *attr,747char *buf)748{749struct ipath_devdata *dd = dev_get_drvdata(dev);750int ret;751752ret = dd->ipath_f_get_ib_cfg(dd, IPATH_IB_CFG_HRTBT);753if (ret >= 0)754ret = scnprintf(buf, PAGE_SIZE, "%d\n", ret);755return ret;756}757758static ssize_t store_hrtbt_enb(struct device *dev,759struct device_attribute *attr,760const char *buf,761size_t count)762{763struct ipath_devdata *dd = dev_get_drvdata(dev);764int ret, r;765u16 val;766767ret = ipath_parse_ushort(buf, &val);768if (ret >= 0 && val > 3)769ret = -EINVAL;770if (ret < 0) {771ipath_dev_err(dd, "attempt to set invalid Heartbeat enable\n");772goto bail;773}774775/*776* Set the "intentional" heartbeat enable per either of777* "Enable" and "Auto", as these are normally set together.778* This bit is consulted when leaving loopback mode,779* because entering loopback mode overrides it and automatically780* disables heartbeat.781*/782r = dd->ipath_f_set_ib_cfg(dd, IPATH_IB_CFG_HRTBT, val);783if (r < 0)784ret = r;785else if (val == IPATH_IB_HRTBT_OFF)786dd->ipath_flags |= IPATH_NO_HRTBT;787else788dd->ipath_flags &= ~IPATH_NO_HRTBT;789790bail:791return ret;792}793794/*795* Get/Set Link-widths enabled. Or of 1=1x, 2=4x (this is human/IB centric,796* _not_ the particular encoding of any given chip)797*/798static ssize_t show_lwid_enb(struct device *dev,799struct device_attribute *attr,800char *buf)801{802struct ipath_devdata *dd = dev_get_drvdata(dev);803int ret;804805ret = dd->ipath_f_get_ib_cfg(dd, IPATH_IB_CFG_LWID_ENB);806if (ret >= 0)807ret = scnprintf(buf, PAGE_SIZE, "%d\n", ret);808return ret;809}810811static ssize_t store_lwid_enb(struct device *dev,812struct device_attribute *attr,813const char *buf,814size_t count)815{816struct ipath_devdata *dd = dev_get_drvdata(dev);817int ret, r;818u16 val;819820ret = ipath_parse_ushort(buf, &val);821if (ret >= 0 && (val == 0 || val > 3))822ret = -EINVAL;823if (ret < 0) {824ipath_dev_err(dd,825"attempt to set invalid Link Width (enable)\n");826goto bail;827}828829r = dd->ipath_f_set_ib_cfg(dd, IPATH_IB_CFG_LWID_ENB, val);830if (r < 0)831ret = r;832833bail:834return ret;835}836837/* Get current link width */838static ssize_t show_lwid(struct device *dev,839struct device_attribute *attr,840char *buf)841842{843struct ipath_devdata *dd = dev_get_drvdata(dev);844int ret;845846ret = dd->ipath_f_get_ib_cfg(dd, IPATH_IB_CFG_LWID);847if (ret >= 0)848ret = scnprintf(buf, PAGE_SIZE, "%d\n", ret);849return ret;850}851852/*853* Get/Set Link-speeds enabled. Or of 1=SDR 2=DDR.854*/855static ssize_t show_spd_enb(struct device *dev,856struct device_attribute *attr,857char *buf)858{859struct ipath_devdata *dd = dev_get_drvdata(dev);860int ret;861862ret = dd->ipath_f_get_ib_cfg(dd, IPATH_IB_CFG_SPD_ENB);863if (ret >= 0)864ret = scnprintf(buf, PAGE_SIZE, "%d\n", ret);865return ret;866}867868static ssize_t store_spd_enb(struct device *dev,869struct device_attribute *attr,870const char *buf,871size_t count)872{873struct ipath_devdata *dd = dev_get_drvdata(dev);874int ret, r;875u16 val;876877ret = ipath_parse_ushort(buf, &val);878if (ret >= 0 && (val == 0 || val > (IPATH_IB_SDR | IPATH_IB_DDR)))879ret = -EINVAL;880if (ret < 0) {881ipath_dev_err(dd,882"attempt to set invalid Link Speed (enable)\n");883goto bail;884}885886r = dd->ipath_f_set_ib_cfg(dd, IPATH_IB_CFG_SPD_ENB, val);887if (r < 0)888ret = r;889890bail:891return ret;892}893894/* Get current link speed */895static ssize_t show_spd(struct device *dev,896struct device_attribute *attr,897char *buf)898{899struct ipath_devdata *dd = dev_get_drvdata(dev);900int ret;901902ret = dd->ipath_f_get_ib_cfg(dd, IPATH_IB_CFG_SPD);903if (ret >= 0)904ret = scnprintf(buf, PAGE_SIZE, "%d\n", ret);905return ret;906}907908/*909* Get/Set RX polarity-invert enable. 0=no, 1=yes.910*/911static ssize_t show_rx_polinv_enb(struct device *dev,912struct device_attribute *attr,913char *buf)914{915struct ipath_devdata *dd = dev_get_drvdata(dev);916int ret;917918ret = dd->ipath_f_get_ib_cfg(dd, IPATH_IB_CFG_RXPOL_ENB);919if (ret >= 0)920ret = scnprintf(buf, PAGE_SIZE, "%d\n", ret);921return ret;922}923924static ssize_t store_rx_polinv_enb(struct device *dev,925struct device_attribute *attr,926const char *buf,927size_t count)928{929struct ipath_devdata *dd = dev_get_drvdata(dev);930int ret, r;931u16 val;932933ret = ipath_parse_ushort(buf, &val);934if (ret >= 0 && val > 1) {935ipath_dev_err(dd,936"attempt to set invalid Rx Polarity (enable)\n");937ret = -EINVAL;938goto bail;939}940941r = dd->ipath_f_set_ib_cfg(dd, IPATH_IB_CFG_RXPOL_ENB, val);942if (r < 0)943ret = r;944945bail:946return ret;947}948949/*950* Get/Set RX lane-reversal enable. 0=no, 1=yes.951*/952static ssize_t show_lanerev_enb(struct device *dev,953struct device_attribute *attr,954char *buf)955{956struct ipath_devdata *dd = dev_get_drvdata(dev);957int ret;958959ret = dd->ipath_f_get_ib_cfg(dd, IPATH_IB_CFG_LREV_ENB);960if (ret >= 0)961ret = scnprintf(buf, PAGE_SIZE, "%d\n", ret);962return ret;963}964965static ssize_t store_lanerev_enb(struct device *dev,966struct device_attribute *attr,967const char *buf,968size_t count)969{970struct ipath_devdata *dd = dev_get_drvdata(dev);971int ret, r;972u16 val;973974ret = ipath_parse_ushort(buf, &val);975if (ret >= 0 && val > 1) {976ret = -EINVAL;977ipath_dev_err(dd,978"attempt to set invalid Lane reversal (enable)\n");979goto bail;980}981982r = dd->ipath_f_set_ib_cfg(dd, IPATH_IB_CFG_LREV_ENB, val);983if (r < 0)984ret = r;985986bail:987return ret;988}989990static DRIVER_ATTR(num_units, S_IRUGO, show_num_units, NULL);991static DRIVER_ATTR(version, S_IRUGO, show_version, NULL);992993static struct attribute *driver_attributes[] = {994&driver_attr_num_units.attr,995&driver_attr_version.attr,996NULL997};998999static struct attribute_group driver_attr_group = {1000.attrs = driver_attributes1001};10021003static ssize_t store_tempsense(struct device *dev,1004struct device_attribute *attr,1005const char *buf,1006size_t count)1007{1008struct ipath_devdata *dd = dev_get_drvdata(dev);1009int ret, stat;1010u16 val;10111012ret = ipath_parse_ushort(buf, &val);1013if (ret <= 0) {1014ipath_dev_err(dd, "attempt to set invalid tempsense config\n");1015goto bail;1016}1017/* If anything but the highest limit, enable T_CRIT_A "interrupt" */1018stat = ipath_tempsense_write(dd, 9, (val == 0x7f7f) ? 0x80 : 0);1019if (stat) {1020ipath_dev_err(dd, "Unable to set tempsense config\n");1021ret = -1;1022goto bail;1023}1024stat = ipath_tempsense_write(dd, 0xB, (u8) (val & 0xFF));1025if (stat) {1026ipath_dev_err(dd, "Unable to set local Tcrit\n");1027ret = -1;1028goto bail;1029}1030stat = ipath_tempsense_write(dd, 0xD, (u8) (val >> 8));1031if (stat) {1032ipath_dev_err(dd, "Unable to set remote Tcrit\n");1033ret = -1;1034goto bail;1035}10361037bail:1038return ret;1039}10401041/*1042* dump tempsense regs. in decimal, to ease shell-scripts.1043*/1044static ssize_t show_tempsense(struct device *dev,1045struct device_attribute *attr,1046char *buf)1047{1048struct ipath_devdata *dd = dev_get_drvdata(dev);1049int ret;1050int idx;1051u8 regvals[8];10521053ret = -ENXIO;1054for (idx = 0; idx < 8; ++idx) {1055if (idx == 6)1056continue;1057ret = ipath_tempsense_read(dd, idx);1058if (ret < 0)1059break;1060regvals[idx] = ret;1061}1062if (idx == 8)1063ret = scnprintf(buf, PAGE_SIZE, "%d %d %02X %02X %d %d\n",1064*(signed char *)(regvals),1065*(signed char *)(regvals + 1),1066regvals[2], regvals[3],1067*(signed char *)(regvals + 5),1068*(signed char *)(regvals + 7));1069return ret;1070}10711072const struct attribute_group *ipath_driver_attr_groups[] = {1073&driver_attr_group,1074NULL,1075};10761077static DEVICE_ATTR(guid, S_IWUSR | S_IRUGO, show_guid, store_guid);1078static DEVICE_ATTR(lmc, S_IWUSR | S_IRUGO, show_lmc, store_lmc);1079static DEVICE_ATTR(lid, S_IWUSR | S_IRUGO, show_lid, store_lid);1080static DEVICE_ATTR(link_state, S_IWUSR, NULL, store_link_state);1081static DEVICE_ATTR(mlid, S_IWUSR | S_IRUGO, show_mlid, store_mlid);1082static DEVICE_ATTR(mtu, S_IWUSR | S_IRUGO, show_mtu, store_mtu);1083static DEVICE_ATTR(enabled, S_IWUSR | S_IRUGO, show_enabled, store_enabled);1084static DEVICE_ATTR(nguid, S_IRUGO, show_nguid, NULL);1085static DEVICE_ATTR(nports, S_IRUGO, show_nports, NULL);1086static DEVICE_ATTR(reset, S_IWUSR, NULL, store_reset);1087static DEVICE_ATTR(serial, S_IRUGO, show_serial, NULL);1088static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);1089static DEVICE_ATTR(status_str, S_IRUGO, show_status_str, NULL);1090static DEVICE_ATTR(boardversion, S_IRUGO, show_boardversion, NULL);1091static DEVICE_ATTR(unit, S_IRUGO, show_unit, NULL);1092static DEVICE_ATTR(rx_pol_inv, S_IWUSR, NULL, store_rx_pol_inv);1093static DEVICE_ATTR(led_override, S_IWUSR, NULL, store_led_override);1094static DEVICE_ATTR(logged_errors, S_IRUGO, show_logged_errs, NULL);1095static DEVICE_ATTR(localbus_info, S_IRUGO, show_localbus_info, NULL);1096static DEVICE_ATTR(jint_max_packets, S_IWUSR | S_IRUGO,1097show_jint_max_packets, store_jint_max_packets);1098static DEVICE_ATTR(jint_idle_ticks, S_IWUSR | S_IRUGO,1099show_jint_idle_ticks, store_jint_idle_ticks);1100static DEVICE_ATTR(tempsense, S_IWUSR | S_IRUGO,1101show_tempsense, store_tempsense);11021103static struct attribute *dev_attributes[] = {1104&dev_attr_guid.attr,1105&dev_attr_lmc.attr,1106&dev_attr_lid.attr,1107&dev_attr_link_state.attr,1108&dev_attr_mlid.attr,1109&dev_attr_mtu.attr,1110&dev_attr_nguid.attr,1111&dev_attr_nports.attr,1112&dev_attr_serial.attr,1113&dev_attr_status.attr,1114&dev_attr_status_str.attr,1115&dev_attr_boardversion.attr,1116&dev_attr_unit.attr,1117&dev_attr_enabled.attr,1118&dev_attr_rx_pol_inv.attr,1119&dev_attr_led_override.attr,1120&dev_attr_logged_errors.attr,1121&dev_attr_tempsense.attr,1122&dev_attr_localbus_info.attr,1123NULL1124};11251126static struct attribute_group dev_attr_group = {1127.attrs = dev_attributes1128};11291130static DEVICE_ATTR(hrtbt_enable, S_IWUSR | S_IRUGO, show_hrtbt_enb,1131store_hrtbt_enb);1132static DEVICE_ATTR(link_width_enable, S_IWUSR | S_IRUGO, show_lwid_enb,1133store_lwid_enb);1134static DEVICE_ATTR(link_width, S_IRUGO, show_lwid, NULL);1135static DEVICE_ATTR(link_speed_enable, S_IWUSR | S_IRUGO, show_spd_enb,1136store_spd_enb);1137static DEVICE_ATTR(link_speed, S_IRUGO, show_spd, NULL);1138static DEVICE_ATTR(rx_pol_inv_enable, S_IWUSR | S_IRUGO, show_rx_polinv_enb,1139store_rx_polinv_enb);1140static DEVICE_ATTR(rx_lane_rev_enable, S_IWUSR | S_IRUGO, show_lanerev_enb,1141store_lanerev_enb);11421143static struct attribute *dev_ibcfg_attributes[] = {1144&dev_attr_hrtbt_enable.attr,1145&dev_attr_link_width_enable.attr,1146&dev_attr_link_width.attr,1147&dev_attr_link_speed_enable.attr,1148&dev_attr_link_speed.attr,1149&dev_attr_rx_pol_inv_enable.attr,1150&dev_attr_rx_lane_rev_enable.attr,1151NULL1152};11531154static struct attribute_group dev_ibcfg_attr_group = {1155.attrs = dev_ibcfg_attributes1156};11571158/**1159* ipath_expose_reset - create a device reset file1160* @dev: the device structure1161*1162* Only expose a file that lets us reset the device after someone1163* enters diag mode. A device reset is quite likely to crash the1164* machine entirely, so we don't want to normally make it1165* available.1166*1167* Called with ipath_mutex held.1168*/1169int ipath_expose_reset(struct device *dev)1170{1171static int exposed;1172int ret;11731174if (!exposed) {1175ret = device_create_file(dev, &dev_attr_reset);1176exposed = 1;1177}1178else1179ret = 0;11801181return ret;1182}11831184int ipath_device_create_group(struct device *dev, struct ipath_devdata *dd)1185{1186int ret;11871188ret = sysfs_create_group(&dev->kobj, &dev_attr_group);1189if (ret)1190goto bail;11911192ret = sysfs_create_group(&dev->kobj, &dev_counter_attr_group);1193if (ret)1194goto bail_attrs;11951196if (dd->ipath_flags & IPATH_HAS_MULT_IB_SPEED) {1197ret = device_create_file(dev, &dev_attr_jint_idle_ticks);1198if (ret)1199goto bail_counter;1200ret = device_create_file(dev, &dev_attr_jint_max_packets);1201if (ret)1202goto bail_idle;12031204ret = sysfs_create_group(&dev->kobj, &dev_ibcfg_attr_group);1205if (ret)1206goto bail_max;1207}12081209return 0;12101211bail_max:1212device_remove_file(dev, &dev_attr_jint_max_packets);1213bail_idle:1214device_remove_file(dev, &dev_attr_jint_idle_ticks);1215bail_counter:1216sysfs_remove_group(&dev->kobj, &dev_counter_attr_group);1217bail_attrs:1218sysfs_remove_group(&dev->kobj, &dev_attr_group);1219bail:1220return ret;1221}12221223void ipath_device_remove_group(struct device *dev, struct ipath_devdata *dd)1224{1225sysfs_remove_group(&dev->kobj, &dev_counter_attr_group);12261227if (dd->ipath_flags & IPATH_HAS_MULT_IB_SPEED) {1228sysfs_remove_group(&dev->kobj, &dev_ibcfg_attr_group);1229device_remove_file(dev, &dev_attr_jint_idle_ticks);1230device_remove_file(dev, &dev_attr_jint_max_packets);1231}12321233sysfs_remove_group(&dev->kobj, &dev_attr_group);12341235device_remove_file(dev, &dev_attr_reset);1236}123712381239