Commit graph

293 commits

Author SHA1 Message Date
Solomon Peachy
646d5f92ef ata: Prevent powering-off ATA hardwre if it reports as mSATA or m.2
As those form factors are typically not runtime removable and as such
expect to always being powered up.

This is an experimental change, and we might revert it if it doens't help

Change-Id: I61187f297866f64589a546352828a0ff8169fa30
2022-12-20 20:38:43 -05:00
Solomon Peachy
0c7394e39a ata: Improve heuristics for detecting SSDs
mSATA devices should be new enough to report their form factor proprerly

Change-Id: I2605c8ee0c97432e6e03bd78719e12bb14837f8d
2022-11-27 09:15:29 -05:00
Solomon Peachy
ce5fe4d108 ata: fix a typo in a definition that's thankfully not used.
Change-Id: I6f2d4d05249dc01b48caa1507ee0e71496c67ba6
2021-06-03 21:04:29 -04:00
Solomon Peachy
00440f2137 ipod6g:: Get rid of magic command numbers in ata driver
Use CMD_* macros instead.  Makes the code a bit easier to follow.

No functional change.

Change-Id: Ieb3d8f6fcca503421d3067aafbd0011a908368e0
2021-06-04 01:03:51 +00:00
Solomon Peachy
aab72f969f ata: Rework power management behavior a bit
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-04-23 13:07:45 +00:00
Solomon Peachy
2743bde09b ATA: Increase delay to power-off when device doesn't support ATA SLEEP
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-12 10:04:52 -05:00
Solomon Peachy
bd507fc7b4 ATA: When device doesn't support powermgmt, only gate ata sleep command.
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-11 19:28:52 +00:00
Solomon Peachy
56a1e87501 ata: Make ata_disk_is_active() only special-case powermgmt-less devices.
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-04 17:37:51 -05:00
Christian Soffke
be99033cbb Always indicate inactive ata disk if device is solid state or doesn't 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
2021-03-04 16:50:50 -05:00
Torne Wuff
5db83c155a pp5020: use ipod firmware timings for ATA PIO.
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-04 03:03:19 +00:00
Solomon Peachy
066d471ae6 ATA: Check to see if the ATA device is solid-state (WIP)
Not all devices advertise this flag, unfortunately.

