Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition) |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
[ source navigation ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]
FreeBSD/Linux Kernel Cross Reference
|
Name | Size | Last modified (GMT) | Description | |
Parent directory | 2008-12-15 18:01:35 | |||
README | 12277 bytes | 1992-02-27 00:31:22 | ||
scsi_33C93.h | 13119 bytes | 1991-08-29 18:52:15 | ||
scsi_33C93_hdw.c | 55673 bytes | 1993-06-02 15:13:27 | ||
scsi_5380.h | 4932 bytes | 1991-08-24 17:21:28 | ||
scsi_5380_hdw.c | 60244 bytes | 1993-06-02 15:13:28 | ||
scsi_53C700.h | 12924 bytes | 1992-02-24 04:07:23 | ||
scsi_53C700_hdw.c | 15743 bytes | 1993-06-02 15:13:29 | ||
scsi_53C94.h | 7926 bytes | 1993-06-02 15:13:30 | ||
scsi_53C94_hdw.c | 74729 bytes | 1993-09-01 21:15:29 | ||
scsi_7061.h | 8723 bytes | 1991-08-24 17:21:36 | ||
scsi_7061_hdw.c | 69200 bytes | 1993-12-24 00:35:21 | ||
scsi_89352.h | 7278 bytes | 1991-07-11 15:08:34 | ||
scsi_89352_hdw.c | 55130 bytes | 1993-06-02 15:13:36 | ||
scsi_aha15.h | 10143 bytes | 1993-06-02 15:13:37 | ||
scsi_aha15_hdw.c | 34520 bytes | 1993-12-24 00:35:22 | ||
scsi_aha17_hdw.c | 34249 bytes | 1993-12-24 00:35:22 | ||
scsi_dma.h | 3757 bytes | 1993-06-02 15:13:39 | ||
scsi_user_dma.c | 4363 bytes | 1991-10-09 20:31:40 | ||
scsi_user_dma.h | 1823 bytes | 1991-10-09 20:31:41 |
1 # 2 # HISTORY 3 # $Log: README,v $ 4 # Revision 2.3 92/02/23 22:43:25 elf 5 # Documented the changes in the MI<->HBA interface functions. 6 # Basically, the first scsi_softc argument is gone. 7 # [92/02/22 19:38:09 af] 8 # 9 # Revision 2.2 91/08/24 12:24:44 af 10 # Created. 11 # [91/08/02 af] 12 # 13 14 This directory contains various examples of HBA support code, 15 among them: 16 17 Chip/Board File Machine tested By 18 19 NCR 53C94 scsi_53C94 DecStation 5000 af@cmu 20 DEC 7061 scsi_7061 DecStation 3100/2100 af@cmu 21 NCR 5380 scsi_5380 VaxStation 3100 af@cmu 22 Fujitsu 89352 scsi_89352 Omron Luna88k danner@cmu 23 Adaptec 1542B scsi_aha15 AT/PC af@cmu 24 25 It should be trivial to modify them for some other machine that uses 26 the same SCSI chips, hopefully by properly conditionalizing and macroizing 27 the existing code. 28 29 There are various rules and assumptions to keep in mind when designing/coding 30 the support code for a new HBA, here is a list. Pls extend this with 31 anything you find is not openly stated here and made your life miserable 32 during the port, and send it back to CMU. 33 34 35 AUTOCONF 36 37 We assume the structures and procedures defined in chips/busses.*, 38 e.g. someone will call configure_bus_master to get to our foo_probe() 39 routine. This should make up its mind on how many targets it sees 40 [see later for dynamic reconfig], allocate a descriptor for each 41 one and leave the driver ready to accept commands (via foo_go()). 42 43 On raw chips you should use a test_unit_ready command, 44 selecting without ATN, and timing out on non-existant 45 devices. Use LUN 0. 46 On boards, there probably is a command to let the board do 47 it (see Adaptec), if not do as above. 48 49 The typical autoconf descriptor might look like 50 51 caddr_t foo_std[NFOO] = { 0 }; 52 struct bus_device *foo_dinfo[NFOO*8]; 53 struct bus_ctlr *foo_minfo[NFOO]; 54 struct bus_driver foo_driver = 55 { foo_probe, scsi_slave, scsi_attach, foo_go, foo_std, "rz", 56 foo_dinfo, "foo", foo_minfo, BUS_INTR_B4_PROBE}; 57 58 which indicates that foo_probe() and foo_go() are our interface functions, 59 and we use the generic scsi_slave() and scsi_attach() for the rest. 60 Their definition is 61 62 foo_probe(reg, ui) 63 vm_offset_t reg; 64 struct bus_ctlr *ui; 65 66 [the "reg" argument might actually be something else on architectures that 67 do not use memory mapped I/O] 68 69 aha_go(tgt, cmd_count, in_count, cmd_only) 70 target_info_t *tgt; 71 boolean_t cmd_only; 72 73 The foo_go() routine is fairly common across chips, look at any example to 74 see how to structure it. Basically, the arguments tell us how much data 75 to expect in either direction, and whether (cmd_only) we think we should 76 be selecting with ATN (cmd_only==FALSE) or not. The only gotcha is cmd_count 77 actually includes the size of any parameters. 78 79 The "go" field of the scsi_softc structure describing your HBA should be 80 set to your foo_go() routine, by the foo_probe() routine. 81 82 DATA DEPENDENCIES 83 84 The upper layer assumes that tgt->cmd_ptr is a pointer to good memory 85 [e.g. no funny padding] where it places the scsi command control blocks 86 AND small (less than 255 bytes) parameters. It also expects small results 87 in there (things like read_capacity, for instance). I think I cleaned 88 up all the places that used to assume tgt->cmd_ptr was aligned, but do not 89 be surprised if I missed one. 90 91 It does NOT use the dma_ptr, or any of the transient_state fields. 92 93 WATCHDOG 94 95 There is an optional MI watchdog facility, which can be used quite simply by 96 filling in the "watchdog" field of the scsi_softc structure describing 97 your HBA. To disable it, leave the field zero (or, dynamically, zero the 98 timeout value). You can use a watchdog of your own if you like, or more 99 likely set this field to point to the MI scsi_watchdog(). 100 This requires that your foo_softc descriptor starts off with a watchdog_t 101 structure, with the "reset" field pointing to a function that will 102 reset the SCSI bus should the watchdog expire. 103 104 When a new SCSI command is initiated you should 105 if (foo->wd.nactive++ == 0) 106 foo->wd.watchdog_state = SCSI_WD_ACTIVE; 107 to activate the watchdog, on each interrupt [or other signal that all 108 is proceeding well for the command and it is making progress] you should 109 if (foo->wd.nactive) 110 foo->wd.watchdog_state = SCSI_WD_ACTIVE; 111 bump down the watchdog 'trigger level', and when the command terminates 112 if (aha->wd.nactive-- == 1) 113 aha->wd.watchdog_state = SCSI_WD_INACTIVE; 114 115 When you detect a SCSI bus reset (possibly we initiated it) you should 116 aha->wd.nactive = 0; 117 and after cleaning up properly invoke 118 scsi_bus_was_reset(sc) 119 scsi_softc_t sc; 120 121 The functiona that is invoked on watchdog expiry is 122 foo_reset_scsibus(foo) 123 register foo_softc_t foo; 124 125 Note that this can be used for dumb chips that do not support select timeouts 126 in hardware [see the 5380 or 7061 code], but its primary use is to detect 127 instances where a target is holding on the SCSI bus way too long. 128 129 The one drawback of resetting the bus is that some devices (like tapes) 130 lose status in case of a reset, and the MI code does not (yet?) try to 131 keep enough information around to be able to recover. If you want to 132 add something very useful you might change the rz_tape.c code to do just 133 that, e.g. on SCSI_RET_ABORTs wait a while for the tape to do whatever, 134 then rewind, and seek forward where the tape should have been positioned at 135 the beginning of the command that failed, then reissue the command. 136 None of the examples so far tries to be 'smart' like making an attempt 137 to get the bus unstuck without resetting it, send us ideas if you have 138 some. 139 140 141 DYNAMIC RECONFIG 142 143 Your code should be ready to add/remove targets on the fly. To do so, 144 notify the upper layer that a target went offline returning 145 SCSI_RET_DEVICE_DOWN when e.g. the select timed out, and clear out 146 the tgt->flags field. 147 To find new devices, define a function 148 149 boolean_t 150 foo_probe_target(tgt, ior) 151 target_info_t *tgt; 152 io_req_t ior; 153 154 and install it in the "probe" field of the scsi_softc_t structure describing 155 the HBA to the upper layer. This function should finalize all HBA-specific 156 info in the target_info structure, then do a scsi_inquiry and check the 157 return code. If this is not SCSI_RET_DEVICE_DOWN the target should be 158 marked TGT_ALIVE. 159 160 161 COMMAND TERMINATION 162 163 Generally, command termination should be reported to the upper layers 164 by setting the tgt->done field to the proper value [it should remain 165 SCSI_RET_IN_PROGRESS while the command is executing] and invoking the 166 target's completion routine, like: 167 if (tgt->ior) { 168 LOG(0xA,"ops->restart"); 169 (*tgt->dev_ops->restart)( tgt, TRUE); 170 } 171 Note that early on some commands will actually wait for completion 172 by spinning on the tgt->done value, because autoconf happens when 173 threads and the scheduler are not working. 174 175 Return SCSI_RET_RETRY if the target was busy, the command will be retried 176 as appropriate. 177 178 Check the completion routines [in rz_disk.c and rz_tape.c for instance] 179 if you are not sure what to return in a troubled case. 180 181 HBA CHIPS GOTCHAS 182 183 All of the examples so far use the idea of 'scripts': the interrupt routine 184 matches the chip state with what is expected and if this is ok (it is 185 in the common important case) it just calls a prepackaged function. 186 We have found this to be _extremely_ simpler than using a state machine 187 of various ridiculous and erroneous sorts, and much more handy for debugging 188 also. Not to mention the saving on code. 189 Nonetheless, there really are no restrictions on how to structure the HBA 190 code, if you prefer state machines go ahead and use them! 191 192 Scheduling of the bus among competing targets is one of the major missing 193 pieces for simple HBAs. A winning strategy used so far is as follows. 194 Allocate a queue_head_t of waiting_targets in your foo_softc, and two 195 target_info_t pointers next_target and active_target. A three-valued 196 state field is also needed. If you enter the foo_go() routine 197 and find the state&BUSY simply enqueue_tail() your tgt on the waiting_targets 198 queue. Otherwise mark the bus BUSY, set next_target to tgt, and proceed 199 to a selection attempt. 200 Note that the attempt might fail and a reselection win over it, therefore 201 the attempt_selection() routine should just retrieve the next_target 202 and install it in active_target, start the selection and let the interrupt 203 routine take care of the rest [see scsi_5380 for a different setup]. 204 If a reselection wins we should note that we had a COLLISION in the state 205 field, install the reconecting target and proceed to completion. 206 When either a command is complete or a target disconnects you should invoke 207 a foo_release_bus() routine, which might look like: 208 209 boolean_t 210 foo_release_bus(foo) 211 register foo_softc_t foo; 212 { 213 boolean_t ret = TRUE; 214 215 LOG(9,"release"); 216 if (foo->state & FOO_STATE_COLLISION) { 217 218 LOG(0xB,"collided"); 219 foo->state &= ~FOO_STATE_COLLISION; 220 foo_attempt_selection(foo); 221 222 } else if (queue_empty(&foo->waiting_targets)) { 223 224 foo->state &= ~FOO_STATE_BUSY; 225 foo->active_target = 0; 226 foo->script = 0; 227 ret = FALSE; 228 229 } else { 230 231 LOG(0xC,"dequeue"); 232 foo->next_target = (target_info_t *) 233 dequeue_head(&foo->waiting_targets); 234 foo_attempt_selection(foo); 235 } 236 return ret; 237 } 238 239 which indicates whether the bus has been handed off to a new target or not. 240 This provides the desired FIFO scheduling of the bus and gives maximum 241 parallelism when targets are allowed to (and infact do) disconnect. 242 243 An area where there are problems most times is how to minimize the 244 interaction of selections and reselections in, e.g. foo_attempt_selection(). 245 This is very much chip specific, but sneaking on the SCSI bus should 246 be a viable alternative in most cases. Check in the specs what happens 247 if you send a command while there is already a reselection pending: 248 a well behaved chip would ignore the command and not screwup its status. 249 [Keep in mind that even if _now_ there is no reselection indication 250 on the next cycle there might be and you won't see it!] 251 252 RANDOM GOTCHAS 253 254 A number of workstations do not provide real DMA support [do not ask me why] 255 but rather a special 'buffer' more or less wide where you have to copy 256 data to and from. This has been handled, see esp the 52C94 code which has 257 even the extreme optimization of issuing the send command even before 258 the data has been copied into the buffer! We have handled even machines 259 where no DMA at all was provided. 260 261 Speaking of DMA.. many of these chips 'prefetch' data, or have a FIFO 262 on board (they have to if they do synch xfers), and when the target 263 disconnects it is always a pain to find out how many bytes exactly did we 264 xfer. Be advised that this hurdle exists, and that the best way to 265 debug your code here is to use a tape. A safe way is to initially 266 disable disconnects [so that you can get the system up from disk] 267 and enable them only on the tape unit that you are using for testing. 268 Later on enable disks but make sure you have some way to recover from 269 a zapped disk ! 270 271 MOVING TO USER SPACE 272 273 All examples have hooks for user-space versions of the driver, the 274 ones for 54C94 and 7061 actually do work. Look in mapped_scsi.c 275 for how this is done, it is fairly simple as far as the kernel is 276 concerned. To keep the option of mapping to user space open you 277 should structure your interrupt routine such that it does all the 278 state gathering and clearing of the interrupt right away. This 279 scheme gives you some assurance that your code will keep on working 280 when the interrupt processing is actually delayed and you recover 281 the interrupt state from the saved structure in the mapped area. 282 283 284 IMPROVEMENTS 285 286 There are a variety of things to be done still, for instance: 287 288 - rewrite scsi_slave() and scsi_attach() to be fully SCSI-II compliant. 289 There are only comments right now as to how that should be done. 290 291 - add enough machinery to the tape code to be able to recover from 292 bus resets. Do so in such a way that other devices might use the ideas. 293 294 - add more devices, like printers scanners modems etc that are currently 295 missing 296 297 - add a 'generic' set_status flavor which simply executes a scsi command 298 passed in from user. This seems the way many vendors and other people 299 have strutured their drivers, it would make it possible to have a common 300 user-level program to do special maintainance work like, for instance, 301 reformatting of disks. 302
[ source navigation ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]
This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.