Commit graph

87 commits

Author SHA1 Message Date
Alexander Motin 519b24f029 CAM: Replace random sbuf_printf() with cheaper cat/putc. 2023-11-22 18:04:05 -05:00
Warner Losh 2ffd30f7ee cam: Remove left-over sys/cdefs.h in sys/cam
These weren't removed when $FreeBSD$ was removed. They aren't needed and
now are a style(9) nonconformity.

Sponsored by:		Netflix
2023-11-06 12:20:23 -07:00
Warner Losh fd9a4a67d0 cam: Minor opt_cam.h cleanup
sys/cam/cam.h includes opt_cam.h, so none of the clients need to do
this. cam.h does all the right dancing to conditionally include
opt_cam.h only when it makes sense. It generally only matters when
cam_debug.h is included (it must be included before that). Many of the
stray opt_cam.h includes were after cam_debug.h which would be a problem
were it not included in cam/cam.h. The other users of CAM options that
aren't debug all already include cam/cam.h.

Also trim unneeded sys/cdefs.h files from the files touched.

Sponsored by:		Netflix
2023-11-06 10:47:15 -07:00
Warner Losh 031beb4e23 sys: Remove $FreeBSD$: one-line sh pattern
Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
2023-08-16 11:54:58 -06:00
Warner Losh 685dc743dc sys: Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:36 -06:00
Warner Losh 2ff63af9b8 sys: Remove $FreeBSD$: one-line .h pattern
Remove /^\s*\*+\s*\$FreeBSD\$.*$\n/
2023-08-16 11:54:18 -06:00
Warner Losh 95ee2897e9 sys: Remove $FreeBSD$: two-line .h pattern
Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
2023-08-16 11:54:11 -06:00
John Baldwin 83453b46e8 mmc_xpt: Update function name in debug trace
Reported by:	mav
Fixes:		7eb538974c cam mmc_xpt/nvme_xpt: Add _sbuf variants of {an,de}nounce xport and proto ops
2023-08-01 16:14:58 -07:00
John Baldwin b2c44f1fc1 cam: Remove non-sbuf announce/denounce proto and xport ops
Reviewed by:	mav, imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D41264
2023-08-01 15:25:38 -07:00
John Baldwin 7eb538974c cam mmc_xpt/nvme_xpt: Add _sbuf variants of {an,de}nounce xport and proto ops
Reviewed by:	imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D41261
2023-08-01 15:23:25 -07:00
John Baldwin 32734eb14c mmc_xpt: Remove dubious end of mmc_print_ident
The end of this function finishes the passed in sbuf, calls printf
manually on the contents, and then clears it.  The caller then tries
to print the resulting sbuf.  This works currently but will not work
for future callers that pass in an external sbuf to be appended to.

Reviewed by:	mav
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D41260
2023-08-01 15:20:53 -07:00
Warner Losh 73551d4f60 cam/mmc: Migrate to modern uintXX_t from u_intXX_t
As per https://lists.freebsd.org/archives/freebsd-scsi/2023-July/000257.html
move to the modern uintXX_t.

MFC After:	3 days
Sponsored by:	Netflix
2023-07-24 21:32:57 -06:00
Warner Losh 4d846d260e spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD
The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with:		pfg
MFC After:		3 days
Sponsored by:		Netflix
2023-05-12 10:44:03 -06:00
Mitchell Horne 489ba22236 kerneldump: remove physical argument from d_dumper
The physical address argument is essentially ignored by every dumper
method. In addition, the dump routines don't actually pass a real
address; every call to dump_append() passes a value of zero for
physical.

Reviewed by:	markj
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D35173
2022-05-13 10:42:48 -03:00
Andriy Gapon 6fd84a627f mmc_da: create disk(9) for pre-2.0 SD cards
It does not look like there is anything in mmc_da code that actually
requires protocol 2.0 or later.  dev/mmc code also does not have such a
restriction.

Tested with a very old 2GB mini-SD card.  Prior to this change mmc_da
would claim the card but would not expose it to GEOM.

