Deleted Added
full compact
isp_library.c (292715) isp_library.c (292725)
1/*-
2 * Copyright (c) 1997-2009 by Matthew Jacob
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *

--- 21 unchanged lines hidden (view full) ---

30 */
31#ifdef __NetBSD__
32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD$");
34#include <dev/ic/isp_netbsd.h>
35#endif
36#ifdef __FreeBSD__
37#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1997-2009 by Matthew Jacob
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *

--- 21 unchanged lines hidden (view full) ---

30 */
31#ifdef __NetBSD__
32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD$");
34#include <dev/ic/isp_netbsd.h>
35#endif
36#ifdef __FreeBSD__
37#include <sys/cdefs.h>
38__FBSDID("$FreeBSD: head/sys/dev/isp/isp_library.c 292715 2015-12-25 03:44:29Z mav $");
38__FBSDID("$FreeBSD: head/sys/dev/isp/isp_library.c 292725 2015-12-25 13:03:18Z mav $");
39#include <dev/isp/isp_freebsd.h>
40#endif
41#ifdef __OpenBSD__
42#include <dev/ic/isp_openbsd.h>
43#endif
44#ifdef __linux__
45#include "isp_linux.h"
46#endif

--- 195 unchanged lines hidden (view full) ---

242 }
243 if (isp->isp_dblev & ISP_LOGDEBUG1) {
244 isp_print_bytes(isp, "first queue entry", QENTRY_LEN, fqe);
245 }
246 ISP_ADD_REQUEST(isp, nxt);
247 return (CMD_QUEUED);
248}
249
39#include <dev/isp/isp_freebsd.h>
40#endif
41#ifdef __OpenBSD__
42#include <dev/ic/isp_openbsd.h>
43#endif
44#ifdef __linux__
45#include "isp_linux.h"
46#endif

--- 195 unchanged lines hidden (view full) ---

