eNB_scheduler_dlsch.c 56.2 KB
Newer Older
1
2
3
4
5
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
Cedric Roux's avatar
Cedric Roux committed
6
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */
nikaeinn's avatar
nikaeinn committed
21
22
23

/*! \file eNB_scheduler_dlsch.c
 * \brief procedures related to eNB for the DLSCH transport channel
24
 * \author  Navid Nikaein and Raymond Knopp
nikaeinn's avatar
nikaeinn committed
25
 * \date 2010 - 2014
26
 * \email: navid.nikaein@eurecom.fr
nikaeinn's avatar
nikaeinn committed
27
 * \version 1.0
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
 * @ingroup _mac

 */

#include "assertions.h"
#include "PHY/defs.h"
#include "PHY/extern.h"

#include "SCHED/defs.h"
#include "SCHED/extern.h"

#include "LAYER2/MAC/defs.h"
#include "LAYER2/MAC/proto.h"
#include "LAYER2/MAC/extern.h"
#include "UTIL/LOG/log.h"
#include "UTIL/LOG/vcd_signal_dumper.h"
#include "UTIL/OPT/opt.h"
#include "OCG.h"
#include "OCG_extern.h"

#include "RRC/LITE/extern.h"
#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h"

//#include "LAYER2/MAC/pre_processor.c"
#include "pdcp.h"

54
#include "SIMULATION/TOOLS/defs.h"	// for taus
55

56
#if defined(ENABLE_ITTI)
57
#include "intertask_interface.h"
58
59
#endif

Cedric Roux's avatar
Cedric Roux committed
60
61
#include "T.h"

62
#define ENABLE_MAC_PAYLOAD_DEBUG
knopp's avatar
   
knopp committed
63
//#define DEBUG_eNB_SCHEDULER 1
64

65
extern RAN_CONTEXT_t RC;
66

67
68
//------------------------------------------------------------------------------
void
69
70
71
add_ue_dlsch_info(module_id_t module_idP,
		  int CC_id,
		  int UE_id, sub_frame_t subframeP, UE_DLSCH_STATUS status)
72
//------------------------------------------------------------------------------
73
{
74

75
76
77
78
79
    eNB_dlsch_info[module_idP][CC_id][UE_id].rnti =
	UE_RNTI(module_idP, UE_id);
    //  eNB_dlsch_info[module_idP][CC_id][ue_mod_idP].weight           = weight;
    eNB_dlsch_info[module_idP][CC_id][UE_id].subframe = subframeP;
    eNB_dlsch_info[module_idP][CC_id][UE_id].status = status;
80

81
    eNB_dlsch_info[module_idP][CC_id][UE_id].serving_num++;
82
83
84

}

85
86
//------------------------------------------------------------------------------
int
87
88
schedule_next_dlue(module_id_t module_idP, int CC_id,
		   sub_frame_t subframeP)
89
//------------------------------------------------------------------------------
90
{
91

92
93
    int next_ue;
    UE_list_t *UE_list = &RC.mac[module_idP]->UE_list;
94

95
96
97
98
99
100
    for (next_ue = UE_list->head; next_ue >= 0;
	 next_ue = UE_list->next[next_ue]) {
	if (eNB_dlsch_info[module_idP][CC_id][next_ue].status ==
	    S_DL_WAITING) {
	    return next_ue;
	}
101
    }
102

103
104
105
106
107
108
109
    for (next_ue = UE_list->head; next_ue >= 0;
	 next_ue = UE_list->next[next_ue]) {
	if (eNB_dlsch_info[module_idP][CC_id][next_ue].status ==
	    S_DL_BUFFERED) {
	    eNB_dlsch_info[module_idP][CC_id][next_ue].status =
		S_DL_WAITING;
	}
110
    }
knopp's avatar
   
knopp committed
111

112
    return (-1);		//next_ue;
113
114
115

}

116
117
//------------------------------------------------------------------------------
unsigned char
118
119
120
121
122
123
124
125
126
generate_dlsch_header(unsigned char *mac_header,
		      unsigned char num_sdus,
		      unsigned short *sdu_lengths,
		      unsigned char *sdu_lcids,
		      unsigned char drx_cmd,
		      unsigned short timing_advance_cmd,
		      unsigned char *ue_cont_res_id,
		      unsigned char short_padding,
		      unsigned short post_padding)
