1 #include <linux/slab.h>
2 #include <linux/vmalloc.h>
3 #include <linux/interrupt.h>
8 #include <linux/swab.h>
9 #include <linux/dma-mapping.h>
11 #include <linux/ipv6.h>
12 #include <linux/inetdevice.h>
13 #include <linux/sysfs.h>
14 #include <linux/aer.h>
15 #include <linux/log2.h>
17 #include <linux/sysfs.h>
19 #define QLC_STATUS_UNSUPPORTED_CMD -2
21 int qlcnicvf_config_bridged_mode(struct qlcnic_adapter
*adapter
, u32 enable
)
26 int qlcnicvf_config_led(struct qlcnic_adapter
*adapter
, u32 state
, u32 rate
)
31 static ssize_t
qlcnic_store_bridged_mode(struct device
*dev
,
32 struct device_attribute
*attr
,
33 const char *buf
, size_t len
)
35 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
39 if (!(adapter
->ahw
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
))
42 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
45 if (strict_strtoul(buf
, 2, &new))
48 if (!qlcnic_config_bridged_mode(adapter
, !!new))
55 static ssize_t
qlcnic_show_bridged_mode(struct device
*dev
,
56 struct device_attribute
*attr
,
59 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
62 if (adapter
->ahw
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
)
63 bridged_mode
= !!(adapter
->flags
& QLCNIC_BRIDGE_ENABLED
);
65 return sprintf(buf
, "%d\n", bridged_mode
);
68 static ssize_t
qlcnic_store_diag_mode(struct device
*dev
,
69 struct device_attribute
*attr
,
70 const char *buf
, size_t len
)
72 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
75 if (strict_strtoul(buf
, 2, &new))
78 if (!!new != !!(adapter
->flags
& QLCNIC_DIAG_ENABLED
))
79 adapter
->flags
^= QLCNIC_DIAG_ENABLED
;
84 static ssize_t
qlcnic_show_diag_mode(struct device
*dev
,
85 struct device_attribute
*attr
, char *buf
)
87 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
88 return sprintf(buf
, "%d\n", !!(adapter
->flags
& QLCNIC_DIAG_ENABLED
));
91 static int qlcnic_validate_beacon(struct qlcnic_adapter
*adapter
, u16 beacon
,
97 QLCDB(adapter
, DRV
, "rate %x state %x\n", *rate
, *state
);
100 *rate
= __QLCNIC_MAX_LED_RATE
;
102 } else if (*state
> __QLCNIC_MAX_LED_STATE
) {
106 if ((!*rate
) || (*rate
> __QLCNIC_MAX_LED_RATE
))
112 static ssize_t
qlcnic_store_beacon(struct device
*dev
,
113 struct device_attribute
*attr
,
114 const char *buf
, size_t len
)
116 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
117 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
118 int err
, max_sds_rings
= adapter
->max_sds_rings
;
121 unsigned long h_beacon
;
123 if (adapter
->ahw
->op_mode
== QLCNIC_NON_PRIV_FUNC
) {
125 "LED test not supported in non privileged mode\n");
129 if (qlcnic_83xx_check(adapter
) &&
130 !test_bit(__QLCNIC_RESETTING
, &adapter
->state
)) {
131 if (kstrtoul(buf
, 2, &h_beacon
))
134 if (ahw
->beacon_state
== h_beacon
)
138 if (!ahw
->beacon_state
) {
139 if (test_and_set_bit(__QLCNIC_LED_ENABLE
,
146 err
= qlcnic_83xx_config_led(adapter
, 1, h_beacon
);
150 err
= qlcnic_83xx_config_led(adapter
, 0, !h_beacon
);
154 /* set the current beacon state */
155 ahw
->beacon_state
= h_beacon
;
157 if (!ahw
->beacon_state
)
158 clear_bit(__QLCNIC_LED_ENABLE
, &adapter
->state
);
164 if (len
!= sizeof(u16
))
165 return QL_STATUS_INVALID_PARAM
;
167 memcpy(&beacon
, buf
, sizeof(u16
));
168 err
= qlcnic_validate_beacon(adapter
, beacon
, &b_state
, &b_rate
);
172 if (adapter
->ahw
->beacon_state
== b_state
)
177 if (!adapter
->ahw
->beacon_state
)
178 if (test_and_set_bit(__QLCNIC_LED_ENABLE
, &adapter
->state
)) {
183 if (test_bit(__QLCNIC_RESETTING
, &adapter
->state
)) {
188 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
)) {
189 err
= qlcnic_diag_alloc_res(adapter
->netdev
, QLCNIC_LED_TEST
);
192 set_bit(__QLCNIC_DIAG_RES_ALLOC
, &adapter
->state
);
195 err
= qlcnic_config_led(adapter
, b_state
, b_rate
);
199 ahw
->beacon_state
= b_state
;
201 if (test_and_clear_bit(__QLCNIC_DIAG_RES_ALLOC
, &adapter
->state
))
202 qlcnic_diag_free_res(adapter
->netdev
, max_sds_rings
);
205 if (!adapter
->ahw
->beacon_state
)
206 clear_bit(__QLCNIC_LED_ENABLE
, &adapter
->state
);
212 static ssize_t
qlcnic_show_beacon(struct device
*dev
,
213 struct device_attribute
*attr
, char *buf
)
215 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
217 return sprintf(buf
, "%d\n", adapter
->ahw
->beacon_state
);
220 static int qlcnic_sysfs_validate_crb(struct qlcnic_adapter
*adapter
,
221 loff_t offset
, size_t size
)
225 if (!(adapter
->flags
& QLCNIC_DIAG_ENABLED
))
228 if (offset
< QLCNIC_PCI_CRBSPACE
) {
229 if (ADDR_IN_RANGE(offset
, QLCNIC_PCI_CAMQM
,
230 QLCNIC_PCI_CAMQM_END
))
236 if ((size
!= crb_size
) || (offset
& (crb_size
-1)))
242 static ssize_t
qlcnic_sysfs_read_crb(struct file
*filp
, struct kobject
*kobj
,
243 struct bin_attribute
*attr
, char *buf
,
244 loff_t offset
, size_t size
)
246 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
247 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
250 ret
= qlcnic_sysfs_validate_crb(adapter
, offset
, size
);
253 qlcnic_read_crb(adapter
, buf
, offset
, size
);
258 static ssize_t
qlcnic_sysfs_write_crb(struct file
*filp
, struct kobject
*kobj
,
259 struct bin_attribute
*attr
, char *buf
,
260 loff_t offset
, size_t size
)
262 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
263 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
266 ret
= qlcnic_sysfs_validate_crb(adapter
, offset
, size
);
270 qlcnic_write_crb(adapter
, buf
, offset
, size
);
274 static int qlcnic_sysfs_validate_mem(struct qlcnic_adapter
*adapter
,
275 loff_t offset
, size_t size
)
277 if (!(adapter
->flags
& QLCNIC_DIAG_ENABLED
))
280 if ((size
!= 8) || (offset
& 0x7))
286 static ssize_t
qlcnic_sysfs_read_mem(struct file
*filp
, struct kobject
*kobj
,
287 struct bin_attribute
*attr
, char *buf
,
288 loff_t offset
, size_t size
)
290 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
291 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
295 ret
= qlcnic_sysfs_validate_mem(adapter
, offset
, size
);
299 if (qlcnic_pci_mem_read_2M(adapter
, offset
, &data
))
302 memcpy(buf
, &data
, size
);
307 static ssize_t
qlcnic_sysfs_write_mem(struct file
*filp
, struct kobject
*kobj
,
308 struct bin_attribute
*attr
, char *buf
,
309 loff_t offset
, size_t size
)
311 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
312 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
316 ret
= qlcnic_sysfs_validate_mem(adapter
, offset
, size
);
320 memcpy(&data
, buf
, size
);
322 if (qlcnic_pci_mem_write_2M(adapter
, offset
, data
))
328 static int qlcnic_is_valid_nic_func(struct qlcnic_adapter
*adapter
, u8 pci_func
)
331 for (i
= 0; i
< adapter
->ahw
->act_pci_func
; i
++) {
332 if (adapter
->npars
[i
].pci_func
== pci_func
)
339 static int validate_pm_config(struct qlcnic_adapter
*adapter
,
340 struct qlcnic_pm_func_cfg
*pm_cfg
, int count
)
342 u8 src_pci_func
, s_esw_id
, d_esw_id
;
344 int i
, src_index
, dest_index
;
346 for (i
= 0; i
< count
; i
++) {
347 src_pci_func
= pm_cfg
[i
].pci_func
;
348 dest_pci_func
= pm_cfg
[i
].dest_npar
;
349 src_index
= qlcnic_is_valid_nic_func(adapter
, src_pci_func
);
352 return QL_STATUS_INVALID_PARAM
;
354 dest_index
= qlcnic_is_valid_nic_func(adapter
, dest_pci_func
);
356 return QL_STATUS_INVALID_PARAM
;
358 s_esw_id
= adapter
->npars
[src_index
].phy_port
;
359 d_esw_id
= adapter
->npars
[dest_index
].phy_port
;
361 if (s_esw_id
!= d_esw_id
)
362 return QL_STATUS_INVALID_PARAM
;
368 static ssize_t
qlcnic_sysfs_write_pm_config(struct file
*filp
,
369 struct kobject
*kobj
,
370 struct bin_attribute
*attr
,
371 char *buf
, loff_t offset
,
374 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
375 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
376 struct qlcnic_pm_func_cfg
*pm_cfg
;
377 u32 id
, action
, pci_func
;
378 int count
, rem
, i
, ret
, index
;
380 count
= size
/ sizeof(struct qlcnic_pm_func_cfg
);
381 rem
= size
% sizeof(struct qlcnic_pm_func_cfg
);
383 return QL_STATUS_INVALID_PARAM
;
385 pm_cfg
= (struct qlcnic_pm_func_cfg
*)buf
;
386 ret
= validate_pm_config(adapter
, pm_cfg
, count
);
390 for (i
= 0; i
< count
; i
++) {
391 pci_func
= pm_cfg
[i
].pci_func
;
392 action
= !!pm_cfg
[i
].action
;
393 index
= qlcnic_is_valid_nic_func(adapter
, pci_func
);
395 return QL_STATUS_INVALID_PARAM
;
397 id
= adapter
->npars
[index
].phy_port
;
398 ret
= qlcnic_config_port_mirroring(adapter
, id
,
404 for (i
= 0; i
< count
; i
++) {
405 pci_func
= pm_cfg
[i
].pci_func
;
406 index
= qlcnic_is_valid_nic_func(adapter
, pci_func
);
407 id
= adapter
->npars
[index
].phy_port
;
408 adapter
->npars
[index
].enable_pm
= !!pm_cfg
[i
].action
;
409 adapter
->npars
[index
].dest_npar
= id
;
415 static ssize_t
qlcnic_sysfs_read_pm_config(struct file
*filp
,
416 struct kobject
*kobj
,
417 struct bin_attribute
*attr
,
418 char *buf
, loff_t offset
,
421 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
422 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
423 struct qlcnic_pm_func_cfg pm_cfg
[QLCNIC_MAX_PCI_FUNC
];
427 if (size
!= sizeof(pm_cfg
))
428 return QL_STATUS_INVALID_PARAM
;
431 sizeof(struct qlcnic_pm_func_cfg
) * QLCNIC_MAX_PCI_FUNC
);
433 for (i
= 0; i
< adapter
->ahw
->act_pci_func
; i
++) {
434 pci_func
= adapter
->npars
[i
].pci_func
;
435 pm_cfg
[pci_func
].action
= adapter
->npars
[i
].enable_pm
;
436 pm_cfg
[pci_func
].dest_npar
= 0;
437 pm_cfg
[pci_func
].pci_func
= i
;
439 memcpy(buf
, &pm_cfg
, size
);
444 static int validate_esw_config(struct qlcnic_adapter
*adapter
,
445 struct qlcnic_esw_func_cfg
*esw_cfg
, int count
)
451 if (qlcnic_82xx_check(adapter
))
452 op_mode
= readl(adapter
->ahw
->pci_base0
+ QLCNIC_DRV_OP_MODE
);
454 op_mode
= QLCRDX(adapter
->ahw
, QLC_83XX_DRV_OP_MODE
);
456 for (i
= 0; i
< count
; i
++) {
457 pci_func
= esw_cfg
[i
].pci_func
;
458 if (pci_func
>= QLCNIC_MAX_PCI_FUNC
)
459 return QL_STATUS_INVALID_PARAM
;
461 if (adapter
->ahw
->op_mode
== QLCNIC_MGMT_FUNC
)
462 if (qlcnic_is_valid_nic_func(adapter
, pci_func
) < 0)
463 return QL_STATUS_INVALID_PARAM
;
465 switch (esw_cfg
[i
].op_mode
) {
466 case QLCNIC_PORT_DEFAULTS
:
467 if (qlcnic_82xx_check(adapter
)) {
468 ret
= QLC_DEV_GET_DRV(op_mode
, pci_func
);
470 ret
= QLC_83XX_GET_FUNC_PRIVILEGE(op_mode
,
472 esw_cfg
[i
].offload_flags
= 0;
475 if (ret
!= QLCNIC_NON_PRIV_FUNC
) {
476 if (esw_cfg
[i
].mac_anti_spoof
!= 0)
477 return QL_STATUS_INVALID_PARAM
;
478 if (esw_cfg
[i
].mac_override
!= 1)
479 return QL_STATUS_INVALID_PARAM
;
480 if (esw_cfg
[i
].promisc_mode
!= 1)
481 return QL_STATUS_INVALID_PARAM
;
484 case QLCNIC_ADD_VLAN
:
485 if (!IS_VALID_VLAN(esw_cfg
[i
].vlan_id
))
486 return QL_STATUS_INVALID_PARAM
;
487 if (!esw_cfg
[i
].op_type
)
488 return QL_STATUS_INVALID_PARAM
;
490 case QLCNIC_DEL_VLAN
:
491 if (!esw_cfg
[i
].op_type
)
492 return QL_STATUS_INVALID_PARAM
;
495 return QL_STATUS_INVALID_PARAM
;
502 static ssize_t
qlcnic_sysfs_write_esw_config(struct file
*file
,
503 struct kobject
*kobj
,
504 struct bin_attribute
*attr
,
505 char *buf
, loff_t offset
,
508 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
509 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
510 struct qlcnic_esw_func_cfg
*esw_cfg
;
511 struct qlcnic_npar_info
*npar
;
512 int count
, rem
, i
, ret
;
514 u8 op_mode
= 0, pci_func
;
516 count
= size
/ sizeof(struct qlcnic_esw_func_cfg
);
517 rem
= size
% sizeof(struct qlcnic_esw_func_cfg
);
519 return QL_STATUS_INVALID_PARAM
;
521 esw_cfg
= (struct qlcnic_esw_func_cfg
*)buf
;
522 ret
= validate_esw_config(adapter
, esw_cfg
, count
);
526 for (i
= 0; i
< count
; i
++) {
527 if (adapter
->ahw
->op_mode
== QLCNIC_MGMT_FUNC
)
528 if (qlcnic_config_switch_port(adapter
, &esw_cfg
[i
]))
529 return QL_STATUS_INVALID_PARAM
;
531 if (adapter
->ahw
->pci_func
!= esw_cfg
[i
].pci_func
)
534 op_mode
= esw_cfg
[i
].op_mode
;
535 qlcnic_get_eswitch_port_config(adapter
, &esw_cfg
[i
]);
536 esw_cfg
[i
].op_mode
= op_mode
;
537 esw_cfg
[i
].pci_func
= adapter
->ahw
->pci_func
;
539 switch (esw_cfg
[i
].op_mode
) {
540 case QLCNIC_PORT_DEFAULTS
:
541 qlcnic_set_eswitch_port_features(adapter
, &esw_cfg
[i
]);
543 case QLCNIC_ADD_VLAN
:
544 qlcnic_set_vlan_config(adapter
, &esw_cfg
[i
]);
546 case QLCNIC_DEL_VLAN
:
547 esw_cfg
[i
].vlan_id
= 0;
548 qlcnic_set_vlan_config(adapter
, &esw_cfg
[i
]);
553 if (adapter
->ahw
->op_mode
!= QLCNIC_MGMT_FUNC
)
556 for (i
= 0; i
< count
; i
++) {
557 pci_func
= esw_cfg
[i
].pci_func
;
558 index
= qlcnic_is_valid_nic_func(adapter
, pci_func
);
559 npar
= &adapter
->npars
[index
];
560 switch (esw_cfg
[i
].op_mode
) {
561 case QLCNIC_PORT_DEFAULTS
:
562 npar
->promisc_mode
= esw_cfg
[i
].promisc_mode
;
563 npar
->mac_override
= esw_cfg
[i
].mac_override
;
564 npar
->offload_flags
= esw_cfg
[i
].offload_flags
;
565 npar
->mac_anti_spoof
= esw_cfg
[i
].mac_anti_spoof
;
566 npar
->discard_tagged
= esw_cfg
[i
].discard_tagged
;
568 case QLCNIC_ADD_VLAN
:
569 npar
->pvid
= esw_cfg
[i
].vlan_id
;
571 case QLCNIC_DEL_VLAN
:
580 static ssize_t
qlcnic_sysfs_read_esw_config(struct file
*file
,
581 struct kobject
*kobj
,
582 struct bin_attribute
*attr
,
583 char *buf
, loff_t offset
,
586 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
587 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
588 struct qlcnic_esw_func_cfg esw_cfg
[QLCNIC_MAX_PCI_FUNC
];
591 if (size
!= sizeof(esw_cfg
))
592 return QL_STATUS_INVALID_PARAM
;
595 sizeof(struct qlcnic_esw_func_cfg
) * QLCNIC_MAX_PCI_FUNC
);
597 for (i
= 0; i
< adapter
->ahw
->act_pci_func
; i
++) {
598 pci_func
= adapter
->npars
[i
].pci_func
;
599 esw_cfg
[pci_func
].pci_func
= pci_func
;
600 if (qlcnic_get_eswitch_port_config(adapter
, &esw_cfg
[pci_func
]))
601 return QL_STATUS_INVALID_PARAM
;
604 memcpy(buf
, &esw_cfg
, size
);
609 static int validate_npar_config(struct qlcnic_adapter
*adapter
,
610 struct qlcnic_npar_func_cfg
*np_cfg
,
615 for (i
= 0; i
< count
; i
++) {
616 pci_func
= np_cfg
[i
].pci_func
;
617 if (qlcnic_is_valid_nic_func(adapter
, pci_func
) < 0)
618 return QL_STATUS_INVALID_PARAM
;
620 if (!IS_VALID_BW(np_cfg
[i
].min_bw
) ||
621 !IS_VALID_BW(np_cfg
[i
].max_bw
))
622 return QL_STATUS_INVALID_PARAM
;
627 static ssize_t
qlcnic_sysfs_write_npar_config(struct file
*file
,
628 struct kobject
*kobj
,
629 struct bin_attribute
*attr
,
630 char *buf
, loff_t offset
,
633 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
634 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
635 struct qlcnic_info nic_info
;
636 struct qlcnic_npar_func_cfg
*np_cfg
;
637 int i
, count
, rem
, ret
, index
;
640 count
= size
/ sizeof(struct qlcnic_npar_func_cfg
);
641 rem
= size
% sizeof(struct qlcnic_npar_func_cfg
);
643 return QL_STATUS_INVALID_PARAM
;
645 np_cfg
= (struct qlcnic_npar_func_cfg
*)buf
;
646 ret
= validate_npar_config(adapter
, np_cfg
, count
);
650 for (i
= 0; i
< count
; i
++) {
651 pci_func
= np_cfg
[i
].pci_func
;
653 memset(&nic_info
, 0, sizeof(struct qlcnic_info
));
654 ret
= qlcnic_get_nic_info(adapter
, &nic_info
, pci_func
);
657 nic_info
.pci_func
= pci_func
;
658 nic_info
.min_tx_bw
= np_cfg
[i
].min_bw
;
659 nic_info
.max_tx_bw
= np_cfg
[i
].max_bw
;
660 ret
= qlcnic_set_nic_info(adapter
, &nic_info
);
663 index
= qlcnic_is_valid_nic_func(adapter
, pci_func
);
664 adapter
->npars
[index
].min_bw
= nic_info
.min_tx_bw
;
665 adapter
->npars
[index
].max_bw
= nic_info
.max_tx_bw
;
671 static ssize_t
qlcnic_sysfs_read_npar_config(struct file
*file
,
672 struct kobject
*kobj
,
673 struct bin_attribute
*attr
,
674 char *buf
, loff_t offset
,
677 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
678 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
679 struct qlcnic_info nic_info
;
680 struct qlcnic_npar_func_cfg np_cfg
[QLCNIC_MAX_PCI_FUNC
];
683 if (size
!= sizeof(np_cfg
))
684 return QL_STATUS_INVALID_PARAM
;
686 memset(&nic_info
, 0, sizeof(struct qlcnic_info
));
688 sizeof(struct qlcnic_npar_func_cfg
) * QLCNIC_MAX_PCI_FUNC
);
690 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
691 if (qlcnic_is_valid_nic_func(adapter
, i
) < 0)
693 ret
= qlcnic_get_nic_info(adapter
, &nic_info
, i
);
697 np_cfg
[i
].pci_func
= i
;
698 np_cfg
[i
].op_mode
= (u8
)nic_info
.op_mode
;
699 np_cfg
[i
].port_num
= nic_info
.phys_port
;
700 np_cfg
[i
].fw_capab
= nic_info
.capabilities
;
701 np_cfg
[i
].min_bw
= nic_info
.min_tx_bw
;
702 np_cfg
[i
].max_bw
= nic_info
.max_tx_bw
;
703 np_cfg
[i
].max_tx_queues
= nic_info
.max_tx_ques
;
704 np_cfg
[i
].max_rx_queues
= nic_info
.max_rx_ques
;
707 memcpy(buf
, &np_cfg
, size
);
711 static ssize_t
qlcnic_sysfs_get_port_stats(struct file
*file
,
712 struct kobject
*kobj
,
713 struct bin_attribute
*attr
,
714 char *buf
, loff_t offset
,
717 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
718 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
719 struct qlcnic_esw_statistics port_stats
;
722 if (qlcnic_83xx_check(adapter
))
723 return QLC_STATUS_UNSUPPORTED_CMD
;
725 if (size
!= sizeof(struct qlcnic_esw_statistics
))
726 return QL_STATUS_INVALID_PARAM
;
728 if (offset
>= QLCNIC_MAX_PCI_FUNC
)
729 return QL_STATUS_INVALID_PARAM
;
731 memset(&port_stats
, 0, size
);
732 ret
= qlcnic_get_port_stats(adapter
, offset
, QLCNIC_QUERY_RX_COUNTER
,
737 ret
= qlcnic_get_port_stats(adapter
, offset
, QLCNIC_QUERY_TX_COUNTER
,
742 memcpy(buf
, &port_stats
, size
);
746 static ssize_t
qlcnic_sysfs_get_esw_stats(struct file
*file
,
747 struct kobject
*kobj
,
748 struct bin_attribute
*attr
,
749 char *buf
, loff_t offset
,
752 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
753 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
754 struct qlcnic_esw_statistics esw_stats
;
757 if (qlcnic_83xx_check(adapter
))
758 return QLC_STATUS_UNSUPPORTED_CMD
;
760 if (size
!= sizeof(struct qlcnic_esw_statistics
))
761 return QL_STATUS_INVALID_PARAM
;
763 if (offset
>= QLCNIC_NIU_MAX_XG_PORTS
)
764 return QL_STATUS_INVALID_PARAM
;
766 memset(&esw_stats
, 0, size
);
767 ret
= qlcnic_get_eswitch_stats(adapter
, offset
, QLCNIC_QUERY_RX_COUNTER
,
772 ret
= qlcnic_get_eswitch_stats(adapter
, offset
, QLCNIC_QUERY_TX_COUNTER
,
777 memcpy(buf
, &esw_stats
, size
);
781 static ssize_t
qlcnic_sysfs_clear_esw_stats(struct file
*file
,
782 struct kobject
*kobj
,
783 struct bin_attribute
*attr
,
784 char *buf
, loff_t offset
,
787 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
788 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
791 if (qlcnic_83xx_check(adapter
))
792 return QLC_STATUS_UNSUPPORTED_CMD
;
794 if (offset
>= QLCNIC_NIU_MAX_XG_PORTS
)
795 return QL_STATUS_INVALID_PARAM
;
797 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_ESWITCH
, offset
,
798 QLCNIC_QUERY_RX_COUNTER
);
802 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_ESWITCH
, offset
,
803 QLCNIC_QUERY_TX_COUNTER
);
810 static ssize_t
qlcnic_sysfs_clear_port_stats(struct file
*file
,
811 struct kobject
*kobj
,
812 struct bin_attribute
*attr
,
813 char *buf
, loff_t offset
,
817 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
818 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
821 if (qlcnic_83xx_check(adapter
))
822 return QLC_STATUS_UNSUPPORTED_CMD
;
824 if (offset
>= QLCNIC_MAX_PCI_FUNC
)
825 return QL_STATUS_INVALID_PARAM
;
827 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_PORT
, offset
,
828 QLCNIC_QUERY_RX_COUNTER
);
832 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_PORT
, offset
,
833 QLCNIC_QUERY_TX_COUNTER
);
840 static ssize_t
qlcnic_sysfs_read_pci_config(struct file
*file
,
841 struct kobject
*kobj
,
842 struct bin_attribute
*attr
,
843 char *buf
, loff_t offset
,
846 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
847 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
848 struct qlcnic_pci_func_cfg pci_cfg
[QLCNIC_MAX_PCI_FUNC
];
849 struct qlcnic_pci_info
*pci_info
;
852 if (size
!= sizeof(pci_cfg
))
853 return QL_STATUS_INVALID_PARAM
;
855 pci_info
= kcalloc(QLCNIC_MAX_PCI_FUNC
, sizeof(*pci_info
), GFP_KERNEL
);
859 ret
= qlcnic_get_pci_info(adapter
, pci_info
);
866 sizeof(struct qlcnic_pci_func_cfg
) * QLCNIC_MAX_PCI_FUNC
);
868 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
869 pci_cfg
[i
].pci_func
= pci_info
[i
].id
;
870 pci_cfg
[i
].func_type
= pci_info
[i
].type
;
871 pci_cfg
[i
].port_num
= pci_info
[i
].default_port
;
872 pci_cfg
[i
].min_bw
= pci_info
[i
].tx_min_bw
;
873 pci_cfg
[i
].max_bw
= pci_info
[i
].tx_max_bw
;
874 memcpy(&pci_cfg
[i
].def_mac_addr
, &pci_info
[i
].mac
, ETH_ALEN
);
877 memcpy(buf
, &pci_cfg
, size
);
882 static struct device_attribute dev_attr_bridged_mode
= {
883 .attr
= {.name
= "bridged_mode", .mode
= (S_IRUGO
| S_IWUSR
)},
884 .show
= qlcnic_show_bridged_mode
,
885 .store
= qlcnic_store_bridged_mode
,
888 static struct device_attribute dev_attr_diag_mode
= {
889 .attr
= {.name
= "diag_mode", .mode
= (S_IRUGO
| S_IWUSR
)},
890 .show
= qlcnic_show_diag_mode
,
891 .store
= qlcnic_store_diag_mode
,
894 static struct device_attribute dev_attr_beacon
= {
895 .attr
= {.name
= "beacon", .mode
= (S_IRUGO
| S_IWUSR
)},
896 .show
= qlcnic_show_beacon
,
897 .store
= qlcnic_store_beacon
,
900 static struct bin_attribute bin_attr_crb
= {
901 .attr
= {.name
= "crb", .mode
= (S_IRUGO
| S_IWUSR
)},
903 .read
= qlcnic_sysfs_read_crb
,
904 .write
= qlcnic_sysfs_write_crb
,
907 static struct bin_attribute bin_attr_mem
= {
908 .attr
= {.name
= "mem", .mode
= (S_IRUGO
| S_IWUSR
)},
910 .read
= qlcnic_sysfs_read_mem
,
911 .write
= qlcnic_sysfs_write_mem
,
914 static struct bin_attribute bin_attr_npar_config
= {
915 .attr
= {.name
= "npar_config", .mode
= (S_IRUGO
| S_IWUSR
)},
917 .read
= qlcnic_sysfs_read_npar_config
,
918 .write
= qlcnic_sysfs_write_npar_config
,
921 static struct bin_attribute bin_attr_pci_config
= {
922 .attr
= {.name
= "pci_config", .mode
= (S_IRUGO
| S_IWUSR
)},
924 .read
= qlcnic_sysfs_read_pci_config
,
928 static struct bin_attribute bin_attr_port_stats
= {
929 .attr
= {.name
= "port_stats", .mode
= (S_IRUGO
| S_IWUSR
)},
931 .read
= qlcnic_sysfs_get_port_stats
,
932 .write
= qlcnic_sysfs_clear_port_stats
,
935 static struct bin_attribute bin_attr_esw_stats
= {
936 .attr
= {.name
= "esw_stats", .mode
= (S_IRUGO
| S_IWUSR
)},
938 .read
= qlcnic_sysfs_get_esw_stats
,
939 .write
= qlcnic_sysfs_clear_esw_stats
,
942 static struct bin_attribute bin_attr_esw_config
= {
943 .attr
= {.name
= "esw_config", .mode
= (S_IRUGO
| S_IWUSR
)},
945 .read
= qlcnic_sysfs_read_esw_config
,
946 .write
= qlcnic_sysfs_write_esw_config
,
949 static struct bin_attribute bin_attr_pm_config
= {
950 .attr
= {.name
= "pm_config", .mode
= (S_IRUGO
| S_IWUSR
)},
952 .read
= qlcnic_sysfs_read_pm_config
,
953 .write
= qlcnic_sysfs_write_pm_config
,
956 void qlcnic_create_sysfs_entries(struct qlcnic_adapter
*adapter
)
958 struct device
*dev
= &adapter
->pdev
->dev
;
960 if (adapter
->ahw
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
)
961 if (device_create_file(dev
, &dev_attr_bridged_mode
))
963 "failed to create bridged_mode sysfs entry\n");
966 void qlcnic_remove_sysfs_entries(struct qlcnic_adapter
*adapter
)
968 struct device
*dev
= &adapter
->pdev
->dev
;
970 if (adapter
->ahw
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
)
971 device_remove_file(dev
, &dev_attr_bridged_mode
);
974 void qlcnic_create_diag_entries(struct qlcnic_adapter
*adapter
)
976 struct device
*dev
= &adapter
->pdev
->dev
;
978 if (device_create_bin_file(dev
, &bin_attr_port_stats
))
979 dev_info(dev
, "failed to create port stats sysfs entry");
981 if (adapter
->ahw
->op_mode
== QLCNIC_NON_PRIV_FUNC
)
983 if (device_create_file(dev
, &dev_attr_diag_mode
))
984 dev_info(dev
, "failed to create diag_mode sysfs entry\n");
985 if (device_create_bin_file(dev
, &bin_attr_crb
))
986 dev_info(dev
, "failed to create crb sysfs entry\n");
987 if (device_create_bin_file(dev
, &bin_attr_mem
))
988 dev_info(dev
, "failed to create mem sysfs entry\n");
990 if (device_create_bin_file(dev
, &bin_attr_pci_config
))
991 dev_info(dev
, "failed to create pci config sysfs entry");
992 if (device_create_file(dev
, &dev_attr_beacon
))
993 dev_info(dev
, "failed to create beacon sysfs entry");
995 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
))
997 if (device_create_bin_file(dev
, &bin_attr_esw_config
))
998 dev_info(dev
, "failed to create esw config sysfs entry");
999 if (adapter
->ahw
->op_mode
!= QLCNIC_MGMT_FUNC
)
1001 if (device_create_bin_file(dev
, &bin_attr_npar_config
))
1002 dev_info(dev
, "failed to create npar config sysfs entry");
1003 if (device_create_bin_file(dev
, &bin_attr_pm_config
))
1004 dev_info(dev
, "failed to create pm config sysfs entry");
1005 if (device_create_bin_file(dev
, &bin_attr_esw_stats
))
1006 dev_info(dev
, "failed to create eswitch stats sysfs entry");
1009 void qlcnic_remove_diag_entries(struct qlcnic_adapter
*adapter
)
1011 struct device
*dev
= &adapter
->pdev
->dev
;
1013 device_remove_bin_file(dev
, &bin_attr_port_stats
);
1015 if (adapter
->ahw
->op_mode
== QLCNIC_NON_PRIV_FUNC
)
1017 device_remove_file(dev
, &dev_attr_diag_mode
);
1018 device_remove_bin_file(dev
, &bin_attr_crb
);
1019 device_remove_bin_file(dev
, &bin_attr_mem
);
1020 device_remove_bin_file(dev
, &bin_attr_pci_config
);
1021 device_remove_file(dev
, &dev_attr_beacon
);
1022 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
))
1024 device_remove_bin_file(dev
, &bin_attr_esw_config
);
1025 if (adapter
->ahw
->op_mode
!= QLCNIC_MGMT_FUNC
)
1027 device_remove_bin_file(dev
, &bin_attr_npar_config
);
1028 device_remove_bin_file(dev
, &bin_attr_pm_config
);
1029 device_remove_bin_file(dev
, &bin_attr_esw_stats
);
1032 void qlcnic_82xx_add_sysfs(struct qlcnic_adapter
*adapter
)
1034 qlcnic_create_diag_entries(adapter
);
1037 void qlcnic_82xx_remove_sysfs(struct qlcnic_adapter
*adapter
)
1039 qlcnic_remove_diag_entries(adapter
);
1042 void qlcnic_83xx_add_sysfs(struct qlcnic_adapter
*adapter
)
1044 qlcnic_create_diag_entries(adapter
);
1047 void qlcnic_83xx_remove_sysfs(struct qlcnic_adapter
*adapter
)
1049 qlcnic_remove_diag_entries(adapter
);