blob: 3906ed926966fa17415c7cc9c297ba0a7221cbde [file] [log] [blame]
Jing Huang7725ccf2009-09-23 17:46:15 -07001/*
2 * Copyright (c) 2005-2009 Brocade Communications Systems, Inc.
3 * All rights reserved
4 * www.brocade.com
5 *
6 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License (GPL) Version 2 as
10 * published by the Free Software Foundation
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 */
17
18/**
19 * bfa_cb_ioim_macros.h BFA IOIM driver interface macros.
20 */
21
22#ifndef __BFA_HCB_IOIM_MACROS_H__
23#define __BFA_HCB_IOIM_MACROS_H__
24
25#include <bfa_os_inc.h>
26/*
27 * #include <linux/dma-mapping.h>
28 *
29 * #include <scsi/scsi.h> #include <scsi/scsi_cmnd.h> #include
30 * <scsi/scsi_device.h> #include <scsi/scsi_host.h>
31 */
32#include "bfad_im_compat.h"
33
34/*
35 * task attribute values in FCP-2 FCP_CMND IU
36 */
37#define SIMPLE_Q 0
38#define HEAD_OF_Q 1
39#define ORDERED_Q 2
40#define ACA_Q 4
41#define UNTAGGED 5
42
43static inline lun_t
44bfad_int_to_lun(u32 luno)
45{
46 union {
47 u16 scsi_lun[4];
48 lun_t bfa_lun;
49 } lun;
50
51 lun.bfa_lun = 0;
52 lun.scsi_lun[0] = bfa_os_htons(luno);
53
Jing Huangf8ceafd2009-09-25 12:29:54 -070054 return lun.bfa_lun;
Jing Huang7725ccf2009-09-23 17:46:15 -070055}
56
57/**
58 * Get LUN for the I/O request
59 */
60#define bfa_cb_ioim_get_lun(__dio) \
61 bfad_int_to_lun(((struct scsi_cmnd *)__dio)->device->lun)
62
63/**
64 * Get CDB for the I/O request
65 */
66static inline u8 *
67bfa_cb_ioim_get_cdb(struct bfad_ioim_s *dio)
68{
69 struct scsi_cmnd *cmnd = (struct scsi_cmnd *)dio;
70
Jing Huangf8ceafd2009-09-25 12:29:54 -070071 return (u8 *) cmnd->cmnd;
Jing Huang7725ccf2009-09-23 17:46:15 -070072}
73
74/**
75 * Get I/O direction (read/write) for the I/O request
76 */
77static inline enum fcp_iodir
78bfa_cb_ioim_get_iodir(struct bfad_ioim_s *dio)
79{
80 struct scsi_cmnd *cmnd = (struct scsi_cmnd *)dio;
81 enum dma_data_direction dmadir;
82
83 dmadir = cmnd->sc_data_direction;
84 if (dmadir == DMA_TO_DEVICE)
85 return FCP_IODIR_WRITE;
86 else if (dmadir == DMA_FROM_DEVICE)
87 return FCP_IODIR_READ;
88 else
89 return FCP_IODIR_NONE;
90}
91
92/**
93 * Get IO size in bytes for the I/O request
94 */
95static inline u32
96bfa_cb_ioim_get_size(struct bfad_ioim_s *dio)
97{
98 struct scsi_cmnd *cmnd = (struct scsi_cmnd *)dio;
99
Jing Huangf8ceafd2009-09-25 12:29:54 -0700100 return scsi_bufflen(cmnd);
Jing Huang7725ccf2009-09-23 17:46:15 -0700101}
102
103/**
104 * Get timeout for the I/O request
105 */
106static inline u8
107bfa_cb_ioim_get_timeout(struct bfad_ioim_s *dio)
108{
109 struct scsi_cmnd *cmnd = (struct scsi_cmnd *)dio;
110 /*
111 * TBD: need a timeout for scsi passthru
112 */
113 if (cmnd->device->host == NULL)
114 return 4;
115
116 return 0;
117}
118
119/**
Jing Huang7725ccf2009-09-23 17:46:15 -0700120 * Get Command Reference Number for the I/O request. 0 if none.
121 */
122static inline u8
123bfa_cb_ioim_get_crn(struct bfad_ioim_s *dio)
124{
125 return 0;
126}
127
128/**
129 * Get SAM-3 priority for the I/O request. 0 is default.
130 */
131static inline u8
132bfa_cb_ioim_get_priority(struct bfad_ioim_s *dio)
133{
134 return 0;
135}
136
137/**
138 * Get task attributes for the I/O request. Default is FCP_TASK_ATTR_SIMPLE(0).
139 */
140static inline u8
141bfa_cb_ioim_get_taskattr(struct bfad_ioim_s *dio)
142{
143 struct scsi_cmnd *cmnd = (struct scsi_cmnd *)dio;
144 u8 task_attr = UNTAGGED;
145
146 if (cmnd->device->tagged_supported) {
147 switch (cmnd->tag) {
148 case HEAD_OF_QUEUE_TAG:
149 task_attr = HEAD_OF_Q;
150 break;
151 case ORDERED_QUEUE_TAG:
152 task_attr = ORDERED_Q;
153 break;
154 default:
155 task_attr = SIMPLE_Q;
156 break;
157 }
158 }
159
160 return task_attr;
161}
162
163/**
164 * Get CDB length in bytes for the I/O request. Default is FCP_CMND_CDB_LEN(16).
165 */
166static inline u8
167bfa_cb_ioim_get_cdblen(struct bfad_ioim_s *dio)
168{
169 struct scsi_cmnd *cmnd = (struct scsi_cmnd *)dio;
170
Jing Huangf8ceafd2009-09-25 12:29:54 -0700171 return cmnd->cmd_len;
Jing Huang7725ccf2009-09-23 17:46:15 -0700172}
173
Jing Huang36d345a2010-07-08 19:57:33 -0700174/**
175 * Assign queue to be used for the I/O request. This value depends on whether
176 * the driver wants to use the queues via any specific algorithm. Currently,
177 * this is not supported.
178 */
179#define bfa_cb_ioim_get_reqq(__dio) BFA_FALSE
Jing Huang7725ccf2009-09-23 17:46:15 -0700180
181#endif /* __BFA_HCB_IOIM_MACROS_H__ */