file
stringlengths
18
26
data
stringlengths
3
1.04M
the_stack_data/193891958.c
/* T T C P . C * BRL-CAD * * Copyright (c) 2004-2014 United States Government as represented by * the U.S. Army Research Laboratory. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * version 2.1 as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this file; see the file named COPYING for more * information. */ /** @file util/ttcp.c * * Test TCP connection. Makes a connection on port 2000 * and transfers zero buffers or data copied from stdin. * * Usable on 4.2, 4.3, and 4.1a systems by defining one of * BSD42 BSD43 (BSD41a) * * Modified for operation under 4.2BSD, 18 Dec 84 * T.C. Slattery, USNA * Minor improvements, Mike Muuss and Terry Slattery, 16-Oct-85. * * Mike Muuss and Terry Slattery have released this code to the Public Domain. */ #define BSD43 /* #define BSD42 */ /* #define BSD41a */ /* does not include common.h or bio.h so it may remain stand-alone */ #ifndef _WIN32 # include <unistd.h> #endif #include <limits.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <errno.h> #include <sys/types.h> #ifndef _WIN32 # include <sys/socket.h> #endif #include <netinet/in.h> #include <arpa/inet.h> #ifndef _WIN32 # include <sys/time.h> /* struct timeval */ # include <netdb.h> #else # include <windows.h> #endif #if defined(SYSV) || defined(__HAIKU__) # include <sys/times.h> # include <sys/param.h> #else # include <sys/resource.h> #endif struct sockaddr_in sinme; struct sockaddr_in sinhim; struct sockaddr_in sindum; struct sockaddr_in frominet; int domain; socklen_t fromlen; int udp = 0; /* 0 = tcp, !0 = udp */ int options = 0; /* socket options */ int one = 1; /* for 4.3 BSD style setsockopt() */ int port = 2000; /* TCP port number (possible range 0 - 65535)*/ char *host; /* ptr to name of host */ int trans; /* 0=receive, !0=transmit mode */ int sinkmode; /* 0=normal I/O, !0=sink/source mode */ struct hostent *addr; /* Usage broken into two strings to avoid the 509 C90 'minimum' */ char Usage[] = "\ Usage: ttcp -t [-options] host <in\n\ -l## length of bufs written to network (default 1024)\n\ -s source a pattern to network\n\ -n## number of bufs written to network (-s only, default 1024)\n\ -p## port number to send to (default 2000)\n\ -u use UDP instead of TCP\n\ "; char Usage2[] = "\ Usage: ttcp -r [-options] >out\n\ -l## length of network read buf (default 1024)\n\ -s sink (discard) all data from network\n\ -p## port number to listen at (default 2000)\n\ -B Only output full blocks, as specified in -l## (for TAR)\n\ -u use UDP instead of TCP\n\ "; char stats[128]; long nbytes; /* bytes on net */ int b_flag = 0; /* use mread() */ double cput, realt; /* user, real time (seconds) */ /* * This function performs the function of a read(II) but will * call read(II) multiple times in order to get the requested * number of characters. This can be necessary because * network connections don't deliver data with the same * grouping as it is written with. Written by Robert S. Miles, BRL. */ int mread(int fd, char *bufp, unsigned n) { unsigned count = 0; int nread; do { nread = read(fd, bufp, n-count); if (nread < 0) { perror("ttcp_mread"); return -1; } if (nread == 0) return (int)count; count += (unsigned)nread; bufp += nread; } while (count < n); return (int)count; } static void err(const char *s) { fprintf(stderr, "ttcp%s: ", trans?"-t":"-r"); perror(s); fprintf(stderr, "errno=%d\n", errno); exit(1); } void mes(const char *s) { fprintf(stderr, "ttcp%s: %s\n", trans?"-t":"-r", s); } void pattern(char *cp, int cnt) { char c; c = 0; while (cnt-- > 0) { while (!isprint((c&0x7F))) c++; *cp++ = (c++&0x7F); } } /******* timing *********/ #if defined(SYSV) || defined(__HAIKU__) /* was long instead of time_t */ extern time_t time(time_t *); static time_t time0; static struct tms tms0; #else static struct timeval time0; /* Time at which timing started */ static struct rusage ru0; /* Resource utilization at the start */ static void prusage(struct rusage *r0, struct rusage *r1, struct timeval *e, struct timeval *b, char *outp); static void tvadd(struct timeval *tsum, struct timeval *t0, struct timeval *t1); static void tvsub(struct timeval *tdiff, struct timeval *t1, struct timeval *t0); static void psecs(long int l, char *cp); #endif void prep_timer(void) { #if defined(SYSV) || defined(__HAIKU__) (void)time(&time0); (void)times(&tms0); #else gettimeofday(&time0, (struct timezone *)0); getrusage(RUSAGE_SELF, &ru0); #endif } double read_timer(char *str, int len) { #if defined(SYSV) || defined(__HAIKU__) time_t now; struct tms tmsnow; char line[132] = {0}; (void)time(&now); realt = now-time0; (void)times(&tmsnow); cput = tmsnow.tms_utime - tms0.tms_utime; if (cput < 0.00001) cput = 0.01; if (realt < 0.00001) realt = cput; sprintf(line, "%g CPU secs in %g elapsed secs (%g%%)", cput, realt, cput/realt*100); strncpy(str, line, len); return cput; #else /* BSD */ struct timeval timedol; struct rusage ru1; struct timeval td; struct timeval tend, tstart; char line[132] = {0}; getrusage(RUSAGE_SELF, &ru1); gettimeofday(&timedol, (struct timezone *)0); prusage(&ru0, &ru1, &timedol, &time0, line); strncpy(str, line, len); /* Get real time */ tvsub(&td, &timedol, &time0); realt = td.tv_sec + ((double)td.tv_usec) / 1000000; /* Get CPU time (user+sys) */ tvadd(&tend, &ru1.ru_utime, &ru1.ru_stime); tvadd(&tstart, &ru0.ru_utime, &ru0.ru_stime); tvsub(&td, &tend, &tstart); cput = td.tv_sec + ((double)td.tv_usec) / 1000000; if (cput < 0.00001) cput = 0.00001; return cput; #endif } #if !defined(SYSV) && !defined(__HAIKU__) static void prusage(struct rusage *r0, struct rusage *r1, struct timeval *e, struct timeval *b, char *outp) { struct timeval tdiff; time_t t; const char *cp; int i; int ms; t = (r1->ru_utime.tv_sec-r0->ru_utime.tv_sec)*100+ (r1->ru_utime.tv_usec-r0->ru_utime.tv_usec)/10000+ (r1->ru_stime.tv_sec-r0->ru_stime.tv_sec)*100+ (r1->ru_stime.tv_usec-r0->ru_stime.tv_usec)/10000; ms = (e->tv_sec-b->tv_sec)*100 + (e->tv_usec-b->tv_usec)/10000; #define END(x) {while (*x) x++;} cp = "%Uuser %Ssys %Ereal %P %Xi+%Dd %Mmaxrss %F+%Rpf %Ccsw"; for (; *cp; cp++) { if (*cp != '%') *outp++ = *cp; else if (cp[1]) switch (*++cp) { case 'U': tvsub(&tdiff, &r1->ru_utime, &r0->ru_utime); sprintf(outp, "%ld.%01ld", (long int)tdiff.tv_sec, (long int)tdiff.tv_usec/100000L); END(outp); break; case 'S': tvsub(&tdiff, &r1->ru_stime, &r0->ru_stime); sprintf(outp, "%ld.%01ld", (long int)tdiff.tv_sec, (long int)tdiff.tv_usec/100000L); END(outp); break; case 'E': psecs(ms / 100, outp); END(outp); break; case 'P': sprintf(outp, "%d%%", (int) (t*100 / ((ms ? ms : 1)))); END(outp); break; case 'W': i = r1->ru_nswap - r0->ru_nswap; sprintf(outp, "%d", i); END(outp); break; case 'X': sprintf(outp, "%ld", t == 0 ? 0 : (r1->ru_ixrss-r0->ru_ixrss)/t); END(outp); break; case 'D': sprintf(outp, "%ld", t == 0 ? 0 : (r1->ru_idrss+r1->ru_isrss-(r0->ru_idrss+r0->ru_isrss))/t); END(outp); break; case 'K': sprintf(outp, "%ld", t == 0 ? 0 : ((r1->ru_ixrss+r1->ru_isrss+r1->ru_idrss) - (r0->ru_ixrss+r0->ru_idrss+r0->ru_isrss))/t); END(outp); break; case 'M': sprintf(outp, "%ld", r1->ru_maxrss/2); END(outp); break; case 'F': sprintf(outp, "%ld", r1->ru_majflt-r0->ru_majflt); END(outp); break; case 'R': sprintf(outp, "%ld", r1->ru_minflt-r0->ru_minflt); END(outp); break; case 'I': sprintf(outp, "%ld", r1->ru_inblock-r0->ru_inblock); END(outp); break; case 'O': sprintf(outp, "%ld", r1->ru_oublock-r0->ru_oublock); END(outp); break; case 'C': sprintf(outp, "%ld+%ld", r1->ru_nvcsw-r0->ru_nvcsw, r1->ru_nivcsw-r0->ru_nivcsw); END(outp); break; } } *outp = '\0'; } static void tvadd(struct timeval *tsum, struct timeval *t0, struct timeval *t1) { tsum->tv_sec = t0->tv_sec + t1->tv_sec; tsum->tv_usec = t0->tv_usec + t1->tv_usec; if (tsum->tv_usec > 1000000) tsum->tv_sec++, tsum->tv_usec -= 1000000; } static void tvsub(struct timeval *tdiff, struct timeval *t1, struct timeval *t0) { tdiff->tv_sec = t1->tv_sec - t0->tv_sec; tdiff->tv_usec = t1->tv_usec - t0->tv_usec; if (tdiff->tv_usec < 0) tdiff->tv_sec--, tdiff->tv_usec += 1000000; } static void psecs(long l, char *cp) { int i; i = l / 3600; if (i) { sprintf(cp, "%d:", i); END(cp); i = l % 3600; sprintf(cp, "%d%d", (i/60) / 10, (i/60) % 10); END(cp); } else { i = l; sprintf(cp, "%d", i / 60); END(cp); } i %= 60; *cp++ = ':'; sprintf(cp, "%d%d", i / 10, i % 10); } #endif int Nread(int fd, char *buf, int count) { struct sockaddr_in from; socklen_t len = (socklen_t)sizeof(from); int cnt; if (udp) { cnt = recvfrom(fd, (void *)buf, (size_t)count, 0, (struct sockaddr *)&from, &len); } else { if (b_flag) cnt = mread(fd, buf, count); /* fill buf */ else cnt = read(fd, buf, count); } return cnt; } int delay(int us) { struct timeval tv; tv.tv_sec = 0; tv.tv_usec = us; (void)select(1, (fd_set *)0, (fd_set *)0, (fd_set *)0, &tv); return 1; } int Nwrite(int fd, char *buf, int count) { int cnt; if (udp) { again: cnt = sendto(fd, (const void *)buf, (size_t) count, 0, (const struct sockaddr *)&sinhim, sizeof(sinhim)); if (cnt<0 && errno == ENOBUFS) { delay(18000); errno = 0; goto again; } } else { cnt = write(fd, buf, count); } return cnt; } int main(int argc, char **argv) { int fd; /* fd of network socket */ char *buf; /* ptr to dynamic buffer */ int buflen = 1024; /* length of buffer */ int nbuf = 1024; /* number of buffers to send in sinkmode */ unsigned long addr_tmp; if (argc < 2) goto usage; argv++; argc--; while (argc>0 && argv[0][0] == '-') { switch (argv[0][1]) { case 'B': b_flag = 1; break; case 't': trans = 1; break; case 'r': trans = 0; break; case 'd': options |= SO_DEBUG; break; case 'n': nbuf = atoi(&argv[0][2]); if (nbuf < 0) { printf("Negative buffer count.\n"); return -1; } if (nbuf >= INT_MAX) { printf("Too many buffers specified.\n"); return -1; } break; case 'l': buflen = atoi(&argv[0][2]); if (buflen <= 0) { printf("Invalid buffer length.\n"); return -1; } if (buflen >= INT_MAX) { printf("Buffer length too large.\n"); return -1; } break; case 's': sinkmode = 1; /* source or sink, really */ break; case 'p': port = atoi(&argv[0][2]); if (port < 0) { port = 0; } if (port > 65535) { port = 65535; } break; case 'u': udp = 1; break; default: goto usage; } argv++; argc--; } if (trans) { /* xmitr */ if (argc != 1) goto usage; memset((char *)&sinhim, 0, sizeof(sinhim)); host = argv[0]; if (atoi(host) > 0) { /* Numeric */ sinhim.sin_family = AF_INET; sinhim.sin_addr.s_addr = inet_addr(host); } else { if ((addr=(struct hostent *)gethostbyname(host)) == NULL) err("bad hostname"); sinhim.sin_family = addr->h_addrtype; memcpy((char*)&addr_tmp, addr->h_addr_list[0], addr->h_length); sinhim.sin_addr.s_addr = addr_tmp; } sinhim.sin_port = htons(port); sinme.sin_port = 0; /* free choice */ } else { /* rcvr */ sinme.sin_port = htons(port); } if ((buf = (char *)malloc(buflen)) == (char *)NULL) err("malloc"); fprintf(stderr, "ttcp%s: nbuf=%d, buflen=%d, port=%d\n", trans?"-t":"-r", nbuf, buflen, port); if ((fd = socket(AF_INET, udp?SOCK_DGRAM:SOCK_STREAM, 0)) < 0) err("socket"); mes("socket"); if (bind(fd, (const struct sockaddr *)&sinme, sizeof(sinme)) < 0) err("bind"); if (!udp) { if (trans) { /* We are the client if transmitting */ if (options) { #ifdef BSD42 if (setsockopt(fd, SOL_SOCKET, options, 0, 0) < 0) #else /* BSD43 */ if (setsockopt(fd, SOL_SOCKET, options, &one, sizeof(one)) < 0) #endif err("setsockopt"); } if (connect(fd, (const struct sockaddr *)&sinhim, sizeof(sinhim)) < 0) err("connect"); mes("connect"); } else { /* otherwise, we are the server and * should listen for the connections */ listen(fd, 0); /* allow a queue of 0 */ if (options) { #ifdef BSD42 if (setsockopt(fd, SOL_SOCKET, options, 0, 0) < 0) #else /* BSD43 */ if (setsockopt(fd, SOL_SOCKET, options, &one, sizeof(one)) < 0) #endif err("setsockopt"); } fromlen = (socklen_t)sizeof(frominet); domain = AF_INET; if ((fd=accept(fd, (struct sockaddr *)&frominet, &fromlen)) < 0) err("accept"); mes("accept"); } } prep_timer(); errno = 0; if (sinkmode) { int cnt; if (trans) { pattern(buf, buflen); if (udp) (void)Nwrite(fd, buf, 4); /* rcvr start */ while (nbuf-- && Nwrite(fd, buf, buflen) == buflen) nbytes += buflen; if (udp) (void)Nwrite(fd, buf, 4); /* rcvr end */ } else { while ((cnt=Nread(fd, buf, buflen)) > 0) { static int going = 0; if (cnt <= 4) { if (going) break; /* "EOF" */ going = 1; prep_timer(); } else nbytes += cnt; } } } else { int cnt; if (trans) { while ((cnt=read(0, buf, buflen)) > 0 && Nwrite(fd, buf, cnt) == cnt) nbytes += cnt; } else { while ((cnt=Nread(fd, buf, buflen)) > 0 && write(1, buf, cnt) == cnt) nbytes += cnt; } } if (errno) err("IO"); (void)read_timer(stats, sizeof(stats)); if (udp&&trans) { (void)Nwrite(fd, buf, 4); /* rcvr end */ (void)Nwrite(fd, buf, 4); /* rcvr end */ (void)Nwrite(fd, buf, 4); /* rcvr end */ (void)Nwrite(fd, buf, 4); /* rcvr end */ } free(buf); fprintf(stderr, "ttcp%s: %s\n", trans?"-t":"-r", stats); if (cput <= 0.0) cput = 0.001; if (realt <= 0.0) realt = 0.001; fprintf(stderr, "ttcp%s: %ld bytes processed\n", trans?"-t":"-r", nbytes); fprintf(stderr, "ttcp%s: %9g CPU sec = %9g KB/cpu sec, %9g Kbits/cpu sec\n", trans?"-t":"-r", cput, ((double)nbytes)/cput/1024, ((double)nbytes)*8/cput/1024); fprintf(stderr, "ttcp%s: %9g real sec = %9g KB/real sec, %9g Kbits/sec\n", trans?"-t":"-r", realt, ((double)nbytes)/realt/1024, ((double)nbytes)*8/realt/1024); return 0; usage: fprintf(stderr, "%s%s", Usage, Usage2); return 1; } /* * Local Variables: * mode: C * tab-width: 8 * indent-tabs-mode: t * c-file-style: "stroustrup" * End: * ex: shiftwidth=4 tabstop=8 */
the_stack_data/82949268.c
#include <string.h> #include <stdio.h> char s[100]; int main() { scanf("%s", s); int l = strlen(s); for(int i = l - 1; ~i; --i) putchar(s[i]); putchar('\n'); return 0; }
the_stack_data/32950554.c
#include <stdio.h> int main (){ int x,y; printf("Informe Um Valor: "); scanf("%d",&x); printf("Informe Um Valor: "); scanf("%d",&y); if (x>0){ if(y>0){ printf("I\n" ); } else { printf("IV\n" ); } } else if (y>0) { printf("II\n"); } else { printf("III\n"); } return 0; }
the_stack_data/92324189.c
void puts(const char*); int main() { puts("Hello, World!"); return 0; }
the_stack_data/127263.c
// Program to find the difference between between 2 months in a year #include <stdio.h> #include <string.h> int main() { enum Month { January, February, March, April, May, June, July, August, September, October, November, December }; enum Month Month1, Month2; Month1 = January; Month2 = September; printf("Difference between January and September is : %d month.\n", Month2 - Month1); }
the_stack_data/100525.c
long repeatedString(char* s, long n) { long i, num, a_ct, rem, ct = 0; int len = strlen(s); for(i=0; i<len; i++) { if(s[i] == 'a') ct++; } num = n/strlen(s); a_ct = ct * num; if(n % len != 0) { rem = n % len; for(i=0; i<rem; i++) { if(s[i] == 'a') a_ct++; } } return a_ct; }
the_stack_data/73576343.c
/* PR tree-optimization/65215 */ struct S { unsigned long long l1 : 48; }; static inline unsigned int foo (unsigned int x) { return (x >> 24) | ((x >> 8) & 0xff00) | ((x << 8) & 0xff0000) | (x << 24); } __attribute__((noinline, noclone)) unsigned int bar (struct S *x) { return foo (x->l1); } int main () { if (__CHAR_BIT__ != 8 || sizeof (unsigned int) != 4 || sizeof (unsigned long long) != 8) return 0; struct S s; s.l1 = foo (0xdeadbeefU) | (0xfeedULL << 32); if (bar (&s) != 0xdeadbeefU) __builtin_abort (); return 0; }
the_stack_data/93886956.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #define M 40 typedef struct{ char nome[25]; float borsellino; } player; typedef struct{ int valore; int seme; //cuori quadri fiori picche } carta; void mix(carta mazzo[]){ int i, cont[2] = {1, 1}; carta temp; for(i=0;i<M;i++){ mazzo[i].valore = cont[0]; mazzo[i].seme = cont[1]; if((i+1)%10==0){ cont[0] = 0; cont[1]++; } cont[0]++; } for(i=0;i<M;i++){ int index = rand()%39+1; temp = mazzo[i]; mazzo[i] = mazzo[index]; mazzo[index] = temp; } } int open(char nome[25], FILE** f, char mode[]){ *f = fopen(nome, mode); if(f == NULL) return 0; else return 1; } int set_ngiocatori(){ int n; do{ printf("\nDigita quanti giocatori giocheranno [MAX 5]: "); scanf("%d", &n); }while(n>5 || n<0); return n; } int elimina(char nome[], player database[], int* dim){ int p, i; p = ricerca(nome, database, *dim); if(p == -1) return -1; for(i=p;i<*dim-1;i++){ database[i] = database[i+1]; } (*dim)--; return 1; } int ricerca(char nome[], player db[], int d){ int i; for(i=0;i<d;i++){ if(strcmp(db[i].nome, nome) == 0) return i; } return -1; } int query_db(FILE **db, player database[], int *dim, char mode){ player buffer; int i; if(mode == 'r'){ if(!open("giocatori.dat", db, "rb")){ printf("\nDatabase non trovato"); return 0; } while(!feof(*db)){ fread(&buffer, sizeof(player), 1, *db); if(!feof(*db)){ database[*dim] = buffer; *dim += 1; } } fclose(*db); return 1; }else if(mode == 'w'){ if(!open("giocatori.dat", db, "wb")){ printf("\nDatabase non trovato"); return 0; } for(i=0;i<*dim;i++){ fwrite(&database[i], sizeof(database[i]), 1, *db); } fclose(*db); return 1; } } int get_db(player database[], int dim){ int i, s; for(i=0;i<dim;i++){ printf("\n-%d\tNOME: %s\tBORSELLINO: %f", i+1, database[i].nome, database[i].borsellino); } printf("\nDigita il numero del giocatore con cui desideri giocare: "); scanf("%d", &s); return s-1; } void set_giocatori(int n, player giocatori[], player database[], int dim){ int i, cont=0, pos=0; char buffer[25]; float b; for(i=0;i<n;i++){ printf("\nDigita il nome del giocatore o altrimenti digita 1 per visualizzare i giocatori nel database\n=> "); scanf("%s", buffer); if(buffer[0] == '1'){ if(dim == 0){ printf("\nDatabase vuoto, digita il nome del giocatore: "); scanf("%s", buffer); strcpy(giocatori[cont].nome, buffer); printf("\nDigita la cifra del borsellino: "); scanf("%f", &b); giocatori[cont].borsellino = b; cont++; }else{ pos = get_db(database, dim); giocatori[cont] = database[pos]; cont++; } }else{ strcpy(giocatori[cont].nome, buffer); printf("\nDigita la cifra del borsellino: "); scanf("%f", &b); giocatori[cont].borsellino = b; cont++; } } } void update_db(player giocatori[], int dim, player database[], int* dim_db){ int i, j, flag=0; for(i=0;i<dim;i++){ for(j=0;j<*dim_db;j++){ if(strcmp(giocatori[i].nome, database[j].nome) == 0){ database[j].borsellino = giocatori[i].borsellino; flag = 1; } } if(flag==0){ database[*dim_db] = giocatori[i]; (*dim_db)++; } flag = 0; } } void stampaCarta(carta carta){ switch(carta.seme){ case 1: switch(carta.valore){ case 1: printf("\nASSO DI %c", 3); break; case 8: printf("\nDONNA DI %c", 3); break; case 9: printf("\nFANTE DI %c", 3); break; case 10: printf("\nRE DI %c", 3); break; default: printf("\n %d di %c", carta.valore, 3); } break; case 2: switch(carta.valore){ case 1: printf("\nASSO DI %c", 4); break; case 8: printf("\nDONNA DI %c", 4); break; case 9: printf("\nFANTE DI %c", 4); break; case 10: printf("\nRE DI %c", 4); break; default: printf("\n %d di %c", carta.valore, 4); } break; case 3: switch(carta.valore){ case 1: printf("\nASSO DI %c", 5); break; case 8: printf("\nDONNA DI %c", 5); break; case 9: printf("\nFANTE DI %c", 5); break; case 10: printf("\nRE DI %c", 5); break; default: printf("\n %d di %c", carta.valore, 5); } break; case 4: switch(carta.valore){ case 1: printf("\nASSO DI %c", 6); break; case 8: printf("\nDONNA DI %c", 6); break; case 9: printf("\nFANTE DI %c", 6); break; case 10: printf("\nRE DI %c", 6); break; default: printf("\n %d di %c", carta.valore, 6); } break; } } float valore(carta carta){ float v; if(carta.valore > 7) v = 0.5; else v = carta.valore; return v; } void gioco(player *giocatore, carta mazzo[]){ printf("\nGIOCATORE: %s", giocatore->nome); //3 4 5 6 cuori quadri fiori picche carta primaC; carta temp; float sommaC = 0; float sommaG = 0; char ch; int stop = 0; float puntata = 0; float val; do{ printf("\nInserisci il valore della tua puntata (minore del totale del borsellino => %f ): ", giocatore->borsellino); fflush(stdin); scanf("%f", &puntata); }while(puntata > giocatore->borsellino && puntata > 0); giocatore->borsellino -= puntata; srand(time(NULL)); printf("\nIl mazziere pesca la prima carta"); primaC = mazzo[rand()%40]; sommaC += valore(primaC); do{ if(stop != 1){ printf("\nLa tua carta:\t"); temp = mazzo[rand()%40]; stampaCarta(temp); if(temp.valore == 10 && temp.seme == 2){ printf("\nHai pescato la matta scegli il valore da assegnargli => "); fflush(stdin); scanf("%f", &val); sommaG += val; } else{ sommaG += valore(temp); } printf("\nPunteggio totale: %f", sommaG); printf("\npremi s per stare o r per richiedere un'altra carta => "); fflush(stdin); scanf("%c", &ch); if(ch == 's') stop = 1; } }while(stop == 0); temp = mazzo[rand()%40]; sommaC += valore(temp); printf("\nPrima carta del mazziere:\t"); stampaCarta(primaC); printf("\nSeconda carta del mazziere:\t"); stampaCarta(temp); printf("\nPunteggio totale mazziere: %f", sommaC); printf("\nIl tuo punteggio totale : %f\n\n" , sommaG); //FIX if(sommaC > 7.5 && sommaG < 7.5){ printf("Il mazziere ha sballato, hai vinto!"); giocatore->borsellino += (puntata)*2; printf("\nValore borsellino %f", giocatore->borsellino); return; }else if(sommaG > 7.5 && sommaC != 7.5 && sommaG != 7.5){ printf("Hai sballato, hai perso la tua puntata!"); printf("\nValore borsellino %f", giocatore->borsellino); return; } if(sommaG == sommaC && sommaG < 7.5){ printf("\nPareggio!"); giocatore->borsellino += puntata; printf("\nValore borsellino %f", giocatore->borsellino); return; } if(sommaG < 7.5 && sommaC < 7.5 && sommaG > sommaC && sommaG != 7.5){ printf("\nHai vinto!"); giocatore->borsellino += (puntata)*2; printf("\nValore borsellino %f", giocatore->borsellino); return; }else if(sommaG < 7.5 && sommaC < 7.5 && sommaC > sommaG && sommaG != 7.5){ printf("\nGame Over, hai perso la tua puntata!"); printf("\nValore borsellino %f", giocatore->borsellino); return; } if(sommaG == 7.5){ printf("\nSette 1/2 reale!"); giocatore->borsellino += (puntata)*4; printf("\nValore borsellino %f", giocatore->borsellino); return; }else if(sommaC == 7.5){ printf("\nGame Over il mazziere ha fatto 7 1/2 reale, perdi il doppio della puntata"); giocatore->borsellino -= puntata; printf("\nValore borsellino %f", giocatore->borsellino); return; } } void main(){ FILE *db; carta mazzo[M]; int dim_db = 0; player giocatori[5], database[10]; printf("\n\t7 1/2"); query_db(&db, database, &dim_db, 'r'); int n = set_ngiocatori(); set_giocatori(n, giocatori, database, dim_db); int i; for(i=0;i<n;i++){ printf("\nGIOCATORE: %s BORSELLINO: %f", giocatori[i].nome, giocatori[i].borsellino); } ///////////// GIOCO int num = n; for(i=0;i<num;i++){ char c; do{ mix(mazzo); gioco(&giocatori[i], mazzo); update_db(giocatori, n, database, &dim_db); query_db(&db, database, &dim_db, 'w'); if(giocatori[i].borsellino <= 0){ printf("\nHai perso tutto!"); elimina(giocatori[i].nome, giocatori, &n); elimina(giocatori[i].nome, database, &dim_db); update_db(giocatori, n, database, &dim_db); query_db(&db, database, &dim_db, 'w'); c = 'x'; }else{ printf("\n\nPremi x per smettere di giocare => "); fflush(stdin); scanf("%c", &c); system("cls"); } }while(c != 'x'); } ///////////// GIOCO }
the_stack_data/100141263.c
/* * Mach Operating System * Copyright (c) 1991,1990,1989 Carnegie Mellon University * All Rights Reserved. * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the * software, derivative works or modified versions, and any portions * thereof, and that both notices appear in supporting documentation. * * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. * * Carnegie Mellon requests users of this software to return to * * Software Distribution Coordinator or [email protected] * School of Computer Science * Carnegie Mellon University * Pittsburgh PA 15213-3890 * * any improvements or extensions that they make and grant Carnegie Mellon * the rights to redistribute these changes. */ /* * HISTORY * $Log: bzero.c,v $ * Revision 2.4 91/05/14 17:54:14 mrt * Correcting copyright * * Revision 2.3 91/02/14 14:18:18 mrt * Added new Mach copyright * [91/02/13 12:46:15 mrt] * * Revision 2.2 89/11/29 14:18:39 af * Forgot to bring over bug fix from kernel. * [89/11/26 10:28:12 af] * * Created. * [89/10/12 af] * */ /* * Object: * bzero EXPORTED function * * Clear memory locations * * Optimize for aligned memory ops, if possible and simple. * Might need later recoding in assembly for better efficiency. */ void bzero(addr, bcount) register unsigned addr; register unsigned bcount; { register int i; if (bcount == 0) /* sanity */ return; switch (addr & 3) { case 1: *((char *) addr++) = 0; if (--bcount == 0) return; case 2: *((char *) addr++) = 0; if (--bcount == 0) return; case 3: *((char *) addr++) = 0; if (--bcount == 0) return; default: break; } for (i = bcount >> 2; i; i--, addr += 4) *((int *) addr) = 0; switch (bcount & 3) { case 3: *((char*)addr++) = 0; case 2: *((char*)addr++) = 0; case 1: *((char*)addr++) = 0; default:break; } }
the_stack_data/126702975.c
#include <stdio.h> /** * 1295. 统计位数为偶数的数字 * 给你一个整数数组 nums,请你返回其中位数为 偶数 的数字的个数。 */ int findNumbers(int *nums, int numsSize) { if (numsSize == 0) { return 0; } int result = 0, tmp = 0, bit = 0; for (int i = 0; i < numsSize; i++) { if (nums[i] == 0) { continue; } tmp = nums[i]; bit = 0; while (tmp != 0) { tmp = tmp / 10; bit++; } if (bit % 2 == 0) { result++; } } return result; }
the_stack_data/232956605.c
unsigned Cur_Vertical_Sep; unsigned High_Confidence; unsigned Two_of_Three_Reports_Valid; unsigned Own_Tracked_Alt; unsigned Own_Tracked_Alt_Rate; unsigned Other_Tracked_Alt; unsigned Alt_Layer_Value; unsigned Positive_RA_Alt_Thresh__0 ; unsigned Positive_RA_Alt_Thresh__1 ; unsigned Positive_RA_Alt_Thresh__2 ; unsigned Positive_RA_Alt_Thresh__3 ; unsigned Up_Separation; unsigned Down_Separation; unsigned Other_RAC; unsigned Other_Capability; unsigned Climb_Inhibit; void main( ) { unsigned enabled, tcas_equipped, intent_not_known; unsigned need_upward_RA, need_downward_RA; unsigned alt_sep; unsigned alim; // New variables added .... unsigned temp1,temp2,temp3,temp4; unsigned result_Non_Crossing_Biased_Climb; unsigned result_Non_Crossing_Biased_Descend; // -- initialize(); Positive_RA_Alt_Thresh__0 = 400; Positive_RA_Alt_Thresh__1 = 500; Positive_RA_Alt_Thresh__2 = 640; Positive_RA_Alt_Thresh__3 = 740; // -- alt_sep_test(); enabled=0; tcas_equipped=0; intent_not_known=0; need_upward_RA=0; need_downward_RA=0; // -- -- alim = ALIM(); if ( Alt_Layer_Value == 0 ) alim = Positive_RA_Alt_Thresh__0 ; if ( Alt_Layer_Value == 1 ) alim = Positive_RA_Alt_Thresh__1 ; if ( Alt_Layer_Value == 2 ) alim = Positive_RA_Alt_Thresh__2 ; alim = Positive_RA_Alt_Thresh__3 ; if ( (High_Confidence !=0/*JORGE*/) && (Own_Tracked_Alt_Rate <= 600) && (Cur_Vertical_Sep > 600) ) enabled = 1 ; if ( Other_Capability == 0 ) tcas_equipped = 1 ; if ( (Two_of_Three_Reports_Valid !=0 /*JORGE*/) && Other_RAC == 0 ) intent_not_known = 1 ; alt_sep = 0; if ((enabled !=0 /*JORGE*/)&& (((tcas_equipped !=0 /*JORGE*/)&& (intent_not_known !=0 /*JORGE*/)) || ! (tcas_equipped !=0 /*JORGE*/))) { ////////////////////////////////////////////////////////////////////////////// { // ENTERING Non_Crossing_Biased_Climb(); unsigned upward_preferred_1; unsigned alim_Non_Crossing_Biased_Climb; unsigned temp11,temp12,temp13; upward_preferred_1 = 0 ; result_Non_Crossing_Biased_Climb=0; // alim = ALIM() ; if ( Alt_Layer_Value == 0 ) alim_Non_Crossing_Biased_Climb = Positive_RA_Alt_Thresh__0 ; if ( Alt_Layer_Value == 1 ) alim_Non_Crossing_Biased_Climb = Positive_RA_Alt_Thresh__1 ; if ( Alt_Layer_Value == 2 ) alim_Non_Crossing_Biased_Climb = Positive_RA_Alt_Thresh__2 ; alim_Non_Crossing_Biased_Climb = Positive_RA_Alt_Thresh__3 ; // temp11 = Inhibit_Biased_Climb(); if (Climb_Inhibit==1) temp11= Up_Separation + 100; else temp11 = Up_Separation; if (temp11 > Down_Separation ) upward_preferred_1 = 1 ; if (upward_preferred_1==1) { // temp12 = Own_Below_Threat(); if (Own_Tracked_Alt < Other_Tracked_Alt) temp12 = 1 ; else temp12 = 0 ; if ( !(temp12 !=0 /*JORGE*/) || ((temp12 !=0 /*JORGE*/)&& (!(Down_Separation >= alim_Non_Crossing_Biased_Climb))) ) result_Non_Crossing_Biased_Climb = 1 ; } else { // temp13= Own_Above_Threat(); if (Other_Tracked_Alt < Own_Tracked_Alt) temp13 = 1 ; else temp13 = 0 ; if ( (temp13 !=0 /*JORGE*/) && (Cur_Vertical_Sep >= 300) && (Up_Separation >= alim_Non_Crossing_Biased_Climb) ) result_Non_Crossing_Biased_Climb = 1 ; } } // LEAVING_NON_CROSSING_BIASED_CLIMB: ////////////////////////////////////////////////////////////////////////////// temp1 = result_Non_Crossing_Biased_Climb; // temp2 = Own_Below_Threat(); if (Own_Tracked_Alt < Other_Tracked_Alt) temp2= 1 ; else temp2 = 0 ; if ( (temp1 !=0 /*JORGE*/) && (temp2 !=0 /*JORGE*/) ) need_upward_RA = 1 ; ////////////////////////////////////////////////////////////////////////////// // temp3 = Non_Crossing_Biased_Descend(); ////////////////////////////////////////////////////////////////////////////// { // ENTERING Non_Crossing_Biased_Descend() unsigned upward_preferred_2; unsigned alim_Non_Crossing_Biased_Descend; unsigned temp21,temp22,temp23; upward_preferred_2 = 0 ; result_Non_Crossing_Biased_Descend = 0 ; // alim_Non_Crossing_Biased_Descend=ALIM() ; if ( Alt_Layer_Value == 0 ) alim_Non_Crossing_Biased_Descend= Positive_RA_Alt_Thresh__0 ; if ( Alt_Layer_Value == 1 ) alim_Non_Crossing_Biased_Descend= Positive_RA_Alt_Thresh__1 ; if ( Alt_Layer_Value == 2 ) alim_Non_Crossing_Biased_Descend= Positive_RA_Alt_Thresh__2 ; alim_Non_Crossing_Biased_Descend= Positive_RA_Alt_Thresh__3 ; // temp21 = Inhibit_Biased_Climb(); if (Climb_Inhibit==1) temp21 = Up_Separation + 100; else temp21 = Up_Separation; if ( temp21 > Down_Separation ) upward_preferred_2 = 1 ; if (upward_preferred_2 ==1) { // temp22 = Own_Below_Threat(); if (Own_Tracked_Alt < Other_Tracked_Alt) temp22 = 1 ; else temp22 = 0; if((temp22 !=0 /*JORGE*/) && (Cur_Vertical_Sep >= 300) && (Down_Separation >= alim_Non_Crossing_Biased_Descend) ) result_Non_Crossing_Biased_Descend = 1 ; } else { // temp23 = Own_Above_Threat(); if (Other_Tracked_Alt < Own_Tracked_Alt) temp23 = 1 ; else temp23 = 0 ; if ( !(temp23 !=0 /*JORGE*/) || ((temp23 !=0 /*JORGE*/) && (Up_Separation >= alim_Non_Crossing_Biased_Descend))) result_Non_Crossing_Biased_Descend = 1 ; } } // ENTERING Non_Crossing_Biased_Descend() ////////////////////////////////////////////////////////////////////////////// temp3= result_Non_Crossing_Biased_Descend; // temp4 = Own_Above_Threat(); if (Other_Tracked_Alt < Own_Tracked_Alt) temp4 = 1 ; else temp4 = 0 ; if ( (temp3 !=0 /*JORGE*/) && (temp4 !=0 /*JORGE*/) ) need_downward_RA = 1 ; if ((need_upward_RA !=0 /*JORGE*/) && (need_downward_RA !=0 /*JORGE*/)) alt_sep = 0; else if ((need_upward_RA !=0 /*JORGE*/)) alt_sep = 1; else if ((need_downward_RA !=0 /*JORGE*/)) { /*property1a(alim) ;*/ // BLAST/ARMC if( Up_Separation >= alim && Down_Separation < alim ) ERROR: goto ERROR; // TRACER // _ABORT( Up_Separation >= alim && Down_Separation < alim ); alt_sep = 2; } else alt_sep = 0; } return; }
the_stack_data/92325201.c
/* This is the work horse function of this program. This is where we find out if the number we are testing is a prime number. A prime number is a number that only has the factors of 1 and itself. */ int is_prime( int num ) { int limit; register int count; if ( num == 0 ) { return 0; /* Zero is not a prime number. */ } /* This code may be copied and used in someone else's program and if that be the case then we can't be sure about the input passed to this function. */ if ( num < 0 ) { #ifdef NEGATIVE_IS_NOT_PRIME return 0; /* Strict */ #endif num *= ( -1 ); /* Just flip it and use it anyway. */ } /* Some may want 1 listed with prime numbers. If they do they can #define LIST_ONE_AS_PRIME at the top of the program with the other definitions. */ #ifdef LIST_ONE_AS_PRIME if ( num == 1 ) { return 1; } #else if ( num == 1 ) { return 0; } #endif /* Take care of an obvious case. */ if ( num == 2 ) { return 1; /* 2 is a prime number. */ } /* Any even number greater than 2 is not a prime number because it is evenly divisible by 2 so we shouldn't waste our time with it. */ if ( num % 2 == 0 ) { return 0; } /* At this point we know that the number is an odd number greater than 2. The number cannot have any factors, other than itself, that are greater than the square root of the number that we are testing so it is pointless to search for them. We will increment count by two steps so we don't search for even numbered factors. If the number we are testing is 3 then the for() loop won't even be used. */ limit = ( int )sqrt( num ); for ( count = 3; count <= limit; count += 2 ) { if ( num % count == 0 ) { return 0; /* We found a factor so num */ } /* is not a prime number. */ } /* We didn't find any factors so num is a prime number. */ return 1; } /* EOF is_prime.c */
the_stack_data/115766838.c
/******************************************************************************* * NHD_24_240320_Framebuffer2GPIO.c * for NHD-1.8-128160EF TFTs with driver IC ILI9163 using the 8 bit parallel interface * * copies the contents of the display framebuffer into a memory region * and outputs a 160x128 area to the TFT display via bit banging GPIOs * * compile with: gcc -o NHD_18 NHD_18_128160_Framebuffer2GPIO.c -lrt -O3 * start with: sudo ./NHD_18 * * framebuffer code adapted from * https://gist.github.com/Darfk/5790622 * * framebuffer info * http://www.ummon.eu/Linux/API/Devices/framebuffer.html * * GPIO code adapted from * https://elinux.org/RPi_GPIO_Code_Samples#Direct_register_access * *******************************************************************************/ #define PRINT_INFO 1 /* change to 0 to surpress all printf output */ #define X_START 0 /* horizontal start position from where the 320x240 area is read */ #define Y_START 0 /* vertical start position from where the 320x240 area is read */ #define BCM2708_PERI_BASE 0x3F000000 #define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) /* GPIO controller */ // define interface connections to GPIOs // /CS is tied to GND (= enabled) // /RD is tied to 3V3 (= disabled) #define NHD_DC 4 /* Pin 07 -> GPIO 04 */ #define NHD_WR 18 /* Pin 12 -> GPIO 18 */ #define NHD_RES 17 /* Pin 11 -> GPIO 17 */ #define NHD_DB0 6 /* Pin 31 -> GPIO 06 */ #define NHD_DB1 12 /* Pin 32 -> GPIO 12 */ #define NHD_DB2 13 /* Pin 33 -> GPIO 13 */ #define NHD_DB3 19 /* Pin 35 -> GPIO 19 */ #define NHD_DB4 16 /* Pin 36 -> GPIO 16 */ #define NHD_DB5 26 /* Pin 37 -> GPIO 26 */ #define NHD_DB6 20 /* Pin 38 -> GPIO 20 */ #define NHD_DB7 21 /* Pin 40 -> GPIO 21 */ #include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <sys/mman.h> #include <unistd.h> #include <linux/fb.h> #include <sys/mman.h> #include <sys/ioctl.h> #include <string.h> #include <stdint.h> #include <time.h> #include <sys/time.h> #define BLOCK_SIZE (4*1024) int mem_fd; void *gpio_map; // delay nanosecondsNoSleep long int start_time; long int time_difference; struct timespec gettime_now; // I/O access volatile unsigned *gpio; // GPIO setup macros. Always use INP_GPIO(x) before using OUT_GPIO(x) or SET_GPIO_ALT(x,y) #define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3)) #define OUT_GPIO(g) *(gpio+((g)/10)) |= (1<<(((g)%10)*3)) #define GPIO_SET *(gpio+7) // sets bits which are 1 ignores bits which are 0 #define GPIO_CLR *(gpio+10) // clears bits which are 1 ignores bits which are 0 void Setup_GPIO(); void TFT_18_9163_Write_8Bit(int8_t); void TFT_18_9163_Write_Command(int8_t); void TFT_18_9163_Write_Data(int8_t); void TFT_18_9163_Init(); void DelayNanosecondsNoSleep (int); int main (void) { if (PRINT_INFO == 1) printf("Starting NHD_24_240320_Framebuffer2GPIO\n"); /************************* * * Framebuffer init * *************************/ /* framebuffer file descriptor */ int fbfd; /* structures for framebuffer information */ struct fb_var_screeninfo vinfo; struct fb_fix_screeninfo finfo; /* screen size in bytes */ /* x * y * bpp / 8 */ unsigned long int screensize; /* row length in pixels */ unsigned int row_length; /* Framebuffer pointer */ int *fbp; /* Open framebuffer */ fbfd = open("/dev/fb0", O_RDWR); if(fbfd == -1) { printf("Error: cannot open framebuffer device"); exit(1); } /* Get fixed screen information */ if(ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo) == -1) { printf("Error reading fixed information"); exit(2); } /* Get variable screen information */ if(ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo) == -1) { printf("Error reading variable information"); exit(3); } if (PRINT_INFO == 1) { printf("%s\n", finfo.id); printf("linelength %d\n", finfo.line_length); printf("%d x %d, %d bpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel); printf("ALPHA offset %d length %d\n", vinfo.transp.offset, vinfo.transp.length); printf("RED offset %d length %d\n", vinfo.red.offset, vinfo.red.length); printf("GREEN offset %d length %d\n", vinfo.green.offset, vinfo.green.length); printf("BLUE offset %d length %d\n", vinfo.blue.offset, vinfo.blue.length); } row_length = vinfo.xres; screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8 ; fbp = mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0); if (*(fbp) == -1) { printf("Error: failed to map framebuffer device to memory\n"); exit(4); } /************************* * * GPIO init * *************************/ Setup_GPIO(); /************************* * * TFT driver init * *************************/ TFT_18_9163_Init(); /************************* * * Pixel processing * *************************/ int row, col, color32, red, green, blue; // fps measurement struct timeval t1, t2; long long elapsedTime; while(1) { // Start frame memory write // 9.1.22 RAMWR (2Ch): Memory Write page 195 TFT_18_9163_Write_Command(0x2C); // Start fps measurement gettimeofday(&t1, NULL); // switch columns and rows (TFT expects data in portrait orientation) for (col=0; col<160; col++) { for (row=0; row<128; row++) { // read 32 bit pixel data from framebuffer memory map color32 = fbp[(row + Y_START)*row_length + (col + X_START)]; // color32 (RGB 8/8/8 pixel data from framebuffer, bits C24....C31 = alpha, not shown) // C23 C22 C21 C20 C19 C18 C17 C16 C15 C14 C13 C12 C11 C10 C09 C08 C07 C06 C05 C04 C03 C02 C01 C00 // R07 R06 R05 R04 R03 R02 R01 R00 G07 G06 G05 G04 G03 G02 G01 G00 B07 B06 B05 B04 B03 B02 B01 B00 red = (color32 >> 16) & 0xFF; // shift down 16 bits, then mask 1 byte TFT_18_9163_Write_Data(red); green = (color32 >> 8) & 0xFF; // shift down 8 bits, then mask 1 byte TFT_18_9163_Write_Data(green); blue = (color32 & 0xFF); // imask 1 byte TFT_18_9163_Write_Data(blue); } } // display on command (stop memory write at end of frame) TFT_18_9163_Write_Command(0x29); // fps measurement gettimeofday(&t2, NULL); elapsedTime = ((t2.tv_sec * 1000000) + t2.tv_usec) - ((t1.tv_sec * 1000000) + t1.tv_usec); if (PRINT_INFO == 1) printf("FPS: %lld , %lld ms\n", 1000/(elapsedTime/1000), elapsedTime/1000); } /* Unmap the memory and release all the files */ munmap(fbp, screensize); close(fbfd); return 0; } // // Set up a memory regions to access GPIO // void Setup_GPIO() { // Set up gpio pointer for direct register access /* open /dev/mem */ if ((mem_fd = open("/dev/mem", O_RDWR|O_SYNC) ) < 0) { printf("Error: Can't open /dev/mem \n"); exit(-1); } /* mmap GPIO */ gpio_map = mmap( NULL, // Any adddress in our space will do BLOCK_SIZE, // Map length PROT_READ|PROT_WRITE, // Enable reading & writting to mapped memory MAP_SHARED, // Shared with other processes mem_fd, // File to map GPIO_BASE // Offset to GPIO peripheral ); close(mem_fd); //No need to keep mem_fd open after mmap if (gpio_map == MAP_FAILED) { printf("Error: mmap failed %d\n", (int)gpio_map); exit(-1); } // Always use volatile pointer! gpio = (volatile unsigned *)gpio_map; // Set up the pins as output // Always use INP_GPIO(x) before using OUT_GPIO(x) INP_GPIO(NHD_DC); OUT_GPIO(NHD_DC); INP_GPIO(NHD_WR); OUT_GPIO(NHD_WR); INP_GPIO(NHD_RES); OUT_GPIO(NHD_RES); INP_GPIO(NHD_DB0); OUT_GPIO(NHD_DB0); INP_GPIO(NHD_DB1); OUT_GPIO(NHD_DB1); INP_GPIO(NHD_DB2); OUT_GPIO(NHD_DB2); INP_GPIO(NHD_DB3); OUT_GPIO(NHD_DB3); INP_GPIO(NHD_DB4); OUT_GPIO(NHD_DB4); INP_GPIO(NHD_DB5); OUT_GPIO(NHD_DB5); INP_GPIO(NHD_DB6); OUT_GPIO(NHD_DB6); INP_GPIO(NHD_DB7); OUT_GPIO(NHD_DB7); } // // Writes a 16 bit value (command or data) to the TFTs driver IC // void TFT_18_9163_Write_8Bit(int8_t command) { if (command & 0x01 ) { GPIO_SET = 1 << NHD_DB0; } else { GPIO_CLR = 1 << NHD_DB0; } if (command & 0x02 ) { GPIO_SET = 1 << NHD_DB1; } else { GPIO_CLR = 1 << NHD_DB1; } if (command & 0x04 ) { GPIO_SET = 1 << NHD_DB2; } else { GPIO_CLR = 1 << NHD_DB2; } if (command & 0x08 ) { GPIO_SET = 1 << NHD_DB3; } else { GPIO_CLR = 1 << NHD_DB3; } if (command & 0x10 ) { GPIO_SET = 1 << NHD_DB4; } else { GPIO_CLR = 1 << NHD_DB4; } if (command & 0x20 ) { GPIO_SET = 1 << NHD_DB5; } else { GPIO_CLR = 1 << NHD_DB5; } if (command & 0x40 ) { GPIO_SET = 1 << NHD_DB6; } else { GPIO_CLR = 1 << NHD_DB6; } if (command & 0x80 ) { GPIO_SET = 1 << NHD_DB7; } else { GPIO_CLR = 1 << NHD_DB7; } } // // Sends a 8 or 16 bit command to the TFTs driver IC // void TFT_18_9163_Write_Command(int8_t command) { // D/C = Low -> Sending command GPIO_CLR = 1 << NHD_DC; TFT_18_9163_Write_8Bit(command); GPIO_CLR = 1 << NHD_WR; // create rising edge for WR DelayNanosecondsNoSleep(10); GPIO_SET = 1 << NHD_WR; } // // Sends a 8 or 16 bit data value to the TFTs driver IC // void TFT_18_9163_Write_Data(int8_t data) { // D/C = High -> Sending data GPIO_SET = 1 << NHD_DC; TFT_18_9163_Write_8Bit(data); GPIO_CLR = 1 << NHD_WR; // create rising edge for WR DelayNanosecondsNoSleep(10); GPIO_SET = 1 << NHD_WR; } // // Initialize the TFT's driver IC after power up or reset // void TFT_18_9163_Init() { // init control wires (GPIO_SET -> HIGH, GPIO_CLR -> LOW) GPIO_SET = 1 << NHD_DC; // Data/Command wire GPIO_SET = 1 << NHD_WR; // Write wire GPIO_SET = 1 << NHD_RES; // Reset signal (ACTIVE = LOW) disabled DelayNanosecondsNoSleep(120*1000); // delay 120ms after powerup before reset GPIO_CLR = 1 << NHD_RES; // Reset is active DelayNanosecondsNoSleep(30); // hold reset active for 30 ns GPIO_SET = 1 << NHD_RES; // Reset is done DelayNanosecondsNoSleep(120*1000); // Delay 120ms after reset // exit sleep mode TFT_18_9163_Write_Command(0x11); DelayNanosecondsNoSleep(100*1000); // Delay 100ms after exit sleep // display OFF TFT_18_9163_Write_Command(0x28); // MADCTL: memory data access control TFT_18_9163_Write_Command(0x36); TFT_18_9163_Write_Data(0x48); // COLMOD: Interface Pixel format TFT_18_9163_Write_Command(0x3A); TFT_18_9163_Write_Data(0x66); // GAMSET: Select gamma curve TFT_18_9163_Write_Command(0x26); TFT_18_9163_Write_Data(0x0C4); // VCOM Control 1 TFT_18_9163_Write_Command(0xC5); TFT_18_9163_Write_Data(0x2F); TFT_18_9163_Write_Data(0x3E); // VCOM Offset TFT_18_9163_Write_Command(0xC7); TFT_18_9163_Write_Data(0x40); // FRMCTRL: Frame Rate Control TFT_18_9163_Write_Command(0xB1); TFT_18_9163_Write_Data(0x0A); TFT_18_9163_Write_Data(0x14); // PWRCTL1: Power Control 1 TFT_18_9163_Write_Command(0xC0); TFT_18_9163_Write_Data(0x0A); TFT_18_9163_Write_Data(0x00); // PWRCTL2: Power Control 2 TFT_18_9163_Write_Command(0xC1); TFT_18_9163_Write_Data(0x02); // X address set TFT_18_9163_Write_Command(0x2A); TFT_18_9163_Write_Data(0x00); TFT_18_9163_Write_Data(0x00); TFT_18_9163_Write_Data(0x00); TFT_18_9163_Write_Data(0x7F); // Y address set TFT_18_9163_Write_Command(0x2B); TFT_18_9163_Write_Data(0x00); TFT_18_9163_Write_Data(0x00); TFT_18_9163_Write_Data(0x00); TFT_18_9163_Write_Data(0x9F); // display on // 9.1.19 DISPON (29h): Display On page 189 // This command is used to recover from DISPLAY OFF mode. // Output from the Frame Memory is enabled. TFT_18_9163_Write_Command(0x29); DelayNanosecondsNoSleep(10*1000); } // // Delay for x nanoseconds without using nanosleep(); // nanosleep can cause a additional delay of up to 10 ms // void DelayNanosecondsNoSleep (int delay_ns) { clock_gettime(CLOCK_REALTIME, &gettime_now); start_time = gettime_now.tv_nsec; // Get nS value while (1) { clock_gettime(CLOCK_REALTIME, &gettime_now); time_difference = gettime_now.tv_nsec - start_time; if (time_difference < 0) time_difference += 1000000000; // (Rolls over every 1 second) if (time_difference > (delay_ns)) // Delay for # nS reached break; } }
the_stack_data/190767629.c
#include <stdio.h> short int checa_primo(int num); int main() { int n, x, i; short int cond = 0; scanf("%d", &n); if (n < 1 || n > 100) return 1; for (i=0; i < n; i++) { scanf("%d", &x); cond = checa_primo(x); if (cond == 2) printf("%d eh primo\n", x); else printf("%d nao eh primo\n", x); } return 0; } short int checa_primo(int num) { int i, vez = 0; for (i=1; i <= num; i++) if (num % i == 0) ++vez; return vez; }
the_stack_data/151705783.c
#include <stdio.h> #include <stdlib.h> /* ------------------------------------------------------------------------ */ #define MAX_ARRAY 9 static int array[MAX_ARRAY] = { 7, 12, 1, -2, 0, 15, 4, 11, 9 }; /* ------------------------------------------------------------------------ */ #define swap(a,b) { int _t_ = a; a = b; b = _t_; } /* ------------------------------------------------------------------------ */ static void printarray(const char *str, int a[], int l, int h) { int i; printf("%s:", str); for (i = l; i <= h; ++i) { printf(" %d", a[i]); } printf("\n"); } /* End of printarray */ /* ------------------------------------------------------------------------ */ static int partition(int a[], int l, int h) { int pivot = a[l]; int left = l; int right = h + 1; while (1) { do { ++left; } while (a[left] <= pivot && left <= h); do { --right; } while (a[right] > pivot); if (left >= right) { break; } swap(a[left], a[right]); } swap(a[l], a[right]); return right; } /* End of partition */ /* ------------------------------------------------------------------------ */ static void quickSort(int a[], int l, int r) { int j; // if (l < r) // { j = partition(a, l, r); if (l < (j -1)) { quickSort(a, l, j - 1); } if ((j+1) < r) { quickSort(a, j + 1, r); } // } } /* End of quickSort */ /* ------------------------------------------------------------------------ */ static int compare(const void *A, const void *B) { return (*(const int *)A - *(const int *)B); } /* End of compare */ /* ------------------------------------------------------------------------ */ int main(void) { int z; int orig[MAX_ARRAY]; int b[MAX_ARRAY]; #ifdef STATIC_ARRAY /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ printarray("Unsorted array is: ", array, 0, MAX_ARRAY-1); for (z = 0; z < MAX_ARRAY; z++) { orig[z] = b[z] = array[z]; } quickSort(array, 0, MAX_ARRAY-1); printarray(" Sorted array is: ", array, 0, MAX_ARRAY-1); qsort(b, MAX_ARRAY, sizeof(int), compare); for (z = 0; z < MAX_ARRAY; z++) { if (array[z] != b[z]) { printf("qsort != quick_sort\n"); printarray("qsort array b", b, 0, MAX_ARRAY - 1); exit(1); } } /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ #else // STATIC_ARRAY /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ int i, j, k, l, m, n, o, p, q; for (i = 0; i < MAX_ARRAY; i++) { for (j = 0; j < MAX_ARRAY; j++) { printf("."); fflush(stdout); for (k = 0; k < MAX_ARRAY; k++) { for (l = 0; l < MAX_ARRAY; l++) { for (m = 0; m < MAX_ARRAY; m++) { for (n = 0; n < MAX_ARRAY; n++) { for (o = 0; o < MAX_ARRAY; o++) { for (p = 0; p < MAX_ARRAY; p++) { for (q = 0; q < MAX_ARRAY; q++) { array[0] = i; array[1] = j; array[2] = k; array[3] = l; array[4] = m; array[5] = n; array[6] = o; array[7] = p; array[8] = q; for (z = 0; z < MAX_ARRAY; z++) { orig[z] = b[z] = array[z]; } quickSort(array, 0, MAX_ARRAY - 1); qsort(b, MAX_ARRAY, sizeof(int), compare); for (z = 0; z < MAX_ARRAY; z++) { if (array[z] != b[z]) { printarray("Unsorted array", orig, 0, MAX_ARRAY - 1); printarray(" Sorted array", array, 0, MAX_ARRAY-1); printf("qsort != quick_sort\n"); printarray("qsort array b", b, 0, MAX_ARRAY - 1); exit(1); } } } } } } } } } } } printf("\n"); fflush(stdout); /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ #endif /* STATIC_ARRAY */ exit(0); } /* End of main */ /* ------------------------------------------------------------------------ */
the_stack_data/140837.c
#include <stdlib.h> #include <string.h> //cmp function don't consider overflow int cmp(const void *lhs, const void *rhs) { return *(long *)lhs - *(long *)rhs; } long distance(int *p1, int *p2) { return (long)(p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1]); } int numberOfBoomerangs(int **points, int pointsSize, int *pointsColSize) { int res = 0, arrSize = 0; long arr[pointsSize * pointsSize]; for (int i = 0; i < pointsSize; ++i) { for (int j = 0; j < pointsSize; ++j) { if (i != j) arr[arrSize++] = distance(points[i], points[j]); } qsort(arr, arrSize, sizeof(long), cmp); for (int i = 1, j = 0; i <= arrSize; ++i) { if (i == arrSize || arr[i] != arr[j]) { res += (i - j) * (i - j - 1); j = i; } } arrSize = 0; } return res; }
the_stack_data/893963.c
/* * Copyright 2019 by Texas Instruments Incorporated. * */ /*****************************************************************************/ /* BOOT_CORTEX_M.C v##### - Initialize the ARM C runtime environment */ /* Copyright (c) 2017@%%%% Texas Instruments Incorporated */ /*****************************************************************************/ #include <stdint.h> #ifdef __TI_RTS_BUILD /*---------------------------------------------------------------------------*/ /* __TI_default_c_int00 indicates that the default TI entry routine is being */ /* used. The linker makes assumptions about what exit does when this symbol */ /* is seen. This symbols should NOT be defined if a customized exit routine */ /* is used. */ /*---------------------------------------------------------------------------*/ __asm("__TI_default_c_int00 .set 1"); #endif /*----------------------------------------------------------------------------*/ /* Define the user mode stack. The size will be determined by the linker. */ /*----------------------------------------------------------------------------*/ __attribute__((section(".stack"))) int __stack; /*----------------------------------------------------------------------------*/ /* Linker defined symbol that will point to the end of the user mode stack. */ /* The linker will enforce 8-byte alignment. */ /*----------------------------------------------------------------------------*/ extern int __STACK_END; /*----------------------------------------------------------------------------*/ /* Function declarations. */ /*----------------------------------------------------------------------------*/ __attribute__((weak)) extern void __mpu_init(void); extern int _system_pre_init(void); extern void __TI_auto_init(void); extern void _args_main(void); extern void exit(int); extern int main(); __attribute__((noreturn)) extern void xdc_runtime_System_exit__E(int); /*----------------------------------------------------------------------------*/ /* Default boot routine for Cortex-M */ /*----------------------------------------------------------------------------*/ static __inline __attribute__((always_inline, noreturn)) void _c_int00_template(int NEEDS_ARGS, int NEEDS_INIT) { // Initialize the stack pointer register char* stack_ptr = (char*)&__STACK_END; __asm volatile ("MSR msp, %0" : : "r" (stack_ptr) : ); // Initialize the FPU if building for floating point #ifdef __ARM_FP volatile uint32_t* cpacr = (volatile uint32_t*)0xE000ED88; *cpacr |= (0xf0 << 16); #endif __mpu_init(); if (_system_pre_init()) { if (NEEDS_INIT) __TI_auto_init(); } if (NEEDS_ARGS) { _args_main(); xdc_runtime_System_exit__E(0); } else { xdc_runtime_System_exit__E(main()); } } /******************************************************************************/ /* Specializations */ /******************************************************************************/ __attribute__((section(".text:_c_int00"), used, noreturn)) void _c_int00(void) { _c_int00_template(1, 1); } __attribute__((section(".text:_c_int00_noargs"), used, noreturn)) void _c_int00_noargs(void) { _c_int00_template(0, 1); } __attribute__((section(".text:_c_int00_noinit"), used, noreturn)) void _c_int00_noinit(void) { _c_int00_template(1, 0); } __attribute__((section(".text:_c_int00_noinit_noargs"), used, noreturn)) void _c_int00_noinit_noargs(void) { _c_int00_template(0, 0); } /* * @(#) ti.targets.arm.rtsarm; 1, 0, 0,0; 8-9-2019 17:26:43; /db/ztree/library/trees/xdctargets/xdctargets-v00/src/ xlibrary */
the_stack_data/125139594.c
/* Copyright 2014 Google Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #include <stdio.h> #include <strings.h> #include <fcntl.h> #include <syscall.h> #include <stdlib.h> double drand48(void); static int entries = 0; static int depth_max = 0; #define PERM 666 int *ran_array, *ordered_ran_array, *ordered_target; int current=0,depth=0; int max_xor; #define paste(front, back) front ## back static int create_main(int max_depth) { int i,j,k,rval; FILE * fp_main; char filename[100]; fp_main = fopen("FOO_main.c","w+"); fprintf (fp_main,"//\n"); fprintf (fp_main,"//\n"); fprintf (fp_main,"#include <stdio.h>\n"); fprintf (fp_main,"#include <stdlib.h>\n"); fprintf (fp_main,"\n"); fprintf (fp_main,"int main(int argc, char* argv[])\n"); fprintf (fp_main,"{\n"); fprintf (fp_main,"\tlong i=0;\n"); fprintf (fp_main,"\tlong j,k;\n"); fprintf (fp_main,"\tj=atol(argv[1]);\n"); fprintf (fp_main,"\tfor(k=0;k<j;k++){\n"); fprintf (fp_main,"\t__asm__( \n"); fprintf (fp_main,"\t\".align 64\\n\\t\"\n"); fprintf (fp_main,"\t\"jmp LP_%06d\\n\\t\"\n",ran_array[0]); for(j=0;j<max_depth;j++){ fprintf (fp_main,"\t\".align 64\\n\\t\"\n"); fprintf (fp_main,"\t\"LP_%06d:\\n\\t\"\n",ordered_ran_array[j]); fprintf (fp_main,"\t\"jmp LP_%06d\\n\\t\"\n",ran_array[ordered_target[j]+1]); fprintf (fp_main,"\t\"xorq %%rdx, %%rcx\\n\\t\"\n"); } fprintf (fp_main,"\t\"LP_%06d:\\n\\t\"\n",ran_array[max_depth]); fprintf (fp_main,"\t);\n"); fprintf (fp_main,"\t}\n"); fprintf (fp_main,"\n"); fprintf (fp_main,"\treturn 0;\n"); fprintf (fp_main,"}\n"); rval=fclose(fp_main); return 0; } main(int argc, char* argv[]) { int max_depth, rval, i, ranval, *temp_array, n=0, max_ran=1000000; if(argc < 2){ printf("generator needs one input number, argc = %d\n",argc); exit(1); } max_depth = atoi(argv[1]); printf (" max_depth= %d\n",max_depth); // the mechanics here causes one extra final jump to be generated to the terminating label // reduce max_depth by 1 max_depth--; if(max_depth >= max_ran){ fprintf(stderr,"too many functions %d, must be less than %d\n",max_depth,max_ran); exit(1); } ran_array = (int*) malloc((max_depth+1)*sizeof(int)); if(ran_array == 0){ fprintf(stderr,"failed to malloc random array\n"); exit(1); } ordered_ran_array = (int*) malloc(max_depth*sizeof(int)); if(ordered_ran_array == 0){ fprintf(stderr,"failed to malloc ordered random array\n"); exit(1); } ordered_target = (int*) malloc((max_depth+1)*sizeof(int)); if(ordered_target == 0){ fprintf(stderr,"failed to malloc ordered target array\n"); exit(1); } temp_array = (int*)malloc(10*max_depth*sizeof(int)); if(temp_array == 0){ fprintf(stderr,"failed to malloc temp random array\n"); exit(1); } for(i=0;i<10*max_depth;i++)temp_array[i]=-1; // warm up rand48 for(i=0;i<100;i++)ranval+=drand48(); for(i=0;i<max_depth;i++){ ranval =(int)( (double)(max_depth)*10.*drand48()); if((ranval < 0) || (ranval >= 10*max_depth)){ fprintf(stderr," bad ranval = %d, max_depth = %d\n",ranval,max_depth); exit(1); } while(temp_array[ranval] >= 0){ ranval++; if(ranval >= 10*max_depth)ranval=0; } ran_array[i]=ranval; temp_array[ranval] = i; } n=0; for(i=0;i<10*max_depth;i++){ if(temp_array[i] >= 0){ ordered_ran_array[n]=i; ordered_target[n]=temp_array[i]; n++; if(n>max_depth){ fprintf(stderr,"too many values in temp_array, should be less than %d, we have %d\n",max_depth,n); exit(1); } } } if(n != max_depth){ fprintf(stderr,"should have found %d random numbers generated but only found %d\n",max_depth-1,n); exit(1); } ran_array[max_depth] = max_ran; ordered_target[max_depth] = max_depth; rval = create_main(max_depth); }
the_stack_data/7951339.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <fcntl.h> #include <errno.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #define N(expr) do { if((expr) < 0) { \ fprintf(stderr, __FILE__ ":%d: %s\n", __LINE__, strerror(errno)); \ exit(1); } } while(0) const char *const usage = "Usage: trylock <lock_file>\n"; int main(int argc, char **argv) { int fd; struct flock lock; struct stat stbuf; if(argc != 2) { printf("%s", usage); return 1; } if((fd = open(argv[1], O_WRONLY)) < 0) { if(stat(argv[1], &stbuf) < 0 && errno != ENOENT) { fprintf(stderr, "could not open file '%s': %s\n", argv[1], strerror(errno)); return 1; } return 0; } lock.l_type = F_WRLCK; lock.l_start = 0; lock.l_whence = SEEK_SET; lock.l_len = 0; if(fcntl(fd, F_SETLK, &lock) < 0) { if(errno == EACCES || errno == EAGAIN) return 1; fprintf(stderr, "could not lock file '%s': %s\n", argv[1], strerror(errno)); return 1; } return 0; }
the_stack_data/128275.c
// Test that -print-target-triple prints correct triple. // RUN: %clang -print-effective-triple 2>&1 \ // RUN: --target=thumb-linux-gnu \ // RUN: | FileCheck %s // CHECK: armv4t-unknown-linux-gnu
the_stack_data/19246.c
#include <stdarg.h> #include <stdio.h> void some_func(char *str, ...) { va_list argp; va_start(argp, str); const char *key = NULL; const char *arg = NULL; for (key = va_arg(argp, const char *); key != NULL; key = va_arg(argp, const char *) ) { arg = va_arg(argp, const char *); printf("%s => %s\n", key, arg); } } int main(void) { some_func( "rand", "key1", "val1", "key2", "val2", NULL ); return 0; }
the_stack_data/218891998.c
/* Null stubs for coprocessor precision settings */ int sprec() { return 0; } int dprec() { return 0; } int ldprec() { return 0; }
the_stack_data/103265793.c
#include<stdio.h> int main (void){ int n,i,k, contpar, contimpar; contpar=0; contimpar=0; printf("Entre com um a quantidade de números\n"); scanf("%d", &k); for(i=0; i < k; i++){ printf("Entre com um número\n"); scanf("%d", &n); if(n%2 == 0 ){ printf("Par\n"); contpar++; }else{ printf("Impar\n"); contimpar++; } } printf("Existem %d pares\n", contpar); printf("Existem %d impares\n", contimpar); return 0; }
the_stack_data/247017437.c
#include <stdio.h> int main() { int i; int j; j=0; i=0; BannerMsg("balle",10); ms_sleep(1000); BannerMsg("Hi Natasha balle",10); ms_sleep(1000); BannerMsg("elepahnant fballe",10); return 0; }
the_stack_data/14201528.c
#include <string.h> /* using kmp preprocess create next array using dp */ char *longestPrefix(char *s) { int N = strlen(s); int next[N]; memset(next, 0, sizeof(next)); for (int i = 1; i < N; ++i) { int j = next[i - 1]; while (j > 0 && s[j] != s[i]) j = next[j - 1]; if (s[j] == s[i]) ++j; next[i] = j; } s[next[N - 1]] = '\0'; return s; }
the_stack_data/717089.c
/****************************************************************************** * * Copyright(c) 2013 - 2017 Realtek Corporation. * * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * *****************************************************************************/ #define __HAL_BTCOEX_C__ #ifdef CONFIG_BT_COEXIST #include <hal_data.h> #include <hal_btcoex.h> #include "btc/mp_precomp.h" /* ************************************ * Global variables * ************************************ */ const char *const BtProfileString[] = { "NONE", "A2DP", "PAN", "HID", "SCO", }; const char *const BtSpecString[] = { "1.0b", "1.1", "1.2", "2.0+EDR", "2.1+EDR", "3.0+HS", "4.0", }; const char *const BtLinkRoleString[] = { "Master", "Slave", }; const char *const h2cStaString[] = { "successful", "h2c busy", "rf off", "fw not read", }; const char *const ioStaString[] = { "success", "can not IO", "rf off", "fw not read", "wait io timeout", "invalid len", "idle Q empty", "insert waitQ fail", "unknown fail", "wrong level", "h2c stopped", }; const char *const GLBtcWifiBwString[] = { "11bg", "HT20", "HT40", "VHT80", "VHT160" }; const char *const GLBtcWifiFreqString[] = { "2.4G", "5G", "2.4G+5G" }; const char *const GLBtcIotPeerString[] = { "UNKNOWN", "REALTEK", "REALTEK_92SE", "BROADCOM", "RALINK", "ATHEROS", "CISCO", "MERU", "MARVELL", "REALTEK_SOFTAP", /* peer is RealTek SOFT_AP, by Bohn, 2009.12.17 */ "SELF_SOFTAP", /* Self is SoftAP */ "AIRGO", "INTEL", "RTK_APCLIENT", "REALTEK_81XX", "REALTEK_WOW", "REALTEK_JAGUAR_BCUTAP", "REALTEK_JAGUAR_CCUTAP" }; const char *const coexOpcodeString[] = { "Wifi status notify", "Wifi progress", "Wifi info", "Power state", "Set Control", "Get Control" }; const char *const coexIndTypeString[] = { "bt info", "pstdma", "limited tx/rx", "coex table", "request" }; const char *const coexH2cResultString[] = { "ok", "unknown", "un opcode", "opVer MM", "par Err", "par OoR", "reqNum MM", "halMac Fail", "h2c TimeOut", "Invalid c2h Len", "data overflow" }; #define HALBTCOUTSRC_AGG_CHK_WINDOW_IN_MS 8000 struct btc_coexist GLBtCoexist; BTC_OFFLOAD gl_coex_offload; u8 GLBtcWiFiInScanState; u8 GLBtcWiFiInIQKState; u8 GLBtcWiFiInIPS; u8 GLBtcWiFiInLPS; u8 GLBtcBtCoexAliveRegistered; /* * BT control H2C/C2H */ /* EXT_EID */ typedef enum _bt_ext_eid { C2H_WIFI_FW_ACTIVE_RSP = 0, C2H_TRIG_BY_BT_FW } BT_EXT_EID; /* C2H_STATUS */ typedef enum _bt_c2h_status { BT_STATUS_OK = 0, BT_STATUS_VERSION_MISMATCH, BT_STATUS_UNKNOWN_OPCODE, BT_STATUS_ERROR_PARAMETER } BT_C2H_STATUS; /* C2H BT OP CODES */ typedef enum _bt_op_code { BT_OP_GET_BT_VERSION = 0x00, BT_OP_WRITE_REG_ADDR = 0x0c, BT_OP_WRITE_REG_VALUE = 0x0d, BT_OP_READ_REG = 0x11, BT_LO_OP_GET_AFH_MAP_L = 0x1e, BT_LO_OP_GET_AFH_MAP_M = 0x1f, BT_LO_OP_GET_AFH_MAP_H = 0x20, BT_OP_GET_BT_COEX_SUPPORTED_FEATURE = 0x2a, BT_OP_GET_BT_COEX_SUPPORTED_VERSION = 0x2b, BT_OP_GET_BT_ANT_DET_VAL = 0x2c, BT_OP_GET_BT_BLE_SCAN_TYPE = 0x2d, BT_OP_GET_BT_BLE_SCAN_PARA = 0x2e, BT_OP_GET_BT_DEVICE_INFO = 0x30, BT_OP_GET_BT_FORBIDDEN_SLOT_VAL = 0x31, BT_OP_SET_BT_LANCONSTRAIN_LEVEL = 0x32, BT_OP_SET_BT_TEST_MODE_VAL = 0x33, BT_OP_MAX } BT_OP_CODE; #define BTC_MPOPER_TIMEOUT 50 /* unit: ms */ #define C2H_MAX_SIZE 16 u8 GLBtcBtMpOperSeq; _mutex GLBtcBtMpOperLock; _timer GLBtcBtMpOperTimer; _sema GLBtcBtMpRptSema; u8 GLBtcBtMpRptSeq; u8 GLBtcBtMpRptStatus; u8 GLBtcBtMpRptRsp[C2H_MAX_SIZE]; u8 GLBtcBtMpRptRspSize; u8 GLBtcBtMpRptWait; u8 GLBtcBtMpRptWiFiOK; u8 GLBtcBtMpRptBTOK; /* * Debug */ u32 GLBtcDbgType[COMP_MAX]; u8 GLBtcDbgBuf[BT_TMP_BUF_SIZE]; u8 gl_btc_trace_buf[BT_TMP_BUF_SIZE]; typedef struct _btcoexdbginfo { u8 *info; u32 size; /* buffer total size */ u32 len; /* now used length */ } BTCDBGINFO, *PBTCDBGINFO; BTCDBGINFO GLBtcDbgInfo; #define BT_Operation(Adapter) _FALSE static void DBG_BT_INFO_INIT(PBTCDBGINFO pinfo, u8 *pbuf, u32 size) { if (NULL == pinfo) return; _rtw_memset(pinfo, 0, sizeof(BTCDBGINFO)); if (pbuf && size) { pinfo->info = pbuf; pinfo->size = size; } } void DBG_BT_INFO(u8 *dbgmsg) { PBTCDBGINFO pinfo; u32 msglen, buflen; u8 *pbuf; pinfo = &GLBtcDbgInfo; if (NULL == pinfo->info) return; msglen = strlen(dbgmsg); if (pinfo->len + msglen > pinfo->size) return; pbuf = pinfo->info + pinfo->len; _rtw_memcpy(pbuf, dbgmsg, msglen); pinfo->len += msglen; } /* ************************************ * Debug related function * ************************************ */ static u8 halbtcoutsrc_IsBtCoexistAvailable(PBTC_COEXIST pBtCoexist) { if (!pBtCoexist->bBinded || NULL == pBtCoexist->Adapter) return _FALSE; return _TRUE; } static void halbtcoutsrc_DbgInit(void) { u8 i; for (i = 0; i < COMP_MAX; i++) GLBtcDbgType[i] = 0; } static void halbtcoutsrc_EnterPwrLock(PBTC_COEXIST pBtCoexist) { struct dvobj_priv *dvobj = adapter_to_dvobj((PADAPTER)pBtCoexist->Adapter); struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(dvobj); _enter_pwrlock(&pwrpriv->lock); } static void halbtcoutsrc_ExitPwrLock(PBTC_COEXIST pBtCoexist) { struct dvobj_priv *dvobj = adapter_to_dvobj((PADAPTER)pBtCoexist->Adapter); struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(dvobj); _exit_pwrlock(&pwrpriv->lock); } static u8 halbtcoutsrc_IsHwMailboxExist(PBTC_COEXIST pBtCoexist) { if (pBtCoexist->board_info.bt_chip_type == BTC_CHIP_CSR_BC4 || pBtCoexist->board_info.bt_chip_type == BTC_CHIP_CSR_BC8 ) return _FALSE; else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) return _FALSE; else return _TRUE; } static u8 halbtcoutsrc_LeaveLps(PBTC_COEXIST pBtCoexist) { PADAPTER padapter; padapter = pBtCoexist->Adapter; pBtCoexist->bt_info.bt_ctrl_lps = _TRUE; pBtCoexist->bt_info.bt_lps_on = _FALSE; return rtw_btcoex_LPS_Leave(padapter); } void halbtcoutsrc_EnterLps(PBTC_COEXIST pBtCoexist) { PADAPTER padapter; padapter = pBtCoexist->Adapter; if (pBtCoexist->bdontenterLPS == _FALSE) { pBtCoexist->bt_info.bt_ctrl_lps = _TRUE; pBtCoexist->bt_info.bt_lps_on = _TRUE; rtw_btcoex_LPS_Enter(padapter); } } void halbtcoutsrc_NormalLps(PBTC_COEXIST pBtCoexist) { PADAPTER padapter; padapter = pBtCoexist->Adapter; if (pBtCoexist->bt_info.bt_ctrl_lps) { pBtCoexist->bt_info.bt_lps_on = _FALSE; rtw_btcoex_LPS_Leave(padapter); pBtCoexist->bt_info.bt_ctrl_lps = _FALSE; /* recover the LPS state to the original */ #if 0 padapter->hal_func.UpdateLPSStatusHandler( padapter, pPSC->RegLeisurePsMode, pPSC->RegPowerSaveMode); #endif } } void halbtcoutsrc_Pre_NormalLps(PBTC_COEXIST pBtCoexist) { PADAPTER padapter; padapter = pBtCoexist->Adapter; if (pBtCoexist->bt_info.bt_ctrl_lps) { pBtCoexist->bt_info.bt_lps_on = _FALSE; rtw_btcoex_LPS_Leave(padapter); } } void halbtcoutsrc_Post_NormalLps(PBTC_COEXIST pBtCoexist) { if (pBtCoexist->bt_info.bt_ctrl_lps) pBtCoexist->bt_info.bt_ctrl_lps = _FALSE; } /* * Constraint: * 1. this function will request pwrctrl->lock */ void halbtcoutsrc_LeaveLowPower(PBTC_COEXIST pBtCoexist) { #ifdef CONFIG_LPS_LCLK PADAPTER padapter; PHAL_DATA_TYPE pHalData; struct pwrctrl_priv *pwrctrl; s32 ready; systime stime; s32 utime; u32 timeout; /* unit: ms */ padapter = pBtCoexist->Adapter; pHalData = GET_HAL_DATA(padapter); pwrctrl = adapter_to_pwrctl(padapter); ready = _FAIL; #ifdef LPS_RPWM_WAIT_MS timeout = LPS_RPWM_WAIT_MS; #else /* !LPS_RPWM_WAIT_MS */ timeout = 30; #endif /* !LPS_RPWM_WAIT_MS */ if (GLBtcBtCoexAliveRegistered == _TRUE) return; stime = rtw_get_current_time(); do { ready = rtw_register_task_alive(padapter, BTCOEX_ALIVE); if (_SUCCESS == ready) break; utime = rtw_get_passing_time_ms(stime); if (utime > timeout) break; rtw_msleep_os(1); } while (1); GLBtcBtCoexAliveRegistered = _TRUE; #endif /* CONFIG_LPS_LCLK */ } /* * Constraint: * 1. this function will request pwrctrl->lock */ void halbtcoutsrc_NormalLowPower(PBTC_COEXIST pBtCoexist) { #ifdef CONFIG_LPS_LCLK PADAPTER padapter; if (GLBtcBtCoexAliveRegistered == _FALSE) return; padapter = pBtCoexist->Adapter; rtw_unregister_task_alive(padapter, BTCOEX_ALIVE); GLBtcBtCoexAliveRegistered = _FALSE; #endif /* CONFIG_LPS_LCLK */ } void halbtcoutsrc_DisableLowPower(PBTC_COEXIST pBtCoexist, u8 bLowPwrDisable) { pBtCoexist->bt_info.bt_disable_low_pwr = bLowPwrDisable; if (bLowPwrDisable) halbtcoutsrc_LeaveLowPower(pBtCoexist); /* leave 32k low power. */ else halbtcoutsrc_NormalLowPower(pBtCoexist); /* original 32k low power behavior. */ } void halbtcoutsrc_AggregationCheck(PBTC_COEXIST pBtCoexist) { PADAPTER padapter; BOOLEAN bNeedToAct = _FALSE; static u32 preTime = 0; u32 curTime = 0; padapter = pBtCoexist->Adapter; /* ===================================== */ /* To void continuous deleteBA=>addBA=>deleteBA=>addBA */ /* This function is not allowed to continuous called. */ /* It can only be called after 8 seconds. */ /* ===================================== */ curTime = rtw_systime_to_ms(rtw_get_current_time()); if ((curTime - preTime) < HALBTCOUTSRC_AGG_CHK_WINDOW_IN_MS) /* over 8 seconds you can execute this function again. */ return; else preTime = curTime; if (pBtCoexist->bt_info.reject_agg_pkt) { bNeedToAct = _TRUE; pBtCoexist->bt_info.pre_reject_agg_pkt = pBtCoexist->bt_info.reject_agg_pkt; } else { if (pBtCoexist->bt_info.pre_reject_agg_pkt) { bNeedToAct = _TRUE; pBtCoexist->bt_info.pre_reject_agg_pkt = pBtCoexist->bt_info.reject_agg_pkt; } if (pBtCoexist->bt_info.pre_bt_ctrl_agg_buf_size != pBtCoexist->bt_info.bt_ctrl_agg_buf_size) { bNeedToAct = _TRUE; pBtCoexist->bt_info.pre_bt_ctrl_agg_buf_size = pBtCoexist->bt_info.bt_ctrl_agg_buf_size; } if (pBtCoexist->bt_info.bt_ctrl_agg_buf_size) { if (pBtCoexist->bt_info.pre_agg_buf_size != pBtCoexist->bt_info.agg_buf_size) bNeedToAct = _TRUE; pBtCoexist->bt_info.pre_agg_buf_size = pBtCoexist->bt_info.agg_buf_size; } } if (bNeedToAct) rtw_btcoex_rx_ampdu_apply(padapter); } u8 halbtcoutsrc_is_autoload_fail(PBTC_COEXIST pBtCoexist) { PADAPTER padapter; PHAL_DATA_TYPE pHalData; padapter = pBtCoexist->Adapter; pHalData = GET_HAL_DATA(padapter); return pHalData->bautoload_fail_flag; } u8 halbtcoutsrc_is_fw_ready(PBTC_COEXIST pBtCoexist) { PADAPTER padapter; padapter = pBtCoexist->Adapter; return GET_HAL_DATA(padapter)->bFWReady; } u8 halbtcoutsrc_IsDualBandConnected(PADAPTER padapter) { u8 ret = BTC_MULTIPORT_SCC; #ifdef CONFIG_MCC_MODE if (MCC_EN(padapter) && (rtw_hal_check_mcc_status(padapter, MCC_STATUS_DOING_MCC))) { struct dvobj_priv *dvobj = adapter_to_dvobj(padapter); struct mcc_obj_priv *mccobjpriv = &(dvobj->mcc_objpriv); u8 band0 = mccobjpriv->iface[0]->mlmeextpriv.cur_channel > 14 ? BAND_ON_5G : BAND_ON_2_4G; u8 band1 = mccobjpriv->iface[1]->mlmeextpriv.cur_channel > 14 ? BAND_ON_5G : BAND_ON_2_4G; if (band0 != band1) ret = BTC_MULTIPORT_MCC_DUAL_BAND; else ret = BTC_MULTIPORT_MCC_DUAL_CHANNEL; } #endif return ret; } u8 halbtcoutsrc_IsWifiBusy(PADAPTER padapter) { if (rtw_mi_check_status(padapter, MI_AP_ASSOC)) return _TRUE; if (rtw_mi_busy_traffic_check(padapter, _FALSE)) return _TRUE; return _FALSE; } static u32 _halbtcoutsrc_GetWifiLinkStatus(PADAPTER padapter) { struct mlme_priv *pmlmepriv; u8 bp2p; u32 portConnectedStatus; pmlmepriv = &padapter->mlmepriv; bp2p = _FALSE; portConnectedStatus = 0; #ifdef CONFIG_P2P if (!rtw_p2p_chk_state(&padapter->wdinfo, P2P_STATE_NONE)) bp2p = _TRUE; #endif /* CONFIG_P2P */ if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE) { if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE) { if (_TRUE == bp2p) portConnectedStatus |= WIFI_P2P_GO_CONNECTED; else portConnectedStatus |= WIFI_AP_CONNECTED; } else { if (_TRUE == bp2p) portConnectedStatus |= WIFI_P2P_GC_CONNECTED; else portConnectedStatus |= WIFI_STA_CONNECTED; } } return portConnectedStatus; } u32 halbtcoutsrc_GetWifiLinkStatus(PBTC_COEXIST pBtCoexist) { /* ================================= */ /* return value: */ /* [31:16]=> connected port number */ /* [15:0]=> port connected bit define */ /* ================================ */ PADAPTER padapter; u32 retVal; u32 portConnectedStatus, numOfConnectedPort; struct dvobj_priv *dvobj; _adapter *iface; int i; padapter = pBtCoexist->Adapter; retVal = 0; portConnectedStatus = 0; numOfConnectedPort = 0; dvobj = adapter_to_dvobj(padapter); for (i = 0; i < dvobj->iface_nums; i++) { iface = dvobj->padapters[i]; if ((iface) && rtw_is_adapter_up(iface)) { retVal = _halbtcoutsrc_GetWifiLinkStatus(iface); if (retVal) { portConnectedStatus |= retVal; numOfConnectedPort++; } } } retVal = (numOfConnectedPort << 16) | portConnectedStatus; return retVal; } struct btc_wifi_link_info halbtcoutsrc_getwifilinkinfo(PBTC_COEXIST pBtCoexist) { u8 n_assoc_iface = 0, i =0, mcc_en = _FALSE; PADAPTER adapter = NULL; PADAPTER iface = NULL; PADAPTER sta_iface = NULL, p2p_iface = NULL, ap_iface = NULL; BTC_LINK_MODE btc_link_moe = BTC_LINK_MAX; struct dvobj_priv *dvobj = NULL; struct mlme_ext_priv *mlmeext = NULL; struct btc_wifi_link_info wifi_link_info; adapter = (PADAPTER)pBtCoexist->Adapter; dvobj = adapter_to_dvobj(adapter); n_assoc_iface = rtw_mi_get_assoc_if_num(adapter); /* init value */ wifi_link_info.link_mode = BTC_LINK_NONE; wifi_link_info.sta_center_channel = 0; wifi_link_info.p2p_center_channel = 0; wifi_link_info.bany_client_join_go = _FALSE; wifi_link_info.benable_noa = _FALSE; wifi_link_info.bhotspot = _FALSE; for (i = 0; i < dvobj->iface_nums; i++) { iface = dvobj->padapters[i]; if (!iface) continue; mlmeext = &iface->mlmeextpriv; if (MLME_IS_GO(iface)) { wifi_link_info.link_mode = BTC_LINK_ONLY_GO; wifi_link_info.p2p_center_channel = rtw_get_center_ch(mlmeext->cur_channel, mlmeext->cur_bwmode, mlmeext->cur_ch_offset); p2p_iface = iface; if (rtw_linked_check(iface)) wifi_link_info.bany_client_join_go = _TRUE; } else if (MLME_IS_GC(iface)) { wifi_link_info.link_mode = BTC_LINK_ONLY_GC; wifi_link_info.p2p_center_channel = rtw_get_center_ch(mlmeext->cur_channel, mlmeext->cur_bwmode, mlmeext->cur_ch_offset); p2p_iface = iface; } else if (MLME_IS_AP(iface)) { wifi_link_info.link_mode = BTC_LINK_ONLY_AP; ap_iface = iface; wifi_link_info.p2p_center_channel = rtw_get_center_ch(mlmeext->cur_channel, mlmeext->cur_bwmode, mlmeext->cur_ch_offset); } else if (MLME_IS_STA(iface) && rtw_linked_check(iface)) { wifi_link_info.link_mode = BTC_LINK_ONLY_STA; wifi_link_info.sta_center_channel = rtw_get_center_ch(mlmeext->cur_channel, mlmeext->cur_bwmode, mlmeext->cur_ch_offset); sta_iface = iface; } } #ifdef CONFIG_MCC_MODE if (MCC_EN(adapter)) { if (rtw_hal_check_mcc_status(adapter, MCC_STATUS_DOING_MCC)) mcc_en = _TRUE; } #endif/* CONFIG_MCC_MODE */ if (n_assoc_iface == 0) { wifi_link_info.link_mode = BTC_LINK_NONE; } else if (n_assoc_iface == 1) { /* by pass */ } else if (n_assoc_iface == 2) { if (sta_iface && p2p_iface) { u8 band_sta = sta_iface->mlmeextpriv.cur_channel > 14 ? BAND_ON_5G : BAND_ON_2_4G; u8 band_p2p = p2p_iface->mlmeextpriv.cur_channel > 14 ? BAND_ON_5G : BAND_ON_2_4G; if (band_sta == band_p2p) { switch (band_sta) { case BAND_ON_2_4G: if (MLME_IS_GO(p2p_iface)) { #ifdef CONFIG_MCC_MODE wifi_link_info.link_mode = mcc_en == _TRUE ? BTC_LINK_2G_MCC_GO_STA : BTC_LINK_2G_SCC_GO_STA; #else /* !CONFIG_MCC_MODE */ wifi_link_info.link_mode = BTC_LINK_2G_SCC_GO_STA; #endif /* CONFIG_MCC_MODE */ } else if (MLME_IS_GC(p2p_iface)) { #ifdef CONFIG_MCC_MODE wifi_link_info.link_mode = mcc_en == _TRUE ? BTC_LINK_2G_MCC_GC_STA : BTC_LINK_2G_SCC_GC_STA; #else /* !CONFIG_MCC_MODE */ wifi_link_info.link_mode = BTC_LINK_2G_SCC_GC_STA; #endif /* CONFIG_MCC_MODE */ } break; case BAND_ON_5G: if (MLME_IS_GO(p2p_iface)) { #ifdef CONFIG_MCC_MODE wifi_link_info.link_mode = mcc_en == _TRUE ? BTC_LINK_5G_MCC_GO_STA : BTC_LINK_5G_SCC_GO_STA; #else /* !CONFIG_MCC_MODE */ wifi_link_info.link_mode = BTC_LINK_5G_SCC_GO_STA; #endif /* CONFIG_MCC_MODE */ } else if (MLME_IS_GC(p2p_iface)) { #ifdef CONFIG_MCC_MODE wifi_link_info.link_mode = mcc_en == _TRUE ? BTC_LINK_5G_MCC_GC_STA : BTC_LINK_5G_SCC_GC_STA; #else /* !CONFIG_MCC_MODE */ wifi_link_info.link_mode = BTC_LINK_5G_SCC_GC_STA; #endif /* CONFIG_MCC_MODE */ } break; } } else { if (MLME_IS_GO(p2p_iface)) wifi_link_info.link_mode = BTC_LINK_25G_MCC_GO_STA; else if (MLME_IS_GC(p2p_iface)) wifi_link_info.link_mode = BTC_LINK_25G_MCC_GC_STA; } } } else { if (pBtCoexist->board_info.btdm_ant_num == 1) RTW_ERR("%s do not support n_assoc_iface > 2 (ant_num == 1)", __func__); } return wifi_link_info; } static void _btmpoper_timer_hdl(void *p) { if (GLBtcBtMpRptWait == _TRUE) { GLBtcBtMpRptWait = _FALSE; _rtw_up_sema(&GLBtcBtMpRptSema); } } /* * !IMPORTANT! * Before call this function, caller should acquire "GLBtcBtMpOperLock"! * Othrewise there will be racing problem and something may go wrong. */ static u8 _btmpoper_cmd(PBTC_COEXIST pBtCoexist, u8 opcode, u8 opcodever, u8 *cmd, u8 size) { PADAPTER padapter; u8 buf[H2C_BTMP_OPER_LEN] = {0}; u8 buflen; u8 seq; s32 ret; if (!cmd && size) size = 0; if ((size + 2) > H2C_BTMP_OPER_LEN) return BT_STATUS_H2C_LENGTH_EXCEEDED; buflen = size + 2; seq = GLBtcBtMpOperSeq & 0xF; GLBtcBtMpOperSeq++; buf[0] = (opcodever & 0xF) | (seq << 4); buf[1] = opcode; if (cmd && size) _rtw_memcpy(buf + 2, cmd, size); GLBtcBtMpRptWait = _TRUE; GLBtcBtMpRptWiFiOK = _FALSE; GLBtcBtMpRptBTOK = _FALSE; GLBtcBtMpRptStatus = 0; padapter = pBtCoexist->Adapter; _set_timer(&GLBtcBtMpOperTimer, BTC_MPOPER_TIMEOUT); if (rtw_hal_fill_h2c_cmd(padapter, H2C_BT_MP_OPER, buflen, buf) == _FAIL) { _cancel_timer_ex(&GLBtcBtMpOperTimer); ret = BT_STATUS_H2C_FAIL; goto exit; } _rtw_down_sema(&GLBtcBtMpRptSema); /* GLBtcBtMpRptWait should be _FALSE here*/ if (GLBtcBtMpRptWiFiOK == _FALSE) { RTW_ERR("%s: Didn't get H2C Rsp Event!\n", __FUNCTION__); ret = BT_STATUS_H2C_TIMTOUT; goto exit; } if (GLBtcBtMpRptBTOK == _FALSE) { RTW_DBG("%s: Didn't get BT response!\n", __FUNCTION__); ret = BT_STATUS_H2C_BT_NO_RSP; goto exit; } if (seq != GLBtcBtMpRptSeq) { RTW_ERR("%s: Sequence number not match!(%d!=%d)!\n", __FUNCTION__, seq, GLBtcBtMpRptSeq); ret = BT_STATUS_C2H_REQNUM_MISMATCH; goto exit; } switch (GLBtcBtMpRptStatus) { /* Examine the status reported from C2H */ case BT_STATUS_OK: ret = BT_STATUS_BT_OP_SUCCESS; RTW_DBG("%s: C2H status = BT_STATUS_BT_OP_SUCCESS\n", __FUNCTION__); break; case BT_STATUS_VERSION_MISMATCH: ret = BT_STATUS_OPCODE_L_VERSION_MISMATCH; RTW_DBG("%s: C2H status = BT_STATUS_OPCODE_L_VERSION_MISMATCH\n", __FUNCTION__); break; case BT_STATUS_UNKNOWN_OPCODE: ret = BT_STATUS_UNKNOWN_OPCODE_L; RTW_DBG("%s: C2H status = MP_BT_STATUS_UNKNOWN_OPCODE_L\n", __FUNCTION__); break; case BT_STATUS_ERROR_PARAMETER: ret = BT_STATUS_PARAMETER_FORMAT_ERROR_L; RTW_DBG("%s: C2H status = MP_BT_STATUS_PARAMETER_FORMAT_ERROR_L\n", __FUNCTION__); break; default: ret = BT_STATUS_UNKNOWN_STATUS_L; RTW_DBG("%s: C2H status = MP_BT_STATUS_UNKNOWN_STATUS_L\n", __FUNCTION__); break; } exit: return ret; } u32 halbtcoutsrc_GetBtPatchVer(PBTC_COEXIST pBtCoexist) { if (pBtCoexist->bt_info.get_bt_fw_ver_cnt <= 5) { if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) { _irqL irqL; u8 ret; _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL); ret = _btmpoper_cmd(pBtCoexist, BT_OP_GET_BT_VERSION, 0, NULL, 0); if (BT_STATUS_BT_OP_SUCCESS == ret) { pBtCoexist->bt_info.bt_real_fw_ver = le32_to_cpu(*(u32 *)GLBtcBtMpRptRsp); pBtCoexist->bt_info.get_bt_fw_ver_cnt++; } _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL); } else { #ifdef CONFIG_BT_COEXIST_SOCKET_TRX u8 dataLen = 2; u8 buf[4] = {0}; buf[0] = 0x0; /* OP_Code */ buf[1] = 0x0; /* OP_Code_Length */ BT_SendEventExtBtCoexControl(pBtCoexist->Adapter, _FALSE, dataLen, &buf[0]); #endif /* !CONFIG_BT_COEXIST_SOCKET_TRX */ } } return pBtCoexist->bt_info.bt_real_fw_ver; } s32 halbtcoutsrc_GetWifiRssi(PADAPTER padapter) { return rtw_dm_get_min_rssi(padapter); } u32 halbtcoutsrc_GetBtCoexSupportedFeature(void *pBtcContext) { PBTC_COEXIST pBtCoexist; u32 ret = BT_STATUS_BT_OP_SUCCESS; u32 data = 0; pBtCoexist = (PBTC_COEXIST)pBtcContext; if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) { u8 buf[3] = {0}; _irqL irqL; u8 op_code; u8 status; _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL); op_code = BT_OP_GET_BT_COEX_SUPPORTED_FEATURE; status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0); if (status == BT_STATUS_BT_OP_SUCCESS) data = le16_to_cpu(*(u16 *)GLBtcBtMpRptRsp); else ret = SET_BT_MP_OPER_RET(op_code, status); _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL); } else ret = BT_STATUS_NOT_IMPLEMENT; return data; } u32 halbtcoutsrc_GetBtCoexSupportedVersion(void *pBtcContext) { PBTC_COEXIST pBtCoexist; u32 ret = BT_STATUS_BT_OP_SUCCESS; u32 data = 0xFFFF; pBtCoexist = (PBTC_COEXIST)pBtcContext; if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) { u8 buf[3] = {0}; _irqL irqL; u8 op_code; u8 status; _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL); op_code = BT_OP_GET_BT_COEX_SUPPORTED_VERSION; status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0); if (status == BT_STATUS_BT_OP_SUCCESS) data = le16_to_cpu(*(u16 *)GLBtcBtMpRptRsp); else ret = SET_BT_MP_OPER_RET(op_code, status); _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL); } else ret = BT_STATUS_NOT_IMPLEMENT; return data; } u32 halbtcoutsrc_GetBtDeviceInfo(void *pBtcContext) { PBTC_COEXIST pBtCoexist; u32 ret = BT_STATUS_BT_OP_SUCCESS; u32 btDeviceInfo = 0; pBtCoexist = (PBTC_COEXIST)pBtcContext; if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) { u8 buf[3] = {0}; _irqL irqL; u8 op_code; u8 status; _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL); op_code = BT_OP_GET_BT_DEVICE_INFO; status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0); if (status == BT_STATUS_BT_OP_SUCCESS) btDeviceInfo = le32_to_cpu(*(u32 *)GLBtcBtMpRptRsp); else ret = SET_BT_MP_OPER_RET(op_code, status); _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL); } else ret = BT_STATUS_NOT_IMPLEMENT; return btDeviceInfo; } u32 halbtcoutsrc_GetBtForbiddenSlotVal(void *pBtcContext) { PBTC_COEXIST pBtCoexist; u32 ret = BT_STATUS_BT_OP_SUCCESS; u32 btForbiddenSlotVal = 0; pBtCoexist = (PBTC_COEXIST)pBtcContext; if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) { u8 buf[3] = {0}; _irqL irqL; u8 op_code; u8 status; _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL); op_code = BT_OP_GET_BT_FORBIDDEN_SLOT_VAL; status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0); if (status == BT_STATUS_BT_OP_SUCCESS) btForbiddenSlotVal = le32_to_cpu(*(u32 *)GLBtcBtMpRptRsp); else ret = SET_BT_MP_OPER_RET(op_code, status); _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL); } else ret = BT_STATUS_NOT_IMPLEMENT; return btForbiddenSlotVal; } static u8 halbtcoutsrc_GetWifiScanAPNum(PADAPTER padapter) { struct mlme_priv *pmlmepriv; struct mlme_ext_priv *pmlmeext; static u8 scan_AP_num = 0; pmlmepriv = &padapter->mlmepriv; pmlmeext = &padapter->mlmeextpriv; if (GLBtcWiFiInScanState == _FALSE) { if (pmlmepriv->num_of_scanned > 0xFF) scan_AP_num = 0xFF; else scan_AP_num = (u8)pmlmepriv->num_of_scanned; } return scan_AP_num; } u32 halbtcoutsrc_GetPhydmVersion(void *pBtcContext) { struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext; PADAPTER Adapter = pBtCoexist->Adapter; #ifdef CONFIG_RTL8192E return RELEASE_VERSION_8192E; #endif #ifdef CONFIG_RTL8821A return RELEASE_VERSION_8821A; #endif #ifdef CONFIG_RTL8723B return RELEASE_VERSION_8723B; #endif #ifdef CONFIG_RTL8812A return RELEASE_VERSION_8812A; #endif #ifdef CONFIG_RTL8703B return RELEASE_VERSION_8703B; #endif #ifdef CONFIG_RTL8822B return RELEASE_VERSION_8822B; #endif #ifdef CONFIG_RTL8723D return RELEASE_VERSION_8723D; #endif #ifdef CONFIG_RTL8821C return RELEASE_VERSION_8821C; #endif #ifdef CONFIG_RTL8192F return RELEASE_VERSION_8192F; #endif #ifdef CONFIG_RTL8822C return RELEASE_VERSION_8822C; #endif #ifdef CONFIG_RTL8814A return RELEASE_VERSION_8814A; #endif #ifdef CONFIG_RTL8814B return RELEASE_VERSION_8814B; #endif } u8 halbtcoutsrc_Get(void *pBtcContext, u8 getType, void *pOutBuf) { PBTC_COEXIST pBtCoexist; PADAPTER padapter; PHAL_DATA_TYPE pHalData; struct mlme_ext_priv *mlmeext; struct btc_wifi_link_info *wifi_link_info; u8 bSoftApExist, bVwifiExist; u8 *pu8; s32 *pS4Tmp; u32 *pU4Tmp; u8 *pU1Tmp; u16 *pU2Tmp; u8 ret; pBtCoexist = (PBTC_COEXIST)pBtcContext; if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) return _FALSE; padapter = pBtCoexist->Adapter; pHalData = GET_HAL_DATA(padapter); mlmeext = &padapter->mlmeextpriv; bSoftApExist = _FALSE; bVwifiExist = _FALSE; pu8 = (u8 *)pOutBuf; pS4Tmp = (s32 *)pOutBuf; pU4Tmp = (u32 *)pOutBuf; pU1Tmp = (u8 *)pOutBuf; pU2Tmp = (u16*)pOutBuf; wifi_link_info = (struct btc_wifi_link_info *)pOutBuf; ret = _TRUE; switch (getType) { case BTC_GET_BL_HS_OPERATION: *pu8 = _FALSE; ret = _FALSE; break; case BTC_GET_BL_HS_CONNECTING: *pu8 = _FALSE; ret = _FALSE; break; case BTC_GET_BL_WIFI_FW_READY: *pu8 = halbtcoutsrc_is_fw_ready(pBtCoexist); break; case BTC_GET_BL_WIFI_CONNECTED: *pu8 = (rtw_mi_check_status(padapter, MI_LINKED)) ? _TRUE : _FALSE; break; case BTC_GET_BL_WIFI_DUAL_BAND_CONNECTED: *pu8 = halbtcoutsrc_IsDualBandConnected(padapter); break; case BTC_GET_BL_WIFI_BUSY: *pu8 = halbtcoutsrc_IsWifiBusy(padapter); break; case BTC_GET_BL_WIFI_SCAN: #if 0 *pu8 = (rtw_mi_check_fwstate(padapter, WIFI_SITE_MONITOR)) ? _TRUE : _FALSE; #else /* Use the value of the new variable GLBtcWiFiInScanState to judge whether WiFi is in scan state or not, since the originally used flag WIFI_SITE_MONITOR in fwstate may not be cleared in time */ *pu8 = GLBtcWiFiInScanState; #endif break; case BTC_GET_BL_WIFI_LINK: *pu8 = (rtw_mi_check_status(padapter, MI_STA_LINKING)) ? _TRUE : _FALSE; break; case BTC_GET_BL_WIFI_ROAM: *pu8 = (rtw_mi_check_status(padapter, MI_STA_LINKING)) ? _TRUE : _FALSE; break; case BTC_GET_BL_WIFI_4_WAY_PROGRESS: *pu8 = _FALSE; break; case BTC_GET_BL_WIFI_UNDER_5G: *pu8 = (pHalData->current_band_type == BAND_ON_5G) ? _TRUE : _FALSE; break; case BTC_GET_BL_WIFI_AP_MODE_ENABLE: *pu8 = (rtw_mi_check_status(padapter, MI_AP_MODE)) ? _TRUE : _FALSE; break; case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION: *pu8 = padapter->securitypriv.dot11PrivacyAlgrthm == 0 ? _FALSE : _TRUE; break; case BTC_GET_BL_WIFI_UNDER_B_MODE: if (mlmeext->cur_wireless_mode == WIRELESS_11B) *pu8 = _TRUE; else *pu8 = _FALSE; break; case BTC_GET_BL_WIFI_IS_IN_MP_MODE: if (padapter->registrypriv.mp_mode == 0) *pu8 = _FALSE; else *pu8 = _TRUE; break; case BTC_GET_BL_EXT_SWITCH: *pu8 = _FALSE; break; case BTC_GET_BL_IS_ASUS_8723B: /* Always return FALSE in linux driver since this case is added only for windows driver */ *pu8 = _FALSE; break; case BTC_GET_BL_RF4CE_CONNECTED: #ifdef CONFIG_RF4CE_COEXIST if (hal_btcoex_get_rf4ce_link_state() == 0) *pu8 = FALSE; else *pu8 = TRUE; #else *pu8 = FALSE; #endif break; case BTC_GET_BL_WIFI_LW_PWR_STATE: /* return false due to coex do not run during 32K */ *pu8 = FALSE; break; case BTC_GET_S4_WIFI_RSSI: *pS4Tmp = halbtcoutsrc_GetWifiRssi(padapter); break; case BTC_GET_S4_HS_RSSI: *pS4Tmp = 0; ret = _FALSE; break; case BTC_GET_U4_WIFI_BW: if (IsLegacyOnly(mlmeext->cur_wireless_mode)) *pU4Tmp = BTC_WIFI_BW_LEGACY; else { switch (pHalData->current_channel_bw) { case CHANNEL_WIDTH_20: *pU4Tmp = BTC_WIFI_BW_HT20; break; case CHANNEL_WIDTH_40: *pU4Tmp = BTC_WIFI_BW_HT40; break; case CHANNEL_WIDTH_80: *pU4Tmp = BTC_WIFI_BW_HT80; break; case CHANNEL_WIDTH_160: *pU4Tmp = BTC_WIFI_BW_HT160; break; default: RTW_INFO("[BTCOEX] unknown bandwidth(%d)\n", pHalData->current_channel_bw); *pU4Tmp = BTC_WIFI_BW_HT40; break; } } break; case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION: case BTC_GET_U4_WIFI_TRAFFIC_DIR: { PRT_LINK_DETECT_T plinkinfo; plinkinfo = &padapter->mlmepriv.LinkDetectInfo; if (plinkinfo->NumTxOkInPeriod > plinkinfo->NumRxOkInPeriod) *pU4Tmp = BTC_WIFI_TRAFFIC_TX; else *pU4Tmp = BTC_WIFI_TRAFFIC_RX; } break; case BTC_GET_U4_WIFI_FW_VER: *pU4Tmp = pHalData->firmware_version << 16; *pU4Tmp |= pHalData->firmware_sub_version; break; case BTC_GET_U4_WIFI_PHY_VER: *pU4Tmp = halbtcoutsrc_GetPhydmVersion(pBtCoexist); break; case BTC_GET_U4_WIFI_LINK_STATUS: *pU4Tmp = halbtcoutsrc_GetWifiLinkStatus(pBtCoexist); break; case BTC_GET_BL_WIFI_LINK_INFO: *wifi_link_info = halbtcoutsrc_getwifilinkinfo(pBtCoexist); break; case BTC_GET_U4_BT_PATCH_VER: *pU4Tmp = halbtcoutsrc_GetBtPatchVer(pBtCoexist); break; case BTC_GET_U4_VENDOR: *pU4Tmp = BTC_VENDOR_OTHER; break; case BTC_GET_U4_SUPPORTED_VERSION: *pU4Tmp = halbtcoutsrc_GetBtCoexSupportedVersion(pBtCoexist); break; case BTC_GET_U4_SUPPORTED_FEATURE: *pU4Tmp = halbtcoutsrc_GetBtCoexSupportedFeature(pBtCoexist); break; case BTC_GET_U4_BT_DEVICE_INFO: *pU4Tmp = halbtcoutsrc_GetBtDeviceInfo(pBtCoexist); break; case BTC_GET_U4_BT_FORBIDDEN_SLOT_VAL: case BTC_GET_U4_BT_A2DP_FLUSH_VAL: *pU4Tmp = halbtcoutsrc_GetBtForbiddenSlotVal(pBtCoexist); break; case BTC_GET_U4_WIFI_IQK_TOTAL: *pU4Tmp = pHalData->odmpriv.n_iqk_cnt; break; case BTC_GET_U4_WIFI_IQK_OK: *pU4Tmp = pHalData->odmpriv.n_iqk_ok_cnt; break; case BTC_GET_U4_WIFI_IQK_FAIL: *pU4Tmp = pHalData->odmpriv.n_iqk_fail_cnt; break; case BTC_GET_U1_WIFI_DOT11_CHNL: *pU1Tmp = padapter->mlmeextpriv.cur_channel; break; case BTC_GET_U1_WIFI_CENTRAL_CHNL: *pU1Tmp = pHalData->current_channel; break; case BTC_GET_U1_WIFI_HS_CHNL: *pU1Tmp = 0; ret = _FALSE; break; case BTC_GET_U1_WIFI_P2P_CHNL: #ifdef CONFIG_P2P { struct wifidirect_info *pwdinfo = &(padapter->wdinfo); *pU1Tmp = pwdinfo->operating_channel; } #else *pU1Tmp = 0; #endif break; case BTC_GET_U1_MAC_PHY_MODE: /* *pU1Tmp = BTC_SMSP; * *pU1Tmp = BTC_DMSP; * *pU1Tmp = BTC_DMDP; * *pU1Tmp = BTC_MP_UNKNOWN; */ break; case BTC_GET_U1_AP_NUM: *pU1Tmp = halbtcoutsrc_GetWifiScanAPNum(padapter); break; case BTC_GET_U1_ANT_TYPE: switch (pHalData->bt_coexist.btAntisolation) { case 0: *pU1Tmp = (u8)BTC_ANT_TYPE_0; pBtCoexist->board_info.ant_type = (u8)BTC_ANT_TYPE_0; break; case 1: *pU1Tmp = (u8)BTC_ANT_TYPE_1; pBtCoexist->board_info.ant_type = (u8)BTC_ANT_TYPE_1; break; case 2: *pU1Tmp = (u8)BTC_ANT_TYPE_2; pBtCoexist->board_info.ant_type = (u8)BTC_ANT_TYPE_2; break; case 3: *pU1Tmp = (u8)BTC_ANT_TYPE_3; pBtCoexist->board_info.ant_type = (u8)BTC_ANT_TYPE_3; break; case 4: *pU1Tmp = (u8)BTC_ANT_TYPE_4; pBtCoexist->board_info.ant_type = (u8)BTC_ANT_TYPE_4; break; } break; case BTC_GET_U1_IOT_PEER: *pU1Tmp = mlmeext->mlmext_info.assoc_AP_vendor; break; /* =======1Ant=========== */ case BTC_GET_U1_LPS_MODE: *pU1Tmp = padapter->dvobj->pwrctl_priv.pwr_mode; break; case BTC_GET_U2_BEACON_PERIOD: *pU2Tmp = mlmeext->mlmext_info.bcn_interval; break; default: ret = _FALSE; break; } return ret; } u16 halbtcoutsrc_LnaConstrainLvl(void *pBtcContext, u8 *lna_constrain_level) { PBTC_COEXIST pBtCoexist; u16 ret = BT_STATUS_BT_OP_SUCCESS; pBtCoexist = (PBTC_COEXIST)pBtcContext; if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) { _irqL irqL; u8 op_code; _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL); ret = _btmpoper_cmd(pBtCoexist, BT_OP_SET_BT_LANCONSTRAIN_LEVEL, 0, lna_constrain_level, 1); _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL); } else { ret = BT_STATUS_NOT_IMPLEMENT; RTW_INFO("%s halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == FALSE\n", __func__); } return ret; } u8 halbtcoutsrc_SetBtGoldenRxRange(void *pBtcContext, u8 profile, u8 range_shift) { /* wait for implementation if necessary */ return 0; } u8 halbtcoutsrc_Set(void *pBtcContext, u8 setType, void *pInBuf) { PBTC_COEXIST pBtCoexist; PADAPTER padapter; PHAL_DATA_TYPE pHalData; u8 *pu8; u8 *pU1Tmp; u16 *pU2Tmp; u32 *pU4Tmp; u8 ret; u8 result = _TRUE; pBtCoexist = (PBTC_COEXIST)pBtcContext; if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) return _FALSE; padapter = pBtCoexist->Adapter; pHalData = GET_HAL_DATA(padapter); pu8 = (u8 *)pInBuf; pU1Tmp = (u8 *)pInBuf; pU2Tmp = (u16*)pInBuf; pU4Tmp = (u32 *)pInBuf; ret = _TRUE; switch (setType) { /* set some u8 type variables. */ case BTC_SET_BL_BT_DISABLE: pBtCoexist->bt_info.bt_disabled = *pu8; break; case BTC_SET_BL_BT_ENABLE_DISABLE_CHANGE: pBtCoexist->bt_info.bt_enable_disable_change = *pu8; break; case BTC_SET_BL_BT_TRAFFIC_BUSY: pBtCoexist->bt_info.bt_busy = *pu8; break; case BTC_SET_BL_BT_LIMITED_DIG: pBtCoexist->bt_info.limited_dig = *pu8; break; case BTC_SET_BL_FORCE_TO_ROAM: pBtCoexist->bt_info.force_to_roam = *pu8; break; case BTC_SET_BL_TO_REJ_AP_AGG_PKT: pBtCoexist->bt_info.reject_agg_pkt = *pu8; break; case BTC_SET_BL_BT_CTRL_AGG_SIZE: pBtCoexist->bt_info.bt_ctrl_agg_buf_size = *pu8; break; case BTC_SET_BL_INC_SCAN_DEV_NUM: pBtCoexist->bt_info.increase_scan_dev_num = *pu8; break; case BTC_SET_BL_BT_TX_RX_MASK: pBtCoexist->bt_info.bt_tx_rx_mask = *pu8; break; case BTC_SET_BL_MIRACAST_PLUS_BT: pBtCoexist->bt_info.miracast_plus_bt = *pu8; break; /* set some u8 type variables. */ case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON: pBtCoexist->bt_info.rssi_adjust_for_agc_table_on = *pU1Tmp; break; case BTC_SET_U1_AGG_BUF_SIZE: pBtCoexist->bt_info.agg_buf_size = *pU1Tmp; break; /* the following are some action which will be triggered */ case BTC_SET_ACT_GET_BT_RSSI: #if 0 BT_SendGetBtRssiEvent(padapter); #else ret = _FALSE; #endif break; case BTC_SET_ACT_AGGREGATE_CTRL: halbtcoutsrc_AggregationCheck(pBtCoexist); break; /* =======1Ant=========== */ /* set some u8 type variables. */ case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE: pBtCoexist->bt_info.rssi_adjust_for_1ant_coex_type = *pU1Tmp; break; case BTC_SET_U1_LPS_VAL: pBtCoexist->bt_info.lps_val = *pU1Tmp; break; case BTC_SET_U1_RPWM_VAL: pBtCoexist->bt_info.rpwm_val = *pU1Tmp; break; /* the following are some action which will be triggered */ case BTC_SET_ACT_LEAVE_LPS: result = halbtcoutsrc_LeaveLps(pBtCoexist); break; case BTC_SET_ACT_ENTER_LPS: halbtcoutsrc_EnterLps(pBtCoexist); break; case BTC_SET_ACT_NORMAL_LPS: halbtcoutsrc_NormalLps(pBtCoexist); break; case BTC_SET_ACT_PRE_NORMAL_LPS: halbtcoutsrc_Pre_NormalLps(pBtCoexist); break; case BTC_SET_ACT_POST_NORMAL_LPS: halbtcoutsrc_Post_NormalLps(pBtCoexist); break; case BTC_SET_ACT_DISABLE_LOW_POWER: halbtcoutsrc_DisableLowPower(pBtCoexist, *pu8); break; case BTC_SET_ACT_UPDATE_RAMASK: /* pBtCoexist->bt_info.ra_mask = *pU4Tmp; if (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE) == _TRUE) { struct sta_info *psta; PWLAN_BSSID_EX cur_network; cur_network = &padapter->mlmeextpriv.mlmext_info.network; psta = rtw_get_stainfo(&padapter->stapriv, cur_network->MacAddress); rtw_hal_update_ra_mask(psta); } */ break; case BTC_SET_ACT_SEND_MIMO_PS: { u8 newMimoPsMode = 3; struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); /* *pU1Tmp = 0 use SM_PS static type */ /* *pU1Tmp = 1 disable SM_PS */ if (*pU1Tmp == 0) newMimoPsMode = WLAN_HT_CAP_SM_PS_STATIC; else if (*pU1Tmp == 1) newMimoPsMode = WLAN_HT_CAP_SM_PS_DISABLED; if (check_fwstate(&padapter->mlmepriv , WIFI_ASOC_STATE) == _TRUE) { /* issue_action_SM_PS(padapter, get_my_bssid(&(pmlmeinfo->network)), newMimoPsMode); */ issue_action_SM_PS_wait_ack(padapter , get_my_bssid(&(pmlmeinfo->network)) , newMimoPsMode, 3 , 1); } } break; case BTC_SET_ACT_CTRL_BT_INFO: #ifdef CONFIG_BT_COEXIST_SOCKET_TRX { u8 dataLen = *pU1Tmp; u8 tmpBuf[BTC_TMP_BUF_SHORT]; if (dataLen) _rtw_memcpy(tmpBuf, pU1Tmp + 1, dataLen); BT_SendEventExtBtInfoControl(padapter, dataLen, &tmpBuf[0]); } #else /* !CONFIG_BT_COEXIST_SOCKET_TRX */ ret = _FALSE; #endif /* CONFIG_BT_COEXIST_SOCKET_TRX */ break; case BTC_SET_ACT_CTRL_BT_COEX: #ifdef CONFIG_BT_COEXIST_SOCKET_TRX { u8 dataLen = *pU1Tmp; u8 tmpBuf[BTC_TMP_BUF_SHORT]; if (dataLen) _rtw_memcpy(tmpBuf, pU1Tmp + 1, dataLen); BT_SendEventExtBtCoexControl(padapter, _FALSE, dataLen, &tmpBuf[0]); } #else /* !CONFIG_BT_COEXIST_SOCKET_TRX */ ret = _FALSE; #endif /* CONFIG_BT_COEXIST_SOCKET_TRX */ break; case BTC_SET_ACT_CTRL_8723B_ANT: #if 0 { u8 dataLen = *pU1Tmp; u8 tmpBuf[BTC_TMP_BUF_SHORT]; if (dataLen) PlatformMoveMemory(&tmpBuf[0], pU1Tmp + 1, dataLen); BT_Set8723bAnt(Adapter, dataLen, &tmpBuf[0]); } #else ret = _FALSE; #endif break; case BTC_SET_BL_BT_LNA_CONSTRAIN_LEVEL: halbtcoutsrc_LnaConstrainLvl(pBtCoexist, pu8); break; case BTC_SET_BL_BT_GOLDEN_RX_RANGE: halbtcoutsrc_SetBtGoldenRxRange(pBtCoexist, (*pU2Tmp & 0xff00) >> 8, (*pU2Tmp & 0xff)); break; case BTC_SET_RESET_COEX_VAR: _rtw_memset(&pBtCoexist->coex_dm, 0x00, sizeof(pBtCoexist->coex_dm)); _rtw_memset(&pBtCoexist->coex_sta, 0x00, sizeof(pBtCoexist->coex_sta)); switch(pBtCoexist->chip_type) { #ifdef CONFIG_RTL8822B case BTC_CHIP_RTL8822B: _rtw_memset(&pBtCoexist->coex_dm_8822b_1ant, 0x00, sizeof(pBtCoexist->coex_dm_8822b_1ant)); _rtw_memset(&pBtCoexist->coex_dm_8822b_2ant, 0x00, sizeof(pBtCoexist->coex_dm_8822b_2ant)); _rtw_memset(&pBtCoexist->coex_sta_8822b_1ant, 0x00, sizeof(pBtCoexist->coex_sta_8822b_1ant)); _rtw_memset(&pBtCoexist->coex_sta_8822b_2ant, 0x00, sizeof(pBtCoexist->coex_sta_8822b_2ant)); break; #endif #ifdef CONFIG_RTL8821C case BTC_CHIP_RTL8821C: _rtw_memset(&pBtCoexist->coex_dm_8821c_1ant, 0x00, sizeof(pBtCoexist->coex_dm_8821c_1ant)); _rtw_memset(&pBtCoexist->coex_dm_8821c_2ant, 0x00, sizeof(pBtCoexist->coex_dm_8821c_2ant)); _rtw_memset(&pBtCoexist->coex_sta_8821c_1ant, 0x00, sizeof(pBtCoexist->coex_sta_8821c_1ant)); _rtw_memset(&pBtCoexist->coex_sta_8821c_2ant, 0x00, sizeof(pBtCoexist->coex_sta_8821c_2ant)); break; #endif #ifdef CONFIG_RTL8723D case BTC_CHIP_RTL8723D: _rtw_memset(&pBtCoexist->coex_dm_8723d_1ant, 0x00, sizeof(pBtCoexist->coex_dm_8723d_1ant)); _rtw_memset(&pBtCoexist->coex_dm_8723d_2ant, 0x00, sizeof(pBtCoexist->coex_dm_8723d_2ant)); _rtw_memset(&pBtCoexist->coex_sta_8723d_1ant, 0x00, sizeof(pBtCoexist->coex_sta_8723d_1ant)); _rtw_memset(&pBtCoexist->coex_sta_8723d_2ant, 0x00, sizeof(pBtCoexist->coex_sta_8723d_2ant)); break; #endif } break; /* ===================== */ default: ret = _FALSE; break; } return result; } u8 halbtcoutsrc_UnderIps(PBTC_COEXIST pBtCoexist) { PADAPTER padapter; struct pwrctrl_priv *pwrpriv; u8 bMacPwrCtrlOn; padapter = pBtCoexist->Adapter; pwrpriv = &padapter->dvobj->pwrctl_priv; bMacPwrCtrlOn = _FALSE; if ((_TRUE == pwrpriv->bips_processing) && (IPS_NONE != pwrpriv->ips_mode_req) ) return _TRUE; if (rf_off == pwrpriv->rf_pwrstate) return _TRUE; rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn); if (_FALSE == bMacPwrCtrlOn) return _TRUE; return _FALSE; } u8 halbtcoutsrc_UnderLps(PBTC_COEXIST pBtCoexist) { return GLBtcWiFiInLPS; } u8 halbtcoutsrc_Under32K(PBTC_COEXIST pBtCoexist) { /* todo: the method to check whether wifi is under 32K or not */ return _FALSE; } void halbtcoutsrc_DisplayCoexStatistics(PBTC_COEXIST pBtCoexist) { #if 0 PADAPTER padapter = (PADAPTER)pBtCoexist->Adapter; PBT_MGNT pBtMgnt = &padapter->MgntInfo.BtInfo.BtMgnt; PHAL_DATA_TYPE pHalData = GET_HAL_DATA(padapter); u8 *cliBuf = pBtCoexist->cliBuf; u8 i, j; u8 tmpbuf[BTC_TMP_BUF_SHORT]; if (gl_coex_offload.cnt_h2c_sent) { CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Coex h2c notify]============"); CL_PRINTF(cliBuf); CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = H2c(%d)/Ack(%d)", "Coex h2c/c2h overall statistics", gl_coex_offload.cnt_h2c_sent, gl_coex_offload.cnt_c2h_ack); for (j = 0; j < COL_STATUS_MAX; j++) { if (gl_coex_offload.status[j]) { CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, ", %s:%d", coexH2cResultString[j], gl_coex_offload.status[j]); CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, BTC_TMP_BUF_SHORT); } } CL_PRINTF(cliBuf); } for (i = 0; i < COL_OP_WIFI_OPCODE_MAX; i++) { if (gl_coex_offload.h2c_record[i].count) { /*==========================================*/ /* H2C result statistics*/ /*==========================================*/ CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = total:%d", coexOpcodeString[i], gl_coex_offload.h2c_record[i].count); for (j = 0; j < COL_STATUS_MAX; j++) { if (gl_coex_offload.h2c_record[i].status[j]) { CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, ", %s:%d", coexH2cResultString[j], gl_coex_offload.h2c_record[i].status[j]); CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, BTC_TMP_BUF_SHORT); } } CL_PRINTF(cliBuf); /*==========================================*/ /* H2C/C2H content*/ /*==========================================*/ CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = ", "H2C / C2H content"); for (j = 0; j < gl_coex_offload.h2c_record[i].h2c_len; j++) { CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, "%02x ", gl_coex_offload.h2c_record[i].h2c_buf[j]); CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, 3); } if (gl_coex_offload.h2c_record[i].c2h_ack_len) { CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, "/ ", 2); for (j = 0; j < gl_coex_offload.h2c_record[i].c2h_ack_len; j++) { CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, "%02x ", gl_coex_offload.h2c_record[i].c2h_ack_buf[j]); CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, 3); } } CL_PRINTF(cliBuf); /*==========================================*/ } } if (gl_coex_offload.cnt_c2h_ind) { CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Coex c2h indication]============"); CL_PRINTF(cliBuf); CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = Ind(%d)", "C2H indication statistics", gl_coex_offload.cnt_c2h_ind); for (j = 0; j < COL_STATUS_MAX; j++) { if (gl_coex_offload.c2h_ind_status[j]) { CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, ", %s:%d", coexH2cResultString[j], gl_coex_offload.c2h_ind_status[j]); CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, BTC_TMP_BUF_SHORT); } } CL_PRINTF(cliBuf); } for (i = 0; i < COL_IND_MAX; i++) { if (gl_coex_offload.c2h_ind_record[i].count) { /*==========================================*/ /* H2C result statistics*/ /*==========================================*/ CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = total:%d", coexIndTypeString[i], gl_coex_offload.c2h_ind_record[i].count); for (j = 0; j < COL_STATUS_MAX; j++) { if (gl_coex_offload.c2h_ind_record[i].status[j]) { CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, ", %s:%d", coexH2cResultString[j], gl_coex_offload.c2h_ind_record[i].status[j]); CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, BTC_TMP_BUF_SHORT); } } CL_PRINTF(cliBuf); /*==========================================*/ /* content*/ /*==========================================*/ CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = ", "C2H indication content"); for (j = 0; j < gl_coex_offload.c2h_ind_record[i].ind_len; j++) { CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, "%02x ", gl_coex_offload.c2h_ind_record[i].ind_buf[j]); CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, 3); } CL_PRINTF(cliBuf); /*==========================================*/ } } CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Statistics]============"); CL_PRINTF(cliBuf); #if (H2C_USE_IO_THREAD != 1) for (i = 0; i < H2C_STATUS_MAX; i++) { if (pHalData->h2cStatistics[i]) { CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s] = %d", "H2C statistics", \ h2cStaString[i], pHalData->h2cStatistics[i]); CL_PRINTF(cliBuf); } } #else for (i = 0; i < IO_STATUS_MAX; i++) { if (Adapter->ioComStr.ioH2cStatistics[i]) { CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s] = %d", "H2C statistics", \ ioStaString[i], Adapter->ioComStr.ioH2cStatistics[i]); CL_PRINTF(cliBuf); } } #endif #if 0 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "lastHMEBoxNum", \ pHalData->LastHMEBoxNum); CL_PRINTF(cliBuf); CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x / 0x%x", "LastOkH2c/FirstFailH2c(fwNotRead)", \ pHalData->lastSuccessH2cEid, pHalData->firstFailedH2cEid); CL_PRINTF(cliBuf); CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", "c2hIsr/c2hIntr/clr1AF/noRdy/noBuf", \ pHalData->InterruptLog.nIMR_C2HCMD, DBG_Var.c2hInterruptCnt, DBG_Var.c2hClrReadC2hCnt, DBG_Var.c2hNotReadyCnt, DBG_Var.c2hBufAlloFailCnt); CL_PRINTF(cliBuf); CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "c2hPacket", \ DBG_Var.c2hPacketCnt); CL_PRINTF(cliBuf); #endif CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "Periodical/ DbgCtrl", \ pBtCoexist->statistics.cntPeriodical, pBtCoexist->statistics.cntDbgCtrl); CL_PRINTF(cliBuf); CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", "PowerOn/InitHw/InitCoexDm/RfStatus", \ pBtCoexist->statistics.cntPowerOn, pBtCoexist->statistics.cntInitHwConfig, pBtCoexist->statistics.cntInitCoexDm, pBtCoexist->statistics.cntRfStatusNotify); CL_PRINTF(cliBuf); CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", "Ips/Lps/Scan/Connect/Mstatus", \ pBtCoexist->statistics.cntIpsNotify, pBtCoexist->statistics.cntLpsNotify, pBtCoexist->statistics.cntScanNotify, pBtCoexist->statistics.cntConnectNotify, pBtCoexist->statistics.cntMediaStatusNotify); CL_PRINTF(cliBuf); CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d", "Special pkt/Bt info/ bind", pBtCoexist->statistics.cntSpecialPacketNotify, pBtCoexist->statistics.cntBtInfoNotify, pBtCoexist->statistics.cntBind); CL_PRINTF(cliBuf); #endif PADAPTER padapter = pBtCoexist->Adapter; PHAL_DATA_TYPE pHalData = GET_HAL_DATA(padapter); u8 *cliBuf = pBtCoexist->cli_buf; if (pHalData->EEPROMBluetoothCoexist == 1) { CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Coex Status]============"); CL_PRINTF(cliBuf); CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "IsBtDisabled", rtw_btcoex_IsBtDisabled(padapter)); CL_PRINTF(cliBuf); CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "IsBtControlLps", rtw_btcoex_IsBtControlLps(padapter)); CL_PRINTF(cliBuf); } } void halbtcoutsrc_DisplayBtLinkInfo(PBTC_COEXIST pBtCoexist) { #if 0 PADAPTER padapter = (PADAPTER)pBtCoexist->Adapter; PBT_MGNT pBtMgnt = &padapter->MgntInfo.BtInfo.BtMgnt; u8 *cliBuf = pBtCoexist->cliBuf; u8 i; if (pBtCoexist->stack_info.profile_notified) { for (i = 0; i < pBtMgnt->ExtConfig.NumberOfACL; i++) { if (pBtMgnt->ExtConfig.HCIExtensionVer >= 1) { CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s", "Bt link type/spec/role", \ BtProfileString[pBtMgnt->ExtConfig.aclLink[i].BTProfile], BtSpecString[pBtMgnt->ExtConfig.aclLink[i].BTCoreSpec], BtLinkRoleString[pBtMgnt->ExtConfig.aclLink[i].linkRole]); CL_PRINTF(cliBuf); } else { CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s", "Bt link type/spec", \ BtProfileString[pBtMgnt->ExtConfig.aclLink[i].BTProfile], BtSpecString[pBtMgnt->ExtConfig.aclLink[i].BTCoreSpec]); CL_PRINTF(cliBuf); } } } #endif } void halbtcoutsrc_DisplayWifiStatus(PBTC_COEXIST pBtCoexist) { PADAPTER padapter = pBtCoexist->Adapter; struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter); u8 *cliBuf = pBtCoexist->cli_buf; s32 wifiRssi = 0, btHsRssi = 0; BOOLEAN bScan = _FALSE, bLink = _FALSE, bRoam = _FALSE, bWifiBusy = _FALSE, bWifiUnderBMode = _FALSE; u32 wifiBw = BTC_WIFI_BW_HT20, wifiTrafficDir = BTC_WIFI_TRAFFIC_TX, wifiFreq = BTC_FREQ_2_4G; u32 wifiLinkStatus = 0x0; BOOLEAN bBtHsOn = _FALSE, bLowPower = _FALSE; u8 wifiChnl = 0, wifiP2PChnl = 0, nScanAPNum = 0, FwPSState; u32 iqk_cnt_total = 0, iqk_cnt_ok = 0, iqk_cnt_fail = 0; u16 wifiBcnInterval = 0; PHAL_DATA_TYPE hal = GET_HAL_DATA(padapter); struct btc_wifi_link_info wifi_link_info; wifi_link_info = halbtcoutsrc_getwifilinkinfo(pBtCoexist); switch (wifi_link_info.link_mode) { case BTC_LINK_NONE: CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin", "None", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go); wifiFreq = hal->current_channel > 14 ? BTC_FREQ_5G : BTC_FREQ_2_4G; break; case BTC_LINK_ONLY_GO: CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin", "ONLY_GO", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go); wifiFreq = hal->current_channel > 14 ? BTC_FREQ_5G : BTC_FREQ_2_4G; break; case BTC_LINK_ONLY_GC: CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin", "ONLY_GC", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go); wifiFreq = hal->current_channel > 14 ? BTC_FREQ_5G : BTC_FREQ_2_4G; break; case BTC_LINK_ONLY_STA: CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin", "ONLY_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go); wifiFreq = hal->current_channel > 14 ? BTC_FREQ_5G : BTC_FREQ_2_4G; break; case BTC_LINK_ONLY_AP: CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin", "ONLY_AP", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go); wifiFreq = hal->current_channel > 14 ? BTC_FREQ_5G : BTC_FREQ_2_4G; break; case BTC_LINK_2G_MCC_GO_STA: CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin", "24G_MCC_GO_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go); wifiFreq = BTC_FREQ_2_4G; break; case BTC_LINK_5G_MCC_GO_STA: CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin", "5G_MCC_GO_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go); wifiFreq = BTC_FREQ_5G; break; case BTC_LINK_25G_MCC_GO_STA: CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin", "2BANDS_MCC_GO_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go); wifiFreq = BTC_FREQ_25G; break; case BTC_LINK_2G_MCC_GC_STA: CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin", "24G_MCC_GC_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go); wifiFreq = BTC_FREQ_2_4G; break; case BTC_LINK_5G_MCC_GC_STA: CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin", "5G_MCC_GC_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go); wifiFreq = BTC_FREQ_5G; break; case BTC_LINK_25G_MCC_GC_STA: CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin", "2BANDS_MCC_GC_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go); wifiFreq = BTC_FREQ_25G; break; case BTC_LINK_2G_SCC_GO_STA: CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin", "24G_SCC_GO_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go); wifiFreq = BTC_FREQ_2_4G; break; case BTC_LINK_5G_SCC_GO_STA: CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin", "5G_SCC_GO_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go); wifiFreq = BTC_FREQ_5G; break; case BTC_LINK_2G_SCC_GC_STA: CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin", "24G_SCC_GC_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go); wifiFreq = BTC_FREQ_2_4G; break; case BTC_LINK_5G_SCC_GC_STA: CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin", "5G_SCC_GC_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go); wifiFreq = BTC_FREQ_5G; break; default: CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin", "UNKNOWN", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go); wifiFreq = hal->current_channel > 14 ? BTC_FREQ_5G : BTC_FREQ_2_4G; break; } CL_PRINTF(cliBuf); wifiLinkStatus = halbtcoutsrc_GetWifiLinkStatus(pBtCoexist); CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", "STA/vWifi/HS/p2pGo/p2pGc", ((wifiLinkStatus & WIFI_STA_CONNECTED) ? 1 : 0), ((wifiLinkStatus & WIFI_AP_CONNECTED) ? 1 : 0), ((wifiLinkStatus & WIFI_HS_CONNECTED) ? 1 : 0), ((wifiLinkStatus & WIFI_P2P_GO_CONNECTED) ? 1 : 0), ((wifiLinkStatus & WIFI_P2P_GC_CONNECTED) ? 1 : 0)); CL_PRINTF(cliBuf); pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan); pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink); pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam); CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d ", "Link/ Roam/ Scan", bLink, bRoam, bScan); CL_PRINTF(cliBuf); pBtCoexist->btc_get(pBtCoexist, BTC_GET_U4_WIFI_IQK_TOTAL, &iqk_cnt_total); pBtCoexist->btc_get(pBtCoexist, BTC_GET_U4_WIFI_IQK_OK, &iqk_cnt_ok); pBtCoexist->btc_get(pBtCoexist, BTC_GET_U4_WIFI_IQK_FAIL, &iqk_cnt_fail); CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d %s %s", "IQK All/ OK/ Fail/AutoLoad/FWDL", iqk_cnt_total, iqk_cnt_ok, iqk_cnt_fail, ((halbtcoutsrc_is_autoload_fail(pBtCoexist) == _TRUE) ? "fail":"ok"), ((halbtcoutsrc_is_fw_ready(pBtCoexist) == _TRUE) ? "ok":"fail")); CL_PRINTF(cliBuf); if (wifiLinkStatus & WIFI_STA_CONNECTED) { CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "IOT Peer", GLBtcIotPeerString[padapter->mlmeextpriv.mlmext_info.assoc_AP_vendor]); CL_PRINTF(cliBuf); } pBtCoexist->btc_get(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi); pBtCoexist->btc_get(pBtCoexist, BTC_GET_U2_BEACON_PERIOD, &wifiBcnInterval); wifiChnl = wifi_link_info.sta_center_channel; wifiP2PChnl = wifi_link_info.p2p_center_channel; CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d dBm/ %d/ %d/ %d", "RSSI/ STA_Chnl/ P2P_Chnl/ BI", wifiRssi-100, wifiChnl, wifiP2PChnl, wifiBcnInterval); CL_PRINTF(cliBuf); pBtCoexist->btc_get(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw); pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy); pBtCoexist->btc_get(pBtCoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &wifiTrafficDir); pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode); pBtCoexist->btc_get(pBtCoexist, BTC_GET_U1_AP_NUM, &nScanAPNum); CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %s/ %s/ %d ", "Band/ BW/ Traffic/ APCnt", GLBtcWifiFreqString[wifiFreq], ((bWifiUnderBMode) ? "11b" : GLBtcWifiBwString[wifiBw]), ((!bWifiBusy) ? "idle" : ((BTC_WIFI_TRAFFIC_TX == wifiTrafficDir) ? "uplink" : "downlink")), nScanAPNum); CL_PRINTF(cliBuf); /* power status */ CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s%s%s", "Power Status", \ ((halbtcoutsrc_UnderIps(pBtCoexist) == _TRUE) ? "IPS ON" : "IPS OFF"), ((halbtcoutsrc_UnderLps(pBtCoexist) == _TRUE) ? ", LPS ON" : ", LPS OFF"), ((halbtcoutsrc_Under32K(pBtCoexist) == _TRUE) ? ", 32k" : "")); CL_PRINTF(cliBuf); CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x %02x (0x%x/0x%x)", "Power mode cmd(lps/rpwm)", pBtCoexist->pwrModeVal[0], pBtCoexist->pwrModeVal[1], pBtCoexist->pwrModeVal[2], pBtCoexist->pwrModeVal[3], pBtCoexist->pwrModeVal[4], pBtCoexist->pwrModeVal[5], pBtCoexist->bt_info.lps_val, pBtCoexist->bt_info.rpwm_val); CL_PRINTF(cliBuf); } void halbtcoutsrc_DisplayDbgMsg(void *pBtcContext, u8 dispType) { PBTC_COEXIST pBtCoexist; pBtCoexist = (PBTC_COEXIST)pBtcContext; switch (dispType) { case BTC_DBG_DISP_COEX_STATISTICS: halbtcoutsrc_DisplayCoexStatistics(pBtCoexist); break; case BTC_DBG_DISP_BT_LINK_INFO: halbtcoutsrc_DisplayBtLinkInfo(pBtCoexist); break; case BTC_DBG_DISP_WIFI_STATUS: halbtcoutsrc_DisplayWifiStatus(pBtCoexist); break; default: break; } } /* ************************************ * IO related function * ************************************ */ u8 halbtcoutsrc_Read1Byte(void *pBtcContext, u32 RegAddr) { PBTC_COEXIST pBtCoexist; PADAPTER padapter; pBtCoexist = (PBTC_COEXIST)pBtcContext; padapter = pBtCoexist->Adapter; return rtw_read8(padapter, RegAddr); } u16 halbtcoutsrc_Read2Byte(void *pBtcContext, u32 RegAddr) { PBTC_COEXIST pBtCoexist; PADAPTER padapter; pBtCoexist = (PBTC_COEXIST)pBtcContext; padapter = pBtCoexist->Adapter; return rtw_read16(padapter, RegAddr); } u32 halbtcoutsrc_Read4Byte(void *pBtcContext, u32 RegAddr) { PBTC_COEXIST pBtCoexist; PADAPTER padapter; pBtCoexist = (PBTC_COEXIST)pBtcContext; padapter = pBtCoexist->Adapter; return rtw_read32(padapter, RegAddr); } void halbtcoutsrc_Write1Byte(void *pBtcContext, u32 RegAddr, u8 Data) { PBTC_COEXIST pBtCoexist; PADAPTER padapter; pBtCoexist = (PBTC_COEXIST)pBtcContext; padapter = pBtCoexist->Adapter; rtw_write8(padapter, RegAddr, Data); } void halbtcoutsrc_BitMaskWrite1Byte(void *pBtcContext, u32 regAddr, u8 bitMask, u8 data1b) { PBTC_COEXIST pBtCoexist; PADAPTER padapter; u8 originalValue, bitShift; u8 i; pBtCoexist = (PBTC_COEXIST)pBtcContext; padapter = pBtCoexist->Adapter; originalValue = 0; bitShift = 0; if (bitMask != 0xff) { originalValue = rtw_read8(padapter, regAddr); for (i = 0; i <= 7; i++) { if ((bitMask >> i) & 0x1) break; } bitShift = i; data1b = (originalValue & ~bitMask) | ((data1b << bitShift) & bitMask); } rtw_write8(padapter, regAddr, data1b); } void halbtcoutsrc_Write2Byte(void *pBtcContext, u32 RegAddr, u16 Data) { PBTC_COEXIST pBtCoexist; PADAPTER padapter; pBtCoexist = (PBTC_COEXIST)pBtcContext; padapter = pBtCoexist->Adapter; rtw_write16(padapter, RegAddr, Data); } void halbtcoutsrc_Write4Byte(void *pBtcContext, u32 RegAddr, u32 Data) { PBTC_COEXIST pBtCoexist; PADAPTER padapter; pBtCoexist = (PBTC_COEXIST)pBtcContext; padapter = pBtCoexist->Adapter; rtw_write32(padapter, RegAddr, Data); } void halbtcoutsrc_WriteLocalReg1Byte(void *pBtcContext, u32 RegAddr, u8 Data) { PBTC_COEXIST pBtCoexist = (PBTC_COEXIST)pBtcContext; PADAPTER Adapter = pBtCoexist->Adapter; if (BTC_INTF_SDIO == pBtCoexist->chip_interface) rtw_write8(Adapter, SDIO_LOCAL_BASE | RegAddr, Data); else rtw_write8(Adapter, RegAddr, Data); } u32 halbtcoutsrc_WaitLIndirectReg_Ready(void *pBtcContext) { PBTC_COEXIST btc = (PBTC_COEXIST)pBtcContext; u32 delay_count = 0, reg = 0; if (!btc->chip_para->lte_indirect_access) return 0; switch (btc->chip_para->indirect_type) { case BTC_INDIRECT_1700: reg = 0x1703; break; case BTC_INDIRECT_7C0: reg = 0x7C3; break; default: return 0; } /* wait for ready bit before access */ while (1) { if ((halbtcoutsrc_Read1Byte(btc, reg) & BIT(5)) == 0) { rtw_mdelay_os(10); if (++delay_count >= 10) break; } else { break; } } return delay_count; } u32 halbtcoutsrc_ReadLIndirectReg(void *pBtcContext, u16 reg_addr) { PBTC_COEXIST btc = (PBTC_COEXIST)pBtcContext; u32 val = 0; if (!btc->chip_para->lte_indirect_access) return 0; /* wait for ready bit before access */ halbtcoutsrc_WaitLIndirectReg_Ready(btc); switch (btc->chip_para->indirect_type) { case BTC_INDIRECT_1700: halbtcoutsrc_Write4Byte(btc, 0x1700, 0x800F0000 | reg_addr); val = halbtcoutsrc_Read4Byte(btc, 0x1708); /* get read data */ break; case BTC_INDIRECT_7C0: halbtcoutsrc_Write4Byte(btc, 0x7c0, 0x800F0000 | reg_addr); val = halbtcoutsrc_Read4Byte(btc, 0x7c8); /* get read data */ break; } return val; } void halbtcoutsrc_WriteLIndirectReg(void *pBtcContext, u16 reg_addr, u32 bit_mask, u32 reg_value) { PBTC_COEXIST btc = (PBTC_COEXIST)pBtcContext; u32 val, i = 0, bitpos = 0, reg0, reg1; if (!btc->chip_para->lte_indirect_access) return; if (bit_mask == 0x0) return; switch (btc->chip_para->indirect_type) { case BTC_INDIRECT_1700: reg0 = 0x1700; reg1 = 0x1704; break; case BTC_INDIRECT_7C0: reg0 = 0x7C0; reg1 = 0x7C4; break; default: return; } if (bit_mask == 0xffffffff) { /* wait for ready bit before access 0x1700 */ halbtcoutsrc_WaitLIndirectReg_Ready(btc); /* put write data */ halbtcoutsrc_Write4Byte(btc, reg1, reg_value); halbtcoutsrc_Write4Byte(btc, reg0, 0xc00F0000 | reg_addr); } else { for (i = 0; i <= 31; i++) { if (((bit_mask >> i) & 0x1) == 0x1) { bitpos = i; break; } } /* read back register value before write */ val = halbtcoutsrc_ReadLIndirectReg(btc, reg_addr); val = (val & (~bit_mask)) | (reg_value << bitpos); /* wait for ready bit before access 0x1700 */ halbtcoutsrc_WaitLIndirectReg_Ready(btc); halbtcoutsrc_Write4Byte(btc, reg1, val); /* put write data */ halbtcoutsrc_Write4Byte(btc, reg0, 0xc00F0000 | reg_addr); } } void halbtcoutsrc_Read_scbd(void *pBtcContext, u16* score_board_val) { PBTC_COEXIST btc = (PBTC_COEXIST)pBtcContext; struct btc_coex_sta *coex_sta = &btc->coex_sta; const struct btc_chip_para *chip_para = btc->chip_para; if (!chip_para->scbd_support) return; *score_board_val = (btc->btc_read_2byte(btc, 0xaa)) & 0x7fff; coex_sta->score_board_BW = *score_board_val; } void halbtcoutsrc_Write_scbd(void *pBtcContext, u16 bitpos, u8 state) { PBTC_COEXIST btc = (PBTC_COEXIST)pBtcContext; struct btc_coex_sta *coex_sta = &btc->coex_sta; const struct btc_chip_para *chip_para = btc->chip_para; u16 val = 0x2; u8* btc_dbg_buf = &gl_btc_trace_buf[0]; if (!chip_para->scbd_support) return; val = val | coex_sta->score_board_WB; /* for 8822b, Scoreboard[10]: 0: CQDDR off, 1: CQDDR on * for 8822c, Scoreboard[10]: 0: CQDDR on, 1:CQDDR fix 2M */ if (!btc->chip_para->new_scbd10_def && (bitpos & BTC_SCBD_FIX2M)) { if (state) val = val & (~BTC_SCBD_FIX2M); else val = val | BTC_SCBD_FIX2M; } else { if (state) val = val | bitpos; else val = val & (~bitpos); } if (val != coex_sta->score_board_WB) { coex_sta->score_board_WB = val; val = val | 0x8000; btc->btc_write_2byte(btc, 0xaa, val); BTC_SPRINTF(btc_dbg_buf, BT_TMP_BUF_SIZE, "[BTCoex], write scoreboard 0x%x\n", val); } else { BTC_SPRINTF(btc_dbg_buf, BT_TMP_BUF_SIZE, "[BTCoex], %s: return for nochange\n", __func__); } BTC_TRACE(btc_dbg_buf); } void halbtcoutsrc_SetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask, u32 Data) { PBTC_COEXIST pBtCoexist; PADAPTER padapter; pBtCoexist = (PBTC_COEXIST)pBtcContext; padapter = pBtCoexist->Adapter; phy_set_bb_reg(padapter, RegAddr, BitMask, Data); } u32 halbtcoutsrc_GetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask) { PBTC_COEXIST pBtCoexist; PADAPTER padapter; pBtCoexist = (PBTC_COEXIST)pBtcContext; padapter = pBtCoexist->Adapter; return phy_query_bb_reg(padapter, RegAddr, BitMask); } void halbtcoutsrc_SetRfReg(void *pBtcContext, enum rf_path eRFPath, u32 RegAddr, u32 BitMask, u32 Data) { PBTC_COEXIST pBtCoexist; PADAPTER padapter; pBtCoexist = (PBTC_COEXIST)pBtcContext; padapter = pBtCoexist->Adapter; phy_set_rf_reg(padapter, eRFPath, RegAddr, BitMask, Data); } u32 halbtcoutsrc_GetRfReg(void *pBtcContext, enum rf_path eRFPath, u32 RegAddr, u32 BitMask) { PBTC_COEXIST pBtCoexist; PADAPTER padapter; pBtCoexist = (PBTC_COEXIST)pBtcContext; padapter = pBtCoexist->Adapter; return phy_query_rf_reg(padapter, eRFPath, RegAddr, BitMask); } u16 halbtcoutsrc_SetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr, u32 Data) { PBTC_COEXIST pBtCoexist; u16 ret = BT_STATUS_BT_OP_SUCCESS; pBtCoexist = (PBTC_COEXIST)pBtcContext; if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) { u8 buf[3] = {0}; _irqL irqL; u8 op_code; u8 status; _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL); Data = cpu_to_le32(Data); op_code = BT_OP_WRITE_REG_VALUE; status = _btmpoper_cmd(pBtCoexist, op_code, 0, (u8 *)&Data, 3); if (status != BT_STATUS_BT_OP_SUCCESS) ret = SET_BT_MP_OPER_RET(op_code, status); else { buf[0] = RegType; *(u16 *)(buf + 1) = cpu_to_le16((u16)RegAddr); op_code = BT_OP_WRITE_REG_ADDR; status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 3); if (status != BT_STATUS_BT_OP_SUCCESS) ret = SET_BT_MP_OPER_RET(op_code, status); } _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL); } else ret = BT_STATUS_NOT_IMPLEMENT; return ret; } u8 halbtcoutsrc_SetBtAntDetection(void *pBtcContext, u8 txTime, u8 btChnl) { /* Always return _FALSE since we don't implement this yet */ #if 0 PBTC_COEXIST pBtCoexist = (PBTC_COEXIST)pBtcContext; PADAPTER Adapter = pBtCoexist->Adapter; u8 btCanTx = 0; BOOLEAN bStatus = FALSE; bStatus = NDBG_SetBtAntDetection(Adapter, txTime, btChnl, &btCanTx); if (bStatus && btCanTx) return _TRUE; else return _FALSE; #else return _FALSE; #endif } BOOLEAN halbtcoutsrc_SetBtTRXMASK( void *pBtcContext, u8 bt_trx_mask ) { /* Always return _FALSE since we don't implement this yet */ #if 0 struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext; PADAPTER Adapter = pBtCoexist->Adapter; BOOLEAN bStatus = FALSE; u8 btCanTx = 0; if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter) || IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter) || IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) { if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) bStatus = NDBG_SetBtTRXMASK(Adapter, 1, bt_trx_mask, &btCanTx); else bStatus = NDBG_SetBtTRXMASK(Adapter, 2, bt_trx_mask, &btCanTx); } if (bStatus) return TRUE; else return FALSE; #else return _FALSE; #endif } u16 halbtcoutsrc_GetBtReg_with_status(void *pBtcContext, u8 RegType, u32 RegAddr, u32 *data) { PBTC_COEXIST pBtCoexist; u16 ret = BT_STATUS_BT_OP_SUCCESS; pBtCoexist = (PBTC_COEXIST)pBtcContext; if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) { u8 buf[3] = {0}; _irqL irqL; u8 op_code; u8 status; buf[0] = RegType; *(u16 *)(buf + 1) = cpu_to_le16((u16)RegAddr); _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL); op_code = BT_OP_READ_REG; status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 3); if (status == BT_STATUS_BT_OP_SUCCESS) *data = le16_to_cpu(*(u16 *)GLBtcBtMpRptRsp); else ret = SET_BT_MP_OPER_RET(op_code, status); _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL); } else ret = BT_STATUS_NOT_IMPLEMENT; return ret; } u32 halbtcoutsrc_GetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr) { u32 regVal; return (BT_STATUS_BT_OP_SUCCESS == halbtcoutsrc_GetBtReg_with_status(pBtcContext, RegType, RegAddr, &regVal)) ? regVal : 0xffffffff; } u16 halbtcoutsrc_setbttestmode(void *pBtcContext, u8 Type) { PBTC_COEXIST pBtCoexist; u16 ret = BT_STATUS_BT_OP_SUCCESS; pBtCoexist = (PBTC_COEXIST)pBtcContext; if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) { _irqL irqL; u8 op_code; u8 status; _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL); Type = cpu_to_le32(Type); op_code = BT_OP_SET_BT_TEST_MODE_VAL; status = _btmpoper_cmd(pBtCoexist, op_code, 0, (u8 *)&Type, 3); if (status != BT_STATUS_BT_OP_SUCCESS) ret = SET_BT_MP_OPER_RET(op_code, status); _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL); } else ret = BT_STATUS_NOT_IMPLEMENT; return ret; } void halbtcoutsrc_FillH2cCmd(void *pBtcContext, u8 elementId, u32 cmdLen, u8 *pCmdBuffer) { PBTC_COEXIST pBtCoexist; PADAPTER padapter; s32 ret = 0; pBtCoexist = (PBTC_COEXIST)pBtcContext; padapter = pBtCoexist->Adapter; ret = rtw_hal_fill_h2c_cmd(padapter, elementId, cmdLen, pCmdBuffer); #ifdef CONFIG_RTL8192F if (ret == _SUCCESS) { switch (elementId) { case H2C_BT_INFO: case H2C_BT_IGNORE_WLANACT: case H2C_WL_OPMODE: case H2C_BT_MP_OPER: case H2C_BT_CONTROL: rtw_msleep_os(20); break; } } #endif } static void halbtcoutsrc_coex_offload_init(void) { u8 i; gl_coex_offload.h2c_req_num = 0; gl_coex_offload.cnt_h2c_sent = 0; gl_coex_offload.cnt_c2h_ack = 0; gl_coex_offload.cnt_c2h_ind = 0; for (i = 0; i < COL_MAX_H2C_REQ_NUM; i++) init_completion(&gl_coex_offload.c2h_event[i]); } static COL_H2C_STATUS halbtcoutsrc_send_h2c(PADAPTER Adapter, PCOL_H2C pcol_h2c, u16 h2c_cmd_len) { COL_H2C_STATUS h2c_status = COL_STATUS_C2H_OK; u8 i; #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0)) reinit_completion(&gl_coex_offload.c2h_event[pcol_h2c->req_num]); /* set event to un signaled state */ #else INIT_COMPLETION(gl_coex_offload.c2h_event[pcol_h2c->req_num]); #endif if (TRUE) { #if 0 /*(USE_HAL_MAC_API == 1) */ if (RT_STATUS_SUCCESS == HAL_MAC_Send_BT_COEX(&GET_HAL_MAC_INFO(Adapter), (u8 *)(pcol_h2c), (u32)h2c_cmd_len, 1)) { if (!wait_for_completion_timeout(&gl_coex_offload.c2h_event[pcol_h2c->req_num], 20)) { h2c_status = COL_STATUS_H2C_TIMTOUT; } } else { h2c_status = COL_STATUS_H2C_HALMAC_FAIL; } #endif } return h2c_status; } static COL_H2C_STATUS halbtcoutsrc_check_c2h_ack(PADAPTER Adapter, PCOL_SINGLE_H2C_RECORD pH2cRecord) { COL_H2C_STATUS c2h_status = COL_STATUS_C2H_OK; PCOL_H2C p_h2c_cmd = (PCOL_H2C)&pH2cRecord->h2c_buf[0]; u8 req_num = p_h2c_cmd->req_num; PCOL_C2H_ACK p_c2h_ack = (PCOL_C2H_ACK)&gl_coex_offload.c2h_ack_buf[req_num]; if ((COL_C2H_ACK_HDR_LEN + p_c2h_ack->ret_len) > gl_coex_offload.c2h_ack_len[req_num]) { c2h_status = COL_STATUS_COEX_DATA_OVERFLOW; return c2h_status; } /* else */ { _rtw_memmove(&pH2cRecord->c2h_ack_buf[0], &gl_coex_offload.c2h_ack_buf[req_num], gl_coex_offload.c2h_ack_len[req_num]); pH2cRecord->c2h_ack_len = gl_coex_offload.c2h_ack_len[req_num]; } if (p_c2h_ack->req_num != p_h2c_cmd->req_num) { c2h_status = COL_STATUS_C2H_REQ_NUM_MISMATCH; } else if (p_c2h_ack->opcode_ver != p_h2c_cmd->opcode_ver) { c2h_status = COL_STATUS_C2H_OPCODE_VER_MISMATCH; } else { c2h_status = p_c2h_ack->status; } return c2h_status; } COL_H2C_STATUS halbtcoutsrc_CoexH2cProcess(void *pBtCoexist, u8 opcode, u8 opcode_ver, u8 *ph2c_par, u8 h2c_par_len) { PADAPTER Adapter = ((struct btc_coexist *)pBtCoexist)->Adapter; u8 H2C_Parameter[BTC_TMP_BUF_SHORT] = {0}; PCOL_H2C pcol_h2c = (PCOL_H2C)&H2C_Parameter[0]; u16 paraLen = 0; COL_H2C_STATUS h2c_status = COL_STATUS_C2H_OK, c2h_status = COL_STATUS_C2H_OK; COL_H2C_STATUS ret_status = COL_STATUS_C2H_OK; u16 i, col_h2c_len = 0; pcol_h2c->opcode = opcode; pcol_h2c->opcode_ver = opcode_ver; pcol_h2c->req_num = gl_coex_offload.h2c_req_num; gl_coex_offload.h2c_req_num++; gl_coex_offload.h2c_req_num %= 16; _rtw_memmove(&pcol_h2c->buf[0], ph2c_par, h2c_par_len); col_h2c_len = h2c_par_len + 2; /* 2=sizeof(OPCode, OPCode_version and Request number) */ BT_PrintData(Adapter, "[COL], H2C cmd: ", col_h2c_len, H2C_Parameter); gl_coex_offload.cnt_h2c_sent++; gl_coex_offload.h2c_record[opcode].count++; gl_coex_offload.h2c_record[opcode].h2c_len = col_h2c_len; _rtw_memmove((void *)&gl_coex_offload.h2c_record[opcode].h2c_buf[0], (void *)pcol_h2c, col_h2c_len); h2c_status = halbtcoutsrc_send_h2c(Adapter, pcol_h2c, col_h2c_len); gl_coex_offload.h2c_record[opcode].c2h_ack_len = 0; if (COL_STATUS_C2H_OK == h2c_status) { /* if reach here, it means H2C get the correct c2h response, */ c2h_status = halbtcoutsrc_check_c2h_ack(Adapter, &gl_coex_offload.h2c_record[opcode]); ret_status = c2h_status; } else { /* check h2c status error, return error status code to upper layer. */ ret_status = h2c_status; } gl_coex_offload.h2c_record[opcode].status[ret_status]++; gl_coex_offload.status[ret_status]++; return ret_status; } u8 halbtcoutsrc_GetAntDetValFromBt(void *pBtcContext) { /* Always return 0 since we don't implement this yet */ #if 0 struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext; PADAPTER Adapter = pBtCoexist->Adapter; u8 AntDetVal = 0x0; u8 opcodeVer = 1; BOOLEAN status = false; status = NDBG_GetAntDetValFromBt(Adapter, opcodeVer, &AntDetVal); RT_TRACE(COMP_DBG, DBG_LOUD, ("$$$ halbtcoutsrc_GetAntDetValFromBt(): status = %d, feature = %x\n", status, AntDetVal)); return AntDetVal; #else return 0; #endif } u8 halbtcoutsrc_GetBleScanTypeFromBt(void *pBtcContext) { PBTC_COEXIST pBtCoexist; u32 ret = BT_STATUS_BT_OP_SUCCESS; u8 data = 0; pBtCoexist = (PBTC_COEXIST)pBtcContext; if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) { u8 buf[3] = {0}; _irqL irqL; u8 op_code; u8 status; _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL); op_code = BT_OP_GET_BT_BLE_SCAN_TYPE; status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0); if (status == BT_STATUS_BT_OP_SUCCESS) data = *(u8 *)GLBtcBtMpRptRsp; else ret = SET_BT_MP_OPER_RET(op_code, status); _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL); } else ret = BT_STATUS_NOT_IMPLEMENT; return data; } u32 halbtcoutsrc_GetBleScanParaFromBt(void *pBtcContext, u8 scanType) { PBTC_COEXIST pBtCoexist; u32 ret = BT_STATUS_BT_OP_SUCCESS; u32 data = 0; pBtCoexist = (PBTC_COEXIST)pBtcContext; if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) { u8 buf[3] = {0}; _irqL irqL; u8 op_code; u8 status; buf[0] = scanType; _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL); op_code = BT_OP_GET_BT_BLE_SCAN_PARA; status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 1); if (status == BT_STATUS_BT_OP_SUCCESS) data = le32_to_cpu(*(u32 *)GLBtcBtMpRptRsp); else ret = SET_BT_MP_OPER_RET(op_code, status); _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL); } else ret = BT_STATUS_NOT_IMPLEMENT; return data; } u8 halbtcoutsrc_GetBtAFHMapFromBt(void *pBtcContext, u8 mapType, u8 *afhMap) { struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext; u8 buf[2] = {0}; _irqL irqL; u8 op_code; u32 *AfhMapL = (u32 *)&(afhMap[0]); u32 *AfhMapM = (u32 *)&(afhMap[4]); u16 *AfhMapH = (u16 *)&(afhMap[8]); u8 status; u32 ret = BT_STATUS_BT_OP_SUCCESS; if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _FALSE) return _FALSE; buf[0] = 0; buf[1] = mapType; _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL); op_code = BT_LO_OP_GET_AFH_MAP_L; status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0); if (status == BT_STATUS_BT_OP_SUCCESS) *AfhMapL = le32_to_cpu(*(u32 *)GLBtcBtMpRptRsp); else { ret = SET_BT_MP_OPER_RET(op_code, status); goto exit; } op_code = BT_LO_OP_GET_AFH_MAP_M; status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0); if (status == BT_STATUS_BT_OP_SUCCESS) *AfhMapM = le32_to_cpu(*(u32 *)GLBtcBtMpRptRsp); else { ret = SET_BT_MP_OPER_RET(op_code, status); goto exit; } op_code = BT_LO_OP_GET_AFH_MAP_H; status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0); if (status == BT_STATUS_BT_OP_SUCCESS) *AfhMapH = le16_to_cpu(*(u16 *)GLBtcBtMpRptRsp); else { ret = SET_BT_MP_OPER_RET(op_code, status); goto exit; } exit: _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL); return (ret == BT_STATUS_BT_OP_SUCCESS) ? _TRUE : _FALSE; } u8 halbtcoutsrc_SetTimer(void *pBtcContext, u32 type, u32 val) { struct btc_coexist *pBtCoexist=(struct btc_coexist *)pBtcContext; if (type >= BTC_TIMER_MAX) return _FALSE; pBtCoexist->coex_sta.cnt_timer[type] = val; RTW_DBG("[BTC], Set Timer: type = %d, val = %d\n", type, val); return _TRUE; } u32 halbtcoutsrc_SetAtomic (void *btc_ctx, u32 *target, u32 val) { *target = val; return _SUCCESS; } void halbtcoutsrc_phydm_modify_AntDiv_HwSw(void *pBtcContext, u8 is_hw) { /* empty function since we don't need it */ } void halbtcoutsrc_phydm_modify_RA_PCR_threshold(void *pBtcContext, u8 RA_offset_direction, u8 RA_threshold_offset) { struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext; /* switch to #if 0 in case the phydm version does not provide the function */ #if 1 phydm_modify_RA_PCR_threshold(pBtCoexist->odm_priv, RA_offset_direction, RA_threshold_offset); #endif } u32 halbtcoutsrc_phydm_query_PHY_counter(void *pBtcContext, u8 info_type) { struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext; /* switch to #if 0 in case the phydm version does not provide the function */ #if 1 return phydm_cmn_info_query((struct dm_struct *)pBtCoexist->odm_priv, (enum phydm_info_query)info_type); #else return 0; #endif } void halbtcoutsrc_reduce_wl_tx_power(void *pBtcContext, s8 tx_power) { struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext; HAL_DATA_TYPE *pHalData = GET_HAL_DATA((PADAPTER)pBtCoexist->Adapter); /* The reduction of wl tx pwr should be processed inside the set tx pwr lvl function */ if (IS_HARDWARE_TYPE_8822C(pBtCoexist->Adapter)) rtw_hal_set_tx_power_level(pBtCoexist->Adapter, pHalData->current_channel); } #if 0 static void BT_CoexOffloadRecordErrC2hAck(PADAPTER Adapter) { PADAPTER pDefaultAdapter = GetDefaultAdapter(Adapter); if (pDefaultAdapter != Adapter) return; if (!hal_btcoex_IsBtExist(Adapter)) return; gl_coex_offload.cnt_c2h_ack++; gl_coex_offload.status[COL_STATUS_INVALID_C2H_LEN]++; } static void BT_CoexOffloadC2hAckCheck(PADAPTER Adapter, u8 *tmpBuf, u8 length) { PADAPTER pDefaultAdapter = GetDefaultAdapter(Adapter); PCOL_C2H_ACK p_c2h_ack = NULL; u8 req_num = 0xff; if (pDefaultAdapter != Adapter) return; if (!hal_btcoex_IsBtExist(Adapter)) return; gl_coex_offload.cnt_c2h_ack++; if (length < COL_C2H_ACK_HDR_LEN) { /* c2h ack length must >= 3 (status, opcode_ver, req_num and ret_len) */ gl_coex_offload.status[COL_STATUS_INVALID_C2H_LEN]++; } else { BT_PrintData(Adapter, "[COL], c2h ack:", length, tmpBuf); p_c2h_ack = (PCOL_C2H_ACK)tmpBuf; req_num = p_c2h_ack->req_num; _rtw_memmove(&gl_coex_offload.c2h_ack_buf[req_num][0], tmpBuf, length); gl_coex_offload.c2h_ack_len[req_num] = length; complete(&gl_coex_offload.c2h_event[req_num]); } } static void BT_CoexOffloadC2hIndCheck(PADAPTER Adapter, u8 *tmpBuf, u8 length) { PADAPTER pDefaultAdapter = GetDefaultAdapter(Adapter); PCOL_C2H_IND p_c2h_ind = NULL; u8 ind_type = 0, ind_version = 0, ind_length = 0; if (pDefaultAdapter != Adapter) return; if (!hal_btcoex_IsBtExist(Adapter)) return; gl_coex_offload.cnt_c2h_ind++; if (length < COL_C2H_IND_HDR_LEN) { /* c2h indication length must >= 3 (type, version and length) */ gl_coex_offload.c2h_ind_status[COL_STATUS_INVALID_C2H_LEN]++; } else { BT_PrintData(Adapter, "[COL], c2h indication:", length, tmpBuf); p_c2h_ind = (PCOL_C2H_IND)tmpBuf; ind_type = p_c2h_ind->type; ind_version = p_c2h_ind->version; ind_length = p_c2h_ind->length; _rtw_memmove(&gl_coex_offload.c2h_ind_buf[0], tmpBuf, length); gl_coex_offload.c2h_ind_len = length; /* log */ gl_coex_offload.c2h_ind_record[ind_type].count++; gl_coex_offload.c2h_ind_record[ind_type].status[COL_STATUS_C2H_OK]++; _rtw_memmove(&gl_coex_offload.c2h_ind_record[ind_type].ind_buf[0], tmpBuf, length); gl_coex_offload.c2h_ind_record[ind_type].ind_len = length; gl_coex_offload.c2h_ind_status[COL_STATUS_C2H_OK]++; /*TODO: need to check c2h indication length*/ /* TODO: Notification */ } } void BT_CoexOffloadC2hCheck(PADAPTER Adapter, u8 *Buffer, u8 Length) { #if 0 /*(USE_HAL_MAC_API == 1)*/ u8 c2hSubCmdId = 0, c2hAckLen = 0, h2cCmdId = 0, h2cSubCmdId = 0, c2hIndLen = 0; BT_PrintData(Adapter, "[COL], c2h packet:", Length - 2, Buffer + 2); c2hSubCmdId = (u8)C2H_HDR_GET_C2H_SUB_CMD_ID(Buffer); if (c2hSubCmdId == C2H_SUB_CMD_ID_H2C_ACK_HDR || c2hSubCmdId == C2H_SUB_CMD_ID_BT_COEX_INFO) { if (c2hSubCmdId == C2H_SUB_CMD_ID_H2C_ACK_HDR) { /* coex c2h ack */ h2cCmdId = (u8)H2C_ACK_HDR_GET_H2C_CMD_ID(Buffer); h2cSubCmdId = (u8)H2C_ACK_HDR_GET_H2C_SUB_CMD_ID(Buffer); if (h2cCmdId == 0xff && h2cSubCmdId == 0x60) { c2hAckLen = (u8)C2H_HDR_GET_LEN(Buffer); if (c2hAckLen >= 8) BT_CoexOffloadC2hAckCheck(Adapter, &Buffer[12], (u8)(c2hAckLen - 8)); else BT_CoexOffloadRecordErrC2hAck(Adapter); } } else if (c2hSubCmdId == C2H_SUB_CMD_ID_BT_COEX_INFO) { /* coex c2h indication */ c2hIndLen = (u8)C2H_HDR_GET_LEN(Buffer); BT_CoexOffloadC2hIndCheck(Adapter, &Buffer[4], (u8)c2hIndLen); } } #endif } #endif /* ************************************ * Extern functions called by other module * ************************************ */ u8 EXhalbtcoutsrc_BindBtCoexWithAdapter(void *padapter) { PBTC_COEXIST pBtCoexist = &GLBtCoexist; HAL_DATA_TYPE *pHalData = GET_HAL_DATA((PADAPTER)padapter); if (pBtCoexist->bBinded) return _FALSE; else pBtCoexist->bBinded = _TRUE; pBtCoexist->statistics.cnt_bind++; pBtCoexist->Adapter = padapter; pBtCoexist->odm_priv = (void *)&(pHalData->odmpriv); pBtCoexist->stack_info.profile_notified = _FALSE; pBtCoexist->bt_info.bt_ctrl_agg_buf_size = _FALSE; pBtCoexist->bt_info.agg_buf_size = 5; pBtCoexist->bt_info.increase_scan_dev_num = _FALSE; pBtCoexist->bt_info.miracast_plus_bt = _FALSE; /* for btc common architecture, inform chip type to coex. mechanism */ if(IS_HARDWARE_TYPE_8822C(padapter)) { #ifdef CONFIG_RTL8822C pBtCoexist->chip_type = BTC_CHIP_RTL8822C; pBtCoexist->chip_para = &btc_chip_para_8822c; #endif } #ifdef CONFIG_RTL8192F else if (IS_HARDWARE_TYPE_8192F(padapter)) { pBtCoexist->chip_type = BTC_CHIP_RTL8725A; pBtCoexist->chip_para = &btc_chip_para_8192f; } #endif else { pBtCoexist->chip_type = BTC_CHIP_UNDEF; pBtCoexist->chip_para = NULL; } return _TRUE; } void EXhalbtcoutsrc_AntInfoSetting(void *padapter) { PBTC_COEXIST pBtCoexist = &GLBtCoexist; u8 antNum = 1, singleAntPath = 0; antNum = rtw_btcoex_get_pg_ant_num((PADAPTER)padapter); EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_PG, antNum); if (antNum == 1) { singleAntPath = rtw_btcoex_get_pg_single_ant_path((PADAPTER)padapter); EXhalbtcoutsrc_SetSingleAntPath(singleAntPath); } pBtCoexist->board_info.customerID = RT_CID_DEFAULT; pBtCoexist->board_info.customer_id = RT_CID_DEFAULT; /* set default antenna position to main port */ pBtCoexist->board_info.btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT; pBtCoexist->board_info.btdm_ant_det_finish = _FALSE; pBtCoexist->board_info.btdm_ant_num_by_ant_det = 1; pBtCoexist->board_info.tfbga_package = rtw_btcoex_is_tfbga_package_type((PADAPTER)padapter); pBtCoexist->board_info.rfe_type = rtw_btcoex_get_pg_rfe_type((PADAPTER)padapter); pBtCoexist->board_info.ant_div_cfg = rtw_btcoex_get_ant_div_cfg((PADAPTER)padapter); pBtCoexist->board_info.ant_distance = 10; } u8 EXhalbtcoutsrc_InitlizeVariables(void *padapter) { PBTC_COEXIST pBtCoexist = &GLBtCoexist; /* pBtCoexist->statistics.cntBind++; */ halbtcoutsrc_DbgInit(); halbtcoutsrc_coex_offload_init(); #ifdef CONFIG_PCI_HCI pBtCoexist->chip_interface = BTC_INTF_PCI; #elif defined(CONFIG_USB_HCI) pBtCoexist->chip_interface = BTC_INTF_USB; #elif defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI) pBtCoexist->chip_interface = BTC_INTF_SDIO; #else pBtCoexist->chip_interface = BTC_INTF_UNKNOWN; #endif EXhalbtcoutsrc_BindBtCoexWithAdapter(padapter); pBtCoexist->btc_read_1byte = halbtcoutsrc_Read1Byte; pBtCoexist->btc_write_1byte = halbtcoutsrc_Write1Byte; pBtCoexist->btc_write_1byte_bitmask = halbtcoutsrc_BitMaskWrite1Byte; pBtCoexist->btc_read_2byte = halbtcoutsrc_Read2Byte; pBtCoexist->btc_write_2byte = halbtcoutsrc_Write2Byte; pBtCoexist->btc_read_4byte = halbtcoutsrc_Read4Byte; pBtCoexist->btc_write_4byte = halbtcoutsrc_Write4Byte; pBtCoexist->btc_write_local_reg_1byte = halbtcoutsrc_WriteLocalReg1Byte; pBtCoexist->btc_read_linderct = halbtcoutsrc_ReadLIndirectReg; pBtCoexist->btc_write_linderct = halbtcoutsrc_WriteLIndirectReg; pBtCoexist->btc_read_scbd = halbtcoutsrc_Read_scbd; pBtCoexist->btc_write_scbd = halbtcoutsrc_Write_scbd; pBtCoexist->btc_set_bb_reg = halbtcoutsrc_SetBbReg; pBtCoexist->btc_get_bb_reg = halbtcoutsrc_GetBbReg; pBtCoexist->btc_set_rf_reg = halbtcoutsrc_SetRfReg; pBtCoexist->btc_get_rf_reg = halbtcoutsrc_GetRfReg; pBtCoexist->btc_fill_h2c = halbtcoutsrc_FillH2cCmd; pBtCoexist->btc_disp_dbg_msg = halbtcoutsrc_DisplayDbgMsg; pBtCoexist->btc_get = halbtcoutsrc_Get; pBtCoexist->btc_set = halbtcoutsrc_Set; pBtCoexist->btc_get_bt_reg = halbtcoutsrc_GetBtReg; pBtCoexist->btc_set_bt_reg = halbtcoutsrc_SetBtReg; pBtCoexist->btc_set_bt_ant_detection = halbtcoutsrc_SetBtAntDetection; pBtCoexist->btc_set_bt_trx_mask = halbtcoutsrc_SetBtTRXMASK; pBtCoexist->btc_coex_h2c_process = halbtcoutsrc_CoexH2cProcess; pBtCoexist->btc_get_bt_coex_supported_feature = halbtcoutsrc_GetBtCoexSupportedFeature; pBtCoexist->btc_get_bt_coex_supported_version= halbtcoutsrc_GetBtCoexSupportedVersion; pBtCoexist->btc_get_ant_det_val_from_bt = halbtcoutsrc_GetAntDetValFromBt; pBtCoexist->btc_get_ble_scan_type_from_bt = halbtcoutsrc_GetBleScanTypeFromBt; pBtCoexist->btc_get_ble_scan_para_from_bt = halbtcoutsrc_GetBleScanParaFromBt; pBtCoexist->btc_get_bt_afh_map_from_bt = halbtcoutsrc_GetBtAFHMapFromBt; pBtCoexist->btc_get_bt_phydm_version = halbtcoutsrc_GetPhydmVersion; pBtCoexist->btc_set_timer = halbtcoutsrc_SetTimer; pBtCoexist->btc_set_atomic= halbtcoutsrc_SetAtomic; pBtCoexist->btc_phydm_modify_RA_PCR_threshold = halbtcoutsrc_phydm_modify_RA_PCR_threshold; pBtCoexist->btc_phydm_query_PHY_counter = halbtcoutsrc_phydm_query_PHY_counter; pBtCoexist->btc_reduce_wl_tx_power = halbtcoutsrc_reduce_wl_tx_power; pBtCoexist->btc_phydm_modify_antdiv_hwsw = halbtcoutsrc_phydm_modify_AntDiv_HwSw; pBtCoexist->cli_buf = &GLBtcDbgBuf[0]; GLBtcWiFiInScanState = _FALSE; GLBtcWiFiInIQKState = _FALSE; GLBtcWiFiInIPS = _FALSE; GLBtcWiFiInLPS = _FALSE; GLBtcBtCoexAliveRegistered = _FALSE; /* BT Control H2C/C2H*/ GLBtcBtMpOperSeq = 0; _rtw_mutex_init(&GLBtcBtMpOperLock); rtw_init_timer(&GLBtcBtMpOperTimer, padapter, _btmpoper_timer_hdl, pBtCoexist); _rtw_init_sema(&GLBtcBtMpRptSema, 0); GLBtcBtMpRptSeq = 0; GLBtcBtMpRptStatus = 0; _rtw_memset(GLBtcBtMpRptRsp, 0, C2H_MAX_SIZE); GLBtcBtMpRptRspSize = 0; GLBtcBtMpRptWait = _FALSE; GLBtcBtMpRptWiFiOK = _FALSE; GLBtcBtMpRptBTOK = _FALSE; return _TRUE; } void EXhalbtcoutsrc_PowerOnSetting(PBTC_COEXIST pBtCoexist) { HAL_DATA_TYPE *pHalData = NULL; if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) return; pHalData = GET_HAL_DATA((PADAPTER)pBtCoexist->Adapter); #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1) rtw_btc_ex_power_on_setting(pBtCoexist); #else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) { #ifdef CONFIG_RTL8723B if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8723b2ant_power_on_setting(pBtCoexist); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8723b1ant_power_on_setting(pBtCoexist); #endif } #ifdef CONFIG_RTL8703B else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8703b1ant_power_on_setting(pBtCoexist); } #endif #ifdef CONFIG_RTL8723D else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8723d2ant_power_on_setting(pBtCoexist); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8723d1ant_power_on_setting(pBtCoexist); } #endif #ifdef CONFIG_RTL8821A else if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8821a1ant_power_on_setting(pBtCoexist); else if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8821a2ant_power_on_setting(pBtCoexist); } #endif #ifdef CONFIG_RTL8822B else if ((IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) && (pHalData->EEPROMBluetoothCoexist == _TRUE)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8822b1ant_power_on_setting(pBtCoexist); else if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8822b2ant_power_on_setting(pBtCoexist); } #endif #ifdef CONFIG_RTL8821C else if ((IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) && (pHalData->EEPROMBluetoothCoexist == _TRUE)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8821c2ant_power_on_setting(pBtCoexist); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8821c1ant_power_on_setting(pBtCoexist); } #endif #ifdef CONFIG_RTL8814A if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8814a2ant_power_on_setting(pBtCoexist); /* else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8814a1ant_power_on_setting(pBtCoexist); */ } #endif #endif } void EXhalbtcoutsrc_PreLoadFirmware(PBTC_COEXIST pBtCoexist) { if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) return; pBtCoexist->statistics.cnt_pre_load_firmware++; if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) { #ifdef CONFIG_RTL8723B if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8723b2ant_pre_load_firmware(pBtCoexist); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8723b1ant_pre_load_firmware(pBtCoexist); #endif } #ifdef CONFIG_RTL8723D else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8723d2ant_pre_load_firmware(pBtCoexist); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8723d1ant_pre_load_firmware(pBtCoexist); } #endif #ifdef CONFIG_RTL8821C else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8821c2ant_pre_load_firmware(pBtCoexist); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8821c1ant_pre_load_firmware(pBtCoexist); } #endif } void EXhalbtcoutsrc_init_hw_config(PBTC_COEXIST pBtCoexist, u8 bWifiOnly) { if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) return; pBtCoexist->statistics.cnt_init_hw_config++; #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1) rtw_btc_ex_init_hw_config(pBtCoexist, bWifiOnly); #else if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) { #ifdef CONFIG_RTL8821A if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8821a2ant_init_hw_config(pBtCoexist, bWifiOnly); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8821a1ant_init_hw_config(pBtCoexist, bWifiOnly); #endif } #ifdef CONFIG_RTL8723B else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8723b2ant_init_hw_config(pBtCoexist, bWifiOnly); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8723b1ant_init_hw_config(pBtCoexist, bWifiOnly); } #endif #ifdef CONFIG_RTL8703B else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8703b1ant_init_hw_config(pBtCoexist, bWifiOnly); } #endif #ifdef CONFIG_RTL8723D else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8723d2ant_init_hw_config(pBtCoexist, bWifiOnly); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8723d1ant_init_hw_config(pBtCoexist, bWifiOnly); } #endif #ifdef CONFIG_RTL8192E else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8192e2ant_init_hw_config(pBtCoexist, bWifiOnly); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8192e1ant_init_hw_config(pBtCoexist, bWifiOnly); } #endif #ifdef CONFIG_RTL8812A else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8812a2ant_init_hw_config(pBtCoexist, bWifiOnly); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8812a1ant_init_hw_config(pBtCoexist, bWifiOnly); } #endif #ifdef CONFIG_RTL8822B else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8822b1ant_init_hw_config(pBtCoexist, bWifiOnly); else if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8822b2ant_init_hw_config(pBtCoexist, bWifiOnly); } #endif #ifdef CONFIG_RTL8821C else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8821c2ant_init_hw_config(pBtCoexist, bWifiOnly); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8821c1ant_init_hw_config(pBtCoexist, bWifiOnly); } #endif #ifdef CONFIG_RTL8814A else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8814a2ant_init_hw_config(pBtCoexist, bWifiOnly); } #endif #endif } void EXhalbtcoutsrc_init_coex_dm(PBTC_COEXIST pBtCoexist) { if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) return; pBtCoexist->statistics.cnt_init_coex_dm++; #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1) rtw_btc_ex_init_coex_dm(pBtCoexist); #else if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) { #ifdef CONFIG_RTL8821A if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8821a2ant_init_coex_dm(pBtCoexist); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8821a1ant_init_coex_dm(pBtCoexist); #endif } #ifdef CONFIG_RTL8723B else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8723b2ant_init_coex_dm(pBtCoexist); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8723b1ant_init_coex_dm(pBtCoexist); } #endif #ifdef CONFIG_RTL8703B else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8703b1ant_init_coex_dm(pBtCoexist); } #endif #ifdef CONFIG_RTL8723D else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8723d2ant_init_coex_dm(pBtCoexist); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8723d1ant_init_coex_dm(pBtCoexist); } #endif #ifdef CONFIG_RTL8192E else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8192e2ant_init_coex_dm(pBtCoexist); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8192e1ant_init_coex_dm(pBtCoexist); } #endif #ifdef CONFIG_RTL8812A else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8812a2ant_init_coex_dm(pBtCoexist); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8812a1ant_init_coex_dm(pBtCoexist); } #endif #ifdef CONFIG_RTL8822B else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8822b1ant_init_coex_dm(pBtCoexist); else if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8822b2ant_init_coex_dm(pBtCoexist); } #endif #ifdef CONFIG_RTL8821C else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8821c2ant_init_coex_dm(pBtCoexist); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8821c1ant_init_coex_dm(pBtCoexist); } #endif #ifdef CONFIG_RTL8814A else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8814a2ant_init_coex_dm(pBtCoexist); } #endif #endif pBtCoexist->initilized = _TRUE; } void EXhalbtcoutsrc_ips_notify(PBTC_COEXIST pBtCoexist, u8 type) { u8 ipsType; if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) return; pBtCoexist->statistics.cnt_ips_notify++; if (pBtCoexist->manual_control) return; if (IPS_NONE == type) { ipsType = BTC_IPS_LEAVE; GLBtcWiFiInIPS = _FALSE; } else { ipsType = BTC_IPS_ENTER; GLBtcWiFiInIPS = _TRUE; } /* All notify is called in cmd thread, don't need to leave low power again * halbtcoutsrc_LeaveLowPower(pBtCoexist); */ #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1) rtw_btc_ex_ips_notify(pBtCoexist, ipsType); #else if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) { #ifdef CONFIG_RTL8821A if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8821a2ant_ips_notify(pBtCoexist, ipsType); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8821a1ant_ips_notify(pBtCoexist, ipsType); #endif } #ifdef CONFIG_RTL8723B else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8723b2ant_ips_notify(pBtCoexist, ipsType); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8723b1ant_ips_notify(pBtCoexist, ipsType); } #endif #ifdef CONFIG_RTL8703B else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8703b1ant_ips_notify(pBtCoexist, ipsType); } #endif #ifdef CONFIG_RTL8723D else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8723d2ant_ips_notify(pBtCoexist, ipsType); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8723d1ant_ips_notify(pBtCoexist, ipsType); } #endif #ifdef CONFIG_RTL8192E else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8192e2ant_ips_notify(pBtCoexist, ipsType); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8192e1ant_ips_notify(pBtCoexist, ipsType); } #endif #ifdef CONFIG_RTL8812A else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8812a2ant_ips_notify(pBtCoexist, ipsType); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8812a1ant_ips_notify(pBtCoexist, ipsType); } #endif #ifdef CONFIG_RTL8822B else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8822b1ant_ips_notify(pBtCoexist, ipsType); else if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8822b2ant_ips_notify(pBtCoexist, ipsType); } #endif #ifdef CONFIG_RTL8821C else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8821c2ant_ips_notify(pBtCoexist, ipsType); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8821c1ant_ips_notify(pBtCoexist, ipsType); } #endif #ifdef CONFIG_RTL8814A else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8814a2ant_ips_notify(pBtCoexist, ipsType); } #endif #endif /* halbtcoutsrc_NormalLowPower(pBtCoexist); */ } void EXhalbtcoutsrc_lps_notify(PBTC_COEXIST pBtCoexist, u8 type) { u8 lpsType; if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) return; pBtCoexist->statistics.cnt_lps_notify++; if (pBtCoexist->manual_control) return; if (PS_MODE_ACTIVE == type) { lpsType = BTC_LPS_DISABLE; GLBtcWiFiInLPS = _FALSE; } else { lpsType = BTC_LPS_ENABLE; GLBtcWiFiInLPS = _TRUE; } #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1) rtw_btc_ex_lps_notify(pBtCoexist, lpsType); #else if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) { #ifdef CONFIG_RTL8821A if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8821a2ant_lps_notify(pBtCoexist, lpsType); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8821a1ant_lps_notify(pBtCoexist, lpsType); #endif } #ifdef CONFIG_RTL8723B else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8723b2ant_lps_notify(pBtCoexist, lpsType); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8723b1ant_lps_notify(pBtCoexist, lpsType); } #endif #ifdef CONFIG_RTL8703B else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8703b1ant_lps_notify(pBtCoexist, lpsType); } #endif #ifdef CONFIG_RTL8723D else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8723d2ant_lps_notify(pBtCoexist, lpsType); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8723d1ant_lps_notify(pBtCoexist, lpsType); } #endif #ifdef CONFIG_RTL8192E else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8192e2ant_lps_notify(pBtCoexist, lpsType); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8192e1ant_lps_notify(pBtCoexist, lpsType); } #endif #ifdef CONFIG_RTL8812A else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8812a2ant_lps_notify(pBtCoexist, lpsType); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8812a1ant_lps_notify(pBtCoexist, lpsType); } #endif #ifdef CONFIG_RTL8822B else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8822b1ant_lps_notify(pBtCoexist, lpsType); else if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8822b2ant_lps_notify(pBtCoexist, lpsType); } #endif #ifdef CONFIG_RTL8821C else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8821c2ant_lps_notify(pBtCoexist, lpsType); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8821c1ant_lps_notify(pBtCoexist, lpsType); } #endif #ifdef CONFIG_RTL8814A else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8814a2ant_lps_notify(pBtCoexist, lpsType); } #endif #endif } void EXhalbtcoutsrc_scan_notify(PBTC_COEXIST pBtCoexist, u8 type) { u8 scanType; if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) return; pBtCoexist->statistics.cnt_scan_notify++; if (pBtCoexist->manual_control) return; if (type) { scanType = BTC_SCAN_START; GLBtcWiFiInScanState = _TRUE; } else { scanType = BTC_SCAN_FINISH; GLBtcWiFiInScanState = _FALSE; } /* All notify is called in cmd thread, don't need to leave low power again * halbtcoutsrc_LeaveLowPower(pBtCoexist); */ #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1) rtw_btc_ex_scan_notify(pBtCoexist, scanType); #else if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) { #ifdef CONFIG_RTL8821A if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8821a2ant_scan_notify(pBtCoexist, scanType); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8821a1ant_scan_notify(pBtCoexist, scanType); #endif } #ifdef CONFIG_RTL8723B else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8723b2ant_scan_notify(pBtCoexist, scanType); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8723b1ant_scan_notify(pBtCoexist, scanType); } #endif #ifdef CONFIG_RTL8703B else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8703b1ant_scan_notify(pBtCoexist, scanType); } #endif #ifdef CONFIG_RTL8723D else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8723d2ant_scan_notify(pBtCoexist, scanType); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8723d1ant_scan_notify(pBtCoexist, scanType); } #endif #ifdef CONFIG_RTL8192E else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8192e2ant_scan_notify(pBtCoexist, scanType); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8192e1ant_scan_notify(pBtCoexist, scanType); } #endif #ifdef CONFIG_RTL8812A else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8812a2ant_scan_notify(pBtCoexist, scanType); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8812a1ant_scan_notify(pBtCoexist, scanType); } #endif #ifdef CONFIG_RTL8822B else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8822b1ant_scan_notify(pBtCoexist, scanType); else if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8822b2ant_scan_notify(pBtCoexist, scanType); } #endif #ifdef CONFIG_RTL8821C else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8821c2ant_scan_notify(pBtCoexist, scanType); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8821c1ant_scan_notify(pBtCoexist, scanType); } #endif #ifdef CONFIG_RTL8814A else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8814a2ant_scan_notify(pBtCoexist, scanType); } #endif #endif /* halbtcoutsrc_NormalLowPower(pBtCoexist); */ } void EXhalbtcoutsrc_SetAntennaPathNotify(PBTC_COEXIST pBtCoexist, u8 type) { #if 0 u8 switchType; if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) return; if (pBtCoexist->manual_control) return; halbtcoutsrc_LeaveLowPower(pBtCoexist); switchType = type; if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8723b1ant_set_antenna_notify(pBtCoexist, type); } if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8723d1ant_set_antenna_notify(pBtCoexist, type); else if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8723d2ant_set_antenna_notify(pBtCoexist, type); } halbtcoutsrc_NormalLowPower(pBtCoexist); #endif } void EXhalbtcoutsrc_connect_notify(PBTC_COEXIST pBtCoexist, u8 assoType) { if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) return; pBtCoexist->statistics.cnt_connect_notify++; if (pBtCoexist->manual_control) return; /* All notify is called in cmd thread, don't need to leave low power again * halbtcoutsrc_LeaveLowPower(pBtCoexist); */ #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1) rtw_btc_ex_connect_notify(pBtCoexist, assoType); #else if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) { #ifdef CONFIG_RTL8821A if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8821a2ant_connect_notify(pBtCoexist, assoType); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8821a1ant_connect_notify(pBtCoexist, assoType); #endif } #ifdef CONFIG_RTL8723B else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8723b2ant_connect_notify(pBtCoexist, assoType); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8723b1ant_connect_notify(pBtCoexist, assoType); } #endif #ifdef CONFIG_RTL8703B else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8703b1ant_connect_notify(pBtCoexist, assoType); } #endif #ifdef CONFIG_RTL8723D else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8723d2ant_connect_notify(pBtCoexist, assoType); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8723d1ant_connect_notify(pBtCoexist, assoType); } #endif #ifdef CONFIG_RTL8192E else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8192e2ant_connect_notify(pBtCoexist, assoType); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8192e1ant_connect_notify(pBtCoexist, assoType); } #endif #ifdef CONFIG_RTL8812A else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8812a2ant_connect_notify(pBtCoexist, assoType); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8812a1ant_connect_notify(pBtCoexist, assoType); } #endif #ifdef CONFIG_RTL8822B else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8822b1ant_connect_notify(pBtCoexist, assoType); else if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8822b2ant_connect_notify(pBtCoexist, assoType); } #endif #ifdef CONFIG_RTL8821C else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8821c2ant_connect_notify(pBtCoexist, assoType); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8821c1ant_connect_notify(pBtCoexist, assoType); } #endif #ifdef CONFIG_RTL8814A else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8814a2ant_connect_notify(pBtCoexist, assoType); } #endif #endif /* halbtcoutsrc_NormalLowPower(pBtCoexist); */ } void EXhalbtcoutsrc_media_status_notify(PBTC_COEXIST pBtCoexist, RT_MEDIA_STATUS mediaStatus) { u8 mStatus = BTC_MEDIA_MAX; PADAPTER adapter = NULL; HAL_DATA_TYPE *hal = NULL; if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) return; if (pBtCoexist->manual_control) return; pBtCoexist->statistics.cnt_media_status_notify++; adapter = (PADAPTER)pBtCoexist->Adapter; hal = GET_HAL_DATA(adapter); if (RT_MEDIA_CONNECT == mediaStatus) { if (hal->current_band_type == BAND_ON_2_4G) mStatus = BTC_MEDIA_CONNECT; else if (hal->current_band_type == BAND_ON_5G) mStatus = BTC_MEDIA_CONNECT_5G; else { mStatus = BTC_MEDIA_CONNECT; RTW_ERR("%s unknow band type\n", __func__); } } else mStatus = BTC_MEDIA_DISCONNECT; /* All notify is called in cmd thread, don't need to leave low power again * halbtcoutsrc_LeaveLowPower(pBtCoexist); */ #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1) rtw_btc_ex_media_status_notify(pBtCoexist, mStatus); #else if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) { #ifdef CONFIG_RTL8821A /* compatible for 8821A */ if (mStatus == BTC_MEDIA_CONNECT_5G) mStatus = BTC_MEDIA_CONNECT; if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8821a2ant_media_status_notify(pBtCoexist, mStatus); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8821a1ant_media_status_notify(pBtCoexist, mStatus); #endif } #ifdef CONFIG_RTL8723B else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8723b2ant_media_status_notify(pBtCoexist, mStatus); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8723b1ant_media_status_notify(pBtCoexist, mStatus); } #endif #ifdef CONFIG_RTL8703B else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8703b1ant_media_status_notify(pBtCoexist, mStatus); } #endif #ifdef CONFIG_RTL8723D else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8723d2ant_media_status_notify(pBtCoexist, mStatus); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8723d1ant_media_status_notify(pBtCoexist, mStatus); } #endif #ifdef CONFIG_RTL8192E else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8192e2ant_media_status_notify(pBtCoexist, mStatus); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8192e1ant_media_status_notify(pBtCoexist, mStatus); } #endif #ifdef CONFIG_RTL8812A else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) { /* compatible for 8812A */ if (mStatus == BTC_MEDIA_CONNECT_5G) mStatus = BTC_MEDIA_CONNECT; if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8812a2ant_media_status_notify(pBtCoexist, mStatus); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8812a1ant_media_status_notify(pBtCoexist, mStatus); } #endif #ifdef CONFIG_RTL8822B else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8822b1ant_media_status_notify(pBtCoexist, mStatus); else if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8822b2ant_media_status_notify(pBtCoexist, mStatus); } #endif #ifdef CONFIG_RTL8821C else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8821c2ant_media_status_notify(pBtCoexist, mStatus); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8821c1ant_media_status_notify(pBtCoexist, mStatus); } #endif #ifdef CONFIG_RTL8814A else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8814a2ant_media_status_notify(pBtCoexist, mStatus); } #endif #endif /* halbtcoutsrc_NormalLowPower(pBtCoexist); */ } void EXhalbtcoutsrc_specific_packet_notify(PBTC_COEXIST pBtCoexist, u8 pktType) { u8 packetType; PADAPTER adapter = NULL; HAL_DATA_TYPE *hal = NULL; if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) return; if (pBtCoexist->manual_control) return; pBtCoexist->statistics.cnt_specific_packet_notify++; adapter = (PADAPTER)pBtCoexist->Adapter; hal = GET_HAL_DATA(adapter); if (PACKET_DHCP == pktType) packetType = BTC_PACKET_DHCP; else if (PACKET_EAPOL == pktType) packetType = BTC_PACKET_EAPOL; else if (PACKET_ARP == pktType) packetType = BTC_PACKET_ARP; else { packetType = BTC_PACKET_UNKNOWN; return; } if (hal->current_band_type == BAND_ON_5G) packetType |= BTC_5G_BAND; /* All notify is called in cmd thread, don't need to leave low power again * halbtcoutsrc_LeaveLowPower(pBtCoexist); */ #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1) rtw_btc_ex_specific_packet_notify(pBtCoexist, packetType); #else if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) { #ifdef CONFIG_RTL8821A /* compatible for 8821A */ if (hal->current_band_type == BAND_ON_5G) packetType &= ~BTC_5G_BAND; if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8821a2ant_specific_packet_notify(pBtCoexist, packetType); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8821a1ant_specific_packet_notify(pBtCoexist, packetType); #endif } #ifdef CONFIG_RTL8723B else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8723b2ant_specific_packet_notify(pBtCoexist, packetType); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8723b1ant_specific_packet_notify(pBtCoexist, packetType); } #endif #ifdef CONFIG_RTL8703B else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8703b1ant_specific_packet_notify(pBtCoexist, packetType); } #endif #ifdef CONFIG_RTL8723D else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8723d2ant_specific_packet_notify(pBtCoexist, packetType); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8723d1ant_specific_packet_notify(pBtCoexist, packetType); } #endif #ifdef CONFIG_RTL8192E else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8192e2ant_specific_packet_notify(pBtCoexist, packetType); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8192e1ant_specific_packet_notify(pBtCoexist, packetType); } #endif #ifdef CONFIG_RTL8812A else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) { /* compatible for 8812A */ if (hal->current_band_type == BAND_ON_5G) packetType &= ~BTC_5G_BAND; if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8812a2ant_specific_packet_notify(pBtCoexist, packetType); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8812a1ant_specific_packet_notify(pBtCoexist, packetType); } #endif #ifdef CONFIG_RTL8822B else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8822b1ant_specific_packet_notify(pBtCoexist, packetType); else if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8822b2ant_specific_packet_notify(pBtCoexist, packetType); } #endif #ifdef CONFIG_RTL8821C else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8821c2ant_specific_packet_notify(pBtCoexist, packetType); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8821c1ant_specific_packet_notify(pBtCoexist, packetType); } #endif #ifdef CONFIG_RTL8814A else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8814a2ant_specific_packet_notify(pBtCoexist, packetType); } #endif #endif /* halbtcoutsrc_NormalLowPower(pBtCoexist); */ } void EXhalbtcoutsrc_bt_info_notify(PBTC_COEXIST pBtCoexist, u8 *tmpBuf, u8 length) { if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) return; pBtCoexist->statistics.cnt_bt_info_notify++; /* All notify is called in cmd thread, don't need to leave low power again * halbtcoutsrc_LeaveLowPower(pBtCoexist); */ #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1) rtw_btc_ex_bt_info_notify(pBtCoexist, tmpBuf, length); #else if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) { #ifdef CONFIG_RTL8821A if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8821a2ant_bt_info_notify(pBtCoexist, tmpBuf, length); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8821a1ant_bt_info_notify(pBtCoexist, tmpBuf, length); #endif } #ifdef CONFIG_RTL8723B else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8723b2ant_bt_info_notify(pBtCoexist, tmpBuf, length); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8723b1ant_bt_info_notify(pBtCoexist, tmpBuf, length); } #endif #ifdef CONFIG_RTL8703B else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8703b1ant_bt_info_notify(pBtCoexist, tmpBuf, length); } #endif #ifdef CONFIG_RTL8723D else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8723d2ant_bt_info_notify(pBtCoexist, tmpBuf, length); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8723d1ant_bt_info_notify(pBtCoexist, tmpBuf, length); } #endif #ifdef CONFIG_RTL8192E else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8192e2ant_bt_info_notify(pBtCoexist, tmpBuf, length); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8192e1ant_bt_info_notify(pBtCoexist, tmpBuf, length); } #endif #ifdef CONFIG_RTL8812A else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8812a2ant_bt_info_notify(pBtCoexist, tmpBuf, length); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8812a1ant_bt_info_notify(pBtCoexist, tmpBuf, length); } #endif #ifdef CONFIG_RTL8822B else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8822b1ant_bt_info_notify(pBtCoexist, tmpBuf, length); else if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8822b2ant_bt_info_notify(pBtCoexist, tmpBuf, length); } #endif #ifdef CONFIG_RTL8821C else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8821c2ant_bt_info_notify(pBtCoexist, tmpBuf, length); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8821c1ant_bt_info_notify(pBtCoexist, tmpBuf, length); } #endif #ifdef CONFIG_RTL8814A else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8814a2ant_bt_info_notify(pBtCoexist, tmpBuf, length); } #endif #endif /* halbtcoutsrc_NormalLowPower(pBtCoexist); */ } void EXhalbtcoutsrc_WlFwDbgInfoNotify(PBTC_COEXIST pBtCoexist, u8* tmpBuf, u8 length) { if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) return; #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1) rtw_btc_ex_wl_fwdbginfo_notify(pBtCoexist, tmpBuf, length); #else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) { #ifdef CONFIG_RTL8703B if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8703b1ant_wl_fwdbginfo_notify(pBtCoexist, tmpBuf, length); #endif } #ifdef CONFIG_RTL8723D else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8723d1ant_wl_fwdbginfo_notify(pBtCoexist, tmpBuf, length); else if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8723d2ant_wl_fwdbginfo_notify(pBtCoexist, tmpBuf, length); } #endif #ifdef CONFIG_RTL8821C else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8821c2ant_wl_fwdbginfo_notify(pBtCoexist, tmpBuf, length); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8821c1ant_wl_fwdbginfo_notify(pBtCoexist, tmpBuf, length); } #endif #endif } void EXhalbtcoutsrc_rx_rate_change_notify(PBTC_COEXIST pBtCoexist, u8 is_data_frame, u8 btc_rate_id) { if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) return; pBtCoexist->statistics.cnt_rate_id_notify++; #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1) rtw_btc_ex_rx_rate_change_notify(pBtCoexist, is_data_frame, btc_rate_id); #else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) { #ifdef CONFIG_RTL8703B if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8703b1ant_rx_rate_change_notify(pBtCoexist, is_data_frame, btc_rate_id); #endif } #ifdef CONFIG_RTL8723D else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8723d1ant_rx_rate_change_notify(pBtCoexist, is_data_frame, btc_rate_id); else if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8723d2ant_rx_rate_change_notify(pBtCoexist, is_data_frame, btc_rate_id); } #endif #ifdef CONFIG_RTL8821C else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8821c1ant_rx_rate_change_notify(pBtCoexist, is_data_frame, btc_rate_id); else if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8821c2ant_rx_rate_change_notify(pBtCoexist, is_data_frame, btc_rate_id); } #endif #endif } void EXhalbtcoutsrc_RfStatusNotify( PBTC_COEXIST pBtCoexist, u8 type ) { if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) return; pBtCoexist->statistics.cnt_rf_status_notify++; #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1) rtw_btc_ex_rf_status_notify(pBtCoexist, type); #else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) { #ifdef CONFIG_RTL8723B if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8723b1ant_rf_status_notify(pBtCoexist, type); #endif } #ifdef CONFIG_RTL8703B else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8703b1ant_rf_status_notify(pBtCoexist, type); } #endif #ifdef CONFIG_RTL8723D else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8723d1ant_rf_status_notify(pBtCoexist, type); } #endif #ifdef CONFIG_RTL8822B else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8822b1ant_rf_status_notify(pBtCoexist, type); else if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8822b2ant_rf_status_notify(pBtCoexist, type); } #endif #ifdef CONFIG_RTL8821C else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8821c2ant_rf_status_notify(pBtCoexist, type); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8821c1ant_rf_status_notify(pBtCoexist, type); } #endif #ifdef CONFIG_RTL8814A else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8814a2ant_rf_status_notify(pBtCoexist, type); } #endif #endif } void EXhalbtcoutsrc_StackOperationNotify(PBTC_COEXIST pBtCoexist, u8 type) { #if 0 u8 stackOpType; if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) return; pBtCoexist->statistics.cntStackOperationNotify++; if (pBtCoexist->manual_control) return; if ((HCI_BT_OP_INQUIRY_START == type) || (HCI_BT_OP_PAGING_START == type) || (HCI_BT_OP_PAIRING_START == type)) stackOpType = BTC_STACK_OP_INQ_PAGE_PAIR_START; else if ((HCI_BT_OP_INQUIRY_FINISH == type) || (HCI_BT_OP_PAGING_SUCCESS == type) || (HCI_BT_OP_PAGING_UNSUCCESS == type) || (HCI_BT_OP_PAIRING_FINISH == type)) stackOpType = BTC_STACK_OP_INQ_PAGE_PAIR_FINISH; else stackOpType = BTC_STACK_OP_NONE; #endif } void EXhalbtcoutsrc_halt_notify(PBTC_COEXIST pBtCoexist) { if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) return; pBtCoexist->statistics.cnt_halt_notify++; #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1) rtw_btc_ex_halt_notify(pBtCoexist); #else if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) { #ifdef CONFIG_RTL8821A if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8821a2ant_halt_notify(pBtCoexist); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8821a1ant_halt_notify(pBtCoexist); #endif } #ifdef CONFIG_RTL8723B else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8723b2ant_halt_notify(pBtCoexist); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8723b1ant_halt_notify(pBtCoexist); } #endif #ifdef CONFIG_RTL8703B else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8703b1ant_halt_notify(pBtCoexist); } #endif #ifdef CONFIG_RTL8723D else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8723d2ant_halt_notify(pBtCoexist); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8723d1ant_halt_notify(pBtCoexist); } #endif #ifdef CONFIG_RTL8192E else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8192e2ant_halt_notify(pBtCoexist); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8192e1ant_halt_notify(pBtCoexist); } #endif #ifdef CONFIG_RTL8812A else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8812a2ant_halt_notify(pBtCoexist); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8812a1ant_halt_notify(pBtCoexist); } #endif #ifdef CONFIG_RTL8822B else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8822b1ant_halt_notify(pBtCoexist); else if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8822b2ant_halt_notify(pBtCoexist); } #endif #ifdef CONFIG_RTL8821C else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8821c2ant_halt_notify(pBtCoexist); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8821c1ant_halt_notify(pBtCoexist); } #endif #ifdef CONFIG_RTL8814A else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8814a2ant_halt_notify(pBtCoexist); } #endif #endif } void EXhalbtcoutsrc_SwitchBtTRxMask(PBTC_COEXIST pBtCoexist) { if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) { halbtcoutsrc_SetBtReg(pBtCoexist, 0, 0x3c, 0x01); /* BT goto standby while GNT_BT 1-->0 */ } else if (pBtCoexist->board_info.btdm_ant_num == 1) { halbtcoutsrc_SetBtReg(pBtCoexist, 0, 0x3c, 0x15); /* BT goto standby while GNT_BT 1-->0 */ } } } void EXhalbtcoutsrc_pnp_notify(PBTC_COEXIST pBtCoexist, u8 pnpState) { if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) return; pBtCoexist->statistics.cnt_pnp_notify++; /* */ /* currently only 1ant we have to do the notification, */ /* once pnp is notified to sleep state, we have to leave LPS that we can sleep normally. */ /* */ #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1) rtw_btc_ex_pnp_notify(pBtCoexist, pnpState); #else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) { #ifdef CONFIG_RTL8723B if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8723b1ant_pnp_notify(pBtCoexist, pnpState); else if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8723b2ant_pnp_notify(pBtCoexist, pnpState); #endif } #ifdef CONFIG_RTL8703B else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8703b1ant_pnp_notify(pBtCoexist, pnpState); } #endif #ifdef CONFIG_RTL8723D else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8723d1ant_pnp_notify(pBtCoexist, pnpState); else if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8723d2ant_pnp_notify(pBtCoexist, pnpState); } #endif #ifdef CONFIG_RTL8821A else if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8821a1ant_pnp_notify(pBtCoexist, pnpState); else if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8821a2ant_pnp_notify(pBtCoexist, pnpState); } #endif #ifdef CONFIG_RTL8192E else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8192e1ant_pnp_notify(pBtCoexist, pnpState); } #endif #ifdef CONFIG_RTL8812A else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8812a1ant_pnp_notify(pBtCoexist, pnpState); } #endif #ifdef CONFIG_RTL8822B else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8822b1ant_pnp_notify(pBtCoexist, pnpState); else if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8822b2ant_pnp_notify(pBtCoexist, pnpState); } #endif #ifdef CONFIG_RTL8821C else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8821c2ant_pnp_notify(pBtCoexist, pnpState); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8821c1ant_pnp_notify(pBtCoexist, pnpState); } #endif #ifdef CONFIG_RTL8814A else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8814a2ant_pnp_notify(pBtCoexist, pnpState); } #endif #endif } void EXhalbtcoutsrc_CoexDmSwitch(PBTC_COEXIST pBtCoexist) { if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) return; pBtCoexist->statistics.cnt_coex_dm_switch++; halbtcoutsrc_LeaveLowPower(pBtCoexist); if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) { #ifdef CONFIG_RTL8723B if (pBtCoexist->board_info.btdm_ant_num == 1) { pBtCoexist->stop_coex_dm = TRUE; ex_halbtc8723b1ant_coex_dm_reset(pBtCoexist); EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_DETECTED, 2); ex_halbtc8723b2ant_init_hw_config(pBtCoexist, FALSE); ex_halbtc8723b2ant_init_coex_dm(pBtCoexist); pBtCoexist->stop_coex_dm = FALSE; } #endif } #ifdef CONFIG_RTL8723D else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) { pBtCoexist->stop_coex_dm = TRUE; ex_halbtc8723d1ant_coex_dm_reset(pBtCoexist); EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_DETECTED, 2); ex_halbtc8723d2ant_init_hw_config(pBtCoexist, FALSE); ex_halbtc8723d2ant_init_coex_dm(pBtCoexist); pBtCoexist->stop_coex_dm = FALSE; } } #endif halbtcoutsrc_NormalLowPower(pBtCoexist); } #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1) void EXhalbtcoutsrc_TimerNotify(PBTC_COEXIST pBtCoexist, u32 timer_type) { rtw_btc_ex_timerup_notify(pBtCoexist, timer_type); } void EXhalbtcoutsrc_WLStatusChangeNotify(PBTC_COEXIST pBtCoexist, u32 change_type) { rtw_btc_ex_wl_status_change_notify(pBtCoexist, change_type); } u32 EXhalbtcoutsrc_CoexTimerCheck(PBTC_COEXIST pBtCoexist) { u32 i, timer_map = 0; for (i = 0; i < BTC_TIMER_MAX; i++) { if (pBtCoexist->coex_sta.cnt_timer[i] > 0) { if (pBtCoexist->coex_sta.cnt_timer[i] == 1) { timer_map |= BIT(i); RTW_DBG("[BTC], %s(): timer_map = 0x%x\n", __func__, timer_map); } pBtCoexist->coex_sta.cnt_timer[i]--; } } return timer_map; } u32 EXhalbtcoutsrc_WLStatusCheck(PBTC_COEXIST pBtCoexist) { struct btc_wifi_link_info link_info; const struct btc_chip_para *chip_para = pBtCoexist->chip_para; u32 change_map = 0; static bool wl_busy_pre; bool wl_busy = _FALSE; s32 wl_rssi; u32 traffic_dir; u8 i, tmp; static u8 rssi_step_pre = 5, wl_noisy_level_pre = 4; /* WL busy to idle or idle to busy */ pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &wl_busy); if (wl_busy != wl_busy_pre) { if (wl_busy) change_map |= BIT(BTC_WLSTATUS_CHANGE_TOBUSY); else change_map |= BIT(BTC_WLSTATUS_CHANGE_TOIDLE); wl_busy_pre = wl_busy; } /* WL RSSI */ pBtCoexist->btc_get(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wl_rssi); tmp = (u8)(wl_rssi & 0xff); for (i = 0; i < 4; i++) { if (tmp >= chip_para->wl_rssi_step[i]) break; } if (rssi_step_pre != i) { rssi_step_pre = i; change_map |= BIT(BTC_WLSTATUS_CHANGE_RSSI); } /* WL Link info */ pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_LINK_INFO, &link_info); if (link_info.link_mode != pBtCoexist->wifi_link_info.link_mode || link_info.sta_center_channel != pBtCoexist->wifi_link_info.sta_center_channel || link_info.p2p_center_channel != pBtCoexist->wifi_link_info.p2p_center_channel || link_info.bany_client_join_go != pBtCoexist->wifi_link_info.bany_client_join_go) { change_map |= BIT(BTC_WLSTATUS_CHANGE_LINKINFO); pBtCoexist->wifi_link_info = link_info; } /* WL Traffic Direction */ pBtCoexist->btc_get(pBtCoexist, BTC_GET_U4_WIFI_TRAFFIC_DIR, &traffic_dir); if (wl_busy && traffic_dir != pBtCoexist->wifi_link_info_ext.traffic_dir) { change_map |= BIT(BTC_WLSTATUS_CHANGE_DIR); pBtCoexist->wifi_link_info_ext.traffic_dir = traffic_dir; } /* Noisy Detect */ if (pBtCoexist->coex_sta.wl_noisy_level != wl_noisy_level_pre) { change_map |= BIT(BTC_WLSTATUS_CHANGE_NOISY); wl_noisy_level_pre = pBtCoexist->coex_sta.wl_noisy_level; } RTW_DBG("[BTC], %s(): change_map = 0x%x\n", __func__, change_map); return change_map; } void EXhalbtcoutsrc_status_monitor(PBTC_COEXIST pBtCoexist) { u32 timer_up_type = 0, wl_status_change_type = 0; timer_up_type = EXhalbtcoutsrc_CoexTimerCheck(pBtCoexist); if (timer_up_type != 0) EXhalbtcoutsrc_TimerNotify(pBtCoexist, timer_up_type); wl_status_change_type = EXhalbtcoutsrc_WLStatusCheck(pBtCoexist); if (wl_status_change_type != 0) EXhalbtcoutsrc_WLStatusChangeNotify(pBtCoexist, wl_status_change_type); rtw_btc_ex_periodical(pBtCoexist); } #endif void EXhalbtcoutsrc_periodical(PBTC_COEXIST pBtCoexist) { if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) return; pBtCoexist->statistics.cnt_periodical++; /* Periodical should be called in cmd thread, */ /* don't need to leave low power again * halbtcoutsrc_LeaveLowPower(pBtCoexist); */ #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1) EXhalbtcoutsrc_status_monitor(pBtCoexist); #else if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) { #ifdef CONFIG_RTL8821A if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8821a2ant_periodical(pBtCoexist); else if (pBtCoexist->board_info.btdm_ant_num == 1) { if (!halbtcoutsrc_UnderIps(pBtCoexist)) ex_halbtc8821a1ant_periodical(pBtCoexist); } #endif } #ifdef CONFIG_RTL8723B else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8723b2ant_periodical(pBtCoexist); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8723b1ant_periodical(pBtCoexist); } #endif #ifdef CONFIG_RTL8723D else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8723d2ant_periodical(pBtCoexist); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8723d1ant_periodical(pBtCoexist); } #endif #ifdef CONFIG_RTL8703B else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8703b1ant_periodical(pBtCoexist); } #endif #ifdef CONFIG_RTL8192E else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8192e2ant_periodical(pBtCoexist); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8192e1ant_periodical(pBtCoexist); } #endif #ifdef CONFIG_RTL8812A else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8812a2ant_periodical(pBtCoexist); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8812a1ant_periodical(pBtCoexist); } #endif #ifdef CONFIG_RTL8822B else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8822b1ant_periodical(pBtCoexist); else if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8822b2ant_periodical(pBtCoexist); } #endif #ifdef CONFIG_RTL8821C else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8821c2ant_periodical(pBtCoexist); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8821c1ant_periodical(pBtCoexist); } #endif #ifdef CONFIG_RTL8814A else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8814a2ant_periodical(pBtCoexist); } #endif #endif /* halbtcoutsrc_NormalLowPower(pBtCoexist); */ } void EXhalbtcoutsrc_dbg_control(PBTC_COEXIST pBtCoexist, u8 opCode, u8 opLen, u8 *pData) { if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) return; pBtCoexist->statistics.cnt_dbg_ctrl++; /* This function doesn't be called yet, */ /* default no need to leave low power to avoid deadlock * halbtcoutsrc_LeaveLowPower(pBtCoexist); */ #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1) /* rtw_btc_ex_dbg_control(pBtCoexist, opCode, opLen, pData); */ #else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) { #ifdef CONFIG_RTL8192E if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8192e1ant_dbg_control(pBtCoexist, opCode, opLen, pData); #endif } #ifdef CONFIG_RTL8812A else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8812a2ant_dbg_control(pBtCoexist, opCode, opLen, pData); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8812a1ant_dbg_control(pBtCoexist, opCode, opLen, pData); } #endif #ifdef CONFIG_RTL8822B else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) if(pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8822b1ant_dbg_control(pBtCoexist, opCode, opLen, pData); #endif #endif /* halbtcoutsrc_NormalLowPower(pBtCoexist); */ } #if 0 void EXhalbtcoutsrc_AntennaDetection( PBTC_COEXIST pBtCoexist, u32 centFreq, u32 offset, u32 span, u32 seconds ) { if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) return; /* Need to refine the following power save operations to enable this function in the future */ #if 0 IPSDisable(pBtCoexist->Adapter, FALSE, 0); LeisurePSLeave(pBtCoexist->Adapter, LPS_DISABLE_BT_COEX); #endif if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8723b1ant_AntennaDetection(pBtCoexist, centFreq, offset, span, seconds); } /* IPSReturn(pBtCoexist->Adapter, 0xff); */ } #endif void EXhalbtcoutsrc_StackUpdateProfileInfo(void) { #ifdef CONFIG_BT_COEXIST_SOCKET_TRX PBTC_COEXIST pBtCoexist = &GLBtCoexist; PADAPTER padapter = NULL; PBT_MGNT pBtMgnt = NULL; u8 i; if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) return; padapter = (PADAPTER)pBtCoexist->Adapter; pBtMgnt = &padapter->coex_info.BtMgnt; pBtCoexist->stack_info.profile_notified = _TRUE; pBtCoexist->stack_info.num_of_link = pBtMgnt->ExtConfig.NumberOfACL + pBtMgnt->ExtConfig.NumberOfSCO; /* reset first */ pBtCoexist->stack_info.bt_link_exist = _FALSE; pBtCoexist->stack_info.sco_exist = _FALSE; pBtCoexist->stack_info.acl_exist = _FALSE; pBtCoexist->stack_info.a2dp_exist = _FALSE; pBtCoexist->stack_info.hid_exist = _FALSE; pBtCoexist->stack_info.num_of_hid = 0; pBtCoexist->stack_info.pan_exist = _FALSE; if (!pBtMgnt->ExtConfig.NumberOfACL) pBtCoexist->stack_info.min_bt_rssi = 0; if (pBtCoexist->stack_info.num_of_link) { pBtCoexist->stack_info.bt_link_exist = _TRUE; if (pBtMgnt->ExtConfig.NumberOfSCO) pBtCoexist->stack_info.sco_exist = _TRUE; if (pBtMgnt->ExtConfig.NumberOfACL) pBtCoexist->stack_info.acl_exist = _TRUE; } for (i = 0; i < pBtMgnt->ExtConfig.NumberOfACL; i++) { if (BT_PROFILE_A2DP == pBtMgnt->ExtConfig.aclLink[i].BTProfile) pBtCoexist->stack_info.a2dp_exist = _TRUE; else if (BT_PROFILE_PAN == pBtMgnt->ExtConfig.aclLink[i].BTProfile) pBtCoexist->stack_info.pan_exist = _TRUE; else if (BT_PROFILE_HID == pBtMgnt->ExtConfig.aclLink[i].BTProfile) { pBtCoexist->stack_info.hid_exist = _TRUE; pBtCoexist->stack_info.num_of_hid++; } else pBtCoexist->stack_info.unknown_acl_exist = _TRUE; } #endif /* CONFIG_BT_COEXIST_SOCKET_TRX */ } void EXhalbtcoutsrc_UpdateMinBtRssi(s8 btRssi) { PBTC_COEXIST pBtCoexist = &GLBtCoexist; if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) return; pBtCoexist->stack_info.min_bt_rssi = btRssi; } void EXhalbtcoutsrc_SetHciVersion(u16 hciVersion) { PBTC_COEXIST pBtCoexist = &GLBtCoexist; if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) return; pBtCoexist->stack_info.hci_version = hciVersion; } void EXhalbtcoutsrc_SetBtPatchVersion(u16 btHciVersion, u16 btPatchVersion) { PBTC_COEXIST pBtCoexist = &GLBtCoexist; if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) return; pBtCoexist->bt_info.bt_real_fw_ver = btPatchVersion; pBtCoexist->bt_info.bt_hci_ver = btHciVersion; } #if 0 void EXhalbtcoutsrc_SetBtExist(u8 bBtExist) { GLBtCoexist.boardInfo.bBtExist = bBtExist; } #endif void EXhalbtcoutsrc_SetChipType(u8 chipType) { switch (chipType) { default: case BT_2WIRE: case BT_ISSC_3WIRE: case BT_ACCEL: case BT_RTL8756: GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_UNDEF; break; case BT_CSR_BC4: GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_CSR_BC4; break; case BT_CSR_BC8: GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_CSR_BC8; break; case BT_RTL8723A: GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_RTL8723A; break; case BT_RTL8821: GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_RTL8821; break; case BT_RTL8723B: GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_RTL8723B; break; } } void EXhalbtcoutsrc_SetAntNum(u8 type, u8 antNum) { if (BT_COEX_ANT_TYPE_PG == type) { GLBtCoexist.board_info.pg_ant_num = antNum; GLBtCoexist.board_info.btdm_ant_num = antNum; #if 0 /* The antenna position: Main (default) or Aux for pgAntNum=2 && btdmAntNum =1 */ /* The antenna position should be determined by auto-detect mechanism */ /* The following is assumed to main, and those must be modified if y auto-detect mechanism is ready */ if ((GLBtCoexist.board_info.pg_ant_num == 2) && (GLBtCoexist.board_info.btdm_ant_num == 1)) GLBtCoexist.board_info.btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT; else GLBtCoexist.board_info.btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT; #endif } else if (BT_COEX_ANT_TYPE_ANTDIV == type) { GLBtCoexist.board_info.btdm_ant_num = antNum; /* GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT; */ } else if (BT_COEX_ANT_TYPE_DETECTED == type) { GLBtCoexist.board_info.btdm_ant_num = antNum; /* GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT; */ } } /* * Currently used by 8723b only, S0 or S1 * */ void EXhalbtcoutsrc_SetSingleAntPath(u8 singleAntPath) { GLBtCoexist.board_info.single_ant_path = singleAntPath; } void EXhalbtcoutsrc_DisplayBtCoexInfo(PBTC_COEXIST pBtCoexist) { HAL_DATA_TYPE *pHalData = NULL; if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) return; halbtcoutsrc_LeaveLowPower(pBtCoexist); /* To prevent the racing with IPS enter */ halbtcoutsrc_EnterPwrLock(pBtCoexist); #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1) pHalData = GET_HAL_DATA((PADAPTER)pBtCoexist->Adapter); if (pHalData->EEPROMBluetoothCoexist == _TRUE) rtw_btc_ex_display_coex_info(pBtCoexist); #else if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) { #ifdef CONFIG_RTL8821A if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8821a2ant_display_coex_info(pBtCoexist); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8821a1ant_display_coex_info(pBtCoexist); #endif } #ifdef CONFIG_RTL8723B else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8723b2ant_display_coex_info(pBtCoexist); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8723b1ant_display_coex_info(pBtCoexist); } #endif #ifdef CONFIG_RTL8703B else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8703b1ant_display_coex_info(pBtCoexist); } #endif #ifdef CONFIG_RTL8723D else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8723d2ant_display_coex_info(pBtCoexist); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8723d1ant_display_coex_info(pBtCoexist); } #endif #ifdef CONFIG_RTL8192E else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8192e2ant_display_coex_info(pBtCoexist); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8192e1ant_display_coex_info(pBtCoexist); } #endif #ifdef CONFIG_RTL8812A else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8812a2ant_display_coex_info(pBtCoexist); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8812a1ant_display_coex_info(pBtCoexist); } #endif #ifdef CONFIG_RTL8822B else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8822b1ant_display_coex_info(pBtCoexist); else if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8822b2ant_display_coex_info(pBtCoexist); } #endif #ifdef CONFIG_RTL8821C else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8821c2ant_display_coex_info(pBtCoexist); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8821c1ant_display_coex_info(pBtCoexist); } #endif #ifdef CONFIG_RTL8814A else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8814a2ant_display_coex_info(pBtCoexist); } #endif #endif halbtcoutsrc_ExitPwrLock(pBtCoexist); halbtcoutsrc_NormalLowPower(pBtCoexist); } void EXhalbtcoutsrc_DisplayAntDetection(PBTC_COEXIST pBtCoexist) { if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) return; halbtcoutsrc_LeaveLowPower(pBtCoexist); if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) { #ifdef CONFIG_RTL8723B if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8723b1ant_display_ant_detection(pBtCoexist); #endif } halbtcoutsrc_NormalLowPower(pBtCoexist); } void ex_halbtcoutsrc_pta_off_on_notify(PBTC_COEXIST pBtCoexist, u8 bBTON) { if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) { #ifdef CONFIG_RTL8812A if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8812a2ant_pta_off_on_notify(pBtCoexist, (bBTON == _TRUE) ? BTC_BT_ON : BTC_BT_OFF); #endif } #ifdef CONFIG_RTL8814A else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8814a2ant_pta_off_on_notify(pBtCoexist, (bBTON == _TRUE) ? BTC_BT_ON : BTC_BT_OFF); } #endif } void EXhalbtcoutsrc_set_rfe_type(u8 type) { GLBtCoexist.board_info.rfe_type= type; } #ifdef CONFIG_RF4CE_COEXIST void EXhalbtcoutsrc_set_rf4ce_link_state(u8 state) { GLBtCoexist.rf4ce_info.link_state = state; } u8 EXhalbtcoutsrc_get_rf4ce_link_state(void) { return GLBtCoexist.rf4ce_info.link_state; } #endif void EXhalbtcoutsrc_switchband_notify(struct btc_coexist *pBtCoexist, u8 type) { if(!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) return; if(pBtCoexist->manual_control) return; /* Driver should guarantee that the HW status isn't in low power mode */ /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */ #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1) rtw_btc_ex_switchband_notify(pBtCoexist, type); #else if(IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) { #ifdef CONFIG_RTL8822B if(pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8822b1ant_switchband_notify(pBtCoexist, type); else if(pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8822b2ant_switchband_notify(pBtCoexist, type); #endif } #ifdef CONFIG_RTL8821C else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8821c2ant_switchband_notify(pBtCoexist, type); else if (pBtCoexist->board_info.btdm_ant_num == 1) ex_halbtc8821c1ant_switchband_notify(pBtCoexist, type); } #endif #ifdef CONFIG_RTL8814A else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) { if (pBtCoexist->board_info.btdm_ant_num == 2) ex_halbtc8814a2ant_switchband_notify(pBtCoexist, type); } #endif #endif /* halbtcoutsrc_NormalLowPower(pBtCoexist); */ } u8 EXhalbtcoutsrc_rate_id_to_btc_rate_id(u8 rate_id) { u8 btc_rate_id = BTC_UNKNOWN; switch (rate_id) { /* CCK rates */ case DESC_RATE1M: btc_rate_id = BTC_CCK_1; break; case DESC_RATE2M: btc_rate_id = BTC_CCK_2; break; case DESC_RATE5_5M: btc_rate_id = BTC_CCK_5_5; break; case DESC_RATE11M: btc_rate_id = BTC_CCK_11; break; /* OFDM rates */ case DESC_RATE6M: btc_rate_id = BTC_OFDM_6; break; case DESC_RATE9M: btc_rate_id = BTC_OFDM_9; break; case DESC_RATE12M: btc_rate_id = BTC_OFDM_12; break; case DESC_RATE18M: btc_rate_id = BTC_OFDM_18; break; case DESC_RATE24M: btc_rate_id = BTC_OFDM_24; break; case DESC_RATE36M: btc_rate_id = BTC_OFDM_36; break; case DESC_RATE48M: btc_rate_id = BTC_OFDM_48; break; case DESC_RATE54M: btc_rate_id = BTC_OFDM_54; break; /* MCS rates */ case DESC_RATEMCS0: btc_rate_id = BTC_MCS_0; break; case DESC_RATEMCS1: btc_rate_id = BTC_MCS_1; break; case DESC_RATEMCS2: btc_rate_id = BTC_MCS_2; break; case DESC_RATEMCS3: btc_rate_id = BTC_MCS_3; break; case DESC_RATEMCS4: btc_rate_id = BTC_MCS_4; break; case DESC_RATEMCS5: btc_rate_id = BTC_MCS_5; break; case DESC_RATEMCS6: btc_rate_id = BTC_MCS_6; break; case DESC_RATEMCS7: btc_rate_id = BTC_MCS_7; break; case DESC_RATEMCS8: btc_rate_id = BTC_MCS_8; break; case DESC_RATEMCS9: btc_rate_id = BTC_MCS_9; break; case DESC_RATEMCS10: btc_rate_id = BTC_MCS_10; break; case DESC_RATEMCS11: btc_rate_id = BTC_MCS_11; break; case DESC_RATEMCS12: btc_rate_id = BTC_MCS_12; break; case DESC_RATEMCS13: btc_rate_id = BTC_MCS_13; break; case DESC_RATEMCS14: btc_rate_id = BTC_MCS_14; break; case DESC_RATEMCS15: btc_rate_id = BTC_MCS_15; break; case DESC_RATEMCS16: btc_rate_id = BTC_MCS_16; break; case DESC_RATEMCS17: btc_rate_id = BTC_MCS_17; break; case DESC_RATEMCS18: btc_rate_id = BTC_MCS_18; break; case DESC_RATEMCS19: btc_rate_id = BTC_MCS_19; break; case DESC_RATEMCS20: btc_rate_id = BTC_MCS_20; break; case DESC_RATEMCS21: btc_rate_id = BTC_MCS_21; break; case DESC_RATEMCS22: btc_rate_id = BTC_MCS_22; break; case DESC_RATEMCS23: btc_rate_id = BTC_MCS_23; break; case DESC_RATEMCS24: btc_rate_id = BTC_MCS_24; break; case DESC_RATEMCS25: btc_rate_id = BTC_MCS_25; break; case DESC_RATEMCS26: btc_rate_id = BTC_MCS_26; break; case DESC_RATEMCS27: btc_rate_id = BTC_MCS_27; break; case DESC_RATEMCS28: btc_rate_id = BTC_MCS_28; break; case DESC_RATEMCS29: btc_rate_id = BTC_MCS_29; break; case DESC_RATEMCS30: btc_rate_id = BTC_MCS_30; break; case DESC_RATEMCS31: btc_rate_id = BTC_MCS_31; break; case DESC_RATEVHTSS1MCS0: btc_rate_id = BTC_VHT_1SS_MCS_0; break; case DESC_RATEVHTSS1MCS1: btc_rate_id = BTC_VHT_1SS_MCS_1; break; case DESC_RATEVHTSS1MCS2: btc_rate_id = BTC_VHT_1SS_MCS_2; break; case DESC_RATEVHTSS1MCS3: btc_rate_id = BTC_VHT_1SS_MCS_3; break; case DESC_RATEVHTSS1MCS4: btc_rate_id = BTC_VHT_1SS_MCS_4; break; case DESC_RATEVHTSS1MCS5: btc_rate_id = BTC_VHT_1SS_MCS_5; break; case DESC_RATEVHTSS1MCS6: btc_rate_id = BTC_VHT_1SS_MCS_6; break; case DESC_RATEVHTSS1MCS7: btc_rate_id = BTC_VHT_1SS_MCS_7; break; case DESC_RATEVHTSS1MCS8: btc_rate_id = BTC_VHT_1SS_MCS_8; break; case DESC_RATEVHTSS1MCS9: btc_rate_id = BTC_VHT_1SS_MCS_9; break; case DESC_RATEVHTSS2MCS0: btc_rate_id = BTC_VHT_2SS_MCS_0; break; case DESC_RATEVHTSS2MCS1: btc_rate_id = BTC_VHT_2SS_MCS_1; break; case DESC_RATEVHTSS2MCS2: btc_rate_id = BTC_VHT_2SS_MCS_2; break; case DESC_RATEVHTSS2MCS3: btc_rate_id = BTC_VHT_2SS_MCS_3; break; case DESC_RATEVHTSS2MCS4: btc_rate_id = BTC_VHT_2SS_MCS_4; break; case DESC_RATEVHTSS2MCS5: btc_rate_id = BTC_VHT_2SS_MCS_5; break; case DESC_RATEVHTSS2MCS6: btc_rate_id = BTC_VHT_2SS_MCS_6; break; case DESC_RATEVHTSS2MCS7: btc_rate_id = BTC_VHT_2SS_MCS_7; break; case DESC_RATEVHTSS2MCS8: btc_rate_id = BTC_VHT_2SS_MCS_8; break; case DESC_RATEVHTSS2MCS9: btc_rate_id = BTC_VHT_2SS_MCS_9; break; case DESC_RATEVHTSS3MCS0: btc_rate_id = BTC_VHT_3SS_MCS_0; break; case DESC_RATEVHTSS3MCS1: btc_rate_id = BTC_VHT_3SS_MCS_1; break; case DESC_RATEVHTSS3MCS2: btc_rate_id = BTC_VHT_3SS_MCS_2; break; case DESC_RATEVHTSS3MCS3: btc_rate_id = BTC_VHT_3SS_MCS_3; break; case DESC_RATEVHTSS3MCS4: btc_rate_id = BTC_VHT_3SS_MCS_4; break; case DESC_RATEVHTSS3MCS5: btc_rate_id = BTC_VHT_3SS_MCS_5; break; case DESC_RATEVHTSS3MCS6: btc_rate_id = BTC_VHT_3SS_MCS_6; break; case DESC_RATEVHTSS3MCS7: btc_rate_id = BTC_VHT_3SS_MCS_7; break; case DESC_RATEVHTSS3MCS8: btc_rate_id = BTC_VHT_3SS_MCS_8; break; case DESC_RATEVHTSS3MCS9: btc_rate_id = BTC_VHT_3SS_MCS_9; break; case DESC_RATEVHTSS4MCS0: btc_rate_id = BTC_VHT_4SS_MCS_0; break; case DESC_RATEVHTSS4MCS1: btc_rate_id = BTC_VHT_4SS_MCS_1; break; case DESC_RATEVHTSS4MCS2: btc_rate_id = BTC_VHT_4SS_MCS_2; break; case DESC_RATEVHTSS4MCS3: btc_rate_id = BTC_VHT_4SS_MCS_3; break; case DESC_RATEVHTSS4MCS4: btc_rate_id = BTC_VHT_4SS_MCS_4; break; case DESC_RATEVHTSS4MCS5: btc_rate_id = BTC_VHT_4SS_MCS_5; break; case DESC_RATEVHTSS4MCS6: btc_rate_id = BTC_VHT_4SS_MCS_6; break; case DESC_RATEVHTSS4MCS7: btc_rate_id = BTC_VHT_4SS_MCS_7; break; case DESC_RATEVHTSS4MCS8: btc_rate_id = BTC_VHT_4SS_MCS_8; break; case DESC_RATEVHTSS4MCS9: btc_rate_id = BTC_VHT_4SS_MCS_9; break; } return btc_rate_id; } /* * Description: * Run BT-Coexist mechansim or not * */ void hal_btcoex_SetBTCoexist(PADAPTER padapter, u8 bBtExist) { PHAL_DATA_TYPE pHalData; pHalData = GET_HAL_DATA(padapter); pHalData->bt_coexist.bBtExist = bBtExist; } /* * Dewcription: * Check is co-exist mechanism enabled or not * * Return: * _TRUE Enable BT co-exist mechanism * _FALSE Disable BT co-exist mechanism */ u8 hal_btcoex_IsBtExist(PADAPTER padapter) { PHAL_DATA_TYPE pHalData; pHalData = GET_HAL_DATA(padapter); return pHalData->bt_coexist.bBtExist; } u8 hal_btcoex_IsBtDisabled(PADAPTER padapter) { if (!hal_btcoex_IsBtExist(padapter)) return _TRUE; if (GLBtCoexist.bt_info.bt_disabled) return _TRUE; else return _FALSE; } void hal_btcoex_SetChipType(PADAPTER padapter, u8 chipType) { PHAL_DATA_TYPE pHalData; pHalData = GET_HAL_DATA(padapter); pHalData->bt_coexist.btChipType = chipType; } void hal_btcoex_SetPgAntNum(PADAPTER padapter, u8 antNum) { PHAL_DATA_TYPE pHalData; pHalData = GET_HAL_DATA(padapter); pHalData->bt_coexist.btTotalAntNum = antNum; } u8 hal_btcoex_Initialize(PADAPTER padapter) { HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter); u8 ret; _rtw_memset(&GLBtCoexist, 0, sizeof(GLBtCoexist)); ret = EXhalbtcoutsrc_InitlizeVariables((void *)padapter); return ret; } void hal_btcoex_PowerOnSetting(PADAPTER padapter) { EXhalbtcoutsrc_PowerOnSetting(&GLBtCoexist); } void hal_btcoex_AntInfoSetting(PADAPTER padapter) { hal_btcoex_SetBTCoexist(padapter, rtw_btcoex_get_bt_coexist(padapter)); hal_btcoex_SetChipType(padapter, rtw_btcoex_get_chip_type(padapter)); hal_btcoex_SetPgAntNum(padapter, rtw_btcoex_get_pg_ant_num(padapter)); EXhalbtcoutsrc_AntInfoSetting(padapter); } void hal_btcoex_PowerOffSetting(PADAPTER padapter) { /* Clear the WiFi on/off bit in scoreboard reg. if necessary */ if (IS_HARDWARE_TYPE_8703B(padapter) || IS_HARDWARE_TYPE_8723D(padapter) || IS_HARDWARE_TYPE_8821C(padapter) || IS_HARDWARE_TYPE_8822B(padapter) || IS_HARDWARE_TYPE_8822C(padapter)) rtw_write16(padapter, 0xaa, 0x8000); } void hal_btcoex_PreLoadFirmware(PADAPTER padapter) { EXhalbtcoutsrc_PreLoadFirmware(&GLBtCoexist); } void hal_btcoex_InitHwConfig(PADAPTER padapter, u8 bWifiOnly) { if (!hal_btcoex_IsBtExist(padapter)) return; EXhalbtcoutsrc_init_hw_config(&GLBtCoexist, bWifiOnly); EXhalbtcoutsrc_init_coex_dm(&GLBtCoexist); } void hal_btcoex_IpsNotify(PADAPTER padapter, u8 type) { EXhalbtcoutsrc_ips_notify(&GLBtCoexist, type); } void hal_btcoex_LpsNotify(PADAPTER padapter, u8 type) { EXhalbtcoutsrc_lps_notify(&GLBtCoexist, type); } void hal_btcoex_ScanNotify(PADAPTER padapter, u8 type) { EXhalbtcoutsrc_scan_notify(&GLBtCoexist, type); } void hal_btcoex_ConnectNotify(PADAPTER padapter, u8 action) { u8 assoType = 0; u8 is_5g_band = _FALSE; is_5g_band = (padapter->mlmeextpriv.cur_channel > 14) ? _TRUE : _FALSE; if (action == _TRUE) { if (is_5g_band == _TRUE) assoType = BTC_ASSOCIATE_5G_START; else assoType = BTC_ASSOCIATE_START; } else { if (is_5g_band == _TRUE) assoType = BTC_ASSOCIATE_5G_FINISH; else assoType = BTC_ASSOCIATE_FINISH; } EXhalbtcoutsrc_connect_notify(&GLBtCoexist, assoType); } void hal_btcoex_MediaStatusNotify(PADAPTER padapter, u8 mediaStatus) { EXhalbtcoutsrc_media_status_notify(&GLBtCoexist, mediaStatus); } void hal_btcoex_SpecialPacketNotify(PADAPTER padapter, u8 pktType) { EXhalbtcoutsrc_specific_packet_notify(&GLBtCoexist, pktType); } void hal_btcoex_IQKNotify(PADAPTER padapter, u8 state) { GLBtcWiFiInIQKState = state; } void hal_btcoex_BtInfoNotify(PADAPTER padapter, u8 length, u8 *tmpBuf) { if (GLBtcWiFiInIQKState == _TRUE) return; EXhalbtcoutsrc_bt_info_notify(&GLBtCoexist, tmpBuf, length); } void hal_btcoex_BtMpRptNotify(PADAPTER padapter, u8 length, u8 *tmpBuf) { u8 extid, status, len, seq; if (GLBtcBtMpRptWait == _FALSE) return; if ((length < 3) || (!tmpBuf)) return; extid = tmpBuf[0]; /* not response from BT FW then exit*/ switch (extid) { case C2H_WIFI_FW_ACTIVE_RSP: GLBtcBtMpRptWiFiOK = _TRUE; break; case C2H_TRIG_BY_BT_FW: GLBtcBtMpRptBTOK = _TRUE; status = tmpBuf[1] & 0xF; len = length - 3; seq = tmpBuf[2] >> 4; GLBtcBtMpRptSeq = seq; GLBtcBtMpRptStatus = status; _rtw_memcpy(GLBtcBtMpRptRsp, tmpBuf + 3, len); GLBtcBtMpRptRspSize = len; break; default: return; } if ((GLBtcBtMpRptWiFiOK == _TRUE) && (GLBtcBtMpRptBTOK == _TRUE)) { GLBtcBtMpRptWait = _FALSE; _cancel_timer_ex(&GLBtcBtMpOperTimer); _rtw_up_sema(&GLBtcBtMpRptSema); } } void hal_btcoex_SuspendNotify(PADAPTER padapter, u8 state) { switch (state) { case BTCOEX_SUSPEND_STATE_SUSPEND: EXhalbtcoutsrc_pnp_notify(&GLBtCoexist, BTC_WIFI_PNP_SLEEP); break; case BTCOEX_SUSPEND_STATE_SUSPEND_KEEP_ANT: /* should switch to "#if 1" once all ICs' coex. revision are upgraded to support the KEEP_ANT case */ #if 0 EXhalbtcoutsrc_pnp_notify(&GLBtCoexist, BTC_WIFI_PNP_SLEEP_KEEP_ANT); #else EXhalbtcoutsrc_pnp_notify(&GLBtCoexist, BTC_WIFI_PNP_SLEEP); EXhalbtcoutsrc_pnp_notify(&GLBtCoexist, BTC_WIFI_PNP_SLEEP_KEEP_ANT); #endif break; case BTCOEX_SUSPEND_STATE_RESUME: #ifdef CONFIG_FW_MULTI_PORT_SUPPORT /* re-download FW after resume, inform WL FW port number */ rtw_hal_set_wifi_btc_port_id_cmd(GLBtCoexist.Adapter); #endif EXhalbtcoutsrc_pnp_notify(&GLBtCoexist, BTC_WIFI_PNP_WAKE_UP); break; } } void hal_btcoex_HaltNotify(PADAPTER padapter, u8 do_halt) { if (do_halt == 1) EXhalbtcoutsrc_halt_notify(&GLBtCoexist); GLBtCoexist.bBinded = _FALSE; GLBtCoexist.Adapter = NULL; } void hal_btcoex_SwitchBtTRxMask(PADAPTER padapter) { EXhalbtcoutsrc_SwitchBtTRxMask(&GLBtCoexist); } void hal_btcoex_Hanlder(PADAPTER padapter) { u32 bt_patch_ver; EXhalbtcoutsrc_periodical(&GLBtCoexist); if (GLBtCoexist.bt_info.bt_get_fw_ver == 0) { GLBtCoexist.btc_get(&GLBtCoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver); GLBtCoexist.bt_info.bt_get_fw_ver = bt_patch_ver; } } s32 hal_btcoex_IsBTCoexRejectAMPDU(PADAPTER padapter) { return (s32)GLBtCoexist.bt_info.reject_agg_pkt; } s32 hal_btcoex_IsBTCoexCtrlAMPDUSize(PADAPTER padapter) { return (s32)GLBtCoexist.bt_info.bt_ctrl_agg_buf_size; } u32 hal_btcoex_GetAMPDUSize(PADAPTER padapter) { return (u32)GLBtCoexist.bt_info.agg_buf_size; } void hal_btcoex_SetManualControl(PADAPTER padapter, u8 bmanual) { GLBtCoexist.manual_control = bmanual; } u8 hal_btcoex_1Ant(PADAPTER padapter) { if (hal_btcoex_IsBtExist(padapter) == _FALSE) return _FALSE; if (GLBtCoexist.board_info.btdm_ant_num == 1) return _TRUE; return _FALSE; } u8 hal_btcoex_IsBtControlLps(PADAPTER padapter) { if (GLBtCoexist.bdontenterLPS == _TRUE) return _TRUE; if (hal_btcoex_IsBtExist(padapter) == _FALSE) return _FALSE; if (GLBtCoexist.bt_info.bt_disabled) return _FALSE; if (GLBtCoexist.bt_info.bt_ctrl_lps) return _TRUE; return _FALSE; } u8 hal_btcoex_IsLpsOn(PADAPTER padapter) { if (GLBtCoexist.bdontenterLPS == _TRUE) return _FALSE; if (hal_btcoex_IsBtExist(padapter) == _FALSE) return _FALSE; if (GLBtCoexist.bt_info.bt_disabled) return _FALSE; if (GLBtCoexist.bt_info.bt_lps_on) return _TRUE; return _FALSE; } u8 hal_btcoex_RpwmVal(PADAPTER padapter) { return GLBtCoexist.bt_info.rpwm_val; } u8 hal_btcoex_LpsVal(PADAPTER padapter) { return GLBtCoexist.bt_info.lps_val; } u32 hal_btcoex_GetRaMask(PADAPTER padapter) { if (!hal_btcoex_IsBtExist(padapter)) return 0; if (GLBtCoexist.bt_info.bt_disabled) return 0; /* Modify by YiWei , suggest by Cosa and Jenyu * Remove the limit antenna number , because 2 antenna case (ex: 8192eu)also want to get BT coex report rate mask. */ /*if (GLBtCoexist.board_info.btdm_ant_num != 1) return 0;*/ return GLBtCoexist.bt_info.ra_mask; } u8 hal_btcoex_query_reduced_wl_pwr_lvl(PADAPTER padapter) { return GLBtCoexist.coex_dm.cur_wl_pwr_lvl; } void hal_btcoex_set_reduced_wl_pwr_lvl(PADAPTER padapter, u8 val) { GLBtCoexist.coex_dm.cur_wl_pwr_lvl = val; } void hal_btcoex_do_reduce_wl_pwr_lvl(PADAPTER padapter) { halbtcoutsrc_reduce_wl_tx_power(&GLBtCoexist, 0); } void hal_btcoex_RecordPwrMode(PADAPTER padapter, u8 *pCmdBuf, u8 cmdLen) { _rtw_memcpy(GLBtCoexist.pwrModeVal, pCmdBuf, cmdLen); } void hal_btcoex_DisplayBtCoexInfo(PADAPTER padapter, u8 *pbuf, u32 bufsize) { PBTCDBGINFO pinfo; pinfo = &GLBtcDbgInfo; DBG_BT_INFO_INIT(pinfo, pbuf, bufsize); EXhalbtcoutsrc_DisplayBtCoexInfo(&GLBtCoexist); DBG_BT_INFO_INIT(pinfo, NULL, 0); } void hal_btcoex_SetDBG(PADAPTER padapter, u32 *pDbgModule) { u32 i; if (NULL == pDbgModule) return; for (i = 0; i < COMP_MAX; i++) GLBtcDbgType[i] = pDbgModule[i]; } u32 hal_btcoex_GetDBG(PADAPTER padapter, u8 *pStrBuf, u32 bufSize) { s32 count; u8 *pstr; u32 leftSize; if ((NULL == pStrBuf) || (0 == bufSize)) return 0; count = 0; pstr = pStrBuf; leftSize = bufSize; /* RTW_INFO(FUNC_ADPT_FMT ": bufsize=%d\n", FUNC_ADPT_ARG(padapter), bufSize); */ count = rtw_sprintf(pstr, leftSize, "#define DBG\t%d\n", DBG); if ((count < 0) || (count >= leftSize)) goto exit; pstr += count; leftSize -= count; count = rtw_sprintf(pstr, leftSize, "BTCOEX Debug Setting:\n"); if ((count < 0) || (count >= leftSize)) goto exit; pstr += count; leftSize -= count; count = rtw_sprintf(pstr, leftSize, "COMP_COEX: 0x%08X\n\n", GLBtcDbgType[COMP_COEX]); if ((count < 0) || (count >= leftSize)) goto exit; pstr += count; leftSize -= count; #if 0 count = rtw_sprintf(pstr, leftSize, "INTERFACE Debug Setting Definition:\n"); if ((count < 0) || (count >= leftSize)) goto exit; pstr += count; leftSize -= count; count = rtw_sprintf(pstr, leftSize, "\tbit[0]=%d for INTF_INIT\n", GLBtcDbgType[BTC_MSG_INTERFACE] & INTF_INIT ? 1 : 0); if ((count < 0) || (count >= leftSize)) goto exit; pstr += count; leftSize -= count; count = rtw_sprintf(pstr, leftSize, "\tbit[2]=%d for INTF_NOTIFY\n\n", GLBtcDbgType[BTC_MSG_INTERFACE] & INTF_NOTIFY ? 1 : 0); if ((count < 0) || (count >= leftSize)) goto exit; pstr += count; leftSize -= count; count = rtw_sprintf(pstr, leftSize, "ALGORITHM Debug Setting Definition:\n"); if ((count < 0) || (count >= leftSize)) goto exit; pstr += count; leftSize -= count; count = rtw_sprintf(pstr, leftSize, "\tbit[0]=%d for BT_RSSI_STATE\n", GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_BT_RSSI_STATE ? 1 : 0); if ((count < 0) || (count >= leftSize)) goto exit; pstr += count; leftSize -= count; count = rtw_sprintf(pstr, leftSize, "\tbit[1]=%d for WIFI_RSSI_STATE\n", GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_WIFI_RSSI_STATE ? 1 : 0); if ((count < 0) || (count >= leftSize)) goto exit; pstr += count; leftSize -= count; count = rtw_sprintf(pstr, leftSize, "\tbit[2]=%d for BT_MONITOR\n", GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_BT_MONITOR ? 1 : 0); if ((count < 0) || (count >= leftSize)) goto exit; pstr += count; leftSize -= count; count = rtw_sprintf(pstr, leftSize, "\tbit[3]=%d for TRACE\n", GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE ? 1 : 0); if ((count < 0) || (count >= leftSize)) goto exit; pstr += count; leftSize -= count; count = rtw_sprintf(pstr, leftSize, "\tbit[4]=%d for TRACE_FW\n", GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE_FW ? 1 : 0); if ((count < 0) || (count >= leftSize)) goto exit; pstr += count; leftSize -= count; count = rtw_sprintf(pstr, leftSize, "\tbit[5]=%d for TRACE_FW_DETAIL\n", GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE_FW_DETAIL ? 1 : 0); if ((count < 0) || (count >= leftSize)) goto exit; pstr += count; leftSize -= count; count = rtw_sprintf(pstr, leftSize, "\tbit[6]=%d for TRACE_FW_EXEC\n", GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE_FW_EXEC ? 1 : 0); if ((count < 0) || (count >= leftSize)) goto exit; pstr += count; leftSize -= count; count = rtw_sprintf(pstr, leftSize, "\tbit[7]=%d for TRACE_SW\n", GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE_SW ? 1 : 0); if ((count < 0) || (count >= leftSize)) goto exit; pstr += count; leftSize -= count; count = rtw_sprintf(pstr, leftSize, "\tbit[8]=%d for TRACE_SW_DETAIL\n", GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE_SW_DETAIL ? 1 : 0); if ((count < 0) || (count >= leftSize)) goto exit; pstr += count; leftSize -= count; count = rtw_sprintf(pstr, leftSize, "\tbit[9]=%d for TRACE_SW_EXEC\n", GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE_SW_EXEC ? 1 : 0); if ((count < 0) || (count >= leftSize)) goto exit; pstr += count; leftSize -= count; #endif exit: count = pstr - pStrBuf; /* RTW_INFO(FUNC_ADPT_FMT ": usedsize=%d\n", FUNC_ADPT_ARG(padapter), count); */ return count; } u8 hal_btcoex_IncreaseScanDeviceNum(PADAPTER padapter) { if (!hal_btcoex_IsBtExist(padapter)) return _FALSE; if (GLBtCoexist.bt_info.increase_scan_dev_num) return _TRUE; return _FALSE; } u8 hal_btcoex_IsBtLinkExist(PADAPTER padapter) { if (GLBtCoexist.bt_link_info.bt_link_exist) return _TRUE; return _FALSE; } void hal_btcoex_SetBtPatchVersion(PADAPTER padapter, u16 btHciVer, u16 btPatchVer) { EXhalbtcoutsrc_SetBtPatchVersion(btHciVer, btPatchVer); } void hal_btcoex_SetHciVersion(PADAPTER padapter, u16 hciVersion) { EXhalbtcoutsrc_SetHciVersion(hciVersion); } void hal_btcoex_StackUpdateProfileInfo(void) { EXhalbtcoutsrc_StackUpdateProfileInfo(); } void hal_btcoex_pta_off_on_notify(PADAPTER padapter, u8 bBTON) { ex_halbtcoutsrc_pta_off_on_notify(&GLBtCoexist, bBTON); } /* * Description: * Setting BT coex antenna isolation type . * coex mechanisn/ spital stream/ best throughput * anttype = 0 , PSTDMA / 2SS / 0.5T , bad isolation , WiFi/BT ANT Distance<15cm , (<20dB) for 2,3 antenna * anttype = 1 , PSTDMA / 1SS / 0.5T , normal isolaiton , 50cm>WiFi/BT ANT Distance>15cm , (>20dB) for 2 antenna * anttype = 2 , TDMA / 2SS / T , normal isolaiton , 50cm>WiFi/BT ANT Distance>15cm , (>20dB) for 3 antenna * anttype = 3 , no TDMA / 1SS / 0.5T , good isolation , WiFi/BT ANT Distance >50cm , (>40dB) for 2 antenna * anttype = 4 , no TDMA / 2SS / T , good isolation , WiFi/BT ANT Distance >50cm , (>40dB) for 3 antenna * wifi only throughput ~ T * wifi/BT share one antenna with SPDT */ void hal_btcoex_SetAntIsolationType(PADAPTER padapter, u8 anttype) { PHAL_DATA_TYPE pHalData; PBTC_COEXIST pBtCoexist = &GLBtCoexist; /*RTW_INFO("####%s , anttype = %d , %d\n" , __func__ , anttype , __LINE__); */ pHalData = GET_HAL_DATA(padapter); pHalData->bt_coexist.btAntisolation = anttype; switch (pHalData->bt_coexist.btAntisolation) { case 0: pBtCoexist->board_info.ant_type = (u8)BTC_ANT_TYPE_0; break; case 1: pBtCoexist->board_info.ant_type = (u8)BTC_ANT_TYPE_1; break; case 2: pBtCoexist->board_info.ant_type = (u8)BTC_ANT_TYPE_2; break; case 3: pBtCoexist->board_info.ant_type = (u8)BTC_ANT_TYPE_3; break; case 4: pBtCoexist->board_info.ant_type = (u8)BTC_ANT_TYPE_4; break; } } #ifdef CONFIG_LOAD_PHY_PARA_FROM_FILE int hal_btcoex_ParseAntIsolationConfigFile( PADAPTER Adapter, char *buffer ) { HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter); u32 i = 0 , j = 0; char *szLine , *ptmp; int rtStatus = _SUCCESS; char param_value_string[10]; u8 param_value; u8 anttype = 4; u8 ant_num = 3 , ant_distance = 50 , rfe_type = 1; typedef struct ant_isolation { char *param_name; /* antenna isolation config parameter name */ u8 *value; /* antenna isolation config parameter value */ } ANT_ISOLATION; ANT_ISOLATION ant_isolation_param[] = { {"ANT_NUMBER" , &ant_num}, {"ANT_DISTANCE" , &ant_distance}, {"RFE_TYPE" , &rfe_type}, {NULL , 0} }; /* RTW_INFO("===>Hal_ParseAntIsolationConfigFile()\n" ); */ ptmp = buffer; for (szLine = GetLineFromBuffer(ptmp) ; szLine != NULL; szLine = GetLineFromBuffer(ptmp)) { /* skip comment */ if (IsCommentString(szLine)) continue; /* RTW_INFO("%s : szLine = %s , strlen(szLine) = %d\n" , __func__ , szLine , strlen(szLine));*/ for (j = 0 ; ant_isolation_param[j].param_name != NULL ; j++) { if (strstr(szLine , ant_isolation_param[j].param_name) != NULL) { i = 0; while (i < strlen(szLine)) { if (szLine[i] != '"') ++i; else { /* skip only has one " */ if (strpbrk(szLine , "\"") == strrchr(szLine , '"')) { RTW_INFO("Fail to parse parameters , format error!\n"); break; } _rtw_memset((void *)param_value_string , 0 , 10); if (!ParseQualifiedString(szLine , &i , param_value_string , '"' , '"')) { RTW_INFO("Fail to parse parameters\n"); return _FAIL; } else if (!GetU1ByteIntegerFromStringInDecimal(param_value_string , ant_isolation_param[j].value)) RTW_INFO("Fail to GetU1ByteIntegerFromStringInDecimal\n"); break; } } } } } /* YiWei 20140716 , for BT coex antenna isolation control */ /* rfe_type = 0 was SPDT , rfe_type = 1 was coupler */ if (ant_num == 3 && ant_distance >= 50) anttype = 3; else if (ant_num == 2 && ant_distance >= 50 && rfe_type == 1) anttype = 2; else if (ant_num == 3 && ant_distance >= 15 && ant_distance < 50) anttype = 2; else if (ant_num == 2 && ant_distance >= 15 && ant_distance < 50 && rfe_type == 1) anttype = 2; else if ((ant_num == 2 && ant_distance < 15 && rfe_type == 1) || (ant_num == 3 && ant_distance < 15)) anttype = 1; else if (ant_num == 2 && rfe_type == 0) anttype = 0; else anttype = 0; hal_btcoex_SetAntIsolationType(Adapter, anttype); RTW_INFO("%s : ant_num = %d\n" , __func__ , ant_num); RTW_INFO("%s : ant_distance = %d\n" , __func__ , ant_distance); RTW_INFO("%s : rfe_type = %d\n" , __func__ , rfe_type); /* RTW_INFO("<===Hal_ParseAntIsolationConfigFile()\n"); */ return rtStatus; } int hal_btcoex_AntIsolationConfig_ParaFile( PADAPTER Adapter, char *pFileName ) { HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter); int rlen = 0 , rtStatus = _FAIL; _rtw_memset(pHalData->para_file_buf , 0 , MAX_PARA_FILE_BUF_LEN); rtw_get_phy_file_path(Adapter, pFileName); if (rtw_is_file_readable(rtw_phy_para_file_path) == _TRUE) { rlen = rtw_retrieve_from_file(rtw_phy_para_file_path, pHalData->para_file_buf, MAX_PARA_FILE_BUF_LEN); if (rlen > 0) rtStatus = _SUCCESS; } if (rtStatus == _SUCCESS) { /*RTW_INFO("%s(): read %s ok\n", __func__ , pFileName);*/ rtStatus = hal_btcoex_ParseAntIsolationConfigFile(Adapter , pHalData->para_file_buf); } else RTW_INFO("%s(): No File %s, Load from *** Array!\n" , __func__ , pFileName); return rtStatus; } #endif /* CONFIG_LOAD_PHY_PARA_FROM_FILE */ u16 hal_btcoex_btreg_read(PADAPTER padapter, u8 type, u16 addr, u32 *data) { u16 ret = 0; halbtcoutsrc_LeaveLowPower(&GLBtCoexist); ret = halbtcoutsrc_GetBtReg_with_status(&GLBtCoexist, type, addr, data); halbtcoutsrc_NormalLowPower(&GLBtCoexist); return ret; } u16 hal_btcoex_btreg_write(PADAPTER padapter, u8 type, u16 addr, u16 val) { u16 ret = 0; halbtcoutsrc_LeaveLowPower(&GLBtCoexist); ret = halbtcoutsrc_SetBtReg(&GLBtCoexist, type, addr, val); halbtcoutsrc_NormalLowPower(&GLBtCoexist); return ret; } void hal_btcoex_set_rfe_type(u8 type) { EXhalbtcoutsrc_set_rfe_type(type); } #ifdef CONFIG_RF4CE_COEXIST void hal_btcoex_set_rf4ce_link_state(u8 state) { EXhalbtcoutsrc_set_rf4ce_link_state(state); } u8 hal_btcoex_get_rf4ce_link_state(void) { return EXhalbtcoutsrc_get_rf4ce_link_state(); } #endif /* CONFIG_RF4CE_COEXIST */ void hal_btcoex_switchband_notify(u8 under_scan, u8 band_type) { switch (band_type) { case BAND_ON_2_4G: if (under_scan) EXhalbtcoutsrc_switchband_notify(&GLBtCoexist, BTC_SWITCH_TO_24G); else EXhalbtcoutsrc_switchband_notify(&GLBtCoexist, BTC_SWITCH_TO_24G_NOFORSCAN); break; case BAND_ON_5G: EXhalbtcoutsrc_switchband_notify(&GLBtCoexist, BTC_SWITCH_TO_5G); break; default: RTW_INFO("[BTCOEX] unkown switch band type\n"); break; } } void hal_btcoex_WlFwDbgInfoNotify(PADAPTER padapter, u8* tmpBuf, u8 length) { EXhalbtcoutsrc_WlFwDbgInfoNotify(&GLBtCoexist, tmpBuf, length); } void hal_btcoex_rx_rate_change_notify(PADAPTER padapter, u8 is_data_frame, u8 rate_id) { EXhalbtcoutsrc_rx_rate_change_notify(&GLBtCoexist, is_data_frame, EXhalbtcoutsrc_rate_id_to_btc_rate_id(rate_id)); } u16 hal_btcoex_btset_testode(PADAPTER padapter, u8 type) { u16 ret = 0; halbtcoutsrc_LeaveLowPower(&GLBtCoexist); ret = halbtcoutsrc_setbttestmode(&GLBtCoexist, type); halbtcoutsrc_NormalLowPower(&GLBtCoexist); return ret; } #endif /* CONFIG_BT_COEXIST */
the_stack_data/71804.c
#include <stdio.h> int main() { char code = 'A'; printf("%d %d %d \n", code, code + 1, code + 2); printf("%c %c %c \n", code, code + 1, code + 2); return 0; }
the_stack_data/137339.c
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/sem.h> #include <sys/types.h> #include <sys/ipc.h> //#include "semun.h" union semun { int val; struct semid_ds *buf; unsigned short *array; }; static int set_sem_val(); static void del_sem_val(); static int semaphore_p(); static int semaphore_v(); static int sem_id; int main(int argc, char* argv) { int pause = 0; char word = '0'; srand((unsigned) getpid()); sem_id = semget((key_t)111, 1, 0666 | IPC_CREAT); if(argc > 1) { if(!set_sem_val()) { printf("set semaphor 1 error\n"); exit(EXIT_FAILURE); } word = '1'; sleep(3); } for(int i = 10; i > 0; i--) { if(!semaphore_p()) { fprintf(stderr,"P operation error\n"); exit(EXIT_FAILURE); } printf("%c", word); fflush(stdout); pause = rand() % 3; sleep(pause); printf("%c", word); fflush(stdout); if(!semaphore_v()) { fprintf(stderr, "V operation error\n"); exit(EXIT_FAILURE); } pause = rand() % 5; sleep(pause); } printf("\n %d finished\n", getpid()); if(argc > 1) { sleep(10); del_sem_val(); } exit(0); } static int set_sem_val() { union semun sem_union; sem_union.val = 1; if(semctl(sem_id, 0, SETVAL, sem_union) == -1) return 0; return 1; } static void del_sem_val() { union semun sem_union; if(semctl(sem_id, 0, IPC_RMID, sem_union) == -1) printf("error del semaphor!\n"); } static int semaphore_p() { struct sembuf sem_buf; sem_buf.sem_num = 0; sem_buf.sem_op = -1; sem_buf.sem_flg = SEM_UNDO; if(semop(sem_id, &sem_buf, 1) == -1) return 0; return 1; } static int semaphore_v() { struct sembuf sem_buf; sem_buf.sem_num = 0; sem_buf.sem_op = 1; sem_buf.sem_flg = SEM_UNDO; if(semop(sem_id, &sem_buf, 1) == -1) { return 0; } return 1; }
the_stack_data/36074334.c
/** * rammstring.c * * Search for a word/letter sequence * in a non-continuous 'stream' of bytes. * * $ gcc match.c -o match * * Ex: * ./match a * ./match kein * ./match trägtMuss * ./match ' ' * * - hash */ #include <stdio.h> #include <string.h> #include <stdlib.h> #include <time.h> #include <assert.h> /* 'Rammstring' */ static const char was_ich_liebe[] = "Ich kann auf Glück verzichten" "Weil es Unglück in sich trägt" "Muss ich es vernichten" "Was ich liebe, will ich richten" "Dass ich froh bin, darf nicht sein" "Nein (nein, nein)" "Ich liebe nicht, dass ich was liebe" "Ich mag es nicht, wenn ich was mag" "Ich freu' mich nicht, wenn ich mich freue" "Weiß ich doch, ich werde es bereuen" "Dass ich froh bin, darf nicht sein" "Wer mich liebt, geht dabei ein" "Was ich liebe" "Das wird verderben" "Was ich liebe" "Das muss auch sterben, muss sterben" "So halte ich mich schadlos" "Lieben darf ich nicht" "Dann brauch' ich nicht zu leiden (nein)" "Und kein Herz zerbricht" "Dass ich froh bin, darf nicht sein" "Nein (nein, nein)" "Was ich liebe" "Das wird verderben" "Was ich liebe" "Das muss auch sterben, muss sterben" "Auf Glück und Freude" "Folgen Qualen" "Für alles Schöne" "Muss man zahlen, ja" "Was ich liebe" "Das wird verderben" "Was ich liebe" "Das muss auch sterben, muss sterben" "Was ich liebe"; /** * Pretend this is recv() * It returns the number of bytes * written in given buffer, which is * null-terminated. * 'trust' chunk can hold the bytes */ static int my_recv(char *chunk, size_t *remaining) { static int pos; int written = 0; if (*remaining <= 0) *chunk = 0; else { written = (rand() % *remaining - 1 + 1 /* min 1 char */) + 1; memcpy(chunk, &was_ich_liebe[pos], written); chunk[written] = '\0'; pos += written; *remaining -= written; } return written; } static int find_sequence(char *input, char *chunk, size_t len) { int rval = 0; for (int i = 0; i < len; ++i) { static int count; if (chunk[i] == input[count]) { /* have we found a full sequence? */ if (count+1 == strlen(input)) { count = 0; rval++; } else /* looks promising.. */ count++; } else count = 0; } return rval; } int main(int argc, char **argv) { if (argc < 2) { fprintf(stdout, "%s\n", was_ich_liebe); exit(0); } size_t remaining = strlen(was_ich_liebe); int total = 0, found = 0; char *input = argv[1]; char buf[remaining+1]; /* setup the seed */ srand(time(NULL)); while (remaining > 0) { int written = my_recv(buf, &remaining); if (written) { fprintf(stdout, "\t{len %d} %s\n", written, buf); total += written; found += find_sequence(input, buf, written); } } fprintf(stdout, "\nFound %d entries for '%s'\n", found, input); return 0; }
the_stack_data/98575543.c
int ft_sqrt(int nb) { int i; i = 0; if (nb == 1) return (1); while (i < nb) { if (i * i == nb) return (i); i++; } return (0); }
the_stack_data/28263574.c
#include <stdint.h> #include <unistd.h> #include <stdio.h> #include <string.h> #include <errno.h> #include <sys/syscall.h> #include <signal.h> #include <limits.h> #include <math.h> #include <crypt.h> #include <stdlib.h> int cmp (const void *a, const void *b) { return isgreater(*(float *)a, *(float *)b) ? 1 : (isless(*(float *)a, *(float *)b) ? -1 : 0); } /* const char *c = "return isgreater(*(float *)a, *(float *)b) ? 1 : (isless(*(float *)a, *(float *)b) ? -1 : 0);"; */ /* char c[] = { 0x74, 0x75, 0x72, 0x6e, 0x20, 0x69, 0x73, 0x67, 0x72, 0x65, 0x61, 0x74, 0x65, 0x72, 0x28, 0x2a, 0x28, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x20, 0x2a, 0x29, 0x61, 0x2c, 0x20, 0x2a, 0x28, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x20, 0x2a, 0x29, 0x62, 0x29, 0x20, 0x3f, 0x20, 0x31, 0x20, 0x3a, 0x20, 0x28, 0x69, 0x73, 0x6c, 0x65, 0x73, 0x73, 0x28, 0x2a, 0x28, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x20, 0x2a, 0x29, 0x61, 0x2c, 0x20, 0x2a, 0x28, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x20, 0x2a, 0x29, 0x62, 0x29, 0x20, 0x3f, 0x20, 0x2d, 0x31, 0x20, 0x3a, 0x20, 0x30, 0x29, 0x3b, 0x00 }; */ int main(int argc, char **argv) { float a[] = { 1.1f, 1.4f, 1.2f, 1.0f, 0.5f, 3.2f, 0.1f }; /* float j = 1.0f, k = 0.4f; */ /* int (*b)(const void*, const void*) = (int (*)(const void*, const void*))c; */ int (*b)(const void*, const void*) = &cmp; /* printf("%p\n", (((*(int (*)())&c[0])))); */ qsort(a, sizeof a/sizeof a[0], sizeof a[0], b); for (unsigned i=0; i<(sizeof a)/(sizeof a[0]); i++) printf("%.1f\n", a[i]); return 0; }
the_stack_data/248579739.c
#include <stdio.h> #include <stdlib.h> /* Author : #YUbuntu Description : Create the binary tree using the # sign method Date : December 19,2018 */ //Definde the struct of binary tree typedef struct BitNode { char data; struct BitNode *lchild, *rchild; } BitNode; //inorder traversing static void inOrder(BitNode *T) { if (T == NULL) { return; } //The left branch of the tree if (T->lchild != NULL) { inOrder(T->lchild); } //The root node of tree printf("%c", T->data); //The right brance of the tree if (T->rchild != NULL) { inOrder(T->rchild); } } //Create the binary tree using the # sign method BitNode *BitNode_Create() { BitNode *temp = NULL; char ch; scanf("%c", &ch); if (ch == '#') { temp = NULL; return temp; } else { temp = (BitNode *)malloc(sizeof(BitNode)); if (temp == NULL) { return NULL; } temp->data = ch; temp->lchild = NULL; temp->rchild = NULL; //Create the left and right subtrees of the root node. temp->lchild = BitNode_Create(); temp->rchild = BitNode_Create(); return temp; } } //Release the binary tree static void BitNode_Free(BitNode *T) { if (T == NULL) { return; } //Release the reource of left branch of the tree if (T->lchild != NULL) { BitNode_Free(T->lchild); T->lchild = NULL; } //Release the resource of right branch of the tree if (T->rchild != NULL) { BitNode_Free(T->rchild); T->rchild = NULL; } //Realase the root node of binary tree last. free(T); } //Test the program int main(int argc, char const *argv[]) { BitNode *T = NULL; printf("Please enter the element value of binary tree : \n"); //Create the binary tree firstly T = BitNode_Create(); //Inorder traversing printf("The result as inordering traversing as follow :\n"); inOrder(T); printf("\n"); //Release the source of the binary tree BitNode_Free(T); printf("Have released the source of the binary tree ! \n"); //stady the console system("pause"); return 0; }
the_stack_data/1066453.c
/* Copyright (C) 2011-2019 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <[email protected]>, 2011. The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. The GNU C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with the GNU C Library; if not, see <http://www.gnu.org/licenses/>. */ #include <uchar.h> #include <wchar.h> /* This is the private state used if PS is NULL. */ static mbstate_t state; size_t c16rtomb(char* s, char16_t c16, mbstate_t* ps) { wchar_t wc = c16; if (ps == NULL) ps = &state; if (s == NULL) { /* Reset any state relating to surrogate pairs. */ ps->__count &= 0x7fffffff; ps->__value.__wch = 0; wc = 0; } if (ps->__count & 0x80000000) { /* The previous call passed in the first surrogate of a surrogate pair. */ ps->__count &= 0x7fffffff; if (wc >= 0xdc00 && wc < 0xe000) wc = (0x10000 + ((ps->__value.__wch & 0x3ff) << 10) + (wc & 0x3ff)); else /* This is not a low surrogate; ensure an EILSEQ error by trying to decode the high surrogate as a wide character on its own. */ wc = ps->__value.__wch; ps->__value.__wch = 0; } else if (wc >= 0xd800 && wc < 0xdc00) { /* The high part of a surrogate pair. */ ps->__count |= 0x80000000; ps->__value.__wch = wc; return 0; } return wcrtomb(s, wc, ps); }
the_stack_data/12636521.c
int main() { // variable declarations int sn; int x; // pre-conditions (sn = 0); (x = 0); // loop body while (unknown()) { { (x = (x + 1)); (sn = (sn + 1)); } } // post-condition if ( (sn != -1) ) assert( (sn == x) ); }
the_stack_data/55199.c
/****************************************************************/ /* PROGRAM NAME: lab1.c */ /* DESCRIPTION: This lab assignment introduces C syntax and use of */ /* command line arguments */ /****************************************************************/ # include <stdio.h> # include <stdlib.h> //argc is the number of arguments, argv is the array of arguments int main(int argc, char *argv[]) { //Our array of randomly given integer arguments //Assignment says we need to name the array randA //Size shall be the number of arguments (-1 since the first argument is file name) //However + 3 to store the largest, smallest, and average values at the end of array //so, + 2 int randA[argc + 2]; //Check and make sure we have at least two arguments if (argc < 2) { printf("\n %s Usage: Need filename and any number of following integer arguments from -100 and 100\n", argv[0]); exit(1); } //Create our variables to store smallest, largets, and average int large; int small; int average; int count = 0; int sumTotal = 0; //Start looping through and grabbing integers int i; for(i = 1; i < argc; ++i) { //First grab the string int inputInt = atoi(argv[i]); //check if it is less than -100 //or greater than 100 if(inputInt < -100 || inputInt > 100) { //Inform the user printf("/nSorry, only values from -100 to 100 are accepted. Continuing execution...\n"); } else { //Add it to the array randA[i - 1] = inputInt; //increase our count ++count; //Add the input int to our sum sumTotal = sumTotal + inputInt; //Next check if it is the smalles or the largest //But automatically assign if it is the first run through if(i == 1) { //assign all of our variables to the first value small = inputInt; large = inputInt; average = inputInt; } else { //It is not first index so we need to compare things if(inputInt < small) { small = inputInt; } else if(inputInt > large) { large = inputInt; } } } } //Now we are done looping, we can calculate our true average average = sumTotal / count; //now we need to assign our values to the end of the array //May have null variables to the end, but use count for indexes and we wont attempt //to acces those randA[count - 1] = large; randA[count] = small; randA[count + 1] = average; //output our results printf("\nLargest value is: %i, At randA index: %i\n", randA[count - 1], count - 1); printf("\nSmallest value is: %i, At randA index: %i\n", randA[count], count); printf("\nAverage of the values is: %i, At randA index: %i\n", randA[count + 1], count + 1); //Finish up and exit printf ("\n"); printf("\nThank you! Have a nice day!\n"); printf ("\n"); exit(0); }
the_stack_data/93011.c
/*******************************************\ * DERSIN ADI: ALGORITMA VE PROGRAMLAMA 2 * * PROJE ADI: Futbol Ligi Takip Sistemi v2 * * * * PROJE YAZAN KISILER: * * EROLL RAMAXHIK - 05 10 0000 901 * * SELIM AGOVIC - 05 11 0000 797 * * ONUR PALA - 05 10 0000 871 * \*******************************************/ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #define YIRMI 21 #define YUZ 100 struct OYUNCU { int t_kod; /// TAKIMIN KODU int f_no; /// FUTBOLCUNUN FORMA NUMARASI char f_ad[YIRMI]; /// FUTBOLCUNUN AD VE SOYAD int a_gol; /// FUTBOLCUNUN ATTIGI GOL struct OYUNCU *sonraki; /// POINTER SONRAKI OYUNCU ICIN }; struct TAKIM { int t_kod; /// TAKIMIN KODU char t_ad[YIRMI]; /// TAKIMI ADI int g_say; /// TAKIMIN GALIBIYET SAYISI int b_say; /// TAKIMIN BERABERLIK SAYISI int m_say; /// TAKIMIN MAGLUBIYET SAYISI int a_gol; /// TAKIMIN ATTIGI GOL SAYISI int y_gol; /// TAKIMIN YEDIGI GOL SAYISI struct OYUNCU *sonraki_oyuncu; /// TAKIMDA FUTBOLCUNUN SONRAKI DUGUM struct SKORLAR *sonraki_hafta; /// TAKIMDA SKORLARIN SONRAKI DUGUM }; struct SKORLAR { int h_no; /// SKORLARIN HAFTA NUMARASI int ev_kod; /// SKORLARIN EV SAHIBI TAKIMIN KODU int mis_kod; /// SKORLARIN MISAFIRIN TAKIMIN KODU int ev_gol; /// SKORLARIN EV SAHIBI ATTIGI GOL SAYISI int mis_gol; /// KORLARIN MISAFIRIN ATTIGI GOL SAYISI struct SKORLAR *sonraki;/// POINTER SONRAKI SKOR ICIN }; /// FONKSYON PROTOTIPLERI void goster_takim() { printf("\n\tTakim Kod Takim Adi OO GG BB MM AA YY AVR Puan"); printf("\n\t--------- --------------------- -- -- -- -- -- -- --- ----"); } void goster_takim_ve_oyuncu() { printf("\n\tTakim Kod Takim Adi Forma no Ad Soyad AA"); printf("\n\t--------- --------------------- -------- -------------------- --"); } void goster_Oyuncu() { printf("\n\tFutbolcu Bilgileri:"); printf("\n\tForma No Ad Soyad AA"); printf("\n\t-------- -------------------- --"); } void goster_skorlar() { printf("\n\tOynadigi maclarin skorlari:\n"); printf("\n\t EV SAHIBI MISAFIR"); printf("\n\tHAFTA TAKIM ADI TAKIM ADI"); printf("\n\t----- -------------------- -- -- --------------------"); } void goster1(); void goster2() { int i,j; char metin[]="PROGRAM BASARILIYLA SONLANDIRILDI"; printf("\n\n"); j=0; printf("\t"); for (;;) { for(i=0; i<100000; i++); for(i=0; i<1000000; i++); printf("%c",metin[j]); j++; if (j==strlen(metin)) { printf(" "); break; } } } int menu(void); int sil_oyuncu(struct OYUNCU *,int, struct TAKIM *[],int); void yazdir_oyuncu(struct OYUNCU *); int main() { /// system("title Futbol Ligi Takip Sistemi v2"); system("color a"); struct TAKIM *team[YUZ] = {NULL}; /// 100 DIZILIK STRUCT OLUSTURULUR int fno,ikinci_fno,kontrol; struct OYUNCU *futBilgi,*onceki,*simdiki,*yeni_futbolcu,*gecici,*temp; char aranan_takim[YIRMI],cvp,max_ad[21]; /// DEGISKENLER BELIRLENIR struct SKORLAR *skor,*onceki_skor,*simdiki_skor; /// ARAMA YAPMAK ICIN EKLENIR struct SKORLAR *skor2,*onceki_skor2,*simdiki_skor2; /// AYNI SEKILDE ARAMA ICIN EKLENIR int tkod,ikinci_tkod,j=0,max=0; int sec,i=0,k=0,max_gol,max_kod,max_fno; int found,evkod,miskod,evgol,misgol,hno,bulundu; int oo=0,avr=0,puan=0; goster1(); while((sec=menu())!=12) /// YANLIS GIRIS YAPILMAMASI SAGLANIR { switch(sec) /// SECIM YAPILIR { case 1: system("cls"); /// C DEKI EKRAN TEMIZLEME FONKSYONU printf("\n\tTAKIM EKLEME FONKSYONA GIRDINIZ\n\n"); printf("\t Takimin kodu giriniz (1-99):\n\t--> "); scanf("%d",&tkod); /// KULLANICININ GIRDIGI KODU ALIR while(tkod<1 || tkod>99) /// YANLIS GIRIS YAPILMAMASI ICIN KOD KONTROL EDILIR { printf("\n\tYanlis girdiniz!!!\n\tLutfen tekrar Takim kodu giriniz:\n\t--> "); scanf("%d",&tkod); } if(team[tkod-1]==NULL) /// TAKIM KODU DAHA ONCE KULLANILMADIYSA YENI TAKIM OLUSTURULUR { i=0; team[tkod-1]=malloc(sizeof(struct TAKIM)); /// YENI DUGUM OLUSTURULUR team[tkod-1]->t_kod = tkod; /// TAKIM DUGUMUNDEKI TAKIM KODU BELIRLENIR team[tkod-1]->sonraki_oyuncu=NULL; /// YENI DUGUM ICIN SONRAKI FUTBOLCUNUN DUGUMU NULL (BOS) ATILIR team[tkod-1]->sonraki_hafta=NULL; /// YENI DUGUM ICIN SONRAKI FUTBOLCUNUN DUGUMU NULL (BOS) ATILIR fflush(stdin); printf("\n\tTakim isimini giriniz:\n\t--> "); gets(team[tkod-1]->t_ad); /// GETS FONKSYONU STRINGI ALIR while(team[tkod-1]->t_ad[i]) { team[tkod-1]->t_ad[i]=(toupper(team[tkod-1]->t_ad[i])); /// HARFLER BUYUTULUR i++; } team[tkod-1]->b_say=0; /// TAKIM DUGUMDEKI BERABERLIK SAYISI BELIRLENIR team[tkod-1]->g_say=0; /// TAKIM DUGUMDEKI GALIBIYET SAYISI BELIRLENIR team[tkod-1]->m_say=0; /// TAKIM DUGUMDEKI MAGLUBIYET SAYISI BELIRLENIR team[tkod-1]->a_gol=0; /// TAKIM DUGUMDEKI ATTIGI GOL SAYISI BELIRLENIR team[tkod-1]->y_gol=0; /// TAKIM DUGUMDEKI YEDIGI GOL SAYISI BELIRLENIR printf("\n\t%s TAKIMI BASARIYLA OLUSTURDUNUZ!!!",team[tkod-1]->t_ad); } else printf("\n\t Girdiginiz takim kodu (%d) daha once kullandiniz!!!",tkod); printf("\n\n"); system("\tpause"); break; case 2: system("cls"); printf("\n\tLIG DISINDAN TRANSFER EDILMESI FONKSYONA GIRDINIZ\n\n"); do { printf("\n\tTakim kodu giriniz:\n\t--> "); scanf("%d",&tkod); } while(tkod<1 || tkod>99); if(team[tkod-1]!=NULL) /// TAKIM BOS DEGILSE YENI BIR FUTBOLCU OLUSTURULUR { fflush(stdin); do { printf("\n\tFutbolcunun forma numarasi giriniz:\n\t--> "); scanf("%d",&fno); /// FUTBOLCUNUN FORMA NUMARASI ALINIR VE OYUNCU DUGUME BAGLANIR } while(fno<1 || fno>99); gecici=team[tkod-1]->sonraki_oyuncu; /// FORMA NUMARASI DAHA ONCE KULLANILDIYSA ASAGDAKI while(gecici!=NULL && gecici->f_no!=fno) /// MESAJ VERILIR { gecici=gecici->sonraki; } if(gecici!=NULL) printf("\n\tForma numaraya ait oyuncu var."); else { /// FORMA NUMARASI DAHA ONCE KULLANILMADIYSA YENI FUTBOLCU OLUSTURULUR VE FUTBOLCUYA /// AIT DIGER BILGILER ALINIR DUGUME BAGLANIR VE SONRAKI FUTBOLCU DUGUM ICIN NULL (BOS) OLARAK GOSTERILIR futBilgi=malloc(sizeof(struct TAKIM)); futBilgi->t_kod = tkod; futBilgi->f_no = fno; j=0; fflush(stdin); printf("\n\tFutbolcunun ad ve soyad giriniz:\n\t--> "); gets(futBilgi->f_ad); while(futBilgi->f_ad[j]) { futBilgi->f_ad[j] = toupper(futBilgi->f_ad[j]); j++; } futBilgi->a_gol=0; futBilgi->sonraki=NULL; onceki=NULL; simdiki=team[tkod-1]->sonraki_oyuncu; while(simdiki!=NULL && fno > simdiki->f_no) { onceki=simdiki; simdiki=simdiki->sonraki; } if(onceki==NULL) { futBilgi->sonraki=team[tkod-1]->sonraki_oyuncu; team[tkod-1]->sonraki_oyuncu=futBilgi; } else { onceki->sonraki=futBilgi; futBilgi->sonraki=simdiki; } printf("\n\tTRANSFER BASARIYLA GERCEKLESTIRDINIZ!!!"); } } else printf("\n\tyazdiginiz takim kodu bulunamadi."); printf("\n\n"); system("\tpause"); break; case 3: system("cls"); printf("\n\tLIG DISINDA TRANSFER EDILMESI FONKSYONA GIRDINIZ\n\n"); /// CASE 3 BIR TAKIMDAN BASKA BIR TAKIMA OYUNCU TRANSFER EDILIR VE TRANSFER ISLEMI GERCEKLESTIRILIR do { printf("\n\tFutbolcunun takim kodu giriniz:\n\t-> "); scanf("%d",&tkod); } while(team[tkod-1]==NULL || tkod<1 || tkod>99); do { printf("\n\tFutbolcunun forma numarasi giriniz:\n\t-> "); scanf("%d",&fno); yeni_futbolcu=team[tkod-1]->sonraki_oyuncu; /// ILK DUGUMDE FORMA NUMARASI MEVCUT ISE DIREKT ALIR VE KULLANICIDAN /// TRANSFER EDECEGI TAKIMIN KODU VE YENI FORMA NUMARASI SORULUR if(fno==yeni_futbolcu->f_no) { found=1; team[tkod-1]->sonraki_oyuncu=yeni_futbolcu->sonraki; gecici=yeni_futbolcu; } else { onceki=team[tkod-1]->sonraki_oyuncu; simdiki=onceki->sonraki; while(simdiki!=NULL) { if(fno==simdiki->f_no) { found=1; gecici=simdiki; onceki->sonraki=simdiki->sonraki; } onceki=simdiki; simdiki=simdiki->sonraki; } } if(found==0) printf("\n\tYazdiginiz forma numara bulunamadi."); } while(found==0); do { printf("\n\tTransfer edecek takima takim kod giriniz:\n\t->"); scanf("%d",&ikinci_tkod); } while(team[ikinci_tkod-1]==NULL); do { found=0; printf("\n\tIkinci takimda futbolcunun forma numarasi yaziniz:\n\t->"); scanf("%d",&ikinci_fno); temp=team[ikinci_tkod-1]->sonraki_oyuncu; /// YENI OYUNCU ICIN GIRILEN FORMA NUMARASI KONTROL EDILIR /// DAHA ONCE GIRILEN FORMA NUMARASININ OLUP OLMADIGI KONTROL EDILIR while(temp!=NULL && temp->f_no!=ikinci_fno) { temp=temp->sonraki; } /// FORMA NO BOS ISE YENI TAKIMDAKI FUTBOLCUYU TRANSFER EDILIR if(temp==NULL) { gecici->f_no=ikinci_fno; onceki=NULL; simdiki=team[ikinci_tkod-1]->sonraki_oyuncu; while(simdiki!=NULL && ikinci_fno>simdiki->f_no) { onceki=simdiki; simdiki=simdiki->sonraki; } if(onceki==NULL) { gecici->sonraki=team[ikinci_tkod-1]->sonraki_oyuncu; team[ikinci_tkod-1]->sonraki_oyuncu=gecici; } else { onceki->sonraki=gecici; gecici->sonraki=simdiki; } printf("\n\tTRANSFER BASARIYLA GERCEKLESTIRDINIZ!!!"); } else { printf("\n\tOyuncu forma numarasi zaten var."); found=1; } } while(found==1); printf("\n\n"); system("\tpause"); break; case 4: system("cls"); printf("\n\tLIG DISINDA TRANSFER EDILMESI FONKSYONA GIRDINIZ\n\n"); /// CASE 4 BIR TAKIMIN FUTBOLCUSU SILINIR printf("\n\tFutbolcunun takim kodu giriniz:\n\t-> "); scanf("%d",&tkod); if(team[tkod-1]!=NULL) { printf("\n\tFutbolcunun forma numarasi giriniz:\n\t-> "); scanf("%d",&fno); gecici=team[tkod-1]->sonraki_oyuncu; while(gecici!=NULL && gecici->f_no!=fno) gecici=gecici->sonraki; if(gecici!=NULL) { /// GIRILEN TAKIM KODU ILK SIRADA ISE ALINIR VE SILINIR DEGILSE /// SONUNA GIDILIR YANI BOS OLANA KADAR if(fno==team[tkod-1]->sonraki_oyuncu->f_no) { gecici=team[tkod-1]->sonraki_oyuncu; team[tkod-1]->sonraki_oyuncu=team[tkod-1]->sonraki_oyuncu->sonraki; free(gecici); /// FREE FONKSYONU DUGUMDEKI TUM BILGILERI SILER VE BELEKTEKI YERI FREE LER } else { onceki=team[tkod-1]->sonraki_oyuncu; simdiki=onceki->sonraki; while(simdiki!=NULL && simdiki->f_no!=fno) { onceki=simdiki; simdiki=simdiki->sonraki; } if(simdiki!=NULL) { gecici=simdiki; onceki->sonraki=simdiki->sonraki; free(gecici); } } } else printf("\n\tFutbolcunun forma numarasi bulunamadi."); } else printf("\n\t Yazdiginiz Takim kodu (%d) bulunamadi!!!",tkod); printf("\n\n"); system("\tpause"); break; case 5: system("cls"); printf("\n\tMAC SKORLARIN KAYDEDILMESI FONKSYONA GIRDINIZ\n\n"); /// CASE 5 YENI SKORLARIN GIRILMESI do { /// SKORLAR ICIN BELLEKTEKI YER AYRILIR /// TUM GEREKLI BILGILER ALINIR VE SONUNDA YENI OLUSTURULAN DUGUME ATANIR skor=malloc(sizeof(struct SKORLAR)); skor2=malloc(sizeof(struct SKORLAR)); printf("\n\tHafta no giriniz:\n\t--> "); scanf("%d",&hno); do { printf("\n\tEv sahibinin takim kodu giriniz:\n\t-> "); scanf("%d",&evkod); } while(evkod<1 || evkod>99); if(team[evkod-1]->sonraki_oyuncu==NULL ) { printf("\n\t%d TAKIMINDA OYUNCU MEVCUT DEGIL",evkod); break; } fflush(stdin); do { printf("\n\tMisafirin takim kodu giriniz:\n\t-> "); scanf("%d",&miskod); } while(miskod<1 || miskod>99); while(miskod==evkod) { printf("\n\tKodu daha once ev sahibi olarak girdiniz\n"); printf("\tMisafirin takim kodu giriniz:\n\t-> "); scanf("%d",&miskod); } if(team[miskod-1]->sonraki_oyuncu==NULL ) { printf("\n\t%d TAKIMINDA OYUNCU MEVCUT DEGIL",miskod); break; } /// TAKIM KODUNUN YANLIS GIRILMEMESI ICIN KONTROL EDILIR if(team[evkod-1]!=NULL && team[miskod-1]!=NULL) { printf("\n\tEv Sahib Takimin Adi\n\t-----------------------"); printf("\n\t%-20s\n",team[evkod-1]->t_ad); fflush(stdin); printf("\n\tEv sahibin attilan gol sayisi yaziniz:\n\t-> "); scanf("%d",&evgol); if(evgol>0) for(i=0; i<evgol; i++) { do { kontrol=0; printf("\n\t%d. golu atan forma numara giriniz:\n\t-> ",i+1); scanf("%d",&fno); if(team[evkod-1]->sonraki_oyuncu->f_no==fno) { team[evkod-1]->sonraki_oyuncu->a_gol+=1; kontrol=1; } else { onceki=team[evkod-1]->sonraki_oyuncu; simdiki=onceki->sonraki; while(simdiki!=NULL) { if(simdiki->f_no==fno) { kontrol=1; simdiki->a_gol+=1; } onceki=simdiki; simdiki=simdiki->sonraki; } } if(kontrol==0) printf("\n\tGirdiginiz forma no mevcut degil.\n"); } while(kontrol==0); } printf("\n\tMisafir Takimin Adi\n\t----------------------- "); printf("\n\t%-20s\n",team[miskod-1]->t_ad); fflush(stdin); printf("\n\tMisafir attilan gol sayisi yaziniz:\n\t-> "); scanf("%d",&misgol); if(misgol>0) for(i=0; i<misgol; i++) { do { kontrol=0; printf("\n\t%d. golu atan forma numara giriniz:\n\t-> ",i+1); scanf("%d",&fno); if(team[miskod-1]->sonraki_oyuncu->f_no==fno) { team[miskod-1]->sonraki_oyuncu->a_gol+=1; kontrol=1; } else { onceki=team[miskod-1]->sonraki_oyuncu; simdiki=onceki->sonraki; while(simdiki!=NULL) { if(simdiki->f_no==fno) { kontrol=1; simdiki->a_gol+=1; } onceki=simdiki; simdiki=simdiki->sonraki; } } if(kontrol==0) printf("\n\tGirdiginiz forma no mevcut degil.\n"); } while(kontrol==0); } skor->h_no=hno; skor->ev_kod=evkod; skor->mis_kod=miskod; skor->ev_gol=evgol; skor->mis_gol=misgol; skor2->h_no=hno; skor2->ev_kod=evkod; skor2->mis_kod=miskod; skor2->ev_gol=evgol; skor2->mis_gol=misgol; if(evgol>misgol) { team[evkod-1]->g_say+=1; team[miskod-1]->m_say+=1; } if(evgol==misgol) { team[evkod-1]->b_say+=1; team[miskod-1]->b_say+=1; } if(evgol<misgol) { team[evkod-1]->m_say+=1; team[miskod-1]->g_say+=1; } team[evkod-1]->a_gol+=evgol; team[evkod-1]->y_gol+=misgol; team[miskod-1]->a_gol+=misgol; team[miskod-1]->y_gol+=evgol; if(team[evkod-1]->sonraki_hafta==NULL) { team[evkod-1]->sonraki_hafta=skor; skor->sonraki=NULL; } else { onceki_skor=NULL; simdiki_skor=team[evkod-1]->sonraki_hafta; while(simdiki_skor!=NULL && skor->h_no > simdiki_skor->h_no) { onceki_skor=simdiki_skor; simdiki_skor=simdiki_skor->sonraki; } if(onceki_skor==NULL) { skor->sonraki=team[evkod-1]->sonraki_hafta; team[evkod-1]->sonraki_hafta=skor; } else { onceki_skor->sonraki=skor; skor->sonraki=simdiki_skor; } } if(team[miskod-1]->sonraki_hafta==NULL) { team[miskod-1]->sonraki_hafta=skor2; skor2->sonraki=NULL; } else { onceki_skor2=NULL; simdiki_skor2=team[miskod-1]->sonraki_hafta; while(simdiki_skor2!=NULL && skor2->h_no > simdiki_skor2->h_no) { onceki_skor2=simdiki_skor2; simdiki_skor2=simdiki_skor2->sonraki; } if(onceki_skor2==NULL) { skor2->sonraki=team[evkod-1]->sonraki_hafta; team[evkod-1]->sonraki_hafta=skor2; } else { onceki_skor2->sonraki=skor2; skor2->sonraki=simdiki_skor2; } } } else { system("cls"); printf("\n\n\tYazdiginiz takim kodlari (%d,%d) bulunamadi!!!\n",evkod,miskod); } do { fflush(stdin); printf("\n\tBaska eklenecek skorlar var mi?\n\t-> "); cvp=getchar(); } while(cvp!='e' && cvp!='E' && cvp!='h' && cvp!='H'); } while(cvp=='e' || cvp=='E'); printf("\n\n"); system("\tpause"); break; case 6: system("cls"); printf("\n\tTAKIMIN DURUM VE FUTBOLCULAR FONKSYONA GIRDINIZ\n\n"); /// TAKIMLARA AIT BILGILERI VE FUTBOLCULAR GOSTERILIR bulundu=0; found=1; j=0; k=0; printf("\n\tAranacak takimin adi yaziniz:\n\t--> "); scanf("%s",aranan_takim); /// KULLANICIDAN TAKIMIN ISMI ALINIR VE while(aranan_takim[j]) { aranan_takim[j]=toupper(aranan_takim[j]); j++; } while(team[tkod-1]->t_ad[k]) { team[tkod-1]->t_ad[k]=toupper(team[tkod-1]->t_ad[k]); k++; } for(i=0; i<100; i++) /// OLUP OLMADIGI KONTROL EDILIR { if(team[i]!=NULL) { found=strcmp(aranan_takim,team[i]->t_ad); if(found==0) { found=i; bulundu=1; break; } } } if(bulundu==1) /// BULUNDUYSA TAKIMIN TUM BILGILERI GOSTERILIR { /// O TAKIMA AIT FUTBOLCULAR GOSTERILIR goster_takim(); k=0; oo=0; avr=0; puan=0; while(team[found]->t_ad[k]) { team[found]->t_ad[k]=(toupper(team[found]->t_ad[k])); k++; } oo=team[found]->b_say+team[found]->g_say+team[found]->m_say; avr=team[found]->a_gol-team[found]->y_gol; for(i=0; i<team[found]->g_say; i++) puan+=3; for(i=0; i<team[found]->b_say; i++) puan+=1; printf("\n\t%3d %-20s%3d %-2d %-2d %-2d %-2d %-2d i%-3d %-4d",team[found]->t_kod, team[found]->t_ad, oo,team[found]->g_say,team[found]->b_say,team[found]->m_say,team[found]->a_gol,team[found]->y_gol,avr,puan); printf("\n\t-----------------------------------------------------------\n"); futBilgi=team[found]->sonraki_oyuncu; yazdir_oyuncu(futBilgi); printf("\n\t------------------------------------"); } else printf("\n\tYazdiginiz takim ismi bulunamadi."); printf("\n\n"); system("\tpause"); break; case 7: system("cls"); printf("\n\tTAKIMIN DURUM VE OYNADIGI MACLAR FONKSYONA GIRDINIZ\n\n"); do { printf("\n\tTakim kodu giriniz:\n\t-> "); scanf("%d",&tkod); } while(tkod<1 || tkod>99); if(team[tkod-1]!=NULL) { goster_takim(); k=0; oo=0; avr=0; puan=0; while(team[tkod-1]->t_ad[k]) { team[tkod-1]->t_ad[k]=(toupper(team[tkod-1]->t_ad[k])); k++; } oo=team[tkod-1]->b_say+team[tkod-1]->g_say+team[tkod-1]->m_say; avr=team[tkod-1]->a_gol-team[tkod-1]->y_gol; for(i=0; i<team[tkod-1]->g_say; i++) puan+=3; for(i=0; i<team[tkod-1]->b_say; i++) puan+=1; printf("\n\t%3d %-20s%3d %-2d %-2d %-2d %-2d %-2d i%-3d %-4d",team[tkod-1]->t_kod, team[tkod-1]->t_ad, oo,team[tkod-1]->g_say,team[tkod-1]->b_say,team[tkod-1]->m_say,team[tkod-1]->a_gol, team[tkod-1]->y_gol,avr,puan); if(team[tkod-1]->sonraki_hafta==NULL) { printf("\n\tTAKIMIN OYNANMIS MACI BULUNMAMAKTADIR"); } else { printf("\n"); goster_skorlar(); onceki_skor2=team[tkod-1]->sonraki_hafta; while(onceki_skor2!=NULL) { printf("\n\t%3d.",onceki_skor2->h_no); printf(" %-20s%2d :%2d ",team[onceki_skor2->ev_kod-1]->t_ad, onceki_skor2->ev_gol,onceki_skor2->mis_gol); printf(" %-20s",team[onceki_skor2->mis_kod-1]->t_ad); onceki_skor2=onceki_skor2->sonraki; } } } else printf("\n\tYazdiginiz takim kodu bulunamadi"); printf("\n\n"); system("\tpause"); break; case 8: system("cls"); printf("\n\tTUM TAKIMLARIN DURUMLARI FONKSYONA GIRDINIZ\n\n"); goster_takim(); for(j=0; j<100; j++) { if(team[j]==NULL) continue; k=0; oo=0; avr=0; puan=0; while(team[j]->t_ad[k]) { team[j]->t_ad[k]=(toupper(team[j]->t_ad[k])); k++; } oo=team[j]->b_say+team[j]->g_say+team[j]->m_say; avr=team[j]->a_gol-team[j]->y_gol; for(i=0; i<team[j]->g_say; i++) puan+=3; for(i=0; i<team[j]->b_say; i++) puan+=1; printf("\n\t%3d %-20s%3d %-2d %-2d %-2d %-2d %-2d i%-3d %-4d",team[j]->t_kod, team[j]->t_ad, oo,team[j]->g_say,team[j]->b_say,team[j]->m_say,team[j]->a_gol,team[j]->y_gol,avr,puan); } printf("\n\t-----------------------------------------------------------"); printf("\n\n"); system("\tpause"); break; case 9: system("cls"); printf("\n\tCOK GOL ATAN VE AZ GOL YIYEN TAKIMLARI FONKSYONA GIRDINIZ\n\n"); max=100; for(i=0; i<100; i++) { max_gol=0; if(team[i]==NULL) continue; if(team[i]->a_gol>max_gol) { max_kod=team[i]->t_kod; } if(team[i]->y_gol<max) { max=team[i]->t_kod; } } goster_takim(); k=0; oo=0; avr=0; puan=0; while(team[max_kod-1]->t_ad[k]) { team[max_kod-1]->t_ad[k]=(toupper(team[max_kod-1]->t_ad[k])); k++; } oo=team[max_kod-1]->b_say+team[max_kod-1]->g_say+team[max_kod-1]->m_say; avr=team[max_kod-1]->a_gol-team[max_kod-1]->y_gol; for(i=0; i<team[max_kod-1]->g_say; i++) puan+=3; for(i=0; i<team[max_kod-1]->b_say; i++) puan+=1; printf("\n\t%3d %-20s%3d %-2d %-2d %-2d %-2d %-2d i%-3d %-4d",team[max_kod-1]->t_kod, team[max_kod-1]->t_ad, oo,team[max_kod-1]->g_say,team[max_kod-1]->b_say,team[max_kod-1]->m_say,team[max_kod-1]->a_gol,team[max_kod-1]->y_gol,avr,puan); k=0; oo=0; avr=0; puan=0; while(team[max-1]->t_ad[k]) { team[max-1]->t_ad[k]=(toupper(team[max-1]->t_ad[k])); k++; } oo=team[max-1]->b_say+team[max-1]->g_say+team[max-1]->m_say; avr=team[max-1]->a_gol-team[max-1]->y_gol; for(i=0; i<team[max-1]->g_say; i++) puan+=3; for(i=0; i<team[max-1]->b_say; i++) puan+=1; printf("\n\t%3d %-20s%3d %-2d %-2d %-2d %-2d %-2d i%-3d %-4d",team[max-1]->t_kod, team[max-1]->t_ad, oo,team[max-1]->g_say,team[max-1]->b_say,team[max-1]->m_say,team[max-1]->a_gol,team[max-1]->y_gol,avr,puan); printf("\n\n"); system("\tpause"); break; case 10: system("cls"); printf("\n\tDEPLASMANDA EN IYI TAKIM FONKSYONA GIRDINIZ\n\n"); /// CASE 10 DEPLASMANDA EN IYI TAKIM BULUP EKRANA GOSTERILIR for(i=0; i<100; i++) { if(team[i]==NULL) continue; max=0; if(team[i]!=NULL) { if(team[i]->sonraki_hafta!=NULL) { onceki_skor2=team[i]->sonraki_hafta; while(onceki_skor2!=NULL) { if(onceki_skor2->mis_gol>max) max=onceki_skor2->mis_kod; onceki_skor2=onceki_skor2->sonraki; } } } } oo=0; avr=0; puan=0; goster_takim(); while(team[max-1]->t_ad[k]) { team[max-1]->t_ad[k]=(toupper(team[max-1]->t_ad[k])); k++; } oo=team[max-1]->b_say+team[max-1]->g_say+team[max-1]->m_say; avr=team[max-1]->a_gol-team[max-1]->y_gol; for(i=0; i<team[max-1]->g_say; i++) puan+=3; for(i=0; i<team[max-1]->b_say; i++) puan+=1; printf("\n\t%3d %-20s%3d %-2d %-2d %-2d %-2d %-2d i%-3d %-4d",team[max-1]->t_kod, team[max-1]->t_ad, oo,team[max-1]->g_say,team[max-1]->b_say,team[max-1]->m_say,team[max-1]->a_gol,team[max-1]->y_gol,avr,puan); printf("\n\n"); system("\tpause"); break; case 11: system("cls"); printf("\n\tTAKIMLARIN GOL KRALI VE LIGDEKI GOL KRALI FONKSYONA GIRDINIZ\n\n"); /// CASE 11 TAKIMLARIN GOL KRALI VE LIGDEKI GOL KRALI BULUP EKRANA GOSTERILIR goster_takim_ve_oyuncu(); for(i=0; i<100; i++) { if(team[i]==NULL) continue; max_gol=0; if(team[i]!=NULL) { if(team[i]->sonraki_oyuncu!=NULL) { onceki=team[i]->sonraki_oyuncu; while(onceki!=NULL) { if(onceki->a_gol>max_gol) { max_gol=onceki->a_gol; max_kod=onceki->t_kod; max_fno=onceki->f_no; found=strlen(onceki->f_ad); for(j=0; j<found; j++) { max_ad[j]=onceki->f_ad[j]; } max_ad[found]='\0'; } onceki=onceki->sonraki; } printf("\n\t%3d %-20s %3d %-20s%2d",max_kod, team[max_kod-1]->t_ad, max_fno,max_ad,max_gol); } } } printf("\n\n\tLigin Gol Krali:\n"); goster_takim_ve_oyuncu(); for(i=0; i<100; i++) { if(team[i]==NULL) continue; if(team[i]!=NULL) { if(team[i]->sonraki_oyuncu!=NULL) { onceki=team[i]->sonraki_oyuncu; while(onceki!=NULL) { if(onceki->a_gol>max_gol) { max_gol=onceki->a_gol; max_kod=onceki->t_kod; max_fno=onceki->f_no; found=strlen(onceki->f_ad); for(j=0; j<found; j++) { max_ad[j]=onceki->f_ad[j]; } max_ad[found]='\0'; } onceki=onceki->sonraki; } } } } printf("\n\t%3d %-20s %3d %-20s%2d",max_kod, team[max_kod-1]->t_ad, max_fno,max_ad,max_gol); printf("\n\n"); system("\tpause"); break; } } printf("\n\n"); goster2(); printf("\n\n"); system("pause"); return 0; } /// CASE 6 DAKI TAKIMIN ADA AIT FUTBOLCULAR EKRANA GOSTERILIR void yazdir_oyuncu(struct OYUNCU *futBilgi) { if(futBilgi==NULL) { printf("\n\tBU TAKIMA AIT HIC BIR FUTBOLCU YOK"); } else { goster_Oyuncu(); while(futBilgi!=NULL) { printf("\n\t%4d %-20s %4d",futBilgi->f_no,futBilgi->f_ad,futBilgi->a_gol); futBilgi=futBilgi->sonraki; } } } /// EKRANA ILK PROGRAM ACARKEN BU FONKSYON GOSTERILIR int menu(void) { int secim; system("CLS"); printf("\n\t\t\21\26\26\20 MENU \21\26\26\20\n"); printf("\n\t1. Takim Ekleme fonksiyon."); printf("\n\t2. Lig disindan transfer edilmesi."); printf("\n\t3. Lig icinde transfer edilmesi."); printf("\n\t4. Lig disinda transfer edilmesi."); printf("\n\t5. Mac skorlarin kaydedilmesi."); printf("\n\t6. Takimin durum ve futbolcular."); printf("\n\t7. Takimin durum ve oynadigi maclar."); printf("\n\t8. Tum takimlarin durumlari."); printf("\n\t9. Cok gol atan ve az gol yiyen takimlari."); printf("\n\t10. Deplasmanda en iyi takim."); printf("\n\t11. Takimlarin gol krali ve ligdeki gol krali."); printf("\n\n\t12. CIKIS"); printf("\n\n\t Seciminizi Giriniz: \n\t---> "); scanf("%d",&secim); return secim; } void goster1() { int i,j; char metin[]="*********************************************"; char metin2[]="* DERSIN ADI: ALGORITMA VE PROGRAMLAMA 2 *"; char metin3[]="* PROJE ADI: Futbol Ligi Takip Sistemi v2 *"; char metin4[]="* *"; char metin5[]="* PROJE YAZAN KISILER: *"; char metin6[]="* EROLL RAMAXHIK - 05 10 0000 901 *"; char metin7[]="* SELIM AGOVIC - 05 11 0000 797 *"; char metin8[]="* ONUR PALA - 05 10 0000 871 *"; char metin9[]="********************************************"; char metin10[]=" "; printf("\n\n"); j=0; printf("\t\t"); for (;;) { for(i=0; i<100000; i++); for(i=0; i<1000000; i++); printf("%c",metin[j]); j++; if (j==strlen(metin)) { printf(" "); break; } } printf("\n\n"); j=0; printf("\t\t"); for (;;) { for(i=0; i<1000000; i++); for(i=0; i<1000000; i++); printf("%c",metin2[j]); j++; if (j==strlen(metin2)) { printf(" "); break; } } printf("\n\n"); j=0; printf("\t\t"); for (;;) { for(i=0; i<1000000; i++); for(i=0; i<1000000; i++); printf("%c",metin3[j]); j++; if (j==strlen(metin3)) { printf(" "); break; } } printf("\n\n"); j=0; printf("\t\t"); for (;;) { for(i=0; i<100000; i++); for(i=0; i<1000000; i++); printf("%c",metin4[j]); j++; if (j==strlen(metin4)) { printf(" "); break; } } printf("\n\n"); j=0; printf("\t\t"); for (;;) { for(i=0; i<100000; i++); for(i=0; i<1000000; i++); printf("%c",metin5[j]); j++; if (j==strlen(metin5)) { printf(" "); break; } } printf("\n\n"); j=0; printf("\t\t"); for (;;) { for(i=0; i<100000; i++); for(i=0; i<10000000; i++); printf("%c",metin6[j]); j++; if (j==strlen(metin6)) { printf(" "); break; } } printf("\n\n"); j=0; printf("\t\t"); for (;;) { for(i=0; i<100000; i++); for(i=0; i<10000000; i++); printf("%c",metin7[j]); j++; if (j==strlen(metin7)) { printf(" "); break; } } printf("\n\n"); j=0; printf("\t\t"); for (;;) { for(i=0; i<100000; i++); for(i=0; i<10000000; i++); printf("%c",metin8[j]); j++; if (j==strlen(metin8)) { printf(" "); break; } } printf("\n\n"); j=0; printf("\t\t"); for (;;) { for(i=0; i<100000; i++); for(i=0; i<10000000; i++); printf("%c",metin9[j]); j++; if (j==strlen(metin9)) { printf(" "); break; } } printf("\n\n"); j=0; printf("\t\t"); for (;;) { for(i=0; i<100000; i++); for(i=0; i<1000000; i++); printf("%c",metin10[j]); j++; if (j==strlen(metin10)) { printf(" "); break; } } }
the_stack_data/28261827.c
/* ******************************************************************************* * Copyright (c) 2020-2021, STMicroelectronics * All rights reserved. * * This software component is licensed by ST under BSD 3-Clause license, * the "License"; You may not use this file except in compliance with the * License. You may obtain a copy of the License at: * opensource.org/licenses/BSD-3-Clause * ******************************************************************************* */ #if defined(ARDUINO_GENERIC_F302K6UX) || defined(ARDUINO_GENERIC_F302K8UX) #include "pins_arduino.h" /** * @brief System Clock Configuration * @param None * @retval None */ WEAK void SystemClock_Config(void) { /* SystemClock_Config can be generated by STM32CubeMX */ #warning "SystemClock_Config() is empty. Default clock at reset is used." } #endif /* ARDUINO_GENERIC_* */
the_stack_data/92399.c
/** * http://www.spoj.com/problems/PALIN/ * * 5. The Next Palindrome * * Problem code: PALIN * * A positive integer is called a palindrome if its representation in the * decimal system is the same when read from left to right and from right to * left. For a given positive integer K of not more than 1000000 digits, write * the value of the smallest palindrome larger than K to output. Numbers are * always displayed without leading zeros. * * Input * The first line contains integer t, the number of test cases. Integers K are given in the next t lines. * * Output * For each K, output the smallest palindrome larger than K. * * Example * Input: * 2 * 808 * 2133 * * Output: * 818 * 2222 */ #include <stdio.h> int main(void) { int numTestCases, num, i; scanf("%i", &numTestCases); int nums[numTestCases]; for (i = 0; i < numTestCases; i++) { scanf("%i", &num); nums[i] = num; } for (i = 0; i < numTestCases; i++) { num = nums[i]; printf("\n"); for (++num; num < (num + 10000); num++) { if (isPalin(num)) { printf("%i\n", num); break; } } } return 0; } int reverseNum(int num) { int n, rev, dig; n = num; rev = 0; while (num > 0) { dig = num % 10; rev = rev * 10 + dig; num = num / 10; } return rev; } int isPalin(int num) { if (num == reverseNum(num)) { return 1; } else { return 0; } }
the_stack_data/54211.c
#include <stdio.h> int main(void) { const unsigned int SIZE = 8; int index; double input[SIZE], sum[SIZE]; printf("Enter 8 floating point values: "); for (index = 0; index < SIZE; index++) scanf("%lf", &input[index]); for (index = 1, sum[0] = input[0]; index < SIZE; index++) sum[index] = sum[index - 1] + input[index]; for (index = 0; index < SIZE; index++) printf("%8.2e ", input[index]); printf("\n"); for (index = 0; index < SIZE; index++) printf("%8.2e ", sum[index]); printf("\n"); return 0; }
the_stack_data/940709.c
/* Rastgele sırada sunum yapılması için bir program yazılması gerekmektedir. Sunum listesi bir dizide saklanmalıdır. rastgeleSıralamaOlustur isimli bir fonksiyonu diziyi ve dizinin boyutunu parametre olarak alacak şekilde yazınız. Lütfen programın tamamını kodlayınız. In order to make a presentation in random order, a program must be written. The presentation list should be stored in an array. Write a function called generateRandomOrder which takes an array and size of the array as a parameter. Please write the entire program. */ #include <stdio.h> #include <stdlib.h> #include <time.h> #include <locale.h> #define SIZE 100 int rastgeleSiralamaOlustur(int dizi[], int x) { int i, j = 0, random; for (i = 0; i < x; i++) { random = 1 + rand() % x; for (j = 0; j <= i; j++) { if (i == j) //Eğer üretilen sayı önceki değerlerden farklıysa { dizi[i] = random; } else if (random == dizi[j]) // Eğer üretilen sayı dizide ise { i--; break; } } } } int main() { setlocale(LC_ALL, "Turkish"); srand(time(NULL)); ////Rastgele Sayı Üretimi int ogrenci_sayisi; printf("Öğrenci Sayısını Giriniz: "); scanf("%d", &ogrenci_sayisi); int dizi[SIZE]; rastgeleSiralamaOlustur(dizi, ogrenci_sayisi); int i = 0; for (i = 0; i < ogrenci_sayisi; i++) printf("%d. Sırada Sunacak Kişi - Listedeki %d. Öğrenci\n", i + 1, dizi[i]); return 0; }
the_stack_data/218892743.c
// RUN: %clang_cc1 -fsanitize=implicit-signed-integer-truncation -fsanitize-recover=implicit-signed-integer-truncation -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_implicit_conversion" --check-prefixes=CHECK // CHECK-DAG: @[[LINE_100_SIGNED_TRUNCATION:.*]] = {{.*}}, i32 100, i32 10 }, {{.*}}, {{.*}}, i8 2 } // CHECK-DAG: @[[LINE_200_SIGNED_TRUNCATION:.*]] = {{.*}}, i32 200, i32 10 }, {{.*}}, {{.*}}, i8 2 } // CHECK-LABEL: @ignorelist_0_convert_signed_int_to_signed_char __attribute__((no_sanitize("undefined"))) signed char ignorelist_0_convert_signed_int_to_signed_char(signed int x) { // We are not in "undefined" group, so that doesn't work. // CHECK: call void @__ubsan_handle_implicit_conversion(i8* bitcast ({ {{{.*}}}, {{{.*}}}*, {{{.*}}}*, i8 }* @[[LINE_100_SIGNED_TRUNCATION]] to i8*) #line 100 return x; } // CHECK-LABEL: @ignorelist_1_convert_signed_int_to_signed_char __attribute__((no_sanitize("integer"))) signed char ignorelist_1_convert_signed_int_to_signed_char(signed int x) { return x; } // CHECK-LABEL: @ignorelist_2_convert_signed_int_to_signed_char __attribute__((no_sanitize("implicit-conversion"))) signed char ignorelist_2_convert_signed_int_to_signed_char(signed int x) { return x; } // CHECK-LABEL: @ignorelist_3_convert_signed_int_to_signed_char __attribute__((no_sanitize("implicit-integer-truncation"))) signed char ignorelist_3_convert_signed_int_to_signed_char(signed int x) { return x; } // CHECK-LABEL: @ignorelist_4_convert_signed_int_to_signed_char __attribute__((no_sanitize("implicit-signed-integer-truncation"))) signed char ignorelist_4_convert_signed_int_to_signed_char(signed int x) { return x; } // CHECK-LABEL: @ignorelist_5_convert_signed_int_to_signed_char __attribute__((no_sanitize("implicit-unsigned-integer-truncation"))) signed char ignorelist_5_convert_signed_int_to_signed_char(signed int x) { // This is an signed truncation, not unsigned-one. // CHECK: call void @__ubsan_handle_implicit_conversion(i8* bitcast ({ {{{.*}}}, {{{.*}}}*, {{{.*}}}*, i8 }* @[[LINE_200_SIGNED_TRUNCATION]] to i8*) #line 200 return x; }
the_stack_data/73557.c
/* * docproc is a simple preprocessor for the template files * used as placeholders for the kernel internal documentation. * docproc is used for documentation-frontend and * dependency-generator. * The two usages have in common that they require * some knowledge of the .tmpl syntax, therefore they * are kept together. * * documentation-frontend * Scans the template file and call kernel-doc for * all occurrences of ![EIF]file * Beforehand each referenced file is scanned for * any symbols that are exported via these macros: * EXPORT_SYMBOL(), EXPORT_SYMBOL_GPL(), & * EXPORT_SYMBOL_GPL_FUTURE() * This is used to create proper -function and * -nofunction arguments in calls to kernel-doc. * Usage: docproc doc file.tmpl * * dependency-generator: * Scans the template file and list all files * referenced in a format recognized by make. * Usage: docproc depend file.tmpl * Writes dependency information to stdout * in the following format: * file.tmpl src.c src2.c * The filenames are obtained from the following constructs: * !Efilename * !Ifilename * !Dfilename * !Ffilename * !Pfilename * */ #define _GNU_SOURCE #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <unistd.h> #include <limits.h> #include <errno.h> #include <sys/types.h> #include <sys/wait.h> /* exitstatus is used to keep track of any failing calls to kernel-doc, * but execution continues. */ int exitstatus = 0; typedef void DFL(char *); DFL *defaultline; typedef void FILEONLY(char * file); FILEONLY *internalfunctions; FILEONLY *externalfunctions; FILEONLY *symbolsonly; FILEONLY *findall; typedef void FILELINE(char * file, char * line); FILELINE * singlefunctions; FILELINE * entity_system; FILELINE * docsection; #define MAXLINESZ 2048 #define MAXFILES 250 #define KERNELDOCPATH "tools/kernel-doc/" #define KERNELDOC "kernel-doc" #define DOCBOOK "-docbook" #define LIST "-list" #define FUNCTION "-function" #define NOFUNCTION "-nofunction" #define NODOCSECTIONS "-no-doc-sections" static char *srctree, *kernsrctree; static char **all_list = NULL; static int all_list_len = 0; static void consume_symbol(const char *sym) { int i; for (i = 0; i < all_list_len; i++) { if (!all_list[i]) continue; if (strcmp(sym, all_list[i])) continue; all_list[i] = NULL; break; } } static void usage (void) { fprintf(stderr, "Usage: docproc {doc|depend} file\n"); fprintf(stderr, "Input is read from file.tmpl. Output is sent to stdout\n"); fprintf(stderr, "doc: frontend when generating kernel documentation\n"); fprintf(stderr, "depend: generate list of files referenced within file\n"); fprintf(stderr, "Environment variable SRCTREE: absolute path to sources.\n"); fprintf(stderr, " KBUILD_SRC: absolute path to kernel source tree.\n"); } /* * Execute kernel-doc with parameters given in svec */ static void exec_kernel_doc(char **svec) { pid_t pid; int ret; char real_filename[PATH_MAX + 1]; /* Make sure output generated so far are flushed */ fflush(stdout); switch (pid=fork()) { case -1: perror("fork"); exit(1); case 0: memset(real_filename, 0, sizeof(real_filename)); strncat(real_filename, kernsrctree, PATH_MAX); strncat(real_filename, "/" KERNELDOCPATH KERNELDOC, PATH_MAX - strlen(real_filename)); execvp(real_filename, svec); fprintf(stderr, "exec "); perror(real_filename); exit(1); default: waitpid(pid, &ret ,0); } if (WIFEXITED(ret)) exitstatus |= WEXITSTATUS(ret); else exitstatus = 0xff; } /* Types used to create list of all exported symbols in a number of files */ struct symbols { char *name; }; struct symfile { char *filename; struct symbols *symbollist; int symbolcnt; }; struct symfile symfilelist[MAXFILES]; int symfilecnt = 0; static void add_new_symbol(struct symfile *sym, char * symname) { sym->symbollist = realloc(sym->symbollist, (sym->symbolcnt + 1) * sizeof(char *)); sym->symbollist[sym->symbolcnt++].name = strdup(symname); } /* Add a filename to the list */ static struct symfile * add_new_file(char * filename) { symfilelist[symfilecnt++].filename = strdup(filename); return &symfilelist[symfilecnt - 1]; } /* Check if file already are present in the list */ static struct symfile * filename_exist(char * filename) { int i; for (i=0; i < symfilecnt; i++) if (strcmp(symfilelist[i].filename, filename) == 0) return &symfilelist[i]; return NULL; } /* * List all files referenced within the template file. * Files are separated by tabs. */ static void adddep(char * file) { printf("\t%s", file); } static void adddep2(char * file, char * line) { line = line; adddep(file); } static void noaction(char * line) { line = line; } static void noaction2(char * file, char * line) { file = file; line = line; } /* Echo the line without further action */ static void printline(char * line) { printf("%s", line); } /* * Find all symbols in filename that are exported with EXPORT_SYMBOL & * EXPORT_SYMBOL_GPL (& EXPORT_SYMBOL_GPL_FUTURE implicitly). * All symbols located are stored in symfilelist. */ static void find_export_symbols(char * filename) { FILE * fp; struct symfile *sym; char line[MAXLINESZ]; if (filename_exist(filename) == NULL) { char real_filename[PATH_MAX + 1]; memset(real_filename, 0, sizeof(real_filename)); strncat(real_filename, srctree, PATH_MAX); strncat(real_filename, "/", PATH_MAX - strlen(real_filename)); strncat(real_filename, filename, PATH_MAX - strlen(real_filename)); sym = add_new_file(filename); fp = fopen(real_filename, "r"); if (fp == NULL) { fprintf(stderr, "docproc: "); perror(real_filename); exit(1); } while (fgets(line, MAXLINESZ, fp)) { char *p; char *e; if (((p = strstr(line, "EXPORT_SYMBOL_GPL")) != NULL) || ((p = strstr(line, "EXPORT_SYMBOL")) != NULL)) { /* Skip EXPORT_SYMBOL{_GPL} */ while (isalnum(*p) || *p == '_') p++; /* Remove parentheses & additional whitespace */ while (isspace(*p)) p++; if (*p != '(') continue; /* Syntax error? */ else p++; while (isspace(*p)) p++; e = p; while (isalnum(*e) || *e == '_') e++; *e = '\0'; add_new_symbol(sym, p); } } fclose(fp); } } /* * Document all external or internal functions in a file. * Call kernel-doc with following parameters: * kernel-doc -docbook -nofunction function_name1 filename * Function names are obtained from all the src files * by find_export_symbols. * intfunc uses -nofunction * extfunc uses -function */ static void docfunctions(char * filename, char * type) { int i,j; int symcnt = 0; int idx = 0; char **vec; for (i=0; i <= symfilecnt; i++) symcnt += symfilelist[i].symbolcnt; vec = malloc((2 + 2 * symcnt + 3) * sizeof(char *)); if (vec == NULL) { perror("docproc: "); exit(1); } vec[idx++] = KERNELDOC; vec[idx++] = DOCBOOK; vec[idx++] = NODOCSECTIONS; for (i=0; i < symfilecnt; i++) { struct symfile * sym = &symfilelist[i]; for (j=0; j < sym->symbolcnt; j++) { vec[idx++] = type; consume_symbol(sym->symbollist[j].name); vec[idx++] = sym->symbollist[j].name; } } vec[idx++] = filename; vec[idx] = NULL; printf("<!-- %s -->\n", filename); exec_kernel_doc(vec); fflush(stdout); free(vec); } static void intfunc(char * filename) { docfunctions(filename, NOFUNCTION); } static void extfunc(char * filename) { docfunctions(filename, FUNCTION); } /* * Document specific function(s) in a file. * Call kernel-doc with the following parameters: * kernel-doc -docbook -function function1 [-function function2] */ static void singfunc(char * filename, char * line) { char *vec[200]; /* Enough for specific functions */ int i, idx = 0; int startofsym = 1; vec[idx++] = KERNELDOC; vec[idx++] = DOCBOOK; /* Split line up in individual parameters preceded by FUNCTION */ for (i=0; line[i]; i++) { if (isspace(line[i])) { line[i] = '\0'; startofsym = 1; continue; } if (startofsym) { startofsym = 0; vec[idx++] = FUNCTION; vec[idx++] = &line[i]; } } for (i = 0; i < idx; i++) { if (strcmp(vec[i], FUNCTION)) continue; consume_symbol(vec[i + 1]); } vec[idx++] = filename; vec[idx] = NULL; exec_kernel_doc(vec); } /* * Insert specific documentation section from a file. * Call kernel-doc with the following parameters: * kernel-doc -docbook -function "doc section" filename */ static void docsect(char *filename, char *line) { char *vec[6]; /* kerneldoc -docbook -function "section" file NULL */ char *s; for (s = line; *s; s++) if (*s == '\n') *s = '\0'; if (asprintf(&s, "DOC: %s", line) < 0) { perror("asprintf"); exit(1); } consume_symbol(s); free(s); vec[0] = KERNELDOC; vec[1] = DOCBOOK; vec[2] = FUNCTION; vec[3] = line; vec[4] = filename; vec[5] = NULL; exec_kernel_doc(vec); } static void find_all_symbols(char *filename) { char *vec[4]; /* kerneldoc -list file NULL */ pid_t pid; int ret, i, count, start; char real_filename[PATH_MAX + 1]; int pipefd[2]; char *data, *str; size_t data_len = 0; vec[0] = KERNELDOC; vec[1] = LIST; vec[2] = filename; vec[3] = NULL; if (pipe(pipefd)) { perror("pipe"); exit(1); } switch (pid=fork()) { case -1: perror("fork"); exit(1); case 0: close(pipefd[0]); dup2(pipefd[1], 1); memset(real_filename, 0, sizeof(real_filename)); strncat(real_filename, kernsrctree, PATH_MAX); strncat(real_filename, "/" KERNELDOCPATH KERNELDOC, PATH_MAX - strlen(real_filename)); execvp(real_filename, vec); fprintf(stderr, "exec "); perror(real_filename); exit(1); default: close(pipefd[1]); data = malloc(4096); do { while ((ret = read(pipefd[0], data + data_len, 4096)) > 0) { data_len += ret; data = realloc(data, data_len + 4096); } } while (ret == -EAGAIN); if (ret != 0) { perror("read"); exit(1); } waitpid(pid, &ret ,0); } if (WIFEXITED(ret)) exitstatus |= WEXITSTATUS(ret); else exitstatus = 0xff; count = 0; /* poor man's strtok, but with counting */ for (i = 0; i < data_len; i++) { if (data[i] == '\n') { count++; data[i] = '\0'; } } start = all_list_len; all_list_len += count; all_list = realloc(all_list, sizeof(char *) * all_list_len); str = data; for (i = 0; i < data_len && start != all_list_len; i++) { if (data[i] == '\0') { all_list[start] = str; str = data + i + 1; start++; } } } /* * Parse file, calling action specific functions for: * 1) Lines containing !E * 2) Lines containing !I * 3) Lines containing !D * 4) Lines containing !F * 5) Lines containing !P * 6) Lines containing !C * 7) Default lines - lines not matching the above */ static void parse_file(FILE *infile) { char line[MAXLINESZ]; char * s; while (fgets(line, MAXLINESZ, infile)) { if (line[0] == '!') { s = line + 2; switch (line[1]) { case 'E': while (*s && !isspace(*s)) s++; *s = '\0'; externalfunctions(line+2); break; case 'I': while (*s && !isspace(*s)) s++; *s = '\0'; internalfunctions(line+2); break; case 'D': while (*s && !isspace(*s)) s++; *s = '\0'; symbolsonly(line+2); break; case 'F': /* filename */ while (*s && !isspace(*s)) s++; *s++ = '\0'; /* function names */ while (isspace(*s)) s++; singlefunctions(line +2, s); break; case 'P': /* filename */ while (*s && !isspace(*s)) s++; *s++ = '\0'; /* DOC: section name */ while (isspace(*s)) s++; docsection(line + 2, s); break; case 'C': while (*s && !isspace(*s)) s++; *s = '\0'; if (findall) findall(line+2); break; default: defaultline(line); } } else { defaultline(line); } } fflush(stdout); } int main(int argc, char *argv[]) { FILE * infile; int i; srctree = getenv("SRCTREE"); if (!srctree) srctree = getcwd(NULL, 0); kernsrctree = getenv("KBUILD_SRC"); if (!kernsrctree || !*kernsrctree) kernsrctree = srctree; if (argc != 3) { usage(); exit(1); } /* Open file, exit on error */ infile = fopen(argv[2], "r"); if (infile == NULL) { fprintf(stderr, "docproc: "); perror(argv[2]); exit(2); } if (strcmp("doc", argv[1]) == 0) { /* Need to do this in two passes. * First pass is used to collect all symbols exported * in the various files; * Second pass generate the documentation. * This is required because some functions are declared * and exported in different files :-(( */ /* Collect symbols */ defaultline = noaction; internalfunctions = find_export_symbols; externalfunctions = find_export_symbols; symbolsonly = find_export_symbols; singlefunctions = noaction2; docsection = noaction2; findall = find_all_symbols; parse_file(infile); /* Rewind to start from beginning of file again */ fseek(infile, 0, SEEK_SET); defaultline = printline; internalfunctions = intfunc; externalfunctions = extfunc; symbolsonly = printline; singlefunctions = singfunc; docsection = docsect; findall = NULL; parse_file(infile); for (i = 0; i < all_list_len; i++) { if (!all_list[i]) continue; fprintf(stderr, "Warning: didn't use docs for %s\n", all_list[i]); } } else if (strcmp("depend", argv[1]) == 0) { /* Create first part of dependency chain * file.tmpl */ printf("%s\t", argv[2]); defaultline = noaction; internalfunctions = adddep; externalfunctions = adddep; symbolsonly = adddep; singlefunctions = adddep2; docsection = adddep2; findall = adddep; parse_file(infile); printf("\n"); } else { fprintf(stderr, "Unknown option: %s\n", argv[1]); exit(1); } fclose(infile); fflush(stdout); return exitstatus; }
the_stack_data/225143252.c
/* ** client.c -- a stream socket client demo */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #include <string.h> #include <netdb.h> #include <sys/types.h> #include <netinet/in.h> #include <sys/socket.h> #include <arpa/inet.h> #define PORT "35801" // the port client will be connecting to #define MAXDATASIZE 100 // max number of bytes we can get at once // get sockaddr, IPv4 or IPv6: void *get_in_addr(struct sockaddr *sa) { if (sa->sa_family == AF_INET) { return &(((struct sockaddr_in*)sa)->sin_addr); } return &(((struct sockaddr_in6*)sa)->sin6_addr); } int main(int argc, char *argv[]) { FILE *logfile; int sockfd, numbytes, second; char buf[MAXDATASIZE]; struct addrinfo hints, *servinfo, *p; int rv; char s[INET6_ADDRSTRLEN]; logfile=fopen("client.log","w+"); if (argc != 3) { fprintf(stderr,"usage: client hostname second\n"); exit(1); } second = atoi(argv[2]); memset(&hints, 0, sizeof hints); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; if ((rv = getaddrinfo(argv[1], PORT, &hints, &servinfo)) != 0) { fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv)); return 1; } // loop through all the results and connect to the first we can for(p = servinfo; p != NULL; p = p->ai_next) { if ((sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) { perror("client: socket"); continue; } if (connect(sockfd, p->ai_addr, p->ai_addrlen) == -1) { perror("client: connect"); close(sockfd); continue; } break; } if (p == NULL) { fprintf(stderr, "client: failed to connect\n"); return 2; } inet_ntop(p->ai_family, get_in_addr((struct sockaddr *)p->ai_addr), s, sizeof s); printf("client: connecting to %s\n", s); freeaddrinfo(servinfo); // all done with this structure if ((numbytes = recv(sockfd, buf, MAXDATASIZE-1, 0)) == -1) { perror("recv"); exit(1); } buf[numbytes] = '\0'; printf("client: received '%s'\n",buf); sleep(second); // if ((numbytes = send(sockfd, "Hello, world!\n", 14, 0)) == -1) { // perror("send"); // exit(1); // } fclose(logfile); close(sockfd); return 0; }
the_stack_data/142564.c
#include <stdio.h> #include <string.h> const char *reverse(const char *str); int main(int argc, char **argv) { char *str; switch (argc) { case 1: str = "Hello"; break; case 2: str = argv[1]; break; default: break; } printf("%s\n", reverse(str)); return 0; } const char *reverse(const char *str) { int length = strlen(str); char *result = (char *)malloc(sizeof(char) * (length + 1)); int i; int j; for (i = length - 1, j = 0; i >= 0; i--, j++) { result[j] = str[i]; } result[length] = '\0'; return result; }
the_stack_data/104828454.c
#include <arpa/inet.h> #include <assert.h> #include <ctype.h> #include <error.h> #include <errno.h> #include <float.h> #include <fcntl.h> #include <limits.h> #include <math.h> #include <locale.h> #include <netdb.h> #include <netinet/in.h> #include <netinet/ip.h> #include <pthread.h> #include <regex.h> #include <setjmp.h> #include <signal.h> #include <stdalign.h> #include <stdarg.h> #include <stdbool.h> #include <stddef.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <stdnoreturn.h> #include <string.h> #include <strings.h> #include <sys/mman.h> #include <sys/types.h> #include <sys/sendfile.h> #include <sys/socket.h> #include <sys/syscall.h> #include <sys/types.h> #include <sys/wait.h> #include <time.h> #include <uchar.h> #include <wchar.h> #include <wctype.h> #include <unistd.h> /* * This looks more complex than it should be. But we need to * get the type for the ~ right in round_down (it needs to be * as wide as the result!), and we want to evaluate the macro * arguments just once each. */ #define __round_mask(x, y) ((__typeof__(x))((y)-1)) #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1) #define round_down(x, y) ((x) & ~__round_mask(x, y)) #define BITS_PER_LONG (CHAR_BIT * 8) #define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1))) #define BITMAP_LAST_WORD_MASK(nbits) (~0UL >> (-(nbits) & (BITS_PER_LONG - 1))) #define BIT_MASK(nr) (((size_t)1) << ((nr) % BITS_PER_LONG)) #define BIT_WORD(nr) ((nr) / BITS_PER_LONG) #define min(x, y) ((x) < (y) ? (x) : (y)) /** * test_and_set_bit - Set a bit and return its old value * @nr: Bit to set * @addr: Address to count from */ static inline int test_and_set_bit(int nr, size_t *addr) { size_t mask = BIT_MASK(nr); size_t *p = ((size_t *)addr) + BIT_WORD(nr); size_t old; old = *p; *p = old | mask; return (old & mask) != 0; } /** * __fls - find last (most-significant) set bit in a long word * @word: the word to search * * Undefined if no set bit exists, so code should check against 0 first. */ static __always_inline unsigned long __fls(unsigned long word) { int num = BITS_PER_LONG - 1; #if BITS_PER_LONG == 64 if (!(word & (~0ul << 32))) { num -= 32; word <<= 32; } #endif if (!(word & (~0ul << (BITS_PER_LONG-16)))) { num -= 16; word <<= 16; } if (!(word & (~0ul << (BITS_PER_LONG-8)))) { num -= 8; word <<= 8; } if (!(word & (~0ul << (BITS_PER_LONG-4)))) { num -= 4; word <<= 4; } if (!(word & (~0ul << (BITS_PER_LONG-2)))) { num -= 2; word <<= 2; } if (!(word & (~0ul << (BITS_PER_LONG-1)))) num -= 1; return num; } /* * This is a common helper function for find_next_bit, find_next_zero_bit, and * find_next_and_bit. The differences are: * - The "invert" argument, which is XORed with each fetched word before * searching it for one bits. * - The optional "addr2", which is anded with "addr1" if present. */ static inline unsigned long _find_next_bit(const unsigned long *addr1, const unsigned long *addr2, unsigned long nbits, unsigned long start, unsigned long invert) { unsigned long tmp; if (start >= nbits) return nbits; tmp = addr1[start / BITS_PER_LONG]; if (addr2) tmp &= addr2[start / BITS_PER_LONG]; tmp ^= invert; /* Handle 1st word. */ tmp &= BITMAP_FIRST_WORD_MASK(start); start = round_down(start, BITS_PER_LONG); while (!tmp) { start += BITS_PER_LONG; if (start >= nbits) return nbits; tmp = addr1[start / BITS_PER_LONG]; if (addr2) tmp &= addr2[start / BITS_PER_LONG]; tmp ^= invert; } return min(start + ffs(tmp), nbits); } /* * Find the next set bit in a memory region. */ unsigned long find_next_bit(const unsigned long *addr, unsigned long size, unsigned long offset) { return _find_next_bit(addr, NULL, size, offset, 0UL); } unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size, unsigned long offset) { return _find_next_bit(addr, NULL, size, offset, ~0UL); } unsigned long find_next_and_bit(const unsigned long *addr1, const unsigned long *addr2, unsigned long size, unsigned long offset) { return _find_next_bit(addr1, addr2, size, offset, 0UL); } /* * Find the first set bit in a memory region. */ unsigned long find_first_bit(const unsigned long *addr, unsigned long size) { unsigned long idx; for (idx = 0; idx * BITS_PER_LONG < size; idx++) { if (addr[idx]) return min(idx * BITS_PER_LONG + ffs(addr[idx]), size); } return size; } unsigned long find_first_zero_bit(const unsigned long *addr, unsigned long size) { unsigned long idx; for (idx = 0; idx * BITS_PER_LONG < size; idx++) { if (addr[idx] != ~0UL) return min(idx * BITS_PER_LONG + ffs(~addr[idx]), size); } return size; } unsigned long find_last_bit(const unsigned long *addr, unsigned long size) { if (size) { unsigned long val = BITMAP_LAST_WORD_MASK(size); unsigned long idx = (size-1) / BITS_PER_LONG; do { val &= addr[idx]; if (val) return idx * BITS_PER_LONG + __fls(val); val = ~0ul; } while (idx--); } return size; } int main(int argc, char **argv) { (void)argc, (void)argv; unsigned long a[20] = {0}, *p = a; for (int i= 0; i < 10; i++) { __asm__ volatile ( "mov %%rax, %%rdx;" "mov $2, %%rcx;" "add $2, 16(%%rax);" ::"a"(p)); printf("%lu %p\n", a[2], (void *)p); } unsigned char arr[360] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, }; /* prints 0x40 */ p = (unsigned long *)arr; printf("%#lx %#lx\n", find_next_zero_bit(p, sizeof arr * CHAR_BIT, 95), ~0ul); return 0; }
the_stack_data/302736.c
/* Sequential Mandlebrot program */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <omp.h> #include <time.h> #define X_RESN 1000 /* x resolution */ #define Y_RESN 1000 /* y resolution */ #define MAX_ITER (2000) #define CHUNK 256 // ref: https://stackoverflow.com/questions/6749621/how-to-create-a-high-resolution-timer-in-linux-to-measure-program-performance // call this function to start a nanosecond-resolution timer struct timespec timer_start() { struct timespec start_time; clock_gettime(CLOCK_MONOTONIC, &start_time); return start_time; } // call this function to end a timer, returning nanoseconds elapsed as a long long timer_end(struct timespec start_time){ struct timespec end_time; clock_gettime(CLOCK_MONOTONIC, &end_time); long diffInNanos = (end_time.tv_sec - start_time.tv_sec) * (long)1e9 + (end_time.tv_nsec - start_time.tv_nsec); return diffInNanos; } typedef struct complextype { double real, imag; } Compl; int main(int argc, char *argv[]) { struct timespec vartime = timer_start(); /* Mandlebrot variables */ int *ks; ks = (int *)malloc((X_RESN*Y_RESN) * sizeof(int)); double *ds; ds = (double *)malloc((X_RESN*Y_RESN) * sizeof(double)); /* Calculate and draw points */ #pragma omp parallel default(shared) { int num_threads = omp_get_num_threads(); // printf("num_threads = %d\n", num_threads); #pragma omp for schedule(dynamic, CHUNK) for (int it = 0; it < X_RESN*Y_RESN; it++) { int i = it / Y_RESN; int j = it % Y_RESN; // mandelbrot set is defined in the region of x = [-2, +2] and y = [-2, +2] double u = ((double)i - (X_RESN / 2.0)) / (X_RESN / 4.0); double v = ((double)j - (Y_RESN / 2.0)) / (Y_RESN / 4.0); Compl z, c, t; z.real = z.imag = 0.0; c.real = v; c.imag = u; int k = 0; double d = 0.0; double lengthsq, temp; do { /* iterate for pixel color */ t = z; z.imag = 2.0 * t.real * t.imag + c.imag; z.real = t.real * t.real - t.imag * t.imag + c.real; lengthsq = z.real * z.real + z.imag * z.imag; d += pow(pow(z.imag - t.imag, 2.0) + pow(z.real - t.real, 2.0), 0.5); k++; } while (lengthsq < 4.0 && k < MAX_ITER); ks[it] = k; ds[it] = d; } } long time_elapsed_nanos = timer_end(vartime); double elapsed = time_elapsed_nanos*0.000000001; printf("%lf\n", elapsed); /* Program Finished */ return 0; }
the_stack_data/50138735.c
#include<stdio.h> int main() { FILE * fp; fp = fopen("file.txt","w+"); fputs("This is tutorialspoint.com",fp); fseek(fp, 7, SEEK_SET); fputs(" C Programming Language ",fp); fclose(fp); return (0); }
the_stack_data/151706958.c
// парсер логических выражений вида OR NOT AND XOR, с возможным заданием переменных TRUE | FALSE #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <string.h> #include <malloc.h> #include <ctype.h> #include <stdbool.h> const char TRUE[] = "True"; const char FALSE[] = "False"; const char EQUAL = '='; const char XOR = '+'; const char INVERSION = '!'; const char CONJUNCTION = '&'; const char DISJUNCTION = '|'; const char SEMICOLON = ';'; const char SPACE = ' '; const char LEFT_BRACKET = '('; const char RIGHT_BRACKET = ')'; const char ZERO = '0'; const char ONE = '1'; enum { BUFFER_SIZE = 256 }; enum { NOT_EXPR = -1, WRONG_FORMAT = -2, DELIMITER = -3, NUMBER = -4, NOT_FOUND = -5, ERROR = -6 }; const char* RESERVED[] = { "and", "not", "xor", "or", "True", "False" }; const char* SERVICE_CHRS[] = { "&", "!", "+", "|", "1", "0" }; typedef struct node { struct node *next; char* name; bool data; } node_t; typedef struct list { size_t size; node_t *head; node_t *tail; } list_t; typedef struct stack { char c; struct stack *next; } stack_t; /* Пpототипы функций */ void error_msg(); void print_result(int v); bool is_operator(char c); bool is_value(char c); bool is_possible(char c); bool has_operators(const char *expr); bool is_right_format(const char *str); /* работа со стэком*/ stack_t *push(stack_t *head, char c); char pop(stack_t **head); int get_priority(char c); /* работа со строками*/ /* замена подстроки строкой*/ char *str_replace(char *dst, int num, const char *str, const char *orig, const char *rep); /* удаление выбранного символа*/ size_t remove_ch(char *str, char c); /* работа с листом*/ list_t *create_list(); void list_push(list_t *lt, char *name, bool value); int get_value(list_t *lt, char *name); void list_pop(list_t *lt); /* парсинг <name>=True|False */ int analyse_and_add(char *expr, list_t *base); /* перевод выражения к виду (!1&0)|1+1 */ int convert(char *expr, list_t *base); /* перевод в обратную польскую нотацию*/ char *to_rpn(const char *expr, list_t *base); /* вычисление */ int calculate(char *expr, list_t *base); int main() { list_t *list = create_list(); char buf[BUFFER_SIZE]; do { char *success = fgets(buf, BUFFER_SIZE, stdin); if (success == NULL) { error_msg(); break; } // Проверка на правильность задания данных <name>=True|False int status = analyse_and_add(buf, list); if (status == WRONG_FORMAT) { error_msg(); break; } else if (status == NOT_EXPR) { int result = calculate(buf, list); print_result(result); break; } } while (true); while (list->size != 0) { list_pop(list); } free(list); return 0; } void error_msg() { printf("[error]"); } void print_result(int v) { if (v == 1) { printf(TRUE); } else if (v == 0) { printf(FALSE); } else { error_msg(); } } bool is_operator(char c) { return strchr("!&|+", c) != NULL; } bool is_value(char c) { return c == ONE || c == ZERO; } bool is_possible(char c) { return strchr("() \n\t", c) == NULL && !is_operator(c) && !is_value(c); } bool has_operators(const char *expr) { bool no_operators = strchr(expr, XOR) == NULL && strchr(expr, DISJUNCTION) == NULL && strchr(expr, CONJUNCTION) == NULL && strchr(expr, INVERSION) == NULL; return !no_operators; } bool is_right_format(const char *str) { bool only_small = false; // проверка на маленькие латинские буквы for (size_t i = 0; i < strlen(str); ++i) { if (str[i] >= 'a' && str[i] <= 'z') { only_small = true; } else { only_small = false; break; } } // проверка на запрещенные имена and or not xor; if (only_small) { for (size_t k = 0; RESERVED[k]; ++k) { if (strcmp(str, RESERVED[k]) == 0) return false; } } return only_small; } /* Функция push записывает на стек (на веpшину котоpого указывает HEAD) символ a . Возвpащает указатель на новую веpшину стека */ stack_t *push(stack_t *head, char c) { stack_t *ptr = (stack_t*)malloc(sizeof(stack_t)); if (ptr == NULL) { /* Если её нет - выход */ error_msg(); return NULL; } /* Инициализация созданной веpшины */ ptr->c = c; /* и подключение её к стеку */ ptr->next = head; /* PTR -новая веpшина стека */ return ptr; } /* Функция pop удаляет символ с веpшины стека. Возвpащает удаляемый символ. Изменяет указатель на веpшину стека */ char pop(stack_t **head) { stack_t *ptr = NULL; char el; /* Если стек пуст, возвpащается '\0' */ if (*head == NULL) return '\0'; /* в PTR - адpес веpшины стека */ ptr = *head; el = ptr->c; /* Изменяем адpес веpшины стека */ *head = ptr->next; /* Освобождение памяти */ free(ptr); /* Возвpат символа с веpшины стека */ return el; } /* Функция возвpащает пpиоpитет опеpации */ int get_priority(char c) { switch (c) { case '!': return 5; case '&': return 4; case '|': return 3; case '+': return 2; case '(': return 1; default: return 0; } } char *str_replace(char *dst, int size, const char *str, const char *orig, const char *rep) { if (!str || !orig || !rep) { return NULL; } const char* ptr; size_t len1 = strlen(orig); size_t len2 = strlen(rep); char* tmp = dst; size -= 1; while ((ptr = strstr(str, orig)) != NULL) { size -= (ptr - str) + len2; if (size < 1) break; strncpy(dst, str, (size_t)(ptr - str)); dst += ptr - str; strncpy(dst, rep, len2); dst += len2; str = ptr + len1; } for (; (*dst = *str) && (size > 0); --size) { ++dst; ++str; } return tmp; } size_t remove_ch(char *s, char ch) { size_t i = 0, j = 0; for (i = 0; s[i]; ++i) if (s[i] != ch) s[j++] = s[i]; s[j] = '\0'; return j; } list_t* create_list() { list_t *lt = (list_t*)malloc(sizeof(list_t)); if (!lt) return NULL; lt->size = 0; lt->head = NULL; lt->tail = lt->head; return lt; } void list_push(list_t *lt, char *name, bool value) { if (lt == NULL) return; node_t* node = (node_t*)malloc(sizeof(node_t)); if (!node) return; node->name = name; node->data = value; node->next = lt->head; lt->head = node; lt->size += 1; } int get_value(list_t *lt, char* name) { node_t *curr = lt->head; while (curr != NULL) { if (strcmp(name, curr->name) == 0) return curr->data; curr = curr->next; } return NOT_FOUND; } void list_pop(list_t *lt) { if ( lt == NULL || lt->size == 0) { return; } node_t *node = lt->head; free(lt->head->name); lt->size -= 1; lt->head = node->next; free(node); if (lt->size == 0) { lt->head = NULL; lt->tail = NULL; } } // Запись в лист пары <name>, <True|False> int analyse_and_add(char *expr, list_t *base) { if (!expr) return ERROR; // если не <name>=True|False char* pos = strchr(expr, EQUAL); char* end = strchr(expr, SEMICOLON); if (pos == NULL || end == NULL) return NOT_EXPR; remove_ch(expr, SPACE); pos = strchr(expr, EQUAL); end = strchr(expr, SEMICOLON); /* Записываем имя*/ size_t len_n = pos - expr; char* name = (char*)calloc(len_n + 1, sizeof(char)); if (!name) { return ERROR; } memmove(name, expr, sizeof(char) * len_n); if (!is_right_format(name)) { free(name); return WRONG_FORMAT; } /* Получаем значение*/ size_t len_v = end - pos; char* value = (char*) calloc(len_v, sizeof(char)); if (!value) { free(name); return ERROR; } memmove(value, pos + 1, sizeof(char) * (len_v-1)); /* Определяем True|False */ bool v; if (strcmp(value, TRUE) == 0) v = true; else if (strcmp(value, FALSE) == 0) v = false; else { free(name); free(value); return WRONG_FORMAT; } /* Записываем в лист ключ-значение*/ list_push(base, name, v); free(value); return v; } int convert(char *expr, list_t *base) { if (!expr || base == NULL) return ERROR; char temp[BUFFER_SIZE]; /* Замена ключевых слов на соответсвующие символы */ size_t i = 0; for (i = 0; RESERVED[i] && SERVICE_CHRS[i]; ++i) { if(str_replace(temp, sizeof(temp) - 1, expr, RESERVED[i], SERVICE_CHRS[i]) == NULL) return ERROR; else strcpy(expr, temp); } /* Замена переменных на их значение */ for (i = 0; expr[i]; ++i) { if (is_possible(expr[i])) { size_t j = i; for (j = i; is_possible(expr[j]) && expr[j]; ++j); char* varible = (char*)calloc(j - i + 1, sizeof(char)); if (!varible) { return ERROR; } memmove(varible, expr + i, j - i); if (strlen(varible) == 0) break; int status = get_value(base, varible); if (status == NOT_FOUND) { free(varible); return NOT_FOUND; } if (status == 0) if (str_replace(temp, sizeof(temp) - 1, expr, varible, "0") == NULL) return ERROR; if (status == 1) if (str_replace(temp, sizeof(temp) - 1, expr, varible, "1") == NULL) return ERROR; strcpy(expr, temp); free(varible); } } /* удаление пробелов*/ remove_ch(expr, SPACE); /* Успех*/ return 0; } char* to_rpn(const char *expr, list_t *base) { stack_t *operators = NULL; char* expr_in_rpn_format = (char*)malloc(BUFFER_SIZE * sizeof(char)); if (expr_in_rpn_format == NULL) return NULL; int k, point; k = point = 0; /* Повтоpяем , пока не дойдем до конца */ while (expr[k]) { /* Если очеpедной символ - ')' */ if (expr[k] == RIGHT_BRACKET) /* то выталкиваем из стека в выходную стpоку */ { /* все знаки опеpаций до ближайшей */ while ((operators->c) != LEFT_BRACKET) /* откpывающей скобки */ expr_in_rpn_format[point++] = pop(&operators); /* Удаляем из стека саму откpывающую скобку */ pop(&operators); } /* Если очеpедной символ - значение , то */ if (is_value(expr[k])) /* пеpеписываем её в выходную стpоку */ expr_in_rpn_format[point++] = expr[k]; /* Если очеpедной символ - '(' , то */ if (expr[k] == LEFT_BRACKET) /* заталкиваем её в стек */ operators = push(operators, LEFT_BRACKET); if (is_operator(expr[k])) /* Если следующий символ - знак опеpации , то: */ { /* если стек пуст */ if (operators == NULL) /* записываем в него опеpацию */ operators = push(operators, expr[k]); /* если не пуст */ else /* если пpиоpитет поступившей опеpации больше пpиоpитета опеpации на веpшине стека */ if (get_priority(operators->c) < get_priority(expr[k])) /* заталкиваем поступившую опеpацию на стек */ operators = push(operators, expr[k]); /* если пpиоpитет меньше */ else { while ((operators != NULL) && (get_priority(operators->c) >= get_priority(expr[k]))) /* пеpеписываем в выходную стpоку все опеpации с большим или pавным пpиоpитетом */ expr_in_rpn_format[point++] = pop(&operators); /* записываем в стек поступившую опеpацию */ operators = push(operators, expr[k]); } } /* Пеpеход к следующему символу входной стpоки */ k++; } /* после pассмотpения всего выpажения */ while (operators != NULL) /* Пеpеписываем все опеpации из */ expr_in_rpn_format[point++] = pop(&operators); /* стека в выходную стpоку */ expr_in_rpn_format[point] = '\0'; return expr_in_rpn_format; } int calculate(char *expr, list_t *base) { if (convert(expr, base) != 0) return ERROR; char* outstring = to_rpn(expr, base); if (outstring == NULL) return ERROR; // Если нет операторов и больше 1 переменной if (strlen(outstring) > 1 && !has_operators(outstring)) { free(outstring); return ERROR; } /* Выделене стэка для операций вычисления */ int *stack = (int*)malloc(strlen(expr)*sizeof(int)); if (stack == NULL) { free(outstring); return ERROR; } // sp = индекс ячейки, куда будет push-иться очередное число int sp = 0; // (sp-1) вершиной стека for (size_t k = 0; outstring[k]; ++k) { char c = outstring[k]; switch (c) { case '\n': break; case '+': stack[sp - 2] ^= stack[sp - 1]; sp--; break; case '|': stack[sp - 2] |= stack[sp - 1]; sp--; break; case '&': stack[sp - 2] = stack[sp - 1] & stack[sp - 2]; sp--; break; case '!': stack[sp - 1] = !stack[sp - 1]; break; case '0': { stack[sp++] = 0; break; } case '1': { stack[sp++] = 1; break; } default: free(stack); free(outstring); return WRONG_FORMAT; } } int result = stack[sp - 1]; free(outstring); free(stack); if (result == 0 || result == 1) return result; return ERROR; }
the_stack_data/11074150.c
/* 12131619 컴퓨터공학과 최재원 2017.11.27 Shell Project #3 */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/wait.h> #include <fcntl.h> #include <errno.h> #include <signal.h> #define MAX_CMD_ARG 10 #define MAX_CMD_GRP 10 #define PERM 0666 const char* prompt = "mysh> "; char* cmdGrps[MAX_CMD_GRP]; char* cmdVector[MAX_CMD_ARG]; char* buffer[MAX_CMD_ARG]; char cmdline[BUFSIZ]; char finish[BUFSIZ]; void fatal(char* str); void execute_cmdline(char* cmd); int parse_cmdgrp(char* cmdGrp); int makelist(char* s, const char* delimiters, char** list, int MAX_LIST); void sigchld_handler(int signo); void execute_program(char* argv); //start -> end 까지가 주어진 argument int main(int argc, char* argv[]) { pid_t pid; int token; struct sigaction act; //install sigchld handler sigemptyset(&act.sa_mask); act.sa_handler = sigchld_handler; act.sa_flags = SA_RESTART; sigaction(SIGCHLD, &act, NULL); //SIGINT, SIGQUIT, SIGTSTP signal을 무시하도록 설정 signal(SIGINT, SIG_IGN); signal(SIGQUIT, SIG_IGN); signal(SIGTSTP, SIG_IGN); signal(SIGTTOU, SIG_IGN); //tcsetpgrp이 background process에서 호출되는 경우 SIGTTOU signal이 날아감 (왜 fork한게 background process group이 되었냐면 setpgid로 새로운 프로세스 그룹을 만들었기 때문) //시작과 동시에는 home directory에 존재한다. if(chdir(getenv("HOME")) == -1) { fatal("shell init fail"); } while(1) { //프롬프트 출력 후 cmdline에 명령을 받아온다. fputs(prompt, stdout); fgets(cmdline, BUFSIZ, stdin); cmdline[strlen(cmdline) - 1] = '\0'; if(!strcmp(cmdline, "exit")) { //exit은 fork를 사용하지 않고 해당 쉘에서 곧바로 종료 printf("Good bye~\n"); exit(0); }else if(cmdline[0] == 'c' && cmdline[1] == 'd') { //cd 명령의 경우 우선 cd라는 이름이 파일이 shell bullitin 명령어 이기 때문에 /bin/sh, 즉 또 다른 쉘을 fork로 생성 후 -c옵션을 통해 //주어진 입력을 수행하도록 할 수 있지만 현재 진행중인 프로세스가 아닌 생성된 프로세스의 working directory가 변경되기 때문에 //chdir함수를 통하여 직접 이동시켜주어야 한다. makelist(cmdline, " \t", cmdVector, MAX_CMD_ARG); if(cmdVector[1] == NULL || !strcmp(cmdVector[1], "~")) { //cd에 주어진 인자가 아무것도 없거나 ~ 인 경우 home directory로 이동하게 해주어야 하는데 // ~ 은 실제 홈디렉토리의 주소가 아니기 때문에 환경변수에 저장되어 있는 값을 이용해 주어야 한다. cmdVector[1] = getenv("HOME"); } if(chdir(cmdVector[1]) == -1) { //에러가 발생 한 경우 에러 메세지 출력 perror(strerror(errno)); } }else { //얻어낸 cmdline을 이용하여 execute_cmdline함수 실행 execute_cmdline(cmdline); } fflush(stdin); fflush(stdout); } return 0; } //str이라는 에러메세지를 stderr에 출력 후 종료 void fatal(char* str) { perror(str); exit(1); } //fork를 이용하여 execute_cmdgrp 함수를 통해 하나씩 실행해준다. //parent는 wait을 통해 대기하기 때문에 한번의 루프에 하나의 명령을 수행하는 형태가 된다. void execute_cmdline(char* cmdline) { pid_t pid; int status; int stateCount = 0, commandCount = 0; int i = 0, j = 0; int background; int result; int p[2]; memset(cmdGrps, 0, sizeof(cmdGrps)); stateCount = makelist(cmdline, ";", cmdGrps, MAX_CMD_GRP); for(i = 0; i < stateCount; ++i) { commandCount = makelist(cmdGrps[i], "|", buffer, MAX_CMD_ARG); //|을 기준으로 나눈다. background = parse_cmdgrp(buffer[commandCount - 1]); //맨 마지막 커맨드로 background 여부 확인 switch(pid = fork()) { case -1: fatal("fork error"); case 0: setpgid(0, 0); //pgid를 자신의 pid와 동일하게 설정 -> 새로운 프로세스 그룹이 생성된다. //SIGINT, SIGQUIT, SIGTSTP 을 다시 default handler로 돌려놓는다. -> 이 것에 죽지않는 것은 shell만 되도록 signal(SIGINT, SIG_DFL); signal(SIGQUIT, SIG_DFL); signal(SIGTSTP, SIG_DFL); //foreground인 경우 잠시동안 터미널 제어권을 가져가도록 한다. if(background == 0) tcsetpgrp(STDIN_FILENO, getpgid(0)); //자신의 부모(위의 setpgid로 자신으로 변경되어 있음)가 터미널 제어권을 갖는다. for(j = 0; j < commandCount - 1; ++j) { pipe(p); switch(pid = fork()) { case -1: fatal("fork error"); case 0: dup2(p[1], 1); //A | B일때 A의 stdout은 파이프의 write로 close(p[0]); close(p[1]); execute_program(buffer[j]); default: dup2(p[0], 0); //이전 친구가 준 파이프를 stdin으로 한다. close(p[0]); close(p[1]); } } execute_program(buffer[j]); default: if(background == 1) { //background task의 경우 waitpid의 WNOHANG 옵션을 이용하여 대기하지 않는다. //또한 "방금" fork된 child를 대기해야 하므로 pid를 첫번째 인자로 넘겨준다. result = waitpid(pid, &status, WNOHANG); }else if(background == 0) { //단순히 wait으로 대기하게 되면 임의의 자식이 reap될 수 있기 때문에 waitpid에 pid를 넘겨주고 세번째 인자는 //0을 넘겨주어 기존 특정 프로세스를 기다리는 wait의 효과를 내어주었다. result = waitpid(pid, &status, 0); //foreground task가 종료된 후 다시 터미널 제어권을 가져온다. (standard input -> 0) tcsetpgrp(STDIN_FILENO, getpgid(0)); }else { fatal("execute_cmdline error"); } fflush(stdin); fflush(stdout); } } } //cmdGrp으로 주어진 명령을 tap이나 띄어쓰기로 나누어 (인자를 구분하여) //cmdVector 배열에 담아준다. background task의 경우 1을 아닌 경우 0을 반환한다. int parse_cmdgrp(char* cmdGrp) { int count = 0; int ret = -1; count = makelist(cmdGrp, " \t", cmdVector, MAX_CMD_ARG); //하나의 명령에 들어있는 여러 옵션들을 makelist를 이용하여 cmdVector배열에 넣어준다. cmdVector[count] = NULL; if(!strcmp(cmdVector[count - 1], "&")) { //background process인 경우 내부에서 fork을 이용하여 새롭게 하나의 프로세스를 생성 후 주어진 명령을 수행하게 한 뒤 cmdVector[count - 1] = '\0'; //null 로 치환 ret = 1; }else { ret = 0; } return ret; } //주어진 s를 delimiters를 구분자로 하여 나누어 list배열에 최대 MAX_LIST개를 넣어준다. //반환되는 값은 list 배열에 넣어준 token의 개수 int makelist(char* s, const char* delimiters, char** list, int MAX_LIST) { int numTokens = 0; char* snew = NULL; char* temp = malloc(strlen(s) + 1); strcpy(temp, s); if((s == NULL) || (delimiters == NULL)) return -1; snew = temp + strspn(temp, delimiters); //delimiter skip then snew pointer is pointing to start of the command if((list[numTokens] = strtok(temp, delimiters)) == NULL) { //token이 하나도 없다면 0을 반환한다. return numTokens; } numTokens = 1; while(1) { if((list[numTokens] = strtok(NULL, delimiters)) == NULL) break; //모두 다 찾은 경우 if(numTokens == (MAX_LIST - 1)) return -1; //최대 token의 수를 초과한 경우 -1 반환 numTokens++; } return numTokens; } //SIGCHLD signal이 오면 그 때 존재하는 모든 zombie process를 reap해준다. void sigchld_handler(int signo) { while(waitpid(-1, NULL, WNOHANG) > 0); } void execute_program(char* argv) { int fd; int i; parse_cmdgrp(argv); //탭, 띄어쓰기로 인자 구분 //cmdVector로 구분되어진 인자에 따라서 redirection이 존재한다면 그에 맞게 수정해준다. for(i = 0; cmdVector[i]; ++i) { if(!strcmp(cmdVector[i], ">")) { //stdout인 경우 if((fd = open(cmdVector[i + 1], O_CREAT | O_TRUNC | O_WRONLY, PERM)) == -1) //파일을 열어준 뒤 fatal("file open error"); dup2(fd, 1); //현재 프로세스의 stdout을 해당 파일로 바꾸어 준다. close(fd); cmdVector[i] = NULL; // execvp함수는 두 번째 인자로 null-terminated를 사용한다는 점을 이용하여 redirection 이후의 인자를 받지 못하도록 null값으로 수정해준다. }else if(!strcmp(cmdVector[i], "<")) { //stdin의 경우 if((fd = open(cmdVector[i + 1], O_RDONLY)) == -1) fatal("file open error"); dup2(fd, 0); //stdin을 해당 파일로 바꾸어 준다. close(fd); cmdVector[i] = NULL; } } execvp(cmdVector[0], cmdVector); fatal("execute_program error"); }
the_stack_data/1172839.c
/* 130. 11011 11011 00000 11011 11011 */ #include<stdio.h> void main() { int i,j; for(i = 0;i < 5;i++) { for(j = 0;j < 5;j++) { if(i == 2 && j == 2) { printf("%d",0); } else { printf("%d",1); } } printf("\n"); } }
the_stack_data/243892052.c
#include <stdio.h> /* print Fahrenheit-Celsius table */ int main(void) { int fahr; for (fahr = 0; fahr <= 300; fahr = fahr + 20) printf("%3d %6.1f\n", fahr, (5.0 / 9.0) * (fahr - 32)); return 0; }
the_stack_data/79220.c
// %%cpp pthread_cancel.c // %run gcc -fsanitize=thread pthread_cancel.c -lpthread -o pthread_cancel.exe // %run ./pthread_cancel.exe #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <sys/syscall.h> #include <sys/time.h> #include <pthread.h> const char* log_prefix(const char* file, int line) { struct timeval tp; gettimeofday(&tp, NULL); struct tm ltime; localtime_r(&tp.tv_sec, &ltime); static __thread char prefix[100]; size_t time_len = strftime(prefix, sizeof(prefix), "%H:%M:%S", &ltime); sprintf(prefix + time_len, ".%03ld %s:%d [tid=%ld]", tp.tv_usec / 1000, file, line, syscall(__NR_gettid)); return prefix; } #define log_printf_impl(fmt, ...) { time_t t = time(0); dprintf(2, "%s: " fmt "%s", log_prefix(__FILE__, __LINE__), __VA_ARGS__); } #define log_printf(...) log_printf_impl(__VA_ARGS__, "") // thread-aware assert #define ta_assert(stmt) if (stmt) {} else { log_printf("'" #stmt "' failed"); exit(EXIT_FAILURE); } static void* thread_func(void* arg) { log_printf(" Thread func started\n"); // В системных функциях разбросаны Cancellation points, в которых может быть прерван поток. sleep(2); log_printf(" Thread func finished\n"); // not printed because thread canceled return NULL; } int main() { log_printf("Main func started\n"); pthread_t thread; log_printf("Thread creating\n"); ta_assert(pthread_create(&thread, NULL, thread_func, 0) == 0); sleep(1); log_printf("Thread canceling\n"); ta_assert(pthread_cancel(thread) == 0); // принимает id потока и прерывает его. ta_assert(pthread_join(thread, NULL) == 0); // Если не сделать join, то останется зомби-поток. log_printf("Thread joined\n"); log_printf("Main func finished\n"); return 0; }
the_stack_data/617950.c
void a() { } void b() { } void c() { } void d() { } void e() { } void f() { } int main( int argc, char** argv ) { motion_prepend_after_call( c, a ); motion_prepend_after_call( d, a ); motion_prepend_advice_around_call( e, a, c ); a(); b(); return 0; }
the_stack_data/6461.c
/** * ppjC je programski jezik podskup jezika C definiran u dokumentu * https://github.com/fer-ppj/ppj-labosi/raw/master/upute/ppj-labos-upute.pdf * * ova skripta poziva ppjC kompajler (za sada samo analizator) pritiskom * na tipku [Ctrl+S], [Shift+Enter] ili [Alt+3] i prikazuje rezultat analize. * * ne garantiram tocnost leksera, sintaksnog niti semantickog analizatora koji * se ovdje pokrece. * * URL skripte prati verzije izvornog programa, tako da je moguca razmjena * izvornih programa u timu putem URL-ova. */ int printf(const char format[]) { /* i wish i could printf */ return 0; } int main(void) { char c = 'a'; int a[c]; return 0; }
the_stack_data/3262171.c
// Copyright 2013 Google Inc. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <pthread.h> #define MAX_STRING 100 #define EXP_TABLE_SIZE 1000 #define MAX_EXP 6 #define MAX_SENTENCE_LENGTH 1000 #define MAX_CODE_LENGTH 40 /* * The size of the hash table for the vocabulary. * The vocabulary won't be allowed to grow beyond 70% of this number. * For instance, if the hash table has 30M entries, then the maximum * vocab size is 21M. This is to minimize the occurrence (and performance * impact) of hash collisions. */ const int vocab_hash_size = 30000000; // Maximum 30 * 0.7 = 21M words in the vocabulary typedef float real; // Precision of float numbers /** * ======== vocab_word ======== * Properties: * cn - The word frequency (number of times it appears). * word - The actual string word. * point - The path indices from root to a word leaf. * code - huffman encoded code for a word, e.g. 0101110. */ struct vocab_word { long long cn; int *point; char *word, *code, codelen; }; /* * ======== Global Variables ======== * */ char train_file[MAX_STRING], output_file[MAX_STRING]; char save_vocab_file[MAX_STRING], read_vocab_file[MAX_STRING]; /* * ======== vocab ======== * This array will hold all of the words in the vocabulary. * This is internal state. */ struct vocab_word *vocab; int binary = 0, cbow = 1, debug_mode = 2, window = 5, min_count = 5, num_threads = 12, min_reduce = 1; /* * ======== vocab_hash ======== * This array is the hash table for the vocabulary. Word strings are hashed * to a hash code (an integer), then the hash code is used as the index into * 'vocab_hash', to retrieve the index of the word within the 'vocab' array. */ int *vocab_hash; /* * ======== vocab_max_size ======== * This is not a limit on the number of words in the vocabulary, but rather * a chunk size for allocating the vocabulary table. The vocabulary table will * be expanded as necessary, and is allocated, e.g., 1,000 words at a time. * * ======== vocab_size ======== * Stores the number of unique words in the vocabulary. * This is not a parameter, but rather internal state. * * ======== layer1_size ======== * This is the number of features in the word vectors. * It is the number of neurons in the hidden layer of the model. */ long long vocab_max_size = 1000, vocab_size = 0, layer1_size = 100; /* * */ long long train_words = 0, word_count_actual = 0, iter = 5, file_size = 0, classes = 0; /* * ======== alpha ======== * TODO - This is a learning rate parameter. * * ======== starting_alpha ======== * * ======== sample ======== * This parameter controls the subsampling of frequent words. * Smaller values of 'sample' mean words are less likely to be kept. * Set 'sample' to 0 to disable subsampling. * See the comments in the subsampling section for more details. */ real alpha = 0.025, starting_alpha, sample = 1e-3; /* * IMPORTANT - Note that the weight matrices are stored as 1D arrays, not * 2D matrices, so to access row 'i' of syn0, the index is (i * layer1_size). * * ======== syn0 ======== * This is the hidden layer weights (which is also the word vectors!) * * ======== syn1 ======== * This is the output layer weights *if using heirarchical softmax* * * ======== syn1neg ======== * This is the output layer weights *if using negative sampling* * * ======== expTable ======== * Stores precalcultaed activations for the output layer. */ real *syn0, *syn1, *syn1neg, *expTable; clock_t start; int hs = 0, negative = 5; const int table_size = 1e8; int *table; /** * ======== InitUnigramTable ======== * This table is used to implement negative sampling. * Each word is given a weight equal to it's frequency (word count) raised to * the 3/4 power. The probability for a selecting a word is just its weight * divided by the sum of weights for all words. * * Note that the vocabulary has been sorted by word count, descending, such * that we will go through the vocabulary from most frequent to least. */ void InitUnigramTable() { int a, i; double train_words_pow = 0; double d1, power = 0.75; // Allocate the table. It's bigger than the vocabulary, because words will // appear in it multiple times based on their frequency. // Every vocab word appears at least once in the table. // The size of the table relative to the size of the vocab dictates the // resolution of the sampling. A larger unigram table means the negative // samples will be selected with a probability that more closely matches the // probability calculated by the equation. table = (int *)malloc(table_size * sizeof(int)); // Calculate the denominator, which is the sum of weights for all words. for (a = 0; a < vocab_size; a++) train_words_pow += pow(vocab[a].cn, power); // 'i' is the vocabulary index of the current word, whereas 'a' will be // the index into the unigram table. i = 0; // Calculate the probability that we choose word 'i'. This is a fraction // betwee 0 and 1. d1 = pow(vocab[i].cn, power) / train_words_pow; // Loop over all positions in the table. for (a = 0; a < table_size; a++) { // Store word 'i' in this position. Word 'i' will appear multiple times // in the table, based on its frequency in the training data. table[a] = i; // If the fraction of the table we have filled is greater than the // probability of choosing this word, then move to the next word. if (a / (double)table_size > d1) { // Move to the next word. i++; // Calculate the probability for the new word, and accumulate it with // the probabilities of all previous words, so that we can compare d1 to // the percentage of the table that we have filled. d1 += pow(vocab[i].cn, power) / train_words_pow; } // Don't go past the end of the vocab. // The total weights for all words should sum up to 1, so there shouldn't // be any extra space at the end of the table. Maybe it's possible to be // off by 1, though? Or maybe this is just precautionary. if (i >= vocab_size) i = vocab_size - 1; } } /** * ======== ReadWord ======== * Reads a single word from a file, assuming space + tab + EOL to be word * boundaries. * * Parameters: * word - A char array allocated to hold the maximum length string. * fin - The training file. */ void ReadWord(char *word, FILE *fin) { // 'a' will be the index into 'word'. int a = 0, ch; // Read until the end of the word or the end of the file. while (!feof(fin)) { // Get the next character. ch = fgetc(fin); // ASCII Character 13 is a carriage return 'CR' whereas character 10 is // newline or line feed 'LF'. if (ch == 13) continue; // Check for word boundaries... if ((ch == ' ') || (ch == '\t') || (ch == '\n')) { // If the word has at least one character, we're done. if (a > 0) { // Put the newline back before returning so that we find it next time. if (ch == '\n') ungetc(ch, fin); break; } // If the word is empty and the character is newline, treat this as the // end of a "sentence" and mark it with the token </s>. if (ch == '\n') { strcpy(word, (char *)"</s>"); return; // If the word is empty and the character is tab or space, just continue // on to the next character. } else continue; } // If the character wasn't space, tab, CR, or newline, add it to the word. word[a] = ch; a++; // If the word's too long, truncate it, but keep going till we find the end // of it. if (a >= MAX_STRING - 1) a--; } // Terminate the string with null. word[a] = 0; } /** * ======== GetWordHash ======== * Returns hash value of a word. The hash is an integer between 0 and * vocab_hash_size (default is 30E6). * * For example, the word 'hat': * hash = ((((h * 257) + a) * 257) + t) % 30E6 */ int GetWordHash(char *word) { unsigned long long a, hash = 0; for (a = 0; a < strlen(word); a++) hash = hash * 257 + word[a]; hash = hash % vocab_hash_size; return hash; } /** * ======== SearchVocab ======== * Lookup the index in the 'vocab' table of the given 'word'. * Returns -1 if the word is not found. * This function uses a hash table for fast lookup. */ int SearchVocab(char *word) { // Compute the hash value for 'word'. unsigned int hash = GetWordHash(word); // Lookup the index in the hash table, handling collisions as needed. // See 'AddWordToVocab' to see how collisions are handled. while (1) { // If the word isn't in the hash table, it's not in the vocab. if (vocab_hash[hash] == -1) return -1; // If the input word matches the word stored at the index, we're good, // return the index. if (!strcmp(word, vocab[vocab_hash[hash]].word)) return vocab_hash[hash]; // Otherwise, we need to scan through the hash table until we find it. hash = (hash + 1) % vocab_hash_size; } // This will never be reached. return -1; } /** * ======== ReadWordIndex ======== * Reads the next word from the training file, and returns its index into the * 'vocab' table. */ int ReadWordIndex(FILE *fin) { char word[MAX_STRING]; ReadWord(word, fin); if (feof(fin)) return -1; return SearchVocab(word); } /** * ======== AddWordToVocab ======== * Adds a new word to the vocabulary (one that hasn't been seen yet). */ int AddWordToVocab(char *word) { // Measure word length. unsigned int hash, length = strlen(word) + 1; // Limit string length (default limit is 100 characters). if (length > MAX_STRING) length = MAX_STRING; // Allocate and store the word string. vocab[vocab_size].word = (char *)calloc(length, sizeof(char)); strcpy(vocab[vocab_size].word, word); // Initialize the word frequency to 0. vocab[vocab_size].cn = 0; // Increment the vocabulary size. vocab_size++; // Reallocate memory if needed if (vocab_size + 2 >= vocab_max_size) { vocab_max_size += 1000; vocab = (struct vocab_word *)realloc(vocab, vocab_max_size * sizeof(struct vocab_word)); } // Add the word to the 'vocab_hash' table so that we can map quickly from the // string to its vocab_word structure. // Hash the word to an integer between 0 and 30E6. hash = GetWordHash(word); // If the spot is already taken in the hash table, find the next empty spot. while (vocab_hash[hash] != -1) hash = (hash + 1) % vocab_hash_size; // Map the hash code to the index of the word in the 'vocab' array. vocab_hash[hash] = vocab_size - 1; // Return the index of the word in the 'vocab' array. return vocab_size - 1; } // Used later for sorting by word counts int VocabCompare(const void *a, const void *b) { return ((struct vocab_word *)b)->cn - ((struct vocab_word *)a)->cn; } /** * ======== SortVocab ======== * Sorts the vocabulary by frequency using word counts, and removes words that * occur fewer than 'min_count' times in the training text. * * Removing words from the vocabulary requires recomputing the hash table. */ void SortVocab() { int a, size; unsigned int hash; /* * Sort the vocabulary by number of occurrences, in descending order. * * Keep </s> at the first position by sorting starting from index 1. * * Sorting the vocabulary this way causes the words with the fewest * occurrences to be at the end of the vocabulary table. This will allow us * to free the memory associated with the words that get filtered out. */ qsort(&vocab[1], vocab_size - 1, sizeof(struct vocab_word), VocabCompare); // Clear the vocabulary hash table. for (a = 0; a < vocab_hash_size; a++) vocab_hash[a] = -1; // Store the initial vocab size to use in the for loop condition. size = vocab_size; // Recompute the number of training words. train_words = 0; // For every word currently in the vocab... for (a = 0; a < size; a++) { // If it occurs fewer than 'min_count' times, remove it from the vocabulary. if ((vocab[a].cn < min_count) && (a != 0)) { // Decrease the size of the new vocabulary. vocab_size--; // Free the memory associated with the word string. free(vocab[a].word); } else { // Hash will be re-computed, as after the sorting it is not actual hash=GetWordHash(vocab[a].word); while (vocab_hash[hash] != -1) hash = (hash + 1) % vocab_hash_size; vocab_hash[hash] = a; train_words += vocab[a].cn; } } // Reallocate the vocab array, chopping off all of the low-frequency words at // the end of the table. vocab = (struct vocab_word *)realloc(vocab, (vocab_size + 1) * sizeof(struct vocab_word)); // Allocate memory for the binary tree construction for (a = 0; a < vocab_size; a++) { vocab[a].code = (char *)calloc(MAX_CODE_LENGTH, sizeof(char)); vocab[a].point = (int *)calloc(MAX_CODE_LENGTH, sizeof(int)); } } // Reduces the vocabulary by removing infrequent tokens void ReduceVocab() { int a, b = 0; unsigned int hash; for (a = 0; a < vocab_size; a++) if (vocab[a].cn > min_reduce) { vocab[b].cn = vocab[a].cn; vocab[b].word = vocab[a].word; b++; } else { free(vocab[a].word); } vocab_size = b; for (a = 0; a < vocab_hash_size; a++) vocab_hash[a] = -1; for (a = 0; a < vocab_size; a++) { // Hash will be re-computed, as it is not actual hash = GetWordHash(vocab[a].word); while (vocab_hash[hash] != -1) hash = (hash + 1) % vocab_hash_size; vocab_hash[hash] = a; } fflush(stdout); min_reduce++; } /** * ======== CreateBinaryTree ======== * Create binary Huffman tree using the word counts. * Frequent words will have short unique binary codes. * Huffman encoding is used for lossless compression. * For each vocabulary word, the vocab_word structure includes a `point` array, * which is the list of internal tree nodes which: * 1. Define the path from the root to the leaf node for the word. * 2. Each correspond to a row of the output matrix. * The `code` array is a list of 0s and 1s which specifies whether each output * in `point` should be trained to output 0 or 1. */ void CreateBinaryTree() { long long a, b, i, min1i, min2i, pos1, pos2, point[MAX_CODE_LENGTH]; char code[MAX_CODE_LENGTH]; // Default is 40 // Note that calloc initializes these arrays to 0. long long *count = (long long *)calloc(vocab_size * 2 + 1, sizeof(long long)); long long *binary = (long long *)calloc(vocab_size * 2 + 1, sizeof(long long)); long long *parent_node = (long long *)calloc(vocab_size * 2 + 1, sizeof(long long)); // The count array is twice the size of the vocabulary, plus one. // - The first half of `count` becomes a list of the word counts // for each word in the vocabulary. We do not modify this part of the // list. // - The second half of `count` is set to a large positive integer (1 // quadrillion). When we combine two trees under a word (e.g., word_id // 13), then we place the total weight of those subtrees into the word's // position in the second half (e.g., count[vocab_size + 13]). // for (a = 0; a < vocab_size; a++) count[a] = vocab[a].cn; for (a = vocab_size; a < vocab_size * 2; a++) count[a] = 1e15; // `pos1` and `pos2` are indeces into the `count` array. // - `pos1` starts at the middle of `count` (the end of the list of word // counts) and moves left. // - `pos2` starts at the beginning of the list of large integers and moves // right. pos1 = vocab_size - 1; pos2 = vocab_size; /* =============================== * Step 1: Create Huffman Tree * =============================== * [Original Comment] Following algorithm constructs the Huffman tree by * adding one node at a time * * The Huffman coding algorithm starts with every node as its own tree, and * then combines the two smallest trees on each step. The weight of a tree is * the sum of the word counts for the words it contains. * * Once the tree is constructed, you can use the `parent_node` array to * navigate it. For the word at index 13, for example, you would look at * parent_node[13], and then parent_node[parent_node[13]], and so on, till * you reach the root. * * A Huffman tree stores all of the words in the vocabulary at the leaves. * Frequent words have short paths, and infrequent words have long paths. * Here, we are also associating each internal node of the tree with a * row of the output matrix. Every time we combine two trees and create a * new node, we give it a row in the output matrix. */ // The number of tree combinations needed is equal to the size of the vocab, // minus 1. for (a = 0; a < vocab_size - 1; a++) { // First, find two smallest nodes 'min1, min2' // Find min1 (at index `min1i`) if (pos1 >= 0) { if (count[pos1] < count[pos2]) { min1i = pos1; pos1--; } else { min1i = pos2; pos2++; } } else { min1i = pos2; pos2++; } // Find min2 (at index `min2i`). if (pos1 >= 0) { if (count[pos1] < count[pos2]) { min2i = pos1; pos1--; } else { min2i = pos2; pos2++; } } else { min2i = pos2; pos2++; } // Calculate the combined weight. We could be combining two words, a word // and a tree, or two trees. count[vocab_size + a] = count[min1i] + count[min2i]; // Store the path for working back up the tree. parent_node[min1i] = vocab_size + a; parent_node[min2i] = vocab_size + a; // binary[min1i] = 0; // This is implied. // min1 is the (left?) node and is labeled '0', min2 is the (right?) node // and is labeled '1'. binary[min2i] = 1; } /* ========================================== * Step 2: Define Samples for Each Word * ========================================== * [Original Comment] Now assign binary code to each vocabulary word * * vocab[word] * .code - A variable-length string of 0s and 1s. * .point - A variable-length array of output row indeces. * .codelen - The length of the `code` array. * The point array has length `codelen + 1`. * */ // For each word in the vocabulary... for (a = 0; a < vocab_size; a++) { b = a; i = 0; // `i` stores the code length. // Construct the binary code... // `code` stores 1s and 0s. // `point` stores indeces. // This loop works backwards from the leaf, so the `code` and `point` // lists end up in reverse order. while (1) { // Lookup whether this is on the left or right of its parent node. code[i] = binary[b]; // Note: point[0] always holds the word iteself... point[i] = b; // Increment the code length. i++; // This will always return an index in the second half of the array. b = parent_node[b]; // We've reached the root when... if (b == vocab_size * 2 - 2) break; } // Record the code length (the length of the `point` list). vocab[a].codelen = i; // Point[0] stores the root node of the path and the root node of // the huffman tree is at index `vocab_size - 2` of the output matrix. vocab[a].point[0] = vocab_size - 2; // For each bit in this word's code... for (b = 0; b < i; b++) { // The binary in array code is in reverse order, that is from leaf to root. // It is reversed here, results code is from root to leaf. vocab[a].code[i - b - 1] = code[b]; // Store the row indeces of the internal nodes leading to this word. // These are the set of outputs which will be trained every time // this word is encountered in the training data as an output word. vocab[a].point[i - b] = point[b] - vocab_size; } } free(count); free(binary); free(parent_node); } /** * ======== LearnVocabFromTrainFile ======== * Builds a vocabulary from the words found in the training file. * * This function will also build a hash table which allows for fast lookup * from the word string to the corresponding vocab_word object. * * Words that occur fewer than 'min_count' times will be filtered out of * vocabulary. */ void LearnVocabFromTrainFile() { char word[MAX_STRING]; FILE *fin; long long a, i; // Populate the vocab table with -1s. for (a = 0; a < vocab_hash_size; a++) vocab_hash[a] = -1; // Open the training file. fin = fopen(train_file, "rb"); if (fin == NULL) { printf("ERROR: training data file not found!\n"); exit(1); } vocab_size = 0; // The special token </s> is used to mark the end of a sentence. In training, // the context window does not go beyond the ends of a sentence. // // Add </s> explicitly here so that it occurs at position 0 in the vocab. AddWordToVocab((char *)"</s>"); while (1) { // Read the next word from the file into the string 'word'. ReadWord(word, fin); // Stop when we've reached the end of the file. if (feof(fin)) break; // Count the total number of tokens in the training text. train_words++; // Print progress at every 100,000 words. if ((debug_mode > 1) && (train_words % 100000 == 0)) { printf("%lldK%c", train_words / 1000, 13); fflush(stdout); } // Look up this word in the vocab to see if we've already added it. i = SearchVocab(word); // If it's not in the vocab... if (i == -1) { // ...add it. a = AddWordToVocab(word); // Initialize the word frequency to 1. vocab[a].cn = 1; // If it's already in the vocab, just increment the word count. } else vocab[i].cn++; // If the vocabulary has grown too large, trim out the most infrequent // words. The vocabulary is considered "too large" when it's filled more // than 70% of the hash table (this is to try and keep hash collisions // down). if (vocab_size > vocab_hash_size * 0.7) ReduceVocab(); } // Sort the vocabulary in descending order by number of word occurrences. // Remove (and free the associated memory) for all the words that occur // fewer than 'min_count' times. SortVocab(); // Report the final vocabulary size, and the total number of words // (excluding those filtered from the vocabulary) in the training set. if (debug_mode > 0) { printf("Vocab size: %lld\n", vocab_size); printf("Words in train file: %lld\n", train_words); } file_size = ftell(fin); fclose(fin); } void SaveVocab() { long long i; FILE *fo = fopen(save_vocab_file, "wb"); for (i = 0; i < vocab_size; i++) fprintf(fo, "%s %lld\n", vocab[i].word, vocab[i].cn); fclose(fo); } void ReadVocab() { long long a, i = 0; char c; char word[MAX_STRING]; FILE *fin = fopen(read_vocab_file, "rb"); if (fin == NULL) { printf("Vocabulary file not found\n"); exit(1); } for (a = 0; a < vocab_hash_size; a++) vocab_hash[a] = -1; vocab_size = 0; while (1) { ReadWord(word, fin); if (feof(fin)) break; a = AddWordToVocab(word); fscanf(fin, "%lld%c", &vocab[a].cn, &c); i++; } SortVocab(); if (debug_mode > 0) { printf("Vocab size: %lld\n", vocab_size); printf("Words in train file: %lld\n", train_words); } fin = fopen(train_file, "rb"); if (fin == NULL) { printf("ERROR: training data file not found!\n"); exit(1); } fseek(fin, 0, SEEK_END); file_size = ftell(fin); fclose(fin); } /** * ======== InitNet ======== * */ void InitNet() { long long a, b; unsigned long long next_random = 1; // Allocate the hidden layer of the network, which is what becomes the word vectors. // The variable for this layer is 'syn0'. a = posix_memalign((void **)&syn0, 128, (long long)vocab_size * layer1_size * sizeof(real)); if (syn0 == NULL) {printf("Memory allocation failed\n"); exit(1);} // If we're using hierarchical softmax for training... if (hs) { a = posix_memalign((void **)&syn1, 128, (long long)vocab_size * layer1_size * sizeof(real)); if (syn1 == NULL) {printf("Memory allocation failed\n"); exit(1);} for (a = 0; a < vocab_size; a++) for (b = 0; b < layer1_size; b++) syn1[a * layer1_size + b] = 0; } // If we're using negative sampling for training... if (negative>0) { // Allocate the output layer of the network. // The variable for this layer is 'syn1neg'. // This layer has the same size as the hidden layer, but is the transpose. a = posix_memalign((void **)&syn1neg, 128, (long long)vocab_size * layer1_size * sizeof(real)); if (syn1neg == NULL) {printf("Memory allocation failed\n"); exit(1);} // Set all of the weights in the output layer to 0. for (a = 0; a < vocab_size; a++) for (b = 0; b < layer1_size; b++) syn1neg[a * layer1_size + b] = 0; } // Randomly initialize the weights for the hidden layer (word vector layer). // TODO - What's the equation here? for (a = 0; a < vocab_size; a++) for (b = 0; b < layer1_size; b++) { next_random = next_random * (unsigned long long)25214903917 + 11; syn0[a * layer1_size + b] = (((next_random & 0xFFFF) / (real)65536) - 0.5) / layer1_size; } // Create a binary tree for Huffman coding. // TODO - As best I can tell, this is only used for hierarchical softmax training... CreateBinaryTree(); } /** * ======== TrainModelThread ======== * This function performs the training of the model. */ void *TrainModelThread(void *id) { /* * word - Stores the index of a word in the vocab table. * word_count - Stores the total number of training words processed. */ long long a, b, d, cw, word, last_word, sentence_length = 0, sentence_position = 0; long long word_count = 0, last_word_count = 0, sen[MAX_SENTENCE_LENGTH + 1]; long long l1, l2, c, target, label, local_iter = iter; unsigned long long next_random = (long long)id; real f, g; clock_t now; // neu1 is only used by the CBOW architecture. real *neu1 = (real *)calloc(layer1_size, sizeof(real)); // neu1e is used by both architectures. real *neu1e = (real *)calloc(layer1_size, sizeof(real)); // Open the training file and seek to the portion of the file that this // thread is responsible for. FILE *fi = fopen(train_file, "rb"); fseek(fi, file_size / (long long)num_threads * (long long)id, SEEK_SET); // This loop covers the whole training operation... while (1) { /* * ======== Variables ======== * iter - This is the number of training epochs to run; default is 5. * word_count - The number of input words processed. * train_words - The total number of words in the training text (not * including words removed from the vocabuly by ReduceVocab). */ // This block prints a progress update, and also adjusts the training // 'alpha' parameter. if (word_count - last_word_count > 10000) { word_count_actual += word_count - last_word_count; last_word_count = word_count; // The percentage complete is based on the total number of passes we are // doing and not just the current pass. if ((debug_mode > 1)) { now=clock(); printf("%cAlpha: %f Progress: %.2f%% Words/thread/sec: %.2fk ", 13, alpha, // Percent complete = [# of input words processed] / // ([# of passes] * [# of words in a pass]) word_count_actual / (real)(iter * train_words + 1) * 100, word_count_actual / ((real)(now - start + 1) / (real)CLOCKS_PER_SEC * 1000)); fflush(stdout); } // Update alpha to: [initial alpha] * [percent of training remaining] // This means that alpha will gradually decrease as we progress through // the training text. alpha = starting_alpha * (1 - word_count_actual / (real)(iter * train_words + 1)); // Don't let alpha go below [initial alpha] * 0.0001. if (alpha < starting_alpha * 0.0001) alpha = starting_alpha * 0.0001; } // This 'if' block retrieves the next sentence from the training text and // stores it in 'sen'. // TODO - Under what condition would sentence_length not be zero? if (sentence_length == 0) { while (1) { // Read the next word from the training data and lookup its index in // the vocab table. 'word' is the word's vocab index. word = ReadWordIndex(fi); if (feof(fi)) break; // If the word doesn't exist in the vocabulary, skip it. if (word == -1) continue; // Track the total number of training words processed. word_count++; // 'vocab' word 0 is a special token "</s>" which indicates the end of // a sentence. if (word == 0) break; /* * ================================= * Subsampling of Frequent Words * ================================= * This code randomly discards training words, but is designed to * keep the relative frequencies the same. That is, less frequent * words will be discarded less often. * * We first calculate the probability that we want to *keep* the word; * this is the value 'ran'. Then, to decide whether to keep the word, * we generate a random fraction (0.0 - 1.0), and if 'ran' is smaller * than this number, we discard the word. This means that the smaller * 'ran' is, the more likely it is that we'll discard this word. * * The quantity (vocab[word].cn / train_words) is the fraction of all * the training words which are 'word'. Let's represent this fraction * by x. * * Using the default 'sample' value of 0.001, the equation for ran is: * ran = (sqrt(x / 0.001) + 1) * (0.001 / x) * * You can plot this function to see it's behavior; it has a curved * L shape. * * Here are some interesting points in this function (again this is * using the default sample value of 0.001). * - ran = 1 (100% chance of being kept) when x <= 0.0026. * - That is, any word which is 0.0026 of the words *or fewer* * will be kept 100% of the time. Only words which represent * more than 0.26% of the total words will be subsampled. * - ran = 0.5 (50% chance of being kept) when x = 0.00746. * - ran = 0.033 (3.3% chance of being kept) when x = 1. * - That is, if a word represented 100% of the training set * (which of course would never happen), it would only be * kept 3.3% of the time. * * NOTE: Seems like it would be more efficient to pre-calculate this * probability for each word and store it in the vocab table... * * Words that are discarded by subsampling aren't added to our training * 'sentence'. This means the discarded word is neither used as an * input word or a context word for other inputs. */ if (sample > 0) { // Calculate the probability of keeping 'word'. real ran = (sqrt(vocab[word].cn / (sample * train_words)) + 1) * (sample * train_words) / vocab[word].cn; // Generate a random number. // The multiplier is 25.xxx billion, so 'next_random' is a 64-bit integer. next_random = next_random * (unsigned long long)25214903917 + 11; // If the probability is less than a random fraction, discard the word. // // (next_random & 0xFFFF) extracts just the lower 16 bits of the // random number. Dividing this by 65536 (2^16) gives us a fraction // between 0 and 1. So the code is just generating a random fraction. if (ran < (next_random & 0xFFFF) / (real)65536) continue; } // If we kept the word, add it to the sentence. sen[sentence_length] = word; sentence_length++; // Verify the sentence isn't too long. if (sentence_length >= MAX_SENTENCE_LENGTH) break; } sentence_position = 0; } if (feof(fi) || (word_count > train_words / num_threads)) { word_count_actual += word_count - last_word_count; local_iter--; if (local_iter == 0) break; word_count = 0; last_word_count = 0; sentence_length = 0; fseek(fi, file_size / (long long)num_threads * (long long)id, SEEK_SET); continue; } // Get the next word in the sentence. The word is represented by its index // into the vocab table. word = sen[sentence_position]; if (word == -1) continue; for (c = 0; c < layer1_size; c++) neu1[c] = 0; for (c = 0; c < layer1_size; c++) neu1e[c] = 0; // This is a standard random integer generator, as seen here: // https://en.wikipedia.org/wiki/Linear_congruential_generator next_random = next_random * (unsigned long long)25214903917 + 11; // 'b' becomes a random integer between 0 and 'window' - 1. // This is the amount we will shrink the window size by. b = next_random % window; /* * ==================================== * CBOW Architecture * ==================================== * sen - This is the array of words in the sentence. Subsampling has * already been applied. Words are represented by their ids. * * sentence_position - This is the index of the current input word. * * a - Offset into the current window, relative to the window start. * a will range from 0 to (window * 2) * * b - The amount to shrink the context window by. * * c - 'c' is a scratch variable used in two unrelated ways: * 1. It's first used as the index of the current context word * within the sentence (the `sen` array). * 2. It's then used as the for-loop variable for calculating * vector dot-products and other arithmetic. * * syn0 - The hidden layer weights. Note that the weights are stored as a * 1D array, so word 'i' is found at (i * layer1_size). * * target - The output word we're working on. If it's the positive sample * then `label` is 1. `label` is 0 for negative samples. * Note: `target` and `label` are only used in negative sampling, * and not HS. * * neu1 - This vector will hold the *average* of all of the context word * vectors. This is the output of the hidden layer for CBOW. * * neu1e - Holds the gradient for updating the hidden layer weights. * It's a vector of length 300, not a matrix. * This same gradient update is applied to all context word * vectors. */ if (cbow) { //train the cbow architecture // in -> hidden cw = 0; // This loop will sum together the word vectors for all of the context // words. // // Loop over the positions in the context window (skipping the word at // the center). 'a' is just the offset within the window, it's not the // index relative to the beginning of the sentence. for (a = b; a < window * 2 + 1 - b; a++) if (a != window) { // Convert the window offset 'a' into an index 'c' into the sentence // array. c = sentence_position - window + a; // Verify c isn't outisde the bounds of the sentence. if (c < 0) continue; if (c >= sentence_length) continue; // Get the context word. That is, get the id of the word (its index in // the vocab table). last_word = sen[c]; // At this point we have two words identified: // 'word' - The word (word ID) at our current position in the // sentence (in the center of a context window). // 'last_word' - The word (word ID) at a position within the context // window. // Verify that the word exists in the vocab if (last_word == -1) continue; // Add the word vector for this context word to the running sum in // neur1. // `layer1_size` is 300, `neu1` is length 300 for (c = 0; c < layer1_size; c++) neu1[c] += syn0[c + last_word * layer1_size]; // Count the number of context words. cw++; } // Skip if there were somehow no context words. if (cw) { // neu1 was the sum of the context word vectors, and now becomes // their average. for (c = 0; c < layer1_size; c++) neu1[c] /= cw; // // HIERARCHICAL SOFTMAX // vocab[word] // .point - A variable-length list of row ids, which are the output // rows to train on. // .code - A variable-length list of 0s and 1s, which are the desired // labels for the outputs in `point`. // .codelen - The length of the `code` array for this // word. // if (hs) for (d = 0; d < vocab[word].codelen; d++) { f = 0; // point[d] is the index of a row of the ouput matrix. // l2 is the index of that word in the output layer weights (syn1). l2 = vocab[word].point[d] * layer1_size; // Propagate hidden -> output // neu1 is the average of the context words from the hidden layer. // This loop computes the dot product between neu1 and the output // weights for the output word at point[d]. for (c = 0; c < layer1_size; c++) f += neu1[c] * syn1[c + l2]; // Apply the sigmoid activation to the current output neuron. if (f <= -MAX_EXP) continue; else if (f >= MAX_EXP) continue; else f = expTable[(int)((f + MAX_EXP) * (EXP_TABLE_SIZE / MAX_EXP / 2))]; // 'g' is the error multiplied by the learning rate. // The error is (label - f), so label = (1 - code), meaning if // code is 0, then this is a positive sample and vice versa. g = (1 - vocab[word].code[d] - f) * alpha; // Propagate errors output -> hidden for (c = 0; c < layer1_size; c++) neu1e[c] += g * syn1[c + l2]; // Learn weights hidden -> output for (c = 0; c < layer1_size; c++) syn1[c + l2] += g * neu1[c]; } // NEGATIVE SAMPLING // Rather than performing backpropagation for every word in our // vocabulary, we only perform it for the positive sample and a few // negative samples (the number of words is given by 'negative'). // These negative words are selected using a "unigram" distribution, // which is generated in the function InitUnigramTable. if (negative > 0) for (d = 0; d < negative + 1; d++) { // On the first iteration, we're going to train the positive sample. if (d == 0) { target = word; label = 1; // On the other iterations, we'll train the negative samples. } else { // Pick a random word to use as a 'negative sample'; do this using // the unigram table. // Get a random integer. next_random = next_random * (unsigned long long)25214903917 + 11; // 'target' becomes the index of the word in the vocab to use as // the negative sample. target = table[(next_random >> 16) % table_size]; // If the target is the special end of sentence token, then just // pick a random word from the vocabulary instead. if (target == 0) target = next_random % (vocab_size - 1) + 1; // Don't use the positive sample as a negative sample! if (target == word) continue; // Mark this as a negative example. label = 0; } // At this point, target might either be the positive sample or a // negative sample, depending on the value of `label`. // Get the index of the target word in the output layer. l2 = target * layer1_size; // Calculate the dot product between: // neu1 - The average of the context word vectors. // syn1neg[l2] - The output weights for the target word. f = 0; for (c = 0; c < layer1_size; c++) f += neu1[c] * syn1neg[c + l2]; // This block does two things: // 1. Calculates the output of the network for this training // pair, using the expTable to evaluate the output layer // activation function. // 2. Calculate the error at the output, stored in 'g', by // subtracting the network output from the desired output, // and finally multiply this by the learning rate. if (f > MAX_EXP) g = (label - 1) * alpha; else if (f < -MAX_EXP) g = (label - 0) * alpha; else g = (label - expTable[(int)((f + MAX_EXP) * (EXP_TABLE_SIZE / MAX_EXP / 2))]) * alpha; // Multiply the error by the output layer weights. // (I think this is the gradient calculation?) // Accumulate these gradients over all of the negative samples. for (c = 0; c < layer1_size; c++) neu1e[c] += g * syn1neg[c + l2]; // Update the output layer weights by multiplying the output error // by the average of the context word vectors. for (c = 0; c < layer1_size; c++) syn1neg[c + l2] += g * neu1[c]; } // hidden -> in // Backpropagate the error to the hidden layer (the word vectors). // This code is used both for heirarchical softmax and for negative // sampling. // // Loop over the positions in the context window (skipping the word at // the center). 'a' is just the offset within the window, it's not // the index relative to the beginning of the sentence. for (a = b; a < window * 2 + 1 - b; a++) if (a != window) { // Convert the window offset 'a' into an index 'c' into the sentence // array. c = sentence_position - window + a; // Verify c isn't outisde the bounds of the sentence. if (c < 0) continue; if (c >= sentence_length) continue; // Get the context word. That is, get the id of the word (its index in // the vocab table). last_word = sen[c]; // Verify word exists in vocab. if (last_word == -1) continue; // Note that `c` is no longer the sentence position, it's just a // for-loop index. // Add the gradient in the vector `neu1e` to the word vector for // the current context word. // syn0[last_word * layer1_size] <-- Accesses the word vector. for (c = 0; c < layer1_size; c++) syn0[c + last_word * layer1_size] += neu1e[c]; } } } /* * ==================================== * Skip-gram Architecture * ==================================== * sen - This is the array of words in the sentence. Subsampling has * already been applied. Words are represented by their ids. * * sentence_position - This is the index of the current input word. * * a - Offset into the current window, relative to the window start. * a will range from 0 to (window * 2) * * b - The amount to shrink the context window by. * * c - 'c' is a scratch variable used in two unrelated ways: * 1. It's first used as the index of the current context word * within the sentence (the `sen` array). * 2. It's then used as the for-loop variable for calculating * vector dot-products and other arithmetic. * * syn0 - The hidden layer weights. Note that the weights are stored as a * 1D array, so word 'i' is found at (i * layer1_size). * * l1 - Index into the hidden layer (syn0). Index of the start of the * weights for the current input word. * * target - The output word we're working on. If it's the positive sample * then `label` is 1. `label` is 0 for negative samples. * Note: `target` and `label` are only used in negative sampling, * and not HS. */ else { // Loop over the positions in the context window (skipping the word at // the center). 'a' is just the offset within the window, it's not // the index relative to the beginning of the sentence. for (a = b; a < window * 2 + 1 - b; a++) if (a != window) { // Convert the window offset 'a' into an index 'c' into the sentence // array. c = sentence_position - window + a; // Verify c isn't outisde the bounds of the sentence. if (c < 0) continue; if (c >= sentence_length) continue; // Get the context word. That is, get the id of the word (its index in // the vocab table). last_word = sen[c]; // At this point we have two words identified: // 'word' - The word at our current position in the sentence (in the // center of a context window). // 'last_word' - The word at a position within the context window. // Verify that the word exists in the vocab (I don't think this should // ever be the case?) if (last_word == -1) continue; // Calculate the index of the start of the weights for 'last_word'. l1 = last_word * layer1_size; for (c = 0; c < layer1_size; c++) neu1e[c] = 0; // HIERARCHICAL SOFTMAX if (hs) for (d = 0; d < vocab[word].codelen; d++) { f = 0; l2 = vocab[word].point[d] * layer1_size; // Propagate hidden -> output for (c = 0; c < layer1_size; c++) f += syn0[c + l1] * syn1[c + l2]; if (f <= -MAX_EXP) continue; else if (f >= MAX_EXP) continue; else f = expTable[(int)((f + MAX_EXP) * (EXP_TABLE_SIZE / MAX_EXP / 2))]; // 'g' is the gradient multiplied by the learning rate g = (1 - vocab[word].code[d] - f) * alpha; // Propagate errors output -> hidden for (c = 0; c < layer1_size; c++) neu1e[c] += g * syn1[c + l2]; // Learn weights hidden -> output for (c = 0; c < layer1_size; c++) syn1[c + l2] += g * syn0[c + l1]; } // NEGATIVE SAMPLING // Rather than performing backpropagation for every word in our // vocabulary, we only perform it for a few words (the number of words // is given by 'negative'). // These words are selected using a "unigram" distribution, which is generated // in the function InitUnigramTable if (negative > 0) for (d = 0; d < negative + 1; d++) { // On the first iteration, we're going to train the positive sample. if (d == 0) { target = word; label = 1; // On the other iterations, we'll train the negative samples. } else { // Pick a random word to use as a 'negative sample'; do this using // the unigram table. // Get a random integer. next_random = next_random * (unsigned long long)25214903917 + 11; // 'target' becomes the index of the word in the vocab to use as // the negative sample. target = table[(next_random >> 16) % table_size]; // If the target is the special end of sentence token, then just // pick a random word from the vocabulary instead. if (target == 0) target = next_random % (vocab_size - 1) + 1; // Don't use the positive sample as a negative sample! if (target == word) continue; // Mark this as a negative example. label = 0; } // Get the index of the target word in the output layer. l2 = target * layer1_size; // At this point, our two words are represented by their index into // the layer weights. // l1 - The index of our input word within the hidden layer weights. // l2 - The index of our output word within the output layer weights. // label - Whether this is a positive (1) or negative (0) example. // Calculate the dot-product between the input words weights (in // syn0) and the output word's weights (in syn1neg). // Note that this calculates the dot-product manually using a for // loop over the vector elements! f = 0; for (c = 0; c < layer1_size; c++) f += syn0[c + l1] * syn1neg[c + l2]; // This block does two things: // 1. Calculates the output of the network for this training // pair, using the expTable to evaluate the output layer // activation function. // 2. Calculate the error at the output, stored in 'g', by // subtracting the network output from the desired output, // and finally multiply this by the learning rate. if (f > MAX_EXP) g = (label - 1) * alpha; else if (f < -MAX_EXP) g = (label - 0) * alpha; else g = (label - expTable[(int)((f + MAX_EXP) * (EXP_TABLE_SIZE / MAX_EXP / 2))]) * alpha; // Multiply the error by the output layer weights. // Accumulate these gradients over the negative samples and the one // positive sample. for (c = 0; c < layer1_size; c++) neu1e[c] += g * syn1neg[c + l2]; // Update the output layer weights by multiplying the output error // by the hidden layer weights. for (c = 0; c < layer1_size; c++) syn1neg[c + l2] += g * syn0[c + l1]; } // Once the hidden layer gradients for the negative samples plus the // one positive sample have been accumulated, update the hidden layer // weights. // Note that we do not average the gradient before applying it. for (c = 0; c < layer1_size; c++) syn0[c + l1] += neu1e[c]; } } // Advance to the next word in the sentence. sentence_position++; // Check if we've reached the end of the sentence. // If so, set sentence_length to 0 and we'll read a new sentence at the // beginning of this loop. if (sentence_position >= sentence_length) { sentence_length = 0; continue; } } fclose(fi); free(neu1); free(neu1e); pthread_exit(NULL); } /** * ======== TrainModel ======== * Main entry point to the training process. */ void TrainModel() { long a, b, c, d; FILE *fo; pthread_t *pt = (pthread_t *)malloc(num_threads * sizeof(pthread_t)); printf("Starting training using file %s\n", train_file); starting_alpha = alpha; // Either load a pre-existing vocabulary, or learn the vocabulary from // the training file. if (read_vocab_file[0] != 0) ReadVocab(); else LearnVocabFromTrainFile(); // Save the vocabulary. if (save_vocab_file[0] != 0) SaveVocab(); // Stop here if no output_file was specified. if (output_file[0] == 0) return; // Allocate the weight matrices and initialize them. InitNet(); // If we're using negative sampling, initialize the unigram table, which // is used to pick words to use as "negative samples" (with more frequent // words being picked more often). if (negative > 0) InitUnigramTable(); // Record the start time of training. start = clock(); // Run training, which occurs in the 'TrainModelThread' function. for (a = 0; a < num_threads; a++) pthread_create(&pt[a], NULL, TrainModelThread, (void *)a); for (a = 0; a < num_threads; a++) pthread_join(pt[a], NULL); fo = fopen(output_file, "wb"); if (classes == 0) { // Save the word vectors fprintf(fo, "%lld %lld\n", vocab_size, layer1_size); for (a = 0; a < vocab_size; a++) { fprintf(fo, "%s ", vocab[a].word); if (binary) for (b = 0; b < layer1_size; b++) fwrite(&syn0[a * layer1_size + b], sizeof(real), 1, fo); else for (b = 0; b < layer1_size; b++) fprintf(fo, "%lf ", syn0[a * layer1_size + b]); fprintf(fo, "\n"); } } else { // Run K-means on the word vectors int clcn = classes, iter = 10, closeid; int *centcn = (int *)malloc(classes * sizeof(int)); int *cl = (int *)calloc(vocab_size, sizeof(int)); real closev, x; real *cent = (real *)calloc(classes * layer1_size, sizeof(real)); for (a = 0; a < vocab_size; a++) cl[a] = a % clcn; for (a = 0; a < iter; a++) { for (b = 0; b < clcn * layer1_size; b++) cent[b] = 0; for (b = 0; b < clcn; b++) centcn[b] = 1; for (c = 0; c < vocab_size; c++) { for (d = 0; d < layer1_size; d++) cent[layer1_size * cl[c] + d] += syn0[c * layer1_size + d]; centcn[cl[c]]++; } for (b = 0; b < clcn; b++) { closev = 0; for (c = 0; c < layer1_size; c++) { cent[layer1_size * b + c] /= centcn[b]; closev += cent[layer1_size * b + c] * cent[layer1_size * b + c]; } closev = sqrt(closev); for (c = 0; c < layer1_size; c++) cent[layer1_size * b + c] /= closev; } for (c = 0; c < vocab_size; c++) { closev = -10; closeid = 0; for (d = 0; d < clcn; d++) { x = 0; for (b = 0; b < layer1_size; b++) x += cent[layer1_size * d + b] * syn0[c * layer1_size + b]; if (x > closev) { closev = x; closeid = d; } } cl[c] = closeid; } } // Save the K-means classes for (a = 0; a < vocab_size; a++) fprintf(fo, "%s %d\n", vocab[a].word, cl[a]); free(centcn); free(cent); free(cl); } fclose(fo); } int ArgPos(char *str, int argc, char **argv) { int a; for (a = 1; a < argc; a++) if (!strcmp(str, argv[a])) { if (a == argc - 1) { printf("Argument missing for %s\n", str); exit(1); } return a; } return -1; } int main(int argc, char **argv) { int i; if (argc == 1) { printf("WORD VECTOR estimation toolkit v 0.1c\n\n"); printf("Options:\n"); printf("Parameters for training:\n"); printf("\t-train <file>\n"); printf("\t\tUse text data from <file> to train the model\n"); printf("\t-output <file>\n"); printf("\t\tUse <file> to save the resulting word vectors / word clusters\n"); printf("\t-size <int>\n"); printf("\t\tSet size of word vectors; default is 100\n"); printf("\t-window <int>\n"); printf("\t\tSet max skip length between words; default is 5\n"); printf("\t-sample <float>\n"); printf("\t\tSet threshold for occurrence of words. Those that appear with higher frequency in the training data\n"); printf("\t\twill be randomly down-sampled; default is 1e-3, useful range is (0, 1e-5)\n"); printf("\t-hs <int>\n"); printf("\t\tUse Hierarchical Softmax; default is 0 (not used)\n"); printf("\t-negative <int>\n"); printf("\t\tNumber of negative examples; default is 5, common values are 3 - 10 (0 = not used)\n"); printf("\t-threads <int>\n"); printf("\t\tUse <int> threads (default 12)\n"); printf("\t-iter <int>\n"); printf("\t\tRun more training iterations (default 5)\n"); printf("\t-min-count <int>\n"); printf("\t\tThis will discard words that appear less than <int> times; default is 5\n"); printf("\t-alpha <float>\n"); printf("\t\tSet the starting learning rate; default is 0.025 for skip-gram and 0.05 for CBOW\n"); printf("\t-classes <int>\n"); printf("\t\tOutput word classes rather than word vectors; default number of classes is 0 (vectors are written)\n"); printf("\t-debug <int>\n"); printf("\t\tSet the debug mode (default = 2 = more info during training)\n"); printf("\t-binary <int>\n"); printf("\t\tSave the resulting vectors in binary moded; default is 0 (off)\n"); printf("\t-save-vocab <file>\n"); printf("\t\tThe vocabulary will be saved to <file>\n"); printf("\t-read-vocab <file>\n"); printf("\t\tThe vocabulary will be read from <file>, not constructed from the training data\n"); printf("\t-cbow <int>\n"); printf("\t\tUse the continuous bag of words model; default is 1 (use 0 for skip-gram model)\n"); printf("\nExamples:\n"); printf("./word2vec -train data.txt -output vec.txt -size 200 -window 5 -sample 1e-4 -negative 5 -hs 0 -binary 0 -cbow 1 -iter 3\n\n"); return 0; } output_file[0] = 0; save_vocab_file[0] = 0; read_vocab_file[0] = 0; if ((i = ArgPos((char *)"-size", argc, argv)) > 0) layer1_size = atoi(argv[i + 1]); if ((i = ArgPos((char *)"-train", argc, argv)) > 0) strcpy(train_file, argv[i + 1]); if ((i = ArgPos((char *)"-save-vocab", argc, argv)) > 0) strcpy(save_vocab_file, argv[i + 1]); if ((i = ArgPos((char *)"-read-vocab", argc, argv)) > 0) strcpy(read_vocab_file, argv[i + 1]); if ((i = ArgPos((char *)"-debug", argc, argv)) > 0) debug_mode = atoi(argv[i + 1]); if ((i = ArgPos((char *)"-binary", argc, argv)) > 0) binary = atoi(argv[i + 1]); if ((i = ArgPos((char *)"-cbow", argc, argv)) > 0) cbow = atoi(argv[i + 1]); if (cbow) alpha = 0.05; if ((i = ArgPos((char *)"-alpha", argc, argv)) > 0) alpha = atof(argv[i + 1]); if ((i = ArgPos((char *)"-output", argc, argv)) > 0) strcpy(output_file, argv[i + 1]); if ((i = ArgPos((char *)"-window", argc, argv)) > 0) window = atoi(argv[i + 1]); if ((i = ArgPos((char *)"-sample", argc, argv)) > 0) sample = atof(argv[i + 1]); if ((i = ArgPos((char *)"-hs", argc, argv)) > 0) hs = atoi(argv[i + 1]); if ((i = ArgPos((char *)"-negative", argc, argv)) > 0) negative = atoi(argv[i + 1]); if ((i = ArgPos((char *)"-threads", argc, argv)) > 0) num_threads = atoi(argv[i + 1]); if ((i = ArgPos((char *)"-iter", argc, argv)) > 0) iter = atoi(argv[i + 1]); if ((i = ArgPos((char *)"-min-count", argc, argv)) > 0) min_count = atoi(argv[i + 1]); if ((i = ArgPos((char *)"-classes", argc, argv)) > 0) classes = atoi(argv[i + 1]); // Allocate the vocabulary table. vocab = (struct vocab_word *)calloc(vocab_max_size, sizeof(struct vocab_word)); // Allocate the hash table for mapping word strings to word entries. vocab_hash = (int *)calloc(vocab_hash_size, sizeof(int)); /* * ======== Precomputed Exp Table ======== * To calculate the softmax output, they use a table of values which are * pre-computed here. * * From the top of this file: * #define EXP_TABLE_SIZE 1000 * #define MAX_EXP 6 * * First, let's look at this inner term: * i / (real)EXP_TABLE_SIZE * 2 - 1 * This is just a straight line that goes from -1 to +1. * (0, -1.0), (1, -0.998), (2, -0.996), ... (999, 0.998), (1000, 1.0). * * Next, multiplying this by MAX_EXP = 6, it causes the output to range * from -6 to +6 instead of -1 to +1. * (0, -6.0), (1, -5.988), (2, -5.976), ... (999, 5.988), (1000, 6.0). * * So the total input range of the table is * Range = MAX_EXP * 2 = 12 * And the increment on the inputs is * Increment = Range / EXP_TABLE_SIZE = 0.012 * * Let's say we want to compute the output for the value x = 0.25. How do * we calculate the position in the table? * index = (x - -MAX_EXP) / increment * Which we can re-write as: * index = (x + MAX_EXP) / (range / EXP_TABLE_SIZE) * = (x + MAX_EXP) / ((2 * MAX_EXP) / EXP_TABLE_SIZE) * = (x + MAX_EXP) * (EXP_TABLE_SIZE / MAX_EXP / 2) * * The last form is what we find in the code elsewhere for using the table: * expTable[(int)((f + MAX_EXP) * (EXP_TABLE_SIZE / MAX_EXP / 2))] * */ // Allocate the table, 1000 floats. expTable = (real *)malloc((EXP_TABLE_SIZE + 1) * sizeof(real)); // For each position in the table... for (i = 0; i < EXP_TABLE_SIZE; i++) { // Calculate the output of e^x for values in the range -6.0 to +6.0. expTable[i] = exp((i / (real)EXP_TABLE_SIZE * 2 - 1) * MAX_EXP); // Precompute the exp() table // Currently the table contains the function exp(x). // We are going to replace this with exp(x) / (exp(x) + 1), which is // just the sigmoid activation function! // Note that // exp(x) / (exp(x) + 1) // is equivalent to // 1 / (1 + exp(-x)) expTable[i] = expTable[i] / (expTable[i] + 1); // Precompute f(x) = x / (x + 1) } TrainModel(); return 0; }
the_stack_data/1128306.c
/* Generated by mkjambase from Jambase */ char *jambase[] = { /* Jambase */ "if $(NT)\n", "{\n", "SLASH ?= \\\\ ;\n", "}\n", "SLASH ?= / ;\n", "rule find-to-root ( dir : patterns + )\n", "{\n", "local globs = [ GLOB $(dir) : $(patterns) ] ;\n", "while ! $(globs) && $(dir:P) != $(dir)\n", "{\n", "dir = $(dir:P) ;\n", "globs = [ GLOB $(dir) : $(patterns) ] ;\n", "}\n", "return $(globs) ;\n", "}\n", ".boost-build-file = ;\n", ".bootstrap-file = ;\n", "BOOST_BUILD_PATH.user-value = $(BOOST_BUILD_PATH) ;\n", "if ! $(BOOST_BUILD_PATH) && $(UNIX)\n", "{\n", "BOOST_BUILD_PATH = /usr/share/boost-build ;\n", "}\n", "rule _poke ( module-name ? : variables + : value * )\n", "{\n", "module $(<)\n", "{\n", "$(>) = $(3) ;\n", "}\n", "}\n", "rule boost-build ( dir ? )\n", "{\n", "if $(.bootstrap-file)\n", "{\n", "EXIT \"Error: Illegal attempt to re-bootstrap the build system by invoking\" ;\n", "ECHO ;\n", "ECHO \" 'boost-build\" $(dir) \";'\" ;\n", "ECHO ;\n", "EXIT \"Please consult the documentation at 'http://www.boost.org'.\" ;\n", "}\n", "BOOST_BUILD_PATH = $(BOOST_BUILD_PATH) $(dir:R=$(.boost-build-file:D)) ;\n", "_poke .ENVIRON : BOOST_BUILD_PATH : $(BOOST_BUILD_PATH) ;\n", "local bootstrap-file =\n", "[ GLOB $(BOOST_BUILD_PATH) : bootstrap.jam ] ;\n", ".bootstrap-file = $(bootstrap-file[1]) ;\n", "if ! $(.bootstrap-file)\n", "{\n", "ECHO \"Unable to load Boost.Build: could not find build system.\" ;\n", "ECHO --------------------------------------------------------- ;\n", "ECHO \"$(.boost-build-file) attempted to load the build system by invoking\" ;\n", "ECHO ;\n", "ECHO \" 'boost-build\" $(dir) \";'\" ;\n", "ECHO ;\n", "ECHO \"but we were unable to find \\\"bootstrap.jam\\\" in the specified directory\" ;\n", "ECHO \"or in BOOST_BUILD_PATH (searching \"$(BOOST_BUILD_PATH:J=\", \")\").\" ;\n", "ECHO ;\n", "EXIT \"Please consult the documentation at 'http://www.boost.org'.\" ;\n", "}\n", "if [ MATCH .*(--debug-configuration).* : $(ARGV) ]\n", "{\n", "ECHO \"notice: loading Boost.Build from\"\n", "[ NORMALIZE_PATH $(.bootstrap-file:D) ] ;\n", "}\n", "include $(.bootstrap-file) ;\n", "}\n", "if [ MATCH .*(bjam).* : $(ARGV[1]:BL) ]\n", "|| $(BOOST_ROOT) # A temporary measure so Jam works with Boost.Build v1\n", "{\n", "local search-path = $(BOOST_BUILD_PATH) $(BOOST_ROOT) ;\n", "local boost-build-files =\n", "[ find-to-root [ PWD ] : boost-build.jam ]\n", "[ GLOB $(search-path) : boost-build.jam ] ;\n", ".boost-build-file = $(boost-build-files[1]) ;\n", "if ! $(.boost-build-file)\n", "{\n", "ECHO \"Unable to load Boost.Build: could not find \\\"boost-build.jam\\\"\" ;\n", "ECHO --------------------------------------------------------------- ;\n", "if ! [ MATCH .*(bjam).* : $(ARGV[1]:BL) ]\n", "{\n", "ECHO \"BOOST_ROOT must be set, either in the environment, or \" ;\n", "ECHO \"on the command-line with -sBOOST_ROOT=..., to the root\" ;\n", "ECHO \"of the boost installation.\" ;\n", "ECHO ;\n", "}\n", "ECHO \"Attempted search from\" [ PWD ] \"up to the root\" ;\n", "ECHO \"and in these directories from BOOST_BUILD_PATH and BOOST_ROOT: \"$(search-path:J=\", \")\".\" ;\n", "EXIT \"Please consult the documentation at 'http://www.boost.org'.\" ;\n", "}\n", "if [ MATCH .*(--debug-configuration).* : $(ARGV) ]\n", "{\n", "ECHO \"notice: found boost-build.jam at\"\n", "[ NORMALIZE_PATH $(.boost-build-file) ] ;\n", "}\n", "include $(.boost-build-file) ;\n", "if ! $(.bootstrap-file)\n", "{\n", "ECHO \"Unable to load Boost.Build\" ;\n", "ECHO -------------------------- ;\n", "ECHO \"\\\"$(.boost-build-file)\\\" was found by searching from\" [ PWD ] \"up to the root\" ;\n", "ECHO \"and in these directories from BOOST_BUILD_PATH and BOOST_ROOT: \"$(search-path:J=\", \")\".\" ;\n", "ECHO ;\n", "ECHO \"However, it failed to call the \\\"boost-build\\\" rule to indicate\" ;\n", "ECHO \"the location of the build system.\" ;\n", "ECHO ;\n", "EXIT \"Please consult the documentation at 'http://www.boost.org'.\" ;\n", "}\n", "}\n", "else\n", "{\n", "if $(NT)\n", "{\n", "local SUPPORTED_TOOLSETS = \"BORLANDC\" \"VC7\" \"VISUALC\" \"VISUALC16\" \"INTELC\" \"WATCOM\"\n", "\"MINGW\" \"LCC\" ;\n", "TOOLSET = \"\" ;\n", "if $(JAM_TOOLSET)\n", "{\n", "local t ;\n", "for t in $(SUPPORTED_TOOLSETS)\n", "{\n", "$(t) = $($(t):J=\" \") ; # reconstitute paths with spaces in them\n", "if $(t) = $(JAM_TOOLSET) { TOOLSET = $(t) ; }\n", "}\n", "if ! $(TOOLSET)\n", "{\n", "ECHO \"The JAM_TOOLSET environment variable is defined but its value\" ;\n", "ECHO \"is invalid, please use one of the following:\" ;\n", "ECHO ;\n", "for t in $(SUPPORTED_TOOLSETS) { ECHO \" \" $(t) ; }\n", "EXIT ;\n", "}\n", "}\n", "if ! $(TOOLSET)\n", "{\n", "if $(BCCROOT)\n", "{\n", "TOOLSET = BORLANDC ;\n", "BORLANDC = $(BCCROOT:J=\" \") ;\n", "}\n", "else if $(MSVC)\n", "{\n", "TOOLSET = VISUALC16 ;\n", "VISUALC16 = $(MSVC:J=\" \") ;\n", "}\n", "else if $(MSVCNT)\n", "{\n", "TOOLSET = VISUALC ;\n", "VISUALC = $(MSVCNT:J=\" \") ;\n", "}\n", "else if $(MSVCDir)\n", "{\n", "TOOLSET = VISUALC ;\n", "VISUALC = $(MSVCDir:J=\" \") ;\n", "}\n", "else if $(MINGW)\n", "{\n", "TOOLSET = MINGW ;\n", "}\n", "else\n", "{\n", "ECHO \"Jam cannot be run because, either:\" ;\n", "ECHO \" a. You didn't set BOOST_ROOT to indicate the root of your\" ;\n", "ECHO \" Boost installation.\" ;\n", "ECHO \" b. You are trying to use stock Jam but didn't indicate which\" ;\n", "ECHO \" compilation toolset to use. To do so, follow these simple\" ;\n", "ECHO \" instructions:\" ;\n", "ECHO ;\n", "ECHO \" - define one of the following environment variable, with the\" ;\n", "ECHO \" appropriate value according to this list:\" ;\n", "ECHO ;\n", "ECHO \" Variable Toolset Description\" ;\n", "ECHO ;\n", "ECHO \" BORLANDC Borland C++ BC++ install path\" ;\n", "ECHO \" VISUALC Microsoft Visual C++ VC++ install path\" ;\n", "ECHO \" VISUALC16 Microsoft Visual C++ 16 bit VC++ 16 bit install\" ;\n", "ECHO \" INTELC Intel C/C++ IC++ install path\" ;\n", "ECHO \" WATCOM Watcom C/C++ Watcom install path\" ;\n", "ECHO \" MINGW MinGW (gcc) MinGW install path\" ;\n", "ECHO \" LCC Win32-LCC LCC-Win32 install path\" ;\n", "ECHO ;\n", "ECHO \" - define the JAM_TOOLSET environment variable with the *name*\" ;\n", "ECHO \" of the toolset variable you want to use.\" ;\n", "ECHO ;\n", "ECHO \" e.g.: set VISUALC=C:\\\\Visual6\" ;\n", "ECHO \" set JAM_TOOLSET=VISUALC\" ;\n", "EXIT ;\n", "}\n", "}\n", "CP ?= copy ;\n", "RM ?= del /f/q ;\n", "SLASH ?= \\\\ ;\n", "SUFLIB ?= .lib ;\n", "SUFOBJ ?= .obj ;\n", "SUFEXE ?= .exe ;\n", "if $(TOOLSET) = BORLANDC\n", "{\n", "ECHO \"Compiler is Borland C++\" ;\n", "AR ?= tlib /C /P64 ;\n", "CC ?= bcc32 ;\n", "CCFLAGS ?= -q -y -d -v -w-par -w-ccc -w-rch -w-pro -w-aus ;\n", "C++ ?= bcc32 ;\n", "C++FLAGS ?= -q -y -d -v -w-par -w-ccc -w-rch -w-pro -w-aus -P ;\n", "LINK ?= $(CC) ;\n", "LINKFLAGS ?= $(CCFLAGS) ;\n", "STDLIBPATH ?= $(BORLANDC)\\\\lib ;\n", "STDHDRS ?= $(BORLANDC)\\\\include ;\n", "NOARSCAN ?= true ;\n", "}\n", "else if $(TOOLSET) = VISUALC16\n", "{\n", "ECHO \"Compiler is Microsoft Visual C++ 16 bit\" ;\n", "AR ?= lib /nologo ;\n", "CC ?= cl /nologo ;\n", "CCFLAGS ?= /D \\\"WIN\\\" ;\n", "C++ ?= $(CC) ;\n", "C++FLAGS ?= $(CCFLAGS) ;\n", "LINK ?= $(CC) ;\n", "LINKFLAGS ?= $(CCFLAGS) ;\n", "LINKLIBS ?=\n", "\\\"$(VISUALC16)\\\\lib\\\\mlibce.lib\\\"\n", "\\\"$(VISUALC16)\\\\lib\\\\oldnames.lib\\\"\n", ";\n", "LINKLIBS ?= ;\n", "NOARSCAN ?= true ;\n", "OPTIM ?= \"\" ;\n", "STDHDRS ?= $(VISUALC16)\\\\include ;\n", "UNDEFFLAG ?= \"/u _\" ;\n", "}\n", "else if $(TOOLSET) = VISUALC\n", "{\n", "ECHO \"Compiler is Microsoft Visual C++\" ;\n", "AR ?= lib ;\n", "AS ?= masm386 ;\n", "CC ?= cl /nologo ;\n", "CCFLAGS ?= \"\" ;\n", "C++ ?= $(CC) ;\n", "C++FLAGS ?= $(CCFLAGS) ;\n", "LINK ?= link /nologo ;\n", "LINKFLAGS ?= \"\" ;\n", "LINKLIBS ?= \\\"$(VISUALC)\\\\lib\\\\advapi32.lib\\\"\n", "\\\"$(VISUALC)\\\\lib\\\\gdi32.lib\\\"\n", "\\\"$(VISUALC)\\\\lib\\\\user32.lib\\\"\n", "\\\"$(VISUALC)\\\\lib\\\\kernel32.lib\\\" ;\n", "OPTIM ?= \"\" ;\n", "STDHDRS ?= $(VISUALC)\\\\include ;\n", "UNDEFFLAG ?= \"/u _\" ;\n", "}\n", "else if $(TOOLSET) = VC7\n", "{\n", "ECHO \"Compiler is Microsoft Visual C++ .NET\" ;\n", "AR ?= lib ;\n", "AS ?= masm386 ;\n", "CC ?= cl /nologo ;\n", "CCFLAGS ?= \"\" ;\n", "C++ ?= $(CC) ;\n", "C++FLAGS ?= $(CCFLAGS) ;\n", "LINK ?= link /nologo ;\n", "LINKFLAGS ?= \"\" ;\n", "LINKLIBS ?= \\\"$(VISUALC)\\\\PlatformSDK\\\\lib\\\\advapi32.lib\\\"\n", "\\\"$(VISUALC)\\\\PlatformSDK\\\\lib\\\\gdi32.lib\\\"\n", "\\\"$(VISUALC)\\\\PlatformSDK\\\\lib\\\\user32.lib\\\"\n", "\\\"$(VISUALC)\\\\PlatformSDK\\\\lib\\\\kernel32.lib\\\" ;\n", "OPTIM ?= \"\" ;\n", "STDHDRS ?= \\\"$(VISUALC)\\\\include\\\"\n", "\\\"$(VISUALC)\\\\PlatformSDK\\\\include\\\" ;\n", "UNDEFFLAG ?= \"/u _\" ;\n", "}\n", "else if $(TOOLSET) = INTELC\n", "{\n", "ECHO \"Compiler is Intel C/C++\" ;\n", "if ! $(VISUALC)\n", "{\n", "ECHO \"As a special exception, when using the Intel C++ compiler, you need\" ;\n", "ECHO \"to define the VISUALC environment variable to indicate the location\" ;\n", "ECHO \"of your Visual C++ installation. Aborting..\" ;\n", "EXIT ;\n", "}\n", "AR ?= lib ;\n", "AS ?= masm386 ;\n", "CC ?= icl /nologo ;\n", "CCFLAGS ?= \"\" ;\n", "C++ ?= $(CC) ;\n", "C++FLAGS ?= $(CCFLAGS) ;\n", "LINK ?= link /nologo ;\n", "LINKFLAGS ?= \"\" ;\n", "LINKLIBS ?= $(VISUALC)\\\\lib\\\\advapi32.lib\n", "$(VISUALC)\\\\lib\\\\kernel32.lib\n", ";\n", "OPTIM ?= \"\" ;\n", "STDHDRS ?= $(INTELC)\\include $(VISUALC)\\\\include ;\n", "UNDEFFLAG ?= \"/u _\" ;\n", "}\n", "else if $(TOOLSET) = WATCOM\n", "{\n", "ECHO \"Compiler is Watcom C/C++\" ;\n", "AR ?= wlib ;\n", "CC ?= wcc386 ;\n", "CCFLAGS ?= /zq /DWIN32 /I$(WATCOM)\\\\h ; # zq=quiet\n", "C++ ?= wpp386 ;\n", "C++FLAGS ?= $(CCFLAGS) ;\n", "CP ?= copy ;\n", "DOT ?= . ;\n", "DOTDOT ?= .. ;\n", "LINK ?= wcl386 ;\n", "LINKFLAGS ?= /zq ; # zq=quiet\n", "LINKLIBS ?= ;\n", "MV ?= move ;\n", "NOARSCAN ?= true ;\n", "OPTIM ?= ;\n", "RM ?= del /f ;\n", "SLASH ?= \\\\ ;\n", "STDHDRS ?= $(WATCOM)\\\\h $(WATCOM)\\\\h\\\\nt ;\n", "SUFEXE ?= .exe ;\n", "SUFLIB ?= .lib ;\n", "SUFOBJ ?= .obj ;\n", "UNDEFFLAG ?= \"/u _\" ;\n", "}\n", "else if $(TOOLSET) = MINGW\n", "{\n", "ECHO \"Compiler is GCC with Mingw\" ;\n", "AR ?= ar -ru ;\n", "CC ?= gcc ;\n", "CCFLAGS ?= \"\" ;\n", "C++ ?= $(CC) ;\n", "C++FLAGS ?= $(CCFLAGS) ;\n", "LINK ?= $(CC) ;\n", "LINKFLAGS ?= \"\" ;\n", "LINKLIBS ?= \"\" ;\n", "OPTIM ?= ;\n", "SUFOBJ = .o ;\n", "SUFLIB = .a ;\n", "SLASH = / ;\n", "}\n", "else if $(TOOLSET) = LCC\n", "{\n", "ECHO \"Compiler is Win32-LCC\" ;\n", "AR ?= lcclib ;\n", "CC ?= lcc ;\n", "CCFLAGS ?= \"\" ;\n", "C++ ?= $(CC) ;\n", "C++FLAGS ?= $(CCFLAGS) ;\n", "LINK ?= lcclnk ;\n", "LINKFLAGS ?= \"\" ;\n", "LINKLIBS ?= \"\" ;\n", "OPTIM ?= ;\n", "NOARSCAN = true ;\n", "}\n", "else\n", "{\n", "EXIT On NT, set BCCROOT, MSVCNT, MINGW or MSVC to the root of the\n", "Borland or Microsoft directories. ;\n", "}\n", "}\n", "else if $(OS2)\n", "{\n", "local SUPPORTED_TOOLSETS = \"gcc\" ;\n", "TOOLSET = \"\" ;\n", "if $(JAM_TOOLSET)\n", "{\n", "local t ;\n", "for t in $(SUPPORTED_TOOLSETS)\n", "{\n", "$(t) = $($(t):J=\" \") ; # reconstitute paths with spaces in them\n", "if $(t) = $(JAM_TOOLSET) { TOOLSET = $(t) ; }\n", "}\n", "if ! $(TOOLSET)\n", "{\n", "ECHO \"The JAM_TOOLSET environment variable is defined but its value\" ;\n", "ECHO \"is invalid, please use one of the following:\" ;\n", "ECHO ;\n", "for t in $(SUPPORTED_TOOLSETS) { ECHO \" \" $(t) ; }\n", "EXIT ;\n", "}\n", "}\n", "if ! $(TOOLSET)\n", "{\n", "ECHO \"Jam cannot be run because you didn't indicate which compilation toolset\" ;\n", "ECHO \"to use. To do so, follow these simple instructions:\" ;\n", "ECHO ;\n", "ECHO \" - define one of the following environment variable, with the\" ;\n", "ECHO \" appropriate value according to this list:\" ;\n", "ECHO ;\n", "ECHO \" Variable Toolset Description\" ;\n", "ECHO ;\n", "ECHO \" gcc gcc GNU Compiler Collection\" ;\n", "ECHO ;\n", "ECHO \" - define the JAM_TOOLSET environment variable with the *name*\" ;\n", "ECHO \" of the toolset variable you want to use.\" ;\n", "ECHO ;\n", "ECHO \" e.g.: set gcc=C:\\gcc\" ;\n", "ECHO \" set JAM_TOOLSET=gcc\" ;\n", "ECHO ;\n", "EXIT ;\n", "}\n", "RM = del /f ;\n", "CP = copy ;\n", "MV ?= move ;\n", "DOT ?= . ;\n", "DOTDOT ?= .. ;\n", "SUFLIB ?= .lib ;\n", "SUFOBJ ?= .obj ;\n", "SUFEXE ?= .exe ;\n", "if $(TOOLSET) = gcc\n", "{\n", "ECHO \"Compiler is gcc\" ;\n", "AR ?= ar -ru ;\n", "CC ?= gcc ;\n", "CCFLAGS ?= \"-Zomf -DNO_VFORK\" ;\n", "C++ ?= $(CC) ;\n", "C++FLAGS ?= $(CCFLAGS) ;\n", "LINK ?= $(CC) ;\n", "LINKFLAGS ?= \"\" ;\n", "LINKLIBS ?= \"\" ;\n", "OPTIM ?= ;\n", "SUFOBJ = .o ;\n", "SUFLIB = .a ;\n", "UNDEFFLAG ?= \"-U\" ;\n", "SLASH = / ;\n", "}\n", "else\n", "{\n", "EXIT \"Sorry, but the $(JAM_TOOLSET) toolset isn't supported for now\" ;\n", "}\n", "}\n", "else if $(VMS)\n", "{\n", "C++ ?= cxx ;\n", "C++FLAGS ?= ;\n", "CC ?= cc ;\n", "CCFLAGS ?= ;\n", "CHMOD ?= set file/prot= ;\n", "CP ?= copy/replace ;\n", "CRELIB ?= true ;\n", "DOT ?= [] ;\n", "DOTDOT ?= [-] ;\n", "EXEMODE ?= (w:e) ;\n", "FILEMODE ?= (w:r) ;\n", "HDRS ?= ;\n", "LINK ?= link ;\n", "LINKFLAGS ?= \"\" ;\n", "LINKLIBS ?= ;\n", "MKDIR ?= create/dir ;\n", "MV ?= rename ;\n", "OPTIM ?= \"\" ;\n", "RM ?= delete ;\n", "RUNVMS ?= mcr ;\n", "SHELLMODE ?= (w:er) ;\n", "SLASH ?= . ;\n", "STDHDRS ?= decc$library_include ;\n", "SUFEXE ?= .exe ;\n", "SUFLIB ?= .olb ;\n", "SUFOBJ ?= .obj ;\n", "switch $(OS)\n", "{\n", "case OPENVMS : CCFLAGS ?= /stand=vaxc ;\n", "case VMS : LINKLIBS ?= sys$library:vaxcrtl.olb/lib ;\n", "}\n", "}\n", "else if $(MAC)\n", "{\n", "local OPT ;\n", "CW ?= \"{CW}\" ;\n", "MACHDRS ?=\n", "\"$(UMACHDRS):Universal:Interfaces:CIncludes\"\n", "\"$(CW):MSL:MSL_C:MSL_Common:Include\"\n", "\"$(CW):MSL:MSL_C:MSL_MacOS:Include\" ;\n", "MACLIBS ?=\n", "\"$(CW):MacOS Support:Universal:Libraries:StubLibraries:Interfacelib\"\n", "\"$(CW):MacOS Support:Universal:Libraries:StubLibraries:Mathlib\" ;\n", "MPWLIBS ?=\n", "\"$(CW):MacOS Support:Libraries:Runtime:Runtime PPC:MSL MPWCRuntime.lib\"\n", "\"$(CW):MSL:MSL_C:MSL_MacOS:Lib:PPC:MSL C.PPC MPW.Lib\" ;\n", "MPWNLLIBS ?=\n", "\"$(CW):MacOS Support:Libraries:Runtime:Runtime PPC:MSL MPWCRuntime.lib\"\n", "\"$(CW):MSL:MSL_C:MSL_MacOS:Lib:PPC:MSL C.PPC MPW(NL).Lib\" ;\n", "SIOUXHDRS ?= ;\n", "SIOUXLIBS ?=\n", "\"$(CW):MacOS Support:Libraries:Runtime:Runtime PPC:MSL RuntimePPC.lib\"\n", "\"$(CW):MSL:MSL_C:MSL_MacOS:Lib:PPC:MSL SIOUX.PPC.Lib\"\n", "\"$(CW):MSL:MSL_C:MSL_MacOS:Lib:PPC:MSL C.PPC.Lib\" ;\n", "C++ ?= mwcppc ;\n", "C++FLAGS ?= -w off -nomapcr ;\n", "CC ?= mwcppc ;\n", "CCFLAGS ?= -w off -nomapcr ;\n", "CP ?= duplicate -y ;\n", "DOT ?= \":\" ;\n", "DOTDOT ?= \"::\" ;\n", "HDRS ?= $(MACHDRS) $(MPWHDRS) ;\n", "LINK ?= mwlinkppc ;\n", "LINKFLAGS ?= -mpwtool -warn ;\n", "LINKLIBS ?= $(MACLIBS) $(MPWLIBS) ;\n", "MKDIR ?= newfolder ;\n", "MV ?= rename -y ;\n", "NOARSCAN ?= true ;\n", "OPTIM ?= ;\n", "RM ?= delete -y ;\n", "SLASH ?= \":\" ;\n", "STDHDRS ?= ;\n", "SUFLIB ?= .lib ;\n", "SUFOBJ ?= .o ;\n", "}\n", "else if $(OS) = BEOS && $(METROWERKS)\n", "{\n", "AR ?= mwld -xml -o ;\n", "BINDIR ?= /boot/apps ;\n", "CC ?= mwcc ;\n", "CCFLAGS ?= -nosyspath ;\n", "C++ ?= $(CC) ;\n", "C++FLAGS ?= -nosyspath ;\n", "FORTRAN ?= \"\" ;\n", "LIBDIR ?= /boot/develop/libraries ;\n", "LINK ?= mwld ;\n", "LINKFLAGS ?= \"\" ;\n", "MANDIR ?= /boot/documentation/\"Shell Tools\"/HTML ;\n", "NOARSCAN ?= true ;\n", "STDHDRS ?= /boot/develop/headers/posix ;\n", "}\n", "else if $(OS) = BEOS\n", "{\n", "BINDIR ?= /boot/apps ;\n", "CC ?= gcc ;\n", "C++ ?= $(CC) ;\n", "FORTRAN ?= \"\" ;\n", "LIBDIR ?= /boot/develop/libraries ;\n", "LINK ?= gcc ;\n", "LINKLIBS ?= -lnet ;\n", "NOARSCAN ?= true ;\n", "STDHDRS ?= /boot/develop/headers/posix ;\n", "}\n", "else if $(UNIX)\n", "{\n", "switch $(OS)\n", "{\n", "case AIX :\n", "LINKLIBS ?= -lbsd ;\n", "case AMIGA :\n", "CC ?= gcc ;\n", "YACC ?= \"bison -y\" ;\n", "case CYGWIN :\n", "CC ?= gcc ;\n", "CCFLAGS += -D__cygwin__ ;\n", "LEX ?= flex ;\n", "RANLIB ?= \"\" ;\n", "SUFEXE ?= .exe ;\n", "YACC ?= \"bison -y\" ;\n", "case DGUX :\n", "RANLIB ?= \"\" ;\n", "RELOCATE ?= true ;\n", "case HPUX :\n", "YACC = ;\n", "CFLAGS += -Ae ;\n", "CCFLAGS += -Ae ;\n", "RANLIB ?= \"\" ;\n", "case INTERIX :\n", "CC ?= gcc ;\n", "RANLIB ?= \"\" ;\n", "case IRIX :\n", "RANLIB ?= \"\" ;\n", "case MPEIX :\n", "CC ?= gcc ;\n", "C++ ?= gcc ;\n", "CCFLAGS += -D_POSIX_SOURCE ;\n", "HDRS += /usr/include ;\n", "RANLIB ?= \"\" ;\n", "NOARSCAN ?= true ;\n", "NOARUPDATE ?= true ;\n", "case MVS :\n", "RANLIB ?= \"\" ;\n", "case NEXT :\n", "AR ?= libtool -o ;\n", "RANLIB ?= \"\" ;\n", "case MACOSX :\n", "AR ?= libtool -o ;\n", "C++ ?= c++ ;\n", "MANDIR ?= /usr/local/share/man ;\n", "RANLIB ?= \"\" ;\n", "case NCR :\n", "RANLIB ?= \"\" ;\n", "case PTX :\n", "RANLIB ?= \"\" ;\n", "case QNX :\n", "AR ?= wlib ;\n", "CC ?= cc ;\n", "CCFLAGS ?= -Q ; # quiet\n", "C++ ?= $(CC) ;\n", "C++FLAGS ?= -Q ; # quiet\n", "LINK ?= $(CC) ;\n", "LINKFLAGS ?= -Q ; # quiet\n", "NOARSCAN ?= true ;\n", "RANLIB ?= \"\" ;\n", "case SCO :\n", "RANLIB ?= \"\" ;\n", "RELOCATE ?= true ;\n", "case SINIX :\n", "RANLIB ?= \"\" ;\n", "case SOLARIS :\n", "RANLIB ?= \"\" ;\n", "AR ?= \"/usr/ccs/bin/ar ru\" ;\n", "case UNICOS :\n", "NOARSCAN ?= true ;\n", "OPTIM ?= -O0 ;\n", "case UNIXWARE :\n", "RANLIB ?= \"\" ;\n", "RELOCATE ?= true ;\n", "}\n", "CCFLAGS ?= ;\n", "C++FLAGS ?= $(CCFLAGS) ;\n", "CHMOD ?= chmod ;\n", "CHGRP ?= chgrp ;\n", "CHOWN ?= chown ;\n", "LEX ?= lex ;\n", "LINKFLAGS ?= $(CCFLAGS) ;\n", "LINKLIBS ?= ;\n", "OPTIM ?= -O ;\n", "RANLIB ?= ranlib ;\n", "YACC ?= yacc ;\n", "YACCFILES ?= y.tab ;\n", "YACCFLAGS ?= -d ;\n", "}\n", "AR ?= ar ru ;\n", "AS ?= as ;\n", "ASFLAGS ?= ;\n", "AWK ?= awk ;\n", "BINDIR ?= /usr/local/bin ;\n", "C++ ?= cc ;\n", "C++FLAGS ?= ;\n", "CC ?= cc ;\n", "CCFLAGS ?= ;\n", "CP ?= cp -f ;\n", "CRELIB ?= ;\n", "DOT ?= . ;\n", "DOTDOT ?= .. ;\n", "EXEMODE ?= 711 ;\n", "FILEMODE ?= 644 ;\n", "FORTRAN ?= f77 ;\n", "FORTRANFLAGS ?= ;\n", "HDRS ?= ;\n", "INSTALLGRIST ?= installed ;\n", "JAMFILE ?= Jamfile ;\n", "JAMRULES ?= Jamrules ;\n", "LEX ?= ;\n", "LIBDIR ?= /usr/local/lib ;\n", "LINK ?= $(CC) ;\n", "LINKFLAGS ?= ;\n", "LINKLIBS ?= ;\n", "LN ?= ln ;\n", "MANDIR ?= /usr/local/man ;\n", "MKDIR ?= mkdir ;\n", "MV ?= mv -f ;\n", "OPTIM ?= ;\n", "RCP ?= rcp ;\n", "RM ?= rm -f ;\n", "RSH ?= rsh ;\n", "SED ?= sed ;\n", "SHELLHEADER ?= \"#!/bin/sh\" ;\n", "SHELLMODE ?= 755 ;\n", "SLASH ?= / ;\n", "STDHDRS ?= /usr/include ;\n", "SUFEXE ?= \"\" ;\n", "SUFLIB ?= .a ;\n", "SUFOBJ ?= .o ;\n", "UNDEFFLAG ?= \"-u _\" ;\n", "YACC ?= ;\n", "YACCFILES ?= ;\n", "YACCFLAGS ?= ;\n", "HDRPATTERN =\n", "\"^[ ]*#[ ]*include[ ]*[<\\\"]([^\\\">]*)[\\\">].*$\" ;\n", "OSFULL = $(OS)$(OSVER)$(OSPLAT) $(OS)$(OSPLAT) $(OS)$(OSVER) $(OS) ;\n", "DEPENDS all : shell files lib exe obj ;\n", "DEPENDS all shell files lib exe obj : first ;\n", "NOTFILE all first shell files lib exe obj dirs clean uninstall ;\n", "ALWAYS clean uninstall ;\n", "rule As\n", "{\n", "DEPENDS $(<) : $(>) ;\n", "ASFLAGS on $(<) += $(ASFLAGS) $(SUBDIRASFLAGS) ;\n", "}\n", "rule Bulk\n", "{\n", "local i ;\n", "for i in $(>)\n", "{\n", "File $(i:D=$(<)) : $(i) ;\n", "}\n", "}\n", "rule Cc\n", "{\n", "local _h ;\n", "DEPENDS $(<) : $(>) ;\n", "CCFLAGS on $(<) += $(CCFLAGS) $(SUBDIRCCFLAGS) ;\n", "if $(RELOCATE)\n", "{\n", "CcMv $(<) : $(>) ;\n", "}\n", "_h = $(SEARCH_SOURCE) $(HDRS) $(SUBDIRHDRS) ;\n", "if $(VMS) && $(_h)\n", "{\n", "SLASHINC on $(<) = \"/inc=(\" $(_h[1]) ,$(_h[2-]) \")\" ;\n", "}\n", "else if $(MAC) && $(_h)\n", "{\n", "local _i _j ;\n", "_j = $(_h[1]) ;\n", "for _i in $(_h[2-])\n", "{\n", "_j = $(_j),$(_i) ;\n", "}\n", "MACINC on $(<) = \\\"$(_j)\\\" ;\n", "}\n", "}\n", "rule C++\n", "{\n", "local _h ;\n", "DEPENDS $(<) : $(>) ;\n", "C++FLAGS on $(<) += $(C++FLAGS) $(SUBDIRC++FLAGS) ;\n", "if $(RELOCATE)\n", "{\n", "CcMv $(<) : $(>) ;\n", "}\n", "_h = $(SEARCH_SOURCE) $(HDRS) $(SUBDIRHDRS) ;\n", "if $(VMS) && $(_h)\n", "{\n", "SLASHINC on $(<) = \"/inc=(\" $(_h[1]) ,$(_h[2-]) \")\" ;\n", "}\n", "else if $(MAC) && $(_h)\n", "{\n", "local _i _j ;\n", "_j = $(_h[1]) ;\n", "for _i in $(_h[2-])\n", "{\n", "_j = $(_j),$(_i) ;\n", "}\n", "MACINC on $(<) = \\\"$(_j)\\\" ;\n", "}\n", "}\n", "rule Chmod\n", "{\n", "if $(CHMOD) { Chmod1 $(<) ; }\n", "}\n", "rule File\n", "{\n", "DEPENDS files : $(<) ;\n", "DEPENDS $(<) : $(>) ;\n", "SEARCH on $(>) = $(SEARCH_SOURCE) ;\n", "MODE on $(<) = $(FILEMODE) ;\n", "Chmod $(<) ;\n", "}\n", "rule Fortran\n", "{\n", "DEPENDS $(<) : $(>) ;\n", "}\n", "rule GenFile\n", "{\n", "local _t = [ FGristSourceFiles $(<) ] ;\n", "local _s = [ FAppendSuffix $(>[1]) : $(SUFEXE) ] ;\n", "Depends $(_t) : $(_s) $(>[2-]) ;\n", "GenFile1 $(_t) : $(_s) $(>[2-]) ;\n", "Clean clean : $(_t) ;\n", "}\n", "rule GenFile1\n", "{\n", "MakeLocate $(<) : $(LOCATE_SOURCE) ;\n", "SEARCH on $(>) = $(SEARCH_SOURCE) ;\n", "}\n", "rule HardLink\n", "{\n", "DEPENDS files : $(<) ;\n", "DEPENDS $(<) : $(>) ;\n", "SEARCH on $(>) = $(SEARCH_SOURCE) ;\n", "}\n", "rule HdrMacroFile\n", "{\n", "HDRMACRO $(<) ;\n", "}\n", "rule HdrRule\n", "{\n", "local s ;\n", "if $(HDRGRIST)\n", "{\n", "s = $(>:G=$(HDRGRIST)) ;\n", "} else {\n", "s = $(>) ;\n", "}\n", "INCLUDES $(<) : $(s) ;\n", "SEARCH on $(s) = $(HDRSEARCH) ;\n", "NOCARE $(s) ;\n", "HDRSEARCH on $(s) = $(HDRSEARCH) ;\n", "HDRSCAN on $(s) = $(HDRSCAN) ;\n", "HDRRULE on $(s) = $(HDRRULE) ;\n", "HDRGRIST on $(s) = $(HDRGRIST) ;\n", "}\n", "rule InstallInto\n", "{\n", "local i t ;\n", "t = $(>:G=$(INSTALLGRIST)) ;\n", "Depends install : $(t) ;\n", "Clean uninstall : $(t) ;\n", "SEARCH on $(>) = $(SEARCH_SOURCE) ;\n", "MakeLocate $(t) : $(<) ;\n", "for i in $(>)\n", "{\n", "local tt = $(i:G=$(INSTALLGRIST)) ;\n", "Depends $(tt) : $(i) ;\n", "Install $(tt) : $(i) ;\n", "Chmod $(tt) ;\n", "if $(OWNER) && $(CHOWN)\n", "{\n", "Chown $(tt) ;\n", "OWNER on $(tt) = $(OWNER) ;\n", "}\n", "if $(GROUP) && $(CHGRP)\n", "{\n", "Chgrp $(tt) ;\n", "GROUP on $(tt) = $(GROUP) ;\n", "}\n", "}\n", "}\n", "rule InstallBin\n", "{\n", "local _t = [ FAppendSuffix $(>) : $(SUFEXE) ] ;\n", "InstallInto $(<) : $(_t) ;\n", "MODE on $(_t:G=installed) = $(EXEMODE) ;\n", "}\n", "rule InstallFile\n", "{\n", "InstallInto $(<) : $(>) ;\n", "MODE on $(>:G=installed) = $(FILEMODE) ;\n", "}\n", "rule InstallLib\n", "{\n", "InstallInto $(<) : $(>) ;\n", "MODE on $(>:G=installed) = $(FILEMODE) ;\n", "}\n", "rule InstallMan\n", "{\n", "local i s d ;\n", "for i in $(>)\n", "{\n", "switch $(i:S)\n", "{\n", "case .1 : s = 1 ; case .2 : s = 2 ; case .3 : s = 3 ;\n", "case .4 : s = 4 ; case .5 : s = 5 ; case .6 : s = 6 ;\n", "case .7 : s = 7 ; case .8 : s = 8 ; case .l : s = l ;\n", "case .n : s = n ; case .man : s = 1 ;\n", "}\n", "d = man$(s) ;\n", "InstallInto $(d:R=$(<)) : $(i) ;\n", "}\n", "MODE on $(>:G=installed) = $(FILEMODE) ;\n", "}\n", "rule InstallShell\n", "{\n", "InstallInto $(<) : $(>) ;\n", "MODE on $(>:G=installed) = $(SHELLMODE) ;\n", "}\n", "rule Lex\n", "{\n", "LexMv $(<) : $(>) ;\n", "DEPENDS $(<) : $(>) ;\n", "MakeLocate $(<) : $(LOCATE_SOURCE) ;\n", "Clean clean : $(<) ;\n", "}\n", "rule Library\n", "{\n", "LibraryFromObjects $(<) : $(>:S=$(SUFOBJ)) ;\n", "Objects $(>) ;\n", "}\n", "rule LibraryFromObjects\n", "{\n", "local _i _l _s ;\n", "_s = [ FGristFiles $(>) ] ;\n", "_l = $(<:S=$(SUFLIB)) ;\n", "if $(KEEPOBJS)\n", "{\n", "DEPENDS obj : $(_s) ;\n", "}\n", "else\n", "{\n", "DEPENDS lib : $(_l) ;\n", "}\n", "if ! $(_l:D)\n", "{\n", "MakeLocate $(_l) $(_l)($(_s:BS)) : $(LOCATE_TARGET) ;\n", "}\n", "if $(NOARSCAN)\n", "{\n", "DEPENDS $(_l) : $(_s) ;\n", "}\n", "else\n", "{\n", "DEPENDS $(_l) : $(_l)($(_s:BS)) ;\n", "for _i in $(_s)\n", "{\n", "DEPENDS $(_l)($(_i:BS)) : $(_i) ;\n", "}\n", "}\n", "Clean clean : $(_l) ;\n", "if $(CRELIB) { CreLib $(_l) : $(_s[1]) ; }\n", "Archive $(_l) : $(_s) ;\n", "if $(RANLIB) { Ranlib $(_l) ; }\n", "if ! ( $(NOARSCAN) || $(KEEPOBJS) ) { RmTemps $(_l) : $(_s) ; }\n", "}\n", "rule Link\n", "{\n", "MODE on $(<) = $(EXEMODE) ;\n", "Chmod $(<) ;\n", "}\n", "rule LinkLibraries\n", "{\n", "local _t = [ FAppendSuffix $(<) : $(SUFEXE) ] ;\n", "DEPENDS $(_t) : $(>:S=$(SUFLIB)) ;\n", "NEEDLIBS on $(_t) += $(>:S=$(SUFLIB)) ;\n", "}\n", "rule Main\n", "{\n", "MainFromObjects $(<) : $(>:S=$(SUFOBJ)) ;\n", "Objects $(>) ;\n", "}\n", "rule MainFromObjects\n", "{\n", "local _s _t ;\n", "_s = [ FGristFiles $(>) ] ;\n", "_t = [ FAppendSuffix $(<) : $(SUFEXE) ] ;\n", "if $(_t) != $(<)\n", "{\n", "DEPENDS $(<) : $(_t) ;\n", "NOTFILE $(<) ;\n", "}\n", "DEPENDS exe : $(_t) ;\n", "DEPENDS $(_t) : $(_s) ;\n", "MakeLocate $(_t) : $(LOCATE_TARGET) ;\n", "Clean clean : $(_t) ;\n", "Link $(_t) : $(_s) ;\n", "}\n", "rule MakeLocate\n", "{\n", "if $(>)\n", "{\n", "LOCATE on $(<) = $(>) ;\n", "Depends $(<) : $(>[1]) ;\n", "MkDir $(>[1]) ;\n", "}\n", "}\n", "rule MkDir\n", "{\n", "NOUPDATE $(<) ;\n", "if $(<) != $(DOT) && ! $($(<)-mkdir)\n", "{\n", "local s ;\n", "$(<)-mkdir = true ;\n", "MkDir1 $(<) ;\n", "Depends dirs : $(<) ;\n", "s = $(<:P) ;\n", "if $(NT)\n", "{\n", "switch $(s)\n", "{\n", "case *: : s = ;\n", "case *:\\\\ : s = ;\n", "}\n", "}\n", "if $(s) && $(s) != $(<)\n", "{\n", "Depends $(<) : $(s) ;\n", "MkDir $(s) ;\n", "}\n", "else if $(s)\n", "{\n", "NOTFILE $(s) ;\n", "}\n", "}\n", "}\n", "rule Object\n", "{\n", "local h ;\n", "Clean clean : $(<) ;\n", "MakeLocate $(<) : $(LOCATE_TARGET) ;\n", "SEARCH on $(>) = $(SEARCH_SOURCE) ;\n", "HDRS on $(<) = $(SEARCH_SOURCE) $(HDRS) $(SUBDIRHDRS) ;\n", "if $(SEARCH_SOURCE)\n", "{\n", "h = $(SEARCH_SOURCE) ;\n", "}\n", "else\n", "{\n", "h = \"\" ;\n", "}\n", "HDRRULE on $(>) = HdrRule ;\n", "HDRSCAN on $(>) = $(HDRPATTERN) ;\n", "HDRSEARCH on $(>) = $(HDRS) $(SUBDIRHDRS) $(h) $(STDHDRS) ;\n", "HDRGRIST on $(>) = $(HDRGRIST) ;\n", "switch $(>:S)\n", "{\n", "case .asm : As $(<) : $(>) ;\n", "case .c : Cc $(<) : $(>) ;\n", "case .C : C++ $(<) : $(>) ;\n", "case .cc : C++ $(<) : $(>) ;\n", "case .cpp : C++ $(<) : $(>) ;\n", "case .f : Fortran $(<) : $(>) ;\n", "case .l : Cc $(<) : $(<:S=.c) ;\n", "Lex $(<:S=.c) : $(>) ;\n", "case .s : As $(<) : $(>) ;\n", "case .y : Cc $(<) : $(<:S=.c) ;\n", "Yacc $(<:S=.c) : $(>) ;\n", "case * : UserObject $(<) : $(>) ;\n", "}\n", "}\n", "rule ObjectCcFlags\n", "{\n", "CCFLAGS on [ FGristFiles $(<:S=$(SUFOBJ)) ] += $(>) ;\n", "}\n", "rule ObjectC++Flags\n", "{\n", "C++FLAGS on [ FGristFiles $(<:S=$(SUFOBJ)) ] += $(>) ;\n", "}\n", "rule ObjectHdrs\n", "{\n", "HDRS on [ FGristFiles $(<:S=$(SUFOBJ)) ] += $(>) ;\n", "}\n", "rule Objects\n", "{\n", "local _i ;\n", "for _i in [ FGristFiles $(<) ]\n", "{\n", "Object $(_i:S=$(SUFOBJ)) : $(_i) ;\n", "DEPENDS obj : $(_i:S=$(SUFOBJ)) ;\n", "}\n", "}\n", "rule RmTemps\n", "{\n", "TEMPORARY $(>) ;\n", "}\n", "rule Setuid\n", "{\n", "MODE on [ FAppendSuffix $(<) : $(SUFEXE) ] = 4711 ;\n", "}\n", "rule Shell\n", "{\n", "DEPENDS shell : $(<) ;\n", "DEPENDS $(<) : $(>) ;\n", "SEARCH on $(>) = $(SEARCH_SOURCE) ;\n", "MODE on $(<) = $(SHELLMODE) ;\n", "Clean clean : $(<) ;\n", "Chmod $(<) ;\n", "}\n", "rule SubDir\n", "{\n", "local _r _s ;\n", "if ! $($(<[1]))\n", "{\n", "if ! $(<[1])\n", "{\n", "EXIT SubDir syntax error ;\n", "}\n", "$(<[1]) = [ FSubDir $(<[2-]) ] ;\n", "}\n", "if ! $($(<[1])-included)\n", "{\n", "$(<[1])-included = TRUE ;\n", "_r = $($(<[1])RULES) ;\n", "if ! $(_r)\n", "{\n", "_r = $(JAMRULES:R=$($(<[1]))) ;\n", "}\n", "include $(_r) ;\n", "}\n", "_s = [ FDirName $(<[2-]) ] ;\n", "SUBDIR = $(_s:R=$($(<[1]))) ;\n", "SUBDIR_TOKENS = $(<[2-]) ;\n", "SEARCH_SOURCE = $(SUBDIR) ;\n", "LOCATE_SOURCE = $(ALL_LOCATE_TARGET) $(SUBDIR) ;\n", "LOCATE_TARGET = $(ALL_LOCATE_TARGET) $(SUBDIR) ;\n", "SOURCE_GRIST = [ FGrist $(<[2-]) ] ;\n", "SUBDIRCCFLAGS = ;\n", "SUBDIRC++FLAGS = ;\n", "SUBDIRHDRS = ;\n", "}\n", "rule SubDirCcFlags\n", "{\n", "SUBDIRCCFLAGS += $(<) ;\n", "}\n", "rule SubDirC++Flags\n", "{\n", "SUBDIRC++FLAGS += $(<) ;\n", "}\n", "rule SubDirHdrs\n", "{\n", "SUBDIRHDRS += $(<) ;\n", "}\n", "rule SubInclude\n", "{\n", "local _s ;\n", "if ! $($(<[1]))\n", "{\n", "EXIT Top level of source tree has not been set with $(<[1]) ;\n", "}\n", "_s = [ FDirName $(<[2-]) ] ;\n", "include $(JAMFILE:D=$(_s):R=$($(<[1]))) ;\n", "}\n", "rule Undefines\n", "{\n", "UNDEFS on [ FAppendSuffix $(<) : $(SUFEXE) ] += $(UNDEFFLAG)$(>) ;\n", "}\n", "rule UserObject\n", "{\n", "EXIT \"Unknown suffix on\" $(>) \"- see UserObject rule in Jamfile(5).\" ;\n", "}\n", "rule Yacc\n", "{\n", "local _h ;\n", "_h = $(<:BS=.h) ;\n", "MakeLocate $(<) $(_h) : $(LOCATE_SOURCE) ;\n", "if $(YACC)\n", "{\n", "DEPENDS $(<) $(_h) : $(>) ;\n", "Yacc1 $(<) $(_h) : $(>) ;\n", "YaccMv $(<) $(_h) : $(>) ;\n", "Clean clean : $(<) $(_h) ;\n", "}\n", "INCLUDES $(<) : $(_h) ;\n", "}\n", "rule FGrist\n", "{\n", "local _g _i ;\n", "_g = $(<[1]) ;\n", "for _i in $(<[2-])\n", "{\n", "_g = $(_g)!$(_i) ;\n", "}\n", "return $(_g) ;\n", "}\n", "rule FGristFiles\n", "{\n", "if ! $(SOURCE_GRIST)\n", "{\n", "return $(<) ;\n", "}\n", "else\n", "{\n", "return $(<:G=$(SOURCE_GRIST)) ;\n", "}\n", "}\n", "rule FGristSourceFiles\n", "{\n", "if ! $(SOURCE_GRIST)\n", "{\n", "return $(<) ;\n", "}\n", "else\n", "{\n", "local _i _o ;\n", "for _i in $(<)\n", "{\n", "switch $(_i)\n", "{\n", "case *.h : _o += $(_i) ;\n", "case * : _o += $(_i:G=$(SOURCE_GRIST)) ;\n", "}\n", "}\n", "return $(_o) ;\n", "}\n", "}\n", "rule FConcat\n", "{\n", "local _t _r ;\n", "$(_r) = $(<[1]) ;\n", "for _t in $(<[2-])\n", "{\n", "$(_r) = $(_r)$(_t) ;\n", "}\n", "return $(_r) ;\n", "}\n", "rule FSubDir\n", "{\n", "local _i _d ;\n", "if ! $(<[1])\n", "{\n", "_d = $(DOT) ;\n", "}\n", "else\n", "{\n", "_d = $(DOTDOT) ;\n", "for _i in $(<[2-])\n", "{\n", "_d = $(_d:R=$(DOTDOT)) ;\n", "}\n", "}\n", "return $(_d) ;\n", "}\n", "rule FDirName\n", "{\n", "local _s _i ;\n", "if ! $(<)\n", "{\n", "_s = $(DOT) ;\n", "}\n", "else if $(VMS)\n", "{\n", "switch $(<[1])\n", "{\n", "case *:* : _s = $(<[1]) ;\n", "case \\\\[*\\\\] : _s = $(<[1]) ;\n", "case * : _s = [.$(<[1])] ;\n", "}\n", "for _i in [.$(<[2-])]\n", "{\n", "_s = $(_i:R=$(_s)) ;\n", "}\n", "}\n", "else if $(MAC)\n", "{\n", "_s = $(DOT) ;\n", "for _i in $(<)\n", "{\n", "_s = $(_i:R=$(_s)) ;\n", "}\n", "}\n", "else\n", "{\n", "_s = $(<[1]) ;\n", "for _i in $(<[2-])\n", "{\n", "_s = $(_i:R=$(_s)) ;\n", "}\n", "}\n", "return $(_s) ;\n", "}\n", "rule _makeCommon\n", "{\n", "if $($(<)[1]) && $($(<)[1]) = $($(>)[1])\n", "{\n", "$(<) = $($(<)[2-]) ;\n", "$(>) = $($(>)[2-]) ;\n", "_makeCommon $(<) : $(>) ;\n", "}\n", "}\n", "rule FRelPath\n", "{\n", "local _l _r ;\n", "_l = $(<) ;\n", "_r = $(>) ;\n", "_makeCommon _l : _r ;\n", "_l = [ FSubDir $(_l) ] ;\n", "_r = [ FDirName $(_r) ] ;\n", "if $(_r) = $(DOT) {\n", "return $(_l) ;\n", "} else {\n", "return $(_r:R=$(_l)) ;\n", "}\n", "}\n", "rule FAppendSuffix\n", "{\n", "if $(>)\n", "{\n", "local _i _o ;\n", "for _i in $(<)\n", "{\n", "if $(_i:S)\n", "{\n", "_o += $(_i) ;\n", "}\n", "else\n", "{\n", "_o += $(_i:S=$(>)) ;\n", "}\n", "}\n", "return $(_o) ;\n", "}\n", "else\n", "{\n", "return $(<) ;\n", "}\n", "}\n", "rule unmakeDir\n", "{\n", "if $(>[1]:D) && $(>[1]:D) != $(>[1]) && $(>[1]:D) != \\\\\\\\\n", "{\n", "unmakeDir $(<) : $(>[1]:D) $(>[1]:BS) $(>[2-]) ;\n", "}\n", "else\n", "{\n", "$(<) = $(>) ;\n", "}\n", "}\n", "rule FConvertToSlashes\n", "{\n", "local _d, _s, _i ;\n", "unmakeDir _d : $(<) ;\n", "_s = $(_d[1]) ;\n", "for _i in $(_d[2-])\n", "{\n", "_s = $(_s)/$(_i) ;\n", "}\n", "return $(_s) ;\n", "}\n", "actions updated together piecemeal Archive\n", "{\n", "$(AR) $(<) $(>)\n", "}\n", "actions As\n", "{\n", "$(AS) $(ASFLAGS) -I$(HDRS) -o $(<) $(>)\n", "}\n", "actions C++\n", "{\n", "$(C++) -c $(C++FLAGS) $(OPTIM) -I$(HDRS) -o $(<) $(>)\n", "}\n", "actions Cc\n", "{\n", "$(CC) -c $(CCFLAGS) $(OPTIM) -I$(HDRS) -o $(<) $(>)\n", "}\n", "actions Chgrp\n", "{\n", "$(CHGRP) $(GROUP) $(<)\n", "}\n", "actions Chmod1\n", "{\n", "$(CHMOD) $(MODE) $(<)\n", "}\n", "actions Chown\n", "{\n", "$(CHOWN) $(OWNER) $(<)\n", "}\n", "actions piecemeal together existing Clean\n", "{\n", "$(RM) $(>)\n", "}\n", "actions File\n", "{\n", "$(CP) $(>) $(<)\n", "}\n", "actions GenFile1\n", "{\n", "$(>[1]) $(<) $(>[2-])\n", "}\n", "actions Fortran\n", "{\n", "$(FORTRAN) $(FORTRANFLAGS) -o $(<) $(>)\n", "}\n", "actions HardLink\n", "{\n", "$(RM) $(<) && $(LN) $(>) $(<)\n", "}\n", "actions Install\n", "{\n", "$(CP) $(>) $(<)\n", "}\n", "actions Lex\n", "{\n", "$(LEX) $(>)\n", "}\n", "actions LexMv\n", "{\n", "$(MV) lex.yy.c $(<)\n", "}\n", "actions Link bind NEEDLIBS\n", "{\n", "$(LINK) $(LINKFLAGS) -o $(<) $(UNDEFS) $(>) $(NEEDLIBS) $(LINKLIBS)\n", "}\n", "actions MkDir1\n", "{\n", "$(MKDIR) $(<)\n", "}\n", "actions together Ranlib\n", "{\n", "$(RANLIB) $(<)\n", "}\n", "actions quietly updated piecemeal together RmTemps\n", "{\n", "$(RM) $(>)\n", "}\n", "actions Shell\n", "{\n", "$(AWK) '\n", "NR == 1 { print \"$(SHELLHEADER)\" }\n", "NR == 1 && /^[#:]/ { next }\n", "/^##/ { next }\n", "{ print }\n", "' < $(>) > $(<)\n", "}\n", "actions Yacc1\n", "{\n", "$(YACC) $(YACCFLAGS) $(>)\n", "}\n", "actions YaccMv\n", "{\n", "$(MV) $(YACCFILES).c $(<[1])\n", "$(MV) $(YACCFILES).h $(<[2])\n", "}\n", "if $(RELOCATE)\n", "{\n", "actions C++\n", "{\n", "$(C++) -c $(C++FLAGS) $(OPTIM) -I$(HDRS) $(>)\n", "}\n", "actions Cc\n", "{\n", "$(CC) -c $(CCFLAGS) $(OPTIM) -I$(HDRS) $(>)\n", "}\n", "actions ignore CcMv\n", "{\n", "[ $(<) != $(>:BS=$(SUFOBJ)) ] && $(MV) $(>:BS=$(SUFOBJ)) $(<)\n", "}\n", "}\n", "if $(NOARUPDATE)\n", "{\n", "actions Archive\n", "{\n", "$(AR) $(<) $(>)\n", "}\n", "}\n", "if $(NT)\n", "{\n", "if $(TOOLSET) = VISUALC || $(TOOLSET) = VC7 || $(TOOLSET) = INTELC\n", "{\n", "actions updated together piecemeal Archive\n", "{\n", "if exist $(<) set _$(<:B)_=$(<)\n", "$(AR) /out:$(<) %_$(<:B)_% $(>)\n", "}\n", "actions As\n", "{\n", "$(AS) /Ml /p /v /w2 $(>) $(<) ,nul,nul;\n", "}\n", "actions Cc\n", "{\n", "$(CC) /c $(CCFLAGS) $(OPTIM) /Fo$(<) /I$(HDRS) /I$(STDHDRS) $(>)\n", "}\n", "actions C++\n", "{\n", "$(C++) /c $(C++FLAGS) $(OPTIM) /Fo$(<) /I$(HDRS) /I$(STDHDRS) /Tp$(>)\n", "}\n", "actions Link bind NEEDLIBS\n", "{\n", "$(LINK) $(LINKFLAGS) /out:$(<) $(UNDEFS) $(>) $(NEEDLIBS) $(LINKLIBS)\n", "}\n", "}\n", "else if $(TOOLSET) = VISUALC16\n", "{\n", "actions updated together piecemeal Archive\n", "{\n", "$(AR) $(<) -+$(>)\n", "}\n", "actions Cc\n", "{\n", "$(CC) /c $(CCFLAGS) $(OPTIM) /Fo$(<) /I$(HDRS) $(>)\n", "}\n", "actions C++\n", "{\n", "$(C++) /c $(C++FLAGS) $(OPTIM) /Fo$(<) /I$(HDRS) /Tp$(>)\n", "}\n", "actions Link bind NEEDLIBS\n", "{\n", "$(LINK) $(LINKFLAGS) /out:$(<) $(UNDEFS) $(>) $(NEEDLIBS) $(LINKLIBS)\n", "}\n", "}\n", "else if $(TOOLSET) = BORLANDC\n", "{\n", "actions updated together piecemeal Archive\n", "{\n", "$(AR) $(<) -+$(>)\n", "}\n", "actions Link bind NEEDLIBS\n", "{\n", "$(LINK) -e$(<) $(LINKFLAGS) $(UNDEFS) -L$(LINKLIBS) $(NEEDLIBS) $(>)\n", "}\n", "actions C++\n", "{\n", "$(C++) -c $(C++FLAGS) $(OPTIM) -I$(HDRS) -o$(<) $(>)\n", "}\n", "actions Cc\n", "{\n", "$(CC) -c $(CCFLAGS) $(OPTIM) -I$(HDRS) -o$(<) $(>)\n", "}\n", "}\n", "else if $(TOOLSET) = MINGW\n", "{\n", "actions together piecemeal Archive\n", "{\n", "$(AR) $(<) $(>:T)\n", "}\n", "actions Cc\n", "{\n", "$(CC) -c $(CCFLAGS) $(OPTIM) -I$(HDRS) -o$(<) $(>)\n", "}\n", "actions C++\n", "{\n", "$(C++) -c $(C++FLAGS) $(OPTIM) -I$(HDRS) -o$(<) $(>)\n", "}\n", "}\n", "else if $(TOOLSET) = WATCOM\n", "{\n", "actions together piecemeal Archive\n", "{\n", "$(AR) $(<) +-$(>)\n", "}\n", "actions Cc\n", "{\n", "$(CC) $(CCFLAGS) $(OPTIM) /Fo=$(<) /I$(HDRS) $(>)\n", "}\n", "actions C++\n", "{\n", "$(C++) $(C++FLAGS) $(OPTIM) /Fo=$(<) /I$(HDRS) $(>)\n", "}\n", "actions Link bind NEEDLIBS\n", "{\n", "$(LINK) $(LINKFLAGS) /Fe=$(<) $(UNDEFS) $(>) $(NEEDLIBS) $(LINKLIBS)\n", "}\n", "actions Shell\n", "{\n", "$(CP) $(>) $(<)\n", "}\n", "}\n", "else if $(TOOLSET) = LCC\n", "{\n", "actions together piecemeal Archive\n", "{\n", "$(AR) /out:$(<) $(>)\n", "}\n", "actions Cc\n", "{\n", "$(CC) $(CCFLAGS) $(OPTIM) -Fo$(<) -I$(HDRS) $(>)\n", "}\n", "actions Link bind NEEDLIBS\n", "{\n", "$(LINK) $(LINKFLAGS) -o $(<) $(UNDEFS) $(>) $(NEEDLIBS) $(LINKLIBS)\n", "}\n", "actions Shell\n", "{\n", "$(CP) $(>) $(<)\n", "}\n", "}\n", "}\n", "else if $(OS2)\n", "{\n", "if $(TOOLSET) = WATCOM\n", "{\n", "actions together piecemeal Archive\n", "{\n", "$(AR) $(<) +-$(>)\n", "}\n", "actions Cc\n", "{\n", "$(CC) $(CCFLAGS) $(OPTIM) /Fo=$(<) /I$(HDRS) $(>)\n", "}\n", "actions C++\n", "{\n", "$(C++) $(C++FLAGS) $(OPTIM) /Fo=$(<) /I$(HDRS) $(>)\n", "}\n", "actions Link bind NEEDLIBS\n", "{\n", "$(LINK) $(LINKFLAGS) /Fe=$(<) $(UNDEFS) $(>) $(NEEDLIBS) $(LINKLIBS)\n", "}\n", "actions Shell\n", "{\n", "$(CP) $(>) $(<)\n", "}\n", "}\n", "else if $(TOOLSET) = EMX\n", "{\n", "actions together piecemeal Archive\n", "{\n", "$(AR) $(<) $(>:T)\n", "}\n", "actions Cc\n", "{\n", "$(CC) -c $(CCFLAGS) $(OPTIM) -I$(HDRS) -o$(<) $(>)\n", "}\n", "actions C++\n", "{\n", "$(C++) -c $(C++FLAGS) $(OPTIM) -I$(HDRS) -o$(<) $(>)\n", "}\n", "}\n", "}\n", "else if $(VMS)\n", "{\n", "actions updated together piecemeal Archive\n", "{\n", "lib/replace $(<) $(>[1]) ,$(>[2-])\n", "}\n", "actions Cc\n", "{\n", "$(CC)/obj=$(<) $(CCFLAGS) $(OPTIM) $(SLASHINC) $(>)\n", "}\n", "actions C++\n", "{\n", "$(C++)/obj=$(<) $(C++FLAGS) $(OPTIM) $(SLASHINC) $(>)\n", "}\n", "actions piecemeal together existing Clean\n", "{\n", "$(RM) $(>[1]);* ,$(>[2-]);*\n", "}\n", "actions together quietly CreLib\n", "{\n", "if f$search(\"$(<)\") .eqs. \"\" then lib/create $(<)\n", "}\n", "actions GenFile1\n", "{\n", "mcr $(>[1]) $(<) $(>[2-])\n", "}\n", "actions Link bind NEEDLIBS\n", "{\n", "$(LINK)/exe=$(<) $(LINKFLAGS) $(>[1]) ,$(>[2-]) ,$(NEEDLIBS)/lib ,$(LINKLIBS)\n", "}\n", "actions quietly updated piecemeal together RmTemps\n", "{\n", "$(RM) $(>[1]);* ,$(>[2-]);*\n", "}\n", "actions Shell\n", "{\n", "$(CP) $(>) $(<)\n", "}\n", "}\n", "else if $(MAC)\n", "{\n", "actions together Archive\n", "{\n", "$(LINK) -library -o $(<) $(>)\n", "}\n", "actions Cc\n", "{\n", "set -e MWCincludes $(MACINC)\n", "$(CC) -o $(<) $(CCFLAGS) $(OPTIM) $(>)\n", "}\n", "actions C++\n", "{\n", "set -e MWCincludes $(MACINC)\n", "$(CC) -o $(<) $(C++FLAGS) $(OPTIM) $(>)\n", "}\n", "actions Link bind NEEDLIBS\n", "{\n", "$(LINK) -o $(<) $(LINKFLAGS) $(>) $(NEEDLIBS) \"$(LINKLIBS)\"\n", "}\n", "}\n", "rule BULK { Bulk $(<) : $(>) ; }\n", "rule FILE { File $(<) : $(>) ; }\n", "rule HDRRULE { HdrRule $(<) : $(>) ; }\n", "rule INSTALL { Install $(<) : $(>) ; }\n", "rule LIBRARY { Library $(<) : $(>) ; }\n", "rule LIBS { LinkLibraries $(<) : $(>) ; }\n", "rule LINK { Link $(<) : $(>) ; }\n", "rule MAIN { Main $(<) : $(>) ; }\n", "rule SETUID { Setuid $(<) ; }\n", "rule SHELL { Shell $(<) : $(>) ; }\n", "rule UNDEFINES { Undefines $(<) : $(>) ; }\n", "rule INSTALLBIN { InstallBin $(BINDIR) : $(<) ; }\n", "rule INSTALLLIB { InstallLib $(LIBDIR) : $(<) ; }\n", "rule INSTALLMAN { InstallMan $(MANDIR) : $(<) ; }\n", "rule addDirName { $(<) += [ FDirName $(>) ] ; }\n", "rule makeDirName { $(<) = [ FDirName $(>) ] ; }\n", "rule makeGristedName { $(<) = [ FGristSourceFiles $(>) ] ; }\n", "rule makeRelPath { $(<[1]) = [ FRelPath $(<[2-]) : $(>) ] ; }\n", "rule makeSuffixed { $(<[1]) = [ FAppendSuffix $(>) : $(<[2]) ] ; }\n", "{\n", "if $(JAMFILE) { include $(JAMFILE) ; }\n", "}\n", "}\n", 0 };
the_stack_data/11862.c
/* せっかく作ったけどなんも書かなかった(`・ω・´) */
the_stack_data/99766.c
#include <unistd.h> void ft_putstr(char *str) { int index; index = 0; while (str[index] != '\0' ) { index++; } write(1, str, index); }
the_stack_data/62638195.c
/* This really should use "dg-do compile" without the -S in dg-options, but the extra options get put after the input file in that case, and hence the test would fail. */ /* { dg-do assemble } */ /* { dg-options "-S -x c-header" } */ struct s { unsigned field; };
the_stack_data/72011535.c
/* * * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. * * Copyright 2007-2020 Broadcom Inc. All rights reserved. * * File: phy84328.c * Purpose: Phys Driver support for Broadcom 84328 40G phy * Note: * * Specifications: * Repeater mode only, no retimer operation. * Supports the following data speeds: * 1.25 Gbps line rate (1 GbE data rate, 8x oversampled over 10 Gbps line rate) * 10.3125 Gbps line rate (10 GbE data rate) * 11.5 Gpbs line rate (for backplane application, proprietary data rate) * 4x10.3125 Gbps line rate (40 GbE data rate) * * Supports the following line-side connections: * 1 GbE and 10 GbE SFP+ SR and LR optical modules * 40 GbE QSFP SR4 and LR4 optical modules * 1 GbE and 10 GbE SFP+ CR (CX1) copper cable * 40 GbE QSFP CR4 copper cable * 10 GbE KR, 11.5 Gbps line rate and 40 GbE KR4 backplanes * * Operates with the following reference clocks: * Single 156.25 MHz differential clock for 1.25 Gbps, 10.3125 Gpbs and 11.5 Gbps * line rates * Single 125.00 MHz differential clock for 1.25 Gbps, 10.3125 Gbps and 11.5 Gbps * line rates * * Supports autonegotiation as follows: * Clause 73 only for starting Clause 72 and requesting FEC * No speed resolution performed * No Clause 73 in 11.5 Gbps line rate, only Clause 72 supported * Clause 72 may be enabled standalone for close systems * Clause 37 is not supported * No on-chip FEC encoding/decoding, but shall pass-through FEC-encoded data. */ #if defined(INCLUDE_PHY_84328) static unsigned int phy84328_maj_rev = 1200; static unsigned int phy84328_min_rev = 0; #include <sal/types.h> #include <soc/drv.h> #include <soc/debug.h> #include <soc/error.h> #include <soc/phyreg.h> #include <shared/bsl.h> #include <soc/phy.h> #include <soc/phy/phyctrl.h> #include <soc/phy/drv.h> #include "phydefs.h" /* Must include before other phy related includes */ #include "phyconfig.h" /* Must be the first phy include after phydefs.h */ #include "phyident.h" #include "phyreg.h" #include "phynull.h" #include "phyxehg.h" #include "phy84328.h" #define PHY84328_SINGLE_PORT_MODE(_pc) \ (SOC_INFO((_pc)->unit).port_num_lanes[(_pc)->port] >= 4) #define PHY84328_ID_84328 0x84328 /* Gallardo_oct_opt */ #define PHY84328_ID_84324 0x84324 /* Gallardo_opt */ #define PHY84328_ID_84088 0x84088 /* Gallardo_oct_bp */ #define PHY84328_ID_84024 0x84024 /* Gallardo_bp */ /* PMD_CONTROL_REG - speed selection */ #define PHY84328_PMD_CONTROL_REG_VAL_4_SPEED_MASK \ (PHY84328_DEV1_PMD_CONTROL_REGISTER_SPEED_SELECTIONLSB_MASK | \ PHY84328_DEV1_PMD_CONTROL_REGISTER_SPEED_SELECTIONMSB_MASK | \ PHY84328_DEV1_PMD_CONTROL_REGISTER_SPEED_SELECTION_MASK) #define PHY84328_PMD_CONTROL_REG_VAL_4_SPEED_SELECTIONLSB \ (1 << PHY84328_DEV1_PMD_CONTROL_REGISTER_SPEED_SELECTIONLSB_SHIFT) #define PHY84328_PMD_CONTROL_REG_VAL_4_SPEED_SELECTIONMSB \ (1 << PHY84328_DEV1_PMD_CONTROL_REGISTER_SPEED_SELECTIONMSB_SHIFT) #define PHY84328_PMD_CONTROL_REG_VAL_4_SPEED_10GB \ (PHY84328_PMD_CONTROL_REG_VAL_4_SPEED_SELECTIONLSB | \ PHY84328_PMD_CONTROL_REG_VAL_4_SPEED_SELECTIONMSB) #define PHY84328_PMD_CONTROL_REG_VAL_4_SPEED_40GB \ (PHY84328_PMD_CONTROL_REG_VAL_4_SPEED_SELECTIONLSB | \ PHY84328_PMD_CONTROL_REG_VAL_4_SPEED_SELECTIONMSB | \ (2 << PHY84328_DEV1_PMD_CONTROL_REGISTER_SPEED_SELECTION_SHIFT)) #define PHY84328_PMD_CONTROL_REG_VAL_4_SPEED_1GB \ (1 << PHY84328_DEV1_PMD_CONTROL_REGISTER_SPEED_SELECTIONMSB_SHIFT) #define PHY84328_DEV1_PMD_CONTROL_REGISTER_PMA_LOOPBACK \ (1 << PHY84328_DEV1_PMD_CONTROL_REGISTER_PMA_LOOPBACK_SHIFT) /* PMD_CONTROL_2_REG - PMA type selection */ #define PHY84328_DEV1_PMD_CONTROL_2_REGISTER_PMA_TYPE_LR4 0x23 #define PHY84328_DEV1_PMD_CONTROL_2_REGISTER_PMA_TYPE_SR4 0x22 #define PHY84328_DEV1_PMD_CONTROL_2_REGISTER_PMA_TYPE_CR4 0x21 #define PHY84328_DEV1_PMD_CONTROL_2_REGISTER_PMA_TYPE_KR4 0x20 #define PHY84328_DEV1_PMD_CONTROL_2_REGISTER_PMA_TYPE_10BASET 0x0f #define PHY84328_DEV1_PMD_CONTROL_2_REGISTER_PMA_TYPE_100BASETX 0x0e #define PHY84328_DEV1_PMD_CONTROL_2_REGISTER_PMA_TYPE_KX 0x0d #define PHY84328_DEV1_PMD_CONTROL_2_REGISTER_PMA_TYPE_1000BASET 0x0c #define PHY84328_DEV1_PMD_CONTROL_2_REGISTER_PMA_TYPE_KR 0x0b #define PHY84328_DEV1_PMD_CONTROL_2_REGISTER_PMA_TYPE_KX4 0x0a #define PHY84328_DEV1_PMD_CONTROL_2_REGISTER_PMA_TYPE_10GBASET 0x09 #define PHY84328_DEV1_PMD_CONTROL_2_REGISTER_PMA_TYPE_LRM 0x08 #define PHY84328_DEV1_PMD_CONTROL_2_REGISTER_PMA_TYPE_SR 0x07 #define PHY84328_DEV1_PMD_CONTROL_2_REGISTER_PMA_TYPE_LR 0x06 #define PHY84328_DEV1_PMD_CONTROL_2_REGISTER_PMA_TYPE_ER 0x05 #define PHY84328_DEV1_PMD_CONTROL_2_REGISTER_PMA_TYPE_LX4 0x04 #define PHY84328_DEV1_PMD_CONTROL_2_REGISTER_PMA_TYPE_SW 0x03 #define PHY84328_DEV1_PMD_CONTROL_2_REGISTER_PMA_TYPE_LW 0x02 #define PHY84328_DEV1_PMD_CONTROL_2_REGISTER_PMA_TYPE_EW 0x01 #define PHY84328_DEV1_PMD_CONTROL_2_REGISTER_PMA_TYPE_CX4 0x00 /* GP_REGISTER_0 new defined bits */ #define PHY84328_DEV1_GP_REG_0_P4_5_CTRL (1 << 1) #define PHY84328_DEV1_GP_REG_0_TX_GPIO (1 << 2) /* GP_REGISTER_1 */ #define PHY84328_DEV1_GP_REGISTER_1_LINE_TYPE_BKPLANE (1 << PHY84328_DEV1_GP_REGISTER_1_LINE_TYPE_SHIFT) #define PHY84328_DEV1_GP_REGISTER_1_SYSTEM_TYPE_BKPLANE (1 << PHY84328_DEV1_GP_REGISTER_1_SYSTEM_TYPE_SHIFT) #define PHY84328_DEV1_GP_REGISTER_1_LINE_CU_TYPE_COPPER (1 << PHY84328_DEV1_GP_REGISTER_1_LINE_CU_TYPE_SHIFT) #define PHY84328_DEV1_GP_REGISTER_1_SYSTEM_CU_TYPE_COPPER (1 << PHY84328_DEV1_GP_REGISTER_1_SYSTEM_CU_TYPE_SHIFT) #define PHY84328_DEV1_GP_REGISTER_1_FINISH_CHANGE (1 << PHY84328_DEV1_GP_REGISTER_1_FINISH_CHANGE_SHIFT) #define PHY84328_DEV1_GP_REGISTER_1_SPEED_100G (1 << PHY84328_DEV1_GP_REGISTER_1_SPEED_100G_SHIFT) #define PHY84328_DEV1_GP_REGISTER_1_SPEED_42G ((1 << PHY84328_DEV1_GP_REGISTER_1_SPEED_40G_SHIFT) | \ (1 << PHY84328_DEV1_GP_REGISTER_1_SPEED_1G_SHIFT) | \ (1 << PHY84328_DEV1_GP_REGISTER_1_SPEED_10G_SHIFT)) #define PHY84328_DEV1_GP_REGISTER_1_SPEED_40G (1 << PHY84328_DEV1_GP_REGISTER_1_SPEED_40G_SHIFT) #define PHY84328_DEV1_GP_REGISTER_1_SPEED_10G (1 << PHY84328_DEV1_GP_REGISTER_1_SPEED_10G_SHIFT) #define PHY84328_DEV1_GP_REGISTER_1_SPEED_1G (1 << PHY84328_DEV1_GP_REGISTER_1_SPEED_1G_SHIFT) /* Datapath4 */ #define PHY84328_DEV1_GP_REGISTER_1_DATAPATH_MASK 0x0060 #define PHY84328_DEV1_GP_REGISTER_1_DATAPATH_4_DEPTH1 0x0040 #define PHY84328_DEV1_GP_REGISTER_1_DATAPATH_4_DEPTH2 0x0060 /* GP_REGISTER_3 - microcode updated */ #define PHY84328_DEV1_GP_REGISTER_3_FINISH_CHANGE_MASK 0x0080 /* Rx polarity inversion */ #define PHY84328_DEV1_GP_REGISTER_RX_INV 0xc0ba #define PHY84328_DEV1_GP_REGISTER_RX_INV_FORCE (1 << 3) #define PHY84328_DEV1_GP_REGISTER_RX_INV_INVERT (1 << 2) /* ANARXSTATUS - link status */ #define PHY84328_DEV1_ANARXSTATUS_RXSTATUS_SIGDET (1 << 15) #define PHY84328_DEV1_ANARXSTATUS_RXSTATUS_CDR (1 << 12) /* Available when PRBS status is selected in anaRxControl */ #define PHY84328_DEV1_ANARXSTATUS_RXSTATUS_RX_PRBS_LOCK (1 << 15) #define PHY84328_DEV1_ANARXSTATUS_RXSTATUS_RX_PRBS_ERR_MASK (0x1fff) /* Squelching done with lectrical idles */ #define PHY84328_DEV1_ANATXACONTROL2_TX_ELECTRAL_IDLE 0x0100 #define PHY84328_CSR_REG_MODULE_AUTO_DETECT (1 << 4) /* * This bounds how long to wait until giving up on configuration updates * - Delay is given in us * - timeout = (MAX_RETRIES * DELAY)us */ #define PHY84328_UPDATE_CHECK_DELAY 20 #define PHY84328_UPDATE_CHECK_MAX_RETRIES 100 /* I2C related defines */ #define PHY84328_BSC_XFER_MAX 0x1F9 #define PHY84328_BSC_WR_MAX 16 #define PHY84328_WRITE_START_ADDR 0x8007 #define PHY84328_READ_START_ADDR 0x8007 #define PHY84328_WR_FREQ_400KHZ 0x0100 #define PHY84328_2W_STAT 0x000C #define PHY84328_2W_STAT_IDLE 0x0000 #define PHY84328_2W_STAT_COMPLETE 0x0004 #define PHY84328_2W_STAT_IN_PRG 0x0008 #define PHY84328_2W_STAT_FAIL 0x000C #define PHY84328_BSC_WRITE_OP 0x22 #define PHY84328_BSC_READ_OP 0x2 #define PHY84328_I2CDEV_WRITE 0x1 #define PHY84328_I2CDEV_READ 0x0 #define PHY84328_I2C_8BIT 0 #define PHY84328_I2C_16BIT 1 #define PHY84328_I2C_TEMP_RAM 0xE #define PHY84328_I2C_OP_TYPE(access_type,data_type) \ ((access_type) | ((data_type) << 8)) #define PHY84328_I2C_ACCESS_TYPE(op_type) ((op_type) & 0xff) #define PHY84328_I2C_DATA_TYPE(op_type) (((op_type) >> 8) & 0xff) #define I2CM_IDLE_WAIT_MSEC 350 #define I2CM_IDLE_WAIT_CHUNK 10 #define I2CM_IDLE_WAIT_COUNT (I2CM_IDLE_WAIT_MSEC / I2CM_IDLE_WAIT_CHUNK) #define PHY84328_ALL_LANES 0x000f #define PHY84328_PREEMPH_CTRL_FORCE_SHIFT 15 #define PHY84328_PREEMPH_CTRL_POST_TAP_SHIFT 10 #define PHY84328_PREEMPH_CTRL_MAIN_TAP_SHIFT 4 #define PHY84328_PREEMPH_CTRL_PRE_TAP_SHIFT 0 #define PHY84328_PREEMPH_FORCE_GET(_val) (((_val) >> PHY84328_PREEMPH_CTRL_FORCE_SHIFT) & 0x1) #define PHY84328_PREEMPH_POST_TAP_GET(_val) (((_val) >> PHY84328_PREEMPH_CTRL_POST_TAP_SHIFT) & 0xf) #define PHY84328_PREEMPH_MAIN_TAP_GET(_val) (((_val) >> PHY84328_PREEMPH_CTRL_MAIN_TAP_SHIFT) & 0x1f) #define PHY84328_PREEMPH_PRE_TAP_GET(_val) (((_val) >> PHY84328_PREEMPH_CTRL_PRE_TAP_SHIFT) & 0x7) #define PHY84328_PREEMPH_FORCE_SET(_val) (((_val) & 1) << PHY84328_PREEMPH_CTRL_FORCE_SHIFT) #define PHY84328_PREEMPH_POST_TAP_SET(_val) (((_val) & 0xf) << PHY84328_PREEMPH_CTRL_POST_TAP_SHIFT) #define PHY84328_PREEMPH_MAIN_TAP_SET(_val) (((_val) & 0x1f) << PHY84328_PREEMPH_CTRL_MAIN_TAP_SHIFT) #define PHY84328_PREEMPH_PRE_TAP_SET(_val) (((_val) & 7) << PHY84328_PREEMPH_CTRL_PRE_TAP_SHIFT) /* CL73 pause advertisement */ #define CL73_AN_ADV_PAUSE (1 << 10) #define CL73_AN_ADV_ASYM_PAUSE (1 << 11) /* Multicore port */ #define PHY84328_MAX_CORES 3 #define PHY84328_CORE_STATE_SIZE (sizeof(phy_ctrl_t) + sizeof(phy84328_dev_desc_t)) #define PHY84328_MULTI_CORE_MODE(_pc) ((_pc)->phy_mode == PHYCTRL_MULTI_CORE_PORT) #define PHY84328_VALID_CORE(_c) ((_c) < PHY84328_MAX_CORES) #define PHY84328_CORES(_u, _p) ((SOC_INFO((_u)).port_num_lanes[(_p)] + 3) / 4) #define PHY84328_CORE_PC(_pc, _c) (phy_ctrl_t *) \ (((uint8 *)(_pc)) + (PHY84328_CORE_STATE_SIZE * (_c))) #define PHY84328_CORE_STATE_SET(unit, port, core, pc) \ do {\ EXT_PHY_SW_STATE(unit, port) = PHY84328_CORE_PC(pc, core);\ if (core > 0) { \ (PHY84328_CORE_PC(pc, core))->flags = (pc)->flags;\ } \ } while (0) #define PHY84328_CALL_SET(_u, _p, _func) \ do { \ int _rv = SOC_E_NONE; \ phy_ctrl_t *_pc = EXT_PHY_SW_STATE((_u), (_p)); \ if (DBG_FLAGS(_pc) & PHY84328_DBG_F_API_SET) { \ LOG_INFO(BSL_LS_SOC_PHY,\ (BSL_META_U(unit,\ "%s(%d, %d)\n"), FUNCTION_NAME(), (_u), (_p))); \ } \ if (! PHY84328_MULTI_CORE_MODE(_pc)) { \ _rv = (_func); \ } else { \ int _c, _ac; \ _ac = PHY84328_CORES((_u), (_p)); \ for (_c = 0; _c < _ac; _c++) { \ PHY84328_CORE_STATE_SET((_u), (_p), _c, _pc); \ _rv = (_func); \ if (_rv != SOC_E_NONE) { \ break; \ } \ } \ PHY84328_CORE_STATE_SET((_u), (_p), 0, _pc); \ } \ return _rv; \ } while (0) #define PHY84328_CALL_GET(_u, _p, _func, _v, _pv) \ do { \ int _rv = SOC_E_NONE; \ phy_ctrl_t *_pc = EXT_PHY_SW_STATE((_u), (_p)); \ if (DBG_FLAGS(_pc) & PHY84328_DBG_F_API_GET) { \ LOG_INFO(BSL_LS_SOC_PHY,\ (BSL_META_U(unit,\ "%s(%d, %d)\n"), FUNCTION_NAME(), (_u), (_p))); \ } \ if (! PHY84328_MULTI_CORE_MODE(_pc)) { \ _rv = (_func); \ } else { \ int _c, _ac; \ _ac = PHY84328_CORES((_u), (_p)); \ for (_c = 0; _c < _ac; _c++) { \ PHY84328_CORE_STATE_SET((_u), (_p), _c, _pc); \ _rv = (_func); \ if (_rv != SOC_E_NONE) { \ break; \ } \ if (_c == 0) { \ (_pv) = *(_v); \ } else if (*(_v) != (_pv)) { \ LOG_ERROR(BSL_LS_SOC_PHY,\ (BSL_META_U(unit,\ "84328 %s val does not match for all cores: u=%d p=%d\n"), \ FUNCTION_NAME(), (_u), (_p))); \ } \ } \ PHY84328_CORE_STATE_SET((_u), (_p), 0, _pc); \ } \ return _rv; \ } while (0) #define PHY_84328_MICRO_PAUSE(_u, _p, _s) \ do { \ phy_ctrl_t *_pc; \ _pc = EXT_PHY_SW_STATE((_u), (_p)); \ if (DEVREV(_pc) == 0x00a0) { \ _phy_84328_micro_pause((_u), (_p), (_s)); \ } \ } while (0) #define PHY_84328_MICRO_RESUME(_u, _p) \ do { \ phy_ctrl_t *_pc; \ _pc = EXT_PHY_SW_STATE((_u), (_p)); \ if (DEVREV(_pc) == 0x00a0) { \ _phy_84328_micro_resume((_u), (_p)); \ } \ } while (0) /* * PHY system interface types * These values are used when configuring system side interface with spn_PHY_SYS_INTERFACE * Always add at the end but never change the order!! Adding also requires updating * grog documentation */ enum { PHY_SYSTEM_INTERFACE_DFLT = 0, PHY_SYSTEM_INTERFACE_KX = 1, PHY_SYSTEM_INTERFACE_KR = 2, PHY_SYSTEM_INTERFACE_SR = 3, PHY_SYSTEM_INTERFACE_LR = 4, PHY_SYSTEM_INTERFACE_CR = 5, /* System side as XFI-DFE, or system side DAC */ PHY_SYSTEM_INTERFACE_KR4 = 6, PHY_SYSTEM_INTERFACE_SR4 = 7, PHY_SYSTEM_INTERFACE_LR4 = 8, PHY_SYSTEM_INTERFACE_CR4 = 9, /* System side as XLAUI-DFE, or system side DAC */ PHY_SYSTEM_INTERFACE_XFI = 10, PHY_SYSTEM_INTERFACE_XLAUI = 11, PHY_SYSTEM_INTERFACE_INVALID /* must be last */ }; soc_port_if_t phy_sys_to_port_if[] = { 0, /* PHY_SYSTEM_INTERFACE_DFLT */ SOC_PORT_IF_KX, /* PHY_SYSTEM_INTERFACE_KX */ SOC_PORT_IF_KR, /* PHY_SYSTEM_INTERFACE_KR */ SOC_PORT_IF_SR, /* PHY_SYSTEM_INTERFACE_SR */ SOC_PORT_IF_LR, /* PHY_SYSTEM_INTERFACE_LR */ SOC_PORT_IF_CR, /* PHY_SYSTEM_INTERFACE_CR */ SOC_PORT_IF_KR4, /* PHY_SYSTEM_INTERFACE_KR4 */ SOC_PORT_IF_SR4, /* PHY_SYSTEM_INTERFACE_SR4 */ SOC_PORT_IF_LR4, /* PHY_SYSTEM_INTERFACE_LR4 */ SOC_PORT_IF_CR4, /* PHY_SYSTEM_INTERFACE_CR4 */ SOC_PORT_IF_XFI, /* PHY_SYSTEM_INTERFACE_XFI */ SOC_PORT_IF_XLAUI, /* PHY_SYSTEM_INTERFACE_XLAUI */ }; /* interface params */ typedef struct phy84328_intf_cfg { int speed; soc_port_if_t type; } phy84328_intf_cfg_t; typedef enum { PHY84328_DATAPATH_20, PHY84328_DATAPATH_4_DEPTH1, PHY84328_DATAPATH_4_DEPTH2 } phy84328_datapath_t; typedef struct phy84328_counters { uint32 intf_updates; uint32 link_down; uint32 retry_serdes_link; uint32 speed_chk_err; uint32 intf_chk_err; uint32 side_sel_err; uint32 no_cdr; uint32 micro_nopause; } phy84328_counters_t; /* * Software RX LOS (Loss of Signal) WAR * The workaround handles conditions when loss of signal is not reliably * detected. A typical scenario is when the cable is still plugged to a module but * the link partner has disable its tx, in which case some modules do not correctly * report loss of signal. */ typedef enum { PHY84328_SW_RX_LOS_RESET, PHY84328_SW_RX_LOS_INITIAL_LINK, PHY84328_SW_RX_LOS_LINK, PHY84328_SW_RX_LOS_START_TIMER, PHY84328_SW_RX_LOS_RX_RESTART, PHY84328_SW_RX_LOS_IDLE } phy84328_sw_rx_los_states_t; #if defined(BROADCOM_DEBUG) || defined(DEBUG_PRINT) const static char *sw_rx_los_state_names[] = { "RESET", "INITIAL_LINK", "LINK", "START_TIMER", "RX_RESTART", "IDLE" }; #endif /* BROADCOM_DEBUG || DEBUG_PRINT */ typedef struct { uint8 cfg_enable; /* configured with ph control or not */ uint8 cur_enable; /* currently enabled or not */ uint8 sys_link; uint8 link_no_pcs; uint8 link_status; uint8 fault_report_dis; uint8 ls_ticks; uint32 restarts; mac_driver_t *macd; phy84328_sw_rx_los_states_t state; } phy84328_sw_rx_los_t; #define PHY84328_LINK_DEBOUNCE 20 typedef struct { int cur_enable; int cfg_enable; int debounce; } phy84328_link_mon_t; typedef struct { int enable; int count; /* resume only if count==0 */ } phy84328_micro_ctrl_t; #define PHY84328_NUM_LANES 4 #define PHY84328_DBG_F_REG (1 << 0) #define PHY84328_DBG_F_EYE (1 << 1) #define PHY84328_DBG_F_DWLD (1 << 3) #define PHY84328_DBG_F_API_SET (1 << 4) #define PHY84328_DBG_F_API_GET (1 << 5) typedef struct { uint32 devid; uint16 devrev; int core_num; uint32 dbg_flags; int p2l_map[PHY84328_NUM_LANES]; /* index: physical lane, array element: */ phy84328_intf_cfg_t line_intf; phy84328_intf_cfg_t sys_intf; phy84328_sw_rx_los_t sw_rx_los; /* sw_rx_los war */ int fw_rx_los; /* rx LOS handled by firmware */ phy84328_counters_t counters; int cur_link; uint16 pol_tx_cfg; uint16 pol_rx_cfg; int mod_auto_detect; /* module auto detect enabled */ phy84328_datapath_t cfg_datapath; phy84328_datapath_t cur_datapath; phy84328_link_mon_t link_mon; int sys_forced_cl72; int an_en; int force_20bit; int sync_init; int int_phy_re_en; soc_timeout_t sync_to; uint16 logical_lane0; int update_config; int bypass_ss_tuning; phy84328_micro_ctrl_t micro_ctrl; int cfg_sys_intf; int port_enable_delay; } phy84328_dev_desc_t; #define DEVID(_pc) (((phy84328_dev_desc_t *)((_pc) + 1))->devid) #define DEVREV(_pc) (((phy84328_dev_desc_t *)((_pc) + 1))->devrev) #define CORE_NUM(_pc) (((phy84328_dev_desc_t *)((_pc) + 1))->core_num) #define DBG_FLAGS(_pc) (((phy84328_dev_desc_t *)((_pc) + 1))->dbg_flags) #define P2L_MAP(_pc,_ix) (((phy84328_dev_desc_t *)((_pc) + 1))->p2l_map[(_ix)]) #define LINE_INTF(_pc) (((phy84328_dev_desc_t *)((_pc) + 1))->line_intf) #define SYS_INTF(_pc) (((phy84328_dev_desc_t *)((_pc) + 1))->sys_intf) #define SW_RX_LOS(_pc) (((phy84328_dev_desc_t *)((_pc) + 1))->sw_rx_los) #define FW_RX_LOS(_pc) (((phy84328_dev_desc_t *)((_pc) + 1))->fw_rx_los) #define COUNTERS(_pc) (((phy84328_dev_desc_t *)((_pc) + 1))->counters) #define CUR_LINK(_pc) (((phy84328_dev_desc_t *)((_pc) + 1))->cur_link) #define POL_TX_CFG(_pc) (((phy84328_dev_desc_t *)((_pc) + 1))->pol_tx_cfg) #define POL_RX_CFG(_pc) (((phy84328_dev_desc_t *)((_pc) + 1))->pol_rx_cfg) #define MOD_AUTO_DETECT(_pc) (((phy84328_dev_desc_t *)((_pc) + 1))->mod_auto_detect) #define CFG_DATAPATH(_pc) (((phy84328_dev_desc_t *)((_pc) + 1))->cfg_datapath) #define CUR_DATAPATH(_pc) (((phy84328_dev_desc_t *)((_pc) + 1))->cur_datapath) #define SYS_FORCED_CL72(_pc) (((phy84328_dev_desc_t *)((_pc) + 1))->sys_forced_cl72) #define AN_EN(_pc) (((phy84328_dev_desc_t *)((_pc) + 1))->an_en) #define FORCE_20BIT(_pc) (((phy84328_dev_desc_t *)((_pc) + 1))->force_20bit) #define FORCE_20BIT_LB (1 << 0) #define FORCE_20BIT_AN (1 << 1) #define LINK_MON(_pc) (((phy84328_dev_desc_t *)((_pc) + 1))->link_mon) #define SYNC_INIT(_pc) (((phy84328_dev_desc_t *)((_pc) + 1))->sync_init) #define SYNC_TO(_pc) (((phy84328_dev_desc_t *)((_pc) + 1))->sync_to) #define INT_PHY_RE_EN(_pc) (((phy84328_dev_desc_t *)((_pc) + 1))->int_phy_re_en) #define LOGICAL_LANE0(_pc) (((phy84328_dev_desc_t *)((_pc) + 1))->logical_lane0) #define BYPASS_SS_TUNING(_pc) (((phy84328_dev_desc_t *)((_pc) + 1))->bypass_ss_tuning) #define MICRO_CTRL(_pc) (((phy84328_dev_desc_t *)((_pc) + 1))->micro_ctrl) #define CFG_SYS_INTF(_pc) (((phy84328_dev_desc_t *)((_pc) + 1))->cfg_sys_intf) #define PORT_ENABLE_DELAY(_pc) (((phy84328_dev_desc_t *)((_pc) + 1))->port_enable_delay) /* Polarity config */ #define POL_CONFIG_ALL_LANES 1 #define POL_CONFIG_LANE_WIDTH 0x4 #define POL_CONFIG_LANE_MASK(_ln) (0xf << ((_ln) * POL_CONFIG_LANE_WIDTH)) /* * When a port is being flexed between 40G->10G, * the polarity config syntax can be in * 40G syntax for first lane, so there is a need to parse * both 10G and 40G polarity config syntax in 10G. */ #define PHY84328_LN(_pc) ((_pc)->phy_id & 0x3) #define PHY84328_POL_MASK(_pc) POL_CONFIG_LANE_MASK(PHY84328_LN(_pc)) #define PHY84328_10G_POL_CFG_GET(_pc, _pol) \ (((_pol) == POL_CONFIG_ALL_LANES) || \ (((_pol) & PHY84328_POL_MASK(_pc)) == PHY84328_POL_MASK(_pc))) typedef enum { PHY84328_INTF_SIDE_LINE, PHY84328_INTF_SIDE_SYS } phy84328_intf_side_t; STATIC int _phy_84328_chip_id_get(int unit, soc_port_t port, phy_ctrl_t *pc, uint32 *chip_id); /* interface primitives */ STATIC int _phy_84328_intf_is_single_port(soc_port_if_t intf_type); STATIC int _phy_84328_intf_is_quad_port(soc_port_if_t intf_type); STATIC int _phy_84328_intf_type_reg_get(int unit, soc_port_t port, soc_port_if_t intf_type, phy84328_intf_side_t side, uint16 *reg_data, uint16 *reg_mask); STATIC int _phy_84328_intf_update(int unit, soc_port_t port, uint16 reg_data, uint16 reg_mask); STATIC int _phy_84328_intf_line_sys_params_get(int unit, soc_port_t port); STATIC int _phy_84328_intf_line_sys_update(int unit, soc_port_t port); STATIC int _phy_84328_intf_line_sys_init(int unit, soc_port_t port); STATIC int _phy_84328_intf_datapath_update(int unit, soc_port_t port); STATIC int _phy_84328_intf_speed_reg_get(int unit, soc_port_t port, int speed, uint16 *reg_data, uint16 *reg_mask); STATIC int _phy_84328_intf_link_get(int unit, soc_port_t port, uint16 *link); STATIC int _phy_84328_intf_print(int unit, soc_port_t port, const char *msg); STATIC void _phy_84328_intf_side_regs_select(int unit, soc_port_t port, phy84328_intf_side_t side); STATIC phy84328_intf_side_t _phy_84328_intf_side_regs_get(int unit, soc_port_t); STATIC int _phy_84328_intf_datapath_reg_get(int unit, soc_port_t port, phy84328_datapath_t datapath, uint16 *reg_data, uint16 *reg_mask); STATIC int _phy_84328_intf_line_forced(int unit, soc_port_t port, soc_port_if_t intf_type); STATIC int _phy_84328_config_devid(int unit,soc_port_t port, phy_ctrl_t *pc, uint32 *devid); STATIC int _phy_84328_speed_set(int unit, soc_port_t port, int speed); STATIC int _phy_84328_polarity_flip(int unit, soc_port_t port, uint16 cfg_tx_pol, uint16 cfg_rx_pol); STATIC int _phy_84328_intf_type_set(int unit, soc_port_t port, soc_port_if_t pif, int must_update); STATIC int _phy_84328_txmode_manual_set(int unit, soc_port_t port, phy84328_intf_side_t side, int set); STATIC int _phy_84328_tx_config(int unit, soc_port_t port); STATIC int _phy_84328_tx_enable(int unit, soc_port_t port, phy84328_intf_side_t side, int enable); STATIC int _phy_84328_sw_rx_los_pause(int unit, soc_port_t, int enable); STATIC int _phy_84328_link_mon_pause(int unit, soc_port_t, int enable); STATIC int _phy_84328_control_tx_driver_set(int unit, soc_port_t port, soc_phy_control_t type, phy84328_intf_side_t side, uint32 value); STATIC int phy_84328_control_port_set(int unit, soc_port_t port, soc_phy_control_t type, uint32 value); STATIC int phy_84328_control_port_get(int unit, soc_port_t port, soc_phy_control_t type, uint32 *value); /* Debug support for selective tracing mdio by this driver */ /* #define PHY84328_MDIO_TRACING 1 */ #ifdef PHY84328_MDIO_TRACING STATIC int _phy_84328_dbg_read(int unit, phy_ctrl_t *pc, uint32 addr, uint16 *data); STATIC int _phy_84328_dbg_write(int unit, phy_ctrl_t *pc, uint32 addr, uint16 data); STATIC int _phy_84328_dbg_modify(int unit, phy_ctrl_t *pc, uint32 addr, uint16 data, uint16 mask); #undef READ_PHY_REG #define READ_PHY_REG(_unit, _pc, _addr, _value) \ ((_phy_84328_dbg_read)((_pc->unit), _pc, (_addr), (_value))) #undef WRITE_PHY_REG #define WRITE_PHY_REG(_unit, _pc, _addr, _value) \ ((_phy_84328_dbg_write)((_pc->unit), _pc, (_addr), (_value))) #undef MODIFY_PHY_REG #define MODIFY_PHY_REG(_unit, _pc, _addr, _data, _mask) \ (_phy_84328_dbg_modify((_unit), (_pc), (_addr), (_data), (_mask))) #endif /* PHY84328_MDIO_TRACING */ extern unsigned char phy84328_ucode_bin[]; extern unsigned int phy84328_ucode_bin_len; extern unsigned char phy84328B0_ucode_bin[]; extern unsigned int phy84328B0_ucode_bin_len; static char *dev_name_84328_a0 = "BCM84328_A0"; static char *dev_name_84328 = "BCM84328"; static char *dev_name_84324 = "BCM84324"; static char *dev_name_84088 = "BCM84088"; static char *dev_name_84024 = "BCM84024"; static const char *phy84328_intf_names[] = SOC_PORT_IF_NAMES_INITIALIZER; /* callback to deliever the firmware by application * return value: TRUE successfully delivered * FALSE fail to deliver * * Example: * * int user_firmware_send (int unit,int port,int flag,unsigned char **data,int *len) * { * *data = phy84328_ucode_bin; * *len = phy84328_ucode_bin_len; * return TRUE; * } * Then initialize the function pointer before the BCM port initialization: * phy_84328_uc_firmware_hook = user_firmware_send; */ int (*phy_84328_uc_firmware_hook)( int unit, /* switch number */ int port, /* port number */ int flag, /* any information need to ba passed. Not used for now*/ unsigned char **addr, /* starting address of delivered firmware */ int *len /* length of the firmware */ ) = NULL; STATIC int _phy_84328_chip_id_get(int unit, soc_port_t port, phy_ctrl_t *pc, uint32 *chip_id) { int rv = SOC_E_NONE; uint16 chip_id_lsb = 0, chip_id_msb = 0; *chip_id = 0; SOC_IF_ERROR_RETURN( READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_CHIP_ID0_REGISTER, &chip_id_lsb)); SOC_IF_ERROR_RETURN( READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_CHIP_ID1_REGISTER, &chip_id_msb)); if (chip_id_msb == 0x8) { if (chip_id_lsb == 0x4328) { *chip_id = PHY84328_ID_84328; } else if (chip_id_lsb == 0x4324) { *chip_id = PHY84328_ID_84324; } else if (chip_id_lsb == 0x4088) { *chip_id = PHY84328_ID_84088; } else if(chip_id_lsb == 0x4024) { *chip_id = PHY84328_ID_84024; } else { LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "PHY84328 bad chip id: u=%d p=%d chipid %x%x\n"), unit, port, chip_id_msb, chip_id_lsb)); rv = SOC_E_BADID; } } return rv; } STATIC void _phy_84328_intf_side_regs_select(int unit, soc_port_t port, phy84328_intf_side_t side) { int rv; uint16 data, mask; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); assert((side == PHY84328_INTF_SIDE_SYS) || (side == PHY84328_INTF_SIDE_LINE)); data = (side == PHY84328_INTF_SIDE_SYS) ? (1 << PHY84328_DEV1_XPMD_REGS_SEL_SELECT_SYS_REGISTERS_SHIFT) : 0; mask = PHY84328_DEV1_XPMD_REGS_SEL_SELECT_SYS_REGISTERS_MASK; /* configure all ports */ rv = MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_XPMD_REGS_SEL, data, mask); if (SOC_FAILURE(rv)) { phy84328_counters_t *counters = &(COUNTERS(pc)); counters->side_sel_err++; } } STATIC phy84328_intf_side_t _phy_84328_intf_side_regs_get(int unit, soc_port_t port) { int rv; uint16 data; phy84328_intf_side_t side = PHY84328_INTF_SIDE_LINE; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); rv = READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_XPMD_REGS_SEL, &data); if (rv == SOC_E_NONE) { side = ((data & PHY84328_DEV1_XPMD_REGS_SEL_SELECT_SYS_REGISTERS_MASK) == (1 << PHY84328_DEV1_XPMD_REGS_SEL_SELECT_SYS_REGISTERS_SHIFT)) ? PHY84328_INTF_SIDE_SYS : PHY84328_INTF_SIDE_LINE; } return side; } STATIC int _phy_84328_intf_print(int unit, soc_port_t port, const char *msg) { #if defined(BROADCOM_DEBUG) || defined(DEBUG_PRINT) phy_ctrl_t *pc; phy84328_intf_cfg_t *line_intf, *sys_intf; pc = EXT_PHY_SW_STATE(unit, port); line_intf = &(LINE_INTF(pc)); sys_intf = &(SYS_INTF(pc)); LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "%s: "), msg)); LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "[LINE:intf=%s,speed=%d], "), phy84328_intf_names[line_intf->type], line_intf->speed)); LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "[SYS :intf=%s,speed=%d]\n"), phy84328_intf_names[sys_intf->type], sys_intf->speed)); #endif /* BROADCOM_DEBUG || DEBUG_PRINT */ return SOC_E_NONE; } STATIC int _phy_84328_intf_is_single_port(soc_port_if_t intf_type) { int rv; switch (intf_type) { case SOC_PORT_IF_CR4: case SOC_PORT_IF_KR4: case SOC_PORT_IF_XLAUI: case SOC_PORT_IF_LR4: case SOC_PORT_IF_SR4: case SOC_PORT_IF_CAUI: /*****CR10 TBD **** case SOC_PORT_IF_CR10: *****CR10 TBD ****/ rv = TRUE; break; default: rv = FALSE; } return rv; } STATIC int _phy_84328_intf_is_quad_port(soc_port_if_t intf_type) { int rv; switch (intf_type) { case SOC_PORT_IF_SR: case SOC_PORT_IF_CR: case SOC_PORT_IF_KR: case SOC_PORT_IF_XFI: case SOC_PORT_IF_SFI: case SOC_PORT_IF_LR: case SOC_PORT_IF_ZR: case SOC_PORT_IF_KX: case SOC_PORT_IF_GMII: case SOC_PORT_IF_SGMII: rv = TRUE; break; default: rv = FALSE; } return rv; } STATIC int _phy_84328_intf_type_10000(soc_port_if_t intf_type) { int rv; switch (intf_type) { case SOC_PORT_IF_SR: case SOC_PORT_IF_CR: case SOC_PORT_IF_KR: case SOC_PORT_IF_ZR: case SOC_PORT_IF_XFI: case SOC_PORT_IF_SFI: case SOC_PORT_IF_LR: rv = TRUE; break; default: rv = FALSE; } return rv; } STATIC int _phy_84328_intf_type_1000(soc_port_if_t intf_type) { int rv; switch (intf_type) { case SOC_PORT_IF_KX: case SOC_PORT_IF_GMII: case SOC_PORT_IF_SGMII: rv = TRUE; break; default: rv = FALSE; } return rv; } /* * Return the settings in gp_register_1 for the line inteface type * * SOC_PORT_IF SPEED GP_REGISTER_1 * ------------ ----------- ------------------------------------------- * XFI 10G(1G) OPTICAL * SR 10G(1G) OPTICAL * LR 10G(1G) OPTICAL+LR * CR 10G(1G) OPTICAL+CU * XLAUI 10G(1G) OPTICAL * SR4 40G OPTICAL * LR4 40G(1G) OPTICAL+LR * CR4 40G(1G) OPTICAL+CU * KX 1G BACKPLANE * KR 10G BACKPLANE * KR4 40G BACKPLANE * KR2 20G BACKPLANE * XFI2 20G(1G) OPTICAL * SR2 20G(1G) OPTICAL * CR2 20G OPTICAL+CU */ STATIC int _phy_84328_intf_type_reg_get(int unit, soc_port_t port, soc_port_if_t intf_type, phy84328_intf_side_t side, uint16 *reg_data, uint16 *reg_mask) { uint16 data = 0; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); assert((side == PHY84328_INTF_SIDE_LINE) || (side == PHY84328_INTF_SIDE_SYS)); *reg_data = 0; *reg_mask = 0; switch (intf_type) { case SOC_PORT_IF_KX: case SOC_PORT_IF_KR: case SOC_PORT_IF_KR4: if (side == PHY84328_INTF_SIDE_SYS) { data = SYS_FORCED_CL72(pc) ? (1 << PHY84328_DEV1_GP_REGISTER_1_SYSTEM_FORCED_CL72_MODE_SHIFT) : (1 << PHY84328_DEV1_GP_REGISTER_1_SYSTEM_TYPE_SHIFT); } else { /* line side */ data = (1 << PHY84328_DEV1_GP_REGISTER_1_LINE_TYPE_SHIFT); } break; case SOC_PORT_IF_SR: case SOC_PORT_IF_SR4: case SOC_PORT_IF_GMII: case SOC_PORT_IF_SGMII: data = 0; break; case SOC_PORT_IF_ZR: data = (1 << PHY84328_DEV1_GP_REGISTER_1_LINE_LR_MODE_SHIFT) | (1 << PHY84328_DEV1_GP_REGISTER_1_LINE_FORCED_CL72_MODE_SHIFT); break; case SOC_PORT_IF_CR4: /* * If CR4 line side and autoneg enabled, then CR4, otherwise, DAC/XLAUI_DFE */ if (side == PHY84328_INTF_SIDE_LINE) { /* * If CR4 line side and autoneg enabled, then CR4, otherwise, DAC/XLAUI_DFE */ data = (AN_EN(pc)) ? (1 << PHY84328_DEV1_GP_REGISTER_1_LINE_CU_TYPE_SHIFT) : ((1 << PHY84328_DEV1_GP_REGISTER_1_LINE_FORCED_CL72_MODE_SHIFT) | (1 << PHY84328_DEV1_GP_REGISTER_1_LINE_CU_TYPE_SHIFT)); } else { /* System side set to XLAUI_DFE */ data = (1 << PHY84328_DEV1_GP_REGISTER_1_SYSTEM_FORCED_CL72_MODE_SHIFT) | (1 << PHY84328_DEV1_GP_REGISTER_1_SYSTEM_CU_TYPE_SHIFT); } break; case SOC_PORT_IF_CR: data = (side == PHY84328_INTF_SIDE_SYS) ? ((1 << PHY84328_DEV1_GP_REGISTER_1_SYSTEM_FORCED_CL72_MODE_SHIFT) | (1 << PHY84328_DEV1_GP_REGISTER_1_SYSTEM_CU_TYPE_SHIFT)) : (1 << PHY84328_DEV1_GP_REGISTER_1_LINE_CU_TYPE_SHIFT); break; case SOC_PORT_IF_XFI: case SOC_PORT_IF_SFI: case SOC_PORT_IF_XLAUI: case SOC_PORT_IF_CAUI: data = (side == PHY84328_INTF_SIDE_SYS) ? ((1 << PHY84328_DEV1_GP_REGISTER_1_SYSTEM_LR_MODE_SHIFT) | (1 << PHY84328_DEV1_GP_REGISTER_1_SYSTEM_CU_TYPE_SHIFT)) : ((1 << PHY84328_DEV1_GP_REGISTER_1_LINE_LR_MODE_SHIFT) | (1 << PHY84328_DEV1_GP_REGISTER_1_LINE_CU_TYPE_SHIFT)); break; case SOC_PORT_IF_LR: case SOC_PORT_IF_LR4: data = (side == PHY84328_INTF_SIDE_SYS) ? (1 << PHY84328_DEV1_GP_REGISTER_1_SYSTEM_LR_MODE_SHIFT) : (1 << PHY84328_DEV1_GP_REGISTER_1_LINE_LR_MODE_SHIFT); break; default: LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 Unsupported interface: u=%d p=%d\n"), unit, port)); return SOC_E_UNAVAIL; }; *reg_data |= (data | PHY84328_DEV1_GP_REGISTER_1_FINISH_CHANGE); if (side == PHY84328_INTF_SIDE_LINE) { *reg_mask |= (PHY84328_DEV1_GP_REGISTER_1_LINE_LR_MODE_MASK | PHY84328_DEV1_GP_REGISTER_1_LINE_FORCED_CL72_MODE_MASK | PHY84328_DEV1_GP_REGISTER_1_LINE_CU_TYPE_MASK | PHY84328_DEV1_GP_REGISTER_1_FINISH_CHANGE_MASK | PHY84328_DEV1_GP_REGISTER_1_LINE_TYPE_MASK); } else { /* System side mask */ *reg_mask |= (PHY84328_DEV1_GP_REGISTER_1_SYSTEM_LR_MODE_MASK | PHY84328_DEV1_GP_REGISTER_1_SYSTEM_FORCED_CL72_MODE_MASK | PHY84328_DEV1_GP_REGISTER_1_SYSTEM_CU_TYPE_MASK | PHY84328_DEV1_GP_REGISTER_1_FINISH_CHANGE_MASK | PHY84328_DEV1_GP_REGISTER_1_SYSTEM_TYPE_MASK); } LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 intf type register: u=%d, p=%d, reg=%04x/%04x, intf=%d\n"), unit, port, *reg_data, *reg_mask, intf_type)); return SOC_E_NONE; } STATIC int _phy_84328_polarity_redo(int unit, soc_port_t port) { phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); return _phy_84328_polarity_flip(unit, port, POL_TX_CFG(pc), POL_RX_CFG(pc)); } STATIC void _phy_84328_micro_pause(int unit, soc_port_t port, const char *loc) { int rv = SOC_E_NONE; uint16 data, mask; int checks; uint16 csr; uint16 saved_side; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); phy84328_micro_ctrl_t *micro_ctrl = &(MICRO_CTRL(pc)); phy84328_counters_t *counters = &(COUNTERS(pc)); if (!micro_ctrl->enable) { return; } /* Access line side registers */ saved_side = _phy_84328_intf_side_regs_get(unit, port); if (saved_side == PHY84328_INTF_SIDE_SYS) { _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_LINE); } micro_ctrl->count++; /* Quiet micro */ data = 0; mask = 0xff00; rv = MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_GP_REG_0, data, mask); if (rv != SOC_E_NONE) { goto fail; } sal_udelay(500); checks = 0; while (checks < 1000) { /* Make sure micro really paused */ rv = READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_GP_REG_2, &data); if (rv != SOC_E_NONE) { goto fail; } if ((data & mask) == 0) { break; } sal_udelay(100); checks++; } if (data & mask) { rv = READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_GP_REG_0, &csr); if (rv != SOC_E_NONE) { goto fail; } LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 microcode did not pause in %s: " "u=%d p%d 1.ca18/1.ca19=%04x/%04x checks=%d\n"), loc, unit, port, csr, data, checks)); counters->micro_nopause++; } fail: if (saved_side != PHY84328_INTF_SIDE_LINE) { _phy_84328_intf_side_regs_select(unit, port, saved_side); } return; } STATIC void _phy_84328_micro_resume(int unit, soc_port_t port) { phy84328_intf_side_t saved_side; int rv = SOC_E_NONE; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); phy84328_micro_ctrl_t *micro_ctrl = &(MICRO_CTRL(pc)); if (!micro_ctrl->enable) { return; } /* Access line side registers */ saved_side = _phy_84328_intf_side_regs_get(unit, port); if (saved_side == PHY84328_INTF_SIDE_SYS) { _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_LINE); } micro_ctrl->count--; if (micro_ctrl->count <= 0) { rv = MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_GP_REG_0, 0xff00, 0xff00); if (rv != SOC_E_NONE) { goto fail; } if (micro_ctrl->count < 0) { LOG_VERBOSE(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 unmatched micro resume\n"))); micro_ctrl->count = 0;; } } fail: if (saved_side != PHY84328_INTF_SIDE_LINE) { _phy_84328_intf_side_regs_select(unit, port, saved_side); } return; } STATIC int _phy_84328_config_update(int unit, soc_port_t port) { int rv; phy84328_datapath_t save_dp; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); PHY_84328_MICRO_PAUSE(unit, port, "config update"); SOC_IF_ERROR_RETURN(_phy_84328_tx_config(unit, port)); save_dp = CUR_DATAPATH(pc); CUR_DATAPATH(pc) = PHY84328_DATAPATH_20; rv = _phy_84328_polarity_redo(unit, port); if (rv != SOC_E_NONE) { LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 failed updating config: u=%d port=%d\n"), unit, port)); } if (save_dp != PHY84328_DATAPATH_20) { CUR_DATAPATH(pc) = PHY84328_DATAPATH_4_DEPTH1; rv = _phy_84328_polarity_redo(unit, port); if (rv != SOC_E_NONE) { LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 failed updating config: u=%d port=%d\n"), unit, port)); } } if (save_dp != CUR_DATAPATH(pc)) { CUR_DATAPATH(pc) = save_dp; } _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_SYS); /* Bypass steady state tuning */ if (BYPASS_SS_TUNING(pc)) { SOC_IF_ERROR_RETURN( MODIFY_PHY84328_MMF_PMA_PMD_REG( unit, pc, PHY84328_DEV1_TUNING_STATE_BYPASS, PHY84328_DEV1_TUNING_STATE_BYPASS_BYPASS_STEADY_STATE_TUNING_MASK, PHY84328_DEV1_TUNING_STATE_BYPASS_BYPASS_STEADY_STATE_TUNING_MASK)); } else { SOC_IF_ERROR_RETURN( MODIFY_PHY84328_MMF_PMA_PMD_REG( unit, pc, PHY84328_DEV1_TUNING_STATE_BYPASS, 0, PHY84328_DEV1_TUNING_STATE_BYPASS_BYPASS_STEADY_STATE_TUNING_MASK)); } _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_LINE); PHY_84328_MICRO_RESUME(unit, port); return SOC_E_NONE; } /* * Updates are done to GP_REGISTER_1 which are line side registers only, ie. no * system side instances of these registers */ STATIC int _phy_84328_intf_update(int unit, soc_port_t port, uint16 reg_data, uint16 reg_mask) { uint16 ucode_csr_bef = 0, ucode_csr = 0, drv_csr = 0; phy84328_intf_side_t saved_side; soc_timeout_t to; int rv = SOC_E_NONE; uint32 checks; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); phy84328_counters_t *counters = &(COUNTERS(pc)); /* Access line side registers */ saved_side = _phy_84328_intf_side_regs_get(unit, port); if (saved_side == PHY84328_INTF_SIDE_SYS) { _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_LINE); } /* Make sure ucode has acked */ rv = READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_GP_REGISTER_3, &ucode_csr_bef); if (SOC_FAILURE(rv)) { LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 failed reading ucode csr: u=%d p=%d err=%d\n"), unit, port, rv)); goto fail; } if ((ucode_csr_bef & PHY84328_DEV1_GP_REGISTER_3_FINISH_CHANGE_MASK) == PHY84328_DEV1_GP_REGISTER_3_FINISH_CHANGE_MASK) { /* Cmd active and ucode acked, so let ucode know drv saw ack */ rv = MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_GP_REGISTER_1, 0, PHY84328_DEV1_GP_REGISTER_1_FINISH_CHANGE_MASK); if (SOC_FAILURE(rv)) { LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 failed clearing ack: u=%d p=%d err=%d\n"), unit, port, rv)); goto fail; } /* Wait for ucode to CTS */ soc_timeout_init(&to, 1000000, 0); while (!soc_timeout_check(&to)) { rv = READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_GP_REGISTER_3, &ucode_csr); if (SOC_FAILURE(rv)) { LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 failed reading ucode csr: u=%d p=%d err=%d\n"), unit, port, rv)); goto fail; } if ((ucode_csr & PHY84328_DEV1_GP_REGISTER_3_FINISH_CHANGE_MASK) == 0) { break; } } if ((ucode_csr & PHY84328_DEV1_GP_REGISTER_3_FINISH_CHANGE_MASK) != 0) { (void) READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_GP_REGISTER_1, &drv_csr); LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 ucode failed to clear to send: u=%d p=%d 1.%04x=%04x 1.%04x=%04x(%04x)\n"), unit, port, PHY84328_DEV1_GP_REGISTER_1, drv_csr, PHY84328_DEV1_GP_REGISTER_3, ucode_csr, ucode_csr_bef)); rv = SOC_E_TIMEOUT; goto fail; } } LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 intf update register: u=%d, p=%d, 1.%04x=%04x/%04x ucode_csr=%04x\n"), unit, port, PHY84328_DEV1_GP_REGISTER_1, reg_data, reg_mask, ucode_csr)); counters->intf_updates++; /* Send command */ rv = MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_GP_REGISTER_1, reg_data, reg_mask); if (SOC_FAILURE(rv)) { LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 failed sending command to ucode: u=%d p=%d err=%d\n"), unit, port, rv)); goto fail; } /* Handshake with microcode by waiting for ack before moving on */ checks = 0; while (checks < 10000) { rv = READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_GP_REGISTER_3, &ucode_csr); if (SOC_FAILURE(rv)) { LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 failed reading ucode csr: u=%d p=%d err=%d\n"), unit, port, rv)); goto fail; } if ((ucode_csr & PHY84328_DEV1_GP_REGISTER_3_FINISH_CHANGE_MASK) == PHY84328_DEV1_GP_REGISTER_3_FINISH_CHANGE_MASK) { break; } sal_udelay(100); checks++; } if ((ucode_csr & PHY84328_DEV1_GP_REGISTER_3_FINISH_CHANGE_MASK) != PHY84328_DEV1_GP_REGISTER_3_FINISH_CHANGE_MASK) { uint16 micro_en; (void) READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_GP_REGISTER_1, &drv_csr); (void) READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_GP_REG_0, &micro_en); LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328: microcode failed to ack: u=%d p=%d 1.%04x=%04x 1.%04x=%04x " "1.%04x=%04x checks=%d\n"), unit, port, PHY84328_DEV1_GP_REGISTER_1, drv_csr, PHY84328_DEV1_GP_REGISTER_3, ucode_csr, PHY84328_DEV1_GP_REG_0, micro_en, checks)); rv = SOC_E_TIMEOUT; goto fail; } /* Cmd active and ucode acked - let ucode know we saw ack */ rv = MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_GP_REGISTER_1, 0, PHY84328_DEV1_GP_REGISTER_1_FINISH_CHANGE_MASK); if (rv != SOC_E_NONE) { goto fail; } fail: if (saved_side == PHY84328_INTF_SIDE_SYS) { _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_SYS); } return rv; } /* * Populates interface type and speed for line and system side interfaces based on * line side interface speed and system side interface type * * Assumption: * line_intf->speed: must already be set based on port configuration * sys_intf->type: must be set to either the configured _spn_PHY_SYS_INTERFACE value or default */ STATIC int _phy_84328_intf_line_sys_params_get(int unit, soc_port_t port) { phy84328_intf_cfg_t *line_intf; phy84328_intf_cfg_t *sys_intf; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); line_intf = &(LINE_INTF(pc)); sys_intf = &(SYS_INTF(pc)); /* * System side interface was specified so make sure it's compatible with * line side speed. If not, overwrite with default compatible interface */ if (PHY84328_MULTI_CORE_MODE(pc)) { sys_intf->speed = 100000; line_intf->type = SOC_PORT_IF_CAUI; sys_intf->type = SOC_PORT_IF_CAUI; } else if (line_intf->speed == 40000) { sys_intf->speed = 40000; line_intf->type = SOC_PORT_IF_SR4; if (!(_phy_84328_intf_is_single_port(sys_intf->type))) { /* system side interface is not compatible so overwrite with default */ LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "PHY84328 incompatible 40G system side interface, " "using default: u=%d p=%d\n"), unit, port)); sys_intf->type = SOC_PORT_IF_XLAUI; } } else { /* 10G/1G */ if (_phy_84328_intf_is_quad_port(sys_intf->type)) { if (sys_intf->type == SOC_PORT_IF_KX) { line_intf->speed = 1000; line_intf->type = SOC_PORT_IF_GMII; sys_intf->speed = 1000; } else { /* 10G system side so fix line side to be 10G compatible */ line_intf->speed = 10000; line_intf->type = SOC_PORT_IF_SR; sys_intf->speed = 10000; } } else { /* system side interface is not compatible so overwrite with default */ LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "PHY84328 incompatible 10G/1G system side interface, " "using default: u=%d p=%d\n"), unit, port)); /* default to 10G interface/speed on both sides */ line_intf->speed = 10000; line_intf->type = SOC_PORT_IF_SR; sys_intf->speed = 10000; sys_intf->type = SOC_PORT_IF_XFI; } } return SOC_E_NONE; } STATIC int _phy_84328_intf_line_sys_update(int unit, soc_port_t port) { phy_ctrl_t *pc; phy_ctrl_t *int_pc; int int_phy_en = 0; uint16 data = 0, mask = 0; uint16 reg_data = 0, reg_mask = 0; phy84328_intf_cfg_t *line_intf, *sys_intf; pc = EXT_PHY_SW_STATE(unit, port); int_pc = INT_PHY_SW_STATE(unit, port); line_intf = &(LINE_INTF(pc)); sys_intf = &(SYS_INTF(pc)); _phy_84328_intf_print(unit, port, "intf update"); reg_data = 0; reg_mask = 0; SOC_IF_ERROR_RETURN( _phy_84328_intf_type_reg_get(unit, port, line_intf->type, PHY84328_INTF_SIDE_LINE, &data, &mask)); reg_data |= data; reg_mask |= mask; SOC_IF_ERROR_RETURN( _phy_84328_intf_type_reg_get(unit, port, sys_intf->type, PHY84328_INTF_SIDE_SYS, &data, &mask)); reg_data |= data; reg_mask |= mask; SOC_IF_ERROR_RETURN( _phy_84328_intf_speed_reg_get(unit, port, line_intf->speed, &data, &mask)); reg_data |= data; reg_mask |= mask; SOC_IF_ERROR_RETURN( _phy_84328_intf_datapath_reg_get(unit, port, CUR_DATAPATH(pc), &data, &mask)); reg_data |= data; reg_mask |= mask; LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 intf update: line=%s sys=%s speed=%d (1.%x = %04x/%04x): u=%d p=%d\n"), phy84328_intf_names[line_intf->type], phy84328_intf_names[sys_intf->type], line_intf->speed, PHY84328_DEV1_GP_REGISTER_1, reg_data, reg_mask, unit, port)); if (SYNC_INIT(pc) == 1) { SOC_IF_ERROR_RETURN(PHY_ENABLE_GET(int_pc->pd, unit, port, &int_phy_en)); if (int_phy_en) { /* Turn off internal PHY while the mode changes */ SOC_IF_ERROR_RETURN(PHY_ENABLE_SET(int_pc->pd, unit, port, 0)); } } /* GP registers are only on the line side */ SOC_IF_ERROR_RETURN(_phy_84328_intf_update(unit, port, reg_data, reg_mask)); if (SYNC_INIT(pc) == 1) { if (int_phy_en) { /* If called from PASS2 we skip this and complete in PASS3 */ if ((PHYCTRL_INIT_STATE(pc) == PHYCTRL_INIT_STATE_PASS2)) { INT_PHY_RE_EN(pc) = 1; /* start timer */ soc_timeout_init(&SYNC_TO(pc), 10000, 0); } else { sal_usleep(10000); /* Turn internal PHY back on now that the mode has been configured */ SOC_IF_ERROR_RETURN(PHY_ENABLE_SET(int_pc->pd, unit, port, 1)); } } } return SOC_E_NONE; } /* * Return the settings in gp_reg_1/gp_register_1 for the inteface speed * Register data and mask are returned to modify the register. */ STATIC int _phy_84328_intf_speed_reg_get(int unit, soc_port_t port, int speed, uint16 *reg_data, uint16 *reg_mask) { *reg_data = 0; *reg_mask = 0; switch (speed) { case 100000: *reg_data = PHY84328_DEV1_GP_REGISTER_1_SPEED_100G; break; case 42000: *reg_data = PHY84328_DEV1_GP_REGISTER_1_SPEED_42G; break; case 40000: *reg_data = PHY84328_DEV1_GP_REGISTER_1_SPEED_40G; break; case 10000: *reg_data = PHY84328_DEV1_GP_REGISTER_1_SPEED_10G; break; case 1000: case 100: case 10: /* This is a special mode that uses the 10G PLL but runs at 1G */ *reg_data = (PHY84328_DEV1_GP_REGISTER_1_SPEED_10G | PHY84328_DEV1_GP_REGISTER_1_SPEED_1G); break; default : LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 invalid line speed %d: u=%d p=%d\n"), speed, unit, port)); return SOC_E_CONFIG; } *reg_data |= PHY84328_DEV1_GP_REGISTER_1_FINISH_CHANGE; *reg_mask |= (PHY84328_DEV1_GP_REGISTER_1_SPEED_1G_MASK | PHY84328_DEV1_GP_REGISTER_1_SPEED_10G_MASK | PHY84328_DEV1_GP_REGISTER_1_SPEED_40G_MASK | PHY84328_DEV1_GP_REGISTER_1_SPEED_100G_MASK | PHY84328_DEV1_GP_REGISTER_1_FINISH_CHANGE_MASK); LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 speed set register: u=%d, p=%d, reg=%04x/%04x), speed=%d\n"), unit, port, *reg_data, *reg_mask, speed)); return SOC_E_NONE; } STATIC int _phy_84328_intf_datapath_reg_get(int unit, soc_port_t port, phy84328_datapath_t datapath, uint16 *reg_data, uint16 *reg_mask) { *reg_data = 0; *reg_mask = 0; switch (datapath) { case PHY84328_DATAPATH_20: *reg_data = 0; break; case PHY84328_DATAPATH_4_DEPTH1: *reg_data = PHY84328_DEV1_GP_REGISTER_1_DATAPATH_4_DEPTH1; break; case PHY84328_DATAPATH_4_DEPTH2: *reg_data = PHY84328_DEV1_GP_REGISTER_1_DATAPATH_4_DEPTH2; break; default : LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 invalid datapath: u=%d p=%d datapath=%d\n"), unit, port, datapath)); return SOC_E_CONFIG; } *reg_data |= PHY84328_DEV1_GP_REGISTER_1_FINISH_CHANGE; *reg_mask = (PHY84328_DEV1_GP_REGISTER_1_DATAPATH_MASK | PHY84328_DEV1_GP_REGISTER_1_FINISH_CHANGE_MASK); LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 datapath set register: u=%d, p=%d, reg=%04x/%04x, datapath=%d\n"), unit, port, *reg_data, *reg_mask, datapath)); return SOC_E_NONE; } STATIC int _phy_84328_intf_datapath_update(int unit, soc_port_t port) { phy_ctrl_t *pc; uint16 data = 0, mask = 0; pc = EXT_PHY_SW_STATE(unit, port); SOC_IF_ERROR_RETURN( _phy_84328_intf_datapath_reg_get(unit, port, CUR_DATAPATH(pc), &data, &mask)); /* GP registers are only on the line side */ SOC_IF_ERROR_RETURN(_phy_84328_intf_update(unit, port, data, mask)); return SOC_E_NONE; } /* * Select channel with mapped access based on interface side and lane number * For details, see PHY-700 */ STATIC int _phy_84328_channel_mapped_select(int unit, soc_port_t port, phy84328_intf_side_t side, int lane) { uint16 lane_sel; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); /* logical channel number for physical channel, indexed by lane/channel */ static uint16 log_ch_map[] = { 0xe4, 0xe1, 0xc6, 0x27 }; if (lane == PHY84328_ALL_LANES) { /* Restore 1:1 channel mappings */ SOC_IF_ERROR_RETURN( MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_LOGAD_CTRL, 0xe4, 0x00ff)); lane_sel = (LOGICAL_LANE0(pc) << PHY84328_DEV1_SINGLE_PMD_CTRL_PHY_CH_TO_ACCESS_IN_SINGLE_PMD_SHIFT) | PHY84328_DEV1_SINGLE_PMD_CTRL_SINGLE_PMD_MODE_MASK | PHY84328_DEV1_SINGLE_PMD_CTRL_PHY_CH_TO_BE_DISABLE_IN_SINGLE_PMD_MASK; } else { /* System side interface always use first channel which then is mapped */ if (side == PHY84328_INTF_SIDE_SYS) { lane_sel = 1; } else { /* Select channel in Single PMD 1.ca86[5:4] and [3..0] that corresponds to lane */ lane_sel = (lane << PHY84328_DEV1_SINGLE_PMD_CTRL_PHY_CH_TO_ACCESS_IN_SINGLE_PMD_SHIFT) | ((1 << lane) & PHY84328_DEV1_SINGLE_PMD_CTRL_PHY_CH_TO_BE_DISABLE_IN_SINGLE_PMD_MASK); } } SOC_IF_ERROR_RETURN( MODIFY_PHY84328_MMF_PMA_PMD_REG( unit, pc, PHY84328_DEV1_SINGLE_PMD_CTRL, lane_sel, PHY84328_DEV1_SINGLE_PMD_CTRL_PHY_CH_TO_ACCESS_IN_SINGLE_PMD_MASK | PHY84328_DEV1_SINGLE_PMD_CTRL_PHY_CH_TO_BE_DISABLE_IN_SINGLE_PMD_MASK)); if (side == PHY84328_INTF_SIDE_SYS) { /* Map the logical channel from physical channel */ lane_sel = (lane == PHY84328_ALL_LANES) ? log_ch_map[0] : log_ch_map[lane]; SOC_IF_ERROR_RETURN( MODIFY_PHY84328_MMF_PMA_PMD_REG( unit, pc, PHY84328_DEV1_LOGAD_CTRL, lane_sel, 0x00ff)); /* Now go to system side to access register */ _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_SYS); } return SOC_E_NONE; } /* * Directly select channel to access based on interface side and lane number. */ STATIC int _phy_84328_channel_direct_select(int unit, soc_port_t port, phy84328_intf_side_t side, int lane) { uint16 lane_sel; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); /* * If all lanes, restore single PMD access with lane 0 broadcast to all lanes * For single lane, select lane in Single PMD 1.ca86[5:4] and [3..0] that corresponds * to the lane with direct lane selection in 1.ca86[8] */ if (lane == PHY84328_ALL_LANES) { lane_sel = (LOGICAL_LANE0(pc) << PHY84328_DEV1_SINGLE_PMD_CTRL_PHY_CH_TO_ACCESS_IN_SINGLE_PMD_SHIFT) | PHY84328_DEV1_SINGLE_PMD_CTRL_SINGLE_PMD_MODE_MASK | PHY84328_DEV1_SINGLE_PMD_CTRL_PHY_CH_TO_BE_DISABLE_IN_SINGLE_PMD_MASK; } else { lane_sel = 0x100 | (lane << PHY84328_DEV1_SINGLE_PMD_CTRL_PHY_CH_TO_ACCESS_IN_SINGLE_PMD_SHIFT) | ((1 << lane) & PHY84328_DEV1_SINGLE_PMD_CTRL_PHY_CH_TO_BE_DISABLE_IN_SINGLE_PMD_MASK); } SOC_IF_ERROR_RETURN( MODIFY_PHY84328_MMF_PMA_PMD_REG( unit, pc, PHY84328_DEV1_SINGLE_PMD_CTRL, lane_sel, 0x100 | PHY84328_DEV1_SINGLE_PMD_CTRL_PHY_CH_TO_ACCESS_IN_SINGLE_PMD_MASK | PHY84328_DEV1_SINGLE_PMD_CTRL_PHY_CH_TO_BE_DISABLE_IN_SINGLE_PMD_MASK)); if (side == PHY84328_INTF_SIDE_SYS) { /* Now go to system side to access register */ _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_SYS); } return SOC_E_NONE; } /* * Select channel to access based on interface side and lane number. * The side is selected before returning. */ STATIC int _phy_84328_channel_select(int unit, soc_port_t port, phy84328_intf_side_t side, int lane) { int rv; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); if (!(PHY84328_SINGLE_PORT_MODE(pc))) { return SOC_E_PARAM; } if (!((lane == PHY84328_ALL_LANES) || ((lane >= 0) && (lane <= 3)))) { return SOC_E_PARAM; } _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_LINE); if ((side == PHY84328_INTF_SIDE_LINE) || (DEVREV(pc) != 0x00a0)) { rv = _phy_84328_channel_direct_select(unit, port, side, lane); } else { rv = _phy_84328_channel_mapped_select(unit, port, side, lane); } return rv; } /* * 20-bit: set txpol in line side 1.c061[5] * 4-bit: set txpol in line side 1.c068[12] */ STATIC int _phy_84328_polarity_flip_tx_set(int unit, soc_port_t port, int flip) { uint16 data, mask; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); /* Clear to flip, set to unflip */ if (CUR_DATAPATH(pc) == PHY84328_DATAPATH_20) { data = flip ? 0 : PHY84328_DEV1_ANATXACONTROL_TXPOL_FLIP_MASK; mask = PHY84328_DEV1_ANATXACONTROL_TXPOL_FLIP_MASK; SOC_IF_ERROR_RETURN( MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_ANATXACONTROL, data, mask)); } else { data = flip ? 0 : PHY84328_DEV1_ANATXACONTROL4_XFI_LOWLATENCY_POLARITY_FLIP_MASK; mask = PHY84328_DEV1_ANATXACONTROL4_XFI_LOWLATENCY_POLARITY_FLIP_MASK; SOC_IF_ERROR_RETURN( MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_ANATXACONTROL4, data, mask)); } return SOC_E_NONE; } STATIC int _phy_84328_polarity_flip_tx(int unit, soc_port_t port, uint16 cfg_pol) { int flip; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); if ((PHY84328_SINGLE_PORT_MODE(pc))) { int lane; for (lane = 0; lane < PHY84328_NUM_LANES; lane++) { /* Check for all lanes or whether this lane has polarity flipped */ if ((cfg_pol == POL_CONFIG_ALL_LANES) || ((cfg_pol & POL_CONFIG_LANE_MASK(lane)) == POL_CONFIG_LANE_MASK(lane))) { flip = 1; } else { flip = 0; } LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 tx polarity flip=%d: u=%d p=%d lane=%d\n"), flip, unit, port, lane)); /* Select the lane on the line side */ SOC_IF_ERROR_RETURN(_phy_84328_channel_select(unit, port, PHY84328_INTF_SIDE_LINE, lane)); SOC_IF_ERROR_RETURN(_phy_84328_polarity_flip_tx_set(unit, port, flip)); } /* Restore to default single port register access */ SOC_IF_ERROR_RETURN(_phy_84328_channel_select(unit, port, PHY84328_INTF_SIDE_LINE, PHY84328_ALL_LANES)); _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_LINE); } else { /* quad mode */ flip = PHY84328_10G_POL_CFG_GET(pc,cfg_pol); SOC_IF_ERROR_RETURN(_phy_84328_polarity_flip_tx_set(unit, port, flip)); LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 polarity flip: u=%d p=%d\n"), unit, port)); } return SOC_E_NONE; } /* RX polarity in 20-bit line side with rx inversion in 1.c0ba[3:2] */ STATIC int _phy_84328_polarity_flip_rx_20bit(int unit, soc_port_t port, int flip) { uint16 data, mask; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); /* Default is clear, set to flip it */ data = flip ? (PHY84328_DEV1_GP_REGISTER_RX_INV_FORCE | PHY84328_DEV1_GP_REGISTER_RX_INV_INVERT) : 0; mask = (PHY84328_DEV1_GP_REGISTER_RX_INV_FORCE | PHY84328_DEV1_GP_REGISTER_RX_INV_INVERT); SOC_IF_ERROR_RETURN( MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_GP_REGISTER_RX_INV, data, mask)); return SOC_E_NONE; } /* RX polarity in 4-bit system side polarity in 1.c068[12] */ STATIC int _phy_84328_polarity_flip_rx_4bit(int unit, soc_port_t port, int flip) { uint16 data, mask; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); /* Default is set, clear to flip it */ data = flip ? 0 : PHY84328_DEV1_ANATXACONTROL4_XFI_LOWLATENCY_POLARITY_FLIP_MASK; mask = PHY84328_DEV1_ANATXACONTROL4_XFI_LOWLATENCY_POLARITY_FLIP_MASK; SOC_IF_ERROR_RETURN( MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_ANATXACONTROL4, data, mask)); return SOC_E_NONE; } STATIC int _phy_84328_polarity_flip_rx(int unit, soc_port_t port, uint16 cfg_pol) { int flip; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); /* * RX polarity flipping in 20-bit done on the line side while 4-bit done on the system side */ if ((PHY84328_SINGLE_PORT_MODE(pc))) { int lane; /* 4-bit polarity handled on system side */ if (CUR_DATAPATH(pc) != PHY84328_DATAPATH_20) { PHY_84328_MICRO_PAUSE(unit, port, "polarity rx"); } for (lane = 0; lane < PHY84328_NUM_LANES; lane++) { flip = 0; if ((cfg_pol == POL_CONFIG_ALL_LANES) || ((cfg_pol & POL_CONFIG_LANE_MASK(lane)) == POL_CONFIG_LANE_MASK(lane))) { flip = 1; } if (CUR_DATAPATH(pc) == PHY84328_DATAPATH_20) { SOC_IF_ERROR_RETURN(_phy_84328_channel_select(unit, port, PHY84328_INTF_SIDE_LINE, lane)); SOC_IF_ERROR_RETURN(_phy_84328_polarity_flip_rx_20bit(unit, port, flip)); } else { SOC_IF_ERROR_RETURN(_phy_84328_channel_select(unit, port, PHY84328_INTF_SIDE_SYS, lane)); SOC_IF_ERROR_RETURN(_phy_84328_polarity_flip_rx_4bit(unit, port, flip)); } LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 rx polarity flip: u=%d p=%d lane=%d\n"), unit, port, lane)); } /* Restore to default single port register access */ SOC_IF_ERROR_RETURN(_phy_84328_channel_select(unit, port, PHY84328_INTF_SIDE_LINE, PHY84328_ALL_LANES)); _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_LINE); if (CUR_DATAPATH(pc) != PHY84328_DATAPATH_20) { PHY_84328_MICRO_RESUME(unit, port); } } else { /* quad mode */ flip = PHY84328_10G_POL_CFG_GET(pc,cfg_pol); if (CUR_DATAPATH(pc) == PHY84328_DATAPATH_20) { _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_LINE); SOC_IF_ERROR_RETURN(_phy_84328_polarity_flip_rx_20bit(unit, port, flip)); } else { _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_SYS); SOC_IF_ERROR_RETURN(_phy_84328_polarity_flip_rx_4bit(unit, port, flip)); _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_LINE); } LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 rx polarity flip: u=%d p=%d\n"), unit, port)); } return SOC_E_NONE; } /* * Flip configured tx/rx polarities * * Property values are either 1 for all lanes or * lane 0: 000f * lane 1: 00f0 * lane 2: 0f00 * lane 3: f000 */ STATIC int _phy_84328_polarity_flip(int unit, soc_port_t port, uint16 cfg_tx_pol, uint16 cfg_rx_pol) { LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 polarity flip: u=%d p%d TX=%x RX=%x\n"), unit, port, cfg_tx_pol, cfg_rx_pol)); SOC_IF_ERROR_RETURN(_phy_84328_polarity_flip_tx(unit, port, cfg_tx_pol)); SOC_IF_ERROR_RETURN(_phy_84328_polarity_flip_rx(unit, port, cfg_rx_pol)); return SOC_E_NONE; } STATIC int _phy_84328_config_devid(int unit,soc_port_t port, phy_ctrl_t *pc, uint32 *devid) { if (soc_property_port_get(unit, port, "phy_84328", FALSE)) { return *devid = PHY84328_ID_84328; } return _phy_84328_chip_id_get(unit, port, pc, devid); } STATIC int _phy_84328_tx_mode_set(int unit, soc_port_t port, phy84328_intf_side_t side, uint16 tx_mode) { phy_ctrl_t *pc; phy84328_intf_side_t saved_side; /* Make sure tx_mode has acceptable values */ if ((tx_mode != 0) && (tx_mode != 1) && (tx_mode != 4)) { LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "PHY84328 invalid tx mode configuration - must be 0, 1, or 4: u%d p%d\n"), unit, port)); return SOC_E_NONE; } pc = EXT_PHY_SW_STATE(unit, port); saved_side = _phy_84328_intf_side_regs_get(unit, port); _phy_84328_intf_side_regs_select(unit, port, side); /* Set manual tx mode updates */ SOC_IF_ERROR_RETURN(_phy_84328_txmode_manual_set(unit, port, side, TRUE)); SOC_IF_ERROR_RETURN( MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_ANATXACONTROL2, tx_mode << PHY84328_DEV1_ANATXACONTROL2_TX_MODESELECT_SHIFT, PHY84328_DEV1_ANATXACONTROL2_TX_MODESELECT_MASK)); if (saved_side != side) { _phy_84328_intf_side_regs_select(unit, port, saved_side); } return SOC_E_NONE; } STATIC int _phy_84328_tx_mode_get(int unit, soc_port_t port, phy84328_intf_side_t side, uint16 *tx_mode) { phy_ctrl_t *pc; uint16 data; phy84328_intf_side_t saved_side; pc = EXT_PHY_SW_STATE(unit, port); saved_side = _phy_84328_intf_side_regs_get(unit, port); _phy_84328_intf_side_regs_select(unit, port, side); SOC_IF_ERROR_RETURN( READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_ANATXACONTROL2, &data)); /* Must exclude bit 13 from tx_mode */ *tx_mode = (data >> PHY84328_DEV1_ANATXACONTROL2_TX_MODESELECT_SHIFT) & 0xd; if (saved_side != side) { _phy_84328_intf_side_regs_select(unit, port, saved_side); } return SOC_E_NONE; } STATIC int _phy_84328_tx_config(int unit, soc_port_t port) { int tx_mode = -1; int tx_idriver = -1; /* tx_modeselect: 0, 1, or 4 */ tx_mode = soc_property_port_get(unit, port, "phy_line_tx_mode", -1); if (tx_mode != -1) { SOC_IF_ERROR_RETURN(_phy_84328_tx_mode_set(unit, port, PHY84328_INTF_SIDE_LINE, (uint16) tx_mode)); } tx_mode = soc_property_port_get(unit, port, "phy_system_tx_mode", -1); if (tx_mode != -1) { SOC_IF_ERROR_RETURN(_phy_84328_tx_mode_set(unit, port, PHY84328_INTF_SIDE_SYS, (uint16) tx_mode)); } /* tx idriver: 0..15 */ tx_idriver = soc_property_port_get(unit, port, "phy_line_driver_current", -1); if (tx_idriver != -1) { SOC_IF_ERROR_RETURN(_phy_84328_control_tx_driver_set(unit, port, SOC_PHY_CONTROL_DRIVER_CURRENT, PHY84328_INTF_SIDE_LINE, tx_idriver)); } tx_idriver = soc_property_port_get(unit, port, "phy_system_driver_current", -1); if (tx_idriver != -1) { SOC_IF_ERROR_RETURN(_phy_84328_control_tx_driver_set(unit, port, SOC_PHY_CONTROL_DRIVER_CURRENT, PHY84328_INTF_SIDE_SYS, tx_idriver)); } return SOC_E_NONE; } STATIC phy84328_datapath_t _phy_84328_datapath_get(int unit, soc_port_t port) { phy84328_datapath_t dp = PHY84328_DATAPATH_20; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); switch (DEVREV(pc)) { case 0x00a0: dp = PHY84328_DATAPATH_20; break; case 0x00b0: default: dp = PHY84328_DATAPATH_4_DEPTH1; break; } return dp; } #if 1 STATIC int _phy_84328_intf_sys_default(int unit, soc_port_t port) { uint16 if_sys_idx = 0; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); if (PHY84328_MULTI_CORE_MODE(pc)) { if_sys_idx = 0; } else { /* Get configured system interface */ if_sys_idx = soc_property_port_get(unit, port, spn_PHY_SYS_INTERFACE, 0); if (if_sys_idx >= (sizeof(phy_sys_to_port_if) / sizeof(soc_port_if_t))) { LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "PHY84328 invalid system side interface: u=%d p=%d intf=%d\n" "Using default interface\n"), unit, port, if_sys_idx)); if_sys_idx = 0; } } return if_sys_idx; } STATIC int _phy_84328_intf_line_speed_default(int unit, soc_port_t port) { int speed; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); if (PHY84328_MULTI_CORE_MODE(pc)) { speed = 100000; } else if (PHY84328_SINGLE_PORT_MODE(pc)) { speed = 40000; } else { speed = 10000; } return speed; } STATIC soc_port_if_t _phy_84328_intf_type_default(int speed, phy84328_intf_side_t side) { soc_port_if_t intf; switch (speed) { case 100000: /**** SR10 on line side? */ intf = (side == PHY84328_INTF_SIDE_LINE) ? SOC_PORT_IF_SR4 : SOC_PORT_IF_CAUI; break; case 40000: intf = (side == PHY84328_INTF_SIDE_LINE) ? SOC_PORT_IF_SR4 : SOC_PORT_IF_XLAUI; break; case 10000: default: intf = (side == PHY84328_INTF_SIDE_LINE) ? SOC_PORT_IF_SR : SOC_PORT_IF_XFI; break; } return intf; } STATIC int _phy_84328_intf_default(int unit, soc_port_t port) { phy84328_intf_cfg_t *line_intf, *sys_intf; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); line_intf = &(LINE_INTF(pc)); sys_intf = &(SYS_INTF(pc)); sal_memset(line_intf, 0, sizeof(phy84328_intf_cfg_t)); sal_memset(sys_intf, 0, sizeof(phy84328_intf_cfg_t)); /* * - interfaces are KR4/KR/KX/XAUI/XFI/SR/LR/CR/SR4/LR4/CR4/SR10/CR10 * - Gallardo is capable of being configured symmetrically and can support all * interfaces on both sides * - system side interfaces cannot be changed dynamically * - configured in Gallardo via config variables * - line side mode can be changed dynamically * - configured specifically with interface set and/or by matching speed * - automatically when module autodetect is enabled * * port mode system side line side * ---------------- ------------------------ -------------------------------- * 100G(multicore) dflt:CAUI dflt:SR10 or user set if/speed * 40G(singleport) dflt:XLAUI or configvar dflt:XLAUI or user set if/speed * 1G/10G(quadport) dflt:XFI or configvar dflt:SFI or user set if/speed */ /* Get configured system interface */ sys_intf->type = phy_sys_to_port_if[_phy_84328_intf_sys_default(unit, port)]; line_intf->speed = _phy_84328_intf_line_speed_default(unit, port); if (sys_intf->type == 0) { /* use defaults based on current line side */ sys_intf->speed = line_intf->speed; line_intf->type = _phy_84328_intf_type_default(line_intf->speed, PHY84328_INTF_SIDE_LINE); sys_intf->type = _phy_84328_intf_type_default(line_intf->speed, PHY84328_INTF_SIDE_SYS); _phy_84328_intf_print(unit, port, "default sys intf"); } else { SOC_IF_ERROR_RETURN(_phy_84328_intf_line_sys_params_get(unit, port)); _phy_84328_intf_print(unit, port, "after updating intf based on sys config"); } CFG_SYS_INTF(pc) = sys_intf->type; return SOC_E_NONE; } /* * TODO: how to handle configs for flex ports * Issues: * - how is the polarity specified if the port number changes * - what is the syntax to specify the lanes for 100G vs 40G vs 10G */ STATIC int _phy_84328_polarity_cfg_init(int unit, soc_port_t port) { phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); /* * The core aware property which specifies the core number must be * with multiple core ports * * Ex: * Assuming port 4 is a 100G port, then if every other lane has tx * polarity flipped: * config add phy_tx_polarity_flip_core0_port4=0x0f0f * config add phy_tx_polarity_flip_core1_port4=0x0f0f * config add phy_tx_polarity_flip_core2_port4=0x000f * * Polarity configuration: * 1: all lanes * nibble==0xF: each nibble specifies a lane - up to 4 lanes * * The polarity configuration is stored in the driver per core control block */ if (PHY84328_MULTI_CORE_MODE(pc)) { POL_TX_CFG(pc) = soc_property_port_suffix_num_get(unit, port, CORE_NUM(pc), spn_PHY_TX_POLARITY_FLIP, "core", 0); POL_RX_CFG(pc) = soc_property_port_suffix_num_get(unit, port, CORE_NUM(pc), spn_PHY_RX_POLARITY_FLIP, "core", 0); } else { POL_TX_CFG(pc) = soc_property_port_get(unit, port, spn_PHY_TX_POLARITY_FLIP, 0); POL_RX_CFG(pc) = soc_property_port_get(unit, port, spn_PHY_RX_POLARITY_FLIP, 0); } return SOC_E_NONE; } #endif /* 100G */ #ifdef BCM_WARM_BOOT_SUPPORT STATIC int _phy_84328_intf_speed_from_reg(uint16 mode, int *speed) { uint16 speed_reg = mode & (PHY84328_DEV1_GP_REGISTER_1_SPEED_1G_MASK | PHY84328_DEV1_GP_REGISTER_1_SPEED_10G_MASK | PHY84328_DEV1_GP_REGISTER_1_SPEED_40G_MASK | PHY84328_DEV1_GP_REGISTER_1_SPEED_100G_MASK); *speed = 0; switch (speed_reg) { case PHY84328_DEV1_GP_REGISTER_1_SPEED_100G: *speed = 100000; break; case PHY84328_DEV1_GP_REGISTER_1_SPEED_42G: *speed = 42000; break; case PHY84328_DEV1_GP_REGISTER_1_SPEED_40G: *speed = 40000; break; case PHY84328_DEV1_GP_REGISTER_1_SPEED_10G: *speed = 10000; break; case PHY84328_DEV1_GP_REGISTER_1_SPEED_10G | PHY84328_DEV1_GP_REGISTER_1_SPEED_1G: /********* 100, 10 not recoverable from PHY ********/ *speed = 1000; break; default: /* hardware has unexpected value */ return SOC_E_FAIL; } return SOC_E_NONE; } STATIC int _phy_84328_intf_type_from_reg(uint16 mode, phy84328_intf_side_t side, int speed, int an, soc_port_if_t *intf_type) { uint16 intf_reg = mode & ((side == PHY84328_INTF_SIDE_LINE) ? 0x5300 : 0xac00); if (side == PHY84328_INTF_SIDE_LINE) { switch (intf_reg) { case 0: switch (speed) { case 40000: case 42000: case 100000: *intf_type = SOC_PORT_IF_SR4; break; case 10000: *intf_type = SOC_PORT_IF_SR; break; case 1000: if (an) { *intf_type = SOC_PORT_IF_GMII; } else { *intf_type = SOC_PORT_IF_SGMII; } break; case 100: case 10: *intf_type = SOC_PORT_IF_SGMII; break; default: return SOC_E_FAIL; } break; case 0x4200: switch (speed) { case 100000: *intf_type = SOC_PORT_IF_CAUI; break; case 40000: case 42000: *intf_type = SOC_PORT_IF_XLAUI; break; case 10000: *intf_type = SOC_PORT_IF_SFI; break; default: return SOC_E_FAIL; } break; case 0x4000: switch (speed) { case 40000: case 42000: *intf_type = SOC_PORT_IF_LR4; break; case 10000: *intf_type = SOC_PORT_IF_LR; break; default: return SOC_E_FAIL; } break; case 0x200: switch (speed) { case 40000: case 42000: case 100000: *intf_type = SOC_PORT_IF_CR4; break; case 10000: *intf_type = SOC_PORT_IF_CR; break; default: return SOC_E_FAIL; } break; case 0x100: switch (speed) { case 40000: case 42000: *intf_type = SOC_PORT_IF_KR4; break; case 10000: *intf_type = SOC_PORT_IF_KR; break; case 1000: case 100: case 10: *intf_type = SOC_PORT_IF_KX; break; default: return SOC_E_FAIL; } break; case 0x1200: switch (speed) { case 40000: case 42000: case 100000: *intf_type = SOC_PORT_IF_CR4; break; case 10000: *intf_type = SOC_PORT_IF_CR; break; default: return SOC_E_FAIL; } break; case 0x5000: switch (speed) { case 10000: *intf_type = SOC_PORT_IF_ZR; break; default: return SOC_E_FAIL; } break; case 0x1000: default: return SOC_E_FAIL; break; } /* switch (intf_reg) */ } else { /* get sys intf type */ switch (intf_reg) { case 0: switch (speed) { case 40000: case 42000: *intf_type = SOC_PORT_IF_SR4; break; case 10000: *intf_type = SOC_PORT_IF_SR; break; case 1000: if (an) { *intf_type = SOC_PORT_IF_GMII; } else { *intf_type = SOC_PORT_IF_SGMII; } break; case 100: case 10: *intf_type = SOC_PORT_IF_SGMII; break; default: return SOC_E_FAIL; } break; case 0x8800: switch (speed) { case 100000: *intf_type = SOC_PORT_IF_CAUI; break; case 40000: case 42000: *intf_type = SOC_PORT_IF_XLAUI; break; case 10000: *intf_type = SOC_PORT_IF_XFI; break; default: return SOC_E_FAIL; } break; case 0x800: switch (speed) { case 40000: case 42000: case 100000: *intf_type = SOC_PORT_IF_CR4; break; case 10000: *intf_type = SOC_PORT_IF_CR; break; default: return SOC_E_FAIL; } break; case 0x400: switch (speed) { case 40000: case 42000: *intf_type = SOC_PORT_IF_KR4; break; case 10000: *intf_type = SOC_PORT_IF_KR; break; case 1000: case 100: case 10: *intf_type = SOC_PORT_IF_KX; break; default: return SOC_E_FAIL; } break; case 0x2800: switch (speed) { case 40000: case 42000: case 100000: *intf_type = SOC_PORT_IF_CR4; break; case 10000: *intf_type = SOC_PORT_IF_CR; break; default: return SOC_E_FAIL; } break; case 0xa000: case 0x2000: default: return SOC_E_FAIL; break; } /* switch (intf_reg) */ } return SOC_E_NONE; } STATIC int _phy_84328_reinit_line_intf(int unit, soc_port_t port, int speed, int an, uint16 mode) { phy_ctrl_t *pc; phy84328_intf_cfg_t *line_intf; pc = EXT_PHY_SW_STATE(unit, port); line_intf = &(LINE_INTF(pc)); line_intf->speed = speed; SOC_IF_ERROR_RETURN(_phy_84328_intf_type_from_reg(mode, PHY84328_INTF_SIDE_LINE, speed, an, &(line_intf->type))); if (AN_EN(pc) && line_intf->type == SOC_PORT_IF_CR4) { if (POL_RX_CFG(pc)) { FORCE_20BIT(pc) |= FORCE_20BIT_AN ; } } return SOC_E_NONE; } STATIC int _phy_84328_reinit_system_intf(int unit, soc_port_t port, int speed, int an, uint16 mode) { phy_ctrl_t *pc; phy84328_intf_cfg_t *system_intf; pc = EXT_PHY_SW_STATE(unit, port); system_intf = &(SYS_INTF(pc)); system_intf->speed = speed; SOC_IF_ERROR_RETURN(_phy_84328_intf_type_from_reg(mode, PHY84328_INTF_SIDE_SYS, speed, an, &(system_intf->type))); return SOC_E_NONE; } /* * For WarmBoot support: preserve SW RxLOS enable/disable status in register 1.0xC01A */ #define PHY84328_NO_PRESERVE_SW_RxLOS 0x100 #define PHY84328_DEV1_LANECTRL_RSV_SHIFT 12 STATIC int _phy_84328_preserve_sw_rx_los(int unit, soc_port_t port, int enable) { uint32 offset; uint16 sw_rx_los_enable; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); /* get the offset of this port/lane */ SOC_IF_ERROR_RETURN( phy_84328_control_port_get(unit, port, SOC_PHY_CONTROL_PORT_OFFSET, &offset) ); offset = 1U << (offset + PHY84328_DEV1_LANECTRL_RSV_SHIFT); sw_rx_los_enable = (enable) ? offset : 0 ; /* register 1.0xC01A , use the reserved bits [15:12] *\ \* to preserve SW RxLOS status for warmboot support */ return MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_LANECTRL, sw_rx_los_enable, (uint16) offset); } STATIC int _phy_84328_sw_rx_los_control_set(int unit, soc_port_t port, uint32 value); /* * During WarmBoot: retrieve SW RxLOS enable/disable status from register 1.0xC01A */ STATIC int _phy_84328_reinit_sw_rx_los(int unit, soc_port_t port) { uint32 offset; uint16 sw_rx_los_enable; phy84328_sw_rx_los_t *sw_rx_los; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); sw_rx_los = &(SW_RX_LOS(pc)); /* get the offset of this port/lane */ SOC_IF_ERROR_RETURN( phy_84328_control_port_get(unit, port, SOC_PHY_CONTROL_PORT_OFFSET, &offset) ); offset = 1U << (offset + PHY84328_DEV1_LANECTRL_RSV_SHIFT); /* register 1.0xC01A , use the reserved bits [15:12] *\ \* to preserve SW RxLOS status during warmboot */ SOC_IF_ERROR_RETURN( READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_LANECTRL, &sw_rx_los_enable) ); sw_rx_los->cfg_enable = (sw_rx_los_enable & offset) ? TRUE : FALSE; /* if SW RxLOS was enabled, hardcode the default RxLOS stable state */ if ( sw_rx_los->cfg_enable ) { sw_rx_los->cur_enable = 1; sw_rx_los->sys_link = 1; sw_rx_los->link_no_pcs = 0; sw_rx_los->link_status = 0; sw_rx_los->fault_report_dis = 0; sw_rx_los->link_no_pcs = 0; sw_rx_los->restarts = 1; sw_rx_los->state = PHY84328_SW_RX_LOS_IDLE; } return SOC_E_NONE; } STATIC int _phy_84328_reinit_fw_rx_los(int unit, soc_port_t port) { uint16 fw_rx_los, fw_rx_los_en_mask; phy_ctrl_t *pc; pc = EXT_PHY_SW_STATE(unit, port); fw_rx_los_en_mask = (1 << 15) | (1 << 14); SOC_IF_ERROR_RETURN( READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, 0xc480, &fw_rx_los)); FW_RX_LOS(pc) = (fw_rx_los & fw_rx_los_en_mask) == fw_rx_los_en_mask; return SOC_E_NONE; } STATIC int _phy_84328_reinit_cur_datapath(int unit, soc_port_t port, uint16 mode) { uint16 datapath_reg; phy_ctrl_t *pc; pc = EXT_PHY_SW_STATE(unit, port); datapath_reg = mode & PHY84328_DEV1_GP_REGISTER_1_DATAPATH_MASK; switch (datapath_reg) { case 0: CUR_DATAPATH(pc) = PHY84328_DATAPATH_20; break; case PHY84328_DEV1_GP_REGISTER_1_DATAPATH_4_DEPTH1: CUR_DATAPATH(pc) = PHY84328_DATAPATH_4_DEPTH1; break; case PHY84328_DEV1_GP_REGISTER_1_DATAPATH_4_DEPTH2: CUR_DATAPATH(pc) = PHY84328_DATAPATH_4_DEPTH2; break; default: return SOC_E_FAIL; } return SOC_E_NONE; } STATIC int _phy_84328_reinit_from_mode(int unit, soc_port_t port) { uint16 mode_reg; uint16 side_reg; uint16 an_reg; int speed; int an =0, an_done = 0; int int_phy_link = 0; phy_ctrl_t *pc, *int_pc; pc = EXT_PHY_SW_STATE(unit, port); int_pc = INT_PHY_SW_STATE(unit, port); /* * Make sure line side registers are selected * if not, have to bail out since the system is in a bad state */ SOC_IF_ERROR_RETURN( READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_XPMD_REGS_SEL, &side_reg)); if (side_reg != 0) { return SOC_E_UNAVAIL; } /* Read the current mode */ SOC_IF_ERROR_RETURN( READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_GP_REGISTER_1, &mode_reg)); /* Get speed */ SOC_IF_ERROR_RETURN(_phy_84328_intf_speed_from_reg(mode_reg, &speed)); /* Get an setting */ if (speed < 10000) { if (int_pc != NULL) { SOC_IF_ERROR_RETURN(PHY_AUTO_NEGOTIATE_GET(int_pc->pd, unit, port, &an, &an_done)); SOC_IF_ERROR_RETURN(PHY_SPEED_GET(int_pc->pd, unit, port, &speed)); } } else { SOC_IF_ERROR_RETURN(READ_PHY84328_MMF_AN_REG(unit, pc, PHY84328_DEV7_AN_CONTROL_REGISTER, &an_reg)); an = (an_reg & PHY84328_DEV7_AN_CONTROL_REGISTER_AUTO_NEGOTIATIONENABLE_MASK) == PHY84328_DEV7_AN_CONTROL_REGISTER_AUTO_NEGOTIATIONENABLE_MASK; } AN_EN(pc) = an; SOC_IF_ERROR_RETURN( _phy_84328_reinit_line_intf(unit, port, speed, an, mode_reg)); SOC_IF_ERROR_RETURN( _phy_84328_reinit_system_intf(unit, port, speed, an, mode_reg)); SOC_IF_ERROR_RETURN( _phy_84328_reinit_cur_datapath(unit, port, mode_reg)); /* * PCS from the internal PHY is used to determine link. */ if (int_pc != NULL) { SOC_IF_ERROR_RETURN(PHY_LINK_GET(int_pc->pd, unit, port, &int_phy_link)); CUR_LINK(pc) = int_phy_link; } else { CUR_LINK(pc) = 0; } return SOC_E_NONE; } STATIC int _phy_84328_reinit(int unit, soc_port_t port) { SOC_IF_ERROR_RETURN( _phy_84328_reinit_from_mode(unit,port)); /* Reinit Firmware RxLOS */ SOC_IF_ERROR_RETURN( _phy_84328_reinit_fw_rx_los(unit, port)); /* Reinit Software RxLOS */ SOC_IF_ERROR_RETURN( _phy_84328_reinit_sw_rx_los(unit, port) ); return SOC_E_NONE; } #endif /* BCM_WARM_BOOT_SUPPORT */ STATIC int _phy_84328_init_pass2(int unit, soc_port_t port) { phy_ctrl_t *pc; phy84328_intf_cfg_t *line_intf, *sys_intf; phy84328_counters_t *counters; phy84328_sw_rx_los_t *sw_rx_los; phy84328_link_mon_t *link_mon; phy84328_micro_ctrl_t *micro_ctrl; uint16 data, mask; uint16 chip_rev; int tx_gpio0 = 0; int link_mon_dflt, port_enable_delay_dflt; LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "PHY84328 init pass2: u=%d p=%d\n"), unit, port)); pc = EXT_PHY_SW_STATE(unit, port); /* * - interfaces are KR4/KR/KX/XAUI/XFI/SR/LR/CR/SR4/LR4/CR4 * - Gallardo is capable of being configured symmetrically and can support all * interfaces on both sides * - system side interfaces cannot be changed dynamically * - configured in Gallardo via config variables * - line side mode can be changed dynamically * - configured specifically with interface set and/or by matching speed * - automatically when module autodetect is enabled * * port mode system side line side * ---------------- ------------------------ -------------------------------- * 40G(singleport) dflt:XLAUI or configvar dflt:XLAUI or user set if/speed * 1G/10G(quadport) dflt:XFI or configvar dflt:SFI or user set if/speed */ line_intf = &(LINE_INTF(pc)); sys_intf = &(SYS_INTF(pc)); counters = &(COUNTERS(pc)); sw_rx_los = &(SW_RX_LOS(pc)); link_mon = &(LINK_MON(pc)); micro_ctrl = &(MICRO_CTRL(pc)); sal_memset(line_intf, 0, sizeof(phy84328_intf_cfg_t)); sal_memset(sys_intf, 0, sizeof(phy84328_intf_cfg_t)); sal_memset(counters, 0, sizeof(phy84328_counters_t)); sal_memset(sw_rx_los, 0, sizeof(phy84328_sw_rx_los_t)); sal_memset(link_mon, 0, sizeof(phy84328_link_mon_t)); LOGICAL_LANE0(pc) = 0; AN_EN(pc) = 0; FORCE_20BIT(pc) = 0; CUR_LINK(pc) = 0; SYNC_INIT(pc) = 1; INT_PHY_RE_EN(pc) = 0; DBG_FLAGS(pc) = 0; FW_RX_LOS(pc) = 0; BYPASS_SS_TUNING(pc) = soc_property_port_get(unit, port, "phy_84328_bypass_ss_tuning", 1); SYS_FORCED_CL72(pc) = soc_property_port_get(unit, port, spn_PORT_INIT_CL72, 0); micro_ctrl->enable = 1; micro_ctrl->count = 0; SOC_IF_ERROR_RETURN( READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_CHIP_REV_REGISTER, &chip_rev)); DEVREV(pc) = chip_rev; port_enable_delay_dflt = (DEVREV(pc) == 0x00a0) ? 60 : 0; PORT_ENABLE_DELAY(pc) = soc_property_port_get(unit, port, "phy_84328_port_enable_delay", port_enable_delay_dflt) * 1000; link_mon_dflt = (DEVREV(pc) == 0x00a0) ? 1 : 0; link_mon->cfg_enable = soc_property_port_get(unit, port, "phy_84328_link_monitor", link_mon_dflt); link_mon->cur_enable = link_mon->cfg_enable; pc->flags |= PHYCTRL_INIT_DONE; SOC_IF_ERROR_RETURN(_phy_84328_intf_default(unit, port)); /* Manually power channel down by default from driver - * it is upto the user to enable the port through CLI or API or * by using correct compilation flags to ensure that port is enabled * as part of initialization by upper layers. */ data = (1 << PHY84328_DEV1_OPTICAL_CONFIGURATION_MAN_TXON_EN_SHIFT) | (1 << PHY84328_DEV1_OPTICAL_CONFIGURATION_TXOFFT_SHIFT); mask = PHY84328_DEV1_OPTICAL_CONFIGURATION_MAN_TXON_EN_MASK | PHY84328_DEV1_OPTICAL_CONFIGURATION_TXOFFT_MASK; SOC_IF_ERROR_RETURN(MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_OPTICAL_CONFIGURATION, data, mask)); /* * Initialize main firmware control register * - First quiesce firmware and clear default settings * - Enable all channels as there are race conditions if not all channels are * enabled when changing to quad-channel mode * - If tx_gpio0 is set, firmware drives line side tx enable/disable based on * the system side cdr state */ data = PHY84328_DEV1_GP_REG_0_ENABLE_LINE_3_0_MASK | PHY84328_DEV1_GP_REG_0_ENABLE_SYSTEM_3_0_MASK; mask = PHY84328_DEV1_GP_REG_0_ENABLE_LINE_3_0_MASK | PHY84328_DEV1_GP_REG_0_ENABLE_SYSTEM_3_0_MASK; tx_gpio0 = soc_property_port_get(unit, port, "phy_84328_tx_gpio0", 0); if (tx_gpio0 == 1) { data |= PHY84328_DEV1_GP_REG_0_TX_GPIO; mask |= data; } /* Update the core info in bit 6 and 5 */ mask |= 0x3 << 5; if (CORE_NUM(pc)){ data |= ((CORE_NUM(pc) % 3) + 1) << 5 ; } SOC_IF_ERROR_RETURN(MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_GP_REG_0, data, mask)); /* Reset does not clear lane control2 */ SOC_IF_ERROR_RETURN (MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_LANECTRL2, 0, PHY84328_DEV1_LANECTRL2_RLOOP1G_MASK)); _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_SYS); SOC_IF_ERROR_RETURN (MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_LANECTRL2, 0, PHY84328_DEV1_LANECTRL2_RLOOP1G_MASK)); /* Make sure accessing line side registers and 1:1 logical channel mappings */ _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_LINE); SOC_IF_ERROR_RETURN( MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_LOGAD_CTRL, 0xe4, 0x00ff)); CFG_DATAPATH(pc) = _phy_84328_datapath_get(unit, port); CUR_DATAPATH(pc) = CFG_DATAPATH(pc); /* Polarity configuration is applied every time interface is configured */ SOC_IF_ERROR_RETURN(_phy_84328_polarity_cfg_init(unit, port)); /* Push configuration to the device */ SOC_IF_ERROR_RETURN(_phy_84328_config_update(unit, port)); #ifdef BCM_WARM_BOOT_SUPPORT if (SOC_WARM_BOOT(unit) || SOC_IS_RELOADING(unit)){ /* Do nothing */ } else #endif { /* Initialize system and line side interfaces */ SOC_IF_ERROR_RETURN(_phy_84328_intf_line_sys_init(unit, port)); } if (PHYCTRL_INIT_STATE(pc) == PHYCTRL_INIT_STATE_PASS2) { /* indicate third pass of init is needed */ PHYCTRL_INIT_STATE_SET(pc,PHYCTRL_INIT_STATE_PASS3); } return SOC_E_NONE; } STATIC int _phy_84328_init_pass3(int unit, soc_port_t port) { int rv; phy_ctrl_t *pc, *int_pc; int regulator_en = 0; LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "PHY84328 init pass3: u=%d p=%d\n"), unit, port)); pc = EXT_PHY_SW_STATE(unit, port); int_pc = INT_PHY_SW_STATE(unit, port); /* Complete what we started from PASS2 in PASS3 */ if (INT_PHY_RE_EN(pc)) { /* wait for timer to expire */ while (!soc_timeout_check(&SYNC_TO(pc))) { sal_usleep(100); } /* Turn internal PHY back on now that the mode has been configured */ SOC_IF_ERROR_RETURN(PHY_ENABLE_SET(int_pc->pd, unit, port, 1)); INT_PHY_RE_EN(pc) = 0; } LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "PHY84328 init pass3 polarity verified: u=%d p=%d\n"), unit, port)); regulator_en = soc_property_port_get(unit, port, spn_PHY_AUX_VOLTAGE_ENABLE, 0); if (regulator_en) { /* Clear 1.c850[13] to enable */ SOC_IF_ERROR_RETURN (MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_REGUALTOR_CTRL, 0, PHY84328_DEV1_REGUALTOR_CTRL_PWRDN_MASK)); } /* Logical lane0 used for auto-negotiation in 40G CR4 */ if (PHY84328_SINGLE_PORT_MODE(pc)) { uint16 logical_lane0; logical_lane0 = soc_property_port_get(unit, port, spn_PHY_LANE0_L2P_MAP, 0); if (logical_lane0 > PHY84328_NUM_LANES) { LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "PHY84328 bad auto-negotiation lane %d: u=%d p=%d" " lane must be 0..3\n"), (int)logical_lane0, unit, port)); } else { SOC_IF_ERROR_RETURN( MODIFY_PHY84328_MMF_PMA_PMD_REG( unit, pc, PHY84328_DEV1_SINGLE_PMD_CTRL, logical_lane0 << PHY84328_DEV1_SINGLE_PMD_CTRL_PHY_CH_TO_ACCESS_IN_SINGLE_PMD_SHIFT, PHY84328_DEV1_SINGLE_PMD_CTRL_PHY_CH_TO_ACCESS_IN_SINGLE_PMD_MASK)); LOGICAL_LANE0(pc) = logical_lane0; } } /* If configured, enable module auto detection */ MOD_AUTO_DETECT(pc) = soc_property_port_get(unit, port, spn_PHY_MOD_AUTO_DETECT, 0); if (MOD_AUTO_DETECT(pc)) { uint16 data, mask; LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "PHY84328 module auto detect enabled: u=%d p=%d\n"), unit, port)); /* SFP MOD_DETECT enables both SFP and QSFP module detect */ data = PHY84328_DEV1_GP_REG_0_ENABLE_SFP_MOD_DETECT_MASK; mask = PHY84328_DEV1_GP_REG_0_ENABLE_SFP_MOD_DETECT_MASK; rv = MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_GP_REG_0, data, mask); if (SOC_FAILURE(rv)) { MOD_AUTO_DETECT(pc) = 0; LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "PHY84328 setting module auto detect failed: u=%d p%d\n"), unit, port)); } } if (soc_property_port_get(unit, port, "phy_84328_port_4_5_control", 0)) { rv = MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_GP_REG_0, PHY84328_DEV1_GP_REG_0_P4_5_CTRL, PHY84328_DEV1_GP_REG_0_P4_5_CTRL); if (SOC_FAILURE(rv)) { LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "PHY84328 setting p4_5 control failed: u=%d p%d\n"), unit, port)); } } #ifdef BCM_WARM_BOOT_SUPPORT if (SOC_WARM_BOOT(unit) || SOC_IS_RELOADING(unit)){ return _phy_84328_reinit(unit, port); } #endif /* Cold boot code only below this */ return SOC_E_NONE; } /* * Check if the core has been initialized. This is done by * looking at all ports which belong to the same core and see * if any one of them have completed initialization. * The primary port is used to determine whether the port is * on the same core as all ports in a core share the primary port. */ STATIC int _phy_84328_core_init_done(int unit, struct phy_driver_s *pd, int primary_port) { int rv; soc_port_t port; phy_ctrl_t *pc; uint32 core_primary_port; PBMP_ALL_ITER(unit, port) { pc = EXT_PHY_SW_STATE(unit, port); if (pc == NULL) { continue; } /* Make sure this port has a 84328 driver */ if (pc->pd != pd) { continue; } rv = phy_84328_control_port_get(unit, port, SOC_PHY_CONTROL_PORT_PRIMARY, &core_primary_port); if (rv != SOC_E_NONE) { continue; } if ((primary_port == core_primary_port) && (pc->flags & PHYCTRL_INIT_DONE)) { return TRUE; } } return FALSE; } STATIC int _phy_84328_init_pass1(int unit, soc_port_t port) { phy_ctrl_t *pc; int offset; soc_port_t primary_port; pc = EXT_PHY_SW_STATE(unit, port); LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "PHY84328 init pass1: u=%d p=%d\n"), unit, port)); /* Set the primary port & offset */ if (soc_phy_primary_and_offset_get(unit, port, &primary_port, &offset) != SOC_E_NONE) { /* * Derive primary and offset * There is an assumption lane 0 on first core on the the MDIO * bus is a primary port */ if (PHY84328_SINGLE_PORT_MODE(pc)) { primary_port = port; offset = 0; } else { primary_port = port - (pc->phy_id & 0x3); offset = pc->phy_id & 0x3; } } /* set the default values that are valid for many boards */ SOC_IF_ERROR_RETURN(phy_84328_control_port_set(unit, port, SOC_PHY_CONTROL_PORT_PRIMARY, primary_port)); SOC_IF_ERROR_RETURN(phy_84328_control_port_set(unit, port,SOC_PHY_CONTROL_PORT_OFFSET, offset)); /* * Since there is a single micro and therefore a single copy of the firmware * shared among the 4 channels in a core, do not download firmware if in quad * channel and the other channels are active. */ if (PHY84328_SINGLE_PORT_MODE(pc) || (!PHY84328_SINGLE_PORT_MODE(pc) && (!_phy_84328_core_init_done(unit, pc->pd, primary_port)))) { uint16 csr_c848 = 0; /* read Ch. 0 1.C848, bit [13] is download done */ SOC_IF_ERROR_RETURN( READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_SPA_CONTROL_STATUS_REGISTER, &csr_c848)); if ((csr_c848 & (1 << 13)) && !(soc_property_port_get(unit, port, spn_PHY_FORCE_FIRMWARE_LOAD, TRUE))) { uint8 *fw_ptr = NULL; int fw_length = 0; uint16 chip_micro_ver = 0, file_micro_ver = 0; SOC_IF_ERROR_RETURN( READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_VERSION, &chip_micro_ver)); if (pc->dev_name == dev_name_84328_a0) { fw_ptr = phy84328_ucode_bin; fw_length = phy84328_ucode_bin_len; } else if (pc->dev_name == dev_name_84328) { fw_ptr = phy84328B0_ucode_bin; fw_length = phy84328B0_ucode_bin_len; } else if (pc->dev_name == dev_name_84088) { fw_ptr = phy84328B0_ucode_bin; fw_length = phy84328B0_ucode_bin_len; } else { /* for other device donot take micro version*/ pc->flags &= (~PHYCTRL_MDIO_BCST); if (PHYCTRL_INIT_STATE(pc) == PHYCTRL_INIT_STATE_PASS1) { /* indicate second pass of init is needed */ PHYCTRL_INIT_STATE_SET(pc,PHYCTRL_INIT_STATE_PASS2); } return SOC_E_NONE; } /* MICRO version is reterived from 4th and 3rd last byte of micro file*/ file_micro_ver = (fw_ptr[fw_length-4] << 8) | (fw_ptr[fw_length-3]); if (file_micro_ver != chip_micro_ver) { pc->flags |= PHYCTRL_MDIO_BCST; } else { pc->flags &= (~PHYCTRL_MDIO_BCST); } /* LOG_CLI((BSL_META_U(unit, "84328 u=%d p=%d skip fw download\n"), unit, port)); */ } else { pc->flags |= PHYCTRL_MDIO_BCST; } } LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "phy_84328_init: u=%d p=%d setting primary=%d offset=%d\n"), unit, port, primary_port, offset)); if (PHYCTRL_INIT_STATE(pc) == PHYCTRL_INIT_STATE_PASS1) { /* indicate second pass of init is needed */ PHYCTRL_INIT_STATE_SET(pc,PHYCTRL_INIT_STATE_PASS2); } return SOC_E_NONE; } /* Function: * phy_84328_init * Purpose: * Initialize 84328 phys * Parameters: * unit - StrataSwitch unit #. * port - StrataSwitch port #. * Returns: * SOC_E_NONE */ STATIC int _phy_84328_init(int unit, soc_port_t port) { int ix; uint16 data; uint32 devid; phy_ctrl_t *pc; pc = EXT_PHY_SW_STATE(unit, port); LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "PHY84328 init: u=%d p=%d state=%d\n"), unit, port,PHYCTRL_INIT_STATE(pc))); _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_LINE); if ((PHYCTRL_INIT_STATE(pc) == PHYCTRL_INIT_STATE_PASS1) || (PHYCTRL_INIT_STATE(pc) == PHYCTRL_INIT_STATE_DEFAULT)) { /* Read the chip id to identify the device */ SOC_IF_ERROR_RETURN(_phy_84328_config_devid(unit, port, pc, &devid)); /* Save it in the device description structure for future use */ DEVID(pc) = devid; /* initialize default p2l map */ for (ix = 0; ix < PHY84328_NUM_LANES; ix++) { P2L_MAP(pc,ix) = ix; } PHY_FLAGS_SET(unit, port, PHY_FLAGS_FIBER | PHY_FLAGS_C45 | PHY_FLAGS_REPEATER); data = (PHY84328_SINGLE_PORT_MODE(pc)) ? PHY84328_DEV1_SINGLE_PMD_CTRL_SINGLE_PMD_MODE_MASK : 0; SOC_IF_ERROR_RETURN (MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_SINGLE_PMD_CTRL, data, PHY84328_DEV1_SINGLE_PMD_CTRL_SINGLE_PMD_MODE_MASK)); SOC_IF_ERROR_RETURN(_phy_84328_init_pass1(unit, port)); if (PHYCTRL_INIT_STATE(pc) != PHYCTRL_INIT_STATE_DEFAULT) { return SOC_E_NONE; } } if ((PHYCTRL_INIT_STATE(pc) == PHYCTRL_INIT_STATE_PASS2) || (PHYCTRL_INIT_STATE(pc) == PHYCTRL_INIT_STATE_DEFAULT)) { SOC_IF_ERROR_RETURN( _phy_84328_init_pass2(unit, port)); LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "PHY84328 init pass2 completed: u=%d p=%d\n"), unit, port)); if (PHYCTRL_INIT_STATE(pc) != PHYCTRL_INIT_STATE_DEFAULT) { return SOC_E_NONE; } } if ((PHYCTRL_INIT_STATE(pc) == PHYCTRL_INIT_STATE_PASS3) || (PHYCTRL_INIT_STATE(pc) == PHYCTRL_INIT_STATE_DEFAULT)) { SOC_IF_ERROR_RETURN( _phy_84328_init_pass3(unit, port)); LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "PHY84328 init pass3 completed: u=%d p=%d\n"), unit, port)); PHYCTRL_INIT_STATE_SET(pc,PHYCTRL_INIT_STATE_DEFAULT); return SOC_E_NONE; } return SOC_E_NONE; } STATIC int _phy_84328_dev_an_get(int unit, soc_port_t port, int *an, int *an_done) { uint16 data; uint16 dev_an_done_mask; phy_ctrl_t *pc; pc = EXT_PHY_SW_STATE(unit, port); *an = 0; *an_done = 0; /* * 7.0000[12] an enabled * 1.0097[0] an/training complete. For 40G, per lane status in bits 12,8,4,0 */ SOC_IF_ERROR_RETURN(READ_PHY84328_MMF_AN_REG(unit, pc, PHY84328_DEV7_AN_CONTROL_REGISTER, &data)); *an = (data & PHY84328_DEV7_AN_CONTROL_REGISTER_AUTO_NEGOTIATIONENABLE_MASK) == PHY84328_DEV7_AN_CONTROL_REGISTER_AUTO_NEGOTIATIONENABLE_MASK; if (*an) { SOC_IF_ERROR_RETURN( READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_BASE_R_PMD_STATUS_REGISTER, &data)); dev_an_done_mask = PHY84328_SINGLE_PORT_MODE(pc) ? 0x1111 : 0x0001; *an_done = (data & dev_an_done_mask) == dev_an_done_mask; } return SOC_E_NONE; } /* * Function: * phy_84328_an_get * Purpose: * Get the current auto-negotiation status (enabled/busy) * Parameters: * unit - StrataSwitch unit #. * port - StrataSwitch port #. * an - (OUT) if true, auto-negotiation is enabled. * an_done - (OUT) if true, auto-negotiation is complete. This * value is undefined if an == false. * Returns: * SOC_E_XXX */ STATIC int phy_84328_an_get(int unit, soc_port_t port, int *an, int *an_done) { phy_ctrl_t *pc, *int_pc; phy84328_intf_cfg_t *line_intf; pc = EXT_PHY_SW_STATE(unit, port); int_pc = INT_PHY_SW_STATE(unit, port); line_intf = &(LINE_INTF(pc)); if ((line_intf->type == SOC_PORT_IF_GMII) || (line_intf->type == SOC_PORT_IF_SGMII)) { SOC_IF_ERROR_RETURN(PHY_AUTO_NEGOTIATE_GET(int_pc->pd, unit, port, an, an_done)); } else { switch (line_intf->type) { case SOC_PORT_IF_KX: case SOC_PORT_IF_KR: case SOC_PORT_IF_KR4: case SOC_PORT_IF_CR4: SOC_IF_ERROR_RETURN(_phy_84328_dev_an_get(unit, port, an, an_done)); break; default: *an = 0; *an_done = 0; break; } } LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "phy_84328_an_get: u=%d p=%d an=%d\n"), unit, port, *an)); return SOC_E_NONE; } /* * Function: * phy_84328_an_set * Purpose: * Enable or disabled auto-negotiation on the specified port. * Parameters: * unit - StrataSwitch unit #. * port - StrataSwitch port #. * an - Boolean, if true, auto-negotiation is enabled * (and/or restarted). If false, autonegotiation is disabled. * Returns: * SOC_E_XXX */ STATIC int _phy_84328_an_set(int unit, soc_port_t port, int an) { int dev_an, dev_an_done; phy_ctrl_t *pc, *int_pc; phy84328_intf_cfg_t *line_intf; pc = EXT_PHY_SW_STATE(unit, port); int_pc = INT_PHY_SW_STATE(unit, port); line_intf = &(LINE_INTF(pc)); LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "phy_84328_an_set: u=%d p=%d an=%s\n"), unit, port, an ? "enable" : "disable")); /* * Determining line side AN status * SR/LR/SR4/LR4/CR/CR2/SR2: no AN * KR/KR4/KR2: line side: cl73/cl72, system side as forced cl72 * CR4: if AN disabled, set interface to 40G CR4 DAC(aka XLAUI_DFE), otherwise, CR4 * GMII: AN handled by internal SerDes */ switch (line_intf->type) { case SOC_PORT_IF_GMII: case SOC_PORT_IF_SGMII: AN_EN(pc) = an; SOC_IF_ERROR_RETURN(PHY_AUTO_NEGOTIATE_SET(int_pc->pd, unit, port, an)); break; case SOC_PORT_IF_KX: case SOC_PORT_IF_KR: case SOC_PORT_IF_KR4: AN_EN(pc) = 1; break; case SOC_PORT_IF_CR4: AN_EN(pc) = an; break; default: /* Interface does not support AN in the firmware so it's always forced */ AN_EN(pc) = FALSE; } SOC_IF_ERROR_RETURN(_phy_84328_intf_type_set(unit, port, line_intf->type, TRUE)); /* If not passtrhu an, make sure firmware has enabled an */ if (line_intf->speed > 1000) { _phy_84328_dev_an_get(unit, port, &dev_an, &dev_an_done); if (dev_an != AN_EN(pc)) { /* LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 device autonegotiation mismatch: u=%d p=%d an=%s\n"), unit, port, AN_EN(pc) ? "en" : "dis")); */ } } return SOC_E_NONE; } /* * Function: * _phy_84328_ability_advert_get * Purpose: * Get the current advertisement for auto-negotiation. * Parameters: * unit - StrataSwitch unit #. * port - StrataSwitch port #. * mode - (OUT) Port mode mask indicating supported options/speeds. * Returns: * SOC_E_XXX * Notes: * The advertisement is retrieved for the ACTIVE medium. * No synchronization performed at this level. */ STATIC int _phy_84328_ability_advert_get(int unit, soc_port_t port, soc_port_ability_t *ability) { phy_ctrl_t *pc, *int_pc; uint16 pause_adv; soc_port_mode_t mode = 0; phy84328_intf_cfg_t *line_intf; if (ability == NULL) { return SOC_E_PARAM; } sal_memset(ability, 0, sizeof(soc_port_ability_t)); pc = EXT_PHY_SW_STATE(unit, port); line_intf = &(LINE_INTF(pc)); if (_phy_84328_intf_line_forced(unit, port, line_intf->type)) { return SOC_E_NONE; } if ((line_intf->type == SOC_PORT_IF_KX) || (line_intf->type == SOC_PORT_IF_GMII)) { int_pc = INT_PHY_SW_STATE(unit, port); if (int_pc) { SOC_IF_ERROR_RETURN(PHY_ABILITY_ADVERT_GET(int_pc->pd, unit, port, ability)); } return SOC_E_NONE; } if(PHY84328_SINGLE_PORT_MODE(pc)) { ability->speed_full_duplex = SOC_PA_SPEED_40GB; } else { ability->speed_full_duplex = SOC_PA_SPEED_10GB; } SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_AN_REG(unit, pc, PHY84328_DEV7_AN_ADVERTISEMENT_1_REGISTER, &pause_adv)); mode = 0; switch (pause_adv & (CL73_AN_ADV_PAUSE | CL73_AN_ADV_ASYM_PAUSE)) { case CL73_AN_ADV_PAUSE: mode = SOC_PA_PAUSE_TX | SOC_PA_PAUSE_RX; break; case CL73_AN_ADV_ASYM_PAUSE: mode = SOC_PA_PAUSE_TX; break; case CL73_AN_ADV_PAUSE | CL73_AN_ADV_ASYM_PAUSE: mode = SOC_PA_PAUSE_RX; break; default: mode = 0; break; } ability->pause = mode; LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "phy_84328_ability_advert_get: u=%d p=%d speed(FD)=0x%x pause=0x%x\n"), unit, port, ability->speed_full_duplex, ability->pause)); return SOC_E_NONE; } /* * Function: * _phy_84328_ability_remote_get * Purpose: * Get the device's complete abilities. * Parameters: * unit - StrataSwitch unit #. * port - StrataSwitch port #. * ability - return device's abilities. * Returns: * SOC_E_XXX */ STATIC int _phy_84328_ability_remote_get(int unit, soc_port_t port, soc_port_ability_t *ability) { int an, an_done; uint16 pause_adv; soc_port_mode_t mode; phy_ctrl_t *pc, *int_pc; phy84328_intf_cfg_t *line_intf; if (ability == NULL) { return SOC_E_PARAM; } /* Only firmware has visibility into remote ability */ sal_memset(ability, 0, sizeof(soc_port_ability_t)); pc = EXT_PHY_SW_STATE(unit, port); line_intf = &(LINE_INTF(pc)); if (_phy_84328_intf_line_forced(unit, port, line_intf->type)) { return SOC_E_NONE; } if ((line_intf->type == SOC_PORT_IF_KX) || (line_intf->type == SOC_PORT_IF_GMII)) { int_pc = INT_PHY_SW_STATE(unit, port); if (int_pc) { SOC_IF_ERROR_RETURN(PHY_ABILITY_REMOTE_GET(int_pc->pd, unit, port, ability)); } return SOC_E_NONE; } ability->speed_half_duplex = SOC_PA_ABILITY_NONE; mode = 0; /* Return what the firmware is setting */ /* If an done, then return the speed for the port */ SOC_IF_ERROR_RETURN(phy_84328_an_get(unit, port, &an, &an_done)); if (an && an_done) { if(PHY84328_SINGLE_PORT_MODE(pc)) { ability->speed_full_duplex = SOC_PA_SPEED_40GB; } else { ability->speed_full_duplex = SOC_PA_SPEED_10GB; } mode = 0; SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_AN_REG(unit, pc, PHY84328_DEV7_AN_LP_BASE_PAGE_ABILITY_1_REG, &pause_adv)); switch (pause_adv & (CL73_AN_ADV_PAUSE | CL73_AN_ADV_ASYM_PAUSE)) { case CL73_AN_ADV_PAUSE: mode = SOC_PA_PAUSE_TX | SOC_PA_PAUSE_RX; break; case CL73_AN_ADV_ASYM_PAUSE: mode = SOC_PA_PAUSE_TX; break; case CL73_AN_ADV_PAUSE | CL73_AN_ADV_ASYM_PAUSE: mode = SOC_PA_PAUSE_RX; break; } ability->pause = mode; } LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "phy_84328_ability_remote_get: u=%d p=%d speed(FD)=0x%x pause=0x%x\n"), unit, port, ability->speed_full_duplex, ability->pause)); return SOC_E_NONE; } /* * Function: * _phy_84328_ability_advert_set * Purpose: * Set the current advertisement for auto-negotiation. * Parameters: * unit - StrataSwitch unit #. * port - StrataSwitch port #. * mode - Port mode mask indicating supported options/speeds. * Returns: * SOC_E_XXX * Notes: * The advertisement is set only for the ACTIVE medium. * No synchronization performed at this level. */ STATIC int _phy_84328_ability_advert_set(int unit, soc_port_t port, soc_port_ability_t *ability) { uint16 pause; phy_ctrl_t *pc, *int_pc; phy84328_intf_cfg_t *line_intf; if (ability == NULL) { return SOC_E_PARAM; } pc = EXT_PHY_SW_STATE(unit, port); line_intf = &(LINE_INTF(pc)); if ((line_intf->type == SOC_PORT_IF_KX) || (line_intf->type == SOC_PORT_IF_GMII)) { int_pc = INT_PHY_SW_STATE(unit, port); if (int_pc) { SOC_IF_ERROR_RETURN(PHY_ABILITY_ADVERT_SET(int_pc->pd, unit, port, ability)); } return SOC_E_NONE; } /* * Advertisement mostly handled by firmware depending on the mode * However, the firmware will honor the pause advertisement set by the driver */ switch (ability->pause & (SOC_PA_PAUSE_TX | SOC_PA_PAUSE_RX)) { case SOC_PA_PAUSE_TX: pause = CL73_AN_ADV_ASYM_PAUSE; break; case SOC_PA_PAUSE_RX: pause = CL73_AN_ADV_PAUSE | CL73_AN_ADV_ASYM_PAUSE; break; case SOC_PA_PAUSE_TX | SOC_PA_PAUSE_RX: pause = CL73_AN_ADV_PAUSE; break; default: pause = 0; break; } SOC_IF_ERROR_RETURN (MODIFY_PHY84328_MMF_AN_REG(unit, pc, PHY84328_DEV7_AN_ADVERTISEMENT_1_REGISTER, pause, (CL73_AN_ADV_PAUSE | CL73_AN_ADV_ASYM_PAUSE))); LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "phy_84328_ability_advert_set: u=%d p=%d speed(FD)=%x pause=0x%x\n"), unit, port, ability->speed_full_duplex, ability->pause)); return SOC_E_NONE; } /* * Function: * phy_84328_ability_local_get * Purpose: * Get the device's complete abilities. * Parameters: * unit - StrataSwitch unit #. * port - StrataSwitch port #. * ability - return device's abilities. * Returns: * SOC_E_XXX */ STATIC int phy_84328_ability_local_get(int unit, soc_port_t port, soc_port_ability_t *ability) { uint32 pa_speed = 0; phy_ctrl_t *pc; pc = EXT_PHY_SW_STATE(unit, port); if (ability == NULL) { return SOC_E_PARAM; } sal_memset(ability, 0, sizeof(soc_port_ability_t)); if (PHY84328_MULTI_CORE_MODE(pc)) { pa_speed = SOC_PA_SPEED_100GB; } else { pa_speed = PHY84328_SINGLE_PORT_MODE(pc) ? (SOC_PA_SPEED_40GB | SOC_PA_SPEED_42GB) : (SOC_PA_SPEED_10GB | SOC_PA_SPEED_1000MB | SOC_PA_SPEED_100MB | SOC_PA_SPEED_10MB); } ability->speed_full_duplex = pa_speed; ability->speed_half_duplex = SOC_PA_ABILITY_NONE; ability->pause = SOC_PA_PAUSE | SOC_PA_PAUSE_ASYMM; ability->interface = SOC_PA_INTF_XGMII; ability->medium = SOC_PA_MEDIUM_FIBER; ability->loopback = SOC_PA_LB_PHY; ability->flags = SOC_PA_AUTONEG; LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "phy_84328_ability_local_get: u=%d p=%d speed=0x%x\n"), unit, port, ability->speed_full_duplex)); return SOC_E_NONE; } STATIC int _phy_84328_mod_auto_detect_speed_check(int unit, soc_port_t port, uint16 csr) { uint16 csr_speed; phy_ctrl_t *pc; phy84328_intf_cfg_t *line_intf; static int speed_tbl[] = { 0, 1000, 10000, 1000, 40000, 0, 0 ,0, 10000 }; pc = EXT_PHY_SW_STATE(unit, port); line_intf = &(LINE_INTF(pc)); csr_speed = csr & (PHY84328_DEV1_GP_REGISTER_1_SPEED_100G_MASK | PHY84328_DEV1_GP_REGISTER_1_SPEED_40G_MASK | PHY84328_DEV1_GP_REGISTER_1_SPEED_10G_MASK | PHY84328_DEV1_GP_REGISTER_1_SPEED_1G_MASK); if (line_intf->speed != speed_tbl[csr_speed]) { LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 module auto detection unexpected: u=%d p=%d csr=0x%x " "csr table speed=%d line speed=%d\n"), unit, port, csr, speed_tbl[csr_speed], line_intf->speed)); } return (line_intf->speed == speed_tbl[csr_speed]); } STATIC int _phy_84328_mod_auto_detect_intf_process(int unit, soc_port_t port, uint16 csr) { int copper_mod = 0; int lr_mod = 0; phy_ctrl_t *pc; phy84328_intf_cfg_t *line_intf; int intf_update = 1; pc = EXT_PHY_SW_STATE(unit, port); line_intf = &(LINE_INTF(pc)); copper_mod = (csr & PHY84328_DEV1_GP_REGISTER_1_LINE_CU_TYPE_MASK) == PHY84328_DEV1_GP_REGISTER_1_LINE_CU_TYPE_MASK; lr_mod = (csr & PHY84328_DEV1_GP_REGISTER_1_LINE_LR_MODE_MASK) == PHY84328_DEV1_GP_REGISTER_1_LINE_LR_MODE_MASK; /* Change interface if going from optical to copper */ if (copper_mod) { switch (line_intf->type) { case SOC_PORT_IF_SR: case SOC_PORT_IF_SFI: case SOC_PORT_IF_XFI: line_intf->type = SOC_PORT_IF_CR; break; case SOC_PORT_IF_SR4: case SOC_PORT_IF_XLAUI: line_intf->type = SOC_PORT_IF_CR4; break; default: /* No interface change if not currently an optical interface */ intf_update = 0; break; } } else { /* Change interface if going from optical SR to LR */ if (lr_mod) { switch (line_intf->type) { case SOC_PORT_IF_SR: case SOC_PORT_IF_SFI: case SOC_PORT_IF_XFI: line_intf->type = SOC_PORT_IF_LR; break; case SOC_PORT_IF_SR4: case SOC_PORT_IF_XLAUI: line_intf->type = SOC_PORT_IF_LR4; break; default: /* No interface change */ intf_update = 0; break; } } /* Change interface if going from copper to optical */ switch (line_intf->type) { case SOC_PORT_IF_CR: line_intf->type = lr_mod ? SOC_PORT_IF_LR : SOC_PORT_IF_SR; break; case SOC_PORT_IF_CR4: line_intf->type = lr_mod ? SOC_PORT_IF_LR4 : SOC_PORT_IF_SR4; break; default: intf_update = 0; break; } } if (intf_update) { SOC_IF_ERROR_RETURN(_phy_84328_intf_line_sys_update(unit, port)); } return SOC_E_NONE; } STATIC int _phy_84328_mod_auto_detect_process(int unit, soc_port_t port, uint16 csr) { LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "PHY84328 module detected: u=%d p=%d csr=%x\n"), unit, port, csr)); /* * Speed cannot change with module detection so it must match the * currently configured speed */ if (!_phy_84328_mod_auto_detect_speed_check(unit, port, csr)) { return SOC_E_FAIL; } /* * Get the line side interface based on the current interface and the * detected module */ SOC_IF_ERROR_RETURN(_phy_84328_mod_auto_detect_intf_process(unit, port, csr)); return SOC_E_NONE; } STATIC int _phy_84328_mod_auto_detect_update(int unit, soc_port_t port) { phy_ctrl_t *pc; uint16 ucode_csr; uint16 drv_csr; pc = EXT_PHY_SW_STATE(unit, port); /* * New module insertion when 1.c843[4] == 1 and 1.c841[4] == 0 */ SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_GP_REGISTER_3, &ucode_csr)); if (ucode_csr & PHY84328_CSR_REG_MODULE_AUTO_DETECT) { SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_GP_REGISTER_1, &drv_csr)); if (!(drv_csr & PHY84328_CSR_REG_MODULE_AUTO_DETECT)) { SOC_IF_ERROR_RETURN(_phy_84328_mod_auto_detect_process(unit, port, ucode_csr)); /* * Ack firmware that the module insertion has been updated * 1.c841[4] = 1, 1.c841[7] = 0 */ SOC_IF_ERROR_RETURN (MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_GP_REGISTER_1, PHY84328_CSR_REG_MODULE_AUTO_DETECT, PHY84328_CSR_REG_MODULE_AUTO_DETECT | PHY84328_DEV1_GP_REGISTER_1_FINISH_CHANGE_MASK)); } } else { /* * New module removal when 1.c843[4] == 0 and 1.c841[4] == 1 */ SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_GP_REGISTER_1, &drv_csr)); if (drv_csr & PHY84328_CSR_REG_MODULE_AUTO_DETECT) { /* * Ack firmware new module removal 1.c841[4] = 0 */ SOC_IF_ERROR_RETURN (MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_GP_REGISTER_1, 0, PHY84328_CSR_REG_MODULE_AUTO_DETECT)); LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "PHY84328 module removed u=%d p=%d\n"), unit, port)); } } return SOC_E_NONE; } STATIC int _phy_84328_do_rxseq_restart(int unit, soc_port_t port,phy84328_intf_side_t side) { uint16 data; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); PHY_84328_MICRO_PAUSE(unit, port, "rxseq restart1"); if (side == PHY84328_INTF_SIDE_SYS) { _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_SYS); } SOC_IF_ERROR_RETURN (MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_DSC_MISC_CTRL0, PHY84328_DEV1_DSC_MISC_CTRL0_RXSEQSTART_MASK, PHY84328_DEV1_DSC_MISC_CTRL0_RXSEQSTART_MASK)); if (side == PHY84328_INTF_SIDE_SYS) { _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_LINE); } PHY_84328_MICRO_RESUME(unit, port); sal_udelay(800); PHY_84328_MICRO_PAUSE(unit, port, "rxseq restart 2"); if (side == PHY84328_INTF_SIDE_SYS) { _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_SYS); } SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_DSC_MISC_CTRL0, &data)); if (data & PHY84328_DEV1_DSC_MISC_CTRL0_RXSEQSTART_MASK) { /* * Usually 1.c21e[15] rx seq start is cleared by the microcode but there are cases when * them micro won't clear it. */ SOC_IF_ERROR_RETURN (MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_DSC_MISC_CTRL0, 0, PHY84328_DEV1_DSC_MISC_CTRL0_RXSEQSTART_MASK)); } if (side == PHY84328_INTF_SIDE_SYS) { _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_LINE); } PHY_84328_MICRO_RESUME(unit, port); return SOC_E_NONE; } /* * Restart rx sequencer * no_cdr_lanes == 0: all lanes have cdr - rxseq being restarted because pcs not up * != 0: bitmap of lanes which do not have cdr so restart only those lanes */ STATIC int _phy_84328_rxseq_restart(int unit, soc_port_t port, int no_cdr_lanes) { int lane; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); phy84328_counters_t *counters = &(COUNTERS(pc)); if (PHY84328_SINGLE_PORT_MODE(pc)) { if (no_cdr_lanes) { for (lane=0; lane < 4; lane++) { if (no_cdr_lanes & (1<<lane)) { counters->no_cdr++; /* Select the lane on the line side */ SOC_IF_ERROR_RETURN(_phy_84328_channel_select(unit, port, PHY84328_INTF_SIDE_LINE, lane)); _phy_84328_do_rxseq_restart(unit, port, PHY84328_INTF_SIDE_LINE); } } SOC_IF_ERROR_RETURN(_phy_84328_channel_select(unit, port, PHY84328_INTF_SIDE_LINE, PHY84328_ALL_LANES)); } } if (!no_cdr_lanes) { SOC_IF_ERROR_RETURN(_phy_84328_do_rxseq_restart(unit, port, PHY84328_INTF_SIDE_LINE)); } return SOC_E_NONE; } /* * Gets rx seq done status * Returns rx_seq_done status and a lane bitmask for lanes which have sigdet but no rx seq done/cdr locked */ STATIC int _phy_84328_rx_seq_done_cdr_lanes_get(int unit, soc_port_t port, phy84328_intf_side_t side, uint32 *rx_seq_done, uint32 *no_cdr_lanes) { uint16 data; int lane_end, lane; uint16 cdr_locked; phy_ctrl_t *pc; pc = EXT_PHY_SW_STATE(unit, port); cdr_locked = 0; *no_cdr_lanes = 0; if (side == PHY84328_INTF_SIDE_SYS) { PHY_84328_MICRO_PAUSE(unit, port, "cdr lanes get"); } if (PHY84328_SINGLE_PORT_MODE(pc)) { lane_end = PHY84328_NUM_LANES; } else { lane_end = 1; _phy_84328_intf_side_regs_select(unit, port, side); } for (lane = 0; lane < lane_end; lane++) { if (PHY84328_SINGLE_PORT_MODE(pc)) { /* Select the lane on the line side */ SOC_IF_ERROR_RETURN(_phy_84328_channel_select(unit, port, side, lane)); } /* Select SigDet/CDR lock status to be read in anaRxStatus */ SOC_IF_ERROR_RETURN( READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_ANARXCONTROL, &data)); if ((data & PHY84328_SYS_DEV1_ANARXCONTROL_STATUS_SEL_MASK) != 0) { SOC_IF_ERROR_RETURN( MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_ANARXCONTROL, 0, PHY84328_SYS_DEV1_ANARXCONTROL_STATUS_SEL_MASK)); } SOC_IF_ERROR_RETURN( READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_ANARXSTATUS, &data)); /* CDR==RxSeqDone */ if ((data & PHY84328_DEV1_ANARXSTATUS_RXSTATUS_CDR) == PHY84328_DEV1_ANARXSTATUS_RXSTATUS_CDR) { cdr_locked++; } else if (data & 0x8000) { /* Sigdet but no cdr lock */ *no_cdr_lanes |= 1 << lane; } } /* Restore to default single port register access */ if (PHY84328_SINGLE_PORT_MODE(pc)) { SOC_IF_ERROR_RETURN(_phy_84328_channel_select(unit, port, PHY84328_INTF_SIDE_LINE, PHY84328_ALL_LANES)); } _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_LINE); if (side == PHY84328_INTF_SIDE_SYS) { PHY_84328_MICRO_RESUME(unit, port); } *rx_seq_done = (cdr_locked == lane_end); return SOC_E_NONE; } STATIC int _phy_84328_rx_seq_done_get(int unit, soc_port_t port, phy84328_intf_side_t side, uint32 *rx_seq_done) { uint32 no_cdr_lanes; return _phy_84328_rx_seq_done_cdr_lanes_get(unit, port, side, rx_seq_done, &no_cdr_lanes); } STATIC int _phy_84328_sw_rx_los_check(int unit, soc_port_t port, uint16 link, uint16 *new_link) { int pcs_link; uint8 sys_link; phy_ctrl_t *pc; phy84328_sw_rx_los_states_t rx_los_state; phy84328_sw_rx_los_t *sw_rx_los; uint32 no_cdr_lanes = 0; uint32 rx_seq_done = 0; #if defined(BROADCOM_DEBUG) || defined(DEBUG_PRINT) int dbg_flag = 1; #endif pc = EXT_PHY_SW_STATE(unit, port); sw_rx_los = &(SW_RX_LOS(pc)); #ifdef BCM_WARM_BOOT_SUPPORT if ( SOC_WARM_BOOT(unit) || SOC_IS_RELOADING(unit) ) { *new_link = sw_rx_los->sys_link; return SOC_E_NONE; } #endif pcs_link = link; sys_link = sw_rx_los->sys_link; rx_los_state = sw_rx_los->state; sw_rx_los->link_status = 0; no_cdr_lanes = 0; rx_seq_done = 0; SOC_IF_ERROR_RETURN( _phy_84328_rx_seq_done_cdr_lanes_get(unit, port, PHY84328_INTF_SIDE_LINE, &rx_seq_done, &no_cdr_lanes)); if (rx_los_state != PHY84328_SW_RX_LOS_IDLE) { #if defined(BROADCOM_DEBUG) || defined(DEBUG_PRINT) LOG_VERBOSE(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 SRL_IN: u=%d p=%d state=%s pcs_link=%d sys_link=%d link_status=%d " "rx_seq_done=%d no_cdr_lanes=%x\n"), unit, port, sw_rx_los_state_names[rx_los_state], pcs_link, sys_link, sw_rx_los->link_status, rx_seq_done, no_cdr_lanes)); #endif } /* * Current State: Don't Care * Next State: IDLE * If link was previously TRUE and is still true, * set the state to IDLE */ if ((sys_link == TRUE) && (pcs_link == TRUE)) { rx_los_state = PHY84328_SW_RX_LOS_IDLE; } /* * Current State: IDLE * Next State: RESET * If the state was IDLE(link up) but now link is down, * enter the RESET state */ if ((rx_los_state == PHY84328_SW_RX_LOS_IDLE) && (pcs_link == FALSE)) { rx_los_state = PHY84328_SW_RX_LOS_RESET; sys_link = FALSE; } /* * Current State: RESET * Next State: INITIAL_LINK or START_TIMER * If state is RESET, it's next state could be INITIAL LINK * or START_TIMER depending upon the pcs_link state */ if (rx_los_state == PHY84328_SW_RX_LOS_RESET) { if ((pcs_link == TRUE) && rx_seq_done) { rx_los_state = PHY84328_SW_RX_LOS_INITIAL_LINK; } else if (rx_seq_done) { rx_los_state = PHY84328_SW_RX_LOS_START_TIMER; sw_rx_los->ls_ticks = 0; } } if (rx_los_state != PHY84328_SW_RX_LOS_IDLE) { #if defined(BROADCOM_DEBUG) || defined(DEBUG_PRINT) if (dbg_flag == 1) { LOG_VERBOSE(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 SRL_UPD: u=%d p=%d state=%s pcs_link=%d sys_link=%d link_status=%d " "rx_seq_done=%d\n====\n"), unit, port, sw_rx_los_state_names[rx_los_state], pcs_link, sys_link, sw_rx_los->link_status, rx_seq_done)); } #endif } /* Take action depending upon the current state */ switch (rx_los_state) { case PHY84328_SW_RX_LOS_IDLE: /* Do nothing */ /* Link ON condition */ break; case PHY84328_SW_RX_LOS_RESET: #ifdef SW_RX_LOS_FLAP_CHECK if (sw_rx_los->fault_report_dis) { SOC_IF_ERROR_RETURN (MAC_CONTROL_SET(sw_rx_los->macd, unit, port, SOC_MAC_CONTROL_FAULT_LOCAL_ENABLE, TRUE)); sw_rx_los->fault_report_dis = 0; } #endif sys_link = FALSE; break; case PHY84328_SW_RX_LOS_INITIAL_LINK: #ifdef SW_RX_LOS_FLAP_CHECK /* Disable local fault reporting to avoid link flaps untill * link stablizes */ SOC_IF_ERROR_RETURN (MAC_CONTROL_SET(sw_rx_los->macd, unit, port, SOC_MAC_CONTROL_FAULT_LOCAL_ENABLE, FALSE)); sw_rx_los->fault_report_dis = 1; #endif #if defined(BROADCOM_DEBUG) || defined(DEBUG_PRINT) if (dbg_flag == 1) { LOG_VERBOSE(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 sw rx los: u=%d p=%d state=%s: restarting RxSeq\n"), unit, port, sw_rx_los_state_names[rx_los_state])); } #endif sw_rx_los->restarts++; SOC_IF_ERROR_RETURN(_phy_84328_rxseq_restart(unit, port, no_cdr_lanes)); /* Skip the link transition for this rx reset */ sw_rx_los->link_status = 1; rx_los_state = PHY84328_SW_RX_LOS_LINK; #if defined(BROADCOM_DEBUG) || defined(DEBUG_PRINT) if (dbg_flag == 1) { LOG_VERBOSE(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 sw rx los: u=%d p=%d state:%s \n"), unit, port, sw_rx_los_state_names[rx_los_state])); } #endif break; case PHY84328_SW_RX_LOS_LINK: if( pcs_link == TRUE) { sys_link = TRUE; sw_rx_los->link_no_pcs = 0; rx_los_state = PHY84328_SW_RX_LOS_IDLE; } else { sw_rx_los->link_no_pcs++; if (sw_rx_los->link_no_pcs > 20) { rx_los_state = PHY84328_SW_RX_LOS_RESET; sw_rx_los->link_no_pcs = 0; } } #ifdef SW_RX_LOS_FLAP_CHECK /* Enable local fault reporting disabled earlier */ SOC_IF_ERROR_RETURN (MAC_CONTROL_SET(sw_rx_los->macd, unit, port, SOC_MAC_CONTROL_FAULT_LOCAL_ENABLE, TRUE)); sw_rx_los->fault_report_dis = 0; #endif #if defined(BROADCOM_DEBUG) || defined(DEBUG_PRINT) if (dbg_flag == 1) { LOG_VERBOSE(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 sw rx los: u=%d p=%d state:%s \n"), unit, port, sw_rx_los_state_names[rx_los_state])); } #endif break; case PHY84328_SW_RX_LOS_START_TIMER: sw_rx_los->ls_ticks++; if (pcs_link || (sw_rx_los->ls_ticks > 24)) { rx_los_state = PHY84328_SW_RX_LOS_RX_RESTART; sw_rx_los->ls_ticks = 0; } #if defined(BROADCOM_DEBUG) || defined(DEBUG_PRINT) if (dbg_flag == 1) { LOG_VERBOSE(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 sw rx los: u=%d p=%d state:%s \n"), unit, port, sw_rx_los_state_names[rx_los_state])); } #endif break; case PHY84328_SW_RX_LOS_RX_RESTART: #ifdef SW_RX_LOS_FLAP_CHECK /* * Disable local fault reporting to avoid link flaps until link stablizes */ SOC_IF_ERROR_RETURN (MAC_CONTROL_SET(sw_rx_los->macd, unit, port, SOC_MAC_CONTROL_FAULT_LOCAL_ENABLE, FALSE)); sw_rx_los->fault_report_dis = 1; #endif #if defined(BROADCOM_DEBUG) || defined(DEBUG_PRINT) if (dbg_flag == 1) { LOG_VERBOSE(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 sw rx los: u=%d p=%d state:%s -> restarting RxSeq\n"), unit, port, sw_rx_los_state_names[rx_los_state])); } #endif sw_rx_los->restarts++; SOC_IF_ERROR_RETURN(_phy_84328_rxseq_restart(unit, port, no_cdr_lanes)); if( pcs_link == FALSE) { rx_los_state = PHY84328_SW_RX_LOS_RESET; } else { rx_los_state = PHY84328_SW_RX_LOS_LINK; } #if defined(BROADCOM_DEBUG) || defined(DEBUG_PRINT) if (dbg_flag == 1) { LOG_VERBOSE(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 sw rx los : u=%d p=%d state:%s \n"), unit, port, sw_rx_los_state_names[rx_los_state])); } #endif /* Skip the link transition for this rx reset */ sw_rx_los->link_status = 1; break; default: break; } sw_rx_los->sys_link = sys_link;; sw_rx_los->state = rx_los_state; *new_link = sys_link; return SOC_E_NONE; } /* Return contents of ANARXSTATUS */ STATIC int _phy_84328_intf_link_get(int unit, soc_port_t port, uint16 *link) { int lane, max_lane; uint16 data; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); *link = 0; if (PHY84328_SINGLE_PORT_MODE(pc)) { max_lane = PHY84328_NUM_LANES; } else { max_lane = 1; } for (lane = 0; lane < max_lane; lane++) { if (PHY84328_SINGLE_PORT_MODE(pc)) { /* Select the lane on the line side */ SOC_IF_ERROR_RETURN(_phy_84328_channel_select(unit, port, PHY84328_INTF_SIDE_LINE, lane)); } /* Select SigDet/CDR lock status to be read in anaRxStatus */ SOC_IF_ERROR_RETURN( READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_ANARXCONTROL, &data)); if ((data & PHY84328_SYS_DEV1_ANARXCONTROL_STATUS_SEL_MASK) != 0) { SOC_IF_ERROR_RETURN( MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_ANARXCONTROL, 0, PHY84328_SYS_DEV1_ANARXCONTROL_STATUS_SEL_MASK)); } /* Check if rxSeq Done in any lane */ SOC_IF_ERROR_RETURN( READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_ANARXSTATUS, &data)); if ((data & PHY84328_DEV1_ANARXSTATUS_RXSTATUS_CDR) == PHY84328_DEV1_ANARXSTATUS_RXSTATUS_CDR) { *link = 1; break; } } /* Restore to default single port register access */ if (PHY84328_SINGLE_PORT_MODE(pc)) { SOC_IF_ERROR_RETURN(_phy_84328_channel_select(unit, port, PHY84328_INTF_SIDE_LINE, PHY84328_ALL_LANES)); } _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_LINE); return SOC_E_NONE; } /* * Called when there is no link so check different link components and attempt to * recover by restarting interface if appropriate */ STATIC int _phy_84328_link_recover(int unit, soc_port_t port, int line_link, int int_phy_link) { phy_ctrl_t *pc; phy84328_counters_t *counters; phy84328_link_mon_t *link_mon; pc = EXT_PHY_SW_STATE(unit, port); counters = &(COUNTERS(pc)); link_mon = &(LINK_MON(pc)); if (line_link && !int_phy_link) { if (link_mon->debounce > PHY84328_LINK_DEBOUNCE) { counters->retry_serdes_link++; LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 restarting intf: u=%d p=%d line=%04x internal=%04x debounce=%d\n"), unit, port, line_link, int_phy_link, link_mon->debounce)); SOC_IF_ERROR_RETURN(_phy_84328_intf_line_sys_update(unit, port)); link_mon->debounce = 0; } else { link_mon->debounce++; } } else { link_mon->debounce = 0; } return SOC_E_NONE; } /* * Function: * phy_84328_link_get * Purpose: * Get layer2 connection status. * Parameters: * unit - StrataSwitch unit #. * port - StrataSwitch port #. * link - address of memory to store link up/down state. * Returns: * SOC_E_NONE */ STATIC int _phy_84328_link_get(int unit, soc_port_t port, int *link) { phy_ctrl_t *pc; phy_ctrl_t *int_pc; uint16 line_link; int int_phy_link; phy84328_sw_rx_los_t *sw_rx_los; phy84328_link_mon_t *link_mon; phy84328_counters_t *counters; if (link == NULL) { return SOC_E_NONE; } if (PHY_FLAGS_TST(unit, port, PHY_FLAGS_DISABLE)) { *link = 0; return SOC_E_NONE; } pc = EXT_PHY_SW_STATE(unit, port); int_pc = INT_PHY_SW_STATE(unit, port); counters = &(COUNTERS(pc)); /* * PCS from the internal PHY is used to determine link. */ if (int_pc != NULL) { SOC_IF_ERROR_RETURN(PHY_LINK_GET(int_pc->pd, unit, port, &int_phy_link)); *link = int_phy_link; } else { *link = 0; } sw_rx_los = &(SW_RX_LOS(pc)); if (sw_rx_los->cur_enable) { uint16 new_link = 0; if (_phy_84328_sw_rx_los_check(unit, port, *link, &new_link) != SOC_E_NONE) { LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 rx los check failed: u=%d port=%d\n"), unit, port)); } *link = new_link; } if (CUR_LINK(pc) && (*link == 0)) { counters->link_down++; } CUR_LINK(pc) = *link; link_mon = &(LINK_MON(pc)); if (link_mon->cur_enable) { if (*link) { link_mon->debounce = 0; } else { SOC_IF_ERROR_RETURN(_phy_84328_intf_link_get(unit, port, &line_link)); if (line_link) { _phy_84328_link_recover(unit, port, line_link, *link); } else { link_mon->debounce = 0; } } } if (MOD_AUTO_DETECT(pc)) { _phy_84328_mod_auto_detect_update(unit, port); } return SOC_E_NONE; } /* * Function: * phy_84328_enable_set * Purpose: * Enable/Disable phy * Parameters: * unit - StrataSwitch unit #. * port - StrataSwitch port #. * enable - on/off state to set * Returns: * SOC_E_NONE */ STATIC int _phy_84328_enable_set(int unit, soc_port_t port, int enable) { uint16 chan_data, chan_mask; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); /* Manually power channel up/down */ chan_data = enable ? 0 : (1 << PHY84328_DEV1_OPTICAL_CONFIGURATION_MAN_TXON_EN_SHIFT) | (1 << PHY84328_DEV1_OPTICAL_CONFIGURATION_TXOFFT_SHIFT); chan_mask = PHY84328_DEV1_OPTICAL_CONFIGURATION_MAN_TXON_EN_MASK | PHY84328_DEV1_OPTICAL_CONFIGURATION_TXOFFT_MASK; SOC_IF_ERROR_RETURN( MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_OPTICAL_CONFIGURATION, chan_data, chan_mask)); if (enable) { /* Let the micro settle down after powering back up */ if (PORT_ENABLE_DELAY(pc)) { sal_udelay(PORT_ENABLE_DELAY(pc)); } PHY_FLAGS_CLR(unit, port, PHY_FLAGS_DISABLE); } else { PHY_FLAGS_SET(unit, port, PHY_FLAGS_DISABLE); } return SOC_E_NONE; } /* * The microcode automatically squelches tx in 1.c066[10] when opposite side has * no link. Setting 1.ca18[7] disables the microcode from squelching */ STATIC int _phy_84328_micro_tx_squelch_enable(int unit, soc_port_t port, int enable) { uint16 data; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); /* 1.ca18[7] 0=micro squelching enabled, 1=micro squelching disabled */ data = enable ? 0 : 0x80; SOC_IF_ERROR_RETURN( MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_GP_REG_0, data, 0x80)); return SOC_E_NONE; } /* * Squelch/unsquelch tx in 1.c066[8] */ STATIC int _phy_84328_tx_squelch(int unit, soc_port_t port, phy84328_intf_side_t side, int squelch) { uint16 data; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); _phy_84328_intf_side_regs_select(unit, port, side); /* 1.c066[8] 0=unsquelch, 1=squelch - electrical idle */ data = squelch ? PHY84328_DEV1_ANATXACONTROL2_TX_ELECTRAL_IDLE : 0; SOC_IF_ERROR_RETURN( MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_ANATXACONTROL2, data, PHY84328_DEV1_ANATXACONTROL2_TX_ELECTRAL_IDLE)); if (side != PHY84328_INTF_SIDE_LINE) { _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_LINE); } return SOC_E_NONE; } /* * Enable/disable transmitter */ STATIC int _phy_84328_tx_enable(int unit, soc_port_t port, phy84328_intf_side_t side, int enable) { uint16 data; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); _phy_84328_intf_side_regs_select(unit, port, side); if (CUR_DATAPATH(pc) == PHY84328_DATAPATH_20) { /* 1.c06a[0] 0=tx enabled, 1=tx disabled */ data = enable ? 0 : (1 << PHY84328_DEV1_ANATXACONTROL6_DISABLE_TRANSMIT_SHIFT); SOC_IF_ERROR_RETURN( MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_ANATXACONTROL6, data, PHY84328_DEV1_ANATXACONTROL6_DISABLE_TRANSMIT_MASK)); } else { /* 1.c068[13] 0=tx enabled, 1=tx disabled */ data = enable ? 0 : (1 << PHY84328_DEV1_ANATXACONTROL4_XFI_LOWLATENCY_FIFO_ZERO_OUT_SHIFT); SOC_IF_ERROR_RETURN(MODIFY_PHY84328_MMF_PMA_PMD_REG( unit, pc, PHY84328_DEV1_ANATXACONTROL4, data, PHY84328_DEV1_ANATXACONTROL4_XFI_LOWLATENCY_FIFO_ZERO_OUT_MASK)); } if (side != PHY84328_INTF_SIDE_LINE) { _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_LINE); } return SOC_E_NONE; } STATIC int _phy_84328_data_path_check(int unit, soc_port_t port) { phy_ctrl_t *pc; phy84328_intf_cfg_t *sys_intf; pc = EXT_PHY_SW_STATE(unit, port); sys_intf = &(SYS_INTF(pc)); if (sys_intf->speed < 10000) { /* Speeds below 10G requires 20-bit datapath */ if (CUR_DATAPATH(pc) != PHY84328_DATAPATH_20) { CUR_DATAPATH(pc) = PHY84328_DATAPATH_20; SOC_IF_ERROR_RETURN(_phy_84328_intf_datapath_update(unit, port)); } } else { /* Speeds 10G and above can use configured dpath, if !forced 20-bit */ if (FORCE_20BIT(pc) != 0) { if (CUR_DATAPATH(pc) != PHY84328_DATAPATH_20) { CUR_DATAPATH(pc) = PHY84328_DATAPATH_20; SOC_IF_ERROR_RETURN(_phy_84328_intf_datapath_update(unit, port)); } } else { if (CUR_DATAPATH(pc) != CFG_DATAPATH(pc)) { CUR_DATAPATH(pc) = CFG_DATAPATH(pc); SOC_IF_ERROR_RETURN(_phy_84328_intf_datapath_update(unit, port)); } } } return SOC_E_NONE; } /* * Function: * phy_84328_lb_set * Purpose: * Put 84328 in PHY PMA/PMD loopback * Parameters: * unit - StrataSwitch unit #. * port - StrataSwitch port #. * enable - binary value for on/off (1/0) * Returns: * SOC_E_NONE */ STATIC int _phy_84328_lb_set(int unit, soc_port_t port, int enable) { int rv = SOC_E_NONE; uint16 data, mask; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); SOC_IF_ERROR_RETURN(_phy_84328_sw_rx_los_pause(unit, port, enable)); SOC_IF_ERROR_RETURN(_phy_84328_link_mon_pause(unit, port, enable)); /* * If enabling loopback * disable tx line */ if (enable) { SOC_IF_ERROR_RETURN(_phy_84328_tx_enable(unit, port, PHY84328_INTF_SIDE_LINE, FALSE )); } /* Loopback requires 20-bit datapath */ FORCE_20BIT(pc) &= ~(FORCE_20BIT_LB); FORCE_20BIT(pc) |= enable ? FORCE_20BIT_LB : 0; SOC_IF_ERROR_RETURN(_phy_84328_data_path_check(unit, port)); /* * If disabling loopback * enable tx line */ if (!enable) { SOC_IF_ERROR_RETURN(_phy_84328_tx_enable(unit, port, PHY84328_INTF_SIDE_LINE, TRUE )); } _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_SYS); data = enable ? (1 << PHY84328_SYS_DEV1_ANATXACONTROL6_RLOOP_SHIFT) : (1 << PHY84328_DEV1_ANATXACONTROL6_LOWLATENCY_PATH_SELECT_SHIFT); mask = PHY84328_SYS_DEV1_ANATXACONTROL6_RLOOP_MASK | PHY84328_DEV1_ANATXACONTROL6_LOWLATENCY_PATH_SELECT_MASK; rv = MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_ANATXACONTROL6, data, mask); if (SOC_FAILURE(rv)) { LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 failed setting loopback: u=%d port=%d\n"), unit, port)); } _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_LINE); return rv; } /* * Function: * phy_84328_lb_get * Purpose: * Get 84328 PHY loopback state * Parameters: * unit - StrataSwitch unit #. * port - StrataSwitch port #. * enable - address of location to store binary value for on/off (1/0) * Returns: * SOC_E_NONE */ STATIC int _phy_84328_lb_get(int unit, soc_port_t port, int *enable) { int rv = SOC_E_NONE; uint16 data; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); if (NULL == enable) { return SOC_E_PARAM; } *enable = 0xFFFF; /* Check if rloop in system side */ _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_SYS); rv = READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_ANATXACONTROL6, &data); *enable &= ((data & PHY84328_SYS_DEV1_ANATXACONTROL6_RLOOP_MASK) == (1 << PHY84328_SYS_DEV1_ANATXACONTROL6_RLOOP_SHIFT)); _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_LINE); return rv; } STATIC int _phy_84328_control_preemphasis_lane_get(soc_phy_control_t type) { int lane; switch (type) { case SOC_PHY_CONTROL_PREEMPHASIS_LANE0: lane = 0; break; case SOC_PHY_CONTROL_PREEMPHASIS_LANE1: lane = 1; break; case SOC_PHY_CONTROL_PREEMPHASIS_LANE2: lane = 2; break; case SOC_PHY_CONTROL_PREEMPHASIS_LANE3: lane = 3; break; default: lane = PHY84328_ALL_LANES; break; } return lane; } STATIC int _phy_84328_control_preemphasis_set(int unit, soc_port_t port, soc_phy_control_t type, phy84328_intf_side_t side, uint32 value) { uint16 preemph_value; int lane, lane_idx, lane_start, lane_end; uint16 tx_fir_sel, tx_fir_mask; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); lane = _phy_84328_control_preemphasis_lane_get(type); if (!PHY84328_SINGLE_PORT_MODE(pc) && (lane != PHY84328_ALL_LANES)) { if (lane != (pc->phy_id & 0x03)) { return SOC_E_PARAM; } } preemph_value = (uint16) (value & 0xffff); /* * Value format: * bit 15: if set, enable forced preemphasis control, otherwise, auto configured - see 1.c192[3:0] * bit 13:10: postcursor_tap - see 1.c067[7:4] * bit 08:04: main_tap - see 1.c066[15:11] * bit 02:00: precursor_tap - see 1.c067[2:0] */ /* * Single mode: if lane specified, enable only that lane, otherwise enable all lanes * Quad mode: if specified lane matches lane for the channel, set the lane */ if (PHY84328_SINGLE_PORT_MODE(pc)) { tx_fir_sel = (lane == PHY84328_ALL_LANES) ? 0xf : (1 << lane); tx_fir_mask = (lane == PHY84328_ALL_LANES) ? PHY84328_DEV1_XFI_AFE_CTL2_TX_FIR_SEL_MASK : (1 << lane); } else { tx_fir_sel = 1 << (pc->phy_id & 0x03); tx_fir_mask = 1 << (pc->phy_id & 0x03); } if (PHY84328_SINGLE_PORT_MODE(pc)) { lane_start = (lane == PHY84328_ALL_LANES) ? 0 : lane; lane_end = (lane == PHY84328_ALL_LANES) ? PHY84328_NUM_LANES : lane + 1; } else { /* Make sure specified lane matches lane for the channel */ if (lane != PHY84328_ALL_LANES) { if (lane != (pc->phy_id & 0x03)) { return SOC_E_PARAM; } } lane_start = 0; lane_end = 1; } if (side == PHY84328_INTF_SIDE_SYS) { PHY_84328_MICRO_PAUSE(unit, port, "preemphasis set"); } if (!PHY84328_SINGLE_PORT_MODE(pc)) { _phy_84328_intf_side_regs_select(unit, port, side); } /* Update all requested lanes */ for (lane_idx = lane_start; lane_idx < lane_end; lane_idx++) { if (PHY84328_SINGLE_PORT_MODE(pc)) { /* Select the lane and side to write */ SOC_IF_ERROR_RETURN(_phy_84328_channel_select(unit, port, side, lane_idx)); } /* Enable manual preemphasis */ SOC_IF_ERROR_RETURN( MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_XFI_AFE_CTL2, tx_fir_sel, tx_fir_mask)); /* Main tap */ SOC_IF_ERROR_RETURN( MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_ANATXACONTROL2, PHY84328_PREEMPH_MAIN_TAP_GET(preemph_value) << PHY84328_DEV1_ANATXACONTROL2_MAIN_TAP_SHIFT, PHY84328_DEV1_ANATXACONTROL2_MAIN_TAP_MASK)); /* Pre and post cursor */ SOC_IF_ERROR_RETURN( MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_ANATXACONTROL3, (PHY84328_PREEMPH_POST_TAP_GET(preemph_value) << PHY84328_DEV1_ANATXACONTROL3_POSTCURSOR_TAP_SHIFT) | (PHY84328_PREEMPH_PRE_TAP_GET(preemph_value) << PHY84328_DEV1_ANATXACONTROL3_PRECURSOR_TAP_SHIFT), (PHY84328_DEV1_ANATXACONTROL3_POSTCURSOR_TAP_MASK | PHY84328_DEV1_ANATXACONTROL3_PRECURSOR_TAP_MASK))); } if (PHY84328_SINGLE_PORT_MODE(pc)) { SOC_IF_ERROR_RETURN(_phy_84328_channel_select(unit, port, side, PHY84328_ALL_LANES)); } _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_LINE); if (side == PHY84328_INTF_SIDE_SYS) { PHY_84328_MICRO_RESUME(unit, port); } return SOC_E_NONE; } STATIC int _phy_84328_control_preemphasis_get(int unit, soc_port_t port, soc_phy_control_t type, phy84328_intf_side_t side, uint32 *value) { int lane, lane_idx; uint16 forced; uint16 data; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); lane = _phy_84328_control_preemphasis_lane_get(type); lane_idx = (lane == PHY84328_ALL_LANES) ? 0 : lane; if (side == PHY84328_INTF_SIDE_SYS) { PHY_84328_MICRO_PAUSE(unit, port, "preemphasis get"); } if (PHY84328_SINGLE_PORT_MODE(pc)) { SOC_IF_ERROR_RETURN(_phy_84328_channel_select(unit, port, side, lane_idx)); } else { _phy_84328_intf_side_regs_select(unit, port, side); } /* * Value format: * bit 15: if set, enable forced preemphasis control, otherwise, auto configured - see 1.c192[3:0] * bit 13:10: postcursor_tap - see 1.c067[7:4] * bit 08:04: main_tap - see 1.c066[15:11] * bit 02:00: precursor_tap - see 1.c067[2:0] */ *value = 0; SOC_IF_ERROR_RETURN( READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_XFI_AFE_CTL2, &data)); data &= 0xf; if (PHY84328_SINGLE_PORT_MODE(pc)) { if (lane == PHY84328_ALL_LANES) { forced = (data == 0xf) ? 1 : 0; } else { forced = (data & (1 << lane)) ? 1 : 0; } } else { forced = (data & (1 << (pc->phy_id & 0x03))) ? 1 : 0; } *value = PHY84328_PREEMPH_FORCE_SET(forced); SOC_IF_ERROR_RETURN( READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_ANATXACONTROL2, &data)); *value |= PHY84328_PREEMPH_MAIN_TAP_SET((data & PHY84328_DEV1_ANATXACONTROL2_MAIN_TAP_MASK) >> PHY84328_DEV1_ANATXACONTROL2_MAIN_TAP_SHIFT); SOC_IF_ERROR_RETURN( READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_ANATXACONTROL3, &data)); *value |= PHY84328_PREEMPH_POST_TAP_SET((data & PHY84328_DEV1_ANATXACONTROL3_POSTCURSOR_TAP_MASK) >> PHY84328_DEV1_ANATXACONTROL3_POSTCURSOR_TAP_SHIFT); *value |= PHY84328_PREEMPH_PRE_TAP_SET((data & PHY84328_DEV1_ANATXACONTROL3_PRECURSOR_TAP_MASK) >> PHY84328_DEV1_ANATXACONTROL3_PRECURSOR_TAP_SHIFT); if (PHY84328_SINGLE_PORT_MODE(pc)) { SOC_IF_ERROR_RETURN(_phy_84328_channel_select(unit, port, side, PHY84328_ALL_LANES)); } _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_LINE); if (side == PHY84328_INTF_SIDE_SYS) { PHY_84328_MICRO_RESUME(unit, port); } return SOC_E_NONE; } STATIC int _phy_84328_txmode_manual_set(int unit, soc_port_t port, phy84328_intf_side_t side, int set) { uint16 data, mask; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); phy84328_intf_side_t cur_side; mask = (side == PHY84328_INTF_SIDE_LINE) ? (1 << 4) : (1 << 3); data = set ? mask : 0; cur_side = _phy_84328_intf_side_regs_get(unit, port); if (cur_side == PHY84328_INTF_SIDE_SYS) { _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_LINE); } SOC_IF_ERROR_RETURN(MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_GP_REG_0, data, mask)); if (cur_side == PHY84328_INTF_SIDE_SYS) { _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_SYS); } return SOC_E_NONE; } STATIC int _phy_84328_control_tx_driver_set(int unit, soc_port_t port, soc_phy_control_t type, phy84328_intf_side_t side, uint32 value) { uint16 data, mask; int lane, lane_idx, lane_start, lane_end; int idriver = 0; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); switch (type) { case SOC_PHY_CONTROL_DRIVER_CURRENT_LANE0: lane = 0; data = (uint16) (value & 0xf); data = data << PHY84328_SYS_DEV1_ANATXACONTROL1_IDRIVER_SHIFT; mask = PHY84328_SYS_DEV1_ANATXACONTROL1_IDRIVER_MASK; idriver = 1; break; case SOC_PHY_CONTROL_DRIVER_CURRENT_LANE1: lane = 1; data = (uint16) (value & 0xf); data = data << PHY84328_SYS_DEV1_ANATXACONTROL1_IDRIVER_SHIFT; mask = PHY84328_SYS_DEV1_ANATXACONTROL1_IDRIVER_MASK; idriver = 1; break; case SOC_PHY_CONTROL_DRIVER_CURRENT_LANE2: lane = 2; data = (uint16) (value & 0xf); data = data << PHY84328_SYS_DEV1_ANATXACONTROL1_IDRIVER_SHIFT; mask = PHY84328_SYS_DEV1_ANATXACONTROL1_IDRIVER_MASK; idriver = 1; break; case SOC_PHY_CONTROL_DRIVER_CURRENT_LANE3: lane = 3; data = (uint16) (value & 0xf); data = data << PHY84328_SYS_DEV1_ANATXACONTROL1_IDRIVER_SHIFT; mask = PHY84328_SYS_DEV1_ANATXACONTROL1_IDRIVER_MASK; idriver = 1; break; case SOC_PHY_CONTROL_DRIVER_CURRENT: lane = PHY84328_ALL_LANES; data = (uint16) (value & 0xf); data = data << PHY84328_SYS_DEV1_ANATXACONTROL1_IDRIVER_SHIFT; mask = PHY84328_SYS_DEV1_ANATXACONTROL1_IDRIVER_MASK; idriver = 1; break; case SOC_PHY_CONTROL_PRE_DRIVER_CURRENT_LANE0: lane = 0; data = (uint16) (value & 0xf); data = data << PHY84328_SYS_DEV1_ANATXACONTROL1_IPREDRIVER_SHIFT; mask = PHY84328_DEV1_ANATXACONTROL1_IPREDRIVER_MASK; break; case SOC_PHY_CONTROL_PRE_DRIVER_CURRENT_LANE1: lane = 1; data = (uint16) (value & 0xf); data = data << PHY84328_SYS_DEV1_ANATXACONTROL1_IPREDRIVER_SHIFT; mask = PHY84328_DEV1_ANATXACONTROL1_IPREDRIVER_MASK; break; case SOC_PHY_CONTROL_PRE_DRIVER_CURRENT_LANE2: lane = 2; data = (uint16) (value & 0xf); data = data << PHY84328_SYS_DEV1_ANATXACONTROL1_IPREDRIVER_SHIFT; mask = PHY84328_DEV1_ANATXACONTROL1_IPREDRIVER_MASK; break; case SOC_PHY_CONTROL_PRE_DRIVER_CURRENT_LANE3: lane = 3; data = (uint16) (value & 0xf); data = data << PHY84328_SYS_DEV1_ANATXACONTROL1_IPREDRIVER_SHIFT; mask = PHY84328_DEV1_ANATXACONTROL1_IPREDRIVER_MASK; break; case SOC_PHY_CONTROL_PRE_DRIVER_CURRENT: lane = PHY84328_ALL_LANES; data = (uint16) (value & 0xf); data = data << PHY84328_SYS_DEV1_ANATXACONTROL1_IPREDRIVER_SHIFT; mask = PHY84328_DEV1_ANATXACONTROL1_IPREDRIVER_MASK; break; default: return SOC_E_PARAM; } /* * Qualify lane * - single mode: if lane specified, enable only that lane in Single_PMD_Ctrl 1.ca86[5:4], * otherwise program all lanes * - quad mode: make sure the lane corresponds to the channel, and program the lane * - 20G mode: if lane specified, enable only that lane, otherwise program all lanes */ if (PHY84328_SINGLE_PORT_MODE(pc)) { lane_start = (lane == PHY84328_ALL_LANES) ? 0 : lane; lane_end = (lane == PHY84328_ALL_LANES) ? PHY84328_NUM_LANES : lane + 1; } else { /* Make sure specified lane matches lane for the channel */ if (lane != PHY84328_ALL_LANES) { if (lane != (pc->phy_id & 0x03)) { return SOC_E_PARAM; } } lane_start = 0; lane_end = 1; } /* * Driver current (idriver) and tx_mode are updated by the firmware by default. * If driver current is programmed with value != 0, * the firmware will no longer update driver current and tx_mode. * Setting driver current to 0 (re)enables firmware update of both driver current and * tx_mode */ if (idriver) { if (data & PHY84328_SYS_DEV1_ANATXACONTROL1_IDRIVER_MASK) { SOC_IF_ERROR_RETURN(_phy_84328_txmode_manual_set(unit, port, side, TRUE)); } else { SOC_IF_ERROR_RETURN(_phy_84328_txmode_manual_set(unit, port, side, FALSE)); } } if (side == PHY84328_INTF_SIDE_SYS) { PHY_84328_MICRO_PAUSE(unit, port, "tx driver set"); } if (!PHY84328_SINGLE_PORT_MODE(pc)) { _phy_84328_intf_side_regs_select(unit, port, side); } /* Update all requested lanes */ for (lane_idx = lane_start; lane_idx < lane_end; lane_idx++) { if (PHY84328_SINGLE_PORT_MODE(pc)) { /* Select the lane and side to write */ SOC_IF_ERROR_RETURN(_phy_84328_channel_select(unit, port, side, lane)); } SOC_IF_ERROR_RETURN(MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_ANATXACONTROL1, data, mask)); } if (PHY84328_SINGLE_PORT_MODE(pc)) { SOC_IF_ERROR_RETURN(_phy_84328_channel_select(unit, port, side, PHY84328_ALL_LANES)); } _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_LINE); if (side == PHY84328_INTF_SIDE_SYS) { PHY_84328_MICRO_RESUME(unit, port); } return SOC_E_NONE; } STATIC int _phy_84328_control_tx_driver_get(int unit, soc_port_t port, soc_phy_control_t type, phy84328_intf_side_t side, uint32 *value) { int rv; int lane = 0; uint16 data, shift, mask; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); switch (type) { case SOC_PHY_CONTROL_DRIVER_CURRENT_LANE0: lane = 0; shift = PHY84328_SYS_DEV1_ANATXACONTROL1_IDRIVER_SHIFT; mask = PHY84328_SYS_DEV1_ANATXACONTROL1_IDRIVER_MASK; break; case SOC_PHY_CONTROL_DRIVER_CURRENT_LANE1: lane = 1; shift = PHY84328_SYS_DEV1_ANATXACONTROL1_IDRIVER_SHIFT; mask = PHY84328_SYS_DEV1_ANATXACONTROL1_IDRIVER_MASK; break; case SOC_PHY_CONTROL_DRIVER_CURRENT_LANE2: lane = 2; shift = PHY84328_SYS_DEV1_ANATXACONTROL1_IDRIVER_SHIFT; mask = PHY84328_SYS_DEV1_ANATXACONTROL1_IDRIVER_MASK; break; case SOC_PHY_CONTROL_DRIVER_CURRENT_LANE3: lane = 3; shift = PHY84328_SYS_DEV1_ANATXACONTROL1_IDRIVER_SHIFT; mask = PHY84328_SYS_DEV1_ANATXACONTROL1_IDRIVER_MASK; break; case SOC_PHY_CONTROL_DRIVER_CURRENT: /* Return value for lane 0 */ lane = 0; shift = PHY84328_SYS_DEV1_ANATXACONTROL1_IDRIVER_SHIFT; mask = PHY84328_SYS_DEV1_ANATXACONTROL1_IDRIVER_MASK; break; case SOC_PHY_CONTROL_PRE_DRIVER_CURRENT_LANE0: lane = 0; shift = PHY84328_SYS_DEV1_ANATXACONTROL1_IPREDRIVER_SHIFT; mask = PHY84328_DEV1_ANATXACONTROL1_IPREDRIVER_MASK; break; case SOC_PHY_CONTROL_PRE_DRIVER_CURRENT_LANE1: lane = 1; shift = PHY84328_SYS_DEV1_ANATXACONTROL1_IPREDRIVER_SHIFT; mask = PHY84328_DEV1_ANATXACONTROL1_IPREDRIVER_MASK; break; case SOC_PHY_CONTROL_PRE_DRIVER_CURRENT_LANE2: lane = 2; shift = PHY84328_SYS_DEV1_ANATXACONTROL1_IPREDRIVER_SHIFT; mask = PHY84328_DEV1_ANATXACONTROL1_IPREDRIVER_MASK; break; case SOC_PHY_CONTROL_PRE_DRIVER_CURRENT_LANE3: lane = 3; shift = PHY84328_SYS_DEV1_ANATXACONTROL1_IPREDRIVER_SHIFT; mask = PHY84328_DEV1_ANATXACONTROL1_IPREDRIVER_MASK; break; case SOC_PHY_CONTROL_PRE_DRIVER_CURRENT: /* Return value for lane 0 */ lane = 0; shift = PHY84328_SYS_DEV1_ANATXACONTROL1_IPREDRIVER_SHIFT; mask = PHY84328_DEV1_ANATXACONTROL1_IPREDRIVER_MASK; break; default: return SOC_E_PARAM; } if (side == PHY84328_INTF_SIDE_SYS) { PHY_84328_MICRO_PAUSE(unit, port, "tx driver get"); } /* Select the lane and side to access */ if (PHY84328_SINGLE_PORT_MODE(pc)) { SOC_IF_ERROR_RETURN(_phy_84328_channel_select(unit, port, side, lane)); } else { _phy_84328_intf_side_regs_select(unit, port, side); } rv = READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_ANATXACONTROL1, &data); if (SOC_FAILURE(rv)) { LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 tx driver get failed: u=%d p=%d\n"), unit, port)); *value = 0xff; } else { *value = (data & mask) >> shift; } if (PHY84328_SINGLE_PORT_MODE(pc)) { /* Restore back to channel 0 */ SOC_IF_ERROR_RETURN(_phy_84328_channel_select(unit, port, side, PHY84328_ALL_LANES)); } _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_LINE); if (side == PHY84328_INTF_SIDE_SYS) { PHY_84328_MICRO_RESUME(unit, port); } return SOC_E_NONE; } STATIC int _phy_84328_control_edc_mode_set(int unit, soc_port_t port, uint32 value) { return SOC_E_UNAVAIL; } /* * enable/disable syncE recoverd clock for 10G/40G modes. */ STATIC int _phy_84328_control_recovery_clock_set(int unit, soc_port_t port, int enable) { return SOC_E_UNAVAIL; } /* * set the frequency of the syncE recoverd clock. */ STATIC int _phy_84328_control_recovery_clock_freq_set(int unit, soc_port_t port, int freq) { return SOC_E_UNAVAIL; } STATIC int _phy_84328_control_prbs_tx_invert_data_set(int unit, soc_port_t port, int invert) { uint16 data; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); data = invert ? (1 << PHY84328_SYS_DEV1_ANATXACONTROL7_NEW_PRBS_INV_SHIFT) : 0; /* tx prbs invert in anaTxAControl7 1.c06b */ SOC_IF_ERROR_RETURN(MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_ANATXACONTROL7, data, PHY84328_SYS_DEV1_ANATXACONTROL7_NEW_PRBS_INV_MASK)); return SOC_E_NONE; } STATIC int _phy_84328_control_prbs_rx_invert_data_set(int unit, soc_port_t port, int invert) { uint16 data; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); data = invert ? (1 << PHY84328_SYS_DEV1_ANARXCONTROL2_PRBS_INV_RX_R_SHIFT) : 0; /* rx prbs invert in anaRxControl2 1.c0b6 */ SOC_IF_ERROR_RETURN( MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_ANARXCONTROL2, data, PHY84328_SYS_DEV1_ANARXCONTROL2_PRBS_INV_RX_R_MASK)); return SOC_E_NONE; } STATIC int _phy_84328_control_prbs_polynomial_set(int unit, soc_port_t port, int poly_ctrl, int tx) { phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 prbs polynomial set: u=%d p=%d polynomial=%d\n"), unit, port, poly_ctrl)); if (poly_ctrl < 0 || poly_ctrl > 3) { LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 prbs invalid polynomial: u=%d p=%d polynomial=%d\n"), unit, port, poly_ctrl)); return SOC_E_PARAM; } /* poly_ctrl: 0==prbs7, 1==prbs15, 2==prbs23, 3==prbs=31 */ if (tx) { /* tx prbs polynomial in anaTxAControl7 1.c06b */ SOC_IF_ERROR_RETURN( MODIFY_PHY84328_MMF_PMA_PMD_REG( unit, pc, PHY84328_DEV1_ANATXACONTROL7, (poly_ctrl << PHY84328_DEV1_ANATXACONTROL7_LANE_PRBS_ORDER_NEW_B1_0_SHIFT), PHY84328_SYS_DEV1_ANATXACONTROL7_LANE_PRBS_ORDER_NEW_B1_0_MASK)); } else { /* rx prbs polynomial in anaRxControl2 1.c0b6 */ SOC_IF_ERROR_RETURN( MODIFY_PHY84328_MMF_PMA_PMD_REG( unit, pc, PHY84328_SYS_DEV1_ANARXCONTROL2, (poly_ctrl << PHY84328_DEV1_ANARXCONTROL2_PRBS_ORDER_RX_R_SHIFT), PHY84328_SYS_DEV1_ANARXCONTROL2_PRBS_ORDER_RX_R_MASK)); } return SOC_E_NONE; } STATIC int _phy_84328_sw_rx_los_pause(int unit, soc_port_t port, int enable) { phy_ctrl_t *pc; phy84328_sw_rx_los_t *sw_rx_los; #ifdef BCM_WARM_BOOT_SUPPORT if ( SOC_WARM_BOOT(unit) || SOC_IS_RELOADING(unit) ) { return SOC_E_NONE; } #endif pc = EXT_PHY_SW_STATE(unit, port); sw_rx_los = &(SW_RX_LOS(pc)); /* Nothing to do if RX LOS not configured */ if (!sw_rx_los->cfg_enable) { return SOC_E_NONE; } sw_rx_los->cur_enable = !enable; return SOC_E_NONE; } STATIC int _phy_84328_link_mon_pause(int unit, soc_port_t port, int enable) { phy_ctrl_t *pc; phy84328_link_mon_t *link_mon; pc = EXT_PHY_SW_STATE(unit, port); link_mon = &(LINK_MON(pc)); /* Nothing to do if LINK_MON not configured */ if (!link_mon->cfg_enable) { return SOC_E_NONE; } link_mon->cur_enable = !enable; return SOC_E_NONE; } STATIC int _phy_84328_control_prbs_enable_set(int unit, soc_port_t port, int enable) { uint16 tx_data, rx_data; uint16 tx_mask, rx_mask; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); SOC_IF_ERROR_RETURN(_phy_84328_sw_rx_los_pause(unit, port, enable)); SOC_IF_ERROR_RETURN(_phy_84328_link_mon_pause(unit, port, enable)); /* Mask enable bits */ tx_mask = (PHY84328_DEV1_ANATXACONTROL7_SELECT_NEW_PRBS_MASK | PHY84328_DEV1_ANATXACONTROL7_NEW_PRBS_EN_MASK); rx_mask = (PHY84328_DEV1_ANARXCONTROL2_PRBS_SEL_RX_R_MASK | PHY84328_DEV1_ANARXCONTROL2_PRBS_EN_RX_R_MASK); /* * PRBS done with 20-bit datapath */ if (enable) { tx_data = (1 << PHY84328_DEV1_ANATXACONTROL7_SELECT_NEW_PRBS_SHIFT) | (1 << PHY84328_DEV1_ANATXACONTROL7_NEW_PRBS_EN_SHIFT); rx_data = (1 << PHY84328_DEV1_ANARXCONTROL2_PRBS_EN_RX_R_SHIFT) | (1 << PHY84328_DEV1_ANARXCONTROL2_PRBS_SEL_RX_R_SHIFT); if (CFG_DATAPATH(pc) != PHY84328_DATAPATH_20) { CUR_DATAPATH(pc) = PHY84328_DATAPATH_20; } } else { tx_data = 0; rx_data = 0; if (CFG_DATAPATH(pc) != PHY84328_DATAPATH_20) { CUR_DATAPATH(pc) = CFG_DATAPATH(pc); } } FORCE_20BIT(pc) &= ~(FORCE_20BIT_LB); FORCE_20BIT(pc) |= enable ? FORCE_20BIT_LB : 0; /* Update datapath */ SOC_IF_ERROR_RETURN(_phy_84328_intf_datapath_update(unit, port)); /* Enable tx prbs in anaTxAcontrol7 1.c06b[6..5] */ SOC_IF_ERROR_RETURN(MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_ANATXACONTROL7, tx_data, tx_mask)); /* Enable rx prbs in anaRxControl2 1.c0b6[6..5] */ SOC_IF_ERROR_RETURN(MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_ANARXCONTROL2, rx_data, rx_mask)); /* * If enabling prbs * disable micro tx squelch updates * unsquelch tx system * else * enable micro tx squelch updates */ SOC_IF_ERROR_RETURN(_phy_84328_micro_tx_squelch_enable(unit, port, !enable)); if (enable) { SOC_IF_ERROR_RETURN(_phy_84328_tx_squelch(unit, port, PHY84328_INTF_SIDE_SYS, 0)); } return SOC_E_NONE; } STATIC int _phy_84328_control_prbs_enable_get(int unit, soc_port_t port, uint32 *value) { uint16 tx_data, rx_data; uint16 tx_en, rx_en; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); /* Enable tx prbs in anaTxAcontrol7 1.c06b[6..5] */ SOC_IF_ERROR_RETURN(READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_ANATXACONTROL7, &tx_data)); /* Enable rx prbs in anaRxControl2 1.c0b6[6..5] */ SOC_IF_ERROR_RETURN(READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_ANARXCONTROL2, &rx_data)); /* Mask enable bits */ tx_data &= (PHY84328_DEV1_ANATXACONTROL7_SELECT_NEW_PRBS_MASK | PHY84328_DEV1_ANATXACONTROL7_NEW_PRBS_EN_MASK); rx_data &= (PHY84328_DEV1_ANARXCONTROL2_PRBS_SEL_RX_R_MASK | PHY84328_DEV1_ANARXCONTROL2_PRBS_EN_RX_R_MASK); tx_en = (tx_data & ((1 << PHY84328_DEV1_ANATXACONTROL7_SELECT_NEW_PRBS_SHIFT) | (1 << PHY84328_DEV1_ANATXACONTROL7_NEW_PRBS_EN_SHIFT))) == ((1 << PHY84328_DEV1_ANATXACONTROL7_SELECT_NEW_PRBS_SHIFT) | (1 << PHY84328_DEV1_ANATXACONTROL7_NEW_PRBS_EN_SHIFT)); rx_en = (rx_data & ((1 << PHY84328_DEV1_ANARXCONTROL2_PRBS_EN_RX_R_SHIFT) | (1 << PHY84328_DEV1_ANARXCONTROL2_PRBS_SEL_RX_R_SHIFT))) == ((1 << PHY84328_DEV1_ANARXCONTROL2_PRBS_EN_RX_R_SHIFT) | (1 << PHY84328_DEV1_ANARXCONTROL2_PRBS_SEL_RX_R_SHIFT)); *value = tx_en && rx_en; return SOC_E_NONE; } STATIC int _phy_84328_control_prbs_polynomial_get(int unit, soc_port_t port, uint32 *value) { uint16 data; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); *value = 0; /* tx prbs polynomial in anaTxAControl7 1.c06b */ SOC_IF_ERROR_RETURN(READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_ANATXACONTROL7, &data)); data &= PHY84328_SYS_DEV1_ANATXACONTROL7_LANE_PRBS_ORDER_NEW_B1_0_MASK; *value = data >> PHY84328_DEV1_ANATXACONTROL7_LANE_PRBS_ORDER_NEW_B1_0_SHIFT; return SOC_E_NONE; } STATIC int _phy_84328_control_prbs_tx_invert_data_get(int unit, soc_port_t port, uint32 *value) { uint16 data; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); *value = 0; /* tx invert in anaTxAControl7 1.c06b */ SOC_IF_ERROR_RETURN(READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_ANATXACONTROL7, &data)); *value = (data & (1 << PHY84328_SYS_DEV1_ANATXACONTROL7_NEW_PRBS_INV_SHIFT)) == (1 << PHY84328_SYS_DEV1_ANATXACONTROL7_NEW_PRBS_INV_SHIFT); return SOC_E_NONE; } STATIC int _phy_84328_control_prbs_rx_status_get(int unit, soc_port_t port, phy84328_intf_side_t side, uint32 *value) { uint16 data, tmp, lane_idx, lanes; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); if (PHY84328_SINGLE_PORT_MODE(pc)) { lanes = PHY84328_NUM_LANES; } else { lanes = 1; } *value = 0; for (lane_idx = 0; lane_idx < lanes; lane_idx++) { if (PHY84328_SINGLE_PORT_MODE(pc)) { /* Select the lane and side to access */ SOC_IF_ERROR_RETURN(_phy_84328_channel_select(unit, port, side, lane_idx)); } /* save anaRxControl 1.c0b1 in tmp*/ SOC_IF_ERROR_RETURN(READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_ANARXCONTROL, &tmp)); /* Select PRBS status in anaRxControl 1.c0b1 */ SOC_IF_ERROR_RETURN(MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_ANARXCONTROL, 7, PHY84328_DEV1_ANARXCONTROL_STATUS_SEL_MASK)); /* Check for rx PRBS lock in anaRxStatus 1.c0b0 */ SOC_IF_ERROR_RETURN(READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_ANARXSTATUS, &data)); /* Restore the old value into anaRxControl 1.c0b1 */ SOC_IF_ERROR_RETURN(WRITE_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_ANARXCONTROL, tmp)); if (data == PHY84328_DEV1_ANARXSTATUS_RXSTATUS_RX_PRBS_LOCK) { *value |= 0; /* locked and no errors */ } else if ((data & PHY84328_DEV1_ANARXSTATUS_RXSTATUS_RX_PRBS_LOCK) != PHY84328_DEV1_ANARXSTATUS_RXSTATUS_RX_PRBS_LOCK) { *value |= -1; /* no lock */ } else { /* locked with errors */ *value |= data & PHY84328_DEV1_ANARXSTATUS_RXSTATUS_RX_PRBS_ERR_MASK; } } /* Restore to default single port register access */ if (PHY84328_SINGLE_PORT_MODE(pc)) { SOC_IF_ERROR_RETURN(_phy_84328_channel_select(unit, port, PHY84328_INTF_SIDE_LINE, PHY84328_ALL_LANES)); } return SOC_E_NONE; } STATIC int _phy_84328_control_edc_mode_get(int unit, soc_port_t port, uint32 *value) { return SOC_E_UNAVAIL; } STATIC int _phy_84328_remote_loopback_set(int unit, soc_port_t port, int intf, uint32 enable) { phy_ctrl_t *pc; /* PHY software state */ uint16 data, mask; pc = EXT_PHY_SW_STATE(unit, port); /* * If enabling remote loopback * disable tx system side */ if (enable) { SOC_IF_ERROR_RETURN(_phy_84328_tx_enable(unit, port, PHY84328_INTF_SIDE_SYS, FALSE )); } /* Loopback requires 20-bit datapath */ FORCE_20BIT(pc) &= ~(FORCE_20BIT_LB); FORCE_20BIT(pc) |= enable ? FORCE_20BIT_LB : 0; SOC_IF_ERROR_RETURN(_phy_84328_data_path_check(unit, port)); /* * If disabling loopback * enable tx system side */ if (!enable) { SOC_IF_ERROR_RETURN(_phy_84328_tx_enable(unit, port, PHY84328_INTF_SIDE_SYS, TRUE )); } data = enable ? (1 << PHY84328_SYS_DEV1_ANATXACONTROL6_RLOOP_SHIFT) : 0; mask = PHY84328_SYS_DEV1_ANATXACONTROL6_RLOOP_MASK; SOC_IF_ERROR_RETURN( MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_ANATXACONTROL6, data, mask)); return SOC_E_NONE; } STATIC int _phy_84328_remote_loopback_get(int unit, soc_port_t port, int intf, uint32 *enable) { int rv; phy_ctrl_t *pc; /* PHY software state */ uint16 data; pc = EXT_PHY_SW_STATE(unit, port); rv = READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_ANATXACONTROL6, &data); *enable = (data & PHY84328_SYS_DEV1_ANATXACONTROL6_RLOOP_MASK) == PHY84328_SYS_DEV1_ANATXACONTROL6_RLOOP_MASK; return rv; } STATIC int _phy_84328_debug_info(int unit, soc_port_t port) { phy_ctrl_t *pc; phy_ctrl_t *int_pc; phy84328_intf_cfg_t *intf; phy84328_intf_cfg_t *line_intf; phy84328_intf_cfg_t *sys_intf; phy84328_counters_t *counters; phy84328_sw_rx_los_t *sw_rx_los; phy84328_link_mon_t *link_mon; phy84328_intf_side_t side, saved_side; char *rx_los_sts; soc_port_if_t iif; int lane; int ian, ian_done, ilink, ispeed; uint16 link_sts[PHY84328_NUM_LANES]; uint16 pol_sts[PHY84328_NUM_LANES]; uint16 pol_inv_sts[PHY84328_NUM_LANES]; uint16 tx_drv[PHY84328_NUM_LANES]; uint16 preemph_main[PHY84328_NUM_LANES]; uint16 preemph_pre_post[PHY84328_NUM_LANES]; uint16 preemph_manual[PHY84328_NUM_LANES]; uint16 data0, data1, data2, data3, data4, data5, data6, data7; uint32 die_temp; uint32 primary_port, offset; uint16 i = 0; pc = EXT_PHY_SW_STATE(unit, port); int_pc = INT_PHY_SW_STATE(unit, port); SOC_IF_ERROR_RETURN(phy_84328_control_port_get(unit, port, SOC_PHY_CONTROL_PORT_PRIMARY, &primary_port)); SOC_IF_ERROR_RETURN(phy_84328_control_port_get(unit, port, SOC_PHY_CONTROL_PORT_OFFSET, &offset)); /* Access line side registers */ saved_side = _phy_84328_intf_side_regs_get(unit, port); if (saved_side == PHY84328_INTF_SIDE_SYS) { _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_LINE); } /* firware rev: 1.c1f0 */ SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_VERSION, &data0)); /* micro enabled: 1.ca18 */ SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_GP_REG_0, &data1)); /* die temperature in 1.c1fd */ SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_TEMPERATURE, &data2)); die_temp = 418 - (((data2 & PHY84328_DEV1_TEMPERATURE_TEMPERATURE_MASK) * 5556) / 10000); sw_rx_los = &(SW_RX_LOS(pc)); link_mon = &(LINK_MON(pc)); rx_los_sts = "dis"; if (sw_rx_los->cur_enable) { rx_los_sts = "sw"; } else if (FW_RX_LOS(pc)) { rx_los_sts = "fw"; } LOG_CLI((BSL_META_U(unit, "Port %-2d: rev=%d:%d, chiprev=%04x, " "micro ver(1.%04x)=%04x, micro(1.%04x)=%04x, die temp=%d(C)%s\n" " pri:offs=%d:%d, mdio=0x%x, datapath=%d, " "rxLOS=%s, mod auto=%s, sync=%s, link mon=%s\n"), port, phy84328_maj_rev, phy84328_min_rev, DEVREV(pc), PHY84328_DEV1_VERSION, data0, PHY84328_DEV1_GP_REG_0, data1, die_temp, data2 & PHY84328_DEV1_TEMPERATURE_FORCE_TEMPERATURE_MASK ? "(forced)" : "", primary_port, offset, pc->phy_id, CUR_DATAPATH(pc) == PHY84328_DATAPATH_20 ? 20 : 4, rx_los_sts, MOD_AUTO_DETECT(pc) ? "en" : "dis", SYNC_INIT(pc) ? "en" : "dis", link_mon->cur_enable ? "en" : "dis")); /* Single PMD control: 1.ca86 */ SOC_IF_ERROR_RETURN(READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_SINGLE_PMD_CTRL, &data0)); /* Broadcast control: 1.c8fe */ SOC_IF_ERROR_RETURN(READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_BROADCAST_CTRL, &data1)); /* AnaPllStatus 1.c050 */ SOC_IF_ERROR_RETURN(READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_ANAPLLASTATUS, &data2)); /* AN 7.0000 */ SOC_IF_ERROR_RETURN(READ_PHY84328_MMF_AN_REG(unit, pc, PHY84328_DEV7_AN_CONTROL_REGISTER, &data3)); /* AN done 1.0097 */ SOC_IF_ERROR_RETURN(READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_BASE_R_PMD_STATUS_REGISTER, &data4)); /* Regulator control 1.c850 */ SOC_IF_ERROR_RETURN(READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_REGUALTOR_CTRL, &data5)); /* Global intf type/speed - driver csr: 1.c841 */ SOC_IF_ERROR_RETURN(READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_GP_REGISTER_1, &data6)); /* Micro csr 1.c843 */ SOC_IF_ERROR_RETURN(READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_GP_REGISTER_3, &data7)); LOG_CLI((BSL_META_U(unit, " PMD(1.%04x)=%04x, bcctrl(1.%04x)=%04x, " "pll(1.%04x)=%04x, an(7.%04x/1.%04x)=%04x/%04x\n" " regulator(1.%04x)=%04x, drvcsr(1.%04x)=%04x, " "ucsr(1.%04x)=%04x\n"), PHY84328_DEV1_SINGLE_PMD_CTRL, data0, PHY84328_DEV1_BROADCAST_CTRL, data1, PHY84328_DEV1_ANAPLLASTATUS, data2, PHY84328_DEV7_AN_CONTROL_REGISTER, PHY84328_SYS_DEV1_BASE_R_PMD_STATUS_REGISTER, data3, data4, PHY84328_DEV1_REGUALTOR_CTRL, data5, PHY84328_DEV1_GP_REGISTER_1, data6, PHY84328_DEV1_GP_REGISTER_3, data7)); counters = &(COUNTERS(pc)); LOG_CLI((BSL_META_U(unit, " Counters: link down=%d, intf updates=%d, " "swRxLOS restarts=%d, no cdr=%d, micro nopause=%d\n" " retry internal=%d, intf chk(speed=%d, " "type=%d, sel=%d)\n"), counters->link_down, counters->intf_updates, sw_rx_los->restarts, counters->no_cdr, counters->micro_nopause, counters->retry_serdes_link, counters->speed_chk_err, counters->intf_chk_err, counters->side_sel_err)); /* Interfaces: software, hardware, internal serdes */ line_intf = &(LINE_INTF(pc)); sys_intf = &(SYS_INTF(pc)); for (side = PHY84328_INTF_SIDE_LINE; side <= PHY84328_INTF_SIDE_SYS; side++) { _phy_84328_intf_side_regs_select(unit, port, side); /* control: 1.0000 */ SOC_IF_ERROR_RETURN(READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_PMD_CONTROL_REGISTER, &data1)); /* PMD type: 1.0007 */ SOC_IF_ERROR_RETURN(READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_PMD_CONTROL_2_REGISTER, &data2)); /* Loopback 1.c06a */ SOC_IF_ERROR_RETURN(READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_ANATXACONTROL6, &data3)); /* Tx disable 1.c066 */ SOC_IF_ERROR_RETURN(READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_ANATXACONTROL2, &data4)); /* Tx disable 1.c06a */ SOC_IF_ERROR_RETURN(READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_ANATXACONTROL6, &data5)); if (PHY84328_SINGLE_PORT_MODE(pc)) { if (side == PHY84328_INTF_SIDE_SYS) { PHY_84328_MICRO_PAUSE(unit, port, ""); } for (lane = 0; lane < PHY84328_NUM_LANES; lane++) { /* Select the lane and side to write */ SOC_IF_ERROR_RETURN(_phy_84328_channel_select(unit, port, side, lane)); /* Link: 1.c0b0 */ SOC_IF_ERROR_RETURN(READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_ANARXSTATUS, &(link_sts[lane]))); if (CUR_DATAPATH(pc) == PHY84328_DATAPATH_20) { /* Polarity setting: 1.c061 */ SOC_IF_ERROR_RETURN(READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_ANATXACONTROL, &(pol_sts[lane]))); } else { /* Polarity setting: 1.c068 */ SOC_IF_ERROR_RETURN(READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_ANATXACONTROL4, &(pol_sts[lane]))); } if (side == PHY84328_INTF_SIDE_LINE) { /* Polarity inversion setting: 1.c0ba[3:2] in the line side */ SOC_IF_ERROR_RETURN(READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_GP_REGISTER_RX_INV, &(pol_inv_sts[lane]))); } /* TX driver: 1.c065 */ SOC_IF_ERROR_RETURN(READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_ANATXACONTROL1, &(tx_drv[lane]))); /* Preemphasis manual: 1.c192[15] */ SOC_IF_ERROR_RETURN(READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_XFI_AFE_CTL2, &(preemph_manual[lane]))); /* Preemphasis main: 1.c066[15:11] */ SOC_IF_ERROR_RETURN(READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_ANATXACONTROL2, &(preemph_main[lane]))); /* Preemphasis pre post: 1.c067 */ SOC_IF_ERROR_RETURN(READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_ANATXACONTROL3, &(preemph_pre_post[lane]))); } /* Back to default channel selection through lane 0 */ SOC_IF_ERROR_RETURN(_phy_84328_channel_select(unit, port, side, PHY84328_ALL_LANES)); _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_LINE); if (side == PHY84328_INTF_SIDE_SYS) { PHY_84328_MICRO_RESUME(unit, port); } } else { /* Link: 1.c0b0 */ SOC_IF_ERROR_RETURN(READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_ANARXSTATUS, &(link_sts[i]))); if (CUR_DATAPATH(pc) == PHY84328_DATAPATH_20) { /* Polarity setting: 1.c061 */ SOC_IF_ERROR_RETURN(READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_ANATXACONTROL, &(pol_sts[i]))); } else { /* Polarity setting: 1.c068 */ SOC_IF_ERROR_RETURN(READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_ANATXACONTROL4, &(pol_sts[i]))); } if (side == PHY84328_INTF_SIDE_LINE) { /* Polarity inversion setting: 1.c0ba[3:2] in the line side */ SOC_IF_ERROR_RETURN(READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_GP_REGISTER_RX_INV, &(pol_inv_sts[i]))); } /* TX driver: 1.c065 */ SOC_IF_ERROR_RETURN(READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_ANATXACONTROL1, &(tx_drv[i]))); /* Preemphasis manual: 1.c192[15] */ SOC_IF_ERROR_RETURN(READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_XFI_AFE_CTL2, &(preemph_manual[i]))); /* Preemphasis main: 1.c066[15:11] */ SOC_IF_ERROR_RETURN(READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_ANATXACONTROL2, &(preemph_main[i]))); /* Preemphasis pre post: 1.c067 */ SOC_IF_ERROR_RETURN(READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_ANATXACONTROL3, &(preemph_pre_post[i]))); } intf = (side == PHY84328_INTF_SIDE_LINE) ? line_intf : sys_intf; if (PHY84328_SINGLE_PORT_MODE(pc)) { LOG_CLI((BSL_META_U(unit, " %s: type=%s, speed=%d, forced cl72=%d, " "mode(1.%04x)=%04x\n" " pmdtype(1.%04x)=%04x, " "lb(1.%04x)=%04x, txdis(1.%04x)=%04x/(1.%04x)=%04x\n" " link(1.%04x) : " "(ln0=%04x, ln1=%04x, ln2=%04x, ln3=%04x)\n" " pol(1.%04x) : " "(ln0=%04x, ln1=%04x, ln2=%04x, ln3=%04x)\n"), (side == PHY84328_INTF_SIDE_LINE) ? "Line " : "System ", phy84328_intf_names[intf->type], intf->speed, SYS_FORCED_CL72(pc), PHY84328_DEV1_PMD_CONTROL_REGISTER, data1, PHY84328_DEV1_PMD_CONTROL_2_REGISTER, data2, PHY84328_SYS_DEV1_ANATXACONTROL6, data3, PHY84328_DEV1_ANATXACONTROL2, data4, PHY84328_DEV1_ANATXACONTROL6, data5, PHY84328_DEV1_ANARXSTATUS, link_sts[0], link_sts[1], link_sts[2], link_sts[3], CUR_DATAPATH(pc) == PHY84328_DATAPATH_20 ? PHY84328_DEV1_ANATXACONTROL : PHY84328_DEV1_ANATXACONTROL4, pol_sts[0], pol_sts[1], pol_sts[2], pol_sts[3])); if (side == PHY84328_INTF_SIDE_LINE) { LOG_CLI((BSL_META_U(unit, " pol_inv(1.%04x) : " "(ln0=%04x, ln1=%04x, ln2=%04x, ln3=%04x)\n"), PHY84328_DEV1_GP_REGISTER_RX_INV, pol_inv_sts[0], pol_inv_sts[1], pol_inv_sts[2], pol_inv_sts[3])); } LOG_CLI((BSL_META_U(unit, " txdrv(1.%04x) : " "(ln0=%04x, ln1=%04x, ln2=%04x, ln3=%04x)\n" " preman(1.%04x) : " "(ln0=%04x, ln1=%04x, ln2=%04x, ln3=%04x)\n" " premain(1.%04x) : " "(ln0=%04x, ln1=%04x, ln2=%04x, ln3=%04x)\n" " preprepos(1.%04x) : " "(ln0=%04x, ln1=%04x, ln2=%04x, ln3=%04x)\n"), PHY84328_DEV1_ANATXACONTROL1, tx_drv[0], tx_drv[1], tx_drv[2], tx_drv[3], PHY84328_SYS_DEV1_XFI_AFE_CTL2, preemph_manual[0], preemph_manual[1], preemph_manual[2], preemph_manual[3], PHY84328_DEV1_ANATXACONTROL2, preemph_main[0], preemph_main[1], preemph_main[2], preemph_main[3], PHY84328_DEV1_ANATXACONTROL3, preemph_pre_post[0], preemph_pre_post[1], preemph_pre_post[2], preemph_pre_post[3])); } else { LOG_CLI((BSL_META_U(unit, "Lane:%d: %s: type=%s, speed=%d, " "forced cl72=%d, mode(1.%04x)=%04x\n" " pmdtype(1.%04x)=%04x, " "lb(1.%04x)=%04x, txdis(1.%04x)=%04x/(1.%04x)=%04x\n" " link(1.%04x)=%04x, " "txdrv(1.%04x)=%04x, pol(1.%04x)=%04x"), i, (side == PHY84328_INTF_SIDE_LINE) ? "Line " : "System ", phy84328_intf_names[intf->type], intf->speed, SYS_FORCED_CL72(pc), PHY84328_DEV1_PMD_CONTROL_REGISTER, data1, PHY84328_DEV1_PMD_CONTROL_2_REGISTER, data2, PHY84328_SYS_DEV1_ANATXACONTROL6, data3, PHY84328_DEV1_ANATXACONTROL2, data4, PHY84328_DEV1_ANATXACONTROL6, data5, PHY84328_DEV1_ANARXSTATUS, link_sts[i], PHY84328_DEV1_ANATXACONTROL1, tx_drv[i], CUR_DATAPATH(pc) == PHY84328_DATAPATH_20 ? PHY84328_DEV1_ANATXACONTROL : PHY84328_DEV1_ANATXACONTROL4, pol_sts[i])); if (side == PHY84328_INTF_SIDE_LINE) { LOG_CLI((BSL_META_U(unit, ", pol_inv(1.%04x)=%04x"), PHY84328_DEV1_GP_REGISTER_RX_INV, pol_inv_sts[i])); } LOG_CLI((BSL_META_U(unit, "\n" " preman(1.%04x)=%04x," "premain(1.%04x)=%04x, preprepos(1.%04x)=%04x\n"), PHY84328_SYS_DEV1_XFI_AFE_CTL2, preemph_manual[i], PHY84328_DEV1_ANATXACONTROL2, preemph_main[i], PHY84328_DEV1_ANATXACONTROL3, preemph_pre_post[i])); } } _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_LINE); if (int_pc) { int lb; SOC_IF_ERROR_RETURN(PHY_INTERFACE_GET(int_pc->pd, unit, port, &iif)); SOC_IF_ERROR_RETURN(PHY_LINK_GET(int_pc->pd, unit, port, &ilink)); SOC_IF_ERROR_RETURN(_phy_84328_lb_get(unit, port, &lb)); if (lb) { /* Clear the sticky bit if in loopback */ SOC_IF_ERROR_RETURN(PHY_LINK_GET(int_pc->pd, unit, port, &ilink)); } SOC_IF_ERROR_RETURN(PHY_SPEED_GET(int_pc->pd, unit, port, &ispeed)); SOC_IF_ERROR_RETURN(PHY_AUTO_NEGOTIATE_GET(int_pc->pd, unit, port, &ian, &ian_done)); LOG_CLI((BSL_META_U(unit, " Internal: type=%s, speed=%d, link=%d, an=%d\n===\n"), phy84328_intf_names[iif], ispeed, ilink, ian)); } if (saved_side == PHY84328_INTF_SIDE_SYS) { _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_SYS); } return SOC_E_NONE; } STATIC int _phy_84328_control_driver_supply_set(int unit, soc_port_t port, phy84328_intf_side_t side, uint32 value) { soc_port_phy_control_driver_supply_t ds; uint16 tx_mode = 0; ds = (soc_port_phy_control_driver_supply_t) value; switch (ds) { case SOC_PHY_CONTROL_DRIVER_SUPPLY_1_5V_1_0V: tx_mode = 4; break; case SOC_PHY_CONTROL_DRIVER_SUPPLY_1_0V_700MV: tx_mode = 0; break; case SOC_PHY_CONTROL_DRIVER_SUPPLY_1_5V_700MV: tx_mode = 1; break; default: return SOC_E_PARAM; } return _phy_84328_tx_mode_set(unit, port, side, tx_mode); } STATIC int _phy_84328_control_driver_supply_get(int unit, soc_port_t port, phy84328_intf_side_t side, uint32 *value) { uint16 tx_mode = 0; soc_port_phy_control_driver_supply_t ds; SOC_IF_ERROR_RETURN(_phy_84328_tx_mode_get(unit, port, side, &tx_mode)); switch (tx_mode) { case 4: ds = SOC_PHY_CONTROL_DRIVER_SUPPLY_1_5V_1_0V; break; case 0: ds = SOC_PHY_CONTROL_DRIVER_SUPPLY_1_0V_700MV; break; case 1: ds = SOC_PHY_CONTROL_DRIVER_SUPPLY_1_5V_700MV; break; default: /* The value is not reliable */ *value = 0; return SOC_E_UNAVAIL; } *value = (uint32) ds; return SOC_E_NONE; } STATIC int _phy_84328_sw_rx_los_control_set(int unit, soc_port_t port, uint32 value) { phy_ctrl_t *pc= EXT_PHY_SW_STATE(unit, port); phy84328_sw_rx_los_t *sw_rx_los = &(SW_RX_LOS(pc)); #ifdef BCM_WARM_BOOT_SUPPORT if ( SOC_WARM_BOOT(unit) || SOC_IS_RELOADING(unit) ) { return SOC_E_NONE; } /* preserve SW RxLOS status in register 1.0xC01A for warmboot support */ SOC_IF_ERROR_RETURN( _phy_84328_preserve_sw_rx_los(unit, port, value) ); #endif sw_rx_los->cfg_enable = value; sw_rx_los->cur_enable = value; if (value) { sw_rx_los->sys_link = 0; sw_rx_los->state = PHY84328_SW_RX_LOS_RESET; sw_rx_los->link_status = 0; sw_rx_los->link_no_pcs = 0; sw_rx_los->restarts = 0; #ifdef SW_RX_LOS_FLAP_CHECK sw_rx_los->fault_report_dis = 0; if (sw_rx_los->macd == NULL) { SOC_IF_ERROR_RETURN(soc_mac_probe(unit, port, &(sw_rx_los->macd))); } #endif } return SOC_E_NONE; } STATIC int _phy_84328_fw_rx_los_control_set(int unit, soc_port_t port, uint32 value) { int lane_start, lane_end, lane; int fw_rx_los_en_data, fw_rx_los_en_mask; phy_ctrl_t *pc= EXT_PHY_SW_STATE(unit, port); uint32 lane_reg[PHY84328_NUM_LANES] = /* per lane registers timeout */ { 0xca99, 0xca9b, 0xca9d, 0xca9f }; FW_RX_LOS(pc) = value; fw_rx_los_en_mask = (1 << 15) | (1 << 14); if (value) { if (PHY84328_SINGLE_PORT_MODE(pc)) { lane_start = 0; lane_end = PHY84328_NUM_LANES; } else { lane_start = pc->phy_id & 0x3; lane_end = lane_start + 1; } for (lane = lane_start; lane < lane_end; lane++) { /* Program the timeout value */ SOC_IF_ERROR_RETURN( MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, lane_reg[lane], 0xffff, 0xffff)); } fw_rx_los_en_data = (1 << 15) | (1 << 14); } else { fw_rx_los_en_data = 0; } SOC_IF_ERROR_RETURN( MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, 0xc480, fw_rx_los_en_data, fw_rx_los_en_mask)); if (value){ /* Update interface type/speed */ SOC_IF_ERROR_RETURN(_phy_84328_intf_line_sys_update(unit, port)); } return SOC_E_NONE; } STATIC int _phy_84328_rx_los_control_set(int unit, soc_port_t port, uint32 value) { phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); int rv = SOC_E_NONE; int rv2 = SOC_E_NONE; switch (value) { case SOC_PHY_CONTROL_RX_LOS_NONE: rv = _phy_84328_sw_rx_los_control_set(unit, port, 0); rv2 = _phy_84328_fw_rx_los_control_set(unit, port, 0); rv = (rv == SOC_E_NONE) ? rv2 : rv; break; case SOC_PHY_CONTROL_RX_LOS_FIRMWARE: if (DEVREV(pc) == 0x00a0) { rv = _phy_84328_sw_rx_los_control_set(unit, port, 1); } else { rv = _phy_84328_sw_rx_los_control_set(unit, port, 0); rv2 = _phy_84328_fw_rx_los_control_set(unit, port, 1); rv = (rv == SOC_E_NONE) ? rv2 : rv; } break; case SOC_PHY_CONTROL_RX_LOS_SOFTWARE: default: if (DEVREV(pc) == 0x00a0) { rv = _phy_84328_sw_rx_los_control_set(unit, port, 1); } else { rv = _phy_84328_fw_rx_los_control_set(unit, port, 0); rv2 = _phy_84328_sw_rx_los_control_set(unit, port, 1); rv = (rv == SOC_E_NONE) ? rv2 : rv; } break; } return rv; } STATIC int _phy_84328_rx_los_control_get(int unit, soc_port_t port, uint32 *value) { phy84328_sw_rx_los_t *sw_rx_los; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); sw_rx_los = &(SW_RX_LOS(pc)); if (sw_rx_los->cur_enable) { *value = SOC_PHY_CONTROL_RX_LOS_SOFTWARE; } else if (FW_RX_LOS(pc)) { *value = SOC_PHY_CONTROL_RX_LOS_FIRMWARE; } else { *value = SOC_PHY_CONTROL_RX_LOS_NONE; } return SOC_E_NONE; } STATIC int _phy_84328_mod_auto_detect_set(int unit, soc_port_t port, uint32 value) { phy_ctrl_t *pc; uint16 data; uint16 rddata; uint16 count = 0; uint16 mask; pc = EXT_PHY_SW_STATE(unit, port); mask = PHY84328_DEV1_GP_REG_0_ENABLE_SFP_MOD_DETECT_MASK; data = value ? mask : 0; SOC_IF_ERROR_RETURN( MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_GP_REG_0, data, mask)); if (!value) { /* Request is disabling mod auto detect, need to wait until I2CM FSM becomes IDLE */ /* Wait approx for 325 ms */ while (count < I2CM_IDLE_WAIT_COUNT){ SOC_IF_ERROR_RETURN( READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_I2C_CONTROL_REGISTER, &rddata)); if ((rddata & 0xC) == 0) { break; } count ++; sal_usleep(I2CM_IDLE_WAIT_CHUNK * 1000); } if (count >= I2CM_IDLE_WAIT_COUNT) { return SOC_E_BUSY; } } /* Update the global database */ MOD_AUTO_DETECT(pc) = value ? 1:0; return SOC_E_NONE; } STATIC int _phy_84328_mod_auto_detect_get(int unit, soc_port_t port, uint32 *value) { phy_ctrl_t *pc; uint16 data; pc = EXT_PHY_SW_STATE(unit, port); SOC_IF_ERROR_RETURN( READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_GP_REG_0, &data)); if( data & PHY84328_DEV1_GP_REG_0_ENABLE_SFP_MOD_DETECT_MASK ) { *value = 1; } else { *value = 0; } return SOC_E_NONE; } STATIC int _phy_84328_force_cl72_config(int unit, soc_port_t port, uint32 enable) { uint16 intf_side = 0; uint16 data = 0 , mask = 0; phy_ctrl_t *pc; /* PHY software state */ pc = EXT_PHY_SW_STATE(unit, port); intf_side = (pc->flags & PHYCTRL_SYS_SIDE_CTRL) ? PHY84328_INTF_SIDE_SYS : PHY84328_INTF_SIDE_LINE; if (intf_side == PHY84328_INTF_SIDE_SYS) { data = enable ? PHY84328_DEV1_GP_REGISTER_1_SYSTEM_FORCED_CL72_MODE_MASK : 0; mask = PHY84328_DEV1_GP_REGISTER_1_SYSTEM_FORCED_CL72_MODE_MASK; } else { data = enable ? PHY84328_DEV1_GP_REGISTER_1_LINE_FORCED_CL72_MODE_MASK : 0; mask = PHY84328_DEV1_GP_REGISTER_1_LINE_FORCED_CL72_MODE_MASK; } data |= PHY84328_DEV1_GP_REGISTER_1_FINISH_CHANGE_MASK; mask |= PHY84328_DEV1_GP_REGISTER_1_FINISH_CHANGE_MASK; SOC_IF_ERROR_RETURN( _phy_84328_intf_update(unit, port, data, mask)); return SOC_E_NONE; } STATIC int _phy_84328_force_cl72_status(int unit, soc_port_t port, uint32 *value) { uint16 intf_side = 0, data = 0; phy_ctrl_t *pc; /* PHY software state */ pc = EXT_PHY_SW_STATE(unit, port); intf_side = (pc->flags & PHYCTRL_SYS_SIDE_CTRL) ? PHY84328_INTF_SIDE_SYS : PHY84328_INTF_SIDE_LINE; SOC_IF_ERROR_RETURN( READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_GP_REGISTER_3, &data)); *value = 0; if (intf_side == PHY84328_INTF_SIDE_SYS) { *value = (data & PHY84328_DEV1_GP_REGISTER_1_SYSTEM_FORCED_CL72_MODE_MASK) ? 1 : 0; } else { *value = (data & PHY84328_DEV1_GP_REGISTER_1_LINE_FORCED_CL72_MODE_MASK) ? 1 : 0; } return SOC_E_NONE; } /* * Function: * _phy_84328_control_set * Purpose: * Configure PHY device specific control fucntion. * Parameters: * unit - StrataSwitch unit #. * port - StrataSwitch port #. * type - Control to update * value - New setting for the control * Returns: * SOC_E_NONE */ STATIC int _phy_84328_control_set(int unit, soc_port_t port, int intf, int lane, soc_phy_control_t type, uint32 value) { phy_ctrl_t *pc; /* PHY software state */ int rv; pc = EXT_PHY_SW_STATE(unit, port); PHY_CONTROL_TYPE_CHECK(type); rv = SOC_E_UNAVAIL; if (intf == PHY_DIAG_INTF_SYS) { _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_SYS); pc->flags |= PHYCTRL_SYS_SIDE_CTRL ; } switch (type) { case SOC_PHY_CONTROL_PREEMPHASIS: /* fall through */ case SOC_PHY_CONTROL_PREEMPHASIS_LANE0: /* fall through */ case SOC_PHY_CONTROL_PREEMPHASIS_LANE1: /* fall through */ case SOC_PHY_CONTROL_PREEMPHASIS_LANE2: /* fall through */ case SOC_PHY_CONTROL_PREEMPHASIS_LANE3: rv = _phy_84328_control_preemphasis_set(unit, port, type, (pc->flags & PHYCTRL_SYS_SIDE_CTRL) ? PHY84328_INTF_SIDE_SYS : PHY84328_INTF_SIDE_LINE, value); break; case SOC_PHY_CONTROL_DRIVER_CURRENT: /* fall through */ case SOC_PHY_CONTROL_DRIVER_CURRENT_LANE0: /* fall through */ case SOC_PHY_CONTROL_DRIVER_CURRENT_LANE1: /* fall through */ case SOC_PHY_CONTROL_DRIVER_CURRENT_LANE2: /* fall through */ case SOC_PHY_CONTROL_DRIVER_CURRENT_LANE3: /* fall through */ case SOC_PHY_CONTROL_PRE_DRIVER_CURRENT: /* fall through */ case SOC_PHY_CONTROL_PRE_DRIVER_CURRENT_LANE0: /* fall through */ case SOC_PHY_CONTROL_PRE_DRIVER_CURRENT_LANE1: /* fall through */ case SOC_PHY_CONTROL_PRE_DRIVER_CURRENT_LANE2: /* fall through */ case SOC_PHY_CONTROL_PRE_DRIVER_CURRENT_LANE3: rv = _phy_84328_control_tx_driver_set(unit, port, type, (pc->flags & PHYCTRL_SYS_SIDE_CTRL) ? PHY84328_INTF_SIDE_SYS : PHY84328_INTF_SIDE_LINE, value); break; case SOC_PHY_CONTROL_EDC_MODE: rv = _phy_84328_control_edc_mode_set(unit,port,value); break; case SOC_PHY_CONTROL_CLOCK_ENABLE: rv = _phy_84328_control_recovery_clock_set(unit,port,value); break; case SOC_PHY_CONTROL_CLOCK_FREQUENCY: rv = _phy_84328_control_recovery_clock_freq_set(unit,port,value); break; case SOC_PHY_CONTROL_PRBS_POLYNOMIAL: rv = _phy_84328_control_prbs_polynomial_set(unit, port, value, TRUE); if (SOC_SUCCESS(rv)) { rv = _phy_84328_control_prbs_polynomial_set(unit, port,value, FALSE); } break; case SOC_PHY_CONTROL_PRBS_TX_INVERT_DATA: rv = _phy_84328_control_prbs_tx_invert_data_set(unit, port, value); if (SOC_SUCCESS(rv)) { rv = _phy_84328_control_prbs_rx_invert_data_set(unit, port, value); } break; case SOC_PHY_CONTROL_PRBS_TX_ENABLE: /* fall through */ case SOC_PHY_CONTROL_PRBS_RX_ENABLE: /* tx/rx is enabled at the same time. no seperate control */ rv = _phy_84328_control_prbs_enable_set(unit, port, value); break; case SOC_PHY_CONTROL_LOOPBACK_REMOTE: rv = _phy_84328_remote_loopback_set(unit, port, intf, value); break; case SOC_PHY_CONTROL_PORT_PRIMARY: rv = soc_phyctrl_primary_set(unit, port, (soc_port_t)value); break; case SOC_PHY_CONTROL_PORT_OFFSET: rv = soc_phyctrl_offset_set(unit, port, (int)value); break; case SOC_PHY_CONTROL_SOFTWARE_RX_LOS: rv = _phy_84328_rx_los_control_set(unit, port, value); break; case SOC_PHY_CONTROL_DUMP: /* in control set for consistency with other drivers */ rv = _phy_84328_debug_info(unit, port); break; case SOC_PHY_CONTROL_DRIVER_SUPPLY: rv = _phy_84328_control_driver_supply_set(unit, port, (pc->flags & PHYCTRL_SYS_SIDE_CTRL) ? PHY84328_INTF_SIDE_SYS : PHY84328_INTF_SIDE_LINE, value); break; case SOC_PHY_CONTROL_RX_SEQ_TOGGLE: /* value is not used since this is always a toggle ->1->0 */ rv = _phy_84328_do_rxseq_restart(unit, port, (pc->flags & PHYCTRL_SYS_SIDE_CTRL) ? PHY84328_INTF_SIDE_SYS : PHY84328_INTF_SIDE_LINE); break; case SOC_PHY_CONTROL_MOD_AUTO_DETECT_ENABLE: rv = _phy_84328_mod_auto_detect_set(unit,port,value); break; case SOC_PHY_CONTROL_CL72: rv = _phy_84328_force_cl72_config(unit, port, value); break; case SOC_PHY_CONTROL_PCS_MODE: { phy_ctrl_t *int_pc; phy84328_intf_cfg_t *line_intf; rv = SOC_E_NONE; int_pc = INT_PHY_SW_STATE(unit, port); line_intf = &(LINE_INTF(pc)); if (int_pc) { SOC_IF_ERROR_RETURN( PHY_CONTROL_SET(int_pc->pd, unit, port, type, value)); SOC_IF_ERROR_RETURN(PHY_SPEED_SET(int_pc->pd, unit, port, line_intf->speed)); } else { rv = SOC_E_INTERNAL; } } break; default: rv = SOC_E_UNAVAIL; break; } if (intf == PHY_DIAG_INTF_SYS) { /* if it is targeted to the system side, switch back */ _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_LINE); pc->flags &= ~PHYCTRL_SYS_SIDE_CTRL ; } return rv; } STATIC int phy_84328_control_port_set(int unit, soc_port_t port, soc_phy_control_t type, uint32 value) { SOC_IF_ERROR_RETURN(_phy_84328_control_set(unit, port, PHY_DIAG_INTF_LINE, PHY_DIAG_LN_DFLT, type, value)); return SOC_E_NONE; } /* * Function: * phy_84328_control_get * Purpose: * Get current control settign of the PHY. * Parameters: * unit - StrataSwitch unit #. * port - StrataSwitch port #. * type - Control to update * value - (OUT)Current setting for the control * Returns: * SOC_E_NONE */ STATIC int _phy_84328_control_get(int unit, soc_port_t port, int intf, int lane, soc_phy_control_t type, uint32 *value) { phy_ctrl_t *pc; /* PHY software state */ int rv, offset; soc_port_t primary; pc = EXT_PHY_SW_STATE(unit, port); PHY_CONTROL_TYPE_CHECK(type); if (intf == PHY_DIAG_INTF_SYS) { _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_SYS); pc->flags |= PHYCTRL_SYS_SIDE_CTRL ; } rv = SOC_E_UNAVAIL; switch(type) { case SOC_PHY_CONTROL_PREEMPHASIS: /* fall through */ case SOC_PHY_CONTROL_PREEMPHASIS_LANE0: /* fall through */ case SOC_PHY_CONTROL_PREEMPHASIS_LANE1: /* fall through */ case SOC_PHY_CONTROL_PREEMPHASIS_LANE2: /* fall through */ case SOC_PHY_CONTROL_PREEMPHASIS_LANE3: rv = _phy_84328_control_preemphasis_get(unit, port, type, (pc->flags & PHYCTRL_SYS_SIDE_CTRL) ? PHY84328_INTF_SIDE_SYS : PHY84328_INTF_SIDE_LINE, value); break; case SOC_PHY_CONTROL_DRIVER_CURRENT: /* fall through */ case SOC_PHY_CONTROL_DRIVER_CURRENT_LANE0: /* fall through */ case SOC_PHY_CONTROL_DRIVER_CURRENT_LANE1: /* fall through */ case SOC_PHY_CONTROL_DRIVER_CURRENT_LANE2: /* fall through */ case SOC_PHY_CONTROL_DRIVER_CURRENT_LANE3: /* fall through */ case SOC_PHY_CONTROL_PRE_DRIVER_CURRENT: /* fall through */ case SOC_PHY_CONTROL_PRE_DRIVER_CURRENT_LANE0: /* fall through */ case SOC_PHY_CONTROL_PRE_DRIVER_CURRENT_LANE1: /* fall through */ case SOC_PHY_CONTROL_PRE_DRIVER_CURRENT_LANE2: /* fall through */ case SOC_PHY_CONTROL_PRE_DRIVER_CURRENT_LANE3: rv = _phy_84328_control_tx_driver_get(unit, port, type, (pc->flags & PHYCTRL_SYS_SIDE_CTRL) ? PHY84328_INTF_SIDE_SYS : PHY84328_INTF_SIDE_LINE, value); break; case SOC_PHY_CONTROL_EDC_MODE: rv = _phy_84328_control_edc_mode_get(unit,port,value); break; case SOC_PHY_CONTROL_CLOCK_ENABLE: rv = SOC_E_NONE; break; case SOC_PHY_CONTROL_PRBS_POLYNOMIAL: rv = _phy_84328_control_prbs_polynomial_get(unit, port, value); break; case SOC_PHY_CONTROL_PRBS_TX_INVERT_DATA: rv = _phy_84328_control_prbs_tx_invert_data_get(unit, port, value); break; case SOC_PHY_CONTROL_PRBS_TX_ENABLE: /* fall through */ case SOC_PHY_CONTROL_PRBS_RX_ENABLE: rv = _phy_84328_control_prbs_enable_get(unit, port, value); break; case SOC_PHY_CONTROL_PRBS_RX_STATUS: rv = _phy_84328_control_prbs_rx_status_get(unit, port, (pc->flags & PHYCTRL_SYS_SIDE_CTRL) ? PHY84328_INTF_SIDE_SYS : PHY84328_INTF_SIDE_LINE, value); break; case SOC_PHY_CONTROL_CLOCK_FREQUENCY: break; case SOC_PHY_CONTROL_PORT_PRIMARY: SOC_IF_ERROR_RETURN (soc_phyctrl_primary_get(unit, port, &primary)); *value = (uint32) primary; rv = SOC_E_NONE; break; case SOC_PHY_CONTROL_PORT_OFFSET: SOC_IF_ERROR_RETURN (soc_phyctrl_offset_get(unit, port, &offset)); *value = (uint32) offset; rv = SOC_E_NONE; break; case SOC_PHY_CONTROL_LOOPBACK_REMOTE: rv = _phy_84328_remote_loopback_get(unit, port, intf, value); break; case SOC_PHY_CONTROL_SOFTWARE_RX_LOS: rv = _phy_84328_rx_los_control_get(unit, port, value); break; case SOC_PHY_CONTROL_DUMP: *value = 0; rv = SOC_E_NONE; break; case SOC_PHY_CONTROL_DRIVER_SUPPLY: rv = _phy_84328_control_driver_supply_get(unit, port, (pc->flags & PHYCTRL_SYS_SIDE_CTRL) ? PHY84328_INTF_SIDE_SYS : PHY84328_INTF_SIDE_LINE, value); break; case SOC_PHY_CONTROL_RX_SEQ_DONE: rv = _phy_84328_rx_seq_done_get(unit, port, (pc->flags & PHYCTRL_SYS_SIDE_CTRL) ? PHY84328_INTF_SIDE_SYS : PHY84328_INTF_SIDE_LINE, value); break; case SOC_PHY_CONTROL_MOD_AUTO_DETECT_ENABLE: rv = _phy_84328_mod_auto_detect_get(unit, port, value); break; case SOC_PHY_CONTROL_CL72_STATUS: rv = _phy_84328_force_cl72_status(unit, port, value); break; case SOC_PHY_CONTROL_PCS_MODE: { phy_ctrl_t *int_pc; int_pc = INT_PHY_SW_STATE(unit, port); if (int_pc) { rv = PHY_CONTROL_GET(int_pc->pd, unit, port, type, value); } else { rv = SOC_E_INTERNAL; } } break; default: rv = SOC_E_UNAVAIL; break; } if (intf == PHY_DIAG_INTF_SYS) { _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_LINE); pc->flags &= ~PHYCTRL_SYS_SIDE_CTRL ; } return rv; } STATIC int phy_84328_control_port_get(int unit, soc_port_t port, soc_phy_control_t type, uint32 *value) { int intf; intf = PHY_DIAG_INTF_LINE; SOC_IF_ERROR_RETURN (_phy_84328_control_get(unit, port, intf, PHY_DIAG_LN_DFLT, type, value)); return SOC_E_NONE; } /* Returns whether interface has cl72 */ STATIC int _phy_84328_cl72_en(int unit, soc_port_t port, phy84328_intf_side_t side) { int cl72 = FALSE; phy_ctrl_t *pc; phy84328_intf_cfg_t *ifc; pc = EXT_PHY_SW_STATE(unit, port); ifc = (side == PHY84328_INTF_SIDE_LINE) ? &(LINE_INTF(pc)) : &(SYS_INTF(pc)); switch (ifc->type) { case SOC_PORT_IF_KR: case SOC_PORT_IF_KR4: cl72 = TRUE; break; case SOC_PORT_IF_CR4: /* System side is always DAC */ if (side == PHY84328_INTF_SIDE_SYS) { cl72 = FALSE; } else { /* If no AN, it's really DAC */ cl72 = AN_EN(pc); } break; default: cl72 = FALSE; break; } return cl72; } /* dsc values */ struct phy84328_dsc_cb { int tx_pre_cursor; int tx_main; int tx_post_cursor; char *vga_bias_reduced; int postc_metric; int pf_ctrl; int vga_sum; int dfe1_bin; int dfe2_bin; int dfe3_bin; int dfe4_bin; int dfe5_bin; int integ_reg; int integ_reg_xfer; int clk90_offset; int slicer_target; int offset_pe; int offset_ze; int offset_me; int offset_po; int offset_zo; int offset_mo; }; STATIC int _phy_84328_diag_dsc(int unit, soc_port_t port, int intf, int lane) { int i, reg, lanes, regval; uint16 data16; phy_ctrl_t *pc; phy84328_intf_side_t side; struct phy84328_dsc_cb *dsc_cbp; struct phy84328_dsc_cb dsc_cb[PHY84328_NUM_LANES]; pc = EXT_PHY_SW_STATE(unit, port); if (PHY84328_SINGLE_PORT_MODE(pc)) { lanes = PHY84328_NUM_LANES ; } else { lanes = 1; } side = (intf == PHY_DIAG_INTF_LINE) ? PHY84328_INTF_SIDE_LINE : PHY84328_INTF_SIDE_SYS; sal_memset((char *)&dsc_cb[0], 0, (sizeof(dsc_cb))); PHY_84328_MICRO_PAUSE(unit, port, "dsc"); _phy_84328_intf_side_regs_select(unit, port, side); for (i = 0; i < lanes; i++) { if (PHY84328_SINGLE_PORT_MODE(pc)) { /* Select the lane and side to access */ SOC_IF_ERROR_RETURN(_phy_84328_channel_select(unit, port, side, i)); } dsc_cbp = &(dsc_cb[i]); /* tx drive pre, main, post cursor taps are read differently for cl72 */ if (_phy_84328_cl72_en(unit, port, side)) { uint16 saved_reg; /* 1.c063[15:14]=1 to get port cl72 tap values in 1.c060 */ reg = 0xc063; SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, reg, &data16)); saved_reg = data16; regval = 0x4000 | (data16 & 0x3fff); SOC_IF_ERROR_RETURN (WRITE_PHY84328_MMF_PMA_PMD_REG(unit, pc, reg, data16)); reg = 0xc060; SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, reg, &data16)); /* tx_pre_cursor */ regval = data16 & 0xf; dsc_cbp->tx_pre_cursor = regval; /* tx_post_cursor */ regval = (data16 >> 10) & 0x1f; dsc_cbp->tx_post_cursor = regval; /* tx_main */ regval = (data16 >> 4) & 0x3f; dsc_cbp->tx_main = regval; /* Restore 1.c063 to original values used to access 1.c060 */ SOC_IF_ERROR_RETURN (WRITE_PHY84328_MMF_PMA_PMD_REG(unit, pc, reg, saved_reg)); } else { reg = 0xc067; SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, reg, &data16)); /* tx_pre_cursor */ regval = data16 & 0x7; dsc_cbp->tx_pre_cursor = regval; /* tx_post_cursor */ regval = (data16 >> 4) & 0x1F; dsc_cbp->tx_post_cursor = regval; /* tx_main */ reg = 0xc066; SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, reg, &data16)); regval = (data16 >> 11) & 0x1F; dsc_cbp->tx_main = regval; } /* vga_bias_reduced */ reg = 0xc0BD; SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, reg, &data16)); regval = data16 & (1 << 4); if (regval) { dsc_cbp->vga_bias_reduced = "88%"; } else { dsc_cbp->vga_bias_reduced = "100%"; } /* post2 tap - c068[10:8] */ reg = 0xc068; SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, reg, &data16)); regval = (data16 >> 8) & 0x7; dsc_cbp->postc_metric = regval; /* pf DSC_3_ADDR=0xc220 + 11 */ reg = 0xc220 + 11; SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, reg, &data16)); regval = (data16 & 0xf); dsc_cbp->pf_ctrl = regval; /* vga sum DSC_3_ADDR=0xc220 + 5 */ reg = 0xc220 + 5; SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, reg, &data16)); regval = (data16 & 63); dsc_cbp->vga_sum = regval; /* dfe1_bin DSC_3_ADDR=0xc220 + 5 */ reg = 0xc220 + 5; SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, reg, &data16)); regval = data16; regval /= 64; regval &= 63; dsc_cbp->dfe1_bin = regval; /* dfe2_bin DSC_3_ADDR=0xc220 + 6 */ reg = 0xc220 + 6; SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, reg, &data16)); regval = data16; regval &= 63; if (regval >= 32) { regval -=64; } dsc_cbp->dfe2_bin = regval; /* dfe3_bin DSC_3_ADDR=0xc220 + 6 */ reg = 0xc220 + 6; SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, reg, &data16)); regval = data16; regval /= 64; regval &= 63; if (regval >= 32) { regval -=64; } dsc_cbp->dfe3_bin = regval; /* dfe4_bin DSC_3_ADDR=0xc220 + 7 */ reg = 0xc220 + 7; SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, reg, &data16)); regval = data16; regval &= 31; if (regval >= 16) { regval -=32; } dsc_cbp->dfe4_bin = regval; /* dfe5_bin DSC_3_ADDR=0xc220 + 7 */ reg = 0xc220 + 7; SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, reg, &data16)); regval = data16; regval /= 32; regval &= 31; if (regval >= 16) { regval -=32; } dsc_cbp->dfe5_bin = regval; /* integ_reg(lane) = rd22_integ_reg (phy, lane) DSC_3_ADDR=0xc220 */ reg = 0xc220; SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, reg, &data16)); regval = data16; regval &= 65535; if (regval >= 32768) { regval -=65536; } regval /= 84; dsc_cbp->integ_reg = regval; /* integ_reg_xfer(lane) = rd22_integ_reg_xfer (phy, lane) */ reg = 0xc221; SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, reg, &data16)); regval = data16; regval &= 65535; if (regval >= 32768) { regval -=65536; } dsc_cbp->integ_reg_xfer = regval; /* clk90_offset(lane) = rd22_clk90_phase_offset (phy, lane) */ reg = 0xc223; SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, reg, &data16)); regval = data16; regval /= 128; regval &= 127; dsc_cbp->clk90_offset = regval; /* slicer_target(lane) = ((25*rd22_rx_thresh_sel (phy, lane)) + 125) */ reg = 0xc21c; SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, reg, &data16)); regval = data16; regval /= 32; regval &= 3; dsc_cbp->slicer_target = regval * 25 + 125; /* offset_pe(lane) = rd22_slicer_offset_pe (phy, lane) */ reg = 0xc22c; SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, reg, &data16)); regval = data16; regval &= 63; if (regval >= 32) { regval -=64; } dsc_cbp->offset_pe = regval; /* offset_ze(lane) = rd22_slicer_offset_ze (phy, lane) */ reg = 0xc22d; SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, reg, &data16)); regval = data16; regval &= 63; if (regval >= 32) { regval -=64; } dsc_cbp->offset_ze = regval; /* offset_me(lane) = rd22_slicer_offset_me (phy, lane) */ reg = 0xc22e; SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, reg, &data16)); regval = data16; regval &= 63; if (regval >= 32) { regval -=64; } dsc_cbp->offset_me = regval; /* offset_po(lane) = rd22_slicer_offset_po (phy, lane) */ reg = 0xc22c; SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, reg, &data16)); regval = data16; regval /= 64; regval &= 63; if (regval >= 32) { regval -=64; } dsc_cbp->offset_po = regval; /* offset_zo(lane) = rd22_slicer_offset_zo (phy, lane) */ reg = 0xc22d; SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, reg, &data16)); regval = data16; regval /= 64; regval &= 63; if (regval >= 32) { regval -=64; } dsc_cbp->offset_zo = regval; /* offset_mo(lane) = rd22_slicer_offset_mo (phy, lane) */ reg = 0xc22e; SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, reg, &data16)); regval = data16; regval /= 64; regval &= 63; if (regval >= 32) { regval -=64; } dsc_cbp->offset_mo = regval; } /* Restore to default single port register access */ if (PHY84328_SINGLE_PORT_MODE(pc)) { SOC_IF_ERROR_RETURN(_phy_84328_channel_select(unit, port, side, PHY84328_ALL_LANES)); } _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_LINE); PHY_84328_MICRO_RESUME(unit, port); /* display */ LOG_CLI((BSL_META_U(unit, "\nDSC parameters for port %d\n"), port)); LOG_CLI((BSL_META_U(unit, "LN PPM PPM_XFR clk90_ofs PF SL_TRGT VGA BIAS DFE1 DFE2 " "DFE3 DFE4 DFE5 PREC MAIN POSTC MTRC " "PE ZE ME PO ZO MO\n"))); for (i = 0; i < lanes; i++) { dsc_cbp = &(dsc_cb[i]); LOG_CLI((BSL_META_U(unit, "%02d %04d %07d %09d %04d %04d %04d %4s %04d %04d %04d %04d " "%04d %04d %04d %04d %04d %04d %04d %2d %3d %3d %2d\n"), i, dsc_cbp->integ_reg,dsc_cbp->integ_reg_xfer, dsc_cbp->clk90_offset, dsc_cbp->pf_ctrl, dsc_cbp->slicer_target, dsc_cbp->vga_sum, dsc_cbp->vga_bias_reduced, dsc_cbp->dfe1_bin, dsc_cbp->dfe2_bin, dsc_cbp->dfe3_bin, dsc_cbp->dfe4_bin, dsc_cbp->dfe5_bin, dsc_cbp->tx_pre_cursor, dsc_cbp->tx_main,dsc_cbp->tx_post_cursor, dsc_cbp->postc_metric, dsc_cbp->offset_pe, dsc_cbp->offset_ze,dsc_cbp->offset_me, dsc_cbp->offset_po, dsc_cbp->offset_zo, dsc_cbp->offset_mo)); } return SOC_E_NONE; } STATIC int _phy_84328_diag_eyescan_uc_ready(int unit, soc_port_t port) { int rv = SOC_E_NONE; uint16 data; soc_timeout_t to; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); if (DBG_FLAGS(pc) & PHY84328_DBG_F_EYE) { LOG_CLI((BSL_META_U(unit, " _phy_84328_diag_eyescan_uc_ready\n"))); } /* Wait for uC ready */ soc_timeout_init(&to, 250000, 0); while (!soc_timeout_check(&to)) { rv = READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_UC_CTRL, &data); if (rv != SOC_E_NONE) { break; } if (data & PHY84328_DEV1_UC_CTRL_READY_FOR_CMD_MASK) { break; } } if ((rv == SOC_E_NONE) && (data & PHY84328_DEV1_UC_CTRL_READY_FOR_CMD_MASK)) { rv = SOC_E_NONE; } else { LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 EYE: uController not ready pass 1!: u=%d, p=%d " "uc_ctrl(1.%04x)=%04x\n"), unit, port, PHY84328_SYS_DEV1_UC_CTRL, data)); rv = SOC_E_TIMEOUT; } return rv; } STATIC int _phy_84328_diag_eyescan_offset(int unit, soc_port_t port, int16 supp_data, int req) { phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); if (DBG_FLAGS(pc) & PHY84328_DBG_F_EYE) { LOG_CLI((BSL_META_U(unit, " _phy_84328_diag_eyescan_offset\n"))); } /* offset 1.c20e */ SOC_IF_ERROR_RETURN( MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_UC_CTRL, supp_data << PHY84328_SYS_DEV1_UC_CTRL_SUPPLEMENT_INFO_SHIFT, PHY84328_SYS_DEV1_UC_CTRL_SUPPLEMENT_INFO_MASK)); SOC_IF_ERROR_RETURN( MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_UC_CTRL, 0, PHY84328_SYS_DEV1_UC_CTRL_READY_FOR_CMD_MASK)); SOC_IF_ERROR_RETURN( MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_UC_CTRL, 0, PHY84328_SYS_DEV1_UC_CTRL_ERROR_FOUND_MASK)); SOC_IF_ERROR_RETURN( MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_UC_CTRL, 0, PHY84328_SYS_DEV1_UC_CTRL_CMD_INFO_MASK)); SOC_IF_ERROR_RETURN( MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_UC_CTRL, (req | (supp_data << PHY84328_SYS_DEV1_UC_CTRL_SUPPLEMENT_INFO_SHIFT)), PHY84328_SYS_DEV1_UC_CTRL_GP_UC_REQ_MASK | PHY84328_SYS_DEV1_UC_CTRL_SUPPLEMENT_INFO_MASK)); /* wait for uC ready for command */ return _phy_84328_diag_eyescan_uc_ready(unit, port); } STATIC uint16 _phy_84328_diag_eyescan_diag_ctrl_get(int unit, soc_port_t port) { uint16 data; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); SOC_IF_ERROR_RETURN(READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_DSC_DIAG_CTRL0, &data)); return data; } STATIC int _phy_84328_diag_eyescan_livelink_en(int unit, soc_port_t port, int en) { uint16 data, mask; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); if (DBG_FLAGS(pc) & PHY84328_DBG_F_EYE) { LOG_CLI((BSL_META_U(unit, "_phy_84328_diag_eyescan_livelink_en: en=%d\n"), en)); } data = 0x2; mask = data; SOC_IF_ERROR_RETURN(MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_DSC_DIAG_CTRL0, data, mask)); data = en ? PHY84328_SYS_DEV1_DSC_DIAG_CTRL0_DIAGNOSTICS_EN_BITS : 0; mask = PHY84328_SYS_DEV1_DSC_DIAG_CTRL0_DIAGNOSTICS_EN_MASK; SOC_IF_ERROR_RETURN(MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_DSC_DIAG_CTRL0, data, mask)); if (DBG_FLAGS(pc) & PHY84328_DBG_F_EYE) { LOG_CLI((BSL_META_U(unit, "_phy_84328_diag_eyescan_livelink_en: en=%d [%04x]\n"), en, _phy_84328_diag_eyescan_diag_ctrl_get(unit, port))); } return SOC_E_NONE; } STATIC int _phy_84328_diag_eyescan_livelink_clear(int unit, soc_port_t port, int unused) { phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); SOC_IF_ERROR_RETURN(_phy_84328_diag_eyescan_offset(unit, port, 0x3, 0x6)); if (DBG_FLAGS(pc) & PHY84328_DBG_F_EYE) { LOG_CLI((BSL_META_U(unit, "_phy_84328_diag_eyescan_livelink_clear: [%04x]\n"), _phy_84328_diag_eyescan_diag_ctrl_get(unit, port))); } return SOC_E_NONE; } STATIC int _phy_84328_diag_eyescan_livelink_start(int unit, soc_port_t port, int unused) { phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); SOC_IF_ERROR_RETURN(_phy_84328_diag_eyescan_offset(unit, port, 0x0, 0x6)); if (DBG_FLAGS(pc) & PHY84328_DBG_F_EYE) { LOG_CLI((BSL_META_U(unit, "_phy_84328_diag_eyescan_livelink_start: [%04x]\n"), _phy_84328_diag_eyescan_diag_ctrl_get(unit, port))); } return SOC_E_NONE; } STATIC int _phy_84328_diag_eyescan_livelink_stop(int unit, soc_port_t port, int unused) { phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); SOC_IF_ERROR_RETURN(_phy_84328_diag_eyescan_offset(unit, port, 0x1, 0x6)); if (DBG_FLAGS(pc) & PHY84328_DBG_F_EYE) { LOG_CLI((BSL_META_U(unit, "_phy_84328_diag_eyescan_livelink_stop: [%04x]\n"), _phy_84328_diag_eyescan_diag_ctrl_get(unit, port))); } return SOC_E_NONE; } STATIC int _phy_84328_diag_eyescan_livelink_read(int unit, soc_port_t port, int *err_counter) { int i; uint16 data; uint32 counter; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); counter = 0; if (DBG_FLAGS(pc) & PHY84328_DBG_F_EYE) { LOG_CLI((BSL_META_U(unit, "_phy_84328_diag_eyescan_livelink_read: "))); } for (i = 0; i < 4; i++) { SOC_IF_ERROR_RETURN(_phy_84328_diag_eyescan_offset(unit, port, 0x2, 0x6)); /* read back the maximum offset */ SOC_IF_ERROR_RETURN( READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_UC_CTRL, &data)); data &= PHY84328_SYS_DEV1_UC_CTRL_SUPPLEMENT_INFO_MASK; data >>= PHY84328_SYS_DEV1_UC_CTRL_SUPPLEMENT_INFO_SHIFT; if (DBG_FLAGS(pc) & PHY84328_DBG_F_EYE) { LOG_CLI((BSL_META_U(unit, "[%d]=%d "), i, data)); } counter += (data << (8 * i)); } *err_counter = counter; if (DBG_FLAGS(pc) & PHY84328_DBG_F_EYE) { LOG_CLI((BSL_META_U(unit, "\n_phy_84328_diag_eyescan_livelink_read: err_counter=%d\n"), *err_counter)); } return SOC_E_NONE; } STATIC int _phy_84328_diag_eyescan_init_voffset_get(int unit, soc_port_t port, int *voffset) { uint16 data; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); *voffset = 0; /* 1.c21c[15:10] */ SOC_IF_ERROR_RETURN(READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_DSC_ANA_CTRL3, &data)); *voffset = (data & PHY84328_DEV1_DSC_ANA_CTRL3_RSVD_FOR_ECO_MASK) >> PHY84328_DEV1_DSC_ANA_CTRL3_RSVD_FOR_ECO_SHIFT; if (DBG_FLAGS(pc) & PHY84328_DBG_F_EYE) { LOG_CLI((BSL_META_U(unit, "_phy_84328_diag_eyescan_init_voffset_get: " "voffset=%x [%04x]\n"), *voffset, _phy_84328_diag_eyescan_diag_ctrl_get(unit, port))); } return SOC_E_NONE; } STATIC int _phy_84328_diag_eyescan_hoffset_set(int unit, soc_port_t port, int *hoffset) { phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); SOC_IF_ERROR_RETURN(_phy_84328_diag_eyescan_offset(unit, port, *hoffset, 0x2)); if (DBG_FLAGS(pc) & PHY84328_DBG_F_EYE) { LOG_CLI((BSL_META_U(unit, "_phy_84328_diag_eyescan_hoffset_set: hoffset=%x [%04x]\n"), *hoffset, _phy_84328_diag_eyescan_diag_ctrl_get(unit, port))); } return SOC_E_NONE; } STATIC int _phy_84328_diag_eyescan_voffset_set(int unit, soc_port_t port, int *voffset) { phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); SOC_IF_ERROR_RETURN(_phy_84328_diag_eyescan_offset(unit, port, *voffset, 0x3)); if (DBG_FLAGS(pc) & PHY84328_DBG_F_EYE) { LOG_CLI((BSL_META_U(unit, "_phy_84328_diag_eyescan_voffset_set: voffset=%x [%04x]\n"), *voffset, _phy_84328_diag_eyescan_diag_ctrl_get(unit, port))); } return SOC_E_NONE; } STATIC int _phy_84328_diag_eyescan_max_left_hoffset_get(int unit, soc_port_t port, int *left_hoffset) { uint16 data; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); SOC_IF_ERROR_RETURN(_phy_84328_diag_eyescan_offset(unit, port, 127, 0x2)); /* read back the maximum offset */ SOC_IF_ERROR_RETURN( READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_UC_CTRL, &data)); data &= PHY84328_SYS_DEV1_UC_CTRL_SUPPLEMENT_INFO_MASK; data >>= PHY84328_SYS_DEV1_UC_CTRL_SUPPLEMENT_INFO_SHIFT; *left_hoffset = -data; if (DBG_FLAGS(pc) & PHY84328_DBG_F_EYE) { LOG_CLI((BSL_META_U(unit, "_phy_84328_diag_eyescan_max_left_hoffset_get: " "max_left_hoffset=%d [%04x]\n"), *left_hoffset, _phy_84328_diag_eyescan_diag_ctrl_get(unit, port))); } return SOC_E_NONE; } STATIC int _phy_84328_diag_eyescan_max_right_hoffset_get(int unit, soc_port_t port, int *right_hoffset) { uint16 data; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); SOC_IF_ERROR_RETURN(_phy_84328_diag_eyescan_offset(unit, port, -128, 0x2)); /* read back the right offset */ SOC_IF_ERROR_RETURN( READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_UC_CTRL, &data)); data &= PHY84328_SYS_DEV1_UC_CTRL_SUPPLEMENT_INFO_MASK; data >>= PHY84328_SYS_DEV1_UC_CTRL_SUPPLEMENT_INFO_SHIFT; *right_hoffset = data; if (DBG_FLAGS(pc) & PHY84328_DBG_F_EYE) { LOG_CLI((BSL_META_U(unit, "_phy_84328_diag_eyescan_max_right_hoffset_get: " "max right hoffset=%d [%04x]\n"), *right_hoffset, _phy_84328_diag_eyescan_diag_ctrl_get(unit, port))); } return SOC_E_NONE; } STATIC int _phy_84328_diag_eyescan_min_voffset_get(int unit, soc_port_t port, int *min_voffset) { uint16 data; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); SOC_IF_ERROR_RETURN(_phy_84328_diag_eyescan_offset(unit, port, -128, 0x3)); /* read back the min offset */ SOC_IF_ERROR_RETURN( READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_UC_CTRL, &data)); data &= PHY84328_SYS_DEV1_UC_CTRL_SUPPLEMENT_INFO_MASK; data >>= PHY84328_SYS_DEV1_UC_CTRL_SUPPLEMENT_INFO_SHIFT; *min_voffset = data - 256; if (DBG_FLAGS(pc) & PHY84328_DBG_F_EYE) { LOG_CLI((BSL_META_U(unit, "_phy_84328_diag_eyescan_min_voffset_get: " "min_voffset=%d [%04x]\n"), *min_voffset, _phy_84328_diag_eyescan_diag_ctrl_get(unit, port))); } return SOC_E_NONE; } STATIC int _phy_84328_diag_eyescan_max_voffset_get(int unit, soc_port_t port, int *max_voffset) { uint16 data; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); SOC_IF_ERROR_RETURN(_phy_84328_diag_eyescan_offset(unit, port, 127, 0x3)); /* read back the max voffset */ SOC_IF_ERROR_RETURN( READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_SYS_DEV1_UC_CTRL, &data)); data &= PHY84328_SYS_DEV1_UC_CTRL_SUPPLEMENT_INFO_MASK; data >>= PHY84328_SYS_DEV1_UC_CTRL_SUPPLEMENT_INFO_SHIFT; *max_voffset = data; if (DBG_FLAGS(pc) & PHY84328_DBG_F_EYE) { LOG_CLI((BSL_META_U(unit, "_phy_84328_diag_eyescan_max_voffset_get: " "max_voffset=%d [%04x]\n"), *max_voffset, _phy_84328_diag_eyescan_diag_ctrl_get(unit, port))); } return SOC_E_NONE; } STATIC int _phy_84328_diag_eyescan(int unit, soc_port_t port, uint32 inst, int op_cmd, void *arg) { int lane; int intf; phy84328_intf_side_t side; int rv = SOC_E_NONE; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); intf = PHY_DIAG_INST_INTF(inst); if (intf == PHY_DIAG_INTF_SYS) { side = PHY84328_INTF_SIDE_SYS; _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_SYS); } else { side = PHY84328_INTF_SIDE_LINE; } lane = PHY_DIAG_INST_LN(inst); if (PHY84328_SINGLE_PORT_MODE(pc) && (lane != 0)) { SOC_IF_ERROR_RETURN(_phy_84328_channel_select(unit, port, side, lane)); } switch (op_cmd) { case PHY_DIAG_CTRL_EYE_ENABLE_LIVELINK: rv = _phy_84328_diag_eyescan_livelink_en(unit, port, 1); break; case PHY_DIAG_CTRL_EYE_DISABLE_LIVELINK: rv = _phy_84328_diag_eyescan_livelink_en(unit, port, 0); break; case PHY_DIAG_CTRL_EYE_CLEAR_LIVELINK: rv = _phy_84328_diag_eyescan_livelink_clear(unit, port, 0); break; case PHY_DIAG_CTRL_EYE_START_LIVELINK: rv = _phy_84328_diag_eyescan_livelink_start(unit, port, 0); break; case PHY_DIAG_CTRL_EYE_STOP_LIVELINK: rv = _phy_84328_diag_eyescan_livelink_stop(unit, port, 0); break; case PHY_DIAG_CTRL_EYE_READ_LIVELINK: rv = _phy_84328_diag_eyescan_livelink_read(unit, port, (int *) arg); break; case PHY_DIAG_CTRL_EYE_GET_INIT_VOFFSET: rv = _phy_84328_diag_eyescan_init_voffset_get(unit, port, (int *)arg); break; case PHY_DIAG_CTRL_EYE_SET_HOFFSET: rv = _phy_84328_diag_eyescan_hoffset_set(unit, port, (int *)arg); break; case PHY_DIAG_CTRL_EYE_SET_VOFFSET: rv = _phy_84328_diag_eyescan_voffset_set(unit, port, (int *)arg); break; case PHY_DIAG_CTRL_EYE_GET_MAX_LEFT_HOFFSET: rv = _phy_84328_diag_eyescan_max_left_hoffset_get(unit, port, (int *)arg); break; case PHY_DIAG_CTRL_EYE_GET_MAX_RIGHT_HOFFSET: rv = _phy_84328_diag_eyescan_max_right_hoffset_get(unit, port, (int *)arg); break; case PHY_DIAG_CTRL_EYE_GET_MIN_VOFFSET: rv = _phy_84328_diag_eyescan_min_voffset_get(unit, port, (int *)arg); break; case PHY_DIAG_CTRL_EYE_GET_MAX_VOFFSET: rv = _phy_84328_diag_eyescan_max_voffset_get(unit, port, (int *)arg); break; } if (PHY84328_SINGLE_PORT_MODE(pc) && (lane != 0)) { SOC_IF_ERROR_RETURN(_phy_84328_channel_select(unit, port, PHY84328_INTF_SIDE_LINE, PHY84328_ALL_LANES)); } if (intf == PHY_DIAG_INTF_SYS) { _phy_84328_intf_side_regs_select(unit, port, PHY84328_INTF_SIDE_LINE); } return rv; } STATIC int _phy_84328_diag_ctrl(int unit, soc_port_t port, uint32 inst, int op_type, int op_cmd, void *arg) { int lane; int intf; int rv = SOC_E_NONE; LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 diag_ctrl: u=%d p=%d ctrl=0x%x\n"), unit, port, op_cmd)); lane = PHY_DIAG_INST_LN(inst); intf = PHY_DIAG_INST_INTF(inst); if (intf == PHY_DIAG_INTF_DFLT) { intf = PHY_DIAG_INTF_LINE; } switch (op_cmd) { case PHY_DIAG_CTRL_DSC: SOC_IF_ERROR_RETURN(_phy_84328_diag_dsc(unit, port, intf, lane)); break; case PHY_DIAG_CTRL_EYE_ENABLE_LIVELINK: case PHY_DIAG_CTRL_EYE_DISABLE_LIVELINK: case PHY_DIAG_CTRL_EYE_CLEAR_LIVELINK: case PHY_DIAG_CTRL_EYE_START_LIVELINK: case PHY_DIAG_CTRL_EYE_STOP_LIVELINK: case PHY_DIAG_CTRL_EYE_READ_LIVELINK: case PHY_DIAG_CTRL_EYE_GET_INIT_VOFFSET: case PHY_DIAG_CTRL_EYE_SET_HOFFSET: case PHY_DIAG_CTRL_EYE_SET_VOFFSET: case PHY_DIAG_CTRL_EYE_GET_MAX_LEFT_HOFFSET: case PHY_DIAG_CTRL_EYE_GET_MAX_RIGHT_HOFFSET: case PHY_DIAG_CTRL_EYE_GET_MIN_VOFFSET: case PHY_DIAG_CTRL_EYE_GET_MAX_VOFFSET: rv = _phy_84328_diag_eyescan(unit, port, inst, op_cmd, arg); break; case PHY_DIAG_CTRL_EYE_MARGIN_VEYE: case PHY_DIAG_CTRL_EYE_MARGIN_HEYE_LEFT: case PHY_DIAG_CTRL_EYE_MARGIN_HEYE_RIGHT: rv = SOC_E_UNAVAIL; break; default: if (op_type == PHY_DIAG_CTRL_SET) { SOC_IF_ERROR_RETURN (_phy_84328_control_set(unit, port, intf, lane, op_cmd, PTR_TO_INT(arg))); } else if (op_type == PHY_DIAG_CTRL_GET) { SOC_IF_ERROR_RETURN (_phy_84328_control_get(unit, port, intf, lane, op_cmd, (uint32 *)arg)); } else { LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 diag_ctrl bad operation: u=%d p=%d ctrl=0x%x\n"), unit, port, op_cmd)); rv = SOC_E_UNAVAIL; } break; } return rv; } /* * Return whether AN is enabled or forced with internal SerDes on the system side */ STATIC int _phy_84328_intf_sys_forced(int unit, soc_port_t port, soc_port_if_t intf_type) { int rv; phy_ctrl_t *pc; pc = EXT_PHY_SW_STATE(unit, port); switch (intf_type) { case SOC_PORT_IF_SR: case SOC_PORT_IF_SR4: case SOC_PORT_IF_LR: case SOC_PORT_IF_LR4: case SOC_PORT_IF_XLAUI: case SOC_PORT_IF_XFI: case SOC_PORT_IF_SFI: case SOC_PORT_IF_CR: case SOC_PORT_IF_CR4: case SOC_PORT_IF_ZR: case SOC_PORT_IF_CAUI: rv = TRUE; break; case SOC_PORT_IF_GMII: rv = FALSE; break; case SOC_PORT_IF_KR: case SOC_PORT_IF_KR4: rv = SYS_FORCED_CL72(pc) ? TRUE : FALSE; break; default: rv = FALSE; } return rv; } STATIC int _phy_84328_intf_line_forced(int unit, soc_port_t port, soc_port_if_t intf_type) { int rv; switch (intf_type) { case SOC_PORT_IF_SR: case SOC_PORT_IF_SR4: case SOC_PORT_IF_LR: case SOC_PORT_IF_ZR: case SOC_PORT_IF_LR4: case SOC_PORT_IF_XLAUI: case SOC_PORT_IF_XFI: case SOC_PORT_IF_SFI: case SOC_PORT_IF_CR: case SOC_PORT_IF_CAUI: rv = TRUE; break; default: rv = FALSE; } return rv; } STATIC int __phy_84328_speed_set(int unit, soc_port_t port, int speed) { int rv = SOC_E_NONE; int cur_an, cur_an_done; int cur_speed = 0; uint32 cur_fw_mode = 0; soc_port_if_t cur_type, new_type; phy_ctrl_t *pc, *int_pc; phy84328_intf_cfg_t *line_intf; phy84328_intf_cfg_t *sys_intf; pc = EXT_PHY_SW_STATE(unit, port); int_pc = INT_PHY_SW_STATE(unit, port); line_intf = &(LINE_INTF(pc)); sys_intf = &(SYS_INTF(pc)); line_intf->speed = speed; sys_intf->speed = speed; /* Make sure datapath is correct one for this speed */ SOC_IF_ERROR_RETURN(_phy_84328_data_path_check(unit, port)); if (int_pc != NULL) { if ((sys_intf->type == SOC_PORT_IF_GMII) || (sys_intf->type == SOC_PORT_IF_SGMII)) { SOC_IF_ERROR_RETURN(PHY_SPEED_SET(int_pc->pd, unit, port, sys_intf->speed)); } else if (_phy_84328_intf_sys_forced(unit, port, sys_intf->type) ) { /* * When setting system side 40G DAC/XLAUI-DFE, tell internal SerDes to match * with XLAUI. * * If flexports, the internal SerDes may be out of sync until it gets a chance * to convert the port, so these operations may be best effort. */ new_type = (sys_intf->type == SOC_PORT_IF_CR4) ? SOC_PORT_IF_XLAUI : sys_intf->type; SOC_IF_ERROR_RETURN(PHY_INTERFACE_GET(int_pc->pd, unit, port, &cur_type)); if (cur_type != new_type) { (void) PHY_INTERFACE_SET(int_pc->pd, unit, port, new_type); } /* Check if it must change to forced */ SOC_IF_ERROR_RETURN(PHY_AUTO_NEGOTIATE_GET(int_pc->pd, unit, port, &cur_an, &cur_an_done)); if (cur_an == TRUE) { (void) PHY_AUTO_NEGOTIATE_SET(int_pc->pd, unit,port, FALSE); } if ((PHYCTRL_INIT_STATE(pc) == PHYCTRL_INIT_STATE_PASS2)) { /* Skip int_pc speed set during phy init */ } else if ((rv = PHY_SPEED_GET(int_pc->pd, unit, port, &cur_speed)) != SOC_E_NONE) { /* LOG_CLI((BSL_META_U(unit, "84328 u=%d p=%d speed get error\n"), unit, port)); */ return rv; } else if (cur_speed != sys_intf->speed) { (void) PHY_SPEED_SET(int_pc->pd, unit, port, sys_intf->speed); } /* For system intf=cr4 use XLAUI_DFE on Serdes (in forced mode)*/ if (sys_intf->type != SOC_PORT_IF_CR4) { /* Skip int_pc fw mode set */ } else if ((rv = PHY_CONTROL_GET(int_pc->pd, unit, port, SOC_PHY_CONTROL_FIRMWARE_MODE, &cur_fw_mode)) != SOC_E_NONE) { /* LOG_CLI((BSL_META_U(unit, "84328 u=%d p=%d fwmode get error\n"), unit, port)); */ return rv; } else if (cur_fw_mode != SOC_PHY_FIRMWARE_FORCE_OSDFE) { (void) PHY_CONTROL_SET(int_pc->pd, unit, port, SOC_PHY_CONTROL_FIRMWARE_MODE, SOC_PHY_FIRMWARE_FORCE_OSDFE); } } else { SOC_IF_ERROR_RETURN(PHY_AUTO_NEGOTIATE_SET(int_pc->pd, unit,port, TRUE)); } } /* Update interface type/speed */ return _phy_84328_intf_line_sys_update(unit, port); } STATIC int _phy_84328_intf_line_sys_init(int unit, soc_port_t port) { phy_ctrl_t *pc; phy84328_intf_cfg_t *line_intf; pc = EXT_PHY_SW_STATE(unit, port); line_intf = &(LINE_INTF(pc)); return __phy_84328_speed_set(unit, port, line_intf->speed); } /* * Function: * phy_84328_speed_set * Purpose: * Set PHY speed * Parameters: * unit - StrataSwitch unit #. * port - StrataSwitch port #. * speed - link speed in Mbps * Returns: * SOC_E_NONE */ STATIC int _phy_84328_speed_set(int unit, soc_port_t port, int speed) { int rv; phy_ctrl_t *pc; phy84328_intf_cfg_t *line_intf; phy84328_intf_cfg_t *sys_intf; COMPILER_REFERENCE(unit); COMPILER_REFERENCE(port); pc = EXT_PHY_SW_STATE(unit, port); line_intf = &(LINE_INTF(pc)); sys_intf = &(SYS_INTF(pc)); LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "phy_84328_speed_set: u=%d p=%d speed=%d\n"), unit, port,speed)); if (PHY84328_SINGLE_PORT_MODE(pc)) { if (! _phy_84328_intf_is_single_port(line_intf->type)) { LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 speed set does not match interface: " "u=%d p=%d speed=%d intf=%d\n"), unit, port, speed, sys_intf->type)); return SOC_E_PARAM; } switch (speed) { case 100000: case 40000: break; case 42000: /* 42G only valid for HG[42] */ if (! IS_HG_PORT(unit, port)) { speed = 40000; } break; default: return SOC_E_PARAM; } } else { if (_phy_84328_intf_is_single_port(line_intf->type)) { LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 invalid intf in quad port: u=%d p=%d intf=%d\n"), unit, port, line_intf->type)); return SOC_E_PARAM; } switch (speed) { case 1000: if (!_phy_84328_intf_type_1000(line_intf->type)) { line_intf->type = SOC_PORT_IF_GMII; } /* * Changing speed to 1000 * - if backplane interface then change to KX * - if not KX, then set to GMII */ if (sys_intf->type == SOC_PORT_IF_KR) { sys_intf->type = SOC_PORT_IF_KX; } else if (sys_intf->type != SOC_PORT_IF_KX) { sys_intf->type = line_intf->type; } break; case 100: case 10: if (line_intf->type != SOC_PORT_IF_SGMII) { line_intf->type = SOC_PORT_IF_SGMII; } sys_intf->type = line_intf->type; break; case 10000: /* * If changing from 1000 to 10000, then adjust interface */ if (line_intf->speed <= 1000) { /* * If changing speed from 1000 to 10000, set line interface to SFI */ if (!_phy_84328_intf_type_10000(line_intf->type)) { line_intf->type = SOC_PORT_IF_SR; } /* * Restore the configured system side interface */ sys_intf->type = CFG_SYS_INTF(pc); if (!_phy_84328_intf_type_10000(sys_intf->type)) { sys_intf->type = SOC_PORT_IF_XFI; } } break; case 40000: default: LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 invalid speed: u=%d p=%d speed=%d\n"), unit, port, speed)); return SOC_E_PARAM; } } rv = __phy_84328_speed_set(unit, port, speed); if (SOC_FAILURE(rv)) { LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 %s failed: u=%d p=%d\n"), FUNCTION_NAME(), unit, port)); } return rv; } /* * Function: * phy_84328_speed_get * Purpose: * Get PHY speed * Parameters: * unit - StrataSwitch unit #. * port - StrataSwitch port #. * speed - current link speed in Mbps * Returns: * SOC_E_NONE */ STATIC int _phy_84328_speed_get(int unit, soc_port_t port, int *speed) { phy84328_intf_cfg_t *line_intf; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); line_intf = &(LINE_INTF(pc)); *speed = line_intf->speed; return SOC_E_NONE; } STATIC int _phy_84328_intf_type_set(int unit, soc_port_t port, soc_port_if_t pif, int must_update) { int rv = SOC_E_NONE; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); phy84328_intf_cfg_t *line_intf; int update = 0; uint16 reg_data = 0, reg_mask = 0; uint16 data = 0, mask = 0; line_intf = &(LINE_INTF(pc)); reg_data = 0; reg_mask = 0; FORCE_20BIT(pc) &= ~(FORCE_20BIT_AN); if (_phy_84328_intf_is_single_port(pif)) { if (!PHY84328_SINGLE_PORT_MODE(pc)) { LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 invalid interface for quad port: u=%d p=%d\n"), unit, port)); return SOC_E_CONFIG; } /* * If rx polarity is flipped and the interface is CR4, then change the datapath * to 20-bit as rx polarity cannot be handle on the line side in 4-bit */ if (pif == SOC_PORT_IF_CR4) { if (AN_EN(pc)) { if (POL_RX_CFG(pc) && (CUR_DATAPATH(pc) != PHY84328_DATAPATH_20)) { CUR_DATAPATH(pc) = PHY84328_DATAPATH_20; update = 1; } if (POL_RX_CFG(pc)) { FORCE_20BIT(pc) |= FORCE_20BIT_AN ; } } else if (FORCE_20BIT(pc) == 0 && CUR_DATAPATH(pc) != CFG_DATAPATH(pc)) { CUR_DATAPATH(pc) = CFG_DATAPATH(pc); update = 1; } SOC_IF_ERROR_RETURN( _phy_84328_intf_datapath_reg_get(unit, port, CUR_DATAPATH(pc), &data, &mask)); reg_data |= data; reg_mask |= mask; } if ((pif != line_intf->type) || must_update) { update = 1; } } else if (_phy_84328_intf_is_quad_port(pif)) { if (PHY84328_SINGLE_PORT_MODE(pc)) { LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 invalid interface for single port: u=%d p=%d\n"), unit, port)); return SOC_E_CONFIG; } if ((line_intf->type != pif) || must_update) { update = 1; SOC_IF_ERROR_RETURN( _phy_84328_intf_type_reg_get(unit, port, pif, PHY84328_INTF_SIDE_LINE, &reg_data, &reg_mask)); } } else { LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 invalid interface for port: u=%d p=%d intf=%d\n"), unit, port, pif)); return SOC_E_CONFIG; } if (update) { line_intf->type = pif; SOC_IF_ERROR_RETURN( _phy_84328_intf_type_reg_get(unit, port, pif, PHY84328_INTF_SIDE_LINE, &data, &mask)); reg_data |= data; reg_mask |= mask; SOC_IF_ERROR_RETURN(_phy_84328_intf_update(unit, port, reg_data, reg_mask)); } return rv; } /* * Function: * phy_84328_interface_set * Purpose: * * * Parameters: * unit - StrataSwitch unit #. * port - StrataSwitch port #. * pif - one of SOC_PORT_IF_* * Returns: * SOC_E_NONE - success * SOC_E_UNAVAIL - unsupported interface */ STATIC int _phy_84328_interface_set(int unit, soc_port_t port, soc_port_if_t pif) { int rv; LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 interface set: u=%d p=%d pif=%s\n"), unit, port, phy84328_intf_names[pif])); if (pif == SOC_PORT_IF_MII) { return phy_null_interface_set(unit, port, pif); } if (pif == SOC_PORT_IF_XGMII) { return phy_null_interface_set(unit, port, pif); } rv = _phy_84328_intf_type_set(unit, port, pif, FALSE); if (SOC_FAILURE(rv)) { LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 interface set check failed: u=%d p=%d\n"), unit, port)); } if (_phy_84328_intf_line_forced(unit, port, pif)) { SOC_IF_ERROR_RETURN(_phy_84328_an_set(unit, port, 0)); } return SOC_E_NONE; } /* * Function: * phy_84328_interface_get * Purpose: * Get the current operating mode of the PHY. * Parameters: * unit - StrataSwitch unit #. * port - StrataSwitch port #. * pif - (OUT) one of SOC_PORT_IF_* * Returns: * SOC_E_NONE */ STATIC int _phy_84328_interface_get(int unit, soc_port_t port, soc_port_if_t *pif) { phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); phy84328_intf_cfg_t *line_intf; /* interface set now operates on line side interface */ line_intf = &(LINE_INTF(pc)); *pif = line_intf->type; return SOC_E_NONE; } STATIC int _phy84328_init_ucode_bcst_load(int unit, int port) { uint16 data16, mask16, num_words; uint8 *fw_ptr; int j, fw_length; phy_ctrl_t *pc; #if defined(BROADCOM_DEBUG) || defined(DEBUG_PRINT) int dbg_flag = 1; #endif pc = EXT_PHY_SW_STATE(unit, port); #if defined(BROADCOM_DEBUG) || defined(DEBUG_PRINT) if (dbg_flag) { LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "PHY84328 bcst download device name %s: u=%d p=%d\n"), pc->dev_name? pc->dev_name: "NULL", unit, port)); } #endif /* find the right firmware */ if (pc->dev_name == dev_name_84328_a0) { fw_ptr = phy84328_ucode_bin; fw_length = phy84328_ucode_bin_len; } else if (pc->dev_name == dev_name_84328) { fw_ptr = phy84328B0_ucode_bin; fw_length = phy84328B0_ucode_bin_len; } else if (pc->dev_name == dev_name_84088) { fw_ptr = phy84328B0_ucode_bin; fw_length = phy84328B0_ucode_bin_len; } else { /* invalid device name */ #if defined(BROADCOM_DEBUG) || defined(DEBUG_PRINT) LOG_WARN(BSL_LS_SOC_PHY, (BSL_META_U(unit, "firmware_bcst,invalid device name %s: u=%d p=%d\n"), pc->dev_name? pc->dev_name: "NULL", unit, port)); #endif return SOC_E_NONE; } /* clear SPA ctrl reg bit 15 and bit 13. * bit 15, 0-use MDIO download to SRAM, 1 SPI-ROM download to SRAM * bit 13, 0 clear download done status, 1 skip download */ mask16 = PHY84328_DEV1_SPA_CONTROL_STATUS_REGISTER_SPI_PORT_USED_MASK | PHY84328_DEV1_SPA_CONTROL_STATUS_REGISTER_SPI_DWLD_DONE_MASK; data16 = 0; SOC_IF_ERROR_RETURN( MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_SPA_CONTROL_STATUS_REGISTER, data16,mask16)); /* set SPA ctrl reg bit 14, 1 RAM boot, 0 internal ROM boot */ mask16 = PHY84328_DEV1_SPA_CONTROL_STATUS_REGISTER_SPI_BOOT_MASK; data16 = mask16; SOC_IF_ERROR_RETURN( MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_SPA_CONTROL_STATUS_REGISTER, data16,mask16)); /* misc_ctrl1 reg bit 3 to 1 for 32k downloading size */ mask16 = PHY84328_DEV1_MISC_CTRL_SPI_DOWNLOAD_SIZE_MASK; data16 = mask16; SOC_IF_ERROR_RETURN( MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_MISC_CTRL, data16,mask16)); /* deassert ucrst 1.ca10 bit 2=0 */ mask16 = PHY84328_DEV1_GEN_CTRL_UCRST_MASK; data16 = 0x00; /*clear; not self-clearing*/ SOC_IF_ERROR_RETURN( MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_GEN_CTRL, data16,mask16)); /* wait for 2ms for M8051 start and 5ms to initialize the RAM */ sal_usleep(10000); /* Wait for 10ms */ /* Write Starting Address, where the Code will reside in SRAM */ data16 = 0x8000; SOC_IF_ERROR_RETURN( WRITE_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_MSG_IN, data16)); /* make sure address word is read by the micro */ sal_udelay(10); /* Wait for 10us */ /* Write SPI SRAM Count Size */ data16 = (fw_length)/2; SOC_IF_ERROR_RETURN( WRITE_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_MSG_IN, data16)); /* make sure read by the micro */ sal_udelay(10); /* Wait for 10us */ if (pc->addr_write != NULL) { SOC_IF_ERROR_RETURN( WRITE_ADDR_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_C45_DEV_PMA_PMD, PHY84328_DEV1_MSG_IN)); } /* Fill in the SRAM */ num_words = (fw_length - 1); for (j = 0; j < num_words; j+=2) { data16 = (fw_ptr[j] << 8) | fw_ptr[j+1]; if (pc->data_write != NULL) { SOC_IF_ERROR_RETURN( WRITE_DATA_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_C45_DEV_PMA_PMD, data16)); } else { /* Make sure the word is read by the Micro */ sal_udelay(10); SOC_IF_ERROR_RETURN( WRITE_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_MSG_IN, data16)); } } return SOC_E_NONE; } STATIC int __phy84328_init_ucode_bcst(int unit, int port, int cmd) { uint16 data16; uint16 mask16; phy_ctrl_t *pc; #if defined(BROADCOM_DEBUG) || defined(DEBUG_PRINT) int dbg_flag = 1; #endif pc = EXT_PHY_SW_STATE(unit, port); #ifdef BCM_WARM_BOOT_SUPPORT if (SOC_WARM_BOOT(unit) || SOC_IS_RELOADING(unit)){ return SOC_E_NONE; } #endif if (cmd == PHYCTRL_UCODE_BCST_SETUP) { #if defined(BROADCOM_DEBUG) || defined(DEBUG_PRINT) if (dbg_flag == 1) { LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "PHY84328 bcst setup: u=%d p=%d\n"), unit, port)); } #endif /* Enable broadcast mode so all lanes get properly reset */ SOC_IF_ERROR_RETURN (MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_BROADCAST_CTRL, PHY84328_DEV1_BROADCAST_CTRL_BROADCAST_MODE_ENABLE_MASK, PHY84328_DEV1_BROADCAST_CTRL_BROADCAST_MODE_ENABLE_MASK)); return SOC_E_NONE; } else if (cmd == PHYCTRL_UCODE_BCST_uC_SETUP) { #if defined(BROADCOM_DEBUG) || defined(DEBUG_PRINT) if (dbg_flag == 1) { LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "PHY84328 micro setup: u=%d p=%d\n"), unit, port)); } #endif /* apply bcst Reset to start download code from MDIO */ mask16 = PHY84328_DEV1_GEN_CTRL_UCRST_MASK; data16 = mask16; /*set*/ SOC_IF_ERROR_RETURN (MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_GEN_CTRL, data16,mask16)); /* clear : 1.ca18 */ SOC_IF_ERROR_RETURN (WRITE_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_GP_REG_0, 0)); /* clear : 1.ca19 */ SOC_IF_ERROR_RETURN (WRITE_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_GP_REG_1, 0)); /* clear : 1.ca1a */ SOC_IF_ERROR_RETURN (WRITE_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_GP_REG_2, 0)); mask16 = PHY84328_DEV1_PMD_CONTROL_REGISTER_RESET_MASK; data16 = mask16; SOC_IF_ERROR_RETURN (MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_PMD_CONTROL_REGISTER, data16,mask16)); /* Wait for 2.8 msec for 8051 to start */ sal_udelay(2800); return SOC_E_NONE; } else if (cmd == PHYCTRL_UCODE_BCST_ENABLE) { #if defined(BROADCOM_DEBUG) || defined(DEBUG_PRINT) if (dbg_flag == 1) { LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "PHY84328 bcst enable: u=%d p=%d\n"), unit, port)); } #endif /* In case reset clears bcst register */ /* restore bcst register after reset */ /* Enable broadcast mode */ SOC_IF_ERROR_RETURN (MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_BROADCAST_CTRL, PHY84328_DEV1_BROADCAST_CTRL_BROADCAST_MODE_ENABLE_MASK, PHY84328_DEV1_BROADCAST_CTRL_BROADCAST_MODE_ENABLE_MASK)); return SOC_E_NONE; } else if (cmd == PHYCTRL_UCODE_BCST_LOAD) { return _phy84328_init_ucode_bcst_load(unit, port); } else if (cmd == PHYCTRL_UCODE_BCST_END) { #if defined(BROADCOM_DEBUG) || defined(DEBUG_PRINT) if (dbg_flag == 1) { LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "PHY84328 bcst end: u=%d p=%d\n"), unit, port)); } #endif /* make sure last code word is read by the micro */ sal_udelay(20); /* Read Hand-Shake message (Done) from Micro */ SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_MSG_OUT, &data16)); /* Download done message */ #if defined(BROADCOM_DEBUG) || defined(DEBUG_PRINT) if (dbg_flag == 1) { LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "PHY84328 MDIO firmware download done message=0x%x: u=%d p=%d\n"), data16, unit, port)); } #endif sal_udelay(100); /* Wait for 100 usecs */ /* Read checksum for Micro. The expected value is 0x0300 , where upper_byte=03 means mdio download is done and lower byte=00 means no checksum error */ SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_MSG_OUT, &data16)); /* Download done message */ #if defined(BROADCOM_DEBUG) || defined(DEBUG_PRINT) if (dbg_flag == 1) { LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "PHY84328 MDIO firmware download status message state 0x%x checksum 0x%x: " "u=%d p=%d\n"), (data16 >> 8) & 0xff, data16 & 0xff, unit, port)); } #endif /* Need to check if checksum is correct */ SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_GP_REG_4, &data16)); if (data16 == 0x600D) { /* read Rev-ID */ SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_VERSION, &data16)); #if defined(BROADCOM_DEBUG) || defined(DEBUG_PRINT) if (dbg_flag == 1) { LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "PHY84328 Firmware revID=0x%x: u=%d p=%d \n"), data16, unit, port)); } #endif } /* Disable broadcast mode */ SOC_IF_ERROR_RETURN (MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_BROADCAST_CTRL, 0, PHY84328_DEV1_BROADCAST_CTRL_BROADCAST_MODE_ENABLE_MASK)); /* Go back to proper PMD mode */ data16 = (PHY84328_SINGLE_PORT_MODE(pc)) ? PHY84328_DEV1_SINGLE_PMD_CTRL_SINGLE_PMD_MODE_MASK : 0; SOC_IF_ERROR_RETURN (MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_SINGLE_PMD_CTRL, data16, PHY84328_DEV1_SINGLE_PMD_CTRL_SINGLE_PMD_MODE_MASK)); /* Make sure micro completes its initialization */ sal_udelay(5000); return SOC_E_NONE; } else { LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "u=%d p=%d firmware_bcst: invalid cmd 0x%x\n"), unit, port,cmd)); } return SOC_E_FAIL; } /* * Function: * phy_84328_precondition_before_probe * Purpose: * When the device is in 40G, ie. after a power reset, and the 10G * port being probed does not have the 40G address in PRTAD, the * device will not respond until the port that has the 40G address * is probed. To avoid not programming ports correctly, make * sure the device is in quad (4x10G) PMD mode when the SDK port is 10G. * Parameters: * unit - StrataSwitch unit #. * pc - phy ctrl descriptor. * Returns: * SOC_E_NONE,SOC_E_NOT_FOUND and SOC_E_<error> */ STATIC int phy_84328_precondition_before_probe(int unit, phy_ctrl_t *pc) { int ids; int rv = SOC_E_NOT_FOUND; uint16 pmd_ctrl; uint16 id0, id1; uint16 saved_phy_id; /* Not required when the port is single PMD */ if (PHY84328_SINGLE_PORT_MODE(pc)) { LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "PMD must not be called when in single PMD\n"))); return rv; } saved_phy_id = pc->phy_id; /* Look for first address that responds */ for (ids = 0; ids < 4; ids++) { pc->phy_id = (saved_phy_id & ~0x3) + ids; LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "Try device with address %x\n"), pc->phy_id)); /* * Make sure the device has the correct dev IDs * Note that this is being called either because the soc probe found * the ids or there was an id override. In the later case, the device * might not have the 84328 ids so this PMD setup will not be supported */ id0 = 0; READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_PMD_IDENTIFIER_REGISTER_0, &id0); if (id0 != 0x600d) { continue; } id1 = 0; READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_PMD_IDENTIFIER_REGISTER_1, &id1); if (id1 != 0x8500) { continue; } /* Read device ids correctly so use this address to make sure device is in 10G */ pmd_ctrl = 0; READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_SINGLE_PMD_CTRL, &pmd_ctrl); if (pmd_ctrl & PHY84328_DEV1_SINGLE_PMD_CTRL_SINGLE_PMD_MODE_MASK) { LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "Device responded to address %x. Setting quad PMD mode\n"), pc->phy_id)); pmd_ctrl = 0; /* Clear single PMD */ SOC_IF_ERROR_RETURN( MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_SINGLE_PMD_CTRL, pmd_ctrl, PHY84328_DEV1_SINGLE_PMD_CTRL_SINGLE_PMD_MODE_MASK)); } /* Found the address that responds and the device now is in 4x10G */ rv = SOC_E_NONE; break; } pc->phy_id = saved_phy_id; return rv; } /* * Function: * phy_84328_probe * Purpose: * Complement the generic phy probe routine to identify this phy when its * phy id0 and id1 is same as some other phy's. * Parameters: * unit - StrataSwitch unit #. * pc - phy ctrl descriptor. * Returns: * SOC_E_NONE,SOC_E_NOT_FOUND and SOC_E_<error> */ STATIC int _phy_84328_probe(int unit, phy_ctrl_t *pc) { uint32 devid; uint16 chip_rev; SOC_IF_ERROR_RETURN(_phy_84328_config_devid(pc->unit, pc->port, pc, &devid)); SOC_IF_ERROR_RETURN( READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_CHIP_REV_REGISTER, &chip_rev)); if (devid == PHY84328_ID_84328) { if (chip_rev == 0x00a0) { pc->dev_name = dev_name_84328_a0; } else { pc->dev_name = dev_name_84328; } } else if (devid == PHY84328_ID_84324){ pc->dev_name = dev_name_84324; } else if (devid == PHY84328_ID_84088){ pc->dev_name = dev_name_84088; } else if (devid == PHY84328_ID_84024){ pc->dev_name = dev_name_84024; } else { /* not found */ LOG_WARN(BSL_LS_SOC_PHY, (BSL_META_U(unit, "port %d: BCM84xxx type PHY device detected, please use " "phy_84<xxx> config variable to select the specific type\n"), pc->port)); return SOC_E_NOT_FOUND; } pc->size = sizeof(phy84328_dev_desc_t); return SOC_E_NONE; } /* * Return the phy_id for the core * * Currently assumes the addresses for the cores are * 4 apart, e.g. core0_addr=n, core1_addr=n+4; core2_addr=n+8 * * This can be modified to specify the address via a config property. * The config property spn_PORT_PHY_ADDR is already available to * specify the address for the port, which in a multicore port, * refers to core0. */ STATIC uint16 _phy_84328_phy_id_get(phy_ctrl_t *pc, int core) { int phy_id = 0xff; int id_map[PHY84328_MAX_CORES] = { 0xff , 0xff, 0xff }; id_map[core%PHY84328_MAX_CORES] = soc_property_port_suffix_num_get( pc->unit, pc->port, core, spn_PORT_PHY_ADDR, "core", id_map[core % PHY84328_MAX_CORES]); phy_id = soc_property_port_get( pc->unit, pc->port, spn_PORT_PHY_ADDR, phy_id); if (phy_id != id_map[core % PHY84328_MAX_CORES]) { return id_map[core % PHY84328_MAX_CORES]; } else { return pc->phy_id + (core * 4); } } STATIC int _phy_84328_bsc_rw(int unit, soc_port_t port, int dev_addr, int opr, int addr, int count, void *data_array,uint32 ram_start) { phy_ctrl_t *pc; soc_timeout_t to; uint16 data16; int i; int access_type; int data_type; #if defined(BROADCOM_DEBUG) || defined(DEBUG_PRINT) sal_usecs_t start; sal_usecs_t end; #endif LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "phy_84328_bsc_read: u=%d p=%d addr=%04x\n"), unit, port, addr)); if (!data_array) { return SOC_E_PARAM; } if (count > PHY84328_BSC_XFER_MAX) { return SOC_E_PARAM; } pc = EXT_PHY_SW_STATE(unit, port); data_type = PHY84328_I2C_DATA_TYPE(opr); access_type = PHY84328_I2C_ACCESS_TYPE(opr); if (access_type == PHY84328_I2CDEV_WRITE) { for (i = 0; i < count; i++) { if (data_type == PHY84328_I2C_8BIT) { SOC_IF_ERROR_RETURN (WRITE_PHY84328_MMF_PMA_PMD_REG(unit, pc, ram_start + i, ((uint8 *)data_array)[i])); } else { /* 16 bit */ SOC_IF_ERROR_RETURN (WRITE_PHY84328_MMF_PMA_PMD_REG(unit, pc, ram_start + i, ((uint16 *)data_array)[i])); } } } data16 = ram_start; SOC_IF_ERROR_RETURN (WRITE_PHY84328_MMF_PMA_PMD_REG(unit, pc, 0x8004, data16)); SOC_IF_ERROR_RETURN (WRITE_PHY84328_MMF_PMA_PMD_REG(unit, pc, 0x8003, addr)); SOC_IF_ERROR_RETURN (WRITE_PHY84328_MMF_PMA_PMD_REG(unit, pc, 0x8002, count)); data16 = 1; data16 |= (dev_addr<<9); if (access_type == PHY84328_I2CDEV_WRITE) { data16 |= PHY84328_WR_FREQ_400KHZ; } SOC_IF_ERROR_RETURN (WRITE_PHY84328_MMF_PMA_PMD_REG(unit,pc,0x8005,data16)); if (access_type == PHY84328_I2CDEV_WRITE) { data16 = 0x8000 | PHY84328_BSC_WRITE_OP; } else { data16 = 0x8000 | PHY84328_BSC_READ_OP; } if (data_type == PHY84328_I2C_16BIT) { data16 |= (1 << 12); } /* Select first i2c port */ if (PHY84328_SINGLE_PORT_MODE(pc)) { SOC_IF_ERROR_RETURN (MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_MISC_CTRL, 0, PHY84328_DEV1_MISC_CTRL_I2C_PORT_SEL_MASK)); } else { SOC_IF_ERROR_RETURN (MODIFY_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_DEV1_MISC_CTRL, (pc->phy_id & 0x3), PHY84328_DEV1_MISC_CTRL_I2C_PORT_SEL_MASK)); } SOC_IF_ERROR_RETURN (WRITE_PHY84328_MMF_PMA_PMD_REG(unit, pc, 0x8000, data16)); #if defined(BROADCOM_DEBUG) || defined(DEBUG_PRINT) start = sal_time_usecs(); #endif soc_timeout_init(&to, 1000000, 0); while (!soc_timeout_check(&to)) { SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, 0x8000, &data16)); if (((data16 & PHY84328_2W_STAT) == PHY84328_2W_STAT_COMPLETE)) { break; } } #if defined(BROADCOM_DEBUG) || defined(DEBUG_PRINT) end = sal_time_usecs(); #endif /* need some delays */ sal_usleep(10000); #if defined(BROADCOM_DEBUG) || defined(DEBUG_PRINT) LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "BSC command status %d time=%d\n"), (data16 & PHY84328_2W_STAT), SAL_USECS_SUB(end, start))); #endif if (access_type == PHY84328_I2CDEV_WRITE) { return SOC_E_NONE; } if ((data16 & PHY84328_2W_STAT) == PHY84328_2W_STAT_COMPLETE) { for (i = 0; i < count; i++) { SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, (ram_start+i), &data16)); if (data_type == PHY84328_I2C_16BIT) { ((uint16 *)data_array)[i] = data16; LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "%04x "), data16)); } else { ((uint8 *)data_array)[i] = (uint8)data16; LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "%02x "), data16)); } } } return SOC_E_NONE; } /* * Read a slave device such as NVRAM/EEPROM connected to the 84328's I2C * interface. This function will be mainly used for diagnostic or workaround * purpose. * Note: * The size of read_array buffer must be greater than or equal to the * parameter nbytes. * usage example: * Retrieve the first 100 byte data of the non-volatile storage device with * I2C bus device address 0x50(default SPF eeprom I2C address) on unit 0, * port 2. * uint8 data8[100]; * phy_84328_i2cdev_read(0,2,0x50,0,100,data8); */ int phy_84328_i2cdev_read(int unit, soc_port_t port, int dev_addr, /* 7 bit I2C bus device address */ int offset, /* starting data address to read */ int nbytes, /* number of bytes to read */ uint8 *read_array) /* buffer to hold retrieved data */ { return _phy_84328_bsc_rw(unit, port, dev_addr,PHY84328_I2CDEV_READ, offset, nbytes, (void *)read_array,PHY84328_READ_START_ADDR); } /* * Write to a slave device such as NVRAM/EEPROM connected to the 84328's I2C * interface. This function will be mainly used for diagnostic or workaround * purpose. * Note: * The size of write_array buffer should be equal to the parameter nbytes. * The EEPROM may limit the maximun write size to 16 bytes * usage example: * Write to first 100 byte space of the non-volatile storage device with * I2C bus device address 0x50(default SPF eeprom I2C address) on unit 0, * port 2, with written data specified in array data8. * uint8 data8[100]; * *** initialize the data8 array with written data *** * * phy_84328_i2cdev_write(0,2,0x50,0,100,data8); */ int phy_84328_i2cdev_write(int unit, soc_port_t port, int dev_addr, /* I2C bus device address */ int offset, /* starting data address to write to */ int nbytes, /* number of bytes to write */ uint8 *write_array) /* buffer to hold written data */ { int j; int rv = SOC_E_NONE; for (j = 0; j < (nbytes/PHY84328_BSC_WR_MAX); j++) { rv = _phy_84328_bsc_rw(unit, port, dev_addr,PHY84328_I2CDEV_WRITE, offset + j * PHY84328_BSC_WR_MAX, PHY84328_BSC_WR_MAX, (void *)(write_array + j * PHY84328_BSC_WR_MAX), PHY84328_WRITE_START_ADDR); if (rv != SOC_E_NONE) { return rv; } sal_usleep(20000); } if (nbytes%PHY84328_BSC_WR_MAX) { rv = _phy_84328_bsc_rw(unit, port, dev_addr,PHY84328_I2CDEV_WRITE, offset + j * PHY84328_BSC_WR_MAX, nbytes%PHY84328_BSC_WR_MAX, (void *)(write_array + j * PHY84328_BSC_WR_MAX), PHY84328_WRITE_START_ADDR); } return rv; } /* * Function: * _phy_84328_reg_read * Purpose: * Routine to read PHY register * Parameters: * uint - BCM unit number * port - port number * flags - Flags which specify the register type * phy_reg_addr - Encoded register address * phy_data - (OUT) Value read from PHY register * Note: * This register read function is not thread safe. Higher level * function that calls this function must obtain a per port lock * to avoid overriding register page mapping between threads. */ STATIC int _phy_84328_reg_read(int unit, soc_port_t port, uint32 flags, uint32 phy_reg_addr, uint32 *phy_data) { uint16 data16; uint16 regdata; phy_ctrl_t *pc; /* PHY software state */ int rv = SOC_E_NONE; int rd_cnt; pc = EXT_PHY_SW_STATE(unit, port); rd_cnt = 1; if (flags & SOC_PHY_I2C_DATA8) { SOC_IF_ERROR_RETURN (phy_84328_i2cdev_read(unit, port, SOC_PHY_I2C_DEVAD(phy_reg_addr), SOC_PHY_I2C_REGAD(phy_reg_addr), rd_cnt, (uint8 *)&data16)); *phy_data = *((uint8 *)&data16); } else if (flags & SOC_PHY_I2C_DATA16) { /* This operation is generally targeted to access 16-bit device, * such as PHY IC inside the SFP. However there is no 16-bit * scratch register space on the device. Use 1.800e * for this operation. */ SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_I2C_TEMP_RAM, &regdata)); rv = _phy_84328_bsc_rw(unit, port, SOC_PHY_I2C_DEVAD(phy_reg_addr), PHY84328_I2C_OP_TYPE(PHY84328_I2CDEV_READ,PHY84328_I2C_16BIT), SOC_PHY_I2C_REGAD(phy_reg_addr),1, (void *)&data16,PHY84328_I2C_TEMP_RAM); *phy_data = data16; /* restore the ram register value */ SOC_IF_ERROR_RETURN (WRITE_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_I2C_TEMP_RAM, regdata)); } else { SOC_IF_ERROR_RETURN (READ_PHY_REG(unit, pc, phy_reg_addr, &data16)); *phy_data = data16; } return rv; } /* * Function: * _phy_84328_reg_write * Purpose: * Routine to write PHY register * Parameters: * uint - BCM unit number * port - port number * flags - Flags which specify the register type * phy_reg_addr - Encoded register address * phy_data - Value write to PHY register * Note: * This register read function is not thread safe. Higher level * function that calls this function must obtain a per port lock * to avoid overriding register page mapping between threads. */ STATIC int _phy_84328_reg_write(int unit, soc_port_t port, uint32 flags, uint32 phy_reg_addr, uint32 phy_data) { uint8 data8[4]; uint16 data16[2]; uint16 regdata[2]; phy_ctrl_t *pc; /* PHY software state */ int rv = SOC_E_NONE; int wr_cnt; pc = EXT_PHY_SW_STATE(unit, port); wr_cnt = 1; if (flags & SOC_PHY_I2C_DATA8) { data8[0] = (uint8)phy_data; SOC_IF_ERROR_RETURN (phy_84328_i2cdev_write(unit, port, SOC_PHY_I2C_DEVAD(phy_reg_addr), SOC_PHY_I2C_REGAD(phy_reg_addr), wr_cnt, data8)); } else if (flags & SOC_PHY_I2C_DATA16) { /* This operation is generally targeted to access 16-bit device, * such as PHY IC inside the SFP. However there is no 16-bit * scratch register space on the device. Use 1.800e * for this operation. */ /* save the temp ram register */ SOC_IF_ERROR_RETURN (READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_I2C_TEMP_RAM, &regdata[0])); data16[0] = phy_data; rv = _phy_84328_bsc_rw(unit, port, SOC_PHY_I2C_DEVAD(phy_reg_addr), PHY84328_I2C_OP_TYPE(PHY84328_I2CDEV_WRITE,PHY84328_I2C_16BIT), SOC_PHY_I2C_REGAD(phy_reg_addr),wr_cnt, (void *)data16,PHY84328_I2C_TEMP_RAM); /* restore the ram register value */ SOC_IF_ERROR_RETURN (WRITE_PHY84328_MMF_PMA_PMD_REG(unit, pc, PHY84328_I2C_TEMP_RAM, regdata[0])); } else { SOC_IF_ERROR_RETURN (WRITE_PHY_REG(unit, pc, phy_reg_addr, (uint16)phy_data)); } return rv; } void _phy_84328_dbg_reg_read(int unit, soc_port_t port, int reg) { uint16 data; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); if (pc == NULL) { return; } READ_PHY84328_MMF_PMA_PMD_REG(unit, pc, reg, &data); LOG_CLI((BSL_META_U(unit, "1.%04x=0x%04x\n"), reg, data)); } void _phy_84328_dbg_reg_write(int unit, soc_port_t port, int reg, uint16 val) { phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); if (pc == NULL) { return; } WRITE_PHY84328_MMF_PMA_PMD_REG(unit, pc, reg, val); _phy_84328_dbg_reg_read(unit, port, reg); } #ifdef PHY84328_MDIO_TRACING STATIC int _phy_84328_dbg_read(int unit, phy_ctrl_t *pc, uint32 addr, uint16 *data) { int rv; rv = (pc->read)(unit, pc->phy_id, addr, data); if (DBG_FLAGS(pc) & PHY84328_DBG_F_REG) { LOG_CLI((BSL_META_U(unit, "p%d(%d): READ addr=%04x data=%04x\n"), pc->port, pc->phy_id, addr, *data)); } return rv; } STATIC int _phy_84328_dbg_write(int unit, phy_ctrl_t *pc, uint32 addr, uint16 data) { int rv; if (DBG_FLAGS(pc) & PHY84328_DBG_F_REG) { LOG_CLI((BSL_META_U(unit, "p%d(%d): WRITE addr=%04x data=%04x\n"), pc->port, pc->phy_id, addr, data)); } rv = (pc->write)(unit, pc->phy_id, addr, data); return rv; } STATIC int _phy_84328_dbg_modify(int unit, phy_ctrl_t *pc, uint32 addr, uint16 data, uint16 mask) { int rv; if (DBG_FLAGS(pc) & PHY84328_DBG_F_REG) { LOG_CLI((BSL_META_U(unit, "p%d(%d): MODIFY addr=%04x data=%04x mask=%04x\n"), pc->port, pc->phy_id, addr, data, mask)); } rv = phy_reg_modify(unit, pc, addr, data, mask); return rv; } #endif /* PHY84328_MDIO_TRACING */ /******************************************************************************/ /* * Function: * phy_84328_probe * Purpose: * Complement the generic phy probe routine to identify this phy when its * phy id0 and id1 is same as some other phy's. * Parameters: * unit - StrataSwitch unit #. * pc - phy ctrl descriptor. * Returns: * SOC_E_NONE,SOC_E_NOT_FOUND and SOC_E_<error> */ STATIC int phy_84328_probe(int unit, phy_ctrl_t *pc) { int rv; char *dev_name = ""; uint16 prim_phy_id; int core, all_cores; soc_port_t port; pc->size = 0; port = pc->port; all_cores = PHY84328_CORES(unit, port); if (all_cores > PHY84328_MAX_CORES) { LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "u=%d p=%d: too many cores %d\n"), unit, port, all_cores)); return SOC_E_NOT_FOUND; } prim_phy_id = pc->phy_id; for (core = 0; core < all_cores; core++) { /* * During probe, reuse the pc for the port (first core only) as there are no * pc's allocated yet for the other cores */ pc->phy_id = _phy_84328_phy_id_get(pc, core); rv = _phy_84328_probe(unit, pc); pc->phy_id = prim_phy_id; if (rv != SOC_E_NONE) { return rv; } /* * Make sure the probed device name for all cores matches the first * core device name */ if (core == 0) { dev_name = pc->dev_name; } else if (pc->dev_name != dev_name) { LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "u=%d p=%d: all cores must have same device: core0=%s != core%d=%s\n"), unit, port, dev_name, core, pc->dev_name)); return SOC_E_NOT_FOUND; } } /* * Allocate one pc + one control block for each core */ pc->size = sizeof(phy84328_dev_desc_t) + ((all_cores - 1) * PHY84328_CORE_STATE_SIZE); return SOC_E_NONE; } STATIC void _phy_84328_init_setup(int unit, soc_port_t port) { int core, all_cores; phy_ctrl_t *core_pc; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); /* DBG_FLAGS(pc) = 0; */ DBG_FLAGS(pc) = PHY84328_DBG_F_API_SET | PHY84328_DBG_F_DWLD; all_cores = PHY84328_CORES(unit, port); for (core = 0; core < all_cores; core++) { core_pc = PHY84328_CORE_PC(pc, core); if (core > 0) { /* Copy state from core 0 pc to other core pcs */ sal_memcpy(core_pc, pc , sizeof(phy_ctrl_t)); /* Populate phy_id for core1..core2 */ core_pc->phy_id = _phy_84328_phy_id_get(pc, core); } CORE_NUM(core_pc) = core; if (all_cores > 1) { core_pc->phy_mode = PHYCTRL_MULTI_CORE_PORT; } } } STATIC int phy_84328_init(int unit, soc_port_t port) { int rv; int pass; int core, all_cores; phy_ctrl_t *core_pc; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); pass = PHYCTRL_INIT_STATE(pc); if (PHYCTRL_INIT_STATE(pc) == PHYCTRL_INIT_STATE_PASS1) { _phy_84328_init_setup(unit, port); } /* if (DBG_FLAGS(pc) & PHY84328_DBG_F_API_SET) { bsl_normal(BSL_APPL_SHELL, unit, "%s(%d, %d)\n", FUNCTION_NAME(), unit, port); } */ all_cores = PHY84328_CORES(unit, port); for (core = 0; core < all_cores; core++) { core_pc = PHY84328_CORE_PC(pc, core); PHY84328_CORE_STATE_SET(unit, port, core, pc); /* copy init state to core_pc */ PHYCTRL_INIT_STATE_SET(core_pc, pass); rv = _phy_84328_init(unit, port); PHY84328_CORE_STATE_SET(unit, port, 0, pc); if (rv != SOC_E_NONE) { return rv; } } return SOC_E_NONE; } STATIC int _phy84328_init_ucode_bcst(int unit, int port, int cmd) { int rv; int core, all_cores; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); all_cores = PHY84328_CORES(unit, port); /* * The actual load needs to happen only on the first core as the * other cores will be in broadcast mode */ if (cmd == PHYCTRL_UCODE_BCST_LOAD) { all_cores = 1; } for (core = 0; core < all_cores; core++) { PHY84328_CORE_STATE_SET(unit, port, core, pc); rv = __phy84328_init_ucode_bcst(unit, port, cmd); PHY84328_CORE_STATE_SET(unit, port, 0, pc); if (rv != SOC_E_NONE) { return rv; } } return SOC_E_NONE; } STATIC int phy_84328_firmware_set(int unit, int port, int offset, uint8 *array,int datalen) { /* phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); */ /* * When array==NULL, this function is used to broadcast the firmware. * array==NULL should be specified only for internal use */ /* if (DBG_FLAGS(pc) & PHY84328_DBG_F_API_SET) { bsl_normal(BSL_APPL_SHELL, unit, "%s(%d, %d)\n", FUNCTION_NAME(), unit, port); } */ if (array == NULL) { return _phy84328_init_ucode_bcst(unit, port, offset); } else { /* bsl_warning(BSL__X, unit, "u=%d p=%d firmware download method not supported\n", unit, port); */ return SOC_E_UNAVAIL; } return SOC_E_NONE; } STATIC int phy_84328_enable_set(int unit, soc_port_t port, int enable) { PHY84328_CALL_SET(unit, port, (_phy_84328_enable_set(unit, port, enable))); } STATIC int phy_84328_speed_set(int unit, soc_port_t port, int speed) { PHY84328_CALL_SET(unit, port, (_phy_84328_speed_set(unit, port, speed))); } STATIC int phy_84328_speed_get(int unit, soc_port_t port, int *speed) { int port_speed = 0; PHY84328_CALL_GET(unit, port, (_phy_84328_speed_get(unit, port, speed)), speed, port_speed); } STATIC int phy_84328_interface_set(int unit, soc_port_t port, soc_port_if_t pif) { PHY84328_CALL_SET(unit, port, (_phy_84328_interface_set(unit, port, pif))); } STATIC int phy_84328_interface_get(int unit, soc_port_t port, soc_port_if_t *pif) { soc_port_if_t port_pif = 0; PHY84328_CALL_GET(unit, port, (_phy_84328_interface_get(unit, port, pif)), pif, port_pif); } STATIC int phy_84328_lb_set(int unit, soc_port_t port, int enable) { PHY84328_CALL_SET(unit, port, (_phy_84328_lb_set(unit, port, enable))); } STATIC int phy_84328_lb_get(int unit, soc_port_t port, int *enable) { int port_enable = 0; PHY84328_CALL_GET(unit, port, (_phy_84328_lb_get(unit, port, enable)), enable, port_enable); } STATIC int phy_84328_link_get(int unit, soc_port_t port, int *link) { int port_link = 0; PHY84328_CALL_GET(unit, port, (_phy_84328_link_get(unit, port, link)), link, port_link); } STATIC int phy_84328_an_set(int unit, soc_port_t port, int an) { PHY84328_CALL_SET(unit, port, (_phy_84328_an_set(unit, port, an))); } STATIC int phy_84328_control_set(int unit, soc_port_t port, soc_phy_control_t type, uint32 value) { PHY84328_CALL_SET(unit, port, (phy_84328_control_port_set(unit, port, type, value))); } STATIC int phy_84328_control_get(int unit, soc_port_t port, soc_phy_control_t type, uint32 *value) { uint32 port_value = 0; PHY84328_CALL_GET(unit, port, (phy_84328_control_port_get(unit, port, type, value)), value, port_value); } STATIC int phy_84328_reg_write(int unit, soc_port_t port, uint32 flags, uint32 phy_reg_addr, uint32 phy_data) { #ifdef BCM_WARM_BOOT_SUPPORT if ( SOC_WARM_BOOT(unit) || SOC_IS_RELOADING(unit) ) { return SOC_E_NONE; } #endif PHY84328_CALL_SET(unit, port, (_phy_84328_reg_write(unit, port, flags, phy_reg_addr, phy_data))); } STATIC int phy_84328_reg_read(int unit, soc_port_t port, uint32 flags, uint32 phy_reg_addr, uint32 *phy_data) { uint32 port_phy_data = 0; PHY84328_CALL_GET(unit, port, (_phy_84328_reg_read( unit, port, flags, phy_reg_addr, phy_data)), phy_data, port_phy_data); } STATIC int phy_84328_ability_advert_set(int unit, soc_port_t port, soc_port_ability_t *ability) { PHY84328_CALL_SET(unit, port, (_phy_84328_ability_advert_set(unit, port, ability))); } STATIC int phy_84328_ability_advert_get(int unit, soc_port_t port, soc_port_ability_t *ability) { int rv; int core, all_cores; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); soc_port_ability_t port_ability; if (DBG_FLAGS(pc) & PHY84328_DBG_F_API_SET) { LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "%s(%d, %d)\n"), FUNCTION_NAME(), unit, port)); } all_cores = PHY84328_CORES(unit, port); for (core = 0; core < all_cores; core++) { PHY84328_CORE_STATE_SET(unit, port, core, pc); rv = _phy_84328_ability_advert_get(unit, port, ability); PHY84328_CORE_STATE_SET(unit, port, 0, pc); if (rv != SOC_E_NONE) { return rv; } if (core > 0) { if (sal_memcmp((const void *) &port_ability, (const void *) ability, sizeof(soc_port_ability_t))){ /* bsl_error(BSL__X, unit, "84328 %s : ability does not match " "for all cores: u=%d p=%d\n", FUNCTION_NAME(), unit, port ); */ } } else if (all_cores > 1) { sal_memcpy(&port_ability, ability , sizeof(soc_port_ability_t)); } } return SOC_E_NONE; } STATIC int phy_84328_diag_ctrl(int unit, soc_port_t port, uint32 inst, int op_type, int op_cmd, void *arg) { int rv = SOC_E_NONE; int core, all_cores; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); uint32 port_arg; if (DBG_FLAGS(pc) & PHY84328_DBG_F_API_SET) { LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "%s(%d, %d)\n"), FUNCTION_NAME(), unit, port)); } all_cores = PHY84328_CORES(unit, port); for (core = 0; core < all_cores; core++) { PHY84328_CORE_STATE_SET(unit, port, core, pc); switch(op_type) { case PHY_DIAG_CTRL_SET: case PHY_DIAG_CTRL_CMD: rv = (_phy_84328_diag_ctrl(unit, port, inst, op_type, op_cmd, arg)); break; case PHY_DIAG_CTRL_GET: rv = (_phy_84328_diag_ctrl(unit, port, inst, op_type, op_cmd, arg)); if (core > 0) { if (sal_memcmp((const void *) &port_arg, (const void *) arg, sizeof(port_arg))){ LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 %s : arg does not match " "for all cores: u=%d p=%d\n"), FUNCTION_NAME(), unit, port )); } } else if (all_cores > 1) { sal_memcpy(&port_arg, arg , sizeof(port_arg)); } break; default: LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 diag_ctrl bad operation: u=%d p=%d ctrl=0x%x\n"), unit, port, op_cmd)); rv = SOC_E_UNAVAIL; break; } PHY84328_CORE_STATE_SET(unit, port, 0, pc); if (rv != SOC_E_NONE) { return rv; } } return SOC_E_NONE; } STATIC int phy_84328_ability_remote_get(int unit, soc_port_t port, soc_port_ability_t *ability) { int rv; int core, all_cores; phy_ctrl_t *pc = EXT_PHY_SW_STATE(unit, port); soc_port_ability_t port_ability; if (DBG_FLAGS(pc) & PHY84328_DBG_F_API_SET) { LOG_INFO(BSL_LS_SOC_PHY, (BSL_META_U(unit, "%s(%d, %d)\n"), FUNCTION_NAME(), unit, port)); } all_cores = PHY84328_CORES(unit, port); for (core = 0; core < all_cores; core++) { PHY84328_CORE_STATE_SET(unit, port, core, pc); rv = _phy_84328_ability_remote_get(unit, port, ability); PHY84328_CORE_STATE_SET(unit, port, 0, pc); if (rv != SOC_E_NONE) { return rv; } if (core > 0) { if (sal_memcmp((const void *) &port_ability, (const void *) ability, sizeof(soc_port_ability_t))){ /* LOG_ERROR(BSL_LS_SOC_PHY, (BSL_META_U(unit, "84328 %s : ability does not match " "for all cores: u=%d p=%d\n"), FUNCTION_NAME(), unit, port )); */ } } else if (all_cores > 1) { sal_memcpy(&port_ability, ability , sizeof(soc_port_ability_t)); } } return SOC_E_NONE; } /* * Variable: * phy_84328_drv * Purpose: * Phy Driver for 40G PHY. */ phy_driver_t phy_84328drv_xe = { "84328 40-Gigabit PHY Driver", phy_84328_init, /* Init */ phy_null_reset, /* Reset (dummy) */ phy_84328_link_get, /* Link get */ phy_84328_enable_set, /* Enable set */ phy_null_enable_get, /* Enable get */ phy_null_set, /* Duplex set */ phy_null_one_get, /* Duplex get */ phy_84328_speed_set, /* Speed set */ phy_84328_speed_get, /* Speed get */ phy_null_set, /* Master set */ phy_null_zero_get, /* Master get */ phy_84328_an_set, /* ANA set */ phy_84328_an_get, /* ANA get */ NULL, /* Local Advert set */ NULL, /* Local Advert get */ phy_null_mode_get, /* Remote Advert get */ phy_84328_lb_set, /* PHY loopback set */ phy_84328_lb_get, /* PHY loopback set */ phy_84328_interface_set, /* IO Interface set */ phy_84328_interface_get, /* IO Interface get */ NULL, /* PHY abilities mask */ NULL, NULL, phy_null_mdix_set, phy_null_mdix_get, phy_null_mdix_status_get, NULL, NULL, phy_null_medium_get, NULL, /* phy_cable_diag */ NULL, /* phy_link_change */ phy_84328_control_set, /* phy_control_set */ phy_84328_control_get, /* phy_control_get */ phy_84328_reg_read, /* phy_reg_read */ phy_84328_reg_write, /* phy_reg_write */ NULL, /* phy_reg_modify */ NULL, /* phy_notify */ phy_84328_probe, /* pd_probe */ phy_84328_ability_advert_set, /* pd_ability_advert_set */ phy_84328_ability_advert_get, /* pd_ability_advert_get */ phy_84328_ability_remote_get, /* pd_ability_remote_get */ phy_84328_ability_local_get, /* pd_ability_local_get */ phy_84328_firmware_set, /* pd_firmware_set */ NULL, /* pd_timesync_config_set */ NULL, /* pd_timesync_config_get */ NULL, /* pd_timesync_control_set */ NULL, /* pd_timesync_control_get */ phy_84328_diag_ctrl, /* .pd_diag_ctrl */ NULL, /* pd_lane_control_set */ NULL, /* pd_lane_control_get */ NULL, /* pd_lane_reg_read */ NULL, /* pd_lane_reg_write */ NULL, /* pd_oam_config_set */ NULL, /* pd_oam_config_get */ NULL, /* pd_oam_control_set */ NULL, /* pd_oam_control_get */ NULL, /* pd_timesync_enhanced_capture_get */ NULL, /* pd_multi_get */ phy_84328_precondition_before_probe /* pd_precondition_before_probe */ }; #else /* INCLUDE_PHY_84328 */ typedef int _phy_84328_not_empty; /* Make ISO compilers happy. */ #endif /* INCLUDE_PHY_84328 */
the_stack_data/165764241.c
#include <stdio.h> #include <stdlib.h> struct Nodo { struct Nodo *padre; struct Nodo *izquierdo; struct Nodo *derecho; int valor; }; struct Nodo *crearNodo(struct Nodo *padre, int valor); void agregarValor(struct Nodo *arbol, int valor); struct Nodo *iniciarArbol(); int main() { struct Nodo *arbol; arbol = iniciarArbol(); agregarValor(arbol, 10); agregarValor(arbol, 20); agregarValor(arbol, 30); } struct Nodo *iniciarArbol() { return crearNodo(NULL, 100); } struct Nodo *crearNodo(struct Nodo *padre, int valor) { struct Nodo *nodo; nodo = calloc(sizeof(struct Nodo), 1); nodo->padre = padre; nodo->valor = valor; return nodo; } void agregarValor(struct Nodo *arbol, int valor) { struct Nodo *temp, *pivote; int derecho = 0; if (arbol) { temp = arbol; while (temp != NULL) { pivote = temp; if (valor > temp->valor) { temp = temp->derecho; derecho = 1; //derecho } else { temp = temp->izquierdo; derecho = 0; //izquierdo } temp = crearNodo(pivote, valor); if (derecho) { printf("insertando %i del lado derecho de %i", valor, pivote->valor); pivote->derecho = temp; } else { printf("insertando %i del lado izquierdo de %i", valor, pivote->valor); pivote->izquierdo = temp; } } } else { printf("Error el arbol es NULL"); } }
the_stack_data/95449859.c
/* * Man page to HTML conversion program. * * Copyright © 2015-2020 by Michael R Sweet * Copyright © 2007-2010, 2014 by Apple Inc. * Copyright © 2004-2006 by Easy Software Products. * * These coded instructions, statements, and computer programs are the * property of Apple Inc. and are protected by Federal copyright * law. Distribution and use rights are outlined in the file "LICENSE.txt" * which should have been included with this file. If this file is * file is missing or damaged, see the license at "http://www.cups.org/". */ /* * Include necessary headers. */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <unistd.h> /* * Local globals... */ static const char /* Start/end tags for fonts */ * const start_fonts[] = { "", "<b>", "<i>" }, * const end_fonts[] = { "", "</b>", "</i>" }; /* * Local functions... */ static void html_alternate(const char *s, const char *first, const char *second, FILE *fp); static void html_fputs(const char *s, int *font, FILE *fp); static void html_putc(int ch, FILE *fp); static void strmove(char *d, const char *s); /* * 'main()' - Convert a man page to HTML. */ int /* O - Exit status */ main(int argc, /* I - Number of command-line args */ char *argv[]) /* I - Command-line arguments */ { FILE *infile, /* Input file */ *outfile; /* Output file */ char line[1024], /* Line from file */ *lineptr, /* Pointer into line */ anchor[1024], /* Anchor */ name[1024], /* Man page name */ ddpost[256]; /* Tagged list post markup */ int section = -1, /* Man page section */ pre = 0, /* Preformatted */ font = 0, /* Current font */ linenum = 0; /* Current line number */ float list_indent = 0.0f, /* Current list indentation */ nested_indent = 0.0f; /* Nested list indentation, if any */ const char *list = NULL, /* Current list, if any */ *nested = NULL; /* Nested list, if any */ const char *post = NULL; /* Text to add after the current line */ /* * Check arguments... */ if (argc > 3) { fputs("Usage: mantohtml [filename.man [filename.html]]\n", stderr); return (1); } /* * Open files as needed... */ if (argc > 1) { if ((infile = fopen(argv[1], "r")) == NULL) { perror(argv[1]); return (1); } } else infile = stdin; if (argc > 2) { if ((outfile = fopen(argv[2], "w")) == NULL) { perror(argv[2]); fclose(infile); return (1); } } else outfile = stdout; /* * Read from input and write the output... */ fputs("<!DOCTYPE HTML>\n" "<html>\n" "<!-- SECTION: Man Pages -->\n" "<head>\n" "\t<link rel=\"stylesheet\" type=\"text/css\" " "href=\"../cups-printable.css\">\n", outfile); anchor[0] = '\0'; while (fgets(line, sizeof(line), infile)) { size_t linelen = strlen(line); /* Length of line */ if (linelen > 0 && line[linelen - 1] == '\n') line[linelen - 1] = '\0'; linenum ++; if (line[0] == '.') { /* * Strip leading whitespace... */ while (line[1] == ' ' || line[1] == '\t') strmove(line + 1, line + 2); /* * Process man page commands... */ if (!strncmp(line, ".TH ", 4) && section < 0) { /* * Grab man page title... */ sscanf(line + 4, "%s%d", name, &section); fprintf(outfile, "\t<title>%s(%d)</title>\n" "</head>\n" "<body>\n" "<h2 class=\"title\"><a name=\"%s\">%s(%d)</a></h2>\n" "%s", name, section, name, name, section, start_fonts[font]); } else if (section < 0) continue; else if (!strncmp(line, ".SH ", 4) || !strncmp(line, ".SS ", 4)) { /* * Grab heading... */ int first = 1; fputs(end_fonts[font], outfile); font = 0; if (list) { fprintf(outfile, "</%s>\n", list); list = NULL; } if (line[2] == 'H') fputs("<h3 class=\"title\"><a name=\"", outfile); else fputs("<h4><a name=\"", outfile); if (anchor[0]) { fputs(anchor, outfile); anchor[0] = '\0'; } else { for (lineptr = line + 4; *lineptr; lineptr ++) if (*lineptr == '\"') continue; else if (isalnum(*lineptr & 255)) html_putc(*lineptr, outfile); else html_putc('_', outfile); } fputs("\">", outfile); for (lineptr = line + 4; *lineptr; lineptr ++) { if (*lineptr == '\"') continue; else if (*lineptr == ' ') { html_putc(' ', outfile); first = 1; } else { if (first) html_putc(*lineptr, outfile); else html_putc(tolower(*lineptr & 255), outfile); first = 0; } } if (line[2] == 'H') fputs("</a></h3>\n", outfile); else fputs("</a></h4>\n", outfile); } else if (!strncmp(line, ".B ", 3)) { /* * Grab bold text... */ fputs(end_fonts[font], outfile); font = 0; if (anchor[0]) fprintf(outfile, "<a name=\"%s\">", anchor); html_alternate(line + 3, "b", "b", outfile); if (anchor[0]) { fputs("</a>", outfile); anchor[0] = '\0'; } if (post) { fputs(post, outfile); post = NULL; } } else if (!strncmp(line, ".I ", 3)) { /* * Grab italic text... */ fputs(end_fonts[font], outfile); font = 0; if (anchor[0]) fprintf(outfile, "<a name=\"%s\">", anchor); html_alternate(line + 3, "i", "i", outfile); if (anchor[0]) { fputs("</a>", outfile); anchor[0] = '\0'; } if (post) { fputs(post, outfile); post = NULL; } } else if (!strncmp(line, ".BI ", 4)) { /* * Alternating bold and italic text... */ fputs(end_fonts[font], outfile); font = 0; if (anchor[0]) fprintf(outfile, "<a name=\"%s\">", anchor); html_alternate(line + 4, "b", "i", outfile); if (anchor[0]) { fputs("</a>", outfile); anchor[0] = '\0'; } if (post) { fputs(post, outfile); post = NULL; } } else if (!strncmp(line, ".BR ", 4)) { /* * Alternating bold and roman (plain) text... */ fputs(end_fonts[font], outfile); font = 0; if (anchor[0]) fprintf(outfile, "<a name=\"%s\">", anchor); html_alternate(line + 4, "b", NULL, outfile); if (anchor[0]) { fputs("</a>", outfile); anchor[0] = '\0'; } if (post) { fputs(post, outfile); post = NULL; } } else if (!strncmp(line, ".IB ", 4)) { /* * Alternating italic and bold text... */ fputs(end_fonts[font], outfile); font = 0; if (anchor[0]) fprintf(outfile, "<a name=\"%s\">", anchor); html_alternate(line + 4, "i", "b", outfile); if (anchor[0]) { fputs("</a>", outfile); anchor[0] = '\0'; } if (post) { fputs(post, outfile); post = NULL; } } else if (!strncmp(line, ".IR ", 4)) { /* * Alternating italic and roman (plain) text... */ fputs(end_fonts[font], outfile); font = 0; if (anchor[0]) fprintf(outfile, "<a name=\"%s\">", anchor); html_alternate(line + 4, "i", NULL, outfile); if (anchor[0]) { fputs("</a>", outfile); anchor[0] = '\0'; } if (post) { fputs(post, outfile); post = NULL; } } else if (!strncmp(line, ".RB ", 4)) { /* * Alternating roman (plain) and bold text... */ fputs(end_fonts[font], outfile); font = 0; if (anchor[0]) fprintf(outfile, "<a name=\"%s\">", anchor); html_alternate(line + 4, NULL, "b", outfile); if (anchor[0]) { fputs("</a>", outfile); anchor[0] = '\0'; } if (post) { fputs(post, outfile); post = NULL; } } else if (!strncmp(line, ".RI ", 4)) { /* * Alternating roman (plain) and italic text... */ fputs(end_fonts[font], outfile); font = 0; if (anchor[0]) fprintf(outfile, "<a name=\"%s\">", anchor); html_alternate(line + 4, NULL, "i", outfile); if (anchor[0]) { fputs("</a>", outfile); anchor[0] = '\0'; } if (post) { fputs(post, outfile); post = NULL; } } else if (!strncmp(line, ".SB ", 4)) { /* * Alternating small and bold text... */ fputs(end_fonts[font], outfile); font = 0; if (anchor[0]) fprintf(outfile, "<a name=\"%s\">", anchor); html_alternate(line + 4, "small", "b", outfile); if (anchor[0]) { fputs("</a>", outfile); anchor[0] = '\0'; } if (post) { fputs(post, outfile); post = NULL; } } else if (!strncmp(line, ".SM ", 4)) { /* * Small text... */ fputs(end_fonts[font], outfile); font = 0; if (anchor[0]) fprintf(outfile, "<a name=\"%s\">", anchor); html_alternate(line + 4, "small", "small", outfile); if (anchor[0]) { fputs("</a>", outfile); anchor[0] = '\0'; } if (post) { fputs(post, outfile); post = NULL; } } else if (!strcmp(line, ".LP") || !strcmp(line, ".PP") || !strcmp(line, ".P")) { /* * New paragraph... */ fputs(end_fonts[font], outfile); font = 0; if (list) { fprintf(outfile, "</%s>\n", list); list = NULL; } fputs("<p>", outfile); if (anchor[0]) { fprintf(outfile, "<a name=\"%s\"></a>", anchor); anchor[0] = '\0'; } } else if (!strcmp(line, ".RS") || !strncmp(line, ".RS ", 4)) { /* * Indent... */ float amount = 3.0; /* Indentation */ if (line[3]) amount = atof(line + 4); fputs(end_fonts[font], outfile); font = 0; if (list) { nested = list; list = NULL; nested_indent = list_indent; list_indent = 0.0f; } fprintf(outfile, "<div style=\"margin-left: %.1fem;\">\n", amount - nested_indent); } else if (!strcmp(line, ".RE")) { /* * Unindent... */ fputs(end_fonts[font], outfile); font = 0; fputs("</div>\n", outfile); if (nested) { list = nested; nested = NULL; list_indent = nested_indent; nested_indent = 0.0f; } } else if (!strcmp(line, ".HP") || !strncmp(line, ".HP ", 4)) { /* * Hanging paragraph... * * .HP i */ float amount = 3.0; /* Indentation */ if (line[3]) amount = atof(line + 4); fputs(end_fonts[font], outfile); font = 0; if (list) { fprintf(outfile, "</%s>\n", list); list = NULL; } fprintf(outfile, "<p style=\"margin-left: %.1fem; text-indent: %.1fem\">", amount, -amount); if (anchor[0]) { fprintf(outfile, "<a name=\"%s\"></a>", anchor); anchor[0] = '\0'; } if (line[1] == 'T') post = "<br>\n"; } else if (!strcmp(line, ".TP") || !strncmp(line, ".TP ", 4)) { /* * Tagged list... * * .TP i */ float amount = 3.0; /* Indentation */ if (line[3]) amount = atof(line + 4); fputs(end_fonts[font], outfile); font = 0; if (list && strcmp(list, "dl")) { fprintf(outfile, "</%s>\n", list); list = NULL; } if (!list) { fputs("<dl class=\"man\">\n", outfile); list = "dl"; list_indent = amount; } fputs("<dt>", outfile); snprintf(ddpost, sizeof(ddpost), "<dd style=\"margin-left: %.1fem\">", amount); post = ddpost; if (anchor[0]) { fprintf(outfile, "<a name=\"%s\"></a>", anchor); anchor[0] = '\0'; } } else if (!strncmp(line, ".IP ", 4)) { /* * Indented paragraph... * * .IP x i */ float amount = 3.0; /* Indentation */ const char *newlist = NULL; /* New list style */ const char *newtype = NULL; /* New list numbering type */ fputs(end_fonts[font], outfile); font = 0; lineptr = line + 4; while (isspace(*lineptr & 255)) lineptr ++; if (!strncmp(lineptr, "\\(bu", 4) || !strncmp(lineptr, "\\(em", 4)) { /* * Bullet list... */ newlist = "ul"; } else if (isdigit(*lineptr & 255)) { /* * Numbered list... */ newlist = "ol"; } else if (islower(*lineptr & 255)) { /* * Lowercase alpha list... */ newlist = "ol"; newtype = "a"; } else if (isupper(*lineptr & 255)) { /* * Lowercase alpha list... */ newlist = "ol"; newtype = "A"; } while (!isspace(*lineptr & 255)) lineptr ++; while (isspace(*lineptr & 255)) lineptr ++; if (isdigit(*lineptr & 255)) amount = atof(lineptr); if (newlist && list && strcmp(newlist, list)) { fprintf(outfile, "</%s>\n", list); list = NULL; } if (newlist && !list) { if (newtype) fprintf(outfile, "<%s type=\"%s\">\n", newlist, newtype); else fprintf(outfile, "<%s>\n", newlist); list = newlist; } if (list) fprintf(outfile, "<li style=\"margin-left: %.1fem;\">", amount); else fprintf(outfile, "<p style=\"margin-left: %.1fem;\">", amount); if (anchor[0]) { fprintf(outfile, "<a name=\"%s\"></a>", anchor); anchor[0] = '\0'; } } else if (!strncmp(line, ".br", 3)) { /* * Grab line break... */ fputs("<br>\n", outfile); } else if (!strncmp(line, ".de ", 4)) { /* * Define macro - ignore... */ while (fgets(line, sizeof(line), infile)) { linenum ++; if (!strncmp(line, "..", 2)) break; } } else if (!strncmp(line, ".ds ", 4) || !strncmp(line, ".rm ", 4) || !strncmp(line, ".tr ", 4) || !strncmp(line, ".hy ", 4) || !strncmp(line, ".IX ", 4) || !strncmp(line, ".PD", 3) || !strncmp(line, ".Sp", 3)) { /* * Ignore unused commands... */ } else if (!strncmp(line, ".Vb", 3) || !strncmp(line, ".nf", 3) || !strncmp(line, ".EX", 3)) { /* * Start preformatted... */ fputs(end_fonts[font], outfile); font = 0; // if (list) // { // fprintf(outfile, "</%s>\n", list); // list = NULL; // } pre = 1; fputs("<pre class=\"man\">\n", outfile); } else if (!strncmp(line, ".Ve", 3) || !strncmp(line, ".fi", 3) || !strncmp(line, ".EE", 3)) { /* * End preformatted... */ fputs(end_fonts[font], outfile); font = 0; if (pre) { pre = 0; fputs("</pre>\n", outfile); } } else if (!strncmp(line, ".\\}", 3)) { /* * Ignore close block... */ } else if (!strncmp(line, ".ie", 3) || !strncmp(line, ".if", 3) || !strncmp(line, ".el", 3)) { /* * If/else - ignore... */ if (strchr(line, '{') != NULL) { /* * Skip whole block... */ while (fgets(line, sizeof(line), infile)) { linenum ++; if (strchr(line, '}') != NULL) break; } } } #if 0 else if (!strncmp(line, ". ", 4)) { /* * Grab ... */ } #endif /* 0 */ else if (!strncmp(line, ".\\\"#", 4)) { /* * Anchor for HTML output... */ strncpy(anchor, line + 4, sizeof(anchor) - 1); anchor[sizeof(anchor) - 1] = '\0'; } else if (strncmp(line, ".\\\"", 3)) { /* * Unknown... */ if ((lineptr = strchr(line, ' ')) != NULL) *lineptr = '\0'; else if ((lineptr = strchr(line, '\n')) != NULL) *lineptr = '\0'; fprintf(stderr, "mantohtml: Unknown man page command \'%s\' on line %d.\n", line, linenum); } /* * Skip continuation lines... */ lineptr = line + strlen(line) - 1; if (lineptr >= line && *lineptr == '\\') { while (fgets(line, sizeof(line), infile)) { linenum ++; lineptr = line + strlen(line) - 2; if (lineptr < line || *lineptr != '\\') break; } } } else { /* * Process man page text... */ html_fputs(line, &font, outfile); putc('\n', outfile); if (post) { fputs(post, outfile); post = NULL; } } } fprintf(outfile, "%s\n", end_fonts[font]); font = 0; if (list) { fprintf(outfile, "</%s>\n", list); list = NULL; } fputs("</body>\n" "</html>\n", outfile); /* * Close files... */ if (infile != stdin) fclose(infile); if (outfile != stdout) fclose(outfile); /* * Return with no errors... */ return (0); } /* * 'html_alternate()' - Alternate words between two styles of text. */ static void html_alternate(const char *s, /* I - String */ const char *first, /* I - First style or NULL */ const char *second, /* I - Second style of NULL */ FILE *fp) /* I - File */ { int i = 0; /* Which style */ int quote = 0; /* Saw quote? */ int dolinks, /* Do hyperlinks to other man pages? */ link = 0; /* Doing a link now? */ /* * Skip leading whitespace... */ while (isspace(*s & 255)) s ++; dolinks = first && !strcmp(first, "b") && !second; while (*s) { if (!i && dolinks) { /* * See if we need to make a link to a man page... */ const char *end; /* End of current word */ const char *next; /* Start of next word */ for (end = s; *end && !isspace(*end & 255); end ++); for (next = end; isspace(*next & 255); next ++); if (isalnum(*s & 255) && *next == '(') { /* * See if the man file is available locally... */ char name[1024], /* Name */ manfile[1024], /* Man page filename */ manurl[1024]; /* Man page URL */ strncpy(name, s, sizeof(name) - 1); name[sizeof(name) - 1] = '\0'; if ((size_t)(end - s) < sizeof(name)) name[end - s] = '\0'; snprintf(manfile, sizeof(manfile), "%s.man", name); snprintf(manurl, sizeof(manurl), "%s.html#%s", name, name); if (!access(manfile, 0)) { /* * Local man page, do a link... */ fprintf(fp, "<a href=\"%s\">", manurl); link = 1; } } } if (!i && first) fprintf(fp, "<%s>", first); else if (i && second) fprintf(fp, "<%s>", second); while ((!isspace(*s & 255) || quote) && *s) { if (*s == '\"') quote = !quote; else if (*s == '\\' && s[1]) { s ++; html_putc(*s++, fp); } else html_putc(*s++, fp); } if (!i && first) fprintf(fp, "</%s>", first); else if (i && second) fprintf(fp, "</%s>", second); if (i && link) { fputs("</a>", fp); link = 0; } i = 1 - i; /* * Skip trailing whitespace... */ while (isspace(*s & 255)) s ++; } putc('\n', fp); } /* * 'html_fputs()' - Output a string, quoting as needed HTML entities. */ static void html_fputs(const char *s, /* I - String */ int *font, /* IO - Font */ FILE *fp) /* I - File */ { while (*s) { if (*s == '\\') { s ++; if (!*s) break; if (*s == 'f') { int newfont; /* New font */ s ++; if (!*s) break; if (!font) { s ++; continue; } switch (*s++) { case 'R' : case 'P' : newfont = 0; break; case 'b' : case 'B' : newfont = 1; break; case 'i' : case 'I' : newfont = 2; break; default : fprintf(stderr, "mantohtml: Unknown font \"\\f%c\" ignored.\n", s[-1]); newfont = *font; break; } if (newfont != *font) { fputs(end_fonts[*font], fp); *font = newfont; fputs(start_fonts[*font], fp); } } else if (*s == '*') { /* * Substitute macro... */ s ++; if (!*s) break; switch (*s++) { case 'R' : fputs("&reg;", fp); break; case '(' : if (!strncmp(s, "lq", 2)) fputs("&ldquo;", fp); else if (!strncmp(s, "rq", 2)) fputs("&rdquo;", fp); else if (!strncmp(s, "Tm", 2)) fputs("<sup>TM</sup>", fp); else fprintf(stderr, "mantohtml: Unknown macro \"\\*(%2s\" ignored.\n", s); if (*s) s ++; if (*s) s ++; break; default : fprintf(stderr, "mantohtml: Unknown macro \"\\*%c\" ignored.\n", s[-1]); break; } } else if (*s == '(') { if (!strncmp(s, "(em", 3)) { fputs("&mdash;", fp); s += 3; } else if (!strncmp(s, "(en", 3)) { fputs("&ndash;", fp); s += 3; } else { putc(*s, fp); s ++; } } else if (*s == '[') { /* * Substitute escaped character... */ s ++; if (!strncmp(s, "co]", 3)) fputs("&copy;", fp); else if (!strncmp(s, "de]", 3)) fputs("&deg;", fp); else if (!strncmp(s, "rg]", 3)) fputs("&reg;", fp); else if (!strncmp(s, "tm]", 3)) fputs("<sup>TM</sup>", fp); if (*s) s ++; if (*s) s ++; if (*s) s ++; } else if (isdigit(s[0]) && isdigit(s[1]) && isdigit(s[2])) { fprintf(fp, "&#%d;", ((s[0] - '0') * 8 + s[1] - '0') * 8 + s[2] - '0'); s += 3; } else { if (*s != '\\' && *s == '\"' && *s == '\'' && *s == '-') fprintf(stderr, "mantohtml: Unrecognized escape \"\\%c\" ignored.\n", *s); html_putc(*s++, fp); } } else if (!strncmp(s, "http://", 7) || !strncmp(s, "https://", 8) || !strncmp(s, "ftp://", 6)) { /* * Embed URL... */ char temp[1024]; /* Temporary string */ const char *end = s + 6; /* End of URL */ while (*end && !isspace(*end & 255)) end ++; if (end[-1] == ',' || end[-1] == '.' || end[-1] == ')') end --; strncpy(temp, s, sizeof(temp) - 1); temp[sizeof(temp) - 1] = '\0'; if ((size_t)(end -s) < sizeof(temp)) temp[end - s] = '\0'; fprintf(fp, "<a href=\"%s\">%s</a>", temp, temp); s = end; } else html_putc(*s++ & 255, fp); } } /* * 'html_putc()' - Put a single character, using entities as needed. */ static void html_putc(int ch, /* I - Character */ FILE *fp) /* I - File */ { if (ch == '&') fputs("&amp;", fp); else if (ch == '<') fputs("&lt;", fp); else putc(ch, fp); } /* * 'strmove()' - Move characters within a string. */ static void strmove(char *d, /* I - Destination */ const char *s) /* I - Source */ { while (*s) *d++ = *s++; *d = '\0'; }
the_stack_data/1199980.c
const char spp_pipe_pmd_info[] __attribute__((used)) = "PMD_INFO_STRING= {\"name\" : \"spp_pipe\", \"params\" : \"rx=<rx_ring> tx=<tx_ring>\", \"pci_ids\" : []}";
the_stack_data/680718.c
extern const unsigned char TestingVersionString[]; extern const double TestingVersionNumber; const unsigned char TestingVersionString[] __attribute__ ((used)) = "@(#)PROGRAM:Testing PROJECT:SwiftUtilities-1" "\n"; const double TestingVersionNumber __attribute__ ((used)) = (double)1.;
the_stack_data/120851.c
#include <stdio.h> #define Max 10000 void ler_vetor(int vet[],int n) { int i; for(i=0;i<n;i++) scanf("%d",&vet[i]); } void busca_maior(int vet[], int n) { int i, maior, indice; maior=-99999; for(i=0;i<n;i++) if(maior<vet[i]) { indice =i; maior = vet[i]; } printf("%d %d\n",indice, maior); } int main() { int n, vetor[Max]; scanf("%d",&n); while(n!=0) { ler_vetor(vetor,n); busca_maior(vetor,n); scanf("%d",&n); } return 0; }
the_stack_data/9513116.c
extern float __VERIFIER_nondet_float(void); extern int __VERIFIER_nondet_int(void); typedef enum {false, true} bool; bool __VERIFIER_nondet_bool(void) { return __VERIFIER_nondet_int() != 0; } int main() { bool _J879, _x__J879; bool _J866, _x__J866; bool _EL_U_847, _x__EL_U_847; float x_5, _x_x_5; float x_4, _x_x_4; float x_14, _x_x_14; float x_0, _x_x_0; float x_6, _x_x_6; bool _EL_U_851, _x__EL_U_851; float x_9, _x_x_9; float x_2, _x_x_2; float x_1, _x_x_1; float x_10, _x_x_10; float x_15, _x_x_15; float x_3, _x_x_3; float x_8, _x_x_8; float x_12, _x_x_12; float x_13, _x_x_13; float x_7, _x_x_7; float x_11, _x_x_11; int __steps_to_fair = __VERIFIER_nondet_int(); _J879 = __VERIFIER_nondet_bool(); _J866 = __VERIFIER_nondet_bool(); _EL_U_847 = __VERIFIER_nondet_bool(); x_5 = __VERIFIER_nondet_float(); x_4 = __VERIFIER_nondet_float(); x_14 = __VERIFIER_nondet_float(); x_0 = __VERIFIER_nondet_float(); x_6 = __VERIFIER_nondet_float(); _EL_U_851 = __VERIFIER_nondet_bool(); x_9 = __VERIFIER_nondet_float(); x_2 = __VERIFIER_nondet_float(); x_1 = __VERIFIER_nondet_float(); x_10 = __VERIFIER_nondet_float(); x_15 = __VERIFIER_nondet_float(); x_3 = __VERIFIER_nondet_float(); x_8 = __VERIFIER_nondet_float(); x_12 = __VERIFIER_nondet_float(); x_13 = __VERIFIER_nondet_float(); x_7 = __VERIFIER_nondet_float(); x_11 = __VERIFIER_nondet_float(); bool __ok = (1 && (((_EL_U_851 || ( !(( !(-12.0 <= (x_0 + (-1.0 * x_14)))) || ( !(( !(-10.0 <= (x_4 + (-1.0 * x_5)))) || _EL_U_847))))) && ( !_J866)) && ( !_J879))); while (__steps_to_fair >= 0 && __ok) { if ((_J866 && _J879)) { __steps_to_fair = __VERIFIER_nondet_int(); } else { __steps_to_fair--; } _x__J879 = __VERIFIER_nondet_bool(); _x__J866 = __VERIFIER_nondet_bool(); _x__EL_U_847 = __VERIFIER_nondet_bool(); _x_x_5 = __VERIFIER_nondet_float(); _x_x_4 = __VERIFIER_nondet_float(); _x_x_14 = __VERIFIER_nondet_float(); _x_x_0 = __VERIFIER_nondet_float(); _x_x_6 = __VERIFIER_nondet_float(); _x__EL_U_851 = __VERIFIER_nondet_bool(); _x_x_9 = __VERIFIER_nondet_float(); _x_x_2 = __VERIFIER_nondet_float(); _x_x_1 = __VERIFIER_nondet_float(); _x_x_10 = __VERIFIER_nondet_float(); _x_x_15 = __VERIFIER_nondet_float(); _x_x_3 = __VERIFIER_nondet_float(); _x_x_8 = __VERIFIER_nondet_float(); _x_x_12 = __VERIFIER_nondet_float(); _x_x_13 = __VERIFIER_nondet_float(); _x_x_7 = __VERIFIER_nondet_float(); _x_x_11 = __VERIFIER_nondet_float(); __ok = ((((((((((((((((((((x_12 + (-1.0 * _x_x_0)) <= -7.0) && (((x_11 + (-1.0 * _x_x_0)) <= -18.0) && (((x_10 + (-1.0 * _x_x_0)) <= -16.0) && (((x_8 + (-1.0 * _x_x_0)) <= -14.0) && (((x_3 + (-1.0 * _x_x_0)) <= -7.0) && (((x_2 + (-1.0 * _x_x_0)) <= -1.0) && (((x_0 + (-1.0 * _x_x_0)) <= -12.0) && ((x_1 + (-1.0 * _x_x_0)) <= -13.0)))))))) && (((x_12 + (-1.0 * _x_x_0)) == -7.0) || (((x_11 + (-1.0 * _x_x_0)) == -18.0) || (((x_10 + (-1.0 * _x_x_0)) == -16.0) || (((x_8 + (-1.0 * _x_x_0)) == -14.0) || (((x_3 + (-1.0 * _x_x_0)) == -7.0) || (((x_2 + (-1.0 * _x_x_0)) == -1.0) || (((x_0 + (-1.0 * _x_x_0)) == -12.0) || ((x_1 + (-1.0 * _x_x_0)) == -13.0))))))))) && ((((x_15 + (-1.0 * _x_x_1)) <= -6.0) && (((x_14 + (-1.0 * _x_x_1)) <= -16.0) && (((x_12 + (-1.0 * _x_x_1)) <= -19.0) && (((x_10 + (-1.0 * _x_x_1)) <= -17.0) && (((x_8 + (-1.0 * _x_x_1)) <= -16.0) && (((x_6 + (-1.0 * _x_x_1)) <= -10.0) && (((x_1 + (-1.0 * _x_x_1)) <= -17.0) && ((x_4 + (-1.0 * _x_x_1)) <= -2.0)))))))) && (((x_15 + (-1.0 * _x_x_1)) == -6.0) || (((x_14 + (-1.0 * _x_x_1)) == -16.0) || (((x_12 + (-1.0 * _x_x_1)) == -19.0) || (((x_10 + (-1.0 * _x_x_1)) == -17.0) || (((x_8 + (-1.0 * _x_x_1)) == -16.0) || (((x_6 + (-1.0 * _x_x_1)) == -10.0) || (((x_1 + (-1.0 * _x_x_1)) == -17.0) || ((x_4 + (-1.0 * _x_x_1)) == -2.0)))))))))) && ((((x_14 + (-1.0 * _x_x_2)) <= -12.0) && (((x_13 + (-1.0 * _x_x_2)) <= -7.0) && (((x_12 + (-1.0 * _x_x_2)) <= -13.0) && (((x_7 + (-1.0 * _x_x_2)) <= -2.0) && (((x_5 + (-1.0 * _x_x_2)) <= -8.0) && (((x_3 + (-1.0 * _x_x_2)) <= -14.0) && (((x_0 + (-1.0 * _x_x_2)) <= -1.0) && ((x_2 + (-1.0 * _x_x_2)) <= -15.0)))))))) && (((x_14 + (-1.0 * _x_x_2)) == -12.0) || (((x_13 + (-1.0 * _x_x_2)) == -7.0) || (((x_12 + (-1.0 * _x_x_2)) == -13.0) || (((x_7 + (-1.0 * _x_x_2)) == -2.0) || (((x_5 + (-1.0 * _x_x_2)) == -8.0) || (((x_3 + (-1.0 * _x_x_2)) == -14.0) || (((x_0 + (-1.0 * _x_x_2)) == -1.0) || ((x_2 + (-1.0 * _x_x_2)) == -15.0)))))))))) && ((((x_13 + (-1.0 * _x_x_3)) <= -11.0) && (((x_12 + (-1.0 * _x_x_3)) <= -7.0) && (((x_9 + (-1.0 * _x_x_3)) <= -13.0) && (((x_7 + (-1.0 * _x_x_3)) <= -19.0) && (((x_5 + (-1.0 * _x_x_3)) <= -19.0) && (((x_3 + (-1.0 * _x_x_3)) <= -5.0) && (((x_0 + (-1.0 * _x_x_3)) <= -9.0) && ((x_2 + (-1.0 * _x_x_3)) <= -16.0)))))))) && (((x_13 + (-1.0 * _x_x_3)) == -11.0) || (((x_12 + (-1.0 * _x_x_3)) == -7.0) || (((x_9 + (-1.0 * _x_x_3)) == -13.0) || (((x_7 + (-1.0 * _x_x_3)) == -19.0) || (((x_5 + (-1.0 * _x_x_3)) == -19.0) || (((x_3 + (-1.0 * _x_x_3)) == -5.0) || (((x_0 + (-1.0 * _x_x_3)) == -9.0) || ((x_2 + (-1.0 * _x_x_3)) == -16.0)))))))))) && ((((x_14 + (-1.0 * _x_x_4)) <= -5.0) && (((x_13 + (-1.0 * _x_x_4)) <= -13.0) && (((x_11 + (-1.0 * _x_x_4)) <= -10.0) && (((x_7 + (-1.0 * _x_x_4)) <= -2.0) && (((x_5 + (-1.0 * _x_x_4)) <= -20.0) && (((x_4 + (-1.0 * _x_x_4)) <= -1.0) && (((x_1 + (-1.0 * _x_x_4)) <= -2.0) && ((x_2 + (-1.0 * _x_x_4)) <= -14.0)))))))) && (((x_14 + (-1.0 * _x_x_4)) == -5.0) || (((x_13 + (-1.0 * _x_x_4)) == -13.0) || (((x_11 + (-1.0 * _x_x_4)) == -10.0) || (((x_7 + (-1.0 * _x_x_4)) == -2.0) || (((x_5 + (-1.0 * _x_x_4)) == -20.0) || (((x_4 + (-1.0 * _x_x_4)) == -1.0) || (((x_1 + (-1.0 * _x_x_4)) == -2.0) || ((x_2 + (-1.0 * _x_x_4)) == -14.0)))))))))) && ((((x_15 + (-1.0 * _x_x_5)) <= -8.0) && (((x_14 + (-1.0 * _x_x_5)) <= -13.0) && (((x_13 + (-1.0 * _x_x_5)) <= -13.0) && (((x_12 + (-1.0 * _x_x_5)) <= -6.0) && (((x_11 + (-1.0 * _x_x_5)) <= -15.0) && (((x_8 + (-1.0 * _x_x_5)) <= -3.0) && (((x_2 + (-1.0 * _x_x_5)) <= -7.0) && ((x_4 + (-1.0 * _x_x_5)) <= -7.0)))))))) && (((x_15 + (-1.0 * _x_x_5)) == -8.0) || (((x_14 + (-1.0 * _x_x_5)) == -13.0) || (((x_13 + (-1.0 * _x_x_5)) == -13.0) || (((x_12 + (-1.0 * _x_x_5)) == -6.0) || (((x_11 + (-1.0 * _x_x_5)) == -15.0) || (((x_8 + (-1.0 * _x_x_5)) == -3.0) || (((x_2 + (-1.0 * _x_x_5)) == -7.0) || ((x_4 + (-1.0 * _x_x_5)) == -7.0)))))))))) && ((((x_15 + (-1.0 * _x_x_6)) <= -5.0) && (((x_14 + (-1.0 * _x_x_6)) <= -12.0) && (((x_12 + (-1.0 * _x_x_6)) <= -1.0) && (((x_11 + (-1.0 * _x_x_6)) <= -6.0) && (((x_9 + (-1.0 * _x_x_6)) <= -15.0) && (((x_8 + (-1.0 * _x_x_6)) <= -12.0) && (((x_0 + (-1.0 * _x_x_6)) <= -16.0) && ((x_2 + (-1.0 * _x_x_6)) <= -7.0)))))))) && (((x_15 + (-1.0 * _x_x_6)) == -5.0) || (((x_14 + (-1.0 * _x_x_6)) == -12.0) || (((x_12 + (-1.0 * _x_x_6)) == -1.0) || (((x_11 + (-1.0 * _x_x_6)) == -6.0) || (((x_9 + (-1.0 * _x_x_6)) == -15.0) || (((x_8 + (-1.0 * _x_x_6)) == -12.0) || (((x_0 + (-1.0 * _x_x_6)) == -16.0) || ((x_2 + (-1.0 * _x_x_6)) == -7.0)))))))))) && ((((x_14 + (-1.0 * _x_x_7)) <= -7.0) && (((x_13 + (-1.0 * _x_x_7)) <= -18.0) && (((x_12 + (-1.0 * _x_x_7)) <= -18.0) && (((x_11 + (-1.0 * _x_x_7)) <= -19.0) && (((x_9 + (-1.0 * _x_x_7)) <= -19.0) && (((x_8 + (-1.0 * _x_x_7)) <= -19.0) && (((x_0 + (-1.0 * _x_x_7)) <= -14.0) && ((x_5 + (-1.0 * _x_x_7)) <= -16.0)))))))) && (((x_14 + (-1.0 * _x_x_7)) == -7.0) || (((x_13 + (-1.0 * _x_x_7)) == -18.0) || (((x_12 + (-1.0 * _x_x_7)) == -18.0) || (((x_11 + (-1.0 * _x_x_7)) == -19.0) || (((x_9 + (-1.0 * _x_x_7)) == -19.0) || (((x_8 + (-1.0 * _x_x_7)) == -19.0) || (((x_0 + (-1.0 * _x_x_7)) == -14.0) || ((x_5 + (-1.0 * _x_x_7)) == -16.0)))))))))) && ((((x_14 + (-1.0 * _x_x_8)) <= -4.0) && (((x_12 + (-1.0 * _x_x_8)) <= -19.0) && (((x_10 + (-1.0 * _x_x_8)) <= -5.0) && (((x_7 + (-1.0 * _x_x_8)) <= -4.0) && (((x_6 + (-1.0 * _x_x_8)) <= -10.0) && (((x_5 + (-1.0 * _x_x_8)) <= -1.0) && (((x_1 + (-1.0 * _x_x_8)) <= -12.0) && ((x_3 + (-1.0 * _x_x_8)) <= -7.0)))))))) && (((x_14 + (-1.0 * _x_x_8)) == -4.0) || (((x_12 + (-1.0 * _x_x_8)) == -19.0) || (((x_10 + (-1.0 * _x_x_8)) == -5.0) || (((x_7 + (-1.0 * _x_x_8)) == -4.0) || (((x_6 + (-1.0 * _x_x_8)) == -10.0) || (((x_5 + (-1.0 * _x_x_8)) == -1.0) || (((x_1 + (-1.0 * _x_x_8)) == -12.0) || ((x_3 + (-1.0 * _x_x_8)) == -7.0)))))))))) && ((((x_15 + (-1.0 * _x_x_9)) <= -20.0) && (((x_12 + (-1.0 * _x_x_9)) <= -8.0) && (((x_11 + (-1.0 * _x_x_9)) <= -6.0) && (((x_10 + (-1.0 * _x_x_9)) <= -14.0) && (((x_9 + (-1.0 * _x_x_9)) <= -13.0) && (((x_8 + (-1.0 * _x_x_9)) <= -7.0) && (((x_3 + (-1.0 * _x_x_9)) <= -7.0) && ((x_4 + (-1.0 * _x_x_9)) <= -8.0)))))))) && (((x_15 + (-1.0 * _x_x_9)) == -20.0) || (((x_12 + (-1.0 * _x_x_9)) == -8.0) || (((x_11 + (-1.0 * _x_x_9)) == -6.0) || (((x_10 + (-1.0 * _x_x_9)) == -14.0) || (((x_9 + (-1.0 * _x_x_9)) == -13.0) || (((x_8 + (-1.0 * _x_x_9)) == -7.0) || (((x_3 + (-1.0 * _x_x_9)) == -7.0) || ((x_4 + (-1.0 * _x_x_9)) == -8.0)))))))))) && ((((x_15 + (-1.0 * _x_x_10)) <= -5.0) && (((x_14 + (-1.0 * _x_x_10)) <= -11.0) && (((x_12 + (-1.0 * _x_x_10)) <= -20.0) && (((x_10 + (-1.0 * _x_x_10)) <= -5.0) && (((x_7 + (-1.0 * _x_x_10)) <= -14.0) && (((x_2 + (-1.0 * _x_x_10)) <= -18.0) && (((x_0 + (-1.0 * _x_x_10)) <= -20.0) && ((x_1 + (-1.0 * _x_x_10)) <= -8.0)))))))) && (((x_15 + (-1.0 * _x_x_10)) == -5.0) || (((x_14 + (-1.0 * _x_x_10)) == -11.0) || (((x_12 + (-1.0 * _x_x_10)) == -20.0) || (((x_10 + (-1.0 * _x_x_10)) == -5.0) || (((x_7 + (-1.0 * _x_x_10)) == -14.0) || (((x_2 + (-1.0 * _x_x_10)) == -18.0) || (((x_0 + (-1.0 * _x_x_10)) == -20.0) || ((x_1 + (-1.0 * _x_x_10)) == -8.0)))))))))) && ((((x_14 + (-1.0 * _x_x_11)) <= -15.0) && (((x_13 + (-1.0 * _x_x_11)) <= -15.0) && (((x_11 + (-1.0 * _x_x_11)) <= -15.0) && (((x_10 + (-1.0 * _x_x_11)) <= -17.0) && (((x_9 + (-1.0 * _x_x_11)) <= -4.0) && (((x_5 + (-1.0 * _x_x_11)) <= -9.0) && (((x_1 + (-1.0 * _x_x_11)) <= -9.0) && ((x_4 + (-1.0 * _x_x_11)) <= -8.0)))))))) && (((x_14 + (-1.0 * _x_x_11)) == -15.0) || (((x_13 + (-1.0 * _x_x_11)) == -15.0) || (((x_11 + (-1.0 * _x_x_11)) == -15.0) || (((x_10 + (-1.0 * _x_x_11)) == -17.0) || (((x_9 + (-1.0 * _x_x_11)) == -4.0) || (((x_5 + (-1.0 * _x_x_11)) == -9.0) || (((x_1 + (-1.0 * _x_x_11)) == -9.0) || ((x_4 + (-1.0 * _x_x_11)) == -8.0)))))))))) && ((((x_15 + (-1.0 * _x_x_12)) <= -20.0) && (((x_14 + (-1.0 * _x_x_12)) <= -13.0) && (((x_13 + (-1.0 * _x_x_12)) <= -3.0) && (((x_12 + (-1.0 * _x_x_12)) <= -20.0) && (((x_6 + (-1.0 * _x_x_12)) <= -5.0) && (((x_5 + (-1.0 * _x_x_12)) <= -3.0) && (((x_1 + (-1.0 * _x_x_12)) <= -11.0) && ((x_3 + (-1.0 * _x_x_12)) <= -20.0)))))))) && (((x_15 + (-1.0 * _x_x_12)) == -20.0) || (((x_14 + (-1.0 * _x_x_12)) == -13.0) || (((x_13 + (-1.0 * _x_x_12)) == -3.0) || (((x_12 + (-1.0 * _x_x_12)) == -20.0) || (((x_6 + (-1.0 * _x_x_12)) == -5.0) || (((x_5 + (-1.0 * _x_x_12)) == -3.0) || (((x_1 + (-1.0 * _x_x_12)) == -11.0) || ((x_3 + (-1.0 * _x_x_12)) == -20.0)))))))))) && ((((x_15 + (-1.0 * _x_x_13)) <= -11.0) && (((x_13 + (-1.0 * _x_x_13)) <= -1.0) && (((x_10 + (-1.0 * _x_x_13)) <= -14.0) && (((x_9 + (-1.0 * _x_x_13)) <= -1.0) && (((x_7 + (-1.0 * _x_x_13)) <= -20.0) && (((x_6 + (-1.0 * _x_x_13)) <= -18.0) && (((x_0 + (-1.0 * _x_x_13)) <= -1.0) && ((x_3 + (-1.0 * _x_x_13)) <= -11.0)))))))) && (((x_15 + (-1.0 * _x_x_13)) == -11.0) || (((x_13 + (-1.0 * _x_x_13)) == -1.0) || (((x_10 + (-1.0 * _x_x_13)) == -14.0) || (((x_9 + (-1.0 * _x_x_13)) == -1.0) || (((x_7 + (-1.0 * _x_x_13)) == -20.0) || (((x_6 + (-1.0 * _x_x_13)) == -18.0) || (((x_0 + (-1.0 * _x_x_13)) == -1.0) || ((x_3 + (-1.0 * _x_x_13)) == -11.0)))))))))) && ((((x_12 + (-1.0 * _x_x_14)) <= -18.0) && (((x_11 + (-1.0 * _x_x_14)) <= -8.0) && (((x_7 + (-1.0 * _x_x_14)) <= -2.0) && (((x_5 + (-1.0 * _x_x_14)) <= -14.0) && (((x_4 + (-1.0 * _x_x_14)) <= -1.0) && (((x_3 + (-1.0 * _x_x_14)) <= -7.0) && (((x_0 + (-1.0 * _x_x_14)) <= -20.0) && ((x_1 + (-1.0 * _x_x_14)) <= -1.0)))))))) && (((x_12 + (-1.0 * _x_x_14)) == -18.0) || (((x_11 + (-1.0 * _x_x_14)) == -8.0) || (((x_7 + (-1.0 * _x_x_14)) == -2.0) || (((x_5 + (-1.0 * _x_x_14)) == -14.0) || (((x_4 + (-1.0 * _x_x_14)) == -1.0) || (((x_3 + (-1.0 * _x_x_14)) == -7.0) || (((x_0 + (-1.0 * _x_x_14)) == -20.0) || ((x_1 + (-1.0 * _x_x_14)) == -1.0)))))))))) && ((((x_13 + (-1.0 * _x_x_15)) <= -3.0) && (((x_12 + (-1.0 * _x_x_15)) <= -19.0) && (((x_8 + (-1.0 * _x_x_15)) <= -1.0) && (((x_5 + (-1.0 * _x_x_15)) <= -20.0) && (((x_4 + (-1.0 * _x_x_15)) <= -15.0) && (((x_3 + (-1.0 * _x_x_15)) <= -20.0) && (((x_0 + (-1.0 * _x_x_15)) <= -6.0) && ((x_1 + (-1.0 * _x_x_15)) <= -16.0)))))))) && (((x_13 + (-1.0 * _x_x_15)) == -3.0) || (((x_12 + (-1.0 * _x_x_15)) == -19.0) || (((x_8 + (-1.0 * _x_x_15)) == -1.0) || (((x_5 + (-1.0 * _x_x_15)) == -20.0) || (((x_4 + (-1.0 * _x_x_15)) == -15.0) || (((x_3 + (-1.0 * _x_x_15)) == -20.0) || (((x_0 + (-1.0 * _x_x_15)) == -6.0) || ((x_1 + (-1.0 * _x_x_15)) == -16.0)))))))))) && ((((_EL_U_847 == (_x__EL_U_847 || ( !(-10.0 <= (_x_x_4 + (-1.0 * _x_x_5)))))) && (_EL_U_851 == (_x__EL_U_851 || ( !(( !(_x__EL_U_847 || ( !(-10.0 <= (_x_x_4 + (-1.0 * _x_x_5)))))) || ( !(-12.0 <= (_x_x_0 + (-1.0 * _x_x_14))))))))) && (_x__J866 == (( !(_J866 && _J879)) && ((_J866 && _J879) || ((( !(-10.0 <= (x_4 + (-1.0 * x_5)))) || ( !(( !(-10.0 <= (x_4 + (-1.0 * x_5)))) || _EL_U_847))) || _J866))))) && (_x__J879 == (( !(_J866 && _J879)) && ((_J866 && _J879) || ((( !(( !(-12.0 <= (x_0 + (-1.0 * x_14)))) || ( !(( !(-10.0 <= (x_4 + (-1.0 * x_5)))) || _EL_U_847)))) || ( !(_EL_U_851 || ( !(( !(-12.0 <= (x_0 + (-1.0 * x_14)))) || ( !(( !(-10.0 <= (x_4 + (-1.0 * x_5)))) || _EL_U_847))))))) || _J879)))))); _J879 = _x__J879; _J866 = _x__J866; _EL_U_847 = _x__EL_U_847; x_5 = _x_x_5; x_4 = _x_x_4; x_14 = _x_x_14; x_0 = _x_x_0; x_6 = _x_x_6; _EL_U_851 = _x__EL_U_851; x_9 = _x_x_9; x_2 = _x_x_2; x_1 = _x_x_1; x_10 = _x_x_10; x_15 = _x_x_15; x_3 = _x_x_3; x_8 = _x_x_8; x_12 = _x_x_12; x_13 = _x_x_13; x_7 = _x_x_7; x_11 = _x_x_11; } }
the_stack_data/111076765.c
/* { dg-do compile } */ char a; void f(void) { char b = 2; for(;;) { unsigned short s = 1, *p = &s, *i; for(*i = 0; *i < 4; ++*i) if(a | (*p /= (b += !!a)) <= 63739) return; if(!s) a = 0; for(;;); } }
the_stack_data/148213.c
#include <stdio.h> void main(){ int i=5, *p; p = &i; printf("%x %d %d %d %d", p,*p+2,**&p,3**p,**&p+4); /* Resposta: o valor do printf anterior foi: 61fe1c 7 5 15 9 */ }
the_stack_data/162644502.c
// Copyright (c) 2020 Johannes Stoelp #include <stdio.h> void greet() { puts("Hello from libgreet.so!"); }
the_stack_data/105244.c
typedef int bool; struct module; void *__VERIFIER_nondet_pointer(void); static inline bool try_module_get(struct module *module); static inline void module_put(struct module *module) { } static inline void __module_get(struct module *module) { } extern void module_put_and_exit(struct module *mod, long code); int module_refcount(struct module *mod); void ldv_check_final_state(void); const int N = 10; void main(void) { struct module *test_module_1 = __VERIFIER_nondet_pointer(); int i; if (module_refcount(test_module_1) == 0) { // true -> error module_put(test_module_1); } ldv_check_final_state(); }
the_stack_data/122502.c
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> int main(int argc, char **argv) { int pipe1[2]; pipe(pipe1); if (fork()) { // cut close(pipe1[1]); close(0); dup(pipe1[0]); close(pipe1[0]); execlp("cut", "cut", "-c5-12", NULL); printf("Error cut\n"); } else { // ps close(pipe1[0]); close(1); dup(pipe1[1]); close(pipe1[1]); execlp("ps", "ps", "-efl", NULL); printf("Error ps\n"); } }
the_stack_data/43979.c
const unsigned char n4_img[7052] = { 0xFF, 0xD8, 0xFF, 0xE0, 0x00, 0x10, 0x4A, 0x46, 0x49, 0x46, 0x00, 0x01, 0x01, 0x01, 0x00, 0x48, 0x00, 0x48, 0x00, 0x00, 0xFF, 0xDB, 0x00, 0x43, 0x00, 0x06, 0x04, 0x05, 0x06, 0x05, 0x04, 0x06, 0x06, 0x05, 0x06, 0x07, 0x07, 0x06, 0x08, 0x0A, 0x10, 0x0A, 0x0A, 0x09, 0x09, 0x0A, 0x14, 0x0E, 0x0F, 0x0C, 0x10, 0x17, 0x14, 0x18, 0x18, 0x17, 0x14, 0x16, 0x16, 0x1A, 0x1D, 0x25, 0x1F, 0x1A, 0x1B, 0x23, 0x1C, 0x16, 0x16, 0x20, 0x2C, 0x20, 0x23, 0x26, 0x27, 0x29, 0x2A, 0x29, 0x19, 0x1F, 0x2D, 0x30, 0x2D, 0x28, 0x30, 0x25, 0x28, 0x29, 0x28, 0xFF, 0xDB, 0x00, 0x43, 0x01, 0x07, 0x07, 0x07, 0x0A, 0x08, 0x0A, 0x13, 0x0A, 0x0A, 0x13, 0x28, 0x1A, 0x16, 0x1A, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0xFF, 0xC0, 0x00, 0x11, 0x08, 0x00, 0xF0, 0x01, 0x2C, 0x03, 0x01, 0x22, 0x00, 0x02, 0x11, 0x01, 0x03, 0x11, 0x01, 0xFF, 0xC4, 0x00, 0x1C, 0x00, 0x01, 0x00, 0x02, 0x02, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x06, 0x02, 0x07, 0x01, 0x03, 0x05, 0x08, 0xFF, 0xC4, 0x00, 0x4E, 0x10, 0x00, 0x01, 0x03, 0x03, 0x01, 0x04, 0x05, 0x09, 0x04, 0x04, 0x0A, 0x08, 0x07, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x03, 0x04, 0x05, 0x11, 0x06, 0x07, 0x12, 0x21, 0x31, 0x13, 0x32, 0x41, 0x51, 0x71, 0x14, 0x15, 0x16, 0x22, 0x52, 0x54, 0x61, 0x92, 0xD1, 0x53, 0x91, 0x93, 0xA1, 0x08, 0x56, 0x74, 0x81, 0x17, 0x18, 0x24, 0x34, 0x43, 0x73, 0x94, 0xA3, 0xB3, 0xD2, 0x23, 0x28, 0x33, 0x37, 0x62, 0xB1, 0xB2, 0xF0, 0x36, 0x38, 0x42, 0x72, 0x84, 0xC1, 0xF1, 0xFF, 0xC4, 0x00, 0x1C, 0x01, 0x01, 0x00, 0x02, 0x03, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x04, 0x02, 0x03, 0x05, 0x06, 0x07, 0x08, 0xFF, 0xC4, 0x00, 0x38, 0x11, 0x00, 0x02, 0x01, 0x02, 0x03, 0x02, 0x0C, 0x05, 0x04, 0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, 0x12, 0x31, 0x06, 0x13, 0x15, 0x16, 0x22, 0x41, 0x51, 0x53, 0x61, 0x71, 0x91, 0xA1, 0x14, 0x52, 0x81, 0xD1, 0xE1, 0x17, 0x23, 0x92, 0xC1, 0x24, 0x54, 0x62, 0xB1, 0xB2, 0xF0, 0xFF, 0xDA, 0x00, 0x0C, 0x03, 0x01, 0x00, 0x02, 0x11, 0x03, 0x11, 0x00, 0x3F, 0x00, 0xD2, 0x4F, 0xEB, 0xBB, 0xC5, 0x62, 0xB2, 0x7F, 0x5D, 0xDE, 0x2B, 0x15, 0xEB, 0xCE, 0x40, 0x44, 0x44, 0x01, 0x10, 0xAD, 0xA2, 0xDB, 0x6E, 0xCF, 0xFF, 0x00, 0x82, 0x13, 0x58, 0xEA, 0xA8, 0xFD, 0x32, 0xE8, 0x49, 0x11, 0x79, 0x43, 0xF3, 0xBF, 0xD2, 0x60, 0x7A, 0x9D, 0x5E, 0xAA, 0xD5, 0x52, 0xAA, 0xA7, 0x6D, 0x2F, 0x73, 0x28, 0xC6, 0xE6, 0xAE, 0x44, 0x1C, 0x91, 0x6D, 0x31, 0x08, 0x88, 0x80, 0x22, 0x22, 0x00, 0x88, 0x88, 0x02, 0x22, 0x20, 0x08, 0x88, 0x80, 0x22, 0x22, 0x00, 0x88, 0x88, 0x02, 0x22, 0x20, 0x08, 0x88, 0x80, 0x22, 0x22, 0x00, 0x88, 0x88, 0x02, 0x22, 0x20, 0x08, 0x88, 0x80, 0x22, 0x22, 0x02, 0xF1, 0xA1, 0xB6, 0x95, 0x76, 0xD1, 0xB6, 0x3A, 0xFB, 0x5D, 0xB6, 0x9E, 0x96, 0x58, 0x2B, 0x1E, 0x5F, 0x21, 0x94, 0x12, 0x46, 0x5A, 0x1B, 0xC3, 0x07, 0xB8, 0x2A, 0x5D, 0x2C, 0x6D, 0x31, 0x9D, 0xE1, 0xC7, 0x3D, 0xEB, 0xAD, 0x49, 0xA7, 0xEA, 0x1F, 0x15, 0xAF, 0x62, 0x31, 0xBB, 0x4B, 0x79, 0x96, 0xD3, 0x67, 0x43, 0xFA, 0xEE, 0xF1, 0x58, 0xAC, 0x9F, 0xD7, 0x77, 0x8A, 0xC5, 0x6C, 0x31, 0x0A, 0xC1, 0xA2, 0xF4, 0x8D, 0xD7, 0x59, 0x5C, 0xA6, 0xA1, 0xB1, 0xC7, 0x14, 0x95, 0x11, 0x42, 0x67, 0x78, 0x92, 0x40, 0xC0, 0x1A, 0x1C, 0x07, 0x33, 0xF1, 0x70, 0x55, 0xF5, 0xEA, 0xE9, 0xDD, 0x43, 0x77, 0xD3, 0x55, 0xB2, 0x55, 0xD8, 0xAB, 0xA4, 0xA2, 0xA8, 0x92, 0x3E, 0x89, 0xCF, 0x8C, 0x02, 0x4B, 0x72, 0x0E, 0x38, 0x83, 0xDA, 0x02, 0xC6, 0x7B, 0x5B, 0x3D, 0x1D, 0xE4, 0xAB, 0x75, 0x9D, 0x17, 0xCB, 0x5D, 0x55, 0x92, 0xF3, 0x59, 0x6B, 0xAF, 0x6B, 0x5B, 0x55, 0x49, 0x21, 0x8A, 0x50, 0xD7, 0x6F, 0x00, 0xE1, 0xDC, 0x7B, 0x54, 0x03, 0x8C, 0xA9, 0x57, 0x3A, 0xFA, 0xAB, 0xA5, 0xC2, 0xA2, 0xBA, 0xE1, 0x31, 0x9E, 0xAE, 0xA1, 0xDB, 0xF2, 0xCA, 0xE0, 0x01, 0x7B, 0xBB, 0xCE, 0x14, 0x64, 0x8D, 0xED, 0xAE, 0xF0, 0xFC, 0x09, 0xB6, 0x2B, 0x5D, 0x55, 0xEE, 0xF1, 0x49, 0x6C, 0xB7, 0xB5, 0xAE, 0xAB, 0xAA, 0x90, 0x47, 0x18, 0x73, 0xB7, 0x41, 0x27, 0xBC, 0xAF, 0x4B, 0x59, 0xE9, 0x2B, 0xAE, 0x8D, 0xB9, 0xC3, 0x41, 0x7C, 0x64, 0x4C, 0xA8, 0x96, 0x2E, 0x99, 0xA2, 0x39, 0x03, 0xC6, 0xEE, 0x48, 0xE7, 0xE2, 0x0A, 0xF2, 0x6D, 0x95, 0xD5, 0x56, 0xBB, 0x8D, 0x3D, 0x7D, 0xBE, 0x67, 0x41, 0x57, 0x4E, 0xF1, 0x24, 0x52, 0x34, 0x0C, 0xB5, 0xC3, 0xB7, 0x8F, 0x05, 0x33, 0x52, 0x6A, 0x2B, 0xB6, 0xA6, 0xAE, 0x65, 0x65, 0xF6, 0xB5, 0xF5, 0x95, 0x2C, 0x8C, 0x44, 0xD7, 0xBC, 0x01, 0x86, 0x82, 0x4E, 0x30, 0x00, 0x1C, 0xC9, 0x58, 0xBD, 0xBD, 0xA5, 0x6D, 0xC3, 0x4B, 0x1E, 0x52, 0x22, 0x2D, 0x84, 0x04, 0x44, 0x40, 0x11, 0x11, 0x00, 0x44, 0x44, 0x01, 0x11, 0x10, 0x04, 0x44, 0x40, 0x11, 0x11, 0x00, 0x44, 0x44, 0x01, 0x11, 0x10, 0x04, 0x44, 0x40, 0x11, 0x11, 0x00, 0x44, 0x44, 0x01, 0x11, 0x10, 0x04, 0x44, 0x40, 0x14, 0x9A, 0x7E, 0xA1, 0xF1, 0x51, 0x94, 0x9A, 0x7E, 0xA1, 0xF1, 0x50, 0xF7, 0x12, 0x74, 0x3F, 0xAE, 0xEF, 0x15, 0x8A, 0xC9, 0xFD, 0x77, 0x78, 0xAC, 0x54, 0x90, 0x11, 0x11, 0x00, 0x2B, 0x63, 0x37, 0x53, 0x68, 0xC3, 0xB2, 0xD3, 0x67, 0x75, 0x81, 0xDE, 0x93, 0xF4, 0x45, 0xBE, 0x70, 0xF2, 0x78, 0xFA, 0xFD, 0x26, 0x41, 0xDE, 0xDE, 0xDE, 0xEA, 0xF0, 0xE4, 0xB5, 0xCA, 0x2D, 0x73, 0xA6, 0xA7, 0x6B, 0xF5, 0x12, 0xA4, 0xD0, 0x44, 0x45, 0xB0, 0x80, 0x88, 0x88, 0x02, 0x22, 0x20, 0x08, 0x88, 0x80, 0x22, 0x22, 0x00, 0x88, 0x88, 0x02, 0x22, 0x20, 0x08, 0x88, 0x80, 0x22, 0x22, 0x00, 0x88, 0x88, 0x02, 0x22, 0x20, 0x08, 0x88, 0x80, 0x22, 0x22, 0x00, 0x88, 0x88, 0x02, 0x22, 0x20, 0x0A, 0x4D, 0x3F, 0x50, 0xF8, 0xA8, 0xCA, 0x4D, 0x3F, 0x50, 0xF8, 0xA8, 0x7B, 0x89, 0x3A, 0x1F, 0xD7, 0x77, 0x8A, 0xC5, 0x64, 0xFE, 0xBB, 0xBC, 0x56, 0x2A, 0x48, 0x08, 0x88, 0x80, 0x22, 0x22, 0x00, 0x88, 0x88, 0x02, 0x22, 0x20, 0x08, 0x88, 0x80, 0x22, 0x22, 0x00, 0x88, 0x4E, 0x16, 0xFB, 0xFD, 0x16, 0x28, 0x6D, 0xD5, 0xAC, 0xD4, 0x8E, 0xB9, 0x52, 0xD2, 0x4E, 0xE6, 0x3E, 0x9C, 0x46, 0x6A, 0x23, 0x6B, 0x8B, 0x72, 0x1F, 0x9C, 0x65, 0x69, 0xAF, 0x57, 0x89, 0x86, 0xDD, 0xAE, 0x65, 0x15, 0x77, 0x63, 0x42, 0x22, 0x97, 0x79, 0x01, 0x97, 0xAB, 0x83, 0x1A, 0xD0, 0xD6, 0xB6, 0xA2, 0x40, 0x00, 0xE0, 0x00, 0xDE, 0x2A, 0x22, 0xDA, 0x9D, 0xD5, 0xC8, 0x61, 0x11, 0x14, 0x90, 0x11, 0x11, 0x00, 0x44, 0x44, 0x01, 0x11, 0x10, 0x04, 0x44, 0x40, 0x11, 0x11, 0x00, 0x44, 0x44, 0x01, 0x11, 0x10, 0x04, 0x44, 0x40, 0x14, 0x9A, 0x7E, 0xA1, 0xF1, 0x51, 0x94, 0x9A, 0x7E, 0xA1, 0xF1, 0x50, 0xF7, 0x12, 0x74, 0x3F, 0xAE, 0xEF, 0x12, 0xB1, 0x59, 0x3F, 0xAE, 0xEF, 0x12, 0xB1, 0x52, 0x40, 0x44, 0x44, 0x01, 0x11, 0x10, 0x04, 0x44, 0x40, 0x11, 0x11, 0x00, 0x44, 0x44, 0x01, 0x4C, 0xB3, 0x51, 0x79, 0xCE, 0xF1, 0x41, 0x41, 0xD2, 0xB6, 0x1F, 0x2B, 0xA8, 0x8E, 0x0E, 0x91, 0xC3, 0x21, 0x9B, 0xCE, 0x0D, 0xDE, 0x23, 0xE1, 0x95, 0x0D, 0x72, 0x09, 0x04, 0x10, 0x70, 0x47, 0x22, 0x14, 0x34, 0xDA, 0xD0, 0x1B, 0xC2, 0xE7, 0xFA, 0x3F, 0x4B, 0x45, 0x6E, 0xAB, 0xAB, 0xF4, 0xA6, 0x8E, 0x4E, 0x82, 0x27, 0xCB, 0xB8, 0xDA, 0x72, 0x0B, 0xB7, 0x41, 0x38, 0xEB, 0xFC, 0x15, 0x2F, 0x64, 0xFB, 0x38, 0x7E, 0xD0, 0x60, 0xB8, 0x49, 0x1D, 0xDA, 0x0B, 0x77, 0x92, 0x18, 0xF8, 0x4B, 0x16, 0xFE, 0xFE, 0xF8, 0x71, 0xE1, 0xEB, 0x0E, 0x5B, 0xBF, 0x9A, 0xA3, 0x19, 0xA5, 0x20, 0x83, 0x23, 0xC8, 0x3C, 0xC1, 0x71, 0x57, 0xED, 0x92, 0x6C, 0xDE, 0x7D, 0xA0, 0x36, 0xEA, 0x69, 0xEF, 0x1E, 0x6D, 0x34, 0x46, 0x30, 0x47, 0x42, 0x64, 0xDF, 0xDE, 0xDE, 0xEE, 0x70, 0xC6, 0x37, 0x7E, 0x3C, 0xD5, 0x49, 0xF1, 0x94, 0xA9, 0xB7, 0x3A, 0x9F, 0x5B, 0x1B, 0xA2, 0xD3, 0x7A, 0x23, 0xCE, 0xD9, 0xE6, 0x84, 0x7E, 0xB1, 0xD5, 0x97, 0x0B, 0x1B, 0x2E, 0x71, 0x50, 0xBE, 0x92, 0x39, 0x24, 0xE9, 0xA4, 0x8F, 0x78, 0x3F, 0x71, 0xED, 0x66, 0x31, 0x91, 0xED, 0x67, 0x9F, 0x62, 0xF7, 0xB6, 0x95, 0xB2, 0x59, 0x34, 0x36, 0x9D, 0x6D, 0xD6, 0x4B, 0xED, 0x3D, 0xC3, 0x7A, 0xA1, 0x90, 0x74, 0x31, 0xC3, 0xB8, 0x46, 0xF0, 0x27, 0x39, 0xDE, 0x3D, 0xDF, 0x9A, 0xD6, 0x95, 0x51, 0xC9, 0x47, 0x5F, 0x53, 0x03, 0x64, 0x25, 0xD0, 0xC8, 0xE8, 0x8B, 0xDB, 0xC3, 0x7B, 0x07, 0x19, 0xFC, 0x97, 0x5B, 0xDF, 0x2C, 0x83, 0x12, 0x48, 0xF7, 0x0E, 0x78, 0x24, 0x95, 0xB3, 0x8B, 0xA8, 0xE4, 0xA4, 0xA7, 0xA7, 0x91, 0x8B, 0x71, 0xB5, 0xAC, 0x11, 0x70, 0x17, 0x2A, 0xC1, 0xAC, 0x22, 0x22, 0x00, 0x88, 0x88, 0x02, 0x22, 0x20, 0x08, 0x88, 0x80, 0x22, 0x22, 0x00, 0x88, 0x88, 0x02, 0x22, 0x20, 0x08, 0x88, 0x80, 0x29, 0x34, 0xFD, 0x43, 0xE2, 0xA3, 0x29, 0x34, 0xFD, 0x43, 0xE2, 0xA1, 0x83, 0xBD, 0xF6, 0x7B, 0x8E, 0xFB, 0xBF, 0x91, 0xCF, 0xCF, 0xD8, 0x2B, 0xD8, 0xB3, 0x69, 0x49, 0x2B, 0x29, 0xDF, 0x25, 0x5B, 0xE4, 0xA6, 0x70, 0x76, 0xE8, 0x61, 0x67, 0x12, 0x30, 0x38, 0xAD, 0x86, 0xA4, 0x52, 0xD0, 0xD5, 0x55, 0x35, 0xCE, 0xA6, 0xA7, 0x96, 0x56, 0x83, 0x82, 0x58, 0xD2, 0x40, 0x2B, 0xE6, 0x98, 0x9E, 0x17, 0xE2, 0xA7, 0x0D, 0x98, 0xA5, 0x07, 0xDA, 0xBF, 0x27, 0xD4, 0x68, 0x70, 0x43, 0x03, 0x87, 0x9F, 0x19, 0x56, 0x4E, 0x4B, 0xB1, 0xE8, 0xBD, 0xAC, 0x51, 0x86, 0x87, 0x87, 0xDF, 0x24, 0xF9, 0x07, 0xD5, 0x3D, 0x07, 0x87, 0xDF, 0x64, 0xF9, 0x07, 0xD5, 0x5F, 0xFC, 0xD1, 0x71, 0xF7, 0x2A, 0x8F, 0xC3, 0x29, 0xE6, 0x8B, 0x8F, 0xB9, 0x54, 0x7E, 0x19, 0x5C, 0xCE, 0x73, 0xE3, 0xBB, 0xEF, 0xFA, 0xFD, 0x8B, 0xDC, 0x83, 0x93, 0xF7, 0x71, 0xF5, 0x7F, 0x72, 0x81, 0xE8, 0x3C, 0x3E, 0xF9, 0x27, 0xC8, 0x3E, 0xAA, 0x35, 0x76, 0x8D, 0x10, 0x53, 0x49, 0x24, 0x15, 0x0F, 0x95, 0xED, 0x19, 0xDD, 0xDD, 0xE6, 0xB6, 0x47, 0x9A, 0x2E, 0x3E, 0xE5, 0x51, 0xF8, 0x65, 0x75, 0xD4, 0x5B, 0xAB, 0x29, 0xD9, 0xBF, 0x3D, 0x2C, 0xCC, 0x60, 0xE6, 0xE7, 0x30, 0x80, 0x3F, 0x7A, 0xCE, 0x1C, 0x27, 0xC7, 0x29, 0x2F, 0xDE, 0xBF, 0x86, 0x84, 0x3E, 0x0F, 0xE5, 0x13, 0x4E, 0x31, 0x82, 0x4D, 0xF6, 0x37, 0xF7, 0x34, 0xCF, 0x9A, 0x2E, 0x1E, 0xE7, 0x3F, 0xC8, 0x53, 0xCC, 0xF7, 0x1F, 0x73, 0x9F, 0xE4, 0x2B, 0x6E, 0x61, 0x17, 0x63, 0x9E, 0x58, 0x8E, 0xEE, 0x3E, 0xE7, 0x33, 0x99, 0x18, 0x6E, 0xF6, 0x5E, 0xC6, 0xA3, 0xF3, 0x3D, 0xC7, 0xDC, 0xE7, 0xF9, 0x0A, 0xE4, 0x59, 0xEE, 0x24, 0x81, 0xE4, 0x73, 0xFC, 0x85, 0x6D, 0xB4, 0x4E, 0x79, 0x62, 0x3B, 0xB8, 0xFB, 0x8E, 0x64, 0x61, 0xBB, 0xC9, 0x7B, 0x14, 0xAA, 0x7D, 0x15, 0x1C, 0x94, 0xEC, 0x74, 0x95, 0x52, 0x31, 0xE4, 0x64, 0x8D, 0xCE, 0x5F, 0x9A, 0xEC, 0x1A, 0x1E, 0x1F, 0x7D, 0x93, 0xE4, 0x1F, 0x55, 0x7D, 0x8E, 0xD7, 0x5F, 0x23, 0x1A, 0xF8, 0xE8, 0xE7, 0x73, 0x1C, 0x32, 0x08, 0x61, 0x20, 0xAC, 0xBC, 0xD1, 0x71, 0xF7, 0x2A, 0x8F, 0xC3, 0x2B, 0x8B, 0x2E, 0x13, 0xE3, 0x5C, 0x9B, 0x55, 0xAD, 0xE8, 0x74, 0xE3, 0x90, 0xE5, 0x11, 0x49, 0x38, 0x46, 0xEB, 0xC5, 0xFD, 0xCA, 0x07, 0xA0, 0xF0, 0xFB, 0xEC, 0x9F, 0x20, 0xFA, 0xAE, 0x1D, 0xA2, 0x20, 0x68, 0x24, 0xD7, 0x49, 0x8E, 0x79, 0x2C, 0x1F, 0x55, 0xB0, 0x3C, 0xD1, 0x71, 0xF7, 0x1A, 0x8F, 0xC3, 0x2A, 0x81, 0xA9, 0x6E, 0xB5, 0xF4, 0xFA, 0xF6, 0xD3, 0xA6, 0x2A, 0x60, 0x6C, 0x54, 0xB7, 0x19, 0x60, 0x86, 0x6D, 0xE6, 0xB9, 0xB2, 0x86, 0x49, 0x26, 0xE1, 0x2D, 0x39, 0xE0, 0x71, 0xC8, 0xE1, 0x59, 0xC1, 0xE7, 0x79, 0x8E, 0x2E, 0xA6, 0xC4, 0x2B, 0x7F, 0xC7, 0xD8, 0xAD, 0x8D, 0xCB, 0xB2, 0x5C, 0x1D, 0x2E, 0x32, 0x54, 0x93, 0xF2, 0x6F, 0xEE, 0x54, 0x75, 0x15, 0xAA, 0xE1, 0x49, 0x5C, 0x23, 0xB2, 0x51, 0x54, 0xDD, 0x29, 0xB7, 0x01, 0x33, 0x41, 0x0B, 0x9E, 0xD0, 0xEE, 0xD6, 0xE5, 0xB9, 0x19, 0xE5, 0xF7, 0xAB, 0x56, 0xCA, 0xF5, 0xF6, 0xAD, 0xD9, 0xEB, 0x2E, 0x4D, 0xA5, 0xD1, 0x95, 0x75, 0xBE, 0x5A, 0x63, 0x2E, 0x32, 0x41, 0x33, 0x77, 0x37, 0x37, 0xB9, 0x61, 0xBD, 0xBB, 0xDF, 0x92, 0xFA, 0x8F, 0x41, 0x69, 0x0B, 0x66, 0x83, 0xB1, 0xC9, 0x69, 0xB1, 0x3A, 0xA7, 0xC9, 0x1D, 0x33, 0xAA, 0x0F, 0x4F, 0x20, 0x7B, 0xB7, 0x88, 0x00, 0xF1, 0x00, 0x70, 0xF5, 0x42, 0xF5, 0x2B, 0x2E, 0x4F, 0x8D, 0xC0, 0x43, 0x23, 0x5C, 0x08, 0xE3, 0xDA, 0xBB, 0xF4, 0x33, 0x1C, 0x4E, 0x2F, 0xF6, 0x57, 0x4B, 0xC5, 0xE8, 0x78, 0xC7, 0x82, 0x85, 0x5A, 0x8E, 0x74, 0xE3, 0xB2, 0x9F, 0x57, 0x61, 0xF0, 0x7D, 0x5C, 0x5A, 0x92, 0xA6, 0xB6, 0xA2, 0xA1, 0xFA, 0x6E, 0xE4, 0x0C, 0xD2, 0x3A, 0x42, 0xD1, 0x4D, 0x27, 0x02, 0x4E, 0x7D, 0x9F, 0x8A, 0xEA, 0x34, 0x9A, 0x8F, 0x1C, 0x34, 0xED, 0xCC, 0x7F, 0xF1, 0xA4, 0xFF, 0x00, 0x2A, 0xFB, 0xB0, 0xDD, 0x6A, 0x7B, 0xDB, 0xF9, 0xAE, 0x3C, 0xED, 0x55, 0xDE, 0xDF, 0xCF, 0xEA, 0xBA, 0xAA, 0x59, 0x82, 0xDD, 0x6F, 0x5F, 0xC1, 0x3C, 0x91, 0x73, 0xE1, 0x3F, 0x24, 0xD4, 0x9D, 0x9A, 0x76, 0xE5, 0xFD, 0x96, 0x4F, 0xA2, 0x79, 0x26, 0xA5, 0xFD, 0x5D, 0xB9, 0x7F, 0x64, 0x93, 0xE8, 0xBE, 0xE6, 0x65, 0xFD, 0xEF, 0x94, 0xC4, 0xC9, 0xE1, 0x74, 0x83, 0x20, 0xB4, 0x3B, 0x27, 0xEE, 0xCA, 0xEC, 0x92, 0xF3, 0x3C, 0x6C, 0x2F, 0x91, 0xEC, 0x6B, 0x47, 0x32, 0x78, 0x01, 0xF9, 0xA9, 0xE3, 0x33, 0x1F, 0x0F, 0x5F, 0xC1, 0x3C, 0x8C, 0xD6, 0x96, 0x3E, 0x16, 0x14, 0xBA, 0x8C, 0x0E, 0x3A, 0x72, 0xE6, 0x4F, 0xEC, 0xD2, 0x7F, 0x95, 0x0D, 0x2E, 0xA4, 0xCF, 0x0D, 0x3B, 0x72, 0x03, 0xF6, 0x59, 0x3E, 0x8B, 0xEE, 0x98, 0x2F, 0xB3, 0xCA, 0xCD, 0xE8, 0xA4, 0x89, 0xEC, 0xEF, 0x6F, 0x11, 0xF7, 0xAE, 0xCF, 0x3C, 0xD5, 0x77, 0xB3, 0xE5, 0x51, 0xB7, 0x98, 0xF8, 0x7A, 0xFE, 0x08, 0x79, 0x3B, 0x5D, 0x48, 0xF8, 0x48, 0x52, 0xEA, 0x4C, 0xF1, 0xD3, 0xB7, 0x2C, 0x7E, 0xCB, 0x27, 0xD1, 0x64, 0x19, 0x71, 0x80, 0xE6, 0xE9, 0x6D, 0xAA, 0xA0, 0x8C, 0x8F, 0x55, 0xF5, 0x11, 0xB9, 0x81, 0xC7, 0xB8, 0x17, 0x00, 0xBE, 0xF5, 0xA3, 0xB9, 0x4B, 0x2B, 0x88, 0x99, 0xED, 0x6F, 0x77, 0x62, 0xF1, 0x36, 0x81, 0xA1, 0xED, 0x1B, 0x42, 0xB6, 0xD2, 0x5B, 0xEF, 0xEE, 0xAA, 0xE8, 0x29, 0xE6, 0xE9, 0xE3, 0x34, 0xF2, 0x06, 0x1D, 0xED, 0xD2, 0xDE, 0x39, 0x07, 0x86, 0x0A, 0xA5, 0x3C, 0xE3, 0x11, 0x85, 0xAD, 0xB1, 0x5D, 0x69, 0xFF, 0x00, 0xBC, 0x0A, 0xF5, 0x72, 0xE5, 0x0D, 0x3A, 0xCF, 0x8A, 0xD1, 0x44, 0x32, 0x98, 0xAF, 0xF7, 0x1B, 0x7B, 0x40, 0xE8, 0x29, 0x65, 0x92, 0x38, 0xC9, 0xEB, 0x61, 0xAF, 0xDD, 0x19, 0x3E, 0x0A, 0x5A, 0xF5, 0x34, 0x2B, 0x46, 0xB4, 0x14, 0xE3, 0xB8, 0xE3, 0xCE, 0x0E, 0x0F, 0x65, 0x84, 0x44, 0x5B, 0x4C, 0x02, 0x22, 0x20, 0x08, 0x88, 0x80, 0x22, 0x22, 0x00, 0x88, 0x88, 0x02, 0x93, 0x4F, 0xD4, 0x3E, 0x2A, 0x32, 0x93, 0x4F, 0xD4, 0x3E, 0x2A, 0x18, 0x3E, 0xB3, 0x3A, 0x36, 0xCF, 0xF6, 0x52, 0xFE, 0x21, 0x5E, 0x9D, 0xA6, 0xD5, 0x4B, 0x6A, 0x89, 0xF1, 0xD1, 0x35, 0xED, 0x63, 0xCE, 0xF3, 0xB7, 0x9D, 0xBD, 0xC5, 0x7A, 0xDE, 0x4A, 0xFE, 0xF6, 0xFD, 0xEB, 0xB6, 0x3A, 0x76, 0x86, 0xFF, 0x00, 0xA4, 0x00, 0x9F, 0x81, 0x5F, 0x95, 0x6A, 0x63, 0x67, 0x38, 0xDA, 0x52, 0x6D, 0x1E, 0xFA, 0xAE, 0x36, 0xAD, 0x48, 0xEC, 0xCE, 0x6D, 0xAF, 0x32, 0x10, 0x5C, 0xE5, 0x4E, 0xF2, 0x78, 0xBD, 0x9F, 0xCC, 0xA7, 0x93, 0xC5, 0xEC, 0xFE, 0x65, 0x56, 0xE3, 0x91, 0x5B, 0x8C, 0x89, 0x07, 0x25, 0x47, 0xB8, 0x51, 0xC3, 0x5F, 0x4A, 0xFA, 0x7A, 0x96, 0x97, 0x44, 0xFE, 0x60, 0x1C, 0x2F, 0x5B, 0xC9, 0xE2, 0xF6, 0x7F, 0x32, 0xB8, 0x75, 0x3C, 0x78, 0x3B, 0xAD, 0xC1, 0xF1, 0x2A, 0x63, 0x5D, 0x45, 0xDD, 0x6F, 0x32, 0x8D, 0x65, 0x16, 0x9A, 0xD1, 0x94, 0xFF, 0x00, 0x43, 0x6D, 0x1F, 0x65, 0x2F, 0xE2, 0x14, 0xF4, 0x36, 0xD1, 0xF6, 0x52, 0xFE, 0x21, 0x56, 0xB3, 0x4A, 0xFE, 0xC2, 0xD5, 0xC7, 0x92, 0xBF, 0xBD, 0xAA, 0xDF, 0xC7, 0xD6, 0xF9, 0xDF, 0xA9, 0x6F, 0x94, 0x6B, 0xF7, 0x8F, 0xD4, 0xAA, 0xFA, 0x1B, 0x68, 0xFB, 0x29, 0x7F, 0x14, 0xAE, 0x3D, 0x0C, 0xB3, 0xFD, 0x8C, 0xBF, 0x8A, 0x55, 0xAF, 0xC9, 0x5F, 0xDE, 0xD4, 0x14, 0xAF, 0xED, 0x2D, 0xFB, 0xD3, 0x94, 0x2B, 0x7C, 0xEF, 0xD4, 0x72, 0x8D, 0x7E, 0xF1, 0xFA, 0x90, 0xE9, 0xA1, 0x6D, 0x35, 0x3C, 0x70, 0xC7, 0x90, 0xC8, 0xDA, 0x1A, 0xDC, 0x9E, 0xC0, 0xBB, 0x72, 0xA7, 0x79, 0x3C, 0x78, 0xE2, 0xDF, 0xCC, 0xA7, 0x93, 0xC5, 0xEC, 0xFE, 0x65, 0x54, 0x75, 0xD3, 0x77, 0x65, 0x37, 0x55, 0x37, 0x76, 0x41, 0xCF, 0x72, 0xF9, 0x9B, 0x6B, 0xFF, 0x00, 0xF9, 0x8F, 0xD3, 0x1F, 0xD6, 0xDB, 0xFF, 0x00, 0xC6, 0x5F, 0x53, 0xF9, 0x3C, 0x5E, 0xCF, 0xE6, 0x57, 0xCB, 0xBB, 0x64, 0x63, 0x47, 0xE9, 0x2B, 0xA6, 0x9A, 0x38, 0x01, 0x25, 0x01, 0xFE, 0xF5, 0x7A, 0xEE, 0x05, 0xD4, 0x53, 0xC7, 0x49, 0x2F, 0x95, 0xFF, 0x00, 0x45, 0x4C, 0x5C, 0xD4, 0xA0, 0x92, 0xED, 0x3E, 0xA1, 0xB8, 0xD5, 0x3A, 0x37, 0xBA, 0x36, 0x81, 0xC4, 0x73, 0x55, 0x4B, 0xCD, 0x5D, 0x65, 0x33, 0xE3, 0x14, 0x70, 0x74, 0xA1, 0xD9, 0xDE, 0x3B, 0x85, 0xD8, 0xFB, 0x95, 0x92, 0xF1, 0xFC, 0xEC, 0xF8, 0x05, 0xE7, 0x2F, 0xB2, 0x65, 0x54, 0x61, 0x0C, 0x34, 0x5C, 0x55, 0x9B, 0x4A, 0xE7, 0x4B, 0x0B, 0xB3, 0x04, 0xA5, 0x6B, 0x9C, 0x42, 0x5C, 0x62, 0x69, 0x78, 0xC3, 0x88, 0x19, 0x1D, 0xC5, 0x64, 0x79, 0xAE, 0x17, 0x55, 0x45, 0x44, 0x54, 0xCC, 0x0F, 0x9D, 0xE1, 0x8D, 0x27, 0x00, 0x9E, 0xF5, 0xD3, 0x36, 0xA4, 0xDB, 0xD0, 0x8D, 0x4D, 0x6B, 0x82, 0x0A, 0xF7, 0xD5, 0xB1, 0xD2, 0x74, 0x8E, 0x24, 0x90, 0x48, 0xC7, 0x1E, 0x7D, 0x8A, 0x5D, 0x55, 0x3B, 0x6A, 0x61, 0x7C, 0x4F, 0xCE, 0xE3, 0xC6, 0x0E, 0x16, 0x51, 0x3D, 0xB2, 0x31, 0xAF, 0x61, 0x05, 0xAE, 0x19, 0x07, 0xBC, 0x2F, 0x0B, 0x68, 0x57, 0x4A, 0xAB, 0x26, 0x87, 0xBD, 0x5C, 0xED, 0xEF, 0x6B, 0x2A, 0xE9, 0x69, 0xDD, 0x24, 0x4E, 0x73, 0x43, 0x80, 0x70, 0xF8, 0x1E, 0x6B, 0x16, 0xD4, 0x53, 0x62, 0xA5, 0x59, 0x2E, 0x9C, 0x9E, 0xEF, 0xE8, 0xF3, 0xAE, 0x3A, 0xD3, 0x49, 0xE9, 0x2A, 0xB7, 0xDA, 0xAE, 0x77, 0x86, 0x52, 0xD5, 0x33, 0x0F, 0x74, 0x52, 0x31, 0xE4, 0x80, 0xE1, 0x91, 0xC4, 0x37, 0x0B, 0xD7, 0xD3, 0x7A, 0x9E, 0xCD, 0xA9, 0x69, 0x27, 0xA9, 0xB1, 0xD7, 0xC7, 0x57, 0x04, 0x0E, 0xDC, 0x91, 0xED, 0x0E, 0x68, 0x69, 0xC6, 0x78, 0xE4, 0x0E, 0xC5, 0xA6, 0xB4, 0x9D, 0x8A, 0xD7, 0xB4, 0xDB, 0x24, 0x7A, 0x9B, 0x59, 0x53, 0xC9, 0x57, 0x77, 0x99, 0xCE, 0x85, 0xF2, 0xC3, 0x29, 0x85, 0xA5, 0xAC, 0x3B, 0xAD, 0x1B, 0xAD, 0xE1, 0xC0, 0x29, 0xB5, 0x76, 0x0D, 0x45, 0xA5, 0x1C, 0xEA, 0x2D, 0x99, 0xC3, 0x05, 0x3D, 0x9E, 0xA5, 0xBD, 0x25, 0x6B, 0x6A, 0xE5, 0x6C, 0x85, 0xCF, 0x19, 0x1C, 0x0B, 0xF8, 0xF5, 0x7B, 0x97, 0x3E, 0x38, 0xD6, 0xA5, 0xAA, 0xD0, 0xE4, 0xAC, 0xCD, 0xCA, 0xA5, 0xE6, 0xB4, 0xF7, 0x37, 0x75, 0x2D, 0x4C, 0x52, 0xE4, 0xC3, 0x2B, 0x24, 0xDD, 0xE7, 0xB8, 0xE0, 0x71, 0xF7, 0x2F, 0x76, 0xD7, 0x52, 0xF9, 0x67, 0x6B, 0x1D, 0x8C, 0x01, 0xDD, 0xF1, 0x0B, 0x5E, 0x68, 0x1D, 0x49, 0xA6, 0xF5, 0x2C, 0x15, 0xB3, 0x69, 0x59, 0x27, 0x92, 0x18, 0x1E, 0xD6, 0xCA, 0x65, 0x8D, 0xCD, 0xC1, 0x20, 0xE3, 0xAD, 0xE0, 0x55, 0xF2, 0xC8, 0x0F, 0x96, 0x00, 0x3B, 0xBE, 0x8B, 0x5E, 0x65, 0x4E, 0x9D, 0x5C, 0x33, 0x9B, 0x57, 0x6B, 0x71, 0x7B, 0x10, 0xE9, 0xCE, 0x0E, 0x50, 0xD5, 0x1F, 0x04, 0xCF, 0xFF, 0x00, 0x8C, 0xEF, 0x9F, 0xB4, 0xCD, 0xFE, 0x21, 0x53, 0x26, 0x95, 0x90, 0xC6, 0x64, 0x91, 0xDB, 0xAC, 0x1C, 0xCA, 0xF3, 0x6E, 0x35, 0x31, 0x52, 0xEB, 0x0B, 0xDB, 0xE6, 0x24, 0x34, 0xD5, 0x4C, 0x39, 0x67, 0xFA, 0x42, 0xAF, 0x9A, 0x33, 0x40, 0xDC, 0xEF, 0xF5, 0x96, 0xEA, 0xFB, 0xA4, 0x11, 0xC9, 0xA5, 0xEA, 0x83, 0x9E, 0x43, 0x66, 0x0D, 0x91, 0xCD, 0x01, 0xC1, 0xBC, 0x07, 0x11, 0xEB, 0x80, 0xAD, 0x61, 0xB1, 0x70, 0xA1, 0x87, 0x4B, 0xAC, 0xF2, 0x55, 0x29, 0x39, 0xD4, 0xF0, 0x29, 0xD0, 0xDC, 0x29, 0x66, 0x95, 0xB1, 0xC7, 0x28, 0x73, 0xDD, 0xC8, 0x60, 0xA9, 0x4B, 0x66, 0xEB, 0xBD, 0x9D, 0xE9, 0x9B, 0x06, 0x8E, 0xB9, 0xDD, 0x6D, 0x54, 0x53, 0xC5, 0x5F, 0x4D, 0x18, 0x74, 0x4F, 0x75, 0x43, 0x9C, 0x1A, 0x4B, 0x80, 0xE2, 0xD3, 0xCF, 0x81, 0x2B, 0x51, 0xD9, 0xAA, 0x24, 0xA9, 0xA4, 0x2F, 0x99, 0xDB, 0xCE, 0xDF, 0x23, 0x38, 0xC7, 0x72, 0xB5, 0x83, 0xC6, 0xBA, 0xEF, 0x66, 0x4B, 0x53, 0x5D, 0x6A, 0x1B, 0x0A, 0xE8, 0x9E, 0x88, 0x8B, 0xA0, 0x56, 0x08, 0x88, 0x80, 0x22, 0x22, 0x00, 0x88, 0x88, 0x02, 0x93, 0x4F, 0xD4, 0x3E, 0x2A, 0x32, 0x93, 0x4F, 0xD4, 0x3E, 0x2A, 0x18, 0x3E, 0xE9, 0x50, 0x2E, 0x17, 0x4A, 0x7A, 0x19, 0x1A, 0xC9, 0xC9, 0x05, 0xC3, 0x23, 0x03, 0x2A, 0x9C, 0x2E, 0x55, 0x9E, 0xF3, 0x2F, 0xCC, 0xBA, 0xA7, 0x9E, 0x59, 0xDC, 0x1D, 0x34, 0x8E, 0x79, 0x03, 0x00, 0xB8, 0xE5, 0x7E, 0x57, 0x86, 0x5F, 0x67, 0xD3, 0x7A, 0x15, 0xF1, 0x3C, 0x2E, 0x52, 0xA7, 0x6C, 0x3C, 0x1A, 0x97, 0x8E, 0xE2, 0xD9, 0xE9, 0x15, 0x0F, 0xB4, 0xFF, 0x00, 0x94, 0xA7, 0xA4, 0x54, 0x3E, 0xD3, 0xFE, 0x52, 0xA9, 0xBB, 0xA1, 0x30, 0x16, 0xEF, 0x80, 0xA5, 0xE2, 0x73, 0x39, 0xD5, 0x8F, 0xFF, 0x00, 0x6F, 0xA7, 0xE4, 0xB9, 0xFA, 0x45, 0x41, 0xED, 0xBF, 0xE4, 0x2B, 0xB2, 0x9A, 0xF7, 0x47, 0x53, 0x3B, 0x22, 0x89, 0xCE, 0x2F, 0x71, 0xC0, 0xCB, 0x48, 0x54, 0x8E, 0x1F, 0x04, 0x64, 0x8E, 0x8A, 0x40, 0xF8, 0x9C, 0x5A, 0xE1, 0xC8, 0x8E, 0x61, 0x1E, 0x5F, 0x4E, 0xDA, 0x5C, 0xCE, 0x1C, 0x2C, 0xC6, 0x29, 0x27, 0x35, 0x1B, 0x75, 0xD9, 0x7E, 0x4D, 0x95, 0x90, 0xB9, 0x5A, 0xFD, 0xB7, 0x3A, 0xEE, 0xDA, 0xA9, 0x7E, 0x65, 0xCF, 0x9C, 0x6B, 0x3D, 0xE6, 0x5F, 0x99, 0x56, 0xE4, 0xE9, 0xF6, 0x9D, 0x7E, 0x77, 0xD0, 0xEE, 0xDF, 0xB1, 0x7F, 0x5C, 0x2A, 0x0F, 0x9C, 0x6B, 0x3D, 0xE6, 0x5F, 0x99, 0x3C, 0xE5, 0x5B, 0xEF, 0x32, 0xFC, 0xC9, 0xC9, 0xD3, 0xED, 0x27, 0x9D, 0xF4, 0x3B, 0xB7, 0xEC, 0x5A, 0x65, 0xBF, 0x51, 0x45, 0x23, 0x98, 0xF7, 0xBF, 0x79, 0xA7, 0x07, 0xD4, 0x2B, 0x0F, 0x48, 0xA8, 0x3D, 0xA7, 0xFC, 0xA5, 0x53, 0xDC, 0x4B, 0x9C, 0x5C, 0xE2, 0x49, 0x3C, 0xC9, 0x54, 0xBB, 0xC6, 0xD1, 0xB4, 0xDD, 0xA6, 0xE9, 0x53, 0x41, 0x5B, 0x56, 0xE6, 0x54, 0xD3, 0xBC, 0xB2, 0x46, 0x86, 0x64, 0x02, 0x3B, 0x32, 0xAF, 0xD0, 0xC9, 0xFE, 0x21, 0xDA, 0x9C, 0x5C, 0x9A, 0xEC, 0x39, 0x70, 0xE1, 0x26, 0x63, 0x5A, 0x4D, 0x51, 0x82, 0x7F, 0x46, 0xFF, 0x00, 0xB3, 0x72, 0x7A, 0x45, 0x43, 0xED, 0x3F, 0xE5, 0x2B, 0xE6, 0xAD, 0xAE, 0xD4, 0xC7, 0x57, 0xFA, 0x47, 0xE9, 0x99, 0x61, 0x24, 0xB0, 0xCB, 0x6F, 0xE6, 0x31, 0xFD, 0x28, 0x5E, 0xBD, 0xF7, 0x6B, 0x16, 0x0F, 0x31, 0xDC, 0x3C, 0xD5, 0x5C, 0xF1, 0x70, 0xE8, 0x1F, 0xE4, 0xE7, 0xA2, 0xE5, 0x26, 0x0E, 0xEF, 0x3F, 0x8E, 0x16, 0x9E, 0xD3, 0x97, 0xDB, 0x8E, 0xA1, 0xDA, 0x86, 0x99, 0xAE, 0xBC, 0x54, 0x9A, 0x9A, 0xA3, 0x71, 0xA4, 0x66, 0xF9, 0x63, 0x5B, 0xEA, 0x89, 0x5B, 0x81, 0x86, 0x80, 0x17, 0xB2, 0xE0, 0xC6, 0x47, 0x53, 0x07, 0x56, 0x58, 0x89, 0x27, 0x1D, 0x1A, 0xB3, 0xDF, 0xD5, 0xE0, 0x76, 0x72, 0xEC, 0x6E, 0x3F, 0x15, 0x77, 0x8A, 0x49, 0x25, 0xE0, 0xD3, 0x3E, 0xEA, 0xBB, 0xFF, 0x00, 0x3B, 0x3E, 0x01, 0x79, 0xC7, 0x82, 0x9F, 0x7C, 0x78, 0x8E, 0x77, 0xBD, 0xC7, 0x0D, 0x6B, 0x72, 0x4F, 0xC3, 0x0B, 0xC7, 0xA3, 0xAF, 0xA7, 0xAE, 0xDF, 0x14, 0xEF, 0x2E, 0xDC, 0xC6, 0x78, 0x11, 0xCF, 0xC5, 0x7D, 0x3B, 0x2D, 0x7F, 0xE2, 0xD3, 0xF2, 0x47, 0xB8, 0xA1, 0x16, 0xE9, 0xA6, 0x96, 0x87, 0x14, 0x75, 0xF0, 0x56, 0x3A, 0x46, 0xC0, 0xE2, 0xE2, 0xCE, 0xB7, 0x02, 0x3F, 0xEF, 0x92, 0xEC, 0xAC, 0xA3, 0x86, 0xB6, 0x21, 0x1C, 0xED, 0x25, 0xA0, 0xEF, 0x60, 0x1C, 0x71, 0xFF, 0x00, 0xB2, 0xB8, 0xA6, 0xA3, 0xA7, 0xA6, 0x73, 0xCD, 0x3C, 0x61, 0x85, 0xFD, 0x6C, 0x13, 0xC5, 0x77, 0xAB, 0xDE, 0x66, 0xF9, 0x34, 0xA5, 0x7A, 0x77, 0x47, 0x11, 0x44, 0xD8, 0x62, 0x64, 0x71, 0x8C, 0x35, 0x80, 0x34, 0x78, 0x05, 0x53, 0xDA, 0xF7, 0xFB, 0xAF, 0xD4, 0xBF, 0xB1, 0xB9, 0x7B, 0x54, 0x8C, 0xB9, 0x79, 0xD5, 0xEE, 0x9D, 0xFF, 0x00, 0xC8, 0xF7, 0x9D, 0x81, 0x91, 0xCB, 0xB3, 0xE2, 0xB4, 0x9E, 0xB9, 0xD5, 0x97, 0xBA, 0xBD, 0xB4, 0x4B, 0xA2, 0xEA, 0x2B, 0xDC, 0xFD, 0x33, 0x53, 0x35, 0x3C, 0x13, 0x51, 0x6E, 0x34, 0x07, 0xB1, 0xF1, 0x31, 0xCE, 0x1B, 0xC0, 0x6F, 0x71, 0x24, 0x9E, 0x05, 0x57, 0xC4, 0x54, 0xD8, 0x83, 0xD0, 0xAB, 0x8F, 0x9F, 0x11, 0x0D, 0x75, 0xBF, 0x61, 0xE9, 0xEC, 0x23, 0xFD, 0xDA, 0xD1, 0x7F, 0x5F, 0x37, 0xFD, 0x4A, 0xFE, 0x70, 0x5A, 0x41, 0xE4, 0x46, 0x0A, 0x83, 0x65, 0xB4, 0x50, 0xD8, 0xED, 0xCD, 0xA1, 0xB4, 0xD3, 0x8A, 0x7A, 0x56, 0x38, 0xB9, 0xB1, 0x87, 0x17, 0x60, 0x9E, 0x7C, 0x49, 0x25, 0x58, 0x2D, 0x56, 0x5A, 0x9B, 0x8D, 0x24, 0xF5, 0x30, 0xBA, 0x26, 0xC7, 0x09, 0x20, 0xEF, 0x92, 0x09, 0xC0, 0xCF, 0x0C, 0x05, 0xC8, 0x3C, 0xE3, 0x35, 0x46, 0xA0, 0xD3, 0xBA, 0x8E, 0xC1, 0x25, 0x34, 0x7B, 0x2C, 0xDC, 0xB5, 0xD3, 0xCA, 0xC2, 0xEA, 0xD6, 0xB6, 0x50, 0x04, 0x8F, 0x07, 0xD5, 0x3E, 0xBE, 0x79, 0x03, 0xD9, 0x85, 0xE6, 0x44, 0xED, 0xB6, 0xC6, 0xED, 0xE8, 0xEF, 0x21, 0xAE, 0x1D, 0xBD, 0x34, 0x5F, 0xFD, 0x85, 0x75, 0xD1, 0x7A, 0xC6, 0xDB, 0xAC, 0x20, 0xAA, 0x96, 0xD4, 0xCA, 0x96, 0xB6, 0x99, 0xCD, 0x6B, 0xFA, 0x76, 0x06, 0x9C, 0x90, 0x48, 0xC6, 0x09, 0xEE, 0x56, 0x44, 0xDA, 0x76, 0xB5, 0xCC, 0xD4, 0xE4, 0x95, 0xAE, 0x69, 0x1D, 0x0B, 0xB2, 0xCB, 0x80, 0xD4, 0x75, 0x95, 0x7A, 0xDE, 0x86, 0x9A, 0xAA, 0x9A, 0x68, 0x9E, 0xEF, 0xF6, 0xC1, 0xC4, 0xCC, 0x5E, 0xD3, 0x9C, 0x34, 0x8E, 0xCD, 0xEF, 0xBD, 0x6E, 0x5B, 0x6D, 0x0D, 0x35, 0xB2, 0x82, 0x1A, 0x2A, 0x18, 0x84, 0x34, 0xB0, 0x8D, 0xD8, 0xE3, 0x04, 0x90, 0xD1, 0xCF, 0xB5, 0x48, 0xDE, 0xC9, 0x59, 0xEA, 0x66, 0x7A, 0x39, 0xA3, 0x6A, 0x75, 0x35, 0x7B, 0x83, 0xA8, 0x20, 0x6B, 0x5E, 0xF6, 0x45, 0x93, 0x26, 0x1C, 0xF0, 0xC1, 0x80, 0x70, 0x39, 0xB8, 0x76, 0xA8, 0xB1, 0x81, 0x50, 0xDA, 0xD9, 0xC6, 0xCD, 0xEF, 0xBF, 0xD5, 0x37, 0xFE, 0xB6, 0xAF, 0x9C, 0x74, 0xEF, 0xF3, 0x07, 0x7F, 0x58, 0x7F, 0xE4, 0x17, 0xD3, 0xD4, 0x15, 0x36, 0xCD, 0x6D, 0xA5, 0x1B, 0x33, 0xA0, 0x96, 0x4B, 0x65, 0x7B, 0x48, 0x31, 0x4B, 0x96, 0x38, 0x80, 0xE2, 0x38, 0xEE, 0x9E, 0x1C, 0x5B, 0xD8, 0x56, 0x8B, 0xDA, 0xBD, 0xB2, 0x8F, 0x4C, 0xEB, 0x6A, 0x3B, 0x6D, 0x8E, 0x01, 0x4B, 0x45, 0x2D, 0x34, 0x72, 0x3A, 0x20, 0xE2, 0xE0, 0x5C, 0x5E, 0xE0, 0x4E, 0x5C, 0x49, 0xE4, 0xD0, 0xAD, 0xE0, 0xAA, 0xAA, 0x55, 0x53, 0x7D, 0x7A, 0x1A, 0xAB, 0x45, 0xCA, 0x36, 0x3C, 0x94, 0x44, 0x5E, 0x90, 0xE6, 0x84, 0x44, 0x40, 0x11, 0x11, 0x00, 0x44, 0x44, 0x01, 0x49, 0xA7, 0xEA, 0x1F, 0x15, 0x19, 0x49, 0xA7, 0xEA, 0x1F, 0x15, 0x0F, 0x71, 0x26, 0xFB, 0x3A, 0xB6, 0xDE, 0x09, 0xC3, 0x6A, 0x3E, 0x41, 0xF5, 0x5E, 0x5D, 0xDB, 0x54, 0xCB, 0x24, 0xEC, 0x36, 0xC9, 0x1F, 0x1C, 0x41, 0xBE, 0xB0, 0x7B, 0x07, 0x3C, 0xFF, 0x00, 0xF8, 0xAB, 0x25, 0x87, 0xD9, 0x3F, 0x72, 0xE9, 0x92, 0x51, 0x0B, 0x83, 0x5E, 0xD7, 0xF1, 0xE3, 0xC9, 0x67, 0x81, 0xE0, 0x06, 0x4B, 0x84, 0xAA, 0xAA, 0xC2, 0x9B, 0x93, 0xEC, 0x93, 0xBA, 0xF4, 0x67, 0x91, 0xA5, 0x82, 0x75, 0x25, 0xB3, 0x4E, 0x2D, 0xBE, 0xC3, 0xDE, 0xF4, 0x96, 0xE9, 0xF6, 0xED, 0xF9, 0x1B, 0xF4, 0x4F, 0x49, 0x2E, 0x9F, 0x6E, 0xDF, 0x91, 0xBF, 0x45, 0x5E, 0xF2, 0xB6, 0x7B, 0x0F, 0xFC, 0xBE, 0xA9, 0xE5, 0x4D, 0xF6, 0x1F, 0xF9, 0x7D, 0x57, 0x6B, 0x9B, 0x39, 0x57, 0xFA, 0x58, 0x7F, 0x14, 0x5B, 0xE4, 0x8C, 0x4F, 0x72, 0xFD, 0x0B, 0x0F, 0xA4, 0x97, 0x4F, 0xB7, 0x6F, 0xC8, 0xDF, 0xA2, 0x91, 0x41, 0xA9, 0xEA, 0xD9, 0x54, 0xC7, 0x56, 0xCA, 0x5F, 0x00, 0xEB, 0x35, 0xAC, 0x6E, 0x4A, 0xAB, 0x9A, 0xA6, 0x76, 0x36, 0x4F, 0xB8, 0x7D, 0x51, 0xB5, 0x2D, 0x73, 0x9A, 0xD0, 0xC7, 0xEF, 0x38, 0xE0, 0x72, 0x5A, 0xEA, 0xF0, 0x57, 0x2A, 0xAB, 0x07, 0x07, 0x86, 0x82, 0xBA, 0xB6, 0x91, 0x49, 0xFD, 0x19, 0x13, 0xCA, 0x71, 0x11, 0x57, 0x95, 0x26, 0x97, 0x91, 0xB1, 0x3D, 0x2F, 0xB7, 0x7B, 0x13, 0xFC, 0xA3, 0xEA, 0xB8, 0xF4, 0xBE, 0xDF, 0xEC, 0xCF, 0xF2, 0x8F, 0xAA, 0xA1, 0x88, 0xCF, 0x6B, 0x4F, 0xDC, 0xB9, 0xE8, 0xCF, 0xB2, 0x57, 0x9E, 0xFD, 0x36, 0xC8, 0xFE, 0x59, 0x7F, 0x22, 0x8F, 0xC3, 0x47, 0xC4, 0xBD, 0xFA, 0x5F, 0x6F, 0xF6, 0x67, 0xF9, 0x47, 0xD5, 0x72, 0xDD, 0x5D, 0x6F, 0x2E, 0x03, 0x76, 0x7E, 0x3F, 0xF0, 0x0F, 0xAA, 0xA1, 0xEE, 0x1F, 0x64, 0xFD, 0xCB, 0x9D, 0xD7, 0x0E, 0x4D, 0x3F, 0x72, 0x8F, 0xD3, 0x6C, 0x8F, 0xE5, 0x97, 0xF2, 0x63, 0xE1, 0xA3, 0xE2, 0x52, 0x62, 0xAB, 0xD5, 0x5A, 0xB3, 0x68, 0x17, 0x3B, 0x5D, 0x8A, 0xF7, 0x51, 0x4E, 0x4C, 0xB3, 0x3E, 0x36, 0xCD, 0x52, 0xE8, 0xD8, 0xD6, 0x34, 0x9E, 0x1C, 0x33, 0x8E, 0x0B, 0x73, 0x59, 0x34, 0x5D, 0xB6, 0x3B, 0x4D, 0x23, 0x2F, 0xB6, 0xEA, 0x0A, 0xDB, 0xA8, 0x8C, 0x79, 0x4D, 0x43, 0xE3, 0x12, 0x19, 0x64, 0xED, 0x25, 0xC4, 0x64, 0xF8, 0x95, 0xAB, 0xEE, 0x74, 0xB2, 0x44, 0xD9, 0xAA, 0x34, 0xEE, 0xED, 0x15, 0xE0, 0xBC, 0xFF, 0x00, 0x29, 0x69, 0xDC, 0x76, 0x0F, 0x5B, 0xD6, 0x1D, 0xEB, 0xCC, 0x23, 0x5D, 0xF6, 0x6A, 0x67, 0xFF, 0x00, 0x69, 0x7F, 0xF9, 0x55, 0x1C, 0x57, 0x07, 0xB1, 0x18, 0x3A, 0x9B, 0x14, 0xA9, 0xB9, 0x2E, 0xD4, 0xBD, 0x8F, 0xA0, 0xE0, 0x69, 0xB9, 0x52, 0x53, 0x8C, 0x36, 0x7D, 0x8B, 0xCE, 0xA8, 0xBC, 0xEC, 0xEB, 0x4C, 0xDE, 0xA6, 0xB6, 0x5C, 0xF4, 0xCC, 0x6F, 0xA9, 0x8C, 0x35, 0xC4, 0xC5, 0x45, 0x13, 0x9A, 0x43, 0x80, 0x23, 0x89, 0x23, 0xBD, 0x6B, 0xD7, 0x5D, 0x2C, 0xB7, 0x7D, 0xB1, 0xE9, 0xAA, 0xAD, 0x37, 0x46, 0x68, 0xED, 0xFE, 0x5D, 0x46, 0xC1, 0x11, 0x89, 0xB1, 0x90, 0xE1, 0x2B, 0x72, 0x70, 0x09, 0x0A, 0x38, 0xD3, 0x57, 0x7A, 0xCB, 0xEC, 0x37, 0x0B, 0xED, 0x5C, 0x15, 0xF8, 0x7B, 0x4C, 0xBB, 0xF2, 0xB9, 0xCE, 0x7B, 0x47, 0x0C, 0x71, 0x1D, 0xCA, 0x44, 0x14, 0x94, 0xD4, 0xFB, 0x60, 0xD2, 0xF1, 0x51, 0xD3, 0x88, 0x63, 0x35, 0xB4, 0x87, 0x71, 0xA3, 0x1C, 0x7A, 0x51, 0xDD, 0xFB, 0x95, 0x7A, 0xF9, 0x65, 0x7A, 0x18, 0x67, 0x5E, 0xAC, 0x5C, 0x55, 0xED, 0x66, 0xB5, 0xDC, 0x6F, 0x6A, 0x71, 0x9A, 0x8B, 0x8B, 0xB7, 0x6F, 0x51, 0xF6, 0xA5, 0xED, 0x82, 0x49, 0xDE, 0xD7, 0x0C, 0xB5, 0xCD, 0xC1, 0x1D, 0xEB, 0xC8, 0xA5, 0xA2, 0xA7, 0xA4, 0xDE, 0xF2, 0x78, 0xC3, 0x37, 0xB1, 0x9C, 0x13, 0xC7, 0x0A, 0xD7, 0x57, 0x03, 0x65, 0x0F, 0x69, 0x6B, 0x77, 0x8F, 0x69, 0x1C, 0x95, 0x3F, 0x50, 0xDB, 0xAE, 0x3D, 0x2C, 0x5E, 0x49, 0x28, 0x8C, 0x60, 0xEF, 0x61, 0xF8, 0xCA, 0xAB, 0x94, 0x63, 0x69, 0xD4, 0xA4, 0xA9, 0x3D, 0x1A, 0xD3, 0xCC, 0xF4, 0x98, 0x4A, 0x8A, 0x69, 0x53, 0xDA, 0xB1, 0x37, 0x90, 0xCA, 0x81, 0x4B, 0x74, 0x82, 0xA6, 0xAD, 0xF4, 0xF1, 0x87, 0xF4, 0x8D, 0xCE, 0x72, 0x38, 0x70, 0x53, 0xA3, 0x6B, 0x9B, 0x13, 0x5A, 0xFC, 0x97, 0x00, 0x01, 0x3D, 0xEB, 0xA6, 0x2A, 0x58, 0x63, 0x94, 0xC9, 0x1C, 0x51, 0xB6, 0x43, 0xCD, 0xC1, 0xA0, 0x13, 0xFB, 0xD7, 0x6A, 0xE5, 0x88, 0xB8, 0xD9, 0xDF, 0xE8, 0x77, 0x8E, 0x6B, 0xE6, 0x3D, 0x5E, 0x3F, 0xD6, 0x8E, 0x1F, 0xDA, 0xE9, 0x3F, 0xC0, 0x8D, 0x7D, 0x38, 0x3F, 0x35, 0xA4, 0x36, 0x87, 0xA1, 0x6B, 0xED, 0xFA, 0xFA, 0xB7, 0x68, 0xCF, 0xA9, 0xA5, 0x7D, 0xBA, 0x83, 0xA2, 0xAA, 0x7D, 0x2B, 0x4B, 0xBA, 0x57, 0x36, 0x38, 0xDA, 0xC2, 0x07, 0x0C, 0x64, 0x91, 0xDE, 0xAA, 0xE3, 0x13, 0x94, 0x2C, 0x8E, 0x7E, 0x61, 0x07, 0x3A, 0x5D, 0x13, 0x67, 0x52, 0xDB, 0xE4, 0x9D, 0x9B, 0xED, 0x2D, 0x0D, 0xCF, 0x6A, 0xA3, 0xED, 0x2B, 0x4F, 0xEB, 0x89, 0xEB, 0xE9, 0x0E, 0x8F, 0xBF, 0xBA, 0xDB, 0x48, 0x61, 0x2D, 0x9E, 0x36, 0xD5, 0xBE, 0x21, 0x23, 0xF2, 0x78, 0xE1, 0xA0, 0xE7, 0x81, 0x01, 0x59, 0x76, 0x7D, 0xAB, 0xE9, 0xF5, 0x1E, 0x98, 0x86, 0xE7, 0x4F, 0x4B, 0x2C, 0x31, 0x49, 0x23, 0xDB, 0xB9, 0x23, 0x86, 0x41, 0x69, 0xC7, 0x62, 0xF4, 0x6F, 0x15, 0x7D, 0x3C, 0x2F, 0x73, 0x37, 0x9B, 0xBA, 0xC7, 0x63, 0x8F, 0x6E, 0x39, 0xAE, 0x1A, 0x73, 0xDB, 0xD7, 0x71, 0xCE, 0x9A, 0xA3, 0xC5, 0x5D, 0x3E, 0x91, 0xAD, 0xB6, 0x45, 0xA2, 0x6E, 0x9A, 0x32, 0x8E, 0xE7, 0x15, 0xD9, 0xF4, 0xAF, 0x75, 0x4B, 0xE3, 0x73, 0x3A, 0x07, 0x97, 0x0C, 0x00, 0xE0, 0x73, 0x90, 0x3B, 0xD6, 0xC1, 0x63, 0x72, 0x79, 0x2F, 0x9A, 0xF6, 0x63, 0xB4, 0xC6, 0x69, 0x5A, 0x6B, 0x84, 0x77, 0x68, 0x6B, 0x6E, 0x0F, 0xA8, 0x7B, 0x1C, 0xC7, 0x74, 0xB9, 0xDC, 0x00, 0x1C, 0xF5, 0x8F, 0xC5, 0x77, 0x6D, 0x33, 0x6A, 0x10, 0x6A, 0x9B, 0x45, 0x1D, 0x35, 0xAA, 0x9E, 0xBA, 0x82, 0x78, 0x67, 0x32, 0x3D, 0xE6, 0x50, 0x03, 0x9B, 0xBA, 0x46, 0x3D, 0x53, 0xDE, 0x56, 0xF2, 0xA1, 0xB4, 0x34, 0x3E, 0x9C, 0xD5, 0x96, 0xBD, 0x57, 0x5F, 0x57, 0x7F, 0xBA, 0x8A, 0xBB, 0x5C, 0x91, 0xC8, 0xD8, 0x21, 0xF2, 0x97, 0xC9, 0xBA, 0x4B, 0xDA, 0x5A, 0x77, 0x48, 0xC0, 0xF5, 0x41, 0x1F, 0xBD, 0x78, 0xFA, 0xEB, 0x46, 0xED, 0x0B, 0x50, 0x55, 0xDC, 0xE9, 0xE9, 0xB5, 0x03, 0x46, 0x9E, 0xA9, 0x90, 0x16, 0x50, 0xCB, 0x59, 0x20, 0x60, 0x68, 0x20, 0x80, 0x58, 0x1A, 0x47, 0x30, 0x0A, 0x85, 0x6F, 0xDB, 0x95, 0xA6, 0x9E, 0x82, 0x96, 0x09, 0x6D, 0x55, 0xEF, 0x92, 0x28, 0x9A, 0xC7, 0x3B, 0x7D, 0x9E, 0xB1, 0x00, 0x02, 0x79, 0xAA, 0xCE, 0x8B, 0xD4, 0xD3, 0x5F, 0xF6, 0xDB, 0x4D, 0x59, 0x4F, 0x2D, 0x5C, 0x34, 0x35, 0x53, 0xCA, 0xF6, 0xD3, 0xC9, 0x29, 0x21, 0xA3, 0xA2, 0x77, 0x02, 0x07, 0x0E, 0xC4, 0x06, 0xF7, 0xD9, 0xC6, 0x94, 0xAC, 0xB2, 0x68, 0xAB, 0x65, 0xBA, 0xBA, 0x58, 0x0D, 0x44, 0x0D, 0x78, 0x71, 0x89, 0xC5, 0xCD, 0x39, 0x7B, 0x8F, 0x03, 0x81, 0xD8, 0x56, 0x90, 0xFD, 0x21, 0x60, 0x34, 0xFB, 0x4F, 0xB7, 0x30, 0x90, 0x7F, 0x91, 0x42, 0x72, 0x3F, 0xAC, 0x91, 0x7D, 0x09, 0x7C, 0xD4, 0xB0, 0xE9, 0xAD, 0x2D, 0x57, 0x75, 0xA9, 0xA6, 0x96, 0x78, 0x28, 0xDA, 0x1C, 0xF6, 0xC6, 0x40, 0x27, 0x2E, 0x03, 0x86, 0x78, 0x76, 0xAF, 0x9A, 0x36, 0x8D, 0xA9, 0x29, 0xB5, 0xF6, 0xAA, 0xA7, 0xBE, 0xD0, 0x53, 0x4D, 0x49, 0x0C, 0x30, 0xB2, 0x9F, 0xA3, 0x9D, 0xC0, 0xB8, 0x96, 0xB9, 0xCE, 0x27, 0x87, 0x0F, 0xFD, 0x49, 0x84, 0x8D, 0x5A, 0x95, 0xD2, 0x4B, 0x42, 0xC6, 0x23, 0x88, 0x8D, 0x14, 0xD3, 0xE9, 0x1E, 0x52, 0x22, 0x2F, 0x5E, 0x70, 0x02, 0x22, 0x20, 0x08, 0x88, 0x80, 0x22, 0x22, 0x00, 0xA4, 0xD3, 0xF5, 0x0F, 0x8A, 0x8C, 0xA4, 0xD3, 0xF5, 0x0F, 0x8A, 0x87, 0xB8, 0x94, 0x5C, 0xDC, 0x4E, 0xF1, 0xF5, 0x8F, 0x3E, 0xF5, 0x83, 0x89, 0xED, 0xE3, 0xF1, 0x5E, 0x14, 0x97, 0xE7, 0x74, 0x8E, 0x02, 0x01, 0x80, 0x4F, 0x37, 0x28, 0x35, 0xD7, 0x19, 0x2A, 0x9C, 0xD2, 0xDC, 0xC7, 0xBB, 0xC3, 0xD5, 0x77, 0x35, 0xEA, 0xA7, 0x9A, 0xE1, 0xE3, 0x1B, 0xC5, 0xDD, 0x9D, 0xF9, 0x66, 0x14, 0x22, 0xAF, 0x1D, 0x59, 0x6A, 0x6E, 0x3B, 0x56, 0x58, 0x0A, 0x93, 0xD3, 0xCD, 0xF6, 0xB2, 0x7C, 0xCB, 0x9E, 0x9E, 0x6F, 0xB5, 0x93, 0xE6, 0x2B, 0x47, 0x2D, 0x43, 0xE5, 0x66, 0xAE, 0x54, 0x8F, 0xCB, 0xEE, 0x5D, 0xB0, 0xB1, 0xC8, 0xCF, 0x01, 0xC5, 0x52, 0xFA, 0x79, 0xBE, 0xD5, 0xFF, 0x00, 0x31, 0x5D, 0x94, 0xD5, 0x92, 0xC3, 0x3B, 0x64, 0x2F, 0x7B, 0xC3, 0x4E, 0x77, 0x4B, 0x8E, 0x0A, 0x98, 0xE7, 0x54, 0xDB, 0xB3, 0x8B, 0x25, 0x66, 0x90, 0x6E, 0xCE, 0x25, 0xCB, 0xD6, 0xF6, 0x8F, 0xDE, 0xB8, 0xF5, 0xBD, 0xA2, 0xBC, 0x01, 0x7F, 0x7F, 0xBB, 0x8F, 0x99, 0x3C, 0xFE, 0xFF, 0x00, 0x77, 0x6F, 0xCC, 0xAC, 0xF2, 0x9E, 0x1B, 0xE6, 0xF6, 0x66, 0xEF, 0x8D, 0xC2, 0xF6, 0xFB, 0x16, 0x0F, 0x5B, 0xDA, 0x3F, 0x7A, 0xE7, 0x27, 0xBC, 0xFD, 0xEA, 0xBD, 0xE7, 0xF7, 0xFD, 0x83, 0x7E, 0x64, 0x37, 0xF7, 0x9F, 0xE8, 0x1B, 0xF3, 0x29, 0xE5, 0x3C, 0x37, 0xCD, 0xEC, 0xC7, 0xC6, 0xE1, 0xBB, 0x7D, 0x8F, 0x78, 0x90, 0x0A, 0xE4, 0x60, 0xAA, 0x5C, 0xB5, 0x33, 0x3E, 0x57, 0x3C, 0x48, 0xF0, 0x1C, 0x49, 0xC6, 0xF1, 0xE0, 0xB0, 0xE9, 0xA6, 0xFB, 0x59, 0x3E, 0x62, 0xAA, 0x3C, 0xEA, 0x09, 0xE9, 0x13, 0x4B, 0xCD, 0x20, 0xB7, 0x44, 0xBB, 0xE1, 0x50, 0x75, 0x65, 0x2C, 0xB5, 0xFA, 0xE2, 0xDD, 0x4B, 0x4D, 0x2F, 0x45, 0x35, 0x41, 0x86, 0x28, 0xE4, 0xC9, 0x1B, 0x8E, 0x73, 0xF0, 0x0F, 0x0E, 0x3C, 0x09, 0x52, 0x3A, 0x79, 0xBE, 0xD6, 0x4F, 0x99, 0x78, 0x95, 0x75, 0xD2, 0x50, 0x6A, 0x7A, 0x0B, 0x86, 0xE1, 0x99, 0xD4, 0xB2, 0x47, 0x30, 0x69, 0x3D, 0x6D, 0xD7, 0xEF, 0x63, 0x3F, 0xB9, 0x70, 0xF3, 0xFC, 0xC6, 0x38, 0xAC, 0x2E, 0xC2, 0x8D, 0xB5, 0x5F, 0xD9, 0x84, 0xB1, 0xCA, 0xBA, 0xD9, 0x4A, 0xC6, 0xFE, 0xD2, 0xDB, 0x45, 0x83, 0x63, 0x16, 0xD7, 0xE9, 0x9D, 0x56, 0xCA, 0xEB, 0xD5, 0x74, 0xB2, 0x1A, 0xD6, 0x54, 0x53, 0x48, 0x1C, 0xC6, 0xC6, 0xF0, 0x1A, 0x19, 0x97, 0x90, 0x72, 0x0B, 0x1C, 0x7B, 0xB8, 0xAF, 0x5F, 0xF8, 0xCF, 0x69, 0x8E, 0xDB, 0x0D, 0xE0, 0xF8, 0x98, 0xBF, 0xCC, 0xB5, 0x55, 0xCF, 0x6C, 0x3E, 0x7A, 0x8E, 0x7A, 0x7A, 0x9D, 0x2F, 0x42, 0x1F, 0x51, 0x1B, 0xA1, 0x6C, 0xCE, 0x93, 0x7D, 0xD1, 0x87, 0x02, 0x01, 0x04, 0xB7, 0xB3, 0x39, 0x54, 0x4B, 0x7D, 0xB2, 0x3A, 0x60, 0xFE, 0x93, 0x76, 0x5D, 0xEC, 0x75, 0x98, 0x38, 0x2F, 0x15, 0x47, 0x2A, 0x8E, 0x26, 0x4D, 0xDB, 0xCD, 0x98, 0xCB, 0x12, 0xE9, 0x2B, 0x5C, 0xFA, 0x3F, 0xF8, 0xCE, 0x69, 0x6F, 0xD5, 0xEB, 0xB7, 0xF7, 0x5F, 0x54, 0xFE, 0x33, 0x9A, 0x5B, 0xF5, 0x7A, 0xED, 0xFD, 0xD7, 0xD5, 0x68, 0x9D, 0x25, 0xA8, 0x61, 0xD0, 0xD3, 0x56, 0xC9, 0x25, 0xA6, 0x9E, 0xEC, 0xDA, 0xD0, 0xD6, 0xB5, 0xB3, 0xE0, 0x74, 0x5B, 0xA4, 0x9E, 0x1C, 0x0F, 0x3C, 0xAE, 0x75, 0xCE, 0xD0, 0x20, 0xD5, 0x16, 0x46, 0xDB, 0xE1, 0xD3, 0x74, 0x76, 0xE7, 0x09, 0x9B, 0x2F, 0x4F, 0x11, 0x05, 0xDC, 0x01, 0x18, 0xEA, 0x8E, 0xF5, 0xA2, 0xA6, 0x5B, 0x0A, 0x72, 0x71, 0x92, 0x7A, 0x78, 0xB3, 0x38, 0xE2, 0x25, 0x25, 0x74, 0xCD, 0xEB, 0xFC, 0x67, 0x34, 0xB7, 0xEA, 0xF5, 0xDB, 0xFB, 0xAF, 0xAA, 0xC2, 0x5F, 0xD2, 0x63, 0x49, 0x4D, 0x1B, 0xA3, 0x9B, 0x4D, 0xDD, 0x24, 0x8D, 0xC3, 0x0E, 0x6B, 0x84, 0x24, 0x11, 0xF1, 0x19, 0x5F, 0x3D, 0x50, 0x43, 0x19, 0xA2, 0x80, 0xBA, 0x36, 0x13, 0xD1, 0xB7, 0x39, 0x68, 0xEE, 0x5D, 0xFD, 0x04, 0x5F, 0x64, 0xCF, 0x94, 0x2E, 0x8C, 0x38, 0x3F, 0x4D, 0xA5, 0x2D, 0xAD, 0xFE, 0x7F, 0x72, 0xB3, 0xC7, 0xC9, 0x3B, 0x1E, 0xC6, 0xAF, 0xDA, 0x25, 0x05, 0xD7, 0x6A, 0x34, 0x7A, 0x86, 0xD3, 0x49, 0x57, 0x43, 0x67, 0x85, 0xF0, 0x39, 0xD4, 0x4C, 0x2D, 0x61, 0x21, 0x98, 0xDE, 0xC0, 0x69, 0xDD, 0xE2, 0xAF, 0x7F, 0xC3, 0xAD, 0x87, 0x27, 0x16, 0x9B, 0xA6, 0x3E, 0x2E, 0x8F, 0xEA, 0xB5, 0x59, 0xA6, 0x80, 0xF3, 0x86, 0x33, 0xE2, 0xD0, 0xBA, 0x5B, 0x04, 0x54, 0x97, 0x1A, 0x4B, 0x83, 0x63, 0x63, 0x9B, 0x49, 0x23, 0x67, 0x31, 0x6E, 0x8C, 0x49, 0xBA, 0x43, 0xB0, 0x7C, 0x71, 0x85, 0xBE, 0x59, 0x5C, 0xA9, 0xC3, 0xA2, 0xEF, 0x63, 0x15, 0x89, 0x52, 0x7A, 0xA3, 0x67, 0x8D, 0xB1, 0xE9, 0x20, 0x30, 0x34, 0xD4, 0xDF, 0x83, 0x0F, 0xD5, 0x64, 0x76, 0xC5, 0xA5, 0x1B, 0xD6, 0xD3, 0x33, 0x8C, 0xF7, 0xC1, 0x0A, 0xF1, 0x1D, 0xB6, 0x3A, 0x20, 0xFC, 0xB7, 0x44, 0xDB, 0x4F, 0x66, 0x77, 0x87, 0xF9, 0x17, 0x9D, 0xB2, 0x2D, 0xA0, 0x3B, 0x4E, 0xEA, 0x2B, 0x85, 0x6D, 0xE2, 0xD8, 0xDB, 0xDC, 0x73, 0xC0, 0x58, 0xC8, 0x6A, 0x9C, 0x0B, 0x62, 0x3B, 0xE0, 0xE4, 0x64, 0x1E, 0xEC, 0x70, 0xC2, 0xA3, 0x0A, 0x72, 0x9C, 0xB6, 0x52, 0xD4, 0xDF, 0x29, 0x28, 0xAB, 0xB2, 0xD7, 0xFC, 0x32, 0x69, 0x3F, 0xD5, 0xB9, 0xFF, 0x00, 0x06, 0x15, 0xCC, 0x7B, 0x69, 0xD3, 0x30, 0xCA, 0xD7, 0xC1, 0xA7, 0x6A, 0x18, 0xF6, 0xF2, 0x7B, 0x59, 0x13, 0x5C, 0x3F, 0x78, 0x54, 0xBB, 0x3E, 0xAE, 0xAA, 0xD2, 0xD7, 0xFA, 0xFB, 0xC9, 0xA7, 0x6D, 0x7C, 0x55, 0x7B, 0xEC, 0x14, 0x92, 0xC8, 0x43, 0x22, 0xDE, 0x78, 0x70, 0xDD, 0xE7, 0xCB, 0x18, 0xE5, 0xDA, 0xBA, 0x75, 0xDE, 0xD1, 0xC6, 0xAC, 0xB2, 0x9A, 0x1F, 0x47, 0xE9, 0x68, 0x65, 0x32, 0xB6, 0x43, 0x51, 0x13, 0xB2, 0xE2, 0x00, 0x3E, 0xA9, 0xF5, 0x47, 0x0E, 0x3D, 0xFD, 0x81, 0x4D, 0x4A, 0x33, 0xA7, 0x2D, 0x99, 0x2D, 0x48, 0x8C, 0x94, 0x95, 0xD1, 0xD5, 0xA9, 0x6E, 0xF3, 0x6A, 0x5D, 0x4D, 0x55, 0x77, 0xA6, 0x96, 0xA2, 0x1B, 0x6D, 0x51, 0x69, 0x6D, 0x24, 0x8F, 0x27, 0x00, 0x30, 0x34, 0x82, 0x01, 0xC7, 0x30, 0x4A, 0x8E, 0xC6, 0x35, 0x83, 0x0C, 0x68, 0x68, 0xF8, 0x0C, 0x28, 0x96, 0x61, 0x8B, 0x6C, 0x19, 0xEE, 0x3F, 0xF3, 0x2A, 0x62, 0xF4, 0x58, 0x5A, 0x51, 0xA7, 0x4D, 0x6C, 0xAD, 0xE7, 0x3E, 0xB4, 0xDC, 0xA4, 0xEE, 0x11, 0x11, 0x59, 0x35, 0x04, 0x44, 0x40, 0x11, 0x11, 0x00, 0x44, 0x44, 0x01, 0x49, 0xA7, 0xEA, 0x1F, 0x15, 0x19, 0x49, 0xA7, 0xEA, 0x1F, 0x15, 0x0C, 0x75, 0x9D, 0x0F, 0xEB, 0xBB, 0xC5, 0x62, 0xB2, 0x7F, 0x5D, 0xDE, 0x2B, 0x15, 0x20, 0x22, 0x22, 0x00, 0x88, 0x88, 0x02, 0x22, 0x20, 0x08, 0x88, 0x80, 0x22, 0x22, 0x00, 0x88, 0x88, 0x02, 0x22, 0x20, 0x09, 0x84, 0x44, 0x01, 0x11, 0x10, 0x04, 0x44, 0x40, 0x30, 0x13, 0x08, 0x88, 0x02, 0x61, 0x11, 0x00, 0x44, 0x44, 0x01, 0x11, 0x10, 0x04, 0x44, 0x40, 0x11, 0x11, 0x00, 0x44, 0x44, 0x01, 0x49, 0xA7, 0xEA, 0x1F, 0x15, 0x19, 0x49, 0xA7, 0xEA, 0x1F, 0x15, 0x0C, 0x1D, 0x0F, 0xEB, 0xBB, 0xC5, 0x62, 0xB2, 0x7F, 0x5D, 0xDE, 0x2B, 0x15, 0x20, 0x22, 0x22, 0x00, 0x88, 0x88, 0x02, 0x22, 0x20, 0x08, 0x8A, 0xFD, 0xB2, 0x2D, 0x3F, 0xA5, 0xF5, 0x05, 0xC6, 0xE3, 0x16, 0xB0, 0xB8, 0x9A, 0x08, 0x22, 0x89, 0xAE, 0x81, 0xC2, 0xA1, 0xB0, 0xEF, 0x38, 0x92, 0x08, 0xCB, 0x81, 0xCF, 0x0C, 0x2C, 0x2A, 0x4D, 0x53, 0x8E, 0xD3, 0x25, 0x2B, 0xBB, 0x14, 0x14, 0x53, 0xAF, 0xD0, 0x53, 0x52, 0x5F, 0xAE, 0x74, 0xD4, 0x12, 0x74, 0xB4, 0x70, 0xD5, 0x4B, 0x1C, 0x0F, 0xDE, 0x0E, 0xDE, 0x8C, 0x38, 0x86, 0x9C, 0x8E, 0x79, 0x00, 0x71, 0x50, 0x56, 0x51, 0x77, 0x57, 0x20, 0x22, 0x22, 0x90, 0x11, 0x11, 0x00, 0x44, 0x44, 0x01, 0x11, 0x10, 0x04, 0x44, 0x40, 0x11, 0x11, 0x00, 0x44, 0x44, 0x01, 0x11, 0x10, 0x04, 0x44, 0x40, 0x11, 0x11, 0x00, 0x44, 0x44, 0x01, 0x11, 0x10, 0x05, 0x26, 0x9B, 0xA8, 0x7C, 0x54, 0x65, 0x26, 0x9F, 0xA8, 0x7C, 0x54, 0x32, 0x4E, 0x87, 0xF5, 0xDD, 0xE2, 0xB1, 0x59, 0x3F, 0xAE, 0xEF, 0x15, 0x8A, 0x92, 0x02, 0x22, 0x20, 0x08, 0x88, 0x80, 0x2C, 0xE1, 0x8D, 0xF3, 0x4F, 0x1C, 0x31, 0x37, 0x7A, 0x49, 0x1C, 0x18, 0xD1, 0x9C, 0x64, 0x93, 0x80, 0x16, 0x0B, 0x38, 0x25, 0x7C, 0x13, 0xC5, 0x34, 0x44, 0x09, 0x22, 0x78, 0x7B, 0x49, 0x19, 0xC1, 0x07, 0x21, 0x43, 0xBD, 0xB4, 0x07, 0xBB, 0xAA, 0xF4, 0x75, 0xFF, 0x00, 0x49, 0xB6, 0x95, 0xDA, 0x86, 0xDC, 0xEA, 0x21, 0x52, 0x5C, 0x22, 0xDE, 0x91, 0x8E, 0xDE, 0x2D, 0xC6, 0x7A, 0xA4, 0xF7, 0x85, 0x5F, 0x56, 0xAD, 0x6F, 0xAF, 0x6F, 0xDA, 0xDD, 0xB4, 0x4D, 0xD4, 0x13, 0x41, 0x28, 0xA4, 0x2F, 0x31, 0x74, 0x50, 0x88, 0xF1, 0xBD, 0x8C, 0xE7, 0x1C, 0xFA, 0xA1, 0x55, 0x56, 0x14, 0x9C, 0xDC, 0x7F, 0x73, 0x7F, 0x81, 0x94, 0xAD, 0x7E, 0x88, 0x3C, 0x02, 0xB1, 0x56, 0x68, 0x8D, 0x49, 0x45, 0xA6, 0x63, 0xD4, 0x35, 0x56, 0xC7, 0xC7, 0x66, 0x91, 0x8C, 0x7B, 0x6A, 0x7A, 0x46, 0x10, 0x5A, 0xF2, 0x03, 0x4E, 0x03, 0xB3, 0xC4, 0x91, 0xD8, 0xAB, 0x84, 0x64, 0x2B, 0x75, 0x7E, 0xD0, 0xF5, 0x15, 0x76, 0x8D, 0x8B, 0x4B, 0x54, 0xD4, 0x40, 0xEB, 0x44, 0x6C, 0x8E, 0x36, 0xB0, 0x42, 0x03, 0xF7, 0x58, 0x41, 0x6F, 0xAD, 0xCF, 0x98, 0x09, 0x37, 0x34, 0xD6, 0xC7, 0xD4, 0x2B, 0x6B, 0x72, 0xA4, 0x88, 0x8B, 0x61, 0x88, 0x44, 0x44, 0x01, 0x11, 0x10, 0x04, 0x44, 0x40, 0x11, 0x11, 0x00, 0x44, 0x44, 0x01, 0x11, 0x10, 0x04, 0x44, 0x40, 0x11, 0x11, 0x00, 0x44, 0x44, 0x01, 0x11, 0x10, 0x04, 0x44, 0x40, 0x14, 0x9A, 0x7E, 0xA1, 0xF1, 0x51, 0x94, 0x9A, 0x7E, 0xA1, 0xF1, 0x50, 0xF7, 0x12, 0x8E, 0x87, 0xF5, 0xDD, 0xE2, 0xB1, 0x59, 0x3F, 0xAE, 0xEF, 0x15, 0x8A, 0x92, 0x02, 0x22, 0x20, 0x08, 0x88, 0x80, 0x22, 0x22, 0x00, 0xAF, 0x7B, 0x24, 0xB8, 0x68, 0xDA, 0x0B, 0x8D, 0xC5, 0xDA, 0xEE, 0x94, 0x54, 0x53, 0xBA, 0x26, 0x8A, 0x70, 0x62, 0x74, 0x98, 0x76, 0x78, 0xF5, 0x7E, 0x0A, 0x88, 0xB8, 0x23, 0x2B, 0x09, 0xC3, 0x6D, 0x5A, 0xF6, 0x25, 0x3B, 0x3B, 0x93, 0xEF, 0xB2, 0xD2, 0x4D, 0x7C, 0xB9, 0x4B, 0x6C, 0x66, 0xE5, 0x03, 0xEA, 0x64, 0x75, 0x3B, 0x71, 0x8D, 0xD8, 0xCB, 0x8E, 0xE8, 0xC7, 0x67, 0x0C, 0x28, 0x28, 0x8B, 0x25, 0xA1, 0x01, 0x11, 0x14, 0x80, 0x88, 0x88, 0x02, 0x22, 0x20, 0x08, 0x88, 0x80, 0x22, 0x22, 0x00, 0x88, 0x88, 0x02, 0x22, 0x20, 0x08, 0x88, 0x80, 0x22, 0x22, 0x00, 0x88, 0x88, 0x02, 0x22, 0x20, 0x08, 0x88, 0x80, 0x29, 0x34, 0xFD, 0x43, 0xE2, 0xA3, 0x29, 0x34, 0xFD, 0x43, 0xE2, 0xA1, 0xEE, 0x24, 0xE8, 0x7F, 0x5D, 0xDE, 0x2B, 0x15, 0x93, 0xFA, 0xEE, 0xF1, 0x58, 0xA9, 0x20, 0x22, 0x22, 0x00, 0x88, 0x88, 0x02, 0x22, 0x20, 0x08, 0x88, 0x80, 0x22, 0x22, 0x00, 0x88, 0x88, 0x02, 0x22, 0x20, 0x08, 0x88, 0x80, 0x22, 0x22, 0x00, 0x88, 0x88, 0x02, 0x22, 0x20, 0x08, 0x88, 0x80, 0x22, 0x22, 0x00, 0x88, 0x88, 0x02, 0x13, 0x80, 0x8A, 0xE7, 0xB2, 0xED, 0x05, 0x51, 0xB4, 0x0B, 0xBD, 0x65, 0x05, 0x35, 0x74, 0x54, 0x46, 0x9A, 0x0E, 0x9C, 0xBE, 0x46, 0x17, 0xEF, 0x7A, 0xC0, 0x63, 0x00, 0xFC, 0x56, 0x33, 0x9A, 0x84, 0x5C, 0xA5, 0xB8, 0xCA, 0x2B, 0x69, 0xD8, 0x8B, 0x7A, 0xD0, 0x57, 0xAB, 0x46, 0x8C, 0xB7, 0xEA, 0x6A, 0xCF, 0x26, 0xF3, 0x65, 0x71, 0x60, 0x87, 0x72, 0x42, 0x5F, 0xEB, 0xB4, 0xB8, 0x64, 0x63, 0x87, 0x06, 0x95, 0x6A, 0xA9, 0xD5, 0xDA, 0x29, 0xFB, 0x1E, 0x16, 0x28, 0xAD, 0x40, 0x6A, 0x7E, 0x81, 0x8D, 0xF2, 0xB1, 0x42, 0xC0, 0x77, 0xC4, 0x81, 0xC4, 0xF4, 0xBC, 0xFA, 0xB9, 0x19, 0x54, 0x7D, 0x59, 0x05, 0xC6, 0xCB, 0x78, 0xAE, 0xD3, 0x95, 0x77, 0x39, 0xEA, 0xE0, 0xB7, 0x4E, 0xE8, 0x43, 0x4C, 0x8E, 0xE8, 0xF2, 0xDE, 0x00, 0x86, 0x93, 0x80, 0xBC, 0x32, 0xB5, 0x71, 0x7C, 0x62, 0x4E, 0x6E, 0xFA, 0xDD, 0x58, 0xCB, 0x6B, 0x67, 0x71, 0x6A, 0xB6, 0x68, 0x5B, 0xCD, 0xC7, 0x44, 0xD6, 0xEA, 0xA8, 0x05, 0x37, 0x9A, 0xA9, 0x1C, 0xE6, 0xC8, 0x5D, 0x26, 0x1F, 0x91, 0x8C, 0xE1, 0xB8, 0xFF, 0x00, 0x88, 0x2A, 0xB0, 0x5E, 0xF6, 0x8E, 0xA2, 0xB9, 0x6A, 0x1B, 0xCD, 0x16, 0x9A, 0xA4, 0xB9, 0xCD, 0x4B, 0x4F, 0x5F, 0x2E, 0xE1, 0x61, 0x7B, 0x8C, 0x59, 0xC6, 0x72, 0x58, 0x0E, 0x0F, 0x25, 0x37, 0x69, 0x7A, 0x2A, 0x7D, 0x07, 0x7E, 0x86, 0xD7, 0x55, 0x59, 0x1D, 0x5B, 0xE4, 0xA7, 0x6D, 0x47, 0x49, 0x1B, 0x0B, 0x40, 0x05, 0xCE, 0x18, 0xC1, 0xFF, 0x00, 0xDB, 0xF9, 0xAC, 0x94, 0xED, 0x3D, 0x89, 0x3D, 0x7A, 0xBC, 0x88, 0x6B, 0x4B, 0xA2, 0xA8, 0xA4, 0xD3, 0xF5, 0x0F, 0x8A, 0x8C, 0xA4, 0xD3, 0xF5, 0x0F, 0x8A, 0xD8, 0xCC, 0x0F, 0xFF, 0xD9 };
the_stack_data/57949951.c
#include<stdio.h> #include<ctype.h> #include<string.h> int search(char *str,char *p,int lens,int lenp){ int i=0,j=0; while(i<lens&&j<lenp){ j=0; while(*(str+i++)==*(p+j++)); } if(i<lens) return (i-j); else return -1; } void delete(char *s,char *p,int lens,int lenp){ int pos=search(s,p,lens,lenp); int k=0; while((pos+k)<=(lens)){ *(s+pos+k)=*(s+pos+lenp+k); k++; } *(s+pos+k)='\0'; } void strconcat(char *s1,char *s2){ int i=0,j=0; while(*(s1+i)!='\0') i++; while(*(s2+j)!='\0') *(s1+i++)=*(s2+j++); }void main(){ int choice,i=0,pos=-1,lens,lenp; char s1[30],s2[30],s[45]; printf("Enter your choice (1-3)\n\t\t1.Concatenation of two strings\n\t\t2.Search for pattern in a string\n\t\t3.Deletion of pattern from a string\n"); scanf("%d",&choice); do{ printf("Enter sentence/string 1 :"); scanf("%s",&s1); printf("Enter pattern/String 2 :"); scanf("%s",&s2); lens=strlen(s1); lenp=strlen(s2); switch(choice){ case 1: strconcat(s1,s2); printf("Resultant string is %s",s1); break; case 2: pos=search(s1,s2,lens,lenp); if(pos!=-1) printf("pattern found at location %d ",pos); else printf("Pattern not located\n"); break; case 3: delete(s1,s2,lens,lenp); printf("Resultant string is %s",s1); break; default:printf("Invalid Choice"); } i++; }while(i=0); }
the_stack_data/231392054.c
#include<stdio.h> int main() { int N,i; scanf("%d",&N); if(N>2 && N<1000) { for(i=1;i<11;i++) printf("%d x %d = %d\n",i,N,i*N); } return 0; }
the_stack_data/48574097.c
#include <stdio.h> #include <stdlib.h> int ImprimeNum(int num) { int n = (num == 1) ? 1 : ImprimeNum(num - 1); printf("%d -> ", num); return n; } int main() { int num; ImprimeNum(10); printf("FIM!"); return 0; }
the_stack_data/90764394.c
#include <stdio.h> int pro(int p) { int s=1; while (p!=1) { if (p%2==0) p=p>>1; else p=3*p+1; s++; } return s; } int main() { int a,b,i,j,k; while (scanf("%d%d",&a,&b)!=EOF) { printf("%d %d ",a,b); if (a>b) { i=b; b=a; a=i; } for (i=a,j=1;i<=b;i++) { k=pro(i); if (k>j) j=k; } printf("%d\n",j); } return 0; }
the_stack_data/4932.c
#include <math.h> #include <stdio.h> #define WIDTH 800 #define HEIGHT 600 #define FPS 30 #define DURATION 2 #define FRAMES_COUNT (FPS * DURATION) #define PIXELS_SIZE (WIDTH * HEIGHT) typedef struct { int y, cb, cr; } YCbCr; typedef struct { int rx, ry, rw, rh; } Rect; Rect vrect(int rx, int ry, int rw, int rh) { return (Rect){ .rx = rx, .ry = ry, .rw = rw, .rh = rh, }; } YCbCr rgb_conveter(int r, int g, int b) { return (YCbCr){ .y = 16 + (65.738 * r + 129.057 * g + 25.064 * b) / 256, .cb = 128 + (-37.945 * r - 74.494 * g + 112.439 * b) / 256, .cr = 128 + (112.439 * r - 94.154 * g - 18.285 * b) / 256, }; } void fill_rect_rgb(char canvas[], Rect rect, int color) { for (int dy = 0; dy < rect.rh; dy++) { for (int dx = 0; dx < rect.rw; dx++) { int x = rect.rx + dx; int y = rect.ry + dy; if (WIDTH <= x && HEIGHT <= y) { canvas[y * WIDTH + x] = color; } } } } int main(void) { char canvas[WIDTH * HEIGHT]; int color = 255; FILE *file = fopen("output.y4m", "w"); fprintf(file, "YUV4MPEG2 W%d H%d F%d:1 Ip A1:1 C444\n", WIDTH, HEIGHT, FRAMES_COUNT); fill_rect_rgb(canvas, vrect(0, 0, 0, 0), color); YCbCr ycbcr = rgb_conveter(255, 0, 0); for (int frame = 0; frame < FRAMES_COUNT; frame++) { fprintf(file, "FRAME\n"); for (int j = 0; j < PIXELS_SIZE; j++) { char pixels[] = {ycbcr.y}; fwrite(pixels, 1, 1, file); } for (int j = 0; j < PIXELS_SIZE; j++) { char pixels[] = {ycbcr.cb}; fwrite(pixels, 1, 1, file); } for (int j = 0; j < PIXELS_SIZE; j++) { char pixels[] = {ycbcr.cr}; fwrite(pixels, 1, 1, file); } float progess = round((float)frame / FRAMES_COUNT * 100); printf("%f%%\r", progess); fflush(stdout); } fclose(file); fprintf(stdout, "Generated output.y4m\n"); }
the_stack_data/6386462.c
#include <stdio.h> #include <stdlib.h> #include <string.h> int dp[1000][1000]; int min(int a, int b, int c) { int m = a; if(m > b) m = b; if(m > c) m = c; return m; } int main(void) { int l1,l2; char *s1 = (char*)malloc(sizeof(char) * 1000); char *s2 = (char*)malloc(sizeof(char) * 1000); scanf("%s", s1); scanf("%s", s2); l1 = strlen(s1); l2 = strlen(s2); //printf("%d\n", l1); //printf("%d\n", l2); if(l2 == 0){ printf("%d", l1); return -1; } if(l1 == 0){ printf("%d", l2); } // 初始化dp路径规划图 for(int i = 0; i < l1; i++){ for(int j = 0; j < l2; j++){ dp[i][j] = 0; } } // 迭代求解动态规划问题 for(int i = 1; i <= l1; i++){ for(int j = 1; j <= l2; j++){ if(s1[i-1] == s2[j-1]){ dp[i][j] = dp[i-1][j-1]; //printf("%d\n", dp[i][j]); } else{ dp[i][j] = 1 + min(dp[i-1][j-1], dp[i][j-1], dp[i-1][j]); //printf("%d\n", dp[i][j]); } } } printf("%d", dp[l1][l2]); return 0; }
the_stack_data/72013866.c
#include <stdio.h> int main(void) { float value_of_trade, trade_commission; printf("Enter value of trade:"); scanf("%f", &value_of_trade); if (value_of_trade < 2500) { trade_commission = 30 + value_of_trade * 1.7f/100; } else if (value_of_trade < 6250){ trade_commission = 56 + value_of_trade * 0.66f/100; } else if (value_of_trade < 20000){ trade_commission = 76 + value_of_trade * 0.34f/100; } else if (value_of_trade < 50000){ trade_commission = 100 + value_of_trade * 0.22f/100; } else if (value_of_trade < 500000){ trade_commission = 155 + value_of_trade * 0.11f/100; } else { trade_commission = 255 + value_of_trade * 0.09f/100; } printf("Commission: $%.2f \n", trade_commission); }
the_stack_data/13531.c
/****************************** * Filename: MemoryLeaker.c * Author: Blakely North * Date Last Edited: 1-22-2019 * Brief Description: A sample and standard new file gcc -Wall -Wextra -O -ansi -pedantic -o MemoryLeaker MemoryLeaker.c ******************************/ /*printf, scanf*/ #include <stdio.h> /*malloc*/ #include <stdlib.h> int power(int base, int exp) { int i; for (i = 0; i < exp; ++i) base *= base; return base; } int main(void) { int input; int *h; char unit; puts("This program was created as a joke, hasn't been tested, and it can be used to do bad things, so I must issuea a disclaimer:"); puts("WARNING:\nTHIS PROGRAM LEAKS MEMORY!\nTHIS MEANS THAT IT BASICLALLY EATS IT UNTILL YOU RESTART YOUR COMPUTER\n\nPLEASE ONLY RUN THIS IF YOU KNOW EXACTLY WHAT A MEMORY LEAK IS!!!\n\nPress Ctrl+C or close this window if you don't know what a memory leak is"); ; puts("\nOkay, enough intro"); puts("Enter how much memory then the units (b, k, m, or g) that you want to leak like so:\n53, b"); scanf("%i, %c", input, unit); while (getchar() != '\n') ; switch (unit) { case 'b': input *= power(10, 0); break; case 'k': input *= power(10, 3); break; case 'm': input *= power(10, 6); break; case 'g': input *= power(10, 9); break; printf("Are you SURE you want to leak %i bytes of memory\n", input); if (getchar() != 'y') return -1; h = malloc(input); if (!h) { printf("Failed to get %i bytes of memory\n", input); while (getchar() != '\n') ; return -2; } printf("%i bytes of memory have been successfully claimed\n", input); printf("Are you 1000% sure you want to have %i bytes of memory to be GONE from your machine until you restart?\n(y/n):", input); if (getchar() == 'y') return 1; else { free(h); putchar('\n'); puts("Operation canceled\nPress enter to exit"); while (getchar() != '\n') ; return 0; } return -3; } }
the_stack_data/34277.c
#include <stdio.h> main() { printf("Hello, "); printf("World!"); printf("\n"); }
the_stack_data/114096.c
/* ************************************************************************** */ /* */ /* :::::::: */ /* ft_str_is_numeric.c :+: :+: */ /* +:+ */ /* By: areintha <[email protected]> +#+ */ /* +#+ */ /* Created: 2021/06/17 13:50:29 by areintha #+# #+# */ /* Updated: 2021/06/17 17:13:25 by areintha ######## odam.nl */ /* */ /* ************************************************************************** */ int ft_str_is_numeric(char *str); int ft_str_is_numeric(char *str) { int r ; if (str[0] == '\0') r = 1 ; else { while (*str) { if (*str >= '0' && *str <= '9') r = 1; else r = 0; str++ ; } } return (r); }
the_stack_data/156393829.c
// ============================================================== // File generated on Tue Jun 02 21:19:44 EEST 2020 // Vivado(TM) HLS - High-Level Synthesis from C, C++ and SystemC v2018.3 (64-bit) // SW Build 2405991 on Thu Dec 6 23:36:41 MST 2018 // IP Build 2404404 on Fri Dec 7 01:43:56 MST 2018 // Copyright 1986-2018 Xilinx, Inc. All Rights Reserved. // ============================================================== #ifndef __linux__ #include "xstatus.h" #include "xparameters.h" #include "xactivatenetwork.h" extern XActivatenetwork_Config XActivatenetwork_ConfigTable[]; XActivatenetwork_Config *XActivatenetwork_LookupConfig(u16 DeviceId) { XActivatenetwork_Config *ConfigPtr = NULL; int Index; for (Index = 0; Index < XPAR_XACTIVATENETWORK_NUM_INSTANCES; Index++) { if (XActivatenetwork_ConfigTable[Index].DeviceId == DeviceId) { ConfigPtr = &XActivatenetwork_ConfigTable[Index]; break; } } return ConfigPtr; } int XActivatenetwork_Initialize(XActivatenetwork *InstancePtr, u16 DeviceId) { XActivatenetwork_Config *ConfigPtr; Xil_AssertNonvoid(InstancePtr != NULL); ConfigPtr = XActivatenetwork_LookupConfig(DeviceId); if (ConfigPtr == NULL) { InstancePtr->IsReady = 0; return (XST_DEVICE_NOT_FOUND); } return XActivatenetwork_CfgInitialize(InstancePtr, ConfigPtr); } #endif
the_stack_data/59513000.c
/* Função: Ler o preço de um par de sapatos e escrever com o desconto que for informado pelo usuario Autor: Gabriel Maciel dos Santos Data: 11/03/18 */ #include <stdio.h> int main(){ float preco, desconto; printf("Informe o valor do par de sapatos:\n"); scanf("%f", &preco); printf("Informe o valor do desconto:\n"); scanf("%f", &desconto); preco = (preco - ((preco * desconto) / 100)); printf("O valor com desconto: R$%.2f", preco); return 0; }
the_stack_data/53823.c
// RUN: %clang -target aarch64 -mcpu=tsv110 -### -c %s 2>&1 | FileCheck -check-prefix=TSV110 %s // RUN: %clang -target aarch64 -mlittle-endian -mcpu=tsv110 -### -c %s 2>&1 | FileCheck -check-prefix=TSV110 %s // RUN: %clang -target aarch64 -mtune=tsv110 -### -c %s 2>&1 | FileCheck -check-prefix=TSV110-TUNE %s // RUN: %clang -target aarch64 -mlittle-endian -mtune=tsv110 -### -c %s 2>&1 | FileCheck -check-prefix=TSV110-TUNE %s // TSV110: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "tsv110" // TSV110-TUNE: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" // RUN: %clang -target arm64 -mcpu=tsv110 -### -c %s 2>&1 | FileCheck -check-prefix=ARM64-TSV110 %s // RUN: %clang -target arm64 -mlittle-endian -mcpu=tsv110 -### -c %s 2>&1 | FileCheck -check-prefix=ARM64-TSV110 %s // RUN: %clang -target arm64 -mtune=tsv110 -### -c %s 2>&1 | FileCheck -check-prefix=ARM64-TSV110-TUNE %s // RUN: %clang -target arm64 -mlittle-endian -mtune=tsv110 -### -c %s 2>&1 | FileCheck -check-prefix=ARM64-TSV110-TUNE %s // ARM64-TSV110: "-cc1"{{.*}} "-triple" "arm64{{.*}}" "-target-cpu" "tsv110" // ARM64-TSV110-TUNE: "-cc1"{{.*}} "-triple" "arm64{{.*}}" "-target-cpu" "generic"
the_stack_data/132458.c
#include <stdio.h> #include <stdlib.h> #include <linux/types.h> // My system has 6 configurable counters and a separate Cycle Count register. // This will contain a nice human-readable name for the configured counters. const char* cpu_name[7] = { "", "", "", "", "", "", "CCNT" }; typedef struct { __u32 reg[7]; // 6 configurables and the cycle count } cpu_perf; void print_counters(cpu_perf data) { printf("Counters overview:\n"); for (int i=0; i<7; i++) { if (cpu_name[i] != "") { printf(" %s: %d\n", cpu_name[i], data.reg[i]); } } } __u32 _read_cpu_counter(int r) { // Read PMXEVCNTR #r // This is done by first writing the counter number to PMSELR and then reading PMXEVCNTR __u32 ret; asm volatile ("MCR p15, 0, %0, c9, c12, 5\t\n" :: "r"(r)); // (write) Select event counter in PMSELR asm volatile ("MRC p15, 0, %0, c9, c13, 2\t\n" : "=r"(ret)); // (read) Read from PMXEVCNTR return ret; } void _setup_cpu_counter(__u32 r, __u32 event, const char* name) { cpu_name[r] = name; // Write PMXEVTYPER #r // This is done by first writing the counter number to PMSELR and then writing PMXEVTYPER // c9 0 c12 5 -> PMSELR: Performance Monitors Event Counter Selection // Last 5 bits selects a performance counter (also called event counter) // This selection is next used by PMXEVTYPER or PMXEVCNTR asm volatile ("MCR p15, 0, %0, c9, c12, 5\t\n" :: "r"(r)); // (write) Select event counter in PMSELR // c9 0 c13 1 -> PMXEVTYPER: Performance Monitors Event Type Select // Selects which event increments the event counter specified in PMSELR // Last 8 bits select the event // From 0x00 -> 0x3F : Common events // 0x40 -> 0xFF : implementation defined events asm volatile ("MCR p15, 0, %0, c9, c13, 1\t\n" :: "r"(event)); // (write) Set the event number in PMXEVTYPER } void init_cpu_perf() { // Disable all counters for configuration (PCMCNTENCLR) // c9 0 c12 2 -> PMCNTENCLR: Performance Monitors Count Enable Clear // 0b10000000000000000000000000111111 // | |||||| // | write 1 disables those 6 performance counters // write 1 here disables cycle counter asm volatile ("MCR p15, 0, %0, c9, c12, 2\t\n" :: "r"(0x8000003f)); // disable counter overflow interrupts // asm volatile ("MCR p15, 0, %0, c9, c14, 2\n\t" :: "r"(0x8000003f)); // Select which events to count in the 6 configurable counters // Note that both of these examples come from the list of required events. _setup_cpu_counter(0, 0x04, "L1DACC"); _setup_cpu_counter(1, 0x03, "L1DFILL"); _setup_cpu_counter(2, 0x06, "ARMV7_PERFCTR_MEM_READ"); _setup_cpu_counter(3, 0x19, "ARMV7_PERFCTR_BUS_ACCESS"); _setup_cpu_counter(4, 0x00, "ARMV7_PERFCTR_PMNC_SW_INCR"); _setup_cpu_counter(5, 0x07, "ARMV7_PERFCTR_MEM_WRITE"); } void reset_cpu_perf() { // Disable all counters (PMCNTENCLR): asm volatile ("MCR p15, 0, %0, c9, c12, 2\t\n" :: "r"(0x8000003f)); __u32 pmcr = 0x1 // enable counters | 0x2 // reset all other counters | 0x4 // reset cycle counter | 0x8 // enable "by 64" divider for CCNT. | 0x10; // Export events to external monitoring // program the performance-counter control-register (PMCR): asm volatile ("MCR p15, 0, %0, c9, c12, 0\t\n" :: "r"(pmcr)); // clear overflows (PMOVSR): asm volatile ("MCR p15, 0, %0, c9, c12, 3\t\n" :: "r"(0x8000003f)); // Enable all counters (PMCNTENSET): asm volatile ("MCR p15, 0, %0, c9, c12, 1\t\n" :: "r"(0x8000003f)); } cpu_perf get_cpu_perf() { cpu_perf ret; int r; // Read the configurable counters for (r=0; r<6; ++r) { ret.reg[r] = _read_cpu_counter(r); } // Read CPU cycle count from the CCNT Register asm volatile ("MRC p15, 0, %0, c9, c13, 0\t\n": "=r"(ret.reg[6])); return ret; } int main() { init_cpu_perf(); // Here's what a test looks like: reset_cpu_perf(); /* * ... Perform your operations */ cpu_perf results_1 = get_cpu_perf(); print_counters(results_1); int data[1500000] = {0}; for (int i=0; i<1500000; i++) { data[i] += rand(); } cpu_perf results_2 = get_cpu_perf(); print_counters(results_2); }
the_stack_data/87636604.c
#include <stdio.h> #include <stdlib.h> int main() { float resultado, numero; printf("Digite um numero: "); scanf("%d", &numero); if ( numero >= 20) { resultado = numero / 2; printf("\nA metade do numero %f eh: %f", numero, resultado); } else { printf("\nO numero %d eh menor que 20", numero); } return 0; }
the_stack_data/1204626.c
/* ** 2011 March 16 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ****************************************************************************** ** ** This file contains code implements a VFS shim that writes diagnostic ** output for each VFS call, similar to "strace". ** ** USAGE: ** ** This source file exports a single symbol which is the name of a ** function: ** ** int vfstrace_register( ** const char *zTraceName, // Name of the newly constructed VFS ** const char *zOldVfsName, // Name of the underlying VFS ** int (*xOut)(const char*,void*), // Output routine. ex: fputs ** void *pOutArg, // 2nd argument to xOut. ex: stderr ** int makeDefault // Make the new VFS the default ** ); ** ** Applications that want to trace their VFS usage must provide a callback ** function with this prototype: ** ** int traceOutput(const char *zMessage, void *pAppData); ** ** This function will "output" the trace messages, where "output" can ** mean different things to different applications. The traceOutput function ** for the command-line shell (see shell.c) is "fputs" from the standard ** library, which means that all trace output is written on the stream ** specified by the second argument. In the case of the command-line shell ** the second argument is stderr. Other applications might choose to output ** trace information to a file, over a socket, or write it into a buffer. ** ** The vfstrace_register() function creates a new "shim" VFS named by ** the zTraceName parameter. A "shim" VFS is an SQLite backend that does ** not really perform the duties of a true backend, but simply filters or ** interprets VFS calls before passing them off to another VFS which does ** the actual work. In this case the other VFS - the one that does the ** real work - is identified by the second parameter, zOldVfsName. If ** the 2nd parameter is NULL then the default VFS is used. The common ** case is for the 2nd parameter to be NULL. ** ** The third and fourth parameters are the pointer to the output function ** and the second argument to the output function. For the SQLite ** command-line shell, when the -vfstrace option is used, these parameters ** are fputs and stderr, respectively. ** ** The fifth argument is true (non-zero) to cause the newly created VFS ** to become the default VFS. The common case is for the fifth parameter ** to be true. ** ** The call to vfstrace_register() simply creates the shim VFS that does ** tracing. The application must also arrange to use the new VFS for ** all database connections that are created and for which tracing is ** desired. This can be done by specifying the trace VFS using URI filename ** notation, or by specifying the trace VFS as the 4th parameter to ** sqlite3_open_v2() or by making the trace VFS be the default (by setting ** the 5th parameter of vfstrace_register() to 1). ** ** ** ENABLING VFSTRACE IN A COMMAND-LINE SHELL ** ** The SQLite command line shell implemented by the shell.c source file ** can be used with this module. To compile in -vfstrace support, first ** gather this file (test_vfstrace.c), the shell source file (shell.c), ** and the SQLite amalgamation source files (sqlite3.c, sqlite3.h) into ** the working directory. Then compile using a command like the following: ** ** gcc -o sqlite3 -Os -I. -DSQLITE_ENABLE_VFSTRACE \ ** -DSQLITE_THREADSAFE=0 -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_RTREE \ ** -DHAVE_READLINE -DHAVE_USLEEP=1 \ ** shell.c test_vfstrace.c sqlite3.c -ldl -lreadline -lncurses ** ** The gcc command above works on Linux and provides (in addition to the ** -vfstrace option) support for FTS3 and FTS4, RTREE, and command-line ** editing using the readline library. The command-line shell does not ** use threads so we added -DSQLITE_THREADSAFE=0 just to make the code ** run a little faster. For compiling on a Mac, you'll probably need ** to omit the -DHAVE_READLINE, the -lreadline, and the -lncurses options. ** The compilation could be simplified to just this: ** ** gcc -DSQLITE_ENABLE_VFSTRACE \ ** shell.c test_vfstrace.c sqlite3.c -ldl -lpthread ** ** In this second example, all unnecessary options have been removed ** Note that since the code is now threadsafe, we had to add the -lpthread ** option to pull in the pthreads library. ** ** To cross-compile for windows using MinGW, a command like this might ** work: ** ** /opt/mingw/bin/i386-mingw32msvc-gcc -o sqlite3.exe -Os -I \ ** -DSQLITE_THREADSAFE=0 -DSQLITE_ENABLE_VFSTRACE \ ** shell.c test_vfstrace.c sqlite3.c ** ** Similar compiler commands will work on different systems. The key ** invariants are (1) you must have -DSQLITE_ENABLE_VFSTRACE so that ** the shell.c source file will know to include the -vfstrace command-line ** option and (2) you must compile and link the three source files ** shell,c, test_vfstrace.c, and sqlite3.c. */ #include <stdlib.h> #include <string.h> #include "sqlite3.h" /* ** An instance of this structure is attached to the each trace VFS to ** provide auxiliary information. */ typedef struct vfstrace_info vfstrace_info; struct vfstrace_info { sqlite3_vfs *pRootVfs; /* The underlying real VFS */ int (*xOut)(const char*, void*); /* Send output here */ void *pOutArg; /* First argument to xOut */ const char *zVfsName; /* Name of this trace-VFS */ sqlite3_vfs *pTraceVfs; /* Pointer back to the trace VFS */ }; /* ** The sqlite3_file object for the trace VFS */ typedef struct vfstrace_file vfstrace_file; struct vfstrace_file { sqlite3_file base; /* Base class. Must be first */ vfstrace_info *pInfo; /* The trace-VFS to which this file belongs */ const char *zFName; /* Base name of the file */ sqlite3_file *pReal; /* The real underlying file */ }; /* ** Method declarations for vfstrace_file. */ static int vfstraceClose(sqlite3_file*); static int vfstraceRead(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst); static int vfstraceWrite(sqlite3_file*,const void*,int iAmt, sqlite3_int64); static int vfstraceTruncate(sqlite3_file*, sqlite3_int64 size); static int vfstraceSync(sqlite3_file*, int flags); static int vfstraceFileSize(sqlite3_file*, sqlite3_int64 *pSize); static int vfstraceLock(sqlite3_file*, int); static int vfstraceUnlock(sqlite3_file*, int); static int vfstraceCheckReservedLock(sqlite3_file*, int *); static int vfstraceFileControl(sqlite3_file*, int op, void *pArg); static int vfstraceSectorSize(sqlite3_file*); static int vfstraceDeviceCharacteristics(sqlite3_file*); static int vfstraceShmLock(sqlite3_file*,int,int,int); static int vfstraceShmMap(sqlite3_file*,int,int,int, void volatile **); static void vfstraceShmBarrier(sqlite3_file*); static int vfstraceShmUnmap(sqlite3_file*,int); /* ** Method declarations for vfstrace_vfs. */ static int vfstraceOpen(sqlite3_vfs*, const char *, sqlite3_file*, int , int *); static int vfstraceDelete(sqlite3_vfs*, const char *zName, int syncDir); static int vfstraceAccess(sqlite3_vfs*, const char *zName, int flags, int *); static int vfstraceFullPathname(sqlite3_vfs*, const char *zName, int, char *); static void *vfstraceDlOpen(sqlite3_vfs*, const char *zFilename); static void vfstraceDlError(sqlite3_vfs*, int nByte, char *zErrMsg); static void (*vfstraceDlSym(sqlite3_vfs*,void*, const char *zSymbol))(void); static void vfstraceDlClose(sqlite3_vfs*, void*); static int vfstraceRandomness(sqlite3_vfs*, int nByte, char *zOut); static int vfstraceSleep(sqlite3_vfs*, int microseconds); static int vfstraceCurrentTime(sqlite3_vfs*, double*); static int vfstraceGetLastError(sqlite3_vfs*, int, char*); static int vfstraceCurrentTimeInt64(sqlite3_vfs*, sqlite3_int64*); static int vfstraceSetSystemCall(sqlite3_vfs*,const char*, sqlite3_syscall_ptr); static sqlite3_syscall_ptr vfstraceGetSystemCall(sqlite3_vfs*, const char *); static const char *vfstraceNextSystemCall(sqlite3_vfs*, const char *zName); /* ** Return a pointer to the tail of the pathname. Examples: ** ** /home/drh/xyzzy.txt -> xyzzy.txt ** xyzzy.txt -> xyzzy.txt */ static const char *fileTail(const char *z){ int i; if( z==0 ) return 0; i = strlen(z)-1; while( i>0 && z[i-1]!='/' ){ i--; } return &z[i]; } /* ** Send trace output defined by zFormat and subsequent arguments. */ static void vfstrace_printf( vfstrace_info *pInfo, const char *zFormat, ... ){ va_list ap; char *zMsg; va_start(ap, zFormat); zMsg = sqlite3_vmprintf(zFormat, ap); va_end(ap); pInfo->xOut(zMsg, pInfo->pOutArg); sqlite3_free(zMsg); } /* ** Convert value rc into a string and print it using zFormat. zFormat ** should have exactly one %s */ static void vfstrace_print_errcode( vfstrace_info *pInfo, const char *zFormat, int rc ){ char zBuf[50]; char *zVal; switch( rc ){ case SQLITE_OK: zVal = "SQLITE_OK"; break; case SQLITE_ERROR: zVal = "SQLITE_ERROR"; break; case SQLITE_PERM: zVal = "SQLITE_PERM"; break; case SQLITE_ABORT: zVal = "SQLITE_ABORT"; break; case SQLITE_BUSY: zVal = "SQLITE_BUSY"; break; case SQLITE_NOMEM: zVal = "SQLITE_NOMEM"; break; case SQLITE_READONLY: zVal = "SQLITE_READONLY"; break; case SQLITE_INTERRUPT: zVal = "SQLITE_INTERRUPT"; break; case SQLITE_IOERR: zVal = "SQLITE_IOERR"; break; case SQLITE_CORRUPT: zVal = "SQLITE_CORRUPT"; break; case SQLITE_FULL: zVal = "SQLITE_FULL"; break; case SQLITE_CANTOPEN: zVal = "SQLITE_CANTOPEN"; break; case SQLITE_PROTOCOL: zVal = "SQLITE_PROTOCOL"; break; case SQLITE_EMPTY: zVal = "SQLITE_EMPTY"; break; case SQLITE_SCHEMA: zVal = "SQLITE_SCHEMA"; break; case SQLITE_CONSTRAINT: zVal = "SQLITE_CONSTRAINT"; break; case SQLITE_MISMATCH: zVal = "SQLITE_MISMATCH"; break; case SQLITE_MISUSE: zVal = "SQLITE_MISUSE"; break; case SQLITE_NOLFS: zVal = "SQLITE_NOLFS"; break; case SQLITE_IOERR_READ: zVal = "SQLITE_IOERR_READ"; break; case SQLITE_IOERR_SHORT_READ: zVal = "SQLITE_IOERR_SHORT_READ"; break; case SQLITE_IOERR_WRITE: zVal = "SQLITE_IOERR_WRITE"; break; case SQLITE_IOERR_FSYNC: zVal = "SQLITE_IOERR_FSYNC"; break; case SQLITE_IOERR_DIR_FSYNC: zVal = "SQLITE_IOERR_DIR_FSYNC"; break; case SQLITE_IOERR_TRUNCATE: zVal = "SQLITE_IOERR_TRUNCATE"; break; case SQLITE_IOERR_FSTAT: zVal = "SQLITE_IOERR_FSTAT"; break; case SQLITE_IOERR_UNLOCK: zVal = "SQLITE_IOERR_UNLOCK"; break; case SQLITE_IOERR_RDLOCK: zVal = "SQLITE_IOERR_RDLOCK"; break; case SQLITE_IOERR_DELETE: zVal = "SQLITE_IOERR_DELETE"; break; case SQLITE_IOERR_BLOCKED: zVal = "SQLITE_IOERR_BLOCKED"; break; case SQLITE_IOERR_NOMEM: zVal = "SQLITE_IOERR_NOMEM"; break; case SQLITE_IOERR_ACCESS: zVal = "SQLITE_IOERR_ACCESS"; break; case SQLITE_IOERR_CHECKRESERVEDLOCK: zVal = "SQLITE_IOERR_CHECKRESERVEDLOCK"; break; case SQLITE_IOERR_LOCK: zVal = "SQLITE_IOERR_LOCK"; break; case SQLITE_IOERR_CLOSE: zVal = "SQLITE_IOERR_CLOSE"; break; case SQLITE_IOERR_DIR_CLOSE: zVal = "SQLITE_IOERR_DIR_CLOSE"; break; case SQLITE_IOERR_SHMOPEN: zVal = "SQLITE_IOERR_SHMOPEN"; break; case SQLITE_IOERR_SHMSIZE: zVal = "SQLITE_IOERR_SHMSIZE"; break; case SQLITE_IOERR_SHMLOCK: zVal = "SQLITE_IOERR_SHMLOCK"; break; case SQLITE_IOERR_SHMMAP: zVal = "SQLITE_IOERR_SHMMAP"; break; case SQLITE_IOERR_SEEK: zVal = "SQLITE_IOERR_SEEK"; break; case SQLITE_IOERR_GETTEMPPATH: zVal = "SQLITE_IOERR_GETTEMPPATH"; break; case SQLITE_IOERR_CONVPATH: zVal = "SQLITE_IOERR_CONVPATH"; break; case SQLITE_READONLY_DBMOVED: zVal = "SQLITE_READONLY_DBMOVED"; break; case SQLITE_LOCKED_SHAREDCACHE: zVal = "SQLITE_LOCKED_SHAREDCACHE"; break; case SQLITE_BUSY_RECOVERY: zVal = "SQLITE_BUSY_RECOVERY"; break; case SQLITE_CANTOPEN_NOTEMPDIR: zVal = "SQLITE_CANTOPEN_NOTEMPDIR"; break; default: { sqlite3_snprintf(sizeof(zBuf), zBuf, "%d", rc); zVal = zBuf; break; } } vfstrace_printf(pInfo, zFormat, zVal); } /* ** Append to a buffer. */ static void strappend(char *z, int *pI, const char *zAppend){ int i = *pI; while( zAppend[0] ){ z[i++] = *(zAppend++); } z[i] = 0; *pI = i; } /* ** Close an vfstrace-file. */ static int vfstraceClose(sqlite3_file *pFile){ vfstrace_file *p = (vfstrace_file *)pFile; vfstrace_info *pInfo = p->pInfo; int rc; vfstrace_printf(pInfo, "%s.xClose(%s)", pInfo->zVfsName, p->zFName); rc = p->pReal->pMethods->xClose(p->pReal); vfstrace_print_errcode(pInfo, " -> %s\n", rc); if( rc==SQLITE_OK ){ sqlite3_free((void*)p->base.pMethods); p->base.pMethods = 0; } return rc; } /* ** Read data from an vfstrace-file. */ static int vfstraceRead( sqlite3_file *pFile, void *zBuf, int iAmt, sqlite_int64 iOfst ){ vfstrace_file *p = (vfstrace_file *)pFile; vfstrace_info *pInfo = p->pInfo; int rc; vfstrace_printf(pInfo, "%s.xRead(%s,n=%d,ofst=%lld)", pInfo->zVfsName, p->zFName, iAmt, iOfst); rc = p->pReal->pMethods->xRead(p->pReal, zBuf, iAmt, iOfst); vfstrace_print_errcode(pInfo, " -> %s\n", rc); return rc; } /* ** Write data to an vfstrace-file. */ static int vfstraceWrite( sqlite3_file *pFile, const void *zBuf, int iAmt, sqlite_int64 iOfst ){ vfstrace_file *p = (vfstrace_file *)pFile; vfstrace_info *pInfo = p->pInfo; int rc; vfstrace_printf(pInfo, "%s.xWrite(%s,n=%d,ofst=%lld)", pInfo->zVfsName, p->zFName, iAmt, iOfst); rc = p->pReal->pMethods->xWrite(p->pReal, zBuf, iAmt, iOfst); vfstrace_print_errcode(pInfo, " -> %s\n", rc); return rc; } /* ** Truncate an vfstrace-file. */ static int vfstraceTruncate(sqlite3_file *pFile, sqlite_int64 size){ vfstrace_file *p = (vfstrace_file *)pFile; vfstrace_info *pInfo = p->pInfo; int rc; vfstrace_printf(pInfo, "%s.xTruncate(%s,%lld)", pInfo->zVfsName, p->zFName, size); rc = p->pReal->pMethods->xTruncate(p->pReal, size); vfstrace_printf(pInfo, " -> %d\n", rc); return rc; } /* ** Sync an vfstrace-file. */ static int vfstraceSync(sqlite3_file *pFile, int flags){ vfstrace_file *p = (vfstrace_file *)pFile; vfstrace_info *pInfo = p->pInfo; int rc; int i; char zBuf[100]; memcpy(zBuf, "|0", 3); i = 0; if( flags & SQLITE_SYNC_FULL ) strappend(zBuf, &i, "|FULL"); else if( flags & SQLITE_SYNC_NORMAL ) strappend(zBuf, &i, "|NORMAL"); if( flags & SQLITE_SYNC_DATAONLY ) strappend(zBuf, &i, "|DATAONLY"); if( flags & ~(SQLITE_SYNC_FULL|SQLITE_SYNC_DATAONLY) ){ sqlite3_snprintf(sizeof(zBuf)-i, &zBuf[i], "|0x%x", flags); } vfstrace_printf(pInfo, "%s.xSync(%s,%s)", pInfo->zVfsName, p->zFName, &zBuf[1]); rc = p->pReal->pMethods->xSync(p->pReal, flags); vfstrace_printf(pInfo, " -> %d\n", rc); return rc; } /* ** Return the current file-size of an vfstrace-file. */ static int vfstraceFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){ vfstrace_file *p = (vfstrace_file *)pFile; vfstrace_info *pInfo = p->pInfo; int rc; vfstrace_printf(pInfo, "%s.xFileSize(%s)", pInfo->zVfsName, p->zFName); rc = p->pReal->pMethods->xFileSize(p->pReal, pSize); vfstrace_print_errcode(pInfo, " -> %s,", rc); vfstrace_printf(pInfo, " size=%lld\n", *pSize); return rc; } /* ** Return the name of a lock. */ static const char *lockName(int eLock){ const char *azLockNames[] = { "NONE", "SHARED", "RESERVED", "PENDING", "EXCLUSIVE" }; if( eLock<0 || eLock>=sizeof(azLockNames)/sizeof(azLockNames[0]) ){ return "???"; }else{ return azLockNames[eLock]; } } /* ** Lock an vfstrace-file. */ static int vfstraceLock(sqlite3_file *pFile, int eLock){ vfstrace_file *p = (vfstrace_file *)pFile; vfstrace_info *pInfo = p->pInfo; int rc; vfstrace_printf(pInfo, "%s.xLock(%s,%s)", pInfo->zVfsName, p->zFName, lockName(eLock)); rc = p->pReal->pMethods->xLock(p->pReal, eLock); vfstrace_print_errcode(pInfo, " -> %s\n", rc); return rc; } /* ** Unlock an vfstrace-file. */ static int vfstraceUnlock(sqlite3_file *pFile, int eLock){ vfstrace_file *p = (vfstrace_file *)pFile; vfstrace_info *pInfo = p->pInfo; int rc; vfstrace_printf(pInfo, "%s.xUnlock(%s,%s)", pInfo->zVfsName, p->zFName, lockName(eLock)); rc = p->pReal->pMethods->xUnlock(p->pReal, eLock); vfstrace_print_errcode(pInfo, " -> %s\n", rc); return rc; } /* ** Check if another file-handle holds a RESERVED lock on an vfstrace-file. */ static int vfstraceCheckReservedLock(sqlite3_file *pFile, int *pResOut){ vfstrace_file *p = (vfstrace_file *)pFile; vfstrace_info *pInfo = p->pInfo; int rc; vfstrace_printf(pInfo, "%s.xCheckReservedLock(%s,%d)", pInfo->zVfsName, p->zFName); rc = p->pReal->pMethods->xCheckReservedLock(p->pReal, pResOut); vfstrace_print_errcode(pInfo, " -> %s", rc); vfstrace_printf(pInfo, ", out=%d\n", *pResOut); return rc; } /* ** File control method. For custom operations on an vfstrace-file. */ static int vfstraceFileControl(sqlite3_file *pFile, int op, void *pArg){ vfstrace_file *p = (vfstrace_file *)pFile; vfstrace_info *pInfo = p->pInfo; int rc; char zBuf[100]; char *zOp; switch( op ){ case SQLITE_FCNTL_LOCKSTATE: zOp = "LOCKSTATE"; break; case SQLITE_GET_LOCKPROXYFILE: zOp = "GET_LOCKPROXYFILE"; break; case SQLITE_SET_LOCKPROXYFILE: zOp = "SET_LOCKPROXYFILE"; break; case SQLITE_LAST_ERRNO: zOp = "LAST_ERRNO"; break; case SQLITE_FCNTL_SIZE_HINT: { sqlite3_snprintf(sizeof(zBuf), zBuf, "SIZE_HINT,%lld", *(sqlite3_int64*)pArg); zOp = zBuf; break; } case SQLITE_FCNTL_CHUNK_SIZE: { sqlite3_snprintf(sizeof(zBuf), zBuf, "CHUNK_SIZE,%d", *(int*)pArg); zOp = zBuf; break; } case SQLITE_FCNTL_FILE_POINTER: zOp = "FILE_POINTER"; break; case SQLITE_FCNTL_SYNC_OMITTED: zOp = "SYNC_OMITTED"; break; case SQLITE_FCNTL_WIN32_AV_RETRY: zOp = "WIN32_AV_RETRY"; break; case SQLITE_FCNTL_PERSIST_WAL: zOp = "PERSIST_WAL"; break; case SQLITE_FCNTL_OVERWRITE: zOp = "OVERWRITE"; break; case SQLITE_FCNTL_VFSNAME: zOp = "VFSNAME"; break; case SQLITE_FCNTL_TEMPFILENAME: zOp = "TEMPFILENAME"; break; case 0xca093fa0: zOp = "DB_UNCHANGED"; break; case SQLITE_FCNTL_PRAGMA: { const char *const* a = (const char*const*)pArg; sqlite3_snprintf(sizeof(zBuf), zBuf, "PRAGMA,[%s,%s]",a[1],a[2]); zOp = zBuf; break; } default: { sqlite3_snprintf(sizeof zBuf, zBuf, "%d", op); zOp = zBuf; break; } } vfstrace_printf(pInfo, "%s.xFileControl(%s,%s)", pInfo->zVfsName, p->zFName, zOp); rc = p->pReal->pMethods->xFileControl(p->pReal, op, pArg); vfstrace_print_errcode(pInfo, " -> %s\n", rc); if( op==SQLITE_FCNTL_VFSNAME && rc==SQLITE_OK ){ *(char**)pArg = sqlite3_mprintf("vfstrace.%s/%z", pInfo->zVfsName, *(char**)pArg); } if( (op==SQLITE_FCNTL_PRAGMA || op==SQLITE_FCNTL_TEMPFILENAME) && rc==SQLITE_OK && *(char**)pArg ){ vfstrace_printf(pInfo, "%s.xFileControl(%s,%s) returns %s", pInfo->zVfsName, p->zFName, zOp, *(char**)pArg); } return rc; } /* ** Return the sector-size in bytes for an vfstrace-file. */ static int vfstraceSectorSize(sqlite3_file *pFile){ vfstrace_file *p = (vfstrace_file *)pFile; vfstrace_info *pInfo = p->pInfo; int rc; vfstrace_printf(pInfo, "%s.xSectorSize(%s)", pInfo->zVfsName, p->zFName); rc = p->pReal->pMethods->xSectorSize(p->pReal); vfstrace_printf(pInfo, " -> %d\n", rc); return rc; } /* ** Return the device characteristic flags supported by an vfstrace-file. */ static int vfstraceDeviceCharacteristics(sqlite3_file *pFile){ vfstrace_file *p = (vfstrace_file *)pFile; vfstrace_info *pInfo = p->pInfo; int rc; vfstrace_printf(pInfo, "%s.xDeviceCharacteristics(%s)", pInfo->zVfsName, p->zFName); rc = p->pReal->pMethods->xDeviceCharacteristics(p->pReal); vfstrace_printf(pInfo, " -> 0x%08x\n", rc); return rc; } /* ** Shared-memory operations. */ static int vfstraceShmLock(sqlite3_file *pFile, int ofst, int n, int flags){ vfstrace_file *p = (vfstrace_file *)pFile; vfstrace_info *pInfo = p->pInfo; int rc; char zLck[100]; int i = 0; memcpy(zLck, "|0", 3); if( flags & SQLITE_SHM_UNLOCK ) strappend(zLck, &i, "|UNLOCK"); if( flags & SQLITE_SHM_LOCK ) strappend(zLck, &i, "|LOCK"); if( flags & SQLITE_SHM_SHARED ) strappend(zLck, &i, "|SHARED"); if( flags & SQLITE_SHM_EXCLUSIVE ) strappend(zLck, &i, "|EXCLUSIVE"); if( flags & ~(0xf) ){ sqlite3_snprintf(sizeof(zLck)-i, &zLck[i], "|0x%x", flags); } vfstrace_printf(pInfo, "%s.xShmLock(%s,ofst=%d,n=%d,%s)", pInfo->zVfsName, p->zFName, ofst, n, &zLck[1]); rc = p->pReal->pMethods->xShmLock(p->pReal, ofst, n, flags); vfstrace_print_errcode(pInfo, " -> %s\n", rc); return rc; } static int vfstraceShmMap( sqlite3_file *pFile, int iRegion, int szRegion, int isWrite, void volatile **pp ){ vfstrace_file *p = (vfstrace_file *)pFile; vfstrace_info *pInfo = p->pInfo; int rc; vfstrace_printf(pInfo, "%s.xShmMap(%s,iRegion=%d,szRegion=%d,isWrite=%d,*)", pInfo->zVfsName, p->zFName, iRegion, szRegion, isWrite); rc = p->pReal->pMethods->xShmMap(p->pReal, iRegion, szRegion, isWrite, pp); vfstrace_print_errcode(pInfo, " -> %s\n", rc); return rc; } static void vfstraceShmBarrier(sqlite3_file *pFile){ vfstrace_file *p = (vfstrace_file *)pFile; vfstrace_info *pInfo = p->pInfo; vfstrace_printf(pInfo, "%s.xShmBarrier(%s)\n", pInfo->zVfsName, p->zFName); p->pReal->pMethods->xShmBarrier(p->pReal); } static int vfstraceShmUnmap(sqlite3_file *pFile, int delFlag){ vfstrace_file *p = (vfstrace_file *)pFile; vfstrace_info *pInfo = p->pInfo; int rc; vfstrace_printf(pInfo, "%s.xShmUnmap(%s,delFlag=%d)", pInfo->zVfsName, p->zFName, delFlag); rc = p->pReal->pMethods->xShmUnmap(p->pReal, delFlag); vfstrace_print_errcode(pInfo, " -> %s\n", rc); return rc; } /* ** Open an vfstrace file handle. */ static int vfstraceOpen( sqlite3_vfs *pVfs, const char *zName, sqlite3_file *pFile, int flags, int *pOutFlags ){ int rc; vfstrace_file *p = (vfstrace_file *)pFile; vfstrace_info *pInfo = (vfstrace_info*)pVfs->pAppData; sqlite3_vfs *pRoot = pInfo->pRootVfs; p->pInfo = pInfo; p->zFName = zName ? fileTail(zName) : "<temp>"; p->pReal = (sqlite3_file *)&p[1]; rc = pRoot->xOpen(pRoot, zName, p->pReal, flags, pOutFlags); vfstrace_printf(pInfo, "%s.xOpen(%s,flags=0x%x)", pInfo->zVfsName, p->zFName, flags); if( p->pReal->pMethods ){ sqlite3_io_methods *pNew = sqlite3_malloc( sizeof(*pNew) ); const sqlite3_io_methods *pSub = p->pReal->pMethods; memset(pNew, 0, sizeof(*pNew)); pNew->iVersion = pSub->iVersion; pNew->xClose = vfstraceClose; pNew->xRead = vfstraceRead; pNew->xWrite = vfstraceWrite; pNew->xTruncate = vfstraceTruncate; pNew->xSync = vfstraceSync; pNew->xFileSize = vfstraceFileSize; pNew->xLock = vfstraceLock; pNew->xUnlock = vfstraceUnlock; pNew->xCheckReservedLock = vfstraceCheckReservedLock; pNew->xFileControl = vfstraceFileControl; pNew->xSectorSize = vfstraceSectorSize; pNew->xDeviceCharacteristics = vfstraceDeviceCharacteristics; if( pNew->iVersion>=2 ){ pNew->xShmMap = pSub->xShmMap ? vfstraceShmMap : 0; pNew->xShmLock = pSub->xShmLock ? vfstraceShmLock : 0; pNew->xShmBarrier = pSub->xShmBarrier ? vfstraceShmBarrier : 0; pNew->xShmUnmap = pSub->xShmUnmap ? vfstraceShmUnmap : 0; } pFile->pMethods = pNew; } vfstrace_print_errcode(pInfo, " -> %s", rc); if( pOutFlags ){ vfstrace_printf(pInfo, ", outFlags=0x%x\n", *pOutFlags); }else{ vfstrace_printf(pInfo, "\n"); } return rc; } /* ** Delete the file located at zPath. If the dirSync argument is true, ** ensure the file-system modifications are synced to disk before ** returning. */ static int vfstraceDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){ vfstrace_info *pInfo = (vfstrace_info*)pVfs->pAppData; sqlite3_vfs *pRoot = pInfo->pRootVfs; int rc; vfstrace_printf(pInfo, "%s.xDelete(\"%s\",%d)", pInfo->zVfsName, zPath, dirSync); rc = pRoot->xDelete(pRoot, zPath, dirSync); vfstrace_print_errcode(pInfo, " -> %s\n", rc); return rc; } /* ** Test for access permissions. Return true if the requested permission ** is available, or false otherwise. */ static int vfstraceAccess( sqlite3_vfs *pVfs, const char *zPath, int flags, int *pResOut ){ vfstrace_info *pInfo = (vfstrace_info*)pVfs->pAppData; sqlite3_vfs *pRoot = pInfo->pRootVfs; int rc; vfstrace_printf(pInfo, "%s.xAccess(\"%s\",%d)", pInfo->zVfsName, zPath, flags); rc = pRoot->xAccess(pRoot, zPath, flags, pResOut); vfstrace_print_errcode(pInfo, " -> %s", rc); vfstrace_printf(pInfo, ", out=%d\n", *pResOut); return rc; } /* ** Populate buffer zOut with the full canonical pathname corresponding ** to the pathname in zPath. zOut is guaranteed to point to a buffer ** of at least (DEVSYM_MAX_PATHNAME+1) bytes. */ static int vfstraceFullPathname( sqlite3_vfs *pVfs, const char *zPath, int nOut, char *zOut ){ vfstrace_info *pInfo = (vfstrace_info*)pVfs->pAppData; sqlite3_vfs *pRoot = pInfo->pRootVfs; int rc; vfstrace_printf(pInfo, "%s.xFullPathname(\"%s\")", pInfo->zVfsName, zPath); rc = pRoot->xFullPathname(pRoot, zPath, nOut, zOut); vfstrace_print_errcode(pInfo, " -> %s", rc); vfstrace_printf(pInfo, ", out=\"%.*s\"\n", nOut, zOut); return rc; } /* ** Open the dynamic library located at zPath and return a handle. */ static void *vfstraceDlOpen(sqlite3_vfs *pVfs, const char *zPath){ vfstrace_info *pInfo = (vfstrace_info*)pVfs->pAppData; sqlite3_vfs *pRoot = pInfo->pRootVfs; vfstrace_printf(pInfo, "%s.xDlOpen(\"%s\")\n", pInfo->zVfsName, zPath); return pRoot->xDlOpen(pRoot, zPath); } /* ** Populate the buffer zErrMsg (size nByte bytes) with a human readable ** utf-8 string describing the most recent error encountered associated ** with dynamic libraries. */ static void vfstraceDlError(sqlite3_vfs *pVfs, int nByte, char *zErrMsg){ vfstrace_info *pInfo = (vfstrace_info*)pVfs->pAppData; sqlite3_vfs *pRoot = pInfo->pRootVfs; vfstrace_printf(pInfo, "%s.xDlError(%d)", pInfo->zVfsName, nByte); pRoot->xDlError(pRoot, nByte, zErrMsg); vfstrace_printf(pInfo, " -> \"%s\"", zErrMsg); } /* ** Return a pointer to the symbol zSymbol in the dynamic library pHandle. */ static void (*vfstraceDlSym(sqlite3_vfs *pVfs,void *p,const char *zSym))(void){ vfstrace_info *pInfo = (vfstrace_info*)pVfs->pAppData; sqlite3_vfs *pRoot = pInfo->pRootVfs; vfstrace_printf(pInfo, "%s.xDlSym(\"%s\")\n", pInfo->zVfsName, zSym); return pRoot->xDlSym(pRoot, p, zSym); } /* ** Close the dynamic library handle pHandle. */ static void vfstraceDlClose(sqlite3_vfs *pVfs, void *pHandle){ vfstrace_info *pInfo = (vfstrace_info*)pVfs->pAppData; sqlite3_vfs *pRoot = pInfo->pRootVfs; vfstrace_printf(pInfo, "%s.xDlOpen()\n", pInfo->zVfsName); pRoot->xDlClose(pRoot, pHandle); } /* ** Populate the buffer pointed to by zBufOut with nByte bytes of ** random data. */ static int vfstraceRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){ vfstrace_info *pInfo = (vfstrace_info*)pVfs->pAppData; sqlite3_vfs *pRoot = pInfo->pRootVfs; vfstrace_printf(pInfo, "%s.xRandomness(%d)\n", pInfo->zVfsName, nByte); return pRoot->xRandomness(pRoot, nByte, zBufOut); } /* ** Sleep for nMicro microseconds. Return the number of microseconds ** actually slept. */ static int vfstraceSleep(sqlite3_vfs *pVfs, int nMicro){ vfstrace_info *pInfo = (vfstrace_info*)pVfs->pAppData; sqlite3_vfs *pRoot = pInfo->pRootVfs; return pRoot->xSleep(pRoot, nMicro); } /* ** Return the current time as a Julian Day number in *pTimeOut. */ static int vfstraceCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){ vfstrace_info *pInfo = (vfstrace_info*)pVfs->pAppData; sqlite3_vfs *pRoot = pInfo->pRootVfs; return pRoot->xCurrentTime(pRoot, pTimeOut); } static int vfstraceCurrentTimeInt64(sqlite3_vfs *pVfs, sqlite3_int64 *pTimeOut){ vfstrace_info *pInfo = (vfstrace_info*)pVfs->pAppData; sqlite3_vfs *pRoot = pInfo->pRootVfs; return pRoot->xCurrentTimeInt64(pRoot, pTimeOut); } /* ** Return th3 emost recent error code and message */ static int vfstraceGetLastError(sqlite3_vfs *pVfs, int iErr, char *zErr){ vfstrace_info *pInfo = (vfstrace_info*)pVfs->pAppData; sqlite3_vfs *pRoot = pInfo->pRootVfs; return pRoot->xGetLastError(pRoot, iErr, zErr); } /* ** Override system calls. */ static int vfstraceSetSystemCall( sqlite3_vfs *pVfs, const char *zName, sqlite3_syscall_ptr pFunc ){ vfstrace_info *pInfo = (vfstrace_info*)pVfs->pAppData; sqlite3_vfs *pRoot = pInfo->pRootVfs; return pRoot->xSetSystemCall(pRoot, zName, pFunc); } static sqlite3_syscall_ptr vfstraceGetSystemCall( sqlite3_vfs *pVfs, const char *zName ){ vfstrace_info *pInfo = (vfstrace_info*)pVfs->pAppData; sqlite3_vfs *pRoot = pInfo->pRootVfs; return pRoot->xGetSystemCall(pRoot, zName); } static const char *vfstraceNextSystemCall(sqlite3_vfs *pVfs, const char *zName){ vfstrace_info *pInfo = (vfstrace_info*)pVfs->pAppData; sqlite3_vfs *pRoot = pInfo->pRootVfs; return pRoot->xNextSystemCall(pRoot, zName); } /* ** Clients invoke this routine to construct a new trace-vfs shim. ** ** Return SQLITE_OK on success. ** ** SQLITE_NOMEM is returned in the case of a memory allocation error. ** SQLITE_NOTFOUND is returned if zOldVfsName does not exist. */ int vfstrace_register( const char *zTraceName, /* Name of the newly constructed VFS */ const char *zOldVfsName, /* Name of the underlying VFS */ int (*xOut)(const char*,void*), /* Output routine. ex: fputs */ void *pOutArg, /* 2nd argument to xOut. ex: stderr */ int makeDefault /* True to make the new VFS the default */ ){ sqlite3_vfs *pNew; sqlite3_vfs *pRoot; vfstrace_info *pInfo; int nName; int nByte; pRoot = sqlite3_vfs_find(zOldVfsName); if( pRoot==0 ) return SQLITE_NOTFOUND; nName = strlen(zTraceName); nByte = sizeof(*pNew) + sizeof(*pInfo) + nName + 1; pNew = sqlite3_malloc( nByte ); if( pNew==0 ) return SQLITE_NOMEM; memset(pNew, 0, nByte); pInfo = (vfstrace_info*)&pNew[1]; pNew->iVersion = pRoot->iVersion; pNew->szOsFile = pRoot->szOsFile + sizeof(vfstrace_file); pNew->mxPathname = pRoot->mxPathname; pNew->zName = (char*)&pInfo[1]; memcpy((char*)&pInfo[1], zTraceName, nName+1); pNew->pAppData = pInfo; pNew->xOpen = vfstraceOpen; pNew->xDelete = vfstraceDelete; pNew->xAccess = vfstraceAccess; pNew->xFullPathname = vfstraceFullPathname; pNew->xDlOpen = pRoot->xDlOpen==0 ? 0 : vfstraceDlOpen; pNew->xDlError = pRoot->xDlError==0 ? 0 : vfstraceDlError; pNew->xDlSym = pRoot->xDlSym==0 ? 0 : vfstraceDlSym; pNew->xDlClose = pRoot->xDlClose==0 ? 0 : vfstraceDlClose; pNew->xRandomness = vfstraceRandomness; pNew->xSleep = vfstraceSleep; pNew->xCurrentTime = vfstraceCurrentTime; pNew->xGetLastError = pRoot->xGetLastError==0 ? 0 : vfstraceGetLastError; if( pNew->iVersion>=2 ){ pNew->xCurrentTimeInt64 = pRoot->xCurrentTimeInt64==0 ? 0 : vfstraceCurrentTimeInt64; if( pNew->iVersion>=3 ){ pNew->xSetSystemCall = pRoot->xSetSystemCall==0 ? 0 : vfstraceSetSystemCall; pNew->xGetSystemCall = pRoot->xGetSystemCall==0 ? 0 : vfstraceGetSystemCall; pNew->xNextSystemCall = pRoot->xNextSystemCall==0 ? 0 : vfstraceNextSystemCall; } } pInfo->pRootVfs = pRoot; pInfo->xOut = xOut; pInfo->pOutArg = pOutArg; pInfo->zVfsName = pNew->zName; pInfo->pTraceVfs = pNew; vfstrace_printf(pInfo, "%s.enabled_for(\"%s\")\n", pInfo->zVfsName, pRoot->zName); return sqlite3_vfs_register(pNew, makeDefault); }
the_stack_data/59512388.c
#include <stdio.h> #include <stdlib.h> typedef struct { char *name; int size; void (*(*_vtable)[])(); } metadata; typedef struct { metadata *clazz; } object; object *alloc(metadata *clazz) { object *p = malloc(clazz->size); p->clazz = clazz; return p; } // D e f i n e C l a s s Animal typedef struct { metadata *clazz; } Animal; #define Animal_foo_SLOT 0 #define Animal_getID_SLOT 1 int Animal_foo(Animal *this) { return (*(int (*)(Animal *))(*(this)->clazz->_vtable)[Animal_getID_SLOT])(((Animal *)this)); } int Animal_getID(Animal *this) { return 1; } void (*Animal_vtable[])() = { (void (*)())&Animal_foo, (void (*)())&Animal_getID }; metadata Animal_metadata = {"Animal", sizeof(Animal), &Animal_vtable}; // D e f i n e C l a s s Dog typedef struct { metadata *clazz; } Dog; #define Dog_foo_SLOT 0 #define Dog_getID_SLOT 1 int Dog_getID(Dog *this) { return 2; } void (*Dog_vtable[])() = { (void (*)())&Animal_foo, (void (*)())&Dog_getID }; metadata Dog_metadata = {"Dog", sizeof(Dog), &Dog_vtable}; // D e f i n e C l a s s Pekinese typedef struct { metadata *clazz; } Pekinese; #define Pekinese_foo_SLOT 0 #define Pekinese_getID_SLOT 1 int Pekinese_getID(Pekinese *this) { return 3; } void (*Pekinese_vtable[])() = { (void (*)())&Animal_foo, (void (*)())&Pekinese_getID }; metadata Pekinese_metadata = {"Pekinese", sizeof(Pekinese), &Pekinese_vtable}; int main(int argc, char *argv[]) { Pekinese * d; d = ((Pekinese *)alloc(&Pekinese_metadata)); printf("%d\n", (*(int (*)(Animal *))(*(d)->clazz->_vtable)[Pekinese_foo_SLOT])(((Animal *)d))); }
the_stack_data/64201202.c
/* * Copyright (c) 2000 by Matt Welsh and The Regents of the University of * California. All rights reserved. * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose, without fee, and without written agreement is * hereby granted, provided that the above copyright notice and the following * two paragraphs appear in all copies of this software. * * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. * * Author: Matt Welsh <[email protected]> * */ /* This is a simple C test program which opens a nonblocking socket and * reads a sequence of packets from it. */ #include <stdio.h> #include <errno.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/ioctl.h> #include <netinet/tcp.h> #include <netinet/in.h> #include <arpa/inet.h> #include <unistd.h> #include <fcntl.h> #undef NDEBUG #include <assert.h> #define PORT 4046 void main() { int fd; int arg; struct sockaddr_in him; char buf[4096]; fd = socket(AF_INET, SOCK_STREAM, 0); setsockopt(fd,SOL_SOCKET, SO_REUSEADDR, (char *)&arg, 4); memset((char *)&him, 0, sizeof(him)); him.sin_port = htons((short)0); him.sin_addr.s_addr = (unsigned long)htonl(INADDR_ANY); him.sin_family = AF_INET; assert(bind(fd, (struct sockaddr *)&him, sizeof(him)) >= 0); memset((char *)&him, 0, sizeof(him)); him.sin_port = htons((short)PORT); him.sin_addr.s_addr = (unsigned long)htonl(INADDR_LOOPBACK); him.sin_family = AF_INET; assert(connect(fd, (struct sockaddr *)&him, sizeof(him)) >= 0); assert(fcntl(fd, F_SETFL, O_NONBLOCK) >= 0); while (1) { int n; fprintf(stderr,"Reading...\n"); n = read(fd, buf, 4096); if (n >= 0) { fprintf(stderr,"Read %d bytes\n", n); } else { fprintf(stderr,"Got error: %d (errno=%d): %s\n", n, errno, strerror(errno)); } } }
the_stack_data/1063332.c
extern const unsigned char kitiosVersionString[]; extern const double kitiosVersionNumber; const unsigned char kitiosVersionString[] __attribute__ ((used)) = "@(#)PROGRAM:kitios PROJECT:kitios-5" "\n"; const double kitiosVersionNumber __attribute__ ((used)) = (double)5.;
the_stack_data/132952361.c
#include <stdio.h> /* print Fahrenheit-Celsius table * for fahr = 0 , 20, ..., 300*/ main() { float fahr, celsius; float lower, upper, step; lower = 0; /* lower limit of temperature*/ upper = 300; /* upper limit */ step = 20; /* step size*/ fahr = lower; printf("The table of Fahrenheit-Celsius conversion\n"); printf("Fahrenheit Celsius\n"); while (fahr <= upper) { celsius = (5.0/9.0) * (fahr - 32.0); printf("%8.0f %8.1f\n",fahr,celsius); fahr = fahr + step; } }
the_stack_data/178264280.c
/* Default definition for ARGP_PROGRAM_VERSION. Copyright (C) 1996-2017 Free Software Foundation, Inc. This file is part of the GNU C Library. Written by Miles Bader <[email protected]>. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ /* If set by the user program to a non-zero value, then a default option --version is added (unless the ARGP_NO_HELP flag is used), which will print this string followed by a newline and exit (unless the ARGP_NO_EXIT flag is used). Overridden by ARGP_PROGRAM_VERSION_HOOK. */ const char *argp_program_version /* This variable should be zero-initialized. On most systems, putting it into BSS is sufficient. Not so on Mac OS X 10.3 and 10.4, see <http://lists.gnu.org/archive/html/bug-gnulib/2009-01/msg00329.html> <http://lists.gnu.org/archive/html/bug-gnulib/2009-08/msg00096.html>. */ #if defined __ELF__ /* On ELF systems, variables in BSS behave well. */ #else = (const char *) 0 #endif ;
the_stack_data/178265108.c
#ifdef _MSC_VER #define _CRT_SECURE_NO_WARNINGS #endif #include <stdio.h> #include <stdlib.h> int main() { enum { nmax = 100 }; int t = 0; for ((void)scanf("%d", &t); t > 0; --t) { int n = 0; (void)scanf("%d", &n); if (n <= 0 || n > nmax) abort(); int a[nmax] = { 0 }; for (int i = 0; i != n; ++i) (void)scanf("%d", &a[i]); int acc = 0; for (int i = 0; i != n - 1; ++i) for (int j = i + 1; j != n; ++j) acc += a[i] * a[j]; printf("%d\n", acc); } }
the_stack_data/243075.c
// Given the coordinate (x, y) of center of a circle and its radius, // write a program that will determine whether a point lies inside the // circle, on the circle or outside the circle. #include<stdio.h> #include<math.h> int main() { int x, y, distance,x1,y1, radius; printf("\n\n enter the coordinates of center\n"); printf("enter the x and y coordinate\n"); scanf("%d %d",&x,&y); printf("enter the radius of the circle\n"); scanf("%d",&radius); printf("enter the coordinate of points\n"); scanf("%d %d",&x1, &y1); distance = sqrt(pow((x1-x),2) + pow((y1-y),2)); if(distance > radius) printf("point lies outside the circle"); if(distance == radius) printf("point lies on the circle"); if(distance < radius) printf("point lies inside the circle"); return 0; }
the_stack_data/264733.c
#include<stdio.h> int main() { int friends; printf("enter your friend number :"); scanf(" %d", &friends); printf("i have %d friend%s",friends, (friends!= 1) ? "s" : "" );//it is a short hand if else statement..... // if friend is not equal to 1 than add 's' otherwisw not.... return 0; }
the_stack_data/237643578.c
/* Copyright (c) 2017, Piotr Durlej * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include <unistd.h> #include <fcntl.h> #include <stdio.h> int mem_fd; int main(int argc, char **argv) { char buf[128]; mem_fd = open("/dev/mem", O_RDWR); if (mem_fd < 0) { perror("open: /dev/mem"); return 1; } if (lseek(mem_fd, 0xfff00, SEEK_SET) < 0) { perror("lseek: /dev/mem"); return 1; } read(mem_fd, buf, sizeof buf - 1); buf[127] = 0; printf("%s\n", buf); return 0; }
the_stack_data/248581901.c
// Copyright (c) 2013, Sergey Lyubka // Copyright (c) 2017, The Monero Project // All rights reserved. // Released under the MIT license. // This program takes a list of files as an input, and produces C++ code that // contains the contents of all these files as a collection of strings. // // Usage: // 1. Compile this file: // cc -o generate-translations-header generate-translations-header.c // // 2. Convert list of files into single header: // ./generate-translations-header veronite_fr.qm veronite_it.qm > translations_files.h // // 3. In your application code, include translations_files.h, then you can // access the files using this function: // static bool find_embedded_file(const std::string &file_name, std::string &data); // std::string data; // find_embedded_file("veronite_fr.qm", data); #include <stdio.h> #include <stdlib.h> static const char *code = "static bool find_embedded_file(const std::string &name, std::string &data) {\n" " const struct embedded_file *p;\n" " for (p = embedded_files; p->name != NULL; p++) {\n" " if (*p->name == name) {\n" " data = *p->data;\n" " return true;\n" " }\n" " }\n" " return false;\n" "}\n"; int main(int argc, char *argv[]) { FILE *fp, *foutput; int i, j, ch; if((foutput = fopen("translation_files.h", "w")) == NULL) { exit(EXIT_FAILURE); } fprintf(foutput, "#ifndef TRANSLATION_FILES_H\n"); fprintf(foutput, "#define TRANSLATION_FILES_H\n\n"); fprintf(foutput, "#include <string>\n\n"); for (i = 1; i < argc; i++) { if ((fp = fopen(argv[i], "rb")) == NULL) { exit(EXIT_FAILURE); } else { fprintf(foutput, "static const std::string translation_file_name_%d = \"%s\";\n", i, argv[i]); fprintf(foutput, "static const std::string translation_file_data_%d = std::string(", i); for (j = 0; (ch = fgetc(fp)) != EOF; j++) { if ((j % 16) == 0) { if (j > 0) { fprintf(foutput, "%s", "\""); } fprintf(foutput, "%s", "\n \""); } fprintf(foutput, "\\x%02x", ch); } fprintf(foutput, "\",\n %d);\n\n", j); fclose(fp); } } fprintf(foutput, "%s", "static const struct embedded_file {\n"); fprintf(foutput, "%s", " const std::string *name;\n"); fprintf(foutput, "%s", " const std::string *data;\n"); fprintf(foutput, "%s", "} embedded_files[] = {\n"); for (i = 1; i < argc; i++) { fprintf(foutput, " {&translation_file_name_%d, &translation_file_data_%d},\n", i, i); } fprintf(foutput, "%s", " {NULL, NULL}\n"); fprintf(foutput, "%s", "};\n\n"); fprintf(foutput, "%s\n", code); fprintf(foutput, "#endif /* TRANSLATION_FILES_H */\n"); fclose(foutput); return EXIT_SUCCESS; }
the_stack_data/20450200.c
#include <stdio.h> char ex_change(char one) { char res; res = one^0x20; return res; } int main(void) { char sec_char, res; printf("알파벳 문자 하나를 입력 하여 주세요. : "); scanf("%c", &sec_char); res = ex_change(sec_char); printf("입력한 문자는 %c, 지금은 %c 입니다. \n", sec_char, res); return 0; }
the_stack_data/173576825.c
#define swap(a, b) ((a) != (b) && ((a) ^= (b) ^= (a) ^= (b))) typedef struct pair { int first; int second; } pair; int compress(int **board, int M, int N) { int res = 0; for (int i = 0; i < M; ++i) { for (int j = 0; j < N; ++j) res = res * 10 + board[i][j]; } return res; } void decompress(int **board, int M, int N, int state) { for (int i = M - 1; i >= 0; --i) { for (int j = N - 1; j >= 0; --j) { board[i][j] = state % 10; state /= 10; } } } pair findZero(int **board, int M, int N) { pair zero; zero.first = zero.second = 0; for (int i = 0; i < M; ++i) { for (int j = 0; j < N; ++j) { if (board[i][j] == 0) { zero.first = i; zero.second = j; return zero; } } } return zero; } int slidingPuzzle(int **board, int boardSize, int *boardColSize) { int M = boardSize, N = *boardColSize; int seen[543211] = {0}, res = 0; int size = 50000, queue[size], front = 0, rear = 0; //queue definition int state = compress(board, M, N), finalstate = 123450; if (state == finalstate) return res; queue[rear] = state; rear = (rear - 1 + size) % size; //push back while (front != rear) { ++res; int s = (front - rear + size) % size; //qsize while (--s >= 0) { state = queue[front]; front = (front - 1 + size) % size; //pop front decompress(board, M, N, state); pair zero = findZero(board, M, N); //board dfs direction int path[5] = {-1, 0, 1, 0, -1}; for (int k = 0; k < 4; ++k) { int x = zero.first + path[k], y = zero.second + path[k + 1]; if (x < 0 || x >= M || y < 0 || y >= N) continue; swap(board[zero.first][zero.second], board[x][y]); state = compress(board, M, N); if (seen[state] == 0) { if (state == finalstate) return res; seen[state] = 1; queue[rear] = state; rear = (rear - 1 + size) % size; //push back } swap(board[zero.first][zero.second], board[x][y]); } } } return -1; }