summaryrefslogtreecommitdiffstats
path: root/deploy/dha_adapters/ipmi_adapter.py
blob: 7cc9305546bad1901bbd2cc4e0bba7dd0780442e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
###############################################################################
# Copyright (c) 2015 Ericsson AB and others.
#           (c) 2016 Enea Software AB
# szilard.cserey@ericsson.com
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
###############################################################################


import time
from hardware_adapter import HardwareAdapter

from common import (
    log,
    exec_cmd,
    err,
)


class IpmiAdapter(HardwareAdapter):

    def __init__(self, yaml_path, attempts=20, delay=3):
        super(IpmiAdapter, self).__init__(yaml_path)
        self.attempts = attempts
        self.delay = delay

    def get_access_info(self, node_id):
        ip = self.get_node_property(node_id, 'ipmiIp')
        username = self.get_node_property(node_id, 'ipmiUser')
        password = self.get_node_property(node_id, 'ipmiPass')
        ipmiport = self.get_node_property(node_id, 'ipmiPort')
        return ip, username, password, ipmiport

    def ipmi_cmd(self, node_id):
        ip, username, password, ipmiport = self.get_access_info(node_id)
        cmd = 'ipmitool -I lanplus -A password'
        cmd += ' -H %s -U %s -P %s' % (ip, username, password)
        if ipmiport:
            cmd += ' -p %d' % int(ipmiport)
        return cmd

    def get_node_pxe_mac(self, node_id):
        mac_list = []
        mac_list.append(self.get_node_property(node_id, 'pxeMac').lower())
        return mac_list

    def node_get_state(self, node_id):
        state = exec_cmd('%s chassis power status' % self.ipmi_cmd(node_id),
                         attempts=self.attempts, delay=self.delay,
                         verbose=True,
                         mask_args=[8,10])
        return state

    def _node_power_cmd(self, node_id, cmd):
        expected = 'Chassis Power is %s' % cmd
        if self.node_get_state(node_id) == expected:
            return

        pow_cmd = '%s chassis power %s' % (self.ipmi_cmd(node_id), cmd)
        exec_cmd(pow_cmd, attempts=self.attempts, delay=self.delay,
                 verbose=True,
                 mask_args=[8,10])

        attempts = self.attempts
        while attempts:
            time.sleep(self.delay)
            state = self.node_get_state(node_id)
            attempts -= 1
            if state == expected:
                return
            elif attempts != 0:
                # reinforce our will, but allow the command to fail,
                # we know our message got across once already...
                exec_cmd(pow_cmd, check=False, mask_args=[8,10])

        err('Could not set chassis %s for node %s' % (cmd, node_id))

    def node_power_on(self, node_id):
        log('Power ON Node %s' % node_id)
        self._node_power_cmd(node_id, 'on')

    def node_power_off(self, node_id):
        log('Power OFF Node %s' % node_id)
        self._node_power_cmd(node_id, 'off')

    def node_reset(self, node_id):
        log('RESET Node %s' % node_id)
        cmd = '%s chassis power reset' % self.ipmi_cmd(node_id)
        exec_cmd(cmd, attempts=self.attempts, delay=self.delay,
                 verbose=True,
                 mask_args=[8,10])

    def node_set_boot_order(self, node_id, boot_order_list):
        log('Set boot order %s on Node %s' % (boot_order_list, node_id))
        boot_order_list.reverse()
        cmd_prefix = self.ipmi_cmd(node_id)
        for dev in boot_order_list:
            if dev == 'pxe':
                exec_cmd('%s chassis bootdev pxe options=persistent'
                         % cmd_prefix, attempts=self.attempts, delay=self.delay,
                         verbose=True,
                         mask_args=[8,10])
            elif dev == 'iso':
                exec_cmd('%s chassis bootdev cdrom' % cmd_prefix,
                         attempts=self.attempts, delay=self.delay,
                         verbose=True,
                         mask_args=[8,10])
            elif dev == 'disk':
                exec_cmd('%s chassis bootdev disk options=persistent'
                         % cmd_prefix, attempts=self.attempts, delay=self.delay,
                         verbose=True,
                         mask_args=[8,10])
