UPSTREAM: NFC: Set active target upon DEP up event reception

As we can potentially get DEP up events without having sent a netlink
command, we need to set the active target properly from dep_link_is_up.
Spontaneous DEP up events can come from devices that detected an active
p2p target. In that case there is no need to call the netlink DEP up
command as the link is already up and running.

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
(cherry picked from commit e29a9e2ae165620d202f3ce45abd3a219b13ffb7)

BUG=chromium:317437
TEST=Tested on a PN544C3 via neard 0.13 using a Nexus 4 as p2p target.

Change-Id: I786726c2b0420bb791a05af56baba322c60ced53
Signed-off-by: Arman Uguray <armansito@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/179680
Reviewed-by: Benson Leung <bleung@chromium.org>
BACKPORT: Update NFC stack to upstream.

This CL updates the NFC stack in chromeos-3.10 to the most recent
upstream changes up to commit 8cc7b932a17e2c1e715575cd69ec5d0e4cd6a9a9.

The following is a short-log of the included patches:

Arman Uguray (1):
      Revert "NFC: llcp: Fix non blocking sockets connections"

Arron Wang (5):
      NFC: Fix secure element state check
      NFC: Update secure element state
      NFC: pn544: Add SE discover operation
      NFC: Export nfc_find_se()
      NFC: pn544: Add SE enable/disable operation

Dan Carpenter (1):
      NFC: hci: Fix enable/disable confusion

Eric Lapuyade (14):
      NFC: Add firmware upload netlink command
      NFC: HCI: Implement fw_upload ops
      NFC: Move nfc_fw_download_done() definition from private to public
      NFC: pn544: i2c: Add firmware download mode power-on support
      NFC: netlink: Add result of firmware operation to completion event
      NFC: pn544: Add firmware operations hci ops
      NFC: pn544: i2c: Add firmware download implementation for pn544
      NFC: NCI: Fix wrong allocation size in nci_spi_allocate_device()
      NFC: NCI: Rename spi ndev -> nsdev and nci_dev -> ndev for consistency
      NFC: NCI: Simplify NCI SPI to become a simple framing/checking layer
      NFC: NCI: Store the spi device pointer from the spi instance
      NFC: NCI: zero struct spi_transfer variables before usage
      NFC: NCI: nci_spi_recv_frame() now returns (not forward) the read frame
      NFC: NCI: Modify NCI SPI to implement CS/INT handshake per the spec

Fengguang Wu (1):
      NFC: digital: digital_tg_send_sensf_res() can be static

Frederic Danis (4):
      NFC: Add basic NCI over SPI
      NFC: Add NCI over SPI send
      NFC: Add NCI over SPI receive
      NFC: Fix NCI over SPI build

Joe Perches (3):
      NFC: Replace nfc_dev_dbg with dev_dbg
      NFC: Convert nfc_dev_info and nfc_dev_err to nfc_<level>
      NFC: Standardize logging style

Olivier Guiter (7):
      NFC: pn533: Fix ACR122 related debug output
      NFC: pn533: Add extended information frame decoding support
      NFC: pn533: Split large Tx frames in chunks
      NFC: pn533: Store the correct frame size (normal vs ext)
      NFC: pn533: Add MI/TG bits only when in Initiator mode
      NFC: pn533: Add support for incoming fragmented frame in target mode
      NFC: pn533: Target mode Tx fragmentation support

Sachin Kamat (2):
      NFC: nfcwilink: Remove redundant dev_set_drvdata
      NFC: pn533: Staticize local symbols

Samuel Ortiz (33):
      NFC: HCI: Follow a positive code path in the HCI ops implementations
      NFC: pn533: Use 0x3 for SENSF_REQ Time Slot Number (TSN)
      NFC: pn533: Copy NFCID2 through ATR_REQ
      NFC: Remove the static supported_se field
      NFC: Extend and fix the internal secure element API
      NFC: Add secure elements addition and removal API
      NFC: Send netlink events for secure elements additions and removals
      NFC: Remove and free all SEs when releasing an NFC device
      NFC: Add secure element enablement internal API
      NFC: Add secure element enablement netlink API
      NFC: llcp: Fix non blocking sockets connections
      NFC: llcp: Do not send pending Tx frames when the remote is not ready
      NFC: llcp: Set the LLC Link Management well known service bit
      NFC: llcp: Fix the well known services endianness
      NFC: netlink: Rename CMD_FW_UPLOAD to CMD_FW_DOWNLOAD
      NFC: pn533: Fix hardware busy loop when establishing the LLCP link
      NFC: pn533: Fix the pn533 polling loop
      NFC: pn533: Request System code from SENSF_REQ
      NFC: pn533: Unconditionaly select the highest p2p bit rate
      NFC: pn533: Enable AUTO RFCA
      NFC: Fix SE discovery failure warning condition
      NFC: Document secure element addition/removal netlink events
      NFC: Define secure element connectivity and transaction events
      NFC: Add a GET_SE netlink API
      NFC: pn533: Add delay between each poll frame
      NFC: pn533: Add some polling entropy
      NFC: pn533: Send ATR_REQ directly for active device detection
      NFC: pn533: Start listen timer from start_poll
      NFC: digital: Remove PR_ERR and PR_DBG macros
      NFC: digital: Add newline to pr_* calls
      NFC: Define secure element IO API and commands
      NFC: netlink: SE API implementation
      NFC: Fix SE API related sparse warning

