[4] | 1 | /******************************************************************************
|
---|
| 2 | * os2ahci.c - main file for os2ahci driver
|
---|
| 3 | *
|
---|
| 4 | * Copyright (c) 2010 Christian Mueller. Parts copied from/inspired by the
|
---|
| 5 | * Linux AHCI driver; those parts are (c) Linux AHCI/ATA maintainers
|
---|
| 6 | *
|
---|
| 7 | * This program is free software; you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * This program is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with this program; if not, write to the Free Software
|
---|
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
| 20 | */
|
---|
| 21 |
|
---|
| 22 | #include "os2ahci.h"
|
---|
| 23 |
|
---|
| 24 | /* -------------------------- macros and constants ------------------------- */
|
---|
| 25 |
|
---|
| 26 | /* parse integer command line parameter */
|
---|
| 27 | #define drv_parm_int(s, value, type, radix) \
|
---|
| 28 | { \
|
---|
| 29 | char _far *_ep; \
|
---|
| 30 | if ((s)[1] != ':') { \
|
---|
| 31 | cprintf("missing colon (:) after /%c\n", *(s)); \
|
---|
| 32 | goto init_fail; \
|
---|
| 33 | } \
|
---|
| 34 | value = (type) strtol((s) + 2, &_ep, radix); \
|
---|
| 35 | s = _ep; \
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | /* ------------------------ typedefs and structures ------------------------ */
|
---|
| 39 |
|
---|
| 40 | /* -------------------------- function prototypes -------------------------- */
|
---|
| 41 |
|
---|
| 42 | /* ------------------------ global/static variables ------------------------ */
|
---|
| 43 |
|
---|
| 44 | int debug = 0; /* if > 0, print debug messages to COM1 */
|
---|
| 45 | int thorough_scan; /* if != 0, perform thorough PCI scan */
|
---|
| 46 | int init_reset; /* if != 0, reset ports during init */
|
---|
| 47 |
|
---|
| 48 | PFN Device_Help = 0; /* pointer to device helper entry point */
|
---|
| 49 | ULONG RMFlags = 0; /* required by resource manager library */
|
---|
| 50 | PFN RM_Help0 = NULL; /* required by resource manager library */
|
---|
| 51 | PFN RM_Help3 = NULL; /* required by resource manager library */
|
---|
| 52 | HDRIVER rm_drvh; /* resource manager driver handle */
|
---|
| 53 | char rm_drvname[80]; /* driver name as returned by RM */
|
---|
| 54 | USHORT add_handle; /* driver handle (RegisterDeviceClass) */
|
---|
| 55 | UCHAR timer_pool[TIMER_POOL_SIZE]; /* timer pool */
|
---|
| 56 |
|
---|
| 57 | /* resource manager driver information structure */
|
---|
| 58 | DRIVERSTRUCT rm_drvinfo = {
|
---|
| 59 | "OS2AHCI", /* driver name */
|
---|
| 60 | "AHCI SATA Driver", /* driver description */
|
---|
| 61 | "GNU", /* vendor name */
|
---|
| 62 | CMVERSION_MAJOR, /* RM interface version major */
|
---|
| 63 | CMVERSION_MINOR, /* RM interface version minor */
|
---|
| 64 | 2010, 4, 27, /* date */
|
---|
| 65 | 0, /* driver flags */
|
---|
| 66 | DRT_ADDDM, /* driver type */
|
---|
| 67 | DRS_ADD, /* driver sub type */
|
---|
| 68 | NULL /* driver callback */
|
---|
| 69 | };
|
---|
| 70 |
|
---|
| 71 | ULONG drv_lock; /* driver-level spinlock */
|
---|
| 72 | IORB_QUEUE driver_queue; /* driver-level IORB queue */
|
---|
| 73 | AD_INFO ad_infos[MAX_AD]; /* adapter information list */
|
---|
| 74 | int ad_info_cnt; /* number of entries in ad_infos[] */
|
---|
| 75 | int init_complete; /* if != 0, initialization has completed */
|
---|
| 76 |
|
---|
| 77 | /* apapter/port-specific options saved when parsing the command line */
|
---|
| 78 | int link_speed[MAX_AD][AHCI_MAX_PORTS];
|
---|
| 79 |
|
---|
| 80 | static char init_msg[] = "OS2AHCI driver version %d.%02d\n";
|
---|
| 81 | static char exit_msg[] = "OS2AHCI driver *not* installed\n";
|
---|
| 82 |
|
---|
| 83 | /* ----------------------------- start of code ----------------------------- */
|
---|
| 84 |
|
---|
| 85 | /******************************************************************************
|
---|
| 86 | * OS/2 device driver main strategy function. This function is only used
|
---|
| 87 | * for initialization purposes; all other calls go directly to the adapter
|
---|
| 88 | * device driver's strategy function.
|
---|
| 89 | */
|
---|
| 90 | USHORT c_strat(RPH _far *req)
|
---|
| 91 | {
|
---|
| 92 | u16 rc;
|
---|
| 93 |
|
---|
| 94 | switch (req->Cmd) {
|
---|
| 95 |
|
---|
| 96 | case CMDInitBase:
|
---|
| 97 | rc = init_drv((RPINITIN _far *) req);
|
---|
| 98 | break;
|
---|
| 99 |
|
---|
| 100 | default:
|
---|
| 101 | rc = STDON | STATUS_ERR_UNKCMD;
|
---|
| 102 | break;
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | return(rc);
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | /******************************************************************************
|
---|
| 109 | * Intialize the os2ahci driver. This includes command line parsing, scanning
|
---|
| 110 | * the PCI bus for supported AHCI adapters, etc.
|
---|
| 111 | */
|
---|
| 112 | USHORT init_drv(RPINITIN _far *req)
|
---|
| 113 | {
|
---|
| 114 | RPINITOUT _far *rsp = (RPINITOUT _far *) req;
|
---|
| 115 | DDD_PARM_LIST _far *ddd_pl = (DDD_PARM_LIST _far *) req->InitArgs;
|
---|
| 116 | APIRET rmrc;
|
---|
| 117 | PSEL p;
|
---|
| 118 | char _far *cmd_line;
|
---|
| 119 | char _far *ep;
|
---|
| 120 | char _far *s;
|
---|
| 121 | int adapter_index;
|
---|
| 122 | int port_index;
|
---|
| 123 | u16 vendor;
|
---|
| 124 | u16 device;
|
---|
| 125 |
|
---|
| 126 | /* set device helper entry point */
|
---|
| 127 | Device_Help = req->DevHlpEP;
|
---|
| 128 |
|
---|
| 129 | /* create driver-level spinlock */
|
---|
| 130 | DevHelp_CreateSpinLock(&drv_lock);
|
---|
| 131 |
|
---|
| 132 | if (debug) {
|
---|
| 133 | /* initialize debug interface (COM1) */
|
---|
| 134 | init_com1();
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | /* print initialization message */
|
---|
| 138 | cprintf(init_msg, VERSION / 100, VERSION % 100);
|
---|
| 139 |
|
---|
| 140 | /* register driver with resource manager */
|
---|
| 141 | if ((rmrc = RMCreateDriver(&rm_drvinfo, &rm_drvh)) != RMRC_SUCCESS) {
|
---|
| 142 | cprintf("failed to register driver with resource manager (rc = %d)\n", rmrc);
|
---|
| 143 | goto init_fail;
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | /* parse command line parameters */
|
---|
| 147 | cmd_line = (char _far *) ((u32) ddd_pl & 0xffff0000l) + ddd_pl->cmd_line_args;
|
---|
| 148 | adapter_index = 0;
|
---|
| 149 | port_index = 0;
|
---|
| 150 |
|
---|
| 151 | for (s = cmd_line; *s != 0; s++) {
|
---|
| 152 | if (*s == '/' && s[1] != '\0') {
|
---|
| 153 | s++;
|
---|
| 154 | switch(tolower(*s)) {
|
---|
| 155 |
|
---|
| 156 | case 'd':
|
---|
| 157 | /* increase debug level */
|
---|
| 158 | debug++;
|
---|
| 159 | break;
|
---|
| 160 |
|
---|
| 161 | case 'i':
|
---|
| 162 | /* add specfied PCI ID as a supported generic AHCI adapter */
|
---|
| 163 | drv_parm_int(s, vendor, u16, 16);
|
---|
| 164 | drv_parm_int(s, device, u16, 16);
|
---|
| 165 | if (add_pci_id(vendor, device)) {
|
---|
| 166 | cprintf("failed to add PCI ID %04x:%04x\n", vendor, device);
|
---|
| 167 | goto init_fail;
|
---|
| 168 | }
|
---|
| 169 | thorough_scan = 1;
|
---|
| 170 | break;
|
---|
| 171 |
|
---|
| 172 | case 't':
|
---|
| 173 | /* perform thorough PCI scan (i.e. look for individual supported PCI IDs) */
|
---|
| 174 | thorough_scan = 1;
|
---|
| 175 | break;
|
---|
| 176 |
|
---|
| 177 | case 'r':
|
---|
| 178 | /* reset ports during initialization */
|
---|
| 179 | init_reset = 1;
|
---|
| 180 | break;
|
---|
| 181 |
|
---|
| 182 | case 'a':
|
---|
| 183 | /* set adapter index for adapter and port-related options */
|
---|
| 184 | drv_parm_int(s, adapter_index, int, 10);
|
---|
| 185 | if (adapter_index < 0 || adapter_index >= MAX_AD) {
|
---|
| 186 | cprintf("invalid adapter index (%d)\n", adapter_index);
|
---|
| 187 | goto init_fail;
|
---|
| 188 | }
|
---|
| 189 | break;
|
---|
| 190 |
|
---|
| 191 | case 'p':
|
---|
| 192 | /* set port index for port-related options */
|
---|
| 193 | drv_parm_int(s, port_index, int, 10);
|
---|
| 194 | if (port_index < 0 || port_index >= AHCI_MAX_PORTS) {
|
---|
| 195 | cprintf("invalid port index (%d)\n", port_index);
|
---|
| 196 | goto init_fail;
|
---|
| 197 | }
|
---|
| 198 | break;
|
---|
| 199 |
|
---|
| 200 | case 's':
|
---|
| 201 | /* set link speed of current port on current adapter */
|
---|
| 202 | drv_parm_int(s, link_speed[adapter_index][port_index], u8, 10);
|
---|
| 203 | init_reset = 1;
|
---|
| 204 | break;
|
---|
| 205 |
|
---|
| 206 | default:
|
---|
| 207 | cprintf("invalid option: /%c\n", *s);
|
---|
| 208 | goto init_fail;
|
---|
| 209 | }
|
---|
| 210 | }
|
---|
| 211 | }
|
---|
| 212 |
|
---|
| 213 | /* scan PCI bus for supported devices */
|
---|
| 214 | scan_pci_bus();
|
---|
| 215 |
|
---|
| 216 | if (ad_info_cnt > 0) {
|
---|
| 217 | /* initialization succeeded and we found at least one AHCI adapter */
|
---|
| 218 | ADD_InitTimer(timer_pool, sizeof(timer_pool));
|
---|
| 219 | mdelay_cal();
|
---|
| 220 |
|
---|
| 221 | if (DevHelp_RegisterDeviceClass("OS2AHCI", (PFN) add_entry, 0, 1,
|
---|
| 222 | &add_handle)) {
|
---|
| 223 | cprintf("error: couldn't register device class\n");
|
---|
| 224 | goto init_fail;
|
---|
| 225 | }
|
---|
| 226 |
|
---|
| 227 | /* allocate context hooks */
|
---|
| 228 | if (DevHelp_AllocateCtxHook(mk_NPFN(restart_hook), &restart_ctxhook_h) != 0 ||
|
---|
| 229 | DevHelp_AllocateCtxHook(mk_NPFN(reset_hook), &reset_ctxhook_h) != 0 ||
|
---|
| 230 | DevHelp_AllocateCtxHook(mk_NPFN(engine_hook), &engine_ctxhook_h)) {
|
---|
| 231 | cprintf("failed to allocate task-time context hooks\n");
|
---|
| 232 | goto init_fail;
|
---|
| 233 | }
|
---|
| 234 |
|
---|
| 235 | rsp->CodeEnd = (u16) end_of_code;
|
---|
| 236 | rsp->DataEnd = (u16) &end_of_data;
|
---|
| 237 | return(STDON);
|
---|
| 238 | }
|
---|
| 239 |
|
---|
| 240 | init_fail:
|
---|
| 241 | /* initialization failed; set segment sizes to 0 and return error */
|
---|
| 242 | cprintf(exit_msg);
|
---|
| 243 | rsp->CodeEnd = 0;
|
---|
| 244 | rsp->DataEnd = 0;
|
---|
| 245 |
|
---|
| 246 | /* free context hooks */
|
---|
| 247 | if (engine_ctxhook_h != 0) DevHelp_FreeCtxHook(engine_ctxhook_h);
|
---|
| 248 | if (reset_ctxhook_h != 0) DevHelp_FreeCtxHook(reset_ctxhook_h);
|
---|
| 249 | if (restart_ctxhook_h != 0) DevHelp_FreeCtxHook(restart_ctxhook_h);
|
---|
| 250 |
|
---|
| 251 | if (rm_drvh != 0) {
|
---|
| 252 | /* remove driver from resource manager */
|
---|
| 253 | RMDestroyDriver(rm_drvh);
|
---|
| 254 | }
|
---|
| 255 |
|
---|
| 256 | cprintf(exit_msg);
|
---|
| 257 | return(STDON | ERROR_I24_QUIET_INIT_FAIL);
|
---|
| 258 | }
|
---|
| 259 |
|
---|
| 260 | /******************************************************************************
|
---|
| 261 | * ADD entry point. This is the main entry point for all ADD requests. Due to
|
---|
| 262 | * the asynchronous nature of ADD drivers, this function primarily queues the
|
---|
| 263 | * IORB(s) to the corresponding adapter or port queues, then triggers the
|
---|
| 264 | * state machine to initiate processing queued IORBs.
|
---|
| 265 | *
|
---|
| 266 | * NOTE: In order to prevent race conditions or engine stalls, certain rules
|
---|
| 267 | * around locking, unlocking and IORB handling in general have been
|
---|
| 268 | * established. Refer to the comments in "trigger_engine()" for
|
---|
| 269 | * details.
|
---|
| 270 | */
|
---|
| 271 | void _far _loadds add_entry(IORBH _far *first_iorb)
|
---|
| 272 | {
|
---|
| 273 | IORBH _far *iorb;
|
---|
| 274 | IORBH _far *next = NULL;
|
---|
| 275 |
|
---|
| 276 | spin_lock(drv_lock);
|
---|
| 277 |
|
---|
| 278 | for (iorb = first_iorb; iorb != NULL; iorb = next) {
|
---|
| 279 | /* Queue this IORB. Queues primarily exist on port level but there are
|
---|
| 280 | * some requests which affect the whole driver, most notably
|
---|
| 281 | * IOCC_CONFIGURATION. In either case, adding the IORB to the driver or
|
---|
| 282 | * port queue will change the links, thus we need to save the original
|
---|
| 283 | * link in 'next'.
|
---|
| 284 | */
|
---|
| 285 | next = (iorb->RequestControl | IORB_CHAIN) ? iorb->pNxtIORB : 0;
|
---|
| 286 |
|
---|
| 287 | iorb->Status = 0;
|
---|
| 288 | iorb->ErrorCode = 0;
|
---|
| 289 | memset(&iorb->ADDWorkSpace, 0x00, sizeof(ADD_WORKSPACE));
|
---|
| 290 |
|
---|
| 291 | if (iorb_driver_level(iorb)) {
|
---|
| 292 | /* adapter-level IORB */
|
---|
| 293 | iorb->UnitHandle = 0;
|
---|
| 294 | iorb_queue_add(&driver_queue, iorb);
|
---|
| 295 |
|
---|
| 296 | } else {
|
---|
| 297 | /* port-level IORB */
|
---|
| 298 | int a = iorb_unit_adapter(iorb);
|
---|
| 299 | int p = iorb_unit_port(iorb);
|
---|
| 300 | int d = iorb_unit_device(iorb);
|
---|
| 301 |
|
---|
| 302 | if (a >= ad_info_cnt ||
|
---|
| 303 | p > ad_infos[a].port_max ||
|
---|
| 304 | d > ad_infos[a].ports[p].dev_max ||
|
---|
| 305 | (ad_infos[a].port_map & (1UL << p)) == 0) {
|
---|
| 306 |
|
---|
| 307 | /* unit handle outside of the allowed range */
|
---|
| 308 | dprintf("warning: IORB for %d.%d.%d out of range\n", a, p, d);
|
---|
| 309 | iorb->Status = IORB_ERROR | IORB_DONE;
|
---|
| 310 | iorb->ErrorCode = IOERR_CMD_SYNTAX;
|
---|
| 311 | if (iorb->RequestControl & IORB_ASYNC_POST) {
|
---|
| 312 | iorb->NotifyAddress(iorb);
|
---|
| 313 | }
|
---|
| 314 | continue;
|
---|
| 315 | }
|
---|
| 316 |
|
---|
| 317 | iorb_queue_add(&ad_infos[a].ports[p].iorb_queue, iorb);
|
---|
| 318 | }
|
---|
| 319 | }
|
---|
| 320 |
|
---|
| 321 | /* trigger state machine */
|
---|
| 322 | trigger_engine();
|
---|
| 323 |
|
---|
| 324 | spin_unlock(drv_lock);
|
---|
| 325 | }
|
---|
| 326 |
|
---|
| 327 | /******************************************************************************
|
---|
| 328 | * Trigger IORB queue engine. This is a wrapper function for trigger_engine_1()
|
---|
| 329 | * which will try to get all IORBs sent on their way a couple of times. If
|
---|
| 330 | * there are still IORBs ready for processing after this, this function will
|
---|
| 331 | * hand off to a context hook which will continue to trigger the engine until
|
---|
| 332 | * all IORBs have been sent.
|
---|
| 333 | */
|
---|
| 334 | void trigger_engine(void)
|
---|
| 335 | {
|
---|
| 336 | int i;
|
---|
| 337 |
|
---|
| 338 | for (i = 0; i < 3; i++) {
|
---|
| 339 | if (trigger_engine_1() == 0) {
|
---|
| 340 | /* done -- all IORBs have been sent on their way */
|
---|
| 341 | return;
|
---|
| 342 | }
|
---|
| 343 | }
|
---|
| 344 |
|
---|
| 345 | /* Something keeps bouncing; hand off to the engine context hook which will
|
---|
| 346 | * keep trying in the background.
|
---|
| 347 | */
|
---|
| 348 | DevHelp_ArmCtxHook(0, engine_ctxhook_h);
|
---|
| 349 | }
|
---|
| 350 |
|
---|
| 351 | /******************************************************************************
|
---|
| 352 | * Trigger IORB queue engine in order to send commands in the driver/port IORB
|
---|
| 353 | * queues to the AHCI hardware. This function will return the number of IORBs
|
---|
| 354 | * sent. Keep in mind that IORBs might "bounce" if the adapter/port is not in
|
---|
| 355 | * a state to accept the command, thus it might take quite a few calls to get
|
---|
| 356 | * all IORBs on their way. This is why there's a wrapper function which tries
|
---|
| 357 | * it a few times, then hands off to a context hook which will keep trying in
|
---|
| 358 | * the background.
|
---|
| 359 | *
|
---|
| 360 | * IORBs might complete before send_iorb() has returned, at any time during
|
---|
| 361 | * interrupt processing or on another CPU on SMP systems. IORB completion
|
---|
| 362 | * means modifications to the corresponding IORB queue (the completed IORB
|
---|
| 363 | * is removed from the queue) thus we need to protect the IORB queues from
|
---|
| 364 | * race conditions. The safest approach short of keeping the driver-level
|
---|
| 365 | * spinlock aquired permanently is to keep it throughout this function and
|
---|
| 366 | * release it temporarily in send_iorb().
|
---|
| 367 | *
|
---|
| 368 | * This implies that the handler functions are fully responsible for aquiring
|
---|
| 369 | * the driver-level spinlock when they need it, and for releasing it again.
|
---|
| 370 | *
|
---|
| 371 | * As a rule of thumb, get the driver-level spinlock whenever accessing
|
---|
| 372 | * volatile variables (IORB queues, values in ad_info[], ...).
|
---|
| 373 | *
|
---|
| 374 | * Additional Notes:
|
---|
| 375 | *
|
---|
| 376 | * - This function is expected to be called with the spinlock aquired
|
---|
| 377 | *
|
---|
| 378 | * - The handler functions are free to process more than one IORB (i.e.
|
---|
| 379 | * command queuing). The idea is that the root IORB (and potential next
|
---|
| 380 | * IORBs) are marked as "processing" which keeps trigger_engine() from
|
---|
| 381 | * touching this IORB queue until all of those IORBs have completed
|
---|
| 382 | * processing and have been removed from the queue.
|
---|
| 383 | *
|
---|
| 384 | * - Adapters can be flagged as 'busy' which means no new IORBs are sent (they
|
---|
| 385 | * just remain in the queue). This can be used to release the driver-level
|
---|
| 386 | * spinlock while making sure no new IORBs are going to hit the hardware.
|
---|
| 387 | * In order to prevent engine stalls, all handlers using this functionality
|
---|
| 388 | * need to invoke trigger_engine() after resetting the busy flag.
|
---|
| 389 | *
|
---|
| 390 | * - Handlers that use the adapter 'busy' flag when processing driver-level
|
---|
| 391 | * IORBs don't need to protect themselves against new IORBs on the driver
|
---|
| 392 | * level because those will always be queued at the end of the driver-
|
---|
| 393 | * level queue (there are no driver-level priority IORBs).
|
---|
| 394 | */
|
---|
| 395 | int trigger_engine_1(void)
|
---|
| 396 | {
|
---|
| 397 | IORBH _far *iorb;
|
---|
| 398 | int iorbs_sent = 0;
|
---|
| 399 | int a;
|
---|
| 400 | int p;
|
---|
| 401 |
|
---|
| 402 | iorbs_sent = 0;
|
---|
| 403 |
|
---|
| 404 | /* process driver-level IORBs */
|
---|
| 405 | if ((iorb = driver_queue.root) != NULL && !add_workspace(iorb)->processing) {
|
---|
| 406 | send_iorb(iorb);
|
---|
| 407 | iorbs_sent++;
|
---|
| 408 | }
|
---|
| 409 |
|
---|
| 410 | /* process port-level IORBs */
|
---|
| 411 | for (a = 0; a < ad_info_cnt; a++) {
|
---|
| 412 | AD_INFO *ai = ad_infos + a;
|
---|
| 413 | if (ai->busy) {
|
---|
| 414 | /* adapter is busy; don't process any IORBs */
|
---|
| 415 | continue;
|
---|
| 416 | }
|
---|
| 417 | for (p = 0; p <= ai->port_max; p++) {
|
---|
| 418 | if ((iorb = ai->ports[p].iorb_queue.root) != NULL &&
|
---|
| 419 | !add_workspace(iorb)->processing) {
|
---|
| 420 | send_iorb(iorb);
|
---|
| 421 | iorbs_sent++;
|
---|
| 422 | }
|
---|
| 423 | }
|
---|
| 424 | }
|
---|
| 425 |
|
---|
| 426 | return(iorbs_sent);
|
---|
| 427 | }
|
---|
| 428 |
|
---|
| 429 | /******************************************************************************
|
---|
| 430 | * Send a single IORB to the corresponding AHCI adapter/port. This is just a
|
---|
| 431 | * switch board for calling the corresponding iocc_*() handler function.
|
---|
| 432 | *
|
---|
| 433 | * NOTE: This function is expected to be called with the driver-level spinlock
|
---|
| 434 | * aquired. It will release it before calling any of the handler
|
---|
| 435 | * functions and re-aquire it when done.
|
---|
| 436 | */
|
---|
| 437 | void send_iorb(IORBH _far *iorb)
|
---|
| 438 | {
|
---|
| 439 | /* Mark IORB as "processing" before doing anything else. Once the IORB is
|
---|
| 440 | * marked as "processing", we can release the spinlock because subsequent
|
---|
| 441 | * invocations of trigger_engine() (e.g. at interrupt time) will ignore this
|
---|
| 442 | * IORB.
|
---|
| 443 | *
|
---|
| 444 | * NOTE: Handler functions are free to look at follow-up IORBs in order to
|
---|
| 445 | * queue them to the hardware (native command queueing). If they
|
---|
| 446 | * choose to do so, they must mark those IORBs as "processing" as
|
---|
| 447 | * well.
|
---|
| 448 | */
|
---|
| 449 | add_workspace(iorb)->processing = 1;
|
---|
| 450 | spin_unlock(drv_lock);
|
---|
| 451 |
|
---|
| 452 | switch (iorb->CommandCode) {
|
---|
| 453 |
|
---|
| 454 | case IOCC_CONFIGURATION:
|
---|
| 455 | iocc_configuration(iorb);
|
---|
| 456 | break;
|
---|
| 457 |
|
---|
| 458 | case IOCC_DEVICE_CONTROL:
|
---|
| 459 | iocc_device_control(iorb);
|
---|
| 460 | break;
|
---|
| 461 |
|
---|
| 462 | case IOCC_UNIT_CONTROL:
|
---|
| 463 | iocc_unit_control(iorb);
|
---|
| 464 | break;
|
---|
| 465 |
|
---|
| 466 | case IOCC_GEOMETRY:
|
---|
| 467 | iocc_geometry(iorb);
|
---|
| 468 | break;
|
---|
| 469 |
|
---|
| 470 | case IOCC_EXECUTE_IO:
|
---|
| 471 | iocc_execute_io(iorb);
|
---|
| 472 | break;
|
---|
| 473 |
|
---|
| 474 | case IOCC_UNIT_STATUS:
|
---|
| 475 | iocc_unit_status(iorb);
|
---|
| 476 | break;
|
---|
| 477 |
|
---|
| 478 | case IOCC_ADAPTER_PASSTHRU:
|
---|
| 479 | iocc_adapter_passthru(iorb);
|
---|
| 480 | break;
|
---|
| 481 |
|
---|
| 482 | default:
|
---|
| 483 | /* unsupported call */
|
---|
| 484 | iorb_seterr(iorb, IOERR_CMD_NOT_SUPPORTED);
|
---|
| 485 | iorb_done(iorb);
|
---|
| 486 | break;
|
---|
| 487 | }
|
---|
| 488 |
|
---|
| 489 | /* re-aquire spinlock before returning to trigger_engine() */
|
---|
| 490 | spin_lock(drv_lock);
|
---|
| 491 | }
|
---|
| 492 |
|
---|
| 493 | /******************************************************************************
|
---|
| 494 | * Handle IOCC_CONFIGURATION requests.
|
---|
| 495 | */
|
---|
| 496 | void iocc_configuration(IORBH _far *iorb)
|
---|
| 497 | {
|
---|
| 498 | int a;
|
---|
| 499 |
|
---|
| 500 | switch (iorb->CommandModifier) {
|
---|
| 501 |
|
---|
| 502 | case IOCM_COMPLETE_INIT:
|
---|
| 503 | /* Complete initialization. From now on, we won't have to restore the BIOS
|
---|
| 504 | * configuration after each command and we're fully operational (i.e. will
|
---|
| 505 | * use interrupts, timers and context hooks instead of polling).
|
---|
| 506 | */
|
---|
| 507 | dprintf("leaving initialization mode\n");
|
---|
| 508 | spin_lock(drv_lock);
|
---|
| 509 | if (!init_complete) {
|
---|
| 510 | for (a = 0; a < ad_info_cnt; a++) {
|
---|
| 511 | ahci_complete_init(ad_infos + a);
|
---|
| 512 | }
|
---|
| 513 | init_complete = 1;
|
---|
| 514 | }
|
---|
| 515 | spin_unlock(drv_lock);
|
---|
| 516 | iorb_done(iorb);
|
---|
| 517 | break;
|
---|
| 518 |
|
---|
| 519 | case IOCM_GET_DEVICE_TABLE:
|
---|
| 520 | /* construct a device table */
|
---|
| 521 | iocm_device_table(iorb);
|
---|
| 522 | break;
|
---|
| 523 |
|
---|
| 524 | default:
|
---|
| 525 | iorb_seterr(iorb, IOERR_CMD_NOT_SUPPORTED);
|
---|
| 526 | iorb_done(iorb);
|
---|
| 527 | break;
|
---|
| 528 | }
|
---|
| 529 | }
|
---|
| 530 |
|
---|
| 531 | /******************************************************************************
|
---|
| 532 | * Handle IOCC_DEVICE_CONTROL requests.
|
---|
| 533 | */
|
---|
| 534 | void iocc_device_control(IORBH _far *iorb)
|
---|
| 535 | {
|
---|
| 536 | AD_INFO *ai;
|
---|
| 537 | IORBH _far *ptr;
|
---|
| 538 | IORBH _far *next = NULL;
|
---|
| 539 | int a = iorb_unit_adapter(iorb);
|
---|
| 540 | int p = iorb_unit_port(iorb);
|
---|
| 541 | int d = iorb_unit_device(iorb);
|
---|
| 542 |
|
---|
| 543 | switch (iorb->CommandModifier) {
|
---|
| 544 |
|
---|
| 545 | case IOCM_ABORT:
|
---|
| 546 | /* abort all pending commands on specified port and device */
|
---|
| 547 | ai = ad_infos + a;
|
---|
| 548 | spin_lock(drv_lock);
|
---|
| 549 | for (ptr = ai->ports[p].iorb_queue.root; ptr != NULL; ptr = next) {
|
---|
| 550 | next = ptr->pNxtIORB;
|
---|
| 551 | /* move all matching IORBs to the abort queue */
|
---|
| 552 | if (ptr != iorb && iorb_unit_device(ptr) == d) {
|
---|
| 553 | iorb_queue_del(&ai->ports[p].iorb_queue, ptr);
|
---|
| 554 | iorb_queue_add(&abort_queue, ptr);
|
---|
| 555 | ptr->ErrorCode = IOERR_CMD_ABORTED;
|
---|
| 556 | }
|
---|
| 557 | }
|
---|
| 558 | spin_unlock(drv_lock);
|
---|
| 559 |
|
---|
| 560 | /* trigger reset context hook which will finish the abort processing */
|
---|
| 561 | DevHelp_ArmCtxHook(0, reset_ctxhook_h);
|
---|
| 562 | break;
|
---|
| 563 |
|
---|
| 564 | case IOCM_SUSPEND:
|
---|
| 565 | case IOCM_RESUME:
|
---|
| 566 | case IOCM_GET_QUEUE_STATUS:
|
---|
| 567 | /* Suspend/resume operations allow access to the hardware for other
|
---|
| 568 | * entities such as IBMIDECD.FLT. Since os2ahci implements both ATA
|
---|
| 569 | * and ATAPI in the same driver, this won't be required.
|
---|
| 570 | */
|
---|
| 571 | iorb_seterr(iorb, IOERR_CMD_NOT_SUPPORTED);
|
---|
| 572 | break;
|
---|
| 573 |
|
---|
| 574 | case IOCM_LOCK_MEDIA:
|
---|
| 575 | case IOCM_UNLOCK_MEDIA:
|
---|
| 576 | case IOCM_EJECT_MEDIA:
|
---|
| 577 | /* unit control commands to lock, unlock and eject media */
|
---|
| 578 | /* will be supported later... */
|
---|
| 579 | iorb_seterr(iorb, IOERR_CMD_NOT_SUPPORTED);
|
---|
| 580 | break;
|
---|
| 581 |
|
---|
| 582 | default:
|
---|
| 583 | iorb_seterr(iorb, IOERR_CMD_NOT_SUPPORTED);
|
---|
| 584 | break;
|
---|
| 585 | }
|
---|
| 586 |
|
---|
| 587 | iorb_done(iorb);
|
---|
| 588 | }
|
---|
| 589 |
|
---|
| 590 | /******************************************************************************
|
---|
| 591 | * Handle IOCC_UNIT_CONTROL requests.
|
---|
| 592 | */
|
---|
| 593 | void iocc_unit_control(IORBH _far *iorb)
|
---|
| 594 | {
|
---|
| 595 | IORB_UNIT_CONTROL _far *iorb_uc = (IORB_UNIT_CONTROL _far *) iorb;
|
---|
| 596 | int a = iorb_unit_adapter(iorb);
|
---|
| 597 | int p = iorb_unit_port(iorb);
|
---|
| 598 | int d = iorb_unit_device(iorb);
|
---|
| 599 |
|
---|
| 600 | spin_lock(drv_lock);
|
---|
| 601 | switch (iorb->CommandModifier) {
|
---|
| 602 |
|
---|
| 603 | case IOCM_ALLOCATE_UNIT:
|
---|
| 604 | /* allocate unit for exclusive access */
|
---|
| 605 | if (ad_infos[a].ports[p].devs[d].allocated) {
|
---|
| 606 | iorb_seterr(iorb, IOERR_UNIT_ALLOCATED);
|
---|
| 607 | } else {
|
---|
| 608 | ad_infos[a].ports[p].devs[d].allocated = 1;
|
---|
| 609 | }
|
---|
| 610 | break;
|
---|
| 611 |
|
---|
| 612 | case IOCM_DEALLOCATE_UNIT:
|
---|
| 613 | /* deallocate exclusive access to unit */
|
---|
| 614 | if (!ad_infos[a].ports[p].devs[d].allocated) {
|
---|
| 615 | iorb_seterr(iorb, IOERR_UNIT_NOT_ALLOCATED);
|
---|
| 616 | } else {
|
---|
| 617 | ad_infos[a].ports[p].devs[d].allocated = 0;
|
---|
| 618 | }
|
---|
| 619 | break;
|
---|
| 620 |
|
---|
| 621 | case IOCM_CHANGE_UNITINFO:
|
---|
| 622 | /* Change unit (device) information. One reason for this IOCM is the
|
---|
| 623 | * interface for filter device drivers: a filter device driver can
|
---|
| 624 | * either change existing UNITINFOs or permanently allocate units
|
---|
| 625 | * and fabricate new [logical] units; the former is the reason why we
|
---|
| 626 | * must store the pointer to the updated UNITNIFO for subsequent
|
---|
| 627 | * IOCC_CONFIGURATION/IOCM_GET_DEVICE_TABLE calls.
|
---|
| 628 | */
|
---|
| 629 | if (!ad_infos[a].ports[p].devs[d].allocated) {
|
---|
| 630 | iorb_seterr(iorb, IOERR_UNIT_NOT_ALLOCATED);
|
---|
| 631 | break;
|
---|
| 632 | }
|
---|
| 633 | ad_infos[a].ports[p].devs[d].unit_info = iorb_uc->pUnitInfo;
|
---|
| 634 | break;
|
---|
| 635 |
|
---|
| 636 | default:
|
---|
| 637 | iorb_seterr(iorb, IOERR_CMD_NOT_SUPPORTED);
|
---|
| 638 | break;
|
---|
| 639 | }
|
---|
| 640 |
|
---|
| 641 | spin_unlock(drv_lock);
|
---|
| 642 | iorb_done(iorb);
|
---|
| 643 | }
|
---|
| 644 |
|
---|
| 645 | /******************************************************************************
|
---|
| 646 | * Scan all ports for AHCI devices and construct a DASD device table.
|
---|
| 647 | *
|
---|
| 648 | * NOTE: This function may be called multiple times. Only the first invocation
|
---|
| 649 | * will actually scan for devices; all subsequent calls will merely
|
---|
| 650 | * return the results of the initial scan, potentially augmented by
|
---|
| 651 | * modified unit infos after IOCC_CONFIGURATION/IOCM_CHANGE_UNITINFO
|
---|
| 652 | * requests.
|
---|
| 653 | */
|
---|
| 654 | void iocm_device_table(IORBH _far *iorb)
|
---|
| 655 | {
|
---|
| 656 | IORB_CONFIGURATION _far *iorb_conf;
|
---|
| 657 | DEVICETABLE _far *dt;
|
---|
| 658 | char _far *pos;
|
---|
| 659 | int rc;
|
---|
| 660 | int a;
|
---|
| 661 | int p;
|
---|
| 662 | int d;
|
---|
| 663 |
|
---|
| 664 | iorb_conf = (IORB_CONFIGURATION _far *) iorb;
|
---|
| 665 | dt = iorb_conf->pDeviceTable;
|
---|
| 666 |
|
---|
| 667 | spin_lock(drv_lock);
|
---|
| 668 |
|
---|
| 669 | /* initialize device table header */
|
---|
| 670 | dt->ADDLevelMajor = ADD_LEVEL_MAJOR;
|
---|
| 671 | dt->ADDLevelMinor = ADD_LEVEL_MINOR;
|
---|
| 672 | dt->ADDHandle = add_handle;
|
---|
| 673 | dt->TotalAdapters = ad_info_cnt;
|
---|
| 674 |
|
---|
| 675 | /* Initial position of dynamic portion of device table (i.e. behind the
|
---|
| 676 | * array of ADAPTERINFO pointers, pAdapter, in the device table)
|
---|
| 677 | */
|
---|
| 678 | pos = (char _far *) (dt->pAdapter + ad_info_cnt);
|
---|
| 679 |
|
---|
| 680 | for (a = 0; a < ad_info_cnt; a++) {
|
---|
| 681 | ADAPTERINFO _far *ptr = (ADAPTERINFO _far *) pos;
|
---|
| 682 | AD_INFO *ad_info = ad_infos + a;
|
---|
| 683 | int units = 0;
|
---|
| 684 |
|
---|
| 685 | /* sanity check for sufficient space in device table */
|
---|
| 686 | if ((u32) (ptr + 1) - (u32) dt > iorb_conf->DeviceTableLen) {
|
---|
| 687 | dprintf("error: device table provided by DASD too small\n");
|
---|
| 688 | iorb_seterr(iorb, IOERR_CMD_SW_RESOURCE);
|
---|
| 689 | goto iocm_device_table_done;
|
---|
| 690 | }
|
---|
| 691 |
|
---|
| 692 | /* set ADAPTERINFO offset in device table */
|
---|
| 693 | dt->pAdapter[a] = (ADAPTERINFO _near *) ((u32) ptr & 0xffff);
|
---|
| 694 |
|
---|
| 695 | /* fill in adapter information structure in device table */
|
---|
| 696 | memset(ptr, 0x00, sizeof(*ptr));
|
---|
| 697 | sprintf(ptr->AdapterName, "AHCI_%d", a);
|
---|
| 698 | ptr->AdapterDevBus = AI_DEVBUS_ST506 | AI_DEVBUS_32BIT;
|
---|
| 699 | ptr->AdapterIOAccess = AI_IOACCESS_BUS_MASTER;
|
---|
| 700 | ptr->AdapterHostBus = AI_HOSTBUS_OTHER | AI_BUSWIDTH_32BIT;
|
---|
| 701 | ptr->AdapterFlags = AF_16M | AF_HW_SCATGAT;
|
---|
| 702 |
|
---|
[8] | 703 | /* AHCI limits S/G elements to 22 bits, thus we'll report only half of
|
---|
| 704 | * our S/G list buffers to reduce complexity. The command preparation code
|
---|
| 705 | * will always try to map as many S/G elements as possible so the physical
|
---|
| 706 | * S/G list capacity is not really wasted except in rare conditions where
|
---|
| 707 | * we need to split commands with long S/G lists without any suitable split
|
---|
| 708 | * points except those at the reported MaxHWSGList.
|
---|
| 709 | */
|
---|
| 710 | ptr->MaxHWSGList = AHCI_MAX_SG / 2;
|
---|
| 711 |
|
---|
[4] | 712 | if (!ad_info->port_scan_done) {
|
---|
| 713 | /* First call; need to scan AHCI hardware for devices. Since this might
|
---|
| 714 | * be a lengthy operation, especially when init_reset is set, we'll mark
|
---|
| 715 | * the adapter as busy (new IORBs will only be queued but not executed)
|
---|
| 716 | * and release the spinlock while scanning the ports so interrupts will
|
---|
| 717 | * be processed.
|
---|
| 718 | */
|
---|
| 719 | if (ad_info->busy) {
|
---|
| 720 | dprintf("error: port scan requested while adapter was busy\n");
|
---|
| 721 | iorb_seterr(iorb, IOERR_CMD_SW_RESOURCE);
|
---|
| 722 | goto iocm_device_table_done;
|
---|
| 723 | }
|
---|
| 724 | ad_info->busy = 1;
|
---|
| 725 | spin_unlock(drv_lock);
|
---|
| 726 | rc = ahci_scan_ports(ad_info);
|
---|
| 727 | spin_lock(drv_lock);
|
---|
| 728 | ad_info->busy = 0;
|
---|
| 729 |
|
---|
| 730 | if (rc != 0) {
|
---|
| 731 | dprintf("error: port scan failed on adapter #%d\n", a);
|
---|
| 732 | iorb_seterr(iorb, IOERR_CMD_SW_RESOURCE);
|
---|
| 733 | goto iocm_device_table_done;
|
---|
| 734 | }
|
---|
| 735 | ad_info->port_scan_done = 1;
|
---|
| 736 | }
|
---|
| 737 |
|
---|
| 738 | /* insert devices (units) into the device table */
|
---|
| 739 | for (p = 0; p <= ad_info->port_max; p++) {
|
---|
| 740 | for (d = 0; d <= ad_info->ports[p].dev_max; d++) {
|
---|
| 741 | if (ad_info->ports[p].devs[d].present) {
|
---|
| 742 | UNITINFO _far *ui = ptr->UnitInfo + units;
|
---|
| 743 |
|
---|
| 744 | /* sanity check for sufficient space in device table */
|
---|
| 745 | if ((u32) (ui + 1) - (u32) dt > iorb_conf->DeviceTableLen) {
|
---|
| 746 | dprintf("error: device table provided by DASD too small\n");
|
---|
| 747 | iorb_seterr(iorb, IOERR_CMD_SW_RESOURCE);
|
---|
| 748 | goto iocm_device_table_done;
|
---|
| 749 | }
|
---|
| 750 |
|
---|
| 751 | if (ad_info->ports[p].devs[d].unit_info == NULL) {
|
---|
| 752 | /* provide initial information about this device (unit) */
|
---|
| 753 | memset(ui, 0x00, sizeof(*ui));
|
---|
| 754 | ui->AdapterIndex = a;
|
---|
| 755 | ui->UnitIndex = units;
|
---|
| 756 | ui->UnitHandle = iorb_unit(a, p, d);
|
---|
| 757 | ui->UnitType = ad_info->ports[p].devs[d].dev_type;
|
---|
| 758 | ui->QueuingCount = AHCI_MAX_CMDS;
|
---|
| 759 | if (ad_info->ports[p].devs[d].removable) {
|
---|
| 760 | ui->UnitFlags |= UF_REMOVABLE;
|
---|
| 761 | }
|
---|
| 762 | } else {
|
---|
| 763 | /* copy updated device (unit) information (IOCM_CHANGE_UNITINFO) */
|
---|
| 764 | memcpy(ui, ad_info->ports[p].devs[d].unit_info, sizeof(*ui));
|
---|
| 765 | }
|
---|
| 766 | units++;
|
---|
| 767 | }
|
---|
| 768 | }
|
---|
| 769 | }
|
---|
| 770 |
|
---|
| 771 | /* set total device (unit) count for this adapter */
|
---|
| 772 | ptr->AdapterUnits = units;
|
---|
| 773 |
|
---|
| 774 | /* calculate offset for next adapter */
|
---|
| 775 | pos = (char _far *) (ptr->UnitInfo + units);
|
---|
| 776 | }
|
---|
| 777 |
|
---|
| 778 | iocm_device_table_done:
|
---|
| 779 | spin_unlock(drv_lock);
|
---|
| 780 | iorb_done(iorb);
|
---|
| 781 | }
|
---|
| 782 |
|
---|
| 783 | /******************************************************************************
|
---|
| 784 | * Handle IOCC_GEOMETRY requests.
|
---|
| 785 | */
|
---|
| 786 | void iocc_geometry(IORBH _far *iorb)
|
---|
| 787 | {
|
---|
| 788 | switch (iorb->CommandModifier) {
|
---|
| 789 |
|
---|
| 790 | case IOCM_GET_MEDIA_GEOMETRY:
|
---|
| 791 | case IOCM_GET_DEVICE_GEOMETRY:
|
---|
| 792 | add_workspace(iorb)->idempotent = 1;
|
---|
| 793 | ahci_get_geometry(iorb);
|
---|
| 794 | break;
|
---|
| 795 |
|
---|
| 796 | default:
|
---|
| 797 | iorb_seterr(iorb, IOERR_CMD_NOT_SUPPORTED);
|
---|
| 798 | iorb_done(iorb);
|
---|
| 799 | }
|
---|
| 800 | }
|
---|
| 801 |
|
---|
| 802 | /******************************************************************************
|
---|
| 803 | * Handle IOCC_EXECUTE_IO requests.
|
---|
| 804 | */
|
---|
| 805 | void iocc_execute_io(IORBH _far *iorb)
|
---|
| 806 | {
|
---|
| 807 | switch (iorb->CommandModifier) {
|
---|
| 808 |
|
---|
| 809 | case IOCM_READ:
|
---|
| 810 | add_workspace(iorb)->idempotent = 1;
|
---|
| 811 | ahci_read(iorb);
|
---|
| 812 | break;
|
---|
| 813 |
|
---|
| 814 | case IOCM_READ_VERIFY:
|
---|
| 815 | add_workspace(iorb)->idempotent = 1;
|
---|
| 816 | ahci_verify(iorb);
|
---|
| 817 | break;
|
---|
| 818 |
|
---|
| 819 | case IOCM_WRITE:
|
---|
| 820 | add_workspace(iorb)->idempotent = 1;
|
---|
| 821 | ahci_write(iorb);
|
---|
| 822 | break;
|
---|
| 823 |
|
---|
| 824 | case IOCM_WRITE_VERIFY:
|
---|
| 825 | add_workspace(iorb)->idempotent = 1;
|
---|
| 826 | ahci_write(iorb);
|
---|
| 827 | break;
|
---|
| 828 |
|
---|
| 829 | default:
|
---|
| 830 | iorb_seterr(iorb, IOERR_CMD_NOT_SUPPORTED);
|
---|
| 831 | iorb_done(iorb);
|
---|
| 832 | }
|
---|
| 833 | }
|
---|
| 834 |
|
---|
| 835 | /******************************************************************************
|
---|
| 836 | * Handle IOCC_UNIT_STATUS requests.
|
---|
| 837 | */
|
---|
| 838 | void iocc_unit_status(IORBH _far *iorb)
|
---|
| 839 | {
|
---|
| 840 | switch (iorb->CommandModifier) {
|
---|
| 841 |
|
---|
| 842 | case IOCM_GET_UNIT_STATUS:
|
---|
| 843 | add_workspace(iorb)->idempotent = 1;
|
---|
| 844 | ahci_unit_ready(iorb);
|
---|
| 845 | break;
|
---|
| 846 |
|
---|
| 847 | default:
|
---|
| 848 | iorb_seterr(iorb, IOERR_CMD_NOT_SUPPORTED);
|
---|
| 849 | iorb_done(iorb);
|
---|
| 850 | }
|
---|
| 851 | }
|
---|
| 852 |
|
---|
| 853 | /******************************************************************************
|
---|
| 854 | * Handle IOCC_ADAPTER_PASSTHROUGH requests.
|
---|
| 855 | */
|
---|
| 856 | void iocc_adapter_passthru(IORBH _far *iorb)
|
---|
| 857 | {
|
---|
| 858 | switch (iorb->CommandModifier) {
|
---|
| 859 |
|
---|
| 860 | case IOCM_EXECUTE_CDB:
|
---|
| 861 | ahci_execute_cdb(iorb);
|
---|
| 862 | break;
|
---|
| 863 |
|
---|
| 864 | case IOCM_EXECUTE_ATA:
|
---|
| 865 | ahci_execute_ata(iorb);
|
---|
| 866 | break;
|
---|
| 867 |
|
---|
| 868 | default:
|
---|
| 869 | iorb_seterr(iorb, IOERR_CMD_NOT_SUPPORTED);
|
---|
| 870 | iorb_done(iorb);
|
---|
| 871 | }
|
---|
| 872 | }
|
---|
| 873 |
|
---|
| 874 | /******************************************************************************
|
---|
| 875 | * Add an IORB to the specified queue.
|
---|
| 876 | */
|
---|
| 877 | void iorb_queue_add(IORB_QUEUE _far *queue, IORBH _far *iorb)
|
---|
| 878 | {
|
---|
| 879 | if (iorb_priority(iorb) {
|
---|
| 880 | /* priority IORB; insert at first position */
|
---|
| 881 | iorb->pNxtIORB = queue->root;
|
---|
| 882 | queue->root = iorb;
|
---|
| 883 |
|
---|
| 884 | } else {
|
---|
| 885 | /* append IORB to end of queue */
|
---|
| 886 | iorb->pNxtIORB = NULL;
|
---|
| 887 |
|
---|
| 888 | if (queue->root == NULL) {
|
---|
| 889 | queue->root = iorb;
|
---|
| 890 | } else {
|
---|
| 891 | queue->tail->pNxtIORB = iorb;
|
---|
| 892 | }
|
---|
| 893 | queue->tail = iorb;
|
---|
| 894 | }
|
---|
| 895 |
|
---|
| 896 | ddprintf("IORB queued: %d/%d (queue = %Fp, IORB = %Fp)\n",
|
---|
| 897 | iorb->CommandCode, iorb->CommandModifier, queue, iorb);
|
---|
| 898 | }
|
---|
| 899 |
|
---|
| 900 | /******************************************************************************
|
---|
| 901 | * Remove an IORB from the specified queue.
|
---|
| 902 | */
|
---|
| 903 | int iorb_queue_del(IORB_QUEUE _far *queue, IORBH _far *iorb)
|
---|
| 904 | {
|
---|
| 905 | IORBH _far *_iorb;
|
---|
| 906 | IORBH _far *_prev = NULL;
|
---|
| 907 | int found = 0;
|
---|
| 908 |
|
---|
| 909 | for (_iorb = queue->root; _iorb != NULL; _iorb = _iorb->pNxtIORB) {
|
---|
| 910 | if (_iorb == iorb) {
|
---|
| 911 | /* found the IORB to be removed */
|
---|
| 912 | if (_prev != NULL) {
|
---|
| 913 | _prev->pNxtIORB = _iorb->pNxtIORB;
|
---|
| 914 | } else {
|
---|
| 915 | queue->root = _iorb->pNxtIORB;
|
---|
| 916 | }
|
---|
| 917 | if (_iorb == queue->tail) {
|
---|
| 918 | queue->tail = _prev;
|
---|
| 919 | }
|
---|
| 920 | found = 1;
|
---|
| 921 | break;
|
---|
| 922 | }
|
---|
| 923 | _prev = _iorb;
|
---|
| 924 | }
|
---|
| 925 |
|
---|
| 926 | if (found) {
|
---|
| 927 | ddprintf("IORB removed: %d/%d (queue = %Fp, IORB = %Fp) - %04x/%04x\n",
|
---|
| 928 | iorb->CommandCode, iorb->CommandModifier, queue, iorb,
|
---|
| 929 | iorb->Status, iorb->ErrorCode);
|
---|
| 930 | } else {
|
---|
| 931 | ddprintf("IORB %Fp not found in queue %Fp\n", iorb, queue);
|
---|
| 932 | }
|
---|
| 933 |
|
---|
| 934 | return(!found);
|
---|
| 935 | }
|
---|
| 936 |
|
---|
| 937 | /******************************************************************************
|
---|
| 938 | * Set the error code in the specified IORB
|
---|
| 939 | *
|
---|
| 940 | * NOTE: This function does *not* call iorb_done(). It merely sets the IORB
|
---|
| 941 | * status to the specified error code.
|
---|
| 942 | */
|
---|
| 943 | void iorb_seterr(IORBH _far *iorb, USHORT error_code)
|
---|
| 944 | {
|
---|
| 945 | iorb->ErrorCode = error_code;
|
---|
| 946 | iorb->Status = IORB_ERROR;
|
---|
| 947 | }
|
---|
| 948 |
|
---|
| 949 | /******************************************************************************
|
---|
| 950 | * Mark the specified IORB as done and notify the asynchronous post function,
|
---|
| 951 | * if any. The IORB is also removed from the corresponding IORB queue.
|
---|
| 952 | *
|
---|
| 953 | * NOTES: This function does not clear the Status field; it merely adds the
|
---|
| 954 | * IORB_DONE flag.
|
---|
| 955 | *
|
---|
| 956 | * This function is expected to be called *without* the corresponding
|
---|
| 957 | * driver-level drv_lock aquired. It will aquire the spinlock before
|
---|
| 958 | * updating the IORB queue and release it before notifying the upstream
|
---|
| 959 | * code in order to prevent deadlocks.
|
---|
| 960 | *
|
---|
| 961 | * Due to this logic, this function is only good for simple task-time
|
---|
| 962 | * completions. Functions working on lists of IORBs (such as interrupt
|
---|
| 963 | * handlers or context hooks) should implement their own logic. See
|
---|
| 964 | * abort_ctxhook() for an example.
|
---|
| 965 | */
|
---|
| 966 | void iorb_done(IORBH _far *iorb)
|
---|
| 967 | {
|
---|
| 968 | int a = iorb_unit_adapter(iorb);
|
---|
| 969 | int p = iorb_unit_port(iorb);
|
---|
| 970 |
|
---|
| 971 | /* remove IORB from corresponding queue */
|
---|
| 972 | spin_lock(drv_lock);
|
---|
| 973 | if (iorb_driver_level(iorb)) {
|
---|
| 974 | iorb_queue_del(&driver_queue, iorb);
|
---|
| 975 | } else {
|
---|
| 976 | iorb_queue_del(&ad_infos[a].ports[p].iorb_queue, iorb);
|
---|
| 977 | }
|
---|
| 978 | aws_free(add_workspace(iorb));
|
---|
| 979 | spin_unlock(drv_lock);
|
---|
| 980 |
|
---|
| 981 | /* notify caller, if requested */
|
---|
| 982 | iorb->Status |= IORB_DONE;
|
---|
| 983 | if (iorb->RequestControl & IORB_ASYNC_POST) {
|
---|
| 984 | iorb->NotifyAddress(iorb);
|
---|
| 985 | }
|
---|
| 986 | }
|
---|
| 987 |
|
---|
[8] | 988 | /******************************************************************************
|
---|
| 989 | * Requeue the specified IORB such that it will be sent downstream for
|
---|
| 990 | * processing again. This includes freeing all resources currently allocated
|
---|
| 991 | * (timer, buffer, ...) and resetting the flags to 0.
|
---|
| 992 | *
|
---|
| 993 | * The following flags are preserved:
|
---|
| 994 | * - no_ncq
|
---|
| 995 | */
|
---|
| 996 | void iorb_requeue(IORBH _far *iorb)
|
---|
| 997 | {
|
---|
| 998 | ADD_WORKSPACE _far *aws = add_workspace(iorb);
|
---|
| 999 | u16 no_ncq = aws->no_ncq;
|
---|
| 1000 |
|
---|
| 1001 | aws_free(aws);
|
---|
| 1002 | memset(aws, 0x00, sizeof(*aws));
|
---|
| 1003 | aws->no_ncq = no_ncq;
|
---|
| 1004 | }
|
---|
| 1005 |
|
---|