/*
 * Copyright (C) ST-Ericsson AB 2010
 * Author:	Sjur Brendeland
 * License terms: GNU General Public License (GPL) version 2
 */

#ifndef CFCTRL_H_
#define CFCTRL_H_
#include <net/caif/caif_layer.h>
#include <net/caif/cfsrvl.h>

/* CAIF Control packet commands */
enum cfctrl_cmd {
	CFCTRL_CMD_LINK_SETUP = 0,
	CFCTRL_CMD_LINK_DESTROY = 1,
	CFCTRL_CMD_LINK_ERR = 2,
	CFCTRL_CMD_ENUM = 3,
	CFCTRL_CMD_SLEEP = 4,
	CFCTRL_CMD_WAKE = 5,
	CFCTRL_CMD_LINK_RECONF = 6,
	CFCTRL_CMD_START_REASON = 7,
	CFCTRL_CMD_RADIO_SET = 8,
	CFCTRL_CMD_MODEM_SET = 9,
	CFCTRL_CMD_MASK = 0xf
};

/* Channel types */
enum cfctrl_srv {
	CFCTRL_SRV_DECM = 0,
	CFCTRL_SRV_VEI = 1,
	CFCTRL_SRV_VIDEO = 2,
	CFCTRL_SRV_DBG = 3,
	CFCTRL_SRV_DATAGRAM = 4,
	CFCTRL_SRV_RFM = 5,
	CFCTRL_SRV_UTIL = 6,
	CFCTRL_SRV_MASK = 0xf
};

#define CFCTRL_RSP_BIT 0x20
#define CFCTRL_ERR_BIT 0x10

struct cfctrl_rsp {
	void (*linksetup_rsp)(struct cflayer *layer, u8 linkid,
			      enum cfctrl_srv serv, u8 phyid,
			      struct cflayer *adapt_layer);
	void (*linkdestroy_rsp)(struct cflayer *layer, u8 linkid);
	void (*linkerror_ind)(void);
	void (*enum_rsp)(void);
	void (*sleep_rsp)(void);
	void (*wake_rsp)(void);
	void (*restart_rsp)(void);
	void (*radioset_rsp)(void);
	void (*reject_rsp)(struct cflayer *layer, u8 linkid,
				struct cflayer *client_layer);
};

/* Link Setup Parameters for CAIF-Links. */
struct cfctrl_link_param {
	enum cfctrl_srv linktype;/* (T3,T0) Type of Channel */
	u8 priority;		  /* (P4,P0) Priority of the channel */
	u8 phyid;		  /* (U2-U0) Physical interface to connect */
	u8 endpoint;		  /* (E1,E0) Endpoint for data channels */
	u8 chtype;		  /* (H1,H0) Channel-Type, applies to
				   *            VEI, DEBUG */
	union {
		struct {
			u8 connid;	/*  (D7,D0) Video LinkId */
		} video;

		struct {
			u32 connid;	/* (N31,Ngit0) Connection ID used
					 *  for Datagram */
		} datagram;

		struct {
			u32 connid;	/* Connection ID used for RFM */
			char volume[20];	/* Volume to mount for RFM */
		} rfm;		/* Configuration for RFM */

		struct {
			u16 fifosize_kb;	/* Psock FIFO size in KB */
			u16 fifosize_bufs;	/* Psock # signal buffers */
			char name[16];	/* Name of the PSOCK service */
			u8 params[255];	/* Link setup Parameters> */
			u16 paramlen;	/* Length of Link Setup
						 *   Parameters */
		} utility;	/* Configuration for Utility Links (Psock) */
	} u;
};

/* This structure is used internally in CFCTRL */
struct cfctrl_request_info {
	int sequence_no;
	enum cfctrl_cmd cmd;
	u8 channel_id;
	struct cfctrl_link_param param;
	struct cflayer *client_layer;
	struct list_head list;
};

struct cfctrl {
	struct cfsrvl serv;
	struct cfctrl_rsp res;
	atomic_t req_seq_no;
	atomic_t rsp_seq_no;
	struct list_head list;
	/* Protects from simultaneous access to first_req list */
	spinlock_t info_list_lock;
#ifndef CAIF_NO_LOOP
	u8 loop_linkid;
	int loop_linkused[256];
	/* Protects simultaneous access to loop_linkid and loop_linkused */
	spinlock_t loop_linkid_lock;
#endif

};

void cfctrl_enum_req(struct cflayer *cfctrl, u8 physlinkid);
int cfctrl_linkup_request(struct cflayer *cfctrl,
			   struct cfctrl_link_param *param,
			   struct cflayer *user_layer);
int  cfctrl_linkdown_req(struct cflayer *cfctrl, u8 linkid,
			 struct cflayer *client);

struct cflayer *cfctrl_create(void);
struct cfctrl_rsp *cfctrl_get_respfuncs(struct cflayer *layer);
int cfctrl_cancel_req(struct cflayer *layr, struct cflayer *adap_layer);
void cfctrl_remove(struct cflayer *layr);

