Commit a1cee865 authored by Hante Meuleman's avatar Hante Meuleman Committed by Kalle Valo
Browse files

brcmfmac: SDIO: avoid using bus state for private states.



Each bus driver is maintaing an exported bus state indicating
if upper layers can or cannot send data. SDIO is using this state
also for more private states. This makes handling the states and
state changes complex. This patch minimises the exposed states
and makes SDIO keep track of an internal state where necessary.

Reviewed-by: default avatarArend Van Spriel <arend@broadcom.com>
Reviewed-by: default avatarFranky (Zhenhui) Lin <frankyl@broadcom.com>
Reviewed-by: default avatarPieter-Paul Giesberts <pieterpg@broadcom.com>
Reviewed-by: default avatarDaniel (Deognyoun) Kim <dekim@broadcom.com>
Signed-off-by: default avatarHante Meuleman <meuleman@broadcom.com>
Signed-off-by: default avatarArend van Spriel <arend@broadcom.com>
Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
parent 8982cd40
Loading
Loading
Loading
Loading
+11 −6
Original line number Diff line number Diff line
@@ -269,6 +269,12 @@ static int brcmf_sdiod_request_data(struct brcmf_sdio_dev *sdiodev, u8 fn,
	return ret;
}

static void brcmf_sdiod_nomedium_state(struct brcmf_sdio_dev *sdiodev)
{
	sdiodev->state = BRCMF_STATE_NOMEDIUM;
	brcmf_bus_change_state(sdiodev->bus_if, BRCMF_BUS_DOWN);
}