242 }
243 if (isp->isp_dblev & ISP_LOGDEBUG1) {
244 isp_print_bytes(isp, "first queue entry", QENTRY_LEN, fqe);
245 }
246 ISP_ADD_REQUEST(isp, nxt);
247 return (CMD_QUEUED);
248}
249
250int
251isp_allocate_xs(ispsoftc_t *isp, XS_T *xs, uint32_t *handlep)
250uint32_t
251isp_allocate_handle(ispsoftc_t *isp, void *xs, int type)
252{
253 isp_hdl_t *hdp;
254
255 hdp = isp->isp_xffree;
252{
253 isp_hdl_t *hdp;
254
255 hdp = isp->isp_xffree;
256 if (hdp == NULL) {
257 return (-1);
258 }
256 if (hdp == NULL)
257 return (ISP_HANDLE_FREE);
259 isp->isp_xffree = hdp->cmd;
260 hdp->cmd = xs;
261 hdp->handle = (hdp - isp->isp_xflist);
258 isp->isp_xffree = hdp->cmd;
259 hdp->cmd = xs;
260 hdp->handle = (hdp - isp->isp_xflist);
262 hdp->handle |= (ISP_HANDLE_INITIATOR << ISP_HANDLE_USAGE_SHIFT);
261 hdp->handle |= (type << ISP_HANDLE_USAGE_SHIFT);
263 hdp->handle |= (isp->isp_seqno++ << ISP_HANDLE_SEQ_SHIFT);
262 hdp->handle |= (isp->isp_seqno++ << ISP_HANDLE_SEQ_SHIFT);
264 *handlep = hdp->handle;
265 return (0);
263 return (hdp->handle);
266}
267
264}
265
268XS_T *
266void *
269isp_find_xs(ispsoftc_t *isp, uint32_t handle)
270{
267isp_find_xs(ispsoftc_t *isp, uint32_t handle)
268{
271 if (!ISP_VALID_INI_HANDLE(isp, handle)) {
269 if (!ISP_VALID_HANDLE(isp, handle)) {
272 isp_prt(isp, ISP_LOGERR, "%s: bad handle 0x%x", __func__, handle);
273 return (NULL);
274 }
275 return (isp->isp_xflist[(handle & ISP_HANDLE_CMD_MASK)].cmd);
276}
277
278uint32_t
270 isp_prt(isp, ISP_LOGERR, "%s: bad handle 0x%x", __func__, handle);
271 return (NULL);
272 }
273 return (isp->isp_xflist[(handle & ISP_HANDLE_CMD_MASK)].cmd);
274}
275
276uint32_t
279isp_find_handle(ispsoftc_t *isp, XS_T *xs)
277isp_find_handle(ispsoftc_t *isp, void *xs)
280{
281 uint32_t i, foundhdl = ISP_HANDLE_FREE;
282
283 if (xs != NULL) {
284 for (i = 0; i < isp->isp_maxcmds; i++) {
285 if (isp->isp_xflist[i].cmd != xs) {
286 continue;
287 }
288 foundhdl = isp->isp_xflist[i].handle;
289 break;
290 }
291 }
292 return (foundhdl);
293}
294
278{
279 uint32_t i, foundhdl = ISP_HANDLE_FREE;
280
281 if (xs != NULL) {
282 for (i = 0; i < isp->isp_maxcmds; i++) {
283 if (isp->isp_xflist[i].cmd != xs) {
284 continue;
285 }
286 foundhdl = isp->isp_xflist[i].handle;
287 break;
288 }
289 }
290 return (foundhdl);
291}
292
295uint32_t
296isp_handle_index(ispsoftc_t *isp, uint32_t handle)
297{
298 if (!ISP_VALID_HANDLE(isp, handle)) {
299 isp_prt(isp, ISP_LOGERR, "%s: bad handle 0x%x", __func__, handle);
300 return (ISP_BAD_HANDLE_INDEX);
301 } else {
302 return (handle & ISP_HANDLE_CMD_MASK);
303 }
304}
305
306void
307isp_destroy_handle(ispsoftc_t *isp, uint32_t handle)
308{
293void
294isp_destroy_handle(ispsoftc_t *isp, uint32_t handle)
295{
309 if (!ISP_VALID_INI_HANDLE(isp, handle)) {
296 if (!ISP_VALID_HANDLE(isp, handle)) {
310 isp_prt(isp, ISP_LOGERR, "%s: bad handle 0x%x", __func__, handle);
311 } else {
312 isp->isp_xflist[(handle & ISP_HANDLE_CMD_MASK)].handle = ISP_HANDLE_FREE;
313 isp->isp_xflist[(handle & ISP_HANDLE_CMD_MASK)].cmd = isp->isp_xffree;
314 isp->isp_xffree = &isp->isp_xflist[(handle & ISP_HANDLE_CMD_MASK)];
315 }
316}
317

--- 260 unchanged lines hidden (view full) ---

578{
579 uint32_t tmp;
580 isp_hdl_t *hdp;
581#ifdef ISP_TARGET_MODE
582 isp_notify_t notify;
583#endif
584
585 for (tmp = 0; isp->isp_xflist && tmp < isp->isp_maxcmds; tmp++) {
297 isp_prt(isp, ISP_LOGERR, "%s: bad handle 0x%x", __func__, handle);
298 } else {
299 isp->isp_xflist[(handle & ISP_HANDLE_CMD_MASK)].handle = ISP_HANDLE_FREE;
300 isp->isp_xflist[(handle & ISP_HANDLE_CMD_MASK)].cmd = isp->isp_xffree;
301 isp->isp_xffree = &isp->isp_xflist[(handle & ISP_HANDLE_CMD_MASK)];
302 }
303}
304

--- 260 unchanged lines hidden (view full) ---

565{
566 uint32_t tmp;
567 isp_hdl_t *hdp;
568#ifdef ISP_TARGET_MODE
569 isp_notify_t notify;
570#endif
571
572 for (tmp = 0; isp->isp_xflist && tmp < isp->isp_maxcmds; tmp++) {
586 XS_T *xs;
587
588 hdp = &isp->isp_xflist[tmp];
573
574 hdp = &isp->isp_xflist[tmp];
589 if (hdp->handle == ISP_HANDLE_FREE) {
590 continue;
591 }
592 xs = hdp->cmd;
593 if (XS_XFRLEN(xs)) {
594 ISP_DMAFREE(isp, xs, hdp->handle);
595 XS_SET_RESID(xs, XS_XFRLEN(xs));
596 } else {
597 XS_SET_RESID(xs, 0);
598 }
599 hdp->handle = 0;
600 hdp->cmd = NULL;
601 XS_SETERR(xs, HBA_BUSRESET);
602 isp_done(xs);
603 }
575 if (ISP_H2HT(hdp->handle) == ISP_HANDLE_INITIATOR) {
576 XS_T *xs = hdp->cmd;
577 if (XS_XFRLEN(xs)) {
578 ISP_DMAFREE(isp, xs, hdp->handle);
579 XS_SET_RESID(xs, XS_XFRLEN(xs));
580 } else {
581 XS_SET_RESID(xs, 0);
582 }
583 hdp->handle = 0;
584 hdp->cmd = NULL;
585 XS_SETERR(xs, HBA_BUSRESET);
586 isp_done(xs);
604#ifdef ISP_TARGET_MODE
587#ifdef ISP_TARGET_MODE
605 for (tmp = 0; isp->isp_tgtlist && tmp < isp->isp_maxcmds; tmp++) {
606 uint8_t local[QENTRY_LEN];
607 hdp = &isp->isp_tgtlist[tmp];
608 if (hdp->handle == ISP_HANDLE_FREE) {
609 continue;
588 } else if (ISP_H2HT(hdp->handle) == ISP_HANDLE_TARGET) {
589 uint8_t local[QENTRY_LEN];
590 ISP_DMAFREE(isp, hdp->cmd, hdp->handle);
591 ISP_MEMZERO(local, QENTRY_LEN);
592 if (IS_24XX(isp)) {
593 ct7_entry_t *ctio = (ct7_entry_t *) local;
594 ctio->ct_syshandle = hdp->handle;
595 ctio->ct_nphdl = CT_HBA_RESET;
596 ctio->ct_header.rqs_entry_type = RQSTYPE_CTIO7;
597 } else {
598 ct2_entry_t *ctio = (ct2_entry_t *) local;
599 ctio->ct_syshandle = hdp->handle;
600 ctio->ct_status = CT_HBA_RESET;
601 ctio->ct_header.rqs_entry_type = RQSTYPE_CTIO2;
602 }
603 isp_async(isp, ISPASYNC_TARGET_ACTION, local);
604#endif
610 }
605 }
611 ISP_DMAFREE(isp, hdp->cmd, hdp->handle);
612 ISP_MEMZERO(local, QENTRY_LEN);
613 if (IS_24XX(isp)) {
614 ct7_entry_t *ctio = (ct7_entry_t *) local;
615 ctio->ct_syshandle = hdp->handle;
616 ctio->ct_nphdl = CT_HBA_RESET;
617 ctio->ct_header.rqs_entry_type = RQSTYPE_CTIO7;
618 } else {
619 ct2_entry_t *ctio = (ct2_entry_t *) local;
620 ctio->ct_syshandle = hdp->handle;
621 ctio->ct_status = CT_HBA_RESET;
622 ctio->ct_header.rqs_entry_type = RQSTYPE_CTIO2;
623 }
624 isp_async(isp, ISPASYNC_TARGET_ACTION, local);
625 }
606 }
607#ifdef ISP_TARGET_MODE
626 for (tmp = 0; tmp < isp->isp_nchan; tmp++) {
627 ISP_MEMZERO(&notify, sizeof (isp_notify_t));
628 notify.nt_ncode = NT_HBA_RESET;
629 notify.nt_hba = isp;
630 notify.nt_wwn = INI_ANY;
631 notify.nt_nphdl = NIL_HANDLE;
632 notify.nt_sid = PORT_ANY;
633 notify.nt_did = PORT_ANY;

--- 1584 unchanged lines hidden (view full) ---

2218 }
2219 if (isp->isp_dblev & ISP_LOGTDEBUG1) {
2220 isp_print_bytes(isp, "first queue entry", QENTRY_LEN, fqe);
2221 }
2222 ISP_ADD_REQUEST(isp, nxt);
2223 return (CMD_QUEUED);
2224}
2225
608 for (tmp = 0; tmp < isp->isp_nchan; tmp++) {
609 ISP_MEMZERO(&notify, sizeof (isp_notify_t));
610 notify.nt_ncode = NT_HBA_RESET;
611 notify.nt_hba = isp;
612 notify.nt_wwn = INI_ANY;
613 notify.nt_nphdl = NIL_HANDLE;
614 notify.nt_sid = PORT_ANY;
615 notify.nt_did = PORT_ANY;

--- 1584 unchanged lines hidden (view full) ---

2200 }
2201 if (isp->isp_dblev & ISP_LOGTDEBUG1) {
2202 isp_print_bytes(isp, "first queue entry", QENTRY_LEN, fqe);
2203 }
2204 ISP_ADD_REQUEST(isp, nxt);
2205 return (CMD_QUEUED);
2206}
2207
2226int
2227isp_allocate_xs_tgt(ispsoftc_t *isp, void *xs, uint32_t *handlep)
2228{
2229 isp_hdl_t *hdp;
2230
2231 hdp = isp->isp_tgtfree;
2232 if (hdp == NULL) {
2233 return (-1);
2234 }
2235 isp->isp_tgtfree = hdp->cmd;
2236 hdp->cmd = xs;
2237 hdp->handle = (hdp - isp->isp_tgtlist);
2238 hdp->handle |= (ISP_HANDLE_TARGET << ISP_HANDLE_USAGE_SHIFT);
2239 /*
2240 * Target handles for SCSI cards are only 16 bits, so
2241 * sequence number protection will be ommitted.
2242 */
2243 if (IS_FC(isp)) {
2244 hdp->handle |= (isp->isp_seqno++ << ISP_HANDLE_SEQ_SHIFT);
2245 }
2246 *handlep = hdp->handle;
2247 return (0);
2248}
2249
2250void *
2251isp_find_xs_tgt(ispsoftc_t *isp, uint32_t handle)
2252{
2253 if (!ISP_VALID_TGT_HANDLE(isp, handle)) {
2254 isp_prt(isp, ISP_LOGERR, "%s: bad handle 0x%x", __func__, handle);
2255 return (NULL);
2256 }
2257 return (isp->isp_tgtlist[(handle & ISP_HANDLE_CMD_MASK)].cmd);
2258}
2259
2260uint32_t
2261isp_find_tgt_handle(ispsoftc_t *isp, void *xs)
2262{
2263 uint32_t i, foundhdl = ISP_HANDLE_FREE;
2264
2265 if (xs != NULL) {
2266 for (i = 0; i < isp->isp_maxcmds; i++) {
2267 if (isp->isp_tgtlist[i].cmd != xs) {
2268 continue;
2269 }
2270 foundhdl = isp->isp_tgtlist[i].handle;
2271 break;
2272 }
2273 }
2274 return (foundhdl);
2275}
2276
2277void
2278isp_destroy_tgt_handle(ispsoftc_t *isp, uint32_t handle)
2279{
2280 if (!ISP_VALID_TGT_HANDLE(isp, handle)) {
2281 isp_prt(isp, ISP_LOGERR, "%s: bad handle 0x%x", __func__, handle);
2282 } else {
2283 isp->isp_tgtlist[(handle & ISP_HANDLE_CMD_MASK)].handle = ISP_HANDLE_FREE;
2284 isp->isp_tgtlist[(handle & ISP_HANDLE_CMD_MASK)].cmd = isp->isp_tgtfree;
2285 isp->isp_tgtfree = &isp->isp_tgtlist[(handle & ISP_HANDLE_CMD_MASK)];
2286 }
2287}
2288
2289#endif
2290
2291/*
2292 * Find port database entries
2293 */
2294int
2295isp_find_pdb_empty(ispsoftc_t *isp, int chan, fcportdb_t **lptr)
2296{

--- 1295 unchanged lines hidden ---
2208#endif
2209
2210/*
2211 * Find port database entries
2212 */
2213int
2214isp_find_pdb_empty(ispsoftc_t *isp, int chan, fcportdb_t **lptr)
2215{

--- 1295 unchanged lines hidden ---