garmin_gps: Coding style

Signed-off-by: Alan Cox <alan@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Alan Cox 2008-07-22 11:11:44 +01:00 committed by Linus Torvalds
parent 64701e8122
commit af6d780b57

View File

@ -33,7 +33,7 @@
#include <linux/tty_flip.h> #include <linux/tty_flip.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <asm/uaccess.h> #include <linux/uaccess.h>
#include <asm/atomic.h> #include <asm/atomic.h>
#include <linux/usb.h> #include <linux/usb.h>
#include <linux/usb/serial.h> #include <linux/usb/serial.h>
@ -44,7 +44,7 @@
static int initial_mode = 1; static int initial_mode = 1;
/* debug flag */ /* debug flag */
static int debug = 0; static int debug;
#define GARMIN_VENDOR_ID 0x091E #define GARMIN_VENDOR_ID 0x091E
@ -65,37 +65,37 @@ static int debug = 0;
#define EINVPKT 1000 /* invalid packet structure */ #define EINVPKT 1000 /* invalid packet structure */
// size of the header of a packet using the usb protocol /* size of the header of a packet using the usb protocol */
#define GARMIN_PKTHDR_LENGTH 12 #define GARMIN_PKTHDR_LENGTH 12
// max. possible size of a packet using the serial protocol /* max. possible size of a packet using the serial protocol */
#define MAX_SERIAL_PKT_SIZ (3 + 255 + 3) #define MAX_SERIAL_PKT_SIZ (3 + 255 + 3)
// max. possible size of a packet with worst case stuffing /* max. possible size of a packet with worst case stuffing */
#define MAX_SERIAL_PKT_SIZ_STUFFED MAX_SERIAL_PKT_SIZ+256 #define MAX_SERIAL_PKT_SIZ_STUFFED (MAX_SERIAL_PKT_SIZ + 256)
// size of a buffer able to hold a complete (no stuffing) packet /* size of a buffer able to hold a complete (no stuffing) packet
// (the document protocol does not contain packets with a larger * (the document protocol does not contain packets with a larger
// size, but in theory a packet may be 64k+12 bytes - if in * size, but in theory a packet may be 64k+12 bytes - if in
// later protocol versions larger packet sizes occur, this value * later protocol versions larger packet sizes occur, this value
// should be increased accordingly, so the input buffer is always * should be increased accordingly, so the input buffer is always
// large enough the store a complete packet inclusive header) * large enough the store a complete packet inclusive header) */
#define GPS_IN_BUFSIZ (GARMIN_PKTHDR_LENGTH+MAX_SERIAL_PKT_SIZ) #define GPS_IN_BUFSIZ (GARMIN_PKTHDR_LENGTH+MAX_SERIAL_PKT_SIZ)
// size of a buffer able to hold a complete (incl. stuffing) packet /* size of a buffer able to hold a complete (incl. stuffing) packet */
#define GPS_OUT_BUFSIZ (GARMIN_PKTHDR_LENGTH+MAX_SERIAL_PKT_SIZ_STUFFED) #define GPS_OUT_BUFSIZ (GARMIN_PKTHDR_LENGTH+MAX_SERIAL_PKT_SIZ_STUFFED)
// where to place the packet id of a serial packet, so we can /* where to place the packet id of a serial packet, so we can
// prepend the usb-packet header without the need to move the * prepend the usb-packet header without the need to move the
// packets data * packets data */
#define GSP_INITIAL_OFFSET (GARMIN_PKTHDR_LENGTH-2) #define GSP_INITIAL_OFFSET (GARMIN_PKTHDR_LENGTH-2)
// max. size of incoming private packets (header+1 param) /* max. size of incoming private packets (header+1 param) */
#define PRIVPKTSIZ (GARMIN_PKTHDR_LENGTH+4) #define PRIVPKTSIZ (GARMIN_PKTHDR_LENGTH+4)
#define GARMIN_LAYERID_TRANSPORT 0 #define GARMIN_LAYERID_TRANSPORT 0
#define GARMIN_LAYERID_APPL 20 #define GARMIN_LAYERID_APPL 20
// our own layer-id to use for some control mechanisms /* our own layer-id to use for some control mechanisms */
#define GARMIN_LAYERID_PRIVATE 0x01106E4B #define GARMIN_LAYERID_PRIVATE 0x01106E4B
#define GARMIN_PKTID_PVT_DATA 51 #define GARMIN_PKTID_PVT_DATA 51
@ -103,7 +103,7 @@ static int debug = 0;
#define CMND_ABORT_TRANSFER 0 #define CMND_ABORT_TRANSFER 0
// packet ids used in private layer /* packet ids used in private layer */
#define PRIV_PKTID_SET_DEBUG 1 #define PRIV_PKTID_SET_DEBUG 1
#define PRIV_PKTID_SET_MODE 2 #define PRIV_PKTID_SET_MODE 2
#define PRIV_PKTID_INFO_REQ 3 #define PRIV_PKTID_INFO_REQ 3
@ -121,7 +121,8 @@ static int debug = 0;
struct garmin_packet { struct garmin_packet {
struct list_head list; struct list_head list;
int seq; int seq;
int size; // the real size of the data array, always > 0 /* the real size of the data array, always > 0 */
int size;
__u8 data[1]; __u8 data[1];
}; };
@ -164,7 +165,7 @@ struct garmin_data {
#define MODE_NATIVE 0 #define MODE_NATIVE 0
#define MODE_GARMIN_SERIAL 1 #define MODE_GARMIN_SERIAL 1
// Flags used in garmin_data.flags: /* Flags used in garmin_data.flags: */
#define FLAGS_SESSION_REPLY_MASK 0x00C0 #define FLAGS_SESSION_REPLY_MASK 0x00C0
#define FLAGS_SESSION_REPLY1_SEEN 0x0080 #define FLAGS_SESSION_REPLY1_SEEN 0x0080
#define FLAGS_SESSION_REPLY2_SEEN 0x0040 #define FLAGS_SESSION_REPLY2_SEEN 0x0040
@ -217,7 +218,8 @@ static unsigned char const PRIVATE_REQ[]
static struct usb_device_id id_table [] = { static struct usb_device_id id_table [] = {
/* the same device id seems to be used by all usb enabled gps devices */ /* the same device id seems to be used by all
usb enabled GPS devices */
{ USB_DEVICE(GARMIN_VENDOR_ID, 3) }, { USB_DEVICE(GARMIN_VENDOR_ID, 3) },
{ } /* Terminating entry */ { } /* Terminating entry */
}; };
@ -235,7 +237,8 @@ static struct usb_driver garmin_driver = {
static inline int noResponseFromAppLayer(struct garmin_data *garmin_data_p) static inline int noResponseFromAppLayer(struct garmin_data *garmin_data_p)
{ {
return atomic_read(&garmin_data_p->req_count) == atomic_read(&garmin_data_p->resp_count); return atomic_read(&garmin_data_p->req_count) ==
atomic_read(&garmin_data_p->resp_count);
} }
@ -325,10 +328,9 @@ static int pkt_add(struct garmin_data * garmin_data_p,
/* in serial mode, if someone is waiting for data from /* in serial mode, if someone is waiting for data from
the device, iconvert and send the next packet to tty. */ the device, iconvert and send the next packet to tty. */
if (result && (state == STATE_GSP_WAIT_DATA)) { if (result && (state == STATE_GSP_WAIT_DATA))
gsp_next_packet(garmin_data_p); gsp_next_packet(garmin_data_p);
} }
}
return result; return result;
} }
@ -391,9 +393,8 @@ static int gsp_send_ack(struct garmin_data * garmin_data_p, __u8 pkt_id)
*ptr++ = pkt_id; *ptr++ = pkt_id;
cksum += pkt_id; cksum += pkt_id;
if (pkt_id == DLE) { if (pkt_id == DLE)
*ptr++ = DLE; *ptr++ = DLE;
}
*ptr++ = 0; *ptr++ = 0;
*ptr++ = 0xFF & (-cksum); *ptr++ = 0xFF & (-cksum);
@ -440,7 +441,7 @@ static int gsp_rec_packet(struct garmin_data * garmin_data_p, int count)
cksum += *recpkt++; cksum += *recpkt++;
cksum += *recpkt++; cksum += *recpkt++;
// sanity check, remove after test ... /* sanity check, remove after test ... */
if ((__u8 *)&(usbdata[3]) != recpkt) { if ((__u8 *)&(usbdata[3]) != recpkt) {
dbg("%s - ptr mismatch %p - %p", dbg("%s - ptr mismatch %p - %p",
__func__, &(usbdata[4]), recpkt); __func__, &(usbdata[4]), recpkt);
@ -504,10 +505,11 @@ static int gsp_receive(struct garmin_data * garmin_data_p,
int i = 0; int i = 0;
__u8 *dest; __u8 *dest;
int size; int size;
// dleSeen: set if last byte read was a DLE /* dleSeen: set if last byte read was a DLE */
int dleSeen; int dleSeen;
// skip: if set, skip incoming data until possible start of /* skip: if set, skip incoming data until possible start of
// new packet * new packet
*/
int skip; int skip;
__u8 data; __u8 data;
@ -521,9 +523,8 @@ static int gsp_receive(struct garmin_data * garmin_data_p,
dbg("%s - dle=%d skip=%d size=%d count=%d", dbg("%s - dle=%d skip=%d size=%d count=%d",
__func__, dleSeen, skip, size, count); __func__, dleSeen, skip, size, count);
if (size == 0) { if (size == 0)
size = GSP_INITIAL_OFFSET; size = GSP_INITIAL_OFFSET;
}
while (offs < count) { while (offs < count) {
@ -554,8 +555,7 @@ static int gsp_receive(struct garmin_data * garmin_data_p,
ack_or_nak_seen = NAK; ack_or_nak_seen = NAK;
dbg("NAK packet complete."); dbg("NAK packet complete.");
} else { } else {
dbg("packet complete " dbg("packet complete - id=0x%X.",
"- id=0x%X.",
0xFF & data); 0xFF & data);
gsp_rec_packet(garmin_data_p, size); gsp_rec_packet(garmin_data_p, size);
} }
@ -589,7 +589,7 @@ static int gsp_receive(struct garmin_data * garmin_data_p,
garmin_data_p->insize = size; garmin_data_p->insize = size;
// copy flags back to structure /* copy flags back to structure */
if (skip) if (skip)
garmin_data_p->flags |= FLAGS_GSP_SKIP; garmin_data_p->flags |= FLAGS_GSP_SKIP;
else else
@ -600,16 +600,13 @@ static int gsp_receive(struct garmin_data * garmin_data_p,
else else
garmin_data_p->flags &= ~FLAGS_GSP_DLESEEN; garmin_data_p->flags &= ~FLAGS_GSP_DLESEEN;
if (ack_or_nak_seen) { if (ack_or_nak_seen)
garmin_data_p->state = STATE_GSP_WAIT_DATA; garmin_data_p->state = STATE_GSP_WAIT_DATA;
}
spin_unlock_irqrestore(&garmin_data_p->lock, flags); spin_unlock_irqrestore(&garmin_data_p->lock, flags);
if (ack_or_nak_seen) { if (ack_or_nak_seen)
gsp_next_packet(garmin_data_p); gsp_next_packet(garmin_data_p);
}
return count; return count;
} }
@ -658,8 +655,7 @@ static int gsp_send(struct garmin_data * garmin_data_p,
return 0; return 0;
} }
dbg("%s - %d bytes in buffer, %d bytes in pkt.", __func__, dbg("%s - %d bytes in buffer, %d bytes in pkt.", __func__, k, i);
k, i);
/* garmin_data_p->outbuffer now contains a complete packet */ /* garmin_data_p->outbuffer now contains a complete packet */
@ -784,7 +780,7 @@ static int nat_receive(struct garmin_data * garmin_data_p,
int len; int len;
while (offs < count) { while (offs < count) {
// if buffer contains header, copy rest of data /* if buffer contains header, copy rest of data */
if (garmin_data_p->insize >= GARMIN_PKTHDR_LENGTH) if (garmin_data_p->insize >= GARMIN_PKTHDR_LENGTH)
len = GARMIN_PKTHDR_LENGTH len = GARMIN_PKTHDR_LENGTH
+getDataLength(garmin_data_p->inbuffer); +getDataLength(garmin_data_p->inbuffer);
@ -792,9 +788,9 @@ static int nat_receive(struct garmin_data * garmin_data_p,
len = GARMIN_PKTHDR_LENGTH; len = GARMIN_PKTHDR_LENGTH;
if (len >= GPS_IN_BUFSIZ) { if (len >= GPS_IN_BUFSIZ) {
/* seem to be an invalid packet, ignore rest of input */ /* seems to be an invalid packet, ignore rest
dbg("%s - packet size too large: %d", of input */
__func__, len); dbg("%s - packet size too large: %d", __func__, len);
garmin_data_p->insize = 0; garmin_data_p->insize = 0;
count = 0; count = 0;
result = -EINVPKT; result = -EINVPKT;
@ -824,9 +820,11 @@ static int nat_receive(struct garmin_data * garmin_data_p,
/* if this was an abort-transfer command, /* if this was an abort-transfer command,
flush all queued data. */ flush all queued data. */
if (isAbortTrfCmnd(garmin_data_p->inbuffer)) { if (isAbortTrfCmnd(garmin_data_p->inbuffer)) {
spin_lock_irqsave(&garmin_data_p->lock, flags); spin_lock_irqsave(&garmin_data_p->lock,
flags);
garmin_data_p->flags |= FLAGS_DROP_DATA; garmin_data_p->flags |= FLAGS_DROP_DATA;
spin_unlock_irqrestore(&garmin_data_p->lock, flags); spin_unlock_irqrestore(
&garmin_data_p->lock, flags);
pkt_clear(garmin_data_p); pkt_clear(garmin_data_p);
} }
} }
@ -896,8 +894,7 @@ static int garmin_clear(struct garmin_data * garmin_data_p)
if (port != NULL && atomic_read(&garmin_data_p->resp_count)) { if (port != NULL && atomic_read(&garmin_data_p->resp_count)) {
/* send a terminate command */ /* send a terminate command */
status = garmin_write_bulk(port, GARMIN_STOP_TRANSFER_REQ, status = garmin_write_bulk(port, GARMIN_STOP_TRANSFER_REQ,
sizeof(GARMIN_STOP_TRANSFER_REQ), sizeof(GARMIN_STOP_TRANSFER_REQ), 1);
1);
} }
/* flush all queued data */ /* flush all queued data */
@ -931,8 +928,7 @@ static int garmin_init_session(struct usb_serial_port *port)
status = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); status = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
if (status) if (status)
dev_err(&serial->dev->dev, dev_err(&serial->dev->dev,
"%s - failed submitting interrupt urb," "%s - failed submitting interrupt urb, error %d\n",
" error %d\n",
__func__, status); __func__, status);
} }
@ -940,8 +936,7 @@ static int garmin_init_session(struct usb_serial_port *port)
dbg("%s - starting session ...", __func__); dbg("%s - starting session ...", __func__);
garmin_data_p->state = STATE_ACTIVE; garmin_data_p->state = STATE_ACTIVE;
status = garmin_write_bulk(port, GARMIN_START_SESSION_REQ, status = garmin_write_bulk(port, GARMIN_START_SESSION_REQ,
sizeof(GARMIN_START_SESSION_REQ), sizeof(GARMIN_START_SESSION_REQ), 0);
0);
if (status >= 0) { if (status >= 0) {
@ -952,13 +947,13 @@ static int garmin_init_session(struct usb_serial_port *port)
/* not needed, but the win32 driver does it too ... */ /* not needed, but the win32 driver does it too ... */
status = garmin_write_bulk(port, status = garmin_write_bulk(port,
GARMIN_START_SESSION_REQ2, GARMIN_START_SESSION_REQ2,
sizeof(GARMIN_START_SESSION_REQ2), sizeof(GARMIN_START_SESSION_REQ2), 0);
0);
if (status >= 0) { if (status >= 0) {
status = 0; status = 0;
spin_lock_irqsave(&garmin_data_p->lock, flags); spin_lock_irqsave(&garmin_data_p->lock, flags);
garmin_data_p->ignorePkts++; garmin_data_p->ignorePkts++;
spin_unlock_irqrestore(&garmin_data_p->lock, flags); spin_unlock_irqrestore(&garmin_data_p->lock,
flags);
} }
} }
} }
@ -1049,13 +1044,15 @@ static void garmin_write_bulk_callback (struct urb *urb)
int status = urb->status; int status = urb->status;
if (port) { if (port) {
struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); struct garmin_data *garmin_data_p =
usb_get_serial_port_data(port);
dbg("%s - port %d", __func__, port->number); dbg("%s - port %d", __func__, port->number);
if (GARMIN_LAYERID_APPL == getLayerId(urb->transfer_buffer) if (GARMIN_LAYERID_APPL == getLayerId(urb->transfer_buffer)
&& (garmin_data_p->mode == MODE_GARMIN_SERIAL)) { && (garmin_data_p->mode == MODE_GARMIN_SERIAL)) {
gsp_send_ack(garmin_data_p, ((__u8 *)urb->transfer_buffer)[4]); gsp_send_ack(garmin_data_p,
((__u8 *)urb->transfer_buffer)[4]);
} }
if (status) { if (status) {
@ -1069,7 +1066,8 @@ static void garmin_write_bulk_callback (struct urb *urb)
usb_serial_port_softint(port); usb_serial_port_softint(port);
} }
/* Ignore errors that resulted from garmin_write_bulk with dismiss_ack=1 */ /* Ignore errors that resulted from garmin_write_bulk with
dismiss_ack = 1 */
/* free up the transfer buffer, as usb_free_urb() does not do this */ /* free up the transfer buffer, as usb_free_urb() does not do this */
kfree(urb->transfer_buffer); kfree(urb->transfer_buffer);
@ -1131,8 +1129,7 @@ static int garmin_write_bulk (struct usb_serial_port *port,
status = usb_submit_urb(urb, GFP_ATOMIC); status = usb_submit_urb(urb, GFP_ATOMIC);
if (status) { if (status) {
dev_err(&port->dev, dev_err(&port->dev,
"%s - usb_submit_urb(write bulk) " "%s - usb_submit_urb(write bulk) failed with status = %d\n",
"failed with status = %d\n",
__func__, status); __func__, status);
count = status; count = status;
} }
@ -1165,12 +1162,13 @@ static int garmin_write (struct tty_struct *tty, struct usb_serial_port *port,
pktid = getPacketId(garmin_data_p->privpkt); pktid = getPacketId(garmin_data_p->privpkt);
if (count == (GARMIN_PKTHDR_LENGTH+pktsiz) if (count == (GARMIN_PKTHDR_LENGTH+pktsiz)
&& GARMIN_LAYERID_PRIVATE == getLayerId(garmin_data_p->privpkt)) { && GARMIN_LAYERID_PRIVATE ==
getLayerId(garmin_data_p->privpkt)) {
dbg("%s - processing private request %d", dbg("%s - processing private request %d",
__func__, pktid); __func__, pktid);
// drop all unfinished transfers /* drop all unfinished transfers */
garmin_clear(garmin_data_p); garmin_clear(garmin_data_p);
switch (pktid) { switch (pktid) {
@ -1256,9 +1254,8 @@ static void garmin_read_process(struct garmin_data * garmin_data_p,
if (garmin_data_p->flags & FLAGS_QUEUING) { if (garmin_data_p->flags & FLAGS_QUEUING) {
pkt_add(garmin_data_p, data, data_length); pkt_add(garmin_data_p, data, data_length);
} else if (garmin_data_p->mode == MODE_GARMIN_SERIAL) { } else if (garmin_data_p->mode == MODE_GARMIN_SERIAL) {
if (getLayerId(data) == GARMIN_LAYERID_APPL) { if (getLayerId(data) == GARMIN_LAYERID_APPL)
pkt_add(garmin_data_p, data, data_length); pkt_add(garmin_data_p, data, data_length);
}
} else { } else {
send_to_tty(garmin_data_p->port, data, data_length); send_to_tty(garmin_data_p->port, data, data_length);
} }
@ -1378,7 +1375,8 @@ static void garmin_read_int_callback (struct urb *urb)
garmin_data_p->flags |= FLAGS_BULK_IN_ACTIVE; garmin_data_p->flags |= FLAGS_BULK_IN_ACTIVE;
/* do not send this packet to the user */ /* do not send this packet to the user */
garmin_data_p->ignorePkts = 1; garmin_data_p->ignorePkts = 1;
spin_unlock_irqrestore(&garmin_data_p->lock, flags); spin_unlock_irqrestore(&garmin_data_p->lock,
flags);
} }
} else { } else {
/* bulk-in transfer still active */ /* bulk-in transfer still active */
@ -1396,8 +1394,8 @@ static void garmin_read_int_callback (struct urb *urb)
spin_unlock_irqrestore(&garmin_data_p->lock, flags); spin_unlock_irqrestore(&garmin_data_p->lock, flags);
/* save the serial number */ /* save the serial number */
garmin_data_p->serial_num garmin_data_p->serial_num = __le32_to_cpup(
= __le32_to_cpup((__le32*)(data+GARMIN_PKTHDR_LENGTH)); (__le32 *)(data+GARMIN_PKTHDR_LENGTH));
dbg("%s - start-of-session reply seen - serial %u.", dbg("%s - start-of-session reply seen - serial %u.",
__func__, garmin_data_p->serial_num); __func__, garmin_data_p->serial_num);
@ -1525,7 +1523,7 @@ static int garmin_attach(struct usb_serial *serial)
init_timer(&garmin_data_p->timer); init_timer(&garmin_data_p->timer);
spin_lock_init(&garmin_data_p->lock); spin_lock_init(&garmin_data_p->lock);
INIT_LIST_HEAD(&garmin_data_p->pktlist); INIT_LIST_HEAD(&garmin_data_p->pktlist);
//garmin_data_p->timer.expires = jiffies + session_timeout; /* garmin_data_p->timer.expires = jiffies + session_timeout; */
garmin_data_p->timer.data = (unsigned long)garmin_data_p; garmin_data_p->timer.data = (unsigned long)garmin_data_p;
garmin_data_p->timer.function = timeout_handler; garmin_data_p->timer.function = timeout_handler;
garmin_data_p->port = port; garmin_data_p->port = port;