Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bmc_application: restore power and usb settings #72

Merged
merged 2 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/api/streaming_data_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl StreamingDataService {
let (written_sender, written_receiver) = watch::channel(0u64);
let cancel = CancellationToken::new();
let (sender, worker) = action
.into_data_processor(64, written_sender, cancel.child_token())
.into_data_processor(256, written_sender, cancel.child_token())
.await?;
let context =
TransferContext::new(id, process_name, size, written_receiver, sender, cancel);
Expand Down
30 changes: 21 additions & 9 deletions src/app/bmc_application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,12 @@ impl BmcApplication {
self.initialize_power().await
}

async fn initialize_power(&self) -> anyhow::Result<()> {
pub async fn initialize_power(&self) -> anyhow::Result<()> {
if self.app_db.get::<u8>(ACTIVATED_NODES_KEY).await != 0 {
self.power_on().await?;
self.power_on().await
} else {
self.power_off().await
}
Ok(())
}

async fn initialize_usb_mode(&self) -> anyhow::Result<()> {
Expand Down Expand Up @@ -187,7 +188,19 @@ impl BmcApplication {
self.power_controller.set_power_node(0b0000, 0b1111).await
}

pub async fn power_off_node(&self, node: NodeId) -> anyhow::Result<()> {
self.power_controller
.set_power_node(node.to_bitfield(), node.to_bitfield())
.await
}

pub async fn configure_usb(&self, config: UsbConfig) -> anyhow::Result<()> {
self.configure_usb_internal(config).await?;
self.app_db.set(USB_CONFIG, config).await;
Ok(())
}

async fn configure_usb_internal(&self, config: UsbConfig) -> anyhow::Result<()> {
log::debug!("changing usb config to {:?}", config);
let (mode, dest, route) = match config {
UsbConfig::UsbA(device) => (UsbMode::Device, device, UsbRoute::UsbA),
Expand All @@ -197,7 +210,6 @@ impl BmcApplication {

self.pin_controller.set_usb_route(route).await?;
self.pin_controller.select_usb(dest, mode)?;
self.app_db.set(USB_CONFIG, config).await;
Ok(())
}

Expand All @@ -220,8 +232,6 @@ impl BmcApplication {
}

pub async fn set_node_in_msd(&self, node: NodeId, router: UsbRoute) -> anyhow::Result<()> {
// The SUPPORTED_MSD_DEVICES list contains vid_pids of USB drivers we know will load the
// storage of a node as a MSD device.
self.configure_node_for_fwupgrade(node, router, SUPPORTED_DEVICES.keys())
.await
.map(|_| ())
Expand All @@ -237,7 +247,8 @@ impl BmcApplication {
I: IntoIterator<Item = &'a (u16, u16)>,
{
log::info!("Powering off node {:?}...", node);
self.activate_slot(!node.to_bitfield(), node.to_bitfield())
self.power_controller
.set_power_node(!node.to_bitfield(), node.to_bitfield())
.await?;
self.pin_controller
.set_usb_boot(!node.to_bitfield(), node.to_bitfield())?;
Expand All @@ -249,10 +260,11 @@ impl BmcApplication {
UsbRoute::UsbA => UsbConfig::UsbA(node),
};
self.usb_boot(node, true).await?;
self.configure_usb(config).await?;
self.configure_usb_internal(config).await?;

log::info!("Prerequisite settings toggled, powering on...");
self.activate_slot(node.to_bitfield(), node.to_bitfield())
self.power_controller
.set_power_node(node.to_bitfield(), node.to_bitfield())
.await?;

tokio::time::sleep(Duration::from_secs(1)).await;
Expand Down
15 changes: 4 additions & 11 deletions src/app/firmware_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use super::bmc_application::UsbConfig;
use crate::app::bmc_application::BmcApplication;
use crate::firmware_update::FwUpdateError;
use crate::utils::{reader_with_crc64, WriteWatcher};
Expand Down Expand Up @@ -100,17 +99,11 @@ impl FirmwareRunner {
bail!(FwUpdateError::ChecksumMismatch)
}

log::info!("Flashing {node} successful, restarting device...");
bmc.activate_slot(!node.to_bitfield(), node.to_bitfield())
.await?;

//TODO: we probably want to restore the state prior flashing
log::info!("Flashing {node} successful, restoring USB & power settings...");
bmc.power_off_node(node).await?;
bmc.usb_boot(node, false).await?;
bmc.configure_usb(UsbConfig::UsbA(node)).await?;
bmc.activate_slot(node.to_bitfield(), node.to_bitfield())
.await?;

Ok(())
bmc.configure_usb(bmc.get_usb_mode().await).await?;
bmc.initialize_power().await
}

pub async fn os_update(self) -> anyhow::Result<()> {
Expand Down
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ fn init_logger() {

simple_logger::SimpleLogger::new()
.with_level(level)
.with_module_level("bmcd", LevelFilter::Info)
.with_module_level("actix_http", LevelFilter::Info)
.with_module_level("h2", LevelFilter::Info)
.with_colors(true)
Expand Down
Loading