From owner-p4-projects@FreeBSD.ORG Sun May 24 16:18:39 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 166AE1065674; Sun, 24 May 2009 16:18:39 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CABAB106564A for ; Sun, 24 May 2009 16:18:38 +0000 (UTC) (envelope-from mav@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id B88EE8FC1E for ; Sun, 24 May 2009 16:18:38 +0000 (UTC) (envelope-from mav@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n4OGIcmx061464 for ; Sun, 24 May 2009 16:18:38 GMT (envelope-from mav@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n4OGIcSw061462 for perforce@freebsd.org; Sun, 24 May 2009 16:18:38 GMT (envelope-from mav@freebsd.org) Date: Sun, 24 May 2009 16:18:38 GMT Message-Id: <200905241618.n4OGIcSw061462@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to mav@freebsd.org using -f From: Alexander Motin To: Perforce Change Reviews Cc: Subject: PERFORCE change 162653 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 24 May 2009 16:18:40 -0000 http://perforce.freebsd.org/chv.cgi?CH=162653 Change 162653 by mav@mav_mavbook on 2009/05/24 16:18:04 Add byte-order swap for ATA_IDENTIFY command result. Affected files ... .. //depot/projects/scottl-camlock/src/sys/cam/ata/ata_xpt.c#2 edit Differences ... ==== //depot/projects/scottl-camlock/src/sys/cam/ata/ata_xpt.c#2 (text+ko) ==== @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -183,6 +184,50 @@ } static void +bswap(int8_t *buf, int len) +{ + u_int16_t *ptr = (u_int16_t*)(buf + len); + + while (--ptr >= (u_int16_t*)buf) + *ptr = ntohs(*ptr); +} + +static void +btrim(int8_t *buf, int len) +{ + int8_t *ptr; + + for (ptr = buf; ptr < buf+len; ++ptr) + if (!*ptr || *ptr == '_') + *ptr = ' '; + for (ptr = buf + len - 1; ptr >= buf && *ptr == ' '; --ptr) + *ptr = 0; +} + +static void +bpack(int8_t *src, int8_t *dst, int len) +{ + int i, j, blank; + + for (i = j = blank = 0 ; i < len; i++) { + if (blank && src[i] == ' ') continue; + if (blank && src[i] != ' ') { + dst[j++] = src[i]; + blank = 0; + continue; + } + if (src[i] == ' ') { + blank = 1; + if (i == 0) + continue; + } + dst[j++] = src[i]; + } + if (j < len) + dst[j] = 0x00; +} + +static void probe_periph_init() { } @@ -438,10 +483,30 @@ { if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) { struct ata_params *ident_buf; + int16_t *ptr; path->device->flags |= CAM_DEV_INQUIRY_DATA_VALID; ident_buf = &path->device->ident_data; + for (ptr = (int16_t *)ident_buf; + ptr < (int16_t *)ident_buf + sizeof(struct ata_params)/2; ptr++) { + *ptr = le16toh(*ptr); + } + if (strncmp(ident_buf->model, "FX", 2) && + strncmp(ident_buf->model, "NEC", 3) && + strncmp(ident_buf->model, "Pioneer", 7) && + strncmp(ident_buf->model, "SHARP", 5)) { + bswap(ident_buf->model, sizeof(ident_buf->model)); + bswap(ident_buf->revision, sizeof(ident_buf->revision)); + bswap(ident_buf->serial, sizeof(ident_buf->serial)); + } + btrim(ident_buf->model, sizeof(ident_buf->model)); + bpack(ident_buf->model, ident_buf->model, sizeof(ident_buf->model)); + btrim(ident_buf->revision, sizeof(ident_buf->revision)); + bpack(ident_buf->revision, ident_buf->revision, sizeof(ident_buf->revision)); + btrim(ident_buf->serial, sizeof(ident_buf->serial)); + bpack(ident_buf->serial, ident_buf->serial, sizeof(ident_buf->serial)); + scsi_find_quirk(path->device); ata_devise_transport(path);