cxgb4: Replaced the backdoor mechanism to access the HW memory with PCIe Window method
[sfrench/cifs-2.6.git] / drivers / net / ethernet / chelsio / cxgb4 / cxgb4_main.c
index 524a8b2894e7430677911cff50a64511b7a6b864..74ef0e69cdc45f24a946be08d4922ed65e9c0d1b 100644 (file)
@@ -3066,6 +3066,8 @@ static ssize_t mem_read(struct file *file, char __user *buf, size_t count,
        loff_t avail = file_inode(file)->i_size;
        unsigned int mem = (uintptr_t)file->private_data & 3;
        struct adapter *adap = file->private_data - mem;
+       __be32 *data;
+       int ret;
 
        if (pos < 0)
                return -EINVAL;
@@ -3074,29 +3076,24 @@ static ssize_t mem_read(struct file *file, char __user *buf, size_t count,
        if (count > avail - pos)
                count = avail - pos;
 
-       while (count) {
-               size_t len;
-               int ret, ofst;
-               __be32 data[16];
+       data = t4_alloc_mem(count);
+       if (!data)
+               return -ENOMEM;
 
-               if ((mem == MEM_MC) || (mem == MEM_MC1))
-                       ret = t4_mc_read(adap, mem % MEM_MC, pos, data, NULL);
-               else
-                       ret = t4_edc_read(adap, mem, pos, data, NULL);
-               if (ret)
-                       return ret;
+       spin_lock(&adap->win0_lock);
+       ret = t4_memory_rw(adap, 0, mem, pos, count, data, T4_MEMORY_READ);
+       spin_unlock(&adap->win0_lock);
+       if (ret) {
+               t4_free_mem(data);
+               return ret;
+       }
+       ret = copy_to_user(buf, data, count);
 
-               ofst = pos % sizeof(data);
-               len = min(count, sizeof(data) - ofst);
-               if (copy_to_user(buf, (u8 *)data + ofst, len))
-                       return -EFAULT;
+       t4_free_mem(data);
+       if (ret)
+               return -EFAULT;
 
-               buf += len;
-               pos += len;
-               count -= len;
-       }
-       count = pos - *ppos;
-       *ppos = pos;
+       *ppos = pos + count;
        return count;
 }
 
@@ -3757,7 +3754,11 @@ static int read_eq_indices(struct adapter *adap, u16 qid, u16 *pidx, u16 *cidx)
        __be64 indices;
        int ret;
 
-       ret = t4_mem_win_read_len(adap, addr, (__be32 *)&indices, 8);
+       spin_lock(&adap->win0_lock);
+       ret = t4_memory_rw(adap, 0, MEM_EDC0, addr,
+                          sizeof(indices), (__be32 *)&indices,
+                          T4_MEMORY_READ);
+       spin_unlock(&adap->win0_lock);
        if (!ret) {
                *cidx = (be64_to_cpu(indices) >> 25) & 0xffff;
                *pidx = (be64_to_cpu(indices) >> 9) & 0xffff;
@@ -5076,7 +5077,7 @@ static int adap_init0_config(struct adapter *adapter, int reset)
                                              adapter->fn, 0, 1, params, val);
                        if (ret == 0) {
                                /*
-                                * For t4_memory_write() below addresses and
+                                * For t4_memory_rw() below addresses and
                                 * sizes have to be in terms of multiples of 4
                                 * bytes.  So, if the Configuration File isn't
                                 * a multiple of 4 bytes in length we'll have
@@ -5092,8 +5093,9 @@ static int adap_init0_config(struct adapter *adapter, int reset)
                                mtype = FW_PARAMS_PARAM_Y_GET(val[0]);
                                maddr = FW_PARAMS_PARAM_Z_GET(val[0]) << 16;
 
-                               ret = t4_memory_write(adapter, mtype, maddr,
-                                                     size, data);
+                               spin_lock(&adapter->win0_lock);
+                               ret = t4_memory_rw(adapter, 0, mtype, maddr,
+                                                  size, data, T4_MEMORY_WRITE);
                                if (ret == 0 && resid != 0) {
                                        union {
                                                __be32 word;
@@ -5104,10 +5106,12 @@ static int adap_init0_config(struct adapter *adapter, int reset)
                                        last.word = data[size >> 2];
                                        for (i = resid; i < 4; i++)
                                                last.buf[i] = 0;
-                                       ret = t4_memory_write(adapter, mtype,
-                                                             maddr + size,
-                                                             4, &last.word);
+                                       ret = t4_memory_rw(adapter, 0, mtype,
+                                                          maddr + size,
+                                                          4, &last.word,
+                                                          T4_MEMORY_WRITE);
                                }
+                               spin_unlock(&adapter->win0_lock);
                        }
                }