Thierry Escande (17):
      NFC: Rename nfc_llcp_disconnect() to nfc_llcp_send_disconnect()
      NFC: Keep socket alive until the DISC PDU is actually sent
      NFC: Fix a potential memory leak
      NFC: Add a nfc hardware simulation driver
      NFC: Fix missing static declarations
      NFC: Digital Protocol stack implementation
      NFC Digital: Implement driver commands mechanism
      NFC Digital: Add NFC-A technology support
      NFC Digital: Add NFC-F technology support
      NFC Digital: Add initiator NFC-DEP support
      NFC Digital: Add target NFC-DEP support
      NFC: rawsock: Fix a memory leak
      NFC: digital: Fix sens_res endiannes handling
      NFC: Sony Port-100 Series driver
      NFC: port100: Commands mechanism implementation
      NFC: port100: Add initiator mode support
      NFC: port100: Add target mode support

Valentin Ilie (1):
      NFC: mei_phy: Clean up file

BUG=chromium:328233
TEST=1. Test tag and device pairing on PN544C3.
     2. Test tag and device pairing on PN533 based SCL3711 USB NFC
     dongle.

Signed-off-by: Arman Uguray <armansito@chromium.org>
Change-Id: I90ad005ed393403cf32f308bf5041f78c1c60496
Reviewed-on: https://chromium-review.googlesource.com/179905
Reviewed-by: Olof Johansson <olofj@chromium.org>
UPSTREAM: NFC: Only warn on SE discovery error

SE discovery errors are currently overwriting the dev_up() return error.
This is wrong for many reasons:

- We don't want to report an error if we actually brought the device up
  but it failed to discover SEs. By doing so we pretend we don't have an
  NFC functional device even we do. The only thing we could not do was
  checking for SEs availability. This is the false negative case.

- In some cases the actual device power up failed but the SE discovery
  succeeded. Userspace then believes the device is up while it's not.
  This is the false positive case.

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
(cherry picked from commit a434c2407467a76c0e1416c45f7b31cfbe1b6b3b)
http://git.kernel.org/cgit/linux/kernel/git/sameo/nfc-next.git/commit/?id=a434c2407467a76c0e1416c45f7b31cfbe1b6b3b

BUG=chromium:336972
TEST=Reproduce crbug.com/333426. Try to enable the NFC adapter using
neard. This should fail immediately instead of immediately succeeding.

Change-Id: I2efe21f743c29916e6e6a91b4af59bbf66746627
Signed-off-by: Arman Uguray <armansito@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/183536
Reviewed-by: Benson Leung <bleung@chromium.org>
UPSTREAM: NFC: pn544: Pass hardware variant information when downloading firmware

Different pn544 hardware variant may use different commands to download
new firmwares. The C2 does a regular firmware download while the C3 uses
a more secure protocol.
As a consequence we need to pass the hardware variant from the HCI SW
version command reply down to the pn544 i2c layer, in order to use the
right protocol at run time.

Signed-off-by: Arron Wang <arron.wang@intel.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
(cherry picked from commit ff745a77fc67a2ae7b4899fb278fe3a8c6a88ab6)
https://git.kernel.org/cgit/linux/kernel/git/sameo/nfc-next.git/commit/?id=ff745a77fc67a2ae7b4899fb278fe3a8c6a88ab6

BUG=chromium:327861
TEST=Check using debug statements that the correct hardware variant is
detected on device that has a PN544C3.

Change-Id: Ie6a30772555f7804d72aa6273fb47480dc228395
Signed-off-by: Arman Uguray <armansito@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/184781
Reviewed-by: Ben Chan <benchan@chromium.org>
UPSTREAM: NFC: pn544: i2c: Support PN544 C3 secure firmware download

PN544 C3 firmwares already contain the command frames to be sent, but as
they may exceed the i2c maximum payload, we need to fragment them into
secure chunks and send them through the secure write command.

Signed-off-by: Arron Wang <arron.wang@intel.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
(cherry picked from commit 7d135968db420ba01926cf6811e057aa7fdcf13a)
https://git.kernel.org/cgit/linux/kernel/git/sameo/nfc-next.git/commit/?id=7d135968db420ba01926cf6811e057aa7fdcf13a

BUG=chromium:327861
TEST=Upload the firmware binary to a PN544C3 using nfctool. Once the
operation has succeeded, power up the NFC adapter. Check using dmesg
that the firmware version is correct.

Change-Id: Ie711e7af2b89aa65e21de2494dc51f7b8d618a05
Signed-off-by: Arman Uguray <armansito@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/184782
Reviewed-by: Ben Chan <benchan@chromium.org>