source: trunk/src/os2ahci/os2ahci.c@ 87

Last change on this file since 87 was 87, checked in by markus, 14 years ago

changed copyright headers according to contract; removed evaluation message

File size: 45.4 KB
Line 
1/******************************************************************************
2 * os2ahci.c - main file for os2ahci driver
3 *
4 * Copyright (c) 2011 thi.guten Software Development
5 * Copyright (c) 2011 Mensys B.V.
6 *
7 * Authors: Christian Mueller, Markus Thielen
8 *
9 * Parts copied from/inspired by the Linux AHCI driver;
10 * those parts are (c) Linux AHCI/ATA maintainers
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 */
26
27#include "os2ahci.h"
28#include "bldday.h"
29
30#include "ioctl.h"
31
32/* -------------------------- macros and constants ------------------------- */
33
34/* parse integer command line parameter */
35#define drv_parm_int(s, value, type, radix) \
36 { \
37 char _far *_ep; \
38 if ((s)[1] != ':') { \
39 cprintf("missing colon (:) after /%c\n", *(s)); \
40 goto init_fail; \
41 } \
42 value = (type) strtol((s) + 2, \
43 (const char _far* _far*) &_ep, \
44 radix); \
45 s = _ep; \
46 }
47
48/* set two-dimensional array of port options */
49#define set_port_option(opt, val) \
50 if (adapter_index == -1) { \
51 /* set option for all adapters and ports */ \
52 memset(opt, val, sizeof(opt)); \
53 } else if (port_index == -1) { \
54 /* set option for all ports on current adapter */ \
55 memset(opt[adapter_index], val, sizeof(*opt)); \
56 } else { \
57 /* set option for specific port */ \
58 opt[adapter_index][port_index] = val; \
59 }
60
61/* ------------------------ typedefs and structures ------------------------ */
62
63/* -------------------------- function prototypes -------------------------- */
64
65void _cdecl small_code_ (void);
66
67static int add_unit_info (IORB_CONFIGURATION _far *iorb_conf, int dt_ai,
68 int a, int p, int d, int scsi_id);
69
70/* ------------------------ global/static variables ------------------------ */
71
72int debug = 0; /* if > 0, print debug messages to COM1 */
73int thorough_scan = 1; /* if != 0, perform thorough PCI scan */
74int init_reset; /* if != 0, reset ports during init */
75
76PFN Device_Help = 0; /* pointer to device helper entry point */
77ULONG RMFlags = 0; /* required by resource manager library */
78PFN RM_Help0 = NULL; /* required by resource manager library */
79PFN RM_Help3 = NULL; /* required by resource manager library */
80HDRIVER rm_drvh; /* resource manager driver handle */
81char rm_drvname[80]; /* driver name as returned by RM */
82USHORT add_handle; /* driver handle (RegisterDeviceClass) */
83UCHAR timer_pool[TIMER_POOL_SIZE]; /* timer pool */
84
85/* resource manager driver information structure */
86DRIVERSTRUCT rm_drvinfo = {
87 "OS2AHCI", /* driver name */
88 "AHCI SATA Driver", /* driver description */
89 "GNU", /* vendor name */
90 CMVERSION_MAJOR, /* RM interface version major */
91 CMVERSION_MINOR, /* RM interface version minor */
92 BLD_YEAR, BLD_MONTH, BLD_DAY, /* date */
93 0, /* driver flags */
94 DRT_ADDDM, /* driver type */
95 DRS_ADD, /* driver sub type */
96 NULL /* driver callback */
97};
98
99ULONG drv_lock; /* driver-level spinlock */
100IORB_QUEUE driver_queue; /* driver-level IORB queue */
101AD_INFO ad_infos[MAX_AD]; /* adapter information list */
102int ad_info_cnt; /* number of entries in ad_infos[] */
103u16 ad_ignore; /* bitmap with adapter indexes to ignore */
104int init_complete; /* if != 0, initialization has completed */
105
106/* apapter/port-specific options saved when parsing the command line */
107u8 emulate_scsi[MAX_AD][AHCI_MAX_PORTS];
108u8 enable_ncq[MAX_AD][AHCI_MAX_PORTS];
109u8 link_speed[MAX_AD][AHCI_MAX_PORTS];
110u8 link_power[MAX_AD][AHCI_MAX_PORTS];
111u8 track_size[MAX_AD][AHCI_MAX_PORTS];
112
113static char init_msg[] = "OS2AHCI driver version %d.%02d\n";
114static char exit_msg[] = "OS2AHCI driver *not* installed\n";
115
116/* ----------------------------- start of code ----------------------------- */
117
118/******************************************************************************
119 * OS/2 device driver main strategy function. This function is only used
120 * for initialization purposes; all other calls go directly to the adapter
121 * device driver's strategy function.
122 */
123USHORT _cdecl c_strat(RPH _far *req)
124{
125 u16 rc;
126
127 switch (req->Cmd) {
128
129 case CMDInitBase:
130 rc = init_drv((RPINITIN _far *) req);
131 break;
132
133 case CMDShutdown:
134 rc = exit_drv(((RPSAVERESTORE _far *) req)->FuncCode);
135 break;
136
137 case CMDGenIOCTL:
138 rc = gen_ioctl((RP_GENIOCTL _far *) req);
139 break;
140
141 default:
142 rc = STDON | STATUS_ERR_UNKCMD;
143 break;
144 }
145
146 return(rc);
147}
148
149/******************************************************************************
150 * Intialize the os2ahci driver. This includes command line parsing, scanning
151 * the PCI bus for supported AHCI adapters, etc.
152 */
153USHORT init_drv(RPINITIN _far *req)
154{
155 RPINITOUT _far *rsp = (RPINITOUT _far *) req;
156 DDD_PARM_LIST _far *ddd_pl = (DDD_PARM_LIST _far *) req->InitArgs;
157 APIRET rmrc;
158 char _far *cmd_line;
159 char _far *s;
160 int adapter_index = -1;
161 int port_index = -1;
162 int invert_option;
163 int optval;
164 u16 vendor;
165 u16 device;
166
167 /* set device helper entry point */
168 Device_Help = req->DevHlpEP;
169
170 /* create driver-level spinlock */
171 DevHelp_CreateSpinLock(&drv_lock);
172
173 /* initialize libc code */
174 init_libc();
175
176 /* print initialization message */
177 cprintf(init_msg, VERSION / 100, VERSION % 100);
178
179 /* register driver with resource manager */
180 if ((rmrc = RMCreateDriver(&rm_drvinfo, &rm_drvh)) != RMRC_SUCCESS) {
181 cprintf("failed to register driver with resource manager (rc = %d)\n", rmrc);
182 goto init_fail;
183 }
184
185 /* parse command line parameters */
186 cmd_line = (char _far *) ((u32) ddd_pl & 0xffff0000l) + ddd_pl->cmd_line_args;
187
188 for (s = cmd_line; *s != 0; s++) {
189 if (*s == '/') {
190 if ((invert_option = (s[1] == '!')) != 0) {
191 s++;
192 }
193 s++;
194 switch (tolower(*s)) {
195
196 case '\0':
197 /* end of command line; can only happen if command line is incorrect */
198 cprintf("incomplete command line option\n");
199 goto init_fail;
200
201 case 'c':
202 /* set COM port base address for debug messages */
203 drv_parm_int(s, com_base, u16, 16);
204 break;
205
206 case 'd':
207 /* increase debug level */
208 if (debug++ == 0) {
209 init_com();
210 }
211 break;
212
213 case 'g':
214 /* add specfied PCI ID as a supported generic AHCI adapter */
215 drv_parm_int(s, vendor, u16, 16);
216 drv_parm_int(s, device, u16, 16);
217 if (add_pci_id(vendor, device)) {
218 cprintf("failed to add PCI ID %04x:%04x\n", vendor, device);
219 goto init_fail;
220 }
221 thorough_scan = 1;
222 break;
223
224 case 't':
225 /* perform thorough PCI scan (i.e. look for individual supported PCI IDs) */
226 thorough_scan = !invert_option;
227 break;
228
229 case 'r':
230 /* reset ports during initialization */
231 init_reset = 1;
232 break;
233
234 case 'a':
235 /* set adapter index for adapter and port-related options */
236 drv_parm_int(s, adapter_index, int, 10);
237 if (adapter_index < 0 || adapter_index >= MAX_AD) {
238 cprintf("invalid adapter index (%d)\n", adapter_index);
239 goto init_fail;
240 }
241 break;
242
243 case 'p':
244 /* set port index for port-related options */
245 drv_parm_int(s, port_index, int, 10);
246 if (port_index < 0 || port_index >= AHCI_MAX_PORTS) {
247 cprintf("invalid port index (%d)\n", port_index);
248 goto init_fail;
249 }
250 break;
251
252 case 'i':
253 /* ignore current adapter index */
254 if (adapter_index >= 0) {
255 ad_ignore |= 1U << adapter_index;
256 }
257 break;
258
259 case 's':
260 /* enable SCSI emulation for ATAPI devices */
261 set_port_option(emulate_scsi, !invert_option);
262 break;
263
264 case 'n':
265 /* enable NCQ */
266 set_port_option(enable_ncq, !invert_option);
267 break;
268
269 case 'l':
270 /* set link speed or power savings */
271 s++;
272 switch (tolower(*s)) {
273 case 's':
274 /* set link speed */
275 drv_parm_int(s, optval, int, 10);
276 set_port_option(link_speed, optval);
277 break;
278 case 'p':
279 /* set power management */
280 drv_parm_int(s, optval, int, 10);
281 set_port_option(link_power, optval);
282 break;
283 default:
284 cprintf("invalid link parameter (%c)\n", *s);
285 goto init_fail;
286 }
287 /* need to reset the port in order to establish link settings */
288 init_reset = 1;
289 break;
290
291 case '4':
292 /* enable 4K sector geometry enhancement (track size = 56) */
293 if (!invert_option) {
294 set_port_option(track_size, 56);
295 }
296 break;
297
298 default:
299 cprintf("invalid option: /%c\n", *s);
300 goto init_fail;
301 }
302 }
303 }
304
305 /* scan PCI bus for supported devices */
306 scan_pci_bus();
307
308 if (ad_info_cnt > 0) {
309 /* initialization succeeded and we found at least one AHCI adapter */
310 ADD_InitTimer(timer_pool, sizeof(timer_pool));
311 mdelay_cal();
312
313 if (DevHelp_RegisterDeviceClass("OS2AHCI", (PFN) add_entry, 0, 1,
314 &add_handle)) {
315 cprintf("error: couldn't register device class\n");
316 goto init_fail;
317 }
318
319 /* allocate context hooks */
320 if (DevHelp_AllocateCtxHook(mk_NPFN(restart_hook), &restart_ctxhook_h) != 0 ||
321 DevHelp_AllocateCtxHook(mk_NPFN(reset_hook), &reset_ctxhook_h) != 0 ||
322 DevHelp_AllocateCtxHook(mk_NPFN(engine_hook), &engine_ctxhook_h)) {
323 cprintf("failed to allocate task-time context hooks\n");
324 goto init_fail;
325 }
326
327 rsp->CodeEnd = (u16) end_of_code;
328 rsp->DataEnd = (u16) &end_of_data;
329 return(STDON);
330
331 } else {
332 /* no adapters found */
333 cprintf(" No adapters found.\n");
334 }
335
336init_fail:
337 /* initialization failed; set segment sizes to 0 and return error */
338 rsp->CodeEnd = 0;
339 rsp->DataEnd = 0;
340
341 /* free context hooks */
342 if (engine_ctxhook_h != 0) DevHelp_FreeCtxHook(engine_ctxhook_h);
343 if (reset_ctxhook_h != 0) DevHelp_FreeCtxHook(reset_ctxhook_h);
344 if (restart_ctxhook_h != 0) DevHelp_FreeCtxHook(restart_ctxhook_h);
345
346 if (rm_drvh != 0) {
347 /* remove driver from resource manager */
348 RMDestroyDriver(rm_drvh);
349 }
350
351 cprintf(exit_msg);
352 return(STDON | ERROR_I24_QUIET_INIT_FAIL);
353}
354
355/******************************************************************************
356 * Generic IOCTL via character device driver. IOCTLs are used to control the
357 * driver operation and to execute native ATA and ATAPI (SCSI) commands from
358 * ring 3 applications.
359 */
360USHORT gen_ioctl(RP_GENIOCTL _far *ioctl)
361{
362 switch (ioctl->Category) {
363
364 case OS2AHCI_IOCTL_CATEGORY:
365
366 switch (ioctl->Function) {
367
368 case OS2AHCI_IOCTL_GET_DEVLIST:
369 return(ioctl_get_devlist(ioctl));
370
371 case OS2AHCI_IOCTL_PASSTHROUGH:
372 return(ioctl_passthrough(ioctl));
373
374 }
375 }
376 return(STDON | STATUS_ERR_UNKCMD);
377}
378
379/******************************************************************************
380 * Device driver exit handler. This handler is called when OS/2 shuts down and
381 * flushes the write caches of all attached devices. Since this is effectively
382 * the same we do when suspending, we'll call out to the corresponding APM
383 * function.
384 *
385 * NOTE: Errors are ignored because there's no way we could stop the shutdown
386 * or do something about the error, unless retrying endlessly is
387 * considered an option.
388 */
389USHORT exit_drv(int func)
390{
391 dprintf("exit_drv(%d) called\n", func);
392
393 if (func == 0) {
394 /* we're only interested in the second phase of the shutdown */
395 return(STDON);
396 }
397
398 apm_suspend();
399 return(STDON);
400}
401
402/******************************************************************************
403 * ADD entry point. This is the main entry point for all ADD requests. Due to
404 * the asynchronous nature of ADD drivers, this function primarily queues the
405 * IORB(s) to the corresponding adapter or port queues, then triggers the
406 * state machine to initiate processing queued IORBs.
407 *
408 * NOTE: In order to prevent race conditions or engine stalls, certain rules
409 * around locking, unlocking and IORB handling in general have been
410 * established. Refer to the comments in "trigger_engine()" for
411 * details.
412 */
413void _cdecl _far _loadds add_entry(IORBH _far *first_iorb)
414{
415 IORBH _far *iorb;
416 IORBH _far *next = NULL;
417
418 spin_lock(drv_lock);
419
420 for (iorb = first_iorb; iorb != NULL; iorb = next) {
421 /* Queue this IORB. Queues primarily exist on port level but there are
422 * some requests which affect the whole driver, most notably
423 * IOCC_CONFIGURATION. In either case, adding the IORB to the driver or
424 * port queue will change the links, thus we need to save the original
425 * link in 'next'.
426 */
427 next = (iorb->RequestControl | IORB_CHAIN) ? iorb->pNxtIORB : 0;
428
429 iorb->Status = 0;
430 iorb->ErrorCode = 0;
431 memset(&iorb->ADDWorkSpace, 0x00, sizeof(ADD_WORKSPACE));
432
433 if (iorb_driver_level(iorb)) {
434 /* driver-level IORB */
435 iorb->UnitHandle = 0;
436 iorb_queue_add(&driver_queue, iorb);
437
438 } else {
439 /* port-level IORB */
440 int a = iorb_unit_adapter(iorb);
441 int p = iorb_unit_port(iorb);
442 int d = iorb_unit_device(iorb);
443
444 if (a >= ad_info_cnt ||
445 p > ad_infos[a].port_max ||
446 d > ad_infos[a].ports[p].dev_max ||
447 (ad_infos[a].port_map & (1UL << p)) == 0) {
448
449 /* unit handle outside of the allowed range */
450 dprintf("warning: IORB for %d.%d.%d out of range\n", a, p, d);
451 iorb->Status = IORB_ERROR;
452 iorb->ErrorCode = IOERR_CMD_SYNTAX;
453 iorb_complete(iorb);
454 continue;
455 }
456
457 iorb_queue_add(&ad_infos[a].ports[p].iorb_queue, iorb);
458 }
459 }
460
461 /* trigger state machine */
462 trigger_engine();
463
464 spin_unlock(drv_lock);
465}
466
467/******************************************************************************
468 * Trigger IORB queue engine. This is a wrapper function for trigger_engine_1()
469 * which will try to get all IORBs sent on their way a couple of times. If
470 * there are still IORBs ready for processing after this, this function will
471 * hand off to a context hook which will continue to trigger the engine until
472 * all IORBs have been sent.
473 */
474void trigger_engine(void)
475{
476 int i;
477
478 for (i = 0; i < 3; i++) {
479 if (trigger_engine_1() == 0) {
480 /* done -- all IORBs have been sent on their way */
481 return;
482 }
483 }
484
485 /* Something keeps bouncing; hand off to the engine context hook which will
486 * keep trying in the background.
487 */
488 DevHelp_ArmCtxHook(0, engine_ctxhook_h);
489}
490
491/******************************************************************************
492 * Trigger IORB queue engine in order to send commands in the driver/port IORB
493 * queues to the AHCI hardware. This function will return the number of IORBs
494 * sent. Keep in mind that IORBs might "bounce" if the adapter/port is not in
495 * a state to accept the command, thus it might take quite a few calls to get
496 * all IORBs on their way. This is why there's a wrapper function which tries
497 * it a few times, then hands off to a context hook which will keep trying in
498 * the background.
499 *
500 * IORBs might complete before send_iorb() has returned, at any time during
501 * interrupt processing or on another CPU on SMP systems. IORB completion
502 * means modifications to the corresponding IORB queue (the completed IORB
503 * is removed from the queue) thus we need to protect the IORB queues from
504 * race conditions. The safest approach short of keeping the driver-level
505 * spinlock aquired permanently is to keep it throughout this function and
506 * release it temporarily in send_iorb().
507 *
508 * This implies that the handler functions are fully responsible for aquiring
509 * the driver-level spinlock when they need it, and for releasing it again.
510 *
511 * As a rule of thumb, get the driver-level spinlock whenever accessing
512 * volatile variables (IORB queues, values in ad_info[], ...).
513 *
514 * Additional Notes:
515 *
516 * - This function is expected to be called with the spinlock aquired
517 *
518 * - Adapters can be flagged as 'busy' which means no new IORBs are sent (they
519 * just remain in the queue). This can be used to release the driver-level
520 * spinlock while making sure no new IORBs are going to hit the hardware.
521 * In order to prevent engine stalls, all handlers using this functionality
522 * need to invoke trigger_engine() after resetting the busy flag.
523 *
524 * - Driver-level IORBs are not synchronized by adapter-level 'busy' flags.
525 * However, the driver-level queue is worked "one entry at a time" which
526 * means that no new IORBs will be queued on the driver-level queue until
527 * the head element has completed processing. This means that driver-
528 * level IORB handlers don't need to protect against each other. But they
529 * they do need to keep in mind interference with port-level IORBs:
530 *
531 * - Driver-level IORB handlers must obtain the spinlock and/or flag all
532 * adapters as 'busy' which are affected by the driver-level IORB
533 *
534 * - Driver-level IORB handlers must not access the hardware of a
535 * particular adapter if it's flagged as 'busy' by another IORB.
536 */
537int trigger_engine_1(void)
538{
539 IORBH _far *iorb;
540 IORBH _far *next;
541 int iorbs_sent = 0;
542 int a;
543 int p;
544
545 iorbs_sent = 0;
546
547 /* process driver-level IORBs */
548 if ((iorb = driver_queue.root) != NULL && !add_workspace(iorb)->processing) {
549 send_iorb(iorb);
550 iorbs_sent++;
551 }
552
553 /* process port-level IORBs */
554 for (a = 0; a < ad_info_cnt; a++) {
555 AD_INFO *ai = ad_infos + a;
556 if (ai->busy) {
557 /* adapter is busy; don't process any IORBs */
558 continue;
559 }
560 for (p = 0; p <= ai->port_max; p++) {
561 /* send all queued IORBs on this port */
562 next = NULL;
563 for (iorb = ai->ports[p].iorb_queue.root; iorb != NULL; iorb = next) {
564 next = iorb->pNxtIORB;
565 if (!add_workspace(iorb)->processing) {
566 send_iorb(iorb);
567 iorbs_sent++;
568 }
569 }
570 }
571 }
572
573 return(iorbs_sent);
574}
575
576/******************************************************************************
577 * Send a single IORB to the corresponding AHCI adapter/port. This is just a
578 * switch board for calling the corresponding iocc_*() handler function.
579 *
580 * NOTE: This function is expected to be called with the driver-level spinlock
581 * aquired. It will release it before calling any of the handler
582 * functions and re-aquire it when done.
583 */
584void send_iorb(IORBH _far *iorb)
585{
586 /* Mark IORB as "processing" before doing anything else. Once the IORB is
587 * marked as "processing", we can release the spinlock because subsequent
588 * invocations of trigger_engine() (e.g. at interrupt time) will ignore this
589 * IORB.
590 */
591 add_workspace(iorb)->processing = 1;
592 spin_unlock(drv_lock);
593
594 switch (iorb->CommandCode) {
595
596 case IOCC_CONFIGURATION:
597 iocc_configuration(iorb);
598 break;
599
600 case IOCC_DEVICE_CONTROL:
601 iocc_device_control(iorb);
602 break;
603
604 case IOCC_UNIT_CONTROL:
605 iocc_unit_control(iorb);
606 break;
607
608 case IOCC_GEOMETRY:
609 iocc_geometry(iorb);
610 break;
611
612 case IOCC_EXECUTE_IO:
613 iocc_execute_io(iorb);
614 break;
615
616 case IOCC_UNIT_STATUS:
617 iocc_unit_status(iorb);
618 break;
619
620 case IOCC_ADAPTER_PASSTHRU:
621 iocc_adapter_passthru(iorb);
622 break;
623
624 default:
625 /* unsupported call */
626 iorb_seterr(iorb, IOERR_CMD_NOT_SUPPORTED);
627 iorb_done(iorb);
628 break;
629 }
630
631 /* re-aquire spinlock before returning to trigger_engine() */
632 spin_lock(drv_lock);
633}
634
635/******************************************************************************
636 * Handle IOCC_CONFIGURATION requests.
637 */
638void iocc_configuration(IORBH _far *iorb)
639{
640 int a;
641
642 switch (iorb->CommandModifier) {
643
644 case IOCM_COMPLETE_INIT:
645 /* Complete initialization. From now on, we won't have to restore the BIOS
646 * configuration after each command and we're fully operational (i.e. will
647 * use interrupts, timers and context hooks instead of polling).
648 */
649 if (!init_complete) {
650 dprintf("leaving initialization mode\n");
651 for (a = 0; a < ad_info_cnt; a++) {
652 lock_adapter(ad_infos + a);
653 ahci_complete_init(ad_infos + a);
654 }
655 init_complete = 1;
656
657 /* release all adapters */
658 for (a = 0; a < ad_info_cnt; a++) {
659 unlock_adapter(ad_infos + a);
660 }
661
662 /* register APM hook */
663 apm_init();
664 }
665 iorb_done(iorb);
666 break;
667
668 case IOCM_GET_DEVICE_TABLE:
669 /* construct a device table */
670 iocm_device_table(iorb);
671 break;
672
673 default:
674 iorb_seterr(iorb, IOERR_CMD_NOT_SUPPORTED);
675 iorb_done(iorb);
676 break;
677 }
678}
679
680/******************************************************************************
681 * Handle IOCC_DEVICE_CONTROL requests.
682 */
683void iocc_device_control(IORBH _far *iorb)
684{
685 AD_INFO *ai = ad_infos + iorb_unit_adapter(iorb);
686 IORBH _far *ptr;
687 IORBH _far *next = NULL;
688 int p = iorb_unit_port(iorb);
689 int d = iorb_unit_device(iorb);
690
691 switch (iorb->CommandModifier) {
692
693 case IOCM_ABORT:
694 /* abort all pending commands on specified port and device */
695 spin_lock(drv_lock);
696 for (ptr = ai->ports[p].iorb_queue.root; ptr != NULL; ptr = next) {
697 next = ptr->pNxtIORB;
698 /* move all matching IORBs to the abort queue */
699 if (ptr != iorb && iorb_unit_device(ptr) == d) {
700 iorb_queue_del(&ai->ports[p].iorb_queue, ptr);
701 iorb_queue_add(&abort_queue, ptr);
702 ptr->ErrorCode = IOERR_CMD_ABORTED;
703 }
704 }
705 spin_unlock(drv_lock);
706
707 /* trigger reset context hook which will finish the abort processing */
708 DevHelp_ArmCtxHook(0, reset_ctxhook_h);
709 break;
710
711 case IOCM_SUSPEND:
712 case IOCM_RESUME:
713 case IOCM_GET_QUEUE_STATUS:
714 /* Suspend/resume operations allow access to the hardware for other
715 * entities such as IBMIDECD.FLT. Since os2ahci implements both ATA
716 * and ATAPI in the same driver, this won't be required.
717 */
718 iorb_seterr(iorb, IOERR_CMD_NOT_SUPPORTED);
719 break;
720
721 case IOCM_LOCK_MEDIA:
722 case IOCM_UNLOCK_MEDIA:
723 case IOCM_EJECT_MEDIA:
724 /* unit control commands to lock, unlock and eject media */
725 /* will be supported later... */
726 iorb_seterr(iorb, IOERR_CMD_NOT_SUPPORTED);
727 break;
728
729 default:
730 iorb_seterr(iorb, IOERR_CMD_NOT_SUPPORTED);
731 break;
732 }
733
734 iorb_done(iorb);
735}
736
737/******************************************************************************
738 * Handle IOCC_UNIT_CONTROL requests.
739 */
740void iocc_unit_control(IORBH _far *iorb)
741{
742 IORB_UNIT_CONTROL _far *iorb_uc = (IORB_UNIT_CONTROL _far *) iorb;
743 int a = iorb_unit_adapter(iorb);
744 int p = iorb_unit_port(iorb);
745 int d = iorb_unit_device(iorb);
746
747 spin_lock(drv_lock);
748 switch (iorb->CommandModifier) {
749
750 case IOCM_ALLOCATE_UNIT:
751 /* allocate unit for exclusive access */
752 if (ad_infos[a].ports[p].devs[d].allocated) {
753 iorb_seterr(iorb, IOERR_UNIT_ALLOCATED);
754 } else {
755 ad_infos[a].ports[p].devs[d].allocated = 1;
756 }
757 break;
758
759 case IOCM_DEALLOCATE_UNIT:
760 /* deallocate exclusive access to unit */
761 if (!ad_infos[a].ports[p].devs[d].allocated) {
762 iorb_seterr(iorb, IOERR_UNIT_NOT_ALLOCATED);
763 } else {
764 ad_infos[a].ports[p].devs[d].allocated = 0;
765 }
766 break;
767
768 case IOCM_CHANGE_UNITINFO:
769 /* Change unit (device) information. One reason for this IOCM is the
770 * interface for filter device drivers: a filter device driver can
771 * either change existing UNITINFOs or permanently allocate units
772 * and fabricate new [logical] units; the former is the reason why we
773 * must store the pointer to the updated UNITNIFO for subsequent
774 * IOCC_CONFIGURATION/IOCM_GET_DEVICE_TABLE calls.
775 */
776 if (!ad_infos[a].ports[p].devs[d].allocated) {
777 iorb_seterr(iorb, IOERR_UNIT_NOT_ALLOCATED);
778 break;
779 }
780 ad_infos[a].ports[p].devs[d].unit_info = iorb_uc->pUnitInfo;
781 break;
782
783 default:
784 iorb_seterr(iorb, IOERR_CMD_NOT_SUPPORTED);
785 break;
786 }
787
788 spin_unlock(drv_lock);
789 iorb_done(iorb);
790}
791
792/******************************************************************************
793 * Scan all ports for AHCI devices and construct a DASD device table.
794 *
795 * NOTES: This function may be called multiple times. Only the first
796 * invocation will actually scan for devices; all subsequent calls will
797 * merely return the results of the initial scan, potentially augmented
798 * by modified unit infos after IOCC_CONFIGURATION/IOCM_CHANGE_UNITINFO
799 * requests.
800 *
801 * In order to support applications that can't deal with ATAPI devices
802 * (i.e. need a SCSI adapter) os2ahci will optionally report ATAPI
803 * dvices as SCSI devices. The corresponding SCSI adapter doesn't
804 * really exist and is only reported here for the IOCM_GET_DEVICETABLE
805 * request. The units attached to this adapter will use the real HW
806 * unit IDs, thus we'll never receive a command specific to the
807 * emulated SCSI adapter and won't need to set up any sort of entity
808 * for it; the only purpose of the emulated SCSI adapter is to pass the
809 * bus type "AI_DEVBUS_SCSI_2" upstream, and the emulated units, of
810 * course. The emulated SCSI target IDs are allocated as follows:
811 *
812 * 0 the virtual adapter
813 * 1..n emulated devices; SCSI target ID increments sequentially
814 */
815void iocm_device_table(IORBH _far *iorb)
816{
817 IORB_CONFIGURATION _far *iorb_conf;
818 DEVICETABLE _far *dt;
819 char _far *pos;
820 int scsi_units = 0;
821 int scsi_id = 1;
822 int rc;
823 int dta;
824 int a;
825 int p;
826 int d;
827
828 iorb_conf = (IORB_CONFIGURATION _far *) iorb;
829 dt = iorb_conf->pDeviceTable;
830
831 spin_lock(drv_lock);
832
833 /* initialize device table header */
834 dt->ADDLevelMajor = ADD_LEVEL_MAJOR;
835 dt->ADDLevelMinor = ADD_LEVEL_MINOR;
836 dt->ADDHandle = add_handle;
837 dt->TotalAdapters = ad_info_cnt + 1;
838
839 /* set start of adapter and device information tables */
840 pos = (char _far *) (dt->pAdapter + dt->TotalAdapters);
841
842 /* go through all adapters, including the virtual SCSI adapter */
843 for (dta = 0; dta < dt->TotalAdapters; dta++) {
844 ADAPTERINFO _far *ptr = (ADAPTERINFO _far *) pos;
845
846 /* sanity check for sufficient space in device table */
847 if ((u32) (ptr + 1) - (u32) dt > iorb_conf->DeviceTableLen) {
848 dprintf("error: device table provided by DASD too small\n");
849 iorb_seterr(iorb, IOERR_CMD_SW_RESOURCE);
850 goto iocm_device_table_done;
851 }
852
853 dt->pAdapter[dta] = (ADAPTERINFO _near *) ((u32) ptr & 0xffff);
854 memset(ptr, 0x00, sizeof(*ptr));
855
856 ptr->AdapterIOAccess = AI_IOACCESS_BUS_MASTER;
857 ptr->AdapterHostBus = AI_HOSTBUS_OTHER | AI_BUSWIDTH_32BIT;
858 ptr->AdapterFlags = AF_16M | AF_HW_SCATGAT;
859 ptr->MaxHWSGList = AHCI_MAX_SG / 2; /* AHCI S/G elements are 22 bits */
860
861 if (dta < ad_info_cnt) {
862 /* this is a physical AHCI adapter */
863 AD_INFO *ad_info = ad_infos + dta;
864
865 ptr->AdapterDevBus = AI_DEVBUS_ST506 | AI_DEVBUS_32BIT;
866 sprintf(ptr->AdapterName, "AHCI_%d", dta);
867
868 if (!ad_info->port_scan_done) {
869 /* first call; need to scan AHCI hardware for devices */
870 if (ad_info->busy) {
871 dprintf("error: port scan requested while adapter was busy\n");
872 iorb_seterr(iorb, IOERR_CMD_SW_RESOURCE);
873 goto iocm_device_table_done;
874 }
875 ad_info->busy = 1;
876 spin_unlock(drv_lock);
877 rc = ahci_scan_ports(ad_info);
878 spin_lock(drv_lock);
879 ad_info->busy = 0;
880
881 if (rc != 0) {
882 dprintf("error: port scan failed on adapter #%d\n", dta);
883 iorb_seterr(iorb, IOERR_CMD_SW_RESOURCE);
884 goto iocm_device_table_done;
885 }
886 ad_info->port_scan_done = 1;
887 }
888
889 /* insert physical (i.e. AHCI) devices into the device table */
890 for (p = 0; p <= ad_info->port_max; p++) {
891 for (d = 0; d <= ad_info->ports[p].dev_max; d++) {
892 if (ad_info->ports[p].devs[d].present) {
893 if (ad_info->ports[p].devs[d].atapi && emulate_scsi[dta][p]) {
894 /* only report this unit as SCSI unit */
895 scsi_units++;
896 continue;
897 }
898 if (add_unit_info(iorb_conf, dta, dta, p, d, 0)) {
899 goto iocm_device_table_done;
900 }
901 }
902 }
903 }
904
905 } else {
906 /* this is the virtual SCSI adapter */
907 if (scsi_units == 0) {
908 /* not a single unit to be emulated via SCSI */
909 dt->TotalAdapters--;
910 break;
911 }
912
913 /* set adapter name and bus type to mimic a SCSI controller */
914 ptr->AdapterDevBus = AI_DEVBUS_SCSI_2 | AI_DEVBUS_16BIT;
915 sprintf(ptr->AdapterName, "AHCI_SCSI_0");
916
917 /* add all ATAPI units to be emulated by this virtual adaper */
918 for (a = 0; a < ad_info_cnt; a++) {
919 AD_INFO *ad_info = ad_infos + a;
920
921 for (p = 0; p <= ad_info->port_max; p++) {
922 for (d = 0; d <= ad_info->ports[p].dev_max; d++) {
923 if (ad_info->ports[p].devs[d].present &&
924 ad_info->ports[p].devs[d].atapi &&
925 emulate_scsi[a][p]) {
926 if (add_unit_info(iorb_conf, dta, a, p, d, scsi_id++)) {
927 goto iocm_device_table_done;
928 }
929 }
930 }
931 }
932 }
933 }
934
935 /* calculate offset for next adapter */
936 pos = (char _far *) (ptr->UnitInfo + ptr->AdapterUnits);
937 }
938
939iocm_device_table_done:
940 spin_unlock(drv_lock);
941 iorb_done(iorb);
942}
943
944/******************************************************************************
945 * Handle IOCC_GEOMETRY requests.
946 */
947void iocc_geometry(IORBH _far *iorb)
948{
949 switch (iorb->CommandModifier) {
950
951 case IOCM_GET_MEDIA_GEOMETRY:
952 case IOCM_GET_DEVICE_GEOMETRY:
953 add_workspace(iorb)->idempotent = 1;
954 ahci_get_geometry(iorb);
955 break;
956
957 default:
958 iorb_seterr(iorb, IOERR_CMD_NOT_SUPPORTED);
959 iorb_done(iorb);
960 }
961}
962
963/******************************************************************************
964 * Handle IOCC_EXECUTE_IO requests.
965 */
966void iocc_execute_io(IORBH _far *iorb)
967{
968 switch (iorb->CommandModifier) {
969
970 case IOCM_READ:
971 add_workspace(iorb)->idempotent = 1;
972 ahci_read(iorb);
973 break;
974
975 case IOCM_READ_VERIFY:
976 add_workspace(iorb)->idempotent = 1;
977 ahci_verify(iorb);
978 break;
979
980 case IOCM_WRITE:
981 add_workspace(iorb)->idempotent = 1;
982 ahci_write(iorb);
983 break;
984
985 case IOCM_WRITE_VERIFY:
986 add_workspace(iorb)->idempotent = 1;
987 ahci_write(iorb);
988 break;
989
990 default:
991 iorb_seterr(iorb, IOERR_CMD_NOT_SUPPORTED);
992 iorb_done(iorb);
993 }
994}
995
996/******************************************************************************
997 * Handle IOCC_UNIT_STATUS requests.
998 */
999void iocc_unit_status(IORBH _far *iorb)
1000{
1001 switch (iorb->CommandModifier) {
1002
1003 case IOCM_GET_UNIT_STATUS:
1004 add_workspace(iorb)->idempotent = 1;
1005 ahci_unit_ready(iorb);
1006 break;
1007
1008 default:
1009 iorb_seterr(iorb, IOERR_CMD_NOT_SUPPORTED);
1010 iorb_done(iorb);
1011 }
1012}
1013
1014/******************************************************************************
1015 * Handle IOCC_ADAPTER_PASSTHROUGH requests.
1016 */
1017void iocc_adapter_passthru(IORBH _far *iorb)
1018{
1019 switch (iorb->CommandModifier) {
1020
1021 case IOCM_EXECUTE_CDB:
1022 add_workspace(iorb)->idempotent = 0;
1023 ahci_execute_cdb(iorb);
1024 break;
1025
1026 case IOCM_EXECUTE_ATA:
1027 add_workspace(iorb)->idempotent = 0;
1028 ahci_execute_ata(iorb);
1029 break;
1030
1031 default:
1032 iorb_seterr(iorb, IOERR_CMD_NOT_SUPPORTED);
1033 iorb_done(iorb);
1034 }
1035}
1036
1037/******************************************************************************
1038 * Add an IORB to the specified queue. This function must be called with the
1039 * adapter-level spinlock aquired.
1040 */
1041void iorb_queue_add(IORB_QUEUE _far *queue, IORBH _far *iorb)
1042{
1043 if (iorb_priority(iorb) {
1044 /* priority IORB; insert at first position */
1045 iorb->pNxtIORB = queue->root;
1046 queue->root = iorb;
1047
1048 } else {
1049 /* append IORB to end of queue */
1050 iorb->pNxtIORB = NULL;
1051
1052 if (queue->root == NULL) {
1053 queue->root = iorb;
1054 } else {
1055 queue->tail->pNxtIORB = iorb;
1056 }
1057 queue->tail = iorb;
1058 }
1059
1060 if (debug) {
1061 /* determine queue type (local, driver, abort or port) and minimum debug
1062 * level; otherwise, queue debug prints can become really confusing.
1063 */
1064 char *queue_type;
1065 int min_debug = 1;
1066
1067 if ((u32) queue >> 16 == (u32) (void _far *) &queue >> 16) {
1068 /* this queue is on the stack */
1069 queue_type = "local";
1070 min_debug = 2;
1071
1072 } else if (queue == &driver_queue) {
1073 queue_type = "driver";
1074
1075 } else if (queue == &abort_queue) {
1076 queue_type = "abort";
1077 min_debug = 2;
1078
1079 } else {
1080 queue_type = "port";
1081 }
1082
1083 if (debug >= min_debug) {
1084 printf("IORB %Fp queued (cmd = %d/%d, queue = %Fp [%s], timeout = %ld)\n",
1085 iorb, iorb->CommandCode, iorb->CommandModifier, queue, queue_type,
1086 iorb->Timeout);
1087 }
1088 }
1089}
1090
1091/******************************************************************************
1092 * Remove an IORB from the specified queue. This function must be called with
1093 * the adapter-level spinlock aquired.
1094 */
1095int iorb_queue_del(IORB_QUEUE _far *queue, IORBH _far *iorb)
1096{
1097 IORBH _far *_iorb;
1098 IORBH _far *_prev = NULL;
1099 int found = 0;
1100
1101 for (_iorb = queue->root; _iorb != NULL; _iorb = _iorb->pNxtIORB) {
1102 if (_iorb == iorb) {
1103 /* found the IORB to be removed */
1104 if (_prev != NULL) {
1105 _prev->pNxtIORB = _iorb->pNxtIORB;
1106 } else {
1107 queue->root = _iorb->pNxtIORB;
1108 }
1109 if (_iorb == queue->tail) {
1110 queue->tail = _prev;
1111 }
1112 found = 1;
1113 break;
1114 }
1115 _prev = _iorb;
1116 }
1117
1118 if (found) {
1119 ddprintf("IORB %Fp removed (queue = %Fp)\n", iorb, queue);
1120 } else {
1121 dprintf("IORB %Fp not found in queue %Fp\n", iorb, queue);
1122 }
1123
1124 return(!found);
1125}
1126
1127/******************************************************************************
1128 * Set the error code in the specified IORB
1129 *
1130 * NOTE: This function does *not* call iorb_done(). It merely sets the IORB
1131 * status to the specified error code.
1132 */
1133void iorb_seterr(IORBH _far *iorb, USHORT error_code)
1134{
1135 iorb->ErrorCode = error_code;
1136 iorb->Status |= IORB_ERROR;
1137}
1138
1139/******************************************************************************
1140 * Mark the specified IORB as done and notify the asynchronous post function,
1141 * if any. The IORB is also removed from the corresponding IORB queue.
1142 *
1143 * NOTES: This function does not clear the Status field; it merely adds the
1144 * IORB_DONE flag.
1145 *
1146 * This function is expected to be called *without* the corresponding
1147 * driver-level drv_lock aquired. It will aquire the spinlock before
1148 * updating the IORB queue and release it before notifying the upstream
1149 * code in order to prevent deadlocks.
1150 *
1151 * Due to this logic, this function is only good for simple task-time
1152 * completions. Functions working on lists of IORBs (such as interrupt
1153 * handlers or context hooks) should call iorb_complete() directly and
1154 * implement their own logic for removing the IORB from the port queue.
1155 * See abort_ctxhook() for an example.
1156 */
1157void iorb_done(IORBH _far *iorb)
1158{
1159 int a = iorb_unit_adapter(iorb);
1160 int p = iorb_unit_port(iorb);
1161
1162 /* remove IORB from corresponding queue */
1163 spin_lock(drv_lock);
1164 if (iorb_driver_level(iorb)) {
1165 iorb_queue_del(&driver_queue, iorb);
1166 } else {
1167 iorb_queue_del(&ad_infos[a].ports[p].iorb_queue, iorb);
1168 }
1169 aws_free(add_workspace(iorb));
1170 spin_unlock(drv_lock);
1171
1172 iorb_complete(iorb);
1173}
1174
1175/******************************************************************************
1176 * Complete an IORB. This should be called without the adapter-level spinlock
1177 * to allow the IORB completion routine to perform whatever processing it
1178 * requires. This implies that the IORB should no longer be in any global
1179 * queue because the IORB completion routine may well reuse the IORB and send
1180 * the next request to us before even returning from this function.
1181 */
1182void iorb_complete(IORBH _far *iorb)
1183{
1184 iorb->Status |= IORB_DONE;
1185
1186 dprintf("IORB %Fp complete (status = 0x%04x, error = 0x%04x)\n",
1187 iorb, iorb->Status, iorb->ErrorCode);
1188
1189 if (iorb->RequestControl & IORB_ASYNC_POST) {
1190 iorb->NotifyAddress(iorb);
1191 }
1192}
1193
1194/******************************************************************************
1195 * Requeue the specified IORB such that it will be sent downstream for
1196 * processing again. This includes freeing all resources currently allocated
1197 * (timer, buffer, ...) and resetting the flags to 0. The driver-level
1198 * spinlock must be aquired when calling this function.
1199 *
1200 * The following flags are preserved:
1201 * - no_ncq
1202 */
1203void iorb_requeue(IORBH _far *iorb)
1204{
1205 ADD_WORKSPACE _far *aws = add_workspace(iorb);
1206 u16 no_ncq = aws->no_ncq;
1207
1208 aws_free(aws);
1209 memset(aws, 0x00, sizeof(*aws));
1210 aws->no_ncq = no_ncq;
1211}
1212
1213/******************************************************************************
1214 * Free resources in ADD workspace (timer, buffer, ...). This function should
1215 * be called with the spinlock held to prevent race conditions.
1216 */
1217void aws_free(ADD_WORKSPACE _far *aws)
1218{
1219 if (aws->timer != 0) {
1220 ADD_CancelTimer(aws->timer);
1221 aws->timer = 0;
1222 }
1223
1224 if (aws->buf != NULL) {
1225 free(aws->buf);
1226 aws->buf = NULL;
1227 }
1228}
1229
1230/******************************************************************************
1231 * Lock the adapter, waiting for availability if necessary. This is expected
1232 * to be called at task/request time without the driver-level spinlock
1233 * aquired. Don't call at interrupt time.
1234 */
1235void lock_adapter(AD_INFO *ai)
1236{
1237 spin_lock(drv_lock);
1238 while (ai->busy) {
1239 spin_unlock(drv_lock);
1240 msleep(250);
1241 spin_lock(drv_lock);
1242 }
1243 ai->busy = 1;
1244 spin_unlock(drv_lock);
1245}
1246
1247/******************************************************************************
1248 * Unlock adapter (i.e. reset busy flag)
1249 */
1250void unlock_adapter(AD_INFO *ai)
1251{
1252 ai->busy = 0;
1253}
1254
1255/******************************************************************************
1256 * Timeout handler for I/O commands. Since timeout handling can involve
1257 * lengthy operations like port resets, the main code is located in a
1258 * separate function which is invoked via a context hook.
1259 */
1260void _cdecl _far timeout_callback(ULONG timer_handle, ULONG p1,
1261 ULONG p2)
1262{
1263 IORBH _far *iorb = (IORBH _far *) p1;
1264 int a = iorb_unit_adapter(iorb);
1265 int p = iorb_unit_port(iorb);
1266
1267 ADD_CancelTimer(timer_handle);
1268 dprintf("timeout for IORB %Fp\n", iorb);
1269
1270 /* Move the timed-out IORB to the abort queue. Since it's possible that the
1271 * IORB has completed after the timeout has expired but before we got to
1272 * this line of code, we'll check the return code of iorb_queue_del(): If it
1273 * returns an error, the IORB must have completed a few microseconds ago and
1274 * there is no timeout.
1275 */
1276 spin_lock(drv_lock);
1277 if (iorb_queue_del(&ad_infos[a].ports[p].iorb_queue, iorb) == 0) {
1278 iorb_queue_add(&abort_queue, iorb);
1279 iorb->ErrorCode = IOERR_ADAPTER_TIMEOUT;
1280 }
1281 spin_unlock(drv_lock);
1282
1283 /* Trigger abort processing function. We don't really care whether this
1284 * succeeds because the only reason why it would fail should be multiple
1285 * calls to DevHelp_ArmCtxHook() before the context hook had a chance to
1286 * start executing, which leaves two scenarios:
1287 *
1288 * - We succeded in arming the context hook. Fine.
1289 *
1290 * - We armed the context hook a second time before it had a chance to
1291 * start executing. In this case, the already scheduled context hook
1292 * will process our IORB as well.
1293 */
1294 DevHelp_ArmCtxHook(0, reset_ctxhook_h);
1295
1296 /* Set up a watchdog timer which calls the context hook manually in case
1297 * some kernel thread is looping around the IORB_COMPLETE status bit
1298 * without yielding the CPU (kernel threads don't preempt). This shouldn't
1299 * happen per design because kernel threads are supposed to yield but it
1300 * does in the early boot phase.
1301 */
1302 ADD_StartTimerMS(&th_reset_watchdog, 5000, (PFN) reset_watchdog, 0, 0);
1303}
1304
1305/******************************************************************************
1306 * Reset handler watchdog. If a timeout occurs, a context hook is armed which
1307 * will execute as soon as a kernel thread yields the CPU. However, some
1308 * kernel components won't yield the CPU during the early boot phase and the
1309 * only way to kick some sense into those components is to run the context
1310 * hook right inside this timer callback. Not exactly pretty, especially
1311 * considering the fact that context hooks were implemented to prevent running
1312 * lengthy operations like a port reset at interrupt time, but without this
1313 * watchdog mechanism we run the risk of getting completely stalled by device
1314 * problems during the early boot phase.
1315 */
1316void _cdecl _far reset_watchdog(ULONG timer_handle, ULONG p1,
1317 ULONG p2)
1318{
1319 /* reset watchdog timer */
1320 ADD_CancelTimer(timer_handle);
1321 dprintf("reset watchdog invoked\n");
1322
1323 /* call context hook manually */
1324 reset_ctxhook(0);
1325}
1326
1327/******************************************************************************
1328 * small_code_ - this dummy func resolves the undefined reference linker
1329 * error that occurrs when linking WATCOM objects with DDK's link.exe
1330 */
1331void _cdecl small_code_(void)
1332{
1333}
1334
1335/******************************************************************************
1336 * Add unit info to ADAPTERINFO array (IOCC_GET_DEVICE_TABLE requests). The
1337 * adapter info array in the device table, dt->pAdapter[], is expected to be
1338 * initialized for the specified index (dt_ai).
1339 *
1340 * Please note that the device table adapter index, dta, is not always equal
1341 * to the physical adapter index, a: if SCSI emulation has been activated, the
1342 * last reported adapter is a virtual SCSI adapter and the physical adapter
1343 * indexes for those units are, of course, different from the device table
1344 * index of the virtual SCSI adapter.
1345 */
1346static int add_unit_info(IORB_CONFIGURATION _far *iorb_conf, int dta,
1347 int a, int p, int d, int scsi_id)
1348{
1349 DEVICETABLE _far *dt = iorb_conf->pDeviceTable;
1350 ADAPTERINFO _far *ptr = (ADAPTERINFO _far *) (((u32) dt & 0xffff0000U) +
1351 (u16) dt->pAdapter[dta]);
1352 UNITINFO _far *ui = ptr->UnitInfo + ptr->AdapterUnits;
1353 AD_INFO *ai = ad_infos + a;
1354
1355 if ((u32) (ui + 1) - (u32) dt > iorb_conf->DeviceTableLen) {
1356 dprintf("error: device table provided by DASD too small\n");
1357 iorb_seterr(&iorb_conf->iorbh, IOERR_CMD_SW_RESOURCE);
1358 return(-1);
1359 }
1360
1361 if (ai->ports[p].devs[d].unit_info == NULL) {
1362 /* provide original information about this device (unit) */
1363 memset(ui, 0x00, sizeof(*ui));
1364 ui->AdapterIndex = dta; /* device table adapter index */
1365 ui->UnitHandle = iorb_unit(a, p, d); /* physical adapter index */
1366 ui->UnitIndex = ptr->AdapterUnits;
1367 ui->UnitType = ai->ports[p].devs[d].dev_type;
1368 ui->QueuingCount = ai->ports[p].devs[d].ncq_max;;
1369 if (ai->ports[p].devs[d].removable) {
1370 ui->UnitFlags |= UF_REMOVABLE;
1371 }
1372 if (scsi_id > 0) {
1373 /* set fake SCSI ID for this unit */
1374 ui->UnitSCSITargetID = scsi_id;
1375 }
1376 } else {
1377 /* copy updated device (unit) information (IOCM_CHANGE_UNITINFO) */
1378 memcpy(ui, ai->ports[p].devs[d].unit_info, sizeof(*ui));
1379 }
1380
1381 ptr->AdapterUnits++;
1382 return(0);
1383}
1384
Note: See TracBrowser for help on using the repository browser.