2 * QLogic qlcnic NIC Driver
3 * Copyright (c) 2009-2013 QLogic Corporation
5 * See LICENSE.qlcnic for copyright and licensing details.
8 #include <linux/slab.h>
9 #include <linux/interrupt.h>
12 #include "qlcnic_hw.h"
14 #include <linux/swab.h>
15 #include <linux/dma-mapping.h>
17 #include <linux/ipv6.h>
18 #include <linux/inetdevice.h>
19 #include <linux/sysfs.h>
20 #include <linux/aer.h>
21 #include <linux/log2.h>
23 #define QLC_STATUS_UNSUPPORTED_CMD -2
25 int qlcnicvf_config_bridged_mode(struct qlcnic_adapter
*adapter
, u32 enable
)
30 int qlcnicvf_config_led(struct qlcnic_adapter
*adapter
, u32 state
, u32 rate
)
35 static ssize_t
qlcnic_store_bridged_mode(struct device
*dev
,
36 struct device_attribute
*attr
,
37 const char *buf
, size_t len
)
39 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
43 if (!(adapter
->ahw
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
))
46 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
49 if (kstrtoul(buf
, 2, &new))
52 if (!qlcnic_config_bridged_mode(adapter
, !!new))
59 static ssize_t
qlcnic_show_bridged_mode(struct device
*dev
,
60 struct device_attribute
*attr
,
63 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
66 if (adapter
->ahw
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
)
67 bridged_mode
= !!(adapter
->flags
& QLCNIC_BRIDGE_ENABLED
);
69 return sprintf(buf
, "%d\n", bridged_mode
);
72 static ssize_t
qlcnic_store_diag_mode(struct device
*dev
,
73 struct device_attribute
*attr
,
74 const char *buf
, size_t len
)
76 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
79 if (kstrtoul(buf
, 2, &new))
82 if (!!new != !!(adapter
->flags
& QLCNIC_DIAG_ENABLED
))
83 adapter
->flags
^= QLCNIC_DIAG_ENABLED
;
88 static ssize_t
qlcnic_show_diag_mode(struct device
*dev
,
89 struct device_attribute
*attr
, char *buf
)
91 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
92 return sprintf(buf
, "%d\n", !!(adapter
->flags
& QLCNIC_DIAG_ENABLED
));
95 static int qlcnic_validate_beacon(struct qlcnic_adapter
*adapter
, u16 beacon
,
101 QLCDB(adapter
, DRV
, "rate %x state %x\n", *rate
, *state
);
104 *rate
= __QLCNIC_MAX_LED_RATE
;
106 } else if (*state
> __QLCNIC_MAX_LED_STATE
) {
110 if ((!*rate
) || (*rate
> __QLCNIC_MAX_LED_RATE
))
116 static int qlcnic_83xx_store_beacon(struct qlcnic_adapter
*adapter
,
117 const char *buf
, size_t len
)
119 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
120 unsigned long h_beacon
;
123 if (test_bit(__QLCNIC_RESETTING
, &adapter
->state
))
126 if (kstrtoul(buf
, 2, &h_beacon
))
129 qlcnic_get_beacon_state(adapter
);
131 if (ahw
->beacon_state
== h_beacon
)
135 if (!ahw
->beacon_state
) {
136 if (test_and_set_bit(__QLCNIC_LED_ENABLE
, &adapter
->state
)) {
143 err
= qlcnic_83xx_config_led(adapter
, 1, h_beacon
);
145 err
= qlcnic_83xx_config_led(adapter
, 0, !h_beacon
);
147 ahw
->beacon_state
= h_beacon
;
149 if (!ahw
->beacon_state
)
150 clear_bit(__QLCNIC_LED_ENABLE
, &adapter
->state
);
156 static int qlcnic_82xx_store_beacon(struct qlcnic_adapter
*adapter
,
157 const char *buf
, size_t len
)
159 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
160 int err
, drv_sds_rings
= adapter
->drv_sds_rings
;
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 qlcnic_get_beacon_state(adapter
);
174 if (ahw
->beacon_state
== b_state
)
178 if (!ahw
->beacon_state
) {
179 if (test_and_set_bit(__QLCNIC_LED_ENABLE
, &adapter
->state
)) {
185 if (test_bit(__QLCNIC_RESETTING
, &adapter
->state
)) {
190 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
)) {
191 err
= qlcnic_diag_alloc_res(adapter
->netdev
, QLCNIC_LED_TEST
);
194 set_bit(__QLCNIC_DIAG_RES_ALLOC
, &adapter
->state
);
197 err
= qlcnic_config_led(adapter
, b_state
, b_rate
);
200 ahw
->beacon_state
= b_state
;
203 if (test_and_clear_bit(__QLCNIC_DIAG_RES_ALLOC
, &adapter
->state
))
204 qlcnic_diag_free_res(adapter
->netdev
, drv_sds_rings
);
207 if (!ahw
->beacon_state
)
208 clear_bit(__QLCNIC_LED_ENABLE
, &adapter
->state
);
214 static ssize_t
qlcnic_store_beacon(struct device
*dev
,
215 struct device_attribute
*attr
,
216 const char *buf
, size_t len
)
218 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
221 if (adapter
->ahw
->op_mode
== QLCNIC_NON_PRIV_FUNC
) {
223 "LED test not supported in non privileged mode\n");
227 if (qlcnic_82xx_check(adapter
))
228 err
= qlcnic_82xx_store_beacon(adapter
, buf
, len
);
229 else if (qlcnic_83xx_check(adapter
))
230 err
= qlcnic_83xx_store_beacon(adapter
, buf
, len
);
237 static ssize_t
qlcnic_show_beacon(struct device
*dev
,
238 struct device_attribute
*attr
, char *buf
)
240 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
242 return sprintf(buf
, "%d\n", adapter
->ahw
->beacon_state
);
245 static int qlcnic_sysfs_validate_crb(struct qlcnic_adapter
*adapter
,
246 loff_t offset
, size_t size
)
250 if (!(adapter
->flags
& QLCNIC_DIAG_ENABLED
))
253 if (offset
< QLCNIC_PCI_CRBSPACE
) {
254 if (ADDR_IN_RANGE(offset
, QLCNIC_PCI_CAMQM
,
255 QLCNIC_PCI_CAMQM_END
))
261 if ((size
!= crb_size
) || (offset
& (crb_size
-1)))
267 static ssize_t
qlcnic_sysfs_read_crb(struct file
*filp
, struct kobject
*kobj
,
268 struct bin_attribute
*attr
, char *buf
,
269 loff_t offset
, size_t size
)
271 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
272 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
275 ret
= qlcnic_sysfs_validate_crb(adapter
, offset
, size
);
278 qlcnic_read_crb(adapter
, buf
, offset
, size
);
283 static ssize_t
qlcnic_sysfs_write_crb(struct file
*filp
, struct kobject
*kobj
,
284 struct bin_attribute
*attr
, char *buf
,
285 loff_t offset
, size_t size
)
287 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
288 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
291 ret
= qlcnic_sysfs_validate_crb(adapter
, offset
, size
);
295 qlcnic_write_crb(adapter
, buf
, offset
, size
);
299 static int qlcnic_sysfs_validate_mem(struct qlcnic_adapter
*adapter
,
300 loff_t offset
, size_t size
)
302 if (!(adapter
->flags
& QLCNIC_DIAG_ENABLED
))
305 if ((size
!= 8) || (offset
& 0x7))
311 static ssize_t
qlcnic_sysfs_read_mem(struct file
*filp
, struct kobject
*kobj
,
312 struct bin_attribute
*attr
, char *buf
,
313 loff_t offset
, size_t size
)
315 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
316 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
320 ret
= qlcnic_sysfs_validate_mem(adapter
, offset
, size
);
324 if (qlcnic_pci_mem_read_2M(adapter
, offset
, &data
))
327 memcpy(buf
, &data
, size
);
332 static ssize_t
qlcnic_sysfs_write_mem(struct file
*filp
, struct kobject
*kobj
,
333 struct bin_attribute
*attr
, char *buf
,
334 loff_t offset
, size_t size
)
336 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
337 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
341 ret
= qlcnic_sysfs_validate_mem(adapter
, offset
, size
);
345 memcpy(&data
, buf
, size
);
347 if (qlcnic_pci_mem_write_2M(adapter
, offset
, data
))
353 int qlcnic_is_valid_nic_func(struct qlcnic_adapter
*adapter
, u8 pci_func
)
357 for (i
= 0; i
< adapter
->ahw
->total_nic_func
; i
++) {
358 if (adapter
->npars
[i
].pci_func
== pci_func
)
364 static int validate_pm_config(struct qlcnic_adapter
*adapter
,
365 struct qlcnic_pm_func_cfg
*pm_cfg
, int count
)
367 u8 src_pci_func
, s_esw_id
, d_esw_id
;
369 int i
, src_index
, dest_index
;
371 for (i
= 0; i
< count
; i
++) {
372 src_pci_func
= pm_cfg
[i
].pci_func
;
373 dest_pci_func
= pm_cfg
[i
].dest_npar
;
374 src_index
= qlcnic_is_valid_nic_func(adapter
, src_pci_func
);
376 return QL_STATUS_INVALID_PARAM
;
378 dest_index
= qlcnic_is_valid_nic_func(adapter
, dest_pci_func
);
380 return QL_STATUS_INVALID_PARAM
;
382 s_esw_id
= adapter
->npars
[src_index
].phy_port
;
383 d_esw_id
= adapter
->npars
[dest_index
].phy_port
;
385 if (s_esw_id
!= d_esw_id
)
386 return QL_STATUS_INVALID_PARAM
;
392 static ssize_t
qlcnic_sysfs_write_pm_config(struct file
*filp
,
393 struct kobject
*kobj
,
394 struct bin_attribute
*attr
,
395 char *buf
, loff_t offset
,
398 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
399 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
400 struct qlcnic_pm_func_cfg
*pm_cfg
;
401 u32 id
, action
, pci_func
;
402 int count
, rem
, i
, ret
, index
;
404 count
= size
/ sizeof(struct qlcnic_pm_func_cfg
);
405 rem
= size
% sizeof(struct qlcnic_pm_func_cfg
);
407 return QL_STATUS_INVALID_PARAM
;
409 pm_cfg
= (struct qlcnic_pm_func_cfg
*)buf
;
410 ret
= validate_pm_config(adapter
, pm_cfg
, count
);
414 for (i
= 0; i
< count
; i
++) {
415 pci_func
= pm_cfg
[i
].pci_func
;
416 action
= !!pm_cfg
[i
].action
;
417 index
= qlcnic_is_valid_nic_func(adapter
, pci_func
);
419 return QL_STATUS_INVALID_PARAM
;
421 id
= adapter
->npars
[index
].phy_port
;
422 ret
= qlcnic_config_port_mirroring(adapter
, id
,
428 for (i
= 0; i
< count
; i
++) {
429 pci_func
= pm_cfg
[i
].pci_func
;
430 index
= qlcnic_is_valid_nic_func(adapter
, pci_func
);
432 return QL_STATUS_INVALID_PARAM
;
433 id
= adapter
->npars
[index
].phy_port
;
434 adapter
->npars
[index
].enable_pm
= !!pm_cfg
[i
].action
;
435 adapter
->npars
[index
].dest_npar
= id
;
441 static ssize_t
qlcnic_sysfs_read_pm_config(struct file
*filp
,
442 struct kobject
*kobj
,
443 struct bin_attribute
*attr
,
444 char *buf
, loff_t offset
,
447 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
448 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
449 struct qlcnic_pm_func_cfg
*pm_cfg
;
454 memset(buf
, 0, size
);
455 pm_cfg
= (struct qlcnic_pm_func_cfg
*)buf
;
456 count
= size
/ sizeof(struct qlcnic_pm_func_cfg
);
457 for (i
= 0; i
< adapter
->ahw
->total_nic_func
; i
++) {
458 pci_func
= adapter
->npars
[i
].pci_func
;
459 if (pci_func
>= count
) {
460 dev_dbg(dev
, "%s: Total nic functions[%d], App sent function count[%d]\n",
461 __func__
, adapter
->ahw
->total_nic_func
, count
);
464 if (!adapter
->npars
[i
].eswitch_status
)
467 pm_cfg
[pci_func
].action
= adapter
->npars
[i
].enable_pm
;
468 pm_cfg
[pci_func
].dest_npar
= 0;
469 pm_cfg
[pci_func
].pci_func
= i
;
474 static int validate_esw_config(struct qlcnic_adapter
*adapter
,
475 struct qlcnic_esw_func_cfg
*esw_cfg
, int count
)
477 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
482 if (qlcnic_82xx_check(adapter
))
483 op_mode
= readl(ahw
->pci_base0
+ QLCNIC_DRV_OP_MODE
);
485 op_mode
= QLCRDX(ahw
, QLC_83XX_DRV_OP_MODE
);
487 for (i
= 0; i
< count
; i
++) {
488 pci_func
= esw_cfg
[i
].pci_func
;
489 if (pci_func
>= ahw
->max_vnic_func
)
490 return QL_STATUS_INVALID_PARAM
;
492 if (adapter
->ahw
->op_mode
== QLCNIC_MGMT_FUNC
)
493 if (qlcnic_is_valid_nic_func(adapter
, pci_func
) < 0)
494 return QL_STATUS_INVALID_PARAM
;
496 switch (esw_cfg
[i
].op_mode
) {
497 case QLCNIC_PORT_DEFAULTS
:
498 if (qlcnic_82xx_check(adapter
)) {
499 ret
= QLC_DEV_GET_DRV(op_mode
, pci_func
);
501 ret
= QLC_83XX_GET_FUNC_PRIVILEGE(op_mode
,
503 esw_cfg
[i
].offload_flags
= 0;
506 if (ret
!= QLCNIC_NON_PRIV_FUNC
) {
507 if (esw_cfg
[i
].mac_anti_spoof
!= 0)
508 return QL_STATUS_INVALID_PARAM
;
509 if (esw_cfg
[i
].mac_override
!= 1)
510 return QL_STATUS_INVALID_PARAM
;
511 if (esw_cfg
[i
].promisc_mode
!= 1)
512 return QL_STATUS_INVALID_PARAM
;
515 case QLCNIC_ADD_VLAN
:
516 if (!IS_VALID_VLAN(esw_cfg
[i
].vlan_id
))
517 return QL_STATUS_INVALID_PARAM
;
518 if (!esw_cfg
[i
].op_type
)
519 return QL_STATUS_INVALID_PARAM
;
521 case QLCNIC_DEL_VLAN
:
522 if (!esw_cfg
[i
].op_type
)
523 return QL_STATUS_INVALID_PARAM
;
526 return QL_STATUS_INVALID_PARAM
;
533 static ssize_t
qlcnic_sysfs_write_esw_config(struct file
*file
,
534 struct kobject
*kobj
,
535 struct bin_attribute
*attr
,
536 char *buf
, loff_t offset
,
539 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
540 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
541 struct qlcnic_esw_func_cfg
*esw_cfg
;
542 struct qlcnic_npar_info
*npar
;
543 int count
, rem
, i
, ret
;
545 u8 op_mode
= 0, pci_func
;
547 count
= size
/ sizeof(struct qlcnic_esw_func_cfg
);
548 rem
= size
% sizeof(struct qlcnic_esw_func_cfg
);
550 return QL_STATUS_INVALID_PARAM
;
552 esw_cfg
= (struct qlcnic_esw_func_cfg
*)buf
;
553 ret
= validate_esw_config(adapter
, esw_cfg
, count
);
557 for (i
= 0; i
< count
; i
++) {
558 if (adapter
->ahw
->op_mode
== QLCNIC_MGMT_FUNC
)
559 if (qlcnic_config_switch_port(adapter
, &esw_cfg
[i
]))
560 return QL_STATUS_INVALID_PARAM
;
562 if (adapter
->ahw
->pci_func
!= esw_cfg
[i
].pci_func
)
565 op_mode
= esw_cfg
[i
].op_mode
;
566 qlcnic_get_eswitch_port_config(adapter
, &esw_cfg
[i
]);
567 esw_cfg
[i
].op_mode
= op_mode
;
568 esw_cfg
[i
].pci_func
= adapter
->ahw
->pci_func
;
570 switch (esw_cfg
[i
].op_mode
) {
571 case QLCNIC_PORT_DEFAULTS
:
572 qlcnic_set_eswitch_port_features(adapter
, &esw_cfg
[i
]);
574 qlcnic_set_netdev_features(adapter
, &esw_cfg
[i
]);
577 case QLCNIC_ADD_VLAN
:
578 qlcnic_set_vlan_config(adapter
, &esw_cfg
[i
]);
580 case QLCNIC_DEL_VLAN
:
581 esw_cfg
[i
].vlan_id
= 0;
582 qlcnic_set_vlan_config(adapter
, &esw_cfg
[i
]);
587 if (adapter
->ahw
->op_mode
!= QLCNIC_MGMT_FUNC
)
590 for (i
= 0; i
< count
; i
++) {
591 pci_func
= esw_cfg
[i
].pci_func
;
592 index
= qlcnic_is_valid_nic_func(adapter
, pci_func
);
594 return QL_STATUS_INVALID_PARAM
;
595 npar
= &adapter
->npars
[index
];
596 switch (esw_cfg
[i
].op_mode
) {
597 case QLCNIC_PORT_DEFAULTS
:
598 npar
->promisc_mode
= esw_cfg
[i
].promisc_mode
;
599 npar
->mac_override
= esw_cfg
[i
].mac_override
;
600 npar
->offload_flags
= esw_cfg
[i
].offload_flags
;
601 npar
->mac_anti_spoof
= esw_cfg
[i
].mac_anti_spoof
;
602 npar
->discard_tagged
= esw_cfg
[i
].discard_tagged
;
604 case QLCNIC_ADD_VLAN
:
605 npar
->pvid
= esw_cfg
[i
].vlan_id
;
607 case QLCNIC_DEL_VLAN
:
616 static ssize_t
qlcnic_sysfs_read_esw_config(struct file
*file
,
617 struct kobject
*kobj
,
618 struct bin_attribute
*attr
,
619 char *buf
, loff_t offset
,
622 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
623 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
624 struct qlcnic_esw_func_cfg
*esw_cfg
;
629 memset(buf
, 0, size
);
630 esw_cfg
= (struct qlcnic_esw_func_cfg
*)buf
;
631 count
= size
/ sizeof(struct qlcnic_esw_func_cfg
);
632 for (i
= 0; i
< adapter
->ahw
->total_nic_func
; i
++) {
633 pci_func
= adapter
->npars
[i
].pci_func
;
634 if (pci_func
>= count
) {
635 dev_dbg(dev
, "%s: Total nic functions[%d], App sent function count[%d]\n",
636 __func__
, adapter
->ahw
->total_nic_func
, count
);
639 if (!adapter
->npars
[i
].eswitch_status
)
642 esw_cfg
[pci_func
].pci_func
= pci_func
;
643 if (qlcnic_get_eswitch_port_config(adapter
, &esw_cfg
[pci_func
]))
644 return QL_STATUS_INVALID_PARAM
;
649 static int validate_npar_config(struct qlcnic_adapter
*adapter
,
650 struct qlcnic_npar_func_cfg
*np_cfg
,
655 for (i
= 0; i
< count
; i
++) {
656 pci_func
= np_cfg
[i
].pci_func
;
657 if (qlcnic_is_valid_nic_func(adapter
, pci_func
) < 0)
658 return QL_STATUS_INVALID_PARAM
;
660 if (!IS_VALID_BW(np_cfg
[i
].min_bw
) ||
661 !IS_VALID_BW(np_cfg
[i
].max_bw
))
662 return QL_STATUS_INVALID_PARAM
;
667 static ssize_t
qlcnic_sysfs_write_npar_config(struct file
*file
,
668 struct kobject
*kobj
,
669 struct bin_attribute
*attr
,
670 char *buf
, loff_t offset
,
673 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
674 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
675 struct qlcnic_info nic_info
;
676 struct qlcnic_npar_func_cfg
*np_cfg
;
677 int i
, count
, rem
, ret
, index
;
680 count
= size
/ sizeof(struct qlcnic_npar_func_cfg
);
681 rem
= size
% sizeof(struct qlcnic_npar_func_cfg
);
683 return QL_STATUS_INVALID_PARAM
;
685 np_cfg
= (struct qlcnic_npar_func_cfg
*)buf
;
686 ret
= validate_npar_config(adapter
, np_cfg
, count
);
690 for (i
= 0; i
< count
; i
++) {
691 pci_func
= np_cfg
[i
].pci_func
;
693 memset(&nic_info
, 0, sizeof(struct qlcnic_info
));
694 ret
= qlcnic_get_nic_info(adapter
, &nic_info
, pci_func
);
697 nic_info
.pci_func
= pci_func
;
698 nic_info
.min_tx_bw
= np_cfg
[i
].min_bw
;
699 nic_info
.max_tx_bw
= np_cfg
[i
].max_bw
;
700 ret
= qlcnic_set_nic_info(adapter
, &nic_info
);
703 index
= qlcnic_is_valid_nic_func(adapter
, pci_func
);
705 return QL_STATUS_INVALID_PARAM
;
706 adapter
->npars
[index
].min_bw
= nic_info
.min_tx_bw
;
707 adapter
->npars
[index
].max_bw
= nic_info
.max_tx_bw
;
713 static ssize_t
qlcnic_sysfs_read_npar_config(struct file
*file
,
714 struct kobject
*kobj
,
715 struct bin_attribute
*attr
,
716 char *buf
, loff_t offset
,
719 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
720 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
721 struct qlcnic_npar_func_cfg
*np_cfg
;
722 struct qlcnic_info nic_info
;
727 memset(&nic_info
, 0, sizeof(struct qlcnic_info
));
728 memset(buf
, 0, size
);
729 np_cfg
= (struct qlcnic_npar_func_cfg
*)buf
;
731 count
= size
/ sizeof(struct qlcnic_npar_func_cfg
);
732 for (i
= 0; i
< adapter
->ahw
->total_nic_func
; i
++) {
733 if (adapter
->npars
[i
].pci_func
>= count
) {
734 dev_dbg(dev
, "%s: Total nic functions[%d], App sent function count[%d]\n",
735 __func__
, adapter
->ahw
->total_nic_func
, count
);
738 if (!adapter
->npars
[i
].eswitch_status
)
740 pci_func
= adapter
->npars
[i
].pci_func
;
741 if (qlcnic_is_valid_nic_func(adapter
, pci_func
) < 0)
743 ret
= qlcnic_get_nic_info(adapter
, &nic_info
, pci_func
);
747 np_cfg
[pci_func
].pci_func
= pci_func
;
748 np_cfg
[pci_func
].op_mode
= (u8
)nic_info
.op_mode
;
749 np_cfg
[pci_func
].port_num
= nic_info
.phys_port
;
750 np_cfg
[pci_func
].fw_capab
= nic_info
.capabilities
;
751 np_cfg
[pci_func
].min_bw
= nic_info
.min_tx_bw
;
752 np_cfg
[pci_func
].max_bw
= nic_info
.max_tx_bw
;
753 np_cfg
[pci_func
].max_tx_queues
= nic_info
.max_tx_ques
;
754 np_cfg
[pci_func
].max_rx_queues
= nic_info
.max_rx_ques
;
759 static ssize_t
qlcnic_sysfs_get_port_stats(struct file
*file
,
760 struct kobject
*kobj
,
761 struct bin_attribute
*attr
,
762 char *buf
, loff_t offset
,
765 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
766 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
767 struct qlcnic_esw_statistics port_stats
;
770 if (qlcnic_83xx_check(adapter
))
771 return QLC_STATUS_UNSUPPORTED_CMD
;
773 if (size
!= sizeof(struct qlcnic_esw_statistics
))
774 return QL_STATUS_INVALID_PARAM
;
776 if (offset
>= adapter
->ahw
->max_vnic_func
)
777 return QL_STATUS_INVALID_PARAM
;
779 memset(&port_stats
, 0, size
);
780 ret
= qlcnic_get_port_stats(adapter
, offset
, QLCNIC_QUERY_RX_COUNTER
,
785 ret
= qlcnic_get_port_stats(adapter
, offset
, QLCNIC_QUERY_TX_COUNTER
,
790 memcpy(buf
, &port_stats
, size
);
794 static ssize_t
qlcnic_sysfs_get_esw_stats(struct file
*file
,
795 struct kobject
*kobj
,
796 struct bin_attribute
*attr
,
797 char *buf
, loff_t offset
,
800 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
801 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
802 struct qlcnic_esw_statistics esw_stats
;
805 if (qlcnic_83xx_check(adapter
))
806 return QLC_STATUS_UNSUPPORTED_CMD
;
808 if (size
!= sizeof(struct qlcnic_esw_statistics
))
809 return QL_STATUS_INVALID_PARAM
;
811 if (offset
>= QLCNIC_NIU_MAX_XG_PORTS
)
812 return QL_STATUS_INVALID_PARAM
;
814 memset(&esw_stats
, 0, size
);
815 ret
= qlcnic_get_eswitch_stats(adapter
, offset
, QLCNIC_QUERY_RX_COUNTER
,
820 ret
= qlcnic_get_eswitch_stats(adapter
, offset
, QLCNIC_QUERY_TX_COUNTER
,
825 memcpy(buf
, &esw_stats
, size
);
829 static ssize_t
qlcnic_sysfs_clear_esw_stats(struct file
*file
,
830 struct kobject
*kobj
,
831 struct bin_attribute
*attr
,
832 char *buf
, loff_t offset
,
835 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
836 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
839 if (qlcnic_83xx_check(adapter
))
840 return QLC_STATUS_UNSUPPORTED_CMD
;
842 if (offset
>= QLCNIC_NIU_MAX_XG_PORTS
)
843 return QL_STATUS_INVALID_PARAM
;
845 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_ESWITCH
, offset
,
846 QLCNIC_QUERY_RX_COUNTER
);
850 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_ESWITCH
, offset
,
851 QLCNIC_QUERY_TX_COUNTER
);
858 static ssize_t
qlcnic_sysfs_clear_port_stats(struct file
*file
,
859 struct kobject
*kobj
,
860 struct bin_attribute
*attr
,
861 char *buf
, loff_t offset
,
865 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
866 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
869 if (qlcnic_83xx_check(adapter
))
870 return QLC_STATUS_UNSUPPORTED_CMD
;
872 if (offset
>= adapter
->ahw
->max_vnic_func
)
873 return QL_STATUS_INVALID_PARAM
;
875 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_PORT
, offset
,
876 QLCNIC_QUERY_RX_COUNTER
);
880 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_PORT
, offset
,
881 QLCNIC_QUERY_TX_COUNTER
);
888 static ssize_t
qlcnic_sysfs_read_pci_config(struct file
*file
,
889 struct kobject
*kobj
,
890 struct bin_attribute
*attr
,
891 char *buf
, loff_t offset
,
894 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
895 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
896 struct qlcnic_pci_func_cfg
*pci_cfg
;
897 struct qlcnic_pci_info
*pci_info
;
901 pci_info
= kcalloc(size
, sizeof(*pci_info
), GFP_KERNEL
);
905 ret
= qlcnic_get_pci_info(adapter
, pci_info
);
911 pci_cfg
= (struct qlcnic_pci_func_cfg
*)buf
;
912 count
= size
/ sizeof(struct qlcnic_pci_func_cfg
);
913 for (i
= 0; i
< count
; i
++) {
914 pci_cfg
[i
].pci_func
= pci_info
[i
].id
;
915 pci_cfg
[i
].func_type
= pci_info
[i
].type
;
916 pci_cfg
[i
].func_state
= 0;
917 pci_cfg
[i
].port_num
= pci_info
[i
].default_port
;
918 pci_cfg
[i
].min_bw
= pci_info
[i
].tx_min_bw
;
919 pci_cfg
[i
].max_bw
= pci_info
[i
].tx_max_bw
;
920 memcpy(&pci_cfg
[i
].def_mac_addr
, &pci_info
[i
].mac
, ETH_ALEN
);
927 static ssize_t
qlcnic_83xx_sysfs_flash_read_handler(struct file
*filp
,
928 struct kobject
*kobj
,
929 struct bin_attribute
*attr
,
930 char *buf
, loff_t offset
,
933 unsigned char *p_read_buf
;
935 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
936 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
939 return QL_STATUS_INVALID_PARAM
;
941 return QL_STATUS_INVALID_PARAM
;
943 count
= size
/ sizeof(u32
);
945 if (size
% sizeof(u32
))
948 p_read_buf
= kcalloc(size
, sizeof(unsigned char), GFP_KERNEL
);
951 if (qlcnic_83xx_lock_flash(adapter
) != 0) {
956 ret
= qlcnic_83xx_lockless_flash_read32(adapter
, offset
, p_read_buf
,
960 qlcnic_83xx_unlock_flash(adapter
);
965 qlcnic_83xx_unlock_flash(adapter
);
966 memcpy(buf
, p_read_buf
, size
);
972 static int qlcnic_83xx_sysfs_flash_bulk_write(struct qlcnic_adapter
*adapter
,
973 char *buf
, loff_t offset
,
977 unsigned char *p_cache
, *p_src
;
979 p_cache
= kcalloc(size
, sizeof(unsigned char), GFP_KERNEL
);
983 memcpy(p_cache
, buf
, size
);
985 count
= size
/ sizeof(u32
);
987 if (qlcnic_83xx_lock_flash(adapter
) != 0) {
992 if (adapter
->ahw
->fdt
.mfg_id
== adapter
->flash_mfg_id
) {
993 ret
= qlcnic_83xx_enable_flash_write(adapter
);
996 qlcnic_83xx_unlock_flash(adapter
);
1001 for (i
= 0; i
< count
/ QLC_83XX_FLASH_WRITE_MAX
; i
++) {
1002 ret
= qlcnic_83xx_flash_bulk_write(adapter
, offset
,
1004 QLC_83XX_FLASH_WRITE_MAX
);
1007 if (adapter
->ahw
->fdt
.mfg_id
== adapter
->flash_mfg_id
) {
1008 ret
= qlcnic_83xx_disable_flash_write(adapter
);
1011 qlcnic_83xx_unlock_flash(adapter
);
1017 qlcnic_83xx_unlock_flash(adapter
);
1021 p_src
= p_src
+ sizeof(u32
)*QLC_83XX_FLASH_WRITE_MAX
;
1022 offset
= offset
+ sizeof(u32
)*QLC_83XX_FLASH_WRITE_MAX
;
1025 if (adapter
->ahw
->fdt
.mfg_id
== adapter
->flash_mfg_id
) {
1026 ret
= qlcnic_83xx_disable_flash_write(adapter
);
1029 qlcnic_83xx_unlock_flash(adapter
);
1035 qlcnic_83xx_unlock_flash(adapter
);
1040 static int qlcnic_83xx_sysfs_flash_write(struct qlcnic_adapter
*adapter
,
1041 char *buf
, loff_t offset
, size_t size
)
1044 unsigned char *p_cache
, *p_src
;
1046 p_cache
= kcalloc(size
, sizeof(unsigned char), GFP_KERNEL
);
1050 memcpy(p_cache
, buf
, size
);
1052 count
= size
/ sizeof(u32
);
1054 if (qlcnic_83xx_lock_flash(adapter
) != 0) {
1059 if (adapter
->ahw
->fdt
.mfg_id
== adapter
->flash_mfg_id
) {
1060 ret
= qlcnic_83xx_enable_flash_write(adapter
);
1063 qlcnic_83xx_unlock_flash(adapter
);
1068 for (i
= 0; i
< count
; i
++) {
1069 ret
= qlcnic_83xx_flash_write32(adapter
, offset
, (u32
*)p_src
);
1071 if (adapter
->ahw
->fdt
.mfg_id
== adapter
->flash_mfg_id
) {
1072 ret
= qlcnic_83xx_disable_flash_write(adapter
);
1075 qlcnic_83xx_unlock_flash(adapter
);
1080 qlcnic_83xx_unlock_flash(adapter
);
1084 p_src
= p_src
+ sizeof(u32
);
1085 offset
= offset
+ sizeof(u32
);
1088 if (adapter
->ahw
->fdt
.mfg_id
== adapter
->flash_mfg_id
) {
1089 ret
= qlcnic_83xx_disable_flash_write(adapter
);
1092 qlcnic_83xx_unlock_flash(adapter
);
1098 qlcnic_83xx_unlock_flash(adapter
);
1103 static ssize_t
qlcnic_83xx_sysfs_flash_write_handler(struct file
*filp
,
1104 struct kobject
*kobj
,
1105 struct bin_attribute
*attr
,
1106 char *buf
, loff_t offset
,
1110 static int flash_mode
;
1112 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
1113 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
1116 return QL_STATUS_INVALID_PARAM
;
1118 ret
= kstrtoul(buf
, 16, &data
);
1121 case QLC_83XX_FLASH_SECTOR_ERASE_CMD
:
1122 flash_mode
= QLC_83XX_ERASE_MODE
;
1123 ret
= qlcnic_83xx_erase_flash_sector(adapter
, offset
);
1125 dev_err(&adapter
->pdev
->dev
,
1126 "%s failed at %d\n", __func__
, __LINE__
);
1131 case QLC_83XX_FLASH_BULK_WRITE_CMD
:
1132 flash_mode
= QLC_83XX_BULK_WRITE_MODE
;
1135 case QLC_83XX_FLASH_WRITE_CMD
:
1136 flash_mode
= QLC_83XX_WRITE_MODE
;
1139 if (flash_mode
== QLC_83XX_BULK_WRITE_MODE
) {
1140 ret
= qlcnic_83xx_sysfs_flash_bulk_write(adapter
, buf
,
1143 dev_err(&adapter
->pdev
->dev
,
1144 "%s failed at %d\n",
1145 __func__
, __LINE__
);
1150 if (flash_mode
== QLC_83XX_WRITE_MODE
) {
1151 ret
= qlcnic_83xx_sysfs_flash_write(adapter
, buf
,
1154 dev_err(&adapter
->pdev
->dev
,
1155 "%s failed at %d\n", __func__
,
1165 static struct device_attribute dev_attr_bridged_mode
= {
1166 .attr
= {.name
= "bridged_mode", .mode
= (S_IRUGO
| S_IWUSR
)},
1167 .show
= qlcnic_show_bridged_mode
,
1168 .store
= qlcnic_store_bridged_mode
,
1171 static struct device_attribute dev_attr_diag_mode
= {
1172 .attr
= {.name
= "diag_mode", .mode
= (S_IRUGO
| S_IWUSR
)},
1173 .show
= qlcnic_show_diag_mode
,
1174 .store
= qlcnic_store_diag_mode
,
1177 static struct device_attribute dev_attr_beacon
= {
1178 .attr
= {.name
= "beacon", .mode
= (S_IRUGO
| S_IWUSR
)},
1179 .show
= qlcnic_show_beacon
,
1180 .store
= qlcnic_store_beacon
,
1183 static struct bin_attribute bin_attr_crb
= {
1184 .attr
= {.name
= "crb", .mode
= (S_IRUGO
| S_IWUSR
)},
1186 .read
= qlcnic_sysfs_read_crb
,
1187 .write
= qlcnic_sysfs_write_crb
,
1190 static struct bin_attribute bin_attr_mem
= {
1191 .attr
= {.name
= "mem", .mode
= (S_IRUGO
| S_IWUSR
)},
1193 .read
= qlcnic_sysfs_read_mem
,
1194 .write
= qlcnic_sysfs_write_mem
,
1197 static struct bin_attribute bin_attr_npar_config
= {
1198 .attr
= {.name
= "npar_config", .mode
= (S_IRUGO
| S_IWUSR
)},
1200 .read
= qlcnic_sysfs_read_npar_config
,
1201 .write
= qlcnic_sysfs_write_npar_config
,
1204 static struct bin_attribute bin_attr_pci_config
= {
1205 .attr
= {.name
= "pci_config", .mode
= (S_IRUGO
| S_IWUSR
)},
1207 .read
= qlcnic_sysfs_read_pci_config
,
1211 static struct bin_attribute bin_attr_port_stats
= {
1212 .attr
= {.name
= "port_stats", .mode
= (S_IRUGO
| S_IWUSR
)},
1214 .read
= qlcnic_sysfs_get_port_stats
,
1215 .write
= qlcnic_sysfs_clear_port_stats
,
1218 static struct bin_attribute bin_attr_esw_stats
= {
1219 .attr
= {.name
= "esw_stats", .mode
= (S_IRUGO
| S_IWUSR
)},
1221 .read
= qlcnic_sysfs_get_esw_stats
,
1222 .write
= qlcnic_sysfs_clear_esw_stats
,
1225 static struct bin_attribute bin_attr_esw_config
= {
1226 .attr
= {.name
= "esw_config", .mode
= (S_IRUGO
| S_IWUSR
)},
1228 .read
= qlcnic_sysfs_read_esw_config
,
1229 .write
= qlcnic_sysfs_write_esw_config
,
1232 static struct bin_attribute bin_attr_pm_config
= {
1233 .attr
= {.name
= "pm_config", .mode
= (S_IRUGO
| S_IWUSR
)},
1235 .read
= qlcnic_sysfs_read_pm_config
,
1236 .write
= qlcnic_sysfs_write_pm_config
,
1239 static struct bin_attribute bin_attr_flash
= {
1240 .attr
= {.name
= "flash", .mode
= (S_IRUGO
| S_IWUSR
)},
1242 .read
= qlcnic_83xx_sysfs_flash_read_handler
,
1243 .write
= qlcnic_83xx_sysfs_flash_write_handler
,
1246 void qlcnic_create_sysfs_entries(struct qlcnic_adapter
*adapter
)
1248 struct device
*dev
= &adapter
->pdev
->dev
;
1250 if (adapter
->ahw
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
)
1251 if (device_create_file(dev
, &dev_attr_bridged_mode
))
1253 "failed to create bridged_mode sysfs entry\n");
1256 void qlcnic_remove_sysfs_entries(struct qlcnic_adapter
*adapter
)
1258 struct device
*dev
= &adapter
->pdev
->dev
;
1260 if (adapter
->ahw
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
)
1261 device_remove_file(dev
, &dev_attr_bridged_mode
);
1264 static void qlcnic_create_diag_entries(struct qlcnic_adapter
*adapter
)
1266 struct device
*dev
= &adapter
->pdev
->dev
;
1268 if (device_create_bin_file(dev
, &bin_attr_port_stats
))
1269 dev_info(dev
, "failed to create port stats sysfs entry");
1271 if (adapter
->ahw
->op_mode
== QLCNIC_NON_PRIV_FUNC
)
1273 if (device_create_file(dev
, &dev_attr_diag_mode
))
1274 dev_info(dev
, "failed to create diag_mode sysfs entry\n");
1275 if (device_create_bin_file(dev
, &bin_attr_crb
))
1276 dev_info(dev
, "failed to create crb sysfs entry\n");
1277 if (device_create_bin_file(dev
, &bin_attr_mem
))
1278 dev_info(dev
, "failed to create mem sysfs entry\n");
1280 if (test_bit(__QLCNIC_MAINTENANCE_MODE
, &adapter
->state
))
1283 if (device_create_bin_file(dev
, &bin_attr_pci_config
))
1284 dev_info(dev
, "failed to create pci config sysfs entry");
1286 if (device_create_file(dev
, &dev_attr_beacon
))
1287 dev_info(dev
, "failed to create beacon sysfs entry");
1289 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
))
1291 if (device_create_bin_file(dev
, &bin_attr_esw_config
))
1292 dev_info(dev
, "failed to create esw config sysfs entry");
1293 if (adapter
->ahw
->op_mode
!= QLCNIC_MGMT_FUNC
)
1295 if (device_create_bin_file(dev
, &bin_attr_npar_config
))
1296 dev_info(dev
, "failed to create npar config sysfs entry");
1297 if (device_create_bin_file(dev
, &bin_attr_pm_config
))
1298 dev_info(dev
, "failed to create pm config sysfs entry");
1299 if (device_create_bin_file(dev
, &bin_attr_esw_stats
))
1300 dev_info(dev
, "failed to create eswitch stats sysfs entry");
1303 static void qlcnic_remove_diag_entries(struct qlcnic_adapter
*adapter
)
1305 struct device
*dev
= &adapter
->pdev
->dev
;
1307 device_remove_bin_file(dev
, &bin_attr_port_stats
);
1309 if (adapter
->ahw
->op_mode
== QLCNIC_NON_PRIV_FUNC
)
1311 device_remove_file(dev
, &dev_attr_diag_mode
);
1312 device_remove_bin_file(dev
, &bin_attr_crb
);
1313 device_remove_bin_file(dev
, &bin_attr_mem
);
1315 if (test_bit(__QLCNIC_MAINTENANCE_MODE
, &adapter
->state
))
1318 device_remove_bin_file(dev
, &bin_attr_pci_config
);
1319 device_remove_file(dev
, &dev_attr_beacon
);
1320 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
))
1322 device_remove_bin_file(dev
, &bin_attr_esw_config
);
1323 if (adapter
->ahw
->op_mode
!= QLCNIC_MGMT_FUNC
)
1325 device_remove_bin_file(dev
, &bin_attr_npar_config
);
1326 device_remove_bin_file(dev
, &bin_attr_pm_config
);
1327 device_remove_bin_file(dev
, &bin_attr_esw_stats
);
1330 void qlcnic_82xx_add_sysfs(struct qlcnic_adapter
*adapter
)
1332 qlcnic_create_diag_entries(adapter
);
1335 void qlcnic_82xx_remove_sysfs(struct qlcnic_adapter
*adapter
)
1337 qlcnic_remove_diag_entries(adapter
);
1340 void qlcnic_83xx_add_sysfs(struct qlcnic_adapter
*adapter
)
1342 struct device
*dev
= &adapter
->pdev
->dev
;
1344 qlcnic_create_diag_entries(adapter
);
1346 if (sysfs_create_bin_file(&dev
->kobj
, &bin_attr_flash
))
1347 dev_info(dev
, "failed to create flash sysfs entry\n");
1350 void qlcnic_83xx_remove_sysfs(struct qlcnic_adapter
*adapter
)
1352 struct device
*dev
= &adapter
->pdev
->dev
;
1354 qlcnic_remove_diag_entries(adapter
);
1355 sysfs_remove_bin_file(&dev
->kobj
, &bin_attr_flash
);