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
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
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
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
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
593
594
595
596
597
598
599
600
601
602
603
604
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/* Copyright © 2003-2011 Emulex. All rights reserved. */
/*
* Source file containing the implementation of the Hardware specific
* functions
*/
#include <oce_impl.h>
#include <oce_stat.h>
#include <oce_ioctl.h>
static ddi_device_acc_attr_t reg_accattr = {
DDI_DEVICE_ATTR_V1,
DDI_STRUCTURE_LE_ACC,
DDI_STRICTORDER_ACC,
DDI_FLAGERR_ACC
};
extern int oce_destroy_q(struct oce_dev *dev, struct oce_mbx *mbx,
size_t req_size, enum qtype qtype);
static int
oce_map_regs(struct oce_dev *dev)
{
int ret = 0;
off_t bar_size = 0;
ASSERT(NULL != dev);
ASSERT(NULL != dev->dip);
/* get number of supported bars */
ret = ddi_dev_nregs(dev->dip, &dev->num_bars);
if (ret != DDI_SUCCESS) {
oce_log(dev, CE_WARN, MOD_CONFIG,
"%d: could not retrieve num_bars", MOD_CONFIG);
return (DDI_FAILURE);
}
/* verify each bar and map it accordingly */
/* PCI CFG */
ret = ddi_dev_regsize(dev->dip, OCE_DEV_CFG_BAR, &bar_size);
if (ret != DDI_SUCCESS) {
oce_log(dev, CE_WARN, MOD_CONFIG,
"Could not get sizeof BAR %d",
OCE_DEV_CFG_BAR);
return (DDI_FAILURE);
}
ret = ddi_regs_map_setup(dev->dip, OCE_DEV_CFG_BAR, &dev->dev_cfg_addr,
0, bar_size, ®_accattr, &dev->dev_cfg_handle);
if (ret != DDI_SUCCESS) {
oce_log(dev, CE_WARN, MOD_CONFIG,
"Could not map bar %d",
OCE_DEV_CFG_BAR);
return (DDI_FAILURE);
}
/* CSR */
ret = ddi_dev_regsize(dev->dip, OCE_PCI_CSR_BAR, &bar_size);
if (ret != DDI_SUCCESS) {
oce_log(dev, CE_WARN, MOD_CONFIG,
"Could not get sizeof BAR %d",
OCE_PCI_CSR_BAR);
return (DDI_FAILURE);
}
ret = ddi_regs_map_setup(dev->dip, OCE_PCI_CSR_BAR, &dev->csr_addr,
0, bar_size, ®_accattr, &dev->csr_handle);
if (ret != DDI_SUCCESS) {
oce_log(dev, CE_WARN, MOD_CONFIG,
"Could not map bar %d",
OCE_PCI_CSR_BAR);
ddi_regs_map_free(&dev->dev_cfg_handle);
return (DDI_FAILURE);
}
/* Doorbells */
ret = ddi_dev_regsize(dev->dip, OCE_PCI_DB_BAR, &bar_size);
if (ret != DDI_SUCCESS) {
oce_log(dev, CE_WARN, MOD_CONFIG,
"%d Could not get sizeof BAR %d",
ret, OCE_PCI_DB_BAR);
ddi_regs_map_free(&dev->csr_handle);
ddi_regs_map_free(&dev->dev_cfg_handle);
return (DDI_FAILURE);
}
ret = ddi_regs_map_setup(dev->dip, OCE_PCI_DB_BAR, &dev->db_addr,
0, 0, ®_accattr, &dev->db_handle);
if (ret != DDI_SUCCESS) {
oce_log(dev, CE_WARN, MOD_CONFIG,
"Could not map bar %d", OCE_PCI_DB_BAR);
ddi_regs_map_free(&dev->csr_handle);
ddi_regs_map_free(&dev->dev_cfg_handle);
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
static void
oce_unmap_regs(struct oce_dev *dev)
{
ASSERT(NULL != dev);
ASSERT(NULL != dev->dip);
ddi_regs_map_free(&dev->db_handle);
ddi_regs_map_free(&dev->csr_handle);
ddi_regs_map_free(&dev->dev_cfg_handle);
}
/*
* function to map the device memory
*
* dev - handle to device private data structure
*
*/
int
oce_pci_init(struct oce_dev *dev)
{
int ret = 0;
ret = oce_map_regs(dev);
if (ret != DDI_SUCCESS) {
return (DDI_FAILURE);
}
dev->fn = OCE_PCI_FUNC(dev);
if (oce_fm_check_acc_handle(dev, dev->dev_cfg_handle) != DDI_FM_OK) {
ddi_fm_service_impact(dev->dip, DDI_SERVICE_DEGRADED);
}
if (ret != DDI_FM_OK) {
oce_pci_fini(dev);
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
} /* oce_pci_init */
/*
* function to free device memory mapping mapped using
* oce_pci_init
*
* dev - handle to device private data
*/
void
oce_pci_fini(struct oce_dev *dev)
{
oce_unmap_regs(dev);
} /* oce_pci_fini */
/*
* function to read the PCI Bus, Device, and function numbers for the
* device instance.
*
* dev - handle to device private data
*/
int
oce_get_bdf(struct oce_dev *dev)
{
pci_regspec_t *pci_rp;
uint32_t length;
int rc;
/* Get "reg" property */
rc = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dev->dip,
0, "reg", (int **)&pci_rp, (uint_t *)&length);
if ((rc != DDI_SUCCESS) ||
(length < (sizeof (pci_regspec_t) / sizeof (int)))) {
oce_log(dev, CE_WARN, MOD_CONFIG,
"Failed to read \"reg\" property, Status = 0x%x", rc);
return (rc);
}
dev->pci_bus = PCI_REG_BUS_G(pci_rp->pci_phys_hi);
dev->pci_device = PCI_REG_DEV_G(pci_rp->pci_phys_hi);
dev->pci_function = PCI_REG_FUNC_G(pci_rp->pci_phys_hi);
oce_log(dev, CE_NOTE, MOD_CONFIG,
"\"reg\" property num=%d, Bus=%d, Device=%d, Function=%d",
length, dev->pci_bus, dev->pci_device, dev->pci_function);
/* Free the memory allocated by ddi_prop_lookup_int_array() */
ddi_prop_free(pci_rp);
return (rc);
}
int
oce_identify_hw(struct oce_dev *dev)
{
int ret = DDI_SUCCESS;
dev->vendor_id = pci_config_get16(dev->pci_cfg_handle,
PCI_CONF_VENID);
dev->device_id = pci_config_get16(dev->pci_cfg_handle,
PCI_CONF_DEVID);
dev->subsys_id = pci_config_get16(dev->pci_cfg_handle,
PCI_CONF_SUBSYSID);
dev->subvendor_id = pci_config_get16(dev->pci_cfg_handle,
PCI_CONF_SUBVENID);
switch (dev->device_id) {
case DEVID_TIGERSHARK:
dev->chip_rev = OC_CNA_GEN2;
break;
case DEVID_TOMCAT:
dev->chip_rev = OC_CNA_GEN3;
break;
default:
dev->chip_rev = 0;
ret = DDI_FAILURE;
break;
}
return (ret);
}
/*
* function to check if a reset is required
*
* dev - software handle to the device
*
*/
boolean_t
oce_is_reset_pci(struct oce_dev *dev)
{
mpu_ep_semaphore_t post_status;
ASSERT(dev != NULL);
ASSERT(dev->dip != NULL);
post_status.dw0 = 0;
post_status.dw0 = OCE_CSR_READ32(dev, MPU_EP_SEMAPHORE);
if (post_status.bits.stage == POST_STAGE_ARMFW_READY) {
return (B_FALSE);
}
return (B_TRUE);
} /* oce_is_reset_pci */
/*
* function to do a soft reset on the device
*
* dev - software handle to the device
*
*/
int
oce_pci_soft_reset(struct oce_dev *dev)
{
pcicfg_soft_reset_t soft_rst;
/* struct mpu_ep_control ep_control; */
/* struct pcicfg_online1 online1; */
clock_t tmo;
clock_t earlier = ddi_get_lbolt();
ASSERT(dev != NULL);
/* issue soft reset */
soft_rst.dw0 = OCE_CFG_READ32(dev, PCICFG_SOFT_RESET);
soft_rst.bits.soft_reset = 0x01;
OCE_CFG_WRITE32(dev, PCICFG_SOFT_RESET, soft_rst.dw0);
/* wait till soft reset bit deasserts */
tmo = drv_usectohz(60000000); /* 1.0min */
do {
if ((ddi_get_lbolt() - earlier) > tmo) {
tmo = 0;
break;
}
soft_rst.dw0 = OCE_CFG_READ32(dev, PCICFG_SOFT_RESET);
if (soft_rst.bits.soft_reset)
drv_usecwait(100);
} while (soft_rst.bits.soft_reset);
if (soft_rst.bits.soft_reset) {
oce_log(dev, CE_WARN, MOD_CONFIG,
"0x%x soft_reset"
"bit asserted[1]. Reset failed",
soft_rst.dw0);
return (DDI_FAILURE);
}
return (oce_POST(dev));
} /* oce_pci_soft_reset */
/*
* function to trigger a POST on the device
*
* dev - software handle to the device
*
*/
int
oce_POST(struct oce_dev *dev)
{
mpu_ep_semaphore_t post_status;
clock_t tmo;
clock_t earlier = ddi_get_lbolt();
/* read semaphore CSR */
post_status.dw0 = OCE_CSR_READ32(dev, MPU_EP_SEMAPHORE);
if (oce_fm_check_acc_handle(dev, dev->csr_handle) != DDI_FM_OK) {
ddi_fm_service_impact(dev->dip, DDI_SERVICE_DEGRADED);
return (DDI_FAILURE);
}
/* if host is ready then wait for fw ready else send POST */
if (post_status.bits.stage <= POST_STAGE_AWAITING_HOST_RDY) {
post_status.bits.stage = POST_STAGE_CHIP_RESET;
OCE_CSR_WRITE32(dev, MPU_EP_SEMAPHORE, post_status.dw0);
if (oce_fm_check_acc_handle(dev, dev->csr_handle) !=
DDI_FM_OK) {
ddi_fm_service_impact(dev->dip, DDI_SERVICE_DEGRADED);
return (DDI_FAILURE);
}
}
/* wait for FW ready */
tmo = drv_usectohz(60000000); /* 1.0min */
for (;;) {
if ((ddi_get_lbolt() - earlier) > tmo) {
tmo = 0;
break;
}
post_status.dw0 = OCE_CSR_READ32(dev, MPU_EP_SEMAPHORE);
if (oce_fm_check_acc_handle(dev, dev->csr_handle) !=
DDI_FM_OK) {
ddi_fm_service_impact(dev->dip, DDI_SERVICE_DEGRADED);
return (DDI_FAILURE);
}
if (post_status.bits.error) {
oce_log(dev, CE_WARN, MOD_CONFIG,
"0x%x POST ERROR!!", post_status.dw0);
return (DDI_FAILURE);
}
if (post_status.bits.stage == POST_STAGE_ARMFW_READY)
return (DDI_SUCCESS);
drv_usecwait(100);
}
return (DDI_FAILURE);
} /* oce_POST */
/*
* function to modify register access attributes corresponding to the
* FM capabilities configured by the user
*
* fm_caps - fm capability configured by the user and accepted by the driver
*/
void
oce_set_reg_fma_flags(int fm_caps)
{
if (fm_caps == DDI_FM_NOT_CAPABLE) {
return;
}
if (DDI_FM_ACC_ERR_CAP(fm_caps)) {
reg_accattr.devacc_attr_access = DDI_FLAGERR_ACC;
} else {
reg_accattr.devacc_attr_access = DDI_DEFAULT_ACC;
}
} /* oce_set_fma_flags */
int
oce_create_nw_interface(struct oce_dev *dev)
{
int ret;
uint32_t capab_flags = OCE_CAPAB_FLAGS;
uint32_t capab_en_flags = OCE_CAPAB_ENABLE;
if (dev->rss_enable) {
capab_flags |= MBX_RX_IFACE_FLAGS_RSS;
capab_en_flags |= MBX_RX_IFACE_FLAGS_RSS;
}
/* create an interface for the device with out mac */
ret = oce_if_create(dev, capab_flags, capab_en_flags,
0, &dev->mac_addr[0], (uint32_t *)&dev->if_id);
if (ret != 0) {
oce_log(dev, CE_WARN, MOD_CONFIG,
"Interface creation failed: 0x%x", ret);
return (ret);
}
atomic_inc_32(&dev->nifs);
dev->if_cap_flags = capab_en_flags;
/* Enable VLAN Promisc on HW */
ret = oce_config_vlan(dev, (uint8_t)dev->if_id, NULL, 0,
B_TRUE, B_TRUE);
if (ret != 0) {
oce_log(dev, CE_WARN, MOD_CONFIG,
"Config vlan failed: %d", ret);
oce_delete_nw_interface(dev);
return (ret);
}
/* set default flow control */
ret = oce_set_flow_control(dev, dev->flow_control);
if (ret != 0) {
oce_log(dev, CE_NOTE, MOD_CONFIG,
"Set flow control failed: %d", ret);
}
ret = oce_set_promiscuous(dev, dev->promisc);
if (ret != 0) {
oce_log(dev, CE_NOTE, MOD_CONFIG,
"Set Promisc failed: %d", ret);
}
return (0);
}
void
oce_delete_nw_interface(struct oce_dev *dev) {
/* currently only single interface is implmeneted */
if (dev->nifs > 0) {
(void) oce_if_del(dev, dev->if_id);
atomic_dec_32(&dev->nifs);
}
}
static void
oce_create_itbl(struct oce_dev *dev, char *itbl)
{
int i;
struct oce_rq **rss_queuep = &dev->rq[1];
int nrss = dev->nrqs - 1;
/* fill the indirection table rq 0 is default queue */
for (i = 0; i < OCE_ITBL_SIZE; i++) {
itbl[i] = rss_queuep[i % nrss]->rss_cpuid;
}
}
int
oce_setup_adapter(struct oce_dev *dev)
{
int ret;
char itbl[OCE_ITBL_SIZE];
char hkey[OCE_HKEY_SIZE];
/* disable the interrupts here and enable in start */
oce_chip_di(dev);
ret = oce_create_nw_interface(dev);
if (ret != DDI_SUCCESS) {
return (DDI_FAILURE);
}
ret = oce_create_queues(dev);
if (ret != DDI_SUCCESS) {
oce_delete_nw_interface(dev);
return (DDI_FAILURE);
}
if (dev->rss_enable) {
(void) oce_create_itbl(dev, itbl);
(void) oce_gen_hkey(hkey, OCE_HKEY_SIZE);
ret = oce_config_rss(dev, dev->if_id, hkey, itbl, OCE_ITBL_SIZE,
OCE_DEFAULT_RSS_TYPE, B_TRUE);
if (ret != DDI_SUCCESS) {
oce_log(dev, CE_NOTE, MOD_CONFIG, "%s",
"Failed to Configure RSS");
oce_delete_queues(dev);
oce_delete_nw_interface(dev);
return (ret);
}
}
ret = oce_setup_handlers(dev);
if (ret != DDI_SUCCESS) {
oce_log(dev, CE_NOTE, MOD_CONFIG, "%s",
"Failed to Setup handlers");
oce_delete_queues(dev);
oce_delete_nw_interface(dev);
return (ret);
}
return (DDI_SUCCESS);
}
void
oce_unsetup_adapter(struct oce_dev *dev)
{
oce_remove_handler(dev);
if (dev->rss_enable) {
char itbl[OCE_ITBL_SIZE] = {0};
char hkey[OCE_HKEY_SIZE] = {0};
int ret = 0;
ret = oce_config_rss(dev, dev->if_id, hkey, itbl, OCE_ITBL_SIZE,
RSS_ENABLE_NONE, B_TRUE);
if (ret != DDI_SUCCESS) {
oce_log(dev, CE_NOTE, MOD_CONFIG, "%s",
"Failed to Disable RSS");
}
}
oce_delete_queues(dev);
oce_delete_nw_interface(dev);
}
int
oce_hw_init(struct oce_dev *dev)
{
int ret;
struct mac_address_format mac_addr;
ret = oce_POST(dev);
if (ret != DDI_SUCCESS) {
oce_log(dev, CE_WARN, MOD_CONFIG, "%s",
"!!!HW POST1 FAILED");
/* ADD FM FAULT */
return (DDI_FAILURE);
}
/* create bootstrap mailbox */
dev->bmbx = oce_alloc_dma_buffer(dev,
sizeof (struct oce_bmbx), NULL, DDI_DMA_CONSISTENT);
if (dev->bmbx == NULL) {
oce_log(dev, CE_WARN, MOD_CONFIG,
"Failed to allocate bmbx: size = %u",
(uint32_t)sizeof (struct oce_bmbx));
return (DDI_FAILURE);
}
ret = oce_reset_fun(dev);
if (ret != 0) {
oce_log(dev, CE_WARN, MOD_CONFIG, "%s",
"!!!FUNCTION RESET FAILED");
goto init_fail;
}
/* reset the Endianess of BMBX */
ret = oce_mbox_init(dev);
if (ret != 0) {
oce_log(dev, CE_WARN, MOD_CONFIG,
"Mailbox initialization2 Failed with %d", ret);
goto init_fail;
}
/* read the firmware version */
ret = oce_get_fw_version(dev);
if (ret != 0) {
oce_log(dev, CE_WARN, MOD_CONFIG,
"Firmaware version read failed with %d", ret);
goto init_fail;
}
/* read the fw config */
ret = oce_get_fw_config(dev);
if (ret != 0) {
oce_log(dev, CE_WARN, MOD_CONFIG,
"Firmware configuration read failed with %d", ret);
goto init_fail;
}
/* read the Factory MAC address */
ret = oce_read_mac_addr(dev, 0, 1,
MAC_ADDRESS_TYPE_NETWORK, &mac_addr);
if (ret != 0) {
oce_log(dev, CE_WARN, MOD_CONFIG,
"MAC address read failed with %d", ret);
goto init_fail;
}
bcopy(&mac_addr.mac_addr[0], &dev->mac_addr[0], ETHERADDRL);
return (DDI_SUCCESS);
init_fail:
oce_hw_fini(dev);
return (DDI_FAILURE);
}
void
oce_hw_fini(struct oce_dev *dev)
{
if (dev->bmbx != NULL) {
oce_free_dma_buffer(dev, dev->bmbx);
dev->bmbx = NULL;
}
}
|