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 * When in suspended state, the IPA can trigger a resume by sending a SUSPEND
81 static void ipa_suspend_handler(struct ipa *ipa, enum ipa_irq_id irq_id)
83 /* Take a a single clock reference to prevent suspend. All
84 * endpoints will be resumed as a result. This reference will
85 * be dropped when we get a power management suspend request.
87 if (!atomic_xchg(&ipa->suspend_ref, 1))
90 /* Acknowledge/clear the suspend interrupt on all endpoints */
91 ipa_interrupt_suspend_clear_all(ipa->interrupt);
95 * ipa_setup() - Set up IPA hardware
98 * Perform initialization that requires issuing immediate commands on
99 * the command TX endpoint. If the modem is doing GSI firmware load
100 * and initialization, this function will be called when an SMP2P
101 * interrupt has been signaled by the modem. Otherwise it will be
102 * called from ipa_probe() after GSI firmware has been successfully
103 * loaded, authenticated, and started by Trust Zone.
105 int ipa_setup(struct ipa *ipa)
107 struct ipa_endpoint *exception_endpoint;
108 struct ipa_endpoint *command_endpoint;
111 /* Setup for IPA v3.5.1 has some slight differences */
112 ret = gsi_setup(&ipa->gsi, ipa->version == IPA_VERSION_3_5_1);
116 ipa->interrupt = ipa_interrupt_setup(ipa);
117 if (IS_ERR(ipa->interrupt)) {
118 ret = PTR_ERR(ipa->interrupt);
119 goto err_gsi_teardown;
121 ipa_interrupt_add(ipa->interrupt, IPA_IRQ_TX_SUSPEND,
122 ipa_suspend_handler);
126 ipa_endpoint_setup(ipa);
128 /* We need to use the AP command TX endpoint to perform other
129 * initialization, so we enable first.
131 command_endpoint = ipa->name_map[IPA_ENDPOINT_AP_COMMAND_TX];
132 ret = ipa_endpoint_enable_one(command_endpoint);
134 goto err_endpoint_teardown;
136 ret = ipa_mem_setup(ipa);
138 goto err_command_disable;
140 ret = ipa_table_setup(ipa);
142 goto err_mem_teardown;
144 /* Enable the exception handling endpoint, and tell the hardware
145 * to use it by default.
147 exception_endpoint = ipa->name_map[IPA_ENDPOINT_AP_LAN_RX];
148 ret = ipa_endpoint_enable_one(exception_endpoint);
150 goto err_table_teardown;
152 ipa_endpoint_default_route_set(ipa, exception_endpoint->endpoint_id);
154 /* We're all set. Now prepare for communication with the modem */
155 ret = ipa_modem_setup(ipa);
157 goto err_default_route_clear;
159 ipa->setup_complete = true;
161 dev_info(&ipa->pdev->dev, "IPA driver setup completed successfully\n");
165 err_default_route_clear:
166 ipa_endpoint_default_route_clear(ipa);
167 ipa_endpoint_disable_one(exception_endpoint);
169 ipa_table_teardown(ipa);
171 ipa_mem_teardown(ipa);
173 ipa_endpoint_disable_one(command_endpoint);
174 err_endpoint_teardown:
175 ipa_endpoint_teardown(ipa);
176 ipa_uc_teardown(ipa);
177 ipa_interrupt_remove(ipa->interrupt, IPA_IRQ_TX_SUSPEND);
178 ipa_interrupt_teardown(ipa->interrupt);
180 gsi_teardown(&ipa->gsi);
186 * ipa_teardown() - Inverse of ipa_setup()
189 static void ipa_teardown(struct ipa *ipa)
191 struct ipa_endpoint *exception_endpoint;
192 struct ipa_endpoint *command_endpoint;
194 ipa_modem_teardown(ipa);
195 ipa_endpoint_default_route_clear(ipa);
196 exception_endpoint = ipa->name_map[IPA_ENDPOINT_AP_LAN_RX];
197 ipa_endpoint_disable_one(exception_endpoint);
198 ipa_table_teardown(ipa);
199 ipa_mem_teardown(ipa);
200 command_endpoint = ipa->name_map[IPA_ENDPOINT_AP_COMMAND_TX];
201 ipa_endpoint_disable_one(command_endpoint);
202 ipa_endpoint_teardown(ipa);
203 ipa_uc_teardown(ipa);
204 ipa_interrupt_remove(ipa->interrupt, IPA_IRQ_TX_SUSPEND);
205 ipa_interrupt_teardown(ipa->interrupt);
206 gsi_teardown(&ipa->gsi);
209 /* Configure QMB Core Master Port selection */
210 static void ipa_hardware_config_comp(struct ipa *ipa)
214 /* Nothing to configure for IPA v3.5.1 */
215 if (ipa->version == IPA_VERSION_3_5_1)
218 val = ioread32(ipa->reg_virt + IPA_REG_COMP_CFG_OFFSET);
220 if (ipa->version == IPA_VERSION_4_0) {
221 val &= ~IPA_QMB_SELECT_CONS_EN_FMASK;
222 val &= ~IPA_QMB_SELECT_PROD_EN_FMASK;
223 val &= ~IPA_QMB_SELECT_GLOBAL_EN_FMASK;
225 val |= GSI_MULTI_AXI_MASTERS_DIS_FMASK;
228 val |= GSI_MULTI_INORDER_RD_DIS_FMASK;
229 val |= GSI_MULTI_INORDER_WR_DIS_FMASK;
231 iowrite32(val, ipa->reg_virt + IPA_REG_COMP_CFG_OFFSET);
234 /* Configure DDR and PCIe max read/write QSB values */
235 static void ipa_hardware_config_qsb(struct ipa *ipa)
239 /* QMB_0 represents DDR; QMB_1 represents PCIe (not present in 4.2) */
240 val = u32_encode_bits(8, GEN_QMB_0_MAX_WRITES_FMASK);
241 if (ipa->version == IPA_VERSION_4_2)
242 val |= u32_encode_bits(0, GEN_QMB_1_MAX_WRITES_FMASK);
244 val |= u32_encode_bits(4, GEN_QMB_1_MAX_WRITES_FMASK);
245 iowrite32(val, ipa->reg_virt + IPA_REG_QSB_MAX_WRITES_OFFSET);
247 if (ipa->version == IPA_VERSION_3_5_1) {
248 val = u32_encode_bits(8, GEN_QMB_0_MAX_READS_FMASK);
249 val |= u32_encode_bits(12, GEN_QMB_1_MAX_READS_FMASK);
251 val = u32_encode_bits(12, GEN_QMB_0_MAX_READS_FMASK);
252 if (ipa->version == IPA_VERSION_4_2)
253 val |= u32_encode_bits(0, GEN_QMB_1_MAX_READS_FMASK);
255 val |= u32_encode_bits(12, GEN_QMB_1_MAX_READS_FMASK);
256 /* GEN_QMB_0_MAX_READS_BEATS is 0 */
257 /* GEN_QMB_1_MAX_READS_BEATS is 0 */
259 iowrite32(val, ipa->reg_virt + IPA_REG_QSB_MAX_READS_OFFSET);
262 static void ipa_idle_indication_cfg(struct ipa *ipa,
263 u32 enter_idle_debounce_thresh,
264 bool const_non_idle_enable)
269 val = u32_encode_bits(enter_idle_debounce_thresh,
270 ENTER_IDLE_DEBOUNCE_THRESH_FMASK);
271 if (const_non_idle_enable)
272 val |= CONST_NON_IDLE_ENABLE_FMASK;
274 offset = ipa_reg_idle_indication_cfg_offset(ipa->version);
275 iowrite32(val, ipa->reg_virt + offset);
279 * ipa_hardware_dcd_config() - Enable dynamic clock division on IPA
282 * Configures when the IPA signals it is idle to the global clock
283 * controller, which can respond by scalling down the clock to
286 static void ipa_hardware_dcd_config(struct ipa *ipa)
288 /* Recommended values for IPA 3.5 according to IPA HPG */
289 ipa_idle_indication_cfg(ipa, 256, false);
292 static void ipa_hardware_dcd_deconfig(struct ipa *ipa)
294 /* Power-on reset values */
295 ipa_idle_indication_cfg(ipa, 0, true);
299 * ipa_hardware_config() - Primitive hardware initialization
302 static void ipa_hardware_config(struct ipa *ipa)
307 /* Fill in backward-compatibility register, based on version */
308 val = ipa_reg_bcr_val(ipa->version);
309 iowrite32(val, ipa->reg_virt + IPA_REG_BCR_OFFSET);
311 if (ipa->version != IPA_VERSION_3_5_1) {
312 /* Enable open global clocks (hardware workaround) */
314 val |= GLOBAL_2X_CLK_FMASK;
315 iowrite32(val, ipa->reg_virt + IPA_REG_CLKON_CFG_OFFSET);
317 /* Disable PA mask to allow HOLB drop (hardware workaround) */
318 val = ioread32(ipa->reg_virt + IPA_REG_TX_CFG_OFFSET);
320 iowrite32(val, ipa->reg_virt + IPA_REG_TX_CFG_OFFSET);
323 ipa_hardware_config_comp(ipa);
325 /* Configure system bus limits */
326 ipa_hardware_config_qsb(ipa);
328 /* Configure aggregation granularity */
329 val = ioread32(ipa->reg_virt + IPA_REG_COUNTER_CFG_OFFSET);
330 granularity = ipa_aggr_granularity_val(IPA_AGGR_GRANULARITY);
331 val = u32_encode_bits(granularity, AGGR_GRANULARITY);
332 iowrite32(val, ipa->reg_virt + IPA_REG_COUNTER_CFG_OFFSET);
334 /* Disable hashed IPv4 and IPv6 routing and filtering for IPA v4.2 */
335 if (ipa->version == IPA_VERSION_4_2)
336 iowrite32(0, ipa->reg_virt + IPA_REG_FILT_ROUT_HASH_EN_OFFSET);
338 /* Enable dynamic clock division */
339 ipa_hardware_dcd_config(ipa);
343 * ipa_hardware_deconfig() - Inverse of ipa_hardware_config()
346 * This restores the power-on reset values (even if they aren't different)
348 static void ipa_hardware_deconfig(struct ipa *ipa)
350 /* Mostly we just leave things as we set them. */
351 ipa_hardware_dcd_deconfig(ipa);
354 #ifdef IPA_VALIDATION
356 /* # IPA resources used based on version (see IPA_RESOURCE_GROUP_COUNT) */
357 static int ipa_resource_group_count(struct ipa *ipa)
359 switch (ipa->version) {
360 case IPA_VERSION_3_5_1:
363 case IPA_VERSION_4_0:
364 case IPA_VERSION_4_1:
367 case IPA_VERSION_4_2:
375 static bool ipa_resource_limits_valid(struct ipa *ipa,
376 const struct ipa_resource_data *data)
378 u32 group_count = ipa_resource_group_count(ipa);
385 /* Return an error if a non-zero resource group limit is specified
386 * for a resource not supported by hardware.
388 for (i = 0; i < data->resource_src_count; i++) {
389 const struct ipa_resource_src *resource;
391 resource = &data->resource_src[i];
392 for (j = group_count; j < IPA_RESOURCE_GROUP_COUNT; j++)
393 if (resource->limits[j].min || resource->limits[j].max)
397 for (i = 0; i < data->resource_dst_count; i++) {
398 const struct ipa_resource_dst *resource;
400 resource = &data->resource_dst[i];
401 for (j = group_count; j < IPA_RESOURCE_GROUP_COUNT; j++)
402 if (resource->limits[j].min || resource->limits[j].max)
409 #else /* !IPA_VALIDATION */
411 static bool ipa_resource_limits_valid(struct ipa *ipa,
412 const struct ipa_resource_data *data)
417 #endif /* !IPA_VALIDATION */
420 ipa_resource_config_common(struct ipa *ipa, u32 offset,
421 const struct ipa_resource_limits *xlimits,
422 const struct ipa_resource_limits *ylimits)
426 val = u32_encode_bits(xlimits->min, X_MIN_LIM_FMASK);
427 val |= u32_encode_bits(xlimits->max, X_MAX_LIM_FMASK);
428 val |= u32_encode_bits(ylimits->min, Y_MIN_LIM_FMASK);
429 val |= u32_encode_bits(ylimits->max, Y_MAX_LIM_FMASK);
431 iowrite32(val, ipa->reg_virt + offset);
434 static void ipa_resource_config_src_01(struct ipa *ipa,
435 const struct ipa_resource_src *resource)
437 u32 offset = IPA_REG_SRC_RSRC_GRP_01_RSRC_TYPE_N_OFFSET(resource->type);
439 ipa_resource_config_common(ipa, offset,
440 &resource->limits[0], &resource->limits[1]);
443 static void ipa_resource_config_src_23(struct ipa *ipa,
444 const struct ipa_resource_src *resource)
446 u32 offset = IPA_REG_SRC_RSRC_GRP_23_RSRC_TYPE_N_OFFSET(resource->type);
448 ipa_resource_config_common(ipa, offset,
449 &resource->limits[2], &resource->limits[3]);
452 static void ipa_resource_config_dst_01(struct ipa *ipa,
453 const struct ipa_resource_dst *resource)
455 u32 offset = IPA_REG_DST_RSRC_GRP_01_RSRC_TYPE_N_OFFSET(resource->type);
457 ipa_resource_config_common(ipa, offset,
458 &resource->limits[0], &resource->limits[1]);
461 static void ipa_resource_config_dst_23(struct ipa *ipa,
462 const struct ipa_resource_dst *resource)
464 u32 offset = IPA_REG_DST_RSRC_GRP_23_RSRC_TYPE_N_OFFSET(resource->type);
466 ipa_resource_config_common(ipa, offset,
467 &resource->limits[2], &resource->limits[3]);
471 ipa_resource_config(struct ipa *ipa, const struct ipa_resource_data *data)
475 if (!ipa_resource_limits_valid(ipa, data))
478 for (i = 0; i < data->resource_src_count; i++) {
479 ipa_resource_config_src_01(ipa, &data->resource_src[i]);
480 ipa_resource_config_src_23(ipa, &data->resource_src[i]);
483 for (i = 0; i < data->resource_dst_count; i++) {
484 ipa_resource_config_dst_01(ipa, &data->resource_dst[i]);
485 ipa_resource_config_dst_23(ipa, &data->resource_dst[i]);
491 static void ipa_resource_deconfig(struct ipa *ipa)
497 * ipa_config() - Configure IPA hardware
499 * @data: IPA configuration data
501 * Perform initialization requiring IPA clock to be enabled.
503 static int ipa_config(struct ipa *ipa, const struct ipa_data *data)
507 /* Get a clock reference to allow initialization. This reference
508 * is held after initialization completes, and won't get dropped
509 * unless/until a system suspend request arrives.
511 atomic_set(&ipa->suspend_ref, 1);
514 ipa_hardware_config(ipa);
516 ret = ipa_endpoint_config(ipa);
518 goto err_hardware_deconfig;
520 ret = ipa_mem_config(ipa);
522 goto err_endpoint_deconfig;
524 ipa_table_config(ipa);
526 /* Assign resource limitation to each group */
527 ret = ipa_resource_config(ipa, data->resource_data);
529 goto err_table_deconfig;
531 ret = ipa_modem_config(ipa);
533 goto err_resource_deconfig;
537 err_resource_deconfig:
538 ipa_resource_deconfig(ipa);
540 ipa_table_deconfig(ipa);
541 ipa_mem_deconfig(ipa);
542 err_endpoint_deconfig:
543 ipa_endpoint_deconfig(ipa);
544 err_hardware_deconfig:
545 ipa_hardware_deconfig(ipa);
547 atomic_set(&ipa->suspend_ref, 0);
553 * ipa_deconfig() - Inverse of ipa_config()
556 static void ipa_deconfig(struct ipa *ipa)
558 ipa_modem_deconfig(ipa);
559 ipa_resource_deconfig(ipa);
560 ipa_table_deconfig(ipa);
561 ipa_mem_deconfig(ipa);
562 ipa_endpoint_deconfig(ipa);
563 ipa_hardware_deconfig(ipa);
565 atomic_set(&ipa->suspend_ref, 0);
568 static int ipa_firmware_load(struct device *dev)
570 const struct firmware *fw;
571 struct device_node *node;
578 node = of_parse_phandle(dev->of_node, "memory-region", 0);
580 dev_err(dev, "DT error getting \"memory-region\" property\n");
584 ret = of_address_to_resource(node, 0, &res);
586 dev_err(dev, "error %d getting \"memory-region\" resource\n",
591 ret = request_firmware(&fw, IPA_FWS_PATH, dev);
593 dev_err(dev, "error %d requesting \"%s\"\n", ret, IPA_FWS_PATH);
598 size = (size_t)resource_size(&res);
599 virt = memremap(phys, size, MEMREMAP_WC);
601 dev_err(dev, "unable to remap firmware memory\n");
603 goto out_release_firmware;
606 ret = qcom_mdt_load(dev, fw, IPA_FWS_PATH, IPA_PAS_ID,
607 virt, phys, size, NULL);
609 dev_err(dev, "error %d loading \"%s\"\n", ret, IPA_FWS_PATH);
610 else if ((ret = qcom_scm_pas_auth_and_reset(IPA_PAS_ID)))
611 dev_err(dev, "error %d authenticating \"%s\"\n", ret,
615 out_release_firmware:
616 release_firmware(fw);
621 static const struct of_device_id ipa_match[] = {
623 .compatible = "qcom,sdm845-ipa",
624 .data = &ipa_data_sdm845,
627 .compatible = "qcom,sc7180-ipa",
628 .data = &ipa_data_sc7180,
632 MODULE_DEVICE_TABLE(of, ipa_match);
634 static phandle of_property_read_phandle(const struct device_node *np,
637 struct property *prop;
640 prop = of_find_property(np, name, &len);
641 if (!prop || len != sizeof(__be32))
644 return be32_to_cpup(prop->value);
647 /* Check things that can be validated at build time. This just
648 * groups these things BUILD_BUG_ON() calls don't clutter the rest
651 static void ipa_validate_build(void)
654 /* We assume we're working on 64-bit hardware */
655 BUILD_BUG_ON(!IS_ENABLED(CONFIG_64BIT));
657 /* Code assumes the EE ID for the AP is 0 (zeroed structure field) */
658 BUILD_BUG_ON(GSI_EE_AP != 0);
660 /* There's no point if we have no channels or event rings */
661 BUILD_BUG_ON(!GSI_CHANNEL_COUNT_MAX);
662 BUILD_BUG_ON(!GSI_EVT_RING_COUNT_MAX);
664 /* GSI hardware design limits */
665 BUILD_BUG_ON(GSI_CHANNEL_COUNT_MAX > 32);
666 BUILD_BUG_ON(GSI_EVT_RING_COUNT_MAX > 31);
668 /* The number of TREs in a transaction is limited by the channel's
669 * TLV FIFO size. A transaction structure uses 8-bit fields
670 * to represents the number of TREs it has allocated and used.
672 BUILD_BUG_ON(GSI_TLV_MAX > U8_MAX);
674 /* Exceeding 128 bytes makes the transaction pool *much* larger */
675 BUILD_BUG_ON(sizeof(struct gsi_trans) > 128);
677 /* This is used as a divisor */
678 BUILD_BUG_ON(!IPA_AGGR_GRANULARITY);
680 /* Aggregation granularity value can't be 0, and must fit */
681 BUILD_BUG_ON(!ipa_aggr_granularity_val(IPA_AGGR_GRANULARITY));
682 BUILD_BUG_ON(ipa_aggr_granularity_val(IPA_AGGR_GRANULARITY) >
683 field_max(AGGR_GRANULARITY));
684 #endif /* IPA_VALIDATE */
688 * ipa_probe() - IPA platform driver probe function
689 * @pdev: Platform device pointer
691 * Return: 0 if successful, or a negative error code (possibly
694 * This is the main entry point for the IPA driver. Initialization proceeds
696 * - The "init" stage involves activities that can be initialized without
697 * access to the IPA hardware.
698 * - The "config" stage requires the IPA clock to be active so IPA registers
699 * can be accessed, but does not require the use of IPA immediate commands.
700 * - The "setup" stage uses IPA immediate commands, and so requires the GSI
701 * layer to be initialized.
703 * A Boolean Device Tree "modem-init" property determines whether GSI
704 * initialization will be performed by the AP (Trust Zone) or the modem.
705 * If the AP does GSI initialization, the setup phase is entered after
706 * this has completed successfully. Otherwise the modem initializes
707 * the GSI layer and signals it has finished by sending an SMP2P interrupt
708 * to the AP; this triggers the start if IPA setup.
710 static int ipa_probe(struct platform_device *pdev)
712 struct wakeup_source *wakeup_source;
713 struct device *dev = &pdev->dev;
714 const struct ipa_data *data;
715 struct ipa_clock *clock;
724 ipa_validate_build();
726 /* If we need Trust Zone, make sure it's available */
727 modem_init = of_property_read_bool(dev->of_node, "modem-init");
729 if (!qcom_scm_is_available())
730 return -EPROBE_DEFER;
732 /* We rely on remoteproc to tell us about modem state changes */
733 phandle = of_property_read_phandle(dev->of_node, "modem-remoteproc");
735 dev_err(dev, "DT missing \"modem-remoteproc\" property\n");
739 rproc = rproc_get_by_phandle(phandle);
741 return -EPROBE_DEFER;
743 /* The clock and interconnects might not be ready when we're
744 * probed, so might return -EPROBE_DEFER.
746 clock = ipa_clock_init(dev);
748 ret = PTR_ERR(clock);
752 /* No more EPROBE_DEFER. Get our configuration data */
753 data = of_device_get_match_data(dev);
755 /* This is really IPA_VALIDATE (should never happen) */
756 dev_err(dev, "matched hardware not supported\n");
761 /* Create a wakeup source. */
762 wakeup_source = wakeup_source_register(dev, "ipa");
763 if (!wakeup_source) {
764 /* The most likely reason for failure is memory exhaustion */
769 /* Allocate and initialize the IPA structure */
770 ipa = kzalloc(sizeof(*ipa), GFP_KERNEL);
773 goto err_wakeup_source_unregister;
777 dev_set_drvdata(dev, ipa);
778 ipa->modem_rproc = rproc;
780 atomic_set(&ipa->suspend_ref, 0);
781 ipa->wakeup_source = wakeup_source;
782 ipa->version = data->version;
784 ret = ipa_reg_init(ipa);
788 ret = ipa_mem_init(ipa, data->mem_data);
792 /* GSI v2.0+ (IPA v4.0+) uses prefetch for the command channel */
793 prefetch = ipa->version != IPA_VERSION_3_5_1;
794 /* IPA v4.2 requires the AP to allocate channels for the modem */
795 modem_alloc = ipa->version == IPA_VERSION_4_2;
797 ret = gsi_init(&ipa->gsi, pdev, prefetch, data->endpoint_count,
798 data->endpoint_data, modem_alloc);
802 /* Result is a non-zero mask endpoints that support filtering */
803 ipa->filter_map = ipa_endpoint_init(ipa, data->endpoint_count,
804 data->endpoint_data);
805 if (!ipa->filter_map) {
810 ret = ipa_table_init(ipa);
812 goto err_endpoint_exit;
814 ret = ipa_modem_init(ipa, modem_init);
818 ret = ipa_config(ipa, data);
822 dev_info(dev, "IPA driver initialized");
824 /* If the modem is doing early initialization, it will trigger a
825 * call to ipa_setup() call when it has finished. In that case
831 /* Otherwise we need to load the firmware and have Trust Zone validate
832 * and install it. If that succeeds we can proceed with setup.
834 ret = ipa_firmware_load(dev);
838 ret = ipa_setup(ipa);
851 ipa_endpoint_exit(ipa);
860 err_wakeup_source_unregister:
861 wakeup_source_unregister(wakeup_source);
863 ipa_clock_exit(clock);
870 static int ipa_remove(struct platform_device *pdev)
872 struct ipa *ipa = dev_get_drvdata(&pdev->dev);
873 struct rproc *rproc = ipa->modem_rproc;
874 struct ipa_clock *clock = ipa->clock;
875 struct wakeup_source *wakeup_source;
878 wakeup_source = ipa->wakeup_source;
880 if (ipa->setup_complete) {
881 ret = ipa_modem_stop(ipa);
891 ipa_endpoint_exit(ipa);
896 wakeup_source_unregister(wakeup_source);
897 ipa_clock_exit(clock);
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.
911 static int ipa_suspend(struct device *dev)
913 struct ipa *ipa = dev_get_drvdata(dev);
916 atomic_set(&ipa->suspend_ref, 0);
922 * ipa_resume() - Power management system resume callback
923 * @dev: IPA device structure
925 * Return: Always returns 0
927 * Called by the PM framework when a system resume operation is invoked.
929 static int ipa_resume(struct device *dev)
931 struct ipa *ipa = dev_get_drvdata(dev);
933 /* This clock reference will keep the IPA out of suspend
934 * until we get a power management suspend request.
936 atomic_set(&ipa->suspend_ref, 1);
942 static const struct dev_pm_ops ipa_pm_ops = {
943 .suspend = ipa_suspend,
944 .resume = ipa_resume,
947 static struct platform_driver ipa_driver = {
949 .remove = ipa_remove,
953 .of_match_table = ipa_match,
957 module_platform_driver(ipa_driver);
959 MODULE_LICENSE("GPL v2");
960 MODULE_DESCRIPTION("Qualcomm IP Accelerator device driver");