Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

  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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
/*-
 * Copyright (c) 2018 Microsemi Corporation.
 * 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, this list of conditions and the following disclaimer.
 * 2. 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 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.
 */

/* $FreeBSD$ */

#include"smartpqi_includes.h"

/*
 * Function to rescan the devices connected to adapter.
 */
int
pqisrc_rescan_devices(pqisrc_softstate_t *softs)
{
	int ret;

	DBG_FUNC("IN\n");

	os_sema_lock(&softs->scan_lock);

	ret = pqisrc_scan_devices(softs);

	os_sema_unlock(&softs->scan_lock);

	DBG_FUNC("OUT\n");

	return ret;
}

void pqisrc_wait_for_rescan_complete(pqisrc_softstate_t *softs)
{
	os_sema_lock(&softs->scan_lock);
	os_sema_unlock(&softs->scan_lock);
}

/*
 * Subroutine to acknowledge the events processed by the driver to the adapter.
 */
static void 
pqisrc_acknowledge_event(pqisrc_softstate_t *softs, 
	struct pqi_event *event)
{

	pqi_event_acknowledge_request_t request;
	ib_queue_t *ib_q = &softs->op_raid_ib_q[0];
	int tmo = PQISRC_EVENT_ACK_RESP_TIMEOUT;
	memset(&request,0,sizeof(request));

	DBG_FUNC("IN\n");

	request.header.iu_type = PQI_REQUEST_IU_ACKNOWLEDGE_VENDOR_EVENT;
	request.header.iu_length = (sizeof(pqi_event_acknowledge_request_t) - 
								PQI_REQUEST_HEADER_LENGTH);
	request.event_type = event->event_type;
	request.event_id   = event->event_id;
	request.additional_event_id = event->additional_event_id;

	/* Submit Event Acknowledge */

	pqisrc_submit_cmnd(softs, ib_q, &request);

	/*
	 * We have to special-case this type of request because the firmware
	 * does not generate an interrupt when this type of request completes.
	 * Therefore, we have to poll until we see that the firmware has
	 * consumed the request before we move on.
	 */

	COND_WAIT(((ib_q->pi_local) == *(ib_q->ci_virt_addr)), tmo);
		if (tmo <= 0) {
			DBG_ERR("wait for event acknowledge timed out\n");
			DBG_ERR("tmo : %d\n",tmo);	
 		}		

	DBG_FUNC(" OUT\n");
}

/*
 * Acknowledge processed events to the adapter.
 */
void
pqisrc_ack_all_events(void *arg1)
{
	int i;
	struct pqi_event *pending_event;
	pqisrc_softstate_t *softs = (pqisrc_softstate_t*)arg1;
		
	DBG_FUNC(" IN\n");

	pending_event = &softs->pending_events[0];
	for (i=0; i < PQI_NUM_SUPPORTED_EVENTS; i++) {
		if (pending_event->pending == true) {
			pending_event->pending = false;
			pqisrc_acknowledge_event(softs, pending_event);
		}
		pending_event++;
	}

	/* Rescan devices except for heartbeat event */
	if ((pqisrc_rescan_devices(softs)) != PQI_STATUS_SUCCESS) {
			DBG_ERR(" Failed to Re-Scan devices\n ");
	}
	DBG_FUNC(" OUT\n");

}

/*
 * Get event index from event type to validate the type of event.
 */
static int 
pqisrc_event_type_to_event_index(unsigned event_type)
{
	int index;

	switch (event_type) {
	case PQI_EVENT_TYPE_HOTPLUG:
		index = PQI_EVENT_HOTPLUG;
		break;
	case PQI_EVENT_TYPE_HARDWARE:
		index = PQI_EVENT_HARDWARE;
		break;
	case PQI_EVENT_TYPE_PHYSICAL_DEVICE:
		index = PQI_EVENT_PHYSICAL_DEVICE;
		break;
	case PQI_EVENT_TYPE_LOGICAL_DEVICE:
		index = PQI_EVENT_LOGICAL_DEVICE;
		break;
	case PQI_EVENT_TYPE_AIO_STATE_CHANGE:
		index = PQI_EVENT_AIO_STATE_CHANGE;
		break;
	case PQI_EVENT_TYPE_AIO_CONFIG_CHANGE:
		index = PQI_EVENT_AIO_CONFIG_CHANGE;
		break;
	default:
		index = -1;
		break;
	}

	return index;
}

/*
 * Function used to process the events supported by the adapter.
 */
