aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/isdn/gigaset/isocdata.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/isdn/gigaset/isocdata.c')
-rw-r--r--drivers/isdn/gigaset/isocdata.c51
1 files changed, 26 insertions, 25 deletions
diff --git a/drivers/isdn/gigaset/isocdata.c b/drivers/isdn/gigaset/isocdata.c
index e0505f238807..e30a7773f93c 100644
--- a/drivers/isdn/gigaset/isocdata.c
+++ b/drivers/isdn/gigaset/isocdata.c
@@ -23,9 +23,9 @@
23 */ 23 */
24void gigaset_isowbuf_init(struct isowbuf_t *iwb, unsigned char idle) 24void gigaset_isowbuf_init(struct isowbuf_t *iwb, unsigned char idle)
25{ 25{
26 atomic_set(&iwb->read, 0); 26 iwb->read = 0;
27 atomic_set(&iwb->nextread, 0); 27 iwb->nextread = 0;
28 atomic_set(&iwb->write, 0); 28 iwb->write = 0;
29 atomic_set(&iwb->writesem, 1); 29 atomic_set(&iwb->writesem, 1);
30 iwb->wbits = 0; 30 iwb->wbits = 0;
31 iwb->idle = idle; 31 iwb->idle = idle;
@@ -39,8 +39,8 @@ static inline int isowbuf_freebytes(struct isowbuf_t *iwb)
39{ 39{
40 int read, write, freebytes; 40 int read, write, freebytes;
41 41
42 read = atomic_read(&iwb->read); 42 read = iwb->read;
43 write = atomic_read(&iwb->write); 43 write = iwb->write;
44 if ((freebytes = read - write) > 0) { 44 if ((freebytes = read - write) > 0) {
45 /* no wraparound: need padding space within regular area */ 45 /* no wraparound: need padding space within regular area */
46 return freebytes - BAS_OUTBUFPAD; 46 return freebytes - BAS_OUTBUFPAD;
@@ -62,7 +62,7 @@ static inline int isowbuf_poscmp(struct isowbuf_t *iwb, int a, int b)
62 int read; 62 int read;
63 if (a == b) 63 if (a == b)
64 return 0; 64 return 0;
65 read = atomic_read(&iwb->read); 65 read = iwb->read;
66 if (a < b) { 66 if (a < b) {
67 if (a < read && read <= b) 67 if (a < read && read <= b)
68 return +1; 68 return +1;
@@ -91,18 +91,18 @@ static inline int isowbuf_startwrite(struct isowbuf_t *iwb)
91#ifdef CONFIG_GIGASET_DEBUG 91#ifdef CONFIG_GIGASET_DEBUG
92 gig_dbg(DEBUG_ISO, 92 gig_dbg(DEBUG_ISO,
93 "%s: acquired iso write semaphore, data[write]=%02x, nbits=%d", 93 "%s: acquired iso write semaphore, data[write]=%02x, nbits=%d",
94 __func__, iwb->data[atomic_read(&iwb->write)], iwb->wbits); 94 __func__, iwb->data[iwb->write], iwb->wbits);
95#endif 95#endif
96 return 1; 96 return 1;
97} 97}
98 98
99/* finish writing 99/* finish writing
100 * release the write semaphore and update the maximum buffer fill level 100 * release the write semaphore
101 * returns the current write position 101 * returns the current write position
102 */ 102 */
103static inline int isowbuf_donewrite(struct isowbuf_t *iwb) 103static inline int isowbuf_donewrite(struct isowbuf_t *iwb)
104{ 104{
105 int write = atomic_read(&iwb->write); 105 int write = iwb->write;
106 atomic_inc(&iwb->writesem); 106 atomic_inc(&iwb->writesem);
107 return write; 107 return write;
108} 108}
@@ -116,7 +116,7 @@ static inline int isowbuf_donewrite(struct isowbuf_t *iwb)
116 */ 116 */
117static inline void isowbuf_putbits(struct isowbuf_t *iwb, u32 data, int nbits) 117static inline void isowbuf_putbits(struct isowbuf_t *iwb, u32 data, int nbits)
118{ 118{
119 int write = atomic_read(&iwb->write); 119 int write = iwb->write;
120 data <<= iwb->wbits; 120 data <<= iwb->wbits;
121 data |= iwb->data[write]; 121 data |= iwb->data[write];
122 nbits += iwb->wbits; 122 nbits += iwb->wbits;
@@ -128,7 +128,7 @@ static inline void isowbuf_putbits(struct isowbuf_t *iwb, u32 data, int nbits)
128 } 128 }
129 iwb->wbits = nbits; 129 iwb->wbits = nbits;
130 iwb->data[write] = data & 0xff; 130 iwb->data[write] = data & 0xff;
131 atomic_set(&iwb->write, write); 131 iwb->write = write;
132} 132}
133 133
134/* put final flag on HDLC bitstream 134/* put final flag on HDLC bitstream
@@ -142,7 +142,7 @@ static inline void isowbuf_putflag(struct isowbuf_t *iwb)
142 /* add two flags, thus reliably covering one byte */ 142 /* add two flags, thus reliably covering one byte */
143 isowbuf_putbits(iwb, 0x7e7e, 8); 143 isowbuf_putbits(iwb, 0x7e7e, 8);
144 /* recover the idle flag byte */ 144 /* recover the idle flag byte */
145 write = atomic_read(&iwb->write); 145 write = iwb->write;
146 iwb->idle = iwb->data[write]; 146 iwb->idle = iwb->data[write];
147 gig_dbg(DEBUG_ISO, "idle fill byte %02x", iwb->idle); 147 gig_dbg(DEBUG_ISO, "idle fill byte %02x", iwb->idle);
148 /* mask extraneous bits in buffer */ 148 /* mask extraneous bits in buffer */
@@ -160,8 +160,8 @@ int gigaset_isowbuf_getbytes(struct isowbuf_t *iwb, int size)
160 int read, write, limit, src, dst; 160 int read, write, limit, src, dst;
161 unsigned char pbyte; 161 unsigned char pbyte;
162 162
163 read = atomic_read(&iwb->nextread); 163 read = iwb->nextread;
164 write = atomic_read(&iwb->write); 164 write = iwb->write;
165 if (likely(read == write)) { 165 if (likely(read == write)) {
166 /* return idle frame */ 166 /* return idle frame */
167 return read < BAS_OUTBUFPAD ? 167 return read < BAS_OUTBUFPAD ?
@@ -176,7 +176,7 @@ int gigaset_isowbuf_getbytes(struct isowbuf_t *iwb, int size)
176 err("invalid size %d", size); 176 err("invalid size %d", size);
177 return -EINVAL; 177 return -EINVAL;
178 } 178 }
179 src = atomic_read(&iwb->read); 179 src = iwb->read;
180 if (unlikely(limit > BAS_OUTBUFSIZE + BAS_OUTBUFPAD || 180 if (unlikely(limit > BAS_OUTBUFSIZE + BAS_OUTBUFPAD ||
181 (read < src && limit >= src))) { 181 (read < src && limit >= src))) {
182 err("isoc write buffer frame reservation violated"); 182 err("isoc write buffer frame reservation violated");
@@ -191,7 +191,8 @@ int gigaset_isowbuf_getbytes(struct isowbuf_t *iwb, int size)
191 if (!isowbuf_startwrite(iwb)) 191 if (!isowbuf_startwrite(iwb))
192 return -EBUSY; 192 return -EBUSY;
193 /* write position could have changed */ 193 /* write position could have changed */
194 if (limit >= (write = atomic_read(&iwb->write))) { 194 write = iwb->write;
195 if (limit >= write) {
195 pbyte = iwb->data[write]; /* save 196 pbyte = iwb->data[write]; /* save
196 partial byte */ 197 partial byte */
197 limit = write + BAS_OUTBUFPAD; 198 limit = write + BAS_OUTBUFPAD;
@@ -213,7 +214,7 @@ int gigaset_isowbuf_getbytes(struct isowbuf_t *iwb, int size)
213 __func__, pbyte, limit); 214 __func__, pbyte, limit);
214 iwb->data[limit] = pbyte; /* restore 215 iwb->data[limit] = pbyte; /* restore
215 partial byte */ 216 partial byte */
216 atomic_set(&iwb->write, limit); 217 iwb->write = limit;
217 } 218 }
218 isowbuf_donewrite(iwb); 219 isowbuf_donewrite(iwb);
219 } 220 }
@@ -233,7 +234,7 @@ int gigaset_isowbuf_getbytes(struct isowbuf_t *iwb, int size)
233 limit = src; 234 limit = src;
234 } 235 }
235 } 236 }
236 atomic_set(&iwb->nextread, limit); 237 iwb->nextread = limit;
237 return read; 238 return read;
238} 239}
239 240
@@ -477,7 +478,7 @@ static inline int trans_buildframe(struct isowbuf_t *iwb,
477 unsigned char c; 478 unsigned char c;
478 479
479 if (unlikely(count <= 0)) 480 if (unlikely(count <= 0))
480 return atomic_read(&iwb->write); /* better ideas? */ 481 return iwb->write;
481 482
482 if (isowbuf_freebytes(iwb) < count || 483 if (isowbuf_freebytes(iwb) < count ||
483 !isowbuf_startwrite(iwb)) { 484 !isowbuf_startwrite(iwb)) {
@@ -486,13 +487,13 @@ static inline int trans_buildframe(struct isowbuf_t *iwb,
486 } 487 }
487 488
488 gig_dbg(DEBUG_STREAM, "put %d bytes", count); 489 gig_dbg(DEBUG_STREAM, "put %d bytes", count);
489 write = atomic_read(&iwb->write); 490 write = iwb->write;
490 do { 491 do {
491 c = bitrev8(*in++); 492 c = bitrev8(*in++);
492 iwb->data[write++] = c; 493 iwb->data[write++] = c;
493 write %= BAS_OUTBUFSIZE; 494 write %= BAS_OUTBUFSIZE;
494 } while (--count > 0); 495 } while (--count > 0);
495 atomic_set(&iwb->write, write); 496 iwb->write = write;
496 iwb->idle = c; 497 iwb->idle = c;
497 498
498 return isowbuf_donewrite(iwb); 499 return isowbuf_donewrite(iwb);
@@ -947,8 +948,8 @@ void gigaset_isoc_input(struct inbuf_t *inbuf)
947 unsigned tail, head, numbytes; 948 unsigned tail, head, numbytes;
948 unsigned char *src; 949 unsigned char *src;
949 950
950 head = atomic_read(&inbuf->head); 951 head = inbuf->head;
951 while (head != (tail = atomic_read(&inbuf->tail))) { 952 while (head != (tail = inbuf->tail)) {
952 gig_dbg(DEBUG_INTR, "buffer state: %u -> %u", head, tail); 953 gig_dbg(DEBUG_INTR, "buffer state: %u -> %u", head, tail);
953 if (head > tail) 954 if (head > tail)
954 tail = RBUFSIZE; 955 tail = RBUFSIZE;
@@ -956,7 +957,7 @@ void gigaset_isoc_input(struct inbuf_t *inbuf)
956 numbytes = tail - head; 957 numbytes = tail - head;
957 gig_dbg(DEBUG_INTR, "processing %u bytes", numbytes); 958 gig_dbg(DEBUG_INTR, "processing %u bytes", numbytes);
958 959
959 if (atomic_read(&cs->mstate) == MS_LOCKED) { 960 if (cs->mstate == MS_LOCKED) {
960 gigaset_dbg_buffer(DEBUG_LOCKCMD, "received response", 961 gigaset_dbg_buffer(DEBUG_LOCKCMD, "received response",
961 numbytes, src); 962 numbytes, src);
962 gigaset_if_receive(inbuf->cs, src, numbytes); 963 gigaset_if_receive(inbuf->cs, src, numbytes);
@@ -970,7 +971,7 @@ void gigaset_isoc_input(struct inbuf_t *inbuf)
970 if (head == RBUFSIZE) 971 if (head == RBUFSIZE)
971 head = 0; 972 head = 0;
972 gig_dbg(DEBUG_INTR, "setting head to %u", head); 973 gig_dbg(DEBUG_INTR, "setting head to %u", head);
973 atomic_set(&inbuf->head, head); 974 inbuf->head = head;
974 } 975 }
975} 976}
976 977