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#ifndef _MV_SAS_H_
27#define _MV_SAS_H_
28
29#include <linux/kernel.h>
30#include <linux/module.h>
31#include <linux/spinlock.h>
32#include <linux/delay.h>
33#include <linux/types.h>
34#include <linux/ctype.h>
35#include <linux/dma-mapping.h>
36#include <linux/pci.h>
37#include <linux/platform_device.h>
38#include <linux/interrupt.h>
39#include <linux/irq.h>
40#include <linux/slab.h>
41#include <linux/vmalloc.h>
42#include <scsi/libsas.h>
43#include <scsi/scsi.h>
44#include <scsi/scsi_tcq.h>
45#include <scsi/sas_ata.h>
46#include "mv_defs.h"
47
48#define DRV_NAME "mvsas"
49#define DRV_VERSION "0.8.16"
50#define MVS_ID_NOT_MAPPED 0x7f
51#define WIDE_PORT_MAX_PHY 4
52#define mv_printk(fmt, arg ...) \
53 printk(KERN_DEBUG"%s %d:" fmt, __FILE__, __LINE__, ## arg)
54#ifdef MV_DEBUG
55#define mv_dprintk(format, arg...) \
56 printk(KERN_DEBUG"%s %d:" format, __FILE__, __LINE__, ## arg)
57#else
58#define mv_dprintk(format, arg...)
59#endif
60#define MV_MAX_U32 0xffffffff
61
62extern int interrupt_coalescing;
63extern struct mvs_tgt_initiator mvs_tgt;
64extern struct mvs_info *tgt_mvi;
65extern const struct mvs_dispatch mvs_64xx_dispatch;
66extern const struct mvs_dispatch mvs_94xx_dispatch;
67
68#define DEV_IS_EXPANDER(type) \
69 ((type == SAS_EDGE_EXPANDER_DEVICE) || (type == SAS_FANOUT_EXPANDER_DEVICE))
70
71#define bit(n) ((u64)1 << n)
72
73#define for_each_phy(__lseq_mask, __mc, __lseq) \
74 for ((__mc) = (__lseq_mask), (__lseq) = 0; \
75 (__mc) != 0 ; \
76 (++__lseq), (__mc) >>= 1)
77
78#define MVS_PHY_ID (1U << sas_phy->id)
79#define MV_INIT_DELAYED_WORK(w, f, d) INIT_DELAYED_WORK(w, f)
80#define UNASSOC_D2H_FIS(id) \
81 ((void *) mvi->rx_fis + 0x100 * id)
82#define SATA_RECEIVED_FIS_LIST(reg_set) \
83 ((void *) mvi->rx_fis + mvi->chip->fis_offs + 0x100 * reg_set)
84#define SATA_RECEIVED_SDB_FIS(reg_set) \
85 (SATA_RECEIVED_FIS_LIST(reg_set) + 0x58)
86#define SATA_RECEIVED_D2H_FIS(reg_set) \
87 (SATA_RECEIVED_FIS_LIST(reg_set) + 0x40)
88#define SATA_RECEIVED_PIO_FIS(reg_set) \
89 (SATA_RECEIVED_FIS_LIST(reg_set) + 0x20)
90#define SATA_RECEIVED_DMA_FIS(reg_set) \
91 (SATA_RECEIVED_FIS_LIST(reg_set) + 0x00)
92
93enum dev_status {
94 MVS_DEV_NORMAL = 0x0,
95 MVS_DEV_EH = 0x1,
96};
97
98enum dev_reset {
99 MVS_SOFT_RESET = 0,
100 MVS_HARD_RESET = 1,
101 MVS_PHY_TUNE = 2,
102};
103
104struct mvs_info;
105
106struct mvs_dispatch {
107 char *name;
108 int (*chip_init)(struct mvs_info *mvi);
109 int (*spi_init)(struct mvs_info *mvi);
110 int (*chip_ioremap)(struct mvs_info *mvi);
111 void (*chip_iounmap)(struct mvs_info *mvi);
112 irqreturn_t (*isr)(struct mvs_info *mvi, int irq, u32 stat);
113 u32 (*isr_status)(struct mvs_info *mvi, int irq);
114 void (*interrupt_enable)(struct mvs_info *mvi);
115 void (*interrupt_disable)(struct mvs_info *mvi);
116
117 u32 (*read_phy_ctl)(struct mvs_info *mvi, u32 port);
118 void (*write_phy_ctl)(struct mvs_info *mvi, u32 port, u32 val);
119
120 u32 (*read_port_cfg_data)(struct mvs_info *mvi, u32 port);
121 void (*write_port_cfg_data)(struct mvs_info *mvi, u32 port, u32 val);
122 void (*write_port_cfg_addr)(struct mvs_info *mvi, u32 port, u32 addr);
123
124 u32 (*read_port_vsr_data)(struct mvs_info *mvi, u32 port);
125 void (*write_port_vsr_data)(struct mvs_info *mvi, u32 port, u32 val);
126 void (*write_port_vsr_addr)(struct mvs_info *mvi, u32 port, u32 addr);
127
128 u32 (*read_port_irq_stat)(struct mvs_info *mvi, u32 port);
129 void (*write_port_irq_stat)(struct mvs_info *mvi, u32 port, u32 val);
130
131 u32 (*read_port_irq_mask)(struct mvs_info *mvi, u32 port);
132 void (*write_port_irq_mask)(struct mvs_info *mvi, u32 port, u32 val);
133
134 void (*command_active)(struct mvs_info *mvi, u32 slot_idx);
135 void (*clear_srs_irq)(struct mvs_info *mvi, u8 reg_set, u8 clear_all);
136 void (*issue_stop)(struct mvs_info *mvi, enum mvs_port_type type,
137 u32 tfs);
138 void (*start_delivery)(struct mvs_info *mvi, u32 tx);
139 u32 (*rx_update)(struct mvs_info *mvi);
140 void (*int_full)(struct mvs_info *mvi);
141 u8 (*assign_reg_set)(struct mvs_info *mvi, u8 *tfs);
142 void (*free_reg_set)(struct mvs_info *mvi, u8 *tfs);
143 u32 (*prd_size)(void);
144 u32 (*prd_count)(void);
145 void (*make_prd)(struct scatterlist *scatter, int nr, void *prd);
146 void (*detect_porttype)(struct mvs_info *mvi, int i);
147 int (*oob_done)(struct mvs_info *mvi, int i);
148 void (*fix_phy_info)(struct mvs_info *mvi, int i,
149 struct sas_identify_frame *id);
150 void (*phy_work_around)(struct mvs_info *mvi, int i);
151 void (*phy_set_link_rate)(struct mvs_info *mvi, u32 phy_id,
152 struct sas_phy_linkrates *rates);
153 u32 (*phy_max_link_rate)(void);
154 void (*phy_disable)(struct mvs_info *mvi, u32 phy_id);
155 void (*phy_enable)(struct mvs_info *mvi, u32 phy_id);
156 void (*phy_reset)(struct mvs_info *mvi, u32 phy_id, int hard);
157 void (*stp_reset)(struct mvs_info *mvi, u32 phy_id);
158 void (*clear_active_cmds)(struct mvs_info *mvi);
159 u32 (*spi_read_data)(struct mvs_info *mvi);
160 void (*spi_write_data)(struct mvs_info *mvi, u32 data);
161 int (*spi_buildcmd)(struct mvs_info *mvi,
162 u32 *dwCmd,
163 u8 cmd,
164 u8 read,
165 u8 length,
166 u32 addr
167 );
168 int (*spi_issuecmd)(struct mvs_info *mvi, u32 cmd);
169 int (*spi_waitdataready)(struct mvs_info *mvi, u32 timeout);
170 void (*dma_fix)(struct mvs_info *mvi, u32 phy_mask,
171 int buf_len, int from, void *prd);
172 void (*tune_interrupt)(struct mvs_info *mvi, u32 time);
173 void (*non_spec_ncq_error)(struct mvs_info *mvi);
174
175};
176
177struct mvs_chip_info {
178 u32 n_host;
179 u32 n_phy;
180 u32 fis_offs;
181 u32 fis_count;
182 u32 srs_sz;
183 u32 sg_width;
184 u32 slot_width;
185 const struct mvs_dispatch *dispatch;
186};
187#define MVS_MAX_SG (1U << mvi->chip->sg_width)
188#define MVS_CHIP_SLOT_SZ (1U << mvi->chip->slot_width)
189#define MVS_RX_FISL_SZ \
190 (mvi->chip->fis_offs + (mvi->chip->fis_count * 0x100))
191#define MVS_CHIP_DISP (mvi->chip->dispatch)
192
193struct mvs_err_info {
194 __le32 flags;
195 __le32 flags2;
196};
197
198struct mvs_cmd_hdr {
199 __le32 flags;
200 __le32 lens;
201 __le32 tags;
202 __le32 data_len;
203 __le64 cmd_tbl;
204 __le64 open_frame;
205 __le64 status_buf;
206 __le64 prd_tbl;
207 __le32 reserved[4];
208};
209
210struct mvs_port {
211 struct asd_sas_port sas_port;
212 u8 port_attached;
213 u8 wide_port_phymap;
214 struct list_head list;
215};
216
217struct mvs_phy {
218 struct mvs_info *mvi;
219 struct mvs_port *port;
220 struct asd_sas_phy sas_phy;
221 struct sas_identify identify;
222 struct scsi_device *sdev;
223 struct timer_list timer;
224 u64 dev_sas_addr;
225 u64 att_dev_sas_addr;
226 u32 att_dev_info;
227 u32 dev_info;
228 u32 phy_type;
229 u32 phy_status;
230 u32 irq_status;
231 u32 frame_rcvd_size;
232 u8 frame_rcvd[32];
233 u8 phy_attached;
234 u8 phy_mode;
235 u8 reserved[2];
236 u32 phy_event;
237 enum sas_linkrate minimum_linkrate;
238 enum sas_linkrate maximum_linkrate;
239};
240
241struct mvs_device {
242 struct list_head dev_entry;
243 enum sas_device_type dev_type;
244 struct mvs_info *mvi_info;
245 struct domain_device *sas_device;
246 struct timer_list timer;
247 u32 attached_phy;
248 u32 device_id;
249 u32 running_req;
250 u8 taskfileset;
251 u8 dev_status;
252 u16 reserved;
253};
254
255
256struct phy_tuning {
257
258 u8 trans_emp_en:1;
259
260 u8 trans_emp_amp:4;
261
262 u8 Reserved_2bit_1:3;
263
264 u8 trans_amp:5;
265
266 u8 trans_amp_adj:2;
267
268 u8 resv_2bit_2:1;
269
270 u8 reserved[2];
271};
272
273struct ffe_control {
274
275 u8 ffe_cap_sel:4;
276
277 u8 ffe_rss_sel:3;
278
279 u8 reserved:1;
280};
281
282
283
284
285
286
287struct hba_info_page {
288
289
290 u8 signature[4];
291
292
293 u32 reserved1[13];
294
295
296
297 u64 sas_addr[8];
298
299
300
301
302
303
304
305
306 struct ffe_control ffe_ctl[8];
307
308 u32 reserved2[12];
309
310
311
312 u8 phy_rate[8];
313
314
315
316 struct phy_tuning phy_tuning[8];
317
318
319 u32 reserved3[10];
320};
321
322struct mvs_slot_info {
323 struct list_head entry;
324 union {
325 struct sas_task *task;
326 void *tdata;
327 };
328 u32 n_elem;
329 u32 tx;
330 u32 slot_tag;
331
332
333
334
335 void *buf;
336 dma_addr_t buf_dma;
337 void *response;
338 struct mvs_port *port;
339 struct mvs_device *device;
340 void *open_frame;
341};
342
343struct mvs_info {
344 unsigned long flags;
345
346
347 spinlock_t lock;
348
349
350 struct pci_dev *pdev;
351 struct device *dev;
352
353
354 void __iomem *regs;
355
356
357 void __iomem *regs_ex;
358 u8 sas_addr[SAS_ADDR_SIZE];
359
360
361 struct sas_ha_struct *sas;
362 struct Scsi_Host *shost;
363
364
365 __le32 *tx;
366 dma_addr_t tx_dma;
367
368
369 u32 tx_prod;
370
371
372 __le32 *rx;
373 dma_addr_t rx_dma;
374
375
376 u32 rx_cons;
377
378
379 __le32 *rx_fis;
380 dma_addr_t rx_fis_dma;
381
382
383 struct mvs_cmd_hdr *slot;
384 dma_addr_t slot_dma;
385
386 u32 chip_id;
387 const struct mvs_chip_info *chip;
388
389 int tags_num;
390 unsigned long *tags;
391
392 struct mvs_phy phy[MVS_MAX_PHYS];
393 struct mvs_port port[MVS_MAX_PHYS];
394 u32 id;
395 u64 sata_reg_set;
396 struct list_head *hba_list;
397 struct list_head soc_entry;
398 struct list_head wq_list;
399 unsigned long instance;
400 u16 flashid;
401 u32 flashsize;
402 u32 flashsectSize;
403
404 void *addon;
405 struct hba_info_page hba_info_param;
406 struct mvs_device devices[MVS_MAX_DEVICES];
407 void *bulk_buffer;
408 dma_addr_t bulk_buffer_dma;
409 void *bulk_buffer1;
410 dma_addr_t bulk_buffer_dma1;
411#define TRASH_BUCKET_SIZE 0x20000
412 void *dma_pool;
413 struct mvs_slot_info slot_info[0];
414};
415
416struct mvs_prv_info{
417 u8 n_host;
418 u8 n_phy;
419 u8 scan_finished;
420 u8 reserve;
421 struct mvs_info *mvi[2];
422 struct tasklet_struct mv_tasklet;
423};
424
425struct mvs_wq {
426 struct delayed_work work_q;
427 struct mvs_info *mvi;
428 void *data;
429 int handler;
430 struct list_head entry;
431};
432
433struct mvs_task_exec_info {
434 struct sas_task *task;
435 struct mvs_cmd_hdr *hdr;
436 struct mvs_port *port;
437 u32 tag;
438 int n_elem;
439};
440
441
442void mvs_get_sas_addr(void *buf, u32 buflen);
443void mvs_tag_clear(struct mvs_info *mvi, u32 tag);
444void mvs_tag_free(struct mvs_info *mvi, u32 tag);
445void mvs_tag_set(struct mvs_info *mvi, unsigned int tag);
446int mvs_tag_alloc(struct mvs_info *mvi, u32 *tag_out);
447void mvs_tag_init(struct mvs_info *mvi);
448void mvs_iounmap(void __iomem *regs);
449int mvs_ioremap(struct mvs_info *mvi, int bar, int bar_ex);
450void mvs_phys_reset(struct mvs_info *mvi, u32 phy_mask, int hard);
451int mvs_phy_control(struct asd_sas_phy *sas_phy, enum phy_func func,
452 void *funcdata);
453void mvs_set_sas_addr(struct mvs_info *mvi, int port_id, u32 off_lo,
454 u32 off_hi, u64 sas_addr);
455void mvs_scan_start(struct Scsi_Host *shost);
456int mvs_scan_finished(struct Scsi_Host *shost, unsigned long time);
457int mvs_queue_command(struct sas_task *task, gfp_t gfp_flags);
458int mvs_abort_task(struct sas_task *task);
459int mvs_abort_task_set(struct domain_device *dev, u8 *lun);
460int mvs_clear_aca(struct domain_device *dev, u8 *lun);
461int mvs_clear_task_set(struct domain_device *dev, u8 * lun);
462void mvs_port_formed(struct asd_sas_phy *sas_phy);
463void mvs_port_deformed(struct asd_sas_phy *sas_phy);
464int mvs_dev_found(struct domain_device *dev);
465void mvs_dev_gone(struct domain_device *dev);
466int mvs_lu_reset(struct domain_device *dev, u8 *lun);
467int mvs_slot_complete(struct mvs_info *mvi, u32 rx_desc, u32 flags);
468int mvs_I_T_nexus_reset(struct domain_device *dev);
469int mvs_query_task(struct sas_task *task);
470void mvs_release_task(struct mvs_info *mvi,
471 struct domain_device *dev);
472void mvs_do_release_task(struct mvs_info *mvi, int phy_no,
473 struct domain_device *dev);
474void mvs_int_port(struct mvs_info *mvi, int phy_no, u32 events);
475void mvs_update_phyinfo(struct mvs_info *mvi, int i, int get_st);
476int mvs_int_rx(struct mvs_info *mvi, bool self_clear);
477struct mvs_device *mvs_find_dev_by_reg_set(struct mvs_info *mvi, u8 reg_set);
478#endif
479
480