Date: Sat, 17 Mar 2012 09:56:10 +0100 From: Pawel Jakub Dawidek <pjd@FreeBSD.org> To: Grzegorz Bernacki <gber@FreeBSD.org> Cc: svn-src-projects@freebsd.org, src-committers@freebsd.org Subject: Re: svn commit: r233073 - projects/nand/sys/geom Message-ID: <20120317085609.GD1340@garage.freebsd.pl> In-Reply-To: <201203170323.q2H3NDCs048073@svn.freebsd.org> References: <201203170323.q2H3NDCs048073@svn.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
--lkTb+7nhmha7W+c3 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Mar 17, 2012 at 03:23:13AM +0000, Grzegorz Bernacki wrote: > Author: gber > Date: Sat Mar 17 03:23:13 2012 > New Revision: 233073 > URL: http://svn.freebsd.org/changeset/base/233073 >=20 > Log: > Add changes required for proper working of NAND chip geom devices. Hmm, adding two new BIO types is a big deal. Is there an ongoing discussion somewhere about this that I'm not aware of? What's the difference between BIO_READOOB/BIO_WRITEOOB and BIO_READ/BIO_WRITE exactly? Also, instead of adding nand-specific ioctls why not to create dedicated GEOM NAND class and use class ioctl method to implement those? > Obtained from: Semihalf > Supported by: FreeBSD Foundation, Juniper Networks >=20 > Modified: > projects/nand/sys/geom/geom.h > projects/nand/sys/geom/geom_dev.c > projects/nand/sys/geom/geom_disk.c > projects/nand/sys/geom/geom_disk.h > projects/nand/sys/geom/geom_io.c > projects/nand/sys/geom/geom_slice.c >=20 > Modified: projects/nand/sys/geom/geom.h > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > --- projects/nand/sys/geom/geom.h Sat Mar 17 03:18:28 2012 (r233072) > +++ projects/nand/sys/geom/geom.h Sat Mar 17 03:23:13 2012 (r233073) > @@ -309,6 +309,8 @@ struct bio *g_alloc_bio(void); > void * g_read_data(struct g_consumer *cp, off_t offset, off_t length, in= t *error); > int g_write_data(struct g_consumer *cp, off_t offset, void *ptr, off_t l= ength); > int g_delete_data(struct g_consumer *cp, off_t offset, off_t length); > +void *g_read_oob(struct g_consumer *cp, off_t offset, off_t length, int = *error); > +int g_write_oob(struct g_consumer *cp, off_t offset, void *ptr, off_t le= ngth); > void g_print_bio(struct bio *bp); > =20 > /* geom_kern.c / geom_kernsim.c */ >=20 > Modified: projects/nand/sys/geom/geom_dev.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > --- projects/nand/sys/geom/geom_dev.c Sat Mar 17 03:18:28 2012 (r233072) > +++ projects/nand/sys/geom/geom_dev.c Sat Mar 17 03:23:13 2012 (r233073) > @@ -311,8 +311,10 @@ g_dev_ioctl(struct cdev *dev, u_long cmd > struct g_consumer *cp; > struct g_provider *pp; > struct g_kerneldump kd; > + struct nand_oob_request *nand_req; > off_t offset, length, chunk; > int i, error; > + void *buf; > u_int u; > =20 > gp =3D dev->si_drv1; > @@ -345,6 +347,16 @@ g_dev_ioctl(struct cdev *dev, u_long cmd > if (error =3D=3D 0 && *(u_int *)data =3D=3D 0) > error =3D ENOENT; > break; > + case DIOCNOOBSIZE: > + error =3D g_io_getattr("NAND::oobsize", cp, &i, data); > + if (error =3D=3D 0 && *(u_int *)data =3D=3D 0) > + error =3D ENOENT; > + break; > + case DIOCNBLKSIZE: > + error =3D g_io_getattr("NAND::blocksize", cp, &i, data); > + if (error =3D=3D 0 && *(u_int *)data =3D=3D 0) > + error =3D ENOENT; > + break; > case DIOCGFRONTSTUFF: > error =3D g_io_getattr("GEOM::frontstuff", cp, &i, data); > break; > @@ -396,6 +408,28 @@ g_dev_ioctl(struct cdev *dev, u_long cmd > break; > } > break; > + case DIOCNREADOOB: > + nand_req =3D (struct nand_oob_request *)data; > + > + buf =3D g_read_oob(cp, nand_req->offset, nand_req->length, > + &error); > + if (error) > + break; > + > + error =3D copyout(buf, nand_req->ubuf, nand_req->length); > + break; > + case DIOCNWRITEOOB: > + nand_req =3D (struct nand_oob_request *)data; > + > + buf =3D g_malloc(nand_req->length, M_WAITOK); > + error =3D copyin(nand_req->ubuf, buf, nand_req->length); > + > + if (error) > + break; > + > + error =3D g_write_oob(cp, nand_req->offset, buf, > + nand_req->length); > + break; > case DIOCGIDENT: > error =3D g_io_getattr("GEOM::ident", cp, &i, data); > break; >=20 > Modified: projects/nand/sys/geom/geom_disk.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > --- projects/nand/sys/geom/geom_disk.c Sat Mar 17 03:18:28 2012 (r233072) > +++ projects/nand/sys/geom/geom_disk.c Sat Mar 17 03:23:13 2012 (r233073) > @@ -368,6 +368,10 @@ g_disk_start(struct bio *bp) > break; > else if (g_handleattr_int(bp, "GEOM::fwheads", dp->d_fwheads)) > break; > + else if (g_handleattr_int(bp, "NAND::oobsize", dp->n_oobsize)) > + break; > + else if (g_handleattr_int(bp, "NAND::pagesize", dp->n_pagesize)) > + break; > else if (g_handleattr_off_t(bp, "GEOM::frontstuff", 0)) > break; > else if (g_handleattr_str(bp, "GEOM::ident", dp->d_ident)) >=20 > Modified: projects/nand/sys/geom/geom_disk.h > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > --- projects/nand/sys/geom/geom_disk.h Sat Mar 17 03:18:28 2012 (r233072) > +++ projects/nand/sys/geom/geom_disk.h Sat Mar 17 03:23:13 2012 (r233073) > @@ -86,6 +86,8 @@ struct disk { > u_int d_maxsize; > u_int d_stripeoffset; > u_int d_stripesize; > + u_int n_oobsize; > + u_int n_pagesize; > char d_ident[DISK_IDENT_SIZE]; > char d_descr[DISK_IDENT_SIZE]; > uint16_t d_hba_vendor; >=20 > Modified: projects/nand/sys/geom/geom_io.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > --- projects/nand/sys/geom/geom_io.c Sat Mar 17 03:18:28 2012 (r233072) > +++ projects/nand/sys/geom/geom_io.c Sat Mar 17 03:23:13 2012 (r233073) > @@ -289,11 +289,13 @@ g_io_check(struct bio *bp) > /* Fail if access counters dont allow the operation */ > switch(bp->bio_cmd) { > case BIO_READ: > + case BIO_READOOB: > case BIO_GETATTR: > if (cp->acr =3D=3D 0) > return (EPERM); > break; > case BIO_WRITE: > + case BIO_WRITEOOB: > case BIO_DELETE: > case BIO_FLUSH: > if (cp->acw =3D=3D 0) > @@ -759,6 +761,52 @@ g_delete_data(struct g_consumer *cp, off > return (error); > } > =20 > +void * > +g_read_oob(struct g_consumer *cp, off_t offset, off_t length, int *error) > +{ > + struct bio *bp; > + void *ptr; > + int errorc; > + > + bp =3D g_alloc_bio(); > + bp->bio_cmd =3D BIO_READOOB; > + bp->bio_done =3D NULL; > + bp->bio_offset =3D offset; > + bp->bio_length =3D length; > + ptr =3D g_malloc(length, M_WAITOK); > + bp->bio_data =3D ptr; > + g_io_request(bp, cp); > + errorc =3D biowait(bp, "groob"); > + if (error !=3D NULL) > + *error =3D errorc; > + > + g_destroy_bio(bp); > + if (errorc) { > + g_free(ptr); > + ptr =3D NULL; > + } > + > + return (ptr); > +} > + > +int > +g_write_oob(struct g_consumer *cp, off_t offset, void *ptr, off_t length) > +{ > + struct bio *bp; > + int error; > + > + bp =3D g_alloc_bio(); > + bp->bio_cmd =3D BIO_WRITEOOB; > + bp->bio_done =3D NULL; > + bp->bio_offset =3D offset; > + bp->bio_length =3D length; > + bp->bio_data =3D ptr; > + g_io_request(bp, cp); > + error =3D biowait(bp, "gwoob"); > + g_destroy_bio(bp); > + return (error); > +} > + > void > g_print_bio(struct bio *bp) > { >=20 > Modified: projects/nand/sys/geom/geom_slice.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > --- projects/nand/sys/geom/geom_slice.c Sat Mar 17 03:18:28 2012 (r233072) > +++ projects/nand/sys/geom/geom_slice.c Sat Mar 17 03:23:13 2012 (r233073) > @@ -215,7 +215,9 @@ g_slice_start(struct bio *bp) > gsl =3D &gsp->slices[idx]; > switch(bp->bio_cmd) { > case BIO_READ: > + case BIO_READOOB: > case BIO_WRITE: > + case BIO_WRITEOOB: > case BIO_DELETE: > if (bp->bio_offset > gsl->length) { > g_io_deliver(bp, EINVAL); /* XXX: EWHAT ? */ > @@ -233,8 +235,10 @@ g_slice_start(struct bio *bp) > if (t + bp->bio_length <=3D ghp->offset) > continue; > switch(bp->bio_cmd) { > - case BIO_READ: idx =3D ghp->ract; break; > - case BIO_WRITE: idx =3D ghp->wact; break; > + case BIO_READ: > + case BIO_READOOB: idx =3D ghp->ract; break; > + case BIO_WRITE: > + case BIO_WRITEOOB: idx =3D ghp->wact; break; > case BIO_DELETE: idx =3D ghp->dact; break; > } > switch(idx) { --=20 Pawel Jakub Dawidek http://www.wheelsystems.com FreeBSD committer http://www.FreeBSD.org Am I Evil? Yes, I Am! http://tupytaj.pl --lkTb+7nhmha7W+c3 Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.18 (FreeBSD) iEYEARECAAYFAk9kUagACgkQForvXbEpPzROdACfaRjm9/rLouEW1w78GdX0rmYi XGEAn1+5Y4v3qTZnsItnV3o5SdQqX8P0 =UCjp -----END PGP SIGNATURE----- --lkTb+7nhmha7W+c3--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120317085609.GD1340>