127
//------------------------------------------------------------------------------
128
{
129

130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
    SCH_SUBHEADER_FIXED *mac_header_ptr =
	(SCH_SUBHEADER_FIXED *) mac_header;
    uint8_t first_element = 0, last_size = 0, i;
    uint8_t mac_header_control_elements[16], *ce_ptr;

    ce_ptr = &mac_header_control_elements[0];

    // compute header components

    if ((short_padding == 1) || (short_padding == 2)) {
	mac_header_ptr->R = 0;
	mac_header_ptr->E = 0;
	mac_header_ptr->LCID = SHORT_PADDING;
	first_element = 1;
	last_size = 1;
knopp's avatar
   
knopp committed
145
    }
146

147
148
149
150
151
152
153
154
    if (short_padding == 2) {
	mac_header_ptr->E = 1;
	mac_header_ptr++;
	mac_header_ptr->R = 0;
	mac_header_ptr->E = 0;
	mac_header_ptr->LCID = SHORT_PADDING;
	last_size = 1;
    }
155

156
157
158
159
160
161
162
163
164
165
166
167
    if (drx_cmd != 255) {
	if (first_element > 0) {
	    mac_header_ptr->E = 1;
	    mac_header_ptr++;
	} else {
	    first_element = 1;
	}

	mac_header_ptr->R = 0;
	mac_header_ptr->E = 0;
	mac_header_ptr->LCID = DRX_CMD;
	last_size = 1;
knopp's avatar
   
knopp committed
168
    }
169

170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
    if (timing_advance_cmd != 31) {
	if (first_element > 0) {
	    mac_header_ptr->E = 1;
	    mac_header_ptr++;
	} else {
	    first_element = 1;
	}

	mac_header_ptr->R = 0;
	mac_header_ptr->E = 0;
	mac_header_ptr->LCID = TIMING_ADV_CMD;
	last_size = 1;
	//    msg("last_size %d,mac_header_ptr %p\n",last_size,mac_header_ptr);
	((TIMING_ADVANCE_CMD *) ce_ptr)->R = 0;
	AssertFatal(timing_advance_cmd < 64,
		    "timing_advance_cmd %d > 63\n", timing_advance_cmd);
	((TIMING_ADVANCE_CMD *) ce_ptr)->TA = timing_advance_cmd;	//(timing_advance_cmd+31)&0x3f;
	LOG_D(MAC, "timing advance =%d (%d)\n", timing_advance_cmd,
	      ((TIMING_ADVANCE_CMD *) ce_ptr)->TA);
	ce_ptr += sizeof(TIMING_ADVANCE_CMD);
	//msg("offset %d\n",ce_ptr-mac_header_control_elements);
knopp's avatar
   
knopp committed
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
    if (ue_cont_res_id) {
	if (first_element > 0) {
	    mac_header_ptr->E = 1;
	    /*
	       printf("[eNB][MAC] last subheader : %x (R%d,E%d,LCID%d)\n",*(unsigned char*)mac_header_ptr,
	       ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->R,
	       ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->E,
	       ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->LCID);
	     */
	    mac_header_ptr++;
	} else {
	    first_element = 1;
	}

	mac_header_ptr->R = 0;
	mac_header_ptr->E = 0;
	mac_header_ptr->LCID = UE_CONT_RES;
	last_size = 1;

	LOG_T(MAC,
	      "[eNB ][RAPROC] Generate contention resolution msg: %x.%x.%x.%x.%x.%x\n",
	      ue_cont_res_id[0], ue_cont_res_id[1], ue_cont_res_id[2],
	      ue_cont_res_id[3], ue_cont_res_id[4], ue_cont_res_id[5]);

	memcpy(ce_ptr, ue_cont_res_id, 6);
	ce_ptr += 6;
	// msg("(cont_res) : offset %d\n",ce_ptr-mac_header_control_elements);
knopp's avatar
   
knopp committed
220
    }
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
    //msg("last_size %d,mac_header_ptr %p\n",last_size,mac_header_ptr);

    for (i = 0; i < num_sdus; i++) {
	LOG_T(MAC, "[eNB] Generate DLSCH header num sdu %d len sdu %d\n",
	      num_sdus, sdu_lengths[i]);

	if (first_element > 0) {
	    mac_header_ptr->E = 1;
	    /*msg("last subheader : %x (R%d,E%d,LCID%d)\n",*(unsigned char*)mac_header_ptr,
	       ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->R,
	       ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->E,
	       ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->LCID);
	     */
	    mac_header_ptr += last_size;
	    //msg("last_size %d,mac_header_ptr %p\n",last_size,mac_header_ptr);
	} else {
	    first_element = 1;
	}
239

240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
	if (sdu_lengths[i] < 128) {
	    ((SCH_SUBHEADER_SHORT *) mac_header_ptr)->R = 0;
	    ((SCH_SUBHEADER_SHORT *) mac_header_ptr)->E = 0;
	    ((SCH_SUBHEADER_SHORT *) mac_header_ptr)->F = 0;
	    ((SCH_SUBHEADER_SHORT *) mac_header_ptr)->LCID = sdu_lcids[i];
	    ((SCH_SUBHEADER_SHORT *) mac_header_ptr)->L =
		(unsigned char) sdu_lengths[i];
	    last_size = 2;
	} else {
	    ((SCH_SUBHEADER_LONG *) mac_header_ptr)->R = 0;
	    ((SCH_SUBHEADER_LONG *) mac_header_ptr)->E = 0;
	    ((SCH_SUBHEADER_LONG *) mac_header_ptr)->F = 1;
	    ((SCH_SUBHEADER_LONG *) mac_header_ptr)->LCID = sdu_lcids[i];
	    ((SCH_SUBHEADER_LONG *) mac_header_ptr)->L_MSB =
		((unsigned short) sdu_lengths[i] >> 8) & 0x7f;
	    ((SCH_SUBHEADER_LONG *) mac_header_ptr)->L_LSB =
		(unsigned short) sdu_lengths[i] & 0xff;
	    ((SCH_SUBHEADER_LONG *) mac_header_ptr)->padding = 0x00;
	    last_size = 3;
259
#ifdef DEBUG_HEADER_PARSING
260
261
262
263
264
	    LOG_D(MAC,
		  "[eNB] generate long sdu, size %x (MSB %x, LSB %x)\n",
		  sdu_lengths[i],
		  ((SCH_SUBHEADER_LONG *) mac_header_ptr)->L_MSB,
		  ((SCH_SUBHEADER_LONG *) mac_header_ptr)->L_LSB);
265
#endif
266
	}
knopp's avatar
   
knopp committed
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
    /*

       printf("last_size %d,mac_header_ptr %p\n",last_size,mac_header_ptr);

       printf("last subheader : %x (R%d,E%d,LCID%d)\n",*(unsigned char*)mac_header_ptr,
       ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->R,
       ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->E,
       ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->LCID);


       if (((SCH_SUBHEADER_FIXED*)mac_header_ptr)->LCID < UE_CONT_RES) {
       if (((SCH_SUBHEADER_SHORT*)mac_header_ptr)->F == 0)
       printf("F = 0, sdu len (L field) %d\n",(((SCH_SUBHEADER_SHORT*)mac_header_ptr)->L));
       else
       printf("F = 1, sdu len (L field) %d\n",(((SCH_SUBHEADER_LONG*)mac_header_ptr)->L));
       }
     */
    if (post_padding > 0) {	// we have lots of padding at the end of the packet
	mac_header_ptr->E = 1;
	mac_header_ptr += last_size;
	// add a padding element
	mac_header_ptr->R = 0;
	mac_header_ptr->E = 0;
	mac_header_ptr->LCID = SHORT_PADDING;
	mac_header_ptr++;
    } else {			// no end of packet padding
	// last SDU subhead is of fixed type (sdu length implicitly to be computed at UE)
	mac_header_ptr++;
    }
298

299
    //msg("After subheaders %d\n",(uint8_t*)mac_header_ptr - mac_header);
300

301
302
303
304
305
306
    if ((ce_ptr - mac_header_control_elements) > 0) {
	// printf("Copying %d bytes for control elements\n",ce_ptr-mac_header_control_elements);
	memcpy((void *) mac_header_ptr, mac_header_control_elements,
	       ce_ptr - mac_header_control_elements);
	mac_header_ptr +=
	    (unsigned char) (ce_ptr - mac_header_control_elements);
307
    }
308
309
310
    //msg("After CEs %d\n",(uint8_t*)mac_header_ptr - mac_header);

    return ((unsigned char *) mac_header_ptr - mac_header);
311
312
313

}

314
315
//------------------------------------------------------------------------------
void
316
317
set_ul_DAI(int module_idP, int UE_idP, int CC_idP, int frameP,
	   int subframeP)
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
    eNB_MAC_INST *eNB = RC.mac[module_idP];
    UE_list_t *UE_list = &eNB->UE_list;
    unsigned char DAI;
    COMMON_channels_t *cc = &eNB->common_channels[CC_idP];
    if (cc->tdd_Config != NULL) {	//TDD
	DAI = (UE_list->UE_template[CC_idP][UE_idP].DAI - 1) & 3;
	LOG_D(MAC,
	      "[eNB %d] CC_id %d Frame %d, subframe %d: DAI %d for UE %d\n",
	      module_idP, CC_idP, frameP, subframeP, DAI, UE_idP);
	// Save DAI for Format 0 DCI

	switch (cc->tdd_Config->subframeAssignment) {
	case 0:
	    //      if ((subframeP==0)||(subframeP==1)||(subframeP==5)||(subframeP==6))
	    break;

	case 1:
	    switch (subframeP) {
	    case 1:
		UE_list->UE_template[CC_idP][UE_idP].DAI_ul[7] = DAI;
		break;

	    case 4:
		UE_list->UE_template[CC_idP][UE_idP].DAI_ul[8] = DAI;
		break;

	    case 6:
		UE_list->UE_template[CC_idP][UE_idP].DAI_ul[2] = DAI;
		break;

	    case 9:
		UE_list->UE_template[CC_idP][UE_idP].DAI_ul[3] = DAI;
		break;
	    }
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
	case 2:
	    //      if ((subframeP==3)||(subframeP==8))
	    //  UE_list->UE_template[CC_idP][UE_idP].DAI_ul = DAI;
	    break;

	case 3:

	    //if ((subframeP==6)||(subframeP==8)||(subframeP==0)) {
	    //  LOG_D(MAC,"schedule_ue_spec: setting UL DAI to %d for subframeP %d => %d\n",DAI,subframeP, ((subframeP+8)%10)>>1);
	    //  UE_list->UE_template[CC_idP][UE_idP].DAI_ul[((subframeP+8)%10)>>1] = DAI;
	    //}
	    switch (subframeP) {
	    case 5:
	    case 6:
	    case 1:
		UE_list->UE_template[CC_idP][UE_idP].DAI_ul[2] = DAI;
		break;

	    case 7:
	    case 8:
		UE_list->UE_template[CC_idP][UE_idP].DAI_ul[3] = DAI;
		break;

	    case 9:
	    case 0:
		UE_list->UE_template[CC_idP][UE_idP].DAI_ul[4] = DAI;
		break;

	    default:
		break;
	    }
387

388
	    break;
389

390
391
392
393
	case 4:
	    //      if ((subframeP==8)||(subframeP==9))
	    //  UE_list->UE_template[CC_idP][UE_idP].DAI_ul = DAI;
	    break;
394

395
396
397
398
	case 5:
	    //      if (subframeP==8)
	    //  UE_list->UE_template[CC_idP][UE_idP].DAI_ul = DAI;
	    break;
399

400
401
402
403
	case 6:
	    //      if ((subframeP==1)||(subframeP==4)||(subframeP==6)||(subframeP==9))
	    //  UE_list->UE_template[CC_idP][UE_idP].DAI_ul = DAI;
	    break;
404

405
406
407
	default:
	    break;
	}
knopp's avatar
   
knopp committed
408
409
410
    }
}

411

412
413
// changes to pre-processor for eMTC

414
415
//------------------------------------------------------------------------------
void
416
417
schedule_ue_spec(module_id_t module_idP,
		 frame_t frameP, sub_frame_t subframeP, int *mbsfn_flag)
418
//------------------------------------------------------------------------------
419
{
knopp's avatar
   
knopp committed
420

421

422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
    uint8_t CC_id;
    int UE_id;
    unsigned char aggregation;
    mac_rlc_status_resp_t rlc_status;
    unsigned char header_len_dcch = 0, header_len_dcch_tmp = 0;
    unsigned char header_len_dtch = 0, header_len_dtch_tmp =
	0, header_len_dtch_last = 0;
    unsigned char ta_len = 0;
    unsigned char sdu_lcids[NB_RB_MAX], lcid, offset, num_sdus = 0;
    uint16_t nb_rb, nb_rb_temp, nb_available_rb;
    uint16_t TBS, j, sdu_lengths[NB_RB_MAX], rnti, padding =
	0, post_padding = 0;
    unsigned char dlsch_buffer[MAX_DLSCH_PAYLOAD_BYTES];
    unsigned char round = 0;
    unsigned char harq_pid = 0;
    eNB_UE_STATS *eNB_UE_stats = NULL;
    uint16_t sdu_length_total = 0;

    eNB_MAC_INST *eNB = RC.mac[module_idP];
    COMMON_channels_t *cc = eNB->common_channels;
    UE_list_t *UE_list = &eNB->UE_list;
    int continue_flag = 0;
    int32_t normalized_rx_power, target_rx_power;
    int32_t tpc = 1;
    static int32_t tpc_accumulated = 0;
    UE_sched_ctrl *ue_sched_ctl;
    int mcs;
    int i;
    int min_rb_unit[MAX_NUM_CCs];
    int N_RB_DL[MAX_NUM_CCs];
    int total_nb_available_rb[MAX_NUM_CCs];
    int N_RBG[MAX_NUM_CCs];
    nfapi_dl_config_request_body_t *dl_req;
    nfapi_dl_config_request_pdu_t *dl_config_pdu;
    int tdd_sfa;
    int ta_update;
nikaeinn's avatar
nikaeinn committed
458

459
#if 0
460
461
462
    if (UE_list->head == -1) {
	return;
    }
463
#endif
464

465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
    start_meas(&eNB->schedule_dlsch);
    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME
	(VCD_SIGNAL_DUMPER_FUNCTIONS_SCHEDULE_DLSCH, VCD_FUNCTION_IN);


    // for TDD: check that we have to act here, otherwise return
    if (cc[0].tdd_Config) {
	tdd_sfa = cc[0].tdd_Config->subframeAssignment;
	switch (subframeP) {
	case 0:
	    // always continue
	    break;
	case 1:
	    return;
	    break;
	case 2:
	    return;
	    break;
	case 3:
	    if ((tdd_sfa != 2) && (tdd_sfa != 5))
		return;
	    break;
	case 4:
	    if ((tdd_sfa != 1) && (tdd_sfa != 2) && (tdd_sfa != 4)
		&& (tdd_sfa != 5))
		return;
	    break;
	case 5:
	    break;
	case 6:
	case 7:
	    if ((tdd_sfa != 1) && (tdd_sfa != 2) && (tdd_sfa != 4)
		&& (tdd_sfa != 5))
		return;
	    break;
	case 8:
	    if ((tdd_sfa != 2) && (tdd_sfa != 3) && (tdd_sfa != 4)
		&& (tdd_sfa != 5))
		return;
	    break;
	case 9:
	    if ((tdd_sfa != 1) && (tdd_sfa != 3) && (tdd_sfa != 4)
		&& (tdd_sfa != 6))
		return;
	    break;
510

Xu Bo's avatar
Xu Bo committed
511
	  }
512
    }
Cedric Roux's avatar
Cedric Roux committed
513

514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
    //weight = get_ue_weight(module_idP,UE_id);
    aggregation = 2;
    for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
	N_RB_DL[CC_id] = to_prb(cc[CC_id].mib->message.dl_Bandwidth);
	min_rb_unit[CC_id] = get_min_rb_unit(module_idP, CC_id);
	// get number of PRBs less those used by common channels
	total_nb_available_rb[CC_id] = N_RB_DL[CC_id];
	for (i = 0; i < N_RB_DL[CC_id]; i++)
	    if (cc[CC_id].vrb_map[i] != 0)
		total_nb_available_rb[CC_id]--;

	N_RBG[CC_id] = to_rbg(cc[CC_id].mib->message.dl_Bandwidth);

	// store the global enb stats:
	eNB->eNB_stats[CC_id].num_dlactive_UEs = UE_list->num_UEs;
	eNB->eNB_stats[CC_id].available_prbs =
	    total_nb_available_rb[CC_id];
	eNB->eNB_stats[CC_id].total_available_prbs +=
	    total_nb_available_rb[CC_id];
	eNB->eNB_stats[CC_id].dlsch_bytes_tx = 0;
	eNB->eNB_stats[CC_id].dlsch_pdus_tx = 0;
535
    }
536

537
  /// CALLING Pre_Processor for downlink scheduling (Returns estimation of RBs required by each UE and the allocation on sub-band)
538

gauthier's avatar
gauthier committed
539
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_DLSCH_PREPROCESSOR,VCD_FUNCTION_IN);
knopp's avatar
   
