Lines Matching refs:dev

46 #define reader_to_dev(x)	(&x->p_dev->dev)
145 #define ZERO_DEV(dev) \
146 memset(&dev->atr_csum,0, \
204 #define ATRLENCK(dev,pos) \
205 if (pos>=dev->atr_len || pos>=MAX_ATR) \
319 static int parse_atr(struct cm4000_dev *dev)
325 DEBUGP(3, dev, "-> parse_atr: dev->atr_len = %i\n", dev->atr_len);
327 if (dev->atr_len < 3) {
328 DEBUGP(5, dev, "parse_atr: atr_len < 3\n");
332 if (dev->atr[0] == 0x3f)
333 set_bit(IS_INVREV, &dev->flags);
335 clear_bit(IS_INVREV, &dev->flags);
338 ch = dev->atr[1];
339 dev->proto = 0; /* XXX PROTO */
341 dev->ta1 = 0x11; /* defaults to 9600 baud */
345 dev->ta1 = dev->atr[2];
346 DEBUGP(5, dev, "Card says FiDi is 0x%.2x\n", dev->ta1);
349 dev->ta1 = 0x11;
353 DEBUGP(5, dev, "Yi=%.2x\n", ch & 0xf0);
358 /* ATRLENCK(dev,ix); */
360 ch = dev->atr[ix];
363 DEBUGP(5, dev, "card is capable of T=1\n");
366 DEBUGP(5, dev, "card is capable of T=0\n");
372 DEBUGP(5, dev, "ix=%d noHist=%d any_t1=%d\n",
373 ix, dev->atr[1] & 15, any_t1);
374 if (ix + 1 + (dev->atr[1] & 0x0f) + any_t1 != dev->atr_len) {
375 DEBUGP(5, dev, "length error\n");
379 set_bit(IS_ANY_T0, &dev->flags);
382 dev->atr_csum = 0;
384 for (i = 1; i < dev->atr_len; i++)
385 dev->atr_csum ^= dev->atr[i];
386 if (dev->atr_csum) {
387 set_bit(IS_BAD_CSUM, &dev->flags);
388 DEBUGP(5, dev, "bad checksum\n");
393 dev->proto = 1; /* XXX PROTO */
394 set_bit(IS_ANY_T1, &dev->flags);
420 static void set_cardparameter(struct cm4000_dev *dev)
423 unsigned int iobase = dev->p_dev->resource[0]->start;
426 DEBUGP(3, dev, "-> set_cardparameter\n");
428 dev->flags1 = dev->flags1 | (((dev->baudv - 1) & 0x0100) >> 8);
429 xoutb(dev->flags1, REG_FLAGS1(iobase));
430 DEBUGP(5, dev, "flags1 = 0x%02x\n", dev->flags1);
433 xoutb((unsigned char)((dev->baudv - 1) & 0xFF), REG_BAUDRATE(iobase));
435 DEBUGP(5, dev, "baudv = %i -> write 0x%02x\n", dev->baudv,
436 ((dev->baudv - 1) & 0xFF));
440 if (!memcmp(dev->atr, card_fixups[i].atr,
446 DEBUGP(3, dev, "<- set_cardparameter\n");
449 static int set_protocol(struct cm4000_dev *dev, struct ptsreq *ptsreq)
456 unsigned int iobase = dev->p_dev->resource[0]->start;
460 DEBUGP(3, dev, "-> set_protocol\n");
461 DEBUGP(5, dev, "ptsreq->Protocol = 0x%.8x, ptsreq->Flags=0x%.8x, "
468 dev->pts[0] = 0xff;
469 dev->pts[1] = 0x00;
472 dev->pts[1]++;
473 dev->proto = dev->pts[1]; /* Set new protocol */
474 dev->pts[1] = (0x01 << 4) | (dev->pts[1]);
477 DEBUGP(5, dev, "Ta(1) from ATR is 0x%.2x\n", dev->ta1);
479 dev->pts[2] = fi_di_table[dev->ta1 & 0x0F][(dev->ta1 >> 4) & 0x0F];
482 dev->pts[3] = dev->pts[0] ^ dev->pts[1] ^ dev->pts[2];
484 DEBUGP(5, dev, "pts0=%.2x, pts1=%.2x, pts2=%.2x, pts3=%.2x\n",
485 dev->pts[0], dev->pts[1], dev->pts[2], dev->pts[3]);
488 if (test_bit(IS_INVREV, &dev->flags))
489 str_invert_revert(dev->pts, 4);
495 DEBUGP(5, dev, "Enable access to the messages buffer\n");
496 dev->flags1 = 0x20 /* T_Active */
497 | (test_bit(IS_INVREV, &dev->flags) ? 0x02 : 0x00) /* inv parity */
498 | ((dev->baudv >> 8) & 0x01); /* MSB-baud */
499 xoutb(dev->flags1, REG_FLAGS1(iobase));
501 DEBUGP(5, dev, "Enable message buffer -> flags1 = 0x%.2x\n",
502 dev->flags1);
505 DEBUGP(5, dev, "Write challenge to buffer: ");
508 xoutb(dev->pts[i], REG_BUF_DATA(iobase)); /* buf data */
510 pr_debug("0x%.2x ", dev->pts[i]);
518 DEBUGP(5, dev, "Set number of bytes to write\n");
526 DEBUGP(5, dev, "Waiting for NumRecBytes getting valid\n");
530 DEBUGP(5, dev, "NumRecBytes is valid\n");
536 DEBUGP(5, dev, "Timeout waiting for NumRecBytes getting "
542 DEBUGP(5, dev, "Reading NumRecBytes\n");
546 DEBUGP(2, dev, "NumRecBytes = %i\n", num_bytes_read);
561 DEBUGP(5, dev, "Timeout reading num_bytes_read\n");
566 DEBUGP(5, dev, "Reset the CARDMAN CONTROLLER\n");
570 DEBUGP(5, dev, "Read PPS reply\n");
577 DEBUGP(2, dev, "PTSreply: ");
584 DEBUGP(5, dev, "Clear Tactive in Flags1\n");
588 if ((dev->pts[0] == pts_reply[0]) &&
589 (dev->pts[1] == pts_reply[1]) &&
590 (dev->pts[2] == pts_reply[2]) && (dev->pts[3] == pts_reply[3])) {
592 dev->baudv = calc_baudv(dev->pts[2]);
593 set_cardparameter(dev);
594 } else if ((dev->pts[0] == pts_reply[0]) &&
595 ((dev->pts[1] & 0xef) == pts_reply[1]) &&
598 dev->baudv = calc_baudv(0x11);
599 set_cardparameter(dev);
604 DEBUGP(3, dev, "<- set_protocol\n");
608 static int io_detect_cm4000(unsigned int iobase, struct cm4000_dev *dev)
613 clear_bit(IS_ATR_VALID, &dev->flags);
614 set_bit(IS_CMM_ABSENT, &dev->flags);
618 xoutb(dev->flags1 | 0x40, REG_FLAGS1(iobase));
620 clear_bit(IS_ATR_VALID, &dev->flags);
621 set_bit(IS_CMM_ABSENT, &dev->flags);
625 xoutb(dev->flags1, REG_FLAGS1(iobase));
629 static void terminate_monitor(struct cm4000_dev *dev)
635 DEBUGP(3, dev, "-> terminate_monitor\n");
636 wait_event_interruptible(dev->devq,
638 (void *)&dev->flags));
645 DEBUGP(5, dev, "Now allow last cycle of monitor!\n");
646 while (test_bit(LOCK_MONITOR, (void *)&dev->flags))
649 DEBUGP(5, dev, "Delete timer\n");
650 del_timer_sync(&dev->timer);
652 dev->monitor_running = 0;
655 DEBUGP(3, dev, "<- terminate_monitor\n");
668 struct cm4000_dev *dev = from_timer(dev, t, timer);
669 unsigned int iobase = dev->p_dev->resource[0]->start;
674 DEBUGP(7, dev, "-> monitor_card\n");
677 if (test_and_set_bit(LOCK_MONITOR, &dev->flags)) {
678 DEBUGP(4, dev, "About to stop monitor\n");
680 dev->rlen =
681 dev->rpos =
682 dev->atr_csum = dev->atr_len_retry = dev->cwarn = 0;
683 dev->mstate = M_FETCH_ATR;
684 clear_bit(LOCK_MONITOR, &dev->flags);
686 wake_up_interruptible(&dev->devq);
687 DEBUGP(2, dev, "<- monitor_card (we are done now)\n");
692 if (test_and_set_bit(LOCK_IO, (void *)&dev->flags)) {
693 DEBUGP(4, dev, "Couldn't get IO lock\n");
698 dev->flags0 = xinb(REG_FLAGS0(iobase));
699 DEBUGP(7, dev, "dev->flags0 = 0x%2x\n", dev->flags0);
700 DEBUGP(7, dev, "smartcard present: %s\n",
701 dev->flags0 & 1 ? "yes" : "no");
702 DEBUGP(7, dev, "cardman present: %s\n",
703 dev->flags0 == 0xff ? "no" : "yes");
705 if ((dev->flags0 & 1) == 0 /* no smartcard inserted */
706 || dev->flags0 == 0xff) { /* no cardman inserted */
708 dev->rlen =
709 dev->rpos =
710 dev->atr_csum = dev->atr_len_retry = dev->cwarn = 0;
711 dev->mstate = M_FETCH_ATR;
713 dev->flags &= 0x000000ff; /* only keep IO and MONITOR locks */
715 if (dev->flags0 == 0xff) {
716 DEBUGP(4, dev, "set IS_CMM_ABSENT bit\n");
717 set_bit(IS_CMM_ABSENT, &dev->flags);
718 } else if (test_bit(IS_CMM_ABSENT, &dev->flags)) {
719 DEBUGP(4, dev, "clear IS_CMM_ABSENT bit "
721 clear_bit(IS_CMM_ABSENT, &dev->flags);
725 } else if ((dev->flags0 & 1) && test_bit(IS_CMM_ABSENT, &dev->flags)) {
728 DEBUGP(4, dev, "clear IS_CMM_ABSENT bit (card is inserted)\n");
729 clear_bit(IS_CMM_ABSENT, &dev->flags);
732 if (test_bit(IS_ATR_VALID, &dev->flags) == 1) {
733 DEBUGP(7, dev, "believe ATR is already valid (do nothing)\n");
737 switch (dev->mstate) {
741 DEBUGP(4, dev, "M_CARDOFF\n");
745 dev->mdelay = T_10MSEC;
753 dev->rlen =
754 dev->rpos =
755 dev->atr_csum =
756 dev->atr_len_retry = dev->cwarn = 0;
757 dev->mstate = M_FETCH_ATR;
760 dev->mdelay = T_50MSEC;
765 DEBUGP(4, dev, "M_FETCH_ATR\n");
767 DEBUGP(4, dev, "Reset BAUDV to 9600\n");
768 dev->baudv = 0x173; /* 9600 */
774 xoutb(dev->flags0 & 2 ? 0x46 : 0x44, REG_FLAGS0(iobase));
775 dev->mdelay = T_40MSEC;
776 dev->mstate = M_TIMEOUT_WAIT;
779 DEBUGP(4, dev, "M_TIMEOUT_WAIT\n");
781 io_read_num_rec_bytes(iobase, &dev->atr_len);
782 dev->mdelay = T_10MSEC;
783 dev->mstate = M_READ_ATR_LEN;
786 DEBUGP(4, dev, "M_READ_ATR_LEN\n");
791 if (dev->atr_len == io_read_num_rec_bytes(iobase, &s)) {
792 if (dev->atr_len_retry++ >= MAX_ATR_LEN_RETRY) { /* + XX msec */
793 dev->mdelay = T_10MSEC;
794 dev->mstate = M_READ_ATR;
797 dev->atr_len = s;
798 dev->atr_len_retry = 0; /* set new timeout */
801 DEBUGP(4, dev, "Current ATR_LEN = %i\n", dev->atr_len);
804 DEBUGP(4, dev, "M_READ_ATR\n");
806 for (i = 0; i < dev->atr_len; i++) {
808 dev->atr[i] = inb(REG_BUF_DATA(iobase));
811 DEBUGP(4, dev, "Deactivate T_Active flags\n");
812 dev->flags1 = 0x01;
813 xoutb(dev->flags1, REG_FLAGS1(iobase));
816 set_bit(IS_ATR_PRESENT, &dev->flags);
817 if (dev->atr[0] == 0x03)
818 str_invert_revert(dev->atr, dev->atr_len);
819 atrc = parse_atr(dev);
821 dev->mdelay = 0;
822 dev->mstate = M_BAD_CARD;
824 dev->mdelay = T_50MSEC;
825 dev->mstate = M_ATR_PRESENT;
826 set_bit(IS_ATR_VALID, &dev->flags);
829 if (test_bit(IS_ATR_VALID, &dev->flags) == 1) {
830 DEBUGP(4, dev, "monitor_card: ATR valid\n");
833 if ((test_bit(IS_AUTOPPS_ACT, &dev->flags) == 0) &&
834 (dev->ta1 != 0x11) &&
835 !(test_bit(IS_ANY_T0, &dev->flags) &&
836 test_bit(IS_ANY_T1, &dev->flags))) {
837 DEBUGP(4, dev, "Perform AUTOPPS\n");
838 set_bit(IS_AUTOPPS_ACT, &dev->flags);
839 ptsreq.protocol = (0x01 << dev->proto);
844 if (set_protocol(dev, &ptsreq) == 0) {
845 DEBUGP(4, dev, "AUTOPPS ret SUCC\n");
846 clear_bit(IS_AUTOPPS_ACT, &dev->flags);
847 wake_up_interruptible(&dev->atrq);
849 DEBUGP(4, dev, "AUTOPPS failed: "
852 clear_bit(IS_ATR_PRESENT, &dev->flags);
853 clear_bit(IS_ATR_VALID, &dev->flags);
854 dev->rlen =
855 dev->rpos =
856 dev->atr_csum =
857 dev->atr_len_retry = dev->cwarn = 0;
858 dev->mstate = M_FETCH_ATR;
860 dev->mdelay = T_50MSEC;
865 set_cardparameter(dev);
866 if (test_bit(IS_AUTOPPS_ACT, &dev->flags) == 1)
867 DEBUGP(4, dev, "AUTOPPS already active "
869 if (dev->ta1 == 0x11)
870 DEBUGP(4, dev, "No AUTOPPS necessary "
872 if (test_bit(IS_ANY_T0, &dev->flags)
873 && test_bit(IS_ANY_T1, &dev->flags))
874 DEBUGP(4, dev, "Do NOT perform AUTOPPS "
876 clear_bit(IS_AUTOPPS_ACT, &dev->flags);
877 wake_up_interruptible(&dev->atrq);
880 DEBUGP(4, dev, "ATR invalid\n");
881 wake_up_interruptible(&dev->atrq);
885 DEBUGP(4, dev, "M_BAD_CARD\n");
887 if (dev->cwarn == 0 || dev->cwarn == 10) {
888 set_bit(IS_BAD_CARD, &dev->flags);
889 dev_warn(&dev->p_dev->dev, MODULE_NAME ": ");
890 if (test_bit(IS_BAD_CSUM, &dev->flags)) {
891 DEBUGP(4, dev, "ATR checksum (0x%.2x, should "
892 "be zero) failed\n", dev->atr_csum);
895 else if (test_bit(IS_BAD_LENGTH, &dev->flags)) {
896 DEBUGP(4, dev, "ATR length error\n");
898 DEBUGP(4, dev, "card damaged or wrong way "
902 dev->cwarn = 0;
903 wake_up_interruptible(&dev->atrq); /* wake open */
905 dev->cwarn++;
906 dev->mdelay = T_100MSEC;
907 dev->mstate = M_FETCH_ATR;
910 DEBUGP(7, dev, "Unknown action\n");
915 DEBUGP(7, dev, "release_io\n");
916 clear_bit(LOCK_IO, &dev->flags);
917 wake_up_interruptible(&dev->ioq); /* whoever needs IO */
920 DEBUGP(7, dev, "<- monitor_card (returns with timer)\n");
921 mod_timer(&dev->timer, jiffies + dev->mdelay);
922 clear_bit(LOCK_MONITOR, &dev->flags);
930 struct cm4000_dev *dev = filp->private_data;
931 unsigned int iobase = dev->p_dev->resource[0]->start;
935 DEBUGP(2, dev, "-> cmm_read(%s,%d)\n", current->comm, current->pid);
940 if (!pcmcia_dev_present(dev->p_dev) || /* device removed */
941 test_bit(IS_CMM_ABSENT, &dev->flags))
944 if (test_bit(IS_BAD_CSUM, &dev->flags))
949 (dev->atrq,
951 || (test_bit(IS_ATR_PRESENT, (void *)&dev->flags) != 0)))) {
957 if (test_bit(IS_ATR_VALID, &dev->flags) == 0)
962 (dev->readq,
963 ((filp->f_flags & O_NONBLOCK) || (dev->rpos < dev->rlen)))) {
971 (dev->ioq,
973 || (test_and_set_bit(LOCK_IO, (void *)&dev->flags) == 0)))) {
980 dev->flags0 = inb(REG_FLAGS0(iobase));
981 if ((dev->flags0 & 1) == 0 /* no smartcard inserted */
982 || dev->flags0 == 0xff) { /* no cardman inserted */
983 clear_bit(IS_ATR_VALID, &dev->flags);
984 if (dev->flags0 & 1) {
985 set_bit(IS_CMM_ABSENT, &dev->flags);
993 DEBUGP(4, dev, "begin read answer\n");
994 j = min(count, (size_t)(dev->rlen - dev->rpos));
995 k = dev->rpos;
998 DEBUGP(4, dev, "read1 j=%d\n", j);
1001 dev->rbuf[i] = xinb(REG_BUF_DATA(iobase));
1003 j = min(count, (size_t)(dev->rlen - dev->rpos));
1005 DEBUGP(4, dev, "read2 j=%d\n", j);
1006 dev->flags1 |= 0x10; /* MSB buf addr set */
1007 xoutb(dev->flags1, REG_FLAGS1(iobase));
1010 dev->rbuf[i] = xinb(REG_BUF_DATA(iobase));
1014 if (dev->proto == 0 && count > dev->rlen - dev->rpos && i) {
1015 DEBUGP(4, dev, "T=0 and count > buffer\n");
1016 dev->rbuf[i] = dev->rbuf[i - 1];
1017 dev->rbuf[i - 1] = dev->procbyte;
1022 dev->rpos = dev->rlen + 1;
1025 DEBUGP(4, dev, "Clear T1Active\n");
1026 dev->flags1 &= 0xdf;
1027 xoutb(dev->flags1, REG_FLAGS1(iobase));
1031 if (!io_detect_cm4000(iobase, dev)) {
1036 if (test_bit(IS_INVREV, &dev->flags) && count > 0)
1037 str_invert_revert(dev->rbuf, count);
1039 if (copy_to_user(buf, dev->rbuf, count))
1043 clear_bit(LOCK_IO, &dev->flags);
1044 wake_up_interruptible(&dev->ioq);
1046 DEBUGP(2, dev, "<- cmm_read returns: rc = %zi\n",
1054 struct cm4000_dev *dev = filp->private_data;
1055 unsigned int iobase = dev->p_dev->resource[0]->start;
1065 DEBUGP(2, dev, "-> cmm_write(%s,%d)\n", current->comm, current->pid);
1070 if (dev->proto == 0 && count < 4) {
1072 DEBUGP(4, dev, "T0 short write\n");
1078 sendT0 = dev->proto ? 0 : nr > 5 ? 0x08 : 0;
1080 if (!pcmcia_dev_present(dev->p_dev) || /* device removed */
1081 test_bit(IS_CMM_ABSENT, &dev->flags))
1084 if (test_bit(IS_BAD_CSUM, &dev->flags)) {
1085 DEBUGP(4, dev, "bad csum\n");
1101 (dev->atrq,
1103 || (test_bit(IS_ATR_PRESENT, (void *)&dev->flags) != 0)))) {
1109 if (test_bit(IS_ATR_VALID, &dev->flags) == 0) { /* invalid atr */
1110 DEBUGP(4, dev, "invalid ATR\n");
1116 (dev->ioq,
1118 || (test_and_set_bit(LOCK_IO, (void *)&dev->flags) == 0)))) {
1124 if (copy_from_user(dev->sbuf, buf, ((count > 512) ? 512 : count)))
1128 dev->flags0 = inb(REG_FLAGS0(iobase));
1129 if ((dev->flags0 & 1) == 0 /* no smartcard inserted */
1130 || dev->flags0 == 0xff) { /* no cardman inserted */
1131 clear_bit(IS_ATR_VALID, &dev->flags);
1132 if (dev->flags0 & 1) {
1133 set_bit(IS_CMM_ABSENT, &dev->flags);
1136 DEBUGP(4, dev, "IO error\n");
1144 if (!io_detect_cm4000(iobase, dev)) {
1150 dev->flags1 |= (sendT0);
1152 set_cardparameter(dev);
1157 dev->flags1 = 0x20 /* T_Active */
1159 | (test_bit(IS_INVREV, &dev->flags) ? 2 : 0)/* inverse parity */
1160 | (((dev->baudv - 1) & 0x0100) >> 8); /* MSB-Baud */
1161 DEBUGP(1, dev, "set dev->flags1 = 0x%.2x\n", dev->flags1);
1162 xoutb(dev->flags1, REG_FLAGS1(iobase));
1165 DEBUGP(4, dev, "Xmit data\n");
1168 dev->flags1 = 0x20 /* T_Active */
1171 | (test_bit(IS_INVREV, &dev->flags) ? 2 : 0)
1172 | (((dev->baudv - 1) & 0x0100) >> 8) /* MSB-Baud */
1174 DEBUGP(4, dev, "dev->flags = 0x%.2x - set address "
1175 "high\n", dev->flags1);
1176 xoutb(dev->flags1, REG_FLAGS1(iobase));
1178 if (test_bit(IS_INVREV, &dev->flags)) {
1179 DEBUGP(4, dev, "Apply inverse convention for 0x%.2x "
1180 "-> 0x%.2x\n", (unsigned char)dev->sbuf[i],
1181 invert_revert(dev->sbuf[i]));
1183 xoutb(invert_revert(dev->sbuf[i]),
1187 xoutb(dev->sbuf[i], REG_BUF_DATA(iobase));
1190 DEBUGP(4, dev, "Xmit done\n");
1192 if (dev->proto == 0) {
1195 DEBUGP(4, dev, "T=0 assumes 0 byte reply\n");
1197 if (test_bit(IS_INVREV, &dev->flags))
1210 nsend = 5 + (unsigned char)dev->sbuf[4];
1211 if (dev->sbuf[4] == 0)
1219 if (test_bit(IS_INVREV, &dev->flags)) {
1220 DEBUGP(4, dev, "T=0 set Procedure byte (inverse-reverse) "
1221 "0x%.2x\n", invert_revert(dev->sbuf[1]));
1222 xoutb(invert_revert(dev->sbuf[1]), REG_NUM_BYTES(iobase));
1224 DEBUGP(4, dev, "T=0 set Procedure byte 0x%.2x\n", dev->sbuf[1]);
1225 xoutb(dev->sbuf[1], REG_NUM_BYTES(iobase));
1228 DEBUGP(1, dev, "set NumSendBytes = 0x%.2x\n",
1232 DEBUGP(1, dev, "Trigger CARDMAN CONTROLLER (0x%.2x)\n",
1234 | (dev->flags0 & 2 ? 0 : 4) /* power on if needed */
1235 |(dev->proto ? 0x10 : 0x08) /* T=1/T=0 */
1238 | (dev->flags0 & 2 ? 0 : 4) /* power on if needed */
1239 |(dev->proto ? 0x10 : 0x08) /* T=1/T=0 */
1244 if (dev->proto == 1) {
1245 DEBUGP(4, dev, "Wait for xmit done\n");
1252 DEBUGP(4, dev, "timeout waiting for xmit done\n");
1261 if (dev->proto) {
1267 DEBUGP(4, dev, "infolen=%d\n", infolen);
1273 DEBUGP(4, dev, "timeout waiting for infoLen\n");
1278 clear_bit(IS_PROCBYTE_PRESENT, &dev->flags);
1281 io_read_num_rec_bytes(iobase, &dev->rlen);
1283 if (dev->proto) {
1284 if (dev->rlen >= infolen + 4)
1290 if (s > dev->rlen) {
1291 DEBUGP(1, dev, "NumRecBytes inc (reset timeout)\n");
1293 dev->rlen = s;
1302 else if (dev->proto == 0) {
1305 DEBUGP(1, dev, "NoProcedure byte set\n");
1309 DEBUGP(1, dev, "NoProcedure byte unset "
1311 dev->procbyte = inb(REG_FLAGS1(iobase));
1312 DEBUGP(1, dev, "Read procedure byte 0x%.2x\n",
1313 dev->procbyte);
1317 DEBUGP(1, dev, "T0Done flag (read reply)\n");
1321 if (dev->proto)
1325 DEBUGP(1, dev, "timeout waiting for numRecBytes\n");
1329 if (dev->proto == 0) {
1330 DEBUGP(1, dev, "Wait for T0Done bit to be set\n");
1337 DEBUGP(1, dev, "timeout waiting for T0Done\n");
1342 dev->procbyte = inb(REG_FLAGS1(iobase));
1343 DEBUGP(4, dev, "Read procedure byte 0x%.2x\n",
1344 dev->procbyte);
1346 io_read_num_rec_bytes(iobase, &dev->rlen);
1347 DEBUGP(4, dev, "Read NumRecBytes = %i\n", dev->rlen);
1352 dev->rpos = dev->proto ? 0 : nr == 4 ? 5 : nr > dev->rlen ? 5 : nr;
1353 DEBUGP(4, dev, "dev->rlen = %i, dev->rpos = %i, nr = %i\n",
1354 dev->rlen, dev->rpos, nr);
1357 DEBUGP(4, dev, "Reset SM\n");
1361 DEBUGP(4, dev, "Write failed but clear T_Active\n");
1362 dev->flags1 &= 0xdf;
1363 xoutb(dev->flags1, REG_FLAGS1(iobase));
1366 clear_bit(LOCK_IO, &dev->flags);
1367 wake_up_interruptible(&dev->ioq);
1368 wake_up_interruptible(&dev->readq); /* tell read we have data */
1371 memset((char *)dev->sbuf, 0, 512);
1374 DEBUGP(2, dev, "<- cmm_write\n");
1378 static void start_monitor(struct cm4000_dev *dev)
1380 DEBUGP(3, dev, "-> start_monitor\n");
1381 if (!dev->monitor_running) {
1382 DEBUGP(5, dev, "create, init and add timer\n");
1383 timer_setup(&dev->timer, monitor_card, 0);
1384 dev->monitor_running = 1;
1385 mod_timer(&dev->timer, jiffies);
1387 DEBUGP(5, dev, "monitor already running\n");
1388 DEBUGP(3, dev, "<- start_monitor\n");
1391 static void stop_monitor(struct cm4000_dev *dev)
1393 DEBUGP(3, dev, "-> stop_monitor\n");
1394 if (dev->monitor_running) {
1395 DEBUGP(5, dev, "stopping monitor\n");
1396 terminate_monitor(dev);
1398 clear_bit(IS_ATR_VALID, &dev->flags);
1399 clear_bit(IS_ATR_PRESENT, &dev->flags);
1401 DEBUGP(5, dev, "monitor already stopped\n");
1402 DEBUGP(3, dev, "<- stop_monitor\n");
1407 struct cm4000_dev *dev = filp->private_data;
1408 unsigned int iobase = dev->p_dev->resource[0]->start;
1421 DEBUGP(3, dev, "cmm_ioctl(device=%d.%d) %s\n", imajor(inode),
1429 DEBUGP(4, dev, "DEV_OK false\n");
1433 if (test_bit(IS_CMM_ABSENT, &dev->flags)) {
1434 DEBUGP(4, dev, "CMM_ABSENT flag set\n");
1440 DEBUGP(4, dev, "ioctype mismatch\n");
1444 DEBUGP(4, dev, "iocnr mismatch\n");
1451 DEBUGP(4, dev, " ... in CM_IOCGSTATUS\n");
1457 status = dev->flags0 & 3;
1458 if (test_bit(IS_ATR_PRESENT, &dev->flags))
1460 if (test_bit(IS_ATR_VALID, &dev->flags))
1462 if (test_bit(IS_CMM_ABSENT, &dev->flags))
1464 if (test_bit(IS_BAD_CARD, &dev->flags))
1471 DEBUGP(4, dev, "... in CM_IOCGATR\n");
1477 (dev->atrq,
1479 || (test_bit(IS_ATR_PRESENT, (void *)&dev->flags)
1489 if (test_bit(IS_ATR_VALID, &dev->flags) == 0) {
1495 if (copy_to_user(atreq->atr, dev->atr,
1496 dev->atr_len))
1499 tmp = dev->atr_len;
1509 DEBUGP(4, dev, "... in CM_IOCARDOFF\n");
1510 if (dev->flags0 & 0x01) {
1511 DEBUGP(4, dev, " Card inserted\n");
1513 DEBUGP(2, dev, " No card inserted\n");
1515 if (dev->flags0 & 0x02) {
1516 DEBUGP(4, dev, " Card powered\n");
1518 DEBUGP(2, dev, " Card not powered\n");
1523 if ((dev->flags0 & 0x01) && (dev->flags0 & 0x02)) {
1527 (dev->ioq,
1529 || (test_and_set_bit(LOCK_IO, (void *)&dev->flags)
1538 DEBUGP(4, dev, "Set Flags0=0x42 \n");
1540 clear_bit(IS_ATR_PRESENT, &dev->flags);
1541 clear_bit(IS_ATR_VALID, &dev->flags);
1542 dev->mstate = M_CARDOFF;
1543 clear_bit(LOCK_IO, &dev->flags);
1545 (dev->atrq,
1547 || (test_bit(IS_ATR_VALID, (void *)&dev->flags) !=
1557 clear_bit(LOCK_IO, &dev->flags);
1558 wake_up_interruptible(&dev->ioq);
1573 DEBUGP(4, dev, "... in CM_IOCSPTS\n");
1576 (dev->atrq,
1578 || (test_bit(IS_ATR_PRESENT, (void *)&dev->flags)
1588 (dev->ioq,
1590 || (test_and_set_bit(LOCK_IO, (void *)&dev->flags)
1599 if ((rc = set_protocol(dev, &krnptsreq)) != 0) {
1601 dev->mstate = M_FETCH_ATR;
1602 clear_bit(IS_ATR_VALID, &dev->flags);
1605 clear_bit(LOCK_IO, &dev->flags);
1606 wake_up_interruptible(&dev->ioq);
1616 DEBUGP(4, dev, "... in default (unknown IOCTL code)\n");
1626 struct cm4000_dev *dev;
1646 dev = link->priv;
1647 filp->private_data = dev;
1649 DEBUGP(2, dev, "-> cmm_open(device=%d.%d process=%s,%d)\n",
1656 ZERO_DEV(dev);
1669 dev->mdelay = T_50MSEC;
1672 start_monitor(dev);
1676 DEBUGP(2, dev, "<- cmm_open\n");
1685 struct cm4000_dev *dev;
1696 dev = link->priv;
1698 DEBUGP(2, dev, "-> cmm_close(maj/min=%d.%d)\n",
1701 stop_monitor(dev);
1703 ZERO_DEV(dev);
1706 wake_up(&dev->devq); /* socket removed? */
1708 DEBUGP(2, dev, "cmm_close\n");
1714 struct cm4000_dev *dev = link->priv;
1719 DEBUGP(3, dev, "-> cmm_cm4000_release\n");
1727 wait_event(dev->devq, (link->open == 0));
1729 /* dev->devq=NULL; this cannot be zeroed earlier */
1730 DEBUGP(3, dev, "<- cmm_cm4000_release\n");
1761 struct cm4000_dev *dev;
1763 dev = link->priv;
1764 stop_monitor(dev);
1771 struct cm4000_dev *dev;
1773 dev = link->priv;
1775 start_monitor(dev);
1788 struct cm4000_dev *dev;
1801 dev = kzalloc(sizeof(struct cm4000_dev), GFP_KERNEL);
1802 if (dev == NULL)
1805 dev->p_dev = link;
1806 link->priv = dev;
1809 init_waitqueue_head(&dev->devq);
1810 init_waitqueue_head(&dev->ioq);
1811 init_waitqueue_head(&dev->atrq);
1812 init_waitqueue_head(&dev->readq);
1817 kfree(dev);
1828 struct cm4000_dev *dev = link->priv;
1838 stop_monitor(dev);
1843 kfree(dev);