From owner-svn-src-stable-10@freebsd.org Mon May 9 13:09:43 2016 Return-Path: Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 332FBB3321A; Mon, 9 May 2016 13:09:43 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 0F2571DC3; Mon, 9 May 2016 13:09:42 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u49D9gN7073747; Mon, 9 May 2016 13:09:42 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u49D9gu3073744; Mon, 9 May 2016 13:09:42 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201605091309.u49D9gu3073744@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Mon, 9 May 2016 13:09:42 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r299258 - in stable/10/sys/dev/mlx5: . mlx5_core mlx5_en X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 May 2016 13:09:43 -0000 Author: hselasky Date: Mon May 9 13:09:41 2016 New Revision: 299258 URL: https://svnweb.freebsd.org/changeset/base/299258 Log: MFC r298771: Add function to detect the presence of a port module and use this function to error out early when no port module is present and doing eeprom access. This also prevents error codes from filling up in dmesg. Sponsored by: Mellanox Technologies Tested by: Netflix Modified: stable/10/sys/dev/mlx5/driver.h stable/10/sys/dev/mlx5/mlx5_core/mlx5_eq.c stable/10/sys/dev/mlx5/mlx5_en/mlx5_en_main.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/mlx5/driver.h ============================================================================== --- stable/10/sys/dev/mlx5/driver.h Mon May 9 12:24:39 2016 (r299257) +++ stable/10/sys/dev/mlx5/driver.h Mon May 9 13:09:41 2016 (r299258) @@ -542,6 +542,7 @@ struct mlx5_core_dev { atomic_t num_qps; u32 issi; struct mlx5_special_contexts special_contexts; + unsigned int module_status[MLX5_MAX_PORTS]; }; enum { @@ -835,6 +836,7 @@ int mlx5_set_port_mtu(struct mlx5_core_d int mlx5_query_port_max_mtu(struct mlx5_core_dev *dev, int *max_mtu); int mlx5_query_port_oper_mtu(struct mlx5_core_dev *dev, int *oper_mtu); +unsigned int mlx5_query_module_status(struct mlx5_core_dev *dev, int module_num); int mlx5_query_module_num(struct mlx5_core_dev *dev, int *module_num); int mlx5_query_eeprom(struct mlx5_core_dev *dev, int i2c_addr, int page_num, int device_addr, int size, int module_num, u32 *data, Modified: stable/10/sys/dev/mlx5/mlx5_core/mlx5_eq.c ============================================================================== --- stable/10/sys/dev/mlx5/mlx5_core/mlx5_eq.c Mon May 9 12:24:39 2016 (r299257) +++ stable/10/sys/dev/mlx5/mlx5_core/mlx5_eq.c Mon May 9 13:09:41 2016 (r299258) @@ -581,6 +581,13 @@ static const char *mlx5_port_module_even } } +unsigned int mlx5_query_module_status(struct mlx5_core_dev *dev, int module_num) +{ + if (module_num < 0 || module_num >= MLX5_MAX_PORTS) + return 0; /* undefined */ + return dev->module_status[module_num]; +} + static void mlx5_port_module_event(struct mlx5_core_dev *dev, struct mlx5_eqe *eqe) { @@ -614,5 +621,8 @@ static void mlx5_port_module_event(struc default: device_printf((&pdev->dev)->bsddev, "INFO: ""Module %u, unknown status", module_num); } + /* store module status */ + if (module_num < MLX5_MAX_PORTS) + dev->module_status[module_num] = module_status; } Modified: stable/10/sys/dev/mlx5/mlx5_en/mlx5_en_main.c ============================================================================== --- stable/10/sys/dev/mlx5/mlx5_en/mlx5_en_main.c Mon May 9 12:24:39 2016 (r299257) +++ stable/10/sys/dev/mlx5/mlx5_en/mlx5_en_main.c Mon May 9 13:09:41 2016 (r299258) @@ -2561,7 +2561,12 @@ out: "reading is not supported\n"); goto err_i2c; } - + /* Check if module is present before doing an access */ + if (mlx5_query_module_status(priv->mdev, module_num) != + MLX5_MODULE_STATUS_PLUGGED) { + error = EINVAL; + goto err_i2c; + } /* * Currently 0XA0 and 0xA2 are the only addresses permitted. * The internal conversion is as follows: