ath10k: add some flags to make memory allocations try harder.

GFP_DMA should have a qualifier of either GFP_KERNEL or GFP_ATOMIC.  With
neither, it neither waits nor has access to emergency memory, which means
maximizing its chance of disaster.

When allocating large memory areas, it can help to use __GFP_REPEAT, which
tries to free pages a few extra times.

And, because the current ath10k driver seems to be a little finicky about
memory allocation problems, let's just add __GFP_HIGH (to allow access to
the emergency pool) for all its allocations for now.  It's probably best to
remove that eventually, but should be okay in the short term since we're
also expanding the size of our emergency pool (in a separate patch).

Change-Id: If1484fb71b20c21aab2926f88edcd2280b1bb85b
diff --git a/drivers/net/wireless/ath/ath10k/ce.c b/drivers/net/wireless/ath/ath10k/ce.c
index 1e4cad8..6663c97 100644
--- a/drivers/net/wireless/ath/ath10k/ce.c
+++ b/drivers/net/wireless/ath/ath10k/ce.c
@@ -922,7 +922,7 @@
 	src_ring = kzalloc(sizeof(*src_ring) +
 			   (nentries *
 			    sizeof(*src_ring->per_transfer_context)),
-			   GFP_KERNEL);
+			   GFP_KERNEL|__GFP_REPEAT|__GFP_HIGH);
 	if (src_ring == NULL)
 		return ERR_PTR(-ENOMEM);
 
@@ -937,7 +937,7 @@
 		dma_alloc_coherent(ar->dev,
 				   (nentries * sizeof(struct ce_desc) +
 				    CE_DESC_RING_ALIGN),
-				   &base_addr, GFP_KERNEL);
+				   &base_addr, GFP_KERNEL|__GFP_REPEAT|__GFP_HIGH);
 	if (!src_ring->base_addr_owner_space_unaligned) {
 		kfree(src_ring);
 		return ERR_PTR(-ENOMEM);
@@ -958,7 +958,7 @@
 	 */
 	src_ring->shadow_base_unaligned =
 		kmalloc((nentries * sizeof(struct ce_desc) +
-			 CE_DESC_RING_ALIGN), GFP_KERNEL);
+			 CE_DESC_RING_ALIGN), GFP_KERNEL|__GFP_REPEAT|__GFP_HIGH);
 	if (!src_ring->shadow_base_unaligned) {
 		dma_free_coherent(ar->dev,
 				  (nentries * sizeof(struct ce_desc) +
@@ -989,7 +989,7 @@
 	dest_ring = kzalloc(sizeof(*dest_ring) +
 			    (nentries *
 			     sizeof(*dest_ring->per_transfer_context)),
-			    GFP_KERNEL);
+			    GFP_KERNEL|__GFP_REPEAT|__GFP_HIGH);
 	if (dest_ring == NULL)
 		return ERR_PTR(-ENOMEM);
 
@@ -1004,7 +1004,7 @@
 		dma_alloc_coherent(ar->dev,
 				   (nentries * sizeof(struct ce_desc) +
 				    CE_DESC_RING_ALIGN),
-				   &base_addr, GFP_KERNEL);
+				   &base_addr, GFP_KERNEL|__GFP_REPEAT|__GFP_HIGH);
 	if (!dest_ring->base_addr_owner_space_unaligned) {
 		kfree(dest_ring);
 		return ERR_PTR(-ENOMEM);
diff --git a/drivers/net/wireless/ath/ath10k/debug.c b/drivers/net/wireless/ath/ath10k/debug.c
index 0386550..a490ada 100644
--- a/drivers/net/wireless/ath/ath10k/debug.c
+++ b/drivers/net/wireless/ath/ath10k/debug.c
@@ -120,7 +120,7 @@
 	ssize_t ret_cnt;
 	int i;
 
-	buf = kzalloc(buf_len, GFP_KERNEL);
+	buf = kzalloc(buf_len, GFP_KERNEL|__GFP_REPEAT|__GFP_HIGH);
 	if (!buf)
 		return -ENOMEM;
 
@@ -303,7 +303,7 @@
 	if (ar->state != ATH10K_STATE_ON)
 		goto exit;
 
-	buf = kzalloc(buf_len, GFP_KERNEL);
+	buf = kzalloc(buf_len, GFP_KERNEL|__GFP_REPEAT|__GFP_HIGH);
 	if (!buf)
 		goto exit;
 
@@ -793,7 +793,7 @@
 	struct ath10k *ar = file->private_data;
 	char *buf;
 
-	buf = kzalloc(size, GFP_KERNEL);
+	buf = kzalloc(size, GFP_KERNEL|__GFP_REPEAT|__GFP_HIGH);
 	if (buf == NULL)
 		return -ENOMEM;
 
diff --git a/drivers/net/wireless/ath/ath10k/htt_rx.c b/drivers/net/wireless/ath/ath10k/htt_rx.c
index f85a3cf..35f7e64 100644
--- a/drivers/net/wireless/ath/ath10k/htt_rx.c
+++ b/drivers/net/wireless/ath/ath10k/htt_rx.c
@@ -495,13 +495,13 @@
 
 	htt->rx_ring.netbufs_ring =
 		kmalloc(htt->rx_ring.size * sizeof(struct sk_buff *),
-			GFP_KERNEL);
+			GFP_KERNEL|__GFP_REPEAT|__GFP_HIGH);
 	if (!htt->rx_ring.netbufs_ring)
 		goto err_netbuf;
 
 	vaddr = dma_alloc_coherent(htt->ar->dev,
 		   (htt->rx_ring.size * sizeof(htt->rx_ring.paddrs_ring)),
-		   &paddr, GFP_DMA);
+		   &paddr, GFP_KERNEL|__GFP_REPEAT|__GFP_HIGH|GFP_DMA);
 	if (!vaddr)
 		goto err_dma_ring;
 
@@ -510,7 +510,7 @@
 
 	vaddr = dma_alloc_coherent(htt->ar->dev,
 				   sizeof(*htt->rx_ring.alloc_idx.vaddr),
-				   &paddr, GFP_DMA);
+				   &paddr, GFP_KERNEL|__GFP_REPEAT|__GFP_HIGH|GFP_DMA);
 	if (!vaddr)
 		goto err_dma_idx;
 
diff --git a/drivers/net/wireless/ath/ath10k/htt_tx.c b/drivers/net/wireless/ath/ath10k/htt_tx.c
index 7a3e2e4..c053400 100644
--- a/drivers/net/wireless/ath/ath10k/htt_tx.c
+++ b/drivers/net/wireless/ath/ath10k/htt_tx.c
@@ -97,13 +97,13 @@
 		   htt->max_num_pending_tx);
 
 	htt->pending_tx = kzalloc(sizeof(*htt->pending_tx) *
-				  htt->max_num_pending_tx, GFP_KERNEL);
+				  htt->max_num_pending_tx, GFP_KERNEL|__GFP_REPEAT|__GFP_HIGH);
 	if (!htt->pending_tx)
 		return -ENOMEM;
 
 	htt->used_msdu_ids = kzalloc(sizeof(unsigned long) *
 				     BITS_TO_LONGS(htt->max_num_pending_tx),
-				     GFP_KERNEL);
+				     GFP_KERNEL|__GFP_REPEAT|__GFP_HIGH);
 	if (!htt->used_msdu_ids) {
 		kfree(htt->pending_tx);
 		return -ENOMEM;
diff --git a/drivers/net/wireless/ath/ath10k/mac.c b/drivers/net/wireless/ath/ath10k/mac.c
index 5307dee..ecd191b 100644
--- a/drivers/net/wireless/ath/ath10k/mac.c
+++ b/drivers/net/wireless/ath/ath10k/mac.c
@@ -1689,7 +1689,7 @@
 	}
 
 	len = sizeof(struct wmi_channel_arg) * arg.n_channels;
-	arg.channels = kzalloc(len, GFP_KERNEL);
+	arg.channels = kzalloc(len, GFP_KERNEL|__GFP_REPEAT|__GFP_HIGH);
 	if (!arg.channels)
 		return -ENOMEM;
 
@@ -4559,7 +4559,7 @@
 	if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
 		channels = kmemdup(ath10k_2ghz_channels,
 				   sizeof(ath10k_2ghz_channels),
-				   GFP_KERNEL);
+				   GFP_KERNEL|__GFP_REPEAT|__GFP_HIGH);
 		if (!channels) {
 			ret = -ENOMEM;
 			goto err_free;
@@ -4580,7 +4580,7 @@
 	if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
 		channels = kmemdup(ath10k_5ghz_channels,
 				   sizeof(ath10k_5ghz_channels),
-				   GFP_KERNEL);
+				   GFP_KERNEL|__GFP_REPEAT|__GFP_HIGH);
 		if (!channels) {
 			ret = -ENOMEM;
 			goto err_free;
diff --git a/drivers/net/wireless/ath/ath10k/pci.c b/drivers/net/wireless/ath/ath10k/pci.c
index 66b1f30..427d861 100644
--- a/drivers/net/wireless/ath/ath10k/pci.c
+++ b/drivers/net/wireless/ath/ath10k/pci.c
@@ -1321,7 +1321,7 @@
 	if (resp && resp_len && *resp_len == 0)
 		return -EINVAL;
 
-	treq = kmemdup(req, req_len, GFP_KERNEL);
+	treq = kmemdup(req, req_len, GFP_KERNEL|__GFP_REPEAT|__GFP_HIGH);
 	if (!treq)
 		return -ENOMEM;
 
@@ -1331,7 +1331,7 @@
 		goto err_dma;
 
 	if (resp && resp_len) {
-		tresp = kzalloc(*resp_len, GFP_KERNEL);
+		tresp = kzalloc(*resp_len, GFP_KERNEL|__GFP_REPEAT|__GFP_HIGH);
 		if (!tresp) {
 			ret = -ENOMEM;
 			goto err_req;
@@ -2568,7 +2568,7 @@
 
 	ath10k_dbg(ATH10K_DBG_PCI, "pci probe\n");
 
-	ar_pci = kzalloc(sizeof(*ar_pci), GFP_KERNEL);
+	ar_pci = kzalloc(sizeof(*ar_pci), GFP_KERNEL|__GFP_REPEAT|__GFP_HIGH);
 	if (ar_pci == NULL)
 		return -ENOMEM;