* Copyright (c) 1987 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
* @(#)mscp.c 1.1 (Berkeley) %G%
* MSCP generic driver routines
#include "../vaxuba/ubavar.h"
#define PCMD PSWP /* priority for command packet waits */
* During transfers, mapping info is saved in the buffer's b_resid.
* Get a command packet. Second argument is true iff we are
* to wait if necessary. Return NULL if none are available and
register struct mscp_info
*mi
;
#define mri (&mi->mi_cmd)
register struct mscp
*mp
;
* Ensure that we have some command credits, and
* that the next command packet is free.
if (mi
->mi_credits
<= MSCP_MINCREDITS
) {
sleep((caddr_t
) &mi
->mi_wantcredits
, PCMD
);
if (mri
->mri_desc
[i
] & MSCP_OWN
) {
sleep((caddr_t
) &mi
->mi_wantcmd
, PCMD
);
mri
->mri_desc
[i
] &= ~MSCP_INT
;
mri
->mri_next
= (mri
->mri_next
+ 1) % mri
->mri_size
;
* Initialise some often-zero fields.
* ARE THE LAST TWO NECESSARY IN GENERAL? IT SURE WOULD BE
* NICE IF DEC SOLD DOCUMENTATION FOR THEIR OWN CONTROLLERS.
mp
->mscp_msglen
= MSCP_MSGLEN
;
mp
->mscp_seq
.seq_bytecount
= 0;
mp
->mscp_seq
.seq_buffer
= 0;
mp
->mscp_seq
.seq_mapbase
= 0;
/*???*/ mp
->mscp_sccc
.sccc_errlgfl
= 0;
/*???*/ mp
->mscp_sccc
.sccc_copyspd
= 0;
* Decode and print an MSCP media ID. It is made up of five 5-bit
* `characters' and 7 bits of numeric information. BITS(i)
* selects character i's bits; CHAR returns the corresponding
#define BITS(i) ((id >> ((i) * 5 + 7)) & 0x1f)
#define CHAR(c) ((c) ? (c) + '@' : ' ')
printf("%c%c %c%c%c%d", CHAR(c4
), CHAR(c3
), CHAR(c2
),
CHAR(c1
), CHAR(c0
), id
& 0x7f);
int mscp_aeb_xor
= 0x8000bb80;
* Do a device go. The driver calls this once it has allocated
* resources for the transfer. Save the resource information in
* bp->b_ubinfo, and finish the MSCP packet.
* N.B.: If we were blocked for some time, the drive could have gone
* off line and might still be that way. We should probably handle
* such a case by changing this command into an on line request and
* not dequeuing the transfer after all.
register struct mscp_info
*mi
;
register struct mscp
*mp
;
register struct buf
*bp
, *dp
;
* Now is also the time to move the transfer off the
* controller and drive queues, and shuffle the drive
* queue on the controller queue. The idea is to try
* to keep as many drives busy as possible---to deal
* the controller's credits out to the drives in a `fair
* share' arrangement. (To do this fully would be more
* trouble than it is worth, though.)
dp
->b_actf
= bp
->av_forw
; /* transfer off drive queue */
mi
->mi_tab
->b_actf
= dp
->b_forw
;/* drive off ctlr queue */
APPEND(dp
, mi
->mi_tab
, b_forw
); /* then back again */
* Move the buffer to the I/O wait queue.
bp
->av_back
= mi
->mi_wtab
.av_back
;
bp
->av_forw
= &mi
->mi_wtab
;
mi
->mi_wtab
.av_back
->av_forw
= bp
;
mi
->mi_wtab
.av_back
= bp
;
* Save the mapping info, finish the command packet, and give
* it to the device. The device's dgo routine should then
* The Emulex SC41/MS will occasionally zero the lower half word
* of the command reference number. The upper half word remains
* intact. To keep running, we convert the buffer address into
* a small but nonzero integer that is unique over all pending
* transfers, and store that value in the upper half word. To
* catch occurrances of the bug (so that we can gripe to Emulex),
* we also put a nonzero value in the lower word.
register u_int i
= mi
->mi_nextbp
;
do { /* find a free value */
i
= (i
+ 1) % AEB_MAX_BP
;
} while (i
!= mi
->mi_nextbp
);
panic("mscp_go: AEB_MAX_BP too small");
mi
->mi_nextbp
= i
% AEB_MAX_BP
;
mp
->mscp_cmdref
= (i
<< 16) ^ mscp_aeb_xor
;
mp
->mscp_cmdref
= (long) bp
;
*mp
->mscp_addr
|= MSCP_OWN
| MSCP_INT
;
* Handle a response ring transition.
register struct mscp_info
*mi
;
register struct uba_device
*ui
;
register struct mscp
*mp
;
struct mscp_driver
*md
= mi
->mi_md
;
char *ctlrname
, *drivename
;
drivename
= md
->md_dname
;
nextrsp
= mi
->mi_rsp
.mri_next
;
if (mi
->mi_rsp
.mri_desc
[nextrsp
] & MSCP_OWN
) {
* No more responses. Remember the next expected
* response index. Check to see if we have some
* credits back, and wake up sleepers if so.
mi
->mi_rsp
.mri_next
= nextrsp
;
if (mi
->mi_wantcredits
&& mi
->mi_credits
> MSCP_MINCREDITS
) {
wakeup((caddr_t
) &mi
->mi_wantcredits
);
* Found a response. Update credit information. If there is
* nothing else to do, jump to `done' to get the next response.
mp
= &mi
->mi_rsp
.mri_ring
[nextrsp
];
mi
->mi_credits
+= MSCP_CREDITS(mp
->mscp_msgtc
);
switch (MSCP_MSGTYPE(mp
->mscp_msgtc
)) {
printf("%s%d: unit %d: unknown message type 0x%x ignored\n",
ctlrname
, mi
->mi_ctlr
, mp
->mscp_unit
,
MSCP_MSGTYPE(mp
->mscp_msgtc
));
* Controllers are allowed to interrupt as any drive, so we
* must check the command before checking for a drive.
if (mp
->mscp_opcode
== (M_OP_SETCTLRC
| M_OP_END
)) {
(*md
->md_ctlrdone
)(mi
, mp
);
* Find the drive info. If there is none, and this is an
* available attention response, try configuring a new drive.
if (mp
->mscp_unit
> md
->md_ndpc
) {
printf("%s%d: unit %d out of range\n",
ctlrname
, mi
->mi_ctlr
, mp
->mscp_unit
);
if ((ui
= mi
->mi_ip
[mp
->mscp_unit
]) == NULL
) {
if ((*md
->md_unconf
)(mi
, mp
) != MSCP_DONE
) {
printf("%s%d: unit %d not configured, ",
ctlrname
, mi
->mi_ctlr
, mp
->mscp_unit
);
if (mp
->mscp_opcode
== M_OP_AVAILATTN
)
printf("available attn");
printf("stray response op 0x%x status 0x%x",
mp
->mscp_opcode
, mp
->mscp_status
);
* Handle individual responses.
st
= mp
->mscp_status
& M_ST_MASK
;
switch (mp
->mscp_opcode
) {
* The controller presents a bogus END packet when
* a read/write command is given with an illegal
* block number. This is contrary to the MSCP
* specification (ENDs are to be given only for
* invalid commands), but that is the way of it.
if (st
== M_ST_INVALCMD
&& mp
->mscp_cmdref
!= 0) {
printf("%s%d: bad lbn (%d)?\n", drivename
,
ui
->ui_unit
, mp
->mscp_seq
.seq_lbn
);
case M_OP_ONLINE
| M_OP_END
:
* Finished an ON LINE request. Call the driver to
* find out whether it succeeded. If so, mark it on
if (ui
->ui_flags
& UNIT_ONLINE
) {
printf("%s%d: duplicate ONLINE ignored\n",
if ((*md
->md_online
)(ui
, mp
) == MSCP_DONE
)
ui
->ui_flags
|= UNIT_ONLINE
;
case M_OP_GETUNITST
| M_OP_END
:
* Got unit status. Call the driver to find out
* whether it succeeded, and if so, mark it.
if ((*md
->md_gotstatus
)(ui
, mp
) == MSCP_DONE
)
ui
->ui_flags
|= UNIT_HAVESTATUS
;
* The drive went offline and we did not notice.
* Mark it off line now, to force an on line request
* next, so we can make sure it is still the same
* IF THE UDA DRIVER HAS A COMMAND AWAITING UNIBUS
* RESOURCES, THAT COMMAND MAY GO OUT BEFORE THE ON
* LINE. IS IT WORTH FIXING??
ui
->ui_flags
&= ~(UNIT_ONLINE
| UNIT_HAVESTATUS
);
(*md
->md_offline
)(ui
, mp
);
case M_OP_READ
| M_OP_END
:
case M_OP_WRITE
| M_OP_END
:
* A transfer finished. Get the buffer, and release its
* map registers via ubadone(). If the command finished
* with an off line or available status, the drive went
* off line (the idiot controller does not tell us until
* it comes back *on* line, or until we try to use it).
if (mp
->mscp_cmdref
== 0) {
* No buffer means there is a bug somewhere!
printf("%s%d: io done, but no buffer?\n",
register u_short
*p
= (u_short
*) &mp
->mscp_cmdref
;
* Note any errors on the part of the controller.
* The lower word should be zero after exclusive
* or'ing with mscp_aeb_xor, and the upper should
* then be in the range [1..AEB_MAX_BP].
mp
->mscp_cmdref
^= mscp_aeb_xor
;
panic("unrecoverable Emulex screwup");
* Calculate the expected response,
* assuming p[1] is correct. The
* actual response is then the expected
int sb
= ((p
[1] + 1) << 16) ^ mscp_aeb_xor
;
Emulex SC41/MS screwup: %s%d, got %d correct, then changed 0x%x to 0x%x\n",
mi
->mi_ok
, sb
, sb
^ p
[0]);
/* convert index back to buffer, and mark free */
bp
= (struct buf
*) mp
->mscp_cmdref
;
register struct buf
*q
= mi
->mi_wtab
.av_forw
;
* Ensure that this response corresponds to
* some outstanding request. If not, ignore
* it entirely. This will likely cause a
* Unibus reset soon, after which the controller
while (q
!= bp
&& q
!= &mi
->mi_wtab
)
printf("%s%d: bad response packet ignored\n",
* Mark any error-due-to-bad-LBN (via `goto rwend').
* WHAT STATUS WILL THESE HAVE? IT SURE WOULD BE NICE
* IF DEC SOLD DOCUMENTATION FOR THEIR OWN CONTROLLERS.
if (st
== M_ST_OFFLINE
|| st
== M_ST_AVAILABLE
) {
ui
->ui_flags
&= ~(UNIT_ONLINE
| UNIT_HAVESTATUS
);
(*md
->md_offline
)(ui
, mp
);
* Unlink the transfer from the wait queue mi_wtab.
* If there are no more transfers on the drive queue
* for this drive, and it is a profiled disk, turn
bp
->av_back
->av_forw
= bp
->av_forw
;
bp
->av_forw
->av_back
= bp
->av_back
;
if (ui
->ui_dk
>= 0 && md
->md_utab
[ui
->ui_unit
].b_forw
== NULL
)
dk_busy
&= ~(1 << ui
->ui_dk
);
* If the transfer has something to do with bad
* block forwarding, let the driver handle the
if ((bp
->b_flags
& B_BAD
) != 0 && md
->md_bb
!= NULL
) {
(*md
->md_bb
)(ui
, mp
, bp
);
* If the transfer failed, give the driver a crack
if (st
!= M_ST_SUCCESS
) {
switch ((*md
->md_ioerr
)(ui
, mp
, bp
)) {
case MSCP_DONE
: /* fixed */
case MSCP_RESTARTED
: /* still working on it */
case MSCP_FAILED
: /* no luck */
* Set the residual count and mark the transfer as
* done. If the I/O wait queue is now empty, release
* the shared BDP, if any.
info
= bp
->b_info
; /* we are about to clobber it */
bp
->b_resid
= bp
->b_bcount
- mp
->mscp_seq
.seq_bytecount
;
(*md
->md_iodone
)(mi
, bp
, info
);
case M_OP_REPLACE
| M_OP_END
:
* A replace operation finished. Just let the driver
* handle it (if it does replaces).
if (md
->md_replace
== NULL
)
printf("%s%d: bogus REPLACE end\n",
(*md
->md_replace
)(ui
, mp
);
* If it is not one of the above, we cannot handle it.
* (And we should not have received it, for that matter.)
printf("%s%d: unknown opcode 0x%x status 0x%x ignored\n",
mi
->mi_md
->md_dname
, ui
->ui_unit
,
mp
->mscp_opcode
, mp
->mscp_status
);
* If the drive needs to be put back in the controller queue,
* do that now. (`bp' below ought to be `dp', but they are all
* struct buf *.) Note that b_active was cleared in the driver;
* we presume that there is something to be done, hence reassert it.
if (ui
->ui_flags
& UNIT_REQUEUE
) {
bp
= &md
->md_utab
[ui
->ui_unit
];
if (bp
->b_active
) panic("mscp_dorsp requeue");
APPEND(bp
, mi
->mi_tab
, b_forw
);
ui
->ui_flags
&= ~UNIT_REQUEUE
;
* Give back the response packet, and take a look at the next.
mp
->mscp_msglen
= MSCP_MSGLEN
;
mi
->mi_rsp
.mri_desc
[nextrsp
] |= MSCP_OWN
;
nextrsp
= (nextrsp
+ 1) % mi
->mi_rsp
.mri_size
;
* Dump the entire contents of an MSCP packet in hex. Mainly useful
register struct mscp
*mp
;
register long *p
= (long *) mp
;
register int i
= mp
->mscp_msglen
;
if (i
> 256) /* sanity */
i
/= sizeof (*p
); /* ASSUMES MULTIPLE OF sizeof(long) */
* Requeue outstanding transfers, e.g., after bus reset.
* Also requeue any drives that have on line or unit status
register struct uba_device
*ui
;
register struct mscp_driver
*md
= mi
->mi_md
;
register struct buf
*bp
, *dp
;
* Clear the controller chain. Mark everything un-busy; we
* will soon fix any that are in fact busy.
mi
->mi_tab
->b_actf
= NULL
;
mi
->mi_tab
->b_active
= 0;
for (unit
= 0, dp
= md
->md_utab
; unit
< md
->md_nunits
; unit
++, dp
++) {
if (ui
== NULL
|| !ui
->ui_alive
|| ui
->ui_ctlr
!= mi
->mi_ctlr
)
* Scan the wait queue, linking buffers onto drive queues.
* Note that these must be put at the front of the drive queue,
* lest we reorder I/O operations.
for (bp
= mi
->mi_wtab
.av_back
; bp
!= &mi
->mi_wtab
; bp
= nextbp
) {
dp
= &md
->md_utab
[minor(bp
->b_dev
) >> md
->md_unitshift
];
bp
->av_forw
= dp
->b_actf
;
mi
->mi_wtab
.av_forw
= mi
->mi_wtab
.av_back
= &mi
->mi_wtab
;
* Scan for drives waiting for on line or status responses,
* and for drives with pending transfers. Put these on the
* controller queue, and mark the controller busy.
for (unit
= 0, dp
= md
->md_utab
; unit
< md
->md_nunits
; unit
++, dp
++) {
if (ui
== NULL
|| !ui
->ui_alive
|| ui
->ui_ctlr
!= mi
->mi_ctlr
)
ui
->ui_flags
&= ~(UNIT_HAVESTATUS
| UNIT_ONLINE
);
if ((ui
->ui_flags
& UNIT_REQUEUE
) == 0 && dp
->b_actf
== NULL
)
ui
->ui_flags
&= ~UNIT_REQUEUE
;
APPEND(dp
, mi
->mi_tab
, b_forw
);
mi
->mi_tab
->b_active
= 1;
* ... and clear the index-to-buffer table.
for (unit
= 0; unit
< AEB_MAX_BP
; unit
++)
* Messages for the various subcodes.
static char unknown_msg
[] = "unknown subcode";
* Subcodes for Success (0)
static char *succ_msgs
[] = {
"spin down ignored", /* 1 = Spin-Down Ignored */
"still connected", /* 2 = Still Connected */
"dup. unit #", /* 4 = Duplicate Unit Number */
"already online", /* 8 = Already Online */
"still online", /* 16 = Still Online */
* Subcodes for Invalid Command (1)
static char *icmd_msgs
[] = {
"invalid msg length", /* 0 = Invalid Message Length */
* Subcodes for Command Aborted (2)
* Subcodes for Unit Offline (3)
static char *offl_msgs
[] = {
"unknown drive", /* 0 = Unknown, or online to other ctlr */
"not mounted", /* 1 = Unmounted, or RUN/STOP at STOP */
"inoperative", /* 2 = Unit Inoperative */
"duplicate", /* 4 = Duplicate Unit Number */
"in diagnosis", /* 8 = Disabled by FS or diagnostic */
* Subcodes for Unit Available (4)
* Subcodes for Media Format Error (5)
static char *media_fmt_msgs
[] = {
"fct unread - edc", /* 0 = FCT unreadable */
"invalid sector header",/* 1 = Invalid Sector Header */
"not 512 sectors", /* 2 = Not 512 Byte Sectors */
"not formatted", /* 3 = Not Formatted */
"fct ecc", /* 4 = FCT ECC */
* Subcodes for Write Protected (6)
* N.B.: Code 6 subcodes are 7 bits higher than other subcodes
static char *wrprot_msgs
[] = {
"software", /* 1 = Software Write Protect */
"hardware", /* 2 = Hardware Write Protect */
* Subcodes for Compare Error (7)
* Subcodes for Data Error (8)
static char *data_msgs
[] = {
"forced error", /* 0 = Forced Error (software) */
"header compare", /* 2 = Header Compare Error */
"sync timeout", /* 3 = Sync Timeout Error */
"uncorrectable ecc", /* 7 = Uncorrectable ECC */
"1 symbol ecc", /* 8 = 1 bit ECC */
"2 symbol ecc", /* 9 = 2 bit ECC */
"3 symbol ecc", /* 10 = 3 bit ECC */
"4 symbol ecc", /* 11 = 4 bit ECC */
"5 symbol ecc", /* 12 = 5 bit ECC */
"6 symbol ecc", /* 13 = 6 bit ECC */
"7 symbol ecc", /* 14 = 7 bit ECC */
"8 symbol ecc", /* 15 = 8 bit ECC */
* Subcodes for Host Buffer Access Error (9)
static char *host_buffer_msgs
[] = {
"odd xfer addr", /* 1 = Odd Transfer Address */
"odd xfer count", /* 2 = Odd Transfer Count */
"non-exist. memory", /* 3 = Non-Existent Memory */
"memory parity", /* 4 = Memory Parity Error */
* Subcodes for Controller Error (10)
static char *cntlr_msgs
[] = {
"serdes overrun", /* 1 = Serialiser/Deserialiser Overrun */
"edc", /* 2 = Error Detection Code? */
"inconsistant internal data struct",/* 3 = Internal Error */
* Subcodes for Drive Error (11)
static char *drive_msgs
[] = {
"sdi command timeout", /* 1 = SDI Command Timeout */
"ctlr detected protocol",/* 2 = Controller Detected Protocol Error */
"positioner", /* 3 = Positioner Error */
"lost rd/wr ready", /* 4 = Lost R/W Ready Error */
"drive clock dropout", /* 5 = Lost Drive Clock */
"lost recvr ready", /* 6 = Lost Receiver Ready */
"drive detected error", /* 7 = Drive Error */
"ctlr detected pulse or parity",/* 8 = Pulse or Parity Error */
* The following table correlates message codes with the
#define SC(m) sizeof (m) / sizeof (m[0]), m
"success", SC(succ_msgs
),
"invalid command", SC(icmd_msgs
),
"unit offline", SC(offl_msgs
),
"media format error", SC(media_fmt_msgs
),
"write protected", SC(wrprot_msgs
),
"data error", SC(data_msgs
),
"host buffer access error", SC(host_buffer_msgs
),
"controller error", SC(cntlr_msgs
),
"drive error", SC(drive_msgs
),
* Print the decoded error event from an MSCP error datagram.
register int event
= mp
->mscp_event
;
register struct code_decode
*cdc
;
* The code is the lower six bits of the event number (aka
* status). If that is 6 (write protect), the subcode is in
* bits 12-15; otherwise, it is in bits 5-11.
* I WONDER WHAT THE OTHER BITS ARE FOR. IT SURE WOULD BE
* NICE IF DEC SOLD DOCUMENTATION FOR THEIR OWN CONTROLLERS.
sc
= (c
!= 6 ? event
>> 5 : event
>> 12) & 0x7ff;
if (c
>= sizeof code_decode
/ sizeof code_decode
[0])
cm
= "- unknown code", scm
= "??";
if (sc
>= cdc
->cdc_nsubcodes
)
scm
= cdc
->cdc_submsgs
[sc
];
printf("%s (%s) (code %d, subcode %d)\n", cm
, scm
, c
, sc
);
* Print the code and logical block number for an error packet.
* THIS IS PROBABLY PECULIAR TO DISK DRIVES. IT SURE WOULD BE
* NICE IF DEC SOLD DOCUMENTATION FOR THEIR OWN CONTROLLERS.
mscp_decodeerror(name
, ctlr
, mp
)
register struct mscp
*mp
;
* For bad blocks, mp->mscp_erd.erd_hdr identifies a code and
* the logical block number. Code 0 is a regular block; code 6
* is a replacement block. The remaining codes are currently
* undefined. The code is in the upper four bits of the header
* (bits 0-27 are the lbn).
int issoft
= mp
->mscp_flags
& (M_LF_SUCC
| M_LF_CONT
);
static char *codemsg
[16] = {
"lbn", "code 1", "code 2", "code 3",
"code 4", "code 5", "rbn", "code 7",
"code 8", "code 9", "code 10", "code 11",
"code 12", "code 13", "code 14", "code 15"
#define BADCODE(h) (codemsg[(unsigned)(h) >> 28])
#define BADLBN(h) ((h) & 0xfffffff)
printf("%s%d: %s error datagram%s: ", name
, ctlr
,
issoft
? "soft" : "hard",
mp
->mscp_flags
& M_LF_CONT
? " (continuing)" : "");
switch (mp
->mscp_format
& 0377) {
case M_FM_CTLRERR
: /* controller error */
case M_FM_BUSADDR
: /* host memory access error */
printf("memory addr 0x%x: ", mp
->mscp_erd
.erd_busaddr
);
printf("unit %d: level %d retry %d, %s %d: ",
mp
->mscp_erd
.erd_level
, mp
->mscp_erd
.erd_retry
,
BADCODE(mp
->mscp_erd
.erd_hdr
),
BADLBN(mp
->mscp_erd
.erd_hdr
));
printf("unit %d: %s %d: ", mp
->mscp_unit
,
BADCODE(mp
->mscp_erd
.erd_hdr
),
BADLBN(mp
->mscp_erd
.erd_hdr
));
printf("unit %d: small disk error, cyl %d: ",
mp
->mscp_unit
, mp
->mscp_erd
.erd_sdecyl
);
printf("unit %d: unknown error, format 0x%x: ",
mp
->mscp_unit
, mp
->mscp_format
);