aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/arcmsr
diff options
context:
space:
mode:
authorChing Huang <ching2048@areca.com.tw>2014-09-24 05:33:34 -0400
committerChristoph Hellwig <hch@lst.de>2014-09-25 08:23:40 -0400
commit2e9feb434a66311f30bde2430a5609e9e24df62b (patch)
treeaf99c6abe8867be11aadb8c62b42b5fce450b568 /drivers/scsi/arcmsr
parent3185ea63907cb281cfdc5aa29aa2d855826ad16a (diff)
arcmsr: simplify ioctl data read/write
Signed-off-by: Ching Huang <ching 2048@areca.com.tw> Reviewed-by: Tomas Henzl <thenzl@redhat.com> Signed-off-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'drivers/scsi/arcmsr')
-rw-r--r--drivers/scsi/arcmsr/arcmsr.h13
-rw-r--r--drivers/scsi/arcmsr/arcmsr_attr.c127
-rw-r--r--drivers/scsi/arcmsr/arcmsr_hba.c208
3 files changed, 119 insertions, 229 deletions
diff --git a/drivers/scsi/arcmsr/arcmsr.h b/drivers/scsi/arcmsr/arcmsr.h
index d1c78efc202e..3bcaaac0ae4b 100644
--- a/drivers/scsi/arcmsr/arcmsr.h
+++ b/drivers/scsi/arcmsr/arcmsr.h
@@ -52,7 +52,7 @@ struct device_attribute;
52 #define ARCMSR_MAX_FREECCB_NUM 320 52 #define ARCMSR_MAX_FREECCB_NUM 320
53#define ARCMSR_MAX_OUTSTANDING_CMD 255 53#define ARCMSR_MAX_OUTSTANDING_CMD 255
54#endif 54#endif
55#define ARCMSR_DRIVER_VERSION "v1.30.00.04-20140428" 55#define ARCMSR_DRIVER_VERSION "v1.30.00.04-20140919"
56#define ARCMSR_SCSI_INITIATOR_ID 255 56#define ARCMSR_SCSI_INITIATOR_ID 255
57#define ARCMSR_MAX_XFER_SECTORS 512 57#define ARCMSR_MAX_XFER_SECTORS 512
58#define ARCMSR_MAX_XFER_SECTORS_B 4096 58#define ARCMSR_MAX_XFER_SECTORS_B 4096
@@ -107,10 +107,11 @@ struct CMD_MESSAGE
107** IOP Message Transfer Data for user space 107** IOP Message Transfer Data for user space
108******************************************************************************* 108*******************************************************************************
109*/ 109*/
110#define ARCMSR_API_DATA_BUFLEN 1032
110struct CMD_MESSAGE_FIELD 111struct CMD_MESSAGE_FIELD
111{ 112{
112 struct CMD_MESSAGE cmdmessage; 113 struct CMD_MESSAGE cmdmessage;
113 uint8_t messagedatabuffer[1032]; 114 uint8_t messagedatabuffer[ARCMSR_API_DATA_BUFLEN];
114}; 115};
115/* IOP message transfer */ 116/* IOP message transfer */
116#define ARCMSR_MESSAGE_FAIL 0x0001 117#define ARCMSR_MESSAGE_FAIL 0x0001
@@ -678,15 +679,15 @@ struct AdapterControlBlock
678 unsigned int uncache_size; 679 unsigned int uncache_size;
679 uint8_t rqbuffer[ARCMSR_MAX_QBUFFER]; 680 uint8_t rqbuffer[ARCMSR_MAX_QBUFFER];
680 /* data collection buffer for read from 80331 */ 681 /* data collection buffer for read from 80331 */
681 int32_t rqbuf_firstindex; 682 int32_t rqbuf_getIndex;
682 /* first of read buffer */ 683 /* first of read buffer */
683 int32_t rqbuf_lastindex; 684 int32_t rqbuf_putIndex;
684 /* last of read buffer */ 685 /* last of read buffer */
685 uint8_t wqbuffer[ARCMSR_MAX_QBUFFER]; 686 uint8_t wqbuffer[ARCMSR_MAX_QBUFFER];
686 /* data collection buffer for write to 80331 */ 687 /* data collection buffer for write to 80331 */
687 int32_t wqbuf_firstindex; 688 int32_t wqbuf_getIndex;
688 /* first of write buffer */ 689 /* first of write buffer */
689 int32_t wqbuf_lastindex; 690 int32_t wqbuf_putIndex;
690 /* last of write buffer */ 691 /* last of write buffer */
691 uint8_t devstate[ARCMSR_MAX_TARGETID][ARCMSR_MAX_TARGETLUN]; 692 uint8_t devstate[ARCMSR_MAX_TARGETID][ARCMSR_MAX_TARGETLUN];
692 /* id0 ..... id15, lun0...lun7 */ 693 /* id0 ..... id15, lun0...lun7 */
diff --git a/drivers/scsi/arcmsr/arcmsr_attr.c b/drivers/scsi/arcmsr/arcmsr_attr.c
index 16422adcc531..9c86481f779f 100644
--- a/drivers/scsi/arcmsr/arcmsr_attr.c
+++ b/drivers/scsi/arcmsr/arcmsr_attr.c
@@ -50,6 +50,7 @@
50#include <linux/errno.h> 50#include <linux/errno.h>
51#include <linux/delay.h> 51#include <linux/delay.h>
52#include <linux/pci.h> 52#include <linux/pci.h>
53#include <linux/circ_buf.h>
53 54
54#include <scsi/scsi_cmnd.h> 55#include <scsi/scsi_cmnd.h>
55#include <scsi/scsi_device.h> 56#include <scsi/scsi_device.h>
@@ -68,7 +69,7 @@ static ssize_t arcmsr_sysfs_iop_message_read(struct file *filp,
68 struct device *dev = container_of(kobj,struct device,kobj); 69 struct device *dev = container_of(kobj,struct device,kobj);
69 struct Scsi_Host *host = class_to_shost(dev); 70 struct Scsi_Host *host = class_to_shost(dev);
70 struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; 71 struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata;
71 uint8_t *pQbuffer,*ptmpQbuffer; 72 uint8_t *ptmpQbuffer;
72 int32_t allxfer_len = 0; 73 int32_t allxfer_len = 0;
73 unsigned long flags; 74 unsigned long flags;
74 75
@@ -78,57 +79,22 @@ static ssize_t arcmsr_sysfs_iop_message_read(struct file *filp,
78 /* do message unit read. */ 79 /* do message unit read. */
79 ptmpQbuffer = (uint8_t *)buf; 80 ptmpQbuffer = (uint8_t *)buf;
80 spin_lock_irqsave(&acb->rqbuffer_lock, flags); 81 spin_lock_irqsave(&acb->rqbuffer_lock, flags);
81 if (acb->rqbuf_firstindex != acb->rqbuf_lastindex) { 82 if (acb->rqbuf_getIndex != acb->rqbuf_putIndex) {
82 pQbuffer = &acb->rqbuffer[acb->rqbuf_firstindex]; 83 unsigned int tail = acb->rqbuf_getIndex;
83 if (acb->rqbuf_firstindex > acb->rqbuf_lastindex) { 84 unsigned int head = acb->rqbuf_putIndex;
84 if ((ARCMSR_MAX_QBUFFER - acb->rqbuf_firstindex) >= 1032) { 85 unsigned int cnt_to_end = CIRC_CNT_TO_END(head, tail, ARCMSR_MAX_QBUFFER);
85 memcpy(ptmpQbuffer, pQbuffer, 1032); 86
86 acb->rqbuf_firstindex += 1032; 87 allxfer_len = CIRC_CNT(head, tail, ARCMSR_MAX_QBUFFER);
87 acb->rqbuf_firstindex %= ARCMSR_MAX_QBUFFER; 88 if (allxfer_len > ARCMSR_API_DATA_BUFLEN)
88 allxfer_len = 1032; 89 allxfer_len = ARCMSR_API_DATA_BUFLEN;
89 } else { 90
90 if (((ARCMSR_MAX_QBUFFER - acb->rqbuf_firstindex) 91 if (allxfer_len <= cnt_to_end)
91 + acb->rqbuf_lastindex) > 1032) { 92 memcpy(ptmpQbuffer, acb->rqbuffer + tail, allxfer_len);
92 memcpy(ptmpQbuffer, pQbuffer, 93 else {
93 ARCMSR_MAX_QBUFFER 94 memcpy(ptmpQbuffer, acb->rqbuffer + tail, cnt_to_end);
94 - acb->rqbuf_firstindex); 95 memcpy(ptmpQbuffer + cnt_to_end, acb->rqbuffer, allxfer_len - cnt_to_end);
95 ptmpQbuffer += ARCMSR_MAX_QBUFFER
96 - acb->rqbuf_firstindex;
97 memcpy(ptmpQbuffer, acb->rqbuffer, 1032
98 - (ARCMSR_MAX_QBUFFER -
99 acb->rqbuf_firstindex));
100 acb->rqbuf_firstindex = 1032 -
101 (ARCMSR_MAX_QBUFFER -
102 acb->rqbuf_firstindex);
103 allxfer_len = 1032;
104 } else {
105 memcpy(ptmpQbuffer, pQbuffer,
106 ARCMSR_MAX_QBUFFER -
107 acb->rqbuf_firstindex);
108 ptmpQbuffer += ARCMSR_MAX_QBUFFER -
109 acb->rqbuf_firstindex;
110 memcpy(ptmpQbuffer, acb->rqbuffer,
111 acb->rqbuf_lastindex);
112 allxfer_len = ARCMSR_MAX_QBUFFER -
113 acb->rqbuf_firstindex +
114 acb->rqbuf_lastindex;
115 acb->rqbuf_firstindex =
116 acb->rqbuf_lastindex;
117 }
118 }
119 } else {
120 if ((acb->rqbuf_lastindex - acb->rqbuf_firstindex) > 1032) {
121 memcpy(ptmpQbuffer, pQbuffer, 1032);
122 acb->rqbuf_firstindex += 1032;
123 allxfer_len = 1032;
124 } else {
125 memcpy(ptmpQbuffer, pQbuffer, acb->rqbuf_lastindex
126 - acb->rqbuf_firstindex);
127 allxfer_len = acb->rqbuf_lastindex -
128 acb->rqbuf_firstindex;
129 acb->rqbuf_firstindex = acb->rqbuf_lastindex;
130 }
131 } 96 }
97 acb->rqbuf_getIndex = (acb->rqbuf_getIndex + allxfer_len) % ARCMSR_MAX_QBUFFER;
132 } 98 }
133 if (acb->acb_flags & ACB_F_IOPDATA_OVERFLOW) { 99 if (acb->acb_flags & ACB_F_IOPDATA_OVERFLOW) {
134 struct QBUFFER __iomem *prbuffer; 100 struct QBUFFER __iomem *prbuffer;
@@ -150,47 +116,42 @@ static ssize_t arcmsr_sysfs_iop_message_write(struct file *filp,
150 struct device *dev = container_of(kobj,struct device,kobj); 116 struct device *dev = container_of(kobj,struct device,kobj);
151 struct Scsi_Host *host = class_to_shost(dev); 117 struct Scsi_Host *host = class_to_shost(dev);
152 struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; 118 struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata;
153 int32_t my_empty_len, user_len, wqbuf_firstindex, wqbuf_lastindex; 119 int32_t user_len, cnt2end;
154 uint8_t *pQbuffer, *ptmpuserbuffer; 120 uint8_t *pQbuffer, *ptmpuserbuffer;
155 unsigned long flags; 121 unsigned long flags;
156 122
157 if (!capable(CAP_SYS_ADMIN)) 123 if (!capable(CAP_SYS_ADMIN))
158 return -EACCES; 124 return -EACCES;
159 if (count > 1032) 125 if (count > ARCMSR_API_DATA_BUFLEN)
160 return -EINVAL; 126 return -EINVAL;
161 /* do message unit write. */ 127 /* do message unit write. */
162 ptmpuserbuffer = (uint8_t *)buf; 128 ptmpuserbuffer = (uint8_t *)buf;
163 user_len = (int32_t)count; 129 user_len = (int32_t)count;
164 spin_lock_irqsave(&acb->wqbuffer_lock, flags); 130 spin_lock_irqsave(&acb->wqbuffer_lock, flags);
165 wqbuf_lastindex = acb->wqbuf_lastindex; 131 if (acb->wqbuf_putIndex != acb->wqbuf_getIndex) {
166 wqbuf_firstindex = acb->wqbuf_firstindex;
167 if (wqbuf_lastindex != wqbuf_firstindex) {
168 arcmsr_write_ioctldata2iop(acb); 132 arcmsr_write_ioctldata2iop(acb);
169 spin_unlock_irqrestore(&acb->wqbuffer_lock, flags); 133 spin_unlock_irqrestore(&acb->wqbuffer_lock, flags);
170 return 0; /*need retry*/ 134 return 0; /*need retry*/
171 } else { 135 } else {
172 my_empty_len = (wqbuf_firstindex-wqbuf_lastindex - 1) 136 pQbuffer = &acb->wqbuffer[acb->wqbuf_putIndex];
173 &(ARCMSR_MAX_QBUFFER - 1); 137 cnt2end = ARCMSR_MAX_QBUFFER - acb->wqbuf_putIndex;
174 if (my_empty_len >= user_len) { 138 if (user_len > cnt2end) {
175 while (user_len > 0) { 139 memcpy(pQbuffer, ptmpuserbuffer, cnt2end);
176 pQbuffer = &acb->wqbuffer[acb->wqbuf_lastindex]; 140 ptmpuserbuffer += cnt2end;
177 memcpy(pQbuffer, ptmpuserbuffer, 1); 141 user_len -= cnt2end;
178 acb->wqbuf_lastindex++; 142 acb->wqbuf_putIndex = 0;
179 acb->wqbuf_lastindex %= ARCMSR_MAX_QBUFFER; 143 pQbuffer = acb->wqbuffer;
180 ptmpuserbuffer++;
181 user_len--;
182 }
183 if (acb->acb_flags & ACB_F_MESSAGE_WQBUFFER_CLEARED) {
184 acb->acb_flags &=
185 ~ACB_F_MESSAGE_WQBUFFER_CLEARED;
186 arcmsr_write_ioctldata2iop(acb);
187 }
188 spin_unlock_irqrestore(&acb->wqbuffer_lock, flags);
189 return count;
190 } else {
191 spin_unlock_irqrestore(&acb->wqbuffer_lock, flags);
192 return 0; /*need retry*/
193 } 144 }
145 memcpy(pQbuffer, ptmpuserbuffer, user_len);
146 acb->wqbuf_putIndex += user_len;
147 acb->wqbuf_putIndex %= ARCMSR_MAX_QBUFFER;
148 if (acb->acb_flags & ACB_F_MESSAGE_WQBUFFER_CLEARED) {
149 acb->acb_flags &=
150 ~ACB_F_MESSAGE_WQBUFFER_CLEARED;
151 arcmsr_write_ioctldata2iop(acb);
152 }
153 spin_unlock_irqrestore(&acb->wqbuffer_lock, flags);
154 return count;
194 } 155 }
195} 156}
196 157
@@ -215,12 +176,12 @@ static ssize_t arcmsr_sysfs_iop_message_clear(struct file *filp,
215 | ACB_F_MESSAGE_RQBUFFER_CLEARED 176 | ACB_F_MESSAGE_RQBUFFER_CLEARED
216 | ACB_F_MESSAGE_WQBUFFER_READED); 177 | ACB_F_MESSAGE_WQBUFFER_READED);
217 spin_lock_irqsave(&acb->rqbuffer_lock, flags); 178 spin_lock_irqsave(&acb->rqbuffer_lock, flags);
218 acb->rqbuf_firstindex = 0; 179 acb->rqbuf_getIndex = 0;
219 acb->rqbuf_lastindex = 0; 180 acb->rqbuf_putIndex = 0;
220 spin_unlock_irqrestore(&acb->rqbuffer_lock, flags); 181 spin_unlock_irqrestore(&acb->rqbuffer_lock, flags);
221 spin_lock_irqsave(&acb->wqbuffer_lock, flags); 182 spin_lock_irqsave(&acb->wqbuffer_lock, flags);
222 acb->wqbuf_firstindex = 0; 183 acb->wqbuf_getIndex = 0;
223 acb->wqbuf_lastindex = 0; 184 acb->wqbuf_putIndex = 0;
224 spin_unlock_irqrestore(&acb->wqbuffer_lock, flags); 185 spin_unlock_irqrestore(&acb->wqbuffer_lock, flags);
225 pQbuffer = acb->rqbuffer; 186 pQbuffer = acb->rqbuffer;
226 memset(pQbuffer, 0, sizeof (struct QBUFFER)); 187 memset(pQbuffer, 0, sizeof (struct QBUFFER));
@@ -234,7 +195,7 @@ static struct bin_attribute arcmsr_sysfs_message_read_attr = {
234 .name = "mu_read", 195 .name = "mu_read",
235 .mode = S_IRUSR , 196 .mode = S_IRUSR ,
236 }, 197 },
237 .size = 1032, 198 .size = ARCMSR_API_DATA_BUFLEN,
238 .read = arcmsr_sysfs_iop_message_read, 199 .read = arcmsr_sysfs_iop_message_read,
239}; 200};
240 201
@@ -243,7 +204,7 @@ static struct bin_attribute arcmsr_sysfs_message_write_attr = {
243 .name = "mu_write", 204 .name = "mu_write",
244 .mode = S_IWUSR, 205 .mode = S_IWUSR,
245 }, 206 },
246 .size = 1032, 207 .size = ARCMSR_API_DATA_BUFLEN,
247 .write = arcmsr_sysfs_iop_message_write, 208 .write = arcmsr_sysfs_iop_message_write,
248}; 209};
249 210
diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c
index 0dd38ccc9470..0b44fb5ee485 100644
--- a/drivers/scsi/arcmsr/arcmsr_hba.c
+++ b/drivers/scsi/arcmsr/arcmsr_hba.c
@@ -58,6 +58,7 @@
58#include <linux/slab.h> 58#include <linux/slab.h>
59#include <linux/pci.h> 59#include <linux/pci.h>
60#include <linux/aer.h> 60#include <linux/aer.h>
61#include <linux/circ_buf.h>
61#include <asm/dma.h> 62#include <asm/dma.h>
62#include <asm/io.h> 63#include <asm/io.h>
63#include <asm/uaccess.h> 64#include <asm/uaccess.h>
@@ -1701,16 +1702,15 @@ arcmsr_Read_iop_rqbuffer_in_DWORD(struct AdapterControlBlock *acb,
1701 buf2 = (uint32_t *)buf1; 1702 buf2 = (uint32_t *)buf1;
1702 } 1703 }
1703 while (iop_len > 0) { 1704 while (iop_len > 0) {
1704 pQbuffer = &acb->rqbuffer[acb->rqbuf_lastindex]; 1705 pQbuffer = &acb->rqbuffer[acb->rqbuf_putIndex];
1705 *pQbuffer = *buf1; 1706 *pQbuffer = *buf1;
1706 acb->rqbuf_lastindex++; 1707 acb->rqbuf_putIndex++;
1707 /* if last, index number set it to 0 */ 1708 /* if last, index number set it to 0 */
1708 acb->rqbuf_lastindex %= ARCMSR_MAX_QBUFFER; 1709 acb->rqbuf_putIndex %= ARCMSR_MAX_QBUFFER;
1709 buf1++; 1710 buf1++;
1710 iop_len--; 1711 iop_len--;
1711 } 1712 }
1712 if (buf2) 1713 kfree(buf2);
1713 kfree(buf2);
1714 /* let IOP know data has been read */ 1714 /* let IOP know data has been read */
1715 arcmsr_iop_message_read(acb); 1715 arcmsr_iop_message_read(acb);
1716 return 1; 1716 return 1;
@@ -1729,10 +1729,10 @@ arcmsr_Read_iop_rqbuffer_data(struct AdapterControlBlock *acb,
1729 iop_data = (uint8_t __iomem *)prbuffer->data; 1729 iop_data = (uint8_t __iomem *)prbuffer->data;
1730 iop_len = readl(&prbuffer->data_len); 1730 iop_len = readl(&prbuffer->data_len);
1731 while (iop_len > 0) { 1731 while (iop_len > 0) {
1732 pQbuffer = &acb->rqbuffer[acb->rqbuf_lastindex]; 1732 pQbuffer = &acb->rqbuffer[acb->rqbuf_putIndex];
1733 *pQbuffer = readb(iop_data); 1733 *pQbuffer = readb(iop_data);
1734 acb->rqbuf_lastindex++; 1734 acb->rqbuf_putIndex++;
1735 acb->rqbuf_lastindex %= ARCMSR_MAX_QBUFFER; 1735 acb->rqbuf_putIndex %= ARCMSR_MAX_QBUFFER;
1736 iop_data++; 1736 iop_data++;
1737 iop_len--; 1737 iop_len--;
1738 } 1738 }
@@ -1748,7 +1748,7 @@ static void arcmsr_iop2drv_data_wrote_handle(struct AdapterControlBlock *acb)
1748 1748
1749 spin_lock_irqsave(&acb->rqbuffer_lock, flags); 1749 spin_lock_irqsave(&acb->rqbuffer_lock, flags);
1750 prbuffer = arcmsr_get_iop_rqbuffer(acb); 1750 prbuffer = arcmsr_get_iop_rqbuffer(acb);
1751 buf_empty_len = (acb->rqbuf_lastindex - acb->rqbuf_firstindex - 1) & 1751 buf_empty_len = (acb->rqbuf_putIndex - acb->rqbuf_getIndex - 1) &
1752 (ARCMSR_MAX_QBUFFER - 1); 1752 (ARCMSR_MAX_QBUFFER - 1);
1753 if (buf_empty_len >= readl(&prbuffer->data_len)) { 1753 if (buf_empty_len >= readl(&prbuffer->data_len)) {
1754 if (arcmsr_Read_iop_rqbuffer_data(acb, prbuffer) == 0) 1754 if (arcmsr_Read_iop_rqbuffer_data(acb, prbuffer) == 0)
@@ -1775,12 +1775,12 @@ static void arcmsr_write_ioctldata2iop_in_DWORD(struct AdapterControlBlock *acb)
1775 acb->acb_flags &= (~ACB_F_MESSAGE_WQBUFFER_READED); 1775 acb->acb_flags &= (~ACB_F_MESSAGE_WQBUFFER_READED);
1776 pwbuffer = arcmsr_get_iop_wqbuffer(acb); 1776 pwbuffer = arcmsr_get_iop_wqbuffer(acb);
1777 iop_data = (uint32_t __iomem *)pwbuffer->data; 1777 iop_data = (uint32_t __iomem *)pwbuffer->data;
1778 while ((acb->wqbuf_firstindex != acb->wqbuf_lastindex) 1778 while ((acb->wqbuf_getIndex != acb->wqbuf_putIndex)
1779 && (allxfer_len < 124)) { 1779 && (allxfer_len < 124)) {
1780 pQbuffer = &acb->wqbuffer[acb->wqbuf_firstindex]; 1780 pQbuffer = &acb->wqbuffer[acb->wqbuf_getIndex];
1781 *buf1 = *pQbuffer; 1781 *buf1 = *pQbuffer;
1782 acb->wqbuf_firstindex++; 1782 acb->wqbuf_getIndex++;
1783 acb->wqbuf_firstindex %= ARCMSR_MAX_QBUFFER; 1783 acb->wqbuf_getIndex %= ARCMSR_MAX_QBUFFER;
1784 buf1++; 1784 buf1++;
1785 allxfer_len++; 1785 allxfer_len++;
1786 } 1786 }
@@ -1818,12 +1818,12 @@ arcmsr_write_ioctldata2iop(struct AdapterControlBlock *acb)
1818 acb->acb_flags &= (~ACB_F_MESSAGE_WQBUFFER_READED); 1818 acb->acb_flags &= (~ACB_F_MESSAGE_WQBUFFER_READED);
1819 pwbuffer = arcmsr_get_iop_wqbuffer(acb); 1819 pwbuffer = arcmsr_get_iop_wqbuffer(acb);
1820 iop_data = (uint8_t __iomem *)pwbuffer->data; 1820 iop_data = (uint8_t __iomem *)pwbuffer->data;
1821 while ((acb->wqbuf_firstindex != acb->wqbuf_lastindex) 1821 while ((acb->wqbuf_getIndex != acb->wqbuf_putIndex)
1822 && (allxfer_len < 124)) { 1822 && (allxfer_len < 124)) {
1823 pQbuffer = &acb->wqbuffer[acb->wqbuf_firstindex]; 1823 pQbuffer = &acb->wqbuffer[acb->wqbuf_getIndex];
1824 writeb(*pQbuffer, iop_data); 1824 writeb(*pQbuffer, iop_data);
1825 acb->wqbuf_firstindex++; 1825 acb->wqbuf_getIndex++;
1826 acb->wqbuf_firstindex %= ARCMSR_MAX_QBUFFER; 1826 acb->wqbuf_getIndex %= ARCMSR_MAX_QBUFFER;
1827 iop_data++; 1827 iop_data++;
1828 allxfer_len++; 1828 allxfer_len++;
1829 } 1829 }
@@ -1838,9 +1838,9 @@ static void arcmsr_iop2drv_data_read_handle(struct AdapterControlBlock *acb)
1838 1838
1839 spin_lock_irqsave(&acb->wqbuffer_lock, flags); 1839 spin_lock_irqsave(&acb->wqbuffer_lock, flags);
1840 acb->acb_flags |= ACB_F_MESSAGE_WQBUFFER_READED; 1840 acb->acb_flags |= ACB_F_MESSAGE_WQBUFFER_READED;
1841 if (acb->wqbuf_firstindex != acb->wqbuf_lastindex) 1841 if (acb->wqbuf_getIndex != acb->wqbuf_putIndex)
1842 arcmsr_write_ioctldata2iop(acb); 1842 arcmsr_write_ioctldata2iop(acb);
1843 if (acb->wqbuf_firstindex == acb->wqbuf_lastindex) 1843 if (acb->wqbuf_getIndex == acb->wqbuf_putIndex)
1844 acb->acb_flags |= ACB_F_MESSAGE_WQBUFFER_CLEARED; 1844 acb->acb_flags |= ACB_F_MESSAGE_WQBUFFER_CLEARED;
1845 spin_unlock_irqrestore(&acb->wqbuffer_lock, flags); 1845 spin_unlock_irqrestore(&acb->wqbuffer_lock, flags);
1846} 1846}
@@ -2210,14 +2210,14 @@ void arcmsr_clear_iop2drv_rqueue_buffer(struct AdapterControlBlock *acb)
2210 for (i = 0; i < 15; i++) { 2210 for (i = 0; i < 15; i++) {
2211 if (acb->acb_flags & ACB_F_IOPDATA_OVERFLOW) { 2211 if (acb->acb_flags & ACB_F_IOPDATA_OVERFLOW) {
2212 acb->acb_flags &= ~ACB_F_IOPDATA_OVERFLOW; 2212 acb->acb_flags &= ~ACB_F_IOPDATA_OVERFLOW;
2213 acb->rqbuf_firstindex = 0; 2213 acb->rqbuf_getIndex = 0;
2214 acb->rqbuf_lastindex = 0; 2214 acb->rqbuf_putIndex = 0;
2215 arcmsr_iop_message_read(acb); 2215 arcmsr_iop_message_read(acb);
2216 mdelay(30); 2216 mdelay(30);
2217 } else if (acb->rqbuf_firstindex != 2217 } else if (acb->rqbuf_getIndex !=
2218 acb->rqbuf_lastindex) { 2218 acb->rqbuf_putIndex) {
2219 acb->rqbuf_firstindex = 0; 2219 acb->rqbuf_getIndex = 0;
2220 acb->rqbuf_lastindex = 0; 2220 acb->rqbuf_putIndex = 0;
2221 mdelay(30); 2221 mdelay(30);
2222 } else 2222 } else
2223 break; 2223 break;
@@ -2256,9 +2256,9 @@ static int arcmsr_iop_message_xfer(struct AdapterControlBlock *acb,
2256 switch (controlcode) { 2256 switch (controlcode) {
2257 case ARCMSR_MESSAGE_READ_RQBUFFER: { 2257 case ARCMSR_MESSAGE_READ_RQBUFFER: {
2258 unsigned char *ver_addr; 2258 unsigned char *ver_addr;
2259 uint8_t *pQbuffer, *ptmpQbuffer; 2259 uint8_t *ptmpQbuffer;
2260 uint32_t allxfer_len = 0; 2260 uint32_t allxfer_len = 0;
2261 ver_addr = kmalloc(1032, GFP_ATOMIC); 2261 ver_addr = kmalloc(ARCMSR_API_DATA_BUFLEN, GFP_ATOMIC);
2262 if (!ver_addr) { 2262 if (!ver_addr) {
2263 retvalue = ARCMSR_MESSAGE_FAIL; 2263 retvalue = ARCMSR_MESSAGE_FAIL;
2264 pr_info("%s: memory not enough!\n", __func__); 2264 pr_info("%s: memory not enough!\n", __func__);
@@ -2266,66 +2266,22 @@ static int arcmsr_iop_message_xfer(struct AdapterControlBlock *acb,
2266 } 2266 }
2267 ptmpQbuffer = ver_addr; 2267 ptmpQbuffer = ver_addr;
2268 spin_lock_irqsave(&acb->rqbuffer_lock, flags); 2268 spin_lock_irqsave(&acb->rqbuffer_lock, flags);
2269 if (acb->rqbuf_firstindex != acb->rqbuf_lastindex) { 2269 if (acb->rqbuf_getIndex != acb->rqbuf_putIndex) {
2270 pQbuffer = &acb->rqbuffer[acb->rqbuf_firstindex]; 2270 unsigned int tail = acb->rqbuf_getIndex;
2271 if (acb->rqbuf_firstindex > acb->rqbuf_lastindex) { 2271 unsigned int head = acb->rqbuf_putIndex;
2272 if ((ARCMSR_MAX_QBUFFER - 2272 unsigned int cnt_to_end = CIRC_CNT_TO_END(head, tail, ARCMSR_MAX_QBUFFER);
2273 acb->rqbuf_firstindex) >= 1032) { 2273
2274 memcpy(ptmpQbuffer, pQbuffer, 1032); 2274 allxfer_len = CIRC_CNT(head, tail, ARCMSR_MAX_QBUFFER);
2275 acb->rqbuf_firstindex += 1032; 2275 if (allxfer_len > ARCMSR_API_DATA_BUFLEN)
2276 acb->rqbuf_firstindex %= ARCMSR_MAX_QBUFFER; 2276 allxfer_len = ARCMSR_API_DATA_BUFLEN;
2277 allxfer_len = 1032; 2277
2278 } else { 2278 if (allxfer_len <= cnt_to_end)
2279 if (((ARCMSR_MAX_QBUFFER - 2279 memcpy(ptmpQbuffer, acb->rqbuffer + tail, allxfer_len);
2280 acb->rqbuf_firstindex) + 2280 else {
2281 acb->rqbuf_lastindex) > 1032) { 2281 memcpy(ptmpQbuffer, acb->rqbuffer + tail, cnt_to_end);
2282 memcpy(ptmpQbuffer, 2282 memcpy(ptmpQbuffer + cnt_to_end, acb->rqbuffer, allxfer_len - cnt_to_end);
2283 pQbuffer, ARCMSR_MAX_QBUFFER
2284 - acb->rqbuf_firstindex);
2285 ptmpQbuffer +=
2286 ARCMSR_MAX_QBUFFER -
2287 acb->rqbuf_firstindex;
2288 memcpy(ptmpQbuffer,
2289 acb->rqbuffer, 1032 -
2290 (ARCMSR_MAX_QBUFFER
2291 - acb->rqbuf_firstindex));
2292 acb->rqbuf_firstindex =
2293 1032 - (ARCMSR_MAX_QBUFFER
2294 - acb->rqbuf_firstindex);
2295 allxfer_len = 1032;
2296 } else {
2297 memcpy(ptmpQbuffer,
2298 pQbuffer, ARCMSR_MAX_QBUFFER
2299 - acb->rqbuf_firstindex);
2300 ptmpQbuffer +=
2301 ARCMSR_MAX_QBUFFER -
2302 acb->rqbuf_firstindex;
2303 memcpy(ptmpQbuffer,
2304 acb->rqbuffer,
2305 acb->rqbuf_lastindex);
2306 allxfer_len = ARCMSR_MAX_QBUFFER
2307 - acb->rqbuf_firstindex +
2308 acb->rqbuf_lastindex;
2309 acb->rqbuf_firstindex =
2310 acb->rqbuf_lastindex;
2311 }
2312 }
2313 } else {
2314 if ((acb->rqbuf_lastindex -
2315 acb->rqbuf_firstindex) > 1032) {
2316 memcpy(ptmpQbuffer, pQbuffer, 1032);
2317 acb->rqbuf_firstindex += 1032;
2318 allxfer_len = 1032;
2319 } else {
2320 memcpy(ptmpQbuffer, pQbuffer,
2321 acb->rqbuf_lastindex -
2322 acb->rqbuf_firstindex);
2323 allxfer_len = acb->rqbuf_lastindex
2324 - acb->rqbuf_firstindex;
2325 acb->rqbuf_firstindex =
2326 acb->rqbuf_lastindex;
2327 }
2328 } 2283 }
2284 acb->rqbuf_getIndex = (acb->rqbuf_getIndex + allxfer_len) % ARCMSR_MAX_QBUFFER;
2329 } 2285 }
2330 memcpy(pcmdmessagefld->messagedatabuffer, ver_addr, 2286 memcpy(pcmdmessagefld->messagedatabuffer, ver_addr,
2331 allxfer_len); 2287 allxfer_len);
@@ -2349,9 +2305,9 @@ static int arcmsr_iop_message_xfer(struct AdapterControlBlock *acb,
2349 } 2305 }
2350 case ARCMSR_MESSAGE_WRITE_WQBUFFER: { 2306 case ARCMSR_MESSAGE_WRITE_WQBUFFER: {
2351 unsigned char *ver_addr; 2307 unsigned char *ver_addr;
2352 int32_t my_empty_len, user_len, wqbuf_firstindex, wqbuf_lastindex; 2308 int32_t user_len, cnt2end;
2353 uint8_t *pQbuffer, *ptmpuserbuffer; 2309 uint8_t *pQbuffer, *ptmpuserbuffer;
2354 ver_addr = kmalloc(1032, GFP_ATOMIC); 2310 ver_addr = kmalloc(ARCMSR_API_DATA_BUFLEN, GFP_ATOMIC);
2355 if (!ver_addr) { 2311 if (!ver_addr) {
2356 retvalue = ARCMSR_MESSAGE_FAIL; 2312 retvalue = ARCMSR_MESSAGE_FAIL;
2357 goto message_out; 2313 goto message_out;
@@ -2361,9 +2317,7 @@ static int arcmsr_iop_message_xfer(struct AdapterControlBlock *acb,
2361 memcpy(ptmpuserbuffer, 2317 memcpy(ptmpuserbuffer,
2362 pcmdmessagefld->messagedatabuffer, user_len); 2318 pcmdmessagefld->messagedatabuffer, user_len);
2363 spin_lock_irqsave(&acb->wqbuffer_lock, flags); 2319 spin_lock_irqsave(&acb->wqbuffer_lock, flags);
2364 wqbuf_lastindex = acb->wqbuf_lastindex; 2320 if (acb->wqbuf_putIndex != acb->wqbuf_getIndex) {
2365 wqbuf_firstindex = acb->wqbuf_firstindex;
2366 if (wqbuf_lastindex != wqbuf_firstindex) {
2367 struct SENSE_DATA *sensebuffer = 2321 struct SENSE_DATA *sensebuffer =
2368 (struct SENSE_DATA *)cmd->sense_buffer; 2322 (struct SENSE_DATA *)cmd->sense_buffer;
2369 arcmsr_write_ioctldata2iop(acb); 2323 arcmsr_write_ioctldata2iop(acb);
@@ -2375,48 +2329,22 @@ static int arcmsr_iop_message_xfer(struct AdapterControlBlock *acb,
2375 sensebuffer->Valid = 1; 2329 sensebuffer->Valid = 1;
2376 retvalue = ARCMSR_MESSAGE_FAIL; 2330 retvalue = ARCMSR_MESSAGE_FAIL;
2377 } else { 2331 } else {
2378 my_empty_len = (wqbuf_firstindex - wqbuf_lastindex - 1) 2332 pQbuffer = &acb->wqbuffer[acb->wqbuf_putIndex];
2379 & (ARCMSR_MAX_QBUFFER - 1); 2333 cnt2end = ARCMSR_MAX_QBUFFER - acb->wqbuf_putIndex;
2380 if (my_empty_len >= user_len) { 2334 if (user_len > cnt2end) {
2381 while (user_len > 0) { 2335 memcpy(pQbuffer, ptmpuserbuffer, cnt2end);
2382 pQbuffer = &acb->wqbuffer[acb->wqbuf_lastindex]; 2336 ptmpuserbuffer += cnt2end;
2383 if ((acb->wqbuf_lastindex + user_len) 2337 user_len -= cnt2end;
2384 > ARCMSR_MAX_QBUFFER) { 2338 acb->wqbuf_putIndex = 0;
2385 memcpy(pQbuffer, ptmpuserbuffer, 2339 pQbuffer = acb->wqbuffer;
2386 ARCMSR_MAX_QBUFFER - 2340 }
2387 acb->wqbuf_lastindex); 2341 memcpy(pQbuffer, ptmpuserbuffer, user_len);
2388 ptmpuserbuffer += 2342 acb->wqbuf_putIndex += user_len;
2389 (ARCMSR_MAX_QBUFFER 2343 acb->wqbuf_putIndex %= ARCMSR_MAX_QBUFFER;
2390 - acb->wqbuf_lastindex); 2344 if (acb->acb_flags & ACB_F_MESSAGE_WQBUFFER_CLEARED) {
2391 user_len -= (ARCMSR_MAX_QBUFFER 2345 acb->acb_flags &=
2392 - acb->wqbuf_lastindex);
2393 acb->wqbuf_lastindex = 0;
2394 } else {
2395 memcpy(pQbuffer, ptmpuserbuffer,
2396 user_len);
2397 acb->wqbuf_lastindex += user_len;
2398 acb->wqbuf_lastindex %=
2399 ARCMSR_MAX_QBUFFER;
2400 user_len = 0;
2401 }
2402 }
2403 if (acb->acb_flags &
2404 ACB_F_MESSAGE_WQBUFFER_CLEARED) {
2405 acb->acb_flags &=
2406 ~ACB_F_MESSAGE_WQBUFFER_CLEARED; 2346 ~ACB_F_MESSAGE_WQBUFFER_CLEARED;
2407 arcmsr_write_ioctldata2iop(acb); 2347 arcmsr_write_ioctldata2iop(acb);
2408 }
2409 } else {
2410 struct SENSE_DATA *sensebuffer =
2411 (struct SENSE_DATA *)cmd->sense_buffer;
2412 /* has error report sensedata */
2413 sensebuffer->ErrorCode =
2414 SCSI_SENSE_CURRENT_ERRORS;
2415 sensebuffer->SenseKey = ILLEGAL_REQUEST;
2416 sensebuffer->AdditionalSenseLength = 0x0A;
2417 sensebuffer->AdditionalSenseCode = 0x20;
2418 sensebuffer->Valid = 1;
2419 retvalue = ARCMSR_MESSAGE_FAIL;
2420 } 2348 }
2421 } 2349 }
2422 spin_unlock_irqrestore(&acb->wqbuffer_lock, flags); 2350 spin_unlock_irqrestore(&acb->wqbuffer_lock, flags);
@@ -2435,8 +2363,8 @@ static int arcmsr_iop_message_xfer(struct AdapterControlBlock *acb,
2435 arcmsr_clear_iop2drv_rqueue_buffer(acb); 2363 arcmsr_clear_iop2drv_rqueue_buffer(acb);
2436 spin_lock_irqsave(&acb->rqbuffer_lock, flags); 2364 spin_lock_irqsave(&acb->rqbuffer_lock, flags);
2437 acb->acb_flags |= ACB_F_MESSAGE_RQBUFFER_CLEARED; 2365 acb->acb_flags |= ACB_F_MESSAGE_RQBUFFER_CLEARED;
2438 acb->rqbuf_firstindex = 0; 2366 acb->rqbuf_getIndex = 0;
2439 acb->rqbuf_lastindex = 0; 2367 acb->rqbuf_putIndex = 0;
2440 memset(pQbuffer, 0, ARCMSR_MAX_QBUFFER); 2368 memset(pQbuffer, 0, ARCMSR_MAX_QBUFFER);
2441 spin_unlock_irqrestore(&acb->rqbuffer_lock, flags); 2369 spin_unlock_irqrestore(&acb->rqbuffer_lock, flags);
2442 if (acb->fw_flag == FW_DEADLOCK) 2370 if (acb->fw_flag == FW_DEADLOCK)
@@ -2452,8 +2380,8 @@ static int arcmsr_iop_message_xfer(struct AdapterControlBlock *acb,
2452 spin_lock_irqsave(&acb->wqbuffer_lock, flags); 2380 spin_lock_irqsave(&acb->wqbuffer_lock, flags);
2453 acb->acb_flags |= (ACB_F_MESSAGE_WQBUFFER_CLEARED | 2381 acb->acb_flags |= (ACB_F_MESSAGE_WQBUFFER_CLEARED |
2454 ACB_F_MESSAGE_WQBUFFER_READED); 2382 ACB_F_MESSAGE_WQBUFFER_READED);
2455 acb->wqbuf_firstindex = 0; 2383 acb->wqbuf_getIndex = 0;
2456 acb->wqbuf_lastindex = 0; 2384 acb->wqbuf_putIndex = 0;
2457 memset(pQbuffer, 0, ARCMSR_MAX_QBUFFER); 2385 memset(pQbuffer, 0, ARCMSR_MAX_QBUFFER);
2458 spin_unlock_irqrestore(&acb->wqbuffer_lock, flags); 2386 spin_unlock_irqrestore(&acb->wqbuffer_lock, flags);
2459 if (acb->fw_flag == FW_DEADLOCK) 2387 if (acb->fw_flag == FW_DEADLOCK)
@@ -2469,16 +2397,16 @@ static int arcmsr_iop_message_xfer(struct AdapterControlBlock *acb,
2469 arcmsr_clear_iop2drv_rqueue_buffer(acb); 2397 arcmsr_clear_iop2drv_rqueue_buffer(acb);
2470 spin_lock_irqsave(&acb->rqbuffer_lock, flags); 2398 spin_lock_irqsave(&acb->rqbuffer_lock, flags);
2471 acb->acb_flags |= ACB_F_MESSAGE_RQBUFFER_CLEARED; 2399 acb->acb_flags |= ACB_F_MESSAGE_RQBUFFER_CLEARED;
2472 acb->rqbuf_firstindex = 0; 2400 acb->rqbuf_getIndex = 0;
2473 acb->rqbuf_lastindex = 0; 2401 acb->rqbuf_putIndex = 0;
2474 pQbuffer = acb->rqbuffer; 2402 pQbuffer = acb->rqbuffer;
2475 memset(pQbuffer, 0, sizeof(struct QBUFFER)); 2403 memset(pQbuffer, 0, sizeof(struct QBUFFER));
2476 spin_unlock_irqrestore(&acb->rqbuffer_lock, flags); 2404 spin_unlock_irqrestore(&acb->rqbuffer_lock, flags);
2477 spin_lock_irqsave(&acb->wqbuffer_lock, flags); 2405 spin_lock_irqsave(&acb->wqbuffer_lock, flags);
2478 acb->acb_flags |= (ACB_F_MESSAGE_WQBUFFER_CLEARED | 2406 acb->acb_flags |= (ACB_F_MESSAGE_WQBUFFER_CLEARED |
2479 ACB_F_MESSAGE_WQBUFFER_READED); 2407 ACB_F_MESSAGE_WQBUFFER_READED);
2480 acb->wqbuf_firstindex = 0; 2408 acb->wqbuf_getIndex = 0;
2481 acb->wqbuf_lastindex = 0; 2409 acb->wqbuf_putIndex = 0;
2482 pQbuffer = acb->wqbuffer; 2410 pQbuffer = acb->wqbuffer;
2483 memset(pQbuffer, 0, sizeof(struct QBUFFER)); 2411 memset(pQbuffer, 0, sizeof(struct QBUFFER));
2484 spin_unlock_irqrestore(&acb->wqbuffer_lock, flags); 2412 spin_unlock_irqrestore(&acb->wqbuffer_lock, flags);