summaryrefslogtreecommitdiffstats
path: root/sys/dev/isci/isci.h
blob: ce0426a158c3f31e59ba0c5b221ca1554ae92321 (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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
/*-
 * BSD LICENSE
 *
 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *   * Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in
 *     the documentation and/or other materials provided with the
 *     distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT
 * OWNER 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.
 *
 * $FreeBSD$
 */

#ifndef _ISCI_H
#define _ISCI_H

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/types.h>
#include <sys/malloc.h>
#include <sys/rman.h>

#include <machine/bus.h>
#include <machine/resource.h>

#include <cam/cam.h>
#include <cam/cam_ccb.h>
#include <cam/cam_sim.h>
#include <cam/cam_xpt_sim.h>

#include <dev/isci/environment.h>
#include <dev/isci/scil/intel_pci.h>

#include <dev/isci/scil/sci_types.h>
#include <dev/isci/scil/sci_object.h>
#include <dev/isci/scil/sci_status.h>
#include <dev/isci/scil/sci_pool.h>
#include <dev/isci/scil/sci_fast_list.h>

#include <dev/isci/scil/sci_controller_constants.h>

#include <dev/isci/scil/scic_controller.h>
#include <dev/isci/scil/scic_config_parameters.h>

#define DEVICE2SOFTC(dev) ((struct isci_softc *) device_get_softc(dev))

#define DEVICE_TIMEOUT 1000
#define SCI_MAX_TIMERS  32

#define ISCI_NUM_PCI_BARS  2
#define ISCI_MAX_LUN		 8

MALLOC_DECLARE(M_ISCI);

struct ISCI_TIMER {
	struct callout		callout;
	SCI_TIMER_CALLBACK_T	callback;
	void			*cookie;
	BOOL			is_started;
};

struct ISCI_REMOTE_DEVICE {
	uint32_t			index;
	struct ISCI_DOMAIN 		*domain;
	SCI_REMOTE_DEVICE_HANDLE_T	sci_object;
	BOOL				is_resetting;
	uint32_t			frozen_lun_mask;
	SCI_FAST_LIST_ELEMENT_T		pending_device_reset_element;

	/*
	 * This queue maintains CCBs that have been returned with
	 *  SCI_IO_FAILURE_INVALID_STATE from the SCI layer.  These CCBs
	 *  need to be retried, but we cannot return CAM_REQUEUE_REQ because
	 *  this status gets passed all the way back up to users of the pass(4)
	 *  interface and breaks things like smartctl.  So instead, we queue
	 *  these CCBs internally.
	 */
	TAILQ_HEAD(,ccb_hdr)		queued_ccbs;

	/*
	 * Marker denoting this remote device needs its first queued ccb to
	 *  be retried.
	 */
	BOOL				release_queued_ccb;

	/*
	 * Points to a CCB in the queue that is currently being processed by
	 *  SCIL.  This allows us to keep in flight CCBs in the queue so as to
	 *  maintain ordering (i.e. in case we retry an I/O and then find out
	 *  it needs to be retried again - it just keeps its same place in the
	 *  queue.
	 */
	union ccb *			queued_ccb_in_progress;
};

struct ISCI_DOMAIN {
	struct ISCI_CONTROLLER		*controller;
	SCI_DOMAIN_HANDLE_T		sci_object;
	uint8_t				index;
	struct ISCI_REMOTE_DEVICE	*da_remote_device;
};

struct ISCI_MEMORY
{
	bus_addr_t	physical_address;
	bus_dma_tag_t	dma_tag;
	bus_dmamap_t	dma_map;
	POINTER_UINT	virtual_address;
	uint32_t	size;
	int		error;
};

struct ISCI_INTERRUPT_INFO
{
	SCIC_CONTROLLER_HANDLER_METHODS_T 	*handlers;
	void					*interrupt_target_handle;
	struct resource				*res;
	int					rid;
	void					*tag;

};

struct ISCI_PHY
{
	struct cdev		*cdev_fault;
	struct cdev		*cdev_locate;
	SCI_CONTROLLER_HANDLE_T	handle;
	int			index;
	int			led_fault;
	int			led_locate;
};

struct ISCI_CONTROLLER
{
	struct isci_softc 	*isci;
	uint8_t			index;
	SCI_CONTROLLER_HANDLE_T	scif_controller_handle;
	struct ISCI_DOMAIN	domain[SCI_MAX_DOMAINS];
	BOOL			is_started;
	BOOL			has_been_scanned;
	uint32_t		initial_discovery_mask;
	BOOL			is_frozen;
	BOOL			release_queued_ccbs;
	BOOL			fail_on_task_timeout;
	uint8_t			*remote_device_memory;
	struct ISCI_MEMORY	cached_controller_memory;
	struct ISCI_MEMORY	uncached_controller_memory;
	struct ISCI_MEMORY	request_memory;
	bus_dma_tag_t		buffer_dma_tag;
	struct mtx		lock;
	struct cam_sim		*sim;
	struct cam_path		*path;
	struct ISCI_REMOTE_DEVICE *remote_device[SCI_MAX_REMOTE_DEVICES];
	void 			*timer_memory;
	SCIC_OEM_PARAMETERS_T	oem_parameters;
	uint32_t		oem_parameters_version;
	uint32_t		queue_depth;
	uint32_t		sim_queue_depth;
	SCI_FAST_LIST_T		pending_device_reset_list;
	struct ISCI_PHY		phys[SCI_MAX_PHYS];

	SCI_MEMORY_DESCRIPTOR_LIST_HANDLE_T mdl;

	SCI_POOL_CREATE(remote_device_pool, struct ISCI_REMOTE_DEVICE *, SCI_MAX_REMOTE_DEVICES);
	SCI_POOL_CREATE(request_pool, struct ISCI_REQUEST *, SCI_MAX_IO_REQUESTS);
	SCI_POOL_CREATE(timer_pool, struct ISCI_TIMER *, SCI_MAX_TIMERS);
	SCI_POOL_CREATE(unmap_buffer_pool, void *, SCI_MAX_REMOTE_DEVICES);
};

struct ISCI_REQUEST
{
	SCI_CONTROLLER_HANDLE_T		controller_handle;
	SCI_REMOTE_DEVICE_HANDLE_T	remote_device_handle;
	bus_dma_tag_t			dma_tag;
	bus_dmamap_t			dma_map;
	SCI_PHYSICAL_ADDRESS		physical_address;
	struct callout			timer;
};

struct ISCI_IO_REQUEST
{
	struct ISCI_REQUEST	parent;
	SCI_IO_REQUEST_HANDLE_T	sci_object;
	union ccb		*ccb;
	uint32_t		num_segments;
	uint32_t		current_sge_index;
	bus_dma_segment_t	*sge;
};

struct ISCI_TASK_REQUEST
{
	struct ISCI_REQUEST		parent;
	struct scsi_sense_data		sense_data;
	SCI_TASK_REQUEST_HANDLE_T	sci_object;
	union ccb			*ccb;

};

struct ISCI_PCI_BAR {

	bus_space_tag_t		bus_tag;
	bus_space_handle_t	bus_handle;
	int			resource_id;
	struct resource		*resource;

};

/*
 * One of these per allocated PCI device.
 */
struct isci_softc {

	struct ISCI_PCI_BAR			pci_bar[ISCI_NUM_PCI_BARS];
	struct ISCI_CONTROLLER			controllers[SCI_MAX_CONTROLLERS];
	SCI_LIBRARY_HANDLE_T			sci_library_handle;
	void *					sci_library_memory;
	SCIC_CONTROLLER_HANDLER_METHODS_T	handlers[4];
	struct ISCI_INTERRUPT_INFO		interrupt_info[4];
	uint32_t				controller_count;
	uint32_t				num_interrupts;
	uint32_t				coalesce_number;
	uint32_t				coalesce_timeout;
	device_t				device;
	SCI_PCI_COMMON_HEADER_T			pci_common_header;
	BOOL					oem_parameters_found;
	struct intr_config_hook			config_hook;
};

int isci_allocate_resources(device_t device);

int isci_allocate_dma_buffer(device_t device, struct ISCI_MEMORY *memory);

void isci_remote_device_reset(struct ISCI_REMOTE_DEVICE *remote_device,
    union ccb *ccb);

/**
 *  Returns the negotiated link rate (in KB/s) for the associated
 *	remote device.  Used to fill out bitrate field for GET_TRANS_SETTINGS.
 *	Will match the negotiated link rate for the lowest numbered local phy
 *	in the port/domain containing this remote device.
 */
uint32_t isci_remote_device_get_bitrate(
    struct ISCI_REMOTE_DEVICE *remote_device);

void isci_remote_device_freeze_lun_queue(
    struct ISCI_REMOTE_DEVICE *remote_device, lun_id_t lun);

void isci_remote_device_release_lun_queue(
    struct ISCI_REMOTE_DEVICE *remote_device, lun_id_t lun);

void isci_remote_device_release_device_queue(
    struct ISCI_REMOTE_DEVICE * remote_device);

void isci_request_construct(struct ISCI_REQUEST *request,
    SCI_CONTROLLER_HANDLE_T scif_controller_handle,
    bus_dma_tag_t io_buffer_dma_tag, bus_addr_t physical_address);

#define isci_io_request_get_max_io_size() \
	((SCI_MAX_SCATTER_GATHER_ELEMENTS - 1) * PAGE_SIZE)

#define isci_task_request_get_object_size() \
	(sizeof(struct ISCI_TASK_REQUEST) + scif_task_request_get_object_size())

#define isci_io_request_get_object_size() \
	(sizeof(struct ISCI_IO_REQUEST) + scif_io_request_get_object_size())

#define isci_request_get_object_size() \
	max( \
	    isci_task_request_get_object_size(), \
	    isci_io_request_get_object_size() \
	)


void isci_io_request_execute_scsi_io(union ccb *ccb,
    struct ISCI_CONTROLLER *controller);

#if __FreeBSD_version >= 900026
void isci_io_request_execute_smp_io(
    union ccb *ccb, struct ISCI_CONTROLLER *controller);
#endif

void isci_io_request_timeout(void *);

void isci_get_oem_parameters(struct isci_softc *isci);

void isci_io_request_complete(
    SCI_CONTROLLER_HANDLE_T scif_controller,
    SCI_REMOTE_DEVICE_HANDLE_T remote_device,
    struct ISCI_IO_REQUEST * isci_request, SCI_IO_STATUS completion_status);

void isci_task_request_complete(
    SCI_CONTROLLER_HANDLE_T scif_controller,
    SCI_REMOTE_DEVICE_HANDLE_T remote_device,
    SCI_TASK_REQUEST_HANDLE_T io_request, SCI_TASK_STATUS completion_status);

void isci_sysctl_initialize(struct isci_softc *isci);

void isci_controller_construct(struct ISCI_CONTROLLER *controller,
    struct isci_softc *isci);

SCI_STATUS isci_controller_initialize(struct ISCI_CONTROLLER *controller);

int isci_controller_allocate_memory(struct ISCI_CONTROLLER *controller);

void isci_controller_domain_discovery_complete(
    struct ISCI_CONTROLLER *isci_controller, struct ISCI_DOMAIN *isci_domain);

int isci_controller_attach_to_cam(struct ISCI_CONTROLLER *controller);

void isci_controller_start(void *controller);

void isci_controller_release_queued_ccbs(struct ISCI_CONTROLLER *controller);

void isci_domain_construct(struct ISCI_DOMAIN *domain, uint32_t domain_index,
    struct ISCI_CONTROLLER *controller);

void isci_interrupt_setup(struct isci_softc *isci);
void isci_interrupt_poll_handler(struct ISCI_CONTROLLER *controller);

void isci_log_message(uint32_t	verbosity, char *log_message_prefix,
    char *log_message, ...);

extern uint32_t g_isci_debug_level;

#endif /* #ifndef _ISCI_H */
OpenPOWER on IntegriCloud