1 // SPDX-License-Identifier: GPL-2.0
3 /* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
4 * Copyright (C) 2018-2020 Linaro Ltd.
7 #include <linux/types.h>
8 #include <linux/atomic.h>
9 #include <linux/bitfield.h>
10 #include <linux/device.h>
11 #include <linux/bug.h>
13 #include <linux/firmware.h>
14 #include <linux/module.h>
16 #include <linux/of_device.h>
17 #include <linux/of_address.h>
18 #include <linux/remoteproc.h>
19 #include <linux/qcom_scm.h>
20 #include <linux/soc/qcom/mdt_loader.h>
23 #include "ipa_clock.h"
25 #include "ipa_endpoint.h"
29 #include "ipa_table.h"
30 #include "ipa_modem.h"
32 #include "ipa_interrupt.h"
33 #include "gsi_trans.h"
36 * DOC: The IP Accelerator
38 * This driver supports the Qualcomm IP Accelerator (IPA), which is a
39 * networking component found in many Qualcomm SoCs. The IPA is connected
40 * to the application processor (AP), but is also connected (and partially
41 * controlled by) other "execution environments" (EEs), such as a modem.
43 * The IPA is the conduit between the AP and the modem that carries network
44 * traffic. This driver presents a network interface representing the
45 * connection of the modem to external (e.g. LTE) networks.
47 * The IPA provides protocol checksum calculation, offloading this work
48 * from the AP. The IPA offers additional functionality, including routing,
49 * filtering, and NAT support, but that more advanced functionality is not
50 * currently supported. Despite that, some resources--including routing
51 * tables and filter tables--are defined in this driver because they must
52 * be initialized even when the advanced hardware features are not used.
54 * There are two distinct layers that implement the IPA hardware, and this
55 * is reflected in the organization of the driver. The generic software
56 * interface (GSI) is an integral component of the IPA, providing a
57 * well-defined communication layer between the AP subsystem and the IPA
58 * core. The GSI implements a set of "channels" used for communication
59 * between the AP and the IPA.
61 * The IPA layer uses GSI channels to implement its "endpoints". And while
62 * a GSI channel carries data between the AP and the IPA, a pair of IPA
63 * endpoints is used to carry traffic between two EEs. Specifically, the main
64 * modem network interface is implemented by two pairs of endpoints: a TX
65 * endpoint on the AP coupled with an RX endpoint on the modem; and another
66 * RX endpoint on the AP receiving data from a TX endpoint on the modem.
69 /* The name of the GSI firmware file relative to /lib/firmware */
70 #define IPA_FWS_PATH "ipa_fws.mdt"
74 * ipa_suspend_handler() - Handle the suspend IPA interrupt
76 * @irq_id: IPA interrupt type (unused)
78 * If an RX endpoint is in suspend state, and the IPA has a packet
79 * destined for that endpoint, the IPA generates a SUSPEND interrupt
80 * to inform the AP that it should resume the endpoint. If we get
81 * one of these interrupts we just resume everything.
83 static void ipa_suspend_handler(struct ipa *ipa, enum ipa_irq_id irq_id)
85 /* Just report the event, and let system resume handle the rest.
86 * More than one endpoint could signal this; if so, ignore
89 if (!test_and_set_bit(IPA_FLAG_RESUMED, ipa->flags))
90 pm_wakeup_dev_event(&ipa->pdev->dev, 0, true);
92 /* Acknowledge/clear the suspend interrupt on all endpoints */
93 ipa_interrupt_suspend_clear_all(ipa->interrupt);
97 * ipa_setup() - Set up IPA hardware
100 * Perform initialization that requires issuing immediate commands on
101 * the command TX endpoint. If the modem is doing GSI firmware load
102 * and initialization, this function will be called when an SMP2P
103 * interrupt has been signaled by the modem. Otherwise it will be
104 * called from ipa_probe() after GSI firmware has been successfully
105 * loaded, authenticated, and started by Trust Zone.
107 int ipa_setup(struct ipa *ipa)
109 struct ipa_endpoint *exception_endpoint;
110 struct ipa_endpoint *command_endpoint;
111 struct device *dev = &ipa->pdev->dev;
114 ret = gsi_setup(&ipa->gsi);
118 ipa->interrupt = ipa_interrupt_setup(ipa);
119 if (IS_ERR(ipa->interrupt)) {
120 ret = PTR_ERR(ipa->interrupt);
121 goto err_gsi_teardown;
123 ipa_interrupt_add(ipa->interrupt, IPA_IRQ_TX_SUSPEND,
124 ipa_suspend_handler);
128 ret = device_init_wakeup(dev, true);
130 goto err_uc_teardown;
132 ipa_endpoint_setup(ipa);
134 /* We need to use the AP command TX endpoint to perform other
135 * initialization, so we enable first.
137 command_endpoint = ipa->name_map[IPA_ENDPOINT_AP_COMMAND_TX];
138 ret = ipa_endpoint_enable_one(command_endpoint);
140 goto err_endpoint_teardown;
142 ret = ipa_mem_setup(ipa);
144 goto err_command_disable;
146 ret = ipa_table_setup(ipa);
148 goto err_mem_teardown;
150 /* Enable the exception handling endpoint, and tell the hardware
151 * to use it by default.
153 exception_endpoint = ipa->name_map[IPA_ENDPOINT_AP_LAN_RX];
154 ret = ipa_endpoint_enable_one(exception_endpoint);
156 goto err_table_teardown;
158 ipa_endpoint_default_route_set(ipa, exception_endpoint->endpoint_id);
160 /* We're all set. Now prepare for communication with the modem */
161 ret = ipa_modem_setup(ipa);
163 goto err_default_route_clear;
165 ipa->setup_complete = true;
167 dev_info(dev, "IPA driver setup completed successfully\n");
171 err_default_route_clear:
172 ipa_endpoint_default_route_clear(ipa);
173 ipa_endpoint_disable_one(exception_endpoint);
175 ipa_table_teardown(ipa);
177 ipa_mem_teardown(ipa);
179 ipa_endpoint_disable_one(command_endpoint);
180 err_endpoint_teardown:
181 ipa_endpoint_teardown(ipa);
182 (void)device_init_wakeup(dev, false);
184 ipa_uc_teardown(ipa);
185 ipa_interrupt_remove(ipa->interrupt, IPA_IRQ_TX_SUSPEND);
186 ipa_interrupt_teardown(ipa->interrupt);
188 gsi_teardown(&ipa->gsi);
194 * ipa_teardown() - Inverse of ipa_setup()
197 static void ipa_teardown(struct ipa *ipa)
199 struct ipa_endpoint *exception_endpoint;
200 struct ipa_endpoint *command_endpoint;
202 ipa_modem_teardown(ipa);
203 ipa_endpoint_default_route_clear(ipa);
204 exception_endpoint = ipa->name_map[IPA_ENDPOINT_AP_LAN_RX];
205 ipa_endpoint_disable_one(exception_endpoint);
206 ipa_table_teardown(ipa);
207 ipa_mem_teardown(ipa);
208 command_endpoint = ipa->name_map[IPA_ENDPOINT_AP_COMMAND_TX];
209 ipa_endpoint_disable_one(command_endpoint);
210 ipa_endpoint_teardown(ipa);
211 (void)device_init_wakeup(&ipa->pdev->dev, false);
212 ipa_uc_teardown(ipa);
213 ipa_interrupt_remove(ipa->interrupt, IPA_IRQ_TX_SUSPEND);
214 ipa_interrupt_teardown(ipa->interrupt);
215 gsi_teardown(&ipa->gsi);
218 /* Configure QMB Core Master Port selection */
219 static void ipa_hardware_config_comp(struct ipa *ipa)
223 /* Nothing to configure for IPA v3.5.1 */
224 if (ipa->version == IPA_VERSION_3_5_1)
227 val = ioread32(ipa->reg_virt + IPA_REG_COMP_CFG_OFFSET);
229 if (ipa->version == IPA_VERSION_4_0) {
230 val &= ~IPA_QMB_SELECT_CONS_EN_FMASK;
231 val &= ~IPA_QMB_SELECT_PROD_EN_FMASK;
232 val &= ~IPA_QMB_SELECT_GLOBAL_EN_FMASK;
234 val |= GSI_MULTI_AXI_MASTERS_DIS_FMASK;
237 val |= GSI_MULTI_INORDER_RD_DIS_FMASK;
238 val |= GSI_MULTI_INORDER_WR_DIS_FMASK;
240 iowrite32(val, ipa->reg_virt + IPA_REG_COMP_CFG_OFFSET);
243 /* Configure DDR and PCIe max read/write QSB values */
244 static void ipa_hardware_config_qsb(struct ipa *ipa)
248 /* QMB_0 represents DDR; QMB_1 represents PCIe (not present in 4.2) */
249 val = u32_encode_bits(8, GEN_QMB_0_MAX_WRITES_FMASK);
250 if (ipa->version == IPA_VERSION_4_2)
251 val |= u32_encode_bits(0, GEN_QMB_1_MAX_WRITES_FMASK);
253 val |= u32_encode_bits(4, GEN_QMB_1_MAX_WRITES_FMASK);
254 iowrite32(val, ipa->reg_virt + IPA_REG_QSB_MAX_WRITES_OFFSET);
256 if (ipa->version == IPA_VERSION_3_5_1) {
257 val = u32_encode_bits(8, GEN_QMB_0_MAX_READS_FMASK);
258 val |= u32_encode_bits(12, GEN_QMB_1_MAX_READS_FMASK);
260 val = u32_encode_bits(12, GEN_QMB_0_MAX_READS_FMASK);
261 if (ipa->version == IPA_VERSION_4_2)
262 val |= u32_encode_bits(0, GEN_QMB_1_MAX_READS_FMASK);
264 val |= u32_encode_bits(12, GEN_QMB_1_MAX_READS_FMASK);
265 /* GEN_QMB_0_MAX_READS_BEATS is 0 */
266 /* GEN_QMB_1_MAX_READS_BEATS is 0 */
268 iowrite32(val, ipa->reg_virt + IPA_REG_QSB_MAX_READS_OFFSET);
271 static void ipa_idle_indication_cfg(struct ipa *ipa,
272 u32 enter_idle_debounce_thresh,
273 bool const_non_idle_enable)
278 val = u32_encode_bits(enter_idle_debounce_thresh,
279 ENTER_IDLE_DEBOUNCE_THRESH_FMASK);
280 if (const_non_idle_enable)
281 val |= CONST_NON_IDLE_ENABLE_FMASK;
283 offset = ipa_reg_idle_indication_cfg_offset(ipa->version);
284 iowrite32(val, ipa->reg_virt + offset);
288 * ipa_hardware_dcd_config() - Enable dynamic clock division on IPA
291 * Configures when the IPA signals it is idle to the global clock
292 * controller, which can respond by scalling down the clock to
295 static void ipa_hardware_dcd_config(struct ipa *ipa)
297 /* Recommended values for IPA 3.5 according to IPA HPG */
298 ipa_idle_indication_cfg(ipa, 256, false);
301 static void ipa_hardware_dcd_deconfig(struct ipa *ipa)
303 /* Power-on reset values */
304 ipa_idle_indication_cfg(ipa, 0, true);
308 * ipa_hardware_config() - Primitive hardware initialization
311 static void ipa_hardware_config(struct ipa *ipa)
313 enum ipa_version version = ipa->version;
317 /* IPA v4.5 has no backward compatibility register */
318 if (version < IPA_VERSION_4_5) {
319 val = ipa_reg_bcr_val(version);
320 iowrite32(val, ipa->reg_virt + IPA_REG_BCR_OFFSET);
323 if (version != IPA_VERSION_3_5_1) {
324 /* Enable open global clocks (hardware workaround) */
326 val |= GLOBAL_2X_CLK_FMASK;
327 iowrite32(val, ipa->reg_virt + IPA_REG_CLKON_CFG_OFFSET);
329 /* Disable PA mask to allow HOLB drop (hardware workaround) */
330 val = ioread32(ipa->reg_virt + IPA_REG_TX_CFG_OFFSET);
331 val &= ~PA_MASK_EN_FMASK;
332 iowrite32(val, ipa->reg_virt + IPA_REG_TX_CFG_OFFSET);
335 ipa_hardware_config_comp(ipa);
337 /* Configure system bus limits */
338 ipa_hardware_config_qsb(ipa);
340 /* Configure aggregation granularity */
341 granularity = ipa_aggr_granularity_val(IPA_AGGR_GRANULARITY);
342 val = u32_encode_bits(granularity, AGGR_GRANULARITY_FMASK);
343 iowrite32(val, ipa->reg_virt + IPA_REG_COUNTER_CFG_OFFSET);
345 /* IPA v4.2 does not support hashed tables, so disable them */
346 if (version == IPA_VERSION_4_2) {
347 u32 offset = ipa_reg_filt_rout_hash_en_offset(version);
349 iowrite32(0, ipa->reg_virt + offset);
352 /* Enable dynamic clock division */
353 ipa_hardware_dcd_config(ipa);
357 * ipa_hardware_deconfig() - Inverse of ipa_hardware_config()
360 * This restores the power-on reset values (even if they aren't different)
362 static void ipa_hardware_deconfig(struct ipa *ipa)
364 /* Mostly we just leave things as we set them. */
365 ipa_hardware_dcd_deconfig(ipa);
368 #ifdef IPA_VALIDATION
370 static bool ipa_resource_limits_valid(struct ipa *ipa,
371 const struct ipa_resource_data *data)
377 /* We program at most 6 source or destination resource group limits */
378 BUILD_BUG_ON(IPA_RESOURCE_GROUP_SRC_MAX > 6);
380 group_count = ipa_resource_group_src_count(ipa->version);
381 if (!group_count || group_count > IPA_RESOURCE_GROUP_SRC_MAX)
384 /* Return an error if a non-zero resource limit is specified
385 * for a resource group not supported by hardware.
387 for (i = 0; i < data->resource_src_count; i++) {
388 const struct ipa_resource_src *resource;
390 resource = &data->resource_src[i];
391 for (j = group_count; j < IPA_RESOURCE_GROUP_SRC_MAX; j++)
392 if (resource->limits[j].min || resource->limits[j].max)
396 group_count = ipa_resource_group_dst_count(ipa->version);
397 if (!group_count || group_count > IPA_RESOURCE_GROUP_DST_MAX)
400 for (i = 0; i < data->resource_dst_count; i++) {
401 const struct ipa_resource_dst *resource;
403 resource = &data->resource_dst[i];
404 for (j = group_count; j < IPA_RESOURCE_GROUP_DST_MAX; j++)
405 if (resource->limits[j].min || resource->limits[j].max)
412 #else /* !IPA_VALIDATION */
414 static bool ipa_resource_limits_valid(struct ipa *ipa,
415 const struct ipa_resource_data *data)
420 #endif /* !IPA_VALIDATION */
423 ipa_resource_config_common(struct ipa *ipa, u32 offset,
424 const struct ipa_resource_limits *xlimits,
425 const struct ipa_resource_limits *ylimits)
429 val = u32_encode_bits(xlimits->min, X_MIN_LIM_FMASK);
430 val |= u32_encode_bits(xlimits->max, X_MAX_LIM_FMASK);
432 val |= u32_encode_bits(ylimits->min, Y_MIN_LIM_FMASK);
433 val |= u32_encode_bits(ylimits->max, Y_MAX_LIM_FMASK);
436 iowrite32(val, ipa->reg_virt + offset);
439 static void ipa_resource_config_src(struct ipa *ipa,
440 const struct ipa_resource_src *resource)
442 u32 group_count = ipa_resource_group_src_count(ipa->version);
443 const struct ipa_resource_limits *ylimits;
446 offset = IPA_REG_SRC_RSRC_GRP_01_RSRC_TYPE_N_OFFSET(resource->type);
447 ylimits = group_count == 1 ? NULL : &resource->limits[1];
448 ipa_resource_config_common(ipa, offset, &resource->limits[0], ylimits);
453 offset = IPA_REG_SRC_RSRC_GRP_23_RSRC_TYPE_N_OFFSET(resource->type);
454 ylimits = group_count == 3 ? NULL : &resource->limits[3];
455 ipa_resource_config_common(ipa, offset, &resource->limits[2], ylimits);
460 offset = IPA_REG_SRC_RSRC_GRP_45_RSRC_TYPE_N_OFFSET(resource->type);
461 ylimits = group_count == 5 ? NULL : &resource->limits[5];
462 ipa_resource_config_common(ipa, offset, &resource->limits[4], ylimits);
465 static void ipa_resource_config_dst(struct ipa *ipa,
466 const struct ipa_resource_dst *resource)
468 u32 group_count = ipa_resource_group_dst_count(ipa->version);
469 const struct ipa_resource_limits *ylimits;
472 offset = IPA_REG_DST_RSRC_GRP_01_RSRC_TYPE_N_OFFSET(resource->type);
473 ylimits = group_count == 1 ? NULL : &resource->limits[1];
474 ipa_resource_config_common(ipa, offset, &resource->limits[0], ylimits);
479 offset = IPA_REG_DST_RSRC_GRP_23_RSRC_TYPE_N_OFFSET(resource->type);
480 ylimits = group_count == 3 ? NULL : &resource->limits[3];
481 ipa_resource_config_common(ipa, offset, &resource->limits[2], ylimits);
486 offset = IPA_REG_DST_RSRC_GRP_45_RSRC_TYPE_N_OFFSET(resource->type);
487 ylimits = group_count == 5 ? NULL : &resource->limits[5];
488 ipa_resource_config_common(ipa, offset, &resource->limits[4], ylimits);
492 ipa_resource_config(struct ipa *ipa, const struct ipa_resource_data *data)
496 if (!ipa_resource_limits_valid(ipa, data))
499 for (i = 0; i < data->resource_src_count; i++)
500 ipa_resource_config_src(ipa, data->resource_src);
502 for (i = 0; i < data->resource_dst_count; i++)
503 ipa_resource_config_dst(ipa, data->resource_dst);
508 static void ipa_resource_deconfig(struct ipa *ipa)
514 * ipa_config() - Configure IPA hardware
516 * @data: IPA configuration data
518 * Perform initialization requiring IPA clock to be enabled.
520 static int ipa_config(struct ipa *ipa, const struct ipa_data *data)
524 /* Get a clock reference to allow initialization. This reference
525 * is held after initialization completes, and won't get dropped
526 * unless/until a system suspend request arrives.
530 ipa_hardware_config(ipa);
532 ret = ipa_endpoint_config(ipa);
534 goto err_hardware_deconfig;
536 ret = ipa_mem_config(ipa);
538 goto err_endpoint_deconfig;
540 ipa_table_config(ipa);
542 /* Assign resource limitation to each group */
543 ret = ipa_resource_config(ipa, data->resource_data);
545 goto err_table_deconfig;
547 ret = ipa_modem_config(ipa);
549 goto err_resource_deconfig;
553 err_resource_deconfig:
554 ipa_resource_deconfig(ipa);
556 ipa_table_deconfig(ipa);
557 ipa_mem_deconfig(ipa);
558 err_endpoint_deconfig:
559 ipa_endpoint_deconfig(ipa);
560 err_hardware_deconfig:
561 ipa_hardware_deconfig(ipa);
568 * ipa_deconfig() - Inverse of ipa_config()
571 static void ipa_deconfig(struct ipa *ipa)
573 ipa_modem_deconfig(ipa);
574 ipa_resource_deconfig(ipa);
575 ipa_table_deconfig(ipa);
576 ipa_mem_deconfig(ipa);
577 ipa_endpoint_deconfig(ipa);
578 ipa_hardware_deconfig(ipa);
582 static int ipa_firmware_load(struct device *dev)
584 const struct firmware *fw;
585 struct device_node *node;
592 node = of_parse_phandle(dev->of_node, "memory-region", 0);
594 dev_err(dev, "DT error getting \"memory-region\" property\n");
598 ret = of_address_to_resource(node, 0, &res);
600 dev_err(dev, "error %d getting \"memory-region\" resource\n",
605 ret = request_firmware(&fw, IPA_FWS_PATH, dev);
607 dev_err(dev, "error %d requesting \"%s\"\n", ret, IPA_FWS_PATH);
612 size = (size_t)resource_size(&res);
613 virt = memremap(phys, size, MEMREMAP_WC);
615 dev_err(dev, "unable to remap firmware memory\n");
617 goto out_release_firmware;
620 ret = qcom_mdt_load(dev, fw, IPA_FWS_PATH, IPA_PAS_ID,
621 virt, phys, size, NULL);
623 dev_err(dev, "error %d loading \"%s\"\n", ret, IPA_FWS_PATH);
624 else if ((ret = qcom_scm_pas_auth_and_reset(IPA_PAS_ID)))
625 dev_err(dev, "error %d authenticating \"%s\"\n", ret,
629 out_release_firmware:
630 release_firmware(fw);
635 static const struct of_device_id ipa_match[] = {
637 .compatible = "qcom,sdm845-ipa",
638 .data = &ipa_data_sdm845,
641 .compatible = "qcom,sc7180-ipa",
642 .data = &ipa_data_sc7180,
646 MODULE_DEVICE_TABLE(of, ipa_match);
648 static phandle of_property_read_phandle(const struct device_node *np,
651 struct property *prop;
654 prop = of_find_property(np, name, &len);
655 if (!prop || len != sizeof(__be32))
658 return be32_to_cpup(prop->value);
661 /* Check things that can be validated at build time. This just
662 * groups these things BUILD_BUG_ON() calls don't clutter the rest
665 static void ipa_validate_build(void)
668 /* We assume we're working on 64-bit hardware */
669 BUILD_BUG_ON(!IS_ENABLED(CONFIG_64BIT));
671 /* Code assumes the EE ID for the AP is 0 (zeroed structure field) */
672 BUILD_BUG_ON(GSI_EE_AP != 0);
674 /* There's no point if we have no channels or event rings */
675 BUILD_BUG_ON(!GSI_CHANNEL_COUNT_MAX);
676 BUILD_BUG_ON(!GSI_EVT_RING_COUNT_MAX);
678 /* GSI hardware design limits */
679 BUILD_BUG_ON(GSI_CHANNEL_COUNT_MAX > 32);
680 BUILD_BUG_ON(GSI_EVT_RING_COUNT_MAX > 31);
682 /* The number of TREs in a transaction is limited by the channel's
683 * TLV FIFO size. A transaction structure uses 8-bit fields
684 * to represents the number of TREs it has allocated and used.
686 BUILD_BUG_ON(GSI_TLV_MAX > U8_MAX);
688 /* This is used as a divisor */
689 BUILD_BUG_ON(!IPA_AGGR_GRANULARITY);
691 /* Aggregation granularity value can't be 0, and must fit */
692 BUILD_BUG_ON(!ipa_aggr_granularity_val(IPA_AGGR_GRANULARITY));
693 BUILD_BUG_ON(ipa_aggr_granularity_val(IPA_AGGR_GRANULARITY) >
694 field_max(AGGR_GRANULARITY_FMASK));
695 #endif /* IPA_VALIDATE */
699 * ipa_probe() - IPA platform driver probe function
700 * @pdev: Platform device pointer
702 * Return: 0 if successful, or a negative error code (possibly
705 * This is the main entry point for the IPA driver. Initialization proceeds
707 * - The "init" stage involves activities that can be initialized without
708 * access to the IPA hardware.
709 * - The "config" stage requires the IPA clock to be active so IPA registers
710 * can be accessed, but does not require the use of IPA immediate commands.
711 * - The "setup" stage uses IPA immediate commands, and so requires the GSI
712 * layer to be initialized.
714 * A Boolean Device Tree "modem-init" property determines whether GSI
715 * initialization will be performed by the AP (Trust Zone) or the modem.
716 * If the AP does GSI initialization, the setup phase is entered after
717 * this has completed successfully. Otherwise the modem initializes
718 * the GSI layer and signals it has finished by sending an SMP2P interrupt
719 * to the AP; this triggers the start if IPA setup.
721 static int ipa_probe(struct platform_device *pdev)
723 struct device *dev = &pdev->dev;
724 const struct ipa_data *data;
725 struct ipa_clock *clock;
732 ipa_validate_build();
734 /* Get configuration data early; needed for clock initialization */
735 data = of_device_get_match_data(dev);
737 /* This is really IPA_VALIDATE (should never happen) */
738 dev_err(dev, "matched hardware not supported\n");
742 /* If we need Trust Zone, make sure it's available */
743 modem_init = of_property_read_bool(dev->of_node, "modem-init");
745 if (!qcom_scm_is_available())
746 return -EPROBE_DEFER;
748 /* We rely on remoteproc to tell us about modem state changes */
749 ph = of_property_read_phandle(dev->of_node, "modem-remoteproc");
751 dev_err(dev, "DT missing \"modem-remoteproc\" property\n");
755 rproc = rproc_get_by_phandle(ph);
757 return -EPROBE_DEFER;
759 /* The clock and interconnects might not be ready when we're
760 * probed, so might return -EPROBE_DEFER.
762 clock = ipa_clock_init(dev, data->clock_data);
764 ret = PTR_ERR(clock);
768 /* No more EPROBE_DEFER. Allocate and initialize the IPA structure */
769 ipa = kzalloc(sizeof(*ipa), GFP_KERNEL);
776 dev_set_drvdata(dev, ipa);
777 ipa->modem_rproc = rproc;
779 ipa->version = data->version;
781 ret = ipa_reg_init(ipa);
785 ret = ipa_mem_init(ipa, data->mem_data);
789 ret = gsi_init(&ipa->gsi, pdev, ipa->version, data->endpoint_count,
790 data->endpoint_data);
794 /* Result is a non-zero mask of endpoints that support filtering */
795 ipa->filter_map = ipa_endpoint_init(ipa, data->endpoint_count,
796 data->endpoint_data);
797 if (!ipa->filter_map) {
802 ret = ipa_table_init(ipa);
804 goto err_endpoint_exit;
806 ret = ipa_modem_init(ipa, modem_init);
810 ret = ipa_config(ipa, data);
814 dev_info(dev, "IPA driver initialized");
816 /* If the modem is doing early initialization, it will trigger a
817 * call to ipa_setup() call when it has finished. In that case
823 /* Otherwise we need to load the firmware and have Trust Zone validate
824 * and install it. If that succeeds we can proceed with setup.
826 ret = ipa_firmware_load(dev);
830 ret = ipa_setup(ipa);
843 ipa_endpoint_exit(ipa);
853 ipa_clock_exit(clock);
860 static int ipa_remove(struct platform_device *pdev)
862 struct ipa *ipa = dev_get_drvdata(&pdev->dev);
863 struct rproc *rproc = ipa->modem_rproc;
864 struct ipa_clock *clock = ipa->clock;
867 if (ipa->setup_complete) {
868 ret = ipa_modem_stop(ipa);
869 /* If starting or stopping is in progress, try once more */
871 usleep_range(USEC_PER_MSEC, 2 * USEC_PER_MSEC);
872 ret = ipa_modem_stop(ipa);
883 ipa_endpoint_exit(ipa);
888 ipa_clock_exit(clock);
894 static void ipa_shutdown(struct platform_device *pdev)
898 ret = ipa_remove(pdev);
900 dev_err(&pdev->dev, "shutdown: remove returned %d\n", ret);
904 * ipa_suspend() - Power management system suspend callback
905 * @dev: IPA device structure
907 * Return: Always returns zero
909 * Called by the PM framework when a system suspend operation is invoked.
910 * Suspends endpoints and releases the clock reference held to keep
911 * the IPA clock running until this point.
913 static int ipa_suspend(struct device *dev)
915 struct ipa *ipa = dev_get_drvdata(dev);
917 /* When a suspended RX endpoint has a packet ready to receive, we
918 * get an IPA SUSPEND interrupt. We trigger a system resume in
919 * that case, but only on the first such interrupt since suspend.
921 __clear_bit(IPA_FLAG_RESUMED, ipa->flags);
923 ipa_endpoint_suspend(ipa);
931 * ipa_resume() - Power management system resume callback
932 * @dev: IPA device structure
934 * Return: Always returns 0
936 * Called by the PM framework when a system resume operation is invoked.
937 * Takes an IPA clock reference to keep the clock running until suspend,
938 * and resumes endpoints.
940 static int ipa_resume(struct device *dev)
942 struct ipa *ipa = dev_get_drvdata(dev);
944 /* This clock reference will keep the IPA out of suspend
945 * until we get a power management suspend request.
949 ipa_endpoint_resume(ipa);
954 static const struct dev_pm_ops ipa_pm_ops = {
955 .suspend = ipa_suspend,
956 .resume = ipa_resume,
959 static struct platform_driver ipa_driver = {
961 .remove = ipa_remove,
962 .shutdown = ipa_shutdown,
966 .of_match_table = ipa_match,
970 module_platform_driver(ipa_driver);
972 MODULE_LICENSE("GPL v2");
973 MODULE_DESCRIPTION("Qualcomm IP Accelerator device driver");