static int brcmf_sdiod_regrw_helper(struct brcmf_sdio_dev *sdiodev, u32 addr,
				   u8 regsz, void *data, bool write)
{
@@ -276,7 +282,7 @@ static int brcmf_sdiod_regrw_helper(struct brcmf_sdio_dev *sdiodev, u32 addr,
	s32 retry = 0;
	int ret;

	if (sdiodev->bus_if->state == BRCMF_BUS_NOMEDIUM)
	if (sdiodev->state == BRCMF_STATE_NOMEDIUM)
		return -ENOMEDIUM;

	/*
@@ -302,7 +308,7 @@ static int brcmf_sdiod_regrw_helper(struct brcmf_sdio_dev *sdiodev, u32 addr,
		 retry++ < SDIOH_API_ACCESS_RETRY_LIMIT);

	if (ret == -ENOMEDIUM)
		brcmf_bus_change_state(sdiodev->bus_if, BRCMF_BUS_NOMEDIUM);
		brcmf_sdiod_nomedium_state(sdiodev);
	else if (ret != 0) {
		/*
		 * SleepCSR register access can fail when
@@ -325,7 +331,7 @@ brcmf_sdiod_set_sbaddr_window(struct brcmf_sdio_dev *sdiodev, u32 address)
	int err = 0, i;
	u8 addr[3];

	if (sdiodev->bus_if->state == BRCMF_BUS_NOMEDIUM)
	if (sdiodev->state == BRCMF_STATE_NOMEDIUM)
		return -ENOMEDIUM;

	addr[0] = (address >> 8) & SBSDIO_SBADDRLOW_MASK;
@@ -454,7 +460,7 @@ static int brcmf_sdiod_buffrw(struct brcmf_sdio_dev *sdiodev, uint fn,
		err = sdio_readsb(sdiodev->func[fn], ((u8 *)(pkt->data)), addr,
				  req_sz);
	if (err == -ENOMEDIUM)
		brcmf_bus_change_state(sdiodev->bus_if, BRCMF_BUS_NOMEDIUM);
		brcmf_sdiod_nomedium_state(sdiodev);
	return err;
}

@@ -589,8 +595,7 @@ static int brcmf_sdiod_sglist_rw(struct brcmf_sdio_dev *sdiodev, uint fn,

		ret = mmc_cmd.error ? mmc_cmd.error : mmc_dat.error;
		if (ret == -ENOMEDIUM) {
			brcmf_bus_change_state(sdiodev->bus_if,
					       BRCMF_BUS_NOMEDIUM);
			brcmf_sdiod_nomedium_state(sdiodev);
			break;
		} else if (ret != 0) {
			brcmf_err("CMD53 sg block %s failed %d\n",
+1 −13
Original line number Diff line number Diff line
@@ -33,11 +33,8 @@

/* The level of bus communication with the dongle */
enum brcmf_bus_state {
	BRCMF_BUS_UNKNOWN,	/* Not determined yet */
	BRCMF_BUS_NOMEDIUM,	/* No medium access to dongle */
	BRCMF_BUS_DOWN,		/* Not ready for frame transfers */
	BRCMF_BUS_LOAD,		/* Download access only (CPU reset) */
	BRCMF_BUS_DATA		/* Ready for frame transfers */
	BRCMF_BUS_UP		/* Ready for frame transfers */
};

/* The level of bus communication with the dongle */
@@ -188,18 +185,9 @@ void brcmf_bus_wowl_config(struct brcmf_bus *bus, bool enabled)
		bus->ops->wowl_config(bus->dev, enabled);
}

static inline bool brcmf_bus_ready(struct brcmf_bus *bus)
{
	return bus->state == BRCMF_BUS_LOAD || bus->state == BRCMF_BUS_DATA;
}

static inline void brcmf_bus_change_state(struct brcmf_bus *bus,
					  enum brcmf_bus_state new_state)
{
	/* NOMEDIUM is permanent */
	if (bus->state == BRCMF_BUS_NOMEDIUM)
		return;

	brcmf_dbg(TRACE, "%d -> %d\n", bus->state, new_state);
	bus->state = new_state;
}
+3 −3
Original line number Diff line number Diff line
@@ -197,7 +197,7 @@ static netdev_tx_t brcmf_netdev_start_xmit(struct sk_buff *skb,
	brcmf_dbg(DATA, "Enter, idx=%d\n", ifp->bssidx);

	/* Can the device send data? */
	if (drvr->bus_if->state != BRCMF_BUS_DATA) {
	if (drvr->bus_if->state != BRCMF_BUS_UP) {
		brcmf_err("xmit rejected state=%d\n", drvr->bus_if->state);
		netif_stop_queue(ndev);
		dev_kfree_skb(skb);
@@ -637,7 +637,7 @@ static int brcmf_netdev_open(struct net_device *ndev)
	brcmf_dbg(TRACE, "Enter, idx=%d\n", ifp->bssidx);

	/* If bus is not ready, can't continue */
	if (bus_if->state != BRCMF_BUS_DATA) {
	if (bus_if->state != BRCMF_BUS_UP) {
		brcmf_err("failed bus is not ready\n");
		return -EAGAIN;
	}
@@ -964,7 +964,7 @@ int brcmf_bus_start(struct device *dev)
		p2p_ifp = NULL;

	/* signal bus ready */
	brcmf_bus_change_state(bus_if, BRCMF_BUS_DATA);
	brcmf_bus_change_state(bus_if, BRCMF_BUS_UP);

	/* Bus is ready, do any initialization */
	ret = brcmf_c_preinit_dcmds(ifp);
+1 −1
Original line number Diff line number Diff line
@@ -109,7 +109,7 @@ brcmf_fil_cmd_data(struct brcmf_if *ifp, u32 cmd, void *data, u32 len, bool set)
	struct brcmf_pub *drvr = ifp->drvr;
	s32 err;

	if (drvr->bus_if->state != BRCMF_BUS_DATA) {
	if (drvr->bus_if->state != BRCMF_BUS_UP) {
		brcmf_err("bus is down. we have nothing to do.\n");
		return -EIO;
	}
+1 −1
Original line number Diff line number Diff line
@@ -1828,7 +1828,7 @@ static int brcmf_pcie_resume(struct pci_dev *pdev)
				goto cleanup;
			brcmf_dbg(PCIE, "Hot resume, continue....\n");
			brcmf_pcie_select_core(devinfo, BCMA_CORE_PCIE2);
			brcmf_bus_change_state(bus, BRCMF_BUS_DATA);
			brcmf_bus_change_state(bus, BRCMF_BUS_UP);
			brcmf_pcie_intr_enable(devinfo);
			return 0;
		}
Loading