1 // SPDX-License-Identifier: GPL-2.0-only
3 * Driver for sTec s1120 PCIe SSDs. sTec was acquired in 2013 by HGST and HGST
4 * was acquired by Western Digital in 2012.
6 * Copyright 2012 sTec, Inc.
7 * Copyright (c) 2017 Western Digital Corporation or its affiliates.
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/init.h>
13 #include <linux/pci.h>
14 #include <linux/slab.h>
15 #include <linux/spinlock.h>
16 #include <linux/blkdev.h>
17 #include <linux/blk-mq.h>
18 #include <linux/sched.h>
19 #include <linux/interrupt.h>
20 #include <linux/compiler.h>
21 #include <linux/workqueue.h>
22 #include <linux/delay.h>
23 #include <linux/time.h>
24 #include <linux/hdreg.h>
25 #include <linux/dma-mapping.h>
26 #include <linux/completion.h>
27 #include <linux/scatterlist.h>
28 #include <linux/version.h>
29 #include <linux/err.h>
30 #include <linux/aer.h>
31 #include <linux/wait.h>
32 #include <linux/stringify.h>
33 #include <scsi/scsi.h>
36 #include <linux/uaccess.h>
37 #include <asm/unaligned.h>
39 #include "skd_s1120.h"
41 static int skd_dbg_level;
42 static int skd_isr_comp_limit = 4;
44 #define SKD_ASSERT(expr) \
46 if (unlikely(!(expr))) { \
47 pr_err("Assertion failed! %s,%s,%s,line=%d\n", \
48 # expr, __FILE__, __func__, __LINE__); \
52 #define DRV_NAME "skd"
53 #define PFX DRV_NAME ": "
55 MODULE_LICENSE("GPL");
57 MODULE_DESCRIPTION("STEC s1120 PCIe SSD block driver");
59 #define PCI_VENDOR_ID_STEC 0x1B39
60 #define PCI_DEVICE_ID_S1120 0x0001
62 #define SKD_FUA_NV (1 << 1)
63 #define SKD_MINORS_PER_DEVICE 16
65 #define SKD_MAX_QUEUE_DEPTH 200u
67 #define SKD_PAUSE_TIMEOUT (5 * 1000)
69 #define SKD_N_FITMSG_BYTES (512u)
70 #define SKD_MAX_REQ_PER_MSG 14
72 #define SKD_N_SPECIAL_FITMSG_BYTES (128u)
74 /* SG elements are 32 bytes, so we can make this 4096 and still be under the
75 * 128KB limit. That allows 4096*4K = 16M xfer size
77 #define SKD_N_SG_PER_REQ_DEFAULT 256u
79 #define SKD_N_COMPLETION_ENTRY 256u
80 #define SKD_N_READ_CAP_BYTES (8u)
82 #define SKD_N_INTERNAL_BYTES (512u)
84 #define SKD_SKCOMP_SIZE \
85 ((sizeof(struct fit_completion_entry_v1) + \
86 sizeof(struct fit_comp_error_info)) * SKD_N_COMPLETION_ENTRY)
88 /* 5 bits of uniqifier, 0xF800 */
89 #define SKD_ID_TABLE_MASK (3u << 8u)
90 #define SKD_ID_RW_REQUEST (0u << 8u)
91 #define SKD_ID_INTERNAL (1u << 8u)
92 #define SKD_ID_FIT_MSG (3u << 8u)
93 #define SKD_ID_SLOT_MASK 0x00FFu
94 #define SKD_ID_SLOT_AND_TABLE_MASK 0x03FFu
96 #define SKD_N_MAX_SECTORS 2048u
98 #define SKD_MAX_RETRIES 2u
100 #define SKD_TIMER_SECONDS(seconds) (seconds)
101 #define SKD_TIMER_MINUTES(minutes) ((minutes) * (60))
103 #define INQ_STD_NBYTES 36
105 enum skd_drvr_state {
109 SKD_DRVR_STATE_STARTING,
110 SKD_DRVR_STATE_ONLINE,
111 SKD_DRVR_STATE_PAUSING,
112 SKD_DRVR_STATE_PAUSED,
113 SKD_DRVR_STATE_RESTARTING,
114 SKD_DRVR_STATE_RESUMING,
115 SKD_DRVR_STATE_STOPPING,
116 SKD_DRVR_STATE_FAULT,
117 SKD_DRVR_STATE_DISAPPEARED,
118 SKD_DRVR_STATE_PROTOCOL_MISMATCH,
119 SKD_DRVR_STATE_BUSY_ERASE,
120 SKD_DRVR_STATE_BUSY_SANITIZE,
121 SKD_DRVR_STATE_BUSY_IMMINENT,
122 SKD_DRVR_STATE_WAIT_BOOT,
123 SKD_DRVR_STATE_SYNCING,
126 #define SKD_WAIT_BOOT_TIMO SKD_TIMER_SECONDS(90u)
127 #define SKD_STARTING_TIMO SKD_TIMER_SECONDS(8u)
128 #define SKD_RESTARTING_TIMO SKD_TIMER_MINUTES(4u)
129 #define SKD_BUSY_TIMO SKD_TIMER_MINUTES(20u)
130 #define SKD_STARTED_BUSY_TIMO SKD_TIMER_SECONDS(60u)
131 #define SKD_START_WAIT_SECONDS 90u
137 SKD_REQ_STATE_COMPLETED,
138 SKD_REQ_STATE_TIMEOUT,
141 enum skd_check_status_action {
142 SKD_CHECK_STATUS_REPORT_GOOD,
143 SKD_CHECK_STATUS_REPORT_SMART_ALERT,
144 SKD_CHECK_STATUS_REQUEUE_REQUEST,
145 SKD_CHECK_STATUS_REPORT_ERROR,
146 SKD_CHECK_STATUS_BUSY_IMMINENT,
150 struct fit_msg_hdr fmh;
151 struct skd_scsi_request scsi[SKD_MAX_REQ_PER_MSG];
154 struct skd_fitmsg_context {
159 struct skd_msg_buf *msg_buf;
160 dma_addr_t mb_dma_address;
163 struct skd_request_context {
164 enum skd_req_state state;
171 enum dma_data_direction data_dir;
172 struct scatterlist *sg;
176 struct fit_sg_descriptor *sksg_list;
177 dma_addr_t sksg_dma_address;
179 struct fit_completion_entry_v1 completion;
181 struct fit_comp_error_info err_info;
187 struct skd_special_context {
188 struct skd_request_context req;
191 dma_addr_t db_dma_address;
193 struct skd_msg_buf *msg_buf;
194 dma_addr_t mb_dma_address;
197 typedef enum skd_irq_type {
203 #define SKD_MAX_BARS 2
206 void __iomem *mem_map[SKD_MAX_BARS];
207 resource_size_t mem_phys[SKD_MAX_BARS];
208 u32 mem_size[SKD_MAX_BARS];
210 struct skd_msix_entry *msix_entries;
212 struct pci_dev *pdev;
213 int pcie_error_reporting_is_enabled;
216 struct gendisk *disk;
217 struct blk_mq_tag_set tag_set;
218 struct request_queue *queue;
219 struct skd_fitmsg_context *skmsg;
220 struct device *class_dev;
228 enum skd_drvr_state state;
231 u32 cur_max_queue_depth;
232 u32 queue_low_water_mark;
233 u32 dev_max_queue_depth;
235 u32 num_fitmsg_context;
238 struct skd_fitmsg_context *skmsg_table;
240 struct skd_special_context internal_skspcl;
241 u32 read_cap_blocksize;
242 u32 read_cap_last_lba;
243 int read_cap_is_valid;
244 int inquiry_is_valid;
245 u8 inq_serial_num[13]; /*12 chars plus null term */
249 struct kmem_cache *msgbuf_cache;
250 struct kmem_cache *sglist_cache;
251 struct kmem_cache *databuf_cache;
252 struct fit_completion_entry_v1 *skcomp_table;
253 struct fit_comp_error_info *skerr_table;
254 dma_addr_t cq_dma_address;
256 wait_queue_head_t waitq;
258 struct timer_list timer;
268 u32 connect_time_stamp;
270 #define SKD_MAX_CONNECT_RETRIES 16
275 struct work_struct start_queue;
276 struct work_struct completion_worker;
279 #define SKD_WRITEL(DEV, VAL, OFF) skd_reg_write32(DEV, VAL, OFF)
280 #define SKD_READL(DEV, OFF) skd_reg_read32(DEV, OFF)
281 #define SKD_WRITEQ(DEV, VAL, OFF) skd_reg_write64(DEV, VAL, OFF)
283 static inline u32 skd_reg_read32(struct skd_device *skdev, u32 offset)
285 u32 val = readl(skdev->mem_map[1] + offset);
287 if (unlikely(skdev->dbg_level >= 2))
288 dev_dbg(&skdev->pdev->dev, "offset %x = %x\n", offset, val);
292 static inline void skd_reg_write32(struct skd_device *skdev, u32 val,
295 writel(val, skdev->mem_map[1] + offset);
296 if (unlikely(skdev->dbg_level >= 2))
297 dev_dbg(&skdev->pdev->dev, "offset %x = %x\n", offset, val);
300 static inline void skd_reg_write64(struct skd_device *skdev, u64 val,
303 writeq(val, skdev->mem_map[1] + offset);
304 if (unlikely(skdev->dbg_level >= 2))
305 dev_dbg(&skdev->pdev->dev, "offset %x = %016llx\n", offset,
310 #define SKD_IRQ_DEFAULT SKD_IRQ_MSIX
311 static int skd_isr_type = SKD_IRQ_DEFAULT;
313 module_param(skd_isr_type, int, 0444);
314 MODULE_PARM_DESC(skd_isr_type, "Interrupt type capability."
315 " (0==legacy, 1==MSI, 2==MSI-X, default==1)");
317 #define SKD_MAX_REQ_PER_MSG_DEFAULT 1
318 static int skd_max_req_per_msg = SKD_MAX_REQ_PER_MSG_DEFAULT;
320 module_param(skd_max_req_per_msg, int, 0444);
321 MODULE_PARM_DESC(skd_max_req_per_msg,
322 "Maximum SCSI requests packed in a single message."
323 " (1-" __stringify(SKD_MAX_REQ_PER_MSG) ", default==1)");
325 #define SKD_MAX_QUEUE_DEPTH_DEFAULT 64
326 #define SKD_MAX_QUEUE_DEPTH_DEFAULT_STR "64"
327 static int skd_max_queue_depth = SKD_MAX_QUEUE_DEPTH_DEFAULT;
329 module_param(skd_max_queue_depth, int, 0444);
330 MODULE_PARM_DESC(skd_max_queue_depth,
331 "Maximum SCSI requests issued to s1120."
332 " (1-200, default==" SKD_MAX_QUEUE_DEPTH_DEFAULT_STR ")");
334 static int skd_sgs_per_request = SKD_N_SG_PER_REQ_DEFAULT;
335 module_param(skd_sgs_per_request, int, 0444);
336 MODULE_PARM_DESC(skd_sgs_per_request,
337 "Maximum SG elements per block request."
338 " (1-4096, default==256)");
340 static int skd_max_pass_thru = 1;
341 module_param(skd_max_pass_thru, int, 0444);
342 MODULE_PARM_DESC(skd_max_pass_thru,
343 "Maximum SCSI pass-thru at a time. IGNORED");
345 module_param(skd_dbg_level, int, 0444);
346 MODULE_PARM_DESC(skd_dbg_level, "s1120 debug level (0,1,2)");
348 module_param(skd_isr_comp_limit, int, 0444);
349 MODULE_PARM_DESC(skd_isr_comp_limit, "s1120 isr comp limit (0=none) default=4");
351 /* Major device number dynamically assigned. */
352 static u32 skd_major;
354 static void skd_destruct(struct skd_device *skdev);
355 static const struct block_device_operations skd_blockdev_ops;
356 static void skd_send_fitmsg(struct skd_device *skdev,
357 struct skd_fitmsg_context *skmsg);
358 static void skd_send_special_fitmsg(struct skd_device *skdev,
359 struct skd_special_context *skspcl);
360 static bool skd_preop_sg_list(struct skd_device *skdev,
361 struct skd_request_context *skreq);
362 static void skd_postop_sg_list(struct skd_device *skdev,
363 struct skd_request_context *skreq);
365 static void skd_restart_device(struct skd_device *skdev);
366 static int skd_quiesce_dev(struct skd_device *skdev);
367 static int skd_unquiesce_dev(struct skd_device *skdev);
368 static void skd_disable_interrupts(struct skd_device *skdev);
369 static void skd_isr_fwstate(struct skd_device *skdev);
370 static void skd_recover_requests(struct skd_device *skdev);
371 static void skd_soft_reset(struct skd_device *skdev);
373 const char *skd_drive_state_to_str(int state);
374 const char *skd_skdev_state_to_str(enum skd_drvr_state state);
375 static void skd_log_skdev(struct skd_device *skdev, const char *event);
376 static void skd_log_skreq(struct skd_device *skdev,
377 struct skd_request_context *skreq, const char *event);
380 *****************************************************************************
381 * READ/WRITE REQUESTS
382 *****************************************************************************
384 static bool skd_inc_in_flight(struct request *rq, void *data, bool reserved)
392 static int skd_in_flight(struct skd_device *skdev)
396 blk_mq_tagset_busy_iter(&skdev->tag_set, skd_inc_in_flight, &count);
402 skd_prep_rw_cdb(struct skd_scsi_request *scsi_req,
403 int data_dir, unsigned lba,
406 if (data_dir == READ)
407 scsi_req->cdb[0] = READ_10;
409 scsi_req->cdb[0] = WRITE_10;
411 scsi_req->cdb[1] = 0;
412 scsi_req->cdb[2] = (lba & 0xff000000) >> 24;
413 scsi_req->cdb[3] = (lba & 0xff0000) >> 16;
414 scsi_req->cdb[4] = (lba & 0xff00) >> 8;
415 scsi_req->cdb[5] = (lba & 0xff);
416 scsi_req->cdb[6] = 0;
417 scsi_req->cdb[7] = (count & 0xff00) >> 8;
418 scsi_req->cdb[8] = count & 0xff;
419 scsi_req->cdb[9] = 0;
423 skd_prep_zerosize_flush_cdb(struct skd_scsi_request *scsi_req,
424 struct skd_request_context *skreq)
426 skreq->flush_cmd = 1;
428 scsi_req->cdb[0] = SYNCHRONIZE_CACHE;
429 scsi_req->cdb[1] = 0;
430 scsi_req->cdb[2] = 0;
431 scsi_req->cdb[3] = 0;
432 scsi_req->cdb[4] = 0;
433 scsi_req->cdb[5] = 0;
434 scsi_req->cdb[6] = 0;
435 scsi_req->cdb[7] = 0;
436 scsi_req->cdb[8] = 0;
437 scsi_req->cdb[9] = 0;
441 * Return true if and only if all pending requests should be failed.
443 static bool skd_fail_all(struct request_queue *q)
445 struct skd_device *skdev = q->queuedata;
447 SKD_ASSERT(skdev->state != SKD_DRVR_STATE_ONLINE);
449 skd_log_skdev(skdev, "req_not_online");
450 switch (skdev->state) {
451 case SKD_DRVR_STATE_PAUSING:
452 case SKD_DRVR_STATE_PAUSED:
453 case SKD_DRVR_STATE_STARTING:
454 case SKD_DRVR_STATE_RESTARTING:
455 case SKD_DRVR_STATE_WAIT_BOOT:
456 /* In case of starting, we haven't started the queue,
457 * so we can't get here... but requests are
458 * possibly hanging out waiting for us because we
459 * reported the dev/skd0 already. They'll wait
460 * forever if connect doesn't complete.
461 * What to do??? delay dev/skd0 ??
463 case SKD_DRVR_STATE_BUSY:
464 case SKD_DRVR_STATE_BUSY_IMMINENT:
465 case SKD_DRVR_STATE_BUSY_ERASE:
468 case SKD_DRVR_STATE_BUSY_SANITIZE:
469 case SKD_DRVR_STATE_STOPPING:
470 case SKD_DRVR_STATE_SYNCING:
471 case SKD_DRVR_STATE_FAULT:
472 case SKD_DRVR_STATE_DISAPPEARED:
478 static blk_status_t skd_mq_queue_rq(struct blk_mq_hw_ctx *hctx,
479 const struct blk_mq_queue_data *mqd)
481 struct request *const req = mqd->rq;
482 struct request_queue *const q = req->q;
483 struct skd_device *skdev = q->queuedata;
484 struct skd_fitmsg_context *skmsg;
485 struct fit_msg_hdr *fmh;
486 const u32 tag = blk_mq_unique_tag(req);
487 struct skd_request_context *const skreq = blk_mq_rq_to_pdu(req);
488 struct skd_scsi_request *scsi_req;
489 unsigned long flags = 0;
490 const u32 lba = blk_rq_pos(req);
491 const u32 count = blk_rq_sectors(req);
492 const int data_dir = rq_data_dir(req);
494 if (unlikely(skdev->state != SKD_DRVR_STATE_ONLINE))
495 return skd_fail_all(q) ? BLK_STS_IOERR : BLK_STS_RESOURCE;
497 if (!(req->rq_flags & RQF_DONTPREP)) {
499 req->rq_flags |= RQF_DONTPREP;
502 blk_mq_start_request(req);
504 WARN_ONCE(tag >= skd_max_queue_depth, "%#x > %#x (nr_requests = %lu)\n",
505 tag, skd_max_queue_depth, q->nr_requests);
507 SKD_ASSERT(skreq->state == SKD_REQ_STATE_IDLE);
509 dev_dbg(&skdev->pdev->dev,
510 "new req=%p lba=%u(0x%x) count=%u(0x%x) dir=%d\n", req, lba,
511 lba, count, count, data_dir);
513 skreq->id = tag + SKD_ID_RW_REQUEST;
514 skreq->flush_cmd = 0;
516 skreq->sg_byte_count = 0;
518 skreq->fitmsg_id = 0;
520 skreq->data_dir = data_dir == READ ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
522 if (req->bio && !skd_preop_sg_list(skdev, skreq)) {
523 dev_dbg(&skdev->pdev->dev, "error Out\n");
524 skreq->status = BLK_STS_RESOURCE;
525 blk_mq_complete_request(req);
529 dma_sync_single_for_device(&skdev->pdev->dev, skreq->sksg_dma_address,
531 sizeof(struct fit_sg_descriptor),
534 /* Either a FIT msg is in progress or we have to start one. */
535 if (skd_max_req_per_msg == 1) {
538 spin_lock_irqsave(&skdev->lock, flags);
539 skmsg = skdev->skmsg;
542 skmsg = &skdev->skmsg_table[tag];
543 skdev->skmsg = skmsg;
545 /* Initialize the FIT msg header */
546 fmh = &skmsg->msg_buf->fmh;
547 memset(fmh, 0, sizeof(*fmh));
548 fmh->protocol_id = FIT_PROTOCOL_ID_SOFIT;
549 skmsg->length = sizeof(*fmh);
551 fmh = &skmsg->msg_buf->fmh;
554 skreq->fitmsg_id = skmsg->id;
556 scsi_req = &skmsg->msg_buf->scsi[fmh->num_protocol_cmds_coalesced];
557 memset(scsi_req, 0, sizeof(*scsi_req));
559 scsi_req->hdr.tag = skreq->id;
560 scsi_req->hdr.sg_list_dma_address =
561 cpu_to_be64(skreq->sksg_dma_address);
563 if (req_op(req) == REQ_OP_FLUSH) {
564 skd_prep_zerosize_flush_cdb(scsi_req, skreq);
565 SKD_ASSERT(skreq->flush_cmd == 1);
567 skd_prep_rw_cdb(scsi_req, data_dir, lba, count);
570 if (req->cmd_flags & REQ_FUA)
571 scsi_req->cdb[1] |= SKD_FUA_NV;
573 scsi_req->hdr.sg_list_len_bytes = cpu_to_be32(skreq->sg_byte_count);
575 /* Complete resource allocations. */
576 skreq->state = SKD_REQ_STATE_BUSY;
578 skmsg->length += sizeof(struct skd_scsi_request);
579 fmh->num_protocol_cmds_coalesced++;
581 dev_dbg(&skdev->pdev->dev, "req=0x%x busy=%d\n", skreq->id,
582 skd_in_flight(skdev));
585 * If the FIT msg buffer is full send it.
587 if (skd_max_req_per_msg == 1) {
588 skd_send_fitmsg(skdev, skmsg);
591 fmh->num_protocol_cmds_coalesced >= skd_max_req_per_msg) {
592 skd_send_fitmsg(skdev, skmsg);
595 spin_unlock_irqrestore(&skdev->lock, flags);
601 static enum blk_eh_timer_return skd_timed_out(struct request *req,
604 struct skd_device *skdev = req->q->queuedata;
606 dev_err(&skdev->pdev->dev, "request with tag %#x timed out\n",
607 blk_mq_unique_tag(req));
609 return BLK_EH_RESET_TIMER;
612 static void skd_complete_rq(struct request *req)
614 struct skd_request_context *skreq = blk_mq_rq_to_pdu(req);
616 blk_mq_end_request(req, skreq->status);
619 static bool skd_preop_sg_list(struct skd_device *skdev,
620 struct skd_request_context *skreq)
622 struct request *req = blk_mq_rq_from_pdu(skreq);
623 struct scatterlist *sgl = &skreq->sg[0], *sg;
627 skreq->sg_byte_count = 0;
629 WARN_ON_ONCE(skreq->data_dir != DMA_TO_DEVICE &&
630 skreq->data_dir != DMA_FROM_DEVICE);
632 n_sg = blk_rq_map_sg(skdev->queue, req, sgl);
637 * Map scatterlist to PCI bus addresses.
638 * Note PCI might change the number of entries.
640 n_sg = dma_map_sg(&skdev->pdev->dev, sgl, n_sg, skreq->data_dir);
644 SKD_ASSERT(n_sg <= skdev->sgs_per_request);
648 for_each_sg(sgl, sg, n_sg, i) {
649 struct fit_sg_descriptor *sgd = &skreq->sksg_list[i];
650 u32 cnt = sg_dma_len(sg);
651 uint64_t dma_addr = sg_dma_address(sg);
653 sgd->control = FIT_SGD_CONTROL_NOT_LAST;
654 sgd->byte_count = cnt;
655 skreq->sg_byte_count += cnt;
656 sgd->host_side_addr = dma_addr;
657 sgd->dev_side_addr = 0;
660 skreq->sksg_list[n_sg - 1].next_desc_ptr = 0LL;
661 skreq->sksg_list[n_sg - 1].control = FIT_SGD_CONTROL_LAST;
663 if (unlikely(skdev->dbg_level > 1)) {
664 dev_dbg(&skdev->pdev->dev,
665 "skreq=%x sksg_list=%p sksg_dma=%pad\n",
666 skreq->id, skreq->sksg_list, &skreq->sksg_dma_address);
667 for (i = 0; i < n_sg; i++) {
668 struct fit_sg_descriptor *sgd = &skreq->sksg_list[i];
670 dev_dbg(&skdev->pdev->dev,
671 " sg[%d] count=%u ctrl=0x%x addr=0x%llx next=0x%llx\n",
672 i, sgd->byte_count, sgd->control,
673 sgd->host_side_addr, sgd->next_desc_ptr);
680 static void skd_postop_sg_list(struct skd_device *skdev,
681 struct skd_request_context *skreq)
684 * restore the next ptr for next IO request so we
685 * don't have to set it every time.
687 skreq->sksg_list[skreq->n_sg - 1].next_desc_ptr =
688 skreq->sksg_dma_address +
689 ((skreq->n_sg) * sizeof(struct fit_sg_descriptor));
690 dma_unmap_sg(&skdev->pdev->dev, &skreq->sg[0], skreq->n_sg,
695 *****************************************************************************
697 *****************************************************************************
700 static void skd_timer_tick_not_online(struct skd_device *skdev);
702 static void skd_start_queue(struct work_struct *work)
704 struct skd_device *skdev = container_of(work, typeof(*skdev),
708 * Although it is safe to call blk_start_queue() from interrupt
709 * context, blk_mq_start_hw_queues() must not be called from
712 blk_mq_start_hw_queues(skdev->queue);
715 static void skd_timer_tick(struct timer_list *t)
717 struct skd_device *skdev = from_timer(skdev, t, timer);
718 unsigned long reqflags;
721 if (skdev->state == SKD_DRVR_STATE_FAULT)
722 /* The driver has declared fault, and we want it to
723 * stay that way until driver is reloaded.
727 spin_lock_irqsave(&skdev->lock, reqflags);
729 state = SKD_READL(skdev, FIT_STATUS);
730 state &= FIT_SR_DRIVE_STATE_MASK;
731 if (state != skdev->drive_state)
732 skd_isr_fwstate(skdev);
734 if (skdev->state != SKD_DRVR_STATE_ONLINE)
735 skd_timer_tick_not_online(skdev);
737 mod_timer(&skdev->timer, (jiffies + HZ));
739 spin_unlock_irqrestore(&skdev->lock, reqflags);
742 static void skd_timer_tick_not_online(struct skd_device *skdev)
744 switch (skdev->state) {
745 case SKD_DRVR_STATE_IDLE:
746 case SKD_DRVR_STATE_LOAD:
748 case SKD_DRVR_STATE_BUSY_SANITIZE:
749 dev_dbg(&skdev->pdev->dev,
750 "drive busy sanitize[%x], driver[%x]\n",
751 skdev->drive_state, skdev->state);
752 /* If we've been in sanitize for 3 seconds, we figure we're not
753 * going to get anymore completions, so recover requests now
755 if (skdev->timer_countdown > 0) {
756 skdev->timer_countdown--;
759 skd_recover_requests(skdev);
762 case SKD_DRVR_STATE_BUSY:
763 case SKD_DRVR_STATE_BUSY_IMMINENT:
764 case SKD_DRVR_STATE_BUSY_ERASE:
765 dev_dbg(&skdev->pdev->dev, "busy[%x], countdown=%d\n",
766 skdev->state, skdev->timer_countdown);
767 if (skdev->timer_countdown > 0) {
768 skdev->timer_countdown--;
771 dev_dbg(&skdev->pdev->dev,
772 "busy[%x], timedout=%d, restarting device.",
773 skdev->state, skdev->timer_countdown);
774 skd_restart_device(skdev);
777 case SKD_DRVR_STATE_WAIT_BOOT:
778 case SKD_DRVR_STATE_STARTING:
779 if (skdev->timer_countdown > 0) {
780 skdev->timer_countdown--;
783 /* For now, we fault the drive. Could attempt resets to
784 * revcover at some point. */
785 skdev->state = SKD_DRVR_STATE_FAULT;
787 dev_err(&skdev->pdev->dev, "DriveFault Connect Timeout (%x)\n",
790 /*start the queue so we can respond with error to requests */
791 /* wakeup anyone waiting for startup complete */
792 schedule_work(&skdev->start_queue);
793 skdev->gendisk_on = -1;
794 wake_up_interruptible(&skdev->waitq);
797 case SKD_DRVR_STATE_ONLINE:
798 /* shouldn't get here. */
801 case SKD_DRVR_STATE_PAUSING:
802 case SKD_DRVR_STATE_PAUSED:
805 case SKD_DRVR_STATE_RESTARTING:
806 if (skdev->timer_countdown > 0) {
807 skdev->timer_countdown--;
810 /* For now, we fault the drive. Could attempt resets to
811 * revcover at some point. */
812 skdev->state = SKD_DRVR_STATE_FAULT;
813 dev_err(&skdev->pdev->dev,
814 "DriveFault Reconnect Timeout (%x)\n",
818 * Recovering does two things:
819 * 1. completes IO with error
820 * 2. reclaims dma resources
821 * When is it safe to recover requests?
822 * - if the drive state is faulted
823 * - if the state is still soft reset after out timeout
824 * - if the drive registers are dead (state = FF)
825 * If it is "unsafe", we still need to recover, so we will
826 * disable pci bus mastering and disable our interrupts.
829 if ((skdev->drive_state == FIT_SR_DRIVE_SOFT_RESET) ||
830 (skdev->drive_state == FIT_SR_DRIVE_FAULT) ||
831 (skdev->drive_state == FIT_SR_DRIVE_STATE_MASK))
832 /* It never came out of soft reset. Try to
833 * recover the requests and then let them
834 * fail. This is to mitigate hung processes. */
835 skd_recover_requests(skdev);
837 dev_err(&skdev->pdev->dev, "Disable BusMaster (%x)\n",
839 pci_disable_device(skdev->pdev);
840 skd_disable_interrupts(skdev);
841 skd_recover_requests(skdev);
844 /*start the queue so we can respond with error to requests */
845 /* wakeup anyone waiting for startup complete */
846 schedule_work(&skdev->start_queue);
847 skdev->gendisk_on = -1;
848 wake_up_interruptible(&skdev->waitq);
851 case SKD_DRVR_STATE_RESUMING:
852 case SKD_DRVR_STATE_STOPPING:
853 case SKD_DRVR_STATE_SYNCING:
854 case SKD_DRVR_STATE_FAULT:
855 case SKD_DRVR_STATE_DISAPPEARED:
861 static int skd_start_timer(struct skd_device *skdev)
865 timer_setup(&skdev->timer, skd_timer_tick, 0);
867 rc = mod_timer(&skdev->timer, (jiffies + HZ));
869 dev_err(&skdev->pdev->dev, "failed to start timer %d\n", rc);
873 static void skd_kill_timer(struct skd_device *skdev)
875 del_timer_sync(&skdev->timer);
879 *****************************************************************************
880 * INTERNAL REQUESTS -- generated by driver itself
881 *****************************************************************************
884 static int skd_format_internal_skspcl(struct skd_device *skdev)
886 struct skd_special_context *skspcl = &skdev->internal_skspcl;
887 struct fit_sg_descriptor *sgd = &skspcl->req.sksg_list[0];
888 struct fit_msg_hdr *fmh;
889 uint64_t dma_address;
890 struct skd_scsi_request *scsi;
892 fmh = &skspcl->msg_buf->fmh;
893 fmh->protocol_id = FIT_PROTOCOL_ID_SOFIT;
894 fmh->num_protocol_cmds_coalesced = 1;
896 scsi = &skspcl->msg_buf->scsi[0];
897 memset(scsi, 0, sizeof(*scsi));
898 dma_address = skspcl->req.sksg_dma_address;
899 scsi->hdr.sg_list_dma_address = cpu_to_be64(dma_address);
900 skspcl->req.n_sg = 1;
901 sgd->control = FIT_SGD_CONTROL_LAST;
903 sgd->host_side_addr = skspcl->db_dma_address;
904 sgd->dev_side_addr = 0;
905 sgd->next_desc_ptr = 0LL;
910 #define WR_BUF_SIZE SKD_N_INTERNAL_BYTES
912 static void skd_send_internal_skspcl(struct skd_device *skdev,
913 struct skd_special_context *skspcl,
916 struct fit_sg_descriptor *sgd = &skspcl->req.sksg_list[0];
917 struct skd_scsi_request *scsi;
918 unsigned char *buf = skspcl->data_buf;
921 if (skspcl->req.state != SKD_REQ_STATE_IDLE)
923 * A refresh is already in progress.
924 * Just wait for it to finish.
928 skspcl->req.state = SKD_REQ_STATE_BUSY;
930 scsi = &skspcl->msg_buf->scsi[0];
931 scsi->hdr.tag = skspcl->req.id;
933 memset(scsi->cdb, 0, sizeof(scsi->cdb));
936 case TEST_UNIT_READY:
937 scsi->cdb[0] = TEST_UNIT_READY;
939 scsi->hdr.sg_list_len_bytes = 0;
943 scsi->cdb[0] = READ_CAPACITY;
944 sgd->byte_count = SKD_N_READ_CAP_BYTES;
945 scsi->hdr.sg_list_len_bytes = cpu_to_be32(sgd->byte_count);
949 scsi->cdb[0] = INQUIRY;
950 scsi->cdb[1] = 0x01; /* evpd */
951 scsi->cdb[2] = 0x80; /* serial number page */
953 sgd->byte_count = 16;
954 scsi->hdr.sg_list_len_bytes = cpu_to_be32(sgd->byte_count);
957 case SYNCHRONIZE_CACHE:
958 scsi->cdb[0] = SYNCHRONIZE_CACHE;
960 scsi->hdr.sg_list_len_bytes = 0;
964 scsi->cdb[0] = WRITE_BUFFER;
966 scsi->cdb[7] = (WR_BUF_SIZE & 0xFF00) >> 8;
967 scsi->cdb[8] = WR_BUF_SIZE & 0xFF;
968 sgd->byte_count = WR_BUF_SIZE;
969 scsi->hdr.sg_list_len_bytes = cpu_to_be32(sgd->byte_count);
970 /* fill incrementing byte pattern */
971 for (i = 0; i < sgd->byte_count; i++)
976 scsi->cdb[0] = READ_BUFFER;
978 scsi->cdb[7] = (WR_BUF_SIZE & 0xFF00) >> 8;
979 scsi->cdb[8] = WR_BUF_SIZE & 0xFF;
980 sgd->byte_count = WR_BUF_SIZE;
981 scsi->hdr.sg_list_len_bytes = cpu_to_be32(sgd->byte_count);
982 memset(skspcl->data_buf, 0, sgd->byte_count);
986 SKD_ASSERT("Don't know what to send");
990 skd_send_special_fitmsg(skdev, skspcl);
993 static void skd_refresh_device_data(struct skd_device *skdev)
995 struct skd_special_context *skspcl = &skdev->internal_skspcl;
997 skd_send_internal_skspcl(skdev, skspcl, TEST_UNIT_READY);
1000 static int skd_chk_read_buf(struct skd_device *skdev,
1001 struct skd_special_context *skspcl)
1003 unsigned char *buf = skspcl->data_buf;
1006 /* check for incrementing byte pattern */
1007 for (i = 0; i < WR_BUF_SIZE; i++)
1008 if (buf[i] != (i & 0xFF))
1014 static void skd_log_check_status(struct skd_device *skdev, u8 status, u8 key,
1015 u8 code, u8 qual, u8 fruc)
1017 /* If the check condition is of special interest, log a message */
1018 if ((status == SAM_STAT_CHECK_CONDITION) && (key == 0x02)
1019 && (code == 0x04) && (qual == 0x06)) {
1020 dev_err(&skdev->pdev->dev,
1021 "*** LOST_WRITE_DATA ERROR *** key/asc/ascq/fruc %02x/%02x/%02x/%02x\n",
1022 key, code, qual, fruc);
1026 static void skd_complete_internal(struct skd_device *skdev,
1027 struct fit_completion_entry_v1 *skcomp,
1028 struct fit_comp_error_info *skerr,
1029 struct skd_special_context *skspcl)
1031 u8 *buf = skspcl->data_buf;
1034 struct skd_scsi_request *scsi = &skspcl->msg_buf->scsi[0];
1036 lockdep_assert_held(&skdev->lock);
1038 SKD_ASSERT(skspcl == &skdev->internal_skspcl);
1040 dev_dbg(&skdev->pdev->dev, "complete internal %x\n", scsi->cdb[0]);
1042 dma_sync_single_for_cpu(&skdev->pdev->dev,
1043 skspcl->db_dma_address,
1044 skspcl->req.sksg_list[0].byte_count,
1047 skspcl->req.completion = *skcomp;
1048 skspcl->req.state = SKD_REQ_STATE_IDLE;
1050 status = skspcl->req.completion.status;
1052 skd_log_check_status(skdev, status, skerr->key, skerr->code,
1053 skerr->qual, skerr->fruc);
1055 switch (scsi->cdb[0]) {
1056 case TEST_UNIT_READY:
1057 if (status == SAM_STAT_GOOD)
1058 skd_send_internal_skspcl(skdev, skspcl, WRITE_BUFFER);
1059 else if ((status == SAM_STAT_CHECK_CONDITION) &&
1060 (skerr->key == MEDIUM_ERROR))
1061 skd_send_internal_skspcl(skdev, skspcl, WRITE_BUFFER);
1063 if (skdev->state == SKD_DRVR_STATE_STOPPING) {
1064 dev_dbg(&skdev->pdev->dev,
1065 "TUR failed, don't send anymore state 0x%x\n",
1069 dev_dbg(&skdev->pdev->dev,
1070 "**** TUR failed, retry skerr\n");
1071 skd_send_internal_skspcl(skdev, skspcl,
1077 if (status == SAM_STAT_GOOD)
1078 skd_send_internal_skspcl(skdev, skspcl, READ_BUFFER);
1080 if (skdev->state == SKD_DRVR_STATE_STOPPING) {
1081 dev_dbg(&skdev->pdev->dev,
1082 "write buffer failed, don't send anymore state 0x%x\n",
1086 dev_dbg(&skdev->pdev->dev,
1087 "**** write buffer failed, retry skerr\n");
1088 skd_send_internal_skspcl(skdev, skspcl,
1094 if (status == SAM_STAT_GOOD) {
1095 if (skd_chk_read_buf(skdev, skspcl) == 0)
1096 skd_send_internal_skspcl(skdev, skspcl,
1099 dev_err(&skdev->pdev->dev,
1100 "*** W/R Buffer mismatch %d ***\n",
1101 skdev->connect_retries);
1102 if (skdev->connect_retries <
1103 SKD_MAX_CONNECT_RETRIES) {
1104 skdev->connect_retries++;
1105 skd_soft_reset(skdev);
1107 dev_err(&skdev->pdev->dev,
1108 "W/R Buffer Connect Error\n");
1114 if (skdev->state == SKD_DRVR_STATE_STOPPING) {
1115 dev_dbg(&skdev->pdev->dev,
1116 "read buffer failed, don't send anymore state 0x%x\n",
1120 dev_dbg(&skdev->pdev->dev,
1121 "**** read buffer failed, retry skerr\n");
1122 skd_send_internal_skspcl(skdev, skspcl,
1128 skdev->read_cap_is_valid = 0;
1129 if (status == SAM_STAT_GOOD) {
1130 skdev->read_cap_last_lba =
1131 (buf[0] << 24) | (buf[1] << 16) |
1132 (buf[2] << 8) | buf[3];
1133 skdev->read_cap_blocksize =
1134 (buf[4] << 24) | (buf[5] << 16) |
1135 (buf[6] << 8) | buf[7];
1137 dev_dbg(&skdev->pdev->dev, "last lba %d, bs %d\n",
1138 skdev->read_cap_last_lba,
1139 skdev->read_cap_blocksize);
1141 set_capacity(skdev->disk, skdev->read_cap_last_lba + 1);
1143 skdev->read_cap_is_valid = 1;
1145 skd_send_internal_skspcl(skdev, skspcl, INQUIRY);
1146 } else if ((status == SAM_STAT_CHECK_CONDITION) &&
1147 (skerr->key == MEDIUM_ERROR)) {
1148 skdev->read_cap_last_lba = ~0;
1149 set_capacity(skdev->disk, skdev->read_cap_last_lba + 1);
1150 dev_dbg(&skdev->pdev->dev, "**** MEDIUM ERROR caused READCAP to fail, ignore failure and continue to inquiry\n");
1151 skd_send_internal_skspcl(skdev, skspcl, INQUIRY);
1153 dev_dbg(&skdev->pdev->dev, "**** READCAP failed, retry TUR\n");
1154 skd_send_internal_skspcl(skdev, skspcl,
1160 skdev->inquiry_is_valid = 0;
1161 if (status == SAM_STAT_GOOD) {
1162 skdev->inquiry_is_valid = 1;
1164 for (i = 0; i < 12; i++)
1165 skdev->inq_serial_num[i] = buf[i + 4];
1166 skdev->inq_serial_num[12] = 0;
1169 if (skd_unquiesce_dev(skdev) < 0)
1170 dev_dbg(&skdev->pdev->dev, "**** failed, to ONLINE device\n");
1171 /* connection is complete */
1172 skdev->connect_retries = 0;
1175 case SYNCHRONIZE_CACHE:
1176 if (status == SAM_STAT_GOOD)
1177 skdev->sync_done = 1;
1179 skdev->sync_done = -1;
1180 wake_up_interruptible(&skdev->waitq);
1184 SKD_ASSERT("we didn't send this");
1189 *****************************************************************************
1191 *****************************************************************************
1194 static void skd_send_fitmsg(struct skd_device *skdev,
1195 struct skd_fitmsg_context *skmsg)
1199 dev_dbg(&skdev->pdev->dev, "dma address %pad, busy=%d\n",
1200 &skmsg->mb_dma_address, skd_in_flight(skdev));
1201 dev_dbg(&skdev->pdev->dev, "msg_buf %p\n", skmsg->msg_buf);
1203 qcmd = skmsg->mb_dma_address;
1204 qcmd |= FIT_QCMD_QID_NORMAL;
1206 if (unlikely(skdev->dbg_level > 1)) {
1207 u8 *bp = (u8 *)skmsg->msg_buf;
1209 for (i = 0; i < skmsg->length; i += 8) {
1210 dev_dbg(&skdev->pdev->dev, "msg[%2d] %8ph\n", i,
1217 if (skmsg->length > 256)
1218 qcmd |= FIT_QCMD_MSGSIZE_512;
1219 else if (skmsg->length > 128)
1220 qcmd |= FIT_QCMD_MSGSIZE_256;
1221 else if (skmsg->length > 64)
1222 qcmd |= FIT_QCMD_MSGSIZE_128;
1225 * This makes no sense because the FIT msg header is
1226 * 64 bytes. If the msg is only 64 bytes long it has
1229 qcmd |= FIT_QCMD_MSGSIZE_64;
1231 dma_sync_single_for_device(&skdev->pdev->dev, skmsg->mb_dma_address,
1232 skmsg->length, DMA_TO_DEVICE);
1234 /* Make sure skd_msg_buf is written before the doorbell is triggered. */
1237 SKD_WRITEQ(skdev, qcmd, FIT_Q_COMMAND);
1240 static void skd_send_special_fitmsg(struct skd_device *skdev,
1241 struct skd_special_context *skspcl)
1245 WARN_ON_ONCE(skspcl->req.n_sg != 1);
1247 if (unlikely(skdev->dbg_level > 1)) {
1248 u8 *bp = (u8 *)skspcl->msg_buf;
1251 for (i = 0; i < SKD_N_SPECIAL_FITMSG_BYTES; i += 8) {
1252 dev_dbg(&skdev->pdev->dev, " spcl[%2d] %8ph\n", i,
1258 dev_dbg(&skdev->pdev->dev,
1259 "skspcl=%p id=%04x sksg_list=%p sksg_dma=%pad\n",
1260 skspcl, skspcl->req.id, skspcl->req.sksg_list,
1261 &skspcl->req.sksg_dma_address);
1262 for (i = 0; i < skspcl->req.n_sg; i++) {
1263 struct fit_sg_descriptor *sgd =
1264 &skspcl->req.sksg_list[i];
1266 dev_dbg(&skdev->pdev->dev,
1267 " sg[%d] count=%u ctrl=0x%x addr=0x%llx next=0x%llx\n",
1268 i, sgd->byte_count, sgd->control,
1269 sgd->host_side_addr, sgd->next_desc_ptr);
1274 * Special FIT msgs are always 128 bytes: a 64-byte FIT hdr
1275 * and one 64-byte SSDI command.
1277 qcmd = skspcl->mb_dma_address;
1278 qcmd |= FIT_QCMD_QID_NORMAL + FIT_QCMD_MSGSIZE_128;
1280 dma_sync_single_for_device(&skdev->pdev->dev, skspcl->mb_dma_address,
1281 SKD_N_SPECIAL_FITMSG_BYTES, DMA_TO_DEVICE);
1282 dma_sync_single_for_device(&skdev->pdev->dev,
1283 skspcl->req.sksg_dma_address,
1284 1 * sizeof(struct fit_sg_descriptor),
1286 dma_sync_single_for_device(&skdev->pdev->dev,
1287 skspcl->db_dma_address,
1288 skspcl->req.sksg_list[0].byte_count,
1291 /* Make sure skd_msg_buf is written before the doorbell is triggered. */
1294 SKD_WRITEQ(skdev, qcmd, FIT_Q_COMMAND);
1298 *****************************************************************************
1300 *****************************************************************************
1303 static void skd_complete_other(struct skd_device *skdev,
1304 struct fit_completion_entry_v1 *skcomp,
1305 struct fit_comp_error_info *skerr);
1314 enum skd_check_status_action action;
1317 static struct sns_info skd_chkstat_table[] = {
1319 { 0x70, 0x02, RECOVERED_ERROR, 0, 0, 0x1c,
1320 SKD_CHECK_STATUS_REPORT_GOOD },
1323 { 0x70, 0x02, NO_SENSE, 0x0B, 0x00, 0x1E, /* warnings */
1324 SKD_CHECK_STATUS_REPORT_SMART_ALERT },
1325 { 0x70, 0x02, NO_SENSE, 0x5D, 0x00, 0x1E, /* thresholds */
1326 SKD_CHECK_STATUS_REPORT_SMART_ALERT },
1327 { 0x70, 0x02, RECOVERED_ERROR, 0x0B, 0x01, 0x1F, /* temperature over trigger */
1328 SKD_CHECK_STATUS_REPORT_SMART_ALERT },
1330 /* Retry (with limits) */
1331 { 0x70, 0x02, 0x0B, 0, 0, 0x1C, /* This one is for DMA ERROR */
1332 SKD_CHECK_STATUS_REQUEUE_REQUEST },
1333 { 0x70, 0x02, 0x06, 0x0B, 0x00, 0x1E, /* warnings */
1334 SKD_CHECK_STATUS_REQUEUE_REQUEST },
1335 { 0x70, 0x02, 0x06, 0x5D, 0x00, 0x1E, /* thresholds */
1336 SKD_CHECK_STATUS_REQUEUE_REQUEST },
1337 { 0x70, 0x02, 0x06, 0x80, 0x30, 0x1F, /* backup power */
1338 SKD_CHECK_STATUS_REQUEUE_REQUEST },
1340 /* Busy (or about to be) */
1341 { 0x70, 0x02, 0x06, 0x3f, 0x01, 0x1F, /* fw changed */
1342 SKD_CHECK_STATUS_BUSY_IMMINENT },
1346 * Look up status and sense data to decide how to handle the error
1348 * mask says which fields must match e.g., mask=0x18 means check
1349 * type and stat, ignore key, asc, ascq.
1352 static enum skd_check_status_action
1353 skd_check_status(struct skd_device *skdev,
1354 u8 cmp_status, struct fit_comp_error_info *skerr)
1358 dev_err(&skdev->pdev->dev, "key/asc/ascq/fruc %02x/%02x/%02x/%02x\n",
1359 skerr->key, skerr->code, skerr->qual, skerr->fruc);
1361 dev_dbg(&skdev->pdev->dev,
1362 "stat: t=%02x stat=%02x k=%02x c=%02x q=%02x fruc=%02x\n",
1363 skerr->type, cmp_status, skerr->key, skerr->code, skerr->qual,
1366 /* Does the info match an entry in the good category? */
1367 for (i = 0; i < ARRAY_SIZE(skd_chkstat_table); i++) {
1368 struct sns_info *sns = &skd_chkstat_table[i];
1370 if (sns->mask & 0x10)
1371 if (skerr->type != sns->type)
1374 if (sns->mask & 0x08)
1375 if (cmp_status != sns->stat)
1378 if (sns->mask & 0x04)
1379 if (skerr->key != sns->key)
1382 if (sns->mask & 0x02)
1383 if (skerr->code != sns->asc)
1386 if (sns->mask & 0x01)
1387 if (skerr->qual != sns->ascq)
1390 if (sns->action == SKD_CHECK_STATUS_REPORT_SMART_ALERT) {
1391 dev_err(&skdev->pdev->dev,
1392 "SMART Alert: sense key/asc/ascq %02x/%02x/%02x\n",
1393 skerr->key, skerr->code, skerr->qual);
1398 /* No other match, so nonzero status means error,
1399 * zero status means good
1402 dev_dbg(&skdev->pdev->dev, "status check: error\n");
1403 return SKD_CHECK_STATUS_REPORT_ERROR;
1406 dev_dbg(&skdev->pdev->dev, "status check good default\n");
1407 return SKD_CHECK_STATUS_REPORT_GOOD;
1410 static void skd_resolve_req_exception(struct skd_device *skdev,
1411 struct skd_request_context *skreq,
1412 struct request *req)
1414 u8 cmp_status = skreq->completion.status;
1416 switch (skd_check_status(skdev, cmp_status, &skreq->err_info)) {
1417 case SKD_CHECK_STATUS_REPORT_GOOD:
1418 case SKD_CHECK_STATUS_REPORT_SMART_ALERT:
1419 skreq->status = BLK_STS_OK;
1420 blk_mq_complete_request(req);
1423 case SKD_CHECK_STATUS_BUSY_IMMINENT:
1424 skd_log_skreq(skdev, skreq, "retry(busy)");
1425 blk_mq_requeue_request(req, true);
1426 dev_info(&skdev->pdev->dev, "drive BUSY imminent\n");
1427 skdev->state = SKD_DRVR_STATE_BUSY_IMMINENT;
1428 skdev->timer_countdown = SKD_TIMER_MINUTES(20);
1429 skd_quiesce_dev(skdev);
1432 case SKD_CHECK_STATUS_REQUEUE_REQUEST:
1433 if (++skreq->retries < SKD_MAX_RETRIES) {
1434 skd_log_skreq(skdev, skreq, "retry");
1435 blk_mq_requeue_request(req, true);
1440 case SKD_CHECK_STATUS_REPORT_ERROR:
1442 skreq->status = BLK_STS_IOERR;
1443 blk_mq_complete_request(req);
1448 static void skd_release_skreq(struct skd_device *skdev,
1449 struct skd_request_context *skreq)
1452 * Reclaim the skd_request_context
1454 skreq->state = SKD_REQ_STATE_IDLE;
1457 static int skd_isr_completion_posted(struct skd_device *skdev,
1458 int limit, int *enqueued)
1460 struct fit_completion_entry_v1 *skcmp;
1461 struct fit_comp_error_info *skerr;
1466 struct skd_request_context *skreq;
1474 lockdep_assert_held(&skdev->lock);
1477 SKD_ASSERT(skdev->skcomp_ix < SKD_N_COMPLETION_ENTRY);
1479 skcmp = &skdev->skcomp_table[skdev->skcomp_ix];
1480 cmp_cycle = skcmp->cycle;
1481 cmp_cntxt = skcmp->tag;
1482 cmp_status = skcmp->status;
1483 cmp_bytes = be32_to_cpu(skcmp->num_returned_bytes);
1485 skerr = &skdev->skerr_table[skdev->skcomp_ix];
1487 dev_dbg(&skdev->pdev->dev,
1488 "cycle=%d ix=%d got cycle=%d cmdctxt=0x%x stat=%d busy=%d rbytes=0x%x proto=%d\n",
1489 skdev->skcomp_cycle, skdev->skcomp_ix, cmp_cycle,
1490 cmp_cntxt, cmp_status, skd_in_flight(skdev),
1491 cmp_bytes, skdev->proto_ver);
1493 if (cmp_cycle != skdev->skcomp_cycle) {
1494 dev_dbg(&skdev->pdev->dev, "end of completions\n");
1498 * Update the completion queue head index and possibly
1499 * the completion cycle count. 8-bit wrap-around.
1502 if (skdev->skcomp_ix >= SKD_N_COMPLETION_ENTRY) {
1503 skdev->skcomp_ix = 0;
1504 skdev->skcomp_cycle++;
1508 * The command context is a unique 32-bit ID. The low order
1509 * bits help locate the request. The request is usually a
1510 * r/w request (see skd_start() above) or a special request.
1513 tag = req_id & SKD_ID_SLOT_AND_TABLE_MASK;
1515 /* Is this other than a r/w request? */
1516 if (tag >= skdev->num_req_context) {
1518 * This is not a completion for a r/w request.
1520 WARN_ON_ONCE(blk_mq_tag_to_rq(skdev->tag_set.tags[hwq],
1522 skd_complete_other(skdev, skcmp, skerr);
1526 rq = blk_mq_tag_to_rq(skdev->tag_set.tags[hwq], tag);
1527 if (WARN(!rq, "No request for tag %#x -> %#x\n", cmp_cntxt,
1530 skreq = blk_mq_rq_to_pdu(rq);
1533 * Make sure the request ID for the slot matches.
1535 if (skreq->id != req_id) {
1536 dev_err(&skdev->pdev->dev,
1537 "Completion mismatch comp_id=0x%04x skreq=0x%04x new=0x%04x\n",
1538 req_id, skreq->id, cmp_cntxt);
1543 SKD_ASSERT(skreq->state == SKD_REQ_STATE_BUSY);
1545 skreq->completion = *skcmp;
1546 if (unlikely(cmp_status == SAM_STAT_CHECK_CONDITION)) {
1547 skreq->err_info = *skerr;
1548 skd_log_check_status(skdev, cmp_status, skerr->key,
1549 skerr->code, skerr->qual,
1552 /* Release DMA resources for the request. */
1553 if (skreq->n_sg > 0)
1554 skd_postop_sg_list(skdev, skreq);
1556 skd_release_skreq(skdev, skreq);
1559 * Capture the outcome and post it back to the native request.
1561 if (likely(cmp_status == SAM_STAT_GOOD)) {
1562 skreq->status = BLK_STS_OK;
1563 blk_mq_complete_request(rq);
1565 skd_resolve_req_exception(skdev, skreq, rq);
1568 /* skd_isr_comp_limit equal zero means no limit */
1570 if (++processed >= limit) {
1577 if (skdev->state == SKD_DRVR_STATE_PAUSING &&
1578 skd_in_flight(skdev) == 0) {
1579 skdev->state = SKD_DRVR_STATE_PAUSED;
1580 wake_up_interruptible(&skdev->waitq);
1586 static void skd_complete_other(struct skd_device *skdev,
1587 struct fit_completion_entry_v1 *skcomp,
1588 struct fit_comp_error_info *skerr)
1593 struct skd_special_context *skspcl;
1595 lockdep_assert_held(&skdev->lock);
1597 req_id = skcomp->tag;
1598 req_table = req_id & SKD_ID_TABLE_MASK;
1599 req_slot = req_id & SKD_ID_SLOT_MASK;
1601 dev_dbg(&skdev->pdev->dev, "table=0x%x id=0x%x slot=%d\n", req_table,
1605 * Based on the request id, determine how to dispatch this completion.
1606 * This swich/case is finding the good cases and forwarding the
1607 * completion entry. Errors are reported below the switch.
1609 switch (req_table) {
1610 case SKD_ID_RW_REQUEST:
1612 * The caller, skd_isr_completion_posted() above,
1613 * handles r/w requests. The only way we get here
1614 * is if the req_slot is out of bounds.
1618 case SKD_ID_INTERNAL:
1619 if (req_slot == 0) {
1620 skspcl = &skdev->internal_skspcl;
1621 if (skspcl->req.id == req_id &&
1622 skspcl->req.state == SKD_REQ_STATE_BUSY) {
1623 skd_complete_internal(skdev,
1624 skcomp, skerr, skspcl);
1630 case SKD_ID_FIT_MSG:
1632 * These id's should never appear in a completion record.
1638 * These id's should never appear anywhere;
1644 * If we get here it is a bad or stale id.
1648 static void skd_reset_skcomp(struct skd_device *skdev)
1650 memset(skdev->skcomp_table, 0, SKD_SKCOMP_SIZE);
1652 skdev->skcomp_ix = 0;
1653 skdev->skcomp_cycle = 1;
1657 *****************************************************************************
1659 *****************************************************************************
1661 static void skd_completion_worker(struct work_struct *work)
1663 struct skd_device *skdev =
1664 container_of(work, struct skd_device, completion_worker);
1665 unsigned long flags;
1666 int flush_enqueued = 0;
1668 spin_lock_irqsave(&skdev->lock, flags);
1671 * pass in limit=0, which means no limit..
1672 * process everything in compq
1674 skd_isr_completion_posted(skdev, 0, &flush_enqueued);
1675 schedule_work(&skdev->start_queue);
1677 spin_unlock_irqrestore(&skdev->lock, flags);
1680 static void skd_isr_msg_from_dev(struct skd_device *skdev);
1683 skd_isr(int irq, void *ptr)
1685 struct skd_device *skdev = ptr;
1690 int flush_enqueued = 0;
1692 spin_lock(&skdev->lock);
1695 intstat = SKD_READL(skdev, FIT_INT_STATUS_HOST);
1697 ack = FIT_INT_DEF_MASK;
1700 dev_dbg(&skdev->pdev->dev, "intstat=0x%x ack=0x%x\n", intstat,
1703 /* As long as there is an int pending on device, keep
1704 * running loop. When none, get out, but if we've never
1705 * done any processing, call completion handler?
1708 /* No interrupts on device, but run the completion
1712 if (likely (skdev->state
1713 == SKD_DRVR_STATE_ONLINE))
1720 SKD_WRITEL(skdev, ack, FIT_INT_STATUS_HOST);
1722 if (likely((skdev->state != SKD_DRVR_STATE_LOAD) &&
1723 (skdev->state != SKD_DRVR_STATE_STOPPING))) {
1724 if (intstat & FIT_ISH_COMPLETION_POSTED) {
1726 * If we have already deferred completion
1727 * processing, don't bother running it again
1731 skd_isr_completion_posted(skdev,
1732 skd_isr_comp_limit, &flush_enqueued);
1735 if (intstat & FIT_ISH_FW_STATE_CHANGE) {
1736 skd_isr_fwstate(skdev);
1737 if (skdev->state == SKD_DRVR_STATE_FAULT ||
1739 SKD_DRVR_STATE_DISAPPEARED) {
1740 spin_unlock(&skdev->lock);
1745 if (intstat & FIT_ISH_MSG_FROM_DEV)
1746 skd_isr_msg_from_dev(skdev);
1750 if (unlikely(flush_enqueued))
1751 schedule_work(&skdev->start_queue);
1754 schedule_work(&skdev->completion_worker);
1755 else if (!flush_enqueued)
1756 schedule_work(&skdev->start_queue);
1758 spin_unlock(&skdev->lock);
1763 static void skd_drive_fault(struct skd_device *skdev)
1765 skdev->state = SKD_DRVR_STATE_FAULT;
1766 dev_err(&skdev->pdev->dev, "Drive FAULT\n");
1769 static void skd_drive_disappeared(struct skd_device *skdev)
1771 skdev->state = SKD_DRVR_STATE_DISAPPEARED;
1772 dev_err(&skdev->pdev->dev, "Drive DISAPPEARED\n");
1775 static void skd_isr_fwstate(struct skd_device *skdev)
1780 int prev_driver_state = skdev->state;
1782 sense = SKD_READL(skdev, FIT_STATUS);
1783 state = sense & FIT_SR_DRIVE_STATE_MASK;
1785 dev_err(&skdev->pdev->dev, "s1120 state %s(%d)=>%s(%d)\n",
1786 skd_drive_state_to_str(skdev->drive_state), skdev->drive_state,
1787 skd_drive_state_to_str(state), state);
1789 skdev->drive_state = state;
1791 switch (skdev->drive_state) {
1792 case FIT_SR_DRIVE_INIT:
1793 if (skdev->state == SKD_DRVR_STATE_PROTOCOL_MISMATCH) {
1794 skd_disable_interrupts(skdev);
1797 if (skdev->state == SKD_DRVR_STATE_RESTARTING)
1798 skd_recover_requests(skdev);
1799 if (skdev->state == SKD_DRVR_STATE_WAIT_BOOT) {
1800 skdev->timer_countdown = SKD_STARTING_TIMO;
1801 skdev->state = SKD_DRVR_STATE_STARTING;
1802 skd_soft_reset(skdev);
1805 mtd = FIT_MXD_CONS(FIT_MTD_FITFW_INIT, 0, 0);
1806 SKD_WRITEL(skdev, mtd, FIT_MSG_TO_DEVICE);
1807 skdev->last_mtd = mtd;
1810 case FIT_SR_DRIVE_ONLINE:
1811 skdev->cur_max_queue_depth = skd_max_queue_depth;
1812 if (skdev->cur_max_queue_depth > skdev->dev_max_queue_depth)
1813 skdev->cur_max_queue_depth = skdev->dev_max_queue_depth;
1815 skdev->queue_low_water_mark =
1816 skdev->cur_max_queue_depth * 2 / 3 + 1;
1817 if (skdev->queue_low_water_mark < 1)
1818 skdev->queue_low_water_mark = 1;
1819 dev_info(&skdev->pdev->dev,
1820 "Queue depth limit=%d dev=%d lowat=%d\n",
1821 skdev->cur_max_queue_depth,
1822 skdev->dev_max_queue_depth,
1823 skdev->queue_low_water_mark);
1825 skd_refresh_device_data(skdev);
1828 case FIT_SR_DRIVE_BUSY:
1829 skdev->state = SKD_DRVR_STATE_BUSY;
1830 skdev->timer_countdown = SKD_BUSY_TIMO;
1831 skd_quiesce_dev(skdev);
1833 case FIT_SR_DRIVE_BUSY_SANITIZE:
1834 /* set timer for 3 seconds, we'll abort any unfinished
1835 * commands after that expires
1837 skdev->state = SKD_DRVR_STATE_BUSY_SANITIZE;
1838 skdev->timer_countdown = SKD_TIMER_SECONDS(3);
1839 schedule_work(&skdev->start_queue);
1841 case FIT_SR_DRIVE_BUSY_ERASE:
1842 skdev->state = SKD_DRVR_STATE_BUSY_ERASE;
1843 skdev->timer_countdown = SKD_BUSY_TIMO;
1845 case FIT_SR_DRIVE_OFFLINE:
1846 skdev->state = SKD_DRVR_STATE_IDLE;
1848 case FIT_SR_DRIVE_SOFT_RESET:
1849 switch (skdev->state) {
1850 case SKD_DRVR_STATE_STARTING:
1851 case SKD_DRVR_STATE_RESTARTING:
1852 /* Expected by a caller of skd_soft_reset() */
1855 skdev->state = SKD_DRVR_STATE_RESTARTING;
1859 case FIT_SR_DRIVE_FW_BOOTING:
1860 dev_dbg(&skdev->pdev->dev, "ISR FIT_SR_DRIVE_FW_BOOTING\n");
1861 skdev->state = SKD_DRVR_STATE_WAIT_BOOT;
1862 skdev->timer_countdown = SKD_WAIT_BOOT_TIMO;
1865 case FIT_SR_DRIVE_DEGRADED:
1866 case FIT_SR_PCIE_LINK_DOWN:
1867 case FIT_SR_DRIVE_NEED_FW_DOWNLOAD:
1870 case FIT_SR_DRIVE_FAULT:
1871 skd_drive_fault(skdev);
1872 skd_recover_requests(skdev);
1873 schedule_work(&skdev->start_queue);
1876 /* PCIe bus returned all Fs? */
1878 dev_info(&skdev->pdev->dev, "state=0x%x sense=0x%x\n", state,
1880 skd_drive_disappeared(skdev);
1881 skd_recover_requests(skdev);
1882 schedule_work(&skdev->start_queue);
1886 * Uknown FW State. Wait for a state we recognize.
1890 dev_err(&skdev->pdev->dev, "Driver state %s(%d)=>%s(%d)\n",
1891 skd_skdev_state_to_str(prev_driver_state), prev_driver_state,
1892 skd_skdev_state_to_str(skdev->state), skdev->state);
1895 static bool skd_recover_request(struct request *req, void *data, bool reserved)
1897 struct skd_device *const skdev = data;
1898 struct skd_request_context *skreq = blk_mq_rq_to_pdu(req);
1900 if (skreq->state != SKD_REQ_STATE_BUSY)
1903 skd_log_skreq(skdev, skreq, "recover");
1905 /* Release DMA resources for the request. */
1906 if (skreq->n_sg > 0)
1907 skd_postop_sg_list(skdev, skreq);
1909 skreq->state = SKD_REQ_STATE_IDLE;
1910 skreq->status = BLK_STS_IOERR;
1911 blk_mq_complete_request(req);
1915 static void skd_recover_requests(struct skd_device *skdev)
1917 blk_mq_tagset_busy_iter(&skdev->tag_set, skd_recover_request, skdev);
1920 static void skd_isr_msg_from_dev(struct skd_device *skdev)
1926 mfd = SKD_READL(skdev, FIT_MSG_FROM_DEVICE);
1928 dev_dbg(&skdev->pdev->dev, "mfd=0x%x last_mtd=0x%x\n", mfd,
1931 /* ignore any mtd that is an ack for something we didn't send */
1932 if (FIT_MXD_TYPE(mfd) != FIT_MXD_TYPE(skdev->last_mtd))
1935 switch (FIT_MXD_TYPE(mfd)) {
1936 case FIT_MTD_FITFW_INIT:
1937 skdev->proto_ver = FIT_PROTOCOL_MAJOR_VER(mfd);
1939 if (skdev->proto_ver != FIT_PROTOCOL_VERSION_1) {
1940 dev_err(&skdev->pdev->dev, "protocol mismatch\n");
1941 dev_err(&skdev->pdev->dev, " got=%d support=%d\n",
1942 skdev->proto_ver, FIT_PROTOCOL_VERSION_1);
1943 dev_err(&skdev->pdev->dev, " please upgrade driver\n");
1944 skdev->state = SKD_DRVR_STATE_PROTOCOL_MISMATCH;
1945 skd_soft_reset(skdev);
1948 mtd = FIT_MXD_CONS(FIT_MTD_GET_CMDQ_DEPTH, 0, 0);
1949 SKD_WRITEL(skdev, mtd, FIT_MSG_TO_DEVICE);
1950 skdev->last_mtd = mtd;
1953 case FIT_MTD_GET_CMDQ_DEPTH:
1954 skdev->dev_max_queue_depth = FIT_MXD_DATA(mfd);
1955 mtd = FIT_MXD_CONS(FIT_MTD_SET_COMPQ_DEPTH, 0,
1956 SKD_N_COMPLETION_ENTRY);
1957 SKD_WRITEL(skdev, mtd, FIT_MSG_TO_DEVICE);
1958 skdev->last_mtd = mtd;
1961 case FIT_MTD_SET_COMPQ_DEPTH:
1962 SKD_WRITEQ(skdev, skdev->cq_dma_address, FIT_MSG_TO_DEVICE_ARG);
1963 mtd = FIT_MXD_CONS(FIT_MTD_SET_COMPQ_ADDR, 0, 0);
1964 SKD_WRITEL(skdev, mtd, FIT_MSG_TO_DEVICE);
1965 skdev->last_mtd = mtd;
1968 case FIT_MTD_SET_COMPQ_ADDR:
1969 skd_reset_skcomp(skdev);
1970 mtd = FIT_MXD_CONS(FIT_MTD_CMD_LOG_HOST_ID, 0, skdev->devno);
1971 SKD_WRITEL(skdev, mtd, FIT_MSG_TO_DEVICE);
1972 skdev->last_mtd = mtd;
1975 case FIT_MTD_CMD_LOG_HOST_ID:
1976 /* hardware interface overflows in y2106 */
1977 skdev->connect_time_stamp = (u32)ktime_get_real_seconds();
1978 data = skdev->connect_time_stamp & 0xFFFF;
1979 mtd = FIT_MXD_CONS(FIT_MTD_CMD_LOG_TIME_STAMP_LO, 0, data);
1980 SKD_WRITEL(skdev, mtd, FIT_MSG_TO_DEVICE);
1981 skdev->last_mtd = mtd;
1984 case FIT_MTD_CMD_LOG_TIME_STAMP_LO:
1985 skdev->drive_jiffies = FIT_MXD_DATA(mfd);
1986 data = (skdev->connect_time_stamp >> 16) & 0xFFFF;
1987 mtd = FIT_MXD_CONS(FIT_MTD_CMD_LOG_TIME_STAMP_HI, 0, data);
1988 SKD_WRITEL(skdev, mtd, FIT_MSG_TO_DEVICE);
1989 skdev->last_mtd = mtd;
1992 case FIT_MTD_CMD_LOG_TIME_STAMP_HI:
1993 skdev->drive_jiffies |= (FIT_MXD_DATA(mfd) << 16);
1994 mtd = FIT_MXD_CONS(FIT_MTD_ARM_QUEUE, 0, 0);
1995 SKD_WRITEL(skdev, mtd, FIT_MSG_TO_DEVICE);
1996 skdev->last_mtd = mtd;
1998 dev_err(&skdev->pdev->dev, "Time sync driver=0x%x device=0x%x\n",
1999 skdev->connect_time_stamp, skdev->drive_jiffies);
2002 case FIT_MTD_ARM_QUEUE:
2003 skdev->last_mtd = 0;
2005 * State should be, or soon will be, FIT_SR_DRIVE_ONLINE.
2014 static void skd_disable_interrupts(struct skd_device *skdev)
2018 sense = SKD_READL(skdev, FIT_CONTROL);
2019 sense &= ~FIT_CR_ENABLE_INTERRUPTS;
2020 SKD_WRITEL(skdev, sense, FIT_CONTROL);
2021 dev_dbg(&skdev->pdev->dev, "sense 0x%x\n", sense);
2023 /* Note that the 1s is written. A 1-bit means
2024 * disable, a 0 means enable.
2026 SKD_WRITEL(skdev, ~0, FIT_INT_MASK_HOST);
2029 static void skd_enable_interrupts(struct skd_device *skdev)
2033 /* unmask interrupts first */
2034 val = FIT_ISH_FW_STATE_CHANGE +
2035 FIT_ISH_COMPLETION_POSTED + FIT_ISH_MSG_FROM_DEV;
2037 /* Note that the compliment of mask is written. A 1-bit means
2038 * disable, a 0 means enable. */
2039 SKD_WRITEL(skdev, ~val, FIT_INT_MASK_HOST);
2040 dev_dbg(&skdev->pdev->dev, "interrupt mask=0x%x\n", ~val);
2042 val = SKD_READL(skdev, FIT_CONTROL);
2043 val |= FIT_CR_ENABLE_INTERRUPTS;
2044 dev_dbg(&skdev->pdev->dev, "control=0x%x\n", val);
2045 SKD_WRITEL(skdev, val, FIT_CONTROL);
2049 *****************************************************************************
2050 * START, STOP, RESTART, QUIESCE, UNQUIESCE
2051 *****************************************************************************
2054 static void skd_soft_reset(struct skd_device *skdev)
2058 val = SKD_READL(skdev, FIT_CONTROL);
2059 val |= (FIT_CR_SOFT_RESET);
2060 dev_dbg(&skdev->pdev->dev, "control=0x%x\n", val);
2061 SKD_WRITEL(skdev, val, FIT_CONTROL);
2064 static void skd_start_device(struct skd_device *skdev)
2066 unsigned long flags;
2070 spin_lock_irqsave(&skdev->lock, flags);
2072 /* ack all ghost interrupts */
2073 SKD_WRITEL(skdev, FIT_INT_DEF_MASK, FIT_INT_STATUS_HOST);
2075 sense = SKD_READL(skdev, FIT_STATUS);
2077 dev_dbg(&skdev->pdev->dev, "initial status=0x%x\n", sense);
2079 state = sense & FIT_SR_DRIVE_STATE_MASK;
2080 skdev->drive_state = state;
2081 skdev->last_mtd = 0;
2083 skdev->state = SKD_DRVR_STATE_STARTING;
2084 skdev->timer_countdown = SKD_STARTING_TIMO;
2086 skd_enable_interrupts(skdev);
2088 switch (skdev->drive_state) {
2089 case FIT_SR_DRIVE_OFFLINE:
2090 dev_err(&skdev->pdev->dev, "Drive offline...\n");
2093 case FIT_SR_DRIVE_FW_BOOTING:
2094 dev_dbg(&skdev->pdev->dev, "FIT_SR_DRIVE_FW_BOOTING\n");
2095 skdev->state = SKD_DRVR_STATE_WAIT_BOOT;
2096 skdev->timer_countdown = SKD_WAIT_BOOT_TIMO;
2099 case FIT_SR_DRIVE_BUSY_SANITIZE:
2100 dev_info(&skdev->pdev->dev, "Start: BUSY_SANITIZE\n");
2101 skdev->state = SKD_DRVR_STATE_BUSY_SANITIZE;
2102 skdev->timer_countdown = SKD_STARTED_BUSY_TIMO;
2105 case FIT_SR_DRIVE_BUSY_ERASE:
2106 dev_info(&skdev->pdev->dev, "Start: BUSY_ERASE\n");
2107 skdev->state = SKD_DRVR_STATE_BUSY_ERASE;
2108 skdev->timer_countdown = SKD_STARTED_BUSY_TIMO;
2111 case FIT_SR_DRIVE_INIT:
2112 case FIT_SR_DRIVE_ONLINE:
2113 skd_soft_reset(skdev);
2116 case FIT_SR_DRIVE_BUSY:
2117 dev_err(&skdev->pdev->dev, "Drive Busy...\n");
2118 skdev->state = SKD_DRVR_STATE_BUSY;
2119 skdev->timer_countdown = SKD_STARTED_BUSY_TIMO;
2122 case FIT_SR_DRIVE_SOFT_RESET:
2123 dev_err(&skdev->pdev->dev, "drive soft reset in prog\n");
2126 case FIT_SR_DRIVE_FAULT:
2127 /* Fault state is bad...soft reset won't do it...
2128 * Hard reset, maybe, but does it work on device?
2129 * For now, just fault so the system doesn't hang.
2131 skd_drive_fault(skdev);
2132 /*start the queue so we can respond with error to requests */
2133 dev_dbg(&skdev->pdev->dev, "starting queue\n");
2134 schedule_work(&skdev->start_queue);
2135 skdev->gendisk_on = -1;
2136 wake_up_interruptible(&skdev->waitq);
2140 /* Most likely the device isn't there or isn't responding
2141 * to the BAR1 addresses. */
2142 skd_drive_disappeared(skdev);
2143 /*start the queue so we can respond with error to requests */
2144 dev_dbg(&skdev->pdev->dev,
2145 "starting queue to error-out reqs\n");
2146 schedule_work(&skdev->start_queue);
2147 skdev->gendisk_on = -1;
2148 wake_up_interruptible(&skdev->waitq);
2152 dev_err(&skdev->pdev->dev, "Start: unknown state %x\n",
2153 skdev->drive_state);
2157 state = SKD_READL(skdev, FIT_CONTROL);
2158 dev_dbg(&skdev->pdev->dev, "FIT Control Status=0x%x\n", state);
2160 state = SKD_READL(skdev, FIT_INT_STATUS_HOST);
2161 dev_dbg(&skdev->pdev->dev, "Intr Status=0x%x\n", state);
2163 state = SKD_READL(skdev, FIT_INT_MASK_HOST);
2164 dev_dbg(&skdev->pdev->dev, "Intr Mask=0x%x\n", state);
2166 state = SKD_READL(skdev, FIT_MSG_FROM_DEVICE);
2167 dev_dbg(&skdev->pdev->dev, "Msg from Dev=0x%x\n", state);
2169 state = SKD_READL(skdev, FIT_HW_VERSION);
2170 dev_dbg(&skdev->pdev->dev, "HW version=0x%x\n", state);
2172 spin_unlock_irqrestore(&skdev->lock, flags);
2175 static void skd_stop_device(struct skd_device *skdev)
2177 unsigned long flags;
2178 struct skd_special_context *skspcl = &skdev->internal_skspcl;
2182 spin_lock_irqsave(&skdev->lock, flags);
2184 if (skdev->state != SKD_DRVR_STATE_ONLINE) {
2185 dev_err(&skdev->pdev->dev, "%s not online no sync\n", __func__);
2189 if (skspcl->req.state != SKD_REQ_STATE_IDLE) {
2190 dev_err(&skdev->pdev->dev, "%s no special\n", __func__);
2194 skdev->state = SKD_DRVR_STATE_SYNCING;
2195 skdev->sync_done = 0;
2197 skd_send_internal_skspcl(skdev, skspcl, SYNCHRONIZE_CACHE);
2199 spin_unlock_irqrestore(&skdev->lock, flags);
2201 wait_event_interruptible_timeout(skdev->waitq,
2202 (skdev->sync_done), (10 * HZ));
2204 spin_lock_irqsave(&skdev->lock, flags);
2206 switch (skdev->sync_done) {
2208 dev_err(&skdev->pdev->dev, "%s no sync\n", __func__);
2211 dev_err(&skdev->pdev->dev, "%s sync done\n", __func__);
2214 dev_err(&skdev->pdev->dev, "%s sync error\n", __func__);
2218 skdev->state = SKD_DRVR_STATE_STOPPING;
2219 spin_unlock_irqrestore(&skdev->lock, flags);
2221 skd_kill_timer(skdev);
2223 spin_lock_irqsave(&skdev->lock, flags);
2224 skd_disable_interrupts(skdev);
2226 /* ensure all ints on device are cleared */
2227 /* soft reset the device to unload with a clean slate */
2228 SKD_WRITEL(skdev, FIT_INT_DEF_MASK, FIT_INT_STATUS_HOST);
2229 SKD_WRITEL(skdev, FIT_CR_SOFT_RESET, FIT_CONTROL);
2231 spin_unlock_irqrestore(&skdev->lock, flags);
2233 /* poll every 100ms, 1 second timeout */
2234 for (i = 0; i < 10; i++) {
2236 SKD_READL(skdev, FIT_STATUS) & FIT_SR_DRIVE_STATE_MASK;
2237 if (dev_state == FIT_SR_DRIVE_INIT)
2239 set_current_state(TASK_INTERRUPTIBLE);
2240 schedule_timeout(msecs_to_jiffies(100));
2243 if (dev_state != FIT_SR_DRIVE_INIT)
2244 dev_err(&skdev->pdev->dev, "%s state error 0x%02x\n", __func__,
2248 /* assume spinlock is held */
2249 static void skd_restart_device(struct skd_device *skdev)
2253 /* ack all ghost interrupts */
2254 SKD_WRITEL(skdev, FIT_INT_DEF_MASK, FIT_INT_STATUS_HOST);
2256 state = SKD_READL(skdev, FIT_STATUS);
2258 dev_dbg(&skdev->pdev->dev, "drive status=0x%x\n", state);
2260 state &= FIT_SR_DRIVE_STATE_MASK;
2261 skdev->drive_state = state;
2262 skdev->last_mtd = 0;
2264 skdev->state = SKD_DRVR_STATE_RESTARTING;
2265 skdev->timer_countdown = SKD_RESTARTING_TIMO;
2267 skd_soft_reset(skdev);
2270 /* assume spinlock is held */
2271 static int skd_quiesce_dev(struct skd_device *skdev)
2275 switch (skdev->state) {
2276 case SKD_DRVR_STATE_BUSY:
2277 case SKD_DRVR_STATE_BUSY_IMMINENT:
2278 dev_dbg(&skdev->pdev->dev, "stopping queue\n");
2279 blk_mq_stop_hw_queues(skdev->queue);
2281 case SKD_DRVR_STATE_ONLINE:
2282 case SKD_DRVR_STATE_STOPPING:
2283 case SKD_DRVR_STATE_SYNCING:
2284 case SKD_DRVR_STATE_PAUSING:
2285 case SKD_DRVR_STATE_PAUSED:
2286 case SKD_DRVR_STATE_STARTING:
2287 case SKD_DRVR_STATE_RESTARTING:
2288 case SKD_DRVR_STATE_RESUMING:
2291 dev_dbg(&skdev->pdev->dev, "state [%d] not implemented\n",
2297 /* assume spinlock is held */
2298 static int skd_unquiesce_dev(struct skd_device *skdev)
2300 int prev_driver_state = skdev->state;
2302 skd_log_skdev(skdev, "unquiesce");
2303 if (skdev->state == SKD_DRVR_STATE_ONLINE) {
2304 dev_dbg(&skdev->pdev->dev, "**** device already ONLINE\n");
2307 if (skdev->drive_state != FIT_SR_DRIVE_ONLINE) {
2309 * If there has been an state change to other than
2310 * ONLINE, we will rely on controller state change
2311 * to come back online and restart the queue.
2312 * The BUSY state means that driver is ready to
2313 * continue normal processing but waiting for controller
2314 * to become available.
2316 skdev->state = SKD_DRVR_STATE_BUSY;
2317 dev_dbg(&skdev->pdev->dev, "drive BUSY state\n");
2322 * Drive has just come online, driver is either in startup,
2323 * paused performing a task, or bust waiting for hardware.
2325 switch (skdev->state) {
2326 case SKD_DRVR_STATE_PAUSED:
2327 case SKD_DRVR_STATE_BUSY:
2328 case SKD_DRVR_STATE_BUSY_IMMINENT:
2329 case SKD_DRVR_STATE_BUSY_ERASE:
2330 case SKD_DRVR_STATE_STARTING:
2331 case SKD_DRVR_STATE_RESTARTING:
2332 case SKD_DRVR_STATE_FAULT:
2333 case SKD_DRVR_STATE_IDLE:
2334 case SKD_DRVR_STATE_LOAD:
2335 skdev->state = SKD_DRVR_STATE_ONLINE;
2336 dev_err(&skdev->pdev->dev, "Driver state %s(%d)=>%s(%d)\n",
2337 skd_skdev_state_to_str(prev_driver_state),
2338 prev_driver_state, skd_skdev_state_to_str(skdev->state),
2340 dev_dbg(&skdev->pdev->dev,
2341 "**** device ONLINE...starting block queue\n");
2342 dev_dbg(&skdev->pdev->dev, "starting queue\n");
2343 dev_info(&skdev->pdev->dev, "STEC s1120 ONLINE\n");
2344 schedule_work(&skdev->start_queue);
2345 skdev->gendisk_on = 1;
2346 wake_up_interruptible(&skdev->waitq);
2349 case SKD_DRVR_STATE_DISAPPEARED:
2351 dev_dbg(&skdev->pdev->dev,
2352 "**** driver state %d, not implemented\n",
2360 *****************************************************************************
2361 * PCIe MSI/MSI-X INTERRUPT HANDLERS
2362 *****************************************************************************
2365 static irqreturn_t skd_reserved_isr(int irq, void *skd_host_data)
2367 struct skd_device *skdev = skd_host_data;
2368 unsigned long flags;
2370 spin_lock_irqsave(&skdev->lock, flags);
2371 dev_dbg(&skdev->pdev->dev, "MSIX = 0x%x\n",
2372 SKD_READL(skdev, FIT_INT_STATUS_HOST));
2373 dev_err(&skdev->pdev->dev, "MSIX reserved irq %d = 0x%x\n", irq,
2374 SKD_READL(skdev, FIT_INT_STATUS_HOST));
2375 SKD_WRITEL(skdev, FIT_INT_RESERVED_MASK, FIT_INT_STATUS_HOST);
2376 spin_unlock_irqrestore(&skdev->lock, flags);
2380 static irqreturn_t skd_statec_isr(int irq, void *skd_host_data)
2382 struct skd_device *skdev = skd_host_data;
2383 unsigned long flags;
2385 spin_lock_irqsave(&skdev->lock, flags);
2386 dev_dbg(&skdev->pdev->dev, "MSIX = 0x%x\n",
2387 SKD_READL(skdev, FIT_INT_STATUS_HOST));
2388 SKD_WRITEL(skdev, FIT_ISH_FW_STATE_CHANGE, FIT_INT_STATUS_HOST);
2389 skd_isr_fwstate(skdev);
2390 spin_unlock_irqrestore(&skdev->lock, flags);
2394 static irqreturn_t skd_comp_q(int irq, void *skd_host_data)
2396 struct skd_device *skdev = skd_host_data;
2397 unsigned long flags;
2398 int flush_enqueued = 0;
2401 spin_lock_irqsave(&skdev->lock, flags);
2402 dev_dbg(&skdev->pdev->dev, "MSIX = 0x%x\n",
2403 SKD_READL(skdev, FIT_INT_STATUS_HOST));
2404 SKD_WRITEL(skdev, FIT_ISH_COMPLETION_POSTED, FIT_INT_STATUS_HOST);
2405 deferred = skd_isr_completion_posted(skdev, skd_isr_comp_limit,
2408 schedule_work(&skdev->start_queue);
2411 schedule_work(&skdev->completion_worker);
2412 else if (!flush_enqueued)
2413 schedule_work(&skdev->start_queue);
2415 spin_unlock_irqrestore(&skdev->lock, flags);
2420 static irqreturn_t skd_msg_isr(int irq, void *skd_host_data)
2422 struct skd_device *skdev = skd_host_data;
2423 unsigned long flags;
2425 spin_lock_irqsave(&skdev->lock, flags);
2426 dev_dbg(&skdev->pdev->dev, "MSIX = 0x%x\n",
2427 SKD_READL(skdev, FIT_INT_STATUS_HOST));
2428 SKD_WRITEL(skdev, FIT_ISH_MSG_FROM_DEV, FIT_INT_STATUS_HOST);
2429 skd_isr_msg_from_dev(skdev);
2430 spin_unlock_irqrestore(&skdev->lock, flags);
2434 static irqreturn_t skd_qfull_isr(int irq, void *skd_host_data)
2436 struct skd_device *skdev = skd_host_data;
2437 unsigned long flags;
2439 spin_lock_irqsave(&skdev->lock, flags);
2440 dev_dbg(&skdev->pdev->dev, "MSIX = 0x%x\n",
2441 SKD_READL(skdev, FIT_INT_STATUS_HOST));
2442 SKD_WRITEL(skdev, FIT_INT_QUEUE_FULL, FIT_INT_STATUS_HOST);
2443 spin_unlock_irqrestore(&skdev->lock, flags);
2448 *****************************************************************************
2449 * PCIe MSI/MSI-X SETUP
2450 *****************************************************************************
2453 struct skd_msix_entry {
2457 struct skd_init_msix_entry {
2459 irq_handler_t handler;
2462 #define SKD_MAX_MSIX_COUNT 13
2463 #define SKD_MIN_MSIX_COUNT 7
2464 #define SKD_BASE_MSIX_IRQ 4
2466 static struct skd_init_msix_entry msix_entries[SKD_MAX_MSIX_COUNT] = {
2467 { "(DMA 0)", skd_reserved_isr },
2468 { "(DMA 1)", skd_reserved_isr },
2469 { "(DMA 2)", skd_reserved_isr },
2470 { "(DMA 3)", skd_reserved_isr },
2471 { "(State Change)", skd_statec_isr },
2472 { "(COMPL_Q)", skd_comp_q },
2473 { "(MSG)", skd_msg_isr },
2474 { "(Reserved)", skd_reserved_isr },
2475 { "(Reserved)", skd_reserved_isr },
2476 { "(Queue Full 0)", skd_qfull_isr },
2477 { "(Queue Full 1)", skd_qfull_isr },
2478 { "(Queue Full 2)", skd_qfull_isr },
2479 { "(Queue Full 3)", skd_qfull_isr },
2482 static int skd_acquire_msix(struct skd_device *skdev)
2485 struct pci_dev *pdev = skdev->pdev;
2487 rc = pci_alloc_irq_vectors(pdev, SKD_MAX_MSIX_COUNT, SKD_MAX_MSIX_COUNT,
2490 dev_err(&skdev->pdev->dev, "failed to enable MSI-X %d\n", rc);
2494 skdev->msix_entries = kcalloc(SKD_MAX_MSIX_COUNT,
2495 sizeof(struct skd_msix_entry), GFP_KERNEL);
2496 if (!skdev->msix_entries) {
2498 dev_err(&skdev->pdev->dev, "msix table allocation error\n");
2502 /* Enable MSI-X vectors for the base queue */
2503 for (i = 0; i < SKD_MAX_MSIX_COUNT; i++) {
2504 struct skd_msix_entry *qentry = &skdev->msix_entries[i];
2506 snprintf(qentry->isr_name, sizeof(qentry->isr_name),
2507 "%s%d-msix %s", DRV_NAME, skdev->devno,
2508 msix_entries[i].name);
2510 rc = devm_request_irq(&skdev->pdev->dev,
2511 pci_irq_vector(skdev->pdev, i),
2512 msix_entries[i].handler, 0,
2513 qentry->isr_name, skdev);
2515 dev_err(&skdev->pdev->dev,
2516 "Unable to register(%d) MSI-X handler %d: %s\n",
2517 rc, i, qentry->isr_name);
2522 dev_dbg(&skdev->pdev->dev, "%d msix irq(s) enabled\n",
2523 SKD_MAX_MSIX_COUNT);
2528 devm_free_irq(&pdev->dev, pci_irq_vector(pdev, i), skdev);
2530 kfree(skdev->msix_entries);
2531 skdev->msix_entries = NULL;
2535 static int skd_acquire_irq(struct skd_device *skdev)
2537 struct pci_dev *pdev = skdev->pdev;
2538 unsigned int irq_flag = PCI_IRQ_LEGACY;
2541 if (skd_isr_type == SKD_IRQ_MSIX) {
2542 rc = skd_acquire_msix(skdev);
2546 dev_err(&skdev->pdev->dev,
2547 "failed to enable MSI-X, re-trying with MSI %d\n", rc);
2550 snprintf(skdev->isr_name, sizeof(skdev->isr_name), "%s%d", DRV_NAME,
2553 if (skd_isr_type != SKD_IRQ_LEGACY)
2554 irq_flag |= PCI_IRQ_MSI;
2555 rc = pci_alloc_irq_vectors(pdev, 1, 1, irq_flag);
2557 dev_err(&skdev->pdev->dev,
2558 "failed to allocate the MSI interrupt %d\n", rc);
2562 rc = devm_request_irq(&pdev->dev, pdev->irq, skd_isr,
2563 pdev->msi_enabled ? 0 : IRQF_SHARED,
2564 skdev->isr_name, skdev);
2566 pci_free_irq_vectors(pdev);
2567 dev_err(&skdev->pdev->dev, "failed to allocate interrupt %d\n",
2575 static void skd_release_irq(struct skd_device *skdev)
2577 struct pci_dev *pdev = skdev->pdev;
2579 if (skdev->msix_entries) {
2582 for (i = 0; i < SKD_MAX_MSIX_COUNT; i++) {
2583 devm_free_irq(&pdev->dev, pci_irq_vector(pdev, i),
2587 kfree(skdev->msix_entries);
2588 skdev->msix_entries = NULL;
2590 devm_free_irq(&pdev->dev, pdev->irq, skdev);
2593 pci_free_irq_vectors(pdev);
2597 *****************************************************************************
2599 *****************************************************************************
2602 static void *skd_alloc_dma(struct skd_device *skdev, struct kmem_cache *s,
2603 dma_addr_t *dma_handle, gfp_t gfp,
2604 enum dma_data_direction dir)
2606 struct device *dev = &skdev->pdev->dev;
2609 buf = kmem_cache_alloc(s, gfp);
2612 *dma_handle = dma_map_single(dev, buf,
2613 kmem_cache_size(s), dir);
2614 if (dma_mapping_error(dev, *dma_handle)) {
2615 kmem_cache_free(s, buf);
2621 static void skd_free_dma(struct skd_device *skdev, struct kmem_cache *s,
2622 void *vaddr, dma_addr_t dma_handle,
2623 enum dma_data_direction dir)
2628 dma_unmap_single(&skdev->pdev->dev, dma_handle,
2629 kmem_cache_size(s), dir);
2630 kmem_cache_free(s, vaddr);
2633 static int skd_cons_skcomp(struct skd_device *skdev)
2636 struct fit_completion_entry_v1 *skcomp;
2638 dev_dbg(&skdev->pdev->dev,
2639 "comp pci_alloc, total bytes %zd entries %d\n",
2640 SKD_SKCOMP_SIZE, SKD_N_COMPLETION_ENTRY);
2642 skcomp = dma_alloc_coherent(&skdev->pdev->dev, SKD_SKCOMP_SIZE,
2643 &skdev->cq_dma_address, GFP_KERNEL);
2645 if (skcomp == NULL) {
2650 skdev->skcomp_table = skcomp;
2651 skdev->skerr_table = (struct fit_comp_error_info *)((char *)skcomp +
2653 SKD_N_COMPLETION_ENTRY);
2659 static int skd_cons_skmsg(struct skd_device *skdev)
2664 dev_dbg(&skdev->pdev->dev,
2665 "skmsg_table kcalloc, struct %lu, count %u total %lu\n",
2666 sizeof(struct skd_fitmsg_context), skdev->num_fitmsg_context,
2667 sizeof(struct skd_fitmsg_context) * skdev->num_fitmsg_context);
2669 skdev->skmsg_table = kcalloc(skdev->num_fitmsg_context,
2670 sizeof(struct skd_fitmsg_context),
2672 if (skdev->skmsg_table == NULL) {
2677 for (i = 0; i < skdev->num_fitmsg_context; i++) {
2678 struct skd_fitmsg_context *skmsg;
2680 skmsg = &skdev->skmsg_table[i];
2682 skmsg->id = i + SKD_ID_FIT_MSG;
2684 skmsg->msg_buf = dma_alloc_coherent(&skdev->pdev->dev,
2686 &skmsg->mb_dma_address,
2688 if (skmsg->msg_buf == NULL) {
2693 WARN(((uintptr_t)skmsg->msg_buf | skmsg->mb_dma_address) &
2694 (FIT_QCMD_ALIGN - 1),
2695 "not aligned: msg_buf %p mb_dma_address %pad\n",
2696 skmsg->msg_buf, &skmsg->mb_dma_address);
2703 static struct fit_sg_descriptor *skd_cons_sg_list(struct skd_device *skdev,
2705 dma_addr_t *ret_dma_addr)
2707 struct fit_sg_descriptor *sg_list;
2709 sg_list = skd_alloc_dma(skdev, skdev->sglist_cache, ret_dma_addr,
2710 GFP_DMA | __GFP_ZERO, DMA_TO_DEVICE);
2712 if (sg_list != NULL) {
2713 uint64_t dma_address = *ret_dma_addr;
2716 for (i = 0; i < n_sg - 1; i++) {
2718 ndp_off = (i + 1) * sizeof(struct fit_sg_descriptor);
2720 sg_list[i].next_desc_ptr = dma_address + ndp_off;
2722 sg_list[i].next_desc_ptr = 0LL;
2728 static void skd_free_sg_list(struct skd_device *skdev,
2729 struct fit_sg_descriptor *sg_list,
2730 dma_addr_t dma_addr)
2732 if (WARN_ON_ONCE(!sg_list))
2735 skd_free_dma(skdev, skdev->sglist_cache, sg_list, dma_addr,
2739 static int skd_init_request(struct blk_mq_tag_set *set, struct request *rq,
2740 unsigned int hctx_idx, unsigned int numa_node)
2742 struct skd_device *skdev = set->driver_data;
2743 struct skd_request_context *skreq = blk_mq_rq_to_pdu(rq);
2745 skreq->state = SKD_REQ_STATE_IDLE;
2746 skreq->sg = (void *)(skreq + 1);
2747 sg_init_table(skreq->sg, skd_sgs_per_request);
2748 skreq->sksg_list = skd_cons_sg_list(skdev, skd_sgs_per_request,
2749 &skreq->sksg_dma_address);
2751 return skreq->sksg_list ? 0 : -ENOMEM;
2754 static void skd_exit_request(struct blk_mq_tag_set *set, struct request *rq,
2755 unsigned int hctx_idx)
2757 struct skd_device *skdev = set->driver_data;
2758 struct skd_request_context *skreq = blk_mq_rq_to_pdu(rq);
2760 skd_free_sg_list(skdev, skreq->sksg_list, skreq->sksg_dma_address);
2763 static int skd_cons_sksb(struct skd_device *skdev)
2766 struct skd_special_context *skspcl;
2768 skspcl = &skdev->internal_skspcl;
2770 skspcl->req.id = 0 + SKD_ID_INTERNAL;
2771 skspcl->req.state = SKD_REQ_STATE_IDLE;
2773 skspcl->data_buf = skd_alloc_dma(skdev, skdev->databuf_cache,
2774 &skspcl->db_dma_address,
2775 GFP_DMA | __GFP_ZERO,
2777 if (skspcl->data_buf == NULL) {
2782 skspcl->msg_buf = skd_alloc_dma(skdev, skdev->msgbuf_cache,
2783 &skspcl->mb_dma_address,
2784 GFP_DMA | __GFP_ZERO, DMA_TO_DEVICE);
2785 if (skspcl->msg_buf == NULL) {
2790 skspcl->req.sksg_list = skd_cons_sg_list(skdev, 1,
2791 &skspcl->req.sksg_dma_address);
2792 if (skspcl->req.sksg_list == NULL) {
2797 if (!skd_format_internal_skspcl(skdev)) {
2806 static const struct blk_mq_ops skd_mq_ops = {
2807 .queue_rq = skd_mq_queue_rq,
2808 .complete = skd_complete_rq,
2809 .timeout = skd_timed_out,
2810 .init_request = skd_init_request,
2811 .exit_request = skd_exit_request,
2814 static int skd_cons_disk(struct skd_device *skdev)
2817 struct gendisk *disk;
2818 struct request_queue *q;
2819 unsigned long flags;
2821 disk = alloc_disk(SKD_MINORS_PER_DEVICE);
2828 sprintf(disk->disk_name, DRV_NAME "%u", skdev->devno);
2830 disk->major = skdev->major;
2831 disk->first_minor = skdev->devno * SKD_MINORS_PER_DEVICE;
2832 disk->fops = &skd_blockdev_ops;
2833 disk->private_data = skdev;
2835 memset(&skdev->tag_set, 0, sizeof(skdev->tag_set));
2836 skdev->tag_set.ops = &skd_mq_ops;
2837 skdev->tag_set.nr_hw_queues = 1;
2838 skdev->tag_set.queue_depth = skd_max_queue_depth;
2839 skdev->tag_set.cmd_size = sizeof(struct skd_request_context) +
2840 skdev->sgs_per_request * sizeof(struct scatterlist);
2841 skdev->tag_set.numa_node = NUMA_NO_NODE;
2842 skdev->tag_set.flags = BLK_MQ_F_SHOULD_MERGE |
2843 BLK_ALLOC_POLICY_TO_MQ_FLAG(BLK_TAG_ALLOC_FIFO);
2844 skdev->tag_set.driver_data = skdev;
2845 rc = blk_mq_alloc_tag_set(&skdev->tag_set);
2848 q = blk_mq_init_queue(&skdev->tag_set);
2850 blk_mq_free_tag_set(&skdev->tag_set);
2854 q->queuedata = skdev;
2859 blk_queue_write_cache(q, true, true);
2860 blk_queue_max_segments(q, skdev->sgs_per_request);
2861 blk_queue_max_hw_sectors(q, SKD_N_MAX_SECTORS);
2863 /* set optimal I/O size to 8KB */
2864 blk_queue_io_opt(q, 8192);
2866 blk_queue_flag_set(QUEUE_FLAG_NONROT, q);
2867 blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, q);
2869 blk_queue_rq_timeout(q, 8 * HZ);
2871 spin_lock_irqsave(&skdev->lock, flags);
2872 dev_dbg(&skdev->pdev->dev, "stopping queue\n");
2873 blk_mq_stop_hw_queues(skdev->queue);
2874 spin_unlock_irqrestore(&skdev->lock, flags);
2880 #define SKD_N_DEV_TABLE 16u
2881 static u32 skd_next_devno;
2883 static struct skd_device *skd_construct(struct pci_dev *pdev)
2885 struct skd_device *skdev;
2886 int blk_major = skd_major;
2890 skdev = kzalloc(sizeof(*skdev), GFP_KERNEL);
2893 dev_err(&pdev->dev, "memory alloc failure\n");
2897 skdev->state = SKD_DRVR_STATE_LOAD;
2899 skdev->devno = skd_next_devno++;
2900 skdev->major = blk_major;
2901 skdev->dev_max_queue_depth = 0;
2903 skdev->num_req_context = skd_max_queue_depth;
2904 skdev->num_fitmsg_context = skd_max_queue_depth;
2905 skdev->cur_max_queue_depth = 1;
2906 skdev->queue_low_water_mark = 1;
2907 skdev->proto_ver = 99;
2908 skdev->sgs_per_request = skd_sgs_per_request;
2909 skdev->dbg_level = skd_dbg_level;
2911 spin_lock_init(&skdev->lock);
2913 INIT_WORK(&skdev->start_queue, skd_start_queue);
2914 INIT_WORK(&skdev->completion_worker, skd_completion_worker);
2916 size = max(SKD_N_FITMSG_BYTES, SKD_N_SPECIAL_FITMSG_BYTES);
2917 skdev->msgbuf_cache = kmem_cache_create("skd-msgbuf", size, 0,
2918 SLAB_HWCACHE_ALIGN, NULL);
2919 if (!skdev->msgbuf_cache)
2921 WARN_ONCE(kmem_cache_size(skdev->msgbuf_cache) < size,
2922 "skd-msgbuf: %d < %zd\n",
2923 kmem_cache_size(skdev->msgbuf_cache), size);
2924 size = skd_sgs_per_request * sizeof(struct fit_sg_descriptor);
2925 skdev->sglist_cache = kmem_cache_create("skd-sglist", size, 0,
2926 SLAB_HWCACHE_ALIGN, NULL);
2927 if (!skdev->sglist_cache)
2929 WARN_ONCE(kmem_cache_size(skdev->sglist_cache) < size,
2930 "skd-sglist: %d < %zd\n",
2931 kmem_cache_size(skdev->sglist_cache), size);
2932 size = SKD_N_INTERNAL_BYTES;
2933 skdev->databuf_cache = kmem_cache_create("skd-databuf", size, 0,
2934 SLAB_HWCACHE_ALIGN, NULL);
2935 if (!skdev->databuf_cache)
2937 WARN_ONCE(kmem_cache_size(skdev->databuf_cache) < size,
2938 "skd-databuf: %d < %zd\n",
2939 kmem_cache_size(skdev->databuf_cache), size);
2941 dev_dbg(&skdev->pdev->dev, "skcomp\n");
2942 rc = skd_cons_skcomp(skdev);
2946 dev_dbg(&skdev->pdev->dev, "skmsg\n");
2947 rc = skd_cons_skmsg(skdev);
2951 dev_dbg(&skdev->pdev->dev, "sksb\n");
2952 rc = skd_cons_sksb(skdev);
2956 dev_dbg(&skdev->pdev->dev, "disk\n");
2957 rc = skd_cons_disk(skdev);
2961 dev_dbg(&skdev->pdev->dev, "VICTORY\n");
2965 dev_dbg(&skdev->pdev->dev, "construct failed\n");
2966 skd_destruct(skdev);
2971 *****************************************************************************
2973 *****************************************************************************
2976 static void skd_free_skcomp(struct skd_device *skdev)
2978 if (skdev->skcomp_table)
2979 dma_free_coherent(&skdev->pdev->dev, SKD_SKCOMP_SIZE,
2980 skdev->skcomp_table, skdev->cq_dma_address);
2982 skdev->skcomp_table = NULL;
2983 skdev->cq_dma_address = 0;
2986 static void skd_free_skmsg(struct skd_device *skdev)
2990 if (skdev->skmsg_table == NULL)
2993 for (i = 0; i < skdev->num_fitmsg_context; i++) {
2994 struct skd_fitmsg_context *skmsg;
2996 skmsg = &skdev->skmsg_table[i];
2998 if (skmsg->msg_buf != NULL) {
2999 dma_free_coherent(&skdev->pdev->dev, SKD_N_FITMSG_BYTES,
3001 skmsg->mb_dma_address);
3003 skmsg->msg_buf = NULL;
3004 skmsg->mb_dma_address = 0;
3007 kfree(skdev->skmsg_table);
3008 skdev->skmsg_table = NULL;
3011 static void skd_free_sksb(struct skd_device *skdev)
3013 struct skd_special_context *skspcl = &skdev->internal_skspcl;
3015 skd_free_dma(skdev, skdev->databuf_cache, skspcl->data_buf,
3016 skspcl->db_dma_address, DMA_BIDIRECTIONAL);
3018 skspcl->data_buf = NULL;
3019 skspcl->db_dma_address = 0;
3021 skd_free_dma(skdev, skdev->msgbuf_cache, skspcl->msg_buf,
3022 skspcl->mb_dma_address, DMA_TO_DEVICE);
3024 skspcl->msg_buf = NULL;
3025 skspcl->mb_dma_address = 0;
3027 skd_free_sg_list(skdev, skspcl->req.sksg_list,
3028 skspcl->req.sksg_dma_address);
3030 skspcl->req.sksg_list = NULL;
3031 skspcl->req.sksg_dma_address = 0;
3034 static void skd_free_disk(struct skd_device *skdev)
3036 struct gendisk *disk = skdev->disk;
3038 if (disk && (disk->flags & GENHD_FL_UP))
3042 blk_cleanup_queue(skdev->queue);
3043 skdev->queue = NULL;
3048 if (skdev->tag_set.tags)
3049 blk_mq_free_tag_set(&skdev->tag_set);
3055 static void skd_destruct(struct skd_device *skdev)
3060 cancel_work_sync(&skdev->start_queue);
3062 dev_dbg(&skdev->pdev->dev, "disk\n");
3063 skd_free_disk(skdev);
3065 dev_dbg(&skdev->pdev->dev, "sksb\n");
3066 skd_free_sksb(skdev);
3068 dev_dbg(&skdev->pdev->dev, "skmsg\n");
3069 skd_free_skmsg(skdev);
3071 dev_dbg(&skdev->pdev->dev, "skcomp\n");
3072 skd_free_skcomp(skdev);
3074 kmem_cache_destroy(skdev->databuf_cache);
3075 kmem_cache_destroy(skdev->sglist_cache);
3076 kmem_cache_destroy(skdev->msgbuf_cache);
3078 dev_dbg(&skdev->pdev->dev, "skdev\n");
3083 *****************************************************************************
3084 * BLOCK DEVICE (BDEV) GLUE
3085 *****************************************************************************
3088 static int skd_bdev_getgeo(struct block_device *bdev, struct hd_geometry *geo)
3090 struct skd_device *skdev;
3093 skdev = bdev->bd_disk->private_data;
3095 dev_dbg(&skdev->pdev->dev, "%s: CMD[%s] getgeo device\n",
3096 bdev->bd_disk->disk_name, current->comm);
3098 if (skdev->read_cap_is_valid) {
3099 capacity = get_capacity(skdev->disk);
3102 geo->cylinders = (capacity) / (255 * 64);
3109 static int skd_bdev_attach(struct device *parent, struct skd_device *skdev)
3111 dev_dbg(&skdev->pdev->dev, "add_disk\n");
3112 device_add_disk(parent, skdev->disk, NULL);
3116 static const struct block_device_operations skd_blockdev_ops = {
3117 .owner = THIS_MODULE,
3118 .getgeo = skd_bdev_getgeo,
3122 *****************************************************************************
3124 *****************************************************************************
3127 static const struct pci_device_id skd_pci_tbl[] = {
3128 { PCI_VENDOR_ID_STEC, PCI_DEVICE_ID_S1120,
3129 PCI_ANY_ID, PCI_ANY_ID, 0, 0, },
3130 { 0 } /* terminate list */
3133 MODULE_DEVICE_TABLE(pci, skd_pci_tbl);
3135 static char *skd_pci_info(struct skd_device *skdev, char *str)
3139 strcpy(str, "PCIe (");
3140 pcie_reg = pci_find_capability(skdev->pdev, PCI_CAP_ID_EXP);
3145 uint16_t pcie_lstat, lspeed, lwidth;
3148 pci_read_config_word(skdev->pdev, pcie_reg, &pcie_lstat);
3149 lspeed = pcie_lstat & (0xF);
3150 lwidth = (pcie_lstat & 0x3F0) >> 4;
3153 strcat(str, "2.5GT/s ");
3154 else if (lspeed == 2)
3155 strcat(str, "5.0GT/s ");
3157 strcat(str, "<unknown> ");
3158 snprintf(lwstr, sizeof(lwstr), "%dX)", lwidth);
3164 static int skd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
3169 struct skd_device *skdev;
3171 dev_dbg(&pdev->dev, "vendor=%04X device=%04x\n", pdev->vendor,
3174 rc = pci_enable_device(pdev);
3177 rc = pci_request_regions(pdev, DRV_NAME);
3180 rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
3182 rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
3184 dev_err(&pdev->dev, "DMA mask error %d\n", rc);
3185 goto err_out_regions;
3189 rc = register_blkdev(0, DRV_NAME);
3191 goto err_out_regions;
3196 skdev = skd_construct(pdev);
3197 if (skdev == NULL) {
3199 goto err_out_regions;
3202 skd_pci_info(skdev, pci_str);
3203 dev_info(&pdev->dev, "%s 64bit\n", pci_str);
3205 pci_set_master(pdev);
3206 rc = pci_enable_pcie_error_reporting(pdev);
3209 "bad enable of PCIe error reporting rc=%d\n", rc);
3210 skdev->pcie_error_reporting_is_enabled = 0;
3212 skdev->pcie_error_reporting_is_enabled = 1;
3214 pci_set_drvdata(pdev, skdev);
3216 for (i = 0; i < SKD_MAX_BARS; i++) {
3217 skdev->mem_phys[i] = pci_resource_start(pdev, i);
3218 skdev->mem_size[i] = (u32)pci_resource_len(pdev, i);
3219 skdev->mem_map[i] = ioremap(skdev->mem_phys[i],
3220 skdev->mem_size[i]);
3221 if (!skdev->mem_map[i]) {
3223 "Unable to map adapter memory!\n");
3225 goto err_out_iounmap;
3227 dev_dbg(&pdev->dev, "mem_map=%p, phyd=%016llx, size=%d\n",
3228 skdev->mem_map[i], (uint64_t)skdev->mem_phys[i],
3229 skdev->mem_size[i]);
3232 rc = skd_acquire_irq(skdev);
3234 dev_err(&pdev->dev, "interrupt resource error %d\n", rc);
3235 goto err_out_iounmap;
3238 rc = skd_start_timer(skdev);
3242 init_waitqueue_head(&skdev->waitq);
3244 skd_start_device(skdev);
3246 rc = wait_event_interruptible_timeout(skdev->waitq,
3247 (skdev->gendisk_on),
3248 (SKD_START_WAIT_SECONDS * HZ));
3249 if (skdev->gendisk_on > 0) {
3250 /* device came on-line after reset */
3251 skd_bdev_attach(&pdev->dev, skdev);
3254 /* we timed out, something is wrong with the device,
3255 don't add the disk structure */
3256 dev_err(&pdev->dev, "error: waiting for s1120 timed out %d!\n",
3258 /* in case of no error; we timeout with ENXIO */
3267 skd_stop_device(skdev);
3268 skd_release_irq(skdev);
3271 for (i = 0; i < SKD_MAX_BARS; i++)
3272 if (skdev->mem_map[i])
3273 iounmap(skdev->mem_map[i]);
3275 if (skdev->pcie_error_reporting_is_enabled)
3276 pci_disable_pcie_error_reporting(pdev);
3278 skd_destruct(skdev);
3281 pci_release_regions(pdev);
3284 pci_disable_device(pdev);
3285 pci_set_drvdata(pdev, NULL);
3289 static void skd_pci_remove(struct pci_dev *pdev)
3292 struct skd_device *skdev;
3294 skdev = pci_get_drvdata(pdev);
3296 dev_err(&pdev->dev, "no device data for PCI\n");
3299 skd_stop_device(skdev);
3300 skd_release_irq(skdev);
3302 for (i = 0; i < SKD_MAX_BARS; i++)
3303 if (skdev->mem_map[i])
3304 iounmap(skdev->mem_map[i]);
3306 if (skdev->pcie_error_reporting_is_enabled)
3307 pci_disable_pcie_error_reporting(pdev);
3309 skd_destruct(skdev);
3311 pci_release_regions(pdev);
3312 pci_disable_device(pdev);
3313 pci_set_drvdata(pdev, NULL);
3318 static int skd_pci_suspend(struct pci_dev *pdev, pm_message_t state)
3321 struct skd_device *skdev;
3323 skdev = pci_get_drvdata(pdev);
3325 dev_err(&pdev->dev, "no device data for PCI\n");
3329 skd_stop_device(skdev);
3331 skd_release_irq(skdev);
3333 for (i = 0; i < SKD_MAX_BARS; i++)
3334 if (skdev->mem_map[i])
3335 iounmap(skdev->mem_map[i]);
3337 if (skdev->pcie_error_reporting_is_enabled)
3338 pci_disable_pcie_error_reporting(pdev);
3340 pci_release_regions(pdev);
3341 pci_save_state(pdev);
3342 pci_disable_device(pdev);
3343 pci_set_power_state(pdev, pci_choose_state(pdev, state));
3347 static int skd_pci_resume(struct pci_dev *pdev)
3351 struct skd_device *skdev;
3353 skdev = pci_get_drvdata(pdev);
3355 dev_err(&pdev->dev, "no device data for PCI\n");
3359 pci_set_power_state(pdev, PCI_D0);
3360 pci_enable_wake(pdev, PCI_D0, 0);
3361 pci_restore_state(pdev);
3363 rc = pci_enable_device(pdev);
3366 rc = pci_request_regions(pdev, DRV_NAME);
3369 rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
3371 rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
3373 dev_err(&pdev->dev, "DMA mask error %d\n", rc);
3374 goto err_out_regions;
3377 pci_set_master(pdev);
3378 rc = pci_enable_pcie_error_reporting(pdev);
3381 "bad enable of PCIe error reporting rc=%d\n", rc);
3382 skdev->pcie_error_reporting_is_enabled = 0;
3384 skdev->pcie_error_reporting_is_enabled = 1;
3386 for (i = 0; i < SKD_MAX_BARS; i++) {
3388 skdev->mem_phys[i] = pci_resource_start(pdev, i);
3389 skdev->mem_size[i] = (u32)pci_resource_len(pdev, i);
3390 skdev->mem_map[i] = ioremap(skdev->mem_phys[i],
3391 skdev->mem_size[i]);
3392 if (!skdev->mem_map[i]) {
3393 dev_err(&pdev->dev, "Unable to map adapter memory!\n");
3395 goto err_out_iounmap;
3397 dev_dbg(&pdev->dev, "mem_map=%p, phyd=%016llx, size=%d\n",
3398 skdev->mem_map[i], (uint64_t)skdev->mem_phys[i],
3399 skdev->mem_size[i]);
3401 rc = skd_acquire_irq(skdev);
3403 dev_err(&pdev->dev, "interrupt resource error %d\n", rc);
3404 goto err_out_iounmap;
3407 rc = skd_start_timer(skdev);
3411 init_waitqueue_head(&skdev->waitq);
3413 skd_start_device(skdev);
3418 skd_stop_device(skdev);
3419 skd_release_irq(skdev);
3422 for (i = 0; i < SKD_MAX_BARS; i++)
3423 if (skdev->mem_map[i])
3424 iounmap(skdev->mem_map[i]);
3426 if (skdev->pcie_error_reporting_is_enabled)
3427 pci_disable_pcie_error_reporting(pdev);
3430 pci_release_regions(pdev);
3433 pci_disable_device(pdev);
3437 static void skd_pci_shutdown(struct pci_dev *pdev)
3439 struct skd_device *skdev;
3441 dev_err(&pdev->dev, "%s called\n", __func__);
3443 skdev = pci_get_drvdata(pdev);
3445 dev_err(&pdev->dev, "no device data for PCI\n");
3449 dev_err(&pdev->dev, "calling stop\n");
3450 skd_stop_device(skdev);
3453 static struct pci_driver skd_driver = {
3455 .id_table = skd_pci_tbl,
3456 .probe = skd_pci_probe,
3457 .remove = skd_pci_remove,
3458 .suspend = skd_pci_suspend,
3459 .resume = skd_pci_resume,
3460 .shutdown = skd_pci_shutdown,
3464 *****************************************************************************
3466 *****************************************************************************
3469 const char *skd_drive_state_to_str(int state)
3472 case FIT_SR_DRIVE_OFFLINE:
3474 case FIT_SR_DRIVE_INIT:
3476 case FIT_SR_DRIVE_ONLINE:
3478 case FIT_SR_DRIVE_BUSY:
3480 case FIT_SR_DRIVE_FAULT:
3482 case FIT_SR_DRIVE_DEGRADED:
3484 case FIT_SR_PCIE_LINK_DOWN:
3486 case FIT_SR_DRIVE_SOFT_RESET:
3487 return "SOFT_RESET";
3488 case FIT_SR_DRIVE_NEED_FW_DOWNLOAD:
3490 case FIT_SR_DRIVE_INIT_FAULT:
3491 return "INIT_FAULT";
3492 case FIT_SR_DRIVE_BUSY_SANITIZE:
3493 return "BUSY_SANITIZE";
3494 case FIT_SR_DRIVE_BUSY_ERASE:
3495 return "BUSY_ERASE";
3496 case FIT_SR_DRIVE_FW_BOOTING:
3497 return "FW_BOOTING";
3503 const char *skd_skdev_state_to_str(enum skd_drvr_state state)
3506 case SKD_DRVR_STATE_LOAD:
3508 case SKD_DRVR_STATE_IDLE:
3510 case SKD_DRVR_STATE_BUSY:
3512 case SKD_DRVR_STATE_STARTING:
3514 case SKD_DRVR_STATE_ONLINE:
3516 case SKD_DRVR_STATE_PAUSING:
3518 case SKD_DRVR_STATE_PAUSED:
3520 case SKD_DRVR_STATE_RESTARTING:
3521 return "RESTARTING";
3522 case SKD_DRVR_STATE_RESUMING:
3524 case SKD_DRVR_STATE_STOPPING:
3526 case SKD_DRVR_STATE_SYNCING:
3528 case SKD_DRVR_STATE_FAULT:
3530 case SKD_DRVR_STATE_DISAPPEARED:
3531 return "DISAPPEARED";
3532 case SKD_DRVR_STATE_BUSY_ERASE:
3533 return "BUSY_ERASE";
3534 case SKD_DRVR_STATE_BUSY_SANITIZE:
3535 return "BUSY_SANITIZE";
3536 case SKD_DRVR_STATE_BUSY_IMMINENT:
3537 return "BUSY_IMMINENT";
3538 case SKD_DRVR_STATE_WAIT_BOOT:
3546 static const char *skd_skreq_state_to_str(enum skd_req_state state)
3549 case SKD_REQ_STATE_IDLE:
3551 case SKD_REQ_STATE_SETUP:
3553 case SKD_REQ_STATE_BUSY:
3555 case SKD_REQ_STATE_COMPLETED:
3557 case SKD_REQ_STATE_TIMEOUT:
3564 static void skd_log_skdev(struct skd_device *skdev, const char *event)
3566 dev_dbg(&skdev->pdev->dev, "skdev=%p event='%s'\n", skdev, event);
3567 dev_dbg(&skdev->pdev->dev, " drive_state=%s(%d) driver_state=%s(%d)\n",
3568 skd_drive_state_to_str(skdev->drive_state), skdev->drive_state,
3569 skd_skdev_state_to_str(skdev->state), skdev->state);
3570 dev_dbg(&skdev->pdev->dev, " busy=%d limit=%d dev=%d lowat=%d\n",
3571 skd_in_flight(skdev), skdev->cur_max_queue_depth,
3572 skdev->dev_max_queue_depth, skdev->queue_low_water_mark);
3573 dev_dbg(&skdev->pdev->dev, " cycle=%d cycle_ix=%d\n",
3574 skdev->skcomp_cycle, skdev->skcomp_ix);
3577 static void skd_log_skreq(struct skd_device *skdev,
3578 struct skd_request_context *skreq, const char *event)
3580 struct request *req = blk_mq_rq_from_pdu(skreq);
3581 u32 lba = blk_rq_pos(req);
3582 u32 count = blk_rq_sectors(req);
3584 dev_dbg(&skdev->pdev->dev, "skreq=%p event='%s'\n", skreq, event);
3585 dev_dbg(&skdev->pdev->dev, " state=%s(%d) id=0x%04x fitmsg=0x%04x\n",
3586 skd_skreq_state_to_str(skreq->state), skreq->state, skreq->id,
3588 dev_dbg(&skdev->pdev->dev, " sg_dir=%d n_sg=%d\n",
3589 skreq->data_dir, skreq->n_sg);
3591 dev_dbg(&skdev->pdev->dev,
3592 "req=%p lba=%u(0x%x) count=%u(0x%x) dir=%d\n", req, lba, lba,
3593 count, count, (int)rq_data_dir(req));
3597 *****************************************************************************
3599 *****************************************************************************
3602 static int __init skd_init(void)
3604 BUILD_BUG_ON(sizeof(struct fit_completion_entry_v1) != 8);
3605 BUILD_BUG_ON(sizeof(struct fit_comp_error_info) != 32);
3606 BUILD_BUG_ON(sizeof(struct skd_command_header) != 16);
3607 BUILD_BUG_ON(sizeof(struct skd_scsi_request) != 32);
3608 BUILD_BUG_ON(sizeof(struct driver_inquiry_data) != 44);
3609 BUILD_BUG_ON(offsetof(struct skd_msg_buf, fmh) != 0);
3610 BUILD_BUG_ON(offsetof(struct skd_msg_buf, scsi) != 64);
3611 BUILD_BUG_ON(sizeof(struct skd_msg_buf) != SKD_N_FITMSG_BYTES);
3613 switch (skd_isr_type) {
3614 case SKD_IRQ_LEGACY:
3619 pr_err(PFX "skd_isr_type %d invalid, re-set to %d\n",
3620 skd_isr_type, SKD_IRQ_DEFAULT);
3621 skd_isr_type = SKD_IRQ_DEFAULT;
3624 if (skd_max_queue_depth < 1 ||
3625 skd_max_queue_depth > SKD_MAX_QUEUE_DEPTH) {
3626 pr_err(PFX "skd_max_queue_depth %d invalid, re-set to %d\n",
3627 skd_max_queue_depth, SKD_MAX_QUEUE_DEPTH_DEFAULT);
3628 skd_max_queue_depth = SKD_MAX_QUEUE_DEPTH_DEFAULT;
3631 if (skd_max_req_per_msg < 1 ||
3632 skd_max_req_per_msg > SKD_MAX_REQ_PER_MSG) {
3633 pr_err(PFX "skd_max_req_per_msg %d invalid, re-set to %d\n",
3634 skd_max_req_per_msg, SKD_MAX_REQ_PER_MSG_DEFAULT);
3635 skd_max_req_per_msg = SKD_MAX_REQ_PER_MSG_DEFAULT;
3638 if (skd_sgs_per_request < 1 || skd_sgs_per_request > 4096) {
3639 pr_err(PFX "skd_sg_per_request %d invalid, re-set to %d\n",
3640 skd_sgs_per_request, SKD_N_SG_PER_REQ_DEFAULT);
3641 skd_sgs_per_request = SKD_N_SG_PER_REQ_DEFAULT;
3644 if (skd_dbg_level < 0 || skd_dbg_level > 2) {
3645 pr_err(PFX "skd_dbg_level %d invalid, re-set to %d\n",
3650 if (skd_isr_comp_limit < 0) {
3651 pr_err(PFX "skd_isr_comp_limit %d invalid, set to %d\n",
3652 skd_isr_comp_limit, 0);
3653 skd_isr_comp_limit = 0;
3656 return pci_register_driver(&skd_driver);
3659 static void __exit skd_exit(void)
3661 pci_unregister_driver(&skd_driver);
3664 unregister_blkdev(skd_major, DRV_NAME);
3667 module_init(skd_init);
3668 module_exit(skd_exit);