Without MMCCAM:
 mmc0: <MMC/SD bus> on sdhci_pci0
 mmc0: Probing bus
 mmc0: SD probe: OK (OCR: 0x00ff8000)
 mmc0: Current OCR: 0x00ff8000
 mmc0: CMD8 failed, RESULT: 1
 mmc0: Probing cards
 mmc0: New card detected (CID 1c53565344432020100002982e007600)
 mmc0: New card detected (CSD 005e00325f5a83d02db7ffbf96800000)
 mmc0: Card at relative address 0xb368 added:
 mmc0:  card: SD SDC   1.0 SN 0002982E MFG 06/2007 by 28 SV
 mmc0:  quirks: 0
 mmc0:  bus: 4bit, 50MHz (high speed timing)
 mmc0:  memory: 3998720 blocks, erase sector 256 blocks
 mmc0: setting transfer rate to 50.000MHz (high speed timing)
 GEOM: new disk mmcsd0
 mmcsd0: 2GB <SD SDC   1.0 SN 0002982E MFG 06/2007 by 28 SV> at mmc0 50.0MHz/4bit/65535-block
 mmc0: setting bus width to 4 bits high speed timing

With MMCCAM and this change:
 sdda0 at sdhci_slot0 bus 0 scbus2 target 0 lun 0
 sdda0: Relative addr: 0000b368
 Card features: <Memory>
 sdda0: Serial Number 0002982E
 sdda0: SD SDC   1.0 SN 0002982E MFG 06/2007 by 28 SV
 GEOM: new disk sdda0

Reviewed by:	manu
MFC after:	3 weeks
2022-01-27 18:59:54 +02:00
Andriy Gapon dfb1c97ab9 mmc_da: remove write-only local variables
MFC after:	1 week
2022-01-12 09:17:35 +02:00
Andriy Gapon 60b7d5a24a mmc_da: use MMC_SECTOR_SIZE constant in place of literals
Suggested by:	manu
MFC after:	2 weeks
2022-01-12 09:14:36 +02:00
Andriy Gapon 44682688f0 mmc_da: implement d_dump method, sddadump
sddadump has been derived from sddastart.

mmc_sim interface has grown a new method, cam_poll, to support polled
operation.

mmc_sim code has been changed to provide a sim_poll hook only if the
controller implements the new method.  The hooks is implemented in terms
of the new mmc_sim_cam_poll method.
Additionally, in-progress CCB-s now have CAM_REQ_INPROG status to
satisfy xpt_pollwait().

mmc_sim_cam_poll method has been implemented in dwmmc host controller.

Reviewed by:	manu, mav, imp
MFC after:	2 weeks
Relnotes:	perhaps
Differential Revision:	https://reviews.freebsd.org/D33843
2022-01-12 09:02:47 +02:00
Andriy Gapon 8eca341d9b follow up to 18679ab1, actually change size of mmc_sim::name to 16
The change was made locally but was not squashed into the commit.

Fixes:		18679ab1 mmc_sim: fix setting of the mutex name
MFC after:	8 days
2021-12-17 13:24:53 +02:00
Andriy Gapon 18679ab1c0 mmc_sim: fix setting of the mutex name
To quote the manual:
 The pointer passed in as name and type is saved rather than the data
 it points to.  The data pointed to must remain stable until the mutex
 is destroyed.

It seems that the type is actually copied, but the name is stored as
a pointer indeed.
mmc_cam_sim_alloc used a name stored on stack.
So, a corrupt mutex name would be reported.
For example:
  lock order reversal: (sleepable after non-sleepable)
  1st 0xd7285b20 <8A><C0><C0>P@<C1><D0>P@<C1>^D^A (aw_mmc_sim, sleep mutex) @ sys/cam/cam_xpt.c:2804

This change moves the name to struct mmc_sim.
Also, that name is used as the sim name as well.
Unused mtx_name variable is removed too.
The name buffer is reduced to 16 characters.

Reviewed by:	manu, bz
MFC after:	10 days
Differential Revision:	https://reviews.freebsd.org/D33412
2021-12-15 13:42:02 +02:00
Andriy Gapon 8b37048bc5 Revert "mmc_sim: fix setting of the mutex name"
This reverts commit df472af034.

