1*3385b472SRobert Mustacchi.\" 2*3385b472SRobert Mustacchi.\" This file and its contents are supplied under the terms of the 3*3385b472SRobert Mustacchi.\" Common Development and Distribution License ("CDDL"), version 1.0. 4*3385b472SRobert Mustacchi.\" You may only use this file in accordance with the terms of version 5*3385b472SRobert Mustacchi.\" 1.0 of the CDDL. 6*3385b472SRobert Mustacchi.\" 7*3385b472SRobert Mustacchi.\" A full copy of the text of the CDDL should have accompanied this 8*3385b472SRobert Mustacchi.\" source. A copy of the CDDL is also available via the Internet at 9*3385b472SRobert Mustacchi.\" http://www.illumos.org/license/CDDL. 10*3385b472SRobert Mustacchi.\" 11*3385b472SRobert Mustacchi.\" 12*3385b472SRobert Mustacchi.\" Copyright (c) 2017, Joyent, Inc. 13*3385b472SRobert Mustacchi.\" 14*3385b472SRobert Mustacchi.Dd Apr 18, 2017 15*3385b472SRobert Mustacchi.Dt IPORT 9 16*3385b472SRobert Mustacchi.Os 17*3385b472SRobert Mustacchi.Sh NAME 18*3385b472SRobert Mustacchi.Nm iport , 19*3385b472SRobert Mustacchi.Nm iportmap , 20*3385b472SRobert Mustacchi.Nm phymap , 21*3385b472SRobert Mustacchi.Nm tgtmap 22*3385b472SRobert Mustacchi.Nd SCSI Device Management Concepts 23*3385b472SRobert Mustacchi.Sh DESCRIPTION 24*3385b472SRobert MustacchiThe 25*3385b472SRobert Mustacchi.Sy iport , 26*3385b472SRobert Mustacchi.Sy iportmap , 27*3385b472SRobert Mustacchi.Sy phymap , 28*3385b472SRobert Mustacchiand 29*3385b472SRobert Mustacchi.Sy tgtmap 30*3385b472SRobert Mustacchiabstractions enable host bus adapter (HBA) drivers to represent the 31*3385b472SRobert Mustacchidevices that they are responsible for enumerating, as well as the 32*3385b472SRobert Mustacchirelationships between these devices. 33*3385b472SRobert MustacchiThese interfaces simplify device drivers by taking care of the creation 34*3385b472SRobert Mustacchiand destruction of device nodes in the devices tree for enumerated 35*3385b472SRobert Mustacchidevices as well as performing some amount of hysteresis. 36*3385b472SRobert Mustacchi.Pp 37*3385b472SRobert MustacchiThese abstractions are used in tandem with SCSI complex addressing. 38*3385b472SRobert MustacchiA device driver that uses these interfaces generally passes both the 39*3385b472SRobert Mustacchi.Dv SCSI_HBA_HBA 40*3385b472SRobert Mustacchiflag and the 41*3385b472SRobert Mustacchi.Dv SCSI_HBA_ADDR_COMPLEX 42*3385b472SRobert Mustacchiin the 43*3385b472SRobert Mustacchi.Fa hba_flags 44*3385b472SRobert Mustacchiargument to 45*3385b472SRobert Mustacchi.Xr scsi_hba_attach_setup 9F . 46*3385b472SRobert Mustacchi.Ss iport 47*3385b472SRobert MustacchiThe 48*3385b472SRobert Mustacchi.Sy iport , 49*3385b472SRobert Mustacchior initiator port, abstracts a collection of attached devices. 50*3385b472SRobert MustacchiOne way to view an iport is that each iport maps to a phy on the HBA. 51*3385b472SRobert MustacchiA phy refers to a physical connector between the HBA and devices. 52*3385b472SRobert MustacchiA phy may be made up of individual lanes. 53*3385b472SRobert MustacchiA lane is connected to a device, for example a disk driver. 54*3385b472SRobert MustacchiMultiple lanes maybe plugged into the same device, for example, an 55*3385b472SRobert Mustacchiexpander. 56*3385b472SRobert MustacchiWhen a phy connects to a device with a single lane, this is often 57*3385b472SRobert Mustacchicalled a 58*3385b472SRobert Mustacchi.Em narrow phy . 59*3385b472SRobert MustacchiWhen a phy connects to a device with multiple lanes, this is often 60*3385b472SRobert Mustacchicalled a 61*3385b472SRobert Mustacchi.Em wide phy . 62*3385b472SRobert Mustacchi.Pp 63*3385b472SRobert MustacchiConsider a device that has two physical ports, and thus two phys. 64*3385b472SRobert MustacchiEach phy has four lanes, thus we describe the phy as having a mask of 65*3385b472SRobert Mustacchi0xf. 66*3385b472SRobert MustacchiEach bit in the mask corresponds to a specific lane. 67*3385b472SRobert MustacchiIn this example, each phy would be represented in the system by an iport 68*3385b472SRobert Mustacchiand may enumerate a different device for each lane of the phy. 69*3385b472SRobert MustacchiIf an expander is attached to one or more of the lanes of a phy, then 70*3385b472SRobert Mustacchiadditional devices will be enumerated under the expander and be added to 71*3385b472SRobert Mustacchithat phy's iport. 72*3385b472SRobert Mustacchi.Pp 73*3385b472SRobert MustacchiAnother example to consider is when each lane of a phy is directly 74*3385b472SRobert Mustacchiconnected to a single disk through a passive backplane. 75*3385b472SRobert MustacchiIn this case, each lane may represent its own iport, since the 76*3385b472SRobert Mustacchimanagement of each is independent, basically there are many devices each 77*3385b472SRobert Mustacchiwith a mask of 0x1. 78*3385b472SRobert Mustacchi.Pp 79*3385b472SRobert Mustacchiiports do not need to map to a physical phy. 80*3385b472SRobert MustacchiSome HBAs support a combination of both physical and virtual devices. 81*3385b472SRobert MustacchiIn that case, the driver may create two different iports, one for the 82*3385b472SRobert Mustacchiphysical devices and one for the virtual devices. 83*3385b472SRobert Mustacchi.Pp 84*3385b472SRobert MustacchiOne property of iports is that they're attached separately from the main 85*3385b472SRobert Mustacchidevice and therefore have their own 86*3385b472SRobert Mustacchi.Xr scsi_hba_tran 9S 87*3385b472SRobert Mustacchistructure. 88*3385b472SRobert MustacchiAs a result, that means that a driver can provide different 89*3385b472SRobert Mustacchientry points for each iport, especially if they represent different 90*3385b472SRobert Mustacchiclasses of resources, for example one iport for all physical devices and 91*3385b472SRobert Mustacchione for all virtual devices. 92*3385b472SRobert MustacchiThis allows for a driver to return different capabilities, among other 93*3385b472SRobert Mustacchibehaviors and entry points, for these different iports. 94*3385b472SRobert MustacchiOne specific case of this is that while physical devices may provide a 95*3385b472SRobert Mustacchimeans to get to a SCSI WWN, virtual devices may not have a WWN and 96*3385b472SRobert Mustacchiinstead must use a different addressing format. 97*3385b472SRobert Mustacchi.Pp 98*3385b472SRobert Mustacchiiports are considered children of the device driver that attach them, 99*3385b472SRobert Mustacchibut they are bound to the same driver. 100*3385b472SRobert MustacchiThis means that when an iport is created, the 101*3385b472SRobert Mustacchi.Xr attach 9E 102*3385b472SRobert Mustacchiand 103*3385b472SRobert Mustacchi.Xr probe 9E 104*3385b472SRobert Mustacchientry points of the parent driver (usually indicated by passing a 105*3385b472SRobert Mustacchi.Vt dev_info 106*3385b472SRobert Mustacchistructure) will be called. 107*3385b472SRobert MustacchiSimilarly, when an iport is removed from the system, then the driver's 108*3385b472SRobert Mustacchi.Xr detach 9E 109*3385b472SRobert Mustacchientry point will be called. 110*3385b472SRobert MustacchiA driver can determine whether an iport is being attached or not by 111*3385b472SRobert Mustacchicalling the 112*3385b472SRobert Mustacchi.Xr scsi_hba_iport_unit_address 9F 113*3385b472SRobert Mustacchifunction. 114*3385b472SRobert MustacchiThe value will return 115*3385b472SRobert Mustacchi.Dv NULL 116*3385b472SRobert Mustacchiif the attaching device represents the driver. 117*3385b472SRobert Mustacchi.Pp 118*3385b472SRobert MustacchiTo manage iports, drivers have two different options. 119*3385b472SRobert MustacchiIf the set of iport an HBA supports are static, then they should use the 120*3385b472SRobert Mustacchi.Xr scsi_hba_iport_register 9F 121*3385b472SRobert Mustacchifunction to register an iport. 122*3385b472SRobert Mustacchi.Pp 123*3385b472SRobert MustacchiIf instead, the set of iports are dynamic and map to the coming and 124*3385b472SRobert Mustacchigoing of phys discovered by the driver (or some other dynamic source), 125*3385b472SRobert Mustacchithen the driver should use the iportmap set of functions. 126*3385b472SRobert MustacchiSee the section 127*3385b472SRobert Mustacchi.Sx phymap and iportmap 128*3385b472SRobert Mustacchifor more information. 129*3385b472SRobert Mustacchi.Ss tgtmap 130*3385b472SRobert MustacchiThe target map represents a set of devices that have been enumerated 131*3385b472SRobert Mustacchiunder an iport. 132*3385b472SRobert MustacchiEach device is represented by a string, which is an address of some 133*3385b472SRobert Mustacchikind. 134*3385b472SRobert MustacchiUsually a physical device's WWN is used. 135*3385b472SRobert Mustacchi.Pp 136*3385b472SRobert MustacchiBy using a target map, the operating system will take 137*3385b472SRobert Mustacchiresponsibility for notifying the driver when devices have come and gone 138*3385b472SRobert Mustacchifrom a target map, once it has settled, and it will also take 139*3385b472SRobert Mustacchiresponsibility for having device nodes come and go, meaning that the 140*3385b472SRobert Mustacchidevice driver does not need to know anything about the devices tree or 141*3385b472SRobert Mustacchiworry about other parts of being a nexus driver. 142*3385b472SRobert Mustacchi.Pp 143*3385b472SRobert MustacchiTarget maps come in two forms which change how the HBA driver is 144*3385b472SRobert Mustacchiresponsible for reporting changes: 145*3385b472SRobert Mustacchi.Bl -enum 146*3385b472SRobert Mustacchi.It 147*3385b472SRobert MustacchiFull-set 148*3385b472SRobert Mustacchi.It 149*3385b472SRobert MustacchiPer-address 150*3385b472SRobert Mustacchi.El 151*3385b472SRobert Mustacchi.Pp 152*3385b472SRobert MustacchiIn the full-set mode, the driver always reports the full set of current 153*3385b472SRobert Mustacchidevices that it sees. 154*3385b472SRobert MustacchiWhen the driver finishes the report, the operating system will inform 155*3385b472SRobert Mustacchithe driver of addresses that were added and addresses that were removed. 156*3385b472SRobert MustacchiThese addresses correspond to newly found devices and recently removed 157*3385b472SRobert Mustacchidevices, respectively. 158*3385b472SRobert MustacchiThe full-set mode allows for a simpler device driver, particularly if 159*3385b472SRobert Mustacchiaddition and removal notifications may be dropped by the hardware. 160*3385b472SRobert Mustacchi.Pp 161*3385b472SRobert MustacchiWhen using the per-address mode of a target map, the HBA driver is 162*3385b472SRobert Mustacchiresponsible for indicating which addresses have come and gone from the 163*3385b472SRobert Mustacchisystem. 164*3385b472SRobert Mustacchi.Pp 165*3385b472SRobert MustacchiIn either mode, the driver will receive two callbacks, if they have been 166*3385b472SRobert Mustacchiregistered when the target map was created. 167*3385b472SRobert MustacchiThe first callback fires before a target driver like sd, ses, etc. is 168*3385b472SRobert Mustacchiattached. 169*3385b472SRobert MustacchiThe second callback fires after the corresponding driver has been 170*3385b472SRobert Mustacchiattached. 171*3385b472SRobert MustacchiThese allow the HBA driver to perform any operations that are 172*3385b472SRobert Mustacchirequired on the devices. 173*3385b472SRobert Mustacchi.Pp 174*3385b472SRobert MustacchiEach target map has two different sets of devices that it manages in 175*3385b472SRobert Mustacchithis form. 176*3385b472SRobert MustacchiThe devices are separated into the following groups: 177*3385b472SRobert Mustacchi.Bl -enum 178*3385b472SRobert Mustacchi.It 179*3385b472SRobert MustacchiSCSI Devices 180*3385b472SRobert Mustacchi.It 181*3385b472SRobert MustacchiSMP (SCSI Management Protocol) devices 182*3385b472SRobert Mustacchi.El 183*3385b472SRobert Mustacchi.Pp 184*3385b472SRobert MustacchiAll SATA, SCSI, SAS, SES, etc. devices all are considered part of the 185*3385b472SRobert Mustacchifirst category. 186*3385b472SRobert Mustacchi.Pp 187*3385b472SRobert MustacchiTarget maps can be created and destroyed with the 188*3385b472SRobert Mustacchi.Xr scsi_hba_tgtmap_create 9F 189*3385b472SRobert Mustacchiand 190*3385b472SRobert Mustacchi.Xr scsi_hba_tgtmap_destroy 9F 191*3385b472SRobert Mustacchifunctions. 192*3385b472SRobert Mustacchi.Pp 193*3385b472SRobert MustacchiThe following functions are used to manage target maps operating in 194*3385b472SRobert Mustacchifull-set mode: 195*3385b472SRobert Mustacchi.Bl -dash 196*3385b472SRobert Mustacchi.It 197*3385b472SRobert Mustacchi.Xr scsi_hba_tgtmap_set_begin 9F 198*3385b472SRobert Mustacchi.It 199*3385b472SRobert Mustacchi.Xr scsi_hba_tgtmap_set_add 9F 200*3385b472SRobert Mustacchi.It 201*3385b472SRobert Mustacchi.Xr scsi_hba_tgtmap_set_end 9F 202*3385b472SRobert Mustacchi.It 203*3385b472SRobert Mustacchi.Xr scsi_hba_tgtmap_set_flush 9F 204*3385b472SRobert Mustacchi.El 205*3385b472SRobert Mustacchi.Pp 206*3385b472SRobert MustacchiThe following functions are used to manage target maps operating in 207*3385b472SRobert Mustacchiper-address mode: 208*3385b472SRobert Mustacchi.Bl -dash 209*3385b472SRobert Mustacchi.It 210*3385b472SRobert Mustacchi.Xr scsi_hba_tgtmap_tgt_add 9F 211*3385b472SRobert Mustacchi.It 212*3385b472SRobert Mustacchi.Xr scsi_hba_tgtmap_tgt_remove 9F 213*3385b472SRobert Mustacchi.El 214*3385b472SRobert Mustacchi.Ss phymap and iportmap 215*3385b472SRobert MustacchiThe phymap and iportmap are often used together to represent complex SAS 216*3385b472SRobert Mustacchitopologies. 217*3385b472SRobert MustacchiThe phymap provides a way to see what phys have been grouped together 218*3385b472SRobert Mustacchiunder the same SAS port. 219*3385b472SRobert MustacchiThe SAS port is represented by the 220*3385b472SRobert Mustacchi.Dq local 221*3385b472SRobert Mustacchiand 222*3385b472SRobert Mustacchi.Dq remote 223*3385b472SRobert MustacchiWWNs. 224*3385b472SRobert MustacchiWhen additional phys come online, if they end up referring to the 225*3385b472SRobert Mustacchisame WWNs, then they'll map to the same port. 226*3385b472SRobert Mustacchi.Pp 227*3385b472SRobert MustacchiThe iportmap is used to maintain a dynamic set of iports related to a 228*3385b472SRobert Mustacchidevice. 229*3385b472SRobert MustacchiThe iports are each identified by an address, which is generally 230*3385b472SRobert Mustacchia unit address string. 231*3385b472SRobert MustacchiFor example, when a new phy is added to the phymap which represents a 232*3385b472SRobert Mustacchinew SAS port being used, then a corresponding iport will be created and 233*3385b472SRobert Mustacchiassociated with that entry from the phymap. 234*3385b472SRobert MustacchiOnce the iport has been created, a normal target map can be created on 235*3385b472SRobert Mustacchitop of it to handle detected SCSI and SMP devices. 236*3385b472SRobert Mustacchi.Pp 237*3385b472SRobert MustacchiBoth the phymap and iportmap operate in a similar fashion to the 238*3385b472SRobert Mustacchiper-address mode of a tgtmap. 239*3385b472SRobert MustacchiEntries can be added and removed through direct functions. 240*3385b472SRobert MustacchiThe phymap provides callbacks similar to the tgtmap; however, the 241*3385b472SRobert Mustacchiiportmap does not. 242*3385b472SRobert MustacchiThis is because when an iport is added or removed, a new node is added 243*3385b472SRobert Mustacchito the devices tree and the driver's 244*3385b472SRobert Mustacchi.Xr attach 9E 245*3385b472SRobert Mustacchientry point is called with a new 246*3385b472SRobert Mustacchi.Vt dev_info_t 247*3385b472SRobert Mustacchistructure representing the iport. 248*3385b472SRobert Mustacchi.Pp 249*3385b472SRobert MustacchiDuring the phymap callback, the HBA driver should create a new iport 250*3385b472SRobert Mustacchiwith the unit address passed in from the callback function. 251*3385b472SRobert MustacchiThis relationship is important when taking advantage of the ability to 252*3385b472SRobert Mustacchimap between an iport and the set of phys that it represents. 253*3385b472SRobert Mustacchi.Pp 254*3385b472SRobert MustacchiThe following functions are used to manage iportmaps: 255*3385b472SRobert Mustacchi.Bl -dash 256*3385b472SRobert Mustacchi.It 257*3385b472SRobert Mustacchi.Xr scsi_hba_iportmap_create 9F 258*3385b472SRobert Mustacchi.It 259*3385b472SRobert Mustacchi.Xr scsi_hba_iportmap_iport_add 9F 260*3385b472SRobert Mustacchi.It 261*3385b472SRobert Mustacchi.Xr scsi_hba_iportmap_iport_remove 9F 262*3385b472SRobert Mustacchi.It 263*3385b472SRobert Mustacchi.Xr scsi_hba_iportmap_destroy 9F 264*3385b472SRobert Mustacchi.El 265*3385b472SRobert Mustacchi.Pp 266*3385b472SRobert MustacchiThe following functions are used to manage phymaps: 267*3385b472SRobert Mustacchi.Bl -dash 268*3385b472SRobert Mustacchi.It 269*3385b472SRobert Mustacchi.Xr sas_phymap_create 9F 270*3385b472SRobert Mustacchi.It 271*3385b472SRobert Mustacchi.Xr sas_phymap_destroy 9F 272*3385b472SRobert Mustacchi.It 273*3385b472SRobert Mustacchi.Xr sas_phymap_phy_add 9F 274*3385b472SRobert Mustacchi.It 275*3385b472SRobert Mustacchi.Xr sas_phymap_phy_rem 9F 276*3385b472SRobert Mustacchi.El 277*3385b472SRobert Mustacchi.Ss SCSI Complex Addressing 278*3385b472SRobert MustacchiTraditionally, SCSI devices were represented by a simple structure, the 279*3385b472SRobert Mustacchi.Xr scsi_address 9S . 280*3385b472SRobert MustacchiThis represented devices by a simple target and lun number. 281*3385b472SRobert MustacchiWhile this interface is useful for simple devices and traditional 282*3385b472SRobert Mustacchiparallel SCSI devices, it is not as useful for SAS-era devices where the 283*3385b472SRobert MustacchiSCSI bus is now a fabric. 284*3385b472SRobert MustacchiA driver may opt into such a complex addressing mode by setting the 285*3385b472SRobert Mustacchi.Dv SCSI_HBA_ADDR_COMPLEX 286*3385b472SRobert Mustacchiflag. 287*3385b472SRobert Mustacchi.Pp 288*3385b472SRobert MustacchiWhen this flag is set, the HBA driver must treat the SCSI address 289*3385b472SRobert Mustacchias an opaque structure. 290*3385b472SRobert MustacchiOnce in this mode, the driver may get and set a private data structure 291*3385b472SRobert Mustacchion the SCSI device. 292*3385b472SRobert MustacchiThis is facilitated by the 293*3385b472SRobert Mustacchi.Xr scsi_device_hba_private_set 9F 294*3385b472SRobert Mustacchiand 295*3385b472SRobert Mustacchi.Xr scsi_device_hba_private_get 9F 296*3385b472SRobert Mustacchifunctions. 297*3385b472SRobert MustacchiIn addition, the system provides a means to map between the 298*3385b472SRobert Mustacchi.Xr scsi_address 9S 299*3385b472SRobert Mustacchistructure and the corresponding 300*3385b472SRobert Mustacchi.Xr scsi_device 9S 301*3385b472SRobert Mustacchistructure. 302*3385b472SRobert MustacchiThis is performed by the 303*3385b472SRobert Mustacchi.Xr scsi_device_unit_address 9F 304*3385b472SRobert Mustacchifunction. 305*3385b472SRobert Mustacchi.Sh SEE ALSO 306*3385b472SRobert Mustacchi.Xr attach 9E , 307*3385b472SRobert Mustacchi.Xr detach 9E , 308*3385b472SRobert Mustacchi.Xr sas_phymap_create 9F , 309*3385b472SRobert Mustacchi.Xr sas_phymap_destroy 9F , 310*3385b472SRobert Mustacchi.Xr sas_phymap_phy_add 9F , 311*3385b472SRobert Mustacchi.Xr sas_phymap_phy_rem 9F , 312*3385b472SRobert Mustacchi.Xr scsi_device_hba_private_get 9F , 313*3385b472SRobert Mustacchi.Xr scsi_device_hba_private_set 9F , 314*3385b472SRobert Mustacchi.Xr scsi_device_unit_address 9F , 315*3385b472SRobert Mustacchi.Xr scsi_hba_attach_setup 9F , 316*3385b472SRobert Mustacchi.Xr scsi_hba_iport_register 9F , 317*3385b472SRobert Mustacchi.Xr scsi_hba_iport_unit_address 9F , 318*3385b472SRobert Mustacchi.Xr scsi_hba_iportmap_create 9F , 319*3385b472SRobert Mustacchi.Xr scsi_hba_iportmap_destroy 9F , 320*3385b472SRobert Mustacchi.Xr scsi_hba_iportmap_iport_add 9F , 321*3385b472SRobert Mustacchi.Xr scsi_hba_iportmap_iport_remove 9F , 322*3385b472SRobert Mustacchi.Xr scsi_hba_tgtmap_create 9F , 323*3385b472SRobert Mustacchi.Xr scsi_hba_tgtmap_destroy 9F , 324*3385b472SRobert Mustacchi.Xr scsi_hba_tgtmap_set_add 9F , 325*3385b472SRobert Mustacchi.Xr scsi_hba_tgtmap_set_begin 9F , 326*3385b472SRobert Mustacchi.Xr scsi_hba_tgtmap_set_end 9F , 327*3385b472SRobert Mustacchi.Xr scsi_hba_tgtmap_set_flush 9F , 328*3385b472SRobert Mustacchi.Xr scsi_hba_tgtmap_tgt_add 9F , 329*3385b472SRobert Mustacchi.Xr scsi_hba_tgtmap_tgt_remove 9F , 330*3385b472SRobert Mustacchi.Xr scsi_address 9S , 331*3385b472SRobert Mustacchi.Xr scsi_device 9S , 332*3385b472SRobert Mustacchi.Xr scsi_hba_tran 9S 333