zfcp_fsf.c 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549
  1. /*
  2. * zfcp device driver
  3. *
  4. * Implementation of FSF commands.
  5. *
  6. * Copyright IBM Corporation 2002, 2008
  7. */
  8. #include <linux/blktrace_api.h>
  9. #include "zfcp_ext.h"
  10. static void zfcp_fsf_request_timeout_handler(unsigned long data)
  11. {
  12. struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
  13. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED, 62,
  14. NULL);
  15. }
  16. static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
  17. unsigned long timeout)
  18. {
  19. fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
  20. fsf_req->timer.data = (unsigned long) fsf_req->adapter;
  21. fsf_req->timer.expires = jiffies + timeout;
  22. add_timer(&fsf_req->timer);
  23. }
  24. static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
  25. {
  26. BUG_ON(!fsf_req->erp_action);
  27. fsf_req->timer.function = zfcp_erp_timeout_handler;
  28. fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
  29. fsf_req->timer.expires = jiffies + 30 * HZ;
  30. add_timer(&fsf_req->timer);
  31. }
  32. /* association between FSF command and FSF QTCB type */
  33. static u32 fsf_qtcb_type[] = {
  34. [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
  35. [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
  36. [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
  37. [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
  38. [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
  39. [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
  40. [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
  41. [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
  42. [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
  43. [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
  44. [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
  45. [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
  46. [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
  47. };
  48. static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
  49. {
  50. u16 subtable = table >> 16;
  51. u16 rule = table & 0xffff;
  52. const char *act_type[] = { "unknown", "OS", "WWPN", "DID", "LUN" };
  53. if (subtable && subtable < ARRAY_SIZE(act_type))
  54. dev_warn(&adapter->ccw_device->dev,
  55. "Access denied according to ACT rule type %s, "
  56. "rule %d\n", act_type[subtable], rule);
  57. }
  58. static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
  59. struct zfcp_port *port)
  60. {
  61. struct fsf_qtcb_header *header = &req->qtcb->header;
  62. dev_warn(&req->adapter->ccw_device->dev,
  63. "Access denied to port 0x%016Lx\n",
  64. (unsigned long long)port->wwpn);
  65. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
  66. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
  67. zfcp_erp_port_access_denied(port, 55, req);
  68. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  69. }
  70. static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req,
  71. struct zfcp_unit *unit)
  72. {
  73. struct fsf_qtcb_header *header = &req->qtcb->header;
  74. dev_warn(&req->adapter->ccw_device->dev,
  75. "Access denied to unit 0x%016Lx on port 0x%016Lx\n",
  76. (unsigned long long)unit->fcp_lun,
  77. (unsigned long long)unit->port->wwpn);
  78. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
  79. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
  80. zfcp_erp_unit_access_denied(unit, 59, req);
  81. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  82. }
  83. static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
  84. {
  85. dev_err(&req->adapter->ccw_device->dev, "FCP device not "
  86. "operational because of an unsupported FC class\n");
  87. zfcp_erp_adapter_shutdown(req->adapter, 0, 123, req);
  88. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  89. }
  90. /**
  91. * zfcp_fsf_req_free - free memory used by fsf request
  92. * @fsf_req: pointer to struct zfcp_fsf_req
  93. */
  94. void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
  95. {
  96. if (likely(req->pool)) {
  97. mempool_free(req, req->pool);
  98. return;
  99. }
  100. if (req->qtcb) {
  101. kmem_cache_free(zfcp_data.fsf_req_qtcb_cache, req);
  102. return;
  103. }
  104. }
  105. /**
  106. * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
  107. * @adapter: pointer to struct zfcp_adapter
  108. *
  109. * Never ever call this without shutting down the adapter first.
  110. * Otherwise the adapter would continue using and corrupting s390 storage.
  111. * Included BUG_ON() call to ensure this is done.
  112. * ERP is supposed to be the only user of this function.
  113. */
  114. void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
  115. {
  116. struct zfcp_fsf_req *req, *tmp;
  117. unsigned long flags;
  118. LIST_HEAD(remove_queue);
  119. unsigned int i;
  120. BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
  121. spin_lock_irqsave(&adapter->req_list_lock, flags);
  122. for (i = 0; i < REQUEST_LIST_SIZE; i++)
  123. list_splice_init(&adapter->req_list[i], &remove_queue);
  124. spin_unlock_irqrestore(&adapter->req_list_lock, flags);
  125. list_for_each_entry_safe(req, tmp, &remove_queue, list) {
  126. list_del(&req->list);
  127. req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
  128. zfcp_fsf_req_complete(req);
  129. }
  130. }
  131. static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
  132. {
  133. struct fsf_status_read_buffer *sr_buf = req->data;
  134. struct zfcp_adapter *adapter = req->adapter;
  135. struct zfcp_port *port;
  136. int d_id = sr_buf->d_id & ZFCP_DID_MASK;
  137. unsigned long flags;
  138. read_lock_irqsave(&zfcp_data.config_lock, flags);
  139. list_for_each_entry(port, &adapter->port_list_head, list)
  140. if (port->d_id == d_id) {
  141. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  142. switch (sr_buf->status_subtype) {
  143. case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT:
  144. zfcp_erp_port_reopen(port, 0, 101, req);
  145. break;
  146. case FSF_STATUS_READ_SUB_ERROR_PORT:
  147. zfcp_erp_port_shutdown(port, 0, 122, req);
  148. break;
  149. }
  150. return;
  151. }
  152. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  153. }
  154. static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, u8 id,
  155. struct fsf_link_down_info *link_down)
  156. {
  157. struct zfcp_adapter *adapter = req->adapter;
  158. if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
  159. return;
  160. atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
  161. if (!link_down)
  162. goto out;
  163. switch (link_down->error_code) {
  164. case FSF_PSQ_LINK_NO_LIGHT:
  165. dev_warn(&req->adapter->ccw_device->dev,
  166. "There is no light signal from the local "
  167. "fibre channel cable\n");
  168. break;
  169. case FSF_PSQ_LINK_WRAP_PLUG:
  170. dev_warn(&req->adapter->ccw_device->dev,
  171. "There is a wrap plug instead of a fibre "
  172. "channel cable\n");
  173. break;
  174. case FSF_PSQ_LINK_NO_FCP:
  175. dev_warn(&req->adapter->ccw_device->dev,
  176. "The adjacent fibre channel node does not "
  177. "support FCP\n");
  178. break;
  179. case FSF_PSQ_LINK_FIRMWARE_UPDATE:
  180. dev_warn(&req->adapter->ccw_device->dev,
  181. "The FCP device is suspended because of a "
  182. "firmware update\n");
  183. break;
  184. case FSF_PSQ_LINK_INVALID_WWPN:
  185. dev_warn(&req->adapter->ccw_device->dev,
  186. "The FCP device detected a WWPN that is "
  187. "duplicate or not valid\n");
  188. break;
  189. case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
  190. dev_warn(&req->adapter->ccw_device->dev,
  191. "The fibre channel fabric does not support NPIV\n");
  192. break;
  193. case FSF_PSQ_LINK_NO_FCP_RESOURCES:
  194. dev_warn(&req->adapter->ccw_device->dev,
  195. "The FCP adapter cannot support more NPIV ports\n");
  196. break;
  197. case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
  198. dev_warn(&req->adapter->ccw_device->dev,
  199. "The adjacent switch cannot support "
  200. "more NPIV ports\n");
  201. break;
  202. case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
  203. dev_warn(&req->adapter->ccw_device->dev,
  204. "The FCP adapter could not log in to the "
  205. "fibre channel fabric\n");
  206. break;
  207. case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
  208. dev_warn(&req->adapter->ccw_device->dev,
  209. "The WWPN assignment file on the FCP adapter "
  210. "has been damaged\n");
  211. break;
  212. case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
  213. dev_warn(&req->adapter->ccw_device->dev,
  214. "The mode table on the FCP adapter "
  215. "has been damaged\n");
  216. break;
  217. case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
  218. dev_warn(&req->adapter->ccw_device->dev,
  219. "All NPIV ports on the FCP adapter have "
  220. "been assigned\n");
  221. break;
  222. default:
  223. dev_warn(&req->adapter->ccw_device->dev,
  224. "The link between the FCP adapter and "
  225. "the FC fabric is down\n");
  226. }
  227. out:
  228. zfcp_erp_adapter_failed(adapter, id, req);
  229. }
  230. static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
  231. {
  232. struct fsf_status_read_buffer *sr_buf = req->data;
  233. struct fsf_link_down_info *ldi =
  234. (struct fsf_link_down_info *) &sr_buf->payload;
  235. switch (sr_buf->status_subtype) {
  236. case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
  237. zfcp_fsf_link_down_info_eval(req, 38, ldi);
  238. break;
  239. case FSF_STATUS_READ_SUB_FDISC_FAILED:
  240. zfcp_fsf_link_down_info_eval(req, 39, ldi);
  241. break;
  242. case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
  243. zfcp_fsf_link_down_info_eval(req, 40, NULL);
  244. };
  245. }
  246. static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
  247. {
  248. struct zfcp_adapter *adapter = req->adapter;
  249. struct fsf_status_read_buffer *sr_buf = req->data;
  250. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  251. zfcp_hba_dbf_event_fsf_unsol("dism", adapter, sr_buf);
  252. mempool_free(sr_buf, adapter->pool.data_status_read);
  253. zfcp_fsf_req_free(req);
  254. return;
  255. }
  256. zfcp_hba_dbf_event_fsf_unsol("read", adapter, sr_buf);
  257. switch (sr_buf->status_type) {
  258. case FSF_STATUS_READ_PORT_CLOSED:
  259. zfcp_fsf_status_read_port_closed(req);
  260. break;
  261. case FSF_STATUS_READ_INCOMING_ELS:
  262. zfcp_fc_incoming_els(req);
  263. break;
  264. case FSF_STATUS_READ_SENSE_DATA_AVAIL:
  265. break;
  266. case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
  267. dev_warn(&adapter->ccw_device->dev,
  268. "The error threshold for checksum statistics "
  269. "has been exceeded\n");
  270. zfcp_hba_dbf_event_berr(adapter, req);
  271. break;
  272. case FSF_STATUS_READ_LINK_DOWN:
  273. zfcp_fsf_status_read_link_down(req);
  274. break;
  275. case FSF_STATUS_READ_LINK_UP:
  276. dev_info(&adapter->ccw_device->dev,
  277. "The local link has been restored\n");
  278. /* All ports should be marked as ready to run again */
  279. zfcp_erp_modify_adapter_status(adapter, 30, NULL,
  280. ZFCP_STATUS_COMMON_RUNNING,
  281. ZFCP_SET);
  282. zfcp_erp_adapter_reopen(adapter,
  283. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  284. ZFCP_STATUS_COMMON_ERP_FAILED,
  285. 102, req);
  286. break;
  287. case FSF_STATUS_READ_NOTIFICATION_LOST:
  288. if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
  289. zfcp_erp_adapter_access_changed(adapter, 135, req);
  290. if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
  291. schedule_work(&adapter->scan_work);
  292. break;
  293. case FSF_STATUS_READ_CFDC_UPDATED:
  294. zfcp_erp_adapter_access_changed(adapter, 136, req);
  295. break;
  296. case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
  297. adapter->adapter_features = sr_buf->payload.word[0];
  298. break;
  299. }
  300. mempool_free(sr_buf, adapter->pool.data_status_read);
  301. zfcp_fsf_req_free(req);
  302. atomic_inc(&adapter->stat_miss);
  303. queue_work(zfcp_data.work_queue, &adapter->stat_work);
  304. }
  305. static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
  306. {
  307. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  308. case FSF_SQ_FCP_RSP_AVAILABLE:
  309. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  310. case FSF_SQ_NO_RETRY_POSSIBLE:
  311. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  312. return;
  313. case FSF_SQ_COMMAND_ABORTED:
  314. req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
  315. break;
  316. case FSF_SQ_NO_RECOM:
  317. dev_err(&req->adapter->ccw_device->dev,
  318. "The FCP adapter reported a problem "
  319. "that cannot be recovered\n");
  320. zfcp_erp_adapter_shutdown(req->adapter, 0, 121, req);
  321. break;
  322. }
  323. /* all non-return stats set FSFREQ_ERROR*/
  324. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  325. }
  326. static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
  327. {
  328. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  329. return;
  330. switch (req->qtcb->header.fsf_status) {
  331. case FSF_UNKNOWN_COMMAND:
  332. dev_err(&req->adapter->ccw_device->dev,
  333. "The FCP adapter does not recognize the command 0x%x\n",
  334. req->qtcb->header.fsf_command);
  335. zfcp_erp_adapter_shutdown(req->adapter, 0, 120, req);
  336. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  337. break;
  338. case FSF_ADAPTER_STATUS_AVAILABLE:
  339. zfcp_fsf_fsfstatus_qual_eval(req);
  340. break;
  341. }
  342. }
  343. static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
  344. {
  345. struct zfcp_adapter *adapter = req->adapter;
  346. struct fsf_qtcb *qtcb = req->qtcb;
  347. union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
  348. zfcp_hba_dbf_event_fsf_response(req);
  349. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  350. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  351. ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
  352. return;
  353. }
  354. switch (qtcb->prefix.prot_status) {
  355. case FSF_PROT_GOOD:
  356. case FSF_PROT_FSF_STATUS_PRESENTED:
  357. return;
  358. case FSF_PROT_QTCB_VERSION_ERROR:
  359. dev_err(&adapter->ccw_device->dev,
  360. "QTCB version 0x%x not supported by FCP adapter "
  361. "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
  362. psq->word[0], psq->word[1]);
  363. zfcp_erp_adapter_shutdown(adapter, 0, 117, req);
  364. break;
  365. case FSF_PROT_ERROR_STATE:
  366. case FSF_PROT_SEQ_NUMB_ERROR:
  367. zfcp_erp_adapter_reopen(adapter, 0, 98, req);
  368. req->status |= ZFCP_STATUS_FSFREQ_RETRY;
  369. break;
  370. case FSF_PROT_UNSUPP_QTCB_TYPE:
  371. dev_err(&adapter->ccw_device->dev,
  372. "The QTCB type is not supported by the FCP adapter\n");
  373. zfcp_erp_adapter_shutdown(adapter, 0, 118, req);
  374. break;
  375. case FSF_PROT_HOST_CONNECTION_INITIALIZING:
  376. atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  377. &adapter->status);
  378. break;
  379. case FSF_PROT_DUPLICATE_REQUEST_ID:
  380. dev_err(&adapter->ccw_device->dev,
  381. "0x%Lx is an ambiguous request identifier\n",
  382. (unsigned long long)qtcb->bottom.support.req_handle);
  383. zfcp_erp_adapter_shutdown(adapter, 0, 78, req);
  384. break;
  385. case FSF_PROT_LINK_DOWN:
  386. zfcp_fsf_link_down_info_eval(req, 37, &psq->link_down_info);
  387. /* FIXME: reopening adapter now? better wait for link up */
  388. zfcp_erp_adapter_reopen(adapter, 0, 79, req);
  389. break;
  390. case FSF_PROT_REEST_QUEUE:
  391. /* All ports should be marked as ready to run again */
  392. zfcp_erp_modify_adapter_status(adapter, 28, NULL,
  393. ZFCP_STATUS_COMMON_RUNNING,
  394. ZFCP_SET);
  395. zfcp_erp_adapter_reopen(adapter,
  396. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  397. ZFCP_STATUS_COMMON_ERP_FAILED, 99, req);
  398. break;
  399. default:
  400. dev_err(&adapter->ccw_device->dev,
  401. "0x%x is not a valid transfer protocol status\n",
  402. qtcb->prefix.prot_status);
  403. zfcp_erp_adapter_shutdown(adapter, 0, 119, req);
  404. }
  405. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  406. }
  407. /**
  408. * zfcp_fsf_req_complete - process completion of a FSF request
  409. * @fsf_req: The FSF request that has been completed.
  410. *
  411. * When a request has been completed either from the FCP adapter,
  412. * or it has been dismissed due to a queue shutdown, this function
  413. * is called to process the completion status and trigger further
  414. * events related to the FSF request.
  415. */
  416. void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
  417. {
  418. if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
  419. zfcp_fsf_status_read_handler(req);
  420. return;
  421. }
  422. del_timer(&req->timer);
  423. zfcp_fsf_protstatus_eval(req);
  424. zfcp_fsf_fsfstatus_eval(req);
  425. req->handler(req);
  426. if (req->erp_action)
  427. zfcp_erp_notify(req->erp_action, 0);
  428. req->status |= ZFCP_STATUS_FSFREQ_COMPLETED;
  429. if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
  430. zfcp_fsf_req_free(req);
  431. else
  432. /* notify initiator waiting for the requests completion */
  433. /*
  434. * FIXME: Race! We must not access fsf_req here as it might have been
  435. * cleaned up already due to the set ZFCP_STATUS_FSFREQ_COMPLETED
  436. * flag. It's an improbable case. But, we have the same paranoia for
  437. * the cleanup flag already.
  438. * Might better be handled using complete()?
  439. * (setting the flag and doing wakeup ought to be atomic
  440. * with regard to checking the flag as long as waitqueue is
  441. * part of the to be released structure)
  442. */
  443. wake_up(&req->completion_wq);
  444. }
  445. static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
  446. {
  447. struct fsf_qtcb_bottom_config *bottom;
  448. struct zfcp_adapter *adapter = req->adapter;
  449. struct Scsi_Host *shost = adapter->scsi_host;
  450. bottom = &req->qtcb->bottom.config;
  451. if (req->data)
  452. memcpy(req->data, bottom, sizeof(*bottom));
  453. fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
  454. fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
  455. fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
  456. fc_host_speed(shost) = bottom->fc_link_speed;
  457. fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
  458. adapter->hydra_version = bottom->adapter_type;
  459. adapter->timer_ticks = bottom->timer_interval;
  460. if (fc_host_permanent_port_name(shost) == -1)
  461. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  462. switch (bottom->fc_topology) {
  463. case FSF_TOPO_P2P:
  464. adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
  465. adapter->peer_wwpn = bottom->plogi_payload.wwpn;
  466. adapter->peer_wwnn = bottom->plogi_payload.wwnn;
  467. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  468. break;
  469. case FSF_TOPO_FABRIC:
  470. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  471. break;
  472. case FSF_TOPO_AL:
  473. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  474. default:
  475. dev_err(&adapter->ccw_device->dev,
  476. "Unknown or unsupported arbitrated loop "
  477. "fibre channel topology detected\n");
  478. zfcp_erp_adapter_shutdown(adapter, 0, 127, req);
  479. return -EIO;
  480. }
  481. return 0;
  482. }
  483. static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
  484. {
  485. struct zfcp_adapter *adapter = req->adapter;
  486. struct fsf_qtcb *qtcb = req->qtcb;
  487. struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
  488. struct Scsi_Host *shost = adapter->scsi_host;
  489. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  490. return;
  491. adapter->fsf_lic_version = bottom->lic_version;
  492. adapter->adapter_features = bottom->adapter_features;
  493. adapter->connection_features = bottom->connection_features;
  494. adapter->peer_wwpn = 0;
  495. adapter->peer_wwnn = 0;
  496. adapter->peer_d_id = 0;
  497. switch (qtcb->header.fsf_status) {
  498. case FSF_GOOD:
  499. if (zfcp_fsf_exchange_config_evaluate(req))
  500. return;
  501. if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
  502. dev_err(&adapter->ccw_device->dev,
  503. "FCP adapter maximum QTCB size (%d bytes) "
  504. "is too small\n",
  505. bottom->max_qtcb_size);
  506. zfcp_erp_adapter_shutdown(adapter, 0, 129, req);
  507. return;
  508. }
  509. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  510. &adapter->status);
  511. break;
  512. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  513. fc_host_node_name(shost) = 0;
  514. fc_host_port_name(shost) = 0;
  515. fc_host_port_id(shost) = 0;
  516. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  517. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  518. adapter->hydra_version = 0;
  519. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  520. &adapter->status);
  521. zfcp_fsf_link_down_info_eval(req, 42,
  522. &qtcb->header.fsf_status_qual.link_down_info);
  523. break;
  524. default:
  525. zfcp_erp_adapter_shutdown(adapter, 0, 130, req);
  526. return;
  527. }
  528. if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
  529. adapter->hardware_version = bottom->hardware_version;
  530. memcpy(fc_host_serial_number(shost), bottom->serial_number,
  531. min(FC_SERIAL_NUMBER_SIZE, 17));
  532. EBCASC(fc_host_serial_number(shost),
  533. min(FC_SERIAL_NUMBER_SIZE, 17));
  534. }
  535. if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
  536. dev_err(&adapter->ccw_device->dev,
  537. "The FCP adapter only supports newer "
  538. "control block versions\n");
  539. zfcp_erp_adapter_shutdown(adapter, 0, 125, req);
  540. return;
  541. }
  542. if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
  543. dev_err(&adapter->ccw_device->dev,
  544. "The FCP adapter only supports older "
  545. "control block versions\n");
  546. zfcp_erp_adapter_shutdown(adapter, 0, 126, req);
  547. }
  548. }
  549. static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
  550. {
  551. struct zfcp_adapter *adapter = req->adapter;
  552. struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
  553. struct Scsi_Host *shost = adapter->scsi_host;
  554. if (req->data)
  555. memcpy(req->data, bottom, sizeof(*bottom));
  556. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
  557. fc_host_permanent_port_name(shost) = bottom->wwpn;
  558. else
  559. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  560. fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
  561. fc_host_supported_speeds(shost) = bottom->supported_speed;
  562. }
  563. static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
  564. {
  565. struct fsf_qtcb *qtcb = req->qtcb;
  566. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  567. return;
  568. switch (qtcb->header.fsf_status) {
  569. case FSF_GOOD:
  570. zfcp_fsf_exchange_port_evaluate(req);
  571. break;
  572. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  573. zfcp_fsf_exchange_port_evaluate(req);
  574. zfcp_fsf_link_down_info_eval(req, 43,
  575. &qtcb->header.fsf_status_qual.link_down_info);
  576. break;
  577. }
  578. }
  579. static int zfcp_fsf_sbal_check(struct zfcp_adapter *adapter)
  580. {
  581. struct zfcp_qdio_queue *req_q = &adapter->req_q;
  582. spin_lock_bh(&adapter->req_q_lock);
  583. if (atomic_read(&req_q->count))
  584. return 1;
  585. spin_unlock_bh(&adapter->req_q_lock);
  586. return 0;
  587. }
  588. static int zfcp_fsf_sbal_available(struct zfcp_adapter *adapter)
  589. {
  590. unsigned int count = atomic_read(&adapter->req_q.count);
  591. if (!count)
  592. atomic_inc(&adapter->qdio_outb_full);
  593. return count > 0;
  594. }
  595. static int zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter)
  596. {
  597. long ret;
  598. spin_unlock_bh(&adapter->req_q_lock);
  599. ret = wait_event_interruptible_timeout(adapter->request_wq,
  600. zfcp_fsf_sbal_check(adapter), 5 * HZ);
  601. if (ret > 0)
  602. return 0;
  603. if (!ret)
  604. atomic_inc(&adapter->qdio_outb_full);
  605. spin_lock_bh(&adapter->req_q_lock);
  606. return -EIO;
  607. }
  608. static struct zfcp_fsf_req *zfcp_fsf_alloc_noqtcb(mempool_t *pool)
  609. {
  610. struct zfcp_fsf_req *req;
  611. req = mempool_alloc(pool, GFP_ATOMIC);
  612. if (!req)
  613. return NULL;
  614. memset(req, 0, sizeof(*req));
  615. req->pool = pool;
  616. return req;
  617. }
  618. static struct zfcp_fsf_req *zfcp_fsf_alloc_qtcb(mempool_t *pool)
  619. {
  620. struct zfcp_fsf_req_qtcb *qtcb;
  621. if (likely(pool))
  622. qtcb = mempool_alloc(pool, GFP_ATOMIC);
  623. else
  624. qtcb = kmem_cache_alloc(zfcp_data.fsf_req_qtcb_cache,
  625. GFP_ATOMIC);
  626. if (unlikely(!qtcb))
  627. return NULL;
  628. memset(qtcb, 0, sizeof(*qtcb));
  629. qtcb->fsf_req.qtcb = &qtcb->qtcb;
  630. qtcb->fsf_req.pool = pool;
  631. return &qtcb->fsf_req;
  632. }
  633. static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_adapter *adapter,
  634. u32 fsf_cmd, int req_flags,
  635. mempool_t *pool)
  636. {
  637. struct qdio_buffer_element *sbale;
  638. struct zfcp_fsf_req *req;
  639. struct zfcp_qdio_queue *req_q = &adapter->req_q;
  640. if (req_flags & ZFCP_REQ_NO_QTCB)
  641. req = zfcp_fsf_alloc_noqtcb(pool);
  642. else
  643. req = zfcp_fsf_alloc_qtcb(pool);
  644. if (unlikely(!req))
  645. return ERR_PTR(-EIO);
  646. if (adapter->req_no == 0)
  647. adapter->req_no++;
  648. INIT_LIST_HEAD(&req->list);
  649. init_timer(&req->timer);
  650. init_waitqueue_head(&req->completion_wq);
  651. req->adapter = adapter;
  652. req->fsf_command = fsf_cmd;
  653. req->req_id = adapter->req_no++;
  654. req->sbal_number = 1;
  655. req->sbal_first = req_q->first;
  656. req->sbal_last = req_q->first;
  657. req->sbale_curr = 1;
  658. sbale = zfcp_qdio_sbale_req(req);
  659. sbale[0].addr = (void *) req->req_id;
  660. sbale[0].flags |= SBAL_FLAGS0_COMMAND;
  661. if (likely(req->qtcb)) {
  662. req->qtcb->prefix.req_seq_no = req->adapter->fsf_req_seq_no;
  663. req->qtcb->prefix.req_id = req->req_id;
  664. req->qtcb->prefix.ulp_info = 26;
  665. req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
  666. req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
  667. req->qtcb->header.req_handle = req->req_id;
  668. req->qtcb->header.fsf_command = req->fsf_command;
  669. req->seq_no = adapter->fsf_req_seq_no;
  670. req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
  671. sbale[1].addr = (void *) req->qtcb;
  672. sbale[1].length = sizeof(struct fsf_qtcb);
  673. }
  674. if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) {
  675. zfcp_fsf_req_free(req);
  676. return ERR_PTR(-EIO);
  677. }
  678. if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP))
  679. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  680. return req;
  681. }
  682. static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
  683. {
  684. struct zfcp_adapter *adapter = req->adapter;
  685. unsigned long flags;
  686. int idx;
  687. /* put allocated FSF request into hash table */
  688. spin_lock_irqsave(&adapter->req_list_lock, flags);
  689. idx = zfcp_reqlist_hash(req->req_id);
  690. list_add_tail(&req->list, &adapter->req_list[idx]);
  691. spin_unlock_irqrestore(&adapter->req_list_lock, flags);
  692. req->qdio_outb_usage = atomic_read(&adapter->req_q.count);
  693. req->issued = get_clock();
  694. if (zfcp_qdio_send(req)) {
  695. del_timer(&req->timer);
  696. spin_lock_irqsave(&adapter->req_list_lock, flags);
  697. /* lookup request again, list might have changed */
  698. if (zfcp_reqlist_find_safe(adapter, req))
  699. zfcp_reqlist_remove(adapter, req);
  700. spin_unlock_irqrestore(&adapter->req_list_lock, flags);
  701. zfcp_erp_adapter_reopen(adapter, 0, 116, req);
  702. return -EIO;
  703. }
  704. /* Don't increase for unsolicited status */
  705. if (req->qtcb)
  706. adapter->fsf_req_seq_no++;
  707. return 0;
  708. }
  709. /**
  710. * zfcp_fsf_status_read - send status read request
  711. * @adapter: pointer to struct zfcp_adapter
  712. * @req_flags: request flags
  713. * Returns: 0 on success, ERROR otherwise
  714. */
  715. int zfcp_fsf_status_read(struct zfcp_adapter *adapter)
  716. {
  717. struct zfcp_fsf_req *req;
  718. struct fsf_status_read_buffer *sr_buf;
  719. struct qdio_buffer_element *sbale;
  720. int retval = -EIO;
  721. spin_lock_bh(&adapter->req_q_lock);
  722. if (zfcp_fsf_req_sbal_get(adapter))
  723. goto out;
  724. req = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
  725. ZFCP_REQ_NO_QTCB,
  726. adapter->pool.fsf_req_status_read);
  727. if (IS_ERR(req)) {
  728. retval = PTR_ERR(req);
  729. goto out;
  730. }
  731. sbale = zfcp_qdio_sbale_req(req);
  732. sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
  733. sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
  734. req->sbale_curr = 2;
  735. sr_buf = mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
  736. if (!sr_buf) {
  737. retval = -ENOMEM;
  738. goto failed_buf;
  739. }
  740. memset(sr_buf, 0, sizeof(*sr_buf));
  741. req->data = sr_buf;
  742. sbale = zfcp_qdio_sbale_curr(req);
  743. sbale->addr = (void *) sr_buf;
  744. sbale->length = sizeof(*sr_buf);
  745. retval = zfcp_fsf_req_send(req);
  746. if (retval)
  747. goto failed_req_send;
  748. goto out;
  749. failed_req_send:
  750. mempool_free(sr_buf, adapter->pool.data_status_read);
  751. failed_buf:
  752. zfcp_fsf_req_free(req);
  753. zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
  754. out:
  755. spin_unlock_bh(&adapter->req_q_lock);
  756. return retval;
  757. }
  758. static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
  759. {
  760. struct zfcp_unit *unit = req->data;
  761. union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
  762. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  763. return;
  764. switch (req->qtcb->header.fsf_status) {
  765. case FSF_PORT_HANDLE_NOT_VALID:
  766. if (fsq->word[0] == fsq->word[1]) {
  767. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 104,
  768. req);
  769. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  770. }
  771. break;
  772. case FSF_LUN_HANDLE_NOT_VALID:
  773. if (fsq->word[0] == fsq->word[1]) {
  774. zfcp_erp_port_reopen(unit->port, 0, 105, req);
  775. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  776. }
  777. break;
  778. case FSF_FCP_COMMAND_DOES_NOT_EXIST:
  779. req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
  780. break;
  781. case FSF_PORT_BOXED:
  782. zfcp_erp_port_boxed(unit->port, 47, req);
  783. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  784. ZFCP_STATUS_FSFREQ_RETRY;
  785. break;
  786. case FSF_LUN_BOXED:
  787. zfcp_erp_unit_boxed(unit, 48, req);
  788. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  789. ZFCP_STATUS_FSFREQ_RETRY;
  790. break;
  791. case FSF_ADAPTER_STATUS_AVAILABLE:
  792. switch (fsq->word[0]) {
  793. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  794. zfcp_test_link(unit->port);
  795. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  796. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  797. break;
  798. }
  799. break;
  800. case FSF_GOOD:
  801. req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
  802. break;
  803. }
  804. }
  805. /**
  806. * zfcp_fsf_abort_fcp_command - abort running SCSI command
  807. * @old_req_id: unsigned long
  808. * @adapter: pointer to struct zfcp_adapter
  809. * @unit: pointer to struct zfcp_unit
  810. * @req_flags: integer specifying the request flags
  811. * Returns: pointer to struct zfcp_fsf_req
  812. *
  813. * FIXME(design): should be watched by a timeout !!!
  814. */
  815. struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
  816. struct zfcp_adapter *adapter,
  817. struct zfcp_unit *unit,
  818. int req_flags)
  819. {
  820. struct qdio_buffer_element *sbale;
  821. struct zfcp_fsf_req *req = NULL;
  822. spin_lock(&adapter->req_q_lock);
  823. if (!zfcp_fsf_sbal_available(adapter))
  824. goto out;
  825. req = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
  826. req_flags, adapter->pool.fsf_req_abort);
  827. if (IS_ERR(req))
  828. goto out;
  829. if (unlikely(!(atomic_read(&unit->status) &
  830. ZFCP_STATUS_COMMON_UNBLOCKED)))
  831. goto out_error_free;
  832. sbale = zfcp_qdio_sbale_req(req);
  833. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  834. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  835. req->data = unit;
  836. req->handler = zfcp_fsf_abort_fcp_command_handler;
  837. req->qtcb->header.lun_handle = unit->handle;
  838. req->qtcb->header.port_handle = unit->port->handle;
  839. req->qtcb->bottom.support.req_handle = (u64) old_req_id;
  840. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  841. if (!zfcp_fsf_req_send(req))
  842. goto out;
  843. out_error_free:
  844. zfcp_fsf_req_free(req);
  845. req = NULL;
  846. out:
  847. spin_unlock(&adapter->req_q_lock);
  848. return req;
  849. }
  850. static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
  851. {
  852. struct zfcp_adapter *adapter = req->adapter;
  853. struct zfcp_send_ct *send_ct = req->data;
  854. struct fsf_qtcb_header *header = &req->qtcb->header;
  855. send_ct->status = -EINVAL;
  856. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  857. goto skip_fsfstatus;
  858. switch (header->fsf_status) {
  859. case FSF_GOOD:
  860. zfcp_san_dbf_event_ct_response(req);
  861. send_ct->status = 0;
  862. break;
  863. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  864. zfcp_fsf_class_not_supp(req);
  865. break;
  866. case FSF_ADAPTER_STATUS_AVAILABLE:
  867. switch (header->fsf_status_qual.word[0]){
  868. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  869. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  870. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  871. break;
  872. }
  873. break;
  874. case FSF_ACCESS_DENIED:
  875. break;
  876. case FSF_PORT_BOXED:
  877. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  878. ZFCP_STATUS_FSFREQ_RETRY;
  879. break;
  880. case FSF_PORT_HANDLE_NOT_VALID:
  881. zfcp_erp_adapter_reopen(adapter, 0, 106, req);
  882. case FSF_GENERIC_COMMAND_REJECTED:
  883. case FSF_PAYLOAD_SIZE_MISMATCH:
  884. case FSF_REQUEST_SIZE_TOO_LARGE:
  885. case FSF_RESPONSE_SIZE_TOO_LARGE:
  886. case FSF_SBAL_MISMATCH:
  887. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  888. break;
  889. }
  890. skip_fsfstatus:
  891. if (send_ct->handler)
  892. send_ct->handler(send_ct->handler_data);
  893. }
  894. static int zfcp_fsf_setup_sbals(struct zfcp_fsf_req *req,
  895. struct scatterlist *sg_req,
  896. struct scatterlist *sg_resp, int max_sbals)
  897. {
  898. int bytes;
  899. bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
  900. sg_req, max_sbals);
  901. if (bytes <= 0)
  902. return -ENOMEM;
  903. req->qtcb->bottom.support.req_buf_length = bytes;
  904. req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
  905. bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
  906. sg_resp, max_sbals);
  907. if (bytes <= 0)
  908. return -ENOMEM;
  909. req->qtcb->bottom.support.resp_buf_length = bytes;
  910. return 0;
  911. }
  912. /**
  913. * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
  914. * @ct: pointer to struct zfcp_send_ct with data for request
  915. * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
  916. * @erp_action: if non-null the Generic Service request sent within ERP
  917. */
  918. int zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
  919. struct zfcp_erp_action *erp_action)
  920. {
  921. struct zfcp_wka_port *wka_port = ct->wka_port;
  922. struct zfcp_adapter *adapter = wka_port->adapter;
  923. struct zfcp_fsf_req *req;
  924. int ret = -EIO;
  925. spin_lock_bh(&adapter->req_q_lock);
  926. if (zfcp_fsf_req_sbal_get(adapter))
  927. goto out;
  928. req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
  929. ZFCP_REQ_AUTO_CLEANUP, pool);
  930. if (IS_ERR(req)) {
  931. ret = PTR_ERR(req);
  932. goto out;
  933. }
  934. ret = zfcp_fsf_setup_sbals(req, ct->req, ct->resp,
  935. FSF_MAX_SBALS_PER_REQ);
  936. if (ret)
  937. goto failed_send;
  938. req->handler = zfcp_fsf_send_ct_handler;
  939. req->qtcb->header.port_handle = wka_port->handle;
  940. req->qtcb->bottom.support.service_class = FSF_CLASS_3;
  941. req->qtcb->bottom.support.timeout = ct->timeout;
  942. req->data = ct;
  943. zfcp_san_dbf_event_ct_request(req);
  944. if (erp_action) {
  945. erp_action->fsf_req = req;
  946. req->erp_action = erp_action;
  947. zfcp_fsf_start_erp_timer(req);
  948. } else
  949. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  950. ret = zfcp_fsf_req_send(req);
  951. if (ret)
  952. goto failed_send;
  953. goto out;
  954. failed_send:
  955. zfcp_fsf_req_free(req);
  956. if (erp_action)
  957. erp_action->fsf_req = NULL;
  958. out:
  959. spin_unlock_bh(&adapter->req_q_lock);
  960. return ret;
  961. }
  962. static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
  963. {
  964. struct zfcp_send_els *send_els = req->data;
  965. struct zfcp_port *port = send_els->port;
  966. struct fsf_qtcb_header *header = &req->qtcb->header;
  967. send_els->status = -EINVAL;
  968. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  969. goto skip_fsfstatus;
  970. switch (header->fsf_status) {
  971. case FSF_GOOD:
  972. zfcp_san_dbf_event_els_response(req);
  973. send_els->status = 0;
  974. break;
  975. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  976. zfcp_fsf_class_not_supp(req);
  977. break;
  978. case FSF_ADAPTER_STATUS_AVAILABLE:
  979. switch (header->fsf_status_qual.word[0]){
  980. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  981. if (port && (send_els->ls_code != ZFCP_LS_ADISC))
  982. zfcp_test_link(port);
  983. /*fall through */
  984. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  985. case FSF_SQ_RETRY_IF_POSSIBLE:
  986. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  987. break;
  988. }
  989. break;
  990. case FSF_ELS_COMMAND_REJECTED:
  991. case FSF_PAYLOAD_SIZE_MISMATCH:
  992. case FSF_REQUEST_SIZE_TOO_LARGE:
  993. case FSF_RESPONSE_SIZE_TOO_LARGE:
  994. break;
  995. case FSF_ACCESS_DENIED:
  996. zfcp_fsf_access_denied_port(req, port);
  997. break;
  998. case FSF_SBAL_MISMATCH:
  999. /* should never occure, avoided in zfcp_fsf_send_els */
  1000. /* fall through */
  1001. default:
  1002. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1003. break;
  1004. }
  1005. skip_fsfstatus:
  1006. if (send_els->handler)
  1007. send_els->handler(send_els->handler_data);
  1008. }
  1009. /**
  1010. * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
  1011. * @els: pointer to struct zfcp_send_els with data for the command
  1012. */
  1013. int zfcp_fsf_send_els(struct zfcp_send_els *els)
  1014. {
  1015. struct zfcp_fsf_req *req;
  1016. struct zfcp_adapter *adapter = els->adapter;
  1017. struct fsf_qtcb_bottom_support *bottom;
  1018. int ret = -EIO;
  1019. if (unlikely(!(atomic_read(&els->port->status) &
  1020. ZFCP_STATUS_COMMON_UNBLOCKED)))
  1021. return -EBUSY;
  1022. spin_lock(&adapter->req_q_lock);
  1023. if (!zfcp_fsf_sbal_available(adapter))
  1024. goto out;
  1025. req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
  1026. ZFCP_REQ_AUTO_CLEANUP, NULL);
  1027. if (IS_ERR(req)) {
  1028. ret = PTR_ERR(req);
  1029. goto out;
  1030. }
  1031. ret = zfcp_fsf_setup_sbals(req, els->req, els->resp, 2);
  1032. if (ret)
  1033. goto failed_send;
  1034. bottom = &req->qtcb->bottom.support;
  1035. req->handler = zfcp_fsf_send_els_handler;
  1036. bottom->d_id = els->d_id;
  1037. bottom->service_class = FSF_CLASS_3;
  1038. bottom->timeout = 2 * R_A_TOV;
  1039. req->data = els;
  1040. zfcp_san_dbf_event_els_request(req);
  1041. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1042. ret = zfcp_fsf_req_send(req);
  1043. if (ret)
  1044. goto failed_send;
  1045. goto out;
  1046. failed_send:
  1047. zfcp_fsf_req_free(req);
  1048. out:
  1049. spin_unlock(&adapter->req_q_lock);
  1050. return ret;
  1051. }
  1052. int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
  1053. {
  1054. struct qdio_buffer_element *sbale;
  1055. struct zfcp_fsf_req *req;
  1056. struct zfcp_adapter *adapter = erp_action->adapter;
  1057. int retval = -EIO;
  1058. spin_lock_bh(&adapter->req_q_lock);
  1059. if (!zfcp_fsf_sbal_available(adapter))
  1060. goto out;
  1061. req = zfcp_fsf_req_create(adapter,
  1062. FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1063. ZFCP_REQ_AUTO_CLEANUP,
  1064. adapter->pool.fsf_req_erp);
  1065. if (IS_ERR(req)) {
  1066. retval = PTR_ERR(req);
  1067. goto out;
  1068. }
  1069. sbale = zfcp_qdio_sbale_req(req);
  1070. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1071. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1072. req->qtcb->bottom.config.feature_selection =
  1073. FSF_FEATURE_CFDC |
  1074. FSF_FEATURE_LUN_SHARING |
  1075. FSF_FEATURE_NOTIFICATION_LOST |
  1076. FSF_FEATURE_UPDATE_ALERT;
  1077. req->erp_action = erp_action;
  1078. req->handler = zfcp_fsf_exchange_config_data_handler;
  1079. erp_action->fsf_req = req;
  1080. zfcp_fsf_start_erp_timer(req);
  1081. retval = zfcp_fsf_req_send(req);
  1082. if (retval) {
  1083. zfcp_fsf_req_free(req);
  1084. erp_action->fsf_req = NULL;
  1085. }
  1086. out:
  1087. spin_unlock_bh(&adapter->req_q_lock);
  1088. return retval;
  1089. }
  1090. int zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter,
  1091. struct fsf_qtcb_bottom_config *data)
  1092. {
  1093. struct qdio_buffer_element *sbale;
  1094. struct zfcp_fsf_req *req = NULL;
  1095. int retval = -EIO;
  1096. spin_lock_bh(&adapter->req_q_lock);
  1097. if (zfcp_fsf_req_sbal_get(adapter))
  1098. goto out;
  1099. req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1100. 0, NULL);
  1101. if (IS_ERR(req)) {
  1102. retval = PTR_ERR(req);
  1103. goto out;
  1104. }
  1105. sbale = zfcp_qdio_sbale_req(req);
  1106. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1107. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1108. req->handler = zfcp_fsf_exchange_config_data_handler;
  1109. req->qtcb->bottom.config.feature_selection =
  1110. FSF_FEATURE_CFDC |
  1111. FSF_FEATURE_LUN_SHARING |
  1112. FSF_FEATURE_NOTIFICATION_LOST |
  1113. FSF_FEATURE_UPDATE_ALERT;
  1114. if (data)
  1115. req->data = data;
  1116. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1117. retval = zfcp_fsf_req_send(req);
  1118. out:
  1119. spin_unlock_bh(&adapter->req_q_lock);
  1120. if (!retval)
  1121. wait_event(req->completion_wq,
  1122. req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  1123. zfcp_fsf_req_free(req);
  1124. return retval;
  1125. }
  1126. /**
  1127. * zfcp_fsf_exchange_port_data - request information about local port
  1128. * @erp_action: ERP action for the adapter for which port data is requested
  1129. * Returns: 0 on success, error otherwise
  1130. */
  1131. int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
  1132. {
  1133. struct qdio_buffer_element *sbale;
  1134. struct zfcp_fsf_req *req;
  1135. struct zfcp_adapter *adapter = erp_action->adapter;
  1136. int retval = -EIO;
  1137. if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1138. return -EOPNOTSUPP;
  1139. spin_lock_bh(&adapter->req_q_lock);
  1140. if (!zfcp_fsf_sbal_available(adapter))
  1141. goto out;
  1142. req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
  1143. ZFCP_REQ_AUTO_CLEANUP,
  1144. adapter->pool.fsf_req_erp);
  1145. if (IS_ERR(req)) {
  1146. retval = PTR_ERR(req);
  1147. goto out;
  1148. }
  1149. sbale = zfcp_qdio_sbale_req(req);
  1150. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1151. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1152. req->handler = zfcp_fsf_exchange_port_data_handler;
  1153. req->erp_action = erp_action;
  1154. erp_action->fsf_req = req;
  1155. zfcp_fsf_start_erp_timer(req);
  1156. retval = zfcp_fsf_req_send(req);
  1157. if (retval) {
  1158. zfcp_fsf_req_free(req);
  1159. erp_action->fsf_req = NULL;
  1160. }
  1161. out:
  1162. spin_unlock_bh(&adapter->req_q_lock);
  1163. return retval;
  1164. }
  1165. /**
  1166. * zfcp_fsf_exchange_port_data_sync - request information about local port
  1167. * @adapter: pointer to struct zfcp_adapter
  1168. * @data: pointer to struct fsf_qtcb_bottom_port
  1169. * Returns: 0 on success, error otherwise
  1170. */
  1171. int zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter,
  1172. struct fsf_qtcb_bottom_port *data)
  1173. {
  1174. struct qdio_buffer_element *sbale;
  1175. struct zfcp_fsf_req *req = NULL;
  1176. int retval = -EIO;
  1177. if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1178. return -EOPNOTSUPP;
  1179. spin_lock_bh(&adapter->req_q_lock);
  1180. if (!zfcp_fsf_sbal_available(adapter))
  1181. goto out;
  1182. req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, 0,
  1183. NULL);
  1184. if (IS_ERR(req)) {
  1185. retval = PTR_ERR(req);
  1186. goto out;
  1187. }
  1188. if (data)
  1189. req->data = data;
  1190. sbale = zfcp_qdio_sbale_req(req);
  1191. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1192. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1193. req->handler = zfcp_fsf_exchange_port_data_handler;
  1194. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1195. retval = zfcp_fsf_req_send(req);
  1196. out:
  1197. spin_unlock_bh(&adapter->req_q_lock);
  1198. if (!retval)
  1199. wait_event(req->completion_wq,
  1200. req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  1201. zfcp_fsf_req_free(req);
  1202. return retval;
  1203. }
  1204. static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
  1205. {
  1206. struct zfcp_port *port = req->data;
  1207. struct fsf_qtcb_header *header = &req->qtcb->header;
  1208. struct fsf_plogi *plogi;
  1209. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1210. return;
  1211. switch (header->fsf_status) {
  1212. case FSF_PORT_ALREADY_OPEN:
  1213. break;
  1214. case FSF_ACCESS_DENIED:
  1215. zfcp_fsf_access_denied_port(req, port);
  1216. break;
  1217. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1218. dev_warn(&req->adapter->ccw_device->dev,
  1219. "Not enough FCP adapter resources to open "
  1220. "remote port 0x%016Lx\n",
  1221. (unsigned long long)port->wwpn);
  1222. zfcp_erp_port_failed(port, 31, req);
  1223. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1224. break;
  1225. case FSF_ADAPTER_STATUS_AVAILABLE:
  1226. switch (header->fsf_status_qual.word[0]) {
  1227. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1228. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1229. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1230. break;
  1231. case FSF_SQ_NO_RETRY_POSSIBLE:
  1232. dev_warn(&req->adapter->ccw_device->dev,
  1233. "Remote port 0x%016Lx could not be opened\n",
  1234. (unsigned long long)port->wwpn);
  1235. zfcp_erp_port_failed(port, 32, req);
  1236. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1237. break;
  1238. }
  1239. break;
  1240. case FSF_GOOD:
  1241. port->handle = header->port_handle;
  1242. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
  1243. ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1244. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1245. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  1246. &port->status);
  1247. /* check whether D_ID has changed during open */
  1248. /*
  1249. * FIXME: This check is not airtight, as the FCP channel does
  1250. * not monitor closures of target port connections caused on
  1251. * the remote side. Thus, they might miss out on invalidating
  1252. * locally cached WWPNs (and other N_Port parameters) of gone
  1253. * target ports. So, our heroic attempt to make things safe
  1254. * could be undermined by 'open port' response data tagged with
  1255. * obsolete WWPNs. Another reason to monitor potential
  1256. * connection closures ourself at least (by interpreting
  1257. * incoming ELS' and unsolicited status). It just crosses my
  1258. * mind that one should be able to cross-check by means of
  1259. * another GID_PN straight after a port has been opened.
  1260. * Alternately, an ADISC/PDISC ELS should suffice, as well.
  1261. */
  1262. plogi = (struct fsf_plogi *) req->qtcb->bottom.support.els;
  1263. if (req->qtcb->bottom.support.els1_length >= sizeof(*plogi)) {
  1264. if (plogi->serv_param.wwpn != port->wwpn)
  1265. atomic_clear_mask(ZFCP_STATUS_PORT_DID_DID,
  1266. &port->status);
  1267. else {
  1268. port->wwnn = plogi->serv_param.wwnn;
  1269. zfcp_fc_plogi_evaluate(port, plogi);
  1270. }
  1271. }
  1272. break;
  1273. case FSF_UNKNOWN_OP_SUBTYPE:
  1274. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1275. break;
  1276. }
  1277. }
  1278. /**
  1279. * zfcp_fsf_open_port - create and send open port request
  1280. * @erp_action: pointer to struct zfcp_erp_action
  1281. * Returns: 0 on success, error otherwise
  1282. */
  1283. int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
  1284. {
  1285. struct qdio_buffer_element *sbale;
  1286. struct zfcp_adapter *adapter = erp_action->adapter;
  1287. struct zfcp_fsf_req *req;
  1288. int retval = -EIO;
  1289. spin_lock_bh(&adapter->req_q_lock);
  1290. if (zfcp_fsf_req_sbal_get(adapter))
  1291. goto out;
  1292. req = zfcp_fsf_req_create(adapter,
  1293. FSF_QTCB_OPEN_PORT_WITH_DID,
  1294. ZFCP_REQ_AUTO_CLEANUP,
  1295. adapter->pool.fsf_req_erp);
  1296. if (IS_ERR(req)) {
  1297. retval = PTR_ERR(req);
  1298. goto out;
  1299. }
  1300. sbale = zfcp_qdio_sbale_req(req);
  1301. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1302. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1303. req->handler = zfcp_fsf_open_port_handler;
  1304. req->qtcb->bottom.support.d_id = erp_action->port->d_id;
  1305. req->data = erp_action->port;
  1306. req->erp_action = erp_action;
  1307. erp_action->fsf_req = req;
  1308. zfcp_fsf_start_erp_timer(req);
  1309. retval = zfcp_fsf_req_send(req);
  1310. if (retval) {
  1311. zfcp_fsf_req_free(req);
  1312. erp_action->fsf_req = NULL;
  1313. }
  1314. out:
  1315. spin_unlock_bh(&adapter->req_q_lock);
  1316. return retval;
  1317. }
  1318. static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
  1319. {
  1320. struct zfcp_port *port = req->data;
  1321. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1322. return;
  1323. switch (req->qtcb->header.fsf_status) {
  1324. case FSF_PORT_HANDLE_NOT_VALID:
  1325. zfcp_erp_adapter_reopen(port->adapter, 0, 107, req);
  1326. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1327. break;
  1328. case FSF_ADAPTER_STATUS_AVAILABLE:
  1329. break;
  1330. case FSF_GOOD:
  1331. zfcp_erp_modify_port_status(port, 33, req,
  1332. ZFCP_STATUS_COMMON_OPEN,
  1333. ZFCP_CLEAR);
  1334. break;
  1335. }
  1336. }
  1337. /**
  1338. * zfcp_fsf_close_port - create and send close port request
  1339. * @erp_action: pointer to struct zfcp_erp_action
  1340. * Returns: 0 on success, error otherwise
  1341. */
  1342. int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
  1343. {
  1344. struct qdio_buffer_element *sbale;
  1345. struct zfcp_adapter *adapter = erp_action->adapter;
  1346. struct zfcp_fsf_req *req;
  1347. int retval = -EIO;
  1348. spin_lock_bh(&adapter->req_q_lock);
  1349. if (zfcp_fsf_req_sbal_get(adapter))
  1350. goto out;
  1351. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT,
  1352. ZFCP_REQ_AUTO_CLEANUP,
  1353. adapter->pool.fsf_req_erp);
  1354. if (IS_ERR(req)) {
  1355. retval = PTR_ERR(req);
  1356. goto out;
  1357. }
  1358. sbale = zfcp_qdio_sbale_req(req);
  1359. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1360. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1361. req->handler = zfcp_fsf_close_port_handler;
  1362. req->data = erp_action->port;
  1363. req->erp_action = erp_action;
  1364. req->qtcb->header.port_handle = erp_action->port->handle;
  1365. erp_action->fsf_req = req;
  1366. zfcp_fsf_start_erp_timer(req);
  1367. retval = zfcp_fsf_req_send(req);
  1368. if (retval) {
  1369. zfcp_fsf_req_free(req);
  1370. erp_action->fsf_req = NULL;
  1371. }
  1372. out:
  1373. spin_unlock_bh(&adapter->req_q_lock);
  1374. return retval;
  1375. }
  1376. static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
  1377. {
  1378. struct zfcp_wka_port *wka_port = req->data;
  1379. struct fsf_qtcb_header *header = &req->qtcb->header;
  1380. if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  1381. wka_port->status = ZFCP_WKA_PORT_OFFLINE;
  1382. goto out;
  1383. }
  1384. switch (header->fsf_status) {
  1385. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1386. dev_warn(&req->adapter->ccw_device->dev,
  1387. "Opening WKA port 0x%x failed\n", wka_port->d_id);
  1388. case FSF_ADAPTER_STATUS_AVAILABLE:
  1389. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1390. case FSF_ACCESS_DENIED:
  1391. wka_port->status = ZFCP_WKA_PORT_OFFLINE;
  1392. break;
  1393. case FSF_PORT_ALREADY_OPEN:
  1394. case FSF_GOOD:
  1395. wka_port->handle = header->port_handle;
  1396. wka_port->status = ZFCP_WKA_PORT_ONLINE;
  1397. }
  1398. out:
  1399. wake_up(&wka_port->completion_wq);
  1400. }
  1401. /**
  1402. * zfcp_fsf_open_wka_port - create and send open wka-port request
  1403. * @wka_port: pointer to struct zfcp_wka_port
  1404. * Returns: 0 on success, error otherwise
  1405. */
  1406. int zfcp_fsf_open_wka_port(struct zfcp_wka_port *wka_port)
  1407. {
  1408. struct qdio_buffer_element *sbale;
  1409. struct zfcp_adapter *adapter = wka_port->adapter;
  1410. struct zfcp_fsf_req *req;
  1411. int retval = -EIO;
  1412. spin_lock_bh(&adapter->req_q_lock);
  1413. if (zfcp_fsf_req_sbal_get(adapter))
  1414. goto out;
  1415. req = zfcp_fsf_req_create(adapter,
  1416. FSF_QTCB_OPEN_PORT_WITH_DID,
  1417. ZFCP_REQ_AUTO_CLEANUP,
  1418. adapter->pool.fsf_req_erp);
  1419. if (unlikely(IS_ERR(req))) {
  1420. retval = PTR_ERR(req);
  1421. goto out;
  1422. }
  1423. sbale = zfcp_qdio_sbale_req(req);
  1424. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1425. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1426. req->handler = zfcp_fsf_open_wka_port_handler;
  1427. req->qtcb->bottom.support.d_id = wka_port->d_id;
  1428. req->data = wka_port;
  1429. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1430. retval = zfcp_fsf_req_send(req);
  1431. if (retval)
  1432. zfcp_fsf_req_free(req);
  1433. out:
  1434. spin_unlock_bh(&adapter->req_q_lock);
  1435. return retval;
  1436. }
  1437. static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
  1438. {
  1439. struct zfcp_wka_port *wka_port = req->data;
  1440. if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
  1441. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1442. zfcp_erp_adapter_reopen(wka_port->adapter, 0, 84, req);
  1443. }
  1444. wka_port->status = ZFCP_WKA_PORT_OFFLINE;
  1445. wake_up(&wka_port->completion_wq);
  1446. }
  1447. /**
  1448. * zfcp_fsf_close_wka_port - create and send close wka port request
  1449. * @erp_action: pointer to struct zfcp_erp_action
  1450. * Returns: 0 on success, error otherwise
  1451. */
  1452. int zfcp_fsf_close_wka_port(struct zfcp_wka_port *wka_port)
  1453. {
  1454. struct qdio_buffer_element *sbale;
  1455. struct zfcp_adapter *adapter = wka_port->adapter;
  1456. struct zfcp_fsf_req *req;
  1457. int retval = -EIO;
  1458. spin_lock_bh(&adapter->req_q_lock);
  1459. if (zfcp_fsf_req_sbal_get(adapter))
  1460. goto out;
  1461. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT,
  1462. ZFCP_REQ_AUTO_CLEANUP,
  1463. adapter->pool.fsf_req_erp);
  1464. if (unlikely(IS_ERR(req))) {
  1465. retval = PTR_ERR(req);
  1466. goto out;
  1467. }
  1468. sbale = zfcp_qdio_sbale_req(req);
  1469. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1470. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1471. req->handler = zfcp_fsf_close_wka_port_handler;
  1472. req->data = wka_port;
  1473. req->qtcb->header.port_handle = wka_port->handle;
  1474. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1475. retval = zfcp_fsf_req_send(req);
  1476. if (retval)
  1477. zfcp_fsf_req_free(req);
  1478. out:
  1479. spin_unlock_bh(&adapter->req_q_lock);
  1480. return retval;
  1481. }
  1482. static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
  1483. {
  1484. struct zfcp_port *port = req->data;
  1485. struct fsf_qtcb_header *header = &req->qtcb->header;
  1486. struct zfcp_unit *unit;
  1487. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1488. goto skip_fsfstatus;
  1489. switch (header->fsf_status) {
  1490. case FSF_PORT_HANDLE_NOT_VALID:
  1491. zfcp_erp_adapter_reopen(port->adapter, 0, 108, req);
  1492. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1493. break;
  1494. case FSF_ACCESS_DENIED:
  1495. zfcp_fsf_access_denied_port(req, port);
  1496. break;
  1497. case FSF_PORT_BOXED:
  1498. zfcp_erp_port_boxed(port, 50, req);
  1499. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1500. ZFCP_STATUS_FSFREQ_RETRY;
  1501. /* can't use generic zfcp_erp_modify_port_status because
  1502. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
  1503. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1504. list_for_each_entry(unit, &port->unit_list_head, list)
  1505. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1506. &unit->status);
  1507. break;
  1508. case FSF_ADAPTER_STATUS_AVAILABLE:
  1509. switch (header->fsf_status_qual.word[0]) {
  1510. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1511. /* fall through */
  1512. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1513. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1514. break;
  1515. }
  1516. break;
  1517. case FSF_GOOD:
  1518. /* can't use generic zfcp_erp_modify_port_status because
  1519. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
  1520. */
  1521. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1522. list_for_each_entry(unit, &port->unit_list_head, list)
  1523. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1524. &unit->status);
  1525. break;
  1526. }
  1527. skip_fsfstatus:
  1528. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
  1529. }
  1530. /**
  1531. * zfcp_fsf_close_physical_port - close physical port
  1532. * @erp_action: pointer to struct zfcp_erp_action
  1533. * Returns: 0 on success
  1534. */
  1535. int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
  1536. {
  1537. struct qdio_buffer_element *sbale;
  1538. struct zfcp_adapter *adapter = erp_action->adapter;
  1539. struct zfcp_fsf_req *req;
  1540. int retval = -EIO;
  1541. spin_lock_bh(&adapter->req_q_lock);
  1542. if (zfcp_fsf_req_sbal_get(adapter))
  1543. goto out;
  1544. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PHYSICAL_PORT,
  1545. ZFCP_REQ_AUTO_CLEANUP,
  1546. adapter->pool.fsf_req_erp);
  1547. if (IS_ERR(req)) {
  1548. retval = PTR_ERR(req);
  1549. goto out;
  1550. }
  1551. sbale = zfcp_qdio_sbale_req(req);
  1552. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1553. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1554. req->data = erp_action->port;
  1555. req->qtcb->header.port_handle = erp_action->port->handle;
  1556. req->erp_action = erp_action;
  1557. req->handler = zfcp_fsf_close_physical_port_handler;
  1558. erp_action->fsf_req = req;
  1559. atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
  1560. &erp_action->port->status);
  1561. zfcp_fsf_start_erp_timer(req);
  1562. retval = zfcp_fsf_req_send(req);
  1563. if (retval) {
  1564. zfcp_fsf_req_free(req);
  1565. erp_action->fsf_req = NULL;
  1566. }
  1567. out:
  1568. spin_unlock_bh(&adapter->req_q_lock);
  1569. return retval;
  1570. }
  1571. static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
  1572. {
  1573. struct zfcp_adapter *adapter = req->adapter;
  1574. struct zfcp_unit *unit = req->data;
  1575. struct fsf_qtcb_header *header = &req->qtcb->header;
  1576. struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
  1577. struct fsf_queue_designator *queue_designator =
  1578. &header->fsf_status_qual.fsf_queue_designator;
  1579. int exclusive, readwrite;
  1580. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1581. return;
  1582. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1583. ZFCP_STATUS_COMMON_ACCESS_BOXED |
  1584. ZFCP_STATUS_UNIT_SHARED |
  1585. ZFCP_STATUS_UNIT_READONLY,
  1586. &unit->status);
  1587. switch (header->fsf_status) {
  1588. case FSF_PORT_HANDLE_NOT_VALID:
  1589. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 109, req);
  1590. /* fall through */
  1591. case FSF_LUN_ALREADY_OPEN:
  1592. break;
  1593. case FSF_ACCESS_DENIED:
  1594. zfcp_fsf_access_denied_unit(req, unit);
  1595. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1596. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1597. break;
  1598. case FSF_PORT_BOXED:
  1599. zfcp_erp_port_boxed(unit->port, 51, req);
  1600. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1601. ZFCP_STATUS_FSFREQ_RETRY;
  1602. break;
  1603. case FSF_LUN_SHARING_VIOLATION:
  1604. if (header->fsf_status_qual.word[0])
  1605. dev_warn(&adapter->ccw_device->dev,
  1606. "LUN 0x%Lx on port 0x%Lx is already in "
  1607. "use by CSS%d, MIF Image ID %x\n",
  1608. (unsigned long long)unit->fcp_lun,
  1609. (unsigned long long)unit->port->wwpn,
  1610. queue_designator->cssid,
  1611. queue_designator->hla);
  1612. else
  1613. zfcp_act_eval_err(adapter,
  1614. header->fsf_status_qual.word[2]);
  1615. zfcp_erp_unit_access_denied(unit, 60, req);
  1616. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1617. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1618. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1619. break;
  1620. case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
  1621. dev_warn(&adapter->ccw_device->dev,
  1622. "No handle is available for LUN "
  1623. "0x%016Lx on port 0x%016Lx\n",
  1624. (unsigned long long)unit->fcp_lun,
  1625. (unsigned long long)unit->port->wwpn);
  1626. zfcp_erp_unit_failed(unit, 34, req);
  1627. /* fall through */
  1628. case FSF_INVALID_COMMAND_OPTION:
  1629. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1630. break;
  1631. case FSF_ADAPTER_STATUS_AVAILABLE:
  1632. switch (header->fsf_status_qual.word[0]) {
  1633. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1634. zfcp_test_link(unit->port);
  1635. /* fall through */
  1636. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1637. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1638. break;
  1639. }
  1640. break;
  1641. case FSF_GOOD:
  1642. unit->handle = header->lun_handle;
  1643. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1644. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
  1645. (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
  1646. (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
  1647. exclusive = (bottom->lun_access_info &
  1648. FSF_UNIT_ACCESS_EXCLUSIVE);
  1649. readwrite = (bottom->lun_access_info &
  1650. FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
  1651. if (!exclusive)
  1652. atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
  1653. &unit->status);
  1654. if (!readwrite) {
  1655. atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
  1656. &unit->status);
  1657. dev_info(&adapter->ccw_device->dev,
  1658. "SCSI device at LUN 0x%016Lx on port "
  1659. "0x%016Lx opened read-only\n",
  1660. (unsigned long long)unit->fcp_lun,
  1661. (unsigned long long)unit->port->wwpn);
  1662. }
  1663. if (exclusive && !readwrite) {
  1664. dev_err(&adapter->ccw_device->dev,
  1665. "Exclusive read-only access not "
  1666. "supported (unit 0x%016Lx, "
  1667. "port 0x%016Lx)\n",
  1668. (unsigned long long)unit->fcp_lun,
  1669. (unsigned long long)unit->port->wwpn);
  1670. zfcp_erp_unit_failed(unit, 35, req);
  1671. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1672. zfcp_erp_unit_shutdown(unit, 0, 80, req);
  1673. } else if (!exclusive && readwrite) {
  1674. dev_err(&adapter->ccw_device->dev,
  1675. "Shared read-write access not "
  1676. "supported (unit 0x%016Lx, port "
  1677. "0x%016Lx\n)",
  1678. (unsigned long long)unit->fcp_lun,
  1679. (unsigned long long)unit->port->wwpn);
  1680. zfcp_erp_unit_failed(unit, 36, req);
  1681. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1682. zfcp_erp_unit_shutdown(unit, 0, 81, req);
  1683. }
  1684. }
  1685. break;
  1686. }
  1687. }
  1688. /**
  1689. * zfcp_fsf_open_unit - open unit
  1690. * @erp_action: pointer to struct zfcp_erp_action
  1691. * Returns: 0 on success, error otherwise
  1692. */
  1693. int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
  1694. {
  1695. struct qdio_buffer_element *sbale;
  1696. struct zfcp_adapter *adapter = erp_action->adapter;
  1697. struct zfcp_fsf_req *req;
  1698. int retval = -EIO;
  1699. spin_lock_bh(&adapter->req_q_lock);
  1700. if (zfcp_fsf_req_sbal_get(adapter))
  1701. goto out;
  1702. req = zfcp_fsf_req_create(adapter, FSF_QTCB_OPEN_LUN,
  1703. ZFCP_REQ_AUTO_CLEANUP,
  1704. adapter->pool.fsf_req_erp);
  1705. if (IS_ERR(req)) {
  1706. retval = PTR_ERR(req);
  1707. goto out;
  1708. }
  1709. sbale = zfcp_qdio_sbale_req(req);
  1710. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1711. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1712. req->qtcb->header.port_handle = erp_action->port->handle;
  1713. req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
  1714. req->handler = zfcp_fsf_open_unit_handler;
  1715. req->data = erp_action->unit;
  1716. req->erp_action = erp_action;
  1717. erp_action->fsf_req = req;
  1718. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
  1719. req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
  1720. zfcp_fsf_start_erp_timer(req);
  1721. retval = zfcp_fsf_req_send(req);
  1722. if (retval) {
  1723. zfcp_fsf_req_free(req);
  1724. erp_action->fsf_req = NULL;
  1725. }
  1726. out:
  1727. spin_unlock_bh(&adapter->req_q_lock);
  1728. return retval;
  1729. }
  1730. static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
  1731. {
  1732. struct zfcp_unit *unit = req->data;
  1733. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1734. return;
  1735. switch (req->qtcb->header.fsf_status) {
  1736. case FSF_PORT_HANDLE_NOT_VALID:
  1737. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 110, req);
  1738. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1739. break;
  1740. case FSF_LUN_HANDLE_NOT_VALID:
  1741. zfcp_erp_port_reopen(unit->port, 0, 111, req);
  1742. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1743. break;
  1744. case FSF_PORT_BOXED:
  1745. zfcp_erp_port_boxed(unit->port, 52, req);
  1746. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1747. ZFCP_STATUS_FSFREQ_RETRY;
  1748. break;
  1749. case FSF_ADAPTER_STATUS_AVAILABLE:
  1750. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  1751. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1752. zfcp_test_link(unit->port);
  1753. /* fall through */
  1754. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1755. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1756. break;
  1757. }
  1758. break;
  1759. case FSF_GOOD:
  1760. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1761. break;
  1762. }
  1763. }
  1764. /**
  1765. * zfcp_fsf_close_unit - close zfcp unit
  1766. * @erp_action: pointer to struct zfcp_unit
  1767. * Returns: 0 on success, error otherwise
  1768. */
  1769. int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
  1770. {
  1771. struct qdio_buffer_element *sbale;
  1772. struct zfcp_adapter *adapter = erp_action->adapter;
  1773. struct zfcp_fsf_req *req;
  1774. int retval = -EIO;
  1775. spin_lock_bh(&adapter->req_q_lock);
  1776. if (zfcp_fsf_req_sbal_get(adapter))
  1777. goto out;
  1778. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_LUN,
  1779. ZFCP_REQ_AUTO_CLEANUP,
  1780. adapter->pool.fsf_req_erp);
  1781. if (IS_ERR(req)) {
  1782. retval = PTR_ERR(req);
  1783. goto out;
  1784. }
  1785. sbale = zfcp_qdio_sbale_req(req);
  1786. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1787. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1788. req->qtcb->header.port_handle = erp_action->port->handle;
  1789. req->qtcb->header.lun_handle = erp_action->unit->handle;
  1790. req->handler = zfcp_fsf_close_unit_handler;
  1791. req->data = erp_action->unit;
  1792. req->erp_action = erp_action;
  1793. erp_action->fsf_req = req;
  1794. zfcp_fsf_start_erp_timer(req);
  1795. retval = zfcp_fsf_req_send(req);
  1796. if (retval) {
  1797. zfcp_fsf_req_free(req);
  1798. erp_action->fsf_req = NULL;
  1799. }
  1800. out:
  1801. spin_unlock_bh(&adapter->req_q_lock);
  1802. return retval;
  1803. }
  1804. static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
  1805. {
  1806. lat_rec->sum += lat;
  1807. lat_rec->min = min(lat_rec->min, lat);
  1808. lat_rec->max = max(lat_rec->max, lat);
  1809. }
  1810. static void zfcp_fsf_req_latency(struct zfcp_fsf_req *req)
  1811. {
  1812. struct fsf_qual_latency_info *lat_inf;
  1813. struct latency_cont *lat;
  1814. struct zfcp_unit *unit = req->unit;
  1815. unsigned long flags;
  1816. lat_inf = &req->qtcb->prefix.prot_status_qual.latency_info;
  1817. switch (req->qtcb->bottom.io.data_direction) {
  1818. case FSF_DATADIR_READ:
  1819. lat = &unit->latencies.read;
  1820. break;
  1821. case FSF_DATADIR_WRITE:
  1822. lat = &unit->latencies.write;
  1823. break;
  1824. case FSF_DATADIR_CMND:
  1825. lat = &unit->latencies.cmd;
  1826. break;
  1827. default:
  1828. return;
  1829. }
  1830. spin_lock_irqsave(&unit->latencies.lock, flags);
  1831. zfcp_fsf_update_lat(&lat->channel, lat_inf->channel_lat);
  1832. zfcp_fsf_update_lat(&lat->fabric, lat_inf->fabric_lat);
  1833. lat->counter++;
  1834. spin_unlock_irqrestore(&unit->latencies.lock, flags);
  1835. }
  1836. #ifdef CONFIG_BLK_DEV_IO_TRACE
  1837. static void zfcp_fsf_trace_latency(struct zfcp_fsf_req *fsf_req)
  1838. {
  1839. struct fsf_qual_latency_info *lat_inf;
  1840. struct scsi_cmnd *scsi_cmnd = (struct scsi_cmnd *)fsf_req->data;
  1841. struct request *req = scsi_cmnd->request;
  1842. struct zfcp_blk_drv_data trace;
  1843. int ticks = fsf_req->adapter->timer_ticks;
  1844. trace.flags = 0;
  1845. trace.magic = ZFCP_BLK_DRV_DATA_MAGIC;
  1846. if (fsf_req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) {
  1847. trace.flags |= ZFCP_BLK_LAT_VALID;
  1848. lat_inf = &fsf_req->qtcb->prefix.prot_status_qual.latency_info;
  1849. trace.channel_lat = lat_inf->channel_lat * ticks;
  1850. trace.fabric_lat = lat_inf->fabric_lat * ticks;
  1851. }
  1852. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1853. trace.flags |= ZFCP_BLK_REQ_ERROR;
  1854. trace.inb_usage = fsf_req->qdio_inb_usage;
  1855. trace.outb_usage = fsf_req->qdio_outb_usage;
  1856. blk_add_driver_data(req->q, req, &trace, sizeof(trace));
  1857. }
  1858. #else
  1859. static inline void zfcp_fsf_trace_latency(struct zfcp_fsf_req *fsf_req)
  1860. {
  1861. }
  1862. #endif
  1863. static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
  1864. {
  1865. struct scsi_cmnd *scpnt = req->data;
  1866. struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
  1867. &(req->qtcb->bottom.io.fcp_rsp);
  1868. u32 sns_len;
  1869. char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
  1870. unsigned long flags;
  1871. if (unlikely(!scpnt))
  1872. return;
  1873. read_lock_irqsave(&req->adapter->abort_lock, flags);
  1874. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
  1875. set_host_byte(scpnt, DID_SOFT_ERROR);
  1876. set_driver_byte(scpnt, SUGGEST_RETRY);
  1877. goto skip_fsfstatus;
  1878. }
  1879. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1880. set_host_byte(scpnt, DID_ERROR);
  1881. goto skip_fsfstatus;
  1882. }
  1883. set_msg_byte(scpnt, COMMAND_COMPLETE);
  1884. scpnt->result |= fcp_rsp_iu->scsi_status;
  1885. if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)
  1886. zfcp_fsf_req_latency(req);
  1887. zfcp_fsf_trace_latency(req);
  1888. if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
  1889. if (fcp_rsp_info[3] == RSP_CODE_GOOD)
  1890. set_host_byte(scpnt, DID_OK);
  1891. else {
  1892. set_host_byte(scpnt, DID_ERROR);
  1893. goto skip_fsfstatus;
  1894. }
  1895. }
  1896. if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
  1897. sns_len = FSF_FCP_RSP_SIZE - sizeof(struct fcp_rsp_iu) +
  1898. fcp_rsp_iu->fcp_rsp_len;
  1899. sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
  1900. sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
  1901. memcpy(scpnt->sense_buffer,
  1902. zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
  1903. }
  1904. if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
  1905. scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
  1906. if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
  1907. scpnt->underflow)
  1908. set_host_byte(scpnt, DID_ERROR);
  1909. }
  1910. skip_fsfstatus:
  1911. if (scpnt->result != 0)
  1912. zfcp_scsi_dbf_event_result("erro", 3, req->adapter, scpnt, req);
  1913. else if (scpnt->retries > 0)
  1914. zfcp_scsi_dbf_event_result("retr", 4, req->adapter, scpnt, req);
  1915. else
  1916. zfcp_scsi_dbf_event_result("norm", 6, req->adapter, scpnt, req);
  1917. scpnt->host_scribble = NULL;
  1918. (scpnt->scsi_done) (scpnt);
  1919. /*
  1920. * We must hold this lock until scsi_done has been called.
  1921. * Otherwise we may call scsi_done after abort regarding this
  1922. * command has completed.
  1923. * Note: scsi_done must not block!
  1924. */
  1925. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1926. }
  1927. static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
  1928. {
  1929. struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
  1930. &(req->qtcb->bottom.io.fcp_rsp);
  1931. char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
  1932. if ((fcp_rsp_info[3] != RSP_CODE_GOOD) ||
  1933. (req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1934. req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  1935. }
  1936. static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
  1937. {
  1938. struct zfcp_unit *unit;
  1939. struct fsf_qtcb_header *header = &req->qtcb->header;
  1940. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
  1941. unit = req->data;
  1942. else
  1943. unit = req->unit;
  1944. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1945. goto skip_fsfstatus;
  1946. switch (header->fsf_status) {
  1947. case FSF_HANDLE_MISMATCH:
  1948. case FSF_PORT_HANDLE_NOT_VALID:
  1949. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 112, req);
  1950. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1951. break;
  1952. case FSF_FCPLUN_NOT_VALID:
  1953. case FSF_LUN_HANDLE_NOT_VALID:
  1954. zfcp_erp_port_reopen(unit->port, 0, 113, req);
  1955. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1956. break;
  1957. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1958. zfcp_fsf_class_not_supp(req);
  1959. break;
  1960. case FSF_ACCESS_DENIED:
  1961. zfcp_fsf_access_denied_unit(req, unit);
  1962. break;
  1963. case FSF_DIRECTION_INDICATOR_NOT_VALID:
  1964. dev_err(&req->adapter->ccw_device->dev,
  1965. "Incorrect direction %d, unit 0x%016Lx on port "
  1966. "0x%016Lx closed\n",
  1967. req->qtcb->bottom.io.data_direction,
  1968. (unsigned long long)unit->fcp_lun,
  1969. (unsigned long long)unit->port->wwpn);
  1970. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 133, req);
  1971. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1972. break;
  1973. case FSF_CMND_LENGTH_NOT_VALID:
  1974. dev_err(&req->adapter->ccw_device->dev,
  1975. "Incorrect CDB length %d, unit 0x%016Lx on "
  1976. "port 0x%016Lx closed\n",
  1977. req->qtcb->bottom.io.fcp_cmnd_length,
  1978. (unsigned long long)unit->fcp_lun,
  1979. (unsigned long long)unit->port->wwpn);
  1980. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 134, req);
  1981. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1982. break;
  1983. case FSF_PORT_BOXED:
  1984. zfcp_erp_port_boxed(unit->port, 53, req);
  1985. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1986. ZFCP_STATUS_FSFREQ_RETRY;
  1987. break;
  1988. case FSF_LUN_BOXED:
  1989. zfcp_erp_unit_boxed(unit, 54, req);
  1990. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1991. ZFCP_STATUS_FSFREQ_RETRY;
  1992. break;
  1993. case FSF_ADAPTER_STATUS_AVAILABLE:
  1994. if (header->fsf_status_qual.word[0] ==
  1995. FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
  1996. zfcp_test_link(unit->port);
  1997. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1998. break;
  1999. }
  2000. skip_fsfstatus:
  2001. if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
  2002. zfcp_fsf_send_fcp_ctm_handler(req);
  2003. else {
  2004. zfcp_fsf_send_fcp_command_task_handler(req);
  2005. req->unit = NULL;
  2006. zfcp_unit_put(unit);
  2007. }
  2008. }
  2009. static void zfcp_set_fcp_dl(struct fcp_cmnd_iu *fcp_cmd, u32 fcp_dl)
  2010. {
  2011. u32 *fcp_dl_ptr;
  2012. /*
  2013. * fcp_dl_addr = start address of fcp_cmnd structure +
  2014. * size of fixed part + size of dynamically sized add_dcp_cdb field
  2015. * SEE FCP-2 documentation
  2016. */
  2017. fcp_dl_ptr = (u32 *) ((unsigned char *) &fcp_cmd[1] +
  2018. (fcp_cmd->add_fcp_cdb_length << 2));
  2019. *fcp_dl_ptr = fcp_dl;
  2020. }
  2021. /**
  2022. * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
  2023. * @adapter: adapter where scsi command is issued
  2024. * @unit: unit where command is sent to
  2025. * @scsi_cmnd: scsi command to be sent
  2026. * @timer: timer to be started when request is initiated
  2027. * @req_flags: flags for fsf_request
  2028. */
  2029. int zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
  2030. struct zfcp_unit *unit,
  2031. struct scsi_cmnd *scsi_cmnd,
  2032. int use_timer, int req_flags)
  2033. {
  2034. struct zfcp_fsf_req *req;
  2035. struct fcp_cmnd_iu *fcp_cmnd_iu;
  2036. unsigned int sbtype;
  2037. int real_bytes, retval = -EIO;
  2038. if (unlikely(!(atomic_read(&unit->status) &
  2039. ZFCP_STATUS_COMMON_UNBLOCKED)))
  2040. return -EBUSY;
  2041. spin_lock(&adapter->req_q_lock);
  2042. if (!zfcp_fsf_sbal_available(adapter))
  2043. goto out;
  2044. req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
  2045. adapter->pool.fsf_req_scsi);
  2046. if (IS_ERR(req)) {
  2047. retval = PTR_ERR(req);
  2048. goto out;
  2049. }
  2050. zfcp_unit_get(unit);
  2051. req->unit = unit;
  2052. req->data = scsi_cmnd;
  2053. req->handler = zfcp_fsf_send_fcp_command_handler;
  2054. req->qtcb->header.lun_handle = unit->handle;
  2055. req->qtcb->header.port_handle = unit->port->handle;
  2056. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2057. scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
  2058. fcp_cmnd_iu = (struct fcp_cmnd_iu *) &(req->qtcb->bottom.io.fcp_cmnd);
  2059. fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
  2060. /*
  2061. * set depending on data direction:
  2062. * data direction bits in SBALE (SB Type)
  2063. * data direction bits in QTCB
  2064. * data direction bits in FCP_CMND IU
  2065. */
  2066. switch (scsi_cmnd->sc_data_direction) {
  2067. case DMA_NONE:
  2068. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2069. sbtype = SBAL_FLAGS0_TYPE_READ;
  2070. break;
  2071. case DMA_FROM_DEVICE:
  2072. req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
  2073. sbtype = SBAL_FLAGS0_TYPE_READ;
  2074. fcp_cmnd_iu->rddata = 1;
  2075. break;
  2076. case DMA_TO_DEVICE:
  2077. req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
  2078. sbtype = SBAL_FLAGS0_TYPE_WRITE;
  2079. fcp_cmnd_iu->wddata = 1;
  2080. break;
  2081. case DMA_BIDIRECTIONAL:
  2082. default:
  2083. retval = -EIO;
  2084. goto failed_scsi_cmnd;
  2085. }
  2086. if (likely((scsi_cmnd->device->simple_tags) ||
  2087. ((atomic_read(&unit->status) & ZFCP_STATUS_UNIT_READONLY) &&
  2088. (atomic_read(&unit->status) & ZFCP_STATUS_UNIT_SHARED))))
  2089. fcp_cmnd_iu->task_attribute = SIMPLE_Q;
  2090. else
  2091. fcp_cmnd_iu->task_attribute = UNTAGGED;
  2092. if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH))
  2093. fcp_cmnd_iu->add_fcp_cdb_length =
  2094. (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
  2095. memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
  2096. req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
  2097. fcp_cmnd_iu->add_fcp_cdb_length + sizeof(u32);
  2098. real_bytes = zfcp_qdio_sbals_from_sg(req, sbtype,
  2099. scsi_sglist(scsi_cmnd),
  2100. FSF_MAX_SBALS_PER_REQ);
  2101. if (unlikely(real_bytes < 0)) {
  2102. if (req->sbal_number < FSF_MAX_SBALS_PER_REQ)
  2103. retval = -EIO;
  2104. else {
  2105. dev_err(&adapter->ccw_device->dev,
  2106. "Oversize data package, unit 0x%016Lx "
  2107. "on port 0x%016Lx closed\n",
  2108. (unsigned long long)unit->fcp_lun,
  2109. (unsigned long long)unit->port->wwpn);
  2110. zfcp_erp_unit_shutdown(unit, 0, 131, req);
  2111. retval = -EINVAL;
  2112. }
  2113. goto failed_scsi_cmnd;
  2114. }
  2115. zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
  2116. if (use_timer)
  2117. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  2118. retval = zfcp_fsf_req_send(req);
  2119. if (unlikely(retval))
  2120. goto failed_scsi_cmnd;
  2121. goto out;
  2122. failed_scsi_cmnd:
  2123. zfcp_unit_put(unit);
  2124. zfcp_fsf_req_free(req);
  2125. scsi_cmnd->host_scribble = NULL;
  2126. out:
  2127. spin_unlock(&adapter->req_q_lock);
  2128. return retval;
  2129. }
  2130. /**
  2131. * zfcp_fsf_send_fcp_ctm - send SCSI task management command
  2132. * @adapter: pointer to struct zfcp-adapter
  2133. * @unit: pointer to struct zfcp_unit
  2134. * @tm_flags: unsigned byte for task management flags
  2135. * @req_flags: int request flags
  2136. * Returns: on success pointer to struct fsf_req, NULL otherwise
  2137. */
  2138. struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_adapter *adapter,
  2139. struct zfcp_unit *unit,
  2140. u8 tm_flags, int req_flags)
  2141. {
  2142. struct qdio_buffer_element *sbale;
  2143. struct zfcp_fsf_req *req = NULL;
  2144. struct fcp_cmnd_iu *fcp_cmnd_iu;
  2145. if (unlikely(!(atomic_read(&unit->status) &
  2146. ZFCP_STATUS_COMMON_UNBLOCKED)))
  2147. return NULL;
  2148. spin_lock(&adapter->req_q_lock);
  2149. if (!zfcp_fsf_sbal_available(adapter))
  2150. goto out;
  2151. req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
  2152. adapter->pool.fsf_req_scsi);
  2153. if (IS_ERR(req))
  2154. goto out;
  2155. req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
  2156. req->data = unit;
  2157. req->handler = zfcp_fsf_send_fcp_command_handler;
  2158. req->qtcb->header.lun_handle = unit->handle;
  2159. req->qtcb->header.port_handle = unit->port->handle;
  2160. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2161. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2162. req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
  2163. sizeof(u32);
  2164. sbale = zfcp_qdio_sbale_req(req);
  2165. sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
  2166. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  2167. fcp_cmnd_iu = (struct fcp_cmnd_iu *) &req->qtcb->bottom.io.fcp_cmnd;
  2168. fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
  2169. fcp_cmnd_iu->task_management_flags = tm_flags;
  2170. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  2171. if (!zfcp_fsf_req_send(req))
  2172. goto out;
  2173. zfcp_fsf_req_free(req);
  2174. req = NULL;
  2175. out:
  2176. spin_unlock(&adapter->req_q_lock);
  2177. return req;
  2178. }
  2179. static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
  2180. {
  2181. if (req->qtcb->header.fsf_status != FSF_GOOD)
  2182. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2183. }
  2184. /**
  2185. * zfcp_fsf_control_file - control file upload/download
  2186. * @adapter: pointer to struct zfcp_adapter
  2187. * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
  2188. * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
  2189. */
  2190. struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
  2191. struct zfcp_fsf_cfdc *fsf_cfdc)
  2192. {
  2193. struct qdio_buffer_element *sbale;
  2194. struct zfcp_fsf_req *req = NULL;
  2195. struct fsf_qtcb_bottom_support *bottom;
  2196. int direction, retval = -EIO, bytes;
  2197. if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
  2198. return ERR_PTR(-EOPNOTSUPP);
  2199. switch (fsf_cfdc->command) {
  2200. case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
  2201. direction = SBAL_FLAGS0_TYPE_WRITE;
  2202. break;
  2203. case FSF_QTCB_UPLOAD_CONTROL_FILE:
  2204. direction = SBAL_FLAGS0_TYPE_READ;
  2205. break;
  2206. default:
  2207. return ERR_PTR(-EINVAL);
  2208. }
  2209. spin_lock_bh(&adapter->req_q_lock);
  2210. if (zfcp_fsf_req_sbal_get(adapter))
  2211. goto out;
  2212. req = zfcp_fsf_req_create(adapter, fsf_cfdc->command, 0, NULL);
  2213. if (IS_ERR(req)) {
  2214. retval = -EPERM;
  2215. goto out;
  2216. }
  2217. req->handler = zfcp_fsf_control_file_handler;
  2218. sbale = zfcp_qdio_sbale_req(req);
  2219. sbale[0].flags |= direction;
  2220. bottom = &req->qtcb->bottom.support;
  2221. bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
  2222. bottom->option = fsf_cfdc->option;
  2223. bytes = zfcp_qdio_sbals_from_sg(req, direction, fsf_cfdc->sg,
  2224. FSF_MAX_SBALS_PER_REQ);
  2225. if (bytes != ZFCP_CFDC_MAX_SIZE) {
  2226. retval = -ENOMEM;
  2227. zfcp_fsf_req_free(req);
  2228. goto out;
  2229. }
  2230. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  2231. retval = zfcp_fsf_req_send(req);
  2232. out:
  2233. spin_unlock_bh(&adapter->req_q_lock);
  2234. if (!retval) {
  2235. wait_event(req->completion_wq,
  2236. req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  2237. return req;
  2238. }
  2239. return ERR_PTR(retval);
  2240. }