slim_ngd: Add NULL pointer check apart from error check

Check against NULL pointer after allocating
the memory for msm_slim_ctrl structure pointer
dynamically to avoid unexpected crashes.

Earlier this pointer is checked only for error
codes. In this patch NULL pointer check is also
added.

Change-Id: I62096dee82476efaf513a042f2cd95d31e735f9d
Signed-off-by: Kiran Gunda <kgunda@codeaurora.org>
slim_msm: Report flow-error and mask apps slimbus port interrupts

Apps side slimbus ports may overflow/underflow if BAM pipes connected
to those ports don't have descriptors scheduled.
Report such errors and mask the port interrupts until BAM pipes have
descriptors scheduled to avoid interrupts firing multiple times.

Change-Id: I6e475ee8a9e510659996a35633dd9bef7030bd87
Signed-off-by: Sagar Dharia <sdharia@codeaurora.org>
slim_msm: Signal client's completion for per transfer notification

Slimbus ports are connected to BAM pipes and ports inform the pipe
when descriptor's data transfer is done. Clients queue a completion
per descrptor when that descriptor is processed. This completion will
get overwritten if client queues multiple descriptors. Use
per-transfer user-data as client's completion to avoid this problem.
This also reduces controller-driver involvement in data transfer.

Change-Id: I46869a0eaebcc8ff7e932a22b39a06aadb6f72d2
Signed-off-by: Sagar Dharia <sdharia@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
slim_msm: Optimize slimbus data port's connection with BAM pipe

Slimbus data port on apps side can be connected in any diretion (as
source, or as destination). BAM pipe connected to that port should
only be disconnected/reconnected if this port direction changes.
This helps with reducing calls to connect/disconnect BAM pipes.
Allocate descriptors to avoid getting descriptor-space from the
common pool and free them only when the port is deallocated.

Change-Id: I8cab16d852f345cae5e81d67d7eb0ce4d83f928d
Signed-off-by: Sagar Dharia <sdharia@codeaurora.org>
slimbus: Fix port allocation and deallocation for manager's ports

Since Manager's ports don't have any direction when allocated, make
sure the direction is not checked when connect-port is called on a
manager port. Ensure that controller's port resourced are freed-up
when dealloc_mgrports is called.

Change-Id: I7f0cae0eac7e270e7af8f0891b26ac5262645258
Signed-off-by: Sagar Dharia <sdharia@codeaurora.org>
slim_msm: Get platform-specific information from platform-data

Number of pipes available to application processor for data channels,
and product-code field of enumeration address needed for setting
these pipes can be different for different platforms.
Store this platform-specific information in platform-data, and get
it from Device-Tree if applicable.

Change-Id: I6a83600d46fa9df914623a0b2ad57896b61dce6a
Signed-off-by: Sagar Dharia <sdharia@codeaurora.org>
slimbus: Provide framer-booted notification to slimbus device drivers

When slimbus resets (due to bus reset sequence, or after it shuts down
and comes up), framer boots up and starts clocking the bus.
Devices on the bus may be in undefined state at that time. Callback
is provided to slimbus device drivers so that controller can report
framer-booted notification so that drivers can take necessary action
to put devices in reset state so that they can acquire sync, report
present, and be operational.

Change-Id: I40bb8a9e3e979fa78691c690862989d48c35b408
Signed-off-by: Sagar Dharia <sdharia@codeaurora.org>
slim_msm: ngd: Return success for channel removal during ADSP SSR

Slimbus master component resides on ADSP when this driver is used.
Wehn ADSP restarts, slimbus component goes down and bus is not
operational until it comes back up. During restart, slimbus clients
are notified since their device goes down, and the clients remove
channels and/or disconnect ports. Since bus is not operational,
return success for channel removal/port disconnection calls so that
the channel, port state is consistent with HW (not active, removed)

Change-Id: I9f893567c52423bd58445d244adbfe7a19c6b45d
Signed-off-by: Sagar Dharia <sdharia@codeaurora.org>
slim_ngd: Return success for resource removal requests if HW restarts

Channel and ports are removed when HW restarts. Return success to
client channel removal, port disconnection requests when slimbus HW
is restarting.

Change-Id: I8e6a4da8e3154477fe24330aba79bed51d6e6cef
Signed-off-by: Sagar Dharia <sdharia@codeaurora.org>
slim_ngd: Fix logical address notification mechanism