"kt">void dspics_resets_init(void) { if (!gpio_request(TRSLAT_RST_B, "translator-rst")) { gpio_direction_output(TRSLAT_RST_B, 0); gpio_export(TRSLAT_RST_B, false); } if (!gpio_request(DSPICS_RST_B, "dspics-rst")) { gpio_direction_output(DSPICS_RST_B, 0); gpio_export(DSPICS_RST_B, false); } } static struct spi_board_info marxbot_spi_board_info[] __initdata = { { .modalias = "spidev", .max_speed_hz = 300000, .bus_num = 1, .chip_select = 1, /* according spi1_cs[] ! */ }, }; #define TURRETCAM_POWER IOMUX_TO_GPIO(MX31_PIN_GPIO3_1) #define BASECAM_POWER IOMUX_TO_GPIO(MX31_PIN_CSI_D5) #define TURRETCAM_RST_B IOMUX_TO_GPIO(MX31_PIN_GPIO3_0) #define BASECAM_RST_B IOMUX_TO_GPIO(MX31_PIN_CSI_D4) #define CAM_CHOICE IOMUX_TO_GPIO(MX31_PIN_TXD2) static int marxbot_basecam_power(struct device *dev, int on) { gpio_set_value(BASECAM_POWER, !on); return 0; } static int marxbot_basecam_reset(struct device *dev) { gpio_set_value(BASECAM_RST_B, 0); udelay(100); gpio_set_value(BASECAM_RST_B, 1); return 0; } static struct i2c_board_info marxbot_i2c_devices[] = { { I2C_BOARD_INFO("mt9t031", 0x5d), }, }; static struct soc_camera_link base_iclink = { .bus_id = 0, /* Must match with the camera ID */ .power = marxbot_basecam_power, .reset = marxbot_basecam_reset, .board_info = &marxbot_i2c_devices[0], .i2c_adapter_id = 0, }; static struct platform_device marxbot_camera[] = { { .name = "soc-camera-pdrv", .id = 0, .dev = { .platform_data = &base_iclink, }, }, }; static struct platform_device *marxbot_cameras[] __initdata = { &marxbot_camera[0], }; static int __init marxbot_cam_init(void) { int ret = gpio_request(CAM_CHOICE, "cam-choice"); if (ret) return ret; gpio_direction_output(CAM_CHOICE, 0); ret = gpio_request(BASECAM_RST_B, "basecam-reset"); if (ret) return ret; gpio_direction_output(BASECAM_RST_B, 1); ret = gpio_request(BASECAM_POWER, "basecam-standby"); if (ret) return ret; gpio_direction_output(BASECAM_POWER, 0); ret = gpio_request(TURRETCAM_RST_B, "turretcam-reset"); if (ret) return ret; gpio_direction_output(TURRETCAM_RST_B, 1); ret = gpio_request(TURRETCAM_POWER, "turretcam-standby"); if (ret) return ret; gpio_direction_output(TURRETCAM_POWER, 0); return 0; } #define SEL0 IOMUX_TO_GPIO(MX31_PIN_DTR_DCE1) #define SEL1 IOMUX_TO_GPIO(MX31_PIN_DSR_DCE1) #define SEL2 IOMUX_TO_GPIO(MX31_PIN_RI_DCE1) #define SEL3 IOMUX_TO_GPIO(MX31_PIN_DCD_DCE1) static void marxbot_init_sel_gpios(void) { if (!gpio_request(SEL0, "sel0")) { gpio_direction_input(SEL0); gpio_export(SEL0, true); } if (!gpio_request(SEL1, "sel1")) { gpio_direction_input(SEL1); gpio_export(SEL1, true); } if (!gpio_request(SEL2, "sel2")) { gpio_direction_input(SEL2); gpio_export(SEL2, true); } if (!gpio_request(SEL3, "sel3")) { gpio_direction_input(SEL3); gpio_export(SEL3, true); } } #define USB_PAD_CFG (PAD_CTL_DRV_MAX | PAD_CTL_SRE_FAST | PAD_CTL_HYS_CMOS | \ PAD_CTL_ODE_CMOS | PAD_CTL_100K_PU) static int marxbot_usbh1_hw_init(struct platform_device *pdev) { mxc_iomux_set_gpr(MUX_PGP_USB_SUSPEND, true); mxc_iomux_set_pad(MX31_PIN_CSPI1_MISO, USB_PAD_CFG); mxc_iomux_set_pad(MX31_PIN_CSPI1_MOSI, USB_PAD_CFG); mxc_iomux_set_pad(MX31_PIN_CSPI1_SS0, USB_PAD_CFG); mxc_iomux_set_pad(MX31_PIN_CSPI1_SS1, USB_PAD_CFG); mxc_iomux_set_pad(MX31_PIN_CSPI1_SS2, USB_PAD_CFG); mxc_iomux_set_pad(MX31_PIN_CSPI1_SCLK, USB_PAD_CFG); mxc_iomux_set_pad(MX31_PIN_CSPI1_SPI_RDY, USB_PAD_CFG); mxc_iomux_set_pad(MX31_PIN_SFS6, USB_PAD_CFG); mdelay(10); return mx31_initialize_usb_hw(pdev->id, MXC_EHCI_POWER_PINS_ENABLED | MXC_EHCI_INTERFACE_SINGLE_UNI); } #define USBH1_VBUSEN_B IOMUX_TO_GPIO(MX31_PIN_NFRE_B) #define USBH1_MODE IOMUX_TO_GPIO(MX31_PIN_NFALE) static int marxbot_isp1105_init(struct usb_phy *otg) { int ret = gpio_request(USBH1_MODE, "usbh1-mode"); if (ret) return ret; /* single ended */ gpio_direction_output(USBH1_MODE, 0); ret = gpio_request(USBH1_VBUSEN_B, "usbh1-vbusen"); if (ret) { gpio_free(USBH1_MODE); return ret; } gpio_direction_output(USBH1_VBUSEN_B, 1); return 0; } static int marxbot_isp1105_set_vbus(struct usb_otg *otg, bool on) { if (on) gpio_set_value(USBH1_VBUSEN_B, 0); else gpio_set_value(USBH1_VBUSEN_B, 1); return 0; } static struct mxc_usbh_platform_data usbh1_pdata __initdata = { .init = marxbot_usbh1_hw_init, .portsc = MXC_EHCI_MODE_UTMI | MXC_EHCI_SERIAL, }; static int __init marxbot_usbh1_init(void) { struct usb_phy *phy; struct platform_device *pdev; phy = kzalloc(sizeof(*phy), GFP_KERNEL); if (!phy) return -ENOMEM; phy->otg = kzalloc(sizeof(struct usb_otg), GFP_KERNEL); if (!phy->otg) { kfree(phy); return -ENOMEM; } phy->label = "ISP1105"; phy->init = marxbot_isp1105_init; phy->otg->set_vbus = marxbot_isp1105_set_vbus; usbh1_pdata.otg = phy; pdev = imx31_add_mxc_ehci_hs(1, &usbh1_pdata); return PTR_ERR_OR_ZERO(pdev); } static const struct fsl_usb2_platform_data usb_pdata __initconst = { .operating_mode = FSL_USB2_DR_DEVICE, .phy_mode = FSL_USB2_PHY_ULPI, }; /* * system init for baseboard usage. Will be called by mx31moboard init. */ void __init mx31moboard_marxbot_init(void) { printk(KERN_INFO "Initializing mx31marxbot peripherals\n"); mxc_iomux_setup_multiple_pins(marxbot_pins, ARRAY_SIZE(marxbot_pins), "marxbot"); marxbot_init_sel_gpios(); dspics_resets_init(); imx31_add_mxc_mmc(1, &sdhc2_pdata); spi_register_board_info(marxbot_spi_board_info, ARRAY_SIZE(marxbot_spi_board_info)); marxbot_cam_init(); platform_add_devices(marxbot_cameras, ARRAY_SIZE(marxbot_cameras)); /* battery present pin */ gpio_request(IOMUX_TO_GPIO(MX31_PIN_LCS0), "bat-present"); gpio_direction_input(IOMUX_TO_GPIO(MX31_PIN_LCS0)); gpio_export(IOMUX_TO_GPIO(MX31_PIN_LCS0), false); imx31_add_fsl_usb2_udc(&usb_pdata); marxbot_usbh1_init(); }