knopp committed
540
  start_meas(&eNB->schedule_dlsch_preprocessor);
541
  dlsch_scheduler_pre_processor(module_idP,
542
543
544
                                frameP,
                                subframeP,
                                N_RBG,
Xu Bo's avatar
Xu Bo committed
545
                                mbsfn_flag);
knopp's avatar
   
knopp committed
546
  stop_meas(&eNB->schedule_dlsch_preprocessor);
gauthier's avatar
gauthier committed
547
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_DLSCH_PREPROCESSOR,VCD_FUNCTION_OUT);
knopp's avatar
   
knopp committed
548

549
  for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
550
    LOG_D(MAC, "doing schedule_ue_spec for CC_id %d\n",CC_id);
551

552
553
    dl_req        = &eNB->DL_req[CC_id].dl_config_request_body;

knopp's avatar
   
knopp committed
554
555
    if (mbsfn_flag[CC_id]>0)
      continue;
556

Xu Bo's avatar
Xu Bo committed
557
558
#ifdef UE_EXPANSION
    for (i = 0; i < dlsch_ue_select[CC_id].ue_num; i++) {
Xu Bo's avatar
Xu Bo committed
559
560
561
562
563
564
      if(dlsch_ue_select[CC_id].list[i].ue_priority == SCH_DL_MSG2){
        continue;
      }
      if(dlsch_ue_select[CC_id].list[i].ue_priority == SCH_DL_MSG4){
        continue;
      }
Xu Bo's avatar
Xu Bo committed
565
      UE_id = dlsch_ue_select[CC_id].list[i].UE_id;
Xu Bo's avatar
Xu Bo committed
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
      rnti = UE_RNTI(module_idP,UE_id);
      if (rnti==NOT_A_RNTI) {
        LOG_E(MAC,"Cannot find rnti for UE_id %d (num_UEs %d)\n",UE_id,UE_list->num_UEs);
        continue;
      }

      eNB_UE_stats = &UE_list->eNB_UE_stats[CC_id][UE_id];
      ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];

      switch(get_tmode(module_idP,CC_id,UE_id)){
      case 1:
      case 2:
      case 7:
        aggregation = get_aggregation(get_bw_index(module_idP,CC_id),
                                      ue_sched_ctl->dl_cqi[CC_id],
                                      format1);
        break;
      case 3:
        aggregation = get_aggregation(get_bw_index(module_idP,CC_id),
                                      ue_sched_ctl->dl_cqi[CC_id],
                                      format2A);
        break;
      default:
        LOG_W(MAC,"Unsupported transmission mode %d\n", get_tmode(module_idP,CC_id,UE_id));
        aggregation = 2;
        break;
      }
Xu Bo's avatar
Xu Bo committed
593

Xu Bo's avatar
Xu Bo committed
594
595
596
597
598
599
600
601
602
      if (cc[CC_id].tdd_Config != NULL) { //TDD
        set_ue_dai (subframeP,
                    UE_id,
                    CC_id,
  		    cc[CC_id].tdd_Config->subframeAssignment,
                    UE_list);
        // update UL DAI after DLSCH scheduling
        set_ul_DAI(module_idP,UE_id,CC_id,frameP,subframeP);
      }