Change-Id: I6d666febdfcba7598e4d29df7d05c0a288e15158
2020-11-03 19:29:26 +00:00
Solomon Peachy
54629073ae ATA: Make sure "hard disk" supports power management
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-11 22:17:13 -04:00
Solomon Peachy
c79f658125 ATA: In picking PIO modes, word 64 is only valid if word 53 bit 1 is set.
Change-Id: I0a7681be7d703c1baa7f8bd7b5e31f04f20f299d
2020-07-08 17:08:08 +00:00
Michael Sevakis
1654efc313 Unify storage threads into one
* 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-10-26 14:35:41 -04:00
Michael Sevakis
6db80020b4 Do some housekeeping with fat.h and SECTOR_SIZE
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
2017-03-12 22:05:44 -04:00
Amaury Pouly
66690ca987 Get rid of USE_ROCKBOX_USB
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>
2015-01-08 16:07:12 +01:00
Michael Sevakis
9a3400a4a6 Fix some more straggling stuff
* 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
2014-08-08 03:23:29 -04:00
Michael Sevakis
a56f1ca1ed Cleanup MV/MD macros a little.
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
2013-08-17 12:18:22 -04:00
Jonas Wielicki
028c5e35ee Add identify() call to reset procedures
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-19 19:15:04 +02:00
Nils Wallménius
2dda258f99 Remove STATICIRAM hack
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>
2012-05-08 22:46:12 +02:00
Boris Gjenero
e4dbcc414b FS#12418 - Merge prototypes from ata-target.h files into new file 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-12-08 21:23:53 +00:00
Boris Gjenero
e5a7388fc7 If Rockbox never turns off ATA power, don't compile code for turning it back 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-27 17:40:57 +00:00
Boris Gjenero
a99d9eca0b Add STORAGE_INIT_ATTR to static ata.c functions that are only called via ata_init().
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31067 a1c6a512-1295-4272-9138-f99709370657
2011-11-27 04:56:47 +00:00
Boris Gjenero
32eb8275f4 Remove last_sleep when it's not needed because IDE power is never turned off.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30943 a1c6a512-1295-4272-9138-f99709370657
2011-11-08 23:29:25 +00:00
Thomas Martitz
cc889e9d60 Change the thread api a bit.
* 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-03-05 17:48:06 +00:00
Andree Buschmann
5d849a963e Clean up multiple definitions of RAM size. Remove -DMEM (make) and MEM (code), use the already defined MEMORYSIZE instead.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29189 a1c6a512-1295-4272-9138-f99709370657
2011-02-02 17:43:32 +00:00
Michael Sevakis
060609a202 i.MX31: Busy wait for a couple microseconds at most then sleep until next 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-22 09:23:31 +00:00
Michael Sevakis
453550a687 Try to get some control over #ifdef hell in usb.c by refactoring and inline 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-18 14:10:06 +00:00
Michael Sparmann
e1eb3abee4 Oops, that didn't belong in there.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29003 a1c6a512-1295-4272-9138-f99709370657
2011-01-07 23:35:29 +00:00
Michael Sparmann
9b5c95f557 Fix CS42L55 (iPod Classic) tone control
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29002 a1c6a512-1295-4272-9138-f99709370657
2011-01-07 23:09:09 +00:00
Michael Sevakis
18f4889d63 Fix USB storage driver. ata_get_info was no longer filling-in num_sectors after recent ATA changes.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28962 a1c6a512-1295-4272-9138-f99709370657
2011-01-04 17:17:38 +00:00
Michael Sparmann
80b50e7587 Fix regression from r28950: ATA broken on MPIO and possibly other targets
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28957 a1c6a512-1295-4272-9138-f99709370657
2011-01-03 13:09:42 +00:00
Michael Sparmann
6f40387e74 Fix yellow
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28952 a1c6a512-1295-4272-9138-f99709370657
2011-01-02 23:09:01 +00:00
Michael Sparmann
1a1fc09863 Fix red
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28951 a1c6a512-1295-4272-9138-f99709370657
2011-01-02 23:02:55 +00:00
Michael Sparmann
9339be1279 Rework ATA driver to get rid of lots of target-specific constants and allow for non-memory-mapped task file registers.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28950 a1c6a512-1295-4272-9138-f99709370657
2011-01-02 22:51:47 +00:00
Michael Sevakis
ff25b3a208 ata: do some threading-related corrections (some sync related where it 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-21 15:33:31 +00:00
Maurus Cuelenaere
64f5033574 Do s/SWAP_WORDS/ATA_SWAP_WORDS/ to prevent namespace clashes.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26111 a1c6a512-1295-4272-9138-f99709370657
2010-05-17 15:15:38 +00:00
Torne Wuff
99cd7f8c19 Make builds with MAX_PHYS_SECTOR_SIZE defined (ipod video) work with larger 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-14 14:40:03 +00:00
Torne Wuff
62321ed0bd Make ATA code not bother to retry requests that return IDNF (specified 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-04-07 20:01:21 +00:00
Torne Wuff
fb680535f6 FS#10955 - LBA48 builds doesn't compile after ata read/write unification
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24444 a1c6a512-1295-4272-9138-f99709370657
2010-02-01 22:59:36 +00:00
Torne Wuff
640d98de0f FS#9721 - No error check after writes in ata.c
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-24 18:09:21 +00:00
Torne Wuff
b896e86842 FS#10798 - unify ata_read_sectors and ata_write_sectors
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-11-24 18:03:57 +00:00
Frank Gevaerts
c0a5a67387 Commit FS#9545, storage cleanup and multi-driver support
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21933 a1c6a512-1295-4272-9138-f99709370657
2009-07-17 22:28:49 +00:00
Jens Arnold
1d6df54df2 Convert a number of places in core and plugins to use the BIT_N() macro 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-06-07 21:27:05 +00:00
Michael Sevakis
bc8cab4c24 Commit the common portion of FS#9708: ATA (IDE) DMA by Boris Gjenero with a 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-12 02:01:25 +00:00
Frank Gevaerts
ca41779fc6 Use total_sectors in ata_get_info() instead of calculating it all over again. This should fix LBA48 issues.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20208 a1c6a512-1295-4272-9138-f99709370657
2009-03-05 22:14:51 +00:00
Andree Buschmann
65d404ff6a Submit FS#9863 by Boris Gjenero. Correct ATA wakeup and power on in case of 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-02-22 13:24:58 +00:00
Michael Sevakis
6da8b4eb49 USB retweaking: Take out the USB_REQUEST/RELEASE_DISK scheme and simply ask 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
2009-01-13 16:27:35 +00:00
Jens Arnold
0ad97d13fc Reclaim a bit of binsize on hdd based archoses by making the bit test 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-12 07:48:01 +00:00
Michael Sevakis
8cfbd3604f Use cookies for thread identification instead of pointers directly which 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-12-10 08:57:10 +00:00