aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorJames Smart <James.Smart@Emulex.Com>2008-08-24 21:49:00 -0400
committerJames Bottomley <James.Bottomley@HansenPartnership.com>2008-10-13 09:28:53 -0400
commite59058c44025d71c9b7f260076a932935d3bba95 (patch)
tree36cd4b31ac3b130849c5ad4d2c0cef035a7389dd /drivers
parent4a27446f3e39b06c28d1c8e31d33a5340826ed5c (diff)
[SCSI] lpfc 8.2.8 : Add kernel-doc function headers
Signed-off-by: James Smart <james.smart@emulex.com> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/scsi/lpfc/lpfc_attr.c919
-rw-r--r--drivers/scsi/lpfc/lpfc_debugfs.c327
-rw-r--r--drivers/scsi/lpfc/lpfc_els.c1345
-rw-r--r--drivers/scsi/lpfc/lpfc_init.c575
-rw-r--r--drivers/scsi/lpfc/lpfc_mbox.c468
-rw-r--r--drivers/scsi/lpfc/lpfc_mem.c115
-rw-r--r--drivers/scsi/lpfc/lpfc_sli.c1063
7 files changed, 4556 insertions, 256 deletions
diff --git a/drivers/scsi/lpfc/lpfc_attr.c b/drivers/scsi/lpfc/lpfc_attr.c
index 37bfa0bd1dae..2926a2a7ee70 100644
--- a/drivers/scsi/lpfc/lpfc_attr.c
+++ b/drivers/scsi/lpfc/lpfc_attr.c
@@ -49,6 +49,21 @@
49#define LPFC_LINK_SPEED_BITMAP 0x00000117 49#define LPFC_LINK_SPEED_BITMAP 0x00000117
50#define LPFC_LINK_SPEED_STRING "0, 1, 2, 4, 8" 50#define LPFC_LINK_SPEED_STRING "0, 1, 2, 4, 8"
51 51
52/**
53 * lpfc_jedec_to_ascii: Hex to ascii convertor according to JEDEC rules.
54 * @incr: integer to convert.
55 * @hdw: ascii string holding converted integer plus a string terminator.
56 *
57 * Description:
58 * JEDEC Joint Electron Device Engineering Council.
59 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
60 * character string. The string is then terminated with a NULL in byte 9.
61 * Hex 0-9 becomes ascii '0' to '9'.
62 * Hex a-f becomes ascii '=' to 'B' capital B.
63 *
64 * Notes:
65 * Coded for 32 bit integers only.
66 **/
52static void 67static void
53lpfc_jedec_to_ascii(int incr, char hdw[]) 68lpfc_jedec_to_ascii(int incr, char hdw[])
54{ 69{
@@ -65,6 +80,14 @@ lpfc_jedec_to_ascii(int incr, char hdw[])
65 return; 80 return;
66} 81}
67 82
83/**
84 * lpfc_drvr_version_show: Return the Emulex driver string with version number.
85 * @dev: class unused variable.
86 * @attr: device attribute, not used.
87 * @buf: on return contains the module description text.
88 *
89 * Returns: size of formatted string.
90 **/
68static ssize_t 91static ssize_t
69lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr, 92lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
70 char *buf) 93 char *buf)
@@ -72,6 +95,14 @@ lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
72 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n"); 95 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
73} 96}
74 97
98/**
99 * lpfc_info_show: Return some pci info about the host in ascii.
100 * @dev: class converted to a Scsi_host structure.
101 * @attr: device attribute, not used.
102 * @buf: on return contains the formatted text from lpfc_info().
103 *
104 * Returns: size of formatted string.
105 **/
75static ssize_t 106static ssize_t
76lpfc_info_show(struct device *dev, struct device_attribute *attr, 107lpfc_info_show(struct device *dev, struct device_attribute *attr,
77 char *buf) 108 char *buf)
@@ -81,6 +112,14 @@ lpfc_info_show(struct device *dev, struct device_attribute *attr,
81 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host)); 112 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
82} 113}
83 114
115/**
116 * lpfc_serialnum_show: Return the hba serial number in ascii.
117 * @dev: class converted to a Scsi_host structure.
118 * @attr: device attribute, not used.
119 * @buf: on return contains the formatted text serial number.
120 *
121 * Returns: size of formatted string.
122 **/
84static ssize_t 123static ssize_t
85lpfc_serialnum_show(struct device *dev, struct device_attribute *attr, 124lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
86 char *buf) 125 char *buf)
@@ -92,6 +131,18 @@ lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
92 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber); 131 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
93} 132}
94 133
134/**
135 * lpfc_temp_sensor_show: Return the temperature sensor level.
136 * @dev: class converted to a Scsi_host structure.
137 * @attr: device attribute, not used.
138 * @buf: on return contains the formatted support level.
139 *
140 * Description:
141 * Returns a number indicating the temperature sensor level currently
142 * supported, zero or one in ascii.
143 *
144 * Returns: size of formatted string.
145 **/
95static ssize_t 146static ssize_t
96lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr, 147lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
97 char *buf) 148 char *buf)
@@ -102,6 +153,14 @@ lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
102 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support); 153 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
103} 154}
104 155
156/**
157 * lpfc_modeldesc_show: Return the model description of the hba.
158 * @dev: class converted to a Scsi_host structure.
159 * @attr: device attribute, not used.
160 * @buf: on return contains the scsi vpd model description.
161 *
162 * Returns: size of formatted string.
163 **/
105static ssize_t 164static ssize_t
106lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr, 165lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
107 char *buf) 166 char *buf)
@@ -113,6 +172,14 @@ lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
113 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc); 172 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
114} 173}
115 174
175/**
176 * lpfc_modelname_show: Return the model name of the hba.
177 * @dev: class converted to a Scsi_host structure.
178 * @attr: device attribute, not used.
179 * @buf: on return contains the scsi vpd model name.
180 *
181 * Returns: size of formatted string.
182 **/
116static ssize_t 183static ssize_t
117lpfc_modelname_show(struct device *dev, struct device_attribute *attr, 184lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
118 char *buf) 185 char *buf)
@@ -124,6 +191,14 @@ lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
124 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName); 191 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
125} 192}
126 193
194/**
195 * lpfc_programtype_show: Return the program type of the hba.
196 * @dev: class converted to a Scsi_host structure.
197 * @attr: device attribute, not used.
198 * @buf: on return contains the scsi vpd program type.
199 *
200 * Returns: size of formatted string.
201 **/
127static ssize_t 202static ssize_t
128lpfc_programtype_show(struct device *dev, struct device_attribute *attr, 203lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
129 char *buf) 204 char *buf)
@@ -135,6 +210,14 @@ lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
135 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType); 210 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
136} 211}
137 212
213/**
214 * lpfc_vportnum_show: Return the port number in ascii of the hba.
215 * @dev: class converted to a Scsi_host structure.
216 * @attr: device attribute, not used.
217 * @buf: on return contains scsi vpd program type.
218 *
219 * Returns: size of formatted string.
220 **/
138static ssize_t 221static ssize_t
139lpfc_vportnum_show(struct device *dev, struct device_attribute *attr, 222lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
140 char *buf) 223 char *buf)
@@ -146,6 +229,14 @@ lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
146 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port); 229 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
147} 230}
148 231
232/**
233 * lpfc_fwrev_show: Return the firmware rev running in the hba.
234 * @dev: class converted to a Scsi_host structure.
235 * @attr: device attribute, not used.
236 * @buf: on return contains the scsi vpd program type.
237 *
238 * Returns: size of formatted string.
239 **/
149static ssize_t 240static ssize_t
150lpfc_fwrev_show(struct device *dev, struct device_attribute *attr, 241lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
151 char *buf) 242 char *buf)
@@ -159,6 +250,14 @@ lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
159 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev); 250 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
160} 251}
161 252
253/**
254 * lpfc_hdw_show: Return the jedec information about the hba.
255 * @dev: class converted to a Scsi_host structure.
256 * @attr: device attribute, not used.
257 * @buf: on return contains the scsi vpd program type.
258 *
259 * Returns: size of formatted string.
260 **/
162static ssize_t 261static ssize_t
163lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf) 262lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
164{ 263{
@@ -171,6 +270,15 @@ lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
171 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw); 270 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
172 return snprintf(buf, PAGE_SIZE, "%s\n", hdw); 271 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
173} 272}
273
274/**
275 * lpfc_option_rom_version_show: Return the adapter ROM FCode version.
276 * @dev: class converted to a Scsi_host structure.
277 * @attr: device attribute, not used.
278 * @buf: on return contains the ROM and FCode ascii strings.
279 *
280 * Returns: size of formatted string.
281 **/
174static ssize_t 282static ssize_t
175lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr, 283lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
176 char *buf) 284 char *buf)
@@ -181,6 +289,18 @@ lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
181 289
182 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion); 290 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
183} 291}
292
293/**
294 * lpfc_state_show: Return the link state of the port.
295 * @dev: class converted to a Scsi_host structure.
296 * @attr: device attribute, not used.
297 * @buf: on return contains text describing the state of the link.
298 *
299 * Notes:
300 * The switch statement has no default so zero will be returned.
301 *
302 * Returns: size of formatted string.
303 **/
184static ssize_t 304static ssize_t
185lpfc_link_state_show(struct device *dev, struct device_attribute *attr, 305lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
186 char *buf) 306 char *buf)
@@ -253,6 +373,18 @@ lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
253 return len; 373 return len;
254} 374}
255 375
376/**
377 * lpfc_num_discovered_ports_show: Return sum of mapped and unmapped vports.
378 * @dev: class device that is converted into a Scsi_host.
379 * @attr: device attribute, not used.
380 * @buf: on return contains the sum of fc mapped and unmapped.
381 *
382 * Description:
383 * Returns the ascii text number of the sum of the fc mapped and unmapped
384 * vport counts.
385 *
386 * Returns: size of formatted string.
387 **/
256static ssize_t 388static ssize_t
257lpfc_num_discovered_ports_show(struct device *dev, 389lpfc_num_discovered_ports_show(struct device *dev,
258 struct device_attribute *attr, char *buf) 390 struct device_attribute *attr, char *buf)
@@ -264,7 +396,20 @@ lpfc_num_discovered_ports_show(struct device *dev,
264 vport->fc_map_cnt + vport->fc_unmap_cnt); 396 vport->fc_map_cnt + vport->fc_unmap_cnt);
265} 397}
266 398
267 399/**
400 * lpfc_issue_lip: Misnomer, name carried over from long ago.
401 * @shost: Scsi_Host pointer.
402 *
403 * Description:
404 * Bring the link down gracefully then re-init the link. The firmware will
405 * re-init the fiber channel interface as required. Does not issue a LIP.
406 *
407 * Returns:
408 * -EPERM port offline or management commands are being blocked
409 * -ENOMEM cannot allocate memory for the mailbox command
410 * -EIO error sending the mailbox command
411 * zero for success
412 **/
268static int 413static int
269lpfc_issue_lip(struct Scsi_Host *shost) 414lpfc_issue_lip(struct Scsi_Host *shost)
270{ 415{
@@ -306,6 +451,21 @@ lpfc_issue_lip(struct Scsi_Host *shost)
306 return 0; 451 return 0;
307} 452}
308 453
454/**
455 * lpfc_do_offline: Issues a mailbox command to bring the link down.
456 * @phba: lpfc_hba pointer.
457 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
458 *
459 * Notes:
460 * Assumes any error from lpfc_do_offline() will be negative.
461 * Can wait up to 5 seconds for the port ring buffers count
462 * to reach zero, prints a warning if it is not zero and continues.
463 * lpfc_workq_post_event() returns a non-zero return coce if call fails.
464 *
465 * Returns:
466 * -EIO error posting the event
467 * zero for success
468 **/
309static int 469static int
310lpfc_do_offline(struct lpfc_hba *phba, uint32_t type) 470lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
311{ 471{
@@ -353,6 +513,22 @@ lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
353 return 0; 513 return 0;
354} 514}
355 515
516/**
517 * lpfc_selective_reset: Offline then onlines the port.
518 * @phba: lpfc_hba pointer.
519 *
520 * Description:
521 * If the port is configured to allow a reset then the hba is brought
522 * offline then online.
523 *
524 * Notes:
525 * Assumes any error from lpfc_do_offline() will be negative.
526 *
527 * Returns:
528 * lpfc_do_offline() return code if not zero
529 * -EIO reset not configured or error posting the event
530 * zero for success
531 **/
356static int 532static int
357lpfc_selective_reset(struct lpfc_hba *phba) 533lpfc_selective_reset(struct lpfc_hba *phba)
358{ 534{
@@ -378,6 +554,27 @@ lpfc_selective_reset(struct lpfc_hba *phba)
378 return 0; 554 return 0;
379} 555}
380 556
557/**
558 * lpfc_issue_reset: Selectively resets an adapter.
559 * @dev: class device that is converted into a Scsi_host.
560 * @attr: device attribute, not used.
561 * @buf: containing the string "selective".
562 * @count: unused variable.
563 *
564 * Description:
565 * If the buf contains the string "selective" then lpfc_selective_reset()
566 * is called to perform the reset.
567 *
568 * Notes:
569 * Assumes any error from lpfc_selective_reset() will be negative.
570 * If lpfc_selective_reset() returns zero then the length of the buffer
571 * is returned which indicates succcess
572 *
573 * Returns:
574 * -EINVAL if the buffer does not contain the string "selective"
575 * length of buf if lpfc-selective_reset() if the call succeeds
576 * return value of lpfc_selective_reset() if the call fails
577**/
381static ssize_t 578static ssize_t
382lpfc_issue_reset(struct device *dev, struct device_attribute *attr, 579lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
383 const char *buf, size_t count) 580 const char *buf, size_t count)
@@ -397,6 +594,14 @@ lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
397 return status; 594 return status;
398} 595}
399 596
597/**
598 * lpfc_nport_evt_cnt_show: Return the number of nport events.
599 * @dev: class device that is converted into a Scsi_host.
600 * @attr: device attribute, not used.
601 * @buf: on return contains the ascii number of nport events.
602 *
603 * Returns: size of formatted string.
604 **/
400static ssize_t 605static ssize_t
401lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr, 606lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
402 char *buf) 607 char *buf)
@@ -408,6 +613,14 @@ lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
408 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt); 613 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
409} 614}
410 615
616/**
617 * lpfc_board_mode_show: Return the state of the board.
618 * @dev: class device that is converted into a Scsi_host.
619 * @attr: device attribute, not used.
620 * @buf: on return contains the state of the adapter.
621 *
622 * Returns: size of formatted string.
623 **/
411static ssize_t 624static ssize_t
412lpfc_board_mode_show(struct device *dev, struct device_attribute *attr, 625lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
413 char *buf) 626 char *buf)
@@ -429,6 +642,19 @@ lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
429 return snprintf(buf, PAGE_SIZE, "%s\n", state); 642 return snprintf(buf, PAGE_SIZE, "%s\n", state);
430} 643}
431 644
645/**
646 * lpfc_board_mode_store: Puts the hba in online, offline, warm or error state.
647 * @dev: class device that is converted into a Scsi_host.
648 * @attr: device attribute, not used.
649 * @buf: containing one of the strings "online", "offline", "warm" or "error".
650 * @count: unused variable.
651 *
652 * Returns:
653 * -EACCES if enable hba reset not enabled
654 * -EINVAL if the buffer does not contain a valid string (see above)
655 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
656 * buf length greater than zero indicates success
657 **/
432static ssize_t 658static ssize_t
433lpfc_board_mode_store(struct device *dev, struct device_attribute *attr, 659lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
434 const char *buf, size_t count) 660 const char *buf, size_t count)
@@ -462,6 +688,24 @@ lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
462 return -EIO; 688 return -EIO;
463} 689}
464 690
691/**
692 * lpfc_get_hba_info: Return various bits of informaton about the adapter.
693 * @phba: pointer to the adapter structure.
694 * @mxri max xri count.
695 * @axri available xri count.
696 * @mrpi max rpi count.
697 * @arpi available rpi count.
698 * @mvpi max vpi count.
699 * @avpi available vpi count.
700 *
701 * Description:
702 * If an integer pointer for an count is not null then the value for the
703 * count is returned.
704 *
705 * Returns:
706 * zero on error
707 * one for success
708 **/
465static int 709static int
466lpfc_get_hba_info(struct lpfc_hba *phba, 710lpfc_get_hba_info(struct lpfc_hba *phba,
467 uint32_t *mxri, uint32_t *axri, 711 uint32_t *mxri, uint32_t *axri,
@@ -524,6 +768,20 @@ lpfc_get_hba_info(struct lpfc_hba *phba,
524 return 1; 768 return 1;
525} 769}
526 770
771/**
772 * lpfc_max_rpi_show: Return maximum rpi.
773 * @dev: class device that is converted into a Scsi_host.
774 * @attr: device attribute, not used.
775 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
776 *
777 * Description:
778 * Calls lpfc_get_hba_info() asking for just the mrpi count.
779 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
780 * to "Unknown" and the buffer length is returned, therefore the caller
781 * must check for "Unknown" in the buffer to detect a failure.
782 *
783 * Returns: size of formatted string.
784 **/
527static ssize_t 785static ssize_t
528lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr, 786lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
529 char *buf) 787 char *buf)
@@ -538,6 +796,20 @@ lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
538 return snprintf(buf, PAGE_SIZE, "Unknown\n"); 796 return snprintf(buf, PAGE_SIZE, "Unknown\n");
539} 797}
540 798
799/**
800 * lpfc_used_rpi_show: Return maximum rpi minus available rpi.
801 * @dev: class device that is converted into a Scsi_host.
802 * @attr: device attribute, not used.
803 * @buf: containing the used rpi count in decimal or "Unknown".
804 *
805 * Description:
806 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
807 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
808 * to "Unknown" and the buffer length is returned, therefore the caller
809 * must check for "Unknown" in the buffer to detect a failure.
810 *
811 * Returns: size of formatted string.
812 **/
541static ssize_t 813static ssize_t
542lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr, 814lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
543 char *buf) 815 char *buf)
@@ -552,6 +824,20 @@ lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
552 return snprintf(buf, PAGE_SIZE, "Unknown\n"); 824 return snprintf(buf, PAGE_SIZE, "Unknown\n");
553} 825}
554 826
827/**
828 * lpfc_max_xri_show: Return maximum xri.
829 * @dev: class device that is converted into a Scsi_host.
830 * @attr: device attribute, not used.
831 * @buf: on return contains the maximum xri count in decimal or "Unknown".
832 *
833 * Description:
834 * Calls lpfc_get_hba_info() asking for just the mrpi count.
835 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
836 * to "Unknown" and the buffer length is returned, therefore the caller
837 * must check for "Unknown" in the buffer to detect a failure.
838 *
839 * Returns: size of formatted string.
840 **/
555static ssize_t 841static ssize_t
556lpfc_max_xri_show(struct device *dev, struct device_attribute *attr, 842lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
557 char *buf) 843 char *buf)
@@ -566,6 +852,20 @@ lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
566 return snprintf(buf, PAGE_SIZE, "Unknown\n"); 852 return snprintf(buf, PAGE_SIZE, "Unknown\n");
567} 853}
568 854
855/**
856 * lpfc_used_xri_show: Return maximum xpi minus the available xpi.
857 * @dev: class device that is converted into a Scsi_host.
858 * @attr: device attribute, not used.
859 * @buf: on return contains the used xri count in decimal or "Unknown".
860 *
861 * Description:
862 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
863 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
864 * to "Unknown" and the buffer length is returned, therefore the caller
865 * must check for "Unknown" in the buffer to detect a failure.
866 *
867 * Returns: size of formatted string.
868 **/
569static ssize_t 869static ssize_t
570lpfc_used_xri_show(struct device *dev, struct device_attribute *attr, 870lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
571 char *buf) 871 char *buf)
@@ -580,6 +880,20 @@ lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
580 return snprintf(buf, PAGE_SIZE, "Unknown\n"); 880 return snprintf(buf, PAGE_SIZE, "Unknown\n");
581} 881}
582 882
883/**
884 * lpfc_max_vpi_show: Return maximum vpi.
885 * @dev: class device that is converted into a Scsi_host.
886 * @attr: device attribute, not used.
887 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
888 *
889 * Description:
890 * Calls lpfc_get_hba_info() asking for just the mvpi count.
891 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
892 * to "Unknown" and the buffer length is returned, therefore the caller
893 * must check for "Unknown" in the buffer to detect a failure.
894 *
895 * Returns: size of formatted string.
896 **/
583static ssize_t 897static ssize_t
584lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr, 898lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
585 char *buf) 899 char *buf)
@@ -594,6 +908,20 @@ lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
594 return snprintf(buf, PAGE_SIZE, "Unknown\n"); 908 return snprintf(buf, PAGE_SIZE, "Unknown\n");
595} 909}
596 910
911/**
912 * lpfc_used_vpi_show: Return maximum vpi minus the available vpi.
913 * @dev: class device that is converted into a Scsi_host.
914 * @attr: device attribute, not used.
915 * @buf: on return contains the used vpi count in decimal or "Unknown".
916 *
917 * Description:
918 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
919 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
920 * to "Unknown" and the buffer length is returned, therefore the caller
921 * must check for "Unknown" in the buffer to detect a failure.
922 *
923 * Returns: size of formatted string.
924 **/
597static ssize_t 925static ssize_t
598lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr, 926lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
599 char *buf) 927 char *buf)
@@ -608,6 +936,19 @@ lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
608 return snprintf(buf, PAGE_SIZE, "Unknown\n"); 936 return snprintf(buf, PAGE_SIZE, "Unknown\n");
609} 937}
610 938
939/**
940 * lpfc_npiv_info_show: Return text about NPIV support for the adapter.
941 * @dev: class device that is converted into a Scsi_host.
942 * @attr: device attribute, not used.
943 * @buf: text that must be interpreted to determine if npiv is supported.
944 *
945 * Description:
946 * Buffer will contain text indicating npiv is not suppoerted on the port,
947 * the port is an NPIV physical port, or it is an npiv virtual port with
948 * the id of the vport.
949 *
950 * Returns: size of formatted string.
951 **/
611static ssize_t 952static ssize_t
612lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr, 953lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
613 char *buf) 954 char *buf)
@@ -623,6 +964,17 @@ lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
623 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi); 964 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
624} 965}
625 966
967/**
968 * lpfc_poll_show: Return text about poll support for the adapter.
969 * @dev: class device that is converted into a Scsi_host.
970 * @attr: device attribute, not used.
971 * @buf: on return contains the cfg_poll in hex.
972 *
973 * Notes:
974 * cfg_poll should be a lpfc_polling_flags type.
975 *
976 * Returns: size of formatted string.
977 **/
626static ssize_t 978static ssize_t
627lpfc_poll_show(struct device *dev, struct device_attribute *attr, 979lpfc_poll_show(struct device *dev, struct device_attribute *attr,
628 char *buf) 980 char *buf)
@@ -634,6 +986,20 @@ lpfc_poll_show(struct device *dev, struct device_attribute *attr,
634 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll); 986 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
635} 987}
636 988
989/**
990 * lpfc_poll_store: Set the value of cfg_poll for the adapter.
991 * @dev: class device that is converted into a Scsi_host.
992 * @attr: device attribute, not used.
993 * @buf: one or more lpfc_polling_flags values.
994 * @count: not used.
995 *
996 * Notes:
997 * buf contents converted to integer and checked for a valid value.
998 *
999 * Returns:
1000 * -EINVAL if the buffer connot be converted or is out of range
1001 * length of the buf on success
1002 **/
637static ssize_t 1003static ssize_t
638lpfc_poll_store(struct device *dev, struct device_attribute *attr, 1004lpfc_poll_store(struct device *dev, struct device_attribute *attr,
639 const char *buf, size_t count) 1005 const char *buf, size_t count)
@@ -692,6 +1058,20 @@ lpfc_poll_store(struct device *dev, struct device_attribute *attr,
692 return strlen(buf); 1058 return strlen(buf);
693} 1059}
694 1060
1061/**
1062 * lpfc_param_show: Return a cfg attribute value in decimal.
1063 *
1064 * Description:
1065 * Macro that given an attr e.g. hba_queue_depth expands
1066 * into a function with the name lpfc_hba_queue_depth_show.
1067 *
1068 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1069 * @dev: class device that is converted into a Scsi_host.
1070 * @attr: device attribute, not used.
1071 * @buf: on return contains the attribute value in decimal.
1072 *
1073 * Returns: size of formatted string.
1074 **/
695#define lpfc_param_show(attr) \ 1075#define lpfc_param_show(attr) \
696static ssize_t \ 1076static ssize_t \
697lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \ 1077lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
@@ -706,6 +1086,20 @@ lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
706 phba->cfg_##attr);\ 1086 phba->cfg_##attr);\
707} 1087}
708 1088
1089/**
1090 * lpfc_param_hex_show: Return a cfg attribute value in hex.
1091 *
1092 * Description:
1093 * Macro that given an attr e.g. hba_queue_depth expands
1094 * into a function with the name lpfc_hba_queue_depth_show
1095 *
1096 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1097 * @dev: class device that is converted into a Scsi_host.
1098 * @attr: device attribute, not used.
1099 * @buf: on return contains the attribute value in hexidecimal.
1100 *
1101 * Returns: size of formatted string.
1102 **/
709#define lpfc_param_hex_show(attr) \ 1103#define lpfc_param_hex_show(attr) \
710static ssize_t \ 1104static ssize_t \
711lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \ 1105lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
@@ -720,6 +1114,25 @@ lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
720 phba->cfg_##attr);\ 1114 phba->cfg_##attr);\
721} 1115}
722 1116
1117/**
1118 * lpfc_param_init: Intializes a cfg attribute.
1119 *
1120 * Description:
1121 * Macro that given an attr e.g. hba_queue_depth expands
1122 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1123 * takes a default argument, a minimum and maximum argument.
1124 *
1125 * lpfc_##attr##_init: Initializes an attribute.
1126 * @phba: pointer the the adapter structure.
1127 * @val: integer attribute value.
1128 *
1129 * Validates the min and max values then sets the adapter config field
1130 * accordingly, or uses the default if out of range and prints an error message.
1131 *
1132 * Returns:
1133 * zero on success
1134 * -EINVAL if default used
1135 **/
723#define lpfc_param_init(attr, default, minval, maxval) \ 1136#define lpfc_param_init(attr, default, minval, maxval) \
724static int \ 1137static int \
725lpfc_##attr##_init(struct lpfc_hba *phba, int val) \ 1138lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
@@ -735,6 +1148,26 @@ lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
735 return -EINVAL;\ 1148 return -EINVAL;\
736} 1149}
737 1150
1151/**
1152 * lpfc_param_set: Set a cfg attribute value.
1153 *
1154 * Description:
1155 * Macro that given an attr e.g. hba_queue_depth expands
1156 * into a function with the name lpfc_hba_queue_depth_set
1157 *
1158 * lpfc_##attr##_set: Sets an attribute value.
1159 * @phba: pointer the the adapter structure.
1160 * @val: integer attribute value.
1161 *
1162 * Description:
1163 * Validates the min and max values then sets the
1164 * adapter config field if in the valid range. prints error message
1165 * and does not set the parameter if invalid.
1166 *
1167 * Returns:
1168 * zero on success
1169 * -EINVAL if val is invalid
1170 **/
738#define lpfc_param_set(attr, default, minval, maxval) \ 1171#define lpfc_param_set(attr, default, minval, maxval) \
739static int \ 1172static int \
740lpfc_##attr##_set(struct lpfc_hba *phba, int val) \ 1173lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
@@ -749,6 +1182,27 @@ lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
749 return -EINVAL;\ 1182 return -EINVAL;\
750} 1183}
751 1184
1185/**
1186 * lpfc_param_store: Set a vport attribute value.
1187 *
1188 * Description:
1189 * Macro that given an attr e.g. hba_queue_depth expands
1190 * into a function with the name lpfc_hba_queue_depth_store.
1191 *
1192 * lpfc_##attr##_store: Set an sttribute value.
1193 * @dev: class device that is converted into a Scsi_host.
1194 * @attr: device attribute, not used.
1195 * @buf: contains the attribute value in ascii.
1196 * @count: not used.
1197 *
1198 * Description:
1199 * Convert the ascii text number to an integer, then
1200 * use the lpfc_##attr##_set function to set the value.
1201 *
1202 * Returns:
1203 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1204 * length of buffer upon success.
1205 **/
752#define lpfc_param_store(attr) \ 1206#define lpfc_param_store(attr) \
753static ssize_t \ 1207static ssize_t \
754lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \ 1208lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
@@ -768,6 +1222,20 @@ lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
768 return -EINVAL;\ 1222 return -EINVAL;\
769} 1223}
770 1224
1225/**
1226 * lpfc_vport_param_show: Return decimal formatted cfg attribute value.
1227 *
1228 * Description:
1229 * Macro that given an attr e.g. hba_queue_depth expands
1230 * into a function with the name lpfc_hba_queue_depth_show
1231 *
1232 * lpfc_##attr##_show: prints the attribute value in decimal.
1233 * @dev: class device that is converted into a Scsi_host.
1234 * @attr: device attribute, not used.
1235 * @buf: on return contains the attribute value in decimal.
1236 *
1237 * Returns: length of formatted string.
1238 **/
771#define lpfc_vport_param_show(attr) \ 1239#define lpfc_vport_param_show(attr) \
772static ssize_t \ 1240static ssize_t \
773lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \ 1241lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
@@ -780,6 +1248,21 @@ lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
780 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\ 1248 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
781} 1249}
782 1250
1251/**
1252 * lpfc_vport_param_hex_show: Return hex formatted attribute value.
1253 *
1254 * Description:
1255 * Macro that given an attr e.g.
1256 * hba_queue_depth expands into a function with the name
1257 * lpfc_hba_queue_depth_show
1258 *
1259 * lpfc_##attr##_show: prints the attribute value in hexidecimal.
1260 * @dev: class device that is converted into a Scsi_host.
1261 * @attr: device attribute, not used.
1262 * @buf: on return contains the attribute value in hexidecimal.
1263 *
1264 * Returns: length of formatted string.
1265 **/
783#define lpfc_vport_param_hex_show(attr) \ 1266#define lpfc_vport_param_hex_show(attr) \
784static ssize_t \ 1267static ssize_t \
785lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \ 1268lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
@@ -792,6 +1275,24 @@ lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
792 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\ 1275 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
793} 1276}
794 1277
1278/**
1279 * lpfc_vport_param_init: Initialize a vport cfg attribute.
1280 *
1281 * Description:
1282 * Macro that given an attr e.g. hba_queue_depth expands
1283 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1284 * takes a default argument, a minimum and maximum argument.
1285 *
1286 * lpfc_##attr##_init: validates the min and max values then sets the
1287 * adapter config field accordingly, or uses the default if out of range
1288 * and prints an error message.
1289 * @phba: pointer the the adapter structure.
1290 * @val: integer attribute value.
1291 *
1292 * Returns:
1293 * zero on success
1294 * -EINVAL if default used
1295 **/
795#define lpfc_vport_param_init(attr, default, minval, maxval) \ 1296#define lpfc_vport_param_init(attr, default, minval, maxval) \
796static int \ 1297static int \
797lpfc_##attr##_init(struct lpfc_vport *vport, int val) \ 1298lpfc_##attr##_init(struct lpfc_vport *vport, int val) \
@@ -807,6 +1308,23 @@ lpfc_##attr##_init(struct lpfc_vport *vport, int val) \
807 return -EINVAL;\ 1308 return -EINVAL;\
808} 1309}
809 1310
1311/**
1312 * lpfc_vport_param_set: Set a vport cfg attribute.
1313 *
1314 * Description:
1315 * Macro that given an attr e.g. hba_queue_depth expands
1316 * into a function with the name lpfc_hba_queue_depth_set
1317 *
1318 * lpfc_##attr##_set: validates the min and max values then sets the
1319 * adapter config field if in the valid range. prints error message
1320 * and does not set the parameter if invalid.
1321 * @phba: pointer the the adapter structure.
1322 * @val: integer attribute value.
1323 *
1324 * Returns:
1325 * zero on success
1326 * -EINVAL if val is invalid
1327 **/
810#define lpfc_vport_param_set(attr, default, minval, maxval) \ 1328#define lpfc_vport_param_set(attr, default, minval, maxval) \
811static int \ 1329static int \
812lpfc_##attr##_set(struct lpfc_vport *vport, int val) \ 1330lpfc_##attr##_set(struct lpfc_vport *vport, int val) \
@@ -821,6 +1339,23 @@ lpfc_##attr##_set(struct lpfc_vport *vport, int val) \
821 return -EINVAL;\ 1339 return -EINVAL;\
822} 1340}
823 1341
1342/**
1343 * lpfc_vport_param_store: Set a vport attribute.
1344 *
1345 * Description:
1346 * Macro that given an attr e.g. hba_queue_depth
1347 * expands into a function with the name lpfc_hba_queue_depth_store
1348 *
1349 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1350 * use the lpfc_##attr##_set function to set the value.
1351 * @cdev: class device that is converted into a Scsi_host.
1352 * @buf: contains the attribute value in decimal.
1353 * @count: not used.
1354 *
1355 * Returns:
1356 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1357 * length of buffer upon success.
1358 **/
824#define lpfc_vport_param_store(attr) \ 1359#define lpfc_vport_param_store(attr) \
825static ssize_t \ 1360static ssize_t \
826lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \ 1361lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
@@ -958,6 +1493,17 @@ static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
958 1493
959static char *lpfc_soft_wwn_key = "C99G71SL8032A"; 1494static char *lpfc_soft_wwn_key = "C99G71SL8032A";
960 1495
1496/**
1497 * lpfc_soft_wwn_enable_store: Allows setting of the wwn if the key is valid.
1498 * @dev: class device that is converted into a Scsi_host.
1499 * @attr: device attribute, not used.
1500 * @buf: containing the string lpfc_soft_wwn_key.
1501 * @count: must be size of lpfc_soft_wwn_key.
1502 *
1503 * Returns:
1504 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1505 * length of buf indicates success
1506 **/
961static ssize_t 1507static ssize_t
962lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr, 1508lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
963 const char *buf, size_t count) 1509 const char *buf, size_t count)
@@ -994,6 +1540,14 @@ lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
994static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL, 1540static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
995 lpfc_soft_wwn_enable_store); 1541 lpfc_soft_wwn_enable_store);
996 1542
1543/**
1544 * lpfc_soft_wwpn_show: Return the cfg soft ww port name of the adapter.
1545 * @dev: class device that is converted into a Scsi_host.
1546 * @attr: device attribute, not used.
1547 * @buf: on return contains the wwpn in hexidecimal.
1548 *
1549 * Returns: size of formatted string.
1550 **/
997static ssize_t 1551static ssize_t
998lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr, 1552lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
999 char *buf) 1553 char *buf)
@@ -1006,7 +1560,19 @@ lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
1006 (unsigned long long)phba->cfg_soft_wwpn); 1560 (unsigned long long)phba->cfg_soft_wwpn);
1007} 1561}
1008 1562
1009 1563/**
1564 * lpfc_soft_wwpn_store: Set the ww port name of the adapter.
1565 * @dev class device that is converted into a Scsi_host.
1566 * @attr: device attribute, not used.
1567 * @buf: contains the wwpn in hexidecimal.
1568 * @count: number of wwpn bytes in buf
1569 *
1570 * Returns:
1571 * -EACCES hba reset not enabled, adapter over temp
1572 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
1573 * -EIO error taking adapter offline or online
1574 * value of count on success
1575 **/
1010static ssize_t 1576static ssize_t
1011lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr, 1577lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
1012 const char *buf, size_t count) 1578 const char *buf, size_t count)
@@ -1080,6 +1646,14 @@ lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
1080static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\ 1646static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1081 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store); 1647 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
1082 1648
1649/**
1650 * lpfc_soft_wwnn_show: Return the cfg soft ww node name for the adapter.
1651 * @dev: class device that is converted into a Scsi_host.
1652 * @attr: device attribute, not used.
1653 * @buf: on return contains the wwnn in hexidecimal.
1654 *
1655 * Returns: size of formatted string.
1656 **/
1083static ssize_t 1657static ssize_t
1084lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr, 1658lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
1085 char *buf) 1659 char *buf)
@@ -1090,7 +1664,16 @@ lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
1090 (unsigned long long)phba->cfg_soft_wwnn); 1664 (unsigned long long)phba->cfg_soft_wwnn);
1091} 1665}
1092 1666
1093 1667/**
1668 * lpfc_soft_wwnn_store: sets the ww node name of the adapter.
1669 * @cdev: class device that is converted into a Scsi_host.
1670 * @buf: contains the ww node name in hexidecimal.
1671 * @count: number of wwnn bytes in buf.
1672 *
1673 * Returns:
1674 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
1675 * value of count on success
1676 **/
1094static ssize_t 1677static ssize_t
1095lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr, 1678lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
1096 const char *buf, size_t count) 1679 const char *buf, size_t count)
@@ -1178,6 +1761,15 @@ module_param(lpfc_nodev_tmo, int, 0);
1178MODULE_PARM_DESC(lpfc_nodev_tmo, 1761MODULE_PARM_DESC(lpfc_nodev_tmo,
1179 "Seconds driver will hold I/O waiting " 1762 "Seconds driver will hold I/O waiting "
1180 "for a device to come back"); 1763 "for a device to come back");
1764
1765/**
1766 * lpfc_nodev_tmo_show: Return the hba dev loss timeout value.
1767 * @dev: class converted to a Scsi_host structure.
1768 * @attr: device attribute, not used.
1769 * @buf: on return contains the dev loss timeout in decimal.
1770 *
1771 * Returns: size of formatted string.
1772 **/
1181static ssize_t 1773static ssize_t
1182lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr, 1774lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
1183 char *buf) 1775 char *buf)
@@ -1189,6 +1781,21 @@ lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
1189 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo); 1781 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
1190} 1782}
1191 1783
1784/**
1785 * lpfc_nodev_tmo_init: Set the hba nodev timeout value.
1786 * @vport: lpfc vport structure pointer.
1787 * @val: contains the nodev timeout value.
1788 *
1789 * Description:
1790 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
1791 * a kernel error message is printed and zero is returned.
1792 * Else if val is in range then nodev tmo and devloss tmo are set to val.
1793 * Otherwise nodev tmo is set to the default value.
1794 *
1795 * Returns:
1796 * zero if already set or if val is in range
1797 * -EINVAL val out of range
1798 **/
1192static int 1799static int
1193lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val) 1800lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
1194{ 1801{
@@ -1215,6 +1822,13 @@ lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
1215 return -EINVAL; 1822 return -EINVAL;
1216} 1823}
1217 1824
1825/**
1826 * lpfc_update_rport_devloss_tmo: Update dev loss tmo value.
1827 * @vport: lpfc vport structure pointer.
1828 *
1829 * Description:
1830 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
1831 **/
1218static void 1832static void
1219lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport) 1833lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
1220{ 1834{
@@ -1229,6 +1843,21 @@ lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
1229 spin_unlock_irq(shost->host_lock); 1843 spin_unlock_irq(shost->host_lock);
1230} 1844}
1231 1845
1846/**
1847 * lpfc_nodev_tmo_set: Set the vport nodev tmo and devloss tmo values.
1848 * @vport: lpfc vport structure pointer.
1849 * @val: contains the tmo value.
1850 *
1851 * Description:
1852 * If the devloss tmo is already set or the vport dev loss tmo has changed
1853 * then a kernel error message is printed and zero is returned.
1854 * Else if val is in range then nodev tmo and devloss tmo are set to val.
1855 * Otherwise nodev tmo is set to the default value.
1856 *
1857 * Returns:
1858 * zero if already set or if val is in range
1859 * -EINVAL val out of range
1860 **/
1232static int 1861static int
1233lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val) 1862lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
1234{ 1863{
@@ -1269,6 +1898,21 @@ MODULE_PARM_DESC(lpfc_devloss_tmo,
1269lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO, 1898lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
1270 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO) 1899 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
1271lpfc_vport_param_show(devloss_tmo) 1900lpfc_vport_param_show(devloss_tmo)
1901
1902/**
1903 * lpfc_devloss_tmo_set: Sets vport nodev tmo, devloss tmo values, changed bit.
1904 * @vport: lpfc vport structure pointer.
1905 * @val: contains the tmo value.
1906 *
1907 * Description:
1908 * If val is in a valid range then set the vport nodev tmo,
1909 * devloss tmo, also set the vport dev loss tmo changed flag.
1910 * Else a kernel error message is printed.
1911 *
1912 * Returns:
1913 * zero if val is in range
1914 * -EINVAL val out of range
1915 **/
1272static int 1916static int
1273lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val) 1917lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
1274{ 1918{
@@ -1366,6 +2010,21 @@ MODULE_PARM_DESC(lpfc_restrict_login,
1366 "Restrict virtual ports login to remote initiators."); 2010 "Restrict virtual ports login to remote initiators.");
1367lpfc_vport_param_show(restrict_login); 2011lpfc_vport_param_show(restrict_login);
1368 2012
2013/**
2014 * lpfc_restrict_login_init: Set the vport restrict login flag.
2015 * @vport: lpfc vport structure pointer.
2016 * @val: contains the restrict login value.
2017 *
2018 * Description:
2019 * If val is not in a valid range then log a kernel error message and set
2020 * the vport restrict login to one.
2021 * If the port type is physical clear the restrict login flag and return.
2022 * Else set the restrict login flag to val.
2023 *
2024 * Returns:
2025 * zero if val is in range
2026 * -EINVAL val out of range
2027 **/
1369static int 2028static int
1370lpfc_restrict_login_init(struct lpfc_vport *vport, int val) 2029lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
1371{ 2030{
@@ -1385,6 +2044,22 @@ lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
1385 return 0; 2044 return 0;
1386} 2045}
1387 2046
2047/**
2048 * lpfc_restrict_login_set: Set the vport restrict login flag.
2049 * @vport: lpfc vport structure pointer.
2050 * @val: contains the restrict login value.
2051 *
2052 * Description:
2053 * If val is not in a valid range then log a kernel error message and set
2054 * the vport restrict login to one.
2055 * If the port type is physical and the val is not zero log a kernel
2056 * error message, clear the restrict login flag and return zero.
2057 * Else set the restrict login flag to val.
2058 *
2059 * Returns:
2060 * zero if val is in range
2061 * -EINVAL val out of range
2062 **/
1388static int 2063static int
1389lpfc_restrict_login_set(struct lpfc_vport *vport, int val) 2064lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
1390{ 2065{
@@ -1441,6 +2116,23 @@ LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
1441# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6]. 2116# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
1442# Default value is 0. 2117# Default value is 0.
1443*/ 2118*/
2119
2120/**
2121 * lpfc_topology_set: Set the adapters topology field.
2122 * @phba: lpfc_hba pointer.
2123 * @val: topology value.
2124 *
2125 * Description:
2126 * If val is in a valid range then set the adapter's topology field and
2127 * issue a lip; if the lip fails reset the topology to the old value.
2128 *
2129 * If the value is not in range log a kernel error message and return an error.
2130 *
2131 * Returns:
2132 * zero if val is in range and lip okay
2133 * non-zero return value from lpfc_issue_lip()
2134 * -EINVAL val out of range
2135 **/
1444static int 2136static int
1445lpfc_topology_set(struct lpfc_hba *phba, int val) 2137lpfc_topology_set(struct lpfc_hba *phba, int val)
1446{ 2138{
@@ -1479,6 +2171,24 @@ static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
1479# 8 = 8 Gigabaud 2171# 8 = 8 Gigabaud
1480# Value range is [0,8]. Default value is 0. 2172# Value range is [0,8]. Default value is 0.
1481*/ 2173*/
2174
2175/**
2176 * lpfc_link_speed_set: Set the adapters link speed.
2177 * @phba: lpfc_hba pointer.
2178 * @val: link speed value.
2179 *
2180 * Description:
2181 * If val is in a valid range then set the adapter's link speed field and
2182 * issue a lip; if the lip fails reset the link speed to the old value.
2183 *
2184 * Notes:
2185 * If the value is not in range log a kernel error message and return an error.
2186 *
2187 * Returns:
2188 * zero if val is in range and lip okay.
2189 * non-zero return value from lpfc_issue_lip()
2190 * -EINVAL val out of range
2191 **/
1482static int 2192static int
1483lpfc_link_speed_set(struct lpfc_hba *phba, int val) 2193lpfc_link_speed_set(struct lpfc_hba *phba, int val)
1484{ 2194{
@@ -1513,6 +2223,23 @@ static int lpfc_link_speed = 0;
1513module_param(lpfc_link_speed, int, 0); 2223module_param(lpfc_link_speed, int, 0);
1514MODULE_PARM_DESC(lpfc_link_speed, "Select link speed"); 2224MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
1515lpfc_param_show(link_speed) 2225lpfc_param_show(link_speed)
2226
2227/**
2228 * lpfc_link_speed_init: Set the adapters link speed.
2229 * @phba: lpfc_hba pointer.
2230 * @val: link speed value.
2231 *
2232 * Description:
2233 * If val is in a valid range then set the adapter's link speed field.
2234 *
2235 * Notes:
2236 * If the value is not in range log a kernel error message, clear the link
2237 * speed and return an error.
2238 *
2239 * Returns:
2240 * zero if val saved.
2241 * -EINVAL val out of range
2242 **/
1516static int 2243static int
1517lpfc_link_speed_init(struct lpfc_hba *phba, int val) 2244lpfc_link_speed_init(struct lpfc_hba *phba, int val)
1518{ 2245{
@@ -1734,6 +2461,24 @@ struct device_attribute *lpfc_vport_attrs[] = {
1734 NULL, 2461 NULL,
1735}; 2462};
1736 2463
2464/**
2465 * sysfs_ctlreg_write: Write method for writing to ctlreg.
2466 * @kobj: kernel kobject that contains the kernel class device.
2467 * @bin_attr: kernel attributes passed to us.
2468 * @buf: contains the data to be written to the adapter IOREG space.
2469 * @off: offset into buffer to beginning of data.
2470 * @count: bytes to transfer.
2471 *
2472 * Description:
2473 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
2474 * Uses the adapter io control registers to send buf contents to the adapter.
2475 *
2476 * Returns:
2477 * -ERANGE off and count combo out of range
2478 * -EINVAL off, count or buff address invalid
2479 * -EPERM adapter is offline
2480 * value of count, buf contents written
2481 **/
1737static ssize_t 2482static ssize_t
1738sysfs_ctlreg_write(struct kobject *kobj, struct bin_attribute *bin_attr, 2483sysfs_ctlreg_write(struct kobject *kobj, struct bin_attribute *bin_attr,
1739 char *buf, loff_t off, size_t count) 2484 char *buf, loff_t off, size_t count)
@@ -1766,6 +2511,23 @@ sysfs_ctlreg_write(struct kobject *kobj, struct bin_attribute *bin_attr,
1766 return count; 2511 return count;
1767} 2512}
1768 2513
2514/**
2515 * sysfs_ctlreg_read: Read method for reading from ctlreg.
2516 * @kobj: kernel kobject that contains the kernel class device.
2517 * @bin_attr: kernel attributes passed to us.
2518 * @buf: if succesful contains the data from the adapter IOREG space.
2519 * @off: offset into buffer to beginning of data.
2520 * @count: bytes to transfer.
2521 *
2522 * Description:
2523 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
2524 * Uses the adapter io control registers to read data into buf.
2525 *
2526 * Returns:
2527 * -ERANGE off and count combo out of range
2528 * -EINVAL off, count or buff address invalid
2529 * value of count, buf contents read
2530 **/
1769static ssize_t 2531static ssize_t
1770sysfs_ctlreg_read(struct kobject *kobj, struct bin_attribute *bin_attr, 2532sysfs_ctlreg_read(struct kobject *kobj, struct bin_attribute *bin_attr,
1771 char *buf, loff_t off, size_t count) 2533 char *buf, loff_t off, size_t count)
@@ -1810,7 +2572,10 @@ static struct bin_attribute sysfs_ctlreg_attr = {
1810 .write = sysfs_ctlreg_write, 2572 .write = sysfs_ctlreg_write,
1811}; 2573};
1812 2574
1813 2575/**
2576 * sysfs_mbox_idle: frees the sysfs mailbox.
2577 * @phba: lpfc_hba pointer
2578 **/
1814static void 2579static void
1815sysfs_mbox_idle(struct lpfc_hba *phba) 2580sysfs_mbox_idle(struct lpfc_hba *phba)
1816{ 2581{
@@ -1824,6 +2589,27 @@ sysfs_mbox_idle(struct lpfc_hba *phba)
1824 } 2589 }
1825} 2590}
1826 2591
2592/**
2593 * sysfs_mbox_write: Write method for writing information via mbox.
2594 * @kobj: kernel kobject that contains the kernel class device.
2595 * @bin_attr: kernel attributes passed to us.
2596 * @buf: contains the data to be written to sysfs mbox.
2597 * @off: offset into buffer to beginning of data.
2598 * @count: bytes to transfer.
2599 *
2600 * Description:
2601 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
2602 * Uses the sysfs mbox to send buf contents to the adapter.
2603 *
2604 * Returns:
2605 * -ERANGE off and count combo out of range
2606 * -EINVAL off, count or buff address invalid
2607 * zero if count is zero
2608 * -EPERM adapter is offline
2609 * -ENOMEM failed to allocate memory for the mail box
2610 * -EAGAIN offset, state or mbox is NULL
2611 * count number of bytes transferred
2612 **/
1827static ssize_t 2613static ssize_t
1828sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr, 2614sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr,
1829 char *buf, loff_t off, size_t count) 2615 char *buf, loff_t off, size_t count)
@@ -1878,6 +2664,29 @@ sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr,
1878 return count; 2664 return count;
1879} 2665}
1880 2666
2667/**
2668 * sysfs_mbox_read: Read method for reading information via mbox.
2669 * @kobj: kernel kobject that contains the kernel class device.
2670 * @bin_attr: kernel attributes passed to us.
2671 * @buf: contains the data to be read from sysfs mbox.
2672 * @off: offset into buffer to beginning of data.
2673 * @count: bytes to transfer.
2674 *
2675 * Description:
2676 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
2677 * Uses the sysfs mbox to receive data from to the adapter.
2678 *
2679 * Returns:
2680 * -ERANGE off greater than mailbox command size
2681 * -EINVAL off, count or buff address invalid
2682 * zero if off and count are zero
2683 * -EACCES adapter over temp
2684 * -EPERM garbage can value to catch a multitude of errors
2685 * -EAGAIN management IO not permitted, state or off error
2686 * -ETIME mailbox timeout
2687 * -ENODEV mailbox error
2688 * count number of bytes transferred
2689 **/
1881static ssize_t 2690static ssize_t
1882sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr, 2691sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr,
1883 char *buf, loff_t off, size_t count) 2692 char *buf, loff_t off, size_t count)
@@ -2059,6 +2868,14 @@ static struct bin_attribute sysfs_mbox_attr = {
2059 .write = sysfs_mbox_write, 2868 .write = sysfs_mbox_write,
2060}; 2869};
2061 2870
2871/**
2872 * lpfc_alloc_sysfs_attr: Creates the sysfs, ctlreg, menlo and mbox entries.
2873 * @vport: address of lpfc vport structure.
2874 *
2875 * Return codes:
2876 * zero on success
2877 * error return code from sysfs_create_bin_file()
2878 **/
2062int 2879int
2063lpfc_alloc_sysfs_attr(struct lpfc_vport *vport) 2880lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
2064{ 2881{
@@ -2082,6 +2899,10 @@ out:
2082 return error; 2899 return error;
2083} 2900}
2084 2901
2902/**
2903 * lpfc_free_sysfs_attr: Removes the sysfs, ctlreg, menlo and mbox entries.
2904 * @vport: address of lpfc vport structure.
2905 **/
2085void 2906void
2086lpfc_free_sysfs_attr(struct lpfc_vport *vport) 2907lpfc_free_sysfs_attr(struct lpfc_vport *vport)
2087{ 2908{
@@ -2096,6 +2917,10 @@ lpfc_free_sysfs_attr(struct lpfc_vport *vport)
2096 * Dynamic FC Host Attributes Support 2917 * Dynamic FC Host Attributes Support
2097 */ 2918 */
2098 2919
2920/**
2921 * lpfc_get_host_port_id: Copy the vport DID into the scsi host port id.
2922 * @shost: kernel scsi host pointer.
2923 **/
2099static void 2924static void
2100lpfc_get_host_port_id(struct Scsi_Host *shost) 2925lpfc_get_host_port_id(struct Scsi_Host *shost)
2101{ 2926{
@@ -2105,6 +2930,10 @@ lpfc_get_host_port_id(struct Scsi_Host *shost)
2105 fc_host_port_id(shost) = vport->fc_myDID; 2930 fc_host_port_id(shost) = vport->fc_myDID;
2106} 2931}
2107 2932
2933/**
2934 * lpfc_get_host_port_type: Set the value of the scsi host port type.
2935 * @shost: kernel scsi host pointer.
2936 **/
2108static void 2937static void
2109lpfc_get_host_port_type(struct Scsi_Host *shost) 2938lpfc_get_host_port_type(struct Scsi_Host *shost)
2110{ 2939{
@@ -2133,6 +2962,10 @@ lpfc_get_host_port_type(struct Scsi_Host *shost)
2133 spin_unlock_irq(shost->host_lock); 2962 spin_unlock_irq(shost->host_lock);
2134} 2963}
2135 2964
2965/**
2966 * lpfc_get_host_port_state: Set the value of the scsi host port state.
2967 * @shost: kernel scsi host pointer.
2968 **/
2136static void 2969static void
2137lpfc_get_host_port_state(struct Scsi_Host *shost) 2970lpfc_get_host_port_state(struct Scsi_Host *shost)
2138{ 2971{
@@ -2167,6 +3000,10 @@ lpfc_get_host_port_state(struct Scsi_Host *shost)
2167 spin_unlock_irq(shost->host_lock); 3000 spin_unlock_irq(shost->host_lock);
2168} 3001}
2169 3002
3003/**
3004 * lpfc_get_host_speed: Set the value of the scsi host speed.
3005 * @shost: kernel scsi host pointer.
3006 **/
2170static void 3007static void
2171lpfc_get_host_speed(struct Scsi_Host *shost) 3008lpfc_get_host_speed(struct Scsi_Host *shost)
2172{ 3009{
@@ -2199,6 +3036,10 @@ lpfc_get_host_speed(struct Scsi_Host *shost)
2199 spin_unlock_irq(shost->host_lock); 3036 spin_unlock_irq(shost->host_lock);
2200} 3037}
2201 3038
3039/**
3040 * lpfc_get_host_fabric_name: Set the value of the scsi host fabric name.
3041 * @shost: kernel scsi host pointer.
3042 **/
2202static void 3043static void
2203lpfc_get_host_fabric_name (struct Scsi_Host *shost) 3044lpfc_get_host_fabric_name (struct Scsi_Host *shost)
2204{ 3045{
@@ -2221,6 +3062,18 @@ lpfc_get_host_fabric_name (struct Scsi_Host *shost)
2221 fc_host_fabric_name(shost) = node_name; 3062 fc_host_fabric_name(shost) = node_name;
2222} 3063}
2223 3064
3065/**
3066 * lpfc_get_stats: Return statistical information about the adapter.
3067 * @shost: kernel scsi host pointer.
3068 *
3069 * Notes:
3070 * NULL on error for link down, no mbox pool, sli2 active,
3071 * management not allowed, memory allocation error, or mbox error.
3072 *
3073 * Returns:
3074 * NULL for error
3075 * address of the adapter host statistics
3076 **/
2224static struct fc_host_statistics * 3077static struct fc_host_statistics *
2225lpfc_get_stats(struct Scsi_Host *shost) 3078lpfc_get_stats(struct Scsi_Host *shost)
2226{ 3079{
@@ -2334,6 +3187,10 @@ lpfc_get_stats(struct Scsi_Host *shost)
2334 return hs; 3187 return hs;
2335} 3188}
2336 3189
3190/**
3191 * lpfc_reset_stats: Copy the adapter link stats information.
3192 * @shost: kernel scsi host pointer.
3193 **/
2337static void 3194static void
2338lpfc_reset_stats(struct Scsi_Host *shost) 3195lpfc_reset_stats(struct Scsi_Host *shost)
2339{ 3196{
@@ -2411,6 +3268,14 @@ lpfc_reset_stats(struct Scsi_Host *shost)
2411 * are no sysfs handlers for link_down_tmo. 3268 * are no sysfs handlers for link_down_tmo.
2412 */ 3269 */
2413 3270
3271/**
3272 * lpfc_get_node_by_target: Return the nodelist for a target.
3273 * @starget: kernel scsi target pointer.
3274 *
3275 * Returns:
3276 * address of the node list if found
3277 * NULL target not found
3278 **/
2414static struct lpfc_nodelist * 3279static struct lpfc_nodelist *
2415lpfc_get_node_by_target(struct scsi_target *starget) 3280lpfc_get_node_by_target(struct scsi_target *starget)
2416{ 3281{
@@ -2432,6 +3297,10 @@ lpfc_get_node_by_target(struct scsi_target *starget)
2432 return NULL; 3297 return NULL;
2433} 3298}
2434 3299
3300/**
3301 * lpfc_get_starget_port_id: Set the target port id to the ndlp DID or -1.
3302 * @starget: kernel scsi target pointer.
3303 **/
2435static void 3304static void
2436lpfc_get_starget_port_id(struct scsi_target *starget) 3305lpfc_get_starget_port_id(struct scsi_target *starget)
2437{ 3306{
@@ -2440,6 +3309,12 @@ lpfc_get_starget_port_id(struct scsi_target *starget)
2440 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1; 3309 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
2441} 3310}
2442 3311
3312/**
3313 * lpfc_get_starget_node_name: Set the target node name.
3314 * @starget: kernel scsi target pointer.
3315 *
3316 * Description: Set the target node name to the ndlp node name wwn or zero.
3317 **/
2443static void 3318static void
2444lpfc_get_starget_node_name(struct scsi_target *starget) 3319lpfc_get_starget_node_name(struct scsi_target *starget)
2445{ 3320{
@@ -2449,6 +3324,12 @@ lpfc_get_starget_node_name(struct scsi_target *starget)
2449 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0; 3324 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
2450} 3325}
2451 3326
3327/**
3328 * lpfc_get_starget_port_name: Set the target port name.
3329 * @starget: kernel scsi target pointer.
3330 *
3331 * Description: set the target port name to the ndlp port name wwn or zero.
3332 **/
2452static void 3333static void
2453lpfc_get_starget_port_name(struct scsi_target *starget) 3334lpfc_get_starget_port_name(struct scsi_target *starget)
2454{ 3335{
@@ -2458,6 +3339,15 @@ lpfc_get_starget_port_name(struct scsi_target *starget)
2458 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0; 3339 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
2459} 3340}
2460 3341
3342/**
3343 * lpfc_set_rport_loss_tmo: Set the rport dev loss tmo.
3344 * @rport: fc rport address.
3345 * @timeout: new value for dev loss tmo.
3346 *
3347 * Description:
3348 * If timeout is non zero set the dev_loss_tmo to timeout, else set
3349 * dev_loss_tmo to one.
3350 **/
2461static void 3351static void
2462lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout) 3352lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
2463{ 3353{
@@ -2467,7 +3357,18 @@ lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
2467 rport->dev_loss_tmo = 1; 3357 rport->dev_loss_tmo = 1;
2468} 3358}
2469 3359
2470 3360/**
3361 * lpfc_rport_show_function: Return rport target information.
3362 *
3363 * Description:
3364 * Macro that uses field to generate a function with the name lpfc_show_rport_
3365 *
3366 * lpfc_show_rport_##field: returns the bytes formatted in buf
3367 * @cdev: class converted to an fc_rport.
3368 * @buf: on return contains the target_field or zero.
3369 *
3370 * Returns: size of formatted string.
3371 **/
2471#define lpfc_rport_show_function(field, format_string, sz, cast) \ 3372#define lpfc_rport_show_function(field, format_string, sz, cast) \
2472static ssize_t \ 3373static ssize_t \
2473lpfc_show_rport_##field (struct device *dev, \ 3374lpfc_show_rport_##field (struct device *dev, \
@@ -2602,6 +3503,10 @@ struct fc_function_template lpfc_vport_transport_functions = {
2602 .vport_disable = lpfc_vport_disable, 3503 .vport_disable = lpfc_vport_disable,
2603}; 3504};
2604 3505
3506/**
3507 * lpfc_get_cfgparam: Used during probe_one to init the adapter structure.
3508 * @phba: lpfc_hba pointer.
3509 **/
2605void 3510void
2606lpfc_get_cfgparam(struct lpfc_hba *phba) 3511lpfc_get_cfgparam(struct lpfc_hba *phba)
2607{ 3512{
@@ -2637,6 +3542,10 @@ lpfc_get_cfgparam(struct lpfc_hba *phba)
2637 return; 3542 return;
2638} 3543}
2639 3544
3545/**
3546 * lpfc_get_vport_cfgparam: Used during port create, init the vport structure.
3547 * @vport: lpfc_vport pointer.
3548 **/
2640void 3549void
2641lpfc_get_vport_cfgparam(struct lpfc_vport *vport) 3550lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
2642{ 3551{
diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
index 094b47e94b29..2588eadffbb9 100644
--- a/drivers/scsi/lpfc/lpfc_debugfs.c
+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
@@ -1,7 +1,7 @@
1/******************************************************************* 1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for * 2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. * 3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2007 Emulex. All rights reserved. * 4 * Copyright (C) 2007-2008 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. * 5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com * 6 * www.emulex.com *
7 * * 7 * *
@@ -46,13 +46,14 @@
46#include "lpfc_debugfs.h" 46#include "lpfc_debugfs.h"
47 47
48#ifdef CONFIG_LPFC_DEBUG_FS 48#ifdef CONFIG_LPFC_DEBUG_FS
49/* debugfs interface 49/**
50 * debugfs interface
50 * 51 *
51 * To access this interface the user should: 52 * To access this interface the user should:
52 * # mkdir /debug 53 * # mkdir /debug
53 * # mount -t debugfs none /debug 54 * # mount -t debugfs none /debug
54 * 55 *
55 * The lpfc debugfs directory hierachy is: 56 * The lpfc debugfs directory hierarchy is:
56 * lpfc/lpfcX/vportY 57 * lpfc/lpfcX/vportY
57 * where X is the lpfc hba unique_id 58 * where X is the lpfc hba unique_id
58 * where Y is the vport VPI on that hba 59 * where Y is the vport VPI on that hba
@@ -61,14 +62,21 @@
61 * discovery_trace 62 * discovery_trace
62 * This is an ACSII readable file that contains a trace of the last 63 * This is an ACSII readable file that contains a trace of the last
63 * lpfc_debugfs_max_disc_trc events that happened on a specific vport. 64 * lpfc_debugfs_max_disc_trc events that happened on a specific vport.
64 * See lpfc_debugfs.h for different categories of 65 * See lpfc_debugfs.h for different categories of discovery events.
65 * discovery events. To enable the discovery trace, the following 66 * To enable the discovery trace, the following module parameters must be set:
66 * module parameters must be set:
67 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support 67 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
68 * lpfc_debugfs_max_disc_trc=X Where X is the event trace depth for 68 * lpfc_debugfs_max_disc_trc=X Where X is the event trace depth for
69 * EACH vport. X MUST also be a power of 2. 69 * EACH vport. X MUST also be a power of 2.
70 * lpfc_debugfs_mask_disc_trc=Y Where Y is an event mask as defined in 70 * lpfc_debugfs_mask_disc_trc=Y Where Y is an event mask as defined in
71 * lpfc_debugfs.h . 71 * lpfc_debugfs.h .
72 *
73 * slow_ring_trace
74 * This is an ACSII readable file that contains a trace of the last
75 * lpfc_debugfs_max_slow_ring_trc events that happened on a specific HBA.
76 * To enable the slow ring trace, the following module parameters must be set:
77 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
78 * lpfc_debugfs_max_slow_ring_trc=X Where X is the event trace depth for
79 * the HBA. X MUST also be a power of 2.
72 */ 80 */
73static int lpfc_debugfs_enable = 1; 81static int lpfc_debugfs_enable = 1;
74module_param(lpfc_debugfs_enable, int, 0); 82module_param(lpfc_debugfs_enable, int, 0);
@@ -117,6 +125,25 @@ struct lpfc_debug {
117static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0); 125static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
118static unsigned long lpfc_debugfs_start_time = 0L; 126static unsigned long lpfc_debugfs_start_time = 0L;
119 127
128/**
129 * lpfc_debugfs_disc_trc_data - Dump discovery logging to a buffer.
130 * @vport: The vport to gather the log info from.
131 * @buf: The buffer to dump log into.
132 * @size: The maximum amount of data to process.
133 *
134 * Description:
135 * This routine gathers the lpfc discovery debugfs data from the @vport and
136 * dumps it to @buf up to @size number of bytes. It will start at the next entry
137 * in the log and process the log until the end of the buffer. Then it will
138 * gather from the beginning of the log and process until the current entry.
139 *
140 * Notes:
141 * Discovery logging will be disabled while while this routine dumps the log.
142 *
143 * Return Value:
144 * This routine returns the amount of bytes that were dumped into @buf and will
145 * not exceed @size.
146 **/
120static int 147static int
121lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size) 148lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
122{ 149{
@@ -125,7 +152,6 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
125 struct lpfc_debugfs_trc *dtp; 152 struct lpfc_debugfs_trc *dtp;
126 char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE]; 153 char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE];
127 154
128
129 enable = lpfc_debugfs_enable; 155 enable = lpfc_debugfs_enable;
130 lpfc_debugfs_enable = 0; 156 lpfc_debugfs_enable = 0;
131 157
@@ -159,6 +185,25 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
159 return len; 185 return len;
160} 186}
161 187
188/**
189 * lpfc_debugfs_slow_ring_trc_data - Dump slow ring logging to a buffer.
190 * @phba: The HBA to gather the log info from.
191 * @buf: The buffer to dump log into.
192 * @size: The maximum amount of data to process.
193 *
194 * Description:
195 * This routine gathers the lpfc slow ring debugfs data from the @phba and
196 * dumps it to @buf up to @size number of bytes. It will start at the next entry
197 * in the log and process the log until the end of the buffer. Then it will
198 * gather from the beginning of the log and process until the current entry.
199 *
200 * Notes:
201 * Slow ring logging will be disabled while while this routine dumps the log.
202 *
203 * Return Value:
204 * This routine returns the amount of bytes that were dumped into @buf and will
205 * not exceed @size.
206 **/
162static int 207static int
163lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size) 208lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
164{ 209{
@@ -203,6 +248,25 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
203 248
204static int lpfc_debugfs_last_hbq = -1; 249static int lpfc_debugfs_last_hbq = -1;
205 250
251/**
252 * lpfc_debugfs_hbqinfo_data - Dump host buffer queue info to a buffer.
253 * @phba: The HBA to gather host buffer info from.
254 * @buf: The buffer to dump log into.
255 * @size: The maximum amount of data to process.
256 *
257 * Description:
258 * This routine dumps the host buffer queue info from the @phba to @buf up to
259 * @size number of bytes. A header that describes the current hbq state will be
260 * dumped to @buf first and then info on each hbq entry will be dumped to @buf
261 * until @size bytes have been dumped or all the hbq info has been dumped.
262 *
263 * Notes:
264 * This routine will rotate through each configured HBQ each time called.
265 *
266 * Return Value:
267 * This routine returns the amount of bytes that were dumped into @buf and will
268 * not exceed @size.
269 **/
206static int 270static int
207lpfc_debugfs_hbqinfo_data(struct lpfc_hba *phba, char *buf, int size) 271lpfc_debugfs_hbqinfo_data(struct lpfc_hba *phba, char *buf, int size)
208{ 272{
@@ -303,6 +367,24 @@ skipit:
303 367
304static int lpfc_debugfs_last_hba_slim_off; 368static int lpfc_debugfs_last_hba_slim_off;
305 369
370/**
371 * lpfc_debugfs_dumpHBASlim_data - Dump HBA SLIM info to a buffer.
372 * @phba: The HBA to gather SLIM info from.
373 * @buf: The buffer to dump log into.
374 * @size: The maximum amount of data to process.
375 *
376 * Description:
377 * This routine dumps the current contents of HBA SLIM for the HBA associated
378 * with @phba to @buf up to @size bytes of data. This is the raw HBA SLIM data.
379 *
380 * Notes:
381 * This routine will only dump up to 1024 bytes of data each time called and
382 * should be called multiple times to dump the entire HBA SLIM.
383 *
384 * Return Value:
385 * This routine returns the amount of bytes that were dumped into @buf and will
386 * not exceed @size.
387 **/
306static int 388static int
307lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size) 389lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size)
308{ 390{
@@ -342,6 +424,21 @@ lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size)
342 return len; 424 return len;
343} 425}
344 426
427/**
428 * lpfc_debugfs_dumpHostSlim_data - Dump host SLIM info to a buffer.
429 * @phba: The HBA to gather Host SLIM info from.
430 * @buf: The buffer to dump log into.
431 * @size: The maximum amount of data to process.
432 *
433 * Description:
434 * This routine dumps the current contents of host SLIM for the host associated
435 * with @phba to @buf up to @size bytes of data. The dump will contain the
436 * Mailbox, PCB, Rings, and Registers that are located in host memory.
437 *
438 * Return Value:
439 * This routine returns the amount of bytes that were dumped into @buf and will
440 * not exceed @size.
441 **/
345static int 442static int
346lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba *phba, char *buf, int size) 443lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba *phba, char *buf, int size)
347{ 444{
@@ -430,6 +527,21 @@ lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba *phba, char *buf, int size)
430 return len; 527 return len;
431} 528}
432 529
530/**
531 * lpfc_debugfs_nodelist_data - Dump target node list to a buffer.
532 * @vport: The vport to gather target node info from.
533 * @buf: The buffer to dump log into.
534 * @size: The maximum amount of data to process.
535 *
536 * Description:
537 * This routine dumps the current target node list associated with @vport to
538 * @buf up to @size bytes of data. Each node entry in the dump will contain a
539 * node state, DID, WWPN, WWNN, RPI, flags, type, and other useful fields.
540 *
541 * Return Value:
542 * This routine returns the amount of bytes that were dumped into @buf and will
543 * not exceed @size.
544 **/
433static int 545static int
434lpfc_debugfs_nodelist_data(struct lpfc_vport *vport, char *buf, int size) 546lpfc_debugfs_nodelist_data(struct lpfc_vport *vport, char *buf, int size)
435{ 547{
@@ -513,7 +625,22 @@ lpfc_debugfs_nodelist_data(struct lpfc_vport *vport, char *buf, int size)
513} 625}
514#endif 626#endif
515 627
516 628/**
629 * lpfc_debugfs_disc_trc - Store discovery trace log.
630 * @vport: The vport to associate this trace string with for retrieval.
631 * @mask: Log entry classification.
632 * @fmt: Format string to be displayed when dumping the log.
633 * @data1: 1st data parameter to be applied to @fmt.
634 * @data2: 2nd data parameter to be applied to @fmt.
635 * @data3: 3rd data parameter to be applied to @fmt.
636 *
637 * Description:
638 * This routine is used by the driver code to add a debugfs log entry to the
639 * discovery trace buffer associated with @vport. Only entries with a @mask that
640 * match the current debugfs discovery mask will be saved. Entries that do not
641 * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like
642 * printf when displaying the log.
643 **/
517inline void 644inline void
518lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt, 645lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
519 uint32_t data1, uint32_t data2, uint32_t data3) 646 uint32_t data1, uint32_t data2, uint32_t data3)
@@ -542,6 +669,19 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
542 return; 669 return;
543} 670}
544 671
672/**
673 * lpfc_debugfs_slow_ring_trc - Store slow ring trace log.
674 * @phba: The phba to associate this trace string with for retrieval.
675 * @fmt: Format string to be displayed when dumping the log.
676 * @data1: 1st data parameter to be applied to @fmt.
677 * @data2: 2nd data parameter to be applied to @fmt.
678 * @data3: 3rd data parameter to be applied to @fmt.
679 *
680 * Description:
681 * This routine is used by the driver code to add a debugfs log entry to the
682 * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and
683 * @data3 are used like printf when displaying the log.
684 **/
545inline void 685inline void
546lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt, 686lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
547 uint32_t data1, uint32_t data2, uint32_t data3) 687 uint32_t data1, uint32_t data2, uint32_t data3)
@@ -568,6 +708,21 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
568} 708}
569 709
570#ifdef CONFIG_LPFC_DEBUG_FS 710#ifdef CONFIG_LPFC_DEBUG_FS
711/**
712 * lpfc_debugfs_disc_trc_open - Open the discovery trace log.
713 * @inode: The inode pointer that contains a vport pointer.
714 * @file: The file pointer to attach the log output.
715 *
716 * Description:
717 * This routine is the entry point for the debugfs open file operation. It gets
718 * the vport from the i_private field in @inode, allocates the necessary buffer
719 * for the log, fills the buffer from the in-memory log for this vport, and then
720 * returns a pointer to that log in the private_data field in @file.
721 *
722 * Returns:
723 * This function returns zero if successful. On error it will return an negative
724 * error value.
725 **/
571static int 726static int
572lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file) 727lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
573{ 728{
@@ -585,7 +740,7 @@ lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
585 if (!debug) 740 if (!debug)
586 goto out; 741 goto out;
587 742
588 /* Round to page boundry */ 743 /* Round to page boundary */
589 size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE); 744 size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
590 size = PAGE_ALIGN(size); 745 size = PAGE_ALIGN(size);
591 746
@@ -603,6 +758,21 @@ out:
603 return rc; 758 return rc;
604} 759}
605 760
761/**
762 * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log.
763 * @inode: The inode pointer that contains a vport pointer.
764 * @file: The file pointer to attach the log output.
765 *
766 * Description:
767 * This routine is the entry point for the debugfs open file operation. It gets
768 * the vport from the i_private field in @inode, allocates the necessary buffer
769 * for the log, fills the buffer from the in-memory log for this vport, and then
770 * returns a pointer to that log in the private_data field in @file.
771 *
772 * Returns:
773 * This function returns zero if successful. On error it will return an negative
774 * error value.
775 **/
606static int 776static int
607lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file) 777lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
608{ 778{
@@ -620,7 +790,7 @@ lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
620 if (!debug) 790 if (!debug)
621 goto out; 791 goto out;
622 792
623 /* Round to page boundry */ 793 /* Round to page boundary */
624 size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE); 794 size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
625 size = PAGE_ALIGN(size); 795 size = PAGE_ALIGN(size);
626 796
@@ -638,6 +808,21 @@ out:
638 return rc; 808 return rc;
639} 809}
640 810
811/**
812 * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer.
813 * @inode: The inode pointer that contains a vport pointer.
814 * @file: The file pointer to attach the log output.
815 *
816 * Description:
817 * This routine is the entry point for the debugfs open file operation. It gets
818 * the vport from the i_private field in @inode, allocates the necessary buffer
819 * for the log, fills the buffer from the in-memory log for this vport, and then
820 * returns a pointer to that log in the private_data field in @file.
821 *
822 * Returns:
823 * This function returns zero if successful. On error it will return an negative
824 * error value.
825 **/
641static int 826static int
642lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file) 827lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
643{ 828{
@@ -649,7 +834,7 @@ lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
649 if (!debug) 834 if (!debug)
650 goto out; 835 goto out;
651 836
652 /* Round to page boundry */ 837 /* Round to page boundary */
653 debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL); 838 debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
654 if (!debug->buffer) { 839 if (!debug->buffer) {
655 kfree(debug); 840 kfree(debug);
@@ -665,6 +850,21 @@ out:
665 return rc; 850 return rc;
666} 851}
667 852
853/**
854 * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer.
855 * @inode: The inode pointer that contains a vport pointer.
856 * @file: The file pointer to attach the log output.
857 *
858 * Description:
859 * This routine is the entry point for the debugfs open file operation. It gets
860 * the vport from the i_private field in @inode, allocates the necessary buffer
861 * for the log, fills the buffer from the in-memory log for this vport, and then
862 * returns a pointer to that log in the private_data field in @file.
863 *
864 * Returns:
865 * This function returns zero if successful. On error it will return an negative
866 * error value.
867 **/
668static int 868static int
669lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file) 869lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
670{ 870{
@@ -676,7 +876,7 @@ lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
676 if (!debug) 876 if (!debug)
677 goto out; 877 goto out;
678 878
679 /* Round to page boundry */ 879 /* Round to page boundary */
680 debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL); 880 debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
681 if (!debug->buffer) { 881 if (!debug->buffer) {
682 kfree(debug); 882 kfree(debug);
@@ -692,6 +892,21 @@ out:
692 return rc; 892 return rc;
693} 893}
694 894
895/**
896 * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer.
897 * @inode: The inode pointer that contains a vport pointer.
898 * @file: The file pointer to attach the log output.
899 *
900 * Description:
901 * This routine is the entry point for the debugfs open file operation. It gets
902 * the vport from the i_private field in @inode, allocates the necessary buffer
903 * for the log, fills the buffer from the in-memory log for this vport, and then
904 * returns a pointer to that log in the private_data field in @file.
905 *
906 * Returns:
907 * This function returns zero if successful. On error it will return an negative
908 * error value.
909 **/
695static int 910static int
696lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file) 911lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
697{ 912{
@@ -703,7 +918,7 @@ lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
703 if (!debug) 918 if (!debug)
704 goto out; 919 goto out;
705 920
706 /* Round to page boundry */ 921 /* Round to page boundary */
707 debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL); 922 debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
708 if (!debug->buffer) { 923 if (!debug->buffer) {
709 kfree(debug); 924 kfree(debug);
@@ -719,6 +934,21 @@ out:
719 return rc; 934 return rc;
720} 935}
721 936
937/**
938 * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file.
939 * @inode: The inode pointer that contains a vport pointer.
940 * @file: The file pointer to attach the log output.
941 *
942 * Description:
943 * This routine is the entry point for the debugfs open file operation. It gets
944 * the vport from the i_private field in @inode, allocates the necessary buffer
945 * for the log, fills the buffer from the in-memory log for this vport, and then
946 * returns a pointer to that log in the private_data field in @file.
947 *
948 * Returns:
949 * This function returns zero if successful. On error it will return an negative
950 * error value.
951 **/
722static int 952static int
723lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file) 953lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
724{ 954{
@@ -730,7 +960,7 @@ lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
730 if (!debug) 960 if (!debug)
731 goto out; 961 goto out;
732 962
733 /* Round to page boundry */ 963 /* Round to page boundary */
734 debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL); 964 debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
735 if (!debug->buffer) { 965 if (!debug->buffer) {
736 kfree(debug); 966 kfree(debug);
@@ -746,6 +976,23 @@ out:
746 return rc; 976 return rc;
747} 977}
748 978
979/**
980 * lpfc_debugfs_lseek - Seek through a debugfs file.
981 * @file: The file pointer to seek through.
982 * @off: The offset to seek to or the amount to seek by.
983 * @whence: Indicates how to seek.
984 *
985 * Description:
986 * This routine is the entry point for the debugfs lseek file operation. The
987 * @whence parameter indicates whether @off is the offset to directly seek to,
988 * or if it is a value to seek forward or reverse by. This function figures out
989 * what the new offset of the debugfs file will be and assigns that value to the
990 * f_pos field of @file.
991 *
992 * Returns:
993 * This function returns the new offset if successful and returns a negative
994 * error if unable to process the seek.
995 **/
749static loff_t 996static loff_t
750lpfc_debugfs_lseek(struct file *file, loff_t off, int whence) 997lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
751{ 998{
@@ -767,6 +1014,22 @@ lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
767 return (pos < 0 || pos > debug->len) ? -EINVAL : (file->f_pos = pos); 1014 return (pos < 0 || pos > debug->len) ? -EINVAL : (file->f_pos = pos);
768} 1015}
769 1016
1017/**
1018 * lpfc_debugfs_read - Read a debugfs file.
1019 * @file: The file pointer to read from.
1020 * @buf: The buffer to copy the data to.
1021 * @nbytes: The number of bytes to read.
1022 * @ppos: The position in the file to start reading from.
1023 *
1024 * Description:
1025 * This routine reads data from from the buffer indicated in the private_data
1026 * field of @file. It will start reading at @ppos and copy up to @nbytes of
1027 * data to @buf.
1028 *
1029 * Returns:
1030 * This function returns the amount of data that was read (this could be less
1031 * than @nbytes if the end of the file was reached) or a negative error value.
1032 **/
770static ssize_t 1033static ssize_t
771lpfc_debugfs_read(struct file *file, char __user *buf, 1034lpfc_debugfs_read(struct file *file, char __user *buf,
772 size_t nbytes, loff_t *ppos) 1035 size_t nbytes, loff_t *ppos)
@@ -776,6 +1039,18 @@ lpfc_debugfs_read(struct file *file, char __user *buf,
776 debug->len); 1039 debug->len);
777} 1040}
778 1041
1042/**
1043 * lpfc_debugfs_release - Release the buffer used to store debugfs file data.
1044 * @inode: The inode pointer that contains a vport pointer. (unused)
1045 * @file: The file pointer that contains the buffer to release.
1046 *
1047 * Description:
1048 * This routine frees the buffer that was allocated when the debugfs file was
1049 * opened.
1050 *
1051 * Returns:
1052 * This function returns zero.
1053 **/
779static int 1054static int
780lpfc_debugfs_release(struct inode *inode, struct file *file) 1055lpfc_debugfs_release(struct inode *inode, struct file *file)
781{ 1056{
@@ -845,6 +1120,16 @@ static struct dentry *lpfc_debugfs_root = NULL;
845static atomic_t lpfc_debugfs_hba_count; 1120static atomic_t lpfc_debugfs_hba_count;
846#endif 1121#endif
847 1122
1123/**
1124 * lpfc_debugfs_initialize - Initialize debugfs for a vport.
1125 * @vport: The vport pointer to initialize.
1126 *
1127 * Description:
1128 * When Debugfs is configured this routine sets up the lpfc debugfs file system.
1129 * If not already created, this routine will create the lpfc directory, and
1130 * lpfcX directory (for this HBA), and vportX directory for this vport. It will
1131 * also create each file used to access lpfc specific debugfs information.
1132 **/
848inline void 1133inline void
849lpfc_debugfs_initialize(struct lpfc_vport *vport) 1134lpfc_debugfs_initialize(struct lpfc_vport *vport)
850{ 1135{
@@ -1033,7 +1318,17 @@ debug_failed:
1033#endif 1318#endif
1034} 1319}
1035 1320
1036 1321/**
1322 * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport.
1323 * @vport: The vport pointer to remove from debugfs.
1324 *
1325 * Description:
1326 * When Debugfs is configured this routine removes debugfs file system elements
1327 * that are specific to this vport. It also checks to see if there are any
1328 * users left for the debugfs directories associated with the HBA and driver. If
1329 * this is the last user of the HBA directory or driver directory then it will
1330 * remove those from the debugfs infrastructure as well.
1331 **/
1037inline void 1332inline void
1038lpfc_debugfs_terminate(struct lpfc_vport *vport) 1333lpfc_debugfs_terminate(struct lpfc_vport *vport)
1039{ 1334{
@@ -1096,5 +1391,3 @@ lpfc_debugfs_terminate(struct lpfc_vport *vport)
1096#endif 1391#endif
1097 return; 1392 return;
1098} 1393}
1099
1100
diff --git a/drivers/scsi/lpfc/lpfc_els.c b/drivers/scsi/lpfc/lpfc_els.c
index f54e0f7eaee3..43049b9d64c9 100644
--- a/drivers/scsi/lpfc/lpfc_els.c
+++ b/drivers/scsi/lpfc/lpfc_els.c
@@ -53,6 +53,28 @@ static void lpfc_register_new_vport(struct lpfc_hba *phba,
53 53
54static int lpfc_max_els_tries = 3; 54static int lpfc_max_els_tries = 3;
55 55
56/**
57 * lpfc_els_chk_latt: Check host link attention event for a vport.
58 * @vport: pointer to a host virtual N_Port data structure.
59 *
60 * This routine checks whether there is an outstanding host link
61 * attention event during the discovery process with the @vport. It is done
62 * by reading the HBA's Host Attention (HA) register. If there is any host
63 * link attention events during this @vport's discovery process, the @vport
64 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
65 * be issued if the link state is not already in host link cleared state,
66 * and a return code shall indicate whether the host link attention event
67 * had happened.
68 *
69 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
70 * state in LPFC_VPORT_READY, the request for checking host link attention
71 * event will be ignored and a return code shall indicate no host link
72 * attention event had happened.
73 *
74 * Return codes
75 * 0 - no host link attention event happened
76 * 1 - host link attention event happened
77 **/
56int 78int
57lpfc_els_chk_latt(struct lpfc_vport *vport) 79lpfc_els_chk_latt(struct lpfc_vport *vport)
58{ 80{
@@ -92,6 +114,34 @@ lpfc_els_chk_latt(struct lpfc_vport *vport)
92 return 1; 114 return 1;
93} 115}
94 116
117/**
118 * lpfc_prep_els_iocb: Allocate and prepare a lpfc iocb data structure.
119 * @vport: pointer to a host virtual N_Port data structure.
120 * @expectRsp: flag indicating whether response is expected.
121 * @cmdSize: size of the ELS command.
122 * @retry: number of retries to the command IOCB when it fails.
123 * @ndlp: pointer to a node-list data structure.
124 * @did: destination identifier.
125 * @elscmd: the ELS command code.
126 *
127 * This routine is used for allocating a lpfc-IOCB data structure from
128 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
129 * passed into the routine for discovery state machine to issue an Extended
130 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
131 * and preparation routine that is used by all the discovery state machine
132 * routines and the ELS command-specific fields will be later set up by
133 * the individual discovery machine routines after calling this routine
134 * allocating and preparing a generic IOCB data structure. It fills in the
135 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
136 * payload and response payload (if expected). The reference count on the
137 * ndlp is incremented by 1 and the reference to the ndlp is put into
138 * context1 of the IOCB data structure for this IOCB to hold the ndlp
139 * reference for the command's callback function to access later.
140 *
141 * Return code
142 * Pointer to the newly allocated/prepared els iocb data structure
143 * NULL - when els iocb data structure allocation/preparation failed
144 **/
95static struct lpfc_iocbq * 145static struct lpfc_iocbq *
96lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp, 146lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
97 uint16_t cmdSize, uint8_t retry, 147 uint16_t cmdSize, uint8_t retry,
@@ -233,6 +283,22 @@ els_iocb_free_pcmb_exit:
233 return NULL; 283 return NULL;
234} 284}
235 285
286/**
287 * lpfc_issue_fabric_reglogin: Issue fabric registration login for a vport.
288 * @vport: pointer to a host virtual N_Port data structure.
289 *
290 * This routine issues a fabric registration login for a @vport. An
291 * active ndlp node with Fabric_DID must already exist for this @vport.
292 * The routine invokes two mailbox commands to carry out fabric registration
293 * login through the HBA firmware: the first mailbox command requests the
294 * HBA to perform link configuration for the @vport; and the second mailbox
295 * command requests the HBA to perform the actual fabric registration login
296 * with the @vport.
297 *
298 * Return code
299 * 0 - successfully issued fabric registration login for @vport
300 * -ENXIO -- failed to issue fabric registration login for @vport
301 **/
236static int 302static int
237lpfc_issue_fabric_reglogin(struct lpfc_vport *vport) 303lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
238{ 304{
@@ -313,6 +379,26 @@ fail:
313 return -ENXIO; 379 return -ENXIO;
314} 380}
315 381
382/**
383 * lpfc_cmpl_els_flogi_fabric: Completion function for flogi to a fabric port.
384 * @vport: pointer to a host virtual N_Port data structure.
385 * @ndlp: pointer to a node-list data structure.
386 * @sp: pointer to service parameter data structure.
387 * @irsp: pointer to the IOCB within the lpfc response IOCB.
388 *
389 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
390 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
391 * port in a fabric topology. It properly sets up the parameters to the @ndlp
392 * from the IOCB response. It also check the newly assigned N_Port ID to the
393 * @vport against the previously assigned N_Port ID. If it is different from
394 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
395 * is invoked on all the remaining nodes with the @vport to unregister the
396 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
397 * is invoked to register login to the fabric.
398 *
399 * Return code
400 * 0 - Success (currently, always return 0)
401 **/
316static int 402static int
317lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, 403lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
318 struct serv_parm *sp, IOCB_t *irsp) 404 struct serv_parm *sp, IOCB_t *irsp)
@@ -416,9 +502,26 @@ lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
416 return 0; 502 return 0;
417} 503}
418 504
419/* 505/**
420 * We FLOGIed into an NPort, initiate pt2pt protocol 506 * lpfc_cmpl_els_flogi_nport: Completion function for flogi to an N_Port.
421 */ 507 * @vport: pointer to a host virtual N_Port data structure.
508 * @ndlp: pointer to a node-list data structure.
509 * @sp: pointer to service parameter data structure.
510 *
511 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
512 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
513 * in a point-to-point topology. First, the @vport's N_Port Name is compared
514 * with the received N_Port Name: if the @vport's N_Port Name is greater than
515 * the received N_Port Name lexicographically, this node shall assign local
516 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
517 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
518 * this node shall just wait for the remote node to issue PLOGI and assign
519 * N_Port IDs.
520 *
521 * Return code
522 * 0 - Success
523 * -ENXIO - Fail
524 **/
422static int 525static int
423lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, 526lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
424 struct serv_parm *sp) 527 struct serv_parm *sp)
@@ -516,6 +619,29 @@ fail:
516 return -ENXIO; 619 return -ENXIO;
517} 620}
518 621
622/**
623 * lpfc_cmpl_els_flogi: Completion callback function for flogi.
624 * @phba: pointer to lpfc hba data structure.
625 * @cmdiocb: pointer to lpfc command iocb data structure.
626 * @rspiocb: pointer to lpfc response iocb data structure.
627 *
628 * This routine is the top-level completion callback function for issuing
629 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
630 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
631 * retry has been made (either immediately or delayed with lpfc_els_retry()
632 * returning 1), the command IOCB will be released and function returned.
633 * If the retry attempt has been given up (possibly reach the maximum
634 * number of retries), one additional decrement of ndlp reference shall be
635 * invoked before going out after releasing the command IOCB. This will
636 * actually release the remote node (Note, lpfc_els_free_iocb() will also
637 * invoke one decrement of ndlp reference count). If no error reported in
638 * the IOCB status, the command Port ID field is used to determine whether
639 * this is a point-to-point topology or a fabric topology: if the Port ID
640 * field is assigned, it is a fabric topology; otherwise, it is a
641 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
642 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
643 * specific topology completion conditions.
644 **/
519static void 645static void
520lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 646lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
521 struct lpfc_iocbq *rspiocb) 647 struct lpfc_iocbq *rspiocb)
@@ -618,6 +744,28 @@ out:
618 lpfc_els_free_iocb(phba, cmdiocb); 744 lpfc_els_free_iocb(phba, cmdiocb);
619} 745}
620 746
747/**
748 * lpfc_issue_els_flogi: Issue an flogi iocb command for a vport.
749 * @vport: pointer to a host virtual N_Port data structure.
750 * @ndlp: pointer to a node-list data structure.
751 * @retry: number of retries to the command IOCB.
752 *
753 * This routine issues a Fabric Login (FLOGI) Request ELS command
754 * for a @vport. The initiator service parameters are put into the payload
755 * of the FLOGI Request IOCB and the top-level callback function pointer
756 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
757 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
758 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
759 *
760 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
761 * will be incremented by 1 for holding the ndlp and the reference to ndlp
762 * will be stored into the context1 field of the IOCB for the completion
763 * callback function to the FLOGI ELS command.
764 *
765 * Return code
766 * 0 - successfully issued flogi iocb for @vport
767 * 1 - failed to issue flogi iocb for @vport
768 **/
621static int 769static int
622lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, 770lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
623 uint8_t retry) 771 uint8_t retry)
@@ -694,6 +842,20 @@ lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
694 return 0; 842 return 0;
695} 843}
696 844
845/**
846 * lpfc_els_abort_flogi: Abort all outstanding flogi iocbs.
847 * @phba: pointer to lpfc hba data structure.
848 *
849 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
850 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
851 * list and issues an abort IOCB commond on each outstanding IOCB that
852 * contains a active Fabric_DID ndlp. Note that this function is to issue
853 * the abort IOCB command on all the outstanding IOCBs, thus when this
854 * function returns, it does not guarantee all the IOCBs are actually aborted.
855 *
856 * Return code
857 * 0 - Sucessfully issued abort iocb on all outstanding flogis (Always 0)
858 **/
697int 859int
698lpfc_els_abort_flogi(struct lpfc_hba *phba) 860lpfc_els_abort_flogi(struct lpfc_hba *phba)
699{ 861{
@@ -729,6 +891,22 @@ lpfc_els_abort_flogi(struct lpfc_hba *phba)
729 return 0; 891 return 0;
730} 892}
731 893
894/**
895 * lpfc_initial_flogi: Issue an initial fabric login for a vport.
896 * @vport: pointer to a host virtual N_Port data structure.
897 *
898 * This routine issues an initial Fabric Login (FLOGI) for the @vport
899 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
900 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
901 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
902 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
903 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
904 * @vport.
905 *
906 * Return code
907 * 0 - failed to issue initial flogi for @vport
908 * 1 - successfully issued initial flogi for @vport
909 **/
732int 910int
733lpfc_initial_flogi(struct lpfc_vport *vport) 911lpfc_initial_flogi(struct lpfc_vport *vport)
734{ 912{
@@ -764,6 +942,22 @@ lpfc_initial_flogi(struct lpfc_vport *vport)
764 return 1; 942 return 1;
765} 943}
766 944
945/**
946 * lpfc_initial_fdisc: Issue an initial fabric discovery for a vport.
947 * @vport: pointer to a host virtual N_Port data structure.
948 *
949 * This routine issues an initial Fabric Discover (FDISC) for the @vport
950 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
951 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
952 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
953 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
954 * is then invoked with the @vport and the ndlp to perform the FDISC for the
955 * @vport.
956 *
957 * Return code
958 * 0 - failed to issue initial fdisc for @vport
959 * 1 - successfully issued initial fdisc for @vport
960 **/
767int 961int
768lpfc_initial_fdisc(struct lpfc_vport *vport) 962lpfc_initial_fdisc(struct lpfc_vport *vport)
769{ 963{
@@ -797,6 +991,17 @@ lpfc_initial_fdisc(struct lpfc_vport *vport)
797 return 1; 991 return 1;
798} 992}
799 993
994/**
995 * lpfc_more_plogi: Check and issue remaining plogis for a vport.
996 * @vport: pointer to a host virtual N_Port data structure.
997 *
998 * This routine checks whether there are more remaining Port Logins
999 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1000 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1001 * to issue ELS PLOGIs up to the configured discover threads with the
1002 * @vport (@vport->cfg_discovery_threads). The function also decrement
1003 * the @vport's num_disc_node by 1 if it is not already 0.
1004 **/
800void 1005void
801lpfc_more_plogi(struct lpfc_vport *vport) 1006lpfc_more_plogi(struct lpfc_vport *vport)
802{ 1007{
@@ -819,6 +1024,37 @@ lpfc_more_plogi(struct lpfc_vport *vport)
819 return; 1024 return;
820} 1025}
821 1026
1027/**
1028 * lpfc_plogi_confirm_nport: Confirm pologi wwpn matches stored ndlp.
1029 * @phba: pointer to lpfc hba data structure.
1030 * @prsp: pointer to response IOCB payload.
1031 * @ndlp: pointer to a node-list data structure.
1032 *
1033 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1034 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1035 * The following cases are considered N_Port confirmed:
1036 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1037 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1038 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1039 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1040 * 1) if there is a node on vport list other than the @ndlp with the same
1041 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1042 * on that node to release the RPI associated with the node; 2) if there is
1043 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1044 * into, a new node shall be allocated (or activated). In either case, the
1045 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1046 * be released and the new_ndlp shall be put on to the vport node list and
1047 * its pointer returned as the confirmed node.
1048 *
1049 * Note that before the @ndlp got "released", the keepDID from not-matching
1050 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1051 * of the @ndlp. This is because the release of @ndlp is actually to put it
1052 * into an inactive state on the vport node list and the vport node list
1053 * management algorithm does not allow two node with a same DID.
1054 *
1055 * Return code
1056 * pointer to the PLOGI N_Port @ndlp
1057 **/
822static struct lpfc_nodelist * 1058static struct lpfc_nodelist *
823lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp, 1059lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
824 struct lpfc_nodelist *ndlp) 1060 struct lpfc_nodelist *ndlp)
@@ -922,6 +1158,17 @@ lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
922 return new_ndlp; 1158 return new_ndlp;
923} 1159}
924 1160
1161/**
1162 * lpfc_end_rscn: Check and handle more rscn for a vport.
1163 * @vport: pointer to a host virtual N_Port data structure.
1164 *
1165 * This routine checks whether more Registration State Change
1166 * Notifications (RSCNs) came in while the discovery state machine was in
1167 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1168 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1169 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1170 * handling the RSCNs.
1171 **/
925void 1172void
926lpfc_end_rscn(struct lpfc_vport *vport) 1173lpfc_end_rscn(struct lpfc_vport *vport)
927{ 1174{
@@ -943,6 +1190,26 @@ lpfc_end_rscn(struct lpfc_vport *vport)
943 } 1190 }
944} 1191}
945 1192
1193/**
1194 * lpfc_cmpl_els_plogi: Completion callback function for plogi.
1195 * @phba: pointer to lpfc hba data structure.
1196 * @cmdiocb: pointer to lpfc command iocb data structure.
1197 * @rspiocb: pointer to lpfc response iocb data structure.
1198 *
1199 * This routine is the completion callback function for issuing the Port
1200 * Login (PLOGI) command. For PLOGI completion, there must be an active
1201 * ndlp on the vport node list that matches the remote node ID from the
1202 * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply
1203 * ignored and command IOCB released. The PLOGI response IOCB status is
1204 * checked for error conditons. If there is error status reported, PLOGI
1205 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1206 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1207 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1208 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1209 * there are additional N_Port nodes with the vport that need to perform
1210 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1211 * PLOGIs.
1212 **/
946static void 1213static void
947lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 1214lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
948 struct lpfc_iocbq *rspiocb) 1215 struct lpfc_iocbq *rspiocb)
@@ -1048,6 +1315,27 @@ out:
1048 return; 1315 return;
1049} 1316}
1050 1317
1318/**
1319 * lpfc_issue_els_plogi: Issue an plogi iocb command for a vport.
1320 * @vport: pointer to a host virtual N_Port data structure.
1321 * @did: destination port identifier.
1322 * @retry: number of retries to the command IOCB.
1323 *
1324 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1325 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1326 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1327 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1328 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1329 *
1330 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1331 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1332 * will be stored into the context1 field of the IOCB for the completion
1333 * callback function to the PLOGI ELS command.
1334 *
1335 * Return code
1336 * 0 - Successfully issued a plogi for @vport
1337 * 1 - failed to issue a plogi for @vport
1338 **/
1051int 1339int
1052lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) 1340lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
1053{ 1341{
@@ -1106,6 +1394,19 @@ lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
1106 return 0; 1394 return 0;
1107} 1395}
1108 1396
1397/**
1398 * lpfc_cmpl_els_prli: Completion callback function for prli.
1399 * @phba: pointer to lpfc hba data structure.
1400 * @cmdiocb: pointer to lpfc command iocb data structure.
1401 * @rspiocb: pointer to lpfc response iocb data structure.
1402 *
1403 * This routine is the completion callback function for a Process Login
1404 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1405 * status. If there is error status reported, PRLI retry shall be attempted
1406 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1407 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1408 * ndlp to mark the PRLI completion.
1409 **/
1109static void 1410static void
1110lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 1411lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1111 struct lpfc_iocbq *rspiocb) 1412 struct lpfc_iocbq *rspiocb)
@@ -1164,6 +1465,27 @@ out:
1164 return; 1465 return;
1165} 1466}
1166 1467
1468/**
1469 * lpfc_issue_els_prli: Issue a prli iocb command for a vport.
1470 * @vport: pointer to a host virtual N_Port data structure.
1471 * @ndlp: pointer to a node-list data structure.
1472 * @retry: number of retries to the command IOCB.
1473 *
1474 * This routine issues a Process Login (PRLI) ELS command for the
1475 * @vport. The PRLI service parameters are set up in the payload of the
1476 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1477 * is put to the IOCB completion callback func field before invoking the
1478 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1479 *
1480 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1481 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1482 * will be stored into the context1 field of the IOCB for the completion
1483 * callback function to the PRLI ELS command.
1484 *
1485 * Return code
1486 * 0 - successfully issued prli iocb command for @vport
1487 * 1 - failed to issue prli iocb command for @vport
1488 **/
1167int 1489int
1168lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, 1490lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1169 uint8_t retry) 1491 uint8_t retry)
@@ -1233,6 +1555,15 @@ lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1233 return 0; 1555 return 0;
1234} 1556}
1235 1557
1558/**
1559 * lpfc_more_adisc: Issue more adisc as needed.
1560 * @vport: pointer to a host virtual N_Port data structure.
1561 *
1562 * This routine determines whether there are more ndlps on a @vport
1563 * node list need to have Address Discover (ADISC) issued. If so, it will
1564 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
1565 * remaining nodes which need to have ADISC sent.
1566 **/
1236void 1567void
1237lpfc_more_adisc(struct lpfc_vport *vport) 1568lpfc_more_adisc(struct lpfc_vport *vport)
1238{ 1569{
@@ -1255,6 +1586,18 @@ lpfc_more_adisc(struct lpfc_vport *vport)
1255 return; 1586 return;
1256} 1587}
1257 1588
1589/**
1590 * lpfc_rscn_disc: Perform rscn discovery for a vport.
1591 * @vport: pointer to a host virtual N_Port data structure.
1592 *
1593 * This routine performs Registration State Change Notification (RSCN)
1594 * discovery for a @vport. If the @vport's node port recovery count is not
1595 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1596 * the nodes that need recovery. If none of the PLOGI were needed through
1597 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1598 * invoked to check and handle possible more RSCN came in during the period
1599 * of processing the current ones.
1600 **/
1258static void 1601static void
1259lpfc_rscn_disc(struct lpfc_vport *vport) 1602lpfc_rscn_disc(struct lpfc_vport *vport)
1260{ 1603{
@@ -1269,6 +1612,22 @@ lpfc_rscn_disc(struct lpfc_vport *vport)
1269 lpfc_end_rscn(vport); 1612 lpfc_end_rscn(vport);
1270} 1613}
1271 1614
1615/**
1616 * lpfc_cmpl_els_adisc: Completion callback function for adisc.
1617 * @phba: pointer to lpfc hba data structure.
1618 * @cmdiocb: pointer to lpfc command iocb data structure.
1619 * @rspiocb: pointer to lpfc response iocb data structure.
1620 *
1621 * This routine is the completion function for issuing the Address Discover
1622 * (ADISC) command. It first checks to see whether link went down during
1623 * the discovery process. If so, the node will be marked as node port
1624 * recovery for issuing discover IOCB by the link attention handler and
1625 * exit. Otherwise, the response status is checked. If error was reported
1626 * in the response status, the ADISC command shall be retried by invoking
1627 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
1628 * the response status, the state machine is invoked to set transition
1629 * with respect to NLP_EVT_CMPL_ADISC event.
1630 **/
1272static void 1631static void
1273lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 1632lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1274 struct lpfc_iocbq *rspiocb) 1633 struct lpfc_iocbq *rspiocb)
@@ -1384,6 +1743,26 @@ out:
1384 return; 1743 return;
1385} 1744}
1386 1745
1746/**
1747 * lpfc_issue_els_adisc: Issue an address discover iocb to an node on a vport.
1748 * @vport: pointer to a virtual N_Port data structure.
1749 * @ndlp: pointer to a node-list data structure.
1750 * @retry: number of retries to the command IOCB.
1751 *
1752 * This routine issues an Address Discover (ADISC) for an @ndlp on a
1753 * @vport. It prepares the payload of the ADISC ELS command, updates the
1754 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
1755 * to issue the ADISC ELS command.
1756 *
1757 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1758 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1759 * will be stored into the context1 field of the IOCB for the completion
1760 * callback function to the ADISC ELS command.
1761 *
1762 * Return code
1763 * 0 - successfully issued adisc
1764 * 1 - failed to issue adisc
1765 **/
1387int 1766int
1388lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, 1767lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1389 uint8_t retry) 1768 uint8_t retry)
@@ -1437,6 +1816,18 @@ lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1437 return 0; 1816 return 0;
1438} 1817}
1439 1818
1819/**
1820 * lpfc_cmpl_els_logo: Completion callback function for logo.
1821 * @phba: pointer to lpfc hba data structure.
1822 * @cmdiocb: pointer to lpfc command iocb data structure.
1823 * @rspiocb: pointer to lpfc response iocb data structure.
1824 *
1825 * This routine is the completion function for issuing the ELS Logout (LOGO)
1826 * command. If no error status was reported from the LOGO response, the
1827 * state machine of the associated ndlp shall be invoked for transition with
1828 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
1829 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
1830 **/
1440static void 1831static void
1441lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 1832lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1442 struct lpfc_iocbq *rspiocb) 1833 struct lpfc_iocbq *rspiocb)
@@ -1502,6 +1893,26 @@ out:
1502 return; 1893 return;
1503} 1894}
1504 1895
1896/**
1897 * lpfc_issue_els_logo: Issue a logo to an node on a vport.
1898 * @vport: pointer to a virtual N_Port data structure.
1899 * @ndlp: pointer to a node-list data structure.
1900 * @retry: number of retries to the command IOCB.
1901 *
1902 * This routine constructs and issues an ELS Logout (LOGO) iocb command
1903 * to a remote node, referred by an @ndlp on a @vport. It constructs the
1904 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
1905 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
1906 *
1907 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1908 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1909 * will be stored into the context1 field of the IOCB for the completion
1910 * callback function to the LOGO ELS command.
1911 *
1912 * Return code
1913 * 0 - successfully issued logo
1914 * 1 - failed to issue logo
1915 **/
1505int 1916int
1506lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, 1917lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1507 uint8_t retry) 1918 uint8_t retry)
@@ -1563,6 +1974,22 @@ lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1563 return 0; 1974 return 0;
1564} 1975}
1565 1976
1977/**
1978 * lpfc_cmpl_els_cmd: Completion callback function for generic els command.
1979 * @phba: pointer to lpfc hba data structure.
1980 * @cmdiocb: pointer to lpfc command iocb data structure.
1981 * @rspiocb: pointer to lpfc response iocb data structure.
1982 *
1983 * This routine is a generic completion callback function for ELS commands.
1984 * Specifically, it is the callback function which does not need to perform
1985 * any command specific operations. It is currently used by the ELS command
1986 * issuing routines for the ELS State Change Request (SCR),
1987 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
1988 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
1989 * certain debug loggings, this callback function simply invokes the
1990 * lpfc_els_chk_latt() routine to check whether link went down during the
1991 * discovery process.
1992 **/
1566static void 1993static void
1567lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 1994lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1568 struct lpfc_iocbq *rspiocb) 1995 struct lpfc_iocbq *rspiocb)
@@ -1587,6 +2014,28 @@ lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1587 return; 2014 return;
1588} 2015}
1589 2016
2017/**
2018 * lpfc_issue_els_scr: Issue a scr to an node on a vport.
2019 * @vport: pointer to a host virtual N_Port data structure.
2020 * @nportid: N_Port identifier to the remote node.
2021 * @retry: number of retries to the command IOCB.
2022 *
2023 * This routine issues a State Change Request (SCR) to a fabric node
2024 * on a @vport. The remote node @nportid is passed into the function. It
2025 * first search the @vport node list to find the matching ndlp. If no such
2026 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2027 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2028 * routine is invoked to send the SCR IOCB.
2029 *
2030 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2031 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2032 * will be stored into the context1 field of the IOCB for the completion
2033 * callback function to the SCR ELS command.
2034 *
2035 * Return code
2036 * 0 - Successfully issued scr command
2037 * 1 - Failed to issue scr command
2038 **/
1590int 2039int
1591lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) 2040lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
1592{ 2041{
@@ -1659,6 +2108,28 @@ lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
1659 return 0; 2108 return 0;
1660} 2109}
1661 2110
2111/**
2112 * lpfc_issue_els_farpr: Issue a farp to an node on a vport.
2113 * @vport: pointer to a host virtual N_Port data structure.
2114 * @nportid: N_Port identifier to the remote node.
2115 * @retry: number of retries to the command IOCB.
2116 *
2117 * This routine issues a Fibre Channel Address Resolution Response
2118 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2119 * is passed into the function. It first search the @vport node list to find
2120 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2121 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2122 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2123 *
2124 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2125 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2126 * will be stored into the context1 field of the IOCB for the completion
2127 * callback function to the PARPR ELS command.
2128 *
2129 * Return code
2130 * 0 - Successfully issued farpr command
2131 * 1 - Failed to issue farpr command
2132 **/
1662static int 2133static int
1663lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) 2134lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
1664{ 2135{
@@ -1748,6 +2219,18 @@ lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
1748 return 0; 2219 return 0;
1749} 2220}
1750 2221
2222/**
2223 * lpfc_cancel_retry_delay_tmo: Cancel the timer with delayed iocb-cmd retry.
2224 * @vport: pointer to a host virtual N_Port data structure.
2225 * @nlp: pointer to a node-list data structure.
2226 *
2227 * This routine cancels the timer with a delayed IOCB-command retry for
2228 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2229 * removes the ELS retry event if it presents. In addition, if the
2230 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2231 * commands are sent for the @vport's nodes that require issuing discovery
2232 * ADISC.
2233 **/
1751void 2234void
1752lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp) 2235lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
1753{ 2236{
@@ -1794,6 +2277,20 @@ lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
1794 return; 2277 return;
1795} 2278}
1796 2279
2280/**
2281 * lpfc_els_retry_delay: Timer function with a ndlp delayed function timer.
2282 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2283 *
2284 * This routine is invoked by the ndlp delayed-function timer to check
2285 * whether there is any pending ELS retry event(s) with the node. If not, it
2286 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2287 * adds the delayed events to the HBA work list and invokes the
2288 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2289 * event. Note that lpfc_nlp_get() is called before posting the event to
2290 * the work list to hold reference count of ndlp so that it guarantees the
2291 * reference to ndlp will still be available when the worker thread gets
2292 * to the event associated with the ndlp.
2293 **/
1797void 2294void
1798lpfc_els_retry_delay(unsigned long ptr) 2295lpfc_els_retry_delay(unsigned long ptr)
1799{ 2296{
@@ -1822,6 +2319,15 @@ lpfc_els_retry_delay(unsigned long ptr)
1822 return; 2319 return;
1823} 2320}
1824 2321
2322/**
2323 * lpfc_els_retry_delay_handler: Work thread handler for ndlp delayed function.
2324 * @ndlp: pointer to a node-list data structure.
2325 *
2326 * This routine is the worker-thread handler for processing the @ndlp delayed
2327 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2328 * the last ELS command from the associated ndlp and invokes the proper ELS
2329 * function according to the delayed ELS command to retry the command.
2330 **/
1825void 2331void
1826lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) 2332lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
1827{ 2333{
@@ -1884,6 +2390,27 @@ lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
1884 return; 2390 return;
1885} 2391}
1886 2392
2393/**
2394 * lpfc_els_retry: Make retry decision on an els command iocb.
2395 * @phba: pointer to lpfc hba data structure.
2396 * @cmdiocb: pointer to lpfc command iocb data structure.
2397 * @rspiocb: pointer to lpfc response iocb data structure.
2398 *
2399 * This routine makes a retry decision on an ELS command IOCB, which has
2400 * failed. The following ELS IOCBs use this function for retrying the command
2401 * when previously issued command responsed with error status: FLOGI, PLOGI,
2402 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2403 * returned error status, it makes the decision whether a retry shall be
2404 * issued for the command, and whether a retry shall be made immediately or
2405 * delayed. In the former case, the corresponding ELS command issuing-function
2406 * is called to retry the command. In the later case, the ELS command shall
2407 * be posted to the ndlp delayed event and delayed function timer set to the
2408 * ndlp for the delayed command issusing.
2409 *
2410 * Return code
2411 * 0 - No retry of els command is made
2412 * 1 - Immediate or delayed retry of els command is made
2413 **/
1887static int 2414static int
1888lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 2415lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1889 struct lpfc_iocbq *rspiocb) 2416 struct lpfc_iocbq *rspiocb)
@@ -2182,12 +2709,26 @@ lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2182 return 0; 2709 return 0;
2183} 2710}
2184 2711
2712/**
2713 * lpfc_els_free_data: Free lpfc dma buffer and data structure with an iocb.
2714 * @phba: pointer to lpfc hba data structure.
2715 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
2716 *
2717 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
2718 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
2719 * checks to see whether there is a lpfc DMA buffer associated with the
2720 * response of the command IOCB. If so, it will be released before releasing
2721 * the lpfc DMA buffer associated with the IOCB itself.
2722 *
2723 * Return code
2724 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2725 **/
2185static int 2726static int
2186lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) 2727lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
2187{ 2728{
2188 struct lpfc_dmabuf *buf_ptr; 2729 struct lpfc_dmabuf *buf_ptr;
2189 2730
2190 /* Free the response before processing the command. */ 2731 /* Free the response before processing the command. */
2191 if (!list_empty(&buf_ptr1->list)) { 2732 if (!list_empty(&buf_ptr1->list)) {
2192 list_remove_head(&buf_ptr1->list, buf_ptr, 2733 list_remove_head(&buf_ptr1->list, buf_ptr,
2193 struct lpfc_dmabuf, 2734 struct lpfc_dmabuf,
@@ -2200,6 +2741,18 @@ lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
2200 return 0; 2741 return 0;
2201} 2742}
2202 2743
2744/**
2745 * lpfc_els_free_bpl: Free lpfc dma buffer and data structure with bpl.
2746 * @phba: pointer to lpfc hba data structure.
2747 * @buf_ptr: pointer to the lpfc dma buffer data structure.
2748 *
2749 * This routine releases the lpfc Direct Memory Access (DMA) buffer
2750 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
2751 * pool.
2752 *
2753 * Return code
2754 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2755 **/
2203static int 2756static int
2204lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) 2757lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
2205{ 2758{
@@ -2208,6 +2761,33 @@ lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
2208 return 0; 2761 return 0;
2209} 2762}
2210 2763
2764/**
2765 * lpfc_els_free_iocb: Free a command iocb and its associated resources.
2766 * @phba: pointer to lpfc hba data structure.
2767 * @elsiocb: pointer to lpfc els command iocb data structure.
2768 *
2769 * This routine frees a command IOCB and its associated resources. The
2770 * command IOCB data structure contains the reference to various associated
2771 * resources, these fields must be set to NULL if the associated reference
2772 * not present:
2773 * context1 - reference to ndlp
2774 * context2 - reference to cmd
2775 * context2->next - reference to rsp
2776 * context3 - reference to bpl
2777 *
2778 * It first properly decrements the reference count held on ndlp for the
2779 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
2780 * set, it invokes the lpfc_els_free_data() routine to release the Direct
2781 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
2782 * adds the DMA buffer the @phba data structure for the delayed release.
2783 * If reference to the Buffer Pointer List (BPL) is present, the
2784 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
2785 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
2786 * invoked to release the IOCB data structure back to @phba IOCBQ list.
2787 *
2788 * Return code
2789 * 0 - Success (currently, always return 0)
2790 **/
2211int 2791int
2212lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) 2792lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
2213{ 2793{
@@ -2274,6 +2854,23 @@ lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
2274 return 0; 2854 return 0;
2275} 2855}
2276 2856
2857/**
2858 * lpfc_cmpl_els_logo_acc: Completion callback function to logo acc response.
2859 * @phba: pointer to lpfc hba data structure.
2860 * @cmdiocb: pointer to lpfc command iocb data structure.
2861 * @rspiocb: pointer to lpfc response iocb data structure.
2862 *
2863 * This routine is the completion callback function to the Logout (LOGO)
2864 * Accept (ACC) Response ELS command. This routine is invoked to indicate
2865 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
2866 * release the ndlp if it has the last reference remaining (reference count
2867 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
2868 * field to NULL to inform the following lpfc_els_free_iocb() routine no
2869 * ndlp reference count needs to be decremented. Otherwise, the ndlp
2870 * reference use-count shall be decremented by the lpfc_els_free_iocb()
2871 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
2872 * IOCB data structure.
2873 **/
2277static void 2874static void
2278lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 2875lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2279 struct lpfc_iocbq *rspiocb) 2876 struct lpfc_iocbq *rspiocb)
@@ -2311,6 +2908,19 @@ lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2311 return; 2908 return;
2312} 2909}
2313 2910
2911/**
2912 * lpfc_mbx_cmpl_dflt_rpi: Completion callbk func for unreg dflt rpi mbox cmd.
2913 * @phba: pointer to lpfc hba data structure.
2914 * @pmb: pointer to the driver internal queue element for mailbox command.
2915 *
2916 * This routine is the completion callback function for unregister default
2917 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
2918 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
2919 * decrements the ndlp reference count held for this completion callback
2920 * function. After that, it invokes the lpfc_nlp_not_used() to check
2921 * whether there is only one reference left on the ndlp. If so, it will
2922 * perform one more decrement and trigger the release of the ndlp.
2923 **/
2314void 2924void
2315lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) 2925lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2316{ 2926{
@@ -2332,6 +2942,22 @@ lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2332 return; 2942 return;
2333} 2943}
2334 2944
2945/**
2946 * lpfc_cmpl_els_rsp: Completion callback function for els response iocb cmd.
2947 * @phba: pointer to lpfc hba data structure.
2948 * @cmdiocb: pointer to lpfc command iocb data structure.
2949 * @rspiocb: pointer to lpfc response iocb data structure.
2950 *
2951 * This routine is the completion callback function for ELS Response IOCB
2952 * command. In normal case, this callback function just properly sets the
2953 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
2954 * field in the command IOCB is not NULL, the referred mailbox command will
2955 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
2956 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
2957 * link down event occurred during the discovery, the lpfc_nlp_not_used()
2958 * routine shall be invoked trying to release the ndlp if no other threads
2959 * are currently referring it.
2960 **/
2335static void 2961static void
2336lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 2962lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2337 struct lpfc_iocbq *rspiocb) 2963 struct lpfc_iocbq *rspiocb)
@@ -2487,6 +3113,31 @@ out:
2487 return; 3113 return;
2488} 3114}
2489 3115
3116/**
3117 * lpfc_els_rsp_acc: Prepare and issue an acc response iocb command.
3118 * @vport: pointer to a host virtual N_Port data structure.
3119 * @flag: the els command code to be accepted.
3120 * @oldiocb: pointer to the original lpfc command iocb data structure.
3121 * @ndlp: pointer to a node-list data structure.
3122 * @mbox: pointer to the driver internal queue element for mailbox command.
3123 *
3124 * This routine prepares and issues an Accept (ACC) response IOCB
3125 * command. It uses the @flag to properly set up the IOCB field for the
3126 * specific ACC response command to be issued and invokes the
3127 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3128 * @mbox pointer is passed in, it will be put into the context_un.mbox
3129 * field of the IOCB for the completion callback function to issue the
3130 * mailbox command to the HBA later when callback is invoked.
3131 *
3132 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3133 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3134 * will be stored into the context1 field of the IOCB for the completion
3135 * callback function to the corresponding response ELS IOCB command.
3136 *
3137 * Return code
3138 * 0 - Successfully issued acc response
3139 * 1 - Failed to issue acc response
3140 **/
2490int 3141int
2491lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, 3142lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
2492 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, 3143 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
@@ -2601,6 +3252,28 @@ lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
2601 return 0; 3252 return 0;
2602} 3253}
2603 3254
3255/**
3256 * lpfc_els_rsp_reject: Propare and issue a rjt response iocb command.
3257 * @vport: pointer to a virtual N_Port data structure.
3258 * @rejectError:
3259 * @oldiocb: pointer to the original lpfc command iocb data structure.
3260 * @ndlp: pointer to a node-list data structure.
3261 * @mbox: pointer to the driver internal queue element for mailbox command.
3262 *
3263 * This routine prepares and issue an Reject (RJT) response IOCB
3264 * command. If a @mbox pointer is passed in, it will be put into the
3265 * context_un.mbox field of the IOCB for the completion callback function
3266 * to issue to the HBA later.
3267 *
3268 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3269 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3270 * will be stored into the context1 field of the IOCB for the completion
3271 * callback function to the reject response ELS IOCB command.
3272 *
3273 * Return code
3274 * 0 - Successfully issued reject response
3275 * 1 - Failed to issue reject response
3276 **/
2604int 3277int
2605lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, 3278lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
2606 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, 3279 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
@@ -2660,6 +3333,25 @@ lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
2660 return 0; 3333 return 0;
2661} 3334}
2662 3335
3336/**
3337 * lpfc_els_rsp_adisc_acc: Prepare and issue acc response to adisc iocb cmd.
3338 * @vport: pointer to a virtual N_Port data structure.
3339 * @oldiocb: pointer to the original lpfc command iocb data structure.
3340 * @ndlp: pointer to a node-list data structure.
3341 *
3342 * This routine prepares and issues an Accept (ACC) response to Address
3343 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3344 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3345 *
3346 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3347 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3348 * will be stored into the context1 field of the IOCB for the completion
3349 * callback function to the ADISC Accept response ELS IOCB command.
3350 *
3351 * Return code
3352 * 0 - Successfully issued acc adisc response
3353 * 1 - Failed to issue adisc acc response
3354 **/
2663int 3355int
2664lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, 3356lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
2665 struct lpfc_nodelist *ndlp) 3357 struct lpfc_nodelist *ndlp)
@@ -2716,6 +3408,25 @@ lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
2716 return 0; 3408 return 0;
2717} 3409}
2718 3410
3411/**
3412 * lpfc_els_rsp_prli_acc: Prepare and issue acc response to prli iocb cmd.
3413 * @vport: pointer to a virtual N_Port data structure.
3414 * @oldiocb: pointer to the original lpfc command iocb data structure.
3415 * @ndlp: pointer to a node-list data structure.
3416 *
3417 * This routine prepares and issues an Accept (ACC) response to Process
3418 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3419 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3420 *
3421 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3422 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3423 * will be stored into the context1 field of the IOCB for the completion
3424 * callback function to the PRLI Accept response ELS IOCB command.
3425 *
3426 * Return code
3427 * 0 - Successfully issued acc prli response
3428 * 1 - Failed to issue acc prli response
3429 **/
2719int 3430int
2720lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, 3431lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
2721 struct lpfc_nodelist *ndlp) 3432 struct lpfc_nodelist *ndlp)
@@ -2795,6 +3506,32 @@ lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
2795 return 0; 3506 return 0;
2796} 3507}
2797 3508
3509/**
3510 * lpfc_els_rsp_rnid_acc: Issue rnid acc response iocb command.
3511 * @vport: pointer to a virtual N_Port data structure.
3512 * @format: rnid command format.
3513 * @oldiocb: pointer to the original lpfc command iocb data structure.
3514 * @ndlp: pointer to a node-list data structure.
3515 *
3516 * This routine issues a Request Node Identification Data (RNID) Accept
3517 * (ACC) response. It constructs the RNID ACC response command according to
3518 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3519 * issue the response. Note that this command does not need to hold the ndlp
3520 * reference count for the callback. So, the ndlp reference count taken by
3521 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3522 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3523 * there is no ndlp reference available.
3524 *
3525 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3526 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3527 * will be stored into the context1 field of the IOCB for the completion
3528 * callback function. However, for the RNID Accept Response ELS command,
3529 * this is undone later by this routine after the IOCB is allocated.
3530 *
3531 * Return code
3532 * 0 - Successfully issued acc rnid response
3533 * 1 - Failed to issue acc rnid response
3534 **/
2798static int 3535static int
2799lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, 3536lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
2800 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) 3537 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
@@ -2875,6 +3612,25 @@ lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
2875 return 0; 3612 return 0;
2876} 3613}
2877 3614
3615/**
3616 * lpfc_els_disc_adisc: Issue remaining adisc iocbs to npr nodes of a vport.
3617 * @vport: pointer to a host virtual N_Port data structure.
3618 *
3619 * This routine issues Address Discover (ADISC) ELS commands to those
3620 * N_Ports which are in node port recovery state and ADISC has not been issued
3621 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
3622 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
3623 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
3624 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
3625 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
3626 * IOCBs quit for later pick up. On the other hand, after walking through
3627 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
3628 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
3629 * no more ADISC need to be sent.
3630 *
3631 * Return code
3632 * The number of N_Ports with adisc issued.
3633 **/
2878int 3634int
2879lpfc_els_disc_adisc(struct lpfc_vport *vport) 3635lpfc_els_disc_adisc(struct lpfc_vport *vport)
2880{ 3636{
@@ -2914,6 +3670,25 @@ lpfc_els_disc_adisc(struct lpfc_vport *vport)
2914 return sentadisc; 3670 return sentadisc;
2915} 3671}
2916 3672
3673/**
3674 * lpfc_els_disc_plogi: Issue plogi for all npr nodes of a vport before adisc.
3675 * @vport: pointer to a host virtual N_Port data structure.
3676 *
3677 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
3678 * which are in node port recovery state, with a @vport. Each time an ELS
3679 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
3680 * the per @vport number of discover count (num_disc_nodes) shall be
3681 * incremented. If the num_disc_nodes reaches a pre-configured threshold
3682 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
3683 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
3684 * later pick up. On the other hand, after walking through all the ndlps with
3685 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
3686 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
3687 * PLOGI need to be sent.
3688 *
3689 * Return code
3690 * The number of N_Ports with plogi issued.
3691 **/
2917int 3692int
2918lpfc_els_disc_plogi(struct lpfc_vport *vport) 3693lpfc_els_disc_plogi(struct lpfc_vport *vport)
2919{ 3694{
@@ -2954,6 +3729,15 @@ lpfc_els_disc_plogi(struct lpfc_vport *vport)
2954 return sentplogi; 3729 return sentplogi;
2955} 3730}
2956 3731
3732/**
3733 * lpfc_els_flush_rscn: Clean up any rscn activities with a vport.
3734 * @vport: pointer to a host virtual N_Port data structure.
3735 *
3736 * This routine cleans up any Registration State Change Notification
3737 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
3738 * @vport together with the host_lock is used to prevent multiple thread
3739 * trying to access the RSCN array on a same @vport at the same time.
3740 **/
2957void 3741void
2958lpfc_els_flush_rscn(struct lpfc_vport *vport) 3742lpfc_els_flush_rscn(struct lpfc_vport *vport)
2959{ 3743{
@@ -2984,6 +3768,18 @@ lpfc_els_flush_rscn(struct lpfc_vport *vport)
2984 vport->fc_rscn_flush = 0; 3768 vport->fc_rscn_flush = 0;
2985} 3769}
2986 3770
3771/**
3772 * lpfc_rscn_payload_check: Check whether there is a pending rscn to a did.
3773 * @vport: pointer to a host virtual N_Port data structure.
3774 * @did: remote destination port identifier.
3775 *
3776 * This routine checks whether there is any pending Registration State
3777 * Configuration Notification (RSCN) to a @did on @vport.
3778 *
3779 * Return code
3780 * None zero - The @did matched with a pending rscn
3781 * 0 - not able to match @did with a pending rscn
3782 **/
2987int 3783int
2988lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) 3784lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
2989{ 3785{
@@ -3053,6 +3849,17 @@ return_did_out:
3053 return did; 3849 return did;
3054} 3850}
3055 3851
3852/**
3853 * lpfc_rscn_recovery_check: Send recovery event to vport nodes matching rscn
3854 * @vport: pointer to a host virtual N_Port data structure.
3855 *
3856 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
3857 * state machine for a @vport's nodes that are with pending RSCN (Registration
3858 * State Change Notification).
3859 *
3860 * Return code
3861 * 0 - Successful (currently alway return 0)
3862 **/
3056static int 3863static int
3057lpfc_rscn_recovery_check(struct lpfc_vport *vport) 3864lpfc_rscn_recovery_check(struct lpfc_vport *vport)
3058{ 3865{
@@ -3071,6 +3878,28 @@ lpfc_rscn_recovery_check(struct lpfc_vport *vport)
3071 return 0; 3878 return 0;
3072} 3879}
3073 3880
3881/**
3882 * lpfc_els_rcv_rscn: Process an unsolicited rscn iocb.
3883 * @vport: pointer to a host virtual N_Port data structure.
3884 * @cmdiocb: pointer to lpfc command iocb data structure.
3885 * @ndlp: pointer to a node-list data structure.
3886 *
3887 * This routine processes an unsolicited RSCN (Registration State Change
3888 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
3889 * to invoke fc_host_post_event() routine to the FC transport layer. If the
3890 * discover state machine is about to begin discovery, it just accepts the
3891 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
3892 * contains N_Port IDs for other vports on this HBA, it just accepts the
3893 * RSCN and ignore processing it. If the state machine is in the recovery
3894 * state, the fc_rscn_id_list of this @vport is walked and the
3895 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
3896 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
3897 * routine is invoked to handle the RSCN event.
3898 *
3899 * Return code
3900 * 0 - Just sent the acc response
3901 * 1 - Sent the acc response and waited for name server completion
3902 **/
3074static int 3903static int
3075lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 3904lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3076 struct lpfc_nodelist *ndlp) 3905 struct lpfc_nodelist *ndlp)
@@ -3241,6 +4070,22 @@ lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3241 return lpfc_els_handle_rscn(vport); 4070 return lpfc_els_handle_rscn(vport);
3242} 4071}
3243 4072
4073/**
4074 * lpfc_els_handle_rscn: Handle rscn for a vport.
4075 * @vport: pointer to a host virtual N_Port data structure.
4076 *
4077 * This routine handles the Registration State Configuration Notification
4078 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4079 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4080 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4081 * NameServer shall be issued. If CT command to the NameServer fails to be
4082 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4083 * RSCN activities with the @vport.
4084 *
4085 * Return code
4086 * 0 - Cleaned up rscn on the @vport
4087 * 1 - Wait for plogi to name server before proceed
4088 **/
3244int 4089int
3245lpfc_els_handle_rscn(struct lpfc_vport *vport) 4090lpfc_els_handle_rscn(struct lpfc_vport *vport)
3246{ 4091{
@@ -3313,6 +4158,31 @@ lpfc_els_handle_rscn(struct lpfc_vport *vport)
3313 return 0; 4158 return 0;
3314} 4159}
3315 4160
4161/**
4162 * lpfc_els_rcv_flogi: Process an unsolicited flogi iocb.
4163 * @vport: pointer to a host virtual N_Port data structure.
4164 * @cmdiocb: pointer to lpfc command iocb data structure.
4165 * @ndlp: pointer to a node-list data structure.
4166 *
4167 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4168 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4169 * point topology. As an unsolicited FLOGI should not be received in a loop
4170 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4171 * lpfc_check_sparm() routine is invoked to check the parameters in the
4172 * unsolicited FLOGI. If parameters validation failed, the routine
4173 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4174 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4175 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4176 * will initiate PLOGI. The higher lexicographical value party shall has
4177 * higher priority (as the winning port) and will initiate PLOGI and
4178 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4179 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4180 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4181 *
4182 * Return code
4183 * 0 - Successfully processed the unsolicited flogi
4184 * 1 - Failed to process the unsolicited flogi
4185 **/
3316static int 4186static int
3317lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 4187lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3318 struct lpfc_nodelist *ndlp) 4188 struct lpfc_nodelist *ndlp)
@@ -3402,6 +4272,22 @@ lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3402 return 0; 4272 return 0;
3403} 4273}
3404 4274
4275/**
4276 * lpfc_els_rcv_rnid: Process an unsolicited rnid iocb.
4277 * @vport: pointer to a host virtual N_Port data structure.
4278 * @cmdiocb: pointer to lpfc command iocb data structure.
4279 * @ndlp: pointer to a node-list data structure.
4280 *
4281 * This routine processes Request Node Identification Data (RNID) IOCB
4282 * received as an ELS unsolicited event. Only when the RNID specified format
4283 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4284 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4285 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4286 * rejected by invoking the lpfc_els_rsp_reject() routine.
4287 *
4288 * Return code
4289 * 0 - Successfully processed rnid iocb (currently always return 0)
4290 **/
3405static int 4291static int
3406lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 4292lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3407 struct lpfc_nodelist *ndlp) 4293 struct lpfc_nodelist *ndlp)
@@ -3441,6 +4327,19 @@ lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3441 return 0; 4327 return 0;
3442} 4328}
3443 4329
4330/**
4331 * lpfc_els_rcv_lirr: Process an unsolicited lirr iocb.
4332 * @vport: pointer to a host virtual N_Port data structure.
4333 * @cmdiocb: pointer to lpfc command iocb data structure.
4334 * @ndlp: pointer to a node-list data structure.
4335 *
4336 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4337 * received as an ELS unsolicited event. Currently, this function just invokes
4338 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4339 *
4340 * Return code
4341 * 0 - Successfully processed lirr iocb (currently always return 0)
4342 **/
3444static int 4343static int
3445lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 4344lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3446 struct lpfc_nodelist *ndlp) 4345 struct lpfc_nodelist *ndlp)
@@ -3456,6 +4355,25 @@ lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3456 return 0; 4355 return 0;
3457} 4356}
3458 4357
4358/**
4359 * lpfc_els_rsp_rps_acc: Completion callbk func for MBX_READ_LNK_STAT mbox cmd.
4360 * @phba: pointer to lpfc hba data structure.
4361 * @pmb: pointer to the driver internal queue element for mailbox command.
4362 *
4363 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4364 * mailbox command. This callback function is to actually send the Accept
4365 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4366 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4367 * mailbox command, constructs the RPS response with the link statistics
4368 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4369 * response to the RPS.
4370 *
4371 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4372 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4373 * will be stored into the context1 field of the IOCB for the completion
4374 * callback function to the RPS Accept Response ELS IOCB command.
4375 *
4376 **/
3459static void 4377static void
3460lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) 4378lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3461{ 4379{
@@ -3531,6 +4449,24 @@ lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3531 return; 4449 return;
3532} 4450}
3533 4451
4452/**
4453 * lpfc_els_rcv_rps: Process an unsolicited rps iocb.
4454 * @vport: pointer to a host virtual N_Port data structure.
4455 * @cmdiocb: pointer to lpfc command iocb data structure.
4456 * @ndlp: pointer to a node-list data structure.
4457 *
4458 * This routine processes Read Port Status (RPS) IOCB received as an
4459 * ELS unsolicited event. It first checks the remote port state. If the
4460 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
4461 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
4462 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
4463 * for reading the HBA link statistics. It is for the callback function,
4464 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
4465 * to actually sending out RPS Accept (ACC) response.
4466 *
4467 * Return codes
4468 * 0 - Successfully processed rps iocb (currently always return 0)
4469 **/
3534static int 4470static int
3535lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 4471lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3536 struct lpfc_nodelist *ndlp) 4472 struct lpfc_nodelist *ndlp)
@@ -3592,6 +4528,25 @@ lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3592 return 0; 4528 return 0;
3593} 4529}
3594 4530
4531/**
4532 * lpfc_els_rsp_rpl_acc: Issue an accept rpl els command.
4533 * @vport: pointer to a host virtual N_Port data structure.
4534 * @cmdsize: size of the ELS command.
4535 * @oldiocb: pointer to the original lpfc command iocb data structure.
4536 * @ndlp: pointer to a node-list data structure.
4537 *
4538 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
4539 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
4540 *
4541 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4542 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4543 * will be stored into the context1 field of the IOCB for the completion
4544 * callback function to the RPL Accept Response ELS command.
4545 *
4546 * Return code
4547 * 0 - Successfully issued ACC RPL ELS command
4548 * 1 - Failed to issue ACC RPL ELS command
4549 **/
3595static int 4550static int
3596lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, 4551lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
3597 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) 4552 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
@@ -3645,6 +4600,22 @@ lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
3645 return 0; 4600 return 0;
3646} 4601}
3647 4602
4603/**
4604 * lpfc_els_rcv_rpl: Process an unsolicited rpl iocb.
4605 * @vport: pointer to a host virtual N_Port data structure.
4606 * @cmdiocb: pointer to lpfc command iocb data structure.
4607 * @ndlp: pointer to a node-list data structure.
4608 *
4609 * This routine processes Read Port List (RPL) IOCB received as an ELS
4610 * unsolicited event. It first checks the remote port state. If the remote
4611 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
4612 * invokes the lpfc_els_rsp_reject() routine to send reject response.
4613 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
4614 * to accept the RPL.
4615 *
4616 * Return code
4617 * 0 - Successfully processed rpl iocb (currently always return 0)
4618 **/
3648static int 4619static int
3649lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 4620lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3650 struct lpfc_nodelist *ndlp) 4621 struct lpfc_nodelist *ndlp)
@@ -3685,6 +4656,30 @@ lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3685 return 0; 4656 return 0;
3686} 4657}
3687 4658
4659/**
4660 * lpfc_els_rcv_farp: Process an unsolicited farp request els command.
4661 * @vport: pointer to a virtual N_Port data structure.
4662 * @cmdiocb: pointer to lpfc command iocb data structure.
4663 * @ndlp: pointer to a node-list data structure.
4664 *
4665 * This routine processes Fibre Channel Address Resolution Protocol
4666 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
4667 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
4668 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
4669 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
4670 * remote PortName is compared against the FC PortName stored in the @vport
4671 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
4672 * compared against the FC NodeName stored in the @vport data structure.
4673 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
4674 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
4675 * invoked to send out FARP Response to the remote node. Before sending the
4676 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
4677 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
4678 * routine is invoked to log into the remote port first.
4679 *
4680 * Return code
4681 * 0 - Either the FARP Match Mode not supported or successfully processed
4682 **/
3688static int 4683static int
3689lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 4684lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3690 struct lpfc_nodelist *ndlp) 4685 struct lpfc_nodelist *ndlp)
@@ -3744,6 +4739,20 @@ lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3744 return 0; 4739 return 0;
3745} 4740}
3746 4741
4742/**
4743 * lpfc_els_rcv_farpr: Process an unsolicited farp response iocb.
4744 * @vport: pointer to a host virtual N_Port data structure.
4745 * @cmdiocb: pointer to lpfc command iocb data structure.
4746 * @ndlp: pointer to a node-list data structure.
4747 *
4748 * This routine processes Fibre Channel Address Resolution Protocol
4749 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
4750 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
4751 * the FARP response request.
4752 *
4753 * Return code
4754 * 0 - Successfully processed FARPR IOCB (currently always return 0)
4755 **/
3747static int 4756static int
3748lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 4757lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3749 struct lpfc_nodelist *ndlp) 4758 struct lpfc_nodelist *ndlp)
@@ -3768,6 +4777,25 @@ lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3768 return 0; 4777 return 0;
3769} 4778}
3770 4779
4780/**
4781 * lpfc_els_rcv_fan: Process an unsolicited fan iocb command.
4782 * @vport: pointer to a host virtual N_Port data structure.
4783 * @cmdiocb: pointer to lpfc command iocb data structure.
4784 * @fan_ndlp: pointer to a node-list data structure.
4785 *
4786 * This routine processes a Fabric Address Notification (FAN) IOCB
4787 * command received as an ELS unsolicited event. The FAN ELS command will
4788 * only be processed on a physical port (i.e., the @vport represents the
4789 * physical port). The fabric NodeName and PortName from the FAN IOCB are
4790 * compared against those in the phba data structure. If any of those is
4791 * different, the lpfc_initial_flogi() routine is invoked to initialize
4792 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
4793 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
4794 * is invoked to register login to the fabric.
4795 *
4796 * Return code
4797 * 0 - Successfully processed fan iocb (currently always return 0).
4798 **/
3771static int 4799static int
3772lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 4800lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3773 struct lpfc_nodelist *fan_ndlp) 4801 struct lpfc_nodelist *fan_ndlp)
@@ -3797,6 +4825,16 @@ lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3797 return 0; 4825 return 0;
3798} 4826}
3799 4827
4828/**
4829 * lpfc_els_timeout: Handler funciton to the els timer.
4830 * @ptr: holder for the timer function associated data.
4831 *
4832 * This routine is invoked by the ELS timer after timeout. It posts the ELS
4833 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
4834 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
4835 * up the worker thread. It is for the worker thread to invoke the routine
4836 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
4837 **/
3800void 4838void
3801lpfc_els_timeout(unsigned long ptr) 4839lpfc_els_timeout(unsigned long ptr)
3802{ 4840{
@@ -3816,6 +4854,15 @@ lpfc_els_timeout(unsigned long ptr)
3816 return; 4854 return;
3817} 4855}
3818 4856
4857/**
4858 * lpfc_els_timeout_handler: Process an els timeout event.
4859 * @vport: pointer to a virtual N_Port data structure.
4860 *
4861 * This routine is the actual handler function that processes an ELS timeout
4862 * event. It walks the ELS ring to get and abort all the IOCBs (except the
4863 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
4864 * invoking the lpfc_sli_issue_abort_iotag() routine.
4865 **/
3819void 4866void
3820lpfc_els_timeout_handler(struct lpfc_vport *vport) 4867lpfc_els_timeout_handler(struct lpfc_vport *vport)
3821{ 4868{
@@ -3886,6 +4933,26 @@ lpfc_els_timeout_handler(struct lpfc_vport *vport)
3886 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); 4933 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
3887} 4934}
3888 4935
4936/**
4937 * lpfc_els_flush_cmd: Clean up the outstanding els commands to a vport.
4938 * @vport: pointer to a host virtual N_Port data structure.
4939 *
4940 * This routine is used to clean up all the outstanding ELS commands on a
4941 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
4942 * routine. After that, it walks the ELS transmit queue to remove all the
4943 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
4944 * the IOCBs with a non-NULL completion callback function, the callback
4945 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
4946 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
4947 * callback function, the IOCB will simply be released. Finally, it walks
4948 * the ELS transmit completion queue to issue an abort IOCB to any transmit
4949 * completion queue IOCB that is associated with the @vport and is not
4950 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
4951 * part of the discovery state machine) out to HBA by invoking the
4952 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
4953 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
4954 * the IOCBs are aborted when this function returns.
4955 **/
3889void 4956void
3890lpfc_els_flush_cmd(struct lpfc_vport *vport) 4957lpfc_els_flush_cmd(struct lpfc_vport *vport)
3891{ 4958{
@@ -3948,6 +5015,23 @@ lpfc_els_flush_cmd(struct lpfc_vport *vport)
3948 return; 5015 return;
3949} 5016}
3950 5017
5018/**
5019 * lpfc_els_flush_all_cmd: Clean up all the outstanding els commands to a HBA.
5020 * @phba: pointer to lpfc hba data structure.
5021 *
5022 * This routine is used to clean up all the outstanding ELS commands on a
5023 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
5024 * routine. After that, it walks the ELS transmit queue to remove all the
5025 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
5026 * the IOCBs with the completion callback function associated, the callback
5027 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5028 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
5029 * callback function associated, the IOCB will simply be released. Finally,
5030 * it walks the ELS transmit completion queue to issue an abort IOCB to any
5031 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
5032 * management plane IOCBs that are not part of the discovery state machine)
5033 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
5034 **/
3951void 5035void
3952lpfc_els_flush_all_cmd(struct lpfc_hba *phba) 5036lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
3953{ 5037{
@@ -3992,6 +5076,20 @@ lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
3992 return; 5076 return;
3993} 5077}
3994 5078
5079/**
5080 * lpfc_els_unsol_buffer: Process an unsolicited event data buffer.
5081 * @phba: pointer to lpfc hba data structure.
5082 * @pring: pointer to a SLI ring.
5083 * @vport: pointer to a host virtual N_Port data structure.
5084 * @elsiocb: pointer to lpfc els command iocb data structure.
5085 *
5086 * This routine is used for processing the IOCB associated with a unsolicited
5087 * event. It first determines whether there is an existing ndlp that matches
5088 * the DID from the unsolicited IOCB. If not, it will create a new one with
5089 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
5090 * IOCB is then used to invoke the proper routine and to set up proper state
5091 * of the discovery state machine.
5092 **/
3995static void 5093static void
3996lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 5094lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3997 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) 5095 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
@@ -4282,6 +5380,19 @@ dropit:
4282 phba->fc_stat.elsRcvDrop++; 5380 phba->fc_stat.elsRcvDrop++;
4283} 5381}
4284 5382
5383/**
5384 * lpfc_find_vport_by_vpid: Find a vport on a HBA through vport identifier.
5385 * @phba: pointer to lpfc hba data structure.
5386 * @vpi: host virtual N_Port identifier.
5387 *
5388 * This routine finds a vport on a HBA (referred by @phba) through a
5389 * @vpi. The function walks the HBA's vport list and returns the address
5390 * of the vport with the matching @vpi.
5391 *
5392 * Return code
5393 * NULL - No vport with the matching @vpi found
5394 * Otherwise - Address to the vport with the matching @vpi.
5395 **/
4285static struct lpfc_vport * 5396static struct lpfc_vport *
4286lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi) 5397lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
4287{ 5398{
@@ -4299,6 +5410,18 @@ lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
4299 return NULL; 5410 return NULL;
4300} 5411}
4301 5412
5413/**
5414 * lpfc_els_unsol_event: Process an unsolicited event from an els sli ring.
5415 * @phba: pointer to lpfc hba data structure.
5416 * @pring: pointer to a SLI ring.
5417 * @elsiocb: pointer to lpfc els iocb data structure.
5418 *
5419 * This routine is used to process an unsolicited event received from a SLI
5420 * (Service Level Interface) ring. The actual processing of the data buffer
5421 * associated with the unsolicited event is done by invoking the routine
5422 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
5423 * SLI ring on which the unsolicited event was received.
5424 **/
4302void 5425void
4303lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 5426lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
4304 struct lpfc_iocbq *elsiocb) 5427 struct lpfc_iocbq *elsiocb)
@@ -4376,6 +5499,19 @@ lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
4376 } 5499 }
4377} 5500}
4378 5501
5502/**
5503 * lpfc_do_scr_ns_plogi: Issue a plogi to the name server for scr.
5504 * @phba: pointer to lpfc hba data structure.
5505 * @vport: pointer to a virtual N_Port data structure.
5506 *
5507 * This routine issues a Port Login (PLOGI) to the Name Server with
5508 * State Change Request (SCR) for a @vport. This routine will create an
5509 * ndlp for the Name Server associated to the @vport if such node does
5510 * not already exist. The PLOGI to Name Server is issued by invoking the
5511 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
5512 * (FDMI) is configured to the @vport, a FDMI node will be created and
5513 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
5514 **/
4379void 5515void
4380lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) 5516lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
4381{ 5517{
@@ -4434,6 +5570,18 @@ lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
4434 return; 5570 return;
4435} 5571}
4436 5572
5573/**
5574 * lpfc_cmpl_reg_new_vport: Completion callback function to register new vport.
5575 * @phba: pointer to lpfc hba data structure.
5576 * @pmb: pointer to the driver internal queue element for mailbox command.
5577 *
5578 * This routine is the completion callback function to register new vport
5579 * mailbox command. If the new vport mailbox command completes successfully,
5580 * the fabric registration login shall be performed on physical port (the
5581 * new vport created is actually a physical port, with VPI 0) or the port
5582 * login to Name Server for State Change Request (SCR) will be performed
5583 * on virtual port (real virtual port, with VPI greater than 0).
5584 **/
4437static void 5585static void
4438lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) 5586lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4439{ 5587{
@@ -4491,6 +5639,15 @@ lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4491 return; 5639 return;
4492} 5640}
4493 5641
5642/**
5643 * lpfc_register_new_vport: Register a new vport with a HBA.
5644 * @phba: pointer to lpfc hba data structure.
5645 * @vport: pointer to a host virtual N_Port data structure.
5646 * @ndlp: pointer to a node-list data structure.
5647 *
5648 * This routine registers the @vport as a new virtual port with a HBA.
5649 * It is done through a registering vpi mailbox command.
5650 **/
4494static void 5651static void
4495lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, 5652lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
4496 struct lpfc_nodelist *ndlp) 5653 struct lpfc_nodelist *ndlp)
@@ -4531,6 +5688,26 @@ mbox_err_exit:
4531 return; 5688 return;
4532} 5689}
4533 5690
5691/**
5692 * lpfc_cmpl_els_fdisc: Completion function for fdisc iocb command.
5693 * @phba: pointer to lpfc hba data structure.
5694 * @cmdiocb: pointer to lpfc command iocb data structure.
5695 * @rspiocb: pointer to lpfc response iocb data structure.
5696 *
5697 * This routine is the completion callback function to a Fabric Discover
5698 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
5699 * single threaded, each FDISC completion callback function will reset
5700 * the discovery timer for all vports such that the timers will not get
5701 * unnecessary timeout. The function checks the FDISC IOCB status. If error
5702 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
5703 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
5704 * assigned to the vport has been changed with the completion of the FDISC
5705 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
5706 * are unregistered from the HBA, and then the lpfc_register_new_vport()
5707 * routine is invoked to register new vport with the HBA. Otherwise, the
5708 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
5709 * Server for State Change Request (SCR).
5710 **/
4534static void 5711static void
4535lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 5712lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4536 struct lpfc_iocbq *rspiocb) 5713 struct lpfc_iocbq *rspiocb)
@@ -4617,6 +5794,26 @@ out:
4617 lpfc_els_free_iocb(phba, cmdiocb); 5794 lpfc_els_free_iocb(phba, cmdiocb);
4618} 5795}
4619 5796
5797/**
5798 * lpfc_issue_els_fdisc: Issue a fdisc iocb command.
5799 * @vport: pointer to a virtual N_Port data structure.
5800 * @ndlp: pointer to a node-list data structure.
5801 * @retry: number of retries to the command IOCB.
5802 *
5803 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
5804 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
5805 * routine to issue the IOCB, which makes sure only one outstanding fabric
5806 * IOCB will be sent off HBA at any given time.
5807 *
5808 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5809 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5810 * will be stored into the context1 field of the IOCB for the completion
5811 * callback function to the FDISC ELS command.
5812 *
5813 * Return code
5814 * 0 - Successfully issued fdisc iocb command
5815 * 1 - Failed to issue fdisc iocb command
5816 **/
4620static int 5817static int
4621lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, 5818lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4622 uint8_t retry) 5819 uint8_t retry)
@@ -4691,6 +5888,20 @@ lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4691 return 0; 5888 return 0;
4692} 5889}
4693 5890
5891/**
5892 * lpfc_cmpl_els_npiv_logo: Completion function with vport logo.
5893 * @phba: pointer to lpfc hba data structure.
5894 * @cmdiocb: pointer to lpfc command iocb data structure.
5895 * @rspiocb: pointer to lpfc response iocb data structure.
5896 *
5897 * This routine is the completion callback function to the issuing of a LOGO
5898 * ELS command off a vport. It frees the command IOCB and then decrement the
5899 * reference count held on ndlp for this completion function, indicating that
5900 * the reference to the ndlp is no long needed. Note that the
5901 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
5902 * callback function and an additional explicit ndlp reference decrementation
5903 * will trigger the actual release of the ndlp.
5904 **/
4694static void 5905static void
4695lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 5906lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4696 struct lpfc_iocbq *rspiocb) 5907 struct lpfc_iocbq *rspiocb)
@@ -4712,6 +5923,22 @@ lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4712 lpfc_nlp_put(ndlp); 5923 lpfc_nlp_put(ndlp);
4713} 5924}
4714 5925
5926/**
5927 * lpfc_issue_els_npiv_logo: Issue a logo off a vport.
5928 * @vport: pointer to a virtual N_Port data structure.
5929 * @ndlp: pointer to a node-list data structure.
5930 *
5931 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
5932 *
5933 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5934 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5935 * will be stored into the context1 field of the IOCB for the completion
5936 * callback function to the LOGO ELS command.
5937 *
5938 * Return codes
5939 * 0 - Successfully issued logo off the @vport
5940 * 1 - Failed to issue logo off the @vport
5941 **/
4715int 5942int
4716lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) 5943lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4717{ 5944{
@@ -4757,6 +5984,17 @@ lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4757 return 0; 5984 return 0;
4758} 5985}
4759 5986
5987/**
5988 * lpfc_fabric_block_timeout: Handler function to the fabric block timer.
5989 * @ptr: holder for the timer function associated data.
5990 *
5991 * This routine is invoked by the fabric iocb block timer after
5992 * timeout. It posts the fabric iocb block timeout event by setting the
5993 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
5994 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
5995 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
5996 * posted event WORKER_FABRIC_BLOCK_TMO.
5997 **/
4760void 5998void
4761lpfc_fabric_block_timeout(unsigned long ptr) 5999lpfc_fabric_block_timeout(unsigned long ptr)
4762{ 6000{
@@ -4775,6 +6013,16 @@ lpfc_fabric_block_timeout(unsigned long ptr)
4775 return; 6013 return;
4776} 6014}
4777 6015
6016/**
6017 * lpfc_resume_fabric_iocbs: Issue a fabric iocb from driver internal list.
6018 * @phba: pointer to lpfc hba data structure.
6019 *
6020 * This routine issues one fabric iocb from the driver internal list to
6021 * the HBA. It first checks whether it's ready to issue one fabric iocb to
6022 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
6023 * remove one pending fabric iocb from the driver internal list and invokes
6024 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
6025 **/
4778static void 6026static void
4779lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) 6027lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
4780{ 6028{
@@ -4824,6 +6072,15 @@ repeat:
4824 return; 6072 return;
4825} 6073}
4826 6074
6075/**
6076 * lpfc_unblock_fabric_iocbs: Unblock issuing fabric iocb command.
6077 * @phba: pointer to lpfc hba data structure.
6078 *
6079 * This routine unblocks the issuing fabric iocb command. The function
6080 * will clear the fabric iocb block bit and then invoke the routine
6081 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
6082 * from the driver internal fabric iocb list.
6083 **/
4827void 6084void
4828lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) 6085lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
4829{ 6086{
@@ -4833,6 +6090,15 @@ lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
4833 return; 6090 return;
4834} 6091}
4835 6092
6093/**
6094 * lpfc_block_fabric_iocbs: Block issuing fabric iocb command.
6095 * @phba: pointer to lpfc hba data structure.
6096 *
6097 * This routine blocks the issuing fabric iocb for a specified amount of
6098 * time (currently 100 ms). This is done by set the fabric iocb block bit
6099 * and set up a timeout timer for 100ms. When the block bit is set, no more
6100 * fabric iocb will be issued out of the HBA.
6101 **/
4836static void 6102static void
4837lpfc_block_fabric_iocbs(struct lpfc_hba *phba) 6103lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
4838{ 6104{
@@ -4846,6 +6112,19 @@ lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
4846 return; 6112 return;
4847} 6113}
4848 6114
6115/**
6116 * lpfc_cmpl_fabric_iocb: Completion callback function for fabric iocb.
6117 * @phba: pointer to lpfc hba data structure.
6118 * @cmdiocb: pointer to lpfc command iocb data structure.
6119 * @rspiocb: pointer to lpfc response iocb data structure.
6120 *
6121 * This routine is the callback function that is put to the fabric iocb's
6122 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
6123 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
6124 * function first restores and invokes the original iocb's callback function
6125 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
6126 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
6127 **/
4849static void 6128static void
4850lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 6129lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4851 struct lpfc_iocbq *rspiocb) 6130 struct lpfc_iocbq *rspiocb)
@@ -4892,6 +6171,30 @@ lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4892 } 6171 }
4893} 6172}
4894 6173
6174/**
6175 * lpfc_issue_fabric_iocb: Issue a fabric iocb command.
6176 * @phba: pointer to lpfc hba data structure.
6177 * @iocb: pointer to lpfc command iocb data structure.
6178 *
6179 * This routine is used as the top-level API for issuing a fabric iocb command
6180 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
6181 * function makes sure that only one fabric bound iocb will be outstanding at
6182 * any given time. As such, this function will first check to see whether there
6183 * is already an outstanding fabric iocb on the wire. If so, it will put the
6184 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
6185 * issued later. Otherwise, it will issue the iocb on the wire and update the
6186 * fabric iocb count it indicate that there is one fabric iocb on the wire.
6187 *
6188 * Note, this implementation has a potential sending out fabric IOCBs out of
6189 * order. The problem is caused by the construction of the "ready" boolen does
6190 * not include the condition that the internal fabric IOCB list is empty. As
6191 * such, it is possible a fabric IOCB issued by this routine might be "jump"
6192 * ahead of the fabric IOCBs in the internal list.
6193 *
6194 * Return code
6195 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
6196 * IOCB_ERROR - failed to issue fabric iocb
6197 **/
4895static int 6198static int
4896lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) 6199lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
4897{ 6200{
@@ -4937,7 +6240,17 @@ lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
4937 return ret; 6240 return ret;
4938} 6241}
4939 6242
4940 6243/**
6244 * lpfc_fabric_abort_vport: Abort a vport's iocbs from driver fabric iocb list.
6245 * @vport: pointer to a virtual N_Port data structure.
6246 *
6247 * This routine aborts all the IOCBs associated with a @vport from the
6248 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6249 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6250 * list, removes each IOCB associated with the @vport off the list, set the
6251 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6252 * associated with the IOCB.
6253 **/
4941static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) 6254static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
4942{ 6255{
4943 LIST_HEAD(completions); 6256 LIST_HEAD(completions);
@@ -4967,6 +6280,17 @@ static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
4967 } 6280 }
4968} 6281}
4969 6282
6283/**
6284 * lpfc_fabric_abort_nport: Abort a ndlp's iocbs from driver fabric iocb list.
6285 * @ndlp: pointer to a node-list data structure.
6286 *
6287 * This routine aborts all the IOCBs associated with an @ndlp from the
6288 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6289 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6290 * list, removes each IOCB associated with the @ndlp off the list, set the
6291 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6292 * associated with the IOCB.
6293 **/
4970void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) 6294void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
4971{ 6295{
4972 LIST_HEAD(completions); 6296 LIST_HEAD(completions);
@@ -4996,6 +6320,17 @@ void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
4996 } 6320 }
4997} 6321}
4998 6322
6323/**
6324 * lpfc_fabric_abort_hba: Abort all iocbs on driver fabric iocb list.
6325 * @phba: pointer to lpfc hba data structure.
6326 *
6327 * This routine aborts all the IOCBs currently on the driver internal
6328 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
6329 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
6330 * list, removes IOCBs off the list, set the status feild to
6331 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
6332 * the IOCB.
6333 **/
4999void lpfc_fabric_abort_hba(struct lpfc_hba *phba) 6334void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
5000{ 6335{
5001 LIST_HEAD(completions); 6336 LIST_HEAD(completions);
diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index d51a2a4b43eb..b9d553c2ac4d 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -52,17 +52,20 @@ static struct scsi_transport_template *lpfc_transport_template = NULL;
52static struct scsi_transport_template *lpfc_vport_transport_template = NULL; 52static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
53static DEFINE_IDR(lpfc_hba_index); 53static DEFINE_IDR(lpfc_hba_index);
54 54
55/************************************************************************/ 55/**
56/* */ 56 * lpfc_config_port_prep: Perform lpfc initialization prior to config port.
57/* lpfc_config_port_prep */ 57 * @phba: pointer to lpfc hba data structure.
58/* This routine will do LPFC initialization prior to the */ 58 *
59/* CONFIG_PORT mailbox command. This will be initialized */ 59 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
60/* as a SLI layer callback routine. */ 60 * mailbox command. It retrieves the revision information from the HBA and
61/* This routine returns 0 on success or -ERESTART if it wants */ 61 * collects the Vital Product Data (VPD) about the HBA for preparing the
62/* the SLI layer to reset the HBA and try again. Any */ 62 * configuration of the HBA.
63/* other return value indicates an error. */ 63 *
64/* */ 64 * Return codes:
65/************************************************************************/ 65 * 0 - success.
66 * -ERESTART - requests the SLI layer to reset the HBA and try again.
67 * Any other value - indicates an error.
68 **/
66int 69int
67lpfc_config_port_prep(struct lpfc_hba *phba) 70lpfc_config_port_prep(struct lpfc_hba *phba)
68{ 71{
@@ -214,7 +217,16 @@ out_free_mbox:
214 return 0; 217 return 0;
215} 218}
216 219
217/* Completion handler for config async event mailbox command. */ 220/**
221 * lpfc_config_async_cmpl: Completion handler for config async event mbox cmd.
222 * @phba: pointer to lpfc hba data structure.
223 * @pmboxq: pointer to the driver internal queue element for mailbox command.
224 *
225 * This is the completion handler for driver's configuring asynchronous event
226 * mailbox command to the device. If the mailbox command returns successfully,
227 * it will set internal async event support flag to 1; otherwise, it will
228 * set internal async event support flag to 0.
229 **/
218static void 230static void
219lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) 231lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
220{ 232{
@@ -226,16 +238,19 @@ lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
226 return; 238 return;
227} 239}
228 240
229/************************************************************************/ 241/**
230/* */ 242 * lpfc_config_port_post: Perform lpfc initialization after config port.
231/* lpfc_config_port_post */ 243 * @phba: pointer to lpfc hba data structure.
232/* This routine will do LPFC initialization after the */ 244 *
233/* CONFIG_PORT mailbox command. This will be initialized */ 245 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
234/* as a SLI layer callback routine. */ 246 * command call. It performs all internal resource and state setups on the
235/* This routine returns 0 on success. Any other return value */ 247 * port: post IOCB buffers, enable appropriate host interrupt attentions,
236/* indicates an error. */ 248 * ELS ring timers, etc.
237/* */ 249 *
238/************************************************************************/ 250 * Return codes
251 * 0 - success.
252 * Any other value - error.
253 **/
239int 254int
240lpfc_config_port_post(struct lpfc_hba *phba) 255lpfc_config_port_post(struct lpfc_hba *phba)
241{ 256{
@@ -450,16 +465,17 @@ lpfc_config_port_post(struct lpfc_hba *phba)
450 return (0); 465 return (0);
451} 466}
452 467
453/************************************************************************/ 468/**
454/* */ 469 * lpfc_hba_down_prep: Perform lpfc uninitialization prior to HBA reset.
455/* lpfc_hba_down_prep */ 470 * @phba: pointer to lpfc HBA data structure.
456/* This routine will do LPFC uninitialization before the */ 471 *
457/* HBA is reset when bringing down the SLI Layer. This will be */ 472 * This routine will do LPFC uninitialization before the HBA is reset when
458/* initialized as a SLI layer callback routine. */ 473 * bringing down the SLI Layer.
459/* This routine returns 0 on success. Any other return value */ 474 *
460/* indicates an error. */ 475 * Return codes
461/* */ 476 * 0 - success.
462/************************************************************************/ 477 * Any other value - error.
478 **/
463int 479int
464lpfc_hba_down_prep(struct lpfc_hba *phba) 480lpfc_hba_down_prep(struct lpfc_hba *phba)
465{ 481{
@@ -481,15 +497,17 @@ lpfc_hba_down_prep(struct lpfc_hba *phba)
481 return 0; 497 return 0;
482} 498}
483 499
484/************************************************************************/ 500/**
485/* */ 501 * lpfc_hba_down_post: Perform lpfc uninitialization after HBA reset.
486/* lpfc_hba_down_post */ 502 * @phba: pointer to lpfc HBA data structure.
487/* This routine will do uninitialization after the HBA is reset */ 503 *
488/* when bringing down the SLI Layer. */ 504 * This routine will do uninitialization after the HBA is reset when bring
489/* This routine returns 0 on success. Any other return value */ 505 * down the SLI Layer.
490/* indicates an error. */ 506 *
491/* */ 507 * Return codes
492/************************************************************************/ 508 * 0 - sucess.
509 * Any other value - error.
510 **/
493int 511int
494lpfc_hba_down_post(struct lpfc_hba *phba) 512lpfc_hba_down_post(struct lpfc_hba *phba)
495{ 513{
@@ -548,7 +566,18 @@ lpfc_hba_down_post(struct lpfc_hba *phba)
548 return 0; 566 return 0;
549} 567}
550 568
551/* HBA heart beat timeout handler */ 569/**
570 * lpfc_hb_timeout: The HBA-timer timeout handler.
571 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
572 *
573 * This is the HBA-timer timeout handler registered to the lpfc driver. When
574 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
575 * work-port-events bitmap and the worker thread is notified. This timeout
576 * event will be used by the worker thread to invoke the actual timeout
577 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
578 * be performed in the timeout handler and the HBA timeout event bit shall
579 * be cleared by the worker thread after it has taken the event bitmap out.
580 **/
552static void 581static void
553lpfc_hb_timeout(unsigned long ptr) 582lpfc_hb_timeout(unsigned long ptr)
554{ 583{
@@ -568,6 +597,22 @@ lpfc_hb_timeout(unsigned long ptr)
568 return; 597 return;
569} 598}
570 599
600/**
601 * lpfc_hb_mbox_cmpl: The lpfc heart-beat mailbox command callback function.
602 * @phba: pointer to lpfc hba data structure.
603 * @pmboxq: pointer to the driver internal queue element for mailbox command.
604 *
605 * This is the callback function to the lpfc heart-beat mailbox command.
606 * If configured, the lpfc driver issues the heart-beat mailbox command to
607 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
608 * heart-beat mailbox command is issued, the driver shall set up heart-beat
609 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
610 * heart-beat outstanding state. Once the mailbox command comes back and
611 * no error conditions detected, the heart-beat mailbox command timer is
612 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
613 * state is cleared for the next heart-beat. If the timer expired with the
614 * heart-beat outstanding state set, the driver will put the HBA offline.
615 **/
571static void 616static void
572lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) 617lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
573{ 618{
@@ -586,6 +631,22 @@ lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
586 return; 631 return;
587} 632}
588 633
634/**
635 * lpfc_hb_timeout_handler: The HBA-timer timeout handler.
636 * @phba: pointer to lpfc hba data structure.
637 *
638 * This is the actual HBA-timer timeout handler to be invoked by the worker
639 * thread whenever the HBA timer fired and HBA-timeout event posted. This
640 * handler performs any periodic operations needed for the device. If such
641 * periodic event has already been attended to either in the interrupt handler
642 * or by processing slow-ring or fast-ring events within the HBA-timer
643 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
644 * the timer for the next timeout period. If lpfc heart-beat mailbox command
645 * is configured and there is no heart-beat mailbox command outstanding, a
646 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
647 * has been a heart-beat mailbox command outstanding, the HBA shall be put
648 * to offline.
649 **/
589void 650void
590lpfc_hb_timeout_handler(struct lpfc_hba *phba) 651lpfc_hb_timeout_handler(struct lpfc_hba *phba)
591{ 652{
@@ -684,6 +745,13 @@ lpfc_hb_timeout_handler(struct lpfc_hba *phba)
684 } 745 }
685} 746}
686 747
748/**
749 * lpfc_offline_eratt: Bring lpfc offline on hardware error attention.
750 * @phba: pointer to lpfc hba data structure.
751 *
752 * This routine is called to bring the HBA offline when HBA hardware error
753 * other than Port Error 6 has been detected.
754 **/
687static void 755static void
688lpfc_offline_eratt(struct lpfc_hba *phba) 756lpfc_offline_eratt(struct lpfc_hba *phba)
689{ 757{
@@ -704,14 +772,16 @@ lpfc_offline_eratt(struct lpfc_hba *phba)
704 return; 772 return;
705} 773}
706 774
707/************************************************************************/ 775/**
708/* */ 776 * lpfc_handle_eratt: The HBA hardware error handler.
709/* lpfc_handle_eratt */ 777 * @phba: pointer to lpfc hba data structure.
710/* This routine will handle processing a Host Attention */ 778 *
711/* Error Status event. This will be initialized */ 779 * This routine is invoked to handle the following HBA hardware error
712/* as a SLI layer callback routine. */ 780 * conditions:
713/* */ 781 * 1 - HBA error attention interrupt
714/************************************************************************/ 782 * 2 - DMA ring index out of range
783 * 3 - Mailbox command came back as unknown
784 **/
715void 785void
716lpfc_handle_eratt(struct lpfc_hba *phba) 786lpfc_handle_eratt(struct lpfc_hba *phba)
717{ 787{
@@ -810,14 +880,13 @@ lpfc_handle_eratt(struct lpfc_hba *phba)
810 } 880 }
811} 881}
812 882
813/************************************************************************/ 883/**
814/* */ 884 * lpfc_handle_latt: The HBA link event handler.
815/* lpfc_handle_latt */ 885 * @phba: pointer to lpfc hba data structure.
816/* This routine will handle processing a Host Attention */ 886 *
817/* Link Status event. This will be initialized */ 887 * This routine is invoked from the worker thread to handle a HBA host
818/* as a SLI layer callback routine. */ 888 * attention link event.
819/* */ 889 **/
820/************************************************************************/
821void 890void
822lpfc_handle_latt(struct lpfc_hba *phba) 891lpfc_handle_latt(struct lpfc_hba *phba)
823{ 892{
@@ -898,12 +967,20 @@ lpfc_handle_latt_err_exit:
898 return; 967 return;
899} 968}
900 969
901/************************************************************************/ 970/**
902/* */ 971 * lpfc_parse_vpd: Parse VPD (Vital Product Data).
903/* lpfc_parse_vpd */ 972 * @phba: pointer to lpfc hba data structure.
904/* This routine will parse the VPD data */ 973 * @vpd: pointer to the vital product data.
905/* */ 974 * @len: length of the vital product data in bytes.
906/************************************************************************/ 975 *
976 * This routine parses the Vital Product Data (VPD). The VPD is treated as
977 * an array of characters. In this routine, the ModelName, ProgramType, and
978 * ModelDesc, etc. fields of the phba data structure will be populated.
979 *
980 * Return codes
981 * 0 - pointer to the VPD passed in is NULL
982 * 1 - success
983 **/
907static int 984static int
908lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len) 985lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
909{ 986{
@@ -1040,6 +1117,18 @@ lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
1040 return(1); 1117 return(1);
1041} 1118}
1042 1119
1120/**
1121 * lpfc_get_hba_model_desc: Retrieve HBA device model name and description.
1122 * @phba: pointer to lpfc hba data structure.
1123 * @mdp: pointer to the data structure to hold the derived model name.
1124 * @descp: pointer to the data structure to hold the derived description.
1125 *
1126 * This routine retrieves HBA's description based on its registered PCI device
1127 * ID. The @descp passed into this function points to an array of 256 chars. It
1128 * shall be returned with the model name, maximum speed, and the host bus type.
1129 * The @mdp passed into this function points to an array of 80 chars. When the
1130 * function returns, the @mdp will be filled with the model name.
1131 **/
1043static void 1132static void
1044lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp) 1133lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
1045{ 1134{
@@ -1190,14 +1279,18 @@ lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
1190 m.name, m.max_speed, m.bus); 1279 m.name, m.max_speed, m.bus);
1191} 1280}
1192 1281
1193/**************************************************/ 1282/**
1194/* lpfc_post_buffer */ 1283 * lpfc_post_buffer: Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring.
1195/* */ 1284 * @phba: pointer to lpfc hba data structure.
1196/* This routine will post count buffers to the */ 1285 * @pring: pointer to a IOCB ring.
1197/* ring with the QUE_RING_BUF_CN command. This */ 1286 * @cnt: the number of IOCBs to be posted to the IOCB ring.
1198/* allows 3 buffers / command to be posted. */ 1287 *
1199/* Returns the number of buffers NOT posted. */ 1288 * This routine posts a given number of IOCBs with the associated DMA buffer
1200/**************************************************/ 1289 * descriptors specified by the cnt argument to the given IOCB ring.
1290 *
1291 * Return codes
1292 * The number of IOCBs NOT able to be posted to the IOCB ring.
1293 **/
1201int 1294int
1202lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt) 1295lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
1203{ 1296{
@@ -1287,12 +1380,17 @@ lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
1287 return 0; 1380 return 0;
1288} 1381}
1289 1382
1290/************************************************************************/ 1383/**
1291/* */ 1384 * lpfc_post_rcv_buf: Post the initial receive IOCB buffers to ELS ring.
1292/* lpfc_post_rcv_buf */ 1385 * @phba: pointer to lpfc hba data structure.
1293/* This routine post initial rcv buffers to the configured rings */ 1386 *
1294/* */ 1387 * This routine posts initial receive IOCB buffers to the ELS ring. The
1295/************************************************************************/ 1388 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
1389 * set to 64 IOCBs.
1390 *
1391 * Return codes
1392 * 0 - success (currently always success)
1393 **/
1296static int 1394static int
1297lpfc_post_rcv_buf(struct lpfc_hba *phba) 1395lpfc_post_rcv_buf(struct lpfc_hba *phba)
1298{ 1396{
@@ -1307,11 +1405,13 @@ lpfc_post_rcv_buf(struct lpfc_hba *phba)
1307 1405
1308#define S(N,V) (((V)<<(N))|((V)>>(32-(N)))) 1406#define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
1309 1407
1310/************************************************************************/ 1408/**
1311/* */ 1409 * lpfc_sha_init: Set up initial array of hash table entries.
1312/* lpfc_sha_init */ 1410 * @HashResultPointer: pointer to an array as hash table.
1313/* */ 1411 *
1314/************************************************************************/ 1412 * This routine sets up the initial values to the array of hash table entries
1413 * for the LC HBAs.
1414 **/
1315static void 1415static void
1316lpfc_sha_init(uint32_t * HashResultPointer) 1416lpfc_sha_init(uint32_t * HashResultPointer)
1317{ 1417{
@@ -1322,11 +1422,16 @@ lpfc_sha_init(uint32_t * HashResultPointer)
1322 HashResultPointer[4] = 0xC3D2E1F0; 1422 HashResultPointer[4] = 0xC3D2E1F0;
1323} 1423}
1324 1424
1325/************************************************************************/ 1425/**
1326/* */ 1426 * lpfc_sha_iterate: Iterate initial hash table with the working hash table.
1327/* lpfc_sha_iterate */ 1427 * @HashResultPointer: pointer to an initial/result hash table.
1328/* */ 1428 * @HashWorkingPointer: pointer to an working hash table.
1329/************************************************************************/ 1429 *
1430 * This routine iterates an initial hash table pointed by @HashResultPointer
1431 * with the values from the working hash table pointeed by @HashWorkingPointer.
1432 * The results are putting back to the initial hash table, returned through
1433 * the @HashResultPointer as the result hash table.
1434 **/
1330static void 1435static void
1331lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer) 1436lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
1332{ 1437{
@@ -1374,22 +1479,29 @@ lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
1374 1479
1375} 1480}
1376 1481
1377/************************************************************************/ 1482/**
1378/* */ 1483 * lpfc_challenge_key: Create challenge key based on WWPN of the HBA.
1379/* lpfc_challenge_key */ 1484 * @RandomChallenge: pointer to the entry of host challenge random number array.
1380/* */ 1485 * @HashWorking: pointer to the entry of the working hash array.
1381/************************************************************************/ 1486 *
1487 * This routine calculates the working hash array referred by @HashWorking
1488 * from the challenge random numbers associated with the host, referred by
1489 * @RandomChallenge. The result is put into the entry of the working hash
1490 * array and returned by reference through @HashWorking.
1491 **/
1382static void 1492static void
1383lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking) 1493lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
1384{ 1494{
1385 *HashWorking = (*RandomChallenge ^ *HashWorking); 1495 *HashWorking = (*RandomChallenge ^ *HashWorking);
1386} 1496}
1387 1497
1388/************************************************************************/ 1498/**
1389/* */ 1499 * lpfc_hba_init: Perform special handling for LC HBA initialization.
1390/* lpfc_hba_init */ 1500 * @phba: pointer to lpfc hba data structure.
1391/* */ 1501 * @hbainit: pointer to an array of unsigned 32-bit integers.
1392/************************************************************************/ 1502 *
1503 * This routine performs the special handling for LC HBA initialization.
1504 **/
1393void 1505void
1394lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit) 1506lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
1395{ 1507{
@@ -1412,6 +1524,15 @@ lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
1412 kfree(HashWorking); 1524 kfree(HashWorking);
1413} 1525}
1414 1526
1527/**
1528 * lpfc_cleanup: Performs vport cleanups before deleting a vport.
1529 * @vport: pointer to a virtual N_Port data structure.
1530 *
1531 * This routine performs the necessary cleanups before deleting the @vport.
1532 * It invokes the discovery state machine to perform necessary state
1533 * transitions and to release the ndlps associated with the @vport. Note,
1534 * the physical port is treated as @vport 0.
1535 **/
1415void 1536void
1416lpfc_cleanup(struct lpfc_vport *vport) 1537lpfc_cleanup(struct lpfc_vport *vport)
1417{ 1538{
@@ -1498,6 +1619,14 @@ lpfc_cleanup(struct lpfc_vport *vport)
1498 return; 1619 return;
1499} 1620}
1500 1621
1622/**
1623 * lpfc_stop_vport_timers: Stop all the timers associated with a vport.
1624 * @vport: pointer to a virtual N_Port data structure.
1625 *
1626 * This routine stops all the timers associated with a @vport. This function
1627 * is invoked before disabling or deleting a @vport. Note that the physical
1628 * port is treated as @vport 0.
1629 **/
1501void 1630void
1502lpfc_stop_vport_timers(struct lpfc_vport *vport) 1631lpfc_stop_vport_timers(struct lpfc_vport *vport)
1503{ 1632{
@@ -1507,6 +1636,13 @@ lpfc_stop_vport_timers(struct lpfc_vport *vport)
1507 return; 1636 return;
1508} 1637}
1509 1638
1639/**
1640 * lpfc_stop_phba_timers: Stop all the timers associated with an HBA.
1641 * @phba: pointer to lpfc hba data structure.
1642 *
1643 * This routine stops all the timers associated with a HBA. This function is
1644 * invoked before either putting a HBA offline or unloading the driver.
1645 **/
1510static void 1646static void
1511lpfc_stop_phba_timers(struct lpfc_hba *phba) 1647lpfc_stop_phba_timers(struct lpfc_hba *phba)
1512{ 1648{
@@ -1519,6 +1655,16 @@ lpfc_stop_phba_timers(struct lpfc_hba *phba)
1519 return; 1655 return;
1520} 1656}
1521 1657
1658/**
1659 * lpfc_block_mgmt_io: Mark a HBA's management interface as blocked.
1660 * @phba: pointer to lpfc hba data structure.
1661 *
1662 * This routine marks a HBA's management interface as blocked. Once the HBA's
1663 * management interface is marked as blocked, all the user space access to
1664 * the HBA, whether they are from sysfs interface or libdfc interface will
1665 * all be blocked. The HBA is set to block the management interface when the
1666 * driver prepares the HBA interface for online or offline.
1667 **/
1522static void 1668static void
1523lpfc_block_mgmt_io(struct lpfc_hba * phba) 1669lpfc_block_mgmt_io(struct lpfc_hba * phba)
1524{ 1670{
@@ -1529,6 +1675,18 @@ lpfc_block_mgmt_io(struct lpfc_hba * phba)
1529 spin_unlock_irqrestore(&phba->hbalock, iflag); 1675 spin_unlock_irqrestore(&phba->hbalock, iflag);
1530} 1676}
1531 1677
1678/**
1679 * lpfc_online: Initialize and bring a HBA online.
1680 * @phba: pointer to lpfc hba data structure.
1681 *
1682 * This routine initializes the HBA and brings a HBA online. During this
1683 * process, the management interface is blocked to prevent user space access
1684 * to the HBA interfering with the driver initialization.
1685 *
1686 * Return codes
1687 * 0 - successful
1688 * 1 - failed
1689 **/
1532int 1690int
1533lpfc_online(struct lpfc_hba *phba) 1691lpfc_online(struct lpfc_hba *phba)
1534{ 1692{
@@ -1574,6 +1732,17 @@ lpfc_online(struct lpfc_hba *phba)
1574 return 0; 1732 return 0;
1575} 1733}
1576 1734
1735/**
1736 * lpfc_unblock_mgmt_io: Mark a HBA's management interface to be not blocked.
1737 * @phba: pointer to lpfc hba data structure.
1738 *
1739 * This routine marks a HBA's management interface as not blocked. Once the
1740 * HBA's management interface is marked as not blocked, all the user space
1741 * access to the HBA, whether they are from sysfs interface or libdfc
1742 * interface will be allowed. The HBA is set to block the management interface
1743 * when the driver prepares the HBA interface for online or offline and then
1744 * set to unblock the management interface afterwards.
1745 **/
1577void 1746void
1578lpfc_unblock_mgmt_io(struct lpfc_hba * phba) 1747lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
1579{ 1748{
@@ -1584,6 +1753,14 @@ lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
1584 spin_unlock_irqrestore(&phba->hbalock, iflag); 1753 spin_unlock_irqrestore(&phba->hbalock, iflag);
1585} 1754}
1586 1755
1756/**
1757 * lpfc_offline_prep: Prepare a HBA to be brought offline.
1758 * @phba: pointer to lpfc hba data structure.
1759 *
1760 * This routine is invoked to prepare a HBA to be brought offline. It performs
1761 * unregistration login to all the nodes on all vports and flushes the mailbox
1762 * queue to make it ready to be brought offline.
1763 **/
1587void 1764void
1588lpfc_offline_prep(struct lpfc_hba * phba) 1765lpfc_offline_prep(struct lpfc_hba * phba)
1589{ 1766{
@@ -1633,6 +1810,14 @@ lpfc_offline_prep(struct lpfc_hba * phba)
1633 lpfc_sli_flush_mbox_queue(phba); 1810 lpfc_sli_flush_mbox_queue(phba);
1634} 1811}
1635 1812
1813/**
1814 * lpfc_offline: Bring a HBA offline.
1815 * @phba: pointer to lpfc hba data structure.
1816 *
1817 * This routine actually brings a HBA offline. It stops all the timers
1818 * associated with the HBA, brings down the SLI layer, and eventually
1819 * marks the HBA as in offline state for the upper layer protocol.
1820 **/
1636void 1821void
1637lpfc_offline(struct lpfc_hba *phba) 1822lpfc_offline(struct lpfc_hba *phba)
1638{ 1823{
@@ -1670,12 +1855,17 @@ lpfc_offline(struct lpfc_hba *phba)
1670 lpfc_destroy_vport_work_array(phba, vports); 1855 lpfc_destroy_vport_work_array(phba, vports);
1671} 1856}
1672 1857
1673/****************************************************************************** 1858/**
1674* Function name: lpfc_scsi_free 1859 * lpfc_scsi_free: Free all the SCSI buffers and IOCBs from driver lists.
1675* 1860 * @phba: pointer to lpfc hba data structure.
1676* Description: Called from lpfc_pci_remove_one free internal driver resources 1861 *
1677* 1862 * This routine is to free all the SCSI buffers and IOCBs from the driver
1678******************************************************************************/ 1863 * list back to kernel. It is called from lpfc_pci_remove_one to free
1864 * the internal resources before the device is removed from the system.
1865 *
1866 * Return codes
1867 * 0 - successful (for now, it always returns 0)
1868 **/
1679static int 1869static int
1680lpfc_scsi_free(struct lpfc_hba *phba) 1870lpfc_scsi_free(struct lpfc_hba *phba)
1681{ 1871{
@@ -1704,6 +1894,22 @@ lpfc_scsi_free(struct lpfc_hba *phba)
1704 return 0; 1894 return 0;
1705} 1895}
1706 1896
1897/**
1898 * lpfc_create_port: Create an FC port.
1899 * @phba: pointer to lpfc hba data structure.
1900 * @instance: a unique integer ID to this FC port.
1901 * @dev: pointer to the device data structure.
1902 *
1903 * This routine creates a FC port for the upper layer protocol. The FC port
1904 * can be created on top of either a physical port or a virtual port provided
1905 * by the HBA. This routine also allocates a SCSI host data structure (shost)
1906 * and associates the FC port created before adding the shost into the SCSI
1907 * layer.
1908 *
1909 * Return codes
1910 * @vport - pointer to the virtual N_Port data structure.
1911 * NULL - port create failed.
1912 **/
1707struct lpfc_vport * 1913struct lpfc_vport *
1708lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) 1914lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
1709{ 1915{
@@ -1777,6 +1983,13 @@ out:
1777 return NULL; 1983 return NULL;
1778} 1984}
1779 1985
1986/**
1987 * destroy_port: Destroy an FC port.
1988 * @vport: pointer to an lpfc virtual N_Port data structure.
1989 *
1990 * This routine destroys a FC port from the upper layer protocol. All the
1991 * resources associated with the port are released.
1992 **/
1780void 1993void
1781destroy_port(struct lpfc_vport *vport) 1994destroy_port(struct lpfc_vport *vport)
1782{ 1995{
@@ -1797,6 +2010,16 @@ destroy_port(struct lpfc_vport *vport)
1797 return; 2010 return;
1798} 2011}
1799 2012
2013/**
2014 * lpfc_get_instance: Get a unique integer ID.
2015 *
2016 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
2017 * uses the kernel idr facility to perform the task.
2018 *
2019 * Return codes:
2020 * instance - a unique integer ID allocated as the new instance.
2021 * -1 - lpfc get instance failed.
2022 **/
1800int 2023int
1801lpfc_get_instance(void) 2024lpfc_get_instance(void)
1802{ 2025{
@@ -1810,11 +2033,21 @@ lpfc_get_instance(void)
1810 return instance; 2033 return instance;
1811} 2034}
1812 2035
1813/* 2036/**
1814 * Note: there is no scan_start function as adapter initialization 2037 * lpfc_scan_finished: method for SCSI layer to detect whether scan is done.
1815 * will have asynchronously kicked off the link initialization. 2038 * @shost: pointer to SCSI host data structure.
1816 */ 2039 * @time: elapsed time of the scan in jiffies.
1817 2040 *
2041 * This routine is called by the SCSI layer with a SCSI host to determine
2042 * whether the scan host is finished.
2043 *
2044 * Note: there is no scan_start function as adapter initialization will have
2045 * asynchronously kicked off the link initialization.
2046 *
2047 * Return codes
2048 * 0 - SCSI host scan is not over yet.
2049 * 1 - SCSI host scan is over.
2050 **/
1818int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time) 2051int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
1819{ 2052{
1820 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 2053 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
@@ -1858,6 +2091,13 @@ finished:
1858 return stat; 2091 return stat;
1859} 2092}
1860 2093
2094/**
2095 * lpfc_host_attrib_init: Initialize SCSI host attributes on a FC port.
2096 * @shost: pointer to SCSI host data structure.
2097 *
2098 * This routine initializes a given SCSI host attributes on a FC port. The
2099 * SCSI host can be either on top of a physical port or a virtual port.
2100 **/
1861void lpfc_host_attrib_init(struct Scsi_Host *shost) 2101void lpfc_host_attrib_init(struct Scsi_Host *shost)
1862{ 2102{
1863 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 2103 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
@@ -1906,6 +2146,25 @@ void lpfc_host_attrib_init(struct Scsi_Host *shost)
1906 spin_unlock_irq(shost->host_lock); 2146 spin_unlock_irq(shost->host_lock);
1907} 2147}
1908 2148
2149/**
2150 * lpfc_enable_msix: Enable MSI-X interrupt mode.
2151 * @phba: pointer to lpfc hba data structure.
2152 *
2153 * This routine is invoked to enable the MSI-X interrupt vectors. The kernel
2154 * function pci_enable_msix() is called to enable the MSI-X vectors. Note that
2155 * pci_enable_msix(), once invoked, enables either all or nothing, depending
2156 * on the current availability of PCI vector resources. The device driver is
2157 * responsible for calling the individual request_irq() to register each MSI-X
2158 * vector with a interrupt handler, which is done in this function. Note that
2159 * later when device is unloading, the driver should always call free_irq()
2160 * on all MSI-X vectors it has done request_irq() on before calling
2161 * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
2162 * will be left with MSI-X enabled and leaks its vectors.
2163 *
2164 * Return codes
2165 * 0 - sucessful
2166 * other values - error
2167 **/
1909static int 2168static int
1910lpfc_enable_msix(struct lpfc_hba *phba) 2169lpfc_enable_msix(struct lpfc_hba *phba)
1911{ 2170{
@@ -1935,6 +2194,13 @@ lpfc_enable_msix(struct lpfc_hba *phba)
1935 return error; 2194 return error;
1936} 2195}
1937 2196
2197/**
2198 * lpfc_disable_msix: Disable MSI-X interrupt mode.
2199 * @phba: pointer to lpfc hba data structure.
2200 *
2201 * This routine is invoked to release the MSI-X vectors and then disable the
2202 * MSI-X interrupt mode.
2203 **/
1938static void 2204static void
1939lpfc_disable_msix(struct lpfc_hba *phba) 2205lpfc_disable_msix(struct lpfc_hba *phba)
1940{ 2206{
@@ -1942,6 +2208,23 @@ lpfc_disable_msix(struct lpfc_hba *phba)
1942 pci_disable_msix(phba->pcidev); 2208 pci_disable_msix(phba->pcidev);
1943} 2209}
1944 2210
2211/**
2212 * lpfc_pci_probe_one: lpfc PCI probe func to register device to PCI subsystem.
2213 * @pdev: pointer to PCI device
2214 * @pid: pointer to PCI device identifier
2215 *
2216 * This routine is to be registered to the kernel's PCI subsystem. When an
2217 * Emulex HBA is presented in PCI bus, the kernel PCI subsystem looks at
2218 * PCI device-specific information of the device and driver to see if the
2219 * driver state that it can support this kind of device. If the match is
2220 * successful, the driver core invokes this routine. If this routine
2221 * determines it can claim the HBA, it does all the initialization that it
2222 * needs to do to handle the HBA properly.
2223 *
2224 * Return code
2225 * 0 - driver can claim the device
2226 * negative value - driver can not claim the device
2227 **/
1945static int __devinit 2228static int __devinit
1946lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) 2229lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
1947{ 2230{
@@ -2262,6 +2545,14 @@ out:
2262 return error; 2545 return error;
2263} 2546}
2264 2547
2548/**
2549 * lpfc_pci_remove_one: lpfc PCI func to unregister device from PCI subsystem.
2550 * @pdev: pointer to PCI device
2551 *
2552 * This routine is to be registered to the kernel's PCI subsystem. When an
2553 * Emulex HBA is removed from PCI bus. It perform all the necessary cleanup
2554 * for the HBA device to be removed from the PCI subsystem properly.
2555 **/
2265static void __devexit 2556static void __devexit
2266lpfc_pci_remove_one(struct pci_dev *pdev) 2557lpfc_pci_remove_one(struct pci_dev *pdev)
2267{ 2558{
@@ -2336,13 +2627,21 @@ lpfc_pci_remove_one(struct pci_dev *pdev)
2336} 2627}
2337 2628
2338/** 2629/**
2339 * lpfc_io_error_detected - called when PCI error is detected 2630 * lpfc_io_error_detected: Driver method for handling PCI I/O error detected.
2340 * @pdev: Pointer to PCI device 2631 * @pdev: pointer to PCI device.
2341 * @state: The current pci conneection state 2632 * @state: the current PCI connection state.
2342 * 2633 *
2343 * This function is called after a PCI bus error affecting 2634 * This routine is registered to the PCI subsystem for error handling. This
2344 * this device has been detected. 2635 * function is called by the PCI subsystem after a PCI bus error affecting
2345 */ 2636 * this device has been detected. When this function is invoked, it will
2637 * need to stop all the I/Os and interrupt(s) to the device. Once that is
2638 * done, it will return PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to
2639 * perform proper recovery as desired.
2640 *
2641 * Return codes
2642 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
2643 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
2644 **/
2346static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev, 2645static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev,
2347 pci_channel_state_t state) 2646 pci_channel_state_t state)
2348{ 2647{
@@ -2376,10 +2675,21 @@ static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev,
2376} 2675}
2377 2676
2378/** 2677/**
2379 * lpfc_io_slot_reset - called after the pci bus has been reset. 2678 * lpfc_io_slot_reset: Restart a PCI device from scratch.
2380 * @pdev: Pointer to PCI device 2679 * @pdev: pointer to PCI device.
2680 *
2681 * This routine is registered to the PCI subsystem for error handling. This is
2682 * called after PCI bus has been reset to restart the PCI card from scratch,
2683 * as if from a cold-boot. During the PCI subsystem error recovery, after the
2684 * driver returns PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform
2685 * proper error recovery and then call this routine before calling the .resume
2686 * method to recover the device. This function will initialize the HBA device,
2687 * enable the interrupt, but it will just put the HBA to offline state without
2688 * passing any I/O traffic.
2381 * 2689 *
2382 * Restart the card from scratch, as if from a cold-boot. 2690 * Return codes
2691 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
2692 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
2383 */ 2693 */
2384static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev) 2694static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev)
2385{ 2695{
@@ -2440,11 +2750,13 @@ static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev)
2440} 2750}
2441 2751
2442/** 2752/**
2443 * lpfc_io_resume - called when traffic can start flowing again. 2753 * lpfc_io_resume: Resume PCI I/O operation.
2444 * @pdev: Pointer to PCI device 2754 * @pdev: pointer to PCI device
2445 * 2755 *
2446 * This callback is called when the error recovery driver tells us that 2756 * This routine is registered to the PCI subsystem for error handling. It is
2447 * its OK to resume normal operation. 2757 * called when kernel error recovery tells the lpfc driver that it is ok to
2758 * resume normal PCI operation after PCI bus error recovery. After this call,
2759 * traffic can start to flow from this device again.
2448 */ 2760 */
2449static void lpfc_io_resume(struct pci_dev *pdev) 2761static void lpfc_io_resume(struct pci_dev *pdev)
2450{ 2762{
@@ -2540,6 +2852,18 @@ static struct pci_driver lpfc_driver = {
2540 .err_handler = &lpfc_err_handler, 2852 .err_handler = &lpfc_err_handler,
2541}; 2853};
2542 2854
2855/**
2856 * lpfc_init: lpfc module initialization routine.
2857 *
2858 * This routine is to be invoked when the lpfc module is loaded into the
2859 * kernel. The special kernel macro module_init() is used to indicate the
2860 * role of this routine to the kernel as lpfc module entry point.
2861 *
2862 * Return codes
2863 * 0 - successful
2864 * -ENOMEM - FC attach transport failed
2865 * all others - failed
2866 */
2543static int __init 2867static int __init
2544lpfc_init(void) 2868lpfc_init(void)
2545{ 2869{
@@ -2573,6 +2897,13 @@ lpfc_init(void)
2573 return error; 2897 return error;
2574} 2898}
2575 2899
2900/**
2901 * lpfc_exit: lpfc module removal routine.
2902 *
2903 * This routine is invoked when the lpfc module is removed from the kernel.
2904 * The special kernel macro module_exit() is used to indicate the role of
2905 * this routine to the kernel as lpfc module exit point.
2906 */
2576static void __exit 2907static void __exit
2577lpfc_exit(void) 2908lpfc_exit(void)
2578{ 2909{
diff --git a/drivers/scsi/lpfc/lpfc_mbox.c b/drivers/scsi/lpfc/lpfc_mbox.c
index 7a9be4c5b7cb..7413bfdf89a4 100644
--- a/drivers/scsi/lpfc/lpfc_mbox.c
+++ b/drivers/scsi/lpfc/lpfc_mbox.c
@@ -37,10 +37,20 @@
37#include "lpfc_crtn.h" 37#include "lpfc_crtn.h"
38#include "lpfc_compat.h" 38#include "lpfc_compat.h"
39 39
40/**********************************************/ 40/**
41 41 * lpfc_dump_mem: Prepare a mailbox command for retrieving HBA's VPD memory.
42/* mailbox command */ 42 * @phba: pointer to lpfc hba data structure.
43/**********************************************/ 43 * @pmb: pointer to the driver internal queue element for mailbox command.
44 * @offset: offset for dumping VPD memory mailbox command.
45 *
46 * The dump mailbox command provides a method for the device driver to obtain
47 * various types of information from the HBA device.
48 *
49 * This routine prepares the mailbox command for dumping HBA Vital Product
50 * Data (VPD) memory. This mailbox command is to be used for retrieving a
51 * portion (DMP_RSP_SIZE bytes) of a HBA's VPD from the HBA at an address
52 * offset specified by the offset parameter.
53 **/
44void 54void
45lpfc_dump_mem(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, uint16_t offset) 55lpfc_dump_mem(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, uint16_t offset)
46{ 56{
@@ -65,10 +75,17 @@ lpfc_dump_mem(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, uint16_t offset)
65 return; 75 return;
66} 76}
67 77
68/**********************************************/ 78/**
69/* lpfc_read_nv Issue a READ NVPARAM */ 79 * lpfc_read_nv: Prepare a mailbox command for reading HBA's NVRAM param.
70/* mailbox command */ 80 * @phba: pointer to lpfc hba data structure.
71/**********************************************/ 81 * @pmb: pointer to the driver internal queue element for mailbox command.
82 *
83 * The read NVRAM mailbox command returns the HBA's non-volatile parameters
84 * that are used as defaults when the Fibre Channel link is brought on-line.
85 *
86 * This routine prepares the mailbox command for reading information stored
87 * in the HBA's NVRAM. Specifically, the HBA's WWNN and WWPN.
88 **/
72void 89void
73lpfc_read_nv(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) 90lpfc_read_nv(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
74{ 91{
@@ -81,10 +98,19 @@ lpfc_read_nv(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
81 return; 98 return;
82} 99}
83 100
84/**********************************************/ 101/**
85/* lpfc_config_async Issue a */ 102 * lpfc_config_async: Prepare a mailbox command for enabling HBA async event.
86/* MBX_ASYNC_EVT_ENABLE mailbox command */ 103 * @phba: pointer to lpfc hba data structure.
87/**********************************************/ 104 * @pmb: pointer to the driver internal queue element for mailbox command.
105 * @ring: ring number for the asynchronous event to be configured.
106 *
107 * The asynchronous event enable mailbox command is used to enable the
108 * asynchronous event posting via the ASYNC_STATUS_CN IOCB response and
109 * specifies the default ring to which events are posted.
110 *
111 * This routine prepares the mailbox command for enabling HBA asynchronous
112 * event support on a IOCB ring.
113 **/
88void 114void
89lpfc_config_async(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, 115lpfc_config_async(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb,
90 uint32_t ring) 116 uint32_t ring)
@@ -99,10 +125,19 @@ lpfc_config_async(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb,
99 return; 125 return;
100} 126}
101 127
102/**********************************************/ 128/**
103/* lpfc_heart_beat Issue a HEART_BEAT */ 129 * lpfc_heart_beat: Prepare a mailbox command for heart beat.
104/* mailbox command */ 130 * @phba: pointer to lpfc hba data structure.
105/**********************************************/ 131 * @pmb: pointer to the driver internal queue element for mailbox command.
132 *
133 * The heart beat mailbox command is used to detect an unresponsive HBA, which
134 * is defined as any device where no error attention is sent and both mailbox
135 * and rings are not processed.
136 *
137 * This routine prepares the mailbox command for issuing a heart beat in the
138 * form of mailbox command to the HBA. The timely completion of the heart
139 * beat mailbox command indicates the health of the HBA.
140 **/
106void 141void
107lpfc_heart_beat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) 142lpfc_heart_beat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
108{ 143{
@@ -115,10 +150,26 @@ lpfc_heart_beat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
115 return; 150 return;
116} 151}
117 152
118/**********************************************/ 153/**
119/* lpfc_read_la Issue a READ LA */ 154 * lpfc_read_la: Prepare a mailbox command for reading HBA link attention.
120/* mailbox command */ 155 * @phba: pointer to lpfc hba data structure.
121/**********************************************/ 156 * @pmb: pointer to the driver internal queue element for mailbox command.
157 * @mp: DMA buffer memory for reading the link attention information into.
158 *
159 * The read link attention mailbox command is issued to read the Link Event
160 * Attention information indicated by the HBA port when the Link Event bit
161 * of the Host Attention (HSTATT) register is set to 1. A Link Event
162 * Attention occurs based on an exception detected at the Fibre Channel link
163 * interface.
164 *
165 * This routine prepares the mailbox command for reading HBA link attention
166 * information. A DMA memory has been set aside and address passed to the
167 * HBA through @mp for the HBA to DMA link attention information into the
168 * memory as part of the execution of the mailbox command.
169 *
170 * Return codes
171 * 0 - Success (currently always return 0)
172 **/
122int 173int
123lpfc_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, struct lpfc_dmabuf *mp) 174lpfc_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, struct lpfc_dmabuf *mp)
124{ 175{
@@ -143,10 +194,21 @@ lpfc_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, struct lpfc_dmabuf *mp)
143 return (0); 194 return (0);
144} 195}
145 196
146/**********************************************/ 197/**
147/* lpfc_clear_la Issue a CLEAR LA */ 198 * lpfc_clear_la: Prepare a mailbox command for clearing HBA link attention.
148/* mailbox command */ 199 * @phba: pointer to lpfc hba data structure.
149/**********************************************/ 200 * @pmb: pointer to the driver internal queue element for mailbox command.
201 *
202 * The clear link attention mailbox command is issued to clear the link event
203 * attention condition indicated by the Link Event bit of the Host Attention
204 * (HSTATT) register. The link event attention condition is cleared only if
205 * the event tag specified matches that of the current link event counter.
206 * The current event tag is read using the read link attention event mailbox
207 * command.
208 *
209 * This routine prepares the mailbox command for clearing HBA link attention
210 * information.
211 **/
150void 212void
151lpfc_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) 213lpfc_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
152{ 214{
@@ -161,10 +223,20 @@ lpfc_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
161 return; 223 return;
162} 224}
163 225
164/**************************************************/ 226/**
165/* lpfc_config_link Issue a CONFIG LINK */ 227 * lpfc_config_link: Prepare a mailbox command for configuring link on a HBA.
166/* mailbox command */ 228 * @phba: pointer to lpfc hba data structure.
167/**************************************************/ 229 * @pmb: pointer to the driver internal queue element for mailbox command.
230 *
231 * The configure link mailbox command is used before the initialize link
232 * mailbox command to override default value and to configure link-oriented
233 * parameters such as DID address and various timers. Typically, this
234 * command would be used after an F_Port login to set the returned DID address
235 * and the fabric timeout values. This command is not valid before a configure
236 * port command has configured the HBA port.
237 *
238 * This routine prepares the mailbox command for configuring link on a HBA.
239 **/
168void 240void
169lpfc_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) 241lpfc_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
170{ 242{
@@ -199,10 +271,20 @@ lpfc_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
199 return; 271 return;
200} 272}
201 273
202/**********************************************/ 274/**
203/* lpfc_init_link Issue an INIT LINK */ 275 * lpfc_init_link: Prepare a mailbox command for initialize link on a HBA.
204/* mailbox command */ 276 * @phba: pointer to lpfc hba data structure.
205/**********************************************/ 277 * @pmb: pointer to the driver internal queue element for mailbox command.
278 * @topology: the link topology for the link to be initialized to.
279 * @linkspeed: the link speed for the link to be initialized to.
280 *
281 * The initialize link mailbox command is used to initialize the Fibre
282 * Channel link. This command must follow a configure port command that
283 * establishes the mode of operation.
284 *
285 * This routine prepares the mailbox command for initializing link on a HBA
286 * with the specified link topology and speed.
287 **/
206void 288void
207lpfc_init_link(struct lpfc_hba * phba, 289lpfc_init_link(struct lpfc_hba * phba,
208 LPFC_MBOXQ_t * pmb, uint32_t topology, uint32_t linkspeed) 290 LPFC_MBOXQ_t * pmb, uint32_t topology, uint32_t linkspeed)
@@ -269,10 +351,27 @@ lpfc_init_link(struct lpfc_hba * phba,
269 return; 351 return;
270} 352}
271 353
272/**********************************************/ 354/**
273/* lpfc_read_sparam Issue a READ SPARAM */ 355 * lpfc_read_sparam: Prepare a mailbox command for reading HBA parameters.
274/* mailbox command */ 356 * @phba: pointer to lpfc hba data structure.
275/**********************************************/ 357 * @pmb: pointer to the driver internal queue element for mailbox command.
358 * @vpi: virtual N_Port identifier.
359 *
360 * The read service parameter mailbox command is used to read the HBA port
361 * service parameters. The service parameters are read into the buffer
362 * specified directly by a BDE in the mailbox command. These service
363 * parameters may then be used to build the payload of an N_Port/F_POrt
364 * login request and reply (LOGI/ACC).
365 *
366 * This routine prepares the mailbox command for reading HBA port service
367 * parameters. The DMA memory is allocated in this function and the addresses
368 * are populated into the mailbox command for the HBA to DMA the service
369 * parameters into.
370 *
371 * Return codes
372 * 0 - Success
373 * 1 - DMA memory allocation failed
374 **/
276int 375int
277lpfc_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, int vpi) 376lpfc_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, int vpi)
278{ 377{
@@ -312,10 +411,21 @@ lpfc_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, int vpi)
312 return (0); 411 return (0);
313} 412}
314 413
315/********************************************/ 414/**
316/* lpfc_unreg_did Issue a UNREG_DID */ 415 * lpfc_unreg_did: Prepare a mailbox command for unregistering DID.
317/* mailbox command */ 416 * @phba: pointer to lpfc hba data structure.
318/********************************************/ 417 * @vpi: virtual N_Port identifier.
418 * @did: remote port identifier.
419 * @pmb: pointer to the driver internal queue element for mailbox command.
420 *
421 * The unregister DID mailbox command is used to unregister an N_Port/F_Port
422 * login for an unknown RPI by specifying the DID of a remote port. This
423 * command frees an RPI context in the HBA port. This has the effect of
424 * performing an implicit N_Port/F_Port logout.
425 *
426 * This routine prepares the mailbox command for unregistering a remote
427 * N_Port/F_Port (DID) login.
428 **/
319void 429void
320lpfc_unreg_did(struct lpfc_hba * phba, uint16_t vpi, uint32_t did, 430lpfc_unreg_did(struct lpfc_hba * phba, uint16_t vpi, uint32_t did,
321 LPFC_MBOXQ_t * pmb) 431 LPFC_MBOXQ_t * pmb)
@@ -333,10 +443,19 @@ lpfc_unreg_did(struct lpfc_hba * phba, uint16_t vpi, uint32_t did,
333 return; 443 return;
334} 444}
335 445
336/**********************************************/ 446/**
337/* lpfc_read_nv Issue a READ CONFIG */ 447 * lpfc_read_config: Prepare a mailbox command for reading HBA configuration.
338/* mailbox command */ 448 * @phba: pointer to lpfc hba data structure.
339/**********************************************/ 449 * @pmb: pointer to the driver internal queue element for mailbox command.
450 *
451 * The read configuration mailbox command is used to read the HBA port
452 * configuration parameters. This mailbox command provides a method for
453 * seeing any parameters that may have changed via various configuration
454 * mailbox commands.
455 *
456 * This routine prepares the mailbox command for reading out HBA configuration
457 * parameters.
458 **/
340void 459void
341lpfc_read_config(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) 460lpfc_read_config(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
342{ 461{
@@ -350,10 +469,18 @@ lpfc_read_config(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
350 return; 469 return;
351} 470}
352 471
353/*************************************************/ 472/**
354/* lpfc_read_lnk_stat Issue a READ LINK STATUS */ 473 * lpfc_read_lnk_stat: Prepare a mailbox command for reading HBA link stats.
355/* mailbox command */ 474 * @phba: pointer to lpfc hba data structure.
356/*************************************************/ 475 * @pmb: pointer to the driver internal queue element for mailbox command.
476 *
477 * The read link status mailbox command is used to read the link status from
478 * the HBA. Link status includes all link-related error counters. These
479 * counters are maintained by the HBA and originated in the link hardware
480 * unit. Note that all of these counters wrap.
481 *
482 * This routine prepares the mailbox command for reading out HBA link status.
483 **/
357void 484void
358lpfc_read_lnk_stat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) 485lpfc_read_lnk_stat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
359{ 486{
@@ -367,10 +494,30 @@ lpfc_read_lnk_stat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
367 return; 494 return;
368} 495}
369 496
370/********************************************/ 497/**
371/* lpfc_reg_login Issue a REG_LOGIN */ 498 * lpfc_reg_login: Prepare a mailbox command for registering remote login.
372/* mailbox command */ 499 * @phba: pointer to lpfc hba data structure.
373/********************************************/ 500 * @vpi: virtual N_Port identifier.
501 * @did: remote port identifier.
502 * @param: pointer to memory holding the server parameters.
503 * @pmb: pointer to the driver internal queue element for mailbox command.
504 * @flag: action flag to be passed back for the complete function.
505 *
506 * The registration login mailbox command is used to register an N_Port or
507 * F_Port login. This registration allows the HBA to cache the remote N_Port
508 * service parameters internally and thereby make the appropriate FC-2
509 * decisions. The remote port service parameters are handed off by the driver
510 * to the HBA using a descriptor entry that directly identifies a buffer in
511 * host memory. In exchange, the HBA returns an RPI identifier.
512 *
513 * This routine prepares the mailbox command for registering remote port login.
514 * The function allocates DMA buffer for passing the service parameters to the
515 * HBA with the mailbox command.
516 *
517 * Return codes
518 * 0 - Success
519 * 1 - DMA memory allocation failed
520 **/
374int 521int
375lpfc_reg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t did, 522lpfc_reg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t did,
376 uint8_t *param, LPFC_MBOXQ_t *pmb, uint32_t flag) 523 uint8_t *param, LPFC_MBOXQ_t *pmb, uint32_t flag)
@@ -418,10 +565,20 @@ lpfc_reg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t did,
418 return (0); 565 return (0);
419} 566}
420 567
421/**********************************************/ 568/**
422/* lpfc_unreg_login Issue a UNREG_LOGIN */ 569 * lpfc_unreg_login: Prepare a mailbox command for unregistering remote login.
423/* mailbox command */ 570 * @phba: pointer to lpfc hba data structure.
424/**********************************************/ 571 * @vpi: virtual N_Port identifier.
572 * @rpi: remote port identifier
573 * @pmb: pointer to the driver internal queue element for mailbox command.
574 *
575 * The unregistration login mailbox command is used to unregister an N_Port
576 * or F_Port login. This command frees an RPI context in the HBA. It has the
577 * effect of performing an implicit N_Port/F_Port logout.
578 *
579 * This routine prepares the mailbox command for unregistering remote port
580 * login.
581 **/
425void 582void
426lpfc_unreg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t rpi, 583lpfc_unreg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t rpi,
427 LPFC_MBOXQ_t * pmb) 584 LPFC_MBOXQ_t * pmb)
@@ -440,10 +597,21 @@ lpfc_unreg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t rpi,
440 return; 597 return;
441} 598}
442 599
443/**************************************************/ 600/**
444/* lpfc_reg_vpi Issue a REG_VPI */ 601 * lpfc_reg_vpi: Prepare a mailbox command for registering vport identifier.
445/* mailbox command */ 602 * @phba: pointer to lpfc hba data structure.
446/**************************************************/ 603 * @vpi: virtual N_Port identifier.
604 * @sid: Fibre Channel S_ID (N_Port_ID assigned to a virtual N_Port).
605 * @pmb: pointer to the driver internal queue element for mailbox command.
606 *
607 * The registration vport identifier mailbox command is used to activate a
608 * virtual N_Port after it has acquired an N_Port_ID. The HBA validates the
609 * N_Port_ID against the information in the selected virtual N_Port context
610 * block and marks it active to allow normal processing of IOCB commands and
611 * received unsolicited exchanges.
612 *
613 * This routine prepares the mailbox command for registering a virtual N_Port.
614 **/
447void 615void
448lpfc_reg_vpi(struct lpfc_hba *phba, uint16_t vpi, uint32_t sid, 616lpfc_reg_vpi(struct lpfc_hba *phba, uint16_t vpi, uint32_t sid,
449 LPFC_MBOXQ_t *pmb) 617 LPFC_MBOXQ_t *pmb)
@@ -461,10 +629,22 @@ lpfc_reg_vpi(struct lpfc_hba *phba, uint16_t vpi, uint32_t sid,
461 629
462} 630}
463 631
464/**************************************************/ 632/**
465/* lpfc_unreg_vpi Issue a UNREG_VNPI */ 633 * lpfc_unreg_vpi: Prepare a mailbox command for unregistering vport id.
466/* mailbox command */ 634 * @phba: pointer to lpfc hba data structure.
467/**************************************************/ 635 * @vpi: virtual N_Port identifier.
636 * @pmb: pointer to the driver internal queue element for mailbox command.
637 *
638 * The unregistration vport identifier mailbox command is used to inactivate
639 * a virtual N_Port. The driver must have logged out and unregistered all
640 * remote N_Ports to abort any activity on the virtual N_Port. The HBA will
641 * unregisters any default RPIs associated with the specified vpi, aborting
642 * any active exchanges. The HBA will post the mailbox response after making
643 * the virtual N_Port inactive.
644 *
645 * This routine prepares the mailbox command for unregistering a virtual
646 * N_Port.
647 **/
468void 648void
469lpfc_unreg_vpi(struct lpfc_hba *phba, uint16_t vpi, LPFC_MBOXQ_t *pmb) 649lpfc_unreg_vpi(struct lpfc_hba *phba, uint16_t vpi, LPFC_MBOXQ_t *pmb)
470{ 650{
@@ -479,6 +659,13 @@ lpfc_unreg_vpi(struct lpfc_hba *phba, uint16_t vpi, LPFC_MBOXQ_t *pmb)
479 659
480} 660}
481 661
662/**
663 * lpfc_config_pcb_setup: Set up IOCB rings in the Port Control Block (PCB)
664 * @phba: pointer to lpfc hba data structure.
665 *
666 * This routine sets up and initializes the IOCB rings in the Port Control
667 * Block (PCB).
668 **/
482static void 669static void
483lpfc_config_pcb_setup(struct lpfc_hba * phba) 670lpfc_config_pcb_setup(struct lpfc_hba * phba)
484{ 671{
@@ -536,6 +723,20 @@ lpfc_config_pcb_setup(struct lpfc_hba * phba)
536 } 723 }
537} 724}
538 725
726/**
727 * lpfc_read_rev: Prepare a mailbox command for reading HBA revision.
728 * @phba: pointer to lpfc hba data structure.
729 * @pmb: pointer to the driver internal queue element for mailbox command.
730 *
731 * The read revision mailbox command is used to read the revision levels of
732 * the HBA components. These components include hardware units, resident
733 * firmware, and available firmware. HBAs that supports SLI-3 mode of
734 * operation provide different response information depending on the version
735 * requested by the driver.
736 *
737 * This routine prepares the mailbox command for reading HBA revision
738 * information.
739 **/
539void 740void
540lpfc_read_rev(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) 741lpfc_read_rev(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
541{ 742{
@@ -548,6 +749,16 @@ lpfc_read_rev(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
548 return; 749 return;
549} 750}
550 751
752/**
753 * lpfc_build_hbq_profile2: Set up the HBQ Selection Profile 2.
754 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
755 * @hbq_desc: pointer to the HBQ selection profile descriptor.
756 *
757 * The Host Buffer Queue (HBQ) Selection Profile 2 specifies that the HBA
758 * tests the incoming frames' R_CTL/TYPE fields with works 10:15 and performs
759 * the Sequence Length Test using the fields in the Selection Profile 2
760 * extension in words 20:31.
761 **/
551static void 762static void
552lpfc_build_hbq_profile2(struct config_hbq_var *hbqmb, 763lpfc_build_hbq_profile2(struct config_hbq_var *hbqmb,
553 struct lpfc_hbq_init *hbq_desc) 764 struct lpfc_hbq_init *hbq_desc)
@@ -557,6 +768,16 @@ lpfc_build_hbq_profile2(struct config_hbq_var *hbqmb,
557 hbqmb->profiles.profile2.seqlenoff = hbq_desc->seqlenoff; 768 hbqmb->profiles.profile2.seqlenoff = hbq_desc->seqlenoff;
558} 769}
559 770
771/**
772 * lpfc_build_hbq_profile3: Set up the HBQ Selection Profile 3.
773 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
774 * @hbq_desc: pointer to the HBQ selection profile descriptor.
775 *
776 * The Host Buffer Queue (HBQ) Selection Profile 3 specifies that the HBA
777 * tests the incoming frame's R_CTL/TYPE fields with words 10:15 and performs
778 * the Sequence Length Test and Byte Field Test using the fields in the
779 * Selection Profile 3 extension in words 20:31.
780 **/
560static void 781static void
561lpfc_build_hbq_profile3(struct config_hbq_var *hbqmb, 782lpfc_build_hbq_profile3(struct config_hbq_var *hbqmb,
562 struct lpfc_hbq_init *hbq_desc) 783 struct lpfc_hbq_init *hbq_desc)
@@ -569,6 +790,17 @@ lpfc_build_hbq_profile3(struct config_hbq_var *hbqmb,
569 sizeof(hbqmb->profiles.profile3.cmdmatch)); 790 sizeof(hbqmb->profiles.profile3.cmdmatch));
570} 791}
571 792
793/**
794 * lpfc_build_hbq_profile5: Set up the HBQ Selection Profile 5.
795 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
796 * @hbq_desc: pointer to the HBQ selection profile descriptor.
797 *
798 * The Host Buffer Queue (HBQ) Selection Profile 5 specifies a header HBQ. The
799 * HBA tests the initial frame of an incoming sequence using the frame's
800 * R_CTL/TYPE fields with words 10:15 and performs the Sequence Length Test
801 * and Byte Field Test using the fields in the Selection Profile 5 extension
802 * words 20:31.
803 **/
572static void 804static void
573lpfc_build_hbq_profile5(struct config_hbq_var *hbqmb, 805lpfc_build_hbq_profile5(struct config_hbq_var *hbqmb,
574 struct lpfc_hbq_init *hbq_desc) 806 struct lpfc_hbq_init *hbq_desc)
@@ -581,6 +813,20 @@ lpfc_build_hbq_profile5(struct config_hbq_var *hbqmb,
581 sizeof(hbqmb->profiles.profile5.cmdmatch)); 813 sizeof(hbqmb->profiles.profile5.cmdmatch));
582} 814}
583 815
816/**
817 * lpfc_config_hbq: Prepare a mailbox command for configuring an HBQ.
818 * @phba: pointer to lpfc hba data structure.
819 * @id: HBQ identifier.
820 * @hbq_desc: pointer to the HBA descriptor data structure.
821 * @hbq_entry_index: index of the HBQ entry data structures.
822 * @pmb: pointer to the driver internal queue element for mailbox command.
823 *
824 * The configure HBQ (Host Buffer Queue) mailbox command is used to configure
825 * an HBQ. The configuration binds events that require buffers to a particular
826 * ring and HBQ based on a selection profile.
827 *
828 * This routine prepares the mailbox command for configuring an HBQ.
829 **/
584void 830void
585lpfc_config_hbq(struct lpfc_hba *phba, uint32_t id, 831lpfc_config_hbq(struct lpfc_hba *phba, uint32_t id,
586 struct lpfc_hbq_init *hbq_desc, 832 struct lpfc_hbq_init *hbq_desc,
@@ -641,8 +887,23 @@ lpfc_config_hbq(struct lpfc_hba *phba, uint32_t id,
641 return; 887 return;
642} 888}
643 889
644 890/**
645 891 * lpfc_config_ring: Prepare a mailbox command for configuring an IOCB ring.
892 * @phba: pointer to lpfc hba data structure.
893 * @ring:
894 * @pmb: pointer to the driver internal queue element for mailbox command.
895 *
896 * The configure ring mailbox command is used to configure an IOCB ring. This
897 * configuration binds from one to six of HBA RC_CTL/TYPE mask entries to the
898 * ring. This is used to map incoming sequences to a particular ring whose
899 * RC_CTL/TYPE mask entry matches that of the sequence. The driver should not
900 * attempt to configure a ring whose number is greater than the number
901 * specified in the Port Control Block (PCB). It is an error to issue the
902 * configure ring command more than once with the same ring number. The HBA
903 * returns an error if the driver attempts this.
904 *
905 * This routine prepares the mailbox command for configuring IOCB ring.
906 **/
646void 907void
647lpfc_config_ring(struct lpfc_hba * phba, int ring, LPFC_MBOXQ_t * pmb) 908lpfc_config_ring(struct lpfc_hba * phba, int ring, LPFC_MBOXQ_t * pmb)
648{ 909{
@@ -684,6 +945,20 @@ lpfc_config_ring(struct lpfc_hba * phba, int ring, LPFC_MBOXQ_t * pmb)
684 return; 945 return;
685} 946}
686 947
948/**
949 * lpfc_config_port: Prepare a mailbox command for configuring port.
950 * @phba: pointer to lpfc hba data structure.
951 * @pmb: pointer to the driver internal queue element for mailbox command.
952 *
953 * The configure port mailbox command is used to identify the Port Control
954 * Block (PCB) in the driver memory. After this command is issued, the
955 * driver must not access the mailbox in the HBA without first resetting
956 * the HBA. The HBA may copy the PCB information to internal storage for
957 * subsequent use; the driver can not change the PCB information unless it
958 * resets the HBA.
959 *
960 * This routine prepares the mailbox command for configuring port.
961 **/
687void 962void
688lpfc_config_port(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) 963lpfc_config_port(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
689{ 964{
@@ -839,6 +1114,21 @@ lpfc_config_port(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
839 sizeof(PCB_t)); 1114 sizeof(PCB_t));
840} 1115}
841 1116
1117/**
1118 * lpfc_kill_board: Prepare a mailbox command for killing board.
1119 * @phba: pointer to lpfc hba data structure.
1120 * @pmb: pointer to the driver internal queue element for mailbox command.
1121 *
1122 * The kill board mailbox command is used to tell firmware to perform a
1123 * graceful shutdown of a channel on a specified board to prepare for reset.
1124 * When the kill board mailbox command is received, the ER3 bit is set to 1
1125 * in the Host Status register and the ER Attention bit is set to 1 in the
1126 * Host Attention register of the HBA function that received the kill board
1127 * command.
1128 *
1129 * This routine prepares the mailbox command for killing the board in
1130 * preparation for a graceful shutdown.
1131 **/
842void 1132void
843lpfc_kill_board(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) 1133lpfc_kill_board(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
844{ 1134{
@@ -850,6 +1140,16 @@ lpfc_kill_board(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
850 return; 1140 return;
851} 1141}
852 1142
1143/**
1144 * lpfc_mbox_put: Put a mailbox cmd into the tail of driver's mailbox queue.
1145 * @phba: pointer to lpfc hba data structure.
1146 * @mbq: pointer to the driver internal queue element for mailbox command.
1147 *
1148 * Driver maintains a internal mailbox command queue implemented as a linked
1149 * list. When a mailbox command is issued, it shall be put into the mailbox
1150 * command queue such that they shall be processed orderly as HBA can process
1151 * one mailbox command at a time.
1152 **/
853void 1153void
854lpfc_mbox_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq) 1154lpfc_mbox_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq)
855{ 1155{
@@ -864,6 +1164,20 @@ lpfc_mbox_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq)
864 return; 1164 return;
865} 1165}
866 1166
1167/**
1168 * lpfc_mbox_get: Remove a mailbox cmd from the head of driver's mailbox queue.
1169 * @phba: pointer to lpfc hba data structure.
1170 *
1171 * Driver maintains a internal mailbox command queue implemented as a linked
1172 * list. When a mailbox command is issued, it shall be put into the mailbox
1173 * command queue such that they shall be processed orderly as HBA can process
1174 * one mailbox command at a time. After HBA finished processing a mailbox
1175 * command, the driver will remove a pending mailbox command from the head of
1176 * the mailbox command queue and send to the HBA for processing.
1177 *
1178 * Return codes
1179 * pointer to the driver internal queue element for mailbox command.
1180 **/
867LPFC_MBOXQ_t * 1181LPFC_MBOXQ_t *
868lpfc_mbox_get(struct lpfc_hba * phba) 1182lpfc_mbox_get(struct lpfc_hba * phba)
869{ 1183{
@@ -877,6 +1191,17 @@ lpfc_mbox_get(struct lpfc_hba * phba)
877 return mbq; 1191 return mbq;
878} 1192}
879 1193
1194/**
1195 * lpfc_mbox_cmpl_put: Put mailbox command into mailbox command complete list.
1196 * @phba: pointer to lpfc hba data structure.
1197 * @mbq: pointer to the driver internal queue element for mailbox command.
1198 *
1199 * This routine put the completed mailbox command into the mailbox command
1200 * complete list. This routine is called from driver interrupt handler
1201 * context.The mailbox complete list is used by the driver worker thread
1202 * to process mailbox complete callback functions outside the driver interrupt
1203 * handler.
1204 **/
880void 1205void
881lpfc_mbox_cmpl_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq) 1206lpfc_mbox_cmpl_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq)
882{ 1207{
@@ -887,6 +1212,17 @@ lpfc_mbox_cmpl_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq)
887 return; 1212 return;
888} 1213}
889 1214
1215/**
1216 * lpfc_mbox_tmo_val: Retrieve mailbox command timeout value.
1217 * @phba: pointer to lpfc hba data structure.
1218 * @cmd: mailbox command code.
1219 *
1220 * This routine retrieves the proper timeout value according to the mailbox
1221 * command code.
1222 *
1223 * Return codes
1224 * Timeout value to be used for the given mailbox command
1225 **/
890int 1226int
891lpfc_mbox_tmo_val(struct lpfc_hba *phba, int cmd) 1227lpfc_mbox_tmo_val(struct lpfc_hba *phba, int cmd)
892{ 1228{
diff --git a/drivers/scsi/lpfc/lpfc_mem.c b/drivers/scsi/lpfc/lpfc_mem.c
index 3c0cebc71800..50d9136a6e04 100644
--- a/drivers/scsi/lpfc/lpfc_mem.c
+++ b/drivers/scsi/lpfc/lpfc_mem.c
@@ -1,7 +1,7 @@
1/******************************************************************* 1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for * 2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. * 3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2006 Emulex. All rights reserved. * 4 * Copyright (C) 2004-2008 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. * 5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com * 6 * www.emulex.com *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig * 7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
@@ -39,7 +39,21 @@
39#define LPFC_MEM_POOL_SIZE 64 /* max elem in non-DMA safety pool */ 39#define LPFC_MEM_POOL_SIZE 64 /* max elem in non-DMA safety pool */
40 40
41 41
42 42/**
43 * lpfc_mem_alloc: create and allocate all PCI and memory pools
44 * @phba: HBA to allocate pools for
45 *
46 * Description: Creates and allocates PCI pools lpfc_scsi_dma_buf_pool,
47 * lpfc_mbuf_pool, lpfc_hbq_pool. Creates and allocates kmalloc-backed mempools
48 * for LPFC_MBOXQ_t and lpfc_nodelist. Also allocates the VPI bitmask.
49 *
50 * Notes: Not interrupt-safe. Must be called with no locks held. If any
51 * allocation fails, frees all successfully allocated memory before returning.
52 *
53 * Returns:
54 * 0 on success
55 * -ENOMEM on failure (if any memory allocations fail)
56 **/
43int 57int
44lpfc_mem_alloc(struct lpfc_hba * phba) 58lpfc_mem_alloc(struct lpfc_hba * phba)
45{ 59{
@@ -120,6 +134,16 @@ lpfc_mem_alloc(struct lpfc_hba * phba)
120 return -ENOMEM; 134 return -ENOMEM;
121} 135}
122 136
137/**
138 * lpfc_mem_free: Frees all PCI and memory allocated by lpfc_mem_alloc
139 * @phba: HBA to free memory for
140 *
141 * Description: Frees PCI pools lpfc_scsi_dma_buf_pool, lpfc_mbuf_pool,
142 * lpfc_hbq_pool. Frees kmalloc-backed mempools for LPFC_MBOXQ_t and
143 * lpfc_nodelist. Also frees the VPI bitmask.
144 *
145 * Returns: None
146 **/
123void 147void
124lpfc_mem_free(struct lpfc_hba * phba) 148lpfc_mem_free(struct lpfc_hba * phba)
125{ 149{
@@ -181,12 +205,29 @@ lpfc_mem_free(struct lpfc_hba * phba)
181 phba->lpfc_scsi_dma_buf_pool = NULL; 205 phba->lpfc_scsi_dma_buf_pool = NULL;
182 phba->lpfc_mbuf_pool = NULL; 206 phba->lpfc_mbuf_pool = NULL;
183 207
184 /* Free the iocb lookup array */ 208 /* Free the iocb lookup array */
185 kfree(psli->iocbq_lookup); 209 kfree(psli->iocbq_lookup);
186 psli->iocbq_lookup = NULL; 210 psli->iocbq_lookup = NULL;
187
188} 211}
189 212
213/**
214 * lpfc_mbuf_alloc: Allocate an mbuf from the lpfc_mbuf_pool PCI pool
215 * @phba: HBA which owns the pool to allocate from
216 * @mem_flags: indicates if this is a priority (MEM_PRI) allocation
217 * @handle: used to return the DMA-mapped address of the mbuf
218 *
219 * Description: Allocates a DMA-mapped buffer from the lpfc_mbuf_pool PCI pool.
220 * Allocates from generic pci_pool_alloc function first and if that fails and
221 * mem_flags has MEM_PRI set (the only defined flag), returns an mbuf from the
222 * HBA's pool.
223 *
224 * Notes: Not interrupt-safe. Must be called with no locks held. Takes
225 * phba->hbalock.
226 *
227 * Returns:
228 * pointer to the allocated mbuf on success
229 * NULL on failure
230 **/
190void * 231void *
191lpfc_mbuf_alloc(struct lpfc_hba *phba, int mem_flags, dma_addr_t *handle) 232lpfc_mbuf_alloc(struct lpfc_hba *phba, int mem_flags, dma_addr_t *handle)
192{ 233{
@@ -206,6 +247,20 @@ lpfc_mbuf_alloc(struct lpfc_hba *phba, int mem_flags, dma_addr_t *handle)
206 return ret; 247 return ret;
207} 248}
208 249
250/**
251 * __lpfc_mem_free: Free an mbuf from the lpfc_mbuf_pool PCI pool (locked)
252 * @phba: HBA which owns the pool to return to
253 * @virt: mbuf to free
254 * @dma: the DMA-mapped address of the lpfc_mbuf_pool to be freed
255 *
256 * Description: Returns an mbuf lpfc_mbuf_pool to the lpfc_mbuf_safety_pool if
257 * it is below its max_count, frees the mbuf otherwise.
258 *
259 * Notes: Must be called with phba->hbalock held to synchronize access to
260 * lpfc_mbuf_safety_pool.
261 *
262 * Returns: None
263 **/
209void 264void
210__lpfc_mbuf_free(struct lpfc_hba * phba, void *virt, dma_addr_t dma) 265__lpfc_mbuf_free(struct lpfc_hba * phba, void *virt, dma_addr_t dma)
211{ 266{
@@ -221,7 +276,21 @@ __lpfc_mbuf_free(struct lpfc_hba * phba, void *virt, dma_addr_t dma)
221 return; 276 return;
222} 277}
223 278
279/**
280 * lpfc_mem_free: Free an mbuf from the lpfc_mbuf_pool PCI pool (unlocked)
281 * @phba: HBA which owns the pool to return to
282 * @virt: mbuf to free
283 * @dma: the DMA-mapped address of the lpfc_mbuf_pool to be freed
284 *
285 * Description: Returns an mbuf lpfc_mbuf_pool to the lpfc_mbuf_safety_pool if
286 * it is below its max_count, frees the mbuf otherwise.
287 *
288 * Notes: Takes phba->hbalock. Can be called with or without other locks held.
289 *
290 * Returns: None
291 **/
224void 292void
293
225lpfc_mbuf_free(struct lpfc_hba * phba, void *virt, dma_addr_t dma) 294lpfc_mbuf_free(struct lpfc_hba * phba, void *virt, dma_addr_t dma)
226{ 295{
227 unsigned long iflags; 296 unsigned long iflags;
@@ -232,6 +301,19 @@ lpfc_mbuf_free(struct lpfc_hba * phba, void *virt, dma_addr_t dma)
232 return; 301 return;
233} 302}
234 303
304/**
305 * lpfc_els_hbq_alloc: Allocate an HBQ buffer
306 * @phba: HBA to allocate HBQ buffer for
307 *
308 * Description: Allocates a DMA-mapped HBQ buffer from the lpfc_hbq_pool PCI
309 * pool along a non-DMA-mapped container for it.
310 *
311 * Notes: Not interrupt-safe. Must be called with no locks held.
312 *
313 * Returns:
314 * pointer to HBQ on success
315 * NULL on failure
316 **/
235struct hbq_dmabuf * 317struct hbq_dmabuf *
236lpfc_els_hbq_alloc(struct lpfc_hba *phba) 318lpfc_els_hbq_alloc(struct lpfc_hba *phba)
237{ 319{
@@ -251,6 +333,18 @@ lpfc_els_hbq_alloc(struct lpfc_hba *phba)
251 return hbqbp; 333 return hbqbp;
252} 334}
253 335
336/**
337 * lpfc_mem_hbq_free: Frees an HBQ buffer allocated with lpfc_els_hbq_alloc
338 * @phba: HBA buffer was allocated for
339 * @hbqbp: HBQ container returned by lpfc_els_hbq_alloc
340 *
341 * Description: Frees both the container and the DMA-mapped buffer returned by
342 * lpfc_els_hbq_alloc.
343 *
344 * Notes: Can be called with or without locks held.
345 *
346 * Returns: None
347 **/
254void 348void
255lpfc_els_hbq_free(struct lpfc_hba *phba, struct hbq_dmabuf *hbqbp) 349lpfc_els_hbq_free(struct lpfc_hba *phba, struct hbq_dmabuf *hbqbp)
256{ 350{
@@ -259,7 +353,18 @@ lpfc_els_hbq_free(struct lpfc_hba *phba, struct hbq_dmabuf *hbqbp)
259 return; 353 return;
260} 354}
261 355
262/* This is ONLY called for the LPFC_ELS_HBQ */ 356/**
357 * lpfc_in_buf_free: Free a DMA buffer
358 * @phba: HBA buffer is associated with
359 * @mp: Buffer to free
360 *
361 * Description: Frees the given DMA buffer in the appropriate way given if the
362 * HBA is running in SLI3 mode with HBQs enabled.
363 *
364 * Notes: Takes phba->hbalock. Can be called with or without other locks held.
365 *
366 * Returns: None
367 **/
263void 368void
264lpfc_in_buf_free(struct lpfc_hba *phba, struct lpfc_dmabuf *mp) 369lpfc_in_buf_free(struct lpfc_hba *phba, struct lpfc_dmabuf *mp)
265{ 370{
diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
index 50fe07646738..3cf488496d86 100644
--- a/drivers/scsi/lpfc/lpfc_sli.c
+++ b/drivers/scsi/lpfc/lpfc_sli.c
@@ -66,10 +66,16 @@ typedef enum _lpfc_iocb_type {
66 LPFC_ABORT_IOCB 66 LPFC_ABORT_IOCB
67} lpfc_iocb_type; 67} lpfc_iocb_type;
68 68
69 /* SLI-2/SLI-3 provide different sized iocbs. Given a pointer 69/**
70 * to the start of the ring, and the slot number of the 70 * lpfc_cmd_iocb: Get next command iocb entry in the ring.
71 * desired iocb entry, calc a pointer to that entry. 71 * @phba: Pointer to HBA context object.
72 */ 72 * @pring: Pointer to driver SLI ring object.
73 *
74 * This function returns pointer to next command iocb entry
75 * in the command ring. The caller must hold hbalock to prevent
76 * other threads consume the next command iocb.
77 * SLI-2/SLI-3 provide different sized iocbs.
78 **/
73static inline IOCB_t * 79static inline IOCB_t *
74lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) 80lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
75{ 81{
@@ -77,6 +83,16 @@ lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
77 pring->cmdidx * phba->iocb_cmd_size); 83 pring->cmdidx * phba->iocb_cmd_size);
78} 84}
79 85
86/**
87 * lpfc_resp_iocb: Get next response iocb entry in the ring.
88 * @phba: Pointer to HBA context object.
89 * @pring: Pointer to driver SLI ring object.
90 *
91 * This function returns pointer to next response iocb entry
92 * in the response ring. The caller must hold hbalock to make sure
93 * that no other thread consume the next response iocb.
94 * SLI-2/SLI-3 provide different sized iocbs.
95 **/
80static inline IOCB_t * 96static inline IOCB_t *
81lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) 97lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
82{ 98{
@@ -84,6 +100,15 @@ lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
84 pring->rspidx * phba->iocb_rsp_size); 100 pring->rspidx * phba->iocb_rsp_size);
85} 101}
86 102
103/**
104 * __lpfc_sli_get_iocbq: Allocates an iocb object from iocb pool.
105 * @phba: Pointer to HBA context object.
106 *
107 * This function is called with hbalock held. This function
108 * allocates a new driver iocb object from the iocb pool. If the
109 * allocation is successful, it returns pointer to the newly
110 * allocated iocb object else it returns NULL.
111 **/
87static struct lpfc_iocbq * 112static struct lpfc_iocbq *
88__lpfc_sli_get_iocbq(struct lpfc_hba *phba) 113__lpfc_sli_get_iocbq(struct lpfc_hba *phba)
89{ 114{
@@ -94,6 +119,15 @@ __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
94 return iocbq; 119 return iocbq;
95} 120}
96 121
122/**
123 * lpfc_sli_get_iocbq: Allocates an iocb object from iocb pool.
124 * @phba: Pointer to HBA context object.
125 *
126 * This function is called with no lock held. This function
127 * allocates a new driver iocb object from the iocb pool. If the
128 * allocation is successful, it returns pointer to the newly
129 * allocated iocb object else it returns NULL.
130 **/
97struct lpfc_iocbq * 131struct lpfc_iocbq *
98lpfc_sli_get_iocbq(struct lpfc_hba *phba) 132lpfc_sli_get_iocbq(struct lpfc_hba *phba)
99{ 133{
@@ -106,6 +140,16 @@ lpfc_sli_get_iocbq(struct lpfc_hba *phba)
106 return iocbq; 140 return iocbq;
107} 141}
108 142
143/**
144 * __lpfc_sli_release_iocbq: Release iocb to the iocb pool.
145 * @phba: Pointer to HBA context object.
146 * @iocbq: Pointer to driver iocb object.
147 *
148 * This function is called with hbalock held to release driver
149 * iocb object to the iocb pool. The iotag in the iocb object
150 * does not change for each use of the iocb object. This function
151 * clears all other fields of the iocb object when it is freed.
152 **/
109static void 153static void
110__lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) 154__lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
111{ 155{
@@ -118,6 +162,14 @@ __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
118 list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); 162 list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
119} 163}
120 164
165/**
166 * lpfc_sli_release_iocbq: Release iocb to the iocb pool.
167 * @phba: Pointer to HBA context object.
168 * @iocbq: Pointer to driver iocb object.
169 *
170 * This function is called with no lock held to release the iocb to
171 * iocb pool.
172 **/
121void 173void
122lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) 174lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
123{ 175{
@@ -131,10 +183,21 @@ lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
131 spin_unlock_irqrestore(&phba->hbalock, iflags); 183 spin_unlock_irqrestore(&phba->hbalock, iflags);
132} 184}
133 185
134/* 186/**
135 * Translate the iocb command to an iocb command type used to decide the final 187 * lpfc_sli_iocb_cmd_type: Get the iocb type.
136 * disposition of each completed IOCB. 188 * @iocb_cmnd : iocb command code.
137 */ 189 *
190 * This function is called by ring event handler function to get the iocb type.
191 * This function translates the iocb command to an iocb command type used to
192 * decide the final disposition of each completed IOCB.
193 * The function returns
194 * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
195 * LPFC_SOL_IOCB if it is a solicited iocb completion
196 * LPFC_ABORT_IOCB if it is an abort iocb
197 * LPFC_UNSOL_IOCB if it is an unsolicited iocb
198 *
199 * The caller is not required to hold any lock.
200 **/
138static lpfc_iocb_type 201static lpfc_iocb_type
139lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) 202lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
140{ 203{
@@ -230,6 +293,17 @@ lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
230 return type; 293 return type;
231} 294}
232 295
296/**
297 * lpfc_sli_ring_map: Issue config_ring mbox for all rings.
298 * @phba: Pointer to HBA context object.
299 *
300 * This function is called from SLI initialization code
301 * to configure every ring of the HBA's SLI interface. The
302 * caller is not required to hold any lock. This function issues
303 * a config_ring mailbox command for each ring.
304 * This function returns zero if successful else returns a negative
305 * error code.
306 **/
233static int 307static int
234lpfc_sli_ring_map(struct lpfc_hba *phba) 308lpfc_sli_ring_map(struct lpfc_hba *phba)
235{ 309{
@@ -262,6 +336,18 @@ lpfc_sli_ring_map(struct lpfc_hba *phba)
262 return ret; 336 return ret;
263} 337}
264 338
339/**
340 * lpfc_sli_ringtxcmpl_put: Adds new iocb to the txcmplq.
341 * @phba: Pointer to HBA context object.
342 * @pring: Pointer to driver SLI ring object.
343 * @piocb: Pointer to the driver iocb object.
344 *
345 * This function is called with hbalock held. The function adds the
346 * new iocb to txcmplq of the given ring. This function always returns
347 * 0. If this function is called for ELS ring, this function checks if
348 * there is a vport associated with the ELS command. This function also
349 * starts els_tmofunc timer if this is an ELS command.
350 **/
265static int 351static int
266lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 352lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
267 struct lpfc_iocbq *piocb) 353 struct lpfc_iocbq *piocb)
@@ -282,6 +368,16 @@ lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
282 return 0; 368 return 0;
283} 369}
284 370
371/**
372 * lpfc_sli_ringtx_get: Get first element of the txq.
373 * @phba: Pointer to HBA context object.
374 * @pring: Pointer to driver SLI ring object.
375 *
376 * This function is called with hbalock held to get next
377 * iocb in txq of the given ring. If there is any iocb in
378 * the txq, the function returns first iocb in the list after
379 * removing the iocb from the list, else it returns NULL.
380 **/
285static struct lpfc_iocbq * 381static struct lpfc_iocbq *
286lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) 382lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
287{ 383{
@@ -293,6 +389,20 @@ lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
293 return cmd_iocb; 389 return cmd_iocb;
294} 390}
295 391
392/**
393 * lpfc_sli_next_iocb_slot: Get next iocb slot in the ring.
394 * @phba: Pointer to HBA context object.
395 * @pring: Pointer to driver SLI ring object.
396 *
397 * This function is called with hbalock held and the caller must post the
398 * iocb without releasing the lock. If the caller releases the lock,
399 * iocb slot returned by the function is not guaranteed to be available.
400 * The function returns pointer to the next available iocb slot if there
401 * is available slot in the ring, else it returns NULL.
402 * If the get index of the ring is ahead of the put index, the function
403 * will post an error attention event to the worker thread to take the
404 * HBA to offline state.
405 **/
296static IOCB_t * 406static IOCB_t *
297lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) 407lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
298{ 408{
@@ -336,6 +446,18 @@ lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
336 return lpfc_cmd_iocb(phba, pring); 446 return lpfc_cmd_iocb(phba, pring);
337} 447}
338 448
449/**
450 * lpfc_sli_next_iotag: Get an iotag for the iocb.
451 * @phba: Pointer to HBA context object.
452 * @iocbq: Pointer to driver iocb object.
453 *
454 * This function gets an iotag for the iocb. If there is no unused iotag and
455 * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
456 * array and assigns a new iotag.
457 * The function returns the allocated iotag if successful, else returns zero.
458 * Zero is not a valid iotag.
459 * The caller is not required to hold any lock.
460 **/
339uint16_t 461uint16_t
340lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) 462lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
341{ 463{
@@ -399,6 +521,20 @@ lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
399 return 0; 521 return 0;
400} 522}
401 523
524/**
525 * lpfc_sli_submit_iocb: Submit an iocb to the firmware.
526 * @phba: Pointer to HBA context object.
527 * @pring: Pointer to driver SLI ring object.
528 * @iocb: Pointer to iocb slot in the ring.
529 * @nextiocb: Pointer to driver iocb object which need to be
530 * posted to firmware.
531 *
532 * This function is called with hbalock held to post a new iocb to
533 * the firmware. This function copies the new iocb to ring iocb slot and
534 * updates the ring pointers. It adds the new iocb to txcmplq if there is
535 * a completion call back for this iocb else the function will free the
536 * iocb object.
537 **/
402static void 538static void
403lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 539lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
404 IOCB_t *iocb, struct lpfc_iocbq *nextiocb) 540 IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
@@ -441,6 +577,18 @@ lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
441 writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); 577 writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
442} 578}
443 579
580/**
581 * lpfc_sli_update_full_ring: Update the chip attention register.
582 * @phba: Pointer to HBA context object.
583 * @pring: Pointer to driver SLI ring object.
584 *
585 * The caller is not required to hold any lock for calling this function.
586 * This function updates the chip attention bits for the ring to inform firmware
587 * that there are pending work to be done for this ring and requests an
588 * interrupt when there is space available in the ring. This function is
589 * called when the driver is unable to post more iocbs to the ring due
590 * to unavailability of space in the ring.
591 **/
444static void 592static void
445lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) 593lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
446{ 594{
@@ -460,6 +608,15 @@ lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
460 pring->stats.iocb_cmd_full++; 608 pring->stats.iocb_cmd_full++;
461} 609}
462 610
611/**
612 * lpfc_sli_update_ring: Update chip attention register.
613 * @phba: Pointer to HBA context object.
614 * @pring: Pointer to driver SLI ring object.
615 *
616 * This function updates the chip attention register bit for the
617 * given ring to inform HBA that there is more work to be done
618 * in this ring. The caller is not required to hold any lock.
619 **/
463static void 620static void
464lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) 621lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
465{ 622{
@@ -473,6 +630,15 @@ lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
473 readl(phba->CAregaddr); /* flush */ 630 readl(phba->CAregaddr); /* flush */
474} 631}
475 632
633/**
634 * lpfc_sli_resume_iocb: Process iocbs in the txq.
635 * @phba: Pointer to HBA context object.
636 * @pring: Pointer to driver SLI ring object.
637 *
638 * This function is called with hbalock held to post pending iocbs
639 * in the txq to the firmware. This function is called when driver
640 * detects space available in the ring.
641 **/
476static void 642static void
477lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) 643lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
478{ 644{
@@ -504,6 +670,16 @@ lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
504 return; 670 return;
505} 671}
506 672
673/**
674 * lpfc_sli_next_hbq_slot: Get next hbq entry for the HBQ.
675 * @phba: Pointer to HBA context object.
676 * @hbqno: HBQ number.
677 *
678 * This function is called with hbalock held to get the next
679 * available slot for the given HBQ. If there is free slot
680 * available for the HBQ it will return pointer to the next available
681 * HBQ entry else it will return NULL.
682 **/
507static struct lpfc_hbq_entry * 683static struct lpfc_hbq_entry *
508lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) 684lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
509{ 685{
@@ -539,6 +715,15 @@ lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
539 hbqp->hbqPutIdx; 715 hbqp->hbqPutIdx;
540} 716}
541 717
718/**
719 * lpfc_sli_hbqbuf_free_all: Free all the hbq buffers.
720 * @phba: Pointer to HBA context object.
721 *
722 * This function is called with no lock held to free all the
723 * hbq buffers while uninitializing the SLI interface. It also
724 * frees the HBQ buffers returned by the firmware but not yet
725 * processed by the upper layers.
726 **/
542void 727void
543lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) 728lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
544{ 729{
@@ -584,6 +769,18 @@ lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
584 spin_unlock_irqrestore(&phba->hbalock, flags); 769 spin_unlock_irqrestore(&phba->hbalock, flags);
585} 770}
586 771
772/**
773 * lpfc_sli_hbq_to_firmware: Post the hbq buffer to firmware.
774 * @phba: Pointer to HBA context object.
775 * @hbqno: HBQ number.
776 * @hbq_buf: Pointer to HBQ buffer.
777 *
778 * This function is called with the hbalock held to post a
779 * hbq buffer to the firmware. If the function finds an empty
780 * slot in the HBQ, it will post the buffer. The function will return
781 * pointer to the hbq entry if it successfully post the buffer
782 * else it will return NULL.
783 **/
587static struct lpfc_hbq_entry * 784static struct lpfc_hbq_entry *
588lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, 785lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
589 struct hbq_dmabuf *hbq_buf) 786 struct hbq_dmabuf *hbq_buf)
@@ -612,6 +809,7 @@ lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
612 return hbqe; 809 return hbqe;
613} 810}
614 811
812/* HBQ for ELS and CT traffic. */
615static struct lpfc_hbq_init lpfc_els_hbq = { 813static struct lpfc_hbq_init lpfc_els_hbq = {
616 .rn = 1, 814 .rn = 1,
617 .entry_count = 200, 815 .entry_count = 200,
@@ -623,6 +821,7 @@ static struct lpfc_hbq_init lpfc_els_hbq = {
623 .add_count = 5, 821 .add_count = 5,
624}; 822};
625 823
824/* HBQ for the extra ring if needed */
626static struct lpfc_hbq_init lpfc_extra_hbq = { 825static struct lpfc_hbq_init lpfc_extra_hbq = {
627 .rn = 1, 826 .rn = 1,
628 .entry_count = 200, 827 .entry_count = 200,
@@ -634,11 +833,22 @@ static struct lpfc_hbq_init lpfc_extra_hbq = {
634 .add_count = 5, 833 .add_count = 5,
635}; 834};
636 835
836/* Array of HBQs */
637struct lpfc_hbq_init *lpfc_hbq_defs[] = { 837struct lpfc_hbq_init *lpfc_hbq_defs[] = {
638 &lpfc_els_hbq, 838 &lpfc_els_hbq,
639 &lpfc_extra_hbq, 839 &lpfc_extra_hbq,
640}; 840};
641 841
842/**
843 * lpfc_sli_hbqbuf_fill_hbqs: Post more hbq buffers to HBQ.
844 * @phba: Pointer to HBA context object.
845 * @hbqno: HBQ number.
846 * @count: Number of HBQ buffers to be posted.
847 *
848 * This function is called with no lock held to post more
849 * hbq buffers to the given HBQ. The function returns 0
850 * when successful and returns 1 other wise.
851 **/
642static int 852static int
643lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) 853lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
644{ 854{
@@ -679,6 +889,15 @@ lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
679 return 1; 889 return 1;
680} 890}
681 891
892/**
893 * lpfc_sli_hbqbuf_add_hbqs: Post more HBQ buffers to firmware.
894 * @phba: Pointer to HBA context object.
895 * @qno: HBQ number.
896 *
897 * This function posts more buffers to the HBQ. This function
898 * is called with no lock held. The function returns 0 when
899 * successful and returns 1 otherwise.
900 **/
682int 901int
683lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) 902lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
684{ 903{
@@ -686,6 +905,15 @@ lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
686 lpfc_hbq_defs[qno]->add_count)); 905 lpfc_hbq_defs[qno]->add_count));
687} 906}
688 907
908/**
909 * lpfc_sli_hbqbuf_init_hbqs: Post initial buffers to the HBQ.
910 * @phba: Pointer to HBA context object.
911 * @qno: HBQ queue number.
912 *
913 * This function is called from SLI initialization code path with
914 * no lock held to post initial HBQ buffers to firmware. The
915 * function returns 0 when successful and returns 1 otherwise.
916 **/
689static int 917static int
690lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) 918lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
691{ 919{
@@ -693,6 +921,16 @@ lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
693 lpfc_hbq_defs[qno]->init_count)); 921 lpfc_hbq_defs[qno]->init_count));
694} 922}
695 923
924/**
925 * lpfc_sli_hbqbuf_find: Find the hbq buffer associated with a tag.
926 * @phba: Pointer to HBA context object.
927 * @tag: Tag of the hbq buffer.
928 *
929 * This function is called with hbalock held. This function searches
930 * for the hbq buffer associated with the given tag in the hbq buffer
931 * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
932 * it returns NULL.
933 **/
696static struct hbq_dmabuf * 934static struct hbq_dmabuf *
697lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) 935lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
698{ 936{
@@ -716,6 +954,15 @@ lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
716 return NULL; 954 return NULL;
717} 955}
718 956
957/**
958 * lpfc_sli_free_hbq: Give back the hbq buffer to firmware.
959 * @phba: Pointer to HBA context object.
960 * @hbq_buffer: Pointer to HBQ buffer.
961 *
962 * This function is called with hbalock. This function gives back
963 * the hbq buffer to firmware. If the HBQ does not have space to
964 * post the buffer, it will free the buffer.
965 **/
719void 966void
720lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer) 967lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
721{ 968{
@@ -729,6 +976,15 @@ lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
729 } 976 }
730} 977}
731 978
979/**
980 * lpfc_sli_chk_mbx_command: Check if the mailbox is a legitimate mailbox.
981 * @mbxCommand: mailbox command code.
982 *
983 * This function is called by the mailbox event handler function to verify
984 * that the completed mailbox command is a legitimate mailbox command. If the
985 * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
986 * and the mailbox event handler will take the HBA offline.
987 **/
732static int 988static int
733lpfc_sli_chk_mbx_command(uint8_t mbxCommand) 989lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
734{ 990{
@@ -793,6 +1049,19 @@ lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
793 } 1049 }
794 return ret; 1050 return ret;
795} 1051}
1052
1053/**
1054 * lpfc_sli_wake_mbox_wait: Completion handler for mbox issued from
1055 * lpfc_sli_issue_mbox_wait.
1056 * @phba: Pointer to HBA context object.
1057 * @pmboxq: Pointer to mailbox command.
1058 *
1059 * This is completion handler function for mailbox commands issued from
1060 * lpfc_sli_issue_mbox_wait function. This function is called by the
1061 * mailbox event handler function with no lock held. This function
1062 * will wake up thread waiting on the wait queue pointed by context1
1063 * of the mailbox.
1064 **/
796static void 1065static void
797lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) 1066lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
798{ 1067{
@@ -812,6 +1081,17 @@ lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
812 return; 1081 return;
813} 1082}
814 1083
1084
1085/**
1086 * lpfc_sli_def_mbox_cmpl: Default mailbox completion handler.
1087 * @phba: Pointer to HBA context object.
1088 * @pmb: Pointer to mailbox object.
1089 *
1090 * This function is the default mailbox completion handler. It
1091 * frees the memory resources associated with the completed mailbox
1092 * command. If the completed command is a REG_LOGIN mailbox command,
1093 * this function will issue a UREG_LOGIN to re-claim the RPI.
1094 **/
815void 1095void
816lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) 1096lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
817{ 1097{
@@ -846,6 +1126,19 @@ lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
846 return; 1126 return;
847} 1127}
848 1128
1129/**
1130 * lpfc_sli_handle_mb_event: Handle mailbox completions from firmware.
1131 * @phba: Pointer to HBA context object.
1132 *
1133 * This function is called with no lock held. This function processes all
1134 * the completed mailbox commands and gives it to upper layers. The interrupt
1135 * service routine processes mailbox completion interrupt and adds completed
1136 * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
1137 * Worker thread call lpfc_sli_handle_mb_event, which will return the
1138 * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
1139 * function returns the mailbox commands to the upper layer by calling the
1140 * completion handler function of each mailbox.
1141 **/
849int 1142int
850lpfc_sli_handle_mb_event(struct lpfc_hba *phba) 1143lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
851{ 1144{
@@ -953,6 +1246,16 @@ lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
953 return 0; 1246 return 0;
954} 1247}
955 1248
1249/**
1250 * lpfc_sli_replace_hbqbuff: Replace the HBQ buffer with a new buffer.
1251 * @phba: Pointer to HBA context object.
1252 * @tag: Tag for the HBQ buffer.
1253 *
1254 * This function is called from unsolicited event handler code path to get the
1255 * HBQ buffer associated with an unsolicited iocb. This function is called with
1256 * no lock held. It returns the buffer associated with the given tag and posts
1257 * another buffer to the firmware.
1258 **/
956static struct lpfc_dmabuf * 1259static struct lpfc_dmabuf *
957lpfc_sli_replace_hbqbuff(struct lpfc_hba *phba, uint32_t tag) 1260lpfc_sli_replace_hbqbuff(struct lpfc_hba *phba, uint32_t tag)
958{ 1261{
@@ -997,6 +1300,18 @@ lpfc_sli_replace_hbqbuff(struct lpfc_hba *phba, uint32_t tag)
997 return &new_hbq_entry->dbuf; 1300 return &new_hbq_entry->dbuf;
998} 1301}
999 1302
1303/**
1304 * lpfc_sli_get_buff: Get the buffer associated with the buffer tag.
1305 * @phba: Pointer to HBA context object.
1306 * @pring: Pointer to driver SLI ring object.
1307 * @tag: buffer tag.
1308 *
1309 * This function is called with no lock held. When QUE_BUFTAG_BIT bit
1310 * is set in the tag the buffer is posted for a particular exchange,
1311 * the function will return the buffer without replacing the buffer.
1312 * If the buffer is for unsolicited ELS or CT traffic, this function
1313 * returns the buffer and also posts another buffer to the firmware.
1314 **/
1000static struct lpfc_dmabuf * 1315static struct lpfc_dmabuf *
1001lpfc_sli_get_buff(struct lpfc_hba *phba, 1316lpfc_sli_get_buff(struct lpfc_hba *phba,
1002 struct lpfc_sli_ring *pring, 1317 struct lpfc_sli_ring *pring,
@@ -1008,6 +1323,21 @@ lpfc_sli_get_buff(struct lpfc_hba *phba,
1008 return lpfc_sli_replace_hbqbuff(phba, tag); 1323 return lpfc_sli_replace_hbqbuff(phba, tag);
1009} 1324}
1010 1325
1326
1327/**
1328 * lpfc_sli_process_unsol_iocb: Unsolicited iocb handler.
1329 * @phba: Pointer to HBA context object.
1330 * @pring: Pointer to driver SLI ring object.
1331 * @saveq: Pointer to the unsolicited iocb.
1332 *
1333 * This function is called with no lock held by the ring event handler
1334 * when there is an unsolicited iocb posted to the response ring by the
1335 * firmware. This function gets the buffer associated with the iocbs
1336 * and calls the event handler for the ring. This function handles both
1337 * qring buffers and hbq buffers.
1338 * When the function returns 1 the caller can free the iocb object otherwise
1339 * upper layer functions will free the iocb objects.
1340 **/
1011static int 1341static int
1012lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 1342lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1013 struct lpfc_iocbq *saveq) 1343 struct lpfc_iocbq *saveq)
@@ -1192,6 +1522,18 @@ lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1192 return 1; 1522 return 1;
1193} 1523}
1194 1524
1525/**
1526 * lpfc_sli_iocbq_lookup: Find command iocb for the given response iocb.
1527 * @phba: Pointer to HBA context object.
1528 * @pring: Pointer to driver SLI ring object.
1529 * @prspiocb: Pointer to response iocb object.
1530 *
1531 * This function looks up the iocb_lookup table to get the command iocb
1532 * corresponding to the given response iocb using the iotag of the
1533 * response iocb. This function is called with the hbalock held.
1534 * This function returns the command iocb object if it finds the command
1535 * iocb else returns NULL.
1536 **/
1195static struct lpfc_iocbq * 1537static struct lpfc_iocbq *
1196lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, 1538lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
1197 struct lpfc_sli_ring *pring, 1539 struct lpfc_sli_ring *pring,
@@ -1217,6 +1559,23 @@ lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
1217 return NULL; 1559 return NULL;
1218} 1560}
1219 1561
1562/**
1563 * lpfc_sli_process_sol_iocb: process solicited iocb completion.
1564 * @phba: Pointer to HBA context object.
1565 * @pring: Pointer to driver SLI ring object.
1566 * @saveq: Pointer to the response iocb to be processed.
1567 *
1568 * This function is called by the ring event handler for non-fcp
1569 * rings when there is a new response iocb in the response ring.
1570 * The caller is not required to hold any locks. This function
1571 * gets the command iocb associated with the response iocb and
1572 * calls the completion handler for the command iocb. If there
1573 * is no completion handler, the function will free the resources
1574 * associated with command iocb. If the response iocb is for
1575 * an already aborted command iocb, the status of the completion
1576 * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
1577 * This function always returns 1.
1578 **/
1220static int 1579static int
1221lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 1580lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1222 struct lpfc_iocbq *saveq) 1581 struct lpfc_iocbq *saveq)
@@ -1282,6 +1641,16 @@ lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1282 return rc; 1641 return rc;
1283} 1642}
1284 1643
1644/**
1645 * lpfc_sli_rsp_pointers_error: Response ring pointer error handler.
1646 * @phba: Pointer to HBA context object.
1647 * @pring: Pointer to driver SLI ring object.
1648 *
1649 * This function is called from the iocb ring event handlers when
1650 * put pointer is ahead of the get pointer for a ring. This function signal
1651 * an error attention condition to the worker thread and the worker
1652 * thread will transition the HBA to offline state.
1653 **/
1285static void 1654static void
1286lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) 1655lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1287{ 1656{
@@ -1312,6 +1681,21 @@ lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1312 return; 1681 return;
1313} 1682}
1314 1683
1684/**
1685 * lpfc_sli_poll_fcp_ring: Handle FCP ring completion in polling mode.
1686 * @phba: Pointer to HBA context object.
1687 *
1688 * This function is called from lpfc_queuecommand, lpfc_poll_timeout,
1689 * lpfc_abort_handler and lpfc_slave_configure when FCP_RING_POLLING
1690 * is enabled.
1691 *
1692 * The caller does not hold any lock.
1693 * The function processes each response iocb in the response ring until it
1694 * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
1695 * LE bit set. The function will call the completion handler of the command iocb
1696 * if the response iocb indicates a completion for a command iocb or it is
1697 * an abort completion.
1698 **/
1315void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba) 1699void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba)
1316{ 1700{
1317 struct lpfc_sli *psli = &phba->sli; 1701 struct lpfc_sli *psli = &phba->sli;
@@ -1465,10 +1849,23 @@ void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba)
1465 return; 1849 return;
1466} 1850}
1467 1851
1468/* 1852/**
1853 * lpfc_sli_handle_fast_ring_event: Handle ring events on FCP ring.
1854 * @phba: Pointer to HBA context object.
1855 * @pring: Pointer to driver SLI ring object.
1856 * @mask: Host attention register mask for this ring.
1857 *
1858 * This function is called from the interrupt context when there is a ring
1859 * event for the fcp ring. The caller does not hold any lock.
1860 * The function processes each response iocb in the response ring until it
1861 * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
1862 * LE bit set. The function will call the completion handler of the command iocb
1863 * if the response iocb indicates a completion for a command iocb or it is
1864 * an abort completion. The function will call lpfc_sli_process_unsol_iocb
1865 * function if this is an unsolicited iocb.
1469 * This routine presumes LPFC_FCP_RING handling and doesn't bother 1866 * This routine presumes LPFC_FCP_RING handling and doesn't bother
1470 * to check it explicitly. 1867 * to check it explicitly. This function always returns 1.
1471 */ 1868 **/
1472static int 1869static int
1473lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, 1870lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
1474 struct lpfc_sli_ring *pring, uint32_t mask) 1871 struct lpfc_sli_ring *pring, uint32_t mask)
@@ -1646,6 +2043,23 @@ lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
1646 return rc; 2043 return rc;
1647} 2044}
1648 2045
2046/**
2047 * lpfc_sli_handle_slow_ring_event: Handle ring events for non-FCP rings.
2048 * @phba: Pointer to HBA context object.
2049 * @pring: Pointer to driver SLI ring object.
2050 * @mask: Host attention register mask for this ring.
2051 *
2052 * This function is called from the worker thread when there is a ring
2053 * event for non-fcp rings. The caller does not hold any lock .
2054 * The function processes each response iocb in the response ring until it
2055 * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
2056 * LE bit set. The function will call lpfc_sli_process_sol_iocb function if the
2057 * response iocb indicates a completion of a command iocb. The function
2058 * will call lpfc_sli_process_unsol_iocb function if this is an unsolicited
2059 * iocb. The function frees the resources or calls the completion handler if
2060 * this iocb is an abort completion. The function returns 0 when the allocated
2061 * iocbs are not freed, otherwise returns 1.
2062 **/
1649int 2063int
1650lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, 2064lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
1651 struct lpfc_sli_ring *pring, uint32_t mask) 2065 struct lpfc_sli_ring *pring, uint32_t mask)
@@ -1904,6 +2318,16 @@ lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
1904 return rc; 2318 return rc;
1905} 2319}
1906 2320
2321/**
2322 * lpfc_sli_abort_iocb_ring: Abort all iocbs in the ring.
2323 * @phba: Pointer to HBA context object.
2324 * @pring: Pointer to driver SLI ring object.
2325 *
2326 * This function aborts all iocbs in the given ring and frees all the iocb
2327 * objects in txq. This function issues an abort iocb for all the iocb commands
2328 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
2329 * the return of this function. The caller is not required to hold any locks.
2330 **/
1907void 2331void
1908lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) 2332lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1909{ 2333{
@@ -1943,6 +2367,19 @@ lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1943 } 2367 }
1944} 2368}
1945 2369
2370/**
2371 * lpfc_sli_brdready: Check for host status bits.
2372 * @phba: Pointer to HBA context object.
2373 * @mask: Bit mask to be checked.
2374 *
2375 * This function reads the host status register and compares
2376 * with the provided bit mask to check if HBA completed
2377 * the restart. This function will wait in a loop for the
2378 * HBA to complete restart. If the HBA does not restart within
2379 * 15 iterations, the function will reset the HBA again. The
2380 * function returns 1 when HBA fail to restart otherwise returns
2381 * zero.
2382 **/
1946int 2383int
1947lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) 2384lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
1948{ 2385{
@@ -1990,6 +2427,13 @@ lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
1990 2427
1991#define BARRIER_TEST_PATTERN (0xdeadbeef) 2428#define BARRIER_TEST_PATTERN (0xdeadbeef)
1992 2429
2430/**
2431 * lpfc_reset_barrier: Make HBA ready for HBA reset.
2432 * @phba: Pointer to HBA context object.
2433 *
2434 * This function is called before resetting an HBA. This
2435 * function requests HBA to quiesce DMAs before a reset.
2436 **/
1993void lpfc_reset_barrier(struct lpfc_hba *phba) 2437void lpfc_reset_barrier(struct lpfc_hba *phba)
1994{ 2438{
1995 uint32_t __iomem *resp_buf; 2439 uint32_t __iomem *resp_buf;
@@ -2063,6 +2507,17 @@ restore_hc:
2063 readl(phba->HCregaddr); /* flush */ 2507 readl(phba->HCregaddr); /* flush */
2064} 2508}
2065 2509
2510/**
2511 * lpfc_sli_brdkill: Issue a kill_board mailbox command.
2512 * @phba: Pointer to HBA context object.
2513 *
2514 * This function issues a kill_board mailbox command and waits for
2515 * the error attention interrupt. This function is called for stopping
2516 * the firmware processing. The caller is not required to hold any
2517 * locks. This function calls lpfc_hba_down_post function to free
2518 * any pending commands after the kill. The function will return 1 when it
2519 * fails to kill the board else will return 0.
2520 **/
2066int 2521int
2067lpfc_sli_brdkill(struct lpfc_hba *phba) 2522lpfc_sli_brdkill(struct lpfc_hba *phba)
2068{ 2523{
@@ -2139,6 +2594,17 @@ lpfc_sli_brdkill(struct lpfc_hba *phba)
2139 return ha_copy & HA_ERATT ? 0 : 1; 2594 return ha_copy & HA_ERATT ? 0 : 1;
2140} 2595}
2141 2596
2597/**
2598 * lpfc_sli_brdreset: Reset the HBA.
2599 * @phba: Pointer to HBA context object.
2600 *
2601 * This function resets the HBA by writing HC_INITFF to the control
2602 * register. After the HBA resets, this function resets all the iocb ring
2603 * indices. This function disables PCI layer parity checking during
2604 * the reset.
2605 * This function returns 0 always.
2606 * The caller is not required to hold any locks.
2607 **/
2142int 2608int
2143lpfc_sli_brdreset(struct lpfc_hba *phba) 2609lpfc_sli_brdreset(struct lpfc_hba *phba)
2144{ 2610{
@@ -2191,6 +2657,19 @@ lpfc_sli_brdreset(struct lpfc_hba *phba)
2191 return 0; 2657 return 0;
2192} 2658}
2193 2659
2660/**
2661 * lpfc_sli_brdrestart: Restart the HBA.
2662 * @phba: Pointer to HBA context object.
2663 *
2664 * This function is called in the SLI initialization code path to
2665 * restart the HBA. The caller is not required to hold any lock.
2666 * This function writes MBX_RESTART mailbox command to the SLIM and
2667 * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
2668 * function to free any pending commands. The function enables
2669 * POST only during the first initialization. The function returns zero.
2670 * The function does not guarantee completion of MBX_RESTART mailbox
2671 * command before the return of this function.
2672 **/
2194int 2673int
2195lpfc_sli_brdrestart(struct lpfc_hba *phba) 2674lpfc_sli_brdrestart(struct lpfc_hba *phba)
2196{ 2675{
@@ -2251,6 +2730,16 @@ lpfc_sli_brdrestart(struct lpfc_hba *phba)
2251 return 0; 2730 return 0;
2252} 2731}
2253 2732
2733/**
2734 * lpfc_sli_chipset_init: Wait for the restart of the HBA after a restart.
2735 * @phba: Pointer to HBA context object.
2736 *
2737 * This function is called after a HBA restart to wait for successful
2738 * restart of the HBA. Successful restart of the HBA is indicated by
2739 * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
2740 * iteration, the function will restart the HBA again. The function returns
2741 * zero if HBA successfully restarted else returns negative error code.
2742 **/
2254static int 2743static int
2255lpfc_sli_chipset_init(struct lpfc_hba *phba) 2744lpfc_sli_chipset_init(struct lpfc_hba *phba)
2256{ 2745{
@@ -2336,12 +2825,25 @@ lpfc_sli_chipset_init(struct lpfc_hba *phba)
2336 return 0; 2825 return 0;
2337} 2826}
2338 2827
2828/**
2829 * lpfc_sli_hbq_count: Get the number of HBQs to be configured.
2830 *
2831 * This function calculates and returns the number of HBQs required to be
2832 * configured.
2833 **/
2339int 2834int
2340lpfc_sli_hbq_count(void) 2835lpfc_sli_hbq_count(void)
2341{ 2836{
2342 return ARRAY_SIZE(lpfc_hbq_defs); 2837 return ARRAY_SIZE(lpfc_hbq_defs);
2343} 2838}
2344 2839
2840/**
2841 * lpfc_sli_hbq_entry_count: Calculate total number of hbq entries.
2842 *
2843 * This function adds the number of hbq entries in every HBQ to get
2844 * the total number of hbq entries required for the HBA and returns
2845 * the total count.
2846 **/
2345static int 2847static int
2346lpfc_sli_hbq_entry_count(void) 2848lpfc_sli_hbq_entry_count(void)
2347{ 2849{
@@ -2354,12 +2856,27 @@ lpfc_sli_hbq_entry_count(void)
2354 return count; 2856 return count;
2355} 2857}
2356 2858
2859/**
2860 * lpfc_sli_hbq_size: Calculate memory required for all hbq entries.
2861 *
2862 * This function calculates amount of memory required for all hbq entries
2863 * to be configured and returns the total memory required.
2864 **/
2357int 2865int
2358lpfc_sli_hbq_size(void) 2866lpfc_sli_hbq_size(void)
2359{ 2867{
2360 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); 2868 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
2361} 2869}
2362 2870
2871/**
2872 * lpfc_sli_hbq_setup: configure and initialize HBQs.
2873 * @phba: Pointer to HBA context object.
2874 *
2875 * This function is called during the SLI initialization to configure
2876 * all the HBQs and post buffers to the HBQ. The caller is not
2877 * required to hold any locks. This function will return zero if successful
2878 * else it will return negative error code.
2879 **/
2363static int 2880static int
2364lpfc_sli_hbq_setup(struct lpfc_hba *phba) 2881lpfc_sli_hbq_setup(struct lpfc_hba *phba)
2365{ 2882{
@@ -2422,6 +2939,19 @@ lpfc_sli_hbq_setup(struct lpfc_hba *phba)
2422 return 0; 2939 return 0;
2423} 2940}
2424 2941
2942/**
2943 * lpfc_do_config_port: Issue config port mailbox command.
2944 * @phba: Pointer to HBA context object.
2945 * @sli_mode: sli mode - 2/3
2946 *
2947 * This function is called by the sli intialization code path
2948 * to issue config_port mailbox command. This function restarts the
2949 * HBA firmware and issues a config_port mailbox command to configure
2950 * the SLI interface in the sli mode specified by sli_mode
2951 * variable. The caller is not required to hold any locks.
2952 * The function returns 0 if successful, else returns negative error
2953 * code.
2954 **/
2425static int 2955static int
2426lpfc_do_config_port(struct lpfc_hba *phba, int sli_mode) 2956lpfc_do_config_port(struct lpfc_hba *phba, int sli_mode)
2427{ 2957{
@@ -2500,6 +3030,20 @@ do_prep_failed:
2500 return rc; 3030 return rc;
2501} 3031}
2502 3032
3033
3034/**
3035 * lpfc_sli_hba_setup: SLI intialization function.
3036 * @phba: Pointer to HBA context object.
3037 *
3038 * This function is the main SLI intialization function. This function
3039 * is called by the HBA intialization code, HBA reset code and HBA
3040 * error attention handler code. Caller is not required to hold any
3041 * locks. This function issues config_port mailbox command to configure
3042 * the SLI, setup iocb rings and HBQ rings. In the end the function
3043 * calls the config_port_post function to issue init_link mailbox
3044 * command and to start the discovery. The function will return zero
3045 * if successful, else it will return negative error code.
3046 **/
2503int 3047int
2504lpfc_sli_hba_setup(struct lpfc_hba *phba) 3048lpfc_sli_hba_setup(struct lpfc_hba *phba)
2505{ 3049{
@@ -2581,19 +3125,19 @@ lpfc_sli_hba_setup_error:
2581 return rc; 3125 return rc;
2582} 3126}
2583 3127
2584/*! lpfc_mbox_timeout 3128
2585 * 3129/**
2586 * \pre 3130 * lpfc_mbox_timeout: Timeout call back function for mbox timer.
2587 * \post 3131 * @ptr: context object - pointer to hba structure.
2588 * \param hba Pointer to per struct lpfc_hba structure
2589 * \param l1 Pointer to the driver's mailbox queue.
2590 * \return
2591 * void
2592 *
2593 * \b Description:
2594 * 3132 *
2595 * This routine handles mailbox timeout events at timer interrupt context. 3133 * This is the callback function for mailbox timer. The mailbox
2596 */ 3134 * timer is armed when a new mailbox command is issued and the timer
3135 * is deleted when the mailbox complete. The function is called by
3136 * the kernel timer code when a mailbox does not complete within
3137 * expected time. This function wakes up the worker thread to
3138 * process the mailbox timeout and returns. All the processing is
3139 * done by the worker thread function lpfc_mbox_timeout_handler.
3140 **/
2597void 3141void
2598lpfc_mbox_timeout(unsigned long ptr) 3142lpfc_mbox_timeout(unsigned long ptr)
2599{ 3143{
@@ -2612,6 +3156,15 @@ lpfc_mbox_timeout(unsigned long ptr)
2612 return; 3156 return;
2613} 3157}
2614 3158
3159
3160/**
3161 * lpfc_mbox_timeout_handler: Worker thread function to handle mailbox timeout.
3162 * @phba: Pointer to HBA context object.
3163 *
3164 * This function is called from worker thread when a mailbox command times out.
3165 * The caller is not required to hold any locks. This function will reset the
3166 * HBA and recover all the pending commands.
3167 **/
2615void 3168void
2616lpfc_mbox_timeout_handler(struct lpfc_hba *phba) 3169lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
2617{ 3170{
@@ -2666,6 +3219,32 @@ lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
2666 return; 3219 return;
2667} 3220}
2668 3221
3222/**
3223 * lpfc_sli_issue_mbox: Issue a mailbox command to firmware.
3224 * @phba: Pointer to HBA context object.
3225 * @pmbox: Pointer to mailbox object.
3226 * @flag: Flag indicating how the mailbox need to be processed.
3227 *
3228 * This function is called by discovery code and HBA management code
3229 * to submit a mailbox command to firmware. This function gets the
3230 * hbalock to protect the data structures.
3231 * The mailbox command can be submitted in polling mode, in which case
3232 * this function will wait in a polling loop for the completion of the
3233 * mailbox.
3234 * If the mailbox is submitted in no_wait mode (not polling) the
3235 * function will submit the command and returns immediately without waiting
3236 * for the mailbox completion. The no_wait is supported only when HBA
3237 * is in SLI2/SLI3 mode - interrupts are enabled.
3238 * The SLI interface allows only one mailbox pending at a time. If the
3239 * mailbox is issued in polling mode and there is already a mailbox
3240 * pending, then the function will return an error. If the mailbox is issued
3241 * in NO_WAIT mode and there is a mailbox pending already, the function
3242 * will return MBX_BUSY after queuing the mailbox into mailbox queue.
3243 * The sli layer owns the mailbox object until the completion of mailbox
3244 * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
3245 * return codes the caller owns the mailbox command after the return of
3246 * the function.
3247 **/
2669int 3248int
2670lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) 3249lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
2671{ 3250{
@@ -2980,9 +3559,16 @@ out_not_finished:
2980 return MBX_NOT_FINISHED; 3559 return MBX_NOT_FINISHED;
2981} 3560}
2982 3561
2983/* 3562/**
2984 * Caller needs to hold lock. 3563 * __lpfc_sli_ringtx_put: Add an iocb to the txq.
2985 */ 3564 * @phba: Pointer to HBA context object.
3565 * @pring: Pointer to driver SLI ring object.
3566 * @piocb: Pointer to address of newly added command iocb.
3567 *
3568 * This function is called with hbalock held to add a command
3569 * iocb to the txq when SLI layer cannot submit the command iocb
3570 * to the ring.
3571 **/
2986static void 3572static void
2987__lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 3573__lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2988 struct lpfc_iocbq *piocb) 3574 struct lpfc_iocbq *piocb)
@@ -2992,6 +3578,23 @@ __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2992 pring->txq_cnt++; 3578 pring->txq_cnt++;
2993} 3579}
2994 3580
3581/**
3582 * lpfc_sli_next_iocb: Get the next iocb in the txq.
3583 * @phba: Pointer to HBA context object.
3584 * @pring: Pointer to driver SLI ring object.
3585 * @piocb: Pointer to address of newly added command iocb.
3586 *
3587 * This function is called with hbalock held before a new
3588 * iocb is submitted to the firmware. This function checks
3589 * txq to flush the iocbs in txq to Firmware before
3590 * submitting new iocbs to the Firmware.
3591 * If there are iocbs in the txq which need to be submitted
3592 * to firmware, lpfc_sli_next_iocb returns the first element
3593 * of the txq after dequeuing it from txq.
3594 * If there is no iocb in the txq then the function will return
3595 * *piocb and *piocb is set to NULL. Caller needs to check
3596 * *piocb to find if there are more commands in the txq.
3597 **/
2995static struct lpfc_iocbq * 3598static struct lpfc_iocbq *
2996lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 3599lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2997 struct lpfc_iocbq **piocb) 3600 struct lpfc_iocbq **piocb)
@@ -3007,9 +3610,30 @@ lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3007 return nextiocb; 3610 return nextiocb;
3008} 3611}
3009 3612
3010/* 3613/**
3011 * Lockless version of lpfc_sli_issue_iocb. 3614 * __lpfc_sli_issue_iocb: Lockless version of lpfc_sli_issue_iocb.
3012 */ 3615 * @phba: Pointer to HBA context object.
3616 * @pring: Pointer to driver SLI ring object.
3617 * @piocb: Pointer to command iocb.
3618 * @flag: Flag indicating if this command can be put into txq.
3619 *
3620 * __lpfc_sli_issue_iocb is used by other functions in the driver
3621 * to issue an iocb command to the HBA. If the PCI slot is recovering
3622 * from error state or if HBA is resetting or if LPFC_STOP_IOCB_EVENT
3623 * flag is turned on, the function returns IOCB_ERROR.
3624 * When the link is down, this function allows only iocbs for
3625 * posting buffers.
3626 * This function finds next available slot in the command ring and
3627 * posts the command to the available slot and writes the port
3628 * attention register to request HBA start processing new iocb.
3629 * If there is no slot available in the ring and
3630 * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the
3631 * txq, otherwise the function returns IOCB_BUSY.
3632 *
3633 * This function is called with hbalock held.
3634 * The function will return success after it successfully submit the
3635 * iocb to firmware or after adding to the txq.
3636 **/
3013static int 3637static int
3014__lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 3638__lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3015 struct lpfc_iocbq *piocb, uint32_t flag) 3639 struct lpfc_iocbq *piocb, uint32_t flag)
@@ -3106,6 +3730,19 @@ __lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3106} 3730}
3107 3731
3108 3732
3733/**
3734 * lpfc_sli_issue_iocb: Wrapper function for __lpfc_sli_issue_iocb.
3735 * @phba: Pointer to HBA context object.
3736 * @pring: Pointer to driver SLI ring object.
3737 * @piocb: Pointer to command iocb.
3738 * @flag: Flag indicating if this command can be put into txq.
3739 *
3740 * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
3741 * function. This function gets the hbalock and calls
3742 * __lpfc_sli_issue_iocb function and will return the error returned
3743 * by __lpfc_sli_issue_iocb function. This wrapper is used by
3744 * functions which do not hold hbalock.
3745 **/
3109int 3746int
3110lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 3747lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3111 struct lpfc_iocbq *piocb, uint32_t flag) 3748 struct lpfc_iocbq *piocb, uint32_t flag)
@@ -3120,6 +3757,17 @@ lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3120 return rc; 3757 return rc;
3121} 3758}
3122 3759
3760/**
3761 * lpfc_extra_ring_setup: Extra ring setup function.
3762 * @phba: Pointer to HBA context object.
3763 *
3764 * This function is called while driver attaches with the
3765 * HBA to setup the extra ring. The extra ring is used
3766 * only when driver needs to support target mode functionality
3767 * or IP over FC functionalities.
3768 *
3769 * This function is called with no lock held.
3770 **/
3123static int 3771static int
3124lpfc_extra_ring_setup( struct lpfc_hba *phba) 3772lpfc_extra_ring_setup( struct lpfc_hba *phba)
3125{ 3773{
@@ -3155,6 +3803,19 @@ lpfc_extra_ring_setup( struct lpfc_hba *phba)
3155 return 0; 3803 return 0;
3156} 3804}
3157 3805
3806/**
3807 * lpfc_sli_async_event_handler: ASYNC iocb handler function.
3808 * @phba: Pointer to HBA context object.
3809 * @pring: Pointer to driver SLI ring object.
3810 * @iocbq: Pointer to iocb object.
3811 *
3812 * This function is called by the slow ring event handler
3813 * function when there is an ASYNC event iocb in the ring.
3814 * This function is called with no lock held.
3815 * Currently this function handles only temperature related
3816 * ASYNC events. The function decodes the temperature sensor
3817 * event message and posts events for the management applications.
3818 **/
3158static void 3819static void
3159lpfc_sli_async_event_handler(struct lpfc_hba * phba, 3820lpfc_sli_async_event_handler(struct lpfc_hba * phba,
3160 struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) 3821 struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
@@ -3210,6 +3871,17 @@ lpfc_sli_async_event_handler(struct lpfc_hba * phba,
3210} 3871}
3211 3872
3212 3873
3874/**
3875 * lpfc_sli_setup: SLI ring setup function.
3876 * @phba: Pointer to HBA context object.
3877 *
3878 * lpfc_sli_setup sets up rings of the SLI interface with
3879 * number of iocbs per ring and iotags. This function is
3880 * called while driver attach to the HBA and before the
3881 * interrupts are enabled. So there is no need for locking.
3882 *
3883 * This function always returns 0.
3884 **/
3213int 3885int
3214lpfc_sli_setup(struct lpfc_hba *phba) 3886lpfc_sli_setup(struct lpfc_hba *phba)
3215{ 3887{
@@ -3321,6 +3993,17 @@ lpfc_sli_setup(struct lpfc_hba *phba)
3321 return 0; 3993 return 0;
3322} 3994}
3323 3995
3996/**
3997 * lpfc_sli_queue_setup: Queue initialization function.
3998 * @phba: Pointer to HBA context object.
3999 *
4000 * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
4001 * ring. This function also initializes ring indices of each ring.
4002 * This function is called during the initialization of the SLI
4003 * interface of an HBA.
4004 * This function is called with no lock held and always returns
4005 * 1.
4006 **/
3324int 4007int
3325lpfc_sli_queue_setup(struct lpfc_hba *phba) 4008lpfc_sli_queue_setup(struct lpfc_hba *phba)
3326{ 4009{
@@ -3349,6 +4032,23 @@ lpfc_sli_queue_setup(struct lpfc_hba *phba)
3349 return 1; 4032 return 1;
3350} 4033}
3351 4034
4035/**
4036 * lpfc_sli_host_down: Vport cleanup function.
4037 * @vport: Pointer to virtual port object.
4038 *
4039 * lpfc_sli_host_down is called to clean up the resources
4040 * associated with a vport before destroying virtual
4041 * port data structures.
4042 * This function does following operations:
4043 * - Free discovery resources associated with this virtual
4044 * port.
4045 * - Free iocbs associated with this virtual port in
4046 * the txq.
4047 * - Send abort for all iocb commands associated with this
4048 * vport in txcmplq.
4049 *
4050 * This function is called with no lock held and always returns 1.
4051 **/
3352int 4052int
3353lpfc_sli_host_down(struct lpfc_vport *vport) 4053lpfc_sli_host_down(struct lpfc_vport *vport)
3354{ 4054{
@@ -3411,6 +4111,21 @@ lpfc_sli_host_down(struct lpfc_vport *vport)
3411 return 1; 4111 return 1;
3412} 4112}
3413 4113
4114/**
4115 * lpfc_sli_hba_down: Resource cleanup function for the HBA.
4116 * @phba: Pointer to HBA context object.
4117 *
4118 * This function cleans up all iocb, buffers, mailbox commands
4119 * while shutting down the HBA. This function is called with no
4120 * lock held and always returns 1.
4121 * This function does the following to cleanup driver resources:
4122 * - Free discovery resources for each virtual port
4123 * - Cleanup any pending fabric iocbs
4124 * - Iterate through the iocb txq and free each entry
4125 * in the list.
4126 * - Free up any buffer posted to the HBA
4127 * - Free mailbox commands in the mailbox queue.
4128 **/
3414int 4129int
3415lpfc_sli_hba_down(struct lpfc_hba *phba) 4130lpfc_sli_hba_down(struct lpfc_hba *phba)
3416{ 4131{
@@ -3501,6 +4216,18 @@ lpfc_sli_hba_down(struct lpfc_hba *phba)
3501 return 1; 4216 return 1;
3502} 4217}
3503 4218
4219/**
4220 * lpfc_sli_pcimem_bcopy: SLI memory copy function.
4221 * @srcp: Source memory pointer.
4222 * @destp: Destination memory pointer.
4223 * @cnt: Number of words required to be copied.
4224 *
4225 * This function is used for copying data between driver memory
4226 * and the SLI memory. This function also changes the endianness
4227 * of each word if native endianness is different from SLI
4228 * endianness. This function can be called with or without
4229 * lock.
4230 **/
3504void 4231void
3505lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) 4232lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
3506{ 4233{
@@ -3518,6 +4245,17 @@ lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
3518 } 4245 }
3519} 4246}
3520 4247
4248
4249/**
4250 * lpfc_sli_ringpostbuf_put: Function to add a buffer to postbufq.
4251 * @phba: Pointer to HBA context object.
4252 * @pring: Pointer to driver SLI ring object.
4253 * @mp: Pointer to driver buffer object.
4254 *
4255 * This function is called with no lock held.
4256 * It always return zero after adding the buffer to the postbufq
4257 * buffer list.
4258 **/
3521int 4259int
3522lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 4260lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3523 struct lpfc_dmabuf *mp) 4261 struct lpfc_dmabuf *mp)
@@ -3531,6 +4269,18 @@ lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3531 return 0; 4269 return 0;
3532} 4270}
3533 4271
4272/**
4273 * lpfc_sli_get_buffer_tag: Tag allocation function for a buffer posted
4274 * using CMD_QUE_XRI64_CX iocb.
4275 * @phba: Pointer to HBA context object.
4276 *
4277 * When HBQ is enabled, buffers are searched based on tags. This function
4278 * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
4279 * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
4280 * does not conflict with tags of buffer posted for unsolicited events.
4281 * The function returns the allocated tag. The function is called with
4282 * no locks held.
4283 **/
3534uint32_t 4284uint32_t
3535lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) 4285lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
3536{ 4286{
@@ -3545,6 +4295,22 @@ lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
3545 return phba->buffer_tag_count; 4295 return phba->buffer_tag_count;
3546} 4296}
3547 4297
4298/**
4299 * lpfc_sli_ring_taggedbuf_get: Search HBQ buffer associated with
4300 * posted using CMD_QUE_XRI64_CX iocb.
4301 * @phba: Pointer to HBA context object.
4302 * @pring: Pointer to driver SLI ring object.
4303 * @tag: Buffer tag.
4304 *
4305 * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
4306 * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
4307 * iocb is posted to the response ring with the tag of the buffer.
4308 * This function searches the pring->postbufq list using the tag
4309 * to find buffer associated with CMD_IOCB_RET_XRI64_CX
4310 * iocb. If the buffer is found then lpfc_dmabuf object of the
4311 * buffer is returned to the caller else NULL is returned.
4312 * This function is called with no lock held.
4313 **/
3548struct lpfc_dmabuf * 4314struct lpfc_dmabuf *
3549lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 4315lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3550 uint32_t tag) 4316 uint32_t tag)
@@ -3573,6 +4339,23 @@ lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3573 return NULL; 4339 return NULL;
3574} 4340}
3575 4341
4342/**
4343 * lpfc_sli_ringpostbuf_get: SLI2 buffer search function for
4344 * unsolicited ct and els events.
4345 * @phba: Pointer to HBA context object.
4346 * @pring: Pointer to driver SLI ring object.
4347 * @phys: DMA address of the buffer.
4348 *
4349 * This function searches the buffer list using the dma_address
4350 * of unsolicited event to find the driver's lpfc_dmabuf object
4351 * corresponding to the dma_address. The function returns the
4352 * lpfc_dmabuf object if a buffer is found else it returns NULL.
4353 * This function is called by the ct and els unsolicited event
4354 * handlers to get the buffer associated with the unsolicited
4355 * event.
4356 *
4357 * This function is called with no lock held.
4358 **/
3576struct lpfc_dmabuf * 4359struct lpfc_dmabuf *
3577lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 4360lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3578 dma_addr_t phys) 4361 dma_addr_t phys)
@@ -3600,6 +4383,17 @@ lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3600 return NULL; 4383 return NULL;
3601} 4384}
3602 4385
4386/**
4387 * lpfc_sli_abort_els_cmpl: Completion handler for the els abort iocbs.
4388 * @phba: Pointer to HBA context object.
4389 * @cmdiocb: Pointer to driver command iocb object.
4390 * @rspiocb: Pointer to driver response iocb object.
4391 *
4392 * This function is the completion handler for the abort iocbs for
4393 * ELS commands. This function is called from the ELS ring event
4394 * handler with no lock held. This function frees memory resources
4395 * associated with the abort iocb.
4396 **/
3603static void 4397static void
3604lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 4398lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3605 struct lpfc_iocbq *rspiocb) 4399 struct lpfc_iocbq *rspiocb)
@@ -3665,6 +4459,17 @@ lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3665 return; 4459 return;
3666} 4460}
3667 4461
4462/**
4463 * lpfc_ignore_els_cmpl: Completion handler for aborted ELS command.
4464 * @phba: Pointer to HBA context object.
4465 * @cmdiocb: Pointer to driver command iocb object.
4466 * @rspiocb: Pointer to driver response iocb object.
4467 *
4468 * The function is called from SLI ring event handler with no
4469 * lock held. This function is the completion handler for ELS commands
4470 * which are aborted. The function frees memory resources used for
4471 * the aborted ELS commands.
4472 **/
3668static void 4473static void
3669lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 4474lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3670 struct lpfc_iocbq *rspiocb) 4475 struct lpfc_iocbq *rspiocb)
@@ -3684,6 +4489,17 @@ lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3684 return; 4489 return;
3685} 4490}
3686 4491
4492/**
4493 * lpfc_sli_issue_abort_iotag: Abort function for a command iocb.
4494 * @phba: Pointer to HBA context object.
4495 * @pring: Pointer to driver SLI ring object.
4496 * @cmdiocb: Pointer to driver command iocb object.
4497 *
4498 * This function issues an abort iocb for the provided command
4499 * iocb. This function is called with hbalock held.
4500 * The function returns 0 when it fails due to memory allocation
4501 * failure or when the command iocb is an abort request.
4502 **/
3687int 4503int
3688lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 4504lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3689 struct lpfc_iocbq *cmdiocb) 4505 struct lpfc_iocbq *cmdiocb)
@@ -3757,6 +4573,29 @@ abort_iotag_exit:
3757 return retval; 4573 return retval;
3758} 4574}
3759 4575
4576/**
4577 * lpfc_sli_validate_fcp_iocb: Filtering function, used to find commands
4578 * associated with a vport/SCSI target/lun.
4579 * @iocbq: Pointer to driver iocb object.
4580 * @vport: Pointer to driver virtual port object.
4581 * @tgt_id: SCSI ID of the target.
4582 * @lun_id: LUN ID of the scsi device.
4583 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
4584 *
4585 * This function acts as iocb filter for functions which abort or count
4586 * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
4587 * 0 if the filtering criteria is met for the given iocb and will return
4588 * 1 if the filtering criteria is not met.
4589 * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
4590 * given iocb is for the SCSI device specified by vport, tgt_id and
4591 * lun_id parameter.
4592 * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
4593 * given iocb is for the SCSI target specified by vport and tgt_id
4594 * parameters.
4595 * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
4596 * given iocb is for the SCSI host associated with the given vport.
4597 * This function is called with no locks held.
4598 **/
3760static int 4599static int
3761lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, 4600lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
3762 uint16_t tgt_id, uint64_t lun_id, 4601 uint16_t tgt_id, uint64_t lun_id,
@@ -3800,6 +4639,25 @@ lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
3800 return rc; 4639 return rc;
3801} 4640}
3802 4641
4642/**
4643 * lpfc_sli_sum_iocb: Function to count the number of FCP iocbs pending.
4644 * @vport: Pointer to virtual port.
4645 * @tgt_id: SCSI ID of the target.
4646 * @lun_id: LUN ID of the scsi device.
4647 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
4648 *
4649 * This function returns number of FCP commands pending for the vport.
4650 * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
4651 * commands pending on the vport associated with SCSI device specified
4652 * by tgt_id and lun_id parameters.
4653 * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
4654 * commands pending on the vport associated with SCSI target specified
4655 * by tgt_id parameter.
4656 * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
4657 * commands pending on the vport.
4658 * This function returns the number of iocbs which satisfy the filter.
4659 * This function is called without any lock held.
4660 **/
3803int 4661int
3804lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, 4662lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
3805 lpfc_ctx_cmd ctx_cmd) 4663 lpfc_ctx_cmd ctx_cmd)
@@ -3819,6 +4677,17 @@ lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
3819 return sum; 4677 return sum;
3820} 4678}
3821 4679
4680/**
4681 * lpfc_sli_abort_fcp_cmpl: Completion handler function for an aborted
4682 * FCP iocb.
4683 * @phba: Pointer to HBA context object
4684 * @cmdiocb: Pointer to command iocb object.
4685 * @rspiocb: Pointer to response iocb object.
4686 *
4687 * This function is called when an aborted FCP iocb completes. This
4688 * function is called by the ring event handler with no lock held.
4689 * This function frees the iocb.
4690 **/
3822void 4691void
3823lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 4692lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3824 struct lpfc_iocbq *rspiocb) 4693 struct lpfc_iocbq *rspiocb)
@@ -3827,6 +4696,28 @@ lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3827 return; 4696 return;
3828} 4697}
3829 4698
4699/**
4700 * lpfc_sli_abort_iocb: This function issue abort for all SCSI commands
4701 * pending on a SCSI host(vport)/target/lun.
4702 * @vport: Pointer to virtual port.
4703 * @pring: Pointer to driver SLI ring object.
4704 * @tgt_id: SCSI ID of the target.
4705 * @lun_id: LUN ID of the scsi device.
4706 * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
4707 *
4708 * This function sends an abort command for every SCSI command
4709 * associated with the given virtual port pending on the ring
4710 * filtered by lpfc_sli_validate_fcp_iocb function.
4711 * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
4712 * FCP iocbs associated with lun specified by tgt_id and lun_id
4713 * parameters
4714 * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
4715 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
4716 * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
4717 * FCP iocbs associated with virtual port.
4718 * This function returns number of iocbs it failed to abort.
4719 * This function is called with no locks held.
4720 **/
3830int 4721int
3831lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, 4722lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
3832 uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) 4723 uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
@@ -3878,6 +4769,24 @@ lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
3878 return errcnt; 4769 return errcnt;
3879} 4770}
3880 4771
4772/**
4773 * lpfc_sli_wake_iocb_wait: iocb completion handler for iocb issued using
4774 * lpfc_sli_issue_iocb_wait.
4775 * @phba: Pointer to HBA context object.
4776 * @cmdiocbq: Pointer to command iocb.
4777 * @rspiocbq: Pointer to response iocb.
4778 *
4779 * This function is the completion handler for iocbs issued using
4780 * lpfc_sli_issue_iocb_wait function. This function is called by the
4781 * ring event handler function without any lock held. This function
4782 * can be called from both worker thread context and interrupt
4783 * context. This function also can be called from other thread which
4784 * cleans up the SLI layer objects.
4785 * This function copy the contents of the response iocb to the
4786 * response iocb memory object provided by the caller of
4787 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
4788 * sleeps for the iocb completion.
4789 **/
3881static void 4790static void
3882lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, 4791lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
3883 struct lpfc_iocbq *cmdiocbq, 4792 struct lpfc_iocbq *cmdiocbq,
@@ -3899,13 +4808,36 @@ lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
3899 return; 4808 return;
3900} 4809}
3901 4810
3902/* 4811/**
3903 * Issue the caller's iocb and wait for its completion, but no longer than the 4812 * lpfc_sli_issue_iocb_wait: Synchronous function to issue iocb commands.
3904 * caller's timeout. Note that iocb_flags is cleared before the 4813 * @phba: Pointer to HBA context object..
3905 * lpfc_sli_issue_call since the wake routine sets a unique value and by 4814 * @pring: Pointer to sli ring.
3906 * definition this is a wait function. 4815 * @piocb: Pointer to command iocb.
3907 */ 4816 * @prspiocbq: Pointer to response iocb.
3908 4817 * @timeout: Timeout in number of seconds.
4818 *
4819 * This function issues the iocb to firmware and waits for the
4820 * iocb to complete. If the iocb command is not
4821 * completed within timeout seconds, it returns IOCB_TIMEDOUT.
4822 * Caller should not free the iocb resources if this function
4823 * returns IOCB_TIMEDOUT.
4824 * The function waits for the iocb completion using an
4825 * non-interruptible wait.
4826 * This function will sleep while waiting for iocb completion.
4827 * So, this function should not be called from any context which
4828 * does not allow sleeping. Due to the same reason, this function
4829 * cannot be called with interrupt disabled.
4830 * This function assumes that the iocb completions occur while
4831 * this function sleep. So, this function cannot be called from
4832 * the thread which process iocb completion for this ring.
4833 * This function clears the iocb_flag of the iocb object before
4834 * issuing the iocb and the iocb completion handler sets this
4835 * flag and wakes this thread when the iocb completes.
4836 * The contents of the response iocb will be copied to prspiocbq
4837 * by the completion handler when the command completes.
4838 * This function returns IOCB_SUCCESS when success.
4839 * This function is called with no lock held.
4840 **/
3909int 4841int
3910lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, 4842lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
3911 struct lpfc_sli_ring *pring, 4843 struct lpfc_sli_ring *pring,
@@ -3983,6 +4915,32 @@ lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
3983 return retval; 4915 return retval;
3984} 4916}
3985 4917
4918/**
4919 * lpfc_sli_issue_mbox_wait: Synchronous function to issue mailbox.
4920 * @phba: Pointer to HBA context object.
4921 * @pmboxq: Pointer to driver mailbox object.
4922 * @timeout: Timeout in number of seconds.
4923 *
4924 * This function issues the mailbox to firmware and waits for the
4925 * mailbox command to complete. If the mailbox command is not
4926 * completed within timeout seconds, it returns MBX_TIMEOUT.
4927 * The function waits for the mailbox completion using an
4928 * interruptible wait. If the thread is woken up due to a
4929 * signal, MBX_TIMEOUT error is returned to the caller. Caller
4930 * should not free the mailbox resources, if this function returns
4931 * MBX_TIMEOUT.
4932 * This function will sleep while waiting for mailbox completion.
4933 * So, this function should not be called from any context which
4934 * does not allow sleeping. Due to the same reason, this function
4935 * cannot be called with interrupt disabled.
4936 * This function assumes that the mailbox completion occurs while
4937 * this function sleep. So, this function cannot be called from
4938 * the worker thread which processes mailbox completion.
4939 * This function is called in the context of HBA management
4940 * applications.
4941 * This function returns MBX_SUCCESS when successful.
4942 * This function is called with no lock held.
4943 **/
3986int 4944int
3987lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, 4945lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
3988 uint32_t timeout) 4946 uint32_t timeout)
@@ -4027,6 +4985,18 @@ lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
4027 return retval; 4985 return retval;
4028} 4986}
4029 4987
4988/**
4989 * lpfc_sli_flush_mbox_queue: mailbox queue cleanup function.
4990 * @phba: Pointer to HBA context.
4991 *
4992 * This function is called to cleanup any pending mailbox
4993 * objects in the driver queue before bringing the HBA offline.
4994 * This function is called while resetting the HBA.
4995 * The function is called without any lock held. The function
4996 * takes hbalock to update SLI data structure.
4997 * This function returns 1 when there is an active mailbox
4998 * command pending else returns 0.
4999 **/
4030int 5000int
4031lpfc_sli_flush_mbox_queue(struct lpfc_hba * phba) 5001lpfc_sli_flush_mbox_queue(struct lpfc_hba * phba)
4032{ 5002{
@@ -4058,6 +5028,27 @@ lpfc_sli_flush_mbox_queue(struct lpfc_hba * phba)
4058 return (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) ? 1 : 0; 5028 return (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) ? 1 : 0;
4059} 5029}
4060 5030
5031/**
5032 * lpfc_intr_handler: The interrupt handler of lpfc driver.
5033 * @irq: Interrupt number.
5034 * @dev_id: The device context pointer.
5035 *
5036 * This function is called from the PCI layer when there is
5037 * an event in the HBA which requires driver attention. When
5038 * the PCI slot is in error recovery or the HBA is undergoing
5039 * initialization the interrupt handler will not process the
5040 * interrupt.
5041 * The error attention, link attention and els ring attention
5042 * events are handled by the worker thread. The interrupt
5043 * handler signals the worker thread and returns for these
5044 * events.
5045 * The SCSI ring event and mailbox events are handled in the
5046 * interrupt context.
5047 * This function is called without any lock held. It gets the
5048 * hbalock to access and update SLI data structures.
5049 * This function returns IRQ_HANDLED when interrupt is handled
5050 * else it returns IRQ_NONE.
5051 **/
4061irqreturn_t 5052irqreturn_t
4062lpfc_intr_handler(int irq, void *dev_id) 5053lpfc_intr_handler(int irq, void *dev_id)
4063{ 5054{