BNX2X: disables TPA
[akaros.git] / kern / src / printfmt.c
index e30b928..8018966 100644 (file)
@@ -12,6 +12,7 @@
 #include <string.h>
 #include <stdarg.h>
 #include <kthread.h>
+#include <ns.h>
 
 /* Print a number (base <= 16) in reverse order,
  * using specified putch function and associated pointer putdat. */
@@ -59,7 +60,9 @@ void vprintfmt(void (*putch)(int, void**), void **putdat, const char *fmt, va_li
        int base, lflag, width, precision, altflag;
        char padc;
        uint8_t *mac, *ip, *mask;
+       struct Gas *g;
        int i;
+       uint32_t *lp;
 
        while (1) {
                while ((ch = *(unsigned char *) fmt) != '%') {
@@ -131,6 +134,11 @@ void vprintfmt(void (*putch)(int, void**), void **putdat, const char *fmt, va_li
                        lflag++;
                        goto reswitch;
 
+               // chan
+               case 'C':
+                       printchan(putch, putdat, va_arg(ap, void*));
+                       break;
+
                // character
                case 'c':
                        putch(va_arg(ap, int), putdat);
@@ -142,9 +150,9 @@ void vprintfmt(void (*putch)(int, void**), void **putdat, const char *fmt, va_li
                        if (err < 0)
                                err = -err;
                        if (err >= NUMERRORS)
-                               printfmt(putch, putdat, "error %d", err);
+                               printfmt(putch, putdat, "error %d(%s)", err, get_cur_errbuf());
                        else
-                               printfmt(putch, putdat, "%s", error_string[err]);
+                               printfmt(putch, putdat, "%s (%s)", error_string[err], get_cur_errbuf());
                        break;
 
                case 'E': // ENET MAC
@@ -155,6 +163,16 @@ void vprintfmt(void (*putch)(int, void**), void **putdat, const char *fmt, va_li
                        }
                        printemac(putch, putdat, mac);
                        break;
+               case 'i':
+                       /* what to do if they screw up? */
+                       if ((lp = va_arg(ap, uint32_t *)) != NULL){
+                               uint32_t hostfmt;
+                               for(i = 0; i < 4; i++){
+                                       hnputl(&hostfmt, lp[i]);
+                                       printfmt(putch, putdat, "%08lx", hostfmt);
+                               }
+                       }
+                       break;
                case 'I':
                        /* what to do if they screw up? */
                        if ((ip = va_arg(ap, uint8_t *)) != NULL)
@@ -165,6 +183,12 @@ void vprintfmt(void (*putch)(int, void**), void **putdat, const char *fmt, va_li
                        if ((mask = va_arg(ap, uint8_t *)) != NULL)
                                printipmask(putch, putdat, mask);
                        break;
+               case 'V':
+                       /* what to do if they screw up? */
+                       if ((ip = va_arg(ap, uint8_t *)) != NULL)
+                               printipv4(putch, putdat, ip);
+                       break;
+
                // string
                case 's':
                        if ((p = va_arg(ap, char *)) == NULL)
@@ -227,6 +251,10 @@ void vprintfmt(void (*putch)(int, void**), void **putdat, const char *fmt, va_li
                        base = 16;
                        goto number;
 
+               // qid
+               case 'Q':
+                       printqid(putch, putdat, va_arg(ap, void*));
+                       break;
                number:
                        printnum(putch, putdat, num, base, width, padc);
                        break;
@@ -269,9 +297,10 @@ typedef struct sprintbuf {
 
 static void sprintputch(int ch, sprintbuf_t *NONNULL *NONNULL b)
 {
-       (*b)->cnt++;
-       if ((*b)->buf < (*b)->ebuf)
+       if ((*b)->buf < (*b)->ebuf) {
                *((*b)->buf++) = ch;
+               (*b)->cnt++;
+       }
 }
 
 int vsnprintf(char *buf, int n, const char *fmt, va_list ap)
@@ -279,8 +308,9 @@ int vsnprintf(char *buf, int n, const char *fmt, va_list ap)
        sprintbuf_t b;// = {buf, buf+n-1, 0};
        sprintbuf_t *COUNT(1) NONNULL bp = &b;
 
+       /* this isn't quite the snprintf 'spec', but errors aren't helpful */
        if (buf == NULL || n < 1)
-               return -EINVAL;
+               return 0;
 
        b.buf = NULL; // zra : help out the Deputy optimizer a bit
        b.ebuf = buf+n-1;