History

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

Pull SCSI updates from James Bottomley: "This is primarily another round of driver updates (lpfc, bfa, fcoe, ipr) plus a new ufshcd driver. There shouldn't be anything controversial in here (The final deletion of scsi proc_ops which caused some build breakage has been held over until the next merge window to give us more time to stabilise it). I'm afraid, with me moving continents at exactly the wrong time, anything submitted after the merge window opened has been held over to the next merge window." * tag 'scsi-misc' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi-misc-2.6: (63 commits) [SCSI] ipr: Driver version 2.5.3 [SCSI] ipr: Increase alignment boundary of command blocks [SCSI] ipr: Increase max concurrent oustanding commands [SCSI] ipr: Remove unnecessary memory barriers [SCSI] ipr: Remove unnecessary interrupt clearing on new adapters [SCSI] ipr: Fix target id allocation re-use problem [SCSI] atp870u, mpt2sas, qla4xxx use pci_dev->revision [SCSI] fcoe: Drop the rtnl_mutex before calling fcoe_ctlr_link_up [SCSI] bfa: Update the driver version to 3.0.23.0 [SCSI] bfa: BSG and User interface fixes. [SCSI] bfa: Fix to avoid vport delete hang on request queue full scenario. [SCSI] bfa: Move service parameter programming logic into firmware. [SCSI] bfa: Revised Fabric Assigned Address(FAA) feature implementation. [SCSI] bfa: Flash controller IOC pll init fixes. [SCSI] bfa: Serialize the IOC hw semaphore unlock logic. [SCSI] bfa: Modify ISR to process pending completions [SCSI] bfa: Add fc host issue lip support [SCSI] mpt2sas: remove extraneous sas_log_info messages [SCSI] libfc: fcoe_transport_create fails in single-CPU environment [SCSI] fcoe: reduce contention for fcoe_rx_list lock [v2] ...

Linus Torvalds committed 14 years ago

Commit a75ee6e2 parents c9651e7 699316963 files · +4407 −941Browse files

Unified · Split

63 files
  1. Documentation/scsi/00-INDEX +2 −0
  2. Documentation/scsi/st.txt +4 −0
  3. Documentation/scsi/ufs.txt +133 −0
  4. drivers/scsi/Kconfig +1 −0
  5. drivers/scsi/Makefile +1 −0
  6. drivers/scsi/atp870u.c +2 −2
  7. drivers/scsi/bfa/bfa.h +4 −5
  8. drivers/scsi/bfa/bfa_core.c +484 −209
  9. drivers/scsi/bfa/bfa_defs_svc.h +1 −1
  10. drivers/scsi/bfa/bfa_fcs_lport.c +2 −0
  11. drivers/scsi/bfa/bfa_fcs_rport.c +4 −1
  12. drivers/scsi/bfa/bfa_ioc.c +71 −117
  13. drivers/scsi/bfa/bfa_ioc.h +16 −1
  14. drivers/scsi/bfa/bfa_ioc_ct.c +106 −45
  15. drivers/scsi/bfa/bfa_svc.c +19 −50
  16. drivers/scsi/bfa/bfa_svc.h +0 −4
  17. drivers/scsi/bfa/bfad_attr.c +43 −4
  18. drivers/scsi/bfa/bfad_bsg.c +11 −51
  19. drivers/scsi/bfa/bfad_bsg.h +0 −2
  20. drivers/scsi/bfa/bfad_drv.h +1 −1
  21. drivers/scsi/bfa/bfi_ms.h +11 −6
  22. drivers/scsi/bfa/bfi_reg.h +6 −0
  23. drivers/scsi/bnx2fc/bnx2fc_fcoe.c +2 −2
  24. drivers/scsi/fcoe/fcoe.c +35 −48
  25. drivers/scsi/fcoe/fcoe_ctlr.c +28 −10
  26. drivers/scsi/ipr.c +46 −27
  27. drivers/scsi/ipr.h +10 −6
  28. drivers/scsi/libfc/fc_exch.c +12 −2
  29. drivers/scsi/libfc/fc_lport.c +9 −1
  30. drivers/scsi/lpfc/Makefile +3 −1
  31. drivers/scsi/lpfc/lpfc.h +7 −1
  32. drivers/scsi/lpfc/lpfc_attr.c +2 −2
  33. drivers/scsi/lpfc/lpfc_debugfs.c +65 −15
  34. drivers/scsi/lpfc/lpfc_els.c +13 −4
  35. drivers/scsi/lpfc/lpfc_hbadisc.c +15 −9
  36. drivers/scsi/lpfc/lpfc_hw4.h +7 −1
  37. drivers/scsi/lpfc/lpfc_init.c +22 −19
  38. drivers/scsi/lpfc/lpfc_nportdisc.c +7 −3
  39. drivers/scsi/lpfc/lpfc_scsi.c +295 −193
  40. drivers/scsi/lpfc/lpfc_scsi.h +11 −2
  41. drivers/scsi/lpfc/lpfc_sli.c +39 −23
  42. drivers/scsi/lpfc/lpfc_version.h +2 −2
  43. drivers/scsi/mpt2sas/mpt2sas_base.c +2 −4
  44. drivers/scsi/mpt2sas/mpt2sas_ctl.c +1 −3
  45. drivers/scsi/pm8001/pm8001_hwi.c +10 −8
  46. drivers/scsi/qla4xxx/ql4_isr.c +2 −2
  47. drivers/scsi/qla4xxx/ql4_os.c +4 −6
  48. drivers/scsi/qla4xxx/ql4_version.h +1 −1
  49. drivers/scsi/scsi_debug.c +20 −7
  50. drivers/scsi/scsi_transport_iscsi.c +4 −4
  51. drivers/scsi/sd.c +10 −5
  52. drivers/scsi/st.c +18 −3
  53. drivers/scsi/st.h +1 −0
  54. drivers/scsi/ufs/Kconfig +49 −0
  55. drivers/scsi/ufs/Makefile +2 −0
  56. drivers/scsi/ufs/ufs.h +207 −0
  57. drivers/scsi/ufs/ufshcd.c +1978 −0
  58. drivers/scsi/ufs/ufshci.h +376 −0
  59. drivers/scsi/vmw_pvscsi.c +64 −1
  60. drivers/scsi/vmw_pvscsi.h +85 −24
  61. include/linux/mtio.h +1 −0
  62. include/scsi/iscsi_if.h +17 −2
  63. include/scsi/libfcoe.h +3 −1
Documentation/scsi/00-INDEX+2−0
@@ -94,3 +94,5 @@ sym53c8xx_2.txt · 93 unmodified lines
9494 - info on second generation driver for sym53c8xx based adapters
9595 tmscsim.txt
9696 - info on driver for AM53c974 based adapters
97+ufs.txt
98+ - info on Universal Flash Storage(UFS) and UFS host controller driver.
Documentation/scsi/st.txt+4−0
@@ -390,6 +390,10 @@ MTSETDRVBUFFER · 389 unmodified lines
390390 MT_ST_SYSV sets the SYSV semantics (mode)
391391 MT_ST_NOWAIT enables immediate mode (i.e., don't wait for
392392 the command to finish) for some commands (e.g., rewind)
393+ MT_ST_NOWAIT_EOF enables immediate filemark mode (i.e. when
394+ writing a filemark, don't wait for it to complete). Please
395+ see the BASICS note about MTWEOFI with respect to the
396+ possible dangers of writing immediate filemarks.
393397 MT_ST_SILI enables setting the SILI bit in SCSI commands when
394398 reading in variable block mode to enhance performance when
395399 reading blocks shorter than the byte count; set this only
Documentation/scsi/ufs.txt+133−0
@@ -0,0 +1,133 @@
1+ Universal Flash Storage
2+ =======================
3+
4+
5+Contents
6+--------
7+
8+1. Overview
9+2. UFS Architecture Overview
10+ 2.1 Application Layer
11+ 2.2 UFS Transport Protocol(UTP) layer
12+ 2.3 UFS Interconnect(UIC) Layer
13+3. UFSHCD Overview
14+ 3.1 UFS controller initialization
15+ 3.2 UTP Transfer requests
16+ 3.3 UFS error handling
17+ 3.4 SCSI Error handling
18+
19+
20+1. Overview
21+-----------
22+
23+Universal Flash Storage(UFS) is a storage specification for flash devices.
24+It is aimed to provide a universal storage interface for both
25+embedded and removable flash memory based storage in mobile
26+devices such as smart phones and tablet computers. The specification
27+is defined by JEDEC Solid State Technology Association. UFS is based
28+on MIPI M-PHY physical layer standard. UFS uses MIPI M-PHY as the
29+physical layer and MIPI Unipro as the link layer.
30+
31+The main goals of UFS is to provide,
32+ * Optimized performance:
33+ For UFS version 1.0 and 1.1 the target performance is as follows,
34+ Support for Gear1 is mandatory (rate A: 1248Mbps, rate B: 1457.6Mbps)
35+ Support for Gear2 is optional (rate A: 2496Mbps, rate B: 2915.2Mbps)
36+ Future version of the standard,
37+ Gear3 (rate A: 4992Mbps, rate B: 5830.4Mbps)
38+ * Low power consumption
39+ * High random IOPs and low latency
40+
41+
42+2. UFS Architecture Overview
43+----------------------------
44+
45+UFS has a layered communication architecture which is based on SCSI
46+SAM-5 architectural model.
47+
48+UFS communication architecture consists of following layers,
49+
50+2.1 Application Layer
51+
52+ The Application layer is composed of UFS command set layer(UCS),
53+ Task Manager and Device manager. The UFS interface is designed to be
54+ protocol agnostic, however SCSI has been selected as a baseline
55+ protocol for versions 1.0 and 1.1 of UFS protocol layer.
56+ UFS supports subset of SCSI commands defined by SPC-4 and SBC-3.
57+ * UCS: It handles SCSI commands supported by UFS specification.
58+ * Task manager: It handles task management functions defined by the
59+ UFS which are meant for command queue control.
60+ * Device manager: It handles device level operations and device
61+ configuration operations. Device level operations mainly involve
62+ device power management operations and commands to Interconnect
63+ layers. Device level configurations involve handling of query
64+ requests which are used to modify and retrieve configuration
65+ information of the device.
66+
67+2.2 UFS Transport Protocol(UTP) layer
68+
69+ UTP layer provides services for
70+ the higher layers through Service Access Points. UTP defines 3
71+ service access points for higher layers.
72+ * UDM_SAP: Device manager service access point is exposed to device
73+ manager for device level operations. These device level operations
74+ are done through query requests.
75+ * UTP_CMD_SAP: Command service access point is exposed to UFS command
76+ set layer(UCS) to transport commands.
77+ * UTP_TM_SAP: Task management service access point is exposed to task
78+ manager to transport task management functions.
79+ UTP transports messages through UFS protocol information unit(UPIU).
80+
81+2.3 UFS Interconnect(UIC) Layer
82+
83+ UIC is the lowest layer of UFS layered architecture. It handles
84+ connection between UFS host and UFS device. UIC consists of
85+ MIPI UniPro and MIPI M-PHY. UIC provides 2 service access points
86+ to upper layer,
87+ * UIC_SAP: To transport UPIU between UFS host and UFS device.
88+ * UIO_SAP: To issue commands to Unipro layers.
89+
90+
91+3. UFSHCD Overview
92+------------------
93+
94+The UFS host controller driver is based on Linux SCSI Framework.
95+UFSHCD is a low level device driver which acts as an interface between
96+SCSI Midlayer and PCIe based UFS host controllers.
97+
98+The current UFSHCD implementation supports following functionality,
99+
100+3.1 UFS controller initialization
101+
102+ The initialization module brings UFS host controller to active state
103+ and prepares the controller to transfer commands/response between
104+ UFSHCD and UFS device.
105+
106+3.2 UTP Transfer requests
107+
108+ Transfer request handling module of UFSHCD receives SCSI commands
109+ from SCSI Midlayer, forms UPIUs and issues the UPIUs to UFS Host
110+ controller. Also, the module decodes, responses received from UFS
111+ host controller in the form of UPIUs and intimates the SCSI Midlayer
112+ of the status of the command.
113+
114+3.3 UFS error handling
115+
116+ Error handling module handles Host controller fatal errors,
117+ Device fatal errors and UIC interconnect layer related errors.
118+
119+3.4 SCSI Error handling
120+
121+ This is done through UFSHCD SCSI error handling routines registered
122+ with SCSI Midlayer. Examples of some of the error handling commands
123+ issues by SCSI Midlayer are Abort task, Lun reset and host reset.
124+ UFSHCD Routines to perform these tasks are registered with
125+ SCSI Midlayer through .eh_abort_handler, .eh_device_reset_handler and
126+ .eh_host_reset_handler.
127+
128+In this version of UFSHCD Query requests and power management
129+functionality are not implemented.
130+
131+UFS Specifications can be found at,
132+UFS - http://www.jedec.org/sites/default/files/docs/JESD220.pdf
133+UFSHCI - http://www.jedec.org/sites/default/files/docs/JESD223.pdf
drivers/scsi/Kconfig+1−0
@@ -619,6 +619,7 @@ config SCSI_ARCMSR · 618 unmodified lines
619619
620620 source "drivers/scsi/megaraid/Kconfig.megaraid"
621621 source "drivers/scsi/mpt2sas/Kconfig"
622+source "drivers/scsi/ufs/Kconfig"
622623
623624 config SCSI_HPTIOP
624625 tristate "HighPoint RocketRAID 3xxx/4xxx Controller support"
drivers/scsi/Makefile+1−0
@@ -108,6 +108,7 @@ obj-$(CONFIG_MEGARAID_LEGACY) += megaraid.o · 107 unmodified lines
108108 obj-$(CONFIG_MEGARAID_NEWGEN) += megaraid/
109109 obj-$(CONFIG_MEGARAID_SAS) += megaraid/
110110 obj-$(CONFIG_SCSI_MPT2SAS) += mpt2sas/
111+obj-$(CONFIG_SCSI_UFSHCD) += ufs/
111112 obj-$(CONFIG_SCSI_ACARD) += atp870u.o
112113 obj-$(CONFIG_SCSI_SUNESP) += esp_scsi.o sun_esp.o
113114 obj-$(CONFIG_SCSI_GDTH) += gdth.o
drivers/scsi/atp870u.c+2−2
@@ -2582,7 +2582,7 @@ static int atp870u_probe(struct pci_dev *pdev, const struct pci_device_id *ent) · 2581 unmodified lines
25822582 * this than via the PCI device table
25832583 */
25842584 if (ent->device == PCI_DEVICE_ID_ARTOP_AEC7610) {
2585− error = pci_read_config_byte(pdev, PCI_CLASS_REVISION, &atpdev->chip_ver);
2585+ atpdev->chip_ver = pdev->revision;
25862586 if (atpdev->chip_ver < 2)
25872587 goto err_eio;
25882588 }
@@ -2601,7 +2601,7 @@ static int atp870u_probe(struct pci_dev *pdev, const struct pci_device_id *ent) · 12 unmodified lines
26012601 base_io &= 0xfffffff8;
26022602
26032603 if ((ent->device == ATP880_DEVID1)||(ent->device == ATP880_DEVID2)) {
2604− error = pci_read_config_byte(pdev, PCI_CLASS_REVISION, &atpdev->chip_ver);
2604+ atpdev->chip_ver = pdev->revision;
26052605 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x80);//JCC082803
26062606
26072607 host_id = inb(base_io + 0x39);
drivers/scsi/bfa/bfa.h+4−5
@@ -225,9 +225,9 @@ struct bfa_faa_args_s { · 224 unmodified lines
225225 };
226226
227227 struct bfa_iocfc_s {
228+ bfa_fsm_t fsm;
228229 struct bfa_s *bfa;
229230 struct bfa_iocfc_cfg_s cfg;
230− int action;
231231 u32 req_cq_pi[BFI_IOC_MAX_CQS];
232232 u32 rsp_cq_ci[BFI_IOC_MAX_CQS];
233233 u8 hw_qid[BFI_IOC_MAX_CQS];
@@ -236,7 +236,9 @@ struct bfa_iocfc_s { · 2 unmodified lines
236236 struct bfa_cb_qe_s dis_hcb_qe;
237237 struct bfa_cb_qe_s en_hcb_qe;
238238 struct bfa_cb_qe_s stats_hcb_qe;
239− bfa_boolean_t cfgdone;
239+ bfa_boolean_t submod_enabled;
240+ bfa_boolean_t cb_reqd; /* Driver call back reqd */
241+ bfa_status_t op_status; /* Status of bfa iocfc op */
240242
241243 struct bfa_dma_s cfg_info;
242244 struct bfi_iocfc_cfg_s *cfginfo;
@@ -341,8 +343,6 @@ void bfa_hwct_msix_getvecs(struct bfa_s *bfa, u32 *vecmap, u32 *nvecs, · 98 unmodified lines
341343 void bfa_hwct_msix_get_rme_range(struct bfa_s *bfa, u32 *start,
342344 u32 *end);
343345 void bfa_iocfc_get_bootwwns(struct bfa_s *bfa, u8 *nwwns, wwn_t *wwns);
344−wwn_t bfa_iocfc_get_pwwn(struct bfa_s *bfa);
345−wwn_t bfa_iocfc_get_nwwn(struct bfa_s *bfa);
346346 int bfa_iocfc_get_pbc_vports(struct bfa_s *bfa,
347347 struct bfi_pbc_vport_s *pbc_vport);
348348
@@ -428,7 +428,6 @@ bfa_status_t bfa_iocfc_israttr_set(struct bfa_s *bfa, · 79 unmodified lines
428428
429429 void bfa_iocfc_enable(struct bfa_s *bfa);
430430 void bfa_iocfc_disable(struct bfa_s *bfa);
431−void bfa_iocfc_cb_dconf_modinit(struct bfa_s *bfa, bfa_status_t status);
432431 #define bfa_timer_start(_bfa, _timer, _timercb, _arg, _timeout) \
433432 bfa_timer_begin(&(_bfa)->timer_mod, _timer, _timercb, _arg, _timeout)
434433
drivers/scsi/bfa/bfa_core.c+484−209
@@ -199,14 +199,432 @@ enum { · 198 unmodified lines
199199 #define DEF_CFG_NUM_SBOOT_TGTS 16
200200 #define DEF_CFG_NUM_SBOOT_LUNS 16
201201
202+/*
203+ * IOCFC state machine definitions/declarations
204+ */
205+bfa_fsm_state_decl(bfa_iocfc, stopped, struct bfa_iocfc_s, enum iocfc_event);
206+bfa_fsm_state_decl(bfa_iocfc, initing, struct bfa_iocfc_s, enum iocfc_event);
207+bfa_fsm_state_decl(bfa_iocfc, dconf_read, struct bfa_iocfc_s, enum iocfc_event);
208+bfa_fsm_state_decl(bfa_iocfc, init_cfg_wait,
209+ struct bfa_iocfc_s, enum iocfc_event);
210+bfa_fsm_state_decl(bfa_iocfc, init_cfg_done,
211+ struct bfa_iocfc_s, enum iocfc_event);
212+bfa_fsm_state_decl(bfa_iocfc, operational,
213+ struct bfa_iocfc_s, enum iocfc_event);
214+bfa_fsm_state_decl(bfa_iocfc, dconf_write,
215+ struct bfa_iocfc_s, enum iocfc_event);
216+bfa_fsm_state_decl(bfa_iocfc, stopping, struct bfa_iocfc_s, enum iocfc_event);
217+bfa_fsm_state_decl(bfa_iocfc, enabling, struct bfa_iocfc_s, enum iocfc_event);
218+bfa_fsm_state_decl(bfa_iocfc, cfg_wait, struct bfa_iocfc_s, enum iocfc_event);
219+bfa_fsm_state_decl(bfa_iocfc, disabling, struct bfa_iocfc_s, enum iocfc_event);
220+bfa_fsm_state_decl(bfa_iocfc, disabled, struct bfa_iocfc_s, enum iocfc_event);
221+bfa_fsm_state_decl(bfa_iocfc, failed, struct bfa_iocfc_s, enum iocfc_event);
222+bfa_fsm_state_decl(bfa_iocfc, init_failed,
223+ struct bfa_iocfc_s, enum iocfc_event);
224+
202225 /*
203226 * forward declaration for IOC FC functions
204227 */
228+static void bfa_iocfc_start_submod(struct bfa_s *bfa);
229+static void bfa_iocfc_disable_submod(struct bfa_s *bfa);
230+static void bfa_iocfc_send_cfg(void *bfa_arg);
205231 static void bfa_iocfc_enable_cbfn(void *bfa_arg, enum bfa_status status);
206232 static void bfa_iocfc_disable_cbfn(void *bfa_arg);
207233 static void bfa_iocfc_hbfail_cbfn(void *bfa_arg);
208234 static void bfa_iocfc_reset_cbfn(void *bfa_arg);
209235 static struct bfa_ioc_cbfn_s bfa_iocfc_cbfn;
236+static void bfa_iocfc_init_cb(void *bfa_arg, bfa_boolean_t complete);
237+static void bfa_iocfc_stop_cb(void *bfa_arg, bfa_boolean_t compl);
238+static void bfa_iocfc_enable_cb(void *bfa_arg, bfa_boolean_t compl);
239+static void bfa_iocfc_disable_cb(void *bfa_arg, bfa_boolean_t compl);
240+
241+static void
242+bfa_iocfc_sm_stopped_entry(struct bfa_iocfc_s *iocfc)
243+{
244+}
245+
246+static void
247+bfa_iocfc_sm_stopped(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
248+{
249+ bfa_trc(iocfc->bfa, event);
250+
251+ switch (event) {
252+ case IOCFC_E_INIT:
253+ case IOCFC_E_ENABLE:
254+ bfa_fsm_set_state(iocfc, bfa_iocfc_sm_initing);
255+ break;
256+ default:
257+ bfa_sm_fault(iocfc->bfa, event);
258+ break;
259+ }
260+}
261+
262+static void
263+bfa_iocfc_sm_initing_entry(struct bfa_iocfc_s *iocfc)
264+{
265+ bfa_ioc_enable(&iocfc->bfa->ioc);
266+}
267+
268+static void
269+bfa_iocfc_sm_initing(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
270+{
271+ bfa_trc(iocfc->bfa, event);
272+
273+ switch (event) {
274+ case IOCFC_E_IOC_ENABLED:
275+ bfa_fsm_set_state(iocfc, bfa_iocfc_sm_dconf_read);
276+ break;
277+ case IOCFC_E_IOC_FAILED:
278+ bfa_fsm_set_state(iocfc, bfa_iocfc_sm_init_failed);
279+ break;
280+ default:
281+ bfa_sm_fault(iocfc->bfa, event);
282+ break;
283+ }
284+}
285+
286+static void
287+bfa_iocfc_sm_dconf_read_entry(struct bfa_iocfc_s *iocfc)
288+{
289+ bfa_dconf_modinit(iocfc->bfa);
290+}
291+
292+static void
293+bfa_iocfc_sm_dconf_read(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
294+{
295+ bfa_trc(iocfc->bfa, event);
296+
297+ switch (event) {
298+ case IOCFC_E_DCONF_DONE:
299+ bfa_fsm_set_state(iocfc, bfa_iocfc_sm_init_cfg_wait);
300+ break;
301+ case IOCFC_E_IOC_FAILED:
302+ bfa_fsm_set_state(iocfc, bfa_iocfc_sm_init_failed);
303+ break;
304+ default:
305+ bfa_sm_fault(iocfc->bfa, event);
306+ break;
307+ }
308+}
309+
310+static void
311+bfa_iocfc_sm_init_cfg_wait_entry(struct bfa_iocfc_s *iocfc)
312+{
313+ bfa_iocfc_send_cfg(iocfc->bfa);
314+}
315+
316+static void
317+bfa_iocfc_sm_init_cfg_wait(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
318+{
319+ bfa_trc(iocfc->bfa, event);
320+
321+ switch (event) {
322+ case IOCFC_E_CFG_DONE:
323+ bfa_fsm_set_state(iocfc, bfa_iocfc_sm_init_cfg_done);
324+ break;
325+ case IOCFC_E_IOC_FAILED:
326+ bfa_fsm_set_state(iocfc, bfa_iocfc_sm_init_failed);
327+ break;
328+ default:
329+ bfa_sm_fault(iocfc->bfa, event);
330+ break;
331+ }
332+}
333+
334+static void
335+bfa_iocfc_sm_init_cfg_done_entry(struct bfa_iocfc_s *iocfc)
336+{
337+ iocfc->bfa->iocfc.op_status = BFA_STATUS_OK;
338+ bfa_cb_queue(iocfc->bfa, &iocfc->bfa->iocfc.init_hcb_qe,
339+ bfa_iocfc_init_cb, iocfc->bfa);
340+}
341+
342+static void
343+bfa_iocfc_sm_init_cfg_done(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
344+{
345+ bfa_trc(iocfc->bfa, event);
346+
347+ switch (event) {
348+ case IOCFC_E_START:
349+ bfa_fsm_set_state(iocfc, bfa_iocfc_sm_operational);
350+ break;
351+ case IOCFC_E_STOP:
352+ bfa_fsm_set_state(iocfc, bfa_iocfc_sm_stopping);
353+ break;
354+ case IOCFC_E_DISABLE:
355+ bfa_fsm_set_state(iocfc, bfa_iocfc_sm_disabling);
356+ break;
357+ case IOCFC_E_IOC_FAILED:
358+ bfa_fsm_set_state(iocfc, bfa_iocfc_sm_failed);
359+ break;
360+ default:
361+ bfa_sm_fault(iocfc->bfa, event);
362+ break;
363+ }
364+}
365+
366+static void
367+bfa_iocfc_sm_operational_entry(struct bfa_iocfc_s *iocfc)
368+{
369+ bfa_fcport_init(iocfc->bfa);
370+ bfa_iocfc_start_submod(iocfc->bfa);
371+}
372+
373+static void
374+bfa_iocfc_sm_operational(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
375+{
376+ bfa_trc(iocfc->bfa, event);
377+
378+ switch (event) {
379+ case IOCFC_E_STOP:
380+ bfa_fsm_set_state(iocfc, bfa_iocfc_sm_dconf_write);
381+ break;
382+ case IOCFC_E_DISABLE:
383+ bfa_fsm_set_state(iocfc, bfa_iocfc_sm_disabling);
384+ break;
385+ case IOCFC_E_IOC_FAILED:
386+ bfa_fsm_set_state(iocfc, bfa_iocfc_sm_failed);
387+ break;
388+ default:
389+ bfa_sm_fault(iocfc->bfa, event);
390+ break;
391+ }
392+}
393+
394+static void
395+bfa_iocfc_sm_dconf_write_entry(struct bfa_iocfc_s *iocfc)
396+{
397+ bfa_dconf_modexit(iocfc->bfa);
398+}
399+
400+static void
401+bfa_iocfc_sm_dconf_write(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
402+{
403+ bfa_trc(iocfc->bfa, event);
404+
405+ switch (event) {
406+ case IOCFC_E_DCONF_DONE:
407+ case IOCFC_E_IOC_FAILED:
408+ bfa_fsm_set_state(iocfc, bfa_iocfc_sm_stopping);
409+ break;
410+ default:
411+ bfa_sm_fault(iocfc->bfa, event);
412+ break;
413+ }
414+}
415+
416+static void
417+bfa_iocfc_sm_stopping_entry(struct bfa_iocfc_s *iocfc)
418+{
419+ bfa_ioc_disable(&iocfc->bfa->ioc);
420+}
421+
422+static void
423+bfa_iocfc_sm_stopping(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
424+{
425+ bfa_trc(iocfc->bfa, event);
426+
427+ switch (event) {
428+ case IOCFC_E_IOC_DISABLED:
429+ bfa_isr_disable(iocfc->bfa);
430+ bfa_iocfc_disable_submod(iocfc->bfa);
431+ bfa_fsm_set_state(iocfc, bfa_iocfc_sm_stopped);
432+ iocfc->bfa->iocfc.op_status = BFA_STATUS_OK;
433+ bfa_cb_queue(iocfc->bfa, &iocfc->bfa->iocfc.stop_hcb_qe,
434+ bfa_iocfc_stop_cb, iocfc->bfa);
435+ break;
436+ default:
437+ bfa_sm_fault(iocfc->bfa, event);
438+ break;
439+ }
440+}
441+
442+static void
443+bfa_iocfc_sm_enabling_entry(struct bfa_iocfc_s *iocfc)
444+{
445+ bfa_ioc_enable(&iocfc->bfa->ioc);
446+}
447+
448+static void
449+bfa_iocfc_sm_enabling(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
450+{
451+ bfa_trc(iocfc->bfa, event);
452+
453+ switch (event) {
454+ case IOCFC_E_IOC_ENABLED:
455+ bfa_fsm_set_state(iocfc, bfa_iocfc_sm_cfg_wait);
456+ break;
457+ case IOCFC_E_IOC_FAILED:
458+ bfa_fsm_set_state(iocfc, bfa_iocfc_sm_failed);
459+
460+ if (iocfc->bfa->iocfc.cb_reqd == BFA_FALSE)
461+ break;
462+
463+ iocfc->bfa->iocfc.op_status = BFA_STATUS_FAILED;
464+ bfa_cb_queue(iocfc->bfa, &iocfc->bfa->iocfc.en_hcb_qe,
465+ bfa_iocfc_enable_cb, iocfc->bfa);
466+ iocfc->bfa->iocfc.cb_reqd = BFA_FALSE;
467+ break;
468+ default:
469+ bfa_sm_fault(iocfc->bfa, event);
470+ break;
471+ }
472+}
473+
474+static void
475+bfa_iocfc_sm_cfg_wait_entry(struct bfa_iocfc_s *iocfc)
476+{
477+ bfa_iocfc_send_cfg(iocfc->bfa);
478+}
479+
480+static void
481+bfa_iocfc_sm_cfg_wait(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
482+{
483+ bfa_trc(iocfc->bfa, event);
484+
485+ switch (event) {
486+ case IOCFC_E_CFG_DONE:
487+ bfa_fsm_set_state(iocfc, bfa_iocfc_sm_operational);
488+ if (iocfc->bfa->iocfc.cb_reqd == BFA_FALSE)
489+ break;
490+
491+ iocfc->bfa->iocfc.op_status = BFA_STATUS_OK;
492+ bfa_cb_queue(iocfc->bfa, &iocfc->bfa->iocfc.en_hcb_qe,
493+ bfa_iocfc_enable_cb, iocfc->bfa);
494+ iocfc->bfa->iocfc.cb_reqd = BFA_FALSE;
495+ break;
496+ case IOCFC_E_IOC_FAILED:
497+ bfa_fsm_set_state(iocfc, bfa_iocfc_sm_failed);
498+ if (iocfc->bfa->iocfc.cb_reqd == BFA_FALSE)
499+ break;
500+
501+ iocfc->bfa->iocfc.op_status = BFA_STATUS_FAILED;
502+ bfa_cb_queue(iocfc->bfa, &iocfc->bfa->iocfc.en_hcb_qe,
503+ bfa_iocfc_enable_cb, iocfc->bfa);
504+ iocfc->bfa->iocfc.cb_reqd = BFA_FALSE;
505+ break;
506+ default:
507+ bfa_sm_fault(iocfc->bfa, event);
508+ break;
509+ }
510+}
511+
512+static void
513+bfa_iocfc_sm_disabling_entry(struct bfa_iocfc_s *iocfc)
514+{
515+ bfa_ioc_disable(&iocfc->bfa->ioc);
516+}
517+
518+static void
519+bfa_iocfc_sm_disabling(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
520+{
521+ bfa_trc(iocfc->bfa, event);
522+
523+ switch (event) {
524+ case IOCFC_E_IOC_DISABLED:
525+ bfa_fsm_set_state(iocfc, bfa_iocfc_sm_disabled);
526+ break;
527+ default:
528+ bfa_sm_fault(iocfc->bfa, event);
529+ break;
530+ }
531+}
532+
533+static void
534+bfa_iocfc_sm_disabled_entry(struct bfa_iocfc_s *iocfc)
535+{
536+ bfa_isr_disable(iocfc->bfa);
537+ bfa_iocfc_disable_submod(iocfc->bfa);
538+ iocfc->bfa->iocfc.op_status = BFA_STATUS_OK;
539+ bfa_cb_queue(iocfc->bfa, &iocfc->bfa->iocfc.dis_hcb_qe,
540+ bfa_iocfc_disable_cb, iocfc->bfa);
541+}
542+
543+static void
544+bfa_iocfc_sm_disabled(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
545+{
546+ bfa_trc(iocfc->bfa, event);
547+
548+ switch (event) {
549+ case IOCFC_E_STOP:
550+ bfa_fsm_set_state(iocfc, bfa_iocfc_sm_dconf_write);
551+ break;
552+ case IOCFC_E_ENABLE:
553+ bfa_fsm_set_state(iocfc, bfa_iocfc_sm_enabling);
554+ break;
555+ default:
556+ bfa_sm_fault(iocfc->bfa, event);
557+ break;
558+ }
559+}
560+
561+static void
562+bfa_iocfc_sm_failed_entry(struct bfa_iocfc_s *iocfc)
563+{
564+ bfa_isr_disable(iocfc->bfa);
565+ bfa_iocfc_disable_submod(iocfc->bfa);
566+}
567+
568+static void
569+bfa_iocfc_sm_failed(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
570+{
571+ bfa_trc(iocfc->bfa, event);
572+
573+ switch (event) {
574+ case IOCFC_E_STOP:
575+ bfa_fsm_set_state(iocfc, bfa_iocfc_sm_dconf_write);
576+ break;
577+ case IOCFC_E_DISABLE:
578+ bfa_fsm_set_state(iocfc, bfa_iocfc_sm_disabling);
579+ break;
580+ case IOCFC_E_IOC_ENABLED:
581+ bfa_fsm_set_state(iocfc, bfa_iocfc_sm_cfg_wait);
582+ break;
583+ case IOCFC_E_IOC_FAILED:
584+ break;
585+ default:
586+ bfa_sm_fault(iocfc->bfa, event);
587+ break;
588+ }
589+}
590+
591+static void
592+bfa_iocfc_sm_init_failed_entry(struct bfa_iocfc_s *iocfc)
593+{
594+ bfa_isr_disable(iocfc->bfa);
595+ iocfc->bfa->iocfc.op_status = BFA_STATUS_FAILED;
596+ bfa_cb_queue(iocfc->bfa, &iocfc->bfa->iocfc.init_hcb_qe,
597+ bfa_iocfc_init_cb, iocfc->bfa);
598+}
599+
600+static void
601+bfa_iocfc_sm_init_failed(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
602+{
603+ bfa_trc(iocfc->bfa, event);
604+
605+ switch (event) {
606+ case IOCFC_E_STOP:
607+ bfa_fsm_set_state(iocfc, bfa_iocfc_sm_stopping);
608+ break;
609+ case IOCFC_E_DISABLE:
610+ bfa_ioc_disable(&iocfc->bfa->ioc);
611+ break;
612+ case IOCFC_E_IOC_ENABLED:
613+ bfa_fsm_set_state(iocfc, bfa_iocfc_sm_dconf_read);
614+ break;
615+ case IOCFC_E_IOC_DISABLED:
616+ bfa_fsm_set_state(iocfc, bfa_iocfc_sm_stopped);
617+ iocfc->bfa->iocfc.op_status = BFA_STATUS_OK;
618+ bfa_cb_queue(iocfc->bfa, &iocfc->bfa->iocfc.dis_hcb_qe,
619+ bfa_iocfc_disable_cb, iocfc->bfa);
620+ break;
621+ case IOCFC_E_IOC_FAILED:
622+ break;
623+ default:
624+ bfa_sm_fault(iocfc->bfa, event);
625+ break;
626+ }
627+}
210628
211629 /*
212630 * BFA Interrupt handling functions
@@ -231,16 +649,19 @@ bfa_reqq_resume(struct bfa_s *bfa, int qid) · 18 unmodified lines
231649 }
232650 }
233651
234−static inline void
652+bfa_boolean_t
235653 bfa_isr_rspq(struct bfa_s *bfa, int qid)
236654 {
237655 struct bfi_msg_s *m;
238656 u32 pi, ci;
239657 struct list_head *waitq;
658+ bfa_boolean_t ret;
240659
241660 ci = bfa_rspq_ci(bfa, qid);
242661 pi = bfa_rspq_pi(bfa, qid);
243662
663+ ret = (ci != pi);
664+
244665 while (ci != pi) {
245666 m = bfa_rspq_elem(bfa, qid, ci);
246667 WARN_ON(m->mhdr.msg_class >= BFI_MC_MAX);
@@ -260,6 +681,8 @@ bfa_isr_rspq(struct bfa_s *bfa, int qid) · 13 unmodified lines
260681 waitq = bfa_reqq(bfa, qid);
261682 if (!list_empty(waitq))
262683 bfa_reqq_resume(bfa, qid);
684+
685+ return ret;
263686 }
264687
265688 static inline void
@@ -320,6 +743,7 @@ bfa_intx(struct bfa_s *bfa) · 54 unmodified lines
320743 {
321744 u32 intr, qintr;
322745 int queue;
746+ bfa_boolean_t rspq_comp = BFA_FALSE;
323747
324748 intr = readl(bfa->iocfc.bfa_regs.intr_status);
325749
@@ -332,11 +756,12 @@ bfa_intx(struct bfa_s *bfa) · 6 unmodified lines
332756 */
333757 if (bfa->queue_process) {
334758 for (queue = 0; queue < BFI_IOC_MAX_CQS; queue++)
335− bfa_isr_rspq(bfa, queue);
759+ if (bfa_isr_rspq(bfa, queue))
760+ rspq_comp = BFA_TRUE;
336761 }
337762
338763 if (!intr)
339− return BFA_TRUE;
764+ return (qintr | rspq_comp) ? BFA_TRUE : BFA_FALSE;
340765
341766 /*
342767 * CPE completion queue interrupt
@@ -525,11 +950,9 @@ bfa_iocfc_send_cfg(void *bfa_arg) · 182 unmodified lines
525950 * Enable interrupt coalescing if it is driver init path
526951 * and not ioc disable/enable path.
527952 */
528− if (!iocfc->cfgdone)
953+ if (bfa_fsm_cmp_state(iocfc, bfa_iocfc_sm_init_cfg_wait))
529954 cfg_info->intr_attr.coalesce = BFA_TRUE;
530955
531− iocfc->cfgdone = BFA_FALSE;
532−
533956 /*
534957 * dma map IOC configuration itself
535958 */
@@ -549,8 +972,6 @@ bfa_iocfc_init_mem(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg, · 13 unmodified lines
549972
550973 bfa->bfad = bfad;
551974 iocfc->bfa = bfa;
552− iocfc->action = BFA_IOCFC_ACT_NONE;
553−
554975 iocfc->cfg = *cfg;
555976
556977 /*
@@ -683,6 +1104,8 @@ bfa_iocfc_start_submod(struct bfa_s *bfa) · 126 unmodified lines
6831104
6841105 for (i = 0; hal_mods[i]; i++)
6851106 hal_mods[i]->start(bfa);
1107+
1108+ bfa->iocfc.submod_enabled = BFA_TRUE;
6861109 }
6871110
6881111 /*
@@ -693,8 +1116,13 @@ bfa_iocfc_disable_submod(struct bfa_s *bfa) · 4 unmodified lines
6931116 {
6941117 int i;
6951118
1119+ if (bfa->iocfc.submod_enabled == BFA_FALSE)
1120+ return;
1121+
6961122 for (i = 0; hal_mods[i]; i++)
6971123 hal_mods[i]->iocdisable(bfa);
1124+
1125+ bfa->iocfc.submod_enabled = BFA_FALSE;
6981126 }
6991127
7001128 static void
@@ -702,15 +1130,8 @@ bfa_iocfc_init_cb(void *bfa_arg, bfa_boolean_t complete) · 1 unmodified line
7021130 {
7031131 struct bfa_s *bfa = bfa_arg;
7041132
705− if (complete) {
706− if (bfa->iocfc.cfgdone && BFA_DCONF_MOD(bfa)->flashdone)
707− bfa_cb_init(bfa->bfad, BFA_STATUS_OK);
708− else
709− bfa_cb_init(bfa->bfad, BFA_STATUS_FAILED);
710− } else {
711− if (bfa->iocfc.cfgdone)
712− bfa->iocfc.action = BFA_IOCFC_ACT_NONE;
713− }
1133+ if (complete)
1134+ bfa_cb_init(bfa->bfad, bfa->iocfc.op_status);
7141135 }
7151136
7161137 static void
@@ -721,8 +1142,6 @@ bfa_iocfc_stop_cb(void *bfa_arg, bfa_boolean_t compl) · 4 unmodified lines
7211142
7221143 if (compl)
7231144 complete(&bfad->comp);
724− else
725− bfa->iocfc.action = BFA_IOCFC_ACT_NONE;
7261145 }
7271146
7281147 static void
@@ -794,8 +1213,6 @@ bfa_iocfc_cfgrsp(struct bfa_s *bfa) · 65 unmodified lines
7941213 fwcfg->num_uf_bufs = be16_to_cpu(fwcfg->num_uf_bufs);
7951214 fwcfg->num_rports = be16_to_cpu(fwcfg->num_rports);
7961215
797− iocfc->cfgdone = BFA_TRUE;
798−
7991216 /*
8001217 * configure queue register offsets as learnt from firmware
8011218 */
@@ -811,22 +1228,13 @@ bfa_iocfc_cfgrsp(struct bfa_s *bfa) · 9 unmodified lines
8111228 */
8121229 bfa_msix_queue_install(bfa);
8131230
814− /*
815− * Configuration is complete - initialize/start submodules
816− */
817− bfa_fcport_init(bfa);
818−
819− if (iocfc->action == BFA_IOCFC_ACT_INIT) {
820− if (BFA_DCONF_MOD(bfa)->flashdone == BFA_TRUE)
821− bfa_cb_queue(bfa, &iocfc->init_hcb_qe,
822− bfa_iocfc_init_cb, bfa);
823− } else {
824− if (bfa->iocfc.action == BFA_IOCFC_ACT_ENABLE)
825− bfa_cb_queue(bfa, &bfa->iocfc.en_hcb_qe,
826− bfa_iocfc_enable_cb, bfa);
827− bfa_iocfc_start_submod(bfa);
1231+ if (bfa->iocfc.cfgrsp->pbc_cfg.pbc_pwwn != 0) {
1232+ bfa->ioc.attr->pwwn = bfa->iocfc.cfgrsp->pbc_cfg.pbc_pwwn;
1233+ bfa->ioc.attr->nwwn = bfa->iocfc.cfgrsp->pbc_cfg.pbc_nwwn;
1234+ bfa_fsm_send_event(iocfc, IOCFC_E_CFG_DONE);
8281235 }
8291236 }
1237+
8301238 void
8311239 bfa_iocfc_reset_queues(struct bfa_s *bfa)
8321240 {
@@ -840,6 +1248,23 @@ bfa_iocfc_reset_queues(struct bfa_s *bfa) · 7 unmodified lines
8401248 }
8411249 }
8421250
1251+/*
1252+ * Process FAA pwwn msg from fw.
1253+ */
1254+static void
1255+bfa_iocfc_process_faa_addr(struct bfa_s *bfa, struct bfi_faa_addr_msg_s *msg)
1256+{
1257+ struct bfa_iocfc_s *iocfc = &bfa->iocfc;
1258+ struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
1259+
1260+ cfgrsp->pbc_cfg.pbc_pwwn = msg->pwwn;
1261+ cfgrsp->pbc_cfg.pbc_nwwn = msg->nwwn;
1262+
1263+ bfa->ioc.attr->pwwn = msg->pwwn;
1264+ bfa->ioc.attr->nwwn = msg->nwwn;
1265+ bfa_fsm_send_event(iocfc, IOCFC_E_CFG_DONE);
1266+}
1267+
8431268 /* Fabric Assigned Address specific functions */
8441269
8451270 /*
@@ -855,83 +1280,12 @@ bfa_faa_validate_request(struct bfa_s *bfa) · 9 unmodified lines
8551280 if ((ioc_type != BFA_IOC_TYPE_FC) || bfa_mfg_is_mezz(card_type))
8561281 return BFA_STATUS_FEATURE_NOT_SUPPORTED;
8571282 } else {
858− if (!bfa_ioc_is_acq_addr(&bfa->ioc))
859− return BFA_STATUS_IOC_NON_OP;
1283+ return BFA_STATUS_IOC_NON_OP;
8601284 }
8611285
8621286 return BFA_STATUS_OK;
8631287 }
8641288
865−bfa_status_t
866−bfa_faa_enable(struct bfa_s *bfa, bfa_cb_iocfc_t cbfn, void *cbarg)
867−{
868− struct bfi_faa_en_dis_s faa_enable_req;
869− struct bfa_iocfc_s *iocfc = &bfa->iocfc;
870− bfa_status_t status;
871−
872− iocfc->faa_args.faa_cb.faa_cbfn = cbfn;
873− iocfc->faa_args.faa_cb.faa_cbarg = cbarg;
874−
875− status = bfa_faa_validate_request(bfa);
876− if (status != BFA_STATUS_OK)
877− return status;
878−
879− if (iocfc->faa_args.busy == BFA_TRUE)
880− return BFA_STATUS_DEVBUSY;
881−
882− if (iocfc->faa_args.faa_state == BFA_FAA_ENABLED)
883− return BFA_STATUS_FAA_ENABLED;
884−
885− if (bfa_fcport_is_trunk_enabled(bfa))
886− return BFA_STATUS_ERROR_TRUNK_ENABLED;
887−
888− bfa_fcport_cfg_faa(bfa, BFA_FAA_ENABLED);
889− iocfc->faa_args.busy = BFA_TRUE;
890−
891− memset(&faa_enable_req, 0, sizeof(struct bfi_faa_en_dis_s));
892− bfi_h2i_set(faa_enable_req.mh, BFI_MC_IOCFC,
893− BFI_IOCFC_H2I_FAA_ENABLE_REQ, bfa_fn_lpu(bfa));
894−
895− bfa_ioc_mbox_send(&bfa->ioc, &faa_enable_req,
896− sizeof(struct bfi_faa_en_dis_s));
897−
898− return BFA_STATUS_OK;
899−}
900−
901−bfa_status_t
902−bfa_faa_disable(struct bfa_s *bfa, bfa_cb_iocfc_t cbfn,
903− void *cbarg)
904−{
905− struct bfi_faa_en_dis_s faa_disable_req;
906− struct bfa_iocfc_s *iocfc = &bfa->iocfc;
907− bfa_status_t status;
908−
909− iocfc->faa_args.faa_cb.faa_cbfn = cbfn;
910− iocfc->faa_args.faa_cb.faa_cbarg = cbarg;
911−
912− status = bfa_faa_validate_request(bfa);
913− if (status != BFA_STATUS_OK)
914− return status;
915−
916− if (iocfc->faa_args.busy == BFA_TRUE)
917− return BFA_STATUS_DEVBUSY;
918−
919− if (iocfc->faa_args.faa_state == BFA_FAA_DISABLED)
920− return BFA_STATUS_FAA_DISABLED;
921−
922− bfa_fcport_cfg_faa(bfa, BFA_FAA_DISABLED);
923− iocfc->faa_args.busy = BFA_TRUE;
924−
925− memset(&faa_disable_req, 0, sizeof(struct bfi_faa_en_dis_s));
926− bfi_h2i_set(faa_disable_req.mh, BFI_MC_IOCFC,
927− BFI_IOCFC_H2I_FAA_DISABLE_REQ, bfa_fn_lpu(bfa));
928−
929− bfa_ioc_mbox_send(&bfa->ioc, &faa_disable_req,
930− sizeof(struct bfi_faa_en_dis_s));
931−
932− return BFA_STATUS_OK;
933−}
934−
9351289 bfa_status_t
9361290 bfa_faa_query(struct bfa_s *bfa, struct bfa_faa_attr_s *attr,
9371291 bfa_cb_iocfc_t cbfn, void *cbarg)
@@ -962,38 +1316,6 @@ bfa_faa_query(struct bfa_s *bfa, struct bfa_faa_attr_s *attr, · 24 unmodified lines
9621316 return BFA_STATUS_OK;
9631317 }
9641318
965−/*
966− * FAA enable response
967− */
968−static void
969−bfa_faa_enable_reply(struct bfa_iocfc_s *iocfc,
970− struct bfi_faa_en_dis_rsp_s *rsp)
971−{
972− void *cbarg = iocfc->faa_args.faa_cb.faa_cbarg;
973− bfa_status_t status = rsp->status;
974−
975− WARN_ON(!iocfc->faa_args.faa_cb.faa_cbfn);
976−
977− iocfc->faa_args.faa_cb.faa_cbfn(cbarg, status);
978− iocfc->faa_args.busy = BFA_FALSE;
979−}
980−
981−/*
982− * FAA disable response
983− */
984−static void
985−bfa_faa_disable_reply(struct bfa_iocfc_s *iocfc,
986− struct bfi_faa_en_dis_rsp_s *rsp)
987−{
988− void *cbarg = iocfc->faa_args.faa_cb.faa_cbarg;
989− bfa_status_t status = rsp->status;
990−
991− WARN_ON(!iocfc->faa_args.faa_cb.faa_cbfn);
992−
993− iocfc->faa_args.faa_cb.faa_cbfn(cbarg, status);
994− iocfc->faa_args.busy = BFA_FALSE;
995−}
996−
9971319 /*
9981320 * FAA query response
9991321 */
@@ -1023,25 +1345,10 @@ bfa_iocfc_enable_cbfn(void *bfa_arg, enum bfa_status status) · 23 unmodified lines
10231345 {
10241346 struct bfa_s *bfa = bfa_arg;
10251347
1026− if (status == BFA_STATUS_FAA_ACQ_ADDR) {
1027− bfa_cb_queue(bfa, &bfa->iocfc.init_hcb_qe,
1028− bfa_iocfc_init_cb, bfa);
1029− return;
1030− }
1031−
1032− if (status != BFA_STATUS_OK) {
1033− bfa_isr_disable(bfa);
1034− if (bfa->iocfc.action == BFA_IOCFC_ACT_INIT)
1035− bfa_cb_queue(bfa, &bfa->iocfc.init_hcb_qe,
1036− bfa_iocfc_init_cb, bfa);
1037− else if (bfa->iocfc.action == BFA_IOCFC_ACT_ENABLE)
1038− bfa_cb_queue(bfa, &bfa->iocfc.en_hcb_qe,
1039− bfa_iocfc_enable_cb, bfa);
1040− return;
1041− }
1042−
1043− bfa_iocfc_send_cfg(bfa);
1044− bfa_dconf_modinit(bfa);
1348+ if (status == BFA_STATUS_OK)
1349+ bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_IOC_ENABLED);
1350+ else
1351+ bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_IOC_FAILED);
10451352 }
10461353
10471354 /*
@@ -1052,17 +1359,7 @@ bfa_iocfc_disable_cbfn(void *bfa_arg) · 4 unmodified lines
10521359 {
10531360 struct bfa_s *bfa = bfa_arg;
10541361
1055− bfa_isr_disable(bfa);
1056− bfa_iocfc_disable_submod(bfa);
1057−
1058− if (bfa->iocfc.action == BFA_IOCFC_ACT_STOP)
1059− bfa_cb_queue(bfa, &bfa->iocfc.stop_hcb_qe, bfa_iocfc_stop_cb,
1060− bfa);
1061− else {
1062− WARN_ON(bfa->iocfc.action != BFA_IOCFC_ACT_DISABLE);
1063− bfa_cb_queue(bfa, &bfa->iocfc.dis_hcb_qe, bfa_iocfc_disable_cb,
1064− bfa);
1065− }
1362+ bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_IOC_DISABLED);
10661363 }
10671364
10681365 /*
@@ -1074,13 +1371,7 @@ bfa_iocfc_hbfail_cbfn(void *bfa_arg) · 5 unmodified lines
10741371 struct bfa_s *bfa = bfa_arg;
10751372
10761373 bfa->queue_process = BFA_FALSE;
1077−
1078− bfa_isr_disable(bfa);
1079− bfa_iocfc_disable_submod(bfa);
1080−
1081− if (bfa->iocfc.action == BFA_IOCFC_ACT_INIT)
1082− bfa_cb_queue(bfa, &bfa->iocfc.init_hcb_qe, bfa_iocfc_init_cb,
1083− bfa);
1374+ bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_IOC_FAILED);
10841375 }
10851376
10861377 /*
@@ -1095,7 +1386,6 @@ bfa_iocfc_reset_cbfn(void *bfa_arg) · 8 unmodified lines
10951386 bfa_isr_enable(bfa);
10961387 }
10971388
1098−
10991389 /*
11001390 * Query IOC memory requirement information.
11011391 */
@@ -1171,6 +1461,12 @@ bfa_iocfc_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg, · 69 unmodified lines
11711461 INIT_LIST_HEAD(&bfa->comp_q);
11721462 for (i = 0; i < BFI_IOC_MAX_CQS; i++)
11731463 INIT_LIST_HEAD(&bfa->reqq_waitq[i]);
1464+
1465+ bfa->iocfc.cb_reqd = BFA_FALSE;
1466+ bfa->iocfc.op_status = BFA_STATUS_OK;
1467+ bfa->iocfc.submod_enabled = BFA_FALSE;
1468+
1469+ bfa_fsm_set_state(&bfa->iocfc, bfa_iocfc_sm_stopped);
11741470 }
11751471
11761472 /*
@@ -1179,8 +1475,7 @@ bfa_iocfc_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg, · 2 unmodified lines
11791475 void
11801476 bfa_iocfc_init(struct bfa_s *bfa)
11811477 {
1182− bfa->iocfc.action = BFA_IOCFC_ACT_INIT;
1183− bfa_ioc_enable(&bfa->ioc);
1478+ bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_INIT);
11841479 }
11851480
11861481 /*
@@ -1190,8 +1485,7 @@ bfa_iocfc_init(struct bfa_s *bfa) · 3 unmodified lines
11901485 void
11911486 bfa_iocfc_start(struct bfa_s *bfa)
11921487 {
1193− if (bfa->iocfc.cfgdone)
1194− bfa_iocfc_start_submod(bfa);
1488+ bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_START);
11951489 }
11961490
11971491 /*
@@ -1201,12 +1495,8 @@ bfa_iocfc_start(struct bfa_s *bfa) · 3 unmodified lines
12011495 void
12021496 bfa_iocfc_stop(struct bfa_s *bfa)
12031497 {
1204− bfa->iocfc.action = BFA_IOCFC_ACT_STOP;
1205−
12061498 bfa->queue_process = BFA_FALSE;
1207− bfa_dconf_modexit(bfa);
1208− if (BFA_DCONF_MOD(bfa)->flashdone == BFA_TRUE)
1209− bfa_ioc_disable(&bfa->ioc);
1499+ bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_STOP);
12101500 }
12111501
12121502 void
@@ -1226,13 +1516,9 @@ bfa_iocfc_isr(void *bfaarg, struct bfi_mbmsg_s *m) · 13 unmodified lines
12261516 case BFI_IOCFC_I2H_UPDATEQ_RSP:
12271517 iocfc->updateq_cbfn(iocfc->updateq_cbarg, BFA_STATUS_OK);
12281518 break;
1229− case BFI_IOCFC_I2H_FAA_ENABLE_RSP:
1230− bfa_faa_enable_reply(iocfc,
1231− (struct bfi_faa_en_dis_rsp_s *)msg);
1232− break;
1233− case BFI_IOCFC_I2H_FAA_DISABLE_RSP:
1234− bfa_faa_disable_reply(iocfc,
1235− (struct bfi_faa_en_dis_rsp_s *)msg);
1519+ case BFI_IOCFC_I2H_ADDR_MSG:
1520+ bfa_iocfc_process_faa_addr(bfa,
1521+ (struct bfi_faa_addr_msg_s *)msg);
12361522 break;
12371523 case BFI_IOCFC_I2H_FAA_QUERY_RSP:
12381524 bfa_faa_query_reply(iocfc, (bfi_faa_query_rsp_t *)msg);
@@ -1306,8 +1592,8 @@ bfa_iocfc_enable(struct bfa_s *bfa) · 67 unmodified lines
13061592 {
13071593 bfa_plog_str(bfa->plog, BFA_PL_MID_HAL, BFA_PL_EID_MISC, 0,
13081594 "IOC Enable");
1309− bfa->iocfc.action = BFA_IOCFC_ACT_ENABLE;
1310− bfa_ioc_enable(&bfa->ioc);
1595+ bfa->iocfc.cb_reqd = BFA_TRUE;
1596+ bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_ENABLE);
13111597 }
13121598
13131599 void
@@ -1315,17 +1601,16 @@ bfa_iocfc_disable(struct bfa_s *bfa) · 1 unmodified line
13151601 {
13161602 bfa_plog_str(bfa->plog, BFA_PL_MID_HAL, BFA_PL_EID_MISC, 0,
13171603 "IOC Disable");
1318− bfa->iocfc.action = BFA_IOCFC_ACT_DISABLE;
13191604
13201605 bfa->queue_process = BFA_FALSE;
1321− bfa_ioc_disable(&bfa->ioc);
1606+ bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_DISABLE);
13221607 }
13231608
1324−
13251609 bfa_boolean_t
13261610 bfa_iocfc_is_operational(struct bfa_s *bfa)
13271611 {
1328− return bfa_ioc_is_operational(&bfa->ioc) && bfa->iocfc.cfgdone;
1612+ return bfa_ioc_is_operational(&bfa->ioc) &&
1613+ bfa_fsm_cmp_state(&bfa->iocfc, bfa_iocfc_sm_operational);
13291614 }
13301615
13311616 /*
@@ -1567,16 +1852,6 @@ bfa_comp_free(struct bfa_s *bfa, struct list_head *comp_q) · 235 unmodified lines
15671852 }
15681853 }
15691854
1570−void
1571−bfa_iocfc_cb_dconf_modinit(struct bfa_s *bfa, bfa_status_t status)
1572−{
1573− if (bfa->iocfc.action == BFA_IOCFC_ACT_INIT) {
1574− if (bfa->iocfc.cfgdone == BFA_TRUE)
1575− bfa_cb_queue(bfa, &bfa->iocfc.init_hcb_qe,
1576− bfa_iocfc_init_cb, bfa);
1577− }
1578−}
1579−
15801855 /*
15811856 * Return the list of PCI vendor/device id lists supported by this
15821857 * BFA instance.
drivers/scsi/bfa/bfa_defs_svc.h+1−1
@@ -52,7 +52,7 @@ struct bfa_iocfc_fwcfg_s { · 51 unmodified lines
5252 u16 num_uf_bufs; /* unsolicited recv buffers */
5353 u8 num_cqs;
5454 u8 fw_tick_res; /* FW clock resolution in ms */
55− u8 rsvd[2];
55+ u8 rsvd[6];
5656 };
5757 #pragma pack()
5858
drivers/scsi/bfa/bfa_fcs_lport.c+2−0
@@ -5717,6 +5717,8 @@ bfa_fcs_vport_free(struct bfa_fcs_vport_s *vport) · 5716 unmodified lines
57175717
57185718 if (vport_drv->comp_del)
57195719 complete(vport_drv->comp_del);
5720+ else
5721+ kfree(vport_drv);
57205722
57215723 bfa_lps_delete(vport->lps);
57225724 }
drivers/scsi/bfa/bfa_fcs_rport.c+4−1
@@ -2169,7 +2169,10 @@ bfa_fcs_rport_update(struct bfa_fcs_rport_s *rport, struct fc_logi_s *plogi) · 2168 unmodified lines
21692169 * - MAX receive frame size
21702170 */
21712171 rport->cisc = plogi->csp.cisc;
2172− rport->maxfrsize = be16_to_cpu(plogi->class3.rxsz);
2172+ if (be16_to_cpu(plogi->class3.rxsz) < be16_to_cpu(plogi->csp.rxsz))
2173+ rport->maxfrsize = be16_to_cpu(plogi->class3.rxsz);
2174+ else
2175+ rport->maxfrsize = be16_to_cpu(plogi->csp.rxsz);
21732176
21742177 bfa_trc(port->fcs, be16_to_cpu(plogi->csp.bbcred));
21752178 bfa_trc(port->fcs, port->fabric->bb_credit);
drivers/scsi/bfa/bfa_ioc.c+71−117
@@ -88,7 +88,6 @@ static void bfa_ioc_hb_monitor(struct bfa_ioc_s *ioc); · 87 unmodified lines
8888 static void bfa_ioc_mbox_poll(struct bfa_ioc_s *ioc);
8989 static void bfa_ioc_mbox_flush(struct bfa_ioc_s *ioc);
9090 static void bfa_ioc_recover(struct bfa_ioc_s *ioc);
91−static void bfa_ioc_check_attr_wwns(struct bfa_ioc_s *ioc);
9291 static void bfa_ioc_event_notify(struct bfa_ioc_s *ioc ,
9392 enum bfa_ioc_event_e event);
9493 static void bfa_ioc_disable_comp(struct bfa_ioc_s *ioc);
@@ -97,7 +96,6 @@ static void bfa_ioc_debug_save_ftrc(struct bfa_ioc_s *ioc); · 2 unmodified lines
9796 static void bfa_ioc_fail_notify(struct bfa_ioc_s *ioc);
9897 static void bfa_ioc_pf_fwmismatch(struct bfa_ioc_s *ioc);
9998
100−
10199 /*
102100 * IOC state machine definitions/declarations
103101 */
@@ -114,7 +112,6 @@ enum ioc_event { · 10 unmodified lines
114112 IOC_E_HWERROR = 10, /* hardware error interrupt */
115113 IOC_E_TIMEOUT = 11, /* timeout */
116114 IOC_E_HWFAILED = 12, /* PCI mapping failure notice */
117− IOC_E_FWRSP_ACQ_ADDR = 13, /* Acquiring address */
118115 };
119116
120117 bfa_fsm_state_decl(bfa_ioc, uninit, struct bfa_ioc_s, enum ioc_event);
@@ -127,7 +124,6 @@ bfa_fsm_state_decl(bfa_ioc, fail, struct bfa_ioc_s, enum ioc_event); · 6 unmodified lines
127124 bfa_fsm_state_decl(bfa_ioc, disabling, struct bfa_ioc_s, enum ioc_event);
128125 bfa_fsm_state_decl(bfa_ioc, disabled, struct bfa_ioc_s, enum ioc_event);
129126 bfa_fsm_state_decl(bfa_ioc, hwfail, struct bfa_ioc_s, enum ioc_event);
130−bfa_fsm_state_decl(bfa_ioc, acq_addr, struct bfa_ioc_s, enum ioc_event);
131127
132128 static struct bfa_sm_table_s ioc_sm_table[] = {
133129 {BFA_SM(bfa_ioc_sm_uninit), BFA_IOC_UNINIT},
@@ -140,7 +136,6 @@ static struct bfa_sm_table_s ioc_sm_table[] = { · 6 unmodified lines
140136 {BFA_SM(bfa_ioc_sm_disabling), BFA_IOC_DISABLING},
141137 {BFA_SM(bfa_ioc_sm_disabled), BFA_IOC_DISABLED},
142138 {BFA_SM(bfa_ioc_sm_hwfail), BFA_IOC_HWFAIL},
143− {BFA_SM(bfa_ioc_sm_acq_addr), BFA_IOC_ACQ_ADDR},
144139 };
145140
146141 /*
@@ -371,17 +366,9 @@ bfa_ioc_sm_getattr(struct bfa_ioc_s *ioc, enum ioc_event event) · 224 unmodified lines
371366 switch (event) {
372367 case IOC_E_FWRSP_GETATTR:
373368 bfa_ioc_timer_stop(ioc);
374− bfa_ioc_check_attr_wwns(ioc);
375− bfa_ioc_hb_monitor(ioc);
376369 bfa_fsm_set_state(ioc, bfa_ioc_sm_op);
377370 break;
378371
379− case IOC_E_FWRSP_ACQ_ADDR:
380− bfa_ioc_timer_stop(ioc);
381− bfa_ioc_hb_monitor(ioc);
382− bfa_fsm_set_state(ioc, bfa_ioc_sm_acq_addr);
383− break;
384−
385372 case IOC_E_PFFAILED:
386373 case IOC_E_HWERROR:
387374 bfa_ioc_timer_stop(ioc);
@@ -406,51 +393,6 @@ bfa_ioc_sm_getattr(struct bfa_ioc_s *ioc, enum ioc_event event) · 18 unmodified lines
406393 }
407394 }
408395
409−/*
410− * Acquiring address from fabric (entry function)
411− */
412−static void
413−bfa_ioc_sm_acq_addr_entry(struct bfa_ioc_s *ioc)
414−{
415−}
416−
417−/*
418− * Acquiring address from the fabric
419− */
420−static void
421−bfa_ioc_sm_acq_addr(struct bfa_ioc_s *ioc, enum ioc_event event)
422−{
423− bfa_trc(ioc, event);
424−
425− switch (event) {
426− case IOC_E_FWRSP_GETATTR:
427− bfa_ioc_check_attr_wwns(ioc);
428− bfa_fsm_set_state(ioc, bfa_ioc_sm_op);
429− break;
430−
431− case IOC_E_PFFAILED:
432− case IOC_E_HWERROR:
433− bfa_hb_timer_stop(ioc);
434− case IOC_E_HBFAIL:
435− ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
436− bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
437− if (event != IOC_E_PFFAILED)
438− bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_GETATTRFAIL);
439− break;
440−
441− case IOC_E_DISABLE:
442− bfa_hb_timer_stop(ioc);
443− bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
444− break;
445−
446− case IOC_E_ENABLE:
447− break;
448−
449− default:
450− bfa_sm_fault(ioc, event);
451− }
452−}
453−
454396 static void
455397 bfa_ioc_sm_op_entry(struct bfa_ioc_s *ioc)
456398 {
@@ -458,6 +400,7 @@ bfa_ioc_sm_op_entry(struct bfa_ioc_s *ioc) · 1 unmodified line
458400
459401 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_OK);
460402 bfa_ioc_event_notify(ioc, BFA_IOC_E_ENABLED);
403+ bfa_ioc_hb_monitor(ioc);
461404 BFA_LOG(KERN_INFO, bfad, bfa_log_level, "IOC enabled\n");
462405 bfa_ioc_aen_post(ioc, BFA_IOC_AEN_ENABLE);
463406 }
@@ -738,26 +681,60 @@ static void · 274 unmodified lines
738681 bfa_iocpf_sm_fwcheck_entry(struct bfa_iocpf_s *iocpf)
739682 {
740683 struct bfi_ioc_image_hdr_s fwhdr;
741− u32 fwstate = readl(iocpf->ioc->ioc_regs.ioc_fwstate);
684+ u32 r32, fwstate, pgnum, pgoff, loff = 0;
685+ int i;
686+
687+ /*
688+ * Spin on init semaphore to serialize.
689+ */
690+ r32 = readl(iocpf->ioc->ioc_regs.ioc_init_sem_reg);
691+ while (r32 & 0x1) {
692+ udelay(20);
693+ r32 = readl(iocpf->ioc->ioc_regs.ioc_init_sem_reg);
694+ }
742695
743696 /* h/w sem init */
744− if (fwstate == BFI_IOC_UNINIT)
697+ fwstate = readl(iocpf->ioc->ioc_regs.ioc_fwstate);
698+ if (fwstate == BFI_IOC_UNINIT) {
699+ writel(1, iocpf->ioc->ioc_regs.ioc_init_sem_reg);
745700 goto sem_get;
701+ }
746702
747703 bfa_ioc_fwver_get(iocpf->ioc, &fwhdr);
748704
749− if (swab32(fwhdr.exec) == BFI_FWBOOT_TYPE_NORMAL)
705+ if (swab32(fwhdr.exec) == BFI_FWBOOT_TYPE_NORMAL) {
706+ writel(1, iocpf->ioc->ioc_regs.ioc_init_sem_reg);
750707 goto sem_get;
708+ }
709+
710+ /*
711+ * Clear fwver hdr
712+ */
713+ pgnum = PSS_SMEM_PGNUM(iocpf->ioc->ioc_regs.smem_pg0, loff);
714+ pgoff = PSS_SMEM_PGOFF(loff);
715+ writel(pgnum, iocpf->ioc->ioc_regs.host_page_num_fn);
716+
717+ for (i = 0; i < sizeof(struct bfi_ioc_image_hdr_s) / sizeof(u32); i++) {
718+ bfa_mem_write(iocpf->ioc->ioc_regs.smem_page_start, loff, 0);
719+ loff += sizeof(u32);
720+ }
751721
752722 bfa_trc(iocpf->ioc, fwstate);
753− bfa_trc(iocpf->ioc, fwhdr.exec);
723+ bfa_trc(iocpf->ioc, swab32(fwhdr.exec));
754724 writel(BFI_IOC_UNINIT, iocpf->ioc->ioc_regs.ioc_fwstate);
725+ writel(BFI_IOC_UNINIT, iocpf->ioc->ioc_regs.alt_ioc_fwstate);
755726
756727 /*
757− * Try to lock and then unlock the semaphore.
728+ * Unlock the hw semaphore. Should be here only once per boot.
758729 */
759730 readl(iocpf->ioc->ioc_regs.ioc_sem_reg);
760731 writel(1, iocpf->ioc->ioc_regs.ioc_sem_reg);
732+
733+ /*
734+ * unlock init semaphore.
735+ */
736+ writel(1, iocpf->ioc->ioc_regs.ioc_init_sem_reg);
737+
761738 sem_get:
762739 bfa_ioc_hw_sem_get(iocpf->ioc);
763740 }
@@ -1707,11 +1684,6 @@ bfa_ioc_download_fw(struct bfa_ioc_s *ioc, u32 boot_type, · 943 unmodified lines
17071684 u32 i;
17081685 u32 asicmode;
17091686
1710− /*
1711− * Initialize LMEM first before code download
1712− */
1713− bfa_ioc_lmem_init(ioc);
1714−
17151687 bfa_trc(ioc, bfa_cb_image_get_size(bfa_ioc_asic_gen(ioc)));
17161688 fwimg = bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc), chunkno);
17171689
@@ -1999,6 +1971,12 @@ bfa_ioc_pll_init(struct bfa_ioc_s *ioc) · 281 unmodified lines
19991971 bfa_ioc_pll_init_asic(ioc);
20001972
20011973 ioc->pllinit = BFA_TRUE;
1974+
1975+ /*
1976+ * Initialize LMEM
1977+ */
1978+ bfa_ioc_lmem_init(ioc);
1979+
20021980 /*
20031981 * release semaphore.
20041982 */
@@ -2122,10 +2100,6 @@ bfa_ioc_isr(struct bfa_ioc_s *ioc, struct bfi_mbmsg_s *m) · 117 unmodified lines
21222100 bfa_ioc_getattr_reply(ioc);
21232101 break;
21242102
2125− case BFI_IOC_I2H_ACQ_ADDR_REPLY:
2126− bfa_fsm_send_event(ioc, IOC_E_FWRSP_ACQ_ADDR);
2127− break;
2128−
21292103 default:
21302104 bfa_trc(ioc, msg->mh.msg_id);
21312105 WARN_ON(1);
@@ -2415,15 +2389,6 @@ bfa_ioc_is_disabled(struct bfa_ioc_s *ioc) · 283 unmodified lines
24152389 bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled);
24162390 }
24172391
2418−/*
2419− * Return TRUE if IOC is in acquiring address state
2420− */
2421−bfa_boolean_t
2422−bfa_ioc_is_acq_addr(struct bfa_ioc_s *ioc)
2423−{
2424− return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_acq_addr);
2425−}
2426−
24272392 /*
24282393 * return true if IOC firmware is different.
24292394 */
@@ -2916,17 +2881,6 @@ bfa_ioc_recover(struct bfa_ioc_s *ioc) · 486 unmodified lines
29162881 bfa_fsm_send_event(ioc, IOC_E_HBFAIL);
29172882 }
29182883
2919−static void
2920−bfa_ioc_check_attr_wwns(struct bfa_ioc_s *ioc)
2921−{
2922− if (bfa_ioc_get_type(ioc) == BFA_IOC_TYPE_LL)
2923− return;
2924− if (ioc->attr->nwwn == 0)
2925− bfa_ioc_aen_post(ioc, BFA_IOC_AEN_INVALID_NWWN);
2926− if (ioc->attr->pwwn == 0)
2927− bfa_ioc_aen_post(ioc, BFA_IOC_AEN_INVALID_PWWN);
2928−}
2929−
29302884 /*
29312885 * BFA IOC PF private functions
29322886 */
@@ -4495,7 +4449,7 @@ bfa_flash_read_part(struct bfa_flash_s *flash, enum bfa_flash_part_type type, · 1562 unmodified lines
44954449 */
44964450
44974451 #define BFA_DIAG_MEMTEST_TOV 50000 /* memtest timeout in msec */
4498−#define BFA_DIAG_FWPING_TOV 1000 /* msec */
4452+#define CT2_BFA_DIAG_MEMTEST_TOV (9*30*1000) /* 4.5 min */
44994453
45004454 /* IOC event handler */
45014455 static void
@@ -4772,7 +4726,7 @@ diag_ledtest_send(struct bfa_diag_s *diag, struct bfa_diag_ledtest_s *ledtest) · 270 unmodified lines
47724726 }
47734727
47744728 static void
4775−diag_ledtest_comp(struct bfa_diag_s *diag, struct bfi_diag_ledtest_rsp_s * msg)
4729+diag_ledtest_comp(struct bfa_diag_s *diag, struct bfi_diag_ledtest_rsp_s *msg)
47764730 {
47774731 bfa_trc(diag, diag->ledtest.lock);
47784732 diag->ledtest.lock = BFA_FALSE;
@@ -4850,6 +4804,8 @@ bfa_diag_memtest(struct bfa_diag_s *diag, struct bfa_diag_memtest_s *memtest, · 71 unmodified lines
48504804 u32 pattern, struct bfa_diag_memtest_result *result,
48514805 bfa_cb_diag_t cbfn, void *cbarg)
48524806 {
4807+ u32 memtest_tov;
4808+
48534809 bfa_trc(diag, pattern);
48544810
48554811 if (!bfa_ioc_adapter_is_disabled(diag->ioc))
@@ -4869,8 +4825,10 @@ bfa_diag_memtest(struct bfa_diag_s *diag, struct bfa_diag_memtest_s *memtest, · 13 unmodified lines
48694825 /* download memtest code and take LPU0 out of reset */
48704826 bfa_ioc_boot(diag->ioc, BFI_FWBOOT_TYPE_MEMTEST, BFI_FWBOOT_ENV_OS);
48714827
4828+ memtest_tov = (bfa_ioc_asic_gen(diag->ioc) == BFI_ASIC_GEN_CT2) ?
4829+ CT2_BFA_DIAG_MEMTEST_TOV : BFA_DIAG_MEMTEST_TOV;
48724830 bfa_timer_begin(diag->ioc->timer_mod, &diag->timer,
4873− bfa_diag_memtest_done, diag, BFA_DIAG_MEMTEST_TOV);
4831+ bfa_diag_memtest_done, diag, memtest_tov);
48744832 diag->timer_active = 1;
48754833 return BFA_STATUS_OK;
48764834 }
@@ -5641,24 +5599,27 @@ bfa_dconf_sm_uninit(struct bfa_dconf_mod_s *dconf, enum bfa_dconf_event event) · 764 unmodified lines
56415599 case BFA_DCONF_SM_INIT:
56425600 if (dconf->min_cfg) {
56435601 bfa_trc(dconf->bfa, dconf->min_cfg);
5602+ bfa_fsm_send_event(&dconf->bfa->iocfc,
5603+ IOCFC_E_DCONF_DONE);
56445604 return;
56455605 }
56465606 bfa_sm_set_state(dconf, bfa_dconf_sm_flash_read);
5647− dconf->flashdone = BFA_FALSE;
5648− bfa_trc(dconf->bfa, dconf->flashdone);
5607+ bfa_timer_start(dconf->bfa, &dconf->timer,
5608+ bfa_dconf_timer, dconf, BFA_DCONF_UPDATE_TOV);
56495609 bfa_status = bfa_flash_read_part(BFA_FLASH(dconf->bfa),
56505610 BFA_FLASH_PART_DRV, dconf->instance,
56515611 dconf->dconf,
56525612 sizeof(struct bfa_dconf_s), 0,
56535613 bfa_dconf_init_cb, dconf->bfa);
56545614 if (bfa_status != BFA_STATUS_OK) {
5615+ bfa_timer_stop(&dconf->timer);
56555616 bfa_dconf_init_cb(dconf->bfa, BFA_STATUS_FAILED);
56565617 bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
56575618 return;
56585619 }
56595620 break;
56605621 case BFA_DCONF_SM_EXIT:
5661− dconf->flashdone = BFA_TRUE;
5622+ bfa_fsm_send_event(&dconf->bfa->iocfc, IOCFC_E_DCONF_DONE);
56625623 case BFA_DCONF_SM_IOCDISABLE:
56635624 case BFA_DCONF_SM_WR:
56645625 case BFA_DCONF_SM_FLASH_COMP:
@@ -5679,15 +5640,20 @@ bfa_dconf_sm_flash_read(struct bfa_dconf_mod_s *dconf, · 14 unmodified lines
56795640
56805641 switch (event) {
56815642 case BFA_DCONF_SM_FLASH_COMP:
5643+ bfa_timer_stop(&dconf->timer);
56825644 bfa_sm_set_state(dconf, bfa_dconf_sm_ready);
56835645 break;
56845646 case BFA_DCONF_SM_TIMEOUT:
56855647 bfa_sm_set_state(dconf, bfa_dconf_sm_ready);
5648+ bfa_fsm_send_event(&dconf->bfa->iocfc, IOCFC_E_IOC_FAILED);
56865649 break;
56875650 case BFA_DCONF_SM_EXIT:
5688− dconf->flashdone = BFA_TRUE;
5689− bfa_trc(dconf->bfa, dconf->flashdone);
5651+ bfa_timer_stop(&dconf->timer);
5652+ bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
5653+ bfa_fsm_send_event(&dconf->bfa->iocfc, IOCFC_E_DCONF_DONE);
5654+ break;
56905655 case BFA_DCONF_SM_IOCDISABLE:
5656+ bfa_timer_stop(&dconf->timer);
56915657 bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
56925658 break;
56935659 default:
@@ -5710,9 +5676,8 @@ bfa_dconf_sm_ready(struct bfa_dconf_mod_s *dconf, enum bfa_dconf_event event) · 16 unmodified lines
57105676 bfa_sm_set_state(dconf, bfa_dconf_sm_dirty);
57115677 break;
57125678 case BFA_DCONF_SM_EXIT:
5713− dconf->flashdone = BFA_TRUE;
5714− bfa_trc(dconf->bfa, dconf->flashdone);
57155679 bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
5680+ bfa_fsm_send_event(&dconf->bfa->iocfc, IOCFC_E_DCONF_DONE);
57165681 break;
57175682 case BFA_DCONF_SM_INIT:
57185683 case BFA_DCONF_SM_IOCDISABLE:
@@ -5774,9 +5739,7 @@ bfa_dconf_sm_final_sync(struct bfa_dconf_mod_s *dconf, · 55 unmodified lines
57745739 bfa_timer_stop(&dconf->timer);
57755740 case BFA_DCONF_SM_TIMEOUT:
57765741 bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
5777− dconf->flashdone = BFA_TRUE;
5778− bfa_trc(dconf->bfa, dconf->flashdone);
5779− bfa_ioc_disable(&dconf->bfa->ioc);
5742+ bfa_fsm_send_event(&dconf->bfa->iocfc, IOCFC_E_DCONF_DONE);
57805743 break;
57815744 default:
57825745 bfa_sm_fault(dconf->bfa, event);
@@ -5823,8 +5786,8 @@ bfa_dconf_sm_iocdown_dirty(struct bfa_dconf_mod_s *dconf, · 40 unmodified lines
58235786 bfa_sm_set_state(dconf, bfa_dconf_sm_dirty);
58245787 break;
58255788 case BFA_DCONF_SM_EXIT:
5826− dconf->flashdone = BFA_TRUE;
58275789 bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
5790+ bfa_fsm_send_event(&dconf->bfa->iocfc, IOCFC_E_DCONF_DONE);
58285791 break;
58295792 case BFA_DCONF_SM_IOCDISABLE:
58305793 break;
@@ -5865,11 +5828,6 @@ bfa_dconf_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg, · 34 unmodified lines
58655828 if (cfg->drvcfg.min_cfg) {
58665829 bfa_mem_kva_curp(dconf) += sizeof(struct bfa_dconf_hdr_s);
58675830 dconf->min_cfg = BFA_TRUE;
5868− /*
5869− * Set the flashdone flag to TRUE explicitly as no flash
5870− * write will happen in min_cfg mode.
5871− */
5872− dconf->flashdone = BFA_TRUE;
58735831 } else {
58745832 dconf->min_cfg = BFA_FALSE;
58755833 bfa_mem_kva_curp(dconf) += sizeof(struct bfa_dconf_s);
@@ -5885,9 +5843,7 @@ bfa_dconf_init_cb(void *arg, bfa_status_t status) · 9 unmodified lines
58855843 struct bfa_s *bfa = arg;
58865844 struct bfa_dconf_mod_s *dconf = BFA_DCONF_MOD(bfa);
58875845
5888− dconf->flashdone = BFA_TRUE;
5889− bfa_trc(bfa, dconf->flashdone);
5890− bfa_iocfc_cb_dconf_modinit(bfa, status);
5846+ bfa_sm_send_event(dconf, BFA_DCONF_SM_FLASH_COMP);
58915847 if (status == BFA_STATUS_OK) {
58925848 bfa_dconf_read_data_valid(bfa) = BFA_TRUE;
58935849 if (dconf->dconf->hdr.signature != BFI_DCONF_SIGNATURE)
@@ -5895,7 +5851,7 @@ bfa_dconf_init_cb(void *arg, bfa_status_t status) · 1 unmodified line
58955851 if (dconf->dconf->hdr.version != BFI_DCONF_VERSION)
58965852 dconf->dconf->hdr.version = BFI_DCONF_VERSION;
58975853 }
5898− bfa_sm_send_event(dconf, BFA_DCONF_SM_FLASH_COMP);
5854+ bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_DCONF_DONE);
58995855 }
59005856
59015857 void
@@ -5977,7 +5933,5 @@ void · 75 unmodified lines
59775933 bfa_dconf_modexit(struct bfa_s *bfa)
59785934 {
59795935 struct bfa_dconf_mod_s *dconf = BFA_DCONF_MOD(bfa);
5980− BFA_DCONF_MOD(bfa)->flashdone = BFA_FALSE;
5981− bfa_trc(bfa, BFA_DCONF_MOD(bfa)->flashdone);
59825936 bfa_sm_send_event(dconf, BFA_DCONF_SM_EXIT);
59835937 }
drivers/scsi/bfa/bfa_ioc.h+16−1
@@ -372,6 +372,22 @@ struct bfa_cb_qe_s { · 371 unmodified lines
372372 void *cbarg;
373373 };
374374
375+/*
376+ * IOCFC state machine definitions/declarations
377+ */
378+enum iocfc_event {
379+ IOCFC_E_INIT = 1, /* IOCFC init request */
380+ IOCFC_E_START = 2, /* IOCFC mod start request */
381+ IOCFC_E_STOP = 3, /* IOCFC stop request */
382+ IOCFC_E_ENABLE = 4, /* IOCFC enable request */
383+ IOCFC_E_DISABLE = 5, /* IOCFC disable request */
384+ IOCFC_E_IOC_ENABLED = 6, /* IOC enabled message */
385+ IOCFC_E_IOC_DISABLED = 7, /* IOC disabled message */
386+ IOCFC_E_IOC_FAILED = 8, /* failure notice by IOC sm */
387+ IOCFC_E_DCONF_DONE = 9, /* dconf read/write done */
388+ IOCFC_E_CFG_DONE = 10, /* IOCFC config complete */
389+};
390+
375391 /*
376392 * ASIC block configurtion related
377393 */
@@ -706,7 +722,6 @@ struct bfa_dconf_s { · 328 unmodified lines
706722 struct bfa_dconf_mod_s {
707723 bfa_sm_t sm;
708724 u8 instance;
709− bfa_boolean_t flashdone;
710725 bfa_boolean_t read_data_valid;
711726 bfa_boolean_t min_cfg;
712727 struct bfa_timer_s timer;
drivers/scsi/bfa/bfa_ioc_ct.c+106−45
@@ -786,17 +786,73 @@ bfa_ioc_ct2_mac_reset(void __iomem *rb) · 785 unmodified lines
786786 }
787787
788788 #define CT2_NFC_MAX_DELAY 1000
789+#define CT2_NFC_VER_VALID 0x143
790+#define BFA_IOC_PLL_POLL 1000000
791+
792+static bfa_boolean_t
793+bfa_ioc_ct2_nfc_halted(void __iomem *rb)
794+{
795+ u32 r32;
796+
797+ r32 = readl(rb + CT2_NFC_CSR_SET_REG);
798+ if (r32 & __NFC_CONTROLLER_HALTED)
799+ return BFA_TRUE;
800+
801+ return BFA_FALSE;
802+}
803+
804+static void
805+bfa_ioc_ct2_nfc_resume(void __iomem *rb)
806+{
807+ u32 r32;
808+ int i;
809+
810+ writel(__HALT_NFC_CONTROLLER, rb + CT2_NFC_CSR_CLR_REG);
811+ for (i = 0; i < CT2_NFC_MAX_DELAY; i++) {
812+ r32 = readl(rb + CT2_NFC_CSR_SET_REG);
813+ if (!(r32 & __NFC_CONTROLLER_HALTED))
814+ return;
815+ udelay(1000);
816+ }
817+ WARN_ON(1);
818+}
819+
789820 bfa_status_t
790821 bfa_ioc_ct2_pll_init(void __iomem *rb, enum bfi_asic_mode mode)
791822 {
792− u32 wgn, r32;
793− int i;
823+ u32 wgn, r32, nfc_ver, i;
794824
795− /*
796− * Initialize PLL if not already done by NFC
797− */
798825 wgn = readl(rb + CT2_WGN_STATUS);
799− if (!(wgn & __GLBL_PF_VF_CFG_RDY)) {
826+ nfc_ver = readl(rb + CT2_RSC_GPR15_REG);
827+
828+ if ((wgn == (__A2T_AHB_LOAD | __WGN_READY)) &&
829+ (nfc_ver >= CT2_NFC_VER_VALID)) {
830+ if (bfa_ioc_ct2_nfc_halted(rb))
831+ bfa_ioc_ct2_nfc_resume(rb);
832+
833+ writel(__RESET_AND_START_SCLK_LCLK_PLLS,
834+ rb + CT2_CSI_FW_CTL_SET_REG);
835+
836+ for (i = 0; i < BFA_IOC_PLL_POLL; i++) {
837+ r32 = readl(rb + CT2_APP_PLL_LCLK_CTL_REG);
838+ if (r32 & __RESET_AND_START_SCLK_LCLK_PLLS)
839+ break;
840+ }
841+
842+ WARN_ON(!(r32 & __RESET_AND_START_SCLK_LCLK_PLLS));
843+
844+ for (i = 0; i < BFA_IOC_PLL_POLL; i++) {
845+ r32 = readl(rb + CT2_APP_PLL_LCLK_CTL_REG);
846+ if (!(r32 & __RESET_AND_START_SCLK_LCLK_PLLS))
847+ break;
848+ }
849+
850+ WARN_ON(r32 & __RESET_AND_START_SCLK_LCLK_PLLS);
851+ udelay(1000);
852+
853+ r32 = readl(rb + CT2_CSI_FW_CTL_REG);
854+ WARN_ON(r32 & __RESET_AND_START_SCLK_LCLK_PLLS);
855+ } else {
800856 writel(__HALT_NFC_CONTROLLER, rb + CT2_NFC_CSR_SET_REG);
801857 for (i = 0; i < CT2_NFC_MAX_DELAY; i++) {
802858 r32 = readl(rb + CT2_NFC_CSR_SET_REG);
@@ -804,57 +860,62 @@ bfa_ioc_ct2_pll_init(void __iomem *rb, enum bfi_asic_mode mode) · 1 unmodified line
804860 break;
805861 udelay(1000);
806862 }
807− }
808863
809− /*
810− * Mask the interrupts and clear any
811− * pending interrupts.
812− */
813− writel(1, (rb + CT2_LPU0_HOSTFN_MBOX0_MSK));
814− writel(1, (rb + CT2_LPU1_HOSTFN_MBOX0_MSK));
815−
816− r32 = readl((rb + CT2_LPU0_HOSTFN_CMD_STAT));
817− if (r32 == 1) {
818− writel(1, (rb + CT2_LPU0_HOSTFN_CMD_STAT));
819− readl((rb + CT2_LPU0_HOSTFN_CMD_STAT));
864+ bfa_ioc_ct2_mac_reset(rb);
865+ bfa_ioc_ct2_sclk_init(rb);
866+ bfa_ioc_ct2_lclk_init(rb);
867+
868+ /*
869+ * release soft reset on s_clk & l_clk
870+ */
871+ r32 = readl(rb + CT2_APP_PLL_SCLK_CTL_REG);
872+ writel(r32 & ~__APP_PLL_SCLK_LOGIC_SOFT_RESET,
873+ (rb + CT2_APP_PLL_SCLK_CTL_REG));
874+
875+ /*
876+ * release soft reset on s_clk & l_clk
877+ */
878+ r32 = readl(rb + CT2_APP_PLL_LCLK_CTL_REG);
879+ writel(r32 & ~__APP_PLL_LCLK_LOGIC_SOFT_RESET,
880+ (rb + CT2_APP_PLL_LCLK_CTL_REG));
820881 }
821− r32 = readl((rb + CT2_LPU1_HOSTFN_CMD_STAT));
822− if (r32 == 1) {
823− writel(1, (rb + CT2_LPU1_HOSTFN_CMD_STAT));
824− readl((rb + CT2_LPU1_HOSTFN_CMD_STAT));
825− }
826−
827− bfa_ioc_ct2_mac_reset(rb);
828− bfa_ioc_ct2_sclk_init(rb);
829− bfa_ioc_ct2_lclk_init(rb);
830−
831− /*
832− * release soft reset on s_clk & l_clk
833− */
834− r32 = readl((rb + CT2_APP_PLL_SCLK_CTL_REG));
835− writel(r32 & ~__APP_PLL_SCLK_LOGIC_SOFT_RESET,
836− (rb + CT2_APP_PLL_SCLK_CTL_REG));
837−
838− /*
839− * release soft reset on s_clk & l_clk
840− */
841− r32 = readl((rb + CT2_APP_PLL_LCLK_CTL_REG));
842− writel(r32 & ~__APP_PLL_LCLK_LOGIC_SOFT_RESET,
843− (rb + CT2_APP_PLL_LCLK_CTL_REG));
844882
845883 /*
846884 * Announce flash device presence, if flash was corrupted.
847885 */
848886 if (wgn == (__WGN_READY | __GLBL_PF_VF_CFG_RDY)) {
849− r32 = readl((rb + PSS_GPIO_OUT_REG));
887+ r32 = readl(rb + PSS_GPIO_OUT_REG);
850888 writel(r32 & ~1, (rb + PSS_GPIO_OUT_REG));
851− r32 = readl((rb + PSS_GPIO_OE_REG));
889+ r32 = readl(rb + PSS_GPIO_OE_REG);
852890 writel(r32 | 1, (rb + PSS_GPIO_OE_REG));
853891 }
854892
893+ /*
894+ * Mask the interrupts and clear any
895+ * pending interrupts.
896+ */
897+ writel(1, (rb + CT2_LPU0_HOSTFN_MBOX0_MSK));
898+ writel(1, (rb + CT2_LPU1_HOSTFN_MBOX0_MSK));
899+
900+ /* For first time initialization, no need to clear interrupts */
901+ r32 = readl(rb + HOST_SEM5_REG);
902+ if (r32 & 0x1) {
903+ r32 = readl(rb + CT2_LPU0_HOSTFN_CMD_STAT);
904+ if (r32 == 1) {
905+ writel(1, rb + CT2_LPU0_HOSTFN_CMD_STAT);
906+ readl((rb + CT2_LPU0_HOSTFN_CMD_STAT));
907+ }
908+ r32 = readl(rb + CT2_LPU1_HOSTFN_CMD_STAT);
909+ if (r32 == 1) {
910+ writel(1, rb + CT2_LPU1_HOSTFN_CMD_STAT);
911+ readl(rb + CT2_LPU1_HOSTFN_CMD_STAT);
912+ }
913+ }
914+
855915 bfa_ioc_ct2_mem_init(rb);
856916
857− writel(BFI_IOC_UNINIT, (rb + CT2_BFA_IOC0_STATE_REG));
858− writel(BFI_IOC_UNINIT, (rb + CT2_BFA_IOC1_STATE_REG));
917+ writel(BFI_IOC_UNINIT, rb + CT2_BFA_IOC0_STATE_REG);
918+ writel(BFI_IOC_UNINIT, rb + CT2_BFA_IOC1_STATE_REG);
919+
859920 return BFA_STATUS_OK;
860921 }
drivers/scsi/bfa/bfa_svc.c+19−50
@@ -1280,6 +1280,7 @@ bfa_lps_sm_loginwait(struct bfa_lps_s *lps, enum bfa_lps_event event) · 1279 unmodified lines
12801280 switch (event) {
12811281 case BFA_LPS_SM_RESUME:
12821282 bfa_sm_set_state(lps, bfa_lps_sm_login);
1283+ bfa_lps_send_login(lps);
12831284 break;
12841285
12851286 case BFA_LPS_SM_OFFLINE:
@@ -1578,7 +1579,7 @@ bfa_lps_login_rsp(struct bfa_s *bfa, struct bfi_lps_login_rsp_s *rsp) · 292 unmodified lines
15781579 break;
15791580
15801581 case BFA_STATUS_VPORT_MAX:
1581− if (!rsp->ext_status)
1582+ if (rsp->ext_status)
15821583 bfa_lps_no_res(lps, rsp->ext_status);
15831584 break;
15841585
@@ -3083,33 +3084,6 @@ bfa_fcport_set_wwns(struct bfa_fcport_s *fcport) · 1498 unmodified lines
30833084 bfa_trc(fcport->bfa, fcport->nwwn);
30843085 }
30853086
3086−static void
3087−bfa_fcport_send_txcredit(void *port_cbarg)
3088−{
3089−
3090− struct bfa_fcport_s *fcport = port_cbarg;
3091− struct bfi_fcport_set_svc_params_req_s *m;
3092−
3093− /*
3094− * check for room in queue to send request now
3095− */
3096− m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
3097− if (!m) {
3098− bfa_trc(fcport->bfa, fcport->cfg.tx_bbcredit);
3099− return;
3100− }
3101−
3102− bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_SET_SVC_PARAMS_REQ,
3103− bfa_fn_lpu(fcport->bfa));
3104− m->tx_bbcredit = cpu_to_be16((u16)fcport->cfg.tx_bbcredit);
3105− m->bb_scn = fcport->cfg.bb_scn;
3106−
3107− /*
3108− * queue I/O message to firmware
3109− */
3110− bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT, m->mh);
3111−}
3112−
31133087 static void
31143088 bfa_fcport_qos_stats_swap(struct bfa_qos_stats_s *d,
31153089 struct bfa_qos_stats_s *s)
@@ -3602,26 +3576,24 @@ bfa_fcport_cfg_speed(struct bfa_s *bfa, enum bfa_port_speed speed) · 486 unmodified lines
36023576 return BFA_STATUS_UNSUPP_SPEED;
36033577 }
36043578
3605− /* For Mezz card, port speed entered needs to be checked */
3606− if (bfa_mfg_is_mezz(fcport->bfa->ioc.attr->card_type)) {
3607− if (bfa_ioc_get_type(&fcport->bfa->ioc) == BFA_IOC_TYPE_FC) {
3608− /* For CT2, 1G is not supported */
3609− if ((speed == BFA_PORT_SPEED_1GBPS) &&
3610− (bfa_asic_id_ct2(bfa->ioc.pcidev.device_id)))
3611− return BFA_STATUS_UNSUPP_SPEED;
3579+ /* Port speed entered needs to be checked */
3580+ if (bfa_ioc_get_type(&fcport->bfa->ioc) == BFA_IOC_TYPE_FC) {
3581+ /* For CT2, 1G is not supported */
3582+ if ((speed == BFA_PORT_SPEED_1GBPS) &&
3583+ (bfa_asic_id_ct2(bfa->ioc.pcidev.device_id)))
3584+ return BFA_STATUS_UNSUPP_SPEED;
36123585
3613− /* Already checked for Auto Speed and Max Speed supp */
3614− if (!(speed == BFA_PORT_SPEED_1GBPS ||
3615− speed == BFA_PORT_SPEED_2GBPS ||
3616− speed == BFA_PORT_SPEED_4GBPS ||
3617− speed == BFA_PORT_SPEED_8GBPS ||
3618− speed == BFA_PORT_SPEED_16GBPS ||
3619− speed == BFA_PORT_SPEED_AUTO))
3620− return BFA_STATUS_UNSUPP_SPEED;
3621− } else {
3622− if (speed != BFA_PORT_SPEED_10GBPS)
3623− return BFA_STATUS_UNSUPP_SPEED;
3624− }
3586+ /* Already checked for Auto Speed and Max Speed supp */
3587+ if (!(speed == BFA_PORT_SPEED_1GBPS ||
3588+ speed == BFA_PORT_SPEED_2GBPS ||
3589+ speed == BFA_PORT_SPEED_4GBPS ||
3590+ speed == BFA_PORT_SPEED_8GBPS ||
3591+ speed == BFA_PORT_SPEED_16GBPS ||
3592+ speed == BFA_PORT_SPEED_AUTO))
3593+ return BFA_STATUS_UNSUPP_SPEED;
3594+ } else {
3595+ if (speed != BFA_PORT_SPEED_10GBPS)
3596+ return BFA_STATUS_UNSUPP_SPEED;
36253597 }
36263598
36273599 fcport->cfg.speed = speed;
@@ -3765,7 +3737,6 @@ bfa_fcport_set_tx_bbcredit(struct bfa_s *bfa, u16 tx_bbcredit, u8 bb_scn) · 137 unmodified lines
37653737 fcport->cfg.bb_scn = bb_scn;
37663738 if (bb_scn)
37673739 fcport->bbsc_op_state = BFA_TRUE;
3768− bfa_fcport_send_txcredit(fcport);
37693740 }
37703741
37713742 /*
@@ -3825,8 +3796,6 @@ bfa_fcport_get_attr(struct bfa_s *bfa, struct bfa_port_attr_s *attr) · 53 unmodified lines
38253796 attr->port_state = BFA_PORT_ST_IOCDIS;
38263797 else if (bfa_ioc_fw_mismatch(&fcport->bfa->ioc))
38273798 attr->port_state = BFA_PORT_ST_FWMISMATCH;
3828− else if (bfa_ioc_is_acq_addr(&fcport->bfa->ioc))
3829− attr->port_state = BFA_PORT_ST_ACQ_ADDR;
38303799 }
38313800
38323801 /* FCoE vlan */
drivers/scsi/bfa/bfa_svc.h+0−4
@@ -663,10 +663,6 @@ void bfa_cb_lps_fdisclogo_comp(void *bfad, void *uarg); · 662 unmodified lines
663663 void bfa_cb_lps_cvl_event(void *bfad, void *uarg);
664664
665665 /* FAA specific APIs */
666−bfa_status_t bfa_faa_enable(struct bfa_s *bfa,
667− bfa_cb_iocfc_t cbfn, void *cbarg);
668−bfa_status_t bfa_faa_disable(struct bfa_s *bfa,
669− bfa_cb_iocfc_t cbfn, void *cbarg);
670666 bfa_status_t bfa_faa_query(struct bfa_s *bfa, struct bfa_faa_attr_s *attr,
671667 bfa_cb_iocfc_t cbfn, void *cbarg);
672668
drivers/scsi/bfa/bfad_attr.c+43−4
@@ -442,6 +442,43 @@ bfad_im_vport_create(struct fc_vport *fc_vport, bool disable) · 441 unmodified lines
442442 return status;
443443 }
444444
445+int
446+bfad_im_issue_fc_host_lip(struct Scsi_Host *shost)
447+{
448+ struct bfad_im_port_s *im_port =
449+ (struct bfad_im_port_s *) shost->hostdata[0];
450+ struct bfad_s *bfad = im_port->bfad;
451+ struct bfad_hal_comp fcomp;
452+ unsigned long flags;
453+ uint32_t status;
454+
455+ init_completion(&fcomp.comp);
456+ spin_lock_irqsave(&bfad->bfad_lock, flags);
457+ status = bfa_port_disable(&bfad->bfa.modules.port,
458+ bfad_hcb_comp, &fcomp);
459+ spin_unlock_irqrestore(&bfad->bfad_lock, flags);
460+
461+ if (status != BFA_STATUS_OK)
462+ return -EIO;
463+
464+ wait_for_completion(&fcomp.comp);
465+ if (fcomp.status != BFA_STATUS_OK)
466+ return -EIO;
467+
468+ spin_lock_irqsave(&bfad->bfad_lock, flags);
469+ status = bfa_port_enable(&bfad->bfa.modules.port,
470+ bfad_hcb_comp, &fcomp);
471+ spin_unlock_irqrestore(&bfad->bfad_lock, flags);
472+ if (status != BFA_STATUS_OK)
473+ return -EIO;
474+
475+ wait_for_completion(&fcomp.comp);
476+ if (fcomp.status != BFA_STATUS_OK)
477+ return -EIO;
478+
479+ return 0;
480+}
481+
445482 static int
446483 bfad_im_vport_delete(struct fc_vport *fc_vport)
447484 {
@@ -457,8 +494,11 @@ bfad_im_vport_delete(struct fc_vport *fc_vport) · 9 unmodified lines
457494 unsigned long flags;
458495 struct completion fcomp;
459496
460− if (im_port->flags & BFAD_PORT_DELETE)
461− goto free_scsi_host;
497+ if (im_port->flags & BFAD_PORT_DELETE) {
498+ bfad_scsi_host_free(bfad, im_port);
499+ list_del(&vport->list_entry);
500+ return 0;
501+ }
462502
463503 port = im_port->port;
464504
@@ -489,7 +529,6 @@ bfad_im_vport_delete(struct fc_vport *fc_vport) · 24 unmodified lines
489529
490530 wait_for_completion(vport->comp_del);
491531
492−free_scsi_host:
493532 bfad_scsi_host_free(bfad, im_port);
494533 list_del(&vport->list_entry);
495534 kfree(vport);
@@ -579,7 +618,7 @@ struct fc_function_template bfad_im_fc_function_template = { · 83 unmodified lines
579618 .show_rport_dev_loss_tmo = 1,
580619 .get_rport_dev_loss_tmo = bfad_im_get_rport_loss_tmo,
581620 .set_rport_dev_loss_tmo = bfad_im_set_rport_loss_tmo,
582−
621+ .issue_fc_host_lip = bfad_im_issue_fc_host_lip,
583622 .vport_create = bfad_im_vport_create,
584623 .vport_delete = bfad_im_vport_delete,
585624 .vport_disable = bfad_im_vport_disable,
drivers/scsi/bfa/bfad_bsg.c+11−51
@@ -1287,50 +1287,6 @@ out: · 1286 unmodified lines
12871287 return 0;
12881288 }
12891289
1290−int
1291−bfad_iocmd_faa_enable(struct bfad_s *bfad, void *cmd)
1292−{
1293− struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
1294− unsigned long flags;
1295− struct bfad_hal_comp fcomp;
1296−
1297− init_completion(&fcomp.comp);
1298− iocmd->status = BFA_STATUS_OK;
1299− spin_lock_irqsave(&bfad->bfad_lock, flags);
1300− iocmd->status = bfa_faa_enable(&bfad->bfa, bfad_hcb_comp, &fcomp);
1301− spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1302−
1303− if (iocmd->status != BFA_STATUS_OK)
1304− goto out;
1305−
1306− wait_for_completion(&fcomp.comp);
1307− iocmd->status = fcomp.status;
1308−out:
1309− return 0;
1310−}
1311−
1312−int
1313−bfad_iocmd_faa_disable(struct bfad_s *bfad, void *cmd)
1314−{
1315− struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
1316− unsigned long flags;
1317− struct bfad_hal_comp fcomp;
1318−
1319− init_completion(&fcomp.comp);
1320− iocmd->status = BFA_STATUS_OK;
1321− spin_lock_irqsave(&bfad->bfad_lock, flags);
1322− iocmd->status = bfa_faa_disable(&bfad->bfa, bfad_hcb_comp, &fcomp);
1323− spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1324−
1325− if (iocmd->status != BFA_STATUS_OK)
1326− goto out;
1327−
1328− wait_for_completion(&fcomp.comp);
1329− iocmd->status = fcomp.status;
1330−out:
1331− return 0;
1332−}
1333−
13341290 int
13351291 bfad_iocmd_faa_query(struct bfad_s *bfad, void *cmd)
13361292 {
@@ -1918,6 +1874,7 @@ bfad_iocmd_debug_fw_core(struct bfad_s *bfad, void *cmd, · 581 unmodified lines
19181874 struct bfa_bsg_debug_s *iocmd = (struct bfa_bsg_debug_s *)cmd;
19191875 void *iocmd_bufptr;
19201876 unsigned long flags;
1877+ u32 offset;
19211878
19221879 if (bfad_chk_iocmd_sz(payload_len, sizeof(struct bfa_bsg_debug_s),
19231880 BFA_DEBUG_FW_CORE_CHUNK_SZ) != BFA_STATUS_OK) {
@@ -1935,8 +1892,10 @@ bfad_iocmd_debug_fw_core(struct bfad_s *bfad, void *cmd, · 11 unmodified lines
19351892
19361893 iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_debug_s);
19371894 spin_lock_irqsave(&bfad->bfad_lock, flags);
1895+ offset = iocmd->offset;
19381896 iocmd->status = bfa_ioc_debug_fwcore(&bfad->bfa.ioc, iocmd_bufptr,
1939− (u32 *)&iocmd->offset, &iocmd->bufsz);
1897+ &offset, &iocmd->bufsz);
1898+ iocmd->offset = offset;
19401899 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
19411900 out:
19421901 return 0;
@@ -2633,12 +2592,6 @@ bfad_iocmd_handler(struct bfad_s *bfad, unsigned int cmd, void *iocmd, · 690 unmodified lines
26332592 case IOCMD_FLASH_DISABLE_OPTROM:
26342593 rc = bfad_iocmd_ablk_optrom(bfad, cmd, iocmd);
26352594 break;
2636− case IOCMD_FAA_ENABLE:
2637− rc = bfad_iocmd_faa_enable(bfad, iocmd);
2638− break;
2639− case IOCMD_FAA_DISABLE:
2640− rc = bfad_iocmd_faa_disable(bfad, iocmd);
2641− break;
26422595 case IOCMD_FAA_QUERY:
26432596 rc = bfad_iocmd_faa_query(bfad, iocmd);
26442597 break;
@@ -2809,9 +2762,16 @@ bfad_im_bsg_vendor_request(struct fc_bsg_job *job) · 164 unmodified lines
28092762 struct bfad_im_port_s *im_port =
28102763 (struct bfad_im_port_s *) job->shost->hostdata[0];
28112764 struct bfad_s *bfad = im_port->bfad;
2765+ struct request_queue *request_q = job->req->q;
28122766 void *payload_kbuf;
28132767 int rc = -EINVAL;
28142768
2769+ /*
2770+ * Set the BSG device request_queue size to 256 to support
2771+ * payloads larger than 512*1024K bytes.
2772+ */
2773+ blk_queue_max_segments(request_q, 256);
2774+
28152775 /* Allocate a temp buffer to hold the passed in user space command */
28162776 payload_kbuf = kzalloc(job->request_payload.payload_len, GFP_KERNEL);
28172777 if (!payload_kbuf) {
drivers/scsi/bfa/bfad_bsg.h+0−2
@@ -83,8 +83,6 @@ enum { · 82 unmodified lines
8383 IOCMD_PORT_CFG_MODE,
8484 IOCMD_FLASH_ENABLE_OPTROM,
8585 IOCMD_FLASH_DISABLE_OPTROM,
86− IOCMD_FAA_ENABLE,
87− IOCMD_FAA_DISABLE,
8886 IOCMD_FAA_QUERY,
8987 IOCMD_CEE_GET_ATTR,
9088 IOCMD_CEE_GET_STATS,
drivers/scsi/bfa/bfad_drv.h+1−1
@@ -56,7 +56,7 @@ · 55 unmodified lines
5656 #ifdef BFA_DRIVER_VERSION
5757 #define BFAD_DRIVER_VERSION BFA_DRIVER_VERSION
5858 #else
59−#define BFAD_DRIVER_VERSION "3.0.2.2"
59+#define BFAD_DRIVER_VERSION "3.0.23.0"
6060 #endif
6161
6262 #define BFAD_PROTO_NAME FCPI_NAME
drivers/scsi/bfa/bfi_ms.h+11−6
@@ -28,17 +28,15 @@ enum bfi_iocfc_h2i_msgs { · 27 unmodified lines
2828 BFI_IOCFC_H2I_CFG_REQ = 1,
2929 BFI_IOCFC_H2I_SET_INTR_REQ = 2,
3030 BFI_IOCFC_H2I_UPDATEQ_REQ = 3,
31− BFI_IOCFC_H2I_FAA_ENABLE_REQ = 4,
32− BFI_IOCFC_H2I_FAA_DISABLE_REQ = 5,
33− BFI_IOCFC_H2I_FAA_QUERY_REQ = 6,
31+ BFI_IOCFC_H2I_FAA_QUERY_REQ = 4,
32+ BFI_IOCFC_H2I_ADDR_REQ = 5,
3433 };
3534
3635 enum bfi_iocfc_i2h_msgs {
3736 BFI_IOCFC_I2H_CFG_REPLY = BFA_I2HM(1),
3837 BFI_IOCFC_I2H_UPDATEQ_RSP = BFA_I2HM(3),
39− BFI_IOCFC_I2H_FAA_ENABLE_RSP = BFA_I2HM(4),
40− BFI_IOCFC_I2H_FAA_DISABLE_RSP = BFA_I2HM(5),
41− BFI_IOCFC_I2H_FAA_QUERY_RSP = BFA_I2HM(6),
38+ BFI_IOCFC_I2H_FAA_QUERY_RSP = BFA_I2HM(4),
39+ BFI_IOCFC_I2H_ADDR_MSG = BFA_I2HM(5),
4240 };
4341
4442 struct bfi_iocfc_cfg_s {
@@ -184,6 +182,13 @@ struct bfi_faa_en_dis_s { · 139 unmodified lines
184182 struct bfi_mhdr_s mh; /* common msg header */
185183 };
186184
185+struct bfi_faa_addr_msg_s {
186+ struct bfi_mhdr_s mh; /* common msg header */
187+ u8 rsvd[4];
188+ wwn_t pwwn; /* Fabric acquired PWWN */
189+ wwn_t nwwn; /* Fabric acquired PWWN */
190+};
191+
187192 /*
188193 * BFI_IOCFC_H2I_FAA_QUERY_REQ message
189194 */
drivers/scsi/bfa/bfi_reg.h+6−0
@@ -335,11 +335,17 @@ enum { · 334 unmodified lines
335335 #define __PMM_1T_PNDB_P 0x00000002
336336 #define CT2_PMM_1T_CONTROL_REG_P1 0x00023c1c
337337 #define CT2_WGN_STATUS 0x00014990
338+#define __A2T_AHB_LOAD 0x00000800
338339 #define __WGN_READY 0x00000400
339340 #define __GLBL_PF_VF_CFG_RDY 0x00000200
341+#define CT2_NFC_CSR_CLR_REG 0x00027420
340342 #define CT2_NFC_CSR_SET_REG 0x00027424
341343 #define __HALT_NFC_CONTROLLER 0x00000002
342344 #define __NFC_CONTROLLER_HALTED 0x00001000
345+#define CT2_RSC_GPR15_REG 0x0002765c
346+#define CT2_CSI_FW_CTL_REG 0x00027080
347+#define CT2_CSI_FW_CTL_SET_REG 0x00027088
348+#define __RESET_AND_START_SCLK_LCLK_PLLS 0x00010000
343349
344350 #define CT2_CSI_MAC0_CONTROL_REG 0x000270d0
345351 #define __CSI_MAC_RESET 0x00000010
drivers/scsi/bnx2fc/bnx2fc_fcoe.c+2−2
@@ -439,13 +439,13 @@ static int bnx2fc_rcv(struct sk_buff *skb, struct net_device *dev, · 438 unmodified lines
439439 fr->fr_dev = lport;
440440
441441 bg = &bnx2fc_global;
442− spin_lock_bh(&bg->fcoe_rx_list.lock);
442+ spin_lock(&bg->fcoe_rx_list.lock);
443443
444444 __skb_queue_tail(&bg->fcoe_rx_list, skb);
445445 if (bg->fcoe_rx_list.qlen == 1)
446446 wake_up_process(bg->thread);
447447
448− spin_unlock_bh(&bg->fcoe_rx_list.lock);
448+ spin_unlock(&bg->fcoe_rx_list.lock);
449449
450450 return 0;
451451 err:
drivers/scsi/fcoe/fcoe.c+35−48
@@ -1436,7 +1436,7 @@ static int fcoe_rcv(struct sk_buff *skb, struct net_device *netdev, · 1435 unmodified lines
14361436 goto err;
14371437
14381438 fps = &per_cpu(fcoe_percpu, cpu);
1439− spin_lock_bh(&fps->fcoe_rx_list.lock);
1439+ spin_lock(&fps->fcoe_rx_list.lock);
14401440 if (unlikely(!fps->thread)) {
14411441 /*
14421442 * The targeted CPU is not ready, let's target
@@ -1447,12 +1447,12 @@ static int fcoe_rcv(struct sk_buff *skb, struct net_device *netdev, · 4 unmodified lines
14471447 "ready for incoming skb- using first online "
14481448 "CPU.\n");
14491449
1450− spin_unlock_bh(&fps->fcoe_rx_list.lock);
1450+ spin_unlock(&fps->fcoe_rx_list.lock);
14511451 cpu = cpumask_first(cpu_online_mask);
14521452 fps = &per_cpu(fcoe_percpu, cpu);
1453− spin_lock_bh(&fps->fcoe_rx_list.lock);
1453+ spin_lock(&fps->fcoe_rx_list.lock);
14541454 if (!fps->thread) {
1455− spin_unlock_bh(&fps->fcoe_rx_list.lock);
1455+ spin_unlock(&fps->fcoe_rx_list.lock);
14561456 goto err;
14571457 }
14581458 }
@@ -1463,24 +1463,17 @@ static int fcoe_rcv(struct sk_buff *skb, struct net_device *netdev, · 4 unmodified lines
14631463 * so we're free to queue skbs into it's queue.
14641464 */
14651465
1466− /* If this is a SCSI-FCP frame, and this is already executing on the
1467− * correct CPU, and the queue for this CPU is empty, then go ahead
1468− * and process the frame directly in the softirq context.
1469− * This lets us process completions without context switching from the
1470− * NET_RX softirq, to our receive processing thread, and then back to
1471− * BLOCK softirq context.
1466+ /*
1467+ * Note: We used to have a set of conditions under which we would
1468+ * call fcoe_recv_frame directly, rather than queuing to the rx list
1469+ * as it could save a few cycles, but doing so is prohibited, as
1470+ * fcoe_recv_frame has several paths that may sleep, which is forbidden
1471+ * in softirq context.
14721472 */
1473− if (fh->fh_type == FC_TYPE_FCP &&
1474− cpu == smp_processor_id() &&
1475− skb_queue_empty(&fps->fcoe_rx_list)) {
1476− spin_unlock_bh(&fps->fcoe_rx_list.lock);
1477− fcoe_recv_frame(skb);
1478− } else {
1479− __skb_queue_tail(&fps->fcoe_rx_list, skb);
1480− if (fps->fcoe_rx_list.qlen == 1)
1481− wake_up_process(fps->thread);
1482− spin_unlock_bh(&fps->fcoe_rx_list.lock);
1483− }
1473+ __skb_queue_tail(&fps->fcoe_rx_list, skb);
1474+ if (fps->thread->state == TASK_INTERRUPTIBLE)
1475+ wake_up_process(fps->thread);
1476+ spin_unlock(&fps->fcoe_rx_list.lock);
14841477
14851478 return 0;
14861479 err:
@@ -1797,23 +1790,29 @@ static int fcoe_percpu_receive_thread(void *arg) · 310 unmodified lines
17971790 {
17981791 struct fcoe_percpu_s *p = arg;
17991792 struct sk_buff *skb;
1793+ struct sk_buff_head tmp;
1794+
1795+ skb_queue_head_init(&tmp);
18001796
18011797 set_user_nice(current, -20);
18021798
18031799 while (!kthread_should_stop()) {
18041800
18051801 spin_lock_bh(&p->fcoe_rx_list.lock);
1806− while ((skb = __skb_dequeue(&p->fcoe_rx_list)) == NULL) {
1802+ skb_queue_splice_init(&p->fcoe_rx_list, &tmp);
1803+ spin_unlock_bh(&p->fcoe_rx_list.lock);
1804+
1805+ while ((skb = __skb_dequeue(&tmp)) != NULL)
1806+ fcoe_recv_frame(skb);
1807+
1808+ spin_lock_bh(&p->fcoe_rx_list.lock);
1809+ if (!skb_queue_len(&p->fcoe_rx_list)) {
18071810 set_current_state(TASK_INTERRUPTIBLE);
18081811 spin_unlock_bh(&p->fcoe_rx_list.lock);
18091812 schedule();
18101813 set_current_state(TASK_RUNNING);
1811− if (kthread_should_stop())
1812− return 0;
1813− spin_lock_bh(&p->fcoe_rx_list.lock);
1814− }
1815− spin_unlock_bh(&p->fcoe_rx_list.lock);
1816− fcoe_recv_frame(skb);
1814+ } else
1815+ spin_unlock_bh(&p->fcoe_rx_list.lock);
18171816 }
18181817 return 0;
18191818 }
@@ -2187,8 +2186,12 @@ static int fcoe_create(struct net_device *netdev, enum fip_state fip_mode) · 367 unmodified lines
21872186 /* start FIP Discovery and FLOGI */
21882187 lport->boot_time = jiffies;
21892188 fc_fabric_login(lport);
2190− if (!fcoe_link_ok(lport))
2189+ if (!fcoe_link_ok(lport)) {
2190+ rtnl_unlock();
21912191 fcoe_ctlr_link_up(&fcoe->ctlr);
2192+ mutex_unlock(&fcoe_config_mutex);
2193+ return rc;
2194+ }
21922195
21932196 out_nodev:
21942197 rtnl_unlock();
@@ -2261,31 +2264,14 @@ static int fcoe_link_ok(struct fc_lport *lport) · 66 unmodified lines
22612264 static void fcoe_percpu_clean(struct fc_lport *lport)
22622265 {
22632266 struct fcoe_percpu_s *pp;
2264− struct fcoe_rcv_info *fr;
2265− struct sk_buff_head *list;
2266− struct sk_buff *skb, *next;
2267− struct sk_buff *head;
2267+ struct sk_buff *skb;
22682268 unsigned int cpu;
22692269
22702270 for_each_possible_cpu(cpu) {
22712271 pp = &per_cpu(fcoe_percpu, cpu);
2272− spin_lock_bh(&pp->fcoe_rx_list.lock);
2273− list = &pp->fcoe_rx_list;
2274− head = list->next;
2275− for (skb = head; skb != (struct sk_buff *)list;
2276− skb = next) {
2277− next = skb->next;
2278− fr = fcoe_dev_from_skb(skb);
2279− if (fr->fr_dev == lport) {
2280− __skb_unlink(skb, list);
2281− kfree_skb(skb);
2282− }
2283− }
22842272
2285− if (!pp->thread || !cpu_online(cpu)) {
2286− spin_unlock_bh(&pp->fcoe_rx_list.lock);
2273+ if (!pp->thread || !cpu_online(cpu))
22872274 continue;
2288− }
22892275
22902276 skb = dev_alloc_skb(0);
22912277 if (!skb) {
@@ -2294,6 +2280,7 @@ static void fcoe_percpu_clean(struct fc_lport *lport) · 2 unmodified lines
22942280 }
22952281 skb->destructor = fcoe_percpu_flush_done;
22962282
2283+ spin_lock_bh(&pp->fcoe_rx_list.lock);
22972284 __skb_queue_tail(&pp->fcoe_rx_list, skb);
22982285 if (pp->fcoe_rx_list.qlen == 1)
22992286 wake_up_process(pp->thread);
drivers/scsi/fcoe/fcoe_ctlr.c+28−10
@@ -242,7 +242,7 @@ static void fcoe_ctlr_announce(struct fcoe_ctlr *fip) · 241 unmodified lines
242242 printk(KERN_INFO "libfcoe: host%d: FIP selected "
243243 "Fibre-Channel Forwarder MAC %pM\n",
244244 fip->lp->host->host_no, sel->fcf_mac);
245− memcpy(fip->dest_addr, sel->fcf_mac, ETH_ALEN);
245+ memcpy(fip->dest_addr, sel->fcoe_mac, ETH_ALEN);
246246 fip->map_dest = 0;
247247 }
248248 unlock:
@@ -824,6 +824,7 @@ static int fcoe_ctlr_parse_adv(struct fcoe_ctlr *fip, · 575 unmodified lines
824824 memcpy(fcf->fcf_mac,
825825 ((struct fip_mac_desc *)desc)->fd_mac,
826826 ETH_ALEN);
827+ memcpy(fcf->fcoe_mac, fcf->fcf_mac, ETH_ALEN);
827828 if (!is_valid_ether_addr(fcf->fcf_mac)) {
828829 LIBFCOE_FIP_DBG(fip,
829830 "Invalid MAC addr %pM in FIP adv\n",
@@ -1013,6 +1014,7 @@ static void fcoe_ctlr_recv_els(struct fcoe_ctlr *fip, struct sk_buff *skb) · 183 unmodified lines
10131014 struct fip_desc *desc;
10141015 struct fip_encaps *els;
10151016 struct fcoe_dev_stats *stats;
1017+ struct fcoe_fcf *sel;
10161018 enum fip_desc_type els_dtype = 0;
10171019 u8 els_op;
10181020 u8 sub;
@@ -1040,7 +1042,8 @@ static void fcoe_ctlr_recv_els(struct fcoe_ctlr *fip, struct sk_buff *skb) · 21 unmodified lines
10401042 goto drop;
10411043 /* Drop ELS if there are duplicate critical descriptors */
10421044 if (desc->fip_dtype < 32) {
1043− if (desc_mask & 1U << desc->fip_dtype) {
1045+ if ((desc->fip_dtype != FIP_DT_MAC) &&
1046+ (desc_mask & 1U << desc->fip_dtype)) {
10441047 LIBFCOE_FIP_DBG(fip, "Duplicate Critical "
10451048 "Descriptors in FIP ELS\n");
10461049 goto drop;
@@ -1049,17 +1052,32 @@ static void fcoe_ctlr_recv_els(struct fcoe_ctlr *fip, struct sk_buff *skb) · 2 unmodified lines
10491052 }
10501053 switch (desc->fip_dtype) {
10511054 case FIP_DT_MAC:
1055+ sel = fip->sel_fcf;
10521056 if (desc_cnt == 1) {
10531057 LIBFCOE_FIP_DBG(fip, "FIP descriptors "
10541058 "received out of order\n");
10551059 goto drop;
10561060 }
1061+ /*
1062+ * Some switch implementations send two MAC descriptors,
1063+ * with first MAC(granted_mac) being the FPMA, and the
1064+ * second one(fcoe_mac) is used as destination address
1065+ * for sending/receiving FCoE packets. FIP traffic is
1066+ * sent using fip_mac. For regular switches, both
1067+ * fip_mac and fcoe_mac would be the same.
1068+ */
1069+ if (desc_cnt == 2)
1070+ memcpy(granted_mac,
1071+ ((struct fip_mac_desc *)desc)->fd_mac,
1072+ ETH_ALEN);
10571073
10581074 if (dlen != sizeof(struct fip_mac_desc))
10591075 goto len_err;
1060− memcpy(granted_mac,
1061− ((struct fip_mac_desc *)desc)->fd_mac,
1062− ETH_ALEN);
1076+
1077+ if ((desc_cnt == 3) && (sel))
1078+ memcpy(sel->fcoe_mac,
1079+ ((struct fip_mac_desc *)desc)->fd_mac,
1080+ ETH_ALEN);
10631081 break;
10641082 case FIP_DT_FLOGI:
10651083 case FIP_DT_FDISC:
@@ -1273,11 +1291,6 @@ static void fcoe_ctlr_recv_clr_vlink(struct fcoe_ctlr *fip, · 207 unmodified lines
12731291 * No Vx_Port description. Clear all NPIV ports,
12741292 * followed by physical port
12751293 */
1276− mutex_lock(&lport->lp_mutex);
1277− list_for_each_entry(vn_port, &lport->vports, list)
1278− fc_lport_reset(vn_port);
1279− mutex_unlock(&lport->lp_mutex);
1280−
12811294 mutex_lock(&fip->ctlr_mutex);
12821295 per_cpu_ptr(lport->dev_stats,
12831296 get_cpu())->VLinkFailureCount++;
@@ -1285,6 +1298,11 @@ static void fcoe_ctlr_recv_clr_vlink(struct fcoe_ctlr *fip, · 1 unmodified line
12851298 fcoe_ctlr_reset(fip);
12861299 mutex_unlock(&fip->ctlr_mutex);
12871300
1301+ mutex_lock(&lport->lp_mutex);
1302+ list_for_each_entry(vn_port, &lport->vports, list)
1303+ fc_lport_reset(vn_port);
1304+ mutex_unlock(&lport->lp_mutex);
1305+
12881306 fc_lport_reset(fip->lp);
12891307 fcoe_ctlr_solicit(fip, NULL);
12901308 } else {
drivers/scsi/ipr.c+46−27
@@ -104,7 +104,9 @@ static DEFINE_SPINLOCK(ipr_driver_lock); · 103 unmodified lines
104104 static const struct ipr_chip_cfg_t ipr_chip_cfg[] = {
105105 { /* Gemstone, Citrine, Obsidian, and Obsidian-E */
106106 .mailbox = 0x0042C,
107+ .max_cmds = 100,
107108 .cache_line_size = 0x20,
109+ .clear_isr = 1,
108110 {
109111 .set_interrupt_mask_reg = 0x0022C,
110112 .clr_interrupt_mask_reg = 0x00230,
@@ -126,7 +128,9 @@ static const struct ipr_chip_cfg_t ipr_chip_cfg[] = { · 15 unmodified lines
126128 },
127129 { /* Snipe and Scamp */
128130 .mailbox = 0x0052C,
131+ .max_cmds = 100,
129132 .cache_line_size = 0x20,
133+ .clear_isr = 1,
130134 {
131135 .set_interrupt_mask_reg = 0x00288,
132136 .clr_interrupt_mask_reg = 0x0028C,
@@ -148,7 +152,9 @@ static const struct ipr_chip_cfg_t ipr_chip_cfg[] = { · 15 unmodified lines
148152 },
149153 { /* CRoC */
150154 .mailbox = 0x00044,
155+ .max_cmds = 1000,
151156 .cache_line_size = 0x20,
157+ .clear_isr = 0,
152158 {
153159 .set_interrupt_mask_reg = 0x00010,
154160 .clr_interrupt_mask_reg = 0x00018,
@@ -847,8 +853,6 @@ static void ipr_do_req(struct ipr_cmnd *ipr_cmd, · 692 unmodified lines
847853
848854 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, 0);
849855
850− mb();
851−
852856 ipr_send_command(ipr_cmd);
853857 }
854858
@@ -982,8 +986,6 @@ static void ipr_send_hcam(struct ipr_ioa_cfg *ioa_cfg, u8 type, · 127 unmodified lines
982986
983987 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_IOA_RES_ADDR);
984988
985− mb();
986−
987989 ipr_send_command(ipr_cmd);
988990 } else {
989991 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
@@ -4339,8 +4341,7 @@ static struct ipr_resource_entry *ipr_find_starget(struct scsi_target *starget) · 3349 unmodified lines
43394341
43404342 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
43414343 if ((res->bus == starget->channel) &&
4342− (res->target == starget->id) &&
4343− (res->lun == 0)) {
4344+ (res->target == starget->id)) {
43444345 return res;
43454346 }
43464347 }
@@ -4414,12 +4415,14 @@ static void ipr_target_destroy(struct scsi_target *starget) · 67 unmodified lines
44144415 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
44154416
44164417 if (ioa_cfg->sis64) {
4417− if (starget->channel == IPR_ARRAY_VIRTUAL_BUS)
4418− clear_bit(starget->id, ioa_cfg->array_ids);
4419− else if (starget->channel == IPR_VSET_VIRTUAL_BUS)
4420− clear_bit(starget->id, ioa_cfg->vset_ids);
4421− else if (starget->channel == 0)
4422− clear_bit(starget->id, ioa_cfg->target_ids);
4418+ if (!ipr_find_starget(starget)) {
4419+ if (starget->channel == IPR_ARRAY_VIRTUAL_BUS)
4420+ clear_bit(starget->id, ioa_cfg->array_ids);
4421+ else if (starget->channel == IPR_VSET_VIRTUAL_BUS)
4422+ clear_bit(starget->id, ioa_cfg->vset_ids);
4423+ else if (starget->channel == 0)
4424+ clear_bit(starget->id, ioa_cfg->target_ids);
4425+ }
44234426 }
44244427
44254428 if (sata_port) {
@@ -5048,12 +5051,14 @@ static irqreturn_t ipr_handle_other_interrupt(struct ipr_ioa_cfg *ioa_cfg, · 622 unmodified lines
50485051 del_timer(&ioa_cfg->reset_cmd->timer);
50495052 ipr_reset_ioa_job(ioa_cfg->reset_cmd);
50505053 } else if ((int_reg & IPR_PCII_HRRQ_UPDATED) == int_reg) {
5051− if (ipr_debug && printk_ratelimit())
5052− dev_err(&ioa_cfg->pdev->dev,
5053− "Spurious interrupt detected. 0x%08X\n", int_reg);
5054− writel(IPR_PCII_HRRQ_UPDATED, ioa_cfg->regs.clr_interrupt_reg32);
5055− int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
5056− return IRQ_NONE;
5054+ if (ioa_cfg->clear_isr) {
5055+ if (ipr_debug && printk_ratelimit())
5056+ dev_err(&ioa_cfg->pdev->dev,
5057+ "Spurious interrupt detected. 0x%08X\n", int_reg);
5058+ writel(IPR_PCII_HRRQ_UPDATED, ioa_cfg->regs.clr_interrupt_reg32);
5059+ int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
5060+ return IRQ_NONE;
5061+ }
50575062 } else {
50585063 if (int_reg & IPR_PCII_IOA_UNIT_CHECKED)
50595064 ioa_cfg->ioa_unit_checked = 1;
@@ -5153,6 +5158,9 @@ static irqreturn_t ipr_isr(int irq, void *devp) · 93 unmodified lines
51535158 }
51545159 }
51555160
5161+ if (ipr_cmd && !ioa_cfg->clear_isr)
5162+ break;
5163+
51565164 if (ipr_cmd != NULL) {
51575165 /* Clear the PCI interrupt */
51585166 num_hrrq = 0;
@@ -5854,14 +5862,12 @@ static int ipr_queuecommand_lck(struct scsi_cmnd *scsi_cmd, · 695 unmodified lines
58545862 rc = ipr_build_ioadl(ioa_cfg, ipr_cmd);
58555863 }
58565864
5857− if (likely(rc == 0)) {
5858− mb();
5859− ipr_send_command(ipr_cmd);
5860− } else {
5861− list_move_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5862− return SCSI_MLQUEUE_HOST_BUSY;
5865+ if (unlikely(rc != 0)) {
5866+ list_move_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5867+ return SCSI_MLQUEUE_HOST_BUSY;
58635868 }
58645869
5870+ ipr_send_command(ipr_cmd);
58655871 return 0;
58665872 }
58675873
@@ -6239,8 +6245,6 @@ static unsigned int ipr_qc_issue(struct ata_queued_cmd *qc) · 371 unmodified lines
62396245 return AC_ERR_INVALID;
62406246 }
62416247
6242− mb();
6243−
62446248 ipr_send_command(ipr_cmd);
62456249
62466250 return 0;
@@ -8277,6 +8281,10 @@ static void ipr_free_cmd_blks(struct ipr_ioa_cfg *ioa_cfg) · 2030 unmodified lines
82778281 if (ioa_cfg->ipr_cmd_pool)
82788282 pci_pool_destroy (ioa_cfg->ipr_cmd_pool);
82798283
8284+ kfree(ioa_cfg->ipr_cmnd_list);
8285+ kfree(ioa_cfg->ipr_cmnd_list_dma);
8286+ ioa_cfg->ipr_cmnd_list = NULL;
8287+ ioa_cfg->ipr_cmnd_list_dma = NULL;
82808288 ioa_cfg->ipr_cmd_pool = NULL;
82818289 }
82828290
@@ -8352,11 +8360,19 @@ static int __devinit ipr_alloc_cmd_blks(struct ipr_ioa_cfg *ioa_cfg) · 69 unmodified lines
83528360 int i;
83538361
83548362 ioa_cfg->ipr_cmd_pool = pci_pool_create (IPR_NAME, ioa_cfg->pdev,
8355− sizeof(struct ipr_cmnd), 16, 0);
8363+ sizeof(struct ipr_cmnd), 512, 0);
83568364
83578365 if (!ioa_cfg->ipr_cmd_pool)
83588366 return -ENOMEM;
83598367
8368+ ioa_cfg->ipr_cmnd_list = kcalloc(IPR_NUM_CMD_BLKS, sizeof(struct ipr_cmnd *), GFP_KERNEL);
8369+ ioa_cfg->ipr_cmnd_list_dma = kcalloc(IPR_NUM_CMD_BLKS, sizeof(dma_addr_t), GFP_KERNEL);
8370+
8371+ if (!ioa_cfg->ipr_cmnd_list || !ioa_cfg->ipr_cmnd_list_dma) {
8372+ ipr_free_cmd_blks(ioa_cfg);
8373+ return -ENOMEM;
8374+ }
8375+
83608376 for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
83618377 ipr_cmd = pci_pool_alloc (ioa_cfg->ipr_cmd_pool, GFP_KERNEL, &dma_addr);
83628378
@@ -8584,6 +8600,7 @@ static void __devinit ipr_init_ioa_cfg(struct ipr_ioa_cfg *ioa_cfg, · 221 unmodified lines
85848600 host->max_channel = IPR_MAX_BUS_TO_SCAN;
85858601 host->unique_id = host->host_no;
85868602 host->max_cmd_len = IPR_MAX_CDB_LEN;
8603+ host->can_queue = ioa_cfg->max_cmds;
85878604 pci_set_drvdata(pdev, ioa_cfg);
85888605
85898606 p = &ioa_cfg->chip_cfg->regs;
@@ -8768,6 +8785,8 @@ static int __devinit ipr_probe_ioa(struct pci_dev *pdev, · 178 unmodified lines
87688785 /* set SIS 32 or SIS 64 */
87698786 ioa_cfg->sis64 = ioa_cfg->ipr_chip->sis_type == IPR_SIS64 ? 1 : 0;
87708787 ioa_cfg->chip_cfg = ioa_cfg->ipr_chip->cfg;
8788+ ioa_cfg->clear_isr = ioa_cfg->chip_cfg->clear_isr;
8789+ ioa_cfg->max_cmds = ioa_cfg->chip_cfg->max_cmds;
87718790
87728791 if (ipr_transop_timeout)
87738792 ioa_cfg->transop_timeout = ipr_transop_timeout;
drivers/scsi/ipr.h+10−6
@@ -38,8 +38,8 @@ · 37 unmodified lines
3838 /*
3939 * Literals
4040 */
41−#define IPR_DRIVER_VERSION "2.5.2"
42−#define IPR_DRIVER_DATE "(April 27, 2011)"
41+#define IPR_DRIVER_VERSION "2.5.3"
42+#define IPR_DRIVER_DATE "(March 10, 2012)"
4343
4444 /*
4545 * IPR_MAX_CMD_PER_LUN: This defines the maximum number of outstanding
@@ -53,7 +53,7 @@ · 7 unmodified lines
5353 * IPR_NUM_BASE_CMD_BLKS: This defines the maximum number of
5454 * ops the mid-layer can send to the adapter.
5555 */
56−#define IPR_NUM_BASE_CMD_BLKS 100
56+#define IPR_NUM_BASE_CMD_BLKS (ioa_cfg->max_cmds)
5757
5858 #define PCI_DEVICE_ID_IBM_OBSIDIAN_E 0x0339
5959
@@ -153,7 +153,7 @@ · 93 unmodified lines
153153 #define IPR_NUM_INTERNAL_CMD_BLKS (IPR_NUM_HCAMS + \
154154 ((IPR_NUM_RESET_RELOAD_RETRIES + 1) * 2) + 4)
155155
156−#define IPR_MAX_COMMANDS IPR_NUM_BASE_CMD_BLKS
156+#define IPR_MAX_COMMANDS 100
157157 #define IPR_NUM_CMD_BLKS (IPR_NUM_BASE_CMD_BLKS + \
158158 IPR_NUM_INTERNAL_CMD_BLKS)
159159
@@ -1305,7 +1305,9 @@ struct ipr_interrupts { · 1145 unmodified lines
13051305
13061306 struct ipr_chip_cfg_t {
13071307 u32 mailbox;
1308+ u16 max_cmds;
13081309 u8 cache_line_size;
1310+ u8 clear_isr;
13091311 struct ipr_interrupt_offsets regs;
13101312 };
13111313
@@ -1388,6 +1390,7 @@ struct ipr_ioa_cfg { · 76 unmodified lines
13881390 u8 sis64:1;
13891391 u8 dump_timeout:1;
13901392 u8 cfg_locked:1;
1393+ u8 clear_isr:1;
13911394
13921395 u8 revid;
13931396
@@ -1501,8 +1504,9 @@ struct ipr_ioa_cfg { · 107 unmodified lines
15011504 struct ata_host ata_host;
15021505 char ipr_cmd_label[8];
15031506 #define IPR_CMD_LABEL "ipr_cmd"
1504− struct ipr_cmnd *ipr_cmnd_list[IPR_NUM_CMD_BLKS];
1505− dma_addr_t ipr_cmnd_list_dma[IPR_NUM_CMD_BLKS];
1507+ u32 max_cmds;
1508+ struct ipr_cmnd **ipr_cmnd_list;
1509+ dma_addr_t *ipr_cmnd_list_dma;
15061510 }; /* struct ipr_ioa_cfg */
15071511
15081512 struct ipr_cmnd {
drivers/scsi/libfc/fc_exch.c+12−2
@@ -2263,7 +2263,18 @@ struct fc_exch_mgr *fc_exch_mgr_alloc(struct fc_lport *lport, · 2262 unmodified lines
22632263 mp->class = class;
22642264 /* adjust em exch xid range for offload */
22652265 mp->min_xid = min_xid;
2266− mp->max_xid = max_xid;
2266+
2267+ /* reduce range so per cpu pool fits into PCPU_MIN_UNIT_SIZE pool */
2268+ pool_exch_range = (PCPU_MIN_UNIT_SIZE - sizeof(*pool)) /
2269+ sizeof(struct fc_exch *);
2270+ if ((max_xid - min_xid + 1) / (fc_cpu_mask + 1) > pool_exch_range) {
2271+ mp->max_xid = pool_exch_range * (fc_cpu_mask + 1) +
2272+ min_xid - 1;
2273+ } else {
2274+ mp->max_xid = max_xid;
2275+ pool_exch_range = (mp->max_xid - mp->min_xid + 1) /
2276+ (fc_cpu_mask + 1);
2277+ }
22672278
22682279 mp->ep_pool = mempool_create_slab_pool(2, fc_em_cachep);
22692280 if (!mp->ep_pool)
@@ -2274,7 +2285,6 @@ struct fc_exch_mgr *fc_exch_mgr_alloc(struct fc_lport *lport, · 4 unmodified lines
22742285 * divided across all cpus. The exch pointers array memory is
22752286 * allocated for exch range per pool.
22762287 */
2277− pool_exch_range = (mp->max_xid - mp->min_xid + 1) / (fc_cpu_mask + 1);
22782288 mp->pool_max_index = pool_exch_range - 1;
22792289
22802290 /*
drivers/scsi/libfc/fc_lport.c+9−1
@@ -1743,8 +1743,16 @@ void fc_lport_flogi_resp(struct fc_seq *sp, struct fc_frame *fp, · 1742 unmodified lines
17431743 mfs = ntohs(flp->fl_csp.sp_bb_data) &
17441744 FC_SP_BB_DATA_MASK;
17451745 if (mfs >= FC_SP_MIN_MAX_PAYLOAD &&
1746− mfs < lport->mfs)
1746+ mfs <= lport->mfs) {
17471747 lport->mfs = mfs;
1748+ fc_host_maxframe_size(lport->host) = mfs;
1749+ } else {
1750+ FC_LPORT_DBG(lport, "FLOGI bad mfs:%hu response, "
1751+ "lport->mfs:%hu\n", mfs, lport->mfs);
1752+ fc_lport_error(lport, fp);
1753+ goto err;
1754+ }
1755+
17481756 csp_flags = ntohs(flp->fl_csp.sp_features);
17491757 r_a_tov = ntohl(flp->fl_csp.sp_r_a_tov);
17501758 e_d_tov = ntohl(flp->fl_csp.sp_e_d_tov);
drivers/scsi/lpfc/Makefile+3−1
@@ -1,7 +1,7 @@
11 #/*******************************************************************
22 # * This file is part of the Emulex Linux Device Driver for *
33 # * Fibre Channel Host Bus Adapters. *
4−# * Copyright (C) 2004-2011 Emulex. All rights reserved. *
4+# * Copyright (C) 2004-2012 Emulex. All rights reserved. *
55 # * EMULEX and SLI are trademarks of Emulex. *
66 # * www.emulex.com *
77 # * *
@@ -22,6 +22,8 @@ · 14 unmodified lines
2222 ccflags-$(GCOV) := -fprofile-arcs -ftest-coverage
2323 ccflags-$(GCOV) += -O0
2424
25+ccflags-y += -Werror
26+
2527 obj-$(CONFIG_SCSI_LPFC) := lpfc.o
2628
2729 lpfc-objs := lpfc_mem.o lpfc_sli.o lpfc_ct.o lpfc_els.o lpfc_hbadisc.o \
drivers/scsi/lpfc/lpfc.h+7−1
@@ -1,7 +1,7 @@
11 /*******************************************************************
22 * This file is part of the Emulex Linux Device Driver for *
33 * Fibre Channel Host Bus Adapters. *
4− * Copyright (C) 2004-2011 Emulex. All rights reserved. *
4+ * Copyright (C) 2004-2012 Emulex. All rights reserved. *
55 * EMULEX and SLI are trademarks of Emulex. *
66 * www.emulex.com *
77 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
@@ -840,6 +840,8 @@ struct lpfc_hba { · 832 unmodified lines
840840 struct dentry *debug_dumpData; /* BlockGuard BPL */
841841 struct dentry *debug_dumpDif; /* BlockGuard BPL */
842842 struct dentry *debug_InjErrLBA; /* LBA to inject errors at */
843+ struct dentry *debug_InjErrNPortID; /* NPortID to inject errors at */
844+ struct dentry *debug_InjErrWWPN; /* WWPN to inject errors at */
843845 struct dentry *debug_writeGuard; /* inject write guard_tag errors */
844846 struct dentry *debug_writeApp; /* inject write app_tag errors */
845847 struct dentry *debug_writeRef; /* inject write ref_tag errors */
@@ -854,6 +856,8 @@ struct lpfc_hba { · 8 unmodified lines
854856 uint32_t lpfc_injerr_rgrd_cnt;
855857 uint32_t lpfc_injerr_rapp_cnt;
856858 uint32_t lpfc_injerr_rref_cnt;
859+ uint32_t lpfc_injerr_nportid;
860+ struct lpfc_name lpfc_injerr_wwpn;
857861 sector_t lpfc_injerr_lba;
858862 #define LPFC_INJERR_LBA_OFF (sector_t)(-1)
859863
@@ -908,6 +912,8 @@ struct lpfc_hba { · 48 unmodified lines
908912 atomic_t fast_event_count;
909913 uint32_t fcoe_eventtag;
910914 uint32_t fcoe_eventtag_at_fcf_scan;
915+ uint32_t fcoe_cvl_eventtag;
916+ uint32_t fcoe_cvl_eventtag_attn;
911917 struct lpfc_fcf fcf;
912918 uint8_t fc_map[3];
913919 uint8_t valid_vlan;
drivers/scsi/lpfc/lpfc_attr.c+2−2
@@ -1,7 +1,7 @@
11 /*******************************************************************
22 * This file is part of the Emulex Linux Device Driver for *
33 * Fibre Channel Host Bus Adapters. *
4− * Copyright (C) 2004-2011 Emulex. All rights reserved. *
4+ * Copyright (C) 2004-2012 Emulex. All rights reserved. *
55 * EMULEX and SLI are trademarks of Emulex. *
66 * www.emulex.com *
77 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
@@ -2575,7 +2575,7 @@ LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff, · 2567 unmodified lines
25752575 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
25762576 # objects that have been registered with the nameserver after login.
25772577 */
2578−LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2578+LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
25792579 "Deregister nameserver objects before LOGO");
25802580
25812581 /*
drivers/scsi/lpfc/lpfc_debugfs.c+65−15
@@ -1,7 +1,7 @@
11 /*******************************************************************
22 * This file is part of the Emulex Linux Device Driver for *
33 * Fibre Channel Host Bus Adapters. *
4− * Copyright (C) 2007-2011 Emulex. All rights reserved. *
4+ * Copyright (C) 2007-2012 Emulex. All rights reserved. *
55 * EMULEX and SLI are trademarks of Emulex. *
66 * www.emulex.com *
77 * *
@@ -1010,25 +1010,35 @@ lpfc_debugfs_dif_err_read(struct file *file, char __user *buf, · 1002 unmodified lines
10101010 {
10111011 struct dentry *dent = file->f_dentry;
10121012 struct lpfc_hba *phba = file->private_data;
1013− char cbuf[16];
1013+ char cbuf[32];
1014+ uint64_t tmp = 0;
10141015 int cnt = 0;
10151016
10161017 if (dent == phba->debug_writeGuard)
1017− cnt = snprintf(cbuf, 16, "%u\n", phba->lpfc_injerr_wgrd_cnt);
1018+ cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wgrd_cnt);
10181019 else if (dent == phba->debug_writeApp)
1019− cnt = snprintf(cbuf, 16, "%u\n", phba->lpfc_injerr_wapp_cnt);
1020+ cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wapp_cnt);
10201021 else if (dent == phba->debug_writeRef)
1021− cnt = snprintf(cbuf, 16, "%u\n", phba->lpfc_injerr_wref_cnt);
1022+ cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wref_cnt);
10221023 else if (dent == phba->debug_readGuard)
1023− cnt = snprintf(cbuf, 16, "%u\n", phba->lpfc_injerr_rgrd_cnt);
1024+ cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rgrd_cnt);
10241025 else if (dent == phba->debug_readApp)
1025− cnt = snprintf(cbuf, 16, "%u\n", phba->lpfc_injerr_rapp_cnt);
1026+ cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rapp_cnt);
10261027 else if (dent == phba->debug_readRef)
1027− cnt = snprintf(cbuf, 16, "%u\n", phba->lpfc_injerr_rref_cnt);
1028− else if (dent == phba->debug_InjErrLBA)
1029− cnt = snprintf(cbuf, 16, "0x%lx\n",
1030− (unsigned long) phba->lpfc_injerr_lba);
1031− else
1028+ cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rref_cnt);
1029+ else if (dent == phba->debug_InjErrNPortID)
1030+ cnt = snprintf(cbuf, 32, "0x%06x\n", phba->lpfc_injerr_nportid);
1031+ else if (dent == phba->debug_InjErrWWPN) {
1032+ memcpy(&tmp, &phba->lpfc_injerr_wwpn, sizeof(struct lpfc_name));
1033+ tmp = cpu_to_be64(tmp);
1034+ cnt = snprintf(cbuf, 32, "0x%016llx\n", tmp);
1035+ } else if (dent == phba->debug_InjErrLBA) {
1036+ if (phba->lpfc_injerr_lba == (sector_t)(-1))
1037+ cnt = snprintf(cbuf, 32, "off\n");
1038+ else
1039+ cnt = snprintf(cbuf, 32, "0x%llx\n",
1040+ (uint64_t) phba->lpfc_injerr_lba);
1041+ } else
10321042 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10331043 "0547 Unknown debugfs error injection entry\n");
10341044
@@ -1042,7 +1052,7 @@ lpfc_debugfs_dif_err_write(struct file *file, const char __user *buf, · 7 unmodified lines
10421052 struct dentry *dent = file->f_dentry;
10431053 struct lpfc_hba *phba = file->private_data;
10441054 char dstbuf[32];
1045− unsigned long tmp;
1055+ uint64_t tmp = 0;
10461056 int size;
10471057
10481058 memset(dstbuf, 0, 32);
@@ -1050,7 +1060,12 @@ lpfc_debugfs_dif_err_write(struct file *file, const char __user *buf, · 1 unmodified line
10501060 if (copy_from_user(dstbuf, buf, size))
10511061 return 0;
10521062
1053− if (strict_strtoul(dstbuf, 0, &tmp))
1063+ if (dent == phba->debug_InjErrLBA) {
1064+ if ((buf[0] == 'o') && (buf[1] == 'f') && (buf[2] == 'f'))
1065+ tmp = (uint64_t)(-1);
1066+ }
1067+
1068+ if ((tmp == 0) && (kstrtoull(dstbuf, 0, &tmp)))
10541069 return 0;
10551070
10561071 if (dent == phba->debug_writeGuard)
@@ -1067,7 +1082,12 @@ lpfc_debugfs_dif_err_write(struct file *file, const char __user *buf, · 10 unmodified lines
10671082 phba->lpfc_injerr_rref_cnt = (uint32_t)tmp;
10681083 else if (dent == phba->debug_InjErrLBA)
10691084 phba->lpfc_injerr_lba = (sector_t)tmp;
1070− else
1085+ else if (dent == phba->debug_InjErrNPortID)
1086+ phba->lpfc_injerr_nportid = (uint32_t)(tmp & Mask_DID);
1087+ else if (dent == phba->debug_InjErrWWPN) {
1088+ tmp = cpu_to_be64(tmp);
1089+ memcpy(&phba->lpfc_injerr_wwpn, &tmp, sizeof(struct lpfc_name));
1090+ } else
10711091 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10721092 "0548 Unknown debugfs error injection entry\n");
10731093
@@ -3949,6 +3969,28 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport) · 2875 unmodified lines
39493969 }
39503970 phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
39513971
3972+ snprintf(name, sizeof(name), "InjErrNPortID");
3973+ phba->debug_InjErrNPortID =
3974+ debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3975+ phba->hba_debugfs_root,
3976+ phba, &lpfc_debugfs_op_dif_err);
3977+ if (!phba->debug_InjErrNPortID) {
3978+ lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3979+ "0809 Cannot create debugfs InjErrNPortID\n");
3980+ goto debug_failed;
3981+ }
3982+
3983+ snprintf(name, sizeof(name), "InjErrWWPN");
3984+ phba->debug_InjErrWWPN =
3985+ debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3986+ phba->hba_debugfs_root,
3987+ phba, &lpfc_debugfs_op_dif_err);
3988+ if (!phba->debug_InjErrWWPN) {
3989+ lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3990+ "0810 Cannot create debugfs InjErrWWPN\n");
3991+ goto debug_failed;
3992+ }
3993+
39523994 snprintf(name, sizeof(name), "writeGuardInjErr");
39533995 phba->debug_writeGuard =
39543996 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
@@ -4321,6 +4363,14 @@ lpfc_debugfs_terminate(struct lpfc_vport *vport) · 366 unmodified lines
43214363 debugfs_remove(phba->debug_InjErrLBA); /* InjErrLBA */
43224364 phba->debug_InjErrLBA = NULL;
43234365 }
4366+ if (phba->debug_InjErrNPortID) { /* InjErrNPortID */
4367+ debugfs_remove(phba->debug_InjErrNPortID);
4368+ phba->debug_InjErrNPortID = NULL;
4369+ }
4370+ if (phba->debug_InjErrWWPN) {
4371+ debugfs_remove(phba->debug_InjErrWWPN); /* InjErrWWPN */
4372+ phba->debug_InjErrWWPN = NULL;
4373+ }
43244374 if (phba->debug_writeGuard) {
43254375 debugfs_remove(phba->debug_writeGuard); /* writeGuard */
43264376 phba->debug_writeGuard = NULL;
drivers/scsi/lpfc/lpfc_els.c+13−4
@@ -1,7 +1,7 @@
11 /*******************************************************************
22 * This file is part of the Emulex Linux Device Driver for *
33 * Fibre Channel Host Bus Adapters. *
4− * Copyright (C) 2004-2011 Emulex. All rights reserved. *
4+ * Copyright (C) 2004-2012 Emulex. All rights reserved. *
55 * EMULEX and SLI are trademarks of Emulex. *
66 * www.emulex.com *
77 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
@@ -925,9 +925,17 @@ lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, · 917 unmodified lines
925925 * due to new FCF discovery
926926 */
927927 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
928− (phba->fcf.fcf_flag & FCF_DISCOVERY) &&
929− !((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
930− (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED))) {
928+ (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
929+ if (phba->link_state < LPFC_LINK_UP)
930+ goto stop_rr_fcf_flogi;
931+ if ((phba->fcoe_cvl_eventtag_attn ==
932+ phba->fcoe_cvl_eventtag) &&
933+ (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
934+ (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED))
935+ goto stop_rr_fcf_flogi;
936+ else
937+ phba->fcoe_cvl_eventtag_attn =
938+ phba->fcoe_cvl_eventtag;
931939 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
932940 "2611 FLOGI failed on FCF (x%x), "
933941 "status:x%x/x%x, tmo:x%x, perform "
@@ -943,6 +951,7 @@ lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, · 9 unmodified lines
943951 goto out;
944952 }
945953
954+stop_rr_fcf_flogi:
946955 /* FLOGI failure */
947956 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
948957 "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n",
drivers/scsi/lpfc/lpfc_hbadisc.c+15−9
@@ -1,7 +1,7 @@
11 /*******************************************************************
22 * This file is part of the Emulex Linux Device Driver for *
33 * Fibre Channel Host Bus Adapters. *
4− * Copyright (C) 2004-2011 Emulex. All rights reserved. *
4+ * Copyright (C) 2004-2012 Emulex. All rights reserved. *
55 * EMULEX and SLI are trademarks of Emulex. *
66 * www.emulex.com *
77 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
@@ -2843,7 +2843,14 @@ lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) · 2835 unmodified lines
28432843 struct lpfc_vport *vport = mboxq->vport;
28442844 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
28452845
2846− if (mboxq->u.mb.mbxStatus) {
2846+ /*
2847+ * VFI not supported for interface type 0, so ignore any mailbox
2848+ * error (except VFI in use) and continue with the discovery.
2849+ */
2850+ if (mboxq->u.mb.mbxStatus &&
2851+ (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
2852+ LPFC_SLI_INTF_IF_TYPE_0) &&
2853+ mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
28472854 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
28482855 "2018 REG_VFI mbxStatus error x%x "
28492856 "HBA state x%x\n",
@@ -5673,14 +5680,13 @@ lpfc_fcf_inuse(struct lpfc_hba *phba) · 2823 unmodified lines
56735680 ret = 1;
56745681 spin_unlock_irq(shost->host_lock);
56755682 goto out;
5676− } else {
5683+ } else if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
5684+ ret = 1;
56775685 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
5678− "2624 RPI %x DID %x flg %x still "
5679− "logged in\n",
5680− ndlp->nlp_rpi, ndlp->nlp_DID,
5681− ndlp->nlp_flag);
5682− if (ndlp->nlp_flag & NLP_RPI_REGISTERED)
5683− ret = 1;
5686+ "2624 RPI %x DID %x flag %x "
5687+ "still logged in\n",
5688+ ndlp->nlp_rpi, ndlp->nlp_DID,
5689+ ndlp->nlp_flag);
56845690 }
56855691 }
56865692 spin_unlock_irq(shost->host_lock);
drivers/scsi/lpfc/lpfc_hw4.h+7−1
@@ -1,7 +1,7 @@
11 /*******************************************************************
22 * This file is part of the Emulex Linux Device Driver for *
33 * Fibre Channel Host Bus Adapters. *
4− * Copyright (C) 2009 Emulex. All rights reserved. *
4+ * Copyright (C) 2009-2012 Emulex. All rights reserved. *
55 * EMULEX and SLI are trademarks of Emulex. *
66 * www.emulex.com *
77 * *
@@ -338,6 +338,12 @@ struct lpfc_cqe { · 330 unmodified lines
338338 #define CQE_CODE_XRI_ABORTED 0x5
339339 #define CQE_CODE_RECEIVE_V1 0x9
340340
341+/*
342+ * Define mask value for xri_aborted and wcqe completed CQE extended status.
343+ * Currently, extended status is limited to 9 bits (0x0 -> 0x103) .
344+ */
345+#define WCQE_PARAM_MASK 0x1FF;
346+
341347 /* completion queue entry for wqe completions */
342348 struct lpfc_wcqe_complete {
343349 uint32_t word0;
drivers/scsi/lpfc/lpfc_init.c+22−19
@@ -1,7 +1,7 @@
11 /*******************************************************************
22 * This file is part of the Emulex Linux Device Driver for *
33 * Fibre Channel Host Bus Adapters. *
4− * Copyright (C) 2004-2011 Emulex. All rights reserved. *
4+ * Copyright (C) 2004-2012 Emulex. All rights reserved. *
55 * EMULEX and SLI are trademarks of Emulex. *
66 * www.emulex.com *
77 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
@@ -2704,16 +2704,14 @@ lpfc_offline_prep(struct lpfc_hba * phba) · 2696 unmodified lines
27042704 }
27052705 spin_lock_irq(shost->host_lock);
27062706 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2707−
2707+ spin_unlock_irq(shost->host_lock);
27082708 /*
27092709 * Whenever an SLI4 port goes offline, free the
2710− * RPI. A new RPI when the adapter port comes
2711− * back online.
2710+ * RPI. Get a new RPI when the adapter port
2711+ * comes back online.
27122712 */
27132713 if (phba->sli_rev == LPFC_SLI_REV4)
27142714 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
2715−
2716− spin_unlock_irq(shost->host_lock);
27172715 lpfc_unreg_rpi(vports[i], ndlp);
27182716 }
27192717 }
@@ -2786,9 +2784,13 @@ lpfc_scsi_buf_update(struct lpfc_hba *phba) · 66 unmodified lines
27862784
27872785 spin_lock_irq(&phba->hbalock);
27882786 spin_lock(&phba->scsi_buf_list_lock);
2789− list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list)
2787+ list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
27902788 sb->cur_iocbq.sli4_xritag =
27912789 phba->sli4_hba.xri_ids[sb->cur_iocbq.sli4_lxritag];
2790+ set_bit(sb->cur_iocbq.sli4_lxritag, phba->sli4_hba.xri_bmask);
2791+ phba->sli4_hba.max_cfg_param.xri_used++;
2792+ phba->sli4_hba.xri_count++;
2793+ }
27922794 spin_unlock(&phba->scsi_buf_list_lock);
27932795 spin_unlock_irq(&phba->hbalock);
27942796 return 0;
@@ -3723,6 +3725,7 @@ lpfc_sli4_async_fip_evt(struct lpfc_hba *phba, · 928 unmodified lines
37233725 break;
37243726
37253727 case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
3728+ phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
37263729 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
37273730 "2549 FCF (x%x) disconnected from network, "
37283731 "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag);
@@ -3784,6 +3787,7 @@ lpfc_sli4_async_fip_evt(struct lpfc_hba *phba, · 55 unmodified lines
37843787 }
37853788 break;
37863789 case LPFC_FIP_EVENT_TYPE_CVL:
3790+ phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
37873791 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
37883792 "2718 Clear Virtual Link Received for VPI 0x%x"
37893793 " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
@@ -5226,8 +5230,7 @@ lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba) · 1436 unmodified lines
52265230 * rpi is normalized to a zero base because the physical rpi is
52275231 * port based.
52285232 */
5229− curr_rpi_range = phba->sli4_hba.next_rpi -
5230− phba->sli4_hba.max_cfg_param.rpi_base;
5233+ curr_rpi_range = phba->sli4_hba.next_rpi;
52315234 spin_unlock_irq(&phba->hbalock);
52325235
52335236 /*
@@ -5818,10 +5821,9 @@ lpfc_sli4_post_status_check(struct lpfc_hba *phba) · 584 unmodified lines
58185821 readl(phba->sli4_hba.u.if_type2.
58195822 ERR2regaddr);
58205823 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5821− "2888 Port Error Detected "
5822− "during POST: "
5823− "port status reg 0x%x, "
5824− "port_smphr reg 0x%x, "
5824+ "2888 Unrecoverable port error "
5825+ "following POST: port status reg "
5826+ "0x%x, port_smphr reg 0x%x, "
58255827 "error 1=0x%x, error 2=0x%x\n",
58265828 reg_data.word0,
58275829 portsmphr_reg.word0,
@@ -6142,7 +6144,6 @@ lpfc_sli4_read_config(struct lpfc_hba *phba) · 314 unmodified lines
61426144 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
61436145 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
61446146 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
6145− phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.rpi_base;
61466147 phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
61476148 (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
61486149 phba->max_vports = phba->max_vpi;
@@ -7231,6 +7232,7 @@ lpfc_pci_function_reset(struct lpfc_hba *phba) · 1082 unmodified lines
72317232 uint32_t rdy_chk, num_resets = 0, reset_again = 0;
72327233 union lpfc_sli4_cfg_shdr *shdr;
72337234 struct lpfc_register reg_data;
7235+ uint16_t devid;
72347236
72357237 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
72367238 switch (if_type) {
@@ -7277,7 +7279,9 @@ lpfc_pci_function_reset(struct lpfc_hba *phba) · 40 unmodified lines
72777279 LPFC_SLIPORT_INIT_PORT);
72787280 writel(reg_data.word0, phba->sli4_hba.u.if_type2.
72797281 CTRLregaddr);
7280−
7282+ /* flush */
7283+ pci_read_config_word(phba->pcidev,
7284+ PCI_DEVICE_ID, &devid);
72817285 /*
72827286 * Poll the Port Status Register and wait for RDY for
72837287 * up to 10 seconds. If the port doesn't respond, treat
@@ -7315,11 +7319,10 @@ lpfc_pci_function_reset(struct lpfc_hba *phba) · 31 unmodified lines
73157319 phba->work_status[1] = readl(
73167320 phba->sli4_hba.u.if_type2.ERR2regaddr);
73177321 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7318− "2890 Port Error Detected "
7319− "during Port Reset: "
7320− "port status reg 0x%x, "
7322+ "2890 Port error detected during port "
7323+ "reset(%d): port status reg 0x%x, "
73217324 "error 1=0x%x, error 2=0x%x\n",
7322− reg_data.word0,
7325+ num_resets, reg_data.word0,
73237326 phba->work_status[0],
73247327 phba->work_status[1]);
73257328 rc = -ENODEV;
drivers/scsi/lpfc/lpfc_nportdisc.c+7−3
@@ -1,7 +1,7 @@
11 /*******************************************************************
22 * This file is part of the Emulex Linux Device Driver for *
33 * Fibre Channel Host Bus Adapters. *
4− * Copyright (C) 2004-2009 Emulex. All rights reserved. *
4+ * Copyright (C) 2004-2012 Emulex. All rights reserved. *
55 * EMULEX and SLI are trademarks of Emulex. *
66 * www.emulex.com *
77 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
@@ -440,11 +440,15 @@ lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, · 432 unmodified lines
440440 spin_unlock_irq(shost->host_lock);
441441 stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
442442 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
443− lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
443+ rc = lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
444444 ndlp, mbox);
445+ if (rc)
446+ mempool_free(mbox, phba->mbox_mem_pool);
445447 return 1;
446448 }
447− lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox);
449+ rc = lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox);
450+ if (rc)
451+ mempool_free(mbox, phba->mbox_mem_pool);
448452 return 1;
449453 out:
450454 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
drivers/scsi/lpfc/lpfc_scsi.c+295−193
@@ -39,8 +39,8 @@ · 38 unmodified lines
3939 #include "lpfc_sli4.h"
4040 #include "lpfc_nl.h"
4141 #include "lpfc_disc.h"
42−#include "lpfc_scsi.h"
4342 #include "lpfc.h"
43+#include "lpfc_scsi.h"
4444 #include "lpfc_logmsg.h"
4545 #include "lpfc_crtn.h"
4646 #include "lpfc_vport.h"
@@ -51,13 +51,19 @@ · 4 unmodified lines
5151 int _dump_buf_done;
5252
5353 static char *dif_op_str[] = {
54− "SCSI_PROT_NORMAL",
55− "SCSI_PROT_READ_INSERT",
56− "SCSI_PROT_WRITE_STRIP",
57− "SCSI_PROT_READ_STRIP",
58− "SCSI_PROT_WRITE_INSERT",
59− "SCSI_PROT_READ_PASS",
60− "SCSI_PROT_WRITE_PASS",
54+ "PROT_NORMAL",
55+ "PROT_READ_INSERT",
56+ "PROT_WRITE_STRIP",
57+ "PROT_READ_STRIP",
58+ "PROT_WRITE_INSERT",
59+ "PROT_READ_PASS",
60+ "PROT_WRITE_PASS",
61+};
62+
63+static char *dif_grd_str[] = {
64+ "NO_GUARD",
65+ "DIF_CRC",
66+ "DIX_IP",
6167 };
6268
6369 struct scsi_dif_tuple {
@@ -1281,10 +1287,14 @@ lpfc_cmd_blksize(struct scsi_cmnd *sc) · 1217 unmodified lines
12811287
12821288 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
12831289
1284−#define BG_ERR_INIT 1
1285−#define BG_ERR_TGT 2
1286−#define BG_ERR_SWAP 3
1287−#define BG_ERR_CHECK 4
1290+/* Return if if error injection is detected by Initiator */
1291+#define BG_ERR_INIT 0x1
1292+/* Return if if error injection is detected by Target */
1293+#define BG_ERR_TGT 0x2
1294+/* Return if if swapping CSUM<-->CRC is required for error injection */
1295+#define BG_ERR_SWAP 0x10
1296+/* Return if disabling Guard/Ref/App checking is required for error injection */
1297+#define BG_ERR_CHECK 0x20
12881298
12891299 /**
12901300 * lpfc_bg_err_inject - Determine if we should inject an error
@@ -1294,10 +1304,7 @@ lpfc_cmd_blksize(struct scsi_cmnd *sc) · 3 unmodified lines
12941304 * @apptag: (out) BlockGuard application tag for transmitted data
12951305 * @new_guard (in) Value to replace CRC with if needed
12961306 *
1297− * Returns (1) if error injection is detected by Initiator
1298− * Returns (2) if error injection is detected by Target
1299− * Returns (3) if swapping CSUM->CRC is required for error injection
1300− * Returns (4) disabling Guard/Ref/App checking is required for error injection
1307+ * Returns BG_ERR_* bit mask or 0 if request ignored
13011308 **/
13021309 static int
13031310 lpfc_bg_err_inject(struct lpfc_hba *phba, struct scsi_cmnd *sc,
@@ -1305,7 +1312,10 @@ lpfc_bg_err_inject(struct lpfc_hba *phba, struct scsi_cmnd *sc, · 1 unmodified line
13051312 {
13061313 struct scatterlist *sgpe; /* s/g prot entry */
13071314 struct scatterlist *sgde; /* s/g data entry */
1315+ struct lpfc_scsi_buf *lpfc_cmd = NULL;
13081316 struct scsi_dif_tuple *src = NULL;
1317+ struct lpfc_nodelist *ndlp;
1318+ struct lpfc_rport_data *rdata;
13091319 uint32_t op = scsi_get_prot_op(sc);
13101320 uint32_t blksize;
13111321 uint32_t numblks;
@@ -1318,8 +1328,9 @@ lpfc_bg_err_inject(struct lpfc_hba *phba, struct scsi_cmnd *sc, · 6 unmodified lines
13181328
13191329 sgpe = scsi_prot_sglist(sc);
13201330 sgde = scsi_sglist(sc);
1321−
13221331 lba = scsi_get_lba(sc);
1332+
1333+ /* First check if we need to match the LBA */
13231334 if (phba->lpfc_injerr_lba != LPFC_INJERR_LBA_OFF) {
13241335 blksize = lpfc_cmd_blksize(sc);
13251336 numblks = (scsi_bufflen(sc) + blksize - 1) / blksize;
@@ -1334,66 +1345,123 @@ lpfc_bg_err_inject(struct lpfc_hba *phba, struct scsi_cmnd *sc, · 8 unmodified lines
13341345 sizeof(struct scsi_dif_tuple);
13351346 if (numblks < blockoff)
13361347 blockoff = numblks;
1337− src = (struct scsi_dif_tuple *)sg_virt(sgpe);
1338− src += blockoff;
13391348 }
13401349 }
13411350
1351+ /* Next check if we need to match the remote NPortID or WWPN */
1352+ rdata = sc->device->hostdata;
1353+ if (rdata && rdata->pnode) {
1354+ ndlp = rdata->pnode;
1355+
1356+ /* Make sure we have the right NPortID if one is specified */
1357+ if (phba->lpfc_injerr_nportid &&
1358+ (phba->lpfc_injerr_nportid != ndlp->nlp_DID))
1359+ return 0;
1360+
1361+ /*
1362+ * Make sure we have the right WWPN if one is specified.
1363+ * wwn[0] should be a non-zero NAA in a good WWPN.
1364+ */
1365+ if (phba->lpfc_injerr_wwpn.u.wwn[0] &&
1366+ (memcmp(&ndlp->nlp_portname, &phba->lpfc_injerr_wwpn,
1367+ sizeof(struct lpfc_name)) != 0))
1368+ return 0;
1369+ }
1370+
1371+ /* Setup a ptr to the protection data if the SCSI host provides it */
1372+ if (sgpe) {
1373+ src = (struct scsi_dif_tuple *)sg_virt(sgpe);
1374+ src += blockoff;
1375+ lpfc_cmd = (struct lpfc_scsi_buf *)sc->host_scribble;
1376+ }
1377+
13421378 /* Should we change the Reference Tag */
13431379 if (reftag) {
13441380 if (phba->lpfc_injerr_wref_cnt) {
13451381 switch (op) {
13461382 case SCSI_PROT_WRITE_PASS:
1347− if (blockoff && src) {
1348− /* Insert error in middle of the IO */
1383+ if (src) {
1384+ /*
1385+ * For WRITE_PASS, force the error
1386+ * to be sent on the wire. It should
1387+ * be detected by the Target.
1388+ * If blockoff != 0 error will be
1389+ * inserted in middle of the IO.
1390+ */
13491391
13501392 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
13511393 "9076 BLKGRD: Injecting reftag error: "
13521394 "write lba x%lx + x%x oldrefTag x%x\n",
13531395 (unsigned long)lba, blockoff,
1354− src->ref_tag);
1396+ be32_to_cpu(src->ref_tag));
13551397
13561398 /*
1357− * NOTE, this will change ref tag in
1358− * the memory location forever!
1399+ * Save the old ref_tag so we can
1400+ * restore it on completion.
13591401 */
1360− src->ref_tag = 0xDEADBEEF;
1402+ if (lpfc_cmd) {
1403+ lpfc_cmd->prot_data_type =
1404+ LPFC_INJERR_REFTAG;
1405+ lpfc_cmd->prot_data_segment =
1406+ src;
1407+ lpfc_cmd->prot_data =
1408+ src->ref_tag;
1409+ }
1410+ src->ref_tag = cpu_to_be32(0xDEADBEEF);
13611411 phba->lpfc_injerr_wref_cnt--;
1362− phba->lpfc_injerr_lba =
1363− LPFC_INJERR_LBA_OFF;
1364− rc = BG_ERR_CHECK;
1412+ if (phba->lpfc_injerr_wref_cnt == 0) {
1413+ phba->lpfc_injerr_nportid = 0;
1414+ phba->lpfc_injerr_lba =
1415+ LPFC_INJERR_LBA_OFF;
1416+ memset(&phba->lpfc_injerr_wwpn,
1417+ 0, sizeof(struct lpfc_name));
1418+ }
1419+ rc = BG_ERR_TGT | BG_ERR_CHECK;
1420+
13651421 break;
13661422 }
13671423 /* Drop thru */
1368− case SCSI_PROT_WRITE_STRIP:
1424+ case SCSI_PROT_WRITE_INSERT:
13691425 /*
1370− * For WRITE_STRIP and WRITE_PASS,
1371− * force the error on data
1372− * being copied from SLI-Host to SLI-Port.
1426+ * For WRITE_INSERT, force the error
1427+ * to be sent on the wire. It should be
1428+ * detected by the Target.
13731429 */
1430+ /* DEADBEEF will be the reftag on the wire */
13741431 *reftag = 0xDEADBEEF;
13751432 phba->lpfc_injerr_wref_cnt--;
1376− phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
1377− rc = BG_ERR_INIT;
1433+ if (phba->lpfc_injerr_wref_cnt == 0) {
1434+ phba->lpfc_injerr_nportid = 0;
1435+ phba->lpfc_injerr_lba =
1436+ LPFC_INJERR_LBA_OFF;
1437+ memset(&phba->lpfc_injerr_wwpn,
1438+ 0, sizeof(struct lpfc_name));
1439+ }
1440+ rc = BG_ERR_TGT | BG_ERR_CHECK;
13781441
13791442 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1380− "9077 BLKGRD: Injecting reftag error: "
1443+ "9078 BLKGRD: Injecting reftag error: "
13811444 "write lba x%lx\n", (unsigned long)lba);
13821445 break;
1383− case SCSI_PROT_WRITE_INSERT:
1446+ case SCSI_PROT_WRITE_STRIP:
13841447 /*
1385− * For WRITE_INSERT, force the
1386− * error to be sent on the wire. It should be
1387− * detected by the Target.
1448+ * For WRITE_STRIP and WRITE_PASS,
1449+ * force the error on data
1450+ * being copied from SLI-Host to SLI-Port.
13881451 */
1389− /* DEADBEEF will be the reftag on the wire */
13901452 *reftag = 0xDEADBEEF;
13911453 phba->lpfc_injerr_wref_cnt--;
1392− phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
1393− rc = BG_ERR_TGT;
1454+ if (phba->lpfc_injerr_wref_cnt == 0) {
1455+ phba->lpfc_injerr_nportid = 0;
1456+ phba->lpfc_injerr_lba =
1457+ LPFC_INJERR_LBA_OFF;
1458+ memset(&phba->lpfc_injerr_wwpn,
1459+ 0, sizeof(struct lpfc_name));
1460+ }
1461+ rc = BG_ERR_INIT;
13941462
13951463 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1396− "9078 BLKGRD: Injecting reftag error: "
1464+ "9077 BLKGRD: Injecting reftag error: "
13971465 "write lba x%lx\n", (unsigned long)lba);
13981466 break;
13991467 }
@@ -1401,11 +1469,6 @@ lpfc_bg_err_inject(struct lpfc_hba *phba, struct scsi_cmnd *sc, · 1 unmodified line
14011469 if (phba->lpfc_injerr_rref_cnt) {
14021470 switch (op) {
14031471 case SCSI_PROT_READ_INSERT:
1404− /*
1405− * For READ_INSERT, it doesn't make sense
1406− * to change the reftag.
1407− */
1408− break;
14091472 case SCSI_PROT_READ_STRIP:
14101473 case SCSI_PROT_READ_PASS:
14111474 /*
@@ -1415,7 +1478,13 @@ lpfc_bg_err_inject(struct lpfc_hba *phba, struct scsi_cmnd *sc, · 3 unmodified lines
14151478 */
14161479 *reftag = 0xDEADBEEF;
14171480 phba->lpfc_injerr_rref_cnt--;
1418− phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
1481+ if (phba->lpfc_injerr_rref_cnt == 0) {
1482+ phba->lpfc_injerr_nportid = 0;
1483+ phba->lpfc_injerr_lba =
1484+ LPFC_INJERR_LBA_OFF;
1485+ memset(&phba->lpfc_injerr_wwpn,
1486+ 0, sizeof(struct lpfc_name));
1487+ }
14191488 rc = BG_ERR_INIT;
14201489
14211490 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
@@ -1431,56 +1500,87 @@ lpfc_bg_err_inject(struct lpfc_hba *phba, struct scsi_cmnd *sc, · 9 unmodified lines
14311500 if (phba->lpfc_injerr_wapp_cnt) {
14321501 switch (op) {
14331502 case SCSI_PROT_WRITE_PASS:
1434− if (blockoff && src) {
1435− /* Insert error in middle of the IO */
1503+ if (src) {
1504+ /*
1505+ * For WRITE_PASS, force the error
1506+ * to be sent on the wire. It should
1507+ * be detected by the Target.
1508+ * If blockoff != 0 error will be
1509+ * inserted in middle of the IO.
1510+ */
14361511
14371512 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
14381513 "9080 BLKGRD: Injecting apptag error: "
14391514 "write lba x%lx + x%x oldappTag x%x\n",
14401515 (unsigned long)lba, blockoff,
1441− src->app_tag);
1516+ be16_to_cpu(src->app_tag));
14421517
14431518 /*
1444− * NOTE, this will change app tag in
1445− * the memory location forever!
1519+ * Save the old app_tag so we can
1520+ * restore it on completion.
14461521 */
1447− src->app_tag = 0xDEAD;
1522+ if (lpfc_cmd) {
1523+ lpfc_cmd->prot_data_type =
1524+ LPFC_INJERR_APPTAG;
1525+ lpfc_cmd->prot_data_segment =
1526+ src;
1527+ lpfc_cmd->prot_data =
1528+ src->app_tag;
1529+ }
1530+ src->app_tag = cpu_to_be16(0xDEAD);
14481531 phba->lpfc_injerr_wapp_cnt--;
1449− phba->lpfc_injerr_lba =
1450− LPFC_INJERR_LBA_OFF;
1451− rc = BG_ERR_CHECK;
1532+ if (phba->lpfc_injerr_wapp_cnt == 0) {
1533+ phba->lpfc_injerr_nportid = 0;
1534+ phba->lpfc_injerr_lba =
1535+ LPFC_INJERR_LBA_OFF;
1536+ memset(&phba->lpfc_injerr_wwpn,
1537+ 0, sizeof(struct lpfc_name));
1538+ }
1539+ rc = BG_ERR_TGT | BG_ERR_CHECK;
14521540 break;
14531541 }
14541542 /* Drop thru */
1455− case SCSI_PROT_WRITE_STRIP:
1543+ case SCSI_PROT_WRITE_INSERT:
14561544 /*
1457− * For WRITE_STRIP and WRITE_PASS,
1458− * force the error on data
1459− * being copied from SLI-Host to SLI-Port.
1545+ * For WRITE_INSERT, force the
1546+ * error to be sent on the wire. It should be
1547+ * detected by the Target.
14601548 */
1549+ /* DEAD will be the apptag on the wire */
14611550 *apptag = 0xDEAD;
14621551 phba->lpfc_injerr_wapp_cnt--;
1463− phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
1464− rc = BG_ERR_INIT;
1552+ if (phba->lpfc_injerr_wapp_cnt == 0) {
1553+ phba->lpfc_injerr_nportid = 0;
1554+ phba->lpfc_injerr_lba =
1555+ LPFC_INJERR_LBA_OFF;
1556+ memset(&phba->lpfc_injerr_wwpn,
1557+ 0, sizeof(struct lpfc_name));
1558+ }
1559+ rc = BG_ERR_TGT | BG_ERR_CHECK;
14651560
14661561 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1467− "0812 BLKGRD: Injecting apptag error: "
1562+ "0813 BLKGRD: Injecting apptag error: "
14681563 "write lba x%lx\n", (unsigned long)lba);
14691564 break;
1470− case SCSI_PROT_WRITE_INSERT:
1565+ case SCSI_PROT_WRITE_STRIP:
14711566 /*
1472− * For WRITE_INSERT, force the
1473− * error to be sent on the wire. It should be
1474− * detected by the Target.
1567+ * For WRITE_STRIP and WRITE_PASS,
1568+ * force the error on data
1569+ * being copied from SLI-Host to SLI-Port.
14751570 */
1476− /* DEAD will be the apptag on the wire */
14771571 *apptag = 0xDEAD;
14781572 phba->lpfc_injerr_wapp_cnt--;
1479− phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
1480− rc = BG_ERR_TGT;
1573+ if (phba->lpfc_injerr_wapp_cnt == 0) {
1574+ phba->lpfc_injerr_nportid = 0;
1575+ phba->lpfc_injerr_lba =
1576+ LPFC_INJERR_LBA_OFF;
1577+ memset(&phba->lpfc_injerr_wwpn,
1578+ 0, sizeof(struct lpfc_name));
1579+ }
1580+ rc = BG_ERR_INIT;
14811581
14821582 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1483− "0813 BLKGRD: Injecting apptag error: "
1583+ "0812 BLKGRD: Injecting apptag error: "
14841584 "write lba x%lx\n", (unsigned long)lba);
14851585 break;
14861586 }
@@ -1488,11 +1588,6 @@ lpfc_bg_err_inject(struct lpfc_hba *phba, struct scsi_cmnd *sc, · 1 unmodified line
14881588 if (phba->lpfc_injerr_rapp_cnt) {
14891589 switch (op) {
14901590 case SCSI_PROT_READ_INSERT:
1491− /*
1492− * For READ_INSERT, it doesn't make sense
1493− * to change the apptag.
1494− */
1495− break;
14961591 case SCSI_PROT_READ_STRIP:
14971592 case SCSI_PROT_READ_PASS:
14981593 /*
@@ -1502,7 +1597,13 @@ lpfc_bg_err_inject(struct lpfc_hba *phba, struct scsi_cmnd *sc, · 3 unmodified lines
15021597 */
15031598 *apptag = 0xDEAD;
15041599 phba->lpfc_injerr_rapp_cnt--;
1505− phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
1600+ if (phba->lpfc_injerr_rapp_cnt == 0) {
1601+ phba->lpfc_injerr_nportid = 0;
1602+ phba->lpfc_injerr_lba =
1603+ LPFC_INJERR_LBA_OFF;
1604+ memset(&phba->lpfc_injerr_wwpn,
1605+ 0, sizeof(struct lpfc_name));
1606+ }
15061607 rc = BG_ERR_INIT;
15071608
15081609 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
@@ -1519,57 +1620,51 @@ lpfc_bg_err_inject(struct lpfc_hba *phba, struct scsi_cmnd *sc, · 10 unmodified lines
15191620 if (phba->lpfc_injerr_wgrd_cnt) {
15201621 switch (op) {
15211622 case SCSI_PROT_WRITE_PASS:
1522− if (blockoff && src) {
1523− /* Insert error in middle of the IO */
1524−
1525− lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1526− "0815 BLKGRD: Injecting guard error: "
1527− "write lba x%lx + x%x oldgrdTag x%x\n",
1528− (unsigned long)lba, blockoff,
1529− src->guard_tag);
1530−
1531− /*
1532− * NOTE, this will change guard tag in
1533− * the memory location forever!
1534− */
1535− src->guard_tag = 0xDEAD;
1536− phba->lpfc_injerr_wgrd_cnt--;
1537− phba->lpfc_injerr_lba =
1538− LPFC_INJERR_LBA_OFF;
1539− rc = BG_ERR_CHECK;
1540− break;
1541− }
1623+ rc = BG_ERR_CHECK;
15421624 /* Drop thru */
1543− case SCSI_PROT_WRITE_STRIP:
1625+
1626+ case SCSI_PROT_WRITE_INSERT:
15441627 /*
1545− * For WRITE_STRIP and WRITE_PASS,
1546− * force the error on data
1547− * being copied from SLI-Host to SLI-Port.
1628+ * For WRITE_INSERT, force the
1629+ * error to be sent on the wire. It should be
1630+ * detected by the Target.
15481631 */
15491632 phba->lpfc_injerr_wgrd_cnt--;
1550− phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
1633+ if (phba->lpfc_injerr_wgrd_cnt == 0) {
1634+ phba->lpfc_injerr_nportid = 0;
1635+ phba->lpfc_injerr_lba =
1636+ LPFC_INJERR_LBA_OFF;
1637+ memset(&phba->lpfc_injerr_wwpn,
1638+ 0, sizeof(struct lpfc_name));
1639+ }
15511640
1552− rc = BG_ERR_SWAP;
1641+ rc |= BG_ERR_TGT | BG_ERR_SWAP;
15531642 /* Signals the caller to swap CRC->CSUM */
15541643
15551644 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1556− "0816 BLKGRD: Injecting guard error: "
1645+ "0817 BLKGRD: Injecting guard error: "
15571646 "write lba x%lx\n", (unsigned long)lba);
15581647 break;
1559− case SCSI_PROT_WRITE_INSERT:
1648+ case SCSI_PROT_WRITE_STRIP:
15601649 /*
1561− * For WRITE_INSERT, force the
1562− * error to be sent on the wire. It should be
1563− * detected by the Target.
1650+ * For WRITE_STRIP and WRITE_PASS,
1651+ * force the error on data
1652+ * being copied from SLI-Host to SLI-Port.
15641653 */
15651654 phba->lpfc_injerr_wgrd_cnt--;
1566− phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
1655+ if (phba->lpfc_injerr_wgrd_cnt == 0) {
1656+ phba->lpfc_injerr_nportid = 0;
1657+ phba->lpfc_injerr_lba =
1658+ LPFC_INJERR_LBA_OFF;
1659+ memset(&phba->lpfc_injerr_wwpn,
1660+ 0, sizeof(struct lpfc_name));
1661+ }
15671662
1568− rc = BG_ERR_SWAP;
1663+ rc = BG_ERR_INIT | BG_ERR_SWAP;
15691664 /* Signals the caller to swap CRC->CSUM */
15701665
15711666 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
1572− "0817 BLKGRD: Injecting guard error: "
1667+ "0816 BLKGRD: Injecting guard error: "
15731668 "write lba x%lx\n", (unsigned long)lba);
15741669 break;
15751670 }
@@ -1577,11 +1672,6 @@ lpfc_bg_err_inject(struct lpfc_hba *phba, struct scsi_cmnd *sc, · 1 unmodified line
15771672 if (phba->lpfc_injerr_rgrd_cnt) {
15781673 switch (op) {
15791674 case SCSI_PROT_READ_INSERT:
1580− /*
1581− * For READ_INSERT, it doesn't make sense
1582− * to change the guard tag.
1583− */
1584− break;
15851675 case SCSI_PROT_READ_STRIP:
15861676 case SCSI_PROT_READ_PASS:
15871677 /*
@@ -1589,11 +1679,16 @@ lpfc_bg_err_inject(struct lpfc_hba *phba, struct scsi_cmnd *sc, · 1 unmodified line
15891679 * error on data being read off the wire. It
15901680 * should force an IO error to the driver.
15911681 */
1592− *apptag = 0xDEAD;
15931682 phba->lpfc_injerr_rgrd_cnt--;
1594− phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
1683+ if (phba->lpfc_injerr_rgrd_cnt == 0) {
1684+ phba->lpfc_injerr_nportid = 0;
1685+ phba->lpfc_injerr_lba =
1686+ LPFC_INJERR_LBA_OFF;
1687+ memset(&phba->lpfc_injerr_wwpn,
1688+ 0, sizeof(struct lpfc_name));
1689+ }
15951690
1596− rc = BG_ERR_SWAP;
1691+ rc = BG_ERR_INIT | BG_ERR_SWAP;
15971692 /* Signals the caller to swap CRC->CSUM */
15981693
15991694 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
@@ -1629,20 +1724,20 @@ lpfc_sc_to_bg_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc, · 29 unmodified lines
16291724 switch (scsi_get_prot_op(sc)) {
16301725 case SCSI_PROT_READ_INSERT:
16311726 case SCSI_PROT_WRITE_STRIP:
1632− *txop = BG_OP_IN_CSUM_OUT_NODIF;
16331727 *rxop = BG_OP_IN_NODIF_OUT_CSUM;
1728+ *txop = BG_OP_IN_CSUM_OUT_NODIF;
16341729 break;
16351730
16361731 case SCSI_PROT_READ_STRIP:
16371732 case SCSI_PROT_WRITE_INSERT:
1638− *txop = BG_OP_IN_NODIF_OUT_CRC;
16391733 *rxop = BG_OP_IN_CRC_OUT_NODIF;
1734+ *txop = BG_OP_IN_NODIF_OUT_CRC;
16401735 break;
16411736
16421737 case SCSI_PROT_READ_PASS:
16431738 case SCSI_PROT_WRITE_PASS:
1644− *txop = BG_OP_IN_CSUM_OUT_CRC;
16451739 *rxop = BG_OP_IN_CRC_OUT_CSUM;
1740+ *txop = BG_OP_IN_CSUM_OUT_CRC;
16461741 break;
16471742
16481743 case SCSI_PROT_NORMAL:
@@ -1658,20 +1753,20 @@ lpfc_sc_to_bg_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc, · 9 unmodified lines
16581753 switch (scsi_get_prot_op(sc)) {
16591754 case SCSI_PROT_READ_STRIP:
16601755 case SCSI_PROT_WRITE_INSERT:
1661− *txop = BG_OP_IN_NODIF_OUT_CRC;
16621756 *rxop = BG_OP_IN_CRC_OUT_NODIF;
1757+ *txop = BG_OP_IN_NODIF_OUT_CRC;
16631758 break;
16641759
16651760 case SCSI_PROT_READ_PASS:
16661761 case SCSI_PROT_WRITE_PASS:
1667− *txop = BG_OP_IN_CRC_OUT_CRC;
16681762 *rxop = BG_OP_IN_CRC_OUT_CRC;
1763+ *txop = BG_OP_IN_CRC_OUT_CRC;
16691764 break;
16701765
16711766 case SCSI_PROT_READ_INSERT:
16721767 case SCSI_PROT_WRITE_STRIP:
1673− *txop = BG_OP_IN_CRC_OUT_NODIF;
16741768 *rxop = BG_OP_IN_NODIF_OUT_CRC;
1769+ *txop = BG_OP_IN_CRC_OUT_NODIF;
16751770 break;
16761771
16771772 case SCSI_PROT_NORMAL:
@@ -1710,20 +1805,20 @@ lpfc_bg_err_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc, · 32 unmodified lines
17101805 switch (scsi_get_prot_op(sc)) {
17111806 case SCSI_PROT_READ_INSERT:
17121807 case SCSI_PROT_WRITE_STRIP:
1713− *txop = BG_OP_IN_CRC_OUT_NODIF;
17141808 *rxop = BG_OP_IN_NODIF_OUT_CRC;
1809+ *txop = BG_OP_IN_CRC_OUT_NODIF;
17151810 break;
17161811
17171812 case SCSI_PROT_READ_STRIP:
17181813 case SCSI_PROT_WRITE_INSERT:
1719− *txop = BG_OP_IN_NODIF_OUT_CSUM;
17201814 *rxop = BG_OP_IN_CSUM_OUT_NODIF;
1815+ *txop = BG_OP_IN_NODIF_OUT_CSUM;
17211816 break;
17221817
17231818 case SCSI_PROT_READ_PASS:
17241819 case SCSI_PROT_WRITE_PASS:
1725− *txop = BG_OP_IN_CRC_OUT_CRC;
1726− *rxop = BG_OP_IN_CRC_OUT_CRC;
1820+ *rxop = BG_OP_IN_CSUM_OUT_CRC;
1821+ *txop = BG_OP_IN_CRC_OUT_CSUM;
17271822 break;
17281823
17291824 case SCSI_PROT_NORMAL:
@@ -1735,20 +1830,20 @@ lpfc_bg_err_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc, · 5 unmodified lines
17351830 switch (scsi_get_prot_op(sc)) {
17361831 case SCSI_PROT_READ_STRIP:
17371832 case SCSI_PROT_WRITE_INSERT:
1738− *txop = BG_OP_IN_NODIF_OUT_CSUM;
17391833 *rxop = BG_OP_IN_CSUM_OUT_NODIF;
1834+ *txop = BG_OP_IN_NODIF_OUT_CSUM;
17401835 break;
17411836
17421837 case SCSI_PROT_READ_PASS:
17431838 case SCSI_PROT_WRITE_PASS:
1744− *txop = BG_OP_IN_CSUM_OUT_CRC;
1745− *rxop = BG_OP_IN_CRC_OUT_CSUM;
1839+ *rxop = BG_OP_IN_CSUM_OUT_CSUM;
1840+ *txop = BG_OP_IN_CSUM_OUT_CSUM;
17461841 break;
17471842
17481843 case SCSI_PROT_READ_INSERT:
17491844 case SCSI_PROT_WRITE_STRIP:
1750− *txop = BG_OP_IN_CSUM_OUT_NODIF;
17511845 *rxop = BG_OP_IN_NODIF_OUT_CSUM;
1846+ *txop = BG_OP_IN_CSUM_OUT_NODIF;
17521847 break;
17531848
17541849 case SCSI_PROT_NORMAL:
@@ -1817,11 +1912,11 @@ lpfc_bg_setup_bpl(struct lpfc_hba *phba, struct scsi_cmnd *sc, · 62 unmodified lines
18171912 reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */
18181913
18191914 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1820− rc = lpfc_bg_err_inject(phba, sc, &reftag, 0, 1);
1915+ rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1);
18211916 if (rc) {
1822− if (rc == BG_ERR_SWAP)
1917+ if (rc & BG_ERR_SWAP)
18231918 lpfc_bg_err_opcodes(phba, sc, &txop, &rxop);
1824− if (rc == BG_ERR_CHECK)
1919+ if (rc & BG_ERR_CHECK)
18251920 checking = 0;
18261921 }
18271922 #endif
@@ -1964,11 +2059,11 @@ lpfc_bg_setup_bpl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc, · 136 unmodified lines
19642059 reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */
19652060
19662061 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1967− rc = lpfc_bg_err_inject(phba, sc, &reftag, 0, 1);
2062+ rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1);
19682063 if (rc) {
1969− if (rc == BG_ERR_SWAP)
2064+ if (rc & BG_ERR_SWAP)
19702065 lpfc_bg_err_opcodes(phba, sc, &txop, &rxop);
1971− if (rc == BG_ERR_CHECK)
2066+ if (rc & BG_ERR_CHECK)
19722067 checking = 0;
19732068 }
19742069 #endif
@@ -2172,11 +2267,11 @@ lpfc_bg_setup_sgl(struct lpfc_hba *phba, struct scsi_cmnd *sc, · 197 unmodified lines
21722267 reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */
21732268
21742269 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2175− rc = lpfc_bg_err_inject(phba, sc, &reftag, 0, 1);
2270+ rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1);
21762271 if (rc) {
2177− if (rc == BG_ERR_SWAP)
2272+ if (rc & BG_ERR_SWAP)
21782273 lpfc_bg_err_opcodes(phba, sc, &txop, &rxop);
2179− if (rc == BG_ERR_CHECK)
2274+ if (rc & BG_ERR_CHECK)
21802275 checking = 0;
21812276 }
21822277 #endif
@@ -2312,11 +2407,11 @@ lpfc_bg_setup_sgl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc, · 129 unmodified lines
23122407 reftag = (uint32_t)scsi_get_lba(sc); /* Truncate LBA */
23132408
23142409 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2315− rc = lpfc_bg_err_inject(phba, sc, &reftag, 0, 1);
2410+ rc = lpfc_bg_err_inject(phba, sc, &reftag, NULL, 1);
23162411 if (rc) {
2317− if (rc == BG_ERR_SWAP)
2412+ if (rc & BG_ERR_SWAP)
23182413 lpfc_bg_err_opcodes(phba, sc, &txop, &rxop);
2319− if (rc == BG_ERR_CHECK)
2414+ if (rc & BG_ERR_CHECK)
23202415 checking = 0;
23212416 }
23222417 #endif
@@ -2788,7 +2883,7 @@ lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd, · 465 unmodified lines
27882883 /* No error was reported - problem in FW? */
27892884 cmd->result = ScsiResult(DID_ERROR, 0);
27902885 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
2791− "9057 BLKGRD: no errors reported!\n");
2886+ "9057 BLKGRD: Unknown error reported!\n");
27922887 }
27932888
27942889 out:
@@ -3460,6 +3555,37 @@ lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn, · 665 unmodified lines
34603555 /* pick up SLI4 exhange busy status from HBA */
34613556 lpfc_cmd->exch_busy = pIocbOut->iocb_flag & LPFC_EXCHANGE_BUSY;
34623557
3558+#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3559+ if (lpfc_cmd->prot_data_type) {
3560+ struct scsi_dif_tuple *src = NULL;
3561+
3562+ src = (struct scsi_dif_tuple *)lpfc_cmd->prot_data_segment;
3563+ /*
3564+ * Used to restore any changes to protection
3565+ * data for error injection.
3566+ */
3567+ switch (lpfc_cmd->prot_data_type) {
3568+ case LPFC_INJERR_REFTAG:
3569+ src->ref_tag =
3570+ lpfc_cmd->prot_data;
3571+ break;
3572+ case LPFC_INJERR_APPTAG:
3573+ src->app_tag =
3574+ (uint16_t)lpfc_cmd->prot_data;
3575+ break;
3576+ case LPFC_INJERR_GUARD:
3577+ src->guard_tag =
3578+ (uint16_t)lpfc_cmd->prot_data;
3579+ break;
3580+ default:
3581+ break;
3582+ }
3583+
3584+ lpfc_cmd->prot_data = 0;
3585+ lpfc_cmd->prot_data_type = 0;
3586+ lpfc_cmd->prot_data_segment = NULL;
3587+ }
3588+#endif
34633589 if (pnode && NLP_CHK_NODE_ACT(pnode))
34643590 atomic_dec(&pnode->cmd_pending);
34653591
@@ -4061,15 +4187,6 @@ lpfc_queuecommand_lck(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *)) · 595 unmodified lines
40614187 cmnd->result = err;
40624188 goto out_fail_command;
40634189 }
4064− /*
4065− * Do not let the mid-layer retry I/O too fast. If an I/O is retried
4066− * without waiting a bit then indicate that the device is busy.
4067− */
4068− if (cmnd->retries &&
4069− time_before(jiffies, (cmnd->jiffies_at_alloc +
4070− msecs_to_jiffies(LPFC_RETRY_PAUSE *
4071− cmnd->retries))))
4072− return SCSI_MLQUEUE_DEVICE_BUSY;
40734190 ndlp = rdata->pnode;
40744191
40754192 if ((scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) &&
@@ -4119,63 +4236,48 @@ lpfc_queuecommand_lck(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *)) · 43 unmodified lines
41194236 if (scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) {
41204237 if (vport->phba->cfg_enable_bg) {
41214238 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
4122− "9033 BLKGRD: rcvd protected cmd:%02x op:%02x "
4123− "str=%s\n",
4124− cmnd->cmnd[0], scsi_get_prot_op(cmnd),
4125− dif_op_str[scsi_get_prot_op(cmnd)]);
4126− lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
4127− "9034 BLKGRD: CDB: %02x %02x %02x %02x %02x "
4128− "%02x %02x %02x %02x %02x\n",
4129− cmnd->cmnd[0], cmnd->cmnd[1], cmnd->cmnd[2],
4130− cmnd->cmnd[3], cmnd->cmnd[4], cmnd->cmnd[5],
4131− cmnd->cmnd[6], cmnd->cmnd[7], cmnd->cmnd[8],
4132− cmnd->cmnd[9]);
4239+ "9033 BLKGRD: rcvd protected cmd:%02x op=%s "
4240+ "guard=%s\n", cmnd->cmnd[0],
4241+ dif_op_str[scsi_get_prot_op(cmnd)],
4242+ dif_grd_str[scsi_host_get_guard(shost)]);
41334243 if (cmnd->cmnd[0] == READ_10)
41344244 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
41354245 "9035 BLKGRD: READ @ sector %llu, "
4136− "count %u\n",
4246+ "cnt %u, rpt %d\n",
41374247 (unsigned long long)scsi_get_lba(cmnd),
4138− blk_rq_sectors(cmnd->request));
4248+ blk_rq_sectors(cmnd->request),
4249+ (cmnd->cmnd[1]>>5));
41394250 else if (cmnd->cmnd[0] == WRITE_10)
41404251 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
41414252 "9036 BLKGRD: WRITE @ sector %llu, "
4142− "count %u cmd=%p\n",
4253+ "cnt %u, wpt %d\n",
41434254 (unsigned long long)scsi_get_lba(cmnd),
41444255 blk_rq_sectors(cmnd->request),
4145− cmnd);
4256+ (cmnd->cmnd[1]>>5));
41464257 }
41474258
41484259 err = lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd);
41494260 } else {
41504261 if (vport->phba->cfg_enable_bg) {
41514262 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
4152− "9038 BLKGRD: rcvd unprotected cmd:"
4153− "%02x op:%02x str=%s\n",
4154− cmnd->cmnd[0], scsi_get_prot_op(cmnd),
4155− dif_op_str[scsi_get_prot_op(cmnd)]);
4156− lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
4157− "9039 BLKGRD: CDB: %02x %02x %02x "
4158− "%02x %02x %02x %02x %02x %02x %02x\n",
4159− cmnd->cmnd[0], cmnd->cmnd[1],
4160− cmnd->cmnd[2], cmnd->cmnd[3],
4161− cmnd->cmnd[4], cmnd->cmnd[5],
4162− cmnd->cmnd[6], cmnd->cmnd[7],
4163− cmnd->cmnd[8], cmnd->cmnd[9]);
4263+ "9038 BLKGRD: rcvd unprotected cmd:"
4264+ "%02x op=%s guard=%s\n", cmnd->cmnd[0],
4265+ dif_op_str[scsi_get_prot_op(cmnd)],
4266+ dif_grd_str[scsi_host_get_guard(shost)]);
41644267 if (cmnd->cmnd[0] == READ_10)
41654268 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
41664269 "9040 dbg: READ @ sector %llu, "
4167− "count %u\n",
4270+ "cnt %u, rpt %d\n",
41684271 (unsigned long long)scsi_get_lba(cmnd),
4169− blk_rq_sectors(cmnd->request));
4272+ blk_rq_sectors(cmnd->request),
4273+ (cmnd->cmnd[1]>>5));
41704274 else if (cmnd->cmnd[0] == WRITE_10)
41714275 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
4172− "9041 dbg: WRITE @ sector %llu, "
4173− "count %u cmd=%p\n",
4174− (unsigned long long)scsi_get_lba(cmnd),
4175− blk_rq_sectors(cmnd->request), cmnd);
4176− else
4177− lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
4178− "9042 dbg: parser not implemented\n");
4276+ "9041 dbg: WRITE @ sector %llu, "
4277+ "cnt %u, wpt %d\n",
4278+ (unsigned long long)scsi_get_lba(cmnd),
4279+ blk_rq_sectors(cmnd->request),
4280+ (cmnd->cmnd[1]>>5));
41794281 }
41804282 err = lpfc_scsi_prep_dma_buf(phba, lpfc_cmd);
41814283 }
drivers/scsi/lpfc/lpfc_scsi.h+11−2
@@ -1,7 +1,7 @@
11 /*******************************************************************
22 * This file is part of the Emulex Linux Device Driver for *
33 * Fibre Channel Host Bus Adapters. *
4− * Copyright (C) 2004-2006 Emulex. All rights reserved. *
4+ * Copyright (C) 2004-2012 Emulex. All rights reserved. *
55 * EMULEX and SLI are trademarks of Emulex. *
66 * www.emulex.com *
77 * *
@@ -150,9 +150,18 @@ struct lpfc_scsi_buf { · 142 unmodified lines
150150 struct lpfc_iocbq cur_iocbq;
151151 wait_queue_head_t *waitq;
152152 unsigned long start_time;
153+
154+#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
155+ /* Used to restore any changes to protection data for error injection */
156+ void *prot_data_segment;
157+ uint32_t prot_data;
158+ uint32_t prot_data_type;
159+#define LPFC_INJERR_REFTAG 1
160+#define LPFC_INJERR_APPTAG 2
161+#define LPFC_INJERR_GUARD 3
162+#endif
153163 };
154164
155165 #define LPFC_SCSI_DMA_EXT_SIZE 264
156166 #define LPFC_BPL_SIZE 1024
157−#define LPFC_RETRY_PAUSE 300
158167 #define MDAC_DIRECT_CMD 0x22
drivers/scsi/lpfc/lpfc_sli.c+39−23
@@ -1,7 +1,7 @@
11 /*******************************************************************
22 * This file is part of the Emulex Linux Device Driver for *
33 * Fibre Channel Host Bus Adapters. *
4− * Copyright (C) 2004-2011 Emulex. All rights reserved. *
4+ * Copyright (C) 2004-2012 Emulex. All rights reserved. *
55 * EMULEX and SLI are trademarks of Emulex. *
66 * www.emulex.com *
77 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
@@ -5578,8 +5578,6 @@ lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba) · 5570 unmodified lines
55785578 for (i = 0; i < count; i++)
55795579 phba->sli4_hba.rpi_ids[i] = base + i;
55805580
5581− lpfc_sli4_node_prep(phba);
5582−
55835581 /* VPIs. */
55845582 count = phba->sli4_hba.max_cfg_param.max_vpi;
55855583 base = phba->sli4_hba.max_cfg_param.vpi_base;
@@ -5613,6 +5611,8 @@ lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba) · 27 unmodified lines
56135611 rc = -ENOMEM;
56145612 goto free_vpi_ids;
56155613 }
5614+ phba->sli4_hba.max_cfg_param.xri_used = 0;
5615+ phba->sli4_hba.xri_count = 0;
56165616 phba->sli4_hba.xri_ids = kzalloc(count *
56175617 sizeof(uint16_t),
56185618 GFP_KERNEL);
@@ -6147,6 +6147,7 @@ lpfc_sli4_hba_setup(struct lpfc_hba *phba) · 528 unmodified lines
61476147 rc = -ENODEV;
61486148 goto out_free_mbox;
61496149 }
6150+ lpfc_sli4_node_prep(phba);
61506151
61516152 /* Create all the SLI4 queues */
61526153 rc = lpfc_sli4_queue_create(phba);
@@ -7251,11 +7252,13 @@ lpfc_sli4_post_async_mbox(struct lpfc_hba *phba) · 1098 unmodified lines
72517252
72527253 out_not_finished:
72537254 spin_lock_irqsave(&phba->hbalock, iflags);
7254− mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
7255− __lpfc_mbox_cmpl_put(phba, mboxq);
7256− /* Release the token */
7257− psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
7258− phba->sli.mbox_active = NULL;
7255+ if (phba->sli.mbox_active) {
7256+ mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
7257+ __lpfc_mbox_cmpl_put(phba, mboxq);
7258+ /* Release the token */
7259+ psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
7260+ phba->sli.mbox_active = NULL;
7261+ }
72597262 spin_unlock_irqrestore(&phba->hbalock, iflags);
72607263
72617264 return MBX_NOT_FINISHED;
@@ -7743,6 +7746,7 @@ lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq, · 481 unmodified lines
77437746 if (pcmd && (*pcmd == ELS_CMD_FLOGI ||
77447747 *pcmd == ELS_CMD_SCR ||
77457748 *pcmd == ELS_CMD_FDISC ||
7749+ *pcmd == ELS_CMD_LOGO ||
77467750 *pcmd == ELS_CMD_PLOGI)) {
77477751 bf_set(els_req64_sp, &wqe->els_req, 1);
77487752 bf_set(els_req64_sid, &wqe->els_req,
@@ -8385,6 +8389,7 @@ lpfc_sli4_abts_err_handler(struct lpfc_hba *phba, · 636 unmodified lines
83858389 struct sli4_wcqe_xri_aborted *axri)
83868390 {
83878391 struct lpfc_vport *vport;
8392+ uint32_t ext_status = 0;
83888393
83898394 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
83908395 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
@@ -8396,12 +8401,20 @@ lpfc_sli4_abts_err_handler(struct lpfc_hba *phba, · 5 unmodified lines
83968401 vport = ndlp->vport;
83978402 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
83988403 "3116 Port generated FCP XRI ABORT event on "
8399− "vpi %d rpi %d xri x%x status 0x%x\n",
8404+ "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n",
84008405 ndlp->vport->vpi, ndlp->nlp_rpi,
84018406 bf_get(lpfc_wcqe_xa_xri, axri),
8402− bf_get(lpfc_wcqe_xa_status, axri));
8407+ bf_get(lpfc_wcqe_xa_status, axri),
8408+ axri->parameter);
84038409
8404− if (bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT)
8410+ /*
8411+ * Catch the ABTS protocol failure case. Older OCe FW releases returned
8412+ * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and
8413+ * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT.
8414+ */
8415+ ext_status = axri->parameter & WCQE_PARAM_MASK;
8416+ if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) &&
8417+ ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0)))
84058418 lpfc_sli_abts_recover_port(vport, ndlp);
84068419 }
84078420
@@ -9807,12 +9820,11 @@ lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba) · 1399 unmodified lines
98079820 unsigned long timeout;
98089821
98099822 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
9823+
98109824 spin_lock_irq(&phba->hbalock);
98119825 psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
9812− spin_unlock_irq(&phba->hbalock);
98139826
98149827 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
9815− spin_lock_irq(&phba->hbalock);
98169828 /* Determine how long we might wait for the active mailbox
98179829 * command to be gracefully completed by firmware.
98189830 */
@@ -9831,7 +9843,9 @@ lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba) · 12 unmodified lines
98319843 */
98329844 break;
98339845 }
9834− }
9846+ } else
9847+ spin_unlock_irq(&phba->hbalock);
9848+
98359849 lpfc_sli_mbox_sys_flush(phba);
98369850 }
98379851
@@ -13272,7 +13286,7 @@ lpfc_sli4_post_els_sgl_list_ext(struct lpfc_hba *phba) · 3434 unmodified lines
1327213286 LPFC_MBOXQ_t *mbox;
1327313287 uint32_t reqlen, alloclen, index;
1327413288 uint32_t mbox_tmo;
13275− uint16_t rsrc_start, rsrc_size, els_xri_cnt;
13289+ uint16_t rsrc_start, rsrc_size, els_xri_cnt, post_els_xri_cnt;
1327613290 uint16_t xritag_start = 0, lxri = 0;
1327713291 struct lpfc_rsrc_blks *rsrc_blk;
1327813292 int cnt, ttl_cnt, rc = 0;
@@ -13294,6 +13308,7 @@ lpfc_sli4_post_els_sgl_list_ext(struct lpfc_hba *phba) · 15 unmodified lines
1329413308
1329513309 cnt = 0;
1329613310 ttl_cnt = 0;
13311+ post_els_xri_cnt = els_xri_cnt;
1329713312 list_for_each_entry(rsrc_blk, &phba->sli4_hba.lpfc_xri_blk_list,
1329813313 list) {
1329913314 rsrc_start = rsrc_blk->rsrc_start;
@@ -13303,11 +13318,12 @@ lpfc_sli4_post_els_sgl_list_ext(struct lpfc_hba *phba) · 3 unmodified lines
1330313318 "3014 Working ELS Extent start %d, cnt %d\n",
1330413319 rsrc_start, rsrc_size);
1330513320
13306− loop_cnt = min(els_xri_cnt, rsrc_size);
13307− if (ttl_cnt + loop_cnt >= els_xri_cnt) {
13308− loop_cnt = els_xri_cnt - ttl_cnt;
13309− ttl_cnt = els_xri_cnt;
13310− }
13321+ loop_cnt = min(post_els_xri_cnt, rsrc_size);
13322+ if (loop_cnt < post_els_xri_cnt) {
13323+ post_els_xri_cnt -= loop_cnt;
13324+ ttl_cnt += loop_cnt;
13325+ } else
13326+ ttl_cnt += post_els_xri_cnt;
1331113327
1331213328 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1331313329 if (!mbox)
@@ -14203,15 +14219,14 @@ lpfc_sli4_seq_abort_rsp(struct lpfc_hba *phba, · 889 unmodified lines
1420314219 * field and RX_ID from ABTS for RX_ID field.
1420414220 */
1420514221 bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_RSP);
14206− bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid);
1420714222 } else {
1420814223 /* ABTS sent by initiator to CT exchange, construction
1420914224 * of BA_ACC will need to allocate a new XRI as for the
14210− * XRI_TAG and RX_ID fields.
14225+ * XRI_TAG field.
1421114226 */
1421214227 bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_INT);
14213− bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, NO_XRI);
1421414228 }
14229+ bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid);
1421514230 bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid);
1421614231
1421714232 /* Xmit CT abts response on exchange <xid> */
@@ -15042,6 +15057,7 @@ lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) · 824 unmodified lines
1504215057 LPFC_MBOXQ_t *mboxq;
1504315058
1504415059 phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
15060+ phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag;
1504515061 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1504615062 if (!mboxq) {
1504715063 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
drivers/scsi/lpfc/lpfc_version.h+2−2
@@ -1,7 +1,7 @@
11 /*******************************************************************
22 * This file is part of the Emulex Linux Device Driver for *
33 * Fibre Channel Host Bus Adapters. *
4− * Copyright (C) 2004-2011 Emulex. All rights reserved. *
4+ * Copyright (C) 2004-2012 Emulex. All rights reserved. *
55 * EMULEX and SLI are trademarks of Emulex. *
66 * www.emulex.com *
77 * *
@@ -18,7 +18,7 @@ · 10 unmodified lines
1818 * included with this package. *
1919 *******************************************************************/
2020
21−#define LPFC_DRIVER_VERSION "8.3.29"
21+#define LPFC_DRIVER_VERSION "8.3.30"
2222 #define LPFC_DRIVER_NAME "lpfc"
2323 #define LPFC_SP_DRIVER_HANDLER_NAME "lpfc:sp"
2424 #define LPFC_FP_DRIVER_HANDLER_NAME "lpfc:fp"
drivers/scsi/mpt2sas/mpt2sas_base.c+2−4
@@ -657,7 +657,7 @@ _base_sas_log_info(struct MPT2SAS_ADAPTER *ioc , u32 log_info) · 656 unmodified lines
657657 return;
658658
659659 /* eat the loginfos associated with task aborts */
660− if (ioc->ignore_loginfos && (log_info == 30050000 || log_info ==
660+ if (ioc->ignore_loginfos && (log_info == 0x30050000 || log_info ==
661661 0x31140000 || log_info == 0x31130000))
662662 return;
663663
@@ -2060,12 +2060,10 @@ _base_display_ioc_capabilities(struct MPT2SAS_ADAPTER *ioc) · 1396 unmodified lines
20602060 {
20612061 int i = 0;
20622062 char desc[16];
2063− u8 revision;
20642063 u32 iounit_pg1_flags;
20652064 u32 bios_version;
20662065
20672066 bios_version = le32_to_cpu(ioc->bios_pg3.BiosVersion);
2068− pci_read_config_byte(ioc->pdev, PCI_CLASS_REVISION, &revision);
20692067 strncpy(desc, ioc->manu_pg0.ChipName, 16);
20702068 printk(MPT2SAS_INFO_FMT "%s: FWVersion(%02d.%02d.%02d.%02d), "
20712069 "ChipRevision(0x%02x), BiosVersion(%02d.%02d.%02d.%02d)\n",
@@ -2074,7 +2072,7 @@ _base_display_ioc_capabilities(struct MPT2SAS_ADAPTER *ioc) · 2 unmodified lines
20742072 (ioc->facts.FWVersion.Word & 0x00FF0000) >> 16,
20752073 (ioc->facts.FWVersion.Word & 0x0000FF00) >> 8,
20762074 ioc->facts.FWVersion.Word & 0x000000FF,
2077− revision,
2075+ ioc->pdev->revision,
20782076 (bios_version & 0xFF000000) >> 24,
20792077 (bios_version & 0x00FF0000) >> 16,
20802078 (bios_version & 0x0000FF00) >> 8,
drivers/scsi/mpt2sas/mpt2sas_ctl.c+1−3
@@ -1026,7 +1026,6 @@ _ctl_getiocinfo(void __user *arg) · 1025 unmodified lines
10261026 {
10271027 struct mpt2_ioctl_iocinfo karg;
10281028 struct MPT2SAS_ADAPTER *ioc;
1029− u8 revision;
10301029
10311030 if (copy_from_user(&karg, arg, sizeof(karg))) {
10321031 printk(KERN_ERR "failure at %s:%d/%s()!\n",
@@ -1046,8 +1045,7 @@ _ctl_getiocinfo(void __user *arg) · 13 unmodified lines
10461045 karg.adapter_type = MPT2_IOCTL_INTERFACE_SAS2;
10471046 if (ioc->pfacts)
10481047 karg.port_number = ioc->pfacts[0].PortNumber;
1049− pci_read_config_byte(ioc->pdev, PCI_CLASS_REVISION, &revision);
1050− karg.hw_rev = revision;
1048+ karg.hw_rev = ioc->pdev->revision;
10511049 karg.pci_id = ioc->pdev->device;
10521050 karg.subsystem_device = ioc->pdev->subsystem_device;
10531051 karg.subsystem_vendor = ioc->pdev->subsystem_vendor;
drivers/scsi/pm8001/pm8001_hwi.c+10−8
@@ -2093,6 +2093,7 @@ mpi_sata_completion(struct pm8001_hba_info *pm8001_ha, void *piomb) · 2092 unmodified lines
20932093 struct ata_task_resp *resp ;
20942094 u32 *sata_resp;
20952095 struct pm8001_device *pm8001_dev;
2096+ unsigned long flags;
20962097
20972098 psataPayload = (struct sata_completion_resp *)(piomb + 4);
20982099 status = le32_to_cpu(psataPayload->status);
@@ -2382,26 +2383,26 @@ mpi_sata_completion(struct pm8001_hba_info *pm8001_ha, void *piomb) · 283 unmodified lines
23822383 ts->stat = SAS_DEV_NO_RESPONSE;
23832384 break;
23842385 }
2385− spin_lock_irq(&t->task_state_lock);
2386+ spin_lock_irqsave(&t->task_state_lock, flags);
23862387 t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
23872388 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
23882389 t->task_state_flags |= SAS_TASK_STATE_DONE;
23892390 if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
2390− spin_unlock_irq(&t->task_state_lock);
2391+ spin_unlock_irqrestore(&t->task_state_lock, flags);
23912392 PM8001_FAIL_DBG(pm8001_ha,
23922393 pm8001_printk("task 0x%p done with io_status 0x%x"
23932394 " resp 0x%x stat 0x%x but aborted by upper layer!\n",
23942395 t, status, ts->resp, ts->stat));
23952396 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
23962397 } else if (t->uldd_task) {
2397− spin_unlock_irq(&t->task_state_lock);
2398+ spin_unlock_irqrestore(&t->task_state_lock, flags);
23982399 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
23992400 mb();/* ditto */
24002401 spin_unlock_irq(&pm8001_ha->lock);
24012402 t->task_done(t);
24022403 spin_lock_irq(&pm8001_ha->lock);
24032404 } else if (!t->uldd_task) {
2404− spin_unlock_irq(&t->task_state_lock);
2405+ spin_unlock_irqrestore(&t->task_state_lock, flags);
24052406 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
24062407 mb();/*ditto*/
24072408 spin_unlock_irq(&pm8001_ha->lock);
@@ -2423,6 +2424,7 @@ static void mpi_sata_event(struct pm8001_hba_info *pm8001_ha , void *piomb) · 15 unmodified lines
24232424 u32 tag = le32_to_cpu(psataPayload->tag);
24242425 u32 port_id = le32_to_cpu(psataPayload->port_id);
24252426 u32 dev_id = le32_to_cpu(psataPayload->device_id);
2427+ unsigned long flags;
24262428
24272429 ccb = &pm8001_ha->ccb_info[tag];
24282430 t = ccb->task;
@@ -2593,26 +2595,26 @@ static void mpi_sata_event(struct pm8001_hba_info *pm8001_ha , void *piomb) · 164 unmodified lines
25932595 ts->stat = SAS_OPEN_TO;
25942596 break;
25952597 }
2596− spin_lock_irq(&t->task_state_lock);
2598+ spin_lock_irqsave(&t->task_state_lock, flags);
25972599 t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
25982600 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
25992601 t->task_state_flags |= SAS_TASK_STATE_DONE;
26002602 if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
2601− spin_unlock_irq(&t->task_state_lock);
2603+ spin_unlock_irqrestore(&t->task_state_lock, flags);
26022604 PM8001_FAIL_DBG(pm8001_ha,
26032605 pm8001_printk("task 0x%p done with io_status 0x%x"
26042606 " resp 0x%x stat 0x%x but aborted by upper layer!\n",
26052607 t, event, ts->resp, ts->stat));
26062608 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
26072609 } else if (t->uldd_task) {
2608− spin_unlock_irq(&t->task_state_lock);
2610+ spin_unlock_irqrestore(&t->task_state_lock, flags);
26092611 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
26102612 mb();/* ditto */
26112613 spin_unlock_irq(&pm8001_ha->lock);
26122614 t->task_done(t);
26132615 spin_lock_irq(&pm8001_ha->lock);
26142616 } else if (!t->uldd_task) {
2615− spin_unlock_irq(&t->task_state_lock);
2617+ spin_unlock_irqrestore(&t->task_state_lock, flags);
26162618 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
26172619 mb();/*ditto*/
26182620 spin_unlock_irq(&pm8001_ha->lock);
drivers/scsi/qla4xxx/ql4_isr.c+2−2
@@ -431,9 +431,9 @@ static void qla4xxx_mbox_status_entry(struct scsi_qla_host *ha, · 430 unmodified lines
431431 mbox_sts_entry->out_mbox[6]));
432432
433433 if (mbox_sts_entry->out_mbox[0] == MBOX_STS_COMMAND_COMPLETE)
434− status = QLA_SUCCESS;
434+ status = ISCSI_PING_SUCCESS;
435435 else
436− status = QLA_ERROR;
436+ status = mbox_sts_entry->out_mbox[6];
437437
438438 data_size = sizeof(mbox_sts_entry->out_mbox);
439439
drivers/scsi/qla4xxx/ql4_os.c+4−6
@@ -834,7 +834,7 @@ static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc) · 833 unmodified lines
834834 static void qla4xxx_set_port_speed(struct Scsi_Host *shost)
835835 {
836836 struct scsi_qla_host *ha = to_qla_host(shost);
837− struct iscsi_cls_host *ihost = shost_priv(shost);
837+ struct iscsi_cls_host *ihost = shost->shost_data;
838838 uint32_t speed = ISCSI_PORT_SPEED_UNKNOWN;
839839
840840 qla4xxx_get_firmware_state(ha);
@@ -859,7 +859,7 @@ static void qla4xxx_set_port_speed(struct Scsi_Host *shost) · 18 unmodified lines
859859 static void qla4xxx_set_port_state(struct Scsi_Host *shost)
860860 {
861861 struct scsi_qla_host *ha = to_qla_host(shost);
862− struct iscsi_cls_host *ihost = shost_priv(shost);
862+ struct iscsi_cls_host *ihost = shost->shost_data;
863863 uint32_t state = ISCSI_PORT_STATE_DOWN;
864864
865865 if (test_bit(AF_LINK_UP, &ha->flags))
@@ -3445,7 +3445,6 @@ static void qla4xxx_free_adapter(struct scsi_qla_host *ha) · 2579 unmodified lines
34453445 int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
34463446 {
34473447 int status = 0;
3448− uint8_t revision_id;
34493448 unsigned long mem_base, mem_len, db_base, db_len;
34503449 struct pci_dev *pdev = ha->pdev;
34513450
@@ -3457,10 +3456,9 @@ int qla4_8xxx_iospace_config(struct scsi_qla_host *ha) · 5 unmodified lines
34573456 goto iospace_error_exit;
34583457 }
34593458
3460− pci_read_config_byte(pdev, PCI_REVISION_ID, &revision_id);
34613459 DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
3462− __func__, revision_id));
3463− ha->revision_id = revision_id;
3460+ __func__, pdev->revision));
3461+ ha->revision_id = pdev->revision;
34643462
34653463 /* remap phys address */
34663464 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
drivers/scsi/qla4xxx/ql4_version.h+1−1
@@ -5,4 +5,4 @@ · 4 unmodified lines
55 * See LICENSE.qla4xxx for copyright and licensing details.
66 */
77
8−#define QLA4XXX_DRIVER_VERSION "5.02.00-k15"
8+#define QLA4XXX_DRIVER_VERSION "5.02.00-k16"
drivers/scsi/scsi_debug.c+20−7
@@ -101,6 +101,7 @@ static const char * scsi_debug_version_date = "20100324"; · 100 unmodified lines
101101 #define DEF_LBPU 0
102102 #define DEF_LBPWS 0
103103 #define DEF_LBPWS10 0
104+#define DEF_LBPRZ 1
104105 #define DEF_LOWEST_ALIGNED 0
105106 #define DEF_NO_LUN_0 0
106107 #define DEF_NUM_PARTS 0
@@ -186,6 +187,7 @@ static int scsi_debug_vpd_use_hostno = DEF_VPD_USE_HOSTNO; · 79 unmodified lines
186187 static unsigned int scsi_debug_lbpu = DEF_LBPU;
187188 static unsigned int scsi_debug_lbpws = DEF_LBPWS;
188189 static unsigned int scsi_debug_lbpws10 = DEF_LBPWS10;
190+static unsigned int scsi_debug_lbprz = DEF_LBPRZ;
189191 static unsigned int scsi_debug_unmap_alignment = DEF_UNMAP_ALIGNMENT;
190192 static unsigned int scsi_debug_unmap_granularity = DEF_UNMAP_GRANULARITY;
191193 static unsigned int scsi_debug_unmap_max_blocks = DEF_UNMAP_MAX_BLOCKS;
@@ -775,10 +777,10 @@ static int inquiry_evpd_b1(unsigned char *arr) · 583 unmodified lines
775777 return 0x3c;
776778 }
777779
778−/* Thin provisioning VPD page (SBC-3) */
780+/* Logical block provisioning VPD page (SBC-3) */
779781 static int inquiry_evpd_b2(unsigned char *arr)
780782 {
781− memset(arr, 0, 0x8);
783+ memset(arr, 0, 0x4);
782784 arr[0] = 0; /* threshold exponent */
783785
784786 if (scsi_debug_lbpu)
@@ -790,7 +792,10 @@ static int inquiry_evpd_b2(unsigned char *arr) · 5 unmodified lines
790792 if (scsi_debug_lbpws10)
791793 arr[1] |= 1 << 5;
792794
793− return 0x8;
795+ if (scsi_debug_lbprz)
796+ arr[1] |= 1 << 2;
797+
798+ return 0x4;
794799 }
795800
796801 #define SDEBUG_LONG_INQ_SZ 96
@@ -1071,8 +1076,11 @@ static int resp_readcap16(struct scsi_cmnd * scp, · 274 unmodified lines
10711076 arr[13] = scsi_debug_physblk_exp & 0xf;
10721077 arr[14] = (scsi_debug_lowest_aligned >> 8) & 0x3f;
10731078
1074− if (scsi_debug_lbp())
1079+ if (scsi_debug_lbp()) {
10751080 arr[14] |= 0x80; /* LBPME */
1081+ if (scsi_debug_lbprz)
1082+ arr[14] |= 0x40; /* LBPRZ */
1083+ }
10761084
10771085 arr[15] = scsi_debug_lowest_aligned & 0xff;
10781086
@@ -2046,10 +2054,13 @@ static void unmap_region(sector_t lba, unsigned int len) · 967 unmodified lines
20462054 block = lba + alignment;
20472055 rem = do_div(block, granularity);
20482056
2049− if (rem == 0 && lba + granularity <= end &&
2050− block < map_size)
2057+ if (rem == 0 && lba + granularity <= end && block < map_size) {
20512058 clear_bit(block, map_storep);
2052−
2059+ if (scsi_debug_lbprz)
2060+ memset(fake_storep +
2061+ block * scsi_debug_sector_size, 0,
2062+ scsi_debug_sector_size);
2063+ }
20532064 lba += granularity - rem;
20542065 }
20552066 }
@@ -2731,6 +2742,7 @@ module_param_named(guard, scsi_debug_guard, int, S_IRUGO); · 675 unmodified lines
27312742 module_param_named(lbpu, scsi_debug_lbpu, int, S_IRUGO);
27322743 module_param_named(lbpws, scsi_debug_lbpws, int, S_IRUGO);
27332744 module_param_named(lbpws10, scsi_debug_lbpws10, int, S_IRUGO);
2745+module_param_named(lbprz, scsi_debug_lbprz, int, S_IRUGO);
27342746 module_param_named(lowest_aligned, scsi_debug_lowest_aligned, int, S_IRUGO);
27352747 module_param_named(max_luns, scsi_debug_max_luns, int, S_IRUGO | S_IWUSR);
27362748 module_param_named(max_queue, scsi_debug_max_queue, int, S_IRUGO | S_IWUSR);
@@ -2772,6 +2784,7 @@ MODULE_PARM_DESC(guard, "protection checksum: 0=crc, 1=ip (def=0)"); · 35 unmodified lines
27722784 MODULE_PARM_DESC(lbpu, "enable LBP, support UNMAP command (def=0)");
27732785 MODULE_PARM_DESC(lbpws, "enable LBP, support WRITE SAME(16) with UNMAP bit (def=0)");
27742786 MODULE_PARM_DESC(lbpws10, "enable LBP, support WRITE SAME(10) with UNMAP bit (def=0)");
2787+MODULE_PARM_DESC(lbprz, "unmapped blocks return 0 on read (def=1)");
27752788 MODULE_PARM_DESC(lowest_aligned, "lowest aligned lba (def=0)");
27762789 MODULE_PARM_DESC(max_luns, "number of LUNs per target to simulate(def=1)");
27772790 MODULE_PARM_DESC(max_queue, "max number of queued commands (1 to 255(def))");
drivers/scsi/scsi_transport_iscsi.c+4−4
@@ -1486,7 +1486,7 @@ void iscsi_post_host_event(uint32_t host_no, struct iscsi_transport *transport, · 1485 unmodified lines
14861486 struct iscsi_uevent *ev;
14871487 int len = NLMSG_SPACE(sizeof(*ev) + data_size);
14881488
1489− skb = alloc_skb(len, GFP_KERNEL);
1489+ skb = alloc_skb(len, GFP_NOIO);
14901490 if (!skb) {
14911491 printk(KERN_ERR "gracefully ignored host event (%d):%d OOM\n",
14921492 host_no, code);
@@ -1504,7 +1504,7 @@ void iscsi_post_host_event(uint32_t host_no, struct iscsi_transport *transport, · 11 unmodified lines
15041504 if (data_size)
15051505 memcpy((char *)ev + sizeof(*ev), data, data_size);
15061506
1507− iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_KERNEL);
1507+ iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_NOIO);
15081508 }
15091509 EXPORT_SYMBOL_GPL(iscsi_post_host_event);
15101510
@@ -1517,7 +1517,7 @@ void iscsi_ping_comp_event(uint32_t host_no, struct iscsi_transport *transport, · 6 unmodified lines
15171517 struct iscsi_uevent *ev;
15181518 int len = NLMSG_SPACE(sizeof(*ev) + data_size);
15191519
1520− skb = alloc_skb(len, GFP_KERNEL);
1520+ skb = alloc_skb(len, GFP_NOIO);
15211521 if (!skb) {
15221522 printk(KERN_ERR "gracefully ignored ping comp: OOM\n");
15231523 return;
@@ -1533,7 +1533,7 @@ void iscsi_ping_comp_event(uint32_t host_no, struct iscsi_transport *transport, · 9 unmodified lines
15331533 ev->r.ping_comp.data_size = data_size;
15341534 memcpy((char *)ev + sizeof(*ev), data, data_size);
15351535
1536− iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_KERNEL);
1536+ iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_NOIO);
15371537 }
15381538 EXPORT_SYMBOL_GPL(iscsi_ping_comp_event);
15391539
drivers/scsi/sd.c+10−5
@@ -664,7 +664,7 @@ static void sd_unprep_fn(struct request_queue *q, struct request *rq) · 663 unmodified lines
664664 }
665665
666666 /**
667− * sd_init_command - build a scsi (read or write) command from
667+ * sd_prep_fn - build a scsi (read or write) command from
668668 * information in the request structure.
669669 * @SCpnt: pointer to mid-level's per scsi command structure that
670670 * contains request and into which the scsi command is written
@@ -711,7 +711,7 @@ static int sd_prep_fn(struct request_queue *q, struct request *rq) · 40 unmodified lines
711711 ret = BLKPREP_KILL;
712712
713713 SCSI_LOG_HLQUEUE(1, scmd_printk(KERN_INFO, SCpnt,
714− "sd_init_command: block=%llu, "
714+ "sd_prep_fn: block=%llu, "
715715 "count=%d\n",
716716 (unsigned long long)block,
717717 this_count));
@@ -1212,9 +1212,14 @@ static unsigned int sd_check_events(struct gendisk *disk, unsigned int clearing) · 494 unmodified lines
12121212 retval = -ENODEV;
12131213
12141214 if (scsi_block_when_processing_errors(sdp)) {
1215+ retval = scsi_autopm_get_device(sdp);
1216+ if (retval)
1217+ goto out;
1218+
12151219 sshdr = kzalloc(sizeof(*sshdr), GFP_KERNEL);
12161220 retval = scsi_test_unit_ready(sdp, SD_TIMEOUT, SD_MAX_RETRIES,
12171221 sshdr);
1222+ scsi_autopm_put_device(sdp);
12181223 }
12191224
12201225 /* failed to execute TUR, assume media not present */
@@ -2644,8 +2649,8 @@ static void sd_probe_async(void *data, async_cookie_t cookie) · 1423 unmodified lines
26442649 * (e.g. /dev/sda). More precisely it is the block device major
26452650 * and minor number that is chosen here.
26462651 *
2647− * Assume sd_attach is not re-entrant (for time being)
2648− * Also think about sd_attach() and sd_remove() running coincidentally.
2652+ * Assume sd_probe is not re-entrant (for time being)
2653+ * Also think about sd_probe() and sd_remove() running coincidentally.
26492654 **/
26502655 static int sd_probe(struct device *dev)
26512656 {
@@ -2660,7 +2665,7 @@ static int sd_probe(struct device *dev) · 8 unmodified lines
26602665 goto out;
26612666
26622667 SCSI_LOG_HLQUEUE(3, sdev_printk(KERN_INFO, sdp,
2663− "sd_attach\n"));
2668+ "sd_probe\n"));
26642669
26652670 error = -ENOMEM;
26662671 sdkp = kzalloc(sizeof(*sdkp), GFP_KERNEL);
drivers/scsi/st.c+18−3
@@ -1105,6 +1105,12 @@ static int check_tape(struct scsi_tape *STp, struct file *filp) · 1104 unmodified lines
11051105 STp->drv_buffer));
11061106 }
11071107 STp->drv_write_prot = ((STp->buffer)->b_data[2] & 0x80) != 0;
1108+ if (!STp->drv_buffer && STp->immediate_filemark) {
1109+ printk(KERN_WARNING
1110+ "%s: non-buffered tape: disabling writing immediate filemarks\n",
1111+ name);
1112+ STp->immediate_filemark = 0;
1113+ }
11081114 }
11091115 st_release_request(SRpnt);
11101116 SRpnt = NULL;
@@ -1313,6 +1319,8 @@ static int st_flush(struct file *filp, fl_owner_t id) · 202 unmodified lines
13131319
13141320 memset(cmd, 0, MAX_COMMAND_SIZE);
13151321 cmd[0] = WRITE_FILEMARKS;
1322+ if (STp->immediate_filemark)
1323+ cmd[1] = 1;
13161324 cmd[4] = 1 + STp->two_fm;
13171325
13181326 SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE,
@@ -2180,8 +2188,9 @@ static void st_log_options(struct scsi_tape * STp, struct st_modedef * STm, char · 861 unmodified lines
21802188 name, STm->defaults_for_writes, STp->omit_blklims, STp->can_partitions,
21812189 STp->scsi2_logical);
21822190 printk(KERN_INFO
2183− "%s: sysv: %d nowait: %d sili: %d\n", name, STm->sysv, STp->immediate,
2184− STp->sili);
2191+ "%s: sysv: %d nowait: %d sili: %d nowait_filemark: %d\n",
2192+ name, STm->sysv, STp->immediate, STp->sili,
2193+ STp->immediate_filemark);
21852194 printk(KERN_INFO "%s: debugging: %d\n",
21862195 name, debugging);
21872196 }
@@ -2223,6 +2232,7 @@ static int st_set_options(struct scsi_tape *STp, long options) · 35 unmodified lines
22232232 STp->can_partitions = (options & MT_ST_CAN_PARTITIONS) != 0;
22242233 STp->scsi2_logical = (options & MT_ST_SCSI2LOGICAL) != 0;
22252234 STp->immediate = (options & MT_ST_NOWAIT) != 0;
2235+ STp->immediate_filemark = (options & MT_ST_NOWAIT_EOF) != 0;
22262236 STm->sysv = (options & MT_ST_SYSV) != 0;
22272237 STp->sili = (options & MT_ST_SILI) != 0;
22282238 DEB( debugging = (options & MT_ST_DEBUGGING) != 0;
@@ -2254,6 +2264,8 @@ static int st_set_options(struct scsi_tape *STp, long options) · 25 unmodified lines
22542264 STp->scsi2_logical = value;
22552265 if ((options & MT_ST_NOWAIT) != 0)
22562266 STp->immediate = value;
2267+ if ((options & MT_ST_NOWAIT_EOF) != 0)
2268+ STp->immediate_filemark = value;
22572269 if ((options & MT_ST_SYSV) != 0)
22582270 STm->sysv = value;
22592271 if ((options & MT_ST_SILI) != 0)
@@ -2713,7 +2725,8 @@ static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned lon · 453 unmodified lines
27132725 cmd[0] = WRITE_FILEMARKS;
27142726 if (cmd_in == MTWSM)
27152727 cmd[1] = 2;
2716− if (cmd_in == MTWEOFI)
2728+ if (cmd_in == MTWEOFI ||
2729+ (cmd_in == MTWEOF && STp->immediate_filemark))
27172730 cmd[1] |= 1;
27182731 cmd[2] = (arg >> 16);
27192732 cmd[3] = (arg >> 8);
@@ -4092,6 +4105,7 @@ static int st_probe(struct device *dev) · 1372 unmodified lines
40924105 tpnt->scsi2_logical = ST_SCSI2LOGICAL;
40934106 tpnt->sili = ST_SILI;
40944107 tpnt->immediate = ST_NOWAIT;
4108+ tpnt->immediate_filemark = 0;
40954109 tpnt->default_drvbuffer = 0xff; /* No forced buffering */
40964110 tpnt->partition = 0;
40974111 tpnt->new_partition = 0;
@@ -4477,6 +4491,7 @@ st_options_show(struct device *dev, struct device_attribute *attr, char *buf) · 379 unmodified lines
44774491 options |= STp->scsi2_logical ? MT_ST_SCSI2LOGICAL : 0;
44784492 options |= STm->sysv ? MT_ST_SYSV : 0;
44794493 options |= STp->immediate ? MT_ST_NOWAIT : 0;
4494+ options |= STp->immediate_filemark ? MT_ST_NOWAIT_EOF : 0;
44804495 options |= STp->sili ? MT_ST_SILI : 0;
44814496
44824497 l = snprintf(buf, PAGE_SIZE, "0x%08x\n", options);
drivers/scsi/st.h+1−0
@@ -120,6 +120,7 @@ struct scsi_tape { · 119 unmodified lines
120120 unsigned char c_algo; /* compression algorithm */
121121 unsigned char pos_unknown; /* after reset position unknown */
122122 unsigned char sili; /* use SILI when reading in variable b mode */
123+ unsigned char immediate_filemark; /* write filemark immediately */
123124 int tape_type;
124125 int long_timeout; /* timeout for commands known to take long time */
125126
drivers/scsi/ufs/Kconfig+49−0
@@ -0,0 +1,49 @@
1+#
2+# Kernel configuration file for the UFS Host Controller
3+#
4+# This code is based on drivers/scsi/ufs/Kconfig
5+# Copyright (C) 2011 Samsung Samsung India Software Operations
6+#
7+# Santosh Yaraganavi <santosh.sy@samsung.com>
8+# Vinayak Holikatti <h.vinayak@samsung.com>
9+
10+# This program is free software; you can redistribute it and/or
11+# modify it under the terms of the GNU General Public License
12+# as published by the Free Software Foundation; either version 2
13+# of the License, or (at your option) any later version.
14+
15+# This program is distributed in the hope that it will be useful,
16+# but WITHOUT ANY WARRANTY; without even the implied warranty of
17+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+# GNU General Public License for more details.
19+
20+# NO WARRANTY
21+# THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
22+# CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
23+# LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
24+# MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
25+# solely responsible for determining the appropriateness of using and
26+# distributing the Program and assumes all risks associated with its
27+# exercise of rights under this Agreement, including but not limited to
28+# the risks and costs of program errors, damage to or loss of data,
29+# programs or equipment, and unavailability or interruption of operations.
30+
31+# DISCLAIMER OF LIABILITY
32+# NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
33+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34+# DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
35+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36+# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37+# USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
38+# HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
39+
40+# You should have received a copy of the GNU General Public License
41+# along with this program; if not, write to the Free Software
42+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
43+# USA.
44+
45+config SCSI_UFSHCD
46+ tristate "Universal Flash Storage host controller driver"
47+ depends on PCI && SCSI
48+ ---help---
49+ This is a generic driver which supports PCIe UFS Host controllers.
drivers/scsi/ufs/Makefile+2−0
@@ -0,0 +1,2 @@
1+# UFSHCD makefile
2+obj-$(CONFIG_SCSI_UFSHCD) += ufshcd.o
drivers/scsi/ufs/ufs.h+207−0
@@ -0,0 +1,207 @@
1+/*
2+ * Universal Flash Storage Host controller driver
3+ *
4+ * This code is based on drivers/scsi/ufs/ufs.h
5+ * Copyright (C) 2011-2012 Samsung India Software Operations
6+ *
7+ * Santosh Yaraganavi <santosh.sy@samsung.com>
8+ * Vinayak Holikatti <h.vinayak@samsung.com>
9+ *
10+ * This program is free software; you can redistribute it and/or
11+ * modify it under the terms of the GNU General Public License
12+ * as published by the Free Software Foundation; either version 2
13+ * of the License, or (at your option) any later version.
14+ *
15+ * This program is distributed in the hope that it will be useful,
16+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+ * GNU General Public License for more details.
19+ *
20+ * NO WARRANTY
21+ * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
22+ * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
23+ * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
24+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
25+ * solely responsible for determining the appropriateness of using and
26+ * distributing the Program and assumes all risks associated with its
27+ * exercise of rights under this Agreement, including but not limited to
28+ * the risks and costs of program errors, damage to or loss of data,
29+ * programs or equipment, and unavailability or interruption of operations.
30+
31+ * DISCLAIMER OF LIABILITY
32+ * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
33+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34+ * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
35+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37+ * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
38+ * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
39+
40+ * You should have received a copy of the GNU General Public License
41+ * along with this program; if not, write to the Free Software
42+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
43+ * USA.
44+ */
45+
46+#ifndef _UFS_H
47+#define _UFS_H
48+
49+#define MAX_CDB_SIZE 16
50+
51+#define UPIU_HEADER_DWORD(byte3, byte2, byte1, byte0)\
52+ ((byte3 << 24) | (byte2 << 16) |\
53+ (byte1 << 8) | (byte0))
54+
55+/*
56+ * UFS Protocol Information Unit related definitions
57+ */
58+
59+/* Task management functions */
60+enum {
61+ UFS_ABORT_TASK = 0x01,
62+ UFS_ABORT_TASK_SET = 0x02,
63+ UFS_CLEAR_TASK_SET = 0x04,
64+ UFS_LOGICAL_RESET = 0x08,
65+ UFS_QUERY_TASK = 0x80,
66+ UFS_QUERY_TASK_SET = 0x81,
67+};
68+
69+/* UTP UPIU Transaction Codes Initiator to Target */
70+enum {
71+ UPIU_TRANSACTION_NOP_OUT = 0x00,
72+ UPIU_TRANSACTION_COMMAND = 0x01,
73+ UPIU_TRANSACTION_DATA_OUT = 0x02,
74+ UPIU_TRANSACTION_TASK_REQ = 0x04,
75+ UPIU_TRANSACTION_QUERY_REQ = 0x26,
76+};
77+
78+/* UTP UPIU Transaction Codes Target to Initiator */
79+enum {
80+ UPIU_TRANSACTION_NOP_IN = 0x20,
81+ UPIU_TRANSACTION_RESPONSE = 0x21,
82+ UPIU_TRANSACTION_DATA_IN = 0x22,
83+ UPIU_TRANSACTION_TASK_RSP = 0x24,
84+ UPIU_TRANSACTION_READY_XFER = 0x31,
85+ UPIU_TRANSACTION_QUERY_RSP = 0x36,
86+};
87+
88+/* UPIU Read/Write flags */
89+enum {
90+ UPIU_CMD_FLAGS_NONE = 0x00,
91+ UPIU_CMD_FLAGS_WRITE = 0x20,
92+ UPIU_CMD_FLAGS_READ = 0x40,
93+};
94+
95+/* UPIU Task Attributes */
96+enum {
97+ UPIU_TASK_ATTR_SIMPLE = 0x00,
98+ UPIU_TASK_ATTR_ORDERED = 0x01,
99+ UPIU_TASK_ATTR_HEADQ = 0x02,
100+ UPIU_TASK_ATTR_ACA = 0x03,
101+};
102+
103+/* UTP QUERY Transaction Specific Fields OpCode */
104+enum {
105+ UPIU_QUERY_OPCODE_NOP = 0x0,
106+ UPIU_QUERY_OPCODE_READ_DESC = 0x1,
107+ UPIU_QUERY_OPCODE_WRITE_DESC = 0x2,
108+ UPIU_QUERY_OPCODE_READ_ATTR = 0x3,
109+ UPIU_QUERY_OPCODE_WRITE_ATTR = 0x4,
110+ UPIU_QUERY_OPCODE_READ_FLAG = 0x5,
111+ UPIU_QUERY_OPCODE_SET_FLAG = 0x6,
112+ UPIU_QUERY_OPCODE_CLEAR_FLAG = 0x7,
113+ UPIU_QUERY_OPCODE_TOGGLE_FLAG = 0x8,
114+};
115+
116+/* UTP Transfer Request Command Type (CT) */
117+enum {
118+ UPIU_COMMAND_SET_TYPE_SCSI = 0x0,
119+ UPIU_COMMAND_SET_TYPE_UFS = 0x1,
120+ UPIU_COMMAND_SET_TYPE_QUERY = 0x2,
121+};
122+
123+enum {
124+ MASK_SCSI_STATUS = 0xFF,
125+ MASK_TASK_RESPONSE = 0xFF00,
126+ MASK_RSP_UPIU_RESULT = 0xFFFF,
127+};
128+
129+/* Task management service response */
130+enum {
131+ UPIU_TASK_MANAGEMENT_FUNC_COMPL = 0x00,
132+ UPIU_TASK_MANAGEMENT_FUNC_NOT_SUPPORTED = 0x04,
133+ UPIU_TASK_MANAGEMENT_FUNC_SUCCEEDED = 0x08,
134+ UPIU_TASK_MANAGEMENT_FUNC_FAILED = 0x05,
135+ UPIU_INCORRECT_LOGICAL_UNIT_NO = 0x09,
136+};
137+/**
138+ * struct utp_upiu_header - UPIU header structure
139+ * @dword_0: UPIU header DW-0
140+ * @dword_1: UPIU header DW-1
141+ * @dword_2: UPIU header DW-2
142+ */
143+struct utp_upiu_header {
144+ u32 dword_0;
145+ u32 dword_1;
146+ u32 dword_2;
147+};
148+
149+/**
150+ * struct utp_upiu_cmd - Command UPIU structure
151+ * @header: UPIU header structure DW-0 to DW-2
152+ * @data_transfer_len: Data Transfer Length DW-3
153+ * @cdb: Command Descriptor Block CDB DW-4 to DW-7
154+ */
155+struct utp_upiu_cmd {
156+ struct utp_upiu_header header;
157+ u32 exp_data_transfer_len;
158+ u8 cdb[MAX_CDB_SIZE];
159+};
160+
161+/**
162+ * struct utp_upiu_rsp - Response UPIU structure
163+ * @header: UPIU header DW-0 to DW-2
164+ * @residual_transfer_count: Residual transfer count DW-3
165+ * @reserved: Reserved double words DW-4 to DW-7
166+ * @sense_data_len: Sense data length DW-8 U16
167+ * @sense_data: Sense data field DW-8 to DW-12
168+ */
169+struct utp_upiu_rsp {
170+ struct utp_upiu_header header;
171+ u32 residual_transfer_count;
172+ u32 reserved[4];
173+ u16 sense_data_len;
174+ u8 sense_data[18];
175+};
176+
177+/**
178+ * struct utp_upiu_task_req - Task request UPIU structure
179+ * @header - UPIU header structure DW0 to DW-2
180+ * @input_param1: Input parameter 1 DW-3
181+ * @input_param2: Input parameter 2 DW-4
182+ * @input_param3: Input parameter 3 DW-5
183+ * @reserved: Reserved double words DW-6 to DW-7
184+ */
185+struct utp_upiu_task_req {
186+ struct utp_upiu_header header;
187+ u32 input_param1;
188+ u32 input_param2;
189+ u32 input_param3;
190+ u32 reserved[2];
191+};
192+
193+/**
194+ * struct utp_upiu_task_rsp - Task Management Response UPIU structure
195+ * @header: UPIU header structure DW0-DW-2
196+ * @output_param1: Ouput parameter 1 DW3
197+ * @output_param2: Output parameter 2 DW4
198+ * @reserved: Reserved double words DW-5 to DW-7
199+ */
200+struct utp_upiu_task_rsp {
201+ struct utp_upiu_header header;
202+ u32 output_param1;
203+ u32 output_param2;
204+ u32 reserved[3];
205+};
206+
207+#endif /* End of Header */
drivers/scsi/ufs/ufshcd.c+1978−0
@@ -0,0 +1,1978 @@
1+/*
2+ * Universal Flash Storage Host controller driver
3+ *
4+ * This code is based on drivers/scsi/ufs/ufshcd.c
5+ * Copyright (C) 2011-2012 Samsung India Software Operations
6+ *
7+ * Santosh Yaraganavi <santosh.sy@samsung.com>
8+ * Vinayak Holikatti <h.vinayak@samsung.com>
9+ *
10+ * This program is free software; you can redistribute it and/or
11+ * modify it under the terms of the GNU General Public License
12+ * as published by the Free Software Foundation; either version 2
13+ * of the License, or (at your option) any later version.
14+ *
15+ * This program is distributed in the hope that it will be useful,
16+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+ * GNU General Public License for more details.
19+ *
20+ * NO WARRANTY
21+ * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
22+ * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
23+ * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
24+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
25+ * solely responsible for determining the appropriateness of using and
26+ * distributing the Program and assumes all risks associated with its
27+ * exercise of rights under this Agreement, including but not limited to
28+ * the risks and costs of program errors, damage to or loss of data,
29+ * programs or equipment, and unavailability or interruption of operations.
30+
31+ * DISCLAIMER OF LIABILITY
32+ * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
33+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34+ * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
35+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37+ * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
38+ * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
39+
40+ * You should have received a copy of the GNU General Public License
41+ * along with this program; if not, write to the Free Software
42+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
43+ * USA.
44+ */
45+
46+#include <linux/module.h>
47+#include <linux/kernel.h>
48+#include <linux/init.h>
49+#include <linux/pci.h>
50+#include <linux/interrupt.h>
51+#include <linux/io.h>
52+#include <linux/delay.h>
53+#include <linux/slab.h>
54+#include <linux/spinlock.h>
55+#include <linux/workqueue.h>
56+#include <linux/errno.h>
57+#include <linux/types.h>
58+#include <linux/wait.h>
59+#include <linux/bitops.h>
60+
61+#include <asm/irq.h>
62+#include <asm/byteorder.h>
63+#include <scsi/scsi.h>
64+#include <scsi/scsi_cmnd.h>
65+#include <scsi/scsi_host.h>
66+#include <scsi/scsi_tcq.h>
67+#include <scsi/scsi_dbg.h>
68+#include <scsi/scsi_eh.h>
69+
70+#include "ufs.h"
71+#include "ufshci.h"
72+
73+#define UFSHCD "ufshcd"
74+#define UFSHCD_DRIVER_VERSION "0.1"
75+
76+enum {
77+ UFSHCD_MAX_CHANNEL = 0,
78+ UFSHCD_MAX_ID = 1,
79+ UFSHCD_MAX_LUNS = 8,
80+ UFSHCD_CMD_PER_LUN = 32,
81+ UFSHCD_CAN_QUEUE = 32,
82+};
83+
84+/* UFSHCD states */
85+enum {
86+ UFSHCD_STATE_OPERATIONAL,
87+ UFSHCD_STATE_RESET,
88+ UFSHCD_STATE_ERROR,
89+};
90+
91+/* Interrupt configuration options */
92+enum {
93+ UFSHCD_INT_DISABLE,
94+ UFSHCD_INT_ENABLE,
95+ UFSHCD_INT_CLEAR,
96+};
97+
98+/* Interrupt aggregation options */
99+enum {
100+ INT_AGGR_RESET,
101+ INT_AGGR_CONFIG,
102+};
103+
104+/**
105+ * struct uic_command - UIC command structure
106+ * @command: UIC command
107+ * @argument1: UIC command argument 1
108+ * @argument2: UIC command argument 2
109+ * @argument3: UIC command argument 3
110+ * @cmd_active: Indicate if UIC command is outstanding
111+ * @result: UIC command result
112+ */
113+struct uic_command {
114+ u32 command;
115+ u32 argument1;
116+ u32 argument2;
117+ u32 argument3;
118+ int cmd_active;
119+ int result;
120+};
121+
122+/**
123+ * struct ufs_hba - per adapter private structure
124+ * @mmio_base: UFSHCI base register address
125+ * @ucdl_base_addr: UFS Command Descriptor base address
126+ * @utrdl_base_addr: UTP Transfer Request Descriptor base address
127+ * @utmrdl_base_addr: UTP Task Management Descriptor base address
128+ * @ucdl_dma_addr: UFS Command Descriptor DMA address
129+ * @utrdl_dma_addr: UTRDL DMA address
130+ * @utmrdl_dma_addr: UTMRDL DMA address
131+ * @host: Scsi_Host instance of the driver
132+ * @pdev: PCI device handle
133+ * @lrb: local reference block
134+ * @outstanding_tasks: Bits representing outstanding task requests
135+ * @outstanding_reqs: Bits representing outstanding transfer requests
136+ * @capabilities: UFS Controller Capabilities
137+ * @nutrs: Transfer Request Queue depth supported by controller
138+ * @nutmrs: Task Management Queue depth supported by controller
139+ * @active_uic_cmd: handle of active UIC command
140+ * @ufshcd_tm_wait_queue: wait queue for task management
141+ * @tm_condition: condition variable for task management
142+ * @ufshcd_state: UFSHCD states
143+ * @int_enable_mask: Interrupt Mask Bits
144+ * @uic_workq: Work queue for UIC completion handling
145+ * @feh_workq: Work queue for fatal controller error handling
146+ * @errors: HBA errors
147+ */
148+struct ufs_hba {
149+ void __iomem *mmio_base;
150+
151+ /* Virtual memory reference */
152+ struct utp_transfer_cmd_desc *ucdl_base_addr;
153+ struct utp_transfer_req_desc *utrdl_base_addr;
154+ struct utp_task_req_desc *utmrdl_base_addr;
155+
156+ /* DMA memory reference */
157+ dma_addr_t ucdl_dma_addr;
158+ dma_addr_t utrdl_dma_addr;
159+ dma_addr_t utmrdl_dma_addr;
160+
161+ struct Scsi_Host *host;
162+ struct pci_dev *pdev;
163+
164+ struct ufshcd_lrb *lrb;
165+
166+ unsigned long outstanding_tasks;
167+ unsigned long outstanding_reqs;
168+
169+ u32 capabilities;
170+ int nutrs;
171+ int nutmrs;
172+ u32 ufs_version;
173+
174+ struct uic_command active_uic_cmd;
175+ wait_queue_head_t ufshcd_tm_wait_queue;
176+ unsigned long tm_condition;
177+
178+ u32 ufshcd_state;
179+ u32 int_enable_mask;
180+
181+ /* Work Queues */
182+ struct work_struct uic_workq;
183+ struct work_struct feh_workq;
184+
185+ /* HBA Errors */
186+ u32 errors;
187+};
188+
189+/**
190+ * struct ufshcd_lrb - local reference block
191+ * @utr_descriptor_ptr: UTRD address of the command
192+ * @ucd_cmd_ptr: UCD address of the command
193+ * @ucd_rsp_ptr: Response UPIU address for this command
194+ * @ucd_prdt_ptr: PRDT address of the command
195+ * @cmd: pointer to SCSI command
196+ * @sense_buffer: pointer to sense buffer address of the SCSI command
197+ * @sense_bufflen: Length of the sense buffer
198+ * @scsi_status: SCSI status of the command
199+ * @command_type: SCSI, UFS, Query.
200+ * @task_tag: Task tag of the command
201+ * @lun: LUN of the command
202+ */
203+struct ufshcd_lrb {
204+ struct utp_transfer_req_desc *utr_descriptor_ptr;
205+ struct utp_upiu_cmd *ucd_cmd_ptr;
206+ struct utp_upiu_rsp *ucd_rsp_ptr;
207+ struct ufshcd_sg_entry *ucd_prdt_ptr;
208+
209+ struct scsi_cmnd *cmd;
210+ u8 *sense_buffer;
211+ unsigned int sense_bufflen;
212+ int scsi_status;
213+
214+ int command_type;
215+ int task_tag;
216+ unsigned int lun;
217+};
218+
219+/**
220+ * ufshcd_get_ufs_version - Get the UFS version supported by the HBA
221+ * @hba - Pointer to adapter instance
222+ *
223+ * Returns UFSHCI version supported by the controller
224+ */
225+static inline u32 ufshcd_get_ufs_version(struct ufs_hba *hba)
226+{
227+ return readl(hba->mmio_base + REG_UFS_VERSION);
228+}
229+
230+/**
231+ * ufshcd_is_device_present - Check if any device connected to
232+ * the host controller
233+ * @reg_hcs - host controller status register value
234+ *
235+ * Returns 0 if device present, non-zero if no device detected
236+ */
237+static inline int ufshcd_is_device_present(u32 reg_hcs)
238+{
239+ return (DEVICE_PRESENT & reg_hcs) ? 0 : -1;
240+}
241+
242+/**
243+ * ufshcd_get_tr_ocs - Get the UTRD Overall Command Status
244+ * @lrb: pointer to local command reference block
245+ *
246+ * This function is used to get the OCS field from UTRD
247+ * Returns the OCS field in the UTRD
248+ */
249+static inline int ufshcd_get_tr_ocs(struct ufshcd_lrb *lrbp)
250+{
251+ return lrbp->utr_descriptor_ptr->header.dword_2 & MASK_OCS;
252+}
253+
254+/**
255+ * ufshcd_get_tmr_ocs - Get the UTMRD Overall Command Status
256+ * @task_req_descp: pointer to utp_task_req_desc structure
257+ *
258+ * This function is used to get the OCS field from UTMRD
259+ * Returns the OCS field in the UTMRD
260+ */
261+static inline int
262+ufshcd_get_tmr_ocs(struct utp_task_req_desc *task_req_descp)
263+{
264+ return task_req_descp->header.dword_2 & MASK_OCS;
265+}
266+
267+/**
268+ * ufshcd_get_tm_free_slot - get a free slot for task management request
269+ * @hba: per adapter instance
270+ *
271+ * Returns maximum number of task management request slots in case of
272+ * task management queue full or returns the free slot number
273+ */
274+static inline int ufshcd_get_tm_free_slot(struct ufs_hba *hba)
275+{
276+ return find_first_zero_bit(&hba->outstanding_tasks, hba->nutmrs);
277+}
278+
279+/**
280+ * ufshcd_utrl_clear - Clear a bit in UTRLCLR register
281+ * @hba: per adapter instance
282+ * @pos: position of the bit to be cleared
283+ */
284+static inline void ufshcd_utrl_clear(struct ufs_hba *hba, u32 pos)
285+{
286+ writel(~(1 << pos),
287+ (hba->mmio_base + REG_UTP_TRANSFER_REQ_LIST_CLEAR));
288+}
289+
290+/**
291+ * ufshcd_get_lists_status - Check UCRDY, UTRLRDY and UTMRLRDY
292+ * @reg: Register value of host controller status
293+ *
294+ * Returns integer, 0 on Success and positive value if failed
295+ */
296+static inline int ufshcd_get_lists_status(u32 reg)
297+{
298+ /*
299+ * The mask 0xFF is for the following HCS register bits
300+ * Bit Description
301+ * 0 Device Present
302+ * 1 UTRLRDY
303+ * 2 UTMRLRDY
304+ * 3 UCRDY
305+ * 4 HEI
306+ * 5 DEI
307+ * 6-7 reserved
308+ */
309+ return (((reg) & (0xFF)) >> 1) ^ (0x07);
310+}
311+
312+/**
313+ * ufshcd_get_uic_cmd_result - Get the UIC command result
314+ * @hba: Pointer to adapter instance
315+ *
316+ * This function gets the result of UIC command completion
317+ * Returns 0 on success, non zero value on error
318+ */
319+static inline int ufshcd_get_uic_cmd_result(struct ufs_hba *hba)
320+{
321+ return readl(hba->mmio_base + REG_UIC_COMMAND_ARG_2) &
322+ MASK_UIC_COMMAND_RESULT;
323+}
324+
325+/**
326+ * ufshcd_free_hba_memory - Free allocated memory for LRB, request
327+ * and task lists
328+ * @hba: Pointer to adapter instance
329+ */
330+static inline void ufshcd_free_hba_memory(struct ufs_hba *hba)
331+{
332+ size_t utmrdl_size, utrdl_size, ucdl_size;
333+
334+ kfree(hba->lrb);
335+
336+ if (hba->utmrdl_base_addr) {
337+ utmrdl_size = sizeof(struct utp_task_req_desc) * hba->nutmrs;
338+ dma_free_coherent(&hba->pdev->dev, utmrdl_size,
339+ hba->utmrdl_base_addr, hba->utmrdl_dma_addr);
340+ }
341+
342+ if (hba->utrdl_base_addr) {
343+ utrdl_size =
344+ (sizeof(struct utp_transfer_req_desc) * hba->nutrs);
345+ dma_free_coherent(&hba->pdev->dev, utrdl_size,
346+ hba->utrdl_base_addr, hba->utrdl_dma_addr);
347+ }
348+
349+ if (hba->ucdl_base_addr) {
350+ ucdl_size =
351+ (sizeof(struct utp_transfer_cmd_desc) * hba->nutrs);
352+ dma_free_coherent(&hba->pdev->dev, ucdl_size,
353+ hba->ucdl_base_addr, hba->ucdl_dma_addr);
354+ }
355+}
356+
357+/**
358+ * ufshcd_is_valid_req_rsp - checks if controller TR response is valid
359+ * @ucd_rsp_ptr: pointer to response UPIU
360+ *
361+ * This function checks the response UPIU for valid transaction type in
362+ * response field
363+ * Returns 0 on success, non-zero on failure
364+ */
365+static inline int
366+ufshcd_is_valid_req_rsp(struct utp_upiu_rsp *ucd_rsp_ptr)
367+{
368+ return ((be32_to_cpu(ucd_rsp_ptr->header.dword_0) >> 24) ==
369+ UPIU_TRANSACTION_RESPONSE) ? 0 : DID_ERROR << 16;
370+}
371+
372+/**
373+ * ufshcd_get_rsp_upiu_result - Get the result from response UPIU
374+ * @ucd_rsp_ptr: pointer to response UPIU
375+ *
376+ * This function gets the response status and scsi_status from response UPIU
377+ * Returns the response result code.
378+ */
379+static inline int
380+ufshcd_get_rsp_upiu_result(struct utp_upiu_rsp *ucd_rsp_ptr)
381+{
382+ return be32_to_cpu(ucd_rsp_ptr->header.dword_1) & MASK_RSP_UPIU_RESULT;
383+}
384+
385+/**
386+ * ufshcd_config_int_aggr - Configure interrupt aggregation values.
387+ * Currently there is no use case where we want to configure
388+ * interrupt aggregation dynamically. So to configure interrupt
389+ * aggregation, #define INT_AGGR_COUNTER_THRESHOLD_VALUE and
390+ * INT_AGGR_TIMEOUT_VALUE are used.
391+ * @hba: per adapter instance
392+ * @option: Interrupt aggregation option
393+ */
394+static inline void
395+ufshcd_config_int_aggr(struct ufs_hba *hba, int option)
396+{
397+ switch (option) {
398+ case INT_AGGR_RESET:
399+ writel((INT_AGGR_ENABLE |
400+ INT_AGGR_COUNTER_AND_TIMER_RESET),
401+ (hba->mmio_base +
402+ REG_UTP_TRANSFER_REQ_INT_AGG_CONTROL));
403+ break;
404+ case INT_AGGR_CONFIG:
405+ writel((INT_AGGR_ENABLE |
406+ INT_AGGR_PARAM_WRITE |
407+ INT_AGGR_COUNTER_THRESHOLD_VALUE |
408+ INT_AGGR_TIMEOUT_VALUE),
409+ (hba->mmio_base +
410+ REG_UTP_TRANSFER_REQ_INT_AGG_CONTROL));
411+ break;
412+ }
413+}
414+
415+/**
416+ * ufshcd_enable_run_stop_reg - Enable run-stop registers,
417+ * When run-stop registers are set to 1, it indicates the
418+ * host controller that it can process the requests
419+ * @hba: per adapter instance
420+ */
421+static void ufshcd_enable_run_stop_reg(struct ufs_hba *hba)
422+{
423+ writel(UTP_TASK_REQ_LIST_RUN_STOP_BIT,
424+ (hba->mmio_base +
425+ REG_UTP_TASK_REQ_LIST_RUN_STOP));
426+ writel(UTP_TRANSFER_REQ_LIST_RUN_STOP_BIT,
427+ (hba->mmio_base +
428+ REG_UTP_TRANSFER_REQ_LIST_RUN_STOP));
429+}
430+
431+/**
432+ * ufshcd_hba_stop - Send controller to reset state
433+ * @hba: per adapter instance
434+ */
435+static inline void ufshcd_hba_stop(struct ufs_hba *hba)
436+{
437+ writel(CONTROLLER_DISABLE, (hba->mmio_base + REG_CONTROLLER_ENABLE));
438+}
439+
440+/**
441+ * ufshcd_hba_start - Start controller initialization sequence
442+ * @hba: per adapter instance
443+ */
444+static inline void ufshcd_hba_start(struct ufs_hba *hba)
445+{
446+ writel(CONTROLLER_ENABLE , (hba->mmio_base + REG_CONTROLLER_ENABLE));
447+}
448+
449+/**
450+ * ufshcd_is_hba_active - Get controller state
451+ * @hba: per adapter instance
452+ *
453+ * Returns zero if controller is active, 1 otherwise
454+ */
455+static inline int ufshcd_is_hba_active(struct ufs_hba *hba)
456+{
457+ return (readl(hba->mmio_base + REG_CONTROLLER_ENABLE) & 0x1) ? 0 : 1;
458+}
459+
460+/**
461+ * ufshcd_send_command - Send SCSI or device management commands
462+ * @hba: per adapter instance
463+ * @task_tag: Task tag of the command
464+ */
465+static inline
466+void ufshcd_send_command(struct ufs_hba *hba, unsigned int task_tag)
467+{
468+ __set_bit(task_tag, &hba->outstanding_reqs);
469+ writel((1 << task_tag),
470+ (hba->mmio_base + REG_UTP_TRANSFER_REQ_DOOR_BELL));
471+}
472+
473+/**
474+ * ufshcd_copy_sense_data - Copy sense data in case of check condition
475+ * @lrb - pointer to local reference block
476+ */
477+static inline void ufshcd_copy_sense_data(struct ufshcd_lrb *lrbp)
478+{
479+ int len;
480+ if (lrbp->sense_buffer) {
481+ len = be16_to_cpu(lrbp->ucd_rsp_ptr->sense_data_len);
482+ memcpy(lrbp->sense_buffer,
483+ lrbp->ucd_rsp_ptr->sense_data,
484+ min_t(int, len, SCSI_SENSE_BUFFERSIZE));
485+ }
486+}
487+
488+/**
489+ * ufshcd_hba_capabilities - Read controller capabilities
490+ * @hba: per adapter instance
491+ */
492+static inline void ufshcd_hba_capabilities(struct ufs_hba *hba)
493+{
494+ hba->capabilities =
495+ readl(hba->mmio_base + REG_CONTROLLER_CAPABILITIES);
496+
497+ /* nutrs and nutmrs are 0 based values */
498+ hba->nutrs = (hba->capabilities & MASK_TRANSFER_REQUESTS_SLOTS) + 1;
499+ hba->nutmrs =
500+ ((hba->capabilities & MASK_TASK_MANAGEMENT_REQUEST_SLOTS) >> 16) + 1;
501+}
502+
503+/**
504+ * ufshcd_send_uic_command - Send UIC commands to unipro layers
505+ * @hba: per adapter instance
506+ * @uic_command: UIC command
507+ */
508+static inline void
509+ufshcd_send_uic_command(struct ufs_hba *hba, struct uic_command *uic_cmnd)
510+{
511+ /* Write Args */
512+ writel(uic_cmnd->argument1,
513+ (hba->mmio_base + REG_UIC_COMMAND_ARG_1));
514+ writel(uic_cmnd->argument2,
515+ (hba->mmio_base + REG_UIC_COMMAND_ARG_2));
516+ writel(uic_cmnd->argument3,
517+ (hba->mmio_base + REG_UIC_COMMAND_ARG_3));
518+
519+ /* Write UIC Cmd */
520+ writel((uic_cmnd->command & COMMAND_OPCODE_MASK),
521+ (hba->mmio_base + REG_UIC_COMMAND));
522+}
523+
524+/**
525+ * ufshcd_map_sg - Map scatter-gather list to prdt
526+ * @lrbp - pointer to local reference block
527+ *
528+ * Returns 0 in case of success, non-zero value in case of failure
529+ */
530+static int ufshcd_map_sg(struct ufshcd_lrb *lrbp)
531+{
532+ struct ufshcd_sg_entry *prd_table;
533+ struct scatterlist *sg;
534+ struct scsi_cmnd *cmd;
535+ int sg_segments;
536+ int i;
537+
538+ cmd = lrbp->cmd;
539+ sg_segments = scsi_dma_map(cmd);
540+ if (sg_segments < 0)
541+ return sg_segments;
542+
543+ if (sg_segments) {
544+ lrbp->utr_descriptor_ptr->prd_table_length =
545+ cpu_to_le16((u16) (sg_segments));
546+
547+ prd_table = (struct ufshcd_sg_entry *)lrbp->ucd_prdt_ptr;
548+
549+ scsi_for_each_sg(cmd, sg, sg_segments, i) {
550+ prd_table[i].size =
551+ cpu_to_le32(((u32) sg_dma_len(sg))-1);
552+ prd_table[i].base_addr =
553+ cpu_to_le32(lower_32_bits(sg->dma_address));
554+ prd_table[i].upper_addr =
555+ cpu_to_le32(upper_32_bits(sg->dma_address));
556+ }
557+ } else {
558+ lrbp->utr_descriptor_ptr->prd_table_length = 0;
559+ }
560+
561+ return 0;
562+}
563+
564+/**
565+ * ufshcd_int_config - enable/disable interrupts
566+ * @hba: per adapter instance
567+ * @option: interrupt option
568+ */
569+static void ufshcd_int_config(struct ufs_hba *hba, u32 option)
570+{
571+ switch (option) {
572+ case UFSHCD_INT_ENABLE:
573+ writel(hba->int_enable_mask,
574+ (hba->mmio_base + REG_INTERRUPT_ENABLE));
575+ break;
576+ case UFSHCD_INT_DISABLE:
577+ if (hba->ufs_version == UFSHCI_VERSION_10)
578+ writel(INTERRUPT_DISABLE_MASK_10,
579+ (hba->mmio_base + REG_INTERRUPT_ENABLE));
580+ else
581+ writel(INTERRUPT_DISABLE_MASK_11,
582+ (hba->mmio_base + REG_INTERRUPT_ENABLE));
583+ break;
584+ }
585+}
586+
587+/**
588+ * ufshcd_compose_upiu - form UFS Protocol Information Unit(UPIU)
589+ * @lrb - pointer to local reference block
590+ */
591+static void ufshcd_compose_upiu(struct ufshcd_lrb *lrbp)
592+{
593+ struct utp_transfer_req_desc *req_desc;
594+ struct utp_upiu_cmd *ucd_cmd_ptr;
595+ u32 data_direction;
596+ u32 upiu_flags;
597+
598+ ucd_cmd_ptr = lrbp->ucd_cmd_ptr;
599+ req_desc = lrbp->utr_descriptor_ptr;
600+
601+ switch (lrbp->command_type) {
602+ case UTP_CMD_TYPE_SCSI:
603+ if (lrbp->cmd->sc_data_direction == DMA_FROM_DEVICE) {
604+ data_direction = UTP_DEVICE_TO_HOST;
605+ upiu_flags = UPIU_CMD_FLAGS_READ;
606+ } else if (lrbp->cmd->sc_data_direction == DMA_TO_DEVICE) {
607+ data_direction = UTP_HOST_TO_DEVICE;
608+ upiu_flags = UPIU_CMD_FLAGS_WRITE;
609+ } else {
610+ data_direction = UTP_NO_DATA_TRANSFER;
611+ upiu_flags = UPIU_CMD_FLAGS_NONE;
612+ }
613+
614+ /* Transfer request descriptor header fields */
615+ req_desc->header.dword_0 =
616+ cpu_to_le32(data_direction | UTP_SCSI_COMMAND);
617+
618+ /*
619+ * assigning invalid value for command status. Controller
620+ * updates OCS on command completion, with the command
621+ * status
622+ */
623+ req_desc->header.dword_2 =
624+ cpu_to_le32(OCS_INVALID_COMMAND_STATUS);
625+
626+ /* command descriptor fields */
627+ ucd_cmd_ptr->header.dword_0 =
628+ cpu_to_be32(UPIU_HEADER_DWORD(UPIU_TRANSACTION_COMMAND,
629+ upiu_flags,
630+ lrbp->lun,
631+ lrbp->task_tag));
632+ ucd_cmd_ptr->header.dword_1 =
633+ cpu_to_be32(
634+ UPIU_HEADER_DWORD(UPIU_COMMAND_SET_TYPE_SCSI,
635+ 0,
636+ 0,
637+ 0));
638+
639+ /* Total EHS length and Data segment length will be zero */
640+ ucd_cmd_ptr->header.dword_2 = 0;
641+
642+ ucd_cmd_ptr->exp_data_transfer_len =
643+ cpu_to_be32(lrbp->cmd->transfersize);
644+
645+ memcpy(ucd_cmd_ptr->cdb,
646+ lrbp->cmd->cmnd,
647+ (min_t(unsigned short,
648+ lrbp->cmd->cmd_len,
649+ MAX_CDB_SIZE)));
650+ break;
651+ case UTP_CMD_TYPE_DEV_MANAGE:
652+ /* For query function implementation */
653+ break;
654+ case UTP_CMD_TYPE_UFS:
655+ /* For UFS native command implementation */
656+ break;
657+ } /* end of switch */
658+}
659+
660+/**
661+ * ufshcd_queuecommand - main entry point for SCSI requests
662+ * @cmd: command from SCSI Midlayer
663+ * @done: call back function
664+ *
665+ * Returns 0 for success, non-zero in case of failure
666+ */
667+static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
668+{
669+ struct ufshcd_lrb *lrbp;
670+ struct ufs_hba *hba;
671+ unsigned long flags;
672+ int tag;
673+ int err = 0;
674+
675+ hba = shost_priv(host);
676+
677+ tag = cmd->request->tag;
678+
679+ if (hba->ufshcd_state != UFSHCD_STATE_OPERATIONAL) {
680+ err = SCSI_MLQUEUE_HOST_BUSY;
681+ goto out;
682+ }
683+
684+ lrbp = &hba->lrb[tag];
685+
686+ lrbp->cmd = cmd;
687+ lrbp->sense_bufflen = SCSI_SENSE_BUFFERSIZE;
688+ lrbp->sense_buffer = cmd->sense_buffer;
689+ lrbp->task_tag = tag;
690+ lrbp->lun = cmd->device->lun;
691+
692+ lrbp->command_type = UTP_CMD_TYPE_SCSI;
693+
694+ /* form UPIU before issuing the command */
695+ ufshcd_compose_upiu(lrbp);
696+ err = ufshcd_map_sg(lrbp);
697+ if (err)
698+ goto out;
699+
700+ /* issue command to the controller */
701+ spin_lock_irqsave(hba->host->host_lock, flags);
702+ ufshcd_send_command(hba, tag);
703+ spin_unlock_irqrestore(hba->host->host_lock, flags);
704+out:
705+ return err;
706+}
707+
708+/**
709+ * ufshcd_memory_alloc - allocate memory for host memory space data structures
710+ * @hba: per adapter instance
711+ *
712+ * 1. Allocate DMA memory for Command Descriptor array
713+ * Each command descriptor consist of Command UPIU, Response UPIU and PRDT
714+ * 2. Allocate DMA memory for UTP Transfer Request Descriptor List (UTRDL).
715+ * 3. Allocate DMA memory for UTP Task Management Request Descriptor List
716+ * (UTMRDL)
717+ * 4. Allocate memory for local reference block(lrb).
718+ *
719+ * Returns 0 for success, non-zero in case of failure
720+ */
721+static int ufshcd_memory_alloc(struct ufs_hba *hba)
722+{
723+ size_t utmrdl_size, utrdl_size, ucdl_size;
724+
725+ /* Allocate memory for UTP command descriptors */
726+ ucdl_size = (sizeof(struct utp_transfer_cmd_desc) * hba->nutrs);
727+ hba->ucdl_base_addr = dma_alloc_coherent(&hba->pdev->dev,
728+ ucdl_size,
729+ &hba->ucdl_dma_addr,
730+ GFP_KERNEL);
731+
732+ /*
733+ * UFSHCI requires UTP command descriptor to be 128 byte aligned.
734+ * make sure hba->ucdl_dma_addr is aligned to PAGE_SIZE
735+ * if hba->ucdl_dma_addr is aligned to PAGE_SIZE, then it will
736+ * be aligned to 128 bytes as well
737+ */
738+ if (!hba->ucdl_base_addr ||
739+ WARN_ON(hba->ucdl_dma_addr & (PAGE_SIZE - 1))) {
740+ dev_err(&hba->pdev->dev,
741+ "Command Descriptor Memory allocation failed\n");
742+ goto out;
743+ }
744+
745+ /*
746+ * Allocate memory for UTP Transfer descriptors
747+ * UFSHCI requires 1024 byte alignment of UTRD
748+ */
749+ utrdl_size = (sizeof(struct utp_transfer_req_desc) * hba->nutrs);
750+ hba->utrdl_base_addr = dma_alloc_coherent(&hba->pdev->dev,
751+ utrdl_size,
752+ &hba->utrdl_dma_addr,
753+ GFP_KERNEL);
754+ if (!hba->utrdl_base_addr ||
755+ WARN_ON(hba->utrdl_dma_addr & (PAGE_SIZE - 1))) {
756+ dev_err(&hba->pdev->dev,
757+ "Transfer Descriptor Memory allocation failed\n");
758+ goto out;
759+ }
760+
761+ /*
762+ * Allocate memory for UTP Task Management descriptors
763+ * UFSHCI requires 1024 byte alignment of UTMRD
764+ */
765+ utmrdl_size = sizeof(struct utp_task_req_desc) * hba->nutmrs;
766+ hba->utmrdl_base_addr = dma_alloc_coherent(&hba->pdev->dev,
767+ utmrdl_size,
768+ &hba->utmrdl_dma_addr,
769+ GFP_KERNEL);
770+ if (!hba->utmrdl_base_addr ||
771+ WARN_ON(hba->utmrdl_dma_addr & (PAGE_SIZE - 1))) {
772+ dev_err(&hba->pdev->dev,
773+ "Task Management Descriptor Memory allocation failed\n");
774+ goto out;
775+ }
776+
777+ /* Allocate memory for local reference block */
778+ hba->lrb = kcalloc(hba->nutrs, sizeof(struct ufshcd_lrb), GFP_KERNEL);
779+ if (!hba->lrb) {
780+ dev_err(&hba->pdev->dev, "LRB Memory allocation failed\n");
781+ goto out;
782+ }
783+ return 0;
784+out:
785+ ufshcd_free_hba_memory(hba);
786+ return -ENOMEM;
787+}
788+
789+/**
790+ * ufshcd_host_memory_configure - configure local reference block with
791+ * memory offsets
792+ * @hba: per adapter instance
793+ *
794+ * Configure Host memory space
795+ * 1. Update Corresponding UTRD.UCDBA and UTRD.UCDBAU with UCD DMA
796+ * address.
797+ * 2. Update each UTRD with Response UPIU offset, Response UPIU length
798+ * and PRDT offset.
799+ * 3. Save the corresponding addresses of UTRD, UCD.CMD, UCD.RSP and UCD.PRDT
800+ * into local reference block.
801+ */
802+static void ufshcd_host_memory_configure(struct ufs_hba *hba)
803+{
804+ struct utp_transfer_cmd_desc *cmd_descp;
805+ struct utp_transfer_req_desc *utrdlp;
806+ dma_addr_t cmd_desc_dma_addr;
807+ dma_addr_t cmd_desc_element_addr;
808+ u16 response_offset;
809+ u16 prdt_offset;
810+ int cmd_desc_size;
811+ int i;
812+
813+ utrdlp = hba->utrdl_base_addr;
814+ cmd_descp = hba->ucdl_base_addr;
815+
816+ response_offset =
817+ offsetof(struct utp_transfer_cmd_desc, response_upiu);
818+ prdt_offset =
819+ offsetof(struct utp_transfer_cmd_desc, prd_table);
820+
821+ cmd_desc_size = sizeof(struct utp_transfer_cmd_desc);
822+ cmd_desc_dma_addr = hba->ucdl_dma_addr;
823+
824+ for (i = 0; i < hba->nutrs; i++) {
825+ /* Configure UTRD with command descriptor base address */
826+ cmd_desc_element_addr =
827+ (cmd_desc_dma_addr + (cmd_desc_size * i));
828+ utrdlp[i].command_desc_base_addr_lo =
829+ cpu_to_le32(lower_32_bits(cmd_desc_element_addr));
830+ utrdlp[i].command_desc_base_addr_hi =
831+ cpu_to_le32(upper_32_bits(cmd_desc_element_addr));
832+
833+ /* Response upiu and prdt offset should be in double words */
834+ utrdlp[i].response_upiu_offset =
835+ cpu_to_le16((response_offset >> 2));
836+ utrdlp[i].prd_table_offset =
837+ cpu_to_le16((prdt_offset >> 2));
838+ utrdlp[i].response_upiu_length =
839+ cpu_to_le16(ALIGNED_UPIU_SIZE);
840+
841+ hba->lrb[i].utr_descriptor_ptr = (utrdlp + i);
842+ hba->lrb[i].ucd_cmd_ptr =
843+ (struct utp_upiu_cmd *)(cmd_descp + i);
844+ hba->lrb[i].ucd_rsp_ptr =
845+ (struct utp_upiu_rsp *)cmd_descp[i].response_upiu;
846+ hba->lrb[i].ucd_prdt_ptr =
847+ (struct ufshcd_sg_entry *)cmd_descp[i].prd_table;
848+ }
849+}
850+
851+/**
852+ * ufshcd_dme_link_startup - Notify Unipro to perform link startup
853+ * @hba: per adapter instance
854+ *
855+ * UIC_CMD_DME_LINK_STARTUP command must be issued to Unipro layer,
856+ * in order to initialize the Unipro link startup procedure.
857+ * Once the Unipro links are up, the device connected to the controller
858+ * is detected.
859+ *
860+ * Returns 0 on success, non-zero value on failure
861+ */
862+static int ufshcd_dme_link_startup(struct ufs_hba *hba)
863+{
864+ struct uic_command *uic_cmd;
865+ unsigned long flags;
866+
867+ /* check if controller is ready to accept UIC commands */
868+ if (((readl(hba->mmio_base + REG_CONTROLLER_STATUS)) &
869+ UIC_COMMAND_READY) == 0x0) {
870+ dev_err(&hba->pdev->dev,
871+ "Controller not ready"
872+ " to accept UIC commands\n");
873+ return -EIO;
874+ }
875+
876+ spin_lock_irqsave(hba->host->host_lock, flags);
877+
878+ /* form UIC command */
879+ uic_cmd = &hba->active_uic_cmd;
880+ uic_cmd->command = UIC_CMD_DME_LINK_STARTUP;
881+ uic_cmd->argument1 = 0;
882+ uic_cmd->argument2 = 0;
883+ uic_cmd->argument3 = 0;
884+
885+ /* enable UIC related interrupts */
886+ hba->int_enable_mask |= UIC_COMMAND_COMPL;
887+ ufshcd_int_config(hba, UFSHCD_INT_ENABLE);
888+
889+ /* sending UIC commands to controller */
890+ ufshcd_send_uic_command(hba, uic_cmd);
891+ spin_unlock_irqrestore(hba->host->host_lock, flags);
892+ return 0;
893+}
894+
895+/**
896+ * ufshcd_make_hba_operational - Make UFS controller operational
897+ * @hba: per adapter instance
898+ *
899+ * To bring UFS host controller to operational state,
900+ * 1. Check if device is present
901+ * 2. Configure run-stop-registers
902+ * 3. Enable required interrupts
903+ * 4. Configure interrupt aggregation
904+ *
905+ * Returns 0 on success, non-zero value on failure
906+ */
907+static int ufshcd_make_hba_operational(struct ufs_hba *hba)
908+{
909+ int err = 0;
910+ u32 reg;
911+
912+ /* check if device present */
913+ reg = readl((hba->mmio_base + REG_CONTROLLER_STATUS));
914+ if (ufshcd_is_device_present(reg)) {
915+ dev_err(&hba->pdev->dev, "cc: Device not present\n");
916+ err = -ENXIO;
917+ goto out;
918+ }
919+
920+ /*
921+ * UCRDY, UTMRLDY and UTRLRDY bits must be 1
922+ * DEI, HEI bits must be 0
923+ */
924+ if (!(ufshcd_get_lists_status(reg))) {
925+ ufshcd_enable_run_stop_reg(hba);
926+ } else {
927+ dev_err(&hba->pdev->dev,
928+ "Host controller not ready to process requests");
929+ err = -EIO;
930+ goto out;
931+ }
932+
933+ /* Enable required interrupts */
934+ hba->int_enable_mask |= (UTP_TRANSFER_REQ_COMPL |
935+ UIC_ERROR |
936+ UTP_TASK_REQ_COMPL |
937+ DEVICE_FATAL_ERROR |
938+ CONTROLLER_FATAL_ERROR |
939+ SYSTEM_BUS_FATAL_ERROR);
940+ ufshcd_int_config(hba, UFSHCD_INT_ENABLE);
941+
942+ /* Configure interrupt aggregation */
943+ ufshcd_config_int_aggr(hba, INT_AGGR_CONFIG);
944+
945+ if (hba->ufshcd_state == UFSHCD_STATE_RESET)
946+ scsi_unblock_requests(hba->host);
947+
948+ hba->ufshcd_state = UFSHCD_STATE_OPERATIONAL;
949+ scsi_scan_host(hba->host);
950+out:
951+ return err;
952+}
953+
954+/**
955+ * ufshcd_hba_enable - initialize the controller
956+ * @hba: per adapter instance
957+ *
958+ * The controller resets itself and controller firmware initialization
959+ * sequence kicks off. When controller is ready it will set
960+ * the Host Controller Enable bit to 1.
961+ *
962+ * Returns 0 on success, non-zero value on failure
963+ */
964+static int ufshcd_hba_enable(struct ufs_hba *hba)
965+{
966+ int retry;
967+
968+ /*
969+ * msleep of 1 and 5 used in this function might result in msleep(20),
970+ * but it was necessary to send the UFS FPGA to reset mode during
971+ * development and testing of this driver. msleep can be changed to
972+ * mdelay and retry count can be reduced based on the controller.
973+ */
974+ if (!ufshcd_is_hba_active(hba)) {
975+
976+ /* change controller state to "reset state" */
977+ ufshcd_hba_stop(hba);
978+
979+ /*
980+ * This delay is based on the testing done with UFS host
981+ * controller FPGA. The delay can be changed based on the
982+ * host controller used.
983+ */
984+ msleep(5);
985+ }
986+
987+ /* start controller initialization sequence */
988+ ufshcd_hba_start(hba);
989+
990+ /*
991+ * To initialize a UFS host controller HCE bit must be set to 1.
992+ * During initialization the HCE bit value changes from 1->0->1.
993+ * When the host controller completes initialization sequence
994+ * it sets the value of HCE bit to 1. The same HCE bit is read back
995+ * to check if the controller has completed initialization sequence.
996+ * So without this delay the value HCE = 1, set in the previous
997+ * instruction might be read back.
998+ * This delay can be changed based on the controller.
999+ */
1000+ msleep(1);
1001+
1002+ /* wait for the host controller to complete initialization */
1003+ retry = 10;
1004+ while (ufshcd_is_hba_active(hba)) {
1005+ if (retry) {
1006+ retry--;
1007+ } else {
1008+ dev_err(&hba->pdev->dev,
1009+ "Controller enable failed\n");
1010+ return -EIO;
1011+ }
1012+ msleep(5);
1013+ }
1014+ return 0;
1015+}
1016+
1017+/**
1018+ * ufshcd_initialize_hba - start the initialization process
1019+ * @hba: per adapter instance
1020+ *
1021+ * 1. Enable the controller via ufshcd_hba_enable.
1022+ * 2. Program the Transfer Request List Address with the starting address of
1023+ * UTRDL.
1024+ * 3. Program the Task Management Request List Address with starting address
1025+ * of UTMRDL.
1026+ *
1027+ * Returns 0 on success, non-zero value on failure.
1028+ */
1029+static int ufshcd_initialize_hba(struct ufs_hba *hba)
1030+{
1031+ if (ufshcd_hba_enable(hba))
1032+ return -EIO;
1033+
1034+ /* Configure UTRL and UTMRL base address registers */
1035+ writel(hba->utrdl_dma_addr,
1036+ (hba->mmio_base + REG_UTP_TRANSFER_REQ_LIST_BASE_L));
1037+ writel(lower_32_bits(hba->utrdl_dma_addr),
1038+ (hba->mmio_base + REG_UTP_TRANSFER_REQ_LIST_BASE_H));
1039+ writel(hba->utmrdl_dma_addr,
1040+ (hba->mmio_base + REG_UTP_TASK_REQ_LIST_BASE_L));
1041+ writel(upper_32_bits(hba->utmrdl_dma_addr),
1042+ (hba->mmio_base + REG_UTP_TASK_REQ_LIST_BASE_H));
1043+
1044+ /* Initialize unipro link startup procedure */
1045+ return ufshcd_dme_link_startup(hba);
1046+}
1047+
1048+/**
1049+ * ufshcd_do_reset - reset the host controller
1050+ * @hba: per adapter instance
1051+ *
1052+ * Returns SUCCESS/FAILED
1053+ */
1054+static int ufshcd_do_reset(struct ufs_hba *hba)
1055+{
1056+ struct ufshcd_lrb *lrbp;
1057+ unsigned long flags;
1058+ int tag;
1059+
1060+ /* block commands from midlayer */
1061+ scsi_block_requests(hba->host);
1062+
1063+ spin_lock_irqsave(hba->host->host_lock, flags);
1064+ hba->ufshcd_state = UFSHCD_STATE_RESET;
1065+
1066+ /* send controller to reset state */
1067+ ufshcd_hba_stop(hba);
1068+ spin_unlock_irqrestore(hba->host->host_lock, flags);
1069+
1070+ /* abort outstanding commands */
1071+ for (tag = 0; tag < hba->nutrs; tag++) {
1072+ if (test_bit(tag, &hba->outstanding_reqs)) {
1073+ lrbp = &hba->lrb[tag];
1074+ scsi_dma_unmap(lrbp->cmd);
1075+ lrbp->cmd->result = DID_RESET << 16;
1076+ lrbp->cmd->scsi_done(lrbp->cmd);
1077+ lrbp->cmd = NULL;
1078+ }
1079+ }
1080+
1081+ /* clear outstanding request/task bit maps */
1082+ hba->outstanding_reqs = 0;
1083+ hba->outstanding_tasks = 0;
1084+
1085+ /* start the initialization process */
1086+ if (ufshcd_initialize_hba(hba)) {
1087+ dev_err(&hba->pdev->dev,
1088+ "Reset: Controller initialization failed\n");
1089+ return FAILED;
1090+ }
1091+ return SUCCESS;
1092+}
1093+
1094+/**
1095+ * ufshcd_slave_alloc - handle initial SCSI device configurations
1096+ * @sdev: pointer to SCSI device
1097+ *
1098+ * Returns success
1099+ */
1100+static int ufshcd_slave_alloc(struct scsi_device *sdev)
1101+{
1102+ struct ufs_hba *hba;
1103+
1104+ hba = shost_priv(sdev->host);
1105+ sdev->tagged_supported = 1;
1106+
1107+ /* Mode sense(6) is not supported by UFS, so use Mode sense(10) */
1108+ sdev->use_10_for_ms = 1;
1109+ scsi_set_tag_type(sdev, MSG_SIMPLE_TAG);
1110+
1111+ /*
1112+ * Inform SCSI Midlayer that the LUN queue depth is same as the
1113+ * controller queue depth. If a LUN queue depth is less than the
1114+ * controller queue depth and if the LUN reports
1115+ * SAM_STAT_TASK_SET_FULL, the LUN queue depth will be adjusted
1116+ * with scsi_adjust_queue_depth.
1117+ */
1118+ scsi_activate_tcq(sdev, hba->nutrs);
1119+ return 0;
1120+}
1121+
1122+/**
1123+ * ufshcd_slave_destroy - remove SCSI device configurations
1124+ * @sdev: pointer to SCSI device
1125+ */
1126+static void ufshcd_slave_destroy(struct scsi_device *sdev)
1127+{
1128+ struct ufs_hba *hba;
1129+
1130+ hba = shost_priv(sdev->host);
1131+ scsi_deactivate_tcq(sdev, hba->nutrs);
1132+}
1133+
1134+/**
1135+ * ufshcd_task_req_compl - handle task management request completion
1136+ * @hba: per adapter instance
1137+ * @index: index of the completed request
1138+ *
1139+ * Returns SUCCESS/FAILED
1140+ */
1141+static int ufshcd_task_req_compl(struct ufs_hba *hba, u32 index)
1142+{
1143+ struct utp_task_req_desc *task_req_descp;
1144+ struct utp_upiu_task_rsp *task_rsp_upiup;
1145+ unsigned long flags;
1146+ int ocs_value;
1147+ int task_result;
1148+
1149+ spin_lock_irqsave(hba->host->host_lock, flags);
1150+
1151+ /* Clear completed tasks from outstanding_tasks */
1152+ __clear_bit(index, &hba->outstanding_tasks);
1153+
1154+ task_req_descp = hba->utmrdl_base_addr;
1155+ ocs_value = ufshcd_get_tmr_ocs(&task_req_descp[index]);
1156+
1157+ if (ocs_value == OCS_SUCCESS) {
1158+ task_rsp_upiup = (struct utp_upiu_task_rsp *)
1159+ task_req_descp[index].task_rsp_upiu;
1160+ task_result = be32_to_cpu(task_rsp_upiup->header.dword_1);
1161+ task_result = ((task_result & MASK_TASK_RESPONSE) >> 8);
1162+
1163+ if (task_result != UPIU_TASK_MANAGEMENT_FUNC_COMPL ||
1164+ task_result != UPIU_TASK_MANAGEMENT_FUNC_SUCCEEDED)
1165+ task_result = FAILED;
1166+ } else {
1167+ task_result = FAILED;
1168+ dev_err(&hba->pdev->dev,
1169+ "trc: Invalid ocs = %x\n", ocs_value);
1170+ }
1171+ spin_unlock_irqrestore(hba->host->host_lock, flags);
1172+ return task_result;
1173+}
1174+
1175+/**
1176+ * ufshcd_adjust_lun_qdepth - Update LUN queue depth if device responds with
1177+ * SAM_STAT_TASK_SET_FULL SCSI command status.
1178+ * @cmd: pointer to SCSI command
1179+ */
1180+static void ufshcd_adjust_lun_qdepth(struct scsi_cmnd *cmd)
1181+{
1182+ struct ufs_hba *hba;
1183+ int i;
1184+ int lun_qdepth = 0;
1185+
1186+ hba = shost_priv(cmd->device->host);
1187+
1188+ /*
1189+ * LUN queue depth can be obtained by counting outstanding commands
1190+ * on the LUN.
1191+ */
1192+ for (i = 0; i < hba->nutrs; i++) {
1193+ if (test_bit(i, &hba->outstanding_reqs)) {
1194+
1195+ /*
1196+ * Check if the outstanding command belongs
1197+ * to the LUN which reported SAM_STAT_TASK_SET_FULL.
1198+ */
1199+ if (cmd->device->lun == hba->lrb[i].lun)
1200+ lun_qdepth++;
1201+ }
1202+ }
1203+
1204+ /*
1205+ * LUN queue depth will be total outstanding commands, except the
1206+ * command for which the LUN reported SAM_STAT_TASK_SET_FULL.
1207+ */
1208+ scsi_adjust_queue_depth(cmd->device, MSG_SIMPLE_TAG, lun_qdepth - 1);
1209+}
1210+
1211+/**
1212+ * ufshcd_scsi_cmd_status - Update SCSI command result based on SCSI status
1213+ * @lrb: pointer to local reference block of completed command
1214+ * @scsi_status: SCSI command status
1215+ *
1216+ * Returns value base on SCSI command status
1217+ */
1218+static inline int
1219+ufshcd_scsi_cmd_status(struct ufshcd_lrb *lrbp, int scsi_status)
1220+{
1221+ int result = 0;
1222+
1223+ switch (scsi_status) {
1224+ case SAM_STAT_GOOD:
1225+ result |= DID_OK << 16 |
1226+ COMMAND_COMPLETE << 8 |
1227+ SAM_STAT_GOOD;
1228+ break;
1229+ case SAM_STAT_CHECK_CONDITION:
1230+ result |= DID_OK << 16 |
1231+ COMMAND_COMPLETE << 8 |
1232+ SAM_STAT_CHECK_CONDITION;
1233+ ufshcd_copy_sense_data(lrbp);
1234+ break;
1235+ case SAM_STAT_BUSY:
1236+ result |= SAM_STAT_BUSY;
1237+ break;
1238+ case SAM_STAT_TASK_SET_FULL:
1239+
1240+ /*
1241+ * If a LUN reports SAM_STAT_TASK_SET_FULL, then the LUN queue
1242+ * depth needs to be adjusted to the exact number of
1243+ * outstanding commands the LUN can handle at any given time.
1244+ */
1245+ ufshcd_adjust_lun_qdepth(lrbp->cmd);
1246+ result |= SAM_STAT_TASK_SET_FULL;
1247+ break;
1248+ case SAM_STAT_TASK_ABORTED:
1249+ result |= SAM_STAT_TASK_ABORTED;
1250+ break;
1251+ default:
1252+ result |= DID_ERROR << 16;
1253+ break;
1254+ } /* end of switch */
1255+
1256+ return result;
1257+}
1258+
1259+/**
1260+ * ufshcd_transfer_rsp_status - Get overall status of the response
1261+ * @hba: per adapter instance
1262+ * @lrb: pointer to local reference block of completed command
1263+ *
1264+ * Returns result of the command to notify SCSI midlayer
1265+ */
1266+static inline int
1267+ufshcd_transfer_rsp_status(struct ufs_hba *hba, struct ufshcd_lrb *lrbp)
1268+{
1269+ int result = 0;
1270+ int scsi_status;
1271+ int ocs;
1272+
1273+ /* overall command status of utrd */
1274+ ocs = ufshcd_get_tr_ocs(lrbp);
1275+
1276+ switch (ocs) {
1277+ case OCS_SUCCESS:
1278+
1279+ /* check if the returned transfer response is valid */
1280+ result = ufshcd_is_valid_req_rsp(lrbp->ucd_rsp_ptr);
1281+ if (result) {
1282+ dev_err(&hba->pdev->dev,
1283+ "Invalid response = %x\n", result);
1284+ break;
1285+ }
1286+
1287+ /*
1288+ * get the response UPIU result to extract
1289+ * the SCSI command status
1290+ */
1291+ result = ufshcd_get_rsp_upiu_result(lrbp->ucd_rsp_ptr);
1292+
1293+ /*
1294+ * get the result based on SCSI status response
1295+ * to notify the SCSI midlayer of the command status
1296+ */
1297+ scsi_status = result & MASK_SCSI_STATUS;
1298+ result = ufshcd_scsi_cmd_status(lrbp, scsi_status);
1299+ break;
1300+ case OCS_ABORTED:
1301+ result |= DID_ABORT << 16;
1302+ break;
1303+ case OCS_INVALID_CMD_TABLE_ATTR:
1304+ case OCS_INVALID_PRDT_ATTR:
1305+ case OCS_MISMATCH_DATA_BUF_SIZE:
1306+ case OCS_MISMATCH_RESP_UPIU_SIZE:
1307+ case OCS_PEER_COMM_FAILURE:
1308+ case OCS_FATAL_ERROR:
1309+ default:
1310+ result |= DID_ERROR << 16;
1311+ dev_err(&hba->pdev->dev,
1312+ "OCS error from controller = %x\n", ocs);
1313+ break;
1314+ } /* end of switch */
1315+
1316+ return result;
1317+}
1318+
1319+/**
1320+ * ufshcd_transfer_req_compl - handle SCSI and query command completion
1321+ * @hba: per adapter instance
1322+ */
1323+static void ufshcd_transfer_req_compl(struct ufs_hba *hba)
1324+{
1325+ struct ufshcd_lrb *lrb;
1326+ unsigned long completed_reqs;
1327+ u32 tr_doorbell;
1328+ int result;
1329+ int index;
1330+
1331+ lrb = hba->lrb;
1332+ tr_doorbell =
1333+ readl(hba->mmio_base + REG_UTP_TRANSFER_REQ_DOOR_BELL);
1334+ completed_reqs = tr_doorbell ^ hba->outstanding_reqs;
1335+
1336+ for (index = 0; index < hba->nutrs; index++) {
1337+ if (test_bit(index, &completed_reqs)) {
1338+
1339+ result = ufshcd_transfer_rsp_status(hba, &lrb[index]);
1340+
1341+ if (lrb[index].cmd) {
1342+ scsi_dma_unmap(lrb[index].cmd);
1343+ lrb[index].cmd->result = result;
1344+ lrb[index].cmd->scsi_done(lrb[index].cmd);
1345+
1346+ /* Mark completed command as NULL in LRB */
1347+ lrb[index].cmd = NULL;
1348+ }
1349+ } /* end of if */
1350+ } /* end of for */
1351+
1352+ /* clear corresponding bits of completed commands */
1353+ hba->outstanding_reqs ^= completed_reqs;
1354+
1355+ /* Reset interrupt aggregation counters */
1356+ ufshcd_config_int_aggr(hba, INT_AGGR_RESET);
1357+}
1358+
1359+/**
1360+ * ufshcd_uic_cc_handler - handle UIC command completion
1361+ * @work: pointer to a work queue structure
1362+ *
1363+ * Returns 0 on success, non-zero value on failure
1364+ */
1365+static void ufshcd_uic_cc_handler (struct work_struct *work)
1366+{
1367+ struct ufs_hba *hba;
1368+
1369+ hba = container_of(work, struct ufs_hba, uic_workq);
1370+
1371+ if ((hba->active_uic_cmd.command == UIC_CMD_DME_LINK_STARTUP) &&
1372+ !(ufshcd_get_uic_cmd_result(hba))) {
1373+
1374+ if (ufshcd_make_hba_operational(hba))
1375+ dev_err(&hba->pdev->dev,
1376+ "cc: hba not operational state\n");
1377+ return;
1378+ }
1379+}
1380+
1381+/**
1382+ * ufshcd_fatal_err_handler - handle fatal errors
1383+ * @hba: per adapter instance
1384+ */
1385+static void ufshcd_fatal_err_handler(struct work_struct *work)
1386+{
1387+ struct ufs_hba *hba;
1388+ hba = container_of(work, struct ufs_hba, feh_workq);
1389+
1390+ /* check if reset is already in progress */
1391+ if (hba->ufshcd_state != UFSHCD_STATE_RESET)
1392+ ufshcd_do_reset(hba);
1393+}
1394+
1395+/**
1396+ * ufshcd_err_handler - Check for fatal errors
1397+ * @work: pointer to a work queue structure
1398+ */
1399+static void ufshcd_err_handler(struct ufs_hba *hba)
1400+{
1401+ u32 reg;
1402+
1403+ if (hba->errors & INT_FATAL_ERRORS)
1404+ goto fatal_eh;
1405+
1406+ if (hba->errors & UIC_ERROR) {
1407+
1408+ reg = readl(hba->mmio_base +
1409+ REG_UIC_ERROR_CODE_PHY_ADAPTER_LAYER);
1410+ if (reg & UIC_DATA_LINK_LAYER_ERROR_PA_INIT)
1411+ goto fatal_eh;
1412+ }
1413+ return;
1414+fatal_eh:
1415+ hba->ufshcd_state = UFSHCD_STATE_ERROR;
1416+ schedule_work(&hba->feh_workq);
1417+}
1418+
1419+/**
1420+ * ufshcd_tmc_handler - handle task management function completion
1421+ * @hba: per adapter instance
1422+ */
1423+static void ufshcd_tmc_handler(struct ufs_hba *hba)
1424+{
1425+ u32 tm_doorbell;
1426+
1427+ tm_doorbell = readl(hba->mmio_base + REG_UTP_TASK_REQ_DOOR_BELL);
1428+ hba->tm_condition = tm_doorbell ^ hba->outstanding_tasks;
1429+ wake_up_interruptible(&hba->ufshcd_tm_wait_queue);
1430+}
1431+
1432+/**
1433+ * ufshcd_sl_intr - Interrupt service routine
1434+ * @hba: per adapter instance
1435+ * @intr_status: contains interrupts generated by the controller
1436+ */
1437+static void ufshcd_sl_intr(struct ufs_hba *hba, u32 intr_status)
1438+{
1439+ hba->errors = UFSHCD_ERROR_MASK & intr_status;
1440+ if (hba->errors)
1441+ ufshcd_err_handler(hba);
1442+
1443+ if (intr_status & UIC_COMMAND_COMPL)
1444+ schedule_work(&hba->uic_workq);
1445+
1446+ if (intr_status & UTP_TASK_REQ_COMPL)
1447+ ufshcd_tmc_handler(hba);
1448+
1449+ if (intr_status & UTP_TRANSFER_REQ_COMPL)
1450+ ufshcd_transfer_req_compl(hba);
1451+}
1452+
1453+/**
1454+ * ufshcd_intr - Main interrupt service routine
1455+ * @irq: irq number
1456+ * @__hba: pointer to adapter instance
1457+ *
1458+ * Returns IRQ_HANDLED - If interrupt is valid
1459+ * IRQ_NONE - If invalid interrupt
1460+ */
1461+static irqreturn_t ufshcd_intr(int irq, void *__hba)
1462+{
1463+ u32 intr_status;
1464+ irqreturn_t retval = IRQ_NONE;
1465+ struct ufs_hba *hba = __hba;
1466+
1467+ spin_lock(hba->host->host_lock);
1468+ intr_status = readl(hba->mmio_base + REG_INTERRUPT_STATUS);
1469+
1470+ if (intr_status) {
1471+ ufshcd_sl_intr(hba, intr_status);
1472+
1473+ /* If UFSHCI 1.0 then clear interrupt status register */
1474+ if (hba->ufs_version == UFSHCI_VERSION_10)
1475+ writel(intr_status,
1476+ (hba->mmio_base + REG_INTERRUPT_STATUS));
1477+ retval = IRQ_HANDLED;
1478+ }
1479+ spin_unlock(hba->host->host_lock);
1480+ return retval;
1481+}
1482+
1483+/**
1484+ * ufshcd_issue_tm_cmd - issues task management commands to controller
1485+ * @hba: per adapter instance
1486+ * @lrbp: pointer to local reference block
1487+ *
1488+ * Returns SUCCESS/FAILED
1489+ */
1490+static int
1491+ufshcd_issue_tm_cmd(struct ufs_hba *hba,
1492+ struct ufshcd_lrb *lrbp,
1493+ u8 tm_function)
1494+{
1495+ struct utp_task_req_desc *task_req_descp;
1496+ struct utp_upiu_task_req *task_req_upiup;
1497+ struct Scsi_Host *host;
1498+ unsigned long flags;
1499+ int free_slot = 0;
1500+ int err;
1501+
1502+ host = hba->host;
1503+
1504+ spin_lock_irqsave(host->host_lock, flags);
1505+
1506+ /* If task management queue is full */
1507+ free_slot = ufshcd_get_tm_free_slot(hba);
1508+ if (free_slot >= hba->nutmrs) {
1509+ spin_unlock_irqrestore(host->host_lock, flags);
1510+ dev_err(&hba->pdev->dev, "Task management queue full\n");
1511+ err = FAILED;
1512+ goto out;
1513+ }
1514+
1515+ task_req_descp = hba->utmrdl_base_addr;
1516+ task_req_descp += free_slot;
1517+
1518+ /* Configure task request descriptor */
1519+ task_req_descp->header.dword_0 = cpu_to_le32(UTP_REQ_DESC_INT_CMD);
1520+ task_req_descp->header.dword_2 =
1521+ cpu_to_le32(OCS_INVALID_COMMAND_STATUS);
1522+
1523+ /* Configure task request UPIU */
1524+ task_req_upiup =
1525+ (struct utp_upiu_task_req *) task_req_descp->task_req_upiu;
1526+ task_req_upiup->header.dword_0 =
1527+ cpu_to_be32(UPIU_HEADER_DWORD(UPIU_TRANSACTION_TASK_REQ, 0,
1528+ lrbp->lun, lrbp->task_tag));
1529+ task_req_upiup->header.dword_1 =
1530+ cpu_to_be32(UPIU_HEADER_DWORD(0, tm_function, 0, 0));
1531+
1532+ task_req_upiup->input_param1 = lrbp->lun;
1533+ task_req_upiup->input_param1 =
1534+ cpu_to_be32(task_req_upiup->input_param1);
1535+ task_req_upiup->input_param2 = lrbp->task_tag;
1536+ task_req_upiup->input_param2 =
1537+ cpu_to_be32(task_req_upiup->input_param2);
1538+
1539+ /* send command to the controller */
1540+ __set_bit(free_slot, &hba->outstanding_tasks);
1541+ writel((1 << free_slot),
1542+ (hba->mmio_base + REG_UTP_TASK_REQ_DOOR_BELL));
1543+
1544+ spin_unlock_irqrestore(host->host_lock, flags);
1545+
1546+ /* wait until the task management command is completed */
1547+ err =
1548+ wait_event_interruptible_timeout(hba->ufshcd_tm_wait_queue,
1549+ (test_bit(free_slot,
1550+ &hba->tm_condition) != 0),
1551+ 60 * HZ);
1552+ if (!err) {
1553+ dev_err(&hba->pdev->dev,
1554+ "Task management command timed-out\n");
1555+ err = FAILED;
1556+ goto out;
1557+ }
1558+ clear_bit(free_slot, &hba->tm_condition);
1559+ return ufshcd_task_req_compl(hba, free_slot);
1560+out:
1561+ return err;
1562+}
1563+
1564+/**
1565+ * ufshcd_device_reset - reset device and abort all the pending commands
1566+ * @cmd: SCSI command pointer
1567+ *
1568+ * Returns SUCCESS/FAILED
1569+ */
1570+static int ufshcd_device_reset(struct scsi_cmnd *cmd)
1571+{
1572+ struct Scsi_Host *host;
1573+ struct ufs_hba *hba;
1574+ unsigned int tag;
1575+ u32 pos;
1576+ int err;
1577+
1578+ host = cmd->device->host;
1579+ hba = shost_priv(host);
1580+ tag = cmd->request->tag;
1581+
1582+ err = ufshcd_issue_tm_cmd(hba, &hba->lrb[tag], UFS_LOGICAL_RESET);
1583+ if (err)
1584+ goto out;
1585+
1586+ for (pos = 0; pos < hba->nutrs; pos++) {
1587+ if (test_bit(pos, &hba->outstanding_reqs) &&
1588+ (hba->lrb[tag].lun == hba->lrb[pos].lun)) {
1589+
1590+ /* clear the respective UTRLCLR register bit */
1591+ ufshcd_utrl_clear(hba, pos);
1592+
1593+ clear_bit(pos, &hba->outstanding_reqs);
1594+
1595+ if (hba->lrb[pos].cmd) {
1596+ scsi_dma_unmap(hba->lrb[pos].cmd);
1597+ hba->lrb[pos].cmd->result =
1598+ DID_ABORT << 16;
1599+ hba->lrb[pos].cmd->scsi_done(cmd);
1600+ hba->lrb[pos].cmd = NULL;
1601+ }
1602+ }
1603+ } /* end of for */
1604+out:
1605+ return err;
1606+}
1607+
1608+/**
1609+ * ufshcd_host_reset - Main reset function registered with scsi layer
1610+ * @cmd: SCSI command pointer
1611+ *
1612+ * Returns SUCCESS/FAILED
1613+ */
1614+static int ufshcd_host_reset(struct scsi_cmnd *cmd)
1615+{
1616+ struct ufs_hba *hba;
1617+
1618+ hba = shost_priv(cmd->device->host);
1619+
1620+ if (hba->ufshcd_state == UFSHCD_STATE_RESET)
1621+ return SUCCESS;
1622+
1623+ return (ufshcd_do_reset(hba) == SUCCESS) ? SUCCESS : FAILED;
1624+}
1625+
1626+/**
1627+ * ufshcd_abort - abort a specific command
1628+ * @cmd: SCSI command pointer
1629+ *
1630+ * Returns SUCCESS/FAILED
1631+ */
1632+static int ufshcd_abort(struct scsi_cmnd *cmd)
1633+{
1634+ struct Scsi_Host *host;
1635+ struct ufs_hba *hba;
1636+ unsigned long flags;
1637+ unsigned int tag;
1638+ int err;
1639+
1640+ host = cmd->device->host;
1641+ hba = shost_priv(host);
1642+ tag = cmd->request->tag;
1643+
1644+ spin_lock_irqsave(host->host_lock, flags);
1645+
1646+ /* check if command is still pending */
1647+ if (!(test_bit(tag, &hba->outstanding_reqs))) {
1648+ err = FAILED;
1649+ spin_unlock_irqrestore(host->host_lock, flags);
1650+ goto out;
1651+ }
1652+ spin_unlock_irqrestore(host->host_lock, flags);
1653+
1654+ err = ufshcd_issue_tm_cmd(hba, &hba->lrb[tag], UFS_ABORT_TASK);
1655+ if (err)
1656+ goto out;
1657+
1658+ scsi_dma_unmap(cmd);
1659+
1660+ spin_lock_irqsave(host->host_lock, flags);
1661+
1662+ /* clear the respective UTRLCLR register bit */
1663+ ufshcd_utrl_clear(hba, tag);
1664+
1665+ __clear_bit(tag, &hba->outstanding_reqs);
1666+ hba->lrb[tag].cmd = NULL;
1667+ spin_unlock_irqrestore(host->host_lock, flags);
1668+out:
1669+ return err;
1670+}
1671+
1672+static struct scsi_host_template ufshcd_driver_template = {
1673+ .module = THIS_MODULE,
1674+ .name = UFSHCD,
1675+ .proc_name = UFSHCD,
1676+ .queuecommand = ufshcd_queuecommand,
1677+ .slave_alloc = ufshcd_slave_alloc,
1678+ .slave_destroy = ufshcd_slave_destroy,
1679+ .eh_abort_handler = ufshcd_abort,
1680+ .eh_device_reset_handler = ufshcd_device_reset,
1681+ .eh_host_reset_handler = ufshcd_host_reset,
1682+ .this_id = -1,
1683+ .sg_tablesize = SG_ALL,
1684+ .cmd_per_lun = UFSHCD_CMD_PER_LUN,
1685+ .can_queue = UFSHCD_CAN_QUEUE,
1686+};
1687+
1688+/**
1689+ * ufshcd_shutdown - main function to put the controller in reset state
1690+ * @pdev: pointer to PCI device handle
1691+ */
1692+static void ufshcd_shutdown(struct pci_dev *pdev)
1693+{
1694+ ufshcd_hba_stop((struct ufs_hba *)pci_get_drvdata(pdev));
1695+}
1696+
1697+#ifdef CONFIG_PM
1698+/**
1699+ * ufshcd_suspend - suspend power management function
1700+ * @pdev: pointer to PCI device handle
1701+ * @state: power state
1702+ *
1703+ * Returns -ENOSYS
1704+ */
1705+static int ufshcd_suspend(struct pci_dev *pdev, pm_message_t state)
1706+{
1707+ /*
1708+ * TODO:
1709+ * 1. Block SCSI requests from SCSI midlayer
1710+ * 2. Change the internal driver state to non operational
1711+ * 3. Set UTRLRSR and UTMRLRSR bits to zero
1712+ * 4. Wait until outstanding commands are completed
1713+ * 5. Set HCE to zero to send the UFS host controller to reset state
1714+ */
1715+
1716+ return -ENOSYS;
1717+}
1718+
1719+/**
1720+ * ufshcd_resume - resume power management function
1721+ * @pdev: pointer to PCI device handle
1722+ *
1723+ * Returns -ENOSYS
1724+ */
1725+static int ufshcd_resume(struct pci_dev *pdev)
1726+{
1727+ /*
1728+ * TODO:
1729+ * 1. Set HCE to 1, to start the UFS host controller
1730+ * initialization process
1731+ * 2. Set UTRLRSR and UTMRLRSR bits to 1
1732+ * 3. Change the internal driver state to operational
1733+ * 4. Unblock SCSI requests from SCSI midlayer
1734+ */
1735+
1736+ return -ENOSYS;
1737+}
1738+#endif /* CONFIG_PM */
1739+
1740+/**
1741+ * ufshcd_hba_free - free allocated memory for
1742+ * host memory space data structures
1743+ * @hba: per adapter instance
1744+ */
1745+static void ufshcd_hba_free(struct ufs_hba *hba)
1746+{
1747+ iounmap(hba->mmio_base);
1748+ ufshcd_free_hba_memory(hba);
1749+ pci_release_regions(hba->pdev);
1750+}
1751+
1752+/**
1753+ * ufshcd_remove - de-allocate PCI/SCSI host and host memory space
1754+ * data structure memory
1755+ * @pdev - pointer to PCI handle
1756+ */
1757+static void ufshcd_remove(struct pci_dev *pdev)
1758+{
1759+ struct ufs_hba *hba = pci_get_drvdata(pdev);
1760+
1761+ /* disable interrupts */
1762+ ufshcd_int_config(hba, UFSHCD_INT_DISABLE);
1763+ free_irq(pdev->irq, hba);
1764+
1765+ ufshcd_hba_stop(hba);
1766+ ufshcd_hba_free(hba);
1767+
1768+ scsi_remove_host(hba->host);
1769+ scsi_host_put(hba->host);
1770+ pci_set_drvdata(pdev, NULL);
1771+ pci_clear_master(pdev);
1772+ pci_disable_device(pdev);
1773+}
1774+
1775+/**
1776+ * ufshcd_set_dma_mask - Set dma mask based on the controller
1777+ * addressing capability
1778+ * @pdev: PCI device structure
1779+ *
1780+ * Returns 0 for success, non-zero for failure
1781+ */
1782+static int ufshcd_set_dma_mask(struct ufs_hba *hba)
1783+{
1784+ int err;
1785+ u64 dma_mask;
1786+
1787+ /*
1788+ * If controller supports 64 bit addressing mode, then set the DMA
1789+ * mask to 64-bit, else set the DMA mask to 32-bit
1790+ */
1791+ if (hba->capabilities & MASK_64_ADDRESSING_SUPPORT)
1792+ dma_mask = DMA_BIT_MASK(64);
1793+ else
1794+ dma_mask = DMA_BIT_MASK(32);
1795+
1796+ err = pci_set_dma_mask(hba->pdev, dma_mask);
1797+ if (err)
1798+ return err;
1799+
1800+ err = pci_set_consistent_dma_mask(hba->pdev, dma_mask);
1801+
1802+ return err;
1803+}
1804+
1805+/**
1806+ * ufshcd_probe - probe routine of the driver
1807+ * @pdev: pointer to PCI device handle
1808+ * @id: PCI device id
1809+ *
1810+ * Returns 0 on success, non-zero value on failure
1811+ */
1812+static int __devinit
1813+ufshcd_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1814+{
1815+ struct Scsi_Host *host;
1816+ struct ufs_hba *hba;
1817+ int err;
1818+
1819+ err = pci_enable_device(pdev);
1820+ if (err) {
1821+ dev_err(&pdev->dev, "pci_enable_device failed\n");
1822+ goto out_error;
1823+ }
1824+
1825+ pci_set_master(pdev);
1826+
1827+ host = scsi_host_alloc(&ufshcd_driver_template,
1828+ sizeof(struct ufs_hba));
1829+ if (!host) {
1830+ dev_err(&pdev->dev, "scsi_host_alloc failed\n");
1831+ err = -ENOMEM;
1832+ goto out_disable;
1833+ }
1834+ hba = shost_priv(host);
1835+
1836+ err = pci_request_regions(pdev, UFSHCD);
1837+ if (err < 0) {
1838+ dev_err(&pdev->dev, "request regions failed\n");
1839+ goto out_disable;
1840+ }
1841+
1842+ hba->mmio_base = pci_ioremap_bar(pdev, 0);
1843+ if (!hba->mmio_base) {
1844+ dev_err(&pdev->dev, "memory map failed\n");
1845+ err = -ENOMEM;
1846+ goto out_release_regions;
1847+ }
1848+
1849+ hba->host = host;
1850+ hba->pdev = pdev;
1851+
1852+ /* Read capabilities registers */
1853+ ufshcd_hba_capabilities(hba);
1854+
1855+ /* Get UFS version supported by the controller */
1856+ hba->ufs_version = ufshcd_get_ufs_version(hba);
1857+
1858+ err = ufshcd_set_dma_mask(hba);
1859+ if (err) {
1860+ dev_err(&pdev->dev, "set dma mask failed\n");
1861+ goto out_iounmap;
1862+ }
1863+
1864+ /* Allocate memory for host memory space */
1865+ err = ufshcd_memory_alloc(hba);
1866+ if (err) {
1867+ dev_err(&pdev->dev, "Memory allocation failed\n");
1868+ goto out_iounmap;
1869+ }
1870+
1871+ /* Configure LRB */
1872+ ufshcd_host_memory_configure(hba);
1873+
1874+ host->can_queue = hba->nutrs;
1875+ host->cmd_per_lun = hba->nutrs;
1876+ host->max_id = UFSHCD_MAX_ID;
1877+ host->max_lun = UFSHCD_MAX_LUNS;
1878+ host->max_channel = UFSHCD_MAX_CHANNEL;
1879+ host->unique_id = host->host_no;
1880+ host->max_cmd_len = MAX_CDB_SIZE;
1881+
1882+ /* Initailize wait queue for task management */
1883+ init_waitqueue_head(&hba->ufshcd_tm_wait_queue);
1884+
1885+ /* Initialize work queues */
1886+ INIT_WORK(&hba->uic_workq, ufshcd_uic_cc_handler);
1887+ INIT_WORK(&hba->feh_workq, ufshcd_fatal_err_handler);
1888+
1889+ /* IRQ registration */
1890+ err = request_irq(pdev->irq, ufshcd_intr, IRQF_SHARED, UFSHCD, hba);
1891+ if (err) {
1892+ dev_err(&pdev->dev, "request irq failed\n");
1893+ goto out_lrb_free;
1894+ }
1895+
1896+ /* Enable SCSI tag mapping */
1897+ err = scsi_init_shared_tag_map(host, host->can_queue);
1898+ if (err) {
1899+ dev_err(&pdev->dev, "init shared queue failed\n");
1900+ goto out_free_irq;
1901+ }
1902+
1903+ pci_set_drvdata(pdev, hba);
1904+
1905+ err = scsi_add_host(host, &pdev->dev);
1906+ if (err) {
1907+ dev_err(&pdev->dev, "scsi_add_host failed\n");
1908+ goto out_free_irq;
1909+ }
1910+
1911+ /* Initialization routine */
1912+ err = ufshcd_initialize_hba(hba);
1913+ if (err) {
1914+ dev_err(&pdev->dev, "Initialization failed\n");
1915+ goto out_free_irq;
1916+ }
1917+
1918+ return 0;
1919+
1920+out_free_irq:
1921+ free_irq(pdev->irq, hba);
1922+out_lrb_free:
1923+ ufshcd_free_hba_memory(hba);
1924+out_iounmap:
1925+ iounmap(hba->mmio_base);
1926+out_release_regions:
1927+ pci_release_regions(pdev);
1928+out_disable:
1929+ scsi_host_put(host);
1930+ pci_clear_master(pdev);
1931+ pci_disable_device(pdev);
1932+out_error:
1933+ return err;
1934+}
1935+
1936+static DEFINE_PCI_DEVICE_TABLE(ufshcd_pci_tbl) = {
1937+ { PCI_VENDOR_ID_SAMSUNG, 0xC00C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
1938+ { } /* terminate list */
1939+};
1940+
1941+MODULE_DEVICE_TABLE(pci, ufshcd_pci_tbl);
1942+
1943+static struct pci_driver ufshcd_pci_driver = {
1944+ .name = UFSHCD,
1945+ .id_table = ufshcd_pci_tbl,
1946+ .probe = ufshcd_probe,
1947+ .remove = __devexit_p(ufshcd_remove),
1948+ .shutdown = ufshcd_shutdown,
1949+#ifdef CONFIG_PM
1950+ .suspend = ufshcd_suspend,
1951+ .resume = ufshcd_resume,
1952+#endif
1953+};
1954+
1955+/**
1956+ * ufshcd_init - Driver registration routine
1957+ */
1958+static int __init ufshcd_init(void)
1959+{
1960+ return pci_register_driver(&ufshcd_pci_driver);
1961+}
1962+module_init(ufshcd_init);
1963+
1964+/**
1965+ * ufshcd_exit - Driver exit clean-up routine
1966+ */
1967+static void __exit ufshcd_exit(void)
1968+{
1969+ pci_unregister_driver(&ufshcd_pci_driver);
1970+}
1971+module_exit(ufshcd_exit);
1972+
1973+
1974+MODULE_AUTHOR("Santosh Yaragnavi <santosh.sy@samsung.com>, "
1975+ "Vinayak Holikatti <h.vinayak@samsung.com>");
1976+MODULE_DESCRIPTION("Generic UFS host controller driver");
1977+MODULE_LICENSE("GPL");
1978+MODULE_VERSION(UFSHCD_DRIVER_VERSION);
drivers/scsi/ufs/ufshci.h+376−0
@@ -0,0 +1,376 @@
1+/*
2+ * Universal Flash Storage Host controller driver
3+ *
4+ * This code is based on drivers/scsi/ufs/ufshci.h
5+ * Copyright (C) 2011-2012 Samsung India Software Operations
6+ *
7+ * Santosh Yaraganavi <santosh.sy@samsung.com>
8+ * Vinayak Holikatti <h.vinayak@samsung.com>
9+ *
10+ * This program is free software; you can redistribute it and/or
11+ * modify it under the terms of the GNU General Public License
12+ * as published by the Free Software Foundation; either version 2
13+ * of the License, or (at your option) any later version.
14+ *
15+ * This program is distributed in the hope that it will be useful,
16+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+ * GNU General Public License for more details.
19+ *
20+ * NO WARRANTY
21+ * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
22+ * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
23+ * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
24+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
25+ * solely responsible for determining the appropriateness of using and
26+ * distributing the Program and assumes all risks associated with its
27+ * exercise of rights under this Agreement, including but not limited to
28+ * the risks and costs of program errors, damage to or loss of data,
29+ * programs or equipment, and unavailability or interruption of operations.
30+
31+ * DISCLAIMER OF LIABILITY
32+ * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
33+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34+ * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
35+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37+ * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
38+ * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
39+
40+ * You should have received a copy of the GNU General Public License
41+ * along with this program; if not, write to the Free Software
42+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
43+ * USA.
44+ */
45+
46+#ifndef _UFSHCI_H
47+#define _UFSHCI_H
48+
49+enum {
50+ TASK_REQ_UPIU_SIZE_DWORDS = 8,
51+ TASK_RSP_UPIU_SIZE_DWORDS = 8,
52+ ALIGNED_UPIU_SIZE = 128,
53+};
54+
55+/* UFSHCI Registers */
56+enum {
57+ REG_CONTROLLER_CAPABILITIES = 0x00,
58+ REG_UFS_VERSION = 0x08,
59+ REG_CONTROLLER_DEV_ID = 0x10,
60+ REG_CONTROLLER_PROD_ID = 0x14,
61+ REG_INTERRUPT_STATUS = 0x20,
62+ REG_INTERRUPT_ENABLE = 0x24,
63+ REG_CONTROLLER_STATUS = 0x30,
64+ REG_CONTROLLER_ENABLE = 0x34,
65+ REG_UIC_ERROR_CODE_PHY_ADAPTER_LAYER = 0x38,
66+ REG_UIC_ERROR_CODE_DATA_LINK_LAYER = 0x3C,
67+ REG_UIC_ERROR_CODE_NETWORK_LAYER = 0x40,
68+ REG_UIC_ERROR_CODE_TRANSPORT_LAYER = 0x44,
69+ REG_UIC_ERROR_CODE_DME = 0x48,
70+ REG_UTP_TRANSFER_REQ_INT_AGG_CONTROL = 0x4C,
71+ REG_UTP_TRANSFER_REQ_LIST_BASE_L = 0x50,
72+ REG_UTP_TRANSFER_REQ_LIST_BASE_H = 0x54,
73+ REG_UTP_TRANSFER_REQ_DOOR_BELL = 0x58,
74+ REG_UTP_TRANSFER_REQ_LIST_CLEAR = 0x5C,
75+ REG_UTP_TRANSFER_REQ_LIST_RUN_STOP = 0x60,
76+ REG_UTP_TASK_REQ_LIST_BASE_L = 0x70,
77+ REG_UTP_TASK_REQ_LIST_BASE_H = 0x74,
78+ REG_UTP_TASK_REQ_DOOR_BELL = 0x78,
79+ REG_UTP_TASK_REQ_LIST_CLEAR = 0x7C,
80+ REG_UTP_TASK_REQ_LIST_RUN_STOP = 0x80,
81+ REG_UIC_COMMAND = 0x90,
82+ REG_UIC_COMMAND_ARG_1 = 0x94,
83+ REG_UIC_COMMAND_ARG_2 = 0x98,
84+ REG_UIC_COMMAND_ARG_3 = 0x9C,
85+};
86+
87+/* Controller capability masks */
88+enum {
89+ MASK_TRANSFER_REQUESTS_SLOTS = 0x0000001F,
90+ MASK_TASK_MANAGEMENT_REQUEST_SLOTS = 0x00070000,
91+ MASK_64_ADDRESSING_SUPPORT = 0x01000000,
92+ MASK_OUT_OF_ORDER_DATA_DELIVERY_SUPPORT = 0x02000000,
93+ MASK_UIC_DME_TEST_MODE_SUPPORT = 0x04000000,
94+};
95+
96+/* UFS Version 08h */
97+#define MINOR_VERSION_NUM_MASK UFS_MASK(0xFFFF, 0)
98+#define MAJOR_VERSION_NUM_MASK UFS_MASK(0xFFFF, 16)
99+
100+/* Controller UFSHCI version */
101+enum {
102+ UFSHCI_VERSION_10 = 0x00010000,
103+ UFSHCI_VERSION_11 = 0x00010100,
104+};
105+
106+/*
107+ * HCDDID - Host Controller Identification Descriptor
108+ * - Device ID and Device Class 10h
109+ */
110+#define DEVICE_CLASS UFS_MASK(0xFFFF, 0)
111+#define DEVICE_ID UFS_MASK(0xFF, 24)
112+
113+/*
114+ * HCPMID - Host Controller Identification Descriptor
115+ * - Product/Manufacturer ID 14h
116+ */
117+#define MANUFACTURE_ID_MASK UFS_MASK(0xFFFF, 0)
118+#define PRODUCT_ID_MASK UFS_MASK(0xFFFF, 16)
119+
120+#define UFS_BIT(x) (1L << (x))
121+
122+#define UTP_TRANSFER_REQ_COMPL UFS_BIT(0)
123+#define UIC_DME_END_PT_RESET UFS_BIT(1)
124+#define UIC_ERROR UFS_BIT(2)
125+#define UIC_TEST_MODE UFS_BIT(3)
126+#define UIC_POWER_MODE UFS_BIT(4)
127+#define UIC_HIBERNATE_EXIT UFS_BIT(5)
128+#define UIC_HIBERNATE_ENTER UFS_BIT(6)
129+#define UIC_LINK_LOST UFS_BIT(7)
130+#define UIC_LINK_STARTUP UFS_BIT(8)
131+#define UTP_TASK_REQ_COMPL UFS_BIT(9)
132+#define UIC_COMMAND_COMPL UFS_BIT(10)
133+#define DEVICE_FATAL_ERROR UFS_BIT(11)
134+#define CONTROLLER_FATAL_ERROR UFS_BIT(16)
135+#define SYSTEM_BUS_FATAL_ERROR UFS_BIT(17)
136+
137+#define UFSHCD_ERROR_MASK (UIC_ERROR |\
138+ DEVICE_FATAL_ERROR |\
139+ CONTROLLER_FATAL_ERROR |\
140+ SYSTEM_BUS_FATAL_ERROR)
141+
142+#define INT_FATAL_ERRORS (DEVICE_FATAL_ERROR |\
143+ CONTROLLER_FATAL_ERROR |\
144+ SYSTEM_BUS_FATAL_ERROR)
145+
146+/* HCS - Host Controller Status 30h */
147+#define DEVICE_PRESENT UFS_BIT(0)
148+#define UTP_TRANSFER_REQ_LIST_READY UFS_BIT(1)
149+#define UTP_TASK_REQ_LIST_READY UFS_BIT(2)
150+#define UIC_COMMAND_READY UFS_BIT(3)
151+#define HOST_ERROR_INDICATOR UFS_BIT(4)
152+#define DEVICE_ERROR_INDICATOR UFS_BIT(5)
153+#define UIC_POWER_MODE_CHANGE_REQ_STATUS_MASK UFS_MASK(0x7, 8)
154+
155+/* HCE - Host Controller Enable 34h */
156+#define CONTROLLER_ENABLE UFS_BIT(0)
157+#define CONTROLLER_DISABLE 0x0
158+
159+/* UECPA - Host UIC Error Code PHY Adapter Layer 38h */
160+#define UIC_PHY_ADAPTER_LAYER_ERROR UFS_BIT(31)
161+#define UIC_PHY_ADAPTER_LAYER_ERROR_CODE_MASK 0x1F
162+
163+/* UECDL - Host UIC Error Code Data Link Layer 3Ch */
164+#define UIC_DATA_LINK_LAYER_ERROR UFS_BIT(31)
165+#define UIC_DATA_LINK_LAYER_ERROR_CODE_MASK 0x7FFF
166+#define UIC_DATA_LINK_LAYER_ERROR_PA_INIT 0x2000
167+
168+/* UECN - Host UIC Error Code Network Layer 40h */
169+#define UIC_NETWORK_LAYER_ERROR UFS_BIT(31)
170+#define UIC_NETWORK_LAYER_ERROR_CODE_MASK 0x7
171+
172+/* UECT - Host UIC Error Code Transport Layer 44h */
173+#define UIC_TRANSPORT_LAYER_ERROR UFS_BIT(31)
174+#define UIC_TRANSPORT_LAYER_ERROR_CODE_MASK 0x7F
175+
176+/* UECDME - Host UIC Error Code DME 48h */
177+#define UIC_DME_ERROR UFS_BIT(31)
178+#define UIC_DME_ERROR_CODE_MASK 0x1
179+
180+#define INT_AGGR_TIMEOUT_VAL_MASK 0xFF
181+#define INT_AGGR_COUNTER_THRESHOLD_MASK UFS_MASK(0x1F, 8)
182+#define INT_AGGR_COUNTER_AND_TIMER_RESET UFS_BIT(16)
183+#define INT_AGGR_STATUS_BIT UFS_BIT(20)
184+#define INT_AGGR_PARAM_WRITE UFS_BIT(24)
185+#define INT_AGGR_ENABLE UFS_BIT(31)
186+
187+/* UTRLRSR - UTP Transfer Request Run-Stop Register 60h */
188+#define UTP_TRANSFER_REQ_LIST_RUN_STOP_BIT UFS_BIT(0)
189+
190+/* UTMRLRSR - UTP Task Management Request Run-Stop Register 80h */
191+#define UTP_TASK_REQ_LIST_RUN_STOP_BIT UFS_BIT(0)
192+
193+/* UICCMD - UIC Command */
194+#define COMMAND_OPCODE_MASK 0xFF
195+#define GEN_SELECTOR_INDEX_MASK 0xFFFF
196+
197+#define MIB_ATTRIBUTE_MASK UFS_MASK(0xFFFF, 16)
198+#define RESET_LEVEL 0xFF
199+
200+#define ATTR_SET_TYPE_MASK UFS_MASK(0xFF, 16)
201+#define CONFIG_RESULT_CODE_MASK 0xFF
202+#define GENERIC_ERROR_CODE_MASK 0xFF
203+
204+/* UIC Commands */
205+enum {
206+ UIC_CMD_DME_GET = 0x01,
207+ UIC_CMD_DME_SET = 0x02,
208+ UIC_CMD_DME_PEER_GET = 0x03,
209+ UIC_CMD_DME_PEER_SET = 0x04,
210+ UIC_CMD_DME_POWERON = 0x10,
211+ UIC_CMD_DME_POWEROFF = 0x11,
212+ UIC_CMD_DME_ENABLE = 0x12,
213+ UIC_CMD_DME_RESET = 0x14,
214+ UIC_CMD_DME_END_PT_RST = 0x15,
215+ UIC_CMD_DME_LINK_STARTUP = 0x16,
216+ UIC_CMD_DME_HIBER_ENTER = 0x17,
217+ UIC_CMD_DME_HIBER_EXIT = 0x18,
218+ UIC_CMD_DME_TEST_MODE = 0x1A,
219+};
220+
221+/* UIC Config result code / Generic error code */
222+enum {
223+ UIC_CMD_RESULT_SUCCESS = 0x00,
224+ UIC_CMD_RESULT_INVALID_ATTR = 0x01,
225+ UIC_CMD_RESULT_FAILURE = 0x01,
226+ UIC_CMD_RESULT_INVALID_ATTR_VALUE = 0x02,
227+ UIC_CMD_RESULT_READ_ONLY_ATTR = 0x03,
228+ UIC_CMD_RESULT_WRITE_ONLY_ATTR = 0x04,
229+ UIC_CMD_RESULT_BAD_INDEX = 0x05,
230+ UIC_CMD_RESULT_LOCKED_ATTR = 0x06,
231+ UIC_CMD_RESULT_BAD_TEST_FEATURE_INDEX = 0x07,
232+ UIC_CMD_RESULT_PEER_COMM_FAILURE = 0x08,
233+ UIC_CMD_RESULT_BUSY = 0x09,
234+ UIC_CMD_RESULT_DME_FAILURE = 0x0A,
235+};
236+
237+#define MASK_UIC_COMMAND_RESULT 0xFF
238+
239+#define INT_AGGR_COUNTER_THRESHOLD_VALUE (0x1F << 8)
240+#define INT_AGGR_TIMEOUT_VALUE (0x02)
241+
242+/* Interrupt disable masks */
243+enum {
244+ /* Interrupt disable mask for UFSHCI v1.0 */
245+ INTERRUPT_DISABLE_MASK_10 = 0xFFFF,
246+
247+ /* Interrupt disable mask for UFSHCI v1.1 */
248+ INTERRUPT_DISABLE_MASK_11 = 0x0,
249+};
250+
251+/*
252+ * Request Descriptor Definitions
253+ */
254+
255+/* Transfer request command type */
256+enum {
257+ UTP_CMD_TYPE_SCSI = 0x0,
258+ UTP_CMD_TYPE_UFS = 0x1,
259+ UTP_CMD_TYPE_DEV_MANAGE = 0x2,
260+};
261+
262+enum {
263+ UTP_SCSI_COMMAND = 0x00000000,
264+ UTP_NATIVE_UFS_COMMAND = 0x10000000,
265+ UTP_DEVICE_MANAGEMENT_FUNCTION = 0x20000000,
266+ UTP_REQ_DESC_INT_CMD = 0x01000000,
267+};
268+
269+/* UTP Transfer Request Data Direction (DD) */
270+enum {
271+ UTP_NO_DATA_TRANSFER = 0x00000000,
272+ UTP_HOST_TO_DEVICE = 0x02000000,
273+ UTP_DEVICE_TO_HOST = 0x04000000,
274+};
275+
276+/* Overall command status values */
277+enum {
278+ OCS_SUCCESS = 0x0,
279+ OCS_INVALID_CMD_TABLE_ATTR = 0x1,
280+ OCS_INVALID_PRDT_ATTR = 0x2,
281+ OCS_MISMATCH_DATA_BUF_SIZE = 0x3,
282+ OCS_MISMATCH_RESP_UPIU_SIZE = 0x4,
283+ OCS_PEER_COMM_FAILURE = 0x5,
284+ OCS_ABORTED = 0x6,
285+ OCS_FATAL_ERROR = 0x7,
286+ OCS_INVALID_COMMAND_STATUS = 0x0F,
287+ MASK_OCS = 0x0F,
288+};
289+
290+/**
291+ * struct ufshcd_sg_entry - UFSHCI PRD Entry
292+ * @base_addr: Lower 32bit physical address DW-0
293+ * @upper_addr: Upper 32bit physical address DW-1
294+ * @reserved: Reserved for future use DW-2
295+ * @size: size of physical segment DW-3
296+ */
297+struct ufshcd_sg_entry {
298+ u32 base_addr;
299+ u32 upper_addr;
300+ u32 reserved;
301+ u32 size;
302+};
303+
304+/**
305+ * struct utp_transfer_cmd_desc - UFS Command Descriptor structure
306+ * @command_upiu: Command UPIU Frame address
307+ * @response_upiu: Response UPIU Frame address
308+ * @prd_table: Physical Region Descriptor
309+ */
310+struct utp_transfer_cmd_desc {
311+ u8 command_upiu[ALIGNED_UPIU_SIZE];
312+ u8 response_upiu[ALIGNED_UPIU_SIZE];
313+ struct ufshcd_sg_entry prd_table[SG_ALL];
314+};
315+
316+/**
317+ * struct request_desc_header - Descriptor Header common to both UTRD and UTMRD
318+ * @dword0: Descriptor Header DW0
319+ * @dword1: Descriptor Header DW1
320+ * @dword2: Descriptor Header DW2
321+ * @dword3: Descriptor Header DW3
322+ */
323+struct request_desc_header {
324+ u32 dword_0;
325+ u32 dword_1;
326+ u32 dword_2;
327+ u32 dword_3;
328+};
329+
330+/**
331+ * struct utp_transfer_req_desc - UTRD structure
332+ * @header: UTRD header DW-0 to DW-3
333+ * @command_desc_base_addr_lo: UCD base address low DW-4
334+ * @command_desc_base_addr_hi: UCD base address high DW-5
335+ * @response_upiu_length: response UPIU length DW-6
336+ * @response_upiu_offset: response UPIU offset DW-6
337+ * @prd_table_length: Physical region descriptor length DW-7
338+ * @prd_table_offset: Physical region descriptor offset DW-7
339+ */
340+struct utp_transfer_req_desc {
341+
342+ /* DW 0-3 */
343+ struct request_desc_header header;
344+
345+ /* DW 4-5*/
346+ u32 command_desc_base_addr_lo;
347+ u32 command_desc_base_addr_hi;
348+
349+ /* DW 6 */
350+ u16 response_upiu_length;
351+ u16 response_upiu_offset;
352+
353+ /* DW 7 */
354+ u16 prd_table_length;
355+ u16 prd_table_offset;
356+};
357+
358+/**
359+ * struct utp_task_req_desc - UTMRD structure
360+ * @header: UTMRD header DW-0 to DW-3
361+ * @task_req_upiu: Pointer to task request UPIU DW-4 to DW-11
362+ * @task_rsp_upiu: Pointer to task response UPIU DW12 to DW-19
363+ */
364+struct utp_task_req_desc {
365+
366+ /* DW 0-3 */
367+ struct request_desc_header header;
368+
369+ /* DW 4-11 */
370+ u32 task_req_upiu[TASK_REQ_UPIU_SIZE_DWORDS];
371+
372+ /* DW 12-19 */
373+ u32 task_rsp_upiu[TASK_RSP_UPIU_SIZE_DWORDS];
374+};
375+
376+#endif /* End of Header */
drivers/scsi/vmw_pvscsi.c+64−1
@@ -17,7 +17,7 @@ · 16 unmodified lines
1717 * along with this program; if not, write to the Free Software
1818 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1919 *
20− * Maintained by: Alok N Kataria <akataria@vmware.com>
20+ * Maintained by: Arvind Kumar <arvindkumar@vmware.com>
2121 *
2222 */
2323
@@ -1178,11 +1178,67 @@ static int __devinit pvscsi_allocate_sg(struct pvscsi_adapter *adapter) · 1154 unmodified lines
11781178 return 0;
11791179 }
11801180
1181+/*
1182+ * Query the device, fetch the config info and return the
1183+ * maximum number of targets on the adapter. In case of
1184+ * failure due to any reason return default i.e. 16.
1185+ */
1186+static u32 pvscsi_get_max_targets(struct pvscsi_adapter *adapter)
1187+{
1188+ struct PVSCSICmdDescConfigCmd cmd;
1189+ struct PVSCSIConfigPageHeader *header;
1190+ struct device *dev;
1191+ dma_addr_t configPagePA;
1192+ void *config_page;
1193+ u32 numPhys = 16;
1194+
1195+ dev = pvscsi_dev(adapter);
1196+ config_page = pci_alloc_consistent(adapter->dev, PAGE_SIZE,
1197+ &configPagePA);
1198+ if (!config_page) {
1199+ dev_warn(dev, "vmw_pvscsi: failed to allocate memory for config page\n");
1200+ goto exit;
1201+ }
1202+ BUG_ON(configPagePA & ~PAGE_MASK);
1203+
1204+ /* Fetch config info from the device. */
1205+ cmd.configPageAddress = ((u64)PVSCSI_CONFIG_CONTROLLER_ADDRESS) << 32;
1206+ cmd.configPageNum = PVSCSI_CONFIG_PAGE_CONTROLLER;
1207+ cmd.cmpAddr = configPagePA;
1208+ cmd._pad = 0;
1209+
1210+ /*
1211+ * Mark the completion page header with error values. If the device
1212+ * completes the command successfully, it sets the status values to
1213+ * indicate success.
1214+ */
1215+ header = config_page;
1216+ memset(header, 0, sizeof *header);
1217+ header->hostStatus = BTSTAT_INVPARAM;
1218+ header->scsiStatus = SDSTAT_CHECK;
1219+
1220+ pvscsi_write_cmd_desc(adapter, PVSCSI_CMD_CONFIG, &cmd, sizeof cmd);
1221+
1222+ if (header->hostStatus == BTSTAT_SUCCESS &&
1223+ header->scsiStatus == SDSTAT_GOOD) {
1224+ struct PVSCSIConfigPageController *config;
1225+
1226+ config = config_page;
1227+ numPhys = config->numPhys;
1228+ } else
1229+ dev_warn(dev, "vmw_pvscsi: PVSCSI_CMD_CONFIG failed. hostStatus = 0x%x, scsiStatus = 0x%x\n",
1230+ header->hostStatus, header->scsiStatus);
1231+ pci_free_consistent(adapter->dev, PAGE_SIZE, config_page, configPagePA);
1232+exit:
1233+ return numPhys;
1234+}
1235+
11811236 static int __devinit pvscsi_probe(struct pci_dev *pdev,
11821237 const struct pci_device_id *id)
11831238 {
11841239 struct pvscsi_adapter *adapter;
11851240 struct Scsi_Host *host;
1241+ struct device *dev;
11861242 unsigned int i;
11871243 unsigned long flags = 0;
11881244 int error;
@@ -1271,6 +1327,13 @@ static int __devinit pvscsi_probe(struct pci_dev *pdev, · 82 unmodified lines
12711327 goto out_release_resources;
12721328 }
12731329
1330+ /*
1331+ * Ask the device for max number of targets.
1332+ */
1333+ host->max_id = pvscsi_get_max_targets(adapter);
1334+ dev = pvscsi_dev(adapter);
1335+ dev_info(dev, "vmw_pvscsi: host->max_id: %u\n", host->max_id);
1336+
12741337 /*
12751338 * From this point on we should reset the adapter if anything goes
12761339 * wrong.
drivers/scsi/vmw_pvscsi.h+85−24
@@ -17,7 +17,7 @@ · 16 unmodified lines
1717 * along with this program; if not, write to the Free Software
1818 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1919 *
20− * Maintained by: Alok N Kataria <akataria@vmware.com>
20+ * Maintained by: Arvind Kumar <arvindkumar@vmware.com>
2121 *
2222 */
2323
@@ -26,7 +26,7 @@ · 2 unmodified lines
2626
2727 #include <linux/types.h>
2828
29−#define PVSCSI_DRIVER_VERSION_STRING "1.0.1.0-k"
29+#define PVSCSI_DRIVER_VERSION_STRING "1.0.2.0-k"
3030
3131 #define PVSCSI_MAX_NUM_SG_ENTRIES_PER_SEGMENT 128
3232
@@ -39,28 +39,45 @@ · 6 unmodified lines
3939 * host adapter status/error codes
4040 */
4141 enum HostBusAdapterStatus {
42− BTSTAT_SUCCESS = 0x00, /* CCB complete normally with no errors */
43− BTSTAT_LINKED_COMMAND_COMPLETED = 0x0a,
44− BTSTAT_LINKED_COMMAND_COMPLETED_WITH_FLAG = 0x0b,
45− BTSTAT_DATA_UNDERRUN = 0x0c,
46− BTSTAT_SELTIMEO = 0x11, /* SCSI selection timeout */
47− BTSTAT_DATARUN = 0x12, /* data overrun/underrun */
48− BTSTAT_BUSFREE = 0x13, /* unexpected bus free */
49− BTSTAT_INVPHASE = 0x14, /* invalid bus phase or sequence requested by target */
50− BTSTAT_LUNMISMATCH = 0x17, /* linked CCB has different LUN from first CCB */
51− BTSTAT_SENSFAILED = 0x1b, /* auto request sense failed */
52− BTSTAT_TAGREJECT = 0x1c, /* SCSI II tagged queueing message rejected by target */
53− BTSTAT_BADMSG = 0x1d, /* unsupported message received by the host adapter */
54− BTSTAT_HAHARDWARE = 0x20, /* host adapter hardware failed */
55− BTSTAT_NORESPONSE = 0x21, /* target did not respond to SCSI ATN, sent a SCSI RST */
56− BTSTAT_SENTRST = 0x22, /* host adapter asserted a SCSI RST */
57− BTSTAT_RECVRST = 0x23, /* other SCSI devices asserted a SCSI RST */
58− BTSTAT_DISCONNECT = 0x24, /* target device reconnected improperly (w/o tag) */
59− BTSTAT_BUSRESET = 0x25, /* host adapter issued BUS device reset */
60− BTSTAT_ABORTQUEUE = 0x26, /* abort queue generated */
61− BTSTAT_HASOFTWARE = 0x27, /* host adapter software error */
62− BTSTAT_HATIMEOUT = 0x30, /* host adapter hardware timeout error */
63− BTSTAT_SCSIPARITY = 0x34, /* SCSI parity error detected */
42+ BTSTAT_SUCCESS = 0x00, /* CCB complete normally with no errors */
43+ BTSTAT_LINKED_COMMAND_COMPLETED = 0x0a,
44+ BTSTAT_LINKED_COMMAND_COMPLETED_WITH_FLAG = 0x0b,
45+ BTSTAT_DATA_UNDERRUN = 0x0c,
46+ BTSTAT_SELTIMEO = 0x11, /* SCSI selection timeout */
47+ BTSTAT_DATARUN = 0x12, /* data overrun/underrun */
48+ BTSTAT_BUSFREE = 0x13, /* unexpected bus free */
49+ BTSTAT_INVPHASE = 0x14, /* invalid bus phase or sequence
50+ * requested by target */
51+ BTSTAT_LUNMISMATCH = 0x17, /* linked CCB has different LUN from
52+ * first CCB */
53+ BTSTAT_INVPARAM = 0x1a, /* invalid parameter in CCB or segment
54+ * list */
55+ BTSTAT_SENSFAILED = 0x1b, /* auto request sense failed */
56+ BTSTAT_TAGREJECT = 0x1c, /* SCSI II tagged queueing message
57+ * rejected by target */
58+ BTSTAT_BADMSG = 0x1d, /* unsupported message received by the
59+ * host adapter */
60+ BTSTAT_HAHARDWARE = 0x20, /* host adapter hardware failed */
61+ BTSTAT_NORESPONSE = 0x21, /* target did not respond to SCSI ATN,
62+ * sent a SCSI RST */
63+ BTSTAT_SENTRST = 0x22, /* host adapter asserted a SCSI RST */
64+ BTSTAT_RECVRST = 0x23, /* other SCSI devices asserted a SCSI
65+ * RST */
66+ BTSTAT_DISCONNECT = 0x24, /* target device reconnected improperly
67+ * (w/o tag) */
68+ BTSTAT_BUSRESET = 0x25, /* host adapter issued BUS device reset */
69+ BTSTAT_ABORTQUEUE = 0x26, /* abort queue generated */
70+ BTSTAT_HASOFTWARE = 0x27, /* host adapter software error */
71+ BTSTAT_HATIMEOUT = 0x30, /* host adapter hardware timeout error */
72+ BTSTAT_SCSIPARITY = 0x34, /* SCSI parity error detected */
73+};
74+
75+/*
76+ * SCSI device status values.
77+ */
78+enum ScsiDeviceStatus {
79+ SDSTAT_GOOD = 0x00, /* No errors. */
80+ SDSTAT_CHECK = 0x02, /* Check condition. */
6481 };
6582
6683 /*
@@ -113,6 +130,29 @@ struct PVSCSICmdDescResetDevice { · 46 unmodified lines
113130 u8 lun[8];
114131 } __packed;
115132
133+/*
134+ * Command descriptor for PVSCSI_CMD_CONFIG --
135+ */
136+
137+struct PVSCSICmdDescConfigCmd {
138+ u64 cmpAddr;
139+ u64 configPageAddress;
140+ u32 configPageNum;
141+ u32 _pad;
142+} __packed;
143+
144+enum PVSCSIConfigPageType {
145+ PVSCSI_CONFIG_PAGE_CONTROLLER = 0x1958,
146+ PVSCSI_CONFIG_PAGE_PHY = 0x1959,
147+ PVSCSI_CONFIG_PAGE_DEVICE = 0x195a,
148+};
149+
150+enum PVSCSIConfigPageAddressType {
151+ PVSCSI_CONFIG_CONTROLLER_ADDRESS = 0x2120,
152+ PVSCSI_CONFIG_BUSTARGET_ADDRESS = 0x2121,
153+ PVSCSI_CONFIG_PHY_ADDRESS = 0x2122,
154+};
155+
116156 /*
117157 * Command descriptor for PVSCSI_CMD_ABORT_CMD --
118158 *
@@ -332,6 +372,27 @@ struct PVSCSIRingCmpDesc { · 213 unmodified lines
332372 u32 _pad[2];
333373 } __packed;
334374
375+struct PVSCSIConfigPageHeader {
376+ u32 pageNum;
377+ u16 numDwords;
378+ u16 hostStatus;
379+ u16 scsiStatus;
380+ u16 reserved[3];
381+} __packed;
382+
383+struct PVSCSIConfigPageController {
384+ struct PVSCSIConfigPageHeader header;
385+ u64 nodeWWN; /* Device name as defined in the SAS spec. */
386+ u16 manufacturer[64];
387+ u16 serialNumber[64];
388+ u16 opromVersion[32];
389+ u16 hwVersion[32];
390+ u16 firmwareVersion[32];
391+ u32 numPhys;
392+ u8 useConsecutivePhyWWNs;
393+ u8 reserved[3];
394+} __packed;
395+
335396 /*
336397 * Interrupt status / IRQ bits.
337398 */
include/linux/mtio.h+1−0
@@ -194,6 +194,7 @@ struct mtpos { · 193 unmodified lines
194194 #define MT_ST_SYSV 0x1000
195195 #define MT_ST_NOWAIT 0x2000
196196 #define MT_ST_SILI 0x4000
197+#define MT_ST_NOWAIT_EOF 0x8000
197198
198199 /* The mode parameters to be controlled. Parameter chosen with bits 20-28 */
199200 #define MT_ST_CLEAR_DEFAULT 0xfffff
include/scsi/iscsi_if.h+17−2
@@ -261,7 +261,8 @@ struct iscsi_uevent { · 260 unmodified lines
261261 } host_event;
262262 struct msg_ping_comp {
263263 uint32_t host_no;
264− uint32_t status;
264+ uint32_t status; /* enum
265+ * iscsi_ping_status_code */
265266 uint32_t pid; /* unique ping id associated
266267 with each ping request */
267268 uint32_t data_size;
@@ -483,6 +484,20 @@ enum iscsi_port_state { · 215 unmodified lines
483484 ISCSI_PORT_STATE_UP = 0x2,
484485 };
485486
487+/* iSCSI PING status/error code */
488+enum iscsi_ping_status_code {
489+ ISCSI_PING_SUCCESS = 0,
490+ ISCSI_PING_FW_DISABLED = 0x1,
491+ ISCSI_PING_IPADDR_INVALID = 0x2,
492+ ISCSI_PING_LINKLOCAL_IPV6_ADDR_INVALID = 0x3,
493+ ISCSI_PING_TIMEOUT = 0x4,
494+ ISCSI_PING_INVALID_DEST_ADDR = 0x5,
495+ ISCSI_PING_OVERSIZE_PACKET = 0x6,
496+ ISCSI_PING_ICMP_ERROR = 0x7,
497+ ISCSI_PING_MAX_REQ_EXCEEDED = 0x8,
498+ ISCSI_PING_NO_ARP_RECEIVED = 0x9,
499+};
500+
486501 #define iscsi_ptr(_handle) ((void*)(unsigned long)_handle)
487502 #define iscsi_handle(_ptr) ((uint64_t)(unsigned long)_ptr)
488503
@@ -578,6 +593,6 @@ struct iscsi_chap_rec { · 89 unmodified lines
578593 char username[ISCSI_CHAP_AUTH_NAME_MAX_LEN];
579594 uint8_t password[ISCSI_CHAP_AUTH_SECRET_MAX_LEN];
580595 uint8_t password_length;
581−} __packed;
596+};
582597
583598 #endif
include/scsi/libfcoe.h+3−1
@@ -165,7 +165,8 @@ struct fcoe_ctlr { · 164 unmodified lines
165165 * @switch_name: WWN of switch from advertisement
166166 * @fabric_name: WWN of fabric from advertisement
167167 * @fc_map: FC_MAP value from advertisement
168− * @fcf_mac: Ethernet address of the FCF
168+ * @fcf_mac: Ethernet address of the FCF for FIP traffic
169+ * @fcoe_mac: Ethernet address of the FCF for FCoE traffic
169170 * @vfid: virtual fabric ID
170171 * @pri: selection priority, smaller values are better
171172 * @flogi_sent: current FLOGI sent to this FCF
@@ -188,6 +189,7 @@ struct fcoe_fcf { · 16 unmodified lines
188189 u32 fc_map;
189190 u16 vfid;
190191 u8 fcf_mac[ETH_ALEN];
192+ u8 fcoe_mac[ETH_ALEN];
191193
192194 u8 pri;
193195 u8 flogi_sent;