From owner-svn-soc-all@FreeBSD.ORG Tue Sep 24 15:11:58 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 831DAA96 for ; Tue, 24 Sep 2013 15:11:58 +0000 (UTC) (envelope-from zcore@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 557D423B8 for ; Tue, 24 Sep 2013 15:11:58 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r8OFBwqq027949 for ; Tue, 24 Sep 2013 15:11:58 GMT (envelope-from zcore@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r8OFBwOs027932 for svn-soc-all@FreeBSD.org; Tue, 24 Sep 2013 15:11:58 GMT (envelope-from zcore@FreeBSD.org) Date: Tue, 24 Sep 2013 15:11:58 GMT Message-Id: <201309241511.r8OFBwOs027932@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to zcore@FreeBSD.org using -f From: zcore@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r257691 - soc2013/zcore/head/usr.sbin/bhyve MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Sep 2013 15:11:58 -0000 Author: zcore Date: Tue Sep 24 15:11:58 2013 New Revision: 257691 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=257691 Log: code cleanup w/o any functionaly change rename some functions/vars, unify coding style and reduce LoCs Modified: soc2013/zcore/head/usr.sbin/bhyve/pci_ahci.c Modified: soc2013/zcore/head/usr.sbin/bhyve/pci_ahci.c ============================================================================== --- soc2013/zcore/head/usr.sbin/bhyve/pci_ahci.c Tue Sep 24 14:52:43 2013 (r257690) +++ soc2013/zcore/head/usr.sbin/bhyve/pci_ahci.c Tue Sep 24 15:11:58 2013 (r257691) @@ -107,7 +107,7 @@ struct ahci_ioreq { struct blockif_req io_req; - struct ahci_port *io_pr; + struct ahci_port *io_port; STAILQ_ENTRY(ahci_ioreq) io_list; uint8_t *cfis; uint32_t len; @@ -118,7 +118,7 @@ struct ahci_port { struct blockif_ctxt *bctx; - struct pci_ahci_softc *pr_sc; + struct pci_ahci_softc *psc; uint64_t cmd_lst; uint64_t rfis; int atapi; @@ -187,7 +187,8 @@ }; #define ahci_ctx(sc) ((sc)->asc_pi->pi_vmctx) -static inline void lba_to_msf(uint8_t *buf, int lba) +static inline void +lba2msf(uint8_t *buf, int lba) { lba += 150; buf[0] = (lba / 75) / 60; @@ -205,9 +206,9 @@ int i; for (i = 0; i < sc->ports; i++) { - struct ahci_port *pr; - pr = &sc->port[i]; - if (pr->is & pr->ie) + struct ahci_port *p; + p = &sc->port[i]; + if (p->is & p->ie) sc->is |= (1 << i); } @@ -216,8 +217,9 @@ pci_generate_msi(sc->asc_pi, 0); } -static void ahci_write_fis(struct ahci_port *p, enum sata_fis_type ft, - uint8_t *fis) +static void +ahci_send_fis(struct ahci_port *p, enum sata_fis_type ft, + uint8_t *fis) { int offset, len, irq; @@ -247,12 +249,13 @@ memcpy(p->rfis + offset, fis, len); if (irq) { p->is |= irq; - ahci_generate_intr(p->pr_sc); + ahci_generate_intr(p->psc); } } -static void ahci_write_fis_sdb(struct ahci_port *p, int slot, - uint32_t tfd) +static void +ahci_send_fis_sdb(struct ahci_port *p, int slot, + uint32_t tfd) { uint8_t fis[8]; uint8_t error; @@ -265,11 +268,12 @@ if (fis[2] & ATA_S_ERROR) p->is |= AHCI_P_IX_TFE; p->tfd = tfd; - ahci_write_fis(p, FIS_TYPE_SETDEVBITS, fis); + ahci_send_fis(p, FIS_TYPE_SETDEVBITS, fis); } -static void ahci_write_fis_d2h(struct ahci_port *p, int slot, - uint8_t *cfis, uint32_t tfd) +static void +ahci_send_fis_d2h(struct ahci_port *p, int slot, + uint8_t *cfis, uint32_t tfd) { uint8_t fis[20]; uint8_t error; @@ -294,10 +298,11 @@ p->is |= AHCI_P_IX_TFE; p->tfd = tfd; p->ci &= ~(1 << slot); - ahci_write_fis(p, FIS_TYPE_REGD2H, fis); + ahci_send_fis(p, FIS_TYPE_REGD2H, fis); } -static void ahci_write_reset_fis_d2h(struct ahci_port *p) +static void +ahci_send_reset_fis_d2h(struct ahci_port *p) { uint8_t fis[20]; @@ -310,33 +315,33 @@ fis[6] = 0xeb; } fis[12] = 1; - ahci_write_fis(p, FIS_TYPE_REGD2H, fis); + ahci_send_fis(p, FIS_TYPE_REGD2H, fis); } static void -ahci_port_reset(struct ahci_port *pr) +ahci_port_reset(struct ahci_port *p) { - pr->sctl = 0; - pr->serr = 0; - pr->sact = 0; - pr->xfermode = ATA_UDMA6; - pr->mult_sectors = 128; + p->sctl = 0; + p->serr = 0; + p->sact = 0; + p->xfermode = ATA_UDMA6; + p->mult_sectors = 128; - if (!pr->bctx) { - pr->ssts = ATA_SS_DET_NO_DEVICE; - pr->sig = 0xFFFFFFFF; - pr->tfd = 0x7F; + if (!p->bctx) { + p->ssts = ATA_SS_DET_NO_DEVICE; + p->sig = 0xFFFFFFFF; + p->tfd = 0x7F; return; } - pr->ssts = ATA_SS_DET_PHY_ONLINE | ATA_SS_SPD_GEN2 | + p->ssts = ATA_SS_DET_PHY_ONLINE | ATA_SS_SPD_GEN2 | ATA_SS_IPM_ACTIVE; - pr->tfd = (1 << 8) | ATA_S_DSC | ATA_S_DMA; - if (!pr->atapi) { - pr->sig = PxSIG_ATA; - pr->tfd |= ATA_S_READY; + p->tfd = (1 << 8) | ATA_S_DSC | ATA_S_DMA; + if (!p->atapi) { + p->sig = PxSIG_ATA; + p->tfd |= ATA_S_READY; } else - pr->sig = PxSIG_ATAPI; - ahci_write_reset_fis_d2h(pr); + p->sig = PxSIG_ATAPI; + ahci_send_reset_fis_d2h(p); } static void @@ -388,7 +393,7 @@ uint32_t len; struct ahci_ioreq *aior; struct blockif_req *breq; - struct pci_ahci_softc *sc = p->pr_sc; + struct pci_ahci_softc *sc = p->psc; struct ahci_prdt_entry *prdt = (struct ahci_prdt_entry *)(cfis + 0x80); struct ahci_cmd_hdr *hdr = p->cmd_lst + slot * AHCI_CL_SIZE; @@ -505,7 +510,7 @@ from = buf; prdt = (struct ahci_prdt_entry *)(cfis + 0x80); for (i = 0; i < hdr->prdtl && len; i++) { - uint8_t *ptr = paddr_guest2host(ahci_ctx(p->pr_sc), + uint8_t *ptr = paddr_guest2host(ahci_ctx(p->psc), prdt->dba, prdt->dbc + 1); memcpy(ptr, from, prdt->dbc + 1); len -= (prdt->dbc + 1); @@ -575,7 +580,7 @@ p->is |= AHCI_P_IX_DP; } p->ci &= ~(1 << slot); - ahci_generate_intr(p->pr_sc); + ahci_generate_intr(p->psc); } static void @@ -617,7 +622,7 @@ p->is |= AHCI_P_IX_DHR; } p->ci &= ~(1 << slot); - ahci_generate_intr(p->pr_sc); + ahci_generate_intr(p->psc); } static void @@ -644,7 +649,7 @@ len = acmd[4]; cfis[4] = (cfis[4] & ~7) | ATA_I_CMD | ATA_I_IN; write_prdt(p, slot, cfis, buf, len); - ahci_write_fis_d2h(p, slot, cfis, ATA_S_READY | ATA_S_DSC); + ahci_send_fis_d2h(p, slot, cfis, ATA_S_READY | ATA_S_DSC); } static void @@ -659,7 +664,7 @@ be32enc(buf + 4, 2048); cfis[4] = (cfis[4] & ~7) | ATA_I_CMD | ATA_I_IN; write_prdt(p, slot, cfis, buf, sizeof(buf)); - ahci_write_fis_d2h(p, slot, cfis, ATA_S_READY | ATA_S_DSC); + ahci_send_fis_d2h(p, slot, cfis, ATA_S_READY | ATA_S_DSC); } static void @@ -685,49 +690,40 @@ p->asc = 0x24; tfd = (p->sense_key << 12) | ATA_S_READY | ATA_S_ERROR; cfis[4] = (cfis[4] & ~7) | ATA_I_CMD | ATA_I_IN; - ahci_write_fis_d2h(p, slot, cfis, tfd); + ahci_send_fis_d2h(p, slot, cfis, tfd); return; } + memset(buf, 0, sizeof(buf)); bp = buf + 2; *bp++ = 1; *bp++ = 1; if (start_track <= 1) { - *bp++ = 0; + bp++; *bp++ = 0x14; *bp++ = 1; - *bp++ = 0; - if (msf) { - *bp++ = 0; - lba_to_msf(bp, 0); - bp += 3; - } else { - *bp++ = 0; - *bp++ = 0; - *bp++ = 0; - *bp++ = 0; - } + bp++; + if (msf) + lba2msf(bp + 1, 0); + bp += 4; } - *bp++ = 0; + bp++; *bp++ = 0x14; *bp++ = 0xaa; - *bp++ = 0; + bp++; sectors = blockif_size(p->bctx) / blockif_sectsz(p->bctx); sectors >>= 2; - if (msf) { - *bp++ = 0; - lba_to_msf(bp, sectors); - bp += 3; - } else { + if (msf) + lba2msf(bp + 1, sectors); + else be32enc(bp, sectors); - bp += 4; - } + bp += 4; size = bp - buf; be16enc(buf, size - 2); if (len > size) len = size; write_prdt(p, slot, cfis, buf, len); cfis[4] = (cfis[4] & ~7) | ATA_I_CMD | ATA_I_IN; - ahci_write_fis_d2h(p, slot, cfis, ATA_S_READY | ATA_S_DSC); + ahci_send_fis_d2h(p, slot, cfis, ATA_S_READY | ATA_S_DSC); break; } case 1: @@ -742,88 +738,54 @@ len = sizeof(buf); write_prdt(p, slot, cfis, buf, len); cfis[4] = (cfis[4] & ~7) | ATA_I_CMD | ATA_I_IN; - ahci_write_fis_d2h(p, slot, cfis, ATA_S_READY | ATA_S_DSC); + ahci_send_fis_d2h(p, slot, cfis, ATA_S_READY | ATA_S_DSC); break; } case 2: { int msf, size; uint64_t sectors; - uint8_t start_track, *bp, buf[50]; + uint8_t start_track, buf[48]; msf = (acmd[1] >> 1) & 1; start_track = acmd[6]; - bp = buf + 2; - *bp++ = 1; - *bp++ = 1; - - *bp++ = 1; - *bp++ = 0x14; - *bp++ = 0; - *bp++ = 0xa0; - *bp++ = 0; - *bp++ = 0; - *bp++ = 0; - *bp++ = 0; - *bp++ = 1; - *bp++ = 0; - *bp++ = 0; - - *bp++ = 1; - *bp++ = 0x14; - *bp++ = 0; - *bp++ = 0xa1; - *bp++ = 0; - *bp++ = 0; - *bp++ = 0; - *bp++ = 0; - *bp++ = 1; - *bp++ = 0; - *bp++ = 0; + memset(buf, 0, sizeof(buf)); + buf[2] = 1; + buf[3] = 1; - *bp++ = 1; - *bp++ = 0x14; - *bp++ = 0; - *bp++ = 0xa2; - *bp++ = 0; - *bp++ = 0; - *bp++ = 0; + buf[4] = 1; + buf[5] = 0x14; + buf[7] = 0xa0; + buf[12] = 1; + + buf[15] = 1; + buf[16] = 0x14; + buf[18] = 0xa1; + buf[23] = 1; + + buf[26] = 1; + buf[27] = 0x14; + buf[29] = 0xa2; sectors = blockif_size(p->bctx) / blockif_sectsz(p->bctx); sectors >>= 2; - if (msf) { - *bp++ = 0; - lba_to_msf(bp, sectors); - bp += 3; - } else { - be32enc(bp, sectors); - bp += 4; - } + if (msf) + lba2msf(buf + 34, sectors); + else + be32enc(buf + 33, sectors); - *bp++ = 1; - *bp++ = 0x14; - *bp++ = 0; - *bp++ = 1; - *bp++ = 0; - *bp++ = 0; - *bp++ = 0; - if (msf) { - *bp++ = 0; - lba_to_msf(bp, 0); - bp += 3; - } else { - *bp++ = 0; - *bp++ = 0; - *bp++ = 0; - *bp++ = 0; - } + buf[37] = 1; + buf[38] = 0x14; + buf[40] = 1; + if (msf) + lba2msf(buf + 45, 0); - size = bp - buf; + size = sizeof(buf); be16enc(buf, size - 2); if (len > size) len = size; write_prdt(p, slot, cfis, buf, len); cfis[4] = (cfis[4] & ~7) | ATA_I_CMD | ATA_I_IN; - ahci_write_fis_d2h(p, slot, cfis, ATA_S_READY | ATA_S_DSC); + ahci_send_fis_d2h(p, slot, cfis, ATA_S_READY | ATA_S_DSC); break; } default: @@ -833,7 +795,7 @@ p->asc = 0x24; tfd = (p->sense_key << 12) | ATA_S_READY | ATA_S_ERROR; cfis[4] = (cfis[4] & ~7) | ATA_I_CMD | ATA_I_IN; - ahci_write_fis_d2h(p, slot, cfis, tfd); + ahci_send_fis_d2h(p, slot, cfis, tfd); break; } } @@ -849,7 +811,7 @@ struct ahci_ioreq *aior; struct blockif_req *breq; uint8_t *acmd = cfis + 0x40; - struct pci_ahci_softc *sc = p->pr_sc; + struct pci_ahci_softc *sc = p->psc; struct ahci_prdt_entry *prdt = (struct ahci_prdt_entry *)(cfis + 0x80); struct ahci_cmd_hdr *hdr = p->cmd_lst + slot * AHCI_CL_SIZE; @@ -861,7 +823,7 @@ len = be32dec(acmd + 6); if (len == 0) { cfis[4] = (cfis[4] & ~7) | ATA_I_CMD | ATA_I_IN; - ahci_write_fis_d2h(p, slot, cfis, ATA_S_READY | ATA_S_DSC); + ahci_send_fis_d2h(p, slot, cfis, ATA_S_READY | ATA_S_DSC); } lba *= 2048; len *= 2048; @@ -917,7 +879,7 @@ buf[12] = p->asc; write_prdt(p, slot, cfis, buf, len); cfis[4] = (cfis[4] & ~7) | ATA_I_CMD | ATA_I_IN; - ahci_write_fis_d2h(p, slot, cfis, ATA_S_READY | ATA_S_DSC); + ahci_send_fis_d2h(p, slot, cfis, ATA_S_READY | ATA_S_DSC); } static void @@ -941,7 +903,7 @@ tfd = (p->sense_key << 12) | ATA_S_READY | ATA_S_ERROR; break; } - ahci_write_fis_d2h(p, slot, cfis, tfd); + ahci_send_fis_d2h(p, slot, cfis, tfd); } static void @@ -1013,7 +975,7 @@ break; } cfis[4] = (cfis[4] & ~7) | ATA_I_CMD | ATA_I_IN; - ahci_write_fis_d2h(p, slot, cfis, tfd); + ahci_send_fis_d2h(p, slot, cfis, tfd); } static void @@ -1045,7 +1007,7 @@ tfd = ATA_S_READY | ATA_S_DSC; } cfis[4] = (cfis[4] & ~7) | ATA_I_CMD | ATA_I_IN; - ahci_write_fis_d2h(p, slot, cfis, tfd); + ahci_send_fis_d2h(p, slot, cfis, tfd); } static void @@ -1064,7 +1026,7 @@ switch (acmd[0]) { case TEST_UNIT_READY: cfis[4] = (cfis[4] & ~7) | ATA_I_CMD | ATA_I_IN; - ahci_write_fis_d2h(p, slot, cfis, ATA_S_READY | ATA_S_DSC); + ahci_send_fis_d2h(p, slot, cfis, ATA_S_READY | ATA_S_DSC); break; case INQUIRY: atapi_inquiry(p, slot, cfis); @@ -1075,7 +1037,7 @@ case PREVENT_ALLOW: /* TODO */ cfis[4] = (cfis[4] & ~7) | ATA_I_CMD | ATA_I_IN; - ahci_write_fis_d2h(p, slot, cfis, ATA_S_READY | ATA_S_DSC); + ahci_send_fis_d2h(p, slot, cfis, ATA_S_READY | ATA_S_DSC); break; case READ_TOC: atapi_read_toc(p, slot, cfis); @@ -1100,7 +1062,7 @@ cfis[4] = (cfis[4] & ~7) | ATA_I_CMD | ATA_I_IN; p->sense_key = ATA_SENSE_ILLEGAL_REQUEST; p->asc = 0x20; - ahci_write_fis_d2h(p, slot, cfis, (p->sense_key << 12) | + ahci_send_fis_d2h(p, slot, cfis, (p->sense_key << 12) | ATA_S_READY | ATA_S_ERROR); break; } @@ -1143,7 +1105,7 @@ } p->is |= AHCI_P_IX_DP; p->ci &= ~(1 << slot); - ahci_generate_intr(p->pr_sc); + ahci_generate_intr(p->psc); break; } case ATA_SET_MULTI: @@ -1157,7 +1119,7 @@ } p->is |= AHCI_P_IX_DP; p->ci &= ~(1 << slot); - ahci_generate_intr(p->pr_sc); + ahci_generate_intr(p->psc); break; case ATA_READ_DMA: case ATA_WRITE_DMA: @@ -1177,7 +1139,7 @@ case ATA_STANDBY_IMMEDIATE: case ATA_IDLE_IMMEDIATE: case ATA_SLEEP: - ahci_write_fis_d2h(p, slot, cfis, ATA_S_READY | ATA_S_DSC); + ahci_send_fis_d2h(p, slot, cfis, ATA_S_READY | ATA_S_DSC); break; case ATA_ATAPI_IDENTIFY: handle_atapi_identify(p, slot, cfis); @@ -1187,7 +1149,7 @@ p->tfd = (ATA_E_ABORT << 8) | ATA_S_READY | ATA_S_ERROR; p->is |= AHCI_P_IX_TFE; p->ci &= ~(1 << slot); - ahci_generate_intr(p->pr_sc); + ahci_generate_intr(p->psc); } else handle_packet_cmd(p, slot, cfis); break; @@ -1196,7 +1158,7 @@ p->tfd = (ATA_E_ABORT << 8) | ATA_S_READY | ATA_S_ERROR; p->is |= AHCI_P_IX_TFE; p->ci &= ~(1 << slot); - ahci_generate_intr(p->pr_sc); + ahci_generate_intr(p->psc); break; } } @@ -1210,7 +1172,7 @@ struct ahci_prdt_entry *prdt; struct pci_ahci_softc *sc; - sc = p->pr_sc; + sc = p->psc; hdr = p->cmd_lst + slot * AHCI_CL_SIZE; cfl = (hdr->flags & 0x1f) * 4; cfis = paddr_guest2host(ahci_ctx(sc), hdr->ctba, @@ -1280,11 +1242,11 @@ DPRINTF("%s %d\n", __func__, err); aior = br->br_param; - p = aior->io_pr; + p = aior->io_port; cfis = aior->cfis; slot = aior->slot; pending = aior->prdtl; - sc = p->pr_sc; + sc = p->psc; hdr = p->cmd_lst + slot * AHCI_CL_SIZE; if (cfis[2] == ATA_WRITE_FPDMA_QUEUED || cfis[2] == ATA_READ_FPDMA_QUEUED) @@ -1317,9 +1279,9 @@ if (ncq) { p->sact &= ~(1 << slot); - ahci_write_fis_sdb(p, slot, tfd); + ahci_send_fis_sdb(p, slot, tfd); } else - ahci_write_fis_d2h(p, slot, cfis, tfd); + ahci_send_fis_d2h(p, slot, cfis, tfd); out: pthread_mutex_unlock(&sc->mtx); DPRINTF("%s exit\n", __func__); @@ -1339,11 +1301,11 @@ DPRINTF("%s %d\n", __func__, err); aior = br->br_param; - p = aior->io_pr; + p = aior->io_port; cfis = aior->cfis; slot = aior->slot; pending = aior->prdtl; - sc = p->pr_sc; + sc = p->psc; hdr = p->cmd_lst + aior->slot * AHCI_CL_SIZE; pthread_mutex_lock(&sc->mtx); @@ -1369,7 +1331,7 @@ } cfis[4] = (cfis[4] & ~7) | ATA_I_CMD | ATA_I_IN; - ahci_write_fis_d2h(p, slot, cfis, tfd); + ahci_send_fis_d2h(p, slot, cfis, tfd); out: pthread_mutex_unlock(&sc->mtx); @@ -1377,27 +1339,27 @@ } static void -pci_ahci_ioreq_init(struct ahci_port *pr) +pci_ahci_ioreq_init(struct ahci_port *p) { - struct ahci_ioreq *vr; + struct ahci_ioreq *aior; int i; - pr->ioqsz = blockif_queuesz(pr->bctx); - pr->ioreq = calloc(pr->ioqsz, sizeof(struct ahci_ioreq)); - STAILQ_INIT(&pr->iofhd); + p->ioqsz = blockif_queuesz(p->bctx); + p->ioreq = calloc(p->ioqsz, sizeof(struct ahci_ioreq)); + STAILQ_INIT(&p->iofhd); /* * Add all i/o request entries to the free queue */ - for (i = 0; i < pr->ioqsz; i++) { - vr = &pr->ioreq[i]; - vr->io_pr = pr; - if (!pr->atapi) - vr->io_req.br_callback = ata_ioreq_cb; + for (i = 0; i < p->ioqsz; i++) { + aior = &p->ioreq[i]; + aior->io_port = p; + if (!p->atapi) + aior->io_req.br_callback = ata_ioreq_cb; else - vr->io_req.br_callback = atapi_ioreq_cb; - vr->io_req.br_param = vr; - STAILQ_INSERT_TAIL(&pr->iofhd, vr, io_list); + aior->io_req.br_callback = atapi_ioreq_cb; + aior->io_req.br_param = aior; + STAILQ_INSERT_TAIL(&p->iofhd, aior, io_list); } } @@ -1455,7 +1417,7 @@ } sc->port[i].bctx = bctxt; - sc->port[i].pr_sc = sc; + sc->port[i].psc = sc; /* * Allocate blockif request structures and add them * to the free list