@@ -1262,6 +1262,80 @@ megasas_display_intel_branding(struct megasas_instance *instance)
1262
1262
}
1263
1263
}
1264
1264
1265
+ /**
1266
+ * megasas_allocate_raid_maps - Allocate memory for RAID maps
1267
+ * @instance: Adapter soft state
1268
+ *
1269
+ * return: if success: return 0
1270
+ * failed: return -ENOMEM
1271
+ */
1272
+ static inline int megasas_allocate_raid_maps (struct megasas_instance * instance )
1273
+ {
1274
+ struct fusion_context * fusion ;
1275
+ int i = 0 ;
1276
+
1277
+ fusion = instance -> ctrl_context ;
1278
+
1279
+ fusion -> drv_map_pages = get_order (fusion -> drv_map_sz );
1280
+
1281
+ for (i = 0 ; i < 2 ; i ++ ) {
1282
+ fusion -> ld_map [i ] = NULL ;
1283
+
1284
+ fusion -> ld_drv_map [i ] = (void * )
1285
+ __get_free_pages (__GFP_ZERO | GFP_KERNEL ,
1286
+ fusion -> drv_map_pages );
1287
+
1288
+ if (!fusion -> ld_drv_map [i ]) {
1289
+ fusion -> ld_drv_map [i ] = vzalloc (fusion -> drv_map_sz );
1290
+
1291
+ if (!fusion -> ld_drv_map [i ]) {
1292
+ dev_err (& instance -> pdev -> dev ,
1293
+ "Could not allocate memory for local map"
1294
+ " size requested: %d\n" ,
1295
+ fusion -> drv_map_sz );
1296
+ goto ld_drv_map_alloc_fail ;
1297
+ }
1298
+ }
1299
+ }
1300
+
1301
+ for (i = 0 ; i < 2 ; i ++ ) {
1302
+ fusion -> ld_map [i ] = dma_alloc_coherent (& instance -> pdev -> dev ,
1303
+ fusion -> max_map_sz ,
1304
+ & fusion -> ld_map_phys [i ],
1305
+ GFP_KERNEL );
1306
+ if (!fusion -> ld_map [i ]) {
1307
+ dev_err (& instance -> pdev -> dev ,
1308
+ "Could not allocate memory for map info %s:%d\n" ,
1309
+ __func__ , __LINE__ );
1310
+ goto ld_map_alloc_fail ;
1311
+ }
1312
+ }
1313
+
1314
+ return 0 ;
1315
+
1316
+ ld_map_alloc_fail :
1317
+ for (i = 0 ; i < 2 ; i ++ ) {
1318
+ if (fusion -> ld_map [i ])
1319
+ dma_free_coherent (& instance -> pdev -> dev ,
1320
+ fusion -> max_map_sz ,
1321
+ fusion -> ld_map [i ],
1322
+ fusion -> ld_map_phys [i ]);
1323
+ }
1324
+
1325
+ ld_drv_map_alloc_fail :
1326
+ for (i = 0 ; i < 2 ; i ++ ) {
1327
+ if (fusion -> ld_drv_map [i ]) {
1328
+ if (is_vmalloc_addr (fusion -> ld_drv_map [i ]))
1329
+ vfree (fusion -> ld_drv_map [i ]);
1330
+ else
1331
+ free_pages ((ulong )fusion -> ld_drv_map [i ],
1332
+ fusion -> drv_map_pages );
1333
+ }
1334
+ }
1335
+
1336
+ return - ENOMEM ;
1337
+ }
1338
+
1265
1339
/**
1266
1340
* megasas_init_adapter_fusion - Initializes the FW
1267
1341
* @instance: Adapter soft state
@@ -1381,45 +1455,14 @@ megasas_init_adapter_fusion(struct megasas_instance *instance)
1381
1455
instance -> r1_ldio_hint_default = MR_R1_LDIO_PIGGYBACK_DEFAULT ;
1382
1456
fusion -> fast_path_io = 0 ;
1383
1457
1384
- fusion -> drv_map_pages = get_order (fusion -> drv_map_sz );
1385
- for (i = 0 ; i < 2 ; i ++ ) {
1386
- fusion -> ld_map [i ] = NULL ;
1387
- fusion -> ld_drv_map [i ] = (void * )__get_free_pages (GFP_KERNEL ,
1388
- fusion -> drv_map_pages );
1389
- if (!fusion -> ld_drv_map [i ]) {
1390
- dev_err (& instance -> pdev -> dev , "Could not allocate "
1391
- "memory for local map info for %d pages\n" ,
1392
- fusion -> drv_map_pages );
1393
- if (i == 1 )
1394
- free_pages ((ulong )fusion -> ld_drv_map [0 ],
1395
- fusion -> drv_map_pages );
1396
- goto fail_ioc_init ;
1397
- }
1398
- memset (fusion -> ld_drv_map [i ], 0 ,
1399
- ((1 << PAGE_SHIFT ) << fusion -> drv_map_pages ));
1400
- }
1401
-
1402
- for (i = 0 ; i < 2 ; i ++ ) {
1403
- fusion -> ld_map [i ] = dma_alloc_coherent (& instance -> pdev -> dev ,
1404
- fusion -> max_map_sz ,
1405
- & fusion -> ld_map_phys [i ],
1406
- GFP_KERNEL );
1407
- if (!fusion -> ld_map [i ]) {
1408
- dev_err (& instance -> pdev -> dev , "Could not allocate memory "
1409
- "for map info\n" );
1410
- goto fail_map_info ;
1411
- }
1412
- }
1458
+ if (megasas_allocate_raid_maps (instance ))
1459
+ goto fail_ioc_init ;
1413
1460
1414
1461
if (!megasas_get_map_info (instance ))
1415
1462
megasas_sync_map_info (instance );
1416
1463
1417
1464
return 0 ;
1418
1465
1419
- fail_map_info :
1420
- if (i == 1 )
1421
- dma_free_coherent (& instance -> pdev -> dev , fusion -> max_map_sz ,
1422
- fusion -> ld_map [0 ], fusion -> ld_map_phys [0 ]);
1423
1466
fail_ioc_init :
1424
1467
megasas_free_cmds_fusion (instance );
1425
1468
fail_alloc_cmds :
@@ -3371,17 +3414,13 @@ megasas_alloc_host_crash_buffer(struct megasas_instance *instance)
3371
3414
{
3372
3415
unsigned int i ;
3373
3416
3374
- instance -> crash_buf_pages = get_order (CRASH_DMA_BUF_SIZE );
3375
3417
for (i = 0 ; i < MAX_CRASH_DUMP_SIZE ; i ++ ) {
3376
- instance -> crash_buf [i ] = (void * )__get_free_pages (GFP_KERNEL ,
3377
- instance -> crash_buf_pages );
3418
+ instance -> crash_buf [i ] = vzalloc (CRASH_DMA_BUF_SIZE );
3378
3419
if (!instance -> crash_buf [i ]) {
3379
3420
dev_info (& instance -> pdev -> dev , "Firmware crash dump "
3380
3421
"memory allocation failed at index %d\n" , i );
3381
3422
break ;
3382
3423
}
3383
- memset (instance -> crash_buf [i ], 0 ,
3384
- ((1 << PAGE_SHIFT ) << instance -> crash_buf_pages ));
3385
3424
}
3386
3425
instance -> drv_buf_alloc = i ;
3387
3426
}
@@ -3393,12 +3432,10 @@ megasas_alloc_host_crash_buffer(struct megasas_instance *instance)
3393
3432
void
3394
3433
megasas_free_host_crash_buffer (struct megasas_instance * instance )
3395
3434
{
3396
- unsigned int i
3397
- ;
3435
+ unsigned int i ;
3398
3436
for (i = 0 ; i < instance -> drv_buf_alloc ; i ++ ) {
3399
3437
if (instance -> crash_buf [i ])
3400
- free_pages ((ulong )instance -> crash_buf [i ],
3401
- instance -> crash_buf_pages );
3438
+ vfree (instance -> crash_buf [i ]);
3402
3439
}
3403
3440
instance -> drv_buf_index = 0 ;
3404
3441
instance -> drv_buf_alloc = 0 ;
0 commit comments