[BACK]Return to utoppy.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / dev / usb

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/sys/dev/usb/utoppy.c between version 1.24 and 1.24.4.5

version 1.24, 2014/07/25 08:10:39 version 1.24.4.5, 2014/12/05 09:37:50
Line 38  __KERNEL_RCSID(0, "$NetBSD$");
Line 38  __KERNEL_RCSID(0, "$NetBSD$");
 #include <sys/kernel.h>  #include <sys/kernel.h>
 #include <sys/fcntl.h>  #include <sys/fcntl.h>
 #include <sys/device.h>  #include <sys/device.h>
 #include <sys/malloc.h>  
 #include <sys/ioctl.h>  #include <sys/ioctl.h>
 #include <sys/uio.h>  #include <sys/uio.h>
 #include <sys/conf.h>  #include <sys/conf.h>
Line 202  int             utoppy_activate(device_t
Line 201  int             utoppy_activate(device_t
 extern struct cfdriver utoppy_cd;  extern struct cfdriver utoppy_cd;
 CFATTACH_DECL_NEW(utoppy, sizeof(struct utoppy_softc), utoppy_match, utoppy_attach, utoppy_detach, utoppy_activate);  CFATTACH_DECL_NEW(utoppy, sizeof(struct utoppy_softc), utoppy_match, utoppy_attach, utoppy_detach, utoppy_activate);
   
 int  int
 utoppy_match(device_t parent, cfdata_t match, void *aux)  utoppy_match(device_t parent, cfdata_t match, void *aux)
 {  {
         struct usb_attach_arg *uaa = aux;          struct usb_attach_arg *uaa = aux;
   
         if (uaa->vendor == USB_VENDOR_TOPFIELD &&          if (uaa->vendor == USB_VENDOR_TOPFIELD &&
             uaa->product == USB_PRODUCT_TOPFIELD_TF5000PVR)              uaa->product == USB_PRODUCT_TOPFIELD_TF5000PVR)
                 return (UMATCH_VENDOR_PRODUCT);                  return UMATCH_VENDOR_PRODUCT;
   
         return (UMATCH_NONE);          return UMATCH_NONE;
 }  }
   
 void  void
 utoppy_attach(device_t parent, device_t self, void *aux)  utoppy_attach(device_t parent, device_t self, void *aux)
 {  {
         struct utoppy_softc *sc = device_private(self);          struct utoppy_softc *sc = device_private(self);
Line 223  utoppy_attach(device_t parent, device_t 
Line 222  utoppy_attach(device_t parent, device_t 
         usbd_interface_handle iface;          usbd_interface_handle iface;
         usb_endpoint_descriptor_t *ed;          usb_endpoint_descriptor_t *ed;
         char *devinfop;          char *devinfop;
         u_int8_t epcount;          uint8_t epcount;
         int i;          int i;
   
         sc->sc_dev = self;          sc->sc_dev = self;
Line 335  utoppy_activate(device_t self, enum deva
Line 334  utoppy_activate(device_t self, enum deva
         }          }
 }  }
   
 int  int
 utoppy_detach(device_t self, int flags)  utoppy_detach(device_t self, int flags)
 {  {
         struct utoppy_softc *sc = device_private(self);          struct utoppy_softc *sc = device_private(self);
Line 368  utoppy_detach(device_t self, int flags)
Line 367  utoppy_detach(device_t self, int flags)
         usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev,          usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev,
                            sc->sc_dev);                             sc->sc_dev);
   
         return (0);          return 0;
 }  }
   
 static const uint16_t utoppy_crc16_lookup[] = {  static const uint16_t utoppy_crc16_lookup[] = {
Line 436  utoppy_usbd_status2errno(usbd_status err
Line 435  utoppy_usbd_status2errno(usbd_status err
 {  {
   
         if (err >= USBD_ERROR_MAX)          if (err >= USBD_ERROR_MAX)
                 return (EFAULT);                  return EFAULT;
         return (utoppy_usbdstatus_lookup[err]);          return utoppy_usbdstatus_lookup[err];
 }  }
   
 #ifdef UTOPPY_DEBUG  #ifdef UTOPPY_DEBUG
Line 470  utoppy_state_string(enum utoppy_state st
Line 469  utoppy_state_string(enum utoppy_state st
                 break;                  break;
         }          }
   
         return (str);          return str;
 }  }
   
 static void  static void
Line 524  utoppy_dump_packet(const void *b, size_t
Line 523  utoppy_dump_packet(const void *b, size_t
   
 static usbd_status  static usbd_status
 utoppy_bulk_transfer(usbd_xfer_handle xfer, usbd_pipe_handle pipe,  utoppy_bulk_transfer(usbd_xfer_handle xfer, usbd_pipe_handle pipe,
     u_int16_t flags, u_int32_t timeout, void *buf, u_int32_t *size,      uint16_t flags, uint32_t timeout, void *buf, uint32_t *size,
     const char *lbl)      const char *lbl)
 {  {
         usbd_status err;          usbd_status err;
Line 534  utoppy_bulk_transfer(usbd_xfer_handle xf
Line 533  utoppy_bulk_transfer(usbd_xfer_handle xf
         err = usbd_sync_transfer_sig(xfer);          err = usbd_sync_transfer_sig(xfer);
   
         usbd_get_xfer_status(xfer, NULL, NULL, size, NULL);          usbd_get_xfer_status(xfer, NULL, NULL, size, NULL);
         return (err);          return err;
 }  }
   
 static int  static int
Line 562  utoppy_send_packet(struct utoppy_softc *
Line 561  utoppy_send_packet(struct utoppy_softc *
         if (len >= UTOPPY_BSIZE) {          if (len >= UTOPPY_BSIZE) {
                 DPRINTF(UTOPPY_DBG_SEND_PACKET, ("%s: utoppy_send_packet: "                  DPRINTF(UTOPPY_DBG_SEND_PACKET, ("%s: utoppy_send_packet: "
                     "packet too big (%d)\n", device_xname(sc->sc_dev), (int)len));                      "packet too big (%d)\n", device_xname(sc->sc_dev), (int)len));
                 return (EINVAL);                  return EINVAL;
         }          }
   
         h->h_len = htole16(dlen + UTOPPY_HEADER_SIZE);          h->h_len = htole16(dlen + UTOPPY_HEADER_SIZE);
Line 614  utoppy_send_packet(struct utoppy_softc *
Line 613  utoppy_send_packet(struct utoppy_softc *
                 memcpy(sc->sc_out_buf, data, thislen);                  memcpy(sc->sc_out_buf, data, thislen);
   
                 err = utoppy_bulk_transfer(sc->sc_out_xfer, sc->sc_out_pipe,                  err = utoppy_bulk_transfer(sc->sc_out_xfer, sc->sc_out_pipe,
                     USBD_NO_COPY, timeout, sc->sc_out_buf, &thislen,                      0, timeout, sc->sc_out_buf, &thislen,
                     "utoppytx");                      "utoppytx");
   
                 if (thislen != min(len, UTOPPY_FRAG_SIZE)) {                  if (thislen != min(len, UTOPPY_FRAG_SIZE)) {
Line 632  utoppy_send_packet(struct utoppy_softc *
Line 631  utoppy_send_packet(struct utoppy_softc *
         DPRINTF(UTOPPY_DBG_SEND_PACKET, ("%s: utoppy_send_packet: "          DPRINTF(UTOPPY_DBG_SEND_PACKET, ("%s: utoppy_send_packet: "
             "usbd_bulk_transfer() returned %d.\n", device_xname(sc->sc_dev),err));              "usbd_bulk_transfer() returned %d.\n", device_xname(sc->sc_dev),err));
   
         return (err ? utoppy_usbd_status2errno(err) : 0);          return err ? utoppy_usbd_status2errno(err) : 0;
 }  }
   
 static int  static int
Line 655  utoppy_recv_packet(struct utoppy_softc *
Line 654  utoppy_recv_packet(struct utoppy_softc *
                 requested = thislen = min(bytesleft, UTOPPY_FRAG_SIZE);                  requested = thislen = min(bytesleft, UTOPPY_FRAG_SIZE);
   
                 err = utoppy_bulk_transfer(sc->sc_in_xfer, sc->sc_in_pipe,                  err = utoppy_bulk_transfer(sc->sc_in_xfer, sc->sc_in_pipe,
                     USBD_NO_COPY | USBD_SHORT_XFER_OK, timeout, sc->sc_in_buf,                      USBD_SHORT_XFER_OK, timeout, sc->sc_in_buf,
                     &thislen, "utoppyrx");                      &thislen, "utoppyrx");
   
                 DPRINTF(UTOPPY_DBG_RECV_PACKET, ("%s: utoppy_recv_packet: "                  DPRINTF(UTOPPY_DBG_RECV_PACKET, ("%s: utoppy_recv_packet: "
Line 672  utoppy_recv_packet(struct utoppy_softc *
Line 671  utoppy_recv_packet(struct utoppy_softc *
         } while (err == 0 && bytesleft && thislen == requested);          } while (err == 0 && bytesleft && thislen == requested);
   
         if (err)          if (err)
                 return (utoppy_usbd_status2errno(err));                  return utoppy_usbd_status2errno(err);
   
         h = sc->sc_in_data;          h = sc->sc_in_data;
   
Line 684  utoppy_recv_packet(struct utoppy_softc *
Line 683  utoppy_recv_packet(struct utoppy_softc *
                 DPRINTF(UTOPPY_DBG_RECV_PACKET, ("%s: utoppy_recv_packet: bad "                  DPRINTF(UTOPPY_DBG_RECV_PACKET, ("%s: utoppy_recv_packet: bad "
                     " length (len %d, h_len %d)\n", device_xname(sc->sc_dev),                      " length (len %d, h_len %d)\n", device_xname(sc->sc_dev),
                     (int)len, le16toh(h->h_len)));                      (int)len, le16toh(h->h_len)));
                 return (EIO);                  return EIO;
         }          }
   
         len = h->h_len = le16toh(h->h_len);          len = h->h_len = le16toh(h->h_len);
Line 708  utoppy_recv_packet(struct utoppy_softc *
Line 707  utoppy_recv_packet(struct utoppy_softc *
                         DPRINTF(UTOPPY_DBG_RECV_PACKET, ("%s: "                          DPRINTF(UTOPPY_DBG_RECV_PACKET, ("%s: "
                             "utoppy_recv_packet: failed to ACK file data: %d\n",                              "utoppy_recv_packet: failed to ACK file data: %d\n",
                             device_xname(sc->sc_dev), err));                              device_xname(sc->sc_dev), err));
                         return (err);                          return err;
                 }                  }
         }          }
   
Line 750  utoppy_recv_packet(struct utoppy_softc *
Line 749  utoppy_recv_packet(struct utoppy_softc *
             (int)len, crc, h->h_crc));              (int)len, crc, h->h_crc));
         DDUMP_PACKET(h, len);          DDUMP_PACKET(h, len);
   
         return ((crc == h->h_crc) ? 0 : EBADMSG);          return (crc == h->h_crc) ? 0 : EBADMSG;
 }  }
   
 static __inline void *  static __inline void *
Line 758  utoppy_current_ptr(void *b)
Line 757  utoppy_current_ptr(void *b)
 {  {
         struct utoppy_header *h = b;          struct utoppy_header *h = b;
   
         return (&h->h_data[h->h_len]);          return &h->h_data[h->h_len];
 }  }
   
 static __inline void  static __inline void
Line 854  utoppy_add_path(struct utoppy_softc *sc,
Line 853  utoppy_add_path(struct utoppy_softc *sc,
             err, (int)len));              err, (int)len));
   
         if (err)          if (err)
                 return (err);                  return err;
   
         if (len < 2)          if (len < 2)
                 return (EINVAL);                  return EINVAL;
   
         /*          /*
          * copyinstr(9) has already copied the terminating NUL character,           * copyinstr(9) has already copied the terminating NUL character,
Line 885  utoppy_add_path(struct utoppy_softc *sc,
Line 884  utoppy_add_path(struct utoppy_softc *sc,
         DPRINTF(UTOPPY_DBG_ADDPATH, ("utoppy_add_path: final len %d\n",          DPRINTF(UTOPPY_DBG_ADDPATH, ("utoppy_add_path: final len %d\n",
             (u_int)len));              (u_int)len));
   
         return (0);          return 0;
 }  }
   
 static __inline int  static __inline int
Line 894  utoppy_get_8(struct utoppy_softc *sc, ui
Line 893  utoppy_get_8(struct utoppy_softc *sc, ui
         uint8_t *p;          uint8_t *p;
   
         if (sc->sc_in_len < sizeof(*vp))          if (sc->sc_in_len < sizeof(*vp))
                 return (1);                  return 1;
   
         p = UTOPPY_IN_DATA(sc);          p = UTOPPY_IN_DATA(sc);
         *vp = *p;          *vp = *p;
         sc->sc_in_offset += sizeof(*vp);          sc->sc_in_offset += sizeof(*vp);
         sc->sc_in_len -= sizeof(*vp);          sc->sc_in_len -= sizeof(*vp);
         return (0);          return 0;
 }  }
   
 static __inline int  static __inline int
Line 910  utoppy_get_16(struct utoppy_softc *sc, u
Line 909  utoppy_get_16(struct utoppy_softc *sc, u
         uint8_t *p;          uint8_t *p;
   
         if (sc->sc_in_len < sizeof(v))          if (sc->sc_in_len < sizeof(v))
                 return (1);                  return 1;
   
         p = UTOPPY_IN_DATA(sc);          p = UTOPPY_IN_DATA(sc);
         v = *p++;          v = *p++;
Line 918  utoppy_get_16(struct utoppy_softc *sc, u
Line 917  utoppy_get_16(struct utoppy_softc *sc, u
         *vp = v;          *vp = v;
         sc->sc_in_offset += sizeof(v);          sc->sc_in_offset += sizeof(v);
         sc->sc_in_len -= sizeof(v);          sc->sc_in_len -= sizeof(v);
         return (0);          return 0;
 }  }
   
 static __inline int  static __inline int
Line 928  utoppy_get_32(struct utoppy_softc *sc, u
Line 927  utoppy_get_32(struct utoppy_softc *sc, u
         uint8_t *p;          uint8_t *p;
   
         if (sc->sc_in_len < sizeof(v))          if (sc->sc_in_len < sizeof(v))
                 return (1);                  return 1;
   
         p = UTOPPY_IN_DATA(sc);          p = UTOPPY_IN_DATA(sc);
         v = *p++;          v = *p++;
Line 938  utoppy_get_32(struct utoppy_softc *sc, u
Line 937  utoppy_get_32(struct utoppy_softc *sc, u
         *vp = v;          *vp = v;
         sc->sc_in_offset += sizeof(v);          sc->sc_in_offset += sizeof(v);
         sc->sc_in_len -= sizeof(v);          sc->sc_in_len -= sizeof(v);
         return (0);          return 0;
 }  }
   
 static __inline int  static __inline int
Line 948  utoppy_get_64(struct utoppy_softc *sc, u
Line 947  utoppy_get_64(struct utoppy_softc *sc, u
         uint8_t *p;          uint8_t *p;
   
         if (sc->sc_in_len < sizeof(v))          if (sc->sc_in_len < sizeof(v))
                 return (1);                  return 1;
   
         p = UTOPPY_IN_DATA(sc);          p = UTOPPY_IN_DATA(sc);
         v = *p++;          v = *p++;
Line 962  utoppy_get_64(struct utoppy_softc *sc, u
Line 961  utoppy_get_64(struct utoppy_softc *sc, u
         *vp = v;          *vp = v;
         sc->sc_in_offset += sizeof(v);          sc->sc_in_offset += sizeof(v);
         sc->sc_in_len -= sizeof(v);          sc->sc_in_len -= sizeof(v);
         return (0);          return 0;
 }  }
   
 static __inline int  static __inline int
Line 971  utoppy_get_string(struct utoppy_softc *s
Line 970  utoppy_get_string(struct utoppy_softc *s
         char *p;          char *p;
   
         if (sc->sc_in_len < len)          if (sc->sc_in_len < len)
                 return (1);                  return 1;
   
         memset(str, 0, len);          memset(str, 0, len);
         p = UTOPPY_IN_DATA(sc);          p = UTOPPY_IN_DATA(sc);
         strncpy(str, p, len);          strncpy(str, p, len);
         sc->sc_in_offset += len;          sc->sc_in_offset += len;
         sc->sc_in_len -= len;          sc->sc_in_len -= len;
         return (0);          return 0;
 }  }
   
 static int  static int
Line 989  utoppy_command(struct utoppy_softc *sc, 
Line 988  utoppy_command(struct utoppy_softc *sc, 
   
         err = utoppy_send_packet(sc, cmd, timeout);          err = utoppy_send_packet(sc, cmd, timeout);
         if (err)          if (err)
                 return (err);                  return err;
   
         err = utoppy_recv_packet(sc, presp, timeout);          err = utoppy_recv_packet(sc, presp, timeout);
         if (err == EBADMSG) {          if (err == EBADMSG) {
Line 997  utoppy_command(struct utoppy_softc *sc, 
Line 996  utoppy_command(struct utoppy_softc *sc, 
                 utoppy_send_packet(sc, UTOPPY_RESP_ERROR, timeout);                  utoppy_send_packet(sc, UTOPPY_RESP_ERROR, timeout);
         }          }
   
         return (err);          return err;
 }  }
   
 static int  static int
Line 1009  utoppy_timestamp_decode(struct utoppy_so
Line 1008  utoppy_timestamp_decode(struct utoppy_so
   
         if (utoppy_get_16(sc, &mjd) || utoppy_get_8(sc, &hour) ||          if (utoppy_get_16(sc, &mjd) || utoppy_get_8(sc, &hour) ||
             utoppy_get_8(sc, &minute) || utoppy_get_8(sc, &sec))              utoppy_get_8(sc, &minute) || utoppy_get_8(sc, &sec))
                 return (1);                  return 1;
   
         if (mjd == 0xffffu && hour == 0xffu && minute == 0xffu && sec == 0xffu){          if (mjd == 0xffffu && hour == 0xffu && minute == 0xffu && sec == 0xffu){
                 *tp = 0;                  *tp = 0;
                 return (0);                  return 0;
         }          }
   
         rv = (mjd < UTOPPY_MJD_1970) ? UTOPPY_MJD_1970 : (uint32_t) mjd;          rv = (mjd < UTOPPY_MJD_1970) ? UTOPPY_MJD_1970 : (uint32_t) mjd;
Line 1027  utoppy_timestamp_decode(struct utoppy_so
Line 1026  utoppy_timestamp_decode(struct utoppy_so
         rv += sec;          rv += sec;
         *tp = (time_t)rv;          *tp = (time_t)rv;
   
         return (0);          return 0;
 }  }
   
 static void  static void
Line 1061  utoppy_turbo_mode(struct utoppy_softc *s
Line 1060  utoppy_turbo_mode(struct utoppy_softc *s
   
         err = utoppy_command(sc, UTOPPY_CMD_TURBO, UTOPPY_SHORT_TIMEOUT, &r);          err = utoppy_command(sc, UTOPPY_CMD_TURBO, UTOPPY_SHORT_TIMEOUT, &r);
         if (err)          if (err)
                 return (err);                  return err;
   
         return ((r == UTOPPY_RESP_SUCCESS) ? 0 : EIO);          return (r == UTOPPY_RESP_SUCCESS) ? 0 : EIO;
 }  }
   
 static int  static int
Line 1076  utoppy_check_ready(struct utoppy_softc *
Line 1075  utoppy_check_ready(struct utoppy_softc *
   
         err = utoppy_command(sc, UTOPPY_CMD_READY, UTOPPY_LONG_TIMEOUT, &r);          err = utoppy_command(sc, UTOPPY_CMD_READY, UTOPPY_LONG_TIMEOUT, &r);
         if (err)          if (err)
                 return (err);                  return err;
   
         return ((r == UTOPPY_RESP_SUCCESS) ? 0 : EIO);          return (r == UTOPPY_RESP_SUCCESS) ? 0 : EIO;
 }  }
   
 static int  static int
Line 1101  utoppy_cancel(struct utoppy_softc *sc)
Line 1100  utoppy_cancel(struct utoppy_softc *sc)
         }          }
   
         if (err)          if (err)
                 return (err);                  return err;
   
         /*          /*
          * Make sure turbo mode is off, otherwise the Toppy will not           * Make sure turbo mode is off, otherwise the Toppy will not
Line 1110  utoppy_cancel(struct utoppy_softc *sc)
Line 1109  utoppy_cancel(struct utoppy_softc *sc)
         (void) utoppy_turbo_mode(sc, 0);          (void) utoppy_turbo_mode(sc, 0);
   
         sc->sc_state = UTOPPY_STATE_IDLE;          sc->sc_state = UTOPPY_STATE_IDLE;
         return (0);          return 0;
 }  }
   
 static int  static int
Line 1123  utoppy_stats(struct utoppy_softc *sc, st
Line 1122  utoppy_stats(struct utoppy_softc *sc, st
         UTOPPY_OUT_INIT(sc);          UTOPPY_OUT_INIT(sc);
         err = utoppy_command(sc, UTOPPY_CMD_STATS, UTOPPY_LONG_TIMEOUT, &r);          err = utoppy_command(sc, UTOPPY_CMD_STATS, UTOPPY_LONG_TIMEOUT, &r);
         if (err)          if (err)
                 return (err);                  return err;
   
         if (r != UTOPPY_RESP_STATS_DATA)          if (r != UTOPPY_RESP_STATS_DATA)
                 return (EIO);                  return EIO;
   
         if (utoppy_get_32(sc, &hsize) || utoppy_get_32(sc, &hfree))          if (utoppy_get_32(sc, &hsize) || utoppy_get_32(sc, &hfree))
                 return (EIO);                  return EIO;
   
         us->us_hdd_size = hsize;          us->us_hdd_size = hsize;
         us->us_hdd_size *= 1024;          us->us_hdd_size *= 1024;
         us->us_hdd_free = hfree;          us->us_hdd_free = hfree;
         us->us_hdd_free *= 1024;          us->us_hdd_free *= 1024;
   
         return (0);          return 0;
 }  }
   
 static int  static int
Line 1162  utoppy_readdir_next(struct utoppy_softc 
Line 1161  utoppy_readdir_next(struct utoppy_softc 
                             UTOPPY_LONG_TIMEOUT);                              UTOPPY_LONG_TIMEOUT);
                 }                  }
                 utoppy_cancel(sc);                  utoppy_cancel(sc);
                 return (err);                  return err;
         }          }
   
         DPRINTF(UTOPPY_DBG_READDIR, ("%s: utoppy_readdir_next: "          DPRINTF(UTOPPY_DBG_READDIR, ("%s: utoppy_readdir_next: "
Line 1182  utoppy_readdir_next(struct utoppy_softc 
Line 1181  utoppy_readdir_next(struct utoppy_softc 
                             "utoppy_send_packet(ACK) returned %d\n",                              "utoppy_send_packet(ACK) returned %d\n",
                             device_xname(sc->sc_dev), err));                              device_xname(sc->sc_dev), err));
                         utoppy_cancel(sc);                          utoppy_cancel(sc);
                         return (err);                          return err;
                 }                  }
                 sc->sc_state = UTOPPY_STATE_READDIR;                  sc->sc_state = UTOPPY_STATE_READDIR;
                 sc->sc_in_offset = 0;                  sc->sc_in_offset = 0;
Line 1203  utoppy_readdir_next(struct utoppy_softc 
Line 1202  utoppy_readdir_next(struct utoppy_softc 
                     "bad response: 0x%x\n", device_xname(sc->sc_dev), resp));                      "bad response: 0x%x\n", device_xname(sc->sc_dev), resp));
                 sc->sc_state = UTOPPY_STATE_IDLE;                  sc->sc_state = UTOPPY_STATE_IDLE;
                 sc->sc_in_len = 0;                  sc->sc_in_len = 0;
                 return (EIO);                  return EIO;
         }          }
   
         return (0);          return 0;
 }  }
   
 static size_t  static size_t
Line 1223  utoppy_readdir_decode(struct utoppy_soft
Line 1222  utoppy_readdir_decode(struct utoppy_soft
             utoppy_get_32(sc, &ud->ud_attributes)) {              utoppy_get_32(sc, &ud->ud_attributes)) {
                 DPRINTF(UTOPPY_DBG_READDIR, ("%s: utoppy_readdir_decode: no "                  DPRINTF(UTOPPY_DBG_READDIR, ("%s: utoppy_readdir_decode: no "
                     "more to decode\n", device_xname(sc->sc_dev)));                      "more to decode\n", device_xname(sc->sc_dev)));
                 return (0);                  return 0;
         }          }
   
         switch (ftype) {          switch (ftype) {
Line 1244  utoppy_readdir_decode(struct utoppy_soft
Line 1243  utoppy_readdir_decode(struct utoppy_soft
             ((ftype == UTOPPY_FTYPE_FILE) ? "FILE" : "UNKNOWN"), ud->ud_path,              ((ftype == UTOPPY_FTYPE_FILE) ? "FILE" : "UNKNOWN"), ud->ud_path,
             ud->ud_size, (u_long)ud->ud_mtime, ud->ud_attributes));              ud->ud_size, (u_long)ud->ud_mtime, ud->ud_attributes));
   
         return (1);          return 1;
 }  }
   
 static int  static int
Line 1260  utoppy_readfile_next(struct utoppy_softc
Line 1259  utoppy_readfile_next(struct utoppy_softc
                     "utoppy_recv_packet() returned %d\n",                      "utoppy_recv_packet() returned %d\n",
                     device_xname(sc->sc_dev), err));                      device_xname(sc->sc_dev), err));
                 utoppy_cancel(sc);                  utoppy_cancel(sc);
                 return (err);                  return err;
         }          }
   
         switch (resp) {          switch (resp) {
Line 1274  utoppy_readfile_next(struct utoppy_softc
Line 1273  utoppy_readfile_next(struct utoppy_softc
                             "utoppy_send_packet(UTOPPY_CMD_ACK) returned %d\n",                              "utoppy_send_packet(UTOPPY_CMD_ACK) returned %d\n",
                             device_xname(sc->sc_dev), err));                              device_xname(sc->sc_dev), err));
                         utoppy_cancel(sc);                          utoppy_cancel(sc);
                         return (err);                          return err;
                 }                  }
   
                 sc->sc_in_len = 0;                  sc->sc_in_len = 0;
Line 1289  utoppy_readfile_next(struct utoppy_softc
Line 1288  utoppy_readfile_next(struct utoppy_softc
                             "UTOPPY_RESP_FILE_DATA did not provide offset\n",                              "UTOPPY_RESP_FILE_DATA did not provide offset\n",
                             device_xname(sc->sc_dev)));                              device_xname(sc->sc_dev)));
                         utoppy_cancel(sc);                          utoppy_cancel(sc);
                         return (EBADMSG);                          return EBADMSG;
                 }                  }
   
                 DPRINTF(UTOPPY_DBG_READ, ("%s: utoppy_readfile_next: "                  DPRINTF(UTOPPY_DBG_READ, ("%s: utoppy_readfile_next: "
Line 1317  utoppy_readfile_next(struct utoppy_softc
Line 1316  utoppy_readfile_next(struct utoppy_softc
                 DPRINTF(UTOPPY_DBG_READ, ("%s: utoppy_readfile_next: bad "                  DPRINTF(UTOPPY_DBG_READ, ("%s: utoppy_readfile_next: bad "
                     "response code 0x%0x\n", device_xname(sc->sc_dev), resp));                      "response code 0x%0x\n", device_xname(sc->sc_dev), resp));
                 utoppy_cancel(sc);                  utoppy_cancel(sc);
                 return (EIO);                  return EIO;
         }          }
   
         return (0);          return 0;
 }  }
   
 int  int
Line 1335  utoppyopen(dev_t dev, int flag, int mode
Line 1334  utoppyopen(dev_t dev, int flag, int mode
                 return ENXIO;                  return ENXIO;
   
         if (sc == NULL || sc->sc_iface == NULL || sc->sc_dying)          if (sc == NULL || sc->sc_iface == NULL || sc->sc_dying)
                 return (ENXIO);                  return ENXIO;
   
         if (sc->sc_state != UTOPPY_STATE_CLOSED) {          if (sc->sc_state != UTOPPY_STATE_CLOSED) {
                 DPRINTF(UTOPPY_DBG_OPEN, ("%s: utoppyopen: already open\n",                  DPRINTF(UTOPPY_DBG_OPEN, ("%s: utoppyopen: already open\n",
                     device_xname(sc->sc_dev)));                      device_xname(sc->sc_dev)));
                 return (EBUSY);                  return EBUSY;
         }          }
   
         DPRINTF(UTOPPY_DBG_OPEN, ("%s: utoppyopen: opening...\n",          DPRINTF(UTOPPY_DBG_OPEN, ("%s: utoppyopen: opening...\n",
Line 1368  utoppyopen(dev_t dev, int flag, int mode
Line 1367  utoppyopen(dev_t dev, int flag, int mode
                 goto done;                  goto done;
         }          }
   
         sc->sc_out_data = malloc(UTOPPY_BSIZE + 1, M_DEVBUF, M_WAITOK);          sc->sc_out_data = kmem_alloc(UTOPPY_BSIZE + 1, KM_SLEEP);
         if (sc->sc_out_data == NULL) {          if (sc->sc_out_data == NULL) {
                 error = ENOMEM;                  error = ENOMEM;
                 goto error;                  goto error;
         }          }
   
         sc->sc_in_data = malloc(UTOPPY_BSIZE + 1, M_DEVBUF, M_WAITOK);          sc->sc_in_data = kmem_alloc(UTOPPY_BSIZE + 1, KM_SLEEP);
         if (sc->sc_in_data == NULL) {          if (sc->sc_in_data == NULL) {
                 free(sc->sc_out_data, M_DEVBUF);                  kmem_free(sc->sc_out_data, UTOPPY_BSIZE + 1);
                 sc->sc_out_data = NULL;                  sc->sc_out_data = NULL;
                 error = ENOMEM;                  error = ENOMEM;
                 goto error;                  goto error;
Line 1407  utoppyopen(dev_t dev, int flag, int mode
Line 1406  utoppyopen(dev_t dev, int flag, int mode
         if (--sc->sc_refcnt < 0)          if (--sc->sc_refcnt < 0)
                 usb_detach_wakeupold(sc->sc_dev);                  usb_detach_wakeupold(sc->sc_dev);
   
         return (error);          return error;
 }  }
   
 int  int
Line 1427  utoppyclose(dev_t dev, int flag, int mod
Line 1426  utoppyclose(dev_t dev, int flag, int mod
                 DPRINTF(UTOPPY_DBG_CLOSE, ("%s: utoppyclose: not properly open:"                  DPRINTF(UTOPPY_DBG_CLOSE, ("%s: utoppyclose: not properly open:"
                     " %s\n", device_xname(sc->sc_dev),                      " %s\n", device_xname(sc->sc_dev),
                     utoppy_state_string(sc->sc_state)));                      utoppy_state_string(sc->sc_state)));
                 return (0);                  return 0;
         }          }
   
         if (sc->sc_out_data)          if (sc->sc_out_data)
Line 1450  utoppyclose(dev_t dev, int flag, int mod
Line 1449  utoppyclose(dev_t dev, int flag, int mod
         }          }
   
         if (sc->sc_out_data) {          if (sc->sc_out_data) {
                 free(sc->sc_out_data, M_DEVBUF);                  kmem_free(sc->sc_out_data, UTOPPY_BSIZE + 1);
                 sc->sc_out_data = NULL;                  sc->sc_out_data = NULL;
         }          }
   
         if (sc->sc_in_data) {          if (sc->sc_in_data) {
                 free(sc->sc_in_data, M_DEVBUF);                  kmem_free(sc->sc_in_data, UTOPPY_BSIZE + 1);
                 sc->sc_in_data = NULL;                  sc->sc_in_data = NULL;
         }          }
   
Line 1464  utoppyclose(dev_t dev, int flag, int mod
Line 1463  utoppyclose(dev_t dev, int flag, int mod
         DPRINTF(UTOPPY_DBG_CLOSE, ("%s: utoppyclose: done.\n",          DPRINTF(UTOPPY_DBG_CLOSE, ("%s: utoppyclose: done.\n",
             device_xname(sc->sc_dev)));              device_xname(sc->sc_dev)));
   
         return (0);          return 0;
 }  }
   
 int  int
Line 1478  utoppyread(dev_t dev, struct uio *uio, i
Line 1477  utoppyread(dev_t dev, struct uio *uio, i
         sc = device_lookup_private(&utoppy_cd, UTOPPYUNIT(dev));          sc = device_lookup_private(&utoppy_cd, UTOPPYUNIT(dev));
   
         if (sc->sc_dying)          if (sc->sc_dying)
                 return (EIO);                  return EIO;
   
         sc->sc_refcnt++;          sc->sc_refcnt++;
   
Line 1494  utoppyread(dev_t dev, struct uio *uio, i
Line 1493  utoppyread(dev_t dev, struct uio *uio, i
                                 err = utoppy_readdir_next(sc);                                  err = utoppy_readdir_next(sc);
                         else                          else
                         if ((err = uiomove(&ud, sizeof(ud), uio)) != 0)                          if ((err = uiomove(&ud, sizeof(ud), uio)) != 0)
                                 utoppy_cancel(sc);                                  utoppy_cancel(sc);
                 }                  }
                 break;                  break;
   
Line 1545  utoppyread(dev_t dev, struct uio *uio, i
Line 1544  utoppyread(dev_t dev, struct uio *uio, i
         if (--sc->sc_refcnt < 0)          if (--sc->sc_refcnt < 0)
                 usb_detach_wakeupold(sc->sc_dev);                  usb_detach_wakeupold(sc->sc_dev);
   
         return (err);          return err;
 }  }
   
 int  int
Line 1559  utoppywrite(dev_t dev, struct uio *uio, 
Line 1558  utoppywrite(dev_t dev, struct uio *uio, 
         sc = device_lookup_private(&utoppy_cd, UTOPPYUNIT(dev));          sc = device_lookup_private(&utoppy_cd, UTOPPYUNIT(dev));
   
         if (sc->sc_dying)          if (sc->sc_dying)
                 return (EIO);                  return EIO;
   
         switch(sc->sc_state) {          switch(sc->sc_state) {
         case UTOPPY_STATE_WRITEFILE:          case UTOPPY_STATE_WRITEFILE:
                 break;                  break;
   
         case UTOPPY_STATE_IDLE:          case UTOPPY_STATE_IDLE:
                 return (0);                  return 0;
   
         default:          default:
                 return (EIO);                  return EIO;
         }          }
   
         sc->sc_refcnt++;          sc->sc_refcnt++;
Line 1648  utoppywrite(dev_t dev, struct uio *uio, 
Line 1647  utoppywrite(dev_t dev, struct uio *uio, 
         if (--sc->sc_refcnt < 0)          if (--sc->sc_refcnt < 0)
                 usb_detach_wakeupold(sc->sc_dev);                  usb_detach_wakeupold(sc->sc_dev);
   
         return (err);          return err;
 }  }
   
 int  int
Line 1666  utoppyioctl(dev_t dev, u_long cmd, void 
Line 1665  utoppyioctl(dev_t dev, u_long cmd, void 
         sc = device_lookup_private(&utoppy_cd, UTOPPYUNIT(dev));          sc = device_lookup_private(&utoppy_cd, UTOPPYUNIT(dev));
   
         if (sc->sc_dying)          if (sc->sc_dying)
                 return (EIO);                  return EIO;
   
         DPRINTF(UTOPPY_DBG_IOCTL, ("%s: utoppyioctl: cmd 0x%08lx, state '%s'\n",          DPRINTF(UTOPPY_DBG_IOCTL, ("%s: utoppyioctl: cmd 0x%08lx, state '%s'\n",
             device_xname(sc->sc_dev), cmd, utoppy_state_string(sc->sc_state)));              device_xname(sc->sc_dev), cmd, utoppy_state_string(sc->sc_state)));
Line 1674  utoppyioctl(dev_t dev, u_long cmd, void 
Line 1673  utoppyioctl(dev_t dev, u_long cmd, void 
         if (sc->sc_state != UTOPPY_STATE_IDLE && cmd != UTOPPYIOCANCEL) {          if (sc->sc_state != UTOPPY_STATE_IDLE && cmd != UTOPPYIOCANCEL) {
                 DPRINTF(UTOPPY_DBG_IOCTL, ("%s: utoppyioctl: still busy.\n",                  DPRINTF(UTOPPY_DBG_IOCTL, ("%s: utoppyioctl: still busy.\n",
                     device_xname(sc->sc_dev)));                      device_xname(sc->sc_dev)));
                 return (EBUSY);                  return EBUSY;
         }          }
   
         sc->sc_refcnt++;          sc->sc_refcnt++;
Line 1913  utoppyioctl(dev_t dev, u_long cmd, void 
Line 1912  utoppyioctl(dev_t dev, u_long cmd, void 
         if (--sc->sc_refcnt < 0)          if (--sc->sc_refcnt < 0)
                 usb_detach_wakeupold(sc->sc_dev);                  usb_detach_wakeupold(sc->sc_dev);
   
         return (err);          return err;
 }  }

Legend:
Removed from v.1.24  
changed lines
  Added in v.1.24.4.5

CVSweb <webmaster@jp.NetBSD.org>