It's possible that multiple slaves report present and expect
corresponding notifications concurrently. Make sure notifications
are sent out in that case. Since notifications cannot be sent when
device doesn't have associated driver, make sure logical address
is not queried in that case.

Change-Id: I2980e1c5c0ad7782dbc5655f55e5efe63a125ddf
Signed-off-by: Sagar Dharia <sdharia@codeaurora.org>
slim_ngd: Handle runtime-pm resume error gracefully

Runtime-pm resume for satellite driver may fail if ADSP is going
through subsystem-restart. Handle that error, and set runtime-pm's
status to suspended if resume fails. Resume typically fails due to
failure to wake slimbus from pause_clock. Make sure another wakeup
can be tried later when ADSP comes back up

Change-Id: Ice88b2ffd528d3a3f229d345c3bbc09f4855b256
Signed-off-by: Sagar Dharia <sdharia@codeaurora.org>
slimbus: Manage channel slots only if framework manages bandwidth

If slimbus controller overrides bandwidth management, channel slots
should not be managed since controller is expected to do that.
Slimbus controller will go into idle mode due to this change when
channel setup/teardown is done. Make sure controller can transition
states correctly in runtime-pm suspend, and system-suspend case.

Change-Id: Ic59423a017c22f7d18f5bafbf7aa5809bbab00f7
Signed-off-by: Sagar Dharia <sdharia@codeaurora.org>
slim_msm: Rectify physical address type

Make sure physical address type is of correct type.

Change-Id: Ide998004894a79d31bcf605eeffdda473d38f0de
Signed-off-by: Sagar Dharia <sdharia@codeaurora.org>
msm: qmi: Match service version and instance during lookup

The remote subsystems construct instance_id from the version and service-
registered instance information. The version field is used to identify the
compatibility between client and service. The instance field is used to
uniquely identify a service from multiple instances of the same service_id
and version.

Currently the kernel QMI client interface matches only the instance during
the service lookup. Update the kernel QMI client interface to construct
instance_id from the version and instance information during lookup.

Change-Id: Ifc61570cf67f487c16acff47d1b7fb1aede2eb8e
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>
Slimbus: Correct the conditional check during channel removal

Use actual channel number to check if the channel to be
removed is present in the define_chan list before removing
it, instead of using the internal channel number used by
the frame work.

Change-Id: Ia53b1708482fca84985ae0d5a2632c3512b2c29c
Signed-off-by: Kiran Gunda <kgunda@codeaurora.org>
slim_msm: Add support for external MDM restart

If external MDM restarts when MDM slimbus channels are active, it
is possible that the MDM framer was clocking the bus, and ADSP was
not active. Make sure apps wakes up ADSP and checks the framer status
so that slimbus is clocked by ADSP instead of MDM, and communication
over slimbus is restored.

Change-Id: Ia75950770fa3eee3afbc8940e4b2d5437d922e9c
Signed-off-by: Naveen Kaje <nkaje@codeaurora.org>
slimbus: Fix logical address notification mechanism

Make sure device-up/down notifications don't involve race condition,
and sub-system restart in such cases is handled gracefully

Change-Id: Ie13eb16e24bcb4b98c84b8351f8c9231a84117fa
Signed-off-by: Sagar Dharia <sdharia@codeaurora.org>
slim_ngd: Handle error flags before handling SENT flag

It's possible that error flags were set alongwith SENT flag for
TX transaction status. In such a scenario, error flag status should
be handled (and SENT flag should be cleared). Move error-flag
handling ahead of SENT flag handling to avoid interrupt being called
twice, and completion being set twice.

Change-Id: I0b8dadd0c5197e049f8d1cd87af4a803a30b0987
Signed-off-by: Sagar Dharia <sdharia@codeaurora.org>
Signed-off-by: Kiran Gunda <kgunda@codeaurora.org>
slimbus: Enable clients to send user messages to devices.

Slimbus protocol allows user messages of destination referred, or
source referred type to be sent to a slimbus device.
Provide framework to support such messages. Note that, controller
may not support all user messages.

Change-Id: I4b8371eaf2b49d81c089d388a6f5299923774f04
Signed-off-by: Sagar Dharia <sdharia@codeaurora.org>
slim_ngd: Support REPEAT_CHANGE_VALUE user message

REPEAT_CHANGE_VALUE user message is used to transfer high amount of
messaging data efficiently.

Change-Id: I39e75f0c73570aaf8f70dfb7077f70664f27a427
Signed-off-by: Sagar Dharia <sdharia@codeaurora.org>