Xu Bo's avatar
Xu Bo committed
603
#else
604
    for (UE_id=UE_list->head; UE_id>=0; UE_id=UE_list->next[UE_id]) {
Xu Bo's avatar
Xu Bo committed
605

606
      continue_flag=0; // reset the flag to allow allocation for the remaining UEs
knopp's avatar
   
knopp committed
607
      rnti = UE_RNTI(module_idP,UE_id);
608
      eNB_UE_stats = &UE_list->eNB_UE_stats[CC_id][UE_id];
609
      ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
610

611

612
      if (rnti==NOT_A_RNTI) {
613
614
        LOG_D(MAC,"Cannot find rnti for UE_id %d (num_UEs %d)\n",UE_id,UE_list->num_UEs);
        continue_flag=1;
615
      }
616

617
      if (eNB_UE_stats==NULL) {
618
619
        LOG_D(MAC,"[eNB] Cannot find eNB_UE_stats\n");
        continue_flag=1;
620
      }
621
622

      if (continue_flag != 1){
623
        switch(get_tmode(module_idP,CC_id,UE_id)){
624
625
626
        case 1:
        case 2:
        case 7:
Xu Bo's avatar
Xu Bo committed
627
			  aggregation = get_aggregation(get_bw_index(module_idP,CC_id), 
Cedric Roux's avatar
Cedric Roux committed
628
					ue_sched_ctl->dl_cqi[CC_id],
629
					format1);
630
631
632
633
		    break;
		case 3:
		    aggregation =
			get_aggregation(get_bw_index(module_idP, CC_id),
Cedric Roux's avatar
Cedric Roux committed
634
					ue_sched_ctl->dl_cqi[CC_id],
635
					format2A);
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
		    break;
		default:
		    LOG_W(MAC, "Unsupported transmission mode %d\n",
			  get_tmode(module_idP, CC_id, UE_id));
		    aggregation = 2;
		}
	    }
	    /* if (continue_flag != 1 */
	    if ((ue_sched_ctl->pre_nb_available_rbs[CC_id] == 0) ||	// no RBs allocated 
		CCE_allocation_infeasible(module_idP, CC_id, 1, subframeP,
					  aggregation, rnti)) {
		LOG_D(MAC,
		      "[eNB %d] Frame %d : no RB allocated for UE %d on CC_id %d: continue \n",
		      module_idP, frameP, UE_id, CC_id);
		continue_flag = 1;	//to next user (there might be rbs availiable for other UEs in TM5
	    }
knopp's avatar
   
knopp committed
652

653
654
655
656
657
658
659
660
661
	    if (cc[CC_id].tdd_Config != NULL) {	//TDD
		set_ue_dai(subframeP,
			   UE_id,
			   CC_id,
			   cc[CC_id].tdd_Config->subframeAssignment,
			   UE_list);
		// update UL DAI after DLSCH scheduling
		set_ul_DAI(module_idP, UE_id, CC_id, frameP, subframeP);
	    }
662

663
664
665
666
667
	    if (continue_flag == 1) {
		add_ue_dlsch_info(module_idP,
				  CC_id, UE_id, subframeP, S_DL_NONE);
		continue;
	    }
Xu Bo's avatar
Xu Bo committed
668
#endif
669
670
#warning RK->CR This old API call has to be revisited for FAPI, or logic must be changed
#if 0
671
672
673
674
675
	    /* add "fake" DCI to have CCE_allocation_infeasible work properly for next allocations */
	    /* if we don't add it, next allocations may succeed but overall allocations may fail */
	    /* will be removed at the end of this function */
	    add_ue_spec_dci(&eNB->common_channels[CC_id].DCI_pdu, &(char[]) {
			    0}, rnti, 1, aggregation, 1, format1, 0);
676
#endif
Cedric Roux's avatar
Cedric Roux committed
677

678
	    nb_available_rb = ue_sched_ctl->pre_nb_available_rbs[CC_id];
679

680
681
682
683
	    if (cc->tdd_Config)
		harq_pid = ((frameP * 10) + subframeP) % 10;
	    else
		harq_pid = ((frameP * 10) + subframeP) & 7;
684

685
	    round = ue_sched_ctl->round[CC_id][harq_pid];
686

687
688
689
690
691
	    UE_list->eNB_UE_stats[CC_id][UE_id].crnti = rnti;
	    UE_list->eNB_UE_stats[CC_id][UE_id].rrc_status =
		mac_eNB_get_rrc_status(module_idP, rnti);
	    UE_list->eNB_UE_stats[CC_id][UE_id].harq_pid = harq_pid;
	    UE_list->eNB_UE_stats[CC_id][UE_id].harq_round = round;
692
693


694
695
696
	    if (UE_list->eNB_UE_stats[CC_id][UE_id].rrc_status <
		RRC_CONNECTED)
		continue;
697

698
699
	    sdu_length_total = 0;
	    num_sdus = 0;
700

701
702
703
704
705
706
707
	    /*
	       DevCheck(((eNB_UE_stats->dl_cqi < MIN_CQI_VALUE) || (eNB_UE_stats->dl_cqi > MAX_CQI_VALUE)),
	       eNB_UE_stats->dl_cqi, MIN_CQI_VALUE, MAX_CQI_VALUE);
	     */
	    eNB_UE_stats->dlsch_mcs1 =
		cqi_to_mcs[ue_sched_ctl->dl_cqi[CC_id]];
	    eNB_UE_stats->dlsch_mcs1 = eNB_UE_stats->dlsch_mcs1;	//cmin(eNB_UE_stats->dlsch_mcs1, openair_daq_vars.target_ue_dl_mcs);
708
709


710
711
	    // store stats
	    //UE_list->eNB_UE_stats[CC_id][UE_id].dl_cqi= eNB_UE_stats->dl_cqi;
712

713
714
715
716
717
	    // initializing the rb allocation indicator for each UE
	    for (j = 0; j < N_RBG[CC_id]; j++) {
		UE_list->
		    UE_template[CC_id][UE_id].rballoc_subband[harq_pid][j]
		    = 0;
718
	    }
Cedric Roux's avatar
Cedric Roux committed
719

720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
	    LOG_D(MAC,
		  "[eNB %d] Frame %d: Scheduling UE %d on CC_id %d (rnti %x, harq_pid %d, round %d, rb %d, cqi %d, mcs %d, rrc %d)\n",
		  module_idP, frameP, UE_id, CC_id, rnti, harq_pid, round,
		  nb_available_rb, ue_sched_ctl->dl_cqi[CC_id],
		  eNB_UE_stats->dlsch_mcs1,
		  UE_list->eNB_UE_stats[CC_id][UE_id].rrc_status);



	    /* process retransmission  */

	    if (round != 8) {

		// get freq_allocation
		nb_rb = UE_list->UE_template[CC_id][UE_id].nb_rb[harq_pid];
		TBS =
		    get_TBS_DL(UE_list->
			       UE_template[CC_id][UE_id].oldmcs1[harq_pid],
			       nb_rb);

		if (nb_rb <= nb_available_rb) {
		    if (cc[CC_id].tdd_Config != NULL) {
			UE_list->UE_template[CC_id][UE_id].DAI++;
			update_ul_dci(module_idP, CC_id, rnti,
				      UE_list->UE_template[CC_id][UE_id].
				      DAI);
			LOG_D(MAC,
			      "DAI update: CC_id %d subframeP %d: UE %d, DAI %d\n",
			      CC_id, subframeP, UE_id,
			      UE_list->UE_template[CC_id][UE_id].DAI);
		    }

		    if (nb_rb == ue_sched_ctl->pre_nb_available_rbs[CC_id]) {
			for (j = 0; j < N_RBG[CC_id]; j++) {	// for indicating the rballoc for each sub-band
			    UE_list->UE_template[CC_id][UE_id].
				rballoc_subband[harq_pid][j] =
				ue_sched_ctl->rballoc_sub_UE[CC_id][j];
			}
		    } else {
			nb_rb_temp = nb_rb;
			j = 0;

			while ((nb_rb_temp > 0) && (j < N_RBG[CC_id])) {
			    if (ue_sched_ctl->rballoc_sub_UE[CC_id][j] ==
				1) {
				if (UE_list->
				    UE_template[CC_id]
				    [UE_id].rballoc_subband[harq_pid][j])
				    printf
					("WARN: rballoc_subband not free for retrans?\n");
				UE_list->
				    UE_template[CC_id]
				    [UE_id].rballoc_subband[harq_pid][j] =
				    ue_sched_ctl->rballoc_sub_UE[CC_id][j];

				if ((j == N_RBG[CC_id] - 1) &&
				    ((N_RB_DL[CC_id] == 25) ||
				     (N_RB_DL[CC_id] == 50))) {
				    nb_rb_temp =
					nb_rb_temp - min_rb_unit[CC_id] +
					1;
				} else {
				    nb_rb_temp =
					nb_rb_temp - min_rb_unit[CC_id];
				}
			    }

			    j = j + 1;
			}
		    }

		    nb_available_rb -= nb_rb;
		    /*
		       eNB->mu_mimo_mode[UE_id].pre_nb_available_rbs = nb_rb;
		       eNB->mu_mimo_mode[UE_id].dl_pow_off = ue_sched_ctl->dl_pow_off[CC_id];

		       for(j=0; j<N_RBG[CC_id]; j++) {
		       eNB->mu_mimo_mode[UE_id].rballoc_sub[j] = UE_list->UE_template[CC_id][UE_id].rballoc_subband[harq_pid][j];
		       }
		     */

		    switch (get_tmode(module_idP, CC_id, UE_id)) {
		    case 1:
		    case 2:
		    case 7:
		    default:
			dl_config_pdu =
			    &dl_req->dl_config_pdu_list[dl_req->
							number_pdu];
			memset((void *) dl_config_pdu, 0,
			       sizeof(nfapi_dl_config_request_pdu_t));
			dl_config_pdu->pdu_type =
			    NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE;
			dl_config_pdu->pdu_size =
			    (uint8_t) (2 +
				       sizeof(nfapi_dl_config_dci_dl_pdu));
			dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.
			    dci_format = NFAPI_DL_DCI_FORMAT_1;
			dl_config_pdu->dci_dl_pdu.
			    dci_dl_pdu_rel8.aggregation_level =
			    get_aggregation(get_bw_index
					    (module_idP, CC_id),
					    ue_sched_ctl->dl_cqi[CC_id],
					    format1);
			dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti =
			    rnti;
			dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type = 1;	// CRNTI : see Table 4-10 from SCF082 - nFAPI specifications
			dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.transmission_power = 6000;	// equal to RS power

			dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.
			    harq_process = harq_pid;
			dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.tpc = 1;	// dont adjust power when retransmitting
			dl_config_pdu->dci_dl_pdu.
			    dci_dl_pdu_rel8.new_data_indicator_1 =
			    UE_list->UE_template[CC_id][UE_id].
			    oldNDI[harq_pid];
			dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1 =
			    UE_list->UE_template[CC_id][UE_id].
			    oldmcs1[harq_pid];
			dl_config_pdu->dci_dl_pdu.
			    dci_dl_pdu_rel8.redundancy_version_1 =
			    round & 3;

			if (cc[CC_id].tdd_Config != NULL) {	//TDD
			    dl_config_pdu->dci_dl_pdu.
				dci_dl_pdu_rel8.downlink_assignment_index =
				(UE_list->UE_template[CC_id][UE_id].DAI -
				 1) & 3;
			    LOG_D(MAC,
				  "[eNB %d] Retransmission CC_id %d : harq_pid %d, round %d, dai %d, mcs %d\n",
				  module_idP, CC_id, harq_pid, round,
				  (UE_list->UE_template[CC_id][UE_id].DAI -
				   1),
				  UE_list->
				  UE_template[CC_id][UE_id].oldmcs1
				  [harq_pid]);
			} else {
			    LOG_D(MAC,
				  "[eNB %d] Retransmission CC_id %d : harq_pid %d, round %d, mcs %d\n",
				  module_idP, CC_id, harq_pid, round,
				  UE_list->
				  UE_template[CC_id][UE_id].oldmcs1
				  [harq_pid]);

			}
			if (!CCE_allocation_infeasible
			    (module_idP, CC_id, 1, subframeP,
			     dl_config_pdu->dci_dl_pdu.
			     dci_dl_pdu_rel8.aggregation_level, rnti)) {
			    dl_req->number_dci++;
			    dl_req->number_pdu++;

			    fill_nfapi_dlsch_config(eNB, dl_req, TBS, -1
						    /* retransmission, no pdu_index */
						    , rnti, 0,	// type 0 allocation from 7.1.6 in 36.213
						    0,	// virtual_resource_block_assignment_flag, unused here
						    0,	// resource_block_coding, to be filled in later
						    getQm(UE_list->UE_template[CC_id][UE_id].oldmcs1[harq_pid]), round & 3,	// redundancy version
						    1,	// transport blocks
						    0,	// transport block to codeword swap flag
						    cc[CC_id].p_eNB == 1 ? 0 : 1,	// transmission_scheme
						    1,	// number of layers
						    1,	// number of subbands
						    //                      uint8_t codebook_index,
						    4,	// UE category capacity
						    UE_list->UE_template[CC_id][UE_id].physicalConfigDedicated->pdsch_ConfigDedicated->p_a, 0,	// delta_power_offset for TM5
						    0,	// ngap
						    0,	// nprb
						    cc[CC_id].p_eNB == 1 ? 1 : 2,	// transmission mode
						    0,	//number of PRBs treated as one subband, not used here
						    0	// number of beamforming vectors, not used here
				);

			    LOG_D(MAC,
				  "Filled NFAPI configuration for DCI/DLSCH %d, retransmission round %d\n",
				  eNB->pdu_index[CC_id], round);

			    program_dlsch_acknak(module_idP, CC_id, UE_id,
						 frameP, subframeP,
						 dl_config_pdu->
						 dci_dl_pdu.dci_dl_pdu_rel8.
						 cce_idx);
			    // No TX request for retransmission (check if null request for FAPI)
			} else {
			    LOG_W(MAC,
				  "Frame %d, Subframe %d: Dropping DLSCH allocation for UE %d\%x, infeasible CCE allocation\n",
				  frameP, subframeP, UE_id, rnti);
			}
		    }


		    add_ue_dlsch_info(module_idP,
				      CC_id, UE_id, subframeP,
				      S_DL_SCHEDULED);

		    //eNB_UE_stats->dlsch_trials[round]++;
		    UE_list->eNB_UE_stats[CC_id][UE_id].
			num_retransmission += 1;
		    UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used_retx =
			nb_rb;
		    UE_list->eNB_UE_stats[CC_id][UE_id].
			total_rbs_used_retx += nb_rb;
		    UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_mcs1 =
			eNB_UE_stats->dlsch_mcs1;
		    UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_mcs2 =
			eNB_UE_stats->dlsch_mcs1;
		} else {
		    LOG_D(MAC,
			  "[eNB %d] Frame %d CC_id %d : don't schedule UE %d, its retransmission takes more resources than we have\n",
			  module_idP, frameP, CC_id, UE_id);
		}
	    } else {		/* This is a potentially new SDU opportunity */

		rlc_status.bytes_in_buffer = 0;
		// Now check RLC information to compute number of required RBs
		// get maximum TBS size for RLC request
		TBS =
		    get_TBS_DL(eNB_UE_stats->dlsch_mcs1, nb_available_rb);
		// check first for RLC data on DCCH
		// add the length for  all the control elements (timing adv, drx, etc) : header + payload

		if (ue_sched_ctl->ta_timer == 0) {
		    ta_update = ue_sched_ctl->ta_update;
		    /* if we send TA then set timer to not send it for a while */
		    if (ta_update != 31)
			ue_sched_ctl->ta_timer = 20;
		    /* reset ta_update */
		    ue_sched_ctl->ta_update = 31;
		} else {
		    ta_update = 31;
		}

		ta_len = (ta_update != 31) ? 2 : 0;

		header_len_dcch = 2;	// 2 bytes DCCH SDU subheader

		if (TBS - ta_len - header_len_dcch > 0) {
		    rlc_status = mac_rlc_status_ind(module_idP, rnti, module_idP, frameP, subframeP, ENB_FLAG_YES, MBMS_FLAG_NO, DCCH, (TBS - ta_len - header_len_dcch));	// transport block set size

		    sdu_lengths[0] = 0;

		    if (rlc_status.bytes_in_buffer > 0) {	// There is DCCH to transmit
			LOG_D(MAC,
			      "[eNB %d] Frame %d, DL-DCCH->DLSCH CC_id %d, Requesting %d bytes from RLC (RRC message)\n",
			      module_idP, frameP, CC_id,
			      TBS - header_len_dcch);
			sdu_lengths[0] = mac_rlc_data_req(module_idP, rnti, module_idP, frameP, ENB_FLAG_YES, MBMS_FLAG_NO, DCCH, TBS,	//not used
							  (char *)
							  &dlsch_buffer
							  [0]);

			T(T_ENB_MAC_UE_DL_SDU, T_INT(module_idP),
			  T_INT(CC_id), T_INT(rnti), T_INT(frameP),
			  T_INT(subframeP), T_INT(harq_pid), T_INT(DCCH),
			  T_INT(sdu_lengths[0]));

			LOG_D(MAC,
			      "[eNB %d][DCCH] CC_id %d Got %d bytes from RLC\n",
			      module_idP, CC_id, sdu_lengths[0]);
			sdu_length_total = sdu_lengths[0];
			sdu_lcids[0] = DCCH;
			UE_list->eNB_UE_stats[CC_id][UE_id].
			    num_pdu_tx[DCCH] += 1;
			UE_list->
			    eNB_UE_stats[CC_id][UE_id].num_bytes_tx[DCCH]
			    += sdu_lengths[0];
			num_sdus = 1;
987
#ifdef DEBUG_eNB_SCHEDULER
988
989
990
			LOG_T(MAC,
			      "[eNB %d][DCCH] CC_id %d Got %d bytes :",
			      module_idP, CC_id, sdu_lengths[0]);
991

992
993
994
			for (j = 0; j < sdu_lengths[0]; j++) {
			    LOG_T(MAC, "%x ", dlsch_buffer[j]);
			}
995

996
			LOG_T(MAC, "\n");
997
#endif
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
		    } else {
			header_len_dcch = 0;
			sdu_length_total = 0;
		    }
		}
		// check for DCCH1 and update header information (assume 2 byte sub-header)
		if (TBS - ta_len - header_len_dcch - sdu_length_total > 0) {
		    rlc_status = mac_rlc_status_ind(module_idP, rnti, module_idP, frameP, subframeP, ENB_FLAG_YES, MBMS_FLAG_NO, DCCH + 1, (TBS - ta_len - header_len_dcch - sdu_length_total));	// transport block set size less allocations for timing advance and
		    // DCCH SDU
		    sdu_lengths[num_sdus] = 0;

		    if (rlc_status.bytes_in_buffer > 0) {
			LOG_D(MAC,
			      "[eNB %d], Frame %d, DCCH1->DLSCH, CC_id %d, Requesting %d bytes from RLC (RRC message)\n",
			      module_idP, frameP, CC_id,
			      TBS - header_len_dcch - sdu_length_total);
			sdu_lengths[num_sdus] += mac_rlc_data_req(module_idP, rnti, module_idP, frameP, ENB_FLAG_YES, MBMS_FLAG_NO, DCCH + 1, TBS,	//not used
								  (char *)
								  &dlsch_buffer
								  [sdu_length_total]);

			T(T_ENB_MAC_UE_DL_SDU, T_INT(module_idP),
			  T_INT(CC_id), T_INT(rnti), T_INT(frameP),
			  T_INT(subframeP), T_INT(harq_pid),
			  T_INT(DCCH + 1), T_INT(sdu_lengths[num_sdus]));

			sdu_lcids[num_sdus] = DCCH1;
			sdu_length_total += sdu_lengths[num_sdus];
			header_len_dcch += 2;
			UE_list->eNB_UE_stats[CC_id][UE_id].
			    num_pdu_tx[DCCH1] += 1;
			UE_list->
			    eNB_UE_stats[CC_id][UE_id].num_bytes_tx[DCCH1]
			    += sdu_lengths[num_sdus];
			num_sdus++;
nikaeinn's avatar
nikaeinn committed
1033
#ifdef DEBUG_eNB_SCHEDULER
1034
1035
1036
			LOG_T(MAC,
			      "[eNB %d][DCCH1] CC_id %d Got %d bytes :",
			      module_idP, CC_id, sdu_lengths[num_sdus]);
1037

1038
1039
1040
			for (j = 0; j < sdu_lengths[num_sdus]; j++) {
			    LOG_T(MAC, "%x ", dlsch_buffer[j]);
			}
1041

1042
			LOG_T(MAC, "\n");
nikaeinn's avatar
nikaeinn committed
1043
#endif
1044

1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
		    }
		}
		// assume the max dtch header size, and adjust it later
		header_len_dtch = 0;
		header_len_dtch_last = 0;	// the header length of the last mac sdu
		// lcid has to be sorted before the actual allocation (similar struct as ue_list).
		for (lcid = NB_RB_MAX - 1; lcid >= DTCH; lcid--) {
		    // TBD: check if the lcid is active

		    header_len_dtch += 3;
		    header_len_dtch_last = 3;
		    LOG_D(MAC,
			  "[eNB %d], Frame %d, DTCH%d->DLSCH, Checking RLC status (tbs %d, len %d)\n",
			  module_idP, frameP, lcid, TBS,
			  TBS - ta_len - header_len_dcch -
			  sdu_length_total - header_len_dtch);

		    if (TBS - ta_len - header_len_dcch - sdu_length_total - header_len_dtch > 0) {	// NN: > 2 ? 
			rlc_status = mac_rlc_status_ind(module_idP,
							rnti,
							module_idP,
							frameP,
							subframeP,
							ENB_FLAG_YES,
							MBMS_FLAG_NO,
							lcid,
							TBS - ta_len -
							header_len_dcch -
							sdu_length_total -
							header_len_dtch);


			if (rlc_status.bytes_in_buffer > 0) {

			    LOG_D(MAC,
				  "[eNB %d][USER-PLANE DEFAULT DRB] Frame %d : DTCH->DLSCH, Requesting %d bytes from RLC (lcid %d total hdr len %d)\n",
				  module_idP, frameP,
				  TBS - header_len_dcch -
				  sdu_length_total - header_len_dtch, lcid,
				  header_len_dtch);
			    sdu_lengths[num_sdus] = mac_rlc_data_req(module_idP, rnti, module_idP, frameP, ENB_FLAG_YES, MBMS_FLAG_NO, lcid, TBS,	//not used
								     (char
								      *)
								     &dlsch_buffer
								     [sdu_length_total]);
			    T(T_ENB_MAC_UE_DL_SDU, T_INT(module_idP),
			      T_INT(CC_id), T_INT(rnti), T_INT(frameP),
			      T_INT(subframeP), T_INT(harq_pid),
			      T_INT(lcid), T_INT(sdu_lengths[num_sdus]));

			    LOG_D(MAC,
				  "[eNB %d][USER-PLANE DEFAULT DRB] Got %d bytes for DTCH %d \n",
				  module_idP, sdu_lengths[num_sdus], lcid);
			    sdu_lcids[num_sdus] = lcid;
			    sdu_length_total += sdu_lengths[num_sdus];
			    UE_list->
				eNB_UE_stats[CC_id][UE_id].num_pdu_tx[lcid]
				+= 1;
			    UE_list->
				eNB_UE_stats[CC_id][UE_id].num_bytes_tx
				[lcid] += sdu_lengths[num_sdus];
			    if (sdu_lengths[num_sdus] < 128) {
				header_len_dtch--;
				header_len_dtch_last--;
			    }
			    num_sdus++;
			}	// no data for this LCID
			else {
			    header_len_dtch -= 3;
			}
		    }		// no TBS left
		    else {
			header_len_dtch -= 3;
			break;
		    }
		}
		if (header_len_dtch == 0)
		    header_len_dtch_last = 0;
		// there is at least one SDU 
		// if (num_sdus > 0 ){
		if ((sdu_length_total + header_len_dcch +
		     header_len_dtch) > 0) {

		    // Now compute number of required RBs for total sdu length
		    // Assume RAH format 2
		    // adjust  header lengths
		    header_len_dcch_tmp = header_len_dcch;
		    header_len_dtch_tmp = header_len_dtch;
		    if (header_len_dtch == 0) {
			header_len_dcch = (header_len_dcch > 0) ? 1 : 0;	//header_len_dcch;  // remove length field
		    } else {
			header_len_dtch_last -= 1;	// now use it to find how many bytes has to be removed for the last MAC SDU 
			header_len_dtch = (header_len_dtch > 0) ? header_len_dtch - header_len_dtch_last : header_len_dtch;	// remove length field for the last SDU
		    }

		    mcs = eNB_UE_stats->dlsch_mcs1;

		    if (mcs == 0) {
			nb_rb = 4;	// don't let the TBS get too small
		    } else {
			nb_rb = min_rb_unit[CC_id];
		    }

		    TBS = get_TBS_DL(mcs, nb_rb);

		    while (TBS <
			   (sdu_length_total + header_len_dcch +
			    header_len_dtch + ta_len)) {
			nb_rb += min_rb_unit[CC_id];	//

			if (nb_rb > nb_available_rb) {	// if we've gone beyond the maximum number of RBs
			    // (can happen if N_RB_DL is odd)
			    TBS =
				get_TBS_DL(eNB_UE_stats->dlsch_mcs1,
					   nb_available_rb);
			    nb_rb = nb_available_rb;
			    break;
			}

			TBS = get_TBS_DL(eNB_UE_stats->dlsch_mcs1, nb_rb);
		    }

		    if (nb_rb == ue_sched_ctl->pre_nb_available_rbs[CC_id]) {
			for (j = 0; j < N_RBG[CC_id]; j++) {	// for indicating the rballoc for each sub-band
			    UE_list->UE_template[CC_id][UE_id].
				rballoc_subband[harq_pid][j] =
				ue_sched_ctl->rballoc_sub_UE[CC_id][j];
			}
		    } else {
			nb_rb_temp = nb_rb;
			j = 0;

			while ((nb_rb_temp > 0) && (j < N_RBG[CC_id])) {
			    if (ue_sched_ctl->rballoc_sub_UE[CC_id][j] ==
				1) {
				UE_list->
				    UE_template[CC_id]
				    [UE_id].rballoc_subband[harq_pid][j] =
				    ue_sched_ctl->rballoc_sub_UE[CC_id][j];

				if ((j == N_RBG[CC_id] - 1) &&
				    ((N_RB_DL[CC_id] == 25) ||
				     (N_RB_DL[CC_id] == 50))) {
				    nb_rb_temp =
					nb_rb_temp - min_rb_unit[CC_id] +
					1;
				} else {
				    nb_rb_temp =
					nb_rb_temp - min_rb_unit[CC_id];
				}
			    }

			    j = j + 1;
			}
		    }

		    // decrease mcs until TBS falls below required length
		    while ((TBS >
			    (sdu_length_total + header_len_dcch +
			     header_len_dtch + ta_len)) && (mcs > 0)) {
			mcs--;
			TBS = get_TBS_DL(mcs, nb_rb);
		    }

		    // if we have decreased too much or we don't have enough RBs, increase MCS
		    while ((TBS <
			    (sdu_length_total + header_len_dcch +
			     header_len_dtch + ta_len))
			   && (((ue_sched_ctl->dl_pow_off[CC_id] > 0)
				&& (mcs < 28))
			       || ((ue_sched_ctl->dl_pow_off[CC_id] == 0)
				   && (mcs <= 15)))) {
			mcs++;
			TBS = get_TBS_DL(mcs, nb_rb);
		    }

		    LOG_D(MAC,
			  "dlsch_mcs before and after the rate matching = (%d, %d)\n",
			  eNB_UE_stats->dlsch_mcs1, mcs);
1224
1225

#ifdef DEBUG_eNB_SCHEDULER
1226
1227
1228
1229
1230
		    LOG_D(MAC,
			  "[eNB %d] CC_id %d Generated DLSCH header (mcs %d, TBS %d, nb_rb %d)\n",
			  module_idP, CC_id, mcs, TBS, nb_rb);
		    // msg("[MAC][eNB ] Reminder of DLSCH with random data %d %d %d %d \n",
		    //  TBS, sdu_length_total, offset, TBS-sdu_length_total-offset);
1231
#endif
1232

1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
		    if ((TBS - header_len_dcch - header_len_dtch -
			 sdu_length_total - ta_len) <= 2) {
			padding =
			    (TBS - header_len_dcch - header_len_dtch -
			     sdu_length_total - ta_len);
			post_padding = 0;
		    } else {
			padding = 0;

			// adjust the header len
			if (header_len_dtch == 0) {
			    header_len_dcch = header_len_dcch_tmp;
			} else {	//if (( header_len_dcch==0)&&((header_len_dtch==1)||(header_len_dtch==2)))
			    header_len_dtch = header_len_dtch_tmp;
			}

			post_padding = TBS - sdu_length_total - header_len_dcch - header_len_dtch - ta_len;	// 1 is for the postpadding header
		    }


		    offset = generate_dlsch_header((unsigned char *) UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0], num_sdus,	//num_sdus
						   sdu_lengths,	//
						   sdu_lcids, 255,	// no drx
						   ta_update,	// timing advance
						   NULL,	// contention res id
						   padding, post_padding);

		    //#ifdef DEBUG_eNB_SCHEDULER
		    if (ta_update != 31) {
			LOG_D(MAC,
			      "[eNB %d][DLSCH] Frame %d Generate header for UE_id %d on CC_id %d: sdu_length_total %d, num_sdus %d, sdu_lengths[0] %d, sdu_lcids[0] %d => payload offset %d,timing advance value : %d, padding %d,post_padding %d,(mcs %d, TBS %d, nb_rb %d),header_dcch %d, header_dtch %d\n",
			      module_idP, frameP, UE_id, CC_id,
			      sdu_length_total, num_sdus, sdu_lengths[0],
			      sdu_lcids[0], offset, ta_update, padding,
			      post_padding, mcs, TBS, nb_rb,
			      header_len_dcch, header_len_dtch);
		    }
		    //#endif
1271
#ifdef DEBUG_eNB_SCHEDULER
1272
		    LOG_T(MAC, "[eNB %d] First 16 bytes of DLSCH : \n");
1273

1274
1275
1276
		    for (i = 0; i < 16; i++) {
			LOG_T(MAC, "%x.", dlsch_buffer[i]);
		    }
1277

1278
		    LOG_T(MAC, "\n");
1279
#endif
Cedric Roux's avatar
Cedric Roux committed
1280

1281
1282
          // cycle through SDUs and place in dlsch_buffer
          memcpy(&UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0][offset],dlsch_buffer,sdu_length_total);
1283
          // memcpy(RC.mac[0].DLSCH_pdu[0][0].payload[0][offset],dcch_buffer,sdu_lengths[0]);
1284
1285

          // fill remainder of DLSCH with random data
1286
          for (j=0; j<(TBS-sdu_length_total-offset); j++) {
1287
            UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0][offset+sdu_length_total+j] = (char)(taus()&0xff);
1288
          }