The change hasn't been reviewed.
2021-12-13 13:51:47 +02:00
Andriy Gapon df472af034 mmc_sim: fix setting of the mutex name
To quote the manual:
 The pointer passed in as name and type is saved rather than the data
 it points to.  The data pointed to must remain stable until the mutex
 is destroyed.

It seems that the type is actually copied, but the name is stored as
a pointer indeed.
mmc_cam_sim_alloc used a name stored on stack.
So, a corrupt mutex name would be reported.
For example:
  lock order reversal: (sleepable after non-sleepable)
  1st 0xd7285b20 <8A><C0><C0>P@<C1><D0>P@<C1>^D^A (aw_mmc_sim, sleep mutex) @ /usr/devel/git/orange/sys/cam/cam_xpt.c:2804

This change moves the name to struct mmc_sim.
Also, that name is used as the sim name as well.
Unused mtx_name variable is removed too.
2021-12-13 13:40:47 +02:00
Andriy Gapon e17b58ecbc sddadone: 'error' gets assigned only errno codes, never MMC_ERR codes
MFC after:	2 weeks
2021-11-13 11:20:14 +02:00
John Baldwin d2bc7754a2 Assert that invalid bus widths can't be passed to bus_width_str().
This appeases a -Wreturn-type warning from GCC.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D31935
2021-09-15 09:03:17 -07:00
Andriy Gapon 66c183f43f mmc_cam_sim_default_action: do not touch the ccb after dispatching it
If MMC_SIM_CAM_REQUEST() is successful the ccb could be running or being
completed as the method returns.  Modifying the ccb status could override
whatever status was already set by a MMC driver.

I am not sure what was the purpose of setting the status to CAM_REQ_INVALID
in the success path.  I assume that it was to catch a possibility that the
ccb could be completed without its status explicitly set.  So, I am keeping
the code, it's just moved to before the MMC_SIM_CAM_REQUEST call.

Without this change I was getting random and phantom EIO errors on Rock64
running off an SD card (dwmmc driver) plus occasional panics like:
  Memory modified after free 0xffffa00003985800(2040) val=6 @ 0xffffa00003985854
  panic: Most recently used by CAM CCB

MFC after:	1 week
2021-07-12 21:29:26 +03:00
Edward Tomasz Napierala a081a943a0 cam: drop unused 'saved_ccb' field from softcs
No functional changes.  Do not MFC this, it changes kernel ABI.

Sponsored by:	NetApp, Inc.
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D30698
2021-07-06 10:04:38 +01:00
Warner Losh a72af82e31 cam: Fix GENERIC-MMCCAM build
Fix forgotten argument and type error. MMCCAM isn't enabled by default,
and I'd mistakenly thought it was, so these went undetected precommit.

Sponsored by:		Netflix
2021-06-28 17:22:35 -06:00
Warner Losh bd69852be1 mmc_sim: stop using cam_sim_alloc_dev
Use the vanilla flavor of cam_sim_alloc. Now that sdiob has been
converted to get the device_t from the cam_path, this data is no longer
necessary.

Reviewed by:		scottl@
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D30856
2021-06-28 16:13:02 -06:00
Warner Losh d6e7349254 cam mmc: Assert that the xpt_bus_register registered a device_t
Reviewed by:		scottl@
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D30854
2021-06-28 15:59:04 -06:00
Emmanuel Vadot 3386347f65 mmc_sim: Make XPT_MMC_GET_TRAN_SETTINGS fully async
Sponsored by:	Diablotin Systems
2021-06-19 19:15:25 +02:00
Emmanuel Vadot 6506efea63 mmccam: Read the common members of CSD v1.0 and v2.0
And only get the differents ones based on the version.

No functional changes intented.

