arcnet: Expand odd BUGLVL macro with if and uses
[cascardo/linux.git] / drivers / net / arcnet / rfc1201.c
index b71431a..d052976 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Linux ARCnet driver - RFC1201 (standard) packet encapsulation
- * 
+ *
  * Written 1994-1999 by Avery Pennarun.
  * Derived from skeleton.c by Donald Becker.
  *
@@ -34,7 +34,6 @@
 MODULE_LICENSE("GPL");
 #define VERSION "arcnet: RFC1201 \"standard\" (`a') encapsulation support loaded.\n"
 
-
 static __be16 type_trans(struct sk_buff *skb, struct net_device *dev);
 static void rx(struct net_device *dev, int bufnum,
               struct archdr *pkthdr, int length);
@@ -44,8 +43,7 @@ static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length,
                      int bufnum);
 static int continue_tx(struct net_device *dev, int bufnum);
 
-static struct ArcProto rfc1201_proto =
-{
+static struct ArcProto rfc1201_proto = {
        .suffix         = 'a',
        .mtu            = 1500, /* could be more, but some receivers can't handle it... */
        .is_ip          = 1,    /* This is for sending IP and ARP packages */
@@ -56,7 +54,6 @@ static struct ArcProto rfc1201_proto =
        .ack_tx         = NULL
 };
 
-
 static int __init arcnet_rfc1201_init(void)
 {
        printk(VERSION);
@@ -84,14 +81,13 @@ static void __exit arcnet_rfc1201_exit(void)
 module_init(arcnet_rfc1201_init);
 module_exit(arcnet_rfc1201_exit);
 
-/*
- * Determine a packet's protocol ID.
- * 
+/* Determine a packet's protocol ID.
+ *
  * With ARCnet we have to convert everything to Ethernet-style stuff.
  */
 static __be16 type_trans(struct sk_buff *skb, struct net_device *dev)
 {
-       struct archdr *pkt = (struct archdr *) skb->data;
+       struct archdr *pkt = (struct archdr *)skb->data;
        struct arc_rfc1201 *soft = &pkt->soft.rfc1201;
        int hdr_size = ARC_HDR_SIZE + RFC1201_HDR_SIZE;
 
@@ -99,9 +95,9 @@ static __be16 type_trans(struct sk_buff *skb, struct net_device *dev)
        skb_reset_mac_header(skb);
        skb_pull(skb, hdr_size);
 
-       if (pkt->hard.dest == 0)
+       if (pkt->hard.dest == 0) {
                skb->pkt_type = PACKET_BROADCAST;
-       else if (dev->flags & IFF_PROMISC) {
+       else if (dev->flags & IFF_PROMISC) {
                /* if we're not sending to ourselves :) */
                if (pkt->hard.dest != dev->dev_addr[0])
                        skb->pkt_type = PACKET_OTHERHOST;
@@ -129,7 +125,6 @@ static __be16 type_trans(struct sk_buff *skb, struct net_device *dev)
        return htons(ETH_P_IP);
 }
 
-
 /* packet receiver */
 static void rx(struct net_device *dev, int bufnum,
               struct archdr *pkthdr, int length)
@@ -149,9 +144,9 @@ static void rx(struct net_device *dev, int bufnum,
                ofs = 256 - length;
 
        if (soft->split_flag == 0xFF) {         /* Exception Packet */
-               if (length >= 4 + RFC1201_HDR_SIZE)
+               if (length >= 4 + RFC1201_HDR_SIZE) {
                        BUGMSG(D_DURING, "compensating for exception packet\n");
-               else {
+               else {
                        BUGMSG(D_EXTRA, "short RFC1201 exception packet from %02Xh",
                               saddr);
                        return;
@@ -169,7 +164,7 @@ static void rx(struct net_device *dev, int bufnum,
 
                if (in->skb) {  /* already assembling one! */
                        BUGMSG(D_EXTRA, "aborting assembly (seq=%d) for unsplit packet (splitflag=%d, seq=%d)\n",
-                        in->sequence, soft->split_flag, soft->sequence);
+                              in->sequence, soft->split_flag, soft->sequence);
                        lp->rfc1201.aborted_seq = soft->sequence;
                        dev_kfree_skb_irq(in->skb);
                        dev->stats.rx_errors++;
@@ -187,7 +182,7 @@ static void rx(struct net_device *dev, int bufnum,
                skb_put(skb, length + ARC_HDR_SIZE);
                skb->dev = dev;
 
-               pkt = (struct archdr *) skb->data;
+               pkt = (struct archdr *)skb->data;
                soft = &pkt->soft.rfc1201;
 
                /* up to sizeof(pkt->soft) has already been copied from the card */
@@ -197,17 +192,17 @@ static void rx(struct net_device *dev, int bufnum,
                                       pkt->soft.raw + sizeof(pkt->soft),
                                              length - sizeof(pkt->soft));
 
-               /*
-                * ARP packets have problems when sent from some DOS systems: the
-                * source address is always 0!  So we take the hardware source addr
-                * (which is impossible to fumble) and insert it ourselves.
+               /* ARP packets have problems when sent from some DOS systems:
+                * the source address is always 0!
+                * So we take the hardware source addr (which is impossible
+                * to fumble) and insert it ourselves.
                 */
                if (soft->proto == ARC_P_ARP) {
-                       struct arphdr *arp = (struct arphdr *) soft->payload;
+                       struct arphdr *arp = (struct arphdr *)soft->payload;
 
                        /* make sure addresses are the right length */
                        if (arp->ar_hln == 1 && arp->ar_pln == 4) {
-                               uint8_t *cptr = (uint8_t *) arp + sizeof(struct arphdr);
+                               uint8_t *cptr = (uint8_t *)arp + sizeof(struct arphdr);
 
                                if (!*cptr) {   /* is saddr = 00? */
                                        BUGMSG(D_EXTRA,
@@ -226,26 +221,28 @@ static void rx(struct net_device *dev, int bufnum,
                                dev->stats.rx_crc_errors++;
                        }
                }
-               BUGLVL(D_SKB) arcnet_dump_skb(dev, skb, "rx");
+               if (BUGLVL(D_SKB))
+                       arcnet_dump_skb(dev, skb, "rx");
 
                skb->protocol = type_trans(skb, dev);
                netif_rx(skb);
        } else {                /* split packet */
-               /*
-                * NOTE: MSDOS ARP packet correction should only need to apply to
-                * unsplit packets, since ARP packets are so short.
+               /* NOTE: MSDOS ARP packet correction should only need to
+                * apply to unsplit packets, since ARP packets are so short.
                 *
-                * My interpretation of the RFC1201 document is that if a packet is
-                * received out of order, the entire assembly process should be
-                * aborted.
+                * My interpretation of the RFC1201 document is that if a
+                * packet is received out of order, the entire assembly
+                * process should be aborted.
                 *
-                * The RFC also mentions "it is possible for successfully received
-                * packets to be retransmitted." As of 0.40 all previously received
-                * packets are allowed, not just the most recent one.
+                * The RFC also mentions "it is possible for successfully
+                * received packets to be retransmitted." As of 0.40 all
+                * previously received packets are allowed, not just the
+                * most recent one.
                 *
-                * We allow multiple assembly processes, one for each ARCnet card
-                * possible on the network.  Seems rather like a waste of memory,
-                * but there's no other way to be reliable.
+                * We allow multiple assembly processes, one for each
+                * ARCnet card possible on the network.
+                * Seems rather like a waste of memory, but there's no
+                * other way to be reliable.
                 */
 
                BUGMSG(D_RX, "packet is split (splitflag=%d, seq=%d)\n",
@@ -265,8 +262,7 @@ static void rx(struct net_device *dev, int bufnum,
                        BUGMSG(D_RX, "brand new splitpacket (splitflag=%d)\n",
                               soft->split_flag);
                        if (in->skb) {  /* already assembling one! */
-                               BUGMSG(D_EXTRA, "aborting previous (seq=%d) assembly "
-                                      "(splitflag=%d, seq=%d)\n",
+                               BUGMSG(D_EXTRA, "aborting previous (seq=%d) assembly (splitflag=%d, seq=%d)\n",
                                       in->sequence, soft->split_flag,
                                       soft->sequence);
                                dev->stats.rx_errors++;
@@ -274,7 +270,7 @@ static void rx(struct net_device *dev, int bufnum,
                                dev_kfree_skb_irq(in->skb);
                        }
                        in->sequence = soft->sequence;
-                       in->numpackets = ((unsigned) soft->split_flag >> 1) + 2;
+                       in->numpackets = ((unsigned)soft->split_flag >> 1) + 2;
                        in->lastpacket = 1;
 
                        if (in->numpackets > 16) {
@@ -294,7 +290,7 @@ static void rx(struct net_device *dev, int bufnum,
                                return;
                        }
                        skb->dev = dev;
-                       pkt = (struct archdr *) skb->data;
+                       pkt = (struct archdr *)skb->data;
                        soft = &pkt->soft.rfc1201;
 
                        memcpy(pkt, pkthdr, ARC_HDR_SIZE + RFC1201_HDR_SIZE);
@@ -302,16 +298,14 @@ static void rx(struct net_device *dev, int bufnum,
 
                        soft->split_flag = 0;   /* end result won't be split */
                } else {        /* not first packet */
-                       int packetnum = ((unsigned) soft->split_flag >> 1) + 1;
+                       int packetnum = ((unsigned)soft->split_flag >> 1) + 1;
 
-                       /*
-                        * if we're not assembling, there's no point trying to
+                       /* if we're not assembling, there's no point trying to
                         * continue.
                         */
                        if (!in->skb) {
                                if (lp->rfc1201.aborted_seq != soft->sequence) {
-                                       BUGMSG(D_EXTRA, "can't continue split without starting "
-                                              "first! (splitflag=%d, seq=%d, aborted=%d)\n",
+                                       BUGMSG(D_EXTRA, "can't continue split without starting first! (splitflag=%d, seq=%d, aborted=%d)\n",
                                        soft->split_flag, soft->sequence,
                                               lp->rfc1201.aborted_seq);
                                        dev->stats.rx_errors++;
@@ -330,8 +324,7 @@ static void rx(struct net_device *dev, int bufnum,
                                        return;
                                }
                                /* "bad" duplicate, kill reassembly */
-                               BUGMSG(D_EXTRA, "out-of-order splitpacket, reassembly "
-                                      "(seq=%d) aborted (splitflag=%d, seq=%d)\n",
+                               BUGMSG(D_EXTRA, "out-of-order splitpacket, reassembly (seq=%d) aborted (splitflag=%d, seq=%d)\n",
                                       in->sequence, soft->split_flag, soft->sequence);
                                lp->rfc1201.aborted_seq = soft->sequence;
                                dev_kfree_skb_irq(in->skb);
@@ -341,7 +334,7 @@ static void rx(struct net_device *dev, int bufnum,
                                in->lastpacket = in->numpackets = 0;
                                return;
                        }
-                       pkt = (struct archdr *) in->skb->data;
+                       pkt = (struct archdr *)in->skb->data;
                        soft = &pkt->soft.rfc1201;
                }
 
@@ -357,11 +350,12 @@ static void rx(struct net_device *dev, int bufnum,
                        in->skb = NULL;
                        in->lastpacket = in->numpackets = 0;
 
-           BUGMSG(D_SKB_SIZE, "skb: received %d bytes from %02X (unsplit)\n",
-               skb->len, pkt->hard.source);
-           BUGMSG(D_SKB_SIZE, "skb: received %d bytes from %02X (split)\n",
-               skb->len, pkt->hard.source);
-                       BUGLVL(D_SKB) arcnet_dump_skb(dev, skb, "rx");
+                       BUGMSG(D_SKB_SIZE, "skb: received %d bytes from %02X (unsplit)\n",
+                              skb->len, pkt->hard.source);
+                       BUGMSG(D_SKB_SIZE, "skb: received %d bytes from %02X (split)\n",
+                              skb->len, pkt->hard.source);
+                       if (BUGLVL(D_SKB))
+                               arcnet_dump_skb(dev, skb, "rx");
 
                        skb->protocol = type_trans(skb, dev);
                        netif_rx(skb);
@@ -369,14 +363,13 @@ static void rx(struct net_device *dev, int bufnum,
        }
 }
 
-
 /* Create the ARCnet hard/soft headers for RFC1201. */
 static int build_header(struct sk_buff *skb, struct net_device *dev,
                        unsigned short type, uint8_t daddr)
 {
        struct arcnet_local *lp = netdev_priv(dev);
        int hdr_size = ARC_HDR_SIZE + RFC1201_HDR_SIZE;
-       struct archdr *pkt = (struct archdr *) skb_push(skb, hdr_size);
+       struct archdr *pkt = (struct archdr *)skb_push(skb, hdr_size);
        struct arc_rfc1201 *soft = &pkt->soft.rfc1201;
 
        /* set the protocol ID according to RFC1201 */
@@ -409,12 +402,11 @@ static int build_header(struct sk_buff *skb, struct net_device *dev,
                return 0;
        }
 
-       /*
-        * Set the source hardware address.
+       /* Set the source hardware address.
         *
         * This is pretty pointless for most purposes, but it can help in
-        * debugging.  ARCnet does not allow us to change the source address in
-        * the actual packet sent)
+        * debugging.  ARCnet does not allow us to change the source address
+        * in the actual packet sent.
         */
        pkt->hard.source = *dev->dev_addr;
 
@@ -424,10 +416,10 @@ static int build_header(struct sk_buff *skb, struct net_device *dev,
        /* see linux/net/ethernet/eth.c to see where I got the following */
 
        if (dev->flags & (IFF_LOOPBACK | IFF_NOARP)) {
-               /* 
-                * FIXME: fill in the last byte of the dest ipaddr here to better
-                * comply with RFC1051 in "noarp" mode.  For now, always broadcasting
-                * will probably at least get packets sent out :)
+               /* FIXME: fill in the last byte of the dest ipaddr here
+                * to better comply with RFC1051 in "noarp" mode.
+                * For now, always broadcasting will probably at least get
+                * packets sent out :)
                 */
                pkt->hard.dest = 0;
                return hdr_size;
@@ -437,7 +429,6 @@ static int build_header(struct sk_buff *skb, struct net_device *dev,
        return hdr_size;
 }
 
-
 static void load_pkt(struct net_device *dev, struct arc_hardware *hard,
                     struct arc_rfc1201 *soft, int softlen, int bufnum)
 {
@@ -461,8 +452,9 @@ static void load_pkt(struct net_device *dev, struct arc_hardware *hard,
                hard->offset[1] = ofs - RFC1201_HDR_SIZE;
                lp->hw.copy_to_card(dev, bufnum, ofs - RFC1201_HDR_SIZE,
                                    &excsoft, RFC1201_HDR_SIZE);
-       } else
+       } else {
                hard->offset[0] = ofs = 256 - softlen;
+       }
 
        lp->hw.copy_to_card(dev, bufnum, 0, hard, ARC_HDR_SIZE);
        lp->hw.copy_to_card(dev, bufnum, ofs, soft, softlen);
@@ -470,7 +462,6 @@ static void load_pkt(struct net_device *dev, struct arc_hardware *hard,
        lp->lastload_dest = hard->dest;
 }
 
-
 static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length,
                      int bufnum)
 {
@@ -478,7 +469,6 @@ static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length,
        const int maxsegsize = XMTU - RFC1201_HDR_SIZE;
        struct Outgoing *out;
 
-
        BUGMSG(D_DURING, "prepare_tx: txbufs=%d/%d/%d\n",
               lp->next_tx, lp->cur_tx, bufnum);
 
@@ -494,8 +484,8 @@ static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length,
                out->numsegs = (out->dataleft + maxsegsize - 1) / maxsegsize;
                out->segnum = 0;
 
-               BUGMSG(D_DURING, "rfc1201 prep_tx: ready for %d-segment split "
-                      "(%d bytes, seq=%d)\n", out->numsegs, out->length,
+               BUGMSG(D_DURING, "rfc1201 prep_tx: ready for %d-segment split (%d bytes, seq=%d)\n",
+                      out->numsegs, out->length,
                       pkt->soft.rfc1201.sequence);
 
                return 0;       /* not done */
@@ -506,7 +496,6 @@ static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length,
        return 1;               /* done */
 }
 
-
 static int continue_tx(struct net_device *dev, int bufnum)
 {
        struct arcnet_local *lp = netdev_priv(dev);
@@ -517,7 +506,7 @@ static int continue_tx(struct net_device *dev, int bufnum)
        int seglen;
 
        BUGMSG(D_DURING,
-         "rfc1201 continue_tx: loading segment %d(+1) of %d (seq=%d)\n",
+              "rfc1201 continue_tx: loading segment %d(+1) of %d (seq=%d)\n",
               out->segnum, out->numsegs, soft->sequence);
 
        /* the "new" soft header comes right before the data chunk */