2 * Intel MIC Platform Software Stack (MPSS)
4 * Copyright(c) 2013 Intel Corporation.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License, version 2, as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * The full GNU General Public License is included in this distribution in
16 * the file called "COPYING".
18 * Intel MIC Host driver.
21 #include <linux/delay.h>
22 #include <linux/firmware.h>
24 #include <linux/mic_common.h>
25 #include "../common/mic_dev.h"
26 #include "mic_device.h"
28 #include "mic_virtio.h"
31 * mic_reset - Reset the MIC device.
32 * @mdev: pointer to mic_device instance
34 static void mic_reset(struct mic_device *mdev)
38 #define MIC_RESET_TO (45)
40 mdev->ops->reset_fw_ready(mdev);
41 mdev->ops->reset(mdev);
43 for (i = 0; i < MIC_RESET_TO; i++) {
44 if (mdev->ops->is_fw_ready(mdev))
47 * Resets typically take 10s of seconds to complete.
48 * Since an MMIO read is required to check if the
49 * firmware is ready or not, a 1 second delay works nicely.
53 mic_set_state(mdev, MIC_RESET_FAILED);
56 /* Initialize the MIC bootparams */
57 void mic_bootparam_init(struct mic_device *mdev)
59 struct mic_bootparam *bootparam = mdev->dp;
61 bootparam->magic = MIC_MAGIC;
62 bootparam->c2h_shutdown_db = mdev->shutdown_db;
63 bootparam->h2c_shutdown_db = -1;
64 bootparam->h2c_config_db = -1;
65 bootparam->shutdown_status = 0;
66 bootparam->shutdown_card = 0;
70 * mic_start - Start the MIC.
71 * @mdev: pointer to mic_device instance
72 * @buf: buffer containing boot string including firmware/ramdisk path.
74 * This function prepares an MIC for boot and initiates boot.
75 * RETURNS: An appropriate -ERRNO error value on error, or zero for success.
77 int mic_start(struct mic_device *mdev, const char *buf)
80 mutex_lock(&mdev->mic_mutex);
82 if (MIC_OFFLINE != mdev->state) {
86 if (!mdev->ops->is_fw_ready(mdev)) {
89 * The state will either be MIC_OFFLINE if the reset succeeded
90 * or MIC_RESET_FAILED if the firmware reset failed.
94 rc = mdev->ops->load_mic_fw(mdev, buf);
97 mic_smpt_restore(mdev);
98 mic_intr_restore(mdev);
99 mdev->intr_ops->enable_interrupts(mdev);
100 mdev->ops->write_spad(mdev, MIC_DPLO_SPAD, mdev->dp_dma_addr);
101 mdev->ops->write_spad(mdev, MIC_DPHI_SPAD, mdev->dp_dma_addr >> 32);
102 mdev->ops->send_firmware_intr(mdev);
103 mic_set_state(mdev, MIC_ONLINE);
105 mutex_unlock(&mdev->mic_mutex);
110 * mic_stop - Prepare the MIC for reset and trigger reset.
111 * @mdev: pointer to mic_device instance
112 * @force: force a MIC to reset even if it is already offline.
116 void mic_stop(struct mic_device *mdev, bool force)
118 mutex_lock(&mdev->mic_mutex);
119 if (MIC_OFFLINE != mdev->state || force) {
120 mic_virtio_reset_devices(mdev);
121 mic_bootparam_init(mdev);
123 if (MIC_RESET_FAILED == mdev->state)
125 mic_set_shutdown_status(mdev, MIC_NOP);
126 mic_set_state(mdev, MIC_OFFLINE);
129 mutex_unlock(&mdev->mic_mutex);
133 * mic_shutdown - Initiate MIC shutdown.
134 * @mdev: pointer to mic_device instance
138 void mic_shutdown(struct mic_device *mdev)
140 struct mic_bootparam *bootparam = mdev->dp;
141 s8 db = bootparam->h2c_shutdown_db;
143 mutex_lock(&mdev->mic_mutex);
144 if (MIC_ONLINE == mdev->state && db != -1) {
145 bootparam->shutdown_card = 1;
146 mdev->ops->send_intr(mdev, db);
147 mic_set_state(mdev, MIC_SHUTTING_DOWN);
149 mutex_unlock(&mdev->mic_mutex);
153 * mic_shutdown_work - Handle shutdown interrupt from MIC.
154 * @work: The work structure.
156 * This work is scheduled whenever the host has received a shutdown
157 * interrupt from the MIC.
159 void mic_shutdown_work(struct work_struct *work)
161 struct mic_device *mdev = container_of(work, struct mic_device,
163 struct mic_bootparam *bootparam = mdev->dp;
165 mutex_lock(&mdev->mic_mutex);
166 mic_set_shutdown_status(mdev, bootparam->shutdown_status);
167 bootparam->shutdown_status = 0;
168 if (MIC_SHUTTING_DOWN != mdev->state)
169 mic_set_state(mdev, MIC_SHUTTING_DOWN);
170 mutex_unlock(&mdev->mic_mutex);
174 * mic_reset_trigger_work - Trigger MIC reset.
175 * @work: The work structure.
177 * This work is scheduled whenever the host wants to reset the MIC.
179 void mic_reset_trigger_work(struct work_struct *work)
181 struct mic_device *mdev = container_of(work, struct mic_device,
184 mic_stop(mdev, false);