Megasas HBA Emulation
PATCH v5 3/3 megasas: LSI Megaraid SAS emulation
In reply to Hannes ReineckeThis patch adds an emulation for the LSI Megaraid SAS 8708EM2 HBA.
--- Makefile.objs | 1 + default-configs/pci.mak | 1 + hw/megasas.c | 1920 +++++++++++++++++++++++++++++++++++++++++++++++ hw/mfi.h | 1197 +++++++++++++++++++++++++++++ hw/pci_ids.h | 3 +- 5 files changed, 3121 insertions(+), 1 deletions(-) create mode 100644 hw/megasas.c create mode 100644 hw/mfi.h
Makefile.objs +1 -0
@@ -258,6 +258,7 @@ hw-obj-$(CONFIG_AHCI) += ide/ich.o # SCSI layer hw-obj-$(CONFIG_LSI_SCSI_PCI) += lsi53c895a.o +hw-obj-$(CONFIG_MEGASAS_SCSI_PCI) += megasas.o hw-obj-$(CONFIG_ESP) += esp.o hw-obj-y += dma-helpers.o sysbus.o isa-bus.o
default-configs/pci.mak +1 -0
@@ -9,6 +9,7 @@ CONFIG_EEPRO100_PCI=y CONFIG_PCNET_PCI=y CONFIG_PCNET_COMMON=y CONFIG_LSI_SCSI_PCI=y +CONFIG_MEGASAS_SCSI_PCI=y CONFIG_RTL8139_PCI=y CONFIG_E1000_PCI=y CONFIG_IDE_CORE=y
hw/megasas.c new file +1920 -0
1,920 lines not on this page · raw message
hw/mfi.h new file +1197 -0
1,066 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.3.4
Part of the diff is not shown here. View the raw message.
v5 cover Megasas HBA Emulation
Hi all,
after getting various feedback from Paolo, Stefan, and Alexander I've respun the patches.
Chances since the previous version:
- iov: Update parameter usage in iov_(to|from)_buf() Updated description for the first patch and clarified the usage Renamed arguments for io_XXX for clarification
- scsi: Add 'hba_private' to SCSIRequest
Kept 'tag' for tracing and just add 'hba_private' as an additional field as per request from Paolo
- megasas: checkpatch.pl fixes and update to work with the changed interface in scsi_req_new(). Also included the suggested fixes from Alex.
Hannes Reinecke (3):
iov: Update parameter usage in iov_(to|from)_buf()
scsi: Add 'hba_private' to SCSIRequest
megasas: LSI Megaraid SAS emulation
Makefile.objs | 1 + default-configs/pci.mak | 1 + hw/esp.c | 2 +- hw/lsi53c895a.c | 22 +- hw/megasas.c | 1920 +++++++++++++++++++++++++++++++++++++++++++++++ hw/mfi.h | 1197 +++++++++++++++++++++++++++++ hw/pci_ids.h | 3 +- hw/scsi-bus.c | 9 +- hw/scsi-disk.c | 4 +- hw/scsi-generic.c | 5 +- hw/scsi.h | 10 +- hw/spapr_vscsi.c | 29 +- hw/usb-msd.c | 9 +- hw/virtio-net.c | 2 +- hw/virtio-serial-bus.c | 2 +- iov.c | 49 +- iov.h | 10 +- 17 files changed, 3192 insertions(+), 83 deletions(-) create mode 100644 hw/megasas.c create mode 100644 hw/mfi.h
Signature · 1 line
1.7.3.4
PATCH v5 1/3 iov: Update parameter usage in iov_(to|from)_buf()
iov_to_buf() has an 'offset' parameter, iov_from_buf() hasn't. This patch adds the missing parameter to iov_from_buf(). It also renames the 'offset' parameter to 'iov_off' to emphasize it's the offset into the iovec and not the buffer.
--- hw/virtio-net.c | 2 +- hw/virtio-serial-bus.c | 2 +- iov.c | 49 ++++++++++++++++++++++++++--------------------- iov.h | 10 ++++---- 4 files changed, 34 insertions(+), 29 deletions(-)
hw/virtio-net.c +1 -1
@@ -657,7 +657,7 @@ static ssize_t virtio_net_receive(VLANClientState *nc, const uint8_t *buf, size_/* copy in packet. ugh */ len =iov_from_buf (sg, elem.in_num, - buf + offset, size - offset); + buf + offset,0 , size - offset); total += len; offset += len;/* If buffers can't be merged, at this point we
hw/virtio-serial-bus.c +1 -1
@@ -103,7 +103,7 @@ static size_t write_to_port(VirtIOSerialPort *port, } len =iov_from_buf (elem.in_sg, elem.in_num, - buf + offset, size - offset); + buf + offset,0 , size - offset); offset += len;virtqueue_push (vq, &elem, len);
iov.c +27 -22
83 lines not on this page · raw message
iov.h +5 -5
@@ -12,8 +12,8 @@#include "qemu-common.h" -size_t iov_from_buf (struct iovec *iov,unsigned int iovcnt, -const void *buf,size_t size); -size_t iov_to_buf (const struct iovec *iov,const unsigned int iovcnt, -void *buf,size_t offset,size_t size); -size_t iov_size (const struct iovec *iov,const unsigned int iovcnt); +size_t iov_from_buf (struct iovec *iov,unsigned int iov_cnt, +const void *buf,size_t iov_off,size_t size); +size_t iov_to_buf (const struct iovec *iov,const unsigned int iov_cnt, +void *buf,size_t iov_off,size_t size); +size_t iov_size (const struct iovec *iov,const unsigned int iov_cnt);
Signature · 1 line
1.7.3.4
PATCH v5 2/3 scsi: Add 'hba_private' to SCSIRequest
'tag' is just an abstraction to identify the command from the driver. So we should make that explicit by replacing 'tag' with a driver-defined pointer 'hba_private'. This saves the lookup for driver handling several commands in parallel.
'tag' is still being kept for tracing purposes.
--- hw/esp.c | 2 +- hw/lsi53c895a.c | 22 ++++++++-------------- hw/scsi-bus.c | 9 ++++++--- hw/scsi-disk.c | 4 ++-- hw/scsi-generic.c | 5 +++-- hw/scsi.h | 10 +++++++--- hw/spapr_vscsi.c | 29 +++++++++-------------------- hw/usb-msd.c | 9 +-------- 8 files changed, 37 insertions(+), 53 deletions(-)
hw/esp.c +1 -1
@@ -244,7 +244,7 @@ static void do_busid_cmd(ESPState *s, uint8_t *buf, uint8_t busid)DPRINTF ("do_busid_cmd: busid 0x%x\n" , busid); lun = busid &7 ; - s->current_req =scsi_req_new (s->current_dev,0 , lun); + s->current_req =scsi_req_new (s->current_dev,0 , lun,NULL ); datalen =scsi_req_enqueue (s->current_req, buf); s->ti_size = datalen;if (datalen !=0 ) {
hw/lsi53c895a.c +8 -14
@@ -661,7 +661,7 @@ static lsi_request *lsi_find_by_tag(LSIState *s, uint32_t tag)static void lsi_request_cancelled (SCSIRequest *req) {LSIState *s =DO_UPCAST (LSIState, dev.qdev, req->bus->qbus.parent); -lsi_request *p; +lsi_request *p = req->hba_private;if (s->current && req == s->current->req) {scsi_req_unref (req);
@@ -670,7 +670,6 @@ static void lsi_request_cancelled(SCSIRequest *req)return ; } - p =lsi_find_by_tag (s, req->tag);if (p) {QTAILQ_REMOVE (&s->queue, p, next);scsi_req_unref (req);
@@ -680,18 +679,12 @@ static void lsi_request_cancelled(SCSIRequest *req)/* Record that data is available for a queued command. Returns zero if the device was reselected, nonzero if the IO is deferred. */ -static int lsi_queue_tag (LSIState *s,uint32_t tag,uint32_t len) +static int lsi_queue_req (LSIState *s,SCSIRequest *req,uint32_t len) { -lsi_request *p; - - p =lsi_find_by_tag (s, tag); -if (!p) { -BADF ("IO with unknown tag %d\n" , tag); -return 1 ; - } +lsi_request *p = req->hba_private;if (p->pending) { -BADF ("Multiple IO pending for tag %d\n" , tag); +BADF ("Multiple IO pending for request %p\n" , p); } p->pending = len;/* Reselect if waiting for it, or if reselection triggers an IRQ
@@ -743,9 +736,9 @@ static void lsi_transfer_data(SCSIRequest *req, uint32_t len)LSIState *s =DO_UPCAST (LSIState, dev.qdev, req->bus->qbus.parent);int out; -if (s->waiting ==1 || !s->current || req->tag != s->current->tag || +if (s->waiting ==1 || !s->current || req->hba_private != s->current || (lsi_irq_on_rsl (s) && !(s->scntl1 &LSI_SCNTL1_CON ))) { -if (lsi_queue_tag (s, req->tag, len)) { +if (lsi_queue_req (s, req, len)) {return ; } }
@@ -789,7 +782,8 @@ static void lsi_do_command(LSIState *s)assert (s->current ==NULL ); s->current =qemu_mallocz (sizeof (lsi_request)); s->current->tag = s->select_tag; - s->current->req =scsi_req_new (dev, s->current->tag, s->current_lun); + s->current->req =scsi_req_new (dev, s->current->tag, s->current_lun, + s->current); n =scsi_req_enqueue (s->current->req, buf);if (n) {
hw/scsi-bus.c +6 -3
@@ -131,7 +131,8 @@ int scsi_bus_legacy_handle_cmdline(SCSIBus *bus)return res; } -SCSIRequest *scsi_req_alloc (size_t size,SCSIDevice *d,uint32_t tag,uint32_t lun) +SCSIRequest *scsi_req_alloc (size_t size,SCSIDevice *d,uint32_t tag, +uint32_t lun,void *hba_private) {SCSIRequest *req;
@@ -141,14 +142,16 @@ SCSIRequest *scsi_req_alloc(size_t size, SCSIDevice *d, uint32_t tag, uint32_t l req->dev = d; req->tag = tag; req->lun = lun; + req->hba_private = hba_private; req->status =-1 ;trace_scsi_req_alloc (req->dev->id, req->lun, req->tag);return req; } -SCSIRequest *scsi_req_new (SCSIDevice *d,uint32_t tag,uint32_t lun) +SCSIRequest *scsi_req_new (SCSIDevice *d,uint32_t tag,uint32_t lun, +void *hba_private) { -return d->info->alloc_req (d, tag, lun); +return d->info->alloc_req (d, tag, lun, hba_private); }uint8_t *scsi_req_get_buf (SCSIRequest *req)
hw/scsi-disk.c +2 -2
@@ -81,13 +81,13 @@ static int scsi_handle_rw_error(SCSIDiskReq *r, int error, int type);static int scsi_disk_emulate_command (SCSIDiskReq *r,uint8_t *outbuf);static SCSIRequest *scsi_new_request (SCSIDevice *d,uint32_t tag, -uint32_t lun) +uint32_t lun,void *hba_private) {SCSIDiskState *s =DO_UPCAST (SCSIDiskState, qdev, d);SCSIRequest *req;SCSIDiskReq *r; - req =scsi_req_alloc (sizeof (SCSIDiskReq), &s->qdev, tag, lun); + req =scsi_req_alloc (sizeof (SCSIDiskReq), &s->qdev, tag, lun, hba_private); r =DO_UPCAST (SCSIDiskReq, req, req); r->iov.iov_base =qemu_blockalign (s->bs,SCSI_DMA_BUF_SIZE );return req;
hw/scsi-generic.c +3 -2
@@ -96,11 +96,12 @@ static int scsi_get_sense(SCSIRequest *req, uint8_t *outbuf, int len)return size; } -static SCSIRequest *scsi_new_request (SCSIDevice *d,uint32_t tag,uint32_t lun) +static SCSIRequest *scsi_new_request (SCSIDevice *d,uint32_t tag,uint32_t lun, +void *hba_private) {SCSIRequest *req; - req =scsi_req_alloc (sizeof (SCSIGenericReq), d, tag, lun); + req =scsi_req_alloc (sizeof (SCSIGenericReq), d, tag, lun, hba_private);return req; }
hw/scsi.h +7 -3
@@ -43,6 +43,7 @@ struct SCSIRequest { } cmd;BlockDriverAIOCB *aiocb;bool enqueued; +void *hba_private;QTAILQ_ENTRY (SCSIRequest) next; };
@@ -67,7 +68,8 @@ struct SCSIDeviceInfo {DeviceInfo qdev;scsi_qdev_initfn init;void (*destroy)(SCSIDevice *s); -SCSIRequest *(*alloc_req)(SCSIDevice *s,uint32_t tag,uint32_t lun); +SCSIRequest *(*alloc_req)(SCSIDevice *s,uint32_t tag,uint32_t lun, +void *hba_private);void (*free_req)(SCSIRequest *req);int32_t (*send_command)(SCSIRequest *req,uint8_t *buf);void (*read_data)(SCSIRequest *req);
@@ -138,8 +140,10 @@ extern const struct SCSISense sense_code_LUN_FAILURE;int scsi_build_sense (SCSISense sense,uint8_t *buf,int len,int fixed);int scsi_sense_valid (SCSISense sense); -SCSIRequest *scsi_req_alloc (size_t size,SCSIDevice *d,uint32_t tag,uint32_t lun); -SCSIRequest *scsi_req_new (SCSIDevice *d,uint32_t tag,uint32_t lun); +SCSIRequest *scsi_req_alloc (size_t size,SCSIDevice *d,uint32_t tag, +uint32_t lun,void *hba_private); +SCSIRequest *scsi_req_new (SCSIDevice *d,uint32_t tag,uint32_t lun, +void *hba_private);int32_t scsi_req_enqueue (SCSIRequest *req,uint8_t *buf);void scsi_req_free (SCSIRequest *req);SCSIRequest *scsi_req_ref (SCSIRequest *req);
hw/spapr_vscsi.c +9 -20
@@ -121,7 +121,7 @@ static struct vscsi_req *vscsi_get_req(VSCSIState *s)return NULL ; } -static void vscsi_put_req (VSCSIState *s,vscsi_req *req) +static void vscsi_put_req (vscsi_req *req) {if (req->sreq !=NULL ) {scsi_req_unref (req->sreq);
@@ -130,15 +130,6 @@ static void vscsi_put_req(VSCSIState *s, vscsi_req *req) req->active =0 ; } -static vscsi_req *vscsi_find_req (VSCSIState *s,SCSIRequest *req) -{ -uint32_t tag = req->tag; -if (tag >=VSCSI_REQ_LIMIT || !s->reqs[tag].active) { -return NULL ; - } -return &s->reqs[tag]; -} -static void vscsi_decode_id_lun (uint64_t srp_lun,int *id,int *lun) {/* XXX Figure that one out properly ! This is crackpot */
@@ -454,7 +445,7 @@ static void vscsi_send_request_sense(VSCSIState *s, vscsi_req *req)if (n) { req->senselen = n;vscsi_send_rsp (s, req,CHECK_CONDITION ,0 ,0 ); -vscsi_put_req (s, req); +vscsi_put_req (req);return ; }
@@ -483,7 +474,7 @@ static void vscsi_send_request_sense(VSCSIState *s, vscsi_req *req)static void vscsi_transfer_data (SCSIRequest *sreq,uint32_t len) {VSCSIState *s =DO_UPCAST (VSCSIState, vdev.qdev, sreq->bus->qbus.parent); -vscsi_req *req =vscsi_find_req (s, sreq); +vscsi_req *req = sreq->hba_private;uint8_t *buf;int rc =0 ;
@@ -530,8 +521,7 @@ static void vscsi_transfer_data(SCSIRequest *sreq, uint32_t len)/* Callback to indicate that the SCSI layer has completed a transfer. */ static void vscsi_command_complete (SCSIRequest *sreq,uint32_t status) { -VSCSIState *s =DO_UPCAST (VSCSIState, vdev.qdev, sreq->bus->qbus.parent); -vscsi_req *req =vscsi_find_req (s, sreq); +vscsi_req *req = sreq->hba_private;int32_t res_in =0 , res_out =0 ; dprintf("VSCSI: SCSI cmd complete, r=0x%x tag=0x%x status=0x%x, req=%p\n",
@@ -563,15 +553,14 @@ static void vscsi_command_complete(SCSIRequest *sreq, uint32_t status) } }vscsi_send_rsp (s, req,0 , res_in, res_out); -vscsi_put_req (s, req); +vscsi_put_req (req); }static void vscsi_request_cancelled (SCSIRequest *sreq) { -VSCSIState *s =DO_UPCAST (VSCSIState, vdev.qdev, sreq->bus->qbus.parent); -vscsi_req *req =vscsi_find_req (s, sreq); +vscsi_req *req = sreq->hba_private; -vscsi_put_req (s, req); +vscsi_put_req (req); }static void vscsi_process_login (VSCSIState *s,vscsi_req *req)
@@ -659,7 +648,7 @@ static int vscsi_queue_cmd(VSCSIState *s, vscsi_req *req) } req->lun = lun; - req->sreq =scsi_req_new (sdev, req->qtag, lun); + req->sreq =scsi_req_new (sdev, req->qtag, lun, req); n =scsi_req_enqueue (req->sreq, srp->cmd.cdb); dprintf("VSCSI: Queued command tag 0x%x CMD 0x%x ID %d LUN %d ret: %d\n",
@@ -858,7 +847,7 @@ static void vscsi_got_payload(VSCSIState *s, vscsi_crq *crq) }if (done) { -vscsi_put_req (s, req); +vscsi_put_req (req); } }
hw/usb-msd.c +1 -8
@@ -216,10 +216,6 @@ static void usb_msd_transfer_data(SCSIRequest *req, uint32_t len)MSDState *s =DO_UPCAST (MSDState, dev.qdev, req->bus->qbus.parent);USBPacket *p = s->packet; -if (req->tag != s->tag) { -fprintf (stderr,"usb-msd: Unexpected SCSI Tag 0x%x\n" , req->tag); - } -assert ((s->mode ==USB_MSDM_DATAOUT ) == (req->cmd.mode ==SCSI_XFER_TO_DEV )); s->scsi_len = len; s->scsi_buf =scsi_req_get_buf (req);
@@ -241,9 +237,6 @@ static void usb_msd_command_complete(SCSIRequest *req, uint32_t status)MSDState *s =DO_UPCAST (MSDState, dev.qdev, req->bus->qbus.parent);USBPacket *p = s->packet; -if (req->tag != s->tag) { -fprintf (stderr,"usb-msd: Unexpected SCSI Tag 0x%x\n" , req->tag); - }DPRINTF ("Command complete %d\n" , status); s->residue = s->data_len; s->result = status !=0 ;
@@ -387,7 +380,7 @@ static int usb_msd_handle_data(USBDevice *dev, USBPacket *p) s->tag, cbw.flags, cbw.cmd_len, s->data_len); s->residue =0 ; s->scsi_len =0 ; - s->req =scsi_req_new (s->scsi_dev, s->tag,0 ); + s->req =scsi_req_new (s->scsi_dev, s->tag,0 ,NULL );scsi_req_enqueue (s->req, cbw.cmd);/* ??? Should check that USB and SCSI data transfer directions match. */
Signature · 1 line
1.7.3.4
Re: [PATCH 2/3] scsi: Add 'hba_private' to SCSIRequest
Quoted 324 lines · Hannes Reinecke
'tag' is just an abstraction to identify the command from the driver. So we should make that explicit by replacing 'tag' with a driver-defined pointer '
hba_private'. This saves the lookup for driver handling several commands in parallel.
'tag' is still being kept for tracing purposes.Signed-off-by Hannes Reinecke<[email protected]>--- hw/esp.c | 2 +- hw/lsi53c895a.c | 22 ++++++++-------------- hw/scsi-bus.c | 9 ++++++--- hw/scsi-disk.c | 4 ++-- hw/scsi-generic.c | 5 +++-- hw/scsi.h | 10 +++++++--- hw/spapr_vscsi.c | 29 +++++++++-------------------- hw/usb-msd.c | 9 +-------- 8 files changed, 37 insertions(+), 53 deletions(-)hw/esp.c +1
-1@@ -244,7 +244,7 @@ static void do_busid_cmd(ESPState *s, uint8_t *buf, uint8_t busid)DPRINTF ("do_busid_cmd: busid 0x%x\n" , busid); lun = busid&7 ; - s->current_req =scsi_req_new (s->current_dev,0 , lun); + s->current_req =scsi_req_new (s->current_dev,0 , lun,NULL ); datalen =scsi_req_enqueue (s->current_req, buf); s->ti_size = datalen;if (datalen !=0 ) {hw/lsi53c895a.c +8
-14@@ -661,7 +661,7 @@ static lsi_request *lsi_find_by_tag(LSIState *s, uint32_t tag)static void lsi_request_cancelled (SCSIRequest *req) {LSIState *s =DO_UPCAST (LSIState, dev.qdev, req->bus->qbus.parent); -lsi_request *p; +lsi_request *p = req->hba_private;if (s->current&& req == s->current->req) {scsi_req_unref (req);@@ -670,7 +670,6 @@ static void lsi_request_cancelled(SCSIRequest *req)return ; } - p =lsi_find_by_tag (s, req->tag);if (p) {QTAILQ_REMOVE (&s->queue, p, next);scsi_req_unref (req);@@ -680,18 +679,12 @@ static void lsi_request_cancelled(SCSIRequest *req)/* Record that data is available for a queued command. Returns zero if the device was reselected, nonzero if the IO is deferred. */ -static int lsi_queue_tag (LSIState *s,uint32_t tag,uint32_t len) +static int lsi_queue_req (LSIState *s,SCSIRequest *req,uint32_t len) { -lsi_request *p; - - p =lsi_find_by_tag (s, tag); -if (!p) { -BADF ("IO with unknown tag %d\n" , tag); -return 1 ; - } +lsi_request *p = req->hba_private;if (p->pending) { -BADF ("Multiple IO pending for tag %d\n" , tag); +BADF ("Multiple IO pending for request %p\n" , p); } p->pending = len;/* Reselect if waiting for it, or if reselection triggers an IRQ @@ -743,9 +736,9 @@ static void lsi_transfer_data(SCSIRequest *req, uint32_t len)LSIState *s =DO_UPCAST (LSIState, dev.qdev, req->bus->qbus.parent);int out; -if (s->waiting ==1 || !s->current || req->tag != s->current->tag || +if (s->waiting ==1 || !s->current || req->hba_private != s->current || (lsi_irq_on_rsl (s)&& !(s->scntl1&LSI_SCNTL1_CON ))) { -if (lsi_queue_tag (s, req->tag, len)) { +if (lsi_queue_req (s, req, len)) {return ; } }@@ -789,7 +782,8 @@ static void lsi_do_command(LSIState *s)assert (s->current ==NULL ); s->current =qemu_mallocz (sizeof (lsi_request)); s->current->tag = s->select_tag; - s->current->req =scsi_req_new (dev, s->current->tag, s->current_lun); + s->current->req =scsi_req_new (dev, s->current->tag, s->current_lun, + s->current); n =scsi_req_enqueue (s->current->req, buf);if (n) {hw/scsi-bus.c +6
-3@@ -131,7 +131,8 @@ int scsi_bus_legacy_handle_cmdline(SCSIBus *bus)return res; } -SCSIRequest *scsi_req_alloc (size_t size,SCSIDevice *d,uint32_t tag,uint32_t lun) +SCSIRequest *scsi_req_alloc (size_t size,SCSIDevice *d,uint32_t tag, +uint32_t lun,void *hba_private) {SCSIRequest *req;@@ -141,14 +142,16 @@ SCSIRequest *scsi_req_alloc(size_t size, SCSIDevice *d, uint32_t tag, uint32_t l req->dev = d; req->tag = tag; req->lun = lun; + req->hba_private = hba_private; req->status =-1 ;trace_scsi_req_alloc (req->dev->id, req->lun, req->tag);return req; } -SCSIRequest *scsi_req_new (SCSIDevice *d,uint32_t tag,uint32_t lun) +SCSIRequest *scsi_req_new (SCSIDevice *d,uint32_t tag,uint32_t lun, +void *hba_private) { -return d->info->alloc_req (d, tag, lun); +return d->info->alloc_req (d, tag, lun, hba_private); }uint8_t *scsi_req_get_buf (SCSIRequest *req)hw/scsi-disk.c +2
-2@@ -81,13 +81,13 @@ static int scsi_handle_rw_error(SCSIDiskReq *r, int error, int type);static int scsi_disk_emulate_command (SCSIDiskReq *r,uint8_t *outbuf);static SCSIRequest *scsi_new_request (SCSIDevice *d,uint32_t tag, -uint32_t lun) +uint32_t lun,void *hba_private) {SCSIDiskState *s =DO_UPCAST (SCSIDiskState, qdev, d);SCSIRequest *req;SCSIDiskReq *r; - req =scsi_req_alloc (sizeof (SCSIDiskReq),&s->qdev, tag, lun); + req =scsi_req_alloc (sizeof (SCSIDiskReq),&s->qdev, tag, lun, hba_private); r =DO_UPCAST (SCSIDiskReq, req, req); r->iov.iov_base =qemu_blockalign (s->bs,SCSI_DMA_BUF_SIZE );return req;hw/scsi-generic.c +3
-2@@ -96,11 +96,12 @@ static int scsi_get_sense(SCSIRequest *req, uint8_t *outbuf, int len)return size; } -static SCSIRequest *scsi_new_request (SCSIDevice *d,uint32_t tag,uint32_t lun) +static SCSIRequest *scsi_new_request (SCSIDevice *d,uint32_t tag,uint32_t lun, +void *hba_private) {SCSIRequest *req; - req =scsi_req_alloc (sizeof (SCSIGenericReq), d, tag, lun); + req =scsi_req_alloc (sizeof (SCSIGenericReq), d, tag, lun, hba_private);return req; }hw/scsi.h +7
-3@@ -43,6 +43,7 @@ struct SCSIRequest { } cmd;BlockDriverAIOCB *aiocb;bool enqueued; +void *hba_private;QTAILQ_ENTRY (SCSIRequest) next; };@@ -67,7 +68,8 @@ struct SCSIDeviceInfo {DeviceInfo qdev;scsi_qdev_initfn init;void (*destroy)(SCSIDevice *s); -SCSIRequest *(*alloc_req)(SCSIDevice *s,uint32_t tag,uint32_t lun); +SCSIRequest *(*alloc_req)(SCSIDevice *s,uint32_t tag,uint32_t lun, +void *hba_private);void (*free_req)(SCSIRequest *req);int32_t (*send_command)(SCSIRequest *req,uint8_t *buf);void (*read_data)(SCSIRequest *req);@@ -138,8 +140,10 @@ extern const struct SCSISense sense_code_LUN_FAILURE;int scsi_build_sense (SCSISense sense,uint8_t *buf,int len,int fixed);int scsi_sense_valid (SCSISense sense); -SCSIRequest *scsi_req_alloc (size_t size,SCSIDevice *d,uint32_t tag,uint32_t lun); -SCSIRequest *scsi_req_new (SCSIDevice *d,uint32_t tag,uint32_t lun); +SCSIRequest *scsi_req_alloc (size_t size,SCSIDevice *d,uint32_t tag, +uint32_t lun,void *hba_private); +SCSIRequest *scsi_req_new (SCSIDevice *d,uint32_t tag,uint32_t lun, +void *hba_private);int32_t scsi_req_enqueue (SCSIRequest *req,uint8_t *buf);void scsi_req_free (SCSIRequest *req);SCSIRequest *scsi_req_ref (SCSIRequest *req);hw/spapr_vscsi.c +9
-20@@ -121,7 +121,7 @@ static struct vscsi_req *vscsi_get_req(VSCSIState *s)return NULL ; } -static void vscsi_put_req (VSCSIState *s,vscsi_req *req) +static void vscsi_put_req (vscsi_req *req) {if (req->sreq !=NULL ) {scsi_req_unref (req->sreq);@@ -130,15 +130,6 @@ static void vscsi_put_req(VSCSIState *s, vscsi_req *req) req->active =0 ; } -static vscsi_req *vscsi_find_req (VSCSIState *s,SCSIRequest *req) -{ -uint32_t tag = req->tag; -if (tag>=VSCSI_REQ_LIMIT || !s->reqs[tag].active) { -return NULL ; - } -return &s->reqs[tag]; -} -static void vscsi_decode_id_lun (uint64_t srp_lun,int *id,int *lun) {/* XXX Figure that one out properly ! This is crackpot */ @@ -454,7 +445,7 @@ static void vscsi_send_request_sense(VSCSIState *s, vscsi_req *req)if (n) { req->senselen = n;vscsi_send_rsp (s, req,CHECK_CONDITION ,0 ,0 ); -vscsi_put_req (s, req); +vscsi_put_req (req);return ; }@@ -483,7 +474,7 @@ static void vscsi_send_request_sense(VSCSIState *s, vscsi_req *req)static void vscsi_transfer_data (SCSIRequest *sreq,uint32_t len) {VSCSIState *s =DO_UPCAST (VSCSIState, vdev.qdev, sreq->bus->qbus.parent); -vscsi_req *req =vscsi_find_req (s, sreq); +vscsi_req *req = sreq->hba_private;uint8_t *buf;int rc =0 ;@@ -530,8 +521,7 @@ static void vscsi_transfer_data(SCSIRequest *sreq, uint32_t len)/* Callback to indicate that the SCSI layer has completed a transfer. */ static void vscsi_command_complete (SCSIRequest *sreq,uint32_t status) { -VSCSIState *s =DO_UPCAST (VSCSIState, vdev.qdev, sreq->bus->qbus.parent); -vscsi_req *req =vscsi_find_req (s, sreq); +vscsi_req *req = sreq->hba_private;int32_t res_in =0 , res_out =0 ; dprintf("VSCSI: SCSI cmd complete, r=0x%x tag=0x%x status=0x%x, req=%p\n",@@ -563,15 +553,14 @@ static void vscsi_command_complete(SCSIRequest *sreq, uint32_t status) } }vscsi_send_rsp (s, req,0 , res_in, res_out); -vscsi_put_req (s, req); +vscsi_put_req (req); }static void vscsi_request_cancelled (SCSIRequest *sreq) { -VSCSIState *s =DO_UPCAST (VSCSIState, vdev.qdev, sreq->bus->qbus.parent); -vscsi_req *req =vscsi_find_req (s, sreq); +vscsi_req *req = sreq->hba_private; -vscsi_put_req (s, req); +vscsi_put_req (req); }static void vscsi_process_login (VSCSIState *s,vscsi_req *req)@@ -659,7 +648,7 @@ static int vscsi_queue_cmd(VSCSIState *s, vscsi_req *req) } req->lun = lun; - req->sreq =scsi_req_new (sdev, req->qtag, lun); + req->sreq =scsi_req_new (sdev, req->qtag, lun, req); n =scsi_req_enqueue (req->sreq, srp->cmd.cdb); dprintf("VSCSI: Queued command tag 0x%x CMD 0x%x ID %d LUN %d ret: %d\n",@@ -858,7 +847,7 @@ static void vscsi_got_payload(VSCSIState *s, vscsi_crq *crq) }if (done) { -vscsi_put_req (s, req); +vscsi_put_req (req); } }hw/usb-msd.c +0
-7@@ -216,10 +216,6 @@ static void usb_msd_transfer_data(SCSIRequest *req, uint32_t len)MSDState *s =DO_UPCAST (MSDState, dev.qdev, req->bus->qbus.parent);USBPacket *p = s->packet; -if (req->tag != s->tag) { -fprintf (stderr,"usb-msd: Unexpected SCSI Tag 0x%x\n" , req->tag); - } -assert ((s->mode ==USB_MSDM_DATAOUT ) == (req->cmd.mode ==SCSI_XFER_TO_DEV )); s->scsi_len = len; s->scsi_buf =scsi_req_get_buf (req);@@ -241,9 +237,6 @@ static void usb_msd_command_complete(SCSIRequest *req, uint32_t status)MSDState *s =DO_UPCAST (MSDState, dev.qdev, req->bus->qbus.parent);USBPacket *p = s->packet; -if (req->tag != s->tag) { -fprintf (stderr,"usb-msd: Unexpected SCSI Tag 0x%x\n" , req->tag); - }DPRINTF ("Command complete %d\n" , status); s->residue = s->data_len; s->result = status !=0 ;
hw/usb-msd.c static int usb_msd_handle_data(USBDevice *dev, USBPacket *p) · line 386
Quoted 8 lines
hw/usb-msd.c +1
-1@@ -387,7 +380,7 @@ static int usb_msd_handle_data(USBDevice *dev, USBPacket *p) s->tag, cbw.flags, cbw.cmd_len, s->data_len); s->residue =0 ; s->scsi_len =0 ; - s->req =scsi_req_new (s->scsi_dev, s->tag,0 ); + s->req =scsi_req_new (s->scsi_dev, s->tag,0 ,NULL );scsi_req_enqueue (s->req, cbw.cmd);/* ??? Should check that USB and SCSI data transfer directions match. */
Have a nice weekend.
Paolo
Re: [PATCH 1/3] iov: Update parameter usage in iov_(to|from)_buf()
In reply to Hannes ReineckeQuoted 6 lines · Hannes Reinecke
iov_to_buf()has an 'offset' parameter,iov_from_buf()hasn't. This patch adds the missing parameter toiov_from_buf(). It also renames the 'offset' parameter to 'iov_off' to emphasize it's the offset into the iovec and not the buffer.Signed-off-by Hannes Reinecke <[email protected]>
Alex
Re: [PATCH 3/3] megasas: LSI Megaraid SAS emulation
In reply to Hannes ReineckeQuoted 1 line · Hannes Reinecke
This patch adds an emulation for the LSI Megaraid SAS 8708EM2 HBA.
Have you tried to execute the current version of megasas and actually do something with it? I just booted up openSUSE 11.4 rescue from DVD with a megasas adapter that contained a raw file backed by tmpfs. Creating a partition worked fine, but when running mkfs.ext3 and mounting afterwards, the mount fails saying there is no ext3 on the disk.
Sounds like data corruption to me :). I know that this used to work a while back, so it might be a regression recently?
Alex
Re: [PATCH 3/3] megasas: LSI Megaraid SAS emulation
Quoted 5 lines · Alexander Graf
Quoted 1 line · Hannes Reinecke
This patch adds an emulation for the LSI Megaraid SAS 8708EM2 HBA.
Quoted 9 lines
Have you tried to execute the current version of megasas and actually do something with it? I just booted up openSUSE 11.4 rescue from DVD with a megasas adapter that contained a raw file backed by tmpfs. Creating a partition worked fine, but when running mkfs.ext3 and mounting afterwards, the mount fails saying there is no ext3 on the disk.
Sounds like data corruption to me :). I know that this used to work a while back, so it might be a regression recently?
It worked here, in the sense that I've booted up an existing openSUSE 11.4 installation. But I wouldn't be surprised if the degradation to use bounce-buffers has some flaws.
My guess here is that we have problems when the transfersizes larger as the internal bounce buffer.
(I probably should be putting in some more references to 'bounce buffers' here to alert people that using bounce buffers in SCSI is the best way of killing performance) (And no, I will not getting into another dog-fight with Paul B. here.
Virtio can do without bounce buffers. AHCI can. So I fail to see why SCSI has to rely on bounce buffers.)
But enough of this, Yeah, bugfixing is needed here. I see what I can do.
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke zSeries & Storage [email protected] +49 911 74053 688 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: Markus Rex, HRB 16746 (AG Nürnberg)
Re: [PATCH 3/3] megasas: LSI Megaraid SAS emulation
Am 02.07.2011 um 15:50 schrieb Hannes Reinecke <[email protected]>:
Quoted 12 lines · Alexander Graf
Quoted 11 lines · Hannes Reinecke
Quoted 2 lines
This patch adds an emulation for the LSI Megaraid SAS 8708EM2 HBA.
Have you tried to execute the current version of megasas and actually do something with it? I just booted up openSUSE 11.4 rescue from DVD with a megasas adapter that contained a raw file backed by tmpfs. Creating a partition worked fine, but when running mkfs.ext3 and mounting afterwards, the mount fails saying there is no ext3 on the disk.
Quoted 6 lines
Quoted 3 lines
Sounds like data corruption to me :). I know that this used to work a while back, so it might be a regression recently?
It worked here, in the sense that I've booted up an existing openSUSE 11.4 installation. But I wouldn't be surprised if the degradation to use bounce-buffers has some flaws.
My guess here is that we have problems when the transfersizes larger as the internal bounce buffer.
Ah, might be a good idea to have some check for that. Just assert() out when the bounce buffer is too small - or at least tell the user about it. Can the iov functions tell you if you exceed the write/read side?
Quoted 4 lines
(I probably should be putting in some more references to 'bounce buffers' here to alert people that using bounce buffers in SCSI is the best way of killing performance) (And no, I will not getting into another dog-fight with Paul B. here.
Virtio can do without bounce buffers. AHCI can. So I fail to see why SCSI has to rely on bounce buffers.)
My hope is that by approaching this incrementally, we can move to a 0-copy approach later on. But for now, let's focus on getting the device emulation part well working an in.
Quoted 2 lines
But enough of this, Yeah, bugfixing is needed here. I see what I can do.
Thanks :)
Alex
Quoted 1 line
Re: [Qemu-devel] [PATCH 3/3] megasas: LSI Megaraid SAS emulation
In reply to Hannes ReineckeQuoted 39 lines · Hannes Reinecke
hw/megasas.c new file +39
-0+static void megasas_mmio_writel (void *opaque,target_phys_addr_t addr, + uint32_t val) +{ + MPTState *s = opaque; + target_phys_addr_t frame_addr; + uint32_t frame_count; + int i; + + DPRINTF_REG("writel mmio %lx: %x\n", (unsigned long)addr, val); + + switch (addr) { + case MFI_IDB: + if (val & MFI_FWINIT_ABORT) { + /* Abort all pending cmds */ + for (i = 0; i <= s->fw_cmds; i++) { + megasas_abort_command(&s->frames[i]); + } + } + if (val & MFI_FWINIT_READY) { + /* move to FW READY */ + megasas_soft_reset(s); + } + if (val & MFI_FWINIT_MFIMODE) { + /* discard MFIs */ + } + break; + case MFI_OMSK: + s->intr_mask = val; + if (!MEGASAS_INTR_ENABLED(s)) { + qemu_irq_lower(s->dev.irq[0]); + } + break; + case MFI_ODCR0: + /* Update reply queue pointer */ + DPRINTF_QUEUE("Update reply queue head %x busy %d\n", + s->reply_queue_index, s->busy); + stl_phys(s->producer_pa, s->reply_queue_index); + s->doorbell = 0; + qemu_irq_lower(s->dev.irq[0]);
hw/megasas.c line 1624
Quoted 10 lines
hw/megasas.c new file +10
-0+ break; + case MFI_IQPH: + s->frame_hi = val; + break; + case MFI_IQPL: + case MFI_IQP: + /* Received MFI frame address */ + frame_addr = (val & ~0xFF); + /* Add possible 64 bit offset */ + frame_addr |= (uint64_t)s->frame_hi;
Is this missing << 32 before ORing the high bits?
hw/megasas.c line 1813
Quoted 5 lines
hw/megasas.c new file +5
-0+static int megasas_scsi_uninit (PCIDevice *d) +{ + MPTState *s = DO_UPCAST(MPTState, dev, d); + + cpu_unregister_io_memory(s->mmio_io_addr);
Need to unregister io_addr and queue_addr.
Quoted 17 lines
hw/megasas.c new file +17
-0+ + return 0; +} + +static const struct SCSIBusOps megasas_scsi_ops = { + .transfer_data = megasas_xfer_complete, + .complete = megasas_command_complete, + .cancel = megasas_command_cancel, +}; + +static int megasas_scsi_init (PCIDevice *dev) +{ + MPTState *s = DO_UPCAST(MPTState, dev, dev); + uint8_t *pci_conf; + int i; + + pci_conf = s->dev.config;
hw/megasas.c line 1840
Quoted 10 lines
hw/megasas.c new file +10
-0+ + /* PCI Vendor ID (word) */ + pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_LSI_LOGIC); + /* PCI device ID (word) */ + pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_LSI_SAS1078); + /* PCI subsystem ID */ + pci_set_word(&pci_conf[PCI_SUBSYSTEM_VENDOR_ID], 0x1000); + pci_set_word(&pci_conf[PCI_SUBSYSTEM_ID], 0x1013); + /* PCI base class code */ + pci_config_set_class(pci_conf, PCI_CLASS_STORAGE_RAID);
PCIDeviceInfo now has vendor_id, device_id, and other fields. These values can be set in the megasas_info definition below.
Quoted 5 lines
hw/megasas.c new file +5
-0+ + /* PCI latency timer = 0 */ + pci_conf[0x0d] = 0; + /* Interrupt pin 1 */ + pci_conf[0x3d] = 0x01;
hw/megasas.c line 1855
Quoted 10 lines
hw/megasas.c new file +10
-0+ + s->mmio_io_addr = cpu_register_io_memory(megasas_mmio_readfn, + megasas_mmio_writefn, s, + DEVICE_NATIVE_ENDIAN); + s->io_addr = cpu_register_io_memory(megasas_io_readfn, + megasas_io_writefn, s, + DEVICE_NATIVE_ENDIAN); + s->queue_addr = cpu_register_io_memory(megasas_queue_readfn, + megasas_queue_writefn, s, + DEVICE_NATIVE_ENDIAN);
Should these be little-endian?
Quoted 27 lines
+ pci_register_bar((struct PCIDevice *)s, 0,
0x40000,
+PCI_BASE_ADDRESS_SPACE_MEMORY,megasas_mmio_mapfunc);
+ pci_register_bar((struct PCIDevice *)s, 2, 256,
+PCI_BASE_ADDRESS_SPACE_IO,megasas_io_mapfunc);
+ pci_register_bar((struct PCIDevice *)s, 3,0x40000,
+PCI_BASE_ADDRESS_SPACE_MEMORY,megasas_queue_mapfunc);
+ if (s->fw_sge>=MEGASAS_MAX_SGE-MFI_PASS_FRAME_SIZE) {
+ s->fw_sge =MEGASAS_MAX_SGE-MFI_PASS_FRAME_SIZE;
+ } else if (s->fw_sge>= 128 -MFI_PASS_FRAME_SIZE) {
+ s->fw_sge = 128 -MFI_PASS_FRAME_SIZE;
+ } else {
+ s->fw_sge = 64 -MFI_PASS_FRAME_SIZE;
+ }
+ if (s->fw_cmds>MEGASAS_MAX_FRAMES) {
+ s->fw_cmds =MEGASAS_MAX_FRAMES;
+ }
+ if (s->raid_mode_str) {
+ if (!strcmp(s->raid_mode_str, "jbod")) {
+ s->is_jbod = 1;
+ } else {
+ s->is_jbod = 0;
+ }
+ }
+ DPRINTF("Using %d sges, %d cmds, %s mode\n",
+ s->fw_sge,s->fw_cmds,s->is_jbod? "jbod" : "raid");
+ s->fw_luns = (MFI_MAX_LD>MAX_SCSI_DEVS) ?
+ MAX_SCSI_DEVS :MFI_MAX_LD;
Quoted 8 lines
+ s->producer_pa = 0;
+ s->consumer_pa = 0;
+ for (i = 0; i <s->fw_cmds; i++) {
+ s->frames[i].index = i;
+ s->frames[i].context = -1;
+ s->frames[i].pa = 0;
+ s->frames[i].state = s;
+ }
It is not clear to me that all register state is initialized here. megasas_soft_reset() seems to touch fw_state and intr_mask but will not be called until mmio_writel(MFI_IDB, MFI_FWINIT_READY). Are there any missing fields that need to be initialized here?
Stefan
Paolo Bonzini
maintainerRe: [PATCH 3/3] megasas: LSI Megaraid SAS emulation
In reply to Hannes ReineckeQuoted 3 lines · Hannes Reinecke
(And no, I will not getting into another dog-fight with Paul B. here. Virtio can do without bounce buffers. AHCI can. So I fail to see why SCSI has to rely on bounce buffers.)
I agree, but I do see why a SCSI device might prefer to rely on bounce buffers for non-I/O commands. This is why in my last RFC series for vmw_pvscsi I let the device choose whether to force a bounce buffer or get an external iovec from the HBA.
Paolo
Re: [PATCH 3/3] megasas: LSI Megaraid SAS emulation
Quoted 10 lines · Paolo Bonzini
Quoted 3 lines · Hannes Reinecke
(And no, I will not getting into another dog-fight with Paul B. here. Virtio can do without bounce buffers. AHCI can. So I fail to see why SCSI has to rely on bounce buffers.)
I agree, but I do see why a SCSI device might prefer to rely on bounce buffers for non-I/O commands. This is why in my last RFC series for
vmw_pvscsiI let the device choose whether to force a bounce buffer or get an external iovec from the HBA.
Yes, sure, for non-I/O commands it's perfectly okay. Most of which will be emulated anyway.
It's bounce buffers for I/O which kills performance.
But I seem to have missed your last RFC (I'm not reading qemu-devel on a regular basis ...). Care to send me a pointer to it?
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke zSeries & Storage [email protected] +49 911 74053 688 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)
Paolo Bonzini
maintainerRe: [PATCH 3/3] megasas: LSI Megaraid SAS emulation
Quoted 11 lines · Hannes Reinecke
Quoted 10 lines · Paolo Bonzini
Quoted 3 lines · Hannes Reinecke
(And no, I will not getting into another dog-fight with Paul B. here. Virtio can do without bounce buffers. AHCI can. So I fail to see why SCSI has to rely on bounce buffers.)
I agree, but I do see why a SCSI device might prefer to rely on bounce buffers for non-I/O commands. This is why in my last RFC series for
vmw_pvscsiI let the device choose whether to force a bounce buffer or get an external iovec from the HBA.
Quoted 7 lines
Yes, sure, for non-I/O commands it's perfectly okay. Most of which will be emulated anyway.
It's bounce buffers for I/O which kills performance.But I seem to have missed your last RFC (I'm not reading qemu-devel on a regular basis ...).
Care to send me a pointer to it?
Sure, http://lists.gnu.org/archive/html/qemu-devel/2011-06/msg00668.html
Paolo
Re: [PATCH 3/3] megasas: LSI Megaraid SAS emulation
Quoted 18 lines · Paolo Bonzini
Quoted 17 lines · Hannes Reinecke
Quoted 7 lines · Paolo Bonzini
Quoted 5 lines · Hannes Reinecke
(And no, I will not getting into another dog-fight with Paul B. here.
Virtio can do without bounce buffers. AHCI can. So I fail to see why
SCSI has to rely on bounce buffers.)Quoted 5 lines
I agree, but I do see why a SCSI device might prefer to rely on bounce buffers for non-I/O commands. This is why in my last RFC series for
vmw_pvscsiI let the device choose whether to force a bounce buffer or get an external iovec from the HBA.Yes, sure, for non-I/O commands it's perfectly okay. Most of which will be emulated anyway.
It's bounce buffers for I/O which kills performance.
Quoted 8 lines
Quoted 4 lines
But I seem to have missed your last RFC (I'm not reading qemu-devel on a
regular basis ...).
Care to send me a pointer to it?Sure,
http://lists.gnu.org/archive/html/qemu-devel/2011-06/msg00668.html
Cool.
Exactly what I need.
FWIW, feel free to add my 'Acked-by' to it.
Any chance of getting them included?
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke zSeries & Storage [email protected] +49 911 74053 688 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)
Re: [Qemu-devel] [PATCH 3/3] megasas: LSI Megaraid SAS emulation
In reply to Stefan HajnocziQuoted 44 lines · Stefan Hajnoczi
Quoted 43 lines · Hannes Reinecke
hw/megasas.c new file +43
-0+static void megasas_mmio_writel (void *opaque,target_phys_addr_t addr, +uint32_t val) +{ +MPTState *s = opaque; +target_phys_addr_t frame_addr; +uint32_t frame_count; +int i; + +DPRINTF_REG ("writel mmio %lx: %x\n" , (unsigned long )addr, val); + +switch (addr) { +case MFI_IDB : +if (val&MFI_FWINIT_ABORT ) { +/* Abort all pending cmds */ +for (i =0 ; i<= s->fw_cmds; i++) { +megasas_abort_command (&s->frames[i]); + } + } +if (val&MFI_FWINIT_READY ) { +/* move to FW READY */ +megasas_soft_reset (s); + } +if (val&MFI_FWINIT_MFIMODE ) { +/* discard MFIs */ + } +break ; +case MFI_OMSK : + s->intr_mask = val; +if (!MEGASAS_INTR_ENABLED (s)) { +qemu_irq_lower (s->dev.irq[0 ]); + } +break ; +case MFI_ODCR0 : +/* Update reply queue pointer */ +DPRINTF_QUEUE ("Update reply queue head %x busy %d\n" , + s->reply_queue_index, s->busy); +stl_phys (s->producer_pa, s->reply_queue_index); + s->doorbell =0 ; +qemu_irq_lower (s->dev.irq[0 ]); +break ; +case MFI_IQPH : + s->frame_hi = val; +break ;
Quoted 9 lines
hw/megasas.c line 1624
Quoted 6 lines
hw/megasas.c new file +6
-0+case MFI_IQPL : +case MFI_IQP : +/* Received MFI frame address */ + frame_addr = (val& ~0xFF ); +/* Add possible 64 bit offset */ + frame_addr |= (uint64_t )s->frame_hi;Is this missing<< 32 before ORing the high bits?
Yes, true. Linux doesn't use the high part, so I haven't seen it yet.
Might explain the strange Win7 failures I've had :-) Fixed.
Quoted 8 lines
hw/megasas.c line 1813
Quoted 5 lines
hw/megasas.c new file +5
-0+static int megasas_scsi_uninit (PCIDevice *d) +{ +MPTState *s =DO_UPCAST (MPTState, dev, d); + +cpu_unregister_io_memory (s->mmio_io_addr);Need to unregister
io_addrandqueue_addr.
Yeah, the unregister function is a bit of a stub currently. Fixed.
Quoted 23 lines
Quoted 23 lines
hw/megasas.c new file +23
-0+ +return 0 ; +} + +static const struct SCSIBusOps megasas_scsi_ops = { + .transfer_data = megasas_xfer_complete, + .complete = megasas_command_complete, + .cancel = megasas_command_cancel, +}; + +static int megasas_scsi_init (PCIDevice *dev) +{ +MPTState *s =DO_UPCAST (MPTState, dev, dev); +uint8_t *pci_conf; +int i; + + pci_conf = s->dev.config; + +/* PCI Vendor ID (word) */ +pci_config_set_vendor_id (pci_conf,PCI_VENDOR_ID_LSI_LOGIC ); +/* PCI device ID (word) */ +pci_config_set_device_id (pci_conf,PCI_DEVICE_ID_LSI_SAS1078 ); +/* PCI subsystem ID */
Quoted 9 lines
hw/megasas.c line 1840
Quoted 4 lines
hw/megasas.c new file +4
-0+pci_set_word (&pci_conf[PCI_SUBSYSTEM_VENDOR_ID ],0x1000 ); +pci_set_word (&pci_conf[PCI_SUBSYSTEM_ID ],0x1013 ); +/* PCI base class code */ +pci_config_set_class (pci_conf,PCI_CLASS_STORAGE_RAID );PCIDeviceInfo now has
vendor_id,device_id, and other fields. These values can be set in themegasas_infodefinition below.
Argl. Interface change again. Okay, will be doing so.
Quoted 9 lines
Quoted 9 lines
hw/megasas.c new file +9
-0+ +/* PCI latency timer = 0 */ + pci_conf[0x0d ] =0 ; +/* Interrupt pin 1 */ + pci_conf[0x3d ] =0x01 ; + + s->mmio_io_addr =cpu_register_io_memory (megasas_mmio_readfn, + megasas_mmio_writefn, s, +DEVICE_NATIVE_ENDIAN );
Quoted 9 lines
hw/megasas.c line 1855
Quoted 6 lines
hw/megasas.c new file +6
-0+ s->io_addr =cpu_register_io_memory (megasas_io_readfn, + megasas_io_writefn, s, +DEVICE_NATIVE_ENDIAN ); + s->queue_addr =cpu_register_io_memory (megasas_queue_readfn, + megasas_queue_writefn, s, +DEVICE_NATIVE_ENDIAN );Should these be little-endian?
Presumably. Haven't tested on big-endian emulations as of now.
Quoted 36 lines
Quoted 25 lines
hw/megasas.c new file +25
-0+pci_register_bar ((struct PCIDevice *)s,0 ,0x40000 , +PCI_BASE_ADDRESS_SPACE_MEMORY , megasas_mmio_mapfunc); +pci_register_bar ((struct PCIDevice *)s,2 ,256 , +PCI_BASE_ADDRESS_SPACE_IO , megasas_io_mapfunc); +pci_register_bar ((struct PCIDevice *)s,3 ,0x40000 , +PCI_BASE_ADDRESS_SPACE_MEMORY , megasas_queue_mapfunc); +if (s->fw_sge>=MEGASAS_MAX_SGE -MFI_PASS_FRAME_SIZE ) { + s->fw_sge =MEGASAS_MAX_SGE -MFI_PASS_FRAME_SIZE ; + }else if (s->fw_sge>=128 -MFI_PASS_FRAME_SIZE ) { + s->fw_sge =128 -MFI_PASS_FRAME_SIZE ; + }else { + s->fw_sge =64 -MFI_PASS_FRAME_SIZE ; + } +if (s->fw_cmds>MEGASAS_MAX_FRAMES ) { + s->fw_cmds =MEGASAS_MAX_FRAMES ; + } +if (s->raid_mode_str) { +if (!strcmp (s->raid_mode_str,"jbod" )) { + s->is_jbod =1 ; + }else { + s->is_jbod =0 ; + } + } +DPRINTF ("Using %d sges, %d cmds, %s mode\n" , + s->fw_sge, s->fw_cmds, s->is_jbod ?"jbod" :"raid" );hw/megasas.c line 1890
Quoted 10 lines
hw/megasas.c new file +10
-0+ s->fw_luns = (MFI_MAX_LD >MAX_SCSI_DEVS ) ? +MAX_SCSI_DEVS :MFI_MAX_LD ; + s->producer_pa =0 ; + s->consumer_pa =0 ; +for (i =0 ; i< s->fw_cmds; i++) { + s->frames[i].index = i; + s->frames[i].context =-1 ; + s->frames[i].pa =0 ; + s->frames[i].state = s; + }
Quoted 5 lines
It is not clear to me that all register state is initialized here.
megasas_soft_reset()seems to touchfw_stateandintr_maskbut will not be called untilmmio_writel(MFI_IDB, MFI_FWINIT_READY). Are there any missing fields that need to be initialized here?
I was under the impression that we'll be getting a reset after initialising the device, so this should've been taken care of. And most of the mmio writes are safe against accidental misuse.
I'll be adding a check to MFI_ODCR0, as this indeed might cause
an error when used uninitialized.
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke zSeries & Storage [email protected] +49 911 74053 688 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)
Paolo Bonzini
maintainerRe: [PATCH 3/3] megasas: LSI Megaraid SAS emulation
In reply to Hannes ReineckeQuoted 7 lines · Hannes Reinecke
Quoted 1 line
Cool.
Exactly what I need.FWIW, feel free to add my 'Acked-by' to it.
Any chance of getting them included?
I'm not very tied to pvscsi; I just needed an HBA that is not a joke by modern standards :) to play with the SCSI layer. There may be hope that megasas will come before pvscsi or eliminate the need for it altogether.
So, feel free to pick up patches 5-8 from that series.
That said, note that scsi-generic does *not* support scatter/gather in that series, so you should still make sure the fallback paths work well. :) In pvscsi I added a qdev property to toggle scatter/gather, it was useful for benchmarking.
Paolo
Re: [PATCH 3/3] megasas: LSI Megaraid SAS emulation
Quoted 5 lines · Paolo Bonzini
Quoted 4 lines · Hannes Reinecke
Quoted 1 line
Cool.
Exactly what I need.
Quoted 9 lines
Quoted 3 lines
FWIW, feel free to add my 'Acked-by' to it.
Any chance of getting them included?
I'm not very tied to pvscsi; I just needed an HBA that is not a joke by modern standards :) to play with the SCSI layer. There may be hope that megasas will come before pvscsi or eliminate the need for it altogether. So, feel free to pick up patches 5-8 from that series.
Hmm. My goal was actually to get the megasas HBA emulation upstream. When sticking it behind another set of patches chances are not exactly increasing. However, it would certainly make my life easier.
Quoted 5 lines
That said, note that scsi-generic does *not* support scatter/gather in that series, so you should still make sure the fallback paths work well. :) In pvscsi I added a qdev property to toggle scatter/gather, it was useful for benchmarking.
Have to check. My patchset did, so it should be reasonably easy to port that one to your infrastructure.
However, I probably will see to fixup the megasas emulation with the current infrastructure, get that in, and then move over to the iovec infrastructure.
But if you promise to merge the iovec infrastructure I'm more than willing to fixup the scsi-generic backend. Just say the word.
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke zSeries & Storage [email protected] +49 911 74053 688 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)
Paolo Bonzini
maintainerRe: [PATCH 3/3] megasas: LSI Megaraid SAS emulation
Quoted 3 lines · Hannes Reinecke
However, I probably will see to fixup the megasas emulation with the current infrastructure, get that in, and then move over to the iovec infrastructure.
Makes sense also for ease of review.
Quoted 2 lines
But if you promise to merge the iovec infrastructure I'm more than willing to fixup the scsi-generic backend.
I am certainly going to get it upstream, but maintainers would like it to have users at the time it is committed.
Paolo