Skip to content

Commit d14807d

Browse files
Hariprasad Shenaidavem330
authored andcommitted
cxgb4: Much cleaner implementation of is_t4()/is_t5()
Signed-off-by: Hariprasad Shenai <hariprasad@chelsio.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 1b85ee0 commit d14807d

File tree

5 files changed

+73
-70
lines changed

5 files changed

+73
-70
lines changed

drivers/net/ethernet/chelsio/cxgb4/cxgb4.h

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,26 @@ struct pci_params {
240240
unsigned char width;
241241
};
242242

243+
#define CHELSIO_CHIP_CODE(version, revision) (((version) << 4) | (revision))
244+
#define CHELSIO_CHIP_FPGA 0x100
245+
#define CHELSIO_CHIP_VERSION(code) (((code) >> 4) & 0xf)
246+
#define CHELSIO_CHIP_RELEASE(code) ((code) & 0xf)
247+
248+
#define CHELSIO_T4 0x4
249+
#define CHELSIO_T5 0x5
250+
251+
enum chip_type {
252+
T4_A1 = CHELSIO_CHIP_CODE(CHELSIO_T4, 1),
253+
T4_A2 = CHELSIO_CHIP_CODE(CHELSIO_T4, 2),
254+
T4_FIRST_REV = T4_A1,
255+
T4_LAST_REV = T4_A2,
256+
257+
T5_A0 = CHELSIO_CHIP_CODE(CHELSIO_T5, 0),
258+
T5_A1 = CHELSIO_CHIP_CODE(CHELSIO_T5, 1),
259+
T5_FIRST_REV = T5_A0,
260+
T5_LAST_REV = T5_A1,
261+
};
262+
243263
struct adapter_params {
244264
struct tp_params tp;
245265
struct vpd_params vpd;
@@ -259,7 +279,7 @@ struct adapter_params {
259279

260280
unsigned char nports; /* # of ethernet ports */
261281
unsigned char portvec;
262-
unsigned char rev; /* chip revision */
282+
enum chip_type chip; /* chip code */
263283
unsigned char offload;
264284

265285
unsigned char bypass;
@@ -512,25 +532,6 @@ struct sge {
512532

513533
struct l2t_data;
514534

515-
#define CHELSIO_CHIP_CODE(version, revision) (((version) << 4) | (revision))
516-
#define CHELSIO_CHIP_VERSION(code) ((code) >> 4)
517-
#define CHELSIO_CHIP_RELEASE(code) ((code) & 0xf)
518-
519-
#define CHELSIO_T4 0x4
520-
#define CHELSIO_T5 0x5
521-
522-
enum chip_type {
523-
T4_A1 = CHELSIO_CHIP_CODE(CHELSIO_T4, 0),
524-
T4_A2 = CHELSIO_CHIP_CODE(CHELSIO_T4, 1),
525-
T4_A3 = CHELSIO_CHIP_CODE(CHELSIO_T4, 2),
526-
T4_FIRST_REV = T4_A1,
527-
T4_LAST_REV = T4_A3,
528-
529-
T5_A1 = CHELSIO_CHIP_CODE(CHELSIO_T5, 0),
530-
T5_FIRST_REV = T5_A1,
531-
T5_LAST_REV = T5_A1,
532-
};
533-
534535
#ifdef CONFIG_PCI_IOV
535536

536537
/* T4 supports SRIOV on PF0-3 and T5 on PF0-7. However, the Serial
@@ -715,12 +716,12 @@ enum {
715716

716717
static inline int is_t5(enum chip_type chip)
717718
{
718-
return (chip >= T5_FIRST_REV && chip <= T5_LAST_REV);
719+
return CHELSIO_CHIP_VERSION(chip) == CHELSIO_T5;
719720
}
720721

721722
static inline int is_t4(enum chip_type chip)
722723
{
723-
return (chip >= T4_FIRST_REV && chip <= T4_LAST_REV);
724+
return CHELSIO_CHIP_VERSION(chip) == CHELSIO_T4;
724725
}
725726

726727
static inline u32 t4_read_reg(struct adapter *adap, u32 reg_addr)

drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@ static int upgrade_fw(struct adapter *adap)
10831083
struct device *dev = adap->pdev_dev;
10841084
char *fw_file_name;
10851085

1086-
switch (CHELSIO_CHIP_VERSION(adap->chip)) {
1086+
switch (CHELSIO_CHIP_VERSION(adap->params.chip)) {
10871087
case CHELSIO_T4:
10881088
fw_file_name = FW_FNAME;
10891089
exp_major = FW_VERSION_MAJOR;
@@ -1093,7 +1093,7 @@ static int upgrade_fw(struct adapter *adap)
10931093
exp_major = FW_VERSION_MAJOR_T5;
10941094
break;
10951095
default:
1096-
dev_err(dev, "Unsupported chip type, %x\n", adap->chip);
1096+
dev_err(dev, "Unsupported chip type, %x\n", adap->params.chip);
10971097
return -EINVAL;
10981098
}
10991099

@@ -1415,7 +1415,7 @@ static int get_sset_count(struct net_device *dev, int sset)
14151415
static int get_regs_len(struct net_device *dev)
14161416
{
14171417
struct adapter *adap = netdev2adap(dev);
1418-
if (is_t4(adap->chip))
1418+
if (is_t4(adap->params.chip))
14191419
return T4_REGMAP_SIZE;
14201420
else
14211421
return T5_REGMAP_SIZE;
@@ -1499,7 +1499,7 @@ static void get_stats(struct net_device *dev, struct ethtool_stats *stats,
14991499
data += sizeof(struct port_stats) / sizeof(u64);
15001500
collect_sge_port_stats(adapter, pi, (struct queue_port_stats *)data);
15011501
data += sizeof(struct queue_port_stats) / sizeof(u64);
1502-
if (!is_t4(adapter->chip)) {
1502+
if (!is_t4(adapter->params.chip)) {
15031503
t4_write_reg(adapter, SGE_STAT_CFG, STATSOURCE_T5(7));
15041504
val1 = t4_read_reg(adapter, SGE_STAT_TOTAL);
15051505
val2 = t4_read_reg(adapter, SGE_STAT_MATCH);
@@ -1521,8 +1521,8 @@ static void get_stats(struct net_device *dev, struct ethtool_stats *stats,
15211521
*/
15221522
static inline unsigned int mk_adap_vers(const struct adapter *ap)
15231523
{
1524-
return CHELSIO_CHIP_VERSION(ap->chip) |
1525-
(CHELSIO_CHIP_RELEASE(ap->chip) << 10) | (1 << 16);
1524+
return CHELSIO_CHIP_VERSION(ap->params.chip) |
1525+
(CHELSIO_CHIP_RELEASE(ap->params.chip) << 10) | (1 << 16);
15261526
}
15271527

15281528
static void reg_block_dump(struct adapter *ap, void *buf, unsigned int start,
@@ -2189,7 +2189,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
21892189
static const unsigned int *reg_ranges;
21902190
int arr_size = 0, buf_size = 0;
21912191

2192-
if (is_t4(ap->chip)) {
2192+
if (is_t4(ap->params.chip)) {
21932193
reg_ranges = &t4_reg_ranges[0];
21942194
arr_size = ARRAY_SIZE(t4_reg_ranges);
21952195
buf_size = T4_REGMAP_SIZE;
@@ -2967,7 +2967,7 @@ static int setup_debugfs(struct adapter *adap)
29672967
size = t4_read_reg(adap, MA_EDRAM1_BAR);
29682968
add_debugfs_mem(adap, "edc1", MEM_EDC1, EDRAM_SIZE_GET(size));
29692969
}
2970-
if (is_t4(adap->chip)) {
2970+
if (is_t4(adap->params.chip)) {
29712971
size = t4_read_reg(adap, MA_EXT_MEMORY_BAR);
29722972
if (i & EXT_MEM_ENABLE)
29732973
add_debugfs_mem(adap, "mc", MEM_MC,
@@ -3419,7 +3419,7 @@ unsigned int cxgb4_dbfifo_count(const struct net_device *dev, int lpfifo)
34193419

34203420
v1 = t4_read_reg(adap, A_SGE_DBFIFO_STATUS);
34213421
v2 = t4_read_reg(adap, SGE_DBFIFO_STATUS2);
3422-
if (is_t4(adap->chip)) {
3422+
if (is_t4(adap->params.chip)) {
34233423
lp_count = G_LP_COUNT(v1);
34243424
hp_count = G_HP_COUNT(v1);
34253425
} else {
@@ -3588,7 +3588,7 @@ static void drain_db_fifo(struct adapter *adap, int usecs)
35883588
do {
35893589
v1 = t4_read_reg(adap, A_SGE_DBFIFO_STATUS);
35903590
v2 = t4_read_reg(adap, SGE_DBFIFO_STATUS2);
3591-
if (is_t4(adap->chip)) {
3591+
if (is_t4(adap->params.chip)) {
35923592
lp_count = G_LP_COUNT(v1);
35933593
hp_count = G_HP_COUNT(v1);
35943594
} else {
@@ -3708,7 +3708,7 @@ static void process_db_drop(struct work_struct *work)
37083708

37093709
adap = container_of(work, struct adapter, db_drop_task);
37103710

3711-
if (is_t4(adap->chip)) {
3711+
if (is_t4(adap->params.chip)) {
37123712
disable_dbs(adap);
37133713
notify_rdma_uld(adap, CXGB4_CONTROL_DB_DROP);
37143714
drain_db_fifo(adap, 1);
@@ -3753,7 +3753,7 @@ static void process_db_drop(struct work_struct *work)
37533753

37543754
void t4_db_full(struct adapter *adap)
37553755
{
3756-
if (is_t4(adap->chip)) {
3756+
if (is_t4(adap->params.chip)) {
37573757
t4_set_reg_field(adap, SGE_INT_ENABLE3,
37583758
DBFIFO_HP_INT | DBFIFO_LP_INT, 0);
37593759
queue_work(workq, &adap->db_full_task);
@@ -3762,7 +3762,7 @@ void t4_db_full(struct adapter *adap)
37623762

37633763
void t4_db_dropped(struct adapter *adap)
37643764
{
3765-
if (is_t4(adap->chip))
3765+
if (is_t4(adap->params.chip))
37663766
queue_work(workq, &adap->db_drop_task);
37673767
}
37683768

@@ -3789,7 +3789,7 @@ static void uld_attach(struct adapter *adap, unsigned int uld)
37893789
lli.nchan = adap->params.nports;
37903790
lli.nports = adap->params.nports;
37913791
lli.wr_cred = adap->params.ofldq_wr_cred;
3792-
lli.adapter_type = adap->params.rev;
3792+
lli.adapter_type = adap->params.chip;
37933793
lli.iscsi_iolen = MAXRXDATA_GET(t4_read_reg(adap, TP_PARA_REG2));
37943794
lli.udb_density = 1 << QUEUESPERPAGEPF0_GET(
37953795
t4_read_reg(adap, SGE_EGRESS_QUEUES_PER_PAGE_PF) >>
@@ -4483,7 +4483,7 @@ static void setup_memwin(struct adapter *adap)
44834483
u32 bar0, mem_win0_base, mem_win1_base, mem_win2_base;
44844484

44854485
bar0 = pci_resource_start(adap->pdev, 0); /* truncation intentional */
4486-
if (is_t4(adap->chip)) {
4486+
if (is_t4(adap->params.chip)) {
44874487
mem_win0_base = bar0 + MEMWIN0_BASE;
44884488
mem_win1_base = bar0 + MEMWIN1_BASE;
44894489
mem_win2_base = bar0 + MEMWIN2_BASE;
@@ -4686,7 +4686,7 @@ static int adap_init0_config(struct adapter *adapter, int reset)
46864686
* then use that. Otherwise, use the configuration file stored
46874687
* in the adapter flash ...
46884688
*/
4689-
switch (CHELSIO_CHIP_VERSION(adapter->chip)) {
4689+
switch (CHELSIO_CHIP_VERSION(adapter->params.chip)) {
46904690
case CHELSIO_T4:
46914691
fw_config_file = FW_CFNAME;
46924692
break;
@@ -5787,7 +5787,7 @@ static void print_port_info(const struct net_device *dev)
57875787

57885788
netdev_info(dev, "Chelsio %s rev %d %s %sNIC PCIe x%d%s%s\n",
57895789
adap->params.vpd.id,
5790-
CHELSIO_CHIP_RELEASE(adap->params.rev), buf,
5790+
CHELSIO_CHIP_RELEASE(adap->params.chip), buf,
57915791
is_offload(adap) ? "R" : "", adap->params.pci.width, spd,
57925792
(adap->flags & USING_MSIX) ? " MSI-X" :
57935793
(adap->flags & USING_MSI) ? " MSI" : "");
@@ -5910,7 +5910,7 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
59105910
if (err)
59115911
goto out_unmap_bar0;
59125912

5913-
if (!is_t4(adapter->chip)) {
5913+
if (!is_t4(adapter->params.chip)) {
59145914
s_qpp = QUEUESPERPAGEPF1 * adapter->fn;
59155915
qpp = 1 << QUEUESPERPAGEPF0_GET(t4_read_reg(adapter,
59165916
SGE_EGRESS_QUEUES_PER_PAGE_PF) >> s_qpp);
@@ -6064,7 +6064,7 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
60646064
out_free_dev:
60656065
free_some_resources(adapter);
60666066
out_unmap_bar:
6067-
if (!is_t4(adapter->chip))
6067+
if (!is_t4(adapter->params.chip))
60686068
iounmap(adapter->bar2);
60696069
out_unmap_bar0:
60706070
iounmap(adapter->regs);
@@ -6116,7 +6116,7 @@ static void remove_one(struct pci_dev *pdev)
61166116

61176117
free_some_resources(adapter);
61186118
iounmap(adapter->regs);
6119-
if (!is_t4(adapter->chip))
6119+
if (!is_t4(adapter->params.chip))
61206120
iounmap(adapter->bar2);
61216121
kfree(adapter);
61226122
pci_disable_pcie_error_reporting(pdev);

drivers/net/ethernet/chelsio/cxgb4/sge.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ static inline void ring_fl_db(struct adapter *adap, struct sge_fl *q)
509509
u32 val;
510510
if (q->pend_cred >= 8) {
511511
val = PIDX(q->pend_cred / 8);
512-
if (!is_t4(adap->chip))
512+
if (!is_t4(adap->params.chip))
513513
val |= DBTYPE(1);
514514
wmb();
515515
t4_write_reg(adap, MYPF_REG(SGE_PF_KDOORBELL), DBPRIO(1) |
@@ -847,7 +847,7 @@ static inline void ring_tx_db(struct adapter *adap, struct sge_txq *q, int n)
847847
wmb(); /* write descriptors before telling HW */
848848
spin_lock(&q->db_lock);
849849
if (!q->db_disabled) {
850-
if (is_t4(adap->chip)) {
850+
if (is_t4(adap->params.chip)) {
851851
t4_write_reg(adap, MYPF_REG(SGE_PF_KDOORBELL),
852852
QID(q->cntxt_id) | PIDX(n));
853853
} else {
@@ -1596,7 +1596,7 @@ static noinline int handle_trace_pkt(struct adapter *adap,
15961596
return 0;
15971597
}
15981598

1599-
if (is_t4(adap->chip))
1599+
if (is_t4(adap->params.chip))
16001600
__skb_pull(skb, sizeof(struct cpl_trace_pkt));
16011601
else
16021602
__skb_pull(skb, sizeof(struct cpl_t5_trace_pkt));
@@ -1661,7 +1661,7 @@ int t4_ethrx_handler(struct sge_rspq *q, const __be64 *rsp,
16611661
const struct cpl_rx_pkt *pkt;
16621662
struct sge_eth_rxq *rxq = container_of(q, struct sge_eth_rxq, rspq);
16631663
struct sge *s = &q->adap->sge;
1664-
int cpl_trace_pkt = is_t4(q->adap->chip) ?
1664+
int cpl_trace_pkt = is_t4(q->adap->params.chip) ?
16651665
CPL_TRACE_PKT : CPL_TRACE_PKT_T5;
16661666

16671667
if (unlikely(*(u8 *)rsp == cpl_trace_pkt))
@@ -2182,7 +2182,7 @@ int t4_sge_alloc_rxq(struct adapter *adap, struct sge_rspq *iq, bool fwevtq,
21822182
static void init_txq(struct adapter *adap, struct sge_txq *q, unsigned int id)
21832183
{
21842184
q->cntxt_id = id;
2185-
if (!is_t4(adap->chip)) {
2185+
if (!is_t4(adap->params.chip)) {
21862186
unsigned int s_qpp;
21872187
unsigned short udb_density;
21882188
unsigned long qpshift;
@@ -2641,7 +2641,7 @@ static int t4_sge_init_hard(struct adapter *adap)
26412641
* Set up to drop DOORBELL writes when the DOORBELL FIFO overflows
26422642
* and generate an interrupt when this occurs so we can recover.
26432643
*/
2644-
if (is_t4(adap->chip)) {
2644+
if (is_t4(adap->params.chip)) {
26452645
t4_set_reg_field(adap, A_SGE_DBFIFO_STATUS,
26462646
V_HP_INT_THRESH(M_HP_INT_THRESH) |
26472647
V_LP_INT_THRESH(M_LP_INT_THRESH),

0 commit comments

Comments
 (0)