aboutsummaryrefslogtreecommitdiff
path: root/sys/cam/cam_periph.c
Commit message (Collapse)AuthorAgeFilesLines
...
* Fix a memory leak in the devctl notify code.Scott Long2016-05-031-0/+1
| | | | | | | | Submitted by: markj MFC after: asap Notes: svn path=/head/; revision=298977
* sys/cam: spelling fixes in comments.Pedro F. Giffuni2016-04-291-1/+1
| | | | | | | No functional change. Notes: svn path=/head/; revision=298810
* tag_action is not used at all in ata. It's set to 1 for orderedWarner Losh2016-04-171-1/+1
| | | | | | | | | | | | | | | | transactions, but that value isn't used. It's bogusly used to report in devstat, due to a cut and paste error from SCSI. Mark it as unused in cam_fill_ataio. Reclaim the memory as a new ata_flags. In addition, tag_id and init_id are completely unused, so reclaim those as 'unused' now too. These were needlessly copied when ata was split from scsi. This allows us, in the future, to create structures that can communicate AUXILIARY regsiter to the SIMs, which cannot be done now. Differential Revision: https://reviews.freebsd.org/D5598 Notes: svn path=/head/; revision=298142
* Add a devctl/devd notification conduit for CAM errors that happen at theScott Long2016-04-141-2/+100
| | | | | | | | | | | | | | | | | | | | | | | periph level. When a relevant error is reported to the periph, some amplifying information is gathered, and the error and information are fed to devctl with the attributes / keys system=CAM, subsystem=periph. The 'type' key will be either 'error' or 'timeout', and based on this, various other keys are also populated. The purpose of this is to provide a concise mechanism for error reporting that is less noisy than the system console but higher in resolution and fidelity than simple sysctl counters. We will be using it at Netflix to populate a structured log and database to track errors and error trends across our world-wide population of drives. Submitted by: imp, scottl Approved by: kenm MFC after: 3 days Sponsored by: Netflix Differential Revision: D5943 Notes: svn path=/head/; revision=298004
* Make pass, sg and targ drivers respect HBA's maxio.Alexander Motin2015-09-301-3/+6
| | | | | | | Previous limitation of 64K (DFLTPHYS) is quite annoying. Notes: svn path=/head/; revision=288420
* Refactor unmapped buffer address handling.Jeff Roberson2015-07-231-5/+5
| | | | | | | | | | | | | | | | | | | | - Use pointer assignment rather than a combination of pointers and flags to switch buffers between unmapped and mapped. This eliminates multiple flags and generally simplifies the logic. - Eliminate b_saveaddr since it is only used with pager bufs which have their b_data re-initialized on each allocation. - Gather up some convenience routines in the buffer cache for manipulating buf space and buf malloc space. - Add an inline, buf_mapped(), to standardize checks around unmapped buffers. In collaboration with: mlaier Reviewed by: kib Tested by: pho (many small revisions ago) Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=285819
* Make periphdriver_register() take XPT lock when modifying the periph_driversEdward Tomasz Napierala2015-03-021-1/+12
| | | | | | | | | | | | | array. This fixes a panic that sometimes occured when kldloading ctl.ko. Reviewed by: mav@ MFC after: 1 month Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=279554
* Fix I/O size calculation for pass(4) driver requests and add latencyKenneth D. Merry2015-02-271-6/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | tracking. It is important to subtract the residual from the requested transfer size to see how much data was actually transferred. With tape drives in particular, it is common to request more data than is returned. Also, add I/O latency tracking for CAM requests issued by cam_periph_runccb(). If the caller supplies a struct devstat, and the I/O is a SCSI or ATA I/O, we will track the elapsed time to provide I/O latency statistics for the request. sys/cam/scsi/cam_periph.c: In cam_periph_runccb(), subtract the residual when reporting I/O totals to devstat(9) for SCSI and ATA passthrough requests. In cam_periph_runccb(), grab the I/O start time and supply the start time to devstat_end_transaction() so that it can calculate the elapsed I/O time. Sponsored by: Spectra Logic MFC after: 1 week Notes: svn path=/head/; revision=279375
* Retry indefinitely on SCSI BUSY status from VMware disks and CDs.Alexander Motin2015-02-021-2/+2
| | | | | | | | | | | VMware returns BUSY status when storage has transient connectivity issues. It is often better to wait and let VM admin fix the problem then crash. Discussed with: ken MFC after: 1 week Notes: svn path=/head/; revision=278111
* Don't denounce peripherals on system shutdown. Together with r267321,Marius Strobl2014-06-191-3/+3
| | | | | | | | | | | | | | | we're now back to the pre-r228483 level of default verbosity. This in turn again typically allows for reading information that userland might have printed on the screen before initiating a halt, but still permits to debug potential device shutdown problems on system shutdown via CAM_DEBUG etc. Reviewed by: mav MFC after: 3 days Sponsored by: Bally Wulff Games & Entertainment GmbH Notes: svn path=/head/; revision=267638
* Do not retry on CAM_FUNC_NOTAVAIL error, but return immediately.Alexander Motin2014-03-041-0/+1
| | | | | | | MFC after: 2 weeks Notes: svn path=/head/; revision=262741
* Take additional reference on SCSI probe periph to cover its freeze count.Alexander Motin2014-01-111-0/+11
| | | | | | | | Otherwise periph may be invalidated and freed before single-stepping freeze is dropped, causing use after free panic. Notes: svn path=/head/; revision=260541
* Fix memory and references leak due to unfreed path.Alexander Motin2013-10-221-1/+3
| | | | | | | Coverity CID: 1054773 Notes: svn path=/head/; revision=256895
* Merge CAM locking changes from the projects/camlock branch to radicallyAlexander Motin2013-10-211-45/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | reduce lock congestion and improve SMP scalability of the SCSI/ATA stack, preparing the ground for the coming next GEOM direct dispatch support. Replace big per-SIM locks with bunch of smaller ones: - per-LUN locks to protect device and peripheral drivers state; - per-target locks to protect list of LUNs on target; - per-bus locks to protect reference counting; - per-send queue locks to protect queue of CCBs to be sent; - per-done queue locks to protect queue of completed CCBs; - remaining per-SIM locks now protect only HBA driver internals. While holding LUN lock it is allowed (while not recommended for performance reasons) to take SIM lock. The opposite acquisition order is forbidden. All the other locks are leaf locks, that can be taken anywhere, but should not be cascaded. Many functions, such as: xpt_action(), xpt_done(), xpt_async(), xpt_create_path(), etc. are no longer require (but allow) SIM lock to be held. To keep compatibility and solve cases where SIM lock can't be dropped, all xpt_async() calls in addition to xpt_done() calls are queued to completion threads for async processing in clean environment without SIM lock held. Instead of single CAM SWI thread, used for commands completion processing before, use multiple (depending on number of CPUs) threads. Load balanced between them using "hash" of the device B:T:L address. HBA drivers that can drop SIM lock during completion processing and have sufficient number of completion threads to efficiently scale to multiple CPUs can use new function xpt_done_direct() to avoid extra context switch. Make ahci(4) driver to use this mechanism depending on hardware setup. Sponsored by: iXsystems, Inc. MFC after: 2 months Notes: svn path=/head/; revision=256843
* Unify periph invalidation and destruction reporting.Alexander Motin2013-10-151-1/+6
| | | | | | | | | | Print message containing device model and serial number on invalidation. Requested by: glebius MFC after: 1 week Notes: svn path=/head/; revision=256552
* Add debug trace points for freeze/release device queue.Alexander Motin2013-09-011-0/+3
| | | | Notes: svn path=/head/; revision=255126
* Remove droping topology mutex after iterating 100 periphs in CAMGETPASSTHRU.Alexander Motin2013-08-071-2/+2
| | | | | | | | That is not so slow and so often operation to handle unneeded otherwise xsoftc.xpt_generation and respective locking complications. Notes: svn path=/head/; revision=254058
* Make some improvements to r253322 to really rescan target, not a bus.Alexander Motin2013-07-151-5/+9
| | | | | | | Add there and in two more places checks for NULL on xpt_alloc_ccb_nowait(). Notes: svn path=/head/; revision=253370
* Improve handling of 0x3F/0x0E "Reported LUNs data has changed" and 0x25/0x00Alexander Motin2013-07-131-31/+42
| | | | | | | | | | | | | "Logical unit not supported" errors. First initiates specific target rescan, second -- destroys specific LUN. That allows to automatically detect changes in list of device LUNs. This mechanism doesn't work when target is completely idle, but probably that is all what can be done without active polling. Reviewed by: ken Sponsored by: iXsystems, Inc. Notes: svn path=/head/; revision=253322
* Simplify the checking of flags for cam_periph_mapmem(). This gets rid ofScott Long2013-06-071-12/+13
| | | | | | | | | | | a lot of code redundancy and grossness at very minor expense. Reviewed by: smh Obtained from: Netflix MFC after: 3 days Notes: svn path=/head/; revision=251479
* MFprojects/camlock r249541:Alexander Motin2013-04-271-13/+8
| | | | | | | | | Give periph validity flag own periph reference. That slightly simplifies the release logic and covers hypothetical case if lock is dropped inside the periph_oninval() method. Notes: svn path=/head/; revision=249980
* MFprojects/camlock r248890, r248897, r248898, r248900, r248903, r248905,Alexander Motin2013-04-141-14/+5
| | | | | | | | | | | | | | | | | | | | | r248917, r248918, r248978, r249001, r249014, r249030: Remove multilevel freezing mechanism, implemented to handle specifics of the ATA/SATA error recovery, when post-reset recovery commands should be allocated when queues are already full of payload requests. Instead of removing frozen CCBs with specified range of priorities from the queue to provide free openings, use simple hack, allowing explicit CCBs over- allocation for requests with priority higher (numerically lower) then CAM_PRIORITY_OOB threshold. Simplify CCB allocation logic by removing SIM-level allocation queue. After that SIM-level queue manages only CCBs execution, while allocation logic is localized within each single device. Suggested by: gibbs Notes: svn path=/head/; revision=249466
* MFprojects/camlock:Alexander Motin2013-04-041-7/+6
| | | | | | | | | | | | | | | | | | | r249017: Some cosmetic things: - Unify device to target insertion inside xpt_alloc_device() instead of duplicating it three times. - Remove extra checks for empty lists of devices and targets on release since zero refcount check also implies it. - Reformat code to reduce indentation. r249103: - Add lock assertions to every point where reference counters are modified. - When reference counters are reaching zero, add assertions that there are no children items left. - Add a bit more locking to the xptpdperiphtraverse(). Notes: svn path=/head/; revision=249108
* Fix panic in the error path caused by recursive acquisition of XPT topologyEdward Tomasz Napierala2013-04-021-1/+1
| | | | | | | | | lock. Reviewed by: ken Notes: svn path=/head/; revision=249008
* Do not remap usermode pages into KVA for physio.Konstantin Belousov2013-03-191-1/+1
| | | | | | | | Sponsored by: The FreeBSD Foundation Tested by: pho Notes: svn path=/head/; revision=248515
* Assert that a ccb passed to cam_periph_mapmem() for XPT_SCSI_IO andKonstantin Belousov2013-03-191-0/+4
| | | | | | | | | | XPT_ATA_IO holds virtual buffer address. Sponsored by: The FreeBSD Foundation Tested by: pho Notes: svn path=/head/; revision=248501
* Fix a panic during CAM EDT traversal.Kenneth D. Merry2012-12-071-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The problem was a race condition between the EDT traversal used by things like 'camcontrol devlist', and CAM peripheral driver removal. The EDT traversal code holds the CAM topology lock, and wants to show devices that have been invalidated. It acquires a reference to the peripheral to make sure the peripheral it is examining doesn't go away. However, because the peripheral removal code in camperiphfree() drops the CAM topology lock to call the peripheral's destructor routine, we can run into a situation where the EDT traversal increments the peripheral reference count after free process is already in progress. At that point, the reference count is ignored, because it was 0 when we started the process. Fix this race by setting a flag, CAM_PERIPH_FREE, that I previously added and checked in xptperiphtraverse() and xptpdperiphtravsere(), but failed to use. If the EDT traversal code sees that flag, it will know that the peripheral free process has already started, and that it should not access that peripheral. Also, fix an inconsistency in the locking between xptpdperiphtraverse() and xptperiphtraverse(). They now both hold the CAM topology lock while calling the peripheral traversal function. cam_xpt.c: Change xptperiphtraverse() to hold the CAM topology lock across calls to the traversal function. Take out the comment in xptpdperiphtraverse() that referenced the locking inconsistency. cam_periph.c: Set the CAM_PERIPH_FREE flag when we are in the process of freeing a peripheral driver. Sponsored by: Spectra Logic Corporation MFC after: 1 week Notes: svn path=/head/; revision=244001
* Add explicit check for not set time inside cam_periph_freeze_after_event().Alexander Motin2012-10-141-0/+3
| | | | | | | | | | | | | System time is set later on boot process then initial bus scan by CAM. Until that moment microtime() is equal to microuptime(), and if system boots quickly, the value can be close to zero. That causes settle time waiting even for buses that don't use reset during probe. On my test system this reduces boot time by 1 second if USB enabled, or by 4 seconds if USB disabled. CAM waited for ctl2cam0 bus "settle". Notes: svn path=/head/; revision=241536
* Implement media change notification for DA and CD removable media devices.Alexander Motin2012-07-291-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It includes three parts: 1) Modifications to CAM to detect media media changes and report them to disk(9) layer. For modern SATA (and potentially UAS) devices it utilizes Asynchronous Notification mechanism to receive events from hardware. Active polling with TEST UNIT READY commands with 3 seconds period is used for incapable hardware. After that both CD and DA drivers work the same way, detecting two conditions: "NOT READY: Medium not present" after medium was detected previously, and "UNIT ATTENTION: Not ready to ready change, medium may have changed". First one reported to disk(9) as media removal, second as media insert/change. To reliably receive second event new AC_UNIT_ATTENTION async added to make UAs broadcasted to all periphs by generic error handling code in cam_periph_error(). 2) Modifications to GEOM core to handle media remove and change events. Media removal handled by spoiling all consumers attached to the provider. Media change event also schedules provider retaste after spoiling to probe new media. New flag G_CF_ORPHAN was added to consumers to reflect that consumer is in process of destruction. It allows retaste to create new geom instance of the same class, while previous one is still dying. 3) Modifications to some GEOM classes: DEV -- to report media change events to devd; VFS -- to handle spoiling same as orphan to prevent accessing replaced media. PART class already handles spoiling alike to orphan. Reviewed by: silence on geom@ and scsi@ Tested by: avg Sponsored by: iXsystems, Inc. / PC-BSD MFC after: 2 months Notes: svn path=/head/; revision=238886
* Fix a typo in a panic() call.Kenneth D. Merry2012-06-281-1/+1
| | | | | | | | | PR: kern/169497 Submitted by: Steven Hartland <steven.hartland@multiplay.co.uk> MFC after: 3 days Notes: svn path=/head/; revision=237682
* Add scsi_extract_sense_ccb() -- wrapper around scsi_extract_sense_len().Alexander Motin2012-06-231-16/+5
| | | | | | | It allows to remove number of duplicate checks from several places. Notes: svn path=/head/; revision=237478
* Don't print SCSI Queue Full and CAM_REQUEUE_REQ statuses as errors if theyAlexander Motin2012-06-221-1/+4
| | | | | | | | | were handled and retried. They are part of normal operation for SCSI TCQ. MFC after: 3 days Notes: svn path=/head/; revision=237446
* Make cam_periph_hold() behavior consistent: drop taken reference andAlexander Motin2012-06-211-0/+4
| | | | | | | | | return ENXIO if periph was invalidated while we were waiting for it. MFC after: 1 week Notes: svn path=/head/; revision=237401
* Fix several reference counting and object lifetime issues betweenKenneth D. Merry2012-06-201-4/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | the pass(4) and enc(4) drivers and devfs. The pass(4) driver uses the destroy_dev_sched() routine to schedule its device node for destruction in a separate thread context. It does this because the passcleanup() routine can get called indirectly from the passclose() routine, and that would cause a deadlock if the close routine tried to destroy its own device node. In any case, once a particular passthrough driver number, e.g. pass3, is destroyed, CAM considers that unit number (3 in this case) available for reuse. The problem is that devfs may not be done cleaning up the previous instance of pass3, and will panic if isn't done cleaning up the previous instance. The solution is to get a callback from devfs when the device node is removed, and make sure we hold a reference to the peripheral until that happens. Testing exposed some other cases where we have reference counting issues, and those were also fixed in the pass(4) driver. cam_periph.c: In camperiphfree(), reorder some of the operations. The peripheral destructor needs to be called before the peripheral is removed from the peripheral is removed from the list. This is because once we remove the peripheral from the list, and drop the topology lock, the peripheral number may be reused. But if the destructor hasn't been called yet, there may still be resources hanging around (like devfs nodes) that haven't been fully cleaned up. cam_xpt.c: Add an argument to xpt_remove_periph() to indicate whether the topology lock is already held. scsi_enc.c: Acquire an extra reference to the peripheral during registration, and release it once we get a callback from devfs indicating that the device node is gone. Call destroy_dev_sched_cb() in enc_oninvalidate() instead of calling destroy_dev() in the cleanup routine. scsi_pass.c: Add reference counting to handle peripheral and devfs object lifetime issues. Add a reference to the peripheral and the devfs node in the peripheral registration. Don't attempt to add a physical path alias if the peripheral has been marked invalid. Release the devfs reference once the initial physical path alias taskqueue run has completed. Schedule devfs node destruction in the passoninvalidate(), and release our peripheral reference in a new routine, passdevgonecb() once the devfs node is gone. This allows the peripheral to fully go away, and the peripheral destructor, passcleanup(), will get called. MFC after: 3 days Sponsored by: Spectra Logic Notes: svn path=/head/; revision=237328
* One more major cam_periph_error() rewrite to improve error handling andAlexander Motin2012-06-091-415/+170
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | reporting. It includes: - removing of error messages controlled by bootverbose, replacing them with more universal and informative debugging on CAM_DEBUG_INFO level, that is now built into the kernel by default; - more close following to the arguments submitted by caller, such as SF_PRINT_ALWAYS, SF_QUIET_IR and SF_NO_PRINT; consumer knows better which errors are usual/expected at this point and which are really informative; - adding two new flags SF_NO_RECOVERY and SF_NO_RETRY to allow caller specify how much assistance it needs at this point; previously consumers controlled that by not calling cam_periph_error() at all, but that made behavior inconsistent and debugging complicated; - tuning debug messages and taken actions order to make debugging output more readable and cause-effect relationships visible; - making camperiphdone() (common device recovery completion handler) to also use cam_periph_error() in most cases, instead of own dumb code; - removing manual sense fetching code from cam_periph_error(); I was told by number of people that it is SIM obligation to fetch sense data, so this code is useless and only significantly complicates recovery logic; - making ada, da and pass driver to use cam_periph_error() with new limited recovery options to handle error recovery and debugging in common way; as one of results, CAM_REQUEUE_REQ and other retrying statuses are now working fine with pass driver, that caused many problems before. - reverting r186891 by raj@ to avoid burning few seconds in tight DELAY() loops on device probe, while device simply loads media; I think that problem may already be fixed in other way, and even if it is not, solution must be different. Sponsored by: iXsystems, Inc. MFC after: 2 weeks Notes: svn path=/head/; revision=236814
* Add CAM_DEBUG_INFO debug messages for periph created/invalidated/destroyedAlexander Motin2012-06-071-0/+4
| | | | | | | and for asyncs sent. Notes: svn path=/head/; revision=236713
* Fix a bug introduced in r230000. We were eliminating all LUNs on a targetKenneth D. Merry2012-01-251-1/+14
| | | | | | | | | | | | | in response to CAM_DEV_NOT_THERE, instead of just the LUN in question. This will now just eliminate the specified LUN in response to CAM_DEV_NOT_THERE. Reported by: Richard Todd <rmtodd@servalan.servalan.com> MFC after: 3 days Notes: svn path=/head/; revision=230544
* Fix a race condition in CAM peripheral free handling, lockingKenneth D. Merry2012-01-121-24/+51
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | in the CAM XPT bus traversal code, and a number of other periph level issues. cam_periph.h, cam_periph.c: Modify cam_periph_acquire() to test the CAM_PERIPH_INVALID flag prior to allowing a reference count to be gained on a peripheral. Callers of this function will receive CAM_REQ_CMP_ERR status in the situation of attempting to reference an invalidated periph. This guarantees that a peripheral scheduled for a deferred free will not be accessed during its wait for destruction. Panic during attempts to drop a reference count on a peripheral that already has a zero reference count. In cam_periph_list(), use a local sbuf with SBUF_FIXEDLEN set so that mallocs do not occur while the xpt topology lock is held, regardless of the allocation policy of the passed in sbuf. Add a new routine, cam_periph_release_locked_buses(), that can be called when the caller already holds the CAM topology lock. Add some extra debugging for duplicate peripheral allocations in cam_periph_alloc(). Treat CAM_DEV_NOT_THERE much the same as a selection timeout (AC_LOST_DEVICE is emitted), but forgo retries. cam_xpt.c: Revamp the way the EDT traversal code does locking and reference counting. This was broken, since it assumed that the EDT would not change during traversal, but that assumption is no longer valid. So, to prevent devices from going away while we traverse the EDT, make sure we properly lock everything and hold references on devices that we are using. The two peripheral driver traversal routines should be examined. xptpdperiphtraverse() holds the topology lock for the entire time it runs. xptperiphtraverse() is now locked properly, but only holds the topology lock while it is traversing the list, and not while the traversal function is running. The bus locking code in xptbustraverse() should also be revisited at a later time, since it is complex and should probably be simplified. scsi_da.c: Pay attention to the return value from cam_periph_acquire(). Return 0 always from daclose() even if the disk is now gone. Add some rudimentary error injection support. scsi_sg.c: Fix reference counting in the sg(4) driver. The sg driver was calling cam_periph_release() on close, but never called cam_periph_acquire() (which increments the reference count) on open. The periph code correctly complained that the sg(4) driver was trying to decrement the refcount when it was already 0. Sponsored by: Spectra Logic MFC after: 2 weeks Notes: svn path=/head/; revision=230000
* Mark MALLOC_DEFINEs static that have no corresponding MALLOC_DECLAREs.Ed Schouten2011-11-071-1/+1
| | | | | | | This means that their use is restricted to a single C file. Notes: svn path=/head/; revision=227293
* Add descriptor sense support to CAM, and honor sense residuals properly inKenneth D. Merry2011-10-031-13/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | CAM. Desriptor sense is a new sense data format that originated in SPC-3. Among other things, it allows for an 8-byte info field, which is necessary to pass back block numbers larger than 4 bytes. This change adds a number of new functions to scsi_all.c (and therefore libcam) that abstract out most access to sense data. This includes a bump of CAM_VERSION, because the CCB ABI has changed. Userland programs that use the CAM pass(4) driver will need to be recompiled. camcontrol.c: Change uses of scsi_extract_sense() to use scsi_extract_sense_len(). Use scsi_get_sks() instead of accessing sense key specific data directly. scsi_modes: Update the control mode page to the latest version (SPC-4). scsi_cmds.c, scsi_target.c: Change references to struct scsi_sense_data to struct scsi_sense_data_fixed. This should be changed to allow the user to specify fixed or descriptor sense, and then use scsi_set_sense_data() to build the sense data. ps3cdrom.c: Use scsi_set_sense_data() instead of setting sense data manually. cam_periph.c: Use scsi_extract_sense_len() instead of using scsi_extract_sense() or accessing sense data directly. cam_ccb.h: Bump the CAM_VERSION from 0x15 to 0x16. The change of struct scsi_sense_data from 32 to 252 bytes changes the size of struct ccb_scsiio, but not the size of union ccb. So the version must be bumped to prevent structure mis-matches. scsi_all.h: Lots of updated SCSI sense data and other structures. Add function prototypes for the new sense data functions. Take out the inline implementation of scsi_extract_sense(). It is now too large to put in a header file. Add macros to calculate whether fields are present and filled in fixed and descriptor sense data scsi_all.c: In scsi_op_desc(), allow the user to pass in NULL inquiry data, and we'll assume a direct access device in that case. Changed the SCSI RESERVED sense key name and description to COMPLETED, as it is now defined in the spec. Change the error recovery action for a number of read errors to prevent lots of retries when the drive has said that the block isn't accessible. This speeds up reconstruction of the block by any RAID software running on top of the drive (e.g. ZFS). In scsi_sense_desc(), allow for invalid sense key numbers. This allows calling this routine without checking the input values first. Change scsi_error_action() to use scsi_extract_sense_len(), and handle things when invalid asc/ascq values are encountered. Add a new routine, scsi_desc_iterate(), that will call the supplied function for every descriptor in descriptor format sense data. Add scsi_set_sense_data(), and scsi_set_sense_data_va(), which build descriptor and fixed format sense data. They currently default to fixed format sense data. Add a number of scsi_get_*() functions, which get different types of sense data fields from either fixed or descriptor format sense data, if the data is present. Add a number of scsi_*_sbuf() functions, which print formatted versions of various sense data fields. These functions work for either fixed or descriptor sense. Add a number of scsi_sense_*_sbuf() functions, which have a standard calling interface and print the indicated field. These functions take descriptors only. Add scsi_sense_desc_sbuf(), which will print a formatted version of the given sense descriptor. Pull out a majority of the scsi_sense_sbuf() function and put it into scsi_sense_only_sbuf(). This allows callers that don't use struct ccb_scsiio to easily utilize the printing routines. Revamp that function to handle descriptor sense and use the new sense fetching and printing routines. Move scsi_extract_sense() into scsi_all.c, and implement it in terms of the new function, scsi_extract_sense_len(). The _len() version takes a length (which should be the sense length - residual) and can indicate which fields are present and valid in the sense data. Add a couple of new scsi_get_*() routines to get the sense key, asc, and ascq only. mly.c: Rename struct scsi_sense_data to struct scsi_sense_data_fixed. sbp_targ.c: Use the new sense fetching routines to get sense data instead of accessing it directly. sbp.c: Change the firewire/SCSI sense data transformation code to use struct scsi_sense_data_fixed instead of struct scsi_sense_data. This should be changed later to use scsi_set_sense_data(). ciss.c: Calculate the sense residual properly. Use scsi_get_sense_key() to fetch the sense key. mps_sas.c, mpt_cam.c: Set the sense residual properly. iir.c: Use scsi_set_sense_data() instead of building sense data by hand. iscsi_subr.c: Use scsi_extract_sense_len() instead of grabbing sense data directly. umass.c: Use scsi_set_sense_data() to build sense data. Grab the sense key using scsi_get_sense_key(). Calculate the sense residual properly. isp_freebsd.h: Use scsi_get_*() routines to grab asc, ascq, and sense key values. Calculate and set the sense residual. MFC after: 3 days Sponsored by: Spectra Logic Corporation Notes: svn path=/head/; revision=225950
* In some cases failed SATA disks may report their presence, but don'tAlexander Motin2011-07-291-8/+19
| | | | | | | | | | | | | | | | | | | | respond to any commands. I've found that because of multiple command retries, each of which cause 30s timeout, bus reset and another retry or requeue for many commands, it may take ages to eventually drop the failed device. The odd thing is that those retries continue even after XPT considered device as dead and invalidated it. This patch makes cam_periph_error() to block any command retries after periph was marked as invalid. With that patch all activity completes in 1-2 minutes, just after several timeouts, required to consider device death. This should make ZFS, gmirror, graid, etc. operation more robust. Reviewed by: mjacob@ on scsi@ Approved by: re (kib) Notes: svn path=/head/; revision=224496
* Lay groundwork in CAM for recording and reporting physical path andJustin T. Gibbs2011-06-141-6/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | other device attributes stored in the CAM Existing Device Table (EDT). This includes some infrastructure requried by the enclosure services driver to export physical path information. Make the CAM device advanced info interface accept store requests. sys/cam/scsi/scsi_all.c: sys/cam/scsi/scsi_all.h: - Replace scsi_get_sas_addr() with a scsi_get_devid() which takes a callback that decides whether to accept a particular descriptor. Provide callbacks for NAA IEEE Registered addresses and for SAS addresses, replacing the old function. This is needed because the old function doesn't work for an enclosure address for a SAS device, which is not flagged as a SAS address, but is NAA IEEE Registered. It may be worthwhile merging this interface with the devid match interface. - Add a few more defines for some device ID fields. sbin/camcontrol/camcontrol.c: - Update for the CCB_DEV_ADVINFO interface change. cam/cam_xpt_internal.h: - Add the new fields for the physical path string to the CAM EDT. cam/cam_ccb.h: - Rename CCB_GDEV_ADVINFO to simply CCB_DEV_ADVINFO, and the ccb structure to ccb_dev_advinfo. - Add a flag that changes this CCB's action to store, rather than the default, retrieve. - Add a new buffer type, CDAI_TYPE_PHYS_PATH, for the new CAM EDT physpath field. - Remove the never-implemented transport & proto flags. cam/cam_xpt.c: cam/cam_xpt.h: - Add xpt_getattr(), which provides a wrapper for fetching a device's attribute using the GEOM strings as key. This method currently supports "GEOM::ident" and "GEOM::physpath". Submitted by: will Reviewed by : gibbs Extend the XPT_DEV_MATCH api to allow a device search by device ID. As far as the API is concerned, device ID is a binary blob to be interpreted by the transport layer. The SCSI implementation assumes it is an array of VPD device ID descriptors. sys/cam/cam_ccb.h: Create a new structure, device_id_match_pattern, and update the XPT_DEV_MATCH datastructures and flags so that this pattern type can be used. sys/cam/cam_xpt.c: - A single pattern matching on both inquiry data and device ID is invalid. Report any violators. - Pass device ID match requests through to the new routine scsi_devid_match(). The direct call of a SCSI routine is a layering violation, but no worse than the one a few lines up that checks inquiry data. Defer cleaning this up until our future, larger, rototilling of CAM. - Zero out cam_ed and cam_et nodes on allocation. Prior to this change, device_id_len and device_id were not inialized, preventing proper detection of the presence of this information. sys/cam/scsi/scsi_all.c: sys/cam/scsi/scsi_all.h: Add the scsi_match_devid() routine. Add a helper function for extracting peripherial driver names sys/cam/cam_periph.c: sys/cam/cam_periph.h: Add the cam_periph_list() method which fills an sbuf with a comma delimited list of the peripheral instances associated with a given CAM path. Add a helper functions for SCSI commands used by the SES driver. sys/cam/scsi/scsi_all.c: sys/cam/scsi/scsi_all.h: Add structure definitions and csio filling functions for the receive diagnostic results and send diagnostic commands. Misc CAM XPT cleanups. sys/cam/cam_xpt.c: Broadcast AC_FOUND_DEVICE and AC_PATH_REGISTERED events at the time async event handlers are attached even when registering just for events on a partitular SIM. Previously, you had to register for these events on all SIMs in the system in order to get the initial broadcast even though subsequent device and path arrivals would be delivered. sys/cam/cam_xpt.c: Remove SIM mutex held asserts from path accessors. CAM paths are reference counted and it is this reference count, not the sim mutex, that garantees they are stable. Sponsored by: Spectra Logic Corporation Notes: svn path=/head/; revision=223081
* Remove always false "< 0" check for unsgined int variable. This check isAlexander Motin2011-04-181-2/+0
| | | | | | | | | also duplicate, as the value was already checked for 0 before decrementing. Reported by: rpaulo Notes: svn path=/head/; revision=220786
* Don't automatically send a START UNIT to sequential access devices-Matt Jacob2011-03-031-0/+9
| | | | | | | | | | this might cause them to load the tape unintentionally. Reviewed by: gibbs MFC after: 1 month Notes: svn path=/head/; revision=219241
* Remove unneeded includes of <sys/linker_set.h>. Other headers that useJohn Baldwin2011-01-111-1/+0
| | | | | | | | | it internally contain nested includes. Reviewed by: bde Notes: svn path=/head/; revision=217265
* Fix a few issues related to the XPT_GDEV_ADVINFO CCB.Kenneth D. Merry2010-12-101-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | camcontrol.c: In buildbusdevlist(), don't attempt to get call getdevid() for an unconfigured device, even when the verbose flag is set. The cam_open_btl() call will almost certainly fail. Probe for the buffer size when issuing the XPT_GDEV_ADVINFO CCB. Probing for the buffer size first helps us avoid allocating the maximum buffer size when it really may not be necessary. This also helps avoid errors from cam_periph_mapmem() if we attempt to map more than MAXPHYS. cam_periph.c: In cam_periph_mapmem(), if the XPT_GDEV_ADVINFO CCB shows a bufsiz of 0, we don't have anything to map, so just return. Also, set the maximum mapping size to MAXPHYS instead of DFLTPHYS for XPT_GDEV_ADVINFO CCBs, since they don't actually go down to the hardware. scsi_pass.c: Don't bother mapping the buffer in XPT_GDEV_ADVINFO CCBs if bufsiz is 0. Notes: svn path=/head/; revision=216361
* Add Serial Management Protocol (SMP) passthrough support to CAM.Kenneth D. Merry2010-11-301-0/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This includes support in the kernel, camcontrol(8), libcam and the mps(4) driver for SMP passthrough. The CAM SCSI probe code has been modified to fetch Inquiry VPD page 0x00 to determine supported pages, and will now fetch page 0x83 in addition to page 0x80 if supported. Add two new CAM CCBs, XPT_SMP_IO, and XPT_GDEV_ADVINFO. The SMP CCB is intended for SMP requests and responses. The ADVINFO is currently used to fetch cached VPD page 0x83 data from the transport layer, but is intended to be extensible to fetch other types of device-specific data. SMP-only devices are not currently represented in the CAM topology, and so the current semantics are that the SIM will route SMP CCBs to either the addressed device, if it contains an SMP target, or its parent, if it contains an SMP target. (This is noted in cam_ccb.h, since it will change later once we have the ability to have SMP-only devices in CAM's topology.) smp_all.c, smp_all.h: New helper routines for SMP. This includes SMP request building routines, response parsing routines, error decoding routines, and structure definitions for a number of SMP commands. libcam/Makefile: Add smp_all.c to libcam, so that SMP functionality is available to userland applications. camcontrol.8, camcontrol.c: Add smp passthrough support to camcontrol. Several new subcommands are now available: 'smpcmd' functions much like 'cmd', except that it allows the user to send generic SMP commands. 'smprg' sends the SMP report general command, and displays the decoded output. It will automatically fetch extended output if it is available. 'smppc' sends the SMP phy control command, with any number of potential options. Among other things, this allows the user to reset a phy on a SAS expander, or disable a phy on an expander. 'smpmaninfo' sends the SMP report manufacturer information and displays the decoded output. 'smpphylist' displays a list of phys on an expander, and the CAM devices attached to those phys, if any. cam.h, cam.c: Add a status value for SMP errors (CAM_SMP_STATUS_ERROR). Add a missing description for CAM_SCSI_IT_NEXUS_LOST. Add support for SMP commands to cam_error_string(). cam_ccb.h: Rename the CAM_DIR_RESV flag to CAM_DIR_BOTH. SMP commands are by nature bi-directional, and we may need to support bi-directional SCSI commands later. Add the XPT_SMP_IO CCB. Since SMP commands are bi-directional, there are pointers for both the request and response. Add a fill routine for SMP CCBs. Add the XPT_GDEV_ADVINFO CCB. This is currently used to fetch cached page 0x83 data from the transport later, but is extensible to fetch many other types of data. cam_periph.c: Add support in cam_periph_mapmem() for XPT_SMP_IO and XPT_GDEV_ADVINFO CCBs. cam_xpt.c: Add support for executing XPT_SMP_IO CCBs. cam_xpt_internal.h: Add fields for VPD pages 0x00 and 0x83 in struct cam_ed. scsi_all.c: Add scsi_get_sas_addr(), a function that parses VPD page 0x83 data and pulls out a SAS address. scsi_all.h: Add VPD page 0x00 and 0x83 structures, and a prototype for scsi_get_sas_addr(). scsi_pass.c: Add support for mapping buffers in XPT_SMP_IO and XPT_GDEV_ADVINFO CCBs. scsi_xpt.c: In the SCSI probe code, first ask the device for VPD page 0x00. If any VPD pages are supported, that page is required to be implemented. Based on the response, we may probe for the serial number (page 0x80) or device id (page 0x83). Add support for the XPT_GDEV_ADVINFO CCB. sys/conf/files: Add smp_all.c. mps.c: Add support for passing in a uio in mps_map_command(), so we can map a S/G list at once. Add support for SMP passthrough commands in mps_data_cb(). SMP is a special case, because the first buffer in the S/G list is outbound and the second buffer is inbound. Add support for warning the user if the busdma code comes back with more buffers than will work for the command. This will, for example, help the user determine why an SMP command failed if busdma comes back with three buffers. mps_pci.c: Add sys/uio.h. mps_sas.c: Add the SAS address and the parent handle to the list of fields we pull from device page 0 and cache in struct mpssas_target. These are needed for SMP passthrough. Add support for the XPT_SMP_IO CCB. For now, this CCB is routed to the addressed device if it supports SMP, or to its parent if it does not and the parent does. This is necessary because CAM does not currently support SMP-only nodes in the topology. Make SMP passthrough support conditional on __FreeBSD_version >= 900026. This will make it easier to MFC this change to the driver without MFCing the CAM changes as well. mps_user.c: Un-staticize mpi_init_sge() so we can use it for the SMP passthrough code. mpsvar.h: Add a uio and iovecs into struct mps_command for SMP passthrough commands. Add a cm_max_segs field to struct mps_command so that we can warn the user if busdma comes back with too many segments. Clear the cm_reply when a command gets freed. If it is not cleared, reply frames will eventually get freed into the pool multiple times and corrupt the pool. (This fix is from scottl.) Add a prototype for mpi_init_sge(). sys/param.h: Bump __FreeBSD_version to 900026 for the for the inclusion of the XPT_GDEV_ADVINFO and XPT_SMP_IO CAM CCBs. Notes: svn path=/head/; revision=216088
* When requesting sense data for SIM not doing it automatically (such asAlexander Motin2010-11-081-2/+3
| | | | | | | | ATAPI or USB), request only as much data as requested by consumer. On the way back -- report how much sense data we have actually received. Notes: svn path=/head/; revision=214989
* Protect periph drivers list and rearrange things to minimize the chance ofMatt Jacob2010-06-021-25/+34
| | | | | | | | | | | | | stepping oneself during probing. Don't blindly decrement a periph probe count. Reviewed by: scsi@ Obtained from: Alexander Motin, Atillio Rao, Others MFC after: 1 month Notes: svn path=/head/; revision=208752
* MFp4: Large set of CAM inprovements.Alexander Motin2010-01-281-180/+209
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Unify bus reset/probe sequence. Whenever bus attached at boot or later, CAM will automatically reset and scan it. It allows to remove duplicate code from many drivers. - Any bus, attached before CAM completed it's boot-time initialization, will equally join to the process, delaying boot if needed. - New kern.cam.boot_delay loader tunable should help controllers that are still unable to register their buses in time (such as slow USB/ PCCard/ CardBus devices), by adding one more event to wait on boot. - To allow synchronization between different CAM levels, concept of requests priorities was extended. Priorities now split between several "run levels". Device can be freezed at specified level, allowing higher priority requests to pass. For example, no payload requests allowed, until PMP driver enable port. ATA XPT negotiate transfer parameters, periph driver configure caching and so on. - Frozen requests are no more counted by request allocation scheduler. It fixes deadlocks, when frozen low priority payload requests occupying slots, required by higher levels to manage theit execution. - Two last changes were holding proper ATA reinitialization and error recovery implementation. Now it is done: SATA controllers and Port Multipliers now implement automatic hot-plug and should correctly recover from timeouts and bus resets. - Improve SCSI error recovery for devices on buses without automatic sense reporting, such as ATAPI or USB. For example, it allows CAM to wait, while CD drive loads disk, instead of immediately return error status. - Decapitalize diagnostic messages and make them more readable and sensible. - Teach PMP driver to limit maximum speed on fan-out ports. - Make boot wait for PMP scan completes, and make rescan more reliable. - Fix pass driver, to return CCB to user level in case of error. - Increase number of retries in cd driver, as device may return several UAs. Notes: svn path=/head/; revision=203108