blob: d8aa95c43f4d1c274f054eadf334337d93673428 [file] [log] [blame]
Stephen M. Cameronedd16362009-12-08 14:09:11 -08001/*
2 * Disk Array driver for HP Smart Array SAS controllers
3 * Copyright 2000, 2009 Hewlett-Packard Development Company, L.P.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 *
18 * Questions/Comments/Bugfixes to iss_storagedev@hp.com
19 *
20 */
21#ifndef HPSA_H
22#define HPSA_H
23
24#include <scsi/scsicam.h>
25
26#define IO_OK 0
27#define IO_ERROR 1
28
29struct ctlr_info;
30
31struct access_method {
32 void (*submit_command)(struct ctlr_info *h,
33 struct CommandList *c);
34 void (*set_intr_mask)(struct ctlr_info *h, unsigned long val);
35 unsigned long (*fifo_full)(struct ctlr_info *h);
Stephen M. Cameron900c5442010-02-04 08:42:35 -060036 bool (*intr_pending)(struct ctlr_info *h);
Stephen M. Cameronedd16362009-12-08 14:09:11 -080037 unsigned long (*command_completed)(struct ctlr_info *h);
38};
39
40struct hpsa_scsi_dev_t {
41 int devtype;
42 int bus, target, lun; /* as presented to the OS */
43 unsigned char scsi3addr[8]; /* as presented to the HW */
44#define RAID_CTLR_LUNID "\0\0\0\0\0\0\0\0"
45 unsigned char device_id[16]; /* from inquiry pg. 0x83 */
46 unsigned char vendor[8]; /* bytes 8-15 of inquiry data */
47 unsigned char model[16]; /* bytes 16-31 of inquiry data */
Stephen M. Cameronedd16362009-12-08 14:09:11 -080048 unsigned char raid_level; /* from inquiry page 0xC1 */
49};
50
51struct ctlr_info {
52 int ctlr;
53 char devname[8];
54 char *product_name;
Stephen M. Cameronedd16362009-12-08 14:09:11 -080055 struct pci_dev *pdev;
Stephen M. Cameron01a02ff2010-02-04 08:41:33 -060056 u32 board_id;
Stephen M. Cameronedd16362009-12-08 14:09:11 -080057 void __iomem *vaddr;
58 unsigned long paddr;
59 int nr_cmds; /* Number of commands allowed on this controller */
60 struct CfgTable __iomem *cfgtable;
61 int interrupts_enabled;
62 int major;
63 int max_commands;
64 int commands_outstanding;
65 int max_outstanding; /* Debug */
66 int usage_count; /* number of opens all all minor devices */
Don Brace303932f2010-02-04 08:42:40 -060067# define PERF_MODE_INT 0
68# define DOORBELL_INT 1
Stephen M. Cameronedd16362009-12-08 14:09:11 -080069# define SIMPLE_MODE_INT 2
70# define MEMQ_MODE_INT 3
71 unsigned int intr[4];
72 unsigned int msix_vector;
73 unsigned int msi_vector;
Stephen M. Camerona9a3a272011-02-15 15:32:53 -060074 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
Stephen M. Cameronedd16362009-12-08 14:09:11 -080075 struct access_method access;
76
77 /* queue and queue Info */
Stephen M. Cameron9e0fc762011-02-15 15:32:48 -060078 struct list_head reqQ;
79 struct list_head cmpQ;
Stephen M. Cameronedd16362009-12-08 14:09:11 -080080 unsigned int Qdepth;
81 unsigned int maxQsinceinit;
82 unsigned int maxSG;
83 spinlock_t lock;
Stephen M. Cameron33a2ffc2010-02-25 14:03:27 -060084 int maxsgentries;
85 u8 max_cmd_sg_entries;
86 int chainsize;
87 struct SGDescriptor **cmd_sg_list;
Stephen M. Cameronedd16362009-12-08 14:09:11 -080088
89 /* pointers to command and error info pool */
90 struct CommandList *cmd_pool;
91 dma_addr_t cmd_pool_dhandle;
92 struct ErrorInfo *errinfo_pool;
93 dma_addr_t errinfo_pool_dhandle;
94 unsigned long *cmd_pool_bits;
95 int nr_allocs;
96 int nr_frees;
Stephen M. Camerona08a8472010-02-04 08:43:16 -060097 int scan_finished;
98 spinlock_t scan_lock;
99 wait_queue_head_t scan_wait_queue;
Stephen M. Cameronedd16362009-12-08 14:09:11 -0800100
101 struct Scsi_Host *scsi_host;
102 spinlock_t devlock; /* to protect hba[ctlr]->dev[]; */
103 int ndevices; /* number of used elements in .dev[] array. */
Scott Teelcfe5bad2011-10-26 16:21:07 -0500104 struct hpsa_scsi_dev_t *dev[HPSA_MAX_DEVICES];
Don Brace303932f2010-02-04 08:42:40 -0600105 /*
106 * Performant mode tables.
107 */
108 u32 trans_support;
109 u32 trans_offset;
110 struct TransTable_struct *transtable;
111 unsigned long transMethod;
112
113 /*
114 * Performant mode completion buffer
115 */
116 u64 *reply_pool;
117 dma_addr_t reply_pool_dhandle;
118 u64 *reply_pool_head;
119 size_t reply_pool_size;
120 unsigned char reply_pool_wraparound;
121 u32 *blockFetchTable;
Stephen M. Cameron339b2b12010-02-04 08:42:50 -0600122 unsigned char *hba_inquiry_data;
Stephen M. Camerona0c12412011-10-26 16:22:04 -0500123 u64 last_intr_timestamp;
124 u32 last_heartbeat;
125 u64 last_heartbeat_timestamp;
126 u32 lockup_detected;
127 struct list_head lockup_list;
Stephen M. Cameron75167d22012-05-01 11:42:51 -0500128 u32 TMFSupportFlags; /* cache what task mgmt funcs are supported. */
129#define HPSATMF_BITS_SUPPORTED (1 << 0)
130#define HPSATMF_PHYS_LUN_RESET (1 << 1)
131#define HPSATMF_PHYS_NEX_RESET (1 << 2)
132#define HPSATMF_PHYS_TASK_ABORT (1 << 3)
133#define HPSATMF_PHYS_TSET_ABORT (1 << 4)
134#define HPSATMF_PHYS_CLEAR_ACA (1 << 5)
135#define HPSATMF_PHYS_CLEAR_TSET (1 << 6)
136#define HPSATMF_PHYS_QRY_TASK (1 << 7)
137#define HPSATMF_PHYS_QRY_TSET (1 << 8)
138#define HPSATMF_PHYS_QRY_ASYNC (1 << 9)
139#define HPSATMF_MASK_SUPPORTED (1 << 16)
140#define HPSATMF_LOG_LUN_RESET (1 << 17)
141#define HPSATMF_LOG_NEX_RESET (1 << 18)
142#define HPSATMF_LOG_TASK_ABORT (1 << 19)
143#define HPSATMF_LOG_TSET_ABORT (1 << 20)
144#define HPSATMF_LOG_CLEAR_ACA (1 << 21)
145#define HPSATMF_LOG_CLEAR_TSET (1 << 22)
146#define HPSATMF_LOG_QRY_TASK (1 << 23)
147#define HPSATMF_LOG_QRY_TSET (1 << 24)
148#define HPSATMF_LOG_QRY_ASYNC (1 << 25)
Stephen M. Cameronedd16362009-12-08 14:09:11 -0800149};
150#define HPSA_ABORT_MSG 0
151#define HPSA_DEVICE_RESET_MSG 1
Stephen M. Cameron64670ac2011-05-03 14:59:51 -0500152#define HPSA_RESET_TYPE_CONTROLLER 0x00
153#define HPSA_RESET_TYPE_BUS 0x01
154#define HPSA_RESET_TYPE_TARGET 0x03
155#define HPSA_RESET_TYPE_LUN 0x04
Stephen M. Cameronedd16362009-12-08 14:09:11 -0800156#define HPSA_MSG_SEND_RETRY_LIMIT 10
Stephen M. Cameron516fda42011-05-03 14:59:15 -0500157#define HPSA_MSG_SEND_RETRY_INTERVAL_MSECS (10000)
Stephen M. Cameronedd16362009-12-08 14:09:11 -0800158
159/* Maximum time in seconds driver will wait for command completions
160 * when polling before giving up.
161 */
162#define HPSA_MAX_POLL_TIME_SECS (20)
163
164/* During SCSI error recovery, HPSA_TUR_RETRY_LIMIT defines
165 * how many times to retry TEST UNIT READY on a device
166 * while waiting for it to become ready before giving up.
167 * HPSA_MAX_WAIT_INTERVAL_SECS is the max wait interval
168 * between sending TURs while waiting for a device
169 * to become ready.
170 */
171#define HPSA_TUR_RETRY_LIMIT (20)
172#define HPSA_MAX_WAIT_INTERVAL_SECS (30)
173
174/* HPSA_BOARD_READY_WAIT_SECS is how long to wait for a board
175 * to become ready, in seconds, before giving up on it.
176 * HPSA_BOARD_READY_POLL_INTERVAL_MSECS * is how long to wait
177 * between polling the board to see if it is ready, in
178 * milliseconds. HPSA_BOARD_READY_POLL_INTERVAL and
179 * HPSA_BOARD_READY_ITERATIONS are derived from those.
180 */
181#define HPSA_BOARD_READY_WAIT_SECS (120)
Stephen M. Cameron2ed71272011-05-03 14:59:31 -0500182#define HPSA_BOARD_NOT_READY_WAIT_SECS (100)
Stephen M. Cameronedd16362009-12-08 14:09:11 -0800183#define HPSA_BOARD_READY_POLL_INTERVAL_MSECS (100)
184#define HPSA_BOARD_READY_POLL_INTERVAL \
185 ((HPSA_BOARD_READY_POLL_INTERVAL_MSECS * HZ) / 1000)
186#define HPSA_BOARD_READY_ITERATIONS \
187 ((HPSA_BOARD_READY_WAIT_SECS * 1000) / \
188 HPSA_BOARD_READY_POLL_INTERVAL_MSECS)
Stephen M. Cameronfe5389c2011-01-06 14:48:03 -0600189#define HPSA_BOARD_NOT_READY_ITERATIONS \
190 ((HPSA_BOARD_NOT_READY_WAIT_SECS * 1000) / \
191 HPSA_BOARD_READY_POLL_INTERVAL_MSECS)
Stephen M. Cameronedd16362009-12-08 14:09:11 -0800192#define HPSA_POST_RESET_PAUSE_MSECS (3000)
193#define HPSA_POST_RESET_NOOP_RETRIES (12)
194
195/* Defining the diffent access_menthods */
196/*
197 * Memory mapped FIFO interface (SMART 53xx cards)
198 */
199#define SA5_DOORBELL 0x20
200#define SA5_REQUEST_PORT_OFFSET 0x40
201#define SA5_REPLY_INTR_MASK_OFFSET 0x34
202#define SA5_REPLY_PORT_OFFSET 0x44
203#define SA5_INTR_STATUS 0x30
204#define SA5_SCRATCHPAD_OFFSET 0xB0
205
206#define SA5_CTCFG_OFFSET 0xB4
207#define SA5_CTMEM_OFFSET 0xB8
208
209#define SA5_INTR_OFF 0x08
210#define SA5B_INTR_OFF 0x04
211#define SA5_INTR_PENDING 0x08
212#define SA5B_INTR_PENDING 0x04
213#define FIFO_EMPTY 0xffffffff
214#define HPSA_FIRMWARE_READY 0xffff0000 /* value in scratchpad register */
215
216#define HPSA_ERROR_BIT 0x02
Stephen M. Cameronedd16362009-12-08 14:09:11 -0800217
Don Brace303932f2010-02-04 08:42:40 -0600218/* Performant mode flags */
219#define SA5_PERF_INTR_PENDING 0x04
220#define SA5_PERF_INTR_OFF 0x05
221#define SA5_OUTDB_STATUS_PERF_BIT 0x01
222#define SA5_OUTDB_CLEAR_PERF_BIT 0x01
223#define SA5_OUTDB_CLEAR 0xA0
224#define SA5_OUTDB_CLEAR_PERF_BIT 0x01
225#define SA5_OUTDB_STATUS 0x9C
226
227
Stephen M. Cameronedd16362009-12-08 14:09:11 -0800228#define HPSA_INTR_ON 1
229#define HPSA_INTR_OFF 0
230/*
231 Send the command to the hardware
232*/
233static void SA5_submit_command(struct ctlr_info *h,
234 struct CommandList *c)
235{
Don Brace303932f2010-02-04 08:42:40 -0600236 dev_dbg(&h->pdev->dev, "Sending %x, tag = %x\n", c->busaddr,
237 c->Header.Tag.lower);
Stephen M. Cameronedd16362009-12-08 14:09:11 -0800238 writel(c->busaddr, h->vaddr + SA5_REQUEST_PORT_OFFSET);
Stephen M. Cameronfec62c32011-07-21 13:16:05 -0500239 (void) readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
Stephen M. Cameronedd16362009-12-08 14:09:11 -0800240 h->commands_outstanding++;
241 if (h->commands_outstanding > h->max_outstanding)
242 h->max_outstanding = h->commands_outstanding;
243}
244
245/*
246 * This card is the opposite of the other cards.
247 * 0 turns interrupts on...
248 * 0x08 turns them off...
249 */
250static void SA5_intr_mask(struct ctlr_info *h, unsigned long val)
251{
252 if (val) { /* Turn interrupts on */
253 h->interrupts_enabled = 1;
254 writel(0, h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
Stephen M. Cameron8cd21da2011-05-03 14:58:55 -0500255 (void) readl(h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
Stephen M. Cameronedd16362009-12-08 14:09:11 -0800256 } else { /* Turn them off */
257 h->interrupts_enabled = 0;
258 writel(SA5_INTR_OFF,
259 h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
Stephen M. Cameron8cd21da2011-05-03 14:58:55 -0500260 (void) readl(h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
Stephen M. Cameronedd16362009-12-08 14:09:11 -0800261 }
262}
Don Brace303932f2010-02-04 08:42:40 -0600263
264static void SA5_performant_intr_mask(struct ctlr_info *h, unsigned long val)
265{
266 if (val) { /* turn on interrupts */
267 h->interrupts_enabled = 1;
268 writel(0, h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
Stephen M. Cameron8cd21da2011-05-03 14:58:55 -0500269 (void) readl(h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
Don Brace303932f2010-02-04 08:42:40 -0600270 } else {
271 h->interrupts_enabled = 0;
272 writel(SA5_PERF_INTR_OFF,
273 h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
Stephen M. Cameron8cd21da2011-05-03 14:58:55 -0500274 (void) readl(h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
Don Brace303932f2010-02-04 08:42:40 -0600275 }
276}
277
278static unsigned long SA5_performant_completed(struct ctlr_info *h)
279{
280 unsigned long register_value = FIFO_EMPTY;
281
Don Brace303932f2010-02-04 08:42:40 -0600282 /* msi auto clears the interrupt pending bit. */
283 if (!(h->msi_vector || h->msix_vector)) {
Stephen M. Cameron2c17d2d2012-05-01 11:42:30 -0500284 /* flush the controller write of the reply queue by reading
285 * outbound doorbell status register.
286 */
287 register_value = readl(h->vaddr + SA5_OUTDB_STATUS);
Don Brace303932f2010-02-04 08:42:40 -0600288 writel(SA5_OUTDB_CLEAR_PERF_BIT, h->vaddr + SA5_OUTDB_CLEAR);
289 /* Do a read in order to flush the write to the controller
290 * (as per spec.)
291 */
292 register_value = readl(h->vaddr + SA5_OUTDB_STATUS);
293 }
294
295 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
296 register_value = *(h->reply_pool_head);
297 (h->reply_pool_head)++;
298 h->commands_outstanding--;
299 } else {
300 register_value = FIFO_EMPTY;
301 }
302 /* Check for wraparound */
303 if (h->reply_pool_head == (h->reply_pool + h->max_commands)) {
304 h->reply_pool_head = h->reply_pool;
305 h->reply_pool_wraparound ^= 1;
306 }
307
308 return register_value;
309}
310
Stephen M. Cameronedd16362009-12-08 14:09:11 -0800311/*
312 * Returns true if fifo is full.
313 *
314 */
315static unsigned long SA5_fifo_full(struct ctlr_info *h)
316{
317 if (h->commands_outstanding >= h->max_commands)
318 return 1;
319 else
320 return 0;
321
322}
323/*
324 * returns value read from hardware.
325 * returns FIFO_EMPTY if there is nothing to read
326 */
327static unsigned long SA5_completed(struct ctlr_info *h)
328{
329 unsigned long register_value
330 = readl(h->vaddr + SA5_REPLY_PORT_OFFSET);
331
332 if (register_value != FIFO_EMPTY)
333 h->commands_outstanding--;
334
335#ifdef HPSA_DEBUG
336 if (register_value != FIFO_EMPTY)
Stephen M. Cameron84ca0be2010-02-04 08:42:30 -0600337 dev_dbg(&h->pdev->dev, "Read %lx back from board\n",
Stephen M. Cameronedd16362009-12-08 14:09:11 -0800338 register_value);
339 else
Stephen M. Cameronf79cfec2012-01-19 14:00:59 -0600340 dev_dbg(&h->pdev->dev, "FIFO Empty read\n");
Stephen M. Cameronedd16362009-12-08 14:09:11 -0800341#endif
342
343 return register_value;
344}
345/*
346 * Returns true if an interrupt is pending..
347 */
Stephen M. Cameron900c5442010-02-04 08:42:35 -0600348static bool SA5_intr_pending(struct ctlr_info *h)
Stephen M. Cameronedd16362009-12-08 14:09:11 -0800349{
350 unsigned long register_value =
351 readl(h->vaddr + SA5_INTR_STATUS);
Stephen M. Cameron84ca0be2010-02-04 08:42:30 -0600352 dev_dbg(&h->pdev->dev, "intr_pending %lx\n", register_value);
Stephen M. Cameron900c5442010-02-04 08:42:35 -0600353 return register_value & SA5_INTR_PENDING;
Stephen M. Cameronedd16362009-12-08 14:09:11 -0800354}
355
Don Brace303932f2010-02-04 08:42:40 -0600356static bool SA5_performant_intr_pending(struct ctlr_info *h)
357{
358 unsigned long register_value = readl(h->vaddr + SA5_INTR_STATUS);
359
360 if (!register_value)
361 return false;
362
363 if (h->msi_vector || h->msix_vector)
364 return true;
365
366 /* Read outbound doorbell to flush */
367 register_value = readl(h->vaddr + SA5_OUTDB_STATUS);
368 return register_value & SA5_OUTDB_STATUS_PERF_BIT;
369}
Stephen M. Cameronedd16362009-12-08 14:09:11 -0800370
371static struct access_method SA5_access = {
372 SA5_submit_command,
373 SA5_intr_mask,
374 SA5_fifo_full,
375 SA5_intr_pending,
376 SA5_completed,
377};
378
Don Brace303932f2010-02-04 08:42:40 -0600379static struct access_method SA5_performant_access = {
380 SA5_submit_command,
381 SA5_performant_intr_mask,
382 SA5_fifo_full,
383 SA5_performant_intr_pending,
384 SA5_performant_completed,
385};
386
Stephen M. Cameronedd16362009-12-08 14:09:11 -0800387struct board_type {
Stephen M. Cameron01a02ff2010-02-04 08:41:33 -0600388 u32 board_id;
Stephen M. Cameronedd16362009-12-08 14:09:11 -0800389 char *product_name;
390 struct access_method *access;
391};
392
Stephen M. Cameronedd16362009-12-08 14:09:11 -0800393#endif /* HPSA_H */
394