summaryrefslogtreecommitdiff
path: root/firmware/drivers/ata.c
AgeCommit message (Collapse)Author
2021-06-03ata: fix a typo in a definition that's thankfully not used.Solomon Peachy
Change-Id: I6f2d4d05249dc01b48caa1507ee0e71496c67ba6
2021-06-04ipod6g:: Get rid of magic command numbers in ata driverSolomon Peachy
Use CMD_* macros instead. Makes the code a bit easier to follow. No functional change. Change-Id: Ieb3d8f6fcca503421d3067aafbd0011a908368e0
2021-04-23ata: Rework power management behavior a bitSolomon Peachy
After continued reports of corruption using iFlash adapters, I went digging for more clues, and this combination of changes seemed to solve data corruption with the iFlash adapters on the ipod video: 1) Instead of SLEEP, use STANDBY_IMMEDIATE when we detect drive as an SSD or CFA-compliant device. The latter is technically higher power than the former, but what this means in practice is unclear. 2) Don't check ATA powermanagement flag prior to issuing powermgmt commands. This reverts the previous "workaround" for the FC1307A -- and PM is a mandatory part of the ATA spec for any CFA device. 3) Prior to issuing SLEEP/STANDBY_IMMEDIATE, issue FLUSH CACHE. The ATA spec says this is redundant for the latter, but says nothing about the former. Either way it is always safe to call first. 4) Delete all other FC1307A_WORKAROUND code related to powermgmt flags. Change-Id: I492d06664c097d9bbd5cccfb9f5b516da165b1ee
2021-03-12ATA: Increase delay to power-off when device doesn't support ATA SLEEPSolomon Peachy
The storage subsystem aggressively issues SLEEPNOW events when idle and power off happened a fixed 2s later. This turns out to not be enough time for FC1307A (eg iFlash) adapters to flush outstanding writes. So, when we detect a lack of PM support, increase the poweroff delay to 5 seconds to compensate for not being able to issue the ATA SLEEP command. Hopefully this is enough time. If not, we will have to re-disable PM entirely when we detect these popular adapters. Thankfully that is now just an #ifdef away. Change-Id: I4112b9acb965973d81f70483bd9d595461c7301c
2021-03-11ATA: When device doesn't support powermgmt, only gate ata sleep command.Solomon Peachy
The FC1307A ATA->SD chipset (used by the common iFlash adapters) doesn't support mandatory ATA power management commands, leading to massive data corruption if they were issued. A workaround was identified (54629073ae) that basically disabled all of rockbox's power management code for these adapters, which extends well beyond the specific ATA commands issued. This patch moves the gating test to the issuance of the actual SLEEP, so that the rest of rockbox's PM code can function as intended. This allows the device to get powered down when idle, yielding potentially significant improvements in battery life. Change-Id: Ia13e2405243fe5efe6f68c3a549ab4933567790b
2021-03-04ata: Make ata_disk_is_active() only special-case powermgmt-less devices.Solomon Peachy
SSDs that respect powermgmt commands should be treated the same, as the powermgmt commands are an important part of ensuring it's safe to shut down. And greatly expand the comment explaining things. Change-Id: Ia52b99fca802f495422b5ee097390a72dbc28f61
2021-03-04Always indicate inactive ata disk if device is solid state or doesn't ↵Christian Soffke
support power management Commit 5462907 made sure that SLEEP commands weren't issued on devices that don't support ATA power management commands (e.g. certain CF->SD converters including several iFlash models). Since Rockbox waits for the disk to become inactive in shutdown_hw(), which won't happen in this case, the OS would previously stall during the shutdown process until a timeout was reached. Change-Id: I03bb05f6f6401bb8f0da5d0b76bd3f07681fdc06
2020-11-04pp5020: use ipod firmware timings for ATA PIO.Torne Wuff
Some mSATA adapters seem to have trouble working with Rockbox using our normal PIO timings; the timing value we use is probably out of spec and is different to the OF. Switch to using the OF's timings according to which PIO mode we select. This may not completely resolve problems with these adapters but allows Rockbox to boot and play audio. Change-Id: If73210700eb4af01864b373709ee1d15c775fb11
2020-11-03ATA: Check to see if the ATA device is solid-state (WIP)Solomon Peachy
Not all devices advertise this flag, unfortunately. Change-Id: I6d666febdfcba7598e4d29df7d05c0a288e15158
2020-07-11ATA: Make sure "hard disk" supports power managementSolomon Peachy
The FC-1307 CF->SD converter that is the basis of a lot of ATA->CF devices (including several iflash iFlash models) claims to not support ATA power management commands. Rockbox unconditionally issues those commands as support is mandated by the ATA spec. This patch checks the capability bit, and if it's not supported, does not attempt to put the ATA subsystem to sleep. It is not clear if the problems lie with the SLEEP commands or the wakeup process, but who knows where else the FC1307 violates the ATA specs, and reliability is much more important than power savings. Change-Id: I8b539c579d0449a8a3cfa63cdd1387db990fe820
2020-07-08ATA: In picking PIO modes, word 64 is only valid if word 53 bit 1 is set.Solomon Peachy
Change-Id: I0a7681be7d703c1baa7f8bd7b5e31f04f20f299d
2017-10-26Unify storage threads into oneMichael Sevakis
* Editing a bunch of drivers' thread routines in order to implement a new feature is tedious. * No matter the number of storage drivers, they share one thread. No extra threads needed for CONFIG_STORAGE_MULTI. * Each has an event callback called by the storage thread. * A default callback is provided to fake sleeping in order to trigger idle callbacks. It could also do other default processing. Changes to it will be part of driver code without editing each one. * Drivers may sleep and wake as they please as long as they give a low pulse on their storage bit to ask to go into sleep mode. Idle callback is called on its behalf and driver immediately put into sleep mode. * Drivers may indicate they are to continue receiving events in USB mode, otherwise they receve nothing until disconnect (they do receive SYS_USB_DISCONNECTED no matter what). * Rework a few things to keep the callback implementation sane and maintainable. ata.c was dreadful with all those bools; make it a state machine and easier to follow. Remove last_user_activity; it has no purpose that isn't served by keeping the disk active through last_disk_activity instead. * Even-out stack sizes partly because of a lack of a decent place to define them by driver or SoC or whatever; it doesn't seem too critical to do that anyway. Many are simply too large while at least one isn't really adequate. They may be individually overridden if necessary (figure out where). The thread uses the greatest size demanded. Newer file code is much more frugal with stack space. I barely see use crack 50% after idle callbacks (usually mid-40s). Card insert/eject doesn't demand much. * No forcing of idle callbacks. If it isn't necessary for one or more non-disk storage types, it really isn't any more necessary for disk storage. Besides, it makes the whole thing easier to implement. Change-Id: Id30c284d82a8af66e47f2cfe104c52cbd8aa7215
2017-03-12Do some housekeeping with fat.h and SECTOR_SIZEMichael Sevakis
Many includes of fat.h are pointless. Some includes are just for SECTOR_SIZE. Add a file 'firmware/include/fs_defines.h' for that and to define tuneable values that were scattered amongst various headers. Remove some local definitions of SECTOR_SIZE since they have to be in agreement with the rest of the fs code anyway. (We'll see what's in fact pointless in a moment ;) Change-Id: I9ba183bf58bd87f5c45eba7bd675c7e2c1c18ed5
2015-01-08Get rid of USE_ROCKBOX_USBAmaury Pouly
Except for unfinished or experimental ports, it isthe case that USE_ROCKBOX_USB and HAVE_USBSTACK are both defined or both undefined. Furthermore, it is a leftover of some early developments on the USB stack and doesn't make sense anymore. Change-Id: Ic87a865b6bb4c7c9a8d45d1f0bb0f2fb536b8cad Reviewed-on: http://gerrit.rockbox.org/1091 Reviewed-by: Amaury Pouly <amaury.pouly@gmail.com>
2014-08-08Fix some more straggling stuffMichael Sevakis
* HWCODEC bootloaders * Remove references to thread structures outside the kernel. They are private and should not be used elsewhere. The mrobe-100 is an offender that gets squashed. * The ata.c hack stuff for large sector disks on iPod Video gets squashed for the same reason. I will no longer maintain it, period; please find the real reason for its difficulties. Change-Id: Iae1a675beac887754eb3cc59b560c941077523f5
2013-08-17Cleanup MV/MD macros a little.Michael Sevakis
When using variadic macros there's no need for IF_MD2/IF_MV2 to deal with function parameters. IF_MD/IF_MV are enough. Throw in IF_MD_DRV/ID_MV_VOL that return the parameter if MD/MV, or 0 if not. Change-Id: I7605e6039f3be19cb47110c84dcb3c5516f2c3eb
2012-05-19Add identify() call to reset proceduresJonas Wielicki
This change is motivated by the ATA specs, section 9.2 Software reset protocol (quote): A host should issue an IDENTIFY DEVICE and/or IDENTIFY PACKET DEVICE command after the software reset protocol has completed to determine the current status of features implemented by the device(s). This indeed fixes a local issue with an SSD in an iriver h320. No other tests were carried out. Change-Id: I191444aec3e55f6890020f601c715d0022d09fb6 Reviewed-on: http://gerrit.rockbox.org/218 Reviewed-by: Bertrik Sikken <bertrik@sikken.nl> Reviewed-by: Linus Nielsen Feltzing <linus@haxx.se> Reviewed-by: Peter D'Hoye <peter.dhoye@gmail.com> Tested-by: Peter D'Hoye <peter.dhoye@gmail.com> Reviewed-by: Marcin Bukat <marcin.bukat@gmail.com>
2012-05-08Remove STATICIRAM hackNils Wallménius
It was only needed by the old arm toolchain that we no longer use or support. Change-Id: Id0e6c67477f8834a637079b03cde5fbf9da68b1c Reviewed-on: http://gerrit.rockbox.org/233 Reviewed-by: Nils Wallménius <nils@rockbox.org>
2011-12-08FS#12418 - Merge prototypes from ata-target.h files into new file ↵Boris Gjenero
ata-driver.h. After this change: - ata.h is for users of ata.c - ata-driver.h is for functions implemented by target-specific code and used by ata.c - ata-target.h is for target-specific defines git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31182 a1c6a512-1295-4272-9138-f99709370657
2011-11-27If Rockbox never turns off ATA power, don't compile code for turning it back ↵Boris Gjenero
on. Note that ATA power may still need to be turned on when starting, so that code in ata_init() always remains. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31079 a1c6a512-1295-4272-9138-f99709370657
2011-11-27Add STORAGE_INIT_ATTR to static ata.c functions that are only called via ↵Boris Gjenero
ata_init(). git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31067 a1c6a512-1295-4272-9138-f99709370657
2011-11-08Remove last_sleep when it's not needed because IDE power is never turned off.Boris Gjenero
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30943 a1c6a512-1295-4272-9138-f99709370657
2011-03-05Change the thread api a bit.Thomas Martitz
* Remove THREAD_ID_CURRENT macro in favor of a thread_self() function, this allows thread functions to be simpler. * thread_self_entry() shortcut for kernel.c. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29521 a1c6a512-1295-4272-9138-f99709370657
2011-02-02Clean up multiple definitions of RAM size. Remove -DMEM (make) and MEM ↵Andree Buschmann
(code), use the already defined MEMORYSIZE instead. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29189 a1c6a512-1295-4272-9138-f99709370657
2011-01-22i.MX31: Busy wait for a couple microseconds at most then sleep until next ↵Michael Sevakis
tick when polling drive status. This prevents pointless jumps to overdrive speed from perceived high load when waiting for lengthy ops to complete such as spinup and sleep. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29108 a1c6a512-1295-4272-9138-f99709370657
2011-01-18Try to get some control over #ifdef hell in usb.c by refactoring and inline ↵Michael Sevakis
function use. SYS_USB_DISCONNECTED_ACK hasn't been doing anything useful for the USB thread; remove it. USB thread simply ignores that value. Observe only valid usb_state transitions. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29084 a1c6a512-1295-4272-9138-f99709370657
2011-01-07Oops, that didn't belong in there.Michael Sparmann
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29003 a1c6a512-1295-4272-9138-f99709370657
2011-01-07Fix CS42L55 (iPod Classic) tone controlMichael Sparmann
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29002 a1c6a512-1295-4272-9138-f99709370657
2011-01-04Fix USB storage driver. ata_get_info was no longer filling-in num_sectors ↵Michael Sevakis
after recent ATA changes. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28962 a1c6a512-1295-4272-9138-f99709370657
2011-01-03Fix regression from r28950: ATA broken on MPIO and possibly other targetsMichael Sparmann
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28957 a1c6a512-1295-4272-9138-f99709370657
2011-01-02Fix yellowMichael Sparmann
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28952 a1c6a512-1295-4272-9138-f99709370657
2011-01-02Fix redMichael Sparmann
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28951 a1c6a512-1295-4272-9138-f99709370657
2011-01-02Rework ATA driver to get rid of lots of target-specific constants and allow ↵Michael Sparmann
for non-memory-mapped task file registers. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28950 a1c6a512-1295-4272-9138-f99709370657
2010-05-21ata: do some threading-related corrections (some sync related where it ↵Michael Sevakis
matters). Make sure 'sleeping' is 'false' before the powerup sequence (throws-off powermgmt and it *is* about to woken again and powermgmt will need to compensate). Avoid looking at mutex flag directly; there's no tangible benefit I can discern and changes to the kernel that alter the meaning shouldn't be able to break anything. For that, in the jz sd driver, have sd_disk_is_active just return 'false' like all the other SD drivers do. If it *must* return this, it should implement it's own method but it seems to not matter. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26234 a1c6a512-1295-4272-9138-f99709370657
2010-05-17Do s/SWAP_WORDS/ATA_SWAP_WORDS/ to prevent namespace clashes.Maurus Cuelenaere
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26111 a1c6a512-1295-4272-9138-f99709370657
2010-04-14Make builds with MAX_PHYS_SECTOR_SIZE defined (ipod video) work with larger ↵Torne Wuff
sizes if the drive is sane. The ipod video build has a MAX_PHYS_SECTOR_SIZE of 1024. This meant it would refuse to boot on drives with sectors larger than 1024 bytes, even if those drives don't actually require the workaround originally intended for the 80GB 5.5G's drive. ata_init() will now, if the drive claims to have >512 byte sectors, try and read sector 1 to determine if the drive is capable of emulating 512-byte sector accesses. If this succeeds, we assume the drive is better at it than us (this is very likely to be true) and set phys_sector_mult to 1, disabling the workaround and ensuring the drive will work regardless of sector size. Making use of this change requires that you build and install an updated bootloader as well as the main build; a new iPod bootloader will be released soon, so if you can't do this yourself, be patient. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25646 a1c6a512-1295-4272-9138-f99709370657
2010-04-07Make ATA code not bother to retry requests that return IDNF (specified ↵Torne Wuff
sector not valid). There's no point retrying these requests for five seconds, the sector number isn't going to get any more valid. It interferes with being able to detect broken drives like the 5.5G 80GB iPod's. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25525 a1c6a512-1295-4272-9138-f99709370657
2010-02-01FS#10955 - LBA48 builds doesn't compile after ata read/write unificationTorne Wuff
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24444 a1c6a512-1295-4272-9138-f99709370657
2009-11-24FS#9721 - No error check after writes in ata.cTorne Wuff
Patch by Boris Gjenero (dreamlayers). Writes are retried on failure now so this should be safe. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23741 a1c6a512-1295-4272-9138-f99709370657
2009-11-24FS#10798 - unify ata_read_sectors and ata_write_sectorsTorne Wuff
Writes will now be retried if they fail, and will be done using multisector transfers which should be faster. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23740 a1c6a512-1295-4272-9138-f99709370657
2009-07-17Commit FS#9545, storage cleanup and multi-driver supportFrank Gevaerts
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21933 a1c6a512-1295-4272-9138-f99709370657
2009-06-07Convert a number of places in core and plugins to use the BIT_N() macro ↵Jens Arnold
instead of 1<<n. Speeds up things on SH1, and also reduces core binsize. Most notable speedups: 1 bit lcd driver: drawpixel +20%, drawline + 27%, hline +5%; jpeg viewer: +8% for 1/8 scaling. Other targets are unaffected. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21205 a1c6a512-1295-4272-9138-f99709370657
2009-03-12Commit the common portion of FS#9708: ATA (IDE) DMA by Boris Gjenero with a ↵Michael Sevakis
couple cosmetic tweaks and without the inclusion of 'FS#9721: No error check after writes in ata.c'changes (which can be done separately). No code is changed for targets without HAVE_ATA_DMA defined other than to not display DMA modes in the View Disk Info debug screen if not using DMA (Gigabeat F/X/S were). No target uses the code yet but Gigabeat S use will follow shortly. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20298 a1c6a512-1295-4272-9138-f99709370657
2009-03-05Use total_sectors in ata_get_info() instead of calculating it all over ↵Frank Gevaerts
again. This should fix LBA48 issues. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20208 a1c6a512-1295-4272-9138-f99709370657
2009-02-22Submit FS#9863 by Boris Gjenero. Correct ATA wakeup and power on in case of ↵Andree Buschmann
SYS_USB_CONNECTED. This way HDDs are spun down properly afterwards before rebooting to USB. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20082 a1c6a512-1295-4272-9138-f99709370657
2009-01-13USB retweaking: Take out the USB_REQUEST/RELEASE_DISK scheme and simply ask ↵Michael Sevakis
the USB core whether or not any drivers require exclusive access at the moment of connect. Doing anthing else just produces nasty effects on Windows because it expects some communication just for enabling the PHY and not allowing it to mount volumes if a thread doesn't ack causes annoying error message boxes. Make behavior of each USB type identical from the system perspective. Some miscellaneous changes (simplify, ata->storage naming, define only used USB_* enums values were possible). git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19762 a1c6a512-1295-4272-9138-f99709370657
2008-12-12Reclaim a bit of binsize on hdd based archoses by making the bit test ↵Jens Arnold
unsigned. On SH1, gcc optimizes this by using a right shift, and a signed '1' made it use an arithmetic right-shift-by-n, which is a libgcc function on SH1. This was the only place in the core using it. No effect on other architectures. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19399 a1c6a512-1295-4272-9138-f99709370657
2008-12-10Use cookies for thread identification instead of pointers directly which ↵Michael Sevakis
gives a buffer against wrongly identifying a thread when the slot is recycled (which has been nagging me for awhile). A slot gets 255 uses before it repeats. Everything gets incompatible so a full update is required. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19377 a1c6a512-1295-4272-9138-f99709370657
2008-11-04*_hard_reset() is only used inside ata.c, so there's no need to export it to ↵Frank Gevaerts
the world git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19004 a1c6a512-1295-4272-9138-f99709370657
2008-11-01conditionalise *_get_info() to get some binsize backFrank Gevaerts
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18965 a1c6a512-1295-4272-9138-f99709370657