diff f6ac182f86bf0bcc777a76db50f94227ef6f7962 uncommitted
--- a/sys/src/9/port/etheriwl.c
+++ b/sys/src/9/port/etheriwl.c
@@ -330,25 +330,14 @@
 };
 
 /*
- * uCode TLV api
- */
-enum {
-	/* api[0] */
-	UcodeApiSta	= 1<<30,
-};
-
-/*
  * uCode capabilities
  */
 enum {
-	/* capa[0] */
-	UcodeCapLar	= 1<<1,
+	UcodeApiSta	= 30,
 
-	/* capa[1] */
-	UcodeCapQuota	= 1<<12,
-	
-	/* capa[2] */
-	UcodeCapLar2	= 1<<9,
+	UcodeCapaLar	= 1,
+	UcodeCapaQuota	= 44,
+	UcodeCapaLar2	= 73,
 };
 
 enum {
@@ -658,8 +647,6 @@
 	Type6005	= 11,	/* also Centrino Advanced-N 6030, 6235 */
 	Type2030	= 12,
 	Type2000	= 16,
-
-	Type7260	= 20,
 };
 
 static struct ratetab {
@@ -721,6 +708,8 @@
 
 #define csr32r(c, r)	(*((c)->nic+((r)/4)))
 #define csr32w(c, r, v)	(*((c)->nic+((r)/4)) = (v))
+/* macro to help with ctlr->fw->(api|capa) */
+#define isset(a, i)	((a)[(i)/32] & 1U<<(i)%32)
 
 static uint
 get16(uchar *p){
@@ -1114,7 +1103,8 @@
 	}
 
 	/* Enable the oscillator to count wake up time for L1 exit. (weird W/A) */
-	if(ctlr->type == Type7260){
+	switch(ctlr->pdev->did){
+	case 0x08b1: case 0x08b2: case 0x08b3: case 0x08b4: /* Wireless 7260/3160 */
 		if((err = niclock(ctlr)) != nil)
 			return err;
 
@@ -2014,7 +2004,7 @@
 	*p++ = mcc[0];
 	*p++ = 0;
 	*p++ = 0;	// reserved
-	if(ctlr->fw->capa[2] & UcodeCapLar2){
+	if(isset(ctlr->fw->capa, UcodeCapaLar2)){
 		p += 4;
 		p += 5*4;
 	}
@@ -2407,7 +2397,7 @@
 		p += 2;			/* sleep_tx_count */
 		p++;			/* sleep state flags */
 
-		*p++ = ctlr->fw->api[0] & UcodeApiSta ? type : 0;		/* station_type */
+		*p++ = isset(ctlr->fw->api, UcodeApiSta) ? type : 0;		/* station_type */
 
 		p += 2;			/* assoc id */
 
@@ -2416,7 +2406,7 @@
 		put32(p, 1<<0);
 		p += 4;			/* tfd_queue_mask */
 
-		if(ctlr->fw->api[0] & UcodeApiSta){
+		if(isset(ctlr->fw->api, UcodeApiSta)){
 			p += 2;		/* rx_ba_window */
 			p++;		/* sp_length */
 			p++;		/* uapsd_acs */
@@ -2750,7 +2740,7 @@
 	uchar c[4*(3*4)], *p;
 	int i;
 
-	if((ctlr->fw->capa[1] & UcodeCapQuota) == 0)
+	if(!isset(ctlr->fw->capa, UcodeCapaQuota))
 		return nil;
 
 	i = 0;
@@ -2883,6 +2873,38 @@
 }
 
 static char*
+sendcalibdata(Ctlr *ctlr)
+{
+	Block *b;
+	uchar c[4];
+	char *err;
+	int i;
+
+	for(i = 0; i < sizeof(ctlr->calib.cmd); i++){
+		if((b = ctlr->calib.cmd[i]) == nil)
+			continue;
+		if(b == ctlr->calib.cfg)
+			put16(c, 1);
+		else if(b == ctlr->calib.nch)
+			put16(c, 2);
+		else if(ctlr->calib.cmd+i < ctlr->calib.papd+nelem(ctlr->calib.papd))
+			put16(c, 4);
+		else if(ctlr->calib.cmd+i < ctlr->calib.txp+nelem(ctlr->calib.txp))
+			put16(c, 5);
+		put16(c+2, BLEN(b));
+		
+		b = copyblock(b, BLEN(b));
+		if((err = qcmd(ctlr, 4, 108, c, sizeof(c), b)) != nil){
+			freeb(b);
+			return err;
+		}
+		if((err = flushq(ctlr, 4)) != nil)
+			return err;
+	}
+	return nil;
+}
+
+static char*
 postboot7000(Ctlr *ctlr)
 {
 	char *err;
@@ -2914,21 +2936,9 @@
 			ctlr->calib.done = 1;
 		}
 	} else {
-		Block *b;
-		int i;
+		if((err = sendcalibdata(ctlr)) != nil)
+			return err;
 
-		for(i = 0; i < nelem(ctlr->calib.cmd); i++){
-			if((b = ctlr->calib.cmd[i]) == nil)
-				continue;
-			b = copyblock(b, BLEN(b));
-			if((qcmd(ctlr, 4, 108, nil, 0, b)) != nil){
-				freeb(b);
-				return err;
-			}
-			if((err = flushq(ctlr, 4)) != nil)
-				return err;
-		}
-
 		if((err = sendphyconfig(ctlr,
 			ctlr->fw->physku,
 			ctlr->fw->main.defcalib.flowmask,
@@ -2947,7 +2957,7 @@
 			print("can't update device power: %s\n", err);
 			return err;
 		}
-		if(ctlr->fw->capa[0] & UcodeCapLar)
+		if(!isset(ctlr->fw->capa, UcodeCapaLar))
 			if((err = sendmccupdate(ctlr, "ZZ")) != nil)
 				return err;
 		if((err = disablebeaconfilter(ctlr)) != nil){
@@ -4421,7 +4431,7 @@
 	int family;
 	
 	pdev = nil;
-	while(pdev = pcimatch(pdev, Vintel, 0)) {
+	while(pdev = pcimatch(pdev, 0x8086, 0)) {
 		Ctlr *ctlr;
 		void *mem;
 		
@@ -4467,6 +4477,7 @@
 			fwname = "iwm-7260-17";
 			break;
 		case 0x08b3:	/* Wireless AC 3160 */
+		case 0x08b4:	/* Wireless AC 3160 */
 			family = 7000;
 			fwname = "iwm-3160-17";
 			break;
@@ -4474,6 +4485,15 @@
 		case 0x095b:	/* Wireless AC 7265 */
 			family = 7000;
 			fwname = "iwm-7265-17";
+			break;
+		case 0x3165:	/* Wireless AC 3165 */
+		case 0x3166:	/* Wireless AC 3165 */
+			family = 7000;
+			fwname = "iwm-7265D-29";
+			break;
+		case 0x24fb:	/* Wireless AC 3168 */
+			family = 7000;
+			fwname = "iwm-3168-29";
 			break;
 		case 0x24f3:	/* Wireless AC 8260 */
 			family = 8000;
