Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

soc: qcom: ipa: modem and microcontroller

This patch includes code implementing the modem functionality.
There are several communication paths between the AP and modem,
separate from the main data path provided by IPA. SMP2P provides
primitive messaging and interrupt capability, and QMI allows more
complex out-of-band messaging to occur between entities on the AP
and modem. (SMP2P and QMI support are added by the next patch.)
Management of these (plus the network device implementing the data
path) is done by code within "ipa_modem.c".

Sort of unrelated, this patch also includes the code supporting the
microcontroller CPU present on the IPA. The microcontroller can be
used to implement special handling of packets, but at this time we
don't support that. Still, it is a component that needs to be
initialized, and in the event of a crash we need to do some
synchronization between the AP and the microcontroller.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Alex Elder and committed by
David S. Miller
a646d6ec 731c46ed

+657
+383
drivers/net/ipa/ipa_modem.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + 3 + /* Copyright (c) 2014-2018, The Linux Foundation. All rights reserved. 4 + * Copyright (C) 2018-2020 Linaro Ltd. 5 + */ 6 + 7 + #include <linux/errno.h> 8 + #include <linux/if_arp.h> 9 + #include <linux/netdevice.h> 10 + #include <linux/skbuff.h> 11 + #include <linux/if_rmnet.h> 12 + #include <linux/remoteproc/qcom_q6v5_ipa_notify.h> 13 + 14 + #include "ipa.h" 15 + #include "ipa_data.h" 16 + #include "ipa_endpoint.h" 17 + #include "ipa_table.h" 18 + #include "ipa_mem.h" 19 + #include "ipa_modem.h" 20 + #include "ipa_smp2p.h" 21 + #include "ipa_qmi.h" 22 + 23 + #define IPA_NETDEV_NAME "rmnet_ipa%d" 24 + #define IPA_NETDEV_TAILROOM 0 /* for padding by mux layer */ 25 + #define IPA_NETDEV_TIMEOUT 10 /* seconds */ 26 + 27 + enum ipa_modem_state { 28 + IPA_MODEM_STATE_STOPPED = 0, 29 + IPA_MODEM_STATE_STARTING, 30 + IPA_MODEM_STATE_RUNNING, 31 + IPA_MODEM_STATE_STOPPING, 32 + }; 33 + 34 + /** struct ipa_priv - IPA network device private data */ 35 + struct ipa_priv { 36 + struct ipa *ipa; 37 + }; 38 + 39 + /** ipa_open() - Opens the modem network interface */ 40 + static int ipa_open(struct net_device *netdev) 41 + { 42 + struct ipa_priv *priv = netdev_priv(netdev); 43 + struct ipa *ipa = priv->ipa; 44 + int ret; 45 + 46 + ret = ipa_endpoint_enable_one(ipa->name_map[IPA_ENDPOINT_AP_MODEM_TX]); 47 + if (ret) 48 + return ret; 49 + ret = ipa_endpoint_enable_one(ipa->name_map[IPA_ENDPOINT_AP_MODEM_RX]); 50 + if (ret) 51 + goto err_disable_tx; 52 + 53 + netif_start_queue(netdev); 54 + 55 + return 0; 56 + 57 + err_disable_tx: 58 + ipa_endpoint_disable_one(ipa->name_map[IPA_ENDPOINT_AP_MODEM_TX]); 59 + 60 + return ret; 61 + } 62 + 63 + /** ipa_stop() - Stops the modem network interface. */ 64 + static int ipa_stop(struct net_device *netdev) 65 + { 66 + struct ipa_priv *priv = netdev_priv(netdev); 67 + struct ipa *ipa = priv->ipa; 68 + 69 + netif_stop_queue(netdev); 70 + 71 + ipa_endpoint_disable_one(ipa->name_map[IPA_ENDPOINT_AP_MODEM_RX]); 72 + ipa_endpoint_disable_one(ipa->name_map[IPA_ENDPOINT_AP_MODEM_TX]); 73 + 74 + return 0; 75 + } 76 + 77 + /** ipa_start_xmit() - Transmits an skb. 78 + * @skb: skb to be transmitted 79 + * @dev: network device 80 + * 81 + * Return codes: 82 + * NETDEV_TX_OK: Success 83 + * NETDEV_TX_BUSY: Error while transmitting the skb. Try again later 84 + */ 85 + static int ipa_start_xmit(struct sk_buff *skb, struct net_device *netdev) 86 + { 87 + struct net_device_stats *stats = &netdev->stats; 88 + struct ipa_priv *priv = netdev_priv(netdev); 89 + struct ipa_endpoint *endpoint; 90 + struct ipa *ipa = priv->ipa; 91 + u32 skb_len = skb->len; 92 + int ret; 93 + 94 + if (!skb_len) 95 + goto err_drop_skb; 96 + 97 + endpoint = ipa->name_map[IPA_ENDPOINT_AP_MODEM_TX]; 98 + if (endpoint->data->qmap && skb->protocol != htons(ETH_P_MAP)) 99 + goto err_drop_skb; 100 + 101 + ret = ipa_endpoint_skb_tx(endpoint, skb); 102 + if (ret) { 103 + if (ret != -E2BIG) 104 + return NETDEV_TX_BUSY; 105 + goto err_drop_skb; 106 + } 107 + 108 + stats->tx_packets++; 109 + stats->tx_bytes += skb_len; 110 + 111 + return NETDEV_TX_OK; 112 + 113 + err_drop_skb: 114 + dev_kfree_skb_any(skb); 115 + stats->tx_dropped++; 116 + 117 + return NETDEV_TX_OK; 118 + } 119 + 120 + void ipa_modem_skb_rx(struct net_device *netdev, struct sk_buff *skb) 121 + { 122 + struct net_device_stats *stats = &netdev->stats; 123 + 124 + if (skb) { 125 + skb->dev = netdev; 126 + skb->protocol = htons(ETH_P_MAP); 127 + stats->rx_packets++; 128 + stats->rx_bytes += skb->len; 129 + 130 + (void)netif_receive_skb(skb); 131 + } else { 132 + stats->rx_dropped++; 133 + } 134 + } 135 + 136 + static const struct net_device_ops ipa_modem_ops = { 137 + .ndo_open = ipa_open, 138 + .ndo_stop = ipa_stop, 139 + .ndo_start_xmit = ipa_start_xmit, 140 + }; 141 + 142 + /** ipa_modem_netdev_setup() - netdev setup function for the modem */ 143 + static void ipa_modem_netdev_setup(struct net_device *netdev) 144 + { 145 + netdev->netdev_ops = &ipa_modem_ops; 146 + ether_setup(netdev); 147 + /* No header ops (override value set by ether_setup()) */ 148 + netdev->header_ops = NULL; 149 + netdev->type = ARPHRD_RAWIP; 150 + netdev->hard_header_len = 0; 151 + netdev->max_mtu = IPA_MTU; 152 + netdev->mtu = netdev->max_mtu; 153 + netdev->addr_len = 0; 154 + netdev->flags &= ~(IFF_BROADCAST | IFF_MULTICAST); 155 + /* The endpoint is configured for QMAP */ 156 + netdev->needed_headroom = sizeof(struct rmnet_map_header); 157 + netdev->needed_tailroom = IPA_NETDEV_TAILROOM; 158 + netdev->watchdog_timeo = IPA_NETDEV_TIMEOUT * HZ; 159 + netdev->hw_features = NETIF_F_SG; 160 + } 161 + 162 + /** ipa_modem_suspend() - suspend callback 163 + * @netdev: Network device 164 + * 165 + * Suspend the modem's endpoints. 166 + */ 167 + void ipa_modem_suspend(struct net_device *netdev) 168 + { 169 + struct ipa_priv *priv = netdev_priv(netdev); 170 + struct ipa *ipa = priv->ipa; 171 + 172 + netif_stop_queue(netdev); 173 + 174 + ipa_endpoint_suspend_one(ipa->name_map[IPA_ENDPOINT_AP_MODEM_RX]); 175 + ipa_endpoint_suspend_one(ipa->name_map[IPA_ENDPOINT_AP_MODEM_TX]); 176 + } 177 + 178 + /** ipa_modem_resume() - resume callback for runtime_pm 179 + * @dev: pointer to device 180 + * 181 + * Resume the modem's endpoints. 182 + */ 183 + void ipa_modem_resume(struct net_device *netdev) 184 + { 185 + struct ipa_priv *priv = netdev_priv(netdev); 186 + struct ipa *ipa = priv->ipa; 187 + 188 + ipa_endpoint_resume_one(ipa->name_map[IPA_ENDPOINT_AP_MODEM_TX]); 189 + ipa_endpoint_resume_one(ipa->name_map[IPA_ENDPOINT_AP_MODEM_RX]); 190 + 191 + netif_wake_queue(netdev); 192 + } 193 + 194 + int ipa_modem_start(struct ipa *ipa) 195 + { 196 + enum ipa_modem_state state; 197 + struct net_device *netdev; 198 + struct ipa_priv *priv; 199 + int ret; 200 + 201 + /* Only attempt to start the modem if it's stopped */ 202 + state = atomic_cmpxchg(&ipa->modem_state, IPA_MODEM_STATE_STOPPED, 203 + IPA_MODEM_STATE_STARTING); 204 + 205 + /* Silently ignore attempts when running, or when changing state */ 206 + if (state != IPA_MODEM_STATE_STOPPED) 207 + return 0; 208 + 209 + netdev = alloc_netdev(sizeof(struct ipa_priv), IPA_NETDEV_NAME, 210 + NET_NAME_UNKNOWN, ipa_modem_netdev_setup); 211 + if (!netdev) { 212 + ret = -ENOMEM; 213 + goto out_set_state; 214 + } 215 + 216 + ipa->name_map[IPA_ENDPOINT_AP_MODEM_TX]->netdev = netdev; 217 + ipa->name_map[IPA_ENDPOINT_AP_MODEM_RX]->netdev = netdev; 218 + 219 + priv = netdev_priv(netdev); 220 + priv->ipa = ipa; 221 + 222 + ret = register_netdev(netdev); 223 + if (ret) 224 + free_netdev(netdev); 225 + else 226 + ipa->modem_netdev = netdev; 227 + 228 + out_set_state: 229 + if (ret) 230 + atomic_set(&ipa->modem_state, IPA_MODEM_STATE_STOPPED); 231 + else 232 + atomic_set(&ipa->modem_state, IPA_MODEM_STATE_RUNNING); 233 + smp_mb__after_atomic(); 234 + 235 + return ret; 236 + } 237 + 238 + int ipa_modem_stop(struct ipa *ipa) 239 + { 240 + struct net_device *netdev = ipa->modem_netdev; 241 + enum ipa_modem_state state; 242 + int ret; 243 + 244 + /* Only attempt to stop the modem if it's running */ 245 + state = atomic_cmpxchg(&ipa->modem_state, IPA_MODEM_STATE_RUNNING, 246 + IPA_MODEM_STATE_STOPPING); 247 + 248 + /* Silently ignore attempts when already stopped */ 249 + if (state == IPA_MODEM_STATE_STOPPED) 250 + return 0; 251 + 252 + /* If we're somewhere between stopped and starting, we're busy */ 253 + if (state != IPA_MODEM_STATE_RUNNING) 254 + return -EBUSY; 255 + 256 + /* Prevent the modem from triggering a call to ipa_setup() */ 257 + ipa_smp2p_disable(ipa); 258 + 259 + if (netdev) { 260 + /* Stop the queue and disable the endpoints if it's open */ 261 + ret = ipa_stop(netdev); 262 + if (ret) 263 + goto out_set_state; 264 + 265 + ipa->modem_netdev = NULL; 266 + unregister_netdev(netdev); 267 + free_netdev(netdev); 268 + } else { 269 + ret = 0; 270 + } 271 + 272 + out_set_state: 273 + if (ret) 274 + atomic_set(&ipa->modem_state, IPA_MODEM_STATE_RUNNING); 275 + else 276 + atomic_set(&ipa->modem_state, IPA_MODEM_STATE_STOPPED); 277 + smp_mb__after_atomic(); 278 + 279 + return ret; 280 + } 281 + 282 + /* Treat a "clean" modem stop the same as a crash */ 283 + static void ipa_modem_crashed(struct ipa *ipa) 284 + { 285 + struct device *dev = &ipa->pdev->dev; 286 + int ret; 287 + 288 + ipa_endpoint_modem_pause_all(ipa, true); 289 + 290 + ipa_endpoint_modem_hol_block_clear_all(ipa); 291 + 292 + ipa_table_reset(ipa, true); 293 + 294 + ret = ipa_table_hash_flush(ipa); 295 + if (ret) 296 + dev_err(dev, "error %d flushing hash cahces\n", ret); 297 + 298 + ret = ipa_endpoint_modem_exception_reset_all(ipa); 299 + if (ret) 300 + dev_err(dev, "error %d resetting exception endpoint", 301 + ret); 302 + 303 + ipa_endpoint_modem_pause_all(ipa, false); 304 + 305 + ret = ipa_modem_stop(ipa); 306 + if (ret) 307 + dev_err(dev, "error %d stopping modem", ret); 308 + 309 + /* Now prepare for the next modem boot */ 310 + ret = ipa_mem_zero_modem(ipa); 311 + if (ret) 312 + dev_err(dev, "error %d zeroing modem memory regions\n", ret); 313 + } 314 + 315 + static void ipa_modem_notify(void *data, enum qcom_rproc_event event) 316 + { 317 + struct ipa *ipa = data; 318 + struct device *dev; 319 + 320 + dev = &ipa->pdev->dev; 321 + switch (event) { 322 + case MODEM_STARTING: 323 + dev_info(dev, "received modem starting event\n"); 324 + ipa_smp2p_notify_reset(ipa); 325 + break; 326 + 327 + case MODEM_RUNNING: 328 + dev_info(dev, "received modem running event\n"); 329 + break; 330 + 331 + case MODEM_STOPPING: 332 + case MODEM_CRASHED: 333 + dev_info(dev, "received modem %s event\n", 334 + event == MODEM_STOPPING ? "stopping" 335 + : "crashed"); 336 + if (ipa->setup_complete) 337 + ipa_modem_crashed(ipa); 338 + break; 339 + 340 + case MODEM_OFFLINE: 341 + dev_info(dev, "received modem offline event\n"); 342 + break; 343 + 344 + case MODEM_REMOVING: 345 + dev_info(dev, "received modem stopping event\n"); 346 + break; 347 + 348 + default: 349 + dev_err(&ipa->pdev->dev, "unrecognized event %u\n", event); 350 + break; 351 + } 352 + } 353 + 354 + int ipa_modem_init(struct ipa *ipa, bool modem_init) 355 + { 356 + return ipa_smp2p_init(ipa, modem_init); 357 + } 358 + 359 + void ipa_modem_exit(struct ipa *ipa) 360 + { 361 + ipa_smp2p_exit(ipa); 362 + } 363 + 364 + int ipa_modem_config(struct ipa *ipa) 365 + { 366 + return qcom_register_ipa_notify(ipa->modem_rproc, ipa_modem_notify, 367 + ipa); 368 + } 369 + 370 + void ipa_modem_deconfig(struct ipa *ipa) 371 + { 372 + qcom_deregister_ipa_notify(ipa->modem_rproc); 373 + } 374 + 375 + int ipa_modem_setup(struct ipa *ipa) 376 + { 377 + return ipa_qmi_setup(ipa); 378 + } 379 + 380 + void ipa_modem_teardown(struct ipa *ipa) 381 + { 382 + ipa_qmi_teardown(ipa); 383 + }
+31
drivers/net/ipa/ipa_modem.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + 3 + /* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved. 4 + * Copyright (C) 2018-2020 Linaro Ltd. 5 + */ 6 + #ifndef _IPA_MODEM_H_ 7 + #define _IPA_MODEM_H_ 8 + 9 + struct ipa; 10 + struct ipa_endpoint; 11 + struct net_device; 12 + struct sk_buff; 13 + 14 + int ipa_modem_start(struct ipa *ipa); 15 + int ipa_modem_stop(struct ipa *ipa); 16 + 17 + void ipa_modem_skb_rx(struct net_device *netdev, struct sk_buff *skb); 18 + 19 + void ipa_modem_suspend(struct net_device *netdev); 20 + void ipa_modem_resume(struct net_device *netdev); 21 + 22 + int ipa_modem_init(struct ipa *ipa, bool modem_init); 23 + void ipa_modem_exit(struct ipa *ipa); 24 + 25 + int ipa_modem_config(struct ipa *ipa); 26 + void ipa_modem_deconfig(struct ipa *ipa); 27 + 28 + int ipa_modem_setup(struct ipa *ipa); 29 + void ipa_modem_teardown(struct ipa *ipa); 30 + 31 + #endif /* _IPA_MODEM_H_ */
+211
drivers/net/ipa/ipa_uc.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + 3 + /* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved. 4 + * Copyright (C) 2018-2020 Linaro Ltd. 5 + */ 6 + 7 + #include <linux/types.h> 8 + #include <linux/io.h> 9 + #include <linux/delay.h> 10 + 11 + #include "ipa.h" 12 + #include "ipa_clock.h" 13 + #include "ipa_uc.h" 14 + 15 + /** 16 + * DOC: The IPA embedded microcontroller 17 + * 18 + * The IPA incorporates a microcontroller that is able to do some additional 19 + * handling/offloading of network activity. The current code makes 20 + * essentially no use of the microcontroller, but it still requires some 21 + * initialization. It needs to be notified in the event the AP crashes. 22 + * 23 + * The microcontroller can generate two interrupts to the AP. One interrupt 24 + * is used to indicate that a response to a request from the AP is available. 25 + * The other is used to notify the AP of the occurrence of an event. In 26 + * addition, the AP can interrupt the microcontroller by writing a register. 27 + * 28 + * A 128 byte block of structured memory within the IPA SRAM is used together 29 + * with these interrupts to implement the communication interface between the 30 + * AP and the IPA microcontroller. Each side writes data to the shared area 31 + * before interrupting its peer, which will read the written data in response 32 + * to the interrupt. Some information found in the shared area is currently 33 + * unused. All remaining space in the shared area is reserved, and must not 34 + * be read or written by the AP. 35 + */ 36 + /* Supports hardware interface version 0x2000 */ 37 + 38 + /* Offset relative to the base of the IPA shared address space of the 39 + * shared region used for communication with the microcontroller. The 40 + * region is 128 bytes in size, but only the first 40 bytes are used. 41 + */ 42 + #define IPA_MEM_UC_OFFSET 0x0000 43 + 44 + /* Delay to allow a the microcontroller to save state when crashing */ 45 + #define IPA_SEND_DELAY 100 /* microseconds */ 46 + 47 + /** 48 + * struct ipa_uc_mem_area - AP/microcontroller shared memory area 49 + * @command: command code (AP->microcontroller) 50 + * @command_param: low 32 bits of command parameter (AP->microcontroller) 51 + * @command_param_hi: high 32 bits of command parameter (AP->microcontroller) 52 + * 53 + * @response: response code (microcontroller->AP) 54 + * @response_param: response parameter (microcontroller->AP) 55 + * 56 + * @event: event code (microcontroller->AP) 57 + * @event_param: event parameter (microcontroller->AP) 58 + * 59 + * @first_error_address: address of first error-source on SNOC 60 + * @hw_state: state of hardware (including error type information) 61 + * @warning_counter: counter of non-fatal hardware errors 62 + * @interface_version: hardware-reported interface version 63 + */ 64 + struct ipa_uc_mem_area { 65 + u8 command; /* enum ipa_uc_command */ 66 + u8 reserved0[3]; 67 + __le32 command_param; 68 + __le32 command_param_hi; 69 + u8 response; /* enum ipa_uc_response */ 70 + u8 reserved1[3]; 71 + __le32 response_param; 72 + u8 event; /* enum ipa_uc_event */ 73 + u8 reserved2[3]; 74 + 75 + __le32 event_param; 76 + __le32 first_error_address; 77 + u8 hw_state; 78 + u8 warning_counter; 79 + __le16 reserved3; 80 + __le16 interface_version; 81 + __le16 reserved4; 82 + }; 83 + 84 + /** enum ipa_uc_command - commands from the AP to the microcontroller */ 85 + enum ipa_uc_command { 86 + IPA_UC_COMMAND_NO_OP = 0, 87 + IPA_UC_COMMAND_UPDATE_FLAGS = 1, 88 + IPA_UC_COMMAND_DEBUG_RUN_TEST = 2, 89 + IPA_UC_COMMAND_DEBUG_GET_INFO = 3, 90 + IPA_UC_COMMAND_ERR_FATAL = 4, 91 + IPA_UC_COMMAND_CLK_GATE = 5, 92 + IPA_UC_COMMAND_CLK_UNGATE = 6, 93 + IPA_UC_COMMAND_MEMCPY = 7, 94 + IPA_UC_COMMAND_RESET_PIPE = 8, 95 + IPA_UC_COMMAND_REG_WRITE = 9, 96 + IPA_UC_COMMAND_GSI_CH_EMPTY = 10, 97 + }; 98 + 99 + /** enum ipa_uc_response - microcontroller response codes */ 100 + enum ipa_uc_response { 101 + IPA_UC_RESPONSE_NO_OP = 0, 102 + IPA_UC_RESPONSE_INIT_COMPLETED = 1, 103 + IPA_UC_RESPONSE_CMD_COMPLETED = 2, 104 + IPA_UC_RESPONSE_DEBUG_GET_INFO = 3, 105 + }; 106 + 107 + /** enum ipa_uc_event - common cpu events reported by the microcontroller */ 108 + enum ipa_uc_event { 109 + IPA_UC_EVENT_NO_OP = 0, 110 + IPA_UC_EVENT_ERROR = 1, 111 + IPA_UC_EVENT_LOG_INFO = 2, 112 + }; 113 + 114 + static struct ipa_uc_mem_area *ipa_uc_shared(struct ipa *ipa) 115 + { 116 + u32 offset = ipa->mem_offset + ipa->mem[IPA_MEM_UC_SHARED].offset; 117 + 118 + return ipa->mem_virt + offset; 119 + } 120 + 121 + /* Microcontroller event IPA interrupt handler */ 122 + static void ipa_uc_event_handler(struct ipa *ipa, enum ipa_irq_id irq_id) 123 + { 124 + struct ipa_uc_mem_area *shared = ipa_uc_shared(ipa); 125 + struct device *dev = &ipa->pdev->dev; 126 + 127 + if (shared->event == IPA_UC_EVENT_ERROR) 128 + dev_err(dev, "microcontroller error event\n"); 129 + else 130 + dev_err(dev, "unsupported microcontroller event %hhu\n", 131 + shared->event); 132 + } 133 + 134 + /* Microcontroller response IPA interrupt handler */ 135 + static void ipa_uc_response_hdlr(struct ipa *ipa, enum ipa_irq_id irq_id) 136 + { 137 + struct ipa_uc_mem_area *shared = ipa_uc_shared(ipa); 138 + 139 + /* An INIT_COMPLETED response message is sent to the AP by the 140 + * microcontroller when it is operational. Other than this, the AP 141 + * should only receive responses from the microcontroller when it has 142 + * sent it a request message. 143 + * 144 + * We can drop the clock reference taken in ipa_uc_init() once we 145 + * know the microcontroller has finished its initialization. 146 + */ 147 + switch (shared->response) { 148 + case IPA_UC_RESPONSE_INIT_COMPLETED: 149 + ipa->uc_loaded = true; 150 + ipa_clock_put(ipa); 151 + break; 152 + default: 153 + dev_warn(&ipa->pdev->dev, 154 + "unsupported microcontroller response %hhu\n", 155 + shared->response); 156 + break; 157 + } 158 + } 159 + 160 + /* ipa_uc_setup() - Set up the microcontroller */ 161 + void ipa_uc_setup(struct ipa *ipa) 162 + { 163 + /* The microcontroller needs the IPA clock running until it has 164 + * completed its initialization. It signals this by sending an 165 + * INIT_COMPLETED response message to the AP. This could occur after 166 + * we have finished doing the rest of the IPA initialization, so we 167 + * need to take an extra "proxy" reference, and hold it until we've 168 + * received that signal. (This reference is dropped in 169 + * ipa_uc_response_hdlr(), above.) 170 + */ 171 + ipa_clock_get(ipa); 172 + 173 + ipa->uc_loaded = false; 174 + ipa_interrupt_add(ipa->interrupt, IPA_IRQ_UC_0, ipa_uc_event_handler); 175 + ipa_interrupt_add(ipa->interrupt, IPA_IRQ_UC_1, ipa_uc_response_hdlr); 176 + } 177 + 178 + /* Inverse of ipa_uc_setup() */ 179 + void ipa_uc_teardown(struct ipa *ipa) 180 + { 181 + ipa_interrupt_remove(ipa->interrupt, IPA_IRQ_UC_1); 182 + ipa_interrupt_remove(ipa->interrupt, IPA_IRQ_UC_0); 183 + if (!ipa->uc_loaded) 184 + ipa_clock_put(ipa); 185 + } 186 + 187 + /* Send a command to the microcontroller */ 188 + static void send_uc_command(struct ipa *ipa, u32 command, u32 command_param) 189 + { 190 + struct ipa_uc_mem_area *shared = ipa_uc_shared(ipa); 191 + 192 + shared->command = command; 193 + shared->command_param = cpu_to_le32(command_param); 194 + shared->command_param_hi = 0; 195 + shared->response = 0; 196 + shared->response_param = 0; 197 + 198 + iowrite32(1, ipa->reg_virt + IPA_REG_IRQ_UC_OFFSET); 199 + } 200 + 201 + /* Tell the microcontroller the AP is shutting down */ 202 + void ipa_uc_panic_notifier(struct ipa *ipa) 203 + { 204 + if (!ipa->uc_loaded) 205 + return; 206 + 207 + send_uc_command(ipa, IPA_UC_COMMAND_ERR_FATAL, 0); 208 + 209 + /* give uc enough time to save state */ 210 + udelay(IPA_SEND_DELAY); 211 + }
+32
drivers/net/ipa/ipa_uc.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + 3 + /* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved. 4 + * Copyright (C) 2019-2020 Linaro Ltd. 5 + */ 6 + #ifndef _IPA_UC_H_ 7 + #define _IPA_UC_H_ 8 + 9 + struct ipa; 10 + 11 + /** 12 + * ipa_uc_setup() - set up the IPA microcontroller subsystem 13 + * @ipa: IPA pointer 14 + */ 15 + void ipa_uc_setup(struct ipa *ipa); 16 + 17 + /** 18 + * ipa_uc_teardown() - inverse of ipa_uc_setup() 19 + * @ipa: IPA pointer 20 + */ 21 + void ipa_uc_teardown(struct ipa *ipa); 22 + 23 + /** 24 + * ipa_uc_panic_notifier() 25 + * @ipa: IPA pointer 26 + * 27 + * Notifier function called when the system crashes, to inform the 28 + * microcontroller of the event. 29 + */ 30 + void ipa_uc_panic_notifier(struct ipa *ipa); 31 + 32 + #endif /* _IPA_UC_H_ */