Lines Matching refs:garmin_data_p

170 static int gsp_next_packet(struct garmin_data *garmin_data_p);
260 static int pkt_add(struct garmin_data *garmin_data_p, in pkt_add() argument
277 spin_lock_irqsave(&garmin_data_p->lock, flags); in pkt_add()
278 garmin_data_p->flags |= FLAGS_QUEUING; in pkt_add()
279 result = list_empty(&garmin_data_p->pktlist); in pkt_add()
280 pkt->seq = garmin_data_p->seq_counter++; in pkt_add()
281 list_add_tail(&pkt->list, &garmin_data_p->pktlist); in pkt_add()
282 state = garmin_data_p->state; in pkt_add()
283 spin_unlock_irqrestore(&garmin_data_p->lock, flags); in pkt_add()
285 dev_dbg(&garmin_data_p->port->dev, in pkt_add()
292 gsp_next_packet(garmin_data_p); in pkt_add()
299 static struct garmin_packet *pkt_pop(struct garmin_data *garmin_data_p) in pkt_pop() argument
304 spin_lock_irqsave(&garmin_data_p->lock, flags); in pkt_pop()
305 if (!list_empty(&garmin_data_p->pktlist)) { in pkt_pop()
306 result = (struct garmin_packet *)garmin_data_p->pktlist.next; in pkt_pop()
309 spin_unlock_irqrestore(&garmin_data_p->lock, flags); in pkt_pop()
315 static void pkt_clear(struct garmin_data *garmin_data_p) in pkt_clear() argument
320 spin_lock_irqsave(&garmin_data_p->lock, flags); in pkt_clear()
321 while (!list_empty(&garmin_data_p->pktlist)) { in pkt_clear()
322 result = (struct garmin_packet *)garmin_data_p->pktlist.next; in pkt_clear()
326 spin_unlock_irqrestore(&garmin_data_p->lock, flags); in pkt_clear()
335 static int gsp_send_ack(struct garmin_data *garmin_data_p, __u8 pkt_id) in gsp_send_ack() argument
342 dev_dbg(&garmin_data_p->port->dev, "%s - pkt-id: 0x%X.\n", __func__, in gsp_send_ack()
365 send_to_tty(garmin_data_p->port, pkt, l); in gsp_send_ack()
381 static int gsp_rec_packet(struct garmin_data *garmin_data_p, int count) in gsp_rec_packet() argument
383 struct device *dev = &garmin_data_p->port->dev; in gsp_rec_packet()
385 const __u8 *recpkt = garmin_data_p->inbuffer+GSP_INITIAL_OFFSET; in gsp_rec_packet()
386 __le32 *usbdata = (__le32 *) garmin_data_p->inbuffer; in gsp_rec_packet()
392 usb_serial_debug_data(&garmin_data_p->port->dev, __func__, in gsp_rec_packet()
426 garmin_write_bulk(garmin_data_p->port, garmin_data_p->inbuffer, in gsp_rec_packet()
431 if (isAbortTrfCmnd(garmin_data_p->inbuffer)) { in gsp_rec_packet()
432 spin_lock_irqsave(&garmin_data_p->lock, flags); in gsp_rec_packet()
433 garmin_data_p->flags |= FLAGS_DROP_DATA; in gsp_rec_packet()
434 spin_unlock_irqrestore(&garmin_data_p->lock, flags); in gsp_rec_packet()
435 pkt_clear(garmin_data_p); in gsp_rec_packet()
461 static int gsp_receive(struct garmin_data *garmin_data_p, in gsp_receive() argument
464 struct device *dev = &garmin_data_p->port->dev; in gsp_receive()
478 spin_lock_irqsave(&garmin_data_p->lock, flags); in gsp_receive()
479 dest = garmin_data_p->inbuffer; in gsp_receive()
480 size = garmin_data_p->insize; in gsp_receive()
481 dleSeen = garmin_data_p->flags & FLAGS_GSP_DLESEEN; in gsp_receive()
482 skip = garmin_data_p->flags & FLAGS_GSP_SKIP; in gsp_receive()
483 spin_unlock_irqrestore(&garmin_data_p->lock, flags); in gsp_receive()
522 gsp_rec_packet(garmin_data_p, size); in gsp_receive()
549 spin_lock_irqsave(&garmin_data_p->lock, flags); in gsp_receive()
551 garmin_data_p->insize = size; in gsp_receive()
555 garmin_data_p->flags |= FLAGS_GSP_SKIP; in gsp_receive()
557 garmin_data_p->flags &= ~FLAGS_GSP_SKIP; in gsp_receive()
560 garmin_data_p->flags |= FLAGS_GSP_DLESEEN; in gsp_receive()
562 garmin_data_p->flags &= ~FLAGS_GSP_DLESEEN; in gsp_receive()
564 spin_unlock_irqrestore(&garmin_data_p->lock, flags); in gsp_receive()
567 if (gsp_next_packet(garmin_data_p) > 0) in gsp_receive()
568 garmin_data_p->state = STATE_ACTIVE; in gsp_receive()
570 garmin_data_p->state = STATE_GSP_WAIT_DATA; in gsp_receive()
584 static int gsp_send(struct garmin_data *garmin_data_p, in gsp_send() argument
587 struct device *dev = &garmin_data_p->port->dev; in gsp_send()
597 garmin_data_p->state, count); in gsp_send()
599 k = garmin_data_p->outsize; in gsp_send()
602 garmin_data_p->outsize = 0; in gsp_send()
606 memcpy(garmin_data_p->outbuffer+k, buf, count); in gsp_send()
608 garmin_data_p->outsize = k; in gsp_send()
611 pktid = getPacketId(garmin_data_p->outbuffer); in gsp_send()
612 datalen = getDataLength(garmin_data_p->outbuffer); in gsp_send()
624 usb_serial_debug_data(&garmin_data_p->port->dev, __func__, k, in gsp_send()
625 garmin_data_p->outbuffer); in gsp_send()
627 garmin_data_p->outsize = 0; in gsp_send()
629 if (getLayerId(garmin_data_p->outbuffer) != GARMIN_LAYERID_APPL) { in gsp_send()
631 getLayerId(garmin_data_p->outbuffer)); in gsp_send()
648 src = garmin_data_p->outbuffer+GARMIN_PKTHDR_LENGTH; in gsp_send()
654 src = garmin_data_p->outbuffer+GARMIN_PKTHDR_LENGTH; in gsp_send()
658 dst = garmin_data_p->outbuffer+GPS_OUT_BUFSIZ-datalen; in gsp_send()
663 dst = garmin_data_p->outbuffer; in gsp_send()
688 i = dst-garmin_data_p->outbuffer; in gsp_send()
690 send_to_tty(garmin_data_p->port, garmin_data_p->outbuffer, i); in gsp_send()
692 garmin_data_p->pkt_id = pktid; in gsp_send()
693 garmin_data_p->state = STATE_WAIT_TTY_ACK; in gsp_send()
702 static int gsp_next_packet(struct garmin_data *garmin_data_p) in gsp_next_packet() argument
707 while ((pkt = pkt_pop(garmin_data_p)) != NULL) { in gsp_next_packet()
708 dev_dbg(&garmin_data_p->port->dev, "%s - next pkt: %d\n", __func__, pkt->seq); in gsp_next_packet()
709 result = gsp_send(garmin_data_p, pkt->data, pkt->size); in gsp_next_packet()
734 static int nat_receive(struct garmin_data *garmin_data_p, in nat_receive() argument
745 if (garmin_data_p->insize >= GARMIN_PKTHDR_LENGTH) in nat_receive()
747 +getDataLength(garmin_data_p->inbuffer); in nat_receive()
754 dev_dbg(&garmin_data_p->port->dev, in nat_receive()
757 garmin_data_p->insize = 0; in nat_receive()
761 len -= garmin_data_p->insize; in nat_receive()
765 dest = garmin_data_p->inbuffer in nat_receive()
766 + garmin_data_p->insize; in nat_receive()
768 garmin_data_p->insize += len; in nat_receive()
774 if (garmin_data_p->insize >= GARMIN_PKTHDR_LENGTH) { in nat_receive()
776 getDataLength(garmin_data_p->inbuffer); in nat_receive()
777 if (garmin_data_p->insize >= len) { in nat_receive()
778 garmin_write_bulk(garmin_data_p->port, in nat_receive()
779 garmin_data_p->inbuffer, in nat_receive()
781 garmin_data_p->insize = 0; in nat_receive()
785 if (isAbortTrfCmnd(garmin_data_p->inbuffer)) { in nat_receive()
786 spin_lock_irqsave(&garmin_data_p->lock, in nat_receive()
788 garmin_data_p->flags |= FLAGS_DROP_DATA; in nat_receive()
790 &garmin_data_p->lock, flags); in nat_receive()
791 pkt_clear(garmin_data_p); in nat_receive()
806 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); in priv_status_resp() local
807 __le32 *pkt = (__le32 *)garmin_data_p->privpkt; in priv_status_resp()
813 pkt[4] = __cpu_to_le32(garmin_data_p->mode); in priv_status_resp()
814 pkt[5] = __cpu_to_le32(garmin_data_p->serial_num); in priv_status_resp()
828 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); in process_resetdev_request() local
830 spin_lock_irqsave(&garmin_data_p->lock, flags); in process_resetdev_request()
831 garmin_data_p->flags &= ~(CLEAR_HALT_REQUIRED); in process_resetdev_request()
832 garmin_data_p->state = STATE_RESET; in process_resetdev_request()
833 garmin_data_p->serial_num = 0; in process_resetdev_request()
834 spin_unlock_irqrestore(&garmin_data_p->lock, flags); in process_resetdev_request()
850 static int garmin_clear(struct garmin_data *garmin_data_p) in garmin_clear() argument
855 pkt_clear(garmin_data_p); in garmin_clear()
857 spin_lock_irqsave(&garmin_data_p->lock, flags); in garmin_clear()
858 garmin_data_p->insize = 0; in garmin_clear()
859 garmin_data_p->outsize = 0; in garmin_clear()
860 spin_unlock_irqrestore(&garmin_data_p->lock, flags); in garmin_clear()
868 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); in garmin_init_session() local
886 garmin_data_p->state = STATE_ACTIVE; in garmin_init_session()
898 usb_kill_anchored_urbs(&garmin_data_p->write_urbs); in garmin_init_session()
910 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); in garmin_open() local
912 spin_lock_irqsave(&garmin_data_p->lock, flags); in garmin_open()
913 garmin_data_p->mode = initial_mode; in garmin_open()
914 garmin_data_p->count = 0; in garmin_open()
915 garmin_data_p->flags &= FLAGS_SESSION_REPLY1_SEEN; in garmin_open()
916 spin_unlock_irqrestore(&garmin_data_p->lock, flags); in garmin_open()
921 if (garmin_data_p->state == STATE_RESET) in garmin_open()
924 garmin_data_p->state = STATE_ACTIVE; in garmin_open()
931 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); in garmin_close() local
934 __func__, garmin_data_p->mode, garmin_data_p->state, in garmin_close()
935 garmin_data_p->flags); in garmin_close()
937 garmin_clear(garmin_data_p); in garmin_close()
941 usb_kill_anchored_urbs(&garmin_data_p->write_urbs); in garmin_close()
944 if (garmin_data_p->state != STATE_RESET) in garmin_close()
945 garmin_data_p->state = STATE_DISCONNECTED; in garmin_close()
954 struct garmin_data *garmin_data_p = in garmin_write_bulk_callback() local
959 if (garmin_data_p->mode == MODE_GARMIN_SERIAL) { in garmin_write_bulk_callback()
960 gsp_send_ack(garmin_data_p, in garmin_write_bulk_callback()
981 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); in garmin_write_bulk() local
986 spin_lock_irqsave(&garmin_data_p->lock, flags); in garmin_write_bulk()
987 garmin_data_p->flags &= ~FLAGS_DROP_DATA; in garmin_write_bulk()
988 spin_unlock_irqrestore(&garmin_data_p->lock, flags); in garmin_write_bulk()
1012 spin_lock_irqsave(&garmin_data_p->lock, flags); in garmin_write_bulk()
1013 garmin_data_p->flags |= APP_REQ_SEEN; in garmin_write_bulk()
1014 spin_unlock_irqrestore(&garmin_data_p->lock, flags); in garmin_write_bulk()
1016 if (garmin_data_p->mode == MODE_GARMIN_SERIAL) { in garmin_write_bulk()
1017 pkt_clear(garmin_data_p); in garmin_write_bulk()
1018 garmin_data_p->state = STATE_GSP_WAIT_DATA; in garmin_write_bulk()
1023 usb_anchor_urb(urb, &garmin_data_p->write_urbs); in garmin_write_bulk()
1046 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); in garmin_write() local
1047 __le32 *privpkt = (__le32 *)garmin_data_p->privpkt; in garmin_write()
1051 if (garmin_data_p->state == STATE_RESET) in garmin_write()
1060 memcpy(garmin_data_p->privpkt, buf, len); in garmin_write()
1062 pktsiz = getDataLength(garmin_data_p->privpkt); in garmin_write()
1063 pktid = getPacketId(garmin_data_p->privpkt); in garmin_write()
1066 getLayerId(garmin_data_p->privpkt) == in garmin_write()
1073 garmin_clear(garmin_data_p); in garmin_write()
1079 garmin_data_p->mode = __le32_to_cpu(privpkt[3]); in garmin_write()
1081 __func__, garmin_data_p->mode); in garmin_write()
1098 garmin_data_p->mode); in garmin_write()
1105 if (garmin_data_p->mode == MODE_GARMIN_SERIAL) { in garmin_write()
1106 return gsp_receive(garmin_data_p, buf, count); in garmin_write()
1108 return nat_receive(garmin_data_p, buf, count); in garmin_write()
1119 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); in garmin_write_room() local
1120 return GPS_OUT_BUFSIZ-garmin_data_p->outsize; in garmin_write_room()
1124 static void garmin_read_process(struct garmin_data *garmin_data_p, in garmin_read_process() argument
1130 if (garmin_data_p->flags & FLAGS_DROP_DATA) { in garmin_read_process()
1132 dev_dbg(&garmin_data_p->port->dev, "%s - pkt dropped\n", __func__); in garmin_read_process()
1133 } else if (garmin_data_p->state != STATE_DISCONNECTED && in garmin_read_process()
1134 garmin_data_p->state != STATE_RESET) { in garmin_read_process()
1139 if (garmin_data_p->flags & FLAGS_QUEUING) { in garmin_read_process()
1140 pkt_add(garmin_data_p, data, data_length); in garmin_read_process()
1144 spin_lock_irqsave(&garmin_data_p->lock, flags); in garmin_read_process()
1145 garmin_data_p->flags |= APP_RESP_SEEN; in garmin_read_process()
1146 spin_unlock_irqrestore(&garmin_data_p->lock, flags); in garmin_read_process()
1148 if (garmin_data_p->mode == MODE_GARMIN_SERIAL) { in garmin_read_process()
1149 pkt_add(garmin_data_p, data, data_length); in garmin_read_process()
1151 send_to_tty(garmin_data_p->port, data, in garmin_read_process()
1164 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); in garmin_read_bulk_callback() local
1177 garmin_read_process(garmin_data_p, data, urb->actual_length, 1); in garmin_read_bulk_callback()
1180 (garmin_data_p->flags & FLAGS_BULK_IN_RESTART) != 0) { in garmin_read_bulk_callback()
1181 spin_lock_irqsave(&garmin_data_p->lock, flags); in garmin_read_bulk_callback()
1182 garmin_data_p->flags &= ~FLAGS_BULK_IN_RESTART; in garmin_read_bulk_callback()
1183 spin_unlock_irqrestore(&garmin_data_p->lock, flags); in garmin_read_bulk_callback()
1191 if ((garmin_data_p->flags & FLAGS_THROTTLED) == 0) { in garmin_read_bulk_callback()
1200 spin_lock_irqsave(&garmin_data_p->lock, flags); in garmin_read_bulk_callback()
1201 garmin_data_p->flags &= ~FLAGS_BULK_IN_ACTIVE; in garmin_read_bulk_callback()
1202 spin_unlock_irqrestore(&garmin_data_p->lock, flags); in garmin_read_bulk_callback()
1212 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); in garmin_read_int_callback() local
1242 if ((garmin_data_p->flags & FLAGS_BULK_IN_ACTIVE) == 0) { in garmin_read_int_callback()
1251 spin_lock_irqsave(&garmin_data_p->lock, flags); in garmin_read_int_callback()
1252 garmin_data_p->flags |= FLAGS_BULK_IN_ACTIVE; in garmin_read_int_callback()
1253 spin_unlock_irqrestore(&garmin_data_p->lock, in garmin_read_int_callback()
1258 spin_lock_irqsave(&garmin_data_p->lock, flags); in garmin_read_int_callback()
1259 garmin_data_p->flags |= FLAGS_BULK_IN_RESTART; in garmin_read_int_callback()
1260 spin_unlock_irqrestore(&garmin_data_p->lock, flags); in garmin_read_int_callback()
1267 spin_lock_irqsave(&garmin_data_p->lock, flags); in garmin_read_int_callback()
1268 garmin_data_p->flags |= FLAGS_SESSION_REPLY1_SEEN; in garmin_read_int_callback()
1269 spin_unlock_irqrestore(&garmin_data_p->lock, flags); in garmin_read_int_callback()
1272 garmin_data_p->serial_num = __le32_to_cpup( in garmin_read_int_callback()
1276 __func__, garmin_data_p->serial_num); in garmin_read_int_callback()
1279 garmin_read_process(garmin_data_p, data, urb->actual_length, 0); in garmin_read_int_callback()
1294 static int garmin_flush_queue(struct garmin_data *garmin_data_p) in garmin_flush_queue() argument
1299 if ((garmin_data_p->flags & FLAGS_THROTTLED) == 0) { in garmin_flush_queue()
1300 pkt = pkt_pop(garmin_data_p); in garmin_flush_queue()
1302 send_to_tty(garmin_data_p->port, pkt->data, pkt->size); in garmin_flush_queue()
1304 mod_timer(&garmin_data_p->timer, (1)+jiffies); in garmin_flush_queue()
1307 spin_lock_irqsave(&garmin_data_p->lock, flags); in garmin_flush_queue()
1308 garmin_data_p->flags &= ~FLAGS_QUEUING; in garmin_flush_queue()
1309 spin_unlock_irqrestore(&garmin_data_p->lock, flags); in garmin_flush_queue()
1319 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); in garmin_throttle() local
1323 spin_lock_irq(&garmin_data_p->lock); in garmin_throttle()
1324 garmin_data_p->flags |= FLAGS_QUEUING|FLAGS_THROTTLED; in garmin_throttle()
1325 spin_unlock_irq(&garmin_data_p->lock); in garmin_throttle()
1332 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); in garmin_unthrottle() local
1335 spin_lock_irq(&garmin_data_p->lock); in garmin_unthrottle()
1336 garmin_data_p->flags &= ~FLAGS_THROTTLED; in garmin_unthrottle()
1337 spin_unlock_irq(&garmin_data_p->lock); in garmin_unthrottle()
1341 if (garmin_data_p->mode == MODE_NATIVE) in garmin_unthrottle()
1342 garmin_flush_queue(garmin_data_p); in garmin_unthrottle()
1344 if ((garmin_data_p->flags & FLAGS_BULK_IN_ACTIVE) != 0) { in garmin_unthrottle()
1360 struct garmin_data *garmin_data_p = from_timer(garmin_data_p, t, timer); in timeout_handler() local
1363 if (garmin_data_p->mode == MODE_NATIVE) in timeout_handler()
1364 if (garmin_data_p->flags & FLAGS_QUEUING) in timeout_handler()
1365 garmin_flush_queue(garmin_data_p); in timeout_handler()
1373 struct garmin_data *garmin_data_p; in garmin_port_probe() local
1375 garmin_data_p = kzalloc(sizeof(struct garmin_data), GFP_KERNEL); in garmin_port_probe()
1376 if (!garmin_data_p) in garmin_port_probe()
1379 timer_setup(&garmin_data_p->timer, timeout_handler, 0); in garmin_port_probe()
1380 spin_lock_init(&garmin_data_p->lock); in garmin_port_probe()
1381 INIT_LIST_HEAD(&garmin_data_p->pktlist); in garmin_port_probe()
1382 garmin_data_p->port = port; in garmin_port_probe()
1383 garmin_data_p->state = 0; in garmin_port_probe()
1384 garmin_data_p->flags = 0; in garmin_port_probe()
1385 garmin_data_p->count = 0; in garmin_port_probe()
1386 init_usb_anchor(&garmin_data_p->write_urbs); in garmin_port_probe()
1387 usb_set_serial_port_data(port, garmin_data_p); in garmin_port_probe()
1395 kfree(garmin_data_p); in garmin_port_probe()
1403 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); in garmin_port_remove() local
1405 usb_kill_anchored_urbs(&garmin_data_p->write_urbs); in garmin_port_remove()
1407 timer_shutdown_sync(&garmin_data_p->timer); in garmin_port_remove()
1408 kfree(garmin_data_p); in garmin_port_remove()