summaryrefslogtreecommitdiffstats
path: root/sys/dev/ispfw/ispfw.c
blob: 633fdf76b8e60ec403236c475b4f8144a644fdc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*-
 * ISP Firmware Helper Pseudo Device for FreeBSD
 *
 * Copyright (c) 2000, 2001, by Matthew Jacob
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice immediately at the beginning of the file, without modification,
 *    this list of conditions, and the following disclaimer.
 * 2. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");

#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/module.h>

#include <dev/ispfw/asm_1040.h>
#include <dev/ispfw/asm_1080.h>
#include <dev/ispfw/asm_12160.h>
#include <dev/ispfw/asm_2100.h>
#include <dev/ispfw/asm_2200.h>
#include <dev/ispfw/asm_2300.h>
#if	_MACHINE_ARCH == sparc64
#include <dev/ispfw/asm_1000.h>
#endif

#define	ISPFW_VERSION	0

#define	PCI_PRODUCT_QLOGIC_ISP1020	0x1020
#define	PCI_PRODUCT_QLOGIC_ISP1080	0x1080
#define	PCI_PRODUCT_QLOGIC_ISP10160	0x1016
#define	PCI_PRODUCT_QLOGIC_ISP12160	0x1216
#define	PCI_PRODUCT_QLOGIC_ISP1240	0x1240
#define	PCI_PRODUCT_QLOGIC_ISP1280	0x1280
#define	PCI_PRODUCT_QLOGIC_ISP2100	0x2100
#define	PCI_PRODUCT_QLOGIC_ISP2200	0x2200
#define	PCI_PRODUCT_QLOGIC_ISP2300	0x2300
#define	PCI_PRODUCT_QLOGIC_ISP2312	0x2312
#if	_MACHINE_ARCH == sparc64
#define	SBUS_PRODUCT_QLOGIC_ISP1000	0x1000
#endif

typedef void ispfwfunc(int, int, int, const u_int16_t **);
extern ispfwfunc *isp_get_firmware_p;
static void isp_get_firmware(int, int, int, const u_int16_t **);

static int ncallers = 0;
static const u_int16_t ***callp = NULL;
static int addcaller(const u_int16_t **);

static int
addcaller(const u_int16_t **caller)
{
	const u_int16_t ***newcallp;
	int i;
	for (i = 0; i < ncallers; i++) {
		if (callp[i] == caller)
			return (1);
	}
	newcallp = malloc((ncallers + 1) * sizeof (const u_int16_t ***),
	    M_DEVBUF, M_NOWAIT);
	if (newcallp == NULL) {
		return (0);
	}
	for (i = 0; i < ncallers; i++) {
		newcallp[i] = callp[i];
	}
	newcallp[ncallers] = caller;
	if (ncallers++)
		free(callp, M_DEVBUF);
	callp = newcallp;
	return (1);
}

static void
isp_get_firmware(int version, int tgtmode, int devid, const u_int16_t **ptrp)
{
	const u_int16_t *rp = NULL;

	if (version == ISPFW_VERSION) {
		switch (devid) {
		case PCI_PRODUCT_QLOGIC_ISP1020:
			if (tgtmode)
				rp = isp_1040_risc_code_it;
			else
				rp = isp_1040_risc_code;
			break;
		case PCI_PRODUCT_QLOGIC_ISP1080:
		case PCI_PRODUCT_QLOGIC_ISP1240:
		case PCI_PRODUCT_QLOGIC_ISP1280:
			if (tgtmode)
				rp = isp_1080_risc_code_it;
			else
				rp = isp_1080_risc_code;
			break;
		case PCI_PRODUCT_QLOGIC_ISP10160:
		case PCI_PRODUCT_QLOGIC_ISP12160:
			if (tgtmode)
				rp = isp_12160_risc_code_it;
			else
				rp = isp_12160_risc_code;
			break;
		case PCI_PRODUCT_QLOGIC_ISP2100:
			rp = isp_2100_risc_code;
			break;
		case PCI_PRODUCT_QLOGIC_ISP2200:
			rp = isp_2200_risc_code;
			break;
		case PCI_PRODUCT_QLOGIC_ISP2300:
		case PCI_PRODUCT_QLOGIC_ISP2312:
			rp = isp_2300_risc_code;
			break;
#if	_MACHINE_ARCH == sparc64
		case SBUS_PRODUCT_QLOGIC_ISP1000:
			if (tgtmode)
				break;
			rp = isp_1000_risc_code;
			break;
#endif
		default:
			break;
		}
	}
	if (rp && addcaller(ptrp)) {
		*ptrp = rp;
	}
}

static int
isp_module_handler(module_t mod, int what, void *arg)
{
	switch (what) {
	case MOD_LOAD:
		isp_get_firmware_p = isp_get_firmware;
		break;
	case MOD_UNLOAD:
		isp_get_firmware_p = NULL;
		if (ncallers)  {
			int i;
			for (i = 0; i < ncallers; i++) {
				*callp[i] = NULL;
			}
			free(callp, M_DEVBUF);
		}
		break;
	default:
		return (EOPNOTSUPP);
		break;
	}
	return (0);
}
static moduledata_t ispfw_mod = {
	"ispfw", isp_module_handler, NULL
};
DECLARE_MODULE(ispfw, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
MODULE_VERSION(ispfw, ISPFW_VERSION);
MODULE_DEPEND(ispfw, isp, 1, 1, 1);
OpenPOWER on IntegriCloud