2019-01-22 01:05:50 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
net: phy: sfp: enable i2c-bus detection on ACPI based systems
Lookup I2C adapter using the "i2c-bus" device property on ACPI based
systems similar to how it's done with DT.
An example DSD describing an SFP on an ACPI based system:
Device (SFP0)
{
Name (_HID, "PRP0001")
Name (_CRS, ResourceTemplate()
{
GpioIo(Exclusive, PullDefault, 0, 0, IoRestrictionNone,
"\\_SB.PCI0.RP01.GPIO", 0, ResourceConsumer)
{ 0, 1, 2, 3, 4 }
})
Name (_DSD, Package ()
{
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package () {
Package () { "compatible", "sff,sfp" },
Package () { "i2c-bus", \_SB.PCI0.RP01.I2C.MUX.CH0 },
Package () { "maximum-power-milliwatt", 1000 },
Package () { "tx-disable-gpios", Package () { ^SFP0, 0, 0, 1} },
Package () { "reset-gpio", Package () { ^SFP0, 0, 1, 1} },
Package () { "mod-def0-gpios", Package () { ^SFP0, 0, 2, 1} },
Package () { "tx-fault-gpios", Package () { ^SFP0, 0, 3, 0} },
Package () { "los-gpios", Package () { ^SFP0, 0, 4, 1} },
},
})
}
Device (PHY0)
{
Name (_HID, "PRP0001")
Name (_DSD, Package ()
{
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package () {
Package () { "compatible", "ethernet-phy-ieee802.3-c45" },
Package () { "sfp", \_SB.PCI0.RP01.SFP0 },
Package () { "managed", "in-band-status" },
Package () { "phy-mode", "sgmii" },
},
})
}
Signed-off-by: Ruslan Babayev <ruslan@babayev.com>
Cc: xe-linux-external@cisco.com
Acked-by: Russell King <rmk+kernel@armlinux.org.uk>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-05-29 06:02:33 +07:00
|
|
|
#include <linux/acpi.h>
|
net: phy: sfp: Add HWMON support for module sensors
SFP modules can contain a number of sensors. The EEPROM also contains
recommended alarm and critical values for each sensor, and indications
of if these have been exceeded. Export this information via
HWMON. Currently temperature, VCC, bias current, transmit power, and
possibly receiver power is supported.
The sensors in the modules can either return calibrate or uncalibrated
values. Uncalibrated values need to be manipulated, using coefficients
provided in the SFP EEPROM. Uncalibrated receive power values require
floating point maths in order to calibrate them. Performing this in
the kernel is hard. So if the SFP module indicates it uses
uncalibrated values, RX power is not made available.
With this hwmon device, it is possible to view the sensor values using
lm-sensors programs:
in0: +3.29 V (crit min = +2.90 V, min = +3.00 V)
(max = +3.60 V, crit max = +3.70 V)
temp1: +33.0°C (low = -5.0°C, high = +80.0°C)
(crit low = -10.0°C, crit = +85.0°C)
power1: 1000.00 nW (max = 794.00 uW, min = 50.00 uW) ALARM (LCRIT)
(lcrit = 40.00 uW, crit = 1000.00 uW)
curr1: +0.00 A (crit min = +0.00 A, min = +0.00 A) ALARM (LCRIT, MIN)
(max = +0.01 A, crit max = +0.01 A)
The scaling sensors performs on the bias current is not particularly
good. The raw values are more useful:
curr1:
curr1_input: 0.000
curr1_min: 0.002
curr1_max: 0.010
curr1_lcrit: 0.000
curr1_crit: 0.011
curr1_min_alarm: 1.000
curr1_max_alarm: 0.000
curr1_lcrit_alarm: 1.000
curr1_crit_alarm: 0.000
In order to keep the I2C overhead to a minimum, the constant values,
such as limits and calibration coefficients are read once at module
insertion time. Thus only reading *_input and *_alarm properties
requires i2c read operations.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-07-18 02:48:13 +07:00
|
|
|
#include <linux/ctype.h>
|
2017-07-25 21:03:39 +07:00
|
|
|
#include <linux/delay.h>
|
2017-10-31 11:42:58 +07:00
|
|
|
#include <linux/gpio/consumer.h>
|
net: phy: sfp: Add HWMON support for module sensors
SFP modules can contain a number of sensors. The EEPROM also contains
recommended alarm and critical values for each sensor, and indications
of if these have been exceeded. Export this information via
HWMON. Currently temperature, VCC, bias current, transmit power, and
possibly receiver power is supported.
The sensors in the modules can either return calibrate or uncalibrated
values. Uncalibrated values need to be manipulated, using coefficients
provided in the SFP EEPROM. Uncalibrated receive power values require
floating point maths in order to calibrate them. Performing this in
the kernel is hard. So if the SFP module indicates it uses
uncalibrated values, RX power is not made available.
With this hwmon device, it is possible to view the sensor values using
lm-sensors programs:
in0: +3.29 V (crit min = +2.90 V, min = +3.00 V)
(max = +3.60 V, crit max = +3.70 V)
temp1: +33.0°C (low = -5.0°C, high = +80.0°C)
(crit low = -10.0°C, crit = +85.0°C)
power1: 1000.00 nW (max = 794.00 uW, min = 50.00 uW) ALARM (LCRIT)
(lcrit = 40.00 uW, crit = 1000.00 uW)
curr1: +0.00 A (crit min = +0.00 A, min = +0.00 A) ALARM (LCRIT, MIN)
(max = +0.01 A, crit max = +0.01 A)
The scaling sensors performs on the bias current is not particularly
good. The raw values are more useful:
curr1:
curr1_input: 0.000
curr1_min: 0.002
curr1_max: 0.010
curr1_lcrit: 0.000
curr1_crit: 0.011
curr1_min_alarm: 1.000
curr1_max_alarm: 0.000
curr1_lcrit_alarm: 1.000
curr1_crit_alarm: 0.000
In order to keep the I2C overhead to a minimum, the constant values,
such as limits and calibration coefficients are read once at module
insertion time. Thus only reading *_input and *_alarm properties
requires i2c read operations.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-07-18 02:48:13 +07:00
|
|
|
#include <linux/hwmon.h>
|
2017-07-25 21:03:39 +07:00
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/jiffies.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/mutex.h>
|
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/phy.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/rtnetlink.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/workqueue.h>
|
|
|
|
|
|
|
|
#include "mdio-i2c.h"
|
|
|
|
#include "sfp.h"
|
|
|
|
#include "swphy.h"
|
|
|
|
|
|
|
|
enum {
|
|
|
|
GPIO_MODDEF0,
|
|
|
|
GPIO_LOS,
|
|
|
|
GPIO_TX_FAULT,
|
|
|
|
GPIO_TX_DISABLE,
|
|
|
|
GPIO_RATE_SELECT,
|
|
|
|
GPIO_MAX,
|
|
|
|
|
|
|
|
SFP_F_PRESENT = BIT(GPIO_MODDEF0),
|
|
|
|
SFP_F_LOS = BIT(GPIO_LOS),
|
|
|
|
SFP_F_TX_FAULT = BIT(GPIO_TX_FAULT),
|
|
|
|
SFP_F_TX_DISABLE = BIT(GPIO_TX_DISABLE),
|
|
|
|
SFP_F_RATE_SELECT = BIT(GPIO_RATE_SELECT),
|
|
|
|
|
|
|
|
SFP_E_INSERT = 0,
|
|
|
|
SFP_E_REMOVE,
|
2019-11-10 21:07:14 +07:00
|
|
|
SFP_E_DEV_ATTACH,
|
|
|
|
SFP_E_DEV_DETACH,
|
2017-07-25 21:03:39 +07:00
|
|
|
SFP_E_DEV_DOWN,
|
|
|
|
SFP_E_DEV_UP,
|
|
|
|
SFP_E_TX_FAULT,
|
|
|
|
SFP_E_TX_CLEAR,
|
|
|
|
SFP_E_LOS_HIGH,
|
|
|
|
SFP_E_LOS_LOW,
|
|
|
|
SFP_E_TIMEOUT,
|
|
|
|
|
|
|
|
SFP_MOD_EMPTY = 0,
|
2019-11-10 21:07:25 +07:00
|
|
|
SFP_MOD_ERROR,
|
2017-07-25 21:03:39 +07:00
|
|
|
SFP_MOD_PROBE,
|
2019-11-10 21:07:25 +07:00
|
|
|
SFP_MOD_WAITDEV,
|
sfp: add high power module support
This patch is the result of work by both Jon Nettleton and Russell King.
Jon wrote the original patch, adding support for SFP modules which
require a power level greater than '1'.
Russell's changes:
- Fix the power levels for big-endian, and make the code flow better.
- Convert to use device_property_read_u8()
- Warn for power levels exceeding host level
SFF-8431 says:
"To avoid exceeding system power supply limits and cooling capacity,
all modules at power up by default shall operate with up to 1.0 W.
Hosts supporting Power Level II or III operation may enable a Power
Level II or III module through the 2-wire interface. Power Level II
or III modules shall assert the power level declaration bit of
SFF-8472."
Print a warning for modules that exceed the host power level, and
leave them operating in power level 1.
- Fix i2c write
The first byte of any write after the bus address is always the
device address. In order to write a value to device D, address I,
value V, we need to generate on the bus:
S DDDDDDDD A IIIIIIII A VVVVVVVV A P
where S = start, R = restart, A = ack, P = stop. Splitting this
as two:
S DDDDDDDD A IIIIIIII A R DDDDDDDD A VVVVVVVV A P
results in the device's address register being written first by I
and then by V - the addressed register within the device is not
written.
- Avoid power mode switching if 0xa2 is not implemented
Some modules indicate that they support power level II or power level
III, but do not implement address 0xa2, meaning that the bit to set
them to high power mode is not accessible.
These modules appear to have the sff8472_compliance field set to zero,
and also do not implement diagnostics. Detect this, but also ensure
that the module does not require the address switching mode, which we
do not implement.
- Use mW for power level rather than power level number.
- Fix high power mode transition
We must not switch to SFP_MOD_PRESENT state until we have finished
initialising, because the remaining state machines check for that
state. Add SFP_MOD_HPOWER as an intermediate state.
- Use definition for I2C register address rather than constant.
Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-02-27 22:53:12 +07:00
|
|
|
SFP_MOD_HPOWER,
|
2019-11-10 21:07:20 +07:00
|
|
|
SFP_MOD_WAITPWR,
|
2017-07-25 21:03:39 +07:00
|
|
|
SFP_MOD_PRESENT,
|
|
|
|
|
2019-11-10 21:07:14 +07:00
|
|
|
SFP_DEV_DETACHED = 0,
|
|
|
|
SFP_DEV_DOWN,
|
2017-07-25 21:03:39 +07:00
|
|
|
SFP_DEV_UP,
|
|
|
|
|
|
|
|
SFP_S_DOWN = 0,
|
2019-12-11 17:56:09 +07:00
|
|
|
SFP_S_FAIL,
|
2019-11-10 21:06:59 +07:00
|
|
|
SFP_S_WAIT,
|
2017-07-25 21:03:39 +07:00
|
|
|
SFP_S_INIT,
|
2019-12-09 21:16:11 +07:00
|
|
|
SFP_S_INIT_PHY,
|
2019-11-10 21:07:09 +07:00
|
|
|
SFP_S_INIT_TX_FAULT,
|
2017-07-25 21:03:39 +07:00
|
|
|
SFP_S_WAIT_LOS,
|
|
|
|
SFP_S_LINK_UP,
|
|
|
|
SFP_S_TX_FAULT,
|
|
|
|
SFP_S_REINIT,
|
|
|
|
SFP_S_TX_DISABLE,
|
|
|
|
};
|
|
|
|
|
2018-08-09 01:54:12 +07:00
|
|
|
static const char * const mod_state_strings[] = {
|
|
|
|
[SFP_MOD_EMPTY] = "empty",
|
2019-11-10 21:07:25 +07:00
|
|
|
[SFP_MOD_ERROR] = "error",
|
2018-08-09 01:54:12 +07:00
|
|
|
[SFP_MOD_PROBE] = "probe",
|
2019-11-10 21:07:25 +07:00
|
|
|
[SFP_MOD_WAITDEV] = "waitdev",
|
2018-08-09 01:54:12 +07:00
|
|
|
[SFP_MOD_HPOWER] = "hpower",
|
2019-11-10 21:07:20 +07:00
|
|
|
[SFP_MOD_WAITPWR] = "waitpwr",
|
2018-08-09 01:54:12 +07:00
|
|
|
[SFP_MOD_PRESENT] = "present",
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *mod_state_to_str(unsigned short mod_state)
|
|
|
|
{
|
|
|
|
if (mod_state >= ARRAY_SIZE(mod_state_strings))
|
|
|
|
return "Unknown module state";
|
|
|
|
return mod_state_strings[mod_state];
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char * const dev_state_strings[] = {
|
2019-11-10 21:07:14 +07:00
|
|
|
[SFP_DEV_DETACHED] = "detached",
|
2018-08-09 01:54:12 +07:00
|
|
|
[SFP_DEV_DOWN] = "down",
|
|
|
|
[SFP_DEV_UP] = "up",
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *dev_state_to_str(unsigned short dev_state)
|
|
|
|
{
|
|
|
|
if (dev_state >= ARRAY_SIZE(dev_state_strings))
|
|
|
|
return "Unknown device state";
|
|
|
|
return dev_state_strings[dev_state];
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char * const event_strings[] = {
|
|
|
|
[SFP_E_INSERT] = "insert",
|
|
|
|
[SFP_E_REMOVE] = "remove",
|
2019-11-10 21:07:14 +07:00
|
|
|
[SFP_E_DEV_ATTACH] = "dev_attach",
|
|
|
|
[SFP_E_DEV_DETACH] = "dev_detach",
|
2018-08-09 01:54:12 +07:00
|
|
|
[SFP_E_DEV_DOWN] = "dev_down",
|
|
|
|
[SFP_E_DEV_UP] = "dev_up",
|
|
|
|
[SFP_E_TX_FAULT] = "tx_fault",
|
|
|
|
[SFP_E_TX_CLEAR] = "tx_clear",
|
|
|
|
[SFP_E_LOS_HIGH] = "los_high",
|
|
|
|
[SFP_E_LOS_LOW] = "los_low",
|
|
|
|
[SFP_E_TIMEOUT] = "timeout",
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *event_to_str(unsigned short event)
|
|
|
|
{
|
|
|
|
if (event >= ARRAY_SIZE(event_strings))
|
|
|
|
return "Unknown event";
|
|
|
|
return event_strings[event];
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char * const sm_state_strings[] = {
|
|
|
|
[SFP_S_DOWN] = "down",
|
2019-12-11 17:56:09 +07:00
|
|
|
[SFP_S_FAIL] = "fail",
|
2019-11-10 21:06:59 +07:00
|
|
|
[SFP_S_WAIT] = "wait",
|
2018-08-09 01:54:12 +07:00
|
|
|
[SFP_S_INIT] = "init",
|
2019-12-09 21:16:11 +07:00
|
|
|
[SFP_S_INIT_PHY] = "init_phy",
|
2019-11-10 21:07:09 +07:00
|
|
|
[SFP_S_INIT_TX_FAULT] = "init_tx_fault",
|
2018-08-09 01:54:12 +07:00
|
|
|
[SFP_S_WAIT_LOS] = "wait_los",
|
|
|
|
[SFP_S_LINK_UP] = "link_up",
|
|
|
|
[SFP_S_TX_FAULT] = "tx_fault",
|
|
|
|
[SFP_S_REINIT] = "reinit",
|
|
|
|
[SFP_S_TX_DISABLE] = "rx_disable",
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *sm_state_to_str(unsigned short sm_state)
|
|
|
|
{
|
|
|
|
if (sm_state >= ARRAY_SIZE(sm_state_strings))
|
|
|
|
return "Unknown state";
|
|
|
|
return sm_state_strings[sm_state];
|
|
|
|
}
|
|
|
|
|
2017-07-25 21:03:39 +07:00
|
|
|
static const char *gpio_of_names[] = {
|
2017-09-07 16:25:50 +07:00
|
|
|
"mod-def0",
|
2017-07-25 21:03:39 +07:00
|
|
|
"los",
|
|
|
|
"tx-fault",
|
|
|
|
"tx-disable",
|
2017-09-07 16:25:50 +07:00
|
|
|
"rate-select0",
|
2017-07-25 21:03:39 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static const enum gpiod_flags gpio_flags[] = {
|
|
|
|
GPIOD_IN,
|
|
|
|
GPIOD_IN,
|
|
|
|
GPIOD_IN,
|
|
|
|
GPIOD_ASIS,
|
|
|
|
GPIOD_ASIS,
|
|
|
|
};
|
|
|
|
|
2019-12-09 20:40:23 +07:00
|
|
|
/* t_start_up (SFF-8431) or t_init (SFF-8472) is the time required for a
|
|
|
|
* non-cooled module to initialise its laser safety circuitry. We wait
|
|
|
|
* an initial T_WAIT period before we check the tx fault to give any PHY
|
|
|
|
* on board (for a copper SFP) time to initialise.
|
|
|
|
*/
|
|
|
|
#define T_WAIT msecs_to_jiffies(50)
|
|
|
|
#define T_START_UP msecs_to_jiffies(300)
|
|
|
|
#define T_START_UP_BAD_GPON msecs_to_jiffies(60000)
|
|
|
|
|
|
|
|
/* t_reset is the time required to assert the TX_DISABLE signal to reset
|
|
|
|
* an indicated TX_FAULT.
|
|
|
|
*/
|
|
|
|
#define T_RESET_US 10
|
|
|
|
#define T_FAULT_RECOVER msecs_to_jiffies(1000)
|
2017-07-25 21:03:39 +07:00
|
|
|
|
2019-12-09 21:15:55 +07:00
|
|
|
/* N_FAULT_INIT is the number of recovery attempts at module initialisation
|
|
|
|
* time. If the TX_FAULT signal is not deasserted after this number of
|
|
|
|
* attempts at clearing it, we decide that the module is faulty.
|
|
|
|
* N_FAULT is the same but after the module has initialised.
|
|
|
|
*/
|
|
|
|
#define N_FAULT_INIT 5
|
|
|
|
#define N_FAULT 5
|
|
|
|
|
2019-12-09 21:16:11 +07:00
|
|
|
/* T_PHY_RETRY is the time interval between attempts to probe the PHY.
|
|
|
|
* R_PHY_RETRY is the number of attempts.
|
|
|
|
*/
|
|
|
|
#define T_PHY_RETRY msecs_to_jiffies(50)
|
|
|
|
#define R_PHY_RETRY 12
|
|
|
|
|
2017-07-25 21:03:39 +07:00
|
|
|
/* SFP module presence detection is poor: the three MOD DEF signals are
|
|
|
|
* the same length on the PCB, which means it's possible for MOD DEF 0 to
|
|
|
|
* connect before the I2C bus on MOD DEF 1/2.
|
|
|
|
*
|
2019-11-10 21:06:33 +07:00
|
|
|
* The SFF-8472 specifies t_serial ("Time from power on until module is
|
|
|
|
* ready for data transmission over the two wire serial bus.") as 300ms.
|
2017-07-25 21:03:39 +07:00
|
|
|
*/
|
2019-11-10 21:07:30 +07:00
|
|
|
#define T_SERIAL msecs_to_jiffies(300)
|
|
|
|
#define T_HPOWER_LEVEL msecs_to_jiffies(300)
|
|
|
|
#define T_PROBE_RETRY_INIT msecs_to_jiffies(100)
|
|
|
|
#define R_PROBE_RETRY_INIT 10
|
|
|
|
#define T_PROBE_RETRY_SLOW msecs_to_jiffies(5000)
|
|
|
|
#define R_PROBE_RETRY_SLOW 12
|
2017-07-25 21:03:39 +07:00
|
|
|
|
2017-10-31 11:42:57 +07:00
|
|
|
/* SFP modules appear to always have their PHY configured for bus address
|
2017-07-25 21:03:39 +07:00
|
|
|
* 0x56 (which with mdio-i2c, translates to a PHY address of 22).
|
|
|
|
*/
|
|
|
|
#define SFP_PHY_ADDR 22
|
|
|
|
|
2017-12-14 17:27:47 +07:00
|
|
|
struct sff_data {
|
|
|
|
unsigned int gpios;
|
|
|
|
bool (*module_supported)(const struct sfp_eeprom_id *id);
|
|
|
|
};
|
|
|
|
|
2017-07-25 21:03:39 +07:00
|
|
|
struct sfp {
|
|
|
|
struct device *dev;
|
|
|
|
struct i2c_adapter *i2c;
|
|
|
|
struct mii_bus *i2c_mii;
|
|
|
|
struct sfp_bus *sfp_bus;
|
|
|
|
struct phy_device *mod_phy;
|
2017-12-14 17:27:47 +07:00
|
|
|
const struct sff_data *type;
|
sfp: add high power module support
This patch is the result of work by both Jon Nettleton and Russell King.
Jon wrote the original patch, adding support for SFP modules which
require a power level greater than '1'.
Russell's changes:
- Fix the power levels for big-endian, and make the code flow better.
- Convert to use device_property_read_u8()
- Warn for power levels exceeding host level
SFF-8431 says:
"To avoid exceeding system power supply limits and cooling capacity,
all modules at power up by default shall operate with up to 1.0 W.
Hosts supporting Power Level II or III operation may enable a Power
Level II or III module through the 2-wire interface. Power Level II
or III modules shall assert the power level declaration bit of
SFF-8472."
Print a warning for modules that exceed the host power level, and
leave them operating in power level 1.
- Fix i2c write
The first byte of any write after the bus address is always the
device address. In order to write a value to device D, address I,
value V, we need to generate on the bus:
S DDDDDDDD A IIIIIIII A VVVVVVVV A P
where S = start, R = restart, A = ack, P = stop. Splitting this
as two:
S DDDDDDDD A IIIIIIII A R DDDDDDDD A VVVVVVVV A P
results in the device's address register being written first by I
and then by V - the addressed register within the device is not
written.
- Avoid power mode switching if 0xa2 is not implemented
Some modules indicate that they support power level II or power level
III, but do not implement address 0xa2, meaning that the bit to set
them to high power mode is not accessible.
These modules appear to have the sff8472_compliance field set to zero,
and also do not implement diagnostics. Detect this, but also ensure
that the module does not require the address switching mode, which we
do not implement.
- Use mW for power level rather than power level number.
- Fix high power mode transition
We must not switch to SFP_MOD_PRESENT state until we have finished
initialising, because the remaining state machines check for that
state. Add SFP_MOD_HPOWER as an intermediate state.
- Use definition for I2C register address rather than constant.
Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-02-27 22:53:12 +07:00
|
|
|
u32 max_power_mW;
|
2017-07-25 21:03:39 +07:00
|
|
|
|
|
|
|
unsigned int (*get_state)(struct sfp *);
|
|
|
|
void (*set_state)(struct sfp *, unsigned int);
|
|
|
|
int (*read)(struct sfp *, bool, u8, void *, size_t);
|
sfp: add high power module support
This patch is the result of work by both Jon Nettleton and Russell King.
Jon wrote the original patch, adding support for SFP modules which
require a power level greater than '1'.
Russell's changes:
- Fix the power levels for big-endian, and make the code flow better.
- Convert to use device_property_read_u8()
- Warn for power levels exceeding host level
SFF-8431 says:
"To avoid exceeding system power supply limits and cooling capacity,
all modules at power up by default shall operate with up to 1.0 W.
Hosts supporting Power Level II or III operation may enable a Power
Level II or III module through the 2-wire interface. Power Level II
or III modules shall assert the power level declaration bit of
SFF-8472."
Print a warning for modules that exceed the host power level, and
leave them operating in power level 1.
- Fix i2c write
The first byte of any write after the bus address is always the
device address. In order to write a value to device D, address I,
value V, we need to generate on the bus:
S DDDDDDDD A IIIIIIII A VVVVVVVV A P
where S = start, R = restart, A = ack, P = stop. Splitting this
as two:
S DDDDDDDD A IIIIIIII A R DDDDDDDD A VVVVVVVV A P
results in the device's address register being written first by I
and then by V - the addressed register within the device is not
written.
- Avoid power mode switching if 0xa2 is not implemented
Some modules indicate that they support power level II or power level
III, but do not implement address 0xa2, meaning that the bit to set
them to high power mode is not accessible.
These modules appear to have the sff8472_compliance field set to zero,
and also do not implement diagnostics. Detect this, but also ensure
that the module does not require the address switching mode, which we
do not implement.
- Use mW for power level rather than power level number.
- Fix high power mode transition
We must not switch to SFP_MOD_PRESENT state until we have finished
initialising, because the remaining state machines check for that
state. Add SFP_MOD_HPOWER as an intermediate state.
- Use definition for I2C register address rather than constant.
Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-02-27 22:53:12 +07:00
|
|
|
int (*write)(struct sfp *, bool, u8, void *, size_t);
|
2017-07-25 21:03:39 +07:00
|
|
|
|
|
|
|
struct gpio_desc *gpio[GPIO_MAX];
|
2019-06-07 23:42:35 +07:00
|
|
|
int gpio_irq[GPIO_MAX];
|
2017-07-25 21:03:39 +07:00
|
|
|
|
2019-11-20 19:29:59 +07:00
|
|
|
bool need_poll;
|
|
|
|
|
2019-06-07 23:42:36 +07:00
|
|
|
struct mutex st_mutex; /* Protects state */
|
2019-11-20 19:29:59 +07:00
|
|
|
unsigned int state_soft_mask;
|
2017-07-25 21:03:39 +07:00
|
|
|
unsigned int state;
|
|
|
|
struct delayed_work poll;
|
|
|
|
struct delayed_work timeout;
|
2019-06-07 23:42:36 +07:00
|
|
|
struct mutex sm_mutex; /* Protects state machine */
|
2017-07-25 21:03:39 +07:00
|
|
|
unsigned char sm_mod_state;
|
2019-11-10 21:07:30 +07:00
|
|
|
unsigned char sm_mod_tries_init;
|
|
|
|
unsigned char sm_mod_tries;
|
2017-07-25 21:03:39 +07:00
|
|
|
unsigned char sm_dev_state;
|
|
|
|
unsigned short sm_state;
|
2019-12-09 21:16:00 +07:00
|
|
|
unsigned char sm_fault_retries;
|
2019-12-09 21:16:11 +07:00
|
|
|
unsigned char sm_phy_retries;
|
2017-07-25 21:03:39 +07:00
|
|
|
|
|
|
|
struct sfp_eeprom_id id;
|
2019-11-10 21:06:39 +07:00
|
|
|
unsigned int module_power_mW;
|
2019-12-09 20:40:23 +07:00
|
|
|
unsigned int module_t_start_up;
|
2019-11-10 21:06:39 +07:00
|
|
|
|
net: phy: sfp: Add HWMON support for module sensors
SFP modules can contain a number of sensors. The EEPROM also contains
recommended alarm and critical values for each sensor, and indications
of if these have been exceeded. Export this information via
HWMON. Currently temperature, VCC, bias current, transmit power, and
possibly receiver power is supported.
The sensors in the modules can either return calibrate or uncalibrated
values. Uncalibrated values need to be manipulated, using coefficients
provided in the SFP EEPROM. Uncalibrated receive power values require
floating point maths in order to calibrate them. Performing this in
the kernel is hard. So if the SFP module indicates it uses
uncalibrated values, RX power is not made available.
With this hwmon device, it is possible to view the sensor values using
lm-sensors programs:
in0: +3.29 V (crit min = +2.90 V, min = +3.00 V)
(max = +3.60 V, crit max = +3.70 V)
temp1: +33.0°C (low = -5.0°C, high = +80.0°C)
(crit low = -10.0°C, crit = +85.0°C)
power1: 1000.00 nW (max = 794.00 uW, min = 50.00 uW) ALARM (LCRIT)
(lcrit = 40.00 uW, crit = 1000.00 uW)
curr1: +0.00 A (crit min = +0.00 A, min = +0.00 A) ALARM (LCRIT, MIN)
(max = +0.01 A, crit max = +0.01 A)
The scaling sensors performs on the bias current is not particularly
good. The raw values are more useful:
curr1:
curr1_input: 0.000
curr1_min: 0.002
curr1_max: 0.010
curr1_lcrit: 0.000
curr1_crit: 0.011
curr1_min_alarm: 1.000
curr1_max_alarm: 0.000
curr1_lcrit_alarm: 1.000
curr1_crit_alarm: 0.000
In order to keep the I2C overhead to a minimum, the constant values,
such as limits and calibration coefficients are read once at module
insertion time. Thus only reading *_input and *_alarm properties
requires i2c read operations.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-07-18 02:48:13 +07:00
|
|
|
#if IS_ENABLED(CONFIG_HWMON)
|
|
|
|
struct sfp_diag diag;
|
net: sfp: allow modules with slow diagnostics to probe
When a module is inserted, we attempt to read read the ID from address
0x50. Once we are able to read the ID, we immediately attempt to
initialise the hwmon support by reading from address 0x51. If this
fails, then we fall into error state, and assume that the module is
not usable.
Modules such as the ALCATELLUCENT 3FE46541AA use a real EEPROM for
I2C address 0x50, which responds immediately. However, address 0x51
is an emulated, which only becomes available once the on-board firmware
has booted. This prompts us to fall into the error state.
Since the module may be usable without diagnostics, arrange for the
hwmon probe independent of the rest of the SFP itself, retrying every
5s for up to about 60s for the monitoring to become available, and
print an error message if it doesn't become available.
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-11-10 21:07:35 +07:00
|
|
|
struct delayed_work hwmon_probe;
|
|
|
|
unsigned int hwmon_tries;
|
net: phy: sfp: Add HWMON support for module sensors
SFP modules can contain a number of sensors. The EEPROM also contains
recommended alarm and critical values for each sensor, and indications
of if these have been exceeded. Export this information via
HWMON. Currently temperature, VCC, bias current, transmit power, and
possibly receiver power is supported.
The sensors in the modules can either return calibrate or uncalibrated
values. Uncalibrated values need to be manipulated, using coefficients
provided in the SFP EEPROM. Uncalibrated receive power values require
floating point maths in order to calibrate them. Performing this in
the kernel is hard. So if the SFP module indicates it uses
uncalibrated values, RX power is not made available.
With this hwmon device, it is possible to view the sensor values using
lm-sensors programs:
in0: +3.29 V (crit min = +2.90 V, min = +3.00 V)
(max = +3.60 V, crit max = +3.70 V)
temp1: +33.0°C (low = -5.0°C, high = +80.0°C)
(crit low = -10.0°C, crit = +85.0°C)
power1: 1000.00 nW (max = 794.00 uW, min = 50.00 uW) ALARM (LCRIT)
(lcrit = 40.00 uW, crit = 1000.00 uW)
curr1: +0.00 A (crit min = +0.00 A, min = +0.00 A) ALARM (LCRIT, MIN)
(max = +0.01 A, crit max = +0.01 A)
The scaling sensors performs on the bias current is not particularly
good. The raw values are more useful:
curr1:
curr1_input: 0.000
curr1_min: 0.002
curr1_max: 0.010
curr1_lcrit: 0.000
curr1_crit: 0.011
curr1_min_alarm: 1.000
curr1_max_alarm: 0.000
curr1_lcrit_alarm: 1.000
curr1_crit_alarm: 0.000
In order to keep the I2C overhead to a minimum, the constant values,
such as limits and calibration coefficients are read once at module
insertion time. Thus only reading *_input and *_alarm properties
requires i2c read operations.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-07-18 02:48:13 +07:00
|
|
|
struct device *hwmon_dev;
|
|
|
|
char *hwmon_name;
|
|
|
|
#endif
|
|
|
|
|
2017-07-25 21:03:39 +07:00
|
|
|
};
|
|
|
|
|
2017-12-14 17:27:47 +07:00
|
|
|
static bool sff_module_supported(const struct sfp_eeprom_id *id)
|
|
|
|
{
|
2019-12-11 17:56:04 +07:00
|
|
|
return id->base.phys_id == SFF8024_ID_SFF_8472 &&
|
2017-12-14 17:27:47 +07:00
|
|
|
id->base.phys_ext_id == SFP_PHYS_EXT_ID_SFP;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct sff_data sff_data = {
|
|
|
|
.gpios = SFP_F_LOS | SFP_F_TX_FAULT | SFP_F_TX_DISABLE,
|
|
|
|
.module_supported = sff_module_supported,
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool sfp_module_supported(const struct sfp_eeprom_id *id)
|
|
|
|
{
|
2019-12-11 17:56:04 +07:00
|
|
|
return id->base.phys_id == SFF8024_ID_SFP &&
|
2017-12-14 17:27:47 +07:00
|
|
|
id->base.phys_ext_id == SFP_PHYS_EXT_ID_SFP;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct sff_data sfp_data = {
|
|
|
|
.gpios = SFP_F_PRESENT | SFP_F_LOS | SFP_F_TX_FAULT |
|
|
|
|
SFP_F_TX_DISABLE | SFP_F_RATE_SELECT,
|
|
|
|
.module_supported = sfp_module_supported,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct of_device_id sfp_of_match[] = {
|
|
|
|
{ .compatible = "sff,sff", .data = &sff_data, },
|
|
|
|
{ .compatible = "sff,sfp", .data = &sfp_data, },
|
|
|
|
{ },
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, sfp_of_match);
|
|
|
|
|
2017-07-25 21:03:39 +07:00
|
|
|
static unsigned long poll_jiffies;
|
|
|
|
|
|
|
|
static unsigned int sfp_gpio_get_state(struct sfp *sfp)
|
|
|
|
{
|
|
|
|
unsigned int i, state, v;
|
|
|
|
|
|
|
|
for (i = state = 0; i < GPIO_MAX; i++) {
|
|
|
|
if (gpio_flags[i] != GPIOD_IN || !sfp->gpio[i])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
v = gpiod_get_value_cansleep(sfp->gpio[i]);
|
|
|
|
if (v)
|
|
|
|
state |= BIT(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2017-12-14 17:27:47 +07:00
|
|
|
static unsigned int sff_gpio_get_state(struct sfp *sfp)
|
|
|
|
{
|
|
|
|
return sfp_gpio_get_state(sfp) | SFP_F_PRESENT;
|
|
|
|
}
|
|
|
|
|
2017-07-25 21:03:39 +07:00
|
|
|
static void sfp_gpio_set_state(struct sfp *sfp, unsigned int state)
|
|
|
|
{
|
|
|
|
if (state & SFP_F_PRESENT) {
|
|
|
|
/* If the module is present, drive the signals */
|
|
|
|
if (sfp->gpio[GPIO_TX_DISABLE])
|
|
|
|
gpiod_direction_output(sfp->gpio[GPIO_TX_DISABLE],
|
2017-10-31 11:42:57 +07:00
|
|
|
state & SFP_F_TX_DISABLE);
|
2017-07-25 21:03:39 +07:00
|
|
|
if (state & SFP_F_RATE_SELECT)
|
|
|
|
gpiod_direction_output(sfp->gpio[GPIO_RATE_SELECT],
|
2017-10-31 11:42:57 +07:00
|
|
|
state & SFP_F_RATE_SELECT);
|
2017-07-25 21:03:39 +07:00
|
|
|
} else {
|
|
|
|
/* Otherwise, let them float to the pull-ups */
|
|
|
|
if (sfp->gpio[GPIO_TX_DISABLE])
|
|
|
|
gpiod_direction_input(sfp->gpio[GPIO_TX_DISABLE]);
|
|
|
|
if (state & SFP_F_RATE_SELECT)
|
|
|
|
gpiod_direction_input(sfp->gpio[GPIO_RATE_SELECT]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
sfp: add high power module support
This patch is the result of work by both Jon Nettleton and Russell King.
Jon wrote the original patch, adding support for SFP modules which
require a power level greater than '1'.
Russell's changes:
- Fix the power levels for big-endian, and make the code flow better.
- Convert to use device_property_read_u8()
- Warn for power levels exceeding host level
SFF-8431 says:
"To avoid exceeding system power supply limits and cooling capacity,
all modules at power up by default shall operate with up to 1.0 W.
Hosts supporting Power Level II or III operation may enable a Power
Level II or III module through the 2-wire interface. Power Level II
or III modules shall assert the power level declaration bit of
SFF-8472."
Print a warning for modules that exceed the host power level, and
leave them operating in power level 1.
- Fix i2c write
The first byte of any write after the bus address is always the
device address. In order to write a value to device D, address I,
value V, we need to generate on the bus:
S DDDDDDDD A IIIIIIII A VVVVVVVV A P
where S = start, R = restart, A = ack, P = stop. Splitting this
as two:
S DDDDDDDD A IIIIIIII A R DDDDDDDD A VVVVVVVV A P
results in the device's address register being written first by I
and then by V - the addressed register within the device is not
written.
- Avoid power mode switching if 0xa2 is not implemented
Some modules indicate that they support power level II or power level
III, but do not implement address 0xa2, meaning that the bit to set
them to high power mode is not accessible.
These modules appear to have the sff8472_compliance field set to zero,
and also do not implement diagnostics. Detect this, but also ensure
that the module does not require the address switching mode, which we
do not implement.
- Use mW for power level rather than power level number.
- Fix high power mode transition
We must not switch to SFP_MOD_PRESENT state until we have finished
initialising, because the remaining state machines check for that
state. Add SFP_MOD_HPOWER as an intermediate state.
- Use definition for I2C register address rather than constant.
Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-02-27 22:53:12 +07:00
|
|
|
static int sfp_i2c_read(struct sfp *sfp, bool a2, u8 dev_addr, void *buf,
|
|
|
|
size_t len)
|
2017-07-25 21:03:39 +07:00
|
|
|
{
|
|
|
|
struct i2c_msg msgs[2];
|
sfp: add high power module support
This patch is the result of work by both Jon Nettleton and Russell King.
Jon wrote the original patch, adding support for SFP modules which
require a power level greater than '1'.
Russell's changes:
- Fix the power levels for big-endian, and make the code flow better.
- Convert to use device_property_read_u8()
- Warn for power levels exceeding host level
SFF-8431 says:
"To avoid exceeding system power supply limits and cooling capacity,
all modules at power up by default shall operate with up to 1.0 W.
Hosts supporting Power Level II or III operation may enable a Power
Level II or III module through the 2-wire interface. Power Level II
or III modules shall assert the power level declaration bit of
SFF-8472."
Print a warning for modules that exceed the host power level, and
leave them operating in power level 1.
- Fix i2c write
The first byte of any write after the bus address is always the
device address. In order to write a value to device D, address I,
value V, we need to generate on the bus:
S DDDDDDDD A IIIIIIII A VVVVVVVV A P
where S = start, R = restart, A = ack, P = stop. Splitting this
as two:
S DDDDDDDD A IIIIIIII A R DDDDDDDD A VVVVVVVV A P
results in the device's address register being written first by I
and then by V - the addressed register within the device is not
written.
- Avoid power mode switching if 0xa2 is not implemented
Some modules indicate that they support power level II or power level
III, but do not implement address 0xa2, meaning that the bit to set
them to high power mode is not accessible.
These modules appear to have the sff8472_compliance field set to zero,
and also do not implement diagnostics. Detect this, but also ensure
that the module does not require the address switching mode, which we
do not implement.
- Use mW for power level rather than power level number.
- Fix high power mode transition
We must not switch to SFP_MOD_PRESENT state until we have finished
initialising, because the remaining state machines check for that
state. Add SFP_MOD_HPOWER as an intermediate state.
- Use definition for I2C register address rather than constant.
Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-02-27 22:53:12 +07:00
|
|
|
u8 bus_addr = a2 ? 0x51 : 0x50;
|
2019-06-02 21:13:00 +07:00
|
|
|
size_t this_len;
|
2017-07-25 21:03:39 +07:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
msgs[0].addr = bus_addr;
|
|
|
|
msgs[0].flags = 0;
|
|
|
|
msgs[0].len = 1;
|
|
|
|
msgs[0].buf = &dev_addr;
|
|
|
|
msgs[1].addr = bus_addr;
|
|
|
|
msgs[1].flags = I2C_M_RD;
|
|
|
|
msgs[1].len = len;
|
|
|
|
msgs[1].buf = buf;
|
|
|
|
|
2019-06-02 21:13:00 +07:00
|
|
|
while (len) {
|
|
|
|
this_len = len;
|
|
|
|
if (this_len > 16)
|
|
|
|
this_len = 16;
|
2017-07-25 21:03:39 +07:00
|
|
|
|
2019-06-02 21:13:00 +07:00
|
|
|
msgs[1].len = this_len;
|
|
|
|
|
|
|
|
ret = i2c_transfer(sfp->i2c, msgs, ARRAY_SIZE(msgs));
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (ret != ARRAY_SIZE(msgs))
|
|
|
|
break;
|
|
|
|
|
|
|
|
msgs[1].buf += this_len;
|
|
|
|
dev_addr += this_len;
|
|
|
|
len -= this_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
return msgs[1].buf - (u8 *)buf;
|
2017-07-25 21:03:39 +07:00
|
|
|
}
|
|
|
|
|
sfp: add high power module support
This patch is the result of work by both Jon Nettleton and Russell King.
Jon wrote the original patch, adding support for SFP modules which
require a power level greater than '1'.
Russell's changes:
- Fix the power levels for big-endian, and make the code flow better.
- Convert to use device_property_read_u8()
- Warn for power levels exceeding host level
SFF-8431 says:
"To avoid exceeding system power supply limits and cooling capacity,
all modules at power up by default shall operate with up to 1.0 W.
Hosts supporting Power Level II or III operation may enable a Power
Level II or III module through the 2-wire interface. Power Level II
or III modules shall assert the power level declaration bit of
SFF-8472."
Print a warning for modules that exceed the host power level, and
leave them operating in power level 1.
- Fix i2c write
The first byte of any write after the bus address is always the
device address. In order to write a value to device D, address I,
value V, we need to generate on the bus:
S DDDDDDDD A IIIIIIII A VVVVVVVV A P
where S = start, R = restart, A = ack, P = stop. Splitting this
as two:
S DDDDDDDD A IIIIIIII A R DDDDDDDD A VVVVVVVV A P
results in the device's address register being written first by I
and then by V - the addressed register within the device is not
written.
- Avoid power mode switching if 0xa2 is not implemented
Some modules indicate that they support power level II or power level
III, but do not implement address 0xa2, meaning that the bit to set
them to high power mode is not accessible.
These modules appear to have the sff8472_compliance field set to zero,
and also do not implement diagnostics. Detect this, but also ensure
that the module does not require the address switching mode, which we
do not implement.
- Use mW for power level rather than power level number.
- Fix high power mode transition
We must not switch to SFP_MOD_PRESENT state until we have finished
initialising, because the remaining state machines check for that
state. Add SFP_MOD_HPOWER as an intermediate state.
- Use definition for I2C register address rather than constant.
Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-02-27 22:53:12 +07:00
|
|
|
static int sfp_i2c_write(struct sfp *sfp, bool a2, u8 dev_addr, void *buf,
|
|
|
|
size_t len)
|
2017-07-25 21:03:39 +07:00
|
|
|
{
|
sfp: add high power module support
This patch is the result of work by both Jon Nettleton and Russell King.
Jon wrote the original patch, adding support for SFP modules which
require a power level greater than '1'.
Russell's changes:
- Fix the power levels for big-endian, and make the code flow better.
- Convert to use device_property_read_u8()
- Warn for power levels exceeding host level
SFF-8431 says:
"To avoid exceeding system power supply limits and cooling capacity,
all modules at power up by default shall operate with up to 1.0 W.
Hosts supporting Power Level II or III operation may enable a Power
Level II or III module through the 2-wire interface. Power Level II
or III modules shall assert the power level declaration bit of
SFF-8472."
Print a warning for modules that exceed the host power level, and
leave them operating in power level 1.
- Fix i2c write
The first byte of any write after the bus address is always the
device address. In order to write a value to device D, address I,
value V, we need to generate on the bus:
S DDDDDDDD A IIIIIIII A VVVVVVVV A P
where S = start, R = restart, A = ack, P = stop. Splitting this
as two:
S DDDDDDDD A IIIIIIII A R DDDDDDDD A VVVVVVVV A P
results in the device's address register being written first by I
and then by V - the addressed register within the device is not
written.
- Avoid power mode switching if 0xa2 is not implemented
Some modules indicate that they support power level II or power level
III, but do not implement address 0xa2, meaning that the bit to set
them to high power mode is not accessible.
These modules appear to have the sff8472_compliance field set to zero,
and also do not implement diagnostics. Detect this, but also ensure
that the module does not require the address switching mode, which we
do not implement.
- Use mW for power level rather than power level number.
- Fix high power mode transition
We must not switch to SFP_MOD_PRESENT state until we have finished
initialising, because the remaining state machines check for that
state. Add SFP_MOD_HPOWER as an intermediate state.
- Use definition for I2C register address rather than constant.
Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-02-27 22:53:12 +07:00
|
|
|
struct i2c_msg msgs[1];
|
|
|
|
u8 bus_addr = a2 ? 0x51 : 0x50;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
msgs[0].addr = bus_addr;
|
|
|
|
msgs[0].flags = 0;
|
|
|
|
msgs[0].len = 1 + len;
|
|
|
|
msgs[0].buf = kmalloc(1 + len, GFP_KERNEL);
|
|
|
|
if (!msgs[0].buf)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
msgs[0].buf[0] = dev_addr;
|
|
|
|
memcpy(&msgs[0].buf[1], buf, len);
|
|
|
|
|
|
|
|
ret = i2c_transfer(sfp->i2c, msgs, ARRAY_SIZE(msgs));
|
|
|
|
|
|
|
|
kfree(msgs[0].buf);
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return ret == ARRAY_SIZE(msgs) ? len : 0;
|
2017-07-25 21:03:39 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int sfp_i2c_configure(struct sfp *sfp, struct i2c_adapter *i2c)
|
|
|
|
{
|
|
|
|
struct mii_bus *i2c_mii;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!i2c_check_functionality(i2c, I2C_FUNC_I2C))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
sfp->i2c = i2c;
|
|
|
|
sfp->read = sfp_i2c_read;
|
sfp: add high power module support
This patch is the result of work by both Jon Nettleton and Russell King.
Jon wrote the original patch, adding support for SFP modules which
require a power level greater than '1'.
Russell's changes:
- Fix the power levels for big-endian, and make the code flow better.
- Convert to use device_property_read_u8()
- Warn for power levels exceeding host level
SFF-8431 says:
"To avoid exceeding system power supply limits and cooling capacity,
all modules at power up by default shall operate with up to 1.0 W.
Hosts supporting Power Level II or III operation may enable a Power
Level II or III module through the 2-wire interface. Power Level II
or III modules shall assert the power level declaration bit of
SFF-8472."
Print a warning for modules that exceed the host power level, and
leave them operating in power level 1.
- Fix i2c write
The first byte of any write after the bus address is always the
device address. In order to write a value to device D, address I,
value V, we need to generate on the bus:
S DDDDDDDD A IIIIIIII A VVVVVVVV A P
where S = start, R = restart, A = ack, P = stop. Splitting this
as two:
S DDDDDDDD A IIIIIIII A R DDDDDDDD A VVVVVVVV A P
results in the device's address register being written first by I
and then by V - the addressed register within the device is not
written.
- Avoid power mode switching if 0xa2 is not implemented
Some modules indicate that they support power level II or power level
III, but do not implement address 0xa2, meaning that the bit to set
them to high power mode is not accessible.
These modules appear to have the sff8472_compliance field set to zero,
and also do not implement diagnostics. Detect this, but also ensure
that the module does not require the address switching mode, which we
do not implement.
- Use mW for power level rather than power level number.
- Fix high power mode transition
We must not switch to SFP_MOD_PRESENT state until we have finished
initialising, because the remaining state machines check for that
state. Add SFP_MOD_HPOWER as an intermediate state.
- Use definition for I2C register address rather than constant.
Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-02-27 22:53:12 +07:00
|
|
|
sfp->write = sfp_i2c_write;
|
2017-07-25 21:03:39 +07:00
|
|
|
|
|
|
|
i2c_mii = mdio_i2c_alloc(sfp->dev, i2c);
|
|
|
|
if (IS_ERR(i2c_mii))
|
|
|
|
return PTR_ERR(i2c_mii);
|
|
|
|
|
|
|
|
i2c_mii->name = "SFP I2C Bus";
|
|
|
|
i2c_mii->phy_mask = ~0;
|
|
|
|
|
|
|
|
ret = mdiobus_register(i2c_mii);
|
|
|
|
if (ret < 0) {
|
|
|
|
mdiobus_free(i2c_mii);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
sfp->i2c_mii = i2c_mii;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Interface */
|
2019-11-20 19:29:59 +07:00
|
|
|
static int sfp_read(struct sfp *sfp, bool a2, u8 addr, void *buf, size_t len)
|
2017-07-25 21:03:39 +07:00
|
|
|
{
|
2019-11-20 19:29:59 +07:00
|
|
|
return sfp->read(sfp, a2, addr, buf, len);
|
2017-07-25 21:03:39 +07:00
|
|
|
}
|
|
|
|
|
2019-11-20 19:29:59 +07:00
|
|
|
static int sfp_write(struct sfp *sfp, bool a2, u8 addr, void *buf, size_t len)
|
2017-07-25 21:03:39 +07:00
|
|
|
{
|
2019-11-20 19:29:59 +07:00
|
|
|
return sfp->write(sfp, a2, addr, buf, len);
|
2017-07-25 21:03:39 +07:00
|
|
|
}
|
|
|
|
|
2019-11-20 19:29:59 +07:00
|
|
|
static unsigned int sfp_soft_get_state(struct sfp *sfp)
|
2017-07-25 21:03:39 +07:00
|
|
|
{
|
2019-11-20 19:29:59 +07:00
|
|
|
unsigned int state = 0;
|
|
|
|
u8 status;
|
2019-12-17 20:50:29 +07:00
|
|
|
int ret;
|
2019-11-20 19:29:59 +07:00
|
|
|
|
2019-12-17 20:50:29 +07:00
|
|
|
ret = sfp_read(sfp, true, SFP_STATUS, &status, sizeof(status));
|
|
|
|
if (ret == sizeof(status)) {
|
2019-11-20 19:29:59 +07:00
|
|
|
if (status & SFP_STATUS_RX_LOS)
|
|
|
|
state |= SFP_F_LOS;
|
|
|
|
if (status & SFP_STATUS_TX_FAULT)
|
|
|
|
state |= SFP_F_TX_FAULT;
|
2019-12-17 20:50:29 +07:00
|
|
|
} else {
|
|
|
|
dev_err_ratelimited(sfp->dev,
|
|
|
|
"failed to read SFP soft status: %d\n",
|
|
|
|
ret);
|
|
|
|
/* Preserve the current state */
|
|
|
|
state = sfp->state;
|
2019-11-20 19:29:59 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
return state & sfp->state_soft_mask;
|
2017-07-25 21:03:39 +07:00
|
|
|
}
|
|
|
|
|
2019-11-20 19:29:59 +07:00
|
|
|
static void sfp_soft_set_state(struct sfp *sfp, unsigned int state)
|
sfp: add high power module support
This patch is the result of work by both Jon Nettleton and Russell King.
Jon wrote the original patch, adding support for SFP modules which
require a power level greater than '1'.
Russell's changes:
- Fix the power levels for big-endian, and make the code flow better.
- Convert to use device_property_read_u8()
- Warn for power levels exceeding host level
SFF-8431 says:
"To avoid exceeding system power supply limits and cooling capacity,
all modules at power up by default shall operate with up to 1.0 W.
Hosts supporting Power Level II or III operation may enable a Power
Level II or III module through the 2-wire interface. Power Level II
or III modules shall assert the power level declaration bit of
SFF-8472."
Print a warning for modules that exceed the host power level, and
leave them operating in power level 1.
- Fix i2c write
The first byte of any write after the bus address is always the
device address. In order to write a value to device D, address I,
value V, we need to generate on the bus:
S DDDDDDDD A IIIIIIII A VVVVVVVV A P
where S = start, R = restart, A = ack, P = stop. Splitting this
as two:
S DDDDDDDD A IIIIIIII A R DDDDDDDD A VVVVVVVV A P
results in the device's address register being written first by I
and then by V - the addressed register within the device is not
written.
- Avoid power mode switching if 0xa2 is not implemented
Some modules indicate that they support power level II or power level
III, but do not implement address 0xa2, meaning that the bit to set
them to high power mode is not accessible.
These modules appear to have the sff8472_compliance field set to zero,
and also do not implement diagnostics. Detect this, but also ensure
that the module does not require the address switching mode, which we
do not implement.
- Use mW for power level rather than power level number.
- Fix high power mode transition
We must not switch to SFP_MOD_PRESENT state until we have finished
initialising, because the remaining state machines check for that
state. Add SFP_MOD_HPOWER as an intermediate state.
- Use definition for I2C register address rather than constant.
Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-02-27 22:53:12 +07:00
|
|
|
{
|
2019-11-20 19:29:59 +07:00
|
|
|
u8 status;
|
|
|
|
|
|
|
|
if (sfp_read(sfp, true, SFP_STATUS, &status, sizeof(status)) ==
|
|
|
|
sizeof(status)) {
|
|
|
|
if (state & SFP_F_TX_DISABLE)
|
|
|
|
status |= SFP_STATUS_TX_DISABLE_FORCE;
|
|
|
|
else
|
|
|
|
status &= ~SFP_STATUS_TX_DISABLE_FORCE;
|
|
|
|
|
|
|
|
sfp_write(sfp, true, SFP_STATUS, &status, sizeof(status));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sfp_soft_start_poll(struct sfp *sfp)
|
|
|
|
{
|
|
|
|
const struct sfp_eeprom_id *id = &sfp->id;
|
|
|
|
|
|
|
|
sfp->state_soft_mask = 0;
|
|
|
|
if (id->ext.enhopts & SFP_ENHOPTS_SOFT_TX_DISABLE &&
|
|
|
|
!sfp->gpio[GPIO_TX_DISABLE])
|
|
|
|
sfp->state_soft_mask |= SFP_F_TX_DISABLE;
|
|
|
|
if (id->ext.enhopts & SFP_ENHOPTS_SOFT_TX_FAULT &&
|
|
|
|
!sfp->gpio[GPIO_TX_FAULT])
|
|
|
|
sfp->state_soft_mask |= SFP_F_TX_FAULT;
|
|
|
|
if (id->ext.enhopts & SFP_ENHOPTS_SOFT_RX_LOS &&
|
|
|
|
!sfp->gpio[GPIO_LOS])
|
|
|
|
sfp->state_soft_mask |= SFP_F_LOS;
|
|
|
|
|
|
|
|
if (sfp->state_soft_mask & (SFP_F_LOS | SFP_F_TX_FAULT) &&
|
|
|
|
!sfp->need_poll)
|
|
|
|
mod_delayed_work(system_wq, &sfp->poll, poll_jiffies);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sfp_soft_stop_poll(struct sfp *sfp)
|
|
|
|
{
|
|
|
|
sfp->state_soft_mask = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int sfp_get_state(struct sfp *sfp)
|
|
|
|
{
|
|
|
|
unsigned int state = sfp->get_state(sfp);
|
|
|
|
|
|
|
|
if (state & SFP_F_PRESENT &&
|
|
|
|
sfp->state_soft_mask & (SFP_F_LOS | SFP_F_TX_FAULT))
|
|
|
|
state |= sfp_soft_get_state(sfp);
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sfp_set_state(struct sfp *sfp, unsigned int state)
|
|
|
|
{
|
|
|
|
sfp->set_state(sfp, state);
|
|
|
|
|
|
|
|
if (state & SFP_F_PRESENT &&
|
|
|
|
sfp->state_soft_mask & SFP_F_TX_DISABLE)
|
|
|
|
sfp_soft_set_state(sfp, state);
|
sfp: add high power module support
This patch is the result of work by both Jon Nettleton and Russell King.
Jon wrote the original patch, adding support for SFP modules which
require a power level greater than '1'.
Russell's changes:
- Fix the power levels for big-endian, and make the code flow better.
- Convert to use device_property_read_u8()
- Warn for power levels exceeding host level
SFF-8431 says:
"To avoid exceeding system power supply limits and cooling capacity,
all modules at power up by default shall operate with up to 1.0 W.
Hosts supporting Power Level II or III operation may enable a Power
Level II or III module through the 2-wire interface. Power Level II
or III modules shall assert the power level declaration bit of
SFF-8472."
Print a warning for modules that exceed the host power level, and
leave them operating in power level 1.
- Fix i2c write
The first byte of any write after the bus address is always the
device address. In order to write a value to device D, address I,
value V, we need to generate on the bus:
S DDDDDDDD A IIIIIIII A VVVVVVVV A P
where S = start, R = restart, A = ack, P = stop. Splitting this
as two:
S DDDDDDDD A IIIIIIII A R DDDDDDDD A VVVVVVVV A P
results in the device's address register being written first by I
and then by V - the addressed register within the device is not
written.
- Avoid power mode switching if 0xa2 is not implemented
Some modules indicate that they support power level II or power level
III, but do not implement address 0xa2, meaning that the bit to set
them to high power mode is not accessible.
These modules appear to have the sff8472_compliance field set to zero,
and also do not implement diagnostics. Detect this, but also ensure
that the module does not require the address switching mode, which we
do not implement.
- Use mW for power level rather than power level number.
- Fix high power mode transition
We must not switch to SFP_MOD_PRESENT state until we have finished
initialising, because the remaining state machines check for that
state. Add SFP_MOD_HPOWER as an intermediate state.
- Use definition for I2C register address rather than constant.
Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-02-27 22:53:12 +07:00
|
|
|
}
|
|
|
|
|
2017-07-25 21:03:39 +07:00
|
|
|
static unsigned int sfp_check(void *buf, size_t len)
|
|
|
|
{
|
|
|
|
u8 *p, check;
|
|
|
|
|
|
|
|
for (p = buf, check = 0; len; p++, len--)
|
|
|
|
check += *p;
|
|
|
|
|
|
|
|
return check;
|
|
|
|
}
|
|
|
|
|
net: phy: sfp: Add HWMON support for module sensors
SFP modules can contain a number of sensors. The EEPROM also contains
recommended alarm and critical values for each sensor, and indications
of if these have been exceeded. Export this information via
HWMON. Currently temperature, VCC, bias current, transmit power, and
possibly receiver power is supported.
The sensors in the modules can either return calibrate or uncalibrated
values. Uncalibrated values need to be manipulated, using coefficients
provided in the SFP EEPROM. Uncalibrated receive power values require
floating point maths in order to calibrate them. Performing this in
the kernel is hard. So if the SFP module indicates it uses
uncalibrated values, RX power is not made available.
With this hwmon device, it is possible to view the sensor values using
lm-sensors programs:
in0: +3.29 V (crit min = +2.90 V, min = +3.00 V)
(max = +3.60 V, crit max = +3.70 V)
temp1: +33.0°C (low = -5.0°C, high = +80.0°C)
(crit low = -10.0°C, crit = +85.0°C)
power1: 1000.00 nW (max = 794.00 uW, min = 50.00 uW) ALARM (LCRIT)
(lcrit = 40.00 uW, crit = 1000.00 uW)
curr1: +0.00 A (crit min = +0.00 A, min = +0.00 A) ALARM (LCRIT, MIN)
(max = +0.01 A, crit max = +0.01 A)
The scaling sensors performs on the bias current is not particularly
good. The raw values are more useful:
curr1:
curr1_input: 0.000
curr1_min: 0.002
curr1_max: 0.010
curr1_lcrit: 0.000
curr1_crit: 0.011
curr1_min_alarm: 1.000
curr1_max_alarm: 0.000
curr1_lcrit_alarm: 1.000
curr1_crit_alarm: 0.000
In order to keep the I2C overhead to a minimum, the constant values,
such as limits and calibration coefficients are read once at module
insertion time. Thus only reading *_input and *_alarm properties
requires i2c read operations.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-07-18 02:48:13 +07:00
|
|
|
/* hwmon */
|
|
|
|
#if IS_ENABLED(CONFIG_HWMON)
|
|
|
|
static umode_t sfp_hwmon_is_visible(const void *data,
|
|
|
|
enum hwmon_sensor_types type,
|
|
|
|
u32 attr, int channel)
|
|
|
|
{
|
|
|
|
const struct sfp *sfp = data;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case hwmon_temp:
|
|
|
|
switch (attr) {
|
|
|
|
case hwmon_temp_min_alarm:
|
|
|
|
case hwmon_temp_max_alarm:
|
|
|
|
case hwmon_temp_lcrit_alarm:
|
|
|
|
case hwmon_temp_crit_alarm:
|
|
|
|
case hwmon_temp_min:
|
|
|
|
case hwmon_temp_max:
|
|
|
|
case hwmon_temp_lcrit:
|
|
|
|
case hwmon_temp_crit:
|
2018-09-04 09:23:56 +07:00
|
|
|
if (!(sfp->id.ext.enhopts & SFP_ENHOPTS_ALARMWARN))
|
|
|
|
return 0;
|
|
|
|
/* fall through */
|
|
|
|
case hwmon_temp_input:
|
2019-08-25 06:04:17 +07:00
|
|
|
case hwmon_temp_label:
|
net: phy: sfp: Add HWMON support for module sensors
SFP modules can contain a number of sensors. The EEPROM also contains
recommended alarm and critical values for each sensor, and indications
of if these have been exceeded. Export this information via
HWMON. Currently temperature, VCC, bias current, transmit power, and
possibly receiver power is supported.
The sensors in the modules can either return calibrate or uncalibrated
values. Uncalibrated values need to be manipulated, using coefficients
provided in the SFP EEPROM. Uncalibrated receive power values require
floating point maths in order to calibrate them. Performing this in
the kernel is hard. So if the SFP module indicates it uses
uncalibrated values, RX power is not made available.
With this hwmon device, it is possible to view the sensor values using
lm-sensors programs:
in0: +3.29 V (crit min = +2.90 V, min = +3.00 V)
(max = +3.60 V, crit max = +3.70 V)
temp1: +33.0°C (low = -5.0°C, high = +80.0°C)
(crit low = -10.0°C, crit = +85.0°C)
power1: 1000.00 nW (max = 794.00 uW, min = 50.00 uW) ALARM (LCRIT)
(lcrit = 40.00 uW, crit = 1000.00 uW)
curr1: +0.00 A (crit min = +0.00 A, min = +0.00 A) ALARM (LCRIT, MIN)
(max = +0.01 A, crit max = +0.01 A)
The scaling sensors performs on the bias current is not particularly
good. The raw values are more useful:
curr1:
curr1_input: 0.000
curr1_min: 0.002
curr1_max: 0.010
curr1_lcrit: 0.000
curr1_crit: 0.011
curr1_min_alarm: 1.000
curr1_max_alarm: 0.000
curr1_lcrit_alarm: 1.000
curr1_crit_alarm: 0.000
In order to keep the I2C overhead to a minimum, the constant values,
such as limits and calibration coefficients are read once at module
insertion time. Thus only reading *_input and *_alarm properties
requires i2c read operations.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-07-18 02:48:13 +07:00
|
|
|
return 0444;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case hwmon_in:
|
|
|
|
switch (attr) {
|
|
|
|
case hwmon_in_min_alarm:
|
|
|
|
case hwmon_in_max_alarm:
|
|
|
|
case hwmon_in_lcrit_alarm:
|
|
|
|
case hwmon_in_crit_alarm:
|
|
|
|
case hwmon_in_min:
|
|
|
|
case hwmon_in_max:
|
|
|
|
case hwmon_in_lcrit:
|
|
|
|
case hwmon_in_crit:
|
2018-09-04 09:23:56 +07:00
|
|
|
if (!(sfp->id.ext.enhopts & SFP_ENHOPTS_ALARMWARN))
|
|
|
|
return 0;
|
|
|
|
/* fall through */
|
|
|
|
case hwmon_in_input:
|
2019-08-25 06:04:17 +07:00
|
|
|
case hwmon_in_label:
|
net: phy: sfp: Add HWMON support for module sensors
SFP modules can contain a number of sensors. The EEPROM also contains
recommended alarm and critical values for each sensor, and indications
of if these have been exceeded. Export this information via
HWMON. Currently temperature, VCC, bias current, transmit power, and
possibly receiver power is supported.
The sensors in the modules can either return calibrate or uncalibrated
values. Uncalibrated values need to be manipulated, using coefficients
provided in the SFP EEPROM. Uncalibrated receive power values require
floating point maths in order to calibrate them. Performing this in
the kernel is hard. So if the SFP module indicates it uses
uncalibrated values, RX power is not made available.
With this hwmon device, it is possible to view the sensor values using
lm-sensors programs:
in0: +3.29 V (crit min = +2.90 V, min = +3.00 V)
(max = +3.60 V, crit max = +3.70 V)
temp1: +33.0°C (low = -5.0°C, high = +80.0°C)
(crit low = -10.0°C, crit = +85.0°C)
power1: 1000.00 nW (max = 794.00 uW, min = 50.00 uW) ALARM (LCRIT)
(lcrit = 40.00 uW, crit = 1000.00 uW)
curr1: +0.00 A (crit min = +0.00 A, min = +0.00 A) ALARM (LCRIT, MIN)
(max = +0.01 A, crit max = +0.01 A)
The scaling sensors performs on the bias current is not particularly
good. The raw values are more useful:
curr1:
curr1_input: 0.000
curr1_min: 0.002
curr1_max: 0.010
curr1_lcrit: 0.000
curr1_crit: 0.011
curr1_min_alarm: 1.000
curr1_max_alarm: 0.000
curr1_lcrit_alarm: 1.000
curr1_crit_alarm: 0.000
In order to keep the I2C overhead to a minimum, the constant values,
such as limits and calibration coefficients are read once at module
insertion time. Thus only reading *_input and *_alarm properties
requires i2c read operations.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-07-18 02:48:13 +07:00
|
|
|
return 0444;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case hwmon_curr:
|
|
|
|
switch (attr) {
|
|
|
|
case hwmon_curr_min_alarm:
|
|
|
|
case hwmon_curr_max_alarm:
|
|
|
|
case hwmon_curr_lcrit_alarm:
|
|
|
|
case hwmon_curr_crit_alarm:
|
|
|
|
case hwmon_curr_min:
|
|
|
|
case hwmon_curr_max:
|
|
|
|
case hwmon_curr_lcrit:
|
|
|
|
case hwmon_curr_crit:
|
2018-09-04 09:23:56 +07:00
|
|
|
if (!(sfp->id.ext.enhopts & SFP_ENHOPTS_ALARMWARN))
|
|
|
|
return 0;
|
|
|
|
/* fall through */
|
|
|
|
case hwmon_curr_input:
|
2019-08-25 06:04:17 +07:00
|
|
|
case hwmon_curr_label:
|
net: phy: sfp: Add HWMON support for module sensors
SFP modules can contain a number of sensors. The EEPROM also contains
recommended alarm and critical values for each sensor, and indications
of if these have been exceeded. Export this information via
HWMON. Currently temperature, VCC, bias current, transmit power, and
possibly receiver power is supported.
The sensors in the modules can either return calibrate or uncalibrated
values. Uncalibrated values need to be manipulated, using coefficients
provided in the SFP EEPROM. Uncalibrated receive power values require
floating point maths in order to calibrate them. Performing this in
the kernel is hard. So if the SFP module indicates it uses
uncalibrated values, RX power is not made available.
With this hwmon device, it is possible to view the sensor values using
lm-sensors programs:
in0: +3.29 V (crit min = +2.90 V, min = +3.00 V)
(max = +3.60 V, crit max = +3.70 V)
temp1: +33.0°C (low = -5.0°C, high = +80.0°C)
(crit low = -10.0°C, crit = +85.0°C)
power1: 1000.00 nW (max = 794.00 uW, min = 50.00 uW) ALARM (LCRIT)
(lcrit = 40.00 uW, crit = 1000.00 uW)
curr1: +0.00 A (crit min = +0.00 A, min = +0.00 A) ALARM (LCRIT, MIN)
(max = +0.01 A, crit max = +0.01 A)
The scaling sensors performs on the bias current is not particularly
good. The raw values are more useful:
curr1:
curr1_input: 0.000
curr1_min: 0.002
curr1_max: 0.010
curr1_lcrit: 0.000
curr1_crit: 0.011
curr1_min_alarm: 1.000
curr1_max_alarm: 0.000
curr1_lcrit_alarm: 1.000
curr1_crit_alarm: 0.000
In order to keep the I2C overhead to a minimum, the constant values,
such as limits and calibration coefficients are read once at module
insertion time. Thus only reading *_input and *_alarm properties
requires i2c read operations.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-07-18 02:48:13 +07:00
|
|
|
return 0444;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case hwmon_power:
|
|
|
|
/* External calibration of receive power requires
|
|
|
|
* floating point arithmetic. Doing that in the kernel
|
|
|
|
* is not easy, so just skip it. If the module does
|
|
|
|
* not require external calibration, we can however
|
|
|
|
* show receiver power, since FP is then not needed.
|
|
|
|
*/
|
|
|
|
if (sfp->id.ext.diagmon & SFP_DIAGMON_EXT_CAL &&
|
|
|
|
channel == 1)
|
|
|
|
return 0;
|
|
|
|
switch (attr) {
|
|
|
|
case hwmon_power_min_alarm:
|
|
|
|
case hwmon_power_max_alarm:
|
|
|
|
case hwmon_power_lcrit_alarm:
|
|
|
|
case hwmon_power_crit_alarm:
|
|
|
|
case hwmon_power_min:
|
|
|
|
case hwmon_power_max:
|
|
|
|
case hwmon_power_lcrit:
|
|
|
|
case hwmon_power_crit:
|
2018-09-04 09:23:56 +07:00
|
|
|
if (!(sfp->id.ext.enhopts & SFP_ENHOPTS_ALARMWARN))
|
|
|
|
return 0;
|
|
|
|
/* fall through */
|
|
|
|
case hwmon_power_input:
|
2019-08-25 06:04:17 +07:00
|
|
|
case hwmon_power_label:
|
net: phy: sfp: Add HWMON support for module sensors
SFP modules can contain a number of sensors. The EEPROM also contains
recommended alarm and critical values for each sensor, and indications
of if these have been exceeded. Export this information via
HWMON. Currently temperature, VCC, bias current, transmit power, and
possibly receiver power is supported.
The sensors in the modules can either return calibrate or uncalibrated
values. Uncalibrated values need to be manipulated, using coefficients
provided in the SFP EEPROM. Uncalibrated receive power values require
floating point maths in order to calibrate them. Performing this in
the kernel is hard. So if the SFP module indicates it uses
uncalibrated values, RX power is not made available.
With this hwmon device, it is possible to view the sensor values using
lm-sensors programs:
in0: +3.29 V (crit min = +2.90 V, min = +3.00 V)
(max = +3.60 V, crit max = +3.70 V)
temp1: +33.0°C (low = -5.0°C, high = +80.0°C)
(crit low = -10.0°C, crit = +85.0°C)
power1: 1000.00 nW (max = 794.00 uW, min = 50.00 uW) ALARM (LCRIT)
(lcrit = 40.00 uW, crit = 1000.00 uW)
curr1: +0.00 A (crit min = +0.00 A, min = +0.00 A) ALARM (LCRIT, MIN)
(max = +0.01 A, crit max = +0.01 A)
The scaling sensors performs on the bias current is not particularly
good. The raw values are more useful:
curr1:
curr1_input: 0.000
curr1_min: 0.002
curr1_max: 0.010
curr1_lcrit: 0.000
curr1_crit: 0.011
curr1_min_alarm: 1.000
curr1_max_alarm: 0.000
curr1_lcrit_alarm: 1.000
curr1_crit_alarm: 0.000
In order to keep the I2C overhead to a minimum, the constant values,
such as limits and calibration coefficients are read once at module
insertion time. Thus only reading *_input and *_alarm properties
requires i2c read operations.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-07-18 02:48:13 +07:00
|
|
|
return 0444;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sfp_hwmon_read_sensor(struct sfp *sfp, int reg, long *value)
|
|
|
|
{
|
|
|
|
__be16 val;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = sfp_read(sfp, true, reg, &val, sizeof(val));
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
*value = be16_to_cpu(val);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sfp_hwmon_to_rx_power(long *value)
|
|
|
|
{
|
2019-07-21 23:50:08 +07:00
|
|
|
*value = DIV_ROUND_CLOSEST(*value, 10);
|
net: phy: sfp: Add HWMON support for module sensors
SFP modules can contain a number of sensors. The EEPROM also contains
recommended alarm and critical values for each sensor, and indications
of if these have been exceeded. Export this information via
HWMON. Currently temperature, VCC, bias current, transmit power, and
possibly receiver power is supported.
The sensors in the modules can either return calibrate or uncalibrated
values. Uncalibrated values need to be manipulated, using coefficients
provided in the SFP EEPROM. Uncalibrated receive power values require
floating point maths in order to calibrate them. Performing this in
the kernel is hard. So if the SFP module indicates it uses
uncalibrated values, RX power is not made available.
With this hwmon device, it is possible to view the sensor values using
lm-sensors programs:
in0: +3.29 V (crit min = +2.90 V, min = +3.00 V)
(max = +3.60 V, crit max = +3.70 V)
temp1: +33.0°C (low = -5.0°C, high = +80.0°C)
(crit low = -10.0°C, crit = +85.0°C)
power1: 1000.00 nW (max = 794.00 uW, min = 50.00 uW) ALARM (LCRIT)
(lcrit = 40.00 uW, crit = 1000.00 uW)
curr1: +0.00 A (crit min = +0.00 A, min = +0.00 A) ALARM (LCRIT, MIN)
(max = +0.01 A, crit max = +0.01 A)
The scaling sensors performs on the bias current is not particularly
good. The raw values are more useful:
curr1:
curr1_input: 0.000
curr1_min: 0.002
curr1_max: 0.010
curr1_lcrit: 0.000
curr1_crit: 0.011
curr1_min_alarm: 1.000
curr1_max_alarm: 0.000
curr1_lcrit_alarm: 1.000
curr1_crit_alarm: 0.000
In order to keep the I2C overhead to a minimum, the constant values,
such as limits and calibration coefficients are read once at module
insertion time. Thus only reading *_input and *_alarm properties
requires i2c read operations.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-07-18 02:48:13 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sfp_hwmon_calibrate(struct sfp *sfp, unsigned int slope, int offset,
|
|
|
|
long *value)
|
|
|
|
{
|
|
|
|
if (sfp->id.ext.diagmon & SFP_DIAGMON_EXT_CAL)
|
|
|
|
*value = DIV_ROUND_CLOSEST(*value * slope, 256) + offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sfp_hwmon_calibrate_temp(struct sfp *sfp, long *value)
|
|
|
|
{
|
|
|
|
sfp_hwmon_calibrate(sfp, be16_to_cpu(sfp->diag.cal_t_slope),
|
|
|
|
be16_to_cpu(sfp->diag.cal_t_offset), value);
|
|
|
|
|
|
|
|
if (*value >= 0x8000)
|
|
|
|
*value -= 0x10000;
|
|
|
|
|
|
|
|
*value = DIV_ROUND_CLOSEST(*value * 1000, 256);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sfp_hwmon_calibrate_vcc(struct sfp *sfp, long *value)
|
|
|
|
{
|
|
|
|
sfp_hwmon_calibrate(sfp, be16_to_cpu(sfp->diag.cal_v_slope),
|
|
|
|
be16_to_cpu(sfp->diag.cal_v_offset), value);
|
|
|
|
|
|
|
|
*value = DIV_ROUND_CLOSEST(*value, 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sfp_hwmon_calibrate_bias(struct sfp *sfp, long *value)
|
|
|
|
{
|
|
|
|
sfp_hwmon_calibrate(sfp, be16_to_cpu(sfp->diag.cal_txi_slope),
|
|
|
|
be16_to_cpu(sfp->diag.cal_txi_offset), value);
|
|
|
|
|
|
|
|
*value = DIV_ROUND_CLOSEST(*value, 500);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sfp_hwmon_calibrate_tx_power(struct sfp *sfp, long *value)
|
|
|
|
{
|
|
|
|
sfp_hwmon_calibrate(sfp, be16_to_cpu(sfp->diag.cal_txpwr_slope),
|
|
|
|
be16_to_cpu(sfp->diag.cal_txpwr_offset), value);
|
|
|
|
|
|
|
|
*value = DIV_ROUND_CLOSEST(*value, 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sfp_hwmon_read_temp(struct sfp *sfp, int reg, long *value)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = sfp_hwmon_read_sensor(sfp, reg, value);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
sfp_hwmon_calibrate_temp(sfp, value);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sfp_hwmon_read_vcc(struct sfp *sfp, int reg, long *value)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = sfp_hwmon_read_sensor(sfp, reg, value);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
sfp_hwmon_calibrate_vcc(sfp, value);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sfp_hwmon_read_bias(struct sfp *sfp, int reg, long *value)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = sfp_hwmon_read_sensor(sfp, reg, value);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
sfp_hwmon_calibrate_bias(sfp, value);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sfp_hwmon_read_tx_power(struct sfp *sfp, int reg, long *value)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = sfp_hwmon_read_sensor(sfp, reg, value);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
sfp_hwmon_calibrate_tx_power(sfp, value);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sfp_hwmon_read_rx_power(struct sfp *sfp, int reg, long *value)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = sfp_hwmon_read_sensor(sfp, reg, value);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
sfp_hwmon_to_rx_power(value);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sfp_hwmon_temp(struct sfp *sfp, u32 attr, long *value)
|
|
|
|
{
|
|
|
|
u8 status;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
switch (attr) {
|
|
|
|
case hwmon_temp_input:
|
|
|
|
return sfp_hwmon_read_temp(sfp, SFP_TEMP, value);
|
|
|
|
|
|
|
|
case hwmon_temp_lcrit:
|
|
|
|
*value = be16_to_cpu(sfp->diag.temp_low_alarm);
|
|
|
|
sfp_hwmon_calibrate_temp(sfp, value);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case hwmon_temp_min:
|
|
|
|
*value = be16_to_cpu(sfp->diag.temp_low_warn);
|
|
|
|
sfp_hwmon_calibrate_temp(sfp, value);
|
|
|
|
return 0;
|
|
|
|
case hwmon_temp_max:
|
|
|
|
*value = be16_to_cpu(sfp->diag.temp_high_warn);
|
|
|
|
sfp_hwmon_calibrate_temp(sfp, value);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case hwmon_temp_crit:
|
|
|
|
*value = be16_to_cpu(sfp->diag.temp_high_alarm);
|
|
|
|
sfp_hwmon_calibrate_temp(sfp, value);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case hwmon_temp_lcrit_alarm:
|
|
|
|
err = sfp_read(sfp, true, SFP_ALARM0, &status, sizeof(status));
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
*value = !!(status & SFP_ALARM0_TEMP_LOW);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case hwmon_temp_min_alarm:
|
|
|
|
err = sfp_read(sfp, true, SFP_WARN0, &status, sizeof(status));
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
*value = !!(status & SFP_WARN0_TEMP_LOW);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case hwmon_temp_max_alarm:
|
|
|
|
err = sfp_read(sfp, true, SFP_WARN0, &status, sizeof(status));
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
*value = !!(status & SFP_WARN0_TEMP_HIGH);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case hwmon_temp_crit_alarm:
|
|
|
|
err = sfp_read(sfp, true, SFP_ALARM0, &status, sizeof(status));
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
*value = !!(status & SFP_ALARM0_TEMP_HIGH);
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sfp_hwmon_vcc(struct sfp *sfp, u32 attr, long *value)
|
|
|
|
{
|
|
|
|
u8 status;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
switch (attr) {
|
|
|
|
case hwmon_in_input:
|
|
|
|
return sfp_hwmon_read_vcc(sfp, SFP_VCC, value);
|
|
|
|
|
|
|
|
case hwmon_in_lcrit:
|
|
|
|
*value = be16_to_cpu(sfp->diag.volt_low_alarm);
|
|
|
|
sfp_hwmon_calibrate_vcc(sfp, value);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case hwmon_in_min:
|
|
|
|
*value = be16_to_cpu(sfp->diag.volt_low_warn);
|
|
|
|
sfp_hwmon_calibrate_vcc(sfp, value);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case hwmon_in_max:
|
|
|
|
*value = be16_to_cpu(sfp->diag.volt_high_warn);
|
|
|
|
sfp_hwmon_calibrate_vcc(sfp, value);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case hwmon_in_crit:
|
|
|
|
*value = be16_to_cpu(sfp->diag.volt_high_alarm);
|
|
|
|
sfp_hwmon_calibrate_vcc(sfp, value);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case hwmon_in_lcrit_alarm:
|
|
|
|
err = sfp_read(sfp, true, SFP_ALARM0, &status, sizeof(status));
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
*value = !!(status & SFP_ALARM0_VCC_LOW);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case hwmon_in_min_alarm:
|
|
|
|
err = sfp_read(sfp, true, SFP_WARN0, &status, sizeof(status));
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
*value = !!(status & SFP_WARN0_VCC_LOW);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case hwmon_in_max_alarm:
|
|
|
|
err = sfp_read(sfp, true, SFP_WARN0, &status, sizeof(status));
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
*value = !!(status & SFP_WARN0_VCC_HIGH);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case hwmon_in_crit_alarm:
|
|
|
|
err = sfp_read(sfp, true, SFP_ALARM0, &status, sizeof(status));
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
*value = !!(status & SFP_ALARM0_VCC_HIGH);
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sfp_hwmon_bias(struct sfp *sfp, u32 attr, long *value)
|
|
|
|
{
|
|
|
|
u8 status;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
switch (attr) {
|
|
|
|
case hwmon_curr_input:
|
|
|
|
return sfp_hwmon_read_bias(sfp, SFP_TX_BIAS, value);
|
|
|
|
|
|
|
|
case hwmon_curr_lcrit:
|
|
|
|
*value = be16_to_cpu(sfp->diag.bias_low_alarm);
|
|
|
|
sfp_hwmon_calibrate_bias(sfp, value);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case hwmon_curr_min:
|
|
|
|
*value = be16_to_cpu(sfp->diag.bias_low_warn);
|
|
|
|
sfp_hwmon_calibrate_bias(sfp, value);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case hwmon_curr_max:
|
|
|
|
*value = be16_to_cpu(sfp->diag.bias_high_warn);
|
|
|
|
sfp_hwmon_calibrate_bias(sfp, value);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case hwmon_curr_crit:
|
|
|
|
*value = be16_to_cpu(sfp->diag.bias_high_alarm);
|
|
|
|
sfp_hwmon_calibrate_bias(sfp, value);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case hwmon_curr_lcrit_alarm:
|
|
|
|
err = sfp_read(sfp, true, SFP_ALARM0, &status, sizeof(status));
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
*value = !!(status & SFP_ALARM0_TX_BIAS_LOW);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case hwmon_curr_min_alarm:
|
|
|
|
err = sfp_read(sfp, true, SFP_WARN0, &status, sizeof(status));
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
*value = !!(status & SFP_WARN0_TX_BIAS_LOW);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case hwmon_curr_max_alarm:
|
|
|
|
err = sfp_read(sfp, true, SFP_WARN0, &status, sizeof(status));
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
*value = !!(status & SFP_WARN0_TX_BIAS_HIGH);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case hwmon_curr_crit_alarm:
|
|
|
|
err = sfp_read(sfp, true, SFP_ALARM0, &status, sizeof(status));
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
*value = !!(status & SFP_ALARM0_TX_BIAS_HIGH);
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sfp_hwmon_tx_power(struct sfp *sfp, u32 attr, long *value)
|
|
|
|
{
|
|
|
|
u8 status;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
switch (attr) {
|
|
|
|
case hwmon_power_input:
|
|
|
|
return sfp_hwmon_read_tx_power(sfp, SFP_TX_POWER, value);
|
|
|
|
|
|
|
|
case hwmon_power_lcrit:
|
|
|
|
*value = be16_to_cpu(sfp->diag.txpwr_low_alarm);
|
|
|
|
sfp_hwmon_calibrate_tx_power(sfp, value);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case hwmon_power_min:
|
|
|
|
*value = be16_to_cpu(sfp->diag.txpwr_low_warn);
|
|
|
|
sfp_hwmon_calibrate_tx_power(sfp, value);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case hwmon_power_max:
|
|
|
|
*value = be16_to_cpu(sfp->diag.txpwr_high_warn);
|
|
|
|
sfp_hwmon_calibrate_tx_power(sfp, value);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case hwmon_power_crit:
|
|
|
|
*value = be16_to_cpu(sfp->diag.txpwr_high_alarm);
|
|
|
|
sfp_hwmon_calibrate_tx_power(sfp, value);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case hwmon_power_lcrit_alarm:
|
|
|
|
err = sfp_read(sfp, true, SFP_ALARM0, &status, sizeof(status));
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
*value = !!(status & SFP_ALARM0_TXPWR_LOW);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case hwmon_power_min_alarm:
|
|
|
|
err = sfp_read(sfp, true, SFP_WARN0, &status, sizeof(status));
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
*value = !!(status & SFP_WARN0_TXPWR_LOW);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case hwmon_power_max_alarm:
|
|
|
|
err = sfp_read(sfp, true, SFP_WARN0, &status, sizeof(status));
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
*value = !!(status & SFP_WARN0_TXPWR_HIGH);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case hwmon_power_crit_alarm:
|
|
|
|
err = sfp_read(sfp, true, SFP_ALARM0, &status, sizeof(status));
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
*value = !!(status & SFP_ALARM0_TXPWR_HIGH);
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sfp_hwmon_rx_power(struct sfp *sfp, u32 attr, long *value)
|
|
|
|
{
|
|
|
|
u8 status;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
switch (attr) {
|
|
|
|
case hwmon_power_input:
|
|
|
|
return sfp_hwmon_read_rx_power(sfp, SFP_RX_POWER, value);
|
|
|
|
|
|
|
|
case hwmon_power_lcrit:
|
|
|
|
*value = be16_to_cpu(sfp->diag.rxpwr_low_alarm);
|
|
|
|
sfp_hwmon_to_rx_power(value);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case hwmon_power_min:
|
|
|
|
*value = be16_to_cpu(sfp->diag.rxpwr_low_warn);
|
|
|
|
sfp_hwmon_to_rx_power(value);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case hwmon_power_max:
|
|
|
|
*value = be16_to_cpu(sfp->diag.rxpwr_high_warn);
|
|
|
|
sfp_hwmon_to_rx_power(value);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case hwmon_power_crit:
|
|
|
|
*value = be16_to_cpu(sfp->diag.rxpwr_high_alarm);
|
|
|
|
sfp_hwmon_to_rx_power(value);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case hwmon_power_lcrit_alarm:
|
|
|
|
err = sfp_read(sfp, true, SFP_ALARM1, &status, sizeof(status));
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
*value = !!(status & SFP_ALARM1_RXPWR_LOW);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case hwmon_power_min_alarm:
|
|
|
|
err = sfp_read(sfp, true, SFP_WARN1, &status, sizeof(status));
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
*value = !!(status & SFP_WARN1_RXPWR_LOW);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case hwmon_power_max_alarm:
|
|
|
|
err = sfp_read(sfp, true, SFP_WARN1, &status, sizeof(status));
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
*value = !!(status & SFP_WARN1_RXPWR_HIGH);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case hwmon_power_crit_alarm:
|
|
|
|
err = sfp_read(sfp, true, SFP_ALARM1, &status, sizeof(status));
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
*value = !!(status & SFP_ALARM1_RXPWR_HIGH);
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sfp_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
|
|
|
|
u32 attr, int channel, long *value)
|
|
|
|
{
|
|
|
|
struct sfp *sfp = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case hwmon_temp:
|
|
|
|
return sfp_hwmon_temp(sfp, attr, value);
|
|
|
|
case hwmon_in:
|
|
|
|
return sfp_hwmon_vcc(sfp, attr, value);
|
|
|
|
case hwmon_curr:
|
|
|
|
return sfp_hwmon_bias(sfp, attr, value);
|
|
|
|
case hwmon_power:
|
|
|
|
switch (channel) {
|
|
|
|
case 0:
|
|
|
|
return sfp_hwmon_tx_power(sfp, attr, value);
|
|
|
|
case 1:
|
|
|
|
return sfp_hwmon_rx_power(sfp, attr, value);
|
|
|
|
default:
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-25 06:04:17 +07:00
|
|
|
static const char *const sfp_hwmon_power_labels[] = {
|
|
|
|
"TX_power",
|
|
|
|
"RX_power",
|
|
|
|
};
|
|
|
|
|
|
|
|
static int sfp_hwmon_read_string(struct device *dev,
|
|
|
|
enum hwmon_sensor_types type,
|
|
|
|
u32 attr, int channel, const char **str)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case hwmon_curr:
|
|
|
|
switch (attr) {
|
|
|
|
case hwmon_curr_label:
|
|
|
|
*str = "bias";
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case hwmon_temp:
|
|
|
|
switch (attr) {
|
|
|
|
case hwmon_temp_label:
|
|
|
|
*str = "temperature";
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case hwmon_in:
|
|
|
|
switch (attr) {
|
|
|
|
case hwmon_in_label:
|
|
|
|
*str = "VCC";
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case hwmon_power:
|
|
|
|
switch (attr) {
|
|
|
|
case hwmon_power_label:
|
|
|
|
*str = sfp_hwmon_power_labels[channel];
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
net: phy: sfp: Add HWMON support for module sensors
SFP modules can contain a number of sensors. The EEPROM also contains
recommended alarm and critical values for each sensor, and indications
of if these have been exceeded. Export this information via
HWMON. Currently temperature, VCC, bias current, transmit power, and
possibly receiver power is supported.
The sensors in the modules can either return calibrate or uncalibrated
values. Uncalibrated values need to be manipulated, using coefficients
provided in the SFP EEPROM. Uncalibrated receive power values require
floating point maths in order to calibrate them. Performing this in
the kernel is hard. So if the SFP module indicates it uses
uncalibrated values, RX power is not made available.
With this hwmon device, it is possible to view the sensor values using
lm-sensors programs:
in0: +3.29 V (crit min = +2.90 V, min = +3.00 V)
(max = +3.60 V, crit max = +3.70 V)
temp1: +33.0°C (low = -5.0°C, high = +80.0°C)
(crit low = -10.0°C, crit = +85.0°C)
power1: 1000.00 nW (max = 794.00 uW, min = 50.00 uW) ALARM (LCRIT)
(lcrit = 40.00 uW, crit = 1000.00 uW)
curr1: +0.00 A (crit min = +0.00 A, min = +0.00 A) ALARM (LCRIT, MIN)
(max = +0.01 A, crit max = +0.01 A)
The scaling sensors performs on the bias current is not particularly
good. The raw values are more useful:
curr1:
curr1_input: 0.000
curr1_min: 0.002
curr1_max: 0.010
curr1_lcrit: 0.000
curr1_crit: 0.011
curr1_min_alarm: 1.000
curr1_max_alarm: 0.000
curr1_lcrit_alarm: 1.000
curr1_crit_alarm: 0.000
In order to keep the I2C overhead to a minimum, the constant values,
such as limits and calibration coefficients are read once at module
insertion time. Thus only reading *_input and *_alarm properties
requires i2c read operations.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-07-18 02:48:13 +07:00
|
|
|
static const struct hwmon_ops sfp_hwmon_ops = {
|
|
|
|
.is_visible = sfp_hwmon_is_visible,
|
|
|
|
.read = sfp_hwmon_read,
|
2019-08-25 06:04:17 +07:00
|
|
|
.read_string = sfp_hwmon_read_string,
|
net: phy: sfp: Add HWMON support for module sensors
SFP modules can contain a number of sensors. The EEPROM also contains
recommended alarm and critical values for each sensor, and indications
of if these have been exceeded. Export this information via
HWMON. Currently temperature, VCC, bias current, transmit power, and
possibly receiver power is supported.
The sensors in the modules can either return calibrate or uncalibrated
values. Uncalibrated values need to be manipulated, using coefficients
provided in the SFP EEPROM. Uncalibrated receive power values require
floating point maths in order to calibrate them. Performing this in
the kernel is hard. So if the SFP module indicates it uses
uncalibrated values, RX power is not made available.
With this hwmon device, it is possible to view the sensor values using
lm-sensors programs:
in0: +3.29 V (crit min = +2.90 V, min = +3.00 V)
(max = +3.60 V, crit max = +3.70 V)
temp1: +33.0°C (low = -5.0°C, high = +80.0°C)
(crit low = -10.0°C, crit = +85.0°C)
power1: 1000.00 nW (max = 794.00 uW, min = 50.00 uW) ALARM (LCRIT)
(lcrit = 40.00 uW, crit = 1000.00 uW)
curr1: +0.00 A (crit min = +0.00 A, min = +0.00 A) ALARM (LCRIT, MIN)
(max = +0.01 A, crit max = +0.01 A)
The scaling sensors performs on the bias current is not particularly
good. The raw values are more useful:
curr1:
curr1_input: 0.000
curr1_min: 0.002
curr1_max: 0.010
curr1_lcrit: 0.000
curr1_crit: 0.011
curr1_min_alarm: 1.000
curr1_max_alarm: 0.000
curr1_lcrit_alarm: 1.000
curr1_crit_alarm: 0.000
In order to keep the I2C overhead to a minimum, the constant values,
such as limits and calibration coefficients are read once at module
insertion time. Thus only reading *_input and *_alarm properties
requires i2c read operations.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-07-18 02:48:13 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static u32 sfp_hwmon_chip_config[] = {
|
|
|
|
HWMON_C_REGISTER_TZ,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct hwmon_channel_info sfp_hwmon_chip = {
|
|
|
|
.type = hwmon_chip,
|
|
|
|
.config = sfp_hwmon_chip_config,
|
|
|
|
};
|
|
|
|
|
|
|
|
static u32 sfp_hwmon_temp_config[] = {
|
|
|
|
HWMON_T_INPUT |
|
|
|
|
HWMON_T_MAX | HWMON_T_MIN |
|
|
|
|
HWMON_T_MAX_ALARM | HWMON_T_MIN_ALARM |
|
|
|
|
HWMON_T_CRIT | HWMON_T_LCRIT |
|
2019-08-25 06:04:17 +07:00
|
|
|
HWMON_T_CRIT_ALARM | HWMON_T_LCRIT_ALARM |
|
|
|
|
HWMON_T_LABEL,
|
net: phy: sfp: Add HWMON support for module sensors
SFP modules can contain a number of sensors. The EEPROM also contains
recommended alarm and critical values for each sensor, and indications
of if these have been exceeded. Export this information via
HWMON. Currently temperature, VCC, bias current, transmit power, and
possibly receiver power is supported.
The sensors in the modules can either return calibrate or uncalibrated
values. Uncalibrated values need to be manipulated, using coefficients
provided in the SFP EEPROM. Uncalibrated receive power values require
floating point maths in order to calibrate them. Performing this in
the kernel is hard. So if the SFP module indicates it uses
uncalibrated values, RX power is not made available.
With this hwmon device, it is possible to view the sensor values using
lm-sensors programs:
in0: +3.29 V (crit min = +2.90 V, min = +3.00 V)
(max = +3.60 V, crit max = +3.70 V)
temp1: +33.0°C (low = -5.0°C, high = +80.0°C)
(crit low = -10.0°C, crit = +85.0°C)
power1: 1000.00 nW (max = 794.00 uW, min = 50.00 uW) ALARM (LCRIT)
(lcrit = 40.00 uW, crit = 1000.00 uW)
curr1: +0.00 A (crit min = +0.00 A, min = +0.00 A) ALARM (LCRIT, MIN)
(max = +0.01 A, crit max = +0.01 A)
The scaling sensors performs on the bias current is not particularly
good. The raw values are more useful:
curr1:
curr1_input: 0.000
curr1_min: 0.002
curr1_max: 0.010
curr1_lcrit: 0.000
curr1_crit: 0.011
curr1_min_alarm: 1.000
curr1_max_alarm: 0.000
curr1_lcrit_alarm: 1.000
curr1_crit_alarm: 0.000
In order to keep the I2C overhead to a minimum, the constant values,
such as limits and calibration coefficients are read once at module
insertion time. Thus only reading *_input and *_alarm properties
requires i2c read operations.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-07-18 02:48:13 +07:00
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct hwmon_channel_info sfp_hwmon_temp_channel_info = {
|
|
|
|
.type = hwmon_temp,
|
|
|
|
.config = sfp_hwmon_temp_config,
|
|
|
|
};
|
|
|
|
|
|
|
|
static u32 sfp_hwmon_vcc_config[] = {
|
|
|
|
HWMON_I_INPUT |
|
|
|
|
HWMON_I_MAX | HWMON_I_MIN |
|
|
|
|
HWMON_I_MAX_ALARM | HWMON_I_MIN_ALARM |
|
|
|
|
HWMON_I_CRIT | HWMON_I_LCRIT |
|
2019-08-25 06:04:17 +07:00
|
|
|
HWMON_I_CRIT_ALARM | HWMON_I_LCRIT_ALARM |
|
|
|
|
HWMON_I_LABEL,
|
net: phy: sfp: Add HWMON support for module sensors
SFP modules can contain a number of sensors. The EEPROM also contains
recommended alarm and critical values for each sensor, and indications
of if these have been exceeded. Export this information via
HWMON. Currently temperature, VCC, bias current, transmit power, and
possibly receiver power is supported.
The sensors in the modules can either return calibrate or uncalibrated
values. Uncalibrated values need to be manipulated, using coefficients
provided in the SFP EEPROM. Uncalibrated receive power values require
floating point maths in order to calibrate them. Performing this in
the kernel is hard. So if the SFP module indicates it uses
uncalibrated values, RX power is not made available.
With this hwmon device, it is possible to view the sensor values using
lm-sensors programs:
in0: +3.29 V (crit min = +2.90 V, min = +3.00 V)
(max = +3.60 V, crit max = +3.70 V)
temp1: +33.0°C (low = -5.0°C, high = +80.0°C)
(crit low = -10.0°C, crit = +85.0°C)
power1: 1000.00 nW (max = 794.00 uW, min = 50.00 uW) ALARM (LCRIT)
(lcrit = 40.00 uW, crit = 1000.00 uW)
curr1: +0.00 A (crit min = +0.00 A, min = +0.00 A) ALARM (LCRIT, MIN)
(max = +0.01 A, crit max = +0.01 A)
The scaling sensors performs on the bias current is not particularly
good. The raw values are more useful:
curr1:
curr1_input: 0.000
curr1_min: 0.002
curr1_max: 0.010
curr1_lcrit: 0.000
curr1_crit: 0.011
curr1_min_alarm: 1.000
curr1_max_alarm: 0.000
curr1_lcrit_alarm: 1.000
curr1_crit_alarm: 0.000
In order to keep the I2C overhead to a minimum, the constant values,
such as limits and calibration coefficients are read once at module
insertion time. Thus only reading *_input and *_alarm properties
requires i2c read operations.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-07-18 02:48:13 +07:00
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct hwmon_channel_info sfp_hwmon_vcc_channel_info = {
|
|
|
|
.type = hwmon_in,
|
|
|
|
.config = sfp_hwmon_vcc_config,
|
|
|
|
};
|
|
|
|
|
|
|
|
static u32 sfp_hwmon_bias_config[] = {
|
|
|
|
HWMON_C_INPUT |
|
|
|
|
HWMON_C_MAX | HWMON_C_MIN |
|
|
|
|
HWMON_C_MAX_ALARM | HWMON_C_MIN_ALARM |
|
|
|
|
HWMON_C_CRIT | HWMON_C_LCRIT |
|
2019-08-25 06:04:17 +07:00
|
|
|
HWMON_C_CRIT_ALARM | HWMON_C_LCRIT_ALARM |
|
|
|
|
HWMON_C_LABEL,
|
net: phy: sfp: Add HWMON support for module sensors
SFP modules can contain a number of sensors. The EEPROM also contains
recommended alarm and critical values for each sensor, and indications
of if these have been exceeded. Export this information via
HWMON. Currently temperature, VCC, bias current, transmit power, and
possibly receiver power is supported.
The sensors in the modules can either return calibrate or uncalibrated
values. Uncalibrated values need to be manipulated, using coefficients
provided in the SFP EEPROM. Uncalibrated receive power values require
floating point maths in order to calibrate them. Performing this in
the kernel is hard. So if the SFP module indicates it uses
uncalibrated values, RX power is not made available.
With this hwmon device, it is possible to view the sensor values using
lm-sensors programs:
in0: +3.29 V (crit min = +2.90 V, min = +3.00 V)
(max = +3.60 V, crit max = +3.70 V)
temp1: +33.0°C (low = -5.0°C, high = +80.0°C)
(crit low = -10.0°C, crit = +85.0°C)
power1: 1000.00 nW (max = 794.00 uW, min = 50.00 uW) ALARM (LCRIT)
(lcrit = 40.00 uW, crit = 1000.00 uW)
curr1: +0.00 A (crit min = +0.00 A, min = +0.00 A) ALARM (LCRIT, MIN)
(max = +0.01 A, crit max = +0.01 A)
The scaling sensors performs on the bias current is not particularly
good. The raw values are more useful:
curr1:
curr1_input: 0.000
curr1_min: 0.002
curr1_max: 0.010
curr1_lcrit: 0.000
curr1_crit: 0.011
curr1_min_alarm: 1.000
curr1_max_alarm: 0.000
curr1_lcrit_alarm: 1.000
curr1_crit_alarm: 0.000
In order to keep the I2C overhead to a minimum, the constant values,
such as limits and calibration coefficients are read once at module
insertion time. Thus only reading *_input and *_alarm properties
requires i2c read operations.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-07-18 02:48:13 +07:00
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct hwmon_channel_info sfp_hwmon_bias_channel_info = {
|
|
|
|
.type = hwmon_curr,
|
|
|
|
.config = sfp_hwmon_bias_config,
|
|
|
|
};
|
|
|
|
|
|
|
|
static u32 sfp_hwmon_power_config[] = {
|
|
|
|
/* Transmit power */
|
|
|
|
HWMON_P_INPUT |
|
|
|
|
HWMON_P_MAX | HWMON_P_MIN |
|
|
|
|
HWMON_P_MAX_ALARM | HWMON_P_MIN_ALARM |
|
|
|
|
HWMON_P_CRIT | HWMON_P_LCRIT |
|
2019-08-25 06:04:17 +07:00
|
|
|
HWMON_P_CRIT_ALARM | HWMON_P_LCRIT_ALARM |
|
|
|
|
HWMON_P_LABEL,
|
net: phy: sfp: Add HWMON support for module sensors
SFP modules can contain a number of sensors. The EEPROM also contains
recommended alarm and critical values for each sensor, and indications
of if these have been exceeded. Export this information via
HWMON. Currently temperature, VCC, bias current, transmit power, and
possibly receiver power is supported.
The sensors in the modules can either return calibrate or uncalibrated
values. Uncalibrated values need to be manipulated, using coefficients
provided in the SFP EEPROM. Uncalibrated receive power values require
floating point maths in order to calibrate them. Performing this in
the kernel is hard. So if the SFP module indicates it uses
uncalibrated values, RX power is not made available.
With this hwmon device, it is possible to view the sensor values using
lm-sensors programs:
in0: +3.29 V (crit min = +2.90 V, min = +3.00 V)
(max = +3.60 V, crit max = +3.70 V)
temp1: +33.0°C (low = -5.0°C, high = +80.0°C)
(crit low = -10.0°C, crit = +85.0°C)
power1: 1000.00 nW (max = 794.00 uW, min = 50.00 uW) ALARM (LCRIT)
(lcrit = 40.00 uW, crit = 1000.00 uW)
curr1: +0.00 A (crit min = +0.00 A, min = +0.00 A) ALARM (LCRIT, MIN)
(max = +0.01 A, crit max = +0.01 A)
The scaling sensors performs on the bias current is not particularly
good. The raw values are more useful:
curr1:
curr1_input: 0.000
curr1_min: 0.002
curr1_max: 0.010
curr1_lcrit: 0.000
curr1_crit: 0.011
curr1_min_alarm: 1.000
curr1_max_alarm: 0.000
curr1_lcrit_alarm: 1.000
curr1_crit_alarm: 0.000
In order to keep the I2C overhead to a minimum, the constant values,
such as limits and calibration coefficients are read once at module
insertion time. Thus only reading *_input and *_alarm properties
requires i2c read operations.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-07-18 02:48:13 +07:00
|
|
|
/* Receive power */
|
|
|
|
HWMON_P_INPUT |
|
|
|
|
HWMON_P_MAX | HWMON_P_MIN |
|
|
|
|
HWMON_P_MAX_ALARM | HWMON_P_MIN_ALARM |
|
|
|
|
HWMON_P_CRIT | HWMON_P_LCRIT |
|
2019-08-25 06:04:17 +07:00
|
|
|
HWMON_P_CRIT_ALARM | HWMON_P_LCRIT_ALARM |
|
|
|
|
HWMON_P_LABEL,
|
net: phy: sfp: Add HWMON support for module sensors
SFP modules can contain a number of sensors. The EEPROM also contains
recommended alarm and critical values for each sensor, and indications
of if these have been exceeded. Export this information via
HWMON. Currently temperature, VCC, bias current, transmit power, and
possibly receiver power is supported.
The sensors in the modules can either return calibrate or uncalibrated
values. Uncalibrated values need to be manipulated, using coefficients
provided in the SFP EEPROM. Uncalibrated receive power values require
floating point maths in order to calibrate them. Performing this in
the kernel is hard. So if the SFP module indicates it uses
uncalibrated values, RX power is not made available.
With this hwmon device, it is possible to view the sensor values using
lm-sensors programs:
in0: +3.29 V (crit min = +2.90 V, min = +3.00 V)
(max = +3.60 V, crit max = +3.70 V)
temp1: +33.0°C (low = -5.0°C, high = +80.0°C)
(crit low = -10.0°C, crit = +85.0°C)
power1: 1000.00 nW (max = 794.00 uW, min = 50.00 uW) ALARM (LCRIT)
(lcrit = 40.00 uW, crit = 1000.00 uW)
curr1: +0.00 A (crit min = +0.00 A, min = +0.00 A) ALARM (LCRIT, MIN)
(max = +0.01 A, crit max = +0.01 A)
The scaling sensors performs on the bias current is not particularly
good. The raw values are more useful:
curr1:
curr1_input: 0.000
curr1_min: 0.002
curr1_max: 0.010
curr1_lcrit: 0.000
curr1_crit: 0.011
curr1_min_alarm: 1.000
curr1_max_alarm: 0.000
curr1_lcrit_alarm: 1.000
curr1_crit_alarm: 0.000
In order to keep the I2C overhead to a minimum, the constant values,
such as limits and calibration coefficients are read once at module
insertion time. Thus only reading *_input and *_alarm properties
requires i2c read operations.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-07-18 02:48:13 +07:00
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct hwmon_channel_info sfp_hwmon_power_channel_info = {
|
|
|
|
.type = hwmon_power,
|
|
|
|
.config = sfp_hwmon_power_config,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct hwmon_channel_info *sfp_hwmon_info[] = {
|
|
|
|
&sfp_hwmon_chip,
|
|
|
|
&sfp_hwmon_vcc_channel_info,
|
|
|
|
&sfp_hwmon_temp_channel_info,
|
|
|
|
&sfp_hwmon_bias_channel_info,
|
|
|
|
&sfp_hwmon_power_channel_info,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct hwmon_chip_info sfp_hwmon_chip_info = {
|
|
|
|
.ops = &sfp_hwmon_ops,
|
|
|
|
.info = sfp_hwmon_info,
|
|
|
|
};
|
|
|
|
|
net: sfp: allow modules with slow diagnostics to probe
When a module is inserted, we attempt to read read the ID from address
0x50. Once we are able to read the ID, we immediately attempt to
initialise the hwmon support by reading from address 0x51. If this
fails, then we fall into error state, and assume that the module is
not usable.
Modules such as the ALCATELLUCENT 3FE46541AA use a real EEPROM for
I2C address 0x50, which responds immediately. However, address 0x51
is an emulated, which only becomes available once the on-board firmware
has booted. This prompts us to fall into the error state.
Since the module may be usable without diagnostics, arrange for the
hwmon probe independent of the rest of the SFP itself, retrying every
5s for up to about 60s for the monitoring to become available, and
print an error message if it doesn't become available.
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-11-10 21:07:35 +07:00
|
|
|
static void sfp_hwmon_probe(struct work_struct *work)
|
net: phy: sfp: Add HWMON support for module sensors
SFP modules can contain a number of sensors. The EEPROM also contains
recommended alarm and critical values for each sensor, and indications
of if these have been exceeded. Export this information via
HWMON. Currently temperature, VCC, bias current, transmit power, and
possibly receiver power is supported.
The sensors in the modules can either return calibrate or uncalibrated
values. Uncalibrated values need to be manipulated, using coefficients
provided in the SFP EEPROM. Uncalibrated receive power values require
floating point maths in order to calibrate them. Performing this in
the kernel is hard. So if the SFP module indicates it uses
uncalibrated values, RX power is not made available.
With this hwmon device, it is possible to view the sensor values using
lm-sensors programs:
in0: +3.29 V (crit min = +2.90 V, min = +3.00 V)
(max = +3.60 V, crit max = +3.70 V)
temp1: +33.0°C (low = -5.0°C, high = +80.0°C)
(crit low = -10.0°C, crit = +85.0°C)
power1: 1000.00 nW (max = 794.00 uW, min = 50.00 uW) ALARM (LCRIT)
(lcrit = 40.00 uW, crit = 1000.00 uW)
curr1: +0.00 A (crit min = +0.00 A, min = +0.00 A) ALARM (LCRIT, MIN)
(max = +0.01 A, crit max = +0.01 A)
The scaling sensors performs on the bias current is not particularly
good. The raw values are more useful:
curr1:
curr1_input: 0.000
curr1_min: 0.002
curr1_max: 0.010
curr1_lcrit: 0.000
curr1_crit: 0.011
curr1_min_alarm: 1.000
curr1_max_alarm: 0.000
curr1_lcrit_alarm: 1.000
curr1_crit_alarm: 0.000
In order to keep the I2C overhead to a minimum, the constant values,
such as limits and calibration coefficients are read once at module
insertion time. Thus only reading *_input and *_alarm properties
requires i2c read operations.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-07-18 02:48:13 +07:00
|
|
|
{
|
net: sfp: allow modules with slow diagnostics to probe
When a module is inserted, we attempt to read read the ID from address
0x50. Once we are able to read the ID, we immediately attempt to
initialise the hwmon support by reading from address 0x51. If this
fails, then we fall into error state, and assume that the module is
not usable.
Modules such as the ALCATELLUCENT 3FE46541AA use a real EEPROM for
I2C address 0x50, which responds immediately. However, address 0x51
is an emulated, which only becomes available once the on-board firmware
has booted. This prompts us to fall into the error state.
Since the module may be usable without diagnostics, arrange for the
hwmon probe independent of the rest of the SFP itself, retrying every
5s for up to about 60s for the monitoring to become available, and
print an error message if it doesn't become available.
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-11-10 21:07:35 +07:00
|
|
|
struct sfp *sfp = container_of(work, struct sfp, hwmon_probe.work);
|
net: phy: sfp: Add HWMON support for module sensors
SFP modules can contain a number of sensors. The EEPROM also contains
recommended alarm and critical values for each sensor, and indications
of if these have been exceeded. Export this information via
HWMON. Currently temperature, VCC, bias current, transmit power, and
possibly receiver power is supported.
The sensors in the modules can either return calibrate or uncalibrated
values. Uncalibrated values need to be manipulated, using coefficients
provided in the SFP EEPROM. Uncalibrated receive power values require
floating point maths in order to calibrate them. Performing this in
the kernel is hard. So if the SFP module indicates it uses
uncalibrated values, RX power is not made available.
With this hwmon device, it is possible to view the sensor values using
lm-sensors programs:
in0: +3.29 V (crit min = +2.90 V, min = +3.00 V)
(max = +3.60 V, crit max = +3.70 V)
temp1: +33.0°C (low = -5.0°C, high = +80.0°C)
(crit low = -10.0°C, crit = +85.0°C)
power1: 1000.00 nW (max = 794.00 uW, min = 50.00 uW) ALARM (LCRIT)
(lcrit = 40.00 uW, crit = 1000.00 uW)
curr1: +0.00 A (crit min = +0.00 A, min = +0.00 A) ALARM (LCRIT, MIN)
(max = +0.01 A, crit max = +0.01 A)
The scaling sensors performs on the bias current is not particularly
good. The raw values are more useful:
curr1:
curr1_input: 0.000
curr1_min: 0.002
curr1_max: 0.010
curr1_lcrit: 0.000
curr1_crit: 0.011
curr1_min_alarm: 1.000
curr1_max_alarm: 0.000
curr1_lcrit_alarm: 1.000
curr1_crit_alarm: 0.000
In order to keep the I2C overhead to a minimum, the constant values,
such as limits and calibration coefficients are read once at module
insertion time. Thus only reading *_input and *_alarm properties
requires i2c read operations.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-07-18 02:48:13 +07:00
|
|
|
int err, i;
|
|
|
|
|
|
|
|
err = sfp_read(sfp, true, 0, &sfp->diag, sizeof(sfp->diag));
|
net: sfp: allow modules with slow diagnostics to probe
When a module is inserted, we attempt to read read the ID from address
0x50. Once we are able to read the ID, we immediately attempt to
initialise the hwmon support by reading from address 0x51. If this
fails, then we fall into error state, and assume that the module is
not usable.
Modules such as the ALCATELLUCENT 3FE46541AA use a real EEPROM for
I2C address 0x50, which responds immediately. However, address 0x51
is an emulated, which only becomes available once the on-board firmware
has booted. This prompts us to fall into the error state.
Since the module may be usable without diagnostics, arrange for the
hwmon probe independent of the rest of the SFP itself, retrying every
5s for up to about 60s for the monitoring to become available, and
print an error message if it doesn't become available.
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-11-10 21:07:35 +07:00
|
|
|
if (err < 0) {
|
|
|
|
if (sfp->hwmon_tries--) {
|
|
|
|
mod_delayed_work(system_wq, &sfp->hwmon_probe,
|
|
|
|
T_PROBE_RETRY_SLOW);
|
|
|
|
} else {
|
|
|
|
dev_warn(sfp->dev, "hwmon probe failed: %d\n", err);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
net: phy: sfp: Add HWMON support for module sensors
SFP modules can contain a number of sensors. The EEPROM also contains
recommended alarm and critical values for each sensor, and indications
of if these have been exceeded. Export this information via
HWMON. Currently temperature, VCC, bias current, transmit power, and
possibly receiver power is supported.
The sensors in the modules can either return calibrate or uncalibrated
values. Uncalibrated values need to be manipulated, using coefficients
provided in the SFP EEPROM. Uncalibrated receive power values require
floating point maths in order to calibrate them. Performing this in
the kernel is hard. So if the SFP module indicates it uses
uncalibrated values, RX power is not made available.
With this hwmon device, it is possible to view the sensor values using
lm-sensors programs:
in0: +3.29 V (crit min = +2.90 V, min = +3.00 V)
(max = +3.60 V, crit max = +3.70 V)
temp1: +33.0°C (low = -5.0°C, high = +80.0°C)
(crit low = -10.0°C, crit = +85.0°C)
power1: 1000.00 nW (max = 794.00 uW, min = 50.00 uW) ALARM (LCRIT)
(lcrit = 40.00 uW, crit = 1000.00 uW)
curr1: +0.00 A (crit min = +0.00 A, min = +0.00 A) ALARM (LCRIT, MIN)
(max = +0.01 A, crit max = +0.01 A)
The scaling sensors performs on the bias current is not particularly
good. The raw values are more useful:
curr1:
curr1_input: 0.000
curr1_min: 0.002
curr1_max: 0.010
curr1_lcrit: 0.000
curr1_crit: 0.011
curr1_min_alarm: 1.000
curr1_max_alarm: 0.000
curr1_lcrit_alarm: 1.000
curr1_crit_alarm: 0.000
In order to keep the I2C overhead to a minimum, the constant values,
such as limits and calibration coefficients are read once at module
insertion time. Thus only reading *_input and *_alarm properties
requires i2c read operations.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-07-18 02:48:13 +07:00
|
|
|
|
|
|
|
sfp->hwmon_name = kstrdup(dev_name(sfp->dev), GFP_KERNEL);
|
net: sfp: allow modules with slow diagnostics to probe
When a module is inserted, we attempt to read read the ID from address
0x50. Once we are able to read the ID, we immediately attempt to
initialise the hwmon support by reading from address 0x51. If this
fails, then we fall into error state, and assume that the module is
not usable.
Modules such as the ALCATELLUCENT 3FE46541AA use a real EEPROM for
I2C address 0x50, which responds immediately. However, address 0x51
is an emulated, which only becomes available once the on-board firmware
has booted. This prompts us to fall into the error state.
Since the module may be usable without diagnostics, arrange for the
hwmon probe independent of the rest of the SFP itself, retrying every
5s for up to about 60s for the monitoring to become available, and
print an error message if it doesn't become available.
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-11-10 21:07:35 +07:00
|
|
|
if (!sfp->hwmon_name) {
|
|
|
|
dev_err(sfp->dev, "out of memory for hwmon name\n");
|
|
|
|
return;
|
|
|
|
}
|
net: phy: sfp: Add HWMON support for module sensors
SFP modules can contain a number of sensors. The EEPROM also contains
recommended alarm and critical values for each sensor, and indications
of if these have been exceeded. Export this information via
HWMON. Currently temperature, VCC, bias current, transmit power, and
possibly receiver power is supported.
The sensors in the modules can either return calibrate or uncalibrated
values. Uncalibrated values need to be manipulated, using coefficients
provided in the SFP EEPROM. Uncalibrated receive power values require
floating point maths in order to calibrate them. Performing this in
the kernel is hard. So if the SFP module indicates it uses
uncalibrated values, RX power is not made available.
With this hwmon device, it is possible to view the sensor values using
lm-sensors programs:
in0: +3.29 V (crit min = +2.90 V, min = +3.00 V)
(max = +3.60 V, crit max = +3.70 V)
temp1: +33.0°C (low = -5.0°C, high = +80.0°C)
(crit low = -10.0°C, crit = +85.0°C)
power1: 1000.00 nW (max = 794.00 uW, min = 50.00 uW) ALARM (LCRIT)
(lcrit = 40.00 uW, crit = 1000.00 uW)
curr1: +0.00 A (crit min = +0.00 A, min = +0.00 A) ALARM (LCRIT, MIN)
(max = +0.01 A, crit max = +0.01 A)
The scaling sensors performs on the bias current is not particularly
good. The raw values are more useful:
curr1:
curr1_input: 0.000
curr1_min: 0.002
curr1_max: 0.010
curr1_lcrit: 0.000
curr1_crit: 0.011
curr1_min_alarm: 1.000
curr1_max_alarm: 0.000
curr1_lcrit_alarm: 1.000
curr1_crit_alarm: 0.000
In order to keep the I2C overhead to a minimum, the constant values,
such as limits and calibration coefficients are read once at module
insertion time. Thus only reading *_input and *_alarm properties
requires i2c read operations.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-07-18 02:48:13 +07:00
|
|
|
|
|
|
|
for (i = 0; sfp->hwmon_name[i]; i++)
|
|
|
|
if (hwmon_is_bad_char(sfp->hwmon_name[i]))
|
|
|
|
sfp->hwmon_name[i] = '_';
|
|
|
|
|
|
|
|
sfp->hwmon_dev = hwmon_device_register_with_info(sfp->dev,
|
|
|
|
sfp->hwmon_name, sfp,
|
|
|
|
&sfp_hwmon_chip_info,
|
|
|
|
NULL);
|
net: sfp: allow modules with slow diagnostics to probe
When a module is inserted, we attempt to read read the ID from address
0x50. Once we are able to read the ID, we immediately attempt to
initialise the hwmon support by reading from address 0x51. If this
fails, then we fall into error state, and assume that the module is
not usable.
Modules such as the ALCATELLUCENT 3FE46541AA use a real EEPROM for
I2C address 0x50, which responds immediately. However, address 0x51
is an emulated, which only becomes available once the on-board firmware
has booted. This prompts us to fall into the error state.
Since the module may be usable without diagnostics, arrange for the
hwmon probe independent of the rest of the SFP itself, retrying every
5s for up to about 60s for the monitoring to become available, and
print an error message if it doesn't become available.
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-11-10 21:07:35 +07:00
|
|
|
if (IS_ERR(sfp->hwmon_dev))
|
|
|
|
dev_err(sfp->dev, "failed to register hwmon device: %ld\n",
|
|
|
|
PTR_ERR(sfp->hwmon_dev));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sfp_hwmon_insert(struct sfp *sfp)
|
|
|
|
{
|
|
|
|
if (sfp->id.ext.sff8472_compliance == SFP_SFF8472_COMPLIANCE_NONE)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!(sfp->id.ext.diagmon & SFP_DIAGMON_DDM))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (sfp->id.ext.diagmon & SFP_DIAGMON_ADDRMODE)
|
|
|
|
/* This driver in general does not support address
|
|
|
|
* change.
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
mod_delayed_work(system_wq, &sfp->hwmon_probe, 1);
|
|
|
|
sfp->hwmon_tries = R_PROBE_RETRY_SLOW;
|
net: phy: sfp: Add HWMON support for module sensors
SFP modules can contain a number of sensors. The EEPROM also contains
recommended alarm and critical values for each sensor, and indications
of if these have been exceeded. Export this information via
HWMON. Currently temperature, VCC, bias current, transmit power, and
possibly receiver power is supported.
The sensors in the modules can either return calibrate or uncalibrated
values. Uncalibrated values need to be manipulated, using coefficients
provided in the SFP EEPROM. Uncalibrated receive power values require
floating point maths in order to calibrate them. Performing this in
the kernel is hard. So if the SFP module indicates it uses
uncalibrated values, RX power is not made available.
With this hwmon device, it is possible to view the sensor values using
lm-sensors programs:
in0: +3.29 V (crit min = +2.90 V, min = +3.00 V)
(max = +3.60 V, crit max = +3.70 V)
temp1: +33.0°C (low = -5.0°C, high = +80.0°C)
(crit low = -10.0°C, crit = +85.0°C)
power1: 1000.00 nW (max = 794.00 uW, min = 50.00 uW) ALARM (LCRIT)
(lcrit = 40.00 uW, crit = 1000.00 uW)
curr1: +0.00 A (crit min = +0.00 A, min = +0.00 A) ALARM (LCRIT, MIN)
(max = +0.01 A, crit max = +0.01 A)
The scaling sensors performs on the bias current is not particularly
good. The raw values are more useful:
curr1:
curr1_input: 0.000
curr1_min: 0.002
curr1_max: 0.010
curr1_lcrit: 0.000
curr1_crit: 0.011
curr1_min_alarm: 1.000
curr1_max_alarm: 0.000
curr1_lcrit_alarm: 1.000
curr1_crit_alarm: 0.000
In order to keep the I2C overhead to a minimum, the constant values,
such as limits and calibration coefficients are read once at module
insertion time. Thus only reading *_input and *_alarm properties
requires i2c read operations.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-07-18 02:48:13 +07:00
|
|
|
|
net: sfp: allow modules with slow diagnostics to probe
When a module is inserted, we attempt to read read the ID from address
0x50. Once we are able to read the ID, we immediately attempt to
initialise the hwmon support by reading from address 0x51. If this
fails, then we fall into error state, and assume that the module is
not usable.
Modules such as the ALCATELLUCENT 3FE46541AA use a real EEPROM for
I2C address 0x50, which responds immediately. However, address 0x51
is an emulated, which only becomes available once the on-board firmware
has booted. This prompts us to fall into the error state.
Since the module may be usable without diagnostics, arrange for the
hwmon probe independent of the rest of the SFP itself, retrying every
5s for up to about 60s for the monitoring to become available, and
print an error message if it doesn't become available.
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-11-10 21:07:35 +07:00
|
|
|
return 0;
|
net: phy: sfp: Add HWMON support for module sensors
SFP modules can contain a number of sensors. The EEPROM also contains
recommended alarm and critical values for each sensor, and indications
of if these have been exceeded. Export this information via
HWMON. Currently temperature, VCC, bias current, transmit power, and
possibly receiver power is supported.
The sensors in the modules can either return calibrate or uncalibrated
values. Uncalibrated values need to be manipulated, using coefficients
provided in the SFP EEPROM. Uncalibrated receive power values require
floating point maths in order to calibrate them. Performing this in
the kernel is hard. So if the SFP module indicates it uses
uncalibrated values, RX power is not made available.
With this hwmon device, it is possible to view the sensor values using
lm-sensors programs:
in0: +3.29 V (crit min = +2.90 V, min = +3.00 V)
(max = +3.60 V, crit max = +3.70 V)
temp1: +33.0°C (low = -5.0°C, high = +80.0°C)
(crit low = -10.0°C, crit = +85.0°C)
power1: 1000.00 nW (max = 794.00 uW, min = 50.00 uW) ALARM (LCRIT)
(lcrit = 40.00 uW, crit = 1000.00 uW)
curr1: +0.00 A (crit min = +0.00 A, min = +0.00 A) ALARM (LCRIT, MIN)
(max = +0.01 A, crit max = +0.01 A)
The scaling sensors performs on the bias current is not particularly
good. The raw values are more useful:
curr1:
curr1_input: 0.000
curr1_min: 0.002
curr1_max: 0.010
curr1_lcrit: 0.000
curr1_crit: 0.011
curr1_min_alarm: 1.000
curr1_max_alarm: 0.000
curr1_lcrit_alarm: 1.000
curr1_crit_alarm: 0.000
In order to keep the I2C overhead to a minimum, the constant values,
such as limits and calibration coefficients are read once at module
insertion time. Thus only reading *_input and *_alarm properties
requires i2c read operations.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-07-18 02:48:13 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sfp_hwmon_remove(struct sfp *sfp)
|
|
|
|
{
|
net: sfp: allow modules with slow diagnostics to probe
When a module is inserted, we attempt to read read the ID from address
0x50. Once we are able to read the ID, we immediately attempt to
initialise the hwmon support by reading from address 0x51. If this
fails, then we fall into error state, and assume that the module is
not usable.
Modules such as the ALCATELLUCENT 3FE46541AA use a real EEPROM for
I2C address 0x50, which responds immediately. However, address 0x51
is an emulated, which only becomes available once the on-board firmware
has booted. This prompts us to fall into the error state.
Since the module may be usable without diagnostics, arrange for the
hwmon probe independent of the rest of the SFP itself, retrying every
5s for up to about 60s for the monitoring to become available, and
print an error message if it doesn't become available.
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-11-10 21:07:35 +07:00
|
|
|
cancel_delayed_work_sync(&sfp->hwmon_probe);
|
2018-09-25 06:50:00 +07:00
|
|
|
if (!IS_ERR_OR_NULL(sfp->hwmon_dev)) {
|
|
|
|
hwmon_device_unregister(sfp->hwmon_dev);
|
|
|
|
sfp->hwmon_dev = NULL;
|
|
|
|
kfree(sfp->hwmon_name);
|
|
|
|
}
|
net: phy: sfp: Add HWMON support for module sensors
SFP modules can contain a number of sensors. The EEPROM also contains
recommended alarm and critical values for each sensor, and indications
of if these have been exceeded. Export this information via
HWMON. Currently temperature, VCC, bias current, transmit power, and
possibly receiver power is supported.
The sensors in the modules can either return calibrate or uncalibrated
values. Uncalibrated values need to be manipulated, using coefficients
provided in the SFP EEPROM. Uncalibrated receive power values require
floating point maths in order to calibrate them. Performing this in
the kernel is hard. So if the SFP module indicates it uses
uncalibrated values, RX power is not made available.
With this hwmon device, it is possible to view the sensor values using
lm-sensors programs:
in0: +3.29 V (crit min = +2.90 V, min = +3.00 V)
(max = +3.60 V, crit max = +3.70 V)
temp1: +33.0°C (low = -5.0°C, high = +80.0°C)
(crit low = -10.0°C, crit = +85.0°C)
power1: 1000.00 nW (max = 794.00 uW, min = 50.00 uW) ALARM (LCRIT)
(lcrit = 40.00 uW, crit = 1000.00 uW)
curr1: +0.00 A (crit min = +0.00 A, min = +0.00 A) ALARM (LCRIT, MIN)
(max = +0.01 A, crit max = +0.01 A)
The scaling sensors performs on the bias current is not particularly
good. The raw values are more useful:
curr1:
curr1_input: 0.000
curr1_min: 0.002
curr1_max: 0.010
curr1_lcrit: 0.000
curr1_crit: 0.011
curr1_min_alarm: 1.000
curr1_max_alarm: 0.000
curr1_lcrit_alarm: 1.000
curr1_crit_alarm: 0.000
In order to keep the I2C overhead to a minimum, the constant values,
such as limits and calibration coefficients are read once at module
insertion time. Thus only reading *_input and *_alarm properties
requires i2c read operations.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-07-18 02:48:13 +07:00
|
|
|
}
|
net: sfp: allow modules with slow diagnostics to probe
When a module is inserted, we attempt to read read the ID from address
0x50. Once we are able to read the ID, we immediately attempt to
initialise the hwmon support by reading from address 0x51. If this
fails, then we fall into error state, and assume that the module is
not usable.
Modules such as the ALCATELLUCENT 3FE46541AA use a real EEPROM for
I2C address 0x50, which responds immediately. However, address 0x51
is an emulated, which only becomes available once the on-board firmware
has booted. This prompts us to fall into the error state.
Since the module may be usable without diagnostics, arrange for the
hwmon probe independent of the rest of the SFP itself, retrying every
5s for up to about 60s for the monitoring to become available, and
print an error message if it doesn't become available.
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-11-10 21:07:35 +07:00
|
|
|
|
|
|
|
static int sfp_hwmon_init(struct sfp *sfp)
|
|
|
|
{
|
|
|
|
INIT_DELAYED_WORK(&sfp->hwmon_probe, sfp_hwmon_probe);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sfp_hwmon_exit(struct sfp *sfp)
|
|
|
|
{
|
|
|
|
cancel_delayed_work_sync(&sfp->hwmon_probe);
|
|
|
|
}
|
net: phy: sfp: Add HWMON support for module sensors
SFP modules can contain a number of sensors. The EEPROM also contains
recommended alarm and critical values for each sensor, and indications
of if these have been exceeded. Export this information via
HWMON. Currently temperature, VCC, bias current, transmit power, and
possibly receiver power is supported.
The sensors in the modules can either return calibrate or uncalibrated
values. Uncalibrated values need to be manipulated, using coefficients
provided in the SFP EEPROM. Uncalibrated receive power values require
floating point maths in order to calibrate them. Performing this in
the kernel is hard. So if the SFP module indicates it uses
uncalibrated values, RX power is not made available.
With this hwmon device, it is possible to view the sensor values using
lm-sensors programs:
in0: +3.29 V (crit min = +2.90 V, min = +3.00 V)
(max = +3.60 V, crit max = +3.70 V)
temp1: +33.0°C (low = -5.0°C, high = +80.0°C)
(crit low = -10.0°C, crit = +85.0°C)
power1: 1000.00 nW (max = 794.00 uW, min = 50.00 uW) ALARM (LCRIT)
(lcrit = 40.00 uW, crit = 1000.00 uW)
curr1: +0.00 A (crit min = +0.00 A, min = +0.00 A) ALARM (LCRIT, MIN)
(max = +0.01 A, crit max = +0.01 A)
The scaling sensors performs on the bias current is not particularly
good. The raw values are more useful:
curr1:
curr1_input: 0.000
curr1_min: 0.002
curr1_max: 0.010
curr1_lcrit: 0.000
curr1_crit: 0.011
curr1_min_alarm: 1.000
curr1_max_alarm: 0.000
curr1_lcrit_alarm: 1.000
curr1_crit_alarm: 0.000
In order to keep the I2C overhead to a minimum, the constant values,
such as limits and calibration coefficients are read once at module
insertion time. Thus only reading *_input and *_alarm properties
requires i2c read operations.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-07-18 02:48:13 +07:00
|
|
|
#else
|
|
|
|
static int sfp_hwmon_insert(struct sfp *sfp)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sfp_hwmon_remove(struct sfp *sfp)
|
|
|
|
{
|
|
|
|
}
|
net: sfp: allow modules with slow diagnostics to probe
When a module is inserted, we attempt to read read the ID from address
0x50. Once we are able to read the ID, we immediately attempt to
initialise the hwmon support by reading from address 0x51. If this
fails, then we fall into error state, and assume that the module is
not usable.
Modules such as the ALCATELLUCENT 3FE46541AA use a real EEPROM for
I2C address 0x50, which responds immediately. However, address 0x51
is an emulated, which only becomes available once the on-board firmware
has booted. This prompts us to fall into the error state.
Since the module may be usable without diagnostics, arrange for the
hwmon probe independent of the rest of the SFP itself, retrying every
5s for up to about 60s for the monitoring to become available, and
print an error message if it doesn't become available.
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-11-10 21:07:35 +07:00
|
|
|
|
|
|
|
static int sfp_hwmon_init(struct sfp *sfp)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sfp_hwmon_exit(struct sfp *sfp)
|
|
|
|
{
|
|
|
|
}
|
net: phy: sfp: Add HWMON support for module sensors
SFP modules can contain a number of sensors. The EEPROM also contains
recommended alarm and critical values for each sensor, and indications
of if these have been exceeded. Export this information via
HWMON. Currently temperature, VCC, bias current, transmit power, and
possibly receiver power is supported.
The sensors in the modules can either return calibrate or uncalibrated
values. Uncalibrated values need to be manipulated, using coefficients
provided in the SFP EEPROM. Uncalibrated receive power values require
floating point maths in order to calibrate them. Performing this in
the kernel is hard. So if the SFP module indicates it uses
uncalibrated values, RX power is not made available.
With this hwmon device, it is possible to view the sensor values using
lm-sensors programs:
in0: +3.29 V (crit min = +2.90 V, min = +3.00 V)
(max = +3.60 V, crit max = +3.70 V)
temp1: +33.0°C (low = -5.0°C, high = +80.0°C)
(crit low = -10.0°C, crit = +85.0°C)
power1: 1000.00 nW (max = 794.00 uW, min = 50.00 uW) ALARM (LCRIT)
(lcrit = 40.00 uW, crit = 1000.00 uW)
curr1: +0.00 A (crit min = +0.00 A, min = +0.00 A) ALARM (LCRIT, MIN)
(max = +0.01 A, crit max = +0.01 A)
The scaling sensors performs on the bias current is not particularly
good. The raw values are more useful:
curr1:
curr1_input: 0.000
curr1_min: 0.002
curr1_max: 0.010
curr1_lcrit: 0.000
curr1_crit: 0.011
curr1_min_alarm: 1.000
curr1_max_alarm: 0.000
curr1_lcrit_alarm: 1.000
curr1_crit_alarm: 0.000
In order to keep the I2C overhead to a minimum, the constant values,
such as limits and calibration coefficients are read once at module
insertion time. Thus only reading *_input and *_alarm properties
requires i2c read operations.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-07-18 02:48:13 +07:00
|
|
|
#endif
|
|
|
|
|
2017-07-25 21:03:39 +07:00
|
|
|
/* Helpers */
|
|
|
|
static void sfp_module_tx_disable(struct sfp *sfp)
|
|
|
|
{
|
|
|
|
dev_dbg(sfp->dev, "tx disable %u -> %u\n",
|
|
|
|
sfp->state & SFP_F_TX_DISABLE ? 1 : 0, 1);
|
|
|
|
sfp->state |= SFP_F_TX_DISABLE;
|
|
|
|
sfp_set_state(sfp, sfp->state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sfp_module_tx_enable(struct sfp *sfp)
|
|
|
|
{
|
|
|
|
dev_dbg(sfp->dev, "tx disable %u -> %u\n",
|
|
|
|
sfp->state & SFP_F_TX_DISABLE ? 1 : 0, 0);
|
|
|
|
sfp->state &= ~SFP_F_TX_DISABLE;
|
|
|
|
sfp_set_state(sfp, sfp->state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sfp_module_tx_fault_reset(struct sfp *sfp)
|
|
|
|
{
|
|
|
|
unsigned int state = sfp->state;
|
|
|
|
|
|
|
|
if (state & SFP_F_TX_DISABLE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
sfp_set_state(sfp, state | SFP_F_TX_DISABLE);
|
|
|
|
|
|
|
|
udelay(T_RESET_US);
|
|
|
|
|
|
|
|
sfp_set_state(sfp, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* SFP state machine */
|
|
|
|
static void sfp_sm_set_timer(struct sfp *sfp, unsigned int timeout)
|
|
|
|
{
|
|
|
|
if (timeout)
|
|
|
|
mod_delayed_work(system_power_efficient_wq, &sfp->timeout,
|
|
|
|
timeout);
|
|
|
|
else
|
|
|
|
cancel_delayed_work(&sfp->timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sfp_sm_next(struct sfp *sfp, unsigned int state,
|
|
|
|
unsigned int timeout)
|
|
|
|
{
|
|
|
|
sfp->sm_state = state;
|
|
|
|
sfp_sm_set_timer(sfp, timeout);
|
|
|
|
}
|
|
|
|
|
2019-11-10 21:06:23 +07:00
|
|
|
static void sfp_sm_mod_next(struct sfp *sfp, unsigned int state,
|
2017-10-31 11:42:57 +07:00
|
|
|
unsigned int timeout)
|
2017-07-25 21:03:39 +07:00
|
|
|
{
|
|
|
|
sfp->sm_mod_state = state;
|
|
|
|
sfp_sm_set_timer(sfp, timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sfp_sm_phy_detach(struct sfp *sfp)
|
|
|
|
{
|
|
|
|
sfp_remove_phy(sfp->sfp_bus);
|
|
|
|
phy_device_remove(sfp->mod_phy);
|
|
|
|
phy_device_free(sfp->mod_phy);
|
|
|
|
sfp->mod_phy = NULL;
|
|
|
|
}
|
|
|
|
|
2019-12-09 21:16:05 +07:00
|
|
|
static int sfp_sm_probe_phy(struct sfp *sfp, bool is_c45)
|
2017-07-25 21:03:39 +07:00
|
|
|
{
|
|
|
|
struct phy_device *phy;
|
|
|
|
int err;
|
|
|
|
|
2019-12-11 17:57:01 +07:00
|
|
|
phy = get_phy_device(sfp->i2c_mii, SFP_PHY_ADDR, is_c45);
|
2019-12-09 21:16:11 +07:00
|
|
|
if (phy == ERR_PTR(-ENODEV))
|
|
|
|
return PTR_ERR(phy);
|
2017-12-15 23:09:36 +07:00
|
|
|
if (IS_ERR(phy)) {
|
|
|
|
dev_err(sfp->dev, "mdiobus scan returned %ld\n", PTR_ERR(phy));
|
2019-12-09 21:16:05 +07:00
|
|
|
return PTR_ERR(phy);
|
2017-07-25 21:03:39 +07:00
|
|
|
}
|
|
|
|
|
2019-12-11 17:57:01 +07:00
|
|
|
err = phy_device_register(phy);
|
|
|
|
if (err) {
|
|
|
|
phy_device_free(phy);
|
|
|
|
dev_err(sfp->dev, "phy_device_register failed: %d\n", err);
|
2019-12-09 21:16:05 +07:00
|
|
|
return err;
|
2019-12-11 17:57:01 +07:00
|
|
|
}
|
|
|
|
|
2017-07-25 21:03:39 +07:00
|
|
|
err = sfp_add_phy(sfp->sfp_bus, phy);
|
|
|
|
if (err) {
|
|
|
|
phy_device_remove(phy);
|
|
|
|
phy_device_free(phy);
|
|
|
|
dev_err(sfp->dev, "sfp_add_phy failed: %d\n", err);
|
2019-12-09 21:16:05 +07:00
|
|
|
return err;
|
2017-07-25 21:03:39 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
sfp->mod_phy = phy;
|
2019-12-09 21:16:05 +07:00
|
|
|
|
|
|
|
return 0;
|
2017-07-25 21:03:39 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sfp_sm_link_up(struct sfp *sfp)
|
|
|
|
{
|
|
|
|
sfp_link_up(sfp->sfp_bus);
|
|
|
|
sfp_sm_next(sfp, SFP_S_LINK_UP, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sfp_sm_link_down(struct sfp *sfp)
|
|
|
|
{
|
|
|
|
sfp_link_down(sfp->sfp_bus);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sfp_sm_link_check_los(struct sfp *sfp)
|
|
|
|
{
|
|
|
|
unsigned int los = sfp->state & SFP_F_LOS;
|
|
|
|
|
2017-11-30 20:59:16 +07:00
|
|
|
/* If neither SFP_OPTIONS_LOS_INVERTED nor SFP_OPTIONS_LOS_NORMAL
|
|
|
|
* are set, we assume that no LOS signal is available.
|
2017-07-25 21:03:39 +07:00
|
|
|
*/
|
2017-11-30 20:59:11 +07:00
|
|
|
if (sfp->id.ext.options & cpu_to_be16(SFP_OPTIONS_LOS_INVERTED))
|
2017-07-25 21:03:39 +07:00
|
|
|
los ^= SFP_F_LOS;
|
2017-11-30 20:59:16 +07:00
|
|
|
else if (!(sfp->id.ext.options & cpu_to_be16(SFP_OPTIONS_LOS_NORMAL)))
|
|
|
|
los = 0;
|
2017-07-25 21:03:39 +07:00
|
|
|
|
|
|
|
if (los)
|
|
|
|
sfp_sm_next(sfp, SFP_S_WAIT_LOS, 0);
|
|
|
|
else
|
|
|
|
sfp_sm_link_up(sfp);
|
|
|
|
}
|
|
|
|
|
2017-11-30 20:59:16 +07:00
|
|
|
static bool sfp_los_event_active(struct sfp *sfp, unsigned int event)
|
|
|
|
{
|
|
|
|
return (sfp->id.ext.options & cpu_to_be16(SFP_OPTIONS_LOS_INVERTED) &&
|
|
|
|
event == SFP_E_LOS_LOW) ||
|
|
|
|
(sfp->id.ext.options & cpu_to_be16(SFP_OPTIONS_LOS_NORMAL) &&
|
|
|
|
event == SFP_E_LOS_HIGH);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool sfp_los_event_inactive(struct sfp *sfp, unsigned int event)
|
|
|
|
{
|
|
|
|
return (sfp->id.ext.options & cpu_to_be16(SFP_OPTIONS_LOS_INVERTED) &&
|
|
|
|
event == SFP_E_LOS_HIGH) ||
|
|
|
|
(sfp->id.ext.options & cpu_to_be16(SFP_OPTIONS_LOS_NORMAL) &&
|
|
|
|
event == SFP_E_LOS_LOW);
|
|
|
|
}
|
|
|
|
|
2019-11-10 21:07:04 +07:00
|
|
|
static void sfp_sm_fault(struct sfp *sfp, unsigned int next_state, bool warn)
|
2017-07-25 21:03:39 +07:00
|
|
|
{
|
2019-12-09 21:16:00 +07:00
|
|
|
if (sfp->sm_fault_retries && !--sfp->sm_fault_retries) {
|
2017-10-31 11:42:57 +07:00
|
|
|
dev_err(sfp->dev,
|
|
|
|
"module persistently indicates fault, disabling\n");
|
2017-07-25 21:03:39 +07:00
|
|
|
sfp_sm_next(sfp, SFP_S_TX_DISABLE, 0);
|
|
|
|
} else {
|
|
|
|
if (warn)
|
|
|
|
dev_err(sfp->dev, "module transmit fault indicated\n");
|
|
|
|
|
2019-11-10 21:07:04 +07:00
|
|
|
sfp_sm_next(sfp, next_state, T_FAULT_RECOVER);
|
2017-07-25 21:03:39 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-11 17:57:01 +07:00
|
|
|
/* Probe a SFP for a PHY device if the module supports copper - the PHY
|
|
|
|
* normally sits at I2C bus address 0x56, and may either be a clause 22
|
|
|
|
* or clause 45 PHY.
|
|
|
|
*
|
|
|
|
* Clause 22 copper SFP modules normally operate in Cisco SGMII mode with
|
|
|
|
* negotiation enabled, but some may be in 1000base-X - which is for the
|
|
|
|
* PHY driver to determine.
|
|
|
|
*
|
|
|
|
* Clause 45 copper SFP+ modules (10G) appear to switch their interface
|
|
|
|
* mode according to the negotiated line speed.
|
|
|
|
*/
|
2019-12-09 21:16:05 +07:00
|
|
|
static int sfp_sm_probe_for_phy(struct sfp *sfp)
|
2019-11-10 21:06:54 +07:00
|
|
|
{
|
2019-12-09 21:16:05 +07:00
|
|
|
int err = 0;
|
|
|
|
|
2019-12-11 17:57:01 +07:00
|
|
|
switch (sfp->id.base.extended_cc) {
|
|
|
|
case SFF8024_ECC_10GBASE_T_SFI:
|
|
|
|
case SFF8024_ECC_10GBASE_T_SR:
|
|
|
|
case SFF8024_ECC_5GBASE_T:
|
|
|
|
case SFF8024_ECC_2_5GBASE_T:
|
2019-12-09 21:16:05 +07:00
|
|
|
err = sfp_sm_probe_phy(sfp, true);
|
2019-12-11 17:57:01 +07:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (sfp->id.base.e1000_base_t)
|
2019-12-09 21:16:05 +07:00
|
|
|
err = sfp_sm_probe_phy(sfp, false);
|
2019-12-11 17:57:01 +07:00
|
|
|
break;
|
|
|
|
}
|
2019-12-09 21:16:05 +07:00
|
|
|
return err;
|
2017-07-25 21:03:39 +07:00
|
|
|
}
|
|
|
|
|
2019-11-10 21:06:39 +07:00
|
|
|
static int sfp_module_parse_power(struct sfp *sfp)
|
sfp: add high power module support
This patch is the result of work by both Jon Nettleton and Russell King.
Jon wrote the original patch, adding support for SFP modules which
require a power level greater than '1'.
Russell's changes:
- Fix the power levels for big-endian, and make the code flow better.
- Convert to use device_property_read_u8()
- Warn for power levels exceeding host level
SFF-8431 says:
"To avoid exceeding system power supply limits and cooling capacity,
all modules at power up by default shall operate with up to 1.0 W.
Hosts supporting Power Level II or III operation may enable a Power
Level II or III module through the 2-wire interface. Power Level II
or III modules shall assert the power level declaration bit of
SFF-8472."
Print a warning for modules that exceed the host power level, and
leave them operating in power level 1.
- Fix i2c write
The first byte of any write after the bus address is always the
device address. In order to write a value to device D, address I,
value V, we need to generate on the bus:
S DDDDDDDD A IIIIIIII A VVVVVVVV A P
where S = start, R = restart, A = ack, P = stop. Splitting this
as two:
S DDDDDDDD A IIIIIIII A R DDDDDDDD A VVVVVVVV A P
results in the device's address register being written first by I
and then by V - the addressed register within the device is not
written.
- Avoid power mode switching if 0xa2 is not implemented
Some modules indicate that they support power level II or power level
III, but do not implement address 0xa2, meaning that the bit to set
them to high power mode is not accessible.
These modules appear to have the sff8472_compliance field set to zero,
and also do not implement diagnostics. Detect this, but also ensure
that the module does not require the address switching mode, which we
do not implement.
- Use mW for power level rather than power level number.
- Fix high power mode transition
We must not switch to SFP_MOD_PRESENT state until we have finished
initialising, because the remaining state machines check for that
state. Add SFP_MOD_HPOWER as an intermediate state.
- Use definition for I2C register address rather than constant.
Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-02-27 22:53:12 +07:00
|
|
|
{
|
2019-11-10 21:06:39 +07:00
|
|
|
u32 power_mW = 1000;
|
sfp: add high power module support
This patch is the result of work by both Jon Nettleton and Russell King.
Jon wrote the original patch, adding support for SFP modules which
require a power level greater than '1'.
Russell's changes:
- Fix the power levels for big-endian, and make the code flow better.
- Convert to use device_property_read_u8()
- Warn for power levels exceeding host level
SFF-8431 says:
"To avoid exceeding system power supply limits and cooling capacity,
all modules at power up by default shall operate with up to 1.0 W.
Hosts supporting Power Level II or III operation may enable a Power
Level II or III module through the 2-wire interface. Power Level II
or III modules shall assert the power level declaration bit of
SFF-8472."
Print a warning for modules that exceed the host power level, and
leave them operating in power level 1.
- Fix i2c write
The first byte of any write after the bus address is always the
device address. In order to write a value to device D, address I,
value V, we need to generate on the bus:
S DDDDDDDD A IIIIIIII A VVVVVVVV A P
where S = start, R = restart, A = ack, P = stop. Splitting this
as two:
S DDDDDDDD A IIIIIIII A R DDDDDDDD A VVVVVVVV A P
results in the device's address register being written first by I
and then by V - the addressed register within the device is not
written.
- Avoid power mode switching if 0xa2 is not implemented
Some modules indicate that they support power level II or power level
III, but do not implement address 0xa2, meaning that the bit to set
them to high power mode is not accessible.
These modules appear to have the sff8472_compliance field set to zero,
and also do not implement diagnostics. Detect this, but also ensure
that the module does not require the address switching mode, which we
do not implement.
- Use mW for power level rather than power level number.
- Fix high power mode transition
We must not switch to SFP_MOD_PRESENT state until we have finished
initialising, because the remaining state machines check for that
state. Add SFP_MOD_HPOWER as an intermediate state.
- Use definition for I2C register address rather than constant.
Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-02-27 22:53:12 +07:00
|
|
|
|
|
|
|
if (sfp->id.ext.options & cpu_to_be16(SFP_OPTIONS_POWER_DECL))
|
2019-11-10 21:06:39 +07:00
|
|
|
power_mW = 1500;
|
sfp: add high power module support
This patch is the result of work by both Jon Nettleton and Russell King.
Jon wrote the original patch, adding support for SFP modules which
require a power level greater than '1'.
Russell's changes:
- Fix the power levels for big-endian, and make the code flow better.
- Convert to use device_property_read_u8()
- Warn for power levels exceeding host level
SFF-8431 says:
"To avoid exceeding system power supply limits and cooling capacity,
all modules at power up by default shall operate with up to 1.0 W.
Hosts supporting Power Level II or III operation may enable a Power
Level II or III module through the 2-wire interface. Power Level II
or III modules shall assert the power level declaration bit of
SFF-8472."
Print a warning for modules that exceed the host power level, and
leave them operating in power level 1.
- Fix i2c write
The first byte of any write after the bus address is always the
device address. In order to write a value to device D, address I,
value V, we need to generate on the bus:
S DDDDDDDD A IIIIIIII A VVVVVVVV A P
where S = start, R = restart, A = ack, P = stop. Splitting this
as two:
S DDDDDDDD A IIIIIIII A R DDDDDDDD A VVVVVVVV A P
results in the device's address register being written first by I
and then by V - the addressed register within the device is not
written.
- Avoid power mode switching if 0xa2 is not implemented
Some modules indicate that they support power level II or power level
III, but do not implement address 0xa2, meaning that the bit to set
them to high power mode is not accessible.
These modules appear to have the sff8472_compliance field set to zero,
and also do not implement diagnostics. Detect this, but also ensure
that the module does not require the address switching mode, which we
do not implement.
- Use mW for power level rather than power level number.
- Fix high power mode transition
We must not switch to SFP_MOD_PRESENT state until we have finished
initialising, because the remaining state machines check for that
state. Add SFP_MOD_HPOWER as an intermediate state.
- Use definition for I2C register address rather than constant.
Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-02-27 22:53:12 +07:00
|
|
|
if (sfp->id.ext.options & cpu_to_be16(SFP_OPTIONS_HIGH_POWER_LEVEL))
|
2019-11-10 21:06:39 +07:00
|
|
|
power_mW = 2000;
|
sfp: add high power module support
This patch is the result of work by both Jon Nettleton and Russell King.
Jon wrote the original patch, adding support for SFP modules which
require a power level greater than '1'.
Russell's changes:
- Fix the power levels for big-endian, and make the code flow better.
- Convert to use device_property_read_u8()
- Warn for power levels exceeding host level
SFF-8431 says:
"To avoid exceeding system power supply limits and cooling capacity,
all modules at power up by default shall operate with up to 1.0 W.
Hosts supporting Power Level II or III operation may enable a Power
Level II or III module through the 2-wire interface. Power Level II
or III modules shall assert the power level declaration bit of
SFF-8472."
Print a warning for modules that exceed the host power level, and
leave them operating in power level 1.
- Fix i2c write
The first byte of any write after the bus address is always the
device address. In order to write a value to device D, address I,
value V, we need to generate on the bus:
S DDDDDDDD A IIIIIIII A VVVVVVVV A P
where S = start, R = restart, A = ack, P = stop. Splitting this
as two:
S DDDDDDDD A IIIIIIII A R DDDDDDDD A VVVVVVVV A P
results in the device's address register being written first by I
and then by V - the addressed register within the device is not
written.
- Avoid power mode switching if 0xa2 is not implemented
Some modules indicate that they support power level II or power level
III, but do not implement address 0xa2, meaning that the bit to set
them to high power mode is not accessible.
These modules appear to have the sff8472_compliance field set to zero,
and also do not implement diagnostics. Detect this, but also ensure
that the module does not require the address switching mode, which we
do not implement.
- Use mW for power level rather than power level number.
- Fix high power mode transition
We must not switch to SFP_MOD_PRESENT state until we have finished
initialising, because the remaining state machines check for that
state. Add SFP_MOD_HPOWER as an intermediate state.
- Use definition for I2C register address rather than constant.
Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-02-27 22:53:12 +07:00
|
|
|
|
2019-11-10 21:06:44 +07:00
|
|
|
if (power_mW > sfp->max_power_mW) {
|
|
|
|
/* Module power specification exceeds the allowed maximum. */
|
|
|
|
if (sfp->id.ext.sff8472_compliance ==
|
|
|
|
SFP_SFF8472_COMPLIANCE_NONE &&
|
|
|
|
!(sfp->id.ext.diagmon & SFP_DIAGMON_DDM)) {
|
|
|
|
/* The module appears not to implement bus address
|
|
|
|
* 0xa2, so assume that the module powers up in the
|
|
|
|
* indicated mode.
|
|
|
|
*/
|
sfp: add high power module support
This patch is the result of work by both Jon Nettleton and Russell King.
Jon wrote the original patch, adding support for SFP modules which
require a power level greater than '1'.
Russell's changes:
- Fix the power levels for big-endian, and make the code flow better.
- Convert to use device_property_read_u8()
- Warn for power levels exceeding host level
SFF-8431 says:
"To avoid exceeding system power supply limits and cooling capacity,
all modules at power up by default shall operate with up to 1.0 W.
Hosts supporting Power Level II or III operation may enable a Power
Level II or III module through the 2-wire interface. Power Level II
or III modules shall assert the power level declaration bit of
SFF-8472."
Print a warning for modules that exceed the host power level, and
leave them operating in power level 1.
- Fix i2c write
The first byte of any write after the bus address is always the
device address. In order to write a value to device D, address I,
value V, we need to generate on the bus:
S DDDDDDDD A IIIIIIII A VVVVVVVV A P
where S = start, R = restart, A = ack, P = stop. Splitting this
as two:
S DDDDDDDD A IIIIIIII A R DDDDDDDD A VVVVVVVV A P
results in the device's address register being written first by I
and then by V - the addressed register within the device is not
written.
- Avoid power mode switching if 0xa2 is not implemented
Some modules indicate that they support power level II or power level
III, but do not implement address 0xa2, meaning that the bit to set
them to high power mode is not accessible.
These modules appear to have the sff8472_compliance field set to zero,
and also do not implement diagnostics. Detect this, but also ensure
that the module does not require the address switching mode, which we
do not implement.
- Use mW for power level rather than power level number.
- Fix high power mode transition
We must not switch to SFP_MOD_PRESENT state until we have finished
initialising, because the remaining state machines check for that
state. Add SFP_MOD_HPOWER as an intermediate state.
- Use definition for I2C register address rather than constant.
Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-02-27 22:53:12 +07:00
|
|
|
dev_err(sfp->dev,
|
|
|
|
"Host does not support %u.%uW modules\n",
|
2019-11-10 21:06:39 +07:00
|
|
|
power_mW / 1000, (power_mW / 100) % 10);
|
sfp: add high power module support
This patch is the result of work by both Jon Nettleton and Russell King.
Jon wrote the original patch, adding support for SFP modules which
require a power level greater than '1'.
Russell's changes:
- Fix the power levels for big-endian, and make the code flow better.
- Convert to use device_property_read_u8()
- Warn for power levels exceeding host level
SFF-8431 says:
"To avoid exceeding system power supply limits and cooling capacity,
all modules at power up by default shall operate with up to 1.0 W.
Hosts supporting Power Level II or III operation may enable a Power
Level II or III module through the 2-wire interface. Power Level II
or III modules shall assert the power level declaration bit of
SFF-8472."
Print a warning for modules that exceed the host power level, and
leave them operating in power level 1.
- Fix i2c write
The first byte of any write after the bus address is always the
device address. In order to write a value to device D, address I,
value V, we need to generate on the bus:
S DDDDDDDD A IIIIIIII A VVVVVVVV A P
where S = start, R = restart, A = ack, P = stop. Splitting this
as two:
S DDDDDDDD A IIIIIIII A R DDDDDDDD A VVVVVVVV A P
results in the device's address register being written first by I
and then by V - the addressed register within the device is not
written.
- Avoid power mode switching if 0xa2 is not implemented
Some modules indicate that they support power level II or power level
III, but do not implement address 0xa2, meaning that the bit to set
them to high power mode is not accessible.
These modules appear to have the sff8472_compliance field set to zero,
and also do not implement diagnostics. Detect this, but also ensure
that the module does not require the address switching mode, which we
do not implement.
- Use mW for power level rather than power level number.
- Fix high power mode transition
We must not switch to SFP_MOD_PRESENT state until we have finished
initialising, because the remaining state machines check for that
state. Add SFP_MOD_HPOWER as an intermediate state.
- Use definition for I2C register address rather than constant.
Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-02-27 22:53:12 +07:00
|
|
|
return -EINVAL;
|
2019-11-10 21:06:44 +07:00
|
|
|
} else {
|
|
|
|
dev_warn(sfp->dev,
|
|
|
|
"Host does not support %u.%uW modules, module left in power mode 1\n",
|
|
|
|
power_mW / 1000, (power_mW / 100) % 10);
|
|
|
|
return 0;
|
sfp: add high power module support
This patch is the result of work by both Jon Nettleton and Russell King.
Jon wrote the original patch, adding support for SFP modules which
require a power level greater than '1'.
Russell's changes:
- Fix the power levels for big-endian, and make the code flow better.
- Convert to use device_property_read_u8()
- Warn for power levels exceeding host level
SFF-8431 says:
"To avoid exceeding system power supply limits and cooling capacity,
all modules at power up by default shall operate with up to 1.0 W.
Hosts supporting Power Level II or III operation may enable a Power
Level II or III module through the 2-wire interface. Power Level II
or III modules shall assert the power level declaration bit of
SFF-8472."
Print a warning for modules that exceed the host power level, and
leave them operating in power level 1.
- Fix i2c write
The first byte of any write after the bus address is always the
device address. In order to write a value to device D, address I,
value V, we need to generate on the bus:
S DDDDDDDD A IIIIIIII A VVVVVVVV A P
where S = start, R = restart, A = ack, P = stop. Splitting this
as two:
S DDDDDDDD A IIIIIIII A R DDDDDDDD A VVVVVVVV A P
results in the device's address register being written first by I
and then by V - the addressed register within the device is not
written.
- Avoid power mode switching if 0xa2 is not implemented
Some modules indicate that they support power level II or power level
III, but do not implement address 0xa2, meaning that the bit to set
them to high power mode is not accessible.
These modules appear to have the sff8472_compliance field set to zero,
and also do not implement diagnostics. Detect this, but also ensure
that the module does not require the address switching mode, which we
do not implement.
- Use mW for power level rather than power level number.
- Fix high power mode transition
We must not switch to SFP_MOD_PRESENT state until we have finished
initialising, because the remaining state machines check for that
state. Add SFP_MOD_HPOWER as an intermediate state.
- Use definition for I2C register address rather than constant.
Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-02-27 22:53:12 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-10 21:06:44 +07:00
|
|
|
/* If the module requires a higher power mode, but also requires
|
|
|
|
* an address change sequence, warn the user that the module may
|
|
|
|
* not be functional.
|
|
|
|
*/
|
|
|
|
if (sfp->id.ext.diagmon & SFP_DIAGMON_ADDRMODE && power_mW > 1000) {
|
sfp: add high power module support
This patch is the result of work by both Jon Nettleton and Russell King.
Jon wrote the original patch, adding support for SFP modules which
require a power level greater than '1'.
Russell's changes:
- Fix the power levels for big-endian, and make the code flow better.
- Convert to use device_property_read_u8()
- Warn for power levels exceeding host level
SFF-8431 says:
"To avoid exceeding system power supply limits and cooling capacity,
all modules at power up by default shall operate with up to 1.0 W.
Hosts supporting Power Level II or III operation may enable a Power
Level II or III module through the 2-wire interface. Power Level II
or III modules shall assert the power level declaration bit of
SFF-8472."
Print a warning for modules that exceed the host power level, and
leave them operating in power level 1.
- Fix i2c write
The first byte of any write after the bus address is always the
device address. In order to write a value to device D, address I,
value V, we need to generate on the bus:
S DDDDDDDD A IIIIIIII A VVVVVVVV A P
where S = start, R = restart, A = ack, P = stop. Splitting this
as two:
S DDDDDDDD A IIIIIIII A R DDDDDDDD A VVVVVVVV A P
results in the device's address register being written first by I
and then by V - the addressed register within the device is not
written.
- Avoid power mode switching if 0xa2 is not implemented
Some modules indicate that they support power level II or power level
III, but do not implement address 0xa2, meaning that the bit to set
them to high power mode is not accessible.
These modules appear to have the sff8472_compliance field set to zero,
and also do not implement diagnostics. Detect this, but also ensure
that the module does not require the address switching mode, which we
do not implement.
- Use mW for power level rather than power level number.
- Fix high power mode transition
We must not switch to SFP_MOD_PRESENT state until we have finished
initialising, because the remaining state machines check for that
state. Add SFP_MOD_HPOWER as an intermediate state.
- Use definition for I2C register address rather than constant.
Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-02-27 22:53:12 +07:00
|
|
|
dev_warn(sfp->dev,
|
2019-11-13 16:55:48 +07:00
|
|
|
"Address Change Sequence not supported but module requires %u.%uW, module may not be functional\n",
|
2019-11-10 21:06:39 +07:00
|
|
|
power_mW / 1000, (power_mW / 100) % 10);
|
sfp: add high power module support
This patch is the result of work by both Jon Nettleton and Russell King.
Jon wrote the original patch, adding support for SFP modules which
require a power level greater than '1'.
Russell's changes:
- Fix the power levels for big-endian, and make the code flow better.
- Convert to use device_property_read_u8()
- Warn for power levels exceeding host level
SFF-8431 says:
"To avoid exceeding system power supply limits and cooling capacity,
all modules at power up by default shall operate with up to 1.0 W.
Hosts supporting Power Level II or III operation may enable a Power
Level II or III module through the 2-wire interface. Power Level II
or III modules shall assert the power level declaration bit of
SFF-8472."
Print a warning for modules that exceed the host power level, and
leave them operating in power level 1.
- Fix i2c write
The first byte of any write after the bus address is always the
device address. In order to write a value to device D, address I,
value V, we need to generate on the bus:
S DDDDDDDD A IIIIIIII A VVVVVVVV A P
where S = start, R = restart, A = ack, P = stop. Splitting this
as two:
S DDDDDDDD A IIIIIIII A R DDDDDDDD A VVVVVVVV A P
results in the device's address register being written first by I
and then by V - the addressed register within the device is not
written.
- Avoid power mode switching if 0xa2 is not implemented
Some modules indicate that they support power level II or power level
III, but do not implement address 0xa2, meaning that the bit to set
them to high power mode is not accessible.
These modules appear to have the sff8472_compliance field set to zero,
and also do not implement diagnostics. Detect this, but also ensure
that the module does not require the address switching mode, which we
do not implement.
- Use mW for power level rather than power level number.
- Fix high power mode transition
We must not switch to SFP_MOD_PRESENT state until we have finished
initialising, because the remaining state machines check for that
state. Add SFP_MOD_HPOWER as an intermediate state.
- Use definition for I2C register address rather than constant.
Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-02-27 22:53:12 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-11-10 21:06:39 +07:00
|
|
|
sfp->module_power_mW = power_mW;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-11-10 21:07:20 +07:00
|
|
|
static int sfp_sm_mod_hpower(struct sfp *sfp, bool enable)
|
2019-11-10 21:06:39 +07:00
|
|
|
{
|
|
|
|
u8 val;
|
|
|
|
int err;
|
|
|
|
|
sfp: add high power module support
This patch is the result of work by both Jon Nettleton and Russell King.
Jon wrote the original patch, adding support for SFP modules which
require a power level greater than '1'.
Russell's changes:
- Fix the power levels for big-endian, and make the code flow better.
- Convert to use device_property_read_u8()
- Warn for power levels exceeding host level
SFF-8431 says:
"To avoid exceeding system power supply limits and cooling capacity,
all modules at power up by default shall operate with up to 1.0 W.
Hosts supporting Power Level II or III operation may enable a Power
Level II or III module through the 2-wire interface. Power Level II
or III modules shall assert the power level declaration bit of
SFF-8472."
Print a warning for modules that exceed the host power level, and
leave them operating in power level 1.
- Fix i2c write
The first byte of any write after the bus address is always the
device address. In order to write a value to device D, address I,
value V, we need to generate on the bus:
S DDDDDDDD A IIIIIIII A VVVVVVVV A P
where S = start, R = restart, A = ack, P = stop. Splitting this
as two:
S DDDDDDDD A IIIIIIII A R DDDDDDDD A VVVVVVVV A P
results in the device's address register being written first by I
and then by V - the addressed register within the device is not
written.
- Avoid power mode switching if 0xa2 is not implemented
Some modules indicate that they support power level II or power level
III, but do not implement address 0xa2, meaning that the bit to set
them to high power mode is not accessible.
These modules appear to have the sff8472_compliance field set to zero,
and also do not implement diagnostics. Detect this, but also ensure
that the module does not require the address switching mode, which we
do not implement.
- Use mW for power level rather than power level number.
- Fix high power mode transition
We must not switch to SFP_MOD_PRESENT state until we have finished
initialising, because the remaining state machines check for that
state. Add SFP_MOD_HPOWER as an intermediate state.
- Use definition for I2C register address rather than constant.
Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-02-27 22:53:12 +07:00
|
|
|
err = sfp_read(sfp, true, SFP_EXT_STATUS, &val, sizeof(val));
|
|
|
|
if (err != sizeof(val)) {
|
|
|
|
dev_err(sfp->dev, "Failed to read EEPROM: %d\n", err);
|
2019-11-10 21:07:20 +07:00
|
|
|
return -EAGAIN;
|
sfp: add high power module support
This patch is the result of work by both Jon Nettleton and Russell King.
Jon wrote the original patch, adding support for SFP modules which
require a power level greater than '1'.
Russell's changes:
- Fix the power levels for big-endian, and make the code flow better.
- Convert to use device_property_read_u8()
- Warn for power levels exceeding host level
SFF-8431 says:
"To avoid exceeding system power supply limits and cooling capacity,
all modules at power up by default shall operate with up to 1.0 W.
Hosts supporting Power Level II or III operation may enable a Power
Level II or III module through the 2-wire interface. Power Level II
or III modules shall assert the power level declaration bit of
SFF-8472."
Print a warning for modules that exceed the host power level, and
leave them operating in power level 1.
- Fix i2c write
The first byte of any write after the bus address is always the
device address. In order to write a value to device D, address I,
value V, we need to generate on the bus:
S DDDDDDDD A IIIIIIII A VVVVVVVV A P
where S = start, R = restart, A = ack, P = stop. Splitting this
as two:
S DDDDDDDD A IIIIIIII A R DDDDDDDD A VVVVVVVV A P
results in the device's address register being written first by I
and then by V - the addressed register within the device is not
written.
- Avoid power mode switching if 0xa2 is not implemented
Some modules indicate that they support power level II or power level
III, but do not implement address 0xa2, meaning that the bit to set
them to high power mode is not accessible.
These modules appear to have the sff8472_compliance field set to zero,
and also do not implement diagnostics. Detect this, but also ensure
that the module does not require the address switching mode, which we
do not implement.
- Use mW for power level rather than power level number.
- Fix high power mode transition
We must not switch to SFP_MOD_PRESENT state until we have finished
initialising, because the remaining state machines check for that
state. Add SFP_MOD_HPOWER as an intermediate state.
- Use definition for I2C register address rather than constant.
Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-02-27 22:53:12 +07:00
|
|
|
}
|
|
|
|
|
2019-12-11 17:57:01 +07:00
|
|
|
/* DM7052 reports as a high power module, responds to reads (with
|
|
|
|
* all bytes 0xff) at 0x51 but does not accept writes. In any case,
|
|
|
|
* if the bit is already set, we're already in high power mode.
|
|
|
|
*/
|
|
|
|
if (!!(val & BIT(0)) == enable)
|
|
|
|
return 0;
|
|
|
|
|
2019-11-10 21:07:20 +07:00
|
|
|
if (enable)
|
|
|
|
val |= BIT(0);
|
|
|
|
else
|
|
|
|
val &= ~BIT(0);
|
sfp: add high power module support
This patch is the result of work by both Jon Nettleton and Russell King.
Jon wrote the original patch, adding support for SFP modules which
require a power level greater than '1'.
Russell's changes:
- Fix the power levels for big-endian, and make the code flow better.
- Convert to use device_property_read_u8()
- Warn for power levels exceeding host level
SFF-8431 says:
"To avoid exceeding system power supply limits and cooling capacity,
all modules at power up by default shall operate with up to 1.0 W.
Hosts supporting Power Level II or III operation may enable a Power
Level II or III module through the 2-wire interface. Power Level II
or III modules shall assert the power level declaration bit of
SFF-8472."
Print a warning for modules that exceed the host power level, and
leave them operating in power level 1.
- Fix i2c write
The first byte of any write after the bus address is always the
device address. In order to write a value to device D, address I,
value V, we need to generate on the bus:
S DDDDDDDD A IIIIIIII A VVVVVVVV A P
where S = start, R = restart, A = ack, P = stop. Splitting this
as two:
S DDDDDDDD A IIIIIIII A R DDDDDDDD A VVVVVVVV A P
results in the device's address register being written first by I
and then by V - the addressed register within the device is not
written.
- Avoid power mode switching if 0xa2 is not implemented
Some modules indicate that they support power level II or power level
III, but do not implement address 0xa2, meaning that the bit to set
them to high power mode is not accessible.
These modules appear to have the sff8472_compliance field set to zero,
and also do not implement diagnostics. Detect this, but also ensure
that the module does not require the address switching mode, which we
do not implement.
- Use mW for power level rather than power level number.
- Fix high power mode transition
We must not switch to SFP_MOD_PRESENT state until we have finished
initialising, because the remaining state machines check for that
state. Add SFP_MOD_HPOWER as an intermediate state.
- Use definition for I2C register address rather than constant.
Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-02-27 22:53:12 +07:00
|
|
|
|
|
|
|
err = sfp_write(sfp, true, SFP_EXT_STATUS, &val, sizeof(val));
|
|
|
|
if (err != sizeof(val)) {
|
|
|
|
dev_err(sfp->dev, "Failed to write EEPROM: %d\n", err);
|
2019-11-10 21:07:20 +07:00
|
|
|
return -EAGAIN;
|
sfp: add high power module support
This patch is the result of work by both Jon Nettleton and Russell King.
Jon wrote the original patch, adding support for SFP modules which
require a power level greater than '1'.
Russell's changes:
- Fix the power levels for big-endian, and make the code flow better.
- Convert to use device_property_read_u8()
- Warn for power levels exceeding host level
SFF-8431 says:
"To avoid exceeding system power supply limits and cooling capacity,
all modules at power up by default shall operate with up to 1.0 W.
Hosts supporting Power Level II or III operation may enable a Power
Level II or III module through the 2-wire interface. Power Level II
or III modules shall assert the power level declaration bit of
SFF-8472."
Print a warning for modules that exceed the host power level, and
leave them operating in power level 1.
- Fix i2c write
The first byte of any write after the bus address is always the
device address. In order to write a value to device D, address I,
value V, we need to generate on the bus:
S DDDDDDDD A IIIIIIII A VVVVVVVV A P
where S = start, R = restart, A = ack, P = stop. Splitting this
as two:
S DDDDDDDD A IIIIIIII A R DDDDDDDD A VVVVVVVV A P
results in the device's address register being written first by I
and then by V - the addressed register within the device is not
written.
- Avoid power mode switching if 0xa2 is not implemented
Some modules indicate that they support power level II or power level
III, but do not implement address 0xa2, meaning that the bit to set
them to high power mode is not accessible.
These modules appear to have the sff8472_compliance field set to zero,
and also do not implement diagnostics. Detect this, but also ensure
that the module does not require the address switching mode, which we
do not implement.
- Use mW for power level rather than power level number.
- Fix high power mode transition
We must not switch to SFP_MOD_PRESENT state until we have finished
initialising, because the remaining state machines check for that
state. Add SFP_MOD_HPOWER as an intermediate state.
- Use definition for I2C register address rather than constant.
Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-02-27 22:53:12 +07:00
|
|
|
}
|
|
|
|
|
2019-11-10 21:07:20 +07:00
|
|
|
if (enable)
|
|
|
|
dev_info(sfp->dev, "Module switched to %u.%uW power level\n",
|
|
|
|
sfp->module_power_mW / 1000,
|
|
|
|
(sfp->module_power_mW / 100) % 10);
|
sfp: add high power module support
This patch is the result of work by both Jon Nettleton and Russell King.
Jon wrote the original patch, adding support for SFP modules which
require a power level greater than '1'.
Russell's changes:
- Fix the power levels for big-endian, and make the code flow better.
- Convert to use device_property_read_u8()
- Warn for power levels exceeding host level
SFF-8431 says:
"To avoid exceeding system power supply limits and cooling capacity,
all modules at power up by default shall operate with up to 1.0 W.
Hosts supporting Power Level II or III operation may enable a Power
Level II or III module through the 2-wire interface. Power Level II
or III modules shall assert the power level declaration bit of
SFF-8472."
Print a warning for modules that exceed the host power level, and
leave them operating in power level 1.
- Fix i2c write
The first byte of any write after the bus address is always the
device address. In order to write a value to device D, address I,
value V, we need to generate on the bus:
S DDDDDDDD A IIIIIIII A VVVVVVVV A P
where S = start, R = restart, A = ack, P = stop. Splitting this
as two:
S DDDDDDDD A IIIIIIII A R DDDDDDDD A VVVVVVVV A P
results in the device's address register being written first by I
and then by V - the addressed register within the device is not
written.
- Avoid power mode switching if 0xa2 is not implemented
Some modules indicate that they support power level II or power level
III, but do not implement address 0xa2, meaning that the bit to set
them to high power mode is not accessible.
These modules appear to have the sff8472_compliance field set to zero,
and also do not implement diagnostics. Detect this, but also ensure
that the module does not require the address switching mode, which we
do not implement.
- Use mW for power level rather than power level number.
- Fix high power mode transition
We must not switch to SFP_MOD_PRESENT state until we have finished
initialising, because the remaining state machines check for that
state. Add SFP_MOD_HPOWER as an intermediate state.
- Use definition for I2C register address rather than constant.
Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-02-27 22:53:12 +07:00
|
|
|
|
2019-11-10 21:07:20 +07:00
|
|
|
return 0;
|
sfp: add high power module support
This patch is the result of work by both Jon Nettleton and Russell King.
Jon wrote the original patch, adding support for SFP modules which
require a power level greater than '1'.
Russell's changes:
- Fix the power levels for big-endian, and make the code flow better.
- Convert to use device_property_read_u8()
- Warn for power levels exceeding host level
SFF-8431 says:
"To avoid exceeding system power supply limits and cooling capacity,
all modules at power up by default shall operate with up to 1.0 W.
Hosts supporting Power Level II or III operation may enable a Power
Level II or III module through the 2-wire interface. Power Level II
or III modules shall assert the power level declaration bit of
SFF-8472."
Print a warning for modules that exceed the host power level, and
leave them operating in power level 1.
- Fix i2c write
The first byte of any write after the bus address is always the
device address. In order to write a value to device D, address I,
value V, we need to generate on the bus:
S DDDDDDDD A IIIIIIII A VVVVVVVV A P
where S = start, R = restart, A = ack, P = stop. Splitting this
as two:
S DDDDDDDD A IIIIIIII A R DDDDDDDD A VVVVVVVV A P
results in the device's address register being written first by I
and then by V - the addressed register within the device is not
written.
- Avoid power mode switching if 0xa2 is not implemented
Some modules indicate that they support power level II or power level
III, but do not implement address 0xa2, meaning that the bit to set
them to high power mode is not accessible.
These modules appear to have the sff8472_compliance field set to zero,
and also do not implement diagnostics. Detect this, but also ensure
that the module does not require the address switching mode, which we
do not implement.
- Use mW for power level rather than power level number.
- Fix high power mode transition
We must not switch to SFP_MOD_PRESENT state until we have finished
initialising, because the remaining state machines check for that
state. Add SFP_MOD_HPOWER as an intermediate state.
- Use definition for I2C register address rather than constant.
Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-02-27 22:53:12 +07:00
|
|
|
}
|
|
|
|
|
2019-11-10 21:07:30 +07:00
|
|
|
static int sfp_sm_mod_probe(struct sfp *sfp, bool report)
|
2017-07-25 21:03:39 +07:00
|
|
|
{
|
|
|
|
/* SFP module inserted - read I2C data */
|
|
|
|
struct sfp_eeprom_id id;
|
2018-03-28 17:18:25 +07:00
|
|
|
bool cotsworks;
|
2017-07-25 21:03:39 +07:00
|
|
|
u8 check;
|
sfp: add high power module support
This patch is the result of work by both Jon Nettleton and Russell King.
Jon wrote the original patch, adding support for SFP modules which
require a power level greater than '1'.
Russell's changes:
- Fix the power levels for big-endian, and make the code flow better.
- Convert to use device_property_read_u8()
- Warn for power levels exceeding host level
SFF-8431 says:
"To avoid exceeding system power supply limits and cooling capacity,
all modules at power up by default shall operate with up to 1.0 W.
Hosts supporting Power Level II or III operation may enable a Power
Level II or III module through the 2-wire interface. Power Level II
or III modules shall assert the power level declaration bit of
SFF-8472."
Print a warning for modules that exceed the host power level, and
leave them operating in power level 1.
- Fix i2c write
The first byte of any write after the bus address is always the
device address. In order to write a value to device D, address I,
value V, we need to generate on the bus:
S DDDDDDDD A IIIIIIII A VVVVVVVV A P
where S = start, R = restart, A = ack, P = stop. Splitting this
as two:
S DDDDDDDD A IIIIIIII A R DDDDDDDD A VVVVVVVV A P
results in the device's address register being written first by I
and then by V - the addressed register within the device is not
written.
- Avoid power mode switching if 0xa2 is not implemented
Some modules indicate that they support power level II or power level
III, but do not implement address 0xa2, meaning that the bit to set
them to high power mode is not accessible.
These modules appear to have the sff8472_compliance field set to zero,
and also do not implement diagnostics. Detect this, but also ensure
that the module does not require the address switching mode, which we
do not implement.
- Use mW for power level rather than power level number.
- Fix high power mode transition
We must not switch to SFP_MOD_PRESENT state until we have finished
initialising, because the remaining state machines check for that
state. Add SFP_MOD_HPOWER as an intermediate state.
- Use definition for I2C register address rather than constant.
Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-02-27 22:53:12 +07:00
|
|
|
int ret;
|
2017-07-25 21:03:39 +07:00
|
|
|
|
sfp: add high power module support
This patch is the result of work by both Jon Nettleton and Russell King.
Jon wrote the original patch, adding support for SFP modules which
require a power level greater than '1'.
Russell's changes:
- Fix the power levels for big-endian, and make the code flow better.
- Convert to use device_property_read_u8()
- Warn for power levels exceeding host level
SFF-8431 says:
"To avoid exceeding system power supply limits and cooling capacity,
all modules at power up by default shall operate with up to 1.0 W.
Hosts supporting Power Level II or III operation may enable a Power
Level II or III module through the 2-wire interface. Power Level II
or III modules shall assert the power level declaration bit of
SFF-8472."
Print a warning for modules that exceed the host power level, and
leave them operating in power level 1.
- Fix i2c write
The first byte of any write after the bus address is always the
device address. In order to write a value to device D, address I,
value V, we need to generate on the bus:
S DDDDDDDD A IIIIIIII A VVVVVVVV A P
where S = start, R = restart, A = ack, P = stop. Splitting this
as two:
S DDDDDDDD A IIIIIIII A R DDDDDDDD A VVVVVVVV A P
results in the device's address register being written first by I
and then by V - the addressed register within the device is not
written.
- Avoid power mode switching if 0xa2 is not implemented
Some modules indicate that they support power level II or power level
III, but do not implement address 0xa2, meaning that the bit to set
them to high power mode is not accessible.
These modules appear to have the sff8472_compliance field set to zero,
and also do not implement diagnostics. Detect this, but also ensure
that the module does not require the address switching mode, which we
do not implement.
- Use mW for power level rather than power level number.
- Fix high power mode transition
We must not switch to SFP_MOD_PRESENT state until we have finished
initialising, because the remaining state machines check for that
state. Add SFP_MOD_HPOWER as an intermediate state.
- Use definition for I2C register address rather than constant.
Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-02-27 22:53:12 +07:00
|
|
|
ret = sfp_read(sfp, false, 0, &id, sizeof(id));
|
|
|
|
if (ret < 0) {
|
2019-11-10 21:07:30 +07:00
|
|
|
if (report)
|
|
|
|
dev_err(sfp->dev, "failed to read EEPROM: %d\n", ret);
|
2017-07-25 21:03:39 +07:00
|
|
|
return -EAGAIN;
|
|
|
|
}
|
|
|
|
|
sfp: add high power module support
This patch is the result of work by both Jon Nettleton and Russell King.
Jon wrote the original patch, adding support for SFP modules which
require a power level greater than '1'.
Russell's changes:
- Fix the power levels for big-endian, and make the code flow better.
- Convert to use device_property_read_u8()
- Warn for power levels exceeding host level
SFF-8431 says:
"To avoid exceeding system power supply limits and cooling capacity,
all modules at power up by default shall operate with up to 1.0 W.
Hosts supporting Power Level II or III operation may enable a Power
Level II or III module through the 2-wire interface. Power Level II
or III modules shall assert the power level declaration bit of
SFF-8472."
Print a warning for modules that exceed the host power level, and
leave them operating in power level 1.
- Fix i2c write
The first byte of any write after the bus address is always the
device address. In order to write a value to device D, address I,
value V, we need to generate on the bus:
S DDDDDDDD A IIIIIIII A VVVVVVVV A P
where S = start, R = restart, A = ack, P = stop. Splitting this
as two:
S DDDDDDDD A IIIIIIII A R DDDDDDDD A VVVVVVVV A P
results in the device's address register being written first by I
and then by V - the addressed register within the device is not
written.
- Avoid power mode switching if 0xa2 is not implemented
Some modules indicate that they support power level II or power level
III, but do not implement address 0xa2, meaning that the bit to set
them to high power mode is not accessible.
These modules appear to have the sff8472_compliance field set to zero,
and also do not implement diagnostics. Detect this, but also ensure
that the module does not require the address switching mode, which we
do not implement.
- Use mW for power level rather than power level number.
- Fix high power mode transition
We must not switch to SFP_MOD_PRESENT state until we have finished
initialising, because the remaining state machines check for that
state. Add SFP_MOD_HPOWER as an intermediate state.
- Use definition for I2C register address rather than constant.
Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-02-27 22:53:12 +07:00
|
|
|
if (ret != sizeof(id)) {
|
|
|
|
dev_err(sfp->dev, "EEPROM short read: %d\n", ret);
|
2017-07-25 21:03:39 +07:00
|
|
|
return -EAGAIN;
|
|
|
|
}
|
|
|
|
|
2018-03-28 17:18:25 +07:00
|
|
|
/* Cotsworks do not seem to update the checksums when they
|
|
|
|
* do the final programming with the final module part number,
|
|
|
|
* serial number and date code.
|
|
|
|
*/
|
|
|
|
cotsworks = !memcmp(id.base.vendor_name, "COTSWORKS ", 16);
|
|
|
|
|
2017-07-25 21:03:39 +07:00
|
|
|
/* Validate the checksum over the base structure */
|
|
|
|
check = sfp_check(&id.base, sizeof(id.base) - 1);
|
|
|
|
if (check != id.base.cc_base) {
|
2018-03-28 17:18:25 +07:00
|
|
|
if (cotsworks) {
|
|
|
|
dev_warn(sfp->dev,
|
|
|
|
"EEPROM base structure checksum failure (0x%02x != 0x%02x)\n",
|
|
|
|
check, id.base.cc_base);
|
|
|
|
} else {
|
|
|
|
dev_err(sfp->dev,
|
|
|
|
"EEPROM base structure checksum failure: 0x%02x != 0x%02x\n",
|
|
|
|
check, id.base.cc_base);
|
|
|
|
print_hex_dump(KERN_ERR, "sfp EE: ", DUMP_PREFIX_OFFSET,
|
|
|
|
16, 1, &id, sizeof(id), true);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2017-07-25 21:03:39 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
check = sfp_check(&id.ext, sizeof(id.ext) - 1);
|
|
|
|
if (check != id.ext.cc_ext) {
|
2018-03-28 17:18:25 +07:00
|
|
|
if (cotsworks) {
|
|
|
|
dev_warn(sfp->dev,
|
|
|
|
"EEPROM extended structure checksum failure (0x%02x != 0x%02x)\n",
|
|
|
|
check, id.ext.cc_ext);
|
|
|
|
} else {
|
|
|
|
dev_err(sfp->dev,
|
|
|
|
"EEPROM extended structure checksum failure: 0x%02x != 0x%02x\n",
|
|
|
|
check, id.ext.cc_ext);
|
|
|
|
print_hex_dump(KERN_ERR, "sfp EE: ", DUMP_PREFIX_OFFSET,
|
|
|
|
16, 1, &id, sizeof(id), true);
|
|
|
|
memset(&id.ext, 0, sizeof(id.ext));
|
|
|
|
}
|
2017-07-25 21:03:39 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
sfp->id = id;
|
|
|
|
|
2017-12-29 19:15:12 +07:00
|
|
|
dev_info(sfp->dev, "module %.*s %.*s rev %.*s sn %.*s dc %.*s\n",
|
|
|
|
(int)sizeof(id.base.vendor_name), id.base.vendor_name,
|
|
|
|
(int)sizeof(id.base.vendor_pn), id.base.vendor_pn,
|
|
|
|
(int)sizeof(id.base.vendor_rev), id.base.vendor_rev,
|
|
|
|
(int)sizeof(id.ext.vendor_sn), id.ext.vendor_sn,
|
|
|
|
(int)sizeof(id.ext.datecode), id.ext.datecode);
|
2017-07-25 21:03:39 +07:00
|
|
|
|
2017-12-14 17:27:47 +07:00
|
|
|
/* Check whether we support this module */
|
2019-11-20 19:29:59 +07:00
|
|
|
if (!sfp->type->module_supported(&id)) {
|
2017-12-14 17:27:47 +07:00
|
|
|
dev_err(sfp->dev,
|
|
|
|
"module is not supported - phys id 0x%02x 0x%02x\n",
|
2017-07-25 21:03:39 +07:00
|
|
|
sfp->id.base.phys_id, sfp->id.base.phys_ext_id);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2017-11-30 20:59:21 +07:00
|
|
|
/* If the module requires address swap mode, warn about it */
|
|
|
|
if (sfp->id.ext.diagmon & SFP_DIAGMON_ADDRMODE)
|
|
|
|
dev_warn(sfp->dev,
|
|
|
|
"module address swap to access page 0xA2 is not supported.\n");
|
|
|
|
|
2019-11-10 21:06:39 +07:00
|
|
|
/* Parse the module power requirement */
|
|
|
|
ret = sfp_module_parse_power(sfp);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
2019-12-09 20:40:23 +07:00
|
|
|
if (!memcmp(id.base.vendor_name, "ALCATELLUCENT ", 16) &&
|
|
|
|
!memcmp(id.base.vendor_pn, "3FE46541AA ", 16))
|
|
|
|
sfp->module_t_start_up = T_START_UP_BAD_GPON;
|
|
|
|
else
|
|
|
|
sfp->module_t_start_up = T_START_UP;
|
|
|
|
|
2019-11-10 21:07:20 +07:00
|
|
|
return 0;
|
2017-07-25 21:03:39 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sfp_sm_mod_remove(struct sfp *sfp)
|
|
|
|
{
|
2019-11-10 21:07:25 +07:00
|
|
|
if (sfp->sm_mod_state > SFP_MOD_WAITDEV)
|
|
|
|
sfp_module_remove(sfp->sfp_bus);
|
2017-07-25 21:03:39 +07:00
|
|
|
|
net: phy: sfp: Add HWMON support for module sensors
SFP modules can contain a number of sensors. The EEPROM also contains
recommended alarm and critical values for each sensor, and indications
of if these have been exceeded. Export this information via
HWMON. Currently temperature, VCC, bias current, transmit power, and
possibly receiver power is supported.
The sensors in the modules can either return calibrate or uncalibrated
values. Uncalibrated values need to be manipulated, using coefficients
provided in the SFP EEPROM. Uncalibrated receive power values require
floating point maths in order to calibrate them. Performing this in
the kernel is hard. So if the SFP module indicates it uses
uncalibrated values, RX power is not made available.
With this hwmon device, it is possible to view the sensor values using
lm-sensors programs:
in0: +3.29 V (crit min = +2.90 V, min = +3.00 V)
(max = +3.60 V, crit max = +3.70 V)
temp1: +33.0°C (low = -5.0°C, high = +80.0°C)
(crit low = -10.0°C, crit = +85.0°C)
power1: 1000.00 nW (max = 794.00 uW, min = 50.00 uW) ALARM (LCRIT)
(lcrit = 40.00 uW, crit = 1000.00 uW)
curr1: +0.00 A (crit min = +0.00 A, min = +0.00 A) ALARM (LCRIT, MIN)
(max = +0.01 A, crit max = +0.01 A)
The scaling sensors performs on the bias current is not particularly
good. The raw values are more useful:
curr1:
curr1_input: 0.000
curr1_min: 0.002
curr1_max: 0.010
curr1_lcrit: 0.000
curr1_crit: 0.011
curr1_min_alarm: 1.000
curr1_max_alarm: 0.000
curr1_lcrit_alarm: 1.000
curr1_crit_alarm: 0.000
In order to keep the I2C overhead to a minimum, the constant values,
such as limits and calibration coefficients are read once at module
insertion time. Thus only reading *_input and *_alarm properties
requires i2c read operations.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-07-18 02:48:13 +07:00
|
|
|
sfp_hwmon_remove(sfp);
|
|
|
|
|
2017-07-25 21:03:39 +07:00
|
|
|
memset(&sfp->id, 0, sizeof(sfp->id));
|
2019-11-10 21:06:39 +07:00
|
|
|
sfp->module_power_mW = 0;
|
2017-07-25 21:03:39 +07:00
|
|
|
|
|
|
|
dev_info(sfp->dev, "module removed\n");
|
|
|
|
}
|
|
|
|
|
2019-11-10 21:07:14 +07:00
|
|
|
/* This state machine tracks the upstream's state */
|
2019-11-10 21:06:13 +07:00
|
|
|
static void sfp_sm_device(struct sfp *sfp, unsigned int event)
|
2017-07-25 21:03:39 +07:00
|
|
|
{
|
2019-11-10 21:06:13 +07:00
|
|
|
switch (sfp->sm_dev_state) {
|
|
|
|
default:
|
2019-11-10 21:07:14 +07:00
|
|
|
if (event == SFP_E_DEV_ATTACH)
|
|
|
|
sfp->sm_dev_state = SFP_DEV_DOWN;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SFP_DEV_DOWN:
|
|
|
|
if (event == SFP_E_DEV_DETACH)
|
|
|
|
sfp->sm_dev_state = SFP_DEV_DETACHED;
|
|
|
|
else if (event == SFP_E_DEV_UP)
|
2019-11-10 21:06:13 +07:00
|
|
|
sfp->sm_dev_state = SFP_DEV_UP;
|
|
|
|
break;
|
2017-07-25 21:03:39 +07:00
|
|
|
|
2019-11-10 21:06:13 +07:00
|
|
|
case SFP_DEV_UP:
|
2019-11-10 21:07:14 +07:00
|
|
|
if (event == SFP_E_DEV_DETACH)
|
|
|
|
sfp->sm_dev_state = SFP_DEV_DETACHED;
|
|
|
|
else if (event == SFP_E_DEV_DOWN)
|
2019-11-10 21:06:13 +07:00
|
|
|
sfp->sm_dev_state = SFP_DEV_DOWN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-07-25 21:03:39 +07:00
|
|
|
|
2019-11-10 21:06:33 +07:00
|
|
|
/* This state machine tracks the insert/remove state of the module, probes
|
|
|
|
* the on-board EEPROM, and sets up the power level.
|
2019-11-10 21:06:13 +07:00
|
|
|
*/
|
|
|
|
static void sfp_sm_module(struct sfp *sfp, unsigned int event)
|
|
|
|
{
|
2019-11-10 21:07:20 +07:00
|
|
|
int err;
|
|
|
|
|
|
|
|
/* Handle remove event globally, it resets this state machine */
|
|
|
|
if (event == SFP_E_REMOVE) {
|
2019-11-10 21:06:28 +07:00
|
|
|
if (sfp->sm_mod_state > SFP_MOD_PROBE)
|
|
|
|
sfp_sm_mod_remove(sfp);
|
2019-11-10 21:07:20 +07:00
|
|
|
sfp_sm_mod_next(sfp, SFP_MOD_EMPTY, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle device detach globally */
|
2019-11-10 21:07:25 +07:00
|
|
|
if (sfp->sm_dev_state < SFP_DEV_DOWN &&
|
|
|
|
sfp->sm_mod_state > SFP_MOD_WAITDEV) {
|
2019-11-10 21:07:20 +07:00
|
|
|
if (sfp->module_power_mW > 1000 &&
|
|
|
|
sfp->sm_mod_state > SFP_MOD_HPOWER)
|
|
|
|
sfp_sm_mod_hpower(sfp, false);
|
2019-11-10 21:07:25 +07:00
|
|
|
sfp_sm_mod_next(sfp, SFP_MOD_WAITDEV, 0);
|
2019-11-10 21:06:28 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-25 21:03:39 +07:00
|
|
|
switch (sfp->sm_mod_state) {
|
|
|
|
default:
|
2019-11-10 21:07:30 +07:00
|
|
|
if (event == SFP_E_INSERT) {
|
2019-11-10 21:06:33 +07:00
|
|
|
sfp_sm_mod_next(sfp, SFP_MOD_PROBE, T_SERIAL);
|
2019-11-10 21:07:30 +07:00
|
|
|
sfp->sm_mod_tries_init = R_PROBE_RETRY_INIT;
|
|
|
|
sfp->sm_mod_tries = R_PROBE_RETRY_SLOW;
|
|
|
|
}
|
2017-07-25 21:03:39 +07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SFP_MOD_PROBE:
|
2019-11-10 21:07:25 +07:00
|
|
|
/* Wait for T_PROBE_INIT to time out */
|
2019-11-10 21:07:20 +07:00
|
|
|
if (event != SFP_E_TIMEOUT)
|
|
|
|
break;
|
|
|
|
|
2019-11-10 21:07:30 +07:00
|
|
|
err = sfp_sm_mod_probe(sfp, sfp->sm_mod_tries == 1);
|
2019-11-10 21:07:20 +07:00
|
|
|
if (err == -EAGAIN) {
|
2019-11-10 21:07:30 +07:00
|
|
|
if (sfp->sm_mod_tries_init &&
|
|
|
|
--sfp->sm_mod_tries_init) {
|
|
|
|
sfp_sm_set_timer(sfp, T_PROBE_RETRY_INIT);
|
|
|
|
break;
|
|
|
|
} else if (sfp->sm_mod_tries && --sfp->sm_mod_tries) {
|
|
|
|
if (sfp->sm_mod_tries == R_PROBE_RETRY_SLOW - 1)
|
|
|
|
dev_warn(sfp->dev,
|
|
|
|
"please wait, module slow to respond\n");
|
|
|
|
sfp_sm_set_timer(sfp, T_PROBE_RETRY_SLOW);
|
|
|
|
break;
|
|
|
|
}
|
2017-07-25 21:03:39 +07:00
|
|
|
}
|
2019-11-10 21:07:20 +07:00
|
|
|
if (err < 0) {
|
|
|
|
sfp_sm_mod_next(sfp, SFP_MOD_ERROR, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-12-04 06:51:28 +07:00
|
|
|
err = sfp_hwmon_insert(sfp);
|
|
|
|
if (err)
|
|
|
|
dev_warn(sfp->dev, "hwmon probe failed: %d\n", err);
|
|
|
|
|
2019-11-10 21:07:25 +07:00
|
|
|
sfp_sm_mod_next(sfp, SFP_MOD_WAITDEV, 0);
|
|
|
|
/* fall through */
|
|
|
|
case SFP_MOD_WAITDEV:
|
|
|
|
/* Ensure that the device is attached before proceeding */
|
|
|
|
if (sfp->sm_dev_state < SFP_DEV_DOWN)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Report the module insertion to the upstream device */
|
|
|
|
err = sfp_module_insert(sfp->sfp_bus, &sfp->id);
|
|
|
|
if (err < 0) {
|
|
|
|
sfp_sm_mod_next(sfp, SFP_MOD_ERROR, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-11-10 21:07:20 +07:00
|
|
|
/* If this is a power level 1 module, we are done */
|
|
|
|
if (sfp->module_power_mW <= 1000)
|
|
|
|
goto insert;
|
2017-07-25 21:03:39 +07:00
|
|
|
|
2019-11-10 21:07:20 +07:00
|
|
|
sfp_sm_mod_next(sfp, SFP_MOD_HPOWER, 0);
|
|
|
|
/* fall through */
|
sfp: add high power module support
This patch is the result of work by both Jon Nettleton and Russell King.
Jon wrote the original patch, adding support for SFP modules which
require a power level greater than '1'.
Russell's changes:
- Fix the power levels for big-endian, and make the code flow better.
- Convert to use device_property_read_u8()
- Warn for power levels exceeding host level
SFF-8431 says:
"To avoid exceeding system power supply limits and cooling capacity,
all modules at power up by default shall operate with up to 1.0 W.
Hosts supporting Power Level II or III operation may enable a Power
Level II or III module through the 2-wire interface. Power Level II
or III modules shall assert the power level declaration bit of
SFF-8472."
Print a warning for modules that exceed the host power level, and
leave them operating in power level 1.
- Fix i2c write
The first byte of any write after the bus address is always the
device address. In order to write a value to device D, address I,
value V, we need to generate on the bus:
S DDDDDDDD A IIIIIIII A VVVVVVVV A P
where S = start, R = restart, A = ack, P = stop. Splitting this
as two:
S DDDDDDDD A IIIIIIII A R DDDDDDDD A VVVVVVVV A P
results in the device's address register being written first by I
and then by V - the addressed register within the device is not
written.
- Avoid power mode switching if 0xa2 is not implemented
Some modules indicate that they support power level II or power level
III, but do not implement address 0xa2, meaning that the bit to set
them to high power mode is not accessible.
These modules appear to have the sff8472_compliance field set to zero,
and also do not implement diagnostics. Detect this, but also ensure
that the module does not require the address switching mode, which we
do not implement.
- Use mW for power level rather than power level number.
- Fix high power mode transition
We must not switch to SFP_MOD_PRESENT state until we have finished
initialising, because the remaining state machines check for that
state. Add SFP_MOD_HPOWER as an intermediate state.
- Use definition for I2C register address rather than constant.
Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-02-27 22:53:12 +07:00
|
|
|
case SFP_MOD_HPOWER:
|
2019-11-10 21:07:20 +07:00
|
|
|
/* Enable high power mode */
|
|
|
|
err = sfp_sm_mod_hpower(sfp, true);
|
2019-11-10 21:07:25 +07:00
|
|
|
if (err < 0) {
|
|
|
|
if (err != -EAGAIN) {
|
|
|
|
sfp_module_remove(sfp->sfp_bus);
|
|
|
|
sfp_sm_mod_next(sfp, SFP_MOD_ERROR, 0);
|
|
|
|
} else {
|
2019-11-10 21:07:30 +07:00
|
|
|
sfp_sm_set_timer(sfp, T_PROBE_RETRY_INIT);
|
2019-11-10 21:07:25 +07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
sfp_sm_mod_next(sfp, SFP_MOD_WAITPWR, T_HPOWER_LEVEL);
|
2019-11-10 21:07:20 +07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SFP_MOD_WAITPWR:
|
|
|
|
/* Wait for T_HPOWER_LEVEL to time out */
|
|
|
|
if (event != SFP_E_TIMEOUT)
|
sfp: add high power module support
This patch is the result of work by both Jon Nettleton and Russell King.
Jon wrote the original patch, adding support for SFP modules which
require a power level greater than '1'.
Russell's changes:
- Fix the power levels for big-endian, and make the code flow better.
- Convert to use device_property_read_u8()
- Warn for power levels exceeding host level
SFF-8431 says:
"To avoid exceeding system power supply limits and cooling capacity,
all modules at power up by default shall operate with up to 1.0 W.
Hosts supporting Power Level II or III operation may enable a Power
Level II or III module through the 2-wire interface. Power Level II
or III modules shall assert the power level declaration bit of
SFF-8472."
Print a warning for modules that exceed the host power level, and
leave them operating in power level 1.
- Fix i2c write
The first byte of any write after the bus address is always the
device address. In order to write a value to device D, address I,
value V, we need to generate on the bus:
S DDDDDDDD A IIIIIIII A VVVVVVVV A P
where S = start, R = restart, A = ack, P = stop. Splitting this
as two:
S DDDDDDDD A IIIIIIII A R DDDDDDDD A VVVVVVVV A P
results in the device's address register being written first by I
and then by V - the addressed register within the device is not
written.
- Avoid power mode switching if 0xa2 is not implemented
Some modules indicate that they support power level II or power level
III, but do not implement address 0xa2, meaning that the bit to set
them to high power mode is not accessible.
These modules appear to have the sff8472_compliance field set to zero,
and also do not implement diagnostics. Detect this, but also ensure
that the module does not require the address switching mode, which we
do not implement.
- Use mW for power level rather than power level number.
- Fix high power mode transition
We must not switch to SFP_MOD_PRESENT state until we have finished
initialising, because the remaining state machines check for that
state. Add SFP_MOD_HPOWER as an intermediate state.
- Use definition for I2C register address rather than constant.
Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-02-27 22:53:12 +07:00
|
|
|
break;
|
2019-11-10 21:07:20 +07:00
|
|
|
|
|
|
|
insert:
|
|
|
|
sfp_sm_mod_next(sfp, SFP_MOD_PRESENT, 0);
|
|
|
|
break;
|
|
|
|
|
2017-07-25 21:03:39 +07:00
|
|
|
case SFP_MOD_PRESENT:
|
|
|
|
case SFP_MOD_ERROR:
|
|
|
|
break;
|
|
|
|
}
|
2019-11-10 21:06:13 +07:00
|
|
|
}
|
2017-07-25 21:03:39 +07:00
|
|
|
|
2019-11-10 21:06:13 +07:00
|
|
|
static void sfp_sm_main(struct sfp *sfp, unsigned int event)
|
|
|
|
{
|
2019-11-10 21:06:59 +07:00
|
|
|
unsigned long timeout;
|
2019-12-09 21:16:11 +07:00
|
|
|
int ret;
|
2019-11-10 21:06:59 +07:00
|
|
|
|
2017-07-25 21:03:39 +07:00
|
|
|
/* Some events are global */
|
|
|
|
if (sfp->sm_state != SFP_S_DOWN &&
|
|
|
|
(sfp->sm_mod_state != SFP_MOD_PRESENT ||
|
|
|
|
sfp->sm_dev_state != SFP_DEV_UP)) {
|
|
|
|
if (sfp->sm_state == SFP_S_LINK_UP &&
|
|
|
|
sfp->sm_dev_state == SFP_DEV_UP)
|
|
|
|
sfp_sm_link_down(sfp);
|
2019-12-11 17:56:09 +07:00
|
|
|
if (sfp->sm_state > SFP_S_INIT)
|
|
|
|
sfp_module_stop(sfp->sfp_bus);
|
2017-07-25 21:03:39 +07:00
|
|
|
if (sfp->mod_phy)
|
|
|
|
sfp_sm_phy_detach(sfp);
|
2019-11-10 21:06:18 +07:00
|
|
|
sfp_module_tx_disable(sfp);
|
2019-11-20 19:29:59 +07:00
|
|
|
sfp_soft_stop_poll(sfp);
|
2017-07-25 21:03:39 +07:00
|
|
|
sfp_sm_next(sfp, SFP_S_DOWN, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The main state machine */
|
|
|
|
switch (sfp->sm_state) {
|
|
|
|
case SFP_S_DOWN:
|
2019-11-10 21:06:59 +07:00
|
|
|
if (sfp->sm_mod_state != SFP_MOD_PRESENT ||
|
|
|
|
sfp->sm_dev_state != SFP_DEV_UP)
|
|
|
|
break;
|
|
|
|
|
2019-11-20 19:29:59 +07:00
|
|
|
if (!(sfp->id.ext.diagmon & SFP_DIAGMON_ADDRMODE))
|
|
|
|
sfp_soft_start_poll(sfp);
|
|
|
|
|
|
|
|
sfp_module_tx_enable(sfp);
|
2019-11-10 21:06:59 +07:00
|
|
|
|
|
|
|
/* Initialise the fault clearance retries */
|
2019-12-09 21:16:00 +07:00
|
|
|
sfp->sm_fault_retries = N_FAULT_INIT;
|
2019-11-10 21:06:59 +07:00
|
|
|
|
|
|
|
/* We need to check the TX_FAULT state, which is not defined
|
|
|
|
* while TX_DISABLE is asserted. The earliest we want to do
|
|
|
|
* anything (such as probe for a PHY) is 50ms.
|
|
|
|
*/
|
|
|
|
sfp_sm_next(sfp, SFP_S_WAIT, T_WAIT);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SFP_S_WAIT:
|
|
|
|
if (event != SFP_E_TIMEOUT)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (sfp->state & SFP_F_TX_FAULT) {
|
2019-12-09 20:40:23 +07:00
|
|
|
/* Wait up to t_init (SFF-8472) or t_start_up (SFF-8431)
|
|
|
|
* from the TX_DISABLE deassertion for the module to
|
|
|
|
* initialise, which is indicated by TX_FAULT
|
|
|
|
* deasserting.
|
2019-11-10 21:06:54 +07:00
|
|
|
*/
|
2019-12-09 20:40:23 +07:00
|
|
|
timeout = sfp->module_t_start_up;
|
2019-11-10 21:06:59 +07:00
|
|
|
if (timeout > T_WAIT)
|
|
|
|
timeout -= T_WAIT;
|
|
|
|
else
|
|
|
|
timeout = 1;
|
|
|
|
|
|
|
|
sfp_sm_next(sfp, SFP_S_INIT, timeout);
|
|
|
|
} else {
|
|
|
|
/* TX_FAULT is not asserted, assume the module has
|
|
|
|
* finished initialising.
|
|
|
|
*/
|
|
|
|
goto init_done;
|
2019-11-10 21:06:54 +07:00
|
|
|
}
|
2017-07-25 21:03:39 +07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SFP_S_INIT:
|
2019-11-10 21:07:09 +07:00
|
|
|
if (event == SFP_E_TIMEOUT && sfp->state & SFP_F_TX_FAULT) {
|
2019-12-09 20:40:23 +07:00
|
|
|
/* TX_FAULT is still asserted after t_init or
|
|
|
|
* or t_start_up, so assume there is a fault.
|
2019-11-10 21:07:09 +07:00
|
|
|
*/
|
|
|
|
sfp_sm_fault(sfp, SFP_S_INIT_TX_FAULT,
|
2019-12-09 21:16:00 +07:00
|
|
|
sfp->sm_fault_retries == N_FAULT_INIT);
|
2019-11-10 21:07:09 +07:00
|
|
|
} else if (event == SFP_E_TIMEOUT || event == SFP_E_TX_CLEAR) {
|
2019-12-09 21:16:11 +07:00
|
|
|
init_done:
|
|
|
|
sfp->sm_phy_retries = R_PHY_RETRY;
|
|
|
|
goto phy_probe;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SFP_S_INIT_PHY:
|
|
|
|
if (event != SFP_E_TIMEOUT)
|
|
|
|
break;
|
|
|
|
phy_probe:
|
|
|
|
/* TX_FAULT deasserted or we timed out with TX_FAULT
|
|
|
|
* clear. Probe for the PHY and check the LOS state.
|
|
|
|
*/
|
|
|
|
ret = sfp_sm_probe_for_phy(sfp);
|
|
|
|
if (ret == -ENODEV) {
|
|
|
|
if (--sfp->sm_phy_retries) {
|
|
|
|
sfp_sm_next(sfp, SFP_S_INIT_PHY, T_PHY_RETRY);
|
2019-12-11 17:56:09 +07:00
|
|
|
break;
|
2019-12-09 21:16:11 +07:00
|
|
|
} else {
|
|
|
|
dev_info(sfp->dev, "no PHY detected\n");
|
2019-12-11 17:56:09 +07:00
|
|
|
}
|
2019-12-09 21:16:11 +07:00
|
|
|
} else if (ret) {
|
|
|
|
sfp_sm_next(sfp, SFP_S_FAIL, 0);
|
|
|
|
break;
|
2019-11-10 21:07:09 +07:00
|
|
|
}
|
2019-12-09 21:16:11 +07:00
|
|
|
if (sfp_module_start(sfp->sfp_bus)) {
|
|
|
|
sfp_sm_next(sfp, SFP_S_FAIL, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sfp_sm_link_check_los(sfp);
|
|
|
|
|
|
|
|
/* Reset the fault retry count */
|
|
|
|
sfp->sm_fault_retries = N_FAULT;
|
2019-11-10 21:07:09 +07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SFP_S_INIT_TX_FAULT:
|
|
|
|
if (event == SFP_E_TIMEOUT) {
|
|
|
|
sfp_module_tx_fault_reset(sfp);
|
2019-12-09 20:40:23 +07:00
|
|
|
sfp_sm_next(sfp, SFP_S_INIT, sfp->module_t_start_up);
|
2019-11-10 21:07:09 +07:00
|
|
|
}
|
2017-07-25 21:03:39 +07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SFP_S_WAIT_LOS:
|
|
|
|
if (event == SFP_E_TX_FAULT)
|
2019-11-10 21:07:04 +07:00
|
|
|
sfp_sm_fault(sfp, SFP_S_TX_FAULT, true);
|
2017-11-30 20:59:16 +07:00
|
|
|
else if (sfp_los_event_inactive(sfp, event))
|
2017-07-25 21:03:39 +07:00
|
|
|
sfp_sm_link_up(sfp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SFP_S_LINK_UP:
|
|
|
|
if (event == SFP_E_TX_FAULT) {
|
|
|
|
sfp_sm_link_down(sfp);
|
2019-11-10 21:07:04 +07:00
|
|
|
sfp_sm_fault(sfp, SFP_S_TX_FAULT, true);
|
2017-11-30 20:59:16 +07:00
|
|
|
} else if (sfp_los_event_active(sfp, event)) {
|
2017-07-25 21:03:39 +07:00
|
|
|
sfp_sm_link_down(sfp);
|
|
|
|
sfp_sm_next(sfp, SFP_S_WAIT_LOS, 0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SFP_S_TX_FAULT:
|
|
|
|
if (event == SFP_E_TIMEOUT) {
|
|
|
|
sfp_module_tx_fault_reset(sfp);
|
2019-12-09 20:40:23 +07:00
|
|
|
sfp_sm_next(sfp, SFP_S_REINIT, sfp->module_t_start_up);
|
2017-07-25 21:03:39 +07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SFP_S_REINIT:
|
|
|
|
if (event == SFP_E_TIMEOUT && sfp->state & SFP_F_TX_FAULT) {
|
2019-11-10 21:07:04 +07:00
|
|
|
sfp_sm_fault(sfp, SFP_S_TX_FAULT, false);
|
2017-07-25 21:03:39 +07:00
|
|
|
} else if (event == SFP_E_TIMEOUT || event == SFP_E_TX_CLEAR) {
|
|
|
|
dev_info(sfp->dev, "module transmit fault recovered\n");
|
|
|
|
sfp_sm_link_check_los(sfp);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SFP_S_TX_DISABLE:
|
|
|
|
break;
|
|
|
|
}
|
2019-11-10 21:06:13 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sfp_sm_event(struct sfp *sfp, unsigned int event)
|
|
|
|
{
|
|
|
|
mutex_lock(&sfp->sm_mutex);
|
|
|
|
|
|
|
|
dev_dbg(sfp->dev, "SM: enter %s:%s:%s event %s\n",
|
|
|
|
mod_state_to_str(sfp->sm_mod_state),
|
|
|
|
dev_state_to_str(sfp->sm_dev_state),
|
|
|
|
sm_state_to_str(sfp->sm_state),
|
|
|
|
event_to_str(event));
|
|
|
|
|
|
|
|
sfp_sm_device(sfp, event);
|
2019-11-10 21:07:14 +07:00
|
|
|
sfp_sm_module(sfp, event);
|
2019-11-10 21:06:13 +07:00
|
|
|
sfp_sm_main(sfp, event);
|
2017-07-25 21:03:39 +07:00
|
|
|
|
2018-08-09 01:54:12 +07:00
|
|
|
dev_dbg(sfp->dev, "SM: exit %s:%s:%s\n",
|
|
|
|
mod_state_to_str(sfp->sm_mod_state),
|
|
|
|
dev_state_to_str(sfp->sm_dev_state),
|
|
|
|
sm_state_to_str(sfp->sm_state));
|
2017-07-25 21:03:39 +07:00
|
|
|
|
|
|
|
mutex_unlock(&sfp->sm_mutex);
|
|
|
|
}
|
|
|
|
|
2019-02-06 17:52:30 +07:00
|
|
|
static void sfp_attach(struct sfp *sfp)
|
|
|
|
{
|
2019-11-10 21:07:14 +07:00
|
|
|
sfp_sm_event(sfp, SFP_E_DEV_ATTACH);
|
2019-02-06 17:52:30 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sfp_detach(struct sfp *sfp)
|
|
|
|
{
|
2019-11-10 21:07:14 +07:00
|
|
|
sfp_sm_event(sfp, SFP_E_DEV_DETACH);
|
2019-02-06 17:52:30 +07:00
|
|
|
}
|
|
|
|
|
2017-07-25 21:03:39 +07:00
|
|
|
static void sfp_start(struct sfp *sfp)
|
|
|
|
{
|
|
|
|
sfp_sm_event(sfp, SFP_E_DEV_UP);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sfp_stop(struct sfp *sfp)
|
|
|
|
{
|
|
|
|
sfp_sm_event(sfp, SFP_E_DEV_DOWN);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sfp_module_info(struct sfp *sfp, struct ethtool_modinfo *modinfo)
|
|
|
|
{
|
|
|
|
/* locking... and check module is present */
|
|
|
|
|
2017-11-30 20:59:21 +07:00
|
|
|
if (sfp->id.ext.sff8472_compliance &&
|
|
|
|
!(sfp->id.ext.diagmon & SFP_DIAGMON_ADDRMODE)) {
|
2017-07-25 21:03:39 +07:00
|
|
|
modinfo->type = ETH_MODULE_SFF_8472;
|
|
|
|
modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
|
|
|
|
} else {
|
|
|
|
modinfo->type = ETH_MODULE_SFF_8079;
|
|
|
|
modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sfp_module_eeprom(struct sfp *sfp, struct ethtool_eeprom *ee,
|
2017-10-31 11:42:57 +07:00
|
|
|
u8 *data)
|
2017-07-25 21:03:39 +07:00
|
|
|
{
|
|
|
|
unsigned int first, last, len;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (ee->len == 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
first = ee->offset;
|
|
|
|
last = ee->offset + ee->len;
|
|
|
|
if (first < ETH_MODULE_SFF_8079_LEN) {
|
|
|
|
len = min_t(unsigned int, last, ETH_MODULE_SFF_8079_LEN);
|
|
|
|
len -= first;
|
|
|
|
|
2017-12-15 23:09:41 +07:00
|
|
|
ret = sfp_read(sfp, false, first, data, len);
|
2017-07-25 21:03:39 +07:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
first += len;
|
|
|
|
data += len;
|
|
|
|
}
|
2017-12-15 23:09:41 +07:00
|
|
|
if (first < ETH_MODULE_SFF_8472_LEN && last > ETH_MODULE_SFF_8079_LEN) {
|
2017-07-25 21:03:39 +07:00
|
|
|
len = min_t(unsigned int, last, ETH_MODULE_SFF_8472_LEN);
|
|
|
|
len -= first;
|
|
|
|
first -= ETH_MODULE_SFF_8079_LEN;
|
|
|
|
|
2017-12-15 23:09:41 +07:00
|
|
|
ret = sfp_read(sfp, true, first, data, len);
|
2017-07-25 21:03:39 +07:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct sfp_socket_ops sfp_module_ops = {
|
2019-02-06 17:52:30 +07:00
|
|
|
.attach = sfp_attach,
|
|
|
|
.detach = sfp_detach,
|
2017-07-25 21:03:39 +07:00
|
|
|
.start = sfp_start,
|
|
|
|
.stop = sfp_stop,
|
|
|
|
.module_info = sfp_module_info,
|
|
|
|
.module_eeprom = sfp_module_eeprom,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void sfp_timeout(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct sfp *sfp = container_of(work, struct sfp, timeout.work);
|
|
|
|
|
|
|
|
rtnl_lock();
|
|
|
|
sfp_sm_event(sfp, SFP_E_TIMEOUT);
|
|
|
|
rtnl_unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sfp_check_state(struct sfp *sfp)
|
|
|
|
{
|
|
|
|
unsigned int state, i, changed;
|
|
|
|
|
2019-06-07 23:42:36 +07:00
|
|
|
mutex_lock(&sfp->st_mutex);
|
2017-07-25 21:03:39 +07:00
|
|
|
state = sfp_get_state(sfp);
|
|
|
|
changed = state ^ sfp->state;
|
|
|
|
changed &= SFP_F_PRESENT | SFP_F_LOS | SFP_F_TX_FAULT;
|
|
|
|
|
|
|
|
for (i = 0; i < GPIO_MAX; i++)
|
|
|
|
if (changed & BIT(i))
|
|
|
|
dev_dbg(sfp->dev, "%s %u -> %u\n", gpio_of_names[i],
|
|
|
|
!!(sfp->state & BIT(i)), !!(state & BIT(i)));
|
|
|
|
|
|
|
|
state |= sfp->state & (SFP_F_TX_DISABLE | SFP_F_RATE_SELECT);
|
|
|
|
sfp->state = state;
|
|
|
|
|
|
|
|
rtnl_lock();
|
|
|
|
if (changed & SFP_F_PRESENT)
|
|
|
|
sfp_sm_event(sfp, state & SFP_F_PRESENT ?
|
|
|
|
SFP_E_INSERT : SFP_E_REMOVE);
|
|
|
|
|
|
|
|
if (changed & SFP_F_TX_FAULT)
|
|
|
|
sfp_sm_event(sfp, state & SFP_F_TX_FAULT ?
|
|
|
|
SFP_E_TX_FAULT : SFP_E_TX_CLEAR);
|
|
|
|
|
|
|
|
if (changed & SFP_F_LOS)
|
|
|
|
sfp_sm_event(sfp, state & SFP_F_LOS ?
|
|
|
|
SFP_E_LOS_HIGH : SFP_E_LOS_LOW);
|
|
|
|
rtnl_unlock();
|
2019-06-07 23:42:36 +07:00
|
|
|
mutex_unlock(&sfp->st_mutex);
|
2017-07-25 21:03:39 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t sfp_irq(int irq, void *data)
|
|
|
|
{
|
|
|
|
struct sfp *sfp = data;
|
|
|
|
|
|
|
|
sfp_check_state(sfp);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sfp_poll(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct sfp *sfp = container_of(work, struct sfp, poll.work);
|
|
|
|
|
|
|
|
sfp_check_state(sfp);
|
2019-11-20 19:29:59 +07:00
|
|
|
|
|
|
|
if (sfp->state_soft_mask & (SFP_F_LOS | SFP_F_TX_FAULT) ||
|
|
|
|
sfp->need_poll)
|
|
|
|
mod_delayed_work(system_wq, &sfp->poll, poll_jiffies);
|
2017-07-25 21:03:39 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct sfp *sfp_alloc(struct device *dev)
|
|
|
|
{
|
|
|
|
struct sfp *sfp;
|
|
|
|
|
|
|
|
sfp = kzalloc(sizeof(*sfp), GFP_KERNEL);
|
|
|
|
if (!sfp)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
sfp->dev = dev;
|
|
|
|
|
|
|
|
mutex_init(&sfp->sm_mutex);
|
2019-06-07 23:42:36 +07:00
|
|
|
mutex_init(&sfp->st_mutex);
|
2017-07-25 21:03:39 +07:00
|
|
|
INIT_DELAYED_WORK(&sfp->poll, sfp_poll);
|
|
|
|
INIT_DELAYED_WORK(&sfp->timeout, sfp_timeout);
|
|
|
|
|
net: sfp: allow modules with slow diagnostics to probe
When a module is inserted, we attempt to read read the ID from address
0x50. Once we are able to read the ID, we immediately attempt to
initialise the hwmon support by reading from address 0x51. If this
fails, then we fall into error state, and assume that the module is
not usable.
Modules such as the ALCATELLUCENT 3FE46541AA use a real EEPROM for
I2C address 0x50, which responds immediately. However, address 0x51
is an emulated, which only becomes available once the on-board firmware
has booted. This prompts us to fall into the error state.
Since the module may be usable without diagnostics, arrange for the
hwmon probe independent of the rest of the SFP itself, retrying every
5s for up to about 60s for the monitoring to become available, and
print an error message if it doesn't become available.
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-11-10 21:07:35 +07:00
|
|
|
sfp_hwmon_init(sfp);
|
|
|
|
|
2017-07-25 21:03:39 +07:00
|
|
|
return sfp;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sfp_cleanup(void *data)
|
|
|
|
{
|
|
|
|
struct sfp *sfp = data;
|
|
|
|
|
net: sfp: allow modules with slow diagnostics to probe
When a module is inserted, we attempt to read read the ID from address
0x50. Once we are able to read the ID, we immediately attempt to
initialise the hwmon support by reading from address 0x51. If this
fails, then we fall into error state, and assume that the module is
not usable.
Modules such as the ALCATELLUCENT 3FE46541AA use a real EEPROM for
I2C address 0x50, which responds immediately. However, address 0x51
is an emulated, which only becomes available once the on-board firmware
has booted. This prompts us to fall into the error state.
Since the module may be usable without diagnostics, arrange for the
hwmon probe independent of the rest of the SFP itself, retrying every
5s for up to about 60s for the monitoring to become available, and
print an error message if it doesn't become available.
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-11-10 21:07:35 +07:00
|
|
|
sfp_hwmon_exit(sfp);
|
|
|
|
|
2017-07-25 21:03:39 +07:00
|
|
|
cancel_delayed_work_sync(&sfp->poll);
|
|
|
|
cancel_delayed_work_sync(&sfp->timeout);
|
|
|
|
if (sfp->i2c_mii) {
|
|
|
|
mdiobus_unregister(sfp->i2c_mii);
|
|
|
|
mdiobus_free(sfp->i2c_mii);
|
|
|
|
}
|
|
|
|
if (sfp->i2c)
|
|
|
|
i2c_put_adapter(sfp->i2c);
|
|
|
|
kfree(sfp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sfp_probe(struct platform_device *pdev)
|
|
|
|
{
|
2017-12-14 17:27:47 +07:00
|
|
|
const struct sff_data *sff;
|
net: phy: sfp: enable i2c-bus detection on ACPI based systems
Lookup I2C adapter using the "i2c-bus" device property on ACPI based
systems similar to how it's done with DT.
An example DSD describing an SFP on an ACPI based system:
Device (SFP0)
{
Name (_HID, "PRP0001")
Name (_CRS, ResourceTemplate()
{
GpioIo(Exclusive, PullDefault, 0, 0, IoRestrictionNone,
"\\_SB.PCI0.RP01.GPIO", 0, ResourceConsumer)
{ 0, 1, 2, 3, 4 }
})
Name (_DSD, Package ()
{
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package () {
Package () { "compatible", "sff,sfp" },
Package () { "i2c-bus", \_SB.PCI0.RP01.I2C.MUX.CH0 },
Package () { "maximum-power-milliwatt", 1000 },
Package () { "tx-disable-gpios", Package () { ^SFP0, 0, 0, 1} },
Package () { "reset-gpio", Package () { ^SFP0, 0, 1, 1} },
Package () { "mod-def0-gpios", Package () { ^SFP0, 0, 2, 1} },
Package () { "tx-fault-gpios", Package () { ^SFP0, 0, 3, 0} },
Package () { "los-gpios", Package () { ^SFP0, 0, 4, 1} },
},
})
}
Device (PHY0)
{
Name (_HID, "PRP0001")
Name (_DSD, Package ()
{
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package () {
Package () { "compatible", "ethernet-phy-ieee802.3-c45" },
Package () { "sfp", \_SB.PCI0.RP01.SFP0 },
Package () { "managed", "in-band-status" },
Package () { "phy-mode", "sgmii" },
},
})
}
Signed-off-by: Ruslan Babayev <ruslan@babayev.com>
Cc: xe-linux-external@cisco.com
Acked-by: Russell King <rmk+kernel@armlinux.org.uk>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-05-29 06:02:33 +07:00
|
|
|
struct i2c_adapter *i2c;
|
2017-07-25 21:03:39 +07:00
|
|
|
struct sfp *sfp;
|
2019-06-07 23:42:35 +07:00
|
|
|
int err, i;
|
2017-07-25 21:03:39 +07:00
|
|
|
|
|
|
|
sfp = sfp_alloc(&pdev->dev);
|
|
|
|
if (IS_ERR(sfp))
|
|
|
|
return PTR_ERR(sfp);
|
|
|
|
|
|
|
|
platform_set_drvdata(pdev, sfp);
|
|
|
|
|
|
|
|
err = devm_add_action(sfp->dev, sfp_cleanup, sfp);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
2017-12-14 17:27:47 +07:00
|
|
|
sff = sfp->type = &sfp_data;
|
|
|
|
|
2017-07-25 21:03:39 +07:00
|
|
|
if (pdev->dev.of_node) {
|
|
|
|
struct device_node *node = pdev->dev.of_node;
|
2017-12-14 17:27:47 +07:00
|
|
|
const struct of_device_id *id;
|
2017-07-25 21:03:39 +07:00
|
|
|
struct device_node *np;
|
|
|
|
|
2017-12-14 17:27:47 +07:00
|
|
|
id = of_match_node(sfp_of_match, node);
|
|
|
|
if (WARN_ON(!id))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
sff = sfp->type = id->data;
|
|
|
|
|
2017-07-25 21:03:39 +07:00
|
|
|
np = of_parse_phandle(node, "i2c-bus", 0);
|
2018-05-22 17:18:00 +07:00
|
|
|
if (!np) {
|
|
|
|
dev_err(sfp->dev, "missing 'i2c-bus' property\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
i2c = of_find_i2c_adapter_by_node(np);
|
|
|
|
of_node_put(np);
|
net: phy: sfp: enable i2c-bus detection on ACPI based systems
Lookup I2C adapter using the "i2c-bus" device property on ACPI based
systems similar to how it's done with DT.
An example DSD describing an SFP on an ACPI based system:
Device (SFP0)
{
Name (_HID, "PRP0001")
Name (_CRS, ResourceTemplate()
{
GpioIo(Exclusive, PullDefault, 0, 0, IoRestrictionNone,
"\\_SB.PCI0.RP01.GPIO", 0, ResourceConsumer)
{ 0, 1, 2, 3, 4 }
})
Name (_DSD, Package ()
{
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package () {
Package () { "compatible", "sff,sfp" },
Package () { "i2c-bus", \_SB.PCI0.RP01.I2C.MUX.CH0 },
Package () { "maximum-power-milliwatt", 1000 },
Package () { "tx-disable-gpios", Package () { ^SFP0, 0, 0, 1} },
Package () { "reset-gpio", Package () { ^SFP0, 0, 1, 1} },
Package () { "mod-def0-gpios", Package () { ^SFP0, 0, 2, 1} },
Package () { "tx-fault-gpios", Package () { ^SFP0, 0, 3, 0} },
Package () { "los-gpios", Package () { ^SFP0, 0, 4, 1} },
},
})
}
Device (PHY0)
{
Name (_HID, "PRP0001")
Name (_DSD, Package ()
{
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package () {
Package () { "compatible", "ethernet-phy-ieee802.3-c45" },
Package () { "sfp", \_SB.PCI0.RP01.SFP0 },
Package () { "managed", "in-band-status" },
Package () { "phy-mode", "sgmii" },
},
})
}
Signed-off-by: Ruslan Babayev <ruslan@babayev.com>
Cc: xe-linux-external@cisco.com
Acked-by: Russell King <rmk+kernel@armlinux.org.uk>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-05-29 06:02:33 +07:00
|
|
|
} else if (has_acpi_companion(&pdev->dev)) {
|
|
|
|
struct acpi_device *adev = ACPI_COMPANION(&pdev->dev);
|
|
|
|
struct fwnode_handle *fw = acpi_fwnode_handle(adev);
|
|
|
|
struct fwnode_reference_args args;
|
|
|
|
struct acpi_handle *acpi_handle;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = acpi_node_get_property_reference(fw, "i2c-bus", 0, &args);
|
2019-06-13 13:51:02 +07:00
|
|
|
if (ret || !is_acpi_device_node(args.fwnode)) {
|
net: phy: sfp: enable i2c-bus detection on ACPI based systems
Lookup I2C adapter using the "i2c-bus" device property on ACPI based
systems similar to how it's done with DT.
An example DSD describing an SFP on an ACPI based system:
Device (SFP0)
{
Name (_HID, "PRP0001")
Name (_CRS, ResourceTemplate()
{
GpioIo(Exclusive, PullDefault, 0, 0, IoRestrictionNone,
"\\_SB.PCI0.RP01.GPIO", 0, ResourceConsumer)
{ 0, 1, 2, 3, 4 }
})
Name (_DSD, Package ()
{
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package () {
Package () { "compatible", "sff,sfp" },
Package () { "i2c-bus", \_SB.PCI0.RP01.I2C.MUX.CH0 },
Package () { "maximum-power-milliwatt", 1000 },
Package () { "tx-disable-gpios", Package () { ^SFP0, 0, 0, 1} },
Package () { "reset-gpio", Package () { ^SFP0, 0, 1, 1} },
Package () { "mod-def0-gpios", Package () { ^SFP0, 0, 2, 1} },
Package () { "tx-fault-gpios", Package () { ^SFP0, 0, 3, 0} },
Package () { "los-gpios", Package () { ^SFP0, 0, 4, 1} },
},
})
}
Device (PHY0)
{
Name (_HID, "PRP0001")
Name (_DSD, Package ()
{
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package () {
Package () { "compatible", "ethernet-phy-ieee802.3-c45" },
Package () { "sfp", \_SB.PCI0.RP01.SFP0 },
Package () { "managed", "in-band-status" },
Package () { "phy-mode", "sgmii" },
},
})
}
Signed-off-by: Ruslan Babayev <ruslan@babayev.com>
Cc: xe-linux-external@cisco.com
Acked-by: Russell King <rmk+kernel@armlinux.org.uk>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-05-29 06:02:33 +07:00
|
|
|
dev_err(&pdev->dev, "missing 'i2c-bus' property\n");
|
|
|
|
return -ENODEV;
|
2017-07-25 21:03:39 +07:00
|
|
|
}
|
net: phy: sfp: enable i2c-bus detection on ACPI based systems
Lookup I2C adapter using the "i2c-bus" device property on ACPI based
systems similar to how it's done with DT.
An example DSD describing an SFP on an ACPI based system:
Device (SFP0)
{
Name (_HID, "PRP0001")
Name (_CRS, ResourceTemplate()
{
GpioIo(Exclusive, PullDefault, 0, 0, IoRestrictionNone,
"\\_SB.PCI0.RP01.GPIO", 0, ResourceConsumer)
{ 0, 1, 2, 3, 4 }
})
Name (_DSD, Package ()
{
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package () {
Package () { "compatible", "sff,sfp" },
Package () { "i2c-bus", \_SB.PCI0.RP01.I2C.MUX.CH0 },
Package () { "maximum-power-milliwatt", 1000 },
Package () { "tx-disable-gpios", Package () { ^SFP0, 0, 0, 1} },
Package () { "reset-gpio", Package () { ^SFP0, 0, 1, 1} },
Package () { "mod-def0-gpios", Package () { ^SFP0, 0, 2, 1} },
Package () { "tx-fault-gpios", Package () { ^SFP0, 0, 3, 0} },
Package () { "los-gpios", Package () { ^SFP0, 0, 4, 1} },
},
})
}
Device (PHY0)
{
Name (_HID, "PRP0001")
Name (_DSD, Package ()
{
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package () {
Package () { "compatible", "ethernet-phy-ieee802.3-c45" },
Package () { "sfp", \_SB.PCI0.RP01.SFP0 },
Package () { "managed", "in-band-status" },
Package () { "phy-mode", "sgmii" },
},
})
}
Signed-off-by: Ruslan Babayev <ruslan@babayev.com>
Cc: xe-linux-external@cisco.com
Acked-by: Russell King <rmk+kernel@armlinux.org.uk>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-05-29 06:02:33 +07:00
|
|
|
|
|
|
|
acpi_handle = ACPI_HANDLE_FWNODE(args.fwnode);
|
|
|
|
i2c = i2c_acpi_find_adapter_by_handle(acpi_handle);
|
|
|
|
} else {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!i2c)
|
|
|
|
return -EPROBE_DEFER;
|
|
|
|
|
|
|
|
err = sfp_i2c_configure(sfp, i2c);
|
|
|
|
if (err < 0) {
|
|
|
|
i2c_put_adapter(i2c);
|
|
|
|
return err;
|
2017-12-14 17:27:47 +07:00
|
|
|
}
|
2017-07-25 21:03:39 +07:00
|
|
|
|
2017-12-14 17:27:47 +07:00
|
|
|
for (i = 0; i < GPIO_MAX; i++)
|
|
|
|
if (sff->gpios & BIT(i)) {
|
2017-07-25 21:03:39 +07:00
|
|
|
sfp->gpio[i] = devm_gpiod_get_optional(sfp->dev,
|
|
|
|
gpio_of_names[i], gpio_flags[i]);
|
|
|
|
if (IS_ERR(sfp->gpio[i]))
|
|
|
|
return PTR_ERR(sfp->gpio[i]);
|
|
|
|
}
|
|
|
|
|
2017-12-14 17:27:47 +07:00
|
|
|
sfp->get_state = sfp_gpio_get_state;
|
|
|
|
sfp->set_state = sfp_gpio_set_state;
|
|
|
|
|
|
|
|
/* Modules that have no detect signal are always present */
|
|
|
|
if (!(sfp->gpio[GPIO_MODDEF0]))
|
|
|
|
sfp->get_state = sff_gpio_get_state;
|
2017-07-25 21:03:39 +07:00
|
|
|
|
sfp: add high power module support
This patch is the result of work by both Jon Nettleton and Russell King.
Jon wrote the original patch, adding support for SFP modules which
require a power level greater than '1'.
Russell's changes:
- Fix the power levels for big-endian, and make the code flow better.
- Convert to use device_property_read_u8()
- Warn for power levels exceeding host level
SFF-8431 says:
"To avoid exceeding system power supply limits and cooling capacity,
all modules at power up by default shall operate with up to 1.0 W.
Hosts supporting Power Level II or III operation may enable a Power
Level II or III module through the 2-wire interface. Power Level II
or III modules shall assert the power level declaration bit of
SFF-8472."
Print a warning for modules that exceed the host power level, and
leave them operating in power level 1.
- Fix i2c write
The first byte of any write after the bus address is always the
device address. In order to write a value to device D, address I,
value V, we need to generate on the bus:
S DDDDDDDD A IIIIIIII A VVVVVVVV A P
where S = start, R = restart, A = ack, P = stop. Splitting this
as two:
S DDDDDDDD A IIIIIIII A R DDDDDDDD A VVVVVVVV A P
results in the device's address register being written first by I
and then by V - the addressed register within the device is not
written.
- Avoid power mode switching if 0xa2 is not implemented
Some modules indicate that they support power level II or power level
III, but do not implement address 0xa2, meaning that the bit to set
them to high power mode is not accessible.
These modules appear to have the sff8472_compliance field set to zero,
and also do not implement diagnostics. Detect this, but also ensure
that the module does not require the address switching mode, which we
do not implement.
- Use mW for power level rather than power level number.
- Fix high power mode transition
We must not switch to SFP_MOD_PRESENT state until we have finished
initialising, because the remaining state machines check for that
state. Add SFP_MOD_HPOWER as an intermediate state.
- Use definition for I2C register address rather than constant.
Signed-off-by: Jon Nettleton <jon@solid-run.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-02-27 22:53:12 +07:00
|
|
|
device_property_read_u32(&pdev->dev, "maximum-power-milliwatt",
|
|
|
|
&sfp->max_power_mW);
|
|
|
|
if (!sfp->max_power_mW)
|
|
|
|
sfp->max_power_mW = 1000;
|
|
|
|
|
|
|
|
dev_info(sfp->dev, "Host maximum power %u.%uW\n",
|
|
|
|
sfp->max_power_mW / 1000, (sfp->max_power_mW / 100) % 10);
|
|
|
|
|
2017-07-25 21:03:39 +07:00
|
|
|
/* Get the initial state, and always signal TX disable,
|
|
|
|
* since the network interface will not be up.
|
|
|
|
*/
|
|
|
|
sfp->state = sfp_get_state(sfp) | SFP_F_TX_DISABLE;
|
|
|
|
|
|
|
|
if (sfp->gpio[GPIO_RATE_SELECT] &&
|
|
|
|
gpiod_get_value_cansleep(sfp->gpio[GPIO_RATE_SELECT]))
|
|
|
|
sfp->state |= SFP_F_RATE_SELECT;
|
|
|
|
sfp_set_state(sfp, sfp->state);
|
|
|
|
sfp_module_tx_disable(sfp);
|
2019-11-10 21:07:25 +07:00
|
|
|
if (sfp->state & SFP_F_PRESENT) {
|
|
|
|
rtnl_lock();
|
|
|
|
sfp_sm_event(sfp, SFP_E_INSERT);
|
|
|
|
rtnl_unlock();
|
|
|
|
}
|
2017-07-25 21:03:39 +07:00
|
|
|
|
|
|
|
for (i = 0; i < GPIO_MAX; i++) {
|
|
|
|
if (gpio_flags[i] != GPIOD_IN || !sfp->gpio[i])
|
|
|
|
continue;
|
|
|
|
|
2019-06-07 23:42:35 +07:00
|
|
|
sfp->gpio_irq[i] = gpiod_to_irq(sfp->gpio[i]);
|
|
|
|
if (!sfp->gpio_irq[i]) {
|
2019-11-20 19:29:59 +07:00
|
|
|
sfp->need_poll = true;
|
2017-07-25 21:03:39 +07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-06-07 23:42:35 +07:00
|
|
|
err = devm_request_threaded_irq(sfp->dev, sfp->gpio_irq[i],
|
|
|
|
NULL, sfp_irq,
|
2017-07-25 21:03:39 +07:00
|
|
|
IRQF_ONESHOT |
|
|
|
|
IRQF_TRIGGER_RISING |
|
|
|
|
IRQF_TRIGGER_FALLING,
|
|
|
|
dev_name(sfp->dev), sfp);
|
2019-06-07 23:42:35 +07:00
|
|
|
if (err) {
|
|
|
|
sfp->gpio_irq[i] = 0;
|
2019-11-20 19:29:59 +07:00
|
|
|
sfp->need_poll = true;
|
2019-06-07 23:42:35 +07:00
|
|
|
}
|
2017-07-25 21:03:39 +07:00
|
|
|
}
|
|
|
|
|
2019-11-20 19:29:59 +07:00
|
|
|
if (sfp->need_poll)
|
2017-07-25 21:03:39 +07:00
|
|
|
mod_delayed_work(system_wq, &sfp->poll, poll_jiffies);
|
|
|
|
|
2018-05-22 17:17:59 +07:00
|
|
|
/* We could have an issue in cases no Tx disable pin is available or
|
|
|
|
* wired as modules using a laser as their light source will continue to
|
|
|
|
* be active when the fiber is removed. This could be a safety issue and
|
|
|
|
* we should at least warn the user about that.
|
|
|
|
*/
|
|
|
|
if (!sfp->gpio[GPIO_TX_DISABLE])
|
|
|
|
dev_warn(sfp->dev,
|
|
|
|
"No tx_disable pin: SFP modules will always be emitting.\n");
|
|
|
|
|
2019-02-06 17:52:30 +07:00
|
|
|
sfp->sfp_bus = sfp_register_socket(sfp->dev, sfp, &sfp_module_ops);
|
|
|
|
if (!sfp->sfp_bus)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2017-07-25 21:03:39 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sfp_remove(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct sfp *sfp = platform_get_drvdata(pdev);
|
|
|
|
|
|
|
|
sfp_unregister_socket(sfp->sfp_bus);
|
|
|
|
|
2019-12-04 06:51:22 +07:00
|
|
|
rtnl_lock();
|
|
|
|
sfp_sm_event(sfp, SFP_E_REMOVE);
|
|
|
|
rtnl_unlock();
|
|
|
|
|
2017-07-25 21:03:39 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-06-07 23:42:35 +07:00
|
|
|
static void sfp_shutdown(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct sfp *sfp = platform_get_drvdata(pdev);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < GPIO_MAX; i++) {
|
|
|
|
if (!sfp->gpio_irq[i])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
devm_free_irq(sfp->dev, sfp->gpio_irq[i], sfp);
|
|
|
|
}
|
|
|
|
|
|
|
|
cancel_delayed_work_sync(&sfp->poll);
|
|
|
|
cancel_delayed_work_sync(&sfp->timeout);
|
|
|
|
}
|
|
|
|
|
2017-07-25 21:03:39 +07:00
|
|
|
static struct platform_driver sfp_driver = {
|
|
|
|
.probe = sfp_probe,
|
|
|
|
.remove = sfp_remove,
|
2019-06-07 23:42:35 +07:00
|
|
|
.shutdown = sfp_shutdown,
|
2017-07-25 21:03:39 +07:00
|
|
|
.driver = {
|
|
|
|
.name = "sfp",
|
|
|
|
.of_match_table = sfp_of_match,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static int sfp_init(void)
|
|
|
|
{
|
|
|
|
poll_jiffies = msecs_to_jiffies(100);
|
|
|
|
|
|
|
|
return platform_driver_register(&sfp_driver);
|
|
|
|
}
|
|
|
|
module_init(sfp_init);
|
|
|
|
|
|
|
|
static void sfp_exit(void)
|
|
|
|
{
|
|
|
|
platform_driver_unregister(&sfp_driver);
|
|
|
|
}
|
|
|
|
module_exit(sfp_exit);
|
|
|
|
|
|
|
|
MODULE_ALIAS("platform:sfp");
|
|
|
|
MODULE_AUTHOR("Russell King");
|
|
|
|
MODULE_LICENSE("GPL v2");
|