diff options
author | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2014-02-07 12:16:38 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2014-02-07 12:16:38 -0500 |
commit | ead00ddca0578aa9984e7e712024aead113e8253 (patch) | |
tree | 05657aad8e7db0de5d319f8fe66090a0b0500fcc | |
parent | 0010b79d56cb1d7717bf146ee59df5a625b0330b (diff) |
Revert "Staging: dgrp: Refactor the function dgrp_receive() in drrp_net_ops.c"
This reverts commit b73db54750482cf3910046c82a84ce8c1684dfbe.
Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
Reported-by: Chen Gang <gang.chen.5i5j@gmail.com>
Cc: Rashika Kheria <rashika.kheria@gmail.com>
Cc: James Hogan <james.hogan@imgtec.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/staging/dgrp/dgrp_net_ops.c | 330 |
1 files changed, 155 insertions, 175 deletions
diff --git a/drivers/staging/dgrp/dgrp_net_ops.c b/drivers/staging/dgrp/dgrp_net_ops.c index 1f61b89eca44..33ac7fb88cbd 100644 --- a/drivers/staging/dgrp/dgrp_net_ops.c +++ b/drivers/staging/dgrp/dgrp_net_ops.c | |||
@@ -2232,177 +2232,6 @@ done: | |||
2232 | return rtn; | 2232 | return rtn; |
2233 | } | 2233 | } |
2234 | 2234 | ||
2235 | /* | ||
2236 | * Common Packet Handling code | ||
2237 | */ | ||
2238 | |||
2239 | static void handle_data_in_packet(struct nd_struct *nd, struct ch_struct *ch, | ||
2240 | long dlen, long plen, int n1, u8 *dbuf) | ||
2241 | { | ||
2242 | char *error; | ||
2243 | long n; | ||
2244 | long remain; | ||
2245 | u8 *buf; | ||
2246 | u8 *b; | ||
2247 | |||
2248 | remain = nd->nd_remain; | ||
2249 | nd->nd_tx_work = 1; | ||
2250 | |||
2251 | /* | ||
2252 | * Otherwise data should appear only when we are | ||
2253 | * in the CS_READY state. | ||
2254 | */ | ||
2255 | |||
2256 | if (ch->ch_state < CS_READY) { | ||
2257 | error = "Data received before RWIN established"; | ||
2258 | nd->nd_remain = 0; | ||
2259 | nd->nd_state = NS_SEND_ERROR; | ||
2260 | nd->nd_error = error; | ||
2261 | } | ||
2262 | |||
2263 | /* | ||
2264 | * Assure that the data received is within the | ||
2265 | * allowable window. | ||
2266 | */ | ||
2267 | |||
2268 | n = (ch->ch_s_rwin - ch->ch_s_rin) & 0xffff; | ||
2269 | |||
2270 | if (dlen > n) { | ||
2271 | error = "Receive data overrun"; | ||
2272 | nd->nd_remain = 0; | ||
2273 | nd->nd_state = NS_SEND_ERROR; | ||
2274 | nd->nd_error = error; | ||
2275 | } | ||
2276 | |||
2277 | /* | ||
2278 | * If we received 3 or less characters, | ||
2279 | * assume it is a human typing, and set RTIME | ||
2280 | * to 10 milliseconds. | ||
2281 | * | ||
2282 | * If we receive 10 or more characters, | ||
2283 | * assume its not a human typing, and set RTIME | ||
2284 | * to 100 milliseconds. | ||
2285 | */ | ||
2286 | |||
2287 | if (ch->ch_edelay != DGRP_RTIME) { | ||
2288 | if (ch->ch_rtime != ch->ch_edelay) { | ||
2289 | ch->ch_rtime = ch->ch_edelay; | ||
2290 | ch->ch_flag |= CH_PARAM; | ||
2291 | } | ||
2292 | } else if (dlen <= 3) { | ||
2293 | if (ch->ch_rtime != 10) { | ||
2294 | ch->ch_rtime = 10; | ||
2295 | ch->ch_flag |= CH_PARAM; | ||
2296 | } | ||
2297 | } else { | ||
2298 | if (ch->ch_rtime != DGRP_RTIME) { | ||
2299 | ch->ch_rtime = DGRP_RTIME; | ||
2300 | ch->ch_flag |= CH_PARAM; | ||
2301 | } | ||
2302 | } | ||
2303 | |||
2304 | /* | ||
2305 | * If a portion of the packet is outside the | ||
2306 | * buffer, shorten the effective length of the | ||
2307 | * data packet to be the amount of data received. | ||
2308 | */ | ||
2309 | |||
2310 | if (remain < plen) | ||
2311 | dlen -= plen - remain; | ||
2312 | |||
2313 | /* | ||
2314 | * Detect if receive flush is now complete. | ||
2315 | */ | ||
2316 | |||
2317 | if ((ch->ch_flag & CH_RX_FLUSH) != 0 && | ||
2318 | ((ch->ch_flush_seq - nd->nd_seq_out) & SEQ_MASK) >= | ||
2319 | ((nd->nd_seq_in - nd->nd_seq_out) & SEQ_MASK)) { | ||
2320 | ch->ch_flag &= ~CH_RX_FLUSH; | ||
2321 | } | ||
2322 | |||
2323 | /* | ||
2324 | * If we are ready to receive, move the data into | ||
2325 | * the receive buffer. | ||
2326 | */ | ||
2327 | |||
2328 | ch->ch_s_rin = (ch->ch_s_rin + dlen) & 0xffff; | ||
2329 | |||
2330 | if (ch->ch_state == CS_READY && | ||
2331 | (ch->ch_tun.un_open_count != 0) && | ||
2332 | (ch->ch_tun.un_flag & UN_CLOSING) == 0 && | ||
2333 | (ch->ch_cflag & CF_CREAD) != 0 && | ||
2334 | (ch->ch_flag & (CH_BAUD0 | CH_RX_FLUSH)) == 0 && | ||
2335 | (ch->ch_send & RR_RX_FLUSH) == 0) { | ||
2336 | |||
2337 | if (ch->ch_rin + dlen >= RBUF_MAX) { | ||
2338 | n = RBUF_MAX - ch->ch_rin; | ||
2339 | |||
2340 | memcpy(ch->ch_rbuf + ch->ch_rin, dbuf, n); | ||
2341 | |||
2342 | ch->ch_rin = 0; | ||
2343 | dbuf += n; | ||
2344 | dlen -= n; | ||
2345 | } | ||
2346 | |||
2347 | memcpy(ch->ch_rbuf + ch->ch_rin, dbuf, dlen); | ||
2348 | |||
2349 | ch->ch_rin += dlen; | ||
2350 | |||
2351 | |||
2352 | /* | ||
2353 | * If we are not in fastcook mode, or | ||
2354 | * if there is a fastcook thread | ||
2355 | * waiting for data, send the data to | ||
2356 | * the line discipline. | ||
2357 | */ | ||
2358 | |||
2359 | if ((ch->ch_flag & CH_FAST_READ) == 0 || | ||
2360 | ch->ch_inwait != 0) { | ||
2361 | dgrp_input(ch); | ||
2362 | } | ||
2363 | |||
2364 | /* | ||
2365 | * If there is a read thread waiting | ||
2366 | * in select, and we are in fastcook | ||
2367 | * mode, wake him up. | ||
2368 | */ | ||
2369 | |||
2370 | if (waitqueue_active(&ch->ch_tun.un_tty->read_wait) && | ||
2371 | (ch->ch_flag & CH_FAST_READ) != 0) | ||
2372 | wake_up_interruptible(&ch->ch_tun.un_tty->read_wait); | ||
2373 | |||
2374 | /* | ||
2375 | * Wake any thread waiting in the | ||
2376 | * fastcook loop. | ||
2377 | */ | ||
2378 | |||
2379 | if ((ch->ch_flag & CH_INPUT) != 0) { | ||
2380 | ch->ch_flag &= ~CH_INPUT; | ||
2381 | wake_up_interruptible(&ch->ch_flag_wait); | ||
2382 | } | ||
2383 | } | ||
2384 | |||
2385 | /* | ||
2386 | * Fabricate and insert a data packet header to | ||
2387 | * preced the remaining data when it comes in. | ||
2388 | */ | ||
2389 | |||
2390 | if (remain < plen) { | ||
2391 | dlen = plen - remain; | ||
2392 | b = buf; | ||
2393 | |||
2394 | b[0] = 0x90 + n1; | ||
2395 | put_unaligned_be16(dlen, b + 1); | ||
2396 | |||
2397 | remain = 3; | ||
2398 | if (remain > 0 && b != buf) | ||
2399 | memcpy(buf, b, remain); | ||
2400 | |||
2401 | nd->nd_remain = remain; | ||
2402 | return; | ||
2403 | } | ||
2404 | } | ||
2405 | |||
2406 | /** | 2235 | /** |
2407 | * dgrp_receive() -- decode data packets received from the remote PortServer. | 2236 | * dgrp_receive() -- decode data packets received from the remote PortServer. |
2408 | * @nd: pointer to a node structure | 2237 | * @nd: pointer to a node structure |
@@ -2477,8 +2306,7 @@ static void dgrp_receive(struct nd_struct *nd) | |||
2477 | plen = dlen + 1; | 2306 | plen = dlen + 1; |
2478 | 2307 | ||
2479 | dbuf = b + 1; | 2308 | dbuf = b + 1; |
2480 | handle_data_in_packet(nd, ch, dlen, plen, n1, dbuf); | 2309 | goto data; |
2481 | break; | ||
2482 | 2310 | ||
2483 | /* | 2311 | /* |
2484 | * Process 2-byte header data packet. | 2312 | * Process 2-byte header data packet. |
@@ -2492,8 +2320,7 @@ static void dgrp_receive(struct nd_struct *nd) | |||
2492 | plen = dlen + 2; | 2320 | plen = dlen + 2; |
2493 | 2321 | ||
2494 | dbuf = b + 2; | 2322 | dbuf = b + 2; |
2495 | handle_data_in_packet(nd, ch, dlen, plen, n1, dbuf); | 2323 | goto data; |
2496 | break; | ||
2497 | 2324 | ||
2498 | /* | 2325 | /* |
2499 | * Process 3-byte header data packet. | 2326 | * Process 3-byte header data packet. |
@@ -2508,6 +2335,159 @@ static void dgrp_receive(struct nd_struct *nd) | |||
2508 | 2335 | ||
2509 | dbuf = b + 3; | 2336 | dbuf = b + 3; |
2510 | 2337 | ||
2338 | /* | ||
2339 | * Common packet handling code. | ||
2340 | */ | ||
2341 | |||
2342 | data: | ||
2343 | nd->nd_tx_work = 1; | ||
2344 | |||
2345 | /* | ||
2346 | * Otherwise data should appear only when we are | ||
2347 | * in the CS_READY state. | ||
2348 | */ | ||
2349 | |||
2350 | if (ch->ch_state < CS_READY) { | ||
2351 | error = "Data received before RWIN established"; | ||
2352 | goto prot_error; | ||
2353 | } | ||
2354 | |||
2355 | /* | ||
2356 | * Assure that the data received is within the | ||
2357 | * allowable window. | ||
2358 | */ | ||
2359 | |||
2360 | n = (ch->ch_s_rwin - ch->ch_s_rin) & 0xffff; | ||
2361 | |||
2362 | if (dlen > n) { | ||
2363 | error = "Receive data overrun"; | ||
2364 | goto prot_error; | ||
2365 | } | ||
2366 | |||
2367 | /* | ||
2368 | * If we received 3 or less characters, | ||
2369 | * assume it is a human typing, and set RTIME | ||
2370 | * to 10 milliseconds. | ||
2371 | * | ||
2372 | * If we receive 10 or more characters, | ||
2373 | * assume its not a human typing, and set RTIME | ||
2374 | * to 100 milliseconds. | ||
2375 | */ | ||
2376 | |||
2377 | if (ch->ch_edelay != DGRP_RTIME) { | ||
2378 | if (ch->ch_rtime != ch->ch_edelay) { | ||
2379 | ch->ch_rtime = ch->ch_edelay; | ||
2380 | ch->ch_flag |= CH_PARAM; | ||
2381 | } | ||
2382 | } else if (dlen <= 3) { | ||
2383 | if (ch->ch_rtime != 10) { | ||
2384 | ch->ch_rtime = 10; | ||
2385 | ch->ch_flag |= CH_PARAM; | ||
2386 | } | ||
2387 | } else { | ||
2388 | if (ch->ch_rtime != DGRP_RTIME) { | ||
2389 | ch->ch_rtime = DGRP_RTIME; | ||
2390 | ch->ch_flag |= CH_PARAM; | ||
2391 | } | ||
2392 | } | ||
2393 | |||
2394 | /* | ||
2395 | * If a portion of the packet is outside the | ||
2396 | * buffer, shorten the effective length of the | ||
2397 | * data packet to be the amount of data received. | ||
2398 | */ | ||
2399 | |||
2400 | if (remain < plen) | ||
2401 | dlen -= plen - remain; | ||
2402 | |||
2403 | /* | ||
2404 | * Detect if receive flush is now complete. | ||
2405 | */ | ||
2406 | |||
2407 | if ((ch->ch_flag & CH_RX_FLUSH) != 0 && | ||
2408 | ((ch->ch_flush_seq - nd->nd_seq_out) & SEQ_MASK) >= | ||
2409 | ((nd->nd_seq_in - nd->nd_seq_out) & SEQ_MASK)) { | ||
2410 | ch->ch_flag &= ~CH_RX_FLUSH; | ||
2411 | } | ||
2412 | |||
2413 | /* | ||
2414 | * If we are ready to receive, move the data into | ||
2415 | * the receive buffer. | ||
2416 | */ | ||
2417 | |||
2418 | ch->ch_s_rin = (ch->ch_s_rin + dlen) & 0xffff; | ||
2419 | |||
2420 | if (ch->ch_state == CS_READY && | ||
2421 | (ch->ch_tun.un_open_count != 0) && | ||
2422 | (ch->ch_tun.un_flag & UN_CLOSING) == 0 && | ||
2423 | (ch->ch_cflag & CF_CREAD) != 0 && | ||
2424 | (ch->ch_flag & (CH_BAUD0 | CH_RX_FLUSH)) == 0 && | ||
2425 | (ch->ch_send & RR_RX_FLUSH) == 0) { | ||
2426 | |||
2427 | if (ch->ch_rin + dlen >= RBUF_MAX) { | ||
2428 | n = RBUF_MAX - ch->ch_rin; | ||
2429 | |||
2430 | memcpy(ch->ch_rbuf + ch->ch_rin, dbuf, n); | ||
2431 | |||
2432 | ch->ch_rin = 0; | ||
2433 | dbuf += n; | ||
2434 | dlen -= n; | ||
2435 | } | ||
2436 | |||
2437 | memcpy(ch->ch_rbuf + ch->ch_rin, dbuf, dlen); | ||
2438 | |||
2439 | ch->ch_rin += dlen; | ||
2440 | |||
2441 | |||
2442 | /* | ||
2443 | * If we are not in fastcook mode, or | ||
2444 | * if there is a fastcook thread | ||
2445 | * waiting for data, send the data to | ||
2446 | * the line discipline. | ||
2447 | */ | ||
2448 | |||
2449 | if ((ch->ch_flag & CH_FAST_READ) == 0 || | ||
2450 | ch->ch_inwait != 0) { | ||
2451 | dgrp_input(ch); | ||
2452 | } | ||
2453 | |||
2454 | /* | ||
2455 | * If there is a read thread waiting | ||
2456 | * in select, and we are in fastcook | ||
2457 | * mode, wake him up. | ||
2458 | */ | ||
2459 | |||
2460 | if (waitqueue_active(&ch->ch_tun.un_tty->read_wait) && | ||
2461 | (ch->ch_flag & CH_FAST_READ) != 0) | ||
2462 | wake_up_interruptible(&ch->ch_tun.un_tty->read_wait); | ||
2463 | |||
2464 | /* | ||
2465 | * Wake any thread waiting in the | ||
2466 | * fastcook loop. | ||
2467 | */ | ||
2468 | |||
2469 | if ((ch->ch_flag & CH_INPUT) != 0) { | ||
2470 | ch->ch_flag &= ~CH_INPUT; | ||
2471 | |||
2472 | wake_up_interruptible(&ch->ch_flag_wait); | ||
2473 | } | ||
2474 | } | ||
2475 | |||
2476 | /* | ||
2477 | * Fabricate and insert a data packet header to | ||
2478 | * preced the remaining data when it comes in. | ||
2479 | */ | ||
2480 | |||
2481 | if (remain < plen) { | ||
2482 | dlen = plen - remain; | ||
2483 | b = buf; | ||
2484 | |||
2485 | b[0] = 0x90 + n1; | ||
2486 | put_unaligned_be16(dlen, b + 1); | ||
2487 | |||
2488 | remain = 3; | ||
2489 | goto done; | ||
2490 | } | ||
2511 | break; | 2491 | break; |
2512 | 2492 | ||
2513 | /* | 2493 | /* |