2 .\" This file and its contents are supplied under the terms of the
3 .\" Common Development and Distribution License ("CDDL"), version 1.0.
4 .\" You may only use this file in accordance with the terms of version
7 .\" A full copy of the text of the CDDL should have accompanied this
8 .\" source. A copy of the CDDL is also available via the Internet at
9 .\" http://www.illumos.org/license/CDDL.
12 .\" Copyright (c) 2017, Joyent, Inc.
15 .Dt SCSI_HBA_TGTMAP_CREATE 9F
18 .Nm scsi_hba_tgtmap_create ,
19 .Nm scsi_hba_tgtmap_destroy ,
20 .Nm scsi_hba_tgtmap_set_begin ,
21 .Nm scsi_hba_tgtmap_set_add ,
22 .Nm scsi_hba_tgtmap_set_end ,
23 .Nm scsi_hba_tgtmap_set_flush ,
24 .Nm scsi_hba_tgtmap_tgt_add ,
25 .Nm scsi_hba_tgtmap_tgt_remove
26 .Nd SCSI target map functions
30 .Fo scsi_hba_tgtmap_create
32 .Fa "scsi_tgtmap_mode_t mode"
35 .Fa "void *tgtmap_priv"
36 .Fa "scsi_tgt_activate_cb_t activate_cb"
37 .Fa "scsi_tgt_deactivate_cb_t deactivate_cb"
38 .Fa "scsi_hba_tgtmap_t *tgtmapout"
41 .Fo scsi_hba_tgtmap_destroy
42 .Fa "scsi_hba_tgtmap_t *tgtmap"
45 .Fo (*scsi_tgt_activate_cb_t)
46 .Fa "void *tgtmap_priv"
48 .Fa "scsi_tgtmap_tgt_type_t type"
49 .Fa "void **tgt_privp"
52 .Fo (*scsi_tgt_deactivate_cb_t)
53 .Fa "void *tgtmap_priv"
55 .Fa "scsi_tgtmap_tgt_type_t type"
57 .Fa "scsi_tgtmap_deact_rsn_t deact"
60 .Fo scsi_hba_tgtmap_set_begin
61 .Fa "scsi_hba_tgtmap_t *map"
64 .Fo scsi_hba_tgtmap_set_add
65 .Fa "scsi_hba_tgtmap_t *tgtmap"
66 .Fa "scsi_tgtmap_tgt_type_t type"
71 .Fo scsi_hba_tgtmap_set_end
72 .Fa "scsi_hba_tgtmap_t *map"
75 .Fo scsi_hba_tgtmap_set_flush
76 .Fa "scsi_hba_tgtmap_t *map"
79 .Fo scsi_hba_tgtmap_tgt_add
80 .Fa "scsi_hba_tgtmap_t *tgtmap"
81 .Fa "scsi_tgtmap_tgt_type_t type"
86 .Fo scsi_hba_tgtmap_tgt_remove
87 .Fa "scsi_hba_tgtmap_t *tgtmap"
88 .Fa "scsi_tgtmap_tgt_type_t type"
93 This interface is still evolving in illumos.
94 API and ABI stability is
103 One of the following values:
105 .It Dv SCSI_TM_FULLSET
106 The target map operates by full-set reporting.
107 .It Dv SCSI_TM_PERADDR
108 The target map operates by per-address reporting.
111 A time in microseconds.
113 A time in microseconds.
115 A private value to be passed to callback functions.
117 An optional callback that will be called when a new device is being
120 An optional callback that will be called when an existing devices is
121 removed from the system.
123 Pointer where the target map is stored.
125 Pointer to an allocated target map.
127 The address of the target map entry the callback is acting upon.
129 One of the following values, indicating the type of the target:
131 .It Dv SCSI_TGT_SCSI_DEVICE
132 The target is some form of SCSI device such as a parallel SCSI, SATA,
134 .It Dv SCSI_TGT_SMP_DEVICE
135 The target is a SCSI Management Protocol device.
138 One of the following values, indicating why the target is being removed:
140 .It Dv SCSI_TGT_DEACT_RSN_GONE
141 The device is being deactivated because it is gone.
142 .It Dv SCSI_TGT_DEACT_RSN_CFG_FAIL
143 The device is being deactivated because the configuration callback
145 .It Dv SCSI_TGT_DEACT_RSN_UNSTBL
146 The device is being deactivated because it was added and removed during
147 the stabilization period and therefore is considered unstable.
152 .Fn scsi_hba_tgtmap_create
154 .Fn scsi_hba_tgtmap_destroy
155 functions are used to create and destroy target maps.
156 A target map is used to manage SCSI and SMP (SCSI Management Protocol)
158 For more background on target maps, see
161 To create a target map, the driver should call the
162 .Fn scsi_hba_tgtmap_create
164 Upon successful completion, a pointer to the target map will be placed
171 argument should correspond to the HBA driver's device node or one of its
176 argument describes how addresses are reported into the target map and
177 the functions used to add and remove devices.
182 then the driver must always report all the devices that are in the set
183 and will be told when the corresponding devices have been removed.
186 .Sx Full-Set Reporting
187 for more information.
189 Otherwise, the driver should set the
194 .Fn scsi_hba_tgtmap_tgt_add
196 .Fn scsi_hba_tgtmap_tgt_destroy
199 .Sx Per-Address Reporting
200 for more information.
206 are both times measured in microseconds that control two different
207 properties of the target map and how it behaves.
210 indicates the amount of time that the system should wait to quiesce all
211 changes and consider the resulting system stable.
212 Changes will not be reported until after
216 indicates how much time needs to elapse after creation before an initial
217 enumeration has been completed.
223 arguments are optional function pointers that will be run in the context
224 of devices being added and removed from the system.
225 This allows the HBA driver to perform any required operations prior to
226 the system attaching a target driver such as
230 in the activate case and after the system has detached the driver, in
233 To destroy a target map, a caller should use the
234 .Fn scsi_hba_tgtmap_destroy
236 Destroying a target map causes all currently present devices
237 to be deactivated, as though they were removed, prior to the
238 final destruction of the target map.
240 Target maps allow for callbacks to be registered and called when
241 devices are being added and removed from the system.
242 A driver specifies these when the target map is created by passing in
250 When a new address is registered in a target map and the driver has
251 specified a function in the
253 argument, the driver will eventually have their activation function
255 This call will be asynchronous with respect to the adding and
256 removing of entries, regardless of whether the target map is using
257 per-address or full-set reporting.
258 This call will occur before any driver is bound to the discovered
263 argument will point to the optional, private argument that was passed
265 .Fn scsi_hba_tgtmap_create
266 function when the target map was created.
271 will describe the address and type of the new device and will correspond
272 with the values passed into either the
273 .Fn scsi_hba_tgtmap_set_add
275 .Fn scsi_hba_tgtmap_tgt_add
280 argument is a modifiable private value.
283 points to the value passed in as
286 .Fn scsi_hba_tgtmap_set_add
288 .Fn scsi_hba_tgtmap_tgt_add
290 The driver may change the value as needed.
291 It will receive the value stored in
293 during the deactivate callback.
295 When a target map has been updated to indicate that a device has been
296 removed, then the driver will receive a deactivation callback if it
298 The deactivate callback will occur after a driver has
299 been detached from the corresponding device.
306 arguments to the callback function are the same as for the activate
310 pointer will be set to the value that was passed when the device was
311 added and will reflect any updates made during an activate callback, if
316 argument gives the driver some amount of information as to why device
318 The deactivation reason provides the driver
319 more information about why the address was being removed from the target
320 map which can be useful in the cases that it itself did not issue it.
322 The return value indicates whether or not some amount of rediscovery of
323 the address is desired or not.
324 This is only meaningful in the case where the
327 .Dv SCSI_TGT_DEACT_RSN_CFG_FAIL .
328 If the driver does wish to attempt rediscovery, then it should return
330 Otherwise, the driver should return
332 If in doubt, use the return value
334 Note, even if the driver returns
336 no action may be taken by the system.
337 .Ss Full-Set Reporting
338 Full-Set reporting is one way of managing a target map.
339 In full-set reporting, whenever an update is being made, the entire data
340 set is reported to the target map.
341 The target map then determines which
342 addresses are new, which have been removed, and which have stayed the
343 same and updates the system state appropriately.
344 If devices have been added or removed from the system, then any activate
345 and deactivate endpoints will be called.
347 To begin a new report, the driver should call the
348 .Fn scsi_hba_tgtmap_set_begin
350 Once the report has begun, the driver should add devices by calling the
351 .Fn scsi_hba_tgtmap_set_add
353 Once all devices have been added, the driver should call the
354 .Fn scsi_hba_tgtmap_set_end
355 function to indicate that the target map processing has ended.
356 If driver wishes to discard a report that has begun, but not yet
357 terminated, then the driver should call the
358 .Fn scsi_hba_tgtmap_set_flush
361 When adding entries, the driver should indicate the address of the
364 This will generally be a world wide number (WWN) in a unit-addressable
366 However, the driver may use its own synthetic numbering.
367 This address will be passed to the activate callbacks and will also be
368 used as the address of the
376 argument indicates how the kernel will interpret the type of device.
377 At this time, devices are broken into two broad categories.
378 Things which are some kind of SCSI device, whether parallel, SCSI, SATA
379 behind a SATL, SES, etc. should use the type
380 .Dv SCSI_TGT_SCSI_DEVICE .
382 .Dv SCSI_TGT_SMP_DEVICE ,
383 is for SCSI Management Protocol (SMP) devices.
387 argument will be passed to the activate and deactivate callbacks,
388 allowing the driver to pass around data corresponding to this address.
389 .Ss Per-Address Reporting
390 When using a target map with per-address reporting, the driver is
391 responsible for indicating what devices have been added and removed.
392 This is useful for various hardware configurations where all entries and
393 removals are processes in a highly-reliable fashion where hardware
396 To add a new device, the driver should call the
397 .Fa scsi_hba_tgtmap_tgt_add
403 arguments describe the address and what kind of device the address
405 For more information, see the previous section,
406 .Sx Full-Address Reporting .
409 argument will be passed along to the activate and deactivate functions,
410 allowing the driver to associate a value with the address in question.
412 When a device has been removed, the driver should call the
413 .Fn scsi_hba_tgtmap_tgt_remove
414 function, ensuring that both the
418 arguments match those that were used when calling the
419 .Fn scsi_hba_tgtmap_tgt_add
423 .Fn scsi_hba_tgtmap_create
425 .Fn scsi_hba_tgtmap_destroy
426 functions are generally called from the context of the
430 entry points of HBA drivers and their iports, though may also be called
441 functions for a target map will be called into the driver from
446 .Fn scsi_hba_tgtmap_set_begin ,
447 .Fn scsi_hba_tgtmap_set_add ,
448 .Fn scsi_hba_tgtmap_set_end ,
449 .Fn scsi_hba_tgtmap_set_flush ,
450 .Fn scsi_hba_tgtmap_tgt_add ,
452 .Fn scsi_hba_tgtmap_tgt_remove
453 functions may be called from
458 It is recommended that device drivers do not call these functions from
460 context and instead should schedule deferred work with a task queue
463 if they receive notifications during an interrupt that causes them to
464 need to call these functions.
466 Upon successful completion, the
467 .Fn scsi_hba_tgtmap_create ,
468 .Fn scsi_hba_tgtmap_destroy ,
469 .Fn scsi_hba_tgtmap_set_begin ,
470 .Fn scsi_hba_tgtmap_set_add ,
471 .Fn scsi_hba_tgtmap_set_end ,
472 .Fn scsi_hba_tgtmap_set_flush ,
473 .Fn scsi_hba_tgtmap_tgt_add ,
475 .Fn scsi_hba_tgtmap_tgt_remove