nForce4 ADMA with NCQ: It's aliiiive..
RFC PATCH 1/1 nForce4 ADMA with NCQ: It's aliiiive..
I've been working on the patch for sata_nv ADMA support for nForce4 that Jeff Garzik has in a git branch. I've gotten it into a state where the ADMA and NCQ features appear to be working with no obvious problems. I've attached a patch against 2.6.18-mm2.
The code was mostly in a working state for the non-NCQ case but there were a number of heinous bugs that prevented NCQ from working, like in the sg list to APRD conversion code and in the interrupt handler.
This is still in quite an experimental state. It has survived system boots into Fedora Core 5 and Bonnie++ benchmark runs without blowing up, but there could still be bugs that could corrupt data, etc. so test with caution.
There is a module parameter adma_enabled which has to be set to 1 to enable ADMA on CK804/MCP04 chipsets (either that or hack the code to make the default 1). I only enabled ADMA on those chipsets and not MCP51, MCP55 or MCP61 since that was all that the original NVIDIA version did. I assume there was a reason for this, though maybe not. Someone with one of these chipsets should probably try it out (replacing the GENERIC type with CK804 in the PCI device table may be all it takes).
A few outstanding issues:
-Error handling likely needs work. EH works well enough to get past drive detection but that's likely about all. When I ran into errors while debugging, it usually locked up the machine when trying to do a soft reset.
-Error handling is also noisy at the moment (it dumps a bunch of controller state information).
-Jeff will probably cringe at how I implemented the bmdma_stop/start/status/setup functions. This kludge of toggling ATA_FLAG_MMIO off for the call into libata was needed since this controller is almost what libata calls ATA_FLAG_MMIO, but not quite (the ATA taskfile registers are MMIO but the BMDMA registers are PIO). This is also why I needed the patch to libata-sff.c to use the adapter's bmdma_status function rather than hardcoded ata_bmdma_status.
Some sample dmesg output:
sata_nv 0000:00:07.0: version 2.1sata_nv 0000:00:07.0: Using ADMA mode
ACPI: PCI Interrupt Link [APSI] enabled at IRQ 23
ACPI: PCI Interrupt 0000:00:07.0[A] -> Link [APSI] -> GSI 23 (level, low) -> IRQ 23
PCI: Setting latency timer of device 0000:00:07.0 to 64sata_nv 0000:00:07.0: Resetting port 0
ata1: SATA max UDMA/133 cmd 0xFFFFC20000004480 ctl 0xFFFFC200000044A0 bmdma 0xD800 irq 23sata_nv 0000:00:07.0: Resetting port 1
ata2: SATA max UDMA/133 cmd 0xFFFFC20000004580 ctl 0xFFFFC200000045A0 bmdma 0xD808 irq 23
scsi0 : sata_nv
PM: Adding info for No Bus:host0sata_nv 0000:00:07.0: Error handling port 0, notifier 0x0, notifier_error 0x0, gen_ctl 0x1501000, int pending 0, status 0x700, dumping CPB states
ata1: SATA link up 1.5 Gbps (SStatus 113 SControl 300)
ata1.00: ATA-6, max UDMA/133, 312581808 sectors: LBA48 NCQ (depth 31/32)
ata1.00: ata1: dev 0 multi count 1
ata1.00: configured for UDMA/133
scsi1 : sata_nv
PM: Adding info for No Bus:host1sata_nv 0000:00:07.0: Error handling port 1, notifier 0x0, notifier_error 0x0, gen_ctl 0x1501000, int pending 0, status 0x700, dumping CPB states
ata2: SATA link down (SStatus 0 SControl 300)
PM: Adding info for No Bus:target0:0:0
scsi 0:0:0:0: Direct-Access ATA ST3160827AS 3.42 PQ: 0 ANSI: 5
PM: Adding info for scsi:0:0:0:0
SCSI device sda: 312581808 512-byte hdwr sectors (160042 MB)
sda: Write Protect is off
sda: Mode Sense: 00 3a 00 00
SCSI device sda: drive cache: write back
SCSI device sda: 312581808 512-byte hdwr sectors (160042 MB)
sda: Write Protect is off
sda: Mode Sense: 00 3a 00 00
SCSI device sda: drive cache: write back
sda: sda1
sd 0:0:0:0: Attached scsi disk sdasata_nv 0000:00:08.0: Using ADMA mode
ACPI: PCI Interrupt Link [APSJ] enabled at IRQ 22
ACPI: PCI Interrupt 0000:00:08.0[A] -> Link [APSJ] -> GSI 22 (level, low) -> IRQ 22
PCI: Setting latency timer of device 0000:00:08.0 to 64sata_nv 0000:00:08.0: Resetting port 0
ata3: SATA max UDMA/133 cmd 0xFFFFC20000006480 ctl 0xFFFFC200000064A0 bmdma 0xC400 irq 22sata_nv 0000:00:08.0: Resetting port 1
ata4: SATA max UDMA/133 cmd 0xFFFFC20000006580 ctl 0xFFFFC200000065A0 bmdma 0xC408 irq 22
scsi2 : sata_nv
PM: Adding info for No Bus:host2sata_nv 0000:00:08.0: Error handling port 0, notifier 0x0, notifier_error 0x0, gen_ctl 0x1501000, int pending 0, status 0x700, dumping CPB states
ata3: SATA link up 3.0 Gbps (SStatus 123 SControl 300)
ata3.00: ATA-7, max UDMA/133, 625142448 sectors: LBA48 NCQ (depth 31/32)
ata3.00: ata3: dev 0 multi count 1
ata3.00: configured for UDMA/133
scsi3 : sata_nv
PM: Adding info for No Bus:host3sata_nv 0000:00:08.0: Error handling port 1, notifier 0x0, notifier_error 0x0, gen_ctl 0x1501000, int pending 0, status 0x700, dumping CPB states
ata4: SATA link up 1.5 Gbps (SStatus 113 SControl 300)
ata4.00: ATA-6, max UDMA/133, 312581808 sectors: LBA48 NCQ (depth 31/32)
ata4.00: ata4: dev 0 multi count 1
ata4.00: configured for UDMA/133
PM: Adding info for No Bus:target2:0:0
scsi 2:0:0:0: Direct-Access ATA ST3320620AS 3.AA PQ: 0 ANSI: 5
PM: Adding info for scsi:2:0:0:0
SCSI device sdb: 625142448 512-byte hdwr sectors (320073 MB)
sdb: Write Protect is off
sdb: Mode Sense: 00 3a 00 00
SCSI device sdb: drive cache: write back
SCSI device sdb: 625142448 512-byte hdwr sectors (320073 MB)
sdb: Write Protect is off
sdb: Mode Sense: 00 3a 00 00
SCSI device sdb: drive cache: write back
sdb: sdb1
sd 2:0:0:0: Attached scsi disk sdb
PM: Adding info for No Bus:target3:0:0
scsi 3:0:0:0: Direct-Access ATA ST3160827AS 3.42 PQ: 0 ANSI: 5
PM: Adding info for scsi:3:0:0:0
SCSI device sdc: 312581808 512-byte hdwr sectors (160042 MB)
sdc: Write Protect is off
sdc: Mode Sense: 00 3a 00 00
SCSI device sdc: drive cache: write back
SCSI device sdc: 312581808 512-byte hdwr sectors (160042 MB)
sdc: Write Protect is off
sdc: Mode Sense: 00 3a 00 00
SCSI device sdc: drive cache: write back
sdc: sdc1 sdc2 sdc3 sdc4 < sdc5 >
sd 3:0:0:0: Attached scsi disk sdc
Finally some Bonnie++ results from before, without NCQ:
Version 1.03 ------Sequential Output------ --Sequential Input- --Random-
-Per Chr- --Block-- -Rewrite- -Per Chr- --Block--
--Seeks--
Machine Size K/sec %CP K/sec %CP K/sec %CP K/sec %CP K/sec %CP /sec %CP
newcastle.ss.sha 4G 33185 79 36840 33 16170 9 33461 73 39788 7 179.4 1
------Sequential Create------ --------Random
Create--------
-Create-- --Read--- -Delete-- -Create-- --Read---
-Delete--
files /sec %CP /sec %CP /sec %CP /sec %CP /sec %CP
/sec %CP
16 6920 81 +++++ +++ 15820 100 8286 99 +++++ +++ 15874 98
and with NCQ:
Version 1.03 ------Sequential Output------ --Sequential Input- --Random-
-Per Chr- --Block-- -Rewrite- -Per Chr- --Block--
--Seeks--
Machine Size K/sec %CP K/sec %CP K/sec %CP K/sec %CP K/sec %CP /sec %CP
newcastle.ss.sha 4G 27068 66 31907 26 17020 8 29163 77 40032 8 205.0 0
------Sequential Create------ --------Random
Create--------
-Create-- --Read--- -Delete-- -Create-- --Read---
-Delete--
files /sec %CP /sec %CP /sec %CP /sec %CP /sec %CP
/sec %CP
16 9566 91 +++++ +++ 16387 99 10606 99 +++++ +++ 23773 99
It looks like there was a bit of a drop in sequential output and sequential character input, but everything else went up..
In case anyone wants to actually apply this to something:
Signature · 3 lines
Robert Hancock Saskatoon, SK, Canada To email, remove "nospam" from [email protected] Home Page: http://www.roberthancock.com/
drivers/ata/libata-sff.c +1 -1
@@ -732,7 +732,7 @@ void ata_bmdma_drive_eh(struct ata_port qc->tf.protocol == ATA_PROT_ATAPI_DMA)) {u8 host_stat; - host_stat =ata_bmdma_status (ap); + host_stat = ap->ops->bmdma_status (ap);ata_ehi_push_desc (&ehc->i,"BMDMA stat 0x%x" , host_stat);
drivers/ata/sata_nv.c +885 -6
1,005 lines not on this page · raw message
Am Samstag 07 Oktober 2006 10:08 schrieb Robert Hancock:
Quoted 1 line
I've been working on the patch for
sata_nvADMA support for nForce4 that
Nice!
Quoted 3 lines
make the default 1). I only enabled ADMA on those chipsets and not MCP51, MCP55 or MCP61 since that was all that the original NVIDIA version did. I assume there was a reason for this, though maybe not.
Unfortunately it doesn't work for me on MCP51 if I change GENERIC to ADMA. So I wonder whether MCP51 has ADMA mode or what needs to be done to get NCQ working. :-(
Cheers,
Signature · 3 lines
(°= =°) //\ Prakash Punnoor /\\ V_/ \_V
Quoted 10 lines · Prakash Punnoor
Am Samstag 07 Oktober 2006 10:08 schrieb Robert Hancock:
Quoted 1 line
I've been working on the patch for
sata_nvADMA support for nForce4 thatNice!
Quoted 3 lines
make the default 1). I only enabled ADMA on those chipsets and not MCP51, MCP55 or MCP61 since that was all that the original NVIDIA version did. I assume there was a reason for this, though maybe not.
Unfortunately it doesn't work for me on MCP51 if I change GENERIC to ADMA. So I wonder whether MCP51 has ADMA mode or what needs to be done to get NCQ working. :-(
What happened when you tried it? It would be useful if you could change the #undef in these lines:
53 #undef ATA_DEBUG /* debugging output */
54 #undef ATA_VERBOSE_DEBUG /* yet more debugging output */
in include/linux/libata.h to #define and rebuild and try it then, that will spew out a bunch more output and I can see if any reasonable looking values are showing up at all. I was capturing this output the crude way, booting with vga=6 to get a smaller font and taking a picture of the screen :-) Also, maybe post the lspci -v output from the SATA controller..
If that doesn't provide any insight, maybe the docs Jeff has provide the answer for whether or not the MCP5x/MCP61 controllers have the same interface as the CK804/MCP04..
Signature · 3 lines
Robert Hancock Saskatoon, SK, Canada To email, remove "nospam" from [email protected] Home Page: http://www.roberthancock.com/
Quoted 19 lines
Quoted 1 line
Unfortunately it doesn't work for me on MCP51 if I change
GENERIC to
Quoted 1 line
ADMA. So I wonder whether MCP51 has ADMA mode or what needs
to be done
Quoted 1 line
to get NCQ working. :-(
What happened when you tried it? It would be useful if you could change the #undef in these lines:
53 #undef
ATA_DEBUG/* debugging output */
54 #undefATA_VERBOSE_DEBUG/* yet more debugging output */in
include/linux/libata.hto #define and rebuild and try it then, that will spew out a bunch more output and I can see if any reasonable looking values are showing up at all. I was capturing this output the crude way, booting with vga=6 to get a smaller font and taking a picture of the screen :-) Also, maybe post the lspci -v output from the SATA controller..
Quoted 3 lines
If that doesn't provide any insight, maybe the docs Jeff has provide the answer for whether or not the MCP5x/MCP61 controllers have the same interface as the CK804/MCP04..
No, only CK804 and MCP04 support ADMA. We'll be publishing some patches for NCQ support for MCP55/MCP61 soon.
-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------
Am Dienstag 10 Oktober 2006 08:44 schrieb Allen Martin:
Quoted 11 lines
Quoted 10 lines
Quoted 1 line
Unfortunately it doesn't work for me on MCP51 if I change
GENERIC to
Quoted 1 line
ADMA. So I wonder whether MCP51 has ADMA mode or what needs
to be done
Quoted 1 line
to get NCQ working. :-(
Quoted 6 lines
Quoted 3 lines
If that doesn't provide any insight, maybe the docs Jeff has provide the answer for whether or not the MCP5x/MCP61 controllers have the same interface as the CK804/MCP04..
No, only CK804 and MCP04 support ADMA. We'll be publishing some patches for NCQ support for MCP55/MCP61 soon.
That's great news! I hope you don't forget the MCP51, as well, as you didn't mention it. :-)
Signature · 3 lines
(°= =°) //\ Prakash Punnoor /\\ V_/ \_V
Am Dienstag 10 Oktober 2006 08:44 schrieb Allen Martin:
Quoted 2 lines
No, only CK804 and MCP04 support ADMA. We'll be publishing some patches for NCQ support for MCP55/MCP61 soon.
Just wondering whether I missed them? It is now 1,5 month later...
Signature · 3 lines
(°= =°) //\ Prakash Punnoor /\\ V_/ \_V
Quoted 6 lines · Prakash Punnoor
Am Dienstag 10 Oktober 2006 08:44 schrieb Allen Martin:
Quoted 2 lines
No, only CK804 and MCP04 support ADMA. We'll be publishing some patches for NCQ support for MCP55/MCP61 soon.
Just wondering whether I missed them? It is now 1,5 month later...
I don't think you missed them.. It would be nice to get this support in, those are the last NVIDIA chipsets which have NCQ support (apparently) that don't support it under Linux. Even just the hardware docs would be useful..
---
Robert Hancock Saskatoon, SK, Canada
To email, remove "nospam" from [email protected] Home Page: http://www.roberthancock.com/
Quoted 7 lines · Robert Hancock
I've been working on the patch for
sata_nvADMA support for nForce4 that Jeff Garzik has in a git branch. I've gotten it into a state where the ADMA and NCQ features appear to be working with no obvious problems. I've attached a patch against 2.6.18-mm2.The code was mostly in a working state for the non-NCQ case but there were a number of heinous bugs that prevented NCQ from working, like in the sg list to APRD conversion code and in the interrupt handler.
This is still in quite an experimental state. It has survived system boots into Fedora Core 5 and Bonnie++ benchmark runs without blowing up, but there could still be bugs that could corrupt data, etc. so test with caution.
There is a module parameter
adma_enabledwhich has to be set to 1 to enable ADMA on CK804/MCP04 chipsets (either that or hack the code to make the default 1). I only enabled ADMA on those chipsets and not MCP51, MCP55 or MCP61 since that was all that the original NVIDIA version did. I assume there was a reason for this, though maybe not. Someone with one of these chipsets should probably try it out (replacing the GENERIC type with CK804 in the PCI device table may be all it takes).
Nice! Good work.
Quoted 10 lines
A few outstanding issues:
-Error handling likely needs work. EH works well enough to get past
drive detection but that's likely about all. When I ran into errors while debugging, it usually locked up the machine when trying to do a soft reset.-Error handling is also noisy at the moment (it dumps a bunch of controller state information).
-Jeff will probably cringe at how I implemented the
bmdma_stop/start/status/setup functions. This kludge of togglingATA_FLAG_MMIOoff for the call into libata was needed since this controller is almost what libata callsATA_FLAG_MMIO, but not quite (the ATA taskfile registers are MMIO but the BMDMA registers are PIO). This is also why I needed the patch tolibata-sff.cto use the adapter'sbmdma_statusfunction rather than hardcodedata_bmdma_status.
*shrug* I don't cringe if that's the most expedient way to do something.
But I really don't think that is necessary. I will take a look at docs and see how things match up, when I am much more awake. Most likely you need to be using another set of registers, and be all MMIO, all the time.
Jeff
Quoted 8 lines · Jeff Garzik
Quoted 2 lines
-Jeff will probably cringe at how I implemented the
bmdma_stop/start/status/setup functions. This kludge of togglingATA_FLAG_MMIOoff for the call into libata was needed since this controller is almost what libata callsATA_FLAG_MMIO, but not quite (the ATA taskfile registers are MMIO but the BMDMA registers are PIO). This is also why I needed the patch tolibata-sff.cto use the adapter'sbmdma_statusfunction rather than hardcodedata_bmdma_status.*shrug* I don't cringe if that's the most expedient way to do something.
But I really don't think that is necessary. I will take a look at docs and see how things match up, when I am much more awake. Most likely you need to be using another set of registers, and be all MMIO, all the time.
Jeff
Hopefully that is the case, it would clean things up a bit..
I've cut another patch, this one against 2.6.18-mm3. I've fixed a couple of issues:
-Error handling now pushes the port back into port-register mode so that the reset will actually work properly.
-It seems there was a problem with the checks for deciding whether to scan the CPB list in the interrupt handler that occasionally caused interrupts to get lost and commands to time out (which unintentionally tested the EH fix above). I think this is fixed now.
Signature · 3 lines
Robert Hancock Saskatoon, SK, Canada To email, remove "nospam" from [email protected] Home Page: http://www.roberthancock.com/
drivers/ata/libata-sff.c +1 -1
@@ -732,7 +732,7 @@ void ata_bmdma_drive_eh(struct ata_port qc->tf.protocol == ATA_PROT_ATAPI_DMA)) {u8 host_stat; - host_stat =ata_bmdma_status (ap); + host_stat = ap->ops->bmdma_status (ap);ata_ehi_push_desc (&ehc->i,"BMDMA stat 0x%x" , host_stat);
drivers/ata/sata_nv.c +874 -6
988 lines not on this page · raw message
Only in linux-2.6.18-mm3-adma/drivers/ata: sata_nv.c.orig
Quoted 10 lines
Quoted 5 lines
-Jeff will probably cringe at how I implemented the bmdma_stop/start/status/setup functions. This kludge of toggling
ATA_FLAG_MMIOoff for the call into libata was needed since this controller is almost what libata callsATA_FLAG_MMIO, but not quite (the ATA taskfile registers are MMIO but the BMDMAregisters are PIO).
Quoted 2 lines
This is also why I needed the patch to
libata-sff.cto use the adapter'sbmdma_statusfunction rather than hardcoded
ata_bmdma_status.
Quoted 7 lines
*shrug* I don't cringe if that's the most expedient way to do something.
But I really don't think that is necessary. I will take a look at docs and see how things match up, when I am much more awake. Most likely you need to be using another set of registers, and be all MMIO, all the time.
You shouldn't be touching BM registers when ADMA is enabled, it can cause bad things to happen.
You should be using BM registers when doing ATAPI protocol though, as it doesn't work through ADMA. So I wouldn't say you should be using MMIO all the time.
-Allen
-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------
Quoted 10 lines · Allen Martin
Quoted 1 line
But I really don't think that is necessary. I will take a look at docs and see how things match up, when I am much more awake. Most likely you need to be using another set of registers, and be all MMIO, all the time.
You shouldn't be touching BM registers when ADMA is enabled, it can cause bad things to happen.
You should be using BM registers when doing ATAPI protocol though, as it doesn't work through ADMA. So I wouldn't say you should be using MMIO all the time.
-Allen
OK, I've updated the code to take this into account, an updated patch is attached. However, this does raise an issue. If we have to fall back to legacy mode to do ATAPI DMA, this means that we can't do 64-bit DMA for such transfers. Since by the time the driver gets a request the SGs have already been created based on the set DMA mask, the only way I can see to handle this is to either allow ATAPI DMA or 64-bit DMA, not both. I've chosen to default to 64-bit DMA in this version, but there is a module parameter which allows overriding this if you care more about using ATAPI devices than efficiency with over 4GB of RAM. I'm open to suggestions on a better way to handle this..
I also updated the comments to clarify which chipsets are supported by ADMA as per Allen's previous comment.
This patch is now against 2.6.19-rc1-mm1. If there are no more suggestions, are there any objections to merging this into libata-dev or the -mm tree? I think it is ready for some more exposure, and since ADMA is currently disabled by default there should be little risk of breakage for those who don't choose to enable it.
Signature · 3 lines
Robert Hancock Saskatoon, SK, Canada To email, remove "nospam" from [email protected] Home Page: http://www.roberthancock.com/
drivers/ata/libata-sff.c +1 -1
@@ -732,7 +732,7 @@ void ata_bmdma_drive_eh(struct ata_port qc->tf.protocol == ATA_PROT_ATAPI_DMA)) {u8 host_stat; - host_stat =ata_bmdma_status (ap); + host_stat = ap->ops->bmdma_status (ap);ata_ehi_push_desc (&ehc->i,"BMDMA stat 0x%x" , host_stat);
drivers/ata/sata_nv.c +905 -6
1,019 lines not on this page · raw message
Quoted 15 lines · Robert Hancock
Quoted 5 lines · Allen Martin
Quoted 4 lines
But I really don't think that is necessary. I will take a look at docs and see how things match up, when I am much more awake. Most likely you need to be using another set of registers, and be all MMIO, all the time.
Quoted 8 lines
You shouldn't be touching BM registers when ADMA is enabled, it can cause bad things to happen.
You should be using BM registers when doing ATAPI protocol though, as it doesn't work through ADMA. So I wouldn't say you should be using MMIO all the time.
-Allen
Quoted 10 lines
OK, I've updated the code to take this into account, an updated patch is attached. However, this does raise an issue. If we have to fall back to legacy mode to do ATAPI DMA, this means that we can't do 64-bit DMA for such transfers. Since by the time the driver gets a request the SGs have already been created based on the set DMA mask, the only way I can see to handle this is to either allow ATAPI DMA or 64-bit DMA, not both. I've chosen to default to 64-bit DMA in this version, but there is a module parameter which allows overriding this if you care more about using ATAPI devices than efficiency with over 4GB of RAM. I'm open to suggestions on a better way to handle this..
Should be easily fixable - in general, set 64-bit dma mask. Then when you detect an atapi device, lower the dma mask settings to 32-bit dma for that device only. So the pci device in question gets a full 64-bit dma mask, the attached scsi devices can have lower masks if necessary. I'd suggest doing this off slave config.
Signature · 1 line
Jens Axboe
Quoted 10 lines · Jens Axboe
Quoted 9 lines · Robert Hancock
Quoted 8 lines · Allen Martin
Quoted 1 line
But I really don't think that is necessary. I will take a look at docs and see how things match up, when I am much more awake. Most likely you need to be using another set of registers, and be all MMIO, all the time.
You shouldn't be touching BM registers when ADMA is enabled, it can cause bad things to happen.
You should be using BM registers when doing ATAPI protocol though, as it doesn't work through ADMA. So I wouldn't say you should be using MMIO all the time.
Quoted 9 lines
Quoted 2 lines
Quoted 1 line
-Allen
OK, I've updated the code to take this into account, an updated patch is attached. However, this does raise an issue. If we have to fall back to legacy mode to do ATAPI DMA, this means that we can't do 64-bit DMA for such transfers. Since by the time the driver gets a request the SGs have already been created based on the set DMA mask, the only way I can see to handle this is to either allow ATAPI DMA or 64-bit DMA, not both. I've chosen to default to 64-bit DMA in this version, but there is a module parameter which allows overriding this if you care more about using ATAPI devices than efficiency with over 4GB of RAM. I'm open to suggestions on a better way to handle this..
Should be easily fixable - in general, set 64-bit dma mask. Then when you detect an atapi device, lower the dma mask settings to 32-bit dma for that device only. So the pci device in question gets a full 64-bit dma mask, the attached scsi devices can have lower masks if necessary. I'd suggest doing this off slave config.
I think that should be feasible.. However, one problem is that slave_config only has access to the struct scsi_device and the ata_scsi_find_dev function to turn that into a struct ata_device isn't exported, which it would need to be in order to do anything useful inside the driver for slave_config. We could export it, or I suppose the other place we could do this handling would be postreset, as at that point we should know what kind of device is attached.. any comments?
Also, how is the driver supposed to be setting the DMA mask for the SCSI device? I suppose blk_queue_bounce_limit would work, but it seems a bit odd to use block layer calls at the libata driver level.
I also noticed that I'm still using the default 64KB libata dma_boundary value, this should be 4GB for ADMA mode (but fixed up back to the default if an ATAPI device is connected, same as with the DMA mask).
Signature · 3 lines
Robert Hancock Saskatoon, SK, Canada To email, remove "nospam" from [email protected] Home Page: http://www.roberthancock.com/
Quoted 33 lines · Robert Hancock
Quoted 25 lines · Jens Axboe
Quoted 13 lines · Robert Hancock
Quoted 4 lines · Allen Martin
Quoted 4 lines
But I really don't think that is necessary. I will take a look at docs and see how things match up, when I am much more awake. Most likely you need to be using another set of registers, and be all MMIO, all the time.
Quoted 8 lines
You shouldn't be touching BM registers when ADMA is enabled, it can cause bad things to happen.
You should be using BM registers when doing ATAPI protocol though, as it doesn't work through ADMA. So I wouldn't say you should be using MMIO all the time.
-Allen
Quoted 10 lines
OK, I've updated the code to take this into account, an updated patch is attached. However, this does raise an issue. If we have to fall back to legacy mode to do ATAPI DMA, this means that we can't do 64-bit DMA for such transfers. Since by the time the driver gets a request the SGs have already been created based on the set DMA mask, the only way I can see to handle this is to either allow ATAPI DMA or 64-bit DMA, not both. I've chosen to default to 64-bit DMA in this version, but there is a module parameter which allows overriding this if you care more about using ATAPI devices than efficiency with over 4GB of RAM. I'm open to suggestions on a better way to handle this..
Quoted 6 lines
Should be easily fixable - in general, set 64-bit dma mask. Then when you detect an atapi device, lower the dma mask settings to 32-bit dma for that device only. So the pci device in question gets a full 64-bit dma mask, the attached scsi devices can have lower masks if necessary. I'd suggest doing this off slave config.
Quoted 7 lines
I think that should be feasible.. However, one problem is that
slave_configonly has access to the structscsi_deviceand theata_scsi_find_devfunction to turn that into a structata_deviceisn't exported, which it would need to be in order to do anything useful inside the driver forslave_config. We could export it, or I suppose the other place we could do this handling would be postreset, as at that point we should know what kind of device is attached.. any comments?
What else do you need? From the scsi device, call the blk_queue_bounce_limit() on the queue tored in there. That shold be it.
Quoted 3 lines
Also, how is the driver supposed to be setting the DMA mask for the SCSI device? I suppose
blk_queue_bounce_limitwould work, but it seems a bit odd to use block layer calls at the libata driver level.
That is the right thing to do.
Quoted 3 lines
I also noticed that I'm still using the default 64KB libata
dma_boundaryvalue, this should be 4GB for ADMA mode (but fixed up back to the default if an ATAPI device is connected, same as with the DMA mask).
You can set that from the same location as the bounce limit.
Signature · 1 line
Jens Axboe
PATCH 1/1 sata_nv ADMA/NCQ support for nForce4
Quoted 5 lines · Jens Axboe
Quoted 1 line
I think that should be feasible.. However, one problem is that
slave_configonly has access to the structscsi_deviceand theata_scsi_find_devfunction to turn that into a structata_deviceisn't exported, which it would need to be in order to do anything useful inside the driver forslave_config. We could export it, or I suppose the other place we could do this handling would be postreset, as at that point we should know what kind of device is attached.. any comments?What else do you need? From the scsi device, call the
blk_queue_bounce_limit()on the queue tored in there. That shold be it.
Quoted 7 lines
Quoted 1 line
Also, how is the driver supposed to be setting the DMA mask for the SCSI device? I suppose
blk_queue_bounce_limitwould work, but it seems a bit odd to use block layer calls at the libata driver level.That is the right thing to do.
Quoted 1 line
I also noticed that I'm still using the default 64KB libata
dma_boundaryvalue, this should be 4GB for ADMA mode (but fixed up back to the default if an ATAPI device is connected, same as with the DMA mask).You can set that from the same location as the bounce limit.
OK, I've cut another patch (v4) which incorporates the auto-setting of the lower bounce limit and segment boundary when an ATAPI device is connected to the port. ATAPI was not actually tested as I don't have any ATAPI SATA devices. I also cleaned up a few other things such as handling failure to set the 64-bit DMA mask as well as using ata_port_printk where appropriate.
I think this resolves all of the outstanding comments and known issues.. as before, commenters, testers, and mergers are welcome :-)
This patch is against 2.6.19-rc2.
---
This patch adds support for ADMA mode on NVIDIA nForce4 (CK804/MCP04) SATA controllers to the sata_nv driver. Benefits of ADMA mode include:
-NCQ support
-Reduced CPU overhead (controller DMAs command information from memory instead of them being pushed in by the CPU) -Full 64-bit DMA support
ADMA mode is disabled by default in this version. To enable ADMA on supported controllers, set the module parameter adma_enabled=1.
Signature · 3 lines
Robert Hancock Saskatoon, SK, Canada To email, remove "nospam" from [email protected] Home Page: http://www.roberthancock.com/
drivers/ata/libata-sff.c +1 -1
@@ -732,7 +732,7 @@ void ata_bmdma_drive_eh(struct ata_port qc->tf.protocol == ATA_PROT_ATAPI_DMA)) {u8 host_stat; - host_stat =ata_bmdma_status (ap); + host_stat = ap->ops->bmdma_status (ap);ata_ehi_push_desc (&ehc->i,"BMDMA stat 0x%x" , host_stat);
drivers/ata/sata_nv.c +928 -11
1,046 lines not on this page · raw message
Re: [PATCH] sata_nv ADMA/NCQ support for nForce4
Quoted 9 lines · Robert Hancock
drivers/ata/sata_nv.c +8
-0+/* ADMA Physical Region Descriptor - one SG segment */ +struct nv_adma_prd { +__le64 addr; +__le32 len; +u8 flags; +u8 packet_len; +__le16 reserved; +};
..
Quoted 8 lines
drivers/ata/sata_nv.c +8
-0+/* ADMA Command Parameter Block +The first 5 SG segments are stored inside the Command Parameter Block itself. +If there are more than 5 segments the remainder are stored in a separate +memory area indicated by next_aprd. */ +struct nv_adma_cpb { +u8 resp_flags;//0 +u8 reserved1;//1 +u8 ctl_flags;//2
drivers/ata/sata_nv.c enum { · line 203
Quoted 10 lines
drivers/ata/sata_nv.c +10
-0+// len is length of taskfile in 64 bit words +u8 len;//3 +u8 tag;//4 +u8 next_cpb_idx;//5 +__le16 reserved2;//6-7 +__le16 tf[12 ];//8-31 +struct nv_adma_prd aprd[5 ];//32-111 +__le64 next_aprd;//112-119 +__le64 reserved3;//120-127 +};
Are those CPB / PRD structs endian-safe when using a big-endian CPU?
Cheers
Re: [PATCH] sata_nv ADMA/NCQ support for nForce4
Quoted 35 lines · Mark Lord
Quoted 9 lines · Robert Hancock
drivers/ata/sata_nv.c +8
-0+/* ADMA Physical Region Descriptor - one SG segment */ +struct nv_adma_prd { +__le64 addr; +__le32 len; +u8 flags; +u8 packet_len; +__le16 reserved; +};..
Quoted 13 lines
(quoted diff) +2
-0+/* ADMA Command Parameter Block + The first 5 SG segments are stored inside the Command ParameterBlock itself.
+ If there are more than 5 segments the remainder are stored in a
separatedrivers/ata/sata_nv.c +7
-0+memory area indicated by next_aprd. */ +struct nv_adma_cpb { +u8 resp_flags;//0 +u8 reserved1;//1 +u8 ctl_flags;//2 +// len is length of taskfile in 64 bit words +u8 len;//3 + u8 tag; //4
drivers/ata/sata_nv.c enum { · line 203
Quoted 7 lines
drivers/ata/sata_nv.c +7
-0+u8 next_cpb_idx;//5 +__le16 reserved2;//6-7 +__le16 tf[12 ];//8-31 +struct nv_adma_prd aprd[5 ];//32-111 +__le64 next_aprd;//112-119 +__le64 reserved3;//120-127 +};Are those CPB / PRD structs endian-safe when using a big-endian CPU?
Quoted 1 line
Cheers
They should be, I believe cpu_to_leXX is used whenever the multi-byte elements are being written. Not that anyone would likely install a big-endian CPU on an nForce4 chipset ;-)
Signature · 3 lines
Robert Hancock Saskatoon, SK, Canada To email, remove "nospam" from [email protected] Home Page: http://www.roberthancock.com/
Re: [PATCH] sata_nv ADMA/NCQ support for nForce4
Quoted 9 lines · Robert Hancock
Quoted 8 lines · Mark Lord
Quoted 7 lines · Robert Hancock
drivers/ata/sata_nv.c +6
-0+/* ADMA Physical Region Descriptor - one SG segment */ +struct nv_adma_prd { +__le64 addr; +__le32 len; +u8 flags; +u8 packet_len;
..
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/ata/sata_nv.c +6
-0+struct nv_adma_cpb { +u8 resp_flags;//0 +u8 reserved1;//1 +u8 ctl_flags;//2 +// len is length of taskfile in 64 bit words +u8 len;//3 + u8 tag; //4
+ u8next_cpb_idx; //5
Quoted 6 lines
..
Quoted 3 lines
Are those CPB / PRD structs endian-safe when using a big-endian CPU?
Cheers
They should be, I believe
cpu_to_leXXis used whenever the multi-byte elements are being written.
I was thinking more about the non wordsized fields, such as the various u8 bytes that gcc will lay out differently depending upon endianess.
Cheers
Re: [PATCH] sata_nv ADMA/NCQ support for nForce4
Mark> I was thinking more about the non wordsized fields, such as Mark> the various u8 bytes that gcc will lay out differently Mark> depending upon endianess.
I don't know of any gcc version that changes the order of struct fields. You might be thinking of bitfields, which are laid out in an endian-dependent way.
- R.
Re: [PATCH] sata_nv ADMA/NCQ support for nForce4
Quoted 7 lines · Roland Dreier
Mark> I was thinking more about the non wordsized fields, such as Mark> the various u8 bytes that gcc will lay out differently Mark> depending upon endianess.
I don't know of any gcc version that changes the order of struct fields. You might be thinking of bitfields, which are laid out in an endian-dependent way.
Ack. And also thinking about other compilers I work with, which apparently are not so friendly.
You are correct -- I just verified it (again) for myself on x86 & PPC, and the layout of u8 doesn't change.
Cheers!
Quoted 2 lines · Robert Hancock
I also noticed that I'm still using the default 64KB libata
dma_boundaryvalue, this should be 4GB for ADMA mode (but fixed up back to the default if an ATAPI device is connected, same as with the DMA mask).
Be careful of that. The original PDC hardware for ADMA still had the "don't cross a 64KB boundary" requirement.
Cheers
Quoted 8 lines · Mark Lord
Quoted 2 lines · Robert Hancock
I also noticed that I'm still using the default 64KB libata
dma_boundaryvalue, this should be 4GB for ADMA mode (but fixed up back to the default if an ATAPI device is connected, same as with the DMA mask).Be careful of that. The original PDC hardware for ADMA still had the "don't cross a 64KB boundary" requirement.
Cheers
That is part of the ADMA spec - but in that case, how come the pdc_adma.c driver sets the dma_boundary in the SCSI host template to 4GB? That seems wrong.
In any case, however, I really doubt the NVIDIA ADMA controller shares this limitation - they provide 32 bits for the region length (standard ADMA only has 16 bits), which wouldn't be very useful if you couldn't cross a 64KB boundary..
Signature · 3 lines
Robert Hancock Saskatoon, SK, Canada To email, remove "nospam" from [email protected] Home Page: http://www.roberthancock.com/
Quoted 2 lines · Robert Hancock
Quoted 1 line · Mark Lord
Robert Hancock wrote:
..
Quoted 2 lines
Quoted 2 lines
Be careful of that. The original PDC hardware for ADMA still had the "don't cross a 64KB boundary" requirement.
..
Quoted 1 line
That is part of the ADMA spec - but in that case, how come the
pdc_adma.cdriver sets thedma_boundaryin the SCSI host template to 4GB? That seems wrong.
Ah, you are correct. My memory is fading of such things. The PDC parts are good for 2^34 transfer sizes (bytes).
Cheers