1289

1290

1291
1292
1293
          if (opt_enabled == 1) {
            trace_pdu(1, (uint8_t *)UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0],
                      TBS, module_idP, 3, UE_RNTI(module_idP,UE_id),
Wilson's avatar
Wilson committed
1294
                      eNB->frame, eNB->subframe,0,0);
1295
1296
            LOG_D(OPT,"[eNB %d][DLSCH] CC_id %d Frame %d  rnti %x  with size %d\n",
                  module_idP, CC_id, frameP, UE_RNTI(module_idP,UE_id), TBS);
1297
1298
          }

1299
1300
1301
          T(T_ENB_MAC_UE_DL_PDU_WITH_DATA, T_INT(module_idP), T_INT(CC_id), T_INT(rnti), T_INT(frameP), T_INT(subframeP),
            T_INT(harq_pid), T_BUFFER(UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0], TBS));

1302
	  UE_list->UE_template[CC_id][UE_id].nb_rb[harq_pid] = nb_rb;
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323

          add_ue_dlsch_info(module_idP,
                            CC_id,
                            UE_id,
                            subframeP,
                            S_DL_SCHEDULED);
          // store stats
          eNB->eNB_stats[CC_id].dlsch_bytes_tx+=sdu_length_total;
          eNB->eNB_stats[CC_id].dlsch_pdus_tx+=1;

          UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used = nb_rb;
          UE_list->eNB_UE_stats[CC_id][UE_id].total_rbs_used += nb_rb;
          UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_mcs1=eNB_UE_stats->dlsch_mcs1;
          UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_mcs2=mcs;
          UE_list->eNB_UE_stats[CC_id][UE_id].TBS = TBS;

          UE_list->eNB_UE_stats[CC_id][UE_id].overhead_bytes= TBS- sdu_length_total;
          UE_list->eNB_UE_stats[CC_id][UE_id].total_sdu_bytes+= sdu_length_total;
          UE_list->eNB_UE_stats[CC_id][UE_id].total_pdu_bytes+= TBS;
          UE_list->eNB_UE_stats[CC_id][UE_id].total_num_pdus+=1;