int 
pqisrc_process_event_intr_src(pqisrc_softstate_t *softs,int obq_id)
{
	uint32_t obq_pi,obq_ci;
	pqi_event_response_t response;
	ob_queue_t *event_q;
	struct pqi_event *pending_event;
	boolean_t  need_delayed_work = false;

	DBG_FUNC(" IN\n");

	OS_ATOMIC64_INC(softs, num_intrs);

	event_q = &softs->event_q;
	obq_ci = event_q->ci_local;
	obq_pi = *(event_q->pi_virt_addr);
	DBG_INFO("Initial Event_q ci : %d Event_q pi : %d\n", obq_ci, obq_pi);

	while(1) {
		int event_index;
		DBG_INFO("queue_id : %d ci : %d pi : %d\n",obq_id, obq_ci, obq_pi);
		if (obq_pi == obq_ci)
			break;

		need_delayed_work = true;

		/* Copy the response */
		memcpy(&response, event_q->array_virt_addr + (obq_ci * event_q->elem_size),
					sizeof(pqi_event_response_t));
		DBG_INFO("response.header.iu_type : 0x%x \n", response.header.iu_type);
		DBG_INFO("response.event_type : 0x%x \n", response.event_type);

		event_index = pqisrc_event_type_to_event_index(response.event_type);

		if (event_index >= 0) {
			if(response.request_acknowledge) {
				pending_event = &softs->pending_events[event_index];
				pending_event->pending = true;
				pending_event->event_type = response.event_type;
				pending_event->event_id = response.event_id;
				pending_event->additional_event_id = response.additional_event_id;
			}
		}
     	
	obq_ci = (obq_ci + 1) % event_q->num_elem;
	}
	/* Update CI */
	event_q->ci_local = obq_ci;
	PCI_MEM_PUT32(softs, event_q->ci_register_abs,
        event_q->ci_register_offset, event_q->ci_local);

	/*Adding events to the task queue for acknowledging*/
	if (need_delayed_work == true) {
		os_eventtaskqueue_enqueue(softs);
	}

	DBG_FUNC("OUT");
	return PQI_STATUS_SUCCESS;

}

/*
 * Function used to send a general management request to adapter.
 */
int pqisrc_submit_management_req(pqisrc_softstate_t *softs, 
                                      pqi_event_config_request_t *request)
{  
	int ret = PQI_STATUS_SUCCESS;
	ib_queue_t *op_ib_q = &softs->op_raid_ib_q[0];
	rcb_t *rcb = NULL;

	DBG_FUNC(" IN\n");

	/* Get the tag */
	request->request_id = pqisrc_get_tag(&softs->taglist);
	if (INVALID_ELEM == request->request_id) {
		DBG_ERR("Tag not available\n");
		ret = PQI_STATUS_FAILURE;
		goto err_out; 
	}

	rcb = &softs->rcb[request->request_id];
	rcb->req_pending = true;
	rcb->tag = request->request_id;
	/* Submit command on operational raid ib queue */
	ret = pqisrc_submit_cmnd(softs, op_ib_q, request);
	if (ret != PQI_STATUS_SUCCESS) {
		DBG_ERR("  Unable to submit command\n");
		goto err_cmd;
	}

	ret = pqisrc_wait_on_condition(softs, rcb);
	if (ret != PQI_STATUS_SUCCESS) {
		DBG_ERR("Management request timed out !!\n");
		goto err_cmd;
	}

	os_reset_rcb(rcb);    
 	pqisrc_put_tag(&softs->taglist,request->request_id);
	DBG_FUNC("OUT\n");
	return ret;

err_cmd:
	os_reset_rcb(rcb); 
	pqisrc_put_tag(&softs->taglist,request->request_id);
err_out:
	DBG_FUNC(" failed OUT : %d\n", ret);
	return ret;
}

/*
 * Build and send the general management request.
 */
static int 
pqi_event_configure(pqisrc_softstate_t *softs , 
                              pqi_event_config_request_t *request, 
                              dma_mem_t *buff)
{
        int ret = PQI_STATUS_SUCCESS;

	DBG_FUNC(" IN\n");

	request->header.comp_feature = 0x00;
	request->header.iu_length = sizeof(pqi_event_config_request_t) - 
		    PQI_REQUEST_HEADER_LENGTH; /* excluding IU header length */
				    
	/*Op OQ id where response to be delivered */
	request->response_queue_id = softs->op_ob_q[0].q_id;
	request->buffer_length 	   = buff->size;
	request->sg_desc.addr 	   = buff->dma_addr;
	request->sg_desc.length    = buff->size;
	request->sg_desc.zero 	   = 0;
	request->sg_desc.type 	   = SGL_DESCRIPTOR_CODE_LAST_ALTERNATIVE_SGL_SEGMENT;
        
	/* submit management req IU*/
	ret = pqisrc_submit_management_req(softs,request);
	if(ret)
		goto err_out;

	DBG_FUNC(" OUT\n");
	return ret;
  
err_out:
	DBG_FUNC("Failed OUT\n");
	return ret;
}

/*
 * Prepare REPORT EVENT CONFIGURATION IU to request that
 * event configuration information be reported.
 */