Sponsored by:	Diablotin Systems
2021-06-19 19:06:54 +02:00
Emmanuel Vadot 20d601682e mmccam: Style(9) more mmc_da.c
No functional changes.
Sponsored by:	Diablotin Systems
2021-06-19 19:06:54 +02:00
Emmanuel Vadot af2253f61c mmccam: Add two new XPT for MMC and use them in mmc_sim and sdhci
For the discovery phase of SD/eMMC we need to do some transaction in a async
way.
The classic CAM XPT_{GET,SET}_TRAN_SETTING cannot be used in a async way.
This also allow us to split the discovery phase into a more complete state
machine and we don't mtx_sleep with a random number to wait for completion
of the tasks.
For mmc_sim we now do the SET_TRAN_SETTING in a taskqueue so we can call
the needed function for regulators/clocks without the cam lock(s). This part is
still needed to be done for sdhci.
We also now save the host OCR in the discovery phase as it wasn't done before and
only worked because the same ccb was reused.

Reviewed by:	imp, kibab, bz
Differential Revision:	https://reviews.freebsd.org/D30038
2021-05-21 17:34:05 +02:00
Emmanuel Vadot 80020d7888 mmccam: probe*: Style(9) 2021-04-27 19:03:16 +02:00
Emmanuel Vadot e017c1c92c mmcprobe_done: Style(9) 2021-04-27 19:03:09 +02:00
Emmanuel Vadot 47bde7925b mmccam: Add mmc_sim, a generic sim for mmc driver to use
This adds a generic sim that abstract a lot of what needs to be implemented
in a driver for mmccam support.
A new interface with three methods is added :

 - mmc_sim_get_tran_settings: Use to get what the controller supports in term
   of capabilities, freq etc ...
 - mmc_sim_set_tran_settings: Use to change the speed/freq/etc of the
   sdcard host controller
 - mmc_sim_cam_request: Used for MMCIO requests

Differential Revision:	https://reviews.freebsd.org/D27485
Reviewed by:	kibab
2021-04-27 19:00:38 +02:00
Edward Tomasz Napierala ec5325dbca cam: make sure to clear even more CCBs allocated on the stack
This is my second pass, this time over all of CAM except
for the SCSI target bits.  There should be no functional
changes.

Reviewed By:	imp
Sponsored by:	NetApp, Inc.
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D29549
2021-04-11 15:24:22 +01:00
Emmanuel Vadot ca7ef91285 mmccam: Convert some printf to CAM_DEBUG
This not not useful if you are not debuging mmccam
2020-11-30 14:49:13 +00:00
Konstantin Belousov cd85379104 Make MAXPHYS tunable. Bump MAXPHYS to 1M.
Replace MAXPHYS by runtime variable maxphys. It is initialized from
MAXPHYS by default, but can be also adjusted with the tunable kern.maxphys.

Make b_pages[] array in struct buf flexible.  Size b_pages[] for buffer
cache buffers exactly to atop(maxbcachebuf) (currently it is sized to
atop(MAXPHYS)), and b_pages[] for pbufs is sized to atop(maxphys) + 1.
The +1 for pbufs allow several pbuf consumers, among them vmapbuf(),
to use unaligned buffers still sized to maxphys, esp. when such
buffers come from userspace (*).  Overall, we save significant amount
of otherwise wasted memory in b_pages[] for buffer cache buffers,
while bumping MAXPHYS to desired high value.

Eliminate all direct uses of the MAXPHYS constant in kernel and driver
sources, except a place which initialize maxphys.  Some random (and
arguably weird) uses of MAXPHYS, e.g. in linuxolator, are converted
straight.  Some drivers, which use MAXPHYS to size embeded structures,
get private MAXPHYS-like constant; their convertion is out of scope
for this work.

Changes to cam/, dev/ahci, dev/ata, dev/mpr, dev/mpt, dev/mvs,
dev/siis, where either submitted by, or based on changes by mav.

Suggested by: mav (*)
Reviewed by:	imp, mav, imp, mckusick, scottl (intermediate versions)
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
Differential revision:	https://reviews.freebsd.org/D27225
2020-11-28 12:12:51 +00:00
Emmanuel Vadot 2fe1b4ca42 mmccam: We can't sleep during sdda_add_part so use M_NOWAIT
Reviewed by:	kibab
Differential Revision:	https://reviews.freebsd.org/D25947
2020-11-26 16:39:56 +00:00
Jung-uk Kim 7e06495b9b Do not truncate the last character from serial number.
strlcpy() requires one more byte for the NULL character.

