Lines Matching defs:mlc

87 static void hil_mlc_clear_di_map(hil_mlc *mlc, int val)
92 mlc->di_map[j] = -1;
95 static void hil_mlc_clear_di_scratch(hil_mlc *mlc)
97 memset(&mlc->di_scratch, 0, sizeof(mlc->di_scratch));
100 static void hil_mlc_copy_di_scratch(hil_mlc *mlc, int idx)
102 memcpy(&mlc->di[idx], &mlc->di_scratch, sizeof(mlc->di_scratch));
105 static int hil_mlc_match_di_scratch(hil_mlc *mlc)
114 if (mlc->di_map[j] == idx)
120 if (!memcmp(mlc->di + idx, &mlc->di_scratch,
121 sizeof(mlc->di_scratch)))
127 static int hil_mlc_find_free_di(hil_mlc *mlc)
138 if (mlc->di_map[j] == idx)
148 static inline void hil_mlc_clean_serio_map(hil_mlc *mlc)
156 if (mlc->di_map[j] == idx)
160 mlc->serio_map[idx].di_revmap = -1;
164 static void hil_mlc_send_polls(hil_mlc *mlc)
171 did = (mlc->ipacket[0] & HIL_PKT_ADDR_MASK) >> 8;
172 serio = did ? mlc->serio[mlc->di_map[did - 1]] : NULL;
175 while (mlc->icount < 15 - i) {
178 p = mlc->ipacket[i];
188 serio = did ? mlc->serio[mlc->di_map[did-1]] : NULL;
240 static int hilse_match(hil_mlc *mlc, int unused)
244 rc = hil_mlc_match_di_scratch(mlc);
246 rc = hil_mlc_find_free_di(mlc);
253 hil_mlc_copy_di_scratch(mlc, rc);
254 mlc->di_map[mlc->ddi] = rc;
255 mlc->serio_map[rc].di_revmap = mlc->ddi;
256 hil_mlc_clean_serio_map(mlc);
257 serio_rescan(mlc->serio[rc]);
261 mlc->di_map[mlc->ddi] = rc;
265 mlc->serio_map[rc].di_revmap = mlc->ddi;
266 hil_mlc_clean_serio_map(mlc);
275 static int hilse_init_lcv(hil_mlc *mlc, int unused)
279 if (mlc->lcv && (now - mlc->lcv_time) < 5)
282 mlc->lcv_time = now;
283 mlc->lcv = 0;
288 static int hilse_inc_lcv(hil_mlc *mlc, int lim)
290 return mlc->lcv++ >= lim ? -1 : 0;
294 static int hilse_set_lcv(hil_mlc *mlc, int val)
296 mlc->lcv = val;
303 static int hilse_set_ddi(hil_mlc *mlc, int val)
305 mlc->ddi = val;
306 hil_mlc_clear_di_map(mlc, val + 1);
311 static int hilse_dec_ddi(hil_mlc *mlc, int unused)
313 mlc->ddi--;
314 if (mlc->ddi <= -1) {
315 mlc->ddi = -1;
316 hil_mlc_clear_di_map(mlc, 0);
319 hil_mlc_clear_di_map(mlc, mlc->ddi + 1);
324 static int hilse_inc_ddi(hil_mlc *mlc, int unused)
326 BUG_ON(mlc->ddi >= 6);
327 mlc->ddi++;
332 static int hilse_take_idd(hil_mlc *mlc, int unused)
341 if (mlc->ipacket[0] & HIL_PKT_CMD)
346 if (((mlc->ipacket[i] & HIL_PKT_ADDR_MASK) ==
347 (mlc->ipacket[0] & HIL_PKT_ADDR_MASK)) &&
348 (mlc->ipacket[i] & HIL_PKT_CMD) &&
349 ((mlc->ipacket[i] & HIL_PKT_DATA_MASK) == HIL_CMD_IDD))
357 if (mlc->ipacket[i])
364 mlc->di_scratch.idd[i] =
365 mlc->ipacket[i] & HIL_PKT_DATA_MASK;
368 if (mlc->di_scratch.idd[1] & HIL_IDD_HEADER_RSC)
371 if (mlc->di_scratch.idd[1] & HIL_IDD_HEADER_EXD)
377 mlc->ddi--;
382 static int hilse_take_rsc(hil_mlc *mlc, int unused)
387 mlc->di_scratch.rsc[i] =
388 mlc->ipacket[i] & HIL_PKT_DATA_MASK;
391 if (mlc->di_scratch.idd[1] & HIL_IDD_HEADER_EXD)
397 static int hilse_take_exd(hil_mlc *mlc, int unused)
402 mlc->di_scratch.exd[i] =
403 mlc->ipacket[i] & HIL_PKT_DATA_MASK;
406 if (mlc->di_scratch.exd[0] & HIL_EXD_HEADER_RNM)
412 static int hilse_take_rnm(hil_mlc *mlc, int unused)
417 mlc->di_scratch.rnm[i] =
418 mlc->ipacket[i] & HIL_PKT_DATA_MASK;
421 mlc->di_scratch.rnm);
426 static int hilse_operate(hil_mlc *mlc, int repoll)
429 if (mlc->opercnt == 0)
431 mlc->opercnt = 1;
433 hil_mlc_send_polls(mlc);
438 mlc->opercnt = 0;
583 static inline void hilse_setup_input(hil_mlc *mlc, const struct hilse_node *node)
588 mlc->imatch = node->object.packet;
589 mlc->imatch |= ((mlc->ddi + 2) << HIL_PKT_ADDR_SHIFT);
592 mlc->imatch = node->object.packet;
593 mlc->imatch |= ((mlc->ddi + 1) << HIL_PKT_ADDR_SHIFT);
596 mlc->imatch = node->object.packet;
599 mlc->imatch = 0;
604 mlc->istarted = 1;
605 mlc->intimeout = usecs_to_jiffies(node->arg);
606 mlc->instart = jiffies;
607 mlc->icount = 15;
608 memset(mlc->ipacket, 0, 16 * sizeof(hil_packet));
609 BUG_ON(down_trylock(&mlc->isem));
617 static int hilse_donode(hil_mlc *mlc)
625 if (mlc->seidx && mlc->seidx != seidx &&
626 mlc->seidx != 41 && mlc->seidx != 42 && mlc->seidx != 43) {
627 printk(KERN_DEBUG PREFIX "z%i \n {%i}", doze, mlc->seidx);
631 seidx = mlc->seidx;
633 node = hil_mlc_se + mlc->seidx;
641 rc = node->object.func(mlc, node->arg);
653 write_lock_irqsave(&mlc->lock, flags);
654 rc = mlc->in(mlc, node->arg);
658 write_unlock_irqrestore(&mlc->lock, flags);
667 mlc->istarted = 0;
668 write_unlock_irqrestore(&mlc->lock, flags);
672 write_lock_irqsave(&mlc->lock, flags);
674 pack |= ((mlc->ddi + 1) << HIL_PKT_ADDR_SHIFT);
678 write_lock_irqsave(&mlc->lock, flags);
680 pack |= ((mlc->ddi + 2) << HIL_PKT_ADDR_SHIFT);
684 write_lock_irqsave(&mlc->lock, flags);
687 if (!mlc->istarted) {
690 hilse_setup_input(mlc, node + 1);
693 write_unlock_irqrestore(&mlc->lock, flags);
695 if (down_trylock(&mlc->osem)) {
699 up(&mlc->osem);
701 write_lock_irqsave(&mlc->lock, flags);
702 if (!mlc->ostarted) {
703 mlc->ostarted = 1;
704 mlc->opacket = pack;
705 rc = mlc->out(mlc);
707 write_unlock_irqrestore(&mlc->lock, flags);
714 mlc->ostarted = 0;
715 mlc->instart = jiffies;
716 write_unlock_irqrestore(&mlc->lock, flags);
721 write_lock_irqsave(&mlc->lock, flags);
722 rc = mlc->cts(mlc);
724 write_unlock_irqrestore(&mlc->lock, flags);
746 if (time_after(now, mlc->instart + mlc->intimeout))
748 mod_timer(&hil_mlcs_kicker, mlc->instart + mlc->intimeout);
756 mlc->seidx += nextidx & HILSEN_MASK;
758 mlc->seidx -= nextidx & HILSEN_MASK;
760 mlc->seidx = nextidx & HILSEN_MASK;
775 struct hil_mlc *mlc = list_entry(tmp, hil_mlc, list);
776 while (hilse_donode(mlc) == 0) {
778 if (mlc->seidx != 41 &&
779 mlc->seidx != 42 &&
780 mlc->seidx != 43)
810 struct hil_mlc *mlc;
817 mlc = map->mlc;
818 BUG_ON(mlc == NULL);
820 mlc->serio_opacket[map->didx] |=
821 ((hil_packet)c) << (8 * (3 - mlc->serio_oidx[map->didx]));
823 if (mlc->serio_oidx[map->didx] >= 3) {
825 if (!(mlc->serio_opacket[map->didx] & HIL_PKT_CMD))
827 switch (mlc->serio_opacket[map->didx] & HIL_PKT_DATA_MASK) {
829 idx = mlc->di[map->didx].idd;
832 idx = mlc->di[map->didx].rsc;
835 idx = mlc->di[map->didx].exd;
838 idx = mlc->di[map->didx].rnm;
843 mlc->serio_oidx[map->didx] = 0;
844 mlc->serio_opacket[map->didx] = 0;
847 mlc->serio_oidx[map->didx]++;
869 mlc->serio_oidx[map->didx] = 0;
870 mlc->serio_opacket[map->didx] = 0;
878 struct hil_mlc *mlc;
886 mlc = map->mlc;
887 BUG_ON(mlc == NULL);
895 struct hil_mlc *mlc;
900 mlc = map->mlc;
901 BUG_ON(mlc == NULL);
915 int hil_mlc_register(hil_mlc *mlc)
920 BUG_ON(mlc == NULL);
922 mlc->istarted = 0;
923 mlc->ostarted = 0;
925 rwlock_init(&mlc->lock);
926 sema_init(&mlc->osem, 1);
928 sema_init(&mlc->isem, 1);
929 mlc->icount = -1;
930 mlc->imatch = 0;
932 mlc->opercnt = 0;
934 sema_init(&(mlc->csem), 0);
936 hil_mlc_clear_di_scratch(mlc);
937 hil_mlc_clear_di_map(mlc, 0);
940 hil_mlc_copy_di_scratch(mlc, i);
942 mlc->serio[i] = mlc_serio;
943 if (!mlc->serio[i]) {
945 kfree(mlc->serio[i]);
955 mlc_serio->port_data = &(mlc->serio_map[i]);
956 mlc->serio_map[i].mlc = mlc;
957 mlc->serio_map[i].didx = i;
958 mlc->serio_map[i].di_revmap = -1;
959 mlc->serio_opacket[i] = 0;
960 mlc->serio_oidx[i] = 0;
964 mlc->tasklet = &hil_mlcs_tasklet;
967 list_add_tail(&mlc->list, &hil_mlcs);
968 mlc->seidx = HILSEN_START;
975 int hil_mlc_unregister(hil_mlc *mlc)
981 BUG_ON(mlc == NULL);
985 if (list_entry(tmp, hil_mlc, list) == mlc)
998 serio_unregister_port(mlc->serio[i]);
999 mlc->serio[i] = NULL;