History

Merge tag 'scsi-misc' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi

Pull first round of SCSI updates from James Bottomley: "This includes one new driver: cxlflash plus the usual grab bag of updates for the major drivers: qla2xxx, ipr, storvsc, pm80xx, hptiop, plus a few assorted fixes. There's another tranch coming, but I want to incubate it another few days in the checkers, plus it includes a mpt2sas separated lifetime fix, which Avago won't get done testing until Friday" * tag 'scsi-misc' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi: (85 commits) aic94xx: set an error code on failure storvsc: Set the error code correctly in failure conditions storvsc: Allow write_same when host is windows 10 storvsc: use storage protocol version to determine storage capabilities storvsc: use correct defaults for values determined by protocol negotiation storvsc: Untangle the storage protocol negotiation from the vmbus protocol negotiation. storvsc: Use a single value to track protocol versions storvsc: Rather than look for sets of specific protocol versions, make decisions based on ranges. cxlflash: Remove unused variable from queuecommand cxlflash: shift wrapping bug in afu_link_reset() cxlflash: off by one bug in cxlflash_show_port_status() cxlflash: Virtual LUN support cxlflash: Superpipe support cxlflash: Base error recovery support qla2xxx: Update driver version to 8.07.00.26-k qla2xxx: Add pci device id 0x2261. qla2xxx: Fix missing device login retries. qla2xxx: do not clear slot in outstanding cmd array qla2xxx: Remove decrement of sp reference count in abort handler. qla2xxx: Add support to show MPI and PEP FW version for ISP27xx. ...

Linus Torvalds committed 11 years ago

Commit df910392 parents 91a247d 9f55bca70 files · +9177 −1327Browse files

Unified · Split

70 files
  1. Documentation/ioctl/ioctl-number.txt +1 −0
  2. Documentation/powerpc/cxlflash.txt +318 −0
  3. MAINTAINERS +1 −1
  4. drivers/message/fusion/mptctl.c +9 −0
  5. drivers/scsi/Kconfig +1 −0
  6. drivers/scsi/Makefile +1 −0
  7. drivers/scsi/aic94xx/aic94xx_init.c +1 −0
  8. drivers/scsi/bfa/bfad_im.c +2 −0
  9. drivers/scsi/cxlflash/Kconfig +11 −0
  10. drivers/scsi/cxlflash/Makefile +2 −0
  11. drivers/scsi/cxlflash/common.h +208 −0
  12. drivers/scsi/cxlflash/lunmgt.c +266 −0
  13. drivers/scsi/cxlflash/main.c +2494 −0
  14. drivers/scsi/cxlflash/main.h +108 −0
  15. drivers/scsi/cxlflash/sislite.h +472 −0
  16. drivers/scsi/cxlflash/superpipe.c +2084 −0
  17. drivers/scsi/cxlflash/superpipe.h +147 −0
  18. drivers/scsi/cxlflash/vlun.c +1243 −0
  19. drivers/scsi/cxlflash/vlun.h +86 −0
  20. drivers/scsi/hpsa.c +185 −116
  21. drivers/scsi/hpsa.h +8 −8
  22. drivers/scsi/hpsa_cmd.h +4 −6
  23. drivers/scsi/hptiop.c +62 −35
  24. drivers/scsi/hptiop.h +3 −3
  25. drivers/scsi/ipr.c +8 −7
  26. drivers/scsi/ipr.h +8 −9
  27. drivers/scsi/libfc/fc_fcp.c +1 −1
  28. drivers/scsi/lpfc/lpfc_hbadisc.c +1 −1
  29. drivers/scsi/megaraid.c +66 −74
  30. drivers/scsi/megaraid/megaraid_sas_base.c +266 −278
  31. drivers/scsi/megaraid/megaraid_sas_fusion.c +46 −49
  32. drivers/scsi/mpt2sas/mpt2sas_base.c +9 −7
  33. drivers/scsi/mpt3sas/mpt3sas_base.c +9 −7
  34. drivers/scsi/mvsas/mv_init.c +4 −1
  35. drivers/scsi/pm8001/pm8001_defs.h +3 −1
  36. drivers/scsi/pm8001/pm8001_hwi.c +4 −0
  37. drivers/scsi/pm8001/pm8001_init.c +4 −1
  38. drivers/scsi/pm8001/pm8001_sas.c +14 −5
  39. drivers/scsi/pm8001/pm8001_sas.h +10 −2
  40. drivers/scsi/pm8001/pm80xx_hwi.c +82 −29
  41. drivers/scsi/pm8001/pm80xx_hwi.h +3 −2
  42. drivers/scsi/qla2xxx/qla_attr.c +19 −5
  43. drivers/scsi/qla2xxx/qla_bsg.c +1 −6
  44. drivers/scsi/qla2xxx/qla_dbg.c +63 −39
  45. drivers/scsi/qla2xxx/qla_def.h +10 −5
  46. drivers/scsi/qla2xxx/qla_gs.c +26 −26
  47. drivers/scsi/qla2xxx/qla_init.c +79 −83
  48. drivers/scsi/qla2xxx/qla_iocb.c +49 −83
  49. drivers/scsi/qla2xxx/qla_isr.c +48 −22
  50. drivers/scsi/qla2xxx/qla_mbx.c +45 −35
  51. drivers/scsi/qla2xxx/qla_mid.c +1 −2
  52. drivers/scsi/qla2xxx/qla_mr.c +9 −13
  53. drivers/scsi/qla2xxx/qla_nx.c +79 −86
  54. drivers/scsi/qla2xxx/qla_nx2.c +8 −12
  55. drivers/scsi/qla2xxx/qla_nx2.h +4 −2
  56. drivers/scsi/qla2xxx/qla_os.c +19 −22
  57. drivers/scsi/qla2xxx/qla_sup.c +7 −7
  58. drivers/scsi/qla2xxx/qla_target.c +64 −75
  59. drivers/scsi/qla2xxx/qla_tmpl.c +15 −12
  60. drivers/scsi/qla2xxx/qla_version.h +1 −1
  61. drivers/scsi/qla2xxx/tcm_qla2xxx.c +6 −0
  62. drivers/scsi/scsi_error.c +9 −0
  63. drivers/scsi/scsi_lib.c +10 −1
  64. drivers/scsi/scsi_transport_iscsi.c +8 −3
  65. drivers/scsi/st.c +23 −60
  66. drivers/scsi/storvsc_drv.c +141 −83
  67. include/scsi/scsi_device.h +2 −1
  68. include/scsi/scsi_transport_iscsi.h +1 −0
  69. include/uapi/scsi/Kbuild +1 −0
  70. include/uapi/scsi/cxlflash_ioctl.h +174 −0
Documentation/ioctl/ioctl-number.txt+1−0
@@ -316,6 +316,7 @@ Code Seq#(hex) Include File Comments · 315 unmodified lines
316316 0xB3 00 linux/mmc/ioctl.h
317317 0xC0 00-0F linux/usb/iowarrior.h
318318 0xCA 00-0F uapi/misc/cxl.h
319+0xCA 80-8F uapi/scsi/cxlflash_ioctl.h
319320 0xCB 00-1F CBM serial IEC bus in development:
320321 <mailto:michael.klein@puffin.lb.shuttle.de>
321322 0xCD 01 linux/reiserfs_fs.h
Documentation/powerpc/cxlflash.txt+318−0
@@ -0,0 +1,318 @@
1+Introduction
2+============
3+
4+ The IBM Power architecture provides support for CAPI (Coherent
5+ Accelerator Power Interface), which is available to certain PCIe slots
6+ on Power 8 systems. CAPI can be thought of as a special tunneling
7+ protocol through PCIe that allow PCIe adapters to look like special
8+ purpose co-processors which can read or write an application's
9+ memory and generate page faults. As a result, the host interface to
10+ an adapter running in CAPI mode does not require the data buffers to
11+ be mapped to the device's memory (IOMMU bypass) nor does it require
12+ memory to be pinned.
13+
14+ On Linux, Coherent Accelerator (CXL) kernel services present CAPI
15+ devices as a PCI device by implementing a virtual PCI host bridge.
16+ This abstraction simplifies the infrastructure and programming
17+ model, allowing for drivers to look similar to other native PCI
18+ device drivers.
19+
20+ CXL provides a mechanism by which user space applications can
21+ directly talk to a device (network or storage) bypassing the typical
22+ kernel/device driver stack. The CXL Flash Adapter Driver enables a
23+ user space application direct access to Flash storage.
24+
25+ The CXL Flash Adapter Driver is a kernel module that sits in the
26+ SCSI stack as a low level device driver (below the SCSI disk and
27+ protocol drivers) for the IBM CXL Flash Adapter. This driver is
28+ responsible for the initialization of the adapter, setting up the
29+ special path for user space access, and performing error recovery. It
30+ communicates directly the Flash Accelerator Functional Unit (AFU)
31+ as described in Documentation/powerpc/cxl.txt.
32+
33+ The cxlflash driver supports two, mutually exclusive, modes of
34+ operation at the device (LUN) level:
35+
36+ - Any flash device (LUN) can be configured to be accessed as a
37+ regular disk device (i.e.: /dev/sdc). This is the default mode.
38+
39+ - Any flash device (LUN) can be configured to be accessed from
40+ user space with a special block library. This mode further
41+ specifies the means of accessing the device and provides for
42+ either raw access to the entire LUN (referred to as direct
43+ or physical LUN access) or access to a kernel/AFU-mediated
44+ partition of the LUN (referred to as virtual LUN access). The
45+ segmentation of a disk device into virtual LUNs is assisted
46+ by special translation services provided by the Flash AFU.
47+
48+Overview
49+========
50+
51+ The Coherent Accelerator Interface Architecture (CAIA) introduces a
52+ concept of a master context. A master typically has special privileges
53+ granted to it by the kernel or hypervisor allowing it to perform AFU
54+ wide management and control. The master may or may not be involved
55+ directly in each user I/O, but at the minimum is involved in the
56+ initial setup before the user application is allowed to send requests
57+ directly to the AFU.
58+
59+ The CXL Flash Adapter Driver establishes a master context with the
60+ AFU. It uses memory mapped I/O (MMIO) for this control and setup. The
61+ Adapter Problem Space Memory Map looks like this:
62+
63+ +-------------------------------+
64+ | 512 * 64 KB User MMIO |
65+ | (per context) |
66+ | User Accessible |
67+ +-------------------------------+
68+ | 512 * 128 B per context |
69+ | Provisioning and Control |
70+ | Trusted Process accessible |
71+ +-------------------------------+
72+ | 64 KB Global |
73+ | Trusted Process accessible |
74+ +-------------------------------+
75+
76+ This driver configures itself into the SCSI software stack as an
77+ adapter driver. The driver is the only entity that is considered a
78+ Trusted Process to program the Provisioning and Control and Global
79+ areas in the MMIO Space shown above. The master context driver
80+ discovers all LUNs attached to the CXL Flash adapter and instantiates
81+ scsi block devices (/dev/sdb, /dev/sdc etc.) for each unique LUN
82+ seen from each path.
83+
84+ Once these scsi block devices are instantiated, an application
85+ written to a specification provided by the block library may get
86+ access to the Flash from user space (without requiring a system call).
87+
88+ This master context driver also provides a series of ioctls for this
89+ block library to enable this user space access. The driver supports
90+ two modes for accessing the block device.
91+
92+ The first mode is called a virtual mode. In this mode a single scsi
93+ block device (/dev/sdb) may be carved up into any number of distinct
94+ virtual LUNs. The virtual LUNs may be resized as long as the sum of
95+ the sizes of all the virtual LUNs, along with the meta-data associated
96+ with it does not exceed the physical capacity.
97+
98+ The second mode is called the physical mode. In this mode a single
99+ block device (/dev/sdb) may be opened directly by the block library
100+ and the entire space for the LUN is available to the application.
101+
102+ Only the physical mode provides persistence of the data. i.e. The
103+ data written to the block device will survive application exit and
104+ restart and also reboot. The virtual LUNs do not persist (i.e. do
105+ not survive after the application terminates or the system reboots).
106+
107+
108+Block library API
109+=================
110+
111+ Applications intending to get access to the CXL Flash from user
112+ space should use the block library, as it abstracts the details of
113+ interfacing directly with the cxlflash driver that are necessary for
114+ performing administrative actions (i.e.: setup, tear down, resize).
115+ The block library can be thought of as a 'user' of services,
116+ implemented as IOCTLs, that are provided by the cxlflash driver
117+ specifically for devices (LUNs) operating in user space access
118+ mode. While it is not a requirement that applications understand
119+ the interface between the block library and the cxlflash driver,
120+ a high-level overview of each supported service (IOCTL) is provided
121+ below.
122+
123+ The block library can be found on GitHub:
124+ http://www.github.com/mikehollinger/ibmcapikv
125+
126+
127+CXL Flash Driver IOCTLs
128+=======================
129+
130+ Users, such as the block library, that wish to interface with a flash
131+ device (LUN) via user space access need to use the services provided
132+ by the cxlflash driver. As these services are implemented as ioctls,
133+ a file descriptor handle must first be obtained in order to establish
134+ the communication channel between a user and the kernel. This file
135+ descriptor is obtained by opening the device special file associated
136+ with the scsi disk device (/dev/sdb) that was created during LUN
137+ discovery. As per the location of the cxlflash driver within the
138+ SCSI protocol stack, this open is actually not seen by the cxlflash
139+ driver. Upon successful open, the user receives a file descriptor
140+ (herein referred to as fd1) that should be used for issuing the
141+ subsequent ioctls listed below.
142+
143+ The structure definitions for these IOCTLs are available in:
144+ uapi/scsi/cxlflash_ioctl.h
145+
146+DK_CXLFLASH_ATTACH
147+------------------
148+
149+ This ioctl obtains, initializes, and starts a context using the CXL
150+ kernel services. These services specify a context id (u16) by which
151+ to uniquely identify the context and its allocated resources. The
152+ services additionally provide a second file descriptor (herein
153+ referred to as fd2) that is used by the block library to initiate
154+ memory mapped I/O (via mmap()) to the CXL flash device and poll for
155+ completion events. This file descriptor is intentionally installed by
156+ this driver and not the CXL kernel services to allow for intermediary
157+ notification and access in the event of a non-user-initiated close(),
158+ such as a killed process. This design point is described in further
159+ detail in the description for the DK_CXLFLASH_DETACH ioctl.
160+
161+ There are a few important aspects regarding the "tokens" (context id
162+ and fd2) that are provided back to the user:
163+
164+ - These tokens are only valid for the process under which they
165+ were created. The child of a forked process cannot continue
166+ to use the context id or file descriptor created by its parent
167+ (see DK_CXLFLASH_VLUN_CLONE for further details).
168+
169+ - These tokens are only valid for the lifetime of the context and
170+ the process under which they were created. Once either is
171+ destroyed, the tokens are to be considered stale and subsequent
172+ usage will result in errors.
173+
174+ - When a context is no longer needed, the user shall detach from
175+ the context via the DK_CXLFLASH_DETACH ioctl.
176+
177+ - A close on fd2 will invalidate the tokens. This operation is not
178+ required by the user.
179+
180+DK_CXLFLASH_USER_DIRECT
181+-----------------------
182+ This ioctl is responsible for transitioning the LUN to direct
183+ (physical) mode access and configuring the AFU for direct access from
184+ user space on a per-context basis. Additionally, the block size and
185+ last logical block address (LBA) are returned to the user.
186+
187+ As mentioned previously, when operating in user space access mode,
188+ LUNs may be accessed in whole or in part. Only one mode is allowed
189+ at a time and if one mode is active (outstanding references exist),
190+ requests to use the LUN in a different mode are denied.
191+
192+ The AFU is configured for direct access from user space by adding an
193+ entry to the AFU's resource handle table. The index of the entry is
194+ treated as a resource handle that is returned to the user. The user
195+ is then able to use the handle to reference the LUN during I/O.
196+
197+DK_CXLFLASH_USER_VIRTUAL
198+------------------------
199+ This ioctl is responsible for transitioning the LUN to virtual mode
200+ of access and configuring the AFU for virtual access from user space
201+ on a per-context basis. Additionally, the block size and last logical
202+ block address (LBA) are returned to the user.
203+
204+ As mentioned previously, when operating in user space access mode,
205+ LUNs may be accessed in whole or in part. Only one mode is allowed
206+ at a time and if one mode is active (outstanding references exist),
207+ requests to use the LUN in a different mode are denied.
208+
209+ The AFU is configured for virtual access from user space by adding
210+ an entry to the AFU's resource handle table. The index of the entry
211+ is treated as a resource handle that is returned to the user. The
212+ user is then able to use the handle to reference the LUN during I/O.
213+
214+ By default, the virtual LUN is created with a size of 0. The user
215+ would need to use the DK_CXLFLASH_VLUN_RESIZE ioctl to adjust the grow
216+ the virtual LUN to a desired size. To avoid having to perform this
217+ resize for the initial creation of the virtual LUN, the user has the
218+ option of specifying a size as part of the DK_CXLFLASH_USER_VIRTUAL
219+ ioctl, such that when success is returned to the user, the
220+ resource handle that is provided is already referencing provisioned
221+ storage. This is reflected by the last LBA being a non-zero value.
222+
223+DK_CXLFLASH_VLUN_RESIZE
224+-----------------------
225+ This ioctl is responsible for resizing a previously created virtual
226+ LUN and will fail if invoked upon a LUN that is not in virtual
227+ mode. Upon success, an updated last LBA is returned to the user
228+ indicating the new size of the virtual LUN associated with the
229+ resource handle.
230+
231+ The partitioning of virtual LUNs is jointly mediated by the cxlflash
232+ driver and the AFU. An allocation table is kept for each LUN that is
233+ operating in the virtual mode and used to program a LUN translation
234+ table that the AFU references when provided with a resource handle.
235+
236+DK_CXLFLASH_RELEASE
237+-------------------
238+ This ioctl is responsible for releasing a previously obtained
239+ reference to either a physical or virtual LUN. This can be
240+ thought of as the inverse of the DK_CXLFLASH_USER_DIRECT or
241+ DK_CXLFLASH_USER_VIRTUAL ioctls. Upon success, the resource handle
242+ is no longer valid and the entry in the resource handle table is
243+ made available to be used again.
244+
245+ As part of the release process for virtual LUNs, the virtual LUN
246+ is first resized to 0 to clear out and free the translation tables
247+ associated with the virtual LUN reference.
248+
249+DK_CXLFLASH_DETACH
250+------------------
251+ This ioctl is responsible for unregistering a context with the
252+ cxlflash driver and release outstanding resources that were
253+ not explicitly released via the DK_CXLFLASH_RELEASE ioctl. Upon
254+ success, all "tokens" which had been provided to the user from the
255+ DK_CXLFLASH_ATTACH onward are no longer valid.
256+
257+DK_CXLFLASH_VLUN_CLONE
258+----------------------
259+ This ioctl is responsible for cloning a previously created
260+ context to a more recently created context. It exists solely to
261+ support maintaining user space access to storage after a process
262+ forks. Upon success, the child process (which invoked the ioctl)
263+ will have access to the same LUNs via the same resource handle(s)
264+ and fd2 as the parent, but under a different context.
265+
266+ Context sharing across processes is not supported with CXL and
267+ therefore each fork must be met with establishing a new context
268+ for the child process. This ioctl simplifies the state management
269+ and playback required by a user in such a scenario. When a process
270+ forks, child process can clone the parents context by first creating
271+ a context (via DK_CXLFLASH_ATTACH) and then using this ioctl to
272+ perform the clone from the parent to the child.
273+
274+ The clone itself is fairly simple. The resource handle and lun
275+ translation tables are copied from the parent context to the child's
276+ and then synced with the AFU.
277+
278+DK_CXLFLASH_VERIFY
279+------------------
280+ This ioctl is used to detect various changes such as the capacity of
281+ the disk changing, the number of LUNs visible changing, etc. In cases
282+ where the changes affect the application (such as a LUN resize), the
283+ cxlflash driver will report the changed state to the application.
284+
285+ The user calls in when they want to validate that a LUN hasn't been
286+ changed in response to a check condition. As the user is operating out
287+ of band from the kernel, they will see these types of events without
288+ the kernel's knowledge. When encountered, the user's architected
289+ behavior is to call in to this ioctl, indicating what they want to
290+ verify and passing along any appropriate information. For now, only
291+ verifying a LUN change (ie: size different) with sense data is
292+ supported.
293+
294+DK_CXLFLASH_RECOVER_AFU
295+-----------------------
296+ This ioctl is used to drive recovery (if such an action is warranted)
297+ of a specified user context. Any state associated with the user context
298+ is re-established upon successful recovery.
299+
300+ User contexts are put into an error condition when the device needs to
301+ be reset or is terminating. Users are notified of this error condition
302+ by seeing all 0xF's on an MMIO read. Upon encountering this, the
303+ architected behavior for a user is to call into this ioctl to recover
304+ their context. A user may also call into this ioctl at any time to
305+ check if the device is operating normally. If a failure is returned
306+ from this ioctl, the user is expected to gracefully clean up their
307+ context via release/detach ioctls. Until they do, the context they
308+ hold is not relinquished. The user may also optionally exit the process
309+ at which time the context/resources they held will be freed as part of
310+ the release fop.
311+
312+DK_CXLFLASH_MANAGE_LUN
313+----------------------
314+ This ioctl is used to switch a LUN from a mode where it is available
315+ for file-system access (legacy), to a mode where it is set aside for
316+ exclusive user space access (superpipe). In case a LUN is visible
317+ across multiple ports and adapters, this ioctl is used to uniquely
318+ identify each LUN by its World Wide Node Name (WWNN).
MAINTAINERS+1−1
@@ -8098,7 +8098,7 @@ S: Supported · 8097 unmodified lines
80988098 F: drivers/scsi/pmcraid.*
80998099
81008100 PMC SIERRA PM8001 DRIVER
8101−M: xjtuwjp@gmail.com
8101+M: Jack Wang <jinpu.wang@profitbricks.com>
81028102 M: lindar_liu@usish.com
81038103 L: pmchba@pmcs.com
81048104 L: linux-scsi@vger.kernel.org
drivers/message/fusion/mptctl.c+9−0
@@ -1859,6 +1859,15 @@ mptctl_do_mpt_command (struct mpt_ioctl_command karg, void __user *mfPtr) · 1858 unmodified lines
18591859 }
18601860 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
18611861
1862+ /* Basic sanity checks to prevent underflows or integer overflows */
1863+ if (karg.maxReplyBytes < 0 ||
1864+ karg.dataInSize < 0 ||
1865+ karg.dataOutSize < 0 ||
1866+ karg.dataSgeOffset < 0 ||
1867+ karg.maxSenseBytes < 0 ||
1868+ karg.dataSgeOffset > ioc->req_sz / 4)
1869+ return -EINVAL;
1870+
18621871 /* Verify that the final request frame will not be too large.
18631872 */
18641873 sz = karg.dataSgeOffset * 4;
drivers/scsi/Kconfig+1−0
@@ -345,6 +345,7 @@ source "drivers/scsi/cxgbi/Kconfig" · 344 unmodified lines
345345 source "drivers/scsi/bnx2i/Kconfig"
346346 source "drivers/scsi/bnx2fc/Kconfig"
347347 source "drivers/scsi/be2iscsi/Kconfig"
348+source "drivers/scsi/cxlflash/Kconfig"
348349
349350 config SGIWD93_SCSI
350351 tristate "SGI WD93C93 SCSI Driver"
drivers/scsi/Makefile+1−0
@@ -102,6 +102,7 @@ obj-$(CONFIG_SCSI_7000FASST) += wd7000.o · 101 unmodified lines
102102 obj-$(CONFIG_SCSI_EATA) += eata.o
103103 obj-$(CONFIG_SCSI_DC395x) += dc395x.o
104104 obj-$(CONFIG_SCSI_AM53C974) += esp_scsi.o am53c974.o
105+obj-$(CONFIG_CXLFLASH) += cxlflash/
105106 obj-$(CONFIG_MEGARAID_LEGACY) += megaraid.o
106107 obj-$(CONFIG_MEGARAID_NEWGEN) += megaraid/
107108 obj-$(CONFIG_MEGARAID_SAS) += megaraid/
drivers/scsi/aic94xx/aic94xx_init.c+1−0
@@ -109,6 +109,7 @@ static int asd_map_memio(struct asd_ha_struct *asd_ha) · 108 unmodified lines
109109 if (!io_handle->addr) {
110110 asd_printk("couldn't map MBAR%d of %s\n", i==0?0:1,
111111 pci_name(asd_ha->pcidev));
112+ err = -ENOMEM;
112113 goto Err_unreq;
113114 }
114115 }
drivers/scsi/bfa/bfad_im.c+2−0
@@ -851,6 +851,8 @@ bfad_im_module_exit(void) · 850 unmodified lines
851851
852852 if (bfad_im_scsi_vport_transport_template)
853853 fc_release_transport(bfad_im_scsi_vport_transport_template);
854+
855+ idr_destroy(&bfad_im_port_index);
854856 }
855857
856858 void
drivers/scsi/cxlflash/Kconfig+11−0
@@ -0,0 +1,11 @@
1+#
2+# IBM CXL-attached Flash Accelerator SCSI Driver
3+#
4+
5+config CXLFLASH
6+ tristate "Support for IBM CAPI Flash"
7+ depends on PCI && SCSI && CXL && EEH
8+ default m
9+ help
10+ Allows CAPI Accelerated IO to Flash
11+ If unsure, say N.
drivers/scsi/cxlflash/Makefile+2−0
@@ -0,0 +1,2 @@
1+obj-$(CONFIG_CXLFLASH) += cxlflash.o
2+cxlflash-y += main.o superpipe.o lunmgt.o vlun.o
drivers/scsi/cxlflash/common.h+208−0
@@ -0,0 +1,208 @@
1+/*
2+ * CXL Flash Device Driver
3+ *
4+ * Written by: Manoj N. Kumar <manoj@linux.vnet.ibm.com>, IBM Corporation
5+ * Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation
6+ *
7+ * Copyright (C) 2015 IBM Corporation
8+ *
9+ * This program is free software; you can redistribute it and/or
10+ * modify it under the terms of the GNU General Public License
11+ * as published by the Free Software Foundation; either version
12+ * 2 of the License, or (at your option) any later version.
13+ */
14+
15+#ifndef _CXLFLASH_COMMON_H
16+#define _CXLFLASH_COMMON_H
17+
18+#include <linux/list.h>
19+#include <linux/types.h>
20+#include <scsi/scsi.h>
21+#include <scsi/scsi_device.h>
22+
23+
24+#define MAX_CONTEXT CXLFLASH_MAX_CONTEXT /* num contexts per afu */
25+
26+#define CXLFLASH_BLOCK_SIZE 4096 /* 4K blocks */
27+#define CXLFLASH_MAX_XFER_SIZE 16777216 /* 16MB transfer */
28+#define CXLFLASH_MAX_SECTORS (CXLFLASH_MAX_XFER_SIZE/512) /* SCSI wants
29+ max_sectors
30+ in units of
31+ 512 byte
32+ sectors
33+ */
34+
35+#define NUM_RRQ_ENTRY 16 /* for master issued cmds */
36+#define MAX_RHT_PER_CONTEXT (PAGE_SIZE / sizeof(struct sisl_rht_entry))
37+
38+/* AFU command retry limit */
39+#define MC_RETRY_CNT 5 /* sufficient for SCSI check and
40+ certain AFU errors */
41+
42+/* Command management definitions */
43+#define CXLFLASH_NUM_CMDS (2 * CXLFLASH_MAX_CMDS) /* Must be a pow2 for
44+ alignment and more
45+ efficient array
46+ index derivation
47+ */
48+
49+#define CXLFLASH_MAX_CMDS 16
50+#define CXLFLASH_MAX_CMDS_PER_LUN CXLFLASH_MAX_CMDS
51+
52+
53+static inline void check_sizes(void)
54+{
55+ BUILD_BUG_ON_NOT_POWER_OF_2(CXLFLASH_NUM_CMDS);
56+}
57+
58+/* AFU defines a fixed size of 4K for command buffers (borrow 4K page define) */
59+#define CMD_BUFSIZE SIZE_4K
60+
61+/* flags in IOA status area for host use */
62+#define B_DONE 0x01
63+#define B_ERROR 0x02 /* set with B_DONE */
64+#define B_TIMEOUT 0x04 /* set with B_DONE & B_ERROR */
65+
66+enum cxlflash_lr_state {
67+ LINK_RESET_INVALID,
68+ LINK_RESET_REQUIRED,
69+ LINK_RESET_COMPLETE
70+};
71+
72+enum cxlflash_init_state {
73+ INIT_STATE_NONE,
74+ INIT_STATE_PCI,
75+ INIT_STATE_AFU,
76+ INIT_STATE_SCSI
77+};
78+
79+enum cxlflash_state {
80+ STATE_NORMAL, /* Normal running state, everything good */
81+ STATE_LIMBO, /* Limbo running state, trying to reset/recover */
82+ STATE_FAILTERM /* Failed/terminating state, error out users/threads */
83+};
84+
85+/*
86+ * Each context has its own set of resource handles that is visible
87+ * only from that context.
88+ */
89+
90+struct cxlflash_cfg {
91+ struct afu *afu;
92+ struct cxl_context *mcctx;
93+
94+ struct pci_dev *dev;
95+ struct pci_device_id *dev_id;
96+ struct Scsi_Host *host;
97+
98+ ulong cxlflash_regs_pci;
99+
100+ struct work_struct work_q;
101+ enum cxlflash_init_state init_state;
102+ enum cxlflash_lr_state lr_state;
103+ int lr_port;
104+
105+ struct cxl_afu *cxl_afu;
106+
107+ struct pci_pool *cxlflash_cmd_pool;
108+ struct pci_dev *parent_dev;
109+
110+ atomic_t recovery_threads;
111+ struct mutex ctx_recovery_mutex;
112+ struct mutex ctx_tbl_list_mutex;
113+ struct ctx_info *ctx_tbl[MAX_CONTEXT];
114+ struct list_head ctx_err_recovery; /* contexts w/ recovery pending */
115+ struct file_operations cxl_fops;
116+
117+ atomic_t num_user_contexts;
118+
119+ /* Parameters that are LUN table related */
120+ int last_lun_index[CXLFLASH_NUM_FC_PORTS];
121+ int promote_lun_index;
122+ struct list_head lluns; /* list of llun_info structs */
123+
124+ wait_queue_head_t tmf_waitq;
125+ bool tmf_active;
126+ wait_queue_head_t limbo_waitq;
127+ enum cxlflash_state state;
128+};
129+
130+struct afu_cmd {
131+ struct sisl_ioarcb rcb; /* IOARCB (cache line aligned) */
132+ struct sisl_ioasa sa; /* IOASA must follow IOARCB */
133+ spinlock_t slock;
134+ struct completion cevent;
135+ char *buf; /* per command buffer */
136+ struct afu *parent;
137+ int slot;
138+ atomic_t free;
139+
140+ u8 cmd_tmf:1;
141+
142+ /* As per the SISLITE spec the IOARCB EA has to be 16-byte aligned.
143+ * However for performance reasons the IOARCB/IOASA should be
144+ * cache line aligned.
145+ */
146+} __aligned(cache_line_size());
147+
148+struct afu {
149+ /* Stuff requiring alignment go first. */
150+
151+ u64 rrq_entry[NUM_RRQ_ENTRY]; /* 128B RRQ */
152+ /*
153+ * Command & data for AFU commands.
154+ */
155+ struct afu_cmd cmd[CXLFLASH_NUM_CMDS];
156+
157+ /* Beware of alignment till here. Preferably introduce new
158+ * fields after this point
159+ */
160+
161+ /* AFU HW */
162+ struct cxl_ioctl_start_work work;
163+ struct cxlflash_afu_map *afu_map; /* entire MMIO map */
164+ struct sisl_host_map *host_map; /* MC host map */
165+ struct sisl_ctrl_map *ctrl_map; /* MC control map */
166+
167+ ctx_hndl_t ctx_hndl; /* master's context handle */
168+ u64 *hrrq_start;
169+ u64 *hrrq_end;
170+ u64 *hrrq_curr;
171+ bool toggle;
172+ bool read_room;
173+ atomic64_t room;
174+ u64 hb;
175+ u32 cmd_couts; /* Number of command checkouts */
176+ u32 internal_lun; /* User-desired LUN mode for this AFU */
177+
178+ char version[8];
179+ u64 interface_version;
180+
181+ struct cxlflash_cfg *parent; /* Pointer back to parent cxlflash_cfg */
182+
183+};
184+
185+static inline u64 lun_to_lunid(u64 lun)
186+{
187+ u64 lun_id;
188+
189+ int_to_scsilun(lun, (struct scsi_lun *)&lun_id);
190+ return swab64(lun_id);
191+}
192+
193+int cxlflash_send_cmd(struct afu *, struct afu_cmd *);
194+void cxlflash_wait_resp(struct afu *, struct afu_cmd *);
195+int cxlflash_afu_reset(struct cxlflash_cfg *);
196+struct afu_cmd *cxlflash_cmd_checkout(struct afu *);
197+void cxlflash_cmd_checkin(struct afu_cmd *);
198+int cxlflash_afu_sync(struct afu *, ctx_hndl_t, res_hndl_t, u8);
199+void cxlflash_list_init(void);
200+void cxlflash_term_global_luns(void);
201+void cxlflash_free_errpage(void);
202+int cxlflash_ioctl(struct scsi_device *, int, void __user *);
203+void cxlflash_stop_term_user_contexts(struct cxlflash_cfg *);
204+int cxlflash_mark_contexts_error(struct cxlflash_cfg *);
205+void cxlflash_term_local_luns(struct cxlflash_cfg *);
206+void cxlflash_restore_luntable(struct cxlflash_cfg *);
207+
208+#endif /* ifndef _CXLFLASH_COMMON_H */
drivers/scsi/cxlflash/lunmgt.c+266−0
@@ -0,0 +1,266 @@
1+/*
2+ * CXL Flash Device Driver
3+ *
4+ * Written by: Manoj N. Kumar <manoj@linux.vnet.ibm.com>, IBM Corporation
5+ * Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation
6+ *
7+ * Copyright (C) 2015 IBM Corporation
8+ *
9+ * This program is free software; you can redistribute it and/or
10+ * modify it under the terms of the GNU General Public License
11+ * as published by the Free Software Foundation; either version
12+ * 2 of the License, or (at your option) any later version.
13+ */
14+
15+#include <misc/cxl.h>
16+#include <asm/unaligned.h>
17+
18+#include <scsi/scsi_host.h>
19+#include <uapi/scsi/cxlflash_ioctl.h>
20+
21+#include "sislite.h"
22+#include "common.h"
23+#include "vlun.h"
24+#include "superpipe.h"
25+
26+/**
27+ * create_local() - allocate and initialize a local LUN information structure
28+ * @sdev: SCSI device associated with LUN.
29+ * @wwid: World Wide Node Name for LUN.
30+ *
31+ * Return: Allocated local llun_info structure on success, NULL on failure
32+ */
33+static struct llun_info *create_local(struct scsi_device *sdev, u8 *wwid)
34+{
35+ struct llun_info *lli = NULL;
36+
37+ lli = kzalloc(sizeof(*lli), GFP_KERNEL);
38+ if (unlikely(!lli)) {
39+ pr_err("%s: could not allocate lli\n", __func__);
40+ goto out;
41+ }
42+
43+ lli->sdev = sdev;
44+ lli->newly_created = true;
45+ lli->host_no = sdev->host->host_no;
46+ lli->in_table = false;
47+
48+ memcpy(lli->wwid, wwid, DK_CXLFLASH_MANAGE_LUN_WWID_LEN);
49+out:
50+ return lli;
51+}
52+
53+/**
54+ * create_global() - allocate and initialize a global LUN information structure
55+ * @sdev: SCSI device associated with LUN.
56+ * @wwid: World Wide Node Name for LUN.
57+ *
58+ * Return: Allocated global glun_info structure on success, NULL on failure
59+ */
60+static struct glun_info *create_global(struct scsi_device *sdev, u8 *wwid)
61+{
62+ struct glun_info *gli = NULL;
63+
64+ gli = kzalloc(sizeof(*gli), GFP_KERNEL);
65+ if (unlikely(!gli)) {
66+ pr_err("%s: could not allocate gli\n", __func__);
67+ goto out;
68+ }
69+
70+ mutex_init(&gli->mutex);
71+ memcpy(gli->wwid, wwid, DK_CXLFLASH_MANAGE_LUN_WWID_LEN);
72+out:
73+ return gli;
74+}
75+
76+/**
77+ * refresh_local() - find and update local LUN information structure by WWID
78+ * @cfg: Internal structure associated with the host.
79+ * @wwid: WWID associated with LUN.
80+ *
81+ * When the LUN is found, mark it by updating it's newly_created field.
82+ *
83+ * Return: Found local lun_info structure on success, NULL on failure
84+ * If a LUN with the WWID is found in the list, refresh it's state.
85+ */
86+static struct llun_info *refresh_local(struct cxlflash_cfg *cfg, u8 *wwid)
87+{
88+ struct llun_info *lli, *temp;
89+
90+ list_for_each_entry_safe(lli, temp, &cfg->lluns, list)
91+ if (!memcmp(lli->wwid, wwid, DK_CXLFLASH_MANAGE_LUN_WWID_LEN)) {
92+ lli->newly_created = false;
93+ return lli;
94+ }
95+
96+ return NULL;
97+}
98+
99+/**
100+ * lookup_global() - find a global LUN information structure by WWID
101+ * @wwid: WWID associated with LUN.
102+ *
103+ * Return: Found global lun_info structure on success, NULL on failure
104+ */
105+static struct glun_info *lookup_global(u8 *wwid)
106+{
107+ struct glun_info *gli, *temp;
108+
109+ list_for_each_entry_safe(gli, temp, &global.gluns, list)
110+ if (!memcmp(gli->wwid, wwid, DK_CXLFLASH_MANAGE_LUN_WWID_LEN))
111+ return gli;
112+
113+ return NULL;
114+}
115+
116+/**
117+ * find_and_create_lun() - find or create a local LUN information structure
118+ * @sdev: SCSI device associated with LUN.
119+ * @wwid: WWID associated with LUN.
120+ *
121+ * The LUN is kept both in a local list (per adapter) and in a global list
122+ * (across all adapters). Certain attributes of the LUN are local to the
123+ * adapter (such as index, port selection mask etc.).
124+ * The block allocation map is shared across all adapters (i.e. associated
125+ * wih the global list). Since different attributes are associated with
126+ * the per adapter and global entries, allocate two separate structures for each
127+ * LUN (one local, one global).
128+ *
129+ * Keep a pointer back from the local to the global entry.
130+ *
131+ * Return: Found/Allocated local lun_info structure on success, NULL on failure
132+ */
133+static struct llun_info *find_and_create_lun(struct scsi_device *sdev, u8 *wwid)
134+{
135+ struct llun_info *lli = NULL;
136+ struct glun_info *gli = NULL;
137+ struct Scsi_Host *shost = sdev->host;
138+ struct cxlflash_cfg *cfg = shost_priv(shost);
139+
140+ mutex_lock(&global.mutex);
141+ if (unlikely(!wwid))
142+ goto out;
143+
144+ lli = refresh_local(cfg, wwid);
145+ if (lli)
146+ goto out;
147+
148+ lli = create_local(sdev, wwid);
149+ if (unlikely(!lli))
150+ goto out;
151+
152+ gli = lookup_global(wwid);
153+ if (gli) {
154+ lli->parent = gli;
155+ list_add(&lli->list, &cfg->lluns);
156+ goto out;
157+ }
158+
159+ gli = create_global(sdev, wwid);
160+ if (unlikely(!gli)) {
161+ kfree(lli);
162+ lli = NULL;
163+ goto out;
164+ }
165+
166+ lli->parent = gli;
167+ list_add(&lli->list, &cfg->lluns);
168+
169+ list_add(&gli->list, &global.gluns);
170+
171+out:
172+ mutex_unlock(&global.mutex);
173+ pr_debug("%s: returning %p\n", __func__, lli);
174+ return lli;
175+}
176+
177+/**
178+ * cxlflash_term_local_luns() - Delete all entries from local LUN list, free.
179+ * @cfg: Internal structure associated with the host.
180+ */
181+void cxlflash_term_local_luns(struct cxlflash_cfg *cfg)
182+{
183+ struct llun_info *lli, *temp;
184+
185+ mutex_lock(&global.mutex);
186+ list_for_each_entry_safe(lli, temp, &cfg->lluns, list) {
187+ list_del(&lli->list);
188+ kfree(lli);
189+ }
190+ mutex_unlock(&global.mutex);
191+}
192+
193+/**
194+ * cxlflash_list_init() - initializes the global LUN list
195+ */
196+void cxlflash_list_init(void)
197+{
198+ INIT_LIST_HEAD(&global.gluns);
199+ mutex_init(&global.mutex);
200+ global.err_page = NULL;
201+}
202+
203+/**
204+ * cxlflash_term_global_luns() - frees resources associated with global LUN list
205+ */
206+void cxlflash_term_global_luns(void)
207+{
208+ struct glun_info *gli, *temp;
209+
210+ mutex_lock(&global.mutex);
211+ list_for_each_entry_safe(gli, temp, &global.gluns, list) {
212+ list_del(&gli->list);
213+ cxlflash_ba_terminate(&gli->blka.ba_lun);
214+ kfree(gli);
215+ }
216+ mutex_unlock(&global.mutex);
217+}
218+
219+/**
220+ * cxlflash_manage_lun() - handles LUN management activities
221+ * @sdev: SCSI device associated with LUN.
222+ * @manage: Manage ioctl data structure.
223+ *
224+ * This routine is used to notify the driver about a LUN's WWID and associate
225+ * SCSI devices (sdev) with a global LUN instance. Additionally it serves to
226+ * change a LUN's operating mode: legacy or superpipe.
227+ *
228+ * Return: 0 on success, -errno on failure
229+ */
230+int cxlflash_manage_lun(struct scsi_device *sdev,
231+ struct dk_cxlflash_manage_lun *manage)
232+{
233+ int rc = 0;
234+ struct llun_info *lli = NULL;
235+ u64 flags = manage->hdr.flags;
236+ u32 chan = sdev->channel;
237+
238+ lli = find_and_create_lun(sdev, manage->wwid);
239+ pr_debug("%s: ENTER: WWID = %016llX%016llX, flags = %016llX li = %p\n",
240+ __func__, get_unaligned_le64(&manage->wwid[0]),
241+ get_unaligned_le64(&manage->wwid[8]),
242+ manage->hdr.flags, lli);
243+ if (unlikely(!lli)) {
244+ rc = -ENOMEM;
245+ goto out;
246+ }
247+
248+ if (flags & DK_CXLFLASH_MANAGE_LUN_ENABLE_SUPERPIPE) {
249+ if (lli->newly_created)
250+ lli->port_sel = CHAN2PORT(chan);
251+ else
252+ lli->port_sel = BOTH_PORTS;
253+ /* Store off lun in unpacked, AFU-friendly format */
254+ lli->lun_id[chan] = lun_to_lunid(sdev->lun);
255+ sdev->hostdata = lli;
256+ } else if (flags & DK_CXLFLASH_MANAGE_LUN_DISABLE_SUPERPIPE) {
257+ if (lli->parent->mode != MODE_NONE)
258+ rc = -EBUSY;
259+ else
260+ sdev->hostdata = NULL;
261+ }
262+
263+out:
264+ pr_debug("%s: returning rc=%d\n", __func__, rc);
265+ return rc;
266+}
drivers/scsi/cxlflash/main.c+2494−0
@@ -0,0 +1,2494 @@
1+/*
2+ * CXL Flash Device Driver
3+ *
4+ * Written by: Manoj N. Kumar <manoj@linux.vnet.ibm.com>, IBM Corporation
5+ * Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation
6+ *
7+ * Copyright (C) 2015 IBM Corporation
8+ *
9+ * This program is free software; you can redistribute it and/or
10+ * modify it under the terms of the GNU General Public License
11+ * as published by the Free Software Foundation; either version
12+ * 2 of the License, or (at your option) any later version.
13+ */
14+
15+#include <linux/delay.h>
16+#include <linux/list.h>
17+#include <linux/module.h>
18+#include <linux/pci.h>
19+
20+#include <asm/unaligned.h>
21+
22+#include <misc/cxl.h>
23+
24+#include <scsi/scsi_cmnd.h>
25+#include <scsi/scsi_host.h>
26+#include <uapi/scsi/cxlflash_ioctl.h>
27+
28+#include "main.h"
29+#include "sislite.h"
30+#include "common.h"
31+
32+MODULE_DESCRIPTION(CXLFLASH_ADAPTER_NAME);
33+MODULE_AUTHOR("Manoj N. Kumar <manoj@linux.vnet.ibm.com>");
34+MODULE_AUTHOR("Matthew R. Ochs <mrochs@linux.vnet.ibm.com>");
35+MODULE_LICENSE("GPL");
36+
37+
38+/**
39+ * cxlflash_cmd_checkout() - checks out an AFU command
40+ * @afu: AFU to checkout from.
41+ *
42+ * Commands are checked out in a round-robin fashion. Note that since
43+ * the command pool is larger than the hardware queue, the majority of
44+ * times we will only loop once or twice before getting a command. The
45+ * buffer and CDB within the command are initialized (zeroed) prior to
46+ * returning.
47+ *
48+ * Return: The checked out command or NULL when command pool is empty.
49+ */
50+struct afu_cmd *cxlflash_cmd_checkout(struct afu *afu)
51+{
52+ int k, dec = CXLFLASH_NUM_CMDS;
53+ struct afu_cmd *cmd;
54+
55+ while (dec--) {
56+ k = (afu->cmd_couts++ & (CXLFLASH_NUM_CMDS - 1));
57+
58+ cmd = &afu->cmd[k];
59+
60+ if (!atomic_dec_if_positive(&cmd->free)) {
61+ pr_debug("%s: returning found index=%d\n",
62+ __func__, cmd->slot);
63+ memset(cmd->buf, 0, CMD_BUFSIZE);
64+ memset(cmd->rcb.cdb, 0, sizeof(cmd->rcb.cdb));
65+ return cmd;
66+ }
67+ }
68+
69+ return NULL;
70+}
71+
72+/**
73+ * cxlflash_cmd_checkin() - checks in an AFU command
74+ * @cmd: AFU command to checkin.
75+ *
76+ * Safe to pass commands that have already been checked in. Several
77+ * internal tracking fields are reset as part of the checkin. Note
78+ * that these are intentionally reset prior to toggling the free bit
79+ * to avoid clobbering values in the event that the command is checked
80+ * out right away.
81+ */
82+void cxlflash_cmd_checkin(struct afu_cmd *cmd)
83+{
84+ cmd->rcb.scp = NULL;
85+ cmd->rcb.timeout = 0;
86+ cmd->sa.ioasc = 0;
87+ cmd->cmd_tmf = false;
88+ cmd->sa.host_use[0] = 0; /* clears both completion and retry bytes */
89+
90+ if (unlikely(atomic_inc_return(&cmd->free) != 1)) {
91+ pr_err("%s: Freeing cmd (%d) that is not in use!\n",
92+ __func__, cmd->slot);
93+ return;
94+ }
95+
96+ pr_debug("%s: released cmd %p index=%d\n", __func__, cmd, cmd->slot);
97+}
98+
99+/**
100+ * process_cmd_err() - command error handler
101+ * @cmd: AFU command that experienced the error.
102+ * @scp: SCSI command associated with the AFU command in error.
103+ *
104+ * Translates error bits from AFU command to SCSI command results.
105+ */
106+static void process_cmd_err(struct afu_cmd *cmd, struct scsi_cmnd *scp)
107+{
108+ struct sisl_ioarcb *ioarcb;
109+ struct sisl_ioasa *ioasa;
110+
111+ if (unlikely(!cmd))
112+ return;
113+
114+ ioarcb = &(cmd->rcb);
115+ ioasa = &(cmd->sa);
116+
117+ if (ioasa->rc.flags & SISL_RC_FLAGS_UNDERRUN) {
118+ pr_debug("%s: cmd underrun cmd = %p scp = %p\n",
119+ __func__, cmd, scp);
120+ scp->result = (DID_ERROR << 16);
121+ }
122+
123+ if (ioasa->rc.flags & SISL_RC_FLAGS_OVERRUN) {
124+ pr_debug("%s: cmd underrun cmd = %p scp = %p\n",
125+ __func__, cmd, scp);
126+ scp->result = (DID_ERROR << 16);
127+ }
128+
129+ pr_debug("%s: cmd failed afu_rc=%d scsi_rc=%d fc_rc=%d "
130+ "afu_extra=0x%X, scsi_entra=0x%X, fc_extra=0x%X\n",
131+ __func__, ioasa->rc.afu_rc, ioasa->rc.scsi_rc,
132+ ioasa->rc.fc_rc, ioasa->afu_extra, ioasa->scsi_extra,
133+ ioasa->fc_extra);
134+
135+ if (ioasa->rc.scsi_rc) {
136+ /* We have a SCSI status */
137+ if (ioasa->rc.flags & SISL_RC_FLAGS_SENSE_VALID) {
138+ memcpy(scp->sense_buffer, ioasa->sense_data,
139+ SISL_SENSE_DATA_LEN);
140+ scp->result = ioasa->rc.scsi_rc;
141+ } else
142+ scp->result = ioasa->rc.scsi_rc | (DID_ERROR << 16);
143+ }
144+
145+ /*
146+ * We encountered an error. Set scp->result based on nature
147+ * of error.
148+ */
149+ if (ioasa->rc.fc_rc) {
150+ /* We have an FC status */
151+ switch (ioasa->rc.fc_rc) {
152+ case SISL_FC_RC_LINKDOWN:
153+ scp->result = (DID_REQUEUE << 16);
154+ break;
155+ case SISL_FC_RC_RESID:
156+ /* This indicates an FCP resid underrun */
157+ if (!(ioasa->rc.flags & SISL_RC_FLAGS_OVERRUN)) {
158+ /* If the SISL_RC_FLAGS_OVERRUN flag was set,
159+ * then we will handle this error else where.
160+ * If not then we must handle it here.
161+ * This is probably an AFU bug. We will
162+ * attempt a retry to see if that resolves it.
163+ */
164+ scp->result = (DID_ERROR << 16);
165+ }
166+ break;
167+ case SISL_FC_RC_RESIDERR:
168+ /* Resid mismatch between adapter and device */
169+ case SISL_FC_RC_TGTABORT:
170+ case SISL_FC_RC_ABORTOK:
171+ case SISL_FC_RC_ABORTFAIL:
172+ case SISL_FC_RC_NOLOGI:
173+ case SISL_FC_RC_ABORTPEND:
174+ case SISL_FC_RC_WRABORTPEND:
175+ case SISL_FC_RC_NOEXP:
176+ case SISL_FC_RC_INUSE:
177+ scp->result = (DID_ERROR << 16);
178+ break;
179+ }
180+ }
181+
182+ if (ioasa->rc.afu_rc) {
183+ /* We have an AFU error */
184+ switch (ioasa->rc.afu_rc) {
185+ case SISL_AFU_RC_NO_CHANNELS:
186+ scp->result = (DID_MEDIUM_ERROR << 16);
187+ break;
188+ case SISL_AFU_RC_DATA_DMA_ERR:
189+ switch (ioasa->afu_extra) {
190+ case SISL_AFU_DMA_ERR_PAGE_IN:
191+ /* Retry */
192+ scp->result = (DID_IMM_RETRY << 16);
193+ break;
194+ case SISL_AFU_DMA_ERR_INVALID_EA:
195+ default:
196+ scp->result = (DID_ERROR << 16);
197+ }
198+ break;
199+ case SISL_AFU_RC_OUT_OF_DATA_BUFS:
200+ /* Retry */
201+ scp->result = (DID_ALLOC_FAILURE << 16);
202+ break;
203+ default:
204+ scp->result = (DID_ERROR << 16);
205+ }
206+ }
207+}
208+
209+/**
210+ * cmd_complete() - command completion handler
211+ * @cmd: AFU command that has completed.
212+ *
213+ * Prepares and submits command that has either completed or timed out to
214+ * the SCSI stack. Checks AFU command back into command pool for non-internal
215+ * (rcb.scp populated) commands.
216+ */
217+static void cmd_complete(struct afu_cmd *cmd)
218+{
219+ struct scsi_cmnd *scp;
220+ u32 resid;
221+ ulong lock_flags;
222+ struct afu *afu = cmd->parent;
223+ struct cxlflash_cfg *cfg = afu->parent;
224+ bool cmd_is_tmf;
225+
226+ spin_lock_irqsave(&cmd->slock, lock_flags);
227+ cmd->sa.host_use_b[0] |= B_DONE;
228+ spin_unlock_irqrestore(&cmd->slock, lock_flags);
229+
230+ if (cmd->rcb.scp) {
231+ scp = cmd->rcb.scp;
232+ if (unlikely(cmd->sa.rc.afu_rc ||
233+ cmd->sa.rc.scsi_rc ||
234+ cmd->sa.rc.fc_rc))
235+ process_cmd_err(cmd, scp);
236+ else
237+ scp->result = (DID_OK << 16);
238+
239+ resid = cmd->sa.resid;
240+ cmd_is_tmf = cmd->cmd_tmf;
241+ cxlflash_cmd_checkin(cmd); /* Don't use cmd after here */
242+
243+ pr_debug("%s: calling scsi_set_resid, scp=%p "
244+ "result=%X resid=%d\n", __func__,
245+ scp, scp->result, resid);
246+
247+ scsi_set_resid(scp, resid);
248+ scsi_dma_unmap(scp);
249+ scp->scsi_done(scp);
250+
251+ if (cmd_is_tmf) {
252+ spin_lock_irqsave(&cfg->tmf_waitq.lock, lock_flags);
253+ cfg->tmf_active = false;
254+ wake_up_all_locked(&cfg->tmf_waitq);
255+ spin_unlock_irqrestore(&cfg->tmf_waitq.lock,
256+ lock_flags);
257+ }
258+ } else
259+ complete(&cmd->cevent);
260+}
261+
262+/**
263+ * send_tmf() - sends a Task Management Function (TMF)
264+ * @afu: AFU to checkout from.
265+ * @scp: SCSI command from stack.
266+ * @tmfcmd: TMF command to send.
267+ *
268+ * Return:
269+ * 0 on success
270+ * SCSI_MLQUEUE_HOST_BUSY when host is busy
271+ */
272+static int send_tmf(struct afu *afu, struct scsi_cmnd *scp, u64 tmfcmd)
273+{
274+ struct afu_cmd *cmd;
275+
276+ u32 port_sel = scp->device->channel + 1;
277+ short lflag = 0;
278+ struct Scsi_Host *host = scp->device->host;
279+ struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)host->hostdata;
280+ ulong lock_flags;
281+ int rc = 0;
282+
283+ cmd = cxlflash_cmd_checkout(afu);
284+ if (unlikely(!cmd)) {
285+ pr_err("%s: could not get a free command\n", __func__);
286+ rc = SCSI_MLQUEUE_HOST_BUSY;
287+ goto out;
288+ }
289+
290+ /* If a Task Management Function is active, do not send one more.
291+ */
292+ spin_lock_irqsave(&cfg->tmf_waitq.lock, lock_flags);
293+ if (cfg->tmf_active)
294+ wait_event_interruptible_locked_irq(cfg->tmf_waitq,
295+ !cfg->tmf_active);
296+ cfg->tmf_active = true;
297+ cmd->cmd_tmf = true;
298+ spin_unlock_irqrestore(&cfg->tmf_waitq.lock, lock_flags);
299+
300+ cmd->rcb.ctx_id = afu->ctx_hndl;
301+ cmd->rcb.port_sel = port_sel;
302+ cmd->rcb.lun_id = lun_to_lunid(scp->device->lun);
303+
304+ lflag = SISL_REQ_FLAGS_TMF_CMD;
305+
306+ cmd->rcb.req_flags = (SISL_REQ_FLAGS_PORT_LUN_ID |
307+ SISL_REQ_FLAGS_SUP_UNDERRUN | lflag);
308+
309+ /* Stash the scp in the reserved field, for reuse during interrupt */
310+ cmd->rcb.scp = scp;
311+
312+ /* Copy the CDB from the cmd passed in */
313+ memcpy(cmd->rcb.cdb, &tmfcmd, sizeof(tmfcmd));
314+
315+ /* Send the command */
316+ rc = cxlflash_send_cmd(afu, cmd);
317+ if (unlikely(rc)) {
318+ cxlflash_cmd_checkin(cmd);
319+ spin_lock_irqsave(&cfg->tmf_waitq.lock, lock_flags);
320+ cfg->tmf_active = false;
321+ spin_unlock_irqrestore(&cfg->tmf_waitq.lock, lock_flags);
322+ goto out;
323+ }
324+
325+ spin_lock_irqsave(&cfg->tmf_waitq.lock, lock_flags);
326+ wait_event_interruptible_locked_irq(cfg->tmf_waitq, !cfg->tmf_active);
327+ spin_unlock_irqrestore(&cfg->tmf_waitq.lock, lock_flags);
328+out:
329+ return rc;
330+}
331+
332+/**
333+ * cxlflash_driver_info() - information handler for this host driver
334+ * @host: SCSI host associated with device.
335+ *
336+ * Return: A string describing the device.
337+ */
338+static const char *cxlflash_driver_info(struct Scsi_Host *host)
339+{
340+ return CXLFLASH_ADAPTER_NAME;
341+}
342+
343+/**
344+ * cxlflash_queuecommand() - sends a mid-layer request
345+ * @host: SCSI host associated with device.
346+ * @scp: SCSI command to send.
347+ *
348+ * Return:
349+ * 0 on success
350+ * SCSI_MLQUEUE_HOST_BUSY when host is busy
351+ */
352+static int cxlflash_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scp)
353+{
354+ struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)host->hostdata;
355+ struct afu *afu = cfg->afu;
356+ struct pci_dev *pdev = cfg->dev;
357+ struct afu_cmd *cmd;
358+ u32 port_sel = scp->device->channel + 1;
359+ int nseg, i, ncount;
360+ struct scatterlist *sg;
361+ ulong lock_flags;
362+ short lflag = 0;
363+ int rc = 0;
364+
365+ pr_debug("%s: (scp=%p) %d/%d/%d/%llu cdb=(%08X-%08X-%08X-%08X)\n",
366+ __func__, scp, host->host_no, scp->device->channel,
367+ scp->device->id, scp->device->lun,
368+ get_unaligned_be32(&((u32 *)scp->cmnd)[0]),
369+ get_unaligned_be32(&((u32 *)scp->cmnd)[1]),
370+ get_unaligned_be32(&((u32 *)scp->cmnd)[2]),
371+ get_unaligned_be32(&((u32 *)scp->cmnd)[3]));
372+
373+ /* If a Task Management Function is active, wait for it to complete
374+ * before continuing with regular commands.
375+ */
376+ spin_lock_irqsave(&cfg->tmf_waitq.lock, lock_flags);
377+ if (cfg->tmf_active) {
378+ spin_unlock_irqrestore(&cfg->tmf_waitq.lock, lock_flags);
379+ rc = SCSI_MLQUEUE_HOST_BUSY;
380+ goto out;
381+ }
382+ spin_unlock_irqrestore(&cfg->tmf_waitq.lock, lock_flags);
383+
384+ switch (cfg->state) {
385+ case STATE_LIMBO:
386+ dev_dbg_ratelimited(&cfg->dev->dev, "%s: device in limbo!\n",
387+ __func__);
388+ rc = SCSI_MLQUEUE_HOST_BUSY;
389+ goto out;
390+ case STATE_FAILTERM:
391+ dev_dbg_ratelimited(&cfg->dev->dev, "%s: device has failed!\n",
392+ __func__);
393+ scp->result = (DID_NO_CONNECT << 16);
394+ scp->scsi_done(scp);
395+ rc = 0;
396+ goto out;
397+ default:
398+ break;
399+ }
400+
401+ cmd = cxlflash_cmd_checkout(afu);
402+ if (unlikely(!cmd)) {
403+ pr_err("%s: could not get a free command\n", __func__);
404+ rc = SCSI_MLQUEUE_HOST_BUSY;
405+ goto out;
406+ }
407+
408+ cmd->rcb.ctx_id = afu->ctx_hndl;
409+ cmd->rcb.port_sel = port_sel;
410+ cmd->rcb.lun_id = lun_to_lunid(scp->device->lun);
411+
412+ if (scp->sc_data_direction == DMA_TO_DEVICE)
413+ lflag = SISL_REQ_FLAGS_HOST_WRITE;
414+ else
415+ lflag = SISL_REQ_FLAGS_HOST_READ;
416+
417+ cmd->rcb.req_flags = (SISL_REQ_FLAGS_PORT_LUN_ID |
418+ SISL_REQ_FLAGS_SUP_UNDERRUN | lflag);
419+
420+ /* Stash the scp in the reserved field, for reuse during interrupt */
421+ cmd->rcb.scp = scp;
422+
423+ nseg = scsi_dma_map(scp);
424+ if (unlikely(nseg < 0)) {
425+ dev_err(&pdev->dev, "%s: Fail DMA map! nseg=%d\n",
426+ __func__, nseg);
427+ rc = SCSI_MLQUEUE_HOST_BUSY;
428+ goto out;
429+ }
430+
431+ ncount = scsi_sg_count(scp);
432+ scsi_for_each_sg(scp, sg, ncount, i) {
433+ cmd->rcb.data_len = sg_dma_len(sg);
434+ cmd->rcb.data_ea = sg_dma_address(sg);
435+ }
436+
437+ /* Copy the CDB from the scsi_cmnd passed in */
438+ memcpy(cmd->rcb.cdb, scp->cmnd, sizeof(cmd->rcb.cdb));
439+
440+ /* Send the command */
441+ rc = cxlflash_send_cmd(afu, cmd);
442+ if (unlikely(rc)) {
443+ cxlflash_cmd_checkin(cmd);
444+ scsi_dma_unmap(scp);
445+ }
446+
447+out:
448+ return rc;
449+}
450+
451+/**
452+ * cxlflash_eh_device_reset_handler() - reset a single LUN
453+ * @scp: SCSI command to send.
454+ *
455+ * Return:
456+ * SUCCESS as defined in scsi/scsi.h
457+ * FAILED as defined in scsi/scsi.h
458+ */
459+static int cxlflash_eh_device_reset_handler(struct scsi_cmnd *scp)
460+{
461+ int rc = SUCCESS;
462+ struct Scsi_Host *host = scp->device->host;
463+ struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)host->hostdata;
464+ struct afu *afu = cfg->afu;
465+ int rcr = 0;
466+
467+ pr_debug("%s: (scp=%p) %d/%d/%d/%llu "
468+ "cdb=(%08X-%08X-%08X-%08X)\n", __func__, scp,
469+ host->host_no, scp->device->channel,
470+ scp->device->id, scp->device->lun,
471+ get_unaligned_be32(&((u32 *)scp->cmnd)[0]),
472+ get_unaligned_be32(&((u32 *)scp->cmnd)[1]),
473+ get_unaligned_be32(&((u32 *)scp->cmnd)[2]),
474+ get_unaligned_be32(&((u32 *)scp->cmnd)[3]));
475+
476+ switch (cfg->state) {
477+ case STATE_NORMAL:
478+ rcr = send_tmf(afu, scp, TMF_LUN_RESET);
479+ if (unlikely(rcr))
480+ rc = FAILED;
481+ break;
482+ case STATE_LIMBO:
483+ wait_event(cfg->limbo_waitq, cfg->state != STATE_LIMBO);
484+ if (cfg->state == STATE_NORMAL)
485+ break;
486+ /* fall through */
487+ default:
488+ rc = FAILED;
489+ break;
490+ }
491+
492+ pr_debug("%s: returning rc=%d\n", __func__, rc);
493+ return rc;
494+}
495+
496+/**
497+ * cxlflash_eh_host_reset_handler() - reset the host adapter
498+ * @scp: SCSI command from stack identifying host.
499+ *
500+ * Return:
501+ * SUCCESS as defined in scsi/scsi.h
502+ * FAILED as defined in scsi/scsi.h
503+ */
504+static int cxlflash_eh_host_reset_handler(struct scsi_cmnd *scp)
505+{
506+ int rc = SUCCESS;
507+ int rcr = 0;
508+ struct Scsi_Host *host = scp->device->host;
509+ struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)host->hostdata;
510+
511+ pr_debug("%s: (scp=%p) %d/%d/%d/%llu "
512+ "cdb=(%08X-%08X-%08X-%08X)\n", __func__, scp,
513+ host->host_no, scp->device->channel,
514+ scp->device->id, scp->device->lun,
515+ get_unaligned_be32(&((u32 *)scp->cmnd)[0]),
516+ get_unaligned_be32(&((u32 *)scp->cmnd)[1]),
517+ get_unaligned_be32(&((u32 *)scp->cmnd)[2]),
518+ get_unaligned_be32(&((u32 *)scp->cmnd)[3]));
519+
520+ switch (cfg->state) {
521+ case STATE_NORMAL:
522+ cfg->state = STATE_LIMBO;
523+ scsi_block_requests(cfg->host);
524+ cxlflash_mark_contexts_error(cfg);
525+ rcr = cxlflash_afu_reset(cfg);
526+ if (rcr) {
527+ rc = FAILED;
528+ cfg->state = STATE_FAILTERM;
529+ } else
530+ cfg->state = STATE_NORMAL;
531+ wake_up_all(&cfg->limbo_waitq);
532+ scsi_unblock_requests(cfg->host);
533+ break;
534+ case STATE_LIMBO:
535+ wait_event(cfg->limbo_waitq, cfg->state != STATE_LIMBO);
536+ if (cfg->state == STATE_NORMAL)
537+ break;
538+ /* fall through */
539+ default:
540+ rc = FAILED;
541+ break;
542+ }
543+
544+ pr_debug("%s: returning rc=%d\n", __func__, rc);
545+ return rc;
546+}
547+
548+/**
549+ * cxlflash_change_queue_depth() - change the queue depth for the device
550+ * @sdev: SCSI device destined for queue depth change.
551+ * @qdepth: Requested queue depth value to set.
552+ *
553+ * The requested queue depth is capped to the maximum supported value.
554+ *
555+ * Return: The actual queue depth set.
556+ */
557+static int cxlflash_change_queue_depth(struct scsi_device *sdev, int qdepth)
558+{
559+
560+ if (qdepth > CXLFLASH_MAX_CMDS_PER_LUN)
561+ qdepth = CXLFLASH_MAX_CMDS_PER_LUN;
562+
563+ scsi_change_queue_depth(sdev, qdepth);
564+ return sdev->queue_depth;
565+}
566+
567+/**
568+ * cxlflash_show_port_status() - queries and presents the current port status
569+ * @dev: Generic device associated with the host owning the port.
570+ * @attr: Device attribute representing the port.
571+ * @buf: Buffer of length PAGE_SIZE to report back port status in ASCII.
572+ *
573+ * Return: The size of the ASCII string returned in @buf.
574+ */
575+static ssize_t cxlflash_show_port_status(struct device *dev,
576+ struct device_attribute *attr,
577+ char *buf)
578+{
579+ struct Scsi_Host *shost = class_to_shost(dev);
580+ struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)shost->hostdata;
581+ struct afu *afu = cfg->afu;
582+
583+ char *disp_status;
584+ int rc;
585+ u32 port;
586+ u64 status;
587+ u64 *fc_regs;
588+
589+ rc = kstrtouint((attr->attr.name + 4), 10, &port);
590+ if (rc || (port >= NUM_FC_PORTS))
591+ return 0;
592+
593+ fc_regs = &afu->afu_map->global.fc_regs[port][0];
594+ status =
595+ (readq_be(&fc_regs[FC_MTIP_STATUS / 8]) & FC_MTIP_STATUS_MASK);
596+
597+ if (status == FC_MTIP_STATUS_ONLINE)
598+ disp_status = "online";
599+ else if (status == FC_MTIP_STATUS_OFFLINE)
600+ disp_status = "offline";
601+ else
602+ disp_status = "unknown";
603+
604+ return snprintf(buf, PAGE_SIZE, "%s\n", disp_status);
605+}
606+
607+/**
608+ * cxlflash_show_lun_mode() - presents the current LUN mode of the host
609+ * @dev: Generic device associated with the host.
610+ * @attr: Device attribute representing the lun mode.
611+ * @buf: Buffer of length PAGE_SIZE to report back the LUN mode in ASCII.
612+ *
613+ * Return: The size of the ASCII string returned in @buf.
614+ */
615+static ssize_t cxlflash_show_lun_mode(struct device *dev,
616+ struct device_attribute *attr, char *buf)
617+{
618+ struct Scsi_Host *shost = class_to_shost(dev);
619+ struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)shost->hostdata;
620+ struct afu *afu = cfg->afu;
621+
622+ return snprintf(buf, PAGE_SIZE, "%u\n", afu->internal_lun);
623+}
624+
625+/**
626+ * cxlflash_store_lun_mode() - sets the LUN mode of the host
627+ * @dev: Generic device associated with the host.
628+ * @attr: Device attribute representing the lun mode.
629+ * @buf: Buffer of length PAGE_SIZE containing the LUN mode in ASCII.
630+ * @count: Length of data resizing in @buf.
631+ *
632+ * The CXL Flash AFU supports a dummy LUN mode where the external
633+ * links and storage are not required. Space on the FPGA is used
634+ * to create 1 or 2 small LUNs which are presented to the system
635+ * as if they were a normal storage device. This feature is useful
636+ * during development and also provides manufacturing with a way
637+ * to test the AFU without an actual device.
638+ *
639+ * 0 = external LUN[s] (default)
640+ * 1 = internal LUN (1 x 64K, 512B blocks, id 0)
641+ * 2 = internal LUN (1 x 64K, 4K blocks, id 0)
642+ * 3 = internal LUN (2 x 32K, 512B blocks, ids 0,1)
643+ * 4 = internal LUN (2 x 32K, 4K blocks, ids 0,1)
644+ *
645+ * Return: The size of the ASCII string returned in @buf.
646+ */
647+static ssize_t cxlflash_store_lun_mode(struct device *dev,
648+ struct device_attribute *attr,
649+ const char *buf, size_t count)
650+{
651+ struct Scsi_Host *shost = class_to_shost(dev);
652+ struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)shost->hostdata;
653+ struct afu *afu = cfg->afu;
654+ int rc;
655+ u32 lun_mode;
656+
657+ rc = kstrtouint(buf, 10, &lun_mode);
658+ if (!rc && (lun_mode < 5) && (lun_mode != afu->internal_lun)) {
659+ afu->internal_lun = lun_mode;
660+ cxlflash_afu_reset(cfg);
661+ scsi_scan_host(cfg->host);
662+ }
663+
664+ return count;
665+}
666+
667+/**
668+ * cxlflash_show_ioctl_version() - presents the current ioctl version of the host
669+ * @dev: Generic device associated with the host.
670+ * @attr: Device attribute representing the ioctl version.
671+ * @buf: Buffer of length PAGE_SIZE to report back the ioctl version.
672+ *
673+ * Return: The size of the ASCII string returned in @buf.
674+ */
675+static ssize_t cxlflash_show_ioctl_version(struct device *dev,
676+ struct device_attribute *attr,
677+ char *buf)
678+{
679+ return scnprintf(buf, PAGE_SIZE, "%u\n", DK_CXLFLASH_VERSION_0);
680+}
681+
682+/**
683+ * cxlflash_show_dev_mode() - presents the current mode of the device
684+ * @dev: Generic device associated with the device.
685+ * @attr: Device attribute representing the device mode.
686+ * @buf: Buffer of length PAGE_SIZE to report back the dev mode in ASCII.
687+ *
688+ * Return: The size of the ASCII string returned in @buf.
689+ */
690+static ssize_t cxlflash_show_dev_mode(struct device *dev,
691+ struct device_attribute *attr, char *buf)
692+{
693+ struct scsi_device *sdev = to_scsi_device(dev);
694+
695+ return snprintf(buf, PAGE_SIZE, "%s\n",
696+ sdev->hostdata ? "superpipe" : "legacy");
697+}
698+
699+/**
700+ * cxlflash_wait_for_pci_err_recovery() - wait for error recovery during probe
701+ * @cxlflash: Internal structure associated with the host.
702+ */
703+static void cxlflash_wait_for_pci_err_recovery(struct cxlflash_cfg *cfg)
704+{
705+ struct pci_dev *pdev = cfg->dev;
706+
707+ if (pci_channel_offline(pdev))
708+ wait_event_timeout(cfg->limbo_waitq,
709+ !pci_channel_offline(pdev),
710+ CXLFLASH_PCI_ERROR_RECOVERY_TIMEOUT);
711+}
712+
713+/*
714+ * Host attributes
715+ */
716+static DEVICE_ATTR(port0, S_IRUGO, cxlflash_show_port_status, NULL);
717+static DEVICE_ATTR(port1, S_IRUGO, cxlflash_show_port_status, NULL);
718+static DEVICE_ATTR(lun_mode, S_IRUGO | S_IWUSR, cxlflash_show_lun_mode,
719+ cxlflash_store_lun_mode);
720+static DEVICE_ATTR(ioctl_version, S_IRUGO, cxlflash_show_ioctl_version, NULL);
721+
722+static struct device_attribute *cxlflash_host_attrs[] = {
723+ &dev_attr_port0,
724+ &dev_attr_port1,
725+ &dev_attr_lun_mode,
726+ &dev_attr_ioctl_version,
727+ NULL
728+};
729+
730+/*
731+ * Device attributes
732+ */
733+static DEVICE_ATTR(mode, S_IRUGO, cxlflash_show_dev_mode, NULL);
734+
735+static struct device_attribute *cxlflash_dev_attrs[] = {
736+ &dev_attr_mode,
737+ NULL
738+};
739+
740+/*
741+ * Host template
742+ */
743+static struct scsi_host_template driver_template = {
744+ .module = THIS_MODULE,
745+ .name = CXLFLASH_ADAPTER_NAME,
746+ .info = cxlflash_driver_info,
747+ .ioctl = cxlflash_ioctl,
748+ .proc_name = CXLFLASH_NAME,
749+ .queuecommand = cxlflash_queuecommand,
750+ .eh_device_reset_handler = cxlflash_eh_device_reset_handler,
751+ .eh_host_reset_handler = cxlflash_eh_host_reset_handler,
752+ .change_queue_depth = cxlflash_change_queue_depth,
753+ .cmd_per_lun = 16,
754+ .can_queue = CXLFLASH_MAX_CMDS,
755+ .this_id = -1,
756+ .sg_tablesize = SG_NONE, /* No scatter gather support. */
757+ .max_sectors = CXLFLASH_MAX_SECTORS,
758+ .use_clustering = ENABLE_CLUSTERING,
759+ .shost_attrs = cxlflash_host_attrs,
760+ .sdev_attrs = cxlflash_dev_attrs,
761+};
762+
763+/*
764+ * Device dependent values
765+ */
766+static struct dev_dependent_vals dev_corsa_vals = { CXLFLASH_MAX_SECTORS };
767+
768+/*
769+ * PCI device binding table
770+ */
771+static struct pci_device_id cxlflash_pci_table[] = {
772+ {PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CORSA,
773+ PCI_ANY_ID, PCI_ANY_ID, 0, 0, (kernel_ulong_t)&dev_corsa_vals},
774+ {}
775+};
776+
777+MODULE_DEVICE_TABLE(pci, cxlflash_pci_table);
778+
779+/**
780+ * free_mem() - free memory associated with the AFU
781+ * @cxlflash: Internal structure associated with the host.
782+ */
783+static void free_mem(struct cxlflash_cfg *cfg)
784+{
785+ int i;
786+ char *buf = NULL;
787+ struct afu *afu = cfg->afu;
788+
789+ if (cfg->afu) {
790+ for (i = 0; i < CXLFLASH_NUM_CMDS; i++) {
791+ buf = afu->cmd[i].buf;
792+ if (!((u64)buf & (PAGE_SIZE - 1)))
793+ free_page((ulong)buf);
794+ }
795+
796+ free_pages((ulong)afu, get_order(sizeof(struct afu)));
797+ cfg->afu = NULL;
798+ }
799+}
800+
801+/**
802+ * stop_afu() - stops the AFU command timers and unmaps the MMIO space
803+ * @cxlflash: Internal structure associated with the host.
804+ *
805+ * Safe to call with AFU in a partially allocated/initialized state.
806+ */
807+static void stop_afu(struct cxlflash_cfg *cfg)
808+{
809+ int i;
810+ struct afu *afu = cfg->afu;
811+
812+ if (likely(afu)) {
813+ for (i = 0; i < CXLFLASH_NUM_CMDS; i++)
814+ complete(&afu->cmd[i].cevent);
815+
816+ if (likely(afu->afu_map)) {
817+ cxl_psa_unmap((void *)afu->afu_map);
818+ afu->afu_map = NULL;
819+ }
820+ }
821+}
822+
823+/**
824+ * term_mc() - terminates the master context
825+ * @cxlflash: Internal structure associated with the host.
826+ * @level: Depth of allocation, where to begin waterfall tear down.
827+ *
828+ * Safe to call with AFU/MC in partially allocated/initialized state.
829+ */
830+static void term_mc(struct cxlflash_cfg *cfg, enum undo_level level)
831+{
832+ int rc = 0;
833+ struct afu *afu = cfg->afu;
834+
835+ if (!afu || !cfg->mcctx) {
836+ pr_err("%s: returning from term_mc with NULL afu or MC\n",
837+ __func__);
838+ return;
839+ }
840+
841+ switch (level) {
842+ case UNDO_START:
843+ rc = cxl_stop_context(cfg->mcctx);
844+ BUG_ON(rc);
845+ case UNMAP_THREE:
846+ cxl_unmap_afu_irq(cfg->mcctx, 3, afu);
847+ case UNMAP_TWO:
848+ cxl_unmap_afu_irq(cfg->mcctx, 2, afu);
849+ case UNMAP_ONE:
850+ cxl_unmap_afu_irq(cfg->mcctx, 1, afu);
851+ case FREE_IRQ:
852+ cxl_free_afu_irqs(cfg->mcctx);
853+ case RELEASE_CONTEXT:
854+ cfg->mcctx = NULL;
855+ }
856+}
857+
858+/**
859+ * term_afu() - terminates the AFU
860+ * @cxlflash: Internal structure associated with the host.
861+ *
862+ * Safe to call with AFU/MC in partially allocated/initialized state.
863+ */
864+static void term_afu(struct cxlflash_cfg *cfg)
865+{
866+ term_mc(cfg, UNDO_START);
867+
868+ if (cfg->afu)
869+ stop_afu(cfg);
870+
871+ pr_debug("%s: returning\n", __func__);
872+}
873+
874+/**
875+ * cxlflash_remove() - PCI entry point to tear down host
876+ * @pdev: PCI device associated with the host.
877+ *
878+ * Safe to use as a cleanup in partially allocated/initialized state.
879+ */
880+static void cxlflash_remove(struct pci_dev *pdev)
881+{
882+ struct cxlflash_cfg *cfg = pci_get_drvdata(pdev);
883+ ulong lock_flags;
884+
885+ /* If a Task Management Function is active, wait for it to complete
886+ * before continuing with remove.
887+ */
888+ spin_lock_irqsave(&cfg->tmf_waitq.lock, lock_flags);
889+ if (cfg->tmf_active)
890+ wait_event_interruptible_locked_irq(cfg->tmf_waitq,
891+ !cfg->tmf_active);
892+ spin_unlock_irqrestore(&cfg->tmf_waitq.lock, lock_flags);
893+
894+ cfg->state = STATE_FAILTERM;
895+ cxlflash_stop_term_user_contexts(cfg);
896+
897+ switch (cfg->init_state) {
898+ case INIT_STATE_SCSI:
899+ cxlflash_term_local_luns(cfg);
900+ scsi_remove_host(cfg->host);
901+ scsi_host_put(cfg->host);
902+ /* Fall through */
903+ case INIT_STATE_AFU:
904+ term_afu(cfg);
905+ case INIT_STATE_PCI:
906+ pci_release_regions(cfg->dev);
907+ pci_disable_device(pdev);
908+ case INIT_STATE_NONE:
909+ flush_work(&cfg->work_q);
910+ free_mem(cfg);
911+ break;
912+ }
913+
914+ pr_debug("%s: returning\n", __func__);
915+}
916+
917+/**
918+ * alloc_mem() - allocates the AFU and its command pool
919+ * @cxlflash: Internal structure associated with the host.
920+ *
921+ * A partially allocated state remains on failure.
922+ *
923+ * Return:
924+ * 0 on success
925+ * -ENOMEM on failure to allocate memory
926+ */
927+static int alloc_mem(struct cxlflash_cfg *cfg)
928+{
929+ int rc = 0;
930+ int i;
931+ char *buf = NULL;
932+
933+ /* This allocation is about 12K, i.e. only 1 64k page
934+ * and upto 4 4k pages
935+ */
936+ cfg->afu = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
937+ get_order(sizeof(struct afu)));
938+ if (unlikely(!cfg->afu)) {
939+ pr_err("%s: cannot get %d free pages\n",
940+ __func__, get_order(sizeof(struct afu)));
941+ rc = -ENOMEM;
942+ goto out;
943+ }
944+ cfg->afu->parent = cfg;
945+ cfg->afu->afu_map = NULL;
946+
947+ for (i = 0; i < CXLFLASH_NUM_CMDS; buf += CMD_BUFSIZE, i++) {
948+ if (!((u64)buf & (PAGE_SIZE - 1))) {
949+ buf = (void *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
950+ if (unlikely(!buf)) {
951+ pr_err("%s: Allocate command buffers fail!\n",
952+ __func__);
953+ rc = -ENOMEM;
954+ free_mem(cfg);
955+ goto out;
956+ }
957+ }
958+
959+ cfg->afu->cmd[i].buf = buf;
960+ atomic_set(&cfg->afu->cmd[i].free, 1);
961+ cfg->afu->cmd[i].slot = i;
962+ }
963+
964+out:
965+ return rc;
966+}
967+
968+/**
969+ * init_pci() - initializes the host as a PCI device
970+ * @cxlflash: Internal structure associated with the host.
971+ *
972+ * Return:
973+ * 0 on success
974+ * -EIO on unable to communicate with device
975+ * A return code from the PCI sub-routines
976+ */
977+static int init_pci(struct cxlflash_cfg *cfg)
978+{
979+ struct pci_dev *pdev = cfg->dev;
980+ int rc = 0;
981+
982+ cfg->cxlflash_regs_pci = pci_resource_start(pdev, 0);
983+ rc = pci_request_regions(pdev, CXLFLASH_NAME);
984+ if (rc < 0) {
985+ dev_err(&pdev->dev,
986+ "%s: Couldn't register memory range of registers\n",
987+ __func__);
988+ goto out;
989+ }
990+
991+ rc = pci_enable_device(pdev);
992+ if (rc || pci_channel_offline(pdev)) {
993+ if (pci_channel_offline(pdev)) {
994+ cxlflash_wait_for_pci_err_recovery(cfg);
995+ rc = pci_enable_device(pdev);
996+ }
997+
998+ if (rc) {
999+ dev_err(&pdev->dev, "%s: Cannot enable adapter\n",
1000+ __func__);
1001+ cxlflash_wait_for_pci_err_recovery(cfg);
1002+ goto out_release_regions;
1003+ }
1004+ }
1005+
1006+ rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
1007+ if (rc < 0) {
1008+ dev_dbg(&pdev->dev, "%s: Failed to set 64 bit PCI DMA mask\n",
1009+ __func__);
1010+ rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
1011+ }
1012+
1013+ if (rc < 0) {
1014+ dev_err(&pdev->dev, "%s: Failed to set PCI DMA mask\n",
1015+ __func__);
1016+ goto out_disable;
1017+ }
1018+
1019+ pci_set_master(pdev);
1020+
1021+ if (pci_channel_offline(pdev)) {
1022+ cxlflash_wait_for_pci_err_recovery(cfg);
1023+ if (pci_channel_offline(pdev)) {
1024+ rc = -EIO;
1025+ goto out_msi_disable;
1026+ }
1027+ }
1028+
1029+ rc = pci_save_state(pdev);
1030+
1031+ if (rc != PCIBIOS_SUCCESSFUL) {
1032+ dev_err(&pdev->dev, "%s: Failed to save PCI config space\n",
1033+ __func__);
1034+ rc = -EIO;
1035+ goto cleanup_nolog;
1036+ }
1037+
1038+out:
1039+ pr_debug("%s: returning rc=%d\n", __func__, rc);
1040+ return rc;
1041+
1042+cleanup_nolog:
1043+out_msi_disable:
1044+ cxlflash_wait_for_pci_err_recovery(cfg);
1045+out_disable:
1046+ pci_disable_device(pdev);
1047+out_release_regions:
1048+ pci_release_regions(pdev);
1049+ goto out;
1050+
1051+}
1052+
1053+/**
1054+ * init_scsi() - adds the host to the SCSI stack and kicks off host scan
1055+ * @cxlflash: Internal structure associated with the host.
1056+ *
1057+ * Return:
1058+ * 0 on success
1059+ * A return code from adding the host
1060+ */
1061+static int init_scsi(struct cxlflash_cfg *cfg)
1062+{
1063+ struct pci_dev *pdev = cfg->dev;
1064+ int rc = 0;
1065+
1066+ rc = scsi_add_host(cfg->host, &pdev->dev);
1067+ if (rc) {
1068+ dev_err(&pdev->dev, "%s: scsi_add_host failed (rc=%d)\n",
1069+ __func__, rc);
1070+ goto out;
1071+ }
1072+
1073+ scsi_scan_host(cfg->host);
1074+
1075+out:
1076+ pr_debug("%s: returning rc=%d\n", __func__, rc);
1077+ return rc;
1078+}
1079+
1080+/**
1081+ * set_port_online() - transitions the specified host FC port to online state
1082+ * @fc_regs: Top of MMIO region defined for specified port.
1083+ *
1084+ * The provided MMIO region must be mapped prior to call. Online state means
1085+ * that the FC link layer has synced, completed the handshaking process, and
1086+ * is ready for login to start.
1087+ */
1088+static void set_port_online(u64 *fc_regs)
1089+{
1090+ u64 cmdcfg;
1091+
1092+ cmdcfg = readq_be(&fc_regs[FC_MTIP_CMDCONFIG / 8]);
1093+ cmdcfg &= (~FC_MTIP_CMDCONFIG_OFFLINE); /* clear OFF_LINE */
1094+ cmdcfg |= (FC_MTIP_CMDCONFIG_ONLINE); /* set ON_LINE */
1095+ writeq_be(cmdcfg, &fc_regs[FC_MTIP_CMDCONFIG / 8]);
1096+}
1097+
1098+/**
1099+ * set_port_offline() - transitions the specified host FC port to offline state
1100+ * @fc_regs: Top of MMIO region defined for specified port.
1101+ *
1102+ * The provided MMIO region must be mapped prior to call.
1103+ */
1104+static void set_port_offline(u64 *fc_regs)
1105+{
1106+ u64 cmdcfg;
1107+
1108+ cmdcfg = readq_be(&fc_regs[FC_MTIP_CMDCONFIG / 8]);
1109+ cmdcfg &= (~FC_MTIP_CMDCONFIG_ONLINE); /* clear ON_LINE */
1110+ cmdcfg |= (FC_MTIP_CMDCONFIG_OFFLINE); /* set OFF_LINE */
1111+ writeq_be(cmdcfg, &fc_regs[FC_MTIP_CMDCONFIG / 8]);
1112+}
1113+
1114+/**
1115+ * wait_port_online() - waits for the specified host FC port come online
1116+ * @fc_regs: Top of MMIO region defined for specified port.
1117+ * @delay_us: Number of microseconds to delay between reading port status.
1118+ * @nretry: Number of cycles to retry reading port status.
1119+ *
1120+ * The provided MMIO region must be mapped prior to call. This will timeout
1121+ * when the cable is not plugged in.
1122+ *
1123+ * Return:
1124+ * TRUE (1) when the specified port is online
1125+ * FALSE (0) when the specified port fails to come online after timeout
1126+ * -EINVAL when @delay_us is less than 1000
1127+ */
1128+static int wait_port_online(u64 *fc_regs, u32 delay_us, u32 nretry)
1129+{
1130+ u64 status;
1131+
1132+ if (delay_us < 1000) {
1133+ pr_err("%s: invalid delay specified %d\n", __func__, delay_us);
1134+ return -EINVAL;
1135+ }
1136+
1137+ do {
1138+ msleep(delay_us / 1000);
1139+ status = readq_be(&fc_regs[FC_MTIP_STATUS / 8]);
1140+ } while ((status & FC_MTIP_STATUS_MASK) != FC_MTIP_STATUS_ONLINE &&
1141+ nretry--);
1142+
1143+ return ((status & FC_MTIP_STATUS_MASK) == FC_MTIP_STATUS_ONLINE);
1144+}
1145+
1146+/**
1147+ * wait_port_offline() - waits for the specified host FC port go offline
1148+ * @fc_regs: Top of MMIO region defined for specified port.
1149+ * @delay_us: Number of microseconds to delay between reading port status.
1150+ * @nretry: Number of cycles to retry reading port status.
1151+ *
1152+ * The provided MMIO region must be mapped prior to call.
1153+ *
1154+ * Return:
1155+ * TRUE (1) when the specified port is offline
1156+ * FALSE (0) when the specified port fails to go offline after timeout
1157+ * -EINVAL when @delay_us is less than 1000
1158+ */
1159+static int wait_port_offline(u64 *fc_regs, u32 delay_us, u32 nretry)
1160+{
1161+ u64 status;
1162+
1163+ if (delay_us < 1000) {
1164+ pr_err("%s: invalid delay specified %d\n", __func__, delay_us);
1165+ return -EINVAL;
1166+ }
1167+
1168+ do {
1169+ msleep(delay_us / 1000);
1170+ status = readq_be(&fc_regs[FC_MTIP_STATUS / 8]);
1171+ } while ((status & FC_MTIP_STATUS_MASK) != FC_MTIP_STATUS_OFFLINE &&
1172+ nretry--);
1173+
1174+ return ((status & FC_MTIP_STATUS_MASK) == FC_MTIP_STATUS_OFFLINE);
1175+}
1176+
1177+/**
1178+ * afu_set_wwpn() - configures the WWPN for the specified host FC port
1179+ * @afu: AFU associated with the host that owns the specified FC port.
1180+ * @port: Port number being configured.
1181+ * @fc_regs: Top of MMIO region defined for specified port.
1182+ * @wwpn: The world-wide-port-number previously discovered for port.
1183+ *
1184+ * The provided MMIO region must be mapped prior to call. As part of the
1185+ * sequence to configure the WWPN, the port is toggled offline and then back
1186+ * online. This toggling action can cause this routine to delay up to a few
1187+ * seconds. When configured to use the internal LUN feature of the AFU, a
1188+ * failure to come online is overridden.
1189+ *
1190+ * Return:
1191+ * 0 when the WWPN is successfully written and the port comes back online
1192+ * -1 when the port fails to go offline or come back up online
1193+ */
1194+static int afu_set_wwpn(struct afu *afu, int port, u64 *fc_regs, u64 wwpn)
1195+{
1196+ int ret = 0;
1197+
1198+ set_port_offline(fc_regs);
1199+
1200+ if (!wait_port_offline(fc_regs, FC_PORT_STATUS_RETRY_INTERVAL_US,
1201+ FC_PORT_STATUS_RETRY_CNT)) {
1202+ pr_debug("%s: wait on port %d to go offline timed out\n",
1203+ __func__, port);
1204+ ret = -1; /* but continue on to leave the port back online */
1205+ }
1206+
1207+ if (ret == 0)
1208+ writeq_be(wwpn, &fc_regs[FC_PNAME / 8]);
1209+
1210+ set_port_online(fc_regs);
1211+
1212+ if (!wait_port_online(fc_regs, FC_PORT_STATUS_RETRY_INTERVAL_US,
1213+ FC_PORT_STATUS_RETRY_CNT)) {
1214+ pr_debug("%s: wait on port %d to go online timed out\n",
1215+ __func__, port);
1216+ ret = -1;
1217+
1218+ /*
1219+ * Override for internal lun!!!
1220+ */
1221+ if (afu->internal_lun) {
1222+ pr_debug("%s: Overriding port %d online timeout!!!\n",
1223+ __func__, port);
1224+ ret = 0;
1225+ }
1226+ }
1227+
1228+ pr_debug("%s: returning rc=%d\n", __func__, ret);
1229+
1230+ return ret;
1231+}
1232+
1233+/**
1234+ * afu_link_reset() - resets the specified host FC port
1235+ * @afu: AFU associated with the host that owns the specified FC port.
1236+ * @port: Port number being configured.
1237+ * @fc_regs: Top of MMIO region defined for specified port.
1238+ *
1239+ * The provided MMIO region must be mapped prior to call. The sequence to
1240+ * reset the port involves toggling it offline and then back online. This
1241+ * action can cause this routine to delay up to a few seconds. An effort
1242+ * is made to maintain link with the device by switching to host to use
1243+ * the alternate port exclusively while the reset takes place.
1244+ * failure to come online is overridden.
1245+ */
1246+static void afu_link_reset(struct afu *afu, int port, u64 *fc_regs)
1247+{
1248+ u64 port_sel;
1249+
1250+ /* first switch the AFU to the other links, if any */
1251+ port_sel = readq_be(&afu->afu_map->global.regs.afu_port_sel);
1252+ port_sel &= ~(1ULL << port);
1253+ writeq_be(port_sel, &afu->afu_map->global.regs.afu_port_sel);
1254+ cxlflash_afu_sync(afu, 0, 0, AFU_GSYNC);
1255+
1256+ set_port_offline(fc_regs);
1257+ if (!wait_port_offline(fc_regs, FC_PORT_STATUS_RETRY_INTERVAL_US,
1258+ FC_PORT_STATUS_RETRY_CNT))
1259+ pr_err("%s: wait on port %d to go offline timed out\n",
1260+ __func__, port);
1261+
1262+ set_port_online(fc_regs);
1263+ if (!wait_port_online(fc_regs, FC_PORT_STATUS_RETRY_INTERVAL_US,
1264+ FC_PORT_STATUS_RETRY_CNT))
1265+ pr_err("%s: wait on port %d to go online timed out\n",
1266+ __func__, port);
1267+
1268+ /* switch back to include this port */
1269+ port_sel |= (1ULL << port);
1270+ writeq_be(port_sel, &afu->afu_map->global.regs.afu_port_sel);
1271+ cxlflash_afu_sync(afu, 0, 0, AFU_GSYNC);
1272+
1273+ pr_debug("%s: returning port_sel=%lld\n", __func__, port_sel);
1274+}
1275+
1276+/*
1277+ * Asynchronous interrupt information table
1278+ */
1279+static const struct asyc_intr_info ainfo[] = {
1280+ {SISL_ASTATUS_FC0_OTHER, "other error", 0, CLR_FC_ERROR | LINK_RESET},
1281+ {SISL_ASTATUS_FC0_LOGO, "target initiated LOGO", 0, 0},
1282+ {SISL_ASTATUS_FC0_CRC_T, "CRC threshold exceeded", 0, LINK_RESET},
1283+ {SISL_ASTATUS_FC0_LOGI_R, "login timed out, retrying", 0, 0},
1284+ {SISL_ASTATUS_FC0_LOGI_F, "login failed", 0, CLR_FC_ERROR},
1285+ {SISL_ASTATUS_FC0_LOGI_S, "login succeeded", 0, 0},
1286+ {SISL_ASTATUS_FC0_LINK_DN, "link down", 0, 0},
1287+ {SISL_ASTATUS_FC0_LINK_UP, "link up", 0, 0},
1288+ {SISL_ASTATUS_FC1_OTHER, "other error", 1, CLR_FC_ERROR | LINK_RESET},
1289+ {SISL_ASTATUS_FC1_LOGO, "target initiated LOGO", 1, 0},
1290+ {SISL_ASTATUS_FC1_CRC_T, "CRC threshold exceeded", 1, LINK_RESET},
1291+ {SISL_ASTATUS_FC1_LOGI_R, "login timed out, retrying", 1, 0},
1292+ {SISL_ASTATUS_FC1_LOGI_F, "login failed", 1, CLR_FC_ERROR},
1293+ {SISL_ASTATUS_FC1_LOGI_S, "login succeeded", 1, 0},
1294+ {SISL_ASTATUS_FC1_LINK_DN, "link down", 1, 0},
1295+ {SISL_ASTATUS_FC1_LINK_UP, "link up", 1, 0},
1296+ {0x0, "", 0, 0} /* terminator */
1297+};
1298+
1299+/**
1300+ * find_ainfo() - locates and returns asynchronous interrupt information
1301+ * @status: Status code set by AFU on error.
1302+ *
1303+ * Return: The located information or NULL when the status code is invalid.
1304+ */
1305+static const struct asyc_intr_info *find_ainfo(u64 status)
1306+{
1307+ const struct asyc_intr_info *info;
1308+
1309+ for (info = &ainfo[0]; info->status; info++)
1310+ if (info->status == status)
1311+ return info;
1312+
1313+ return NULL;
1314+}
1315+
1316+/**
1317+ * afu_err_intr_init() - clears and initializes the AFU for error interrupts
1318+ * @afu: AFU associated with the host.
1319+ */
1320+static void afu_err_intr_init(struct afu *afu)
1321+{
1322+ int i;
1323+ u64 reg;
1324+
1325+ /* global async interrupts: AFU clears afu_ctrl on context exit
1326+ * if async interrupts were sent to that context. This prevents
1327+ * the AFU form sending further async interrupts when
1328+ * there is
1329+ * nobody to receive them.
1330+ */
1331+
1332+ /* mask all */
1333+ writeq_be(-1ULL, &afu->afu_map->global.regs.aintr_mask);
1334+ /* set LISN# to send and point to master context */
1335+ reg = ((u64) (((afu->ctx_hndl << 8) | SISL_MSI_ASYNC_ERROR)) << 40);
1336+
1337+ if (afu->internal_lun)
1338+ reg |= 1; /* Bit 63 indicates local lun */
1339+ writeq_be(reg, &afu->afu_map->global.regs.afu_ctrl);
1340+ /* clear all */
1341+ writeq_be(-1ULL, &afu->afu_map->global.regs.aintr_clear);
1342+ /* unmask bits that are of interest */
1343+ /* note: afu can send an interrupt after this step */
1344+ writeq_be(SISL_ASTATUS_MASK, &afu->afu_map->global.regs.aintr_mask);
1345+ /* clear again in case a bit came on after previous clear but before */
1346+ /* unmask */
1347+ writeq_be(-1ULL, &afu->afu_map->global.regs.aintr_clear);
1348+
1349+ /* Clear/Set internal lun bits */
1350+ reg = readq_be(&afu->afu_map->global.fc_regs[0][FC_CONFIG2 / 8]);
1351+ reg &= SISL_FC_INTERNAL_MASK;
1352+ if (afu->internal_lun)
1353+ reg |= ((u64)(afu->internal_lun - 1) << SISL_FC_INTERNAL_SHIFT);
1354+ writeq_be(reg, &afu->afu_map->global.fc_regs[0][FC_CONFIG2 / 8]);
1355+
1356+ /* now clear FC errors */
1357+ for (i = 0; i < NUM_FC_PORTS; i++) {
1358+ writeq_be(0xFFFFFFFFU,
1359+ &afu->afu_map->global.fc_regs[i][FC_ERROR / 8]);
1360+ writeq_be(0, &afu->afu_map->global.fc_regs[i][FC_ERRCAP / 8]);
1361+ }
1362+
1363+ /* sync interrupts for master's IOARRIN write */
1364+ /* note that unlike asyncs, there can be no pending sync interrupts */
1365+ /* at this time (this is a fresh context and master has not written */
1366+ /* IOARRIN yet), so there is nothing to clear. */
1367+
1368+ /* set LISN#, it is always sent to the context that wrote IOARRIN */
1369+ writeq_be(SISL_MSI_SYNC_ERROR, &afu->host_map->ctx_ctrl);
1370+ writeq_be(SISL_ISTATUS_MASK, &afu->host_map->intr_mask);
1371+}
1372+
1373+/**
1374+ * cxlflash_sync_err_irq() - interrupt handler for synchronous errors
1375+ * @irq: Interrupt number.
1376+ * @data: Private data provided at interrupt registration, the AFU.
1377+ *
1378+ * Return: Always return IRQ_HANDLED.
1379+ */
1380+static irqreturn_t cxlflash_sync_err_irq(int irq, void *data)
1381+{
1382+ struct afu *afu = (struct afu *)data;
1383+ u64 reg;
1384+ u64 reg_unmasked;
1385+
1386+ reg = readq_be(&afu->host_map->intr_status);
1387+ reg_unmasked = (reg & SISL_ISTATUS_UNMASK);
1388+
1389+ if (reg_unmasked == 0UL) {
1390+ pr_err("%s: %llX: spurious interrupt, intr_status %016llX\n",
1391+ __func__, (u64)afu, reg);
1392+ goto cxlflash_sync_err_irq_exit;
1393+ }
1394+
1395+ pr_err("%s: %llX: unexpected interrupt, intr_status %016llX\n",
1396+ __func__, (u64)afu, reg);
1397+
1398+ writeq_be(reg_unmasked, &afu->host_map->intr_clear);
1399+
1400+cxlflash_sync_err_irq_exit:
1401+ pr_debug("%s: returning rc=%d\n", __func__, IRQ_HANDLED);
1402+ return IRQ_HANDLED;
1403+}
1404+
1405+/**
1406+ * cxlflash_rrq_irq() - interrupt handler for read-response queue (normal path)
1407+ * @irq: Interrupt number.
1408+ * @data: Private data provided at interrupt registration, the AFU.
1409+ *
1410+ * Return: Always return IRQ_HANDLED.
1411+ */
1412+static irqreturn_t cxlflash_rrq_irq(int irq, void *data)
1413+{
1414+ struct afu *afu = (struct afu *)data;
1415+ struct afu_cmd *cmd;
1416+ bool toggle = afu->toggle;
1417+ u64 entry,
1418+ *hrrq_start = afu->hrrq_start,
1419+ *hrrq_end = afu->hrrq_end,
1420+ *hrrq_curr = afu->hrrq_curr;
1421+
1422+ /* Process however many RRQ entries that are ready */
1423+ while (true) {
1424+ entry = *hrrq_curr;
1425+
1426+ if ((entry & SISL_RESP_HANDLE_T_BIT) != toggle)
1427+ break;
1428+
1429+ cmd = (struct afu_cmd *)(entry & ~SISL_RESP_HANDLE_T_BIT);
1430+ cmd_complete(cmd);
1431+
1432+ /* Advance to next entry or wrap and flip the toggle bit */
1433+ if (hrrq_curr < hrrq_end)
1434+ hrrq_curr++;
1435+ else {
1436+ hrrq_curr = hrrq_start;
1437+ toggle ^= SISL_RESP_HANDLE_T_BIT;
1438+ }
1439+ }
1440+
1441+ afu->hrrq_curr = hrrq_curr;
1442+ afu->toggle = toggle;
1443+
1444+ return IRQ_HANDLED;
1445+}
1446+
1447+/**
1448+ * cxlflash_async_err_irq() - interrupt handler for asynchronous errors
1449+ * @irq: Interrupt number.
1450+ * @data: Private data provided at interrupt registration, the AFU.
1451+ *
1452+ * Return: Always return IRQ_HANDLED.
1453+ */
1454+static irqreturn_t cxlflash_async_err_irq(int irq, void *data)
1455+{
1456+ struct afu *afu = (struct afu *)data;
1457+ struct cxlflash_cfg *cfg;
1458+ u64 reg_unmasked;
1459+ const struct asyc_intr_info *info;
1460+ struct sisl_global_map *global = &afu->afu_map->global;
1461+ u64 reg;
1462+ u8 port;
1463+ int i;
1464+
1465+ cfg = afu->parent;
1466+
1467+ reg = readq_be(&global->regs.aintr_status);
1468+ reg_unmasked = (reg & SISL_ASTATUS_UNMASK);
1469+
1470+ if (reg_unmasked == 0) {
1471+ pr_err("%s: spurious interrupt, aintr_status 0x%016llX\n",
1472+ __func__, reg);
1473+ goto out;
1474+ }
1475+
1476+ /* it is OK to clear AFU status before FC_ERROR */
1477+ writeq_be(reg_unmasked, &global->regs.aintr_clear);
1478+
1479+ /* check each bit that is on */
1480+ for (i = 0; reg_unmasked; i++, reg_unmasked = (reg_unmasked >> 1)) {
1481+ info = find_ainfo(1ULL << i);
1482+ if ((reg_unmasked & 0x1) || !info)
1483+ continue;
1484+
1485+ port = info->port;
1486+
1487+ pr_err("%s: FC Port %d -> %s, fc_status 0x%08llX\n",
1488+ __func__, port, info->desc,
1489+ readq_be(&global->fc_regs[port][FC_STATUS / 8]));
1490+
1491+ /*
1492+ * do link reset first, some OTHER errors will set FC_ERROR
1493+ * again if cleared before or w/o a reset
1494+ */
1495+ if (info->action & LINK_RESET) {
1496+ pr_err("%s: FC Port %d: resetting link\n",
1497+ __func__, port);
1498+ cfg->lr_state = LINK_RESET_REQUIRED;
1499+ cfg->lr_port = port;
1500+ schedule_work(&cfg->work_q);
1501+ }
1502+
1503+ if (info->action & CLR_FC_ERROR) {
1504+ reg = readq_be(&global->fc_regs[port][FC_ERROR / 8]);
1505+
1506+ /*
1507+ * since all errors are unmasked, FC_ERROR and FC_ERRCAP
1508+ * should be the same and tracing one is sufficient.
1509+ */
1510+
1511+ pr_err("%s: fc %d: clearing fc_error 0x%08llX\n",
1512+ __func__, port, reg);
1513+
1514+ writeq_be(reg, &global->fc_regs[port][FC_ERROR / 8]);
1515+ writeq_be(0, &global->fc_regs[port][FC_ERRCAP / 8]);
1516+ }
1517+ }
1518+
1519+out:
1520+ pr_debug("%s: returning rc=%d, afu=%p\n", __func__, IRQ_HANDLED, afu);
1521+ return IRQ_HANDLED;
1522+}
1523+
1524+/**
1525+ * start_context() - starts the master context
1526+ * @cxlflash: Internal structure associated with the host.
1527+ *
1528+ * Return: A success or failure value from CXL services.
1529+ */
1530+static int start_context(struct cxlflash_cfg *cfg)
1531+{
1532+ int rc = 0;
1533+
1534+ rc = cxl_start_context(cfg->mcctx,
1535+ cfg->afu->work.work_element_descriptor,
1536+ NULL);
1537+
1538+ pr_debug("%s: returning rc=%d\n", __func__, rc);
1539+ return rc;
1540+}
1541+
1542+/**
1543+ * read_vpd() - obtains the WWPNs from VPD
1544+ * @cxlflash: Internal structure associated with the host.
1545+ * @wwpn: Array of size NUM_FC_PORTS to pass back WWPNs
1546+ *
1547+ * Return:
1548+ * 0 on success
1549+ * -ENODEV when VPD or WWPN keywords not found
1550+ */
1551+static int read_vpd(struct cxlflash_cfg *cfg, u64 wwpn[])
1552+{
1553+ struct pci_dev *dev = cfg->parent_dev;
1554+ int rc = 0;
1555+ int ro_start, ro_size, i, j, k;
1556+ ssize_t vpd_size;
1557+ char vpd_data[CXLFLASH_VPD_LEN];
1558+ char tmp_buf[WWPN_BUF_LEN] = { 0 };
1559+ char *wwpn_vpd_tags[NUM_FC_PORTS] = { "V5", "V6" };
1560+
1561+ /* Get the VPD data from the device */
1562+ vpd_size = pci_read_vpd(dev, 0, sizeof(vpd_data), vpd_data);
1563+ if (unlikely(vpd_size <= 0)) {
1564+ pr_err("%s: Unable to read VPD (size = %ld)\n",
1565+ __func__, vpd_size);
1566+ rc = -ENODEV;
1567+ goto out;
1568+ }
1569+
1570+ /* Get the read only section offset */
1571+ ro_start = pci_vpd_find_tag(vpd_data, 0, vpd_size,
1572+ PCI_VPD_LRDT_RO_DATA);
1573+ if (unlikely(ro_start < 0)) {
1574+ pr_err("%s: VPD Read-only data not found\n", __func__);
1575+ rc = -ENODEV;
1576+ goto out;
1577+ }
1578+
1579+ /* Get the read only section size, cap when extends beyond read VPD */
1580+ ro_size = pci_vpd_lrdt_size(&vpd_data[ro_start]);
1581+ j = ro_size;
1582+ i = ro_start + PCI_VPD_LRDT_TAG_SIZE;
1583+ if (unlikely((i + j) > vpd_size)) {
1584+ pr_debug("%s: Might need to read more VPD (%d > %ld)\n",
1585+ __func__, (i + j), vpd_size);
1586+ ro_size = vpd_size - i;
1587+ }
1588+
1589+ /*
1590+ * Find the offset of the WWPN tag within the read only
1591+ * VPD data and validate the found field (partials are
1592+ * no good to us). Convert the ASCII data to an integer
1593+ * value. Note that we must copy to a temporary buffer
1594+ * because the conversion service requires that the ASCII
1595+ * string be terminated.
1596+ */
1597+ for (k = 0; k < NUM_FC_PORTS; k++) {
1598+ j = ro_size;
1599+ i = ro_start + PCI_VPD_LRDT_TAG_SIZE;
1600+
1601+ i = pci_vpd_find_info_keyword(vpd_data, i, j, wwpn_vpd_tags[k]);
1602+ if (unlikely(i < 0)) {
1603+ pr_err("%s: Port %d WWPN not found in VPD\n",
1604+ __func__, k);
1605+ rc = -ENODEV;
1606+ goto out;
1607+ }
1608+
1609+ j = pci_vpd_info_field_size(&vpd_data[i]);
1610+ i += PCI_VPD_INFO_FLD_HDR_SIZE;
1611+ if (unlikely((i + j > vpd_size) || (j != WWPN_LEN))) {
1612+ pr_err("%s: Port %d WWPN incomplete or VPD corrupt\n",
1613+ __func__, k);
1614+ rc = -ENODEV;
1615+ goto out;
1616+ }
1617+
1618+ memcpy(tmp_buf, &vpd_data[i], WWPN_LEN);
1619+ rc = kstrtoul(tmp_buf, WWPN_LEN, (ulong *)&wwpn[k]);
1620+ if (unlikely(rc)) {
1621+ pr_err("%s: Fail to convert port %d WWPN to integer\n",
1622+ __func__, k);
1623+ rc = -ENODEV;
1624+ goto out;
1625+ }
1626+ }
1627+
1628+out:
1629+ pr_debug("%s: returning rc=%d\n", __func__, rc);
1630+ return rc;
1631+}
1632+
1633+/**
1634+ * cxlflash_context_reset() - timeout handler for AFU commands
1635+ * @cmd: AFU command that timed out.
1636+ *
1637+ * Sends a reset to the AFU.
1638+ */
1639+void cxlflash_context_reset(struct afu_cmd *cmd)
1640+{
1641+ int nretry = 0;
1642+ u64 rrin = 0x1;
1643+ u64 room = 0;
1644+ struct afu *afu = cmd->parent;
1645+ ulong lock_flags;
1646+
1647+ pr_debug("%s: cmd=%p\n", __func__, cmd);
1648+
1649+ spin_lock_irqsave(&cmd->slock, lock_flags);
1650+
1651+ /* Already completed? */
1652+ if (cmd->sa.host_use_b[0] & B_DONE) {
1653+ spin_unlock_irqrestore(&cmd->slock, lock_flags);
1654+ return;
1655+ }
1656+
1657+ cmd->sa.host_use_b[0] |= (B_DONE | B_ERROR | B_TIMEOUT);
1658+ spin_unlock_irqrestore(&cmd->slock, lock_flags);
1659+
1660+ /*
1661+ * We really want to send this reset at all costs, so spread
1662+ * out wait time on successive retries for available room.
1663+ */
1664+ do {
1665+ room = readq_be(&afu->host_map->cmd_room);
1666+ atomic64_set(&afu->room, room);
1667+ if (room)
1668+ goto write_rrin;
1669+ udelay(nretry);
1670+ } while (nretry++ < MC_ROOM_RETRY_CNT);
1671+
1672+ pr_err("%s: no cmd_room to send reset\n", __func__);
1673+ return;
1674+
1675+write_rrin:
1676+ nretry = 0;
1677+ writeq_be(rrin, &afu->host_map->ioarrin);
1678+ do {
1679+ rrin = readq_be(&afu->host_map->ioarrin);
1680+ if (rrin != 0x1)
1681+ break;
1682+ /* Double delay each time */
1683+ udelay(2 ^ nretry);
1684+ } while (nretry++ < MC_ROOM_RETRY_CNT);
1685+}
1686+
1687+/**
1688+ * init_pcr() - initialize the provisioning and control registers
1689+ * @cxlflash: Internal structure associated with the host.
1690+ *
1691+ * Also sets up fast access to the mapped registers and initializes AFU
1692+ * command fields that never change.
1693+ */
1694+void init_pcr(struct cxlflash_cfg *cfg)
1695+{
1696+ struct afu *afu = cfg->afu;
1697+ struct sisl_ctrl_map *ctrl_map;
1698+ int i;
1699+
1700+ for (i = 0; i < MAX_CONTEXT; i++) {
1701+ ctrl_map = &afu->afu_map->ctrls[i].ctrl;
1702+ /* disrupt any clients that could be running */
1703+ /* e. g. clients that survived a master restart */
1704+ writeq_be(0, &ctrl_map->rht_start);
1705+ writeq_be(0, &ctrl_map->rht_cnt_id);
1706+ writeq_be(0, &ctrl_map->ctx_cap);
1707+ }
1708+
1709+ /* copy frequently used fields into afu */
1710+ afu->ctx_hndl = (u16) cxl_process_element(cfg->mcctx);
1711+ /* ctx_hndl is 16 bits in CAIA */
1712+ afu->host_map = &afu->afu_map->hosts[afu->ctx_hndl].host;
1713+ afu->ctrl_map = &afu->afu_map->ctrls[afu->ctx_hndl].ctrl;
1714+
1715+ /* Program the Endian Control for the master context */
1716+ writeq_be(SISL_ENDIAN_CTRL, &afu->host_map->endian_ctrl);
1717+
1718+ /* initialize cmd fields that never change */
1719+ for (i = 0; i < CXLFLASH_NUM_CMDS; i++) {
1720+ afu->cmd[i].rcb.ctx_id = afu->ctx_hndl;
1721+ afu->cmd[i].rcb.msi = SISL_MSI_RRQ_UPDATED;
1722+ afu->cmd[i].rcb.rrq = 0x0;
1723+ }
1724+}
1725+
1726+/**
1727+ * init_global() - initialize AFU global registers
1728+ * @cxlflash: Internal structure associated with the host.
1729+ */
1730+int init_global(struct cxlflash_cfg *cfg)
1731+{
1732+ struct afu *afu = cfg->afu;
1733+ u64 wwpn[NUM_FC_PORTS]; /* wwpn of AFU ports */
1734+ int i = 0, num_ports = 0;
1735+ int rc = 0;
1736+ u64 reg;
1737+
1738+ rc = read_vpd(cfg, &wwpn[0]);
1739+ if (rc) {
1740+ pr_err("%s: could not read vpd rc=%d\n", __func__, rc);
1741+ goto out;
1742+ }
1743+
1744+ pr_debug("%s: wwpn0=0x%llX wwpn1=0x%llX\n", __func__, wwpn[0], wwpn[1]);
1745+
1746+ /* set up RRQ in AFU for master issued cmds */
1747+ writeq_be((u64) afu->hrrq_start, &afu->host_map->rrq_start);
1748+ writeq_be((u64) afu->hrrq_end, &afu->host_map->rrq_end);
1749+
1750+ /* AFU configuration */
1751+ reg = readq_be(&afu->afu_map->global.regs.afu_config);
1752+ reg |= SISL_AFUCONF_AR_ALL|SISL_AFUCONF_ENDIAN;
1753+ /* enable all auto retry options and control endianness */
1754+ /* leave others at default: */
1755+ /* CTX_CAP write protected, mbox_r does not clear on read and */
1756+ /* checker on if dual afu */
1757+ writeq_be(reg, &afu->afu_map->global.regs.afu_config);
1758+
1759+ /* global port select: select either port */
1760+ if (afu->internal_lun) {
1761+ /* only use port 0 */
1762+ writeq_be(PORT0, &afu->afu_map->global.regs.afu_port_sel);
1763+ num_ports = NUM_FC_PORTS - 1;
1764+ } else {
1765+ writeq_be(BOTH_PORTS, &afu->afu_map->global.regs.afu_port_sel);
1766+ num_ports = NUM_FC_PORTS;
1767+ }
1768+
1769+ for (i = 0; i < num_ports; i++) {
1770+ /* unmask all errors (but they are still masked at AFU) */
1771+ writeq_be(0, &afu->afu_map->global.fc_regs[i][FC_ERRMSK / 8]);
1772+ /* clear CRC error cnt & set a threshold */
1773+ (void)readq_be(&afu->afu_map->global.
1774+ fc_regs[i][FC_CNT_CRCERR / 8]);
1775+ writeq_be(MC_CRC_THRESH, &afu->afu_map->global.fc_regs[i]
1776+ [FC_CRC_THRESH / 8]);
1777+
1778+ /* set WWPNs. If already programmed, wwpn[i] is 0 */
1779+ if (wwpn[i] != 0 &&
1780+ afu_set_wwpn(afu, i,
1781+ &afu->afu_map->global.fc_regs[i][0],
1782+ wwpn[i])) {
1783+ pr_err("%s: failed to set WWPN on port %d\n",
1784+ __func__, i);
1785+ rc = -EIO;
1786+ goto out;
1787+ }
1788+ /* Programming WWPN back to back causes additional
1789+ * offline/online transitions and a PLOGI
1790+ */
1791+ msleep(100);
1792+
1793+ }
1794+
1795+ /* set up master's own CTX_CAP to allow real mode, host translation */
1796+ /* tbls, afu cmds and read/write GSCSI cmds. */
1797+ /* First, unlock ctx_cap write by reading mbox */
1798+ (void)readq_be(&afu->ctrl_map->mbox_r); /* unlock ctx_cap */
1799+ writeq_be((SISL_CTX_CAP_REAL_MODE | SISL_CTX_CAP_HOST_XLATE |
1800+ SISL_CTX_CAP_READ_CMD | SISL_CTX_CAP_WRITE_CMD |
1801+ SISL_CTX_CAP_AFU_CMD | SISL_CTX_CAP_GSCSI_CMD),
1802+ &afu->ctrl_map->ctx_cap);
1803+ /* init heartbeat */
1804+ afu->hb = readq_be(&afu->afu_map->global.regs.afu_hb);
1805+
1806+out:
1807+ return rc;
1808+}
1809+
1810+/**
1811+ * start_afu() - initializes and starts the AFU
1812+ * @cxlflash: Internal structure associated with the host.
1813+ */
1814+static int start_afu(struct cxlflash_cfg *cfg)
1815+{
1816+ struct afu *afu = cfg->afu;
1817+ struct afu_cmd *cmd;
1818+
1819+ int i = 0;
1820+ int rc = 0;
1821+
1822+ for (i = 0; i < CXLFLASH_NUM_CMDS; i++) {
1823+ cmd = &afu->cmd[i];
1824+
1825+ init_completion(&cmd->cevent);
1826+ spin_lock_init(&cmd->slock);
1827+ cmd->parent = afu;
1828+ }
1829+
1830+ init_pcr(cfg);
1831+
1832+ /* initialize RRQ pointers */
1833+ afu->hrrq_start = &afu->rrq_entry[0];
1834+ afu->hrrq_end = &afu->rrq_entry[NUM_RRQ_ENTRY - 1];
1835+ afu->hrrq_curr = afu->hrrq_start;
1836+ afu->toggle = 1;
1837+
1838+ rc = init_global(cfg);
1839+
1840+ pr_debug("%s: returning rc=%d\n", __func__, rc);
1841+ return rc;
1842+}
1843+
1844+/**
1845+ * init_mc() - create and register as the master context
1846+ * @cxlflash: Internal structure associated with the host.
1847+ *
1848+ * Return:
1849+ * 0 on success
1850+ * -ENOMEM when unable to obtain a context from CXL services
1851+ * A failure value from CXL services.
1852+ */
1853+static int init_mc(struct cxlflash_cfg *cfg)
1854+{
1855+ struct cxl_context *ctx;
1856+ struct device *dev = &cfg->dev->dev;
1857+ struct afu *afu = cfg->afu;
1858+ int rc = 0;
1859+ enum undo_level level;
1860+
1861+ ctx = cxl_get_context(cfg->dev);
1862+ if (unlikely(!ctx))
1863+ return -ENOMEM;
1864+ cfg->mcctx = ctx;
1865+
1866+ /* Set it up as a master with the CXL */
1867+ cxl_set_master(ctx);
1868+
1869+ /* During initialization reset the AFU to start from a clean slate */
1870+ rc = cxl_afu_reset(cfg->mcctx);
1871+ if (unlikely(rc)) {
1872+ dev_err(dev, "%s: initial AFU reset failed rc=%d\n",
1873+ __func__, rc);
1874+ level = RELEASE_CONTEXT;
1875+ goto out;
1876+ }
1877+
1878+ rc = cxl_allocate_afu_irqs(ctx, 3);
1879+ if (unlikely(rc)) {
1880+ dev_err(dev, "%s: call to allocate_afu_irqs failed rc=%d!\n",
1881+ __func__, rc);
1882+ level = RELEASE_CONTEXT;
1883+ goto out;
1884+ }
1885+
1886+ rc = cxl_map_afu_irq(ctx, 1, cxlflash_sync_err_irq, afu,
1887+ "SISL_MSI_SYNC_ERROR");
1888+ if (unlikely(rc <= 0)) {
1889+ dev_err(dev, "%s: IRQ 1 (SISL_MSI_SYNC_ERROR) map failed!\n",
1890+ __func__);
1891+ level = FREE_IRQ;
1892+ goto out;
1893+ }
1894+
1895+ rc = cxl_map_afu_irq(ctx, 2, cxlflash_rrq_irq, afu,
1896+ "SISL_MSI_RRQ_UPDATED");
1897+ if (unlikely(rc <= 0)) {
1898+ dev_err(dev, "%s: IRQ 2 (SISL_MSI_RRQ_UPDATED) map failed!\n",
1899+ __func__);
1900+ level = UNMAP_ONE;
1901+ goto out;
1902+ }
1903+
1904+ rc = cxl_map_afu_irq(ctx, 3, cxlflash_async_err_irq, afu,
1905+ "SISL_MSI_ASYNC_ERROR");
1906+ if (unlikely(rc <= 0)) {
1907+ dev_err(dev, "%s: IRQ 3 (SISL_MSI_ASYNC_ERROR) map failed!\n",
1908+ __func__);
1909+ level = UNMAP_TWO;
1910+ goto out;
1911+ }
1912+
1913+ rc = 0;
1914+
1915+ /* This performs the equivalent of the CXL_IOCTL_START_WORK.
1916+ * The CXL_IOCTL_GET_PROCESS_ELEMENT is implicit in the process
1917+ * element (pe) that is embedded in the context (ctx)
1918+ */
1919+ rc = start_context(cfg);
1920+ if (unlikely(rc)) {
1921+ dev_err(dev, "%s: start context failed rc=%d\n", __func__, rc);
1922+ level = UNMAP_THREE;
1923+ goto out;
1924+ }
1925+ret:
1926+ pr_debug("%s: returning rc=%d\n", __func__, rc);
1927+ return rc;
1928+out:
1929+ term_mc(cfg, level);
1930+ goto ret;
1931+}
1932+
1933+/**
1934+ * init_afu() - setup as master context and start AFU
1935+ * @cxlflash: Internal structure associated with the host.
1936+ *
1937+ * This routine is a higher level of control for configuring the
1938+ * AFU on probe and reset paths.
1939+ *
1940+ * Return:
1941+ * 0 on success
1942+ * -ENOMEM when unable to map the AFU MMIO space
1943+ * A failure value from internal services.
1944+ */
1945+static int init_afu(struct cxlflash_cfg *cfg)
1946+{
1947+ u64 reg;
1948+ int rc = 0;
1949+ struct afu *afu = cfg->afu;
1950+ struct device *dev = &cfg->dev->dev;
1951+
1952+ cxl_perst_reloads_same_image(cfg->cxl_afu, true);
1953+
1954+ rc = init_mc(cfg);
1955+ if (rc) {
1956+ dev_err(dev, "%s: call to init_mc failed, rc=%d!\n",
1957+ __func__, rc);
1958+ goto err1;
1959+ }
1960+
1961+ /* Map the entire MMIO space of the AFU.
1962+ */
1963+ afu->afu_map = cxl_psa_map(cfg->mcctx);
1964+ if (!afu->afu_map) {
1965+ rc = -ENOMEM;
1966+ term_mc(cfg, UNDO_START);
1967+ dev_err(dev, "%s: call to cxl_psa_map failed!\n", __func__);
1968+ goto err1;
1969+ }
1970+
1971+ /* don't byte reverse on reading afu_version, else the string form */
1972+ /* will be backwards */
1973+ reg = afu->afu_map->global.regs.afu_version;
1974+ memcpy(afu->version, &reg, 8);
1975+ afu->interface_version =
1976+ readq_be(&afu->afu_map->global.regs.interface_version);
1977+ pr_debug("%s: afu version %s, interface version 0x%llX\n",
1978+ __func__, afu->version, afu->interface_version);
1979+
1980+ rc = start_afu(cfg);
1981+ if (rc) {
1982+ dev_err(dev, "%s: call to start_afu failed, rc=%d!\n",
1983+ __func__, rc);
1984+ term_mc(cfg, UNDO_START);
1985+ cxl_psa_unmap((void *)afu->afu_map);
1986+ afu->afu_map = NULL;
1987+ goto err1;
1988+ }
1989+
1990+ afu_err_intr_init(cfg->afu);
1991+ atomic64_set(&afu->room, readq_be(&afu->host_map->cmd_room));
1992+
1993+ /* Restore the LUN mappings */
1994+ cxlflash_restore_luntable(cfg);
1995+err1:
1996+ pr_debug("%s: returning rc=%d\n", __func__, rc);
1997+ return rc;
1998+}
1999+
2000+/**
2001+ * cxlflash_send_cmd() - sends an AFU command
2002+ * @afu: AFU associated with the host.
2003+ * @cmd: AFU command to send.
2004+ *
2005+ * Return:
2006+ * 0 on success
2007+ * -1 on failure
2008+ */
2009+int cxlflash_send_cmd(struct afu *afu, struct afu_cmd *cmd)
2010+{
2011+ struct cxlflash_cfg *cfg = afu->parent;
2012+ int nretry = 0;
2013+ int rc = 0;
2014+ u64 room;
2015+ long newval;
2016+
2017+ /*
2018+ * This routine is used by critical users such an AFU sync and to
2019+ * send a task management function (TMF). Thus we want to retry a
2020+ * bit before returning an error. To avoid the performance penalty
2021+ * of MMIO, we spread the update of 'room' over multiple commands.
2022+ */
2023+retry:
2024+ newval = atomic64_dec_if_positive(&afu->room);
2025+ if (!newval) {
2026+ do {
2027+ room = readq_be(&afu->host_map->cmd_room);
2028+ atomic64_set(&afu->room, room);
2029+ if (room)
2030+ goto write_ioarrin;
2031+ udelay(nretry);
2032+ } while (nretry++ < MC_ROOM_RETRY_CNT);
2033+
2034+ pr_err("%s: no cmd_room to send 0x%X\n",
2035+ __func__, cmd->rcb.cdb[0]);
2036+
2037+ goto no_room;
2038+ } else if (unlikely(newval < 0)) {
2039+ /* This should be rare. i.e. Only if two threads race and
2040+ * decrement before the MMIO read is done. In this case
2041+ * just benefit from the other thread having updated
2042+ * afu->room.
2043+ */
2044+ if (nretry++ < MC_ROOM_RETRY_CNT) {
2045+ udelay(nretry);
2046+ goto retry;
2047+ }
2048+
2049+ goto no_room;
2050+ }
2051+
2052+write_ioarrin:
2053+ writeq_be((u64)&cmd->rcb, &afu->host_map->ioarrin);
2054+out:
2055+ pr_debug("%s: cmd=%p len=%d ea=%p rc=%d\n", __func__, cmd,
2056+ cmd->rcb.data_len, (void *)cmd->rcb.data_ea, rc);
2057+ return rc;
2058+
2059+no_room:
2060+ afu->read_room = true;
2061+ schedule_work(&cfg->work_q);
2062+ rc = SCSI_MLQUEUE_HOST_BUSY;
2063+ goto out;
2064+}
2065+
2066+/**
2067+ * cxlflash_wait_resp() - polls for a response or timeout to a sent AFU command
2068+ * @afu: AFU associated with the host.
2069+ * @cmd: AFU command that was sent.
2070+ */
2071+void cxlflash_wait_resp(struct afu *afu, struct afu_cmd *cmd)
2072+{
2073+ ulong timeout = jiffies + (cmd->rcb.timeout * 2 * HZ);
2074+
2075+ timeout = wait_for_completion_timeout(&cmd->cevent, timeout);
2076+ if (!timeout)
2077+ cxlflash_context_reset(cmd);
2078+
2079+ if (unlikely(cmd->sa.ioasc != 0))
2080+ pr_err("%s: CMD 0x%X failed, IOASC: flags 0x%X, afu_rc 0x%X, "
2081+ "scsi_rc 0x%X, fc_rc 0x%X\n", __func__, cmd->rcb.cdb[0],
2082+ cmd->sa.rc.flags, cmd->sa.rc.afu_rc, cmd->sa.rc.scsi_rc,
2083+ cmd->sa.rc.fc_rc);
2084+}
2085+
2086+/**
2087+ * cxlflash_afu_sync() - builds and sends an AFU sync command
2088+ * @afu: AFU associated with the host.
2089+ * @ctx_hndl_u: Identifies context requesting sync.
2090+ * @res_hndl_u: Identifies resource requesting sync.
2091+ * @mode: Type of sync to issue (lightweight, heavyweight, global).
2092+ *
2093+ * The AFU can only take 1 sync command at a time. This routine enforces this
2094+ * limitation by using a mutex to provide exlusive access to the AFU during
2095+ * the sync. This design point requires calling threads to not be on interrupt
2096+ * context due to the possibility of sleeping during concurrent sync operations.
2097+ *
2098+ * AFU sync operations are only necessary and allowed when the device is
2099+ * operating normally. When not operating normally, sync requests can occur as
2100+ * part of cleaning up resources associated with an adapter prior to removal.
2101+ * In this scenario, these requests are simply ignored (safe due to the AFU
2102+ * going away).
2103+ *
2104+ * Return:
2105+ * 0 on success
2106+ * -1 on failure
2107+ */
2108+int cxlflash_afu_sync(struct afu *afu, ctx_hndl_t ctx_hndl_u,
2109+ res_hndl_t res_hndl_u, u8 mode)
2110+{
2111+ struct cxlflash_cfg *cfg = afu->parent;
2112+ struct afu_cmd *cmd = NULL;
2113+ int rc = 0;
2114+ int retry_cnt = 0;
2115+ static DEFINE_MUTEX(sync_active);
2116+
2117+ if (cfg->state != STATE_NORMAL) {
2118+ pr_debug("%s: Sync not required! (%u)\n", __func__, cfg->state);
2119+ return 0;
2120+ }
2121+
2122+ mutex_lock(&sync_active);
2123+retry:
2124+ cmd = cxlflash_cmd_checkout(afu);
2125+ if (unlikely(!cmd)) {
2126+ retry_cnt++;
2127+ udelay(1000 * retry_cnt);
2128+ if (retry_cnt < MC_RETRY_CNT)
2129+ goto retry;
2130+ pr_err("%s: could not get a free command\n", __func__);
2131+ rc = -1;
2132+ goto out;
2133+ }
2134+
2135+ pr_debug("%s: afu=%p cmd=%p %d\n", __func__, afu, cmd, ctx_hndl_u);
2136+
2137+ memset(cmd->rcb.cdb, 0, sizeof(cmd->rcb.cdb));
2138+
2139+ cmd->rcb.req_flags = SISL_REQ_FLAGS_AFU_CMD;
2140+ cmd->rcb.port_sel = 0x0; /* NA */
2141+ cmd->rcb.lun_id = 0x0; /* NA */
2142+ cmd->rcb.data_len = 0x0;
2143+ cmd->rcb.data_ea = 0x0;
2144+ cmd->rcb.timeout = MC_AFU_SYNC_TIMEOUT;
2145+
2146+ cmd->rcb.cdb[0] = 0xC0; /* AFU Sync */
2147+ cmd->rcb.cdb[1] = mode;
2148+
2149+ /* The cdb is aligned, no unaligned accessors required */
2150+ *((u16 *)&cmd->rcb.cdb[2]) = swab16(ctx_hndl_u);
2151+ *((u32 *)&cmd->rcb.cdb[4]) = swab32(res_hndl_u);
2152+
2153+ rc = cxlflash_send_cmd(afu, cmd);
2154+ if (unlikely(rc))
2155+ goto out;
2156+
2157+ cxlflash_wait_resp(afu, cmd);
2158+
2159+ /* set on timeout */
2160+ if (unlikely((cmd->sa.ioasc != 0) ||
2161+ (cmd->sa.host_use_b[0] & B_ERROR)))
2162+ rc = -1;
2163+out:
2164+ mutex_unlock(&sync_active);
2165+ if (cmd)
2166+ cxlflash_cmd_checkin(cmd);
2167+ pr_debug("%s: returning rc=%d\n", __func__, rc);
2168+ return rc;
2169+}
2170+
2171+/**
2172+ * cxlflash_afu_reset() - resets the AFU
2173+ * @cxlflash: Internal structure associated with the host.
2174+ *
2175+ * Return:
2176+ * 0 on success
2177+ * A failure value from internal services.
2178+ */
2179+int cxlflash_afu_reset(struct cxlflash_cfg *cfg)
2180+{
2181+ int rc = 0;
2182+ /* Stop the context before the reset. Since the context is
2183+ * no longer available restart it after the reset is complete
2184+ */
2185+
2186+ term_afu(cfg);
2187+
2188+ rc = init_afu(cfg);
2189+
2190+ pr_debug("%s: returning rc=%d\n", __func__, rc);
2191+ return rc;
2192+}
2193+
2194+/**
2195+ * cxlflash_worker_thread() - work thread handler for the AFU
2196+ * @work: Work structure contained within cxlflash associated with host.
2197+ *
2198+ * Handles the following events:
2199+ * - Link reset which cannot be performed on interrupt context due to
2200+ * blocking up to a few seconds
2201+ * - Read AFU command room
2202+ */
2203+static void cxlflash_worker_thread(struct work_struct *work)
2204+{
2205+ struct cxlflash_cfg *cfg = container_of(work, struct cxlflash_cfg,
2206+ work_q);
2207+ struct afu *afu = cfg->afu;
2208+ int port;
2209+ ulong lock_flags;
2210+
2211+ /* Avoid MMIO if the device has failed */
2212+
2213+ if (cfg->state != STATE_NORMAL)
2214+ return;
2215+
2216+ spin_lock_irqsave(cfg->host->host_lock, lock_flags);
2217+
2218+ if (cfg->lr_state == LINK_RESET_REQUIRED) {
2219+ port = cfg->lr_port;
2220+ if (port < 0)
2221+ pr_err("%s: invalid port index %d\n", __func__, port);
2222+ else {
2223+ spin_unlock_irqrestore(cfg->host->host_lock,
2224+ lock_flags);
2225+
2226+ /* The reset can block... */
2227+ afu_link_reset(afu, port,
2228+ &afu->afu_map->
2229+ global.fc_regs[port][0]);
2230+ spin_lock_irqsave(cfg->host->host_lock, lock_flags);
2231+ }
2232+
2233+ cfg->lr_state = LINK_RESET_COMPLETE;
2234+ }
2235+
2236+ if (afu->read_room) {
2237+ atomic64_set(&afu->room, readq_be(&afu->host_map->cmd_room));
2238+ afu->read_room = false;
2239+ }
2240+
2241+ spin_unlock_irqrestore(cfg->host->host_lock, lock_flags);
2242+}
2243+
2244+/**
2245+ * cxlflash_probe() - PCI entry point to add host
2246+ * @pdev: PCI device associated with the host.
2247+ * @dev_id: PCI device id associated with device.
2248+ *
2249+ * Return: 0 on success / non-zero on failure
2250+ */
2251+static int cxlflash_probe(struct pci_dev *pdev,
2252+ const struct pci_device_id *dev_id)
2253+{
2254+ struct Scsi_Host *host;
2255+ struct cxlflash_cfg *cfg = NULL;
2256+ struct device *phys_dev;
2257+ struct dev_dependent_vals *ddv;
2258+ int rc = 0;
2259+
2260+ dev_dbg(&pdev->dev, "%s: Found CXLFLASH with IRQ: %d\n",
2261+ __func__, pdev->irq);
2262+
2263+ ddv = (struct dev_dependent_vals *)dev_id->driver_data;
2264+ driver_template.max_sectors = ddv->max_sectors;
2265+
2266+ host = scsi_host_alloc(&driver_template, sizeof(struct cxlflash_cfg));
2267+ if (!host) {
2268+ dev_err(&pdev->dev, "%s: call to scsi_host_alloc failed!\n",
2269+ __func__);
2270+ rc = -ENOMEM;
2271+ goto out;
2272+ }
2273+
2274+ host->max_id = CXLFLASH_MAX_NUM_TARGETS_PER_BUS;
2275+ host->max_lun = CXLFLASH_MAX_NUM_LUNS_PER_TARGET;
2276+ host->max_channel = NUM_FC_PORTS - 1;
2277+ host->unique_id = host->host_no;
2278+ host->max_cmd_len = CXLFLASH_MAX_CDB_LEN;
2279+
2280+ cfg = (struct cxlflash_cfg *)host->hostdata;
2281+ cfg->host = host;
2282+ rc = alloc_mem(cfg);
2283+ if (rc) {
2284+ dev_err(&pdev->dev, "%s: call to scsi_host_alloc failed!\n",
2285+ __func__);
2286+ rc = -ENOMEM;
2287+ goto out;
2288+ }
2289+
2290+ cfg->init_state = INIT_STATE_NONE;
2291+ cfg->dev = pdev;
2292+
2293+ /*
2294+ * The promoted LUNs move to the top of the LUN table. The rest stay
2295+ * on the bottom half. The bottom half grows from the end
2296+ * (index = 255), whereas the top half grows from the beginning
2297+ * (index = 0).
2298+ */
2299+ cfg->promote_lun_index = 0;
2300+ cfg->last_lun_index[0] = CXLFLASH_NUM_VLUNS/2 - 1;
2301+ cfg->last_lun_index[1] = CXLFLASH_NUM_VLUNS/2 - 1;
2302+
2303+ cfg->dev_id = (struct pci_device_id *)dev_id;
2304+ cfg->mcctx = NULL;
2305+
2306+ init_waitqueue_head(&cfg->tmf_waitq);
2307+ init_waitqueue_head(&cfg->limbo_waitq);
2308+
2309+ INIT_WORK(&cfg->work_q, cxlflash_worker_thread);
2310+ cfg->lr_state = LINK_RESET_INVALID;
2311+ cfg->lr_port = -1;
2312+ mutex_init(&cfg->ctx_tbl_list_mutex);
2313+ mutex_init(&cfg->ctx_recovery_mutex);
2314+ INIT_LIST_HEAD(&cfg->ctx_err_recovery);
2315+ INIT_LIST_HEAD(&cfg->lluns);
2316+
2317+ pci_set_drvdata(pdev, cfg);
2318+
2319+ /* Use the special service provided to look up the physical
2320+ * PCI device, since we are called on the probe of the virtual
2321+ * PCI host bus (vphb)
2322+ */
2323+ phys_dev = cxl_get_phys_dev(pdev);
2324+ if (!dev_is_pci(phys_dev)) {
2325+ pr_err("%s: not a pci dev\n", __func__);
2326+ rc = -ENODEV;
2327+ goto out_remove;
2328+ }
2329+ cfg->parent_dev = to_pci_dev(phys_dev);
2330+
2331+ cfg->cxl_afu = cxl_pci_to_afu(pdev);
2332+
2333+ rc = init_pci(cfg);
2334+ if (rc) {
2335+ dev_err(&pdev->dev, "%s: call to init_pci "
2336+ "failed rc=%d!\n", __func__, rc);
2337+ goto out_remove;
2338+ }
2339+ cfg->init_state = INIT_STATE_PCI;
2340+
2341+ rc = init_afu(cfg);
2342+ if (rc) {
2343+ dev_err(&pdev->dev, "%s: call to init_afu "
2344+ "failed rc=%d!\n", __func__, rc);
2345+ goto out_remove;
2346+ }
2347+ cfg->init_state = INIT_STATE_AFU;
2348+
2349+
2350+ rc = init_scsi(cfg);
2351+ if (rc) {
2352+ dev_err(&pdev->dev, "%s: call to init_scsi "
2353+ "failed rc=%d!\n", __func__, rc);
2354+ goto out_remove;
2355+ }
2356+ cfg->init_state = INIT_STATE_SCSI;
2357+
2358+out:
2359+ pr_debug("%s: returning rc=%d\n", __func__, rc);
2360+ return rc;
2361+
2362+out_remove:
2363+ cxlflash_remove(pdev);
2364+ goto out;
2365+}
2366+
2367+/**
2368+ * cxlflash_pci_error_detected() - called when a PCI error is detected
2369+ * @pdev: PCI device struct.
2370+ * @state: PCI channel state.
2371+ *
2372+ * Return: PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
2373+ */
2374+static pci_ers_result_t cxlflash_pci_error_detected(struct pci_dev *pdev,
2375+ pci_channel_state_t state)
2376+{
2377+ int rc = 0;
2378+ struct cxlflash_cfg *cfg = pci_get_drvdata(pdev);
2379+ struct device *dev = &cfg->dev->dev;
2380+
2381+ dev_dbg(dev, "%s: pdev=%p state=%u\n", __func__, pdev, state);
2382+
2383+ switch (state) {
2384+ case pci_channel_io_frozen:
2385+ cfg->state = STATE_LIMBO;
2386+
2387+ /* Turn off legacy I/O */
2388+ scsi_block_requests(cfg->host);
2389+ rc = cxlflash_mark_contexts_error(cfg);
2390+ if (unlikely(rc))
2391+ dev_err(dev, "%s: Failed to mark user contexts!(%d)\n",
2392+ __func__, rc);
2393+ term_mc(cfg, UNDO_START);
2394+ stop_afu(cfg);
2395+
2396+ return PCI_ERS_RESULT_NEED_RESET;
2397+ case pci_channel_io_perm_failure:
2398+ cfg->state = STATE_FAILTERM;
2399+ wake_up_all(&cfg->limbo_waitq);
2400+ scsi_unblock_requests(cfg->host);
2401+ return PCI_ERS_RESULT_DISCONNECT;
2402+ default:
2403+ break;
2404+ }
2405+ return PCI_ERS_RESULT_NEED_RESET;
2406+}
2407+
2408+/**
2409+ * cxlflash_pci_slot_reset() - called when PCI slot has been reset
2410+ * @pdev: PCI device struct.
2411+ *
2412+ * This routine is called by the pci error recovery code after the PCI
2413+ * slot has been reset, just before we should resume normal operations.
2414+ *
2415+ * Return: PCI_ERS_RESULT_RECOVERED or PCI_ERS_RESULT_DISCONNECT
2416+ */
2417+static pci_ers_result_t cxlflash_pci_slot_reset(struct pci_dev *pdev)
2418+{
2419+ int rc = 0;
2420+ struct cxlflash_cfg *cfg = pci_get_drvdata(pdev);
2421+ struct device *dev = &cfg->dev->dev;
2422+
2423+ dev_dbg(dev, "%s: pdev=%p\n", __func__, pdev);
2424+
2425+ rc = init_afu(cfg);
2426+ if (unlikely(rc)) {
2427+ dev_err(dev, "%s: EEH recovery failed! (%d)\n", __func__, rc);
2428+ return PCI_ERS_RESULT_DISCONNECT;
2429+ }
2430+
2431+ return PCI_ERS_RESULT_RECOVERED;
2432+}
2433+
2434+/**
2435+ * cxlflash_pci_resume() - called when normal operation can resume
2436+ * @pdev: PCI device struct
2437+ */
2438+static void cxlflash_pci_resume(struct pci_dev *pdev)
2439+{
2440+ struct cxlflash_cfg *cfg = pci_get_drvdata(pdev);
2441+ struct device *dev = &cfg->dev->dev;
2442+
2443+ dev_dbg(dev, "%s: pdev=%p\n", __func__, pdev);
2444+
2445+ cfg->state = STATE_NORMAL;
2446+ wake_up_all(&cfg->limbo_waitq);
2447+ scsi_unblock_requests(cfg->host);
2448+}
2449+
2450+static const struct pci_error_handlers cxlflash_err_handler = {
2451+ .error_detected = cxlflash_pci_error_detected,
2452+ .slot_reset = cxlflash_pci_slot_reset,
2453+ .resume = cxlflash_pci_resume,
2454+};
2455+
2456+/*
2457+ * PCI device structure
2458+ */
2459+static struct pci_driver cxlflash_driver = {
2460+ .name = CXLFLASH_NAME,
2461+ .id_table = cxlflash_pci_table,
2462+ .probe = cxlflash_probe,
2463+ .remove = cxlflash_remove,
2464+ .err_handler = &cxlflash_err_handler,
2465+};
2466+
2467+/**
2468+ * init_cxlflash() - module entry point
2469+ *
2470+ * Return: 0 on success / non-zero on failure
2471+ */
2472+static int __init init_cxlflash(void)
2473+{
2474+ pr_info("%s: IBM Power CXL Flash Adapter: %s\n",
2475+ __func__, CXLFLASH_DRIVER_DATE);
2476+
2477+ cxlflash_list_init();
2478+
2479+ return pci_register_driver(&cxlflash_driver);
2480+}
2481+
2482+/**
2483+ * exit_cxlflash() - module exit point
2484+ */
2485+static void __exit exit_cxlflash(void)
2486+{
2487+ cxlflash_term_global_luns();
2488+ cxlflash_free_errpage();
2489+
2490+ pci_unregister_driver(&cxlflash_driver);
2491+}
2492+
2493+module_init(init_cxlflash);
2494+module_exit(exit_cxlflash);
drivers/scsi/cxlflash/main.h+108−0
@@ -0,0 +1,108 @@
1+/*
2+ * CXL Flash Device Driver
3+ *
4+ * Written by: Manoj N. Kumar <manoj@linux.vnet.ibm.com>, IBM Corporation
5+ * Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation
6+ *
7+ * Copyright (C) 2015 IBM Corporation
8+ *
9+ * This program is free software; you can redistribute it and/or
10+ * modify it under the terms of the GNU General Public License
11+ * as published by the Free Software Foundation; either version
12+ * 2 of the License, or (at your option) any later version.
13+ */
14+
15+#ifndef _CXLFLASH_MAIN_H
16+#define _CXLFLASH_MAIN_H
17+
18+#include <linux/list.h>
19+#include <linux/types.h>
20+#include <scsi/scsi.h>
21+#include <scsi/scsi_device.h>
22+
23+#define CXLFLASH_NAME "cxlflash"
24+#define CXLFLASH_ADAPTER_NAME "IBM POWER CXL Flash Adapter"
25+#define CXLFLASH_DRIVER_DATE "(August 13, 2015)"
26+
27+#define PCI_DEVICE_ID_IBM_CORSA 0x04F0
28+#define CXLFLASH_SUBS_DEV_ID 0x04F0
29+
30+/* Since there is only one target, make it 0 */
31+#define CXLFLASH_TARGET 0
32+#define CXLFLASH_MAX_CDB_LEN 16
33+
34+/* Really only one target per bus since the Texan is directly attached */
35+#define CXLFLASH_MAX_NUM_TARGETS_PER_BUS 1
36+#define CXLFLASH_MAX_NUM_LUNS_PER_TARGET 65536
37+
38+#define CXLFLASH_PCI_ERROR_RECOVERY_TIMEOUT (120 * HZ)
39+
40+#define NUM_FC_PORTS CXLFLASH_NUM_FC_PORTS /* ports per AFU */
41+
42+/* FC defines */
43+#define FC_MTIP_CMDCONFIG 0x010
44+#define FC_MTIP_STATUS 0x018
45+
46+#define FC_PNAME 0x300
47+#define FC_CONFIG 0x320
48+#define FC_CONFIG2 0x328
49+#define FC_STATUS 0x330
50+#define FC_ERROR 0x380
51+#define FC_ERRCAP 0x388
52+#define FC_ERRMSK 0x390
53+#define FC_CNT_CRCERR 0x538
54+#define FC_CRC_THRESH 0x580
55+
56+#define FC_MTIP_CMDCONFIG_ONLINE 0x20ULL
57+#define FC_MTIP_CMDCONFIG_OFFLINE 0x40ULL
58+
59+#define FC_MTIP_STATUS_MASK 0x30ULL
60+#define FC_MTIP_STATUS_ONLINE 0x20ULL
61+#define FC_MTIP_STATUS_OFFLINE 0x10ULL
62+
63+/* TIMEOUT and RETRY definitions */
64+
65+/* AFU command timeout values */
66+#define MC_AFU_SYNC_TIMEOUT 5 /* 5 secs */
67+
68+/* AFU command room retry limit */
69+#define MC_ROOM_RETRY_CNT 10
70+
71+/* FC CRC clear periodic timer */
72+#define MC_CRC_THRESH 100 /* threshold in 5 mins */
73+
74+#define FC_PORT_STATUS_RETRY_CNT 100 /* 100 100ms retries = 10 seconds */
75+#define FC_PORT_STATUS_RETRY_INTERVAL_US 100000 /* microseconds */
76+
77+/* VPD defines */
78+#define CXLFLASH_VPD_LEN 256
79+#define WWPN_LEN 16
80+#define WWPN_BUF_LEN (WWPN_LEN + 1)
81+
82+enum undo_level {
83+ RELEASE_CONTEXT = 0,
84+ FREE_IRQ,
85+ UNMAP_ONE,
86+ UNMAP_TWO,
87+ UNMAP_THREE,
88+ UNDO_START
89+};
90+
91+struct dev_dependent_vals {
92+ u64 max_sectors;
93+};
94+
95+struct asyc_intr_info {
96+ u64 status;
97+ char *desc;
98+ u8 port;
99+ u8 action;
100+#define CLR_FC_ERROR 0x01
101+#define LINK_RESET 0x02
102+};
103+
104+#ifndef CONFIG_CXL_EEH
105+#define cxl_perst_reloads_same_image(_a, _b) do { } while (0)
106+#endif
107+
108+#endif /* _CXLFLASH_MAIN_H */
drivers/scsi/cxlflash/sislite.h+472−0
@@ -0,0 +1,472 @@
1+/*
2+ * CXL Flash Device Driver
3+ *
4+ * Written by: Manoj N. Kumar <manoj@linux.vnet.ibm.com>, IBM Corporation
5+ * Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation
6+ *
7+ * Copyright (C) 2015 IBM Corporation
8+ *
9+ * This program is free software; you can redistribute it and/or
10+ * modify it under the terms of the GNU General Public License
11+ * as published by the Free Software Foundation; either version
12+ * 2 of the License, or (at your option) any later version.
13+ */
14+
15+#ifndef _SISLITE_H
16+#define _SISLITE_H
17+
18+#include <linux/types.h>
19+
20+typedef u16 ctx_hndl_t;
21+typedef u32 res_hndl_t;
22+
23+#define SIZE_4K 4096
24+#define SIZE_64K 65536
25+
26+/*
27+ * IOARCB: 64 bytes, min 16 byte alignment required, host native endianness
28+ * except for SCSI CDB which remains big endian per SCSI standards.
29+ */
30+struct sisl_ioarcb {
31+ u16 ctx_id; /* ctx_hndl_t */
32+ u16 req_flags;
33+#define SISL_REQ_FLAGS_RES_HNDL 0x8000U /* bit 0 (MSB) */
34+#define SISL_REQ_FLAGS_PORT_LUN_ID 0x0000U
35+
36+#define SISL_REQ_FLAGS_SUP_UNDERRUN 0x4000U /* bit 1 */
37+
38+#define SISL_REQ_FLAGS_TIMEOUT_SECS 0x0000U /* bits 8,9 */
39+#define SISL_REQ_FLAGS_TIMEOUT_MSECS 0x0040U
40+#define SISL_REQ_FLAGS_TIMEOUT_USECS 0x0080U
41+#define SISL_REQ_FLAGS_TIMEOUT_CYCLES 0x00C0U
42+
43+#define SISL_REQ_FLAGS_TMF_CMD 0x0004u /* bit 13 */
44+
45+#define SISL_REQ_FLAGS_AFU_CMD 0x0002U /* bit 14 */
46+
47+#define SISL_REQ_FLAGS_HOST_WRITE 0x0001U /* bit 15 (LSB) */
48+#define SISL_REQ_FLAGS_HOST_READ 0x0000U
49+
50+ union {
51+ u32 res_hndl; /* res_hndl_t */
52+ u32 port_sel; /* this is a selection mask:
53+ * 0x1 -> port#0 can be selected,
54+ * 0x2 -> port#1 can be selected.
55+ * Can be bitwise ORed.
56+ */
57+ };
58+ u64 lun_id;
59+ u32 data_len; /* 4K for read/write */
60+ u32 ioadl_len;
61+ union {
62+ u64 data_ea; /* min 16 byte aligned */
63+ u64 ioadl_ea;
64+ };
65+ u8 msi; /* LISN to send on RRQ write */
66+#define SISL_MSI_CXL_PFAULT 0 /* reserved for CXL page faults */
67+#define SISL_MSI_SYNC_ERROR 1 /* recommended for AFU sync error */
68+#define SISL_MSI_RRQ_UPDATED 2 /* recommended for IO completion */
69+#define SISL_MSI_ASYNC_ERROR 3 /* master only - for AFU async error */
70+
71+ u8 rrq; /* 0 for a single RRQ */
72+ u16 timeout; /* in units specified by req_flags */
73+ u32 rsvd1;
74+ u8 cdb[16]; /* must be in big endian */
75+ struct scsi_cmnd *scp;
76+} __packed;
77+
78+struct sisl_rc {
79+ u8 flags;
80+#define SISL_RC_FLAGS_SENSE_VALID 0x80U
81+#define SISL_RC_FLAGS_FCP_RSP_CODE_VALID 0x40U
82+#define SISL_RC_FLAGS_OVERRUN 0x20U
83+#define SISL_RC_FLAGS_UNDERRUN 0x10U
84+
85+ u8 afu_rc;
86+#define SISL_AFU_RC_RHT_INVALID 0x01U /* user error */
87+#define SISL_AFU_RC_RHT_UNALIGNED 0x02U /* should never happen */
88+#define SISL_AFU_RC_RHT_OUT_OF_BOUNDS 0x03u /* user error */
89+#define SISL_AFU_RC_RHT_DMA_ERR 0x04u /* see afu_extra
90+ may retry if afu_retry is off
91+ possible on master exit
92+ */
93+#define SISL_AFU_RC_RHT_RW_PERM 0x05u /* no RW perms, user error */
94+#define SISL_AFU_RC_LXT_UNALIGNED 0x12U /* should never happen */
95+#define SISL_AFU_RC_LXT_OUT_OF_BOUNDS 0x13u /* user error */
96+#define SISL_AFU_RC_LXT_DMA_ERR 0x14u /* see afu_extra
97+ may retry if afu_retry is off
98+ possible on master exit
99+ */
100+#define SISL_AFU_RC_LXT_RW_PERM 0x15u /* no RW perms, user error */
101+
102+#define SISL_AFU_RC_NOT_XLATE_HOST 0x1au /* possible if master exited */
103+
104+ /* NO_CHANNELS means the FC ports selected by dest_port in
105+ * IOARCB or in the LXT entry are down when the AFU tried to select
106+ * a FC port. If the port went down on an active IO, it will set
107+ * fc_rc to =0x54(NOLOGI) or 0x57(LINKDOWN) instead.
108+ */
109+#define SISL_AFU_RC_NO_CHANNELS 0x20U /* see afu_extra, may retry */
110+#define SISL_AFU_RC_CAP_VIOLATION 0x21U /* either user error or
111+ afu reset/master restart
112+ */
113+#define SISL_AFU_RC_OUT_OF_DATA_BUFS 0x30U /* always retry */
114+#define SISL_AFU_RC_DATA_DMA_ERR 0x31U /* see afu_extra
115+ may retry if afu_retry is off
116+ */
117+
118+ u8 scsi_rc; /* SCSI status byte, retry as appropriate */
119+#define SISL_SCSI_RC_CHECK 0x02U
120+#define SISL_SCSI_RC_BUSY 0x08u
121+
122+ u8 fc_rc; /* retry */
123+ /*
124+ * We should only see fc_rc=0x57 (LINKDOWN) or 0x54(NOLOGI) for
125+ * commands that are in flight when a link goes down or is logged out.
126+ * If the link is down or logged out before AFU selects the port, either
127+ * it will choose the other port or we will get afu_rc=0x20 (no_channel)
128+ * if there is no valid port to use.
129+ *
130+ * ABORTPEND/ABORTOK/ABORTFAIL/TGTABORT can be retried, typically these
131+ * would happen if a frame is dropped and something times out.
132+ * NOLOGI or LINKDOWN can be retried if the other port is up.
133+ * RESIDERR can be retried as well.
134+ *
135+ * ABORTFAIL might indicate that lots of frames are getting CRC errors.
136+ * So it maybe retried once and reset the link if it happens again.
137+ * The link can also be reset on the CRC error threshold interrupt.
138+ */
139+#define SISL_FC_RC_ABORTPEND 0x52 /* exchange timeout or abort request */
140+#define SISL_FC_RC_WRABORTPEND 0x53 /* due to write XFER_RDY invalid */
141+#define SISL_FC_RC_NOLOGI 0x54 /* port not logged in, in-flight cmds */
142+#define SISL_FC_RC_NOEXP 0x55 /* FC protocol error or HW bug */
143+#define SISL_FC_RC_INUSE 0x56 /* tag already in use, HW bug */
144+#define SISL_FC_RC_LINKDOWN 0x57 /* link down, in-flight cmds */
145+#define SISL_FC_RC_ABORTOK 0x58 /* pending abort completed w/success */
146+#define SISL_FC_RC_ABORTFAIL 0x59 /* pending abort completed w/fail */
147+#define SISL_FC_RC_RESID 0x5A /* ioasa underrun/overrun flags set */
148+#define SISL_FC_RC_RESIDERR 0x5B /* actual data len does not match SCSI
149+ reported len, possbly due to dropped
150+ frames */
151+#define SISL_FC_RC_TGTABORT 0x5C /* command aborted by target */
152+};
153+
154+#define SISL_SENSE_DATA_LEN 20 /* Sense data length */
155+
156+/*
157+ * IOASA: 64 bytes & must follow IOARCB, min 16 byte alignment required,
158+ * host native endianness
159+ */
160+struct sisl_ioasa {
161+ union {
162+ struct sisl_rc rc;
163+ u32 ioasc;
164+#define SISL_IOASC_GOOD_COMPLETION 0x00000000U
165+ };
166+ u32 resid;
167+ u8 port;
168+ u8 afu_extra;
169+ /* when afu_rc=0x04, 0x14, 0x31 (_xxx_DMA_ERR):
170+ * afu_exta contains PSL response code. Useful codes are:
171+ */
172+#define SISL_AFU_DMA_ERR_PAGE_IN 0x0A /* AFU_retry_on_pagein Action
173+ * Enabled N/A
174+ * Disabled retry
175+ */
176+#define SISL_AFU_DMA_ERR_INVALID_EA 0x0B /* this is a hard error
177+ * afu_rc Implies
178+ * 0x04, 0x14 master exit.
179+ * 0x31 user error.
180+ */
181+ /* when afu rc=0x20 (no channels):
182+ * afu_extra bits [4:5]: available portmask, [6:7]: requested portmask.
183+ */
184+#define SISL_AFU_NO_CLANNELS_AMASK(afu_extra) (((afu_extra) & 0x0C) >> 2)
185+#define SISL_AFU_NO_CLANNELS_RMASK(afu_extra) ((afu_extra) & 0x03)
186+
187+ u8 scsi_extra;
188+ u8 fc_extra;
189+ u8 sense_data[SISL_SENSE_DATA_LEN];
190+
191+ /* These fields are defined by the SISlite architecture for the
192+ * host to use as they see fit for their implementation.
193+ */
194+ union {
195+ u64 host_use[4];
196+ u8 host_use_b[32];
197+ };
198+} __packed;
199+
200+#define SISL_RESP_HANDLE_T_BIT 0x1ULL /* Toggle bit */
201+
202+/* MMIO space is required to support only 64-bit access */
203+
204+/*
205+ * This AFU has two mechanisms to deal with endian-ness.
206+ * One is a global configuration (in the afu_config) register
207+ * below that specifies the endian-ness of the host.
208+ * The other is a per context (i.e. application) specification
209+ * controlled by the endian_ctrl field here. Since the master
210+ * context is one such application the master context's
211+ * endian-ness is set to be the same as the host.
212+ *
213+ * As per the SISlite spec, the MMIO registers are always
214+ * big endian.
215+ */
216+#define SISL_ENDIAN_CTRL_BE 0x8000000000000080ULL
217+#define SISL_ENDIAN_CTRL_LE 0x0000000000000000ULL
218+
219+#ifdef __BIG_ENDIAN
220+#define SISL_ENDIAN_CTRL SISL_ENDIAN_CTRL_BE
221+#else
222+#define SISL_ENDIAN_CTRL SISL_ENDIAN_CTRL_LE
223+#endif
224+
225+/* per context host transport MMIO */
226+struct sisl_host_map {
227+ __be64 endian_ctrl; /* Per context Endian Control. The AFU will
228+ * operate on whatever the context is of the
229+ * host application.
230+ */
231+
232+ __be64 intr_status; /* this sends LISN# programmed in ctx_ctrl.
233+ * Only recovery in a PERM_ERR is a context
234+ * exit since there is no way to tell which
235+ * command caused the error.
236+ */
237+#define SISL_ISTATUS_PERM_ERR_CMDROOM 0x0010ULL /* b59, user error */
238+#define SISL_ISTATUS_PERM_ERR_RCB_READ 0x0008ULL /* b60, user error */
239+#define SISL_ISTATUS_PERM_ERR_SA_WRITE 0x0004ULL /* b61, user error */
240+#define SISL_ISTATUS_PERM_ERR_RRQ_WRITE 0x0002ULL /* b62, user error */
241+ /* Page in wait accessing RCB/IOASA/RRQ is reported in b63.
242+ * Same error in data/LXT/RHT access is reported via IOASA.
243+ */
244+#define SISL_ISTATUS_TEMP_ERR_PAGEIN 0x0001ULL /* b63, can be generated
245+ * only when AFU auto
246+ * retry is disabled.
247+ * If user can determine
248+ * the command that
249+ * caused the error, it
250+ * can be retried.
251+ */
252+#define SISL_ISTATUS_UNMASK (0x001FULL) /* 1 means unmasked */
253+#define SISL_ISTATUS_MASK ~(SISL_ISTATUS_UNMASK) /* 1 means masked */
254+
255+ __be64 intr_clear;
256+ __be64 intr_mask;
257+ __be64 ioarrin; /* only write what cmd_room permits */
258+ __be64 rrq_start; /* start & end are both inclusive */
259+ __be64 rrq_end; /* write sequence: start followed by end */
260+ __be64 cmd_room;
261+ __be64 ctx_ctrl; /* least signiifcant byte or b56:63 is LISN# */
262+ __be64 mbox_w; /* restricted use */
263+};
264+
265+/* per context provisioning & control MMIO */
266+struct sisl_ctrl_map {
267+ __be64 rht_start;
268+ __be64 rht_cnt_id;
269+ /* both cnt & ctx_id args must be ULL */
270+#define SISL_RHT_CNT_ID(cnt, ctx_id) (((cnt) << 48) | ((ctx_id) << 32))
271+
272+ __be64 ctx_cap; /* afu_rc below is when the capability is violated */
273+#define SISL_CTX_CAP_PROXY_ISSUE 0x8000000000000000ULL /* afu_rc 0x21 */
274+#define SISL_CTX_CAP_REAL_MODE 0x4000000000000000ULL /* afu_rc 0x21 */
275+#define SISL_CTX_CAP_HOST_XLATE 0x2000000000000000ULL /* afu_rc 0x1a */
276+#define SISL_CTX_CAP_PROXY_TARGET 0x1000000000000000ULL /* afu_rc 0x21 */
277+#define SISL_CTX_CAP_AFU_CMD 0x0000000000000008ULL /* afu_rc 0x21 */
278+#define SISL_CTX_CAP_GSCSI_CMD 0x0000000000000004ULL /* afu_rc 0x21 */
279+#define SISL_CTX_CAP_WRITE_CMD 0x0000000000000002ULL /* afu_rc 0x21 */
280+#define SISL_CTX_CAP_READ_CMD 0x0000000000000001ULL /* afu_rc 0x21 */
281+ __be64 mbox_r;
282+};
283+
284+/* single copy global regs */
285+struct sisl_global_regs {
286+ __be64 aintr_status;
287+ /* In cxlflash, each FC port/link gets a byte of status */
288+#define SISL_ASTATUS_FC0_OTHER 0x8000ULL /* b48, other err,
289+ FC_ERRCAP[31:20] */
290+#define SISL_ASTATUS_FC0_LOGO 0x4000ULL /* b49, target sent FLOGI/PLOGI/LOGO
291+ while logged in */
292+#define SISL_ASTATUS_FC0_CRC_T 0x2000ULL /* b50, CRC threshold exceeded */
293+#define SISL_ASTATUS_FC0_LOGI_R 0x1000ULL /* b51, login state mechine timed out
294+ and retrying */
295+#define SISL_ASTATUS_FC0_LOGI_F 0x0800ULL /* b52, login failed,
296+ FC_ERROR[19:0] */
297+#define SISL_ASTATUS_FC0_LOGI_S 0x0400ULL /* b53, login succeeded */
298+#define SISL_ASTATUS_FC0_LINK_DN 0x0200ULL /* b54, link online to offline */
299+#define SISL_ASTATUS_FC0_LINK_UP 0x0100ULL /* b55, link offline to online */
300+
301+#define SISL_ASTATUS_FC1_OTHER 0x0080ULL /* b56 */
302+#define SISL_ASTATUS_FC1_LOGO 0x0040ULL /* b57 */
303+#define SISL_ASTATUS_FC1_CRC_T 0x0020ULL /* b58 */
304+#define SISL_ASTATUS_FC1_LOGI_R 0x0010ULL /* b59 */
305+#define SISL_ASTATUS_FC1_LOGI_F 0x0008ULL /* b60 */
306+#define SISL_ASTATUS_FC1_LOGI_S 0x0004ULL /* b61 */
307+#define SISL_ASTATUS_FC1_LINK_DN 0x0002ULL /* b62 */
308+#define SISL_ASTATUS_FC1_LINK_UP 0x0001ULL /* b63 */
309+
310+#define SISL_FC_INTERNAL_UNMASK 0x0000000300000000ULL /* 1 means unmasked */
311+#define SISL_FC_INTERNAL_MASK ~(SISL_FC_INTERNAL_UNMASK)
312+#define SISL_FC_INTERNAL_SHIFT 32
313+
314+#define SISL_ASTATUS_UNMASK 0xFFFFULL /* 1 means unmasked */
315+#define SISL_ASTATUS_MASK ~(SISL_ASTATUS_UNMASK) /* 1 means masked */
316+
317+ __be64 aintr_clear;
318+ __be64 aintr_mask;
319+ __be64 afu_ctrl;
320+ __be64 afu_hb;
321+ __be64 afu_scratch_pad;
322+ __be64 afu_port_sel;
323+#define SISL_AFUCONF_AR_IOARCB 0x4000ULL
324+#define SISL_AFUCONF_AR_LXT 0x2000ULL
325+#define SISL_AFUCONF_AR_RHT 0x1000ULL
326+#define SISL_AFUCONF_AR_DATA 0x0800ULL
327+#define SISL_AFUCONF_AR_RSRC 0x0400ULL
328+#define SISL_AFUCONF_AR_IOASA 0x0200ULL
329+#define SISL_AFUCONF_AR_RRQ 0x0100ULL
330+/* Aggregate all Auto Retry Bits */
331+#define SISL_AFUCONF_AR_ALL (SISL_AFUCONF_AR_IOARCB|SISL_AFUCONF_AR_LXT| \
332+ SISL_AFUCONF_AR_RHT|SISL_AFUCONF_AR_DATA| \
333+ SISL_AFUCONF_AR_RSRC|SISL_AFUCONF_AR_IOASA| \
334+ SISL_AFUCONF_AR_RRQ)
335+#ifdef __BIG_ENDIAN
336+#define SISL_AFUCONF_ENDIAN 0x0000ULL
337+#else
338+#define SISL_AFUCONF_ENDIAN 0x0020ULL
339+#endif
340+#define SISL_AFUCONF_MBOX_CLR_READ 0x0010ULL
341+ __be64 afu_config;
342+ __be64 rsvd[0xf8];
343+ __be64 afu_version;
344+ __be64 interface_version;
345+};
346+
347+#define CXLFLASH_NUM_FC_PORTS 2
348+#define CXLFLASH_MAX_CONTEXT 512 /* how many contexts per afu */
349+#define CXLFLASH_NUM_VLUNS 512
350+
351+struct sisl_global_map {
352+ union {
353+ struct sisl_global_regs regs;
354+ char page0[SIZE_4K]; /* page 0 */
355+ };
356+
357+ char page1[SIZE_4K]; /* page 1 */
358+
359+ /* pages 2 & 3 */
360+ __be64 fc_regs[CXLFLASH_NUM_FC_PORTS][CXLFLASH_NUM_VLUNS];
361+
362+ /* pages 4 & 5 (lun tbl) */
363+ __be64 fc_port[CXLFLASH_NUM_FC_PORTS][CXLFLASH_NUM_VLUNS];
364+
365+};
366+
367+/*
368+ * CXL Flash Memory Map
369+ *
370+ * +-------------------------------+
371+ * | 512 * 64 KB User MMIO |
372+ * | (per context) |
373+ * | User Accessible |
374+ * +-------------------------------+
375+ * | 512 * 128 B per context |
376+ * | Provisioning and Control |
377+ * | Trusted Process accessible |
378+ * +-------------------------------+
379+ * | 64 KB Global |
380+ * | Trusted Process accessible |
381+ * +-------------------------------+
382+*/
383+struct cxlflash_afu_map {
384+ union {
385+ struct sisl_host_map host;
386+ char harea[SIZE_64K]; /* 64KB each */
387+ } hosts[CXLFLASH_MAX_CONTEXT];
388+
389+ union {
390+ struct sisl_ctrl_map ctrl;
391+ char carea[cache_line_size()]; /* 128B each */
392+ } ctrls[CXLFLASH_MAX_CONTEXT];
393+
394+ union {
395+ struct sisl_global_map global;
396+ char garea[SIZE_64K]; /* 64KB single block */
397+ };
398+};
399+
400+/*
401+ * LXT - LBA Translation Table
402+ * LXT control blocks
403+ */
404+struct sisl_lxt_entry {
405+ u64 rlba_base; /* bits 0:47 is base
406+ * b48:55 is lun index
407+ * b58:59 is write & read perms
408+ * (if no perm, afu_rc=0x15)
409+ * b60:63 is port_sel mask
410+ */
411+};
412+
413+/*
414+ * RHT - Resource Handle Table
415+ * Per the SISlite spec, RHT entries are to be 16-byte aligned
416+ */
417+struct sisl_rht_entry {
418+ struct sisl_lxt_entry *lxt_start;
419+ u32 lxt_cnt;
420+ u16 rsvd;
421+ u8 fp; /* format & perm nibbles.
422+ * (if no perm, afu_rc=0x05)
423+ */
424+ u8 nmask;
425+} __packed __aligned(16);
426+
427+struct sisl_rht_entry_f1 {
428+ u64 lun_id;
429+ union {
430+ struct {
431+ u8 valid;
432+ u8 rsvd[5];
433+ u8 fp;
434+ u8 port_sel;
435+ };
436+
437+ u64 dw;
438+ };
439+} __packed __aligned(16);
440+
441+/* make the fp byte */
442+#define SISL_RHT_FP(fmt, perm) (((fmt) << 4) | (perm))
443+
444+/* make the fp byte for a clone from a source fp and clone flags
445+ * flags must be only 2 LSB bits.
446+ */
447+#define SISL_RHT_FP_CLONE(src_fp, cln_flags) ((src_fp) & (0xFC | (cln_flags)))
448+
449+#define RHT_PERM_READ 0x01U
450+#define RHT_PERM_WRITE 0x02U
451+#define RHT_PERM_RW (RHT_PERM_READ | RHT_PERM_WRITE)
452+
453+/* extract the perm bits from a fp */
454+#define SISL_RHT_PERM(fp) ((fp) & RHT_PERM_RW)
455+
456+#define PORT0 0x01U
457+#define PORT1 0x02U
458+#define BOTH_PORTS (PORT0 | PORT1)
459+
460+/* AFU Sync Mode byte */
461+#define AFU_LW_SYNC 0x0U
462+#define AFU_HW_SYNC 0x1U
463+#define AFU_GSYNC 0x2U
464+
465+/* Special Task Management Function CDB */
466+#define TMF_LUN_RESET 0x1U
467+#define TMF_CLEAR_ACA 0x2U
468+
469+
470+#define SISLITE_MAX_WS_BLOCKS 512
471+
472+#endif /* _SISLITE_H */
drivers/scsi/cxlflash/superpipe.c+2084−0
@@ -0,0 +1,2084 @@
1+/*
2+ * CXL Flash Device Driver
3+ *
4+ * Written by: Manoj N. Kumar <manoj@linux.vnet.ibm.com>, IBM Corporation
5+ * Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation
6+ *
7+ * Copyright (C) 2015 IBM Corporation
8+ *
9+ * This program is free software; you can redistribute it and/or
10+ * modify it under the terms of the GNU General Public License
11+ * as published by the Free Software Foundation; either version
12+ * 2 of the License, or (at your option) any later version.
13+ */
14+
15+#include <linux/delay.h>
16+#include <linux/file.h>
17+#include <linux/syscalls.h>
18+#include <misc/cxl.h>
19+#include <asm/unaligned.h>
20+
21+#include <scsi/scsi.h>
22+#include <scsi/scsi_host.h>
23+#include <scsi/scsi_cmnd.h>
24+#include <scsi/scsi_eh.h>
25+#include <uapi/scsi/cxlflash_ioctl.h>
26+
27+#include "sislite.h"
28+#include "common.h"
29+#include "vlun.h"
30+#include "superpipe.h"
31+
32+struct cxlflash_global global;
33+
34+/**
35+ * marshal_rele_to_resize() - translate release to resize structure
36+ * @rele: Source structure from which to translate/copy.
37+ * @resize: Destination structure for the translate/copy.
38+ */
39+static void marshal_rele_to_resize(struct dk_cxlflash_release *release,
40+ struct dk_cxlflash_resize *resize)
41+{
42+ resize->hdr = release->hdr;
43+ resize->context_id = release->context_id;
44+ resize->rsrc_handle = release->rsrc_handle;
45+}
46+
47+/**
48+ * marshal_det_to_rele() - translate detach to release structure
49+ * @detach: Destination structure for the translate/copy.
50+ * @rele: Source structure from which to translate/copy.
51+ */
52+static void marshal_det_to_rele(struct dk_cxlflash_detach *detach,
53+ struct dk_cxlflash_release *release)
54+{
55+ release->hdr = detach->hdr;
56+ release->context_id = detach->context_id;
57+}
58+
59+/**
60+ * cxlflash_free_errpage() - frees resources associated with global error page
61+ */
62+void cxlflash_free_errpage(void)
63+{
64+
65+ mutex_lock(&global.mutex);
66+ if (global.err_page) {
67+ __free_page(global.err_page);
68+ global.err_page = NULL;
69+ }
70+ mutex_unlock(&global.mutex);
71+}
72+
73+/**
74+ * cxlflash_stop_term_user_contexts() - stops/terminates known user contexts
75+ * @cfg: Internal structure associated with the host.
76+ *
77+ * When the host needs to go down, all users must be quiesced and their
78+ * memory freed. This is accomplished by putting the contexts in error
79+ * state which will notify the user and let them 'drive' the tear-down.
80+ * Meanwhile, this routine camps until all user contexts have been removed.
81+ */
82+void cxlflash_stop_term_user_contexts(struct cxlflash_cfg *cfg)
83+{
84+ struct device *dev = &cfg->dev->dev;
85+ int i, found;
86+
87+ cxlflash_mark_contexts_error(cfg);
88+
89+ while (true) {
90+ found = false;
91+
92+ for (i = 0; i < MAX_CONTEXT; i++)
93+ if (cfg->ctx_tbl[i]) {
94+ found = true;
95+ break;
96+ }
97+
98+ if (!found && list_empty(&cfg->ctx_err_recovery))
99+ return;
100+
101+ dev_dbg(dev, "%s: Wait for user contexts to quiesce...\n",
102+ __func__);
103+ wake_up_all(&cfg->limbo_waitq);
104+ ssleep(1);
105+ }
106+}
107+
108+/**
109+ * find_error_context() - locates a context by cookie on the error recovery list
110+ * @cfg: Internal structure associated with the host.
111+ * @rctxid: Desired context by id.
112+ * @file: Desired context by file.
113+ *
114+ * Return: Found context on success, NULL on failure
115+ */
116+static struct ctx_info *find_error_context(struct cxlflash_cfg *cfg, u64 rctxid,
117+ struct file *file)
118+{
119+ struct ctx_info *ctxi;
120+
121+ list_for_each_entry(ctxi, &cfg->ctx_err_recovery, list)
122+ if ((ctxi->ctxid == rctxid) || (ctxi->file == file))
123+ return ctxi;
124+
125+ return NULL;
126+}
127+
128+/**
129+ * get_context() - obtains a validated and locked context reference
130+ * @cfg: Internal structure associated with the host.
131+ * @rctxid: Desired context (raw, un-decoded format).
132+ * @arg: LUN information or file associated with request.
133+ * @ctx_ctrl: Control information to 'steer' desired lookup.
134+ *
135+ * NOTE: despite the name pid, in linux, current->pid actually refers
136+ * to the lightweight process id (tid) and can change if the process is
137+ * multi threaded. The tgid remains constant for the process and only changes
138+ * when the process of fork. For all intents and purposes, think of tgid
139+ * as a pid in the traditional sense.
140+ *
141+ * Return: Validated context on success, NULL on failure
142+ */
143+struct ctx_info *get_context(struct cxlflash_cfg *cfg, u64 rctxid,
144+ void *arg, enum ctx_ctrl ctx_ctrl)
145+{
146+ struct device *dev = &cfg->dev->dev;
147+ struct ctx_info *ctxi = NULL;
148+ struct lun_access *lun_access = NULL;
149+ struct file *file = NULL;
150+ struct llun_info *lli = arg;
151+ u64 ctxid = DECODE_CTXID(rctxid);
152+ int rc;
153+ pid_t pid = current->tgid, ctxpid = 0;
154+
155+ if (ctx_ctrl & CTX_CTRL_FILE) {
156+ lli = NULL;
157+ file = (struct file *)arg;
158+ }
159+
160+ if (ctx_ctrl & CTX_CTRL_CLONE)
161+ pid = current->parent->tgid;
162+
163+ if (likely(ctxid < MAX_CONTEXT)) {
164+ while (true) {
165+ rc = mutex_lock_interruptible(&cfg->ctx_tbl_list_mutex);
166+ if (rc)
167+ goto out;
168+
169+ ctxi = cfg->ctx_tbl[ctxid];
170+ if (ctxi)
171+ if ((file && (ctxi->file != file)) ||
172+ (!file && (ctxi->ctxid != rctxid)))
173+ ctxi = NULL;
174+
175+ if ((ctx_ctrl & CTX_CTRL_ERR) ||
176+ (!ctxi && (ctx_ctrl & CTX_CTRL_ERR_FALLBACK)))
177+ ctxi = find_error_context(cfg, rctxid, file);
178+ if (!ctxi) {
179+ mutex_unlock(&cfg->ctx_tbl_list_mutex);
180+ goto out;
181+ }
182+
183+ /*
184+ * Need to acquire ownership of the context while still
185+ * under the table/list lock to serialize with a remove
186+ * thread. Use the 'try' to avoid stalling the
187+ * table/list lock for a single context.
188+ *
189+ * Note that the lock order is:
190+ *
191+ * cfg->ctx_tbl_list_mutex -> ctxi->mutex
192+ *
193+ * Therefore release ctx_tbl_list_mutex before retrying.
194+ */
195+ rc = mutex_trylock(&ctxi->mutex);
196+ mutex_unlock(&cfg->ctx_tbl_list_mutex);
197+ if (rc)
198+ break; /* got the context's lock! */
199+ }
200+
201+ if (ctxi->unavail)
202+ goto denied;
203+
204+ ctxpid = ctxi->pid;
205+ if (likely(!(ctx_ctrl & CTX_CTRL_NOPID)))
206+ if (pid != ctxpid)
207+ goto denied;
208+
209+ if (lli) {
210+ list_for_each_entry(lun_access, &ctxi->luns, list)
211+ if (lun_access->lli == lli)
212+ goto out;
213+ goto denied;
214+ }
215+ }
216+
217+out:
218+ dev_dbg(dev, "%s: rctxid=%016llX ctxinfo=%p ctxpid=%u pid=%u "
219+ "ctx_ctrl=%u\n", __func__, rctxid, ctxi, ctxpid, pid,
220+ ctx_ctrl);
221+
222+ return ctxi;
223+
224+denied:
225+ mutex_unlock(&ctxi->mutex);
226+ ctxi = NULL;
227+ goto out;
228+}
229+
230+/**
231+ * put_context() - release a context that was retrieved from get_context()
232+ * @ctxi: Context to release.
233+ *
234+ * For now, releasing the context equates to unlocking it's mutex.
235+ */
236+void put_context(struct ctx_info *ctxi)
237+{
238+ mutex_unlock(&ctxi->mutex);
239+}
240+
241+/**
242+ * afu_attach() - attach a context to the AFU
243+ * @cfg: Internal structure associated with the host.
244+ * @ctxi: Context to attach.
245+ *
246+ * Upon setting the context capabilities, they must be confirmed with
247+ * a read back operation as the context might have been closed since
248+ * the mailbox was unlocked. When this occurs, registration is failed.
249+ *
250+ * Return: 0 on success, -errno on failure
251+ */
252+static int afu_attach(struct cxlflash_cfg *cfg, struct ctx_info *ctxi)
253+{
254+ struct device *dev = &cfg->dev->dev;
255+ struct afu *afu = cfg->afu;
256+ struct sisl_ctrl_map *ctrl_map = ctxi->ctrl_map;
257+ int rc = 0;
258+ u64 val;
259+
260+ /* Unlock cap and restrict user to read/write cmds in translated mode */
261+ readq_be(&ctrl_map->mbox_r);
262+ val = (SISL_CTX_CAP_READ_CMD | SISL_CTX_CAP_WRITE_CMD);
263+ writeq_be(val, &ctrl_map->ctx_cap);
264+ val = readq_be(&ctrl_map->ctx_cap);
265+ if (val != (SISL_CTX_CAP_READ_CMD | SISL_CTX_CAP_WRITE_CMD)) {
266+ dev_err(dev, "%s: ctx may be closed val=%016llX\n",
267+ __func__, val);
268+ rc = -EAGAIN;
269+ goto out;
270+ }
271+
272+ /* Set up MMIO registers pointing to the RHT */
273+ writeq_be((u64)ctxi->rht_start, &ctrl_map->rht_start);
274+ val = SISL_RHT_CNT_ID((u64)MAX_RHT_PER_CONTEXT, (u64)(afu->ctx_hndl));
275+ writeq_be(val, &ctrl_map->rht_cnt_id);
276+out:
277+ dev_dbg(dev, "%s: returning rc=%d\n", __func__, rc);
278+ return rc;
279+}
280+
281+/**
282+ * read_cap16() - issues a SCSI READ_CAP16 command
283+ * @sdev: SCSI device associated with LUN.
284+ * @lli: LUN destined for capacity request.
285+ *
286+ * Return: 0 on success, -errno on failure
287+ */
288+static int read_cap16(struct scsi_device *sdev, struct llun_info *lli)
289+{
290+ struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)sdev->host->hostdata;
291+ struct device *dev = &cfg->dev->dev;
292+ struct glun_info *gli = lli->parent;
293+ u8 *cmd_buf = NULL;
294+ u8 *scsi_cmd = NULL;
295+ u8 *sense_buf = NULL;
296+ int rc = 0;
297+ int result = 0;
298+ int retry_cnt = 0;
299+ u32 tout = (MC_DISCOVERY_TIMEOUT * HZ);
300+
301+retry:
302+ cmd_buf = kzalloc(CMD_BUFSIZE, GFP_KERNEL);
303+ scsi_cmd = kzalloc(MAX_COMMAND_SIZE, GFP_KERNEL);
304+ sense_buf = kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL);
305+ if (unlikely(!cmd_buf || !scsi_cmd || !sense_buf)) {
306+ rc = -ENOMEM;
307+ goto out;
308+ }
309+
310+ scsi_cmd[0] = SERVICE_ACTION_IN_16; /* read cap(16) */
311+ scsi_cmd[1] = SAI_READ_CAPACITY_16; /* service action */
312+ put_unaligned_be32(CMD_BUFSIZE, &scsi_cmd[10]);
313+
314+ dev_dbg(dev, "%s: %ssending cmd(0x%x)\n", __func__,
315+ retry_cnt ? "re" : "", scsi_cmd[0]);
316+
317+ result = scsi_execute(sdev, scsi_cmd, DMA_FROM_DEVICE, cmd_buf,
318+ CMD_BUFSIZE, sense_buf, tout, 5, 0, NULL);
319+
320+ if (driver_byte(result) == DRIVER_SENSE) {
321+ result &= ~(0xFF<<24); /* DRIVER_SENSE is not an error */
322+ if (result & SAM_STAT_CHECK_CONDITION) {
323+ struct scsi_sense_hdr sshdr;
324+
325+ scsi_normalize_sense(sense_buf, SCSI_SENSE_BUFFERSIZE,
326+ &sshdr);
327+ switch (sshdr.sense_key) {
328+ case NO_SENSE:
329+ case RECOVERED_ERROR:
330+ /* fall through */
331+ case NOT_READY:
332+ result &= ~SAM_STAT_CHECK_CONDITION;
333+ break;
334+ case UNIT_ATTENTION:
335+ switch (sshdr.asc) {
336+ case 0x29: /* Power on Reset or Device Reset */
337+ /* fall through */
338+ case 0x2A: /* Device capacity changed */
339+ case 0x3F: /* Report LUNs changed */
340+ /* Retry the command once more */
341+ if (retry_cnt++ < 1) {
342+ kfree(cmd_buf);
343+ kfree(scsi_cmd);
344+ kfree(sense_buf);
345+ goto retry;
346+ }
347+ }
348+ break;
349+ default:
350+ break;
351+ }
352+ }
353+ }
354+
355+ if (result) {
356+ dev_err(dev, "%s: command failed, result=0x%x\n",
357+ __func__, result);
358+ rc = -EIO;
359+ goto out;
360+ }
361+
362+ /*
363+ * Read cap was successful, grab values from the buffer;
364+ * note that we don't need to worry about unaligned access
365+ * as the buffer is allocated on an aligned boundary.
366+ */
367+ mutex_lock(&gli->mutex);
368+ gli->max_lba = be64_to_cpu(*((u64 *)&cmd_buf[0]));
369+ gli->blk_len = be32_to_cpu(*((u32 *)&cmd_buf[8]));
370+ mutex_unlock(&gli->mutex);
371+
372+out:
373+ kfree(cmd_buf);
374+ kfree(scsi_cmd);
375+ kfree(sense_buf);
376+
377+ dev_dbg(dev, "%s: maxlba=%lld blklen=%d rc=%d\n",
378+ __func__, gli->max_lba, gli->blk_len, rc);
379+ return rc;
380+}
381+
382+/**
383+ * get_rhte() - obtains validated resource handle table entry reference
384+ * @ctxi: Context owning the resource handle.
385+ * @rhndl: Resource handle associated with entry.
386+ * @lli: LUN associated with request.
387+ *
388+ * Return: Validated RHTE on success, NULL on failure
389+ */
390+struct sisl_rht_entry *get_rhte(struct ctx_info *ctxi, res_hndl_t rhndl,
391+ struct llun_info *lli)
392+{
393+ struct sisl_rht_entry *rhte = NULL;
394+
395+ if (unlikely(!ctxi->rht_start)) {
396+ pr_debug("%s: Context does not have allocated RHT!\n",
397+ __func__);
398+ goto out;
399+ }
400+
401+ if (unlikely(rhndl >= MAX_RHT_PER_CONTEXT)) {
402+ pr_debug("%s: Bad resource handle! (%d)\n", __func__, rhndl);
403+ goto out;
404+ }
405+
406+ if (unlikely(ctxi->rht_lun[rhndl] != lli)) {
407+ pr_debug("%s: Bad resource handle LUN! (%d)\n",
408+ __func__, rhndl);
409+ goto out;
410+ }
411+
412+ rhte = &ctxi->rht_start[rhndl];
413+ if (unlikely(rhte->nmask == 0)) {
414+ pr_debug("%s: Unopened resource handle! (%d)\n",
415+ __func__, rhndl);
416+ rhte = NULL;
417+ goto out;
418+ }
419+
420+out:
421+ return rhte;
422+}
423+
424+/**
425+ * rhte_checkout() - obtains free/empty resource handle table entry
426+ * @ctxi: Context owning the resource handle.
427+ * @lli: LUN associated with request.
428+ *
429+ * Return: Free RHTE on success, NULL on failure
430+ */
431+struct sisl_rht_entry *rhte_checkout(struct ctx_info *ctxi,
432+ struct llun_info *lli)
433+{
434+ struct sisl_rht_entry *rhte = NULL;
435+ int i;
436+
437+ /* Find a free RHT entry */
438+ for (i = 0; i < MAX_RHT_PER_CONTEXT; i++)
439+ if (ctxi->rht_start[i].nmask == 0) {
440+ rhte = &ctxi->rht_start[i];
441+ ctxi->rht_out++;
442+ break;
443+ }
444+
445+ if (likely(rhte))
446+ ctxi->rht_lun[i] = lli;
447+
448+ pr_debug("%s: returning rhte=%p (%d)\n", __func__, rhte, i);
449+ return rhte;
450+}
451+
452+/**
453+ * rhte_checkin() - releases a resource handle table entry
454+ * @ctxi: Context owning the resource handle.
455+ * @rhte: RHTE to release.
456+ */
457+void rhte_checkin(struct ctx_info *ctxi,
458+ struct sisl_rht_entry *rhte)
459+{
460+ u32 rsrc_handle = rhte - ctxi->rht_start;
461+
462+ rhte->nmask = 0;
463+ rhte->fp = 0;
464+ ctxi->rht_out--;
465+ ctxi->rht_lun[rsrc_handle] = NULL;
466+ ctxi->rht_needs_ws[rsrc_handle] = false;
467+}
468+
469+/**
470+ * rhte_format1() - populates a RHTE for format 1
471+ * @rhte: RHTE to populate.
472+ * @lun_id: LUN ID of LUN associated with RHTE.
473+ * @perm: Desired permissions for RHTE.
474+ * @port_sel: Port selection mask
475+ */
476+static void rht_format1(struct sisl_rht_entry *rhte, u64 lun_id, u32 perm,
477+ u32 port_sel)
478+{
479+ /*
480+ * Populate the Format 1 RHT entry for direct access (physical
481+ * LUN) using the synchronization sequence defined in the
482+ * SISLite specification.
483+ */
484+ struct sisl_rht_entry_f1 dummy = { 0 };
485+ struct sisl_rht_entry_f1 *rhte_f1 = (struct sisl_rht_entry_f1 *)rhte;
486+
487+ memset(rhte_f1, 0, sizeof(*rhte_f1));
488+ rhte_f1->fp = SISL_RHT_FP(1U, 0);
489+ dma_wmb(); /* Make setting of format bit visible */
490+
491+ rhte_f1->lun_id = lun_id;
492+ dma_wmb(); /* Make setting of LUN id visible */
493+
494+ /*
495+ * Use a dummy RHT Format 1 entry to build the second dword
496+ * of the entry that must be populated in a single write when
497+ * enabled (valid bit set to TRUE).
498+ */
499+ dummy.valid = 0x80;
500+ dummy.fp = SISL_RHT_FP(1U, perm);
501+ dummy.port_sel = port_sel;
502+ rhte_f1->dw = dummy.dw;
503+
504+ dma_wmb(); /* Make remaining RHT entry fields visible */
505+}
506+
507+/**
508+ * cxlflash_lun_attach() - attaches a user to a LUN and manages the LUN's mode
509+ * @gli: LUN to attach.
510+ * @mode: Desired mode of the LUN.
511+ * @locked: Mutex status on current thread.
512+ *
513+ * Return: 0 on success, -errno on failure
514+ */
515+int cxlflash_lun_attach(struct glun_info *gli, enum lun_mode mode, bool locked)
516+{
517+ int rc = 0;
518+
519+ if (!locked)
520+ mutex_lock(&gli->mutex);
521+
522+ if (gli->mode == MODE_NONE)
523+ gli->mode = mode;
524+ else if (gli->mode != mode) {
525+ pr_debug("%s: LUN operating in mode %d, requested mode %d\n",
526+ __func__, gli->mode, mode);
527+ rc = -EINVAL;
528+ goto out;
529+ }
530+
531+ gli->users++;
532+ WARN_ON(gli->users <= 0);
533+out:
534+ pr_debug("%s: Returning rc=%d gli->mode=%u gli->users=%u\n",
535+ __func__, rc, gli->mode, gli->users);
536+ if (!locked)
537+ mutex_unlock(&gli->mutex);
538+ return rc;
539+}
540+
541+/**
542+ * cxlflash_lun_detach() - detaches a user from a LUN and resets the LUN's mode
543+ * @gli: LUN to detach.
544+ *
545+ * When resetting the mode, terminate block allocation resources as they
546+ * are no longer required (service is safe to call even when block allocation
547+ * resources were not present - such as when transitioning from physical mode).
548+ * These resources will be reallocated when needed (subsequent transition to
549+ * virtual mode).
550+ */
551+void cxlflash_lun_detach(struct glun_info *gli)
552+{
553+ mutex_lock(&gli->mutex);
554+ WARN_ON(gli->mode == MODE_NONE);
555+ if (--gli->users == 0) {
556+ gli->mode = MODE_NONE;
557+ cxlflash_ba_terminate(&gli->blka.ba_lun);
558+ }
559+ pr_debug("%s: gli->users=%u\n", __func__, gli->users);
560+ WARN_ON(gli->users < 0);
561+ mutex_unlock(&gli->mutex);
562+}
563+
564+/**
565+ * _cxlflash_disk_release() - releases the specified resource entry
566+ * @sdev: SCSI device associated with LUN.
567+ * @ctxi: Context owning resources.
568+ * @release: Release ioctl data structure.
569+ *
570+ * For LUNs in virtual mode, the virtual LUN associated with the specified
571+ * resource handle is resized to 0 prior to releasing the RHTE. Note that the
572+ * AFU sync should _not_ be performed when the context is sitting on the error
573+ * recovery list. A context on the error recovery list is not known to the AFU
574+ * due to reset. When the context is recovered, it will be reattached and made
575+ * known again to the AFU.
576+ *
577+ * Return: 0 on success, -errno on failure
578+ */
579+int _cxlflash_disk_release(struct scsi_device *sdev,
580+ struct ctx_info *ctxi,
581+ struct dk_cxlflash_release *release)
582+{
583+ struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)sdev->host->hostdata;
584+ struct device *dev = &cfg->dev->dev;
585+ struct llun_info *lli = sdev->hostdata;
586+ struct glun_info *gli = lli->parent;
587+ struct afu *afu = cfg->afu;
588+ bool put_ctx = false;
589+
590+ struct dk_cxlflash_resize size;
591+ res_hndl_t rhndl = release->rsrc_handle;
592+
593+ int rc = 0;
594+ u64 ctxid = DECODE_CTXID(release->context_id),
595+ rctxid = release->context_id;
596+
597+ struct sisl_rht_entry *rhte;
598+ struct sisl_rht_entry_f1 *rhte_f1;
599+
600+ dev_dbg(dev, "%s: ctxid=%llu rhndl=0x%llx gli->mode=%u gli->users=%u\n",
601+ __func__, ctxid, release->rsrc_handle, gli->mode, gli->users);
602+
603+ if (!ctxi) {
604+ ctxi = get_context(cfg, rctxid, lli, CTX_CTRL_ERR_FALLBACK);
605+ if (unlikely(!ctxi)) {
606+ dev_dbg(dev, "%s: Bad context! (%llu)\n",
607+ __func__, ctxid);
608+ rc = -EINVAL;
609+ goto out;
610+ }
611+
612+ put_ctx = true;
613+ }
614+
615+ rhte = get_rhte(ctxi, rhndl, lli);
616+ if (unlikely(!rhte)) {
617+ dev_dbg(dev, "%s: Bad resource handle! (%d)\n",
618+ __func__, rhndl);
619+ rc = -EINVAL;
620+ goto out;
621+ }
622+
623+ /*
624+ * Resize to 0 for virtual LUNS by setting the size
625+ * to 0. This will clear LXT_START and LXT_CNT fields
626+ * in the RHT entry and properly sync with the AFU.
627+ *
628+ * Afterwards we clear the remaining fields.
629+ */
630+ switch (gli->mode) {
631+ case MODE_VIRTUAL:
632+ marshal_rele_to_resize(release, &size);
633+ size.req_size = 0;
634+ rc = _cxlflash_vlun_resize(sdev, ctxi, &size);
635+ if (rc) {
636+ dev_dbg(dev, "%s: resize failed rc %d\n", __func__, rc);
637+ goto out;
638+ }
639+
640+ break;
641+ case MODE_PHYSICAL:
642+ /*
643+ * Clear the Format 1 RHT entry for direct access
644+ * (physical LUN) using the synchronization sequence
645+ * defined in the SISLite specification.
646+ */
647+ rhte_f1 = (struct sisl_rht_entry_f1 *)rhte;
648+
649+ rhte_f1->valid = 0;
650+ dma_wmb(); /* Make revocation of RHT entry visible */
651+
652+ rhte_f1->lun_id = 0;
653+ dma_wmb(); /* Make clearing of LUN id visible */
654+
655+ rhte_f1->dw = 0;
656+ dma_wmb(); /* Make RHT entry bottom-half clearing visible */
657+
658+ if (!ctxi->err_recovery_active)
659+ cxlflash_afu_sync(afu, ctxid, rhndl, AFU_HW_SYNC);
660+ break;
661+ default:
662+ WARN(1, "Unsupported LUN mode!");
663+ goto out;
664+ }
665+
666+ rhte_checkin(ctxi, rhte);
667+ cxlflash_lun_detach(gli);
668+
669+out:
670+ if (put_ctx)
671+ put_context(ctxi);
672+ dev_dbg(dev, "%s: returning rc=%d\n", __func__, rc);
673+ return rc;
674+}
675+
676+int cxlflash_disk_release(struct scsi_device *sdev,
677+ struct dk_cxlflash_release *release)
678+{
679+ return _cxlflash_disk_release(sdev, NULL, release);
680+}
681+
682+/**
683+ * destroy_context() - releases a context
684+ * @cfg: Internal structure associated with the host.
685+ * @ctxi: Context to release.
686+ *
687+ * Note that the rht_lun member of the context was cut from a single
688+ * allocation when the context was created and therefore does not need
689+ * to be explicitly freed. Also note that we conditionally check for the
690+ * existence of the context control map before clearing the RHT registers
691+ * and context capabilities because it is possible to destroy a context
692+ * while the context is in the error state (previous mapping was removed
693+ * [so we don't have to worry about clearing] and context is waiting for
694+ * a new mapping).
695+ */
696+static void destroy_context(struct cxlflash_cfg *cfg,
697+ struct ctx_info *ctxi)
698+{
699+ struct afu *afu = cfg->afu;
700+
701+ WARN_ON(!list_empty(&ctxi->luns));
702+
703+ /* Clear RHT registers and drop all capabilities for this context */
704+ if (afu->afu_map && ctxi->ctrl_map) {
705+ writeq_be(0, &ctxi->ctrl_map->rht_start);
706+ writeq_be(0, &ctxi->ctrl_map->rht_cnt_id);
707+ writeq_be(0, &ctxi->ctrl_map->ctx_cap);
708+ }
709+
710+ /* Free memory associated with context */
711+ free_page((ulong)ctxi->rht_start);
712+ kfree(ctxi->rht_needs_ws);
713+ kfree(ctxi->rht_lun);
714+ kfree(ctxi);
715+ atomic_dec_if_positive(&cfg->num_user_contexts);
716+}
717+
718+/**
719+ * create_context() - allocates and initializes a context
720+ * @cfg: Internal structure associated with the host.
721+ * @ctx: Previously obtained CXL context reference.
722+ * @ctxid: Previously obtained process element associated with CXL context.
723+ * @adap_fd: Previously obtained adapter fd associated with CXL context.
724+ * @file: Previously obtained file associated with CXL context.
725+ * @perms: User-specified permissions.
726+ *
727+ * The context's mutex is locked when an allocated context is returned.
728+ *
729+ * Return: Allocated context on success, NULL on failure
730+ */
731+static struct ctx_info *create_context(struct cxlflash_cfg *cfg,
732+ struct cxl_context *ctx, int ctxid,
733+ int adap_fd, struct file *file,
734+ u32 perms)
735+{
736+ struct device *dev = &cfg->dev->dev;
737+ struct afu *afu = cfg->afu;
738+ struct ctx_info *ctxi = NULL;
739+ struct llun_info **lli = NULL;
740+ bool *ws = NULL;
741+ struct sisl_rht_entry *rhte;
742+
743+ ctxi = kzalloc(sizeof(*ctxi), GFP_KERNEL);
744+ lli = kzalloc((MAX_RHT_PER_CONTEXT * sizeof(*lli)), GFP_KERNEL);
745+ ws = kzalloc((MAX_RHT_PER_CONTEXT * sizeof(*ws)), GFP_KERNEL);
746+ if (unlikely(!ctxi || !lli || !ws)) {
747+ dev_err(dev, "%s: Unable to allocate context!\n", __func__);
748+ goto err;
749+ }
750+
751+ rhte = (struct sisl_rht_entry *)get_zeroed_page(GFP_KERNEL);
752+ if (unlikely(!rhte)) {
753+ dev_err(dev, "%s: Unable to allocate RHT!\n", __func__);
754+ goto err;
755+ }
756+
757+ ctxi->rht_lun = lli;
758+ ctxi->rht_needs_ws = ws;
759+ ctxi->rht_start = rhte;
760+ ctxi->rht_perms = perms;
761+
762+ ctxi->ctrl_map = &afu->afu_map->ctrls[ctxid].ctrl;
763+ ctxi->ctxid = ENCODE_CTXID(ctxi, ctxid);
764+ ctxi->lfd = adap_fd;
765+ ctxi->pid = current->tgid; /* tgid = pid */
766+ ctxi->ctx = ctx;
767+ ctxi->file = file;
768+ mutex_init(&ctxi->mutex);
769+ INIT_LIST_HEAD(&ctxi->luns);
770+ INIT_LIST_HEAD(&ctxi->list); /* initialize for list_empty() */
771+
772+ atomic_inc(&cfg->num_user_contexts);
773+ mutex_lock(&ctxi->mutex);
774+out:
775+ return ctxi;
776+
777+err:
778+ kfree(ws);
779+ kfree(lli);
780+ kfree(ctxi);
781+ ctxi = NULL;
782+ goto out;
783+}
784+
785+/**
786+ * _cxlflash_disk_detach() - detaches a LUN from a context
787+ * @sdev: SCSI device associated with LUN.
788+ * @ctxi: Context owning resources.
789+ * @detach: Detach ioctl data structure.
790+ *
791+ * As part of the detach, all per-context resources associated with the LUN
792+ * are cleaned up. When detaching the last LUN for a context, the context
793+ * itself is cleaned up and released.
794+ *
795+ * Return: 0 on success, -errno on failure
796+ */
797+static int _cxlflash_disk_detach(struct scsi_device *sdev,
798+ struct ctx_info *ctxi,
799+ struct dk_cxlflash_detach *detach)
800+{
801+ struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)sdev->host->hostdata;
802+ struct device *dev = &cfg->dev->dev;
803+ struct llun_info *lli = sdev->hostdata;
804+ struct lun_access *lun_access, *t;
805+ struct dk_cxlflash_release rel;
806+ bool put_ctx = false;
807+
808+ int i;
809+ int rc = 0;
810+ int lfd;
811+ u64 ctxid = DECODE_CTXID(detach->context_id),
812+ rctxid = detach->context_id;
813+
814+ dev_dbg(dev, "%s: ctxid=%llu\n", __func__, ctxid);
815+
816+ if (!ctxi) {
817+ ctxi = get_context(cfg, rctxid, lli, CTX_CTRL_ERR_FALLBACK);
818+ if (unlikely(!ctxi)) {
819+ dev_dbg(dev, "%s: Bad context! (%llu)\n",
820+ __func__, ctxid);
821+ rc = -EINVAL;
822+ goto out;
823+ }
824+
825+ put_ctx = true;
826+ }
827+
828+ /* Cleanup outstanding resources tied to this LUN */
829+ if (ctxi->rht_out) {
830+ marshal_det_to_rele(detach, &rel);
831+ for (i = 0; i < MAX_RHT_PER_CONTEXT; i++) {
832+ if (ctxi->rht_lun[i] == lli) {
833+ rel.rsrc_handle = i;
834+ _cxlflash_disk_release(sdev, ctxi, &rel);
835+ }
836+
837+ /* No need to loop further if we're done */
838+ if (ctxi->rht_out == 0)
839+ break;
840+ }
841+ }
842+
843+ /* Take our LUN out of context, free the node */
844+ list_for_each_entry_safe(lun_access, t, &ctxi->luns, list)
845+ if (lun_access->lli == lli) {
846+ list_del(&lun_access->list);
847+ kfree(lun_access);
848+ lun_access = NULL;
849+ break;
850+ }
851+
852+ /* Tear down context following last LUN cleanup */
853+ if (list_empty(&ctxi->luns)) {
854+ ctxi->unavail = true;
855+ mutex_unlock(&ctxi->mutex);
856+ mutex_lock(&cfg->ctx_tbl_list_mutex);
857+ mutex_lock(&ctxi->mutex);
858+
859+ /* Might not have been in error list so conditionally remove */
860+ if (!list_empty(&ctxi->list))
861+ list_del(&ctxi->list);
862+ cfg->ctx_tbl[ctxid] = NULL;
863+ mutex_unlock(&cfg->ctx_tbl_list_mutex);
864+ mutex_unlock(&ctxi->mutex);
865+
866+ lfd = ctxi->lfd;
867+ destroy_context(cfg, ctxi);
868+ ctxi = NULL;
869+ put_ctx = false;
870+
871+ /*
872+ * As a last step, clean up external resources when not
873+ * already on an external cleanup thread, i.e.: close(adap_fd).
874+ *
875+ * NOTE: this will free up the context from the CXL services,
876+ * allowing it to dole out the same context_id on a future
877+ * (or even currently in-flight) disk_attach operation.
878+ */
879+ if (lfd != -1)
880+ sys_close(lfd);
881+ }
882+
883+out:
884+ if (put_ctx)
885+ put_context(ctxi);
886+ dev_dbg(dev, "%s: returning rc=%d\n", __func__, rc);
887+ return rc;
888+}
889+
890+static int cxlflash_disk_detach(struct scsi_device *sdev,
891+ struct dk_cxlflash_detach *detach)
892+{
893+ return _cxlflash_disk_detach(sdev, NULL, detach);
894+}
895+
896+/**
897+ * cxlflash_cxl_release() - release handler for adapter file descriptor
898+ * @inode: File-system inode associated with fd.
899+ * @file: File installed with adapter file descriptor.
900+ *
901+ * This routine is the release handler for the fops registered with
902+ * the CXL services on an initial attach for a context. It is called
903+ * when a close is performed on the adapter file descriptor returned
904+ * to the user. Programmatically, the user is not required to perform
905+ * the close, as it is handled internally via the detach ioctl when
906+ * a context is being removed. Note that nothing prevents the user
907+ * from performing a close, but the user should be aware that doing
908+ * so is considered catastrophic and subsequent usage of the superpipe
909+ * API with previously saved off tokens will fail.
910+ *
911+ * When initiated from an external close (either by the user or via
912+ * a process tear down), the routine derives the context reference
913+ * and calls detach for each LUN associated with the context. The
914+ * final detach operation will cause the context itself to be freed.
915+ * Note that the saved off lfd is reset prior to calling detach to
916+ * signify that the final detach should not perform a close.
917+ *
918+ * When initiated from a detach operation as part of the tear down
919+ * of a context, the context is first completely freed and then the
920+ * close is performed. This routine will fail to derive the context
921+ * reference (due to the context having already been freed) and then
922+ * call into the CXL release entry point.
923+ *
924+ * Thus, with exception to when the CXL process element (context id)
925+ * lookup fails (a case that should theoretically never occur), every
926+ * call into this routine results in a complete freeing of a context.
927+ *
928+ * As part of the detach, all per-context resources associated with the LUN
929+ * are cleaned up. When detaching the last LUN for a context, the context
930+ * itself is cleaned up and released.
931+ *
932+ * Return: 0 on success
933+ */
934+static int cxlflash_cxl_release(struct inode *inode, struct file *file)
935+{
936+ struct cxl_context *ctx = cxl_fops_get_context(file);
937+ struct cxlflash_cfg *cfg = container_of(file->f_op, struct cxlflash_cfg,
938+ cxl_fops);
939+ struct device *dev = &cfg->dev->dev;
940+ struct ctx_info *ctxi = NULL;
941+ struct dk_cxlflash_detach detach = { { 0 }, 0 };
942+ struct lun_access *lun_access, *t;
943+ enum ctx_ctrl ctrl = CTX_CTRL_ERR_FALLBACK | CTX_CTRL_FILE;
944+ int ctxid;
945+
946+ ctxid = cxl_process_element(ctx);
947+ if (unlikely(ctxid < 0)) {
948+ dev_err(dev, "%s: Context %p was closed! (%d)\n",
949+ __func__, ctx, ctxid);
950+ goto out;
951+ }
952+
953+ ctxi = get_context(cfg, ctxid, file, ctrl);
954+ if (unlikely(!ctxi)) {
955+ ctxi = get_context(cfg, ctxid, file, ctrl | CTX_CTRL_CLONE);
956+ if (!ctxi) {
957+ dev_dbg(dev, "%s: Context %d already free!\n",
958+ __func__, ctxid);
959+ goto out_release;
960+ }
961+
962+ dev_dbg(dev, "%s: Another process owns context %d!\n",
963+ __func__, ctxid);
964+ put_context(ctxi);
965+ goto out;
966+ }
967+
968+ dev_dbg(dev, "%s: close(%d) for context %d\n",
969+ __func__, ctxi->lfd, ctxid);
970+
971+ /* Reset the file descriptor to indicate we're on a close() thread */
972+ ctxi->lfd = -1;
973+ detach.context_id = ctxi->ctxid;
974+ list_for_each_entry_safe(lun_access, t, &ctxi->luns, list)
975+ _cxlflash_disk_detach(lun_access->sdev, ctxi, &detach);
976+out_release:
977+ cxl_fd_release(inode, file);
978+out:
979+ dev_dbg(dev, "%s: returning\n", __func__);
980+ return 0;
981+}
982+
983+/**
984+ * unmap_context() - clears a previously established mapping
985+ * @ctxi: Context owning the mapping.
986+ *
987+ * This routine is used to switch between the error notification page
988+ * (dummy page of all 1's) and the real mapping (established by the CXL
989+ * fault handler).
990+ */
991+static void unmap_context(struct ctx_info *ctxi)
992+{
993+ unmap_mapping_range(ctxi->file->f_mapping, 0, 0, 1);
994+}
995+
996+/**
997+ * get_err_page() - obtains and allocates the error notification page
998+ *
999+ * Return: error notification page on success, NULL on failure
1000+ */
1001+static struct page *get_err_page(void)
1002+{
1003+ struct page *err_page = global.err_page;
1004+
1005+ if (unlikely(!err_page)) {
1006+ err_page = alloc_page(GFP_KERNEL);
1007+ if (unlikely(!err_page)) {
1008+ pr_err("%s: Unable to allocate err_page!\n", __func__);
1009+ goto out;
1010+ }
1011+
1012+ memset(page_address(err_page), -1, PAGE_SIZE);
1013+
1014+ /* Serialize update w/ other threads to avoid a leak */
1015+ mutex_lock(&global.mutex);
1016+ if (likely(!global.err_page))
1017+ global.err_page = err_page;
1018+ else {
1019+ __free_page(err_page);
1020+ err_page = global.err_page;
1021+ }
1022+ mutex_unlock(&global.mutex);
1023+ }
1024+
1025+out:
1026+ pr_debug("%s: returning err_page=%p\n", __func__, err_page);
1027+ return err_page;
1028+}
1029+
1030+/**
1031+ * cxlflash_mmap_fault() - mmap fault handler for adapter file descriptor
1032+ * @vma: VM area associated with mapping.
1033+ * @vmf: VM fault associated with current fault.
1034+ *
1035+ * To support error notification via MMIO, faults are 'caught' by this routine
1036+ * that was inserted before passing back the adapter file descriptor on attach.
1037+ * When a fault occurs, this routine evaluates if error recovery is active and
1038+ * if so, installs the error page to 'notify' the user about the error state.
1039+ * During normal operation, the fault is simply handled by the original fault
1040+ * handler that was installed by CXL services as part of initializing the
1041+ * adapter file descriptor. The VMA's page protection bits are toggled to
1042+ * indicate cached/not-cached depending on the memory backing the fault.
1043+ *
1044+ * Return: 0 on success, VM_FAULT_SIGBUS on failure
1045+ */
1046+static int cxlflash_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
1047+{
1048+ struct file *file = vma->vm_file;
1049+ struct cxl_context *ctx = cxl_fops_get_context(file);
1050+ struct cxlflash_cfg *cfg = container_of(file->f_op, struct cxlflash_cfg,
1051+ cxl_fops);
1052+ struct device *dev = &cfg->dev->dev;
1053+ struct ctx_info *ctxi = NULL;
1054+ struct page *err_page = NULL;
1055+ enum ctx_ctrl ctrl = CTX_CTRL_ERR_FALLBACK | CTX_CTRL_FILE;
1056+ int rc = 0;
1057+ int ctxid;
1058+
1059+ ctxid = cxl_process_element(ctx);
1060+ if (unlikely(ctxid < 0)) {
1061+ dev_err(dev, "%s: Context %p was closed! (%d)\n",
1062+ __func__, ctx, ctxid);
1063+ goto err;
1064+ }
1065+
1066+ ctxi = get_context(cfg, ctxid, file, ctrl);
1067+ if (unlikely(!ctxi)) {
1068+ dev_dbg(dev, "%s: Bad context! (%d)\n", __func__, ctxid);
1069+ goto err;
1070+ }
1071+
1072+ dev_dbg(dev, "%s: fault(%d) for context %d\n",
1073+ __func__, ctxi->lfd, ctxid);
1074+
1075+ if (likely(!ctxi->err_recovery_active)) {
1076+ vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
1077+ rc = ctxi->cxl_mmap_vmops->fault(vma, vmf);
1078+ } else {
1079+ dev_dbg(dev, "%s: err recovery active, use err_page!\n",
1080+ __func__);
1081+
1082+ err_page = get_err_page();
1083+ if (unlikely(!err_page)) {
1084+ dev_err(dev, "%s: Could not obtain error page!\n",
1085+ __func__);
1086+ rc = VM_FAULT_RETRY;
1087+ goto out;
1088+ }
1089+
1090+ get_page(err_page);
1091+ vmf->page = err_page;
1092+ vma->vm_page_prot = pgprot_cached(vma->vm_page_prot);
1093+ }
1094+
1095+out:
1096+ if (likely(ctxi))
1097+ put_context(ctxi);
1098+ dev_dbg(dev, "%s: returning rc=%d\n", __func__, rc);
1099+ return rc;
1100+
1101+err:
1102+ rc = VM_FAULT_SIGBUS;
1103+ goto out;
1104+}
1105+
1106+/*
1107+ * Local MMAP vmops to 'catch' faults
1108+ */
1109+static const struct vm_operations_struct cxlflash_mmap_vmops = {
1110+ .fault = cxlflash_mmap_fault,
1111+};
1112+
1113+/**
1114+ * cxlflash_cxl_mmap() - mmap handler for adapter file descriptor
1115+ * @file: File installed with adapter file descriptor.
1116+ * @vma: VM area associated with mapping.
1117+ *
1118+ * Installs local mmap vmops to 'catch' faults for error notification support.
1119+ *
1120+ * Return: 0 on success, -errno on failure
1121+ */
1122+static int cxlflash_cxl_mmap(struct file *file, struct vm_area_struct *vma)
1123+{
1124+ struct cxl_context *ctx = cxl_fops_get_context(file);
1125+ struct cxlflash_cfg *cfg = container_of(file->f_op, struct cxlflash_cfg,
1126+ cxl_fops);
1127+ struct device *dev = &cfg->dev->dev;
1128+ struct ctx_info *ctxi = NULL;
1129+ enum ctx_ctrl ctrl = CTX_CTRL_ERR_FALLBACK | CTX_CTRL_FILE;
1130+ int ctxid;
1131+ int rc = 0;
1132+
1133+ ctxid = cxl_process_element(ctx);
1134+ if (unlikely(ctxid < 0)) {
1135+ dev_err(dev, "%s: Context %p was closed! (%d)\n",
1136+ __func__, ctx, ctxid);
1137+ rc = -EIO;
1138+ goto out;
1139+ }
1140+
1141+ ctxi = get_context(cfg, ctxid, file, ctrl);
1142+ if (unlikely(!ctxi)) {
1143+ dev_dbg(dev, "%s: Bad context! (%d)\n", __func__, ctxid);
1144+ rc = -EIO;
1145+ goto out;
1146+ }
1147+
1148+ dev_dbg(dev, "%s: mmap(%d) for context %d\n",
1149+ __func__, ctxi->lfd, ctxid);
1150+
1151+ rc = cxl_fd_mmap(file, vma);
1152+ if (likely(!rc)) {
1153+ /* Insert ourself in the mmap fault handler path */
1154+ ctxi->cxl_mmap_vmops = vma->vm_ops;
1155+ vma->vm_ops = &cxlflash_mmap_vmops;
1156+ }
1157+
1158+out:
1159+ if (likely(ctxi))
1160+ put_context(ctxi);
1161+ return rc;
1162+}
1163+
1164+/*
1165+ * Local fops for adapter file descriptor
1166+ */
1167+static const struct file_operations cxlflash_cxl_fops = {
1168+ .owner = THIS_MODULE,
1169+ .mmap = cxlflash_cxl_mmap,
1170+ .release = cxlflash_cxl_release,
1171+};
1172+
1173+/**
1174+ * cxlflash_mark_contexts_error() - move contexts to error state and list
1175+ * @cfg: Internal structure associated with the host.
1176+ *
1177+ * A context is only moved over to the error list when there are no outstanding
1178+ * references to it. This ensures that a running operation has completed.
1179+ *
1180+ * Return: 0 on success, -errno on failure
1181+ */
1182+int cxlflash_mark_contexts_error(struct cxlflash_cfg *cfg)
1183+{
1184+ int i, rc = 0;
1185+ struct ctx_info *ctxi = NULL;
1186+
1187+ mutex_lock(&cfg->ctx_tbl_list_mutex);
1188+
1189+ for (i = 0; i < MAX_CONTEXT; i++) {
1190+ ctxi = cfg->ctx_tbl[i];
1191+ if (ctxi) {
1192+ mutex_lock(&ctxi->mutex);
1193+ cfg->ctx_tbl[i] = NULL;
1194+ list_add(&ctxi->list, &cfg->ctx_err_recovery);
1195+ ctxi->err_recovery_active = true;
1196+ ctxi->ctrl_map = NULL;
1197+ unmap_context(ctxi);
1198+ mutex_unlock(&ctxi->mutex);
1199+ }
1200+ }
1201+
1202+ mutex_unlock(&cfg->ctx_tbl_list_mutex);
1203+ return rc;
1204+}
1205+
1206+/*
1207+ * Dummy NULL fops
1208+ */
1209+static const struct file_operations null_fops = {
1210+ .owner = THIS_MODULE,
1211+};
1212+
1213+/**
1214+ * cxlflash_disk_attach() - attach a LUN to a context
1215+ * @sdev: SCSI device associated with LUN.
1216+ * @attach: Attach ioctl data structure.
1217+ *
1218+ * Creates a context and attaches LUN to it. A LUN can only be attached
1219+ * one time to a context (subsequent attaches for the same context/LUN pair
1220+ * are not supported). Additional LUNs can be attached to a context by
1221+ * specifying the 'reuse' flag defined in the cxlflash_ioctl.h header.
1222+ *
1223+ * Return: 0 on success, -errno on failure
1224+ */
1225+static int cxlflash_disk_attach(struct scsi_device *sdev,
1226+ struct dk_cxlflash_attach *attach)
1227+{
1228+ struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)sdev->host->hostdata;
1229+ struct device *dev = &cfg->dev->dev;
1230+ struct afu *afu = cfg->afu;
1231+ struct llun_info *lli = sdev->hostdata;
1232+ struct glun_info *gli = lli->parent;
1233+ struct cxl_ioctl_start_work *work;
1234+ struct ctx_info *ctxi = NULL;
1235+ struct lun_access *lun_access = NULL;
1236+ int rc = 0;
1237+ u32 perms;
1238+ int ctxid = -1;
1239+ u64 rctxid = 0UL;
1240+ struct file *file;
1241+
1242+ struct cxl_context *ctx;
1243+
1244+ int fd = -1;
1245+
1246+ /* On first attach set fileops */
1247+ if (atomic_read(&cfg->num_user_contexts) == 0)
1248+ cfg->cxl_fops = cxlflash_cxl_fops;
1249+
1250+ if (attach->num_interrupts > 4) {
1251+ dev_dbg(dev, "%s: Cannot support this many interrupts %llu\n",
1252+ __func__, attach->num_interrupts);
1253+ rc = -EINVAL;
1254+ goto out;
1255+ }
1256+
1257+ if (gli->max_lba == 0) {
1258+ dev_dbg(dev, "%s: No capacity info for this LUN (%016llX)\n",
1259+ __func__, lli->lun_id[sdev->channel]);
1260+ rc = read_cap16(sdev, lli);
1261+ if (rc) {
1262+ dev_err(dev, "%s: Invalid device! (%d)\n",
1263+ __func__, rc);
1264+ rc = -ENODEV;
1265+ goto out;
1266+ }
1267+ dev_dbg(dev, "%s: LBA = %016llX\n", __func__, gli->max_lba);
1268+ dev_dbg(dev, "%s: BLK_LEN = %08X\n", __func__, gli->blk_len);
1269+ }
1270+
1271+ if (attach->hdr.flags & DK_CXLFLASH_ATTACH_REUSE_CONTEXT) {
1272+ rctxid = attach->context_id;
1273+ ctxi = get_context(cfg, rctxid, NULL, 0);
1274+ if (!ctxi) {
1275+ dev_dbg(dev, "%s: Bad context! (%016llX)\n",
1276+ __func__, rctxid);
1277+ rc = -EINVAL;
1278+ goto out;
1279+ }
1280+
1281+ list_for_each_entry(lun_access, &ctxi->luns, list)
1282+ if (lun_access->lli == lli) {
1283+ dev_dbg(dev, "%s: Already attached!\n",
1284+ __func__);
1285+ rc = -EINVAL;
1286+ goto out;
1287+ }
1288+ }
1289+
1290+ lun_access = kzalloc(sizeof(*lun_access), GFP_KERNEL);
1291+ if (unlikely(!lun_access)) {
1292+ dev_err(dev, "%s: Unable to allocate lun_access!\n", __func__);
1293+ rc = -ENOMEM;
1294+ goto out;
1295+ }
1296+
1297+ lun_access->lli = lli;
1298+ lun_access->sdev = sdev;
1299+
1300+ /* Non-NULL context indicates reuse */
1301+ if (ctxi) {
1302+ dev_dbg(dev, "%s: Reusing context for LUN! (%016llX)\n",
1303+ __func__, rctxid);
1304+ list_add(&lun_access->list, &ctxi->luns);
1305+ fd = ctxi->lfd;
1306+ goto out_attach;
1307+ }
1308+
1309+ ctx = cxl_dev_context_init(cfg->dev);
1310+ if (unlikely(IS_ERR_OR_NULL(ctx))) {
1311+ dev_err(dev, "%s: Could not initialize context %p\n",
1312+ __func__, ctx);
1313+ rc = -ENODEV;
1314+ goto err0;
1315+ }
1316+
1317+ ctxid = cxl_process_element(ctx);
1318+ if (unlikely((ctxid > MAX_CONTEXT) || (ctxid < 0))) {
1319+ dev_err(dev, "%s: ctxid (%d) invalid!\n", __func__, ctxid);
1320+ rc = -EPERM;
1321+ goto err1;
1322+ }
1323+
1324+ file = cxl_get_fd(ctx, &cfg->cxl_fops, &fd);
1325+ if (unlikely(fd < 0)) {
1326+ rc = -ENODEV;
1327+ dev_err(dev, "%s: Could not get file descriptor\n", __func__);
1328+ goto err1;
1329+ }
1330+
1331+ /* Translate read/write O_* flags from fcntl.h to AFU permission bits */
1332+ perms = SISL_RHT_PERM(attach->hdr.flags + 1);
1333+
1334+ ctxi = create_context(cfg, ctx, ctxid, fd, file, perms);
1335+ if (unlikely(!ctxi)) {
1336+ dev_err(dev, "%s: Failed to create context! (%d)\n",
1337+ __func__, ctxid);
1338+ goto err2;
1339+ }
1340+
1341+ work = &ctxi->work;
1342+ work->num_interrupts = attach->num_interrupts;
1343+ work->flags = CXL_START_WORK_NUM_IRQS;
1344+
1345+ rc = cxl_start_work(ctx, work);
1346+ if (unlikely(rc)) {
1347+ dev_dbg(dev, "%s: Could not start context rc=%d\n",
1348+ __func__, rc);
1349+ goto err3;
1350+ }
1351+
1352+ rc = afu_attach(cfg, ctxi);
1353+ if (unlikely(rc)) {
1354+ dev_err(dev, "%s: Could not attach AFU rc %d\n", __func__, rc);
1355+ goto err4;
1356+ }
1357+
1358+ /*
1359+ * No error paths after this point. Once the fd is installed it's
1360+ * visible to user space and can't be undone safely on this thread.
1361+ * There is no need to worry about a deadlock here because no one
1362+ * knows about us yet; we can be the only one holding our mutex.
1363+ */
1364+ list_add(&lun_access->list, &ctxi->luns);
1365+ mutex_unlock(&ctxi->mutex);
1366+ mutex_lock(&cfg->ctx_tbl_list_mutex);
1367+ mutex_lock(&ctxi->mutex);
1368+ cfg->ctx_tbl[ctxid] = ctxi;
1369+ mutex_unlock(&cfg->ctx_tbl_list_mutex);
1370+ fd_install(fd, file);
1371+
1372+out_attach:
1373+ attach->hdr.return_flags = 0;
1374+ attach->context_id = ctxi->ctxid;
1375+ attach->block_size = gli->blk_len;
1376+ attach->mmio_size = sizeof(afu->afu_map->hosts[0].harea);
1377+ attach->last_lba = gli->max_lba;
1378+ attach->max_xfer = (sdev->host->max_sectors * 512) / gli->blk_len;
1379+
1380+out:
1381+ attach->adap_fd = fd;
1382+
1383+ if (ctxi)
1384+ put_context(ctxi);
1385+
1386+ dev_dbg(dev, "%s: returning ctxid=%d fd=%d bs=%lld rc=%d llba=%lld\n",
1387+ __func__, ctxid, fd, attach->block_size, rc, attach->last_lba);
1388+ return rc;
1389+
1390+err4:
1391+ cxl_stop_context(ctx);
1392+err3:
1393+ put_context(ctxi);
1394+ destroy_context(cfg, ctxi);
1395+ ctxi = NULL;
1396+err2:
1397+ /*
1398+ * Here, we're overriding the fops with a dummy all-NULL fops because
1399+ * fput() calls the release fop, which will cause us to mistakenly
1400+ * call into the CXL code. Rather than try to add yet more complexity
1401+ * to that routine (cxlflash_cxl_release) we should try to fix the
1402+ * issue here.
1403+ */
1404+ file->f_op = &null_fops;
1405+ fput(file);
1406+ put_unused_fd(fd);
1407+ fd = -1;
1408+err1:
1409+ cxl_release_context(ctx);
1410+err0:
1411+ kfree(lun_access);
1412+ goto out;
1413+}
1414+
1415+/**
1416+ * recover_context() - recovers a context in error
1417+ * @cfg: Internal structure associated with the host.
1418+ * @ctxi: Context to release.
1419+ *
1420+ * Restablishes the state for a context-in-error.
1421+ *
1422+ * Return: 0 on success, -errno on failure
1423+ */
1424+static int recover_context(struct cxlflash_cfg *cfg, struct ctx_info *ctxi)
1425+{
1426+ struct device *dev = &cfg->dev->dev;
1427+ int rc = 0;
1428+ int old_fd, fd = -1;
1429+ int ctxid = -1;
1430+ struct file *file;
1431+ struct cxl_context *ctx;
1432+ struct afu *afu = cfg->afu;
1433+
1434+ ctx = cxl_dev_context_init(cfg->dev);
1435+ if (unlikely(IS_ERR_OR_NULL(ctx))) {
1436+ dev_err(dev, "%s: Could not initialize context %p\n",
1437+ __func__, ctx);
1438+ rc = -ENODEV;
1439+ goto out;
1440+ }
1441+
1442+ ctxid = cxl_process_element(ctx);
1443+ if (unlikely((ctxid > MAX_CONTEXT) || (ctxid < 0))) {
1444+ dev_err(dev, "%s: ctxid (%d) invalid!\n", __func__, ctxid);
1445+ rc = -EPERM;
1446+ goto err1;
1447+ }
1448+
1449+ file = cxl_get_fd(ctx, &cfg->cxl_fops, &fd);
1450+ if (unlikely(fd < 0)) {
1451+ rc = -ENODEV;
1452+ dev_err(dev, "%s: Could not get file descriptor\n", __func__);
1453+ goto err1;
1454+ }
1455+
1456+ rc = cxl_start_work(ctx, &ctxi->work);
1457+ if (unlikely(rc)) {
1458+ dev_dbg(dev, "%s: Could not start context rc=%d\n",
1459+ __func__, rc);
1460+ goto err2;
1461+ }
1462+
1463+ /* Update with new MMIO area based on updated context id */
1464+ ctxi->ctrl_map = &afu->afu_map->ctrls[ctxid].ctrl;
1465+
1466+ rc = afu_attach(cfg, ctxi);
1467+ if (rc) {
1468+ dev_err(dev, "%s: Could not attach AFU rc %d\n", __func__, rc);
1469+ goto err3;
1470+ }
1471+
1472+ /*
1473+ * No error paths after this point. Once the fd is installed it's
1474+ * visible to user space and can't be undone safely on this thread.
1475+ */
1476+ old_fd = ctxi->lfd;
1477+ ctxi->ctxid = ENCODE_CTXID(ctxi, ctxid);
1478+ ctxi->lfd = fd;
1479+ ctxi->ctx = ctx;
1480+ ctxi->file = file;
1481+
1482+ /*
1483+ * Put context back in table (note the reinit of the context list);
1484+ * we must first drop the context's mutex and then acquire it in
1485+ * order with the table/list mutex to avoid a deadlock - safe to do
1486+ * here because no one can find us at this moment in time.
1487+ */
1488+ mutex_unlock(&ctxi->mutex);
1489+ mutex_lock(&cfg->ctx_tbl_list_mutex);
1490+ mutex_lock(&ctxi->mutex);
1491+ list_del_init(&ctxi->list);
1492+ cfg->ctx_tbl[ctxid] = ctxi;
1493+ mutex_unlock(&cfg->ctx_tbl_list_mutex);
1494+ fd_install(fd, file);
1495+
1496+ /* Release the original adapter fd and associated CXL resources */
1497+ sys_close(old_fd);
1498+out:
1499+ dev_dbg(dev, "%s: returning ctxid=%d fd=%d rc=%d\n",
1500+ __func__, ctxid, fd, rc);
1501+ return rc;
1502+
1503+err3:
1504+ cxl_stop_context(ctx);
1505+err2:
1506+ fput(file);
1507+ put_unused_fd(fd);
1508+err1:
1509+ cxl_release_context(ctx);
1510+ goto out;
1511+}
1512+
1513+/**
1514+ * check_state() - checks and responds to the current adapter state
1515+ * @cfg: Internal structure associated with the host.
1516+ *
1517+ * This routine can block and should only be used on process context.
1518+ * Note that when waking up from waiting in limbo, the state is unknown
1519+ * and must be checked again before proceeding.
1520+ *
1521+ * Return: 0 on success, -errno on failure
1522+ */
1523+static int check_state(struct cxlflash_cfg *cfg)
1524+{
1525+ struct device *dev = &cfg->dev->dev;
1526+ int rc = 0;
1527+
1528+retry:
1529+ switch (cfg->state) {
1530+ case STATE_LIMBO:
1531+ dev_dbg(dev, "%s: Limbo, going to wait...\n", __func__);
1532+ rc = wait_event_interruptible(cfg->limbo_waitq,
1533+ cfg->state != STATE_LIMBO);
1534+ if (unlikely(rc))
1535+ break;
1536+ goto retry;
1537+ case STATE_FAILTERM:
1538+ dev_dbg(dev, "%s: Failed/Terminating!\n", __func__);
1539+ rc = -ENODEV;
1540+ break;
1541+ default:
1542+ break;
1543+ }
1544+
1545+ return rc;
1546+}
1547+
1548+/**
1549+ * cxlflash_afu_recover() - initiates AFU recovery
1550+ * @sdev: SCSI device associated with LUN.
1551+ * @recover: Recover ioctl data structure.
1552+ *
1553+ * Only a single recovery is allowed at a time to avoid exhausting CXL
1554+ * resources (leading to recovery failure) in the event that we're up
1555+ * against the maximum number of contexts limit. For similar reasons,
1556+ * a context recovery is retried if there are multiple recoveries taking
1557+ * place at the same time and the failure was due to CXL services being
1558+ * unable to keep up.
1559+ *
1560+ * Because a user can detect an error condition before the kernel, it is
1561+ * quite possible for this routine to act as the kernel's EEH detection
1562+ * source (MMIO read of mbox_r). Because of this, there is a window of
1563+ * time where an EEH might have been detected but not yet 'serviced'
1564+ * (callback invoked, causing the device to enter limbo state). To avoid
1565+ * looping in this routine during that window, a 1 second sleep is in place
1566+ * between the time the MMIO failure is detected and the time a wait on the
1567+ * limbo wait queue is attempted via check_state().
1568+ *
1569+ * Return: 0 on success, -errno on failure
1570+ */
1571+static int cxlflash_afu_recover(struct scsi_device *sdev,
1572+ struct dk_cxlflash_recover_afu *recover)
1573+{
1574+ struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)sdev->host->hostdata;
1575+ struct device *dev = &cfg->dev->dev;
1576+ struct llun_info *lli = sdev->hostdata;
1577+ struct afu *afu = cfg->afu;
1578+ struct ctx_info *ctxi = NULL;
1579+ struct mutex *mutex = &cfg->ctx_recovery_mutex;
1580+ u64 ctxid = DECODE_CTXID(recover->context_id),
1581+ rctxid = recover->context_id;
1582+ long reg;
1583+ int lretry = 20; /* up to 2 seconds */
1584+ int rc = 0;
1585+
1586+ atomic_inc(&cfg->recovery_threads);
1587+ rc = mutex_lock_interruptible(mutex);
1588+ if (rc)
1589+ goto out;
1590+
1591+ dev_dbg(dev, "%s: reason 0x%016llX rctxid=%016llX\n",
1592+ __func__, recover->reason, rctxid);
1593+
1594+retry:
1595+ /* Ensure that this process is attached to the context */
1596+ ctxi = get_context(cfg, rctxid, lli, CTX_CTRL_ERR_FALLBACK);
1597+ if (unlikely(!ctxi)) {
1598+ dev_dbg(dev, "%s: Bad context! (%llu)\n", __func__, ctxid);
1599+ rc = -EINVAL;
1600+ goto out;
1601+ }
1602+
1603+ if (ctxi->err_recovery_active) {
1604+retry_recover:
1605+ rc = recover_context(cfg, ctxi);
1606+ if (unlikely(rc)) {
1607+ dev_err(dev, "%s: Recovery failed for context %llu (rc=%d)\n",
1608+ __func__, ctxid, rc);
1609+ if ((rc == -ENODEV) &&
1610+ ((atomic_read(&cfg->recovery_threads) > 1) ||
1611+ (lretry--))) {
1612+ dev_dbg(dev, "%s: Going to try again!\n",
1613+ __func__);
1614+ mutex_unlock(mutex);
1615+ msleep(100);
1616+ rc = mutex_lock_interruptible(mutex);
1617+ if (rc)
1618+ goto out;
1619+ goto retry_recover;
1620+ }
1621+
1622+ goto out;
1623+ }
1624+
1625+ ctxi->err_recovery_active = false;
1626+ recover->context_id = ctxi->ctxid;
1627+ recover->adap_fd = ctxi->lfd;
1628+ recover->mmio_size = sizeof(afu->afu_map->hosts[0].harea);
1629+ recover->hdr.return_flags |=
1630+ DK_CXLFLASH_RECOVER_AFU_CONTEXT_RESET;
1631+ goto out;
1632+ }
1633+
1634+ /* Test if in error state */
1635+ reg = readq_be(&afu->ctrl_map->mbox_r);
1636+ if (reg == -1) {
1637+ dev_dbg(dev, "%s: MMIO read fail! Wait for recovery...\n",
1638+ __func__);
1639+ mutex_unlock(&ctxi->mutex);
1640+ ctxi = NULL;
1641+ ssleep(1);
1642+ rc = check_state(cfg);
1643+ if (unlikely(rc))
1644+ goto out;
1645+ goto retry;
1646+ }
1647+
1648+ dev_dbg(dev, "%s: MMIO working, no recovery required!\n", __func__);
1649+out:
1650+ if (likely(ctxi))
1651+ put_context(ctxi);
1652+ mutex_unlock(mutex);
1653+ atomic_dec_if_positive(&cfg->recovery_threads);
1654+ return rc;
1655+}
1656+
1657+/**
1658+ * process_sense() - evaluates and processes sense data
1659+ * @sdev: SCSI device associated with LUN.
1660+ * @verify: Verify ioctl data structure.
1661+ *
1662+ * Return: 0 on success, -errno on failure
1663+ */
1664+static int process_sense(struct scsi_device *sdev,
1665+ struct dk_cxlflash_verify *verify)
1666+{
1667+ struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)sdev->host->hostdata;
1668+ struct device *dev = &cfg->dev->dev;
1669+ struct llun_info *lli = sdev->hostdata;
1670+ struct glun_info *gli = lli->parent;
1671+ u64 prev_lba = gli->max_lba;
1672+ struct scsi_sense_hdr sshdr = { 0 };
1673+ int rc = 0;
1674+
1675+ rc = scsi_normalize_sense((const u8 *)&verify->sense_data,
1676+ DK_CXLFLASH_VERIFY_SENSE_LEN, &sshdr);
1677+ if (!rc) {
1678+ dev_err(dev, "%s: Failed to normalize sense data!\n", __func__);
1679+ rc = -EINVAL;
1680+ goto out;
1681+ }
1682+
1683+ switch (sshdr.sense_key) {
1684+ case NO_SENSE:
1685+ case RECOVERED_ERROR:
1686+ /* fall through */
1687+ case NOT_READY:
1688+ break;
1689+ case UNIT_ATTENTION:
1690+ switch (sshdr.asc) {
1691+ case 0x29: /* Power on Reset or Device Reset */
1692+ /* fall through */
1693+ case 0x2A: /* Device settings/capacity changed */
1694+ rc = read_cap16(sdev, lli);
1695+ if (rc) {
1696+ rc = -ENODEV;
1697+ break;
1698+ }
1699+ if (prev_lba != gli->max_lba)
1700+ dev_dbg(dev, "%s: Capacity changed old=%lld "
1701+ "new=%lld\n", __func__, prev_lba,
1702+ gli->max_lba);
1703+ break;
1704+ case 0x3F: /* Report LUNs changed, Rescan. */
1705+ scsi_scan_host(cfg->host);
1706+ break;
1707+ default:
1708+ rc = -EIO;
1709+ break;
1710+ }
1711+ break;
1712+ default:
1713+ rc = -EIO;
1714+ break;
1715+ }
1716+out:
1717+ dev_dbg(dev, "%s: sense_key %x asc %x ascq %x rc %d\n", __func__,
1718+ sshdr.sense_key, sshdr.asc, sshdr.ascq, rc);
1719+ return rc;
1720+}
1721+
1722+/**
1723+ * cxlflash_disk_verify() - verifies a LUN is the same and handle size changes
1724+ * @sdev: SCSI device associated with LUN.
1725+ * @verify: Verify ioctl data structure.
1726+ *
1727+ * Return: 0 on success, -errno on failure
1728+ */
1729+static int cxlflash_disk_verify(struct scsi_device *sdev,
1730+ struct dk_cxlflash_verify *verify)
1731+{
1732+ int rc = 0;
1733+ struct ctx_info *ctxi = NULL;
1734+ struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)sdev->host->hostdata;
1735+ struct device *dev = &cfg->dev->dev;
1736+ struct llun_info *lli = sdev->hostdata;
1737+ struct glun_info *gli = lli->parent;
1738+ struct sisl_rht_entry *rhte = NULL;
1739+ res_hndl_t rhndl = verify->rsrc_handle;
1740+ u64 ctxid = DECODE_CTXID(verify->context_id),
1741+ rctxid = verify->context_id;
1742+ u64 last_lba = 0;
1743+
1744+ dev_dbg(dev, "%s: ctxid=%llu rhndl=%016llX, hint=%016llX, "
1745+ "flags=%016llX\n", __func__, ctxid, verify->rsrc_handle,
1746+ verify->hint, verify->hdr.flags);
1747+
1748+ ctxi = get_context(cfg, rctxid, lli, 0);
1749+ if (unlikely(!ctxi)) {
1750+ dev_dbg(dev, "%s: Bad context! (%llu)\n", __func__, ctxid);
1751+ rc = -EINVAL;
1752+ goto out;
1753+ }
1754+
1755+ rhte = get_rhte(ctxi, rhndl, lli);
1756+ if (unlikely(!rhte)) {
1757+ dev_dbg(dev, "%s: Bad resource handle! (%d)\n",
1758+ __func__, rhndl);
1759+ rc = -EINVAL;
1760+ goto out;
1761+ }
1762+
1763+ /*
1764+ * Look at the hint/sense to see if it requires us to redrive
1765+ * inquiry (i.e. the Unit attention is due to the WWN changing).
1766+ */
1767+ if (verify->hint & DK_CXLFLASH_VERIFY_HINT_SENSE) {
1768+ rc = process_sense(sdev, verify);
1769+ if (unlikely(rc)) {
1770+ dev_err(dev, "%s: Failed to validate sense data (%d)\n",
1771+ __func__, rc);
1772+ goto out;
1773+ }
1774+ }
1775+
1776+ switch (gli->mode) {
1777+ case MODE_PHYSICAL:
1778+ last_lba = gli->max_lba;
1779+ break;
1780+ case MODE_VIRTUAL:
1781+ /* Cast lxt_cnt to u64 for multiply to be treated as 64bit op */
1782+ last_lba = ((u64)rhte->lxt_cnt * MC_CHUNK_SIZE * gli->blk_len);
1783+ last_lba /= CXLFLASH_BLOCK_SIZE;
1784+ last_lba--;
1785+ break;
1786+ default:
1787+ WARN(1, "Unsupported LUN mode!");
1788+ }
1789+
1790+ verify->last_lba = last_lba;
1791+
1792+out:
1793+ if (likely(ctxi))
1794+ put_context(ctxi);
1795+ dev_dbg(dev, "%s: returning rc=%d llba=%llX\n",
1796+ __func__, rc, verify->last_lba);
1797+ return rc;
1798+}
1799+
1800+/**
1801+ * decode_ioctl() - translates an encoded ioctl to an easily identifiable string
1802+ * @cmd: The ioctl command to decode.
1803+ *
1804+ * Return: A string identifying the decoded ioctl.
1805+ */
1806+static char *decode_ioctl(int cmd)
1807+{
1808+ switch (cmd) {
1809+ case DK_CXLFLASH_ATTACH:
1810+ return __stringify_1(DK_CXLFLASH_ATTACH);
1811+ case DK_CXLFLASH_USER_DIRECT:
1812+ return __stringify_1(DK_CXLFLASH_USER_DIRECT);
1813+ case DK_CXLFLASH_USER_VIRTUAL:
1814+ return __stringify_1(DK_CXLFLASH_USER_VIRTUAL);
1815+ case DK_CXLFLASH_VLUN_RESIZE:
1816+ return __stringify_1(DK_CXLFLASH_VLUN_RESIZE);
1817+ case DK_CXLFLASH_RELEASE:
1818+ return __stringify_1(DK_CXLFLASH_RELEASE);
1819+ case DK_CXLFLASH_DETACH:
1820+ return __stringify_1(DK_CXLFLASH_DETACH);
1821+ case DK_CXLFLASH_VERIFY:
1822+ return __stringify_1(DK_CXLFLASH_VERIFY);
1823+ case DK_CXLFLASH_VLUN_CLONE:
1824+ return __stringify_1(DK_CXLFLASH_VLUN_CLONE);
1825+ case DK_CXLFLASH_RECOVER_AFU:
1826+ return __stringify_1(DK_CXLFLASH_RECOVER_AFU);
1827+ case DK_CXLFLASH_MANAGE_LUN:
1828+ return __stringify_1(DK_CXLFLASH_MANAGE_LUN);
1829+ }
1830+
1831+ return "UNKNOWN";
1832+}
1833+
1834+/**
1835+ * cxlflash_disk_direct_open() - opens a direct (physical) disk
1836+ * @sdev: SCSI device associated with LUN.
1837+ * @arg: UDirect ioctl data structure.
1838+ *
1839+ * On successful return, the user is informed of the resource handle
1840+ * to be used to identify the direct lun and the size (in blocks) of
1841+ * the direct lun in last LBA format.
1842+ *
1843+ * Return: 0 on success, -errno on failure
1844+ */
1845+static int cxlflash_disk_direct_open(struct scsi_device *sdev, void *arg)
1846+{
1847+ struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)sdev->host->hostdata;
1848+ struct device *dev = &cfg->dev->dev;
1849+ struct afu *afu = cfg->afu;
1850+ struct llun_info *lli = sdev->hostdata;
1851+ struct glun_info *gli = lli->parent;
1852+
1853+ struct dk_cxlflash_udirect *pphys = (struct dk_cxlflash_udirect *)arg;
1854+
1855+ u64 ctxid = DECODE_CTXID(pphys->context_id),
1856+ rctxid = pphys->context_id;
1857+ u64 lun_size = 0;
1858+ u64 last_lba = 0;
1859+ u64 rsrc_handle = -1;
1860+ u32 port = CHAN2PORT(sdev->channel);
1861+
1862+ int rc = 0;
1863+
1864+ struct ctx_info *ctxi = NULL;
1865+ struct sisl_rht_entry *rhte = NULL;
1866+
1867+ pr_debug("%s: ctxid=%llu ls=0x%llx\n", __func__, ctxid, lun_size);
1868+
1869+ rc = cxlflash_lun_attach(gli, MODE_PHYSICAL, false);
1870+ if (unlikely(rc)) {
1871+ dev_dbg(dev, "%s: Failed to attach to LUN! (PHYSICAL)\n",
1872+ __func__);
1873+ goto out;
1874+ }
1875+
1876+ ctxi = get_context(cfg, rctxid, lli, 0);
1877+ if (unlikely(!ctxi)) {
1878+ dev_dbg(dev, "%s: Bad context! (%llu)\n", __func__, ctxid);
1879+ rc = -EINVAL;
1880+ goto err1;
1881+ }
1882+
1883+ rhte = rhte_checkout(ctxi, lli);
1884+ if (unlikely(!rhte)) {
1885+ dev_dbg(dev, "%s: too many opens for this context\n", __func__);
1886+ rc = -EMFILE; /* too many opens */
1887+ goto err1;
1888+ }
1889+
1890+ rsrc_handle = (rhte - ctxi->rht_start);
1891+
1892+ rht_format1(rhte, lli->lun_id[sdev->channel], ctxi->rht_perms, port);
1893+ cxlflash_afu_sync(afu, ctxid, rsrc_handle, AFU_LW_SYNC);
1894+
1895+ last_lba = gli->max_lba;
1896+ pphys->hdr.return_flags = 0;
1897+ pphys->last_lba = last_lba;
1898+ pphys->rsrc_handle = rsrc_handle;
1899+
1900+out:
1901+ if (likely(ctxi))
1902+ put_context(ctxi);
1903+ dev_dbg(dev, "%s: returning handle 0x%llx rc=%d llba %lld\n",
1904+ __func__, rsrc_handle, rc, last_lba);
1905+ return rc;
1906+
1907+err1:
1908+ cxlflash_lun_detach(gli);
1909+ goto out;
1910+}
1911+
1912+/**
1913+ * ioctl_common() - common IOCTL handler for driver
1914+ * @sdev: SCSI device associated with LUN.
1915+ * @cmd: IOCTL command.
1916+ *
1917+ * Handles common fencing operations that are valid for multiple ioctls. Always
1918+ * allow through ioctls that are cleanup oriented in nature, even when operating
1919+ * in a failed/terminating state.
1920+ *
1921+ * Return: 0 on success, -errno on failure
1922+ */
1923+static int ioctl_common(struct scsi_device *sdev, int cmd)
1924+{
1925+ struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)sdev->host->hostdata;
1926+ struct device *dev = &cfg->dev->dev;
1927+ struct llun_info *lli = sdev->hostdata;
1928+ int rc = 0;
1929+
1930+ if (unlikely(!lli)) {
1931+ dev_dbg(dev, "%s: Unknown LUN\n", __func__);
1932+ rc = -EINVAL;
1933+ goto out;
1934+ }
1935+
1936+ rc = check_state(cfg);
1937+ if (unlikely(rc) && (cfg->state == STATE_FAILTERM)) {
1938+ switch (cmd) {
1939+ case DK_CXLFLASH_VLUN_RESIZE:
1940+ case DK_CXLFLASH_RELEASE:
1941+ case DK_CXLFLASH_DETACH:
1942+ dev_dbg(dev, "%s: Command override! (%d)\n",
1943+ __func__, rc);
1944+ rc = 0;
1945+ break;
1946+ }
1947+ }
1948+out:
1949+ return rc;
1950+}
1951+
1952+/**
1953+ * cxlflash_ioctl() - IOCTL handler for driver
1954+ * @sdev: SCSI device associated with LUN.
1955+ * @cmd: IOCTL command.
1956+ * @arg: Userspace ioctl data structure.
1957+ *
1958+ * Return: 0 on success, -errno on failure
1959+ */
1960+int cxlflash_ioctl(struct scsi_device *sdev, int cmd, void __user *arg)
1961+{
1962+ typedef int (*sioctl) (struct scsi_device *, void *);
1963+
1964+ struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)sdev->host->hostdata;
1965+ struct device *dev = &cfg->dev->dev;
1966+ struct afu *afu = cfg->afu;
1967+ struct dk_cxlflash_hdr *hdr;
1968+ char buf[sizeof(union cxlflash_ioctls)];
1969+ size_t size = 0;
1970+ bool known_ioctl = false;
1971+ int idx;
1972+ int rc = 0;
1973+ struct Scsi_Host *shost = sdev->host;
1974+ sioctl do_ioctl = NULL;
1975+
1976+ static const struct {
1977+ size_t size;
1978+ sioctl ioctl;
1979+ } ioctl_tbl[] = { /* NOTE: order matters here */
1980+ {sizeof(struct dk_cxlflash_attach), (sioctl)cxlflash_disk_attach},
1981+ {sizeof(struct dk_cxlflash_udirect), cxlflash_disk_direct_open},
1982+ {sizeof(struct dk_cxlflash_release), (sioctl)cxlflash_disk_release},
1983+ {sizeof(struct dk_cxlflash_detach), (sioctl)cxlflash_disk_detach},
1984+ {sizeof(struct dk_cxlflash_verify), (sioctl)cxlflash_disk_verify},
1985+ {sizeof(struct dk_cxlflash_recover_afu), (sioctl)cxlflash_afu_recover},
1986+ {sizeof(struct dk_cxlflash_manage_lun), (sioctl)cxlflash_manage_lun},
1987+ {sizeof(struct dk_cxlflash_uvirtual), cxlflash_disk_virtual_open},
1988+ {sizeof(struct dk_cxlflash_resize), (sioctl)cxlflash_vlun_resize},
1989+ {sizeof(struct dk_cxlflash_clone), (sioctl)cxlflash_disk_clone},
1990+ };
1991+
1992+ /* Restrict command set to physical support only for internal LUN */
1993+ if (afu->internal_lun)
1994+ switch (cmd) {
1995+ case DK_CXLFLASH_RELEASE:
1996+ case DK_CXLFLASH_USER_VIRTUAL:
1997+ case DK_CXLFLASH_VLUN_RESIZE:
1998+ case DK_CXLFLASH_VLUN_CLONE:
1999+ dev_dbg(dev, "%s: %s not supported for lun_mode=%d\n",
2000+ __func__, decode_ioctl(cmd), afu->internal_lun);
2001+ rc = -EINVAL;
2002+ goto cxlflash_ioctl_exit;
2003+ }
2004+
2005+ switch (cmd) {
2006+ case DK_CXLFLASH_ATTACH:
2007+ case DK_CXLFLASH_USER_DIRECT:
2008+ case DK_CXLFLASH_RELEASE:
2009+ case DK_CXLFLASH_DETACH:
2010+ case DK_CXLFLASH_VERIFY:
2011+ case DK_CXLFLASH_RECOVER_AFU:
2012+ case DK_CXLFLASH_USER_VIRTUAL:
2013+ case DK_CXLFLASH_VLUN_RESIZE:
2014+ case DK_CXLFLASH_VLUN_CLONE:
2015+ dev_dbg(dev, "%s: %s (%08X) on dev(%d/%d/%d/%llu)\n",
2016+ __func__, decode_ioctl(cmd), cmd, shost->host_no,
2017+ sdev->channel, sdev->id, sdev->lun);
2018+ rc = ioctl_common(sdev, cmd);
2019+ if (unlikely(rc))
2020+ goto cxlflash_ioctl_exit;
2021+
2022+ /* fall through */
2023+
2024+ case DK_CXLFLASH_MANAGE_LUN:
2025+ known_ioctl = true;
2026+ idx = _IOC_NR(cmd) - _IOC_NR(DK_CXLFLASH_ATTACH);
2027+ size = ioctl_tbl[idx].size;
2028+ do_ioctl = ioctl_tbl[idx].ioctl;
2029+
2030+ if (likely(do_ioctl))
2031+ break;
2032+
2033+ /* fall through */
2034+ default:
2035+ rc = -EINVAL;
2036+ goto cxlflash_ioctl_exit;
2037+ }
2038+
2039+ if (unlikely(copy_from_user(&buf, arg, size))) {
2040+ dev_err(dev, "%s: copy_from_user() fail! "
2041+ "size=%lu cmd=%d (%s) arg=%p\n",
2042+ __func__, size, cmd, decode_ioctl(cmd), arg);
2043+ rc = -EFAULT;
2044+ goto cxlflash_ioctl_exit;
2045+ }
2046+
2047+ hdr = (struct dk_cxlflash_hdr *)&buf;
2048+ if (hdr->version != DK_CXLFLASH_VERSION_0) {
2049+ dev_dbg(dev, "%s: Version %u not supported for %s\n",
2050+ __func__, hdr->version, decode_ioctl(cmd));
2051+ rc = -EINVAL;
2052+ goto cxlflash_ioctl_exit;
2053+ }
2054+
2055+ if (hdr->rsvd[0] || hdr->rsvd[1] || hdr->rsvd[2] || hdr->return_flags) {
2056+ dev_dbg(dev, "%s: Reserved/rflags populated!\n", __func__);
2057+ rc = -EINVAL;
2058+ goto cxlflash_ioctl_exit;
2059+ }
2060+
2061+ rc = do_ioctl(sdev, (void *)&buf);
2062+ if (likely(!rc))
2063+ if (unlikely(copy_to_user(arg, &buf, size))) {
2064+ dev_err(dev, "%s: copy_to_user() fail! "
2065+ "size=%lu cmd=%d (%s) arg=%p\n",
2066+ __func__, size, cmd, decode_ioctl(cmd), arg);
2067+ rc = -EFAULT;
2068+ }
2069+
2070+ /* fall through to exit */
2071+
2072+cxlflash_ioctl_exit:
2073+ if (unlikely(rc && known_ioctl))
2074+ dev_err(dev, "%s: ioctl %s (%08X) on dev(%d/%d/%d/%llu) "
2075+ "returned rc %d\n", __func__,
2076+ decode_ioctl(cmd), cmd, shost->host_no,
2077+ sdev->channel, sdev->id, sdev->lun, rc);
2078+ else
2079+ dev_dbg(dev, "%s: ioctl %s (%08X) on dev(%d/%d/%d/%llu) "
2080+ "returned rc %d\n", __func__, decode_ioctl(cmd),
2081+ cmd, shost->host_no, sdev->channel, sdev->id,
2082+ sdev->lun, rc);
2083+ return rc;
2084+}
drivers/scsi/cxlflash/superpipe.h+147−0
@@ -0,0 +1,147 @@
1+/*
2+ * CXL Flash Device Driver
3+ *
4+ * Written by: Manoj N. Kumar <manoj@linux.vnet.ibm.com>, IBM Corporation
5+ * Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation
6+ *
7+ * Copyright (C) 2015 IBM Corporation
8+ *
9+ * This program is free software; you can redistribute it and/or
10+ * modify it under the terms of the GNU General Public License
11+ * as published by the Free Software Foundation; either version
12+ * 2 of the License, or (at your option) any later version.
13+ */
14+
15+#ifndef _CXLFLASH_SUPERPIPE_H
16+#define _CXLFLASH_SUPERPIPE_H
17+
18+extern struct cxlflash_global global;
19+
20+/*
21+ * Terminology: use afu (and not adapter) to refer to the HW.
22+ * Adapter is the entire slot and includes PSL out of which
23+ * only the AFU is visible to user space.
24+ */
25+
26+/* Chunk size parms: note sislite minimum chunk size is
27+ 0x10000 LBAs corresponding to a NMASK or 16.
28+*/
29+#define MC_CHUNK_SIZE (1 << MC_RHT_NMASK) /* in LBAs */
30+
31+#define MC_DISCOVERY_TIMEOUT 5 /* 5 secs */
32+
33+#define CHAN2PORT(_x) ((_x) + 1)
34+#define PORT2CHAN(_x) ((_x) - 1)
35+
36+enum lun_mode {
37+ MODE_NONE = 0,
38+ MODE_VIRTUAL,
39+ MODE_PHYSICAL
40+};
41+
42+/* Global (entire driver, spans adapters) lun_info structure */
43+struct glun_info {
44+ u64 max_lba; /* from read cap(16) */
45+ u32 blk_len; /* from read cap(16) */
46+ enum lun_mode mode; /* NONE, VIRTUAL, PHYSICAL */
47+ int users; /* Number of users w/ references to LUN */
48+
49+ u8 wwid[16];
50+
51+ struct mutex mutex;
52+
53+ struct blka blka;
54+ struct list_head list;
55+};
56+
57+/* Local (per-adapter) lun_info structure */
58+struct llun_info {
59+ u64 lun_id[CXLFLASH_NUM_FC_PORTS]; /* from REPORT_LUNS */
60+ u32 lun_index; /* Index in the LUN table */
61+ u32 host_no; /* host_no from Scsi_host */
62+ u32 port_sel; /* What port to use for this LUN */
63+ bool newly_created; /* Whether the LUN was just discovered */
64+ bool in_table; /* Whether a LUN table entry was created */
65+
66+ u8 wwid[16]; /* Keep a duplicate copy here? */
67+
68+ struct glun_info *parent; /* Pointer to entry in global LUN structure */
69+ struct scsi_device *sdev;
70+ struct list_head list;
71+};
72+
73+struct lun_access {
74+ struct llun_info *lli;
75+ struct scsi_device *sdev;
76+ struct list_head list;
77+};
78+
79+enum ctx_ctrl {
80+ CTX_CTRL_CLONE = (1 << 1),
81+ CTX_CTRL_ERR = (1 << 2),
82+ CTX_CTRL_ERR_FALLBACK = (1 << 3),
83+ CTX_CTRL_NOPID = (1 << 4),
84+ CTX_CTRL_FILE = (1 << 5)
85+};
86+
87+#define ENCODE_CTXID(_ctx, _id) (((((u64)_ctx) & 0xFFFFFFFF0) << 28) | _id)
88+#define DECODE_CTXID(_val) (_val & 0xFFFFFFFF)
89+
90+struct ctx_info {
91+ struct sisl_ctrl_map *ctrl_map; /* initialized at startup */
92+ struct sisl_rht_entry *rht_start; /* 1 page (req'd for alignment),
93+ alloc/free on attach/detach */
94+ u32 rht_out; /* Number of checked out RHT entries */
95+ u32 rht_perms; /* User-defined permissions for RHT entries */
96+ struct llun_info **rht_lun; /* Mapping of RHT entries to LUNs */
97+ bool *rht_needs_ws; /* User-desired write-same function per RHTE */
98+
99+ struct cxl_ioctl_start_work work;
100+ u64 ctxid;
101+ int lfd;
102+ pid_t pid;
103+ bool unavail;
104+ bool err_recovery_active;
105+ struct mutex mutex; /* Context protection */
106+ struct cxl_context *ctx;
107+ struct list_head luns; /* LUNs attached to this context */
108+ const struct vm_operations_struct *cxl_mmap_vmops;
109+ struct file *file;
110+ struct list_head list; /* Link contexts in error recovery */
111+};
112+
113+struct cxlflash_global {
114+ struct mutex mutex;
115+ struct list_head gluns;/* list of glun_info structs */
116+ struct page *err_page; /* One page of all 0xF for error notification */
117+};
118+
119+int cxlflash_vlun_resize(struct scsi_device *, struct dk_cxlflash_resize *);
120+int _cxlflash_vlun_resize(struct scsi_device *, struct ctx_info *,
121+ struct dk_cxlflash_resize *);
122+
123+int cxlflash_disk_release(struct scsi_device *, struct dk_cxlflash_release *);
124+int _cxlflash_disk_release(struct scsi_device *, struct ctx_info *,
125+ struct dk_cxlflash_release *);
126+
127+int cxlflash_disk_clone(struct scsi_device *, struct dk_cxlflash_clone *);
128+
129+int cxlflash_disk_virtual_open(struct scsi_device *, void *);
130+
131+int cxlflash_lun_attach(struct glun_info *, enum lun_mode, bool);
132+void cxlflash_lun_detach(struct glun_info *);
133+
134+struct ctx_info *get_context(struct cxlflash_cfg *, u64, void *, enum ctx_ctrl);
135+void put_context(struct ctx_info *);
136+
137+struct sisl_rht_entry *get_rhte(struct ctx_info *, res_hndl_t,
138+ struct llun_info *);
139+
140+struct sisl_rht_entry *rhte_checkout(struct ctx_info *, struct llun_info *);
141+void rhte_checkin(struct ctx_info *, struct sisl_rht_entry *);
142+
143+void cxlflash_ba_terminate(struct ba_lun *);
144+
145+int cxlflash_manage_lun(struct scsi_device *, struct dk_cxlflash_manage_lun *);
146+
147+#endif /* ifndef _CXLFLASH_SUPERPIPE_H */
drivers/scsi/cxlflash/vlun.c+1243−0
@@ -0,0 +1,1243 @@
1+/*
2+ * CXL Flash Device Driver
3+ *
4+ * Written by: Manoj N. Kumar <manoj@linux.vnet.ibm.com>, IBM Corporation
5+ * Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation
6+ *
7+ * Copyright (C) 2015 IBM Corporation
8+ *
9+ * This program is free software; you can redistribute it and/or
10+ * modify it under the terms of the GNU General Public License
11+ * as published by the Free Software Foundation; either version
12+ * 2 of the License, or (at your option) any later version.
13+ */
14+
15+#include <linux/syscalls.h>
16+#include <misc/cxl.h>
17+#include <asm/unaligned.h>
18+#include <asm/bitsperlong.h>
19+
20+#include <scsi/scsi_cmnd.h>
21+#include <scsi/scsi_host.h>
22+#include <uapi/scsi/cxlflash_ioctl.h>
23+
24+#include "sislite.h"
25+#include "common.h"
26+#include "vlun.h"
27+#include "superpipe.h"
28+
29+/**
30+ * marshal_virt_to_resize() - translate uvirtual to resize structure
31+ * @virt: Source structure from which to translate/copy.
32+ * @resize: Destination structure for the translate/copy.
33+ */
34+static void marshal_virt_to_resize(struct dk_cxlflash_uvirtual *virt,
35+ struct dk_cxlflash_resize *resize)
36+{
37+ resize->hdr = virt->hdr;
38+ resize->context_id = virt->context_id;
39+ resize->rsrc_handle = virt->rsrc_handle;
40+ resize->req_size = virt->lun_size;
41+ resize->last_lba = virt->last_lba;
42+}
43+
44+/**
45+ * marshal_clone_to_rele() - translate clone to release structure
46+ * @clone: Source structure from which to translate/copy.
47+ * @rele: Destination structure for the translate/copy.
48+ */
49+static void marshal_clone_to_rele(struct dk_cxlflash_clone *clone,
50+ struct dk_cxlflash_release *release)
51+{
52+ release->hdr = clone->hdr;
53+ release->context_id = clone->context_id_dst;
54+}
55+
56+/**
57+ * ba_init() - initializes a block allocator
58+ * @ba_lun: Block allocator to initialize.
59+ *
60+ * Return: 0 on success, -errno on failure
61+ */
62+static int ba_init(struct ba_lun *ba_lun)
63+{
64+ struct ba_lun_info *bali = NULL;
65+ int lun_size_au = 0, i = 0;
66+ int last_word_underflow = 0;
67+ u64 *lam;
68+
69+ pr_debug("%s: Initializing LUN: lun_id = %llX, "
70+ "ba_lun->lsize = %lX, ba_lun->au_size = %lX\n",
71+ __func__, ba_lun->lun_id, ba_lun->lsize, ba_lun->au_size);
72+
73+ /* Calculate bit map size */
74+ lun_size_au = ba_lun->lsize / ba_lun->au_size;
75+ if (lun_size_au == 0) {
76+ pr_debug("%s: Requested LUN size of 0!\n", __func__);
77+ return -EINVAL;
78+ }
79+
80+ /* Allocate lun information container */
81+ bali = kzalloc(sizeof(struct ba_lun_info), GFP_KERNEL);
82+ if (unlikely(!bali)) {
83+ pr_err("%s: Failed to allocate lun_info for lun_id %llX\n",
84+ __func__, ba_lun->lun_id);
85+ return -ENOMEM;
86+ }
87+
88+ bali->total_aus = lun_size_au;
89+ bali->lun_bmap_size = lun_size_au / BITS_PER_LONG;
90+
91+ if (lun_size_au % BITS_PER_LONG)
92+ bali->lun_bmap_size++;
93+
94+ /* Allocate bitmap space */
95+ bali->lun_alloc_map = kzalloc((bali->lun_bmap_size * sizeof(u64)),
96+ GFP_KERNEL);
97+ if (unlikely(!bali->lun_alloc_map)) {
98+ pr_err("%s: Failed to allocate lun allocation map: "
99+ "lun_id = %llX\n", __func__, ba_lun->lun_id);
100+ kfree(bali);
101+ return -ENOMEM;
102+ }
103+
104+ /* Initialize the bit map size and set all bits to '1' */
105+ bali->free_aun_cnt = lun_size_au;
106+
107+ for (i = 0; i < bali->lun_bmap_size; i++)
108+ bali->lun_alloc_map[i] = 0xFFFFFFFFFFFFFFFFULL;
109+
110+ /* If the last word not fully utilized, mark extra bits as allocated */
111+ last_word_underflow = (bali->lun_bmap_size * BITS_PER_LONG);
112+ last_word_underflow -= bali->free_aun_cnt;
113+ if (last_word_underflow > 0) {
114+ lam = &bali->lun_alloc_map[bali->lun_bmap_size - 1];
115+ for (i = (HIBIT - last_word_underflow + 1);
116+ i < BITS_PER_LONG;
117+ i++)
118+ clear_bit(i, (ulong *)lam);
119+ }
120+
121+ /* Initialize high elevator index, low/curr already at 0 from kzalloc */
122+ bali->free_high_idx = bali->lun_bmap_size;
123+
124+ /* Allocate clone map */
125+ bali->aun_clone_map = kzalloc((bali->total_aus * sizeof(u8)),
126+ GFP_KERNEL);
127+ if (unlikely(!bali->aun_clone_map)) {
128+ pr_err("%s: Failed to allocate clone map: lun_id = %llX\n",
129+ __func__, ba_lun->lun_id);
130+ kfree(bali->lun_alloc_map);
131+ kfree(bali);
132+ return -ENOMEM;
133+ }
134+
135+ /* Pass the allocated lun info as a handle to the user */
136+ ba_lun->ba_lun_handle = bali;
137+
138+ pr_debug("%s: Successfully initialized the LUN: "
139+ "lun_id = %llX, bitmap size = %X, free_aun_cnt = %llX\n",
140+ __func__, ba_lun->lun_id, bali->lun_bmap_size,
141+ bali->free_aun_cnt);
142+ return 0;
143+}
144+
145+/**
146+ * find_free_range() - locates a free bit within the block allocator
147+ * @low: First word in block allocator to start search.
148+ * @high: Last word in block allocator to search.
149+ * @bali: LUN information structure owning the block allocator to search.
150+ * @bit_word: Passes back the word in the block allocator owning the free bit.
151+ *
152+ * Return: The bit position within the passed back word, -1 on failure
153+ */
154+static int find_free_range(u32 low,
155+ u32 high,
156+ struct ba_lun_info *bali, int *bit_word)
157+{
158+ int i;
159+ u64 bit_pos = -1;
160+ ulong *lam, num_bits;
161+
162+ for (i = low; i < high; i++)
163+ if (bali->lun_alloc_map[i] != 0) {
164+ lam = (ulong *)&bali->lun_alloc_map[i];
165+ num_bits = (sizeof(*lam) * BITS_PER_BYTE);
166+ bit_pos = find_first_bit(lam, num_bits);
167+
168+ pr_devel("%s: Found free bit %llX in lun "
169+ "map entry %llX at bitmap index = %X\n",
170+ __func__, bit_pos, bali->lun_alloc_map[i],
171+ i);
172+
173+ *bit_word = i;
174+ bali->free_aun_cnt--;
175+ clear_bit(bit_pos, lam);
176+ break;
177+ }
178+
179+ return bit_pos;
180+}
181+
182+/**
183+ * ba_alloc() - allocates a block from the block allocator
184+ * @ba_lun: Block allocator from which to allocate a block.
185+ *
186+ * Return: The allocated block, -1 on failure
187+ */
188+static u64 ba_alloc(struct ba_lun *ba_lun)
189+{
190+ u64 bit_pos = -1;
191+ int bit_word = 0;
192+ struct ba_lun_info *bali = NULL;
193+
194+ bali = ba_lun->ba_lun_handle;
195+
196+ pr_debug("%s: Received block allocation request: "
197+ "lun_id = %llX, free_aun_cnt = %llX\n",
198+ __func__, ba_lun->lun_id, bali->free_aun_cnt);
199+
200+ if (bali->free_aun_cnt == 0) {
201+ pr_debug("%s: No space left on LUN: lun_id = %llX\n",
202+ __func__, ba_lun->lun_id);
203+ return -1ULL;
204+ }
205+
206+ /* Search to find a free entry, curr->high then low->curr */
207+ bit_pos = find_free_range(bali->free_curr_idx,
208+ bali->free_high_idx, bali, &bit_word);
209+ if (bit_pos == -1) {
210+ bit_pos = find_free_range(bali->free_low_idx,
211+ bali->free_curr_idx,
212+ bali, &bit_word);
213+ if (bit_pos == -1) {
214+ pr_debug("%s: Could not find an allocation unit on LUN:"
215+ " lun_id = %llX\n", __func__, ba_lun->lun_id);
216+ return -1ULL;
217+ }
218+ }
219+
220+ /* Update the free_curr_idx */
221+ if (bit_pos == HIBIT)
222+ bali->free_curr_idx = bit_word + 1;
223+ else
224+ bali->free_curr_idx = bit_word;
225+
226+ pr_debug("%s: Allocating AU number %llX, on lun_id %llX, "
227+ "free_aun_cnt = %llX\n", __func__,
228+ ((bit_word * BITS_PER_LONG) + bit_pos), ba_lun->lun_id,
229+ bali->free_aun_cnt);
230+
231+ return (u64) ((bit_word * BITS_PER_LONG) + bit_pos);
232+}
233+
234+/**
235+ * validate_alloc() - validates the specified block has been allocated
236+ * @ba_lun_info: LUN info owning the block allocator.
237+ * @aun: Block to validate.
238+ *
239+ * Return: 0 on success, -1 on failure
240+ */
241+static int validate_alloc(struct ba_lun_info *bali, u64 aun)
242+{
243+ int idx = 0, bit_pos = 0;
244+
245+ idx = aun / BITS_PER_LONG;
246+ bit_pos = aun % BITS_PER_LONG;
247+
248+ if (test_bit(bit_pos, (ulong *)&bali->lun_alloc_map[idx]))
249+ return -1;
250+
251+ return 0;
252+}
253+
254+/**
255+ * ba_free() - frees a block from the block allocator
256+ * @ba_lun: Block allocator from which to allocate a block.
257+ * @to_free: Block to free.
258+ *
259+ * Return: 0 on success, -1 on failure
260+ */
261+static int ba_free(struct ba_lun *ba_lun, u64 to_free)
262+{
263+ int idx = 0, bit_pos = 0;
264+ struct ba_lun_info *bali = NULL;
265+
266+ bali = ba_lun->ba_lun_handle;
267+
268+ if (validate_alloc(bali, to_free)) {
269+ pr_debug("%s: The AUN %llX is not allocated on lun_id %llX\n",
270+ __func__, to_free, ba_lun->lun_id);
271+ return -1;
272+ }
273+
274+ pr_debug("%s: Received a request to free AU %llX on lun_id %llX, "
275+ "free_aun_cnt = %llX\n", __func__, to_free, ba_lun->lun_id,
276+ bali->free_aun_cnt);
277+
278+ if (bali->aun_clone_map[to_free] > 0) {
279+ pr_debug("%s: AUN %llX on lun_id %llX has been cloned. Clone "
280+ "count = %X\n", __func__, to_free, ba_lun->lun_id,
281+ bali->aun_clone_map[to_free]);
282+ bali->aun_clone_map[to_free]--;
283+ return 0;
284+ }
285+
286+ idx = to_free / BITS_PER_LONG;
287+ bit_pos = to_free % BITS_PER_LONG;
288+
289+ set_bit(bit_pos, (ulong *)&bali->lun_alloc_map[idx]);
290+ bali->free_aun_cnt++;
291+
292+ if (idx < bali->free_low_idx)
293+ bali->free_low_idx = idx;
294+ else if (idx > bali->free_high_idx)
295+ bali->free_high_idx = idx;
296+
297+ pr_debug("%s: Successfully freed AU at bit_pos %X, bit map index %X on "
298+ "lun_id %llX, free_aun_cnt = %llX\n", __func__, bit_pos, idx,
299+ ba_lun->lun_id, bali->free_aun_cnt);
300+
301+ return 0;
302+}
303+
304+/**
305+ * ba_clone() - Clone a chunk of the block allocation table
306+ * @ba_lun: Block allocator from which to allocate a block.
307+ * @to_free: Block to free.
308+ *
309+ * Return: 0 on success, -1 on failure
310+ */
311+static int ba_clone(struct ba_lun *ba_lun, u64 to_clone)
312+{
313+ struct ba_lun_info *bali = ba_lun->ba_lun_handle;
314+
315+ if (validate_alloc(bali, to_clone)) {
316+ pr_debug("%s: AUN %llX is not allocated on lun_id %llX\n",
317+ __func__, to_clone, ba_lun->lun_id);
318+ return -1;
319+ }
320+
321+ pr_debug("%s: Received a request to clone AUN %llX on lun_id %llX\n",
322+ __func__, to_clone, ba_lun->lun_id);
323+
324+ if (bali->aun_clone_map[to_clone] == MAX_AUN_CLONE_CNT) {
325+ pr_debug("%s: AUN %llX on lun_id %llX hit max clones already\n",
326+ __func__, to_clone, ba_lun->lun_id);
327+ return -1;
328+ }
329+
330+ bali->aun_clone_map[to_clone]++;
331+
332+ return 0;
333+}
334+
335+/**
336+ * ba_space() - returns the amount of free space left in the block allocator
337+ * @ba_lun: Block allocator.
338+ *
339+ * Return: Amount of free space in block allocator
340+ */
341+static u64 ba_space(struct ba_lun *ba_lun)
342+{
343+ struct ba_lun_info *bali = ba_lun->ba_lun_handle;
344+
345+ return bali->free_aun_cnt;
346+}
347+
348+/**
349+ * cxlflash_ba_terminate() - frees resources associated with the block allocator
350+ * @ba_lun: Block allocator.
351+ *
352+ * Safe to call in a partially allocated state.
353+ */
354+void cxlflash_ba_terminate(struct ba_lun *ba_lun)
355+{
356+ struct ba_lun_info *bali = ba_lun->ba_lun_handle;
357+
358+ if (bali) {
359+ kfree(bali->aun_clone_map);
360+ kfree(bali->lun_alloc_map);
361+ kfree(bali);
362+ ba_lun->ba_lun_handle = NULL;
363+ }
364+}
365+
366+/**
367+ * init_vlun() - initializes a LUN for virtual use
368+ * @lun_info: LUN information structure that owns the block allocator.
369+ *
370+ * Return: 0 on success, -errno on failure
371+ */
372+static int init_vlun(struct llun_info *lli)
373+{
374+ int rc = 0;
375+ struct glun_info *gli = lli->parent;
376+ struct blka *blka = &gli->blka;
377+
378+ memset(blka, 0, sizeof(*blka));
379+ mutex_init(&blka->mutex);
380+
381+ /* LUN IDs are unique per port, save the index instead */
382+ blka->ba_lun.lun_id = lli->lun_index;
383+ blka->ba_lun.lsize = gli->max_lba + 1;
384+ blka->ba_lun.lba_size = gli->blk_len;
385+
386+ blka->ba_lun.au_size = MC_CHUNK_SIZE;
387+ blka->nchunk = blka->ba_lun.lsize / MC_CHUNK_SIZE;
388+
389+ rc = ba_init(&blka->ba_lun);
390+ if (unlikely(rc))
391+ pr_debug("%s: cannot init block_alloc, rc=%d\n", __func__, rc);
392+
393+ pr_debug("%s: returning rc=%d lli=%p\n", __func__, rc, lli);
394+ return rc;
395+}
396+
397+/**
398+ * write_same16() - sends a SCSI WRITE_SAME16 (0) command to specified LUN
399+ * @sdev: SCSI device associated with LUN.
400+ * @lba: Logical block address to start write same.
401+ * @nblks: Number of logical blocks to write same.
402+ *
403+ * Return: 0 on success, -errno on failure
404+ */
405+static int write_same16(struct scsi_device *sdev,
406+ u64 lba,
407+ u32 nblks)
408+{
409+ u8 *cmd_buf = NULL;
410+ u8 *scsi_cmd = NULL;
411+ u8 *sense_buf = NULL;
412+ int rc = 0;
413+ int result = 0;
414+ int ws_limit = SISLITE_MAX_WS_BLOCKS;
415+ u64 offset = lba;
416+ int left = nblks;
417+ u32 tout = sdev->request_queue->rq_timeout;
418+ struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)sdev->host->hostdata;
419+ struct device *dev = &cfg->dev->dev;
420+
421+ cmd_buf = kzalloc(CMD_BUFSIZE, GFP_KERNEL);
422+ scsi_cmd = kzalloc(MAX_COMMAND_SIZE, GFP_KERNEL);
423+ sense_buf = kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL);
424+ if (unlikely(!cmd_buf || !scsi_cmd || !sense_buf)) {
425+ rc = -ENOMEM;
426+ goto out;
427+ }
428+
429+ while (left > 0) {
430+
431+ scsi_cmd[0] = WRITE_SAME_16;
432+ put_unaligned_be64(offset, &scsi_cmd[2]);
433+ put_unaligned_be32(ws_limit < left ? ws_limit : left,
434+ &scsi_cmd[10]);
435+
436+ result = scsi_execute(sdev, scsi_cmd, DMA_TO_DEVICE, cmd_buf,
437+ CMD_BUFSIZE, sense_buf, tout, 5, 0, NULL);
438+ if (result) {
439+ dev_err_ratelimited(dev, "%s: command failed for "
440+ "offset %lld result=0x%x\n",
441+ __func__, offset, result);
442+ rc = -EIO;
443+ goto out;
444+ }
445+ left -= ws_limit;
446+ offset += ws_limit;
447+ }
448+
449+out:
450+ kfree(cmd_buf);
451+ kfree(scsi_cmd);
452+ kfree(sense_buf);
453+ pr_debug("%s: returning rc=%d\n", __func__, rc);
454+ return rc;
455+}
456+
457+/**
458+ * grow_lxt() - expands the translation table associated with the specified RHTE
459+ * @afu: AFU associated with the host.
460+ * @sdev: SCSI device associated with LUN.
461+ * @ctxid: Context ID of context owning the RHTE.
462+ * @rhndl: Resource handle associated with the RHTE.
463+ * @rhte: Resource handle entry (RHTE).
464+ * @new_size: Number of translation entries associated with RHTE.
465+ *
466+ * By design, this routine employs a 'best attempt' allocation and will
467+ * truncate the requested size down if there is not sufficient space in
468+ * the block allocator to satisfy the request but there does exist some
469+ * amount of space. The user is made aware of this by returning the size
470+ * allocated.
471+ *
472+ * Return: 0 on success, -errno on failure
473+ */
474+static int grow_lxt(struct afu *afu,
475+ struct scsi_device *sdev,
476+ ctx_hndl_t ctxid,
477+ res_hndl_t rhndl,
478+ struct sisl_rht_entry *rhte,
479+ u64 *new_size)
480+{
481+ struct sisl_lxt_entry *lxt = NULL, *lxt_old = NULL;
482+ struct llun_info *lli = sdev->hostdata;
483+ struct glun_info *gli = lli->parent;
484+ struct blka *blka = &gli->blka;
485+ u32 av_size;
486+ u32 ngrps, ngrps_old;
487+ u64 aun; /* chunk# allocated by block allocator */
488+ u64 delta = *new_size - rhte->lxt_cnt;
489+ u64 my_new_size;
490+ int i, rc = 0;
491+
492+ /*
493+ * Check what is available in the block allocator before re-allocating
494+ * LXT array. This is done up front under the mutex which must not be
495+ * released until after allocation is complete.
496+ */
497+ mutex_lock(&blka->mutex);
498+ av_size = ba_space(&blka->ba_lun);
499+ if (unlikely(av_size <= 0)) {
500+ pr_debug("%s: ba_space error: av_size %d\n", __func__, av_size);
501+ mutex_unlock(&blka->mutex);
502+ rc = -ENOSPC;
503+ goto out;
504+ }
505+
506+ if (av_size < delta)
507+ delta = av_size;
508+
509+ lxt_old = rhte->lxt_start;
510+ ngrps_old = LXT_NUM_GROUPS(rhte->lxt_cnt);
511+ ngrps = LXT_NUM_GROUPS(rhte->lxt_cnt + delta);
512+
513+ if (ngrps != ngrps_old) {
514+ /* reallocate to fit new size */
515+ lxt = kzalloc((sizeof(*lxt) * LXT_GROUP_SIZE * ngrps),
516+ GFP_KERNEL);
517+ if (unlikely(!lxt)) {
518+ mutex_unlock(&blka->mutex);
519+ rc = -ENOMEM;
520+ goto out;
521+ }
522+
523+ /* copy over all old entries */
524+ memcpy(lxt, lxt_old, (sizeof(*lxt) * rhte->lxt_cnt));
525+ } else
526+ lxt = lxt_old;
527+
528+ /* nothing can fail from now on */
529+ my_new_size = rhte->lxt_cnt + delta;
530+
531+ /* add new entries to the end */
532+ for (i = rhte->lxt_cnt; i < my_new_size; i++) {
533+ /*
534+ * Due to the earlier check of available space, ba_alloc
535+ * cannot fail here. If it did due to internal error,
536+ * leave a rlba_base of -1u which will likely be a
537+ * invalid LUN (too large).
538+ */
539+ aun = ba_alloc(&blka->ba_lun);
540+ if ((aun == -1ULL) || (aun >= blka->nchunk))
541+ pr_debug("%s: ba_alloc error: allocated chunk# %llX, "
542+ "max %llX\n", __func__, aun, blka->nchunk - 1);
543+
544+ /* select both ports, use r/w perms from RHT */
545+ lxt[i].rlba_base = ((aun << MC_CHUNK_SHIFT) |
546+ (lli->lun_index << LXT_LUNIDX_SHIFT) |
547+ (RHT_PERM_RW << LXT_PERM_SHIFT |
548+ lli->port_sel));
549+ }
550+
551+ mutex_unlock(&blka->mutex);
552+
553+ /*
554+ * The following sequence is prescribed in the SISlite spec
555+ * for syncing up with the AFU when adding LXT entries.
556+ */
557+ dma_wmb(); /* Make LXT updates are visible */
558+
559+ rhte->lxt_start = lxt;
560+ dma_wmb(); /* Make RHT entry's LXT table update visible */
561+
562+ rhte->lxt_cnt = my_new_size;
563+ dma_wmb(); /* Make RHT entry's LXT table size update visible */
564+
565+ cxlflash_afu_sync(afu, ctxid, rhndl, AFU_LW_SYNC);
566+
567+ /* free old lxt if reallocated */
568+ if (lxt != lxt_old)
569+ kfree(lxt_old);
570+ *new_size = my_new_size;
571+out:
572+ pr_debug("%s: returning rc=%d\n", __func__, rc);
573+ return rc;
574+}
575+
576+/**
577+ * shrink_lxt() - reduces translation table associated with the specified RHTE
578+ * @afu: AFU associated with the host.
579+ * @sdev: SCSI device associated with LUN.
580+ * @rhndl: Resource handle associated with the RHTE.
581+ * @rhte: Resource handle entry (RHTE).
582+ * @ctxi: Context owning resources.
583+ * @new_size: Number of translation entries associated with RHTE.
584+ *
585+ * Return: 0 on success, -errno on failure
586+ */
587+static int shrink_lxt(struct afu *afu,
588+ struct scsi_device *sdev,
589+ res_hndl_t rhndl,
590+ struct sisl_rht_entry *rhte,
591+ struct ctx_info *ctxi,
592+ u64 *new_size)
593+{
594+ struct sisl_lxt_entry *lxt, *lxt_old;
595+ struct llun_info *lli = sdev->hostdata;
596+ struct glun_info *gli = lli->parent;
597+ struct blka *blka = &gli->blka;
598+ ctx_hndl_t ctxid = DECODE_CTXID(ctxi->ctxid);
599+ bool needs_ws = ctxi->rht_needs_ws[rhndl];
600+ bool needs_sync = !ctxi->err_recovery_active;
601+ u32 ngrps, ngrps_old;
602+ u64 aun; /* chunk# allocated by block allocator */
603+ u64 delta = rhte->lxt_cnt - *new_size;
604+ u64 my_new_size;
605+ int i, rc = 0;
606+
607+ lxt_old = rhte->lxt_start;
608+ ngrps_old = LXT_NUM_GROUPS(rhte->lxt_cnt);
609+ ngrps = LXT_NUM_GROUPS(rhte->lxt_cnt - delta);
610+
611+ if (ngrps != ngrps_old) {
612+ /* Reallocate to fit new size unless new size is 0 */
613+ if (ngrps) {
614+ lxt = kzalloc((sizeof(*lxt) * LXT_GROUP_SIZE * ngrps),
615+ GFP_KERNEL);
616+ if (unlikely(!lxt)) {
617+ rc = -ENOMEM;
618+ goto out;
619+ }
620+
621+ /* Copy over old entries that will remain */
622+ memcpy(lxt, lxt_old,
623+ (sizeof(*lxt) * (rhte->lxt_cnt - delta)));
624+ } else
625+ lxt = NULL;
626+ } else
627+ lxt = lxt_old;
628+
629+ /* Nothing can fail from now on */
630+ my_new_size = rhte->lxt_cnt - delta;
631+
632+ /*
633+ * The following sequence is prescribed in the SISlite spec
634+ * for syncing up with the AFU when removing LXT entries.
635+ */
636+ rhte->lxt_cnt = my_new_size;
637+ dma_wmb(); /* Make RHT entry's LXT table size update visible */
638+
639+ rhte->lxt_start = lxt;
640+ dma_wmb(); /* Make RHT entry's LXT table update visible */
641+
642+ if (needs_sync)
643+ cxlflash_afu_sync(afu, ctxid, rhndl, AFU_HW_SYNC);
644+
645+ if (needs_ws) {
646+ /*
647+ * Mark the context as unavailable, so that we can release
648+ * the mutex safely.
649+ */
650+ ctxi->unavail = true;
651+ mutex_unlock(&ctxi->mutex);
652+ }
653+
654+ /* Free LBAs allocated to freed chunks */
655+ mutex_lock(&blka->mutex);
656+ for (i = delta - 1; i >= 0; i--) {
657+ /* Mask the higher 48 bits before shifting, even though
658+ * it is a noop
659+ */
660+ aun = (lxt_old[my_new_size + i].rlba_base & SISL_ASTATUS_MASK);
661+ aun = (aun >> MC_CHUNK_SHIFT);
662+ if (needs_ws)
663+ write_same16(sdev, aun, MC_CHUNK_SIZE);
664+ ba_free(&blka->ba_lun, aun);
665+ }
666+ mutex_unlock(&blka->mutex);
667+
668+ if (needs_ws) {
669+ /* Make the context visible again */
670+ mutex_lock(&ctxi->mutex);
671+ ctxi->unavail = false;
672+ }
673+
674+ /* Free old lxt if reallocated */
675+ if (lxt != lxt_old)
676+ kfree(lxt_old);
677+ *new_size = my_new_size;
678+out:
679+ pr_debug("%s: returning rc=%d\n", __func__, rc);
680+ return rc;
681+}
682+
683+/**
684+ * _cxlflash_vlun_resize() - changes the size of a virtual lun
685+ * @sdev: SCSI device associated with LUN owning virtual LUN.
686+ * @ctxi: Context owning resources.
687+ * @resize: Resize ioctl data structure.
688+ *
689+ * On successful return, the user is informed of the new size (in blocks)
690+ * of the virtual lun in last LBA format. When the size of the virtual
691+ * lun is zero, the last LBA is reflected as -1. See comment in the
692+ * prologue for _cxlflash_disk_release() regarding AFU syncs and contexts
693+ * on the error recovery list.
694+ *
695+ * Return: 0 on success, -errno on failure
696+ */
697+int _cxlflash_vlun_resize(struct scsi_device *sdev,
698+ struct ctx_info *ctxi,
699+ struct dk_cxlflash_resize *resize)
700+{
701+ struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)sdev->host->hostdata;
702+ struct llun_info *lli = sdev->hostdata;
703+ struct glun_info *gli = lli->parent;
704+ struct afu *afu = cfg->afu;
705+ bool put_ctx = false;
706+
707+ res_hndl_t rhndl = resize->rsrc_handle;
708+ u64 new_size;
709+ u64 nsectors;
710+ u64 ctxid = DECODE_CTXID(resize->context_id),
711+ rctxid = resize->context_id;
712+
713+ struct sisl_rht_entry *rhte;
714+
715+ int rc = 0;
716+
717+ /*
718+ * The requested size (req_size) is always assumed to be in 4k blocks,
719+ * so we have to convert it here from 4k to chunk size.
720+ */
721+ nsectors = (resize->req_size * CXLFLASH_BLOCK_SIZE) / gli->blk_len;
722+ new_size = DIV_ROUND_UP(nsectors, MC_CHUNK_SIZE);
723+
724+ pr_debug("%s: ctxid=%llu rhndl=0x%llx, req_size=0x%llx,"
725+ "new_size=%llx\n", __func__, ctxid, resize->rsrc_handle,
726+ resize->req_size, new_size);
727+
728+ if (unlikely(gli->mode != MODE_VIRTUAL)) {
729+ pr_debug("%s: LUN mode does not support resize! (%d)\n",
730+ __func__, gli->mode);
731+ rc = -EINVAL;
732+ goto out;
733+
734+ }
735+
736+ if (!ctxi) {
737+ ctxi = get_context(cfg, rctxid, lli, CTX_CTRL_ERR_FALLBACK);
738+ if (unlikely(!ctxi)) {
739+ pr_debug("%s: Bad context! (%llu)\n", __func__, ctxid);
740+ rc = -EINVAL;
741+ goto out;
742+ }
743+
744+ put_ctx = true;
745+ }
746+
747+ rhte = get_rhte(ctxi, rhndl, lli);
748+ if (unlikely(!rhte)) {
749+ pr_debug("%s: Bad resource handle! (%u)\n", __func__, rhndl);
750+ rc = -EINVAL;
751+ goto out;
752+ }
753+
754+ if (new_size > rhte->lxt_cnt)
755+ rc = grow_lxt(afu, sdev, ctxid, rhndl, rhte, &new_size);
756+ else if (new_size < rhte->lxt_cnt)
757+ rc = shrink_lxt(afu, sdev, rhndl, rhte, ctxi, &new_size);
758+
759+ resize->hdr.return_flags = 0;
760+ resize->last_lba = (new_size * MC_CHUNK_SIZE * gli->blk_len);
761+ resize->last_lba /= CXLFLASH_BLOCK_SIZE;
762+ resize->last_lba--;
763+
764+out:
765+ if (put_ctx)
766+ put_context(ctxi);
767+ pr_debug("%s: resized to %lld returning rc=%d\n",
768+ __func__, resize->last_lba, rc);
769+ return rc;
770+}
771+
772+int cxlflash_vlun_resize(struct scsi_device *sdev,
773+ struct dk_cxlflash_resize *resize)
774+{
775+ return _cxlflash_vlun_resize(sdev, NULL, resize);
776+}
777+
778+/**
779+ * cxlflash_restore_luntable() - Restore LUN table to prior state
780+ * @cfg: Internal structure associated with the host.
781+ */
782+void cxlflash_restore_luntable(struct cxlflash_cfg *cfg)
783+{
784+ struct llun_info *lli, *temp;
785+ u32 chan;
786+ u32 lind;
787+ struct afu *afu = cfg->afu;
788+ struct sisl_global_map *agm = &afu->afu_map->global;
789+
790+ mutex_lock(&global.mutex);
791+
792+ list_for_each_entry_safe(lli, temp, &cfg->lluns, list) {
793+ if (!lli->in_table)
794+ continue;
795+
796+ lind = lli->lun_index;
797+
798+ if (lli->port_sel == BOTH_PORTS) {
799+ writeq_be(lli->lun_id[0], &agm->fc_port[0][lind]);
800+ writeq_be(lli->lun_id[1], &agm->fc_port[1][lind]);
801+ pr_debug("%s: Virtual LUN on slot %d id0=%llx, "
802+ "id1=%llx\n", __func__, lind,
803+ lli->lun_id[0], lli->lun_id[1]);
804+ } else {
805+ chan = PORT2CHAN(lli->port_sel);
806+ writeq_be(lli->lun_id[chan], &agm->fc_port[chan][lind]);
807+ pr_debug("%s: Virtual LUN on slot %d chan=%d, "
808+ "id=%llx\n", __func__, lind, chan,
809+ lli->lun_id[chan]);
810+ }
811+ }
812+
813+ mutex_unlock(&global.mutex);
814+}
815+
816+/**
817+ * init_luntable() - write an entry in the LUN table
818+ * @cfg: Internal structure associated with the host.
819+ * @lli: Per adapter LUN information structure.
820+ *
821+ * On successful return, a LUN table entry is created.
822+ * At the top for LUNs visible on both ports.
823+ * At the bottom for LUNs visible only on one port.
824+ *
825+ * Return: 0 on success, -errno on failure
826+ */
827+static int init_luntable(struct cxlflash_cfg *cfg, struct llun_info *lli)
828+{
829+ u32 chan;
830+ u32 lind;
831+ int rc = 0;
832+ struct afu *afu = cfg->afu;
833+ struct sisl_global_map *agm = &afu->afu_map->global;
834+
835+ mutex_lock(&global.mutex);
836+
837+ if (lli->in_table)
838+ goto out;
839+
840+ if (lli->port_sel == BOTH_PORTS) {
841+ /*
842+ * If this LUN is visible from both ports, we will put
843+ * it in the top half of the LUN table.
844+ */
845+ if ((cfg->promote_lun_index == cfg->last_lun_index[0]) ||
846+ (cfg->promote_lun_index == cfg->last_lun_index[1])) {
847+ rc = -ENOSPC;
848+ goto out;
849+ }
850+
851+ lind = lli->lun_index = cfg->promote_lun_index;
852+ writeq_be(lli->lun_id[0], &agm->fc_port[0][lind]);
853+ writeq_be(lli->lun_id[1], &agm->fc_port[1][lind]);
854+ cfg->promote_lun_index++;
855+ pr_debug("%s: Virtual LUN on slot %d id0=%llx, id1=%llx\n",
856+ __func__, lind, lli->lun_id[0], lli->lun_id[1]);
857+ } else {
858+ /*
859+ * If this LUN is visible only from one port, we will put
860+ * it in the bottom half of the LUN table.
861+ */
862+ chan = PORT2CHAN(lli->port_sel);
863+ if (cfg->promote_lun_index == cfg->last_lun_index[chan]) {
864+ rc = -ENOSPC;
865+ goto out;
866+ }
867+
868+ lind = lli->lun_index = cfg->last_lun_index[chan];
869+ writeq_be(lli->lun_id[chan], &agm->fc_port[chan][lind]);
870+ cfg->last_lun_index[chan]--;
871+ pr_debug("%s: Virtual LUN on slot %d chan=%d, id=%llx\n",
872+ __func__, lind, chan, lli->lun_id[chan]);
873+ }
874+
875+ lli->in_table = true;
876+out:
877+ mutex_unlock(&global.mutex);
878+ pr_debug("%s: returning rc=%d\n", __func__, rc);
879+ return rc;
880+}
881+
882+/**
883+ * cxlflash_disk_virtual_open() - open a virtual disk of specified size
884+ * @sdev: SCSI device associated with LUN owning virtual LUN.
885+ * @arg: UVirtual ioctl data structure.
886+ *
887+ * On successful return, the user is informed of the resource handle
888+ * to be used to identify the virtual lun and the size (in blocks) of
889+ * the virtual lun in last LBA format. When the size of the virtual lun
890+ * is zero, the last LBA is reflected as -1.
891+ *
892+ * Return: 0 on success, -errno on failure
893+ */
894+int cxlflash_disk_virtual_open(struct scsi_device *sdev, void *arg)
895+{
896+ struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)sdev->host->hostdata;
897+ struct device *dev = &cfg->dev->dev;
898+ struct llun_info *lli = sdev->hostdata;
899+ struct glun_info *gli = lli->parent;
900+
901+ struct dk_cxlflash_uvirtual *virt = (struct dk_cxlflash_uvirtual *)arg;
902+ struct dk_cxlflash_resize resize;
903+
904+ u64 ctxid = DECODE_CTXID(virt->context_id),
905+ rctxid = virt->context_id;
906+ u64 lun_size = virt->lun_size;
907+ u64 last_lba = 0;
908+ u64 rsrc_handle = -1;
909+
910+ int rc = 0;
911+
912+ struct ctx_info *ctxi = NULL;
913+ struct sisl_rht_entry *rhte = NULL;
914+
915+ pr_debug("%s: ctxid=%llu ls=0x%llx\n", __func__, ctxid, lun_size);
916+
917+ mutex_lock(&gli->mutex);
918+ if (gli->mode == MODE_NONE) {
919+ /* Setup the LUN table and block allocator on first call */
920+ rc = init_luntable(cfg, lli);
921+ if (rc) {
922+ dev_err(dev, "%s: call to init_luntable failed "
923+ "rc=%d!\n", __func__, rc);
924+ goto err0;
925+ }
926+
927+ rc = init_vlun(lli);
928+ if (rc) {
929+ dev_err(dev, "%s: call to init_vlun failed rc=%d!\n",
930+ __func__, rc);
931+ rc = -ENOMEM;
932+ goto err0;
933+ }
934+ }
935+
936+ rc = cxlflash_lun_attach(gli, MODE_VIRTUAL, true);
937+ if (unlikely(rc)) {
938+ dev_err(dev, "%s: Failed to attach to LUN! (VIRTUAL)\n",
939+ __func__);
940+ goto err0;
941+ }
942+ mutex_unlock(&gli->mutex);
943+
944+ ctxi = get_context(cfg, rctxid, lli, 0);
945+ if (unlikely(!ctxi)) {
946+ dev_err(dev, "%s: Bad context! (%llu)\n", __func__, ctxid);
947+ rc = -EINVAL;
948+ goto err1;
949+ }
950+
951+ rhte = rhte_checkout(ctxi, lli);
952+ if (unlikely(!rhte)) {
953+ dev_err(dev, "%s: too many opens for this context\n", __func__);
954+ rc = -EMFILE; /* too many opens */
955+ goto err1;
956+ }
957+
958+ rsrc_handle = (rhte - ctxi->rht_start);
959+
960+ /* Populate RHT format 0 */
961+ rhte->nmask = MC_RHT_NMASK;
962+ rhte->fp = SISL_RHT_FP(0U, ctxi->rht_perms);
963+
964+ /* Resize even if requested size is 0 */
965+ marshal_virt_to_resize(virt, &resize);
966+ resize.rsrc_handle = rsrc_handle;
967+ rc = _cxlflash_vlun_resize(sdev, ctxi, &resize);
968+ if (rc) {
969+ dev_err(dev, "%s: resize failed rc %d\n", __func__, rc);
970+ goto err2;
971+ }
972+ last_lba = resize.last_lba;
973+
974+ if (virt->hdr.flags & DK_CXLFLASH_UVIRTUAL_NEED_WRITE_SAME)
975+ ctxi->rht_needs_ws[rsrc_handle] = true;
976+
977+ virt->hdr.return_flags = 0;
978+ virt->last_lba = last_lba;
979+ virt->rsrc_handle = rsrc_handle;
980+
981+out:
982+ if (likely(ctxi))
983+ put_context(ctxi);
984+ pr_debug("%s: returning handle 0x%llx rc=%d llba %lld\n",
985+ __func__, rsrc_handle, rc, last_lba);
986+ return rc;
987+
988+err2:
989+ rhte_checkin(ctxi, rhte);
990+err1:
991+ cxlflash_lun_detach(gli);
992+ goto out;
993+err0:
994+ /* Special common cleanup prior to successful LUN attach */
995+ cxlflash_ba_terminate(&gli->blka.ba_lun);
996+ mutex_unlock(&gli->mutex);
997+ goto out;
998+}
999+
1000+/**
1001+ * clone_lxt() - copies translation tables from source to destination RHTE
1002+ * @afu: AFU associated with the host.
1003+ * @blka: Block allocator associated with LUN.
1004+ * @ctxid: Context ID of context owning the RHTE.
1005+ * @rhndl: Resource handle associated with the RHTE.
1006+ * @rhte: Destination resource handle entry (RHTE).
1007+ * @rhte_src: Source resource handle entry (RHTE).
1008+ *
1009+ * Return: 0 on success, -errno on failure
1010+ */
1011+static int clone_lxt(struct afu *afu,
1012+ struct blka *blka,
1013+ ctx_hndl_t ctxid,
1014+ res_hndl_t rhndl,
1015+ struct sisl_rht_entry *rhte,
1016+ struct sisl_rht_entry *rhte_src)
1017+{
1018+ struct sisl_lxt_entry *lxt;
1019+ u32 ngrps;
1020+ u64 aun; /* chunk# allocated by block allocator */
1021+ int i, j;
1022+
1023+ ngrps = LXT_NUM_GROUPS(rhte_src->lxt_cnt);
1024+
1025+ if (ngrps) {
1026+ /* allocate new LXTs for clone */
1027+ lxt = kzalloc((sizeof(*lxt) * LXT_GROUP_SIZE * ngrps),
1028+ GFP_KERNEL);
1029+ if (unlikely(!lxt))
1030+ return -ENOMEM;
1031+
1032+ /* copy over */
1033+ memcpy(lxt, rhte_src->lxt_start,
1034+ (sizeof(*lxt) * rhte_src->lxt_cnt));
1035+
1036+ /* clone the LBAs in block allocator via ref_cnt */
1037+ mutex_lock(&blka->mutex);
1038+ for (i = 0; i < rhte_src->lxt_cnt; i++) {
1039+ aun = (lxt[i].rlba_base >> MC_CHUNK_SHIFT);
1040+ if (ba_clone(&blka->ba_lun, aun) == -1ULL) {
1041+ /* free the clones already made */
1042+ for (j = 0; j < i; j++) {
1043+ aun = (lxt[j].rlba_base >>
1044+ MC_CHUNK_SHIFT);
1045+ ba_free(&blka->ba_lun, aun);
1046+ }
1047+
1048+ mutex_unlock(&blka->mutex);
1049+ kfree(lxt);
1050+ return -EIO;
1051+ }
1052+ }
1053+ mutex_unlock(&blka->mutex);
1054+ } else {
1055+ lxt = NULL;
1056+ }
1057+
1058+ /*
1059+ * The following sequence is prescribed in the SISlite spec
1060+ * for syncing up with the AFU when adding LXT entries.
1061+ */
1062+ dma_wmb(); /* Make LXT updates are visible */
1063+
1064+ rhte->lxt_start = lxt;
1065+ dma_wmb(); /* Make RHT entry's LXT table update visible */
1066+
1067+ rhte->lxt_cnt = rhte_src->lxt_cnt;
1068+ dma_wmb(); /* Make RHT entry's LXT table size update visible */
1069+
1070+ cxlflash_afu_sync(afu, ctxid, rhndl, AFU_LW_SYNC);
1071+
1072+ pr_debug("%s: returning\n", __func__);
1073+ return 0;
1074+}
1075+
1076+/**
1077+ * cxlflash_disk_clone() - clone a context by making snapshot of another
1078+ * @sdev: SCSI device associated with LUN owning virtual LUN.
1079+ * @clone: Clone ioctl data structure.
1080+ *
1081+ * This routine effectively performs cxlflash_disk_open operation for each
1082+ * in-use virtual resource in the source context. Note that the destination
1083+ * context must be in pristine state and cannot have any resource handles
1084+ * open at the time of the clone.
1085+ *
1086+ * Return: 0 on success, -errno on failure
1087+ */
1088+int cxlflash_disk_clone(struct scsi_device *sdev,
1089+ struct dk_cxlflash_clone *clone)
1090+{
1091+ struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)sdev->host->hostdata;
1092+ struct llun_info *lli = sdev->hostdata;
1093+ struct glun_info *gli = lli->parent;
1094+ struct blka *blka = &gli->blka;
1095+ struct afu *afu = cfg->afu;
1096+ struct dk_cxlflash_release release = { { 0 }, 0 };
1097+
1098+ struct ctx_info *ctxi_src = NULL,
1099+ *ctxi_dst = NULL;
1100+ struct lun_access *lun_access_src, *lun_access_dst;
1101+ u32 perms;
1102+ u64 ctxid_src = DECODE_CTXID(clone->context_id_src),
1103+ ctxid_dst = DECODE_CTXID(clone->context_id_dst),
1104+ rctxid_src = clone->context_id_src,
1105+ rctxid_dst = clone->context_id_dst;
1106+ int adap_fd_src = clone->adap_fd_src;
1107+ int i, j;
1108+ int rc = 0;
1109+ bool found;
1110+ LIST_HEAD(sidecar);
1111+
1112+ pr_debug("%s: ctxid_src=%llu ctxid_dst=%llu adap_fd_src=%d\n",
1113+ __func__, ctxid_src, ctxid_dst, adap_fd_src);
1114+
1115+ /* Do not clone yourself */
1116+ if (unlikely(rctxid_src == rctxid_dst)) {
1117+ rc = -EINVAL;
1118+ goto out;
1119+ }
1120+
1121+ if (unlikely(gli->mode != MODE_VIRTUAL)) {
1122+ rc = -EINVAL;
1123+ pr_debug("%s: Clone not supported on physical LUNs! (%d)\n",
1124+ __func__, gli->mode);
1125+ goto out;
1126+ }
1127+
1128+ ctxi_src = get_context(cfg, rctxid_src, lli, CTX_CTRL_CLONE);
1129+ ctxi_dst = get_context(cfg, rctxid_dst, lli, 0);
1130+ if (unlikely(!ctxi_src || !ctxi_dst)) {
1131+ pr_debug("%s: Bad context! (%llu,%llu)\n", __func__,
1132+ ctxid_src, ctxid_dst);
1133+ rc = -EINVAL;
1134+ goto out;
1135+ }
1136+
1137+ if (unlikely(adap_fd_src != ctxi_src->lfd)) {
1138+ pr_debug("%s: Invalid source adapter fd! (%d)\n",
1139+ __func__, adap_fd_src);
1140+ rc = -EINVAL;
1141+ goto out;
1142+ }
1143+
1144+ /* Verify there is no open resource handle in the destination context */
1145+ for (i = 0; i < MAX_RHT_PER_CONTEXT; i++)
1146+ if (ctxi_dst->rht_start[i].nmask != 0) {
1147+ rc = -EINVAL;
1148+ goto out;
1149+ }
1150+
1151+ /* Clone LUN access list */
1152+ list_for_each_entry(lun_access_src, &ctxi_src->luns, list) {
1153+ found = false;
1154+ list_for_each_entry(lun_access_dst, &ctxi_dst->luns, list)
1155+ if (lun_access_dst->sdev == lun_access_src->sdev) {
1156+ found = true;
1157+ break;
1158+ }
1159+
1160+ if (!found) {
1161+ lun_access_dst = kzalloc(sizeof(*lun_access_dst),
1162+ GFP_KERNEL);
1163+ if (unlikely(!lun_access_dst)) {
1164+ pr_err("%s: Unable to allocate lun_access!\n",
1165+ __func__);
1166+ rc = -ENOMEM;
1167+ goto out;
1168+ }
1169+
1170+ *lun_access_dst = *lun_access_src;
1171+ list_add(&lun_access_dst->list, &sidecar);
1172+ }
1173+ }
1174+
1175+ if (unlikely(!ctxi_src->rht_out)) {
1176+ pr_debug("%s: Nothing to clone!\n", __func__);
1177+ goto out_success;
1178+ }
1179+
1180+ /* User specified permission on attach */
1181+ perms = ctxi_dst->rht_perms;
1182+
1183+ /*
1184+ * Copy over checked-out RHT (and their associated LXT) entries by
1185+ * hand, stopping after we've copied all outstanding entries and
1186+ * cleaning up if the clone fails.
1187+ *
1188+ * Note: This loop is equivalent to performing cxlflash_disk_open and
1189+ * cxlflash_vlun_resize. As such, LUN accounting needs to be taken into
1190+ * account by attaching after each successful RHT entry clone. In the
1191+ * event that a clone failure is experienced, the LUN detach is handled
1192+ * via the cleanup performed by _cxlflash_disk_release.
1193+ */
1194+ for (i = 0; i < MAX_RHT_PER_CONTEXT; i++) {
1195+ if (ctxi_src->rht_out == ctxi_dst->rht_out)
1196+ break;
1197+ if (ctxi_src->rht_start[i].nmask == 0)
1198+ continue;
1199+
1200+ /* Consume a destination RHT entry */
1201+ ctxi_dst->rht_out++;
1202+ ctxi_dst->rht_start[i].nmask = ctxi_src->rht_start[i].nmask;
1203+ ctxi_dst->rht_start[i].fp =
1204+ SISL_RHT_FP_CLONE(ctxi_src->rht_start[i].fp, perms);
1205+ ctxi_dst->rht_lun[i] = ctxi_src->rht_lun[i];
1206+
1207+ rc = clone_lxt(afu, blka, ctxid_dst, i,
1208+ &ctxi_dst->rht_start[i],
1209+ &ctxi_src->rht_start[i]);
1210+ if (rc) {
1211+ marshal_clone_to_rele(clone, &release);
1212+ for (j = 0; j < i; j++) {
1213+ release.rsrc_handle = j;
1214+ _cxlflash_disk_release(sdev, ctxi_dst,
1215+ &release);
1216+ }
1217+
1218+ /* Put back the one we failed on */
1219+ rhte_checkin(ctxi_dst, &ctxi_dst->rht_start[i]);
1220+ goto err;
1221+ }
1222+
1223+ cxlflash_lun_attach(gli, gli->mode, false);
1224+ }
1225+
1226+out_success:
1227+ list_splice(&sidecar, &ctxi_dst->luns);
1228+ sys_close(adap_fd_src);
1229+
1230+ /* fall through */
1231+out:
1232+ if (ctxi_src)
1233+ put_context(ctxi_src);
1234+ if (ctxi_dst)
1235+ put_context(ctxi_dst);
1236+ pr_debug("%s: returning rc=%d\n", __func__, rc);
1237+ return rc;
1238+
1239+err:
1240+ list_for_each_entry_safe(lun_access_src, lun_access_dst, &sidecar, list)
1241+ kfree(lun_access_src);
1242+ goto out;
1243+}
drivers/scsi/cxlflash/vlun.h+86−0
@@ -0,0 +1,86 @@
1+/*
2+ * CXL Flash Device Driver
3+ *
4+ * Written by: Manoj N. Kumar <manoj@linux.vnet.ibm.com>, IBM Corporation
5+ * Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation
6+ *
7+ * Copyright (C) 2015 IBM Corporation
8+ *
9+ * This program is free software; you can redistribute it and/or
10+ * modify it under the terms of the GNU General Public License
11+ * as published by the Free Software Foundation; either version
12+ * 2 of the License, or (at your option) any later version.
13+ */
14+
15+#ifndef _CXLFLASH_VLUN_H
16+#define _CXLFLASH_VLUN_H
17+
18+/* RHT - Resource Handle Table */
19+#define MC_RHT_NMASK 16 /* in bits */
20+#define MC_CHUNK_SHIFT MC_RHT_NMASK /* shift to go from LBA to chunk# */
21+
22+#define HIBIT (BITS_PER_LONG - 1)
23+
24+#define MAX_AUN_CLONE_CNT 0xFF
25+
26+/*
27+ * LXT - LBA Translation Table
28+ *
29+ * +-------+-------+-------+-------+-------+-------+-------+---+---+
30+ * | RLBA_BASE |LUN_IDX| P |SEL|
31+ * +-------+-------+-------+-------+-------+-------+-------+---+---+
32+ *
33+ * The LXT Entry contains the physical LBA where the chunk starts (RLBA_BASE).
34+ * AFU ORes the low order bits from the virtual LBA (offset into the chunk)
35+ * with RLBA_BASE. The result is the physical LBA to be sent to storage.
36+ * The LXT Entry also contains an index to a LUN TBL and a bitmask of which
37+ * outgoing (FC) * ports can be selected. The port select bit-mask is ANDed
38+ * with a global port select bit-mask maintained by the driver.
39+ * In addition, it has permission bits that are ANDed with the
40+ * RHT permissions to arrive at the final permissions for the chunk.
41+ *
42+ * LXT tables are allocated dynamically in groups. This is done to avoid
43+ * a malloc/free overhead each time the LXT has to grow or shrink.
44+ *
45+ * Based on the current lxt_cnt (used), it is always possible to know
46+ * how many are allocated (used+free). The number of allocated entries is
47+ * not stored anywhere.
48+ *
49+ * The LXT table is re-allocated whenever it needs to cross into another group.
50+*/
51+#define LXT_GROUP_SIZE 8
52+#define LXT_NUM_GROUPS(lxt_cnt) (((lxt_cnt) + 7)/8) /* alloc'ed groups */
53+#define LXT_LUNIDX_SHIFT 8 /* LXT entry, shift for LUN index */
54+#define LXT_PERM_SHIFT 4 /* LXT entry, shift for permission bits */
55+
56+struct ba_lun_info {
57+ u64 *lun_alloc_map;
58+ u32 lun_bmap_size;
59+ u32 total_aus;
60+ u64 free_aun_cnt;
61+
62+ /* indices to be used for elevator lookup of free map */
63+ u32 free_low_idx;
64+ u32 free_curr_idx;
65+ u32 free_high_idx;
66+
67+ u8 *aun_clone_map;
68+};
69+
70+struct ba_lun {
71+ u64 lun_id;
72+ u64 wwpn;
73+ size_t lsize; /* LUN size in number of LBAs */
74+ size_t lba_size; /* LBA size in number of bytes */
75+ size_t au_size; /* Allocation Unit size in number of LBAs */
76+ struct ba_lun_info *ba_lun_handle;
77+};
78+
79+/* Block Allocator */
80+struct blka {
81+ struct ba_lun ba_lun;
82+ u64 nchunk; /* number of chunks */
83+ struct mutex mutex;
84+};
85+
86+#endif /* ifndef _CXLFLASH_SUPERPIPE_H */
drivers/scsi/hpsa.c+185−116
@@ -1,6 +1,7 @@
11 /*
22 * Disk Array driver for HP Smart Array SAS controllers
3− * Copyright 2000, 2014 Hewlett-Packard Development Company, L.P.
3+ * Copyright 2014-2015 PMC-Sierra, Inc.
4+ * Copyright 2000,2009-2015 Hewlett-Packard Development Company, L.P.
45 *
56 * This program is free software; you can redistribute it and/or modify
67 * it under the terms of the GNU General Public License as published by
@@ -11,11 +12,7 @@ · 4 unmodified lines
1112 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
1213 * NON INFRINGEMENT. See the GNU General Public License for more details.
1314 *
14− * You should have received a copy of the GNU General Public License
15− * along with this program; if not, write to the Free Software
16− * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17− *
18− * Questions/Comments/Bugfixes to iss_storagedev@hp.com
15+ * Questions/Comments/Bugfixes to storagedev@pmcs.com
1916 *
2017 */
2118
@@ -132,6 +129,11 @@ static const struct pci_device_id hpsa_pci_device_id[] = { · 110 unmodified lines
132129 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21CD},
133130 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSI, 0x103C, 0x21CE},
134131 {PCI_VENDOR_ID_ADAPTEC2, 0x0290, 0x9005, 0x0580},
132+ {PCI_VENDOR_ID_ADAPTEC2, 0x0290, 0x9005, 0x0581},
133+ {PCI_VENDOR_ID_ADAPTEC2, 0x0290, 0x9005, 0x0582},
134+ {PCI_VENDOR_ID_ADAPTEC2, 0x0290, 0x9005, 0x0583},
135+ {PCI_VENDOR_ID_ADAPTEC2, 0x0290, 0x9005, 0x0584},
136+ {PCI_VENDOR_ID_ADAPTEC2, 0x0290, 0x9005, 0x0585},
135137 {PCI_VENDOR_ID_HP_3PAR, 0x0075, 0x1590, 0x0076},
136138 {PCI_VENDOR_ID_HP_3PAR, 0x0075, 0x1590, 0x0087},
137139 {PCI_VENDOR_ID_HP_3PAR, 0x0075, 0x1590, 0x007D},
@@ -190,6 +192,11 @@ static struct board_type products[] = { · 52 unmodified lines
190192 {0x21CD103C, "Smart Array", &SA5_access},
191193 {0x21CE103C, "Smart HBA", &SA5_access},
192194 {0x05809005, "SmartHBA-SA", &SA5_access},
195+ {0x05819005, "SmartHBA-SA 8i", &SA5_access},
196+ {0x05829005, "SmartHBA-SA 8i8e", &SA5_access},
197+ {0x05839005, "SmartHBA-SA 8e", &SA5_access},
198+ {0x05849005, "SmartHBA-SA 16i", &SA5_access},
199+ {0x05859005, "SmartHBA-SA 4i4e", &SA5_access},
193200 {0x00761590, "HP Storage P1224 Array Controller", &SA5_access},
194201 {0x00871590, "HP Storage P1224e Array Controller", &SA5_access},
195202 {0x007D1590, "HP Storage P1228 Array Controller", &SA5_access},
@@ -267,6 +274,7 @@ static int hpsa_scsi_ioaccel_queue_command(struct ctlr_info *h, · 71 unmodified lines
267274 static void hpsa_command_resubmit_worker(struct work_struct *work);
268275 static u32 lockup_detected(struct ctlr_info *h);
269276 static int detect_controller_lockup(struct ctlr_info *h);
277+static int is_ext_target(struct ctlr_info *h, struct hpsa_scsi_dev_t *device);
270278
271279 static inline struct ctlr_info *sdev_to_hba(struct scsi_device *sdev)
272280 {
@@ -325,7 +333,7 @@ static int check_for_unit_attention(struct ctlr_info *h, · 52 unmodified lines
325333
326334 decode_sense_data(c->err_info->SenseInfo, sense_len,
327335 &sense_key, &asc, &ascq);
328− if (sense_key != UNIT_ATTENTION || asc == -1)
336+ if (sense_key != UNIT_ATTENTION || asc == 0xff)
329337 return 0;
330338
331339 switch (asc) {
@@ -717,12 +725,107 @@ static ssize_t host_show_hp_ssd_smart_path_enabled(struct device *dev, · 385 unmodified lines
717725 return snprintf(buf, 20, "%d\n", offload_enabled);
718726 }
719727
728+#define MAX_PATHS 8
729+#define PATH_STRING_LEN 50
730+
731+static ssize_t path_info_show(struct device *dev,
732+ struct device_attribute *attr, char *buf)
733+{
734+ struct ctlr_info *h;
735+ struct scsi_device *sdev;
736+ struct hpsa_scsi_dev_t *hdev;
737+ unsigned long flags;
738+ int i;
739+ int output_len = 0;
740+ u8 box;
741+ u8 bay;
742+ u8 path_map_index = 0;
743+ char *active;
744+ unsigned char phys_connector[2];
745+ unsigned char path[MAX_PATHS][PATH_STRING_LEN];
746+
747+ memset(path, 0, MAX_PATHS * PATH_STRING_LEN);
748+ sdev = to_scsi_device(dev);
749+ h = sdev_to_hba(sdev);
750+ spin_lock_irqsave(&h->devlock, flags);
751+ hdev = sdev->hostdata;
752+ if (!hdev) {
753+ spin_unlock_irqrestore(&h->devlock, flags);
754+ return -ENODEV;
755+ }
756+
757+ bay = hdev->bay;
758+ for (i = 0; i < MAX_PATHS; i++) {
759+ path_map_index = 1<<i;
760+ if (i == hdev->active_path_index)
761+ active = "Active";
762+ else if (hdev->path_map & path_map_index)
763+ active = "Inactive";
764+ else
765+ continue;
766+
767+ output_len = snprintf(path[i],
768+ PATH_STRING_LEN, "[%d:%d:%d:%d] %20.20s ",
769+ h->scsi_host->host_no,
770+ hdev->bus, hdev->target, hdev->lun,
771+ scsi_device_type(hdev->devtype));
772+
773+ if (is_ext_target(h, hdev) ||
774+ (hdev->devtype == TYPE_RAID) ||
775+ is_logical_dev_addr_mode(hdev->scsi3addr)) {
776+ output_len += snprintf(path[i] + output_len,
777+ PATH_STRING_LEN, "%s\n",
778+ active);
779+ continue;
780+ }
781+
782+ box = hdev->box[i];
783+ memcpy(&phys_connector, &hdev->phys_connector[i],
784+ sizeof(phys_connector));
785+ if (phys_connector[0] < '0')
786+ phys_connector[0] = '0';
787+ if (phys_connector[1] < '0')
788+ phys_connector[1] = '0';
789+ if (hdev->phys_connector[i] > 0)
790+ output_len += snprintf(path[i] + output_len,
791+ PATH_STRING_LEN,
792+ "PORT: %.2s ",
793+ phys_connector);
794+ if (hdev->devtype == TYPE_DISK &&
795+ hdev->expose_state != HPSA_DO_NOT_EXPOSE) {
796+ if (box == 0 || box == 0xFF) {
797+ output_len += snprintf(path[i] + output_len,
798+ PATH_STRING_LEN,
799+ "BAY: %hhu %s\n",
800+ bay, active);
801+ } else {
802+ output_len += snprintf(path[i] + output_len,
803+ PATH_STRING_LEN,
804+ "BOX: %hhu BAY: %hhu %s\n",
805+ box, bay, active);
806+ }
807+ } else if (box != 0 && box != 0xFF) {
808+ output_len += snprintf(path[i] + output_len,
809+ PATH_STRING_LEN, "BOX: %hhu %s\n",
810+ box, active);
811+ } else
812+ output_len += snprintf(path[i] + output_len,
813+ PATH_STRING_LEN, "%s\n", active);
814+ }
815+
816+ spin_unlock_irqrestore(&h->devlock, flags);
817+ return snprintf(buf, output_len+1, "%s%s%s%s%s%s%s%s",
818+ path[0], path[1], path[2], path[3],
819+ path[4], path[5], path[6], path[7]);
820+}
821+
720822 static DEVICE_ATTR(raid_level, S_IRUGO, raid_level_show, NULL);
721823 static DEVICE_ATTR(lunid, S_IRUGO, lunid_show, NULL);
722824 static DEVICE_ATTR(unique_id, S_IRUGO, unique_id_show, NULL);
723825 static DEVICE_ATTR(rescan, S_IWUSR, NULL, host_store_rescan);
724826 static DEVICE_ATTR(hp_ssd_smart_path_enabled, S_IRUGO,
725827 host_show_hp_ssd_smart_path_enabled, NULL);
828+static DEVICE_ATTR(path_info, S_IRUGO, path_info_show, NULL);
726829 static DEVICE_ATTR(hp_ssd_smart_path_status, S_IWUSR|S_IRUGO|S_IROTH,
727830 host_show_hp_ssd_smart_path_status,
728831 host_store_hp_ssd_smart_path_status);
@@ -744,6 +847,7 @@ static struct device_attribute *hpsa_sdev_attrs[] = { · 15 unmodified lines
744847 &dev_attr_lunid,
745848 &dev_attr_unique_id,
746849 &dev_attr_hp_ssd_smart_path_enabled,
850+ &dev_attr_path_info,
747851 &dev_attr_lockup_detected,
748852 NULL,
749853 };
@@ -1083,17 +1187,19 @@ static int hpsa_scsi_add_entry(struct ctlr_info *h, int hostno, · 333 unmodified lines
10831187
10841188 /* This is a non-zero lun of a multi-lun device.
10851189 * Search through our list and find the device which
1086− * has the same 8 byte LUN address, excepting byte 4.
1190+ * has the same 8 byte LUN address, excepting byte 4 and 5.
10871191 * Assign the same bus and target for this new LUN.
10881192 * Use the logical unit number from the firmware.
10891193 */
10901194 memcpy(addr1, device->scsi3addr, 8);
10911195 addr1[4] = 0;
1196+ addr1[5] = 0;
10921197 for (i = 0; i < n; i++) {
10931198 sd = h->dev[i];
10941199 memcpy(addr2, sd->scsi3addr, 8);
10951200 addr2[4] = 0;
1096− /* differ only in byte 4? */
1201+ addr2[5] = 0;
1202+ /* differ only in byte 4 and 5? */
10971203 if (memcmp(addr1, addr2, 8) == 0) {
10981204 device->bus = sd->bus;
10991205 device->target = sd->target;
@@ -1286,8 +1392,9 @@ static inline int device_updated(struct hpsa_scsi_dev_t *dev1, · 186 unmodified lines
12861392 return 1;
12871393 if (dev1->offload_enabled != dev2->offload_enabled)
12881394 return 1;
1289− if (dev1->queue_depth != dev2->queue_depth)
1290− return 1;
1395+ if (!is_logical_dev_addr_mode(dev1->scsi3addr))
1396+ if (dev1->queue_depth != dev2->queue_depth)
1397+ return 1;
12911398 return 0;
12921399 }
12931400
@@ -1376,17 +1483,23 @@ static void hpsa_show_volume_status(struct ctlr_info *h, · 82 unmodified lines
13761483 h->scsi_host->host_no,
13771484 sd->bus, sd->target, sd->lun);
13781485 break;
1486+ case HPSA_LV_NOT_AVAILABLE:
1487+ dev_info(&h->pdev->dev,
1488+ "C%d:B%d:T%d:L%d Volume is waiting for transforming volume.\n",
1489+ h->scsi_host->host_no,
1490+ sd->bus, sd->target, sd->lun);
1491+ break;
13791492 case HPSA_LV_UNDERGOING_RPI:
13801493 dev_info(&h->pdev->dev,
1381− "C%d:B%d:T%d:L%d Volume is undergoing rapid parity initialization process.\n",
1494+ "C%d:B%d:T%d:L%d Volume is undergoing rapid parity init.\n",
13821495 h->scsi_host->host_no,
13831496 sd->bus, sd->target, sd->lun);
13841497 break;
13851498 case HPSA_LV_PENDING_RPI:
13861499 dev_info(&h->pdev->dev,
1387− "C%d:B%d:T%d:L%d Volume is queued for rapid parity initialization process.\n",
1388− h->scsi_host->host_no,
1389− sd->bus, sd->target, sd->lun);
1500+ "C%d:B%d:T%d:L%d Volume is queued for rapid parity initialization process.\n",
1501+ h->scsi_host->host_no,
1502+ sd->bus, sd->target, sd->lun);
13901503 break;
13911504 case HPSA_LV_ENCRYPTED_NO_KEY:
13921505 dev_info(&h->pdev->dev,
@@ -2585,34 +2698,6 @@ out: · 1192 unmodified lines
25852698 return rc;
25862699 }
25872700
2588−static int hpsa_bmic_ctrl_mode_sense(struct ctlr_info *h,
2589− unsigned char *scsi3addr, unsigned char page,
2590− struct bmic_controller_parameters *buf, size_t bufsize)
2591−{
2592− int rc = IO_OK;
2593− struct CommandList *c;
2594− struct ErrorInfo *ei;
2595−
2596− c = cmd_alloc(h);
2597− if (fill_cmd(c, BMIC_SENSE_CONTROLLER_PARAMETERS, h, buf, bufsize,
2598− page, scsi3addr, TYPE_CMD)) {
2599− rc = -1;
2600− goto out;
2601− }
2602− rc = hpsa_scsi_do_simple_cmd_with_retry(h, c,
2603− PCI_DMA_FROMDEVICE, NO_TIMEOUT);
2604− if (rc)
2605− goto out;
2606− ei = c->err_info;
2607− if (ei->CommandStatus != 0 && ei->CommandStatus != CMD_DATA_UNDERRUN) {
2608− hpsa_scsi_interpret_error(h, c);
2609− rc = -1;
2610− }
2611−out:
2612− cmd_free(h, c);
2613− return rc;
2614−}
2615−
26162701 static int hpsa_send_reset(struct ctlr_info *h, unsigned char *scsi3addr,
26172702 u8 reset_type, int reply_queue)
26182703 {
@@ -2749,11 +2834,10 @@ static int hpsa_do_reset(struct ctlr_info *h, struct hpsa_scsi_dev_t *dev, · 130 unmodified lines
27492834 lockup_detected(h));
27502835
27512836 if (unlikely(lockup_detected(h))) {
2752− dev_warn(&h->pdev->dev,
2753− "Controller lockup detected during reset wait\n");
2754− mutex_unlock(&h->reset_mutex);
2755− rc = -ENODEV;
2756− }
2837+ dev_warn(&h->pdev->dev,
2838+ "Controller lockup detected during reset wait\n");
2839+ rc = -ENODEV;
2840+ }
27572841
27582842 if (unlikely(rc))
27592843 atomic_set(&dev->reset_cmds_out, 0);
@@ -3186,6 +3270,7 @@ static int hpsa_volume_offline(struct ctlr_info *h, · 426 unmodified lines
31863270 /* Keep volume offline in certain cases: */
31873271 switch (ldstat) {
31883272 case HPSA_LV_UNDERGOING_ERASE:
3273+ case HPSA_LV_NOT_AVAILABLE:
31893274 case HPSA_LV_UNDERGOING_RPI:
31903275 case HPSA_LV_PENDING_RPI:
31913276 case HPSA_LV_ENCRYPTED_NO_KEY:
@@ -3562,29 +3647,6 @@ static u8 *figure_lunaddrbytes(struct ctlr_info *h, int raid_ctlr_position, · 370 unmodified lines
35623647 return NULL;
35633648 }
35643649
3565−static int hpsa_hba_mode_enabled(struct ctlr_info *h)
3566−{
3567− int rc;
3568− int hba_mode_enabled;
3569− struct bmic_controller_parameters *ctlr_params;
3570− ctlr_params = kzalloc(sizeof(struct bmic_controller_parameters),
3571− GFP_KERNEL);
3572−
3573− if (!ctlr_params)
3574− return -ENOMEM;
3575− rc = hpsa_bmic_ctrl_mode_sense(h, RAID_CTLR_LUNID, 0, ctlr_params,
3576− sizeof(struct bmic_controller_parameters));
3577− if (rc) {
3578− kfree(ctlr_params);
3579− return rc;
3580− }
3581−
3582− hba_mode_enabled =
3583− ((ctlr_params->nvram_flags & HBA_MODE_ENABLED_FLAG) != 0);
3584− kfree(ctlr_params);
3585− return hba_mode_enabled;
3586−}
3587−
35883650 /* get physical drive ioaccel handle and queue depth */
35893651 static void hpsa_get_ioaccel_drive_info(struct ctlr_info *h,
35903652 struct hpsa_scsi_dev_t *dev,
@@ -3615,6 +3677,31 @@ static void hpsa_get_ioaccel_drive_info(struct ctlr_info *h, · 24 unmodified lines
36153677 atomic_set(&dev->reset_cmds_out, 0);
36163678 }
36173679
3680+static void hpsa_get_path_info(struct hpsa_scsi_dev_t *this_device,
3681+ u8 *lunaddrbytes,
3682+ struct bmic_identify_physical_device *id_phys)
3683+{
3684+ if (PHYS_IOACCEL(lunaddrbytes)
3685+ && this_device->ioaccel_handle)
3686+ this_device->hba_ioaccel_enabled = 1;
3687+
3688+ memcpy(&this_device->active_path_index,
3689+ &id_phys->active_path_number,
3690+ sizeof(this_device->active_path_index));
3691+ memcpy(&this_device->path_map,
3692+ &id_phys->redundant_path_present_map,
3693+ sizeof(this_device->path_map));
3694+ memcpy(&this_device->box,
3695+ &id_phys->alternate_paths_phys_box_on_port,
3696+ sizeof(this_device->box));
3697+ memcpy(&this_device->phys_connector,
3698+ &id_phys->alternate_paths_phys_connector,
3699+ sizeof(this_device->phys_connector));
3700+ memcpy(&this_device->bay,
3701+ &id_phys->phys_bay_in_box,
3702+ sizeof(this_device->bay));
3703+}
3704+
36183705 static void hpsa_update_scsi_devices(struct ctlr_info *h, int hostno)
36193706 {
36203707 /* the idea here is we could get notified
@@ -3637,7 +3724,6 @@ static void hpsa_update_scsi_devices(struct ctlr_info *h, int hostno) · 16 unmodified lines
36373724 int ncurrent = 0;
36383725 int i, n_ext_target_devs, ndevs_to_allocate;
36393726 int raid_ctlr_position;
3640− int rescan_hba_mode;
36413727 DECLARE_BITMAP(lunzerobits, MAX_EXT_TARGETS);
36423728
36433729 currentsd = kzalloc(sizeof(*currentsd) * HPSA_MAX_DEVICES, GFP_KERNEL);
@@ -3653,17 +3739,6 @@ static void hpsa_update_scsi_devices(struct ctlr_info *h, int hostno) · 9 unmodified lines
36533739 }
36543740 memset(lunzerobits, 0, sizeof(lunzerobits));
36553741
3656− rescan_hba_mode = hpsa_hba_mode_enabled(h);
3657− if (rescan_hba_mode < 0)
3658− goto out;
3659−
3660− if (!h->hba_mode_enabled && rescan_hba_mode)
3661− dev_warn(&h->pdev->dev, "HBA mode enabled\n");
3662− else if (h->hba_mode_enabled && !rescan_hba_mode)
3663− dev_warn(&h->pdev->dev, "HBA mode disabled\n");
3664−
3665− h->hba_mode_enabled = rescan_hba_mode;
3666−
36673742 if (hpsa_gather_lun_info(h, physdev_list, &nphysicals,
36683743 logdev_list, &nlogicals))
36693744 goto out;
@@ -3739,9 +3814,6 @@ static void hpsa_update_scsi_devices(struct ctlr_info *h, int hostno) · 69 unmodified lines
37393814 /* do not expose masked devices */
37403815 if (MASKED_DEVICE(lunaddrbytes) &&
37413816 i < nphysicals + (raid_ctlr_position == 0)) {
3742− if (h->hba_mode_enabled)
3743− dev_warn(&h->pdev->dev,
3744− "Masked physical device detected\n");
37453817 this_device->expose_state = HPSA_DO_NOT_EXPOSE;
37463818 } else {
37473819 this_device->expose_state =
@@ -3761,30 +3833,21 @@ static void hpsa_update_scsi_devices(struct ctlr_info *h, int hostno) · 13 unmodified lines
37613833 ncurrent++;
37623834 break;
37633835 case TYPE_DISK:
3764− if (i >= nphysicals) {
3765− ncurrent++;
3766− break;
3767− }
3768−
3769− if (h->hba_mode_enabled)
3770− /* never use raid mapper in HBA mode */
3836+ if (i < nphysicals + (raid_ctlr_position == 0)) {
3837+ /* The disk is in HBA mode. */
3838+ /* Never use RAID mapper in HBA mode. */
37713839 this_device->offload_enabled = 0;
3772− else if (!(h->transMethod & CFGTBL_Trans_io_accel1 ||
3773− h->transMethod & CFGTBL_Trans_io_accel2))
3774− break;
3775−
3776− hpsa_get_ioaccel_drive_info(h, this_device,
3777− lunaddrbytes, id_phys);
3778− atomic_set(&this_device->ioaccel_cmds_out, 0);
3840+ hpsa_get_ioaccel_drive_info(h, this_device,
3841+ lunaddrbytes, id_phys);
3842+ hpsa_get_path_info(this_device, lunaddrbytes,
3843+ id_phys);
3844+ }
37793845 ncurrent++;
37803846 break;
37813847 case TYPE_TAPE:
37823848 case TYPE_MEDIUM_CHANGER:
3783− ncurrent++;
3784− break;
37853849 case TYPE_ENCLOSURE:
3786− if (h->hba_mode_enabled)
3787− ncurrent++;
3850+ ncurrent++;
37883851 break;
37893852 case TYPE_RAID:
37903853 /* Only present the Smartarray HBA as a RAID controller.
@@ -5104,7 +5167,7 @@ static int hpsa_eh_device_reset_handler(struct scsi_cmnd *scsicmd) · 1313 unmodified lines
51045167 int rc;
51055168 struct ctlr_info *h;
51065169 struct hpsa_scsi_dev_t *dev;
5107− char msg[40];
5170+ char msg[48];
51085171
51095172 /* find the controller to which the command to be aborted was sent */
51105173 h = sdev_to_hba(scsicmd->device);
@@ -5122,16 +5185,18 @@ static int hpsa_eh_device_reset_handler(struct scsi_cmnd *scsicmd) · 11 unmodified lines
51225185
51235186 /* if controller locked up, we can guarantee command won't complete */
51245187 if (lockup_detected(h)) {
5125− sprintf(msg, "cmd %d RESET FAILED, lockup detected",
5126− hpsa_get_cmd_index(scsicmd));
5188+ snprintf(msg, sizeof(msg),
5189+ "cmd %d RESET FAILED, lockup detected",
5190+ hpsa_get_cmd_index(scsicmd));
51275191 hpsa_show_dev_msg(KERN_WARNING, h, dev, msg);
51285192 return FAILED;
51295193 }
51305194
51315195 /* this reset request might be the result of a lockup; check */
51325196 if (detect_controller_lockup(h)) {
5133− sprintf(msg, "cmd %d RESET FAILED, new lockup detected",
5134− hpsa_get_cmd_index(scsicmd));
5197+ snprintf(msg, sizeof(msg),
5198+ "cmd %d RESET FAILED, new lockup detected",
5199+ hpsa_get_cmd_index(scsicmd));
51355200 hpsa_show_dev_msg(KERN_WARNING, h, dev, msg);
51365201 return FAILED;
51375202 }
@@ -5145,7 +5210,8 @@ static int hpsa_eh_device_reset_handler(struct scsi_cmnd *scsicmd) · 7 unmodified lines
51455210 /* send a reset to the SCSI LUN which the command was sent to */
51465211 rc = hpsa_do_reset(h, dev, dev->scsi3addr, HPSA_RESET_TYPE_LUN,
51475212 DEFAULT_REPLY_QUEUE);
5148− sprintf(msg, "reset %s", rc == 0 ? "completed successfully" : "failed");
5213+ snprintf(msg, sizeof(msg), "reset %s",
5214+ rc == 0 ? "completed successfully" : "failed");
51495215 hpsa_show_dev_msg(KERN_WARNING, h, dev, msg);
51505216 return rc == 0 ? SUCCESS : FAILED;
51515217 }
@@ -7989,7 +8055,6 @@ reinit_after_soft_reset: · 2837 unmodified lines
79898055
79908056 pci_set_drvdata(pdev, h);
79918057 h->ndevices = 0;
7992− h->hba_mode_enabled = 0;
79938058
79948059 spin_lock_init(&h->devlock);
79958060 rc = hpsa_put_ctlr_into_performant_mode(h);
@@ -8054,7 +8119,7 @@ reinit_after_soft_reset: · 58 unmodified lines
80548119 rc = hpsa_kdump_soft_reset(h);
80558120 if (rc)
80568121 /* Neither hard nor soft reset worked, we're hosed. */
8057− goto clean9;
8122+ goto clean7;
80588123
80598124 dev_info(&h->pdev->dev, "Board READY.\n");
80608125 dev_info(&h->pdev->dev,
@@ -8100,8 +8165,6 @@ reinit_after_soft_reset: · 39 unmodified lines
81008165 h->heartbeat_sample_interval);
81018166 return 0;
81028167
8103−clean9: /* wq, sh, perf, sg, cmd, irq, shost, pci, lu, aer/h */
8104− kfree(h->hba_inquiry_data);
81058168 clean7: /* perf, sg, cmd, irq, shost, pci, lu, aer/h */
81068169 hpsa_free_performant_mode(h);
81078170 h->access.set_intr_mask(h, HPSA_INTR_OFF);
@@ -8209,6 +8272,14 @@ static void hpsa_remove_one(struct pci_dev *pdev) · 101 unmodified lines
82098272 destroy_workqueue(h->rescan_ctlr_wq);
82108273 destroy_workqueue(h->resubmit_wq);
82118274
8275+ /*
8276+ * Call before disabling interrupts.
8277+ * scsi_remove_host can trigger I/O operations especially
8278+ * when multipath is enabled. There can be SYNCHRONIZE CACHE
8279+ * operations which cannot complete and will hang the system.
8280+ */
8281+ if (h->scsi_host)
8282+ scsi_remove_host(h->scsi_host); /* init_one 8 */
82128283 /* includes hpsa_free_irqs - init_one 4 */
82138284 /* includes hpsa_disable_interrupt_mode - pci_init 2 */
82148285 hpsa_shutdown(pdev);
@@ -8217,8 +8288,6 @@ static void hpsa_remove_one(struct pci_dev *pdev) · 2 unmodified lines
82178288
82188289 kfree(h->hba_inquiry_data); /* init_one 10 */
82198290 h->hba_inquiry_data = NULL; /* init_one 10 */
8220− if (h->scsi_host)
8221− scsi_remove_host(h->scsi_host); /* init_one 8 */
82228291 hpsa_free_ioaccel2_sg_chain_blocks(h);
82238292 hpsa_free_performant_mode(h); /* init_one 7 */
82248293 hpsa_free_sg_chain_blocks(h); /* init_one 6 */
drivers/scsi/hpsa.h+8−8
@@ -1,6 +1,7 @@
11 /*
22 * Disk Array driver for HP Smart Array SAS controllers
3− * Copyright 2000, 2014 Hewlett-Packard Development Company, L.P.
3+ * Copyright 2014-2015 PMC-Sierra, Inc.
4+ * Copyright 2000,2009-2015 Hewlett-Packard Development Company, L.P.
45 *
56 * This program is free software; you can redistribute it and/or modify
67 * it under the terms of the GNU General Public License as published by
@@ -11,11 +12,7 @@ · 4 unmodified lines
1112 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
1213 * NON INFRINGEMENT. See the GNU General Public License for more details.
1314 *
14− * You should have received a copy of the GNU General Public License
15− * along with this program; if not, write to the Free Software
16− * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17− *
18− * Questions/Comments/Bugfixes to iss_storagedev@hp.com
15+ * Questions/Comments/Bugfixes to storagedev@pmcs.com
1916 *
2017 */
2118 #ifndef HPSA_H
@@ -53,6 +50,11 @@ struct hpsa_scsi_dev_t { · 31 unmodified lines
5350 * device via "ioaccel" path.
5451 */
5552 u32 ioaccel_handle;
53+ u8 active_path_index;
54+ u8 path_map;
55+ u8 bay;
56+ u8 box[8];
57+ u16 phys_connector[8];
5658 int offload_config; /* I/O accel RAID offload configured */
5759 int offload_enabled; /* I/O accel RAID offload enabled */
5860 int offload_to_be_enabled;
@@ -114,7 +116,6 @@ struct bmic_controller_parameters { · 55 unmodified lines
114116 u8 automatic_drive_slamming;
115117 u8 reserved1;
116118 u8 nvram_flags;
117−#define HBA_MODE_ENABLED_FLAG (1 << 3)
118119 u8 cache_nvram_flags;
119120 u8 drive_config_flags;
120121 u16 reserved2;
@@ -153,7 +154,6 @@ struct ctlr_info { · 32 unmodified lines
153154 unsigned int msi_vector;
154155 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
155156 struct access_method access;
156− char hba_mode_enabled;
157157
158158 /* queue and queue Info */
159159 unsigned int Qdepth;
drivers/scsi/hpsa_cmd.h+4−6
@@ -1,6 +1,7 @@
11 /*
22 * Disk Array driver for HP Smart Array SAS controllers
3− * Copyright 2000, 2014 Hewlett-Packard Development Company, L.P.
3+ * Copyright 2014-2015 PMC-Sierra, Inc.
4+ * Copyright 2000,2009-2015 Hewlett-Packard Development Company, L.P.
45 *
56 * This program is free software; you can redistribute it and/or modify
67 * it under the terms of the GNU General Public License as published by
@@ -11,11 +12,7 @@ · 4 unmodified lines
1112 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
1213 * NON INFRINGEMENT. See the GNU General Public License for more details.
1314 *
14− * You should have received a copy of the GNU General Public License
15− * along with this program; if not, write to the Free Software
16− * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17− *
18− * Questions/Comments/Bugfixes to iss_storagedev@hp.com
15+ * Questions/Comments/Bugfixes to storagedev@pmcs.com
1916 *
2017 */
2118 #ifndef HPSA_CMD_H
@@ -167,6 +164,7 @@ · 145 unmodified lines
167164 /* Logical volume states */
168165 #define HPSA_VPD_LV_STATUS_UNSUPPORTED 0xff
169166 #define HPSA_LV_OK 0x0
167+#define HPSA_LV_NOT_AVAILABLE 0x0b
170168 #define HPSA_LV_UNDERGOING_ERASE 0x0F
171169 #define HPSA_LV_UNDERGOING_RPI 0x12
172170 #define HPSA_LV_PENDING_RPI 0x13
drivers/scsi/hptiop.c+62−35
@@ -1,6 +1,6 @@
11 /*
22 * HighPoint RR3xxx/4xxx controller driver for Linux
3− * Copyright (C) 2006-2012 HighPoint Technologies, Inc. All Rights Reserved.
3+ * Copyright (C) 2006-2015 HighPoint Technologies, Inc. All Rights Reserved.
44 *
55 * This program is free software; you can redistribute it and/or modify
66 * it under the terms of the GNU General Public License as published by
@@ -42,7 +42,7 @@ MODULE_DESCRIPTION("HighPoint RocketRAID 3xxx/4xxx Controller Driver"); · 35 unmodified lines
4242
4343 static char driver_name[] = "hptiop";
4444 static const char driver_name_long[] = "RocketRAID 3xxx/4xxx Controller driver";
45−static const char driver_ver[] = "v1.8";
45+static const char driver_ver[] = "v1.10.0";
4646
4747 static int iop_send_sync_msg(struct hptiop_hba *hba, u32 msg, u32 millisec);
4848 static void hptiop_finish_scsi_req(struct hptiop_hba *hba, u32 tag,
@@ -764,9 +764,7 @@ static void hptiop_finish_scsi_req(struct hptiop_hba *hba, u32 tag, · 715 unmodified lines
764764 scsi_set_resid(scp,
765765 scsi_bufflen(scp) - le32_to_cpu(req->dataxfer_length));
766766 scp->result = SAM_STAT_CHECK_CONDITION;
767− memcpy(scp->sense_buffer, &req->sg_list,
768− min_t(size_t, SCSI_SENSE_BUFFERSIZE,
769− le32_to_cpu(req->dataxfer_length)));
767+ memcpy(scp->sense_buffer, &req->sg_list, SCSI_SENSE_BUFFERSIZE);
770768 goto skip_resid;
771769 break;
772770
@@ -1037,8 +1035,9 @@ static int hptiop_queuecommand_lck(struct scsi_cmnd *scp, · 264 unmodified lines
10371035
10381036 scp->result = 0;
10391037
1040− if (scp->device->channel || scp->device->lun ||
1041− scp->device->id > hba->max_devices) {
1038+ if (scp->device->channel ||
1039+ (scp->device->id > hba->max_devices) ||
1040+ ((scp->device->id == (hba->max_devices-1)) && scp->device->lun)) {
10421041 scp->result = DID_BAD_TARGET << 16;
10431042 free_req(hba, _req);
10441043 goto cmd_done;
@@ -1168,6 +1167,14 @@ static struct device_attribute *hptiop_attrs[] = { · 123 unmodified lines
11681167 NULL
11691168 };
11701169
1170+static int hptiop_slave_config(struct scsi_device *sdev)
1171+{
1172+ if (sdev->type == TYPE_TAPE)
1173+ blk_queue_max_hw_sectors(sdev->request_queue, 8192);
1174+
1175+ return 0;
1176+}
1177+
11711178 static struct scsi_host_template driver_template = {
11721179 .module = THIS_MODULE,
11731180 .name = driver_name,
@@ -1179,6 +1186,7 @@ static struct scsi_host_template driver_template = { · 5 unmodified lines
11791186 .use_clustering = ENABLE_CLUSTERING,
11801187 .proc_name = driver_name,
11811188 .shost_attrs = hptiop_attrs,
1189+ .slave_configure = hptiop_slave_config,
11821190 .this_id = -1,
11831191 .change_queue_depth = hptiop_adjust_disk_queue_depth,
11841192 };
@@ -1323,6 +1331,7 @@ static int hptiop_probe(struct pci_dev *pcidev, const struct pci_device_id *id) · 138 unmodified lines
13231331 }
13241332
13251333 hba = (struct hptiop_hba *)host->hostdata;
1334+ memset(hba, 0, sizeof(struct hptiop_hba));
13261335
13271336 hba->ops = iop_ops;
13281337 hba->pcidev = pcidev;
@@ -1336,7 +1345,7 @@ static int hptiop_probe(struct pci_dev *pcidev, const struct pci_device_id *id) · 7 unmodified lines
13361345 init_waitqueue_head(&hba->reset_wq);
13371346 init_waitqueue_head(&hba->ioctl_wq);
13381347
1339− host->max_lun = 1;
1348+ host->max_lun = 128;
13401349 host->max_channel = 0;
13411350 host->io_port = 0;
13421351 host->n_io_port = 0;
@@ -1428,34 +1437,33 @@ static int hptiop_probe(struct pci_dev *pcidev, const struct pci_device_id *id) · 85 unmodified lines
14281437 dprintk("req_size=%d, max_requests=%d\n", req_size, hba->max_requests);
14291438
14301439 hba->req_size = req_size;
1431− start_virt = dma_alloc_coherent(&pcidev->dev,
1432− hba->req_size*hba->max_requests + 0x20,
1433− &start_phy, GFP_KERNEL);
1440+ hba->req_list = NULL;
14341441
1435− if (!start_virt) {
1436− printk(KERN_ERR "scsi%d: fail to alloc request mem\n",
1437− hba->host->host_no);
1438− goto free_request_irq;
1439− }
1442+ for (i = 0; i < hba->max_requests; i++) {
1443+ start_virt = dma_alloc_coherent(&pcidev->dev,
1444+ hba->req_size + 0x20,
1445+ &start_phy, GFP_KERNEL);
1446+
1447+ if (!start_virt) {
1448+ printk(KERN_ERR "scsi%d: fail to alloc request mem\n",
1449+ hba->host->host_no);
1450+ goto free_request_mem;
1451+ }
14401452
1441− hba->dma_coherent = start_virt;
1442− hba->dma_coherent_handle = start_phy;
1453+ hba->dma_coherent[i] = start_virt;
1454+ hba->dma_coherent_handle[i] = start_phy;
14431455
1444− if ((start_phy & 0x1f) != 0) {
1445− offset = ((start_phy + 0x1f) & ~0x1f) - start_phy;
1446− start_phy += offset;
1447− start_virt += offset;
1448− }
1456+ if ((start_phy & 0x1f) != 0) {
1457+ offset = ((start_phy + 0x1f) & ~0x1f) - start_phy;
1458+ start_phy += offset;
1459+ start_virt += offset;
1460+ }
14491461
1450− hba->req_list = NULL;
1451− for (i = 0; i < hba->max_requests; i++) {
14521462 hba->reqs[i].next = NULL;
14531463 hba->reqs[i].req_virt = start_virt;
14541464 hba->reqs[i].req_shifted_phy = start_phy >> 5;
14551465 hba->reqs[i].index = i;
14561466 free_req(hba, &hba->reqs[i]);
1457− start_virt = (char *)start_virt + hba->req_size;
1458− start_phy = start_phy + hba->req_size;
14591467 }
14601468
14611469 /* Enable Interrupt and start background task */
@@ -1474,11 +1482,16 @@ static int hptiop_probe(struct pci_dev *pcidev, const struct pci_device_id *id) · 12 unmodified lines
14741482 return 0;
14751483
14761484 free_request_mem:
1477− dma_free_coherent(&hba->pcidev->dev,
1478− hba->req_size * hba->max_requests + 0x20,
1479− hba->dma_coherent, hba->dma_coherent_handle);
1485+ for (i = 0; i < hba->max_requests; i++) {
1486+ if (hba->dma_coherent[i] && hba->dma_coherent_handle[i])
1487+ dma_free_coherent(&hba->pcidev->dev,
1488+ hba->req_size + 0x20,
1489+ hba->dma_coherent[i],
1490+ hba->dma_coherent_handle[i]);
1491+ else
1492+ break;
1493+ }
14801494
1481−free_request_irq:
14821495 free_irq(hba->pcidev->irq, hba);
14831496
14841497 unmap_pci_bar:
@@ -1546,6 +1559,7 @@ static void hptiop_remove(struct pci_dev *pcidev) · 61 unmodified lines
15461559 {
15471560 struct Scsi_Host *host = pci_get_drvdata(pcidev);
15481561 struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
1562+ u32 i;
15491563
15501564 dprintk("scsi%d: hptiop_remove\n", hba->host->host_no);
15511565
@@ -1555,10 +1569,15 @@ static void hptiop_remove(struct pci_dev *pcidev) · 3 unmodified lines
15551569
15561570 free_irq(hba->pcidev->irq, hba);
15571571
1558− dma_free_coherent(&hba->pcidev->dev,
1559− hba->req_size * hba->max_requests + 0x20,
1560− hba->dma_coherent,
1561− hba->dma_coherent_handle);
1572+ for (i = 0; i < hba->max_requests; i++) {
1573+ if (hba->dma_coherent[i] && hba->dma_coherent_handle[i])
1574+ dma_free_coherent(&hba->pcidev->dev,
1575+ hba->req_size + 0x20,
1576+ hba->dma_coherent[i],
1577+ hba->dma_coherent_handle[i]);
1578+ else
1579+ break;
1580+ }
15621581
15631582 hba->ops->internal_memfree(hba);
15641583
@@ -1653,6 +1672,14 @@ static struct pci_device_id hptiop_id_table[] = { · 88 unmodified lines
16531672 { PCI_VDEVICE(TTI, 0x3020), (kernel_ulong_t)&hptiop_mv_ops },
16541673 { PCI_VDEVICE(TTI, 0x4520), (kernel_ulong_t)&hptiop_mvfrey_ops },
16551674 { PCI_VDEVICE(TTI, 0x4522), (kernel_ulong_t)&hptiop_mvfrey_ops },
1675+ { PCI_VDEVICE(TTI, 0x3610), (kernel_ulong_t)&hptiop_mvfrey_ops },
1676+ { PCI_VDEVICE(TTI, 0x3611), (kernel_ulong_t)&hptiop_mvfrey_ops },
1677+ { PCI_VDEVICE(TTI, 0x3620), (kernel_ulong_t)&hptiop_mvfrey_ops },
1678+ { PCI_VDEVICE(TTI, 0x3622), (kernel_ulong_t)&hptiop_mvfrey_ops },
1679+ { PCI_VDEVICE(TTI, 0x3640), (kernel_ulong_t)&hptiop_mvfrey_ops },
1680+ { PCI_VDEVICE(TTI, 0x3660), (kernel_ulong_t)&hptiop_mvfrey_ops },
1681+ { PCI_VDEVICE(TTI, 0x3680), (kernel_ulong_t)&hptiop_mvfrey_ops },
1682+ { PCI_VDEVICE(TTI, 0x3690), (kernel_ulong_t)&hptiop_mvfrey_ops },
16561683 {},
16571684 };
16581685
drivers/scsi/hptiop.h+3−3
@@ -1,6 +1,6 @@
11 /*
22 * HighPoint RR3xxx/4xxx controller driver for Linux
3− * Copyright (C) 2006-2012 HighPoint Technologies, Inc. All Rights Reserved.
3+ * Copyright (C) 2006-2015 HighPoint Technologies, Inc. All Rights Reserved.
44 *
55 * This program is free software; you can redistribute it and/or modify
66 * it under the terms of the GNU General Public License as published by
@@ -327,8 +327,8 @@ struct hptiop_hba { · 320 unmodified lines
327327 struct hptiop_request reqs[HPTIOP_MAX_REQUESTS];
328328
329329 /* used to free allocated dma area */
330− void *dma_coherent;
331− dma_addr_t dma_coherent_handle;
330+ void *dma_coherent[HPTIOP_MAX_REQUESTS];
331+ dma_addr_t dma_coherent_handle[HPTIOP_MAX_REQUESTS];
332332
333333 atomic_t reset_count;
334334 atomic_t resetting;
drivers/scsi/ipr.c+8−7
@@ -1165,7 +1165,8 @@ static void ipr_init_res_entry(struct ipr_resource_entry *res, · 1164 unmodified lines
11651165
11661166 if (ioa_cfg->sis64) {
11671167 proto = cfgtew->u.cfgte64->proto;
1168− res->res_flags = cfgtew->u.cfgte64->res_flags;
1168+ res->flags = be16_to_cpu(cfgtew->u.cfgte64->flags);
1169+ res->res_flags = be16_to_cpu(cfgtew->u.cfgte64->res_flags);
11691170 res->qmodel = IPR_QUEUEING_MODEL64(res);
11701171 res->type = cfgtew->u.cfgte64->res_type;
11711172
@@ -1313,8 +1314,8 @@ static void ipr_update_res_entry(struct ipr_resource_entry *res, · 141 unmodified lines
13131314 int new_path = 0;
13141315
13151316 if (res->ioa_cfg->sis64) {
1316− res->flags = cfgtew->u.cfgte64->flags;
1317− res->res_flags = cfgtew->u.cfgte64->res_flags;
1317+ res->flags = be16_to_cpu(cfgtew->u.cfgte64->flags);
1318+ res->res_flags = be16_to_cpu(cfgtew->u.cfgte64->res_flags);
13181319 res->type = cfgtew->u.cfgte64->res_type;
13191320
13201321 memcpy(&res->std_inq_data, &cfgtew->u.cfgte64->std_inq_data,
@@ -1900,7 +1901,7 @@ static void ipr_log_array_error(struct ipr_ioa_cfg *ioa_cfg, · 579 unmodified lines
19001901 * Return value:
19011902 * none
19021903 **/
1903−static void ipr_log_hex_data(struct ipr_ioa_cfg *ioa_cfg, u32 *data, int len)
1904+static void ipr_log_hex_data(struct ipr_ioa_cfg *ioa_cfg, __be32 *data, int len)
19041905 {
19051906 int i;
19061907
@@ -2270,7 +2271,7 @@ static void ipr_log_fabric_error(struct ipr_ioa_cfg *ioa_cfg, · 363 unmodified lines
22702271 ((unsigned long)fabric + be16_to_cpu(fabric->length));
22712272 }
22722273
2273− ipr_log_hex_data(ioa_cfg, (u32 *)fabric, add_len);
2274+ ipr_log_hex_data(ioa_cfg, (__be32 *)fabric, add_len);
22742275 }
22752276
22762277 /**
@@ -2364,7 +2365,7 @@ static void ipr_log_sis64_fabric_error(struct ipr_ioa_cfg *ioa_cfg, · 87 unmodified lines
23642365 ((unsigned long)fabric + be16_to_cpu(fabric->length));
23652366 }
23662367
2367− ipr_log_hex_data(ioa_cfg, (u32 *)fabric, add_len);
2368+ ipr_log_hex_data(ioa_cfg, (__be32 *)fabric, add_len);
23682369 }
23692370
23702371 /**
@@ -4455,7 +4456,7 @@ static ssize_t ipr_show_device_id(struct device *dev, struct device_attribute *a · 2084 unmodified lines
44554456 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
44564457 res = (struct ipr_resource_entry *)sdev->hostdata;
44574458 if (res && ioa_cfg->sis64)
4458− len = snprintf(buf, PAGE_SIZE, "0x%llx\n", res->dev_id);
4459+ len = snprintf(buf, PAGE_SIZE, "0x%llx\n", be64_to_cpu(res->dev_id));
44594460 else if (res)
44604461 len = snprintf(buf, PAGE_SIZE, "0x%llx\n", res->lun_wwn);
44614462
drivers/scsi/ipr.h+8−9
@@ -39,8 +39,8 @@ · 38 unmodified lines
3939 /*
4040 * Literals
4141 */
42−#define IPR_DRIVER_VERSION "2.6.1"
43−#define IPR_DRIVER_DATE "(March 12, 2015)"
42+#define IPR_DRIVER_VERSION "2.6.2"
43+#define IPR_DRIVER_DATE "(June 11, 2015)"
4444
4545 /*
4646 * IPR_MAX_CMD_PER_LUN: This defines the maximum number of outstanding
@@ -1005,13 +1005,13 @@ struct ipr_hostrcb_type_24_error { · 958 unmodified lines
10051005 struct ipr_hostrcb_type_07_error {
10061006 u8 failure_reason[64];
10071007 struct ipr_vpd vpd;
1008− u32 data[222];
1008+ __be32 data[222];
10091009 }__attribute__((packed, aligned (4)));
10101010
10111011 struct ipr_hostrcb_type_17_error {
10121012 u8 failure_reason[64];
10131013 struct ipr_ext_vpd vpd;
1014− u32 data[476];
1014+ __be32 data[476];
10151015 }__attribute__((packed, aligned (4)));
10161016
10171017 struct ipr_hostrcb_config_element {
@@ -1289,18 +1289,17 @@ struct ipr_resource_entry { · 271 unmodified lines
12891289 (((res)->bus << 24) | ((res)->target << 8) | (res)->lun)
12901290
12911291 u8 ata_class;
1292−
1293− u8 flags;
1294− __be16 res_flags;
1295−
12961292 u8 type;
12971293
1294+ u16 flags;
1295+ u16 res_flags;
1296+
12981297 u8 qmodel;
12991298 struct ipr_std_inq_data std_inq_data;
13001299
13011300 __be32 res_handle;
13021301 __be64 dev_id;
1303− __be64 lun_wwn;
1302+ u64 lun_wwn;
13041303 struct scsi_lun dev_lun;
13051304 u8 res_path[8];
13061305
drivers/scsi/libfc/fc_fcp.c+1−1
@@ -191,7 +191,7 @@ static void fc_fcp_pkt_hold(struct fc_fcp_pkt *fsp) · 190 unmodified lines
191191 }
192192
193193 /**
194− * fc_fcp_pkt_destory() - Release hold on a fcp_pkt
194+ * fc_fcp_pkt_destroy() - Release hold on a fcp_pkt
195195 * @seq: The sequence that the FCP packet is on (required by destructor API)
196196 * @fsp: The FCP packet to be released
197197 *
drivers/scsi/lpfc/lpfc_hbadisc.c+1−1
@@ -701,7 +701,7 @@ lpfc_work_done(struct lpfc_hba *phba) · 700 unmodified lines
701701 HA_RXMASK));
702702 }
703703 }
704− if ((phba->sli_rev == LPFC_SLI_REV4) &
704+ if ((phba->sli_rev == LPFC_SLI_REV4) &&
705705 (!list_empty(&pring->txq)))
706706 lpfc_drain_txq(phba);
707707 /*
drivers/scsi/megaraid.c+66−74
@@ -268,8 +268,8 @@ mega_query_adapter(adapter_t *adapter) · 267 unmodified lines
268268 raw_mbox[2] = NC_SUBOP_PRODUCT_INFO; /* i.e. 0x0E */
269269
270270 if ((retval = issue_scb_block(adapter, raw_mbox)))
271− printk(KERN_WARNING
272− "megaraid: Product_info cmd failed with error: %d\n",
271+ dev_warn(&adapter->dev->dev,
272+ "Product_info cmd failed with error: %d\n",
273273 retval);
274274
275275 pci_unmap_single(adapter->dev, prod_info_dma_handle,
@@ -334,7 +334,7 @@ mega_query_adapter(adapter_t *adapter) · 58 unmodified lines
334334 adapter->bios_version[4] = 0;
335335 }
336336
337− printk(KERN_NOTICE "megaraid: [%s:%s] detected %d logical drives.\n",
337+ dev_notice(&adapter->dev->dev, "[%s:%s] detected %d logical drives\n",
338338 adapter->fw_version, adapter->bios_version, adapter->numldrv);
339339
340340 /*
@@ -342,7 +342,7 @@ mega_query_adapter(adapter_t *adapter) · 1 unmodified line
342342 */
343343 adapter->support_ext_cdb = mega_support_ext_cdb(adapter);
344344 if (adapter->support_ext_cdb)
345− printk(KERN_NOTICE "megaraid: supports extended CDBs.\n");
345+ dev_notice(&adapter->dev->dev, "supports extended CDBs\n");
346346
347347
348348 return 0;
@@ -678,11 +678,11 @@ mega_build_cmd(adapter_t *adapter, Scsi_Cmnd *cmd, int *busy) · 329 unmodified lines
678678
679679 if(!(adapter->flag & (1L << cmd->device->channel))) {
680680
681− printk(KERN_NOTICE
682− "scsi%d: scanning scsi channel %d ",
681+ dev_notice(&adapter->dev->dev,
682+ "scsi%d: scanning scsi channel %d "
683+ "for logical drives\n",
683684 adapter->host->host_no,
684685 cmd->device->channel);
685− printk("for logical drives.\n");
686686
687687 adapter->flag |= (1L << cmd->device->channel);
688688 }
@@ -983,11 +983,11 @@ mega_prepare_passthru(adapter_t *adapter, scb_t *scb, Scsi_Cmnd *cmd, · 294 unmodified lines
983983 case READ_CAPACITY:
984984 if(!(adapter->flag & (1L << cmd->device->channel))) {
985985
986− printk(KERN_NOTICE
987− "scsi%d: scanning scsi channel %d [P%d] ",
986+ dev_notice(&adapter->dev->dev,
987+ "scsi%d: scanning scsi channel %d [P%d] "
988+ "for physical devices\n",
988989 adapter->host->host_no,
989990 cmd->device->channel, channel);
990− printk("for physical devices.\n");
991991
992992 adapter->flag |= (1L << cmd->device->channel);
993993 }
@@ -1045,11 +1045,11 @@ mega_prepare_extpassthru(adapter_t *adapter, scb_t *scb, Scsi_Cmnd *cmd, · 51 unmodified lines
10451045 case READ_CAPACITY:
10461046 if(!(adapter->flag & (1L << cmd->device->channel))) {
10471047
1048− printk(KERN_NOTICE
1049− "scsi%d: scanning scsi channel %d [P%d] ",
1048+ dev_notice(&adapter->dev->dev,
1049+ "scsi%d: scanning scsi channel %d [P%d] "
1050+ "for physical devices\n",
10501051 adapter->host->host_no,
10511052 cmd->device->channel, channel);
1052− printk("for physical devices.\n");
10531053
10541054 adapter->flag |= (1L << cmd->device->channel);
10551055 }
@@ -1241,7 +1241,7 @@ issue_scb_block(adapter_t *adapter, u_char *raw_mbox) · 185 unmodified lines
12411241 return mbox->m_in.status;
12421242
12431243 bug_blocked_mailbox:
1244− printk(KERN_WARNING "megaraid: Blocked mailbox......!!\n");
1244+ dev_warn(&adapter->dev->dev, "Blocked mailbox......!!\n");
12451245 udelay (1000);
12461246 return -1;
12471247 }
@@ -1454,9 +1454,8 @@ mega_cmd_done(adapter_t *adapter, u8 completed[], int nstatus, int status) · 206 unmodified lines
14541454 * Make sure f/w has completed a valid command
14551455 */
14561456 if( !(scb->state & SCB_ISSUED) || scb->cmd == NULL ) {
1457− printk(KERN_CRIT
1458− "megaraid: invalid command ");
1459− printk("Id %d, scb->state:%x, scsi cmd:%p\n",
1457+ dev_crit(&adapter->dev->dev, "invalid command "
1458+ "Id %d, scb->state:%x, scsi cmd:%p\n",
14601459 cmdid, scb->state, scb->cmd);
14611460
14621461 continue;
@@ -1467,8 +1466,8 @@ mega_cmd_done(adapter_t *adapter, u8 completed[], int nstatus, int status) · 4 unmodified lines
14671466 */
14681467 if( scb->state & SCB_ABORT ) {
14691468
1470− printk(KERN_WARNING
1471− "megaraid: aborted cmd [%x] complete.\n",
1469+ dev_warn(&adapter->dev->dev,
1470+ "aborted cmd [%x] complete\n",
14721471 scb->idx);
14731472
14741473 scb->cmd->result = (DID_ABORT << 16);
@@ -1486,8 +1485,8 @@ mega_cmd_done(adapter_t *adapter, u8 completed[], int nstatus, int status) · 11 unmodified lines
14861485 */
14871486 if( scb->state & SCB_RESET ) {
14881487
1489− printk(KERN_WARNING
1490− "megaraid: reset cmd [%x] complete.\n",
1488+ dev_warn(&adapter->dev->dev,
1489+ "reset cmd [%x] complete\n",
14911490 scb->idx);
14921491
14931492 scb->cmd->result = (DID_RESET << 16);
@@ -1553,8 +1552,7 @@ mega_cmd_done(adapter_t *adapter, u8 completed[], int nstatus, int status) · 59 unmodified lines
15531552 if( sg_page(sgl) ) {
15541553 c = *(unsigned char *) sg_virt(&sgl[0]);
15551554 } else {
1556− printk(KERN_WARNING
1557− "megaraid: invalid sg.\n");
1555+ dev_warn(&adapter->dev->dev, "invalid sg\n");
15581556 c = 0;
15591557 }
15601558
@@ -1902,11 +1900,10 @@ megaraid_reset(struct scsi_cmnd *cmd) · 341 unmodified lines
19021900 mc.opcode = MEGA_RESET_RESERVATIONS;
19031901
19041902 if( mega_internal_command(adapter, &mc, NULL) != 0 ) {
1905− printk(KERN_WARNING
1906− "megaraid: reservation reset failed.\n");
1903+ dev_warn(&adapter->dev->dev, "reservation reset failed\n");
19071904 }
19081905 else {
1909− printk(KERN_INFO "megaraid: reservation reset.\n");
1906+ dev_info(&adapter->dev->dev, "reservation reset\n");
19101907 }
19111908 #endif
19121909
@@ -1939,7 +1936,7 @@ megaraid_abort_and_reset(adapter_t *adapter, Scsi_Cmnd *cmd, int aor) · 26 unmodified lines
19391936 struct list_head *pos, *next;
19401937 scb_t *scb;
19411938
1942− printk(KERN_WARNING "megaraid: %s cmd=%x <c=%d t=%d l=%d>\n",
1939+ dev_warn(&adapter->dev->dev, "%s cmd=%x <c=%d t=%d l=%d>\n",
19431940 (aor == SCB_ABORT)? "ABORTING":"RESET",
19441941 cmd->cmnd[0], cmd->device->channel,
19451942 cmd->device->id, (u32)cmd->device->lun);
@@ -1963,8 +1960,8 @@ megaraid_abort_and_reset(adapter_t *adapter, Scsi_Cmnd *cmd, int aor) · 17 unmodified lines
19631960 */
19641961 if( scb->state & SCB_ISSUED ) {
19651962
1966− printk(KERN_WARNING
1967− "megaraid: %s[%x], fw owner.\n",
1963+ dev_warn(&adapter->dev->dev,
1964+ "%s[%x], fw owner\n",
19681965 (aor==SCB_ABORT) ? "ABORTING":"RESET",
19691966 scb->idx);
19701967
@@ -1976,8 +1973,8 @@ megaraid_abort_and_reset(adapter_t *adapter, Scsi_Cmnd *cmd, int aor) · 5 unmodified lines
19761973 * Not yet issued! Remove from the pending
19771974 * list
19781975 */
1979− printk(KERN_WARNING
1980− "megaraid: %s-[%x], driver owner.\n",
1976+ dev_warn(&adapter->dev->dev,
1977+ "%s-[%x], driver owner\n",
19811978 (aor==SCB_ABORT) ? "ABORTING":"RESET",
19821979 scb->idx);
19831980
@@ -2197,7 +2194,7 @@ proc_show_rebuild_rate(struct seq_file *m, void *v) · 213 unmodified lines
21972194
21982195 if( mega_adapinq(adapter, dma_handle) != 0 ) {
21992196 seq_puts(m, "Adapter inquiry failed.\n");
2200− printk(KERN_WARNING "megaraid: inquiry failed.\n");
2197+ dev_warn(&adapter->dev->dev, "inquiry failed\n");
22012198 goto free_inquiry;
22022199 }
22032200
@@ -2241,7 +2238,7 @@ proc_show_battery(struct seq_file *m, void *v) · 37 unmodified lines
22412238
22422239 if( mega_adapinq(adapter, dma_handle) != 0 ) {
22432240 seq_puts(m, "Adapter inquiry failed.\n");
2244− printk(KERN_WARNING "megaraid: inquiry failed.\n");
2241+ dev_warn(&adapter->dev->dev, "inquiry failed\n");
22452242 goto free_inquiry;
22462243 }
22472244
@@ -2350,7 +2347,7 @@ proc_show_pdrv(struct seq_file *m, adapter_t *adapter, int channel) · 102 unmodified lines
23502347
23512348 if( mega_adapinq(adapter, dma_handle) != 0 ) {
23522349 seq_puts(m, "Adapter inquiry failed.\n");
2353− printk(KERN_WARNING "megaraid: inquiry failed.\n");
2350+ dev_warn(&adapter->dev->dev, "inquiry failed\n");
23542351 goto free_inquiry;
23552352 }
23562353
@@ -2525,7 +2522,7 @@ proc_show_rdrv(struct seq_file *m, adapter_t *adapter, int start, int end ) · 168 unmodified lines
25252522
25262523 if( mega_adapinq(adapter, dma_handle) != 0 ) {
25272524 seq_puts(m, "Adapter inquiry failed.\n");
2528− printk(KERN_WARNING "megaraid: inquiry failed.\n");
2525+ dev_warn(&adapter->dev->dev, "inquiry failed\n");
25292526 goto free_inquiry;
25302527 }
25312528
@@ -2799,7 +2796,7 @@ mega_create_proc_entry(int index, struct proc_dir_entry *parent) · 267 unmodified lines
27992796 dir = adapter->controller_proc_dir_entry =
28002797 proc_mkdir_data(string, 0, parent, adapter);
28012798 if(!dir) {
2802− printk(KERN_WARNING "\nmegaraid: proc_mkdir failed\n");
2799+ dev_warn(&adapter->dev->dev, "proc_mkdir failed\n");
28032800 return;
28042801 }
28052802
@@ -2807,7 +2804,7 @@ mega_create_proc_entry(int index, struct proc_dir_entry *parent) · 1 unmodified line
28072804 de = proc_create_data(f->name, S_IRUSR, dir, &mega_proc_fops,
28082805 f->show);
28092806 if (!de) {
2810− printk(KERN_WARNING "\nmegaraid: proc_create failed\n");
2807+ dev_warn(&adapter->dev->dev, "proc_create failed\n");
28112808 return;
28122809 }
28132810
@@ -2874,9 +2871,9 @@ megaraid_biosparam(struct scsi_device *sdev, struct block_device *bdev, · 60 unmodified lines
28742871 return rval;
28752872 }
28762873
2877− printk(KERN_INFO
2878− "megaraid: invalid partition on this disk on channel %d\n",
2879− sdev->channel);
2874+ dev_info(&adapter->dev->dev,
2875+ "invalid partition on this disk on channel %d\n",
2876+ sdev->channel);
28802877
28812878 /* Default heads (64) & sectors (32) */
28822879 heads = 64;
@@ -2936,7 +2933,7 @@ mega_init_scb(adapter_t *adapter) · 53 unmodified lines
29362933 scb->sgl = (mega_sglist *)scb->sgl64;
29372934
29382935 if( !scb->sgl ) {
2939− printk(KERN_WARNING "RAID: Can't allocate sglist.\n");
2936+ dev_warn(&adapter->dev->dev, "RAID: Can't allocate sglist\n");
29402937 mega_free_sgl(adapter);
29412938 return -1;
29422939 }
@@ -2946,7 +2943,7 @@ mega_init_scb(adapter_t *adapter) · 3 unmodified lines
29462943 &scb->pthru_dma_addr);
29472944
29482945 if( !scb->pthru ) {
2949− printk(KERN_WARNING "RAID: Can't allocate passthru.\n");
2946+ dev_warn(&adapter->dev->dev, "RAID: Can't allocate passthru\n");
29502947 mega_free_sgl(adapter);
29512948 return -1;
29522949 }
@@ -2956,8 +2953,8 @@ mega_init_scb(adapter_t *adapter) · 3 unmodified lines
29562953 &scb->epthru_dma_addr);
29572954
29582955 if( !scb->epthru ) {
2959− printk(KERN_WARNING
2960− "Can't allocate extended passthru.\n");
2956+ dev_warn(&adapter->dev->dev,
2957+ "Can't allocate extended passthru\n");
29612958 mega_free_sgl(adapter);
29622959 return -1;
29632960 }
@@ -3154,8 +3151,8 @@ megadev_ioctl(struct file *filep, unsigned int cmd, unsigned long arg) · 190 unmodified lines
31543151 * Do we support this feature
31553152 */
31563153 if( !adapter->support_random_del ) {
3157− printk(KERN_WARNING "megaraid: logdrv ");
3158− printk("delete on non-supporting F/W.\n");
3154+ dev_warn(&adapter->dev->dev, "logdrv "
3155+ "delete on non-supporting F/W\n");
31593156
31603157 return (-EINVAL);
31613158 }
@@ -3179,7 +3176,7 @@ megadev_ioctl(struct file *filep, unsigned int cmd, unsigned long arg) · 17 unmodified lines
31793176 if( uioc.uioc_rmbox[0] == MEGA_MBOXCMD_PASSTHRU64 ||
31803177 uioc.uioc_rmbox[0] == MEGA_MBOXCMD_EXTPTHRU ) {
31813178
3182− printk(KERN_WARNING "megaraid: rejected passthru.\n");
3179+ dev_warn(&adapter->dev->dev, "rejected passthru\n");
31833180
31843181 return (-EINVAL);
31853182 }
@@ -3683,11 +3680,11 @@ mega_enum_raid_scsi(adapter_t *adapter) · 497 unmodified lines
36833680
36843681 for( i = 0; i < adapter->product_info.nchannels; i++ ) {
36853682 if( (adapter->mega_ch_class >> i) & 0x01 ) {
3686− printk(KERN_INFO "megaraid: channel[%d] is raid.\n",
3683+ dev_info(&adapter->dev->dev, "channel[%d] is raid\n",
36873684 i);
36883685 }
36893686 else {
3690− printk(KERN_INFO "megaraid: channel[%d] is scsi.\n",
3687+ dev_info(&adapter->dev->dev, "channel[%d] is scsi\n",
36913688 i);
36923689 }
36933690 }
@@ -3893,7 +3890,7 @@ mega_do_del_logdrv(adapter_t *adapter, int logdrv) · 199 unmodified lines
38933890
38943891 /* log this event */
38953892 if(rval) {
3896− printk(KERN_WARNING "megaraid: Delete LD-%d failed.", logdrv);
3893+ dev_warn(&adapter->dev->dev, "Delete LD-%d failed", logdrv);
38973894 return rval;
38983895 }
38993896
@@ -4161,7 +4158,7 @@ mega_internal_command(adapter_t *adapter, megacmd_t *mc, mega_passthru *pthru) · 261 unmodified lines
41614158 * this information.
41624159 */
41634160 if (rval && trace_level) {
4164− printk("megaraid: cmd [%x, %x, %x] status:[%x]\n",
4161+ dev_info(&adapter->dev->dev, "cmd [%x, %x, %x] status:[%x]\n",
41654162 mc->cmd, mc->opcode, mc->subopcode, rval);
41664163 }
41674164
@@ -4244,11 +4241,8 @@ megaraid_probe_one(struct pci_dev *pdev, const struct pci_device_id *id) · 76 unmodified lines
42444241 subsysvid = pdev->subsystem_vendor;
42454242 subsysid = pdev->subsystem_device;
42464243
4247− printk(KERN_NOTICE "megaraid: found 0x%4.04x:0x%4.04x:bus %d:",
4248− id->vendor, id->device, pci_bus);
4249−
4250− printk("slot %d:func %d\n",
4251− PCI_SLOT(pci_dev_func), PCI_FUNC(pci_dev_func));
4244+ dev_notice(&pdev->dev, "found 0x%4.04x:0x%4.04x\n",
4245+ id->vendor, id->device);
42524246
42534247 /* Read the base port and IRQ from PCI */
42544248 mega_baseport = pci_resource_start(pdev, 0);
@@ -4259,14 +4253,13 @@ megaraid_probe_one(struct pci_dev *pdev, const struct pci_device_id *id) · 4 unmodified lines
42594253 flag |= BOARD_MEMMAP;
42604254
42614255 if (!request_mem_region(mega_baseport, 128, "megaraid")) {
4262− printk(KERN_WARNING "megaraid: mem region busy!\n");
4256+ dev_warn(&pdev->dev, "mem region busy!\n");
42634257 goto out_disable_device;
42644258 }
42654259
42664260 mega_baseport = (unsigned long)ioremap(mega_baseport, 128);
42674261 if (!mega_baseport) {
4268− printk(KERN_WARNING
4269− "megaraid: could not map hba memory\n");
4262+ dev_warn(&pdev->dev, "could not map hba memory\n");
42704263 goto out_release_region;
42714264 }
42724265 } else {
@@ -4285,7 +4278,7 @@ megaraid_probe_one(struct pci_dev *pdev, const struct pci_device_id *id) · 12 unmodified lines
42854278 adapter = (adapter_t *)host->hostdata;
42864279 memset(adapter, 0, sizeof(adapter_t));
42874280
4288− printk(KERN_NOTICE
4281+ dev_notice(&pdev->dev,
42894282 "scsi%d:Found MegaRAID controller at 0x%lx, IRQ:%d\n",
42904283 host->host_no, mega_baseport, irq);
42914284
@@ -4323,21 +4316,20 @@ megaraid_probe_one(struct pci_dev *pdev, const struct pci_device_id *id) · 31 unmodified lines
43234316 adapter->mega_buffer = pci_alloc_consistent(adapter->dev,
43244317 MEGA_BUFFER_SIZE, &adapter->buf_dma_handle);
43254318 if (!adapter->mega_buffer) {
4326− printk(KERN_WARNING "megaraid: out of RAM.\n");
4319+ dev_warn(&pdev->dev, "out of RAM\n");
43274320 goto out_host_put;
43284321 }
43294322
43304323 adapter->scb_list = kmalloc(sizeof(scb_t) * MAX_COMMANDS, GFP_KERNEL);
43314324 if (!adapter->scb_list) {
4332− printk(KERN_WARNING "megaraid: out of RAM.\n");
4325+ dev_warn(&pdev->dev, "out of RAM\n");
43334326 goto out_free_cmd_buffer;
43344327 }
43354328
43364329 if (request_irq(irq, (adapter->flag & BOARD_MEMMAP) ?
43374330 megaraid_isr_memmapped : megaraid_isr_iomapped,
43384331 IRQF_SHARED, "megaraid", adapter)) {
4339− printk(KERN_WARNING
4340− "megaraid: Couldn't register IRQ %d!\n", irq);
4332+ dev_warn(&pdev->dev, "Couldn't register IRQ %d!\n", irq);
43414333 goto out_free_scb_list;
43424334 }
43434335
@@ -4357,9 +4349,9 @@ megaraid_probe_one(struct pci_dev *pdev, const struct pci_device_id *id) · 13 unmodified lines
43574349 if (!strcmp(adapter->fw_version, "3.00") ||
43584350 !strcmp(adapter->fw_version, "3.01")) {
43594351
4360− printk( KERN_WARNING
4361− "megaraid: Your card is a Dell PERC "
4362− "2/SC RAID controller with "
4352+ dev_warn(&pdev->dev,
4353+ "Your card is a Dell PERC "
4354+ "2/SC RAID controller with "
43634355 "firmware\nmegaraid: 3.00 or 3.01. "
43644356 "This driver is known to have "
43654357 "corruption issues\nmegaraid: with "
@@ -4390,12 +4382,12 @@ megaraid_probe_one(struct pci_dev *pdev, const struct pci_device_id *id) · 24 unmodified lines
43904382 if (!strcmp(adapter->fw_version, "H01.07") ||
43914383 !strcmp(adapter->fw_version, "H01.08") ||
43924384 !strcmp(adapter->fw_version, "H01.09") ) {
4393− printk(KERN_WARNING
4394− "megaraid: Firmware H.01.07, "
4385+ dev_warn(&pdev->dev,
4386+ "Firmware H.01.07, "
43954387 "H.01.08, and H.01.09 on 1M/2M "
43964388 "controllers\n"
4397− "megaraid: do not support 64 bit "
4398− "addressing.\nmegaraid: DISABLING "
4389+ "do not support 64 bit "
4390+ "addressing.\nDISABLING "
43994391 "64 bit support.\n");
44004392 adapter->flag &= ~BOARD_64BIT;
44014393 }
@@ -4503,8 +4495,8 @@ megaraid_probe_one(struct pci_dev *pdev, const struct pci_device_id *id) · 101 unmodified lines
45034495 */
45044496 adapter->has_cluster = mega_support_cluster(adapter);
45054497 if (adapter->has_cluster) {
4506− printk(KERN_NOTICE
4507− "megaraid: Cluster driver, initiator id:%d\n",
4498+ dev_notice(&pdev->dev,
4499+ "Cluster driver, initiator id:%d\n",
45084500 adapter->this_id);
45094501 }
45104502 #endif
@@ -4571,7 +4563,7 @@ __megaraid_shutdown(adapter_t *adapter) · 60 unmodified lines
45714563 issue_scb_block(adapter, raw_mbox);
45724564
45734565 if (atomic_read(&adapter->pend_cmds) > 0)
4574− printk(KERN_WARNING "megaraid: pending commands!!\n");
4566+ dev_warn(&adapter->dev->dev, "pending commands!!\n");
45754567
45764568 /*
45774569 * Have a delibrate delay to make sure all the caches are
drivers/scsi/megaraid/megaraid_sas_base.c+266−278
@@ -216,7 +216,7 @@ struct megasas_cmd *megasas_get_cmd(struct megasas_instance · 215 unmodified lines
216216 struct megasas_cmd, list);
217217 list_del_init(&cmd->list);
218218 } else {
219− printk(KERN_ERR "megasas: Command pool empty!\n");
219+ dev_err(&instance->pdev->dev, "Command pool empty!\n");
220220 }
221221
222222 spin_unlock_irqrestore(&instance->mfi_pool_lock, flags);
@@ -273,6 +273,7 @@ static inline void · 50 unmodified lines
273273 megasas_enable_intr_xscale(struct megasas_instance *instance)
274274 {
275275 struct megasas_register_set __iomem *regs;
276+
276277 regs = instance->reg_set;
277278 writel(0, &(regs)->outbound_intr_mask);
278279
@@ -289,6 +290,7 @@ megasas_disable_intr_xscale(struct megasas_instance *instance) · 10 unmodified lines
289290 {
290291 struct megasas_register_set __iomem *regs;
291292 u32 mask = 0x1f;
293+
292294 regs = instance->reg_set;
293295 writel(mask, &regs->outbound_intr_mask);
294296 /* Dummy readl to force pci flush */
@@ -313,6 +315,7 @@ megasas_clear_intr_xscale(struct megasas_register_set __iomem * regs) · 18 unmodified lines
313315 {
314316 u32 status;
315317 u32 mfiStatus = 0;
318+
316319 /*
317320 * Check if it is our interrupt
318321 */
@@ -348,6 +351,7 @@ megasas_fire_cmd_xscale(struct megasas_instance *instance, · 29 unmodified lines
348351 struct megasas_register_set __iomem *regs)
349352 {
350353 unsigned long flags;
354+
351355 spin_lock_irqsave(&instance->hba_lock, flags);
352356 writel((frame_phys_addr >> 3)|(frame_count),
353357 &(regs)->inbound_queue_port);
@@ -364,15 +368,16 @@ megasas_adp_reset_xscale(struct megasas_instance *instance, · 10 unmodified lines
364368 {
365369 u32 i;
366370 u32 pcidata;
371+
367372 writel(MFI_ADP_RESET, &regs->inbound_doorbell);
368373
369374 for (i = 0; i < 3; i++)
370375 msleep(1000); /* sleep for 3 secs */
371376 pcidata = 0;
372377 pci_read_config_dword(instance->pdev, MFI_1068_PCSR_OFFSET, &pcidata);
373− printk(KERN_NOTICE "pcidata = %x\n", pcidata);
378+ dev_notice(&instance->pdev->dev, "pcidata = %x\n", pcidata);
374379 if (pcidata & 0x2) {
375− printk(KERN_NOTICE "mfi 1068 offset read=%x\n", pcidata);
380+ dev_notice(&instance->pdev->dev, "mfi 1068 offset read=%x\n", pcidata);
376381 pcidata &= ~0x2;
377382 pci_write_config_dword(instance->pdev,
378383 MFI_1068_PCSR_OFFSET, pcidata);
@@ -383,9 +388,9 @@ megasas_adp_reset_xscale(struct megasas_instance *instance, · 4 unmodified lines
383388 pcidata = 0;
384389 pci_read_config_dword(instance->pdev,
385390 MFI_1068_FW_HANDSHAKE_OFFSET, &pcidata);
386− printk(KERN_NOTICE "1068 offset handshake read=%x\n", pcidata);
391+ dev_notice(&instance->pdev->dev, "1068 offset handshake read=%x\n", pcidata);
387392 if ((pcidata & 0xffff0000) == MFI_1068_FW_READY) {
388− printk(KERN_NOTICE "1068 offset pcidt=%x\n", pcidata);
393+ dev_notice(&instance->pdev->dev, "1068 offset pcidt=%x\n", pcidata);
389394 pcidata = 0;
390395 pci_write_config_dword(instance->pdev,
391396 MFI_1068_FW_HANDSHAKE_OFFSET, pcidata);
@@ -402,7 +407,6 @@ static int · 10 unmodified lines
402407 megasas_check_reset_xscale(struct megasas_instance *instance,
403408 struct megasas_register_set __iomem *regs)
404409 {
405−
406410 if ((instance->adprecovery != MEGASAS_HBA_OPERATIONAL) &&
407411 (le32_to_cpu(*instance->consumer) ==
408412 MEGASAS_ADPRESET_INPROG_SIGN))
@@ -433,7 +437,7 @@ static struct megasas_instance_template megasas_instance_template_xscale = { · 24 unmodified lines
433437
434438 /**
435439 * The following functions are defined for ppc (deviceid : 0x60)
436−* controllers
440+* controllers
437441 */
438442
439443 /**
@@ -444,6 +448,7 @@ static inline void · 4 unmodified lines
444448 megasas_enable_intr_ppc(struct megasas_instance *instance)
445449 {
446450 struct megasas_register_set __iomem *regs;
451+
447452 regs = instance->reg_set;
448453 writel(0xFFFFFFFF, &(regs)->outbound_doorbell_clear);
449454
@@ -462,6 +467,7 @@ megasas_disable_intr_ppc(struct megasas_instance *instance) · 12 unmodified lines
462467 {
463468 struct megasas_register_set __iomem *regs;
464469 u32 mask = 0xFFFFFFFF;
470+
465471 regs = instance->reg_set;
466472 writel(mask, &regs->outbound_intr_mask);
467473 /* Dummy readl to force pci flush */
@@ -522,6 +528,7 @@ megasas_fire_cmd_ppc(struct megasas_instance *instance, · 54 unmodified lines
522528 struct megasas_register_set __iomem *regs)
523529 {
524530 unsigned long flags;
531+
525532 spin_lock_irqsave(&instance->hba_lock, flags);
526533 writel((frame_phys_addr | (frame_count<<1))|1,
527534 &(regs)->inbound_queue_port);
@@ -566,6 +573,7 @@ static inline void · 38 unmodified lines
566573 megasas_enable_intr_skinny(struct megasas_instance *instance)
567574 {
568575 struct megasas_register_set __iomem *regs;
576+
569577 regs = instance->reg_set;
570578 writel(0xFFFFFFFF, &(regs)->outbound_intr_mask);
571579
@@ -584,6 +592,7 @@ megasas_disable_intr_skinny(struct megasas_instance *instance) · 12 unmodified lines
584592 {
585593 struct megasas_register_set __iomem *regs;
586594 u32 mask = 0xFFFFFFFF;
595+
587596 regs = instance->reg_set;
588597 writel(mask, &regs->outbound_intr_mask);
589598 /* Dummy readl to force pci flush */
@@ -634,8 +643,8 @@ megasas_clear_intr_skinny(struct megasas_register_set __iomem *regs) · 44 unmodified lines
634643 writel(status, &regs->outbound_intr_status);
635644
636645 /*
637− * dummy read to flush PCI
638− */
646+ * dummy read to flush PCI
647+ */
639648 readl(&regs->outbound_intr_status);
640649
641650 return mfiStatus;
@@ -654,6 +663,7 @@ megasas_fire_cmd_skinny(struct megasas_instance *instance, · 12 unmodified lines
654663 struct megasas_register_set __iomem *regs)
655664 {
656665 unsigned long flags;
666+
657667 spin_lock_irqsave(&instance->hba_lock, flags);
658668 writel(upper_32_bits(frame_phys_addr),
659669 &(regs)->inbound_high_queue_port);
@@ -706,6 +716,7 @@ static inline void · 46 unmodified lines
706716 megasas_enable_intr_gen2(struct megasas_instance *instance)
707717 {
708718 struct megasas_register_set __iomem *regs;
719+
709720 regs = instance->reg_set;
710721 writel(0xFFFFFFFF, &(regs)->outbound_doorbell_clear);
711722
@@ -725,6 +736,7 @@ megasas_disable_intr_gen2(struct megasas_instance *instance) · 13 unmodified lines
725736 {
726737 struct megasas_register_set __iomem *regs;
727738 u32 mask = 0xFFFFFFFF;
739+
728740 regs = instance->reg_set;
729741 writel(mask, &regs->outbound_intr_mask);
730742 /* Dummy readl to force pci flush */
@@ -750,6 +762,7 @@ megasas_clear_intr_gen2(struct megasas_register_set __iomem *regs) · 19 unmodified lines
750762 {
751763 u32 status;
752764 u32 mfiStatus = 0;
765+
753766 /*
754767 * Check if it is our interrupt
755768 */
@@ -786,6 +799,7 @@ megasas_fire_cmd_gen2(struct megasas_instance *instance, · 30 unmodified lines
786799 struct megasas_register_set __iomem *regs)
787800 {
788801 unsigned long flags;
802+
789803 spin_lock_irqsave(&instance->hba_lock, flags);
790804 writel((frame_phys_addr | (frame_count<<1))|1,
791805 &(regs)->inbound_queue_port);
@@ -800,10 +814,10 @@ static int · 8 unmodified lines
800814 megasas_adp_reset_gen2(struct megasas_instance *instance,
801815 struct megasas_register_set __iomem *reg_set)
802816 {
803− u32 retry = 0 ;
804− u32 HostDiag;
805− u32 __iomem *seq_offset = &reg_set->seq_offset;
806− u32 __iomem *hostdiag_offset = &reg_set->host_diag;
817+ u32 retry = 0 ;
818+ u32 HostDiag;
819+ u32 __iomem *seq_offset = &reg_set->seq_offset;
820+ u32 __iomem *hostdiag_offset = &reg_set->host_diag;
807821
808822 if (instance->instancet == &megasas_instance_template_skinny) {
809823 seq_offset = &reg_set->fusion_seq_offset;
@@ -821,10 +835,10 @@ megasas_adp_reset_gen2(struct megasas_instance *instance, · 11 unmodified lines
821835
822836 HostDiag = (u32)readl(hostdiag_offset);
823837
824− while ( !( HostDiag & DIAG_WRITE_ENABLE) ) {
838+ while (!(HostDiag & DIAG_WRITE_ENABLE)) {
825839 msleep(100);
826840 HostDiag = (u32)readl(hostdiag_offset);
827− printk(KERN_NOTICE "RESETGEN2: retry=%x, hostdiag=%x\n",
841+ dev_notice(&instance->pdev->dev, "RESETGEN2: retry=%x, hostdiag=%x\n",
828842 retry, HostDiag);
829843
830844 if (retry++ >= 100)
@@ -832,17 +846,17 @@ megasas_adp_reset_gen2(struct megasas_instance *instance, · 1 unmodified line
832846
833847 }
834848
835− printk(KERN_NOTICE "ADP_RESET_GEN2: HostDiag=%x\n", HostDiag);
849+ dev_notice(&instance->pdev->dev, "ADP_RESET_GEN2: HostDiag=%x\n", HostDiag);
836850
837851 writel((HostDiag | DIAG_RESET_ADAPTER), hostdiag_offset);
838852
839853 ssleep(10);
840854
841855 HostDiag = (u32)readl(hostdiag_offset);
842− while ( ( HostDiag & DIAG_RESET_ADAPTER) ) {
856+ while (HostDiag & DIAG_RESET_ADAPTER) {
843857 msleep(100);
844858 HostDiag = (u32)readl(hostdiag_offset);
845− printk(KERN_NOTICE "RESET_GEN2: retry=%x, hostdiag=%x\n",
859+ dev_notice(&instance->pdev->dev, "RESET_GEN2: retry=%x, hostdiag=%x\n",
846860 retry, HostDiag);
847861
848862 if (retry++ >= 1000)
@@ -904,7 +918,6 @@ int · 55 unmodified lines
904918 megasas_issue_polled(struct megasas_instance *instance, struct megasas_cmd *cmd)
905919 {
906920 int seconds;
907−
908921 struct megasas_header *frame_hdr = &cmd->frame->hdr;
909922
910923 frame_hdr->cmd_status = MFI_CMD_STATUS_POLL_MODE;
@@ -940,6 +953,7 @@ megasas_issue_blocked_cmd(struct megasas_instance *instance, · 29 unmodified lines
940953 struct megasas_cmd *cmd, int timeout)
941954 {
942955 int ret = 0;
956+
943957 cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS;
944958
945959 instance->instancet->issue_dcmd(instance, cmd);
@@ -1120,7 +1134,7 @@ static u32 megasas_get_frame_count(struct megasas_instance *instance, · 174 unmodified lines
11201134 int num_cnt;
11211135 int sge_bytes;
11221136 u32 sge_sz;
1123− u32 frame_count=0;
1137+ u32 frame_count = 0;
11241138
11251139 sge_sz = (IS_DMA64) ? sizeof(struct megasas_sge64) :
11261140 sizeof(struct megasas_sge32);
@@ -1151,14 +1165,14 @@ static u32 megasas_get_frame_count(struct megasas_instance *instance, · 24 unmodified lines
11511165 num_cnt = sge_count - 3;
11521166 }
11531167
1154− if(num_cnt>0){
1168+ if (num_cnt > 0) {
11551169 sge_bytes = sge_sz * num_cnt;
11561170
11571171 frame_count = (sge_bytes / MEGAMFI_FRAME_SIZE) +
11581172 ((sge_bytes % MEGAMFI_FRAME_SIZE) ? 1 : 0) ;
11591173 }
11601174 /* Main frame */
1161− frame_count +=1;
1175+ frame_count += 1;
11621176
11631177 if (frame_count > 7)
11641178 frame_count = 8;
@@ -1215,9 +1229,9 @@ megasas_build_dcdb(struct megasas_instance *instance, struct scsi_cmnd *scp, · 50 unmodified lines
12151229 memcpy(pthru->cdb, scp->cmnd, scp->cmd_len);
12161230
12171231 /*
1218− * If the command is for the tape device, set the
1219− * pthru timeout to the os layer timeout value.
1220− */
1232+ * If the command is for the tape device, set the
1233+ * pthru timeout to the os layer timeout value.
1234+ */
12211235 if (scp->device->type == TYPE_TAPE) {
12221236 if ((scp->request->timeout / HZ) > 0xFFFF)
12231237 pthru->timeout = cpu_to_le16(0xFFFF);
@@ -1241,7 +1255,7 @@ megasas_build_dcdb(struct megasas_instance *instance, struct scsi_cmnd *scp, · 17 unmodified lines
12411255 &pthru->sgl);
12421256
12431257 if (pthru->sge_count > instance->max_num_sge) {
1244− printk(KERN_ERR "megasas: DCDB two many SGE NUM=%x\n",
1258+ dev_err(&instance->pdev->dev, "DCDB too many SGE NUM=%x\n",
12451259 pthru->sge_count);
12461260 return 0;
12471261 }
@@ -1382,7 +1396,7 @@ megasas_build_ldio(struct megasas_instance *instance, struct scsi_cmnd *scp, · 134 unmodified lines
13821396 ldio->sge_count = megasas_make_sgl32(instance, scp, &ldio->sgl);
13831397
13841398 if (ldio->sge_count > instance->max_num_sge) {
1385− printk(KERN_ERR "megasas: build_ld_io: sge_count = %x\n",
1399+ dev_err(&instance->pdev->dev, "build_ld_io: sge_count = %x\n",
13861400 ldio->sge_count);
13871401 return 0;
13881402 }
@@ -1435,7 +1449,7 @@ inline int megasas_cmd_type(struct scsi_cmnd *cmd) · 46 unmodified lines
14351449
14361450 /**
14371451 * megasas_dump_pending_frames - Dumps the frame address of all pending cmds
1438− * in FW
1452+ * in FW
14391453 * @instance: Adapter soft state
14401454 */
14411455 static inline void
@@ -1449,63 +1463,60 @@ megasas_dump_pending_frames(struct megasas_instance *instance) · 7 unmodified lines
14491463 u32 sgcount;
14501464 u32 max_cmd = instance->max_fw_cmds;
14511465
1452− printk(KERN_ERR "\nmegasas[%d]: Dumping Frame Phys Address of all pending cmds in FW\n",instance->host->host_no);
1453− printk(KERN_ERR "megasas[%d]: Total OS Pending cmds : %d\n",instance->host->host_no,atomic_read(&instance->fw_outstanding));
1466+ dev_err(&instance->pdev->dev, "[%d]: Dumping Frame Phys Address of all pending cmds in FW\n",instance->host->host_no);
1467+ dev_err(&instance->pdev->dev, "[%d]: Total OS Pending cmds : %d\n",instance->host->host_no,atomic_read(&instance->fw_outstanding));
14541468 if (IS_DMA64)
1455− printk(KERN_ERR "\nmegasas[%d]: 64 bit SGLs were sent to FW\n",instance->host->host_no);
1469+ dev_err(&instance->pdev->dev, "[%d]: 64 bit SGLs were sent to FW\n",instance->host->host_no);
14561470 else
1457− printk(KERN_ERR "\nmegasas[%d]: 32 bit SGLs were sent to FW\n",instance->host->host_no);
1471+ dev_err(&instance->pdev->dev, "[%d]: 32 bit SGLs were sent to FW\n",instance->host->host_no);
14581472
1459− printk(KERN_ERR "megasas[%d]: Pending OS cmds in FW : \n",instance->host->host_no);
1473+ dev_err(&instance->pdev->dev, "[%d]: Pending OS cmds in FW : \n",instance->host->host_no);
14601474 for (i = 0; i < max_cmd; i++) {
14611475 cmd = instance->cmd_list[i];
1462− if(!cmd->scmd)
1476+ if (!cmd->scmd)
14631477 continue;
1464− printk(KERN_ERR "megasas[%d]: Frame addr :0x%08lx : ",instance->host->host_no,(unsigned long)cmd->frame_phys_addr);
1478+ dev_err(&instance->pdev->dev, "[%d]: Frame addr :0x%08lx : ",instance->host->host_no,(unsigned long)cmd->frame_phys_addr);
14651479 if (megasas_cmd_type(cmd->scmd) == READ_WRITE_LDIO) {
14661480 ldio = (struct megasas_io_frame *)cmd->frame;
14671481 mfi_sgl = &ldio->sgl;
14681482 sgcount = ldio->sge_count;
1469− printk(KERN_ERR "megasas[%d]: frame count : 0x%x, Cmd : 0x%x, Tgt id : 0x%x,"
1483+ dev_err(&instance->pdev->dev, "[%d]: frame count : 0x%x, Cmd : 0x%x, Tgt id : 0x%x,"
14701484 " lba lo : 0x%x, lba_hi : 0x%x, sense_buf addr : 0x%x,sge count : 0x%x\n",
14711485 instance->host->host_no, cmd->frame_count, ldio->cmd, ldio->target_id,
14721486 le32_to_cpu(ldio->start_lba_lo), le32_to_cpu(ldio->start_lba_hi),
14731487 le32_to_cpu(ldio->sense_buf_phys_addr_lo), sgcount);
1474− }
1475− else {
1488+ } else {
14761489 pthru = (struct megasas_pthru_frame *) cmd->frame;
14771490 mfi_sgl = &pthru->sgl;
14781491 sgcount = pthru->sge_count;
1479− printk(KERN_ERR "megasas[%d]: frame count : 0x%x, Cmd : 0x%x, Tgt id : 0x%x, "
1492+ dev_err(&instance->pdev->dev, "[%d]: frame count : 0x%x, Cmd : 0x%x, Tgt id : 0x%x, "
14801493 "lun : 0x%x, cdb_len : 0x%x, data xfer len : 0x%x, sense_buf addr : 0x%x,sge count : 0x%x\n",
14811494 instance->host->host_no, cmd->frame_count, pthru->cmd, pthru->target_id,
14821495 pthru->lun, pthru->cdb_len, le32_to_cpu(pthru->data_xfer_len),
14831496 le32_to_cpu(pthru->sense_buf_phys_addr_lo), sgcount);
14841497 }
1485− if(megasas_dbg_lvl & MEGASAS_DBG_LVL){
1486− for (n = 0; n < sgcount; n++){
1487− if (IS_DMA64)
1488− printk(KERN_ERR "megasas: sgl len : 0x%x, sgl addr : 0x%llx ",
1489− le32_to_cpu(mfi_sgl->sge64[n].length),
1490− le64_to_cpu(mfi_sgl->sge64[n].phys_addr));
1491− else
1492− printk(KERN_ERR "megasas: sgl len : 0x%x, sgl addr : 0x%x ",
1493− le32_to_cpu(mfi_sgl->sge32[n].length),
1494− le32_to_cpu(mfi_sgl->sge32[n].phys_addr));
1498+ if (megasas_dbg_lvl & MEGASAS_DBG_LVL) {
1499+ for (n = 0; n < sgcount; n++) {
1500+ if (IS_DMA64)
1501+ dev_err(&instance->pdev->dev, "sgl len : 0x%x, sgl addr : 0x%llx\n",
1502+ le32_to_cpu(mfi_sgl->sge64[n].length),
1503+ le64_to_cpu(mfi_sgl->sge64[n].phys_addr));
1504+ else
1505+ dev_err(&instance->pdev->dev, "sgl len : 0x%x, sgl addr : 0x%x\n",
1506+ le32_to_cpu(mfi_sgl->sge32[n].length),
1507+ le32_to_cpu(mfi_sgl->sge32[n].phys_addr));
14951508 }
14961509 }
1497− printk(KERN_ERR "\n");
14981510 } /*for max_cmd*/
1499− printk(KERN_ERR "\nmegasas[%d]: Pending Internal cmds in FW : \n",instance->host->host_no);
1511+ dev_err(&instance->pdev->dev, "[%d]: Pending Internal cmds in FW : \n",instance->host->host_no);
15001512 for (i = 0; i < max_cmd; i++) {
15011513
15021514 cmd = instance->cmd_list[i];
15031515
1504− if(cmd->sync_cmd == 1){
1505− printk(KERN_ERR "0x%08lx : ", (unsigned long)cmd->frame_phys_addr);
1506− }
1516+ if (cmd->sync_cmd == 1)
1517+ dev_err(&instance->pdev->dev, "0x%08lx : ", (unsigned long)cmd->frame_phys_addr);
15071518 }
1508− printk(KERN_ERR "megasas[%d]: Dumping Done.\n\n",instance->host->host_no);
1519+ dev_err(&instance->pdev->dev, "[%d]: Dumping Done\n\n",instance->host->host_no);
15091520 }
15101521
15111522 u32
@@ -1623,7 +1634,7 @@ megasas_queue_command(struct Scsi_Host *shost, struct scsi_cmnd *scmd) · 111 unmodified lines
16231634 }
16241635
16251636 if (instance->instancet->build_and_issue_cmd(instance, scmd)) {
1626− printk(KERN_ERR "megasas: Err returned from build_and_issue_cmd\n");
1637+ dev_err(&instance->pdev->dev, "Err returned from build_and_issue_cmd\n");
16271638 return SCSI_MLQUEUE_HOST_BUSY;
16281639 }
16291640
@@ -1651,8 +1662,8 @@ static struct megasas_instance *megasas_lookup_instance(u16 host_no) · 21 unmodified lines
16511662 static int megasas_slave_configure(struct scsi_device *sdev)
16521663 {
16531664 /*
1654− * The RAID firmware may require extended timeouts.
1655− */
1665+ * The RAID firmware may require extended timeouts.
1666+ */
16561667 blk_queue_rq_timeout(sdev->request_queue,
16571668 MEGASAS_DEFAULT_CMD_TIMEOUT * HZ);
16581669
@@ -1661,8 +1672,9 @@ static int megasas_slave_configure(struct scsi_device *sdev) · 2 unmodified lines
16611672
16621673 static int megasas_slave_alloc(struct scsi_device *sdev)
16631674 {
1664− u16 pd_index = 0;
1675+ u16 pd_index = 0;
16651676 struct megasas_instance *instance ;
1677+
16661678 instance = megasas_lookup_instance(sdev->host->host_no);
16671679 if (sdev->channel < MEGASAS_MAX_PD_CHANNELS) {
16681680 /*
@@ -1728,8 +1740,7 @@ void megaraid_sas_kill_hba(struct megasas_instance *instance) · 59 unmodified lines
17281740 (instance->pdev->device == PCI_DEVICE_ID_LSI_PLASMA) ||
17291741 (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) ||
17301742 (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY)) {
1731− writel(MFI_STOP_ADP,
1732− &instance->reg_set->doorbell);
1743+ writel(MFI_STOP_ADP, &instance->reg_set->doorbell);
17331744 /* Flush */
17341745 readl(&instance->reg_set->doorbell);
17351746 if (instance->mpio && instance->requestorId)
@@ -1783,7 +1794,7 @@ static void megasas_complete_cmd_dpc(unsigned long instance_addr) · 47 unmodified lines
17831794 unsigned long flags;
17841795
17851796 /* If we have already declared adapter dead, donot complete cmds */
1786− if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR )
1797+ if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR)
17871798 return;
17881799
17891800 spin_lock_irqsave(&instance->completion_lock, flags);
@@ -1794,7 +1805,7 @@ static void megasas_complete_cmd_dpc(unsigned long instance_addr) · 4 unmodified lines
17941805 while (consumer != producer) {
17951806 context = le32_to_cpu(instance->reply_queue[consumer]);
17961807 if (context >= instance->max_fw_cmds) {
1797− printk(KERN_ERR "Unexpected context value %x\n",
1808+ dev_err(&instance->pdev->dev, "Unexpected context value %x\n",
17981809 context);
17991810 BUG();
18001811 }
@@ -1873,8 +1884,8 @@ static int megasas_get_ld_vf_affiliation_111(struct megasas_instance *instance, · 72 unmodified lines
18731884 cmd = megasas_get_cmd(instance);
18741885
18751886 if (!cmd) {
1876− printk(KERN_DEBUG "megasas: megasas_get_ld_vf_affiliation_111:"
1877− "Failed to get cmd for scsi%d.\n",
1887+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "megasas_get_ld_vf_affiliation_111:"
1888+ "Failed to get cmd for scsi%d\n",
18781889 instance->host->host_no);
18791890 return -ENOMEM;
18801891 }
@@ -1882,8 +1893,8 @@ static int megasas_get_ld_vf_affiliation_111(struct megasas_instance *instance, · 1 unmodified line
18821893 dcmd = &cmd->frame->dcmd;
18831894
18841895 if (!instance->vf_affiliation_111) {
1885− printk(KERN_WARNING "megasas: SR-IOV: Couldn't get LD/VF "
1886− "affiliation for scsi%d.\n", instance->host->host_no);
1896+ dev_warn(&instance->pdev->dev, "SR-IOV: Couldn't get LD/VF "
1897+ "affiliation for scsi%d\n", instance->host->host_no);
18871898 megasas_return_cmd(instance, cmd);
18881899 return -ENOMEM;
18891900 }
@@ -1897,8 +1908,8 @@ static int megasas_get_ld_vf_affiliation_111(struct megasas_instance *instance, · 7 unmodified lines
18971908 sizeof(struct MR_LD_VF_AFFILIATION_111),
18981909 &new_affiliation_111_h);
18991910 if (!new_affiliation_111) {
1900− printk(KERN_DEBUG "megasas: SR-IOV: Couldn't allocate "
1901− "memory for new affiliation for scsi%d.\n",
1911+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "SR-IOV: Couldn't allocate "
1912+ "memory for new affiliation for scsi%d\n",
19021913 instance->host->host_no);
19031914 megasas_return_cmd(instance, cmd);
19041915 return -ENOMEM;
@@ -1929,14 +1940,14 @@ static int megasas_get_ld_vf_affiliation_111(struct megasas_instance *instance, · 24 unmodified lines
19291940 dcmd->sgl.sge32[0].length = cpu_to_le32(
19301941 sizeof(struct MR_LD_VF_AFFILIATION_111));
19311942
1932− printk(KERN_WARNING "megasas: SR-IOV: Getting LD/VF affiliation for "
1943+ dev_warn(&instance->pdev->dev, "SR-IOV: Getting LD/VF affiliation for "
19331944 "scsi%d\n", instance->host->host_no);
19341945
19351946 megasas_issue_blocked_cmd(instance, cmd, 0);
19361947
19371948 if (dcmd->cmd_status) {
1938− printk(KERN_WARNING "megasas: SR-IOV: LD/VF affiliation DCMD"
1939− " failed with status 0x%x for scsi%d.\n",
1949+ dev_warn(&instance->pdev->dev, "SR-IOV: LD/VF affiliation DCMD"
1950+ " failed with status 0x%x for scsi%d\n",
19401951 dcmd->cmd_status, instance->host->host_no);
19411952 retval = 1; /* Do a scan if we couldn't get affiliation */
19421953 goto out;
@@ -1947,9 +1958,8 @@ static int megasas_get_ld_vf_affiliation_111(struct megasas_instance *instance, · 4 unmodified lines
19471958 for (ld = 0 ; ld < new_affiliation_111->vdCount; ld++)
19481959 if (instance->vf_affiliation_111->map[ld].policy[thisVf] !=
19491960 new_affiliation_111->map[ld].policy[thisVf]) {
1950− printk(KERN_WARNING "megasas: SR-IOV: "
1951− "Got new LD/VF affiliation "
1952− "for scsi%d.\n",
1961+ dev_warn(&instance->pdev->dev, "SR-IOV: "
1962+ "Got new LD/VF affiliation for scsi%d\n",
19531963 instance->host->host_no);
19541964 memcpy(instance->vf_affiliation_111,
19551965 new_affiliation_111,
@@ -1985,8 +1995,8 @@ static int megasas_get_ld_vf_affiliation_12(struct megasas_instance *instance, · 29 unmodified lines
19851995 cmd = megasas_get_cmd(instance);
19861996
19871997 if (!cmd) {
1988− printk(KERN_DEBUG "megasas: megasas_get_ld_vf_affiliation12: "
1989− "Failed to get cmd for scsi%d.\n",
1998+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "megasas_get_ld_vf_affiliation12: "
1999+ "Failed to get cmd for scsi%d\n",
19902000 instance->host->host_no);
19912001 return -ENOMEM;
19922002 }
@@ -1994,8 +2004,8 @@ static int megasas_get_ld_vf_affiliation_12(struct megasas_instance *instance, · 1 unmodified line
19942004 dcmd = &cmd->frame->dcmd;
19952005
19962006 if (!instance->vf_affiliation) {
1997− printk(KERN_WARNING "megasas: SR-IOV: Couldn't get LD/VF "
1998− "affiliation for scsi%d.\n", instance->host->host_no);
2007+ dev_warn(&instance->pdev->dev, "SR-IOV: Couldn't get LD/VF "
2008+ "affiliation for scsi%d\n", instance->host->host_no);
19992009 megasas_return_cmd(instance, cmd);
20002010 return -ENOMEM;
20012011 }
@@ -2010,8 +2020,8 @@ static int megasas_get_ld_vf_affiliation_12(struct megasas_instance *instance, · 8 unmodified lines
20102020 sizeof(struct MR_LD_VF_AFFILIATION),
20112021 &new_affiliation_h);
20122022 if (!new_affiliation) {
2013− printk(KERN_DEBUG "megasas: SR-IOV: Couldn't allocate "
2014− "memory for new affiliation for scsi%d.\n",
2023+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "SR-IOV: Couldn't allocate "
2024+ "memory for new affiliation for scsi%d\n",
20152025 instance->host->host_no);
20162026 megasas_return_cmd(instance, cmd);
20172027 return -ENOMEM;
@@ -2042,14 +2052,14 @@ static int megasas_get_ld_vf_affiliation_12(struct megasas_instance *instance, · 24 unmodified lines
20422052 dcmd->sgl.sge32[0].length = cpu_to_le32((MAX_LOGICAL_DRIVES + 1) *
20432053 sizeof(struct MR_LD_VF_AFFILIATION));
20442054
2045− printk(KERN_WARNING "megasas: SR-IOV: Getting LD/VF affiliation for "
2055+ dev_warn(&instance->pdev->dev, "SR-IOV: Getting LD/VF affiliation for "
20462056 "scsi%d\n", instance->host->host_no);
20472057
20482058 megasas_issue_blocked_cmd(instance, cmd, 0);
20492059
20502060 if (dcmd->cmd_status) {
2051− printk(KERN_WARNING "megasas: SR-IOV: LD/VF affiliation DCMD"
2052− " failed with status 0x%x for scsi%d.\n",
2061+ dev_warn(&instance->pdev->dev, "SR-IOV: LD/VF affiliation DCMD"
2062+ " failed with status 0x%x for scsi%d\n",
20532063 dcmd->cmd_status, instance->host->host_no);
20542064 retval = 1; /* Do a scan if we couldn't get affiliation */
20552065 goto out;
@@ -2057,8 +2067,8 @@ static int megasas_get_ld_vf_affiliation_12(struct megasas_instance *instance, · 1 unmodified line
20572067
20582068 if (!initial) {
20592069 if (!new_affiliation->ldCount) {
2060− printk(KERN_WARNING "megasas: SR-IOV: Got new LD/VF "
2061− "affiliation for passive path for scsi%d.\n",
2070+ dev_warn(&instance->pdev->dev, "SR-IOV: Got new LD/VF "
2071+ "affiliation for passive path for scsi%d\n",
20622072 instance->host->host_no);
20632073 retval = 1;
20642074 goto out;
@@ -2123,8 +2133,8 @@ static int megasas_get_ld_vf_affiliation_12(struct megasas_instance *instance, · 58 unmodified lines
21232133 }
21242134 out:
21252135 if (doscan) {
2126− printk(KERN_WARNING "megasas: SR-IOV: Got new LD/VF "
2127− "affiliation for scsi%d.\n", instance->host->host_no);
2136+ dev_warn(&instance->pdev->dev, "SR-IOV: Got new LD/VF "
2137+ "affiliation for scsi%d\n", instance->host->host_no);
21282138 memcpy(instance->vf_affiliation, new_affiliation,
21292139 new_affiliation->size);
21302140 retval = 1;
@@ -2164,8 +2174,8 @@ int megasas_sriov_start_heartbeat(struct megasas_instance *instance, · 33 unmodified lines
21642174 cmd = megasas_get_cmd(instance);
21652175
21662176 if (!cmd) {
2167− printk(KERN_DEBUG "megasas: megasas_sriov_start_heartbeat: "
2168− "Failed to get cmd for scsi%d.\n",
2177+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "megasas_sriov_start_heartbeat: "
2178+ "Failed to get cmd for scsi%d\n",
21692179 instance->host->host_no);
21702180 return -ENOMEM;
21712181 }
@@ -2178,9 +2188,9 @@ int megasas_sriov_start_heartbeat(struct megasas_instance *instance, · 6 unmodified lines
21782188 sizeof(struct MR_CTRL_HB_HOST_MEM),
21792189 &instance->hb_host_mem_h);
21802190 if (!instance->hb_host_mem) {
2181− printk(KERN_DEBUG "megasas: SR-IOV: Couldn't allocate"
2182− " memory for heartbeat host memory for "
2183− "scsi%d.\n", instance->host->host_no);
2191+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "SR-IOV: Couldn't allocate"
2192+ " memory for heartbeat host memory for scsi%d\n",
2193+ instance->host->host_no);
21842194 retval = -ENOMEM;
21852195 goto out;
21862196 }
@@ -2200,7 +2210,7 @@ int megasas_sriov_start_heartbeat(struct megasas_instance *instance, · 13 unmodified lines
22002210 dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(instance->hb_host_mem_h);
22012211 dcmd->sgl.sge32[0].length = cpu_to_le32(sizeof(struct MR_CTRL_HB_HOST_MEM));
22022212
2203− printk(KERN_WARNING "megasas: SR-IOV: Starting heartbeat for scsi%d\n",
2213+ dev_warn(&instance->pdev->dev, "SR-IOV: Starting heartbeat for scsi%d\n",
22042214 instance->host->host_no);
22052215
22062216 if (instance->ctrl_context && !instance->mask_interrupts)
@@ -2236,7 +2246,7 @@ void megasas_sriov_heartbeat_handler(unsigned long instance_addr) · 29 unmodified lines
22362246 mod_timer(&instance->sriov_heartbeat_timer,
22372247 jiffies + MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF);
22382248 } else {
2239− printk(KERN_WARNING "megasas: SR-IOV: Heartbeat never "
2249+ dev_warn(&instance->pdev->dev, "SR-IOV: Heartbeat never "
22402250 "completed for scsi%d\n", instance->host->host_no);
22412251 schedule_work(&instance->work_init);
22422252 }
@@ -2274,7 +2284,7 @@ static int megasas_wait_for_outstanding(struct megasas_instance *instance) · 31 unmodified lines
22742284 &clist_local);
22752285 spin_unlock_irqrestore(&instance->hba_lock, flags);
22762286
2277− printk(KERN_NOTICE "megasas: HBA reset wait ...\n");
2287+ dev_notice(&instance->pdev->dev, "HBA reset wait ...\n");
22782288 for (i = 0; i < wait_time; i++) {
22792289 msleep(1000);
22802290 spin_lock_irqsave(&instance->hba_lock, flags);
@@ -2285,28 +2295,28 @@ static int megasas_wait_for_outstanding(struct megasas_instance *instance) · 4 unmodified lines
22852295 }
22862296
22872297 if (adprecovery != MEGASAS_HBA_OPERATIONAL) {
2288− printk(KERN_NOTICE "megasas: reset: Stopping HBA.\n");
2298+ dev_notice(&instance->pdev->dev, "reset: Stopping HBA.\n");
22892299 spin_lock_irqsave(&instance->hba_lock, flags);
2290− instance->adprecovery = MEGASAS_HW_CRITICAL_ERROR;
2300+ instance->adprecovery = MEGASAS_HW_CRITICAL_ERROR;
22912301 spin_unlock_irqrestore(&instance->hba_lock, flags);
22922302 return FAILED;
22932303 }
22942304
2295− reset_index = 0;
2305+ reset_index = 0;
22962306 while (!list_empty(&clist_local)) {
2297− reset_cmd = list_entry((&clist_local)->next,
2307+ reset_cmd = list_entry((&clist_local)->next,
22982308 struct megasas_cmd, list);
22992309 list_del_init(&reset_cmd->list);
23002310 if (reset_cmd->scmd) {
23012311 reset_cmd->scmd->result = DID_RESET << 16;
2302− printk(KERN_NOTICE "%d:%p reset [%02x]\n",
2312+ dev_notice(&instance->pdev->dev, "%d:%p reset [%02x]\n",
23032313 reset_index, reset_cmd,
23042314 reset_cmd->scmd->cmnd[0]);
23052315
23062316 reset_cmd->scmd->scsi_done(reset_cmd->scmd);
23072317 megasas_return_cmd(instance, reset_cmd);
23082318 } else if (reset_cmd->sync_cmd) {
2309− printk(KERN_NOTICE "megasas:%p synch cmds"
2319+ dev_notice(&instance->pdev->dev, "%p synch cmds"
23102320 "reset queue\n",
23112321 reset_cmd);
23122322
@@ -2315,7 +2325,7 @@ static int megasas_wait_for_outstanding(struct megasas_instance *instance) · 2 unmodified lines
23152325 reset_cmd->frame_phys_addr,
23162326 0, instance->reg_set);
23172327 } else {
2318− printk(KERN_NOTICE "megasas: %p unexpected"
2328+ dev_notice(&instance->pdev->dev, "%p unexpected"
23192329 "cmds lst\n",
23202330 reset_cmd);
23212331 }
@@ -2326,14 +2336,13 @@ static int megasas_wait_for_outstanding(struct megasas_instance *instance) · 4 unmodified lines
23262336 }
23272337
23282338 for (i = 0; i < resetwaittime; i++) {
2329−
23302339 int outstanding = atomic_read(&instance->fw_outstanding);
23312340
23322341 if (!outstanding)
23332342 break;
23342343
23352344 if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) {
2336− printk(KERN_NOTICE "megasas: [%2d]waiting for %d "
2345+ dev_notice(&instance->pdev->dev, "[%2d]waiting for %d "
23372346 "commands to complete\n",i,outstanding);
23382347 /*
23392348 * Call cmd completion routine. Cmd to be
@@ -2365,10 +2374,8 @@ static int megasas_wait_for_outstanding(struct megasas_instance *instance) · 25 unmodified lines
23652374 i++;
23662375 } while (i <= 3);
23672376
2368− if (atomic_read(&instance->fw_outstanding) &&
2369− !kill_adapter_flag) {
2377+ if (atomic_read(&instance->fw_outstanding) && !kill_adapter_flag) {
23702378 if (instance->disableOnlineCtrlReset == 0) {
2371−
23722379 megasas_do_ocr(instance);
23732380
23742381 /* wait for 5 secs to let FW finish the pending cmds */
@@ -2384,11 +2391,11 @@ static int megasas_wait_for_outstanding(struct megasas_instance *instance) · 9 unmodified lines
23842391
23852392 if (atomic_read(&instance->fw_outstanding) ||
23862393 (kill_adapter_flag == 2)) {
2387− printk(KERN_NOTICE "megaraid_sas: pending cmds after reset\n");
2394+ dev_notice(&instance->pdev->dev, "pending cmds after reset\n");
23882395 /*
2389− * Send signal to FW to stop processing any pending cmds.
2390− * The controller will be taken offline by the OS now.
2391− */
2396+ * Send signal to FW to stop processing any pending cmds.
2397+ * The controller will be taken offline by the OS now.
2398+ */
23922399 if ((instance->pdev->device ==
23932400 PCI_DEVICE_ID_LSI_SAS0073SKINNY) ||
23942401 (instance->pdev->device ==
@@ -2401,12 +2408,12 @@ static int megasas_wait_for_outstanding(struct megasas_instance *instance) · 6 unmodified lines
24012408 }
24022409 megasas_dump_pending_frames(instance);
24032410 spin_lock_irqsave(&instance->hba_lock, flags);
2404− instance->adprecovery = MEGASAS_HW_CRITICAL_ERROR;
2411+ instance->adprecovery = MEGASAS_HW_CRITICAL_ERROR;
24052412 spin_unlock_irqrestore(&instance->hba_lock, flags);
24062413 return FAILED;
24072414 }
24082415
2409− printk(KERN_NOTICE "megaraid_sas: no pending cmds after reset\n");
2416+ dev_notice(&instance->pdev->dev, "no pending cmds after reset\n");
24102417
24112418 return SUCCESS;
24122419 }
@@ -2430,16 +2437,15 @@ static int megasas_generic_reset(struct scsi_cmnd *scmd) · 17 unmodified lines
24302437 scmd->cmnd[0], scmd->retries);
24312438
24322439 if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) {
2433− printk(KERN_ERR "megasas: cannot recover from previous reset "
2434− "failures\n");
2440+ dev_err(&instance->pdev->dev, "cannot recover from previous reset failures\n");
24352441 return FAILED;
24362442 }
24372443
24382444 ret_val = megasas_wait_for_outstanding(instance);
24392445 if (ret_val == SUCCESS)
2440− printk(KERN_NOTICE "megasas: reset successful \n");
2446+ dev_notice(&instance->pdev->dev, "reset successful\n");
24412447 else
2442− printk(KERN_ERR "megasas: failed to do reset\n");
2448+ dev_err(&instance->pdev->dev, "failed to do reset\n");
24432449
24442450 return ret_val;
24452451 }
@@ -2481,14 +2487,10 @@ blk_eh_timer_return megasas_reset_timer(struct scsi_cmnd *scmd) · 35 unmodified lines
24812487 */
24822488 static int megasas_reset_device(struct scsi_cmnd *scmd)
24832489 {
2484− int ret;
2485−
24862490 /*
24872491 * First wait for all commands to complete
24882492 */
2489− ret = megasas_generic_reset(scmd);
2490−
2491− return ret;
2493+ return megasas_generic_reset(scmd);
24922494 }
24932495
24942496 /**
@@ -2498,6 +2500,7 @@ static int megasas_reset_bus_host(struct scsi_cmnd *scmd) · 3 unmodified lines
24982500 {
24992501 int ret;
25002502 struct megasas_instance *instance;
2503+
25012504 instance = (struct megasas_instance *)scmd->device->host->hostdata;
25022505
25032506 /*
@@ -2516,7 +2519,7 @@ static int megasas_reset_bus_host(struct scsi_cmnd *scmd) · 12 unmodified lines
25162519
25172520 /**
25182521 * megasas_bios_param - Returns disk geometry for a disk
2519− * @sdev: device handle
2522+ * @sdev: device handle
25202523 * @bdev: block device
25212524 * @capacity: drive capacity
25222525 * @geom: geometry parameters
@@ -2529,6 +2532,7 @@ megasas_bios_param(struct scsi_device *sdev, struct block_device *bdev, · 6 unmodified lines
25292532 int sectors;
25302533 sector_t cylinders;
25312534 unsigned long tmp;
2535+
25322536 /* Default heads (64) & sectors (32) */
25332537 heads = 64;
25342538 sectors = 32;
@@ -2575,6 +2579,7 @@ static void · 40 unmodified lines
25752579 megasas_service_aen(struct megasas_instance *instance, struct megasas_cmd *cmd)
25762580 {
25772581 unsigned long flags;
2582+
25782583 /*
25792584 * Don't signal app if it is just an aborted previously registered aen
25802585 */
@@ -2595,9 +2600,10 @@ megasas_service_aen(struct megasas_instance *instance, struct megasas_cmd *cmd) · 14 unmodified lines
25952600 if ((instance->unload == 0) &&
25962601 ((instance->issuepend_done == 1))) {
25972602 struct megasas_aen_event *ev;
2603+
25982604 ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
25992605 if (!ev) {
2600− printk(KERN_ERR "megasas_service_aen: out of memory\n");
2606+ dev_err(&instance->pdev->dev, "megasas_service_aen: out of memory\n");
26012607 } else {
26022608 ev->instance = instance;
26032609 instance->ev = ev;
@@ -2654,8 +2660,7 @@ megasas_fw_crash_buffer_show(struct device *cdev, · 50 unmodified lines
26542660
26552661 buff_addr = (unsigned long) buf;
26562662
2657− if (buff_offset >
2658− (instance->fw_crash_buffer_size * dmachunk)) {
2663+ if (buff_offset > (instance->fw_crash_buffer_size * dmachunk)) {
26592664 dev_err(&instance->pdev->dev,
26602665 "Firmware crash dump offset is out of range\n");
26612666 spin_unlock_irqrestore(&instance->crashdump_lock, flags);
@@ -2667,7 +2672,7 @@ megasas_fw_crash_buffer_show(struct device *cdev, · 5 unmodified lines
26672672
26682673 src_addr = (unsigned long)instance->crash_buf[buff_offset / dmachunk] +
26692674 (buff_offset % dmachunk);
2670− memcpy(buf, (void *)src_addr, size);
2675+ memcpy(buf, (void *)src_addr, size);
26712676 spin_unlock_irqrestore(&instance->crashdump_lock, flags);
26722677
26732678 return size;
@@ -2727,6 +2732,7 @@ megasas_fw_crash_state_show(struct device *cdev, · 53 unmodified lines
27272732 struct Scsi_Host *shost = class_to_shost(cdev);
27282733 struct megasas_instance *instance =
27292734 (struct megasas_instance *) shost->hostdata;
2735+
27302736 return snprintf(buf, PAGE_SIZE, "%d\n", instance->fw_crash_state);
27312737 }
27322738
@@ -2811,8 +2817,6 @@ megasas_complete_abort(struct megasas_instance *instance, · 78 unmodified lines
28112817 cmd->cmd_status_drv = 0;
28122818 wake_up(&instance->abort_cmd_wait_q);
28132819 }
2814−
2815− return;
28162820 }
28172821
28182822 /**
@@ -2820,10 +2824,10 @@ megasas_complete_abort(struct megasas_instance *instance, · 1 unmodified line
28202824 * @instance: Adapter soft state
28212825 * @cmd: Command to be completed
28222826 * @alt_status: If non-zero, use this value as status to
2823− * SCSI mid-layer instead of the value returned
2824− * by the FW. This should be used if caller wants
2825− * an alternate status (as in the case of aborted
2826− * commands)
2827+ * SCSI mid-layer instead of the value returned
2828+ * by the FW. This should be used if caller wants
2829+ * an alternate status (as in the case of aborted
2830+ * commands)
28272831 */
28282832 void
28292833 megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd,
@@ -2847,10 +2851,10 @@ megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd, · 17 unmodified lines
28472851 MR_DCMD_CTRL_EVENT_GET_INFO left over from the main kernel
28482852 when booting the kdump kernel. Ignore this command to
28492853 prevent a kernel panic on shutdown of the kdump kernel. */
2850− printk(KERN_WARNING "megaraid_sas: MFI_CMD_INVALID command "
2851− "completed.\n");
2852− printk(KERN_WARNING "megaraid_sas: If you have a controller "
2853− "other than PERC5, please upgrade your firmware.\n");
2854+ dev_warn(&instance->pdev->dev, "MFI_CMD_INVALID command "
2855+ "completed\n");
2856+ dev_warn(&instance->pdev->dev, "If you have a controller "
2857+ "other than PERC5, please upgrade your firmware\n");
28542858 break;
28552859 case MFI_CMD_PD_SCSI_IO:
28562860 case MFI_CMD_LD_SCSI_IO:
@@ -2918,7 +2922,7 @@ megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd, · 61 unmodified lines
29182922 break;
29192923
29202924 default:
2921− printk(KERN_DEBUG "megasas: MFI FW status %#x\n",
2925+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "MFI FW status %#x\n",
29222926 hdr->cmd_status);
29232927 cmd->scmd->result = DID_ERROR << 16;
29242928 break;
@@ -2944,8 +2948,7 @@ megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd, · 19 unmodified lines
29442948 if (cmd->frame->hdr.cmd_status != 0) {
29452949 if (cmd->frame->hdr.cmd_status !=
29462950 MFI_STAT_NOT_FOUND)
2947− printk(KERN_WARNING "megasas: map sync"
2948− "failed, status = 0x%x.\n",
2951+ dev_warn(&instance->pdev->dev, "map syncfailed, status = 0x%x\n",
29492952 cmd->frame->hdr.cmd_status);
29502953 else {
29512954 megasas_return_cmd(instance, cmd);
@@ -2997,7 +3000,7 @@ megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd, · 45 unmodified lines
29973000 break;
29983001
29993002 default:
3000− printk("megasas: Unknown command completed! [0x%X]\n",
3003+ dev_info(&instance->pdev->dev, "Unknown command completed! [0x%X]\n",
30013004 hdr->cmd);
30023005 break;
30033006 }
@@ -3005,7 +3008,7 @@ megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd, · 1 unmodified line
30053008
30063009 /**
30073010 * megasas_issue_pending_cmds_again - issue all pending cmds
3008− * in FW again because of the fw reset
3011+ * in FW again because of the fw reset
30093012 * @instance: Adapter soft state
30103013 */
30113014 static inline void
@@ -3023,19 +3026,19 @@ megasas_issue_pending_cmds_again(struct megasas_instance *instance) · 11 unmodified lines
30233026 spin_unlock_irqrestore(&instance->hba_lock, flags);
30243027
30253028 while (!list_empty(&clist_local)) {
3026− cmd = list_entry((&clist_local)->next,
3029+ cmd = list_entry((&clist_local)->next,
30273030 struct megasas_cmd, list);
30283031 list_del_init(&cmd->list);
30293032
30303033 if (cmd->sync_cmd || cmd->scmd) {
3031− printk(KERN_NOTICE "megaraid_sas: command %p, %p:%d"
3032− "detected to be pending while HBA reset.\n",
3034+ dev_notice(&instance->pdev->dev, "command %p, %p:%d"
3035+ "detected to be pending while HBA reset\n",
30333036 cmd, cmd->scmd, cmd->sync_cmd);
30343037
30353038 cmd->retry_for_fw_reset++;
30363039
30373040 if (cmd->retry_for_fw_reset == 3) {
3038− printk(KERN_NOTICE "megaraid_sas: cmd %p, %p:%d"
3041+ dev_notice(&instance->pdev->dev, "cmd %p, %p:%d"
30393042 "was tried multiple times during reset."
30403043 "Shutting down the HBA\n",
30413044 cmd, cmd->scmd, cmd->sync_cmd);
@@ -3048,18 +3051,18 @@ megasas_issue_pending_cmds_again(struct megasas_instance *instance) · 6 unmodified lines
30483051
30493052 if (cmd->sync_cmd == 1) {
30503053 if (cmd->scmd) {
3051− printk(KERN_NOTICE "megaraid_sas: unexpected"
3054+ dev_notice(&instance->pdev->dev, "unexpected"
30523055 "cmd attached to internal command!\n");
30533056 }
3054− printk(KERN_NOTICE "megasas: %p synchronous cmd"
3057+ dev_notice(&instance->pdev->dev, "%p synchronous cmd"
30553058 "on the internal reset queue,"
30563059 "issue it again.\n", cmd);
30573060 cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS;
30583061 instance->instancet->fire_cmd(instance,
3059− cmd->frame_phys_addr ,
3062+ cmd->frame_phys_addr,
30603063 0, instance->reg_set);
30613064 } else if (cmd->scmd) {
3062− printk(KERN_NOTICE "megasas: %p scsi cmd [%02x]"
3065+ dev_notice(&instance->pdev->dev, "%p scsi cmd [%02x]"
30633066 "detected on the internal queue, issue again.\n",
30643067 cmd, cmd->scmd->cmnd[0]);
30653068
@@ -3068,22 +3071,22 @@ megasas_issue_pending_cmds_again(struct megasas_instance *instance) · 2 unmodified lines
30683071 cmd->frame_phys_addr,
30693072 cmd->frame_count-1, instance->reg_set);
30703073 } else {
3071− printk(KERN_NOTICE "megasas: %p unexpected cmd on the"
3074+ dev_notice(&instance->pdev->dev, "%p unexpected cmd on the"
30723075 "internal reset defer list while re-issue!!\n",
30733076 cmd);
30743077 }
30753078 }
30763079
30773080 if (instance->aen_cmd) {
3078− printk(KERN_NOTICE "megaraid_sas: aen_cmd in def process\n");
3081+ dev_notice(&instance->pdev->dev, "aen_cmd in def process\n");
30793082 megasas_return_cmd(instance, instance->aen_cmd);
30803083
3081− instance->aen_cmd = NULL;
3084+ instance->aen_cmd = NULL;
30823085 }
30833086
30843087 /*
3085− * Initiate AEN (Asynchronous Event Notification)
3086− */
3088+ * Initiate AEN (Asynchronous Event Notification)
3089+ */
30873090 seq_num = instance->last_seq_num;
30883091 class_locale.members.reserved = 0;
30893092 class_locale.members.locale = MR_EVT_LOCALE_ALL;
@@ -3110,17 +3113,17 @@ megasas_internal_reset_defer_cmds(struct megasas_instance *instance) · 20 unmodified lines
31103113 u32 defer_index;
31113114 unsigned long flags;
31123115
3113− defer_index = 0;
3116+ defer_index = 0;
31143117 spin_lock_irqsave(&instance->mfi_pool_lock, flags);
31153118 for (i = 0; i < max_cmd; i++) {
31163119 cmd = instance->cmd_list[i];
31173120 if (cmd->sync_cmd == 1 || cmd->scmd) {
3118− printk(KERN_NOTICE "megasas: moving cmd[%d]:%p:%d:%p"
3121+ dev_notice(&instance->pdev->dev, "moving cmd[%d]:%p:%d:%p"
31193122 "on the defer queue as internal\n",
31203123 defer_index, cmd, cmd->sync_cmd, cmd->scmd);
31213124
31223125 if (!list_empty(&cmd->list)) {
3123− printk(KERN_NOTICE "megaraid_sas: ERROR while"
3126+ dev_notice(&instance->pdev->dev, "ERROR while"
31243127 " moving this cmd:%p, %d %p, it was"
31253128 "discovered on some list?\n",
31263129 cmd, cmd->sync_cmd, cmd->scmd);
@@ -3145,13 +3148,13 @@ process_fw_state_change_wq(struct work_struct *work) · 18 unmodified lines
31453148 unsigned long flags;
31463149
31473150 if (instance->adprecovery != MEGASAS_ADPRESET_SM_INFAULT) {
3148− printk(KERN_NOTICE "megaraid_sas: error, recovery st %x \n",
3151+ dev_notice(&instance->pdev->dev, "error, recovery st %x\n",
31493152 instance->adprecovery);
31503153 return ;
31513154 }
31523155
31533156 if (instance->adprecovery == MEGASAS_ADPRESET_SM_INFAULT) {
3154− printk(KERN_NOTICE "megaraid_sas: FW detected to be in fault"
3157+ dev_notice(&instance->pdev->dev, "FW detected to be in fault"
31553158 "state, restarting it...\n");
31563159
31573160 instance->instancet->disable_intr(instance);
@@ -3159,21 +3162,21 @@ process_fw_state_change_wq(struct work_struct *work) · 1 unmodified line
31593162
31603163 atomic_set(&instance->fw_reset_no_pci_access, 1);
31613164 instance->instancet->adp_reset(instance, instance->reg_set);
3162− atomic_set(&instance->fw_reset_no_pci_access, 0 );
3165+ atomic_set(&instance->fw_reset_no_pci_access, 0);
31633166
3164− printk(KERN_NOTICE "megaraid_sas: FW restarted successfully,"
3167+ dev_notice(&instance->pdev->dev, "FW restarted successfully,"
31653168 "initiating next stage...\n");
31663169
3167− printk(KERN_NOTICE "megaraid_sas: HBA recovery state machine,"
3170+ dev_notice(&instance->pdev->dev, "HBA recovery state machine,"
31683171 "state 2 starting...\n");
31693172
3170− /*waitting for about 20 second before start the second init*/
3173+ /* waiting for about 20 second before start the second init */
31713174 for (wait = 0; wait < 30; wait++) {
31723175 msleep(1000);
31733176 }
31743177
31753178 if (megasas_transition_to_ready(instance, 1)) {
3176− printk(KERN_NOTICE "megaraid_sas:adapter not ready\n");
3179+ dev_notice(&instance->pdev->dev, "adapter not ready\n");
31773180
31783181 atomic_set(&instance->fw_reset_no_pci_access, 1);
31793182 megaraid_sas_kill_hba(instance);
@@ -3200,15 +3203,14 @@ process_fw_state_change_wq(struct work_struct *work) · 20 unmodified lines
32003203 megasas_issue_pending_cmds_again(instance);
32013204 instance->issuepend_done = 1;
32023205 }
3203− return ;
32043206 }
32053207
32063208 /**
32073209 * megasas_deplete_reply_queue - Processes all completed commands
32083210 * @instance: Adapter soft state
32093211 * @alt_status: Alternate status to be returned to
3210− * SCSI mid-layer instead of the status
3211− * returned by the FW
3212+ * SCSI mid-layer instead of the status
3213+ * returned by the FW
32123214 * Note: this must be called with hba lock held
32133215 */
32143216 static int
@@ -3238,13 +3240,13 @@ megasas_deplete_reply_queue(struct megasas_instance *instance, · 23 unmodified lines
32383240 instance->reg_set) & MFI_STATE_MASK;
32393241
32403242 if (fw_state != MFI_STATE_FAULT) {
3241− printk(KERN_NOTICE "megaraid_sas: fw state:%x\n",
3243+ dev_notice(&instance->pdev->dev, "fw state:%x\n",
32423244 fw_state);
32433245 }
32443246
32453247 if ((fw_state == MFI_STATE_FAULT) &&
32463248 (instance->disableOnlineCtrlReset == 0)) {
3247− printk(KERN_NOTICE "megaraid_sas: wait adp restart\n");
3249+ dev_notice(&instance->pdev->dev, "wait adp restart\n");
32483250
32493251 if ((instance->pdev->device ==
32503252 PCI_DEVICE_ID_LSI_SAS1064R) ||
@@ -3265,14 +3267,14 @@ megasas_deplete_reply_queue(struct megasas_instance *instance, · 14 unmodified lines
32653267 atomic_set(&instance->fw_outstanding, 0);
32663268 megasas_internal_reset_defer_cmds(instance);
32673269
3268− printk(KERN_NOTICE "megasas: fwState=%x, stage:%d\n",
3270+ dev_notice(&instance->pdev->dev, "fwState=%x, stage:%d\n",
32693271 fw_state, instance->adprecovery);
32703272
32713273 schedule_work(&instance->work_init);
32723274 return IRQ_HANDLED;
32733275
32743276 } else {
3275− printk(KERN_NOTICE "megasas: fwstate:%x, dis_OCR=%x\n",
3277+ dev_notice(&instance->pdev->dev, "fwstate:%x, dis_OCR=%x\n",
32763278 fw_state, instance->disableOnlineCtrlReset);
32773279 }
32783280 }
@@ -3288,13 +3290,13 @@ static irqreturn_t megasas_isr(int irq, void *devp) · 9 unmodified lines
32883290 struct megasas_irq_context *irq_context = devp;
32893291 struct megasas_instance *instance = irq_context->instance;
32903292 unsigned long flags;
3291− irqreturn_t rc;
3293+ irqreturn_t rc;
32923294
32933295 if (atomic_read(&instance->fw_reset_no_pci_access))
32943296 return IRQ_HANDLED;
32953297
32963298 spin_lock_irqsave(&instance->hba_lock, flags);
3297− rc = megasas_deplete_reply_queue(instance, DID_OK);
3299+ rc = megasas_deplete_reply_queue(instance, DID_OK);
32983300 spin_unlock_irqrestore(&instance->hba_lock, flags);
32993301
33003302 return rc;
@@ -3322,7 +3324,7 @@ megasas_transition_to_ready(struct megasas_instance *instance, int ocr) · 21 unmodified lines
33223324 fw_state = abs_state & MFI_STATE_MASK;
33233325
33243326 if (fw_state != MFI_STATE_READY)
3325− printk(KERN_INFO "megasas: Waiting for FW to come to ready"
3327+ dev_info(&instance->pdev->dev, "Waiting for FW to come to ready"
33263328 " state\n");
33273329
33283330 while (fw_state != MFI_STATE_READY) {
@@ -3330,7 +3332,7 @@ megasas_transition_to_ready(struct megasas_instance *instance, int ocr) · 1 unmodified line
33303332 switch (fw_state) {
33313333
33323334 case MFI_STATE_FAULT:
3333− printk(KERN_DEBUG "megasas: FW in FAULT state!!\n");
3335+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "FW in FAULT state!!\n");
33343336 if (ocr) {
33353337 max_wait = MEGASAS_RESET_WAIT_TIME;
33363338 cur_state = MFI_STATE_FAULT;
@@ -3469,7 +3471,7 @@ megasas_transition_to_ready(struct megasas_instance *instance, int ocr) · 132 unmodified lines
34693471 break;
34703472
34713473 default:
3472− printk(KERN_DEBUG "megasas: Unknown state 0x%x\n",
3474+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "Unknown state 0x%x\n",
34733475 fw_state);
34743476 return -ENODEV;
34753477 }
@@ -3491,7 +3493,7 @@ megasas_transition_to_ready(struct megasas_instance *instance, int ocr) · 15 unmodified lines
34913493 * Return error if fw_state hasn't changed after max_wait
34923494 */
34933495 if (curr_abs_state == abs_state) {
3494− printk(KERN_DEBUG "FW state [%d] hasn't changed "
3496+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "FW state [%d] hasn't changed "
34953497 "in %d secs\n", fw_state, max_wait);
34963498 return -ENODEV;
34973499 }
@@ -3499,7 +3501,7 @@ megasas_transition_to_ready(struct megasas_instance *instance, int ocr) · 1 unmodified line
34993501 abs_state = curr_abs_state;
35003502 fw_state = curr_abs_state & MFI_STATE_MASK;
35013503 }
3502− printk(KERN_INFO "megasas: FW now in Ready state\n");
3504+ dev_info(&instance->pdev->dev, "FW now in Ready state\n");
35033505
35043506 return 0;
35053507 }
@@ -3570,9 +3572,8 @@ static int megasas_create_frame_pool(struct megasas_instance *instance) · 64 unmodified lines
35703572 sge_sz = (IS_DMA64) ? sizeof(struct megasas_sge64) :
35713573 sizeof(struct megasas_sge32);
35723574
3573− if (instance->flag_ieee) {
3575+ if (instance->flag_ieee)
35743576 sge_sz = sizeof(struct megasas_sge_skinny);
3575− }
35763577
35773578 /*
35783579 * For MFI controllers.
@@ -3594,7 +3595,7 @@ static int megasas_create_frame_pool(struct megasas_instance *instance) · 15 unmodified lines
35943595 instance->pdev, total_sz, 256, 0);
35953596
35963597 if (!instance->frame_dma_pool) {
3597− printk(KERN_DEBUG "megasas: failed to setup frame pool\n");
3598+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "failed to setup frame pool\n");
35983599 return -ENOMEM;
35993600 }
36003601
@@ -3602,7 +3603,7 @@ static int megasas_create_frame_pool(struct megasas_instance *instance) · 1 unmodified line
36023603 instance->pdev, 128, 4, 0);
36033604
36043605 if (!instance->sense_dma_pool) {
3605− printk(KERN_DEBUG "megasas: failed to setup sense pool\n");
3606+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "failed to setup sense pool\n");
36063607
36073608 pci_pool_destroy(instance->frame_dma_pool);
36083609 instance->frame_dma_pool = NULL;
@@ -3630,7 +3631,7 @@ static int megasas_create_frame_pool(struct megasas_instance *instance) · 21 unmodified lines
36303631 * whatever has been allocated
36313632 */
36323633 if (!cmd->frame || !cmd->sense) {
3633− printk(KERN_DEBUG "megasas: pci_pool_alloc failed \n");
3634+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "pci_pool_alloc failed\n");
36343635 megasas_teardown_frame_pool(instance);
36353636 return -ENOMEM;
36363637 }
@@ -3656,6 +3657,7 @@ static int megasas_create_frame_pool(struct megasas_instance *instance) · 19 unmodified lines
36563657 void megasas_free_cmds(struct megasas_instance *instance)
36573658 {
36583659 int i;
3660+
36593661 /* First free the MFI frame pool */
36603662 megasas_teardown_frame_pool(instance);
36613663
@@ -3708,7 +3710,7 @@ int megasas_alloc_cmds(struct megasas_instance *instance) · 46 unmodified lines
37083710 instance->cmd_list = kcalloc(max_cmd, sizeof(struct megasas_cmd*), GFP_KERNEL);
37093711
37103712 if (!instance->cmd_list) {
3711− printk(KERN_DEBUG "megasas: out of memory\n");
3713+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "out of memory\n");
37123714 return -ENOMEM;
37133715 }
37143716
@@ -3744,7 +3746,7 @@ int megasas_alloc_cmds(struct megasas_instance *instance) · 29 unmodified lines
37443746 * Create a frame pool and assign one frame to each cmd
37453747 */
37463748 if (megasas_create_frame_pool(instance)) {
3747− printk(KERN_DEBUG "megasas: Error creating frame DMA pool\n");
3749+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "Error creating frame DMA pool\n");
37483750 megasas_free_cmds(instance);
37493751 }
37503752
@@ -3773,7 +3775,7 @@ megasas_get_pd_list(struct megasas_instance *instance) · 22 unmodified lines
37733775 cmd = megasas_get_cmd(instance);
37743776
37753777 if (!cmd) {
3776− printk(KERN_DEBUG "megasas (get_pd_list): Failed to get cmd\n");
3778+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "(get_pd_list): Failed to get cmd\n");
37773779 return -ENOMEM;
37783780 }
37793781
@@ -3783,7 +3785,7 @@ megasas_get_pd_list(struct megasas_instance *instance) · 3 unmodified lines
37833785 MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST), &ci_h);
37843786
37853787 if (!ci) {
3786− printk(KERN_DEBUG "Failed to alloc mem for pd_list\n");
3788+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to alloc mem for pd_list\n");
37873789 megasas_return_cmd(instance, cmd);
37883790 return -ENOMEM;
37893791 }
@@ -3811,12 +3813,12 @@ megasas_get_pd_list(struct megasas_instance *instance) · 21 unmodified lines
38113813 ret = megasas_issue_polled(instance, cmd);
38123814
38133815 /*
3814− * the following function will get the instance PD LIST.
3815− */
3816+ * the following function will get the instance PD LIST.
3817+ */
38163818
38173819 pd_addr = ci->addr;
38183820
3819− if ( ret == 0 &&
3821+ if (ret == 0 &&
38203822 (le32_to_cpu(ci->count) <
38213823 (MEGASAS_MAX_PD_CHANNELS * MEGASAS_MAX_DEV_PER_CHANNEL))) {
38223824
@@ -3868,7 +3870,7 @@ megasas_get_ld_list(struct megasas_instance *instance) · 45 unmodified lines
38683870 cmd = megasas_get_cmd(instance);
38693871
38703872 if (!cmd) {
3871− printk(KERN_DEBUG "megasas_get_ld_list: Failed to get cmd\n");
3873+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "megasas_get_ld_list: Failed to get cmd\n");
38723874 return -ENOMEM;
38733875 }
38743876
@@ -3879,7 +3881,7 @@ megasas_get_ld_list(struct megasas_instance *instance) · 4 unmodified lines
38793881 &ci_h);
38803882
38813883 if (!ci) {
3882− printk(KERN_DEBUG "Failed to alloc mem in get_ld_list\n");
3884+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to alloc mem in get_ld_list\n");
38833885 megasas_return_cmd(instance, cmd);
38843886 return -ENOMEM;
38853887 }
@@ -3954,8 +3956,8 @@ megasas_ld_list_query(struct megasas_instance *instance, u8 query_type) · 68 unmodified lines
39543956 cmd = megasas_get_cmd(instance);
39553957
39563958 if (!cmd) {
3957− printk(KERN_WARNING
3958− "megasas:(megasas_ld_list_query): Failed to get cmd\n");
3959+ dev_warn(&instance->pdev->dev,
3960+ "megasas_ld_list_query: Failed to get cmd\n");
39593961 return -ENOMEM;
39603962 }
39613963
@@ -3965,8 +3967,8 @@ megasas_ld_list_query(struct megasas_instance *instance, u8 query_type) · 3 unmodified lines
39653967 sizeof(struct MR_LD_TARGETID_LIST), &ci_h);
39663968
39673969 if (!ci) {
3968− printk(KERN_WARNING
3969− "megasas: Failed to alloc mem for ld_list_query\n");
3970+ dev_warn(&instance->pdev->dev,
3971+ "Failed to alloc mem for ld_list_query\n");
39703972 megasas_return_cmd(instance, cmd);
39713973 return -ENOMEM;
39723974 }
@@ -4052,11 +4054,11 @@ static void megasas_update_ext_vd_details(struct megasas_instance *instance) · 79 unmodified lines
40524054 instance->supportmax256vd ? "Extended VD(240 VD)firmware" :
40534055 "Legacy(64 VD) firmware");
40544056
4055− old_map_sz = sizeof(struct MR_FW_RAID_MAP) +
4057+ old_map_sz = sizeof(struct MR_FW_RAID_MAP) +
40564058 (sizeof(struct MR_LD_SPAN_MAP) *
40574059 (instance->fw_supported_vd_count - 1));
4058− new_map_sz = sizeof(struct MR_FW_RAID_MAP_EXT);
4059− fusion->drv_map_sz = sizeof(struct MR_DRV_RAID_MAP) +
4060+ new_map_sz = sizeof(struct MR_FW_RAID_MAP_EXT);
4061+ fusion->drv_map_sz = sizeof(struct MR_DRV_RAID_MAP) +
40604062 (sizeof(struct MR_LD_SPAN_MAP) *
40614063 (instance->drv_supported_vd_count - 1));
40624064
@@ -4067,7 +4069,6 @@ static void megasas_update_ext_vd_details(struct megasas_instance *instance) · 4 unmodified lines
40674069 fusion->current_map_sz = new_map_sz;
40684070 else
40694071 fusion->current_map_sz = old_map_sz;
4070−
40714072 }
40724073
40734074 /**
@@ -4093,7 +4094,7 @@ megasas_get_ctrl_info(struct megasas_instance *instance) · 19 unmodified lines
40934094 cmd = megasas_get_cmd(instance);
40944095
40954096 if (!cmd) {
4096− printk(KERN_DEBUG "megasas: Failed to get a free cmd\n");
4097+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to get a free cmd\n");
40974098 return -ENOMEM;
40984099 }
40994100
@@ -4103,7 +4104,7 @@ megasas_get_ctrl_info(struct megasas_instance *instance) · 3 unmodified lines
41034104 sizeof(struct megasas_ctrl_info), &ci_h);
41044105
41054106 if (!ci) {
4106− printk(KERN_DEBUG "Failed to alloc mem for ctrl info\n");
4107+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to alloc mem for ctrl info\n");
41074108 megasas_return_cmd(instance, cmd);
41084109 return -ENOMEM;
41094110 }
@@ -4214,9 +4215,7 @@ static int · 104 unmodified lines
42144215 megasas_issue_init_mfi(struct megasas_instance *instance)
42154216 {
42164217 __le32 context;
4217−
42184218 struct megasas_cmd *cmd;
4219−
42204219 struct megasas_init_frame *init_frame;
42214220 struct megasas_init_queue_info *initq_info;
42224221 dma_addr_t init_frame_h;
@@ -4269,7 +4268,7 @@ megasas_issue_init_mfi(struct megasas_instance *instance) · 46 unmodified lines
42694268 */
42704269
42714270 if (megasas_issue_polled(instance, cmd)) {
4272− printk(KERN_ERR "megasas: Failed to init firmware\n");
4271+ dev_err(&instance->pdev->dev, "Failed to init firmware\n");
42734272 megasas_return_cmd(instance, cmd);
42744273 goto fail_fw_init;
42754274 }
@@ -4342,7 +4341,7 @@ megasas_init_adapter_mfi(struct megasas_instance *instance) · 66 unmodified lines
43424341 &instance->reply_queue_h);
43434342
43444343 if (!instance->reply_queue) {
4345− printk(KERN_DEBUG "megasas: Out of DMA mem for reply queue\n");
4344+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "Out of DMA mem for reply queue\n");
43464345 goto fail_reply_queue;
43474346 }
43484347
@@ -4361,7 +4360,7 @@ megasas_init_adapter_mfi(struct megasas_instance *instance) · 12 unmodified lines
43614360 (instance->instancet->read_fw_status_reg(reg_set) &
43624361 0x04000000);
43634362
4364− printk(KERN_NOTICE "megasas_init_mfi: fw_support_ieee=%d",
4363+ dev_notice(&instance->pdev->dev, "megasas_init_mfi: fw_support_ieee=%d",
43654364 instance->fw_support_ieee);
43664365
43674366 if (instance->fw_support_ieee)
@@ -4505,7 +4504,7 @@ static int megasas_init_fw(struct megasas_instance *instance) · 137 unmodified lines
45054504 instance->bar = find_first_bit(&bar_list, sizeof(unsigned long));
45064505 if (pci_request_selected_regions(instance->pdev, instance->bar,
45074506 "megasas: LSI")) {
4508− printk(KERN_DEBUG "megasas: IO memory region busy!\n");
4507+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "IO memory region busy!\n");
45094508 return -EBUSY;
45104509 }
45114510
@@ -4513,7 +4512,7 @@ static int megasas_init_fw(struct megasas_instance *instance) · 1 unmodified line
45134512 instance->reg_set = ioremap_nocache(base_addr, 8192);
45144513
45154514 if (!instance->reg_set) {
4516− printk(KERN_DEBUG "megasas: Failed to map IO mem\n");
4515+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to map IO mem\n");
45174516 goto fail_ioremap;
45184517 }
45194518
@@ -4551,7 +4550,7 @@ static int megasas_init_fw(struct megasas_instance *instance) · 31 unmodified lines
45514550 (instance, instance->reg_set);
45524551 atomic_set(&instance->fw_reset_no_pci_access, 0);
45534552 dev_info(&instance->pdev->dev,
4554− "megasas: FW restarted successfully from %s!\n",
4553+ "FW restarted successfully from %s!\n",
45554554 __func__);
45564555
45574556 /*waitting for about 30 second before retry*/
@@ -4652,16 +4651,15 @@ static int megasas_init_fw(struct megasas_instance *instance) · 94 unmodified lines
46524651
46534652 instance->instancet->enable_intr(instance);
46544653
4655− printk(KERN_ERR "megasas: INIT adapter done\n");
4654+ dev_err(&instance->pdev->dev, "INIT adapter done\n");
46564655
46574656 /** for passthrough
4658− * the following function will get the PD LIST.
4659− */
4660−
4661− memset(instance->pd_list, 0 ,
4657+ * the following function will get the PD LIST.
4658+ */
4659+ memset(instance->pd_list, 0,
46624660 (MEGASAS_MAX_PD * sizeof(struct megasas_pd_list)));
46634661 if (megasas_get_pd_list(instance) < 0) {
4664− printk(KERN_ERR "megasas: failed to get PD list\n");
4662+ dev_err(&instance->pdev->dev, "failed to get PD list\n");
46654663 goto fail_get_pd_list;
46664664 }
46674665
@@ -4686,7 +4684,7 @@ static int megasas_init_fw(struct megasas_instance *instance) · 18 unmodified lines
46864684 le16_to_cpu(ctrl_info->max_strips_per_io);
46874685 max_sectors_2 = le32_to_cpu(ctrl_info->max_request_size);
46884686
4689− tmp_sectors = min_t(u32, max_sectors_1 , max_sectors_2);
4687+ tmp_sectors = min_t(u32, max_sectors_1, max_sectors_2);
46904688
46914689 instance->disableOnlineCtrlReset =
46924690 ctrl_info->properties.OnOffProperties.disableOnlineCtrlReset;
@@ -4960,7 +4958,7 @@ megasas_register_aen(struct megasas_instance *instance, u32 seq_num, · 267 unmodified lines
49604958 aen_cmd, 30);
49614959
49624960 if (ret_val) {
4963− printk(KERN_DEBUG "megasas: Failed to abort "
4961+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to abort "
49644962 "previous AEN command\n");
49654963 return ret_val;
49664964 }
@@ -5051,7 +5049,7 @@ static int megasas_start_aen(struct megasas_instance *instance) · 84 unmodified lines
50515049 static int megasas_io_attach(struct megasas_instance *instance)
50525050 {
50535051 struct Scsi_Host *host = instance->host;
5054− u32 error;
5052+ u32 error;
50555053
50565054 /*
50575055 * Export parameters required by SCSI mid-layer
@@ -5079,7 +5077,7 @@ static int megasas_io_attach(struct megasas_instance *instance) · 21 unmodified lines
50795077 (max_sectors <= MEGASAS_MAX_SECTORS)) {
50805078 instance->max_sectors_per_req = max_sectors;
50815079 } else {
5082− printk(KERN_INFO "megasas: max_sectors should be > 0"
5080+ dev_info(&instance->pdev->dev, "max_sectors should be > 0"
50835081 "and <= %d (or < 1MB for GEN2 controller)\n",
50845082 instance->max_sectors_per_req);
50855083 }
@@ -5126,7 +5124,7 @@ static int · 40 unmodified lines
51265124 megasas_set_dma_mask(struct pci_dev *pdev)
51275125 {
51285126 /*
5129− * All our contollers are capable of performing 64-bit DMA
5127+ * All our controllers are capable of performing 64-bit DMA
51305128 */
51315129 if (IS_DMA64) {
51325130 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) {
@@ -5206,13 +5204,13 @@ static int megasas_probe_one(struct pci_dev *pdev, · 73 unmodified lines
52065204 sizeof(struct megasas_instance));
52075205
52085206 if (!host) {
5209− printk(KERN_DEBUG "megasas: scsi_host_alloc failed\n");
5207+ dev_printk(KERN_DEBUG, &pdev->dev, "scsi_host_alloc failed\n");
52105208 goto fail_alloc_instance;
52115209 }
52125210
52135211 instance = (struct megasas_instance *)host->hostdata;
52145212 memset(instance, 0, sizeof(*instance));
5215− atomic_set( &instance->fw_reset_no_pci_access, 0 );
5213+ atomic_set(&instance->fw_reset_no_pci_access, 0);
52165214 instance->pdev = pdev;
52175215
52185216 switch (instance->pdev->device) {
@@ -5226,7 +5224,7 @@ static int megasas_probe_one(struct pci_dev *pdev, · 7 unmodified lines
52265224 instance->ctrl_context = (void *)__get_free_pages(GFP_KERNEL,
52275225 instance->ctrl_context_pages);
52285226 if (!instance->ctrl_context) {
5229− printk(KERN_DEBUG "megasas: Failed to allocate "
5227+ dev_printk(KERN_DEBUG, &pdev->dev, "Failed to allocate "
52305228 "memory for Fusion context info\n");
52315229 goto fail_alloc_dma_buf;
52325230 }
@@ -5245,7 +5243,7 @@ static int megasas_probe_one(struct pci_dev *pdev, · 12 unmodified lines
52455243 &instance->consumer_h);
52465244
52475245 if (!instance->producer || !instance->consumer) {
5248− printk(KERN_DEBUG "megasas: Failed to allocate"
5246+ dev_printk(KERN_DEBUG, &pdev->dev, "Failed to allocate"
52495247 "memory for producer, consumer\n");
52505248 goto fail_alloc_dma_buf;
52515249 }
@@ -5276,7 +5274,7 @@ static int megasas_probe_one(struct pci_dev *pdev, · 24 unmodified lines
52765274 CRASH_DMA_BUF_SIZE,
52775275 &instance->crash_dump_h);
52785276 if (!instance->crash_dump_buf)
5279− dev_err(&instance->pdev->dev, "Can't allocate Firmware "
5277+ dev_err(&pdev->dev, "Can't allocate Firmware "
52805278 "crash dump DMA buffer\n");
52815279
52825280 megasas_poll_wait_aen = 0;
@@ -5292,7 +5290,7 @@ static int megasas_probe_one(struct pci_dev *pdev, · 9 unmodified lines
52925290 &instance->evt_detail_h);
52935291
52945292 if (!instance->evt_detail) {
5295− printk(KERN_DEBUG "megasas: Failed to allocate memory for "
5293+ dev_printk(KERN_DEBUG, &pdev->dev, "Failed to allocate memory for "
52965294 "event detail structure\n");
52975295 goto fail_alloc_dma_buf;
52985296 }
@@ -5356,7 +5354,7 @@ static int megasas_probe_one(struct pci_dev *pdev, · 57 unmodified lines
53565354 pci_alloc_consistent(pdev, sizeof(struct MR_LD_VF_AFFILIATION_111),
53575355 &instance->vf_affiliation_111_h);
53585356 if (!instance->vf_affiliation_111)
5359− printk(KERN_WARNING "megasas: Can't allocate "
5357+ dev_warn(&pdev->dev, "Can't allocate "
53605358 "memory for VF affiliation buffer\n");
53615359 } else {
53625360 instance->vf_affiliation =
@@ -5365,7 +5363,7 @@ static int megasas_probe_one(struct pci_dev *pdev, · 2 unmodified lines
53655363 sizeof(struct MR_LD_VF_AFFILIATION),
53665364 &instance->vf_affiliation_h);
53675365 if (!instance->vf_affiliation)
5368− printk(KERN_WARNING "megasas: Can't allocate "
5366+ dev_warn(&pdev->dev, "Can't allocate "
53695367 "memory for VF affiliation buffer\n");
53705368 }
53715369 }
@@ -5399,7 +5397,7 @@ static int megasas_probe_one(struct pci_dev *pdev, · 27 unmodified lines
53995397 * Initiate AEN (Asynchronous Event Notification)
54005398 */
54015399 if (megasas_start_aen(instance)) {
5402− printk(KERN_DEBUG "megasas: start aen failed\n");
5400+ dev_printk(KERN_DEBUG, &pdev->dev, "start aen failed\n");
54035401 goto fail_start_aen;
54045402 }
54055403
@@ -5409,8 +5407,8 @@ static int megasas_probe_one(struct pci_dev *pdev, · 3 unmodified lines
54095407
54105408 return 0;
54115409
5412− fail_start_aen:
5413− fail_io_attach:
5410+fail_start_aen:
5411+fail_io_attach:
54145412 megasas_mgmt_info.count--;
54155413 megasas_mgmt_info.instance[megasas_mgmt_info.max_index] = NULL;
54165414 megasas_mgmt_info.max_index--;
@@ -5428,7 +5426,7 @@ static int megasas_probe_one(struct pci_dev *pdev, · 11 unmodified lines
54285426 if (instance->msix_vectors)
54295427 pci_disable_msix(instance->pdev);
54305428 fail_init_mfi:
5431− fail_alloc_dma_buf:
5429+fail_alloc_dma_buf:
54325430 if (instance->evt_detail)
54335431 pci_free_consistent(pdev, sizeof(struct megasas_evt_detail),
54345432 instance->evt_detail,
@@ -5442,8 +5440,8 @@ fail_init_mfi: · 7 unmodified lines
54425440 instance->consumer_h);
54435441 scsi_host_put(host);
54445442
5445− fail_alloc_instance:
5446− fail_set_dma_mask:
5443+fail_alloc_instance:
5444+fail_set_dma_mask:
54475445 pci_disable_device(pdev);
54485446
54495447 return -ENODEV;
@@ -5485,8 +5483,6 @@ static void megasas_flush_cache(struct megasas_instance *instance) · 35 unmodified lines
54855483 " from %s\n", __func__);
54865484
54875485 megasas_return_cmd(instance, cmd);
5488−
5489− return;
54905486 }
54915487
54925488 /**
@@ -5532,8 +5528,6 @@ static void megasas_shutdown_controller(struct megasas_instance *instance, · 39 unmodified lines
55325528 "from %s\n", __func__);
55335529
55345530 megasas_return_cmd(instance, cmd);
5535−
5536− return;
55375531 }
55385532
55395533 #ifdef CONFIG_PM
@@ -5607,7 +5601,7 @@ megasas_resume(struct pci_dev *pdev) · 67 unmodified lines
56075601 rval = pci_enable_device_mem(pdev);
56085602
56095603 if (rval) {
5610− printk(KERN_ERR "megasas: Enable device failed\n");
5604+ dev_err(&pdev->dev, "Enable device failed\n");
56115605 return rval;
56125606 }
56135607
@@ -5686,7 +5680,7 @@ megasas_resume(struct pci_dev *pdev) · 72 unmodified lines
56865680 * Initiate AEN (Asynchronous Event Notification)
56875681 */
56885682 if (megasas_start_aen(instance))
5689− printk(KERN_ERR "megasas: Start AEN failed\n");
5683+ dev_err(&instance->pdev->dev, "Start AEN failed\n");
56905684
56915685 return 0;
56925686
@@ -5839,8 +5833,6 @@ static void megasas_detach_one(struct pci_dev *pdev) · 146 unmodified lines
58395833 scsi_host_put(host);
58405834
58415835 pci_disable_device(pdev);
5842−
5843− return;
58445836 }
58455837
58465838 /**
@@ -5909,11 +5901,11 @@ static unsigned int megasas_mgmt_poll(struct file *file, poll_table *wait) · 62 unmodified lines
59095901 {
59105902 unsigned int mask;
59115903 unsigned long flags;
5904+
59125905 poll_wait(file, &megasas_poll_wait, wait);
59135906 spin_lock_irqsave(&poll_aen_lock, flags);
59145907 if (megasas_poll_wait_aen)
5915− mask = (POLLIN | POLLRDNORM);
5916−
5908+ mask = (POLLIN | POLLRDNORM);
59175909 else
59185910 mask = 0;
59195911 megasas_poll_wait_aen = 0;
@@ -5927,8 +5919,7 @@ static unsigned int megasas_mgmt_poll(struct file *file, poll_table *wait) · 7 unmodified lines
59275919 * @cmd: MFI command frame
59285920 */
59295921
5930−static int megasas_set_crash_dump_params_ioctl(
5931− struct megasas_cmd *cmd)
5922+static int megasas_set_crash_dump_params_ioctl(struct megasas_cmd *cmd)
59325923 {
59335924 struct megasas_instance *local_instance;
59345925 int i, error = 0;
@@ -5982,14 +5973,14 @@ megasas_mgmt_fw_ioctl(struct megasas_instance *instance, · 47 unmodified lines
59825973 memset(kbuff_arr, 0, sizeof(kbuff_arr));
59835974
59845975 if (ioc->sge_count > MAX_IOCTL_SGE) {
5985− printk(KERN_DEBUG "megasas: SGE count [%d] > max limit [%d]\n",
5976+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "SGE count [%d] > max limit [%d]\n",
59865977 ioc->sge_count, MAX_IOCTL_SGE);
59875978 return -EINVAL;
59885979 }
59895980
59905981 cmd = megasas_get_cmd(instance);
59915982 if (!cmd) {
5992− printk(KERN_DEBUG "megasas: Failed to get a cmd packet\n");
5983+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to get a cmd packet\n");
59935984 return -ENOMEM;
59945985 }
59955986
@@ -6034,8 +6025,8 @@ megasas_mgmt_fw_ioctl(struct megasas_instance *instance, · 38 unmodified lines
60346025 ioc->sgl[i].iov_len,
60356026 &buf_handle, GFP_KERNEL);
60366027 if (!kbuff_arr[i]) {
6037− printk(KERN_DEBUG "megasas: Failed to alloc "
6038− "kernel SGL buffer for IOCTL \n");
6028+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to alloc "
6029+ "kernel SGL buffer for IOCTL\n");
60396030 error = -ENOMEM;
60406031 goto out;
60416032 }
@@ -6108,7 +6099,7 @@ megasas_mgmt_fw_ioctl(struct megasas_instance *instance, · 66 unmodified lines
61086099
61096100 if (copy_to_user((void __user *)((unsigned long)(*sense_ptr)),
61106101 sense, ioc->sense_len)) {
6111− printk(KERN_ERR "megasas: Failed to copy out to user "
6102+ dev_err(&instance->pdev->dev, "Failed to copy out to user "
61126103 "sense data\n");
61136104 error = -EFAULT;
61146105 goto out;
@@ -6120,11 +6111,11 @@ megasas_mgmt_fw_ioctl(struct megasas_instance *instance, · 5 unmodified lines
61206111 */
61216112 if (copy_to_user(&user_ioc->frame.hdr.cmd_status,
61226113 &cmd->frame->hdr.cmd_status, sizeof(u8))) {
6123− printk(KERN_DEBUG "megasas: Error copying out cmd_status\n");
6114+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "Error copying out cmd_status\n");
61246115 error = -EFAULT;
61256116 }
61266117
6127− out:
6118+out:
61286119 if (sense) {
61296120 dma_free_coherent(&instance->pdev->dev, ioc->sense_len,
61306121 sense, sense_handle);
@@ -6180,7 +6171,7 @@ static int megasas_mgmt_ioctl_fw(struct file *file, unsigned long arg) · 49 unmodified lines
61806171 }
61816172
61826173 if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) {
6183− printk(KERN_ERR "Controller in crit error\n");
6174+ dev_err(&instance->pdev->dev, "Controller in crit error\n");
61846175 error = -ENODEV;
61856176 goto out_kfree_ioc;
61866177 }
@@ -6205,7 +6196,7 @@ static int megasas_mgmt_ioctl_fw(struct file *file, unsigned long arg) · 18 unmodified lines
62056196 spin_unlock_irqrestore(&instance->hba_lock, flags);
62066197
62076198 if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) {
6208− printk(KERN_NOTICE "megasas: waiting"
6199+ dev_notice(&instance->pdev->dev, "waiting"
62096200 "for controller reset to finish\n");
62106201 }
62116202
@@ -6216,7 +6207,7 @@ static int megasas_mgmt_ioctl_fw(struct file *file, unsigned long arg) · 4 unmodified lines
62166207 if (instance->adprecovery != MEGASAS_HBA_OPERATIONAL) {
62176208 spin_unlock_irqrestore(&instance->hba_lock, flags);
62186209
6219− printk(KERN_ERR "megaraid_sas: timed out while"
6210+ dev_err(&instance->pdev->dev, "timed out while"
62206211 "waiting for HBA to recover\n");
62216212 error = -ENODEV;
62226213 goto out_up;
@@ -6224,10 +6215,10 @@ static int megasas_mgmt_ioctl_fw(struct file *file, unsigned long arg) · 1 unmodified line
62246215 spin_unlock_irqrestore(&instance->hba_lock, flags);
62256216
62266217 error = megasas_mgmt_fw_ioctl(instance, user_ioc, ioc);
6227− out_up:
6218+out_up:
62286219 up(&instance->ioctl_sem);
62296220
6230− out_kfree_ioc:
6221+out_kfree_ioc:
62316222 kfree(ioc);
62326223 return error;
62336224 }
@@ -6275,7 +6266,7 @@ static int megasas_mgmt_ioctl_aen(struct file *file, unsigned long arg) · 41 unmodified lines
62756266 spin_unlock_irqrestore(&instance->hba_lock, flags);
62766267
62776268 if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) {
6278− printk(KERN_NOTICE "megasas: waiting for"
6269+ dev_notice(&instance->pdev->dev, "waiting for"
62796270 "controller reset to finish\n");
62806271 }
62816272
@@ -6285,8 +6276,8 @@ static int megasas_mgmt_ioctl_aen(struct file *file, unsigned long arg) · 3 unmodified lines
62856276 spin_lock_irqsave(&instance->hba_lock, flags);
62866277 if (instance->adprecovery != MEGASAS_HBA_OPERATIONAL) {
62876278 spin_unlock_irqrestore(&instance->hba_lock, flags);
6288− printk(KERN_ERR "megaraid_sas: timed out while waiting"
6289− "for HBA to recover.\n");
6279+ dev_err(&instance->pdev->dev, "timed out while waiting"
6280+ "for HBA to recover\n");
62906281 return -ENODEV;
62916282 }
62926283 spin_unlock_irqrestore(&instance->hba_lock, flags);
@@ -6462,7 +6453,8 @@ static ssize_t · 169 unmodified lines
64626453 megasas_sysfs_set_dbg_lvl(struct device_driver *dd, const char *buf, size_t count)
64636454 {
64646455 int retval = count;
6465− if(sscanf(buf,"%u",&megasas_dbg_lvl)<1){
6456+
6457+ if (sscanf(buf, "%u", &megasas_dbg_lvl) < 1) {
64666458 printk(KERN_ERR "megasas: could not set dbg_lvl\n");
64676459 retval = -EINVAL;
64686460 }
@@ -6502,7 +6494,7 @@ megasas_aen_polling(struct work_struct *work) · 33 unmodified lines
65026494 if (instance->adprecovery == MEGASAS_HBA_OPERATIONAL)
65036495 break;
65046496 if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) {
6505− printk(KERN_NOTICE "megasas: %s waiting for "
6497+ dev_notice(&instance->pdev->dev, "%s waiting for "
65066498 "controller reset to finish for scsi%d\n",
65076499 __func__, instance->host->host_no);
65086500 }
@@ -6524,14 +6516,12 @@ megasas_aen_polling(struct work_struct *work) · 15 unmodified lines
65246516 pd_index =
65256517 (i * MEGASAS_MAX_DEV_PER_CHANNEL) + j;
65266518
6527− sdev1 =
6528− scsi_device_lookup(host, i, j, 0);
6519+ sdev1 = scsi_device_lookup(host, i, j, 0);
65296520
65306521 if (instance->pd_list[pd_index].driveState
65316522 == MR_PD_STATE_SYSTEM) {
6532− if (!sdev1) {
6523+ if (!sdev1)
65336524 scsi_add_device(host, i, j, 0);
6534− }
65356525
65366526 if (sdev1)
65376527 scsi_device_put(sdev1);
@@ -6552,14 +6542,12 @@ megasas_aen_polling(struct work_struct *work) · 14 unmodified lines
65526542 pd_index =
65536543 (i * MEGASAS_MAX_DEV_PER_CHANNEL) + j;
65546544
6555− sdev1 =
6556− scsi_device_lookup(host, i, j, 0);
6545+ sdev1 = scsi_device_lookup(host, i, j, 0);
65576546
65586547 if (instance->pd_list[pd_index].driveState
65596548 == MR_PD_STATE_SYSTEM) {
6560− if (sdev1) {
6549+ if (sdev1)
65616550 scsi_device_put(sdev1);
6562− }
65636551 } else {
65646552 if (sdev1) {
65656553 scsi_remove_device(sdev1);
@@ -6644,13 +6632,13 @@ megasas_aen_polling(struct work_struct *work) · 78 unmodified lines
66446632 break;
66456633 }
66466634 } else {
6647− printk(KERN_ERR "invalid evt_detail!\n");
6635+ dev_err(&instance->pdev->dev, "invalid evt_detail!\n");
66486636 kfree(ev);
66496637 return;
66506638 }
66516639
66526640 if (doscan) {
6653− printk(KERN_INFO "megaraid_sas: scanning for scsi%d...\n",
6641+ dev_info(&instance->pdev->dev, "scanning for scsi%d...\n",
66546642 instance->host->host_no);
66556643 if (megasas_get_pd_list(instance) == 0) {
66566644 for (i = 0; i < MEGASAS_MAX_PD_CHANNELS; i++) {
@@ -6705,7 +6693,7 @@ megasas_aen_polling(struct work_struct *work) · 48 unmodified lines
67056693 }
67066694 }
67076695
6708− if ( instance->aen_cmd != NULL ) {
6696+ if (instance->aen_cmd != NULL) {
67096697 kfree(ev);
67106698 return ;
67116699 }
@@ -6722,7 +6710,7 @@ megasas_aen_polling(struct work_struct *work) · 10 unmodified lines
67226710 mutex_unlock(&instance->aen_mutex);
67236711
67246712 if (error)
6725− printk(KERN_ERR "register aen failed error %x\n", error);
6713+ dev_err(&instance->pdev->dev, "register aen failed error %x\n", error);
67266714
67276715 kfree(ev);
67286716 }
drivers/scsi/megaraid/megaraid_sas_fusion.c+46−49
@@ -221,7 +221,7 @@ static void megasas_teardown_frame_pool_fusion( · 220 unmodified lines
221221 struct megasas_cmd_fusion *cmd;
222222
223223 if (!fusion->sg_dma_pool || !fusion->sense_dma_pool) {
224− printk(KERN_ERR "megasas: dma pool is null. SG Pool %p, "
224+ dev_err(&instance->pdev->dev, "dma pool is null. SG Pool %p, "
225225 "sense pool : %p\n", fusion->sg_dma_pool,
226226 fusion->sense_dma_pool);
227227 return;
@@ -332,8 +332,7 @@ static int megasas_create_frame_pool_fusion(struct megasas_instance *instance) · 104 unmodified lines
332332 total_sz_chain_frame, 4,
333333 0);
334334 if (!fusion->sg_dma_pool) {
335− printk(KERN_DEBUG "megasas: failed to setup request pool "
336− "fusion\n");
335+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "failed to setup request pool fusion\n");
337336 return -ENOMEM;
338337 }
339338 fusion->sense_dma_pool = pci_pool_create("megasas sense pool fusion",
@@ -341,8 +340,7 @@ static int megasas_create_frame_pool_fusion(struct megasas_instance *instance) · 1 unmodified line
341340 SCSI_SENSE_BUFFERSIZE, 64, 0);
342341
343342 if (!fusion->sense_dma_pool) {
344− printk(KERN_DEBUG "megasas: failed to setup sense pool "
345− "fusion\n");
343+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "failed to setup sense pool fusion\n");
346344 pci_pool_destroy(fusion->sg_dma_pool);
347345 fusion->sg_dma_pool = NULL;
348346 return -ENOMEM;
@@ -366,7 +364,7 @@ static int megasas_create_frame_pool_fusion(struct megasas_instance *instance) · 17 unmodified lines
366364 * whatever has been allocated
367365 */
368366 if (!cmd->sg_frame || !cmd->sense) {
369− printk(KERN_DEBUG "megasas: pci_pool_alloc failed\n");
367+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "pci_pool_alloc failed\n");
370368 megasas_teardown_frame_pool_fusion(instance);
371369 return -ENOMEM;
372370 }
@@ -412,7 +410,7 @@ megasas_alloc_cmds_fusion(struct megasas_instance *instance) · 39 unmodified lines
412410 &fusion->req_frames_desc_phys, GFP_KERNEL);
413411
414412 if (!fusion->req_frames_desc) {
415− printk(KERN_ERR "megasas; Could not allocate memory for "
413+ dev_err(&instance->pdev->dev, "Could not allocate memory for "
416414 "request_frames\n");
417415 goto fail_req_desc;
418416 }
@@ -423,7 +421,7 @@ megasas_alloc_cmds_fusion(struct megasas_instance *instance) · 4 unmodified lines
423421 fusion->reply_alloc_sz * count, 16, 0);
424422
425423 if (!fusion->reply_frames_desc_pool) {
426− printk(KERN_ERR "megasas; Could not allocate memory for "
424+ dev_err(&instance->pdev->dev, "Could not allocate memory for "
427425 "reply_frame pool\n");
428426 goto fail_reply_desc;
429427 }
@@ -432,7 +430,7 @@ megasas_alloc_cmds_fusion(struct megasas_instance *instance) · 2 unmodified lines
432430 pci_pool_alloc(fusion->reply_frames_desc_pool, GFP_KERNEL,
433431 &fusion->reply_frames_desc_phys);
434432 if (!fusion->reply_frames_desc) {
435− printk(KERN_ERR "megasas; Could not allocate memory for "
433+ dev_err(&instance->pdev->dev, "Could not allocate memory for "
436434 "reply_frame pool\n");
437435 pci_pool_destroy(fusion->reply_frames_desc_pool);
438436 goto fail_reply_desc;
@@ -449,7 +447,7 @@ megasas_alloc_cmds_fusion(struct megasas_instance *instance) · 10 unmodified lines
449447 fusion->io_frames_alloc_sz, 16, 0);
450448
451449 if (!fusion->io_request_frames_pool) {
452− printk(KERN_ERR "megasas: Could not allocate memory for "
450+ dev_err(&instance->pdev->dev, "Could not allocate memory for "
453451 "io_request_frame pool\n");
454452 goto fail_io_frames;
455453 }
@@ -458,7 +456,7 @@ megasas_alloc_cmds_fusion(struct megasas_instance *instance) · 2 unmodified lines
458456 pci_pool_alloc(fusion->io_request_frames_pool, GFP_KERNEL,
459457 &fusion->io_request_frames_phys);
460458 if (!fusion->io_request_frames) {
461− printk(KERN_ERR "megasas: Could not allocate memory for "
459+ dev_err(&instance->pdev->dev, "Could not allocate memory for "
462460 "io_request_frames frames\n");
463461 pci_pool_destroy(fusion->io_request_frames_pool);
464462 goto fail_io_frames;
@@ -473,7 +471,7 @@ megasas_alloc_cmds_fusion(struct megasas_instance *instance) · 8 unmodified lines
473471 * max_cmd, GFP_KERNEL);
474472
475473 if (!fusion->cmd_list) {
476− printk(KERN_DEBUG "megasas: out of memory. Could not alloc "
474+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "out of memory. Could not alloc "
477475 "memory for cmd_list_fusion\n");
478476 goto fail_cmd_list;
479477 }
@@ -483,7 +481,7 @@ megasas_alloc_cmds_fusion(struct megasas_instance *instance) · 3 unmodified lines
483481 fusion->cmd_list[i] = kmalloc(sizeof(struct megasas_cmd_fusion),
484482 GFP_KERNEL);
485483 if (!fusion->cmd_list[i]) {
486− printk(KERN_ERR "Could not alloc cmd list fusion\n");
484+ dev_err(&instance->pdev->dev, "Could not alloc cmd list fusion\n");
487485
488486 for (j = 0; j < i; j++)
489487 kfree(fusion->cmd_list[j]);
@@ -527,7 +525,7 @@ megasas_alloc_cmds_fusion(struct megasas_instance *instance) · 37 unmodified lines
527525 * Create a frame pool and assign one frame to each cmd
528526 */
529527 if (megasas_create_frame_pool_fusion(instance)) {
530− printk(KERN_DEBUG "megasas: Error creating frame DMA pool\n");
528+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "Error creating frame DMA pool\n");
531529 megasas_free_cmds_fusion(instance);
532530 goto fail_req_desc;
533531 }
@@ -613,7 +611,7 @@ megasas_ioc_init_fusion(struct megasas_instance *instance) · 79 unmodified lines
613611 cmd = megasas_get_cmd(instance);
614612
615613 if (!cmd) {
616− printk(KERN_ERR "Could not allocate cmd for INIT Frame\n");
614+ dev_err(&instance->pdev->dev, "Could not allocate cmd for INIT Frame\n");
617615 ret = 1;
618616 goto fail_get_cmd;
619617 }
@@ -624,7 +622,7 @@ megasas_ioc_init_fusion(struct megasas_instance *instance) · 4 unmodified lines
624622 &ioc_init_handle, GFP_KERNEL);
625623
626624 if (!IOCInitMessage) {
627− printk(KERN_ERR "Could not allocate memory for "
625+ dev_err(&instance->pdev->dev, "Could not allocate memory for "
628626 "IOCInitMessage\n");
629627 ret = 1;
630628 goto fail_fw_init;
@@ -714,7 +712,7 @@ megasas_ioc_init_fusion(struct megasas_instance *instance) · 83 unmodified lines
714712 ret = 1;
715713 goto fail_fw_init;
716714 }
717− printk(KERN_ERR "megasas:IOC Init cmd success\n");
715+ dev_err(&instance->pdev->dev, "Init cmd success\n");
718716
719717 ret = 0;
720718
@@ -757,7 +755,7 @@ megasas_get_ld_map_info(struct megasas_instance *instance) · 36 unmodified lines
757755 cmd = megasas_get_cmd(instance);
758756
759757 if (!cmd) {
760− printk(KERN_DEBUG "megasas: Failed to get cmd for map info.\n");
758+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to get cmd for map info\n");
761759 return -ENOMEM;
762760 }
763761
@@ -776,7 +774,7 @@ megasas_get_ld_map_info(struct megasas_instance *instance) · 12 unmodified lines
776774 ci_h = fusion->ld_map_phys[(instance->map_id & 1)];
777775
778776 if (!ci) {
779− printk(KERN_DEBUG "Failed to alloc mem for ld_map_info\n");
777+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to alloc mem for ld_map_info\n");
780778 megasas_return_cmd(instance, cmd);
781779 return -ENOMEM;
782780 }
@@ -851,8 +849,7 @@ megasas_sync_map_info(struct megasas_instance *instance) · 68 unmodified lines
851849 cmd = megasas_get_cmd(instance);
852850
853851 if (!cmd) {
854− printk(KERN_DEBUG "megasas: Failed to get cmd for sync"
855− "info.\n");
852+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to get cmd for sync info\n");
856853 return -ENOMEM;
857854 }
858855
@@ -1097,7 +1094,7 @@ megasas_init_adapter_fusion(struct megasas_instance *instance) · 238 unmodified lines
10971094 &fusion->ld_map_phys[i],
10981095 GFP_KERNEL);
10991096 if (!fusion->ld_map[i]) {
1100− printk(KERN_ERR "megasas: Could not allocate memory "
1097+ dev_err(&instance->pdev->dev, "Could not allocate memory "
11011098 "for map info\n");
11021099 goto fail_map_info;
11031100 }
@@ -1162,7 +1159,7 @@ map_cmd_status(struct megasas_cmd_fusion *cmd, u8 status, u8 ext_status) · 58 unmodified lines
11621159 cmd->scmd->result = DID_IMM_RETRY << 16;
11631160 break;
11641161 default:
1165− printk(KERN_DEBUG "megasas: FW status %#x\n", status);
1162+ dev_printk(KERN_DEBUG, &cmd->instance->pdev->dev, "FW status %#x\n", status);
11661163 cmd->scmd->result = DID_ERROR << 16;
11671164 break;
11681165 }
@@ -1851,7 +1848,7 @@ megasas_build_io_fusion(struct megasas_instance *instance, · 682 unmodified lines
18511848 &io_request->SGL, cmd);
18521849
18531850 if (sge_count > instance->max_num_sge) {
1854− printk(KERN_ERR "megasas: Error. sge_count (0x%x) exceeds "
1851+ dev_err(&instance->pdev->dev, "Error. sge_count (0x%x) exceeds "
18551852 "max (0x%x) allowed\n", sge_count,
18561853 instance->max_num_sge);
18571854 return 1;
@@ -1885,7 +1882,7 @@ megasas_get_request_descriptor(struct megasas_instance *instance, u16 index) · 27 unmodified lines
18851882 struct fusion_context *fusion;
18861883
18871884 if (index >= instance->max_fw_cmds) {
1888− printk(KERN_ERR "megasas: Invalid SMID (0x%x)request for "
1885+ dev_err(&instance->pdev->dev, "Invalid SMID (0x%x)request for "
18891886 "descriptor for scsi%d\n", index,
18901887 instance->host->host_no);
18911888 return NULL;
@@ -1927,7 +1924,7 @@ megasas_build_and_issue_cmd_fusion(struct megasas_instance *instance, · 35 unmodified lines
19271924
19281925 if (megasas_build_io_fusion(instance, scmd, cmd)) {
19291926 megasas_return_cmd_fusion(instance, cmd);
1930− printk(KERN_ERR "megasas: Error building command.\n");
1927+ dev_err(&instance->pdev->dev, "Error building command\n");
19311928 cmd->request_desc = NULL;
19321929 return 1;
19331930 }
@@ -1937,7 +1934,7 @@ megasas_build_and_issue_cmd_fusion(struct megasas_instance *instance, · 3 unmodified lines
19371934
19381935 if (cmd->io_request->ChainOffset != 0 &&
19391936 cmd->io_request->ChainOffset != 0xF)
1940− printk(KERN_ERR "megasas: The chain offset value is not "
1937+ dev_err(&instance->pdev->dev, "The chain offset value is not "
19411938 "correct : %x\n", cmd->io_request->ChainOffset);
19421939
19431940 /*
@@ -2025,7 +2022,7 @@ complete_cmd_fusion(struct megasas_instance *instance, u32 MSIxIndex) · 81 unmodified lines
20252022 if (reply_descript_type ==
20262023 MPI2_RPY_DESCRIPT_FLAGS_SCSI_IO_SUCCESS) {
20272024 if (megasas_dbg_lvl == 5)
2028− printk(KERN_ERR "\nmegasas: FAST Path "
2025+ dev_err(&instance->pdev->dev, "\nFAST Path "
20292026 "IO Success\n");
20302027 }
20312028 /* Fall thru and complete IO */
@@ -2186,7 +2183,7 @@ irqreturn_t megasas_isr_fusion(int irq, void *devp) · 154 unmodified lines
21862183 else if (fw_state == MFI_STATE_FAULT)
21872184 schedule_work(&instance->work_init);
21882185 } else if (fw_state == MFI_STATE_FAULT) {
2189− printk(KERN_WARNING "megaraid_sas: Iop2SysDoorbellInt"
2186+ dev_warn(&instance->pdev->dev, "Iop2SysDoorbellInt"
21902187 "for scsi%d\n", instance->host->host_no);
21912188 schedule_work(&instance->work_init);
21922189 }
@@ -2269,7 +2266,7 @@ build_mpt_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd) · 76 unmodified lines
22692266 u16 index;
22702267
22712268 if (build_mpt_mfi_pass_thru(instance, cmd)) {
2272− printk(KERN_ERR "Couldn't build MFI pass thru cmd\n");
2269+ dev_err(&instance->pdev->dev, "Couldn't build MFI pass thru cmd\n");
22732270 return NULL;
22742271 }
22752272
@@ -2303,7 +2300,7 @@ megasas_issue_dcmd_fusion(struct megasas_instance *instance, · 27 unmodified lines
23032300
23042301 req_desc = build_mpt_cmd(instance, cmd);
23052302 if (!req_desc) {
2306− printk(KERN_ERR "Couldn't issue MFI pass thru cmd\n");
2303+ dev_err(&instance->pdev->dev, "Couldn't issue MFI pass thru cmd\n");
23072304 return;
23082305 }
23092306 megasas_fire_cmd_fusion(instance, req_desc);
@@ -2413,7 +2410,7 @@ int megasas_wait_for_outstanding_fusion(struct megasas_instance *instance, · 103 unmodified lines
24132410 fw_state = instance->instancet->read_fw_status_reg(
24142411 instance->reg_set) & MFI_STATE_MASK;
24152412 if (fw_state == MFI_STATE_FAULT) {
2416− printk(KERN_WARNING "megasas: Found FW in FAULT state,"
2413+ dev_warn(&instance->pdev->dev, "Found FW in FAULT state,"
24172414 " will reset adapter scsi%d.\n",
24182415 instance->host->host_no);
24192416 retval = 1;
@@ -2436,7 +2433,7 @@ int megasas_wait_for_outstanding_fusion(struct megasas_instance *instance, · 16 unmodified lines
24362433 hb_seconds_missed++;
24372434 if (hb_seconds_missed ==
24382435 (MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF/HZ)) {
2439− printk(KERN_WARNING "megasas: SR-IOV:"
2436+ dev_warn(&instance->pdev->dev, "SR-IOV:"
24402437 " Heartbeat never completed "
24412438 " while polling during I/O "
24422439 " timeout handling for "
@@ -2454,7 +2451,7 @@ int megasas_wait_for_outstanding_fusion(struct megasas_instance *instance, · 11 unmodified lines
24542451 goto out;
24552452
24562453 if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) {
2457− printk(KERN_NOTICE "megasas: [%2d]waiting for %d "
2454+ dev_notice(&instance->pdev->dev, "[%2d]waiting for %d "
24582455 "commands to complete for scsi%d\n", i,
24592456 outstanding, instance->host->host_no);
24602457 megasas_complete_cmd_dpc_fusion(
@@ -2464,7 +2461,7 @@ int megasas_wait_for_outstanding_fusion(struct megasas_instance *instance, · 3 unmodified lines
24642461 }
24652462
24662463 if (atomic_read(&instance->fw_outstanding)) {
2467− printk("megaraid_sas: pending commands remain after waiting, "
2464+ dev_err(&instance->pdev->dev, "pending commands remain after waiting, "
24682465 "will reset adapter scsi%d.\n",
24692466 instance->host->host_no);
24702467 retval = 1;
@@ -2564,7 +2561,7 @@ int megasas_reset_fusion(struct Scsi_Host *shost, int iotimeout) · 93 unmodified lines
25642561 mutex_lock(&instance->reset_mutex);
25652562
25662563 if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) {
2567− printk(KERN_WARNING "megaraid_sas: Hardware critical error, "
2564+ dev_warn(&instance->pdev->dev, "Hardware critical error, "
25682565 "returning FAILED for scsi%d.\n",
25692566 instance->host->host_no);
25702567 mutex_unlock(&instance->reset_mutex);
@@ -2618,7 +2615,7 @@ int megasas_reset_fusion(struct Scsi_Host *shost, int iotimeout) · 47 unmodified lines
26182615 if (megasas_wait_for_outstanding_fusion(instance, iotimeout,
26192616 &convert)) {
26202617 instance->adprecovery = MEGASAS_ADPRESET_SM_INFAULT;
2621− printk(KERN_WARNING "megaraid_sas: resetting fusion "
2618+ dev_warn(&instance->pdev->dev, "resetting fusion "
26222619 "adapter scsi%d.\n", instance->host->host_no);
26232620 if (convert)
26242621 iotimeout = 0;
@@ -2645,7 +2642,7 @@ int megasas_reset_fusion(struct Scsi_Host *shost, int iotimeout) · 20 unmodified lines
26452642 if (instance->disableOnlineCtrlReset ||
26462643 (abs_state == MFI_STATE_FAULT && !reset_adapter)) {
26472644 /* Reset not supported, kill adapter */
2648− printk(KERN_WARNING "megaraid_sas: Reset not supported"
2645+ dev_warn(&instance->pdev->dev, "Reset not supported"
26492646 ", killing adapter scsi%d.\n",
26502647 instance->host->host_no);
26512648 megaraid_sas_kill_hba(instance);
@@ -2663,7 +2660,7 @@ int megasas_reset_fusion(struct Scsi_Host *shost, int iotimeout) · 11 unmodified lines
26632660 instance->hb_host_mem->HB.driverCounter)) {
26642661 instance->hb_host_mem->HB.driverCounter =
26652662 instance->hb_host_mem->HB.fwCounter;
2666− printk(KERN_WARNING "megasas: SR-IOV:"
2663+ dev_warn(&instance->pdev->dev, "SR-IOV:"
26672664 "Late FW heartbeat update for "
26682665 "scsi%d.\n",
26692666 instance->host->host_no);
@@ -2679,8 +2676,8 @@ int megasas_reset_fusion(struct Scsi_Host *shost, int iotimeout) · 9 unmodified lines
26792676 abs_state = status_reg &
26802677 MFI_STATE_MASK;
26812678 if (abs_state == MFI_STATE_READY) {
2682− printk(KERN_WARNING "megasas"
2683− ": SR-IOV: FW was found"
2679+ dev_warn(&instance->pdev->dev,
2680+ "SR-IOV: FW was found"
26842681 "to be in ready state "
26852682 "for scsi%d.\n",
26862683 instance->host->host_no);
@@ -2689,7 +2686,7 @@ int megasas_reset_fusion(struct Scsi_Host *shost, int iotimeout) · 2 unmodified lines
26892686 msleep(20);
26902687 }
26912688 if (abs_state != MFI_STATE_READY) {
2692− printk(KERN_WARNING "megasas: SR-IOV: "
2689+ dev_warn(&instance->pdev->dev, "SR-IOV: "
26932690 "FW not in ready state after %d"
26942691 " seconds for scsi%d, status_reg = "
26952692 "0x%x.\n",
@@ -2731,7 +2728,7 @@ int megasas_reset_fusion(struct Scsi_Host *shost, int iotimeout) · 35 unmodified lines
27312728 host_diag =
27322729 readl(&instance->reg_set->fusion_host_diag);
27332730 if (retry++ == 100) {
2734− printk(KERN_WARNING "megaraid_sas: "
2731+ dev_warn(&instance->pdev->dev,
27352732 "Host diag unlock failed! "
27362733 "for scsi%d\n",
27372734 instance->host->host_no);
@@ -2754,7 +2751,7 @@ int megasas_reset_fusion(struct Scsi_Host *shost, int iotimeout) · 16 unmodified lines
27542751 host_diag =
27552752 readl(&instance->reg_set->fusion_host_diag);
27562753 if (retry++ == 1000) {
2757− printk(KERN_WARNING "megaraid_sas: "
2754+ dev_warn(&instance->pdev->dev,
27582755 "Diag reset adapter never "
27592756 "cleared for scsi%d!\n",
27602757 instance->host->host_no);
@@ -2777,7 +2774,7 @@ int megasas_reset_fusion(struct Scsi_Host *shost, int iotimeout) · 16 unmodified lines
27772774 instance->reg_set) & MFI_STATE_MASK;
27782775 }
27792776 if (abs_state <= MFI_STATE_FW_INIT) {
2780− printk(KERN_WARNING "megaraid_sas: firmware "
2777+ dev_warn(&instance->pdev->dev, "firmware "
27812778 "state < MFI_STATE_FW_INIT, state = "
27822779 "0x%x for scsi%d\n", abs_state,
27832780 instance->host->host_no);
@@ -2786,7 +2783,7 @@ int megasas_reset_fusion(struct Scsi_Host *shost, int iotimeout) · 2 unmodified lines
27862783
27872784 /* Wait for FW to become ready */
27882785 if (megasas_transition_to_ready(instance, 1)) {
2789− printk(KERN_WARNING "megaraid_sas: Failed to "
2786+ dev_warn(&instance->pdev->dev, "Failed to "
27902787 "transition controller to ready "
27912788 "for scsi%d.\n",
27922789 instance->host->host_no);
@@ -2795,7 +2792,7 @@ int megasas_reset_fusion(struct Scsi_Host *shost, int iotimeout) · 2 unmodified lines
27952792
27962793 megasas_reset_reply_desc(instance);
27972794 if (megasas_ioc_init_fusion(instance)) {
2798− printk(KERN_WARNING "megaraid_sas: "
2795+ dev_warn(&instance->pdev->dev,
27992796 "megasas_ioc_init_fusion() failed!"
28002797 " for scsi%d\n",
28012798 instance->host->host_no);
@@ -2836,7 +2833,7 @@ int megasas_reset_fusion(struct Scsi_Host *shost, int iotimeout) · 34 unmodified lines
28362833 }
28372834
28382835 /* Adapter reset completed successfully */
2839− printk(KERN_WARNING "megaraid_sas: Reset "
2836+ dev_warn(&instance->pdev->dev, "Reset "
28402837 "successful for scsi%d.\n",
28412838 instance->host->host_no);
28422839
@@ -2852,7 +2849,7 @@ int megasas_reset_fusion(struct Scsi_Host *shost, int iotimeout) · 9 unmodified lines
28522849 goto out;
28532850 }
28542851 /* Reset failed, kill the adapter */
2855− printk(KERN_WARNING "megaraid_sas: Reset failed, killing "
2852+ dev_warn(&instance->pdev->dev, "Reset failed, killing "
28562853 "adapter scsi%d.\n", instance->host->host_no);
28572854 megaraid_sas_kill_hba(instance);
28582855 instance->skip_heartbeat_timer_del = 1;
drivers/scsi/mpt2sas/mpt2sas_base.c+9−7
@@ -1557,7 +1557,8 @@ mpt2sas_base_map_resources(struct MPT2SAS_ADAPTER *ioc) · 1556 unmodified lines
15571557 goto out_fail;
15581558 }
15591559
1560− for (i = 0, memap_sz = 0, pio_sz = 0 ; i < DEVICE_COUNT_RESOURCE; i++) {
1560+ for (i = 0, memap_sz = 0, pio_sz = 0; (i < DEVICE_COUNT_RESOURCE) &&
1561+ (!memap_sz || !pio_sz); i++) {
15611562 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
15621563 if (pio_sz)
15631564 continue;
@@ -1572,16 +1573,17 @@ mpt2sas_base_map_resources(struct MPT2SAS_ADAPTER *ioc) · 8 unmodified lines
15721573 chip_phys = (u64)ioc->chip_phys;
15731574 memap_sz = pci_resource_len(pdev, i);
15741575 ioc->chip = ioremap(ioc->chip_phys, memap_sz);
1575− if (ioc->chip == NULL) {
1576− printk(MPT2SAS_ERR_FMT "unable to map "
1577− "adapter memory!\n", ioc->name);
1578− r = -EINVAL;
1579− goto out_fail;
1580− }
15811576 }
15821577 }
15831578 }
15841579
1580+ if (ioc->chip == NULL) {
1581+ printk(MPT2SAS_ERR_FMT "unable to map adapter memory! "
1582+ "or resource not found\n", ioc->name);
1583+ r = -EINVAL;
1584+ goto out_fail;
1585+ }
1586+
15851587 _base_mask_interrupts(ioc);
15861588
15871589 r = _base_get_ioc_facts(ioc, CAN_SLEEP);
drivers/scsi/mpt3sas/mpt3sas_base.c+9−7
@@ -1843,7 +1843,8 @@ mpt3sas_base_map_resources(struct MPT3SAS_ADAPTER *ioc) · 1842 unmodified lines
18431843 goto out_fail;
18441844 }
18451845
1846− for (i = 0, memap_sz = 0, pio_sz = 0 ; i < DEVICE_COUNT_RESOURCE; i++) {
1846+ for (i = 0, memap_sz = 0, pio_sz = 0; (i < DEVICE_COUNT_RESOURCE) &&
1847+ (!memap_sz || !pio_sz); i++) {
18471848 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
18481849 if (pio_sz)
18491850 continue;
@@ -1856,15 +1857,16 @@ mpt3sas_base_map_resources(struct MPT3SAS_ADAPTER *ioc) · 6 unmodified lines
18561857 chip_phys = (u64)ioc->chip_phys;
18571858 memap_sz = pci_resource_len(pdev, i);
18581859 ioc->chip = ioremap(ioc->chip_phys, memap_sz);
1859− if (ioc->chip == NULL) {
1860− pr_err(MPT3SAS_FMT "unable to map adapter memory!\n",
1861− ioc->name);
1862− r = -EINVAL;
1863− goto out_fail;
1864− }
18651860 }
18661861 }
18671862
1863+ if (ioc->chip == NULL) {
1864+ pr_err(MPT3SAS_FMT "unable to map adapter memory! "
1865+ " or resource not found\n", ioc->name);
1866+ r = -EINVAL;
1867+ goto out_fail;
1868+ }
1869+
18681870 _base_mask_interrupts(ioc);
18691871
18701872 r = _base_get_ioc_facts(ioc, CAN_SLEEP);
drivers/scsi/mvsas/mv_init.c+4−1
@@ -338,8 +338,11 @@ int mvs_ioremap(struct mvs_info *mvi, int bar, int bar_ex) · 337 unmodified lines
338338
339339 res_start = pci_resource_start(pdev, bar);
340340 res_len = pci_resource_len(pdev, bar);
341− if (!res_start || !res_len)
341+ if (!res_start || !res_len) {
342+ iounmap(mvi->regs_ex);
343+ mvi->regs_ex = NULL;
342344 goto err_out;
345+ }
343346
344347 res_flag = pci_resource_flags(pdev, bar);
345348 if (res_flag & IORESOURCE_CACHEABLE)
drivers/scsi/pm8001/pm8001_defs.h+3−1
@@ -49,13 +49,15 @@ enum chip_flavors { · 48 unmodified lines
4949 chip_8019,
5050 chip_8074,
5151 chip_8076,
52− chip_8077
52+ chip_8077,
53+ chip_8006,
5354 };
5455
5556 enum phy_speed {
5657 PHY_SPEED_15 = 0x01,
5758 PHY_SPEED_30 = 0x02,
5859 PHY_SPEED_60 = 0x04,
60+ PHY_SPEED_120 = 0x08,
5961 };
6062
6163 enum data_direction {
drivers/scsi/pm8001/pm8001_hwi.c+4−0
@@ -3263,6 +3263,10 @@ void pm8001_get_lrate_mode(struct pm8001_phy *phy, u8 link_rate) · 3262 unmodified lines
32633263 struct sas_phy *sas_phy = phy->sas_phy.phy;
32643264
32653265 switch (link_rate) {
3266+ case PHY_SPEED_120:
3267+ phy->sas_phy.linkrate = SAS_LINK_RATE_12_0_GBPS;
3268+ phy->sas_phy.phy->negotiated_linkrate = SAS_LINK_RATE_12_0_GBPS;
3269+ break;
32663270 case PHY_SPEED_60:
32673271 phy->sas_phy.linkrate = SAS_LINK_RATE_6_0_GBPS;
32683272 phy->sas_phy.phy->negotiated_linkrate = SAS_LINK_RATE_6_0_GBPS;
drivers/scsi/pm8001/pm8001_init.c+4−1
@@ -57,6 +57,7 @@ static const struct pm8001_chip_info pm8001_chips[] = { · 56 unmodified lines
5757 [chip_8074] = {0, 8, &pm8001_80xx_dispatch,},
5858 [chip_8076] = {0, 16, &pm8001_80xx_dispatch,},
5959 [chip_8077] = {0, 16, &pm8001_80xx_dispatch,},
60+ [chip_8006] = {0, 16, &pm8001_80xx_dispatch,},
6061 };
6162 static int pm8001_id;
6263
@@ -1107,6 +1108,8 @@ err_out_enable: · 1044 unmodified lines
11071108 */
11081109 static struct pci_device_id pm8001_pci_table[] = {
11091110 { PCI_VDEVICE(PMC_Sierra, 0x8001), chip_8001 },
1111+ { PCI_VDEVICE(PMC_Sierra, 0x8006), chip_8006 },
1112+ { PCI_VDEVICE(ADAPTEC2, 0x8006), chip_8006 },
11101113 { PCI_VDEVICE(ATTO, 0x0042), chip_8001 },
11111114 /* Support for SPC/SPCv/SPCve controllers */
11121115 { PCI_VDEVICE(ADAPTEC2, 0x8001), chip_8001 },
@@ -1217,7 +1220,7 @@ MODULE_AUTHOR("Anand Kumar Santhanam <AnandKumar.Santhanam@pmcs.com>"); · 104 unmodified lines
12171220 MODULE_AUTHOR("Sangeetha Gnanasekaran <Sangeetha.Gnanasekaran@pmcs.com>");
12181221 MODULE_AUTHOR("Nikith Ganigarakoppal <Nikith.Ganigarakoppal@pmcs.com>");
12191222 MODULE_DESCRIPTION(
1220− "PMC-Sierra PM8001/8081/8088/8089/8074/8076/8077 "
1223+ "PMC-Sierra PM8001/8006/8081/8088/8089/8074/8076/8077 "
12211224 "SAS/SATA controller driver");
12221225 MODULE_VERSION(DRV_VERSION);
12231226 MODULE_LICENSE("GPL");
drivers/scsi/pm8001/pm8001_sas.c+14−5
@@ -790,6 +790,7 @@ pm8001_exec_internal_task_abort(struct pm8001_hba_info *pm8001_ha, · 789 unmodified lines
790790 ccb->device = pm8001_dev;
791791 ccb->ccb_tag = ccb_tag;
792792 ccb->task = task;
793+ ccb->n_elem = 0;
793794
794795 res = PM8001_CHIP_DISP->task_abort(pm8001_ha,
795796 pm8001_dev, flag, task_tag, ccb_tag);
@@ -975,19 +976,27 @@ int pm8001_I_T_nexus_reset(struct domain_device *dev) · 179 unmodified lines
975976 phy = sas_get_local_phy(dev);
976977
977978 if (dev_is_sata(dev)) {
978− DECLARE_COMPLETION_ONSTACK(completion_setstate);
979979 if (scsi_is_sas_phy_local(phy)) {
980980 rc = 0;
981981 goto out;
982982 }
983983 rc = sas_phy_reset(phy, 1);
984+ if (rc) {
985+ PM8001_EH_DBG(pm8001_ha,
986+ pm8001_printk("phy reset failed for device %x\n"
987+ "with rc %d\n", pm8001_dev->device_id, rc));
988+ rc = TMF_RESP_FUNC_FAILED;
989+ goto out;
990+ }
984991 msleep(2000);
985992 rc = pm8001_exec_internal_task_abort(pm8001_ha, pm8001_dev ,
986993 dev, 1, 0);
987− pm8001_dev->setds_completion = &completion_setstate;
988− rc = PM8001_CHIP_DISP->set_dev_state_req(pm8001_ha,
989− pm8001_dev, 0x01);
990− wait_for_completion(&completion_setstate);
994+ if (rc) {
995+ PM8001_EH_DBG(pm8001_ha,
996+ pm8001_printk("task abort failed %x\n"
997+ "with rc %d\n", pm8001_dev->device_id, rc));
998+ rc = TMF_RESP_FUNC_FAILED;
999+ }
9911000 } else {
9921001 rc = sas_phy_reset(phy, 1);
9931002 msleep(2000);
drivers/scsi/pm8001/pm8001_sas.h+10−2
@@ -58,7 +58,7 @@ · 57 unmodified lines
5858 #include "pm8001_defs.h"
5959
6060 #define DRV_NAME "pm80xx"
61−#define DRV_VERSION "0.1.37"
61+#define DRV_VERSION "0.1.38"
6262 #define PM8001_FAIL_LOGGING 0x01 /* Error message logging */
6363 #define PM8001_INIT_LOGGING 0x02 /* driver init logging */
6464 #define PM8001_DISC_LOGGING 0x04 /* discovery layer logging */
@@ -241,7 +241,7 @@ struct pm8001_chip_info { · 176 unmodified lines
241241 struct pm8001_port {
242242 struct asd_sas_port sas_port;
243243 u8 port_attached;
244− u8 wide_port_phymap;
244+ u16 wide_port_phymap;
245245 u8 port_state;
246246 struct list_head list;
247247 };
@@ -569,6 +569,14 @@ struct pm8001_fw_image_header { · 321 unmodified lines
569569 #define NCQ_READ_LOG_FLAG 0x80000000
570570 #define NCQ_ABORT_ALL_FLAG 0x40000000
571571 #define NCQ_2ND_RLE_FLAG 0x20000000
572+
573+/* Device states */
574+#define DS_OPERATIONAL 0x01
575+#define DS_PORT_IN_RESET 0x02
576+#define DS_IN_RECOVERY 0x03
577+#define DS_IN_ERROR 0x04
578+#define DS_NON_OPERATIONAL 0x07
579+
572580 /**
573581 * brief param structure for firmware flash update.
574582 */
drivers/scsi/pm8001/pm80xx_hwi.c+82−29
@@ -309,6 +309,9 @@ static void read_main_config_table(struct pm8001_hba_info *pm8001_ha) · 308 unmodified lines
309309 pm8001_mr32(address, MAIN_INT_VECTOR_TABLE_OFFSET);
310310 pm8001_ha->main_cfg_tbl.pm80xx_tbl.phy_attr_table_offset =
311311 pm8001_mr32(address, MAIN_SAS_PHY_ATTR_TABLE_OFFSET);
312+ /* read port recover and reset timeout */
313+ pm8001_ha->main_cfg_tbl.pm80xx_tbl.port_recovery_timer =
314+ pm8001_mr32(address, MAIN_PORT_RECOVERY_TIMER);
312315 }
313316
314317 /**
@@ -585,6 +588,12 @@ static void update_main_config_table(struct pm8001_hba_info *pm8001_ha) · 270 unmodified lines
585588 pm8001_ha->main_cfg_tbl.pm80xx_tbl.port_recovery_timer);
586589 pm8001_mw32(address, MAIN_INT_REASSERTION_DELAY,
587590 pm8001_ha->main_cfg_tbl.pm80xx_tbl.interrupt_reassertion_delay);
591+
592+ pm8001_ha->main_cfg_tbl.pm80xx_tbl.port_recovery_timer &= 0xffff0000;
593+ pm8001_ha->main_cfg_tbl.pm80xx_tbl.port_recovery_timer |=
594+ PORT_RECOVERY_TIMEOUT;
595+ pm8001_mw32(address, MAIN_PORT_RECOVERY_TIMER,
596+ pm8001_ha->main_cfg_tbl.pm80xx_tbl.port_recovery_timer);
588597 }
589598
590599 /**
@@ -843,6 +852,7 @@ pm80xx_set_thermal_config(struct pm8001_hba_info *pm8001_ha) · 252 unmodified lines
843852 int rc;
844853 u32 tag;
845854 u32 opc = OPC_INB_SET_CONTROLLER_CONFIG;
855+ u32 page_code;
846856
847857 memset(&payload, 0, sizeof(struct set_ctrl_cfg_req));
848858 rc = pm8001_tag_alloc(pm8001_ha, &tag);
@@ -851,8 +861,14 @@ pm80xx_set_thermal_config(struct pm8001_hba_info *pm8001_ha) · 2 unmodified lines
851861
852862 circularQ = &pm8001_ha->inbnd_q_tbl[0];
853863 payload.tag = cpu_to_le32(tag);
864+
865+ if (IS_SPCV_12G(pm8001_ha->pdev))
866+ page_code = THERMAL_PAGE_CODE_7H;
867+ else
868+ page_code = THERMAL_PAGE_CODE_8H;
869+
854870 payload.cfg_pg[0] = (THERMAL_LOG_ENABLE << 9) |
855− (THERMAL_ENABLE << 8) | THERMAL_OP_CODE;
871+ (THERMAL_ENABLE << 8) | page_code;
856872 payload.cfg_pg[1] = (LTEMPHIL << 24) | (RTEMPHIL << 8);
857873
858874 rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload, 0);
@@ -1593,6 +1609,13 @@ mpi_ssp_completion(struct pm8001_hba_info *pm8001_ha , void *piomb) · 734 unmodified lines
15931609 ts->stat = SAS_OPEN_REJECT;
15941610 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
15951611 break;
1612+ case IO_XFER_ERROR_INVALID_SSP_RSP_FRAME:
1613+ PM8001_IO_DBG(pm8001_ha,
1614+ pm8001_printk("IO_XFER_ERROR_INVALID_SSP_RSP_FRAME\n"));
1615+ ts->resp = SAS_TASK_COMPLETE;
1616+ ts->stat = SAS_OPEN_REJECT;
1617+ ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
1618+ break;
15961619 case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
15971620 PM8001_IO_DBG(pm8001_ha,
15981621 pm8001_printk("IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n"));
@@ -2829,6 +2852,32 @@ static void pm80xx_hw_event_ack_req(struct pm8001_hba_info *pm8001_ha, · 1230 unmodified lines
28292852 static int pm80xx_chip_phy_ctl_req(struct pm8001_hba_info *pm8001_ha,
28302853 u32 phyId, u32 phy_op);
28312854
2855+static void hw_event_port_recover(struct pm8001_hba_info *pm8001_ha,
2856+ void *piomb)
2857+{
2858+ struct hw_event_resp *pPayload = (struct hw_event_resp *)(piomb + 4);
2859+ u32 phyid_npip_portstate = le32_to_cpu(pPayload->phyid_npip_portstate);
2860+ u8 phy_id = (u8)((phyid_npip_portstate & 0xFF0000) >> 16);
2861+ u32 lr_status_evt_portid =
2862+ le32_to_cpu(pPayload->lr_status_evt_portid);
2863+ u8 deviceType = pPayload->sas_identify.dev_type;
2864+ u8 link_rate = (u8)((lr_status_evt_portid & 0xF0000000) >> 28);
2865+ struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
2866+ u8 port_id = (u8)(lr_status_evt_portid & 0x000000FF);
2867+ struct pm8001_port *port = &pm8001_ha->port[port_id];
2868+
2869+ if (deviceType == SAS_END_DEVICE) {
2870+ pm80xx_chip_phy_ctl_req(pm8001_ha, phy_id,
2871+ PHY_NOTIFY_ENABLE_SPINUP);
2872+ }
2873+
2874+ port->wide_port_phymap |= (1U << phy_id);
2875+ pm8001_get_lrate_mode(phy, link_rate);
2876+ phy->sas_phy.oob_mode = SAS_OOB_MODE;
2877+ phy->phy_state = PHY_STATE_LINK_UP_SPCV;
2878+ phy->phy_attached = 1;
2879+}
2880+
28322881 /**
28332882 * hw_event_sas_phy_up -FW tells me a SAS phy up event.
28342883 * @pm8001_ha: our hba card information
@@ -2856,6 +2905,7 @@ hw_event_sas_phy_up(struct pm8001_hba_info *pm8001_ha, void *piomb) · 21 unmodified lines
28562905 unsigned long flags;
28572906 u8 deviceType = pPayload->sas_identify.dev_type;
28582907 port->port_state = portstate;
2908+ port->wide_port_phymap |= (1U << phy_id);
28592909 phy->phy_state = PHY_STATE_LINK_UP_SPCV;
28602910 PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
28612911 "portid:%d; phyid:%d; linkrate:%d; "
@@ -2981,7 +3031,6 @@ hw_event_phy_down(struct pm8001_hba_info *pm8001_ha, void *piomb) · 119 unmodified lines
29813031 struct pm8001_port *port = &pm8001_ha->port[port_id];
29823032 struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
29833033 port->port_state = portstate;
2984− phy->phy_type = 0;
29853034 phy->identify.device_type = 0;
29863035 phy->phy_attached = 0;
29873036 memset(&phy->dev_sas_addr, 0, SAS_ADDR_SIZE);
@@ -2993,9 +3042,13 @@ hw_event_phy_down(struct pm8001_hba_info *pm8001_ha, void *piomb) · 5 unmodified lines
29933042 pm8001_printk(" PortInvalid portID %d\n", port_id));
29943043 PM8001_MSG_DBG(pm8001_ha,
29953044 pm8001_printk(" Last phy Down and port invalid\n"));
2996− port->port_attached = 0;
2997− pm80xx_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_PHY_DOWN,
2998− port_id, phy_id, 0, 0);
3045+ if (phy->phy_type & PORT_TYPE_SATA) {
3046+ phy->phy_type = 0;
3047+ port->port_attached = 0;
3048+ pm80xx_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_PHY_DOWN,
3049+ port_id, phy_id, 0, 0);
3050+ }
3051+ sas_phy_disconnected(&phy->sas_phy);
29993052 break;
30003053 case PORT_IN_RESET:
30013054 PM8001_MSG_DBG(pm8001_ha,
@@ -3003,22 +3056,26 @@ hw_event_phy_down(struct pm8001_hba_info *pm8001_ha, void *piomb) · 1 unmodified line
30033056 break;
30043057 case PORT_NOT_ESTABLISHED:
30053058 PM8001_MSG_DBG(pm8001_ha,
3006− pm8001_printk(" phy Down and PORT_NOT_ESTABLISHED\n"));
3059+ pm8001_printk(" Phy Down and PORT_NOT_ESTABLISHED\n"));
30073060 port->port_attached = 0;
30083061 break;
30093062 case PORT_LOSTCOMM:
30103063 PM8001_MSG_DBG(pm8001_ha,
3011− pm8001_printk(" phy Down and PORT_LOSTCOMM\n"));
3064+ pm8001_printk(" Phy Down and PORT_LOSTCOMM\n"));
30123065 PM8001_MSG_DBG(pm8001_ha,
30133066 pm8001_printk(" Last phy Down and port invalid\n"));
3014− port->port_attached = 0;
3015− pm80xx_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_PHY_DOWN,
3016− port_id, phy_id, 0, 0);
3067+ if (phy->phy_type & PORT_TYPE_SATA) {
3068+ port->port_attached = 0;
3069+ phy->phy_type = 0;
3070+ pm80xx_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_PHY_DOWN,
3071+ port_id, phy_id, 0, 0);
3072+ }
3073+ sas_phy_disconnected(&phy->sas_phy);
30173074 break;
30183075 default:
30193076 port->port_attached = 0;
30203077 PM8001_MSG_DBG(pm8001_ha,
3021− pm8001_printk(" phy Down and(default) = 0x%x\n",
3078+ pm8001_printk(" Phy Down and(default) = 0x%x\n",
30223079 portstate));
30233080 break;
30243081
@@ -3084,7 +3141,7 @@ static int mpi_thermal_hw_event(struct pm8001_hba_info *pm8001_ha, void *piomb) · 59 unmodified lines
30843141 */
30853142 static int mpi_hw_event(struct pm8001_hba_info *pm8001_ha, void *piomb)
30863143 {
3087− unsigned long flags;
3144+ unsigned long flags, i;
30883145 struct hw_event_resp *pPayload =
30893146 (struct hw_event_resp *)(piomb + 4);
30903147 u32 lr_status_evt_portid =
@@ -3097,9 +3154,9 @@ static int mpi_hw_event(struct pm8001_hba_info *pm8001_ha, void *piomb) · 6 unmodified lines
30973154 (u16)((lr_status_evt_portid & 0x00FFFF00) >> 8);
30983155 u8 status =
30993156 (u8)((lr_status_evt_portid & 0x0F000000) >> 24);
3100−
31013157 struct sas_ha_struct *sas_ha = pm8001_ha->sas;
31023158 struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
3159+ struct pm8001_port *port = &pm8001_ha->port[port_id];
31033160 struct asd_sas_phy *sas_phy = sas_ha->sas_phy[phy_id];
31043161 PM8001_MSG_DBG(pm8001_ha,
31053162 pm8001_printk("portid:%d phyid:%d event:0x%x status:0x%x\n",
@@ -3125,7 +3182,9 @@ static int mpi_hw_event(struct pm8001_hba_info *pm8001_ha, void *piomb) · 19 unmodified lines
31253182 case HW_EVENT_PHY_DOWN:
31263183 PM8001_MSG_DBG(pm8001_ha,
31273184 pm8001_printk("HW_EVENT_PHY_DOWN\n"));
3128− sas_ha->notify_phy_event(&phy->sas_phy, PHYE_LOSS_OF_SIGNAL);
3185+ if (phy->phy_type & PORT_TYPE_SATA)
3186+ sas_ha->notify_phy_event(&phy->sas_phy,
3187+ PHYE_LOSS_OF_SIGNAL);
31293188 phy->phy_attached = 0;
31303189 phy->phy_state = 0;
31313190 hw_event_phy_down(pm8001_ha, piomb);
@@ -3169,9 +3228,6 @@ static int mpi_hw_event(struct pm8001_hba_info *pm8001_ha, void *piomb) · 37 unmodified lines
31693228 pm8001_printk("HW_EVENT_LINK_ERR_INVALID_DWORD\n"));
31703229 pm80xx_hw_event_ack_req(pm8001_ha, 0,
31713230 HW_EVENT_LINK_ERR_INVALID_DWORD, port_id, phy_id, 0, 0);
3172− sas_phy_disconnected(sas_phy);
3173− phy->phy_attached = 0;
3174− sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
31753231 break;
31763232 case HW_EVENT_LINK_ERR_DISPARITY_ERROR:
31773233 PM8001_MSG_DBG(pm8001_ha,
@@ -3179,9 +3235,6 @@ static int mpi_hw_event(struct pm8001_hba_info *pm8001_ha, void *piomb) · 1 unmodified line
31793235 pm80xx_hw_event_ack_req(pm8001_ha, 0,
31803236 HW_EVENT_LINK_ERR_DISPARITY_ERROR,
31813237 port_id, phy_id, 0, 0);
3182− sas_phy_disconnected(sas_phy);
3183− phy->phy_attached = 0;
3184− sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
31853238 break;
31863239 case HW_EVENT_LINK_ERR_CODE_VIOLATION:
31873240 PM8001_MSG_DBG(pm8001_ha,
@@ -3189,9 +3242,6 @@ static int mpi_hw_event(struct pm8001_hba_info *pm8001_ha, void *piomb) · 1 unmodified line
31893242 pm80xx_hw_event_ack_req(pm8001_ha, 0,
31903243 HW_EVENT_LINK_ERR_CODE_VIOLATION,
31913244 port_id, phy_id, 0, 0);
3192− sas_phy_disconnected(sas_phy);
3193− phy->phy_attached = 0;
3194− sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
31953245 break;
31963246 case HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH:
31973247 PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
@@ -3199,9 +3249,6 @@ static int mpi_hw_event(struct pm8001_hba_info *pm8001_ha, void *piomb) · 1 unmodified line
31993249 pm80xx_hw_event_ack_req(pm8001_ha, 0,
32003250 HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH,
32013251 port_id, phy_id, 0, 0);
3202− sas_phy_disconnected(sas_phy);
3203− phy->phy_attached = 0;
3204− sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
32053252 break;
32063253 case HW_EVENT_MALFUNCTION:
32073254 PM8001_MSG_DBG(pm8001_ha,
@@ -3257,13 +3304,19 @@ static int mpi_hw_event(struct pm8001_hba_info *pm8001_ha, void *piomb) · 49 unmodified lines
32573304 pm80xx_hw_event_ack_req(pm8001_ha, 0,
32583305 HW_EVENT_PORT_RECOVERY_TIMER_TMO,
32593306 port_id, phy_id, 0, 0);
3260− sas_phy_disconnected(sas_phy);
3261− phy->phy_attached = 0;
3262− sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
3307+ for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
3308+ if (port->wide_port_phymap & (1 << i)) {
3309+ phy = &pm8001_ha->phy[i];
3310+ sas_ha->notify_phy_event(&phy->sas_phy,
3311+ PHYE_LOSS_OF_SIGNAL);
3312+ port->wide_port_phymap &= ~(1 << i);
3313+ }
3314+ }
32633315 break;
32643316 case HW_EVENT_PORT_RECOVER:
32653317 PM8001_MSG_DBG(pm8001_ha,
32663318 pm8001_printk("HW_EVENT_PORT_RECOVER\n"));
3319+ hw_event_port_recover(pm8001_ha, piomb);
32673320 break;
32683321 case HW_EVENT_PORT_RESET_COMPLETE:
32693322 PM8001_MSG_DBG(pm8001_ha,
drivers/scsi/pm8001/pm80xx_hwi.h+3−2
@@ -177,7 +177,8 @@ · 176 unmodified lines
177177 /* Thermal related */
178178 #define THERMAL_ENABLE 0x1
179179 #define THERMAL_LOG_ENABLE 0x1
180−#define THERMAL_OP_CODE 0x6
180+#define THERMAL_PAGE_CODE_7H 0x6
181+#define THERMAL_PAGE_CODE_8H 0x7
181182 #define LTEMPHIL 70
182183 #define RTEMPHIL 100
183184
@@ -1174,7 +1175,7 @@ typedef struct SASProtocolTimerConfig SASProtocolTimerConfig_t; · 990 unmodified lines
11741175 #define IO_XFER_ERROR_INTERNAL_CRC_ERROR 0x54
11751176 #define MPI_IO_RQE_BUSY_FULL 0x55
11761177 #define IO_XFER_ERR_EOB_DATA_OVERRUN 0x56
1177−#define IO_XFR_ERROR_INVALID_SSP_RSP_FRAME 0x57
1178+#define IO_XFER_ERROR_INVALID_SSP_RSP_FRAME 0x57
11781179 #define IO_OPEN_CNX_ERROR_OPEN_PREEMPTED 0x58
11791180
11801181 #define MPI_ERR_IO_RESOURCE_UNAVAILABLE 0x1004
drivers/scsi/qla2xxx/qla_attr.c+19−5
@@ -884,7 +884,6 @@ qla2x00_sysfs_read_dcbx_tlv(struct file *filp, struct kobject *kobj, · 883 unmodified lines
884884 struct device, kobj)));
885885 struct qla_hw_data *ha = vha->hw;
886886 int rval;
887− uint16_t actual_size;
888887
889888 if (!capable(CAP_SYS_ADMIN) || off != 0 || count > DCBX_TLV_DATA_SIZE)
890889 return 0;
@@ -901,7 +900,6 @@ qla2x00_sysfs_read_dcbx_tlv(struct file *filp, struct kobject *kobj, · 10 unmodified lines
901900 }
902901
903902 do_read:
904− actual_size = 0;
905903 memset(ha->dcbx_tlv, 0, DCBX_TLV_DATA_SIZE);
906904
907905 rval = qla2x00_get_dcbx_params(vha, ha->dcbx_tlv_dma,
@@ -1079,8 +1077,7 @@ qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr, · 171 unmodified lines
10791077 char *buf)
10801078 {
10811079 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1082− return scnprintf(buf, PAGE_SIZE, "%s\n",
1083− vha->hw->model_desc ? vha->hw->model_desc : "");
1080+ return scnprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_desc);
10841081 }
10851082
10861083 static ssize_t
@@ -1348,7 +1345,8 @@ qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr, · 261 unmodified lines
13481345 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
13491346 struct qla_hw_data *ha = vha->hw;
13501347
1351− if (!IS_QLA81XX(ha) && !IS_QLA8031(ha) && !IS_QLA8044(ha))
1348+ if (!IS_QLA81XX(ha) && !IS_QLA8031(ha) && !IS_QLA8044(ha) &&
1349+ !IS_QLA27XX(ha))
13521350 return scnprintf(buf, PAGE_SIZE, "\n");
13531351
13541352 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
@@ -1537,6 +1535,20 @@ qla2x00_allow_cna_fw_dump_store(struct device *dev, · 182 unmodified lines
15371535 return strlen(buf);
15381536 }
15391537
1538+static ssize_t
1539+qla2x00_pep_version_show(struct device *dev, struct device_attribute *attr,
1540+ char *buf)
1541+{
1542+ scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1543+ struct qla_hw_data *ha = vha->hw;
1544+
1545+ if (!IS_QLA27XX(ha))
1546+ return scnprintf(buf, PAGE_SIZE, "\n");
1547+
1548+ return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
1549+ ha->pep_version[0], ha->pep_version[1], ha->pep_version[2]);
1550+}
1551+
15401552 static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
15411553 static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
15421554 static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
@@ -1581,6 +1593,7 @@ static DEVICE_ATTR(fw_dump_size, S_IRUGO, qla2x00_fw_dump_size_show, NULL); · 38 unmodified lines
15811593 static DEVICE_ATTR(allow_cna_fw_dump, S_IRUGO | S_IWUSR,
15821594 qla2x00_allow_cna_fw_dump_show,
15831595 qla2x00_allow_cna_fw_dump_store);
1596+static DEVICE_ATTR(pep_version, S_IRUGO, qla2x00_pep_version_show, NULL);
15841597
15851598 struct device_attribute *qla2x00_host_attrs[] = {
15861599 &dev_attr_driver_version,
@@ -1614,6 +1627,7 @@ struct device_attribute *qla2x00_host_attrs[] = { · 27 unmodified lines
16141627 &dev_attr_diag_megabytes,
16151628 &dev_attr_fw_dump_size,
16161629 &dev_attr_allow_cna_fw_dump,
1630+ &dev_attr_pep_version,
16171631 NULL,
16181632 };
16191633
drivers/scsi/qla2xxx/qla_bsg.c+1−6
@@ -405,7 +405,7 @@ done: · 404 unmodified lines
405405 return rval;
406406 }
407407
408−inline uint16_t
408+static inline uint16_t
409409 qla24xx_calc_ct_iocbs(uint16_t dsds)
410410 {
411411 uint16_t iocbs;
@@ -1733,7 +1733,6 @@ qla24xx_process_bidir_cmd(struct fc_bsg_job *bsg_job) · 1321 unmodified lines
17331733 struct Scsi_Host *host = bsg_job->shost;
17341734 scsi_qla_host_t *vha = shost_priv(host);
17351735 struct qla_hw_data *ha = vha->hw;
1736− uint16_t thread_id;
17371736 uint32_t rval = EXT_STATUS_OK;
17381737 uint16_t req_sg_cnt = 0;
17391738 uint16_t rsp_sg_cnt = 0;
@@ -1790,8 +1789,6 @@ qla24xx_process_bidir_cmd(struct fc_bsg_job *bsg_job) · 50 unmodified lines
17901789 goto done;
17911790 }
17921791
1793− thread_id = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
1794−
17951792 mutex_lock(&ha->selflogin_lock);
17961793 if (vha->self_login_loop_id == 0) {
17971794 /* Initialize all required fields of fcport */
@@ -2174,7 +2171,6 @@ qla24xx_bsg_request(struct fc_bsg_job *bsg_job) · 376 unmodified lines
21742171 {
21752172 int ret = -EINVAL;
21762173 struct fc_rport *rport;
2177− fc_port_t *fcport = NULL;
21782174 struct Scsi_Host *host;
21792175 scsi_qla_host_t *vha;
21802176
@@ -2183,7 +2179,6 @@ qla24xx_bsg_request(struct fc_bsg_job *bsg_job) · 2 unmodified lines
21832179
21842180 if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) {
21852181 rport = bsg_job->rport;
2186− fcport = *(fc_port_t **) rport->dd_data;
21872182 host = rport_to_shost(rport);
21882183 vha = shost_priv(host);
21892184 } else {
drivers/scsi/qla2xxx/qla_dbg.c+63−39
@@ -19,14 +19,14 @@ · 18 unmodified lines
1919 * | Device Discovery | 0x2016 | 0x2020-0x2022, |
2020 * | | | 0x2011-0x2012, |
2121 * | | | 0x2099-0x20a4 |
22− * | Queue Command and IO tracing | 0x3059 | 0x300b |
22+ * | Queue Command and IO tracing | 0x3075 | 0x300b |
2323 * | | | 0x3027-0x3028 |
2424 * | | | 0x303d-0x3041 |
2525 * | | | 0x302d,0x3033 |
2626 * | | | 0x3036,0x3038 |
2727 * | | | 0x303a |
2828 * | DPC Thread | 0x4023 | 0x4002,0x4013 |
29− * | Async Events | 0x5087 | 0x502b-0x502f |
29+ * | Async Events | 0x508a | 0x502b-0x502f |
3030 * | | | 0x5047 |
3131 * | | | 0x5084,0x5075 |
3232 * | | | 0x503d,0x5044 |
@@ -117,7 +117,7 @@ qla27xx_dump_mpi_ram(struct qla_hw_data *ha, uint32_t addr, uint32_t *ram, · 84 unmodified lines
117117 {
118118 int rval;
119119 uint32_t cnt, stat, timer, dwords, idx;
120− uint16_t mb0, mb1;
120+ uint16_t mb0;
121121 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
122122 dma_addr_t dump_dma = ha->gid_list_dma;
123123 uint32_t *dump = (uint32_t *)ha->gid_list;
@@ -161,7 +161,7 @@ qla27xx_dump_mpi_ram(struct qla_hw_data *ha, uint32_t addr, uint32_t *ram, · 37 unmodified lines
161161 &ha->mbx_cmd_flags);
162162
163163 mb0 = RD_REG_WORD(&reg->mailbox0);
164− mb1 = RD_REG_WORD(&reg->mailbox1);
164+ RD_REG_WORD(&reg->mailbox1);
165165
166166 WRT_REG_DWORD(&reg->hccr,
167167 HCCRX_CLR_RISC_INT);
@@ -486,7 +486,7 @@ qla25xx_copy_fce(struct qla_hw_data *ha, void *ptr, uint32_t **last_chain) · 318 unmodified lines
486486 return ptr;
487487
488488 *last_chain = &fcec->type;
489− fcec->type = __constant_htonl(DUMP_CHAIN_FCE);
489+ fcec->type = htonl(DUMP_CHAIN_FCE);
490490 fcec->chain_size = htonl(sizeof(struct qla2xxx_fce_chain) +
491491 fce_calc_size(ha->fce_bufs));
492492 fcec->size = htonl(fce_calc_size(ha->fce_bufs));
@@ -527,7 +527,7 @@ qla2xxx_copy_atioqueues(struct qla_hw_data *ha, void *ptr, · 34 unmodified lines
527527 /* aqp = ha->atio_q_map[que]; */
528528 q = ptr;
529529 *last_chain = &q->type;
530− q->type = __constant_htonl(DUMP_CHAIN_QUEUE);
530+ q->type = htonl(DUMP_CHAIN_QUEUE);
531531 q->chain_size = htonl(
532532 sizeof(struct qla2xxx_mqueue_chain) +
533533 sizeof(struct qla2xxx_mqueue_header) +
@@ -536,7 +536,7 @@ qla2xxx_copy_atioqueues(struct qla_hw_data *ha, void *ptr, · 2 unmodified lines
536536
537537 /* Add header. */
538538 qh = ptr;
539− qh->queue = __constant_htonl(TYPE_ATIO_QUEUE);
539+ qh->queue = htonl(TYPE_ATIO_QUEUE);
540540 qh->number = htonl(que);
541541 qh->size = htonl(aqp->length * sizeof(request_t));
542542 ptr += sizeof(struct qla2xxx_mqueue_header);
@@ -571,7 +571,7 @@ qla25xx_copy_mqueues(struct qla_hw_data *ha, void *ptr, uint32_t **last_chain) · 28 unmodified lines
571571 /* Add chain. */
572572 q = ptr;
573573 *last_chain = &q->type;
574− q->type = __constant_htonl(DUMP_CHAIN_QUEUE);
574+ q->type = htonl(DUMP_CHAIN_QUEUE);
575575 q->chain_size = htonl(
576576 sizeof(struct qla2xxx_mqueue_chain) +
577577 sizeof(struct qla2xxx_mqueue_header) +
@@ -580,7 +580,7 @@ qla25xx_copy_mqueues(struct qla_hw_data *ha, void *ptr, uint32_t **last_chain) · 2 unmodified lines
580580
581581 /* Add header. */
582582 qh = ptr;
583− qh->queue = __constant_htonl(TYPE_REQUEST_QUEUE);
583+ qh->queue = htonl(TYPE_REQUEST_QUEUE);
584584 qh->number = htonl(que);
585585 qh->size = htonl(req->length * sizeof(request_t));
586586 ptr += sizeof(struct qla2xxx_mqueue_header);
@@ -599,7 +599,7 @@ qla25xx_copy_mqueues(struct qla_hw_data *ha, void *ptr, uint32_t **last_chain) · 12 unmodified lines
599599 /* Add chain. */
600600 q = ptr;
601601 *last_chain = &q->type;
602− q->type = __constant_htonl(DUMP_CHAIN_QUEUE);
602+ q->type = htonl(DUMP_CHAIN_QUEUE);
603603 q->chain_size = htonl(
604604 sizeof(struct qla2xxx_mqueue_chain) +
605605 sizeof(struct qla2xxx_mqueue_header) +
@@ -608,7 +608,7 @@ qla25xx_copy_mqueues(struct qla_hw_data *ha, void *ptr, uint32_t **last_chain) · 2 unmodified lines
608608
609609 /* Add header. */
610610 qh = ptr;
611− qh->queue = __constant_htonl(TYPE_RESPONSE_QUEUE);
611+ qh->queue = htonl(TYPE_RESPONSE_QUEUE);
612612 qh->number = htonl(que);
613613 qh->size = htonl(rsp->length * sizeof(response_t));
614614 ptr += sizeof(struct qla2xxx_mqueue_header);
@@ -627,15 +627,15 @@ qla25xx_copy_mq(struct qla_hw_data *ha, void *ptr, uint32_t **last_chain) · 12 unmodified lines
627627 uint32_t cnt, que_idx;
628628 uint8_t que_cnt;
629629 struct qla2xxx_mq_chain *mq = ptr;
630− device_reg_t __iomem *reg;
630+ device_reg_t *reg;
631631
632632 if (!ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha))
633633 return ptr;
634634
635635 mq = ptr;
636636 *last_chain = &mq->type;
637− mq->type = __constant_htonl(DUMP_CHAIN_MQ);
638− mq->chain_size = __constant_htonl(sizeof(struct qla2xxx_mq_chain));
637+ mq->type = htonl(DUMP_CHAIN_MQ);
638+ mq->chain_size = htonl(sizeof(struct qla2xxx_mq_chain));
639639
640640 que_cnt = ha->max_req_queues > ha->max_rsp_queues ?
641641 ha->max_req_queues : ha->max_rsp_queues;
@@ -695,8 +695,10 @@ qla2300_fw_dump(scsi_qla_host_t *vha, int hardware_locked) · 53 unmodified lines
695695
696696 flags = 0;
697697
698+#ifndef __CHECKER__
698699 if (!hardware_locked)
699700 spin_lock_irqsave(&ha->hardware_lock, flags);
701+#endif
700702
701703 if (!ha->fw_dump) {
702704 ql_log(ql_log_warn, vha, 0xd002,
@@ -832,8 +834,12 @@ qla2300_fw_dump(scsi_qla_host_t *vha, int hardware_locked) · 129 unmodified lines
832834 qla2xxx_dump_post_process(base_vha, rval);
833835
834836 qla2300_fw_dump_failed:
837+#ifndef __CHECKER__
835838 if (!hardware_locked)
836839 spin_unlock_irqrestore(&ha->hardware_lock, flags);
840+#else
841+ ;
842+#endif
837843 }
838844
839845 /**
@@ -859,8 +865,10 @@ qla2100_fw_dump(scsi_qla_host_t *vha, int hardware_locked) · 19 unmodified lines
859865 mb0 = mb2 = 0;
860866 flags = 0;
861867
868+#ifndef __CHECKER__
862869 if (!hardware_locked)
863870 spin_lock_irqsave(&ha->hardware_lock, flags);
871+#endif
864872
865873 if (!ha->fw_dump) {
866874 ql_log(ql_log_warn, vha, 0xd004,
@@ -1030,8 +1038,12 @@ qla2100_fw_dump(scsi_qla_host_t *vha, int hardware_locked) · 163 unmodified lines
10301038 qla2xxx_dump_post_process(base_vha, rval);
10311039
10321040 qla2100_fw_dump_failed:
1041+#ifndef __CHECKER__
10331042 if (!hardware_locked)
10341043 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1044+#else
1045+ ;
1046+#endif
10351047 }
10361048
10371049 void
@@ -1039,7 +1051,6 @@ qla24xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked) · 1 unmodified line
10391051 {
10401052 int rval;
10411053 uint32_t cnt;
1042− uint32_t risc_address;
10431054 struct qla_hw_data *ha = vha->hw;
10441055 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
10451056 uint32_t __iomem *dmp_reg;
@@ -1047,7 +1058,6 @@ qla24xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked) · 1 unmodified line
10471058 uint16_t __iomem *mbx_reg;
10481059 unsigned long flags;
10491060 struct qla24xx_fw_dump *fw;
1050− uint32_t ext_mem_cnt;
10511061 void *nxt;
10521062 void *nxt_chain;
10531063 uint32_t *last_chain = NULL;
@@ -1056,12 +1066,13 @@ qla24xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked) · 2 unmodified lines
10561066 if (IS_P3P_TYPE(ha))
10571067 return;
10581068
1059− risc_address = ext_mem_cnt = 0;
10601069 flags = 0;
10611070 ha->fw_dump_cap_flags = 0;
10621071
1072+#ifndef __CHECKER__
10631073 if (!hardware_locked)
10641074 spin_lock_irqsave(&ha->hardware_lock, flags);
1075+#endif
10651076
10661077 if (!ha->fw_dump) {
10671078 ql_log(ql_log_warn, vha, 0xd006,
@@ -1274,8 +1285,8 @@ qla24xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked) · 206 unmodified lines
12741285 nxt_chain = (void *)ha->fw_dump + ha->chain_offset;
12751286 nxt_chain = qla2xxx_copy_atioqueues(ha, nxt_chain, &last_chain);
12761287 if (last_chain) {
1277− ha->fw_dump->version |= __constant_htonl(DUMP_CHAIN_VARIANT);
1278− *last_chain |= __constant_htonl(DUMP_CHAIN_LAST);
1288+ ha->fw_dump->version |= htonl(DUMP_CHAIN_VARIANT);
1289+ *last_chain |= htonl(DUMP_CHAIN_LAST);
12791290 }
12801291
12811292 /* Adjust valid length. */
@@ -1285,8 +1296,12 @@ qla24xx_fw_dump_failed_0: · 3 unmodified lines
12851296 qla2xxx_dump_post_process(base_vha, rval);
12861297
12871298 qla24xx_fw_dump_failed:
1299+#ifndef __CHECKER__
12881300 if (!hardware_locked)
12891301 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1302+#else
1303+ ;
1304+#endif
12901305 }
12911306
12921307 void
@@ -1294,7 +1309,6 @@ qla25xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked) · 1 unmodified line
12941309 {
12951310 int rval;
12961311 uint32_t cnt;
1297− uint32_t risc_address;
12981312 struct qla_hw_data *ha = vha->hw;
12991313 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
13001314 uint32_t __iomem *dmp_reg;
@@ -1302,17 +1316,17 @@ qla25xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked) · 1 unmodified line
13021316 uint16_t __iomem *mbx_reg;
13031317 unsigned long flags;
13041318 struct qla25xx_fw_dump *fw;
1305− uint32_t ext_mem_cnt;
13061319 void *nxt, *nxt_chain;
13071320 uint32_t *last_chain = NULL;
13081321 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
13091322
1310− risc_address = ext_mem_cnt = 0;
13111323 flags = 0;
13121324 ha->fw_dump_cap_flags = 0;
13131325
1326+#ifndef __CHECKER__
13141327 if (!hardware_locked)
13151328 spin_lock_irqsave(&ha->hardware_lock, flags);
1329+#endif
13161330
13171331 if (!ha->fw_dump) {
13181332 ql_log(ql_log_warn, vha, 0xd008,
@@ -1329,7 +1343,7 @@ qla25xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked) · 10 unmodified lines
13291343 }
13301344 fw = &ha->fw_dump->isp.isp25;
13311345 qla2xxx_prep_dump(ha, ha->fw_dump);
1332− ha->fw_dump->version = __constant_htonl(2);
1346+ ha->fw_dump->version = htonl(2);
13331347
13341348 fw->host_status = htonl(RD_REG_DWORD(&reg->host_status));
13351349
@@ -1593,8 +1607,8 @@ qla25xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked) · 257 unmodified lines
15931607 nxt_chain = qla25xx_copy_mqueues(ha, nxt_chain, &last_chain);
15941608 nxt_chain = qla2xxx_copy_atioqueues(ha, nxt_chain, &last_chain);
15951609 if (last_chain) {
1596− ha->fw_dump->version |= __constant_htonl(DUMP_CHAIN_VARIANT);
1597− *last_chain |= __constant_htonl(DUMP_CHAIN_LAST);
1610+ ha->fw_dump->version |= htonl(DUMP_CHAIN_VARIANT);
1611+ *last_chain |= htonl(DUMP_CHAIN_LAST);
15981612 }
15991613
16001614 /* Adjust valid length. */
@@ -1604,8 +1618,12 @@ qla25xx_fw_dump_failed_0: · 3 unmodified lines
16041618 qla2xxx_dump_post_process(base_vha, rval);
16051619
16061620 qla25xx_fw_dump_failed:
1621+#ifndef __CHECKER__
16071622 if (!hardware_locked)
16081623 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1624+#else
1625+ ;
1626+#endif
16091627 }
16101628
16111629 void
@@ -1613,7 +1631,6 @@ qla81xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked) · 1 unmodified line
16131631 {
16141632 int rval;
16151633 uint32_t cnt;
1616− uint32_t risc_address;
16171634 struct qla_hw_data *ha = vha->hw;
16181635 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
16191636 uint32_t __iomem *dmp_reg;
@@ -1621,17 +1638,17 @@ qla81xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked) · 1 unmodified line
16211638 uint16_t __iomem *mbx_reg;
16221639 unsigned long flags;
16231640 struct qla81xx_fw_dump *fw;
1624− uint32_t ext_mem_cnt;
16251641 void *nxt, *nxt_chain;
16261642 uint32_t *last_chain = NULL;
16271643 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
16281644
1629− risc_address = ext_mem_cnt = 0;
16301645 flags = 0;
16311646 ha->fw_dump_cap_flags = 0;
16321647
1648+#ifndef __CHECKER__
16331649 if (!hardware_locked)
16341650 spin_lock_irqsave(&ha->hardware_lock, flags);
1651+#endif
16351652
16361653 if (!ha->fw_dump) {
16371654 ql_log(ql_log_warn, vha, 0xd00a,
@@ -1914,8 +1931,8 @@ qla81xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked) · 276 unmodified lines
19141931 nxt_chain = qla25xx_copy_mqueues(ha, nxt_chain, &last_chain);
19151932 nxt_chain = qla2xxx_copy_atioqueues(ha, nxt_chain, &last_chain);
19161933 if (last_chain) {
1917− ha->fw_dump->version |= __constant_htonl(DUMP_CHAIN_VARIANT);
1918− *last_chain |= __constant_htonl(DUMP_CHAIN_LAST);
1934+ ha->fw_dump->version |= htonl(DUMP_CHAIN_VARIANT);
1935+ *last_chain |= htonl(DUMP_CHAIN_LAST);
19191936 }
19201937
19211938 /* Adjust valid length. */
@@ -1925,16 +1942,19 @@ qla81xx_fw_dump_failed_0: · 3 unmodified lines
19251942 qla2xxx_dump_post_process(base_vha, rval);
19261943
19271944 qla81xx_fw_dump_failed:
1945+#ifndef __CHECKER__
19281946 if (!hardware_locked)
19291947 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1948+#else
1949+ ;
1950+#endif
19301951 }
19311952
19321953 void
19331954 qla83xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
19341955 {
19351956 int rval;
1936− uint32_t cnt, reg_data;
1937− uint32_t risc_address;
1957+ uint32_t cnt;
19381958 struct qla_hw_data *ha = vha->hw;
19391959 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
19401960 uint32_t __iomem *dmp_reg;
@@ -1942,17 +1962,17 @@ qla83xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked) · 1 unmodified line
19421962 uint16_t __iomem *mbx_reg;
19431963 unsigned long flags;
19441964 struct qla83xx_fw_dump *fw;
1945− uint32_t ext_mem_cnt;
19461965 void *nxt, *nxt_chain;
19471966 uint32_t *last_chain = NULL;
19481967 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
19491968
1950− risc_address = ext_mem_cnt = 0;
19511969 flags = 0;
19521970 ha->fw_dump_cap_flags = 0;
19531971
1972+#ifndef __CHECKER__
19541973 if (!hardware_locked)
19551974 spin_lock_irqsave(&ha->hardware_lock, flags);
1975+#endif
19561976
19571977 if (!ha->fw_dump) {
19581978 ql_log(ql_log_warn, vha, 0xd00c,
@@ -1979,16 +1999,16 @@ qla83xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked) · 20 unmodified lines
19791999
19802000 WRT_REG_DWORD(&reg->iobase_addr, 0x6000);
19812001 dmp_reg = &reg->iobase_window;
1982− reg_data = RD_REG_DWORD(dmp_reg);
2002+ RD_REG_DWORD(dmp_reg);
19832003 WRT_REG_DWORD(dmp_reg, 0);
19842004
19852005 dmp_reg = &reg->unused_4_1[0];
1986− reg_data = RD_REG_DWORD(dmp_reg);
2006+ RD_REG_DWORD(dmp_reg);
19872007 WRT_REG_DWORD(dmp_reg, 0);
19882008
19892009 WRT_REG_DWORD(&reg->iobase_addr, 0x6010);
19902010 dmp_reg = &reg->unused_4_1[2];
1991− reg_data = RD_REG_DWORD(dmp_reg);
2011+ RD_REG_DWORD(dmp_reg);
19922012 WRT_REG_DWORD(dmp_reg, 0);
19932013
19942014 /* select PCR and disable ecc checking and correction */
@@ -2420,8 +2440,8 @@ copy_queue: · 425 unmodified lines
24202440 nxt_chain = qla25xx_copy_mqueues(ha, nxt_chain, &last_chain);
24212441 nxt_chain = qla2xxx_copy_atioqueues(ha, nxt_chain, &last_chain);
24222442 if (last_chain) {
2423− ha->fw_dump->version |= __constant_htonl(DUMP_CHAIN_VARIANT);
2424− *last_chain |= __constant_htonl(DUMP_CHAIN_LAST);
2443+ ha->fw_dump->version |= htonl(DUMP_CHAIN_VARIANT);
2444+ *last_chain |= htonl(DUMP_CHAIN_LAST);
24252445 }
24262446
24272447 /* Adjust valid length. */
@@ -2431,8 +2451,12 @@ qla83xx_fw_dump_failed_0: · 3 unmodified lines
24312451 qla2xxx_dump_post_process(base_vha, rval);
24322452
24332453 qla83xx_fw_dump_failed:
2454+#ifndef __CHECKER__
24342455 if (!hardware_locked)
24352456 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2457+#else
2458+ ;
2459+#endif
24362460 }
24372461
24382462 /****************************************************************************/
drivers/scsi/qla2xxx/qla_def.h+10−5
@@ -3061,6 +3061,7 @@ struct qla_hw_data { · 3060 unmodified lines
30613061 #define PCI_DEVICE_ID_QLOGIC_ISP2031 0x2031
30623062 #define PCI_DEVICE_ID_QLOGIC_ISP2071 0x2071
30633063 #define PCI_DEVICE_ID_QLOGIC_ISP2271 0x2271
3064+#define PCI_DEVICE_ID_QLOGIC_ISP2261 0x2261
30643065
30653066 uint32_t device_type;
30663067 #define DT_ISP2100 BIT_0
@@ -3084,7 +3085,8 @@ struct qla_hw_data { · 17 unmodified lines
30843085 #define DT_ISP8044 BIT_18
30853086 #define DT_ISP2071 BIT_19
30863087 #define DT_ISP2271 BIT_20
3087−#define DT_ISP_LAST (DT_ISP2271 << 1)
3088+#define DT_ISP2261 BIT_21
3089+#define DT_ISP_LAST (DT_ISP2261 << 1)
30883090
30893091 #define DT_T10_PI BIT_25
30903092 #define DT_IIDMA BIT_26
@@ -3116,6 +3118,7 @@ struct qla_hw_data { · 25 unmodified lines
31163118 #define IS_QLAFX00(ha) (DT_MASK(ha) & DT_ISPFX00)
31173119 #define IS_QLA2071(ha) (DT_MASK(ha) & DT_ISP2071)
31183120 #define IS_QLA2271(ha) (DT_MASK(ha) & DT_ISP2271)
3121+#define IS_QLA2261(ha) (DT_MASK(ha) & DT_ISP2261)
31193122
31203123 #define IS_QLA23XX(ha) (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA2322(ha) || \
31213124 IS_QLA6312(ha) || IS_QLA6322(ha))
@@ -3124,7 +3127,7 @@ struct qla_hw_data { · 2 unmodified lines
31243127 #define IS_QLA25XX(ha) (IS_QLA2532(ha))
31253128 #define IS_QLA83XX(ha) (IS_QLA2031(ha) || IS_QLA8031(ha))
31263129 #define IS_QLA84XX(ha) (IS_QLA8432(ha))
3127−#define IS_QLA27XX(ha) (IS_QLA2071(ha) || IS_QLA2271(ha))
3130+#define IS_QLA27XX(ha) (IS_QLA2071(ha) || IS_QLA2271(ha) || IS_QLA2261(ha))
31283131 #define IS_QLA24XX_TYPE(ha) (IS_QLA24XX(ha) || IS_QLA54XX(ha) || \
31293132 IS_QLA84XX(ha))
31303133 #define IS_CNA_CAPABLE(ha) (IS_QLA81XX(ha) || IS_QLA82XX(ha) || \
@@ -3166,6 +3169,7 @@ struct qla_hw_data { · 35 unmodified lines
31663169 #define IS_TGT_MODE_CAPABLE(ha) (ha->tgt.atio_q_length)
31673170 #define IS_SHADOW_REG_CAPABLE(ha) (IS_QLA27XX(ha))
31683171 #define IS_DPORT_CAPABLE(ha) (IS_QLA83XX(ha) || IS_QLA27XX(ha))
3172+#define IS_FAWWN_CAPABLE(ha) (IS_QLA83XX(ha) || IS_QLA27XX(ha))
31693173
31703174 /* HBA serial number */
31713175 uint8_t serial0;
@@ -3288,6 +3292,7 @@ struct qla_hw_data { · 116 unmodified lines
32883292 uint8_t mpi_version[3];
32893293 uint32_t mpi_capabilities;
32903294 uint8_t phy_version[3];
3295+ uint8_t pep_version[3];
32913296
32923297 /* Firmware dump template */
32933298 void *fw_dump_template;
@@ -3420,9 +3425,9 @@ struct qla_hw_data { · 126 unmodified lines
34203425 mempool_t *ctx_mempool;
34213426 #define FCP_CMND_DMA_POOL_SIZE 512
34223427
3423− unsigned long nx_pcibase; /* Base I/O address */
3424− uint8_t *nxdb_rd_ptr; /* Doorbell read pointer */
3425− unsigned long nxdb_wr_ptr; /* Door bell write pointer */
3428+ void __iomem *nx_pcibase; /* Base I/O address */
3429+ void __iomem *nxdb_rd_ptr; /* Doorbell read pointer */
3430+ void __iomem *nxdb_wr_ptr; /* Door bell write pointer */
34263431
34273432 uint32_t crb_win;
34283433 uint32_t curr_window;
drivers/scsi/qla2xxx/qla_gs.c+26−26
@@ -35,10 +35,10 @@ qla2x00_prep_ms_iocb(scsi_qla_host_t *vha, uint32_t req_size, uint32_t rsp_size) · 34 unmodified lines
3535 ms_pkt->entry_type = MS_IOCB_TYPE;
3636 ms_pkt->entry_count = 1;
3737 SET_TARGET_ID(ha, ms_pkt->loop_id, SIMPLE_NAME_SERVER);
38− ms_pkt->control_flags = __constant_cpu_to_le16(CF_READ | CF_HEAD_TAG);
38+ ms_pkt->control_flags = cpu_to_le16(CF_READ | CF_HEAD_TAG);
3939 ms_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
40− ms_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
41− ms_pkt->total_dsd_count = __constant_cpu_to_le16(2);
40+ ms_pkt->cmd_dsd_count = cpu_to_le16(1);
41+ ms_pkt->total_dsd_count = cpu_to_le16(2);
4242 ms_pkt->rsp_bytecount = cpu_to_le32(rsp_size);
4343 ms_pkt->req_bytecount = cpu_to_le32(req_size);
4444
@@ -74,10 +74,10 @@ qla24xx_prep_ms_iocb(scsi_qla_host_t *vha, uint32_t req_size, uint32_t rsp_size) · 29 unmodified lines
7474
7575 ct_pkt->entry_type = CT_IOCB_TYPE;
7676 ct_pkt->entry_count = 1;
77− ct_pkt->nport_handle = __constant_cpu_to_le16(NPH_SNS);
77+ ct_pkt->nport_handle = cpu_to_le16(NPH_SNS);
7878 ct_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
79− ct_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
80− ct_pkt->rsp_dsd_count = __constant_cpu_to_le16(1);
79+ ct_pkt->cmd_dsd_count = cpu_to_le16(1);
80+ ct_pkt->rsp_dsd_count = cpu_to_le16(1);
8181 ct_pkt->rsp_byte_count = cpu_to_le32(rsp_size);
8282 ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
8383
@@ -142,7 +142,7 @@ qla2x00_chk_ms_status(scsi_qla_host_t *vha, ms_iocb_entry_t *ms_pkt, · 58 unmodified lines
142142 case CS_DATA_UNDERRUN:
143143 case CS_DATA_OVERRUN: /* Overrun? */
144144 if (ct_rsp->header.response !=
145− __constant_cpu_to_be16(CT_ACCEPT_RESPONSE)) {
145+ cpu_to_be16(CT_ACCEPT_RESPONSE)) {
146146 ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x2077,
147147 "%s failed rejected request on port_id: %02x%02x%02x Compeltion status 0x%x, response 0x%x\n",
148148 routine, vha->d_id.b.domain,
@@ -1153,10 +1153,10 @@ qla2x00_prep_ms_fdmi_iocb(scsi_qla_host_t *vha, uint32_t req_size, · 1004 unmodified lines
11531153 ms_pkt->entry_type = MS_IOCB_TYPE;
11541154 ms_pkt->entry_count = 1;
11551155 SET_TARGET_ID(ha, ms_pkt->loop_id, vha->mgmt_svr_loop_id);
1156− ms_pkt->control_flags = __constant_cpu_to_le16(CF_READ | CF_HEAD_TAG);
1156+ ms_pkt->control_flags = cpu_to_le16(CF_READ | CF_HEAD_TAG);
11571157 ms_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
1158− ms_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
1159− ms_pkt->total_dsd_count = __constant_cpu_to_le16(2);
1158+ ms_pkt->cmd_dsd_count = cpu_to_le16(1);
1159+ ms_pkt->total_dsd_count = cpu_to_le16(2);
11601160 ms_pkt->rsp_bytecount = cpu_to_le32(rsp_size);
11611161 ms_pkt->req_bytecount = cpu_to_le32(req_size);
11621162
@@ -1193,8 +1193,8 @@ qla24xx_prep_ms_fdmi_iocb(scsi_qla_host_t *vha, uint32_t req_size, · 30 unmodified lines
11931193 ct_pkt->entry_count = 1;
11941194 ct_pkt->nport_handle = cpu_to_le16(vha->mgmt_svr_loop_id);
11951195 ct_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
1196− ct_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
1197− ct_pkt->rsp_dsd_count = __constant_cpu_to_le16(1);
1196+ ct_pkt->cmd_dsd_count = cpu_to_le16(1);
1197+ ct_pkt->rsp_dsd_count = cpu_to_le16(1);
11981198 ct_pkt->rsp_byte_count = cpu_to_le32(rsp_size);
11991199 ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
12001200
@@ -1281,19 +1281,19 @@ qla2x00_fdmi_rhba(scsi_qla_host_t *vha) · 80 unmodified lines
12811281
12821282 /* Prepare FDMI command arguments -- attribute block, attributes. */
12831283 memcpy(ct_req->req.rhba.hba_identifier, vha->port_name, WWN_SIZE);
1284− ct_req->req.rhba.entry_count = __constant_cpu_to_be32(1);
1284+ ct_req->req.rhba.entry_count = cpu_to_be32(1);
12851285 memcpy(ct_req->req.rhba.port_name, vha->port_name, WWN_SIZE);
12861286 size = 2 * WWN_SIZE + 4 + 4;
12871287
12881288 /* Attributes */
12891289 ct_req->req.rhba.attrs.count =
1290− __constant_cpu_to_be32(FDMI_HBA_ATTR_COUNT);
1290+ cpu_to_be32(FDMI_HBA_ATTR_COUNT);
12911291 entries = ct_req->req.rhba.hba_identifier;
12921292
12931293 /* Nodename. */
12941294 eiter = entries + size;
1295− eiter->type = __constant_cpu_to_be16(FDMI_HBA_NODE_NAME);
1296− eiter->len = __constant_cpu_to_be16(4 + WWN_SIZE);
1295+ eiter->type = cpu_to_be16(FDMI_HBA_NODE_NAME);
1296+ eiter->len = cpu_to_be16(4 + WWN_SIZE);
12971297 memcpy(eiter->a.node_name, vha->node_name, WWN_SIZE);
12981298 size += 4 + WWN_SIZE;
12991299
@@ -1302,7 +1302,7 @@ qla2x00_fdmi_rhba(scsi_qla_host_t *vha) · 2 unmodified lines
13021302
13031303 /* Manufacturer. */
13041304 eiter = entries + size;
1305− eiter->type = __constant_cpu_to_be16(FDMI_HBA_MANUFACTURER);
1305+ eiter->type = cpu_to_be16(FDMI_HBA_MANUFACTURER);
13061306 alen = strlen(QLA2XXX_MANUFACTURER);
13071307 snprintf(eiter->a.manufacturer, sizeof(eiter->a.manufacturer),
13081308 "%s", "QLogic Corporation");
@@ -1315,7 +1315,7 @@ qla2x00_fdmi_rhba(scsi_qla_host_t *vha) · 6 unmodified lines
13151315
13161316 /* Serial number. */
13171317 eiter = entries + size;
1318− eiter->type = __constant_cpu_to_be16(FDMI_HBA_SERIAL_NUMBER);
1318+ eiter->type = cpu_to_be16(FDMI_HBA_SERIAL_NUMBER);
13191319 if (IS_FWI2_CAPABLE(ha))
13201320 qla2xxx_get_vpd_field(vha, "SN", eiter->a.serial_num,
13211321 sizeof(eiter->a.serial_num));
@@ -1335,7 +1335,7 @@ qla2x00_fdmi_rhba(scsi_qla_host_t *vha) · 13 unmodified lines
13351335
13361336 /* Model name. */
13371337 eiter = entries + size;
1338− eiter->type = __constant_cpu_to_be16(FDMI_HBA_MODEL);
1338+ eiter->type = cpu_to_be16(FDMI_HBA_MODEL);
13391339 snprintf(eiter->a.model, sizeof(eiter->a.model),
13401340 "%s", ha->model_number);
13411341 alen = strlen(eiter->a.model);
@@ -1348,7 +1348,7 @@ qla2x00_fdmi_rhba(scsi_qla_host_t *vha) · 6 unmodified lines
13481348
13491349 /* Model description. */
13501350 eiter = entries + size;
1351− eiter->type = __constant_cpu_to_be16(FDMI_HBA_MODEL_DESCRIPTION);
1351+ eiter->type = cpu_to_be16(FDMI_HBA_MODEL_DESCRIPTION);
13521352 snprintf(eiter->a.model_desc, sizeof(eiter->a.model_desc),
13531353 "%s", ha->model_desc);
13541354 alen = strlen(eiter->a.model_desc);
@@ -1361,7 +1361,7 @@ qla2x00_fdmi_rhba(scsi_qla_host_t *vha) · 6 unmodified lines
13611361
13621362 /* Hardware version. */
13631363 eiter = entries + size;
1364− eiter->type = __constant_cpu_to_be16(FDMI_HBA_HARDWARE_VERSION);
1364+ eiter->type = cpu_to_be16(FDMI_HBA_HARDWARE_VERSION);
13651365 if (!IS_FWI2_CAPABLE(ha)) {
13661366 snprintf(eiter->a.hw_version, sizeof(eiter->a.hw_version),
13671367 "HW:%s", ha->adapter_id);
@@ -1385,7 +1385,7 @@ qla2x00_fdmi_rhba(scsi_qla_host_t *vha) · 17 unmodified lines
13851385
13861386 /* Driver version. */
13871387 eiter = entries + size;
1388− eiter->type = __constant_cpu_to_be16(FDMI_HBA_DRIVER_VERSION);
1388+ eiter->type = cpu_to_be16(FDMI_HBA_DRIVER_VERSION);
13891389 snprintf(eiter->a.driver_version, sizeof(eiter->a.driver_version),
13901390 "%s", qla2x00_version_str);
13911391 alen = strlen(eiter->a.driver_version);
@@ -1398,7 +1398,7 @@ qla2x00_fdmi_rhba(scsi_qla_host_t *vha) · 6 unmodified lines
13981398
13991399 /* Option ROM version. */
14001400 eiter = entries + size;
1401− eiter->type = __constant_cpu_to_be16(FDMI_HBA_OPTION_ROM_VERSION);
1401+ eiter->type = cpu_to_be16(FDMI_HBA_OPTION_ROM_VERSION);
14021402 snprintf(eiter->a.orom_version, sizeof(eiter->a.orom_version),
14031403 "%d.%02d", ha->bios_revision[1], ha->bios_revision[0]);
14041404 alen = strlen(eiter->a.orom_version);
@@ -1411,7 +1411,7 @@ qla2x00_fdmi_rhba(scsi_qla_host_t *vha) · 6 unmodified lines
14111411
14121412 /* Firmware version */
14131413 eiter = entries + size;
1414− eiter->type = __constant_cpu_to_be16(FDMI_HBA_FIRMWARE_VERSION);
1414+ eiter->type = cpu_to_be16(FDMI_HBA_FIRMWARE_VERSION);
14151415 ha->isp_ops->fw_version_str(vha, eiter->a.fw_version,
14161416 sizeof(eiter->a.fw_version));
14171417 alen = strlen(eiter->a.fw_version);
@@ -2484,8 +2484,8 @@ qla24xx_prep_ms_fm_iocb(scsi_qla_host_t *vha, uint32_t req_size, · 1066 unmodified lines
24842484 ct_pkt->entry_count = 1;
24852485 ct_pkt->nport_handle = cpu_to_le16(vha->mgmt_svr_loop_id);
24862486 ct_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
2487− ct_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
2488− ct_pkt->rsp_dsd_count = __constant_cpu_to_le16(1);
2487+ ct_pkt->cmd_dsd_count = cpu_to_le16(1);
2488+ ct_pkt->rsp_dsd_count = cpu_to_le16(1);
24892489 ct_pkt->rsp_byte_count = cpu_to_le32(rsp_size);
24902490 ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
24912491
drivers/scsi/qla2xxx/qla_init.c+79−83
@@ -1132,7 +1132,7 @@ qla24xx_reset_risc(scsi_qla_host_t *vha) · 1131 unmodified lines
11321132 unsigned long flags = 0;
11331133 struct qla_hw_data *ha = vha->hw;
11341134 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1135− uint32_t cnt, d2;
1135+ uint32_t cnt;
11361136 uint16_t wd;
11371137 static int abts_cnt; /* ISP abort retry counts */
11381138 int rval = QLA_SUCCESS;
@@ -1164,7 +1164,7 @@ qla24xx_reset_risc(scsi_qla_host_t *vha) · 25 unmodified lines
11641164 udelay(100);
11651165
11661166 /* Wait for firmware to complete NVRAM accesses. */
1167− d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1167+ RD_REG_WORD(&reg->mailbox0);
11681168 for (cnt = 10000; RD_REG_WORD(&reg->mailbox0) != 0 &&
11691169 rval == QLA_SUCCESS; cnt--) {
11701170 barrier();
@@ -1183,7 +1183,7 @@ qla24xx_reset_risc(scsi_qla_host_t *vha) · 12 unmodified lines
11831183 RD_REG_DWORD(&reg->mailbox0));
11841184
11851185 /* Wait for soft-reset to complete. */
1186− d2 = RD_REG_DWORD(&reg->ctrl_status);
1186+ RD_REG_DWORD(&reg->ctrl_status);
11871187 for (cnt = 0; cnt < 6000000; cnt++) {
11881188 barrier();
11891189 if ((RD_REG_DWORD(&reg->ctrl_status) &
@@ -1226,7 +1226,7 @@ qla24xx_reset_risc(scsi_qla_host_t *vha) · 36 unmodified lines
12261226 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
12271227 RD_REG_DWORD(&reg->hccr);
12281228
1229− d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1229+ RD_REG_WORD(&reg->mailbox0);
12301230 for (cnt = 6000000; RD_REG_WORD(&reg->mailbox0) != 0 &&
12311231 rval == QLA_SUCCESS; cnt--) {
12321232 barrier();
@@ -1277,16 +1277,19 @@ qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data) · 44 unmodified lines
12771277 static void
12781278 qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
12791279 {
1280− struct qla_hw_data *ha = vha->hw;
12811280 uint32_t wd32 = 0;
12821281 uint delta_msec = 100;
12831282 uint elapsed_msec = 0;
12841283 uint timeout_msec;
12851284 ulong n;
12861285
1287− if (!IS_QLA25XX(ha) && !IS_QLA2031(ha))
1286+ if (vha->hw->pdev->subsystem_device != 0x0175 &&
1287+ vha->hw->pdev->subsystem_device != 0x0240)
12881288 return;
12891289
1290+ WRT_REG_DWORD(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
1291+ udelay(100);
1292+
12901293 attempt:
12911294 timeout_msec = TIMEOUT_SEMAPHORE;
12921295 n = timeout_msec / delta_msec;
@@ -1690,7 +1693,7 @@ allocate: · 397 unmodified lines
16901693 ha->fw_dump->signature[1] = 'L';
16911694 ha->fw_dump->signature[2] = 'G';
16921695 ha->fw_dump->signature[3] = 'C';
1693− ha->fw_dump->version = __constant_htonl(1);
1696+ ha->fw_dump->version = htonl(1);
16941697
16951698 ha->fw_dump->fixed_size = htonl(fixed_size);
16961699 ha->fw_dump->mem_size = htonl(mem_size);
@@ -2070,8 +2073,8 @@ qla2x00_config_rings(struct scsi_qla_host *vha) · 373 unmodified lines
20702073 struct rsp_que *rsp = ha->rsp_q_map[0];
20712074
20722075 /* Setup ring parameters in initialization control block. */
2073− ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
2074− ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
2076+ ha->init_cb->request_q_outpointer = cpu_to_le16(0);
2077+ ha->init_cb->response_q_inpointer = cpu_to_le16(0);
20752078 ha->init_cb->request_q_length = cpu_to_le16(req->length);
20762079 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
20772080 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
@@ -2090,7 +2093,7 @@ void · 12 unmodified lines
20902093 qla24xx_config_rings(struct scsi_qla_host *vha)
20912094 {
20922095 struct qla_hw_data *ha = vha->hw;
2093− device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
2096+ device_reg_t *reg = ISP_QUE_REG(ha, 0);
20942097 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
20952098 struct qla_msix_entry *msix;
20962099 struct init_cb_24xx *icb;
@@ -2100,8 +2103,8 @@ qla24xx_config_rings(struct scsi_qla_host *vha) · 3 unmodified lines
21002103
21012104 /* Setup ring parameters in initialization control block. */
21022105 icb = (struct init_cb_24xx *)ha->init_cb;
2103− icb->request_q_outpointer = __constant_cpu_to_le16(0);
2104− icb->response_q_inpointer = __constant_cpu_to_le16(0);
2106+ icb->request_q_outpointer = cpu_to_le16(0);
2107+ icb->response_q_inpointer = cpu_to_le16(0);
21052108 icb->request_q_length = cpu_to_le16(req->length);
21062109 icb->response_q_length = cpu_to_le16(rsp->length);
21072110 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
@@ -2110,18 +2113,17 @@ qla24xx_config_rings(struct scsi_qla_host *vha) · 2 unmodified lines
21102113 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
21112114
21122115 /* Setup ATIO queue dma pointers for target mode */
2113− icb->atio_q_inpointer = __constant_cpu_to_le16(0);
2116+ icb->atio_q_inpointer = cpu_to_le16(0);
21142117 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
21152118 icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma));
21162119 icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma));
21172120
21182121 if (IS_SHADOW_REG_CAPABLE(ha))
2119− icb->firmware_options_2 |=
2120− __constant_cpu_to_le32(BIT_30|BIT_29);
2122+ icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
21212123
21222124 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
2123− icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
2124− icb->rid = __constant_cpu_to_le16(rid);
2125+ icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
2126+ icb->rid = cpu_to_le16(rid);
21252127 if (ha->flags.msix_enabled) {
21262128 msix = &ha->msix_entries[1];
21272129 ql_dbg(ql_dbg_init, vha, 0x00fd,
@@ -2131,26 +2133,22 @@ qla24xx_config_rings(struct scsi_qla_host *vha) · 3 unmodified lines
21312133 }
21322134 /* Use alternate PCI bus number */
21332135 if (MSB(rid))
2134− icb->firmware_options_2 |=
2135− __constant_cpu_to_le32(BIT_19);
2136+ icb->firmware_options_2 |= cpu_to_le32(BIT_19);
21362137 /* Use alternate PCI devfn */
21372138 if (LSB(rid))
2138− icb->firmware_options_2 |=
2139− __constant_cpu_to_le32(BIT_18);
2139+ icb->firmware_options_2 |= cpu_to_le32(BIT_18);
21402140
21412141 /* Use Disable MSIX Handshake mode for capable adapters */
21422142 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
21432143 (ha->flags.msix_enabled)) {
2144− icb->firmware_options_2 &=
2145− __constant_cpu_to_le32(~BIT_22);
2144+ icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
21462145 ha->flags.disable_msix_handshake = 1;
21472146 ql_dbg(ql_dbg_init, vha, 0x00fe,
21482147 "MSIX Handshake Disable Mode turned on.\n");
21492148 } else {
2150− icb->firmware_options_2 |=
2151− __constant_cpu_to_le32(BIT_22);
2149+ icb->firmware_options_2 |= cpu_to_le32(BIT_22);
21522150 }
2153− icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
2151+ icb->firmware_options_2 |= cpu_to_le32(BIT_23);
21542152
21552153 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
21562154 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
@@ -2248,7 +2246,7 @@ qla2x00_init_rings(scsi_qla_host_t *vha) · 91 unmodified lines
22482246 }
22492247
22502248 if (IS_FWI2_CAPABLE(ha)) {
2251− mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
2249+ mid_init_cb->options = cpu_to_le16(BIT_1);
22522250 mid_init_cb->init_cb.execution_throttle =
22532251 cpu_to_le16(ha->fw_xcb_count);
22542252 /* D-Port Status */
@@ -2677,8 +2675,8 @@ qla2x00_nvram_config(scsi_qla_host_t *vha) · 422 unmodified lines
26772675 nv->frame_payload_size = 1024;
26782676 }
26792677
2680− nv->max_iocb_allocation = __constant_cpu_to_le16(256);
2681− nv->execution_throttle = __constant_cpu_to_le16(16);
2678+ nv->max_iocb_allocation = cpu_to_le16(256);
2679+ nv->execution_throttle = cpu_to_le16(16);
26822680 nv->retry_count = 8;
26832681 nv->retry_delay = 1;
26842682
@@ -2696,7 +2694,7 @@ qla2x00_nvram_config(scsi_qla_host_t *vha) · 11 unmodified lines
26962694 nv->host_p[1] = BIT_2;
26972695 nv->reset_delay = 5;
26982696 nv->port_down_retry_count = 8;
2699− nv->max_luns_per_target = __constant_cpu_to_le16(8);
2697+ nv->max_luns_per_target = cpu_to_le16(8);
27002698 nv->link_down_timeout = 60;
27012699
27022700 rval = 1;
@@ -2824,7 +2822,7 @@ qla2x00_nvram_config(scsi_qla_host_t *vha) · 121 unmodified lines
28242822 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
28252823 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
28262824
2827− icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
2825+ icb->execution_throttle = cpu_to_le16(0xFFFF);
28282826
28292827 ha->retry_count = nv->retry_count;
28302828
@@ -2876,10 +2874,10 @@ qla2x00_nvram_config(scsi_qla_host_t *vha) · 45 unmodified lines
28762874 if (ql2xloginretrycount)
28772875 ha->login_retry_count = ql2xloginretrycount;
28782876
2879− icb->lun_enables = __constant_cpu_to_le16(0);
2877+ icb->lun_enables = cpu_to_le16(0);
28802878 icb->command_resource_count = 0;
28812879 icb->immediate_notify_resource_count = 0;
2882− icb->timeout = __constant_cpu_to_le16(0);
2880+ icb->timeout = cpu_to_le16(0);
28832881
28842882 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
28852883 /* Enable RIO */
@@ -3958,12 +3956,10 @@ qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport, · 1072 unmodified lines
39583956 uint16_t *next_loopid)
39593957 {
39603958 int rval;
3961− int retry;
39623959 uint8_t opts;
39633960 struct qla_hw_data *ha = vha->hw;
39643961
39653962 rval = QLA_SUCCESS;
3966− retry = 0;
39673963
39683964 if (IS_ALOGIO_CAPABLE(ha)) {
39693965 if (fcport->flags & FCF_ASYNC_SENT)
@@ -5117,7 +5113,7 @@ qla24xx_nvram_config(scsi_qla_host_t *vha) · 1147 unmodified lines
51175113 /* Bad NVRAM data, set defaults parameters. */
51185114 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
51195115 || nv->id[3] != ' ' ||
5120− nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
5116+ nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
51215117 /* Reset NVRAM data. */
51225118 ql_log(ql_log_warn, vha, 0x006b,
51235119 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
@@ -5130,12 +5126,12 @@ qla24xx_nvram_config(scsi_qla_host_t *vha) · 6 unmodified lines
51305126 * Set default initialization control block.
51315127 */
51325128 memset(nv, 0, ha->nvram_size);
5133− nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
5134− nv->version = __constant_cpu_to_le16(ICB_VERSION);
5129+ nv->nvram_version = cpu_to_le16(ICB_VERSION);
5130+ nv->version = cpu_to_le16(ICB_VERSION);
51355131 nv->frame_payload_size = 2048;
5136− nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5137− nv->exchange_count = __constant_cpu_to_le16(0);
5138− nv->hard_address = __constant_cpu_to_le16(124);
5132+ nv->execution_throttle = cpu_to_le16(0xFFFF);
5133+ nv->exchange_count = cpu_to_le16(0);
5134+ nv->hard_address = cpu_to_le16(124);
51395135 nv->port_name[0] = 0x21;
51405136 nv->port_name[1] = 0x00 + ha->port_no + 1;
51415137 nv->port_name[2] = 0x00;
@@ -5153,29 +5149,29 @@ qla24xx_nvram_config(scsi_qla_host_t *vha) · 11 unmodified lines
51535149 nv->node_name[6] = 0x55;
51545150 nv->node_name[7] = 0x86;
51555151 qla24xx_nvram_wwn_from_ofw(vha, nv);
5156− nv->login_retry_count = __constant_cpu_to_le16(8);
5157− nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
5158− nv->login_timeout = __constant_cpu_to_le16(0);
5152+ nv->login_retry_count = cpu_to_le16(8);
5153+ nv->interrupt_delay_timer = cpu_to_le16(0);
5154+ nv->login_timeout = cpu_to_le16(0);
51595155 nv->firmware_options_1 =
5160− __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
5161− nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
5162− nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
5163− nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
5164− nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
5165− nv->efi_parameters = __constant_cpu_to_le32(0);
5156+ cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
5157+ nv->firmware_options_2 = cpu_to_le32(2 << 4);
5158+ nv->firmware_options_2 |= cpu_to_le32(BIT_12);
5159+ nv->firmware_options_3 = cpu_to_le32(2 << 13);
5160+ nv->host_p = cpu_to_le32(BIT_11|BIT_10);
5161+ nv->efi_parameters = cpu_to_le32(0);
51665162 nv->reset_delay = 5;
5167− nv->max_luns_per_target = __constant_cpu_to_le16(128);
5168− nv->port_down_retry_count = __constant_cpu_to_le16(30);
5169− nv->link_down_timeout = __constant_cpu_to_le16(30);
5163+ nv->max_luns_per_target = cpu_to_le16(128);
5164+ nv->port_down_retry_count = cpu_to_le16(30);
5165+ nv->link_down_timeout = cpu_to_le16(30);
51705166
51715167 rval = 1;
51725168 }
51735169
51745170 if (!qla_ini_mode_enabled(vha)) {
51755171 /* Don't enable full login after initial LIP */
5176− nv->firmware_options_1 &= __constant_cpu_to_le32(~BIT_13);
5172+ nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
51775173 /* Don't enable LIP full login for initiator */
5178− nv->host_p &= __constant_cpu_to_le32(~BIT_10);
5174+ nv->host_p &= cpu_to_le32(~BIT_10);
51795175 }
51805176
51815177 qlt_24xx_config_nvram_stage1(vha, nv);
@@ -5209,14 +5205,14 @@ qla24xx_nvram_config(scsi_qla_host_t *vha) · 27 unmodified lines
52095205
52105206 qlt_24xx_config_nvram_stage2(vha, icb);
52115207
5212− if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
5208+ if (nv->host_p & cpu_to_le32(BIT_15)) {
52135209 /* Use alternate WWN? */
52145210 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
52155211 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
52165212 }
52175213
52185214 /* Prepare nodename */
5219− if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
5215+ if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
52205216 /*
52215217 * Firmware will apply the following mask if the nodename was
52225218 * not provided.
@@ -5248,7 +5244,7 @@ qla24xx_nvram_config(scsi_qla_host_t *vha) · 25 unmodified lines
52485244 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
52495245 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
52505246
5251− icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5247+ icb->execution_throttle = cpu_to_le16(0xFFFF);
52525248
52535249 ha->retry_count = le16_to_cpu(nv->login_retry_count);
52545250
@@ -5256,7 +5252,7 @@ qla24xx_nvram_config(scsi_qla_host_t *vha) · 1 unmodified line
52565252 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
52575253 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
52585254 if (le16_to_cpu(nv->login_timeout) < 4)
5259− nv->login_timeout = __constant_cpu_to_le16(4);
5255+ nv->login_timeout = cpu_to_le16(4);
52605256 ha->login_timeout = le16_to_cpu(nv->login_timeout);
52615257 icb->login_timeout = nv->login_timeout;
52625258
@@ -5307,7 +5303,7 @@ qla24xx_nvram_config(scsi_qla_host_t *vha) · 44 unmodified lines
53075303 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
53085304 le16_to_cpu(icb->interrupt_delay_timer): 2;
53095305 }
5310− icb->firmware_options_2 &= __constant_cpu_to_le32(
5306+ icb->firmware_options_2 &= cpu_to_le32(
53115307 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
53125308 vha->flags.process_response_queue = 0;
53135309 if (ha->zio_mode != QLA_ZIO_DISABLED) {
@@ -6063,7 +6059,7 @@ qla81xx_nvram_config(scsi_qla_host_t *vha) · 749 unmodified lines
60636059 /* Bad NVRAM data, set defaults parameters. */
60646060 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
60656061 || nv->id[3] != ' ' ||
6066− nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
6062+ nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
60676063 /* Reset NVRAM data. */
60686064 ql_log(ql_log_info, vha, 0x0073,
60696065 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
@@ -6077,11 +6073,11 @@ qla81xx_nvram_config(scsi_qla_host_t *vha) · 7 unmodified lines
60776073 * Set default initialization control block.
60786074 */
60796075 memset(nv, 0, ha->nvram_size);
6080− nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
6081− nv->version = __constant_cpu_to_le16(ICB_VERSION);
6076+ nv->nvram_version = cpu_to_le16(ICB_VERSION);
6077+ nv->version = cpu_to_le16(ICB_VERSION);
60826078 nv->frame_payload_size = 2048;
6083− nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
6084− nv->exchange_count = __constant_cpu_to_le16(0);
6079+ nv->execution_throttle = cpu_to_le16(0xFFFF);
6080+ nv->exchange_count = cpu_to_le16(0);
60856081 nv->port_name[0] = 0x21;
60866082 nv->port_name[1] = 0x00 + ha->port_no + 1;
60876083 nv->port_name[2] = 0x00;
@@ -6098,20 +6094,20 @@ qla81xx_nvram_config(scsi_qla_host_t *vha) · 10 unmodified lines
60986094 nv->node_name[5] = 0x1c;
60996095 nv->node_name[6] = 0x55;
61006096 nv->node_name[7] = 0x86;
6101− nv->login_retry_count = __constant_cpu_to_le16(8);
6102− nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
6103− nv->login_timeout = __constant_cpu_to_le16(0);
6097+ nv->login_retry_count = cpu_to_le16(8);
6098+ nv->interrupt_delay_timer = cpu_to_le16(0);
6099+ nv->login_timeout = cpu_to_le16(0);
61046100 nv->firmware_options_1 =
6105− __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
6106− nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
6107− nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
6108− nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
6109− nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
6110− nv->efi_parameters = __constant_cpu_to_le32(0);
6101+ cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
6102+ nv->firmware_options_2 = cpu_to_le32(2 << 4);
6103+ nv->firmware_options_2 |= cpu_to_le32(BIT_12);
6104+ nv->firmware_options_3 = cpu_to_le32(2 << 13);
6105+ nv->host_p = cpu_to_le32(BIT_11|BIT_10);
6106+ nv->efi_parameters = cpu_to_le32(0);
61116107 nv->reset_delay = 5;
6112− nv->max_luns_per_target = __constant_cpu_to_le16(128);
6113− nv->port_down_retry_count = __constant_cpu_to_le16(30);
6114− nv->link_down_timeout = __constant_cpu_to_le16(180);
6108+ nv->max_luns_per_target = cpu_to_le16(128);
6109+ nv->port_down_retry_count = cpu_to_le16(30);
6110+ nv->link_down_timeout = cpu_to_le16(180);
61156111 nv->enode_mac[0] = 0x00;
61166112 nv->enode_mac[1] = 0xC0;
61176113 nv->enode_mac[2] = 0xDD;
@@ -6170,13 +6166,13 @@ qla81xx_nvram_config(scsi_qla_host_t *vha) · 52 unmodified lines
61706166 qlt_81xx_config_nvram_stage2(vha, icb);
61716167
61726168 /* Use alternate WWN? */
6173− if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
6169+ if (nv->host_p & cpu_to_le32(BIT_15)) {
61746170 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
61756171 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
61766172 }
61776173
61786174 /* Prepare nodename */
6179− if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
6175+ if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
61806176 /*
61816177 * Firmware will apply the following mask if the nodename was
61826178 * not provided.
@@ -6205,7 +6201,7 @@ qla81xx_nvram_config(scsi_qla_host_t *vha) · 22 unmodified lines
62056201 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
62066202 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
62076203
6208− icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
6204+ icb->execution_throttle = cpu_to_le16(0xFFFF);
62096205
62106206 ha->retry_count = le16_to_cpu(nv->login_retry_count);
62116207
@@ -6213,7 +6209,7 @@ qla81xx_nvram_config(scsi_qla_host_t *vha) · 1 unmodified line
62136209 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
62146210 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
62156211 if (le16_to_cpu(nv->login_timeout) < 4)
6216− nv->login_timeout = __constant_cpu_to_le16(4);
6212+ nv->login_timeout = cpu_to_le16(4);
62176213 ha->login_timeout = le16_to_cpu(nv->login_timeout);
62186214 icb->login_timeout = nv->login_timeout;
62196215
@@ -6259,7 +6255,7 @@ qla81xx_nvram_config(scsi_qla_host_t *vha) · 39 unmodified lines
62596255
62606256 /* if not running MSI-X we need handshaking on interrupts */
62616257 if (!vha->hw->flags.msix_enabled && (IS_QLA83XX(ha) || IS_QLA27XX(ha)))
6262− icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_22);
6258+ icb->firmware_options_2 |= cpu_to_le32(BIT_22);
62636259
62646260 /* Enable ZIO. */
62656261 if (!vha->flags.init_done) {
@@ -6268,7 +6264,7 @@ qla81xx_nvram_config(scsi_qla_host_t *vha) · 2 unmodified lines
62686264 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
62696265 le16_to_cpu(icb->interrupt_delay_timer): 2;
62706266 }
6271− icb->firmware_options_2 &= __constant_cpu_to_le32(
6267+ icb->firmware_options_2 &= cpu_to_le32(
62726268 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
62736269 vha->flags.process_response_queue = 0;
62746270 if (ha->zio_mode != QLA_ZIO_DISABLED) {
drivers/scsi/qla2xxx/qla_iocb.c+49−83
@@ -108,8 +108,7 @@ qla2x00_prep_cont_type0_iocb(struct scsi_qla_host *vha) · 107 unmodified lines
108108 cont_pkt = (cont_entry_t *)req->ring_ptr;
109109
110110 /* Load packet defaults. */
111− *((uint32_t *)(&cont_pkt->entry_type)) =
112− __constant_cpu_to_le32(CONTINUE_TYPE);
111+ *((uint32_t *)(&cont_pkt->entry_type)) = cpu_to_le32(CONTINUE_TYPE);
113112
114113 return (cont_pkt);
115114 }
@@ -138,8 +137,8 @@ qla2x00_prep_cont_type1_iocb(scsi_qla_host_t *vha, struct req_que *req) · 22 unmodified lines
138137
139138 /* Load packet defaults. */
140139 *((uint32_t *)(&cont_pkt->entry_type)) = IS_QLAFX00(vha->hw) ?
141− __constant_cpu_to_le32(CONTINUE_A64_TYPE_FX00) :
142− __constant_cpu_to_le32(CONTINUE_A64_TYPE);
140+ cpu_to_le32(CONTINUE_A64_TYPE_FX00) :
141+ cpu_to_le32(CONTINUE_A64_TYPE);
143142
144143 return (cont_pkt);
145144 }
@@ -204,11 +203,11 @@ void qla2x00_build_scsi_iocbs_32(srb_t *sp, cmd_entry_t *cmd_pkt, · 58 unmodified lines
204203
205204 /* Update entry type to indicate Command Type 2 IOCB */
206205 *((uint32_t *)(&cmd_pkt->entry_type)) =
207− __constant_cpu_to_le32(COMMAND_TYPE);
206+ cpu_to_le32(COMMAND_TYPE);
208207
209208 /* No data transfer */
210209 if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) {
211− cmd_pkt->byte_count = __constant_cpu_to_le32(0);
210+ cmd_pkt->byte_count = cpu_to_le32(0);
212211 return;
213212 }
214213
@@ -261,12 +260,11 @@ void qla2x00_build_scsi_iocbs_64(srb_t *sp, cmd_entry_t *cmd_pkt, · 46 unmodified lines
261260 cmd = GET_CMD_SP(sp);
262261
263262 /* Update entry type to indicate Command Type 3 IOCB */
264− *((uint32_t *)(&cmd_pkt->entry_type)) =
265− __constant_cpu_to_le32(COMMAND_A64_TYPE);
263+ *((uint32_t *)(&cmd_pkt->entry_type)) = cpu_to_le32(COMMAND_A64_TYPE);
266264
267265 /* No data transfer */
268266 if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) {
269− cmd_pkt->byte_count = __constant_cpu_to_le32(0);
267+ cmd_pkt->byte_count = cpu_to_le32(0);
270268 return;
271269 }
272270
@@ -310,7 +308,7 @@ void qla2x00_build_scsi_iocbs_64(srb_t *sp, cmd_entry_t *cmd_pkt, · 37 unmodified lines
310308 int
311309 qla2x00_start_scsi(srb_t *sp)
312310 {
313− int ret, nseg;
311+ int nseg;
314312 unsigned long flags;
315313 scsi_qla_host_t *vha;
316314 struct scsi_cmnd *cmd;
@@ -327,7 +325,6 @@ qla2x00_start_scsi(srb_t *sp) · 10 unmodified lines
327325 struct rsp_que *rsp;
328326
329327 /* Setup device pointers. */
330− ret = 0;
331328 vha = sp->fcport->vha;
332329 ha = vha->hw;
333330 reg = &ha->iobase->isp;
@@ -403,7 +400,7 @@ qla2x00_start_scsi(srb_t *sp) · 69 unmodified lines
403400 /* Set target ID and LUN number*/
404401 SET_TARGET_ID(ha, cmd_pkt->target, sp->fcport->loop_id);
405402 cmd_pkt->lun = cpu_to_le16(cmd->device->lun);
406− cmd_pkt->control_flags = __constant_cpu_to_le16(CF_SIMPLE_TAG);
403+ cmd_pkt->control_flags = cpu_to_le16(CF_SIMPLE_TAG);
407404
408405 /* Load SCSI command packet. */
409406 memcpy(cmd_pkt->scsi_cdb, cmd->cmnd, cmd->cmd_len);
@@ -454,7 +451,7 @@ void · 44 unmodified lines
454451 qla2x00_start_iocbs(struct scsi_qla_host *vha, struct req_que *req)
455452 {
456453 struct qla_hw_data *ha = vha->hw;
457− device_reg_t __iomem *reg = ISP_QUE_REG(ha, req->id);
454+ device_reg_t *reg = ISP_QUE_REG(ha, req->id);
458455
459456 if (IS_P3P_TYPE(ha)) {
460457 qla82xx_start_iocbs(vha);
@@ -597,12 +594,11 @@ qla24xx_build_scsi_type_6_iocbs(srb_t *sp, struct cmd_type_6 *cmd_pkt, · 136 unmodified lines
597594 cmd = GET_CMD_SP(sp);
598595
599596 /* Update entry type to indicate Command Type 3 IOCB */
600− *((uint32_t *)(&cmd_pkt->entry_type)) =
601− __constant_cpu_to_le32(COMMAND_TYPE_6);
597+ *((uint32_t *)(&cmd_pkt->entry_type)) = cpu_to_le32(COMMAND_TYPE_6);
602598
603599 /* No data transfer */
604600 if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) {
605− cmd_pkt->byte_count = __constant_cpu_to_le32(0);
601+ cmd_pkt->byte_count = cpu_to_le32(0);
606602 return 0;
607603 }
608604
@@ -611,13 +607,11 @@ qla24xx_build_scsi_type_6_iocbs(srb_t *sp, struct cmd_type_6 *cmd_pkt, · 2 unmodified lines
611607
612608 /* Set transfer direction */
613609 if (cmd->sc_data_direction == DMA_TO_DEVICE) {
614− cmd_pkt->control_flags =
615− __constant_cpu_to_le16(CF_WRITE_DATA);
610+ cmd_pkt->control_flags = cpu_to_le16(CF_WRITE_DATA);
616611 vha->qla_stats.output_bytes += scsi_bufflen(cmd);
617612 vha->qla_stats.output_requests++;
618613 } else if (cmd->sc_data_direction == DMA_FROM_DEVICE) {
619− cmd_pkt->control_flags =
620− __constant_cpu_to_le16(CF_READ_DATA);
614+ cmd_pkt->control_flags = cpu_to_le16(CF_READ_DATA);
621615 vha->qla_stats.input_bytes += scsi_bufflen(cmd);
622616 vha->qla_stats.input_requests++;
623617 }
@@ -680,7 +674,7 @@ qla24xx_build_scsi_type_6_iocbs(srb_t *sp, struct cmd_type_6 *cmd_pkt, · 56 unmodified lines
680674 *
681675 * Returns the number of dsd list needed to store @dsds.
682676 */
683−inline uint16_t
677+static inline uint16_t
684678 qla24xx_calc_dsd_lists(uint16_t dsds)
685679 {
686680 uint16_t dsd_lists = 0;
@@ -700,7 +694,7 @@ qla24xx_calc_dsd_lists(uint16_t dsds) · 13 unmodified lines
700694 * @cmd_pkt: Command type 3 IOCB
701695 * @tot_dsds: Total number of segments to transfer
702696 */
703−inline void
697+static inline void
704698 qla24xx_build_scsi_iocbs(srb_t *sp, struct cmd_type_7 *cmd_pkt,
705699 uint16_t tot_dsds)
706700 {
@@ -710,32 +704,27 @@ qla24xx_build_scsi_iocbs(srb_t *sp, struct cmd_type_7 *cmd_pkt, · 3 unmodified lines
710704 struct scsi_cmnd *cmd;
711705 struct scatterlist *sg;
712706 int i;
713− struct req_que *req;
714707
715708 cmd = GET_CMD_SP(sp);
716709
717710 /* Update entry type to indicate Command Type 3 IOCB */
718− *((uint32_t *)(&cmd_pkt->entry_type)) =
719− __constant_cpu_to_le32(COMMAND_TYPE_7);
711+ *((uint32_t *)(&cmd_pkt->entry_type)) = cpu_to_le32(COMMAND_TYPE_7);
720712
721713 /* No data transfer */
722714 if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) {
723− cmd_pkt->byte_count = __constant_cpu_to_le32(0);
715+ cmd_pkt->byte_count = cpu_to_le32(0);
724716 return;
725717 }
726718
727719 vha = sp->fcport->vha;
728− req = vha->req;
729720
730721 /* Set transfer direction */
731722 if (cmd->sc_data_direction == DMA_TO_DEVICE) {
732− cmd_pkt->task_mgmt_flags =
733− __constant_cpu_to_le16(TMF_WRITE_DATA);
723+ cmd_pkt->task_mgmt_flags = cpu_to_le16(TMF_WRITE_DATA);
734724 vha->qla_stats.output_bytes += scsi_bufflen(cmd);
735725 vha->qla_stats.output_requests++;
736726 } else if (cmd->sc_data_direction == DMA_FROM_DEVICE) {
737− cmd_pkt->task_mgmt_flags =
738− __constant_cpu_to_le16(TMF_READ_DATA);
727+ cmd_pkt->task_mgmt_flags = cpu_to_le16(TMF_READ_DATA);
739728 vha->qla_stats.input_bytes += scsi_bufflen(cmd);
740729 vha->qla_stats.input_requests++;
741730 }
@@ -809,7 +798,7 @@ qla24xx_set_t10dif_tags(srb_t *sp, struct fw_dif_context *pkt, · 67 unmodified lines
809798 * match LBA in CDB + N
810799 */
811800 case SCSI_PROT_DIF_TYPE2:
812− pkt->app_tag = __constant_cpu_to_le16(0);
801+ pkt->app_tag = cpu_to_le16(0);
813802 pkt->app_tag_mask[0] = 0x0;
814803 pkt->app_tag_mask[1] = 0x0;
815804
@@ -840,7 +829,7 @@ qla24xx_set_t10dif_tags(srb_t *sp, struct fw_dif_context *pkt, · 24 unmodified lines
840829 case SCSI_PROT_DIF_TYPE1:
841830 pkt->ref_tag = cpu_to_le32((uint32_t)
842831 (0xffffffff & scsi_get_lba(cmd)));
843− pkt->app_tag = __constant_cpu_to_le16(0);
832+ pkt->app_tag = cpu_to_le16(0);
844833 pkt->app_tag_mask[0] = 0x0;
845834 pkt->app_tag_mask[1] = 0x0;
846835
@@ -933,11 +922,9 @@ qla24xx_walk_and_build_sglist_no_difb(struct qla_hw_data *ha, srb_t *sp, · 86 unmodified lines
933922 dma_addr_t sle_dma;
934923 uint32_t sle_dma_len, tot_prot_dma_len = 0;
935924 struct scsi_cmnd *cmd;
936− struct scsi_qla_host *vha;
937925
938926 memset(&sgx, 0, sizeof(struct qla2_sgx));
939927 if (sp) {
940− vha = sp->fcport->vha;
941928 cmd = GET_CMD_SP(sp);
942929 prot_int = cmd->device->sector_size;
943930
@@ -947,7 +934,6 @@ qla24xx_walk_and_build_sglist_no_difb(struct qla_hw_data *ha, srb_t *sp, · 3 unmodified lines
947934
948935 sg_prot = scsi_prot_sglist(cmd);
949936 } else if (tc) {
950− vha = tc->vha;
951937 prot_int = tc->blk_sz;
952938 sgx.tot_bytes = tc->bufflen;
953939 sgx.cur_sg = tc->sg;
@@ -1047,15 +1033,12 @@ qla24xx_walk_and_build_sglist(struct qla_hw_data *ha, srb_t *sp, uint32_t *dsd, · 93 unmodified lines
10471033 int i;
10481034 uint16_t used_dsds = tot_dsds;
10491035 struct scsi_cmnd *cmd;
1050− struct scsi_qla_host *vha;
10511036
10521037 if (sp) {
10531038 cmd = GET_CMD_SP(sp);
10541039 sgl = scsi_sglist(cmd);
1055− vha = sp->fcport->vha;
10561040 } else if (tc) {
10571041 sgl = tc->sg;
1058− vha = tc->vha;
10591042 } else {
10601043 BUG();
10611044 return 1;
@@ -1231,7 +1214,6 @@ qla24xx_build_scsi_crc_2_iocbs(srb_t *sp, struct cmd_type_crc_2 *cmd_pkt, · 169 unmodified lines
12311214 uint32_t *cur_dsd, *fcp_dl;
12321215 scsi_qla_host_t *vha;
12331216 struct scsi_cmnd *cmd;
1234− int sgc;
12351217 uint32_t total_bytes = 0;
12361218 uint32_t data_bytes;
12371219 uint32_t dif_bytes;
@@ -1247,10 +1229,8 @@ qla24xx_build_scsi_crc_2_iocbs(srb_t *sp, struct cmd_type_crc_2 *cmd_pkt, · 9 unmodified lines
12471229
12481230 cmd = GET_CMD_SP(sp);
12491231
1250− sgc = 0;
12511232 /* Update entry type to indicate Command Type CRC_2 IOCB */
1252− *((uint32_t *)(&cmd_pkt->entry_type)) =
1253− __constant_cpu_to_le32(COMMAND_TYPE_CRC_2);
1233+ *((uint32_t *)(&cmd_pkt->entry_type)) = cpu_to_le32(COMMAND_TYPE_CRC_2);
12541234
12551235 vha = sp->fcport->vha;
12561236 ha = vha->hw;
@@ -1258,7 +1238,7 @@ qla24xx_build_scsi_crc_2_iocbs(srb_t *sp, struct cmd_type_crc_2 *cmd_pkt, · 1 unmodified line
12581238 /* No data transfer */
12591239 data_bytes = scsi_bufflen(cmd);
12601240 if (!data_bytes || cmd->sc_data_direction == DMA_NONE) {
1261− cmd_pkt->byte_count = __constant_cpu_to_le32(0);
1241+ cmd_pkt->byte_count = cpu_to_le32(0);
12621242 return QLA_SUCCESS;
12631243 }
12641244
@@ -1267,10 +1247,10 @@ qla24xx_build_scsi_crc_2_iocbs(srb_t *sp, struct cmd_type_crc_2 *cmd_pkt, · 2 unmodified lines
12671247 /* Set transfer direction */
12681248 if (cmd->sc_data_direction == DMA_TO_DEVICE) {
12691249 cmd_pkt->control_flags =
1270− __constant_cpu_to_le16(CF_WRITE_DATA);
1250+ cpu_to_le16(CF_WRITE_DATA);
12711251 } else if (cmd->sc_data_direction == DMA_FROM_DEVICE) {
12721252 cmd_pkt->control_flags =
1273− __constant_cpu_to_le16(CF_READ_DATA);
1253+ cpu_to_le16(CF_READ_DATA);
12741254 }
12751255
12761256 if ((scsi_get_prot_op(cmd) == SCSI_PROT_READ_INSERT) ||
@@ -1392,7 +1372,7 @@ qla24xx_build_scsi_crc_2_iocbs(srb_t *sp, struct cmd_type_crc_2 *cmd_pkt, · 115 unmodified lines
13921372 crc_ctx_pkt->blk_size = cpu_to_le16(blk_size);
13931373 crc_ctx_pkt->prot_opts = cpu_to_le16(fw_prot_opts);
13941374 crc_ctx_pkt->byte_count = cpu_to_le32(data_bytes);
1395− crc_ctx_pkt->guard_seed = __constant_cpu_to_le16(0);
1375+ crc_ctx_pkt->guard_seed = cpu_to_le16(0);
13961376 /* Fibre channel byte count */
13971377 cmd_pkt->byte_count = cpu_to_le32(total_bytes);
13981378 fcp_dl = (uint32_t *)(crc_ctx_pkt->fcp_cmnd.cdb + 16 +
@@ -1400,13 +1380,12 @@ qla24xx_build_scsi_crc_2_iocbs(srb_t *sp, struct cmd_type_crc_2 *cmd_pkt, · 1 unmodified line
14001380 *fcp_dl = htonl(total_bytes);
14011381
14021382 if (!data_bytes || cmd->sc_data_direction == DMA_NONE) {
1403− cmd_pkt->byte_count = __constant_cpu_to_le32(0);
1383+ cmd_pkt->byte_count = cpu_to_le32(0);
14041384 return QLA_SUCCESS;
14051385 }
14061386 /* Walks data segments */
14071387
1408− cmd_pkt->control_flags |=
1409− __constant_cpu_to_le16(CF_DATA_SEG_DESCR_ENABLE);
1388+ cmd_pkt->control_flags |= cpu_to_le16(CF_DATA_SEG_DESCR_ENABLE);
14101389
14111390 if (!bundling && tot_prot_dsds) {
14121391 if (qla24xx_walk_and_build_sglist_no_difb(ha, sp,
@@ -1418,8 +1397,7 @@ qla24xx_build_scsi_crc_2_iocbs(srb_t *sp, struct cmd_type_crc_2 *cmd_pkt, · 5 unmodified lines
14181397
14191398 if (bundling && tot_prot_dsds) {
14201399 /* Walks dif segments */
1421− cmd_pkt->control_flags |=
1422− __constant_cpu_to_le16(CF_DIF_SEG_DESCR_ENABLE);
1400+ cmd_pkt->control_flags |= cpu_to_le16(CF_DIF_SEG_DESCR_ENABLE);
14231401 cur_dsd = (uint32_t *) &crc_ctx_pkt->u.bundling.dif_address;
14241402 if (qla24xx_walk_and_build_prot_sglist(ha, sp, cur_dsd,
14251403 tot_prot_dsds, NULL))
@@ -1442,7 +1420,7 @@ crc_queuing_error: · 16 unmodified lines
14421420 int
14431421 qla24xx_start_scsi(srb_t *sp)
14441422 {
1445− int ret, nseg;
1423+ int nseg;
14461424 unsigned long flags;
14471425 uint32_t *clr_ptr;
14481426 uint32_t index;
@@ -1458,8 +1436,6 @@ qla24xx_start_scsi(srb_t *sp) · 9 unmodified lines
14581436 struct qla_hw_data *ha = vha->hw;
14591437
14601438 /* Setup device pointers. */
1461− ret = 0;
1462−
14631439 qla25xx_set_que(sp, &rsp);
14641440 req = vha->req;
14651441
@@ -1753,7 +1729,7 @@ qla24xx_dif_start_scsi(srb_t *sp) · 287 unmodified lines
17531729 cmd_pkt->entry_count = (uint8_t)req_cnt;
17541730 /* Specify response queue number where completion should happen */
17551731 cmd_pkt->entry_status = (uint8_t) rsp->id;
1756− cmd_pkt->timeout = __constant_cpu_to_le16(0);
1732+ cmd_pkt->timeout = cpu_to_le16(0);
17571733 wmb();
17581734
17591735 /* Adjust ring index. */
@@ -1819,7 +1795,7 @@ qla2x00_alloc_iocbs(scsi_qla_host_t *vha, srb_t *sp) · 59 unmodified lines
18191795 {
18201796 struct qla_hw_data *ha = vha->hw;
18211797 struct req_que *req = ha->req_q_map[0];
1822− device_reg_t __iomem *reg = ISP_QUE_REG(ha, req->id);
1798+ device_reg_t *reg = ISP_QUE_REG(ha, req->id);
18231799 uint32_t index, handle;
18241800 request_t *pkt;
18251801 uint16_t cnt, req_cnt;
@@ -2044,10 +2020,10 @@ qla24xx_els_iocb(srb_t *sp, struct els_entry_24xx *els_iocb) · 218 unmodified lines
20442020 els_iocb->entry_status = 0;
20452021 els_iocb->handle = sp->handle;
20462022 els_iocb->nport_handle = cpu_to_le16(sp->fcport->loop_id);
2047− els_iocb->tx_dsd_count = __constant_cpu_to_le16(bsg_job->request_payload.sg_cnt);
2023+ els_iocb->tx_dsd_count = cpu_to_le16(bsg_job->request_payload.sg_cnt);
20482024 els_iocb->vp_index = sp->fcport->vha->vp_idx;
20492025 els_iocb->sof_type = EST_SOFI3;
2050− els_iocb->rx_dsd_count = __constant_cpu_to_le16(bsg_job->reply_payload.sg_cnt);
2026+ els_iocb->rx_dsd_count = cpu_to_le16(bsg_job->reply_payload.sg_cnt);
20512027
20522028 els_iocb->opcode =
20532029 sp->type == SRB_ELS_CMD_RPT ?
@@ -2091,7 +2067,6 @@ qla2x00_ct_iocb(srb_t *sp, ms_iocb_entry_t *ct_iocb) · 37 unmodified lines
20912067 struct qla_hw_data *ha = vha->hw;
20922068 struct fc_bsg_job *bsg_job = sp->u.bsg_job;
20932069 int loop_iterartion = 0;
2094− int cont_iocb_prsnt = 0;
20952070 int entry_count = 1;
20962071
20972072 memset(ct_iocb, 0, sizeof(ms_iocb_entry_t));
@@ -2099,13 +2074,13 @@ qla2x00_ct_iocb(srb_t *sp, ms_iocb_entry_t *ct_iocb) · 1 unmodified line
20992074 ct_iocb->entry_status = 0;
21002075 ct_iocb->handle1 = sp->handle;
21012076 SET_TARGET_ID(ha, ct_iocb->loop_id, sp->fcport->loop_id);
2102− ct_iocb->status = __constant_cpu_to_le16(0);
2103− ct_iocb->control_flags = __constant_cpu_to_le16(0);
2077+ ct_iocb->status = cpu_to_le16(0);
2078+ ct_iocb->control_flags = cpu_to_le16(0);
21042079 ct_iocb->timeout = 0;
21052080 ct_iocb->cmd_dsd_count =
2106− __constant_cpu_to_le16(bsg_job->request_payload.sg_cnt);
2081+ cpu_to_le16(bsg_job->request_payload.sg_cnt);
21072082 ct_iocb->total_dsd_count =
2108− __constant_cpu_to_le16(bsg_job->request_payload.sg_cnt + 1);
2083+ cpu_to_le16(bsg_job->request_payload.sg_cnt + 1);
21092084 ct_iocb->req_bytecount =
21102085 cpu_to_le32(bsg_job->request_payload.payload_len);
21112086 ct_iocb->rsp_bytecount =
@@ -2142,7 +2117,6 @@ qla2x00_ct_iocb(srb_t *sp, ms_iocb_entry_t *ct_iocb) · 30 unmodified lines
21422117 vha->hw->req_q_map[0]);
21432118 cur_dsd = (uint32_t *) cont_pkt->dseg_0_address;
21442119 avail_dsds = 5;
2145− cont_iocb_prsnt = 1;
21462120 entry_count++;
21472121 }
21482122
@@ -2170,7 +2144,6 @@ qla24xx_ct_iocb(srb_t *sp, struct ct_entry_24xx *ct_iocb) · 21 unmodified lines
21702144 struct qla_hw_data *ha = vha->hw;
21712145 struct fc_bsg_job *bsg_job = sp->u.bsg_job;
21722146 int loop_iterartion = 0;
2173− int cont_iocb_prsnt = 0;
21742147 int entry_count = 1;
21752148
21762149 ct_iocb->entry_type = CT_IOCB_TYPE;
@@ -2180,13 +2153,13 @@ qla24xx_ct_iocb(srb_t *sp, struct ct_entry_24xx *ct_iocb) · 3 unmodified lines
21802153
21812154 ct_iocb->nport_handle = cpu_to_le16(sp->fcport->loop_id);
21822155 ct_iocb->vp_index = sp->fcport->vha->vp_idx;
2183− ct_iocb->comp_status = __constant_cpu_to_le16(0);
2156+ ct_iocb->comp_status = cpu_to_le16(0);
21842157
21852158 ct_iocb->cmd_dsd_count =
2186− __constant_cpu_to_le16(bsg_job->request_payload.sg_cnt);
2159+ cpu_to_le16(bsg_job->request_payload.sg_cnt);
21872160 ct_iocb->timeout = 0;
21882161 ct_iocb->rsp_dsd_count =
2189− __constant_cpu_to_le16(bsg_job->reply_payload.sg_cnt);
2162+ cpu_to_le16(bsg_job->reply_payload.sg_cnt);
21902163 ct_iocb->rsp_byte_count =
21912164 cpu_to_le32(bsg_job->reply_payload.payload_len);
21922165 ct_iocb->cmd_byte_count =
@@ -2217,7 +2190,6 @@ qla24xx_ct_iocb(srb_t *sp, struct ct_entry_24xx *ct_iocb) · 24 unmodified lines
22172190 ha->req_q_map[0]);
22182191 cur_dsd = (uint32_t *) cont_pkt->dseg_0_address;
22192192 avail_dsds = 5;
2220− cont_iocb_prsnt = 1;
22212193 entry_count++;
22222194 }
22232195
@@ -2240,7 +2212,7 @@ qla24xx_ct_iocb(srb_t *sp, struct ct_entry_24xx *ct_iocb) · 16 unmodified lines
22402212 int
22412213 qla82xx_start_scsi(srb_t *sp)
22422214 {
2243− int ret, nseg;
2215+ int nseg;
22442216 unsigned long flags;
22452217 struct scsi_cmnd *cmd;
22462218 uint32_t *clr_ptr;
@@ -2260,7 +2232,6 @@ qla82xx_start_scsi(srb_t *sp) · 13 unmodified lines
22602232 struct rsp_que *rsp = NULL;
22612233
22622234 /* Setup device pointers. */
2263− ret = 0;
22642235 reg = &ha->iobase->isp82;
22652236 cmd = GET_CMD_SP(sp);
22662237 req = vha->req;
@@ -2539,16 +2510,12 @@ sufficient_dsds: · 272 unmodified lines
25392510 /* write, read and verify logic */
25402511 dbval = dbval | (req->id << 8) | (req->ring_index << 16);
25412512 if (ql2xdbwr)
2542− qla82xx_wr_32(ha, ha->nxdb_wr_ptr, dbval);
2513+ qla82xx_wr_32(ha, (uintptr_t __force)ha->nxdb_wr_ptr, dbval);
25432514 else {
2544− WRT_REG_DWORD(
2545− (unsigned long __iomem *)ha->nxdb_wr_ptr,
2546− dbval);
2515+ WRT_REG_DWORD(ha->nxdb_wr_ptr, dbval);
25472516 wmb();
2548− while (RD_REG_DWORD((void __iomem *)ha->nxdb_rd_ptr) != dbval) {
2549− WRT_REG_DWORD(
2550− (unsigned long __iomem *)ha->nxdb_wr_ptr,
2551− dbval);
2517+ while (RD_REG_DWORD(ha->nxdb_rd_ptr) != dbval) {
2518+ WRT_REG_DWORD(ha->nxdb_wr_ptr, dbval);
25522519 wmb();
25532520 }
25542521 }
@@ -2682,7 +2649,7 @@ qla25xx_build_bidir_iocb(srb_t *sp, struct scsi_qla_host *vha, · 127 unmodified lines
26822649
26832650 /*Update entry type to indicate bidir command */
26842651 *((uint32_t *)(&cmd_pkt->entry_type)) =
2685− __constant_cpu_to_le32(COMMAND_BIDIRECTIONAL);
2652+ cpu_to_le32(COMMAND_BIDIRECTIONAL);
26862653
26872654 /* Set the transfer direction, in this set both flags
26882655 * Also set the BD_WRAP_BACK flag, firmware will take care
@@ -2690,8 +2657,7 @@ qla25xx_build_bidir_iocb(srb_t *sp, struct scsi_qla_host *vha, · 1 unmodified line
26902657 */
26912658 cmd_pkt->wr_dseg_count = cpu_to_le16(bsg_job->request_payload.sg_cnt);
26922659 cmd_pkt->rd_dseg_count = cpu_to_le16(bsg_job->reply_payload.sg_cnt);
2693− cmd_pkt->control_flags =
2694− __constant_cpu_to_le16(BD_WRITE_DATA | BD_READ_DATA |
2660+ cmd_pkt->control_flags = cpu_to_le16(BD_WRITE_DATA | BD_READ_DATA |
26952661 BD_WRAP_BACK);
26962662
26972663 req_data_len = rsp_data_len = bsg_job->request_payload.payload_len;
drivers/scsi/qla2xxx/qla_isr.c+48−22
@@ -116,7 +116,7 @@ bool · 115 unmodified lines
116116 qla2x00_check_reg32_for_disconnect(scsi_qla_host_t *vha, uint32_t reg)
117117 {
118118 /* Check for PCI disconnection */
119− if (reg == 0xffffffff) {
119+ if (reg == 0xffffffff && !pci_channel_offline(vha->hw->pdev)) {
120120 if (!test_and_set_bit(PFLG_DISCONNECTED, &vha->pci_flags) &&
121121 !test_bit(PFLG_DRIVER_REMOVING, &vha->pci_flags) &&
122122 !test_bit(PFLG_DRIVER_PROBING, &vha->pci_flags)) {
@@ -560,6 +560,17 @@ qla2x00_is_a_vp_did(scsi_qla_host_t *vha, uint32_t rscn_entry) · 437 unmodified lines
560560 return ret;
561561 }
562562
563+static inline fc_port_t *
564+qla2x00_find_fcport_by_loopid(scsi_qla_host_t *vha, uint16_t loop_id)
565+{
566+ fc_port_t *fcport;
567+
568+ list_for_each_entry(fcport, &vha->vp_fcports, list)
569+ if (fcport->loop_id == loop_id)
570+ return fcport;
571+ return NULL;
572+}
573+
563574 /**
564575 * qla2x00_async_event() - Process aynchronous events.
565576 * @ha: SCSI driver HA context
@@ -575,7 +586,7 @@ qla2x00_async_event(scsi_qla_host_t *vha, struct rsp_que *rsp, uint16_t *mb) · 9 unmodified lines
575586 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
576587 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
577588 struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82;
578− uint32_t rscn_entry, host_pid, tmp_pid;
589+ uint32_t rscn_entry, host_pid;
579590 unsigned long flags;
580591 fc_port_t *fcport = NULL;
581592
@@ -897,11 +908,29 @@ skip_rio: · 315 unmodified lines
897908 (mb[1] != 0xffff)) && vha->vp_idx != (mb[3] & 0xff))
898909 break;
899910
900− /* Global event -- port logout or port unavailable. */
901− if (mb[1] == 0xffff && mb[2] == 0x7) {
911+ if (mb[2] == 0x7) {
902912 ql_dbg(ql_dbg_async, vha, 0x5010,
903− "Port unavailable %04x %04x %04x.\n",
913+ "Port %s %04x %04x %04x.\n",
914+ mb[1] == 0xffff ? "unavailable" : "logout",
904915 mb[1], mb[2], mb[3]);
916+
917+ if (mb[1] == 0xffff)
918+ goto global_port_update;
919+
920+ /* Port logout */
921+ fcport = qla2x00_find_fcport_by_loopid(vha, mb[1]);
922+ if (!fcport)
923+ break;
924+ if (atomic_read(&fcport->state) != FCS_ONLINE)
925+ break;
926+ ql_dbg(ql_dbg_async, vha, 0x508a,
927+ "Marking port lost loopid=%04x portid=%06x.\n",
928+ fcport->loop_id, fcport->d_id.b24);
929+ qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
930+ break;
931+
932+global_port_update:
933+ /* Port unavailable. */
905934 ql_log(ql_log_warn, vha, 0x505e,
906935 "Link is offline.\n");
907936
@@ -998,7 +1027,6 @@ skip_rio: · 90 unmodified lines
9981027 list_for_each_entry(fcport, &vha->vp_fcports, list) {
9991028 if (atomic_read(&fcport->state) != FCS_ONLINE)
10001029 continue;
1001− tmp_pid = fcport->d_id.b24;
10021030 if (fcport->d_id.b24 == rscn_entry) {
10031031 qla2x00_mark_device_lost(vha, fcport, 0, 0);
10041032 break;
@@ -1565,7 +1593,7 @@ qla24xx_tm_iocb_entry(scsi_qla_host_t *vha, struct req_que *req, void *tsk) · 560 unmodified lines
15651593 "Async-%s error - hdl=%x entry-status(%x).\n",
15661594 type, sp->handle, sts->entry_status);
15671595 iocb->u.tmf.data = QLA_FUNCTION_FAILED;
1568− } else if (sts->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1596+ } else if (sts->comp_status != cpu_to_le16(CS_COMPLETE)) {
15691597 ql_log(ql_log_warn, fcport->vha, 0x5039,
15701598 "Async-%s error - hdl=%x completion status(%x).\n",
15711599 type, sp->handle, sts->comp_status);
@@ -2045,14 +2073,18 @@ qla2x00_status_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, void *pkt) · 473 unmodified lines
20452073 }
20462074
20472075 /* Validate handle. */
2048− if (handle < req->num_outstanding_cmds)
2076+ if (handle < req->num_outstanding_cmds) {
20492077 sp = req->outstanding_cmds[handle];
2050− else
2051− sp = NULL;
2052−
2053− if (sp == NULL) {
2078+ if (!sp) {
2079+ ql_dbg(ql_dbg_io, vha, 0x3075,
2080+ "%s(%ld): Already returned command for status handle (0x%x).\n",
2081+ __func__, vha->host_no, sts->handle);
2082+ return;
2083+ }
2084+ } else {
20542085 ql_dbg(ql_dbg_io, vha, 0x3017,
2055− "Invalid status handle (0x%x).\n", sts->handle);
2086+ "Invalid status handle, out of range (0x%x).\n",
2087+ sts->handle);
20562088
20572089 if (!test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
20582090 if (IS_P3P_TYPE(ha))
@@ -2339,12 +2371,12 @@ out: · 280 unmodified lines
23392371 ql_dbg(ql_dbg_io, fcport->vha, 0x3022,
23402372 "FCP command status: 0x%x-0x%x (0x%x) nexus=%ld:%d:%llu "
23412373 "portid=%02x%02x%02x oxid=0x%x cdb=%10phN len=0x%x "
2342− "rsp_info=0x%x resid=0x%x fw_resid=0x%x.\n",
2374+ "rsp_info=0x%x resid=0x%x fw_resid=0x%x sp=%p cp=%p.\n",
23432375 comp_status, scsi_status, res, vha->host_no,
23442376 cp->device->id, cp->device->lun, fcport->d_id.b.domain,
23452377 fcport->d_id.b.area, fcport->d_id.b.al_pa, ox_id,
23462378 cp->cmnd, scsi_bufflen(cp), rsp_info_len,
2347− resid_len, fw_resid_len);
2379+ resid_len, fw_resid_len, sp, cp);
23482380
23492381 if (rsp->status_srb == NULL)
23502382 sp->done(ha, sp, res);
@@ -2441,13 +2473,7 @@ qla2x00_error_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, sts_entry_t *pkt) · 90 unmodified lines
24412473 }
24422474 fatal:
24432475 ql_log(ql_log_warn, vha, 0x5030,
2444− "Error entry - invalid handle/queue.\n");
2445−
2446− if (IS_P3P_TYPE(ha))
2447− set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
2448− else
2449− set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2450− qla2xxx_wake_dpc(vha);
2476+ "Error entry - invalid handle/queue (%04x).\n", que);
24512477 }
24522478
24532479 /**
drivers/scsi/qla2xxx/qla_mbx.c+45−35
@@ -555,7 +555,9 @@ qla2x00_get_fw_version(scsi_qla_host_t *vha) · 554 unmodified lines
555555 if (IS_FWI2_CAPABLE(ha))
556556 mcp->in_mb |= MBX_17|MBX_16|MBX_15;
557557 if (IS_QLA27XX(ha))
558− mcp->in_mb |= MBX_21|MBX_20|MBX_19|MBX_18;
558+ mcp->in_mb |= MBX_23 | MBX_22 | MBX_21 | MBX_20 | MBX_19 |
559+ MBX_18 | MBX_14 | MBX_13 | MBX_11 | MBX_10 | MBX_9 | MBX_8;
560+
559561 mcp->flags = 0;
560562 mcp->tov = MBX_TOV_SECONDS;
561563 rval = qla2x00_mailbox_command(vha, mcp);
@@ -571,6 +573,7 @@ qla2x00_get_fw_version(scsi_qla_host_t *vha) · 9 unmodified lines
571573 ha->fw_memory_size = 0x1FFFF; /* Defaults to 128KB. */
572574 else
573575 ha->fw_memory_size = (mcp->mb[5] << 16) | mcp->mb[4];
576+
574577 if (IS_QLA81XX(vha->hw) || IS_QLA8031(vha->hw) || IS_QLA8044(ha)) {
575578 ha->mpi_version[0] = mcp->mb[10] & 0xff;
576579 ha->mpi_version[1] = mcp->mb[11] >> 8;
@@ -580,6 +583,7 @@ qla2x00_get_fw_version(scsi_qla_host_t *vha) · 3 unmodified lines
580583 ha->phy_version[1] = mcp->mb[9] >> 8;
581584 ha->phy_version[2] = mcp->mb[9] & 0xff;
582585 }
586+
583587 if (IS_FWI2_CAPABLE(ha)) {
584588 ha->fw_attributes_h = mcp->mb[15];
585589 ha->fw_attributes_ext[0] = mcp->mb[16];
@@ -591,7 +595,14 @@ qla2x00_get_fw_version(scsi_qla_host_t *vha) · 5 unmodified lines
591595 "%s: Ext_FwAttributes Upper: 0x%x, Lower: 0x%x.\n",
592596 __func__, mcp->mb[17], mcp->mb[16]);
593597 }
598+
594599 if (IS_QLA27XX(ha)) {
600+ ha->mpi_version[0] = mcp->mb[10] & 0xff;
601+ ha->mpi_version[1] = mcp->mb[11] >> 8;
602+ ha->mpi_version[2] = mcp->mb[11] & 0xff;
603+ ha->pep_version[0] = mcp->mb[13] & 0xff;
604+ ha->pep_version[1] = mcp->mb[14] >> 8;
605+ ha->pep_version[2] = mcp->mb[14] & 0xff;
595606 ha->fw_shared_ram_start = (mcp->mb[19] << 16) | mcp->mb[18];
596607 ha->fw_shared_ram_end = (mcp->mb[21] << 16) | mcp->mb[20];
597608 }
@@ -1135,20 +1146,22 @@ qla2x00_get_adapter_id(scsi_qla_host_t *vha, uint16_t *id, uint8_t *al_pa, · 537 unmodified lines
11351146 vha->fcoe_vn_port_mac[0] = mcp->mb[13] & 0xff;
11361147 }
11371148 /* If FA-WWN supported */
1138− if (mcp->mb[7] & BIT_14) {
1139− vha->port_name[0] = MSB(mcp->mb[16]);
1140− vha->port_name[1] = LSB(mcp->mb[16]);
1141− vha->port_name[2] = MSB(mcp->mb[17]);
1142− vha->port_name[3] = LSB(mcp->mb[17]);
1143− vha->port_name[4] = MSB(mcp->mb[18]);
1144− vha->port_name[5] = LSB(mcp->mb[18]);
1145− vha->port_name[6] = MSB(mcp->mb[19]);
1146− vha->port_name[7] = LSB(mcp->mb[19]);
1147− fc_host_port_name(vha->host) =
1148− wwn_to_u64(vha->port_name);
1149− ql_dbg(ql_dbg_mbx, vha, 0x10ca,
1150− "FA-WWN acquired %016llx\n",
1151− wwn_to_u64(vha->port_name));
1149+ if (IS_FAWWN_CAPABLE(vha->hw)) {
1150+ if (mcp->mb[7] & BIT_14) {
1151+ vha->port_name[0] = MSB(mcp->mb[16]);
1152+ vha->port_name[1] = LSB(mcp->mb[16]);
1153+ vha->port_name[2] = MSB(mcp->mb[17]);
1154+ vha->port_name[3] = LSB(mcp->mb[17]);
1155+ vha->port_name[4] = MSB(mcp->mb[18]);
1156+ vha->port_name[5] = LSB(mcp->mb[18]);
1157+ vha->port_name[6] = MSB(mcp->mb[19]);
1158+ vha->port_name[7] = LSB(mcp->mb[19]);
1159+ fc_host_port_name(vha->host) =
1160+ wwn_to_u64(vha->port_name);
1161+ ql_dbg(ql_dbg_mbx, vha, 0x10ca,
1162+ "FA-WWN acquired %016llx\n",
1163+ wwn_to_u64(vha->port_name));
1164+ }
11521165 }
11531166 }
11541167
@@ -1239,7 +1252,7 @@ qla2x00_init_firmware(scsi_qla_host_t *vha, uint16_t size) · 84 unmodified lines
12391252 "Entered %s.\n", __func__);
12401253
12411254 if (IS_P3P_TYPE(ha) && ql2xdbwr)
1242− qla82xx_wr_32(ha, ha->nxdb_wr_ptr,
1255+ qla82xx_wr_32(ha, (uintptr_t __force)ha->nxdb_wr_ptr,
12431256 (0x04 | (ha->portnum << 5) | (0 << 8) | (0 << 16)));
12441257
12451258 if (ha->flags.npiv_supported)
@@ -1865,7 +1878,6 @@ qla24xx_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain, · 619 unmodified lines
18651878 uint32_t iop[2];
18661879 struct qla_hw_data *ha = vha->hw;
18671880 struct req_que *req;
1868− struct rsp_que *rsp;
18691881
18701882 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1061,
18711883 "Entered %s.\n", __func__);
@@ -1874,7 +1886,6 @@ qla24xx_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain, · 2 unmodified lines
18741886 req = ha->req_q_map[0];
18751887 else
18761888 req = vha->req;
1877− rsp = req->rsp;
18781889
18791890 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
18801891 if (lg == NULL) {
@@ -1888,11 +1899,11 @@ qla24xx_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain, · 7 unmodified lines
18881899 lg->entry_count = 1;
18891900 lg->handle = MAKE_HANDLE(req->id, lg->handle);
18901901 lg->nport_handle = cpu_to_le16(loop_id);
1891− lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI);
1902+ lg->control_flags = cpu_to_le16(LCF_COMMAND_PLOGI);
18921903 if (opt & BIT_0)
1893− lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI);
1904+ lg->control_flags |= cpu_to_le16(LCF_COND_PLOGI);
18941905 if (opt & BIT_1)
1895− lg->control_flags |= __constant_cpu_to_le16(LCF_SKIP_PRLI);
1906+ lg->control_flags |= cpu_to_le16(LCF_SKIP_PRLI);
18961907 lg->port_id[0] = al_pa;
18971908 lg->port_id[1] = area;
18981909 lg->port_id[2] = domain;
@@ -1907,7 +1918,7 @@ qla24xx_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain, · 8 unmodified lines
19071918 "Failed to complete IOCB -- error status (%x).\n",
19081919 lg->entry_status);
19091920 rval = QLA_FUNCTION_FAILED;
1910− } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1921+ } else if (lg->comp_status != cpu_to_le16(CS_COMPLETE)) {
19111922 iop[0] = le32_to_cpu(lg->io_parameter[0]);
19121923 iop[1] = le32_to_cpu(lg->io_parameter[1]);
19131924
@@ -1961,7 +1972,7 @@ qla24xx_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain, · 47 unmodified lines
19611972 mb[10] |= BIT_0; /* Class 2. */
19621973 if (lg->io_parameter[9] || lg->io_parameter[10])
19631974 mb[10] |= BIT_1; /* Class 3. */
1964− if (lg->io_parameter[0] & __constant_cpu_to_le32(BIT_7))
1975+ if (lg->io_parameter[0] & cpu_to_le32(BIT_7))
19651976 mb[10] |= BIT_7; /* Confirmed Completion
19661977 * Allowed
19671978 */
@@ -2142,7 +2153,6 @@ qla24xx_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain, · 174 unmodified lines
21422153 dma_addr_t lg_dma;
21432154 struct qla_hw_data *ha = vha->hw;
21442155 struct req_que *req;
2145− struct rsp_que *rsp;
21462156
21472157 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106d,
21482158 "Entered %s.\n", __func__);
@@ -2159,13 +2169,12 @@ qla24xx_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain, · 10 unmodified lines
21592169 req = ha->req_q_map[0];
21602170 else
21612171 req = vha->req;
2162− rsp = req->rsp;
21632172 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
21642173 lg->entry_count = 1;
21652174 lg->handle = MAKE_HANDLE(req->id, lg->handle);
21662175 lg->nport_handle = cpu_to_le16(loop_id);
21672176 lg->control_flags =
2168− __constant_cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO|
2177+ cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO|
21692178 LCF_FREE_NPORT);
21702179 lg->port_id[0] = al_pa;
21712180 lg->port_id[1] = area;
@@ -2181,7 +2190,7 @@ qla24xx_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain, · 9 unmodified lines
21812190 "Failed to complete IOCB -- error status (%x).\n",
21822191 lg->entry_status);
21832192 rval = QLA_FUNCTION_FAILED;
2184− } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
2193+ } else if (lg->comp_status != cpu_to_le16(CS_COMPLETE)) {
21852194 ql_dbg(ql_dbg_mbx, vha, 0x1071,
21862195 "Failed to complete IOCB -- completion status (%x) "
21872196 "ioparam=%x/%x.\n", le16_to_cpu(lg->comp_status),
@@ -2673,7 +2682,7 @@ qla24xx_abort_command(srb_t *sp) · 485 unmodified lines
26732682 "Failed to complete IOCB -- error status (%x).\n",
26742683 abt->entry_status);
26752684 rval = QLA_FUNCTION_FAILED;
2676− } else if (abt->nport_handle != __constant_cpu_to_le16(0)) {
2685+ } else if (abt->nport_handle != cpu_to_le16(0)) {
26772686 ql_dbg(ql_dbg_mbx, vha, 0x1090,
26782687 "Failed to complete IOCB -- completion status (%x).\n",
26792688 le16_to_cpu(abt->nport_handle));
@@ -2756,8 +2765,7 @@ __qla24xx_issue_tmf(char *name, uint32_t type, struct fc_port *fcport, · 76 unmodified lines
27562765 "Failed to complete IOCB -- error status (%x).\n",
27572766 sts->entry_status);
27582767 rval = QLA_FUNCTION_FAILED;
2759− } else if (sts->comp_status !=
2760− __constant_cpu_to_le16(CS_COMPLETE)) {
2768+ } else if (sts->comp_status != cpu_to_le16(CS_COMPLETE)) {
27612769 ql_dbg(ql_dbg_mbx, vha, 0x1096,
27622770 "Failed to complete IOCB -- completion status (%x).\n",
27632771 le16_to_cpu(sts->comp_status));
@@ -2853,7 +2861,8 @@ qla2x00_write_serdes_word(scsi_qla_host_t *vha, uint16_t addr, uint16_t data) · 89 unmodified lines
28532861 mbx_cmd_t mc;
28542862 mbx_cmd_t *mcp = &mc;
28552863
2856− if (!IS_QLA2031(vha->hw) && !IS_QLA27XX(vha->hw))
2864+ if (!IS_QLA25XX(vha->hw) && !IS_QLA2031(vha->hw) &&
2865+ !IS_QLA27XX(vha->hw))
28572866 return QLA_FUNCTION_FAILED;
28582867
28592868 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1182,
@@ -2891,7 +2900,8 @@ qla2x00_read_serdes_word(scsi_qla_host_t *vha, uint16_t addr, uint16_t *data) · 31 unmodified lines
28912900 mbx_cmd_t mc;
28922901 mbx_cmd_t *mcp = &mc;
28932902
2894− if (!IS_QLA2031(vha->hw) && !IS_QLA27XX(vha->hw))
2903+ if (!IS_QLA25XX(vha->hw) && !IS_QLA2031(vha->hw) &&
2904+ !IS_QLA27XX(vha->hw))
28952905 return QLA_FUNCTION_FAILED;
28962906
28972907 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1185,
@@ -3483,7 +3493,7 @@ qla24xx_modify_vp_config(scsi_qla_host_t *vha) · 585 unmodified lines
34833493 "Failed to complete IOCB -- error status (%x).\n",
34843494 vpmod->comp_status);
34853495 rval = QLA_FUNCTION_FAILED;
3486− } else if (vpmod->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
3496+ } else if (vpmod->comp_status != cpu_to_le16(CS_COMPLETE)) {
34873497 ql_dbg(ql_dbg_mbx, vha, 0x10bf,
34883498 "Failed to complete IOCB -- completion status (%x).\n",
34893499 le16_to_cpu(vpmod->comp_status));
@@ -3542,7 +3552,7 @@ qla24xx_control_vp(scsi_qla_host_t *vha, int cmd) · 52 unmodified lines
35423552 vce->entry_type = VP_CTRL_IOCB_TYPE;
35433553 vce->entry_count = 1;
35443554 vce->command = cpu_to_le16(cmd);
3545− vce->vp_count = __constant_cpu_to_le16(1);
3555+ vce->vp_count = cpu_to_le16(1);
35463556
35473557 /* index map in firmware starts with 1; decrement index
35483558 * this is ok as we never use index 0
@@ -3562,7 +3572,7 @@ qla24xx_control_vp(scsi_qla_host_t *vha, int cmd) · 13 unmodified lines
35623572 "Failed to complete IOCB -- error status (%x).\n",
35633573 vce->entry_status);
35643574 rval = QLA_FUNCTION_FAILED;
3565− } else if (vce->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
3575+ } else if (vce->comp_status != cpu_to_le16(CS_COMPLETE)) {
35663576 ql_dbg(ql_dbg_mbx, vha, 0x10c5,
35673577 "Failed to complet IOCB -- completion status (%x).\n",
35683578 le16_to_cpu(vce->comp_status));
drivers/scsi/qla2xxx/qla_mid.c+1−2
@@ -371,7 +371,6 @@ qla2x00_do_dpc_vp(scsi_qla_host_t *vha) · 370 unmodified lines
371371 void
372372 qla2x00_do_dpc_all_vps(scsi_qla_host_t *vha)
373373 {
374− int ret;
375374 struct qla_hw_data *ha = vha->hw;
376375 scsi_qla_host_t *vp;
377376 unsigned long flags = 0;
@@ -392,7 +391,7 @@ qla2x00_do_dpc_all_vps(scsi_qla_host_t *vha) · 14 unmodified lines
392391 atomic_inc(&vp->vref_count);
393392 spin_unlock_irqrestore(&ha->vport_slock, flags);
394393
395− ret = qla2x00_do_dpc_vp(vp);
394+ qla2x00_do_dpc_vp(vp);
396395
397396 spin_lock_irqsave(&ha->vport_slock, flags);
398397 atomic_dec(&vp->vref_count);
drivers/scsi/qla2xxx/qla_mr.c+9−13
@@ -862,7 +862,7 @@ qlafx00_config_queues(struct scsi_qla_host *vha) · 861 unmodified lines
862862 dma_addr_t bar2_hdl = pci_resource_start(ha->pdev, 2);
863863
864864 req->length = ha->req_que_len;
865− req->ring = (void *)ha->iobase + ha->req_que_off;
865+ req->ring = (void __force *)ha->iobase + ha->req_que_off;
866866 req->dma = bar2_hdl + ha->req_que_off;
867867 if ((!req->ring) || (req->length == 0)) {
868868 ql_log_pci(ql_log_info, ha->pdev, 0x012f,
@@ -877,7 +877,7 @@ qlafx00_config_queues(struct scsi_qla_host *vha) · 8 unmodified lines
877877 ha->req_que_off, (u64)req->dma);
878878
879879 rsp->length = ha->rsp_que_len;
880− rsp->ring = (void *)ha->iobase + ha->rsp_que_off;
880+ rsp->ring = (void __force *)ha->iobase + ha->rsp_que_off;
881881 rsp->dma = bar2_hdl + ha->rsp_que_off;
882882 if ((!rsp->ring) || (rsp->length == 0)) {
883883 ql_log_pci(ql_log_info, ha->pdev, 0x0131,
@@ -1317,10 +1317,10 @@ int · 433 unmodified lines
13171317 qlafx00_configure_devices(scsi_qla_host_t *vha)
13181318 {
13191319 int rval;
1320− unsigned long flags, save_flags;
1320+ unsigned long flags;
13211321 rval = QLA_SUCCESS;
13221322
1323− save_flags = flags = vha->dpc_flags;
1323+ flags = vha->dpc_flags;
13241324
13251325 ql_dbg(ql_dbg_disc, vha, 0x2090,
13261326 "Configure devices -- dpc flags =0x%lx\n", flags);
@@ -1425,7 +1425,7 @@ qlafx00_init_response_q_entries(struct rsp_que *rsp) · 98 unmodified lines
14251425 pkt = rsp->ring_ptr;
14261426 for (cnt = 0; cnt < rsp->length; cnt++) {
14271427 pkt->signature = RESPONSE_PROCESSED;
1428− WRT_REG_DWORD((void __iomem *)&pkt->signature,
1428+ WRT_REG_DWORD((void __force __iomem *)&pkt->signature,
14291429 RESPONSE_PROCESSED);
14301430 pkt++;
14311431 }
@@ -2279,7 +2279,6 @@ qlafx00_status_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, void *pkt) · 847 unmodified lines
22792279 struct sts_entry_fx00 *sts;
22802280 __le16 comp_status;
22812281 __le16 scsi_status;
2282− uint16_t ox_id;
22832282 __le16 lscsi_status;
22842283 int32_t resid;
22852284 uint32_t sense_len, par_sense_len, rsp_info_len, resid_len,
@@ -2344,7 +2343,6 @@ qlafx00_status_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, void *pkt) · 58 unmodified lines
23442343
23452344 fcport = sp->fcport;
23462345
2347− ox_id = 0;
23482346 sense_len = par_sense_len = rsp_info_len = resid_len =
23492347 fw_resid_len = 0;
23502348 if (scsi_status & cpu_to_le16((uint16_t)SS_SENSE_LEN_VALID))
@@ -2528,12 +2526,12 @@ check_scsi_status: · 177 unmodified lines
25282526 ql_dbg(ql_dbg_io, fcport->vha, 0x3058,
25292527 "FCP command status: 0x%x-0x%x (0x%x) nexus=%ld:%d:%llu "
25302528 "tgt_id: 0x%x lscsi_status: 0x%x cdb=%10phN len=0x%x "
2531− "rsp_info=0x%x resid=0x%x fw_resid=0x%x sense_len=0x%x, "
2529+ "rsp_info=%p resid=0x%x fw_resid=0x%x sense_len=0x%x, "
25322530 "par_sense_len=0x%x, rsp_info_len=0x%x\n",
25332531 comp_status, scsi_status, res, vha->host_no,
25342532 cp->device->id, cp->device->lun, fcport->tgt_id,
25352533 lscsi_status, cp->cmnd, scsi_bufflen(cp),
2536− rsp_info_len, resid_len, fw_resid_len, sense_len,
2534+ rsp_info, resid_len, fw_resid_len, sense_len,
25372535 par_sense_len, rsp_info_len);
25382536
25392537 if (rsp->status_srb == NULL)
@@ -3009,7 +3007,7 @@ qlafx00_build_scsi_iocbs(srb_t *sp, struct cmd_type_7_fx00 *cmd_pkt, · 469 unmodified lines
30093007
30103008 /* No data transfer */
30113009 if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) {
3012− lcmd_pkt->byte_count = __constant_cpu_to_le32(0);
3010+ lcmd_pkt->byte_count = cpu_to_le32(0);
30133011 return;
30143012 }
30153013
@@ -3071,7 +3069,7 @@ qlafx00_build_scsi_iocbs(srb_t *sp, struct cmd_type_7_fx00 *cmd_pkt, · 55 unmodified lines
30713069 int
30723070 qlafx00_start_scsi(srb_t *sp)
30733071 {
3074− int ret, nseg;
3072+ int nseg;
30753073 unsigned long flags;
30763074 uint32_t index;
30773075 uint32_t handle;
@@ -3088,8 +3086,6 @@ qlafx00_start_scsi(srb_t *sp) · 10 unmodified lines
30883086 struct scsi_lun llun;
30893087
30903088 /* Setup device pointers. */
3091− ret = 0;
3092−
30933089 rsp = ha->rsp_q_map[0];
30943090 req = vha->req;
30953091
drivers/scsi/qla2xxx/qla_nx.c+79−86
@@ -347,32 +347,31 @@ char *qdev_state(uint32_t dev_state) · 346 unmodified lines
347347 }
348348
349349 /*
350− * In: 'off' is offset from CRB space in 128M pci map
351− * Out: 'off' is 2M pci map addr
350+ * In: 'off_in' is offset from CRB space in 128M pci map
351+ * Out: 'off_out' is 2M pci map addr
352352 * side effect: lock crb window
353353 */
354354 static void
355−qla82xx_pci_set_crbwindow_2M(struct qla_hw_data *ha, ulong *off)
355+qla82xx_pci_set_crbwindow_2M(struct qla_hw_data *ha, ulong off_in,
356+ void __iomem **off_out)
356357 {
357358 u32 win_read;
358359 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
359360
360− ha->crb_win = CRB_HI(*off);
361− writel(ha->crb_win,
362− (void __iomem *)(CRB_WINDOW_2M + ha->nx_pcibase));
361+ ha->crb_win = CRB_HI(off_in);
362+ writel(ha->crb_win, CRB_WINDOW_2M + ha->nx_pcibase);
363363
364364 /* Read back value to make sure write has gone through before trying
365365 * to use it.
366366 */
367− win_read = RD_REG_DWORD((void __iomem *)
368− (CRB_WINDOW_2M + ha->nx_pcibase));
367+ win_read = RD_REG_DWORD(CRB_WINDOW_2M + ha->nx_pcibase);
369368 if (win_read != ha->crb_win) {
370369 ql_dbg(ql_dbg_p3p, vha, 0xb000,
371370 "%s: Written crbwin (0x%x) "
372371 "!= Read crbwin (0x%x), off=0x%lx.\n",
373− __func__, ha->crb_win, win_read, *off);
372+ __func__, ha->crb_win, win_read, off_in);
374373 }
375− *off = (*off & MASK(16)) + CRB_INDIRECT_2M + ha->nx_pcibase;
374+ *off_out = (off_in & MASK(16)) + CRB_INDIRECT_2M + ha->nx_pcibase;
376375 }
377376
378377 static inline unsigned long
@@ -417,29 +416,30 @@ qla82xx_pci_set_crbwindow(struct qla_hw_data *ha, u64 off) · 38 unmodified lines
417416 }
418417
419418 static int
420−qla82xx_pci_get_crb_addr_2M(struct qla_hw_data *ha, ulong *off)
419+qla82xx_pci_get_crb_addr_2M(struct qla_hw_data *ha, ulong off_in,
420+ void __iomem **off_out)
421421 {
422422 struct crb_128M_2M_sub_block_map *m;
423423
424− if (*off >= QLA82XX_CRB_MAX)
424+ if (off_in >= QLA82XX_CRB_MAX)
425425 return -1;
426426
427− if (*off >= QLA82XX_PCI_CAMQM && (*off < QLA82XX_PCI_CAMQM_2M_END)) {
428− *off = (*off - QLA82XX_PCI_CAMQM) +
427+ if (off_in >= QLA82XX_PCI_CAMQM && off_in < QLA82XX_PCI_CAMQM_2M_END) {
428+ *off_out = (off_in - QLA82XX_PCI_CAMQM) +
429429 QLA82XX_PCI_CAMQM_2M_BASE + ha->nx_pcibase;
430430 return 0;
431431 }
432432
433− if (*off < QLA82XX_PCI_CRBSPACE)
433+ if (off_in < QLA82XX_PCI_CRBSPACE)
434434 return -1;
435435
436− *off -= QLA82XX_PCI_CRBSPACE;
436+ *off_out = (void __iomem *)(off_in - QLA82XX_PCI_CRBSPACE);
437437
438438 /* Try direct map */
439− m = &crb_128M_2M_map[CRB_BLK(*off)].sub_block[CRB_SUBBLK(*off)];
439+ m = &crb_128M_2M_map[CRB_BLK(off_in)].sub_block[CRB_SUBBLK(off_in)];
440440
441− if (m->valid && (m->start_128M <= *off) && (m->end_128M > *off)) {
442− *off = *off + m->start_2M - m->start_128M + ha->nx_pcibase;
441+ if (m->valid && (m->start_128M <= off_in) && (m->end_128M > off_in)) {
442+ *off_out = off_in + m->start_2M - m->start_128M + ha->nx_pcibase;
443443 return 0;
444444 }
445445 /* Not in direct map, use crb window */
@@ -465,51 +465,61 @@ static int qla82xx_crb_win_lock(struct qla_hw_data *ha) · 19 unmodified lines
465465 }
466466
467467 int
468−qla82xx_wr_32(struct qla_hw_data *ha, ulong off, u32 data)
468+qla82xx_wr_32(struct qla_hw_data *ha, ulong off_in, u32 data)
469469 {
470+ void __iomem *off;
470471 unsigned long flags = 0;
471472 int rv;
472473
473− rv = qla82xx_pci_get_crb_addr_2M(ha, &off);
474+ rv = qla82xx_pci_get_crb_addr_2M(ha, off_in, &off);
474475
475476 BUG_ON(rv == -1);
476477
477478 if (rv == 1) {
479+#ifndef __CHECKER__
478480 write_lock_irqsave(&ha->hw_lock, flags);
481+#endif
479482 qla82xx_crb_win_lock(ha);
480− qla82xx_pci_set_crbwindow_2M(ha, &off);
483+ qla82xx_pci_set_crbwindow_2M(ha, off_in, &off);
481484 }
482485
483486 writel(data, (void __iomem *)off);
484487
485488 if (rv == 1) {
486489 qla82xx_rd_32(ha, QLA82XX_PCIE_REG(PCIE_SEM7_UNLOCK));
490+#ifndef __CHECKER__
487491 write_unlock_irqrestore(&ha->hw_lock, flags);
492+#endif
488493 }
489494 return 0;
490495 }
491496
492497 int
493−qla82xx_rd_32(struct qla_hw_data *ha, ulong off)
498+qla82xx_rd_32(struct qla_hw_data *ha, ulong off_in)
494499 {
500+ void __iomem *off;
495501 unsigned long flags = 0;
496502 int rv;
497503 u32 data;
498504
499− rv = qla82xx_pci_get_crb_addr_2M(ha, &off);
505+ rv = qla82xx_pci_get_crb_addr_2M(ha, off_in, &off);
500506
501507 BUG_ON(rv == -1);
502508
503509 if (rv == 1) {
510+#ifndef __CHECKER__
504511 write_lock_irqsave(&ha->hw_lock, flags);
512+#endif
505513 qla82xx_crb_win_lock(ha);
506− qla82xx_pci_set_crbwindow_2M(ha, &off);
514+ qla82xx_pci_set_crbwindow_2M(ha, off_in, &off);
507515 }
508− data = RD_REG_DWORD((void __iomem *)off);
516+ data = RD_REG_DWORD(off);
509517
510518 if (rv == 1) {
511519 qla82xx_rd_32(ha, QLA82XX_PCIE_REG(PCIE_SEM7_UNLOCK));
520+#ifndef __CHECKER__
512521 write_unlock_irqrestore(&ha->hw_lock, flags);
522+#endif
513523 }
514524 return data;
515525 }
@@ -547,9 +557,6 @@ void qla82xx_idc_unlock(struct qla_hw_data *ha) · 31 unmodified lines
547557 qla82xx_rd_32(ha, QLA82XX_PCIE_REG(PCIE_SEM5_UNLOCK));
548558 }
549559
550−/* PCI Windowing for DDR regions. */
551−#define QLA82XX_ADDR_IN_RANGE(addr, low, high) \
552− (((addr) <= (high)) && ((addr) >= (low)))
553560 /*
554561 * check memory access boundary.
555562 * used by test agent. support ddr access only for now
@@ -558,9 +565,9 @@ static unsigned long · 2 unmodified lines
558565 qla82xx_pci_mem_bound_check(struct qla_hw_data *ha,
559566 unsigned long long addr, int size)
560567 {
561− if (!QLA82XX_ADDR_IN_RANGE(addr, QLA82XX_ADDR_DDR_NET,
568+ if (!addr_in_range(addr, QLA82XX_ADDR_DDR_NET,
562569 QLA82XX_ADDR_DDR_NET_MAX) ||
563− !QLA82XX_ADDR_IN_RANGE(addr + size - 1, QLA82XX_ADDR_DDR_NET,
570+ !addr_in_range(addr + size - 1, QLA82XX_ADDR_DDR_NET,
564571 QLA82XX_ADDR_DDR_NET_MAX) ||
565572 ((size != 1) && (size != 2) && (size != 4) && (size != 8)))
566573 return 0;
@@ -577,7 +584,7 @@ qla82xx_pci_set_window(struct qla_hw_data *ha, unsigned long long addr) · 10 unmodified lines
577584 u32 win_read;
578585 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
579586
580− if (QLA82XX_ADDR_IN_RANGE(addr, QLA82XX_ADDR_DDR_NET,
587+ if (addr_in_range(addr, QLA82XX_ADDR_DDR_NET,
581588 QLA82XX_ADDR_DDR_NET_MAX)) {
582589 /* DDR network side */
583590 window = MN_WIN(addr);
@@ -592,7 +599,7 @@ qla82xx_pci_set_window(struct qla_hw_data *ha, unsigned long long addr) · 8 unmodified lines
592599 __func__, window, win_read);
593600 }
594601 addr = GET_MEM_OFFS_2M(addr) + QLA82XX_PCI_DDR_NET;
595− } else if (QLA82XX_ADDR_IN_RANGE(addr, QLA82XX_ADDR_OCM0,
602+ } else if (addr_in_range(addr, QLA82XX_ADDR_OCM0,
596603 QLA82XX_ADDR_OCM0_MAX)) {
597604 unsigned int temp1;
598605 if ((addr & 0x00ff800) == 0xff800) {
@@ -615,7 +622,7 @@ qla82xx_pci_set_window(struct qla_hw_data *ha, unsigned long long addr) · 16 unmodified lines
615622 }
616623 addr = GET_MEM_OFFS_2M(addr) + QLA82XX_PCI_OCM0_2M;
617624
618− } else if (QLA82XX_ADDR_IN_RANGE(addr, QLA82XX_ADDR_QDR_NET,
625+ } else if (addr_in_range(addr, QLA82XX_ADDR_QDR_NET,
619626 QLA82XX_P3_ADDR_QDR_NET_MAX)) {
620627 /* QDR network side */
621628 window = MS_WIN(addr);
@@ -656,16 +663,16 @@ static int qla82xx_pci_is_same_window(struct qla_hw_data *ha, · 34 unmodified lines
656663 qdr_max = QLA82XX_P3_ADDR_QDR_NET_MAX;
657664
658665 /* DDR network side */
659− if (QLA82XX_ADDR_IN_RANGE(addr, QLA82XX_ADDR_DDR_NET,
666+ if (addr_in_range(addr, QLA82XX_ADDR_DDR_NET,
660667 QLA82XX_ADDR_DDR_NET_MAX))
661668 BUG();
662− else if (QLA82XX_ADDR_IN_RANGE(addr, QLA82XX_ADDR_OCM0,
669+ else if (addr_in_range(addr, QLA82XX_ADDR_OCM0,
663670 QLA82XX_ADDR_OCM0_MAX))
664671 return 1;
665− else if (QLA82XX_ADDR_IN_RANGE(addr, QLA82XX_ADDR_OCM1,
672+ else if (addr_in_range(addr, QLA82XX_ADDR_OCM1,
666673 QLA82XX_ADDR_OCM1_MAX))
667674 return 1;
668− else if (QLA82XX_ADDR_IN_RANGE(addr, QLA82XX_ADDR_QDR_NET, qdr_max)) {
675+ else if (addr_in_range(addr, QLA82XX_ADDR_QDR_NET, qdr_max)) {
669676 /* QDR network side */
670677 window = ((addr - QLA82XX_ADDR_QDR_NET) >> 22) & 0x3f;
671678 if (ha->qdr_sn_window == window)
@@ -922,20 +929,18 @@ qla82xx_md_rw_32(struct qla_hw_data *ha, uint32_t off, u32 data, uint8_t flag) · 250 unmodified lines
922929 {
923930 uint32_t off_value, rval = 0;
924931
925− WRT_REG_DWORD((void __iomem *)(CRB_WINDOW_2M + ha->nx_pcibase),
926− (off & 0xFFFF0000));
932+ WRT_REG_DWORD(CRB_WINDOW_2M + ha->nx_pcibase, off & 0xFFFF0000);
927933
928934 /* Read back value to make sure write has gone through */
929− RD_REG_DWORD((void __iomem *)(CRB_WINDOW_2M + ha->nx_pcibase));
935+ RD_REG_DWORD(CRB_WINDOW_2M + ha->nx_pcibase);
930936 off_value = (off & 0x0000FFFF);
931937
932938 if (flag)
933− WRT_REG_DWORD((void __iomem *)
934− (off_value + CRB_INDIRECT_2M + ha->nx_pcibase),
935− data);
939+ WRT_REG_DWORD(off_value + CRB_INDIRECT_2M + ha->nx_pcibase,
940+ data);
936941 else
937− rval = RD_REG_DWORD((void __iomem *)
938− (off_value + CRB_INDIRECT_2M + ha->nx_pcibase));
942+ rval = RD_REG_DWORD(off_value + CRB_INDIRECT_2M +
943+ ha->nx_pcibase);
939944
940945 return rval;
941946 }
@@ -1663,8 +1668,7 @@ qla82xx_iospace_config(struct qla_hw_data *ha) · 721 unmodified lines
16631668 }
16641669
16651670 len = pci_resource_len(ha->pdev, 0);
1666− ha->nx_pcibase =
1667− (unsigned long)ioremap(pci_resource_start(ha->pdev, 0), len);
1671+ ha->nx_pcibase = ioremap(pci_resource_start(ha->pdev, 0), len);
16681672 if (!ha->nx_pcibase) {
16691673 ql_log_pci(ql_log_fatal, ha->pdev, 0x000e,
16701674 "Cannot remap pcibase MMIO, aborting.\n");
@@ -1673,17 +1677,13 @@ qla82xx_iospace_config(struct qla_hw_data *ha) · 2 unmodified lines
16731677
16741678 /* Mapping of IO base pointer */
16751679 if (IS_QLA8044(ha)) {
1676− ha->iobase =
1677− (device_reg_t *)((uint8_t *)ha->nx_pcibase);
1680+ ha->iobase = ha->nx_pcibase;
16781681 } else if (IS_QLA82XX(ha)) {
1679− ha->iobase =
1680− (device_reg_t *)((uint8_t *)ha->nx_pcibase +
1681− 0xbc000 + (ha->pdev->devfn << 11));
1682+ ha->iobase = ha->nx_pcibase + 0xbc000 + (ha->pdev->devfn << 11);
16821683 }
16831684
16841685 if (!ql2xdbwr) {
1685− ha->nxdb_wr_ptr =
1686− (unsigned long)ioremap((pci_resource_start(ha->pdev, 4) +
1686+ ha->nxdb_wr_ptr = ioremap((pci_resource_start(ha->pdev, 4) +
16871687 (ha->pdev->devfn << 12)), 4);
16881688 if (!ha->nxdb_wr_ptr) {
16891689 ql_log_pci(ql_log_fatal, ha->pdev, 0x000f,
@@ -1694,10 +1694,10 @@ qla82xx_iospace_config(struct qla_hw_data *ha) · 4 unmodified lines
16941694 /* Mapping of IO base pointer,
16951695 * door bell read and write pointer
16961696 */
1697− ha->nxdb_rd_ptr = (uint8_t *) ha->nx_pcibase + (512 * 1024) +
1697+ ha->nxdb_rd_ptr = ha->nx_pcibase + (512 * 1024) +
16981698 (ha->pdev->devfn * 8);
16991699 } else {
1700− ha->nxdb_wr_ptr = (ha->pdev->devfn == 6 ?
1700+ ha->nxdb_wr_ptr = (void __iomem *)(ha->pdev->devfn == 6 ?
17011701 QLA82XX_CAMRAM_DB1 :
17021702 QLA82XX_CAMRAM_DB2);
17031703 }
@@ -1707,12 +1707,12 @@ qla82xx_iospace_config(struct qla_hw_data *ha) · 3 unmodified lines
17071707 ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc006,
17081708 "nx_pci_base=%p iobase=%p "
17091709 "max_req_queues=%d msix_count=%d.\n",
1710− (void *)ha->nx_pcibase, ha->iobase,
1710+ ha->nx_pcibase, ha->iobase,
17111711 ha->max_req_queues, ha->msix_count);
17121712 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0010,
17131713 "nx_pci_base=%p iobase=%p "
17141714 "max_req_queues=%d msix_count=%d.\n",
1715− (void *)ha->nx_pcibase, ha->iobase,
1715+ ha->nx_pcibase, ha->iobase,
17161716 ha->max_req_queues, ha->msix_count);
17171717 return 0;
17181718
@@ -1740,8 +1740,8 @@ qla82xx_pci_config(scsi_qla_host_t *vha) · 21 unmodified lines
17401740 ret = pci_set_mwi(ha->pdev);
17411741 ha->chip_revision = ha->pdev->revision;
17421742 ql_dbg(ql_dbg_init, vha, 0x0043,
1743− "Chip revision:%d.\n",
1744− ha->chip_revision);
1743+ "Chip revision:%d; pci_set_mwi() returned %d.\n",
1744+ ha->chip_revision, ret);
17451745 return 0;
17461746 }
17471747
@@ -1768,8 +1768,8 @@ void qla82xx_config_rings(struct scsi_qla_host *vha) · 20 unmodified lines
17681768
17691769 /* Setup ring parameters in initialization control block. */
17701770 icb = (struct init_cb_81xx *)ha->init_cb;
1771− icb->request_q_outpointer = __constant_cpu_to_le16(0);
1772− icb->response_q_inpointer = __constant_cpu_to_le16(0);
1771+ icb->request_q_outpointer = cpu_to_le16(0);
1772+ icb->response_q_inpointer = cpu_to_le16(0);
17731773 icb->request_q_length = cpu_to_le16(req->length);
17741774 icb->response_q_length = cpu_to_le16(rsp->length);
17751775 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
@@ -1777,9 +1777,9 @@ void qla82xx_config_rings(struct scsi_qla_host *vha) · 1 unmodified line
17771777 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
17781778 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
17791779
1780− WRT_REG_DWORD((unsigned long __iomem *)&reg->req_q_out[0], 0);
1781− WRT_REG_DWORD((unsigned long __iomem *)&reg->rsp_q_in[0], 0);
1782− WRT_REG_DWORD((unsigned long __iomem *)&reg->rsp_q_out[0], 0);
1780+ WRT_REG_DWORD(&reg->req_q_out[0], 0);
1781+ WRT_REG_DWORD(&reg->rsp_q_in[0], 0);
1782+ WRT_REG_DWORD(&reg->rsp_q_out[0], 0);
17831783 }
17841784
17851785 static int
@@ -2298,7 +2298,7 @@ void qla82xx_init_flags(struct qla_hw_data *ha) · 512 unmodified lines
22982298 ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
22992299 }
23002300
2301−inline void
2301+static inline void
23022302 qla82xx_set_idc_version(scsi_qla_host_t *vha)
23032303 {
23042304 int idc_ver;
@@ -2481,14 +2481,12 @@ try_blob_fw: · 176 unmodified lines
24812481 ql_log(ql_log_info, vha, 0x00a5,
24822482 "Firmware loaded successfully from binary blob.\n");
24832483 return QLA_SUCCESS;
2484− } else {
2485− ql_log(ql_log_fatal, vha, 0x00a6,
2486− "Firmware load failed for binary blob.\n");
2487− blob->fw = NULL;
2488− blob = NULL;
2489− goto fw_load_failed;
24902484 }
2491− return QLA_SUCCESS;
2485+
2486+ ql_log(ql_log_fatal, vha, 0x00a6,
2487+ "Firmware load failed for binary blob.\n");
2488+ blob->fw = NULL;
2489+ blob = NULL;
24922490
24932491 fw_load_failed:
24942492 return QLA_FUNCTION_FAILED;
@@ -2549,7 +2547,7 @@ qla82xx_read_flash_data(scsi_qla_host_t *vha, uint32_t *dwptr, uint32_t faddr, · 54 unmodified lines
25492547 "Do ROM fast read failed.\n");
25502548 goto done_read;
25512549 }
2552− dwptr[i] = __constant_cpu_to_le32(val);
2550+ dwptr[i] = cpu_to_le32(val);
25532551 }
25542552 done_read:
25552553 return dwptr;
@@ -2671,7 +2669,7 @@ qla82xx_write_flash_data(struct scsi_qla_host *vha, uint32_t *dwptr, · 115 unmodified lines
26712669 {
26722670 int ret;
26732671 uint32_t liter;
2674− uint32_t sec_mask, rest_addr;
2672+ uint32_t rest_addr;
26752673 dma_addr_t optrom_dma;
26762674 void *optrom = NULL;
26772675 int page_mode = 0;
@@ -2693,7 +2691,6 @@ qla82xx_write_flash_data(struct scsi_qla_host *vha, uint32_t *dwptr, · 15 unmodified lines
26932691 }
26942692
26952693 rest_addr = ha->fdt_block_size - 1;
2696− sec_mask = ~rest_addr;
26972694
26982695 ret = qla82xx_unprotect_flash(ha);
26992696 if (ret) {
@@ -2789,7 +2786,6 @@ qla82xx_start_iocbs(scsi_qla_host_t *vha) · 89 unmodified lines
27892786 {
27902787 struct qla_hw_data *ha = vha->hw;
27912788 struct req_que *req = ha->req_q_map[0];
2792− struct device_reg_82xx __iomem *reg;
27932789 uint32_t dbval;
27942790
27952791 /* Adjust ring index. */
@@ -2800,18 +2796,16 @@ qla82xx_start_iocbs(scsi_qla_host_t *vha) · 4 unmodified lines
28002796 } else
28012797 req->ring_ptr++;
28022798
2803− reg = &ha->iobase->isp82;
28042799 dbval = 0x04 | (ha->portnum << 5);
28052800
28062801 dbval = dbval | (req->id << 8) | (req->ring_index << 16);
28072802 if (ql2xdbwr)
2808− qla82xx_wr_32(ha, ha->nxdb_wr_ptr, dbval);
2803+ qla82xx_wr_32(ha, (unsigned long)ha->nxdb_wr_ptr, dbval);
28092804 else {
2810− WRT_REG_DWORD((unsigned long __iomem *)ha->nxdb_wr_ptr, dbval);
2805+ WRT_REG_DWORD(ha->nxdb_wr_ptr, dbval);
28112806 wmb();
2812− while (RD_REG_DWORD((void __iomem *)ha->nxdb_rd_ptr) != dbval) {
2813− WRT_REG_DWORD((unsigned long __iomem *)ha->nxdb_wr_ptr,
2814− dbval);
2807+ while (RD_REG_DWORD(ha->nxdb_rd_ptr) != dbval) {
2808+ WRT_REG_DWORD(ha->nxdb_wr_ptr, dbval);
28152809 wmb();
28162810 }
28172811 }
@@ -3842,8 +3836,7 @@ qla82xx_minidump_process_rdocm(scsi_qla_host_t *vha, · 1024 unmodified lines
38423836 loop_cnt = ocm_hdr->op_count;
38433837
38443838 for (i = 0; i < loop_cnt; i++) {
3845− r_value = RD_REG_DWORD((void __iomem *)
3846− (r_addr + ha->nx_pcibase));
3839+ r_value = RD_REG_DWORD(r_addr + ha->nx_pcibase);
38473840 *data_ptr++ = cpu_to_le32(r_value);
38483841 r_addr += r_stride;
38493842 }
drivers/scsi/qla2xxx/qla_nx2.c+8−12
@@ -462,12 +462,11 @@ qla8044_flash_lock(scsi_qla_host_t *vha) · 461 unmodified lines
462462 static void
463463 qla8044_flash_unlock(scsi_qla_host_t *vha)
464464 {
465− int ret_val;
466465 struct qla_hw_data *ha = vha->hw;
467466
468467 /* Reading FLASH_UNLOCK register unlocks the Flash */
469468 qla8044_wr_reg(ha, QLA8044_FLASH_LOCK_ID, 0xFF);
470− ret_val = qla8044_rd_reg(ha, QLA8044_FLASH_UNLOCK);
469+ qla8044_rd_reg(ha, QLA8044_FLASH_UNLOCK);
471470 }
472471
473472
@@ -561,7 +560,7 @@ qla8044_read_optrom_data(struct scsi_qla_host *vha, uint8_t *buf, · 87 unmodified lines
561560 return buf;
562561 }
563562
564−inline int
563+static inline int
565564 qla8044_need_reset(struct scsi_qla_host *vha)
566565 {
567566 uint32_t drv_state, drv_active;
@@ -1130,9 +1129,9 @@ qla8044_ms_mem_write_128b(struct scsi_qla_host *vha, · 562 unmodified lines
11301129 }
11311130
11321131 for (i = 0; i < count; i++, addr += 16) {
1133− if (!((QLA8044_ADDR_IN_RANGE(addr, QLA8044_ADDR_QDR_NET,
1132+ if (!((addr_in_range(addr, QLA8044_ADDR_QDR_NET,
11341133 QLA8044_ADDR_QDR_NET_MAX)) ||
1135− (QLA8044_ADDR_IN_RANGE(addr, QLA8044_ADDR_DDR_NET,
1134+ (addr_in_range(addr, QLA8044_ADDR_DDR_NET,
11361135 QLA8044_ADDR_DDR_NET_MAX)))) {
11371136 ret_val = QLA_FUNCTION_FAILED;
11381137 goto exit_ms_mem_write_unlock;
@@ -1605,7 +1604,7 @@ qla8044_set_idc_dontreset(struct scsi_qla_host *vha) · 466 unmodified lines
16051604 qla8044_wr_reg(ha, QLA8044_IDC_DRV_CTRL, idc_ctrl);
16061605 }
16071606
1608−inline void
1607+static inline void
16091608 qla8044_set_rst_ready(struct scsi_qla_host *vha)
16101609 {
16111610 uint32_t drv_state;
@@ -2992,7 +2991,7 @@ qla8044_minidump_process_rddfe(struct scsi_qla_host *vha, · 1380 unmodified lines
29922991 uint32_t addr1, addr2, value, data, temp, wrVal;
29932992 uint8_t stride, stride2;
29942993 uint16_t count;
2995− uint32_t poll, mask, data_size, modify_mask;
2994+ uint32_t poll, mask, modify_mask;
29962995 uint32_t wait_count = 0;
29972996
29982997 uint32_t *data_ptr = *d_ptr;
@@ -3009,7 +3008,6 @@ qla8044_minidump_process_rddfe(struct scsi_qla_host *vha, · 10 unmodified lines
30093008 poll = rddfe->poll;
30103009 mask = rddfe->mask;
30113010 modify_mask = rddfe->modify_mask;
3012− data_size = rddfe->data_size;
30133011
30143012 addr2 = addr1 + stride;
30153013
@@ -3091,7 +3089,7 @@ qla8044_minidump_process_rdmdio(struct scsi_qla_host *vha, · 75 unmodified lines
30913089 uint8_t stride1, stride2;
30923090 uint32_t addr3, addr4, addr5, addr6, addr7;
30933091 uint16_t count, loop_cnt;
3094− uint32_t poll, mask;
3092+ uint32_t mask;
30953093 uint32_t *data_ptr = *d_ptr;
30963094
30973095 struct qla8044_minidump_entry_rdmdio *rdmdio;
@@ -3105,7 +3103,6 @@ qla8044_minidump_process_rdmdio(struct scsi_qla_host *vha, · 7 unmodified lines
31053103 stride2 = rdmdio->stride_2;
31063104 count = rdmdio->count;
31073105
3108− poll = rdmdio->poll;
31093106 mask = rdmdio->mask;
31103107 value2 = rdmdio->value_2;
31113108
@@ -3164,7 +3161,7 @@ error: · 52 unmodified lines
31643161 static uint32_t qla8044_minidump_process_pollwr(struct scsi_qla_host *vha,
31653162 struct qla8044_minidump_entry_hdr *entry_hdr, uint32_t **d_ptr)
31663163 {
3167− uint32_t addr1, addr2, value1, value2, poll, mask, r_value;
3164+ uint32_t addr1, addr2, value1, value2, poll, r_value;
31683165 uint32_t wait_count = 0;
31693166 struct qla8044_minidump_entry_pollwr *pollwr_hdr;
31703167
@@ -3175,7 +3172,6 @@ static uint32_t qla8044_minidump_process_pollwr(struct scsi_qla_host *vha, · 4 unmodified lines
31753172 value2 = pollwr_hdr->value_2;
31763173
31773174 poll = pollwr_hdr->poll;
3178− mask = pollwr_hdr->mask;
31793175
31803176 while (wait_count < poll) {
31813177 qla8044_rd_reg_indirect(vha, addr1, &r_value);
drivers/scsi/qla2xxx/qla_nx2.h+4−2
@@ -58,8 +58,10 @@ · 57 unmodified lines
5858 #define QLA8044_PCI_QDR_NET_MAX ((unsigned long)0x043fffff)
5959
6060 /* PCI Windowing for DDR regions. */
61−#define QLA8044_ADDR_IN_RANGE(addr, low, high) \
62− (((addr) <= (high)) && ((addr) >= (low)))
61+static inline bool addr_in_range(u64 addr, u64 low, u64 high)
62+{
63+ return addr <= high && addr >= low;
64+}
6365
6466 /* Indirectly Mapped Registers */
6567 #define QLA8044_FLASH_SPI_STATUS 0x2808E010
drivers/scsi/qla2xxx/qla_os.c+19−22
@@ -656,7 +656,7 @@ qla2x00_sp_compl(void *data, void *ptr, int res) · 655 unmodified lines
656656 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
657657 sp, GET_CMD_SP(sp));
658658 if (ql2xextended_error_logging & ql_dbg_io)
659− BUG();
659+ WARN_ON(atomic_read(&sp->ref_count) == 0);
660660 return;
661661 }
662662 if (!atomic_dec_and_test(&sp->ref_count))
@@ -958,8 +958,8 @@ qla2xxx_eh_abort(struct scsi_cmnd *cmd) · 295 unmodified lines
958958 }
959959
960960 ql_dbg(ql_dbg_taskm, vha, 0x8002,
961− "Aborting from RISC nexus=%ld:%d:%llu sp=%p cmd=%p\n",
962− vha->host_no, id, lun, sp, cmd);
961+ "Aborting from RISC nexus=%ld:%d:%llu sp=%p cmd=%p handle=%x\n",
962+ vha->host_no, id, lun, sp, cmd, sp->handle);
963963
964964 /* Get a reference to the sp and drop the lock.*/
965965 sp_get(sp);
@@ -967,14 +967,9 @@ qla2xxx_eh_abort(struct scsi_cmnd *cmd) · 1 unmodified line
967967 spin_unlock_irqrestore(&ha->hardware_lock, flags);
968968 rval = ha->isp_ops->abort_command(sp);
969969 if (rval) {
970− if (rval == QLA_FUNCTION_PARAMETER_ERROR) {
971− /*
972− * Decrement the ref_count since we can't find the
973− * command
974− */
975− atomic_dec(&sp->ref_count);
970+ if (rval == QLA_FUNCTION_PARAMETER_ERROR)
976971 ret = SUCCESS;
977− } else
972+ else
978973 ret = FAILED;
979974
980975 ql_dbg(ql_dbg_taskm, vha, 0x8003,
@@ -986,12 +981,6 @@ qla2xxx_eh_abort(struct scsi_cmnd *cmd) · 5 unmodified lines
986981 }
987982
988983 spin_lock_irqsave(&ha->hardware_lock, flags);
989− /*
990− * Clear the slot in the oustanding_cmds array if we can't find the
991− * command to reclaim the resources.
992− */
993− if (rval == QLA_FUNCTION_PARAMETER_ERROR)
994− vha->req->outstanding_cmds[sp->handle] = NULL;
995984 sp->done(ha, sp, 0);
996985 spin_unlock_irqrestore(&ha->hardware_lock, flags);
997986
@@ -2219,6 +2208,13 @@ qla2x00_set_isp_flags(struct qla_hw_data *ha) · 1221 unmodified lines
22192208 ha->device_type |= DT_IIDMA;
22202209 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
22212210 break;
2211+ case PCI_DEVICE_ID_QLOGIC_ISP2261:
2212+ ha->device_type |= DT_ISP2261;
2213+ ha->device_type |= DT_ZIO_SUPPORTED;
2214+ ha->device_type |= DT_FWI2;
2215+ ha->device_type |= DT_IIDMA;
2216+ ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2217+ break;
22222218 }
22232219
22242220 if (IS_QLA82XX(ha))
@@ -2296,7 +2292,8 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id) · 71 unmodified lines
22962292 pdev->device == PCI_DEVICE_ID_QLOGIC_ISPF001 ||
22972293 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8044 ||
22982294 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2071 ||
2299− pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2271) {
2295+ pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2271 ||
2296+ pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2261) {
23002297 bars = pci_select_bars(pdev, IORESOURCE_MEM);
23012298 mem_only = 1;
23022299 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
@@ -2974,7 +2971,6 @@ qla2x00_shutdown(struct pci_dev *pdev) · 671 unmodified lines
29742971 static void
29752972 qla2x00_delete_all_vps(struct qla_hw_data *ha, scsi_qla_host_t *base_vha)
29762973 {
2977− struct Scsi_Host *scsi_host;
29782974 scsi_qla_host_t *vha;
29792975 unsigned long flags;
29802976
@@ -2985,7 +2981,7 @@ qla2x00_delete_all_vps(struct qla_hw_data *ha, scsi_qla_host_t *base_vha) · 4 unmodified lines
29852981 BUG_ON(base_vha->list.next == &ha->vp_list);
29862982 /* This assumes first entry in ha->vp_list is always base vha */
29872983 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
2988− scsi_host = scsi_host_get(vha->host);
2984+ scsi_host_get(vha->host);
29892985
29902986 spin_unlock_irqrestore(&ha->vport_slock, flags);
29912987 mutex_unlock(&ha->vport_lock);
@@ -3275,9 +3271,10 @@ void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport, · 283 unmodified lines
32753271 if (!do_login)
32763272 return;
32773273
3274+ set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
3275+
32783276 if (fcport->login_retry == 0) {
32793277 fcport->login_retry = vha->hw->login_retry_count;
3280− set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
32813278
32823279 ql_dbg(ql_dbg_disc, vha, 0x2067,
32833280 "Port login retry %8phN, id = 0x%04x retry cnt=%d.\n",
@@ -4801,7 +4798,6 @@ qla2x00_disable_board_on_pci_error(struct work_struct *work) · 1517 unmodified lines
48014798 static int
48024799 qla2x00_do_dpc(void *data)
48034800 {
4804− int rval;
48054801 scsi_qla_host_t *base_vha;
48064802 struct qla_hw_data *ha;
48074803
@@ -5033,7 +5029,7 @@ loop_resync_check: · 225 unmodified lines
50335029 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
50345030 &base_vha->dpc_flags))) {
50355031
5036− rval = qla2x00_loop_resync(base_vha);
5032+ qla2x00_loop_resync(base_vha);
50375033
50385034 clear_bit(LOOP_RESYNC_ACTIVE,
50395035 &base_vha->dpc_flags);
@@ -5717,6 +5713,7 @@ static struct pci_device_id qla2xxx_pci_tbl[] = { · 677 unmodified lines
57175713 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8044) },
57185714 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2071) },
57195715 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2271) },
5716+ { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2261) },
57205717 { 0 },
57215718 };
57225719 MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
drivers/scsi/qla2xxx/qla_sup.c+7−7
@@ -316,7 +316,7 @@ qla2x00_clear_nvram_protection(struct qla_hw_data *ha) · 315 unmodified lines
316316
317317 wprot_old = cpu_to_le16(qla2x00_get_nvram_word(ha, ha->nvram_base));
318318 stat = qla2x00_write_nvram_word_tmo(ha, ha->nvram_base,
319− __constant_cpu_to_le16(0x1234), 100000);
319+ cpu_to_le16(0x1234), 100000);
320320 wprot = cpu_to_le16(qla2x00_get_nvram_word(ha, ha->nvram_base));
321321 if (stat != QLA_SUCCESS || wprot != 0x1234) {
322322 /* Write enable. */
@@ -691,9 +691,9 @@ qla2xxx_get_flt_info(scsi_qla_host_t *vha, uint32_t flt_addr) · 368 unmodified lines
691691 region = (struct qla_flt_region *)&flt[1];
692692 ha->isp_ops->read_optrom(vha, (uint8_t *)req->ring,
693693 flt_addr << 2, OPTROM_BURST_SIZE);
694− if (*wptr == __constant_cpu_to_le16(0xffff))
694+ if (*wptr == cpu_to_le16(0xffff))
695695 goto no_flash_data;
696− if (flt->version != __constant_cpu_to_le16(1)) {
696+ if (flt->version != cpu_to_le16(1)) {
697697 ql_log(ql_log_warn, vha, 0x0047,
698698 "Unsupported FLT detected: version=0x%x length=0x%x checksum=0x%x.\n",
699699 le16_to_cpu(flt->version), le16_to_cpu(flt->length),
@@ -892,7 +892,7 @@ qla2xxx_get_fdt_info(scsi_qla_host_t *vha) · 192 unmodified lines
892892 fdt = (struct qla_fdt_layout *)req->ring;
893893 ha->isp_ops->read_optrom(vha, (uint8_t *)req->ring,
894894 ha->flt_region_fdt << 2, OPTROM_BURST_SIZE);
895− if (*wptr == __constant_cpu_to_le16(0xffff))
895+ if (*wptr == cpu_to_le16(0xffff))
896896 goto no_flash_data;
897897 if (fdt->sig[0] != 'Q' || fdt->sig[1] != 'L' || fdt->sig[2] != 'I' ||
898898 fdt->sig[3] != 'D')
@@ -991,7 +991,7 @@ qla2xxx_get_idc_param(scsi_qla_host_t *vha) · 92 unmodified lines
991991 ha->isp_ops->read_optrom(vha, (uint8_t *)req->ring,
992992 QLA82XX_IDC_PARAM_ADDR , 8);
993993
994− if (*wptr == __constant_cpu_to_le32(0xffffffff)) {
994+ if (*wptr == cpu_to_le32(0xffffffff)) {
995995 ha->fcoe_dev_init_timeout = QLA82XX_ROM_DEV_INIT_TIMEOUT;
996996 ha->fcoe_reset_timeout = QLA82XX_ROM_DRV_RESET_ACK_TIMEOUT;
997997 } else {
@@ -1051,9 +1051,9 @@ qla2xxx_flash_npiv_conf(scsi_qla_host_t *vha) · 53 unmodified lines
10511051
10521052 ha->isp_ops->read_optrom(vha, (uint8_t *)&hdr,
10531053 ha->flt_region_npiv_conf << 2, sizeof(struct qla_npiv_header));
1054− if (hdr.version == __constant_cpu_to_le16(0xffff))
1054+ if (hdr.version == cpu_to_le16(0xffff))
10551055 return;
1056− if (hdr.version != __constant_cpu_to_le16(1)) {
1056+ if (hdr.version != cpu_to_le16(1)) {
10571057 ql_dbg(ql_dbg_user, vha, 0x7090,
10581058 "Unsupported NPIV-Config "
10591059 "detected: version=0x%x entries=0x%x checksum=0x%x.\n",
drivers/scsi/qla2xxx/qla_target.c+64−75
@@ -1141,7 +1141,7 @@ static void qlt_send_notify_ack(struct scsi_qla_host *vha, · 1140 unmodified lines
11411141 nack->u.isp24.nport_handle = ntfy->u.isp24.nport_handle;
11421142 if (le16_to_cpu(ntfy->u.isp24.status) == IMM_NTFY_ELS) {
11431143 nack->u.isp24.flags = ntfy->u.isp24.flags &
1144− __constant_cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB);
1144+ cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB);
11451145 }
11461146 nack->u.isp24.srr_rx_id = ntfy->u.isp24.srr_rx_id;
11471147 nack->u.isp24.status = ntfy->u.isp24.status;
@@ -1199,7 +1199,7 @@ static void qlt_24xx_send_abts_resp(struct scsi_qla_host *vha, · 51 unmodified lines
11991199 resp->sof_type = abts->sof_type;
12001200 resp->exchange_address = abts->exchange_address;
12011201 resp->fcp_hdr_le = abts->fcp_hdr_le;
1202− f_ctl = __constant_cpu_to_le32(F_CTL_EXCH_CONTEXT_RESP |
1202+ f_ctl = cpu_to_le32(F_CTL_EXCH_CONTEXT_RESP |
12031203 F_CTL_LAST_SEQ | F_CTL_END_SEQ |
12041204 F_CTL_SEQ_INITIATIVE);
12051205 p = (uint8_t *)&f_ctl;
@@ -1274,15 +1274,14 @@ static void qlt_24xx_retry_term_exchange(struct scsi_qla_host *vha, · 68 unmodified lines
12741274 ctio->entry_count = 1;
12751275 ctio->nport_handle = entry->nport_handle;
12761276 ctio->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK;
1277− ctio->timeout = __constant_cpu_to_le16(QLA_TGT_TIMEOUT);
1277+ ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
12781278 ctio->vp_index = vha->vp_idx;
12791279 ctio->initiator_id[0] = entry->fcp_hdr_le.d_id[0];
12801280 ctio->initiator_id[1] = entry->fcp_hdr_le.d_id[1];
12811281 ctio->initiator_id[2] = entry->fcp_hdr_le.d_id[2];
12821282 ctio->exchange_addr = entry->exchange_addr_to_abort;
1283− ctio->u.status1.flags =
1284− __constant_cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1 |
1285− CTIO7_FLAGS_TERMINATE);
1283+ ctio->u.status1.flags = cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1 |
1284+ CTIO7_FLAGS_TERMINATE);
12861285 ctio->u.status1.ox_id = cpu_to_le16(entry->fcp_hdr_le.ox_id);
12871286
12881287 /* Memory Barrier */
@@ -1522,20 +1521,19 @@ static void qlt_24xx_send_task_mgmt_ctio(struct scsi_qla_host *ha, · 233 unmodified lines
15221521 ctio->entry_count = 1;
15231522 ctio->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK;
15241523 ctio->nport_handle = mcmd->sess->loop_id;
1525− ctio->timeout = __constant_cpu_to_le16(QLA_TGT_TIMEOUT);
1524+ ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
15261525 ctio->vp_index = ha->vp_idx;
15271526 ctio->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2];
15281527 ctio->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1];
15291528 ctio->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0];
15301529 ctio->exchange_addr = atio->u.isp24.exchange_addr;
15311530 ctio->u.status1.flags = (atio->u.isp24.attr << 9) |
1532− __constant_cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1 |
1533− CTIO7_FLAGS_SEND_STATUS);
1531+ cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS);
15341532 temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id);
15351533 ctio->u.status1.ox_id = cpu_to_le16(temp);
15361534 ctio->u.status1.scsi_status =
1537− __constant_cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID);
1538− ctio->u.status1.response_len = __constant_cpu_to_le16(8);
1535+ cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID);
1536+ ctio->u.status1.response_len = cpu_to_le16(8);
15391537 ctio->u.status1.sense_data[0] = resp_code;
15401538
15411539 /* Memory Barrier */
@@ -1786,7 +1784,7 @@ static int qlt_24xx_build_ctio_pkt(struct qla_tgt_prm *prm, · 244 unmodified lines
17861784
17871785 pkt->handle = h | CTIO_COMPLETION_HANDLE_MARK;
17881786 pkt->nport_handle = prm->cmd->loop_id;
1789− pkt->timeout = __constant_cpu_to_le16(QLA_TGT_TIMEOUT);
1787+ pkt->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
17901788 pkt->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2];
17911789 pkt->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1];
17921790 pkt->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0];
@@ -2087,10 +2085,9 @@ static void qlt_24xx_init_ctio_to_isp(struct ctio7_to_24xx *ctio, · 294 unmodified lines
20872085 {
20882086 prm->sense_buffer_len = min_t(uint32_t, prm->sense_buffer_len,
20892087 (uint32_t)sizeof(ctio->u.status1.sense_data));
2090− ctio->u.status0.flags |=
2091− __constant_cpu_to_le16(CTIO7_FLAGS_SEND_STATUS);
2088+ ctio->u.status0.flags |= cpu_to_le16(CTIO7_FLAGS_SEND_STATUS);
20922089 if (qlt_need_explicit_conf(prm->tgt->ha, prm->cmd, 0)) {
2093− ctio->u.status0.flags |= __constant_cpu_to_le16(
2090+ ctio->u.status0.flags |= cpu_to_le16(
20942091 CTIO7_FLAGS_EXPLICIT_CONFORM |
20952092 CTIO7_FLAGS_CONFORM_REQ);
20962093 }
@@ -2107,17 +2104,17 @@ static void qlt_24xx_init_ctio_to_isp(struct ctio7_to_24xx *ctio, · 10 unmodified lines
21072104 "non GOOD status\n");
21082105 goto skip_explict_conf;
21092106 }
2110− ctio->u.status1.flags |= __constant_cpu_to_le16(
2107+ ctio->u.status1.flags |= cpu_to_le16(
21112108 CTIO7_FLAGS_EXPLICIT_CONFORM |
21122109 CTIO7_FLAGS_CONFORM_REQ);
21132110 }
21142111 skip_explict_conf:
21152112 ctio->u.status1.flags &=
2116− ~__constant_cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0);
2113+ ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0);
21172114 ctio->u.status1.flags |=
2118− __constant_cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1);
2115+ cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1);
21192116 ctio->u.status1.scsi_status |=
2120− __constant_cpu_to_le16(SS_SENSE_LEN_VALID);
2117+ cpu_to_le16(SS_SENSE_LEN_VALID);
21212118 ctio->u.status1.sense_length =
21222119 cpu_to_le16(prm->sense_buffer_len);
21232120 for (i = 0; i < prm->sense_buffer_len/4; i++)
@@ -2137,9 +2134,9 @@ skip_explict_conf: · 13 unmodified lines
21372134 #endif
21382135 } else {
21392136 ctio->u.status1.flags &=
2140− ~__constant_cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0);
2137+ ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0);
21412138 ctio->u.status1.flags |=
2142− __constant_cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1);
2139+ cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1);
21432140 ctio->u.status1.sense_length = 0;
21442141 memset(ctio->u.status1.sense_data, 0,
21452142 sizeof(ctio->u.status1.sense_data));
@@ -2261,7 +2258,6 @@ static inline int · 115 unmodified lines
22612258 qlt_build_ctio_crc2_pkt(struct qla_tgt_prm *prm, scsi_qla_host_t *vha)
22622259 {
22632260 uint32_t *cur_dsd;
2264− int sgc;
22652261 uint32_t transfer_length = 0;
22662262 uint32_t data_bytes;
22672263 uint32_t dif_bytes;
@@ -2278,7 +2274,6 @@ qlt_build_ctio_crc2_pkt(struct qla_tgt_prm *prm, scsi_qla_host_t *vha) · 10 unmodified lines
22782274 struct atio_from_isp *atio = &prm->cmd->atio;
22792275 uint16_t t16;
22802276
2281− sgc = 0;
22822277 ha = vha->hw;
22832278
22842279 pkt = (struct ctio_crc2_to_fw *)vha->req->ring_ptr;
@@ -2368,7 +2363,7 @@ qlt_build_ctio_crc2_pkt(struct qla_tgt_prm *prm, scsi_qla_host_t *vha) · 83 unmodified lines
23682363
23692364 pkt->handle = h | CTIO_COMPLETION_HANDLE_MARK;
23702365 pkt->nport_handle = prm->cmd->loop_id;
2371− pkt->timeout = __constant_cpu_to_le16(QLA_TGT_TIMEOUT);
2366+ pkt->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
23722367 pkt->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2];
23732368 pkt->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1];
23742369 pkt->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0];
@@ -2384,9 +2379,9 @@ qlt_build_ctio_crc2_pkt(struct qla_tgt_prm *prm, scsi_qla_host_t *vha) · 9 unmodified lines
23842379
23852380 /* Set transfer direction */
23862381 if (cmd->dma_data_direction == DMA_TO_DEVICE)
2387− pkt->flags = __constant_cpu_to_le16(CTIO7_FLAGS_DATA_IN);
2382+ pkt->flags = cpu_to_le16(CTIO7_FLAGS_DATA_IN);
23882383 else if (cmd->dma_data_direction == DMA_FROM_DEVICE)
2389− pkt->flags = __constant_cpu_to_le16(CTIO7_FLAGS_DATA_OUT);
2384+ pkt->flags = cpu_to_le16(CTIO7_FLAGS_DATA_OUT);
23902385
23912386
23922387 pkt->dseg_count = prm->tot_dsds;
@@ -2438,11 +2433,11 @@ qlt_build_ctio_crc2_pkt(struct qla_tgt_prm *prm, scsi_qla_host_t *vha) · 45 unmodified lines
24382433 crc_ctx_pkt->blk_size = cpu_to_le16(cmd->blk_sz);
24392434 crc_ctx_pkt->prot_opts = cpu_to_le16(fw_prot_opts);
24402435 crc_ctx_pkt->byte_count = cpu_to_le32(data_bytes);
2441− crc_ctx_pkt->guard_seed = __constant_cpu_to_le16(0);
2436+ crc_ctx_pkt->guard_seed = cpu_to_le16(0);
24422437
24432438
24442439 /* Walks data segments */
2445− pkt->flags |= __constant_cpu_to_le16(CTIO7_FLAGS_DSD_PTR);
2440+ pkt->flags |= cpu_to_le16(CTIO7_FLAGS_DSD_PTR);
24462441
24472442 if (!bundling && prm->prot_seg_cnt) {
24482443 if (qla24xx_walk_and_build_sglist_no_difb(ha, NULL, cur_dsd,
@@ -2548,7 +2543,7 @@ int qlt_xmit_response(struct qla_tgt_cmd *cmd, int xmit_type, · 99 unmodified lines
25482543
25492544 if (qlt_has_data(cmd) && (xmit_type & QLA_TGT_XMIT_DATA)) {
25502545 pkt->u.status0.flags |=
2551− __constant_cpu_to_le16(CTIO7_FLAGS_DATA_IN |
2546+ cpu_to_le16(CTIO7_FLAGS_DATA_IN |
25522547 CTIO7_FLAGS_STATUS_MODE_0);
25532548
25542549 if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL)
@@ -2560,11 +2555,11 @@ int qlt_xmit_response(struct qla_tgt_cmd *cmd, int xmit_type, · 5 unmodified lines
25602555 cpu_to_le16(prm.rq_result);
25612556 pkt->u.status0.residual =
25622557 cpu_to_le32(prm.residual);
2563− pkt->u.status0.flags |= __constant_cpu_to_le16(
2558+ pkt->u.status0.flags |= cpu_to_le16(
25642559 CTIO7_FLAGS_SEND_STATUS);
25652560 if (qlt_need_explicit_conf(ha, cmd, 0)) {
25662561 pkt->u.status0.flags |=
2567− __constant_cpu_to_le16(
2562+ cpu_to_le16(
25682563 CTIO7_FLAGS_EXPLICIT_CONFORM |
25692564 CTIO7_FLAGS_CONFORM_REQ);
25702565 }
@@ -2592,12 +2587,12 @@ int qlt_xmit_response(struct qla_tgt_cmd *cmd, int xmit_type, · 21 unmodified lines
25922587 ctio->entry_count = 1;
25932588 ctio->entry_type = CTIO_TYPE7;
25942589 ctio->dseg_count = 0;
2595− ctio->u.status1.flags &= ~__constant_cpu_to_le16(
2590+ ctio->u.status1.flags &= ~cpu_to_le16(
25962591 CTIO7_FLAGS_DATA_IN);
25972592
25982593 /* Real finish is ctio_m1's finish */
25992594 pkt->handle |= CTIO_INTERMEDIATE_HANDLE_MARK;
2600− pkt->u.status0.flags |= __constant_cpu_to_le16(
2595+ pkt->u.status0.flags |= cpu_to_le16(
26012596 CTIO7_FLAGS_DONT_RET_CTIO);
26022597
26032598 /* qlt_24xx_init_ctio_to_isp will correct
@@ -2687,7 +2682,7 @@ int qlt_rdy_to_xfer(struct qla_tgt_cmd *cmd) · 83 unmodified lines
26872682 }
26882683
26892684 pkt = (struct ctio7_to_24xx *)prm.pkt;
2690− pkt->u.status0.flags |= __constant_cpu_to_le16(CTIO7_FLAGS_DATA_OUT |
2685+ pkt->u.status0.flags |= cpu_to_le16(CTIO7_FLAGS_DATA_OUT |
26912686 CTIO7_FLAGS_STATUS_MODE_0);
26922687
26932688 if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL)
@@ -2762,7 +2757,7 @@ qlt_handle_dif_error(struct scsi_qla_host *vha, struct qla_tgt_cmd *cmd, · 68 unmodified lines
27622757
27632758 /* Update protection tag */
27642759 if (cmd->prot_sg_cnt) {
2765− uint32_t i, j = 0, k = 0, num_ent;
2760+ uint32_t i, k = 0, num_ent;
27662761 struct scatterlist *sg, *sgl;
27672762
27682763
@@ -2775,7 +2770,6 @@ qlt_handle_dif_error(struct scsi_qla_host *vha, struct qla_tgt_cmd *cmd, · 6 unmodified lines
27752770 k += num_ent;
27762771 continue;
27772772 }
2778− j = blocks_done - k - 1;
27792773 k = blocks_done;
27802774 break;
27812775 }
@@ -2969,14 +2963,14 @@ static int __qlt_send_term_exchange(struct scsi_qla_host *vha, · 187 unmodified lines
29692963 ctio24 = (struct ctio7_to_24xx *)pkt;
29702964 ctio24->entry_type = CTIO_TYPE7;
29712965 ctio24->nport_handle = cmd ? cmd->loop_id : CTIO7_NHANDLE_UNRECOGNIZED;
2972− ctio24->timeout = __constant_cpu_to_le16(QLA_TGT_TIMEOUT);
2966+ ctio24->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
29732967 ctio24->vp_index = vha->vp_idx;
29742968 ctio24->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2];
29752969 ctio24->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1];
29762970 ctio24->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0];
29772971 ctio24->exchange_addr = atio->u.isp24.exchange_addr;
29782972 ctio24->u.status1.flags = (atio->u.isp24.attr << 9) |
2979− __constant_cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1 |
2973+ cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1 |
29802974 CTIO7_FLAGS_TERMINATE);
29812975 temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id);
29822976 ctio24->u.status1.ox_id = cpu_to_le16(temp);
@@ -3216,7 +3210,7 @@ static int qlt_term_ctio_exchange(struct scsi_qla_host *vha, void *ctio, · 233 unmodified lines
32163210 if (ctio != NULL) {
32173211 struct ctio7_from_24xx *c = (struct ctio7_from_24xx *)ctio;
32183212 term = !(c->flags &
3219− __constant_cpu_to_le16(OF_TERM_EXCH));
3213+ cpu_to_le16(OF_TERM_EXCH));
32203214 } else
32213215 term = 1;
32223216
@@ -3364,7 +3358,6 @@ static void qlt_do_ctio_completion(struct scsi_qla_host *vha, uint32_t handle, · 141 unmodified lines
33643358 {
33653359 struct qla_hw_data *ha = vha->hw;
33663360 struct se_cmd *se_cmd;
3367− const struct target_core_fabric_ops *tfo;
33683361 struct qla_tgt_cmd *cmd;
33693362
33703363 if (handle & CTIO_INTERMEDIATE_HANDLE_MARK) {
@@ -3382,7 +3375,6 @@ static void qlt_do_ctio_completion(struct scsi_qla_host *vha, uint32_t handle, · 11 unmodified lines
33823375 return;
33833376
33843377 se_cmd = &cmd->se_cmd;
3385− tfo = se_cmd->se_tfo;
33863378 cmd->cmd_sent_to_fw = 0;
33873379
33883380 qlt_unmap_sg(vha, cmd);
@@ -3480,13 +3472,9 @@ skip_term: · 91 unmodified lines
34803472 if (cmd->state == QLA_TGT_STATE_PROCESSED) {
34813473 cmd->cmd_flags |= BIT_12;
34823474 } else if (cmd->state == QLA_TGT_STATE_NEED_DATA) {
3483− int rx_status = 0;
3484−
34853475 cmd->state = QLA_TGT_STATE_DATA_IN;
34863476
3487− if (unlikely(status != CTIO_SUCCESS))
3488− rx_status = -EIO;
3489− else
3477+ if (status == CTIO_SUCCESS)
34903478 cmd->write_data_transferred = 1;
34913479
34923480 ha->tgt.tgt_ops->handle_data(cmd);
@@ -3928,12 +3916,11 @@ static int qlt_handle_task_mgmt(struct scsi_qla_host *vha, void *iocb) · 435 unmodified lines
39283916 struct qla_tgt *tgt;
39293917 struct qla_tgt_sess *sess;
39303918 uint32_t lun, unpacked_lun;
3931− int lun_size, fn;
3919+ int fn;
39323920
39333921 tgt = vha->vha_tgt.qla_tgt;
39343922
39353923 lun = a->u.isp24.fcp_cmnd.lun;
3936− lun_size = sizeof(a->u.isp24.fcp_cmnd.lun);
39373924 fn = a->u.isp24.fcp_cmnd.task_mgmt_flags;
39383925 sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha,
39393926 a->u.isp24.fcp_hdr.s_id);
@@ -4578,16 +4565,20 @@ static void qlt_reject_free_srr_imm(struct scsi_qla_host *vha, · 638 unmodified lines
45784565 struct qla_hw_data *ha = vha->hw;
45794566 unsigned long flags = 0;
45804567
4568+#ifndef __CHECKER__
45814569 if (!ha_locked)
45824570 spin_lock_irqsave(&ha->hardware_lock, flags);
4571+#endif
45834572
45844573 qlt_send_notify_ack(vha, (void *)&imm->imm_ntfy, 0, 0, 0,
45854574 NOTIFY_ACK_SRR_FLAGS_REJECT,
45864575 NOTIFY_ACK_SRR_REJECT_REASON_UNABLE_TO_PERFORM,
45874576 NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_NO_EXPL);
45884577
4578+#ifndef __CHECKER__
45894579 if (!ha_locked)
45904580 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4581+#endif
45914582
45924583 kfree(imm);
45934584 }
@@ -4931,14 +4922,14 @@ static int __qlt_send_busy(struct scsi_qla_host *vha, · 337 unmodified lines
49314922 ctio24 = (struct ctio7_to_24xx *)pkt;
49324923 ctio24->entry_type = CTIO_TYPE7;
49334924 ctio24->nport_handle = sess->loop_id;
4934− ctio24->timeout = __constant_cpu_to_le16(QLA_TGT_TIMEOUT);
4925+ ctio24->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
49354926 ctio24->vp_index = vha->vp_idx;
49364927 ctio24->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2];
49374928 ctio24->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1];
49384929 ctio24->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0];
49394930 ctio24->exchange_addr = atio->u.isp24.exchange_addr;
49404931 ctio24->u.status1.flags = (atio->u.isp24.attr << 9) |
4941− __constant_cpu_to_le16(
4932+ cpu_to_le16(
49424933 CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS |
49434934 CTIO7_FLAGS_DONT_RET_CTIO);
49444935 /*
@@ -5266,7 +5257,7 @@ static void qlt_response_pkt(struct scsi_qla_host *vha, response_t *pkt) · 321 unmodified lines
52665257 struct atio_from_isp *atio = (struct atio_from_isp *)pkt;
52675258 int rc;
52685259 if (atio->u.isp2x.status !=
5269− __constant_cpu_to_le16(ATIO_CDB_VALID)) {
5260+ cpu_to_le16(ATIO_CDB_VALID)) {
52705261 ql_dbg(ql_dbg_tgt, vha, 0xe05e,
52715262 "qla_target(%d): ATIO with error "
52725263 "status %x received\n", vha->vp_idx,
@@ -5340,7 +5331,7 @@ static void qlt_response_pkt(struct scsi_qla_host *vha, response_t *pkt) · 67 unmodified lines
53405331 le16_to_cpu(entry->u.isp2x.status));
53415332 tgt->notify_ack_expected--;
53425333 if (entry->u.isp2x.status !=
5343− __constant_cpu_to_le16(NOTIFY_ACK_SUCCESS)) {
5334+ cpu_to_le16(NOTIFY_ACK_SUCCESS)) {
53445335 ql_dbg(ql_dbg_tgt, vha, 0xe061,
53455336 "qla_target(%d): NOTIFY_ACK "
53465337 "failed %x\n", vha->vp_idx,
@@ -5659,7 +5650,7 @@ static void qlt_tmr_work(struct qla_tgt *tgt, · 312 unmodified lines
56595650 uint8_t *s_id = NULL; /* to hide compiler warnings */
56605651 int rc;
56615652 uint32_t lun, unpacked_lun;
5662− int lun_size, fn;
5653+ int fn;
56635654 void *iocb;
56645655
56655656 spin_lock_irqsave(&ha->hardware_lock, flags);
@@ -5691,7 +5682,6 @@ static void qlt_tmr_work(struct qla_tgt *tgt, · 25 unmodified lines
56915682
56925683 iocb = a;
56935684 lun = a->u.isp24.fcp_cmnd.lun;
5694− lun_size = sizeof(lun);
56955685 fn = a->u.isp24.fcp_cmnd.task_mgmt_flags;
56965686 unpacked_lun = scsilun_to_int((struct scsi_lun *)&lun);
56975687
@@ -6215,19 +6205,19 @@ qlt_24xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_24xx *nv) · 517 unmodified lines
62156205 ha->tgt.saved_set = 1;
62166206 }
62176207
6218− nv->exchange_count = __constant_cpu_to_le16(0xFFFF);
6208+ nv->exchange_count = cpu_to_le16(0xFFFF);
62196209
62206210 /* Enable target mode */
6221− nv->firmware_options_1 |= __constant_cpu_to_le32(BIT_4);
6211+ nv->firmware_options_1 |= cpu_to_le32(BIT_4);
62226212
62236213 /* Disable ini mode, if requested */
62246214 if (!qla_ini_mode_enabled(vha))
6225− nv->firmware_options_1 |= __constant_cpu_to_le32(BIT_5);
6215+ nv->firmware_options_1 |= cpu_to_le32(BIT_5);
62266216
62276217 /* Disable Full Login after LIP */
6228− nv->firmware_options_1 &= __constant_cpu_to_le32(~BIT_13);
6218+ nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
62296219 /* Enable initial LIP */
6230− nv->firmware_options_1 &= __constant_cpu_to_le32(~BIT_9);
6220+ nv->firmware_options_1 &= cpu_to_le32(~BIT_9);
62316221 if (ql2xtgt_tape_enable)
62326222 /* Enable FC Tape support */
62336223 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
@@ -6236,9 +6226,9 @@ qlt_24xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_24xx *nv) · 2 unmodified lines
62366226 nv->firmware_options_2 &= cpu_to_le32(~BIT_12);
62376227
62386228 /* Disable Full Login after LIP */
6239− nv->host_p &= __constant_cpu_to_le32(~BIT_10);
6229+ nv->host_p &= cpu_to_le32(~BIT_10);
62406230 /* Enable target PRLI control */
6241− nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_14);
6231+ nv->firmware_options_2 |= cpu_to_le32(BIT_14);
62426232 } else {
62436233 if (ha->tgt.saved_set) {
62446234 nv->exchange_count = ha->tgt.saved_exchange_count;
@@ -6260,12 +6250,12 @@ qlt_24xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_24xx *nv) · 15 unmodified lines
62606250 fc_host_supported_classes(vha->host) =
62616251 FC_COS_CLASS2 | FC_COS_CLASS3;
62626252
6263− nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_8);
6253+ nv->firmware_options_2 |= cpu_to_le32(BIT_8);
62646254 } else {
62656255 if (vha->flags.init_done)
62666256 fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
62676257
6268− nv->firmware_options_2 &= ~__constant_cpu_to_le32(BIT_8);
6258+ nv->firmware_options_2 &= ~cpu_to_le32(BIT_8);
62696259 }
62706260 }
62716261
@@ -6277,7 +6267,7 @@ qlt_24xx_config_nvram_stage2(struct scsi_qla_host *vha, · 5 unmodified lines
62776267
62786268 if (ha->tgt.node_name_set) {
62796269 memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE);
6280− icb->firmware_options_1 |= __constant_cpu_to_le32(BIT_14);
6270+ icb->firmware_options_1 |= cpu_to_le32(BIT_14);
62816271 }
62826272 }
62836273
@@ -6302,20 +6292,19 @@ qlt_81xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_81xx *nv) · 18 unmodified lines
63026292 ha->tgt.saved_set = 1;
63036293 }
63046294
6305− nv->exchange_count = __constant_cpu_to_le16(0xFFFF);
6295+ nv->exchange_count = cpu_to_le16(0xFFFF);
63066296
63076297 /* Enable target mode */
6308− nv->firmware_options_1 |= __constant_cpu_to_le32(BIT_4);
6298+ nv->firmware_options_1 |= cpu_to_le32(BIT_4);
63096299
63106300 /* Disable ini mode, if requested */
63116301 if (!qla_ini_mode_enabled(vha))
6312− nv->firmware_options_1 |=
6313− __constant_cpu_to_le32(BIT_5);
6302+ nv->firmware_options_1 |= cpu_to_le32(BIT_5);
63146303
63156304 /* Disable Full Login after LIP */
6316− nv->firmware_options_1 &= __constant_cpu_to_le32(~BIT_13);
6305+ nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
63176306 /* Enable initial LIP */
6318− nv->firmware_options_1 &= __constant_cpu_to_le32(~BIT_9);
6307+ nv->firmware_options_1 &= cpu_to_le32(~BIT_9);
63196308 if (ql2xtgt_tape_enable)
63206309 /* Enable FC tape support */
63216310 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
@@ -6324,9 +6313,9 @@ qlt_81xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_81xx *nv) · 2 unmodified lines
63246313 nv->firmware_options_2 &= cpu_to_le32(~BIT_12);
63256314
63266315 /* Disable Full Login after LIP */
6327− nv->host_p &= __constant_cpu_to_le32(~BIT_10);
6316+ nv->host_p &= cpu_to_le32(~BIT_10);
63286317 /* Enable target PRLI control */
6329− nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_14);
6318+ nv->firmware_options_2 |= cpu_to_le32(BIT_14);
63306319 } else {
63316320 if (ha->tgt.saved_set) {
63326321 nv->exchange_count = ha->tgt.saved_exchange_count;
@@ -6348,12 +6337,12 @@ qlt_81xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_81xx *nv) · 15 unmodified lines
63486337 fc_host_supported_classes(vha->host) =
63496338 FC_COS_CLASS2 | FC_COS_CLASS3;
63506339
6351− nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_8);
6340+ nv->firmware_options_2 |= cpu_to_le32(BIT_8);
63526341 } else {
63536342 if (vha->flags.init_done)
63546343 fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
63556344
6356− nv->firmware_options_2 &= ~__constant_cpu_to_le32(BIT_8);
6345+ nv->firmware_options_2 &= ~cpu_to_le32(BIT_8);
63576346 }
63586347 }
63596348
@@ -6368,7 +6357,7 @@ qlt_81xx_config_nvram_stage2(struct scsi_qla_host *vha, · 8 unmodified lines
63686357
63696358 if (ha->tgt.node_name_set) {
63706359 memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE);
6371− icb->firmware_options_1 |= __constant_cpu_to_le32(BIT_14);
6360+ icb->firmware_options_1 |= cpu_to_le32(BIT_14);
63726361 }
63736362 }
63746363
drivers/scsi/qla2xxx/qla_tmpl.c+15−12
@@ -137,39 +137,39 @@ qla27xx_insertbuf(void *mem, ulong size, void *buf, ulong *len) · 136 unmodified lines
137137 }
138138
139139 static inline void
140−qla27xx_read8(void *window, void *buf, ulong *len)
140+qla27xx_read8(void __iomem *window, void *buf, ulong *len)
141141 {
142142 uint8_t value = ~0;
143143
144144 if (buf) {
145− value = RD_REG_BYTE((__iomem void *)window);
145+ value = RD_REG_BYTE(window);
146146 }
147147 qla27xx_insert32(value, buf, len);
148148 }
149149
150150 static inline void
151−qla27xx_read16(void *window, void *buf, ulong *len)
151+qla27xx_read16(void __iomem *window, void *buf, ulong *len)
152152 {
153153 uint16_t value = ~0;
154154
155155 if (buf) {
156− value = RD_REG_WORD((__iomem void *)window);
156+ value = RD_REG_WORD(window);
157157 }
158158 qla27xx_insert32(value, buf, len);
159159 }
160160
161161 static inline void
162−qla27xx_read32(void *window, void *buf, ulong *len)
162+qla27xx_read32(void __iomem *window, void *buf, ulong *len)
163163 {
164164 uint32_t value = ~0;
165165
166166 if (buf) {
167− value = RD_REG_DWORD((__iomem void *)window);
167+ value = RD_REG_DWORD(window);
168168 }
169169 qla27xx_insert32(value, buf, len);
170170 }
171171
172−static inline void (*qla27xx_read_vector(uint width))(void *, void *, ulong *)
172+static inline void (*qla27xx_read_vector(uint width))(void __iomem*, void *, ulong *)
173173 {
174174 return
175175 (width == 1) ? qla27xx_read8 :
@@ -181,7 +181,7 @@ static inline void · 5 unmodified lines
181181 qla27xx_read_reg(__iomem struct device_reg_24xx *reg,
182182 uint offset, void *buf, ulong *len)
183183 {
184− void *window = (void *)reg + offset;
184+ void __iomem *window = (void __iomem *)reg + offset;
185185
186186 qla27xx_read32(window, buf, len);
187187 }
@@ -202,8 +202,8 @@ qla27xx_read_window(__iomem struct device_reg_24xx *reg, · 14 unmodified lines
202202 uint32_t addr, uint offset, uint count, uint width, void *buf,
203203 ulong *len)
204204 {
205− void *window = (void *)reg + offset;
206− void (*readn)(void *, void *, ulong *) = qla27xx_read_vector(width);
205+ void __iomem *window = (void __iomem *)reg + offset;
206+ void (*readn)(void __iomem*, void *, ulong *) = qla27xx_read_vector(width);
207207
208208 qla27xx_write_reg(reg, IOBASE_ADDR, addr, buf);
209209 while (count--) {
@@ -805,9 +805,8 @@ static void · 595 unmodified lines
805805 qla27xx_driver_info(struct qla27xx_fwdt_template *tmp)
806806 {
807807 uint8_t v[] = { 0, 0, 0, 0, 0, 0 };
808− int rval = 0;
809808
810− rval = sscanf(qla2x00_version_str, "%hhu.%hhu.%hhu.%hhu.%hhu.%hhu",
809+ sscanf(qla2x00_version_str, "%hhu.%hhu.%hhu.%hhu.%hhu.%hhu",
811810 v+0, v+1, v+2, v+3, v+4, v+5);
812811
813812 tmp->driver_info[0] = v[3] << 24 | v[2] << 16 | v[1] << 8 | v[0];
@@ -940,8 +939,10 @@ qla27xx_fwdump(scsi_qla_host_t *vha, int hardware_locked) · 126 unmodified lines
940939 {
941940 ulong flags = 0;
942941
942+#ifndef __CHECKER__
943943 if (!hardware_locked)
944944 spin_lock_irqsave(&vha->hw->hardware_lock, flags);
945+#endif
945946
946947 if (!vha->hw->fw_dump)
947948 ql_log(ql_log_warn, vha, 0xd01e, "fwdump buffer missing.\n");
@@ -954,6 +955,8 @@ qla27xx_fwdump(scsi_qla_host_t *vha, int hardware_locked) · 6 unmodified lines
954955 else
955956 qla27xx_execute_fwdt_template(vha);
956957
958+#ifndef __CHECKER__
957959 if (!hardware_locked)
958960 spin_unlock_irqrestore(&vha->hw->hardware_lock, flags);
961+#endif
959962 }
drivers/scsi/qla2xxx/qla_version.h+1−1
@@ -7,7 +7,7 @@ · 6 unmodified lines
77 /*
88 * Driver version
99 */
10−#define QLA2XXX_VERSION "8.07.00.18-k"
10+#define QLA2XXX_VERSION "8.07.00.26-k"
1111
1212 #define QLA_DRIVER_MAJOR_VER 8
1313 #define QLA_DRIVER_MINOR_VER 7
drivers/scsi/qla2xxx/tcm_qla2xxx.c+6−0
@@ -420,6 +420,12 @@ static void tcm_qla2xxx_set_default_node_attrs(struct se_node_acl *nacl) · 419 unmodified lines
420420
421421 static int tcm_qla2xxx_get_cmd_state(struct se_cmd *se_cmd)
422422 {
423+ if (!(se_cmd->se_cmd_flags & SCF_SCSI_TMR_CDB)) {
424+ struct qla_tgt_cmd *cmd = container_of(se_cmd,
425+ struct qla_tgt_cmd, se_cmd);
426+ return cmd->state;
427+ }
428+
423429 return 0;
424430 }
425431
drivers/scsi/scsi_error.c+9−0
@@ -420,6 +420,10 @@ static void scsi_report_sense(struct scsi_device *sdev, · 419 unmodified lines
420420 evt_type = SDEV_EVT_MODE_PARAMETER_CHANGE_REPORTED;
421421 sdev_printk(KERN_WARNING, sdev,
422422 "Mode parameters changed");
423+ } else if (sshdr->asc == 0x2a && sshdr->ascq == 0x06) {
424+ evt_type = SDEV_EVT_ALUA_STATE_CHANGE_REPORTED;
425+ sdev_printk(KERN_WARNING, sdev,
426+ "Asymmetric access state changed");
423427 } else if (sshdr->asc == 0x2a && sshdr->ascq == 0x09) {
424428 evt_type = SDEV_EVT_CAPACITY_CHANGE_REPORTED;
425429 sdev_printk(KERN_WARNING, sdev,
@@ -1155,8 +1159,13 @@ int scsi_eh_get_sense(struct list_head *work_q, · 729 unmodified lines
11551159 struct Scsi_Host *shost;
11561160 int rtn;
11571161
1162+ /*
1163+ * If SCSI_EH_ABORT_SCHEDULED has been set, it is timeout IO,
1164+ * should not get sense.
1165+ */
11581166 list_for_each_entry_safe(scmd, next, work_q, eh_entry) {
11591167 if ((scmd->eh_eflags & SCSI_EH_CANCEL_CMD) ||
1168+ (scmd->eh_eflags & SCSI_EH_ABORT_SCHEDULED) ||
11601169 SCSI_SENSE_VALID(scmd))
11611170 continue;
11621171
drivers/scsi/scsi_lib.c+10−1
@@ -2423,7 +2423,7 @@ scsi_mode_sense(struct scsi_device *sdev, int dbd, int modepage, · 2422 unmodified lines
24232423 unsigned char cmd[12];
24242424 int use_10_for_ms;
24252425 int header_length;
2426− int result;
2426+ int result, retry_count = retries;
24272427 struct scsi_sense_hdr my_sshdr;
24282428
24292429 memset(data, 0, sizeof(*data));
@@ -2502,6 +2502,11 @@ scsi_mode_sense(struct scsi_device *sdev, int dbd, int modepage, · 72 unmodified lines
25022502 data->block_descriptor_length = buffer[3];
25032503 }
25042504 data->header_length = header_length;
2505+ } else if ((status_byte(result) == CHECK_CONDITION) &&
2506+ scsi_sense_valid(sshdr) &&
2507+ sshdr->sense_key == UNIT_ATTENTION && retry_count) {
2508+ retry_count--;
2509+ goto retry;
25052510 }
25062511
25072512 return result;
@@ -2707,6 +2712,9 @@ static void scsi_evt_emit(struct scsi_device *sdev, struct scsi_event *evt) · 199 unmodified lines
27072712 case SDEV_EVT_LUN_CHANGE_REPORTED:
27082713 envp[idx++] = "SDEV_UA=REPORTED_LUNS_DATA_HAS_CHANGED";
27092714 break;
2715+ case SDEV_EVT_ALUA_STATE_CHANGE_REPORTED:
2716+ envp[idx++] = "SDEV_UA=ASYMMETRIC_ACCESS_STATE_CHANGED";
2717+ break;
27102718 default:
27112719 /* do nothing */
27122720 break;
@@ -2810,6 +2818,7 @@ struct scsi_event *sdev_evt_alloc(enum scsi_device_event evt_type, · 97 unmodified lines
28102818 case SDEV_EVT_SOFT_THRESHOLD_REACHED_REPORTED:
28112819 case SDEV_EVT_MODE_PARAMETER_CHANGE_REPORTED:
28122820 case SDEV_EVT_LUN_CHANGE_REPORTED:
2821+ case SDEV_EVT_ALUA_STATE_CHANGE_REPORTED:
28132822 default:
28142823 /* do nothing */
28152824 break;
drivers/scsi/scsi_transport_iscsi.c+8−3
@@ -2042,6 +2042,7 @@ iscsi_alloc_session(struct Scsi_Host *shost, struct iscsi_transport *transport, · 2041 unmodified lines
20422042 session->transport = transport;
20432043 session->creator = -1;
20442044 session->recovery_tmo = 120;
2045+ session->recovery_tmo_sysfs_override = false;
20452046 session->state = ISCSI_SESSION_FREE;
20462047 INIT_DELAYED_WORK(&session->recovery_work, session_recovery_timedout);
20472048 INIT_LIST_HEAD(&session->sess_list);
@@ -2786,7 +2787,8 @@ iscsi_set_param(struct iscsi_transport *transport, struct iscsi_uevent *ev) · 738 unmodified lines
27862787 switch (ev->u.set_param.param) {
27872788 case ISCSI_PARAM_SESS_RECOVERY_TMO:
27882789 sscanf(data, "%d", &value);
2789− session->recovery_tmo = value;
2790+ if (!session->recovery_tmo_sysfs_override)
2791+ session->recovery_tmo = value;
27902792 break;
27912793 default:
27922794 err = transport->set_param(conn, ev->u.set_param.param,
@@ -4049,13 +4051,15 @@ store_priv_session_##field(struct device *dev, \ · 1256 unmodified lines
40494051 if ((session->state == ISCSI_SESSION_FREE) || \
40504052 (session->state == ISCSI_SESSION_FAILED)) \
40514053 return -EBUSY; \
4052− if (strncmp(buf, "off", 3) == 0) \
4054+ if (strncmp(buf, "off", 3) == 0) { \
40534055 session->field = -1; \
4054− else { \
4056+ session->field##_sysfs_override = true; \
4057+ } else { \
40554058 val = simple_strtoul(buf, &cp, 0); \
40564059 if (*cp != '\0' && *cp != '\n') \
40574060 return -EINVAL; \
40584061 session->field = val; \
4062+ session->field##_sysfs_override = true; \
40594063 } \
40604064 return count; \
40614065 }
@@ -4066,6 +4070,7 @@ store_priv_session_##field(struct device *dev, \ · 4 unmodified lines
40664070 static ISCSI_CLASS_ATTR(priv_sess, field, S_IRUGO | S_IWUSR, \
40674071 show_priv_session_##field, \
40684072 store_priv_session_##field)
4073+
40694074 iscsi_priv_session_rw_attr(recovery_tmo, "%d");
40704075
40714076 static struct attribute *iscsi_session_attrs[] = {
drivers/scsi/st.c+23−60
@@ -85,6 +85,7 @@ static int debug_flag; · 84 unmodified lines
8585
8686 static struct class st_sysfs_class;
8787 static const struct attribute_group *st_dev_groups[];
88+static const struct attribute_group *st_drv_groups[];
8889
8990 MODULE_AUTHOR("Kai Makisara");
9091 MODULE_DESCRIPTION("SCSI tape (st) driver");
@@ -198,15 +199,13 @@ static int sgl_unmap_user_pages(struct st_buffer *, const unsigned int, int); · 107 unmodified lines
198199 static int st_probe(struct device *);
199200 static int st_remove(struct device *);
200201
201−static int do_create_sysfs_files(void);
202−static void do_remove_sysfs_files(void);
203−
204202 static struct scsi_driver st_template = {
205203 .gendrv = {
206204 .name = "st",
207205 .owner = THIS_MODULE,
208206 .probe = st_probe,
209207 .remove = st_remove,
208+ .groups = st_drv_groups,
210209 },
211210 };
212211
@@ -4404,14 +4403,8 @@ static int __init init_st(void) · 4191 unmodified lines
44044403 if (err)
44054404 goto err_chrdev;
44064405
4407− err = do_create_sysfs_files();
4408− if (err)
4409− goto err_scsidrv;
4410−
44114406 return 0;
44124407
4413−err_scsidrv:
4414− scsi_unregister_driver(&st_template.gendrv);
44154408 err_chrdev:
44164409 unregister_chrdev_region(MKDEV(SCSI_TAPE_MAJOR, 0),
44174410 ST_MAX_TAPE_ENTRIES);
@@ -4422,11 +4415,11 @@ err_class: · 4 unmodified lines
44224415
44234416 static void __exit exit_st(void)
44244417 {
4425− do_remove_sysfs_files();
44264418 scsi_unregister_driver(&st_template.gendrv);
44274419 unregister_chrdev_region(MKDEV(SCSI_TAPE_MAJOR, 0),
44284420 ST_MAX_TAPE_ENTRIES);
44294421 class_unregister(&st_sysfs_class);
4422+ idr_destroy(&st_index_idr);
44304423 printk(KERN_INFO "st: Unloaded.\n");
44314424 }
44324425
@@ -4435,68 +4428,38 @@ module_exit(exit_st); · 2 unmodified lines
44354428
44364429
44374430 /* The sysfs driver interface. Read-only at the moment */
4438−static ssize_t st_try_direct_io_show(struct device_driver *ddp, char *buf)
4431+static ssize_t try_direct_io_show(struct device_driver *ddp, char *buf)
44394432 {
4440− return snprintf(buf, PAGE_SIZE, "%d\n", try_direct_io);
4433+ return scnprintf(buf, PAGE_SIZE, "%d\n", try_direct_io);
44414434 }
4442−static DRIVER_ATTR(try_direct_io, S_IRUGO, st_try_direct_io_show, NULL);
4435+static DRIVER_ATTR_RO(try_direct_io);
44434436
4444−static ssize_t st_fixed_buffer_size_show(struct device_driver *ddp, char *buf)
4437+static ssize_t fixed_buffer_size_show(struct device_driver *ddp, char *buf)
44454438 {
4446− return snprintf(buf, PAGE_SIZE, "%d\n", st_fixed_buffer_size);
4439+ return scnprintf(buf, PAGE_SIZE, "%d\n", st_fixed_buffer_size);
44474440 }
4448−static DRIVER_ATTR(fixed_buffer_size, S_IRUGO, st_fixed_buffer_size_show, NULL);
4441+static DRIVER_ATTR_RO(fixed_buffer_size);
44494442
4450−static ssize_t st_max_sg_segs_show(struct device_driver *ddp, char *buf)
4443+static ssize_t max_sg_segs_show(struct device_driver *ddp, char *buf)
44514444 {
4452− return snprintf(buf, PAGE_SIZE, "%d\n", st_max_sg_segs);
4445+ return scnprintf(buf, PAGE_SIZE, "%d\n", st_max_sg_segs);
44534446 }
4454−static DRIVER_ATTR(max_sg_segs, S_IRUGO, st_max_sg_segs_show, NULL);
4447+static DRIVER_ATTR_RO(max_sg_segs);
44554448
4456−static ssize_t st_version_show(struct device_driver *ddd, char *buf)
4449+static ssize_t version_show(struct device_driver *ddd, char *buf)
44574450 {
4458− return snprintf(buf, PAGE_SIZE, "[%s]\n", verstr);
4451+ return scnprintf(buf, PAGE_SIZE, "[%s]\n", verstr);
44594452 }
4460−static DRIVER_ATTR(version, S_IRUGO, st_version_show, NULL);
4461−
4462−static int do_create_sysfs_files(void)
4463−{
4464− struct device_driver *sysfs = &st_template.gendrv;
4465− int err;
4453+static DRIVER_ATTR_RO(version);
44664454
4467− err = driver_create_file(sysfs, &driver_attr_try_direct_io);
4468− if (err)
4469− return err;
4470− err = driver_create_file(sysfs, &driver_attr_fixed_buffer_size);
4471− if (err)
4472− goto err_try_direct_io;
4473− err = driver_create_file(sysfs, &driver_attr_max_sg_segs);
4474− if (err)
4475− goto err_attr_fixed_buf;
4476− err = driver_create_file(sysfs, &driver_attr_version);
4477− if (err)
4478− goto err_attr_max_sg;
4479−
4480− return 0;
4481−
4482−err_attr_max_sg:
4483− driver_remove_file(sysfs, &driver_attr_max_sg_segs);
4484−err_attr_fixed_buf:
4485− driver_remove_file(sysfs, &driver_attr_fixed_buffer_size);
4486−err_try_direct_io:
4487− driver_remove_file(sysfs, &driver_attr_try_direct_io);
4488− return err;
4489−}
4490−
4491−static void do_remove_sysfs_files(void)
4492−{
4493− struct device_driver *sysfs = &st_template.gendrv;
4494−
4495− driver_remove_file(sysfs, &driver_attr_version);
4496− driver_remove_file(sysfs, &driver_attr_max_sg_segs);
4497− driver_remove_file(sysfs, &driver_attr_fixed_buffer_size);
4498− driver_remove_file(sysfs, &driver_attr_try_direct_io);
4499−}
4455+static struct attribute *st_drv_attrs[] = {
4456+ &driver_attr_try_direct_io.attr,
4457+ &driver_attr_fixed_buffer_size.attr,
4458+ &driver_attr_max_sg_segs.attr,
4459+ &driver_attr_version.attr,
4460+ NULL,
4461+};
4462+ATTRIBUTE_GROUPS(st_drv);
45004463
45014464 /* The sysfs simple class interface */
45024465 static ssize_t
drivers/scsi/storvsc_drv.c+141−83
@@ -56,15 +56,18 @@ · 55 unmodified lines
5656 * V1 RC > 2008/1/31: 2.0
5757 * Win7: 4.2
5858 * Win8: 5.1
59+ * Win8.1: 6.0
60+ * Win10: 6.2
5961 */
6062
63+#define VMSTOR_PROTO_VERSION(MAJOR_, MINOR_) ((((MAJOR_) & 0xff) << 8) | \
64+ (((MINOR_) & 0xff)))
6165
62−#define VMSTOR_WIN7_MAJOR 4
63−#define VMSTOR_WIN7_MINOR 2
64−
65−#define VMSTOR_WIN8_MAJOR 5
66−#define VMSTOR_WIN8_MINOR 1
67−
66+#define VMSTOR_PROTO_VERSION_WIN6 VMSTOR_PROTO_VERSION(2, 0)
67+#define VMSTOR_PROTO_VERSION_WIN7 VMSTOR_PROTO_VERSION(4, 2)
68+#define VMSTOR_PROTO_VERSION_WIN8 VMSTOR_PROTO_VERSION(5, 1)
69+#define VMSTOR_PROTO_VERSION_WIN8_1 VMSTOR_PROTO_VERSION(6, 0)
70+#define VMSTOR_PROTO_VERSION_WIN10 VMSTOR_PROTO_VERSION(6, 2)
6871
6972 /* Packet structure describing virtual storage requests. */
7073 enum vstor_packet_operation {
@@ -148,21 +151,18 @@ struct hv_fc_wwn_packet { · 77 unmodified lines
148151
149152 /*
150153 * Sense buffer size changed in win8; have a run-time
151− * variable to track the size we should use.
154+ * variable to track the size we should use. This value will
155+ * likely change during protocol negotiation but it is valid
156+ * to start by assuming pre-Win8.
152157 */
153−static int sense_buffer_size;
158+static int sense_buffer_size = PRE_WIN8_STORVSC_SENSE_BUFFER_SIZE;
154159
155160 /*
156− * The size of the vmscsi_request has changed in win8. The
157− * additional size is because of new elements added to the
158− * structure. These elements are valid only when we are talking
159− * to a win8 host.
160− * Track the correction to size we need to apply.
161− */
162−
163−static int vmscsi_size_delta;
164−static int vmstor_current_major;
165−static int vmstor_current_minor;
161+ * The storage protocol version is determined during the
162+ * initial exchange with the host. It will indicate which
163+ * storage functionality is available in the host.
164+*/
165+static int vmstor_proto_version;
166166
167167 struct vmscsi_win8_extension {
168168 /*
@@ -206,6 +206,56 @@ struct vmscsi_request { · 37 unmodified lines
206206 } __attribute((packed));
207207
208208
209+/*
210+ * The size of the vmscsi_request has changed in win8. The
211+ * additional size is because of new elements added to the
212+ * structure. These elements are valid only when we are talking
213+ * to a win8 host.
214+ * Track the correction to size we need to apply. This value
215+ * will likely change during protocol negotiation but it is
216+ * valid to start by assuming pre-Win8.
217+ */
218+static int vmscsi_size_delta = sizeof(struct vmscsi_win8_extension);
219+
220+/*
221+ * The list of storage protocols in order of preference.
222+ */
223+struct vmstor_protocol {
224+ int protocol_version;
225+ int sense_buffer_size;
226+ int vmscsi_size_delta;
227+};
228+
229+
230+static const struct vmstor_protocol vmstor_protocols[] = {
231+ {
232+ VMSTOR_PROTO_VERSION_WIN10,
233+ POST_WIN7_STORVSC_SENSE_BUFFER_SIZE,
234+ 0
235+ },
236+ {
237+ VMSTOR_PROTO_VERSION_WIN8_1,
238+ POST_WIN7_STORVSC_SENSE_BUFFER_SIZE,
239+ 0
240+ },
241+ {
242+ VMSTOR_PROTO_VERSION_WIN8,
243+ POST_WIN7_STORVSC_SENSE_BUFFER_SIZE,
244+ 0
245+ },
246+ {
247+ VMSTOR_PROTO_VERSION_WIN7,
248+ PRE_WIN8_STORVSC_SENSE_BUFFER_SIZE,
249+ sizeof(struct vmscsi_win8_extension),
250+ },
251+ {
252+ VMSTOR_PROTO_VERSION_WIN6,
253+ PRE_WIN8_STORVSC_SENSE_BUFFER_SIZE,
254+ sizeof(struct vmscsi_win8_extension),
255+ }
256+};
257+
258+
209259 /*
210260 * This structure is sent during the intialization phase to get the different
211261 * properties of the channel.
@@ -426,7 +476,6 @@ static void storvsc_host_scan(struct work_struct *work) · 214 unmodified lines
426476 struct storvsc_scan_work *wrk;
427477 struct Scsi_Host *host;
428478 struct scsi_device *sdev;
429− unsigned long flags;
430479
431480 wrk = container_of(work, struct storvsc_scan_work, work);
432481 host = wrk->host;
@@ -443,14 +492,8 @@ static void storvsc_host_scan(struct work_struct *work) · 10 unmodified lines
443492 * may have been removed this way.
444493 */
445494 mutex_lock(&host->scan_mutex);
446− spin_lock_irqsave(host->host_lock, flags);
447− list_for_each_entry(sdev, &host->__devices, siblings) {
448− spin_unlock_irqrestore(host->host_lock, flags);
495+ shost_for_each_device(sdev, host)
449496 scsi_test_unit_ready(sdev, 1, 1, NULL);
450− spin_lock_irqsave(host->host_lock, flags);
451− continue;
452− }
453− spin_unlock_irqrestore(host->host_lock, flags);
454497 mutex_unlock(&host->scan_mutex);
455498 /*
456499 * Now scan the host to discover LUNs that may have been added.
@@ -481,18 +524,6 @@ done: · 24 unmodified lines
481524 kfree(wrk);
482525 }
483526
484−/*
485− * Major/minor macros. Minor version is in LSB, meaning that earlier flat
486− * version numbers will be interpreted as "0.x" (i.e., 1 becomes 0.1).
487− */
488−
489−static inline u16 storvsc_get_version(u8 major, u8 minor)
490−{
491− u16 version;
492−
493− version = ((major << 8) | minor);
494− return version;
495−}
496527
497528 /*
498529 * We can get incoming messages from the host that are not in response to
@@ -885,7 +916,7 @@ static int storvsc_channel_init(struct hv_device *device) · 386 unmodified lines
885916 struct storvsc_device *stor_device;
886917 struct storvsc_cmd_request *request;
887918 struct vstor_packet *vstor_packet;
888− int ret, t;
919+ int ret, t, i;
889920 int max_chns;
890921 bool process_sub_channels = false;
891922
@@ -921,41 +952,65 @@ static int storvsc_channel_init(struct hv_device *device) · 29 unmodified lines
921952 }
922953
923954 if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO ||
924− vstor_packet->status != 0)
955+ vstor_packet->status != 0) {
956+ ret = -EINVAL;
925957 goto cleanup;
958+ }
926959
927960
928− /* reuse the packet for version range supported */
929− memset(vstor_packet, 0, sizeof(struct vstor_packet));
930− vstor_packet->operation = VSTOR_OPERATION_QUERY_PROTOCOL_VERSION;
931− vstor_packet->flags = REQUEST_COMPLETION_FLAG;
961+ for (i = 0; i < ARRAY_SIZE(vmstor_protocols); i++) {
962+ /* reuse the packet for version range supported */
963+ memset(vstor_packet, 0, sizeof(struct vstor_packet));
964+ vstor_packet->operation =
965+ VSTOR_OPERATION_QUERY_PROTOCOL_VERSION;
966+ vstor_packet->flags = REQUEST_COMPLETION_FLAG;
932967
933− vstor_packet->version.major_minor =
934− storvsc_get_version(vmstor_current_major, vmstor_current_minor);
968+ vstor_packet->version.major_minor =
969+ vmstor_protocols[i].protocol_version;
935970
936− /*
937− * The revision number is only used in Windows; set it to 0.
938− */
939− vstor_packet->version.revision = 0;
971+ /*
972+ * The revision number is only used in Windows; set it to 0.
973+ */
974+ vstor_packet->version.revision = 0;
940975
941− ret = vmbus_sendpacket(device->channel, vstor_packet,
976+ ret = vmbus_sendpacket(device->channel, vstor_packet,
942977 (sizeof(struct vstor_packet) -
943978 vmscsi_size_delta),
944979 (unsigned long)request,
945980 VM_PKT_DATA_INBAND,
946981 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
947− if (ret != 0)
948− goto cleanup;
982+ if (ret != 0)
983+ goto cleanup;
949984
950− t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
951− if (t == 0) {
952− ret = -ETIMEDOUT;
953− goto cleanup;
985+ t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
986+ if (t == 0) {
987+ ret = -ETIMEDOUT;
988+ goto cleanup;
989+ }
990+
991+ if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO) {
992+ ret = -EINVAL;
993+ goto cleanup;
994+ }
995+
996+ if (vstor_packet->status == 0) {
997+ vmstor_proto_version =
998+ vmstor_protocols[i].protocol_version;
999+
1000+ sense_buffer_size =
1001+ vmstor_protocols[i].sense_buffer_size;
1002+
1003+ vmscsi_size_delta =
1004+ vmstor_protocols[i].vmscsi_size_delta;
1005+
1006+ break;
1007+ }
9541008 }
9551009
956− if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO ||
957− vstor_packet->status != 0)
1010+ if (vstor_packet->status != 0) {
1011+ ret = -EINVAL;
9581012 goto cleanup;
1013+ }
9591014
9601015
9611016 memset(vstor_packet, 0, sizeof(struct vstor_packet));
@@ -979,8 +1034,10 @@ static int storvsc_channel_init(struct hv_device *device) · 17 unmodified lines
9791034 }
9801035
9811036 if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO ||
982− vstor_packet->status != 0)
1037+ vstor_packet->status != 0) {
1038+ ret = -EINVAL;
9831039 goto cleanup;
1040+ }
9841041
9851042 /*
9861043 * Check to see if multi-channel support is there.
@@ -988,8 +1045,7 @@ static int storvsc_channel_init(struct hv_device *device) · 1 unmodified line
9881045 * support multi-channel.
9891046 */
9901047 max_chns = vstor_packet->storage_channel_properties.max_channel_cnt;
991− if ((vmbus_proto_version != VERSION_WIN7) &&
992− (vmbus_proto_version != VERSION_WS2008)) {
1048+ if (vmstor_proto_version >= VMSTOR_PROTO_VERSION_WIN8) {
9931049 if (vstor_packet->storage_channel_properties.flags &
9941050 STORAGE_CHANNEL_SUPPORTS_MULTI_CHANNEL)
9951051 process_sub_channels = true;
@@ -1018,8 +1074,10 @@ static int storvsc_channel_init(struct hv_device *device) · 22 unmodified lines
10181074 }
10191075
10201076 if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO ||
1021− vstor_packet->status != 0)
1077+ vstor_packet->status != 0) {
1078+ ret = -EINVAL;
10221079 goto cleanup;
1080+ }
10231081
10241082 if (process_sub_channels)
10251083 handle_multichannel_storage(device, max_chns);
@@ -1428,15 +1486,19 @@ static int storvsc_device_configure(struct scsi_device *sdevice) · 402 unmodified lines
14281486
14291487 /*
14301488 * If the host is WIN8 or WIN8 R2, claim conformance to SPC-3
1431− * if the device is a MSFT virtual device.
1489+ * if the device is a MSFT virtual device. If the host is
1490+ * WIN10 or newer, allow write_same.
14321491 */
14331492 if (!strncmp(sdevice->vendor, "Msft", 4)) {
1434− switch (vmbus_proto_version) {
1435− case VERSION_WIN8:
1436− case VERSION_WIN8_1:
1493+ switch (vmstor_proto_version) {
1494+ case VMSTOR_PROTO_VERSION_WIN8:
1495+ case VMSTOR_PROTO_VERSION_WIN8_1:
14371496 sdevice->scsi_level = SCSI_SPC_3;
14381497 break;
14391498 }
1499+
1500+ if (vmstor_proto_version >= VMSTOR_PROTO_VERSION_WIN10)
1501+ sdevice->no_write_same = 0;
14401502 }
14411503
14421504 return 0;
@@ -1563,7 +1625,7 @@ static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd) · 120 unmodified lines
15631625 u32 payload_sz;
15641626 u32 length;
15651627
1566− if (vmstor_current_major <= VMSTOR_WIN8_MAJOR) {
1628+ if (vmstor_proto_version <= VMSTOR_PROTO_VERSION_WIN8) {
15671629 /*
15681630 * On legacy hosts filter unimplemented commands.
15691631 * Future hosts are expected to correctly handle
@@ -1598,10 +1660,18 @@ static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd) · 28 unmodified lines
15981660 vm_srb->data_in = READ_TYPE;
15991661 vm_srb->win8_extension.srb_flags |= SRB_FLAGS_DATA_IN;
16001662 break;
1601− default:
1663+ case DMA_NONE:
16021664 vm_srb->data_in = UNKNOWN_TYPE;
16031665 vm_srb->win8_extension.srb_flags |= SRB_FLAGS_NO_DATA_TRANSFER;
16041666 break;
1667+ default:
1668+ /*
1669+ * This is DMA_BIDIRECTIONAL or something else we are never
1670+ * supposed to see here.
1671+ */
1672+ WARN(1, "Unexpected data direction: %d\n",
1673+ scmnd->sc_data_direction);
1674+ return -EINVAL;
16051675 }
16061676
16071677
@@ -1758,22 +1828,11 @@ static int storvsc_probe(struct hv_device *device, · 150 unmodified lines
17581828 * set state to properly communicate with the host.
17591829 */
17601830
1761− switch (vmbus_proto_version) {
1762− case VERSION_WS2008:
1763− case VERSION_WIN7:
1764− sense_buffer_size = PRE_WIN8_STORVSC_SENSE_BUFFER_SIZE;
1765− vmscsi_size_delta = sizeof(struct vmscsi_win8_extension);
1766− vmstor_current_major = VMSTOR_WIN7_MAJOR;
1767− vmstor_current_minor = VMSTOR_WIN7_MINOR;
1831+ if (vmbus_proto_version < VERSION_WIN8) {
17681832 max_luns_per_target = STORVSC_IDE_MAX_LUNS_PER_TARGET;
17691833 max_targets = STORVSC_IDE_MAX_TARGETS;
17701834 max_channels = STORVSC_IDE_MAX_CHANNELS;
1771− break;
1772− default:
1773− sense_buffer_size = POST_WIN7_STORVSC_SENSE_BUFFER_SIZE;
1774− vmscsi_size_delta = 0;
1775− vmstor_current_major = VMSTOR_WIN8_MAJOR;
1776− vmstor_current_minor = VMSTOR_WIN8_MINOR;
1835+ } else {
17771836 max_luns_per_target = STORVSC_MAX_LUNS_PER_TARGET;
17781837 max_targets = STORVSC_MAX_TARGETS;
17791838 max_channels = STORVSC_MAX_CHANNELS;
@@ -1783,7 +1842,6 @@ static int storvsc_probe(struct hv_device *device, · 3 unmodified lines
17831842 * VCPUs in the guest.
17841843 */
17851844 max_sub_channels = (num_cpus / storvsc_vcpus_per_sub_channel);
1786− break;
17871845 }
17881846
17891847 scsi_driver.can_queue = (max_outstanding_req_per_channel *
include/scsi/scsi_device.h+2−1
@@ -57,9 +57,10 @@ enum scsi_device_event { · 56 unmodified lines
5757 SDEV_EVT_SOFT_THRESHOLD_REACHED_REPORTED, /* 38 07 UA reported */
5858 SDEV_EVT_MODE_PARAMETER_CHANGE_REPORTED, /* 2A 01 UA reported */
5959 SDEV_EVT_LUN_CHANGE_REPORTED, /* 3F 0E UA reported */
60+ SDEV_EVT_ALUA_STATE_CHANGE_REPORTED, /* 2A 06 UA reported */
6061
6162 SDEV_EVT_FIRST = SDEV_EVT_MEDIA_CHANGE,
62− SDEV_EVT_LAST = SDEV_EVT_LUN_CHANGE_REPORTED,
63+ SDEV_EVT_LAST = SDEV_EVT_ALUA_STATE_CHANGE_REPORTED,
6364
6465 SDEV_EVT_MAXBITS = SDEV_EVT_LAST + 1
6566 };
include/scsi/scsi_transport_iscsi.h+1−0
@@ -241,6 +241,7 @@ struct iscsi_cls_session { · 240 unmodified lines
241241
242242 /* recovery fields */
243243 int recovery_tmo;
244+ bool recovery_tmo_sysfs_override;
244245 struct delayed_work recovery_work;
245246
246247 unsigned int target_id;
include/uapi/scsi/Kbuild+1−0
@@ -3,3 +3,4 @@ header-y += fc/ · 2 unmodified lines
33 header-y += scsi_bsg_fc.h
44 header-y += scsi_netlink.h
55 header-y += scsi_netlink_fc.h
6+header-y += cxlflash_ioctl.h
include/uapi/scsi/cxlflash_ioctl.h+174−0
@@ -0,0 +1,174 @@
1+/*
2+ * CXL Flash Device Driver
3+ *
4+ * Written by: Manoj N. Kumar <manoj@linux.vnet.ibm.com>, IBM Corporation
5+ * Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation
6+ *
7+ * Copyright (C) 2015 IBM Corporation
8+ *
9+ * This program is free software; you can redistribute it and/or
10+ * modify it under the terms of the GNU General Public License
11+ * as published by the Free Software Foundation; either version
12+ * 2 of the License, or (at your option) any later version.
13+ */
14+
15+#ifndef _CXLFLASH_IOCTL_H
16+#define _CXLFLASH_IOCTL_H
17+
18+#include <linux/types.h>
19+
20+/*
21+ * Structure and flag definitions CXL Flash superpipe ioctls
22+ */
23+
24+#define DK_CXLFLASH_VERSION_0 0
25+
26+struct dk_cxlflash_hdr {
27+ __u16 version; /* Version data */
28+ __u16 rsvd[3]; /* Reserved for future use */
29+ __u64 flags; /* Input flags */
30+ __u64 return_flags; /* Returned flags */
31+};
32+
33+/*
34+ * Notes:
35+ * -----
36+ * The 'context_id' field of all ioctl structures contains the context
37+ * identifier for a context in the lower 32-bits (upper 32-bits are not
38+ * to be used when identifying a context to the AFU). That said, the value
39+ * in its entirety (all 64-bits) is to be treated as an opaque cookie and
40+ * should be presented as such when issuing ioctls.
41+ *
42+ * For DK_CXLFLASH_ATTACH ioctl, user specifies read/write access
43+ * permissions via the O_RDONLY, O_WRONLY, and O_RDWR flags defined in
44+ * the fcntl.h header file.
45+ */
46+#define DK_CXLFLASH_ATTACH_REUSE_CONTEXT 0x8000000000000000ULL
47+
48+struct dk_cxlflash_attach {
49+ struct dk_cxlflash_hdr hdr; /* Common fields */
50+ __u64 num_interrupts; /* Requested number of interrupts */
51+ __u64 context_id; /* Returned context */
52+ __u64 mmio_size; /* Returned size of MMIO area */
53+ __u64 block_size; /* Returned block size, in bytes */
54+ __u64 adap_fd; /* Returned adapter file descriptor */
55+ __u64 last_lba; /* Returned last LBA on the device */
56+ __u64 max_xfer; /* Returned max transfer size, blocks */
57+ __u64 reserved[8]; /* Reserved for future use */
58+};
59+
60+struct dk_cxlflash_detach {
61+ struct dk_cxlflash_hdr hdr; /* Common fields */
62+ __u64 context_id; /* Context to detach */
63+ __u64 reserved[8]; /* Reserved for future use */
64+};
65+
66+struct dk_cxlflash_udirect {
67+ struct dk_cxlflash_hdr hdr; /* Common fields */
68+ __u64 context_id; /* Context to own physical resources */
69+ __u64 rsrc_handle; /* Returned resource handle */
70+ __u64 last_lba; /* Returned last LBA on the device */
71+ __u64 reserved[8]; /* Reserved for future use */
72+};
73+
74+#define DK_CXLFLASH_UVIRTUAL_NEED_WRITE_SAME 0x8000000000000000ULL
75+
76+struct dk_cxlflash_uvirtual {
77+ struct dk_cxlflash_hdr hdr; /* Common fields */
78+ __u64 context_id; /* Context to own virtual resources */
79+ __u64 lun_size; /* Requested size, in 4K blocks */
80+ __u64 rsrc_handle; /* Returned resource handle */
81+ __u64 last_lba; /* Returned last LBA of LUN */
82+ __u64 reserved[8]; /* Reserved for future use */
83+};
84+
85+struct dk_cxlflash_release {
86+ struct dk_cxlflash_hdr hdr; /* Common fields */
87+ __u64 context_id; /* Context owning resources */
88+ __u64 rsrc_handle; /* Resource handle to release */
89+ __u64 reserved[8]; /* Reserved for future use */
90+};
91+
92+struct dk_cxlflash_resize {
93+ struct dk_cxlflash_hdr hdr; /* Common fields */
94+ __u64 context_id; /* Context owning resources */
95+ __u64 rsrc_handle; /* Resource handle of LUN to resize */
96+ __u64 req_size; /* New requested size, in 4K blocks */
97+ __u64 last_lba; /* Returned last LBA of LUN */
98+ __u64 reserved[8]; /* Reserved for future use */
99+};
100+
101+struct dk_cxlflash_clone {
102+ struct dk_cxlflash_hdr hdr; /* Common fields */
103+ __u64 context_id_src; /* Context to clone from */
104+ __u64 context_id_dst; /* Context to clone to */
105+ __u64 adap_fd_src; /* Source context adapter fd */
106+ __u64 reserved[8]; /* Reserved for future use */
107+};
108+
109+#define DK_CXLFLASH_VERIFY_SENSE_LEN 18
110+#define DK_CXLFLASH_VERIFY_HINT_SENSE 0x8000000000000000ULL
111+
112+struct dk_cxlflash_verify {
113+ struct dk_cxlflash_hdr hdr; /* Common fields */
114+ __u64 context_id; /* Context owning resources to verify */
115+ __u64 rsrc_handle; /* Resource handle of LUN */
116+ __u64 hint; /* Reasons for verify */
117+ __u64 last_lba; /* Returned last LBA of device */
118+ __u8 sense_data[DK_CXLFLASH_VERIFY_SENSE_LEN]; /* SCSI sense data */
119+ __u8 pad[6]; /* Pad to next 8-byte boundary */
120+ __u64 reserved[8]; /* Reserved for future use */
121+};
122+
123+#define DK_CXLFLASH_RECOVER_AFU_CONTEXT_RESET 0x8000000000000000ULL
124+
125+struct dk_cxlflash_recover_afu {
126+ struct dk_cxlflash_hdr hdr; /* Common fields */
127+ __u64 reason; /* Reason for recovery request */
128+ __u64 context_id; /* Context to recover / updated ID */
129+ __u64 mmio_size; /* Returned size of MMIO area */
130+ __u64 adap_fd; /* Returned adapter file descriptor */
131+ __u64 reserved[8]; /* Reserved for future use */
132+};
133+
134+#define DK_CXLFLASH_MANAGE_LUN_WWID_LEN 16
135+#define DK_CXLFLASH_MANAGE_LUN_ENABLE_SUPERPIPE 0x8000000000000000ULL
136+#define DK_CXLFLASH_MANAGE_LUN_DISABLE_SUPERPIPE 0x4000000000000000ULL
137+#define DK_CXLFLASH_MANAGE_LUN_ALL_PORTS_ACCESSIBLE 0x2000000000000000ULL
138+
139+struct dk_cxlflash_manage_lun {
140+ struct dk_cxlflash_hdr hdr; /* Common fields */
141+ __u8 wwid[DK_CXLFLASH_MANAGE_LUN_WWID_LEN]; /* Page83 WWID, NAA-6 */
142+ __u64 reserved[8]; /* Rsvd, future use */
143+};
144+
145+union cxlflash_ioctls {
146+ struct dk_cxlflash_attach attach;
147+ struct dk_cxlflash_detach detach;
148+ struct dk_cxlflash_udirect udirect;
149+ struct dk_cxlflash_uvirtual uvirtual;
150+ struct dk_cxlflash_release release;
151+ struct dk_cxlflash_resize resize;
152+ struct dk_cxlflash_clone clone;
153+ struct dk_cxlflash_verify verify;
154+ struct dk_cxlflash_recover_afu recover_afu;
155+ struct dk_cxlflash_manage_lun manage_lun;
156+};
157+
158+#define MAX_CXLFLASH_IOCTL_SZ (sizeof(union cxlflash_ioctls))
159+
160+#define CXL_MAGIC 0xCA
161+#define CXL_IOWR(_n, _s) _IOWR(CXL_MAGIC, _n, struct _s)
162+
163+#define DK_CXLFLASH_ATTACH CXL_IOWR(0x80, dk_cxlflash_attach)
164+#define DK_CXLFLASH_USER_DIRECT CXL_IOWR(0x81, dk_cxlflash_udirect)
165+#define DK_CXLFLASH_RELEASE CXL_IOWR(0x82, dk_cxlflash_release)
166+#define DK_CXLFLASH_DETACH CXL_IOWR(0x83, dk_cxlflash_detach)
167+#define DK_CXLFLASH_VERIFY CXL_IOWR(0x84, dk_cxlflash_verify)
168+#define DK_CXLFLASH_RECOVER_AFU CXL_IOWR(0x85, dk_cxlflash_recover_afu)
169+#define DK_CXLFLASH_MANAGE_LUN CXL_IOWR(0x86, dk_cxlflash_manage_lun)
170+#define DK_CXLFLASH_USER_VIRTUAL CXL_IOWR(0x87, dk_cxlflash_uvirtual)
171+#define DK_CXLFLASH_VLUN_RESIZE CXL_IOWR(0x88, dk_cxlflash_resize)
172+#define DK_CXLFLASH_VLUN_CLONE CXL_IOWR(0x89, dk_cxlflash_clone)
173+
174+#endif /* ifndef _CXLFLASH_IOCTL_H */