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#ifndef __CSIO_HW_H__
36#define __CSIO_HW_H__
37
38#include <linux/kernel.h>
39#include <linux/pci.h>
40#include <linux/device.h>
41#include <linux/workqueue.h>
42#include <linux/compiler.h>
43#include <linux/cdev.h>
44#include <linux/list.h>
45#include <linux/mempool.h>
46#include <linux/io.h>
47#include <linux/spinlock_types.h>
48#include <scsi/scsi_device.h>
49#include <scsi/scsi_transport_fc.h>
50
51#include "csio_hw_chip.h"
52#include "csio_wr.h"
53#include "csio_mb.h"
54#include "csio_scsi.h"
55#include "csio_defs.h"
56#include "t4_regs.h"
57#include "t4_msg.h"
58
59
60
61
62#define FW_HOSTERROR 255
63
64#define CSIO_HW_NAME "Chelsio FCoE Adapter"
65#define CSIO_MAX_PFN 8
66#define CSIO_MAX_PPORTS 4
67
68#define CSIO_MAX_LUN 0xFFFF
69#define CSIO_MAX_QUEUE 2048
70#define CSIO_MAX_CMD_PER_LUN 32
71#define CSIO_MAX_DDP_BUF_SIZE (1024 * 1024)
72#define CSIO_MAX_SECTOR_SIZE 128
73
74
75#define CSIO_EXTRA_MSI_IQS 2
76
77#define CSIO_EXTRA_VECS 2
78#define CSIO_MAX_SCSI_CPU 128
79#define CSIO_MAX_SCSI_QSETS (CSIO_MAX_SCSI_CPU * CSIO_MAX_PPORTS)
80#define CSIO_MAX_MSIX_VECS (CSIO_MAX_SCSI_QSETS + CSIO_EXTRA_VECS)
81
82
83enum {
84 CSIO_INTR_WRSIZE = 128,
85 CSIO_INTR_IQSIZE = ((CSIO_MAX_MSIX_VECS + 1) * CSIO_INTR_WRSIZE),
86 CSIO_FWEVT_WRSIZE = 128,
87 CSIO_FWEVT_IQLEN = 128,
88 CSIO_FWEVT_FLBUFS = 64,
89 CSIO_FWEVT_IQSIZE = (CSIO_FWEVT_WRSIZE * CSIO_FWEVT_IQLEN),
90 CSIO_HW_NIQ = 1,
91 CSIO_HW_NFLQ = 1,
92 CSIO_HW_NEQ = 1,
93 CSIO_HW_NINTXQ = 1,
94};
95
96struct csio_msix_entries {
97 unsigned short vector;
98 void *dev_id;
99 char desc[24];
100};
101
102struct csio_scsi_qset {
103 int iq_idx;
104 int eq_idx;
105 uint32_t intr_idx;
106};
107
108struct csio_scsi_cpu_info {
109 int16_t max_cpus;
110};
111
112extern int csio_dbg_level;
113extern int csio_force_master;
114extern unsigned int csio_port_mask;
115extern int csio_msi;
116
117#define CSIO_VENDOR_ID 0x1425
118#define CSIO_ASIC_DEVID_PROTO_MASK 0xFF00
119#define CSIO_ASIC_DEVID_TYPE_MASK 0x00FF
120
121#define CSIO_GLBL_INTR_MASK (CIM | MPS | PL | PCIE | MC | EDC0 | \
122 EDC1 | LE | TP | MA | PM_TX | PM_RX | \
123 ULP_RX | CPL_SWITCH | SGE | \
124 ULP_TX | SF)
125
126
127
128
129
130enum {
131
132 CSIO_SGE_DBFIFO_INT_THRESH = 10,
133
134 CSIO_SGE_RX_DMA_OFFSET = 2,
135
136 CSIO_SGE_FLBUF_SIZE1 = 65536,
137 CSIO_SGE_FLBUF_SIZE2 = 1536,
138 CSIO_SGE_FLBUF_SIZE3 = 9024,
139 CSIO_SGE_FLBUF_SIZE4 = 9216,
140 CSIO_SGE_FLBUF_SIZE5 = 2048,
141 CSIO_SGE_FLBUF_SIZE6 = 128,
142 CSIO_SGE_FLBUF_SIZE7 = 8192,
143 CSIO_SGE_FLBUF_SIZE8 = 16384,
144
145 CSIO_SGE_TIMER_VAL_0 = 5,
146 CSIO_SGE_TIMER_VAL_1 = 10,
147 CSIO_SGE_TIMER_VAL_2 = 20,
148 CSIO_SGE_TIMER_VAL_3 = 50,
149 CSIO_SGE_TIMER_VAL_4 = 100,
150 CSIO_SGE_TIMER_VAL_5 = 200,
151
152 CSIO_SGE_INT_CNT_VAL_0 = 1,
153 CSIO_SGE_INT_CNT_VAL_1 = 4,
154 CSIO_SGE_INT_CNT_VAL_2 = 8,
155 CSIO_SGE_INT_CNT_VAL_3 = 16,
156};
157
158
159enum csio_evt {
160 CSIO_EVT_FW = 0,
161 CSIO_EVT_MBX,
162 CSIO_EVT_SCN,
163 CSIO_EVT_DEV_LOSS,
164 CSIO_EVT_MAX,
165};
166
167#define CSIO_EVT_MSG_SIZE 512
168#define CSIO_EVTQ_SIZE 512
169
170
171struct csio_evt_msg {
172 struct list_head list;
173 enum csio_evt type;
174 uint8_t data[CSIO_EVT_MSG_SIZE];
175};
176
177enum {
178 EEPROMVSIZE = 32768,
179 SERNUM_LEN = 16,
180 EC_LEN = 16,
181 ID_LEN = 16,
182 TRACE_LEN = 112,
183};
184
185enum {
186 SF_PAGE_SIZE = 256,
187 SF_SEC_SIZE = 64 * 1024,
188 SF_SIZE = SF_SEC_SIZE * 16,
189};
190
191
192enum {
193 SF_ATTEMPTS = 10,
194
195
196 SF_PROG_PAGE = 2,
197 SF_WR_DISABLE = 4,
198 SF_RD_STATUS = 5,
199 SF_WR_ENABLE = 6,
200 SF_RD_DATA_FAST = 0xb,
201 SF_RD_ID = 0x9f,
202 SF_ERASE_SECTOR = 0xd8,
203
204 FW_START_SEC = 8,
205 FW_END_SEC = 15,
206 FW_IMG_START = FW_START_SEC * SF_SEC_SIZE,
207 FW_MAX_SIZE = (FW_END_SEC - FW_START_SEC + 1) * SF_SEC_SIZE,
208
209 FLASH_CFG_MAX_SIZE = 0x10000 ,
210 FLASH_CFG_OFFSET = 0x1f0000,
211 FLASH_CFG_START_SEC = FLASH_CFG_OFFSET / SF_SEC_SIZE,
212};
213
214
215
216
217#define FLASH_START(start) ((start) * SF_SEC_SIZE)
218#define FLASH_MAX_SIZE(nsecs) ((nsecs) * SF_SEC_SIZE)
219
220enum {
221
222
223
224 FLASH_FW_START_SEC = 8,
225 FLASH_FW_NSECS = 8,
226 FLASH_FW_START = FLASH_START(FLASH_FW_START_SEC),
227 FLASH_FW_MAX_SIZE = FLASH_MAX_SIZE(FLASH_FW_NSECS),
228
229
230 FLASH_CFG_START = FLASH_START(FLASH_CFG_START_SEC),
231};
232
233#undef FLASH_START
234#undef FLASH_MAX_SIZE
235
236
237enum {
238 CSIO_MGMT_EQ_WRSIZE = 512,
239 CSIO_MGMT_IQ_WRSIZE = 128,
240 CSIO_MGMT_EQLEN = 64,
241 CSIO_MGMT_IQLEN = 64,
242};
243
244#define CSIO_MGMT_EQSIZE (CSIO_MGMT_EQLEN * CSIO_MGMT_EQ_WRSIZE)
245#define CSIO_MGMT_IQSIZE (CSIO_MGMT_IQLEN * CSIO_MGMT_IQ_WRSIZE)
246
247
248struct csio_mgmtm_stats {
249 uint32_t n_abort_req;
250 uint32_t n_abort_rsp;
251 uint32_t n_close_req;
252 uint32_t n_close_rsp;
253 uint32_t n_err;
254 uint32_t n_drop;
255 uint32_t n_active;
256 uint32_t n_cbfn;
257};
258
259
260struct csio_mgmtm {
261 struct csio_hw *hw;
262 int eq_idx;
263 int iq_idx;
264 int msi_vec;
265 struct list_head active_q;
266 struct list_head abort_q;
267 struct list_head cbfn_q;
268 struct list_head mgmt_req_freelist;
269
270 struct timer_list mgmt_timer;
271 struct csio_mgmtm_stats stats;
272};
273
274struct csio_adap_desc {
275 char model_no[16];
276 char description[32];
277};
278
279struct pci_params {
280 uint16_t vendor_id;
281 uint16_t device_id;
282 int vpd_cap_addr;
283 uint16_t speed;
284 uint8_t width;
285};
286
287
288struct csio_hw_params {
289 uint32_t sf_size;
290
291
292 uint32_t sf_nsec;
293 struct pci_params pci;
294 uint32_t log_level;
295
296
297};
298
299struct csio_vpd {
300 uint32_t cclk;
301 uint8_t ec[EC_LEN + 1];
302 uint8_t sn[SERNUM_LEN + 1];
303 uint8_t id[ID_LEN + 1];
304};
305
306struct csio_pport {
307 uint16_t pcap;
308 uint8_t portid;
309 uint8_t link_status;
310 uint16_t link_speed;
311 uint8_t mac[6];
312 uint8_t mod_type;
313 uint8_t rsvd1;
314 uint8_t rsvd2;
315 uint8_t rsvd3;
316};
317
318
319struct csio_fcoe_res_info {
320 uint16_t e_d_tov;
321 uint16_t r_a_tov_seq;
322 uint16_t r_a_tov_els;
323 uint16_t r_r_tov;
324 uint32_t max_xchgs;
325 uint32_t max_ssns;
326 uint32_t used_xchgs;
327 uint32_t used_ssns;
328 uint32_t max_fcfs;
329 uint32_t max_vnps;
330 uint32_t used_fcfs;
331 uint32_t used_vnps;
332};
333
334
335enum csio_hw_ev {
336 CSIO_HWE_CFG = (uint32_t)1,
337 CSIO_HWE_INIT,
338 CSIO_HWE_INIT_DONE,
339 CSIO_HWE_FATAL,
340 CSIO_HWE_PCIERR_DETECTED,
341 CSIO_HWE_PCIERR_SLOT_RESET,
342 CSIO_HWE_PCIERR_RESUME,
343 CSIO_HWE_QUIESCED,
344 CSIO_HWE_HBA_RESET,
345 CSIO_HWE_HBA_RESET_DONE,
346 CSIO_HWE_FW_DLOAD,
347 CSIO_HWE_PCI_REMOVE,
348 CSIO_HWE_SUSPEND,
349 CSIO_HWE_RESUME,
350 CSIO_HWE_MAX,
351};
352
353
354struct csio_hw_stats {
355 uint32_t n_evt_activeq;
356 uint32_t n_evt_freeq;
357 uint32_t n_evt_drop;
358 uint32_t n_evt_unexp;
359 uint32_t n_pcich_offline;
360 uint32_t n_lnlkup_miss;
361 uint32_t n_cpl_fw6_msg;
362 uint32_t n_cpl_fw6_pld;
363 uint32_t n_cpl_unexp;
364 uint32_t n_mbint_unexp;
365
366 uint32_t n_plint_unexp;
367
368 uint32_t n_plint_cnt;
369 uint32_t n_int_stray;
370 uint32_t n_err;
371 uint32_t n_err_fatal;
372 uint32_t n_err_nomem;
373 uint32_t n_err_io;
374 enum csio_hw_ev n_evt_sm[CSIO_HWE_MAX];
375 uint64_t n_reset_start;
376 uint32_t rsvd1;
377};
378
379
380#define CSIO_HWF_MASTER 0x00000001
381
382
383
384#define CSIO_HWF_HW_INTR_ENABLED 0x00000002
385
386
387#define CSIO_HWF_FWEVT_PENDING 0x00000004
388#define CSIO_HWF_Q_MEM_ALLOCED 0x00000008
389
390
391#define CSIO_HWF_Q_FW_ALLOCED 0x00000010
392
393
394#define CSIO_HWF_VPD_VALID 0x00000020
395#define CSIO_HWF_DEVID_CACHED 0X00000040
396
397#define CSIO_HWF_FWEVT_STOP 0x00000080
398
399
400#define CSIO_HWF_USING_SOFT_PARAMS 0x00000100
401
402
403#define CSIO_HWF_HOST_INTR_ENABLED 0x00000200
404
405
406
407#define csio_is_hw_intr_enabled(__hw) \
408 ((__hw)->flags & CSIO_HWF_HW_INTR_ENABLED)
409#define csio_is_host_intr_enabled(__hw) \
410 ((__hw)->flags & CSIO_HWF_HOST_INTR_ENABLED)
411#define csio_is_hw_master(__hw) ((__hw)->flags & CSIO_HWF_MASTER)
412#define csio_is_valid_vpd(__hw) ((__hw)->flags & CSIO_HWF_VPD_VALID)
413#define csio_is_dev_id_cached(__hw) ((__hw)->flags & CSIO_HWF_DEVID_CACHED)
414#define csio_valid_vpd_copied(__hw) ((__hw)->flags |= CSIO_HWF_VPD_VALID)
415#define csio_dev_id_cached(__hw) ((__hw)->flags |= CSIO_HWF_DEVID_CACHED)
416
417
418enum csio_intr_mode {
419 CSIO_IM_NONE = 0,
420 CSIO_IM_INTX = 1,
421 CSIO_IM_MSI = 2,
422 CSIO_IM_MSIX = 3,
423};
424
425
426struct csio_hw {
427 struct csio_sm sm;
428
429
430 spinlock_t lock;
431
432 struct csio_scsim scsim;
433 struct csio_wrm wrm;
434 struct pci_dev *pdev;
435
436 void __iomem *regstart;
437
438
439
440 uint32_t num_sqsets;
441
442 uint32_t num_scsi_msix_cpus;
443
444
445
446
447
448 struct csio_scsi_qset sqset[CSIO_MAX_PPORTS][CSIO_MAX_SCSI_CPU];
449 struct csio_scsi_cpu_info scsi_cpu_info[CSIO_MAX_PPORTS];
450
451 uint32_t evtflag;
452 uint32_t flags;
453
454 struct csio_mgmtm mgmtm;
455 struct csio_mbm mbm;
456
457
458 uint32_t num_lns;
459 struct csio_lnode *rln;
460 struct list_head sln_head;
461
462
463 int intr_iq_idx;
464
465
466 int fwevt_iq_idx;
467 struct work_struct evtq_work;
468
469
470 struct list_head evt_free_q;
471
472
473 struct list_head evt_active_q;
474
475
476 char name[32];
477 char hw_ver[16];
478 char model_desc[32];
479 char drv_version[32];
480 char fwrev_str[32];
481 uint32_t optrom_ver;
482 uint32_t fwrev;
483 uint32_t tp_vers;
484 char chip_ver;
485 uint16_t chip_id;
486 uint32_t cfg_finiver;
487 uint32_t cfg_finicsum;
488 uint32_t cfg_cfcsum;
489 uint8_t cfg_csum_status;
490 uint8_t cfg_store;
491 enum csio_dev_state fw_state;
492 struct csio_vpd vpd;
493
494 uint8_t pfn;
495
496
497 uint32_t port_vec;
498 uint8_t num_pports;
499
500
501 uint8_t rst_retries;
502 uint8_t cur_evt;
503 uint8_t prev_evt;
504 uint32_t dev_num;
505 struct csio_pport pport[CSIO_MAX_PPORTS];
506 struct csio_hw_params params;
507
508 struct pci_pool *scsi_pci_pool;
509 mempool_t *mb_mempool;
510 mempool_t *rnode_mempool;
511
512
513 enum csio_intr_mode intr_mode;
514 uint32_t fwevt_intr_idx;
515
516
517 uint32_t nondata_intr_idx;
518
519
520
521 uint8_t cfg_neq;
522
523
524 uint8_t cfg_niq;
525
526
527
528 struct csio_fcoe_res_info fres_info;
529 struct csio_hw_chip_ops *chip_ops;
530
531
532
533
534 struct csio_msix_entries msix_entries[CSIO_MAX_MSIX_VECS];
535
536 struct dentry *debugfs_root;
537 struct csio_hw_stats stats;
538};
539
540
541#define csio_reg(_b, _r) ((_b) + (_r))
542
543#define csio_rd_reg8(_h, _r) readb(csio_reg((_h)->regstart, (_r)))
544#define csio_rd_reg16(_h, _r) readw(csio_reg((_h)->regstart, (_r)))
545#define csio_rd_reg32(_h, _r) readl(csio_reg((_h)->regstart, (_r)))
546#define csio_rd_reg64(_h, _r) readq(csio_reg((_h)->regstart, (_r)))
547
548#define csio_wr_reg8(_h, _v, _r) writeb((_v), \
549 csio_reg((_h)->regstart, (_r)))
550#define csio_wr_reg16(_h, _v, _r) writew((_v), \
551 csio_reg((_h)->regstart, (_r)))
552#define csio_wr_reg32(_h, _v, _r) writel((_v), \
553 csio_reg((_h)->regstart, (_r)))
554#define csio_wr_reg64(_h, _v, _r) writeq((_v), \
555 csio_reg((_h)->regstart, (_r)))
556
557void csio_set_reg_field(struct csio_hw *, uint32_t, uint32_t, uint32_t);
558
559
560static inline uint32_t
561csio_core_ticks_to_us(struct csio_hw *hw, uint32_t ticks)
562{
563
564 return (ticks * 1000 + hw->vpd.cclk/2) / hw->vpd.cclk;
565}
566
567static inline uint32_t
568csio_us_to_core_ticks(struct csio_hw *hw, uint32_t us)
569{
570 return (us * hw->vpd.cclk) / 1000;
571}
572
573
574#define csio_hw_to_wrm(hw) ((struct csio_wrm *)(&(hw)->wrm))
575#define csio_hw_to_mbm(hw) ((struct csio_mbm *)(&(hw)->mbm))
576#define csio_hw_to_scsim(hw) ((struct csio_scsim *)(&(hw)->scsim))
577#define csio_hw_to_mgmtm(hw) ((struct csio_mgmtm *)(&(hw)->mgmtm))
578
579#define CSIO_PCI_BUS(hw) ((hw)->pdev->bus->number)
580#define CSIO_PCI_DEV(hw) (PCI_SLOT((hw)->pdev->devfn))
581#define CSIO_PCI_FUNC(hw) (PCI_FUNC((hw)->pdev->devfn))
582
583#define csio_set_fwevt_intr_idx(_h, _i) ((_h)->fwevt_intr_idx = (_i))
584#define csio_get_fwevt_intr_idx(_h) ((_h)->fwevt_intr_idx)
585#define csio_set_nondata_intr_idx(_h, _i) ((_h)->nondata_intr_idx = (_i))
586#define csio_get_nondata_intr_idx(_h) ((_h)->nondata_intr_idx)
587
588
589#define CSIO_DEVID(__dev) ((__dev)->dev_num)
590#define CSIO_DEVID_LO(__dev) (CSIO_DEVID((__dev)) & 0xFFFF)
591#define CSIO_DEVID_HI(__dev) ((CSIO_DEVID((__dev)) >> 16) & 0xFFFF)
592
593#define csio_info(__hw, __fmt, ...) \
594 dev_info(&(__hw)->pdev->dev, __fmt, ##__VA_ARGS__)
595
596#define csio_fatal(__hw, __fmt, ...) \
597 dev_crit(&(__hw)->pdev->dev, __fmt, ##__VA_ARGS__)
598
599#define csio_err(__hw, __fmt, ...) \
600 dev_err(&(__hw)->pdev->dev, __fmt, ##__VA_ARGS__)
601
602#define csio_warn(__hw, __fmt, ...) \
603 dev_warn(&(__hw)->pdev->dev, __fmt, ##__VA_ARGS__)
604
605#ifdef __CSIO_DEBUG__
606#define csio_dbg(__hw, __fmt, ...) \
607 csio_info((__hw), __fmt, ##__VA_ARGS__);
608#else
609#define csio_dbg(__hw, __fmt, ...)
610#endif
611
612int csio_hw_wait_op_done_val(struct csio_hw *, int, uint32_t, int,
613 int, int, uint32_t *);
614void csio_hw_tp_wr_bits_indirect(struct csio_hw *, unsigned int,
615 unsigned int, unsigned int);
616int csio_mgmt_req_lookup(struct csio_mgmtm *, struct csio_ioreq *);
617void csio_hw_intr_disable(struct csio_hw *);
618int csio_hw_slow_intr_handler(struct csio_hw *);
619int csio_handle_intr_status(struct csio_hw *, unsigned int,
620 const struct intr_info *);
621
622int csio_hw_start(struct csio_hw *);
623int csio_hw_stop(struct csio_hw *);
624int csio_hw_reset(struct csio_hw *);
625int csio_is_hw_ready(struct csio_hw *);
626int csio_is_hw_removing(struct csio_hw *);
627
628int csio_fwevtq_handler(struct csio_hw *);
629void csio_evtq_worker(struct work_struct *);
630int csio_enqueue_evt(struct csio_hw *, enum csio_evt, void *, uint16_t);
631void csio_evtq_flush(struct csio_hw *hw);
632
633int csio_request_irqs(struct csio_hw *);
634void csio_intr_enable(struct csio_hw *);
635void csio_intr_disable(struct csio_hw *, bool);
636void csio_hw_fatal_err(struct csio_hw *);
637
638struct csio_lnode *csio_lnode_alloc(struct csio_hw *);
639int csio_config_queues(struct csio_hw *);
640
641int csio_hw_init(struct csio_hw *);
642void csio_hw_exit(struct csio_hw *);
643#endif
644