knopp's avatar
knopp committed
1324
          if (cc[CC_id].tdd_Config != NULL) { // TDD
1325
1326
1327
1328
            UE_list->UE_template[CC_id][UE_id].DAI++;
            update_ul_dci(module_idP,CC_id,rnti,UE_list->UE_template[CC_id][UE_id].DAI);
          }

knopp's avatar
knopp committed
1329
1330
	  // do PUCCH power control
          // this is the normalized RX power
1331
	  eNB_UE_stats =  &UE_list->eNB_UE_stats[CC_id][UE_id];
1332

1333
          /* TODO: fix how we deal with power, unit is not dBm, it's special from nfapi */
1334
	  normalized_rx_power = ue_sched_ctl->pucch1_snr[CC_id];
1335
	  target_rx_power = 208;
knopp's avatar
knopp committed
1336
1337
1338
	    
          // this assumes accumulated tpc
	  // make sure that we are only sending a tpc update once a frame, otherwise the control loop will freak out
1339
1340
1341
	  int32_t framex10psubframe = UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_frame*10+UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_subframe;
          if (((framex10psubframe+10)<=(frameP*10+subframeP)) || //normal case
	      ((framex10psubframe>(frameP*10+subframeP)) && (((10240-framex10psubframe+frameP*10+subframeP)>=10)))) //frame wrap-around