Submitted by:	Henri Hennebert (hlh at restart dot be)
MFC after:	3 days
2020-11-24 21:14:36 +00:00
Ilya Bakulin b6b885c4fe Always return MMC errors from mmc_handle_reply()
There are two ways to propagate the error in MMCCAM:
 * Using cmd.error which is set by the peripheral driver;
 * Using CCB status which is... also set by the driver.

The problem is that those two error conditions don't necessarily match.
This leads to the confusion when handling the MMC reply. So enforce the consistency
by panicking if request is marked as completed successfully but MMC-level error
is present (this hints to the programming error).

Reviewed by:	manu
Approved by:	imp (mentor)
Differential Revision:	https://reviews.freebsd.org/D26925
2020-11-03 21:38:59 +00:00
Andriy Gapon 15f4848ab7 mmc_da: universally use uint8_t for the partition index
Also, assert in sdda_init_switch_part() that the index is within the
defined range.

MFC after:	1 week
2020-09-08 06:19:23 +00:00
Andriy Gapon fd38fa398a mmc_da: fix a typo and a too long line
MFC after:	1 week
2020-09-08 06:18:34 +00:00
Andriy Gapon 4dfdaf4d92 mmc_da: make sure that part_index is not used uninitialized in sddastart
This is a fix to r334065.

Without this change I once got stuck I/O with endless partition switching:

(sdda0:aw_mmc_sim2:0:0:0): sddastart
(sdda0:aw_mmc_sim2:0:0:0): Partition  0 -> -525703168
(sdda0:aw_mmc_sim2:0:0:0): xpt_action: func 0x91d XPT_MMC_IO
(sdda0:aw_mmc_sim2:0:0:0): xpt_done: func= 0x91d XPT_MMC_IO status 0x1
(sdda0:aw_mmc_sim2:0:0:0): sddadone
(sdda0:aw_mmc_sim2:0:0:0): Card status: 00000000
(sdda0:aw_mmc_sim2:0:0:0): Current state: 4
(sdda0:aw_mmc_sim2:0:0:0): Compteting partition switch to 0

Note that -525703168 (an int) is 0xe0aa6800 in binary representation.
The partition indexes are actually stored as uint8_t, so that value
was converted / truncated to zero.

MFC after:	1 week
2020-09-08 05:46:10 +00:00
Mateusz Guzik 27dcd3d90b cam: clean up empty lines in .c and .h files 2020-09-01 22:13:48 +00:00
Bjoern A. Zeeb 1e5d733503 mmc_da: fix memory leak in sddaregister()
In case we are failing to allocate mmcdata, we are returning with
a softc allocated but not attached to anything and thus leak the
memory.

Reviewed by:	scottl
MFC after:	2 weeks
X-MFC:		only if we also mfc other mmccam changes?
Differential Revision:	https://reviews.freebsd.org/D25987
2020-08-07 19:58:16 +00:00
Emmanuel Vadot e70d59c0dd mmccam: Unhold the periph when we add the device
Otherwise the device node aren't created.

Pointy hat to:	     manu
Reported by:	bz
2020-08-06 08:21:33 +00:00
Ilya Bakulin 9ea7265066 Minor cleanups in mmc_xpt.c
* Downgrade some CAM debug messages from _INFO to _DEBUG level;
 * Add KASSERT for the case when we suspect incorrect CAM SIM initialization (using cam_sim_alloc() instead of cam_sim_alloc_dev());
 * Use waiting version of xpt_alloc_ccb(), we are not in hurry;
 * With the waiting version we cannot get NULL return, so remove the NULL check;
 * In some csses, the name of mmcprobe_done has been written as mmc_probedone();
 * Send AC_LOST_DEVICE if we, well, lost the device;
 * Misc style(9) fixes.

Reviewed by:	manu
Approved by:	imp (mentor)
Differential Revision:	https://reviews.freebsd.org/D25843
2020-08-04 21:58:43 +00:00
Emmanuel Vadot f2df51ecc5 mmccam: Hold the periph during init
We need to sleep during this routine so acquire the cam hold too.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D25946
2020-08-04 20:04:00 +00:00