| 897 | } |
| 898 | |
| 899 | static const struct tcp_hwrate_limit_table * |
| 900 | tcp_find_suitable_rate(const struct tcp_rate_set *rs, uint64_t bytes_per_sec, uint32_t flags) |
| 901 | { |
| 902 | /** |
| 903 | * Hunt the rate table with the restrictions in flags and find a |
| 904 | * suitable rate if possible. |
| 905 | * RS_PACING_EXACT_MATCH - look for an exact match to rate. |
| 906 | * RS_PACING_GT - must be greater than. |
| 907 | * RS_PACING_GEQ - must be greater than or equal. |
| 908 | * RS_PACING_LT - must be less than. |
| 909 | * RS_PACING_SUB_OK - If we don't meet criteria a |
| 910 | * substitute is ok. |
| 911 | */ |
| 912 | int i, matched; |
| 913 | struct tcp_hwrate_limit_table *rte = NULL; |
| 914 | |
| 915 | if ((rs->rs_flags & RS_INT_TBL) && |
| 916 | (rs->rs_rate_cnt >= ALL_HARDWARE_RATES)) { |
| 917 | /* |
| 918 | * Here we don't want to paw thru |
| 919 | * a big table, we have everything |
| 920 | * from 1Meg - 1000Meg in 1Meg increments. |
| 921 | * Use an alternate method to "lookup". |
| 922 | */ |
| 923 | return (tcp_int_find_suitable_rate(rs, bytes_per_sec, flags)); |
| 924 | } |
| 925 | if ((flags & RS_PACING_LT) || |
| 926 | (flags & RS_PACING_EXACT_MATCH)) { |
| 927 | /* |
| 928 | * For exact and less than we go forward through the table. |
| 929 | * This way when we find one larger we stop (exact was a |
| 930 | * toss up). |
| 931 | */ |
| 932 | for (i = rs->rs_lowest_valid, matched = 0; i <= rs->rs_highest_valid; i++) { |
| 933 | if ((flags & RS_PACING_EXACT_MATCH) && |
| 934 | (bytes_per_sec == rs->rs_rlt[i].rate)) { |
| 935 | rte = &rs->rs_rlt[i]; |
| 936 | matched = 1; |
| 937 | break; |
| 938 | } else if ((flags & RS_PACING_LT) && |
| 939 | (bytes_per_sec <= rs->rs_rlt[i].rate)) { |
| 940 | rte = &rs->rs_rlt[i]; |
| 941 | matched = 1; |
| 942 | break; |
| 943 | } |
| 944 | if (bytes_per_sec > rs->rs_rlt[i].rate) |
| 945 | break; |
| 946 | } |
| 947 | if ((matched == 0) && |
| 948 | (flags & RS_PACING_LT) && |
| 949 | (flags & RS_PACING_SUB_OK)) { |
| 950 | /* Kick in a substitute (the lowest) */ |
| 951 | rte = &rs->rs_rlt[rs->rs_lowest_valid]; |
| 952 | } |
| 953 | } else { |
| 954 | /* |
| 955 | * Here we go backward through the table so that we can find |
| 956 | * the one greater in theory faster (but its probably a |
no test coverage detected