1342
1343
	    if (ue_sched_ctl->pucch1_cqi_update[CC_id] == 1) { 
	      ue_sched_ctl->pucch1_cqi_update[CC_id] = 0;
1344

knopp's avatar
knopp committed
1345
1346
	      UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_frame=frameP;
	      UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_subframe=subframeP;
1347
	      
1348
	      if (normalized_rx_power>(target_rx_power+4)) {
knopp's avatar
knopp committed
1349
1350
		tpc = 0; //-1
		tpc_accumulated--;
1351
	      } else if (normalized_rx_power<(target_rx_power-4)) {
knopp's avatar
knopp committed
1352
1353
1354
1355
1356
		tpc = 2; //+1
		tpc_accumulated++;
	      } else {
		tpc = 1; //0
	      }
1357
1358
	      	      
	      LOG_D(MAC,"[eNB %d] DLSCH scheduler: frame %d, subframe %d, harq_pid %d, tpc %d, accumulated %d, normalized/target rx power %d/%d\n",
knopp's avatar
knopp committed
1359
		    module_idP,frameP, subframeP,harq_pid,tpc,
1360
		    tpc_accumulated,normalized_rx_power,target_rx_power);
1361

1362
	    } // Po_PUCCH has been updated 
knopp's avatar
knopp committed
1363
1364
	    else {
	      tpc = 1; //0
1365
	    } // time to do TPC update 
