Skip to content

Commit 7d4093d

Browse files
brandonchuanglguohan
authored andcommitted
[device/platform] Add reset in sfputil.py for Accton AS7326-56X (#3685)
Add reset in sfputil.py for as7326-56x. Signed-off-by: brandon_chuang <[email protected]>
1 parent 65fc916 commit 7d4093d

File tree

2 files changed

+109
-2
lines changed
  • device/accton/x86_64-accton_as7326_56x-r0/plugins
  • platform/broadcom/sonic-platform-modules-accton/as7326-56x/modules

2 files changed

+109
-2
lines changed

device/accton/x86_64-accton_as7326_56x-r0/plugins/sfputil.py

+23-1
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,30 @@ def set_low_power_mode(self, port_num, lpmode):
219219
time.sleep(0.01)
220220

221221
def reset(self, port_num):
222-
raise NotImplementedError
222+
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
223+
return False
224+
225+
cpld_i = self.get_cpld_num(port_num)
226+
cpld_ps = self._cpld_mapping[cpld_i]
227+
path = "/sys/bus/i2c/devices/{0}/module_reset_{1}"
228+
port_ps = path.format(cpld_ps, port_num)
229+
230+
self.__port_to_mod_rst = port_ps
231+
try:
232+
reg_file = open(self.__port_to_mod_rst, 'r+', buffering=0)
233+
except IOError as e:
234+
print "Error: unable to open file: %s" % str(e)
235+
return False
223236

237+
#toggle reset
238+
reg_file.seek(0)
239+
reg_file.write('1')
240+
time.sleep(1)
241+
reg_file.seek(0)
242+
reg_file.write('0')
243+
reg_file.close()
244+
245+
return True
224246
@property
225247
def _get_present_bitmap(self):
226248
nodes = []

platform/broadcom/sonic-platform-modules-accton/as7326-56x/modules/accton_i2c_cpld.c

+86-1
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,14 @@ enum as7326_56x_cpld_sysfs_attributes {
285285
TRANSCEIVER_TXFAULT_ATTR_ID(48),
286286
TRANSCEIVER_TXFAULT_ATTR_ID(57),
287287
TRANSCEIVER_TXFAULT_ATTR_ID(58),
288+
TRANSCEIVER_RESET_ATTR_ID(49),
289+
TRANSCEIVER_RESET_ATTR_ID(50),
290+
TRANSCEIVER_RESET_ATTR_ID(51),
291+
TRANSCEIVER_RESET_ATTR_ID(52),
292+
TRANSCEIVER_RESET_ATTR_ID(53),
293+
TRANSCEIVER_RESET_ATTR_ID(54),
294+
TRANSCEIVER_RESET_ATTR_ID(55),
295+
TRANSCEIVER_RESET_ATTR_ID(56),
288296
};
289297

290298
/* sysfs attributes for hwmon
@@ -297,6 +305,8 @@ static ssize_t show_rxlos_all(struct device *dev, struct device_attribute *da,
297305
char *buf);
298306
static ssize_t set_tx_disable(struct device *dev, struct device_attribute *da,
299307
const char *buf, size_t count);
308+
static ssize_t set_reset(struct device *dev, struct device_attribute *da,
309+
const char *buf, size_t count);
300310
static ssize_t access(struct device *dev, struct device_attribute *da,
301311
const char *buf, size_t count);
302312
static ssize_t show_version(struct device *dev, struct device_attribute *da,
@@ -437,6 +447,15 @@ DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(48);
437447
DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(57);
438448
DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(58);
439449

450+
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(49);
451+
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(50);
452+
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(51);
453+
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(52);
454+
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(53);
455+
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(54);
456+
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(55);
457+
DECLARE_TRANSCEIVER_RESET_SENSOR_DEVICE_ATTR(56);
458+
440459
static struct attribute *as7326_56x_cpld3_attributes[] = {
441460
&sensor_dev_attr_version.dev_attr.attr,
442461
&sensor_dev_attr_access.dev_attr.attr,
@@ -507,7 +526,7 @@ static struct attribute *as7326_56x_cpld2_attributes[] = {
507526
DECLARE_SFP_TRANSCEIVER_ATTR(22),
508527
DECLARE_SFP_TRANSCEIVER_ATTR(23),
509528
DECLARE_SFP_TRANSCEIVER_ATTR(24),
510-
DECLARE_SFP_TRANSCEIVER_ATTR(25),
529+
DECLARE_SFP_TRANSCEIVER_ATTR(25),
511530
DECLARE_SFP_TRANSCEIVER_ATTR(26),
512531
DECLARE_SFP_TRANSCEIVER_ATTR(27),
513532
DECLARE_SFP_TRANSCEIVER_ATTR(28),
@@ -574,6 +593,14 @@ static struct attribute *as7326_56x_cpld1_attributes[] = {
574593
DECLARE_SFP_TRANSCEIVER_ATTR(48),
575594
DECLARE_SFP_TRANSCEIVER_ATTR(57),
576595
DECLARE_SFP_TRANSCEIVER_ATTR(58),
596+
DECLARE_TRANSCEIVER_RESET_ATTR(49),
597+
DECLARE_TRANSCEIVER_RESET_ATTR(50),
598+
DECLARE_TRANSCEIVER_RESET_ATTR(51),
599+
DECLARE_TRANSCEIVER_RESET_ATTR(52),
600+
DECLARE_TRANSCEIVER_RESET_ATTR(53),
601+
DECLARE_TRANSCEIVER_RESET_ATTR(54),
602+
DECLARE_TRANSCEIVER_RESET_ATTR(55),
603+
DECLARE_TRANSCEIVER_RESET_ATTR(56),
577604
NULL
578605
};
579606

@@ -724,6 +751,11 @@ static ssize_t show_status(struct device *dev, struct device_attribute *da,
724751
reg = 0x19;
725752
mask = 0x1 << (( attr->index - MODULE_RXLOS_57)+2);
726753
break;
754+
case MODULE_RESET_49 ... MODULE_RESET_56:
755+
reg = 0x4;
756+
mask = 0x1 << (attr->index - MODULE_RESET_49);
757+
revert = 1;
758+
break;
727759
default:
728760
return 0;
729761
}
@@ -806,6 +838,59 @@ static ssize_t set_tx_disable(struct device *dev, struct device_attribute *da,
806838
return status;
807839
}
808840

841+
static ssize_t set_reset(struct device *dev, struct device_attribute *da,
842+
const char *buf, size_t count)
843+
{
844+
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
845+
struct i2c_client *client = to_i2c_client(dev);
846+
struct as7326_56x_cpld_data *data = i2c_get_clientdata(client);
847+
long reset;
848+
int status;
849+
u8 reg = 0, mask = 0;
850+
851+
status = kstrtol(buf, 10, &reset);
852+
if (status) {
853+
return status;
854+
}
855+
856+
switch (attr->index)
857+
{
858+
case MODULE_RESET_49 ... MODULE_RESET_56:
859+
reg = 0x4;
860+
mask = 0x1 << (attr->index - MODULE_RESET_49);
861+
break;
862+
default:
863+
return 0;
864+
}
865+
866+
/* Read current status */
867+
mutex_lock(&data->update_lock);
868+
status = as7326_56x_cpld_read_internal(client, reg);
869+
if (unlikely(status < 0)) {
870+
goto exit;
871+
}
872+
873+
/* Update reset status */
874+
if (!reset) {
875+
status |= mask;
876+
}
877+
else {
878+
status &= ~mask;
879+
}
880+
881+
status = as7326_56x_cpld_write_internal(client, reg, status);
882+
if (unlikely(status < 0)) {
883+
goto exit;
884+
}
885+
886+
mutex_unlock(&data->update_lock);
887+
return count;
888+
889+
exit:
890+
mutex_unlock(&data->update_lock);
891+
return status;
892+
}
893+
809894
static ssize_t access(struct device *dev, struct device_attribute *da,
810895
const char *buf, size_t count)
811896
{

0 commit comments

Comments
 (0)