| @@ -1,34 +1,34 @@ | | | @@ -1,34 +1,34 @@ |
1 | /* $NetBSD: vioscsi.c,v 1.19.2.1 2019/07/15 08:23:23 martin Exp $ */ | | 1 | /* $NetBSD: vioscsi.c,v 1.19.2.2 2020/07/13 14:13:12 martin Exp $ */ |
2 | /* $OpenBSD: vioscsi.c,v 1.3 2015/03/14 03:38:49 jsg Exp $ */ | | 2 | /* $OpenBSD: vioscsi.c,v 1.3 2015/03/14 03:38:49 jsg Exp $ */ |
3 | | | 3 | |
4 | /* | | 4 | /* |
5 | * Copyright (c) 2013 Google Inc. | | 5 | * Copyright (c) 2013 Google Inc. |
6 | * | | 6 | * |
7 | * Permission to use, copy, modify, and distribute this software for any | | 7 | * Permission to use, copy, modify, and distribute this software for any |
8 | * purpose with or without fee is hereby granted, provided that the above | | 8 | * purpose with or without fee is hereby granted, provided that the above |
9 | * copyright notice and this permission notice appear in all copies. | | 9 | * copyright notice and this permission notice appear in all copies. |
10 | * | | 10 | * |
11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | | 11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | | 12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | | 13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | | 14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
15 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | | 15 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
16 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | | 16 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
17 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | | 17 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
18 | */ | | 18 | */ |
19 | | | 19 | |
20 | #include <sys/cdefs.h> | | 20 | #include <sys/cdefs.h> |
21 | __KERNEL_RCSID(0, "$NetBSD: vioscsi.c,v 1.19.2.1 2019/07/15 08:23:23 martin Exp $"); | | 21 | __KERNEL_RCSID(0, "$NetBSD: vioscsi.c,v 1.19.2.2 2020/07/13 14:13:12 martin Exp $"); |
22 | | | 22 | |
23 | #include <sys/param.h> | | 23 | #include <sys/param.h> |
24 | #include <sys/systm.h> | | 24 | #include <sys/systm.h> |
25 | #include <sys/device.h> | | 25 | #include <sys/device.h> |
26 | #include <sys/bus.h> | | 26 | #include <sys/bus.h> |
27 | #include <sys/buf.h> | | 27 | #include <sys/buf.h> |
28 | #include <sys/module.h> | | 28 | #include <sys/module.h> |
29 | | | 29 | |
30 | #include <dev/pci/pcidevs.h> | | 30 | #include <dev/pci/pcidevs.h> |
31 | #include <dev/pci/pcireg.h> | | 31 | #include <dev/pci/pcireg.h> |
32 | #include <dev/pci/pcivar.h> | | 32 | #include <dev/pci/pcivar.h> |
33 | | | 33 | |
34 | #include <dev/pci/vioscsireg.h> | | 34 | #include <dev/pci/vioscsireg.h> |
| @@ -188,27 +188,27 @@ vioscsi_attach(device_t parent, device_t | | | @@ -188,27 +188,27 @@ vioscsi_attach(device_t parent, device_t |
188 | adapt->adapt_max_periph = adapt->adapt_openings; | | 188 | adapt->adapt_max_periph = adapt->adapt_openings; |
189 | adapt->adapt_request = vioscsi_scsipi_request; | | 189 | adapt->adapt_request = vioscsi_scsipi_request; |
190 | adapt->adapt_minphys = minphys; | | 190 | adapt->adapt_minphys = minphys; |
191 | | | 191 | |
192 | /* | | 192 | /* |
193 | * Fill in the scsipi_channel. | | 193 | * Fill in the scsipi_channel. |
194 | */ | | 194 | */ |
195 | memset(chan, 0, sizeof(*chan)); | | 195 | memset(chan, 0, sizeof(*chan)); |
196 | chan->chan_adapter = adapt; | | 196 | chan->chan_adapter = adapt; |
197 | chan->chan_bustype = &scsi_bustype; | | 197 | chan->chan_bustype = &scsi_bustype; |
198 | chan->chan_channel = 0; | | 198 | chan->chan_channel = 0; |
199 | chan->chan_ntargets = MIN(max_target, 16); /* cap reasonably */ | | 199 | chan->chan_ntargets = MIN(max_target, 16); /* cap reasonably */ |
200 | chan->chan_nluns = MIN(max_lun, 1024); /* cap reasonably */ | | 200 | chan->chan_nluns = MIN(max_lun, 1024); /* cap reasonably */ |
201 | chan->chan_id = 0; | | 201 | chan->chan_id = max_target; |
202 | chan->chan_flags = SCSIPI_CHAN_NOSETTLE; | | 202 | chan->chan_flags = SCSIPI_CHAN_NOSETTLE; |
203 | | | 203 | |
204 | config_found(self, &sc->sc_channel, scsiprint); | | 204 | config_found(self, &sc->sc_channel, scsiprint); |
205 | return; | | 205 | return; |
206 | | | 206 | |
207 | err: | | 207 | err: |
208 | if (qsize > 0) | | 208 | if (qsize > 0) |
209 | vioscsi_free_reqs(sc, vsc); | | 209 | vioscsi_free_reqs(sc, vsc); |
210 | | | 210 | |
211 | for (i=0; i < __arraycount(sc->sc_vqs); i++) { | | 211 | for (i=0; i < __arraycount(sc->sc_vqs); i++) { |
212 | if (sc->sc_vqs[i].vq_num > 0) | | 212 | if (sc->sc_vqs[i].vq_num > 0) |
213 | virtio_free_vq(vsc, &sc->sc_vqs[i]); | | 213 | virtio_free_vq(vsc, &sc->sc_vqs[i]); |
214 | } | | 214 | } |
| @@ -312,27 +312,27 @@ vioscsi_scsipi_request(struct scsipi_cha | | | @@ -312,27 +312,27 @@ vioscsi_scsipi_request(struct scsipi_cha |
312 | slot = vr - sc->sc_reqs; | | 312 | slot = vr - sc->sc_reqs; |
313 | | | 313 | |
314 | /* | | 314 | /* |
315 | * "The only supported format for the LUN field is: first byte set to | | 315 | * "The only supported format for the LUN field is: first byte set to |
316 | * 1, second byte set to target, third and fourth byte representing a | | 316 | * 1, second byte set to target, third and fourth byte representing a |
317 | * single level LUN structure, followed by four zero bytes." | | 317 | * single level LUN structure, followed by four zero bytes." |
318 | */ | | 318 | */ |
319 | if (periph->periph_target >= 256 || periph->periph_lun >= 16384 | | 319 | if (periph->periph_target >= 256 || periph->periph_lun >= 16384 |
320 | || periph->periph_target < 0 || periph->periph_lun < 0) { | | 320 | || periph->periph_target < 0 || periph->periph_lun < 0) { |
321 | goto stuffup; | | 321 | goto stuffup; |
322 | } | | 322 | } |
323 | | | 323 | |
324 | req->lun[0] = 1; | | 324 | req->lun[0] = 1; |
325 | req->lun[1] = periph->periph_target - 1; | | 325 | req->lun[1] = periph->periph_target; |
326 | req->lun[2] = 0x40 | ((periph->periph_lun >> 8) & 0x3F); | | 326 | req->lun[2] = 0x40 | ((periph->periph_lun >> 8) & 0x3F); |
327 | req->lun[3] = periph->periph_lun & 0xFF; | | 327 | req->lun[3] = periph->periph_lun & 0xFF; |
328 | memset(req->lun + 4, 0, 4); | | 328 | memset(req->lun + 4, 0, 4); |
329 | DPRINTF(("%s: command %p for %d:%d at slot %d\n", __func__, | | 329 | DPRINTF(("%s: command %p for %d:%d at slot %d\n", __func__, |
330 | xs, periph->periph_target, periph->periph_lun, slot)); | | 330 | xs, periph->periph_target, periph->periph_lun, slot)); |
331 | | | 331 | |
332 | /* tag */ | | 332 | /* tag */ |
333 | switch (XS_CTL_TAGTYPE(xs)) { | | 333 | switch (XS_CTL_TAGTYPE(xs)) { |
334 | case XS_CTL_HEAD_TAG: | | 334 | case XS_CTL_HEAD_TAG: |
335 | req->task_attr = VIRTIO_SCSI_S_HEAD; | | 335 | req->task_attr = VIRTIO_SCSI_S_HEAD; |
336 | break; | | 336 | break; |
337 | | | 337 | |
338 | #if 0 /* XXX */ | | 338 | #if 0 /* XXX */ |