knopp's avatar
knopp committed
1366
1367
1368
1369
	  else {
	    tpc = 1; //0
	  }

1370
	  dl_config_pdu                                                         = &dl_req->dl_config_pdu_list[dl_req->number_pdu]; 
1371
1372
	  memset((void*)dl_config_pdu,0,sizeof(nfapi_dl_config_request_pdu_t));
	  dl_config_pdu->pdu_type                                               = NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE; 
1373
	  dl_config_pdu->pdu_size                                               = (uint8_t)(2+sizeof(nfapi_dl_config_dci_dl_pdu));
1374
	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.dci_format                  = NFAPI_DL_DCI_FORMAT_1;
Cedric Roux's avatar
Cedric Roux committed
1375
	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level           = get_aggregation(get_bw_index(module_idP,CC_id),ue_sched_ctl->dl_cqi[CC_id],format1);
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti                        = rnti;
	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type                   = 1;    // CRNTI : see Table 4-10 from SCF082 - nFAPI specifications
	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.transmission_power          = 6000; // equal to RS power
	  
	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.harq_process                = harq_pid;
	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.tpc                         = tpc; // dont adjust power when retransmitting
	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.new_data_indicator_1        = 1-UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1                       = mcs;
	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.redundancy_version_1        = 0;
	  //deactivate second codeword
	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_2                       = 0;
	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.redundancy_version_2        = 1;
	  if (cc[CC_id].tdd_Config != NULL) { //TDD
	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.downlink_assignment_index = (UE_list->UE_template[CC_id][UE_id].DAI-1)&3;
1390
1391
	    LOG_D(MAC,"[eNB %d] Initial transmission CC_id %d : harq_pid %d, dai %d, mcs %d\n",
		  module_idP,CC_id,harq_pid,
1392
1393
1394
		  (UE_list->UE_template[CC_id][UE_id].DAI-1),
		  mcs);
	  } else {
1395
1396
	    LOG_D(MAC,"[eNB %d] Initial transmission CC_id %d : harq_pid %d, mcs %d\n",
		  module_idP,CC_id,harq_pid,mcs);
1397
1398
	    
	  }
1399
	  LOG_D(MAC,"Checking feasibility pdu %d (new sdu)\n",dl_req->number_pdu);
1400
	  if (!CCE_allocation_infeasible(module_idP,CC_id,1,subframeP,dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level,rnti)) {
1401
1402
1403


	    ue_sched_ctl->round[CC_id][harq_pid] = 0;
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
	    dl_req->number_dci++;
	    dl_req->number_pdu++;
	    
	    // Toggle NDI for next time
	    LOG_D(MAC,"CC_id %d Frame %d, subframeP %d: Toggling Format1 NDI for UE %d (rnti %x/%d) oldNDI %d\n",
		  CC_id, frameP,subframeP,UE_id,
		  rnti,harq_pid,UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid]);
	    
	    UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid]=1-UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
	    UE_list->UE_template[CC_id][UE_id].oldmcs1[harq_pid] = mcs;
	    UE_list->UE_template[CC_id][UE_id].oldmcs2[harq_pid] = 0;
	    AssertFatal(UE_list->UE_template[CC_id][UE_id].physicalConfigDedicated!=NULL,"physicalConfigDedicated is NULL\n");
	    AssertFatal(UE_list->UE_template[CC_id][UE_id].physicalConfigDedicated->pdsch_ConfigDedicated!=NULL,"physicalConfigDedicated->pdsch_ConfigDedicated is NULL\n");
	    
	    fill_nfapi_dlsch_config(eNB,dl_req,
				    TBS,
				    eNB->pdu_index[CC_id],
				    rnti,
				    0, // type 0 allocation from 7.1.6 in 36.213
				    0, // virtual_resource_block_assignment_flag, unused here
				    0, // resource_block_coding, to be filled in later
				    getQm(mcs),
				    0, // redundancy version
				    1, // transport blocks
				    0, // transport block to codeword swap flag
				    cc[CC_id].p_eNB == 1 ? 0 : 1, // transmission_scheme
				    1, // number of layers
				    1, // number of subbands
				    //			     uint8_t codebook_index,
				    4, // UE category capacity
				    UE_list->UE_template[CC_id][UE_id].physicalConfigDedicated->pdsch_ConfigDedicated->p_a, 
				    0, // delta_power_offset for TM5
				    0, // ngap
				    0, // nprb
				    cc[CC_id].p_eNB == 1 ? 1 : 2, // transmission mode
				    0, //number of PRBs treated as one subband, not used here
				    0 // number of beamforming vectors, not used here
				    );  
	    eNB->TX_req[CC_id].sfn_sf = fill_nfapi_tx_req(&eNB->TX_req[CC_id].tx_request_body,
							  (frameP*10)+subframeP,
							  TBS,
1445
							  eNB->pdu_index[CC_id],
1446
							  eNB->UE_list.DLSCH_pdu[CC_id][0][(unsigned char)UE_id].payload[0]);
1447
	    
knopp's avatar
knopp committed
1448
	    LOG_D(MAC,"Filled NFAPI configuration for DCI/DLSCH/TXREQ %d, new SDU\n",eNB->pdu_index[CC_id]);
1449

1450
1451
	    eNB->pdu_index[CC_id]++;
	    program_dlsch_acknak(module_idP,CC_id,UE_id,frameP,subframeP,dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.cce_idx);
Xu Bo's avatar
Xu Bo committed
1452
1453
1454
#ifdef UE_EXPANSION
        last_dlsch_ue_id[CC_id] = UE_id;
#endif
1455
1456
1457
1458
1459
	  }
	  else {
	    LOG_W(MAC,"Frame %d, Subframe %d: Dropping DLSCH allocation for UE %d/%x, infeasible CCE allocations\n",
		  frameP,subframeP,UE_id,rnti);
	  }
1460
        } else {  // There is no data from RLC or MAC header, so don't schedule
1461
1462

        }
1463
      }
1464

knopp's avatar
knopp committed
1465
1466
      if (cc[CC_id].tdd_Config != NULL){ // TDD
        set_ul_DAI(module_idP,UE_id,CC_id,frameP,subframeP);
1467
      }
1468

1469
1470
    } // UE_id loop
  }  // CC_id loop
knopp's avatar
   
knopp committed
1471

Cedric Roux's avatar
Cedric Roux committed
1472

1473
  fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_flag);
1474
  stop_meas(&eNB->schedule_dlsch);
gauthier's avatar
gauthier committed
1475
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_SCHEDULE_DLSCH,VCD_FUNCTION_OUT);
1476
1477


1478
1479
}

1480
1481
1482
//------------------------------------------------------------------------------
void
fill_DLSCH_dci(
1483
1484
1485
	       module_id_t module_idP,
	       frame_t frameP,
	       sub_frame_t subframeP,
Xu Bo's avatar
Xu Bo committed
1486
	       int* mbsfn_flagP)
1487
//------------------------------------------------------------------------------