int pqisrc_report_event_config(pqisrc_softstate_t *softs)
{

	int ret,i ;
	pqi_event_config_request_t request; 
	pqi_event_config_t  *event_config_p ;
	dma_mem_t  buf_report_event ;
	/*bytes to be allocaed for report event config data-in buffer */
	uint32_t alloc_size = sizeof(pqi_event_config_t) ;
	memset(&request, 0 , sizeof(request));

	DBG_FUNC(" IN\n");

	memset(&buf_report_event, 0, sizeof(struct dma_mem)); 
	buf_report_event.tag 	= "pqi_report_event_buf" ;
	buf_report_event.size 	= alloc_size;
	buf_report_event.align 	= PQISRC_DEFAULT_DMA_ALIGN;

	/* allocate memory */
	ret = os_dma_mem_alloc(softs, &buf_report_event);
	if (ret) {
		DBG_ERR("Failed to Allocate report event config buffer : %d\n", ret);
		goto err_out;
	}
	DBG_INFO("buf_report_event.dma_addr	= %p \n",(void*)buf_report_event.dma_addr);
	DBG_INFO("buf_report_event.virt_addr 	= %p \n",(void*)buf_report_event.virt_addr);
  
	request.header.iu_type = PQI_REQUEST_IU_REPORT_VENDOR_EVENT_CONFIG;

	/* Event configuration */
	ret=pqi_event_configure(softs,&request,&buf_report_event);
	if(ret)
		goto free_mem;
    

	event_config_p = (pqi_event_config_t*)buf_report_event.virt_addr;
	softs->event_config.num_event_descriptors = MIN(event_config_p->num_event_descriptors,
		                                            PQI_MAX_EVENT_DESCRIPTORS) ;
							    
        for (i=0; i < softs->event_config.num_event_descriptors ;i++){
		softs->event_config.descriptors[i].event_type = 
					event_config_p->descriptors[i].event_type;
	}
        /* free the allocated memory*/
	os_dma_mem_free(softs, &buf_report_event);
	   
	DBG_FUNC(" OUT\n");
	return ret;

free_mem:
	os_dma_mem_free(softs, &buf_report_event);
err_out:
	DBG_FUNC("Failed OUT\n");
	return PQI_STATUS_FAILURE;
}

/*
 * Prepare SET EVENT CONFIGURATION IU to request that
 * event configuration parameters be set.
 */
int pqisrc_set_event_config(pqisrc_softstate_t *softs)
{

	int ret,i;
	pqi_event_config_request_t request;
	pqi_event_config_t *event_config_p;
	dma_mem_t buf_set_event;
	/*bytes to be allocaed for set event config data-out buffer */
	uint32_t alloc_size = sizeof(pqi_event_config_t);
	memset(&request, 0 , sizeof(request));

	DBG_FUNC(" IN\n");

 	memset(&buf_set_event, 0, sizeof(struct dma_mem));
	buf_set_event.tag 	= "pqi_set_event_buf";
	buf_set_event.size 	= alloc_size;
	buf_set_event.align 	= PQISRC_DEFAULT_DMA_ALIGN;
	  
	/* allocate memory */
	ret = os_dma_mem_alloc(softs, &buf_set_event);
	if (ret) {
		DBG_ERR("Failed to Allocate set event config buffer : %d\n", ret);
		goto err_out;
	}
		 
	DBG_INFO("buf_set_event.dma_addr  	= %p\n",(void*)buf_set_event.dma_addr);
	DBG_INFO("buf_set_event.virt_addr 	= %p\n",(void*)buf_set_event.virt_addr);

	request.header.iu_type = PQI_REQUEST_IU_SET_EVENT_CONFIG;
	request.iu_specific.global_event_oq_id = softs->event_q.q_id; 

	/*pointer to data-out buffer*/

	event_config_p = (pqi_event_config_t *)buf_set_event.virt_addr;

	event_config_p->num_event_descriptors = softs->event_config.num_event_descriptors;

	for (i=0; i < softs->event_config.num_event_descriptors ; i++){
		event_config_p->descriptors[i].event_type = 
					softs->event_config.descriptors[i].event_type;
		if( pqisrc_event_type_to_event_index(event_config_p->descriptors[i].event_type) != -1)
			event_config_p->descriptors[i].oq_id = softs->event_q.q_id;
		else
			event_config_p->descriptors[i].oq_id = 0; /* Not supported this event. */
			
	}
        /* Event configuration */
	ret = pqi_event_configure(softs,&request,&buf_set_event);
		if(ret)
			goto free_mem;
    
	os_dma_mem_free(softs, &buf_set_event);
	   
	DBG_FUNC(" OUT\n");
	return ret;

free_mem:
	os_dma_mem_free(softs, &buf_set_event);
err_out:
	DBG_FUNC("Failed OUT\n");
	return PQI_STATUS_FAILURE;

}