#endif				/* CFCTRL_H_ */
/td><td class='ctrl'><select name='context' onchange='this.form.submit();'><option value='1'>1</option><option value='2'>2</option><option value='3' selected='selected'>3</option><option value='4'>4</option><option value='5'>5</option><option value='6'>6</option><option value='7'>7</option><option value='8'>8</option><option value='9'>9</option><option value='10'>10</option><option value='15'>15</option><option value='20'>20</option><option value='25'>25</option><option value='30'>30</option><option value='35'>35</option><option value='40'>40</option></select></td></tr><tr><td class='label'>space:</td><td class='ctrl'><select name='ignorews' onchange='this.form.submit();'><option value='0' selected='selected'>include</option><option value='1'>ignore</option></select></td></tr><tr><td class='label'>mode:</td><td class='ctrl'><select name='dt' onchange='this.form.submit();'><option value='0' selected='selected'>unified</option><option value='1'>ssdiff</option><option value='2'>stat only</option></select></td></tr><tr><td/><td class='ctrl'><noscript><input type='submit' value='reload'/></noscript></td></tr></table></form></div><table summary='commit info' class='commit-info'>
<tr><th>author</th><td>Bjorn Helgaas &lt;bhelgaas@google.com&gt;</td><td class='right'>2017-01-27 15:00:45 -0600</td></tr>
<tr><th>committer</th><td>Bjorn Helgaas &lt;bhelgaas@google.com&gt;</td><td class='right'>2017-01-27 15:00:45 -0600</td></tr>
<tr><th>commit</th><td colspan='2' class='oid'><a href='/cgit.cgi/linux/net-next.git/commit/sound/soc/fsl/p1022_rdk.c?id=030305d69fc6963c16003f50d7e8d74b02d0a143'>030305d69fc6963c16003f50d7e8d74b02d0a143</a> (<a href='/cgit.cgi/linux/net-next.git/patch/sound/soc/fsl/p1022_rdk.c?id=030305d69fc6963c16003f50d7e8d74b02d0a143'>patch</a>)</td></tr>
<tr><th>tree</th><td colspan='2' class='oid'><a href='/cgit.cgi/linux/net-next.git/tree/?id=030305d69fc6963c16003f50d7e8d74b02d0a143'>363a4e34d199178769b7e7eeb26ea2620a55847b</a> /<a href='/cgit.cgi/linux/net-next.git/tree/sound/soc/fsl/p1022_rdk.c?id=030305d69fc6963c16003f50d7e8d74b02d0a143'>sound/soc/fsl/p1022_rdk.c</a></td></tr>
<tr><th>parent</th><td colspan='2' class='oid'><a href='/cgit.cgi/linux/net-next.git/commit/sound/soc/fsl/p1022_rdk.c?id=4d191b1b63c209e37bf27938ef365244d3c41084'>4d191b1b63c209e37bf27938ef365244d3c41084</a> (<a href='/cgit.cgi/linux/net-next.git/diff/sound/soc/fsl/p1022_rdk.c?id=030305d69fc6963c16003f50d7e8d74b02d0a143&amp;id2=4d191b1b63c209e37bf27938ef365244d3c41084'>diff</a>)</td></tr></table>
<div class='commit-subject'>PCI/ASPM: Handle PCI-to-PCIe bridges as roots of PCIe hierarchies</div><div class='commit-msg'>In a struct pcie_link_state, link-&gt;root points to the pcie_link_state of
the root of the PCIe hierarchy.  For the topmost link, this points to
itself (link-&gt;root = link).  For others, we copy the pointer from the
parent (link-&gt;root = link-&gt;parent-&gt;root).

Previously we recognized that Root Ports originated PCIe hierarchies, but
we treated PCI/PCI-X to PCIe Bridges as being in the middle of the
hierarchy, and when we tried to copy the pointer from link-&gt;parent-&gt;root,
there was no parent, and we dereferenced a NULL pointer:

  BUG: unable to handle kernel NULL pointer dereference at 0000000000000090
  IP: [&lt;ffffffff9e424350&gt;] pcie_aspm_init_link_state+0x170/0x820

Recognize that PCI/PCI-X to PCIe Bridges originate PCIe hierarchies just
like Root Ports do, so link-&gt;root for these devices should also point to
itself.

Fixes: 51ebfc92b72b ("PCI: Enumerate switches below PCI-to-PCIe bridges")
Link: https://bugzilla.kernel.org/show_bug.cgi?id=193411
Link: https://bugzilla.opensuse.org/show_bug.cgi?id=1022181
Tested-by: lists@ssl-mail.com
Tested-by: Jayachandran C. &lt;jnair@caviumnetworks.com&gt;
Signed-off-by: Bjorn Helgaas &lt;bhelgaas@google.com&gt;
CC: stable@vger.kernel.org	# v4.2+</div><div class='diffstat-header'><a href='/cgit.cgi/linux/net-next.git/diff/?id=030305d69fc6963c16003f50d7e8d74b02d0a143'>Diffstat</a> (limited to 'sound/soc/fsl/p1022_rdk.c')</div><table summary='diffstat' class='diffstat'>