Lines Matching refs:db
174 static void bsd_clear(struct bsd_db *db) in bsd_clear() argument
176 db->clear_count++; in bsd_clear()
177 db->max_ent = FIRST - 1; in bsd_clear()
178 db->n_bits = BSD_INIT_BITS; in bsd_clear()
179 db->bytes_out = 0; in bsd_clear()
180 db->in_count = 0; in bsd_clear()
181 db->incomp_count = 0; in bsd_clear()
182 db->ratio = 0; in bsd_clear()
183 db->checkpoint = CHECK_GAP; in bsd_clear()
199 static int bsd_check(struct bsd_db *db) /* 1=output CLEAR */ in bsd_check() argument
203 if (db->in_count >= db->checkpoint) in bsd_check()
206 if (db->in_count >= RATIO_MAX || db->bytes_out >= RATIO_MAX) in bsd_check()
208 db->in_count -= (db->in_count >> 2); in bsd_check()
209 db->bytes_out -= (db->bytes_out >> 2); in bsd_check()
212 db->checkpoint = db->in_count + CHECK_GAP; in bsd_check()
214 if (db->max_ent >= db->maxmaxcode) in bsd_check()
224 new_ratio = db->in_count << RATIO_SCALE_LOG; in bsd_check()
225 if (db->bytes_out != 0) in bsd_check()
227 new_ratio /= db->bytes_out; in bsd_check()
230 if (new_ratio < db->ratio || new_ratio < 1 * RATIO_SCALE) in bsd_check()
232 bsd_clear(db); in bsd_check()
235 db->ratio = new_ratio; in bsd_check()
247 struct bsd_db *db = (struct bsd_db *) state; in bsd_stats() local
249 stats->unc_bytes = db->uncomp_bytes; in bsd_stats()
250 stats->unc_packets = db->uncomp_count; in bsd_stats()
251 stats->comp_bytes = db->comp_bytes; in bsd_stats()
252 stats->comp_packets = db->comp_count; in bsd_stats()
253 stats->inc_bytes = db->incomp_bytes; in bsd_stats()
254 stats->inc_packets = db->incomp_count; in bsd_stats()
255 stats->in_count = db->in_count; in bsd_stats()
256 stats->bytes_out = db->bytes_out; in bsd_stats()
266 struct bsd_db *db = (struct bsd_db *) state; in bsd_reset() local
268 bsd_clear(db); in bsd_reset()
269 db->seqno = 0; in bsd_reset()
270 db->clear_count = 0; in bsd_reset()
278 struct bsd_db *db = (struct bsd_db *) state; in bsd_free() local
280 if (db) { in bsd_free()
284 vfree(db->dict); in bsd_free()
285 db->dict = NULL; in bsd_free()
290 vfree(db->lens); in bsd_free()
291 db->lens = NULL; in bsd_free()
296 kfree(db); in bsd_free()
308 struct bsd_db *db; in bsd_alloc() local
332 db = kzalloc(sizeof(struct bsd_db), GFP_KERNEL); in bsd_alloc()
333 if (!db) in bsd_alloc()
336 db->xmit = data->flags & IPPP_COMP_FLAG_XMIT; in bsd_alloc()
337 decomp = db->xmit ? 0 : 1; in bsd_alloc()
343 db->dict = vmalloc(hsize * sizeof(struct bsd_dict)); in bsd_alloc()
344 if (!db->dict) { in bsd_alloc()
345 bsd_free(db); in bsd_alloc()
354 db->lens = NULL; in bsd_alloc()
356 db->lens = vmalloc((maxmaxcode + 1) * sizeof(db->lens[0])); in bsd_alloc()
357 if (!db->lens) { in bsd_alloc()
358 bsd_free(db); in bsd_alloc()
366 db->totlen = sizeof(struct bsd_db) + (sizeof(struct bsd_dict) * hsize); in bsd_alloc()
367 db->hsize = hsize; in bsd_alloc()
368 db->hshift = hshift; in bsd_alloc()
369 db->maxmaxcode = maxmaxcode; in bsd_alloc()
370 db->maxbits = bits; in bsd_alloc()
372 return (void *)db; in bsd_alloc()
380 struct bsd_db *db = state; in bsd_init() local
389 decomp = db->xmit ? 0 : 1; in bsd_init()
393 || (BSD_NBITS(data->options[0]) != db->maxbits) in bsd_init()
394 || (decomp && db->lens == NULL)) { in bsd_init()
395 …d: %d %d %d %d %lx\n", data->optlen, data->num, data->options[0], decomp, (unsigned long)db->lens); in bsd_init()
401 db->lens[indx] = 1; in bsd_init()
403 indx = db->hsize; in bsd_init()
405 db->dict[indx].codem1 = BADCODEM1; in bsd_init()
406 db->dict[indx].cptr = 0; in bsd_init()
409 db->unit = unit; in bsd_init()
410 db->mru = 0; in bsd_init()
412 db->debug = 1; in bsd_init()
414 bsd_reset(db, 0, 0, NULL, 0, NULL); in bsd_init()
427 static unsigned short *lens_ptr(struct bsd_db *db, int idx) in lens_ptr() argument
429 if ((unsigned int) idx > (unsigned int) db->maxmaxcode) { in lens_ptr()
433 return lens_ptrx(db, idx); in lens_ptr()
436 static struct bsd_dict *dict_ptr(struct bsd_db *db, int idx) in dict_ptr() argument
438 if ((unsigned int) idx >= (unsigned int) db->hsize) { in dict_ptr()
442 return dict_ptrx(db, idx); in dict_ptr()
446 #define lens_ptr(db, idx) lens_ptrx(db, idx) argument
447 #define dict_ptr(db, idx) dict_ptrx(db, idx) argument
455 struct bsd_db *db; in bsd_compress() local
492 db = (struct bsd_db *) state; in bsd_compress()
493 hshift = db->hshift; in bsd_compress()
494 max_ent = db->max_ent; in bsd_compress()
495 n_bits = db->n_bits; in bsd_compress()
505 v[0] = db->seqno >> 8; in bsd_compress()
506 v[1] = db->seqno; in bsd_compress()
515 dictp = dict_ptr(db, hval); in bsd_compress()
531 if (hval >= db->hsize) in bsd_compress()
532 hval -= db->hsize; in bsd_compress()
533 dictp = dict_ptr(db, hval); in bsd_compress()
545 if (max_ent < db->maxmaxcode) { in bsd_compress()
552 db->n_bits = ++n_bits; in bsd_compress()
560 dictp2 = dict_ptr(db, max_ent + 1); in bsd_compress()
562 dictp3 = dict_ptr(db, indx); in bsd_compress()
570 db->max_ent = ++max_ent; in bsd_compress()
572 if (db->lens) { in bsd_compress()
573 unsigned short *len1 = lens_ptr(db, max_ent); in bsd_compress()
574 unsigned short *len2 = lens_ptr(db, ent); in bsd_compress()
584 db->bytes_out += skb_out->len; /* Do not count bytes from here */ in bsd_compress()
585 db->uncomp_bytes += isize; in bsd_compress()
586 db->in_count += isize; in bsd_compress()
587 ++db->uncomp_count; in bsd_compress()
588 ++db->seqno; in bsd_compress()
591 ++db->bytes_out; /* must be set before calling bsd_check */ in bsd_compress()
597 if (bsd_check(db)) in bsd_compress()
611 if (max_ent >= mxcode && max_ent < db->maxmaxcode) in bsd_compress()
612 db->n_bits++; in bsd_compress()
616 ++db->incomp_count; in bsd_compress()
617 db->incomp_bytes += isize; in bsd_compress()
622 ++db->comp_count; in bsd_compress()
623 db->comp_bytes += skb_out->len; in bsd_compress()
644 struct bsd_db *db; in bsd_decompress() local
660 db = (struct bsd_db *) state; in bsd_decompress()
661 max_ent = db->max_ent; in bsd_decompress()
664 n_bits = db->n_bits; in bsd_decompress()
689 if (seq != db->seqno) { in bsd_decompress()
690 if (db->debug) { in bsd_decompress()
692 db->unit, seq, db->seqno - 1); in bsd_decompress()
697 ++db->seqno; in bsd_decompress()
698 db->bytes_out += ilen; in bsd_decompress()
714 db->in_count += (skb_out->len - 1); /* don't count the header */ in bsd_decompress()
739 if (db->debug) in bsd_decompress()
740 printk(KERN_DEBUG "bsd_decomp%d: bad CLEAR\n", db->unit); in bsd_decompress()
743 bsd_clear(db); in bsd_decompress()
747 if ((incode > max_ent + 2) || (incode > db->maxmaxcode) in bsd_decompress()
749 if (db->debug) { in bsd_decompress()
751 db->unit, incode, oldcode); in bsd_decompress()
753 max_ent, skb_out->len, db->seqno); in bsd_decompress()
767 codelen = *(lens_ptr(db, finchar)); in bsd_decompress()
769 if (db->debug) { in bsd_decompress()
770 printk(KERN_DEBUG "bsd_decomp%d: ran out of mru\n", db->unit); in bsd_decompress()
786 struct bsd_dict *dictp2 = dict_ptr(db, finchar); in bsd_decompress()
788 dictp = dict_ptr(db, dictp2->cptr); in bsd_decompress()
793 printk(KERN_ERR "bsd_decomp%d: fell off end of chain ", db->unit); in bsd_decompress()
797 printk(KERN_ERR "bsd_decomp%d: bad code chain 0x%x finchar=0x%x ", db->unit, incode, finchar); in bsd_decompress()
815 …printk(KERN_ERR "bsd_decomp%d: short by %d after code 0x%x, max_ent=0x%x\n", db->unit, codelen, in… in bsd_decompress()
828 if (oldcode != CLEAR && max_ent < db->maxmaxcode) { in bsd_decompress()
835 hval = BSD_HASH(oldcode, finchar, db->hshift); in bsd_decompress()
836 dictp = dict_ptr(db, hval); in bsd_decompress()
843 if (hval >= db->hsize) in bsd_decompress()
844 hval -= db->hsize; in bsd_decompress()
845 dictp = dict_ptr(db, hval); in bsd_decompress()
854 dictp2 = dict_ptr(db, max_ent + 1); in bsd_decompress()
856 dictp3 = dict_ptr(db, indx); in bsd_decompress()
864 db->max_ent = ++max_ent; in bsd_decompress()
867 lens1 = lens_ptr(db, max_ent); in bsd_decompress()
868 lens2 = lens_ptr(db, oldcode); in bsd_decompress()
872 if (max_ent >= MAXCODE(n_bits) && max_ent < db->maxmaxcode) { in bsd_decompress()
873 db->n_bits = ++n_bits; in bsd_decompress()
880 ++db->comp_count; in bsd_decompress()
881 ++db->uncomp_count; in bsd_decompress()
882 db->comp_bytes += skb_in->len - BSD_OVHD; in bsd_decompress()
883 db->uncomp_bytes += skb_out->len; in bsd_decompress()
885 if (bsd_check(db)) { in bsd_decompress()
886 if (db->debug) in bsd_decompress()
888 db->unit, db->seqno - 1); in bsd_decompress()